pi-outpost 0.56.0 → 0.57.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/dist/contract/validate-structured-exchange.mjs +1 -1
  3. package/dist/pi-outpost.mjs +626 -154
  4. package/dist/pi-outpost.sea.mjs +2 -2
  5. package/dist/sea-prep.blob +2 -2
  6. package/dist/web/assets/{CodeEditor-DW06InQx.js → CodeEditor-BIH6CdMn.js} +2 -2
  7. package/dist/web/assets/{PdfViewer-Bon2alNC.js → PdfViewer-BTK9Pwfa.js} +2 -2
  8. package/dist/web/assets/{abnfDiagram-WEYOIA3C-D4OGFFrL.js → abnfDiagram-WEYOIA3C-lOBfa3Zk.js} +1 -1
  9. package/dist/web/assets/{architecture-WOLXFQ4H-DA7E09Jj.js → architecture-WOLXFQ4H-BxoPEz1Q.js} +1 -1
  10. package/dist/web/assets/{architectureDiagram-ZHVYKT53-DCUB1Bbf.js → architectureDiagram-ZHVYKT53-CYy51DKY.js} +1 -1
  11. package/dist/web/assets/{blockDiagram-RJAE7QA3-BtVrRDzI.js → blockDiagram-RJAE7QA3-LJlH-2Bl.js} +1 -1
  12. package/dist/web/assets/{c4Diagram-XDPPPE54-CWKeiHWN.js → c4Diagram-XDPPPE54-B2B-BwKL.js} +1 -1
  13. package/dist/web/assets/channel-BDNYhMNU.js +1 -0
  14. package/dist/web/assets/{chunk-2E7WHVMD-B83qjvEZ.js → chunk-2E7WHVMD-Dr2lQGM1.js} +1 -1
  15. package/dist/web/assets/{chunk-4EMNKR2T-B-vN-2a8.js → chunk-4EMNKR2T-AF6kxqF-.js} +1 -1
  16. package/dist/web/assets/{chunk-55XCU76K-GJ8enTst.js → chunk-55XCU76K-CFBoCByy.js} +1 -1
  17. package/dist/web/assets/{chunk-7S6XSTFO-nBK2HuEp.js → chunk-7S6XSTFO-Cu5LCmOf.js} +1 -1
  18. package/dist/web/assets/{chunk-AQDTSKZB-DdjPxkpE.js → chunk-AQDTSKZB-CL_Kx2hG.js} +1 -1
  19. package/dist/web/assets/{chunk-DSNLSHJZ-B3N6pTGn.js → chunk-DSNLSHJZ-D-XSjeO-.js} +3 -3
  20. package/dist/web/assets/{chunk-HAGFOTED-L2Zi-3o4.js → chunk-HAGFOTED-BpSSAyhD.js} +1 -1
  21. package/dist/web/assets/{chunk-HNE4Q36P-DffWt-6e.js → chunk-HNE4Q36P-BWLJS9fF.js} +1 -1
  22. package/dist/web/assets/{chunk-NQOKRVIF-DD9X9cJ3.js → chunk-NQOKRVIF-30ZBT7ib.js} +1 -1
  23. package/dist/web/assets/{chunk-UHW7PFBP-DDq5tq6j.js → chunk-UHW7PFBP-DbFC6Kqg.js} +1 -1
  24. package/dist/web/assets/{chunk-VQ5W62QI-xdGlkAsp.js → chunk-VQ5W62QI-BCYKoxfl.js} +1 -1
  25. package/dist/web/assets/{chunk-WQQL4CDK-DPNUauEU.js → chunk-WQQL4CDK-DPlv7C9B.js} +1 -1
  26. package/dist/web/assets/{chunk-YZO67HFG-7820jJMx.js → chunk-YZO67HFG-BLUL5tmC.js} +1 -1
  27. package/dist/web/assets/{chunk-ZAUX2LTX-BSAkkNmt.js → chunk-ZAUX2LTX-Bwza4fLr.js} +1 -1
  28. package/dist/web/assets/{chunk-ZCHMQSOR-BYvKBq47.js → chunk-ZCHMQSOR-D0FggULn.js} +1 -1
  29. package/dist/web/assets/{classDiagram-v2-4MYWR3UA-D8_V_0sz.js → classDiagram-v2-4MYWR3UA-Bk4Capy3.js} +1 -1
  30. package/dist/web/assets/{conversationExport-CxC-uGG5.js → conversationExport-0nyaeKNF.js} +1 -1
  31. package/dist/web/assets/{cynefin-EF2NZ3EQ-DtMxpZWx.js → cynefin-EF2NZ3EQ-DzV97kfv.js} +1 -1
  32. package/dist/web/assets/{cynefinDiagram-WF24UDRP-BxnPcRNs.js → cynefinDiagram-WF24UDRP-Cf8rKSpR.js} +1 -1
  33. package/dist/web/assets/{dagre-NK4GIZVX-D_PZO-3p.js → dagre-NK4GIZVX-D__XgaEv.js} +1 -1
  34. package/dist/web/assets/{diagram-CBK3MWTC-Dl6oTLzj.js → diagram-CBK3MWTC-D6z3NCJr.js} +1 -1
  35. package/dist/web/assets/{diagram-I5XIIV2D-CCWuEDY9.js → diagram-I5XIIV2D-DS10H88Z.js} +1 -1
  36. package/dist/web/assets/{diagram-ODIL2UCW-cB4An-U5.js → diagram-ODIL2UCW-DsHs8DGN.js} +1 -1
  37. package/dist/web/assets/{diagram-PFBEJUXE-BlM2NtYA.js → diagram-PFBEJUXE-tKYMPwBi.js} +1 -1
  38. package/dist/web/assets/{diagram-RJA3I4VV-BIVdgSY3.js → diagram-RJA3I4VV-6e-ArJPM.js} +1 -1
  39. package/dist/web/assets/{diagram-TYUNFSNR-fU2D-jh_.js → diagram-TYUNFSNR-B3j9ZE2j.js} +1 -1
  40. package/dist/web/assets/{dist-Ddxe0AAc.js → dist-BH8zN7Zg.js} +1 -1
  41. package/dist/web/assets/{dist-Cw4_6ALo.js → dist-BI873TWC.js} +1 -1
  42. package/dist/web/assets/{dist-CC7m26En.js → dist-Bd3qcY-a.js} +1 -1
  43. package/dist/web/assets/{dist-CrdgSEPc.js → dist-BwT1ugnl.js} +1 -1
  44. package/dist/web/assets/{dist-B3pnSx3X.js → dist-CC_XBenB.js} +1 -1
  45. package/dist/web/assets/{dist-ClGl4dnb.js → dist-DjTllVa-.js} +1 -1
  46. package/dist/web/assets/{dist-TjHlbCYw.js → dist-DkPwhxV7.js} +1 -1
  47. package/dist/web/assets/{docxExport-1eYht7KT.js → docxExport-DVePkHyV.js} +1 -1
  48. package/dist/web/assets/{ebnfDiagram-V4P3TTPT-DlI1I3vA.js → ebnfDiagram-V4P3TTPT-DIyK46QA.js} +1 -1
  49. package/dist/web/assets/{elk-QONTBCTQ-D1JekY0t.js → elk-QONTBCTQ-Y1YPFVtm.js} +1 -1
  50. package/dist/web/assets/{erDiagram-KYQIGQAA-kq_SP_ND.js → erDiagram-KYQIGQAA-BKC4DjFM.js} +1 -1
  51. package/dist/web/assets/{eventmodeling-K75KTNOO-C7IIxgpN.js → eventmodeling-K75KTNOO-C28ROj2m.js} +1 -1
  52. package/dist/web/assets/flowDiagram-IUGLLWBU-D4IFH9IO.js +1 -0
  53. package/dist/web/assets/{ganttDiagram-R7GPNTJY-Dq3-B0Ll.js → ganttDiagram-R7GPNTJY-DwNq4Tva.js} +1 -1
  54. package/dist/web/assets/{gitGraph-VSP46ZUC-DuvQALvs.js → gitGraph-VSP46ZUC-C4cL0DSH.js} +1 -1
  55. package/dist/web/assets/{gitGraphDiagram-PDYL7XHY-Da0CRY-2.js → gitGraphDiagram-PDYL7XHY-DJ4VD1OR.js} +1 -1
  56. package/dist/web/assets/{info-OHQRW6UA-Ovgd-9v9.js → info-OHQRW6UA-CYBU-xSj.js} +1 -1
  57. package/dist/web/assets/{infoDiagram-MVDRKAX5-yEyCP2Ce.js → infoDiagram-MVDRKAX5-Dq_L-w1u.js} +1 -1
  58. package/dist/web/assets/{ishikawaDiagram-HPEHV2GE-B8QcyIwk.js → ishikawaDiagram-HPEHV2GE-D1g4xt4c.js} +1 -1
  59. package/dist/web/assets/{journeyDiagram-BOSHW7O7-BpBl3CU2.js → journeyDiagram-BOSHW7O7-BWpIG50H.js} +1 -1
  60. package/dist/web/assets/{kanban-definition-FNSA4HC5-qiRCTwC4.js → kanban-definition-FNSA4HC5-CYtexyr1.js} +1 -1
  61. package/dist/web/assets/{line-CY2YCO9s.js → line-o0UO7Tkx.js} +1 -1
  62. package/dist/web/assets/{loadReferencedImage-HmX-11oE.js → loadReferencedImage-d-cNU_4L.js} +1 -1
  63. package/dist/web/assets/main-8SBKD8FK.css +2 -0
  64. package/dist/web/assets/{main-Buqq77Ng.js → main-Bi-WPEpf.js} +32 -31
  65. package/dist/web/assets/{mermaid-parser.core-CkumFOgt.js → mermaid-parser.core-7RNwn3fu.js} +3 -3
  66. package/dist/web/assets/{mermaid.core-BMxNKlaY.js → mermaid.core-bsPCHPw0.js} +4 -4
  67. package/dist/web/assets/{mermaidToImage-BuA9Xm_J.js → mermaidToImage-UE8_p2E5.js} +3 -3
  68. package/dist/web/assets/{mindmap-definition-6OY57UG3-CsLOBetK.js → mindmap-definition-6OY57UG3-e2lWeHyW.js} +1 -1
  69. package/dist/web/assets/{packet-JDAUHWVQ-D6U8cq4U.js → packet-JDAUHWVQ-4VBPuxYC.js} +1 -1
  70. package/dist/web/assets/{pdf-tbgQZNz6.js → pdf-Dx5J3Df4.js} +1 -1
  71. package/dist/web/assets/{pegDiagram-ECIUJNBX-ByAKVJlD.js → pegDiagram-ECIUJNBX-DOeDVMs7.js} +1 -1
  72. package/dist/web/assets/{pie-XZMESJXO-DAUFxYmA.js → pie-XZMESJXO-DGZo66aQ.js} +1 -1
  73. package/dist/web/assets/{pieDiagram-GNMPY74T-BhFMwT8I.js → pieDiagram-GNMPY74T-Czp4vSoe.js} +1 -1
  74. package/dist/web/assets/{quadrantDiagram-D57K4MC3-RJ27NwZb.js → quadrantDiagram-D57K4MC3-BXM_JHPz.js} +1 -1
  75. package/dist/web/assets/{radar-ABXABTNO-DGekn8s4.js → radar-ABXABTNO-CVolemZj.js} +1 -1
  76. package/dist/web/assets/{railroad-I3PHUGI6-C7NnYuSc.js → railroad-I3PHUGI6-B-doo8JH.js} +1 -1
  77. package/dist/web/assets/{railroad-abnf-LNEFI6M7-CPLiesZe.js → railroad-abnf-LNEFI6M7-BfTWL1Id.js} +1 -1
  78. package/dist/web/assets/{railroad-ebnf-DWYD2UWJ-D55m71s2.js → railroad-ebnf-DWYD2UWJ-BFeWo67Y.js} +1 -1
  79. package/dist/web/assets/{railroad-peg-JR7BVNR7-M9o6xT4z.js → railroad-peg-JR7BVNR7-Bk2NmFKK.js} +1 -1
  80. package/dist/web/assets/{railroadDiagram-Y72NRBL7-BlrrqzUe.js → railroadDiagram-Y72NRBL7-Dc1XIDGF.js} +1 -1
  81. package/dist/web/assets/{requirementDiagram-EQYSW5RA-DzsZKjfI.js → requirementDiagram-EQYSW5RA-DmbzKUaK.js} +1 -1
  82. package/dist/web/assets/{sankeyDiagram-SY24JHO5-IFnYBhGN.js → sankeyDiagram-SY24JHO5-DVHdeQhs.js} +1 -1
  83. package/dist/web/assets/{sequenceDiagram-BLEHNHQU-eDHsRVuS.js → sequenceDiagram-BLEHNHQU-CB5GSoTC.js} +1 -1
  84. package/dist/web/assets/{stateDiagram-v2-A6IESKWZ-CbLEjwPC.js → stateDiagram-v2-A6IESKWZ-DCJbl6WI.js} +1 -1
  85. package/dist/web/assets/{swimlanes-B3ENRKFQ-B9kd7NEK.js → swimlanes-B3ENRKFQ-DvhB-YGC.js} +1 -1
  86. package/dist/web/assets/swimlanesDiagram-AYQRV4AK-BlCSR7eU.js +8 -0
  87. package/dist/web/assets/{timeline-definition-JXYKGLGB-C2Ww2TVj.js → timeline-definition-JXYKGLGB-BaV8aqeu.js} +1 -1
  88. package/dist/web/assets/{treeView-D4JQ5SDB-C1CPVvUq.js → treeView-D4JQ5SDB-ND_zQpjS.js} +1 -1
  89. package/dist/web/assets/{treemap-SAJKECNS-CQvjDt7h.js → treemap-SAJKECNS-D6wNzjtO.js} +1 -1
  90. package/dist/web/assets/{usecaseDiagram-WPOLBNNX-CMM3vxho.js → usecaseDiagram-WPOLBNNX-DlHi--Zm.js} +1 -1
  91. package/dist/web/assets/{vennDiagram-Q3Y3IDCW-D88It7hB.js → vennDiagram-Q3Y3IDCW-DpUXTi9U.js} +1 -1
  92. package/dist/web/assets/{wardley-7MLQ67FV-C4pnE_Aj.js → wardley-7MLQ67FV-RiTx-hi3.js} +1 -1
  93. package/dist/web/assets/{wardleyDiagram-IVAIDKWA-DBy9jTgO.js → wardleyDiagram-IVAIDKWA-D51nBiW5.js} +1 -1
  94. package/dist/web/assets/{xychartDiagram-4URNHDU4-BEO7OMi7.js → xychartDiagram-4URNHDU4-D_AjQw-A.js} +1 -1
  95. package/dist/web/index.html +2 -2
  96. package/package.json +2 -2
  97. package/dist/web/assets/channel-ghk8vvbi.js +0 -1
  98. package/dist/web/assets/flowDiagram-IUGLLWBU-BoPRcGY4.js +0 -1
  99. package/dist/web/assets/main-D1SGZDRR.css +0 -2
  100. package/dist/web/assets/swimlanesDiagram-AYQRV4AK-lIzADDxU.js +0 -8
@@ -1,4 +1,4 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/core-DFGL04am.js","assets/frame-BuvfWkjw.js","assets/mermaid.core-BMxNKlaY.js","assets/chunk-Y2CYZVJY-DsF7k-Jl.js","assets/src-B0SIfd8P.js","assets/chunk-DSNLSHJZ-B3N6pTGn.js","assets/chunk-7S6XSTFO-nBK2HuEp.js","assets/dist-CRDUZiS0.js","assets/chunk-YZO67HFG-7820jJMx.js","assets/chunk-AQDTSKZB-DdjPxkpE.js","assets/chunk-DUW6YSOI-Dgx8z5s3.js","assets/chunk-UHW7PFBP-DDq5tq6j.js","assets/chunk-HAGFOTED-L2Zi-3o4.js","assets/chunk-J5ZVWO5B-oDCd-gWO.js","assets/rough.esm-Dy-Kn_BL.js","assets/chunk-ZAUX2LTX-BSAkkNmt.js","assets/chunk-WQQL4CDK-DPNUauEU.js","assets/line-CY2YCO9s.js","assets/path-fybaL0A-.js","assets/array-BifhSqXX.js","assets/chunk-HNE4Q36P-DffWt-6e.js","assets/mermaidToImage-BuA9Xm_J.js","assets/CodeEditor-DW06InQx.js","assets/dist-7keixpik.js","assets/docxExport-1eYht7KT.js","assets/loadReferencedImage-HmX-11oE.js","assets/conversationExport-CxC-uGG5.js"])))=>i.map(i=>d[i]);
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/core-DFGL04am.js","assets/frame-BuvfWkjw.js","assets/mermaid.core-bsPCHPw0.js","assets/chunk-Y2CYZVJY-DsF7k-Jl.js","assets/src-B0SIfd8P.js","assets/chunk-DSNLSHJZ-D-XSjeO-.js","assets/chunk-7S6XSTFO-Cu5LCmOf.js","assets/dist-CRDUZiS0.js","assets/chunk-YZO67HFG-BLUL5tmC.js","assets/chunk-AQDTSKZB-CL_Kx2hG.js","assets/chunk-DUW6YSOI-Dgx8z5s3.js","assets/chunk-UHW7PFBP-DbFC6Kqg.js","assets/chunk-HAGFOTED-BpSSAyhD.js","assets/chunk-J5ZVWO5B-oDCd-gWO.js","assets/rough.esm-Dy-Kn_BL.js","assets/chunk-ZAUX2LTX-Bwza4fLr.js","assets/chunk-WQQL4CDK-DPlv7C9B.js","assets/line-o0UO7Tkx.js","assets/path-fybaL0A-.js","assets/array-BifhSqXX.js","assets/chunk-HNE4Q36P-BWLJS9fF.js","assets/mermaidToImage-UE8_p2E5.js","assets/CodeEditor-BIH6CdMn.js","assets/dist-7keixpik.js","assets/docxExport-DVePkHyV.js","assets/loadReferencedImage-d-cNU_4L.js","assets/conversationExport-0nyaeKNF.js"])))=>i.map(i=>d[i]);
2
2
  import{a as e,c as t,d as n,f as r,g as i,m as a,n as o,p as s,s as c,t as l}from"./frame-BuvfWkjw.js";var u=s((e=>{var t=Symbol.for(`react.transitional.element`),n=Symbol.for(`react.portal`),r=Symbol.for(`react.fragment`),i=Symbol.for(`react.strict_mode`),a=Symbol.for(`react.profiler`),o=Symbol.for(`react.consumer`),s=Symbol.for(`react.context`),c=Symbol.for(`react.forward_ref`),l=Symbol.for(`react.suspense`),u=Symbol.for(`react.memo`),d=Symbol.for(`react.lazy`),f=Symbol.for(`react.activity`),p=Symbol.for(`react.view_transition`),m=Symbol.iterator;function h(e){return typeof e!=`object`||!e?null:(e=m&&e[m]||e[`@@iterator`],typeof e==`function`?e:null)}var g={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},_=Object.assign,v={};function y(e,t,n){this.props=e,this.context=t,this.refs=v,this.updater=n||g}y.prototype.isReactComponent={},y.prototype.setState=function(e,t){if(typeof e!=`object`&&typeof e!=`function`&&e!=null)throw Error(`takes an object of state variables to update or a function which returns an object of state variables.`);this.updater.enqueueSetState(this,e,t,`setState`)},y.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,`forceUpdate`)};function b(){}b.prototype=y.prototype;function x(e,t,n){this.props=e,this.context=t,this.refs=v,this.updater=n||g}var S=x.prototype=new b;S.constructor=x,_(S,y.prototype),S.isPureReactComponent=!0;var C=Array.isArray;function w(){}var T={H:null,A:null,T:null,S:null},E=Object.prototype.hasOwnProperty;function D(e,n,r){var i=r.ref;return{$$typeof:t,type:e,key:n,ref:i===void 0?null:i,props:r}}function O(e,t){return D(e.type,t,e.props)}function ee(e){return typeof e==`object`&&!!e&&e.$$typeof===t}function te(e){var t={"=":`=0`,":":`=2`};return`$`+e.replace(/[=:]/g,function(e){return t[e]})}var k=/\/+/g;function ne(e,t){return typeof e==`object`&&e&&e.key!=null?te(``+e.key):t.toString(36)}function A(e){switch(e.status){case`fulfilled`:return e.value;case`rejected`:throw e.reason;default:switch(typeof e.status==`string`?e.then(w,w):(e.status=`pending`,e.then(function(t){e.status===`pending`&&(e.status=`fulfilled`,e.value=t)},function(t){e.status===`pending`&&(e.status=`rejected`,e.reason=t)})),e.status){case`fulfilled`:return e.value;case`rejected`:throw e.reason}}throw e}function re(e,r,i,a,o){var s=typeof e;(s===`undefined`||s===`boolean`)&&(e=null);var c=!1;if(e===null)c=!0;else switch(s){case`bigint`:case`string`:case`number`:c=!0;break;case`object`:switch(e.$$typeof){case t:case n:c=!0;break;case d:return c=e._init,re(c(e._payload),r,i,a,o)}}if(c)return o=o(e),c=a===``?`.`+ne(e,0):a,C(o)?(i=``,c!=null&&(i=c.replace(k,`$&/`)+`/`),re(o,r,i,``,function(e){return e})):o!=null&&(ee(o)&&(o=O(o,i+(o.key==null||e&&e.key===o.key?``:(``+o.key).replace(k,`$&/`)+`/`)+c)),r.push(o)),1;c=0;var l=a===``?`.`:a+`:`;if(C(e))for(var u=0;u<e.length;u++)a=e[u],s=l+ne(a,u),c+=re(a,r,i,s,o);else if(u=h(e),typeof u==`function`)for(e=u.call(e),u=0;!(a=e.next()).done;)a=a.value,s=l+ne(a,u++),c+=re(a,r,i,s,o);else if(s===`object`){if(typeof e.then==`function`)return re(A(e),r,i,a,o);throw r=String(e),Error(`Objects are not valid as a React child (found: `+(r===`[object Object]`?`object with keys {`+Object.keys(e).join(`, `)+`}`:r)+`). If you meant to render a collection of children, use an array instead.`)}return c}function j(e,t,n){if(e==null)return e;var r=[],i=0;return re(e,r,``,``,function(e){return t.call(n,e,i++)}),r}function ie(e){if(e._status===-1){var t=e._result,n=t();n.then(function(t){(e._status===0||e._status===-1)&&(e._status=1,e._result=t,n.status===void 0&&(n.status=`fulfilled`,n.value=t))},function(t){(e._status===0||e._status===-1)&&(e._status=2,e._result=t,n.status===void 0&&(n.status=`rejected`,n.reason=t))}),e._status===-1&&(e._status=0,e._result=n)}if(e._status===1)return e._result.default;throw e._result}var ae=typeof reportError==`function`?reportError:function(e){if(typeof window==`object`&&typeof window.ErrorEvent==`function`){var t=new window.ErrorEvent(`error`,{bubbles:!0,cancelable:!0,message:typeof e==`object`&&e&&typeof e.message==`string`?String(e.message):String(e),error:e});if(!window.dispatchEvent(t))return}else if(typeof process==`object`&&typeof process.emit==`function`){process.emit(`uncaughtException`,e);return}console.error(e)};function oe(e){var t=T.T,n={};n.types=t===null?null:t.types,T.T=n;try{var r=e(),i=T.S;i!==null&&i(n,r),typeof r==`object`&&r&&typeof r.then==`function`&&r.then(w,ae)}catch(e){ae(e)}finally{t!==null&&n.types!==null&&(t.types=n.types),T.T=t}}function se(e){var t=T.T;if(t!==null){var n=t.types;n===null?t.types=[e]:n.indexOf(e)===-1&&n.push(e)}else oe(se.bind(null,e))}var ce={map:j,forEach:function(e,t,n){j(e,function(){t.apply(this,arguments)},n)},count:function(e){var t=0;return j(e,function(){t++}),t},toArray:function(e){return j(e,function(e){return e})||[]},only:function(e){if(!ee(e))throw Error(`React.Children.only expected to receive a single React element child.`);return e}};e.Activity=f,e.Children=ce,e.Component=y,e.Fragment=r,e.Profiler=a,e.PureComponent=x,e.StrictMode=i,e.Suspense=l,e.ViewTransition=p,e.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=T,e.__COMPILER_RUNTIME={__proto__:null,c:function(e){return T.H.useMemoCache(e)}},e.addTransitionType=se,e.cache=function(e){return function(){return e.apply(null,arguments)}},e.cacheSignal=function(){return null},e.cloneElement=function(e,t,n){if(e==null)throw Error(`The argument must be a React element, but you passed `+e+`.`);var r=_({},e.props),i=e.key;if(t!=null)for(a in t.key!==void 0&&(i=``+t.key),t)!E.call(t,a)||a===`key`||a===`__self`||a===`__source`||a===`ref`&&t.ref===void 0||(r[a]=t[a]);var a=arguments.length-2;if(a===1)r.children=n;else if(1<a){for(var o=Array(a),s=0;s<a;s++)o[s]=arguments[s+2];r.children=o}return D(e.type,i,r)},e.createContext=function(e){return e={$$typeof:s,_currentValue:e,_currentValue2:e,_threadCount:0,Provider:null,Consumer:null},e.Provider=e,e.Consumer={$$typeof:o,_context:e},e},e.createElement=function(e,t,n){var r,i={},a=null;if(t!=null)for(r in t.key!==void 0&&(a=``+t.key),t)E.call(t,r)&&r!==`key`&&r!==`__self`&&r!==`__source`&&(i[r]=t[r]);var o=arguments.length-2;if(o===1)i.children=n;else if(1<o){for(var s=Array(o),c=0;c<o;c++)s[c]=arguments[c+2];i.children=s}if(e&&e.defaultProps)for(r in o=e.defaultProps,o)i[r]===void 0&&(i[r]=o[r]);return D(e,a,i)},e.createRef=function(){return{current:null}},e.forwardRef=function(e){return{$$typeof:c,render:e}},e.isValidElement=ee,e.lazy=function(e){return{$$typeof:d,_payload:{_status:-1,_result:e},_init:ie}},e.memo=function(e,t){return{$$typeof:u,type:e,compare:t===void 0?null:t}},e.startTransition=oe,e.unstable_useCacheRefresh=function(){return T.H.useCacheRefresh()},e.use=function(e){return T.H.use(e)},e.useActionState=function(e,t,n){return T.H.useActionState(e,t,n)},e.useCallback=function(e,t){return T.H.useCallback(e,t)},e.useContext=function(e){return T.H.useContext(e)},e.useDebugValue=function(){},e.useDeferredValue=function(e,t){return T.H.useDeferredValue(e,t)},e.useEffect=function(e,t){return T.H.useEffect(e,t)},e.useEffectEvent=function(e){return T.H.useEffectEvent(e)},e.useId=function(){return T.H.useId()},e.useImperativeHandle=function(e,t,n){return T.H.useImperativeHandle(e,t,n)},e.useInsertionEffect=function(e,t){return T.H.useInsertionEffect(e,t)},e.useLayoutEffect=function(e,t){return T.H.useLayoutEffect(e,t)},e.useMemo=function(e,t){return T.H.useMemo(e,t)},e.useOptimistic=function(e,t){return T.H.useOptimistic(e,t)},e.useReducer=function(e,t,n){return T.H.useReducer(e,t,n)},e.useRef=function(e){return T.H.useRef(e)},e.useState=function(e){return T.H.useState(e)},e.useSyncExternalStore=function(e,t,n){return T.H.useSyncExternalStore(e,t,n)},e.useTransition=function(){return T.H.useTransition()},e.version=`19.3.1`})),d=s(((e,t)=>{t.exports=u()})),f=s((e=>{function t(e,t){var n=e.length;e.push(t);a:for(;0<n;){var r=n-1>>>1,a=e[r];if(0<i(a,t))e[r]=t,e[n]=a,n=r;else break a}}function n(e){return e.length===0?null:e[0]}function r(e){if(e.length===0)return null;var t=e[0],n=e.pop();if(n!==t){e[0]=n;a:for(var r=0,a=e.length,o=a>>>1;r<o;){var s=2*(r+1)-1,c=e[s],l=s+1,u=e[l];if(0>i(c,n))l<a&&0>i(u,c)?(e[r]=u,e[l]=n,r=l):(e[r]=c,e[s]=n,r=s);else if(l<a&&0>i(u,n))e[r]=u,e[l]=n,r=l;else break a}}return t}function i(e,t){var n=e.sortIndex-t.sortIndex;return n===0?e.id-t.id:n}if(e.unstable_now=void 0,typeof performance==`object`&&typeof performance.now==`function`){var a=performance;e.unstable_now=function(){return a.now()}}else{var o=Date,s=o.now();e.unstable_now=function(){return o.now()-s}}var c=[],l=[],u=1,d=null,f=3,p=!1,m=!1,h=!1,g=!1,_=typeof setTimeout==`function`?setTimeout:null,v=typeof clearTimeout==`function`?clearTimeout:null,y=typeof setImmediate<`u`?setImmediate:null;function b(e){for(var i=n(l);i!==null;){if(i.callback===null)r(l);else if(i.startTime<=e)r(l),i.sortIndex=i.expirationTime,t(c,i);else break;i=n(l)}}function x(e){if(h=!1,b(e),!m){if(n(c)!==null)m=!0,S||(S=!0,O());else{var t=n(l);t!==null&&k(x,t.startTime-e)}}}var S=!1,C=-1,w=5,T=-1;function E(){return g?!0:!(e.unstable_now()-T<w)}function D(){if(g=!1,S){var t=e.unstable_now();T=t;var i=!0;try{a:{m=!1,h&&(h=!1,v(C),C=-1),p=!0;var a=f;try{b:{for(b(t),d=n(c);d!==null&&!(d.expirationTime>t&&E());){var o=d.callback;if(typeof o==`function`){d.callback=null,f=d.priorityLevel;var s=o(d.expirationTime<=t);if(t=e.unstable_now(),typeof s==`function`){d.callback=s,b(t),i=!0;break b}d===n(c)&&r(c),b(t)}else r(c);d=n(c)}if(d!==null)i=!0;else{var u=n(l);u!==null&&k(x,u.startTime-t),i=!1}}break a}finally{d=null,f=a,p=!1}i=void 0}}finally{i?O():S=!1}}}var O;if(typeof y==`function`)O=function(){y(D)};else if(typeof MessageChannel<`u`){var ee=new MessageChannel,te=ee.port2;ee.port1.onmessage=D,O=function(){te.postMessage(null)}}else O=function(){_(D,0)};function k(t,n){C=_(function(){t(e.unstable_now())},n)}e.unstable_IdlePriority=5,e.unstable_ImmediatePriority=1,e.unstable_LowPriority=4,e.unstable_NormalPriority=3,e.unstable_Profiling=null,e.unstable_UserBlockingPriority=2,e.unstable_cancelCallback=function(e){e.callback=null},e.unstable_forceFrameRate=function(e){0>e||125<e?console.error(`forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported`):w=0<e?Math.floor(1e3/e):5},e.unstable_getCurrentPriorityLevel=function(){return f},e.unstable_next=function(e){switch(f){case 1:case 2:case 3:var t=3;break;default:t=f}var n=f;f=t;try{return e()}finally{f=n}},e.unstable_requestPaint=function(){g=!0},e.unstable_runWithPriority=function(e,t){switch(e){case 1:case 2:case 3:case 4:case 5:break;default:e=3}var n=f;f=e;try{return t()}finally{f=n}},e.unstable_scheduleCallback=function(r,i,a){var o=e.unstable_now();switch(typeof a==`object`&&a?(a=a.delay,a=typeof a==`number`&&0<a?o+a:o):a=o,r){case 1:var s=-1;break;case 2:s=250;break;case 5:s=1073741823;break;case 4:s=1e4;break;default:s=5e3}return s=a+s,r={id:u++,callback:i,priorityLevel:r,startTime:a,expirationTime:s,sortIndex:-1},a>o?(r.sortIndex=a,t(l,r),n(c)===null&&r===n(l)&&(h?(v(C),C=-1):h=!0,k(x,a-o))):(r.sortIndex=s,t(c,r),m||p||(m=!0,S||(S=!0,O()))),r},e.unstable_shouldYield=E,e.unstable_wrapCallback=function(e){var t=f;return function(){var n=f;f=t;try{return e.apply(this,arguments)}finally{f=n}}}})),p=s(((e,t)=>{t.exports=f()})),m=s((e=>{var t=d();function n(e){var t=`https://react.dev/errors/`+e;if(1<arguments.length){t+=`?args[]=`+encodeURIComponent(arguments[1]);for(var n=2;n<arguments.length;n++)t+=`&args[]=`+encodeURIComponent(arguments[n])}return`Minified React error #`+e+`; visit `+t+` for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`}function r(){}var i={d:{f:r,r:function(){throw Error(n(522))},D:r,C:r,L:r,m:r,X:r,S:r,M:r},p:0,findDOMNode:null},a=Symbol.for(`react.portal`),o=Symbol.for(`react.recoverable`),s=Symbol.for(`react.optimistic_key`);function c(e,t,n){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:a,key:r==null?null:r===s?s:``+r,children:e,containerInfo:t,implementation:n}}var l=t.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;function u(e,t){if(e===`font`)return``;if(typeof t==`string`)return t===`use-credentials`?t:``}e.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=i,e.browser=function(e){return{$$typeof:o,_reason:e}},e.createPortal=function(e,t){var r=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!t||t.nodeType!==1&&t.nodeType!==9&&t.nodeType!==11)throw Error(n(299));return c(e,t,null,r)},e.flushSync=function(e){var t=l.T,n=i.p;try{if(l.T=null,i.p=2,e)return e()}finally{l.T=t,i.p=n,i.d.f()}},e.preconnect=function(e,t){typeof e==`string`&&(t?(t=t.crossOrigin,t=typeof t==`string`?t===`use-credentials`?t:``:void 0):t=null,i.d.C(e,t))},e.prefetchDNS=function(e){typeof e==`string`&&i.d.D(e)},e.preinit=function(e,t){if(typeof e==`string`&&t&&typeof t.as==`string`){var n=t.as,r=u(n,t.crossOrigin),a=typeof t.integrity==`string`?t.integrity:void 0,o=typeof t.fetchPriority==`string`?t.fetchPriority:void 0;n===`style`?i.d.S(e,typeof t.precedence==`string`?t.precedence:void 0,{crossOrigin:r,integrity:a,fetchPriority:o}):n===`script`&&i.d.X(e,{crossOrigin:r,integrity:a,fetchPriority:o,nonce:typeof t.nonce==`string`?t.nonce:void 0})}},e.preinitModule=function(e,t){if(typeof e==`string`){if(typeof t==`object`&&t){if(t.as==null||t.as===`script`){var n=u(t.as,t.crossOrigin);i.d.M(e,{crossOrigin:n,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0,fetchPriority:typeof t.fetchPriority==`string`?t.fetchPriority:void 0})}}else t??i.d.M(e)}},e.preload=function(e,t){if(typeof e==`string`&&typeof t==`object`&&t&&typeof t.as==`string`){var n=t.as,r=u(n,t.crossOrigin);i.d.L(e,n,{crossOrigin:r,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0,type:typeof t.type==`string`?t.type:void 0,fetchPriority:typeof t.fetchPriority==`string`?t.fetchPriority:void 0,referrerPolicy:typeof t.referrerPolicy==`string`?t.referrerPolicy:void 0,imageSrcSet:typeof t.imageSrcSet==`string`?t.imageSrcSet:void 0,imageSizes:typeof t.imageSizes==`string`?t.imageSizes:void 0,media:typeof t.media==`string`?t.media:void 0})}},e.preloadModule=function(e,t){if(typeof e==`string`){if(t){var n=u(t.as,t.crossOrigin);i.d.m(e,{as:typeof t.as==`string`&&t.as!==`script`?t.as:void 0,crossOrigin:n,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0,fetchPriority:typeof t.fetchPriority==`string`?t.fetchPriority:void 0})}else i.d.m(e)}},e.requestFormReset=function(e){i.d.r(e)},e.unstable_batchedUpdates=function(e,t){return e(t)},e.useFormState=function(e,t,n){return l.H.useFormState(e,t,n)},e.useFormStatus=function(){return l.H.useHostTransitionStatus()},e.version=`19.3.1`})),h=s(((e,t)=>{function n(){if(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<`u`&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE==`function`)try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(n)}catch(e){console.error(e)}}n(),t.exports=m()})),g=s((e=>{var t=p(),n=d(),r=h();function i(e){var t=`https://react.dev/errors/`+e;if(1<arguments.length){t+=`?args[]=`+encodeURIComponent(arguments[1]);for(var n=2;n<arguments.length;n++)t+=`&args[]=`+encodeURIComponent(arguments[n])}return`Minified React error #`+e+`; visit `+t+` for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`}function a(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function o(e){for(var t=e,n=t;n&&!n.alternate;)t=n,t.flags&4098&&(e=t.return),n=t.return;for(;t.return;)t=t.return;return t.tag===3?e:null}function s(e){if(e.tag===13){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function c(e){if(e.tag===31){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function l(e){if(o(e)!==e)throw Error(i(188))}function u(e){var t=e.alternate;if(!t){if(t=o(e),t===null)throw Error(i(188));return t===e?e:null}for(var n=e,r=t;;){var a=n.return;if(a===null)break;var s=a.alternate;if(s===null){if(r=a.return,r!==null){n=r;continue}break}if(a.child===s.child){for(s=a.child;s;){if(s===n)return l(a),e;if(s===r)return l(a),t;s=s.sibling}throw Error(i(188))}if(n.return!==r.return)n=a,r=s;else{for(var c=!1,u=a.child;u;){if(u===n){c=!0,n=a,r=s;break}if(u===r){c=!0,r=a,n=s;break}u=u.sibling}if(!c){for(u=s.child;u;){if(u===n){c=!0,n=s,r=a;break}if(u===r){c=!0,r=s,n=a;break}u=u.sibling}if(!c)throw Error(i(189))}}if(n.alternate!==r)throw Error(i(190))}if(n.tag!==3)throw Error(i(188));return n.stateNode.current===n?e:t}function f(e){var t=e.tag;if(t===5||t===26||t===27||t===6)return e;for(e=e.child;e!==null;){if(t=f(e),t!==null)return t;e=e.sibling}return null}function m(e,t,n,r,i,a){for(;e!==null;){if((e.tag===5||e.tag===27||e.tag===6)&&n(e,r,i,a)||(e.tag!==22||e.memoizedState===null)&&(t||e.tag!==5&&e.tag!==27)&&m(e.child,t,n,r,i,a))return!0;e=e.sibling}return!1}function g(e){for(e=e.return;e!==null;){if(e.tag===3||e.tag===5||e.tag===27)return e;e=e.return}return null}function _(e){var t=!1;for(e=e.return;e!==null&&(e.tag===4&&(t=!0),e.tag!==3&&e.tag!==5&&e.tag!==27);)e=e.return;return t}function v(e){var t=[null,null],n=g(e);return n===null||y(t,e,n.child,{foundSelf:!1}),t}function y(e,t,n,r){for(;n!==null;){if(n===t)r.foundSelf=!0;else if(n.tag===5||n.tag===27||n.tag===6){if(r.foundSelf)return e[1]=n,!0;e[0]=n}else if((n.tag!==22||n.memoizedState===null)&&y(e,t,n.child,r))return!0;n=n.sibling}return!1}function b(e){switch(e.tag){case 5:case 27:case 6:return e.stateNode;case 3:return e.stateNode.containerInfo;default:throw Error(i(559))}}var x=null,S=null;function C(e,t,n){return e===n||e===t&&(x=e,!0)}function w(e,t,n){return e===n?(S=e,!1):e===t&&(S!==null&&(x=e),!0)}function T(e){if(e===null)return null;do e=e===null?null:e.return;while(e&&e.tag!==5&&e.tag!==27&&e.tag!==3);return e||null}function E(e,t,n){for(var r=0,i=e;i;i=n(i))r++;i=0;for(var a=t;a;a=n(a))i++;for(;0<r-i;)e=n(e),r--;for(;0<i-r;)t=n(t),i--;for(;r--;){if(e===t||t!==null&&e===t.alternate)return e;e=n(e),t=n(t)}return null}var D=Object.assign,O=Symbol.for(`react.element`),ee=Symbol.for(`react.transitional.element`),te=Symbol.for(`react.portal`),k=Symbol.for(`react.fragment`),ne=Symbol.for(`react.strict_mode`),A=Symbol.for(`react.profiler`),re=Symbol.for(`react.consumer`),j=Symbol.for(`react.context`),ie=Symbol.for(`react.forward_ref`),ae=Symbol.for(`react.suspense`),oe=Symbol.for(`react.suspense_list`),se=Symbol.for(`react.memo`),ce=Symbol.for(`react.lazy`),le=Symbol.for(`react.activity`),ue=Symbol.for(`react.legacy_hidden`),de=Symbol.for(`react.memo_cache_sentinel`),fe=Symbol.for(`react.view_transition`),M=Symbol.for(`react.recoverable`),pe=Symbol.iterator;function N(e){return typeof e!=`object`||!e?null:(e=pe&&e[pe]||e[`@@iterator`],typeof e==`function`?e:null)}var me=Symbol.for(`react.client.reference`);function he(e){if(e==null)return null;if(typeof e==`function`)return e.$$typeof===me?null:e.displayName||e.name||null;if(typeof e==`string`)return e;switch(e){case k:return`Fragment`;case A:return`Profiler`;case ne:return`StrictMode`;case ae:return`Suspense`;case oe:return`SuspenseList`;case le:return`Activity`;case fe:return`ViewTransition`}if(typeof e==`object`)switch(e.$$typeof){case te:return`Portal`;case j:return e.displayName||`Context`;case re:return(e._context.displayName||`Context`)+`.Consumer`;case ie:var t=e.render;return e=e.displayName,e||=(e=t.displayName||t.name||``,e===``?`ForwardRef`:`ForwardRef(`+e+`)`),e;case se:return t=e.displayName||null,t===null?he(e.type)||`Memo`:t;case ce:t=e._payload,e=e._init;try{return he(e(t))}catch{}}return null}var ge=Array.isArray,P=n.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,_e=r.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,ve={pending:!1,data:null,method:null,action:null},ye=[],be=-1;function xe(e){return{current:e}}function Se(e){0>be||(e.current=ye[be],ye[be]=null,be--)}function Ce(e,t){be++,ye[be]=e.current,e.current=t}var we=xe(null),Te=xe(null),Ee=xe(null),De=xe(null);function Oe(e,t){switch(Ce(Ee,t),Ce(Te,e),Ce(we,null),t.nodeType){case 9:case 11:e=(e=t.documentElement)&&(e=e.namespaceURI)?kp(e):0;break;default:if(e=t.tagName,t=t.namespaceURI)t=kp(t),e=Ap(t,e);else switch(e){case`svg`:e=1;break;case`math`:e=2;break;default:e=0}}Se(we),Ce(we,e)}function ke(){Se(we),Se(Te),Se(Ee)}function Ae(e){var t=e.memoizedState;t!==null&&(Eh._currentValue=t.memoizedState,Ce(De,e)),t=we.current;var n=Ap(t,e.type);t!==n&&(Ce(Te,e),Ce(we,n))}function je(e){Te.current===e&&(Se(we),Se(Te)),De.current===e&&(Se(De),Eh._currentValue=ve)}var Me,Ne;function Pe(e){if(Me===void 0)try{throw Error()}catch(e){var t=e.stack.trim().match(/\n( *(at )?)/);Me=t&&t[1]||``,Ne=-1<e.stack.indexOf(`
3
3
  at`)?` (<anonymous>)`:-1<e.stack.indexOf(`@`)?`@unknown:0:0`:``}return`
4
4
  `+Me+e+Ne}var Fe=!1;function Ie(e,t){if(!e||Fe)return``;Fe=!0;var n=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{var r={DetermineComponentFrameRoot:function(){try{if(t){var n=function(){throw Error()};if(Object.defineProperty(n.prototype,"props",{set:function(){throw Error()}}),typeof Reflect==`object`&&Reflect.construct){try{Reflect.construct(n,[])}catch(e){var r=e}Reflect.construct(e,[],n)}else{try{n.call()}catch(e){r=e}n=!1;try{var i=Object.getOwnPropertyDescriptor(e.prototype,`props`);Object.defineProperty(e.prototype,"props",{configurable:!0,set:function(){throw Error()}}),n=!0,new e}finally{n&&(i===void 0?delete e.prototype.props:Object.defineProperty(e.prototype,"props",i))}}}else{try{throw Error()}catch(e){r=e}(n=e())&&typeof n.catch==`function`&&n.catch(function(){})}}catch(e){if(e&&r&&typeof e.stack==`string`)return[e.stack,r.stack]}return[null,null]}};r.DetermineComponentFrameRoot.displayName=`DetermineComponentFrameRoot`;var i=Object.getOwnPropertyDescriptor(r.DetermineComponentFrameRoot,`name`);i&&i.configurable&&Object.defineProperty(r.DetermineComponentFrameRoot,"name",{value:`DetermineComponentFrameRoot`});var a=r.DetermineComponentFrameRoot(),o=a[0],s=a[1];if(o&&s){var c=o.split(`
@@ -17,8 +17,8 @@ Error generating stack: `+e.message+`
17
17
  `),n=Ie(t);if(n===-1)return;let r=t[n],i=/^(\s*)(flowchart|graph)([ \t]+(TD|TB|BT|LR|RL)\b)?(.*)$/i.exec(r);if(i!==null){let[,e,r,,a,o]=i,s=a===void 0?`TB`:Fe(a),c=Pe(s),l=[...t];return l[n]=`${e}${r} ${c}${o}`,{direction:s,turned:l.join(`
18
18
  `)}}let a=/^(\s*)stateDiagram(-v2)?\s*$/i.exec(r);if(a!==null)return Re(t,n,a[1])}function Re(e,t,n){let r=0;for(let n=t+1;n<e.length;n+=1){let t=e[n],i=r===0?/^\s*direction\s+(TD|TB|BT|LR|RL)\s*$/i.exec(t):null;if(i!==null){let r=Fe(i[1]),a=[...e];return a[n]=t.replace(/(direction\s+)(TD|TB|BT|LR|RL)/i,`$1${Pe(r)}`),{direction:r,turned:a.join(`
19
19
  `)}}r+=(t.match(/\{/g)?.length??0)-(t.match(/\}/g)?.length??0),r<0&&(r=0)}let i=[...e];return i.splice(t+1,0,`${n} direction LR`),{direction:`TB`,turned:i.join(`
20
- `)}}var ze=Promise.resolve();function Be(e){let t=ze.then(e,e);return ze=t.then(()=>void 0,()=>void 0),t}var Ve=`text-xs text-zinc-500 underline hover:text-zinc-800 dark:hover:text-zinc-200 disabled:opacity-50`,He=`flex flex-wrap items-center gap-3 text-xs`,Ue=null;async function We(e){let t=await(Ue??=ye(()=>import(`./mermaid.core-BMxNKlaY.js`).then(e=>e.t),__vite__mapDeps([2,1,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20])));return t.default.initialize({startOnLoad:!1,theme:e,look:`classic`,securityLevel:`strict`,suppressErrorRendering:!0}),t}function Ge(e){let t=/viewBox="\s*[\d.-]+[\s,]+[\d.-]+[\s,]+([\d.]+)[\s,]+([\d.]+)/.exec(e),n=t?Number(t[1]):NaN;return Number.isFinite(n)&&n>0?n:void 0}function Ke(e,t){if(typeof e!=`object`||!e||!(`props`in e))return null;let n=e.props;if(t!==void 0&&!RegExp(`\\blanguage-${t}\\b`).test(n.className??``))return null;let r=n.children;return typeof r==`string`?r:Array.isArray(r)&&r.every(e=>typeof e==`string`)?r.join(``):null}function qe(e){let t=Ke(e,`mermaid`);return t===null?null:t.trim()}function Je(e){let{children:t,...n}=e,r=qe(t);if(r!==null)return(0,N.jsx)(Ye,{code:r});let i=Ke(t);return i===null?(0,N.jsx)(`pre`,{...n,children:t}):(0,N.jsxs)(`div`,{className:`code-block relative`,"data-testid":`code-block`,children:[(0,N.jsx)(`pre`,{...n,children:t}),(0,N.jsx)(me,{iconOnly:!0,text:i.replace(/\n$/,``),className:`absolute right-1.5 top-1.5 rounded border border-zinc-300 bg-white/80 px-1.5 py-0.5 text-xs text-zinc-500 hover:text-zinc-800 dark:border-zinc-700 dark:bg-zinc-900/80 dark:text-zinc-400 dark:hover:text-zinc-100`})]})}function Ye({code:e}){let t=(0,v.useId)().replace(/[^a-zA-Z0-9]/g,``),n=x()===`light`?`default`:`dark`,[r,i]=(0,v.useState)(null),[a,o]=(0,v.useState)(null),[s,c]=(0,v.useState)(!1),[l,u]=(0,v.useState)(!1),[d,f]=(0,v.useState)(!1),[p,m]=(0,v.useState)(null),h=(0,v.useRef)(!1),g=(0,v.useRef)(0),_=(0,v.useRef)(0),y=()=>`mermaid-${t}-${++_.current}`,b=(0,v.useMemo)(()=>Le(e),[e]),S=b===void 0?`landscape`:Ne(b.direction),[C,w]=(0,v.useState)(void 0),T=r?.svg??null,E=r!==null&&r.orientation!==S,D=(0,v.useRef)(null),O=(0,v.useRef)(e);O.current=e,(0,v.useEffect)(()=>(g.current+=1,i(null),w(void 0),u(!1),o(null),m(null),()=>{g.current+=1}),[e]);async function ee(){if(!r||h.current)return;h.current=!0,f(!0),m(null);let e=g.current;try{let{renderDiagram:n}=await ye(async()=>{let{renderDiagram:e}=await import(`./mermaidToImage-BuA9Xm_J.js`).then(e=>e.r);return{renderDiagram:e}},__vite__mapDeps([21,1])),i=await n(r.source,`mermaid-download-${t}`);if(e!==g.current)return;let a=URL.createObjectURL(new Blob([i.svg],{type:`image/svg+xml;charset=utf-8`}));try{let e=document.createElement(`a`);e.href=a,e.download=`diagram.svg`,e.click()}finally{URL.revokeObjectURL(a)}}catch(t){e===g.current&&m(t instanceof Error?t.message:String(t))}finally{h.current=!1,f(!1)}}return(0,v.useEffect)(()=>{let e=!1,t=setTimeout(()=>void Be(async()=>{try{let t=(await We(n)).default,r=O.current,a=Le(r),s=a===void 0?`landscape`:Ne(a.direction);if(C!==void 0&&a!==void 0){let n=C===s?r:a.turned,{svg:c}=await t.render(y(),n);e||(i({svg:c,orientation:C,source:n}),o(null));return}let c=await t.render(y(),r),l={svg:c.svg,orientation:s,source:r},u=Ge(c.svg);if(a!==void 0&&u!==void 0&&u>710){let e=await t.render(y(),a.turned),n=Ge(e.svg);if(n!==void 0){let t=s===`landscape`?je(u,n):je(n,u);t!==s&&(l={svg:e.svg,orientation:t,source:a.turned})}}e||(i(l),o(null))}catch(t){e||(i(null),o(t instanceof Error?t.message:String(t)))}}),300);return()=>{e=!0,clearTimeout(t)}},[e,t,n,C]),T?(0,N.jsxs)(`div`,{ref:D,className:`my-2 flex flex-col gap-2 rounded-lg border border-zinc-200 bg-zinc-50 p-3 dark:border-zinc-800 dark:bg-zinc-900`,children:[(0,N.jsxs)(`div`,{className:`${He} order-3`,children:[(0,N.jsx)(`button`,{type:`button`,onClick:()=>c(!s),title:s?`Show diagram`:`Show code`,className:Ve,children:s?`⚏ diagram`:`⌗ code`}),!s&&b!==void 0&&r!==null&&(0,N.jsx)(`button`,{type:`button`,"data-testid":`mermaid-orientation`,onClick:()=>w(e=>Ae(e??r.orientation)),title:r.orientation===`portrait`?`Turn it across the page — it is drawn down`:`Turn it down the page — it is drawn across`,"aria-label":`Turn the diagram ${Ae(r.orientation)}`,className:`text-xs text-zinc-500 underline hover:text-zinc-800 dark:hover:text-zinc-200 disabled:opacity-50`,children:r.orientation===`portrait`?`↔ landscape`:`↕ portrait`}),!s&&(0,N.jsx)(`button`,{type:`button`,onClick:()=>u(!0),"aria-label":`Show diagram at full size`,className:`text-xs text-zinc-500 underline hover:text-zinc-800 dark:hover:text-zinc-200 disabled:opacity-50`,children:`⤢ enlarge`}),(0,N.jsx)(`button`,{type:`button`,className:Ve,disabled:d,onClick:()=>void ee(),title:`Save as .svg — insert it as a picture in a document`,children:d?`preparing SVG…`:`⤓ download SVG`}),(0,N.jsx)(me,{text:e,className:Ve}),p&&(0,N.jsxs)(`span`,{role:`alert`,className:`text-red-600 dark:text-red-400`,children:[`Could not download SVG: `,p]})]}),s?(0,N.jsx)(`pre`,{className:`overflow-x-auto font-mono text-xs text-zinc-500 dark:text-zinc-400`,children:e}):(0,N.jsx)(`div`,{className:`flex justify-center overflow-x-auto [&_svg]:max-w-full`,dangerouslySetInnerHTML:{__html:T}}),E&&!s&&(0,N.jsxs)(`div`,{className:`mt-1 text-center text-xs text-zinc-400 dark:text-zinc-600`,"data-testid":`mermaid-turned`,children:[`drawn `,r?.orientation,` to fit — the source asks for `,S]}),(0,N.jsx)(Oe,{label:`diagram`,testId:`mermaid-enlarged`,open:l,onClose:()=>u(!1),anchorRef:D,actions:(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`button`,{type:`button`,className:Ve,disabled:d,onClick:()=>void ee(),children:d?`preparing SVG…`:`⤓ download SVG`}),p&&(0,N.jsxs)(`span`,{role:`alert`,className:`text-red-600 dark:text-red-400`,children:[`Could not download SVG: `,p]})]}),children:(0,N.jsx)(`div`,{style:{width:Ge(T)},className:`[&_svg]:!h-auto [&_svg]:!max-w-none [&_svg]:!w-full`,dangerouslySetInnerHTML:{__html:T}})})]}):(0,N.jsxs)(`pre`,{className:`my-2 overflow-x-auto rounded-lg border border-zinc-200 bg-zinc-50 p-3 font-mono text-xs text-zinc-500 dark:border-zinc-800 dark:bg-zinc-900 dark:text-zinc-400`,children:[e,a&&(0,N.jsx)(`div`,{className:`mt-2 text-red-600 dark:text-red-400`,children:a})]})}function Xe({html:e,className:t=``,as:n=`div`}){return(0,N.jsx)(n,{className:`rendered-ansi overflow-x-auto font-mono text-xs leading-relaxed [&_span]:whitespace-pre-wrap ${t}`,dangerouslySetInnerHTML:{__html:e}})}function Ze({lines:e,fill:t=!1}){return(0,N.jsx)(`div`,{className:`overflow-auto rounded border border-zinc-200 font-mono text-xs leading-relaxed dark:border-zinc-800 ${t?`max-h-full`:`max-h-72`}`,children:k(te(e)).map((e,t)=>e===null?(0,N.jsx)(`div`,{className:`bg-zinc-100 px-2 text-center text-zinc-400 dark:bg-zinc-800/60 dark:text-zinc-600`,children:`⋯`},t):(0,N.jsxs)(`div`,{className:`grid grid-cols-2`,children:[(0,N.jsx)(`div`,{className:`whitespace-pre-wrap break-words border-r border-zinc-200 px-2 dark:border-zinc-800 ${e.changed?e.left===null?`bg-zinc-50 dark:bg-zinc-900/40`:`bg-red-50 text-red-700 dark:bg-red-950/40 dark:text-red-300`:`text-zinc-500 dark:text-zinc-500`}`,children:e.left??` `}),(0,N.jsx)(`div`,{className:`whitespace-pre-wrap break-words px-2 ${e.changed?e.right===null?`bg-zinc-50 dark:bg-zinc-900/40`:`bg-emerald-50 text-emerald-800 dark:bg-emerald-950/40 dark:text-emerald-300`:`text-zinc-500 dark:text-zinc-500`}`,children:e.right??` `})]},t))})}function Qe({lines:e}){return(0,N.jsx)(`pre`,{className:`max-h-72 overflow-auto rounded border border-zinc-200 font-mono text-xs leading-relaxed dark:border-zinc-800`,children:ne(e).map((e,t)=>e===null?(0,N.jsx)(`div`,{className:`bg-zinc-100 px-2 text-center text-zinc-400 dark:bg-zinc-800/60 dark:text-zinc-600`,children:`⋯`},t):(0,N.jsxs)(`div`,{className:e.type===`add`?`bg-emerald-50 px-2 text-emerald-800 dark:bg-emerald-950/40 dark:text-emerald-300`:e.type===`del`?`bg-red-50 px-2 text-red-700 dark:bg-red-950/40 dark:text-red-300`:`px-2 text-zinc-500 dark:text-zinc-500`,children:[e.type===`add`?`+ `:e.type===`del`?`− `:` `,e.text]},t))})}function $e({item:e,canEdit:t,onEdit:n}){let[r,i]=(0,v.useState)(null),a=(0,v.useRef)(null),o=t&&e.entryId!==void 0,s=r!==null;(0,v.useEffect)(()=>{s&&a.current?.focus()},[s]),(0,v.useEffect)(()=>{i(null)},[e.entryId,e.text]);function c(){let a=r?.trim();t&&e.entryId&&a&&(a===e.text||n(e.entryId,a,e.images),i(null))}return(0,N.jsxs)(`div`,{className:`group ml-auto flex max-w-[85%] items-start gap-1.5`,children:[o&&!s&&(0,N.jsx)(`button`,{type:`button`,onClick:()=>i(e.text),title:`edit this prompt and ask again (branches the conversation)`,"aria-label":`Edit this prompt`,className:`mt-1.5 shrink-0 rounded px-1 py-0.5 text-xs text-zinc-400 opacity-0 hover:bg-zinc-200 hover:text-zinc-700 focus-visible:opacity-100 group-hover:opacity-100 dark:text-zinc-500 dark:hover:bg-zinc-700 dark:hover:text-zinc-200`,children:`✎`}),(0,N.jsxs)(`div`,{className:`min-w-0 flex-1 rounded-xl bg-blue-100 px-4 py-2 text-[15px] text-blue-950 dark:bg-blue-950/60 dark:text-zinc-100`,children:[e.images&&e.images.length>0&&(0,N.jsx)(`div`,{className:`mb-1.5 flex flex-wrap gap-1.5`,children:e.images.map((e,t)=>(0,N.jsx)(`img`,{src:`data:${e.mimeType};base64,${e.data}`,alt:``,className:`max-h-48 max-w-full rounded-lg object-contain`},t))}),s?(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`textarea`,{ref:a,value:r,"aria-label":`Edit prompt`,onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),c()),e.key===`Escape`&&i(null)},rows:Math.min(10,Math.max(2,r.split(`
21
- `).length)),className:`w-full resize-none rounded-md bg-white/70 px-2 py-1 text-[15px] outline-none ring-1 ring-blue-300 dark:bg-zinc-900/60 dark:ring-blue-900`}),(0,N.jsxs)(`div`,{className:`mt-1.5 flex items-center justify-end gap-2 text-xs`,children:[(0,N.jsx)(`span`,{className:`mr-auto text-blue-900/70 dark:text-zinc-400`,children:t?`asks again from here — the current answer moves to its own branch`:`waiting: the agent is running (or the connection dropped)`}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>i(null),className:`rounded border border-blue-300 px-2 py-0.5 hover:bg-white/60 dark:border-zinc-700 dark:hover:bg-zinc-800`,children:`cancel`}),(0,N.jsx)(`button`,{type:`button`,onClick:c,disabled:!t||!r.trim()||r.trim()===e.text,className:`rounded border border-blue-400 bg-white/70 px-2 py-0.5 font-medium disabled:opacity-50 dark:border-blue-800 dark:bg-zinc-900/60`,children:`send`})]})]}):(0,N.jsx)(`div`,{className:`whitespace-pre-wrap`,children:e.text})]})]})}var et=`urn:structured-exchange:1`,tt=[`graph`,`sequence`];function nt(e){return rt(e)?[`graph`,`sequence`,`table`]:tt}function rt(e){return e===`urn:structured-exchange:2`||e===`urn:structured-exchange:3`}function it(e){if(Array.isArray(e))return{cells:e};let t=e.heading;return typeof t==`string`?{cells:[],role:e.role,heading:t}:{cells:e.cells,role:e.role}}var at={nodes:500,edges:2e3,participants:100,messages:1e3,columns:50,rows:5e3,removals:500,ref:200,localId:200,label:500,kind:100,kindsPerVocabulary:64,columnName:200,cell:1e3},ot=`urn:structured-exchange:2`,st={profile:200,attributesPerItem:50,removeAttributesPerItem:50,attributeName:200,attributeString:1e3,attributeListItems:50,revision:200,locationsPerItem:10,uri:2e3,position:1e6,artifactsPerItem:20,artifactsPerDocument:50,artifactRel:100,artifactMediaType:100,artifactLabel:500,artifactDigest:71,relations:2e3,heading:500,headingDepth:6,viewpoints:20,viewpointConcern:500},ct=8e6,lt=`urn:structured-exchange:3`,ut=[et,ot,lt];function dt(e){return ut.find(t=>t===e)}var ft=4e6,pt=Math.max(ft,ct);function mt(e){return rt(e)?ct:ft}var ht=e=>new TextEncoder().encode(e).length;function gt(e){return e===`bytes`?pt:e===`relations`?st.relations:at[e]}function _t(e,t){let n=gt(e),r=t?.[e];return r===void 0||r>=n?{limit:n,level:`ceiling`}:{limit:r,level:`deployment`}}function vt(e,t,n){let r=ht(e),i=_t(`bytes`,t),a=n===void 0?1/0:mt(n),o=Math.min(i.limit,a),s=o===a&&a<i.limit?`ceiling`:i.level;if(!(r<=o))return{rule:`document-too-large`,path:``,message:`document is ${r} bytes, past the ${o}-byte ${s===`ceiling`?`contract ceiling`:`limit this deployment applies`}`,limit:o,observed:r,level:s}}var yt={graph:[`nodes`,`edges`],sequence:[`participants`,`messages`],table:[`columns`,`rows`,`relations`]};function bt(e,t){if(t===void 0)return[];let n=[];for(let r of yt[e.kind]??[]){let i=e.data[r];if(!Array.isArray(i))continue;let{limit:a,level:o}=_t(r,t);o===`deployment`&&i.length>a&&n.push({rule:`collection-past-deployment-limit`,path:`/data/${r}`,message:`${r} has ${i.length} entries, past the ${a} this deployment allows`,limit:a,observed:i.length,level:o})}return n}function xt(e,t){let n={};for(let t of yt[e.kind]??[]){let r=e.data[t];Array.isArray(r)&&(n[t]=r.length)}return{kind:e.kind,bytes:ht(t),counts:n}}var St=6.6,Ct=5.4;function wt(e,t,n){let r=e.flatMap(e=>e.split(/\r?\n/)).reduce((e,t)=>Math.max(e,t.length),0);return Math.min(Math.max(r*St+22,t),n)}function Tt(e,t,n,r){let i=t.map(e=>kt(e).length).reduce((e,t)=>Math.max(e,t),0);return Math.max(wt(e,n,r),Math.min(i*Ct+22,r))}function Et(e,t,n=St){let r=Math.max(Math.floor((t-22)/n+1e-6),4),i=[],a=e.split(/\r?\n/);if(a.length>1)return a.flatMap(e=>Et(e,t,n)).slice(0,3);let o=``;for(let t of e.split(/\s+/)){let e=o===``?t:`${o} ${t}`;if(e.length<=r)o=e;else for(o!==``&&i.push(o),o=t;o.length>r&&i.length<3;)i.push(o.slice(0,r)),o=o.slice(r)}if(o!==``&&i.push(o),i.length===0)return[``];if(i.length<=3)return i;let s=i.slice(0,3);return s[2]=`${s[2].slice(0,Math.max(r-1,1))}…`,s}function Dt(e,t){return e*15+t*15+14}function Ot(e,t){return e.flatMap(e=>Et(kt(e),t,Ct))}function kt(e){return`${e.field}: ${e.from===void 0?``:`${e.from} → `}${e.to}`}function At(e,t){return`${e}: ${jt(t)}`}function jt(e){return Array.isArray(e)?e.map(e=>jt(e)).join(`, `):e===null?`null`:typeof e==`object`&&e&&typeof e.ref==`string`?`<${e.ref}>`:String(e)}function Mt(e){let t=e.range===void 0?``:` lines ${e.range.startLine}–${e.range.endLine}`,n=e.revision===void 0?``:` at ${e.revision}`;return`${e.uri}${t}${n}`}function Nt(e){let t=e.label===void 0?e.uri:`${e.label} (${e.uri})`,n=e.mediaType===void 0?``:`, ${e.mediaType}`;return`${e.rel}: ${t}${n} — ${e.sha256.slice(0,14)}…`}var Pt=864e5,Ft=/^(\d{4})-(\d{2})-(\d{2})$/;function It(e){let t=Ft.exec(e);if(t===null)return;let[n,r,i]=[Number(t[1]),Number(t[2]),Number(t[3])],a=new Date(Date.UTC(n,r-1,i));if(a.setUTCFullYear(n,r-1,i),a.getUTCFullYear()===n&&a.getUTCMonth()===r-1&&a.getUTCDate()===i)return Math.round(a.getTime()/Pt)}function Lt(e){let t=new Date(e*Pt);return`${String(t.getUTCFullYear()).padStart(4,`0`)}-${String(t.getUTCMonth()+1).padStart(2,`0`)}-${String(t.getUTCDate()).padStart(2,`0`)}`}function Rt(e=new Date){return Math.round(Date.UTC(e.getFullYear(),e.getMonth(),e.getDate())/Pt)}function zt(e){let t=It(e.type===`activity`?e.start:e.date),n=It(e.type===`activity`?e.end:e.date);return t===void 0||n===void 0?void 0:{start:t,end:n}}function Bt(e){let t=new Map;return e.rows.forEach((e,n)=>{e.type===`task`&&(t.has(e.id)||t.set(e.id,{id:e.id,type:`task`,row:n,days:Vt(e)}),e.items.forEach((e,r)=>{e.id===void 0||t.has(e.id)||t.set(e.id,{id:e.id,type:e.type,row:n,item:r,days:zt(e)})}))}),t}function Vt(e){let t;for(let n of e.items){let e=zt(n);e!==void 0&&(t=t===void 0?{...e}:{start:Math.min(t.start,e.start),end:Math.max(t.end,e.end)})}return t}function Ht(e){return e.type??`finish-to-start`}function Ut(e){return{from:e.startsWith(`finish`)?`end`:`start`,to:e.endsWith(`finish`)?`end`:`start`}}function Wt(e,t){let n=t.get(e.from)?.days,r=t.get(e.to)?.days;if(n===void 0||r===void 0)return;let i=Ut(Ht(e));return r[i.to]>=n[i.from]}function Gt(e){if(`date`in e){let t=It(e.date)??0;return{start:t,end:t}}return{start:It(e.start)??0,end:It(e.end)??0}}function Kt(e){if(e.previous===void 0)return;let t=Gt(e.type===`activity`?{start:e.start,end:e.end}:{date:e.date}),n=Gt(e.previous);return{start:t.start-n.start,end:t.end-n.end}}function qt(e){if(e===0)return``;let t=e>0?`+`:`−`,n=Math.abs(e);return n<14?`${t}${n}d`:n<70?`${t}${Math.round(n/7)}w`:`${t}${Math.round(n/30.44)}mo`}function Jt(e){let t=Kt(e);return t===void 0?``:t.start===t.end?qt(t.start):t.start===0?`end${qt(t.end)}`:t.end===0?`start${qt(t.start)}`:`${qt(t.start)}, end${qt(t.end)}`}function Yt(e,t){if(e.role!==void 0||t?.role!==void 0)return!0;let n=Kt(e);return n!==void 0&&(n.start!==0||n.end!==0)}function Xt(e){return e.role!==void 0||e.items.some(t=>Yt(t,e))}var Zt={week:12,month:4,quarter:.75};function Qt(e,t){let n=e>=8?`week`:e>=1?`month`:`quarter`;if(t===void 0)return n;let r=[`week`,`month`,`quarter`];return r[Math.max(r.indexOf(n),r.indexOf(t))]}var $t=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`];function en(e){return e.width>=24?e.label:e.width>=9?e.label.charAt(0):``}function tn(e,t){return t===`month`?en(e):e.width>=e.label.length*6+4?e.label:``}function nn(e){return((e+3)%7+7)%7}function rn(e){let t=e-nn(e)+3,n=new Date(t*Pt).getUTCFullYear();return Math.floor((t-cn(n,0))/7)+1}function an(e){if(e.label!==void 0&&e.label!==``)return e.label;if(e.type===`milestone`&&e.kind!==void 0&&e.kind!==``)return e.kind}function on(e){return e.length*St}function sn(e,t){let n=new Date(e*Pt),r=n.getUTCFullYear(),i=n.getUTCMonth(),a=[];for(;;){i+=1,i===12&&(i=0,r+=1);let e=cn(r,i);if(e>t)return a;a.push({day:e,year:r,month:i})}}function cn(e,t){let n=new Date(0);return n.setUTCFullYear(e,t,1),Math.round(n.getTime()/Pt)}function ln(e,t){let n=e=>e===`bar`||e===`ghost`;return n(e)&&t===`star`||e===`star`&&n(t)}function un(e,t){return e.x0<t.x1&&t.x0<e.x1}function dn(e,t){if(t<=0||e.width<=t)return;let n=e.items.filter(e=>e.change!==void 0);if(n.length>0){let e=Math.min(...n.flatMap(e=>e.ghost===void 0?[e.glyph.x]:[e.glyph.x,e.ghost.x]));return e<t*.9?void 0:Math.max(0,e-t/6)}if(`x`in e.today&&e.today.x>t*.8)return Math.max(0,e.today.x-t/3)}function fn(e,t,n={}){let r=It(e.time.start)??0,i=It(e.time.end)??r,a=n.pxPerDay??Zt[e.time.scale]??4,o=(i-r+1)*a,s=e=>(e-r)*a,c=sn(r,i),l=new Date(r*Pt),u=[{day:r,year:l.getUTCFullYear(),month:l.getUTCMonth()},...c],d=u.map((e,t)=>{let n=t+1<u.length?u[t+1].day:i+1;return{label:$t[e.month],x:s(e.day),width:(n-e.day)*a,year:e.year,month:e.month}}),f=[];u.forEach((e,t)=>{let n=d[t],r=f[f.length-1];r!==void 0&&r.label===String(e.year)?r.width+=n.width:f.push({label:String(e.year),x:n.x,width:n.width})});let p=Qt(a,n.unit),m=(e,t)=>e.map((n,r)=>{let o=r+1<e.length?e[r+1]:i+1;return{label:t(n),x:s(n),width:(o-n)*a}}),h=f,g;if(p===`week`){let e=[];for(let t=r-nn(r)+7;t<=i;t+=7)e.push(t);g=m([r,...e],e=>`W${rn(e)}`),h=d.map(e=>({label:`${e.label} ${e.year}`,x:e.x,width:e.width}))}else if(p===`quarter`){let e=u.filter((e,t)=>t===0||e.month%3==0);g=e.map((t,n)=>{let r=n+1<e.length?e[n+1].day:i+1;return{label:`Q${Math.floor(t.month/3)+1}`,x:s(t.day),width:(r-t.day)*a}})}else g=d;let _=g.slice(1).map(e=>e.x),v=[],y=[],b=0,x=e.comparedTo!==void 0,S=(e,t)=>{if(!x)return;if(e.role===`added`||t.role===`added`)return`(new)`;let n=Jt(e);return n===``?void 0:`(${n})`},C=(e,t,n)=>{let r=S(e,t);return r===void 0?n:n===void 0?r:`${n} ${r}`},w=(e,t)=>{if(x)return e.role===`removed`||t.role===`removed`?`removed`:e.role===`added`||t.role===`added`?`added`:Jt(e)===``?void 0:`moved`},T=(e,t)=>{let n=[],r=[],i=[],c=e.map(e=>({...e,days:zt(e.item)})).filter(e=>e.days!==void 0).sort((e,t)=>Number(e.item.type===`milestone`)-Number(t.item.type===`milestone`)||e.days.start-t.days.start||e.row-t.row||e.index-t.index);for(let{item:e,index:t,row:l,days:u,text:d,note:f,change:p}of c){let c=[],m;if(p===`moved`&&e.previous!==void 0){let t=Gt(e.previous);if(e.type===`activity`)m={x0:s(t.start),x1:s(t.end+1)};else{let e=s(t.start)+a/2;m={x0:e-7,x1:e+7,cx:e}}c.push({kind:`ghost`,x0:m.x0,x1:m.x1})}let h,g,_,v;if(e.type===`activity`){if(g=s(u.start),_=s(u.end+1),c.push({kind:`bar`,x0:g,x1:_}),d!==void 0){let e=on(d);h=e+12<=_-g?{text:d,inside:!0,x:g+6,width:e}:pn(d,g,_,o),f!==void 0&&(h.note=f),c.push({kind:`label`,x0:h.x,x1:h.x+h.width})}}else v=s(u.start)+a/2,g=v-7,_=v+7,c.push({kind:`star`,x0:g,x1:_}),d!==void 0&&(h=pn(d,g,_,o),f!==void 0&&(h.note=f),c.push({kind:`label`,x0:h.x,x1:h.x+h.width}));let y=n.findIndex(e=>c.every(t=>e.every(e=>ln(t.kind,e.kind)||!un(t,e))));y===-1&&(y=n.length,n.push([])),n[y].push(...c),r.push({row:l,item:t,type:e.type,lane:y,days:u,...e.kind?{kind:e.kind}:{},...p===void 0?{}:{change:p}}),i.push({label:h===void 0?void 0:{...h,...p===`removed`?{struck:!0}:{}},x0:g,x1:_,cx:v,ghost:m})}return r.forEach((e,n)=>{let r=i[n],a=t+4+e.lane*24+12,o=e.type===`activity`?{x:r.x0,y:a-6,width:r.x1-r.x0,height:12}:{x:r.x0,y:a-7,width:14,height:14},s=r.ghost;y.push({...e,glyph:o,...r.cx===void 0?{}:{center:{x:r.cx,y:a}},...r.label===void 0?{}:{label:{...r.label,y:a-8,height:16}},...s===void 0?{}:e.type===`activity`?{ghost:{x:s.x0,y:a-6,width:s.x1-s.x0,height:12}}:{ghost:{x:s.x0,y:a-7,width:14,height:14},ghostCenter:{x:s.cx,y:a}}})}),Math.max(1,n.length)},E=e=>e*24+8,D=(e,t)=>{let n=T(e.items.map((n,r)=>({row:t,index:r,item:n,text:C(n,e,an(n)),note:S(n,e),change:w(n,e)})),b),r=E(n);v.push({type:`task`,row:t,y:b,height:r,lanes:n,label:e.label,id:e.id}),b+=r},O,ee=()=>{if(O!==void 0){if(O.tasks.length===0){let e=O.label?26:10;v.push({type:`separator`,row:O.row,y:b,height:e,...O.label?{label:O.label}:{}}),b+=e}else{let e=T(O.tasks.flatMap(({task:e,row:t})=>e.items.map((n,r)=>({row:t,index:r,item:n,text:C(n,e,an(n)??(n.type===`activity`?e.label:void 0)),note:S(n,e),change:w(n,e)}))),b),t=E(e);v.push({type:`section`,row:O.row,y:b,height:t,lanes:e,...O.label?{label:O.label}:{},tasks:O.tasks.map(({task:e})=>e.id)}),b+=t}O=void 0}},te=(()=>{let t=new Set;if(!(n.onlyChanged&&x))return;let r;return e.rows.forEach((e,n)=>{e.type===`separator`?r=n:Xt(e)&&(t.add(n),r!==void 0&&t.add(r))}),t})(),k=te===void 0?0:e.rows.filter((e,t)=>e.type===`task`&&!te.has(t)).length;e.rows.forEach((e,t)=>{if(te===void 0||te.has(t)){if(e.type===`separator`){if(n.compact){ee(),O={row:t,...e.label?{label:e.label}:{},tasks:[]};return}let r=e.label?26:10;v.push({type:`separator`,row:t,y:b,height:r,...e.label?{label:e.label}:{}}),b+=r}else O===void 0?D(e,t):O.tasks.push({task:e,row:t})}}),ee();let ne=[];for(let t of e.rows)if(t.type===`task`)for(let e of t.items)e.kind&&!ne.includes(e.kind)&&ne.push(e.kind);for(let t of[...e.periods??[],...e.references??[]])t.kind&&!ne.includes(t.kind)&&ne.push(t.kind);let A=[];(e.periods??[]).forEach((e,t)=>{let n=Math.max(It(e.start)??r,r),o=Math.min(It(e.end)??i,i);n>o||A.push({index:t,x:s(n),width:(o-n+1)*a,start:e.start,end:e.end,...e.label?{label:e.label}:{},...e.kind?{kind:e.kind}:{}})});let re=(e.references??[]).flatMap((e,t)=>{let n=It(e.date);return n===void 0||n<r||n>i?[]:[{index:t,x:s(n)+a/2,label:e.label,date:e.date,...e.kind?{kind:e.kind}:{}}]}),j=[];if(t>=r&&t<=i){let e=s(t)+a/2;j.push({x0:e-26,x1:e+26})}let ie=[],ae=[...A.filter(e=>e.label).map(e=>({of:`period`,index:e.index,text:e.label,x:e.x+3,room:e.width-6})),...re.map(e=>{let t=on(e.label)*(10/11);return{of:`reference`,index:e.index,text:e.label,x:Math.min(Math.max(2,e.x-t/2),o-t-2),room:o-4}})].sort((e,t)=>e.x-t.x);for(let e of ae){let t=on(e.text)*(10/11);if(t>e.room)continue;let n={x0:e.x-2,x1:e.x+t+2};j.some(e=>n.x0<e.x1&&e.x0<n.x1)||(j.push(n),ie.push({of:e.of,index:e.index,text:e.text,x:e.x,width:t}))}return{width:o,height:b,start:r,end:i,years:f,months:d,monthLines:c.map(e=>s(e.day)),unit:p,upper:h,lower:g,unitLines:_,rows:v,items:y,dependencies:mn(e,v,y,s),today:t<r?{outside:`before`,day:t}:t>i?{outside:`after`,day:t}:{x:s(t)+a/2,day:t},kinds:ne,hiddenTasks:k,periods:A,references:re,headerLabels:ie}}function pn(e,t,n,r){let i=on(e),a=n+4;if(a+i<=r)return{text:e,inside:!1,x:a,width:i};let o=t-4-i;return o>=0?{text:e,inside:!1,x:o,width:i}:{text:e,inside:!1,x:Math.max(0,r-i),width:i}}function mn(e,t,n,r){let i=Bt(e),a=new Map(n.map(e=>[`${e.row}:${e.item}`,e])),o=new Map(t.map(e=>[e.row,e])),s=(e,t)=>{let s=i.get(e);if(s?.days===void 0)return;if(s.item!==void 0){let e=a.get(`${s.row}:${s.item}`);if(e===void 0)return;let n=e.glyph.y+e.glyph.height/2;return e.center===void 0?{x:t===`start`?e.glyph.x:e.glyph.x+e.glyph.width,y:n}:{x:e.center.x+(t===`start`?-7:7),y:n}}let c=r(t===`start`?s.days.start:s.days.end+1),l=o.get(s.row);if(l!==void 0&&l.type===`task`)return{x:c,y:l.y+4+12};let u=n.filter(e=>e.row===s.row).sort((e,n)=>t===`start`?e.glyph.x-n.glyph.x:n.glyph.x+n.glyph.width-(e.glyph.x+e.glyph.width));if(u.length!==0)return{x:c,y:u[0].glyph.y+u[0].glyph.height/2}},c=[];return(e.dependencies??[]).forEach((e,t)=>{let n=Ht(e),r=Ut(n),a=s(e.from,r.from),o=s(e.to,r.to),l=Wt(e,i);if(a===void 0||o===void 0||l===void 0)return;let u={x:a.x+(r.from===`end`?8:-8),y:a.y},d={x:o.x+(r.to===`start`?-8:8),y:o.y};if(a.y===o.y&&r.from===`end`&&r.to===`start`&&o.x>=a.x-14){c.push({index:t,from:e.from,to:e.to,type:n,satisfied:l,points:[a,o]});return}let f=o.y>a.y?o.y-12:(o.y,a.y,o.y+12);c.push({index:t,from:e.from,to:e.to,type:n,satisfied:l,points:[a,u,{x:u.x,y:f},{x:d.x,y:f},d,o]})}),c}function hn(e){let t=e.rows.reduce((e,t)=>Math.max(e,(t.label??``).length),0);return Math.min(Math.max(t*St+24,120),280)}function gn(e,t){for(let n of e.rows){if(n.type!==`task`)continue;if(n.id===t)return`"${n.label}" (${t})`;let e=n.items.find(e=>e.id===t);if(e!==void 0){let n=an(e);return n===void 0?t:`"${n}" (${t})`}}return t}function _n(e,t,n){let r=n===!1?` — not satisfied by the dates`:``;return`${gn(e,t.to)} waits on ${gn(e,t.from)} (${Ht(t)})${r}`}function vn(e){let t=[];e.title!==void 0&&e.title!==``&&t.push(e.title),e.comparedTo!==void 0&&t.push(`Compared with ${e.comparedTo.label}${e.comparedTo.date===void 0?``:` (${e.comparedTo.date})`}`),t.push(`From ${e.time.start} to ${e.time.end}, by ${e.time.scale}`);for(let n of e.rows){if(t.push(``),n.type===`separator`){t.push(n.label?`— ${n.label} —`:`———`);continue}let e=n.role===void 0?``:n.role===`added`?` — new`:` — removed`;t.push(`${n.label} [${n.id}]${n.items.length===0?` — no items`:``}${e}`);for(let e of n.items){let n=e.type===`activity`?`${e.start} to ${e.end}`:e.date,r=e.label===void 0?``:`: ${e.label}`,i=e.kind===void 0?``:` [${e.kind}]`,a=e.id===void 0?``:` (${e.id})`,o=(()=>{if(e.role===`added`)return` — new`;if(e.role===`removed`)return` — removed`;let t=Jt(e);return t===``||e.previous===void 0?``:` — moved ${t}, was ${`date`in e.previous?e.previous.date:`${e.previous.start} to ${e.previous.end}`}`})();t.push(` ${e.type} ${n}${r}${i}${a}${o}`)}}let n=[...(e.periods??[]).map(e=>` period ${e.start} to ${e.end}${e.label?`: ${e.label}`:``}${e.kind?` [${e.kind}]`:``}`),...(e.references??[]).map(e=>` reference ${e.date}: ${e.label}${e.kind?` [${e.kind}]`:``}`)];n.length>0&&t.push(``,`Calendar`,...n);let r=e.dependencies??[];if(r.length>0){let n=Bt(e);t.push(``,`Dependencies`);for(let i of r)t.push(` ${_n(e,i,Wt(i,n))}`)}return t}function yn(e){let t=[],n=(e,n)=>{let r=It(e);return r===void 0&&t.push({rule:`invalid-date`,path:n,message:`"${e}" is not a day of the calendar`}),r},r=n(e.time.start,`/data/time/start`),i=n(e.time.end,`/data/time/end`),a=r!==void 0&&i!==void 0&&r<=i?{start:r,end:i}:void 0;r!==void 0&&i!==void 0&&r>i&&t.push({rule:`inverted-range`,path:`/data/time`,message:`the timeline starts on ${e.time.start}, after it ends on ${e.time.end}`});let o=`${e.time.start} to ${e.time.end}`,s=new Map,c=(e,n)=>{if(e===void 0)return;let r=s.get(e);r===void 0?s.set(e,n):t.push({rule:`duplicate-identifier`,path:`${n}/id`,message:`identifier "${e}" is already declared at ${r}`})},l=e.comparedTo!==void 0;e.comparedTo?.date!==void 0&&n(e.comparedTo.date,`/data/comparedTo/date`);let u=e=>t.push({rule:`comparison-without-reference`,path:e,message:"previous dates and change roles describe a comparison; declare `comparedTo` naming the plan they compare with"}),d=new Set;return e.rows.forEach((e,r)=>{if(e.type!==`task`)return;let i=`/data/rows/${r}`;c(e.id,i),e.role!==void 0&&!l&&u(`${i}/role`),e.items.forEach((r,s)=>{let f=`${i}/items/${s}`;if(c(r.id,f),r.kind!==void 0&&d.add(r.kind),r.role!==void 0&&!l&&u(`${f}/role`),r.previous!==void 0){l||u(`${f}/previous`),(r.role!==void 0||e.role!==void 0)&&t.push({rule:`contradictory-change`,path:`${f}/previous`,message:`an item that is ${r.role??`in a task that is ${e.role}`} has no previous dates; it is new or dropped, not moved`});let i=r.previous,s=r.type===`activity`?{first:n(i.start,`${f}/previous/start`),last:n(i.end,`${f}/previous/end`)}:(()=>{let e=n(i.date,`${f}/previous/date`);return{first:e,last:e}})();s.first!==void 0&&s.last!==void 0&&(s.first>s.last?t.push({rule:`inverted-range`,path:`${f}/previous`,message:`the previous dates start on ${i.start}, after they end on ${i.end}`}):a!==void 0&&(s.first<a.start||s.last>a.end)&&t.push({rule:`item-outside-range`,path:`${f}/previous`,message:`the previous dates fall outside the timeline's range ${o}; the range covers both plans, so widen \`time\``}))}r.role!==void 0&&e.role!==void 0&&r.role!==e.role&&t.push({rule:`contradictory-change`,path:`${f}/role`,message:`an item ${r.role} in a task that is ${e.role}`});let p,m;if(r.type===`activity`){if(p=n(r.start,`${f}/start`),m=n(r.end,`${f}/end`),p!==void 0&&m!==void 0&&p>m){t.push({rule:`inverted-range`,path:f,message:`the activity starts on ${r.start}, after it ends on ${r.end}`});return}}else p=m=n(r.date,`${f}/date`);a!==void 0&&p!==void 0&&m!==void 0&&(p<a.start||m>a.end)&&t.push({rule:`item-outside-range`,path:f,message:r.type===`activity`?`the activity runs ${r.start} to ${r.end}, outside the timeline's range ${o}; widen \`time\` or move the activity`:`the milestone falls on ${r.date}, outside the timeline's range ${o}; widen \`time\` or move the milestone`})})}),(e.periods??[]).forEach((e,r)=>{let i=`/data/periods/${r}`;e.kind!==void 0&&d.add(e.kind);let s=n(e.start,`${i}/start`),c=n(e.end,`${i}/end`);s!==void 0&&c!==void 0&&(s>c?t.push({rule:`inverted-range`,path:i,message:`the period starts on ${e.start}, after it ends on ${e.end}`}):a!==void 0&&(c<a.start||s>a.end)&&t.push({rule:`period-outside-range`,path:i,message:`the period ${e.start} to ${e.end} lies wholly outside the timeline's range ${o}, so nothing of it could be drawn`}))}),(e.references??[]).forEach((e,r)=>{let i=`/data/references/${r}`;e.kind!==void 0&&d.add(e.kind);let s=n(e.date,`${i}/date`);s!==void 0&&a!==void 0&&(s<a.start||s>a.end)&&t.push({rule:`item-outside-range`,path:i,message:`the reference date ${e.date} is outside the timeline's range ${o}; widen \`time\` or move it`})}),d.size>at.kindsPerVocabulary&&t.push({rule:`too-many-kinds`,path:`/data/rows`,message:`${d.size} distinct item types, and no more than ${at.kindsPerVocabulary} can be told apart in a rendering`,observed:d.size,limit:at.kindsPerVocabulary}),t.push(...xn(e,Bt(e))),t.push(...bn(e)),t}function bn(e){let t=new Set;for(let n of e.rows)if(n.type===`task`){n.role===`removed`&&t.add(n.id);for(let e of n.items)e.id!==void 0&&(e.role===`removed`||n.role===`removed`)&&t.add(e.id)}let n=[];return(e.dependencies??[]).forEach((e,r)=>{for(let i of[`from`,`to`])t.has(e[i])&&n.push({rule:`dependency-on-removed`,path:`/data/dependencies/${r}/${i}`,message:`"${e[i]}" was dropped from the plan, so nothing can depend on it any more; remove the dependency`})}),n}function xn(e,t){let n=[],r=e.dependencies??[],i=[],a=new Map;r.forEach((r,o)=>{let s=`/data/dependencies/${o}`,c=!0;for(let i of[`from`,`to`]){let a=r[i],o=t.get(a);if(o===void 0)c=!1,n.push({rule:`unresolved-endpoint`,path:`${s}/${i}`,message:`"${a}" is not the identifier of any task or item this timeline declares`});else if(o.type===`task`&&o.days===void 0){c=!1;let t=e.rows[o.row];if(t.type===`task`&&t.items.length>0)continue;n.push({rule:`empty-task-endpoint`,path:`${s}/${i}`,message:`task "${a}" holds no item, so it has no start or finish for a dependency to link`})}}if(!c)return;let l=t.get(r.from),u=t.get(r.to),d=(e,t)=>e.type===`task`&&t.type!==`task`&&t.row===e.row;if(l.id===u.id||d(l,u)||d(u,l)){n.push({rule:`self-dependency`,path:s,message:l.id===u.id?`"${l.id}" cannot depend on itself`:`a task and one of its own items cannot depend on each other: the task's span is made of its items`});return}let f=JSON.stringify([r.from,r.to,Ht(r)]),p=a.get(f);p===void 0?(a.set(f,o),i.push({from:r.from,to:r.to,index:o})):n.push({rule:`duplicate-dependency`,path:s,message:`the same dependency is already declared at /data/dependencies/${p}`})});let o=Sn(i);return o!==void 0&&n.push({rule:`dependency-cycle`,path:`/data/dependencies/${o.index}`,message:`dependencies form a cycle, which no dates can honour: ${o.ids.join(` → `)}`}),n}function Sn(e){let t=new Map;for(let n of e){let e=t.get(n.from)??[];e.push({to:n.to,index:n.index}),t.set(n.from,e)}let n=new Map,r=[];for(let e of t.keys()){if(n.has(e))continue;let i=[{id:e,next:0}];for(n.set(e,`open`),r.push({id:e,index:-1});i.length>0;){let e=i[i.length-1],a=t.get(e.id)??[];if(e.next>=a.length){n.set(e.id,`done`),i.pop(),r.pop();continue}let o=a[e.next++],s=n.get(o.to);if(s===`open`){let e=r.findIndex(e=>e.id===o.to);return{ids:[...r.slice(e).map(e=>e.id),o.to],index:o.index}}s===void 0&&(n.set(o.to,`open`),i.push({id:o.to,next:0}),r.push({id:o.to,index:o.index}))}}}function Cn(e){let t=e.data;return e.kind===`graph`?Array.isArray(t.nodes)&&Array.isArray(t.edges):e.kind===`sequence`?Array.isArray(t.participants)&&Array.isArray(t.messages):e.kind===`timeline`?typeof t.time==`object`&&t.time!==null&&Array.isArray(t.rows):Array.isArray(t.columns)&&Array.isArray(t.rows)}function wn(e){return e.kind===`graph`?e.data.nodes:e.kind===`sequence`?e.data.participants:[]}function Tn(e){return e.kind===`graph`?e.data.edges:e.kind===`sequence`?e.data.messages:[]}function En(e){return e.kind===`graph`||e.kind===`sequence`?e.data.containers??[]:[]}function Dn(e){return e.kind===`graph`?`/data/nodes`:`/data/participants`}function On(e){return e.kind===`graph`?`/data/edges`:`/data/messages`}function kn(e){if(e.kind===`timeline`)return[];let t=e.data,n=[];for(let e of[`nodes`,`edges`,`participants`,`messages`,`rows`,`relations`]){let r=t[e];Array.isArray(r)&&r.forEach((t,r)=>{if(typeof t!=`object`||!t||Array.isArray(t))return;let i=t;n.push({at:`/data/${e}/${r}`,ref:typeof i.ref==`string`?i.ref:void 0,set:i.set,expect:i.expect,locations:i.locations})})}return n}function An(e){if(e.kind!==`table`)return[];let t=e.data.rows,n=[];return t.forEach((e,t)=>{if(typeof e!=`object`||!e||Array.isArray(e))return;let r=e;(r.ref!==void 0||r.set!==void 0)&&n.push({at:`/data/rows/${t}`,...typeof r.ref==`string`?{ref:r.ref}:{},...r.set===void 0?{}:{set:r.set}})}),n}function jn(e){if(e.kind!==`table`)return[];let t=e.data.rows,n=[];return t.forEach((e,t)=>{if(typeof e!=`object`||!e||Array.isArray(e))return;let r=e.id;typeof r==`string`&&n.push({id:r,at:`/data/rows/${t}`})}),n}function Mn(e){if(e.kind!==`table`)return[];let t=e.data.relations;return Array.isArray(t)?t:[]}function Nn(e,t){return e===`timeline`?`a timeline is maintained by presenting the revised timeline again, not proposed as a change, ${t}`:`a ${e} is a projection and cannot be proposed, ${t}`}function Pn(e){let t=[];if(!Cn(e))return t.push({rule:`kind-data-mismatch`,path:`/data`,message:`data does not carry what kind "${e.kind}" declares`}),t;let n=nt(e.schema).includes(e.kind);e.target!==void 0&&!n&&t.push({rule:`kind-not-proposable`,path:`/target`,message:Nn(e.kind,`so it carries no target`)}),e.removals!==void 0&&(n?e.target===void 0&&t.push({rule:`removal-without-target`,path:`/removals`,message:`removals need a target: an artifact that does not exist yet has nothing to remove`}):t.push({rule:`kind-not-proposable`,path:`/removals`,message:Nn(e.kind,`so it declares no removals`)}));let r=wn(e),i=Dn(e),a=new Map;r.forEach((e,n)=>{let r=a.get(e.id);r===void 0?a.set(e.id,n):t.push({rule:`duplicate-identifier`,path:`${i}/${n}/id`,message:`identifier "${e.id}" is already declared at ${i}/${r}`})});let o=new Map;En(e).forEach((e,n)=>{let r=o.get(e.id);r===void 0?o.set(e.id,n):t.push({rule:`duplicate-container-identifier`,path:`/data/containers/${n}/id`,message:`container "${e.id}" is already declared at /data/containers/${r}`})}),r.forEach((e,n)=>{for(let[r,a]of[[`container`,e.container],[`set/container`,e.set?.container]])a!==void 0&&!o.has(a)&&t.push({rule:`unresolved-container`,path:`${i}/${n}/${r}`,message:`"${a}" is not a container declared in /data/containers`})});let s=On(e);Tn(e).forEach((e,n)=>{for(let r of[`from`,`to`]){let o=e[r];a.has(o)||t.push({rule:`unresolved-endpoint`,path:`${s}/${n}/${r}`,message:`"${o}" is not an identifier declared in ${i}`})}});let c=new Map,l=(e,n,r)=>{if(n===void 0)return;let i=`${e}:${n}`,a=c.get(i);a===void 0?c.set(i,r):t.push({rule:`duplicate-reference`,path:r,message:`${e} "${n}" is already addressed at ${a}; a proposal states one intention per thing`})};r.forEach((e,t)=>l(`element`,e.ref,`${i}/${t}`)),Tn(e).forEach((e,t)=>l(`relationship`,e.ref,`${s}/${t}`)),An(e).forEach(e=>l(`row`,e.ref,e.at)),(e.removals??[]).forEach((e,t)=>l(e.type,e.ref,`/removals/${t}`));let u=[...r.map((e,t)=>({at:`${i}/${t}`,ref:e.ref,set:e.set})),...Tn(e).map((t,n)=>({at:`${On(e)}/${n}`,ref:t.ref,set:t.set})),...An(e)];for(let r of u)r.set!==void 0&&(r.ref===void 0?t.push({rule:`change-without-reference`,path:`${r.at}/set`,message:`a change names a reference to change; without one this is a new thing, and its fields are its values`}):n?e.target===void 0&&t.push({rule:`change-without-target`,path:`${r.at}/set`,message:`a change needs a target: naming what is being changed is what makes this a proposal rather than a new artifact`}):t.push({rule:`kind-not-proposable`,path:`${r.at}/set`,message:Nn(e.kind,`so nothing in it declares a change`)}));let d=e=>{let t=new Set;for(let n of e)n.kind!==void 0&&n.kind!==``&&t.add(n.kind);return t},f=[[e.kind===`sequence`?`participant`:`element`,i,d(r)],[e.kind===`sequence`?`message`:`relationship`,On(e),d(Tn(e))]];for(let[e,n,r]of f)r.size>at.kindsPerVocabulary&&t.push({rule:`too-many-kinds`,path:n,message:`${r.size} distinct ${e} types, and no more than ${at.kindsPerVocabulary} can be told apart in a rendering`,observed:r.size,limit:at.kindsPerVocabulary});let p=e.viewpoints;if(Array.isArray(p)){if(e.kind!==`graph`)t.push({rule:`viewpoints-without-graph`,path:`/viewpoints`,message:`only a graph declares viewpoints; a ${e.kind} has no element and relationship kinds for one to retain`});else{let n=new Set(r.map(e=>e.kind).filter(e=>!!e)),i=new Set(Tn(e).map(e=>e.kind).filter(e=>!!e)),a=new Map;p.forEach((e,r)=>{let o=`/viewpoints/${r}`,{id:s,elementKinds:c,relationshipKinds:l}=e,u=a.get(s);u===void 0?a.set(s,r):t.push({rule:`duplicate-viewpoint-identifier`,path:`${o}/id`,message:`viewpoint "${s}" is already declared at /viewpoints/${u}`}),c===void 0&&l===void 0&&t.push({rule:`empty-viewpoint`,path:o,message:`viewpoint "${s}" retains no kind, so it would show nothing it was not already showing; name elementKinds, relationshipKinds, or both`});let d=[[c,n,i,`elementKinds`,`element`,`relationship`],[l,i,n,`relationshipKinds`,`relationship`,`element`]];for(let[e,n,r,i,a,c]of d)e?.forEach((e,l)=>{n.has(e)||t.push({rule:`unresolved-viewpoint-kind`,path:`${o}/${i}/${l}`,message:`viewpoint "${s}" retains ${a} kind "${e}", and no ${a} of this document has it`+(r.has(e)?` (it is a ${c} kind here, which is a different vocabulary)`:``)})})})}}if(e.kind===`table`){let{columns:n,rows:r}=e.data;r.forEach((e,r)=>{let{cells:i,heading:a}=it(e);a===void 0&&i.length!==n.length&&t.push({rule:`row-column-mismatch`,path:`/data/rows/${r}`,message:`row has ${i.length} values but ${n.length} columns are declared`,observed:i.length,limit:n.length})})}e.kind===`timeline`&&t.push(...yn(e.data));for(let n of kn(e)){n.expect!==void 0&&(e.target===void 0?t.push({rule:`expectation-without-target`,path:`${n.at}/expect`,message:`an expectation is checked by the authority a proposal targets; a document that targets nothing has nobody to check it`}):n.ref===void 0&&t.push({rule:`expectation-without-reference`,path:`${n.at}/expect`,message:`an expectation describes something that already exists, and this item carries no reference to one`}));let r=n.set?.removeAttributes;if(Array.isArray(r)){let e=n.set?.attributes??{},i=new Map;r.forEach((r,a)=>{if(typeof r!=`string`)return;let o=i.get(r);o===void 0?i.set(r,a):t.push({rule:`duplicate-attribute-removal`,path:`${n.at}/set/removeAttributes/${a}`,message:`"${r}" is already removed at ${n.at}/set/removeAttributes/${o}`}),Object.prototype.hasOwnProperty.call(e,r)&&t.push({rule:`attribute-set-and-removed`,path:`${n.at}/set/removeAttributes/${a}`,message:`"${r}" is both assigned and removed; a proposal states one intention per property`})})}Array.isArray(n.locations)&&n.locations.forEach((e,r)=>{if(typeof e!=`object`||!e)return;let i=e.range;i!==void 0&&(i.endLine<i.startLine||i.endLine===i.startLine&&i.endCharacter!==void 0&&i.startCharacter!==void 0&&i.endCharacter<i.startCharacter)&&t.push({rule:`location-range-reversed`,path:`${n.at}/locations/${r}/range`,message:`a range ends before it begins, so it selects nothing a reader could be taken to`})})}e.kind===`table`&&e.data.rows.forEach((e,n)=>{if(typeof e!=`object`||!e||Array.isArray(e))return;let r=e;r.role!==void 0&&r.set!==void 0&&t.push({rule:`role-with-change`,path:`/data/rows/${n}/role`,message:`a row states what it observed or what it asks for, not both: a declared role beside a change is a report and an instruction at once`})});let m=new Map;for(let n of jn(e)){let e=m.get(n.id);e===void 0?m.set(n.id,n.at):t.push({rule:`duplicate-identifier`,path:`${n.at}/id`,message:`identifier "${n.id}" is already declared at ${e}`})}return Mn(e).forEach((e,n)=>{for(let r of[`from`,`to`]){let i=e[r];if(typeof i!=`object`||!i)continue;let a=i.id;typeof a==`string`&&(m.has(a)||t.push({rule:`unresolved-endpoint`,path:`/data/relations/${n}/${r}`,message:`"${a}" is not the identifier of any row this document declares`}))}}),t}function Fn(e,t){let n=t(e);if(n.length>0)return{valid:!1,issues:n};let r=e,i=Pn(r);return i.length>0?{valid:!1,issues:i}:{valid:!0,envelope:r,issues:[]}}function In(e,t,n){let r=vt(e,n);if(r!==void 0)return{valid:!1,issues:[r]};let i;try{i=JSON.parse(e)}catch{return{valid:!1,issues:[{rule:`not-json`,path:``,message:`document is not parseable JSON`}]}}let a=Fn(i,t);if(!a.valid)return a;let o=vt(e,n,a.envelope.schema);if(o!==void 0)return{valid:!1,issues:[o]};let s=bt(a.envelope,n);return s.length>0?{valid:!1,issues:s}:{valid:!0,envelope:a.envelope,measurement:xt(a.envelope,e),issues:[]}}function Ln(e){if(typeof e!=`object`||!e||Array.isArray(e))return;let t=e.schema;if(typeof t==`string`&&t.startsWith(`urn:structured-exchange:`))return t}function Rn(e,t,n){let r=vt(e,n);if(r!==void 0)return{status:`too-large`,issue:r};let i;try{i=JSON.parse(e)}catch{return{status:`not-a-document`,why:`unparseable`}}let a=Ln(i);if(a===void 0)return{status:`not-a-document`,why:`undeclared`};if(dt(a)===void 0)return{status:`unsupported-version`,schema:a};let o=Fn(i,t);if(!o.valid)return{status:`invalid`,issues:o.issues};let s=vt(e,n,o.envelope.schema);return s===void 0?{status:`valid`,envelope:o.envelope}:{status:`too-large`,issue:s}}function zn(e){let t=e.replace(/\r\n/g,`
20
+ `)}}var ze=Promise.resolve();function Be(e){let t=ze.then(e,e);return ze=t.then(()=>void 0,()=>void 0),t}var Ve=`text-xs text-zinc-500 underline hover:text-zinc-800 dark:hover:text-zinc-200 disabled:opacity-50`,He=`flex flex-wrap items-center gap-3 text-xs`,Ue=null;async function We(e){let t=await(Ue??=ye(()=>import(`./mermaid.core-bsPCHPw0.js`).then(e=>e.t),__vite__mapDeps([2,1,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20])));return t.default.initialize({startOnLoad:!1,theme:e,look:`classic`,securityLevel:`strict`,suppressErrorRendering:!0}),t}function Ge(e){let t=/viewBox="\s*[\d.-]+[\s,]+[\d.-]+[\s,]+([\d.]+)[\s,]+([\d.]+)/.exec(e),n=t?Number(t[1]):NaN;return Number.isFinite(n)&&n>0?n:void 0}function Ke(e,t){if(typeof e!=`object`||!e||!(`props`in e))return null;let n=e.props;if(t!==void 0&&!RegExp(`\\blanguage-${t}\\b`).test(n.className??``))return null;let r=n.children;return typeof r==`string`?r:Array.isArray(r)&&r.every(e=>typeof e==`string`)?r.join(``):null}function qe(e){let t=Ke(e,`mermaid`);return t===null?null:t.trim()}function Je(e){let{children:t,...n}=e,r=qe(t);if(r!==null)return(0,N.jsx)(Ye,{code:r});let i=Ke(t);return i===null?(0,N.jsx)(`pre`,{...n,children:t}):(0,N.jsxs)(`div`,{className:`code-block relative`,"data-testid":`code-block`,children:[(0,N.jsx)(`pre`,{...n,children:t}),(0,N.jsx)(me,{iconOnly:!0,text:i.replace(/\n$/,``),className:`absolute right-1.5 top-1.5 rounded border border-zinc-300 bg-white/80 px-1.5 py-0.5 text-xs text-zinc-500 hover:text-zinc-800 dark:border-zinc-700 dark:bg-zinc-900/80 dark:text-zinc-400 dark:hover:text-zinc-100`})]})}function Ye({code:e}){let t=(0,v.useId)().replace(/[^a-zA-Z0-9]/g,``),n=x()===`light`?`default`:`dark`,[r,i]=(0,v.useState)(null),[a,o]=(0,v.useState)(null),[s,c]=(0,v.useState)(!1),[l,u]=(0,v.useState)(!1),[d,f]=(0,v.useState)(!1),[p,m]=(0,v.useState)(null),h=(0,v.useRef)(!1),g=(0,v.useRef)(0),_=(0,v.useRef)(0),y=()=>`mermaid-${t}-${++_.current}`,b=(0,v.useMemo)(()=>Le(e),[e]),S=b===void 0?`landscape`:Ne(b.direction),[C,w]=(0,v.useState)(void 0),T=r?.svg??null,E=r!==null&&r.orientation!==S,D=(0,v.useRef)(null),O=(0,v.useRef)(e);O.current=e,(0,v.useEffect)(()=>(g.current+=1,i(null),w(void 0),u(!1),o(null),m(null),()=>{g.current+=1}),[e]);async function ee(){if(!r||h.current)return;h.current=!0,f(!0),m(null);let e=g.current;try{let{renderDiagram:n}=await ye(async()=>{let{renderDiagram:e}=await import(`./mermaidToImage-UE8_p2E5.js`).then(e=>e.r);return{renderDiagram:e}},__vite__mapDeps([21,1])),i=await n(r.source,`mermaid-download-${t}`);if(e!==g.current)return;let a=URL.createObjectURL(new Blob([i.svg],{type:`image/svg+xml;charset=utf-8`}));try{let e=document.createElement(`a`);e.href=a,e.download=`diagram.svg`,e.click()}finally{URL.revokeObjectURL(a)}}catch(t){e===g.current&&m(t instanceof Error?t.message:String(t))}finally{h.current=!1,f(!1)}}return(0,v.useEffect)(()=>{let e=!1,t=setTimeout(()=>void Be(async()=>{try{let t=(await We(n)).default,r=O.current,a=Le(r),s=a===void 0?`landscape`:Ne(a.direction);if(C!==void 0&&a!==void 0){let n=C===s?r:a.turned,{svg:c}=await t.render(y(),n);e||(i({svg:c,orientation:C,source:n}),o(null));return}let c=await t.render(y(),r),l={svg:c.svg,orientation:s,source:r},u=Ge(c.svg);if(a!==void 0&&u!==void 0&&u>710){let e=await t.render(y(),a.turned),n=Ge(e.svg);if(n!==void 0){let t=s===`landscape`?je(u,n):je(n,u);t!==s&&(l={svg:e.svg,orientation:t,source:a.turned})}}e||(i(l),o(null))}catch(t){e||(i(null),o(t instanceof Error?t.message:String(t)))}}),300);return()=>{e=!0,clearTimeout(t)}},[e,t,n,C]),T?(0,N.jsxs)(`div`,{ref:D,className:`my-2 flex flex-col gap-2 rounded-lg border border-zinc-200 bg-zinc-50 p-3 dark:border-zinc-800 dark:bg-zinc-900`,children:[(0,N.jsxs)(`div`,{className:`${He} order-3`,children:[(0,N.jsx)(`button`,{type:`button`,onClick:()=>c(!s),title:s?`Show diagram`:`Show code`,className:Ve,children:s?`⚏ diagram`:`⌗ code`}),!s&&b!==void 0&&r!==null&&(0,N.jsx)(`button`,{type:`button`,"data-testid":`mermaid-orientation`,onClick:()=>w(e=>Ae(e??r.orientation)),title:r.orientation===`portrait`?`Turn it across the page — it is drawn down`:`Turn it down the page — it is drawn across`,"aria-label":`Turn the diagram ${Ae(r.orientation)}`,className:`text-xs text-zinc-500 underline hover:text-zinc-800 dark:hover:text-zinc-200 disabled:opacity-50`,children:r.orientation===`portrait`?`↔ landscape`:`↕ portrait`}),!s&&(0,N.jsx)(`button`,{type:`button`,onClick:()=>u(!0),"aria-label":`Show diagram at full size`,className:`text-xs text-zinc-500 underline hover:text-zinc-800 dark:hover:text-zinc-200 disabled:opacity-50`,children:`⤢ enlarge`}),(0,N.jsx)(`button`,{type:`button`,className:Ve,disabled:d,onClick:()=>void ee(),title:`Save as .svg — insert it as a picture in a document`,children:d?`preparing SVG…`:`⤓ download SVG`}),(0,N.jsx)(me,{text:e,className:Ve}),p&&(0,N.jsxs)(`span`,{role:`alert`,className:`text-red-600 dark:text-red-400`,children:[`Could not download SVG: `,p]})]}),s?(0,N.jsx)(`pre`,{className:`overflow-x-auto font-mono text-xs text-zinc-500 dark:text-zinc-400`,children:e}):(0,N.jsx)(`div`,{className:`flex justify-center overflow-x-auto [&_svg]:max-w-full`,dangerouslySetInnerHTML:{__html:T}}),E&&!s&&(0,N.jsxs)(`div`,{className:`mt-1 text-center text-xs text-zinc-400 dark:text-zinc-600`,"data-testid":`mermaid-turned`,children:[`drawn `,r?.orientation,` to fit — the source asks for `,S]}),(0,N.jsx)(Oe,{label:`diagram`,testId:`mermaid-enlarged`,open:l,onClose:()=>u(!1),anchorRef:D,actions:(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`button`,{type:`button`,className:Ve,disabled:d,onClick:()=>void ee(),children:d?`preparing SVG…`:`⤓ download SVG`}),p&&(0,N.jsxs)(`span`,{role:`alert`,className:`text-red-600 dark:text-red-400`,children:[`Could not download SVG: `,p]})]}),children:(0,N.jsx)(`div`,{style:{width:Ge(T)},className:`[&_svg]:!h-auto [&_svg]:!max-w-none [&_svg]:!w-full`,dangerouslySetInnerHTML:{__html:T}})})]}):(0,N.jsxs)(`pre`,{className:`my-2 overflow-x-auto rounded-lg border border-zinc-200 bg-zinc-50 p-3 font-mono text-xs text-zinc-500 dark:border-zinc-800 dark:bg-zinc-900 dark:text-zinc-400`,children:[e,a&&(0,N.jsx)(`div`,{className:`mt-2 text-red-600 dark:text-red-400`,children:a})]})}function Xe({html:e,className:t=``,as:n=`div`}){return(0,N.jsx)(n,{className:`rendered-ansi overflow-x-auto font-mono text-xs leading-relaxed [&_span]:whitespace-pre-wrap ${t}`,dangerouslySetInnerHTML:{__html:e}})}function Ze({lines:e,fill:t=!1}){return(0,N.jsx)(`div`,{className:`overflow-auto rounded border border-zinc-200 font-mono text-xs leading-relaxed dark:border-zinc-800 ${t?`max-h-full`:`max-h-72`}`,children:k(te(e)).map((e,t)=>e===null?(0,N.jsx)(`div`,{className:`bg-zinc-100 px-2 text-center text-zinc-400 dark:bg-zinc-800/60 dark:text-zinc-600`,children:`⋯`},t):(0,N.jsxs)(`div`,{className:`grid grid-cols-2`,children:[(0,N.jsx)(`div`,{className:`whitespace-pre-wrap break-words border-r border-zinc-200 px-2 dark:border-zinc-800 ${e.changed?e.left===null?`bg-zinc-50 dark:bg-zinc-900/40`:`bg-red-50 text-red-700 dark:bg-red-950/40 dark:text-red-300`:`text-zinc-500 dark:text-zinc-500`}`,children:e.left??` `}),(0,N.jsx)(`div`,{className:`whitespace-pre-wrap break-words px-2 ${e.changed?e.right===null?`bg-zinc-50 dark:bg-zinc-900/40`:`bg-emerald-50 text-emerald-800 dark:bg-emerald-950/40 dark:text-emerald-300`:`text-zinc-500 dark:text-zinc-500`}`,children:e.right??` `})]},t))})}function Qe({lines:e}){return(0,N.jsx)(`pre`,{className:`max-h-72 overflow-auto rounded border border-zinc-200 font-mono text-xs leading-relaxed dark:border-zinc-800`,children:ne(e).map((e,t)=>e===null?(0,N.jsx)(`div`,{className:`bg-zinc-100 px-2 text-center text-zinc-400 dark:bg-zinc-800/60 dark:text-zinc-600`,children:`⋯`},t):(0,N.jsxs)(`div`,{className:e.type===`add`?`bg-emerald-50 px-2 text-emerald-800 dark:bg-emerald-950/40 dark:text-emerald-300`:e.type===`del`?`bg-red-50 px-2 text-red-700 dark:bg-red-950/40 dark:text-red-300`:`px-2 text-zinc-500 dark:text-zinc-500`,children:[e.type===`add`?`+ `:e.type===`del`?`− `:` `,e.text]},t))})}function $e({item:e,canEdit:t,onEdit:n,queued:r}){let[i,a]=(0,v.useState)(null),[o,s]=(0,v.useState)(!1),c=(0,v.useRef)(null),l=t&&e.entryId!==void 0&&!o,u=i!==null;(0,v.useEffect)(()=>{u&&c.current?.focus()},[u]),(0,v.useEffect)(()=>{if(!o)return;let e=setTimeout(()=>s(!1),3e3);return()=>clearTimeout(e)},[o]);let d=r?.onDraftChange;(0,v.useEffect)(()=>{d?.(i)},[i,d]),(0,v.useEffect)(()=>{a(null)},[e.entryId,e.text]);function f(){let r=i?.trim();t&&e.entryId&&r&&(r===e.text||n(e.entryId,r,e.images),a(null))}let p=`mt-1.5 shrink-0 rounded px-1 py-0.5 text-xs text-zinc-400 opacity-0 hover:bg-zinc-200 hover:text-zinc-700 focus-visible:opacity-100 group-hover:opacity-100 dark:text-zinc-500 dark:hover:bg-zinc-700 dark:hover:text-zinc-200`;return(0,N.jsxs)(`div`,{className:`group ml-auto flex max-w-[85%] items-start gap-1.5`,...r?{"data-queued-prompt":e.entryId}:{},children:[l&&!u&&(0,N.jsx)(`button`,{type:`button`,onClick:()=>a(e.text),title:r?`edit this queued message — the agent has not read it yet`:`edit this prompt and ask again (branches the conversation)`,"aria-label":r?`Edit this queued message`:`Edit this prompt`,className:p,children:`✎`}),r&&l&&!u&&(0,N.jsx)(`button`,{type:`button`,onClick:()=>{s(!0),r.onRemove()},title:`remove this queued message — the agent will not read it`,"aria-label":`Remove this queued message`,className:p,children:`✕`}),(0,N.jsxs)(`div`,{className:r?`min-w-0 flex-1 rounded-xl border border-dashed border-blue-300 bg-blue-50 px-4 py-2 text-[15px] text-blue-950 dark:border-blue-900 dark:bg-blue-950/30 dark:text-zinc-100`:`min-w-0 flex-1 rounded-xl bg-blue-100 px-4 py-2 text-[15px] text-blue-950 dark:bg-blue-950/60 dark:text-zinc-100`,children:[r&&!u&&(0,N.jsx)(`div`,{className:`mb-0.5 text-[11px] uppercase tracking-wide text-blue-900/60 dark:text-zinc-400`,children:`queued — not read yet`}),e.images&&e.images.length>0&&(0,N.jsx)(`div`,{className:`mb-1.5 flex flex-wrap gap-1.5`,children:e.images.map((e,t)=>(0,N.jsx)(`img`,{src:`data:${e.mimeType};base64,${e.data}`,alt:``,className:`max-h-48 max-w-full rounded-lg object-contain`},t))}),u?(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`textarea`,{ref:c,value:i,"aria-label":`Edit prompt`,onChange:e=>a(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),f()),e.key===`Escape`&&a(null)},rows:Math.min(10,Math.max(2,i.split(`
21
+ `).length)),className:`w-full resize-none rounded-md bg-white/70 px-2 py-1 text-[15px] outline-none ring-1 ring-blue-300 dark:bg-zinc-900/60 dark:ring-blue-900`}),(0,N.jsxs)(`div`,{className:`mt-1.5 flex items-center justify-end gap-2 text-xs`,children:[(0,N.jsx)(`span`,{className:`mr-auto text-blue-900/70 dark:text-zinc-400`,children:r?t?`replaces the queued message — the agent has not read it yet`:`waiting: the connection dropped`:t?`asks again from here — the current answer moves to its own branch`:`waiting: the agent is running (or the connection dropped)`}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>a(null),className:`rounded border border-blue-300 px-2 py-0.5 hover:bg-white/60 dark:border-zinc-700 dark:hover:bg-zinc-800`,children:`cancel`}),(0,N.jsx)(`button`,{type:`button`,onClick:f,disabled:!t||!i.trim()||i.trim()===e.text,className:`rounded border border-blue-400 bg-white/70 px-2 py-0.5 font-medium disabled:opacity-50 dark:border-blue-800 dark:bg-zinc-900/60`,children:r?`save`:`send`})]})]}):(0,N.jsx)(`div`,{className:`whitespace-pre-wrap`,children:e.text})]})]})}var et=`urn:structured-exchange:1`,tt=[`graph`,`sequence`];function nt(e){return rt(e)?[`graph`,`sequence`,`table`]:tt}function rt(e){return e===`urn:structured-exchange:2`||e===`urn:structured-exchange:3`}function it(e){if(Array.isArray(e))return{cells:e};let t=e.heading;return typeof t==`string`?{cells:[],role:e.role,heading:t}:{cells:e.cells,role:e.role}}var at={nodes:500,edges:2e3,participants:100,messages:1e3,columns:50,rows:5e3,removals:500,ref:200,localId:200,label:500,kind:100,kindsPerVocabulary:64,columnName:200,cell:1e3},ot=`urn:structured-exchange:2`,st={profile:200,attributesPerItem:50,removeAttributesPerItem:50,attributeName:200,attributeString:1e3,attributeListItems:50,revision:200,locationsPerItem:10,uri:2e3,position:1e6,artifactsPerItem:20,artifactsPerDocument:50,artifactRel:100,artifactMediaType:100,artifactLabel:500,artifactDigest:71,relations:2e3,heading:500,headingDepth:6,viewpoints:20,viewpointConcern:500},ct=8e6,lt=`urn:structured-exchange:3`,ut=[et,ot,lt];function dt(e){return ut.find(t=>t===e)}var ft=4e6,pt=Math.max(ft,ct);function mt(e){return rt(e)?ct:ft}var ht=e=>new TextEncoder().encode(e).length;function gt(e){return e===`bytes`?pt:e===`relations`?st.relations:at[e]}function _t(e,t){let n=gt(e),r=t?.[e];return r===void 0||r>=n?{limit:n,level:`ceiling`}:{limit:r,level:`deployment`}}function vt(e,t,n){let r=ht(e),i=_t(`bytes`,t),a=n===void 0?1/0:mt(n),o=Math.min(i.limit,a),s=o===a&&a<i.limit?`ceiling`:i.level;if(!(r<=o))return{rule:`document-too-large`,path:``,message:`document is ${r} bytes, past the ${o}-byte ${s===`ceiling`?`contract ceiling`:`limit this deployment applies`}`,limit:o,observed:r,level:s}}var yt={graph:[`nodes`,`edges`],sequence:[`participants`,`messages`],table:[`columns`,`rows`,`relations`]};function bt(e,t){if(t===void 0)return[];let n=[];for(let r of yt[e.kind]??[]){let i=e.data[r];if(!Array.isArray(i))continue;let{limit:a,level:o}=_t(r,t);o===`deployment`&&i.length>a&&n.push({rule:`collection-past-deployment-limit`,path:`/data/${r}`,message:`${r} has ${i.length} entries, past the ${a} this deployment allows`,limit:a,observed:i.length,level:o})}return n}function xt(e,t){let n={};for(let t of yt[e.kind]??[]){let r=e.data[t];Array.isArray(r)&&(n[t]=r.length)}return{kind:e.kind,bytes:ht(t),counts:n}}var St=6.6,Ct=5.4;function wt(e,t,n){let r=e.flatMap(e=>e.split(/\r?\n/)).reduce((e,t)=>Math.max(e,t.length),0);return Math.min(Math.max(r*St+22,t),n)}function Tt(e,t,n,r){let i=t.map(e=>kt(e).length).reduce((e,t)=>Math.max(e,t),0);return Math.max(wt(e,n,r),Math.min(i*Ct+22,r))}function Et(e,t,n=St){let r=Math.max(Math.floor((t-22)/n+1e-6),4),i=[],a=e.split(/\r?\n/);if(a.length>1)return a.flatMap(e=>Et(e,t,n)).slice(0,3);let o=``;for(let t of e.split(/\s+/)){let e=o===``?t:`${o} ${t}`;if(e.length<=r)o=e;else for(o!==``&&i.push(o),o=t;o.length>r&&i.length<3;)i.push(o.slice(0,r)),o=o.slice(r)}if(o!==``&&i.push(o),i.length===0)return[``];if(i.length<=3)return i;let s=i.slice(0,3);return s[2]=`${s[2].slice(0,Math.max(r-1,1))}…`,s}function Dt(e,t){return e*15+t*15+14}function Ot(e,t){return e.flatMap(e=>Et(kt(e),t,Ct))}function kt(e){return`${e.field}: ${e.from===void 0?``:`${e.from} → `}${e.to}`}function At(e,t){return`${e}: ${jt(t)}`}function jt(e){return Array.isArray(e)?e.map(e=>jt(e)).join(`, `):e===null?`null`:typeof e==`object`&&e&&typeof e.ref==`string`?`<${e.ref}>`:String(e)}function Mt(e){let t=e.range===void 0?``:` lines ${e.range.startLine}–${e.range.endLine}`,n=e.revision===void 0?``:` at ${e.revision}`;return`${e.uri}${t}${n}`}function Nt(e){let t=e.label===void 0?e.uri:`${e.label} (${e.uri})`,n=e.mediaType===void 0?``:`, ${e.mediaType}`;return`${e.rel}: ${t}${n} — ${e.sha256.slice(0,14)}…`}var Pt=864e5,Ft=/^(\d{4})-(\d{2})-(\d{2})$/;function It(e){let t=Ft.exec(e);if(t===null)return;let[n,r,i]=[Number(t[1]),Number(t[2]),Number(t[3])],a=new Date(Date.UTC(n,r-1,i));if(a.setUTCFullYear(n,r-1,i),a.getUTCFullYear()===n&&a.getUTCMonth()===r-1&&a.getUTCDate()===i)return Math.round(a.getTime()/Pt)}function Lt(e){let t=new Date(e*Pt);return`${String(t.getUTCFullYear()).padStart(4,`0`)}-${String(t.getUTCMonth()+1).padStart(2,`0`)}-${String(t.getUTCDate()).padStart(2,`0`)}`}function Rt(e=new Date){return Math.round(Date.UTC(e.getFullYear(),e.getMonth(),e.getDate())/Pt)}function zt(e){let t=It(e.type===`activity`?e.start:e.date),n=It(e.type===`activity`?e.end:e.date);return t===void 0||n===void 0?void 0:{start:t,end:n}}function Bt(e){let t=new Map;return e.rows.forEach((e,n)=>{e.type===`task`&&(t.has(e.id)||t.set(e.id,{id:e.id,type:`task`,row:n,days:Vt(e)}),e.items.forEach((e,r)=>{e.id===void 0||t.has(e.id)||t.set(e.id,{id:e.id,type:e.type,row:n,item:r,days:zt(e)})}))}),t}function Vt(e){let t;for(let n of e.items){let e=zt(n);e!==void 0&&(t=t===void 0?{...e}:{start:Math.min(t.start,e.start),end:Math.max(t.end,e.end)})}return t}function Ht(e){return e.type??`finish-to-start`}function Ut(e){return{from:e.startsWith(`finish`)?`end`:`start`,to:e.endsWith(`finish`)?`end`:`start`}}function Wt(e,t){let n=t.get(e.from)?.days,r=t.get(e.to)?.days;if(n===void 0||r===void 0)return;let i=Ut(Ht(e));return r[i.to]>=n[i.from]}function Gt(e){if(`date`in e){let t=It(e.date)??0;return{start:t,end:t}}return{start:It(e.start)??0,end:It(e.end)??0}}function Kt(e){if(e.previous===void 0)return;let t=Gt(e.type===`activity`?{start:e.start,end:e.end}:{date:e.date}),n=Gt(e.previous);return{start:t.start-n.start,end:t.end-n.end}}function qt(e){if(e===0)return``;let t=e>0?`+`:`−`,n=Math.abs(e);return n<14?`${t}${n}d`:n<70?`${t}${Math.round(n/7)}w`:`${t}${Math.round(n/30.44)}mo`}function Jt(e){let t=Kt(e);return t===void 0?``:t.start===t.end?qt(t.start):t.start===0?`end${qt(t.end)}`:t.end===0?`start${qt(t.start)}`:`${qt(t.start)}, end${qt(t.end)}`}function Yt(e,t){if(e.role!==void 0||t?.role!==void 0)return!0;let n=Kt(e);return n!==void 0&&(n.start!==0||n.end!==0)}function Xt(e){return e.role!==void 0||e.items.some(t=>Yt(t,e))}var Zt={week:12,month:4,quarter:.75};function Qt(e,t){let n=e>=8?`week`:e>=1?`month`:`quarter`;if(t===void 0)return n;let r=[`week`,`month`,`quarter`];return r[Math.max(r.indexOf(n),r.indexOf(t))]}var $t=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`];function en(e){return e.width>=24?e.label:e.width>=9?e.label.charAt(0):``}function tn(e,t){return t===`month`?en(e):e.width>=e.label.length*6+4?e.label:``}function nn(e){return((e+3)%7+7)%7}function rn(e){let t=e-nn(e)+3,n=new Date(t*Pt).getUTCFullYear();return Math.floor((t-cn(n,0))/7)+1}function an(e){if(e.label!==void 0&&e.label!==``)return e.label;if(e.type===`milestone`&&e.kind!==void 0&&e.kind!==``)return e.kind}function on(e){return e.length*St}function sn(e,t){let n=new Date(e*Pt),r=n.getUTCFullYear(),i=n.getUTCMonth(),a=[];for(;;){i+=1,i===12&&(i=0,r+=1);let e=cn(r,i);if(e>t)return a;a.push({day:e,year:r,month:i})}}function cn(e,t){let n=new Date(0);return n.setUTCFullYear(e,t,1),Math.round(n.getTime()/Pt)}function ln(e,t){let n=e=>e===`bar`||e===`ghost`;return n(e)&&t===`star`||e===`star`&&n(t)}function un(e,t){return e.x0<t.x1&&t.x0<e.x1}function dn(e,t){if(t<=0||e.width<=t)return;let n=e.items.filter(e=>e.change!==void 0);if(n.length>0){let e=Math.min(...n.flatMap(e=>e.ghost===void 0?[e.glyph.x]:[e.glyph.x,e.ghost.x]));return e<t*.9?void 0:Math.max(0,e-t/6)}if(`x`in e.today&&e.today.x>t*.8)return Math.max(0,e.today.x-t/3)}function fn(e,t,n={}){let r=It(e.time.start)??0,i=It(e.time.end)??r,a=n.pxPerDay??Zt[e.time.scale]??4,o=(i-r+1)*a,s=e=>(e-r)*a,c=sn(r,i),l=new Date(r*Pt),u=[{day:r,year:l.getUTCFullYear(),month:l.getUTCMonth()},...c],d=u.map((e,t)=>{let n=t+1<u.length?u[t+1].day:i+1;return{label:$t[e.month],x:s(e.day),width:(n-e.day)*a,year:e.year,month:e.month}}),f=[];u.forEach((e,t)=>{let n=d[t],r=f[f.length-1];r!==void 0&&r.label===String(e.year)?r.width+=n.width:f.push({label:String(e.year),x:n.x,width:n.width})});let p=Qt(a,n.unit),m=(e,t)=>e.map((n,r)=>{let o=r+1<e.length?e[r+1]:i+1;return{label:t(n),x:s(n),width:(o-n)*a}}),h=f,g;if(p===`week`){let e=[];for(let t=r-nn(r)+7;t<=i;t+=7)e.push(t);g=m([r,...e],e=>`W${rn(e)}`),h=d.map(e=>({label:`${e.label} ${e.year}`,x:e.x,width:e.width}))}else if(p===`quarter`){let e=u.filter((e,t)=>t===0||e.month%3==0);g=e.map((t,n)=>{let r=n+1<e.length?e[n+1].day:i+1;return{label:`Q${Math.floor(t.month/3)+1}`,x:s(t.day),width:(r-t.day)*a}})}else g=d;let _=g.slice(1).map(e=>e.x),v=[],y=[],b=0,x=e.comparedTo!==void 0,S=(e,t)=>{if(!x)return;if(e.role===`added`||t.role===`added`)return`(new)`;let n=Jt(e);return n===``?void 0:`(${n})`},C=(e,t,n)=>{let r=S(e,t);return r===void 0?n:n===void 0?r:`${n} ${r}`},w=(e,t)=>{if(x)return e.role===`removed`||t.role===`removed`?`removed`:e.role===`added`||t.role===`added`?`added`:Jt(e)===``?void 0:`moved`},T=(e,t)=>{let n=[],r=[],i=[],c=e.map(e=>({...e,days:zt(e.item)})).filter(e=>e.days!==void 0).sort((e,t)=>Number(e.item.type===`milestone`)-Number(t.item.type===`milestone`)||e.days.start-t.days.start||e.row-t.row||e.index-t.index);for(let{item:e,index:t,row:l,days:u,text:d,note:f,change:p}of c){let c=[],m;if(p===`moved`&&e.previous!==void 0){let t=Gt(e.previous);if(e.type===`activity`)m={x0:s(t.start),x1:s(t.end+1)};else{let e=s(t.start)+a/2;m={x0:e-7,x1:e+7,cx:e}}c.push({kind:`ghost`,x0:m.x0,x1:m.x1})}let h,g,_,v;if(e.type===`activity`){if(g=s(u.start),_=s(u.end+1),c.push({kind:`bar`,x0:g,x1:_}),d!==void 0){let e=on(d);h=e+12<=_-g?{text:d,inside:!0,x:g+6,width:e}:pn(d,g,_,o),f!==void 0&&(h.note=f),c.push({kind:`label`,x0:h.x,x1:h.x+h.width})}}else v=s(u.start)+a/2,g=v-7,_=v+7,c.push({kind:`star`,x0:g,x1:_}),d!==void 0&&(h=pn(d,g,_,o),f!==void 0&&(h.note=f),c.push({kind:`label`,x0:h.x,x1:h.x+h.width}));let y=n.findIndex(e=>c.every(t=>e.every(e=>ln(t.kind,e.kind)||!un(t,e))));y===-1&&(y=n.length,n.push([])),n[y].push(...c),r.push({row:l,item:t,type:e.type,lane:y,days:u,...e.kind?{kind:e.kind}:{},...p===void 0?{}:{change:p}}),i.push({label:h===void 0?void 0:{...h,...p===`removed`?{struck:!0}:{}},x0:g,x1:_,cx:v,ghost:m})}return r.forEach((e,n)=>{let r=i[n],a=t+4+e.lane*24+12,o=e.type===`activity`?{x:r.x0,y:a-6,width:r.x1-r.x0,height:12}:{x:r.x0,y:a-7,width:14,height:14},s=r.ghost;y.push({...e,glyph:o,...r.cx===void 0?{}:{center:{x:r.cx,y:a}},...r.label===void 0?{}:{label:{...r.label,y:a-8,height:16}},...s===void 0?{}:e.type===`activity`?{ghost:{x:s.x0,y:a-6,width:s.x1-s.x0,height:12}}:{ghost:{x:s.x0,y:a-7,width:14,height:14},ghostCenter:{x:s.cx,y:a}}})}),Math.max(1,n.length)},E=e=>e*24+8,D=(e,t)=>{let n=T(e.items.map((n,r)=>({row:t,index:r,item:n,text:C(n,e,an(n)),note:S(n,e),change:w(n,e)})),b),r=E(n);v.push({type:`task`,row:t,y:b,height:r,lanes:n,label:e.label,id:e.id}),b+=r},O,ee=()=>{if(O!==void 0){if(O.tasks.length===0){let e=O.label?26:10;v.push({type:`separator`,row:O.row,y:b,height:e,...O.label?{label:O.label}:{}}),b+=e}else{let e=T(O.tasks.flatMap(({task:e,row:t})=>e.items.map((n,r)=>({row:t,index:r,item:n,text:C(n,e,an(n)??(n.type===`activity`?e.label:void 0)),note:S(n,e),change:w(n,e)}))),b),t=E(e);v.push({type:`section`,row:O.row,y:b,height:t,lanes:e,...O.label?{label:O.label}:{},tasks:O.tasks.map(({task:e})=>e.id)}),b+=t}O=void 0}},te=(()=>{let t=new Set;if(!(n.onlyChanged&&x))return;let r;return e.rows.forEach((e,n)=>{e.type===`separator`?r=n:Xt(e)&&(t.add(n),r!==void 0&&t.add(r))}),t})(),k=te===void 0?0:e.rows.filter((e,t)=>e.type===`task`&&!te.has(t)).length;e.rows.forEach((e,t)=>{if(te===void 0||te.has(t)){if(e.type===`separator`){if(n.compact){ee(),O={row:t,...e.label?{label:e.label}:{},tasks:[]};return}let r=e.label?26:10;v.push({type:`separator`,row:t,y:b,height:r,...e.label?{label:e.label}:{}}),b+=r}else O===void 0?D(e,t):O.tasks.push({task:e,row:t})}}),ee();let ne=[];for(let t of e.rows)if(t.type===`task`)for(let e of t.items)e.kind&&!ne.includes(e.kind)&&ne.push(e.kind);for(let t of[...e.periods??[],...e.references??[]])t.kind&&!ne.includes(t.kind)&&ne.push(t.kind);let A=[];(e.periods??[]).forEach((e,t)=>{let n=Math.max(It(e.start)??r,r),o=Math.min(It(e.end)??i,i);n>o||A.push({index:t,x:s(n),width:(o-n+1)*a,start:e.start,end:e.end,...e.label?{label:e.label}:{},...e.kind?{kind:e.kind}:{}})});let re=(e.references??[]).flatMap((e,t)=>{let n=It(e.date);return n===void 0||n<r||n>i?[]:[{index:t,x:s(n)+a/2,label:e.label,date:e.date,...e.kind?{kind:e.kind}:{}}]}),j=[];if(t>=r&&t<=i){let e=s(t)+a/2;j.push({x0:e-26,x1:e+26})}let ie=[],ae=[...A.filter(e=>e.label).map(e=>({of:`period`,index:e.index,text:e.label,x:e.x+3,room:e.width-6})),...re.map(e=>{let t=on(e.label)*(10/11);return{of:`reference`,index:e.index,text:e.label,x:Math.min(Math.max(2,e.x-t/2),o-t-2),room:o-4}})].sort((e,t)=>e.x-t.x);for(let e of ae){let t=on(e.text)*(10/11);if(t>e.room)continue;let n={x0:e.x-2,x1:e.x+t+2};j.some(e=>n.x0<e.x1&&e.x0<n.x1)||(j.push(n),ie.push({of:e.of,index:e.index,text:e.text,x:e.x,width:t}))}return{width:o,height:b,start:r,end:i,years:f,months:d,monthLines:c.map(e=>s(e.day)),unit:p,upper:h,lower:g,unitLines:_,rows:v,items:y,dependencies:mn(e,v,y,s),today:t<r?{outside:`before`,day:t}:t>i?{outside:`after`,day:t}:{x:s(t)+a/2,day:t},kinds:ne,hiddenTasks:k,periods:A,references:re,headerLabels:ie}}function pn(e,t,n,r){let i=on(e),a=n+4;if(a+i<=r)return{text:e,inside:!1,x:a,width:i};let o=t-4-i;return o>=0?{text:e,inside:!1,x:o,width:i}:{text:e,inside:!1,x:Math.max(0,r-i),width:i}}function mn(e,t,n,r){let i=Bt(e),a=new Map(n.map(e=>[`${e.row}:${e.item}`,e])),o=new Map(t.map(e=>[e.row,e])),s=(e,t)=>{let s=i.get(e);if(s?.days===void 0)return;if(s.item!==void 0){let e=a.get(`${s.row}:${s.item}`);if(e===void 0)return;let n=e.glyph.y+e.glyph.height/2;return e.center===void 0?{x:t===`start`?e.glyph.x:e.glyph.x+e.glyph.width,y:n}:{x:e.center.x+(t===`start`?-7:7),y:n}}let c=r(t===`start`?s.days.start:s.days.end+1),l=o.get(s.row);if(l!==void 0&&l.type===`task`)return{x:c,y:l.y+4+12};let u=n.filter(e=>e.row===s.row).sort((e,n)=>t===`start`?e.glyph.x-n.glyph.x:n.glyph.x+n.glyph.width-(e.glyph.x+e.glyph.width));if(u.length!==0)return{x:c,y:u[0].glyph.y+u[0].glyph.height/2}},c=[];return(e.dependencies??[]).forEach((e,t)=>{let n=Ht(e),r=Ut(n),a=s(e.from,r.from),o=s(e.to,r.to),l=Wt(e,i);if(a===void 0||o===void 0||l===void 0)return;let u={x:a.x+(r.from===`end`?8:-8),y:a.y},d={x:o.x+(r.to===`start`?-8:8),y:o.y};if(a.y===o.y&&r.from===`end`&&r.to===`start`&&o.x>=a.x-14){c.push({index:t,from:e.from,to:e.to,type:n,satisfied:l,points:[a,o]});return}let f=o.y>a.y?o.y-12:(o.y,a.y,o.y+12);c.push({index:t,from:e.from,to:e.to,type:n,satisfied:l,points:[a,u,{x:u.x,y:f},{x:d.x,y:f},d,o]})}),c}function hn(e){let t=e.rows.reduce((e,t)=>Math.max(e,(t.label??``).length),0);return Math.min(Math.max(t*St+24,120),280)}function gn(e,t){for(let n of e.rows){if(n.type!==`task`)continue;if(n.id===t)return`"${n.label}" (${t})`;let e=n.items.find(e=>e.id===t);if(e!==void 0){let n=an(e);return n===void 0?t:`"${n}" (${t})`}}return t}function _n(e,t,n){let r=n===!1?` — not satisfied by the dates`:``;return`${gn(e,t.to)} waits on ${gn(e,t.from)} (${Ht(t)})${r}`}function vn(e){let t=[];e.title!==void 0&&e.title!==``&&t.push(e.title),e.comparedTo!==void 0&&t.push(`Compared with ${e.comparedTo.label}${e.comparedTo.date===void 0?``:` (${e.comparedTo.date})`}`),t.push(`From ${e.time.start} to ${e.time.end}, by ${e.time.scale}`);for(let n of e.rows){if(t.push(``),n.type===`separator`){t.push(n.label?`— ${n.label} —`:`———`);continue}let e=n.role===void 0?``:n.role===`added`?` — new`:` — removed`;t.push(`${n.label} [${n.id}]${n.items.length===0?` — no items`:``}${e}`);for(let e of n.items){let n=e.type===`activity`?`${e.start} to ${e.end}`:e.date,r=e.label===void 0?``:`: ${e.label}`,i=e.kind===void 0?``:` [${e.kind}]`,a=e.id===void 0?``:` (${e.id})`,o=(()=>{if(e.role===`added`)return` — new`;if(e.role===`removed`)return` — removed`;let t=Jt(e);return t===``||e.previous===void 0?``:` — moved ${t}, was ${`date`in e.previous?e.previous.date:`${e.previous.start} to ${e.previous.end}`}`})();t.push(` ${e.type} ${n}${r}${i}${a}${o}`)}}let n=[...(e.periods??[]).map(e=>` period ${e.start} to ${e.end}${e.label?`: ${e.label}`:``}${e.kind?` [${e.kind}]`:``}`),...(e.references??[]).map(e=>` reference ${e.date}: ${e.label}${e.kind?` [${e.kind}]`:``}`)];n.length>0&&t.push(``,`Calendar`,...n);let r=e.dependencies??[];if(r.length>0){let n=Bt(e);t.push(``,`Dependencies`);for(let i of r)t.push(` ${_n(e,i,Wt(i,n))}`)}return t}function yn(e){let t=[],n=(e,n)=>{let r=It(e);return r===void 0&&t.push({rule:`invalid-date`,path:n,message:`"${e}" is not a day of the calendar`}),r},r=n(e.time.start,`/data/time/start`),i=n(e.time.end,`/data/time/end`),a=r!==void 0&&i!==void 0&&r<=i?{start:r,end:i}:void 0;r!==void 0&&i!==void 0&&r>i&&t.push({rule:`inverted-range`,path:`/data/time`,message:`the timeline starts on ${e.time.start}, after it ends on ${e.time.end}`});let o=`${e.time.start} to ${e.time.end}`,s=new Map,c=(e,n)=>{if(e===void 0)return;let r=s.get(e);r===void 0?s.set(e,n):t.push({rule:`duplicate-identifier`,path:`${n}/id`,message:`identifier "${e}" is already declared at ${r}`})},l=e.comparedTo!==void 0;e.comparedTo?.date!==void 0&&n(e.comparedTo.date,`/data/comparedTo/date`);let u=e=>t.push({rule:`comparison-without-reference`,path:e,message:"previous dates and change roles describe a comparison; declare `comparedTo` naming the plan they compare with"}),d=new Set;return e.rows.forEach((e,r)=>{if(e.type!==`task`)return;let i=`/data/rows/${r}`;c(e.id,i),e.role!==void 0&&!l&&u(`${i}/role`),e.items.forEach((r,s)=>{let f=`${i}/items/${s}`;if(c(r.id,f),r.kind!==void 0&&d.add(r.kind),r.role!==void 0&&!l&&u(`${f}/role`),r.previous!==void 0){l||u(`${f}/previous`),(r.role!==void 0||e.role!==void 0)&&t.push({rule:`contradictory-change`,path:`${f}/previous`,message:`an item that is ${r.role??`in a task that is ${e.role}`} has no previous dates; it is new or dropped, not moved`});let i=r.previous,s=r.type===`activity`?{first:n(i.start,`${f}/previous/start`),last:n(i.end,`${f}/previous/end`)}:(()=>{let e=n(i.date,`${f}/previous/date`);return{first:e,last:e}})();s.first!==void 0&&s.last!==void 0&&(s.first>s.last?t.push({rule:`inverted-range`,path:`${f}/previous`,message:`the previous dates start on ${i.start}, after they end on ${i.end}`}):a!==void 0&&(s.first<a.start||s.last>a.end)&&t.push({rule:`item-outside-range`,path:`${f}/previous`,message:`the previous dates fall outside the timeline's range ${o}; the range covers both plans, so widen \`time\``}))}r.role!==void 0&&e.role!==void 0&&r.role!==e.role&&t.push({rule:`contradictory-change`,path:`${f}/role`,message:`an item ${r.role} in a task that is ${e.role}`});let p,m;if(r.type===`activity`){if(p=n(r.start,`${f}/start`),m=n(r.end,`${f}/end`),p!==void 0&&m!==void 0&&p>m){t.push({rule:`inverted-range`,path:f,message:`the activity starts on ${r.start}, after it ends on ${r.end}`});return}}else p=m=n(r.date,`${f}/date`);a!==void 0&&p!==void 0&&m!==void 0&&(p<a.start||m>a.end)&&t.push({rule:`item-outside-range`,path:f,message:r.type===`activity`?`the activity runs ${r.start} to ${r.end}, outside the timeline's range ${o}; widen \`time\` or move the activity`:`the milestone falls on ${r.date}, outside the timeline's range ${o}; widen \`time\` or move the milestone`})})}),(e.periods??[]).forEach((e,r)=>{let i=`/data/periods/${r}`;e.kind!==void 0&&d.add(e.kind);let s=n(e.start,`${i}/start`),c=n(e.end,`${i}/end`);s!==void 0&&c!==void 0&&(s>c?t.push({rule:`inverted-range`,path:i,message:`the period starts on ${e.start}, after it ends on ${e.end}`}):a!==void 0&&(c<a.start||s>a.end)&&t.push({rule:`period-outside-range`,path:i,message:`the period ${e.start} to ${e.end} lies wholly outside the timeline's range ${o}, so nothing of it could be drawn`}))}),(e.references??[]).forEach((e,r)=>{let i=`/data/references/${r}`;e.kind!==void 0&&d.add(e.kind);let s=n(e.date,`${i}/date`);s!==void 0&&a!==void 0&&(s<a.start||s>a.end)&&t.push({rule:`item-outside-range`,path:i,message:`the reference date ${e.date} is outside the timeline's range ${o}; widen \`time\` or move it`})}),d.size>at.kindsPerVocabulary&&t.push({rule:`too-many-kinds`,path:`/data/rows`,message:`${d.size} distinct item types, and no more than ${at.kindsPerVocabulary} can be told apart in a rendering`,observed:d.size,limit:at.kindsPerVocabulary}),t.push(...xn(e,Bt(e))),t.push(...bn(e)),t}function bn(e){let t=new Set;for(let n of e.rows)if(n.type===`task`){n.role===`removed`&&t.add(n.id);for(let e of n.items)e.id!==void 0&&(e.role===`removed`||n.role===`removed`)&&t.add(e.id)}let n=[];return(e.dependencies??[]).forEach((e,r)=>{for(let i of[`from`,`to`])t.has(e[i])&&n.push({rule:`dependency-on-removed`,path:`/data/dependencies/${r}/${i}`,message:`"${e[i]}" was dropped from the plan, so nothing can depend on it any more; remove the dependency`})}),n}function xn(e,t){let n=[],r=e.dependencies??[],i=[],a=new Map;r.forEach((r,o)=>{let s=`/data/dependencies/${o}`,c=!0;for(let i of[`from`,`to`]){let a=r[i],o=t.get(a);if(o===void 0)c=!1,n.push({rule:`unresolved-endpoint`,path:`${s}/${i}`,message:`"${a}" is not the identifier of any task or item this timeline declares`});else if(o.type===`task`&&o.days===void 0){c=!1;let t=e.rows[o.row];if(t.type===`task`&&t.items.length>0)continue;n.push({rule:`empty-task-endpoint`,path:`${s}/${i}`,message:`task "${a}" holds no item, so it has no start or finish for a dependency to link`})}}if(!c)return;let l=t.get(r.from),u=t.get(r.to),d=(e,t)=>e.type===`task`&&t.type!==`task`&&t.row===e.row;if(l.id===u.id||d(l,u)||d(u,l)){n.push({rule:`self-dependency`,path:s,message:l.id===u.id?`"${l.id}" cannot depend on itself`:`a task and one of its own items cannot depend on each other: the task's span is made of its items`});return}let f=JSON.stringify([r.from,r.to,Ht(r)]),p=a.get(f);p===void 0?(a.set(f,o),i.push({from:r.from,to:r.to,index:o})):n.push({rule:`duplicate-dependency`,path:s,message:`the same dependency is already declared at /data/dependencies/${p}`})});let o=Sn(i);return o!==void 0&&n.push({rule:`dependency-cycle`,path:`/data/dependencies/${o.index}`,message:`dependencies form a cycle, which no dates can honour: ${o.ids.join(` → `)}`}),n}function Sn(e){let t=new Map;for(let n of e){let e=t.get(n.from)??[];e.push({to:n.to,index:n.index}),t.set(n.from,e)}let n=new Map,r=[];for(let e of t.keys()){if(n.has(e))continue;let i=[{id:e,next:0}];for(n.set(e,`open`),r.push({id:e,index:-1});i.length>0;){let e=i[i.length-1],a=t.get(e.id)??[];if(e.next>=a.length){n.set(e.id,`done`),i.pop(),r.pop();continue}let o=a[e.next++],s=n.get(o.to);if(s===`open`){let e=r.findIndex(e=>e.id===o.to);return{ids:[...r.slice(e).map(e=>e.id),o.to],index:o.index}}s===void 0&&(n.set(o.to,`open`),i.push({id:o.to,next:0}),r.push({id:o.to,index:o.index}))}}}function Cn(e){let t=e.data;return e.kind===`graph`?Array.isArray(t.nodes)&&Array.isArray(t.edges):e.kind===`sequence`?Array.isArray(t.participants)&&Array.isArray(t.messages):e.kind===`timeline`?typeof t.time==`object`&&t.time!==null&&Array.isArray(t.rows):Array.isArray(t.columns)&&Array.isArray(t.rows)}function wn(e){return e.kind===`graph`?e.data.nodes:e.kind===`sequence`?e.data.participants:[]}function Tn(e){return e.kind===`graph`?e.data.edges:e.kind===`sequence`?e.data.messages:[]}function En(e){return e.kind===`graph`||e.kind===`sequence`?e.data.containers??[]:[]}function Dn(e){return e.kind===`graph`?`/data/nodes`:`/data/participants`}function On(e){return e.kind===`graph`?`/data/edges`:`/data/messages`}function kn(e){if(e.kind===`timeline`)return[];let t=e.data,n=[];for(let e of[`nodes`,`edges`,`participants`,`messages`,`rows`,`relations`]){let r=t[e];Array.isArray(r)&&r.forEach((t,r)=>{if(typeof t!=`object`||!t||Array.isArray(t))return;let i=t;n.push({at:`/data/${e}/${r}`,ref:typeof i.ref==`string`?i.ref:void 0,set:i.set,expect:i.expect,locations:i.locations})})}return n}function An(e){if(e.kind!==`table`)return[];let t=e.data.rows,n=[];return t.forEach((e,t)=>{if(typeof e!=`object`||!e||Array.isArray(e))return;let r=e;(r.ref!==void 0||r.set!==void 0)&&n.push({at:`/data/rows/${t}`,...typeof r.ref==`string`?{ref:r.ref}:{},...r.set===void 0?{}:{set:r.set}})}),n}function jn(e){if(e.kind!==`table`)return[];let t=e.data.rows,n=[];return t.forEach((e,t)=>{if(typeof e!=`object`||!e||Array.isArray(e))return;let r=e.id;typeof r==`string`&&n.push({id:r,at:`/data/rows/${t}`})}),n}function Mn(e){if(e.kind!==`table`)return[];let t=e.data.relations;return Array.isArray(t)?t:[]}function Nn(e,t){return e===`timeline`?`a timeline is maintained by presenting the revised timeline again, not proposed as a change, ${t}`:`a ${e} is a projection and cannot be proposed, ${t}`}function Pn(e){let t=[];if(!Cn(e))return t.push({rule:`kind-data-mismatch`,path:`/data`,message:`data does not carry what kind "${e.kind}" declares`}),t;let n=nt(e.schema).includes(e.kind);e.target!==void 0&&!n&&t.push({rule:`kind-not-proposable`,path:`/target`,message:Nn(e.kind,`so it carries no target`)}),e.removals!==void 0&&(n?e.target===void 0&&t.push({rule:`removal-without-target`,path:`/removals`,message:`removals need a target: an artifact that does not exist yet has nothing to remove`}):t.push({rule:`kind-not-proposable`,path:`/removals`,message:Nn(e.kind,`so it declares no removals`)}));let r=wn(e),i=Dn(e),a=new Map;r.forEach((e,n)=>{let r=a.get(e.id);r===void 0?a.set(e.id,n):t.push({rule:`duplicate-identifier`,path:`${i}/${n}/id`,message:`identifier "${e.id}" is already declared at ${i}/${r}`})});let o=new Map;En(e).forEach((e,n)=>{let r=o.get(e.id);r===void 0?o.set(e.id,n):t.push({rule:`duplicate-container-identifier`,path:`/data/containers/${n}/id`,message:`container "${e.id}" is already declared at /data/containers/${r}`})}),r.forEach((e,n)=>{for(let[r,a]of[[`container`,e.container],[`set/container`,e.set?.container]])a!==void 0&&!o.has(a)&&t.push({rule:`unresolved-container`,path:`${i}/${n}/${r}`,message:`"${a}" is not a container declared in /data/containers`})});let s=On(e);Tn(e).forEach((e,n)=>{for(let r of[`from`,`to`]){let o=e[r];a.has(o)||t.push({rule:`unresolved-endpoint`,path:`${s}/${n}/${r}`,message:`"${o}" is not an identifier declared in ${i}`})}});let c=new Map,l=(e,n,r)=>{if(n===void 0)return;let i=`${e}:${n}`,a=c.get(i);a===void 0?c.set(i,r):t.push({rule:`duplicate-reference`,path:r,message:`${e} "${n}" is already addressed at ${a}; a proposal states one intention per thing`})};r.forEach((e,t)=>l(`element`,e.ref,`${i}/${t}`)),Tn(e).forEach((e,t)=>l(`relationship`,e.ref,`${s}/${t}`)),An(e).forEach(e=>l(`row`,e.ref,e.at)),(e.removals??[]).forEach((e,t)=>l(e.type,e.ref,`/removals/${t}`));let u=[...r.map((e,t)=>({at:`${i}/${t}`,ref:e.ref,set:e.set})),...Tn(e).map((t,n)=>({at:`${On(e)}/${n}`,ref:t.ref,set:t.set})),...An(e)];for(let r of u)r.set!==void 0&&(r.ref===void 0?t.push({rule:`change-without-reference`,path:`${r.at}/set`,message:`a change names a reference to change; without one this is a new thing, and its fields are its values`}):n?e.target===void 0&&t.push({rule:`change-without-target`,path:`${r.at}/set`,message:`a change needs a target: naming what is being changed is what makes this a proposal rather than a new artifact`}):t.push({rule:`kind-not-proposable`,path:`${r.at}/set`,message:Nn(e.kind,`so nothing in it declares a change`)}));let d=e=>{let t=new Set;for(let n of e)n.kind!==void 0&&n.kind!==``&&t.add(n.kind);return t},f=[[e.kind===`sequence`?`participant`:`element`,i,d(r)],[e.kind===`sequence`?`message`:`relationship`,On(e),d(Tn(e))]];for(let[e,n,r]of f)r.size>at.kindsPerVocabulary&&t.push({rule:`too-many-kinds`,path:n,message:`${r.size} distinct ${e} types, and no more than ${at.kindsPerVocabulary} can be told apart in a rendering`,observed:r.size,limit:at.kindsPerVocabulary});let p=e.viewpoints;if(Array.isArray(p)){if(e.kind!==`graph`)t.push({rule:`viewpoints-without-graph`,path:`/viewpoints`,message:`only a graph declares viewpoints; a ${e.kind} has no element and relationship kinds for one to retain`});else{let n=new Set(r.map(e=>e.kind).filter(e=>!!e)),i=new Set(Tn(e).map(e=>e.kind).filter(e=>!!e)),a=new Map;p.forEach((e,r)=>{let o=`/viewpoints/${r}`,{id:s,elementKinds:c,relationshipKinds:l}=e,u=a.get(s);u===void 0?a.set(s,r):t.push({rule:`duplicate-viewpoint-identifier`,path:`${o}/id`,message:`viewpoint "${s}" is already declared at /viewpoints/${u}`}),c===void 0&&l===void 0&&t.push({rule:`empty-viewpoint`,path:o,message:`viewpoint "${s}" retains no kind, so it would show nothing it was not already showing; name elementKinds, relationshipKinds, or both`});let d=[[c,n,i,`elementKinds`,`element`,`relationship`],[l,i,n,`relationshipKinds`,`relationship`,`element`]];for(let[e,n,r,i,a,c]of d)e?.forEach((e,l)=>{n.has(e)||t.push({rule:`unresolved-viewpoint-kind`,path:`${o}/${i}/${l}`,message:`viewpoint "${s}" retains ${a} kind "${e}", and no ${a} of this document has it`+(r.has(e)?` (it is a ${c} kind here, which is a different vocabulary)`:``)})})})}}if(e.kind===`table`){let{columns:n,rows:r}=e.data;r.forEach((e,r)=>{let{cells:i,heading:a}=it(e);a===void 0&&i.length!==n.length&&t.push({rule:`row-column-mismatch`,path:`/data/rows/${r}`,message:`row has ${i.length} values but ${n.length} columns are declared`,observed:i.length,limit:n.length})})}e.kind===`timeline`&&t.push(...yn(e.data));for(let n of kn(e)){n.expect!==void 0&&(e.target===void 0?t.push({rule:`expectation-without-target`,path:`${n.at}/expect`,message:`an expectation is checked by the authority a proposal targets; a document that targets nothing has nobody to check it`}):n.ref===void 0&&t.push({rule:`expectation-without-reference`,path:`${n.at}/expect`,message:`an expectation describes something that already exists, and this item carries no reference to one`}));let r=n.set?.removeAttributes;if(Array.isArray(r)){let e=n.set?.attributes??{},i=new Map;r.forEach((r,a)=>{if(typeof r!=`string`)return;let o=i.get(r);o===void 0?i.set(r,a):t.push({rule:`duplicate-attribute-removal`,path:`${n.at}/set/removeAttributes/${a}`,message:`"${r}" is already removed at ${n.at}/set/removeAttributes/${o}`}),Object.prototype.hasOwnProperty.call(e,r)&&t.push({rule:`attribute-set-and-removed`,path:`${n.at}/set/removeAttributes/${a}`,message:`"${r}" is both assigned and removed; a proposal states one intention per property`})})}Array.isArray(n.locations)&&n.locations.forEach((e,r)=>{if(typeof e!=`object`||!e)return;let i=e.range;i!==void 0&&(i.endLine<i.startLine||i.endLine===i.startLine&&i.endCharacter!==void 0&&i.startCharacter!==void 0&&i.endCharacter<i.startCharacter)&&t.push({rule:`location-range-reversed`,path:`${n.at}/locations/${r}/range`,message:`a range ends before it begins, so it selects nothing a reader could be taken to`})})}e.kind===`table`&&e.data.rows.forEach((e,n)=>{if(typeof e!=`object`||!e||Array.isArray(e))return;let r=e;r.role!==void 0&&r.set!==void 0&&t.push({rule:`role-with-change`,path:`/data/rows/${n}/role`,message:`a row states what it observed or what it asks for, not both: a declared role beside a change is a report and an instruction at once`})});let m=new Map;for(let n of jn(e)){let e=m.get(n.id);e===void 0?m.set(n.id,n.at):t.push({rule:`duplicate-identifier`,path:`${n.at}/id`,message:`identifier "${n.id}" is already declared at ${e}`})}return Mn(e).forEach((e,n)=>{for(let r of[`from`,`to`]){let i=e[r];if(typeof i!=`object`||!i)continue;let a=i.id;typeof a==`string`&&(m.has(a)||t.push({rule:`unresolved-endpoint`,path:`/data/relations/${n}/${r}`,message:`"${a}" is not the identifier of any row this document declares`}))}}),t}function Fn(e,t){let n=t(e);if(n.length>0)return{valid:!1,issues:n};let r=e,i=Pn(r);return i.length>0?{valid:!1,issues:i}:{valid:!0,envelope:r,issues:[]}}function In(e,t,n){let r=vt(e,n);if(r!==void 0)return{valid:!1,issues:[r]};let i;try{i=JSON.parse(e)}catch{return{valid:!1,issues:[{rule:`not-json`,path:``,message:`document is not parseable JSON`}]}}let a=Fn(i,t);if(!a.valid)return a;let o=vt(e,n,a.envelope.schema);if(o!==void 0)return{valid:!1,issues:[o]};let s=bt(a.envelope,n);return s.length>0?{valid:!1,issues:s}:{valid:!0,envelope:a.envelope,measurement:xt(a.envelope,e),issues:[]}}function Ln(e){if(typeof e!=`object`||!e||Array.isArray(e))return;let t=e.schema;if(typeof t==`string`&&t.startsWith(`urn:structured-exchange:`))return t}function Rn(e,t,n){let r=vt(e,n);if(r!==void 0)return{status:`too-large`,issue:r};let i;try{i=JSON.parse(e)}catch{return{status:`not-a-document`,why:`unparseable`}}let a=Ln(i);if(a===void 0)return{status:`not-a-document`,why:`undeclared`};if(dt(a)===void 0)return{status:`unsupported-version`,schema:a};let o=Fn(i,t);if(!o.valid)return{status:`invalid`,issues:o.issues};let s=vt(e,n,o.envelope.schema);return s===void 0?{status:`valid`,envelope:o.envelope}:{status:`too-large`,issue:s}}function zn(e){let t=e.replace(/\r\n/g,`
22
22
  `).replace(/\s+$/,``),n=2166136261;for(let e=0;e<t.length;e++)n^=t.charCodeAt(e),n=Math.imul(n,16777619);return`sx-${(n>>>0).toString(16).padStart(8,`0`)}-${t.length.toString(36)}`}async function Bn(e){try{return await navigator.clipboard.writeText(e),!0}catch{let t=document.createElement(`textarea`);t.value=e,t.setAttribute(`readonly`,``),t.style.cssText=`position:fixed;top:0;left:0;opacity:0;pointer-events:none`,document.body.append(t);try{return t.select(),document.execCommand(`copy`)}catch{return!1}finally{t.remove()}}}function Vn(e,t,n){return e>=t&&e<=n}function Hn(e){return e===8205}function Un(e){return Vn(e,55296,56319)}function Wn(e){return Vn(e,127462,127487)}function Gn(e){return Vn(e,65024,65039)}function Kn(e){return Vn(e,768,879)||Vn(e,6832,6911)||Vn(e,7616,7679)||Vn(e,65056,65071)}function qn(e){return e>65535?2:1}function Jn(e,t){for(;t<e.length;){let n=e.codePointAt(t);if(Kn(n)||Gn(n))t+=qn(n);else break}return t}function Yn(e,t){let n=e.codePointAt(t),r=t+qn(n);for(r=Jn(e,r);r<e.length-1&&Hn(e.codePointAt(r));){let t=e.codePointAt(r+1);r+=1+qn(t),r=Jn(e,r)}return Wn(n)&&r<e.length&&Wn(e.codePointAt(r))&&(r+=qn(e.codePointAt(r))),r}function Xn(e){return Un(e)||Kn(e)||Gn(e)||Hn(e)}function Zn(e,t){if(t===0)return!0;let n=0,r=0;for(;r<e.length;)if(r=Yn(e,r),n++,n>=t)return!0;return!1}function Qn(e,t){let n=0,r=0;for(;r<e.length;)if(r=Yn(e,r),n++,n>t)return!1;return!0}function $n(e,t){if(t===0)return!0;let n=0;for(;n<e.length;){if(Xn(e.charCodeAt(n)))return Zn(e,t);if(n++,n>=t)return!0}return!1}function er(e,t){let n=0;for(;n<e.length;){if(Xn(e.charCodeAt(n)))return Qn(e,t);if(n++,n>t)return!1}return!0}function tr(e){return Array.isArray(e)}function nr(e){return dr(typeof e,`bigint`)}function rr(e){return dr(typeof e,`boolean`)}function ir(e){if(ur(e)||!ar(e))return!1;let t=Function.prototype.toString.call(e);return!!(/^class\s/.test(t)||/\[native code\]/.test(t))}function ar(e){return dr(typeof e,`function`)}function or(e){return dr(e,null)}function sr(e){return dr(typeof e,`object`)&&!or(e)}function cr(e){return dr(typeof e,`string`)}function lr(e){return dr(typeof e,`symbol`)}function ur(e){return dr(e,void 0)}function dr(e,t){return e===t}function fr(e,t){return er(e,t)}function pr(e,t){return $n(e,t)}function mr(e){return e instanceof Boolean}function hr(e){return e instanceof Number}function gr(e){return e instanceof String}function _r(e){return globalThis.ArrayBuffer.isView(e)}function vr(e){return e instanceof globalThis.RegExp}function yr(e){return e instanceof globalThis.Date}var br=[];function xr(e){br=e.variables}var Sr=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&`schema`in e&&`kind`in e&&`data`in e&&Object.getOwnPropertyNames(e).every((e,t)=>br[0].test(e)||!1)&&e.schema===`urn:structured-exchange:1`&&(e.kind===`graph`||e.kind===`sequence`||e.kind===`table`)&&(e.target===void 0||!(`target`in e)||Cr(e.target))&&(e.removals===void 0||!(`removals`in e)||Array.isArray(e.removals)&&e.removals.every((e,t)=>wr(e))&&e.removals.length<=500)&&[typeof e.data==`object`&&e.data!==null&&!Array.isArray(e.data)&&`nodes`in e.data&&`edges`in e.data&&Object.getOwnPropertyNames(e.data).every((e,t)=>br[2].test(e)||!1)&&Array.isArray(e.data.nodes)&&e.data.nodes.every((e,t)=>Or(e))&&e.data.nodes.length<=500&&e.data.nodes.length>=1&&Array.isArray(e.data.edges)&&e.data.edges.every((e,t)=>Ar(e))&&e.data.edges.length<=2e3&&(e.data.containers===void 0||!(`containers`in e.data)||Array.isArray(e.data.containers)&&e.data.containers.every((e,t)=>Mr(e))&&e.data.containers.length<=50),typeof e.data==`object`&&e.data!==null&&!Array.isArray(e.data)&&`participants`in e.data&&`messages`in e.data&&Object.getOwnPropertyNames(e.data).every((e,t)=>br[8].test(e)||!1)&&Array.isArray(e.data.participants)&&e.data.participants.every((e,t)=>Or(e))&&e.data.participants.length<=100&&e.data.participants.length>=1&&Array.isArray(e.data.messages)&&e.data.messages.every((e,t)=>Nr(e))&&e.data.messages.length<=1e3&&(e.data.containers===void 0||!(`containers`in e.data)||Array.isArray(e.data.containers)&&e.data.containers.every((e,t)=>Mr(e))&&e.data.containers.length<=50),typeof e.data==`object`&&e.data!==null&&!Array.isArray(e.data)&&`columns`in e.data&&`rows`in e.data&&Object.getOwnPropertyNames(e.data).length===2&&Array.isArray(e.data.columns)&&e.data.columns.every((e,t)=>typeof e==`string`&&fr(e,200)&&pr(e,1))&&e.data.columns.length<=50&&e.data.columns.length>=1&&Array.isArray(e.data.rows)&&e.data.rows.every((e,t)=>[Fr(e),typeof e==`object`&&!!e&&!Array.isArray(e)&&`cells`in e&&Object.getOwnPropertyNames(e).every((e,t)=>br[11].test(e)||!1)&&Fr(e.cells)&&(e.role===void 0||!(`role`in e)||e.role===`added`||e.role===`changed`||e.role===`context`||e.role===`removed`)].reduce((e,t,n)=>t===!0?++e:e,0)===1)&&e.data.rows.length<=5e3].reduce((e,t,n)=>t===!0?++e:e,0)===1),Cr=(e=>typeof e==`string`&&fr(e,200)&&pr(e,1)),wr=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&`type`in e&&`ref`in e&&Object.getOwnPropertyNames(e).every((e,t)=>br[1].test(e)||!1)&&(e.type===`element`||e.type===`relationship`)&&Cr(e.ref)&&(e.label===void 0||!(`label`in e)||Tr(e.label))&&(e.kind===void 0||!(`kind`in e)||Er(e.kind))&&(e.from===void 0||!(`from`in e)||Dr(e.from))&&(e.to===void 0||!(`to`in e)||Dr(e.to))),Tr=(e=>typeof e==`string`&&fr(e,500)),Er=(e=>typeof e==`string`&&fr(e,100)&&pr(e,1)),Dr=(e=>typeof e==`string`&&fr(e,200)&&pr(e,1)),Or=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&`id`in e&&Object.getOwnPropertyNames(e).every((e,t)=>br[3].test(e)||!1)&&Dr(e.id)&&(e.ref===void 0||!(`ref`in e)||Cr(e.ref))&&(e.label===void 0||!(`label`in e)||Tr(e.label))&&(e.kind===void 0||!(`kind`in e)||Er(e.kind))&&(e.set===void 0||!(`set`in e)||kr(e.set))&&(e.container===void 0||!(`container`in e)||Dr(e.container))&&(typeof e!=`object`||!e||Array.isArray(e)||`ref`in e?!0:!(typeof e==`object`&&e&&!Array.isArray(e))||`label`in e)),kr=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&Object.getOwnPropertyNames(e).every((e,t)=>br[4].test(e)||!1)&&(e.label===void 0||!(`label`in e)||Tr(e.label))&&(e.kind===void 0||!(`kind`in e)||Er(e.kind))&&(e.container===void 0||!(`container`in e)||Dr(e.container))&&Object.getOwnPropertyNames(e).length>=1),Ar=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&`from`in e&&`to`in e&&Object.getOwnPropertyNames(e).every((e,t)=>br[5].test(e)||!1)&&Dr(e.from)&&Dr(e.to)&&(e.kind===void 0||!(`kind`in e)||Er(e.kind))&&(e.ref===void 0||!(`ref`in e)||Cr(e.ref))&&(e.label===void 0||!(`label`in e)||Tr(e.label))&&(e.set===void 0||!(`set`in e)||jr(e.set))&&(typeof e!=`object`||!e||Array.isArray(e)||`ref`in e?!0:!(typeof e==`object`&&e&&!Array.isArray(e))||`kind`in e)),jr=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&Object.getOwnPropertyNames(e).every((e,t)=>br[6].test(e)||!1)&&(e.kind===void 0||!(`kind`in e)||Er(e.kind))&&(e.label===void 0||!(`label`in e)||Tr(e.label))&&Object.getOwnPropertyNames(e).length>=1),Mr=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&`id`in e&&`label`in e&&Object.getOwnPropertyNames(e).every((e,t)=>br[7].test(e)||!1)&&Dr(e.id)&&Tr(e.label)&&(e.kind===void 0||!(`kind`in e)||Er(e.kind))),Nr=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&`from`in e&&`to`in e&&Object.getOwnPropertyNames(e).every((e,t)=>br[9].test(e)||!1)&&Dr(e.from)&&Dr(e.to)&&(e.ref===void 0||!(`ref`in e)||Cr(e.ref))&&(e.label===void 0||!(`label`in e)||Tr(e.label))&&(e.set===void 0||!(`set`in e)||Pr(e.set))&&(typeof e!=`object`||!e||Array.isArray(e)||`ref`in e?!0:!(typeof e==`object`&&e&&!Array.isArray(e))||`label`in e)),Pr=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&Object.getOwnPropertyNames(e).every((e,t)=>br[10].test(e)||!1)&&(e.label===void 0||!(`label`in e)||Tr(e.label))&&Object.getOwnPropertyNames(e).length>=1),Fr=(e=>Array.isArray(e)&&e.every((e,t)=>(typeof e==`string`||Number.isFinite(e)||typeof e==`boolean`||e===null)&&(typeof e!=`string`||fr(e,1e3)))&&e.length<=50);function Ir(e){return Sr(e)}xr({variables:[RegExp(`(^schema$|^kind$|^target$|^removals$|^data$)`,`u`),RegExp(`(^type$|^ref$|^label$|^kind$|^from$|^to$)`,`u`),RegExp(`(^nodes$|^edges$|^containers$)`,`u`),RegExp(`(^id$|^ref$|^label$|^kind$|^set$|^container$)`,`u`),RegExp(`(^label$|^kind$|^container$)`,`u`),RegExp(`(^from$|^to$|^kind$|^ref$|^label$|^set$)`,`u`),RegExp(`(^kind$|^label$)`,`u`),RegExp(`(^id$|^label$|^kind$)`,`u`),RegExp(`(^participants$|^messages$|^containers$)`,`u`),RegExp(`(^from$|^to$|^ref$|^label$|^set$)`,`u`),RegExp(`(^label$)`,`u`),RegExp(`(^cells$|^role$)`,`u`)]});function Lr(){throw Error(`Unreachable`)}function Rr(e){let t=new Set,n=e;for(;n&&n!==Object.prototype;){for(let e of Reflect.ownKeys(n))e!==`constructor`&&typeof e!=`symbol`&&t.add(e);n=Object.getPrototypeOf(n)}return[...t]}function zr(e){return typeof e==`number`}var Br;(function(e){e[e.Array=0]=`Array`,e[e.BigInt=1]=`BigInt`,e[e.Boolean=2]=`Boolean`,e[e.Date=3]=`Date`,e[e.Constructor=4]=`Constructor`,e[e.Function=5]=`Function`,e[e.Null=6]=`Null`,e[e.Number=7]=`Number`,e[e.Object=8]=`Object`,e[e.RegExp=9]=`RegExp`,e[e.String=10]=`String`,e[e.Symbol=11]=`Symbol`,e[e.TypeArray=12]=`TypeArray`,e[e.Undefined=13]=`Undefined`})(Br||={});var Vr=BigInt(`14695981039346656037`),[Hr,Ur]=[BigInt(`1099511628211`),BigInt(`18446744073709551616`)],Wr=Array.from({length:256}).map((e,t)=>BigInt(t)),Gr=new Float64Array(1),Kr=new DataView(Gr.buffer),qr=new Uint8Array(Gr.buffer);function Jr(e){Vr^=Wr[e],Vr=Vr*Hr%Ur}function Yr(e){Jr(Br.Array);for(let t of e)ui(t)}function Xr(e){Jr(Br.BigInt),Kr.setBigInt64(0,e);for(let e of qr)Jr(e)}function Zr(e){Jr(Br.Boolean),Jr(+!!e)}function Qr(e){Jr(Br.Constructor),ui(e.toString())}function $r(e){Jr(Br.Date),ui(e.getTime())}function ei(e){Jr(Br.Function),ui(e.toString())}function ti(e){Jr(Br.Null)}function ni(e){Jr(Br.Number),Kr.setFloat64(0,e,!0);for(let e of qr)Jr(e)}function ri(e){Jr(Br.Object);for(let t of Rr(e).sort())ui(t),ui(e[t])}function ii(e){Jr(Br.RegExp),oi(e.toString())}var ai=new TextEncoder;function oi(e){Jr(Br.String);for(let t of ai.encode(e))Jr(t)}function si(e){Jr(Br.Symbol),ui(e.toString())}function ci(e){Jr(Br.TypeArray);let t=new Uint8Array(e.buffer);for(let e=0;e<t.length;e++)Jr(t[e])}function li(e){return Jr(Br.Undefined)}function ui(e){return _r(e)?ci(e):yr(e)?$r(e):vr(e)?ii(e):mr(e)?Zr(e.valueOf()):gr(e)?oi(e.valueOf()):hr(e)?ni(e.valueOf()):zr(e)?ni(e):tr(e)?Yr(e):rr(e)?Zr(e):nr(e)?Xr(e):ir(e)?Qr(e):or(e)?ti(e):sr(e)?ri(e):cr(e)?oi(e):lr(e)?si(e):ur(e)?li(e):ar(e)?ei(e):Lr()}function di(e){return Vr=BigInt(`14695981039346656037`),ui(e),Vr}function fi(e){return di(e).toString(16).padStart(16,`0`)}var pi=[];function mi(e){pi=e.variables}var hi=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&`schema`in e&&`kind`in e&&`data`in e&&Object.getOwnPropertyNames(e).every((e,t)=>pi[0].test(e)||!1)&&e.schema===`urn:structured-exchange:2`&&(e.kind===`graph`||e.kind===`sequence`||e.kind===`table`)&&(e.profile===void 0||!(`profile`in e)||typeof e.profile==`string`&&fr(e.profile,200)&&pr(e.profile,1))&&(e.target===void 0||!(`target`in e)||typeof e.target==`object`&&e.target!==null&&!Array.isArray(e.target)&&`ref`in e.target&&Object.getOwnPropertyNames(e.target).every((e,t)=>pi[1].test(e)||!1)&&gi(e.target.ref)&&(e.target.revision===void 0||!(`revision`in e.target)||_i(e.target.revision)))&&(e.removals===void 0||!(`removals`in e)||Array.isArray(e.removals)&&e.removals.every((e,t)=>vi(e))&&e.removals.length<=500)&&(e.artifacts===void 0||!(`artifacts`in e)||Array.isArray(e.artifacts)&&e.artifacts.every((e,t)=>Si(e))&&e.artifacts.length<=50)&&(e.viewpoints===void 0||!(`viewpoints`in e)||Array.isArray(e.viewpoints)&&e.viewpoints.every((e,t)=>Ci(e))&&e.viewpoints.length<=20)&&[typeof e.data==`object`&&e.data!==null&&!Array.isArray(e.data)&&`nodes`in e.data&&`edges`in e.data&&Object.getOwnPropertyNames(e.data).every((e,t)=>pi[6].test(e)||!1)&&Array.isArray(e.data.nodes)&&e.data.nodes.every((e,t)=>wi(e))&&e.data.nodes.length<=500&&e.data.nodes.length>=1&&Array.isArray(e.data.edges)&&e.data.edges.every((e,t)=>Ii(e))&&e.data.edges.length<=2e3&&(e.data.containers===void 0||!(`containers`in e.data)||Array.isArray(e.data.containers)&&e.data.containers.every((e,t)=>Ri(e))&&e.data.containers.length<=50),typeof e.data==`object`&&e.data!==null&&!Array.isArray(e.data)&&`participants`in e.data&&`messages`in e.data&&Object.getOwnPropertyNames(e.data).every((e,t)=>pi[16].test(e)||!1)&&Array.isArray(e.data.participants)&&e.data.participants.every((e,t)=>wi(e))&&e.data.participants.length<=100&&e.data.participants.length>=1&&Array.isArray(e.data.messages)&&e.data.messages.every((e,t)=>zi(e))&&e.data.messages.length<=1e3&&(e.data.containers===void 0||!(`containers`in e.data)||Array.isArray(e.data.containers)&&e.data.containers.every((e,t)=>Ri(e))&&e.data.containers.length<=50),typeof e.data==`object`&&e.data!==null&&!Array.isArray(e.data)&&`columns`in e.data&&`rows`in e.data&&Object.getOwnPropertyNames(e.data).every((e,t)=>pi[19].test(e)||!1)&&Array.isArray(e.data.columns)&&e.data.columns.every((e,t)=>typeof e==`string`&&fr(e,200)&&pr(e,1))&&e.data.columns.length<=50&&e.data.columns.length>=1&&Array.isArray(e.data.rows)&&e.data.rows.every((e,t)=>[Vi(e),Hi(e),Gi(e)].reduce((e,t,n)=>t===!0?++e:e,0)===1)&&e.data.rows.length<=5e3&&(e.data.relations===void 0||!(`relations`in e.data)||Array.isArray(e.data.relations)&&e.data.relations.every((e,t)=>Ki(e))&&e.data.relations.length<=2e3)].reduce((e,t,n)=>t===!0?++e:e,0)===1),gi=(e=>typeof e==`string`&&fr(e,200)&&pr(e,1)),_i=(e=>typeof e==`string`&&fr(e,200)&&pr(e,1)),vi=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&`type`in e&&`ref`in e&&Object.getOwnPropertyNames(e).every((e,t)=>pi[2].test(e)||!1)&&(e.type===`element`||e.type===`relationship`||e.type===`row`)&&gi(e.ref)&&(e.label===void 0||!(`label`in e)||yi(e.label))&&(e.kind===void 0||!(`kind`in e)||bi(e.kind))&&(e.from===void 0||!(`from`in e)||xi(e.from))&&(e.to===void 0||!(`to`in e)||xi(e.to))),yi=(e=>typeof e==`string`&&fr(e,500)),bi=(e=>typeof e==`string`&&fr(e,100)&&pr(e,1)),xi=(e=>typeof e==`string`&&fr(e,200)&&pr(e,1)),Si=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&`rel`in e&&`uri`in e&&`sha256`in e&&Object.getOwnPropertyNames(e).every((e,t)=>pi[3].test(e)||!1)&&typeof e.rel==`string`&&fr(e.rel,100)&&pr(e.rel,1)&&typeof e.uri==`string`&&fr(e.uri,2e3)&&pr(e.uri,1)&&typeof e.sha256==`string`&&pi[4].test(e.sha256)&&(e.mediaType===void 0||!(`mediaType`in e)||typeof e.mediaType==`string`&&fr(e.mediaType,100)&&pr(e.mediaType,1))&&(e.label===void 0||!(`label`in e)||yi(e.label))),Ci=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&`id`in e&&`label`in e&&`concern`in e&&Object.getOwnPropertyNames(e).every((e,t)=>pi[5].test(e)||!1)&&xi(e.id)&&typeof e.label==`string`&&fr(e.label,500)&&pr(e.label,1)&&typeof e.concern==`string`&&fr(e.concern,500)&&pr(e.concern,1)&&(e.elementKinds===void 0||!(`elementKinds`in e)||Array.isArray(e.elementKinds)&&e.elementKinds.every((e,t)=>bi(e))&&e.elementKinds.length<=64&&e.elementKinds.length>=1&&new Set(e.elementKinds.map(fi)).size===e.elementKinds.length)&&(e.relationshipKinds===void 0||!(`relationshipKinds`in e)||Array.isArray(e.relationshipKinds)&&e.relationshipKinds.every((e,t)=>bi(e))&&e.relationshipKinds.length<=64&&e.relationshipKinds.length>=1&&new Set(e.relationshipKinds.map(fi)).size===e.relationshipKinds.length)),wi=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&`id`in e&&Object.getOwnPropertyNames(e).every((e,t)=>pi[7].test(e)||!1)&&xi(e.id)&&(e.ref===void 0||!(`ref`in e)||gi(e.ref))&&(e.label===void 0||!(`label`in e)||yi(e.label))&&(e.kind===void 0||!(`kind`in e)||bi(e.kind))&&(e.set===void 0||!(`set`in e)||Ti(e.set))&&(e.container===void 0||!(`container`in e)||xi(e.container))&&(e.attributes===void 0||!(`attributes`in e)||Ei(e.attributes))&&(e.expect===void 0||!(`expect`in e)||ji(e.expect))&&(e.locations===void 0||!(`locations`in e)||Mi(e.locations))&&(e.artifacts===void 0||!(`artifacts`in e)||Fi(e.artifacts))&&(typeof e!=`object`||!e||Array.isArray(e)||`ref`in e?!0:!(typeof e==`object`&&e&&!Array.isArray(e))||`label`in e)),Ti=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&Object.getOwnPropertyNames(e).every((e,t)=>pi[8].test(e)||!1)&&(e.label===void 0||!(`label`in e)||yi(e.label))&&(e.kind===void 0||!(`kind`in e)||bi(e.kind))&&(e.container===void 0||!(`container`in e)||xi(e.container))&&(e.attributes===void 0||!(`attributes`in e)||Ei(e.attributes))&&(e.removeAttributes===void 0||!(`removeAttributes`in e)||Ai(e.removeAttributes))&&Object.getOwnPropertyNames(e).length>=1),Ei=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&Object.getOwnPropertyNames(e).every((t,n)=>pi[9].test(t)||Di(e[t]))&&Object.getOwnPropertyNames(e).every((e,t)=>typeof e!=`string`||fr(e,200)&&pr(e,1))&&Object.getOwnPropertyNames(e).length<=50),Di=(e=>[Oi(e),ki(e),Array.isArray(e)&&e.every((e,t)=>[Oi(e),ki(e)].reduce((e,t,n)=>t===!0?++e:e,0)===1)&&e.length<=50].reduce((e,t,n)=>t===!0?++e:e,0)===1),Oi=(e=>(typeof e==`string`||Number.isFinite(e)||typeof e==`boolean`||e===null)&&(typeof e!=`string`||fr(e,1e3))),ki=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&`ref`in e&&Object.getOwnPropertyNames(e).length===1&&gi(e.ref)),Ai=(e=>Array.isArray(e)&&e.every((e,t)=>xi(e))&&e.length<=50),ji=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&Object.getOwnPropertyNames(e).every((e,t)=>pi[10].test(e)||!1)&&(e.label===void 0||!(`label`in e)||yi(e.label))&&(e.kind===void 0||!(`kind`in e)||bi(e.kind))&&(e.container===void 0||!(`container`in e)||xi(e.container))&&(e.revision===void 0||!(`revision`in e)||_i(e.revision))&&(e.attributes===void 0||!(`attributes`in e)||Ei(e.attributes))&&Object.getOwnPropertyNames(e).length>=1),Mi=(e=>Array.isArray(e)&&e.every((e,t)=>Ni(e))&&e.length<=10),Ni=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&`uri`in e&&Object.getOwnPropertyNames(e).every((e,t)=>pi[11].test(e)||!1)&&typeof e.uri==`string`&&fr(e.uri,2e3)&&pr(e.uri,1)&&(e.revision===void 0||!(`revision`in e)||_i(e.revision))&&(e.range===void 0||!(`range`in e)||typeof e.range==`object`&&e.range!==null&&!Array.isArray(e.range)&&`startLine`in e.range&&`endLine`in e.range&&Object.getOwnPropertyNames(e.range).every((e,t)=>pi[12].test(e)||!1)&&Pi(e.range.startLine)&&(e.range.startCharacter===void 0||!(`startCharacter`in e.range)||Pi(e.range.startCharacter))&&Pi(e.range.endLine)&&(e.range.endCharacter===void 0||!(`endCharacter`in e.range)||Pi(e.range.endCharacter)))),Pi=(e=>Number.isInteger(e)&&(!(Number.isFinite(e)||typeof e==`bigint`)||e<=1e6&&e>=0)),Fi=(e=>Array.isArray(e)&&e.every((e,t)=>Si(e))&&e.length<=20),Ii=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&`from`in e&&`to`in e&&Object.getOwnPropertyNames(e).every((e,t)=>pi[13].test(e)||!1)&&xi(e.from)&&xi(e.to)&&(e.kind===void 0||!(`kind`in e)||bi(e.kind))&&(e.ref===void 0||!(`ref`in e)||gi(e.ref))&&(e.label===void 0||!(`label`in e)||yi(e.label))&&(e.set===void 0||!(`set`in e)||Li(e.set))&&(e.attributes===void 0||!(`attributes`in e)||Ei(e.attributes))&&(e.expect===void 0||!(`expect`in e)||ji(e.expect))&&(e.locations===void 0||!(`locations`in e)||Mi(e.locations))&&(e.artifacts===void 0||!(`artifacts`in e)||Fi(e.artifacts))&&(typeof e!=`object`||!e||Array.isArray(e)||`ref`in e?!0:!(typeof e==`object`&&e&&!Array.isArray(e))||`kind`in e)),Li=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&Object.getOwnPropertyNames(e).every((e,t)=>pi[14].test(e)||!1)&&(e.kind===void 0||!(`kind`in e)||bi(e.kind))&&(e.label===void 0||!(`label`in e)||yi(e.label))&&(e.attributes===void 0||!(`attributes`in e)||Ei(e.attributes))&&(e.removeAttributes===void 0||!(`removeAttributes`in e)||Ai(e.removeAttributes))&&Object.getOwnPropertyNames(e).length>=1),Ri=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&`id`in e&&`label`in e&&Object.getOwnPropertyNames(e).every((e,t)=>pi[15].test(e)||!1)&&xi(e.id)&&yi(e.label)&&(e.kind===void 0||!(`kind`in e)||bi(e.kind))),zi=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&`from`in e&&`to`in e&&Object.getOwnPropertyNames(e).every((e,t)=>pi[17].test(e)||!1)&&xi(e.from)&&xi(e.to)&&(e.ref===void 0||!(`ref`in e)||gi(e.ref))&&(e.label===void 0||!(`label`in e)||yi(e.label))&&(e.set===void 0||!(`set`in e)||Bi(e.set))&&(e.attributes===void 0||!(`attributes`in e)||Ei(e.attributes))&&(e.expect===void 0||!(`expect`in e)||ji(e.expect))&&(e.locations===void 0||!(`locations`in e)||Mi(e.locations))&&(e.artifacts===void 0||!(`artifacts`in e)||Fi(e.artifacts))&&(typeof e!=`object`||!e||Array.isArray(e)||`ref`in e?!0:!(typeof e==`object`&&e&&!Array.isArray(e))||`label`in e)),Bi=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&Object.getOwnPropertyNames(e).every((e,t)=>pi[18].test(e)||!1)&&(e.label===void 0||!(`label`in e)||yi(e.label))&&(e.attributes===void 0||!(`attributes`in e)||Ei(e.attributes))&&(e.removeAttributes===void 0||!(`removeAttributes`in e)||Ai(e.removeAttributes))&&Object.getOwnPropertyNames(e).length>=1),Vi=(e=>Array.isArray(e)&&e.every((e,t)=>(typeof e==`string`||Number.isFinite(e)||typeof e==`boolean`||e===null)&&(typeof e!=`string`||fr(e,1e3)))&&e.length<=50),Hi=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&`cells`in e&&Object.getOwnPropertyNames(e).every((e,t)=>pi[20].test(e)||!1)&&Vi(e.cells)&&(e.role===void 0||!(`role`in e)||Ui(e.role))&&(e.id===void 0||!(`id`in e)||xi(e.id))&&(e.ref===void 0||!(`ref`in e)||gi(e.ref))&&(e.kind===void 0||!(`kind`in e)||bi(e.kind))&&(e.label===void 0||!(`label`in e)||yi(e.label))&&(e.set===void 0||!(`set`in e)||Wi(e.set))&&(e.attributes===void 0||!(`attributes`in e)||Ei(e.attributes))&&(e.expect===void 0||!(`expect`in e)||ji(e.expect))&&(e.locations===void 0||!(`locations`in e)||Mi(e.locations))&&(e.artifacts===void 0||!(`artifacts`in e)||Fi(e.artifacts))),Ui=(e=>e===`added`||e===`changed`||e===`context`||e===`removed`),Wi=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&Object.getOwnPropertyNames(e).every((e,t)=>pi[21].test(e)||!1)&&(e.label===void 0||!(`label`in e)||yi(e.label))&&(e.kind===void 0||!(`kind`in e)||bi(e.kind))&&(e.cells===void 0||!(`cells`in e)||Vi(e.cells))&&(e.attributes===void 0||!(`attributes`in e)||Ei(e.attributes))&&(e.removeAttributes===void 0||!(`removeAttributes`in e)||Ai(e.removeAttributes))&&Object.getOwnPropertyNames(e).length>=1),Gi=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&`heading`in e&&Object.getOwnPropertyNames(e).every((e,t)=>pi[22].test(e)||!1)&&typeof e.heading==`string`&&fr(e.heading,500)&&pr(e.heading,1)&&(e.depth===void 0||!(`depth`in e)||Number.isInteger(e.depth)&&(!(Number.isFinite(e.depth)||typeof e.depth==`bigint`)||e.depth<=6&&e.depth>=1))&&(e.role===void 0||!(`role`in e)||Ui(e.role))&&(e.id===void 0||!(`id`in e)||xi(e.id))&&(e.ref===void 0||!(`ref`in e)||gi(e.ref))),Ki=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&`from`in e&&`to`in e&&`kind`in e&&Object.getOwnPropertyNames(e).every((e,t)=>pi[23].test(e)||!1)&&qi(e.from)&&qi(e.to)&&bi(e.kind)&&(e.ref===void 0||!(`ref`in e)||gi(e.ref))&&(e.label===void 0||!(`label`in e)||yi(e.label))&&(e.attributes===void 0||!(`attributes`in e)||Ei(e.attributes))),qi=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&Object.getOwnPropertyNames(e).every((e,t)=>pi[24].test(e)||!1)&&(e.id===void 0||!(`id`in e)||xi(e.id))&&(e.ref===void 0||!(`ref`in e)||gi(e.ref))&&Object.getOwnPropertyNames(e).length>=1&&Object.getOwnPropertyNames(e).length<=1&&[!(typeof e==`object`&&e&&!Array.isArray(e))||`id`in e,!(typeof e==`object`&&e&&!Array.isArray(e))||`ref`in e].reduce((e,t,n)=>t===!0?++e:e,0)===1);function Ji(e){return hi(e)}mi({variables:[RegExp(`(^schema$|^kind$|^profile$|^target$|^removals$|^artifacts$|^viewpoints$|^data$)`,`u`),RegExp(`(^ref$|^revision$)`,`u`),RegExp(`(^type$|^ref$|^label$|^kind$|^from$|^to$)`,`u`),RegExp(`(^rel$|^uri$|^sha256$|^mediaType$|^label$)`,`u`),RegExp(`^sha256:[0-9a-f]{64}$`,`u`),RegExp(`(^id$|^label$|^concern$|^elementKinds$|^relationshipKinds$)`,`u`),RegExp(`(^nodes$|^edges$|^containers$)`,`u`),RegExp(`(^id$|^ref$|^label$|^kind$|^set$|^container$|^attributes$|^expect$|^locations$|^artifacts$)`,`u`),RegExp(`(^label$|^kind$|^container$|^attributes$|^removeAttributes$)`,`u`),RegExp(`(?!)`,`u`),RegExp(`(^label$|^kind$|^container$|^revision$|^attributes$)`,`u`),RegExp(`(^uri$|^revision$|^range$)`,`u`),RegExp(`(^startLine$|^startCharacter$|^endLine$|^endCharacter$)`,`u`),RegExp(`(^from$|^to$|^kind$|^ref$|^label$|^set$|^attributes$|^expect$|^locations$|^artifacts$)`,`u`),RegExp(`(^kind$|^label$|^attributes$|^removeAttributes$)`,`u`),RegExp(`(^id$|^label$|^kind$)`,`u`),RegExp(`(^participants$|^messages$|^containers$)`,`u`),RegExp(`(^from$|^to$|^ref$|^label$|^set$|^attributes$|^expect$|^locations$|^artifacts$)`,`u`),RegExp(`(^label$|^attributes$|^removeAttributes$)`,`u`),RegExp(`(^columns$|^rows$|^relations$)`,`u`),RegExp(`(^cells$|^role$|^id$|^ref$|^kind$|^label$|^set$|^attributes$|^expect$|^locations$|^artifacts$)`,`u`),RegExp(`(^label$|^kind$|^cells$|^attributes$|^removeAttributes$)`,`u`),RegExp(`(^heading$|^depth$|^role$|^id$|^ref$)`,`u`),RegExp(`(^from$|^to$|^kind$|^ref$|^label$|^attributes$)`,`u`),RegExp(`(^id$|^ref$)`,`u`)]});var Yi=[];function Xi(e){Yi=e.variables}var Zi=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&`schema`in e&&`kind`in e&&`data`in e&&Object.getOwnPropertyNames(e).every((e,t)=>Yi[0].test(e)||!1)&&e.schema===`urn:structured-exchange:3`&&(e.kind===`graph`||e.kind===`sequence`||e.kind===`table`||e.kind===`timeline`)&&(e.profile===void 0||!(`profile`in e)||typeof e.profile==`string`&&fr(e.profile,200)&&pr(e.profile,1))&&(e.target===void 0||!(`target`in e)||typeof e.target==`object`&&e.target!==null&&!Array.isArray(e.target)&&`ref`in e.target&&Object.getOwnPropertyNames(e.target).every((e,t)=>Yi[1].test(e)||!1)&&Qi(e.target.ref)&&(e.target.revision===void 0||!(`revision`in e.target)||$i(e.target.revision)))&&(e.removals===void 0||!(`removals`in e)||Array.isArray(e.removals)&&e.removals.every((e,t)=>ea(e))&&e.removals.length<=500)&&(e.artifacts===void 0||!(`artifacts`in e)||Array.isArray(e.artifacts)&&e.artifacts.every((e,t)=>ia(e))&&e.artifacts.length<=50)&&(e.viewpoints===void 0||!(`viewpoints`in e)||Array.isArray(e.viewpoints)&&e.viewpoints.every((e,t)=>aa(e))&&e.viewpoints.length<=20)&&[typeof e.data==`object`&&e.data!==null&&!Array.isArray(e.data)&&`nodes`in e.data&&`edges`in e.data&&Object.getOwnPropertyNames(e.data).every((e,t)=>Yi[6].test(e)||!1)&&Array.isArray(e.data.nodes)&&e.data.nodes.every((e,t)=>oa(e))&&e.data.nodes.length<=500&&e.data.nodes.length>=1&&Array.isArray(e.data.edges)&&e.data.edges.every((e,t)=>va(e))&&e.data.edges.length<=2e3&&(e.data.containers===void 0||!(`containers`in e.data)||Array.isArray(e.data.containers)&&e.data.containers.every((e,t)=>ba(e))&&e.data.containers.length<=50),typeof e.data==`object`&&e.data!==null&&!Array.isArray(e.data)&&`participants`in e.data&&`messages`in e.data&&Object.getOwnPropertyNames(e.data).every((e,t)=>Yi[16].test(e)||!1)&&Array.isArray(e.data.participants)&&e.data.participants.every((e,t)=>oa(e))&&e.data.participants.length<=100&&e.data.participants.length>=1&&Array.isArray(e.data.messages)&&e.data.messages.every((e,t)=>xa(e))&&e.data.messages.length<=1e3&&(e.data.containers===void 0||!(`containers`in e.data)||Array.isArray(e.data.containers)&&e.data.containers.every((e,t)=>ba(e))&&e.data.containers.length<=50),typeof e.data==`object`&&e.data!==null&&!Array.isArray(e.data)&&`columns`in e.data&&`rows`in e.data&&Object.getOwnPropertyNames(e.data).every((e,t)=>Yi[19].test(e)||!1)&&Array.isArray(e.data.columns)&&e.data.columns.every((e,t)=>typeof e==`string`&&fr(e,200)&&pr(e,1))&&e.data.columns.length<=50&&e.data.columns.length>=1&&Array.isArray(e.data.rows)&&e.data.rows.every((e,t)=>[Ca(e),wa(e),Da(e)].reduce((e,t,n)=>t===!0?++e:e,0)===1)&&e.data.rows.length<=5e3&&(e.data.relations===void 0||!(`relations`in e.data)||Array.isArray(e.data.relations)&&e.data.relations.every((e,t)=>Oa(e))&&e.data.relations.length<=2e3),typeof e.data==`object`&&e.data!==null&&!Array.isArray(e.data)&&`time`in e.data&&`rows`in e.data&&Object.getOwnPropertyNames(e.data).every((e,t)=>Yi[25].test(e)||!1)&&(e.data.title===void 0||!(`title`in e.data)||ta(e.data.title))&&typeof e.data.time==`object`&&e.data.time!==null&&!Array.isArray(e.data.time)&&`start`in e.data.time&&`end`in e.data.time&&`scale`in e.data.time&&Object.getOwnPropertyNames(e.data.time).length===3&&Aa(e.data.time.start)&&Aa(e.data.time.end)&&(e.data.time.scale===`week`||e.data.time.scale===`month`||e.data.time.scale===`quarter`)&&Array.isArray(e.data.rows)&&e.data.rows.every((e,t)=>ja(e))&&e.data.rows.length<=500&&(e.data.dependencies===void 0||!(`dependencies`in e.data)||Array.isArray(e.data.dependencies)&&e.data.dependencies.every((e,t)=>Ra(e))&&e.data.dependencies.length<=2e3)&&(e.data.comparedTo===void 0||!(`comparedTo`in e.data)||typeof e.data.comparedTo==`object`&&e.data.comparedTo!==null&&!Array.isArray(e.data.comparedTo)&&`label`in e.data.comparedTo&&Object.getOwnPropertyNames(e.data.comparedTo).every((e,t)=>Yi[32].test(e)||!1)&&typeof e.data.comparedTo.label==`string`&&fr(e.data.comparedTo.label,500)&&pr(e.data.comparedTo.label,1)&&(e.data.comparedTo.date===void 0||!(`date`in e.data.comparedTo)||Aa(e.data.comparedTo.date)))&&(e.data.periods===void 0||!(`periods`in e.data)||Array.isArray(e.data.periods)&&e.data.periods.every((e,t)=>za(e))&&e.data.periods.length<=100)&&(e.data.references===void 0||!(`references`in e.data)||Array.isArray(e.data.references)&&e.data.references.every((e,t)=>Ba(e))&&e.data.references.length<=50)].reduce((e,t,n)=>t===!0?++e:e,0)===1),Qi=(e=>typeof e==`string`&&fr(e,200)&&pr(e,1)),$i=(e=>typeof e==`string`&&fr(e,200)&&pr(e,1)),ea=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&`type`in e&&`ref`in e&&Object.getOwnPropertyNames(e).every((e,t)=>Yi[2].test(e)||!1)&&(e.type===`element`||e.type===`relationship`||e.type===`row`)&&Qi(e.ref)&&(e.label===void 0||!(`label`in e)||ta(e.label))&&(e.kind===void 0||!(`kind`in e)||na(e.kind))&&(e.from===void 0||!(`from`in e)||ra(e.from))&&(e.to===void 0||!(`to`in e)||ra(e.to))),ta=(e=>typeof e==`string`&&fr(e,500)),na=(e=>typeof e==`string`&&fr(e,100)&&pr(e,1)),ra=(e=>typeof e==`string`&&fr(e,200)&&pr(e,1)),ia=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&`rel`in e&&`uri`in e&&`sha256`in e&&Object.getOwnPropertyNames(e).every((e,t)=>Yi[3].test(e)||!1)&&typeof e.rel==`string`&&fr(e.rel,100)&&pr(e.rel,1)&&typeof e.uri==`string`&&fr(e.uri,2e3)&&pr(e.uri,1)&&typeof e.sha256==`string`&&Yi[4].test(e.sha256)&&(e.mediaType===void 0||!(`mediaType`in e)||typeof e.mediaType==`string`&&fr(e.mediaType,100)&&pr(e.mediaType,1))&&(e.label===void 0||!(`label`in e)||ta(e.label))),aa=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&`id`in e&&`label`in e&&`concern`in e&&Object.getOwnPropertyNames(e).every((e,t)=>Yi[5].test(e)||!1)&&ra(e.id)&&typeof e.label==`string`&&fr(e.label,500)&&pr(e.label,1)&&typeof e.concern==`string`&&fr(e.concern,500)&&pr(e.concern,1)&&(e.elementKinds===void 0||!(`elementKinds`in e)||Array.isArray(e.elementKinds)&&e.elementKinds.every((e,t)=>na(e))&&e.elementKinds.length<=64&&e.elementKinds.length>=1&&new Set(e.elementKinds.map(fi)).size===e.elementKinds.length)&&(e.relationshipKinds===void 0||!(`relationshipKinds`in e)||Array.isArray(e.relationshipKinds)&&e.relationshipKinds.every((e,t)=>na(e))&&e.relationshipKinds.length<=64&&e.relationshipKinds.length>=1&&new Set(e.relationshipKinds.map(fi)).size===e.relationshipKinds.length)),oa=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&`id`in e&&Object.getOwnPropertyNames(e).every((e,t)=>Yi[7].test(e)||!1)&&ra(e.id)&&(e.ref===void 0||!(`ref`in e)||Qi(e.ref))&&(e.label===void 0||!(`label`in e)||ta(e.label))&&(e.kind===void 0||!(`kind`in e)||na(e.kind))&&(e.set===void 0||!(`set`in e)||sa(e.set))&&(e.container===void 0||!(`container`in e)||ra(e.container))&&(e.attributes===void 0||!(`attributes`in e)||ca(e.attributes))&&(e.expect===void 0||!(`expect`in e)||pa(e.expect))&&(e.locations===void 0||!(`locations`in e)||ma(e.locations))&&(e.artifacts===void 0||!(`artifacts`in e)||_a(e.artifacts))&&(typeof e!=`object`||!e||Array.isArray(e)||`ref`in e?!0:!(typeof e==`object`&&e&&!Array.isArray(e))||`label`in e)),sa=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&Object.getOwnPropertyNames(e).every((e,t)=>Yi[8].test(e)||!1)&&(e.label===void 0||!(`label`in e)||ta(e.label))&&(e.kind===void 0||!(`kind`in e)||na(e.kind))&&(e.container===void 0||!(`container`in e)||ra(e.container))&&(e.attributes===void 0||!(`attributes`in e)||ca(e.attributes))&&(e.removeAttributes===void 0||!(`removeAttributes`in e)||fa(e.removeAttributes))&&Object.getOwnPropertyNames(e).length>=1),ca=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&Object.getOwnPropertyNames(e).every((t,n)=>Yi[9].test(t)||la(e[t]))&&Object.getOwnPropertyNames(e).every((e,t)=>typeof e!=`string`||fr(e,200)&&pr(e,1))&&Object.getOwnPropertyNames(e).length<=50),la=(e=>[ua(e),da(e),Array.isArray(e)&&e.every((e,t)=>[ua(e),da(e)].reduce((e,t,n)=>t===!0?++e:e,0)===1)&&e.length<=50].reduce((e,t,n)=>t===!0?++e:e,0)===1),ua=(e=>(typeof e==`string`||Number.isFinite(e)||typeof e==`boolean`||e===null)&&(typeof e!=`string`||fr(e,1e3))),da=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&`ref`in e&&Object.getOwnPropertyNames(e).length===1&&Qi(e.ref)),fa=(e=>Array.isArray(e)&&e.every((e,t)=>ra(e))&&e.length<=50),pa=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&Object.getOwnPropertyNames(e).every((e,t)=>Yi[10].test(e)||!1)&&(e.label===void 0||!(`label`in e)||ta(e.label))&&(e.kind===void 0||!(`kind`in e)||na(e.kind))&&(e.container===void 0||!(`container`in e)||ra(e.container))&&(e.revision===void 0||!(`revision`in e)||$i(e.revision))&&(e.attributes===void 0||!(`attributes`in e)||ca(e.attributes))&&Object.getOwnPropertyNames(e).length>=1),ma=(e=>Array.isArray(e)&&e.every((e,t)=>ha(e))&&e.length<=10),ha=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&`uri`in e&&Object.getOwnPropertyNames(e).every((e,t)=>Yi[11].test(e)||!1)&&typeof e.uri==`string`&&fr(e.uri,2e3)&&pr(e.uri,1)&&(e.revision===void 0||!(`revision`in e)||$i(e.revision))&&(e.range===void 0||!(`range`in e)||typeof e.range==`object`&&e.range!==null&&!Array.isArray(e.range)&&`startLine`in e.range&&`endLine`in e.range&&Object.getOwnPropertyNames(e.range).every((e,t)=>Yi[12].test(e)||!1)&&ga(e.range.startLine)&&(e.range.startCharacter===void 0||!(`startCharacter`in e.range)||ga(e.range.startCharacter))&&ga(e.range.endLine)&&(e.range.endCharacter===void 0||!(`endCharacter`in e.range)||ga(e.range.endCharacter)))),ga=(e=>Number.isInteger(e)&&(!(Number.isFinite(e)||typeof e==`bigint`)||e<=1e6&&e>=0)),_a=(e=>Array.isArray(e)&&e.every((e,t)=>ia(e))&&e.length<=20),va=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&`from`in e&&`to`in e&&Object.getOwnPropertyNames(e).every((e,t)=>Yi[13].test(e)||!1)&&ra(e.from)&&ra(e.to)&&(e.kind===void 0||!(`kind`in e)||na(e.kind))&&(e.ref===void 0||!(`ref`in e)||Qi(e.ref))&&(e.label===void 0||!(`label`in e)||ta(e.label))&&(e.set===void 0||!(`set`in e)||ya(e.set))&&(e.attributes===void 0||!(`attributes`in e)||ca(e.attributes))&&(e.expect===void 0||!(`expect`in e)||pa(e.expect))&&(e.locations===void 0||!(`locations`in e)||ma(e.locations))&&(e.artifacts===void 0||!(`artifacts`in e)||_a(e.artifacts))&&(typeof e!=`object`||!e||Array.isArray(e)||`ref`in e?!0:!(typeof e==`object`&&e&&!Array.isArray(e))||`kind`in e)),ya=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&Object.getOwnPropertyNames(e).every((e,t)=>Yi[14].test(e)||!1)&&(e.kind===void 0||!(`kind`in e)||na(e.kind))&&(e.label===void 0||!(`label`in e)||ta(e.label))&&(e.attributes===void 0||!(`attributes`in e)||ca(e.attributes))&&(e.removeAttributes===void 0||!(`removeAttributes`in e)||fa(e.removeAttributes))&&Object.getOwnPropertyNames(e).length>=1),ba=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&`id`in e&&`label`in e&&Object.getOwnPropertyNames(e).every((e,t)=>Yi[15].test(e)||!1)&&ra(e.id)&&ta(e.label)&&(e.kind===void 0||!(`kind`in e)||na(e.kind))),xa=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&`from`in e&&`to`in e&&Object.getOwnPropertyNames(e).every((e,t)=>Yi[17].test(e)||!1)&&ra(e.from)&&ra(e.to)&&(e.ref===void 0||!(`ref`in e)||Qi(e.ref))&&(e.label===void 0||!(`label`in e)||ta(e.label))&&(e.set===void 0||!(`set`in e)||Sa(e.set))&&(e.attributes===void 0||!(`attributes`in e)||ca(e.attributes))&&(e.expect===void 0||!(`expect`in e)||pa(e.expect))&&(e.locations===void 0||!(`locations`in e)||ma(e.locations))&&(e.artifacts===void 0||!(`artifacts`in e)||_a(e.artifacts))&&(typeof e!=`object`||!e||Array.isArray(e)||`ref`in e?!0:!(typeof e==`object`&&e&&!Array.isArray(e))||`label`in e)),Sa=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&Object.getOwnPropertyNames(e).every((e,t)=>Yi[18].test(e)||!1)&&(e.label===void 0||!(`label`in e)||ta(e.label))&&(e.attributes===void 0||!(`attributes`in e)||ca(e.attributes))&&(e.removeAttributes===void 0||!(`removeAttributes`in e)||fa(e.removeAttributes))&&Object.getOwnPropertyNames(e).length>=1),Ca=(e=>Array.isArray(e)&&e.every((e,t)=>(typeof e==`string`||Number.isFinite(e)||typeof e==`boolean`||e===null)&&(typeof e!=`string`||fr(e,1e3)))&&e.length<=50),wa=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&`cells`in e&&Object.getOwnPropertyNames(e).every((e,t)=>Yi[20].test(e)||!1)&&Ca(e.cells)&&(e.role===void 0||!(`role`in e)||Ta(e.role))&&(e.id===void 0||!(`id`in e)||ra(e.id))&&(e.ref===void 0||!(`ref`in e)||Qi(e.ref))&&(e.kind===void 0||!(`kind`in e)||na(e.kind))&&(e.label===void 0||!(`label`in e)||ta(e.label))&&(e.set===void 0||!(`set`in e)||Ea(e.set))&&(e.attributes===void 0||!(`attributes`in e)||ca(e.attributes))&&(e.expect===void 0||!(`expect`in e)||pa(e.expect))&&(e.locations===void 0||!(`locations`in e)||ma(e.locations))&&(e.artifacts===void 0||!(`artifacts`in e)||_a(e.artifacts))),Ta=(e=>e===`added`||e===`changed`||e===`context`||e===`removed`),Ea=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&Object.getOwnPropertyNames(e).every((e,t)=>Yi[21].test(e)||!1)&&(e.label===void 0||!(`label`in e)||ta(e.label))&&(e.kind===void 0||!(`kind`in e)||na(e.kind))&&(e.cells===void 0||!(`cells`in e)||Ca(e.cells))&&(e.attributes===void 0||!(`attributes`in e)||ca(e.attributes))&&(e.removeAttributes===void 0||!(`removeAttributes`in e)||fa(e.removeAttributes))&&Object.getOwnPropertyNames(e).length>=1),Da=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&`heading`in e&&Object.getOwnPropertyNames(e).every((e,t)=>Yi[22].test(e)||!1)&&typeof e.heading==`string`&&fr(e.heading,500)&&pr(e.heading,1)&&(e.depth===void 0||!(`depth`in e)||Number.isInteger(e.depth)&&(!(Number.isFinite(e.depth)||typeof e.depth==`bigint`)||e.depth<=6&&e.depth>=1))&&(e.role===void 0||!(`role`in e)||Ta(e.role))&&(e.id===void 0||!(`id`in e)||ra(e.id))&&(e.ref===void 0||!(`ref`in e)||Qi(e.ref))),Oa=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&`from`in e&&`to`in e&&`kind`in e&&Object.getOwnPropertyNames(e).every((e,t)=>Yi[23].test(e)||!1)&&ka(e.from)&&ka(e.to)&&na(e.kind)&&(e.ref===void 0||!(`ref`in e)||Qi(e.ref))&&(e.label===void 0||!(`label`in e)||ta(e.label))&&(e.attributes===void 0||!(`attributes`in e)||ca(e.attributes))),ka=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&Object.getOwnPropertyNames(e).every((e,t)=>Yi[24].test(e)||!1)&&(e.id===void 0||!(`id`in e)||ra(e.id))&&(e.ref===void 0||!(`ref`in e)||Qi(e.ref))&&Object.getOwnPropertyNames(e).length>=1&&Object.getOwnPropertyNames(e).length<=1&&[!(typeof e==`object`&&e&&!Array.isArray(e))||`id`in e,!(typeof e==`object`&&e&&!Array.isArray(e))||`ref`in e].reduce((e,t,n)=>t===!0?++e:e,0)===1),Aa=(e=>typeof e==`string`&&Yi[26].test(e)),ja=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&`type`in e&&(e.type===`task`||e.type===`separator`)&&(typeof e!=`object`||!e||Array.isArray(e)||e.type===void 0||!(`type`in e)||e.type===`task`?Ma(e):!0)&&(typeof e!=`object`||!e||Array.isArray(e)||e.type===void 0||!(`type`in e)||e.type===`separator`?La(e):!0)),Ma=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&`type`in e&&`id`in e&&`label`in e&&`items`in e&&Object.getOwnPropertyNames(e).every((e,t)=>Yi[27].test(e)||!1)&&e.type===`task`&&ra(e.id)&&ta(e.label)&&Array.isArray(e.items)&&e.items.every((e,t)=>Na(e))&&e.items.length<=100&&(e.role===void 0||!(`role`in e)||Fa(e.role))),Na=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&`type`in e&&(e.type===`activity`||e.type===`milestone`)&&(typeof e!=`object`||!e||Array.isArray(e)||e.type===void 0||!(`type`in e)||e.type===`activity`?Pa(e):!0)&&(typeof e!=`object`||!e||Array.isArray(e)||e.type===void 0||!(`type`in e)||e.type===`milestone`?Ia(e):!0)),Pa=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&`type`in e&&`start`in e&&`end`in e&&Object.getOwnPropertyNames(e).every((e,t)=>Yi[28].test(e)||!1)&&e.type===`activity`&&Aa(e.start)&&Aa(e.end)&&(e.id===void 0||!(`id`in e)||ra(e.id))&&(e.label===void 0||!(`label`in e)||ta(e.label))&&(e.kind===void 0||!(`kind`in e)||na(e.kind))&&(e.previous===void 0||!(`previous`in e)||typeof e.previous==`object`&&e.previous!==null&&!Array.isArray(e.previous)&&`start`in e.previous&&`end`in e.previous&&Object.getOwnPropertyNames(e.previous).length===2&&Aa(e.previous.start)&&Aa(e.previous.end))&&(e.role===void 0||!(`role`in e)||Fa(e.role))),Fa=(e=>e===`added`||e===`removed`),Ia=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&`type`in e&&`date`in e&&Object.getOwnPropertyNames(e).every((e,t)=>Yi[29].test(e)||!1)&&e.type===`milestone`&&Aa(e.date)&&(e.id===void 0||!(`id`in e)||ra(e.id))&&(e.label===void 0||!(`label`in e)||ta(e.label))&&(e.kind===void 0||!(`kind`in e)||na(e.kind))&&(e.previous===void 0||!(`previous`in e)||typeof e.previous==`object`&&e.previous!==null&&!Array.isArray(e.previous)&&`date`in e.previous&&Object.getOwnPropertyNames(e.previous).length===1&&Aa(e.previous.date))&&(e.role===void 0||!(`role`in e)||Fa(e.role))),La=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&`type`in e&&Object.getOwnPropertyNames(e).every((e,t)=>Yi[30].test(e)||!1)&&e.type===`separator`&&(e.label===void 0||!(`label`in e)||ta(e.label))),Ra=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&`from`in e&&`to`in e&&Object.getOwnPropertyNames(e).every((e,t)=>Yi[31].test(e)||!1)&&ra(e.from)&&ra(e.to)&&(e.type===void 0||!(`type`in e)||e.type===`finish-to-start`||e.type===`start-to-start`||e.type===`finish-to-finish`||e.type===`start-to-finish`)),za=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&`start`in e&&`end`in e&&Object.getOwnPropertyNames(e).every((e,t)=>Yi[33].test(e)||!1)&&Aa(e.start)&&Aa(e.end)&&(e.label===void 0||!(`label`in e)||ta(e.label))&&(e.kind===void 0||!(`kind`in e)||na(e.kind))),Ba=(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&`date`in e&&`label`in e&&Object.getOwnPropertyNames(e).every((e,t)=>Yi[34].test(e)||!1)&&Aa(e.date)&&typeof e.label==`string`&&fr(e.label,500)&&pr(e.label,1)&&(e.kind===void 0||!(`kind`in e)||na(e.kind)));function Va(e){return Zi(e)}Xi({variables:[RegExp(`(^schema$|^kind$|^profile$|^target$|^removals$|^artifacts$|^viewpoints$|^data$)`,`u`),RegExp(`(^ref$|^revision$)`,`u`),RegExp(`(^type$|^ref$|^label$|^kind$|^from$|^to$)`,`u`),RegExp(`(^rel$|^uri$|^sha256$|^mediaType$|^label$)`,`u`),RegExp(`^sha256:[0-9a-f]{64}$`,`u`),RegExp(`(^id$|^label$|^concern$|^elementKinds$|^relationshipKinds$)`,`u`),RegExp(`(^nodes$|^edges$|^containers$)`,`u`),RegExp(`(^id$|^ref$|^label$|^kind$|^set$|^container$|^attributes$|^expect$|^locations$|^artifacts$)`,`u`),RegExp(`(^label$|^kind$|^container$|^attributes$|^removeAttributes$)`,`u`),RegExp(`(?!)`,`u`),RegExp(`(^label$|^kind$|^container$|^revision$|^attributes$)`,`u`),RegExp(`(^uri$|^revision$|^range$)`,`u`),RegExp(`(^startLine$|^startCharacter$|^endLine$|^endCharacter$)`,`u`),RegExp(`(^from$|^to$|^kind$|^ref$|^label$|^set$|^attributes$|^expect$|^locations$|^artifacts$)`,`u`),RegExp(`(^kind$|^label$|^attributes$|^removeAttributes$)`,`u`),RegExp(`(^id$|^label$|^kind$)`,`u`),RegExp(`(^participants$|^messages$|^containers$)`,`u`),RegExp(`(^from$|^to$|^ref$|^label$|^set$|^attributes$|^expect$|^locations$|^artifacts$)`,`u`),RegExp(`(^label$|^attributes$|^removeAttributes$)`,`u`),RegExp(`(^columns$|^rows$|^relations$)`,`u`),RegExp(`(^cells$|^role$|^id$|^ref$|^kind$|^label$|^set$|^attributes$|^expect$|^locations$|^artifacts$)`,`u`),RegExp(`(^label$|^kind$|^cells$|^attributes$|^removeAttributes$)`,`u`),RegExp(`(^heading$|^depth$|^role$|^id$|^ref$)`,`u`),RegExp(`(^from$|^to$|^kind$|^ref$|^label$|^attributes$)`,`u`),RegExp(`(^id$|^ref$)`,`u`),RegExp(`(^title$|^time$|^rows$|^dependencies$|^comparedTo$|^periods$|^references$)`,`u`),RegExp(`^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$`,`u`),RegExp(`(^type$|^id$|^label$|^items$|^role$)`,`u`),RegExp(`(^type$|^start$|^end$|^id$|^label$|^kind$|^previous$|^role$)`,`u`),RegExp(`(^type$|^date$|^id$|^label$|^kind$|^previous$|^role$)`,`u`),RegExp(`(^type$|^label$)`,`u`),RegExp(`(^from$|^to$|^type$)`,`u`),RegExp(`(^label$|^date$)`,`u`),RegExp(`(^start$|^end$|^label$|^kind$)`,`u`),RegExp(`(^date$|^label$|^kind$)`,`u`)]});var Ha={[et]:Ir,[ot]:Ji,[lt]:Va},Ua=e=>{let t=Ln(e),n=dt(t);return n===void 0&&t!==void 0?[{rule:`unsupported-version`,path:`/schema`,message:`this build validates ${ut.join(` and `)}`}]:Ha[n??`urn:structured-exchange:1`](e)?[]:[{rule:`schema/invalid`,path:``,message:`does not conform to the published structured-exchange schema`}]},Wa=Object.defineProperty,Ga=(e,t,n)=>t in e?Wa(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ka=(e,t)=>{for(var n in t)Wa(e,n,{get:t[n],enumerable:!0})},qa=(e,t,n)=>Ga(e,typeof t==`symbol`?t:t+``,n),Ja={};Ka(Ja,{Graph:()=>Po,alg:()=>so});var Ya=Object.defineProperty,Xa=(e,t)=>{for(var n in t)Ya(e,n,{get:t[n],enumerable:!0})},Za=class{constructor(e){this._isDirected=!0,this._isMultigraph=!1,this._isCompound=!1,this._nodes={},this._in={},this._preds={},this._out={},this._sucs={},this._edgeObjs={},this._edgeLabels={},this._nodeCount=0,this._edgeCount=0,this._defaultNodeLabelFn=()=>{},this._defaultEdgeLabelFn=()=>{},e&&(this._isDirected=`directed`in e?e.directed:!0,this._isMultigraph=`multigraph`in e&&e.multigraph,this._isCompound=`compound`in e&&e.compound),this._isCompound&&(this._parent={},this._children={},this._children[`\0`]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(e){return this._label=e,this}graph(){return this._label}setDefaultNodeLabel(e){return this._defaultNodeLabelFn=typeof e==`function`?e:()=>e,this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){return this.nodes().filter(e=>Object.keys(this._in[e]).length===0)}sinks(){return this.nodes().filter(e=>Object.keys(this._out[e]).length===0)}setNodes(e,t){return e.forEach(e=>{t===void 0?this.setNode(e):this.setNode(e,t)}),this}setNode(e,t){return e in this._nodes?(arguments.length>1&&(this._nodes[e]=t),this):(this._nodes[e]=arguments.length>1?t:this._defaultNodeLabelFn(e),this._isCompound&&(this._parent[e]=`\0`,this._children[e]={},this._children[`\0`][e]=!0),this._in[e]={},this._preds[e]={},this._out[e]={},this._sucs[e]={},++this._nodeCount,this)}node(e){return this._nodes[e]}hasNode(e){return e in this._nodes}removeNode(e){if(e in this._nodes){let t=e=>this.removeEdge(this._edgeObjs[e]);delete this._nodes[e],this._isCompound&&(this._removeFromParentsChildList(e),delete this._parent[e],this.children(e).forEach(e=>{this.setParent(e)}),delete this._children[e]),Object.keys(this._in[e]).forEach(t),delete this._in[e],delete this._preds[e],Object.keys(this._out[e]).forEach(t),delete this._out[e],delete this._sucs[e],--this._nodeCount}return this}setParent(e,t){if(!this._isCompound)throw Error(`Cannot set parent in a non-compound graph`);if(t===void 0)t=`\0`;else{t+=``;for(let n=t;n!==void 0;n=this.parent(n))if(n===e)throw Error(`Setting `+t+` as parent of `+e+` would create a cycle`);this.setNode(t)}return this.setNode(e),this._removeFromParentsChildList(e),this._parent[e]=t,this._children[t][e]=!0,this}parent(e){if(this._isCompound){let t=this._parent[e];if(t!==`\0`)return t}}children(e=`\0`){if(this._isCompound){let t=this._children[e];if(t)return Object.keys(t)}else{if(e===`\0`)return this.nodes();if(this.hasNode(e))return[]}return[]}predecessors(e){let t=this._preds[e];if(t)return Object.keys(t)}successors(e){let t=this._sucs[e];if(t)return Object.keys(t)}neighbors(e){let t=this.predecessors(e);if(t){let n=new Set(t),r=this.successors(e);if(r)for(let e of r)n.add(e);return Array.from(n.values())}}isLeaf(e){let t;return t=this.isDirected()?this.successors(e):this.neighbors(e),(t?.length??0)===0}filterNodes(e){let t=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});t.setGraph(this.graph()),Object.entries(this._nodes).forEach(([n,r])=>{e(n)&&t.setNode(n,r)}),Object.values(this._edgeObjs).forEach(e=>{t.hasNode(e.v)&&t.hasNode(e.w)&&t.setEdge(e,this.edge(e))});let n={},r=e=>{let i=this.parent(e);return!i||t.hasNode(i)?(n[e]=i,i):i in n?n[i]:r(i)};return this._isCompound&&t.nodes().forEach(e=>t.setParent(e,r(e))),t}setDefaultEdgeLabel(e){return this._defaultEdgeLabelFn=typeof e==`function`?e:()=>e,this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(e,t){return e.reduce((e,n)=>(t===void 0?this.setEdge(e,n):this.setEdge(e,n,t),n)),this}setEdge(e,t,n,r){let i,a,o,s,c=!1;typeof e==`object`&&e&&`v`in e?(i=e.v,a=e.w,o=e.name,arguments.length===2&&(s=t,c=!0)):(i=e,a=t,o=r,arguments.length>2&&(s=n,c=!0)),i=``+i,a=``+a,o!==void 0&&(o=``+o);let l=eo(this._isDirected,i,a,o);if(l in this._edgeLabels)return c&&(this._edgeLabels[l]=s),this;if(o!==void 0&&!this._isMultigraph)throw Error(`Cannot set a named edge when isMultigraph = false`);this.setNode(i),this.setNode(a),this._edgeLabels[l]=c?s:this._defaultEdgeLabelFn(i,a,o);let u=to(this._isDirected,i,a,o);return i=u.v,a=u.w,Object.freeze(u),this._edgeObjs[l]=u,Qa(this._preds[a],i),Qa(this._sucs[i],a),this._in[a][l]=u,this._out[i][l]=u,this._edgeCount++,this}edge(e,t,n){let r=arguments.length===1?no(this._isDirected,e):eo(this._isDirected,e,t,n);return this._edgeLabels[r]}edgeAsObj(e,t,n){let r=arguments.length===1?this.edge(e):this.edge(e,t,n);return typeof r!=`object`||!r?{label:r}:r}hasEdge(e,t,n){return(arguments.length===1?no(this._isDirected,e):eo(this._isDirected,e,t,n))in this._edgeLabels}removeEdge(e,t,n){let r=arguments.length===1?no(this._isDirected,e):eo(this._isDirected,e,t,n),i=this._edgeObjs[r];if(i){let e=i.v,t=i.w;delete this._edgeLabels[r],delete this._edgeObjs[r],$a(this._preds[t],e),$a(this._sucs[e],t),delete this._in[t][r],delete this._out[e][r],this._edgeCount--}return this}inEdges(e,t){return this.isDirected()?this.filterEdges(this._in[e],e,t):this.nodeEdges(e,t)}outEdges(e,t){return this.isDirected()?this.filterEdges(this._out[e],e,t):this.nodeEdges(e,t)}nodeEdges(e,t){if(e in this._nodes)return this.filterEdges({...this._in[e],...this._out[e]},e,t)}_removeFromParentsChildList(e){delete this._children[this._parent[e]][e]}filterEdges(e,t,n){if(!e)return;let r=Object.values(e);return n?r.filter(e=>e.v===t&&e.w===n||e.v===n&&e.w===t):r}};function Qa(e,t){e[t]?e[t]++:e[t]=1}function $a(e,t){e[t]!==void 0&&!--e[t]&&delete e[t]}function eo(e,t,n,r){let i=``+t,a=``+n;if(!e&&i>a){let e=i;i=a,a=e}return i+``+a+``+(r===void 0?`\0`:r)}function to(e,t,n,r){let i=``+t,a=``+n;if(!e&&i>a){let e=i;i=a,a=e}let o={v:i,w:a};return r&&(o.name=r),o}function no(e,t){return eo(e,t.v,t.w,t.name)}Xa({},{read:()=>oo,write:()=>ro});function ro(e){let t={options:{directed:e.isDirected(),multigraph:e.isMultigraph(),compound:e.isCompound()},nodes:io(e),edges:ao(e)},n=e.graph();return n!==void 0&&(t.value=structuredClone(n)),t}function io(e){return e.nodes().map(t=>{let n=e.node(t),r=e.parent(t),i={v:t};return n!==void 0&&(i.value=n),r!==void 0&&(i.parent=r),i})}function ao(e){return e.edges().map(t=>{let n=e.edge(t),r={v:t.v,w:t.w};return t.name!==void 0&&(r.name=t.name),n!==void 0&&(r.value=n),r})}function oo(e){let t=new Za(e.options);return e.value!==void 0&&t.setGraph(e.value),e.nodes.forEach(e=>{t.setNode(e.v,e.value),e.parent&&t.setParent(e.v,e.parent)}),e.edges.forEach(e=>{t.setEdge({v:e.v,w:e.w,name:e.name},e.value)}),t}var so={};Xa(so,{CycleException:()=>Co,bellmanFord:()=>lo,components:()=>fo,dijkstra:()=>ho,dijkstraAll:()=>_o,findCycles:()=>yo,floydWarshall:()=>xo,isAcyclic:()=>To,postorder:()=>ko,preorder:()=>Ao,prim:()=>jo,shortestPaths:()=>Mo,tarjan:()=>vo,topsort:()=>wo});var co=()=>1;function lo(e,t,n,r){return uo(e,String(t),n||co,r||function(t){return e.outEdges(t)??[]})}function uo(e,t,n,r){let i={},a,o=0,s=e.nodes(),c=function(e){let t=i[e.v],r=i[e.w];if(!t||!r)return;let o=n(e);t.distance+o<r.distance&&(i[e.w]={distance:t.distance+o,predecessor:e.v},a=!0)},l=function(){s.forEach(function(e){r(e).forEach(function(t){let n=t.v===e?t.v:t.w,r=n===t.v?t.w:t.v;c({v:n,w:r})})})};s.forEach(function(e){i[e]={distance:e===t?0:1/0,predecessor:``}});let u=s.length;for(let e=1;e<u&&(a=!1,o++,l(),a);e++);if(o===u-1&&(a=!1,l(),a))throw Error(`The graph contains a negative weight cycle`);return i}function fo(e){let t={},n=[],r;function i(n){var a,o;n in t||(t[n]=!0,r.push(n),(a=e.successors(n))==null||a.forEach(i),(o=e.predecessors(n))==null||o.forEach(i))}return e.nodes().forEach(function(e){r=[],i(e),r.length&&n.push(r)}),n}var po=class{constructor(){this._arr=[],this._keyIndices={}}size(){return this._arr.length}keys(){return this._arr.map(e=>e.key)}has(e){return e in this._keyIndices}priority(e){let t=this._keyIndices[e];if(t!==void 0)return this._arr[t].priority}min(){if(this.size()===0)throw Error(`Queue underflow`);return this._arr[0].key}add(e,t){let n=this._keyIndices,r=String(e);if(!(r in n)){let e=this._arr,i=e.length;return n[r]=i,e.push({key:r,priority:t}),this._decrease(i),!0}return!1}removeMin(){if(this.size()===0)throw Error(`Queue underflow`);this._swap(0,this._arr.length-1);let e=this._arr.pop();return delete this._keyIndices[e.key],this._heapify(0),e.key}decrease(e,t){let n=this._keyIndices[e];if(n===void 0)throw Error(`Key not found: ${e}`);let r=this._arr[n].priority;if(t>r)throw Error(`New priority is greater than current priority. Key: ${e} Old: ${r} New: ${t}`);this._arr[n].priority=t,this._decrease(n)}_heapify(e){let t=this._arr,n=2*e,r=n+1,i=e;n<t.length&&(i=t[n].priority<t[i].priority?n:i,r<t.length&&(i=t[r].priority<t[i].priority?r:i),i!==e&&(this._swap(e,i),this._heapify(i)))}_decrease(e){let t=this._arr,n=t[e].priority,r;for(;e!==0&&(r=e>>1,!(t[r].priority<n));)this._swap(e,r),e=r}_swap(e,t){let n=this._arr,r=this._keyIndices,i=n[e],a=n[t];n[e]=a,n[t]=i,r[a.key]=e,r[i.key]=t}},mo=()=>1;function ho(e,t,n,r){return go(e,String(t),n||mo,r||function(t){return e.outEdges(t)??[]})}function go(e,t,n,r){let i={},a=new po,o,s,c=function(e){let t=e.v===o?e.w:e.v,r=i[t];if(!r)return;let c=n(e),l=s.distance+c;if(c<0)throw Error(`dijkstra does not allow negative edge weights. Bad edge: `+e+` Weight: `+c);l<r.distance&&(r.distance=l,r.predecessor=o,a.decrease(t,l))};for(e.nodes().forEach(function(e){let n=e===t?0:1/0;i[e]={distance:n,predecessor:``},a.add(e,n)});a.size()>0;){o=a.removeMin();let e=i[o];if(!e||e.distance===1/0)break;s=e,r(o).forEach(c)}return i}function _o(e,t,n){return e.nodes().reduce(function(r,i){return r[i]=ho(e,i,t,n),r},{})}function vo(e){let t=0,n=[],r={},i=[];function a(o){var s;let c=r[o]={onStack:!0,lowlink:t,index:t++};if(n.push(o),(s=e.successors(o))==null||s.forEach(function(e){if(e in r){let t=r[e];t!=null&&t.onStack&&(c.lowlink=Math.min(c.lowlink,t.index))}else{a(e);let t=r[e];t&&(c.lowlink=Math.min(c.lowlink,t.lowlink))}}),c.lowlink===c.index){let e=[],t;do{t=n.pop();let i=r[t];i&&(i.onStack=!1),e.push(t)}while(o!==t);i.push(e)}}return e.nodes().forEach(function(e){e in r||a(e)}),i}function yo(e){return vo(e).filter(function(t){let n=t[0];return n?t.length>1||t.length===1&&(e.outEdges(n,n)??[]).length>0:!1})}var bo=()=>1;function xo(e,t,n){return So(e,t||bo,n||function(t){return e.outEdges(t)??[]})}function So(e,t,n){let r={},i=e.nodes();return i.forEach(function(e){let a={};r[e]=a,a[e]={distance:0,predecessor:``},i.forEach(function(t){e!==t&&(a[t]={distance:1/0,predecessor:``})}),n(e).forEach(function(n){let r=n.v===e?n.w:n.v,i=t(n);a[r]={distance:i,predecessor:e}})}),i.forEach(function(e){let t=r[e];t&&i.forEach(function(n){let a=r[n];a&&i.forEach(function(n){let r=a[e],i=t[n],o=a[n];if(r&&i&&o){let e=r.distance+i.distance;e<o.distance&&(o.distance=e,o.predecessor=i.predecessor)}})})}),r}var Co=class extends Error{constructor(e){super(e),this.name=`CycleException`}};function wo(e){let t={},n={},r=[];function i(a){var o;if(a in n)throw new Co;a in t||(n[a]=!0,t[a]=!0,(o=e.predecessors(a))==null||o.forEach(i),delete n[a],r.push(a))}if(e.sinks().forEach(i),Object.keys(t).length!==e.nodeCount())throw new Co;return r}function To(e){try{wo(e)}catch(e){if(e instanceof Co)return!1;throw e}return!0}function Eo(e,t,n,r,i){Array.isArray(t)||(t=[t]);let a=(t=>(e.isDirected()?e.successors(t):e.neighbors(t))??[]),o={};return t.forEach(function(t){if(!e.hasNode(t))throw Error(`Graph does not have node: `+t);i=Do(e,t,n===`post`,o,a,r,i)}),i}function Do(e,t,n,r,i,a,o){return t in r||(r[t]=!0,n||(o=a(o,t)),i(t).forEach(function(t){o=Do(e,t,n,r,i,a,o)}),n&&(o=a(o,t))),o}function Oo(e,t,n){return Eo(e,t,n,function(e,t){return e.push(t),e},[])}function ko(e,t){return Oo(e,t,`post`)}function Ao(e,t){return Oo(e,t,`pre`)}function jo(e,t){var n;let r=new Za,i={},a=new po,o;function s(e){let n=e.v===o?e.w:e.v,r=a.priority(n);if(r!==void 0){let s=t(e);s<r&&(i[n]=o,a.decrease(n,s))}}if(e.nodeCount()===0)return r;e.nodes().forEach(function(e){a.add(e,1/0),r.setNode(e)});let c=e.nodes()[0];c!==void 0&&a.decrease(c,0);let l=!1;for(;a.size()>0;){if(o=a.removeMin(),o in i)r.setEdge(o,i[o]);else{if(l)throw Error(`Input graph is not connected: `+e);l=!0}(n=e.nodeEdges(o))==null||n.forEach(s)}return r}function Mo(e,t,n,r){return No(e,t,n,r??(t=>e.outEdges(t)??[]))}function No(e,t,n,r){if(n===void 0)return ho(e,t,n,r);let i=!1,a=e.nodes();for(let o=0;o<a.length;o++){let s=a[o];if(s===void 0)continue;let c=r(s);for(let e=0;e<c.length;e++){let t=c[e];if(!t)continue;let r=t.v===s?t.v:t.w;n({v:r,w:r===t.v?t.w:t.v})<0&&(i=!0)}if(i)return lo(e,t,n,r)}return ho(e,t,n,r)}var Po=Za;function Fo(e,t,n,r){let i=r;for(;e.hasNode(i);)i=Zo(r);return n.dummy=t,e.setNode(i,n),i}function Io(e){let t=new Po().setGraph(e.graph());return e.nodes().forEach(n=>t.setNode(n,e.node(n))),e.edges().forEach(n=>{let r=t.edge(n.v,n.w)||{weight:0,minlen:1},i=e.edge(n);t.setEdge(n.v,n.w,{weight:r.weight+i.weight,minlen:Math.max(r.minlen,i.minlen)})}),t}function Lo(e){let t=new Po({multigraph:e.isMultigraph()}).setGraph(e.graph());return e.nodes().forEach(n=>{e.children(n).length||t.setNode(n,e.node(n))}),e.edges().forEach(n=>{t.setEdge(n,e.edge(n))}),t}function Ro(e,t){let n=e.x,r=e.y,i=t.x-n,a=t.y-r,o=e.width/2,s=e.height/2;if(!i&&!a)throw Error(`Not possible to find intersection inside of the rectangle`);let c,l;return Math.abs(a)*o>Math.abs(i)*s?(a<0&&(s=-s),c=s*i/a,l=s):(i<0&&(o=-o),c=o,l=o*a/i),{x:n+c,y:r+l}}function zo(e){let t=Qo(Ko(e)+1).map(()=>[]);return e.nodes().forEach(n=>{let r=e.node(n),i=r.rank;i!==void 0&&(t[i]||(t[i]=[]),t[i][r.order]=n)}),t}function Bo(e){let t=e.nodes().map(t=>{let n=e.node(t).rank;return n===void 0?Number.MAX_VALUE:n}),n=Go(Math.min,t);e.nodes().forEach(t=>{let r=e.node(t);Object.hasOwn(r,`rank`)&&(r.rank-=n)})}function Vo(e){let t=e.nodes().map(t=>e.node(t).rank).filter(e=>e!==void 0),n=Go(Math.min,t),r=[];e.nodes().forEach(t=>{let i=e.node(t).rank-n;r[i]||(r[i]=[]),r[i].push(t)});let i=0,a=e.graph().nodeRankFactor;Array.from(r).forEach((t,n)=>{t===void 0&&n%a!==0?--i:t!==void 0&&i&&t.forEach(t=>e.node(t).rank+=i)})}function Ho(e,t,n,r){let i={width:0,height:0};return arguments.length>=4&&(i.rank=n,i.order=r),Fo(e,`border`,i,t)}function Uo(e,t=Wo){let n=[];for(let r=0;r<e.length;r+=t){let i=e.slice(r,r+t);n.push(i)}return n}var Wo=65535;function Go(e,t){return t.length>Wo?e(...Uo(t).map(t=>e(...t))):e(...t)}function Ko(e){let t=e.nodes().map(t=>{let n=e.node(t).rank;return n===void 0?Number.MIN_VALUE:n});return Go(Math.max,t)}function qo(e,t){let n={lhs:[],rhs:[]};return e.forEach(e=>{t(e)?n.lhs.push(e):n.rhs.push(e)}),n}function Jo(e,t){let n=Date.now();try{return t()}finally{console.log(e+` time: `+(Date.now()-n)+`ms`)}}function Yo(e,t){return t()}var Xo=0;function Zo(e){return e+(``+ ++Xo)}function Qo(e,t,n=1){t??(t=e,e=0);let r=e=>e<t;n<0&&(r=e=>t<e);let i=[];for(let t=e;r(t);t+=n)i.push(t);return i}function $o(e,t){let n={};for(let r of t)e[r]!==void 0&&(n[r]=e[r]);return n}function es(e,t){let n;return n=typeof t==`string`?e=>e[t]:t,Object.entries(e).reduce((e,[t,r])=>(e[t]=n(r,t),e),{})}function ts(e,t){return e.reduce((e,n,r)=>(e[n]=t[r],e),{})}var ns=`\0`;function rs(e,t,n){if(!(e&&t&&n&&t.dummy===`edge`&&n.dummy===`edge`&&t.edgeObj&&n.edgeObj&&e[t.edgeObj.v]&&e[n.edgeObj.v]&&e[t.edgeObj.w]&&e[n.edgeObj.w]))return 0;let r=!0;t.edgeObj.w===n.edgeObj.w&&(r=!1);let i=r?e[t.edgeObj.v]?.rank??NaN:e[t.edgeObj.w]?.rank??NaN,a=Object.entries(e).find(e=>e[1].edgeObj?.v===t.edgeObj.v&&e[1].edgeObj?.w===t.edgeObj.w&&e[1].rank===i),o=Object.entries(e).find(e=>e[1].edgeObj?.v===n.edgeObj.v&&e[1].edgeObj?.w===n.edgeObj.w&&e[1].rank===i);if(!a||!o)return 0;let s=a[1].order??NaN,c=o[1].order??NaN;return isNaN(s-c)?0:s-c}var is=`3.1.1`,as=class{constructor(){qa(this,`_sentinel`);let e={};e._next=e._prev=e,this._sentinel=e}dequeue(){let e=this._sentinel,t=e._prev;if(t!==e)return os(t),t}enqueue(e){let t=this._sentinel;e._prev&&e._next&&os(e),e._next=t._next,t._next._prev=e,t._next=e,e._prev=t}toString(){let e=[],t=this._sentinel,n=t._prev;for(;n!==t;)e.push(JSON.stringify(n,ss)),n=n._prev;return`[`+e.join(`, `)+`]`}};function os(e){e._prev._next=e._next,e._next._prev=e._prev,delete e._next,delete e._prev}function ss(e,t){if(e!==`_next`&&e!==`_prev`)return t}var cs=as,ls=()=>1;function us(e,t){if(e.nodeCount()<=1)return[];let n=ps(e,t||ls);return ds(n.graph,n.buckets,n.zeroIdx).flatMap(t=>e.outEdges(t.v,t.w)||[])}function ds(e,t,n){let r=[],i=t[t.length-1],a=t[0],o;for(;e.nodeCount();){for(;o=a.dequeue();)fs(e,t,n,o);for(;o=i.dequeue();)fs(e,t,n,o);if(e.nodeCount()){for(let i=t.length-2;i>0;--i)if(o=t[i]?.dequeue(),o){r=r.concat(fs(e,t,n,o,!0)||[]);break}}}return r}function fs(e,t,n,r,i){let a=[],o=i?a:void 0;return(e.inEdges(r.v)||[]).forEach(r=>{let o=e.edge(r),s=e.node(r.v);i&&a.push({v:r.v,w:r.w}),s.out-=o,ms(t,n,s)}),(e.outEdges(r.v)||[]).forEach(r=>{let i=e.edge(r),a=r.w,o=e.node(a);o.in-=i,ms(t,n,o)}),e.removeNode(r.v),o}function ps(e,t){let n=new Po,r=0,i=0;e.nodes().forEach(e=>{n.setNode(e,{v:e,in:0,out:0})}),e.edges().forEach(e=>{let a=n.edge(e.v,e.w)||0,o=t(e),s=a+o;n.setEdge(e.v,e.w,s);let c=n.node(e.v),l=n.node(e.w);i=Math.max(i,c.out+=o),r=Math.max(r,l.in+=o)});let a=hs(i+r+3).map(()=>new cs),o=r+1;return n.nodes().forEach(e=>{ms(a,o,n.node(e))}),{graph:n,buckets:a,zeroIdx:o}}function ms(e,t,n){var r,i,a;n.out?n.in?(a=e[n.out-n.in+t])==null||a.enqueue(n):(i=e[e.length-1])==null||i.enqueue(n):(r=e[0])==null||r.enqueue(n)}function hs(e){let t=[];for(let n=0;n<e;n++)t.push(n);return t}function gs(e,t){(e.graph().acyclicer===`greedy`?us(e,n(e)):_s(e,t??null)).forEach(t=>{let n=e.edge(t);e.removeEdge(t),n.forwardName=t.name,n.reversed=!0,e.setEdge(t.w,t.v,n,Zo(`rev`))});function n(e){return t=>e.edge(t).weight}}function _s(e,t){let n=[],r={},i={};function a(t){Object.hasOwn(i,t)||(i[t]=!0,r[t]=!0,e.outEdges(t).forEach(e=>{Object.hasOwn(r,e.w)?n.push(e):a(e.w)}),delete r[t])}function o(a){var s;Object.hasOwn(i,a)||(i[a]=!0,r[a]=!0,(s=e.outEdges(a))==null||s.forEach(i=>{Object.hasOwn(r,i.w)||t.node(a)?.rank>t.node(i.w)?.rank&&ys(e,i.w,i)?n.push(i):o(i.w)}),delete r[a])}let s=a;return t&&typeof t.node==`function`&&(s=o),e.sources().forEach(s),e.nodes().forEach(s),n}function vs(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.reversed){e.removeEdge(t);let r=n.forwardName;delete n.reversed,delete n.forwardName,e.setEdge(t.w,t.v,n,r)}})}function ys(e,t,n){let r=new Set;function i(t){if(e.sources().includes(t))return!0;r.add(t);for(let a of e.inEdges(t)??[])if((a.v!==n.v||a.w!==n.w)&&!r.has(a.v)&&i(a.v))return!0;return!1}return i(t)}function bs(e){e.graph().dummyChains=[],e.edges().forEach(t=>xs(e,t))}function xs(e,t){let n=t.v,r=e.node(n).rank,i=t.w,a=e.node(i).rank,o=t.name,s=e.edge(t),c=s.labelRank;if(a===r+1)return;e.removeEdge(t);let l,u,d=0;for(++r;r<a;++d,++r)s.points=[],u={width:0,height:0,edgeLabel:s,edgeObj:t,rank:r},l=Fo(e,`edge`,u,`_d`),r===c&&(u.width=s.width,u.height=s.height,u.dummy=`edge-label`,u.labelpos=s.labelpos),e.setEdge(n,l,{weight:s.weight},o),d===0&&e.graph().dummyChains.push(l),n=l;e.setEdge(n,i,{weight:s.weight},o)}function Ss(e){e.graph().dummyChains.forEach(t=>{let n=e.node(t),r=n.edgeLabel,i;for(e.setEdge(n.edgeObj,r);n.dummy;)i=e.successors(t)[0],e.removeNode(t),r.points.push({x:n.x,y:n.y}),n.dummy===`edge-label`&&(r.x=n.x,r.y=n.y,r.width=n.width,r.height=n.height),t=i,n=e.node(t)})}function Cs(e){let t={};function n(r){let i=e.node(r);if(Object.hasOwn(t,r))return i.rank;t[r]=!0;let a=e.outEdges(r),o=a?a.map(t=>t==null?1/0:n(t.w)-e.edge(t).minlen):[],s=Go(Math.min,o);return s===1/0&&(s=0),i.rank=s}e.sources().forEach(n)}function ws(e,t){return e.node(t.w).rank-e.node(t.v).rank-e.edge(t).minlen}var Ts=Es;function Es(e){let t=new Po({directed:!1}),n=e.nodes();if(n.length===0)throw Error(`Graph must have at least one node`);let r=n[0],i=e.nodeCount();t.setNode(r,{});let a,o;for(;Ds(t,e)<i&&(a=Os(t,e),a);)o=t.hasNode(a.v)?ws(e,a):-ws(e,a),ks(t,e,o);return t}function Ds(e,t){function n(r){let i=t.nodeEdges(r);i&&i.forEach(i=>{let a=i.v,o=r===a?i.w:a;!e.hasNode(o)&&!ws(t,i)&&(e.setNode(o,{}),e.setEdge(r,o,{}),n(o))})}return e.nodes().forEach(n),e.nodeCount()}function Os(e,t){return t.edges().reduce((n,r)=>{let i=1/0;return e.hasNode(r.v)!==e.hasNode(r.w)&&(i=ws(t,r)),i<n[0]?[i,r]:n},[1/0,null])[1]}function ks(e,t,n){e.nodes().forEach(e=>t.node(e).rank+=n)}var{preorder:As,postorder:js}=so,Ms=Ns;Ns.initLowLimValues=Ls,Ns.initCutValues=Ps,Ns.calcCutValue=Is,Ns.leaveEdge=zs,Ns.enterEdge=Bs,Ns.exchangeEdges=Vs;function Ns(e){e=Io(e),Cs(e);let t=Ts(e);Ls(t),Ps(t,e);let n,r;for(;n=zs(t);)r=Bs(t,e,n),Vs(t,e,n,r)}function Ps(e,t){let n=js(e,e.nodes());n=n.slice(0,n.length-1),n.forEach(n=>Fs(e,t,n))}function Fs(e,t,n){let r=e.node(n).parent,i=e.edge(n,r);i.cutvalue=Is(e,t,n)}function Is(e,t,n){let r=e.node(n).parent,i=!0,a=t.edge(n,r),o=0;a||=(i=!1,t.edge(r,n)),o=a.weight;let s=t.nodeEdges(n);return s&&s.forEach(a=>{let s=a.v===n,c=s?a.w:a.v;if(c!==r){let r=s===i,l=t.edge(a).weight;if(o+=r?l:-l,Us(e,n,c)){let t=e.edge(n,c).cutvalue;o+=r?-t:t}}}),o}function Ls(e,t){arguments.length<2&&(t=e.nodes()[0]),Rs(e,{},1,t)}function Rs(e,t,n,r,i){let a=n,o=e.node(r);t[r]=!0;let s=e.neighbors(r);return s&&s.forEach(i=>{Object.hasOwn(t,i)||(n=Rs(e,t,n,i,r))}),o.low=a,o.lim=n++,i?o.parent=i:delete o.parent,n}function zs(e){return e.edges().find(t=>e.edge(t).cutvalue<0)}function Bs(e,t,n){let r=n.v,i=n.w;t.hasEdge(r,i)||(r=n.w,i=n.v);let a=e.node(r),o=e.node(i),s=a,c=!1;return a.lim>o.lim&&(s=o,c=!0),t.edges().filter(t=>c===Ws(e,e.node(t.v),s)&&c!==Ws(e,e.node(t.w),s)).reduce((e,n)=>ws(t,n)<ws(t,e)?n:e)}function Vs(e,t,n,r){let i=n.v,a=n.w;e.removeEdge(i,a),e.setEdge(r.v,r.w,{}),Ls(e),Ps(e,t),Hs(e,t)}function Hs(e,t){let n=e.nodes().find(t=>!e.node(t).parent);if(!n)return;let r=As(e,[n]);r=r.slice(1),r.forEach(n=>{let r=e.node(n).parent,i=t.edge(n,r),a=!1;i||(i=t.edge(r,n),a=!0),t.node(n).rank=t.node(r).rank+(a?i.minlen:-i.minlen)})}function Us(e,t,n){return e.hasEdge(t,n)}function Ws(e,t,n){return n.low<=t.lim&&t.lim<=n.lim}var Gs=Ks;function Ks(e){let t=e.graph().ranker;if(typeof t==`function`)return t(e);switch(t){case`network-simplex`:Ys(e);break;case`tight-tree`:Js(e);break;case`longest-path`:qs(e);break;case`none`:break;default:Ys(e)}}var qs=Cs;function Js(e){Cs(e),Ts(e)}function Ys(e){Ms(e)}var Xs=Zs;function Zs(e){let t=$s(e),n=e.graph();Array.isArray(n.dummyChains)&&n.dummyChains.forEach(n=>{let r=e.node(n),i=r.edgeObj,a=Qs(e,t,i.v,i.w),o=a.path,s=a.lca,c=0,l=o[c],u=!0;for(;n!==i.w;){if(r=e.node(n),u){for(;(l=o[c])!==s&&e.node(l).maxRank<r.rank;)c++;l===s&&(u=!1)}if(!u){for(;c<o.length-1&&e.node(o[c+1]).minRank<=r.rank;)c++;l=o[c]}l!==void 0&&e.setParent(n,l),n=e.successors(n)[0]}})}function Qs(e,t,n,r){let i=[],a=[],o=Math.min(t[n].low,t[r].low),s=Math.max(t[n].lim,t[r].lim),c;c=n;do c=e.parent(c),i.push(c);while(c&&(t[c].low>o||s>t[c].lim));let l=c,u=r;for(;(u=e.parent(u))!==l;)a.push(u);return{path:i.concat(a.reverse()),lca:l}}function $s(e){let t={},n=0;function r(i){let a=n;e.children(i).forEach(r),t[i]={low:a,lim:n++}}return e.children(ns).forEach(r),t}function ec(e){let t=Fo(e,`root`,{},`_root`),n=nc(e),r=Object.values(n),i=Go(Math.max,r)-1,a=2*i+1;e.graph().nestingRoot=t,e.edges().forEach(t=>e.edge(t).minlen*=a);let o=rc(e)+1;e.children(ns).forEach(r=>{tc(e,t,a,o,i,n,r)}),e.graph().nodeRankFactor=a}function tc(e,t,n,r,i,a,o){let s=e.children(o);if(!s.length){o!==t&&e.setEdge(t,o,{weight:0,minlen:n});return}let c=Ho(e,`_bt`),l=Ho(e,`_bb`),u=e.node(o);e.setParent(c,o),u.borderTop=c,e.setParent(l,o),u.borderBottom=l,s.forEach(s=>{tc(e,t,n,r,i,a,s);let u=e.node(s),d=u.borderTop?u.borderTop:s,f=u.borderBottom?u.borderBottom:s,p=u.borderTop?r:2*r,m=d===f?i-(a[o]??0)+1:1;e.setEdge(c,d,{weight:p,minlen:m,nestingEdge:!0}),e.setEdge(f,l,{weight:p,minlen:m,nestingEdge:!0})}),e.parent(o)||e.setEdge(t,c,{weight:0,minlen:i+(a[o]??0)})}function nc(e){let t={};function n(r,i){let a=e.children(r);a&&a.length&&a.forEach(e=>n(e,i+1)),t[r]=i}return e.children(ns).forEach(e=>n(e,1)),t}function rc(e){return e.edges().reduce((t,n)=>t+e.edge(n).weight,0)}function ic(e){let t=e.graph();e.removeNode(t.nestingRoot),delete t.nestingRoot,e.edges().forEach(t=>{e.edge(t).nestingEdge&&e.removeEdge(t)})}var ac=oc;function oc(e){function t(n){let r=e.children(n),i=e.node(n);if(r.length&&r.forEach(t),i&&Object.hasOwn(i,`minRank`)){i.borderLeft=[],i.borderRight=[];for(let t=i.minRank,r=i.maxRank+1;t<r;++t)sc(e,`borderLeft`,`_bl`,n,i,t),sc(e,`borderRight`,`_br`,n,i,t)}}e.children(ns).forEach(t)}function sc(e,t,n,r,i,a){let o={width:0,height:0,rank:a,borderType:t},s=i[t][a-1],c=Fo(e,`border`,o,n);i[t][a]=c,e.setParent(c,r),s&&e.setEdge(s,c,{weight:1})}function cc(e){let t=e.graph().rankdir?.toLowerCase();(t===`lr`||t===`rl`)&&uc(e)}function lc(e){let t=e.graph().rankdir?.toLowerCase();(t===`bt`||t===`rl`)&&fc(e),(t===`lr`||t===`rl`)&&(mc(e),uc(e))}function uc(e){e.nodes().forEach(t=>dc(e.node(t))),e.edges().forEach(t=>dc(e.edge(t)))}function dc(e){let t=e.width;e.width=e.height,e.height=t}function fc(e){e.nodes().forEach(t=>pc(e.node(t))),e.edges().forEach(t=>{var n;let r=e.edge(t);(n=r.points)==null||n.forEach(pc),Object.hasOwn(r,`y`)&&pc(r)})}function pc(e){e.y=-e.y}function mc(e){e.nodes().forEach(t=>hc(e.node(t))),e.edges().forEach(t=>{var n;let r=e.edge(t);(n=r.points)==null||n.forEach(hc),Object.hasOwn(r,`x`)&&hc(r)})}function hc(e){let t=e.x;e.x=e.y,e.y=t}function gc(e,t=null){let n={},r=e.nodes().filter(t=>!e.children(t).length),i=r.map(t=>e.node(t).rank),a=Qo(Go(Math.max,i)+1).map(()=>[]);function o(t){if(n[t])return;n[t]=!0;let r=e.node(t);a[r.rank].push(t);let i=e.successors(t);i&&[...i].sort((e,t)=>s(e,t)).forEach(o)}r.sort((t,n)=>e.node(t).rank-e.node(n).rank).forEach(o);function s(n,r){return rs(t,e.node(n),e.node(r))}return a}function _c(e,t){let n=0;for(let r=1;r<t.length;++r)n+=vc(e,t[r-1],t[r]);return n}function vc(e,t,n){let r=ts(n,n.map((e,t)=>t)),i=t.flatMap(t=>{let n=e.outEdges(t);return n?n.map(t=>({pos:r[t.w],weight:e.edge(t).weight})).sort((e,t)=>e.pos-t.pos):[]}),a=1;for(;a<n.length;)a<<=1;let o=2*a-1;--a;let s=Array(o).fill(0),c=0;return i.forEach(e=>{let t=e.pos+a;s[t]+=e.weight;let n=0;for(;t>0;)t%2&&(n+=s[t+1]),t=t-1>>1,s[t]+=e.weight;c+=e.weight*n}),c}function yc(e,t=[]){return t.map(t=>{let n=e.inEdges(t);if(!n||!n.length)return{v:t};{let r=n.reduce((t,n)=>{let r=e.edge(n),i=e.node(n.v);return{sum:t.sum+r.weight*i.order,weight:t.weight+r.weight}},{sum:0,weight:0});return{v:t,barycenter:r.sum/r.weight,weight:r.weight}}})}function bc(e,t){let n={};return e.forEach((e,t)=>{let r={indegree:0,in:[],out:[],vs:[e.v],i:t};e.barycenter!==void 0&&(r.barycenter=e.barycenter,r.weight=e.weight),n[e.v]=r}),t.edges().forEach(e=>{let t=n[e.v],r=n[e.w];t!==void 0&&r!==void 0&&(r.indegree++,t.out.push(r))}),xc(Object.values(n).filter(e=>!e.indegree))}function xc(e){let t=[];function n(e){return t=>{t.merged||(t.barycenter===void 0||e.barycenter===void 0||t.barycenter>=e.barycenter)&&Sc(e,t)}}function r(t){return n=>{n.in.push(t),--n.indegree===0&&e.push(n)}}for(;e.length;){let i=e.pop();t.push(i),i.in.reverse().forEach(n(i)),i.out.forEach(r(i))}return t.filter(e=>!e.merged).map(e=>$o(e,[`vs`,`i`,`barycenter`,`weight`]))}function Sc(e,t){let n=0,r=0;e.weight&&(n+=e.barycenter*e.weight,r+=e.weight),t.weight&&(n+=t.barycenter*t.weight,r+=t.weight),e.vs=t.vs.concat(e.vs),e.barycenter=n/r,e.weight=r,e.i=Math.min(t.i,e.i),t.merged=!0}function Cc(e,t,n,r,i){let a={},o=null,s=null,c=i;typeof t==`boolean`?(c=t,a={}):t&&(a=t,o=n??null,s=r??null);let l=qo(e,e=>Object.hasOwn(e,`barycenter`)),u=l.lhs,d=l.rhs.sort((e,t)=>t.i-e.i),f=[],p=0,m=0,h=0;u.sort(Tc(s,o,!!c));for(let[e,t]of Object.entries(a)){let n=u.findIndex(t=>t.vs[0]===e);u.splice(n+1,0,t)}h=wc(f,d,h),u.forEach(e=>{h+=e.vs.length,f.push(e.vs),p+=e.barycenter*e.weight,m+=e.weight,h=wc(f,d,h)});let g={vs:f.flat(1)};return m&&(g.barycenter=p/m,g.weight=m),g}function wc(e,t,n){let r;for(;t.length&&(r=t[t.length-1]).i<=n;)t.pop(),e.push(r.vs),n++;return n}function Tc(e,t,n){return(r,i)=>{if(r.barycenter<i.barycenter)return-1;if(r.barycenter>i.barycenter)return 1;if(e&&(typeof r.vs[0]==`string`||typeof i.vs[0]==`string`)){let n=rs(t,e.node(r.vs[0]),e.node(i.vs[0]));if(n!==0)return n}return n?i.i-r.i:r.i-i.i}}function Ec(e,t,n,r,i){var a,o;let s=null,c=i;typeof r==`boolean`?(c=r,s=null):r!==void 0&&(s=r);let l=e.children(t),u=e.node(t),d=u?u.borderLeft:void 0,f=u?u.borderRight:void 0,p={};d&&(l=l.filter(e=>e!==d&&e!==f));let m=yc(e,l);m.forEach(t=>{if(e.children(t.v).length){let{result:r}=Ec(e,t.v,n,s,c);p[t.v]=r,Object.hasOwn(r,`barycenter`)&&Oc(t,r)}});let h=bc(m,n);Dc(h,p);let g={},_=!1;for(let t=0;t<h.length;t++)for(let n=t+1;n<h.length;n++)if(h[t]&&h[n]&&(a=h[t])!=null&&a.barycenter&&(o=h[n])!=null&&o.barycenter&&h[t]?.barycenter===h[n].barycenter){let r=h[t]?.vs[0]??``,i=h[n]?.vs[0]??``,a=e.node(r),o=e.node(i);if(a.dummy===`edge`&&o.dummy===`edge`&&a.edgeObj?.v===o.edgeObj?.v&&a.edgeObj?.w===o.edgeObj?.w){if(a.edgeLabel.reversed){g[i]=h[t],h.splice(t,1),t--;break}g[r]=h[n],h.splice(n,1),n--}else _=!0}let v=Cc(h,g,s,e,c);if(d&&f){v.vs=[d,v.vs,f].flat(1);let t=e.predecessors(d);if(t&&t.length){let n=e.node(t[0]),r=e.predecessors(f),i=e.node(r[0]);Object.hasOwn(v,`barycenter`)||(v.barycenter=0,v.weight=0),v.barycenter=(v.barycenter*v.weight+n.order+i.order)/(v.weight+2),v.weight+=2}}return Object.defineProperty(v,"result",{value:v,enumerable:!1,configurable:!0,writable:!0}),Object.defineProperty(v,"usedBias",{value:_,enumerable:!1,configurable:!0,writable:!0}),v}function Dc(e,t){e.forEach(e=>{e.vs=e.vs.flatMap(e=>t[e]?t[e].vs:e)})}function Oc(e,t){e.barycenter===void 0?(e.barycenter=t.barycenter,e.weight=t.weight):(e.barycenter=(e.barycenter*e.weight+t.barycenter*t.weight)/(e.weight+t.weight),e.weight+=t.weight)}function kc(e,t,n,r){r||=e.nodes();let i=Ac(e),a=new Po({compound:!0}).setGraph({root:i}).setDefaultNodeLabel(t=>e.node(t));return r.forEach(r=>{let o=e.node(r),s=e.parent(r);if(o.rank===t||o.minRank<=t&&t<=o.maxRank){a.setNode(r),a.setParent(r,s||i);let c=e[n](r);c&&c.forEach(t=>{let n=t.v===r?t.w:t.v,i=a.edge(n,r),o=i===void 0?0:i.weight;a.setEdge(n,r,{weight:e.edge(t).weight+o})}),Object.hasOwn(o,`minRank`)&&a.setNode(r,{borderLeft:o.borderLeft[t],borderRight:o.borderRight[t]})}}),a}function Ac(e){let t;for(;e.hasNode(t=Zo(`_root`)););return t}function jc(e,t,n){let r={},i;n.forEach(n=>{let a=e.parent(n),o,s;for(;a;){if(o=e.parent(a),o?(s=r[o],r[o]=a):(s=i,i=a),s&&s!==a){t.setEdge(s,a);return}a=o}})}function Mc(e,t={},n=null){if(typeof t.customOrder==`function`){t.customOrder(e,Mc);return}let r=Ko(e),i=Nc(e,Qo(1,r+1),`inEdges`),a=Nc(e,Qo(r-1,-1,-1),`outEdges`),o=gc(e,n);if(Fc(e,o),t.disableOptimalOrderHeuristic)return;let s=1/0,c,l=t.constraints||[];for(let t=0,r=0;r<4;++t,++r){Pc(t%2?i:a,t%4>=2,l,n),o=zo(e);let u=_c(e,o);u<s?(r=0,c=Object.assign({},o),s=u):u===s&&(c=structuredClone(o))}Fc(e,c)}function Nc(e,t,n){let r=new Map,i=(e,t)=>{r.has(e)||r.set(e,[]),r.get(e).push(t)};for(let t of e.nodes()){let n=e.node(t);if(typeof n.rank==`number`&&i(n.rank,t),typeof n.minRank==`number`&&typeof n.maxRank==`number`)for(let e=n.minRank;e<=n.maxRank;e++)e!==n.rank&&i(e,t)}return t.map(function(t){return kc(e,t,n,r.get(t)||[])})}function Pc(e,t,n,r){let i=!0,a=new Po;e.forEach(function(e){n.forEach(e=>a.setEdge(e.left,e.right));let o=e.graph().root,{result:s,usedBias:c}=Ec(e,o,a,r,i);t&&c&&(i=!i),s.vs.forEach((t,n)=>e.node(t).order=n),jc(e,a,s.vs)})}function Fc(e,t){Object.values(t).forEach(t=>t.forEach((t,n)=>e.node(t).order=n))}function Ic(e,t){let n={};function r(t,r){let i=0,a=0,o=t.length,s=r[r.length-1];return r.forEach((t,c)=>{let l=Rc(e,t),u=l?e.node(l).order:o;(l||t===s)&&(r.slice(a,c+1).forEach(t=>{let r=e.predecessors(t);r&&r.forEach(r=>{let a=e.node(r),o=a.order;(o<i||u<o)&&!(a.dummy&&e.node(t).dummy)&&zc(n,r,t)})}),a=c+1,i=u)}),r}return t.length&&t.reduce(r),n}function Lc(e,t){let n={};function r(t,r,i,a,o){Qo(r,i).forEach(r=>{let i=t[r];if(i!==void 0&&e.node(i).dummy){let t=e.predecessors(i);t&&t.forEach(t=>{if(t===void 0)return;let r=e.node(t);r.dummy&&(r.order<a||r.order>o)&&zc(n,t,i)})}})}function i(t,n){let i=-1,a=-1,o=0;return n.forEach((s,c)=>{if(e.node(s).dummy===`border`){let t=e.predecessors(s);if(t&&t.length){let s=t[0];if(s===void 0)return;a=e.node(s).order,r(n,o,c,i,a),o=c,i=a}}r(n,o,n.length,a,t.length)}),n}return t.length&&t.reduce(i),n}function Rc(e,t){if(e.node(t).dummy){let n=e.predecessors(t);if(n)return n.find(t=>e.node(t).dummy)}}function zc(e,t,n){if(t>n){let e=t;t=n,n=e}let r=e[t];r||(e[t]=r={}),r[n]=!0}function Bc(e,t,n){if(t>n){let e=t;t=n,n=e}let r=e[t];return r!==void 0&&Object.hasOwn(r,n)}function Vc(e,t,n,r,i){let a={},o={},s={};return t.forEach(e=>{e.forEach((e,t)=>{a[e]=e,o[e]=e,s[e]=t})}),t.forEach(t=>{let c=-1,l=-1,u=!1,d=t,f=t.findIndex(t=>i?.includes(t)||Xc(t,e,i));f>0&&(d=[t[f],...t.slice(0,f),...t.slice(f+1)],u=!0),d.forEach(t=>{let d=r(t);if(d&&d.length){i!=null&&i.includes(t)&&(d=d.filter(t=>Xc(t,e,i)));let r=d.sort((e,t)=>{let n=s[e],r=s[t];return(n===void 0?0:n)-(r===void 0?0:r)}),f=(r.length-1)/2;for(let e=Math.floor(f),i=Math.ceil(f);e<=i;++e){let i=r[e];if(i===void 0)continue;let d=s[i];if(d!==void 0&&o[t]===t&&c<d&&s[i]!==l&&!Bc(n,t,i)){let e=a[i];e!==void 0&&(o[i]=t,o[t]=a[t]=e,c=d,u&&=(c=-1,l=s[i]??-1,!1))}}}})}),{root:a,align:o}}function Hc(e,t,n,r,i=!1){let a={},o=Uc(e,t,n,i),s=i?`borderLeft`:`borderRight`;function c(e,t){let n=o.nodes().slice(),r={},i=n.pop();for(;i;){if(r[i])e(i);else{r[i]=!0,n.push(i);for(let e of t(i))n.push(e)}i=n.pop()}}function l(e){let t=o.inEdges(e);t?a[e]=t.reduce((e,t)=>{let n=a[t.v]??0,r=o.edge(t);return Math.max(e,n+(r===void 0?0:r))},0):a[e]=0}function u(t){let n=o.outEdges(t),r=1/0;n&&(r=n.reduce((e,t)=>{let n=a[t.w],r=o.edge(t);return Math.min(e,(n===void 0?0:n)-(r===void 0?0:r))},1/0));let i=e.node(t);r!==1/0&&i.borderType!==s&&(a[t]=Math.max(a[t]===void 0?0:a[t],r))}function d(e){return o.predecessors(e)||[]}function f(e){return o.successors(e)||[]}return c(l,d),c(u,f),Object.keys(r).forEach(e=>{let t=n[e];t!==void 0&&(a[e]=a[t]??0)}),a}function Uc(e,t,n,r){let i=new Po,a=e.graph(),o=Jc(a.nodesep,a.edgesep,r);return t.forEach(t=>{let r;t.forEach(t=>{let a=n[t];if(a!==void 0){if(i.setNode(a),r!==void 0){let s=n[r];if(s!==void 0){let n=i.edge(s,a);i.setEdge(s,a,Math.max(o(e,t,r),n||0))}}r=t}})}),i}function Wc(e,t){return Object.values(t).reduce((t,n)=>{let r=-1/0,i=1/0;Object.entries(n).forEach(([t,n])=>{let a=Yc(e,t)/2;r=Math.max(n+a,r),i=Math.min(n-a,i)});let a=r-i;return a<t[0]&&(t=[a,n]),t},[1/0,null])[1]}function Gc(e,t){let n=Object.values(t),r=Go(Math.min,n),i=Go(Math.max,n);[`u`,`d`].forEach(n=>{[`l`,`r`].forEach(a=>{let o=n+a,s=e[o];if(!s||s===t)return;let c=Object.values(s),l=r-Go(Math.min,c);a!==`l`&&(l=i-Go(Math.max,c)),l&&(e[o]=es(s,e=>e+l))})})}function Kc(e,t=void 0){let n=e.ul;return n?es(n,(n,r)=>{if(t){let n=e[t.toLowerCase()];if(n&&n[r]!==void 0)return n[r]}let i=Object.values(e).map(e=>{let t=e[r];return t===void 0?0:t}).sort((e,t)=>e-t);return((i[1]??0)+(i[2]??0))/2}):{}}function qc(e,t){let n=zo(e),r=Object.assign(Ic(e,n),Lc(e,n)),i={},a;return[`u`,`d`].forEach(o=>{a=o===`u`?n:Object.values(n).reverse(),[`l`,`r`].forEach(n=>{n===`r`&&(a=a.map(e=>Object.values(e).reverse()));let s=Vc(e,a,r,t=>(o===`u`?e.predecessors(t):e.successors(t))||[],t),c=Hc(e,a,s.root,s.align,n===`r`);n===`r`&&(c=es(c,e=>-e)),i[o+n]=c})}),Gc(i,Wc(e,i)),Kc(i,e.graph().align)}function Jc(e,t,n){return(r,i,a)=>{let o=r.node(i),s=r.node(a),c=0,l;if(c+=o.width/2,Object.hasOwn(o,`labelpos`))switch(o.labelpos.toLowerCase()){case`l`:l=-o.width/2;break;case`r`:l=o.width/2}if(l&&(c+=n?l:-l),l=void 0,c+=(o.dummy?t:e)/2,c+=(s.dummy?t:e)/2,c+=s.width/2,Object.hasOwn(s,`labelpos`))switch(s.labelpos.toLowerCase()){case`l`:l=s.width/2;break;case`r`:l=-s.width/2}return l&&(c+=n?l:-l),c}}function Yc(e,t){return e.node(t).width}function Xc(e,t,n){if(!n)return!1;let r=t.node(e)?.edgeObj;if(!r||t.node(e).edgeLabel.reversed)return!1;let i=n.indexOf(r?.v),a=n.indexOf(r?.w);return i!==-1&&a!==-1&&i===(a+1)%n.length||i===(a-1)%n.length}function Zc(e,t){e=Lo(e),Qc(e),Object.entries(qc(e,t)).forEach(([t,n])=>e.node(t).x=n)}function Qc(e){let t=zo(e),n=e.graph(),r=n.ranksep,i=n.rankalign,a=0;t.forEach(t=>{let n=t.reduce((t,n)=>{let r=e.node(n).height??0;return t>r?t:r},0);t.forEach(t=>{let r=e.node(t);r.y=i===`top`?a+r.height/2:i===`bottom`?a+n-r.height/2:a+n/2}),a+=n+r})}var $c=new WeakMap;function el(e,t={}){return nl(e,Yo,t),e}function tl(e,t,n){let r=t;for(;r!==void 0;){let t=e.parent(r);if(t===n)return r;r=t}}function nl(e,t,n){let r=e.nodes().filter(t=>e.children(t).length),i={};r.forEach(r=>{let a=e.node(r);if(a&&a.rankdir){let o=new Po({multigraph:!0,compound:!0});o.setGraph({rankdir:a.rankdir});let s=e.children(r);s.forEach(t=>{let n={...e.node(t)};o.setNode(t,n);let i=e.parent(t);i&&i!==r&&s.includes(i)&&o.setParent(t,i)});let c=new Set;e.edges().forEach(t=>{let n=tl(e,t.v,r),i=tl(e,t.w,r);if(n&&i&&n!==i){let r=`${n}\0${i}`;c.has(r)||(c.add(r),o.setEdge(n,i,{...e.edge(t)}))}}),nl(o,t,n);let l=pl(o);rl(l,t,n,null),il(o,l);let u=1/0,d=1/0,f=-1/0,p=-1/0;o.nodes().forEach(e=>{if(e===r)return;let t=o.node(e);t&&typeof t.x==`number`&&typeof t.y==`number`&&typeof t.width==`number`&&typeof t.height==`number`&&(u=Math.min(u,t.x-t.width/2),f=Math.max(f,t.x+t.width/2),d=Math.min(d,t.y-t.height/2),p=Math.max(p,t.y+t.height/2))}),(!isFinite(u)||!isFinite(d)||!isFinite(f)||!isFinite(p))&&(u=d=0,f=p=0);let m=f-u,h=p-d;i[r]={minX:u,minY:d,maxX:f,maxY:p,width:m,height:h,offsetX:u,offsetY:d},a._dagreClusterSubgraph=o}});let a=[],o=t=>{let n=[],r=(e.children(t)||[]).filter(e=>e!==t);for(;r.length>0;){let t=r.shift();n.push(t),(e.children(t)||[]).filter(e=>e!==t).forEach(e=>r.push(e))}return n},s=new Map;r.forEach(t=>{let n=e.node(t);n&&n.rankdir&&i[t]&&s.set(t,(e.children(t)||[]).filter(e=>e!==t))});let c=new Set([...s.values()].flat()),l=new Map;s.forEach((e,t)=>{c.has(t)||l.set(t,o(t))});let u=new Set([...l.values()].flat()),d=e=>{for(let[t,n]of l)if(n.includes(e))return t;return e},f=[];e.edges().forEach(t=>{(u.has(t.v)||u.has(t.w))&&f.push({edge:t,label:e.edge(t)})});let p=new Map;u.forEach(t=>{let n=e.parent(t);p.set(t,typeof n==`string`?n:void 0)}),l.forEach((t,n)=>{let r=e.node(n),o=[];t.forEach(t=>{let n=e.node(t);n&&(o.push({id:t,node:n,parent:p.get(t)}),e.removeNode(t))});let s=f.filter(({edge:e})=>t.includes(e.v)||t.includes(e.w)),c=i[n];r&&(a.push({clusterId:n,subgraph:r._dagreClusterSubgraph,bounds:c,children:t,removedNodes:o,removedEdges:s}),r.width=c.width,r.height=c.height)});let m=new Set;f.forEach(({edge:t,label:n})=>{let r=d(t.v),i=d(t.w);if(r!==i&&e.hasNode(r)&&e.hasNode(i)){let t=`${r}\0${i}`;m.has(t)||(m.add(t),e.setEdge(r,i,{...n,width:0,height:0}))}});let h=pl(e),g=rl(h,t,n,$c.get(e)??null);$c.set(e,g),il(e,h),m.forEach(t=>{let n=t.indexOf(`\0`),r=t.slice(0,n),i=t.slice(n+1);e.hasEdge(r,i)&&e.removeEdge(r,i)}),a.forEach(({clusterId:t,subgraph:n,bounds:r,removedNodes:i,removedEdges:a})=>{let o=e.node(t),s=o?.x??0,c=o?.y??0,l=(r.minX+r.maxX)/2,u=(r.minY+r.maxY)/2;i.forEach(({id:t,node:n,parent:r})=>{e.setNode(t,n),r!==void 0&&e.setParent(t,r)}),a.forEach(({edge:t,label:n})=>{e.setEdge(t,n)}),n.nodes().forEach(r=>{if(r===t)return;let i=n.node(r),a=e.node(r);a&&i&&typeof i.x==`number`&&typeof i.y==`number`&&(a.x=s+(i.x-l),a.y=c+(i.y-u))}),delete o._dagreClusterSubgraph}),r.forEach(t=>{let n=e.node(t),r=i[t];if(n&&n.rankdir&&n._dagreClusterSubgraph&&r){let i=n._dagreClusterSubgraph,a=n.x??0,o=n.y??0,s=(r.minX+r.maxX)/2,c=(r.minY+r.maxY)/2;i.nodes().forEach(n=>{if(n===t)return;let r=i.node(n),l=e.node(n);if(l&&r&&typeof r.x==`number`&&typeof r.y==`number`){let e=r.x-s,t=r.y-c;l.x=a+e,l.y=o+t}}),delete n._dagreClusterSubgraph}})}function rl(e,t,n,r=null){var i,a;let o=n?.useDynamic!==!1,s=o&&(i=r?.graph)!=null?i:null,c=o&&(a=r?.rawNodes)!=null?a:null;t(` makeSpaceForEdgeLabels`,()=>ml(e)),t(` removeSelfEdges`,()=>Cl(e)),t(` acyclic`,()=>gs(e,s)),t(` nestingGraph.run`,()=>ec(e)),t(` rank`,()=>Gs(Lo(e))),t(` injectEdgeLabelProxies`,()=>hl(e)),t(` removeEmptyRanks`,()=>Vo(e)),t(` nestingGraph.cleanup`,()=>ic(e)),t(` normalizeRanks`,()=>Bo(e)),t(` assignRankMinMax`,()=>gl(e)),t(` removeEdgeLabelProxies`,()=>_l(e)),t(` normalize.run`,()=>bs(e)),t(` parentDummyChains`,()=>Xs(e)),t(` addBorderSegments`,()=>ac(e)),t(` order`,()=>Mc(e,n,c)),t(` insertSelfEdges`,()=>wl(e)),t(` adjustCoordinateSystem`,()=>cc(e)),t(` position`,()=>Zc(e,n.corePath)),t(` positionSelfEdges`,()=>Tl(e));let l=JSON.parse(JSON.stringify(e._nodes));return t(` removeBorderNodes`,()=>Sl(e)),t(` normalize.undo`,()=>Ss(e)),t(` fixupEdgeLabelCoords`,()=>bl(e)),t(` undoCoordinateSystem`,()=>lc(e)),t(` translateGraph`,()=>vl(e)),t(` assignNodeIntersects`,()=>yl(e)),t(` reversePoints`,()=>xl(e)),t(` acyclic.undo`,()=>vs(e)),{graph:e,rawNodes:l}}function il(e,t){e.nodes().forEach(n=>{let r=e.node(n),i=t.node(n);r&&(r.x=i.x,r.y=i.y,r.order=i.order,r.rank=i.rank,t.children(n).length&&(r.width=i.width,r.height=i.height))}),e.edges().forEach(n=>{let r=e.edge(n),i=t.edge(n);r.points=i.points,Object.hasOwn(i,`x`)&&(r.x=i.x,r.y=i.y)}),e.graph().width=t.graph().width,e.graph().height=t.graph().height}var al=[`nodesep`,`edgesep`,`ranksep`,`marginx`,`marginy`],ol={ranksep:50,edgesep:20,nodesep:50,rankdir:`TB`,rankalign:`center`},sl=[`acyclicer`,`ranker`,`rankdir`,`align`,`rankalign`],cl=[`width`,`height`,`rank`],ll={width:0,height:0},ul=[`minlen`,`weight`,`width`,`height`,`labeloffset`],dl={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:`r`},fl=[`labelpos`];function pl(e){let t=new Po({multigraph:!0,compound:!0}),n=Dl(e.graph());return t.setGraph(Object.assign({},ol,El(n,al),$o(n,sl))),e.nodes().forEach(n=>{let r=El(Dl(e.node(n)),cl);Object.keys(ll).forEach(e=>{r[e]===void 0&&(r[e]=ll[e])}),t.setNode(n,r);let i=e.parent(n);i!==void 0&&t.setParent(n,i)}),e.edges().forEach(n=>{let r=Dl(e.edge(n));t.setEdge(n,Object.assign({},dl,El(r,ul),$o(r,fl)))}),t}function ml(e){let t=e.graph();t.ranksep/=2,e.edges().forEach(n=>{let r=e.edge(n);r.minlen*=2,(r.labelpos??`r`).toLowerCase()!==`c`&&(t.rankdir===`TB`||t.rankdir===`BT`?r.width+=r.labeloffset:r.height+=r.labeloffset)})}function hl(e){e.edges().forEach(t=>{let n=e.edge(t);if(n.width&&n.height){let n=e.node(t.v);Fo(e,`edge-proxy`,{rank:(e.node(t.w).rank-n.rank)/2+n.rank,e:t},`_ep`)}})}function gl(e){let t=0;e.nodes().forEach(n=>{let r=e.node(n);r.borderTop&&(r.minRank=e.node(r.borderTop).rank,r.maxRank=e.node(r.borderBottom).rank,t=Math.max(t,r.maxRank))}),e.graph().maxRank=t}function _l(e){e.nodes().forEach(t=>{let n=e.node(t);if(n.dummy===`edge-proxy`){let r=n;e.edge(r.e).labelRank=n.rank,e.removeNode(t)}})}function vl(e){let t=1/0,n=0,r=1/0,i=0,a=e.graph(),o=a.marginx||0,s=a.marginy||0;function c(e){let a=e.x,o=e.y,s=e.width,c=e.height;t=Math.min(t,a-s/2),n=Math.max(n,a+s/2),r=Math.min(r,o-c/2),i=Math.max(i,o+c/2)}e.nodes().forEach(t=>c(e.node(t))),e.edges().forEach(t=>{let n=e.edge(t);Object.hasOwn(n,`x`)&&c(n)}),t-=o,r-=s,e.nodes().forEach(n=>{let i=e.node(n);i.x-=t,i.y-=r}),e.edges().forEach(n=>{let i=e.edge(n);i.points.forEach(e=>{e.x-=t,e.y-=r}),Object.hasOwn(i,`x`)&&(i.x-=t),Object.hasOwn(i,`y`)&&(i.y-=r)}),a.width=n-t+o,a.height=i-r+s}function yl(e){e.edges().forEach(t=>{if(t.v===t.w)return;let n=e.edge(t),r=e.node(t.v),i=e.node(t.w),a,o;n.points?(a=n.points[0],o=n.points[n.points.length-1]):(n.points=[],a=i,o=r),n.points.unshift(Ro(r,a)),n.points.push(Ro(i,o))})}function bl(e){e.edges().forEach(t=>{let n=e.edge(t);if(Object.hasOwn(n,`x`))switch((n.labelpos===`l`||n.labelpos===`r`)&&(n.width-=n.labeloffset),n.labelpos){case`l`:n.x-=n.width/2+n.labeloffset;break;case`r`:n.x+=n.width/2+n.labeloffset}})}function xl(e){e.edges().forEach(t=>{let n=e.edge(t);n.reversed&&n.points.reverse()})}function Sl(e){e.nodes().forEach(t=>{if(e.children(t).length){let n=e.node(t),r=e.node(n.borderTop),i=e.node(n.borderBottom),a=e.node(n.borderLeft[n.borderLeft.length-1]),o=e.node(n.borderRight[n.borderRight.length-1]);n.width=Math.abs(o.x-a.x),n.height=Math.abs(i.y-r.y),n.x=a.x+n.width/2,n.y=r.y+n.height/2}}),e.nodes().forEach(t=>{e.node(t).dummy===`border`&&e.removeNode(t)})}function Cl(e){e.edges().forEach(t=>{if(t.v===t.w){let n=e.node(t.v);n.selfEdges||=[],n.selfEdges.push({e:t,label:e.edge(t)}),e.removeEdge(t)}})}function wl(e){zo(e).forEach(t=>{let n=0;t.forEach((t,r)=>{let i=e.node(t);typeof i.rank!=`number`&&(i.rank=0),i.order=r+n,(i.selfEdges||[]).forEach(t=>{Fo(e,`selfedge`,{width:t.label.width,height:t.label.height,rank:i.rank,order:r+ ++n,e:t.e,edgeLabel:t.label},`_se`),(!Array.isArray(t.label.points)||t.label.points.length!==7)&&(t.label.points=[{x:0,y:-10},{x:0,y:-10},{x:0,y:0},{x:0,y:10},{x:0,y:10},{x:0,y:0},{x:0,y:0}])}),delete i.selfEdges})})}function Tl(e){e.nodes().forEach(t=>{let n=e.node(t),r=e=>typeof e==`number`&&isFinite(e);if(n.dummy===`selfedge`){let i=n,a=e.node(i.e.v),o=r(a?.x)?a.x:0,s=r(a?.y)?a.y:0,c=r(a?.width)?a.width:0,l=r(a?.height)?a.height:0,u=r(n.x)?n.x:o,d=r(n.y)?n.y:s,f=c/2,p=l/2;i.edgeLabel.points=[{x:u+f,y:d-p},{x:u+f,y:d-p},{x:u,y:d},{x:u-f,y:d+p},{x:u-f,y:d+p},{x:u,y:d},{x:u,y:d}],i.edgeLabel.x=u,i.edgeLabel.y=d,e.setEdge(i.e,i.edgeLabel),e.removeNode(t)}else n&&Array.isArray(n.selfEdges)&&n.selfEdges.forEach(e=>{if(!Array.isArray(e.label.points)||e.label.points.length!==7){let t=r(n.x)?n.x:0,i=r(n.y)?n.y:0,a=r(n.width)?n.width:0,o=r(n.height)?n.height:0,s=a/2,c=o/2;e.label.points=[{x:t+s,y:i-c},{x:t+s,y:i-c},{x:t,y:i},{x:t-s,y:i+c},{x:t-s,y:i+c},{x:t,y:i},{x:t,y:i}]}})})}function El(e,t){return es($o(e,t),Number)}function Dl(e){let t={};return e&&Object.entries(e).forEach(([e,n])=>{typeof e==`string`&&(e=e.toLowerCase()),t[e]=n}),t}function Ol(e){let t=zo(e),n=new Po({compound:!0,multigraph:!0}).setGraph({});return e.nodes().forEach(t=>{n.setNode(t,{label:t}),n.setParent(t,`layer`+e.node(t).rank)}),e.edges().forEach(e=>n.setEdge(e.v,e.w,{},e.name)),t.forEach((e,t)=>{let r=`layer`+t;n.setNode(r,{rank:`same`}),e.reduce((e,t)=>(n.setEdge(e,t,{style:`invis`}),t))}),n}var kl={graphlib:Ja,version:is,layout:el,debug:Ol,util:{time:Jo,notime:Yo}};function Al(e,t){return t?e.ref===void 0?`added`:e.set===void 0?`context`:`changed`:`unchanged`}function jl(e,t){if(t&&e.heading===void 0)return e.ref===void 0?`added`:e.set===void 0?`context`:`changed`}function Ml(e,t){return t?e.ref===void 0?`added`:e.set===void 0?`context`:`changed`:`unchanged`}function Nl(e){let t=e.set;if(t===void 0)return[];let n=e;return Object.entries(t).filter(([e])=>e!==`attributes`&&e!==`removeAttributes`).map(([e,t])=>{let r=n[e];return{field:e,...typeof r==`string`?{from:r}:{},to:String(t)}})}var Pl={added:`added`,changed:`changed`,context:`existing`,unchanged:``},Fl={added:`added`,changed:`changed`,context:`existing`,removed:`removed`},Il=[`added`,`changed`,`context`,`removed`];function Ll(e){return e.rows.some(e=>it(e).role!==void 0)}function Rl(e,t){if(t)return it(e).role??`context`}function zl(e){if(e.length===0)return;let t=Math.min(...e.map(e=>e.x)),n=Math.min(...e.map(e=>e.y)),r=Math.max(...e.map(e=>e.x+e.width)),i=Math.max(...e.map(e=>e.y+e.height));return{x:t-Ul,y:n-Ul-Wl,width:r-t+Ul*2,height:i-n+Ul*2+Wl}}var Bl=64,Vl=24,Hl=12,Ul=10,Wl=16,Gl=16,Kl=160,ql=52;function Jl(e,t,n=`landscape`){let r=new kl.graphlib.Graph({compound:!0,multigraph:!0});r.setGraph({rankdir:n===`portrait`?`TB`:`LR`,ranksep:Bl,nodesep:Vl,marginx:Hl,marginy:Hl}),r.setDefaultEdgeLabel(()=>({}));for(let n of e.nodes)r.setNode(n.id,t(n));let i=e.containers??[],a=new Map;for(let t of e.nodes)t.container!==void 0&&i.some(e=>e.id===t.container)&&(r.setNode(t.container,{label:t.container}),r.setParent(t.id,t.container),a.set(t.container,[...a.get(t.container)??[],t.id]));e.edges.forEach((e,t)=>{e.from!==e.to&&r.hasNode(e.from)&&r.hasNode(e.to)&&r.setEdge(e.from,e.to,{},String(t))}),kl.layout(r);let o=e.nodes.map(e=>{let n=r.node(e.id),{width:i,height:a}=t(e);return{id:e.id,x:(n?.x??Hl+i/2)-i/2,y:(n?.y??Hl+a/2)-a/2,width:i,height:a}}),s=[];e.edges.forEach((e,t)=>{if(e.from===e.to)return;let n=r.edge(e.from,e.to,String(t));n?.points!==void 0&&n.points.length>0&&s.push({index:t,points:n.points.map(e=>({x:e.x,y:e.y}))})});let c=[],l=o.reduce((e,t)=>Math.max(e,t.y+t.height),Hl)+Gl,u=new Map(o.map(e=>[e.id,e]));for(let e of i){let t=zl((a.get(e.id)??[]).flatMap(e=>{let t=u.get(e);return t===void 0?[]:[t]}));t===void 0?(c.push({id:e.id,label:e.label,x:Hl,y:l,width:Kl,height:ql}),l+=68):c.push({id:e.id,label:e.label,...t})}let d=[...o.map(e=>({x:e.x,y:e.y,width:e.width,height:e.height})),...c],f=Math.min(0,...d.map(e=>e.x))-Hl,p=Math.min(0,...d.map(e=>e.y))-Hl;if(f<0||p<0){for(let e of o)e.x-=f,e.y-=p;for(let e of c)e.x-=f,e.y-=p;for(let e of s)for(let t of e.points)t.x-=f,t.y-=p}let m=[...o.map(e=>({x:e.x,y:e.y,width:e.width,height:e.height})),...c].reduce((e,t)=>({width:Math.max(e.width,t.x+t.width),height:Math.max(e.height,t.y+t.height)}),{width:0,height:0});return{nodes:o,edges:s,containers:c,width:m.width+Hl,height:m.height+Hl}}var Yl={attributes:[],expectations:[],assignments:[],removedAttributes:[],locations:[],artifacts:[]};function Xl(e){if(typeof e!=`object`||!e)return Yl;let t=e,n=e=>typeof e==`object`&&e&&!Array.isArray(e)?Object.entries(e):[],r=t.set,i=r?.removeAttributes;return{attributes:n(t.attributes),expectations:n(t.expect?.attributes),assignments:n(r?.attributes),removedAttributes:Array.isArray(i)?i.filter(e=>typeof e==`string`):[],locations:Array.isArray(t.locations)?t.locations:[],artifacts:Array.isArray(t.artifacts)?t.artifacts:[]}}function Zl(e){let t=e.target;if(typeof t==`string`)return{ref:t};if(typeof t!=`object`||!t)return;let n=t;if(typeof n.ref==`string`)return{ref:n.ref,...typeof n.revision==`string`?{revision:n.revision}:{}}}function Ql(e,t){let n=(e.removals??[]).map(e=>({type:e.type,ref:e.ref})),r=e.profile,i=e.artifacts,a={...typeof r==`string`?{profile:r}:{},...(()=>{let t=Zl(e);return t===void 0?{}:{target:t}})(),artifacts:Array.isArray(i)?i:[]};if(e.kind===`table`){let r=e.data,i=Ll(r),o=r.rows.map(e=>{let n=Array.isArray(e)?{}:e,r=(Array.isArray(e)?void 0:e.role)??jl({ref:typeof n.ref==`string`?n.ref:void 0,set:n.set,heading:typeof n.heading==`string`?n.heading:void 0},t)??Rl(e,i),{cells:a,heading:o}=it(e),s=Array.isArray(e)?{}:e;return{cells:a,...r===void 0?{}:{role:r},...o===void 0?{}:{heading:o},...typeof s.depth==`number`?{depth:s.depth}:{},...typeof s.id==`string`?{id:s.id}:{},...typeof s.ref==`string`?{ref:s.ref}:{},...typeof s.kind==`string`?{kind:s.kind}:{},changes:Nl(s),...Xl(e)}}),s=new Map;for(let e of o){if(e.id===void 0)continue;let t=e.cells.find(e=>typeof e==`string`&&e!==``);s.set(e.id,(typeof t==`string`?t:void 0)??e.ref??e.id)}let c=r.relations,l=(Array.isArray(c)?c:[]).map(e=>{let t=e,n=e=>{let t=typeof e?.id==`string`?e.id:void 0,n=typeof e?.ref==`string`?e.ref:void 0;return{id:t,ref:n,label:(t===void 0?void 0:s.get(t))??n??t??``}},r=n(t.from),i=n(t.to);return{kind:t.kind??``,...typeof t.label==`string`?{label:t.label}:{},...r.id===void 0?{}:{fromRow:r.id},...i.id===void 0?{}:{toRow:i.id},...r.ref===void 0?{}:{fromRef:r.ref},...i.ref===void 0?{}:{toRef:i.ref},fromLabel:r.label,toLabel:i.label}});return{thingNoun:`column`,linkNoun:`row`,things:[],links:[],columns:r.columns,rows:o,containers:[],removals:n,traces:l,...a}}if(e.kind===`timeline`)return{thingNoun:`task`,linkNoun:`dependency`,things:[],links:[],containers:[],removals:n,traces:[],...a};let o=e.kind===`graph`,s=o?e.data.nodes:e.data.participants,c=o?e.data.edges:e.data.messages,l=new Map(s.map(e=>[e.id,$l(e)]));return{thingNoun:o?`element`:`participant`,linkNoun:o?`relationship`:`message`,things:s.map(e=>({id:e.id,label:$l(e),kind:e.kind,role:Al(e,t),changes:Nl(e),container:e.container,...Xl(e)})),links:c.map(e=>({from:e.from,to:e.to,fromLabel:l.get(e.from)??e.from,toLabel:l.get(e.to)??e.to,label:e.label,kind:`kind`in e?e.kind:void 0,role:Ml(e,t),changes:Nl(e),isLoop:e.from===e.to,...Xl(e)})),containers:e.data.containers??[],removals:n,traces:[],...a}}function $l(e){return e.label??e.ref??e.id}function eu(e){if(e.kind===`graph`){let t=e.data,n=[`flowchart TD`],r=t.containers??[],i=new Set(r.map(e=>e.id)),a=e=>t.nodes.filter(t=>t.container===e);for(let e of r){n.push(` subgraph ${tu(e.id)}["${ru(e.label)}"]`);for(let t of a(e.id))n.push(` ${tu(t.id)}["${ru($l(t))}"]`);n.push(` end`)}for(let e of t.nodes)e.container!==void 0&&i.has(e.container)||n.push(` ${tu(e.id)}["${ru($l(e))}"]`);for(let e of t.edges){let t=e.label??e.kind,r=t===void 0?`-->`:`-- "${ru(t)}" -->`;n.push(` ${tu(e.from)} ${r} ${tu(e.to)}`)}return n.join(`
23
23
  `)}if(e.kind===`sequence`){let t=e.data,n=[`sequenceDiagram`],r=t.containers??[],i=new Set(r.map(e=>e.id)),a=(e,t)=>`${t}participant ${tu(e.id)} as "${ru($l(e))}"`;for(let e of r){n.push(` box ${ru(e.label)}`);for(let r of t.participants.filter(t=>t.container===e.id))n.push(a(r,` `));n.push(` end`)}for(let e of t.participants)e.container!==void 0&&i.has(e.container)||n.push(a(e,` `));for(let e of t.messages)n.push(` ${tu(e.from)}->>${tu(e.to)}: ${ru(e.label??``)}`);return n.join(`
24
24
  `)}}function tu(e){return`n${[...e].map(e=>e.charCodeAt(0).toString(36)).join(``)}`}var nu={"#":`#35;`,'"':`#quot;`,";":`#59;`,"<":`#60;`,">":`#62;`};function ru(e){return e.replace(/[#";<>]/g,e=>nu[e]).replace(/[\r\n\t\f\v\u0000-\u001f\u2028\u2029]+/g,` `)}function iu(e,t){return`${e}:${t}`}var au=new Set;function ou(e,t,n){return n===void 0||n===``?!1:e.has(iu(t,n))}function su(e){let t=e?.viewpoints;return Array.isArray(t)?t:[]}function cu(e,t){let n=new Set,r=(e,t,r)=>{if(t===void 0)return;let i=new Set(t);for(let t of e)t.kind!==void 0&&t.kind!==``&&!i.has(t.kind)&&n.add(iu(r,t.kind))};return r(e.nodes,t.elementKinds,`element`),r(e.edges,t.relationshipKinds,`relationship`),n}function lu(e,t){if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;return!0}var uu=40,du=22;function fu(e){let t=e.containers??[],n;if(t.length===0)n=e.participants;else{let r=new Set(t.map(e=>e.id)),i=new Set;n=[];for(let t of e.participants){if(i.has(t.id))continue;let a=t.container;if(a===void 0||!r.has(a))n.push(t),i.add(t.id);else for(let t of e.participants)t.container!==a||i.has(t.id)||(n.push(t),i.add(t.id))}}let r=[];n.forEach((e,n)=>{let i=t.find(t=>t.id===e.container);if(i===void 0)return;let a=r.at(-1);a!==void 0&&a.container.id===i.id&&a.to===n-1?a.to=n:r.push({container:i,from:n,to:n})});let i=t.length>0?du:0,a=new Map(n.map((e,t)=>[e.id,t])),o=Math.max(...e.participants.map(e=>Tt([$l(e)],Nl(e),110,240)),wt(e.messages.map(e=>e.label??``),110,240)*.8),s=o-14,c=e.participants.reduce((e,t)=>Math.max(e,Dt(Et($l(t),s).length,Ot(Nl(t),s).length)),Dt(1,0))+8;return{columns:n,bands:r,bandHeight:i,lifelineX:o,boxW:s,headerHeight:c,messageGap:uu,width:Math.max(e.participants.length*o,240),height:i+c+(e.messages.length+1)*uu,xOf:e=>(a.get(e)??0)*o+o/2}}function pu(e,t){let n=[$l(e)];t!==`unchanged`&&n.push(`(${Pl[t]})`),e.ref!==void 0&&n.push(`[${e.ref}]`);for(let t of Nl(e))n.push(kt(t));return n.join(` `)}function mu(e,t){let n=t.cx-e.cx,r=t.cy-e.cy;if(n===0&&r===0)return{x:e.cx,y:e.cy};let i=Math.min(n===0?1/0:e.w/2/Math.abs(n),r===0?1/0:e.h/2/Math.abs(r));return{x:e.cx+n*i,y:e.cy+r*i}}function hu(e,t){if(e.length<3)return e.map((e,t)=>`${t===0?`M`:`L`} ${e.x} ${e.y}`).join(` `);let n=[`M ${e[0].x} ${e[0].y}`];for(let r=1;r<e.length-1;r++){let i=e[r-1],a=e[r],o=e[r+1],s=Math.hypot(a.x-i.x,a.y-i.y),c=Math.hypot(o.x-a.x,o.y-a.y);if(s===0||c===0)continue;let l=((a.x-i.x)*(o.y-a.y)-(a.y-i.y)*(o.x-a.x))/(s*c);if(Math.abs(l)<.02)continue;let u=Math.min(t,s/2,c/2),d={x:a.x-(a.x-i.x)/s*u,y:a.y-(a.y-i.y)/s*u},f={x:a.x+(o.x-a.x)/c*u,y:a.y+(o.y-a.y)/c*u};n.push(`L ${d.x} ${d.y}`,`Q ${a.x} ${a.y} ${f.x} ${f.y}`)}let r=e[e.length-1];return n.push(`L ${r.x} ${r.y}`),n.join(` `)}function gu(e,t,n,r,i){if(e===t){let t=26+r*12,n=e.cx-e.w/4,i=e.cx+e.w/4,a=e.y;return{d:`M ${n} ${a} C ${n} ${a-t}, ${i} ${a-t}, ${i} ${a}`,labelAt:{x:e.cx,y:a-t*.75},span:t*2}}let a=mu(e,t),o=mu(t,e),s=Math.hypot(o.x-a.x,o.y-a.y),c=(n??[]).slice(1,-1),l=i===void 0?c:c.map((e,t)=>{let n=c.length===1?.5:t/(c.length-1);return{x:e.x+i.from.dx*(1-n)+i.to.dx*n,y:e.y+i.from.dy*(1-n)+i.to.dy*n}});if(l.length>0&&r===0){let e=l[Math.floor((l.length-1)/2)];return{d:hu([a,...l,o],12),labelAt:e,span:s}}let u=r===0?0:Math.ceil(r/2)*22*(r%2==1?1:-1),d=(a.x+o.x)/2,f=(a.y+o.y)/2;if(u===0)return{d:`M ${a.x} ${a.y} L ${o.x} ${o.y}`,labelAt:{x:d,y:f},span:s};let p=s===0?0:-(o.y-a.y)/s,m=s===0?0:(o.x-a.x)/s,h=d+p*u*2,g=f+m*u*2;return{d:`M ${a.x} ${a.y} Q ${h} ${g} ${o.x} ${o.y}`,labelAt:{x:d+p*u,y:f+m*u},span:s}}function _u(e){let t=(e.match(/-?\d+(?:\.\d+)?/g)??[]).map(Number);if(t.length<2)return;let n=1/0,r=1/0,i=-1/0,a=-1/0;for(let e=0;e+1<t.length;e+=2)n=Math.min(n,t[e]),i=Math.max(i,t[e]),r=Math.min(r,t[e+1]),a=Math.max(a,t[e+1]);return{minX:n,minY:r,maxX:i,maxY:a}}function vu(e,t,n,r){let i=t=>{let n=e.participants.find(e=>e.id===t);return n===void 0?t:$l(n)},a=t.label===void 0||t.label===``?``:`: ${t.label}`;return[`${n+1}.`,`${i(t.from)} → ${i(t.to)}${a}`,t.from===t.to?`(to itself)`:``,r===`unchanged`?``:`[${Pl[r]}]`,Nl(t).map(kt).join(`, `)].filter(e=>e!==``).join(` `)}function yu(e,t,n){let r=t=>{let n=e.nodes.find(e=>e.id===t);return n===void 0?t:$l(n)},i=t.label??t.kind;return[`${r(t.from)} → ${r(t.to)}`,i===void 0?``:`(${i})`,n===`unchanged`?``:`[${Pl[n]}]`,Nl(t).map(kt).join(`, `)].filter(e=>e!==``).join(` `)}function bu(e){if(e===void 0||e===``)return;let t=In(e,Ua);return t.valid?{valid:!0,envelope:t.envelope,issues:[]}:t}function xu(e){let t=bu(e);return t?.valid===!0?t.envelope:void 0}function Su(e){return Rn(e,Ua)}var Cu=`pi-outpost/structured-exchange-arrangement-1`,wu=()=>({format:Cu,views:{}}),Tu=()=>({elements:{},relationships:{}});function Eu(e){return/\.json$/i.test(e)?e.replace(/\.json$/i,`.arrangement.json`):`${e}.arrangement.json`}var Du=e=>e.replace(/[%>#[\]\s]/g,e=>`%${e.charCodeAt(0).toString(16).padStart(2,`0`).toUpperCase()}`);function Ou(e){return e.ref===void 0?`id:${Du(e.id)}`:`ref:${Du(e.ref)}`}function ku(e){let t=new Map(e.nodes.map(e=>[e.id,e])),n=new Map;return e.edges.map(e=>{if(e.ref!==void 0)return`ref:${Du(e.ref)}`;let r=t.get(e.from),i=t.get(e.to),a=`${r===void 0?`id:${Du(e.from)}`:Ou(r)}>${i===void 0?`id:${Du(e.to)}`:Ou(i)}[${Du(e.kind??``)}]`,o=n.get(a)??0;return n.set(a,o+1),`${a}#${o}`})}var Au=e=>typeof e==`object`&&!!e&&!Array.isArray(e),ju=e=>Au(e)&&Number.isFinite(e.x)&&Number.isFinite(e.y);function Mu(e){let t;try{t=JSON.parse(e)}catch{return{ok:!1,reason:`it is not parseable JSON`}}if(!Au(t)||t.format!==`pi-outpost/structured-exchange-arrangement-1`)return{ok:!1,reason:`it does not declare "format": "${Cu}"`};if(!Au(t.views))return{ok:!1,reason:`it has no views`};let n={};for(let[e,r]of Object.entries(t.views)){if(!Au(r))return{ok:!1,reason:`view "${e}" is not an object`};let t=Tu();if(r.orientation!==void 0){if(r.orientation!==`landscape`&&r.orientation!==`portrait`)return{ok:!1,reason:`view "${e}" has an unknown orientation`};t.orientation=r.orientation}if(!Au(r.elements))return{ok:!1,reason:`view "${e}" has no elements`};if(!Au(r.relationships))return{ok:!1,reason:`view "${e}" has no relationships`};for(let[n,i]of Object.entries(r.elements)){if(!ju(i))return{ok:!1,reason:`element "${n}" of view "${e}" has no x and y`};t.elements[n]={x:i.x,y:i.y}}for(let[n,i]of Object.entries(r.relationships)){if(!Au(i))return{ok:!1,reason:`relationship "${n}" of view "${e}" is not an object`};let r={};for(let t of[`exit`,`entry`])if(i[t]!==void 0){if(!ju(i[t]))return{ok:!1,reason:`relationship "${n}" of view "${e}" has an unreadable ${t}`};r[t]={x:i[t].x,y:i[t].y}}if(i.waypoints!==void 0){if(!Array.isArray(i.waypoints)||!i.waypoints.every(ju))return{ok:!1,reason:`relationship "${n}" of view "${e}" has unreadable waypoints`};r.waypoints=i.waypoints.map(e=>({x:e.x,y:e.y}))}if(i.label!==void 0){let t=i.label;if(!Au(t)||!Number.isFinite(t.along)||!ju(t.offset)||t.across!==void 0&&!Number.isFinite(t.across))return{ok:!1,reason:`relationship "${n}" of view "${e}" has an unreadable label`};r.label={along:t.along,...t.across===void 0?{}:{across:t.across},offset:{x:t.offset.x,y:t.offset.y}}}t.relationships[n]=r}n[e]=t}return{ok:!0,arrangement:{format:Cu,views:n}}}var Nu=e=>Math.round(e*1e4)/1e4,Pu=e=>Math.round(e/10)*10,Fu=e=>({x:Pu(e.x),y:Pu(e.y)});function Iu(e){let t={};return e.entry!==void 0&&(t.entry={x:Nu(e.entry.x),y:Nu(e.entry.y)}),e.exit!==void 0&&(t.exit={x:Nu(e.exit.x),y:Nu(e.exit.y)}),e.label!==void 0&&(t.label={...e.label.across===void 0||e.label.across===0?{}:{across:Math.round(e.label.across)},along:Nu(e.label.along),offset:{x:Math.round(e.label.offset.x),y:Math.round(e.label.offset.y)}}),e.waypoints!==void 0&&e.waypoints.length>0&&(t.waypoints=e.waypoints.map(e=>({x:Math.round(e.x),y:Math.round(e.y)}))),t}var Lu=e=>Object.keys(e).sort().map(t=>[t,e[t]]);function Ru(e){let t={};for(let[n,r]of Lu(e.views))t[n]={elements:Object.fromEntries(Lu(r.elements).map(([e,t])=>[e,Fu(t)])),...r.orientation===void 0?{}:{orientation:r.orientation},relationships:Object.fromEntries(Lu(r.relationships).map(([e,t])=>[e,Iu(t)]))};return`${JSON.stringify({format:Cu,views:t},null,2).replace(/\{\n\s*"x": (-?[\d.]+),\n\s*"y": (-?[\d.]+)\n\s*\}/g,`{ "x": $1, "y": $2 }`)}\n`}var zu={shape:`label`,perimeter:`rectanglePerimeter`},Bu={shape:`connector`,endArrow:`classic`,rounded:1},Vu={ellipse:{shape:`ellipse`,perimeter:`ellipsePerimeter`},rhombus:{shape:`rhombus`,perimeter:`rhombusPerimeter`},triangle:{shape:`triangle`,perimeter:`trianglePerimeter`},line:{shape:`line`},image:{shape:`image`},roundImage:{shape:`image`,perimeter:`ellipsePerimeter`},rhombusImage:{shape:`image`,perimeter:`rhombusPerimeter`},arrow:{shape:`arrow`,edgeStyle:`none`},swimlane:{shape:`swimlane`}};function Hu(e,t){let n=e.startsWith(`;`)?{}:{...t?Bu:zu};for(let t of e.split(`;`)){let e=t.indexOf(`=`);if(e>=0){let r=t.slice(0,e),i=t.slice(e+1);i===`none`?delete n[r]:n[r]=i.trim()!==``&&Number.isFinite(Number(i))?Number.parseFloat(i):i}else if(Object.hasOwn(Vu,t))for(let[e,r]of Object.entries(Vu[t]))r===`none`?delete n[e]:n[e]=r}return n}var Uu=(e,t,n)=>{let r=e[t],i=typeof r==`number`?r:Number.parseFloat(String(r??``));return Number.isFinite(i)?i:n},Wu=1,Gu=2,Ku=4,qu=8,Ju=15,Yu=6,Xu=e=>({x:e.x+e.width/2,y:e.y+e.height/2}),Zu=e=>Math.round(e*10)/10,Qu=(e,t,n)=>t>=e.x&&t<=e.x+e.width&&n>=e.y&&n<=e.y+e.height;function $u(e){let{style:t}=e;if(Uu(t,`rotation`,0)%360!=0||t.direction!==void 0&&t.direction!==`east`||Uu(t,`flipH`,0)===1||Uu(t,`flipV`,0)===1)return!1;let n=String(t.shape??``);if(n.startsWith(`mxgraph.`)||n.startsWith(`stencil(`)||Uu(t,`roundedPerimeter`,0)===1&&Uu(t,`rounded`,0)===1||Uu(t,`labelPerimeter`,0)===1)return!1;let r=t.perimeter;return r===void 0||[`rectanglePerimeter`,`ellipsePerimeter`,`rhombusPerimeter`,`centerPerimeter`].includes(String(r))}function ed(e,t,n,r,i,a,o,s){let c=(s-a)*(n-e)-(o-i)*(r-t),l=(o-i)*(t-a)-(s-a)*(e-i),u=(n-e)*(t-a)-(r-t)*(e-i),d=l/c,f=u/c;return d>=0&&d<=1&&f>=0&&f<=1?{x:e+d*(n-e),y:t+d*(r-t)}:null}function td(e,t,n){let r=e.x+e.width/2,i=e.y+e.height/2,a=Math.atan2(t.y-i,t.x-r),o={x:0,y:0},s=Math.PI,c=s/2-a,l=Math.atan2(e.height,e.width);return a<-s+l||a>s-l?(o.x=e.x,o.y=i-e.width*Math.tan(a)/2):a<-l?(o.y=e.y,o.x=r-e.height*Math.tan(c)/2):a<l?(o.x=e.x+e.width,o.y=i+e.width*Math.tan(a)/2):(o.y=e.y+e.height,o.x=r+e.height*Math.tan(c)/2),n&&(t.x>=e.x&&t.x<=e.x+e.width?o.x=t.x:t.y>=e.y&&t.y<=e.y+e.height&&(o.y=t.y),t.x<e.x?o.x=e.x:t.x>e.x+e.width&&(o.x=e.x+e.width),t.y<e.y?o.y=e.y:t.y>e.y+e.height&&(o.y=e.y+e.height)),o}function nd(e,t,n){let{x:r,y:i}=e,a=e.width/2,o=e.height/2,s=r+a,c=i+o,l=t.x,u=t.y,d=Math.trunc(l-s),f=Math.trunc(u-c);if(d===0&&f!==0)return{x:s,y:c+o*f/Math.abs(f)};if(d===0&&f===0)return{x:l,y:u};if(n){if(u>=i&&u<=i+e.height){let e=u-c,t=Math.sqrt(a*a*(1-e*e/(o*o)))||0;return l<=r&&(t=-t),{x:s+t,y:u}}if(l>=r&&l<=r+e.width){let e=l-s,t=Math.sqrt(o*o*(1-e*e/(a*a)))||0;return u<=i&&(t=-t),{x:l,y:c+t}}}let p=a*o/Math.sqrt(o*o*d*d+a*a*f*f);return{x:s+p*d,y:c+p*f}}function rd(e,t,n){let{x:r,y:i}=e,a=e.width,o=e.height,s=r+a/2,c=i+o/2,l=t.x,u=t.y;if(s===l)return c>u?{x:s,y:i}:{x:s,y:i+o};if(c===u)return s>l?{x:r,y:c}:{x:r+a,y:c};let d=s,f=c;return n&&(l>=r&&l<=r+a?d=l:u>=i&&u<=i+o&&(f=u)),l<s?u<c?ed(l,u,d,f,s,i,r,c):ed(l,u,d,f,s,i+o,r,c):u<c?ed(l,u,d,f,s,i,r+a,c):ed(l,u,d,f,s,i+o,r+a,c)}function id(e,t,n,r){let i=r+Uu(e.style,`perimeterSpacing`,0),a={x:e.box.x-i,y:e.box.y-i,width:e.box.width+2*i,height:e.box.height+2*i},o=e.style.perimeter,s=null;return o!==void 0&&(a.width>0||a.height>0)&&(o===`ellipsePerimeter`?s=nd(a,t,n):o===`rhombusPerimeter`?s=rd(a,t,n):o===`rectanglePerimeter`&&(s=td(a,t,n))),s??Xu(e.box)}var ad=(e,t)=>({x:t.x+e.origin.x,y:t.y+e.origin.y});function od(e){let t=(e&Wu)<<3;return t|=(e&Gu)<<1,t|=(e&Ku)>>1,t|=(e&qu)>>3,t}function sd(e,t,n){let r=e.style.portConstraint??t.style[n?`sourcePortConstraint`:`targetPortConstraint`];if(r===void 0)return Ju;let i=String(r),a=0;return i.includes(`north`)&&(a|=Gu),i.includes(`west`)&&(a|=Wu),i.includes(`south`)&&(a|=Ku),i.includes(`east`)&&(a|=qu),a}var cd=10;function ld(e,t){let n=e.style[t?`sourceJettySize`:`targetJettySize`]??e.style.jettySize??cd;if(n===`auto`){let n=e.style[t?`startArrow`:`endArrow`];if(n!==void 0&&n!==`none`){let n=Uu(e.style,t?`startSize`:`endSize`,Yu);return Math.max(2,Math.ceil((n+cd)/cd))*cd}return 20}return typeof n==`number`?n:Number.parseFloat(String(n))}var ud=(e,t,n,r,i)=>{let a=e.absolutePoints.map(e=>e===null?null:{x:Zu(e.x),y:Zu(e.y)}),o=t?.box??null,s=n?.box??null,c=[],l=e=>c.push(e),u=i.length>0&&i[0]!=null?{x:i[0].x,y:i[0].y}:null,d=!0,f=null,p=e=>(e.x=Zu(e.x),e.y=Zu(e.y),(u===null||Math.abs(u.x-e.x)>=1||Math.abs(u.y-e.y)>=1)&&(i.push({x:e.x,y:e.y}),u=e),u),m=a[0]??null;m===null&&t!==null?m=Xu(t.box):m!==null&&(m={...m});let h=a.length-1,g;if(r!==null&&r.length>0){let i=r.map(t=>ad(e,t));if(i.length===0)return;m!==null&&i[0]!==void 0&&(Math.abs(i[0].x-m.x)<1&&(i[0].x=m.x),Math.abs(i[0].y-m.y)<1&&(i[0].y=m.y)),g=a[h],g!=null&&i[i.length-1]!==void 0&&(Math.abs(i[i.length-1].x-g.x)<1&&(i[i.length-1].x=g.x),Math.abs(i[i.length-1].y-g.y)<1&&(i[i.length-1].y=g.y)),f=i[0];let c=t,u=o,p=a[0],_=!1,v=!1,y=f;p!=null&&(c=null);for(let e=0;e<2;e++){let t=p!=null&&p.x===y.x,r=p!=null&&p.y===y.y,o=c!==null&&y.y>=u.y&&y.y<=u.y+u.height,l=c!==null&&y.x>=u.x&&y.x<=u.x+u.width;if(_=r||p==null&&o,v=t||p==null&&l,!(e===0&&(_&&v||t&&r))){if(p!=null&&!r&&!t&&(o||l)){d=!o;break}if(v||_){d=_,e===1&&(d=i.length%2==0?_:v);break}}c=n,u=s,p=a[h],p!=null&&(c=null),y=i[i.length-1],t&&r&&(i=i.slice(1))}d&&(a[0]!=null&&a[0].y!==f.y||a[0]==null&&t!==null&&(f.y<o.y||f.y>o.y+o.height))?l({x:m.x,y:f.y}):!d&&(a[0]!=null&&a[0].x!==f.x||a[0]==null&&t!==null&&(f.x<o.x||f.x>o.x+o.width))&&l({x:f.x,y:m.y}),d?m.y=f.y:m.x=f.x;for(let e of i)d=!d,f=e,d?m.y=f.y:m.x=f.x,l({...m})}else f=m,d=!0;if(m=a[h]??null,m===null&&n!==null&&(m=Xu(n.box)),m!==null&&f!==null&&(d&&(a[h]!=null&&a[h].y!==f.y||a[h]==null&&n!==null&&(f.y<s.y||f.y>s.y+s.height))?l({x:m.x,y:f.y}):!d&&(a[h]!=null&&a[h].x!==f.x||a[h]==null&&n!==null&&(f.x<s.x||f.x>s.x+s.width))&&l({x:f.x,y:m.y})),a[0]==null&&t!==null)for(;c.length>0&&Qu(o,c[0].x,c[0].y);)c.splice(0,1);if(a[h]==null&&n!==null)for(;c.length>0&&Qu(s,c[c.length-1].x,c[c.length-1].y);)c.splice(c.length-1,1);for(let e of c)p(e);let _=i[i.length-1];if(g!=null&&_!=null&&Math.abs(g.x-_.x)<=1&&Math.abs(g.y-_.y)<=1){i.splice(i.length-1,1);let e=i[i.length-1];e!=null&&(Math.abs(e.x-g.x)<1&&(e.x=g.x),Math.abs(e.y-g.y)<1&&(e.y=g.y))}},dd=[[-1,0],[0,-1],[1,0],[0,1],[-1,0],[0,-1],[1,0]],fd=[[[513,2308,2081,2562],[513,1090,514,2184,2114,2561],[513,1090,514,2564,2184,2562],[513,2308,2561,1090,514,2568,2308]],[[514,1057,513,2308,2081,2562],[514,2184,2114,2561],[514,2184,2562,1057,513,2564,2184],[514,1057,513,2568,2308,2561]],[[1090,514,1057,513,2308,2081,2562],[2114,2561],[1090,2562,1057,513,2564,2184],[1090,514,1057,513,2308,2561,2568]],[[2081,2562],[1057,513,1090,514,2184,2114,2561],[1057,513,1090,514,2184,2562,2564],[1057,2561,1090,514,2568,2308]]],pd=1024,md=2048,hd=480,gd=512,_d=(e,t,n,r,i)=>{let a=e.absolutePoints.map(e=>e===null?null:{x:Zu(e.x),y:Zu(e.y)}),o=t===null?null:{...t.box,x:Zu(t.box.x),y:Zu(t.box.y),width:Zu(t.box.width),height:Zu(t.box.height)},s=n===null?null:{...n.box,x:Zu(n.box.x),y:Zu(n.box.y),width:Zu(n.box.width),height:Zu(n.box.height)},c=a[0]??null,l=a[a.length-1]??null,u=o===null?c.x:o.x,d=o===null?c.y:o.y,f=o===null?1:o.width,p=o===null?1:o.height,m=s===null?l.x:s.x,h=s===null?l.y:s.y,g=s===null?1:s.width,_=s===null?1:s.height,v=ld(e,!0),y=ld(e,!1),b=y+v,x=!1;if(c!==null&&l!==null){let e=l.x-c.x,t=l.y-c.y;x=e*e+t*t<b*b}if(x||r!==null&&r.length>0){ud(e,t,n,r,i);return}let S=[Ju,Ju];if(t!==null&&(S[0]=sd(t,e,!0)),n!==null&&(S[1]=sd(n,e,!1)),f===0||p===0||g===0||_===0)return;let C=[0,0],w=[[u,d,f,p],[m,h,g,_]],T=[v,y],E=[[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0]];for(let e=0;e<2;e++)E[e][1]=w[e][0]-T[e],E[e][2]=w[e][1]-T[e],E[e][4]=w[e][0]+w[e][2]+T[e],E[e][8]=w[e][1]+w[e][3]+T[e];let D=w[0][0]+w[0][2]/2,O=w[0][1]+w[0][3]/2,ee=w[1][0]+w[1][2]/2,te=w[1][1]+w[1][3]/2,k=D-ee,ne=O-te,A=0;k<0?A=ne<0?2:1:ne<=0&&(A=3,k===0&&(A=2));let re=t===null?null:c,j=[[.5,.5],[.5,.5]];t===null&&(j[0]=[0,0]),n===null&&(j[1]=[0,0]);for(let e=0;e<2;e++)re!==null&&(j[e][0]=(re.x-w[e][0])/w[e][2],Math.abs(re.x-w[e][0])<=1?C[e]=Wu:Math.abs(re.x-w[e][0]-w[e][2])<=1&&(C[e]=qu),j[e][1]=(re.y-w[e][1])/w[e][3],Math.abs(re.y-w[e][1])<=1?C[e]=Gu:Math.abs(re.y-w[e][1]-w[e][3])<=1&&(C[e]=Ku)),re=n===null?null:l;let ie=w[0][1]-(w[1][1]+w[1][3]),ae=w[0][0]-(w[1][0]+w[1][2]),oe=w[1][1]-(w[0][1]+w[0][3]),se=w[1][0]-(w[0][0]+w[0][2]),ce=[];ce[1]=Math.max(ae-b,0),ce[2]=Math.max(ie-b,0),ce[4]=Math.max(oe-b,0),ce[3]=Math.max(se-b,0);let le=[],ue=[],de=[];ue[0]=ae>=se?Wu:qu,de[0]=ie>=oe?Gu:Ku,ue[1]=od(ue[0]),de[1]=od(de[0]);let fe=ae>=se?ae:se,M=ie>=oe?ie:oe,pe=[[0,0],[0,0]],N=!1;for(let e=0;e<2;e++)C[e]===0&&((ue[e]&S[e])===0&&(ue[e]=od(ue[e])),(de[e]&S[e])===0&&(de[e]=od(de[e])),pe[e][0]=de[e],pe[e][1]=ue[e]);M>0&&fe>0&&((ue[0]&S[0])>0&&(de[1]&S[1])>0?(pe[0]=[ue[0],de[0]],pe[1]=[de[1],ue[1]],N=!0):(de[0]&S[0])>0&&(ue[1]&S[1])>0&&(pe[0]=[de[0],ue[0]],pe[1]=[ue[1],de[1]],N=!0)),M>0&&!N&&(pe[0]=[de[0],ue[0]],pe[1]=[de[1],ue[1]],N=!0),fe>0&&!N&&(pe[0]=[ue[0],de[0]],pe[1]=[ue[1],de[1]],N=!0);for(let e=0;e<2;e++)C[e]===0&&((pe[e][0]&S[e])===0&&(pe[e][0]=pe[e][1]),le[e]=pe[e][0]&S[e],le[e]|=(pe[e][1]&S[e])<<8,le[e]|=(pe[1-e][e]&S[e])<<16,le[e]|=(pe[1-e][1-e]&S[e])<<24,le[e]&15||(le[e]=le[e]<<8),le[e]&3840||(le[e]=le[e]&15|le[e]>>8),le[e]&983040||(le[e]=le[e]&65535|(le[e]&251658240)>>8),C[e]=le[e]&15,(S[e]===Wu||S[e]===Gu||S[e]===qu||S[e]===Ku)&&(C[e]=S[e]));let me=C[0]===qu?3:C[0],he=C[1]===qu?3:C[1];me-=A,he-=A,me<1&&(me+=4),he<1&&(he+=4);let ge=fd[me-1][he-1],P=Array.from({length:12},()=>[0,0]);switch(P[0][0]=w[0][0],P[0][1]=w[0][1],C[0]){case Wu:P[0][0]-=v,P[0][1]+=j[0][1]*w[0][3];break;case Ku:P[0][0]+=j[0][0]*w[0][2],P[0][1]+=w[0][3]+v;break;case qu:P[0][0]+=w[0][2]+v,P[0][1]+=j[0][1]*w[0][3];break;case Gu:P[0][0]+=j[0][0]*w[0][2],P[0][1]-=v}let _e=0,ve=(C[0]&9)>0?0:1,ye=ve,be=0;for(let e of ge){let t=e&15,n=t===qu?3:t;n+=A,n>4&&(n-=4);let r=dd[n-1];be=n%2>0?0:1,be!==ve&&(_e++,P[_e][0]=P[_e-1][0],P[_e][1]=P[_e-1][1]);let i=(e&md)>0,a=(e&pd)>0,o=(e&hd)>>5;o<<=A,o>15&&(o>>=4);let s=(e&gd)>0;if((a||i)&&o<9){let e=0,t=+!a;if(e=s&&be===0?w[t][0]+j[t][0]*w[t][2]:s?w[t][1]+j[t][1]*w[t][3]:E[t][o],be===0){let t=P[_e][0],n=(e-t)*r[0];n>0&&(P[_e][0]+=r[0]*n)}else{let t=P[_e][1],n=(e-t)*r[1];n>0&&(P[_e][1]+=r[1]*n)}}else s&&(P[_e][0]+=r[0]*Math.abs(ce[n]/2),P[_e][1]+=r[1]*Math.abs(ce[n]/2));_e>0&&P[_e][be]===P[_e-1][be]?_e--:ve=be}for(let e=0;e<=_e&&(e!==_e||(((C[1]&9)>0?0:1)===ye?0:1)==(_e+1)%2);e++)i.push({x:Zu(P[e][0]),y:Zu(P[e][1])});let xe=1;for(;xe<i.length;){let[e,t]=[i[xe-1],i[xe]];e==null||t==null||e.x!==t.x||e.y!==t.y?xe++:i.splice(xe,1)}},vd=(e,t,n)=>Qu(e,t,n),yd=(e,t,n,r,i)=>{let a=r!==null&&r.length>0?ad(e,r[0]):null,o=e.absolutePoints[0],s=e.absolutePoints[e.absolutePoints.length-1],c=o==null?t?.box??null:{x:o.x,y:o.y,width:0,height:0},l=s==null?n?.box??null:{x:s.x,y:s.y,width:0,height:0};if(c===null||l===null)return;let u=Math.max(c.x,l.x),d=Math.min(c.x+c.width,l.x+l.width),f=a===null?Math.round(d+(u-d)/2):a.x,p=c.y+c.height/2,m=l.y+l.height/2;if(a!==null&&(a.y>=c.y&&a.y<=c.y+c.height&&(p=a.y),a.y>=l.y&&a.y<=l.y+l.height&&(m=a.y)),!vd(l,f,p)&&!vd(c,f,p)&&i.push({x:f,y:p}),!vd(l,f,m)&&!vd(c,f,m)&&i.push({x:f,y:m}),i.length===1){if(a!==null)!vd(l,f,a.y)&&!vd(c,f,a.y)&&i.push({x:f,y:a.y});else{let e=Math.max(c.y,l.y),t=Math.min(c.y+c.height,l.y+l.height);i.push({x:f,y:e+(t-e)/2})}}a=null},bd=(e,t,n,r,i)=>{let a=r!==null&&r.length>0?ad(e,r[0]):null,o=e.absolutePoints[0],s=e.absolutePoints[e.absolutePoints.length-1],c=o==null?t?.box??null:{x:o.x,y:o.y,width:0,height:0},l=s==null?n?.box??null:{x:s.x,y:s.y,width:0,height:0};if(c===null||l===null)return;let u=Math.max(c.y,l.y),d=Math.min(c.y+c.height,l.y+l.height),f=c.x+c.width/2;a!==null&&a.x>=c.x&&a.x<=c.x+c.width&&(f=a.x);let p=a===null?Math.round(d+(u-d)/2):a.y;if(!vd(l,f,p)&&!vd(c,f,p)&&i.push({x:f,y:p}),f=a!==null&&a.x>=l.x&&a.x<=l.x+l.width?a.x:l.x+l.width/2,!vd(l,f,p)&&!vd(c,f,p)&&i.push({x:f,y:p}),i.length===1){if(a!==null)!vd(l,a.x,p)&&!vd(c,a.x,p)&&i.push({x:a.x,y:p});else{let e=Math.max(c.x,l.x),t=Math.min(c.x+c.width,l.x+l.width);i.push({x:e+(t-e)/2,y:p})}}},xd=(e,t,n,r,i)=>{let a=r!==null&&r.length>0?r[0]:null,o=!1,s=!1;if(t!==null&&n!==null){let r=t.box,i=n.box;if(a!==null){let t=Math.min(r.x,i.x),n=Math.max(r.x+r.width,i.x+i.width),c=Math.min(r.y,i.y),l=Math.max(r.y+r.height,i.y+i.height);a=ad(e,a),o=a.y<c||a.y>l,s=a.x<t||a.x>n}else o=Math.max(r.x,i.x)===Math.min(r.x+r.width,i.x+i.width),o||(s=Math.max(r.y,i.y)===Math.min(r.y+r.height,i.y+i.height))}!s&&(o||e.style.elbow===`vertical`)?bd(e,t,n,r,i):yd(e,t,n,r,i)},Sd={orthogonalEdgeStyle:_d,segmentEdgeStyle:ud,elbowEdgeStyle:xd,sideToSideEdgeStyle:yd,topToBottomEdgeStyle:bd},Cd=new Set([_d,ud,xd,yd,bd]),wd=new Set([xd,yd,bd]);function Td(e){let t=new Map(e.cells.filter(e=>e.id!==void 0).map(e=>[e.id,e])),n=new Map,r=(e,i=new Set)=>{if(e.id!==void 0&&n.has(e.id))return n.get(e.id);let a={x:0,y:0},o=e.parent===void 0?void 0:t.get(e.parent);if(o!==void 0&&!i.has(o.id??``)){if(i.add(o.id??``),o.edge)a=null;else if(o.vertex){let e=r(o,i),t=o.geometry;a=e===null||t===void 0||t.relative?null:{x:e.x+t.x,y:e.y+t.y}}}return e.id!==void 0&&n.set(e.id,a),a},i=new Map;for(let t of e.cells){if(t.id===void 0)continue;let e=r(t);!t.vertex||t.geometry===void 0||t.geometry.relative||e===null||t.geometry.unreadable.length>0||i.set(t.id,{box:{x:e.x+t.geometry.x,y:e.y+t.geometry.y,width:t.geometry.width,height:t.geometry.height},style:Hu(t.style,!1)})}return{terminals:i,origins:n}}function Ed(e,t){let n=e.geometry;if(n===void 0||e.id===void 0)return;let r=t.origins.get(e.id);if(r==null)return;let i=Hu(e.style,!0);if(i.sourcePort!==void 0||i.targetPort!==void 0||i.snapToPoint!==void 0||Uu(i,`fixedPointSpacing`,0)===1||i.orthogonal!==void 0)return;let a=e.source===void 0?null:t.terminals.get(e.source),o=e.target===void 0?null:t.terminals.get(e.target);if(a===void 0||o===void 0||a!==null&&!$u(a)||o!==null&&!$u(o)||a!==null&&a===o)return;let s=Uu(i,`noEdgeStyle`,0)===1?void 0:i.edgeStyle,c=s===void 0?null:Sd[String(s)];if(c===void 0)return;let l={style:i,absolutePoints:[null,null],origin:r},u=(e,t)=>{let a=t?`exit`:`entry`;if(e!==null&&e.style.perimeter===`centerPerimeter`)return Xu(e.box);let o=i[`${a}X`],s=i[`${a}Y`];if(e!==null&&o!==void 0&&s!==void 0){let t=Number.parseFloat(String(o)),n=Number.parseFloat(String(s)),r=i[`${a}Perimeter`]===void 0||!!Number(i[`${a}Perimeter`]),c=Uu(i,`${a}Dx`,0),l=Uu(i,`${a}Dy`,0),u={x:e.box.x+t*e.box.width+c,y:e.box.y+n*e.box.height+l};return r&&(u=id(e,u,!1,0)),u}if(e===null){let e=t?n.sourcePointAt:n.targetPointAt;return e===void 0?null:{x:e.x+r.x,y:e.y+r.y}}return null};if(l.absolutePoints=[u(a,!0),u(o,!1)],a===null&&l.absolutePoints[0]===null||o===null&&l.absolutePoints[1]===null)return;let d=n.points.length>0?n.points:null,f=[l.absolutePoints[0]];if(c!==null)c(l,a,o,d,f);else if(d!==null)for(let e of d)f.push(ad(l,e));f.push(l.absolutePoints[1]);let p=c!==null&&Cd.has(c),m=(e,t,n)=>{let r=f.length,a=f[n?Math.min(1,r-1):Math.max(0,r-2)]??null;a===null&&t!==null&&(a=Xu(t.box));let o=Uu(i,`perimeterSpacing`,0)+Uu(i,n?`sourcePerimeterSpacing`:`targetPerimeterSpacing`,0);return a===null?Xu(e.box):id(e,a,p,o)};if(f[f.length-1]===null&&o!==null&&(f[f.length-1]=m(o,a,!1)),f[0]===null&&a!==null&&(f[0]=m(a,o,!0)),c!==null&&(wd.has(c)||c===_d&&d===null)&&f.length>2){let e=(e,t)=>e!==null&&t!==null&&Math.abs(e.x-t.x)<.01&&Math.abs(e.y-t.y)<.01,t=!1;for(let n=1;n<f.length&&!t;n++)t=e(f[n-1],f[n]);if(t)for(let t=f.length-2;t>0&&f.length>2;t--)(e(f[t],f[t+1])||e(f[t],f[t-1]))&&f.splice(t,1)}if(f.some(e=>e===null)||f.length<2)return;let h=f,g=[],_=0;for(let e=1;e<h.length;e++){let t=Math.hypot(h[e-1].x-h[e].x,h[e-1].y-h[e].y);g.push(t),_+=t}return{points:h,segments:g,length:_}}function Dd(e,t,n={x:0,y:0}){let{points:r,segments:i}=e,a=t.x/2,o=Math.round((a+.5)*e.length),s=i[0]??0,c=0,l=1;for(;o>=Math.round(c+s)&&l<r.length-1;)c+=s,s=i[l++];let u=s===0?0:(o-c)/s,d=r[l-1],f=r[l],p=f.x-d.x,m=f.y-d.y,h=s===0?0:m/s,g=s===0?0:p/s;return{x:d.x+p*u+(h*t.y+n.x),y:d.y+m*u-(g*t.y-n.y)}}function Od(e){let t=String(e.shape??``);return t===`ellipse`||t===`doubleEllipse`?`ellipse`:t===`rhombus`?`rhombus`:`box`}function kd(e,t,n,r,i){let a=n.width/2-i,o=n.height/2-i;if(a<=0||o<=0)return 0;let s=n.x+n.width/2,c=n.y+n.height/2,l=(e.x-s)/a,u=(e.y-c)/o,d=(t.x-e.x)/a,f=(t.y-e.y)/o,p=0,m=1;if(r===`ellipse`){let e=d*d+f*f;if(e===0)return 0;let t=2*(l*d+u*f),n=l*l+u*u-1,r=t*t-4*e*n;if(r<=0)return 0;let i=Math.sqrt(r);p=Math.max(0,(-t-i)/(2*e)),m=Math.min(1,(-t+i)/(2*e))}else{let e=r===`box`?[[1,0],[-1,0],[0,1],[0,-1]]:[[1,1],[1,-1],[-1,1],[-1,-1]];for(let[t,n]of e){let e=t*l+n*u-1,r=t*d+n*f;if(r===0){if(e>=0)return 0;continue}let i=-e/r;r<0?p=Math.max(p,i):m=Math.min(m,i)}}return m<=p?0:(m-p)*Math.hypot(t.x-e.x,t.y-e.y)}function Ad(e,t){let n=Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x),r=Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y);return n>0&&r>0?n*r:0}function jd(e,t,n){let r=Math.max(1,t.length)*n*.45,i=n*1.18;return{x:e.x-r/2,y:e.y-i/2,width:r,height:i}}function Md(e,t,n,r={x:0,y:0}){let i=[e.label,...t.filter(t=>t.parent===e.id).map(e=>e.label)],a=t=>{let n=n=>{let r=RegExp(`(?:^|;)${t}${n}=([^;]*)`).exec(e.style)?.[1],i=r===void 0?NaN:Number.parseFloat(r);return Number.isFinite(i)?i:void 0},r=n(`X`),i=n(`Y`);return r===void 0||i===void 0?void 0:{x:r,y:i}};return{id:e.id,label:i.filter(e=>e!==``).join(` `),source:e.source,target:e.target,exit:a(`exit`),entry:a(`entry`),points:n,waypoints:(e.geometry?.points??[]).map(e=>({x:r.x+e.x,y:r.y+e.y}))}}var Nd=[.25,.5,.75,.125,.375,.625,.875],Pd=.06;function Fd(e,t){let n=t.x+t.width/2-(e.x+e.width/2),r=t.y+t.height/2-(e.y+e.height/2);return Math.abs(n)>=Math.abs(r)?n>=0?`X=1;Y=0.5`:`X=0;Y=0.5`:r>=0?`X=0.5;Y=1`:`X=0.5;Y=0`}var Id=(e,t)=>{let[n,r]=Fd(e,t).split(`;`).map(e=>Number(e.slice(2)));return{x:e.x+e.width*n,y:e.y+e.height*r}},Ld=(e,t)=>e.x<t.x+t.width&&t.x<e.x+e.width&&e.y<t.y+t.height&&t.y<e.y+e.height,Rd=e=>e.reduce((t,n,r)=>r===0?0:t+Math.hypot(n.x-e[r-1].x,n.y-e[r-1].y),0),zd=e=>e.replace(/\s+/g,` `).trim().toLowerCase();function Bd(e,t){let n=e.width>0?(t.x-e.x)/e.width:.5,r=e.height>0?(t.y-e.y)/e.height:.5,[i,,a]=[[`left`,Math.abs(n),r],[`right`,Math.abs(1-n),r],[`top`,Math.abs(r),n],[`bottom`,Math.abs(1-r),n]].reduce((e,t)=>t[1]<e[1]?t:e);return{side:i,along:a}}var Vd=(e,t)=>{let n=String(t);return e===`left`?`X=0;Y=${n}`:e===`right`?`X=1;Y=${n}`:e===`top`?`X=${n};Y=0`:`X=${n};Y=1`};function Hd(e){let t=e=>e>0&&e<1;if(e.x===0&&t(e.y))return`left`;if(e.x===1&&t(e.y))return`right`;if(e.y===0&&t(e.x))return`top`;if(e.y===1&&t(e.x))return`bottom`}function Ud(e,t,n){return t===`right`?n.x+n.width<=e.x:t===`left`?n.x>=e.x+e.width:t===`bottom`?n.y+n.height<=e.y:n.y>=e.y+e.height}var Wd={left:`left side`,right:`right side`,top:`top`,bottom:`bottom`},Gd=(e,t)=>`${e}:${t}`;function Kd(e,t){let n=new Map;for(let r of e){if(r.points.length<2)continue;let e=(e,i,a)=>{if(e===void 0||!t.has(e))return;let o=n.get(e)??[];o.push({wire:r,shape:e,point:i,role:a}),n.set(e,o)};e(r.source,r.points[0],`exit`),e(r.target,r.points[r.points.length-1],`entry`)}return n}function qd(e,t){let n=[];for(let r of e){if(r.points.length<2)continue;let e=r.source===void 0?void 0:t.get(r.source),i=r.target===void 0?void 0:t.get(r.target);if(e!==void 0&&i!==void 0)for(let[t,a,o,s]of[[`exit`,r.exit,e,i],[`entry`,r.entry,i,e]]){let e=a===void 0?void 0:Hd(a);e!==void 0&&Ud(o,e,s)&&n.push({wire:r,role:t,side:e})}}return n}function Jd(e,t,n){let r=new Map,i=Kd(e,t);for(let[e,a]of i){let i=t.get(e),o=new Map;for(let e of a){if(!n.has(Gd(e.wire.id,e.role)))continue;let r=e.role===`exit`?e.wire.target:e.wire.source,a=r===void 0?void 0:t.get(r);if(a===void 0)continue;let s=Bd(i,Id(i,a)).side;o.set(s,[...o.get(s)??[],e])}for(let[e,t]of o){let o=a.filter(e=>!n.has(Gd(e.wire.id,e.role))).map(e=>Bd(i,e.point)).filter(t=>t.side===e).map(e=>e.along),s=t.length===1?[.5,...Nd.filter(e=>e!==.5)]:t.length===2?[.25,.75,...Nd.filter(e=>e!==.25&&e!==.75)]:Nd,c=s.filter(e=>o.every(t=>Math.abs(t-e)>Pd));t.forEach((t,n)=>{let o=c[n];o===void 0?r.set(Gd(t.wire.id,t.role),Xd(i,a,r,e)??Vd(e,s[n%s.length])):r.set(Gd(t.wire.id,t.role),Vd(e,o))})}}return r}function Yd(e,t,n,r,i){return t.flatMap(t=>{let a=Gd(t.wire.id,t.role),o=n.get(a);if(o!==void 0){let[t,n]=o.split(`;`).map(e=>Number(e.slice(2))),i=Bd(e,{x:e.x+e.width*t,y:e.y+e.height*n});return i.side===r?[i.along]:[]}if(i?.has(a))return[];let s=Bd(e,t.point);return s.side===r?[s.along]:[]})}function Xd(e,t,n,r){for(let i of[`right`,`bottom`,`left`,`top`].filter(e=>e!==r)){let r=Yd(e,t,n,i),a=Nd.find(e=>r.every(t=>Math.abs(t-e)>Pd));if(a!==void 0)return Vd(i,a)}}function Zd(e,t,n){let r=qd(e,t).filter(e=>!n.has(e.wire.id)),i=new Set([...[...n].flatMap(([e,t])=>t.map(t=>Gd(e,t))),...r.map(e=>Gd(e.wire.id,e.role))]);return{away:r,moving:i,placements:Jd(e,t,i)}}function Qd(e,t,n){let r=new Map;for(let[i,a]of Zd(e,t,n).placements){let e=i.slice(i.lastIndexOf(`:`)+1);r.set(i,a.split(`;`).map(t=>`${e}${t}`).join(`;`))}return r}var $d=e=>`(${Math.round(e.x)}, ${Math.round(e.y)})`;function ef(e,t){let n=(e,t)=>Math.abs(e.x-t.x)<=1&&Math.abs(e.y-t.y)<=1;for(let r=0;r+1<e.length;r++){let i=e[r],a=e[r+1],o=Math.hypot(a.x-i.x,a.y-i.y);if(o>=.5&&o<20){let e=Math.abs(a.x-i.x)<Math.abs(a.y-i.y),r=n=>t.find(t=>e?Math.abs(t.y-n.y)<=1:Math.abs(t.x-n.x)<=1),s=t.find(e=>n(e,a))??t.find(e=>n(e,i))??r(a)??r(i),c=`a ${Math.max(1,Math.round(o))}-unit segment`;if(s===void 0)return{where:i,why:c,vertical:e,waypoints:t,fix:``};let l=n(s,a)||(e?Math.abs(s.y-a.y)<=1:Math.abs(s.x-a.x)<=1)?i:a,u=e?{x:s.x,y:l.y}:{x:l.x,y:s.y};return{where:i,why:c,vertical:e,waypoint:s,waypoints:t.map(e=>e===s?u:e),fix:`move its waypoint at ${$d(s)} to ${$d(u)}`}}let s=e[r+2];if(s===void 0)continue;let c={x:a.x-i.x,y:a.y-i.y},l={x:s.x-a.x,y:s.y-a.y};if(Math.abs(c.x*l.y-c.y*l.x)<.5&&c.x*l.x+c.y*l.y<0){let e=t.find(e=>n(e,a)),r=`a segment that goes back over the one before it`;return e===void 0?{where:a,why:r,vertical:c.x===0,waypoints:t,fix:``}:{where:a,why:r,vertical:c.x===0,waypoint:e,waypoints:t.filter(t=>t!==e),fix:`remove its waypoint at ${$d(e)}`}}}}function tf(e,t,n=e=>`"${e}"`,r=new Map,i){let a=[],{away:o,moving:s,placements:c}=Zd(e,t,r),l=(e,t)=>c.get(Gd(e,t)).split(`;`).map(e=>`${t}${e}`).join(`;`),u=new Map;for(let[r,i]of Kd(e,t)){let e=t.get(r),o=i.filter(e=>!s.has(Gd(e.wire.id,e.role))),l=[];for(let e of o){let t=l.find(t=>Math.abs(t[0].point.x-e.point.x)<=1&&Math.abs(t[0].point.y-e.point.y)<=1);t?t.push(e):l.push([e])}for(let s of l){if(new Set(s.map(e=>e.wire.id)).size<2)continue;let l=new Set(s.map(e=>zd(e.wire.label)));if(l.size===1&&!l.has(``))continue;let{side:d,along:f}=Bd(e,s[0].point),p=[...o.map(t=>Bd(e,t.point)).filter(e=>e.side===d).map(e=>e.along),...i.flatMap(t=>{let n=c.get(Gd(t.wire.id,t.role));if(n===void 0)return[];let[r,i]=n.split(`;`).map(e=>Number(e.slice(2))),a=Bd(e,{x:e.x+e.width*r,y:e.y+e.height*i});return a.side===d?[a.along]:[]})];p.push(...u.get(`${r}:${d}`)??[]);let m=Nd.filter(e=>p.every(t=>Math.abs(t-e)>Pd)&&Math.abs(f-e)>Pd),h=s.slice(1);u.set(`${r}:${d}`,[...u.get(`${r}:${d}`)??[],...m.slice(0,h.length)]);let g=s.map(e=>n(e.wire.id)),_=l.has(``)?`they are not labelled as the same data`:`they carry different data`,v=h.slice(0,m.length).map((e,t)=>`${Vd(d,m[t]).split(`;`).map(t=>`${e.role}${t}`).join(`;`)} for ${n(e.wire.id)}`),y=t=>[...i.map(t=>Bd(e,t.point)).filter(e=>e.side===t).map(e=>e.along),...i.flatMap(n=>c.has(Gd(n.wire.id,n.role))?Yd(e,[n],c,t):[]),...u.get(`${r}:${t}`)??[]],b=h.slice(m.length).map(i=>{let a=i.role===`exit`?i.wire.target:i.wire.source,o=a===void 0?void 0:t.get(a),s=o===void 0?void 0:Bd(e,Id(e,o)).side,c=[...new Set([s,`right`,`bottom`,`left`,`top`])].filter(e=>e!==void 0&&e!==d);for(let e of c){let t=Nd.find(t=>y(e).every(e=>Math.abs(e-t)>Pd));if(t!==void 0)return u.set(`${r}:${e}`,[...u.get(`${r}:${e}`)??[],t]),`${Vd(e,t).split(`;`).map(e=>`${i.role}${e}`).join(`;`)} for ${n(i.wire.id)}, on its ${Wd[e]}`}return`${n(i.wire.id)}: no side of this shape has a free point left, so make the shape larger`}),x=v.length===0?`that ${Wd[d]} has no free point left, so move them to other sides: ${b.join(`, `)}`:`give each its own point on its ${Wd[d]}: ${v.join(`, `)}${b.length>0?`, and, since that side has no free point left, ${b.join(`, `)}`:``}`;a.push({rule:`shared-point`,wires:[...new Set(s.map(e=>e.wire.id))],shapes:[r],message:`connectors ${g.join(`, `)} meet shape ${n(r)} at the same point, and ${_}: ${x}. Only wires with the same label may share a point`})}}let d=new Set;for(let{wire:e,role:t,side:r}of o){d.add(e.id);let i=t===`exit`?e.source:e.target,o=t===`exit`?e.target:e.source;a.push({rule:`facing-away`,wires:[e.id],shapes:[i],message:`connector ${n(e.id)} ${t===`exit`?`leaves`:`enters`} shape ${n(i)} on its ${Wd[r]}, facing away from ${n(o)}: fix it on the side facing it (${l(e.id,t)}), or drop ${t}X/${t}Y to let draw.io choose`})}for(let i of e){if(i.points.length<2||d.has(i.id)||r.has(i.id))continue;let e=i.source===void 0?void 0:t.get(i.source),o=i.target===void 0?void 0:t.get(i.target);if(e===void 0||o===void 0||Ld(e,o))continue;let s=Id(e,o),c=Id(o,e),l=Math.hypot(c.x-s.x,c.y-s.y),u=Rd(i.points);if(u<=2*l||u-l<80)continue;let f=Fd(e,o).split(`;`).map(e=>`exit${e}`).join(`;`),p=Fd(o,e).split(`;`).map(e=>`entry${e}`).join(`;`);a.push({rule:`detour`,wires:[i.id],shapes:[i.source,i.target],message:`connector ${n(i.id)} runs ${Math.round(u)} units to join shapes ${n(i.source)} and ${n(i.target)}, whose facing sides are ${Math.round(l)} apart: fix its exit and entry on those sides (${f};${p}), or give it a waypoint on the short way (<Array as="points"><mxPoint x="…" y="…"/></Array> in its geometry)`})}for(let o of e){if(o.waypoints.length===0&&o.exit===void 0&&o.entry===void 0||d.has(o.id)||r.has(o.id))continue;let e=ef(o.points,o.waypoints);if(e===void 0)continue;let s=(e,t)=>{if(i===void 0)return!0;let n=i(o,e,t);return n!==void 0&&ef(n,e)===void 0},c;if(e.waypoint!==void 0&&s(e.waypoints)?c=e.fix:s([])&&(c=`remove its waypoints (the <Array as="points"> in its geometry) to let draw.io route it`),c===void 0){let n=o.source===void 0?void 0:t.get(o.source),r=o.target===void 0?void 0:t.get(o.target);if(n===void 0||r===void 0)continue;let i=o.points[0],a=o.points[o.points.length-1],l=(t,n)=>e.vertical?(n.y-t.y)/t.height:(n.x-t.x)/t.width,u=e=>Math.round(e*1e4)/1e4,d=o.entry===void 0?void 0:u(l(r,i)),f=o.exit===void 0?void 0:u(l(n,a)),p=e.vertical?`Y`:`X`;d!==void 0&&d>0&&d<1&&s(o.waypoints,{[`entry${p}`]:d})?c=`put its entry level with its exit: entry${p}=${d}`:f!==void 0&&f>0&&f<1&&s(o.waypoints,{[`exit${p}`]:f})?c=`put its exit level with its entry: exit${p}=${f}`:(o.exit!==void 0||o.entry!==void 0)&&s(o.waypoints,{...o.exit?{exitX:NaN}:{},...o.entry?{entryX:NaN}:{}})&&(c=`drop exitX/exitY and entryX/entryY to let draw.io choose where it leaves and enters`)}if(c===void 0){let r=t.get(o.source),i=t.get(o.target),a=Math.round(r.y+r.height/2-(i.y+i.height/2)),s=Math.round(r.x+r.width/2-(i.x+i.width/2)),l=e.vertical?{name:`y`,by:a}:{name:`x`,by:s};if(l.by===0)continue;c=`line up the shapes it joins, whose middles are ${Math.abs(l.by)} units apart: move ${n(o.target)} by ${l.by>0?`+`:``}${l.by} on ${l.name}`}a.push({rule:`needless-bend`,wires:[o.id],shapes:[],message:`connector ${n(o.id)} has a needless bend near ${$d(e.where)}: ${e.why}. Fix it: ${c}`})}return a}var nf=class extends Error{constructor(e){super(e),this.name=`XmlError`}},rf=new Map([[`amp`,`&`],[`lt`,`<`],[`gt`,`>`],[`quot`,`"`],[`apos`,`'`]]);function af(e){return e.includes(`&`)?e.replace(/&(#x[0-9a-fA-F]+|#[0-9]+|[a-zA-Z]+);/g,(e,t)=>{if(t.startsWith(`#x`)||t.startsWith(`#X`)){let n=Number.parseInt(t.slice(2),16);return Number.isFinite(n)&&n>0?of(n,e):e}if(t.startsWith(`#`)){let n=Number.parseInt(t.slice(1),10);return Number.isFinite(n)&&n>0?of(n,e):e}return rf.get(t)??e}):e}function of(e,t){try{return String.fromCodePoint(e)}catch{return t}}function sf(e){let t={},n=/([^\s=/>]+)\s*=\s*("([^"]*)"|'([^']*)')/g,r;for(;(r=n.exec(e))!==null;)t[r[1]]=af(r[3]??r[4]??``);return t}function cf(e,t){let n=0,r=e.length;for(;n<r;){let r=e.indexOf(`<`,n);if(r===-1){i(e.slice(n));return}if(r>n&&i(e.slice(n,r))===!1)return;if(e.startsWith(`<!--`,r)){let t=e.indexOf(`-->`,r+4);if(t===-1)return;n=t+3;continue}if(e.startsWith(`<![CDATA[`,r)){let i=e.indexOf(`]]>`,r+9);if(i===-1)throw new nf(`unterminated CDATA section`);if(t({kind:`text`,text:e.slice(r+9,i)})===!1)return;n=i+3;continue}if(/^<!doctype/i.test(e.slice(r,r+9)))throw new nf(`this document declares a DOCTYPE, which is refused`);if(e.startsWith(`<?`,r)){let t=e.indexOf(`?>`,r+2);if(t===-1)throw new nf(`unterminated processing instruction`);n=t+2;continue}let a=lf(e,r);if(a===-1)throw new nf(`unterminated tag`);let o=e.slice(r+1,a);if(n=a+1,o.startsWith(`/`)){if(t({kind:`close`,name:o.slice(1).trim()})===!1)return;continue}let s=o.endsWith(`/`),c=s?o.slice(0,-1):o,l=c.search(/[\s/]/),u=(l===-1?c:c.slice(0,l)).trim();if(u===``)throw new nf(`a tag has no name`);if(t({kind:`open`,name:u,attributes:l===-1?{}:sf(c.slice(l)),selfClosing:s})===!1)return}function i(e){if(e!==``)return t({kind:`text`,text:af(e)})}}function lf(e,t){let n=null;for(let r=t+1;r<e.length;r++){let t=e[r];if(n!==null)t===n&&(n=null);else if(t===`"`||t===`'`)n=t;else if(t===`>`)return r}return-1}var uf=class extends Error{constructor(e){super(e),this.name=`DrawioReadError`}},df=[`x`,`y`,`width`,`height`];function ff(e){let t=e.replace(/[^\x20-\x7e]/g,`?`);return t.length>40?`${t.slice(0,39)}…`:t}function pf(e){let t=``,n=null;for(let r of e??``)r===`<`?n=``:r===`>`?(n!==null&&/^br\b/i.test(n)&&(t+=` `),n=null):n===null?t+=r:n+=r;return t.replace(/&nbsp;/g,` `).replace(/\s+/g,` `).trim()}function mf(e){let t={x:0,y:0,width:0,height:0,relative:e.relative===`1`,unreadable:[],sourcePoint:!1,targetPoint:!1,points:[]};for(let n of df){let r=e[n];if(r===void 0)continue;let i=Number(r);r.trim()===``||!Number.isFinite(i)?t.unreadable.push(`${n}="${r}"`):t[n]=i}return t}function hf(e,t){let n=[],r=[],i=null,a=null,o=null,s=!1;try{cf(e,e=>{if(e.kind===`text`)return;if(e.kind===`close`){let t=r.pop();if(t!==e.name)throw new uf(`</${ff(e.name)}> closes <${ff(t??`nothing`)}>`);e.name===`mxCell`?a=null:e.name===`mxGeometry`?o=null:(e.name===`object`||e.name===`UserObject`)&&(i=null);return}let{name:t,attributes:c,selfClosing:l}=e;if(r.length===0){if(t!==`mxGraphModel`)throw new uf(`its model is <${ff(t)}>, not <mxGraphModel>`);s=!0}if(t===`object`||t===`UserObject`)i=c;else if(t===`mxCell`){let e={id:(i??c).id??c.id,parent:c.parent,vertex:c.vertex===`1`,edge:c.edge===`1`,source:c.source,target:c.target,label:pf(i?i.label??i.value:c.value),style:c.style??``,geometry:void 0};n.push(e),a=l?null:e}else if(t===`mxGeometry`&&a!==null&&(c.as??`geometry`)===`geometry`){let e=mf(c);a.geometry=e,o=l?null:e}else if(t===`mxPoint`&&o!==null){let e={x:Number(c.x??0)||0,y:Number(c.y??0)||0},t=o;c.as===`sourcePoint`?(t.sourcePoint=!0,t.sourcePointAt=e):c.as===`targetPoint`?(t.targetPoint=!0,t.targetPointAt=e):c.as===`offset`?t.offset=e:r[r.length-1]===`Array`&&r[r.length-2]===`mxGeometry`&&t.points.push(e)}l||r.push(t)})}catch(e){throw e instanceof uf?e:e instanceof nf?new uf(`page "${t}" is not well-formed XML: ${e.message}`):e}if(!s)throw new uf(`page "${t}" holds no <mxGraphModel>`);if(r.length>0)throw new uf(`page "${t}" ends inside <${r[r.length-1]}>`);return n}function gf(e,t){let n=e.replace(/^/,``).trim(),r;try{cf(n,e=>{if(e.kind===`open`)return r=e.name,!1})}catch(e){throw e instanceof nf?new uf(`this is not well-formed XML: ${e.message}`):e}if(r===`mxGraphModel`)return[{name:`Page-1`,cells:hf(n,`Page-1`)}];if(r!==`mxfile`)throw new uf(r===void 0?`the file is empty`:`its root is <${ff(r)}>, not <mxfile> or <mxGraphModel>`);let i=[],a=/<diagram\b([^>]*?)(\/>|>([\s\S]*?)<\/diagram>)/g,o;for(;(o=a.exec(n))!==null;){let e=`Page-${i.length+1}`;cf(`<diagram${o[1]}/>`,t=>(t.kind===`open`&&t.attributes.name&&(e=t.attributes.name),!1));let n=(o[3]??``).trim();if(n===``)throw new uf(`page "${e}" is empty`);let r;try{if(n.startsWith(`<`))r=n;else if(t===void 0)throw new uf(`its compressed data cannot be read here`);else r=t(n)}catch(t){throw t instanceof uf?new uf(`page "${e}" cannot be read: ${t.message}`):t}i.push({name:e,cells:hf(r,e)})}if(i.length===0)throw new uf(`the <mxfile> holds no <diagram> page`);return i}function _f(e){let t=e.label.length>40?`${e.label.slice(0,39)}…`:e.label;return t===``?`"${e.id}"`:`"${e.id}" (${t})`}function vf(e,t){let n=Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x),r=Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y);return n>0&&r>0?n*r:0}function yf(e,t){return t.x>=e.x&&t.y>=e.y&&t.x+t.width<=e.x+e.width&&t.y+t.height<=e.y+e.height}var bf=.1;function xf(e){if(e.label===``)return!1;let t=e.style.split(`;`)[0];return![`line`,`image`,`group`,`text`,`edgeLabel`].includes(t)&&!/(^|;)(shape=(line|image)|image=)/.test(e.style)}var Sf={shapes:0,ends:1,sharedPoints:2,detours:3,crossings:4,labels:5};function Cf(e,t){let n=t.length,r=new Map,i=(n,i,a,o)=>{let s={severity:n,page:e.name,cells:i,message:a};t.push(s),o!==void 0&&r.set(s,o)},a=new Map;for(let t of e.cells)t.id===void 0||t.id===``?i(`error`,[],`a cell${t.label?` labelled "${t.label}"`:``} has no id`):a.has(t.id)?i(`error`,[t.id],`the id "${t.id}" is used by more than one cell`):a.set(t.id,t);let o=e.cells[0];for(let t of e.cells)t.id!==void 0&&(t.parent===void 0?t!==o&&i(`error`,[t.id],`cell ${_f(t)} has no parent; every cell but the root belongs to a layer or a container`):a.has(t.parent)||i(`error`,[t.id],`cell ${_f(t)} belongs to "${t.parent}", which does not exist`));let s=e=>e.geometry?.relative===!0||e.parent!==void 0&&a.get(e.parent)?.edge===!0;for(let t of e.cells)if(t.id!==void 0){if(t.edge){for(let[e,n,r]of[[`start`,t.source,t.geometry?.sourcePoint],[`end`,t.target,t.geometry?.targetPoint]])n!==void 0&&!a.has(n)?i(`error`,[t.id],`connector ${_f(t)} has its ${e} on "${n}", which does not exist`):n===void 0&&r!==!0&&i(`error`,[t.id],`connector ${_f(t)} is attached to nothing at its ${e}: give it a ${e===`start`?`source`:`target`}, or a ${e===`start`?`sourcePoint`:`targetPoint`}`);t.geometry===void 0&&i(`error`,[t.id],`connector ${_f(t)} has no <mxGeometry relative="1" as="geometry">`)}if(t.vertex){let e=t.geometry;e===void 0?i(`error`,[t.id],`shape ${_f(t)} has no <mxGeometry as="geometry">, so it has no size or place`):e.unreadable.length>0?i(`error`,[t.id],`shape ${_f(t)} has geometry that is not numbers: ${e.unreadable.join(`, `)}`):e.width<0||e.height<0?i(`error`,[t.id],`shape ${_f(t)} is ${e.width} × ${e.height}: a negative size cannot be drawn`):!s(t)&&e.width===0&&e.height===0&&i(`warning`,[t.id],`shape ${_f(t)} is 0 × 0, so nothing of it shows`,Sf.shapes)}}let c=e.cells.filter(e=>e.vertex&&e.id!==void 0&&e.geometry!==void 0&&e.geometry.unreadable.length===0&&!s(e)&&e.geometry.width>0&&e.geometry.height>0),l=new Set(c.filter(e=>c.some(t=>t.parent===e.id)).map(e=>e.id)),u=new Map;for(let e of c){let t=e.parent??``;u.set(t,[...u.get(t)??[],e])}for(let e of u.values()){let t=e.filter(xf);for(let e=0;e<t.length;e++)for(let n=e+1;n<t.length;n++){let[r,a]=[t[e],t[n]],o=Math.min(r.geometry.width*r.geometry.height,a.geometry.width*a.geometry.height);vf(r.geometry,a.geometry)>bf*o&&!yf(r.geometry,a.geometry)&&!yf(a.geometry,r.geometry)&&i(`warning`,[r.id,a.id],`shapes ${_f(r)} and ${_f(a)} overlap`,Sf.shapes)}}for(let e of c){let t=e.parent===void 0?void 0:a.get(e.parent);t!==void 0&&t.vertex&&l.has(t.id??``)&&t.geometry!==void 0&&(t.style.split(`;`)[0]===`group`||/(^|;)rotation=(?!0(;|$))/.test(t.style)||yf({...t.geometry,x:0,y:0},e.geometry)||i(`warning`,[e.id,t.id??``],`shape ${_f(e)} lies partly outside its container ${_f(t)}`,Sf.shapes))}Ef(e,a,l,i);let d=t.splice(n),f=e=>e.severity===`error`?-1:r.get(e)??-1;t.push(...d.map((e,t)=>({issue:e,index:t})).sort((e,t)=>f(e.issue)-f(t.issue)||e.index-t.index).map(({issue:e})=>e))}var wf=2,Tf=.3;function Ef(e,t,n,r){let i=Td(e),a=[...i.terminals.entries()].flatMap(([e,r])=>{let i=t.get(e);return i!==void 0&&xf(i)&&!n.has(e)&&r.box.width>0&&r.box.height>0?[{id:e,cell:i,box:r.box,outline:Od(r.style)}]:[]}),o=e=>{let n=new Set;for(let r=e===void 0?void 0:t.get(e);r?.parent!==void 0&&!n.has(r.parent);r=t.get(r.parent))n.add(r.parent);return n},s=(e,t,n)=>e.some((r,i)=>i>0&&kd(e[i-1],r,t,n,wf)>0),c=[],l=[],u=new Map,d=new Map,f=[];for(let n of e.cells){if(!n.edge||n.id===void 0)continue;let p=Ed(n,i);if(p===void 0)continue;c.push(Md({...n,id:n.id},e.cells,p.points,i.origins.get(n.id)??void 0)),u.set(n.id,p);let m=new Set([n.source,n.target].filter(e=>e!==void 0)),h=new Set([...o(n.source),...o(n.target),...o(n.id)]);for(let e of a)m.has(e.id)||h.has(e.id)||s(p.points,e.box,e.outline)&&r(`warning`,[n.id,e.id],`connector ${_f(n)} runs through shape ${_f(e.cell)}: move the shape off its path, give the connector a waypoint that goes around it (<Array as="points"><mxPoint x="…" y="…"/></Array> in its geometry), or fix its exit and entry on other sides (exitX/exitY, entryX/entryY)`,Sf.crossings);let g=n.source===void 0?void 0:i.terminals.get(n.source),_=n.target===void 0?void 0:i.terminals.get(n.target);if(g!==void 0&&_!==void 0&&Ad(g.box,_.box)===0){let e=[[`source`,n.source,g,_,`exit`],[`target`,n.target,_,g,`entry`]].filter(([,e,n])=>t.get(e)!==void 0&&s(p.points,n.box,Od(n.style)));if(e.length>0){let t=(n.geometry?.points.length??0)>0,r=e=>RegExp(`(?:^|;)${e}X=`).test(n.style)&&RegExp(`(?:^|;)${e}Y=`).test(n.style);d.set(n.id,e.map(([,,,,e])=>e).filter(e=>!t||r(e))),f.push({edge:{...n,id:n.id},own:e.map(([e,t,,,n])=>({role:e,id:t,prefix:n})),waypoints:t})}}let v=[];if(n.label!==``&&n.geometry!==void 0){let e=n.geometry.relative?{x:n.geometry.x,y:n.geometry.y}:{x:0,y:0};v.push({text:n.label,centre:Dd(p,e,n.geometry.offset),style:n.style,holder:n.id,along:e,...n.geometry.offset?{offset:n.geometry.offset}:{}})}for(let t of e.cells){if(t.parent!==n.id||t.label===``||t.geometry===void 0||!t.geometry.relative||t.id===void 0)continue;let e={x:t.geometry.x,y:t.geometry.y};v.push({text:t.label,centre:Dd(p,e,t.geometry.offset),style:t.style,holder:t.id,along:e,...t.geometry.offset?{offset:t.geometry.offset}:{}})}for(let e of v){let t=Number(/(?:^|;)fontSize=([\d.]+)/.exec(e.style)?.[1]??11)||11,i=jd(e.centre,e.text,t);l.push({wire:n.id,holder:e.holder,text:e.text,fontSize:t,along:e.along,...e.offset?{offset:e.offset}:{},box:i,around:h});for(let t of a)h.has(t.id)||Ad(i,t.box)>Tf*i.width*i.height&&r(`warning`,[n.id,t.id],`the label "${e.text.length>40?`${e.text.slice(0,39)}…`:e.text}" of connector ${_f(n)} sits on shape ${_f(t.cell)}: move the label along the connector (its mxGeometry x, from -1 at the source to 1 at the target) or beside it (y), or move the shape`,Sf.labels)}}let p=e=>{let n=t.get(e);return n===void 0?`"${e}"`:_f(n)},m=new Map([...i.terminals].map(([e,t])=>[e,t.box])),h=Qd(c,m,d);for(let{edge:e,own:n,waypoints:i}of f){let a=n.map(({role:e,id:n})=>`its ${e} ${_f(t.get(n))}`).join(` and `),o=n.flatMap(({prefix:t})=>h.get(`${e.id}:${t}`)??[]).join(`;`),s=`remove its waypoints (the <Array as="points"> in its geometry) to let draw.io route it, or move the first and last of them off those shapes`,c=i&&o===``?`connector ${_f(e)} runs through ${a}: its waypoints take it back across them. Fix it: ${s}`:i?`connector ${_f(e)} runs through ${a}: its exit or entry is on a side facing away from the other end, and it has waypoints. Put them on the sides facing each other (${o}), and ${s}`:`connector ${_f(e)} runs through ${a}: its exit or entry is on a side facing away from the other end. Put them on the sides facing each other (${o}), or drop exitX/exitY and entryX/entryY to let draw.io choose`;r(`warning`,[e.id,...n.map(({id:e})=>e)],c,Sf.ends)}let g={"shared-point":Sf.sharedPoints,"facing-away":Sf.ends,detour:Sf.detours,"needless-bend":Sf.detours},_=(e,n,r={})=>{let a=t.get(e.id),o=i.origins.get(e.id);if(a?.geometry===void 0||o==null)return;let s=a.style;for(let[e,t]of Object.entries(r)){let n=Number.isNaN(t)?[e,e.replace(/X$/,`Y`)]:[e];for(let e of n)s=s.replace(RegExp(`(^|;)${e}=[^;]*`),`$1`);Number.isNaN(t)||(s=`${s}${s.endsWith(`;`)?``:`;`}${e}=${t};`)}return Ed({...a,style:s,geometry:{...a.geometry,points:n.map(e=>({x:e.x-o.x,y:e.y-o.y}))}},i)?.points},v=new Set(d.keys());for(let e of tf(c,m,p,d,_)){r(`warning`,[...e.wires,...e.shapes],e.message,g[e.rule]);for(let t of e.wires)v.add(t)}jf(l,u,c,a,p,r,_,s,v)}var Df=[0,-.3,.3,-.6,.6,-.8,.8],Of=[-14,14,-28,28],kf=[10,-10,20,-20,30,-30,40,-40],Af=e=>e.length>40?`${e.slice(0,39)}…`:e;function jf(e,t,n,r,i,a,o,s,c){let l=(e,t)=>Ad(e,t)>Tf*Math.min(e.width*e.height,t.width*t.height),u=(e,t)=>t.points.reduce((n,r,i)=>i===0?0:n+kd(t.points[i-1],r,e,`box`,0),0),d=(n,i)=>e.every(e=>e===n||!l(i,e.box))&&r.every(e=>n.around.has(e.id)||Ad(i,e.box)<=Tf*i.width*i.height)&&[...t].every(([e,t])=>e===n.wire||u(i,t)<4),f=e=>{let n=t.get(e.wire);if(n===void 0)return;let r=[e.along.x,...Df.filter(t=>Math.abs(t-e.along.x)>.05).sort((t,n)=>Math.abs(t-e.along.x)-Math.abs(n-e.along.x))];for(let t of[e.along.y,...Of.map(t=>e.along.y+t)])for(let i of r)if((i!==e.along.x||t!==e.along.y)&&d(e,jd(Dd(n,{x:i,y:t},e.offset),e.text,e.fontSize)))return{x:i,y:t}},p=e=>{let t=f(e);if(t===void 0)return`move the shapes so the connectors part, or shorten the label`;let n=t.y===e.along.y?``:` y="${t.y}"`;return`move it ${n===``?`along`:`beside`} its connector: set x="${t.x}"${n} in the mxGeometry of ${i(e.holder)}`},m=new Set;for(let t=0;t<e.length;t++)for(let n=t+1;n<e.length;n++){let r=e[t],o=e[n];r.wire===o.wire||m.has(r)||m.has(o)||c.has(r.wire)||c.has(o.wire)||!l(r.box,o.box)||(m.add(o),a(`warning`,[o.wire,r.wire],`the label "${Af(o.text)}" of connector ${i(o.wire)} lies on the label "${Af(r.text)}" of connector ${i(r.wire)}: ${p(o)}`,Sf.labels))}for(let n of e)if(!(m.has(n)||c.has(n.wire))){for(let[e,r]of t)if(!(e===n.wire||c.has(e)||u(n.box,r)<4)){m.add(n),a(`warning`,[n.wire,e],`the label "${Af(n.text)}" of connector ${i(n.wire)} lies across connector ${i(e)}: ${p(n)}`,Sf.labels);break}}let h=e=>e.replace(/\s+/g,` `).trim().toLowerCase(),g=(e,t)=>{let n=0,r,i;for(let a=1;a<e.length;a++)for(let o=1;o<t.length;o++){let[s,c,l,u]=[e[a-1],e[a],t[o-1],t[o]],d=Math.abs(s.x-c.x)<.5&&Math.abs(l.x-u.x)<.5&&Math.abs(s.x-l.x)<8,f=Math.abs(s.y-c.y)<.5&&Math.abs(l.y-u.y)<.5&&Math.abs(s.y-l.y)<8;if(!d&&!f)continue;let[p,m]=d?[Math.max(Math.min(s.y,c.y),Math.min(l.y,u.y)),Math.min(Math.max(s.y,c.y),Math.max(l.y,u.y))]:[Math.max(Math.min(s.x,c.x),Math.min(l.x,u.x)),Math.min(Math.max(s.x,c.x),Math.max(l.x,u.x))];m-p<=0||(n+=m-p,r===void 0&&(r=d?{x:s.x,y:p}:{x:p,y:s.y},i=d?{x:s.x,y:m}:{x:m,y:s.y}))}return{total:n,from:r,to:i}},_=new Set,v=new Map,y=e=>v.get(e.id)??e.points;for(let e=0;e<n.length;e++)for(let t=e+1;t<n.length;t++){let l=n[e],u=n[t];if(h(l.label)!==``&&h(l.label)===h(u.label)||_.has(u.id)||c.has(l.id)||c.has(u.id))continue;let d=g(l.points,u.points);if(d.total<12||d.from===void 0||d.to===void 0)continue;_.add(u.id);let f=Math.abs(d.from.x-d.to.x)<.5,p={x:(d.from.x+d.to.x)/2,y:(d.from.y+d.to.y)/2},m=(e,t)=>f?{x:e.x+t,y:e.y}:{x:e.x,y:e.y+t},b=e=>`(${Math.round(e.x)}, ${Math.round(e.y)})`,x=e=>{let t,i=S(e,(i,a)=>{let c=o(e,i,a);if(c===void 0||ef(c,i)!==void 0||r.some(e=>s(c,e.box,e.outline)))return!1;let l=t=>h(t.label)!==``&&h(t.label)===h(e.label);return n.every(t=>t===e||l(t)||g(y(t),c).total<12)?(t=c,!0):!1});if(i!==void 0&&t!==void 0)return v.set(e.id,t),{wire:e,fix:i}},S=(e,t)=>{for(let n of kf){for(let r of e.waypoints){let i=m(r,n);if(t(e.waypoints.map(e=>e===r?i:e)))return`move its waypoint at ${b(r)} to ${b(i)}`}if(e.waypoints.length>1){let r=e.waypoints.map(e=>m(e,n));if(t(r))return`move its waypoints to ${r.map(b).join(`, `)}`}if(e.waypoints.length===0){let r=e.points.slice(1,-1).map(e=>m(e,n));if(r.length>0&&t(r))return`add waypoints at ${r.map(b).join(`, `)}: <Array as="points">${r.map(e=>`<mxPoint x="${Math.round(e.x)}" y="${Math.round(e.y)}"/>`).join(``)}</Array> in its geometry`;let i=m(p,n);if(t([i]))return`add a waypoint at ${b(i)}: <Array as="points"><mxPoint x="${Math.round(i.x)}" y="${Math.round(i.y)}"/></Array> in its geometry`}}for(let n of[`exit`,`entry`]){let r=n===`exit`?e.exit:e.entry;if(r===void 0)continue;let i=r.x===0||r.x===1?{axis:`Y`,along:r.y,keep:`${n}X=${r.x}`}:{axis:`X`,along:r.x,keep:`${n}Y=${r.y}`};for(let r of[.25,.75,.125,.375,.625,.875,.5])if(!(Math.abs(r-i.along)<.06)&&t(e.waypoints,{[`${n}${i.axis}`]:r}))return`move its ${n} to ${n}${i.axis}=${r} (keeping ${i.keep})`}},C=x(u)??x(l),w=C?.fix,T=C?.wire??u,E=h(l.label)===``||h(u.label)===``?`they are not labelled as the same data`:`they carry different data`;a(`warning`,[u.id,l.id],`connectors ${i(l.id)} and ${i(u.id)} run along the same line for ${Math.round(d.total)} units from (${Math.round(d.from.x)}, ${Math.round(d.from.y)}), and ${E}: a reader cannot tell them apart. Fix ${i(T.id)}: ${w??`give it another exit or entry point (exitX/exitY, entryX/entryY), or move a shape so their routes part`}`,Sf.crossings)}}function Mf(e,t){return Nf(gf(e,t))}function Nf(e){let t=[];for(let n of e)Cf(n,t);return{pages:e.map(e=>({name:e.name,shapes:e.cells.filter(e=>e.vertex).length,connectors:e.cells.filter(e=>e.edge).length})),issues:t}}var Pf=`(?:(?!</mxCell>)[\\s\\S])*?`;function Ff(e,t,n){let r=RegExp(`(^|;)${t}=[^;]*`);return r.test(e)?e.replace(r,`$1${t}=${n}`):`${e}${e.endsWith(`;`)||e===``?``:`;`}${t}=${n};`}function If(e){let t=new Map,n=(e,n)=>{let r=t.get(e)??{},i=new Set(Object.keys(r));for(let e of n.split(`;`)){let[t,n]=e.split(`=`);t&&n&&!i.has(t)&&(r[t]=n)}t.set(e,r)};for(let t of e){for(let e of t.matchAll(/((?:exit|entry)[XY]=[\d.]+;(?:exit|entry)[XY]=[\d.]+) for "([^"]+)"/g))n(e[2],e[1]);let e=/^connector "([^"]+)".*Fix it: put its (?:entry|exit) level with its (?:exit|entry): ((?:exit|entry)[XY]=[\d.]+)/.exec(t);e&&n(e[1],e[2]);let r=/^connector "([^"]+)".*fix its exit and entry on those sides \(((?:(?:exit|entry)[XY]=[\d.]+;?)+)\)/.exec(t);r&&n(r[1],r[2]);let i=/Fix "([^"]{1,200})"(?: \([^)]{0,80}\))?: move its (?:exit|entry) to ((?:exit|entry)[XY]=[\d.]+) \(keeping ((?:exit|entry)[XY]=[\d.]+)\)/.exec(t);i&&n(i[1],`${i[2]};${i[3]}`);let a=/^connector "([^"]+)".*Fix it: drop exitX\/exitY and entryX\/entryY to let draw\.io choose where/.exec(t);a&&n(a[1],`exitX=none;exitY=none;entryX=none;entryY=none`);let o=/^connector "([^"]+)".*?(?:sides facing each other|side facing it) \(((?:(?:exit|entry)[XY]=[\d.]+;?)+)\)/.exec(t);o&&n(o[1],o[2])}return t}function Lf(e){return e.flatMap(e=>{let t=/Fix "([^"]{1,200})"(?: \([^)]{0,80}\))?: (?:move its waypoints to|add waypoints at) ((?:\(-?\d+, -?\d+\)(?:, )?)+)/.exec(e);return t?[{wire:t[1],points:[...t[2].matchAll(/\((-?\d+), (-?\d+)\)/g)].map(e=>({x:Number(e[1]),y:Number(e[2])}))}]:[]})}function Rf(e,t){let n=e;for(let e of t){let t=e.wire.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),r=e.points.map(e=>`<mxPoint x="${e.x}" y="${e.y}"/>`).join(``),i=RegExp(`(<mxCell\\b[^>]*\\bid="${t}"[^>]*>\\s*<mxGeometry\\b[^>]*[^/]>${Pf}<Array as="points">)[\\s\\S]*?(</Array>)`);n=i.test(n)?n.replace(i,(e,t,n)=>`${t}${r}${n}`):Uf(n,e.wire,r)}return n}function zf(e){return e.flatMap(e=>{let t=/Fix "([^"]{1,200})"(?: \([^)]{0,80}\))?: move its waypoint at/.exec(e)?.[1]??/^connector "([^"]+)"/.exec(e)?.[1];if(t===void 0)return[];let n=/(?:Fix it|Fix "[^"]{1,200}"(?: \([^)]{0,80}\))?): move its waypoint at \((-?\d+), (-?\d+)\) to \((-?\d+), (-?\d+)\)/.exec(e);if(n)return[{wire:t,from:{x:Number(n[1]),y:Number(n[2])},to:{x:Number(n[3]),y:Number(n[4])}}];let r=/Fix it: remove its waypoint at \((-?\d+), (-?\d+)\)/.exec(e);return r?[{wire:t,from:{x:Number(r[1]),y:Number(r[2])},to:null}]:[]})}function Bf(e,t){let n=e;for(let e of t){let t=e.wire.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);n=n.replace(RegExp(`(<mxCell\\b[^>]*\\bid="${t}"${Pf}<Array as="points">)([\\s\\S]*?)(</Array>)`),(t,n,r,i)=>{let a=r.match(/<mxPoint\b[^>]*\/>/g)?.find(t=>{let n=Number(/\bx="([^"]*)"/.exec(t)?.[1]??0),r=Number(/\by="([^"]*)"/.exec(t)?.[1]??0);return Math.abs(n-e.from.x)<=1&&Math.abs(r-e.from.y)<=1});if(a===void 0)return`${n}${r}${i}`;let o=e.to===null?``:`<mxPoint x="${e.to.x}" y="${e.to.y}"/>`;return`${n}${r.replace(a,o)}${i}`})}return n}function Vf(e){return e.flatMap(e=>{let t=/set x="(-?[\d.]+)"(?: y="(-?[\d.]+)")? in the mxGeometry of "([^"]+)"/.exec(e);return t?[{cell:t[3],x:t[1],...t[2]===void 0?{}:{y:t[2]}}]:[]})}function Hf(e,t){let n=e;for(let e of t){let t=e.cell.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);n=n.replace(RegExp(`(<mxCell\\b[^>]*\\bid="${t}"[^>]*>\\s*<mxGeometry\\b)([^>]*?)(/?>)`),(t,n,r,i)=>{let a=(e,t,n)=>RegExp(`\\b${t}="[^"]*"`).test(e)?e.replace(RegExp(`\\b${t}="[^"]*"`),`${t}="${n}"`):`${e} ${t}="${n}"`,o=a(r,`x`,e.x);return e.y!==void 0&&(o=a(o,`y`,e.y)),`${n}${o}${i}`})}return n}function Uf(e,t,n){let r=t.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);return e.replace(RegExp(`(<mxCell\\b[^>]*\\bid="${r}"[^>]*>\\s*<mxGeometry\\b[^>]*?)(/>|>)`),(e,t,r)=>r===`/>`?`${t}><Array as="points">${n}</Array></mxGeometry>`:`${t}><Array as="points">${n}</Array>`)}function Wf(e){return e.flatMap(e=>{let t=/Fix "([^"]{1,200})"(?: \([^)]{0,80}\))?: add a waypoint at \((-?\d+), (-?\d+)\)/.exec(e);return t?[{wire:t[1],at:{x:Number(t[2]),y:Number(t[3])}}]:[]})}function Gf(e,t){let n=e;for(let e of t){let t=e.wire.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),r=`<Array as="points"><mxPoint x="${e.at.x}" y="${e.at.y}"/></Array>`;n=n.replace(RegExp(`(<mxCell\\b[^>]*\\bid="${t}"[^>]*>\\s*<mxGeometry\\b[^>]*?)(/>|>)`),(e,t,n)=>n===`/>`?`${t}>${r}</mxGeometry>`:`${t}>${r}`)}return n}function Kf(e){return e.flatMap(e=>{let t=/Fix it: line up the shapes it joins, whose middles are \d+ units apart: move "([^"]{1,200})"(?: \([^)]{0,80}\))? by ([+-]?\d+) on (x|y)/.exec(e);return t?[{shape:t[1],by:Number(t[2]),axis:t[3]}]:[]})}function qf(e,t){let n=e;for(let e of t){let t=e.shape.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);n=n.replace(RegExp(`(<mxCell\\b[^>]*\\bid="${t}"[^>]*>\\s*<mxGeometry\\b[^>]*?\\b${e.axis}=")(-?[\\d.]+)`),(t,n,r)=>`${n}${Number(r)+e.by}`)}return n}function Jf(e){return new Set(e.flatMap(e=>{let t=/^connector "([^"]+)".*(?:Fix it: remove its waypoints|and remove its waypoints)/.exec(e);return t?[t[1]]:[]}))}function Yf(e,t){let n=e;for(let e of t){let t=e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);n=n.replace(RegExp(`(<mxCell\\b[^>]*\\bid="${t}"${Pf})<Array as="points">[\\s\\S]*?</Array>`),`$1`)}return n}function Xf(e,t){return e.replace(/<mxCell\b[^>]*>/g,e=>{let n=/\bid="([^"]*)"/.exec(e)?.[1],r=n===void 0?void 0:t.get(n);return r?e.replace(/\bstyle="([^"]*)"/,(e,t)=>{let n=t;for(let[e,t]of Object.entries(r))n=Ff(n,e,t);return`style="${n}"`}):e})}var Zf=/at the same point|facing away|runs .* units to join|runs through its (source|target)|needless bend|lies on the label|lies across connector|run along the same line/;function Qf(e,t=12,n,r={}){let i=e,a=new Set,o=r.only??(()=>!0);for(let e=0;;e++){let s=Mf(i).issues.map(e=>e.message),c=s.filter(e=>Zf.test(e));n?.(e,c);let l=new Map([...If(s)].filter(([e])=>o(e))),u=zf(s).filter(e=>o(e.wire)),d=new Set([...Jf(s)].filter(o)),f=r.moveShapes===!1?[]:Kf(s).filter(e=>o(e.shape)),p=Vf(s).filter(e=>o(e.cell)),m=Wf(s).filter(e=>o(e.wire)),h=Lf(s).filter(e=>o(e.wire));if(l.size===0&&d.size===0&&u.length===0&&f.length===0&&p.length===0&&m.length===0&&h.length===0)return{rounds:e,converged:c.length===0,looped:!1,left:c,xml:i};let g=Rf(Gf(Hf(qf(Bf(Yf(Xf(i,l),d),u),f),p),m),h);if(g===i||a.has(g)||e>=t)return{rounds:e,converged:!1,looped:!0,left:c,xml:i};a.add(i),i=g}}var $f=e=>e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`).replace(/\n/g,`&#10;`),ep=(e,t)=>t===void 0?``:` ${e}="${$f(t)}"`;function tp(e){let t=[`x`,`y`,`width`,`height`].map(t=>e[t]===0?``:` ${t}="${e[t]}"`).join(``),n=[e.points.length===0?``:`<Array as="points">${e.points.map(e=>`<mxPoint x="${e.x}" y="${e.y}"/>`).join(``)}</Array>`,e.offset===void 0?``:`<mxPoint x="${e.offset.x}" y="${e.offset.y}" as="offset"/>`].join(``),r=`<mxGeometry${t}${e.relative?` relative="1"`:``} as="geometry"`;return n===``?`${r}/>`:`${r}>${n}</mxGeometry>`}function np(e){let t=`${e.vertex?` vertex="1"`:``}${e.edge?` edge="1"`:``}`,n=`<mxCell${ep(`id`,e.id)}${ep(`value`,e.label===``?void 0:e.label)}${ep(`style`,e.style===``?void 0:e.style)}${t}${ep(`parent`,e.parent)}${ep(`source`,e.source)}${ep(`target`,e.target)}`;return e.geometry===void 0?`${n}/>`:`${n}>${tp(e.geometry)}</mxCell>`}function rp(e){return[`<mxfile host="pi-outpost">`,`<diagram${ep(`name`,e.name)}>`,`<mxGraphModel><root>`,...e.cells.map(np),`</root></mxGraphModel>`,`</diagram>`,`</mxfile>`,``].join(`
@@ -831,12 +831,12 @@ l0,-`+(t+144)+`c-2,-159.3,-10,-310.7,-24,-454c-53.3,-528,-210,-949.7,
831
831
  `).trim();return r===``?void 0:r}function sB({text:e}){let t=(0,v.useMemo)(()=>[dz,Cz],[]),n=(0,v.useMemo)(()=>[WA],[]);return(0,N.jsx)(`div`,{className:`prose-chat max-h-96 overflow-auto text-zinc-700 dark:text-zinc-300`,children:(0,N.jsx)(SC,{remarkPlugins:t,rehypePlugins:n,children:re(e)})})}function cB({item:e}){return(0,N.jsx)(`pre`,{className:`max-h-96 overflow-auto whitespace-pre-wrap font-mono text-xs text-zinc-700 dark:text-zinc-300`,children:e.output?e.output:e.running?`running…`:`(no output)`})}var lB={id:`raw`,match:()=>!0,stable:!1,Expanded:cB},uB={id:`codemode`,match:e=>e.toolName===`codemode`,stable:!0,extensionOwned:!0,compactHeader:!0,showsRawReveal:!0,Expanded:({item:e})=>(0,N.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,N.jsxs)(`section`,{"aria-label":`Script`,children:[(0,N.jsx)(`h4`,{className:`mb-1 text-xs font-medium text-zinc-500`,children:`Script`}),e.callHtml?(0,N.jsx)(Xe,{html:e.callHtml,className:`max-h-64 text-zinc-700 dark:text-zinc-300`}):(0,N.jsx)(`pre`,{className:`max-h-64 overflow-auto whitespace-pre-wrap font-mono text-xs`,children:typeof e.args?.code==`string`?e.args.code:JSON.stringify(e.args)})]}),(0,N.jsxs)(`section`,{"aria-label":`Calls and result`,children:[(0,N.jsx)(`h4`,{className:`mb-1 text-xs font-medium text-zinc-500`,children:`Calls and result`}),e.outputHtml?(0,N.jsx)(Xe,{html:e.outputHtml,className:`max-h-96 text-zinc-700 dark:text-zinc-300`}):(0,N.jsx)(cB,{item:e})]})]})},dB={id:`extension-html`,match:e=>!!e.outputHtml,stable:!1,extensionOwned:!0,showsRawReveal:!0,hasCollapsed:e=>!!e.outputHtmlCollapsed,Collapsed:({item:e})=>(0,N.jsx)(Xe,{html:e.outputHtmlCollapsed??``,className:`max-h-96 text-zinc-700 dark:text-zinc-300`}),Expanded:({item:e})=>(0,N.jsx)(Xe,{html:e.outputHtml??``,className:`max-h-96 text-zinc-700 dark:text-zinc-300`})};function fB(e){if(e.toolName!==`edit`||e.args===null||typeof e.args!=`object`)return null;let t=e.args.edits;if(!Array.isArray(t))return null;let n=t.filter(e=>typeof e==`object`&&!!e&&typeof e.oldText==`string`&&typeof e.newText==`string`);return n.length>0?n:null}var pB={id:`file-edit`,match:e=>fB(e)!==null,stable:!0,startsExpanded:!0,showsRawReveal:!0,Expanded:({item:e})=>(0,N.jsx)(`div`,{className:`flex flex-col gap-2`,children:(fB(e)??[]).map((e,t)=>(0,N.jsx)(Ze,{lines:ee(e.oldText,e.newText)},t))})};function mB(e){if(e.toolName!==`write`||e.args===null||typeof e.args!=`object`)return null;let t=e.args.content;return typeof t==`string`?t:null}var hB={id:`file-write`,match:e=>mB(e)!==null,stable:!0,startsExpanded:!0,showsRawReveal:!0,Expanded:({item:e})=>(0,N.jsx)(Qe,{lines:(mB(e)??``).split(`
832
832
  `).map(e=>({type:`add`,text:e}))})},gB={id:`pi-render`,match:e=>e.output?ie(e.output)!==void 0:!1,stable:!1,Collapsed:({item:e})=>(0,N.jsx)(sB,{text:ie(e.output??``)??``}),Expanded:cB},_B={id:`orient-summary`,match:e=>e.output?oB(j(e.output))!==void 0:!1,stable:!1,Collapsed:({item:e})=>(0,N.jsx)(sB,{text:oB(j(e.output??``))??``}),Expanded:cB};function vB(e){let t=e.trim();return t===`/dev/null`||t===``?null:t.replace(/^[ab]\//,``)}function yB(e){let t=[],n=null,r=null,i=!1,a=()=>{n&&n.lines.length>0&&t.push(n),n=null};for(let t of e.split(`
833
833
  `))if(t.startsWith(`diff --git `)){a(),i=!1,r=null;let e=/^diff --git (.+?) (.+)$/.exec(t),o=e?vB(e[2])??vB(e[1]):null;n=o===null?null:{path:o,lines:[],added:0,removed:0}}else if(t.startsWith(`--- `))i=!1,r=vB(t.slice(4));else if(t.startsWith(`+++ `)){i=!1;let e=vB(t.slice(4))??r;e!==null&&(n===null||n.lines.length>0)?(a(),n={path:e,lines:[],added:0,removed:0}):e!==null&&n!==null&&(n.path=e)}else if(t.startsWith(`@@`))i=n!==null;else if(i&&n!==null){if(t.startsWith(`+`))n.lines.push({type:`add`,text:t.slice(1)}),n.added++;else if(t.startsWith(`-`))n.lines.push({type:`del`,text:t.slice(1)}),n.removed++;else if(t.startsWith(` `))n.lines.push({type:`same`,text:t.slice(1)});else if(t.startsWith(`\\`))continue;else i=!1}return a(),t}var bB=/^\s*git\s+(diff|show)\b/;function xB(e){if(e.toolName!==`bash`||e.args===null||typeof e.args!=`object`)return null;let t=e.args.command;return typeof t!=`string`||!bB.test(t)?null:t}var SB=6;function CB({onClick:e,children:t}){return(0,N.jsx)(`button`,{type:`button`,onClick:e,className:`rounded px-1.5 py-0.5 text-xs text-zinc-400 hover:bg-zinc-100 hover:text-zinc-700 dark:text-zinc-600 dark:hover:bg-zinc-800 dark:hover:text-zinc-300`,children:t})}function wB({item:e,dispatch:t}){let n=yB(e.output??``),[r,i]=(0,v.useState)(!1);if(n.length===0)return(0,N.jsx)(cB,{item:e});let a=r?n:n.slice(0,SB);return(0,N.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[a.map(e=>(0,N.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,N.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,N.jsx)(`span`,{className:`truncate font-mono text-xs text-zinc-600 dark:text-zinc-400`,children:e.path}),(0,N.jsxs)(`span`,{className:`shrink-0 font-mono text-xs`,children:[(0,N.jsxs)(`span`,{className:`text-emerald-600 dark:text-emerald-400`,children:[`+`,e.added]}),` `,(0,N.jsxs)(`span`,{className:`text-red-600 dark:text-red-400`,children:[`−`,e.removed]})]}),(0,N.jsxs)(`span`,{className:`ml-auto flex shrink-0 items-center`,children:[(0,N.jsx)(CB,{onClick:()=>t({kind:`openFile`,path:e.path}),children:`open`}),(0,N.jsx)(CB,{onClick:()=>t({kind:`openFileHistory`,path:e.path}),children:`history`})]})]}),(0,N.jsx)(Qe,{lines:e.lines})]},e.path)),!r&&n.length>SB&&(0,N.jsxs)(`button`,{type:`button`,onClick:()=>i(!0),className:`self-start text-xs text-zinc-500 hover:text-zinc-700 dark:hover:text-zinc-300`,children:[`show `,n.length-SB,` more file`,n.length-SB===1?``:`s`]})]})}var TB={id:`git-diff`,match:e=>xB(e)!==null,stable:!0,showsRawReveal:!0,Expanded:wB},EB=/^(.*?):(\d+):(.*)$/;function DB(e){let t=[],n=new Map;for(let r of e.split(`
834
- `)){let e=EB.exec(r);if(e===null)continue;let[,i,a,o]=e;if(i===``)continue;let s=n.get(i);s===void 0&&(s={path:i,hits:[]},n.set(i,s),t.push(s)),s.hits.push({line:Number(a),text:o})}return t}function OB(e){return e.reduce((e,t)=>e+t.hits.length,0)}var kB=8,AB=5;function jB({item:e,dispatch:t}){let n=DB(e.output??``),[r,i]=(0,v.useState)(!1);if(n.length===0)return(0,N.jsx)(cB,{item:e});let a=r?n:n.slice(0,kB);return(0,N.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,N.jsxs)(`div`,{className:`text-xs text-zinc-500`,children:[OB(n),` match`,OB(n)===1?``:`es`,` in `,n.length,` file`,n.length===1?``:`s`]}),a.map(e=>(0,N.jsxs)(`div`,{className:`flex flex-col`,children:[(0,N.jsxs)(`button`,{type:`button`,onClick:()=>t({kind:`openFile`,path:e.path}),className:`flex items-center gap-2 truncate text-left font-mono text-xs text-zinc-600 hover:text-zinc-900 dark:text-zinc-400 dark:hover:text-zinc-100`,children:[(0,N.jsx)(`span`,{className:`truncate`,children:e.path}),(0,N.jsx)(`span`,{className:`shrink-0 text-zinc-400 dark:text-zinc-600`,children:e.hits.length})]}),(0,N.jsxs)(`div`,{className:`overflow-x-auto rounded border border-zinc-200 font-mono text-xs dark:border-zinc-800`,children:[e.hits.slice(0,AB).map((e,t)=>(0,N.jsxs)(`div`,{className:`flex gap-2 px-2`,children:[(0,N.jsx)(`span`,{className:`shrink-0 select-none text-zinc-400 dark:text-zinc-600`,children:e.line}),(0,N.jsx)(`span`,{className:`whitespace-pre text-zinc-700 dark:text-zinc-300`,children:e.text})]},t)),e.hits.length>AB&&(0,N.jsxs)(`div`,{className:`px-2 text-zinc-400 dark:text-zinc-600`,children:[`+`,e.hits.length-AB,` more in this file`]})]})]},e.path)),!r&&n.length>kB&&(0,N.jsxs)(`button`,{type:`button`,onClick:()=>i(!0),className:`self-start text-xs text-zinc-500 hover:text-zinc-700 dark:hover:text-zinc-300`,children:[`show `,n.length-kB,` more file`,n.length-kB===1?``:`s`]})]})}var MB=[uB,dB,Dg,pB,hB,TB,{id:`code-search`,match:e=>e.toolName===`grep`,stable:!0,showsRawReveal:!0,Expanded:jB},gB,_B,lB];function NB(e){for(let t of MB){let n=!1;try{n=t.match(e)}catch{n=!1}if(n)return t}return lB}function PB(e,t){let n=NB(e);if(t===void 0||t===n.id)return n;let r=MB.find(e=>e.id===t);if(r===void 0||r.id===lB.id||n.extensionOwned===!0)return n;let i=!1;try{i=r.match(e)}catch{i=!1}return i?r:n}function FB(e){if(typeof e!=`object`||!e)return``;let t=e,n=[`command`,`path`,`file_path`,`pattern`,`query`].find(e=>typeof t[e]==`string`);if(n)return t[n];let r=JSON.stringify(t);return r===`{}`?``:r}function IB({item:e,dispatch:t=nB}){let n=(0,v.useRef)(void 0),r=PB(e,n.current);n.current=r.id;let i=r.startsExpanded===!0,[a,o]=(0,v.useState)(i);(0,v.useEffect)(()=>{o(i)},[i]);let[s,c]=(0,v.useState)(!1),l=(0,v.useRef)(null),u=r.compactHeader?void 0:e.callHtml,d=r.compactHeader?``:FB(e.args),f=r.Collapsed,p=!a&&f!==void 0&&(r.hasCollapsed?.(e)??!0);return(0,N.jsxs)(`div`,{className:`rounded-lg border text-sm ${e.isError?`border-red-300 bg-red-50 dark:border-red-900/60 dark:bg-red-950/20`:`border-zinc-200 bg-zinc-50 dark:border-zinc-800 dark:bg-zinc-900/60`}`,children:[(0,N.jsxs)(`div`,{onMouseDown:e=>{l.current={x:e.clientX,y:e.clientY}},onClick:e=>{let t=l.current;l.current=null,!(e.detail>0&&t&&Math.hypot(e.clientX-t.x,e.clientY-t.y)>4)&&o(!a)},className:`flex w-full cursor-pointer items-center gap-2 px-3 py-2 text-left`,children:[(0,N.jsxs)(`button`,{type:`button`,"aria-expanded":a,"aria-label":u?e.toolName:void 0,className:`flex shrink-0 items-center gap-2`,children:[(0,N.jsx)(`span`,{className:`h-2 w-2 shrink-0 rounded-full ${e.running?`animate-pulse motion-reduce:animate-none bg-amber-400`:e.isError?`bg-red-500`:`bg-emerald-500`}`}),!u&&(0,N.jsx)(`span`,{className:`font-mono font-medium text-zinc-700 dark:text-zinc-300`,children:e.toolName})]}),u?(0,N.jsx)(Xe,{as:`span`,html:u,className:`min-w-0 flex-1 text-zinc-700 dark:text-zinc-300`}):d&&(0,N.jsx)(`span`,{className:`min-w-0 overflow-x-auto whitespace-nowrap font-mono text-xs text-zinc-500 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden`,children:d}),(0,N.jsx)(`span`,{className:`ml-auto text-xs text-zinc-400 dark:text-zinc-600`,children:a?`▾`:`▸`})]}),e.running&&e.progress!=null&&(0,N.jsx)(`div`,{className:`border-t border-zinc-200 px-3 py-1.5 dark:border-zinc-800`,children:(0,N.jsx)(`progress`,{value:e.progress,max:1,"aria-label":`${e.toolName} progress`,className:`h-1.5 w-full appearance-none overflow-hidden rounded-full bg-zinc-200 dark:bg-zinc-800 [&::-moz-progress-bar]:bg-emerald-500 [&::-webkit-progress-bar]:bg-transparent [&::-webkit-progress-value]:rounded-full [&::-webkit-progress-value]:bg-emerald-500`})}),p&&f!==void 0&&(0,N.jsx)(`div`,{className:`border-t border-zinc-200 px-3 py-2 dark:border-zinc-800`,children:(0,N.jsx)(f,{item:e,dispatch:t})}),a&&(0,N.jsxs)(`div`,{className:`border-t border-zinc-200 px-3 py-2 dark:border-zinc-800`,children:[(0,N.jsx)(r.Expanded,{item:e,dispatch:t}),r.showsRawReveal===!0&&(0,N.jsxs)(`div`,{className:`mt-2`,children:[(0,N.jsx)(`button`,{type:`button`,onClick:()=>c(!s),className:`text-xs text-zinc-400 hover:text-zinc-600 dark:text-zinc-600 dark:hover:text-zinc-400`,children:s?`hide raw output`:`raw output`}),s&&(0,N.jsx)(`div`,{className:`mt-1`,children:(0,N.jsx)(cB,{item:e})})]})]})]})}function LB({item:e}){let[t,n]=(0,v.useState)(!1),r=e.details!==void 0,i=!!e.contentHtml,a=e.contentHtmlCollapsed??e.contentHtml,o=r||i&&!!e.contentHtmlCollapsed;return(0,N.jsxs)(`div`,{className:`rounded-lg border border-violet-200 bg-violet-50 px-3 py-2 text-sm dark:border-violet-900/60 dark:bg-violet-950/30`,children:[(0,N.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,N.jsxs)(`span`,{className:`font-mono text-xs font-bold text-violet-700 dark:text-violet-300`,children:[`[`,e.customType,`]`]}),o&&(0,N.jsx)(`button`,{type:`button`,onClick:()=>n(!t),title:`Show details`,className:`ml-auto text-xs text-violet-500 hover:text-violet-700 dark:text-violet-500 dark:hover:text-violet-300`,children:t?`▾`:`▸`})]}),i&&a?(0,N.jsx)(Xe,{html:t||!e.contentHtmlCollapsed?e.contentHtml??a:a,className:`mt-1 text-violet-950 dark:text-violet-100`}):(0,N.jsx)(`div`,{className:`prose-chat mt-1 text-violet-950 dark:text-violet-100`,children:(0,N.jsx)(SC,{remarkPlugins:[dz,Cz],rehypePlugins:[WA],children:re(e.text)})}),t&&r&&(0,N.jsx)(`pre`,{className:`mt-2 max-h-96 overflow-auto border-t border-violet-200 pt-2 font-mono text-xs text-violet-600 dark:border-violet-900/60 dark:text-violet-400`,children:JSON.stringify(e.details,null,2)})]})}var RB=`pi-outpost:update-notice-dismissed`;function zB(){try{return window.localStorage.getItem(RB)}catch{return null}}function BB({notice:e}){let[t,n]=(0,v.useState)(()=>zB());return t===e.latest?null:(0,N.jsxs)(`div`,{role:`status`,"data-testid":`update-notice`,className:`flex items-center gap-2 border-b border-sky-200 bg-sky-50 px-4 py-1.5 text-xs text-sky-900 dark:border-sky-900 dark:bg-sky-950/40 dark:text-sky-200`,children:[(0,N.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[`pi-outpost `,e.latest,` is available (you have `,e.running,`). `,e.instruction,` `,(0,N.jsx)(`a`,{href:e.releaseNotes,target:`_blank`,rel:`noreferrer`,className:`font-medium underline underline-offset-2`,children:`What's new`})]}),(0,N.jsx)(`code`,{className:`shrink-0 rounded bg-white/70 px-1.5 py-0.5 font-mono dark:bg-sky-900/40`,children:e.copy}),(0,N.jsx)(me,{text:e.copy}),(0,N.jsx)(`button`,{type:`button`,"aria-label":`Dismiss the update notice`,onClick:()=>{try{window.localStorage.setItem(RB,e.latest)}catch{}n(e.latest)},className:`shrink-0 rounded px-1.5 text-sky-700 hover:bg-sky-100 dark:text-sky-300 dark:hover:bg-sky-900/50`,children:`×`})]})}var VB=`pi-outpost:changes-notice-dismissed`;function HB(){try{return window.localStorage.getItem(VB)}catch{return null}}function UB(e){return(0,N.jsx)(`a`,{...e,target:`_blank`,rel:`noreferrer`})}function WB({changes:e}){let[t,n]=(0,v.useState)(()=>HB()),[r,i]=(0,v.useState)(!1);if(t===e.to)return null;let a=e.entries.length>0;return(0,N.jsxs)(`div`,{role:`status`,"data-testid":`changes-notice`,className:`border-b border-zinc-200 bg-zinc-50 text-xs text-zinc-700 dark:border-zinc-800 dark:bg-zinc-900/60 dark:text-zinc-300`,children:[(0,N.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-1.5`,children:[(0,N.jsx)(`span`,{className:`shrink-0 rounded-full bg-sky-100 px-1.5 font-medium leading-4 text-sky-800 dark:bg-sky-900/50 dark:text-sky-200`,children:`New`}),(0,N.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[`pi-outpost was updated to `,e.to,` (from `,e.from,`).`]}),a?(0,N.jsx)(`button`,{type:`button`,"aria-expanded":r,onClick:()=>i(!r),className:`shrink-0 rounded px-1.5 font-medium text-zinc-900 underline-offset-2 hover:underline dark:text-zinc-100`,children:r?`Hide what changed`:`What's changed`}):(0,N.jsx)(UB,{href:e.releaseNotes,className:`shrink-0 font-medium text-zinc-900 underline-offset-2 hover:underline dark:text-zinc-100`,children:`Release notes`}),(0,N.jsx)(`button`,{type:`button`,"aria-label":`Dismiss the update news`,onClick:()=>{try{window.localStorage.setItem(VB,e.to)}catch{}n(e.to)},className:`shrink-0 rounded px-1.5 text-zinc-500 hover:bg-zinc-200 hover:text-zinc-800 dark:text-zinc-400 dark:hover:bg-zinc-800 dark:hover:text-zinc-100`,children:`×`})]}),r&&a&&(0,N.jsx)(`div`,{"data-testid":`changes-notice-body`,className:`max-h-[50vh] overflow-y-auto border-t border-zinc-200 px-4 py-3 dark:border-zinc-800`,children:(0,N.jsxs)(`div`,{className:`mx-auto max-w-3xl`,children:[e.entries.map(e=>(0,N.jsxs)(`section`,{className:`mb-4`,children:[(0,N.jsxs)(`h2`,{className:`text-sm font-semibold text-zinc-900 dark:text-zinc-100`,children:[e.version,e.date&&(0,N.jsx)(`span`,{className:`ml-2 font-normal text-zinc-500 dark:text-zinc-400`,children:e.date})]}),(0,N.jsx)(`div`,{className:`prose-chat text-zinc-800 dark:text-zinc-200`,children:(0,N.jsx)(SC,{remarkPlugins:[dz],components:{a:UB},children:e.markdown})})]},e.version)),(0,N.jsx)(UB,{href:e.releaseNotes,className:`font-medium text-zinc-900 underline-offset-2 hover:underline dark:text-zinc-100`,children:`Release notes on GitHub`})]})})]})}function GB(e){return e.id??e.root}function KB(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${Math.round(e/1e3)}k`:String(e)}function qB({item:e}){let[t,n]=(0,v.useState)(!1),r=e.tokensBefore?`Conversation compacted here — ${KB(e.tokensBefore)} tokens summarised`:`Conversation compacted here`;return(0,N.jsxs)(`div`,{className:`my-1`,"data-compaction-boundary":!0,children:[(0,N.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,N.jsx)(`span`,{className:`h-px flex-1 bg-amber-300 dark:bg-amber-900`}),(0,N.jsxs)(`button`,{type:`button`,onClick:()=>n(!t),"aria-expanded":t,className:`rounded-full border border-amber-300 bg-amber-50 px-2 py-0.5 text-xs text-amber-800 hover:bg-amber-100 dark:border-amber-900 dark:bg-amber-950/40 dark:text-amber-300 dark:hover:bg-amber-950/70`,children:[r,` `,t?`▾`:`▸`]}),(0,N.jsx)(`span`,{className:`h-px flex-1 bg-amber-300 dark:bg-amber-900`})]}),t&&(0,N.jsxs)(`div`,{className:`mt-2 whitespace-pre-wrap rounded-lg border border-amber-200 bg-amber-50/60 px-3 py-2 text-sm text-zinc-700 dark:border-amber-900/60 dark:bg-amber-950/20 dark:text-zinc-300`,children:[(0,N.jsx)(`p`,{className:`mb-1 text-xs font-medium text-amber-800 dark:text-amber-300`,children:`What the agent kept of everything above:`}),e.summary||`(the runtime recorded no summary)`]})]})}function JB({older:e,onLoad:t}){if(e.remaining<=0&&!e.error)return null;let n=e.remaining,r=e.loading?`Loading earlier messages…`:`Load ${n} earlier message${n===1?``:`s`}`;return(0,N.jsxs)(`div`,{className:`flex flex-col items-center gap-1 pb-2`,"data-older-messages":!0,children:[(0,N.jsx)(`button`,{type:`button`,onClick:t,disabled:e.loading,"aria-busy":e.loading,"aria-label":e.loading?`Loading earlier messages`:`Load ${n} earlier messages`,className:`rounded-full border border-zinc-300 bg-white px-3 py-1 text-xs text-zinc-600 hover:bg-zinc-50 disabled:cursor-progress disabled:opacity-60 dark:border-zinc-700 dark:bg-zinc-900 dark:text-zinc-400 dark:hover:bg-zinc-800`,children:r}),e.error&&(0,N.jsxs)(`p`,{role:`status`,className:`text-xs text-red-600 dark:text-red-400`,children:[e.error,` — try again`]})]})}var YB={cost:0,unpriced:0,turns:0,input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0};function XB(e){let t={...YB};for(let n of e){if(n.kind!==`assistant`||!n.usage)continue;let e=n.usage;t.turns+=1,t.input+=e.input,t.output+=e.output,t.cacheRead+=e.cacheRead,t.cacheWrite+=e.cacheWrite,t.totalTokens+=e.totalTokens,e.cost===void 0?t.unpriced+=1:t.cost+=e.cost}return t}function ZB(e){let t=e>0&&e<.01?4:2;return`$${e.toFixed(t)}`}function QB(e){return e<1e3?String(e):e<1e6?`${Math.round(e/1e3)}k`:`${(e/1e6).toFixed(1)}M`}var $B=80,eV=new WeakMap;function tV(e){let t=typeof e==`object`&&!!e;if(t){let t=eV.get(e);if(t!==void 0)return t}let n=0;try{n=JSON.stringify(e)?.length??0}catch{n=0}return t&&eV.set(e,n),n}function nV(e){let t=e.replace(/\s+/g,` `).trim();return t.length>$B?`${t.slice(0,79)}…`:t}function rV(e,t){return{index:e,title:t,turns:0,toolCalls:0,failedToolCalls:0,input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,unpriced:0}}function iV(e,t){e.turns+=1,e.input+=t.input,e.output+=t.output,e.cacheRead+=t.cacheRead,e.cacheWrite+=t.cacheWrite,e.totalTokens+=t.totalTokens,t.cost===void 0?e.unpriced+=1:e.cost=(e.cost??0)+t.cost}function aV(e){if(e.length===0)return 0;let t=[...e].sort((e,t)=>e-t),n=Math.floor(t.length/2);return t.length%2==1?t[n]:(t[n-1]+t[n])/2}function oV(e){let t=[],n=[],r=[],i=new Map,a=rV(-1,``),o=a;e.forEach((e,a)=>{if(e.kind===`user`){o=rV(a,nV(e.text)),r.push(o);return}if(e.kind===`assistant`){if(!e.usage)return;t.push({index:a,number:t.length+1,requestIndex:o.index,usage:e.usage}),iV(o,e.usage);return}if(e.kind!==`tool`)return;let s={index:a,toolCallId:e.toolCallId,name:e.toolName,inputSize:tV(e.args),outputSize:e.output.length,isError:e.isError===!0,running:e.running===!0,requestIndex:o.index};n.push(s),o.toolCalls+=1,s.isError&&(o.failedToolCalls+=1);let c=i.get(s.name)??{name:s.name,calls:0,failures:0,inputSize:0,outputSize:0};c.calls+=1,s.isError&&(c.failures+=1),c.inputSize+=s.inputSize,c.outputSize+=s.outputSize,i.set(s.name,c)}),(a.turns>0||a.toolCalls>0)&&r.unshift(a);let s=XB(e),c=t.map(e=>e.usage.cost).filter(e=>e!==void 0),l=n.filter(e=>e.isError).length;return{turns:t,requests:r,toolCalls:n,tools:[...i.values()],totals:s,pricedTurns:c.length,averageTurnCost:c.length===0?0:s.cost/c.length,medianTurnCost:aV(c),totalToolCalls:n.length,failedToolCalls:l,toolCallsPerTurn:t.length===0?0:n.length/t.length}}function sV(e,t){let n=[...e];return t===`input`?n.sort((e,t)=>t.inputSize-e.inputSize):t===`failure`?n.sort((e,t)=>Number(t.isError)-Number(e.isError)||t.outputSize-e.outputSize):n.sort((e,t)=>t.outputSize-e.outputSize)}function cV(e){return e.filter(e=>e.index>=0).sort((e,t)=>t.totalTokens-e.totalTokens||(t.cost??0)-(e.cost??0))}function lV(e){return e<1e3?`${e} B`:e<1e6?`${Math.round(e/1e3)} kB`:`${(e/1e6).toFixed(1)} MB`}var uV=768,dV=26,fV=132,pV=12,mV=96,hV=124,gV=[{key:`input`,label:`input`,className:`text-emerald-500`,value:e=>e.usage.input},{key:`output`,label:`output`,className:`text-blue-500`,value:e=>e.usage.output},{key:`cacheRead`,label:`cache read`,className:`text-violet-500`,value:e=>e.usage.cacheRead},{key:`cacheWrite`,label:`cache write`,className:`text-amber-500`,value:e=>e.usage.cacheWrite}],_V=[{key:`cost`,label:`cost`,className:`text-rose-500`,value:e=>e.usage.cost??0}];function vV({title:e,children:t}){return(0,N.jsxs)(`section`,{className:`border-t border-zinc-200 px-4 py-3 dark:border-zinc-800`,children:[(0,N.jsx)(`h3`,{className:`mb-2 font-mono text-[11px] uppercase tracking-wide text-zinc-400 dark:text-zinc-500`,children:e}),t]})}function yV({children:e}){return(0,N.jsx)(`p`,{className:`text-xs text-zinc-400 dark:text-zinc-500`,children:e})}function bV({label:e,value:t,hint:n}){return(0,N.jsxs)(`div`,{className:`rounded-md border border-zinc-200 px-2 py-1.5 dark:border-zinc-800`,children:[(0,N.jsx)(`div`,{"aria-label":`${e}: ${t}`,className:`font-mono text-sm text-zinc-700 dark:text-zinc-200`,children:t}),(0,N.jsx)(`div`,{className:`text-[11px] text-zinc-500 dark:text-zinc-400`,children:e}),n&&(0,N.jsx)(`div`,{className:`text-[10px] text-zinc-400 dark:text-zinc-500`,children:n})]})}function xV({turns:e,series:t,format:n,onJump:r,describe:i}){let a=Math.max(1,...e.flatMap(e=>t.map(t=>t.value(e)))),o=Math.max(e.length*dV,dV),s=e=>dV/2+e*dV,c=e=>pV+mV*(1-e/a);return(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`div`,{className:`mb-1 flex flex-wrap gap-x-3 gap-y-1`,children:t.map(e=>(0,N.jsxs)(`span`,{className:`flex items-center gap-1 text-[10px] text-zinc-500 dark:text-zinc-400`,children:[(0,N.jsx)(`span`,{className:`inline-block h-0.5 w-3 bg-current ${e.className}`}),e.label]},e.key))}),(0,N.jsxs)(`div`,{className:`flex`,children:[(0,N.jsxs)(`div`,{"aria-hidden":!0,className:`flex w-12 shrink-0 flex-col justify-between py-2 pr-1 text-right font-mono text-[9px] text-zinc-400 dark:text-zinc-600`,style:{height:fV},children:[(0,N.jsx)(`span`,{children:n(a)}),(0,N.jsx)(`span`,{children:`0`})]}),(0,N.jsx)(`div`,{className:`min-w-0 flex-1 overflow-x-auto`,children:(0,N.jsxs)(`svg`,{width:o,height:fV,role:`group`,"aria-label":`Per-turn chart`,children:[(0,N.jsx)(`line`,{x1:0,x2:o,y1:108,y2:108,stroke:`currentColor`,className:`text-zinc-200 dark:text-zinc-800`}),t.map(t=>(0,N.jsx)(`polyline`,{fill:`none`,stroke:`currentColor`,strokeWidth:1.5,className:t.className,points:e.map((e,n)=>`${s(n)},${c(t.value(e))}`).join(` `)},t.key)),e.map((n,a)=>(0,N.jsxs)(`g`,{children:[t.map(e=>(0,N.jsx)(`circle`,{cx:s(a),cy:c(e.value(n)),r:2,fill:`currentColor`,className:e.className},e.key)),(0,N.jsx)(`rect`,{x:s(a)-dV/2,y:0,width:dV,height:fV,fill:`transparent`,role:`button`,tabIndex:0,"aria-label":`Turn ${n.number}: ${i(n)} — jump to it`,className:`cursor-pointer outline-none focus-visible:fill-zinc-500/10`,onClick:()=>r(n.index),onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),r(n.index))},children:(0,N.jsx)(`title`,{children:`turn ${n.number} · ${i(n)}`})}),(e.length<=12||n.number%5==0)&&(0,N.jsx)(`text`,{x:s(a),y:hV,textAnchor:`middle`,className:`fill-zinc-400 text-[9px] dark:fill-zinc-600`,children:n.number})]},n.index))]})})]})]})}function SV({onJump:e,label:t,children:n}){return(0,N.jsx)(`button`,{type:`button`,onClick:e,"aria-label":t,className:`flex w-full items-baseline gap-2 rounded-md px-2 py-1 text-left text-xs hover:bg-zinc-100 dark:hover:bg-zinc-900`,children:n})}function CV({analysis:e,onJump:t,onClose:n}){let[r,i]=(0,v.useState)(`output`),{totals:a}=e;function o(e){t(e),window.innerWidth<uV&&n()}let s=e.turns.length===0&&e.toolCalls.length===0,c=sV(e.toolCalls,r),l=cV(e.requests);return(0,N.jsxs)(`aside`,{"aria-label":`Session analysis`,className:`absolute inset-y-0 right-0 z-10 w-full overflow-y-auto border-l border-zinc-200 bg-white shadow-xl md:w-[26rem] dark:border-zinc-800 dark:bg-zinc-950`,children:[(0,N.jsxs)(`header`,{className:`sticky top-0 flex items-center gap-2 border-b border-zinc-200 bg-white px-4 py-2 dark:border-zinc-800 dark:bg-zinc-950`,children:[(0,N.jsx)(`h2`,{className:`font-mono text-xs text-zinc-600 dark:text-zinc-300`,children:`session analysis`}),(0,N.jsx)(`button`,{type:`button`,onClick:n,"aria-label":`Close session analysis`,className:`ml-auto rounded-md px-2 py-1 text-sm text-zinc-500 hover:bg-zinc-100 dark:text-zinc-400 dark:hover:bg-zinc-900`,children:`×`})]}),s?(0,N.jsx)(`div`,{className:`px-4 py-6`,children:(0,N.jsx)(yV,{children:`Nothing to analyse yet — no turn has reported figures and no tool has been called.`})}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(vV,{title:`tokens`,children:(0,N.jsxs)(`div`,{className:`grid grid-cols-3 gap-2`,children:[(0,N.jsx)(bV,{label:`total`,value:QB(a.totalTokens)}),(0,N.jsx)(bV,{label:`fresh input`,value:QB(a.input)}),(0,N.jsx)(bV,{label:`output`,value:QB(a.output)}),(0,N.jsx)(bV,{label:`cache read`,value:QB(a.cacheRead)}),(0,N.jsx)(bV,{label:`cache write`,value:QB(a.cacheWrite)}),(0,N.jsx)(bV,{label:`turns`,value:String(e.turns.length)})]})}),(0,N.jsx)(vV,{title:`cost`,children:e.pricedTurns===0?(0,N.jsx)(yV,{children:`No turn was priced — this provider reports tokens only.`}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`div`,{className:`grid grid-cols-3 gap-2`,children:[(0,N.jsx)(bV,{label:`total`,value:ZB(a.cost)}),(0,N.jsx)(bV,{label:`average turn`,value:ZB(e.averageTurnCost)}),(0,N.jsx)(bV,{label:`median turn`,value:ZB(e.medianTurnCost)})]}),(0,N.jsxs)(`p`,{className:`mt-1 text-[11px] text-zinc-400 dark:text-zinc-500`,children:[`over `,e.pricedTurns,` priced turn`,e.pricedTurns===1?``:`s`,a.unpriced>0&&`, ${a.unpriced} unpriced`]})]})}),(0,N.jsx)(vV,{title:`tool calls`,children:e.totalToolCalls===0?(0,N.jsx)(yV,{children:`No tool call recorded in this session.`}):(0,N.jsxs)(`div`,{className:`grid grid-cols-3 gap-2`,children:[(0,N.jsx)(bV,{label:`calls`,value:String(e.totalToolCalls)}),(0,N.jsx)(bV,{label:`per turn`,value:e.toolCallsPerTurn.toFixed(1)}),(0,N.jsx)(bV,{label:`failed`,value:String(e.failedToolCalls)})]})}),(0,N.jsx)(vV,{title:`tokens per turn`,children:e.turns.length===0?(0,N.jsx)(yV,{children:`No turn has reported figures yet.`}):(0,N.jsx)(xV,{turns:e.turns,series:gV,format:QB,onJump:o,describe:e=>`${QB(e.usage.totalTokens)} tokens (input ${e.usage.input}, output ${e.usage.output}, cache read ${e.usage.cacheRead}, cache write ${e.usage.cacheWrite})`})}),(0,N.jsx)(vV,{title:`cost per turn`,children:e.pricedTurns===0?(0,N.jsx)(yV,{children:`No turn was priced, so there is no cost to plot.`}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(xV,{turns:e.turns.filter(e=>e.usage.cost!==void 0),series:_V,format:ZB,onJump:o,describe:e=>ZB(e.usage.cost??0)}),a.unpriced>0&&(0,N.jsxs)(`p`,{className:`mt-1 text-[10px] text-zinc-400 dark:text-zinc-500`,children:[a.unpriced,` unpriced turn`,a.unpriced===1?``:`s`,` left out — they carry no price to plot`]})]})}),(0,N.jsx)(vV,{title:`costliest tool calls`,children:c.length===0?(0,N.jsx)(yV,{children:`No tool call recorded in this session.`}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`div`,{className:`mb-1 flex items-center gap-2`,children:[(0,N.jsx)(`label`,{htmlFor:`tool-ranking`,className:`text-[11px] text-zinc-500 dark:text-zinc-400`,children:`rank by`}),(0,N.jsxs)(`select`,{id:`tool-ranking`,value:r,onChange:e=>i(e.target.value),className:`rounded-md border border-zinc-300 bg-white px-1.5 py-0.5 font-mono text-[11px] text-zinc-600 dark:border-zinc-800 dark:bg-zinc-900 dark:text-zinc-300`,children:[(0,N.jsx)(`option`,{value:`output`,children:`output size`}),(0,N.jsx)(`option`,{value:`input`,children:`input size`}),(0,N.jsx)(`option`,{value:`failure`,children:`failure`})]})]}),(0,N.jsx)(`p`,{className:`mb-1 text-[10px] text-zinc-400 dark:text-zinc-500`,children:`measured content size, not tokens — a tool call carries no price`}),c.slice(0,10).map(e=>(0,N.jsxs)(SV,{onJump:()=>o(e.index),label:`Jump to the ${e.name} call, output ${lV(e.outputSize)}`,children:[(0,N.jsx)(`span`,{className:`font-mono text-zinc-600 dark:text-zinc-300`,children:e.name}),e.isError&&(0,N.jsx)(`span`,{className:`text-red-500`,children:`failed`}),e.running&&(0,N.jsx)(`span`,{className:`text-zinc-400`,children:`running`}),(0,N.jsxs)(`span`,{className:`ml-auto font-mono text-zinc-500 dark:text-zinc-400`,children:[`in `,lV(e.inputSize),` · out `,lV(e.outputSize)]})]},e.toolCallId||`${e.index}`))]})}),(0,N.jsx)(vV,{title:`tools`,children:e.tools.length===0?(0,N.jsx)(yV,{children:`No tool has been called yet.`}):(0,N.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,N.jsx)(`thead`,{children:(0,N.jsxs)(`tr`,{className:`text-left text-[10px] uppercase text-zinc-400 dark:text-zinc-500`,children:[(0,N.jsx)(`th`,{className:`font-normal`,children:`tool`}),(0,N.jsx)(`th`,{className:`font-normal`,children:`calls`}),(0,N.jsx)(`th`,{className:`font-normal`,children:`failed`}),(0,N.jsx)(`th`,{className:`text-right font-normal`,children:`in / out`})]})}),(0,N.jsx)(`tbody`,{className:`font-mono text-zinc-600 dark:text-zinc-300`,children:[...e.tools].sort((e,t)=>t.outputSize-e.outputSize).map(e=>(0,N.jsxs)(`tr`,{children:[(0,N.jsx)(`td`,{children:e.name}),(0,N.jsx)(`td`,{children:e.calls}),(0,N.jsx)(`td`,{className:e.failures>0?`text-red-500`:``,children:e.failures}),(0,N.jsxs)(`td`,{className:`text-right`,children:[lV(e.inputSize),` / `,lV(e.outputSize)]})]},e.name))})]})}),(0,N.jsx)(vV,{title:`costliest requests`,children:l.length===0?(0,N.jsx)(yV,{children:`No request has consumed anything yet.`}):l.slice(0,10).map(e=>(0,N.jsxs)(SV,{onJump:()=>o(e.index),label:`Jump to the request "${e.title}"`,children:[(0,N.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-zinc-600 dark:text-zinc-300`,children:e.title}),(0,N.jsxs)(`span`,{className:`shrink-0 font-mono text-zinc-500 dark:text-zinc-400`,children:[QB(e.totalTokens),` tok`,e.cost!==void 0&&` · ${ZB(e.cost)}`]}),(0,N.jsxs)(`span`,{className:`shrink-0 text-[10px] text-zinc-400 dark:text-zinc-500`,children:[e.turns,`t / `,e.toolCalls,`c`,e.failedToolCalls>0&&` · ${e.failedToolCalls}✗`]})]},e.index))})]})]})}var wV=2e3;function TV({items:e,scrollerRef:t,hideTools:n,onShowTools:r,onJump:i}){let[a,o]=(0,v.useState)(null),s=(0,v.useRef)(null),[c,l]=(0,v.useState)(0),u=(0,v.useRef)(null);(0,v.useEffect)(()=>()=>{u.current&&clearTimeout(u.current)},[]);let d=(0,v.useCallback)(t=>{let i=e[t];i&&(i.kind===`tool`&&n&&r(),s.current=t,l(e=>e+1))},[e,n,r]);return(0,v.useEffect)(()=>{let e=s.current;if(e===null)return;s.current=null;let n=t.current?.querySelector(`[data-item-index="${e}"]`);n&&(i(n),n.scrollIntoView?.({behavior:`smooth`,block:`center`}),o(e),u.current&&clearTimeout(u.current),u.current=setTimeout(()=>o(null),wV))},[c,n,t,i]),{jumpToItem:d,highlightIndex:a}}var EV={tools:`pi-outpost:hide-tools`,reasoning:`pi-outpost:hide-reasoning`},DV=[`tools`,`reasoning`],OV={tools:`Tool calls`,reasoning:`Reasoning`};function kV(e){try{return localStorage.getItem(EV[e])===`1`}catch{return!1}}function AV(){return{tools:!kV(`tools`),reasoning:!kV(`reasoning`)}}function jV(e,t){try{localStorage.setItem(EV[e],t?`0`:`1`)}catch{}}function MV(e){return DV.filter(t=>!e[t]).length}function NV(e,t){let n=null;for(let r of e)(r.repo===``||t===r.repo||t.startsWith(`${r.repo}/`))&&(n===null||r.repo.length>n.repo.length)&&(n=r);return n}var PV=/(?:^|\s)@([^\s@]+)/g,FV=new Set([`,`,`.`,`;`,`:`,`!`,`?`,`)`,`]`]);function IV(e){let t=e.length;for(;t>0&&FV.has(e[t-1]);)t--;return e.slice(0,t)}function LV(e){return[...e.matchAll(PV)].map(([,e])=>IV(e??``)).filter(e=>e.length>0)}var RV=class extends Error{reason;constructor(e,t){super(e),this.name=`UploadError`,this.reason=t}},zV=class extends RV{constructor(){super(`The workspace changed before the import finished`),this.name=`UploadContextChangedError`}};function BV(e){return e.size>26214400?Promise.reject(new RV(`Files are limited to 25 MB`,`too-large`)):new Promise((t,n)=>{let r=new FileReader;r.onload=()=>t(String(r.result).split(`,`,2)[1]??``),r.onerror=()=>n(new RV(`The file could not be read`)),r.onabort=()=>n(new RV(`Reading the file was cancelled`)),r.readAsDataURL(e)})}function VV(e){return new Promise((t,n)=>{let r=new FileReader;r.onload=()=>t(r.result.split(`,`,2)[1]??``),r.onerror=()=>n(r.error),r.readAsDataURL(e)})}function HV(e){return e.type.startsWith(`image/`)?`image`:e.type===`application/pdf`||le(e.name)||ue(e.name)?`extraction-tool`:e.size<=524288?`inline-text`:GV(e)&&e.size<=26214400?`extraction-tool`:`unsupported`}function UV(e){let t=HV(e);return t===`extraction-tool`||t===`image`&&e.size>7340032}var WV=new Set([`application/json`,`application/xml`,`application/javascript`,`application/x-yaml`,`application/yaml`,`application/sql`]);function GV(e){return e.type.startsWith(`text/`)||WV.has(e.type)}function KV(e){return GV(e)?`${e.name}: file too large to upload (max 25 MB)`:`${e.name}: unsupported file type${e.type?` (${e.type})`:``}`}function qV(e,t){return t instanceof RV?t.reason===`denied`?`${e.name}: cannot upload — the workspace is read-only`:t.reason===`too-large`?`${e.name}: file too large to upload (max 25 MB)`:t.reason===`invalid`?`${e.name}: ${t.message}`:`${e.name}: upload failed — ${t.message}`:`${e.name}: upload failed`}async function JV(e){let t;try{t=await e.text()}catch{return{attachments:[],errors:[`${e.name}: could not be read`]}}return t.includes(`\0`)?{attachments:[],errors:[`${e.name}: unsupported binary file`]}:{attachments:[{name:e.name,kind:`text`,data:t,mimeType:e.type||`text/plain`,source:`manual`}],errors:[]}}async function YV(e){try{let t=await VV(e);return{attachments:[{name:e.name,kind:`image`,data:t,mimeType:e.type,source:`manual`}],errors:[]}}catch{return{attachments:[],errors:[`${e.name}: could not be read`]}}}async function XV(e,t){if(e.size>26214400)return{attachments:[],errors:[`${e.name}: file too large to upload (max 25 MB)`]};let n;try{n=await VV(e)}catch{return{attachments:[],errors:[`${e.name}: could not be read`]}}try{return{attachments:[tH(await t(e.name,n))],errors:[]}}catch(t){return{attachments:[],errors:[qV(e,t)]}}}async function ZV(e,t){let n=await Promise.all([...e].map(e=>{let n=HV(e);return n===`unsupported`?Promise.resolve({attachments:[],errors:[KV(e)]}):n===`inline-text`?JV(e):n===`image`&&e.size<=7340032?YV(e):XV(e,t)}));return{attachments:n.flatMap(e=>e.attachments),errors:n.flatMap(e=>e.errors)}}function QV(e,t){let n=t.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);return RegExp(`(^|\\s)@${n}[,.;:!?)\\]]*(\\s|$)`).test(e)}var $V=LV;function eH(e,t){let n=e.trim(),r=e=>{n+=`${n?`
834
+ `)){let e=EB.exec(r);if(e===null)continue;let[,i,a,o]=e;if(i===``)continue;let s=n.get(i);s===void 0&&(s={path:i,hits:[]},n.set(i,s),t.push(s)),s.hits.push({line:Number(a),text:o})}return t}function OB(e){return e.reduce((e,t)=>e+t.hits.length,0)}var kB=8,AB=5;function jB({item:e,dispatch:t}){let n=DB(e.output??``),[r,i]=(0,v.useState)(!1);if(n.length===0)return(0,N.jsx)(cB,{item:e});let a=r?n:n.slice(0,kB);return(0,N.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,N.jsxs)(`div`,{className:`text-xs text-zinc-500`,children:[OB(n),` match`,OB(n)===1?``:`es`,` in `,n.length,` file`,n.length===1?``:`s`]}),a.map(e=>(0,N.jsxs)(`div`,{className:`flex flex-col`,children:[(0,N.jsxs)(`button`,{type:`button`,onClick:()=>t({kind:`openFile`,path:e.path}),className:`flex items-center gap-2 truncate text-left font-mono text-xs text-zinc-600 hover:text-zinc-900 dark:text-zinc-400 dark:hover:text-zinc-100`,children:[(0,N.jsx)(`span`,{className:`truncate`,children:e.path}),(0,N.jsx)(`span`,{className:`shrink-0 text-zinc-400 dark:text-zinc-600`,children:e.hits.length})]}),(0,N.jsxs)(`div`,{className:`overflow-x-auto rounded border border-zinc-200 font-mono text-xs dark:border-zinc-800`,children:[e.hits.slice(0,AB).map((e,t)=>(0,N.jsxs)(`div`,{className:`flex gap-2 px-2`,children:[(0,N.jsx)(`span`,{className:`shrink-0 select-none text-zinc-400 dark:text-zinc-600`,children:e.line}),(0,N.jsx)(`span`,{className:`whitespace-pre text-zinc-700 dark:text-zinc-300`,children:e.text})]},t)),e.hits.length>AB&&(0,N.jsxs)(`div`,{className:`px-2 text-zinc-400 dark:text-zinc-600`,children:[`+`,e.hits.length-AB,` more in this file`]})]})]},e.path)),!r&&n.length>kB&&(0,N.jsxs)(`button`,{type:`button`,onClick:()=>i(!0),className:`self-start text-xs text-zinc-500 hover:text-zinc-700 dark:hover:text-zinc-300`,children:[`show `,n.length-kB,` more file`,n.length-kB===1?``:`s`]})]})}var MB=[uB,dB,Dg,pB,hB,TB,{id:`code-search`,match:e=>e.toolName===`grep`,stable:!0,showsRawReveal:!0,Expanded:jB},gB,_B,lB];function NB(e){for(let t of MB){let n=!1;try{n=t.match(e)}catch{n=!1}if(n)return t}return lB}function PB(e,t){let n=NB(e);if(t===void 0||t===n.id)return n;let r=MB.find(e=>e.id===t);if(r===void 0||r.id===lB.id||n.extensionOwned===!0)return n;let i=!1;try{i=r.match(e)}catch{i=!1}return i?r:n}function FB(e){if(typeof e!=`object`||!e)return``;let t=e,n=[`command`,`path`,`file_path`,`pattern`,`query`].find(e=>typeof t[e]==`string`);if(n)return t[n];let r=JSON.stringify(t);return r===`{}`?``:r}function IB({item:e,dispatch:t=nB}){let n=(0,v.useRef)(void 0),r=PB(e,n.current);n.current=r.id;let i=r.startsExpanded===!0,[a,o]=(0,v.useState)(i);(0,v.useEffect)(()=>{o(i)},[i]);let[s,c]=(0,v.useState)(!1),l=(0,v.useRef)(null),u=r.compactHeader?void 0:e.callHtml,d=r.compactHeader?``:FB(e.args),f=r.Collapsed,p=!a&&f!==void 0&&(r.hasCollapsed?.(e)??!0);return(0,N.jsxs)(`div`,{className:`rounded-lg border text-sm ${e.isError?`border-red-300 bg-red-50 dark:border-red-900/60 dark:bg-red-950/20`:`border-zinc-200 bg-zinc-50 dark:border-zinc-800 dark:bg-zinc-900/60`}`,children:[(0,N.jsxs)(`div`,{onMouseDown:e=>{l.current={x:e.clientX,y:e.clientY}},onClick:e=>{let t=l.current;l.current=null,!(e.detail>0&&t&&Math.hypot(e.clientX-t.x,e.clientY-t.y)>4)&&o(!a)},className:`flex w-full cursor-pointer items-center gap-2 px-3 py-2 text-left`,children:[(0,N.jsxs)(`button`,{type:`button`,"aria-expanded":a,"aria-label":u?e.toolName:void 0,className:`flex shrink-0 items-center gap-2`,children:[(0,N.jsx)(`span`,{className:`h-2 w-2 shrink-0 rounded-full ${e.running?`animate-pulse motion-reduce:animate-none bg-amber-400`:e.isError?`bg-red-500`:`bg-emerald-500`}`}),!u&&(0,N.jsx)(`span`,{className:`font-mono font-medium text-zinc-700 dark:text-zinc-300`,children:e.toolName})]}),u?(0,N.jsx)(Xe,{as:`span`,html:u,className:`min-w-0 flex-1 text-zinc-700 dark:text-zinc-300`}):d&&(0,N.jsx)(`span`,{className:`min-w-0 overflow-x-auto whitespace-nowrap font-mono text-xs text-zinc-500 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden`,children:d}),(0,N.jsx)(`span`,{className:`ml-auto text-xs text-zinc-400 dark:text-zinc-600`,children:a?`▾`:`▸`})]}),e.running&&e.progress!=null&&(0,N.jsx)(`div`,{className:`border-t border-zinc-200 px-3 py-1.5 dark:border-zinc-800`,children:(0,N.jsx)(`progress`,{value:e.progress,max:1,"aria-label":`${e.toolName} progress`,className:`h-1.5 w-full appearance-none overflow-hidden rounded-full bg-zinc-200 dark:bg-zinc-800 [&::-moz-progress-bar]:bg-emerald-500 [&::-webkit-progress-bar]:bg-transparent [&::-webkit-progress-value]:rounded-full [&::-webkit-progress-value]:bg-emerald-500`})}),p&&f!==void 0&&(0,N.jsx)(`div`,{className:`border-t border-zinc-200 px-3 py-2 dark:border-zinc-800`,children:(0,N.jsx)(f,{item:e,dispatch:t})}),a&&(0,N.jsxs)(`div`,{className:`border-t border-zinc-200 px-3 py-2 dark:border-zinc-800`,children:[(0,N.jsx)(r.Expanded,{item:e,dispatch:t}),r.showsRawReveal===!0&&(0,N.jsxs)(`div`,{className:`mt-2`,children:[(0,N.jsx)(`button`,{type:`button`,onClick:()=>c(!s),className:`text-xs text-zinc-400 hover:text-zinc-600 dark:text-zinc-600 dark:hover:text-zinc-400`,children:s?`hide raw output`:`raw output`}),s&&(0,N.jsx)(`div`,{className:`mt-1`,children:(0,N.jsx)(cB,{item:e})})]})]})]})}function LB({item:e}){let[t,n]=(0,v.useState)(!1),r=e.details!==void 0,i=!!e.contentHtml,a=e.contentHtmlCollapsed??e.contentHtml,o=r||i&&!!e.contentHtmlCollapsed;return(0,N.jsxs)(`div`,{className:`rounded-lg border border-violet-200 bg-violet-50 px-3 py-2 text-sm dark:border-violet-900/60 dark:bg-violet-950/30`,children:[(0,N.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,N.jsxs)(`span`,{className:`font-mono text-xs font-bold text-violet-700 dark:text-violet-300`,children:[`[`,e.customType,`]`]}),o&&(0,N.jsx)(`button`,{type:`button`,onClick:()=>n(!t),title:`Show details`,className:`ml-auto text-xs text-violet-500 hover:text-violet-700 dark:text-violet-500 dark:hover:text-violet-300`,children:t?`▾`:`▸`})]}),i&&a?(0,N.jsx)(Xe,{html:t||!e.contentHtmlCollapsed?e.contentHtml??a:a,className:`mt-1 text-violet-950 dark:text-violet-100`}):(0,N.jsx)(`div`,{className:`prose-chat mt-1 text-violet-950 dark:text-violet-100`,children:(0,N.jsx)(SC,{remarkPlugins:[dz,Cz],rehypePlugins:[WA],children:re(e.text)})}),t&&r&&(0,N.jsx)(`pre`,{className:`mt-2 max-h-96 overflow-auto border-t border-violet-200 pt-2 font-mono text-xs text-violet-600 dark:border-violet-900/60 dark:text-violet-400`,children:JSON.stringify(e.details,null,2)})]})}var RB=`pi-outpost:update-notice-dismissed`;function zB(){try{return window.localStorage.getItem(RB)}catch{return null}}function BB({notice:e}){let[t,n]=(0,v.useState)(()=>zB());return t===e.latest?null:(0,N.jsxs)(`div`,{role:`status`,"data-testid":`update-notice`,className:`flex items-center gap-2 border-b border-sky-200 bg-sky-50 px-4 py-1.5 text-xs text-sky-900 dark:border-sky-900 dark:bg-sky-950/40 dark:text-sky-200`,children:[(0,N.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[`pi-outpost `,e.latest,` is available (you have `,e.running,`). `,e.instruction,` `,(0,N.jsx)(`a`,{href:e.releaseNotes,target:`_blank`,rel:`noreferrer`,className:`font-medium underline underline-offset-2`,children:`What's new`})]}),(0,N.jsx)(`code`,{className:`shrink-0 rounded bg-white/70 px-1.5 py-0.5 font-mono dark:bg-sky-900/40`,children:e.copy}),(0,N.jsx)(me,{text:e.copy}),(0,N.jsx)(`button`,{type:`button`,"aria-label":`Dismiss the update notice`,onClick:()=>{try{window.localStorage.setItem(RB,e.latest)}catch{}n(e.latest)},className:`shrink-0 rounded px-1.5 text-sky-700 hover:bg-sky-100 dark:text-sky-300 dark:hover:bg-sky-900/50`,children:`×`})]})}var VB=`pi-outpost:changes-notice-dismissed`;function HB(){try{return window.localStorage.getItem(VB)}catch{return null}}function UB(e){return(0,N.jsx)(`a`,{...e,target:`_blank`,rel:`noreferrer`})}function WB({changes:e}){let[t,n]=(0,v.useState)(()=>HB()),[r,i]=(0,v.useState)(!1);if(t===e.to)return null;let a=e.entries.length>0;return(0,N.jsxs)(`div`,{role:`status`,"data-testid":`changes-notice`,className:`border-b border-zinc-200 bg-zinc-50 text-xs text-zinc-700 dark:border-zinc-800 dark:bg-zinc-900/60 dark:text-zinc-300`,children:[(0,N.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-1.5`,children:[(0,N.jsx)(`span`,{className:`shrink-0 rounded-full bg-sky-100 px-1.5 font-medium leading-4 text-sky-800 dark:bg-sky-900/50 dark:text-sky-200`,children:`New`}),(0,N.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[`pi-outpost was updated to `,e.to,` (from `,e.from,`).`]}),a?(0,N.jsx)(`button`,{type:`button`,"aria-expanded":r,onClick:()=>i(!r),className:`shrink-0 rounded px-1.5 font-medium text-zinc-900 underline-offset-2 hover:underline dark:text-zinc-100`,children:r?`Hide what changed`:`What's changed`}):(0,N.jsx)(UB,{href:e.releaseNotes,className:`shrink-0 font-medium text-zinc-900 underline-offset-2 hover:underline dark:text-zinc-100`,children:`Release notes`}),(0,N.jsx)(`button`,{type:`button`,"aria-label":`Dismiss the update news`,onClick:()=>{try{window.localStorage.setItem(VB,e.to)}catch{}n(e.to)},className:`shrink-0 rounded px-1.5 text-zinc-500 hover:bg-zinc-200 hover:text-zinc-800 dark:text-zinc-400 dark:hover:bg-zinc-800 dark:hover:text-zinc-100`,children:`×`})]}),r&&a&&(0,N.jsx)(`div`,{"data-testid":`changes-notice-body`,className:`max-h-[50vh] overflow-y-auto border-t border-zinc-200 px-4 py-3 dark:border-zinc-800`,children:(0,N.jsxs)(`div`,{className:`mx-auto max-w-3xl`,children:[e.entries.map(e=>(0,N.jsxs)(`section`,{className:`mb-4`,children:[(0,N.jsxs)(`h2`,{className:`text-sm font-semibold text-zinc-900 dark:text-zinc-100`,children:[e.version,e.date&&(0,N.jsx)(`span`,{className:`ml-2 font-normal text-zinc-500 dark:text-zinc-400`,children:e.date})]}),(0,N.jsx)(`div`,{className:`prose-chat text-zinc-800 dark:text-zinc-200`,children:(0,N.jsx)(SC,{remarkPlugins:[dz],components:{a:UB},children:e.markdown})})]},e.version)),(0,N.jsx)(UB,{href:e.releaseNotes,className:`font-medium text-zinc-900 underline-offset-2 hover:underline dark:text-zinc-100`,children:`Release notes on GitHub`})]})})]})}function GB(e){return e.id??e.root}function KB(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${Math.round(e/1e3)}k`:String(e)}function qB({item:e}){let[t,n]=(0,v.useState)(!1),r=e.tokensBefore?`Conversation compacted here — ${KB(e.tokensBefore)} tokens summarised`:`Conversation compacted here`;return(0,N.jsxs)(`div`,{className:`my-1`,"data-compaction-boundary":!0,children:[(0,N.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,N.jsx)(`span`,{className:`h-px flex-1 bg-amber-300 dark:bg-amber-900`}),(0,N.jsxs)(`button`,{type:`button`,onClick:()=>n(!t),"aria-expanded":t,className:`rounded-full border border-amber-300 bg-amber-50 px-2 py-0.5 text-xs text-amber-800 hover:bg-amber-100 dark:border-amber-900 dark:bg-amber-950/40 dark:text-amber-300 dark:hover:bg-amber-950/70`,children:[r,` `,t?`▾`:`▸`]}),(0,N.jsx)(`span`,{className:`h-px flex-1 bg-amber-300 dark:bg-amber-900`})]}),t&&(0,N.jsxs)(`div`,{className:`mt-2 whitespace-pre-wrap rounded-lg border border-amber-200 bg-amber-50/60 px-3 py-2 text-sm text-zinc-700 dark:border-amber-900/60 dark:bg-amber-950/20 dark:text-zinc-300`,children:[(0,N.jsx)(`p`,{className:`mb-1 text-xs font-medium text-amber-800 dark:text-amber-300`,children:`What the agent kept of everything above:`}),e.summary||`(the runtime recorded no summary)`]})]})}function JB({older:e,onLoad:t}){if(e.remaining<=0&&!e.error)return null;let n=e.remaining,r=e.loading?`Loading earlier messages…`:`Load ${n} earlier message${n===1?``:`s`}`;return(0,N.jsxs)(`div`,{className:`flex flex-col items-center gap-1 pb-2`,"data-older-messages":!0,children:[(0,N.jsx)(`button`,{type:`button`,onClick:t,disabled:e.loading,"aria-busy":e.loading,"aria-label":e.loading?`Loading earlier messages`:`Load ${n} earlier messages`,className:`rounded-full border border-zinc-300 bg-white px-3 py-1 text-xs text-zinc-600 hover:bg-zinc-50 disabled:cursor-progress disabled:opacity-60 dark:border-zinc-700 dark:bg-zinc-900 dark:text-zinc-400 dark:hover:bg-zinc-800`,children:r}),e.error&&(0,N.jsxs)(`p`,{role:`status`,className:`text-xs text-red-600 dark:text-red-400`,children:[e.error,` — try again`]})]})}var YB={cost:0,unpriced:0,turns:0,input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0};function XB(e){let t={...YB};for(let n of e){if(n.kind!==`assistant`||!n.usage)continue;let e=n.usage;t.turns+=1,t.input+=e.input,t.output+=e.output,t.cacheRead+=e.cacheRead,t.cacheWrite+=e.cacheWrite,t.totalTokens+=e.totalTokens,e.cost===void 0?t.unpriced+=1:t.cost+=e.cost}return t}function ZB(e){let t=e>0&&e<.01?4:2;return`$${e.toFixed(t)}`}function QB(e){return e<1e3?String(e):e<1e6?`${Math.round(e/1e3)}k`:`${(e/1e6).toFixed(1)}M`}var $B=80,eV=new WeakMap;function tV(e){let t=typeof e==`object`&&!!e;if(t){let t=eV.get(e);if(t!==void 0)return t}let n=0;try{n=JSON.stringify(e)?.length??0}catch{n=0}return t&&eV.set(e,n),n}function nV(e){let t=e.replace(/\s+/g,` `).trim();return t.length>$B?`${t.slice(0,79)}…`:t}function rV(e,t){return{index:e,title:t,turns:0,toolCalls:0,failedToolCalls:0,input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,unpriced:0}}function iV(e,t){e.turns+=1,e.input+=t.input,e.output+=t.output,e.cacheRead+=t.cacheRead,e.cacheWrite+=t.cacheWrite,e.totalTokens+=t.totalTokens,t.cost===void 0?e.unpriced+=1:e.cost=(e.cost??0)+t.cost}function aV(e){if(e.length===0)return 0;let t=[...e].sort((e,t)=>e-t),n=Math.floor(t.length/2);return t.length%2==1?t[n]:(t[n-1]+t[n])/2}function oV(e){let t=[],n=[],r=[],i=new Map,a=rV(-1,``),o=a;e.forEach((e,a)=>{if(e.kind===`user`){o=rV(a,nV(e.text)),r.push(o);return}if(e.kind===`assistant`){if(!e.usage)return;t.push({index:a,number:t.length+1,requestIndex:o.index,usage:e.usage}),iV(o,e.usage);return}if(e.kind!==`tool`)return;let s={index:a,toolCallId:e.toolCallId,name:e.toolName,inputSize:tV(e.args),outputSize:e.output.length,isError:e.isError===!0,running:e.running===!0,requestIndex:o.index};n.push(s),o.toolCalls+=1,s.isError&&(o.failedToolCalls+=1);let c=i.get(s.name)??{name:s.name,calls:0,failures:0,inputSize:0,outputSize:0};c.calls+=1,s.isError&&(c.failures+=1),c.inputSize+=s.inputSize,c.outputSize+=s.outputSize,i.set(s.name,c)}),(a.turns>0||a.toolCalls>0)&&r.unshift(a);let s=XB(e),c=t.map(e=>e.usage.cost).filter(e=>e!==void 0),l=n.filter(e=>e.isError).length;return{turns:t,requests:r,toolCalls:n,tools:[...i.values()],totals:s,pricedTurns:c.length,averageTurnCost:c.length===0?0:s.cost/c.length,medianTurnCost:aV(c),totalToolCalls:n.length,failedToolCalls:l,toolCallsPerTurn:t.length===0?0:n.length/t.length}}function sV(e,t){let n=[...e];return t===`input`?n.sort((e,t)=>t.inputSize-e.inputSize):t===`failure`?n.sort((e,t)=>Number(t.isError)-Number(e.isError)||t.outputSize-e.outputSize):n.sort((e,t)=>t.outputSize-e.outputSize)}function cV(e){return e.filter(e=>e.index>=0).sort((e,t)=>t.totalTokens-e.totalTokens||(t.cost??0)-(e.cost??0))}function lV(e){return e<1e3?`${e} B`:e<1e6?`${Math.round(e/1e3)} kB`:`${(e/1e6).toFixed(1)} MB`}var uV=768,dV=26,fV=132,pV=12,mV=96,hV=124,gV=[{key:`input`,label:`input`,className:`text-emerald-500`,value:e=>e.usage.input},{key:`output`,label:`output`,className:`text-blue-500`,value:e=>e.usage.output},{key:`cacheRead`,label:`cache read`,className:`text-violet-500`,value:e=>e.usage.cacheRead},{key:`cacheWrite`,label:`cache write`,className:`text-amber-500`,value:e=>e.usage.cacheWrite}],_V=[{key:`cost`,label:`cost`,className:`text-rose-500`,value:e=>e.usage.cost??0}];function vV({title:e,children:t}){return(0,N.jsxs)(`section`,{className:`border-t border-zinc-200 px-4 py-3 dark:border-zinc-800`,children:[(0,N.jsx)(`h3`,{className:`mb-2 font-mono text-[11px] uppercase tracking-wide text-zinc-400 dark:text-zinc-500`,children:e}),t]})}function yV({children:e}){return(0,N.jsx)(`p`,{className:`text-xs text-zinc-400 dark:text-zinc-500`,children:e})}function bV({label:e,value:t,hint:n}){return(0,N.jsxs)(`div`,{className:`rounded-md border border-zinc-200 px-2 py-1.5 dark:border-zinc-800`,children:[(0,N.jsx)(`div`,{"aria-label":`${e}: ${t}`,className:`font-mono text-sm text-zinc-700 dark:text-zinc-200`,children:t}),(0,N.jsx)(`div`,{className:`text-[11px] text-zinc-500 dark:text-zinc-400`,children:e}),n&&(0,N.jsx)(`div`,{className:`text-[10px] text-zinc-400 dark:text-zinc-500`,children:n})]})}function xV({turns:e,series:t,format:n,onJump:r,describe:i}){let a=Math.max(1,...e.flatMap(e=>t.map(t=>t.value(e)))),o=Math.max(e.length*dV,dV),s=e=>dV/2+e*dV,c=e=>pV+mV*(1-e/a);return(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`div`,{className:`mb-1 flex flex-wrap gap-x-3 gap-y-1`,children:t.map(e=>(0,N.jsxs)(`span`,{className:`flex items-center gap-1 text-[10px] text-zinc-500 dark:text-zinc-400`,children:[(0,N.jsx)(`span`,{className:`inline-block h-0.5 w-3 bg-current ${e.className}`}),e.label]},e.key))}),(0,N.jsxs)(`div`,{className:`flex`,children:[(0,N.jsxs)(`div`,{"aria-hidden":!0,className:`flex w-12 shrink-0 flex-col justify-between py-2 pr-1 text-right font-mono text-[9px] text-zinc-400 dark:text-zinc-600`,style:{height:fV},children:[(0,N.jsx)(`span`,{children:n(a)}),(0,N.jsx)(`span`,{children:`0`})]}),(0,N.jsx)(`div`,{className:`min-w-0 flex-1 overflow-x-auto`,children:(0,N.jsxs)(`svg`,{width:o,height:fV,role:`group`,"aria-label":`Per-turn chart`,children:[(0,N.jsx)(`line`,{x1:0,x2:o,y1:108,y2:108,stroke:`currentColor`,className:`text-zinc-200 dark:text-zinc-800`}),t.map(t=>(0,N.jsx)(`polyline`,{fill:`none`,stroke:`currentColor`,strokeWidth:1.5,className:t.className,points:e.map((e,n)=>`${s(n)},${c(t.value(e))}`).join(` `)},t.key)),e.map((n,a)=>(0,N.jsxs)(`g`,{children:[t.map(e=>(0,N.jsx)(`circle`,{cx:s(a),cy:c(e.value(n)),r:2,fill:`currentColor`,className:e.className},e.key)),(0,N.jsx)(`rect`,{x:s(a)-dV/2,y:0,width:dV,height:fV,fill:`transparent`,role:`button`,tabIndex:0,"aria-label":`Turn ${n.number}: ${i(n)} — jump to it`,className:`cursor-pointer outline-none focus-visible:fill-zinc-500/10`,onClick:()=>r(n.index),onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),r(n.index))},children:(0,N.jsx)(`title`,{children:`turn ${n.number} · ${i(n)}`})}),(e.length<=12||n.number%5==0)&&(0,N.jsx)(`text`,{x:s(a),y:hV,textAnchor:`middle`,className:`fill-zinc-400 text-[9px] dark:fill-zinc-600`,children:n.number})]},n.index))]})})]})]})}function SV({onJump:e,label:t,children:n}){return(0,N.jsx)(`button`,{type:`button`,onClick:e,"aria-label":t,className:`flex w-full items-baseline gap-2 rounded-md px-2 py-1 text-left text-xs hover:bg-zinc-100 dark:hover:bg-zinc-900`,children:n})}function CV({analysis:e,onJump:t,onClose:n}){let[r,i]=(0,v.useState)(`output`),{totals:a}=e;function o(e){t(e),window.innerWidth<uV&&n()}let s=e.turns.length===0&&e.toolCalls.length===0,c=sV(e.toolCalls,r),l=cV(e.requests);return(0,N.jsxs)(`aside`,{"aria-label":`Session analysis`,className:`absolute inset-y-0 right-0 z-10 w-full overflow-y-auto border-l border-zinc-200 bg-white shadow-xl md:w-[26rem] dark:border-zinc-800 dark:bg-zinc-950`,children:[(0,N.jsxs)(`header`,{className:`sticky top-0 flex items-center gap-2 border-b border-zinc-200 bg-white px-4 py-2 dark:border-zinc-800 dark:bg-zinc-950`,children:[(0,N.jsx)(`h2`,{className:`font-mono text-xs text-zinc-600 dark:text-zinc-300`,children:`session analysis`}),(0,N.jsx)(`button`,{type:`button`,onClick:n,"aria-label":`Close session analysis`,className:`ml-auto rounded-md px-2 py-1 text-sm text-zinc-500 hover:bg-zinc-100 dark:text-zinc-400 dark:hover:bg-zinc-900`,children:`×`})]}),s?(0,N.jsx)(`div`,{className:`px-4 py-6`,children:(0,N.jsx)(yV,{children:`Nothing to analyse yet — no turn has reported figures and no tool has been called.`})}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(vV,{title:`tokens`,children:(0,N.jsxs)(`div`,{className:`grid grid-cols-3 gap-2`,children:[(0,N.jsx)(bV,{label:`total`,value:QB(a.totalTokens)}),(0,N.jsx)(bV,{label:`fresh input`,value:QB(a.input)}),(0,N.jsx)(bV,{label:`output`,value:QB(a.output)}),(0,N.jsx)(bV,{label:`cache read`,value:QB(a.cacheRead)}),(0,N.jsx)(bV,{label:`cache write`,value:QB(a.cacheWrite)}),(0,N.jsx)(bV,{label:`turns`,value:String(e.turns.length)})]})}),(0,N.jsx)(vV,{title:`cost`,children:e.pricedTurns===0?(0,N.jsx)(yV,{children:`No turn was priced — this provider reports tokens only.`}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`div`,{className:`grid grid-cols-3 gap-2`,children:[(0,N.jsx)(bV,{label:`total`,value:ZB(a.cost)}),(0,N.jsx)(bV,{label:`average turn`,value:ZB(e.averageTurnCost)}),(0,N.jsx)(bV,{label:`median turn`,value:ZB(e.medianTurnCost)})]}),(0,N.jsxs)(`p`,{className:`mt-1 text-[11px] text-zinc-400 dark:text-zinc-500`,children:[`over `,e.pricedTurns,` priced turn`,e.pricedTurns===1?``:`s`,a.unpriced>0&&`, ${a.unpriced} unpriced`]})]})}),(0,N.jsx)(vV,{title:`tool calls`,children:e.totalToolCalls===0?(0,N.jsx)(yV,{children:`No tool call recorded in this session.`}):(0,N.jsxs)(`div`,{className:`grid grid-cols-3 gap-2`,children:[(0,N.jsx)(bV,{label:`calls`,value:String(e.totalToolCalls)}),(0,N.jsx)(bV,{label:`per turn`,value:e.toolCallsPerTurn.toFixed(1)}),(0,N.jsx)(bV,{label:`failed`,value:String(e.failedToolCalls)})]})}),(0,N.jsx)(vV,{title:`tokens per turn`,children:e.turns.length===0?(0,N.jsx)(yV,{children:`No turn has reported figures yet.`}):(0,N.jsx)(xV,{turns:e.turns,series:gV,format:QB,onJump:o,describe:e=>`${QB(e.usage.totalTokens)} tokens (input ${e.usage.input}, output ${e.usage.output}, cache read ${e.usage.cacheRead}, cache write ${e.usage.cacheWrite})`})}),(0,N.jsx)(vV,{title:`cost per turn`,children:e.pricedTurns===0?(0,N.jsx)(yV,{children:`No turn was priced, so there is no cost to plot.`}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(xV,{turns:e.turns.filter(e=>e.usage.cost!==void 0),series:_V,format:ZB,onJump:o,describe:e=>ZB(e.usage.cost??0)}),a.unpriced>0&&(0,N.jsxs)(`p`,{className:`mt-1 text-[10px] text-zinc-400 dark:text-zinc-500`,children:[a.unpriced,` unpriced turn`,a.unpriced===1?``:`s`,` left out — they carry no price to plot`]})]})}),(0,N.jsx)(vV,{title:`costliest tool calls`,children:c.length===0?(0,N.jsx)(yV,{children:`No tool call recorded in this session.`}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`div`,{className:`mb-1 flex items-center gap-2`,children:[(0,N.jsx)(`label`,{htmlFor:`tool-ranking`,className:`text-[11px] text-zinc-500 dark:text-zinc-400`,children:`rank by`}),(0,N.jsxs)(`select`,{id:`tool-ranking`,value:r,onChange:e=>i(e.target.value),className:`rounded-md border border-zinc-300 bg-white px-1.5 py-0.5 font-mono text-[11px] text-zinc-600 dark:border-zinc-800 dark:bg-zinc-900 dark:text-zinc-300`,children:[(0,N.jsx)(`option`,{value:`output`,children:`output size`}),(0,N.jsx)(`option`,{value:`input`,children:`input size`}),(0,N.jsx)(`option`,{value:`failure`,children:`failure`})]})]}),(0,N.jsx)(`p`,{className:`mb-1 text-[10px] text-zinc-400 dark:text-zinc-500`,children:`measured content size, not tokens — a tool call carries no price`}),c.slice(0,10).map(e=>(0,N.jsxs)(SV,{onJump:()=>o(e.index),label:`Jump to the ${e.name} call, output ${lV(e.outputSize)}`,children:[(0,N.jsx)(`span`,{className:`font-mono text-zinc-600 dark:text-zinc-300`,children:e.name}),e.isError&&(0,N.jsx)(`span`,{className:`text-red-500`,children:`failed`}),e.running&&(0,N.jsx)(`span`,{className:`text-zinc-400`,children:`running`}),(0,N.jsxs)(`span`,{className:`ml-auto font-mono text-zinc-500 dark:text-zinc-400`,children:[`in `,lV(e.inputSize),` · out `,lV(e.outputSize)]})]},e.toolCallId||`${e.index}`))]})}),(0,N.jsx)(vV,{title:`tools`,children:e.tools.length===0?(0,N.jsx)(yV,{children:`No tool has been called yet.`}):(0,N.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,N.jsx)(`thead`,{children:(0,N.jsxs)(`tr`,{className:`text-left text-[10px] uppercase text-zinc-400 dark:text-zinc-500`,children:[(0,N.jsx)(`th`,{className:`font-normal`,children:`tool`}),(0,N.jsx)(`th`,{className:`font-normal`,children:`calls`}),(0,N.jsx)(`th`,{className:`font-normal`,children:`failed`}),(0,N.jsx)(`th`,{className:`text-right font-normal`,children:`in / out`})]})}),(0,N.jsx)(`tbody`,{className:`font-mono text-zinc-600 dark:text-zinc-300`,children:[...e.tools].sort((e,t)=>t.outputSize-e.outputSize).map(e=>(0,N.jsxs)(`tr`,{children:[(0,N.jsx)(`td`,{children:e.name}),(0,N.jsx)(`td`,{children:e.calls}),(0,N.jsx)(`td`,{className:e.failures>0?`text-red-500`:``,children:e.failures}),(0,N.jsxs)(`td`,{className:`text-right`,children:[lV(e.inputSize),` / `,lV(e.outputSize)]})]},e.name))})]})}),(0,N.jsx)(vV,{title:`costliest requests`,children:l.length===0?(0,N.jsx)(yV,{children:`No request has consumed anything yet.`}):l.slice(0,10).map(e=>(0,N.jsxs)(SV,{onJump:()=>o(e.index),label:`Jump to the request "${e.title}"`,children:[(0,N.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-zinc-600 dark:text-zinc-300`,children:e.title}),(0,N.jsxs)(`span`,{className:`shrink-0 font-mono text-zinc-500 dark:text-zinc-400`,children:[QB(e.totalTokens),` tok`,e.cost!==void 0&&` · ${ZB(e.cost)}`]}),(0,N.jsxs)(`span`,{className:`shrink-0 text-[10px] text-zinc-400 dark:text-zinc-500`,children:[e.turns,`t / `,e.toolCalls,`c`,e.failedToolCalls>0&&` · ${e.failedToolCalls}✗`]})]},e.index))})]})]})}var wV=2e3;function TV({items:e,scrollerRef:t,hideTools:n,onShowTools:r,onJump:i}){let[a,o]=(0,v.useState)(null),s=(0,v.useRef)(null),[c,l]=(0,v.useState)(0),u=(0,v.useRef)(null);(0,v.useEffect)(()=>()=>{u.current&&clearTimeout(u.current)},[]);let d=(0,v.useCallback)(t=>{let i=e[t];i&&(i.kind===`tool`&&n&&r(),s.current=t,l(e=>e+1))},[e,n,r]);return(0,v.useEffect)(()=>{let e=s.current;if(e===null)return;s.current=null;let n=t.current?.querySelector(`[data-item-index="${e}"]`);n&&(i(n),n.scrollIntoView?.({behavior:`smooth`,block:`center`}),o(e),u.current&&clearTimeout(u.current),u.current=setTimeout(()=>o(null),wV))},[c,n,t,i]),{jumpToItem:d,highlightIndex:a}}var EV={tools:`pi-outpost:hide-tools`,reasoning:`pi-outpost:hide-reasoning`},DV=[`tools`,`reasoning`],OV={tools:`Tool calls`,reasoning:`Reasoning`};function kV(e){try{return localStorage.getItem(EV[e])===`1`}catch{return!1}}function AV(){return{tools:!kV(`tools`),reasoning:!kV(`reasoning`)}}function jV(e,t){try{localStorage.setItem(EV[e],t?`0`:`1`)}catch{}}function MV(e){return DV.filter(t=>!e[t]).length}function NV(e,t){let n=null;for(let r of e)(r.repo===``||t===r.repo||t.startsWith(`${r.repo}/`))&&(n===null||r.repo.length>n.repo.length)&&(n=r);return n}function PV({isStreaming:e,count:t,onSend:n}){let[r,i]=(0,v.useState)(!1);(0,v.useEffect)(()=>{e||i(!1)},[e]);let a=t===1?`send it now`:`send all ${t} now`;return r?(0,N.jsxs)(`div`,{role:`group`,"aria-label":`Confirm sending the queued messages now`,className:`ml-auto flex max-w-[85%] flex-wrap items-center justify-end gap-2 rounded-lg border border-amber-300 bg-amber-50 px-3 py-2 text-xs text-amber-900 dark:border-amber-900/60 dark:bg-amber-950/30 dark:text-amber-200`,children:[(0,N.jsx)(`span`,{className:`mr-auto`,children:`This stops the current step: a reply being written is dropped and a running tool is stopped. Work already done is kept.`}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>i(!1),className:`rounded border border-amber-300 px-2 py-0.5 dark:border-amber-800`,children:`cancel`}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>{i(!1),n()},className:`rounded border border-amber-400 bg-white/70 px-2 py-0.5 font-medium dark:border-amber-700 dark:bg-zinc-900/60`,children:`stop and send`})]}):(0,N.jsx)(`div`,{className:`flex justify-end`,children:(0,N.jsx)(`button`,{type:`button`,onClick:()=>e?i(!0):n(),title:e?`stop the current step and send the queued messages now`:`send the queued messages now`,className:`rounded border border-blue-300 px-2 py-0.5 text-xs text-blue-900 hover:bg-blue-50 dark:border-blue-900 dark:text-zinc-300 dark:hover:bg-blue-950/40`,children:a})})}var FV=/(?:^|\s)@([^\s@]+)/g,IV=new Set([`,`,`.`,`;`,`:`,`!`,`?`,`)`,`]`]);function LV(e){let t=e.length;for(;t>0&&IV.has(e[t-1]);)t--;return e.slice(0,t)}function RV(e){return[...e.matchAll(FV)].map(([,e])=>LV(e??``)).filter(e=>e.length>0)}var zV=class extends Error{reason;constructor(e,t){super(e),this.name=`UploadError`,this.reason=t}},BV=class extends zV{constructor(){super(`The workspace changed before the import finished`),this.name=`UploadContextChangedError`}};function VV(e){return e.size>26214400?Promise.reject(new zV(`Files are limited to 25 MB`,`too-large`)):new Promise((t,n)=>{let r=new FileReader;r.onload=()=>t(String(r.result).split(`,`,2)[1]??``),r.onerror=()=>n(new zV(`The file could not be read`)),r.onabort=()=>n(new zV(`Reading the file was cancelled`)),r.readAsDataURL(e)})}function HV(e){return new Promise((t,n)=>{let r=new FileReader;r.onload=()=>t(r.result.split(`,`,2)[1]??``),r.onerror=()=>n(r.error),r.readAsDataURL(e)})}function UV(e){return e.type.startsWith(`image/`)?`image`:e.type===`application/pdf`||le(e.name)||ue(e.name)?`extraction-tool`:e.size<=524288?`inline-text`:KV(e)&&e.size<=26214400?`extraction-tool`:`unsupported`}function WV(e){let t=UV(e);return t===`extraction-tool`||t===`image`&&e.size>7340032}var GV=new Set([`application/json`,`application/xml`,`application/javascript`,`application/x-yaml`,`application/yaml`,`application/sql`]);function KV(e){return e.type.startsWith(`text/`)||GV.has(e.type)}function qV(e){return KV(e)?`${e.name}: file too large to upload (max 25 MB)`:`${e.name}: unsupported file type${e.type?` (${e.type})`:``}`}function JV(e,t){return t instanceof zV?t.reason===`denied`?`${e.name}: cannot upload — the workspace is read-only`:t.reason===`too-large`?`${e.name}: file too large to upload (max 25 MB)`:t.reason===`invalid`?`${e.name}: ${t.message}`:`${e.name}: upload failed — ${t.message}`:`${e.name}: upload failed`}async function YV(e){let t;try{t=await e.text()}catch{return{attachments:[],errors:[`${e.name}: could not be read`]}}return t.includes(`\0`)?{attachments:[],errors:[`${e.name}: unsupported binary file`]}:{attachments:[{name:e.name,kind:`text`,data:t,mimeType:e.type||`text/plain`,source:`manual`}],errors:[]}}async function XV(e){try{let t=await HV(e);return{attachments:[{name:e.name,kind:`image`,data:t,mimeType:e.type,source:`manual`}],errors:[]}}catch{return{attachments:[],errors:[`${e.name}: could not be read`]}}}async function ZV(e,t){if(e.size>26214400)return{attachments:[],errors:[`${e.name}: file too large to upload (max 25 MB)`]};let n;try{n=await HV(e)}catch{return{attachments:[],errors:[`${e.name}: could not be read`]}}try{return{attachments:[nH(await t(e.name,n))],errors:[]}}catch(t){return{attachments:[],errors:[JV(e,t)]}}}async function QV(e,t){let n=await Promise.all([...e].map(e=>{let n=UV(e);return n===`unsupported`?Promise.resolve({attachments:[],errors:[qV(e)]}):n===`inline-text`?YV(e):n===`image`&&e.size<=7340032?XV(e):ZV(e,t)}));return{attachments:n.flatMap(e=>e.attachments),errors:n.flatMap(e=>e.errors)}}function $V(e,t){let n=t.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);return RegExp(`(^|\\s)@${n}[,.;:!?)\\]]*(\\s|$)`).test(e)}var eH=RV;function tH(e,t){let n=e.trim(),r=e=>{n+=`${n?`
835
835
 
836
- `:``}${e}`};for(let e of t)e.kind===`path`?QV(n,e.data)||r(`@${e.data}`):e.kind===`text`&&r(`\`\`\`${e.name}\n${e.data}\n\`\`\``);return n}function tH(e){return{name:e,kind:`path`,data:e,mimeType:`text/plain`,source:`manual`}}function nH(e,t){return e.some(e=>e.kind===`path`&&e.data===t)?e:[...e,tH(t)]}function rH(e,t){return e.filter((e,n)=>n!==t)}function iH(e,t){if(!t)return!1;let n=e.composedPath();if(n.length>0)return n.includes(t);let r=e.target;return r!==null&&t.contains(r)}function aH(e){let t=(0,v.useRef)(null);return(0,v.useEffect)(()=>{function n(n){t.current&&!iH(n,t.current)&&e()}return document.addEventListener(`mousedown`,n),()=>document.removeEventListener(`mousedown`,n)},[e]),t}var oH=100,sH=new Intl.Collator(void 0,{sensitivity:`base`,numeric:!0}),cH={extension:`ext`,prompt:`prompt`,skill:`skill`};function lH(e){return e===`directory`||e===`symlink-directory`}function uH(e,t){let n=e.slice(0,t),r=/(?:^|\s)@([^\s@]*)$/.exec(n);return r?{start:t-r[1].length-1,query:r[1]}:null}function dH({isStreaming:e,connected:t,commands:n,fileSearch:r,prefill:i,attachments:a,pendingUploads:o=[],onAttach:s,onMentionPaths:c,onRemoveAttachment:l,onSend:u,onAbort:d,onSearchFiles:f,onClearFileSearch:p,initialDraft:m,onDraftChange:h}){let[g,_]=(0,v.useState)(m??``);(0,v.useEffect)(()=>{h?.(g)},[g,h]);let[y,b]=(0,v.useState)(0),[x,S]=(0,v.useState)(0),[C,w]=(0,v.useState)(!1),T=(0,v.useRef)(null),E=(0,v.useRef)(null),D=(0,v.useRef)(null),O=(0,v.useRef)(null),ee=(0,v.useRef)(null);(0,v.useEffect)(()=>{i&&_(i.text)},[i?.nonce]),(0,v.useEffect)(()=>{ee.current!==null&&(D.current?.focus(),D.current?.setSelectionRange(ee.current,ee.current),ee.current=null)},[g]),(0,v.useLayoutEffect)(()=>{let e=D.current;if(!e)return;let t=-1,n=()=>{t=e.offsetWidth,e.style.overflowY=`hidden`,e.style.height=`auto`,e.style.height=`${e.scrollHeight}px`,e.scrollHeight>e.clientHeight&&(e.style.overflowY=`auto`)};n();let r=typeof ResizeObserver>`u`?void 0:new ResizeObserver(()=>{e.offsetWidth!==t&&n()});return r?.observe(e,{box:`border-box`}),()=>r?.disconnect()},[g]);let te=(0,v.useMemo)(()=>$V(g),[g]);(0,v.useEffect)(()=>{c(te)},[te.join(`
837
- `)]);let k=(0,v.useMemo)(()=>{let e=/^\/(\S*)$/.exec(g);return e?e[1].toLowerCase():null},[g]),ne=(0,v.useMemo)(()=>k===null?[]:n.filter(e=>e.name.toLowerCase().includes(k)).sort((e,t)=>{let n=e.name.toLowerCase().startsWith(k);return n===t.name.toLowerCase().startsWith(k)?sH.compare(e.name,t.name):n?-1:1}).slice(0,oH),[k,n]),A=k===null?uH(g,y):null;(0,v.useEffect)(()=>{if(!A||A.query.length===0){p();return}let e=window.setTimeout(()=>f(A.query),150);return()=>clearTimeout(e)},[A?.query]);let re=(0,v.useMemo)(()=>{if(ne.length>0)return{kind:`command`,items:ne};let e=A&&r?.query===A.query?r.results:[];return e.length>0?{kind:`file`,items:e}:null},[ne,A,r]),j=re!==null&&!C,ie=k===null?A?`file:${A.query}`:null:`cmd:${k}`;(0,v.useEffect)(()=>{S(0)},[ie]),(0,v.useEffect)(()=>{w(!1)},[k===null?A?`file`:null:`command`]),(0,v.useEffect)(()=>{if(!j)return;let e=e=>{iH(e,T.current)||w(!0)};return document.addEventListener(`mousedown`,e),document.addEventListener(`touchstart`,e),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`touchstart`,e)}},[j]),(0,v.useEffect)(()=>{E.current?.querySelector(`[data-selected="true"]`)?.scrollIntoView({block:`nearest`})},[x]);let ae=o.length>0,[oe,se]=(0,v.useState)(!1);(0,v.useEffect)(()=>{ae||se(!1)},[ae]);function ce(){if(ae){se(!0);return}let e=eH(g,a),t=a.filter(e=>e.kind===`image`).map(e=>({data:e.data,mimeType:e.mimeType})),n=a.every(e=>e.kind===`path`);(g.trim()||!n&&e||t.length!==0)&&(u(e,t.length>0?t:void 0),_(``),p())}function le(e){let t=`/${e.name} `;_(t),ee.current=t.length,b(t.length)}function ue(e){if(!A)return;let t=g.slice(0,A.start),n=g.slice(y),r=`@${e.path}${lH(e.type)?`/`:` `}`,i=`${t}${r}${n}`;_(i),p();let a=t.length+r.length;ee.current=a,b(a)}function de(){if(re){if(re.kind===`command`){let e=re.items[x];e&&le(e)}else{let e=re.items[x];e&&ue(e)}}}function fe(e){if(j&&re){if(e.key===`ArrowDown`){e.preventDefault(),S(e=>(e+1)%re.items.length);return}if(e.key===`ArrowUp`){e.preventDefault(),S(e=>(e-1+re.items.length)%re.items.length);return}if(e.key===`Tab`||e.key===`Enter`){e.preventDefault(),de();return}if(e.key===`Escape`){e.preventDefault(),w(!0);return}}e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),ce())}function M(e){b(e.currentTarget.selectionStart??0)}function pe(e){let t=Array.from(e.clipboardData.files);t.length>0&&(e.preventDefault(),s(t))}return(0,N.jsxs)(`div`,{ref:T,className:`relative`,children:[(a.length>0||ae)&&(0,N.jsxs)(`div`,{className:`mb-2 flex flex-wrap gap-2`,children:[o.map(e=>(0,N.jsxs)(`span`,{"data-pending-upload":e.name,title:`${e.name} — copying into the workspace`,className:`flex items-center gap-1.5 rounded-md border border-dashed border-zinc-300 bg-zinc-50 py-1 pl-1.5 pr-2 text-xs text-zinc-500 dark:border-zinc-600 dark:bg-zinc-800/40 dark:text-zinc-400`,children:[(0,N.jsx)(`span`,{"aria-hidden":!0,className:`animate-pulse`,children:`⏳`}),(0,N.jsx)(`span`,{className:`max-w-40 truncate`,children:e.name}),(0,N.jsx)(`span`,{className:`sr-only`,children:`uploading`})]},e.id)),oe&&(0,N.jsx)(`span`,{role:`status`,className:`flex items-center py-1 text-xs text-amber-600 dark:text-amber-400`,children:`waiting for the attachment to finish uploading…`}),a.map((e,t)=>(0,N.jsxs)(`span`,{title:e.kind===`path`?`${e.name} — sent as a reference; the agent reads the file itself`:e.name,className:`flex items-center gap-1.5 rounded-md border border-zinc-200 bg-zinc-50 py-1 pl-1.5 pr-1 text-xs text-zinc-600 dark:border-zinc-700 dark:bg-zinc-800/60 dark:text-zinc-300`,children:[e.kind===`image`?(0,N.jsx)(`img`,{src:`data:${e.mimeType};base64,${e.data}`,alt:e.name,className:`h-8 w-8 rounded object-cover`}):(0,N.jsx)(`span`,{"aria-hidden":!0,className:e.kind===`path`?`font-mono font-bold text-blue-600 dark:text-blue-400`:``,children:e.kind===`path`?`@`:`📄`}),(0,N.jsx)(`span`,{className:`max-w-40 truncate`,children:e.name}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>l(t),title:`remove attachment`,className:`rounded px-1 text-zinc-400 hover:bg-zinc-200 hover:text-zinc-700 dark:hover:bg-zinc-700 dark:hover:text-zinc-200`,children:`✕`})]},`${e.name}:${t}`))]}),j&&re&&(0,N.jsx)(`div`,{ref:E,className:`absolute bottom-full left-0 z-20 mb-2 max-h-72 w-full max-w-xl overflow-y-auto rounded-lg border border-zinc-200 bg-white py-1 shadow-xl dark:border-zinc-700 dark:bg-zinc-900`,children:re.kind===`command`?re.items.map((e,t)=>(0,N.jsxs)(`button`,{type:`button`,"data-selected":t===x,onMouseEnter:()=>S(t),onClick:()=>le(e),className:`flex w-full items-baseline gap-2 px-3 py-1.5 text-left text-sm ${t===x?`bg-zinc-100 dark:bg-zinc-800`:``}`,children:[(0,N.jsxs)(`span`,{className:`font-mono text-zinc-800 dark:text-zinc-200`,children:[`/`,e.name]}),e.argumentHint&&(0,N.jsx)(`span`,{className:`font-mono text-xs text-zinc-500`,children:e.argumentHint}),e.description&&(0,N.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-xs text-zinc-500`,children:e.description}),(0,N.jsx)(`span`,{className:`ml-auto shrink-0 rounded bg-zinc-200 px-1 text-[10px] uppercase text-zinc-500 dark:bg-zinc-800`,children:cH[e.source]})]},e.name)):re.items.map((e,t)=>(0,N.jsx)(`button`,{type:`button`,"data-selected":t===x,onMouseEnter:()=>S(t),onClick:()=>ue(e),className:`flex w-full items-baseline gap-2 px-3 py-1.5 text-left text-sm ${t===x?`bg-zinc-100 dark:bg-zinc-800`:``}`,children:(0,N.jsxs)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-zinc-800 dark:text-zinc-200`,children:[e.path,lH(e.type)?`/`:``]})},e.path))}),(0,N.jsxs)(`div`,{className:`flex items-end gap-2 rounded-xl border border-zinc-200 bg-zinc-50 p-2 focus-within:border-zinc-400 dark:border-zinc-800 dark:bg-zinc-900 dark:focus-within:border-zinc-600`,children:[(0,N.jsx)(`textarea`,{ref:D,value:g,onChange:e=>{_(e.target.value),b(e.target.selectionStart??e.target.value.length)},onKeyDown:fe,onClick:M,onKeyUp:M,onPaste:pe,placeholder:t?e?`steer the agent… (Enter to send)`:`message pi… (/ for commands, @ for files, Enter to send, Shift+Enter for newline)`:`connecting…`,disabled:!t,rows:1,className:`max-h-[min(40vh,20rem)] flex-1 resize-none overflow-y-hidden bg-transparent px-2 py-1.5 text-[15px] outline-none placeholder:text-zinc-400 disabled:opacity-50 dark:placeholder:text-zinc-600`}),e&&(0,N.jsx)(`button`,{type:`button`,onClick:d,title:`stop`,"aria-label":`Stop the agent`,className:`rounded-lg bg-red-100 p-2 text-red-700 hover:bg-red-200 dark:bg-red-900/60 dark:text-red-200 dark:hover:bg-red-900`,children:(0,N.jsx)(`svg`,{viewBox:`0 0 24 24`,fill:`currentColor`,"aria-hidden":!0,className:`h-4 w-4`,children:(0,N.jsx)(`rect`,{x:`6`,y:`6`,width:`12`,height:`12`,rx:`2`})})}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>O.current?.click(),disabled:!t,title:`attach files`,"aria-label":`Attach files`,className:`rounded-lg p-2 text-zinc-500 hover:bg-zinc-200 hover:text-zinc-700 disabled:opacity-30 dark:text-zinc-400 dark:hover:bg-zinc-800 dark:hover:text-zinc-200`,children:(0,N.jsx)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:1.8,"aria-hidden":!0,className:`h-4 w-4`,children:(0,N.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`m21.44 11.05-9.19 9.19a6 6 0 0 1-8.49-8.49l8.57-8.57A4 4 0 1 1 18 8.84l-8.59 8.57a2 2 0 0 1-2.83-2.83l8.49-8.48`})})}),(0,N.jsx)(`input`,{ref:O,type:`file`,multiple:!0,hidden:!0,onChange:e=>{e.target.files?.length&&s(Array.from(e.target.files)),e.target.value=``}}),(0,N.jsx)(`button`,{type:`button`,onClick:ce,disabled:!t||ae||!g.trim()&&a.length===0,title:ae?`waiting for an attachment to finish uploading`:e?`steer`:`send`,"aria-label":e?`Steer the agent`:`Send message`,className:`rounded-lg bg-zinc-900 p-2 text-zinc-100 hover:bg-zinc-800 disabled:opacity-30 dark:bg-zinc-100 dark:text-zinc-900 dark:hover:bg-white`,children:e?(0,N.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:1.8,"aria-hidden":!0,className:`h-4 w-4`,children:[(0,N.jsx)(`circle`,{cx:`6`,cy:`19`,r:`3`}),(0,N.jsx)(`path`,{strokeLinecap:`round`,d:`M9 19h8.5a3.5 3.5 0 0 0 0-7h-11a3.5 3.5 0 0 1 0-7H15`}),(0,N.jsx)(`circle`,{cx:`18`,cy:`5`,r:`3`})]}):(0,N.jsx)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:1.8,"aria-hidden":!0,className:`h-4 w-4`,children:(0,N.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M6 12 3.27 3.13c6.6 1.9 12.83 4.9 18.43 8.87-5.6 3.97-11.83 6.97-18.43 8.87L6 12Zm0 0h7.5`})})})]})]})}var fH=`rounded-md border px-3 py-1.5 text-sm border-zinc-200 hover:bg-zinc-100 dark:border-zinc-800 dark:hover:bg-zinc-800`,pH=`rounded-md bg-zinc-900 px-3 py-1.5 text-sm text-zinc-100 hover:bg-zinc-800 dark:bg-zinc-100 dark:text-zinc-900 dark:hover:bg-white`,mH=`w-full rounded-md border border-zinc-300 bg-white px-2 py-1.5 text-sm outline-none focus:border-zinc-500 dark:border-zinc-700 dark:bg-zinc-950 dark:focus:border-zinc-500`,hH=`mb-4 ${mH}`,gH=`1,3`,_H=` — `;function vH(e){let t=e.indexOf(`
838
- `);return t===-1?{heading:e,body:``}:{heading:e.slice(0,t),body:e.slice(t+1).trim()}}function yH(e){let t=/^(\d+)\.\s+(\S[\s\S]*)$/.exec(e.trim());if(!t)return null;let n=t[2],r=n.indexOf(_H);return{index:Number(t[1]),label:r===-1?n:n.slice(0,r),description:r===-1?``:n.slice(r+3)}}function bH(e){if(e.method!==`input`||e.placeholder!==gH)return null;let{heading:t,body:n}=vH(e.title),r=[];for(let e of n.split(`
839
- `)){let t=yH(e);t&&r.push(t)}return r.length<2||r.some((e,t)=>e.index!==t+1)?null:{heading:t,options:r}}function xH({request:e,onRespond:t}){let[n,r]=(0,v.useState)(e.method===`editor`?e.prefill??``:``),[i,a]=(0,v.useState)([]),[o,s]=(0,v.useState)(!1),c=(e.method===`select`||e.method===`confirm`||e.method===`input`)&&e.timeout,[l,u]=(0,v.useState)(c?Math.ceil(c/1e3):null),d=bH(e),{heading:f,body:p}=vH(e.title);function m(){t({id:e.id,cancelled:!0})}function h(e){a(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e].sort((e,t)=>e-t))}function g(){let r=n.trim();t({id:e.id,value:r.length>0?r:i.join(`,`)})}return(0,v.useEffect)(()=>{if(!o)return;let e=setTimeout(()=>s(!1),400);return()=>clearTimeout(e)},[o]),(0,v.useEffect)(()=>{if(l===null)return;if(l<=0){t({id:e.id,cancelled:!0});return}let n=setTimeout(()=>u(e=>e===null?null:e-1),1e3);return()=>clearTimeout(n)},[l,e.id,t]),(0,N.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4`,onClick:()=>s(!0),children:(0,N.jsxs)(`div`,{className:`w-full ${p?`max-w-2xl`:`max-w-md`} rounded-xl border bg-white p-4 shadow-2xl transition-shadow dark:bg-zinc-900 ${o?`border-zinc-400 ring-2 ring-zinc-400/60 dark:border-zinc-500 dark:ring-zinc-500/60`:`border-zinc-200 dark:border-zinc-700`}`,onClick:e=>e.stopPropagation(),children:[(0,N.jsxs)(`div`,{className:`mb-3 flex items-start gap-3`,children:[(0,N.jsx)(`h2`,{className:`flex-1 text-sm font-semibold text-zinc-900 dark:text-zinc-100`,children:f}),(0,N.jsx)(`button`,{type:`button`,onClick:m,"aria-label":`Refuse to answer`,title:`Refuse to answer`,className:`-mr-1 -mt-1 rounded-md px-1.5 py-0.5 text-sm leading-none text-zinc-400 hover:bg-zinc-100 hover:text-zinc-700 dark:text-zinc-500 dark:hover:bg-zinc-800 dark:hover:text-zinc-200`,children:`✕`})]}),p&&!d&&(0,N.jsx)(`pre`,{className:`mb-3 max-h-72 overflow-auto whitespace-pre-wrap break-words rounded-md bg-zinc-50 p-2 font-mono text-xs text-zinc-600 dark:bg-zinc-950 dark:text-zinc-400`,children:p}),e.method===`select`&&(0,N.jsx)(`div`,{className:`mb-1 flex flex-col gap-1`,children:e.options.map(n=>{let r=yH(n);return(0,N.jsx)(`button`,{type:`button`,onClick:()=>t({id:e.id,value:n}),className:`text-left ${fH}`,children:r?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`span`,{className:`font-medium text-zinc-900 dark:text-zinc-100`,children:r.label}),r.description&&(0,N.jsx)(`span`,{className:`mt-0.5 block text-xs text-zinc-500 dark:text-zinc-400`,children:r.description})]}):n},n)})}),e.method===`confirm`&&(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`p`,{className:`mb-4 text-sm text-zinc-600 dark:text-zinc-400`,children:e.message}),(0,N.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,N.jsx)(`button`,{type:`button`,onClick:()=>t({id:e.id,confirmed:!1}),className:fH,children:`No`}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>t({id:e.id,confirmed:!0}),className:pH,children:`Yes`})]})]}),d&&(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`div`,{className:`mb-3 flex flex-col gap-1`,children:d.options.map(e=>(0,N.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 rounded-md px-2 py-1.5 text-sm hover:bg-zinc-100 dark:hover:bg-zinc-800`,children:[(0,N.jsx)(`input`,{type:`checkbox`,checked:i.includes(e.index),onChange:()=>h(e.index),className:`mt-0.5`}),(0,N.jsxs)(`span`,{children:[(0,N.jsx)(`span`,{className:`font-medium text-zinc-900 dark:text-zinc-100`,children:e.label}),e.description&&(0,N.jsx)(`span`,{className:`mt-0.5 block text-xs text-zinc-500 dark:text-zinc-400`,children:e.description})]})]},e.index))}),(0,N.jsx)(`input`,{value:n,onChange:e=>r(e.target.value),placeholder:`…or type your own answer`,onKeyDown:e=>{e.key===`Enter`&&g(),e.key===`Escape`&&m()},className:`mb-1 ${mH}`}),(0,N.jsx)(`p`,{className:`mb-4 text-xs text-zinc-400 dark:text-zinc-600`,children:`A typed answer replaces the selection above.`}),(0,N.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,N.jsx)(`button`,{type:`button`,onClick:m,className:fH,children:`Cancel`}),(0,N.jsx)(`button`,{type:`button`,onClick:g,className:pH,children:`OK`})]})]}),e.method===`input`&&!d&&(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`input`,{autoFocus:!0,value:n,onChange:e=>r(e.target.value),placeholder:e.placeholder,onKeyDown:r=>{r.key===`Enter`&&t({id:e.id,value:n}),r.key===`Escape`&&m()},className:hH}),(0,N.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,N.jsx)(`button`,{type:`button`,onClick:m,className:fH,children:`Cancel`}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>t({id:e.id,value:n}),className:pH,children:`OK`})]})]}),e.method===`editor`&&(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`textarea`,{autoFocus:!0,value:n,onChange:e=>r(e.target.value),rows:8,onKeyDown:e=>{e.key===`Escape`&&m()},className:`resize-none font-mono ${hH}`}),(0,N.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,N.jsx)(`button`,{type:`button`,onClick:m,className:fH,children:`Cancel`}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>t({id:e.id,value:n}),className:pH,children:`OK`})]})]}),l!==null&&(0,N.jsxs)(`p`,{className:`mt-3 text-right text-xs text-zinc-400 dark:text-zinc-600`,children:[`auto-dismiss in `,l,`s`]})]})})}var SH=`rounded-md border px-3 py-1.5 text-sm border-zinc-200 hover:bg-zinc-100 disabled:opacity-50 dark:border-zinc-800 dark:hover:bg-zinc-800`,CH=`rounded-md bg-zinc-900 px-3 py-1.5 text-sm text-zinc-100 hover:bg-zinc-800 disabled:opacity-50 dark:bg-zinc-100 dark:text-zinc-900 dark:hover:bg-white`,wH=e=>new Date(e).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`});function TH({request:e,onRespond:t}){let[n,r]=(0,v.useState)(null),[i,a]=(0,v.useState)(!1);(0,v.useEffect)(()=>{if(!i)return;let e=setTimeout(()=>a(!1),400);return()=>clearTimeout(e)},[i]),(0,v.useEffect)(()=>r(null),[e.id]);function o(i){n||(r(i),t(e.id,i))}let{hosts:s,directories:c}=e.grant,l=e.kind===`connection`;return(0,N.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4`,onClick:()=>a(!0),children:(0,N.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-labelledby":`sandbox-grant-title`,"data-testid":`sandbox-grant-dialog`,"data-request-id":e.id,className:`w-full max-w-2xl rounded-xl border bg-white p-4 shadow-2xl transition-shadow dark:bg-zinc-900 ${i?`border-zinc-400 ring-2 ring-zinc-400/60 dark:border-zinc-500 dark:ring-zinc-500/60`:`border-zinc-200 dark:border-zinc-700`}`,onClick:e=>e.stopPropagation(),children:[(0,N.jsx)(`h2`,{id:`sandbox-grant-title`,className:`mb-3 text-sm font-semibold text-zinc-900 dark:text-zinc-100`,children:l?`A running command is connecting to ${s.join(`, `)}`:`The agent asks to run a command beyond its sandbox`}),(0,N.jsx)(`div`,{className:`mb-1 text-xs font-medium text-zinc-500 dark:text-zinc-400`,children:l?`The running command`:`Command`}),(0,N.jsx)(`pre`,{"data-testid":`sandbox-grant-command`,className:`mb-3 max-h-48 overflow-auto whitespace-pre-wrap break-all rounded-md bg-zinc-50 p-2 font-mono text-xs text-zinc-800 dark:bg-zinc-950 dark:text-zinc-200`,children:e.command}),(0,N.jsx)(`div`,{className:`mb-1 text-xs font-medium text-zinc-500 dark:text-zinc-400`,children:l?`It is waiting to reach`:`It would also reach`}),(0,N.jsxs)(`ul`,{"data-testid":`sandbox-grant-targets`,className:`mb-3 list-disc pl-5 text-sm text-zinc-800 dark:text-zinc-200`,children:[s.map(e=>(0,N.jsxs)(`li`,{children:[`host `,(0,N.jsx)(`code`,{className:`font-mono`,children:e})]},`host:${e}`)),c.map(e=>(0,N.jsxs)(`li`,{children:[e.access===`write`?`read and write`:`read`,` `,(0,N.jsx)(`code`,{className:`break-all font-mono`,children:e.path})]},`dir:${e.path}`))]}),e.overridesReadOnly&&(0,N.jsx)(`p`,{"data-testid":`sandbox-grant-overrides`,className:`mb-3 rounded-md bg-amber-50 p-2 text-xs text-amber-800 dark:bg-amber-900/40 dark:text-amber-200`,children:`Writing is off in this project's sandbox: allowing this lets the command write there anyway.`}),l?(0,N.jsx)(`p`,{"data-testid":`sandbox-grant-reason`,className:`mb-4 text-sm text-zinc-600 dark:text-zinc-400`,children:`Not in this sandbox's allowed hosts. The agent did not ask for it: the command connected, and waits for your answer.`}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`div`,{className:`mb-1 text-xs font-medium text-zinc-500 dark:text-zinc-400`,children:`The agent says`}),(0,N.jsx)(`blockquote`,{"data-testid":`sandbox-grant-reason`,className:`mb-4 border-l-2 border-zinc-300 pl-2 text-sm italic text-zinc-600 dark:border-zinc-700 dark:text-zinc-400`,children:e.reason})]}),(0,N.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[(0,N.jsxs)(`span`,{className:`mr-auto text-xs text-zinc-500 dark:text-zinc-400`,children:[`Refused if unanswered by `,wH(e.expiresAt)]}),(0,N.jsx)(`button`,{type:`button`,className:SH,disabled:n!==null,onClick:()=>o(`refuse`),children:`Refuse`}),(0,N.jsx)(`button`,{type:`button`,className:SH,disabled:n!==null,onClick:()=>o(`session`),children:`Allow for this session`}),(0,N.jsx)(`button`,{type:`button`,className:CH,disabled:n!==null,onClick:()=>o(`once`),children:l?`Allow for this command`:`Allow once`})]})]})})}var EH={info:`border-blue-300 bg-blue-50 text-blue-800 dark:border-blue-900 dark:bg-blue-950/60 dark:text-blue-200`,warning:`border-amber-300 bg-amber-50 text-amber-800 dark:border-amber-900 dark:bg-amber-950/60 dark:text-amber-200`,error:`border-red-300 bg-red-50 text-red-800 dark:border-red-900 dark:bg-red-950/60 dark:text-red-200`},DH=6e3;function OH({notification:e,onDismiss:t}){let n=(0,v.useRef)(t);return(0,v.useEffect)(()=>{n.current=t}),(0,v.useEffect)(()=>{let e=setTimeout(()=>n.current(),DH);return()=>clearTimeout(e)},[e.id]),(0,N.jsxs)(`div`,{role:`status`,className:`flex items-start gap-2 rounded-lg border px-3 py-2 text-sm shadow-lg ${EH[e.notifyType??`info`]}`,children:[(0,N.jsx)(`span`,{className:`min-w-0 flex-1 break-words`,children:e.message}),(0,N.jsx)(`button`,{type:`button`,"aria-label":`Dismiss notification`,onClick:()=>n.current(),className:`-mr-1 shrink-0 rounded px-1 leading-5 opacity-60 transition-opacity hover:opacity-100 focus-visible:opacity-100`,children:`×`})]})}function kH({notifications:e,onDismiss:t}){return e.length===0?null:(0,N.jsx)(`div`,{className:`fixed right-4 top-16 z-40 flex w-80 flex-col gap-2`,children:e.map(e=>(0,N.jsx)(OH,{notification:e,onDismiss:()=>t(e.id)},e.id))})}var AH={30:`#3f3f46`,31:`#dc2626`,32:`#16a34a`,33:`#ca8a04`,34:`#2563eb`,35:`#9333ea`,36:`#0891b2`,37:`#71717a`,90:`#a1a1aa`,91:`#ef4444`,92:`#22c55e`,93:`#eab308`,94:`#3b82f6`,95:`#a855f7`,96:`#06b6d4`,97:`#d4d4d8`};function jH(e){if(!Number.isInteger(e)||e<0||e>255)return;if(e<16)return AH[e<8?30+e:90+e-8];if(e>=232){let t=8+(e-232)*10;return`rgb(${t} ${t} ${t})`}let t=e-16,n=e=>e===0?0:55+e*40;return`rgb(${n(Math.floor(t/36))} ${n(Math.floor(t/6)%6)} ${n(t%6)})`}var MH=/\u001B\[[0-9;:]*[A-Za-z]|\u001B[()][A-Za-z0-9]|\u001B[A-Za-z]/g;function NH(e,t){let n={...e};for(let e=0;e<t.length;e++){let r=t[e];if(r===0)for(let e of Object.keys(n))delete n[e];else if(r===1)n.bold=!0;else if(r===2)n.dim=!0;else if(r===3)n.italic=!0;else if(r===4)n.underline=!0;else if(r===22)delete n.bold,delete n.dim;else if(r===23)delete n.italic;else if(r===24)delete n.underline;else if(r===39)delete n.color;else if(AH[r]!==void 0)n.color=AH[r];else if(r===38){if(t[e+1]===2){let[r,i,a]=[t[e+2],t[e+3],t[e+4]];[r,i,a].every(e=>Number.isFinite(e))&&(n.color=`rgb(${r} ${i} ${a})`),e+=4}else if(t[e+1]===5){let r=jH(t[e+2]);r!==void 0&&(n.color=r),e+=2}}}return n}function PH(e){let t=[],n={},r=0;MH.lastIndex=0;for(let i=MH.exec(e);i!==null;i=MH.exec(e)){i.index>r&&t.push({text:e.slice(r,i.index),...n}),r=i.index+i[0].length;let a=i[0];if(a.endsWith(`m`)){let e=a.slice(2,-1),t=e===``?[0]:e.split(/[;:]/).map(e=>e===``?0:Number(e));n=NH(n,t)}}return r<e.length&&t.push({text:e.slice(r),...n}),t}function FH(e){return e.replace(MH,``)}function IH({text:e}){let t=PH(e);return(0,N.jsx)(N.Fragment,{children:t.map((e,t)=>(0,N.jsx)(`span`,{style:{...e.color?{color:e.color}:{},...e.bold?{fontWeight:600}:{},...e.dim?{opacity:.7}:{},...e.italic?{fontStyle:`italic`}:{},...e.underline?{textDecoration:`underline`}:{}},children:e.text},t))})}function LH({widgets:e,placement:t,controls:n={}}){let r=Object.entries(e).filter(([,e])=>e.placement===t);return r.length===0?null:(0,N.jsx)(`div`,{className:`mb-2 flex flex-col gap-1`,children:r.map(([e,t])=>(0,N.jsx)(zH,{name:e,lines:t.lines,control:n[e]??{}},e))})}function RH({text:e}){return(0,N.jsx)(`div`,{className:`min-h-4`,children:(0,N.jsx)(IH,{text:e})})}function zH({name:e,lines:t,control:n}){let r=(0,v.useRef)(null),i=t.slice(0,n.pinnedLines??0),a=t.slice(i.length),o=n.anchor?n.anchor(t)-i.length:-1;return(0,v.useLayoutEffect)(()=>{let e=r.current,t=o>=0?e?.children[o]:void 0;e&&t&&(e.scrollTop=t.offsetTop)},[t,o]),(0,N.jsxs)(`div`,{"data-widget":e,className:`flex items-start gap-2 rounded-md border border-zinc-200 bg-zinc-50 px-3 py-1.5 font-mono text-xs text-zinc-600 dark:border-zinc-800 dark:bg-zinc-900 dark:text-zinc-400`,children:[(0,N.jsxs)(`div`,{className:`min-w-0 flex-1 whitespace-pre-wrap`,children:[i.map((e,t)=>(0,N.jsx)(RH,{text:e},t)),(0,N.jsx)(`div`,{ref:r,tabIndex:0,"aria-label":n.region??`Extension widget ${e}`,className:`relative max-h-[20vh] overflow-y-auto rounded-sm focus:outline-none focus-visible:ring-1 focus-visible:ring-zinc-400`,children:a.map((e,t)=>(0,N.jsx)(RH,{text:e},t))})]}),n.close&&(0,N.jsx)(`button`,{type:`button`,"aria-label":n.close.label,title:n.close.label,onClick:n.close.run,className:`-mr-1 shrink-0 rounded px-1 font-sans text-sm leading-5 opacity-60 transition-opacity hover:opacity-100 focus-visible:opacity-100`,children:`×`})]})}var BH=null,VH=null;function HH(){return VH??=ye(()=>import(`./CodeEditor-DW06InQx.js`).then(e=>e.t).then(e=>BH=e,e=>{throw VH=null,e}),__vite__mapDeps([22,1,23])),VH}var UH=(0,v.lazy)(()=>{if(BH!==null){let e=BH;return{then:t=>t({default:e.CodeEditor})}}return HH().then(e=>({default:e.CodeEditor}))});function WH({text:e,path:t,serverUrl:n,token:r,workspace:i,template:a}){let[o,s]=(0,v.useState)(`idle`),[c,l]=(0,v.useState)(`plain`),[u,d]=(0,v.useState)(null),f=(0,v.useRef)(!1),p=(0,v.useRef)({plain:0,template:0});async function m(a){if(!(f.current||Date.now()-p.current[a]<750)){f.current=!0,p.current[a]=Date.now(),l(a),s(`working`),d(null);try{let{downloadDocx:o,downloadDocxInTemplate:c}=await ye(async()=>{let{downloadDocx:e,downloadDocxInTemplate:t}=await import(`./docxExport-1eYht7KT.js`);return{downloadDocx:e,downloadDocxInTemplate:t}},__vite__mapDeps([24,21,1,25])),l=typeof e==`function`?e():e;await(a===`template`?c:o)(l,t,{serverUrl:n,token:r,workspace:i}),s(`idle`)}catch(e){s(`failed`),d(e instanceof Error?e.message:String(e))}finally{f.current=!1}}}let h=`shrink-0 rounded px-1.5 py-0.5 text-xs text-zinc-400 hover:bg-zinc-100 hover:text-zinc-700 disabled:opacity-50 dark:text-zinc-600 dark:hover:bg-zinc-800 dark:hover:text-zinc-300`,g=(e,t)=>o===`working`&&c===e?`… exporting`:o===`failed`&&c===e?`⚠ export failed`:t,_=(e,t)=>o===`failed`&&c===e?`Could not export: ${u??`unknown reason`}`:t;return(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`button`,{type:`button`,onClick:()=>void m(`plain`),disabled:o===`working`,title:_(`plain`,`Download as a Word document`),"aria-label":`Download as a Word document`,className:h,children:g(`plain`,`⤓ word`)}),a!==void 0&&(0,N.jsx)(`button`,{type:`button`,onClick:()=>void m(`template`),disabled:o===`working`,title:_(`template`,`Download as a Word document in the template ${a}`),"aria-label":`Download as a Word document in the template ${a}`,className:h,children:g(`template`,`⤓ word · template`)})]})}var GH=3e4,KH=(0,v.forwardRef)(function({serverUrl:e},t){let[n,r]=(0,v.useState)(null),i=(0,v.useRef)(null),a=(0,v.useRef)(Promise.resolve()),o=(0,v.useRef)(null),s=(0,v.useRef)(0);function c(e,t){let n=i.current;n!==null&&n.id===e&&(clearTimeout(n.timer),i.current=null,r(null),t instanceof Error?n.reject(t):n.resolve(t))}if((0,v.useImperativeHandle)(t,()=>({draw(e){let t=()=>new Promise((t,n)=>{let a=++s.current,o=setTimeout(()=>c(a,Error(`the draw.io viewer did not answer`)),GH);i.current={id:a,resolve:t,reject:n,timer:o},r({id:a,xml:e})}),n=a.current.then(t,t);return a.current=n.catch(()=>void 0),n}}),[]),(0,v.useEffect)(()=>()=>{let e=i.current;e!==null&&(clearTimeout(e.timer),i.current=null,e.reject(Error(`the poster was closed`)))},[]),n===null)return null;let{id:l}=n;return(0,N.jsx)(`div`,{"aria-hidden":`true`,"data-testid":`drawio-painter`,style:{position:`fixed`,left:-2e4,top:0,width:1200,height:900,pointerEvents:`none`},children:(0,N.jsx)(Km,{ref:o,xml:n.xml,serverUrl:e,title:`draw.io diagram for a poster`,className:`flex h-full flex-col`,onRendered:e=>{if(e!==null)return c(l,Error(e));o.current?.exportSvg().then(({svg:e})=>c(l,e),e=>c(l,e instanceof Error?e:Error(String(e))))}},l)})});function qH(e,t=window.location.href){return new URL(`${e}/${l}`,t).href}var JH=`allow-scripts allow-same-origin`,YH=`Discard the unsaved touch-ups to this diagram?`;function XH(e,t,n){let r=URL.createObjectURL(new Blob([t],{type:n}));try{let t=document.createElement(`a`);t.href=r,t.download=e,t.click()}finally{URL.revokeObjectURL(r)}}function ZH({path:i,content:a,mtimeMs:s,writable:l,loadFile:u,fallback:d,onTouchUpDirtyChange:f}){let{serverUrl:p,fileIo:m,onOpenNative:h}=Fm(),g=x()===`dark`,_=(0,v.useRef)(null),y=(0,v.useRef)(null),b=(0,v.useMemo)(()=>qH(p),[p]),S=(0,v.useMemo)(()=>{try{return{page:r(a)}}catch(e){return{problem:e instanceof Error?e.message:String(e)}}},[a]),C=(0,v.useRef)(null),w=(0,v.useRef)(null),T=(0,v.useRef)(!1),E=(0,v.useRef)(null),D=(0,v.useRef)(()=>{}),[O,ee]=(0,v.useState)(!l||m===void 0),te=(0,v.useRef)(!1),k=(0,v.useRef)(f);k.current=f;let ne=(0,v.useRef)({path:i,content:a,mtimeMs:s,dark:g,readOnly:O,poster:S,loadFile:u});ne.current={path:i,content:a,mtimeMs:s,dark:g,readOnly:O,poster:S,loadFile:u};let[A,re]=(0,v.useState)(null),j=(0,v.useRef)(A);j.current=A;let ie=(0,v.useRef)(!1),ae=(0,v.useRef)(()=>{});(0,v.useEffect)(()=>{let r=!0,i=new URL(b).origin,a=e=>_.current?.contentWindow?.postMessage(e,i),s=(e,t)=>{r&&a({type:o.ANSWER,id:e,value:t})};ae.current=s;let u=0;async function d(){let e=++u,{path:t,content:n,mtimeMs:i,poster:s,dark:c}=ne.current;if(!(`page`in s))return;let d=l&&m!==void 0;if(d)try{await m.read(t)}catch{d=!1}r&&e===u&&(C.current=d?{mtimeMs:i}:null,w.current=n,ee(!d),a({type:o.OPEN,poster:{...s.page,revision:0,readOnly:!d},theme:c?`dark`:`light`}))}D.current=()=>{te.current&&!T.current&&ne.current.content!==E.current&&(E.current=null,ne.current.content===w.current?C.current!==null&&(C.current={mtimeMs:ne.current.mtimeMs}):d())};async function f(e,t,r){let{path:i,poster:a}=ne.current;if(!(`page`in a)||m===void 0||C.current===null||ne.current.readOnly)s(e,{saved:!1,message:`this file cannot be saved here`});else try{let o=n(a.page.title,{html:t,css:r,format:a.page.format}),{mtimeMs:c}=await m.write(i,o,C.current.mtimeMs);C.current={mtimeMs:c},ne.current.content!==o&&(E.current=ne.current.content),w.current=o,s(e,{saved:!0,revision:0,message:`Saved. The agent reads this version.`})}catch(t){let n=t instanceof wz&&t.reason===`conflict`;s(e,{saved:!1,message:n?`the file changed on disk since it was opened, so it was not saved. Close and reopen it to see what is there now.`:t instanceof Error?t.message:String(t)})}}async function p(e,t){let n;try{n={ok:!0,value:await t()}}catch(e){n={ok:!1,message:e instanceof Error?e.message:String(e)}}s(e,n)}async function h(){if(m?.find===void 0)throw Error(`this view cannot look through the project's files`);let e=new Set;for(let t of[`.drawio`,`.dio`])for(let n of await m.find(t))n.type===`file`&&ce(n.path)&&e.add(n.path);let t=ne.current.path;return Promise.all([...e].map(async e=>{let n=[];try{n=Mz((await m.read(e)).content)}catch{}return{path:Fz(t,e),pages:n}}))}async function g(e,t){let n=oe(ne.current.path,e);if(!ce(n))throw Error(`"${e}" is not a .drawio file`);if(m===void 0)throw Error(`this view cannot read the project's files`);let r;try{r=(await m.read(n)).content}catch(t){throw Error(`"${e}" could not be read: ${t instanceof Error?t.message:String(t)}`)}let i=Pz(r,t);if(y.current===null)throw Error(`the poster was closed`);return y.current.draw(i)}async function v(e,t,n){let i=t=>s(e,{ok:!1,message:t});if(j.current!==null)return i(`another diagram is open for touch-up`);let a=oe(ne.current.path,t);if(!ce(a))return i(`"${t}" is not a .drawio file`);if(m===void 0)return i(`this view cannot read the project's files`);let o;try{o=(await m.read(a)).content,Mz(o)}catch(e){return i(`"${t}" could not be opened: ${e instanceof Error?e.message:String(e)}`)}r&&(ie.current=!1,re({file:a,page:n,id:e,before:o}))}async function x(){if(m?.find===void 0)throw Error(`this view cannot look through the project's files`);let e=new Set;for(let n of Object.keys(c))for(let r of await m.find(n))r.type===`file`&&t(r.path)!==void 0&&e.add(r.path);let n=ne.current.path;return[...e].map(e=>Fz(n,e))}async function S(n){let r=oe(ne.current.path,n),i=t(r);if(i===void 0)throw Error(`"${n}" is not a picture file (SVG, PNG, JPEG, GIF or WebP)`);let a=ne.current.loadFile;if(a===void 0)throw Error(`this view cannot read the project's files`);let o=await a(r);if(o===void 0)throw Error(`"${n}" could not be read: it is not there, or not in the project`);if(o.size>20971520)throw Error(`"${n}" is ${Math.round(o.size/1024/1024)} MB, more than a poster reads (${e/1024/1024} MB)`);return{type:i,bytes:new Uint8Array(await o.arrayBuffer())}}function O(e){if(_.current===null||e.source!==_.current.contentWindow||e.origin!==i)return;let t=e.data;if(typeof t==`object`&&t){if(t.type===o.READY)te.current=!0,d();else if(t.type===o.DIRTY)T.current=t.dirty===!0,k.current?.(T.current),D.current();else if(t.type===o.SAVE&&typeof t.html==`string`&&typeof t.css==`string`)f(t.id,t.html,t.css);else if(t.type===o.DELIVER&&typeof t.name==`string`&&typeof t.mediaType==`string`&&t.bytes instanceof Uint8Array)XH(t.name,t.bytes,t.mediaType),s(t.id,`Downloaded "${t.name}".`);else if(t.type===o.DRAWIO_LIST)p(t.id,h);else if(t.type===o.DRAWIO_DRAW){let{path:e,page:n}=t;typeof e==`string`&&p(t.id,()=>g(e,typeof n==`string`?n:void 0))}else if(t.type===o.DRAWIO_EDIT){let{path:e,page:n}=t;typeof e==`string`&&v(t.id,e,typeof n==`string`?n:void 0)}else if(t.type===o.PICTURE_LIST)p(t.id,x);else if(t.type===o.PICTURE_READ){let{path:e}=t;typeof e==`string`&&p(t.id,()=>S(e))}}}return window.addEventListener(`message`,O),()=>{r=!1,te.current=!1,re(null),D.current=()=>{},k.current?.(!1),window.removeEventListener(`message`,O)}},[b,m,l]),(0,v.useEffect)(()=>D.current(),[a,s]),(0,v.useEffect)(()=>{te.current&&_.current?.contentWindow?.postMessage({type:o.THEME,theme:g?`dark`:`light`},new URL(b).origin)},[g,b]);async function se(){let e=j.current;if(e===null||ie.current&&!window.confirm(YH))return;re(null);let t;try{t={ok:!0,value:(await m.read(e.file)).content!==e.before}}catch(e){t={ok:!1,message:`the diagram could not be read again: ${e instanceof Error?e.message:String(e)}`}}ae.current(e.id,t)}let le=(0,v.useRef)(null);(0,v.useEffect)(()=>{if(A===null)return;le.current?.focus();function e(e){e.key!==`Escape`||e.defaultPrevented||(e.preventDefault(),e.stopImmediatePropagation(),ue.current())}return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[A]);let ue=(0,v.useRef)(se);ue.current=se;let de=(0,v.useCallback)(()=>void ue.current(),[]),fe=(0,v.useCallback)(e=>{ie.current=e},[]);return`problem`in S?(0,N.jsxs)(`div`,{"data-testid":`poster-unreadable`,children:[(0,N.jsxs)(`p`,{className:`border-b border-amber-300 bg-amber-50 px-3 py-1.5 text-xs text-amber-900 dark:border-amber-700 dark:bg-amber-950/40 dark:text-amber-200`,children:[`This poster cannot be opened in the editor: `,S.problem,`.`]}),d]}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`iframe`,{ref:_,title:i,"data-testid":`poster-frame`,"data-read-only":O?`true`:`false`,sandbox:JH,src:b,className:`block h-full w-full border-0`}),(0,N.jsx)(KH,{ref:y,serverUrl:p}),A!==null&&De(_.current)!==void 0&&(0,Ee.createPortal)((0,N.jsx)(`div`,{ref:le,tabIndex:-1,role:`dialog`,"aria-modal":`true`,"aria-label":`Touch up ${A.file}`,"data-testid":`poster-diagram-touch-up`,className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4 outline-none`,children:(0,N.jsxs)(`div`,{className:`flex h-full max-h-[56rem] w-full max-w-[90rem] flex-col overflow-hidden rounded-lg border border-zinc-300 bg-white shadow-xl dark:border-zinc-700 dark:bg-zinc-900`,children:[(0,N.jsxs)(`header`,{className:`flex shrink-0 items-center gap-2 border-b border-zinc-200 px-3 py-2 text-sm dark:border-zinc-800`,children:[(0,N.jsxs)(`span`,{className:`min-w-0 flex-1 truncate font-medium`,title:A.file,children:[A.file,A.page===void 0?``:` — ${A.page}`]}),h&&(0,N.jsx)(`button`,{type:`button`,className:`text-xs text-zinc-500 underline hover:text-zinc-800 dark:hover:text-zinc-200 disabled:opacity-50`,onClick:()=>h(A.file),title:`Open the diagram in draw.io desktop, for anything more than a touch-up; its saves come back here`,children:`↗ draw.io desktop`}),(0,N.jsx)(`button`,{type:`button`,className:`text-xs text-zinc-500 underline hover:text-zinc-800 dark:hover:text-zinc-200 disabled:opacity-50`,onClick:()=>void se(),title:`Back to the poster, which takes the diagram as saved (Escape)`,children:`back to the poster`})]}),(0,N.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,N.jsx)(Uz,{path:A.file,variant:`viewer`,page:A.page,startTouchUp:!0,onTouchUpDirtyChange:fe,onEscape:de})})]})}),De(_.current))]})}var QH=`pi-outpost:open`,$H=4,eU={css:`text/css`,js:`text/javascript`,mjs:`text/javascript`,png:`image/png`,jpg:`image/jpeg`,jpeg:`image/jpeg`,gif:`image/gif`,webp:`image/webp`,avif:`image/avif`,svg:`image/svg+xml`,ico:`image/x-icon`,bmp:`image/bmp`,woff:`font/woff`,woff2:`font/woff2`,ttf:`font/ttf`,otf:`font/otf`,mp4:`video/mp4`,webm:`video/webm`,mp3:`audio/mpeg`,wav:`audio/wav`,ogg:`audio/ogg`},tU=`(function () {
836
+ `:``}${e}`};for(let e of t)e.kind===`path`?$V(n,e.data)||r(`@${e.data}`):e.kind===`text`&&r(`\`\`\`${e.name}\n${e.data}\n\`\`\``);return n}function nH(e){return{name:e,kind:`path`,data:e,mimeType:`text/plain`,source:`manual`}}function rH(e,t){return e.some(e=>e.kind===`path`&&e.data===t)?e:[...e,nH(t)]}function iH(e,t){return e.filter((e,n)=>n!==t)}function aH(e,t){if(!t)return!1;let n=e.composedPath();if(n.length>0)return n.includes(t);let r=e.target;return r!==null&&t.contains(r)}function oH(e){let t=(0,v.useRef)(null);return(0,v.useEffect)(()=>{function n(n){t.current&&!aH(n,t.current)&&e()}return document.addEventListener(`mousedown`,n),()=>document.removeEventListener(`mousedown`,n)},[e]),t}var sH=100,cH=new Intl.Collator(void 0,{sensitivity:`base`,numeric:!0}),lH={extension:`ext`,prompt:`prompt`,skill:`skill`};function uH(e){return e===`directory`||e===`symlink-directory`}function dH(e,t){let n=e.slice(0,t),r=/(?:^|\s)@([^\s@]*)$/.exec(n);return r?{start:t-r[1].length-1,query:r[1]}:null}function fH({isStreaming:e,connected:t,commands:n,fileSearch:r,prefill:i,attachments:a,pendingUploads:o=[],onAttach:s,onMentionPaths:c,onRemoveAttachment:l,onSend:u,onAbort:d,onSearchFiles:f,onClearFileSearch:p,initialDraft:m,onDraftChange:h}){let[g,_]=(0,v.useState)(m??``);(0,v.useEffect)(()=>{h?.(g)},[g,h]);let[y,b]=(0,v.useState)(0),[x,S]=(0,v.useState)(0),[C,w]=(0,v.useState)(!1),T=(0,v.useRef)(null),E=(0,v.useRef)(null),D=(0,v.useRef)(null),O=(0,v.useRef)(null),ee=(0,v.useRef)(null);(0,v.useEffect)(()=>{i&&_(i.text)},[i?.nonce]),(0,v.useEffect)(()=>{ee.current!==null&&(D.current?.focus(),D.current?.setSelectionRange(ee.current,ee.current),ee.current=null)},[g]),(0,v.useLayoutEffect)(()=>{let e=D.current;if(!e)return;let t=-1,n=()=>{t=e.offsetWidth,e.style.overflowY=`hidden`,e.style.height=`auto`,e.style.height=`${e.scrollHeight}px`,e.scrollHeight>e.clientHeight&&(e.style.overflowY=`auto`)};n();let r=typeof ResizeObserver>`u`?void 0:new ResizeObserver(()=>{e.offsetWidth!==t&&n()});return r?.observe(e,{box:`border-box`}),()=>r?.disconnect()},[g]);let te=(0,v.useMemo)(()=>eH(g),[g]);(0,v.useEffect)(()=>{c(te)},[te.join(`
837
+ `)]);let k=(0,v.useMemo)(()=>{let e=/^\/(\S*)$/.exec(g);return e?e[1].toLowerCase():null},[g]),ne=(0,v.useMemo)(()=>k===null?[]:n.filter(e=>e.name.toLowerCase().includes(k)).sort((e,t)=>{let n=e.name.toLowerCase().startsWith(k);return n===t.name.toLowerCase().startsWith(k)?cH.compare(e.name,t.name):n?-1:1}).slice(0,sH),[k,n]),A=k===null?dH(g,y):null;(0,v.useEffect)(()=>{if(!A||A.query.length===0){p();return}let e=window.setTimeout(()=>f(A.query),150);return()=>clearTimeout(e)},[A?.query]);let re=(0,v.useMemo)(()=>{if(ne.length>0)return{kind:`command`,items:ne};let e=A&&r?.query===A.query?r.results:[];return e.length>0?{kind:`file`,items:e}:null},[ne,A,r]),j=re!==null&&!C,ie=k===null?A?`file:${A.query}`:null:`cmd:${k}`;(0,v.useEffect)(()=>{S(0)},[ie]),(0,v.useEffect)(()=>{w(!1)},[k===null?A?`file`:null:`command`]),(0,v.useEffect)(()=>{if(!j)return;let e=e=>{aH(e,T.current)||w(!0)};return document.addEventListener(`mousedown`,e),document.addEventListener(`touchstart`,e),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`touchstart`,e)}},[j]),(0,v.useEffect)(()=>{E.current?.querySelector(`[data-selected="true"]`)?.scrollIntoView({block:`nearest`})},[x]);let ae=o.length>0,[oe,se]=(0,v.useState)(!1);(0,v.useEffect)(()=>{ae||se(!1)},[ae]);function ce(){if(ae){se(!0);return}let e=tH(g,a),t=a.filter(e=>e.kind===`image`).map(e=>({data:e.data,mimeType:e.mimeType})),n=a.every(e=>e.kind===`path`);(g.trim()||!n&&e||t.length!==0)&&(u(e,t.length>0?t:void 0),_(``),p())}function le(e){let t=`/${e.name} `;_(t),ee.current=t.length,b(t.length)}function ue(e){if(!A)return;let t=g.slice(0,A.start),n=g.slice(y),r=`@${e.path}${uH(e.type)?`/`:` `}`,i=`${t}${r}${n}`;_(i),p();let a=t.length+r.length;ee.current=a,b(a)}function de(){if(re){if(re.kind===`command`){let e=re.items[x];e&&le(e)}else{let e=re.items[x];e&&ue(e)}}}function fe(e){if(j&&re){if(e.key===`ArrowDown`){e.preventDefault(),S(e=>(e+1)%re.items.length);return}if(e.key===`ArrowUp`){e.preventDefault(),S(e=>(e-1+re.items.length)%re.items.length);return}if(e.key===`Tab`||e.key===`Enter`){e.preventDefault(),de();return}if(e.key===`Escape`){e.preventDefault(),w(!0);return}}e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),ce())}function M(e){b(e.currentTarget.selectionStart??0)}function pe(e){let t=Array.from(e.clipboardData.files);t.length>0&&(e.preventDefault(),s(t))}return(0,N.jsxs)(`div`,{ref:T,className:`relative`,children:[(a.length>0||ae)&&(0,N.jsxs)(`div`,{className:`mb-2 flex flex-wrap gap-2`,children:[o.map(e=>(0,N.jsxs)(`span`,{"data-pending-upload":e.name,title:`${e.name} — copying into the workspace`,className:`flex items-center gap-1.5 rounded-md border border-dashed border-zinc-300 bg-zinc-50 py-1 pl-1.5 pr-2 text-xs text-zinc-500 dark:border-zinc-600 dark:bg-zinc-800/40 dark:text-zinc-400`,children:[(0,N.jsx)(`span`,{"aria-hidden":!0,className:`animate-pulse`,children:`⏳`}),(0,N.jsx)(`span`,{className:`max-w-40 truncate`,children:e.name}),(0,N.jsx)(`span`,{className:`sr-only`,children:`uploading`})]},e.id)),oe&&(0,N.jsx)(`span`,{role:`status`,className:`flex items-center py-1 text-xs text-amber-600 dark:text-amber-400`,children:`waiting for the attachment to finish uploading…`}),a.map((e,t)=>(0,N.jsxs)(`span`,{title:e.kind===`path`?`${e.name} — sent as a reference; the agent reads the file itself`:e.name,className:`flex items-center gap-1.5 rounded-md border border-zinc-200 bg-zinc-50 py-1 pl-1.5 pr-1 text-xs text-zinc-600 dark:border-zinc-700 dark:bg-zinc-800/60 dark:text-zinc-300`,children:[e.kind===`image`?(0,N.jsx)(`img`,{src:`data:${e.mimeType};base64,${e.data}`,alt:e.name,className:`h-8 w-8 rounded object-cover`}):(0,N.jsx)(`span`,{"aria-hidden":!0,className:e.kind===`path`?`font-mono font-bold text-blue-600 dark:text-blue-400`:``,children:e.kind===`path`?`@`:`📄`}),(0,N.jsx)(`span`,{className:`max-w-40 truncate`,children:e.name}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>l(t),title:`remove attachment`,className:`rounded px-1 text-zinc-400 hover:bg-zinc-200 hover:text-zinc-700 dark:hover:bg-zinc-700 dark:hover:text-zinc-200`,children:`✕`})]},`${e.name}:${t}`))]}),j&&re&&(0,N.jsx)(`div`,{ref:E,className:`absolute bottom-full left-0 z-20 mb-2 max-h-72 w-full max-w-xl overflow-y-auto rounded-lg border border-zinc-200 bg-white py-1 shadow-xl dark:border-zinc-700 dark:bg-zinc-900`,children:re.kind===`command`?re.items.map((e,t)=>(0,N.jsxs)(`button`,{type:`button`,"data-selected":t===x,onMouseEnter:()=>S(t),onClick:()=>le(e),className:`flex w-full items-baseline gap-2 px-3 py-1.5 text-left text-sm ${t===x?`bg-zinc-100 dark:bg-zinc-800`:``}`,children:[(0,N.jsxs)(`span`,{className:`font-mono text-zinc-800 dark:text-zinc-200`,children:[`/`,e.name]}),e.argumentHint&&(0,N.jsx)(`span`,{className:`font-mono text-xs text-zinc-500`,children:e.argumentHint}),e.description&&(0,N.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-xs text-zinc-500`,children:e.description}),(0,N.jsx)(`span`,{className:`ml-auto shrink-0 rounded bg-zinc-200 px-1 text-[10px] uppercase text-zinc-500 dark:bg-zinc-800`,children:lH[e.source]})]},e.name)):re.items.map((e,t)=>(0,N.jsx)(`button`,{type:`button`,"data-selected":t===x,onMouseEnter:()=>S(t),onClick:()=>ue(e),className:`flex w-full items-baseline gap-2 px-3 py-1.5 text-left text-sm ${t===x?`bg-zinc-100 dark:bg-zinc-800`:``}`,children:(0,N.jsxs)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-zinc-800 dark:text-zinc-200`,children:[e.path,uH(e.type)?`/`:``]})},e.path))}),(0,N.jsxs)(`div`,{className:`flex items-end gap-2 rounded-xl border border-zinc-200 bg-zinc-50 p-2 focus-within:border-zinc-400 dark:border-zinc-800 dark:bg-zinc-900 dark:focus-within:border-zinc-600`,children:[(0,N.jsx)(`textarea`,{ref:D,value:g,onChange:e=>{_(e.target.value),b(e.target.selectionStart??e.target.value.length)},onKeyDown:fe,onClick:M,onKeyUp:M,onPaste:pe,placeholder:t?e?`steer the agent… (Enter to send)`:`message pi… (/ for commands, @ for files, Enter to send, Shift+Enter for newline)`:`connecting…`,disabled:!t,rows:1,className:`max-h-[min(40vh,20rem)] flex-1 resize-none overflow-y-hidden bg-transparent px-2 py-1.5 text-[15px] outline-none placeholder:text-zinc-400 disabled:opacity-50 dark:placeholder:text-zinc-600`}),e&&(0,N.jsx)(`button`,{type:`button`,onClick:d,title:`stop`,"aria-label":`Stop the agent`,className:`rounded-lg bg-red-100 p-2 text-red-700 hover:bg-red-200 dark:bg-red-900/60 dark:text-red-200 dark:hover:bg-red-900`,children:(0,N.jsx)(`svg`,{viewBox:`0 0 24 24`,fill:`currentColor`,"aria-hidden":!0,className:`h-4 w-4`,children:(0,N.jsx)(`rect`,{x:`6`,y:`6`,width:`12`,height:`12`,rx:`2`})})}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>O.current?.click(),disabled:!t,title:`attach files`,"aria-label":`Attach files`,className:`rounded-lg p-2 text-zinc-500 hover:bg-zinc-200 hover:text-zinc-700 disabled:opacity-30 dark:text-zinc-400 dark:hover:bg-zinc-800 dark:hover:text-zinc-200`,children:(0,N.jsx)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:1.8,"aria-hidden":!0,className:`h-4 w-4`,children:(0,N.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`m21.44 11.05-9.19 9.19a6 6 0 0 1-8.49-8.49l8.57-8.57A4 4 0 1 1 18 8.84l-8.59 8.57a2 2 0 0 1-2.83-2.83l8.49-8.48`})})}),(0,N.jsx)(`input`,{ref:O,type:`file`,multiple:!0,hidden:!0,onChange:e=>{e.target.files?.length&&s(Array.from(e.target.files)),e.target.value=``}}),(0,N.jsx)(`button`,{type:`button`,onClick:ce,disabled:!t||ae||!g.trim()&&a.length===0,title:ae?`waiting for an attachment to finish uploading`:e?`steer`:`send`,"aria-label":e?`Steer the agent`:`Send message`,className:`rounded-lg bg-zinc-900 p-2 text-zinc-100 hover:bg-zinc-800 disabled:opacity-30 dark:bg-zinc-100 dark:text-zinc-900 dark:hover:bg-white`,children:e?(0,N.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:1.8,"aria-hidden":!0,className:`h-4 w-4`,children:[(0,N.jsx)(`circle`,{cx:`6`,cy:`19`,r:`3`}),(0,N.jsx)(`path`,{strokeLinecap:`round`,d:`M9 19h8.5a3.5 3.5 0 0 0 0-7h-11a3.5 3.5 0 0 1 0-7H15`}),(0,N.jsx)(`circle`,{cx:`18`,cy:`5`,r:`3`})]}):(0,N.jsx)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:1.8,"aria-hidden":!0,className:`h-4 w-4`,children:(0,N.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M6 12 3.27 3.13c6.6 1.9 12.83 4.9 18.43 8.87-5.6 3.97-11.83 6.97-18.43 8.87L6 12Zm0 0h7.5`})})})]})]})}var pH=`rounded-md border px-3 py-1.5 text-sm border-zinc-200 hover:bg-zinc-100 dark:border-zinc-800 dark:hover:bg-zinc-800`,mH=`rounded-md bg-zinc-900 px-3 py-1.5 text-sm text-zinc-100 hover:bg-zinc-800 dark:bg-zinc-100 dark:text-zinc-900 dark:hover:bg-white`,hH=`w-full rounded-md border border-zinc-300 bg-white px-2 py-1.5 text-sm outline-none focus:border-zinc-500 dark:border-zinc-700 dark:bg-zinc-950 dark:focus:border-zinc-500`,gH=`mb-4 ${hH}`,_H=`1,3`,vH=` — `;function yH(e){let t=e.indexOf(`
838
+ `);return t===-1?{heading:e,body:``}:{heading:e.slice(0,t),body:e.slice(t+1).trim()}}function bH(e){let t=/^(\d+)\.\s+(\S[\s\S]*)$/.exec(e.trim());if(!t)return null;let n=t[2],r=n.indexOf(vH);return{index:Number(t[1]),label:r===-1?n:n.slice(0,r),description:r===-1?``:n.slice(r+3)}}function xH(e){if(e.method!==`input`||e.placeholder!==_H)return null;let{heading:t,body:n}=yH(e.title),r=[];for(let e of n.split(`
839
+ `)){let t=bH(e);t&&r.push(t)}return r.length<2||r.some((e,t)=>e.index!==t+1)?null:{heading:t,options:r}}function SH({request:e,onRespond:t}){let[n,r]=(0,v.useState)(e.method===`editor`?e.prefill??``:``),[i,a]=(0,v.useState)([]),[o,s]=(0,v.useState)(!1),c=(e.method===`select`||e.method===`confirm`||e.method===`input`)&&e.timeout,[l,u]=(0,v.useState)(c?Math.ceil(c/1e3):null),d=xH(e),{heading:f,body:p}=yH(e.title);function m(){t({id:e.id,cancelled:!0})}function h(e){a(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e].sort((e,t)=>e-t))}function g(){let r=n.trim();t({id:e.id,value:r.length>0?r:i.join(`,`)})}return(0,v.useEffect)(()=>{if(!o)return;let e=setTimeout(()=>s(!1),400);return()=>clearTimeout(e)},[o]),(0,v.useEffect)(()=>{if(l===null)return;if(l<=0){t({id:e.id,cancelled:!0});return}let n=setTimeout(()=>u(e=>e===null?null:e-1),1e3);return()=>clearTimeout(n)},[l,e.id,t]),(0,N.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4`,onClick:()=>s(!0),children:(0,N.jsxs)(`div`,{className:`w-full ${p?`max-w-2xl`:`max-w-md`} rounded-xl border bg-white p-4 shadow-2xl transition-shadow dark:bg-zinc-900 ${o?`border-zinc-400 ring-2 ring-zinc-400/60 dark:border-zinc-500 dark:ring-zinc-500/60`:`border-zinc-200 dark:border-zinc-700`}`,onClick:e=>e.stopPropagation(),children:[(0,N.jsxs)(`div`,{className:`mb-3 flex items-start gap-3`,children:[(0,N.jsx)(`h2`,{className:`flex-1 text-sm font-semibold text-zinc-900 dark:text-zinc-100`,children:f}),(0,N.jsx)(`button`,{type:`button`,onClick:m,"aria-label":`Refuse to answer`,title:`Refuse to answer`,className:`-mr-1 -mt-1 rounded-md px-1.5 py-0.5 text-sm leading-none text-zinc-400 hover:bg-zinc-100 hover:text-zinc-700 dark:text-zinc-500 dark:hover:bg-zinc-800 dark:hover:text-zinc-200`,children:`✕`})]}),p&&!d&&(0,N.jsx)(`pre`,{className:`mb-3 max-h-72 overflow-auto whitespace-pre-wrap break-words rounded-md bg-zinc-50 p-2 font-mono text-xs text-zinc-600 dark:bg-zinc-950 dark:text-zinc-400`,children:p}),e.method===`select`&&(0,N.jsx)(`div`,{className:`mb-1 flex flex-col gap-1`,children:e.options.map(n=>{let r=bH(n);return(0,N.jsx)(`button`,{type:`button`,onClick:()=>t({id:e.id,value:n}),className:`text-left ${pH}`,children:r?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`span`,{className:`font-medium text-zinc-900 dark:text-zinc-100`,children:r.label}),r.description&&(0,N.jsx)(`span`,{className:`mt-0.5 block text-xs text-zinc-500 dark:text-zinc-400`,children:r.description})]}):n},n)})}),e.method===`confirm`&&(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`p`,{className:`mb-4 text-sm text-zinc-600 dark:text-zinc-400`,children:e.message}),(0,N.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,N.jsx)(`button`,{type:`button`,onClick:()=>t({id:e.id,confirmed:!1}),className:pH,children:`No`}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>t({id:e.id,confirmed:!0}),className:mH,children:`Yes`})]})]}),d&&(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`div`,{className:`mb-3 flex flex-col gap-1`,children:d.options.map(e=>(0,N.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 rounded-md px-2 py-1.5 text-sm hover:bg-zinc-100 dark:hover:bg-zinc-800`,children:[(0,N.jsx)(`input`,{type:`checkbox`,checked:i.includes(e.index),onChange:()=>h(e.index),className:`mt-0.5`}),(0,N.jsxs)(`span`,{children:[(0,N.jsx)(`span`,{className:`font-medium text-zinc-900 dark:text-zinc-100`,children:e.label}),e.description&&(0,N.jsx)(`span`,{className:`mt-0.5 block text-xs text-zinc-500 dark:text-zinc-400`,children:e.description})]})]},e.index))}),(0,N.jsx)(`input`,{value:n,onChange:e=>r(e.target.value),placeholder:`…or type your own answer`,onKeyDown:e=>{e.key===`Enter`&&g(),e.key===`Escape`&&m()},className:`mb-1 ${hH}`}),(0,N.jsx)(`p`,{className:`mb-4 text-xs text-zinc-400 dark:text-zinc-600`,children:`A typed answer replaces the selection above.`}),(0,N.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,N.jsx)(`button`,{type:`button`,onClick:m,className:pH,children:`Cancel`}),(0,N.jsx)(`button`,{type:`button`,onClick:g,className:mH,children:`OK`})]})]}),e.method===`input`&&!d&&(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`input`,{autoFocus:!0,value:n,onChange:e=>r(e.target.value),placeholder:e.placeholder,onKeyDown:r=>{r.key===`Enter`&&t({id:e.id,value:n}),r.key===`Escape`&&m()},className:gH}),(0,N.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,N.jsx)(`button`,{type:`button`,onClick:m,className:pH,children:`Cancel`}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>t({id:e.id,value:n}),className:mH,children:`OK`})]})]}),e.method===`editor`&&(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`textarea`,{autoFocus:!0,value:n,onChange:e=>r(e.target.value),rows:8,onKeyDown:e=>{e.key===`Escape`&&m()},className:`resize-none font-mono ${gH}`}),(0,N.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,N.jsx)(`button`,{type:`button`,onClick:m,className:pH,children:`Cancel`}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>t({id:e.id,value:n}),className:mH,children:`OK`})]})]}),l!==null&&(0,N.jsxs)(`p`,{className:`mt-3 text-right text-xs text-zinc-400 dark:text-zinc-600`,children:[`auto-dismiss in `,l,`s`]})]})})}var CH=`rounded-md border px-3 py-1.5 text-sm border-zinc-200 hover:bg-zinc-100 disabled:opacity-50 dark:border-zinc-800 dark:hover:bg-zinc-800`,wH=`rounded-md bg-zinc-900 px-3 py-1.5 text-sm text-zinc-100 hover:bg-zinc-800 disabled:opacity-50 dark:bg-zinc-100 dark:text-zinc-900 dark:hover:bg-white`,TH=e=>new Date(e).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`});function EH({request:e,onRespond:t}){let[n,r]=(0,v.useState)(null),[i,a]=(0,v.useState)(!1);(0,v.useEffect)(()=>{if(!i)return;let e=setTimeout(()=>a(!1),400);return()=>clearTimeout(e)},[i]),(0,v.useEffect)(()=>r(null),[e.id]);function o(i){n||(r(i),t(e.id,i))}let{hosts:s,directories:c}=e.grant,l=e.kind===`connection`;return(0,N.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4`,onClick:()=>a(!0),children:(0,N.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-labelledby":`sandbox-grant-title`,"data-testid":`sandbox-grant-dialog`,"data-request-id":e.id,className:`w-full max-w-2xl rounded-xl border bg-white p-4 shadow-2xl transition-shadow dark:bg-zinc-900 ${i?`border-zinc-400 ring-2 ring-zinc-400/60 dark:border-zinc-500 dark:ring-zinc-500/60`:`border-zinc-200 dark:border-zinc-700`}`,onClick:e=>e.stopPropagation(),children:[(0,N.jsx)(`h2`,{id:`sandbox-grant-title`,className:`mb-3 text-sm font-semibold text-zinc-900 dark:text-zinc-100`,children:l?`A running command is connecting to ${s.join(`, `)}`:`The agent asks to run a command beyond its sandbox`}),(0,N.jsx)(`div`,{className:`mb-1 text-xs font-medium text-zinc-500 dark:text-zinc-400`,children:l?`The running command`:`Command`}),(0,N.jsx)(`pre`,{"data-testid":`sandbox-grant-command`,className:`mb-3 max-h-48 overflow-auto whitespace-pre-wrap break-all rounded-md bg-zinc-50 p-2 font-mono text-xs text-zinc-800 dark:bg-zinc-950 dark:text-zinc-200`,children:e.command}),(0,N.jsx)(`div`,{className:`mb-1 text-xs font-medium text-zinc-500 dark:text-zinc-400`,children:l?`It is waiting to reach`:`It would also reach`}),(0,N.jsxs)(`ul`,{"data-testid":`sandbox-grant-targets`,className:`mb-3 list-disc pl-5 text-sm text-zinc-800 dark:text-zinc-200`,children:[s.map(e=>(0,N.jsxs)(`li`,{children:[`host `,(0,N.jsx)(`code`,{className:`font-mono`,children:e})]},`host:${e}`)),c.map(e=>(0,N.jsxs)(`li`,{children:[e.access===`write`?`read and write`:`read`,` `,(0,N.jsx)(`code`,{className:`break-all font-mono`,children:e.path})]},`dir:${e.path}`))]}),e.overridesReadOnly&&(0,N.jsx)(`p`,{"data-testid":`sandbox-grant-overrides`,className:`mb-3 rounded-md bg-amber-50 p-2 text-xs text-amber-800 dark:bg-amber-900/40 dark:text-amber-200`,children:`Writing is off in this project's sandbox: allowing this lets the command write there anyway.`}),l?(0,N.jsx)(`p`,{"data-testid":`sandbox-grant-reason`,className:`mb-4 text-sm text-zinc-600 dark:text-zinc-400`,children:`Not in this sandbox's allowed hosts. The agent did not ask for it: the command connected, and waits for your answer.`}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`div`,{className:`mb-1 text-xs font-medium text-zinc-500 dark:text-zinc-400`,children:`The agent says`}),(0,N.jsx)(`blockquote`,{"data-testid":`sandbox-grant-reason`,className:`mb-4 border-l-2 border-zinc-300 pl-2 text-sm italic text-zinc-600 dark:border-zinc-700 dark:text-zinc-400`,children:e.reason})]}),(0,N.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[(0,N.jsxs)(`span`,{className:`mr-auto text-xs text-zinc-500 dark:text-zinc-400`,children:[`Refused if unanswered by `,TH(e.expiresAt)]}),(0,N.jsx)(`button`,{type:`button`,className:CH,disabled:n!==null,onClick:()=>o(`refuse`),children:`Refuse`}),(0,N.jsx)(`button`,{type:`button`,className:CH,disabled:n!==null,onClick:()=>o(`session`),children:`Allow for this session`}),(0,N.jsx)(`button`,{type:`button`,className:wH,disabled:n!==null,onClick:()=>o(`once`),children:l?`Allow for this command`:`Allow once`})]})]})})}var DH={info:`border-blue-300 bg-blue-50 text-blue-800 dark:border-blue-900 dark:bg-blue-950/60 dark:text-blue-200`,warning:`border-amber-300 bg-amber-50 text-amber-800 dark:border-amber-900 dark:bg-amber-950/60 dark:text-amber-200`,error:`border-red-300 bg-red-50 text-red-800 dark:border-red-900 dark:bg-red-950/60 dark:text-red-200`},OH=6e3;function kH({notification:e,onDismiss:t}){let n=(0,v.useRef)(t);return(0,v.useEffect)(()=>{n.current=t}),(0,v.useEffect)(()=>{let e=setTimeout(()=>n.current(),OH);return()=>clearTimeout(e)},[e.id]),(0,N.jsxs)(`div`,{role:`status`,className:`flex items-start gap-2 rounded-lg border px-3 py-2 text-sm shadow-lg ${DH[e.notifyType??`info`]}`,children:[(0,N.jsx)(`span`,{className:`min-w-0 flex-1 break-words`,children:e.message}),(0,N.jsx)(`button`,{type:`button`,"aria-label":`Dismiss notification`,onClick:()=>n.current(),className:`-mr-1 shrink-0 rounded px-1 leading-5 opacity-60 transition-opacity hover:opacity-100 focus-visible:opacity-100`,children:`×`})]})}function AH({notifications:e,onDismiss:t}){return e.length===0?null:(0,N.jsx)(`div`,{className:`fixed right-4 top-16 z-40 flex w-80 flex-col gap-2`,children:e.map(e=>(0,N.jsx)(kH,{notification:e,onDismiss:()=>t(e.id)},e.id))})}var jH={30:`#3f3f46`,31:`#dc2626`,32:`#16a34a`,33:`#ca8a04`,34:`#2563eb`,35:`#9333ea`,36:`#0891b2`,37:`#71717a`,90:`#a1a1aa`,91:`#ef4444`,92:`#22c55e`,93:`#eab308`,94:`#3b82f6`,95:`#a855f7`,96:`#06b6d4`,97:`#d4d4d8`};function MH(e){if(!Number.isInteger(e)||e<0||e>255)return;if(e<16)return jH[e<8?30+e:90+e-8];if(e>=232){let t=8+(e-232)*10;return`rgb(${t} ${t} ${t})`}let t=e-16,n=e=>e===0?0:55+e*40;return`rgb(${n(Math.floor(t/36))} ${n(Math.floor(t/6)%6)} ${n(t%6)})`}var NH=/\u001B\[[0-9;:]*[A-Za-z]|\u001B[()][A-Za-z0-9]|\u001B[A-Za-z]/g;function PH(e,t){let n={...e};for(let e=0;e<t.length;e++){let r=t[e];if(r===0)for(let e of Object.keys(n))delete n[e];else if(r===1)n.bold=!0;else if(r===2)n.dim=!0;else if(r===3)n.italic=!0;else if(r===4)n.underline=!0;else if(r===22)delete n.bold,delete n.dim;else if(r===23)delete n.italic;else if(r===24)delete n.underline;else if(r===39)delete n.color;else if(jH[r]!==void 0)n.color=jH[r];else if(r===38){if(t[e+1]===2){let[r,i,a]=[t[e+2],t[e+3],t[e+4]];[r,i,a].every(e=>Number.isFinite(e))&&(n.color=`rgb(${r} ${i} ${a})`),e+=4}else if(t[e+1]===5){let r=MH(t[e+2]);r!==void 0&&(n.color=r),e+=2}}}return n}function FH(e){let t=[],n={},r=0;NH.lastIndex=0;for(let i=NH.exec(e);i!==null;i=NH.exec(e)){i.index>r&&t.push({text:e.slice(r,i.index),...n}),r=i.index+i[0].length;let a=i[0];if(a.endsWith(`m`)){let e=a.slice(2,-1),t=e===``?[0]:e.split(/[;:]/).map(e=>e===``?0:Number(e));n=PH(n,t)}}return r<e.length&&t.push({text:e.slice(r),...n}),t}function IH(e){return e.replace(NH,``)}function LH({text:e}){let t=FH(e);return(0,N.jsx)(N.Fragment,{children:t.map((e,t)=>(0,N.jsx)(`span`,{style:{...e.color?{color:e.color}:{},...e.bold?{fontWeight:600}:{},...e.dim?{opacity:.7}:{},...e.italic?{fontStyle:`italic`}:{},...e.underline?{textDecoration:`underline`}:{}},children:e.text},t))})}function RH({widgets:e,placement:t,controls:n={}}){let r=Object.entries(e).filter(([,e])=>e.placement===t);return r.length===0?null:(0,N.jsx)(`div`,{className:`mb-2 flex flex-col gap-1`,children:r.map(([e,t])=>(0,N.jsx)(BH,{name:e,lines:t.lines,control:n[e]??{}},e))})}function zH({text:e}){return(0,N.jsx)(`div`,{className:`min-h-4`,children:(0,N.jsx)(LH,{text:e})})}function BH({name:e,lines:t,control:n}){let r=(0,v.useRef)(null),i=t.slice(0,n.pinnedLines??0),a=t.slice(i.length),o=n.anchor?n.anchor(t)-i.length:-1;return(0,v.useLayoutEffect)(()=>{let e=r.current,t=o>=0?e?.children[o]:void 0;e&&t&&(e.scrollTop=t.offsetTop)},[t,o]),(0,N.jsxs)(`div`,{"data-widget":e,className:`flex items-start gap-2 rounded-md border border-zinc-200 bg-zinc-50 px-3 py-1.5 font-mono text-xs text-zinc-600 dark:border-zinc-800 dark:bg-zinc-900 dark:text-zinc-400`,children:[(0,N.jsxs)(`div`,{className:`min-w-0 flex-1 whitespace-pre-wrap`,children:[i.map((e,t)=>(0,N.jsx)(zH,{text:e},t)),(0,N.jsx)(`div`,{ref:r,tabIndex:0,"aria-label":n.region??`Extension widget ${e}`,className:`relative max-h-[20vh] overflow-y-auto rounded-sm focus:outline-none focus-visible:ring-1 focus-visible:ring-zinc-400`,children:a.map((e,t)=>(0,N.jsx)(zH,{text:e},t))})]}),n.close&&(0,N.jsx)(`button`,{type:`button`,"aria-label":n.close.label,title:n.close.label,onClick:n.close.run,className:`-mr-1 shrink-0 rounded px-1 font-sans text-sm leading-5 opacity-60 transition-opacity hover:opacity-100 focus-visible:opacity-100`,children:`×`})]})}var VH=null,HH=null;function UH(){return HH??=ye(()=>import(`./CodeEditor-BIH6CdMn.js`).then(e=>e.t).then(e=>VH=e,e=>{throw HH=null,e}),__vite__mapDeps([22,1,23])),HH}var WH=(0,v.lazy)(()=>{if(VH!==null){let e=VH;return{then:t=>t({default:e.CodeEditor})}}return UH().then(e=>({default:e.CodeEditor}))});function GH({text:e,path:t,serverUrl:n,token:r,workspace:i,template:a}){let[o,s]=(0,v.useState)(`idle`),[c,l]=(0,v.useState)(`plain`),[u,d]=(0,v.useState)(null),f=(0,v.useRef)(!1),p=(0,v.useRef)({plain:0,template:0});async function m(a){if(!(f.current||Date.now()-p.current[a]<750)){f.current=!0,p.current[a]=Date.now(),l(a),s(`working`),d(null);try{let{downloadDocx:o,downloadDocxInTemplate:c}=await ye(async()=>{let{downloadDocx:e,downloadDocxInTemplate:t}=await import(`./docxExport-DVePkHyV.js`);return{downloadDocx:e,downloadDocxInTemplate:t}},__vite__mapDeps([24,21,1,25])),l=typeof e==`function`?e():e;await(a===`template`?c:o)(l,t,{serverUrl:n,token:r,workspace:i}),s(`idle`)}catch(e){s(`failed`),d(e instanceof Error?e.message:String(e))}finally{f.current=!1}}}let h=`shrink-0 rounded px-1.5 py-0.5 text-xs text-zinc-400 hover:bg-zinc-100 hover:text-zinc-700 disabled:opacity-50 dark:text-zinc-600 dark:hover:bg-zinc-800 dark:hover:text-zinc-300`,g=(e,t)=>o===`working`&&c===e?`… exporting`:o===`failed`&&c===e?`⚠ export failed`:t,_=(e,t)=>o===`failed`&&c===e?`Could not export: ${u??`unknown reason`}`:t;return(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`button`,{type:`button`,onClick:()=>void m(`plain`),disabled:o===`working`,title:_(`plain`,`Download as a Word document`),"aria-label":`Download as a Word document`,className:h,children:g(`plain`,`⤓ word`)}),a!==void 0&&(0,N.jsx)(`button`,{type:`button`,onClick:()=>void m(`template`),disabled:o===`working`,title:_(`template`,`Download as a Word document in the template ${a}`),"aria-label":`Download as a Word document in the template ${a}`,className:h,children:g(`template`,`⤓ word · template`)})]})}var KH=3e4,qH=(0,v.forwardRef)(function({serverUrl:e},t){let[n,r]=(0,v.useState)(null),i=(0,v.useRef)(null),a=(0,v.useRef)(Promise.resolve()),o=(0,v.useRef)(null),s=(0,v.useRef)(0);function c(e,t){let n=i.current;n!==null&&n.id===e&&(clearTimeout(n.timer),i.current=null,r(null),t instanceof Error?n.reject(t):n.resolve(t))}if((0,v.useImperativeHandle)(t,()=>({draw(e){let t=()=>new Promise((t,n)=>{let a=++s.current,o=setTimeout(()=>c(a,Error(`the draw.io viewer did not answer`)),KH);i.current={id:a,resolve:t,reject:n,timer:o},r({id:a,xml:e})}),n=a.current.then(t,t);return a.current=n.catch(()=>void 0),n}}),[]),(0,v.useEffect)(()=>()=>{let e=i.current;e!==null&&(clearTimeout(e.timer),i.current=null,e.reject(Error(`the poster was closed`)))},[]),n===null)return null;let{id:l}=n;return(0,N.jsx)(`div`,{"aria-hidden":`true`,"data-testid":`drawio-painter`,style:{position:`fixed`,left:-2e4,top:0,width:1200,height:900,pointerEvents:`none`},children:(0,N.jsx)(Km,{ref:o,xml:n.xml,serverUrl:e,title:`draw.io diagram for a poster`,className:`flex h-full flex-col`,onRendered:e=>{if(e!==null)return c(l,Error(e));o.current?.exportSvg().then(({svg:e})=>c(l,e),e=>c(l,e instanceof Error?e:Error(String(e))))}},l)})});function JH(e,t=window.location.href){return new URL(`${e}/${l}`,t).href}var YH=`allow-scripts allow-same-origin`,XH=`Discard the unsaved touch-ups to this diagram?`;function ZH(e,t,n){let r=URL.createObjectURL(new Blob([t],{type:n}));try{let t=document.createElement(`a`);t.href=r,t.download=e,t.click()}finally{URL.revokeObjectURL(r)}}function QH({path:i,content:a,mtimeMs:s,writable:l,loadFile:u,fallback:d,onTouchUpDirtyChange:f}){let{serverUrl:p,fileIo:m,onOpenNative:h}=Fm(),g=x()===`dark`,_=(0,v.useRef)(null),y=(0,v.useRef)(null),b=(0,v.useMemo)(()=>JH(p),[p]),S=(0,v.useMemo)(()=>{try{return{page:r(a)}}catch(e){return{problem:e instanceof Error?e.message:String(e)}}},[a]),C=(0,v.useRef)(null),w=(0,v.useRef)(null),T=(0,v.useRef)(!1),E=(0,v.useRef)(null),D=(0,v.useRef)(()=>{}),[O,ee]=(0,v.useState)(!l||m===void 0),te=(0,v.useRef)(!1),k=(0,v.useRef)(f);k.current=f;let ne=(0,v.useRef)({path:i,content:a,mtimeMs:s,dark:g,readOnly:O,poster:S,loadFile:u});ne.current={path:i,content:a,mtimeMs:s,dark:g,readOnly:O,poster:S,loadFile:u};let[A,re]=(0,v.useState)(null),j=(0,v.useRef)(A);j.current=A;let ie=(0,v.useRef)(!1),ae=(0,v.useRef)(()=>{});(0,v.useEffect)(()=>{let r=!0,i=new URL(b).origin,a=e=>_.current?.contentWindow?.postMessage(e,i),s=(e,t)=>{r&&a({type:o.ANSWER,id:e,value:t})};ae.current=s;let u=0;async function d(){let e=++u,{path:t,content:n,mtimeMs:i,poster:s,dark:c}=ne.current;if(!(`page`in s))return;let d=l&&m!==void 0;if(d)try{await m.read(t)}catch{d=!1}r&&e===u&&(C.current=d?{mtimeMs:i}:null,w.current=n,ee(!d),a({type:o.OPEN,poster:{...s.page,revision:0,readOnly:!d},theme:c?`dark`:`light`}))}D.current=()=>{te.current&&!T.current&&ne.current.content!==E.current&&(E.current=null,ne.current.content===w.current?C.current!==null&&(C.current={mtimeMs:ne.current.mtimeMs}):d())};async function f(e,t,r){let{path:i,poster:a}=ne.current;if(!(`page`in a)||m===void 0||C.current===null||ne.current.readOnly)s(e,{saved:!1,message:`this file cannot be saved here`});else try{let o=n(a.page.title,{html:t,css:r,format:a.page.format}),{mtimeMs:c}=await m.write(i,o,C.current.mtimeMs);C.current={mtimeMs:c},ne.current.content!==o&&(E.current=ne.current.content),w.current=o,s(e,{saved:!0,revision:0,message:`Saved. The agent reads this version.`})}catch(t){let n=t instanceof wz&&t.reason===`conflict`;s(e,{saved:!1,message:n?`the file changed on disk since it was opened, so it was not saved. Close and reopen it to see what is there now.`:t instanceof Error?t.message:String(t)})}}async function p(e,t){let n;try{n={ok:!0,value:await t()}}catch(e){n={ok:!1,message:e instanceof Error?e.message:String(e)}}s(e,n)}async function h(){if(m?.find===void 0)throw Error(`this view cannot look through the project's files`);let e=new Set;for(let t of[`.drawio`,`.dio`])for(let n of await m.find(t))n.type===`file`&&ce(n.path)&&e.add(n.path);let t=ne.current.path;return Promise.all([...e].map(async e=>{let n=[];try{n=Mz((await m.read(e)).content)}catch{}return{path:Fz(t,e),pages:n}}))}async function g(e,t){let n=oe(ne.current.path,e);if(!ce(n))throw Error(`"${e}" is not a .drawio file`);if(m===void 0)throw Error(`this view cannot read the project's files`);let r;try{r=(await m.read(n)).content}catch(t){throw Error(`"${e}" could not be read: ${t instanceof Error?t.message:String(t)}`)}let i=Pz(r,t);if(y.current===null)throw Error(`the poster was closed`);return y.current.draw(i)}async function v(e,t,n){let i=t=>s(e,{ok:!1,message:t});if(j.current!==null)return i(`another diagram is open for touch-up`);let a=oe(ne.current.path,t);if(!ce(a))return i(`"${t}" is not a .drawio file`);if(m===void 0)return i(`this view cannot read the project's files`);let o;try{o=(await m.read(a)).content,Mz(o)}catch(e){return i(`"${t}" could not be opened: ${e instanceof Error?e.message:String(e)}`)}r&&(ie.current=!1,re({file:a,page:n,id:e,before:o}))}async function x(){if(m?.find===void 0)throw Error(`this view cannot look through the project's files`);let e=new Set;for(let n of Object.keys(c))for(let r of await m.find(n))r.type===`file`&&t(r.path)!==void 0&&e.add(r.path);let n=ne.current.path;return[...e].map(e=>Fz(n,e))}async function S(n){let r=oe(ne.current.path,n),i=t(r);if(i===void 0)throw Error(`"${n}" is not a picture file (SVG, PNG, JPEG, GIF or WebP)`);let a=ne.current.loadFile;if(a===void 0)throw Error(`this view cannot read the project's files`);let o=await a(r);if(o===void 0)throw Error(`"${n}" could not be read: it is not there, or not in the project`);if(o.size>20971520)throw Error(`"${n}" is ${Math.round(o.size/1024/1024)} MB, more than a poster reads (${e/1024/1024} MB)`);return{type:i,bytes:new Uint8Array(await o.arrayBuffer())}}function O(e){if(_.current===null||e.source!==_.current.contentWindow||e.origin!==i)return;let t=e.data;if(typeof t==`object`&&t){if(t.type===o.READY)te.current=!0,d();else if(t.type===o.DIRTY)T.current=t.dirty===!0,k.current?.(T.current),D.current();else if(t.type===o.SAVE&&typeof t.html==`string`&&typeof t.css==`string`)f(t.id,t.html,t.css);else if(t.type===o.DELIVER&&typeof t.name==`string`&&typeof t.mediaType==`string`&&t.bytes instanceof Uint8Array)ZH(t.name,t.bytes,t.mediaType),s(t.id,`Downloaded "${t.name}".`);else if(t.type===o.DRAWIO_LIST)p(t.id,h);else if(t.type===o.DRAWIO_DRAW){let{path:e,page:n}=t;typeof e==`string`&&p(t.id,()=>g(e,typeof n==`string`?n:void 0))}else if(t.type===o.DRAWIO_EDIT){let{path:e,page:n}=t;typeof e==`string`&&v(t.id,e,typeof n==`string`?n:void 0)}else if(t.type===o.PICTURE_LIST)p(t.id,x);else if(t.type===o.PICTURE_READ){let{path:e}=t;typeof e==`string`&&p(t.id,()=>S(e))}}}return window.addEventListener(`message`,O),()=>{r=!1,te.current=!1,re(null),D.current=()=>{},k.current?.(!1),window.removeEventListener(`message`,O)}},[b,m,l]),(0,v.useEffect)(()=>D.current(),[a,s]),(0,v.useEffect)(()=>{te.current&&_.current?.contentWindow?.postMessage({type:o.THEME,theme:g?`dark`:`light`},new URL(b).origin)},[g,b]);async function se(){let e=j.current;if(e===null||ie.current&&!window.confirm(XH))return;re(null);let t;try{t={ok:!0,value:(await m.read(e.file)).content!==e.before}}catch(e){t={ok:!1,message:`the diagram could not be read again: ${e instanceof Error?e.message:String(e)}`}}ae.current(e.id,t)}let le=(0,v.useRef)(null);(0,v.useEffect)(()=>{if(A===null)return;le.current?.focus();function e(e){e.key!==`Escape`||e.defaultPrevented||(e.preventDefault(),e.stopImmediatePropagation(),ue.current())}return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[A]);let ue=(0,v.useRef)(se);ue.current=se;let de=(0,v.useCallback)(()=>void ue.current(),[]),fe=(0,v.useCallback)(e=>{ie.current=e},[]);return`problem`in S?(0,N.jsxs)(`div`,{"data-testid":`poster-unreadable`,children:[(0,N.jsxs)(`p`,{className:`border-b border-amber-300 bg-amber-50 px-3 py-1.5 text-xs text-amber-900 dark:border-amber-700 dark:bg-amber-950/40 dark:text-amber-200`,children:[`This poster cannot be opened in the editor: `,S.problem,`.`]}),d]}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`iframe`,{ref:_,title:i,"data-testid":`poster-frame`,"data-read-only":O?`true`:`false`,sandbox:YH,src:b,className:`block h-full w-full border-0`}),(0,N.jsx)(qH,{ref:y,serverUrl:p}),A!==null&&De(_.current)!==void 0&&(0,Ee.createPortal)((0,N.jsx)(`div`,{ref:le,tabIndex:-1,role:`dialog`,"aria-modal":`true`,"aria-label":`Touch up ${A.file}`,"data-testid":`poster-diagram-touch-up`,className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4 outline-none`,children:(0,N.jsxs)(`div`,{className:`flex h-full max-h-[56rem] w-full max-w-[90rem] flex-col overflow-hidden rounded-lg border border-zinc-300 bg-white shadow-xl dark:border-zinc-700 dark:bg-zinc-900`,children:[(0,N.jsxs)(`header`,{className:`flex shrink-0 items-center gap-2 border-b border-zinc-200 px-3 py-2 text-sm dark:border-zinc-800`,children:[(0,N.jsxs)(`span`,{className:`min-w-0 flex-1 truncate font-medium`,title:A.file,children:[A.file,A.page===void 0?``:` — ${A.page}`]}),h&&(0,N.jsx)(`button`,{type:`button`,className:`text-xs text-zinc-500 underline hover:text-zinc-800 dark:hover:text-zinc-200 disabled:opacity-50`,onClick:()=>h(A.file),title:`Open the diagram in draw.io desktop, for anything more than a touch-up; its saves come back here`,children:`↗ draw.io desktop`}),(0,N.jsx)(`button`,{type:`button`,className:`text-xs text-zinc-500 underline hover:text-zinc-800 dark:hover:text-zinc-200 disabled:opacity-50`,onClick:()=>void se(),title:`Back to the poster, which takes the diagram as saved (Escape)`,children:`back to the poster`})]}),(0,N.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,N.jsx)(Uz,{path:A.file,variant:`viewer`,page:A.page,startTouchUp:!0,onTouchUpDirtyChange:fe,onEscape:de})})]})}),De(_.current))]})}var $H=`pi-outpost:open`,eU=4,tU={css:`text/css`,js:`text/javascript`,mjs:`text/javascript`,png:`image/png`,jpg:`image/jpeg`,jpeg:`image/jpeg`,gif:`image/gif`,webp:`image/webp`,avif:`image/avif`,svg:`image/svg+xml`,ico:`image/x-icon`,bmp:`image/bmp`,woff:`font/woff`,woff2:`font/woff2`,ttf:`font/ttf`,otf:`font/otf`,mp4:`video/mp4`,webm:`video/webm`,mp3:`audio/mpeg`,wav:`audio/wav`,ogg:`audio/ogg`},nU=`(function () {
840
840
  document.addEventListener("click", function (event) {
841
841
  var link = event.target && event.target.closest ? event.target.closest("a[href]") : null;
842
842
  if (!link || event.defaultPrevented) return;
@@ -861,11 +861,11 @@ l0,-`+(t+144)+`c-2,-159.3,-10,-310.7,-24,-454c-53.3,-528,-210,-949.7,
861
861
  }
862
862
  if (/^[a-z][a-z0-9+.-]*:/i.test(href)) return;
863
863
  event.preventDefault();
864
- parent.postMessage({ type: "${QH}", href: href }, "*");
864
+ parent.postMessage({ type: "${$H}", href: href }, "*");
865
865
  }, true);
866
- })();`;function nU(e){if(e==null)return!1;let t=e.trim();return t!==``&&!t.startsWith(`#`)&&!ae(t)}function rU(e,t){return eU[e.split(`.`).pop()?.toLowerCase()??``]??t}function iU(e,t){return new Promise((n,r)=>{let i=new FileReader;i.onload=()=>n(String(i.result).replace(/^data:[^;,]*/,`data:${t}`)),i.onerror=()=>r(i.error),i.readAsDataURL(e)})}async function aU(e,t,n){let r=new DOMParser().parseFromString(e,`text/html`),i=new Map,a=e=>{let t=i.get(e);return t===void 0&&(t=n(e).catch(()=>void 0),i.set(e,t)),t},o=async e=>(await a(e))?.text(),s=async e=>{let t=await a(e);return t===void 0?void 0:iU(t,rU(e,t.type||`application/octet-stream`))},c=async(e,t,n=0)=>{let r=[...e.matchAll(/@import\s+(?:url\(\s*(['"]?)([^'")]+)\1\s*\)|(['"])([^'"]+)\3)[^;]*;/gi)];for(let i of r){let r=i[2]??i[4];if(!nU(r)||n>=$H)continue;let a=oe(t,r),s=await o(a);s!==void 0&&(e=e.replace(i[0],await c(s,a,n+1)))}let i=/url\(\s*(['"]?)([^'")]+)\1\s*\)/gi,a=new Map;for(let n of new Set([...e.matchAll(i)].map(e=>e[2]))){if(!nU(n))continue;let e=await s(oe(t,n));e!==void 0&&a.set(n,e)}return e.replace(i,(e,t,n)=>a.has(n)?`url("${a.get(n)}")`:e)},l=Array.from(r.querySelectorAll(`style`));for(let e of Array.from(r.querySelectorAll(`link[href]`))){let n=(e.getAttribute(`rel`)??``).toLowerCase().split(/\s+/),i=e.getAttribute(`href`);if(!nU(i))continue;let a=oe(t,i);if(n.includes(`stylesheet`)){let t=await o(a);if(t===void 0)continue;let n=r.createElement(`style`),i=e.getAttribute(`media`);i!==null&&n.setAttribute(`media`,i),n.textContent=await c(t,a),e.replaceWith(n)}else if(n.includes(`icon`)){let t=await s(a);t!==void 0&&e.setAttribute(`href`,t)}}for(let e of l)e.textContent=await c(e.textContent??``,t);for(let e of Array.from(r.querySelectorAll(`[style]`)))e.setAttribute(`style`,await c(e.getAttribute(`style`)??``,t));for(let e of Array.from(r.querySelectorAll(`script[src]`))){let n=e.getAttribute(`src`);if(!nU(n))continue;let r=await o(oe(t,n));r!==void 0&&(e.removeAttribute(`src`),e.textContent=r.replace(/<\/script/gi,`<\\/script`))}for(let[e,n]of[[`img`,`src`],[`source`,`src`],[`video`,`src`],[`video`,`poster`],[`audio`,`src`],[`track`,`src`],[`input`,`src`],[`image`,`href`],[`image`,`xlink:href`],[`use`,`href`]])for(let i of Array.from(r.getElementsByTagName(e))){let e=i.getAttribute(n);if(!nU(e))continue;let r=await s(oe(t,e));r!==void 0&&i.setAttribute(n,r)}for(let e of Array.from(r.querySelectorAll(`img[srcset], source[srcset]`))){let n=(e.getAttribute(`srcset`)??``).split(`,`).map(e=>e.trim()).filter(Boolean),r=[];for(let e of n){let[n,...i]=e.split(/\s+/),a=nU(n)?await s(oe(t,n)):void 0;r.push([a??n,...i].join(` `))}e.setAttribute(`srcset`,r.join(`, `))}let u=r.createElement(`script`);return u.textContent=tU,r.head.prepend(u),`<!doctype html>\n${r.documentElement.outerHTML}`}var oU=`allow-scripts allow-popups allow-popups-to-escape-sandbox`;function sU({source:e,path:t,load:n,onOpen:r}){let i=(0,v.useRef)(null),[a,o]=(0,v.useState)(null);return(0,v.useEffect)(()=>{let r=!0;return aU(e,t,n).then(e=>{r&&o(e)},()=>{r&&o(e)}),()=>{r=!1}},[e,t,n]),(0,v.useEffect)(()=>{function e(e){if(i.current===null||e.source!==i.current.contentWindow)return;let n=e.data;typeof n==`object`&&n&&n.type===`pi-outpost:open`&&typeof n.href==`string`&&r(oe(t,n.href))}return window.addEventListener(`message`,e),()=>window.removeEventListener(`message`,e)},[t,r]),a===null?(0,N.jsx)(`div`,{className:`p-4 text-sm text-zinc-500`,"data-testid":`html-page-loading`,children:`Loading…`}):(0,N.jsx)(`iframe`,{ref:i,title:t,"data-testid":`html-page`,sandbox:oU,srcDoc:a,className:`h-full min-h-[24rem] w-full border-0 bg-white`})}function cU({query:e,onQueryChange:t,matchCount:n,truncated:r=!1,currentIndex:i,searching:a=!1,onNext:o,onPrev:s,onClose:c,inputRef:l}){let u=(0,v.useRef)(null),d=l??u;(0,v.useEffect)(()=>{d.current?.focus(),d.current?.select()},[]);let f=n===0?a?`searching…`:`0/0`:`${i+1}/${n}${r?`+`:``}`;return(0,N.jsxs)(`div`,{role:`search`,"aria-label":`Find in file`,className:`flex items-center gap-2 border-b border-zinc-200 bg-zinc-50 px-3 py-1.5 text-xs dark:border-zinc-800 dark:bg-zinc-900`,children:[(0,N.jsx)(`input`,{ref:d,type:`text`,value:e,onChange:e=>t(e.target.value),onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),e.shiftKey?s():o()):e.key===`Escape`&&(e.stopPropagation(),c())},placeholder:`Find in file`,"aria-label":`Find`,className:`min-w-0 flex-1 rounded border border-zinc-300 bg-white px-2 py-1 text-xs text-zinc-700 outline-none focus-visible:ring-1 focus-visible:ring-zinc-400 dark:border-zinc-700 dark:bg-zinc-950 dark:text-zinc-200`}),(0,N.jsx)(`span`,{className:`shrink-0 tabular-nums text-zinc-500 dark:text-zinc-400`,children:f}),(0,N.jsx)(`button`,{type:`button`,onClick:s,disabled:n===0,"aria-label":`Previous match`,title:`Previous match (Shift+Enter)`,className:`shrink-0 rounded px-1.5 py-0.5 text-zinc-500 hover:bg-zinc-200 disabled:opacity-40 dark:text-zinc-400 dark:hover:bg-zinc-800`,children:`‹`}),(0,N.jsx)(`button`,{type:`button`,onClick:o,disabled:n===0,"aria-label":`Next match`,title:`Next match (Enter)`,className:`shrink-0 rounded px-1.5 py-0.5 text-zinc-500 hover:bg-zinc-200 disabled:opacity-40 dark:text-zinc-400 dark:hover:bg-zinc-800`,children:`›`}),(0,N.jsx)(`button`,{type:`button`,onClick:c,"aria-label":`Close find bar`,title:`Close (Esc)`,className:`shrink-0 rounded px-1.5 py-0.5 text-zinc-500 hover:bg-zinc-200 dark:text-zinc-400 dark:hover:bg-zinc-800`,children:`✕`})]})}var lU=3e3;function uU(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function dU(e,t,n=1/0){if(t===``)return[];let r=new RegExp(uU(t),`gi`),i=[],a;for(;(a=r.exec(e))!==null&&(i.push({start:a.index,end:a.index+a[0].length}),!(i.length>=n)););return i}function fU(e){let t=document.createTreeWalker(e,NodeFilter.SHOW_TEXT),n=[],r=``;for(let e=t.nextNode();e!==null;e=t.nextNode()){let t=e.data.length;t!==0&&(n.push({node:e,start:r.length,end:r.length+t}),r+=e.data)}return{nodes:n,text:r}}function pU(e,t,n=lU){let r={matches:[],truncated:!1,clear:()=>{}};if(t===``)return r;let{nodes:i,text:a}=fU(e);if(a===``)return r;let o=dU(a,t,n+1),s=o.length>n,c=s?o.slice(0,n):o;if(c.length===0)return{matches:[],truncated:s,clear:()=>{}};let l=Array(c.length);for(let e=c.length-1;e>=0;e--){let{start:t,end:n}=c[e],r=[];for(let e of i){if(e.end<=t||e.start>=n)continue;let i=Math.max(0,t-e.start),a=Math.min(e.node.data.length,n-e.start);if(i>=a)continue;let o=e.node;a<o.data.length&&o.splitText(a);let s=i>0?o.splitText(i):o,c=document.createElement(`mark`);c.className=`find-match`,s.replaceWith(c),c.appendChild(s),r.push(c)}l[e]={marks:r}}return{matches:l,truncated:s,clear:()=>{for(let{marks:e}of l)for(let t of e)t.replaceWith(document.createTextNode(t.textContent??``));e.normalize()}}}var mU=(0,v.lazy)(()=>ye(()=>import(`./PdfViewer-Bon2alNC.js`),[])),hU=250,gU=`(min-width: 768px)`;function _U(){let[e,t]=(0,v.useState)(()=>window.matchMedia?.(gU).matches??!0);return(0,v.useEffect)(()=>{let e=window.matchMedia?.(gU);if(e===void 0)return;let n=()=>t(e.matches);return n(),e.addEventListener?.(`change`,n),()=>e.removeEventListener?.(`change`,n)},[]),e}function vU(e,t){let[n,r]=(0,v.useState)(e);return(0,v.useEffect)(()=>{let n=window.setTimeout(()=>r(e),t);return()=>window.clearTimeout(n)},[e,t]),n}function yU(e){let t=Su(e);return t.status===`valid`?t.envelope:void 0}var bU=`shrink-0 rounded px-1.5 py-0.5 text-xs text-zinc-400 hover:bg-zinc-100 hover:text-zinc-700 dark:text-zinc-600 dark:hover:bg-zinc-800 dark:hover:text-zinc-300`;function xU(e){return/\.(md|markdown)$/i.test(e)}var SU=ce;function CU(e){return/\.html?$/i.test(e)}function wU(e){return/\.poster\.html$/i.test(e)}function TU(e,t){return t===void 0?!0:t===null?!1:t===``||e===t||e.startsWith(`${t}/`)}function EU({file:e,writableRoot:t,isStreaming:n,onDirtyChange:r,gitState:i,initialShowGitDiff:a=!1,gitDiff:o,gitBaseline:s=null,onFetchGitDiff:c,onClearGitDiff:l,inRepository:u,onOpenGitHistory:d,onClose:f,onReload:p,onSave:m,serverUrl:h=``,token:g=null,workspace:_,docxTemplate:y,onImageLoad:b,onPdfLoad:x,rawRevision:S=0,onOpenNative:C}){let[w,T]=(0,v.useState)(`rendered`),[E,D]=(0,v.useState)(null),[O,te]=(0,v.useState)(a),[k,ne]=(0,v.useState)(e.status===`loaded`&&e.justCreated?{draft:e.content,baseContent:e.content,baseMtimeMs:e.mtimeMs}:null),[A,j]=(0,v.useState)(`idle`),ie=(0,v.useRef)(null),[ae,ce]=(0,v.useState)(0),ue=(0,v.useCallback)(()=>ce(e=>e+1),[]),fe=(0,v.useRef)(null),M=e.status===`loaded`?e:null,pe=M!==null&&xU(e.path),he=M!==null&&wU(e.path),ge=M!==null&&CU(e.path)&&!he,P=M!==null&&SU(e.path),_e=se(e.path),ve=le(e.path),ye=(0,v.useMemo)(()=>M===null?void 0:Su(M.content),[M?.content]),be=ye?.status===`valid`,xe=ye?.status===`valid`||ye?.status===`invalid`,Se=xe||pe||ge||P,Ce=w===`source`,we=_U(),Ee=TU(e.path,t)&&!ve,De=M!==null&&!_e&&!ve;(0,v.useEffect)(()=>{De&&HH().catch(()=>{})},[De]);let Oe=k!==null&&k.draft!==k.baseContent,[ke,Ae]=(0,v.useState)(!1),je=Oe||ke,Me=M?.pendingSave!==void 0,Ne=k!==null&&M!==null&&M.mtimeMs!==k.baseMtimeMs,Pe=M?.saveError?.conflict===!0||Ne,Fe=k?.draft??M?.content??``,Ie=vU(Fe,hU),Le=(0,v.useMemo)(()=>M===null?void 0:Su(Ie),[Ie,M===null]),[Re,ze]=(0,v.useState)(()=>e.status===`loaded`?yU(e.content):void 0);(0,v.useEffect)(()=>{Le?.status===`valid`&&ze(Le.envelope)},[Le]);let Be=Le!==void 0&&Le.status!==`valid`&&Re!==void 0,Ve=Le?.status===`invalid`?Ie===M?.content&&M.documentIssues!==void 0?M.documentIssues:Le.issues:void 0,He=Le?.status===`not-a-document`?Le.why===`unparseable`?`This is not parseable JSON yet.`:"This no longer declares a structured-exchange `schema`.":Le?.status===`unsupported-version`?`This declares ${Le.schema}, which this version does not render.`:void 0,Ue=w===`split`&&Se&&!O&&M!==null&&we,We=O?void 0:Ue?xe?Re:void 0:k===null&&!Ce&&ye?.status===`valid`?ye.envelope:void 0,Ge=(0,v.useRef)(null),Ke=k!==null,qe=M!==null&&k===null&&!Ue&&!O&&(!pe||Ce)&&(!be||Ce)&&(!ge||Ce)&&(!P||Ce)&&(!he||Ce),Ye=O||Ue?`none`:ve?`pdf`:k!==null||qe?`text`:M!==null&&!_e?`dom`:`none`,[Xe,Qe]=(0,v.useState)(!1),[$e,et]=(0,v.useState)(``),[tt,nt]=(0,v.useState)(0),rt=(0,v.useRef)(null),it=(0,v.useRef)(null),at=(0,v.useRef)(null),[ot,st]=(0,v.useState)({matchCount:0,currentIndex:-1,searching:!1}),[ct,lt]=(0,v.useState)([]),[ut,dt]=(0,v.useState)(!1),ft=(0,v.useRef)(null),pt=(0,v.useRef)([]),mt=(0,v.useRef)(0),ht=(0,v.useRef)(``);function gt(e){mt.current=e;for(let[t,n]of pt.current.entries())for(let r of n.marks)r.isConnected&&r.classList.toggle(`find-match-current`,t===e);let t=pt.current[e]?.marks;t?.[0]?.isConnected&&t[0].scrollIntoView({block:`center`})}let _t=Xe?$e:``,vt=(0,v.useMemo)(()=>Ye===`text`?dU(Fe,_t):[],[Ye,Fe,_t]);(0,v.useEffect)(()=>{Xe&&Ye===`none`&&Qe(!1)},[Xe,Ye]),(0,v.useEffect)(()=>{function e(){ft.current?.clear(),ft.current=null,pt.current=[],lt([]),dt(!1)}let t=it.current;if(Ye!==`dom`||_t===``||t===null){e();return}ft.current?.clear();let n=pU(t,_t);ft.current=n,pt.current=n.matches,lt(n.matches),dt(n.truncated);let r=_t!==ht.current;ht.current=_t;let i=r?0:Math.min(mt.current,Math.max(n.matches.length-1,0));return nt(i),gt(i),e},[Ye,_t,w,Ce]);function yt(e,t){let n=e[t];n!==void 0&&ie.current?.select(n.start,n.end)}(0,v.useEffect)(()=>{if(Ye!==`text`||!Xe)return;let e=dU(Fe,_t),t=_t!==ht.current;ht.current=_t;let n=t?0:Math.min(tt,Math.max(e.length-1,0));nt(n),e.length>0&&yt(e,n)},[_t,Ye,Xe,Ke,ae]),(0,v.useEffect)(()=>{ie.current?.markMatches(Ye===`text`?vt:[],tt)},[Ye,vt,tt,Ke,ae]);let bt=M?.reveal,[xt,St]=(0,v.useState)(void 0);(0,v.useEffect)(()=>{if(bt!==void 0&&M!==null){if(bt.page!==void 0)St({page:bt.page});else if(bt.line!==void 0){k===null&&T(`source`);let e=dU(Fe,bt.query),t=DU(Fe,bt.line),n=e.findIndex(e=>e.start>=t);ht.current=bt.query,nt(n===-1?0:n)}et(bt.query),Qe(!0)}},[bt]);function Ct(){Qe(!0)}function wt(){Qe(!1)}function Tt(){if(Ye===`pdf`)at.current?.findNext();else if(Ye===`text`){if(vt.length===0)return;let e=(tt+1)%vt.length;nt(e),yt(vt,e)}else{let e=pt.current.length;if(e===0)return;let t=(mt.current+1)%e;nt(t),gt(t)}}function Et(){if(Ye===`pdf`)at.current?.findPrevious();else if(Ye===`text`){if(vt.length===0)return;let e=(tt-1+vt.length)%vt.length;nt(e),yt(vt,e)}else{let e=pt.current.length;if(e===0)return;let t=(mt.current-1+e)%e;nt(t),gt(t)}}let Dt=Ye===`pdf`?{matchCount:ot.matchCount,currentIndex:ot.currentIndex,truncated:!1,searching:ot.searching}:Ye===`text`?{matchCount:vt.length,currentIndex:vt.length>0?Math.min(tt,vt.length-1):-1,truncated:!1,searching:!1}:{matchCount:ct.length,currentIndex:ct.length>0?Math.min(tt,ct.length-1):-1,truncated:ut,searching:!1},Ot=k===null?null:(0,N.jsx)(v.Suspense,{fallback:(0,N.jsx)(`div`,{className:`p-4 text-sm text-zinc-400 dark:text-zinc-600`,children:`loading editor…`}),children:(0,N.jsx)(UH,{handle:ie,onReady:ue,path:e.path,value:k.draft,baseline:s,onChange:e=>ne(t=>t===null?t:{...t,draft:e}),onSave:()=>{Oe&&!Me&&!Pe&&It()}})},`editor`);function kt(t){return M===null?null:(0,N.jsx)(v.Suspense,{fallback:(0,N.jsx)(`div`,{className:`p-4`,children:(0,N.jsx)(Te,{code:M.content,path:e.path})}),children:(0,N.jsx)(UH,{readOnly:!0,handle:t?ie:void 0,onReady:t?ue:void 0,path:e.path,value:M.content,baseline:s})},`source`)}let At=(0,v.useCallback)(e=>fetch(de(h,e,g,void 0,_)).then(e=>e.ok?e.blob():void 0,()=>void 0),[h,g,_]);function jt(t){return(0,N.jsx)(`div`,{className:`prose-chat mx-auto max-w-3xl p-4 text-zinc-700 dark:text-zinc-300`,children:(0,N.jsx)(SC,{remarkPlugins:[dz,Cz],rehypePlugins:[WA],components:{pre:Je,a:({href:t,children:n,...r})=>!t||/^[a-z][a-z0-9+.-]*:/i.test(t)?(0,N.jsx)(`a`,{href:t,target:`_blank`,rel:`noreferrer`,...r,children:n}):t.startsWith(`#`)?(0,N.jsx)(`a`,{href:t,...r,children:n}):(0,N.jsx)(`a`,{href:t,onClick:n=>{n.preventDefault(),p(oe(e.path,t))},...r,children:n}),img:({src:t,alt:n,...r})=>{let i=typeof t==`string`&&t!==``&&!/^[a-z][a-z0-9+.-]*:/i.test(t)&&!t.startsWith(`//`)?de(h,oe(e.path,t),g,void 0,_):t;return(0,N.jsx)(`img`,{...r,src:i,alt:n??``,loading:`lazy`,className:`max-w-full rounded-lg`})}},children:re(t)})})}function Mt(e){(w!==`split`||e===`split`||!Oe||window.confirm(`Discard unsaved changes?`))&&(e===w||!ke||window.confirm(`Discard unsaved changes?`))&&(w===`split`&&e!==`split`&&ne(null),D(null),T(e))}function Nt(){(!je||window.confirm(`Discard unsaved changes?`))&&f()}function Pt(){M&&(!ke||window.confirm(`Discard unsaved changes?`))&&(Se&&w===`rendered`?(D(`rendered`),T(we?`split`:`source`)):he&&w===`rendered`&&(D(`rendered`),T(`source`)),ne({draft:M.content,baseContent:M.content,baseMtimeMs:M.mtimeMs}))}function Ft(){E===null?ne(Ue&&M!==null?{draft:M.content,baseContent:M.content,baseMtimeMs:M.mtimeMs}:null):(ne(null),T(E),D(null))}function It(t=!1){M&&k!==null&&!Me&&(fe.current=k.draft,m(e.path,k.draft,k.baseMtimeMs,t))}function Lt(){ne(null),p(e.path)}function Rt(){let t=!O;te(t),t?c(e.path):l()}return(0,v.useEffect)(()=>{k!==null&&M!==null&&fe.current!==null&&M.content===fe.current&&M.mtimeMs!==k.baseMtimeMs&&(fe.current=null,ne({...k,baseContent:M.content,baseMtimeMs:M.mtimeMs}))},[M?.mtimeMs]),(0,v.useEffect)(()=>{function e(e){if(e.key===`Escape`)Xe?wt():Nt();else if((e.metaKey||e.ctrlKey)&&e.key.toLowerCase()===`f`){if(Ye===`none`)return;e.preventDefault(),Ct()}}return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)}),(0,v.useEffect)(()=>{Ue&&Ee&&k===null&&M!==null&&ne({draft:M.content,baseContent:M.content,baseMtimeMs:M.mtimeMs})},[Ue,Ee,M?.mtimeMs]),(0,v.useEffect)(()=>{j(n?`streaming`:e=>e===`streaming`?`done`:e)},[n]),(0,v.useEffect)(()=>(r(je),()=>r(!1)),[je]),(0,v.useEffect)(()=>(a&&c(e.path),()=>l()),[]),(0,N.jsxs)(`div`,{className:`absolute inset-0 z-20 flex flex-col bg-white dark:bg-zinc-950`,children:[(0,N.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-zinc-200 px-3 py-2 dark:border-zinc-800`,children:[(Se||he)&&!O&&(0,N.jsx)(`div`,{className:`flex shrink-0 items-center gap-0.5`,role:`group`,"aria-label":`How to show this document`,children:[[`rendered`,`⚏ rendered`,`Show the rendering`],[`split`,`⇹ split`,`Edit the file beside its rendering`],[`source`,`⌗ source`,`Show the file as written`]].filter(([e])=>!(he&&e===`split`)).map(([e,t,n])=>(0,N.jsx)(`button`,{type:`button`,onClick:()=>Mt(e),"aria-pressed":w===e,title:n,className:`rounded px-1.5 py-0.5 text-xs ${w===e?`bg-zinc-100 text-zinc-700 dark:bg-zinc-800 dark:text-zinc-200`:`text-zinc-400 hover:bg-zinc-100 hover:text-zinc-700 dark:text-zinc-600 dark:hover:bg-zinc-800 dark:hover:text-zinc-300`}`,children:t},e))}),i!==void 0&&k===null&&(0,N.jsx)(`button`,{type:`button`,onClick:Rt,"aria-pressed":O,title:O?`Show file content`:`Show uncommitted changes (vs HEAD)`,className:`shrink-0 rounded px-1.5 py-0.5 text-xs ${O?`bg-amber-100 text-amber-800 dark:bg-amber-950/60 dark:text-amber-300`:`text-zinc-400 hover:bg-zinc-100 hover:text-zinc-700 dark:text-zinc-600 dark:hover:bg-zinc-800 dark:hover:text-zinc-300`}`,children:`± diff`}),u&&k===null&&(0,N.jsx)(`button`,{type:`button`,onClick:()=>d(e.path),title:`Show this file's history`,className:`shrink-0 rounded px-1.5 py-0.5 text-xs text-zinc-400 hover:bg-zinc-100 hover:text-zinc-700 dark:text-zinc-600 dark:hover:bg-zinc-800 dark:hover:text-zinc-300`,children:`⎇ history`}),(0,N.jsxs)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-xs text-zinc-500 dark:text-zinc-400`,title:e.path,children:[e.path,je&&(0,N.jsx)(`span`,{className:`ml-1 text-amber-500`,children:`●`})]}),P&&C&&(0,N.jsx)(`button`,{type:`button`,onClick:()=>C(e.path),title:`Open with the application associated with .drawio files — draw.io desktop, where it is installed`,className:`shrink-0 rounded border border-zinc-300 px-2 py-0.5 text-xs text-zinc-600 hover:border-zinc-400 hover:text-zinc-900 dark:border-zinc-700 dark:text-zinc-300 dark:hover:border-zinc-500 dark:hover:text-zinc-100`,children:`↗ open in draw.io`}),M&&!_e&&!ve&&!P&&!he&&!O&&!xe&&(0,N.jsx)(WH,{text:Fe,path:e.path,serverUrl:h,token:g,workspace:_,template:y}),We?.kind===`table`&&(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(WH,{text:()=>Ge.current?.markdown?.()??``,path:`${e.path.replace(/\.[^./]*$/,``)}.md`,serverUrl:h,token:g,workspace:_,template:y}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>Ge.current?.xlsx?.(),title:`Download as an Excel workbook`,"aria-label":`Download as an Excel workbook`,className:bU,children:`⤓ excel`})]}),(We?.kind===`graph`||We?.kind===`sequence`||We?.kind===`timeline`)&&(0,N.jsx)(`button`,{type:`button`,onClick:()=>Ge.current?.svg?.(),title:`Download the figure as SVG`,"aria-label":`Download the figure as SVG`,className:bU,children:`⤓ svg`}),M&&k===null&&(0,N.jsx)(me,{text:M.content}),M&&k===null&&!O&&Ee&&(0,N.jsx)(`button`,{type:`button`,onClick:Pt,className:`shrink-0 rounded border border-zinc-300 px-2 py-0.5 text-xs text-zinc-500 hover:border-zinc-400 hover:text-zinc-700 dark:border-zinc-700 dark:text-zinc-400 dark:hover:border-zinc-500 dark:hover:text-zinc-200`,children:`✎ edit`}),M&&k===null&&!Ee&&(0,N.jsx)(`span`,{className:`shrink-0 text-xs text-zinc-400 dark:text-zinc-600`,title:`Outside the writable zone`,children:`🔒 read-only`}),k!==null&&(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`button`,{type:`button`,onClick:()=>It(),disabled:!Oe||Me||Pe,className:`shrink-0 rounded border border-emerald-300 px-2 py-0.5 text-xs text-emerald-700 hover:border-emerald-500 disabled:opacity-50 dark:border-emerald-900 dark:text-emerald-400 dark:hover:border-emerald-600`,children:Me?`saving…`:`save`}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>{(!Oe||window.confirm(`Discard unsaved changes?`))&&Ft()},className:`shrink-0 rounded border border-zinc-300 px-2 py-0.5 text-xs text-zinc-500 hover:border-zinc-400 dark:border-zinc-700 dark:text-zinc-400 dark:hover:border-zinc-500`,children:Oe?`cancel`:`done`})]}),(0,N.jsx)(`button`,{type:`button`,onClick:Nt,title:`Close (Esc)`,"aria-label":`Close file viewer`,className:`shrink-0 px-1 text-sm text-zinc-400 hover:text-zinc-600 dark:text-zinc-600 dark:hover:text-zinc-300`,children:`✕`})]}),Xe&&Ye!==`none`&&(0,N.jsx)(cU,{inputRef:rt,query:$e,onQueryChange:et,matchCount:Dt.matchCount,currentIndex:Dt.currentIndex,truncated:Dt.truncated,searching:Dt.searching,onNext:Tt,onPrev:Et,onClose:wt}),Pe&&k!==null&&(0,N.jsxs)(`div`,{className:`flex items-center gap-3 border-b border-amber-300 bg-amber-50 px-3 py-2 text-sm text-amber-800 dark:border-amber-900/60 dark:bg-amber-950/30 dark:text-amber-300`,children:[(0,N.jsx)(`span`,{className:`min-w-0 flex-1`,children:`File changed on disk since you started editing.`}),(0,N.jsx)(`button`,{type:`button`,onClick:Lt,className:`shrink-0 rounded border border-amber-400 px-2 py-0.5 text-xs hover:bg-amber-100 dark:border-amber-800 dark:hover:bg-amber-950/60`,children:`reload (discard my edits)`}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>It(!0),disabled:Me,className:`shrink-0 rounded border border-amber-400 px-2 py-0.5 text-xs hover:bg-amber-100 disabled:opacity-50 dark:border-amber-800 dark:hover:bg-amber-950/60`,children:`overwrite with my version`})]}),k!==null&&M?.saveError&&!M.saveError.conflict&&(0,N.jsx)(`div`,{className:`border-b border-red-300 bg-red-50 px-3 py-2 text-sm text-red-700 dark:border-red-900/60 dark:bg-red-950/30 dark:text-red-300`,children:M.saveError.message}),(0,N.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-auto`,children:[O&&k===null&&(0,N.jsxs)(`div`,{className:`p-4`,children:[o?.path===e.path&&`error`in o&&(0,N.jsx)(`div`,{className:`rounded-lg border border-red-300 bg-red-50 px-3 py-2 text-sm text-red-700 dark:border-red-900/60 dark:bg-red-950/30 dark:text-red-300`,children:o.error}),o?.path===e.path&&`before`in o&&(0,N.jsx)(Ze,{fill:!0,lines:ee(o.before,o.after)}),o?.path!==e.path&&(0,N.jsx)(`div`,{className:`text-sm text-zinc-400 dark:text-zinc-600`,children:`loading diff…`})]}),ve&&k===null&&!O&&(0,N.jsx)(Og,{label:`This PDF`,children:(0,N.jsx)(v.Suspense,{fallback:(0,N.jsx)(`div`,{className:`p-4 text-sm text-zinc-400 dark:text-zinc-600`,children:`loading…`}),children:(0,N.jsx)(mU,{ref:at,path:e.path,serverUrl:h,token:g,workspace:_,revision:S,findQuery:Ye===`pdf`?_t:``,onFindStateChange:st,...xt?{startAt:xt}:{},...x?{onLoaded:x}:{}})})}),_e&&k===null&&!O&&(0,N.jsx)(`div`,{className:`flex h-full items-center justify-center p-4`,children:(0,N.jsx)(`img`,{src:de(h,e.path,g,S,_),alt:e.path,onLoad:()=>b?.(e.path),className:`max-h-full max-w-full rounded object-contain`})}),e.status===`loading`&&k===null&&!O&&!_e&&!ve&&(0,N.jsx)(`div`,{className:`p-4 text-sm text-zinc-400 dark:text-zinc-600`,children:`loading…`}),e.status===`error`&&!_e&&!ve&&(0,N.jsx)(`div`,{className:`p-4 text-sm text-red-600 dark:text-red-400`,children:e.message}),k!==null&&!Ue&&Ot,M&&k===null&&!Ue&&!O&&pe&&!Ce&&(0,N.jsx)(`div`,{ref:it,children:jt(M.content)}),M&&k===null&&!Ue&&!O&&P&&!Ce&&(0,N.jsx)(`div`,{className:`h-full`,"data-testid":`file-drawio`,children:(0,N.jsx)(Uz,{path:e.path,xml:M.content,variant:`viewer`,fallback:kt(!1),onTouchUpDirtyChange:Ae})}),M&&k===null&&!Ue&&!O&&he&&!Ce&&(0,N.jsx)(`div`,{className:`h-full`,"data-testid":`file-poster`,children:(0,N.jsx)(ZH,{path:e.path,content:M.content,mtimeMs:M.mtimeMs,writable:Ee,loadFile:At,fallback:kt(!1),onTouchUpDirtyChange:Ae})}),M&&k===null&&!Ue&&!O&&ge&&!Ce&&(0,N.jsx)(`div`,{className:`h-full`,"data-testid":`file-html`,children:(0,N.jsx)(sU,{source:M.content,path:e.path,load:At,onOpen:p})}),Ue&&(0,N.jsxs)(`div`,{className:`flex h-full min-h-0`,"data-testid":`file-split`,children:[(0,N.jsx)(`div`,{className:`min-w-0 flex-1 overflow-auto border-r border-zinc-200 dark:border-zinc-800`,children:Ot??kt(!1)}),(0,N.jsx)(`div`,{className:`min-w-0 flex-1 overflow-auto`,"data-testid":`file-split-rendering`,children:pe&&!xe?(0,N.jsx)(`div`,{className:`prose-chat p-4 text-zinc-700 dark:text-zinc-300`,children:jt(Ie)}):P&&!xe?(0,N.jsx)(Km,{xml:Ie,serverUrl:h,title:e.path}):ge&&!xe?(0,N.jsx)(sU,{source:Ie,path:e.path,load:At,onOpen:p}):(0,N.jsxs)(N.Fragment,{children:[Be&&(0,N.jsx)(`p`,{"data-testid":`file-split-stale`,className:`flex flex-wrap items-center gap-2 border-b border-amber-300 bg-amber-50 px-3 py-1.5 text-xs text-amber-900 dark:border-amber-700 dark:bg-amber-950/40 dark:text-amber-200`,children:(0,N.jsxs)(`span`,{children:[`Showing the document as it last stood.`,` `,He??`The text beside it does not satisfy the schema it declares.`]})}),Ve!==void 0&&(0,N.jsxs)(`ul`,{"data-testid":`file-split-issues`,className:`space-y-0.5 border-b border-zinc-200 px-3 py-1.5 text-xs text-zinc-500 dark:border-zinc-800 dark:text-zinc-400`,children:[Ve.slice(0,6).map((e,t)=>(0,N.jsxs)(`li`,{children:[(0,N.jsx)(`span`,{className:`font-mono opacity-70`,children:e.path===``?`(document)`:e.path}),` `,e.message]},t)),Ve.length>6&&(0,N.jsxs)(`li`,{className:`opacity-70`,children:[`…and `,Ve.length-6,` more`]})]}),Re===void 0?(0,N.jsxs)(`p`,{className:`p-4 text-sm text-zinc-400 dark:text-zinc-600`,"data-testid":`file-split-nothing`,children:[`Nothing to draw yet. `,He??`This document does not satisfy the schema it declares.`]}):(0,N.jsx)(Og,{label:`This diagram`,children:(0,N.jsx)(`div`,{className:`p-4`,"data-testid":`file-structured-exchange`,children:(0,N.jsx)(Tg,{envelope:Re,source:Fe,exportRef:Ge,file:{path:e.path,writable:Ee}})})})]})})]}),M&&k===null&&!Ue&&!O&&be&&!Ce&&ye?.status===`valid`&&(0,N.jsx)(Og,{label:`This diagram`,children:(0,N.jsx)(`div`,{className:`mx-auto max-w-5xl p-4`,"data-testid":`file-structured-exchange`,children:(0,N.jsx)(Tg,{envelope:ye.envelope,source:M.content,exportRef:Ge,file:{path:e.path,writable:Ee}})})}),M&&k===null&&!Ue&&!O&&ye?.status===`invalid`&&(0,N.jsxs)(`div`,{"data-testid":`file-structured-exchange-invalid`,className:`mx-4 mt-4 rounded-lg border border-amber-300 bg-amber-50 px-3 py-2 text-sm text-amber-900 dark:border-amber-800 dark:bg-amber-950/40 dark:text-amber-200`,children:[(0,N.jsx)(`p`,{className:`font-medium`,children:`This declares a structured-exchange document and does not satisfy the schema.`}),(0,N.jsxs)(`ul`,{className:`mt-1 space-y-0.5 text-xs`,children:[(M.documentIssues??ye.issues).slice(0,8).map((e,t)=>(0,N.jsxs)(`li`,{children:[(0,N.jsx)(`span`,{className:`font-mono opacity-70`,children:e.path===``?`(document)`:e.path}),` `,e.message]},t)),(M.documentIssues??ye.issues).length>8&&(0,N.jsxs)(`li`,{className:`opacity-70`,children:[`…and `,(M.documentIssues??ye.issues).length-8,` more`]})]})]}),M&&k===null&&!Ue&&!O&&ye?.status===`unsupported-version`&&(0,N.jsxs)(`div`,{"data-testid":`file-structured-exchange-unsupported`,className:`mx-4 mt-4 rounded-lg border border-zinc-300 bg-zinc-50 px-3 py-2 text-sm text-zinc-600 dark:border-zinc-700 dark:bg-zinc-900 dark:text-zinc-400`,children:[`This document declares `,(0,N.jsx)(`span`,{className:`font-mono`,children:ye.schema}),`, which this version does not render. Shown as text.`]}),qe&&kt(!0)]}),A!==`idle`&&(0,N.jsxs)(`button`,{type:`button`,onClick:Nt,"aria-live":`polite`,className:`flex items-center gap-2 border-t border-zinc-200 px-3 py-2 text-left text-sm hover:bg-zinc-50 dark:border-zinc-800 dark:hover:bg-zinc-900`,children:[A===`streaming`?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`span`,{"aria-hidden":!0,className:`h-2 w-2 animate-pulse motion-reduce:animate-none rounded-full bg-amber-500`}),(0,N.jsx)(`span`,{className:`text-amber-700 dark:text-amber-400`,children:`π is replying…`})]}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`span`,{"aria-hidden":!0,className:`h-2 w-2 rounded-full bg-emerald-500`}),(0,N.jsx)(`span`,{className:`text-emerald-700 dark:text-emerald-400`,children:`π replied`})]}),(0,N.jsx)(`span`,{className:`ml-auto text-xs text-zinc-400 dark:text-zinc-500`,children:`show conversation →`})]})]})}function DU(e,t){let n=0;for(let r=1;r<t;r++){let t=e.indexOf(`
867
- `,n);if(t===-1)return e.length;n=t+1}return n}function OU(e){return e.split(`
868
- `).map(e=>e.startsWith(`diff --git `)?{kind:`file`,text:e.slice(11)}:e.startsWith(`@@`)||e.startsWith(`+++`)||e.startsWith(`---`)||e.startsWith(`index `)?{kind:`hunk`,text:e}:e.startsWith(`+`)?{kind:`add`,text:e.slice(1)}:e.startsWith(`-`)?{kind:`del`,text:e.slice(1)}:{kind:`context`,text:e.startsWith(` `)?e.slice(1):e})}function kU({show:e,onClose:t}){return(0,v.useEffect)(()=>{function e(e){e.key===`Escape`&&(e.stopImmediatePropagation(),t())}return document.addEventListener(`keydown`,e,!0),()=>document.removeEventListener(`keydown`,e,!0)},[t]),(0,N.jsxs)(`div`,{className:`absolute inset-0 z-30 flex flex-col bg-white dark:bg-zinc-950`,children:[(0,N.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-zinc-200 px-3 py-2 dark:border-zinc-800`,children:[(0,N.jsx)(`span`,{className:`font-mono text-xs text-amber-600 dark:text-amber-500`,children:e.sha.slice(0,12)}),(0,N.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm text-zinc-500 dark:text-zinc-400`,children:`commit diff`}),(0,N.jsx)(`button`,{type:`button`,onClick:t,title:`Close (Esc)`,"aria-label":`Close commit diff`,className:`shrink-0 px-1 text-sm text-zinc-400 hover:text-zinc-600 dark:text-zinc-600 dark:hover:text-zinc-300`,children:`✕`})]}),e.truncated&&(0,N.jsx)(`div`,{className:`border-b border-amber-300 bg-amber-50 px-3 py-1.5 text-xs text-amber-800 dark:border-amber-900/60 dark:bg-amber-950/30 dark:text-amber-300`,children:`Patch truncated — showing the first 256 KiB.`}),(0,N.jsx)(`pre`,{className:`min-h-0 flex-1 overflow-auto p-3 font-mono text-xs leading-relaxed`,children:OU(e.patch).map((e,t)=>(0,N.jsxs)(`div`,{className:e.kind===`file`?`mt-3 border-t border-zinc-200 pt-2 font-bold text-zinc-700 first:mt-0 first:border-t-0 first:pt-0 dark:border-zinc-800 dark:text-zinc-200`:e.kind===`hunk`?`text-sky-600 dark:text-sky-400`:e.kind===`add`?`bg-emerald-50 text-emerald-800 dark:bg-emerald-950/40 dark:text-emerald-300`:e.kind===`del`?`bg-red-50 text-red-700 dark:bg-red-950/40 dark:text-red-300`:`text-zinc-500 dark:text-zinc-500`,children:[e.kind===`add`?`+ `:e.kind===`del`?`− `:``,e.text||` `]},t))})]})}var AU=[`off`,`minimal`,`low`,`medium`,`high`,`xhigh`],jU=`worktree`,MU={defaultWidth:288,minWidth:224,maxWidth:640,keyboardStep:16,storageKey:`pi-outpost.files-sidebar-width.v1`},NU={defaultWidth:416,minWidth:224,maxWidth:640,keyboardStep:16,storageKey:`pi-outpost.history-list-width.v1`},PU={defaultWidth:288,minWidth:160,maxWidth:640,keyboardStep:16,storageKey:`pi-outpost.terminal-height.v1`};function FU(e,t){return Number.isFinite(e)?Math.min(t.maxWidth,Math.max(t.minWidth,Math.round(e))):t.defaultWidth}function IU(e,t){return e===null||e.trim()===``?t.defaultWidth:FU(Number(e),t)}function LU(e,t){try{return IU((t??window.localStorage).getItem(e.storageKey),e)}catch{return e.defaultWidth}}function RU(e,t,n){try{(n??window.localStorage).setItem(t.storageKey,String(FU(e,t)))}catch{}}function zU(e,t=`x`){let[n,r]=(0,v.useState)(()=>LU(e)),i=(0,v.useRef)(n),a=(0,v.useRef)(null),o=(0,v.useCallback)(t=>{let n=FU(t,e);return i.current=n,r(n),n},[e]),s=(0,v.useCallback)(()=>{a.current!==null&&(a.current=null,RU(i.current,e))},[e]);return{width:n,separatorProps:{onPointerDown:e=>{e.isPrimary!==!1&&(e.button??0)===0&&(e.preventDefault(),e.currentTarget.setPointerCapture?.(e.pointerId),a.current={pointerId:e.pointerId,startX:t===`y`?e.clientY:e.clientX,startWidth:i.current})},onPointerMove:e=>{let n=a.current;n!==null&&n.pointerId===e.pointerId&&o(n.startWidth+(t===`y`?n.startX-e.clientY:e.clientX-n.startX))},onPointerUp:e=>{a.current?.pointerId===e.pointerId&&s()},onPointerCancel:e=>{let t=a.current;t!==null&&t.pointerId===e.pointerId&&(a.current=null,o(t.startWidth))},onLostPointerCapture:s,onKeyDown:n=>{let r=null;n.key===(t===`y`?`ArrowDown`:`ArrowLeft`)?r=i.current-e.keyboardStep:n.key===(t===`y`?`ArrowUp`:`ArrowRight`)?r=i.current+e.keyboardStep:n.key===`Home`&&(r=e.defaultWidth),r!==null&&(n.preventDefault(),RU(o(r),e))}}}}function BU({axis:e=`x`,label:t,width:n,config:r,separatorProps:i,className:a=``}){return(0,N.jsx)(`div`,{...i,role:`separator`,"aria-label":t,"aria-orientation":e===`y`?`horizontal`:`vertical`,"aria-valuemin":r.minWidth,"aria-valuemax":r.maxWidth,"aria-valuenow":n,tabIndex:0,title:t,className:`group absolute z-20 touch-none outline-none ${e===`y`?`inset-x-0 -top-1 h-2 cursor-row-resize`:`inset-y-0 -right-1 w-2 cursor-col-resize`} ${a}`,children:(0,N.jsx)(`span`,{className:`pointer-events-none absolute ${e===`y`?`inset-x-0 top-1/2 h-px`:`inset-y-0 left-1/2 w-px`} bg-transparent transition-colors group-hover:bg-blue-400 group-focus-visible:bg-blue-500 group-active:bg-blue-500 dark:group-hover:bg-blue-500`})})}var VU=`#10b981`,HU=[`#8b5cf6`,`#f59e0b`,`#0ea5e9`,`#f43f5e`,`#14b8a6`,`#d946ef`];function UU(e){return e===0?VU:HU[(e-1)%HU.length]}function WU(e){return HU[e%HU.length]}function GU(e){return e*14+7+1}function KU(e){return e*14+2}function qU({row:e,laneCount:t,colorOf:n=UU}){let r=KU(t),i=GU(e.lane),a=e.highlight?VU:n(e.lane),o=e.dashed?`3 3`:void 0;return(0,N.jsxs)(`svg`,{width:r,height:36,viewBox:`0 0 ${r} 36`,"aria-hidden":!0,className:`shrink-0`,children:[e.through.map(e=>(0,N.jsx)(`line`,{x1:GU(e),y1:0,x2:GU(e),y2:36,stroke:n(e),strokeWidth:2,opacity:.55},e)),e.lineAbove&&(0,N.jsx)(`line`,{x1:i,y1:0,x2:i,y2:18,stroke:a,strokeWidth:2,strokeDasharray:o}),e.lineBelow&&(0,N.jsx)(`line`,{x1:i,y1:18,x2:i,y2:36,stroke:a,strokeWidth:2,strokeDasharray:o}),e.forkTo.map(e=>(0,N.jsx)(`path`,{d:`M ${i} 18 C ${i} 36, ${GU(e)} 18, ${GU(e)} 36`,fill:`none`,stroke:n(e),strokeWidth:2,opacity:.75},`fork-${e}`)),(e.mergeFrom??[]).map(e=>(0,N.jsx)(`path`,{d:`M ${i} 18 C ${i} 0, ${GU(e)} 18, ${GU(e)} 0`,fill:`none`,stroke:n(e),strokeWidth:2,opacity:.75},`merge-${e}`)),e.emphasis===`current`?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`circle`,{cx:i,cy:18,r:6,fill:`none`,stroke:a,strokeWidth:2}),(0,N.jsx)(`circle`,{cx:i,cy:18,r:2.5,fill:a})]}):(0,N.jsx)(`circle`,{cx:i,cy:18,r:4,fill:e.emphasis===`filled`?a:`var(--tree-off, #d4d4d8)`,stroke:a,strokeWidth:e.emphasis===`filled`?0:1.5})]})}function JU(e,t){let n=[],r=t===void 0?[]:[t],i=r.length,a=t!==void 0,o=()=>{let e=r.indexOf(null);return e===-1?(r.push(null),i=Math.max(i,r.length),r.length-1):e};for(let s of e){let e=r.reduce((e,t,n)=>t===s.sha?[...e,n]:e,[]),c=e[0]??o();s.sha===t&&(a=!1);let l=(s.sha===t?e.length-1:e.length)===0,u=e.slice(1);for(let e of u)r[e]=null;i=Math.max(i,c+1);let[d,...f]=s.parents;r[c]=d??null;let p=f.map(e=>{let t=o();return r[t]=e,t});n.push({lane:c,through:r.reduce((e,t,n)=>t!==null&&n!==c&&!p.includes(n)&&!(a&&n===0)?[...e,n]:e,[]),forkTo:p,mergeFrom:u,tip:l})}return{lanes:n,laneCount:Math.max(i,1)}}function YU(e){let t=e.find(e=>e.head)?.sha,{lanes:n,laneCount:r}=JU(e,t);return{rows:e.map((e,t)=>{let{lane:r,through:i,forkTo:a,mergeFrom:o,tip:s}=n[t];return{lane:r,through:i,forkTo:a,mergeFrom:o,entry:e,lineAbove:!s,lineBelow:e.parents.length>0,emphasis:e.head?`current`:`filled`}}),laneCount:r}}function XU(e,t={}){let{lanes:n,laneCount:r}=JU(e),i=e.map((e,t)=>{let{lane:r,through:i,forkTo:a,mergeFrom:o}=n[t];return{lane:r,through:i,forkTo:a,mergeFrom:o,rev:e.sha,path:e.path,entry:e,lineAbove:!0,lineBelow:e.parents.length>0,emphasis:`filled`}}),a=i[0];return i.unshift({rev:jU,path:a?.path??``,lane:a?.lane??0,through:a?.through??[],forkTo:[],mergeFrom:[],lineAbove:!1,lineBelow:i.length>0,emphasis:`current`,dashed:!t.dirty}),i[1]&&(i[1].lineAbove=!0),{rows:i,laneCount:r}}var ZU=20;function QU(e){let t=(Date.now()-new Date(e).getTime())/1e3;return t<90?`now`:t<3600?`${Math.round(t/60)}m ago`:t<86400?`${Math.round(t/3600)}h ago`:`${Math.round(t/86400)}d ago`}function $U(e){return e.rev===`worktree`?`working tree`:e.rev.slice(0,7)}function eW(e,t){return e!==null&&t!==null&&e.rev===t.rev&&e.path===t.path}function tW(e){return{rev:e.rev,path:e.path}}function nW({history:e,diff:t,dirty:n,onFetchDiff:r,onClearDiff:i,onClose:a}){let[o,s]=(0,v.useState)({base:null,target:null}),{base:c,target:l}=o,[u,d]=(0,v.useState)(0),f=(0,v.useRef)([]),p=zU(NU),{rows:m,laneCount:h}=(0,v.useMemo)(()=>XU(e.entries,{dirty:n}),[e.entries,n]),g=(0,v.useRef)({onFetchDiff:r,onClose:a});g.current={onFetchDiff:r,onClose:a},(0,v.useEffect)(()=>{function e(e){e.key===`Escape`&&(e.stopImmediatePropagation(),g.current.onClose())}return document.addEventListener(`keydown`,e,!0),()=>document.removeEventListener(`keydown`,e,!0)},[]),(0,v.useEffect)(()=>{c===null||l===null||eW(c,l)||g.current.onFetchDiff(c,l)},[c,l]);let _=(0,v.useCallback)((e,t)=>{let n=tW(e);s(r=>{if(t===`base`)return{base:n,target:eW(n,r.target)?r.base:r.target};if(t===`target`)return{base:eW(n,r.base)?r.target:r.base,target:n};if(r.base===null&&r.target===null){let t=e.entry?.parents[0],r=t===void 0?void 0:m.find(e=>e.rev===t);return{base:r?tW(r):null,target:n}}return{base:eW(n,r.base)?r.target:r.base,target:n}})},[m]),y=(0,v.useCallback)(()=>{s({base:null,target:null}),i()},[i]),b=(0,v.useCallback)(()=>s(e=>({base:e.target,target:e.base})),[]),x=(0,v.useCallback)(e=>{d(t=>{let n=Math.max(0,Math.min(m.length-1,t+e));return f.current[n]?.focus(),n})},[m.length]),S=e=>{let t=tW(e);return eW(t,c)?`base`:eW(t,l)?`target`:null},C=m.findIndex(e=>eW(tW(e),c)),w=m.findIndex(e=>eW(tW(e),l)),T=C>=0&&w>=0?{top:Math.min(C,w)*36+18,height:Math.abs(w-C)*36}:null;return(0,N.jsxs)(`div`,{className:`absolute inset-0 z-30 flex flex-col bg-white dark:bg-zinc-950`,children:[(0,N.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-zinc-200 px-3 py-2 dark:border-zinc-800`,children:[(0,N.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-xs text-zinc-500 dark:text-zinc-400`,title:e.path,children:e.path}),c!==null&&l!==null&&(0,N.jsxs)(`span`,{className:`shrink-0 font-mono text-xs text-zinc-500 dark:text-zinc-400`,"aria-label":`Comparing ${$U(c)} to ${$U(l)}`,children:[(0,N.jsx)(`span`,{className:`text-amber-600 dark:text-amber-500`,children:$U(c)}),` → `,(0,N.jsx)(`span`,{className:`text-amber-600 dark:text-amber-500`,children:$U(l)})]}),c!==null&&l!==null&&(0,N.jsx)(`button`,{type:`button`,onClick:b,title:`Compare the other way round`,className:`shrink-0 rounded px-1.5 py-0.5 text-xs text-zinc-400 hover:bg-zinc-100 hover:text-zinc-700 dark:text-zinc-500 dark:hover:bg-zinc-800 dark:hover:text-zinc-200`,children:`⇄ swap`}),(c!==null||l!==null)&&(0,N.jsx)(`button`,{type:`button`,onClick:y,className:`shrink-0 rounded px-1.5 py-0.5 text-xs text-zinc-400 hover:bg-zinc-100 hover:text-zinc-700 dark:text-zinc-500 dark:hover:bg-zinc-800 dark:hover:text-zinc-200`,children:`clear`}),(0,N.jsx)(`button`,{type:`button`,onClick:a,title:`Close (Esc)`,"aria-label":`Close file history`,className:`shrink-0 px-1 text-sm text-zinc-400 hover:text-zinc-600 dark:text-zinc-600 dark:hover:text-zinc-300`,children:`✕`})]}),(0,N.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col md:flex-row`,children:[(0,N.jsxs)(`div`,{role:`region`,"aria-label":`Commit history`,style:{"--history-list-width":`${p.width}px`},className:`relative flex max-h-[40%] w-full shrink-0 flex-col border-b border-zinc-200 md:max-h-none md:w-[var(--history-list-width)] md:border-b-0 md:border-r dark:border-zinc-800`,children:[(0,N.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,onKeyDown:e=>{e.key===`ArrowDown`?(e.preventDefault(),x(1)):e.key===`ArrowUp`&&(e.preventDefault(),x(-1))},children:[e.status===`loading`&&(0,N.jsx)(`div`,{className:`px-3 py-2 text-xs text-zinc-500`,children:`Reading history…`}),e.status===`error`&&(0,N.jsx)(`div`,{className:`m-3 rounded-lg border border-red-300 bg-red-50 px-3 py-2 text-sm text-red-700 dark:border-red-900/60 dark:bg-red-950/30 dark:text-red-300`,children:e.error}),e.status===`loaded`&&e.entries.length===0&&(0,N.jsx)(`div`,{className:`px-3 py-2 text-xs text-zinc-500`,children:`No commits touch this file yet.`}),e.status===`loaded`&&e.entries.length>0&&(0,N.jsxs)(`div`,{className:`relative`,role:`group`,"aria-label":`Commits`,children:[T&&(0,N.jsx)(rW,{top:T.top,height:T.height,baseFirst:C<w}),m.map((e,t)=>(0,N.jsx)(oW,{ref:e=>{f.current[t]=e},row:e,laneCount:h,role:S(e),isFocused:t===u,onSelect:t=>_(e,t),onFocus:()=>d(t)},e.rev))]})]}),(0,N.jsx)(BU,{label:`Resize History commit list`,width:p.width,config:NU,separatorProps:p.separatorProps,className:`hidden md:block`})]}),(0,N.jsx)(`div`,{role:`region`,"aria-label":`History diff`,className:`min-h-0 min-w-0 flex-1 overflow-auto p-3`,children:(0,N.jsx)(sW,{diff:t,base:c,target:l})})]})]})}function rW({top:e,height:t,baseFirst:n}){return(0,N.jsxs)(`div`,{"aria-hidden":!0,className:`pointer-events-none absolute left-0 z-10 motion-safe:transition-all motion-safe:duration-150 motion-safe:ease-out`,style:{top:e,height:t,width:ZU},children:[(0,N.jsx)(`div`,{className:`absolute inset-y-0 left-2 w-px bg-zinc-400 dark:bg-zinc-500`}),(0,N.jsx)(iW,{label:n?`base`:`target`,className:`top-0`}),(0,N.jsx)(iW,{label:n?`target`:`base`,className:`bottom-0`})]})}function iW({label:e,className:t}){return(0,N.jsx)(`div`,{className:`absolute left-2 flex h-px w-2.5 items-center bg-zinc-400 dark:bg-zinc-500 ${t}`,children:(0,N.jsx)(`span`,{className:`absolute -left-1 -top-1.5 rotate-180 text-[9px] leading-none text-zinc-500 [writing-mode:vertical-rl] dark:text-zinc-400`,children:e})})}var aW=`shrink-0 rounded px-1 py-0.5 text-[10px] text-zinc-400 opacity-0 hover:bg-zinc-200 hover:text-zinc-700 focus-visible:opacity-100 group-hover:opacity-100 aria-disabled:cursor-default aria-disabled:opacity-30 dark:text-zinc-500 dark:hover:bg-zinc-700 dark:hover:text-zinc-200`;function oW({row:e,laneCount:t,role:n,isFocused:r,onSelect:i,onFocus:a,ref:o}){let s=e.entry,c=s?`${s.sha.slice(0,7)} ${s.subject}`:`Working tree`;return(0,N.jsxs)(`div`,{ref:o,role:`button`,tabIndex:r?0:-1,"aria-label":c,"aria-current":n===null?void 0:`true`,onFocus:a,onClick:()=>i(),onKeyDown:e=>{e.target===e.currentTarget&&(e.key===`Enter`||e.key===` `?(e.preventDefault(),i()):e.key===`b`?i(`base`):e.key===`t`&&i(`target`))},style:{height:36,paddingLeft:ZU},className:`group flex cursor-pointer items-center gap-2 pr-2 focus:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-zinc-400 hover:bg-zinc-100 dark:hover:bg-zinc-800/70 ${n===null?``:`bg-zinc-100 dark:bg-zinc-800/60`}`,children:[(0,N.jsx)(qU,{row:e,laneCount:t}),s?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`span`,{className:`shrink-0 font-mono text-xs text-amber-600 dark:text-amber-500`,children:s.sha.slice(0,7)}),(0,N.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm text-zinc-700 dark:text-zinc-300`,title:s.subject,children:s.subject}),(0,N.jsxs)(`span`,{className:`shrink-0 text-[10px] text-zinc-400 dark:text-zinc-600`,children:[s.author,` · `,QU(s.date)]}),(0,N.jsxs)(`span`,{className:`shrink-0 font-mono text-[10px] tabular-nums`,"aria-label":`${s.added} lines added, ${s.deleted} removed`,children:[(0,N.jsxs)(`span`,{className:`text-emerald-600 dark:text-emerald-500`,children:[`+`,s.added]}),` `,(0,N.jsxs)(`span`,{className:`text-red-600 dark:text-red-400`,children:[`−`,s.deleted]})]})]}):(0,N.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm text-zinc-500 dark:text-zinc-400`,children:`working tree`}),(0,N.jsxs)(`span`,{className:`flex shrink-0 gap-0.5`,children:[(0,N.jsx)(`button`,{type:`button`,title:n===`target`?`Make this the base (swaps the two)`:`Compare from this version`,onClick:e=>{e.stopPropagation(),i(`base`)},className:aW,children:`base`}),(0,N.jsx)(`button`,{type:`button`,title:n===`base`?`Make this the target (swaps the two)`:`Compare to this version`,onClick:e=>{e.stopPropagation(),i(`target`)},className:aW,children:`target`})]})]})}function sW({diff:e,base:t,target:n}){return t===null&&n===null?(0,N.jsx)(`p`,{className:`text-sm text-zinc-400 dark:text-zinc-600`,children:`Pick a commit to see what changed.`}):t===null||n===null?(0,N.jsx)(`p`,{className:`text-sm text-zinc-400 dark:text-zinc-600`,children:`Now pick the version to compare it against.`}):e?.status===`error`?(0,N.jsx)(`div`,{className:`rounded-lg border border-red-300 bg-red-50 px-3 py-2 text-sm text-red-700 dark:border-red-900/60 dark:bg-red-950/30 dark:text-red-300`,children:e.error}):e===null?(0,N.jsx)(`p`,{className:`text-sm text-zinc-400 dark:text-zinc-600`,children:`Loading…`}):e.status===`loaded`&&e.beforeText===e.afterText?(0,N.jsx)(`p`,{className:`text-sm text-zinc-400 dark:text-zinc-600`,children:`These two versions are identical.`}):e.status===`loaded`&&O(e.beforeText,e.afterText)?(0,N.jsx)(`p`,{className:`text-sm text-zinc-400 dark:text-zinc-600`,children:`These two versions differ only in their line endings.`}):(0,N.jsx)(`div`,{className:e.status===`loading`?`opacity-40`:void 0,children:(0,N.jsx)(Ze,{fill:!0,lines:ee(e.beforeText,e.afterText)})})}var cW=`inline-flex h-7 shrink-0 items-center gap-1 whitespace-nowrap rounded-md border px-2 text-xs leading-none`,lW=`inline-flex h-7 min-w-0 items-center gap-1 whitespace-nowrap rounded-md border px-2 text-xs leading-none`;function uW(e){let t=e.filter(e=>!e.sideOf).flatMap(t=>[t,...e.filter(e=>e.sideOf===t.root)]);return[...t,...e.filter(e=>!t.includes(e))]}var dW={stopped:`stopped`,starting:`starting…`,idle:`idle`,working:`working`,waiting:`waiting for you`,"ready-for-review":`ready for review`};function fW({activity:e}){switch(e){case`stopped`:return(0,N.jsx)(`span`,{className:`h-2 w-2 shrink-0 rounded-full border border-dashed border-zinc-400 dark:border-zinc-600`});case`starting`:return(0,N.jsx)(`svg`,{className:`h-2.5 w-2.5 shrink-0 animate-spin text-zinc-500 dark:text-zinc-400`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`3.5`,strokeLinecap:`round`,children:(0,N.jsx)(`path`,{d:`M12 3a9 9 0 0 1 9 9`})});case`working`:return(0,N.jsxs)(`span`,{className:`relative flex h-2 w-2 shrink-0 items-center justify-center`,children:[(0,N.jsx)(`span`,{className:`absolute h-2 w-2 animate-ping rounded-full bg-blue-700 opacity-60 dark:bg-blue-400`}),(0,N.jsx)(`span`,{className:`relative h-2 w-2 rounded-full bg-blue-700 dark:bg-blue-400`})]});case`waiting`:return(0,N.jsx)(`span`,{className:`h-2 w-2 shrink-0 rounded-full bg-amber-500`});case`ready-for-review`:return(0,N.jsx)(`span`,{className:`h-2 w-2 shrink-0 rotate-45 rounded-[1px] border-2 border-violet-600 bg-violet-100 dark:border-violet-400 dark:bg-violet-950`});default:return(0,N.jsx)(`span`,{className:`h-1.5 w-1.5 shrink-0 rounded-full bg-zinc-400 dark:bg-zinc-600`})}}function pW({className:e}){return(0,N.jsxs)(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,"aria-hidden":`true`,children:[(0,N.jsx)(`path`,{d:`M12 6v7`}),(0,N.jsx)(`path`,{d:`M12 18h.01`})]})}function mW({className:e}){return(0,N.jsxs)(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,N.jsx)(`path`,{d:`M7 3h10v18H7z`}),(0,N.jsx)(`path`,{d:`m9.5 12 1.7 1.7 3.5-3.7`})]})}function hW(e){let{workspace:t,workspaces:n,locked:r}=e,[i,a]=(0,v.useState)(!1),o=(0,v.useRef)(null);if((0,v.useEffect)(()=>{if(!i)return;let e=e=>{iH(e,o.current)||a(!1)},t=e=>{e.key===`Escape`&&a(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[i]),r||!t)return null;let s=n.filter(e=>GB(e)!==GB(t)),c=n.filter(e=>!e.sideOf).length,l=n.filter(e=>e.needsAttention);return(0,N.jsxs)(`div`,{ref:o,className:`relative min-w-[4rem] max-w-[16rem]`,children:[(0,N.jsxs)(`button`,{type:`button`,onClick:()=>a(e=>!e),"aria-expanded":i,"aria-haspopup":`menu`,title:`Project: ${t.name} (${dW[t.activity]})`,className:`${lW} max-w-full gap-1.5 ${l.length>0?`border-amber-500 bg-amber-50 text-zinc-700 dark:bg-amber-950/40 dark:text-zinc-200`:`border-zinc-400 bg-zinc-100 text-zinc-700 dark:border-zinc-600 dark:bg-zinc-800 dark:text-zinc-200`}`,children:[(0,N.jsx)(fW,{activity:t.activity}),(0,N.jsx)(`span`,{className:`truncate font-medium`,children:t.name}),l.length>0?(0,N.jsxs)(`span`,{className:`flex items-center gap-1 text-amber-600 dark:text-amber-500`,children:[(0,N.jsx)(pW,{className:`h-3 w-3`}),(0,N.jsx)(`span`,{className:`font-semibold`,children:l.length})]}):s.some(e=>e.activity===`working`)&&(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`span`,{className:`h-3 w-px bg-zinc-300 dark:bg-zinc-600`}),(0,N.jsx)(`span`,{className:`flex items-center gap-1`,children:s.map(e=>e.activity===`working`?(0,N.jsxs)(`span`,{className:`relative flex h-1.5 w-1.5 items-center justify-center`,children:[(0,N.jsx)(`span`,{className:`absolute h-1.5 w-1.5 animate-ping rounded-full bg-blue-700 opacity-60 dark:bg-blue-400`}),(0,N.jsx)(`span`,{className:`relative h-1.5 w-1.5 rounded-full bg-blue-700 dark:bg-blue-400`})]},GB(e)):(0,N.jsx)(`span`,{className:`h-1 w-1 rounded-full bg-zinc-300 dark:bg-zinc-600`},GB(e)))})]}),(0,N.jsx)(`svg`,{className:`h-3 w-3 text-zinc-500`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,N.jsx)(`path`,{d:`m6 9 6 6 6-6`})})]}),i&&(0,N.jsxs)(`div`,{role:`menu`,className:`absolute left-0 top-full z-40 mt-1 w-87 rounded-md border border-zinc-300 bg-white p-1 shadow-lg dark:border-zinc-700 dark:bg-zinc-900`,children:[uW(n).map(n=>{let r=GB(n),i=r===GB(t),o=n.sideOf!==void 0;return(0,N.jsxs)(`div`,{"data-testid":o?`side-session-row`:`project-row`,className:`group flex items-center gap-2.5 rounded-md py-2 pr-2.5 ${o?`pl-7`:`pl-2.5`} ${i?`bg-zinc-100 dark:bg-zinc-800`:`hover:bg-zinc-50 dark:hover:bg-zinc-800/50`}`,children:[(0,N.jsxs)(`button`,{type:`button`,role:`menuitem`,onClick:()=>{a(!1),o?e.onSwitch(n.root,n.id):e.onSwitch(n.root)},className:`flex min-w-0 flex-1 items-center gap-2.5 text-left`,children:[(0,N.jsx)(fW,{activity:n.activity}),(0,N.jsxs)(`span`,{className:`flex min-w-0 flex-col gap-0.5`,children:[(0,N.jsx)(`span`,{className:`truncate text-[13px] ${i?`font-semibold text-zinc-900 dark:text-zinc-100`:`font-medium text-zinc-900 dark:text-zinc-100`}`,children:o?n.label??n.name:n.name}),!o&&(0,N.jsx)(`span`,{className:`truncate font-mono text-[11px] text-zinc-400 dark:text-zinc-500`,children:n.root})]})]}),(0,N.jsxs)(`span`,{className:`flex shrink-0 items-center gap-1.5`,children:[n.needsAttention?(0,N.jsxs)(`span`,{className:`flex items-center gap-1 text-[11px] font-medium ${n.activity===`ready-for-review`?`text-violet-700 dark:text-violet-400`:`text-amber-600 dark:text-amber-500`}`,children:[n.activity===`ready-for-review`?(0,N.jsx)(mW,{className:`h-3 w-3`}):(0,N.jsx)(pW,{className:`h-3 w-3`}),dW[n.activity]]}):(0,N.jsx)(`span`,{className:`text-[11px] ${n.activity===`working`?`text-blue-700 dark:text-blue-400`:`text-zinc-400 dark:text-zinc-500`}`,children:dW[n.activity]}),!o&&e.onOpenSide&&(0,N.jsx)(`button`,{type:`button`,title:`New side session on ${n.name}`,"aria-label":`New side session on ${n.name}`,onClick:t=>{t.stopPropagation(),a(!1),e.onOpenSide?.(n.root)},className:`flex h-5 w-5 items-center justify-center rounded border border-zinc-300 text-zinc-500 hover:border-zinc-400 hover:text-zinc-800 dark:border-zinc-600 dark:text-zinc-400 dark:hover:border-zinc-500 dark:hover:text-zinc-100`,children:(0,N.jsxs)(`svg`,{className:`h-2.5 w-2.5`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,children:[(0,N.jsx)(`path`,{d:`M12 5v14`}),(0,N.jsx)(`path`,{d:`M5 12h14`})]})}),(o||c>1)&&(0,N.jsx)(`button`,{type:`button`,title:`Close ${o?n.label??n.name:n.name}`,"aria-label":`Close ${o?n.label??n.name:n.name}`,onClick:t=>{t.stopPropagation(),o?e.onClose(n.root,n.id):e.onClose(n.root)},className:`flex h-5 w-5 items-center justify-center rounded border border-transparent text-zinc-400 opacity-0 group-hover:border-zinc-300 group-hover:opacity-100 hover:text-zinc-700 dark:group-hover:border-zinc-600 dark:hover:text-zinc-200`,children:(0,N.jsxs)(`svg`,{className:`h-2.5 w-2.5`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,children:[(0,N.jsx)(`path`,{d:`M18 6 6 18`}),(0,N.jsx)(`path`,{d:`m6 6 12 12`})]})})]})]},r)}),(0,N.jsx)(`div`,{className:`my-1 h-px bg-zinc-200 dark:bg-zinc-700`}),(0,N.jsxs)(`button`,{type:`button`,role:`menuitem`,onClick:()=>{a(!1),e.onOpen()},className:`flex w-full items-center gap-2.5 rounded-md px-2.5 py-2 text-left text-[13px] text-zinc-700 hover:bg-zinc-50 dark:text-zinc-300 dark:hover:bg-zinc-800/50`,children:[(0,N.jsxs)(`svg`,{className:`h-3.5 w-3.5 text-zinc-500`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,N.jsx)(`path`,{d:`M12 5v14`}),(0,N.jsx)(`path`,{d:`M5 12h14`})]}),`Open a project…`]})]})]})}function gW({label:e,browse:t,onBrowse:n,onSelect:r,onCancel:i}){let a=t?.path??`/`,o=t?.entries??[],s=t?.status===`loading`,[c,l]=(0,v.useState)(a);return(0,v.useEffect)(()=>{l(a)},[a]),(0,N.jsxs)(`div`,{className:`rounded-md border border-zinc-300 p-2 dark:border-zinc-700`,"data-testid":`server-path-picker`,children:[(0,N.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[(0,N.jsx)(`span`,{className:`text-xs font-semibold text-zinc-600 dark:text-zinc-300`,children:e}),(0,N.jsx)(`button`,{type:`button`,onClick:i,className:`text-xs text-zinc-500 hover:text-zinc-800 dark:text-zinc-400 dark:hover:text-zinc-200`,children:`Cancel`})]}),(0,N.jsxs)(`form`,{className:`mb-2 flex gap-1`,onSubmit:e=>{e.preventDefault();let t=c.trim();t&&n(t)},children:[(0,N.jsx)(`input`,{value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Escape`&&(e.stopPropagation(),l(a))},spellCheck:!1,autoCapitalize:`off`,autoCorrect:`off`,"aria-label":`Current directory`,"data-testid":`picker-path`,className:`min-w-0 flex-1 rounded border border-zinc-300 px-2 py-1 font-mono text-xs text-zinc-700 focus:border-zinc-500 focus:outline-none dark:border-zinc-700 dark:bg-zinc-900 dark:text-zinc-200`}),(0,N.jsx)(`button`,{type:`submit`,disabled:c.trim()===``||c===a,className:`rounded border border-zinc-300 px-2 py-1 text-xs text-zinc-600 hover:border-zinc-400 disabled:cursor-not-allowed disabled:opacity-40 dark:border-zinc-700 dark:text-zinc-300`,children:`Go`})]}),t?.status===`error`&&(0,N.jsx)(`p`,{role:`alert`,className:`mb-2 text-xs text-red-600 dark:text-red-400`,children:t.error}),(0,N.jsxs)(`div`,{className:`mb-2 flex gap-2`,children:[(0,N.jsx)(`button`,{type:`button`,disabled:!t?.parent,onClick:()=>t?.parent&&n(t.parent),className:`rounded border border-zinc-300 px-2 py-1 text-xs text-zinc-600 hover:border-zinc-400 disabled:cursor-not-allowed disabled:opacity-40 dark:border-zinc-700 dark:text-zinc-300`,children:`Up`}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>r(a),className:`rounded bg-zinc-800 px-2 py-1 text-xs font-medium text-white hover:bg-zinc-700 dark:bg-zinc-200 dark:text-zinc-900`,children:`Use this directory`})]}),(0,N.jsxs)(`ul`,{className:`max-h-40 overflow-y-auto`,children:[s&&o.length===0&&(0,N.jsx)(`li`,{className:`px-2 py-1 text-xs text-zinc-400`,children:`Loading…`}),!s&&o.length===0&&t?.status!==`error`&&(0,N.jsx)(`li`,{className:`px-2 py-1 text-xs text-zinc-400 dark:text-zinc-500`,children:`No subdirectories`}),o.map(e=>(0,N.jsx)(`li`,{children:(0,N.jsxs)(`button`,{type:`button`,onClick:()=>n(e.path),className:`w-full truncate rounded px-2 py-1 text-left font-mono text-xs text-zinc-600 hover:bg-zinc-100 dark:text-zinc-300 dark:hover:bg-zinc-800`,title:e.path,children:[e.name,e.name.endsWith(`:`)?`\\`:`/`]})},e.path))]})]})}function _W(e){return e.split(/[\\/]/).filter(Boolean).at(-1)??e}function vW(e){let{sandbox:t,applyState:n,blocked:r=!1,onCloseBrowser:i}=e,[a,o]=(0,v.useState)(!1),s=(0,v.useRef)(!1);if((0,v.useEffect)(()=>{r&&a&&(s.current=!1,o(!1))},[r,a]),(0,v.useEffect)(()=>{s.current&&n?.status!==`applying`&&(n?.status===`error`?s.current=!1:(s.current=!1,o(!1),i()))},[n,i]),!t)return(0,N.jsx)(`span`,{className:`${cW} border-dashed border-zinc-300 text-zinc-400 dark:border-zinc-700 dark:text-zinc-500`,title:`This server runs without a sandbox, so there is no root to move`,children:`No sandbox`});let c=t.locks?.root===!0,l=_W(t.root);return(0,N.jsxs)(`div`,{className:`relative min-w-[4rem] max-w-[14rem]`,children:[(0,N.jsxs)(`button`,{type:`button`,disabled:c,"aria-label":c?`Sandbox root: ${t.root} (locked)`:`Sandbox root: ${t.root}`,title:c?`${t.root} — locked by the server's configuration`:t.root,onClick:()=>{e.onOpened(),o(!0),e.onBrowse(t.root)},className:`${lW} max-w-full gap-1.5 ${c?`cursor-not-allowed border-zinc-200 text-zinc-400 dark:border-zinc-800 dark:text-zinc-500`:`border-zinc-300 text-zinc-600 hover:border-zinc-400 hover:text-zinc-800 dark:border-zinc-700 dark:text-zinc-300 dark:hover:border-zinc-500 dark:hover:text-zinc-100`}`,children:[(0,N.jsx)(`span`,{className:`truncate font-mono`,children:l}),c?(0,N.jsx)(`span`,{className:`text-zinc-400`,children:`(locked)`}):(0,N.jsx)(`span`,{"aria-hidden":`true`,children:`▾`})]}),a&&!r&&(0,N.jsxs)(`div`,{className:`absolute left-0 top-full z-20 mt-1 w-[380px] rounded-lg border border-zinc-200 bg-white p-2 shadow-xl dark:border-zinc-700 dark:bg-zinc-900`,children:[n?.status===`error`&&(0,N.jsx)(`p`,{role:`alert`,className:`mb-2 text-xs text-red-600 dark:text-red-400`,children:n.message}),(0,N.jsx)(gW,{label:`Choose the sandbox root`,browse:e.browse,onBrowse:e.onBrowse,onSelect:t=>{s.current=!0,e.onSelect(t)},onCancel:()=>{s.current=!1,o(!1),i()}})]})]})}function yW(e){let t=(Date.now()-new Date(e).getTime())/1e3;return t<90?`now`:t<3600?`${Math.round(t/60)}m ago`:t<86400?`${Math.round(t/3600)}h ago`:`${Math.round(t/86400)}d ago`}function bW(e){return e.slice(e.lastIndexOf(`/`)+1)}function xW({status:e,selected:t,log:n,onFetchLog:r,onCloseLog:i,onShowCommit:a}){let[o,s]=(0,v.useState)(!1),c=()=>{s(!1),i()},l=aH(()=>{o&&c()}),u=e?.repos??[],d=(t===null?null:NV(u,t))??(t===null&&u.length===1?u[0]:null),f=d&&(d.ahead>0||d.behind>0)?` ${d.ahead>0?`↑${d.ahead}`:``}${d.behind>0?`↓${d.behind}`:``}`:``,p=u.length>1&&d!==null&&d.repo!==``?`${bW(d.repo)} `:``,m=e===null?`…`:d?.branch??`—`,h=d!==null&&n?.repo===d.repo?n:null,g=h?.entries??null,_=h?.error??null,y=(0,v.useMemo)(()=>g===null?null:YU(g),[g]);return(0,v.useEffect)(()=>{o&&d!==null&&n?.repo!==d.repo&&r(d.repo)},[o,d?.repo,r]),(0,N.jsxs)(`div`,{className:`relative min-w-[4rem] max-w-[14rem] shrink-[2]`,ref:l,children:[(0,N.jsxs)(`button`,{type:`button`,disabled:d===null,onClick:()=>{if(d!==null){if(o)return c();s(!0),r(d.repo)}},title:d===null?`no repository selected`:`git history — ${d.repo===``?`this project`:d.repo}`,className:`${lW} max-w-full border-zinc-300 font-mono text-zinc-500 hover:border-zinc-400 hover:text-zinc-700 disabled:cursor-default disabled:hover:border-zinc-300 disabled:hover:text-zinc-500 dark:border-zinc-800 dark:text-zinc-400 dark:hover:border-zinc-600 dark:hover:text-zinc-200 dark:disabled:hover:border-zinc-800 dark:disabled:hover:text-zinc-400`,children:[(0,N.jsxs)(`span`,{className:`truncate`,children:[p,`⎇ `,m]}),f]}),o&&d!==null&&(0,N.jsxs)(`div`,{className:`absolute left-0 top-full z-20 mt-1 max-h-96 w-[26rem] max-w-[80vw] overflow-y-auto rounded-lg border border-zinc-200 bg-white py-1 shadow-xl dark:border-zinc-700 dark:bg-zinc-900`,children:[_!==null&&(0,N.jsxs)(`div`,{role:`alert`,className:`px-3 py-2 text-xs text-red-600 dark:text-red-400`,children:[`history unavailable: `,_]}),g===null&&_===null&&(0,N.jsx)(`div`,{className:`px-3 py-2 text-xs text-zinc-500`,children:`loading…`}),g?.length===0&&(0,N.jsx)(`div`,{className:`px-3 py-2 text-xs text-zinc-500`,children:`no commits`}),y?.rows.map(e=>{let{entry:t}=e;return(0,N.jsxs)(`button`,{type:`button`,onClick:()=>{a(d.repo,t.sha),c()},style:{height:36},className:`flex w-full items-center gap-2 pl-2 pr-3 text-left text-sm hover:bg-zinc-100 dark:hover:bg-zinc-800`,children:[(0,N.jsx)(qU,{row:e,laneCount:y.laneCount}),(0,N.jsx)(`span`,{className:`shrink-0 font-mono text-xs text-amber-600 dark:text-amber-500`,children:t.sha.slice(0,7)}),t.refs.map(t=>{let n=t===d.branch?`#10b981`:UU(e.lane);return(0,N.jsx)(`span`,{style:{borderColor:n,color:n},className:`max-w-[8rem] shrink-0 truncate rounded-full border px-1.5 font-mono text-[10px] leading-4 ${t===d.branch?`font-semibold`:``}`,children:t},t)}),t.tags.map(e=>(0,N.jsxs)(`span`,{title:`tag ${e}`,className:`max-w-[8rem] shrink-0 truncate rounded border border-zinc-300 px-1 font-mono text-[10px] leading-4 text-zinc-500 dark:border-zinc-600 dark:text-zinc-400`,children:[`◆ `,e]},`tag-${e}`)),(0,N.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-zinc-700 dark:text-zinc-300`,title:t.subject,children:t.subject}),(0,N.jsxs)(`span`,{className:`shrink-0 text-xs text-zinc-400 dark:text-zinc-600`,children:[t.author,` · `,yW(t.date)]})]},t.sha)})]})]})}var SW=[{name:`draw.io / diagrams.net`,website:`https://www.drawio.com/`,license:`Apache-2.0`,text:` Apache License
866
+ })();`;function rU(e){if(e==null)return!1;let t=e.trim();return t!==``&&!t.startsWith(`#`)&&!ae(t)}function iU(e,t){return tU[e.split(`.`).pop()?.toLowerCase()??``]??t}function aU(e,t){return new Promise((n,r)=>{let i=new FileReader;i.onload=()=>n(String(i.result).replace(/^data:[^;,]*/,`data:${t}`)),i.onerror=()=>r(i.error),i.readAsDataURL(e)})}async function oU(e,t,n){let r=new DOMParser().parseFromString(e,`text/html`),i=new Map,a=e=>{let t=i.get(e);return t===void 0&&(t=n(e).catch(()=>void 0),i.set(e,t)),t},o=async e=>(await a(e))?.text(),s=async e=>{let t=await a(e);return t===void 0?void 0:aU(t,iU(e,t.type||`application/octet-stream`))},c=async(e,t,n=0)=>{let r=[...e.matchAll(/@import\s+(?:url\(\s*(['"]?)([^'")]+)\1\s*\)|(['"])([^'"]+)\3)[^;]*;/gi)];for(let i of r){let r=i[2]??i[4];if(!rU(r)||n>=eU)continue;let a=oe(t,r),s=await o(a);s!==void 0&&(e=e.replace(i[0],await c(s,a,n+1)))}let i=/url\(\s*(['"]?)([^'")]+)\1\s*\)/gi,a=new Map;for(let n of new Set([...e.matchAll(i)].map(e=>e[2]))){if(!rU(n))continue;let e=await s(oe(t,n));e!==void 0&&a.set(n,e)}return e.replace(i,(e,t,n)=>a.has(n)?`url("${a.get(n)}")`:e)},l=Array.from(r.querySelectorAll(`style`));for(let e of Array.from(r.querySelectorAll(`link[href]`))){let n=(e.getAttribute(`rel`)??``).toLowerCase().split(/\s+/),i=e.getAttribute(`href`);if(!rU(i))continue;let a=oe(t,i);if(n.includes(`stylesheet`)){let t=await o(a);if(t===void 0)continue;let n=r.createElement(`style`),i=e.getAttribute(`media`);i!==null&&n.setAttribute(`media`,i),n.textContent=await c(t,a),e.replaceWith(n)}else if(n.includes(`icon`)){let t=await s(a);t!==void 0&&e.setAttribute(`href`,t)}}for(let e of l)e.textContent=await c(e.textContent??``,t);for(let e of Array.from(r.querySelectorAll(`[style]`)))e.setAttribute(`style`,await c(e.getAttribute(`style`)??``,t));for(let e of Array.from(r.querySelectorAll(`script[src]`))){let n=e.getAttribute(`src`);if(!rU(n))continue;let r=await o(oe(t,n));r!==void 0&&(e.removeAttribute(`src`),e.textContent=r.replace(/<\/script/gi,`<\\/script`))}for(let[e,n]of[[`img`,`src`],[`source`,`src`],[`video`,`src`],[`video`,`poster`],[`audio`,`src`],[`track`,`src`],[`input`,`src`],[`image`,`href`],[`image`,`xlink:href`],[`use`,`href`]])for(let i of Array.from(r.getElementsByTagName(e))){let e=i.getAttribute(n);if(!rU(e))continue;let r=await s(oe(t,e));r!==void 0&&i.setAttribute(n,r)}for(let e of Array.from(r.querySelectorAll(`img[srcset], source[srcset]`))){let n=(e.getAttribute(`srcset`)??``).split(`,`).map(e=>e.trim()).filter(Boolean),r=[];for(let e of n){let[n,...i]=e.split(/\s+/),a=rU(n)?await s(oe(t,n)):void 0;r.push([a??n,...i].join(` `))}e.setAttribute(`srcset`,r.join(`, `))}let u=r.createElement(`script`);return u.textContent=nU,r.head.prepend(u),`<!doctype html>\n${r.documentElement.outerHTML}`}var sU=`allow-scripts allow-popups allow-popups-to-escape-sandbox`;function cU({source:e,path:t,load:n,onOpen:r}){let i=(0,v.useRef)(null),[a,o]=(0,v.useState)(null);return(0,v.useEffect)(()=>{let r=!0;return oU(e,t,n).then(e=>{r&&o(e)},()=>{r&&o(e)}),()=>{r=!1}},[e,t,n]),(0,v.useEffect)(()=>{function e(e){if(i.current===null||e.source!==i.current.contentWindow)return;let n=e.data;typeof n==`object`&&n&&n.type===`pi-outpost:open`&&typeof n.href==`string`&&r(oe(t,n.href))}return window.addEventListener(`message`,e),()=>window.removeEventListener(`message`,e)},[t,r]),a===null?(0,N.jsx)(`div`,{className:`p-4 text-sm text-zinc-500`,"data-testid":`html-page-loading`,children:`Loading…`}):(0,N.jsx)(`iframe`,{ref:i,title:t,"data-testid":`html-page`,sandbox:sU,srcDoc:a,className:`h-full min-h-[24rem] w-full border-0 bg-white`})}function lU({query:e,onQueryChange:t,matchCount:n,truncated:r=!1,currentIndex:i,searching:a=!1,onNext:o,onPrev:s,onClose:c,inputRef:l}){let u=(0,v.useRef)(null),d=l??u;(0,v.useEffect)(()=>{d.current?.focus(),d.current?.select()},[]);let f=n===0?a?`searching…`:`0/0`:`${i+1}/${n}${r?`+`:``}`;return(0,N.jsxs)(`div`,{role:`search`,"aria-label":`Find in file`,className:`flex items-center gap-2 border-b border-zinc-200 bg-zinc-50 px-3 py-1.5 text-xs dark:border-zinc-800 dark:bg-zinc-900`,children:[(0,N.jsx)(`input`,{ref:d,type:`text`,value:e,onChange:e=>t(e.target.value),onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),e.shiftKey?s():o()):e.key===`Escape`&&(e.stopPropagation(),c())},placeholder:`Find in file`,"aria-label":`Find`,className:`min-w-0 flex-1 rounded border border-zinc-300 bg-white px-2 py-1 text-xs text-zinc-700 outline-none focus-visible:ring-1 focus-visible:ring-zinc-400 dark:border-zinc-700 dark:bg-zinc-950 dark:text-zinc-200`}),(0,N.jsx)(`span`,{className:`shrink-0 tabular-nums text-zinc-500 dark:text-zinc-400`,children:f}),(0,N.jsx)(`button`,{type:`button`,onClick:s,disabled:n===0,"aria-label":`Previous match`,title:`Previous match (Shift+Enter)`,className:`shrink-0 rounded px-1.5 py-0.5 text-zinc-500 hover:bg-zinc-200 disabled:opacity-40 dark:text-zinc-400 dark:hover:bg-zinc-800`,children:`‹`}),(0,N.jsx)(`button`,{type:`button`,onClick:o,disabled:n===0,"aria-label":`Next match`,title:`Next match (Enter)`,className:`shrink-0 rounded px-1.5 py-0.5 text-zinc-500 hover:bg-zinc-200 disabled:opacity-40 dark:text-zinc-400 dark:hover:bg-zinc-800`,children:`›`}),(0,N.jsx)(`button`,{type:`button`,onClick:c,"aria-label":`Close find bar`,title:`Close (Esc)`,className:`shrink-0 rounded px-1.5 py-0.5 text-zinc-500 hover:bg-zinc-200 dark:text-zinc-400 dark:hover:bg-zinc-800`,children:`✕`})]})}var uU=3e3;function dU(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function fU(e,t,n=1/0){if(t===``)return[];let r=new RegExp(dU(t),`gi`),i=[],a;for(;(a=r.exec(e))!==null&&(i.push({start:a.index,end:a.index+a[0].length}),!(i.length>=n)););return i}function pU(e){let t=document.createTreeWalker(e,NodeFilter.SHOW_TEXT),n=[],r=``;for(let e=t.nextNode();e!==null;e=t.nextNode()){let t=e.data.length;t!==0&&(n.push({node:e,start:r.length,end:r.length+t}),r+=e.data)}return{nodes:n,text:r}}function mU(e,t,n=uU){let r={matches:[],truncated:!1,clear:()=>{}};if(t===``)return r;let{nodes:i,text:a}=pU(e);if(a===``)return r;let o=fU(a,t,n+1),s=o.length>n,c=s?o.slice(0,n):o;if(c.length===0)return{matches:[],truncated:s,clear:()=>{}};let l=Array(c.length);for(let e=c.length-1;e>=0;e--){let{start:t,end:n}=c[e],r=[];for(let e of i){if(e.end<=t||e.start>=n)continue;let i=Math.max(0,t-e.start),a=Math.min(e.node.data.length,n-e.start);if(i>=a)continue;let o=e.node;a<o.data.length&&o.splitText(a);let s=i>0?o.splitText(i):o,c=document.createElement(`mark`);c.className=`find-match`,s.replaceWith(c),c.appendChild(s),r.push(c)}l[e]={marks:r}}return{matches:l,truncated:s,clear:()=>{for(let{marks:e}of l)for(let t of e)t.replaceWith(document.createTextNode(t.textContent??``));e.normalize()}}}var hU=(0,v.lazy)(()=>ye(()=>import(`./PdfViewer-BTK9Pwfa.js`),[])),gU=250,_U=`(min-width: 768px)`;function vU(){let[e,t]=(0,v.useState)(()=>window.matchMedia?.(_U).matches??!0);return(0,v.useEffect)(()=>{let e=window.matchMedia?.(_U);if(e===void 0)return;let n=()=>t(e.matches);return n(),e.addEventListener?.(`change`,n),()=>e.removeEventListener?.(`change`,n)},[]),e}function yU(e,t){let[n,r]=(0,v.useState)(e);return(0,v.useEffect)(()=>{let n=window.setTimeout(()=>r(e),t);return()=>window.clearTimeout(n)},[e,t]),n}function bU(e){let t=Su(e);return t.status===`valid`?t.envelope:void 0}var xU=`shrink-0 rounded px-1.5 py-0.5 text-xs text-zinc-400 hover:bg-zinc-100 hover:text-zinc-700 dark:text-zinc-600 dark:hover:bg-zinc-800 dark:hover:text-zinc-300`;function SU(e){return/\.(md|markdown)$/i.test(e)}var CU=ce;function wU(e){return/\.html?$/i.test(e)}function TU(e){return/\.poster\.html$/i.test(e)}function EU(e,t){return t===void 0?!0:t===null?!1:t===``||e===t||e.startsWith(`${t}/`)}function DU({file:e,writableRoot:t,isStreaming:n,onDirtyChange:r,gitState:i,initialShowGitDiff:a=!1,gitDiff:o,gitBaseline:s=null,onFetchGitDiff:c,onClearGitDiff:l,inRepository:u,onOpenGitHistory:d,onClose:f,onReload:p,onSave:m,serverUrl:h=``,token:g=null,workspace:_,docxTemplate:y,onImageLoad:b,onPdfLoad:x,rawRevision:S=0,onOpenNative:C}){let[w,T]=(0,v.useState)(`rendered`),[E,D]=(0,v.useState)(null),[O,te]=(0,v.useState)(a),[k,ne]=(0,v.useState)(e.status===`loaded`&&e.justCreated?{draft:e.content,baseContent:e.content,baseMtimeMs:e.mtimeMs}:null),[A,j]=(0,v.useState)(`idle`),ie=(0,v.useRef)(null),[ae,ce]=(0,v.useState)(0),ue=(0,v.useCallback)(()=>ce(e=>e+1),[]),fe=(0,v.useRef)(null),M=e.status===`loaded`?e:null,pe=M!==null&&SU(e.path),he=M!==null&&TU(e.path),ge=M!==null&&wU(e.path)&&!he,P=M!==null&&CU(e.path),_e=se(e.path),ve=le(e.path),ye=(0,v.useMemo)(()=>M===null?void 0:Su(M.content),[M?.content]),be=ye?.status===`valid`,xe=ye?.status===`valid`||ye?.status===`invalid`,Se=xe||pe||ge||P,Ce=w===`source`,we=vU(),Ee=EU(e.path,t)&&!ve,De=M!==null&&!_e&&!ve;(0,v.useEffect)(()=>{De&&UH().catch(()=>{})},[De]);let Oe=k!==null&&k.draft!==k.baseContent,[ke,Ae]=(0,v.useState)(!1),je=Oe||ke,Me=M?.pendingSave!==void 0,Ne=k!==null&&M!==null&&M.mtimeMs!==k.baseMtimeMs,Pe=M?.saveError?.conflict===!0||Ne,Fe=k?.draft??M?.content??``,Ie=yU(Fe,gU),Le=(0,v.useMemo)(()=>M===null?void 0:Su(Ie),[Ie,M===null]),[Re,ze]=(0,v.useState)(()=>e.status===`loaded`?bU(e.content):void 0);(0,v.useEffect)(()=>{Le?.status===`valid`&&ze(Le.envelope)},[Le]);let Be=Le!==void 0&&Le.status!==`valid`&&Re!==void 0,Ve=Le?.status===`invalid`?Ie===M?.content&&M.documentIssues!==void 0?M.documentIssues:Le.issues:void 0,He=Le?.status===`not-a-document`?Le.why===`unparseable`?`This is not parseable JSON yet.`:"This no longer declares a structured-exchange `schema`.":Le?.status===`unsupported-version`?`This declares ${Le.schema}, which this version does not render.`:void 0,Ue=w===`split`&&Se&&!O&&M!==null&&we,We=O?void 0:Ue?xe?Re:void 0:k===null&&!Ce&&ye?.status===`valid`?ye.envelope:void 0,Ge=(0,v.useRef)(null),Ke=k!==null,qe=M!==null&&k===null&&!Ue&&!O&&(!pe||Ce)&&(!be||Ce)&&(!ge||Ce)&&(!P||Ce)&&(!he||Ce),Ye=O||Ue?`none`:ve?`pdf`:k!==null||qe?`text`:M!==null&&!_e?`dom`:`none`,[Xe,Qe]=(0,v.useState)(!1),[$e,et]=(0,v.useState)(``),[tt,nt]=(0,v.useState)(0),rt=(0,v.useRef)(null),it=(0,v.useRef)(null),at=(0,v.useRef)(null),[ot,st]=(0,v.useState)({matchCount:0,currentIndex:-1,searching:!1}),[ct,lt]=(0,v.useState)([]),[ut,dt]=(0,v.useState)(!1),ft=(0,v.useRef)(null),pt=(0,v.useRef)([]),mt=(0,v.useRef)(0),ht=(0,v.useRef)(``);function gt(e){mt.current=e;for(let[t,n]of pt.current.entries())for(let r of n.marks)r.isConnected&&r.classList.toggle(`find-match-current`,t===e);let t=pt.current[e]?.marks;t?.[0]?.isConnected&&t[0].scrollIntoView({block:`center`})}let _t=Xe?$e:``,vt=(0,v.useMemo)(()=>Ye===`text`?fU(Fe,_t):[],[Ye,Fe,_t]);(0,v.useEffect)(()=>{Xe&&Ye===`none`&&Qe(!1)},[Xe,Ye]),(0,v.useEffect)(()=>{function e(){ft.current?.clear(),ft.current=null,pt.current=[],lt([]),dt(!1)}let t=it.current;if(Ye!==`dom`||_t===``||t===null){e();return}ft.current?.clear();let n=mU(t,_t);ft.current=n,pt.current=n.matches,lt(n.matches),dt(n.truncated);let r=_t!==ht.current;ht.current=_t;let i=r?0:Math.min(mt.current,Math.max(n.matches.length-1,0));return nt(i),gt(i),e},[Ye,_t,w,Ce]);function yt(e,t){let n=e[t];n!==void 0&&ie.current?.select(n.start,n.end)}(0,v.useEffect)(()=>{if(Ye!==`text`||!Xe)return;let e=fU(Fe,_t),t=_t!==ht.current;ht.current=_t;let n=t?0:Math.min(tt,Math.max(e.length-1,0));nt(n),e.length>0&&yt(e,n)},[_t,Ye,Xe,Ke,ae]),(0,v.useEffect)(()=>{ie.current?.markMatches(Ye===`text`?vt:[],tt)},[Ye,vt,tt,Ke,ae]);let bt=M?.reveal,[xt,St]=(0,v.useState)(void 0);(0,v.useEffect)(()=>{if(bt!==void 0&&M!==null){if(bt.page!==void 0)St({page:bt.page});else if(bt.line!==void 0){k===null&&T(`source`);let e=fU(Fe,bt.query),t=OU(Fe,bt.line),n=e.findIndex(e=>e.start>=t);ht.current=bt.query,nt(n===-1?0:n)}et(bt.query),Qe(!0)}},[bt]);function Ct(){Qe(!0)}function wt(){Qe(!1)}function Tt(){if(Ye===`pdf`)at.current?.findNext();else if(Ye===`text`){if(vt.length===0)return;let e=(tt+1)%vt.length;nt(e),yt(vt,e)}else{let e=pt.current.length;if(e===0)return;let t=(mt.current+1)%e;nt(t),gt(t)}}function Et(){if(Ye===`pdf`)at.current?.findPrevious();else if(Ye===`text`){if(vt.length===0)return;let e=(tt-1+vt.length)%vt.length;nt(e),yt(vt,e)}else{let e=pt.current.length;if(e===0)return;let t=(mt.current-1+e)%e;nt(t),gt(t)}}let Dt=Ye===`pdf`?{matchCount:ot.matchCount,currentIndex:ot.currentIndex,truncated:!1,searching:ot.searching}:Ye===`text`?{matchCount:vt.length,currentIndex:vt.length>0?Math.min(tt,vt.length-1):-1,truncated:!1,searching:!1}:{matchCount:ct.length,currentIndex:ct.length>0?Math.min(tt,ct.length-1):-1,truncated:ut,searching:!1},Ot=k===null?null:(0,N.jsx)(v.Suspense,{fallback:(0,N.jsx)(`div`,{className:`p-4 text-sm text-zinc-400 dark:text-zinc-600`,children:`loading editor…`}),children:(0,N.jsx)(WH,{handle:ie,onReady:ue,path:e.path,value:k.draft,baseline:s,onChange:e=>ne(t=>t===null?t:{...t,draft:e}),onSave:()=>{Oe&&!Me&&!Pe&&It()}})},`editor`);function kt(t){return M===null?null:(0,N.jsx)(v.Suspense,{fallback:(0,N.jsx)(`div`,{className:`p-4`,children:(0,N.jsx)(Te,{code:M.content,path:e.path})}),children:(0,N.jsx)(WH,{readOnly:!0,handle:t?ie:void 0,onReady:t?ue:void 0,path:e.path,value:M.content,baseline:s})},`source`)}let At=(0,v.useCallback)(e=>fetch(de(h,e,g,void 0,_)).then(e=>e.ok?e.blob():void 0,()=>void 0),[h,g,_]);function jt(t){return(0,N.jsx)(`div`,{className:`prose-chat mx-auto max-w-3xl p-4 text-zinc-700 dark:text-zinc-300`,children:(0,N.jsx)(SC,{remarkPlugins:[dz,Cz],rehypePlugins:[WA],components:{pre:Je,a:({href:t,children:n,...r})=>!t||/^[a-z][a-z0-9+.-]*:/i.test(t)?(0,N.jsx)(`a`,{href:t,target:`_blank`,rel:`noreferrer`,...r,children:n}):t.startsWith(`#`)?(0,N.jsx)(`a`,{href:t,...r,children:n}):(0,N.jsx)(`a`,{href:t,onClick:n=>{n.preventDefault(),p(oe(e.path,t))},...r,children:n}),img:({src:t,alt:n,...r})=>{let i=typeof t==`string`&&t!==``&&!/^[a-z][a-z0-9+.-]*:/i.test(t)&&!t.startsWith(`//`)?de(h,oe(e.path,t),g,void 0,_):t;return(0,N.jsx)(`img`,{...r,src:i,alt:n??``,loading:`lazy`,className:`max-w-full rounded-lg`})}},children:re(t)})})}function Mt(e){(w!==`split`||e===`split`||!Oe||window.confirm(`Discard unsaved changes?`))&&(e===w||!ke||window.confirm(`Discard unsaved changes?`))&&(w===`split`&&e!==`split`&&ne(null),D(null),T(e))}function Nt(){(!je||window.confirm(`Discard unsaved changes?`))&&f()}function Pt(){M&&(!ke||window.confirm(`Discard unsaved changes?`))&&(Se&&w===`rendered`?(D(`rendered`),T(we?`split`:`source`)):he&&w===`rendered`&&(D(`rendered`),T(`source`)),ne({draft:M.content,baseContent:M.content,baseMtimeMs:M.mtimeMs}))}function Ft(){E===null?ne(Ue&&M!==null?{draft:M.content,baseContent:M.content,baseMtimeMs:M.mtimeMs}:null):(ne(null),T(E),D(null))}function It(t=!1){M&&k!==null&&!Me&&(fe.current=k.draft,m(e.path,k.draft,k.baseMtimeMs,t))}function Lt(){ne(null),p(e.path)}function Rt(){let t=!O;te(t),t?c(e.path):l()}return(0,v.useEffect)(()=>{k!==null&&M!==null&&fe.current!==null&&M.content===fe.current&&M.mtimeMs!==k.baseMtimeMs&&(fe.current=null,ne({...k,baseContent:M.content,baseMtimeMs:M.mtimeMs}))},[M?.mtimeMs]),(0,v.useEffect)(()=>{function e(e){if(e.key===`Escape`)Xe?wt():Nt();else if((e.metaKey||e.ctrlKey)&&e.key.toLowerCase()===`f`){if(Ye===`none`)return;e.preventDefault(),Ct()}}return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)}),(0,v.useEffect)(()=>{Ue&&Ee&&k===null&&M!==null&&ne({draft:M.content,baseContent:M.content,baseMtimeMs:M.mtimeMs})},[Ue,Ee,M?.mtimeMs]),(0,v.useEffect)(()=>{j(n?`streaming`:e=>e===`streaming`?`done`:e)},[n]),(0,v.useEffect)(()=>(r(je),()=>r(!1)),[je]),(0,v.useEffect)(()=>(a&&c(e.path),()=>l()),[]),(0,N.jsxs)(`div`,{className:`absolute inset-0 z-20 flex flex-col bg-white dark:bg-zinc-950`,children:[(0,N.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-zinc-200 px-3 py-2 dark:border-zinc-800`,children:[(Se||he)&&!O&&(0,N.jsx)(`div`,{className:`flex shrink-0 items-center gap-0.5`,role:`group`,"aria-label":`How to show this document`,children:[[`rendered`,`⚏ rendered`,`Show the rendering`],[`split`,`⇹ split`,`Edit the file beside its rendering`],[`source`,`⌗ source`,`Show the file as written`]].filter(([e])=>!(he&&e===`split`)).map(([e,t,n])=>(0,N.jsx)(`button`,{type:`button`,onClick:()=>Mt(e),"aria-pressed":w===e,title:n,className:`rounded px-1.5 py-0.5 text-xs ${w===e?`bg-zinc-100 text-zinc-700 dark:bg-zinc-800 dark:text-zinc-200`:`text-zinc-400 hover:bg-zinc-100 hover:text-zinc-700 dark:text-zinc-600 dark:hover:bg-zinc-800 dark:hover:text-zinc-300`}`,children:t},e))}),i!==void 0&&k===null&&(0,N.jsx)(`button`,{type:`button`,onClick:Rt,"aria-pressed":O,title:O?`Show file content`:`Show uncommitted changes (vs HEAD)`,className:`shrink-0 rounded px-1.5 py-0.5 text-xs ${O?`bg-amber-100 text-amber-800 dark:bg-amber-950/60 dark:text-amber-300`:`text-zinc-400 hover:bg-zinc-100 hover:text-zinc-700 dark:text-zinc-600 dark:hover:bg-zinc-800 dark:hover:text-zinc-300`}`,children:`± diff`}),u&&k===null&&(0,N.jsx)(`button`,{type:`button`,onClick:()=>d(e.path),title:`Show this file's history`,className:`shrink-0 rounded px-1.5 py-0.5 text-xs text-zinc-400 hover:bg-zinc-100 hover:text-zinc-700 dark:text-zinc-600 dark:hover:bg-zinc-800 dark:hover:text-zinc-300`,children:`⎇ history`}),(0,N.jsxs)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-xs text-zinc-500 dark:text-zinc-400`,title:e.path,children:[e.path,je&&(0,N.jsx)(`span`,{className:`ml-1 text-amber-500`,children:`●`})]}),P&&C&&(0,N.jsx)(`button`,{type:`button`,onClick:()=>C(e.path),title:`Open with the application associated with .drawio files — draw.io desktop, where it is installed`,className:`shrink-0 rounded border border-zinc-300 px-2 py-0.5 text-xs text-zinc-600 hover:border-zinc-400 hover:text-zinc-900 dark:border-zinc-700 dark:text-zinc-300 dark:hover:border-zinc-500 dark:hover:text-zinc-100`,children:`↗ open in draw.io`}),M&&!_e&&!ve&&!P&&!he&&!O&&!xe&&(0,N.jsx)(GH,{text:Fe,path:e.path,serverUrl:h,token:g,workspace:_,template:y}),We?.kind===`table`&&(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(GH,{text:()=>Ge.current?.markdown?.()??``,path:`${e.path.replace(/\.[^./]*$/,``)}.md`,serverUrl:h,token:g,workspace:_,template:y}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>Ge.current?.xlsx?.(),title:`Download as an Excel workbook`,"aria-label":`Download as an Excel workbook`,className:xU,children:`⤓ excel`})]}),(We?.kind===`graph`||We?.kind===`sequence`||We?.kind===`timeline`)&&(0,N.jsx)(`button`,{type:`button`,onClick:()=>Ge.current?.svg?.(),title:`Download the figure as SVG`,"aria-label":`Download the figure as SVG`,className:xU,children:`⤓ svg`}),M&&k===null&&(0,N.jsx)(me,{text:M.content}),M&&k===null&&!O&&Ee&&(0,N.jsx)(`button`,{type:`button`,onClick:Pt,className:`shrink-0 rounded border border-zinc-300 px-2 py-0.5 text-xs text-zinc-500 hover:border-zinc-400 hover:text-zinc-700 dark:border-zinc-700 dark:text-zinc-400 dark:hover:border-zinc-500 dark:hover:text-zinc-200`,children:`✎ edit`}),M&&k===null&&!Ee&&(0,N.jsx)(`span`,{className:`shrink-0 text-xs text-zinc-400 dark:text-zinc-600`,title:`Outside the writable zone`,children:`🔒 read-only`}),k!==null&&(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`button`,{type:`button`,onClick:()=>It(),disabled:!Oe||Me||Pe,className:`shrink-0 rounded border border-emerald-300 px-2 py-0.5 text-xs text-emerald-700 hover:border-emerald-500 disabled:opacity-50 dark:border-emerald-900 dark:text-emerald-400 dark:hover:border-emerald-600`,children:Me?`saving…`:`save`}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>{(!Oe||window.confirm(`Discard unsaved changes?`))&&Ft()},className:`shrink-0 rounded border border-zinc-300 px-2 py-0.5 text-xs text-zinc-500 hover:border-zinc-400 dark:border-zinc-700 dark:text-zinc-400 dark:hover:border-zinc-500`,children:Oe?`cancel`:`done`})]}),(0,N.jsx)(`button`,{type:`button`,onClick:Nt,title:`Close (Esc)`,"aria-label":`Close file viewer`,className:`shrink-0 px-1 text-sm text-zinc-400 hover:text-zinc-600 dark:text-zinc-600 dark:hover:text-zinc-300`,children:`✕`})]}),Xe&&Ye!==`none`&&(0,N.jsx)(lU,{inputRef:rt,query:$e,onQueryChange:et,matchCount:Dt.matchCount,currentIndex:Dt.currentIndex,truncated:Dt.truncated,searching:Dt.searching,onNext:Tt,onPrev:Et,onClose:wt}),Pe&&k!==null&&(0,N.jsxs)(`div`,{className:`flex items-center gap-3 border-b border-amber-300 bg-amber-50 px-3 py-2 text-sm text-amber-800 dark:border-amber-900/60 dark:bg-amber-950/30 dark:text-amber-300`,children:[(0,N.jsx)(`span`,{className:`min-w-0 flex-1`,children:`File changed on disk since you started editing.`}),(0,N.jsx)(`button`,{type:`button`,onClick:Lt,className:`shrink-0 rounded border border-amber-400 px-2 py-0.5 text-xs hover:bg-amber-100 dark:border-amber-800 dark:hover:bg-amber-950/60`,children:`reload (discard my edits)`}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>It(!0),disabled:Me,className:`shrink-0 rounded border border-amber-400 px-2 py-0.5 text-xs hover:bg-amber-100 disabled:opacity-50 dark:border-amber-800 dark:hover:bg-amber-950/60`,children:`overwrite with my version`})]}),k!==null&&M?.saveError&&!M.saveError.conflict&&(0,N.jsx)(`div`,{className:`border-b border-red-300 bg-red-50 px-3 py-2 text-sm text-red-700 dark:border-red-900/60 dark:bg-red-950/30 dark:text-red-300`,children:M.saveError.message}),(0,N.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-auto`,children:[O&&k===null&&(0,N.jsxs)(`div`,{className:`p-4`,children:[o?.path===e.path&&`error`in o&&(0,N.jsx)(`div`,{className:`rounded-lg border border-red-300 bg-red-50 px-3 py-2 text-sm text-red-700 dark:border-red-900/60 dark:bg-red-950/30 dark:text-red-300`,children:o.error}),o?.path===e.path&&`before`in o&&(0,N.jsx)(Ze,{fill:!0,lines:ee(o.before,o.after)}),o?.path!==e.path&&(0,N.jsx)(`div`,{className:`text-sm text-zinc-400 dark:text-zinc-600`,children:`loading diff…`})]}),ve&&k===null&&!O&&(0,N.jsx)(Og,{label:`This PDF`,children:(0,N.jsx)(v.Suspense,{fallback:(0,N.jsx)(`div`,{className:`p-4 text-sm text-zinc-400 dark:text-zinc-600`,children:`loading…`}),children:(0,N.jsx)(hU,{ref:at,path:e.path,serverUrl:h,token:g,workspace:_,revision:S,findQuery:Ye===`pdf`?_t:``,onFindStateChange:st,...xt?{startAt:xt}:{},...x?{onLoaded:x}:{}})})}),_e&&k===null&&!O&&(0,N.jsx)(`div`,{className:`flex h-full items-center justify-center p-4`,children:(0,N.jsx)(`img`,{src:de(h,e.path,g,S,_),alt:e.path,onLoad:()=>b?.(e.path),className:`max-h-full max-w-full rounded object-contain`})}),e.status===`loading`&&k===null&&!O&&!_e&&!ve&&(0,N.jsx)(`div`,{className:`p-4 text-sm text-zinc-400 dark:text-zinc-600`,children:`loading…`}),e.status===`error`&&!_e&&!ve&&(0,N.jsx)(`div`,{className:`p-4 text-sm text-red-600 dark:text-red-400`,children:e.message}),k!==null&&!Ue&&Ot,M&&k===null&&!Ue&&!O&&pe&&!Ce&&(0,N.jsx)(`div`,{ref:it,children:jt(M.content)}),M&&k===null&&!Ue&&!O&&P&&!Ce&&(0,N.jsx)(`div`,{className:`h-full`,"data-testid":`file-drawio`,children:(0,N.jsx)(Uz,{path:e.path,xml:M.content,variant:`viewer`,fallback:kt(!1),onTouchUpDirtyChange:Ae})}),M&&k===null&&!Ue&&!O&&he&&!Ce&&(0,N.jsx)(`div`,{className:`h-full`,"data-testid":`file-poster`,children:(0,N.jsx)(QH,{path:e.path,content:M.content,mtimeMs:M.mtimeMs,writable:Ee,loadFile:At,fallback:kt(!1),onTouchUpDirtyChange:Ae})}),M&&k===null&&!Ue&&!O&&ge&&!Ce&&(0,N.jsx)(`div`,{className:`h-full`,"data-testid":`file-html`,children:(0,N.jsx)(cU,{source:M.content,path:e.path,load:At,onOpen:p})}),Ue&&(0,N.jsxs)(`div`,{className:`flex h-full min-h-0`,"data-testid":`file-split`,children:[(0,N.jsx)(`div`,{className:`min-w-0 flex-1 overflow-auto border-r border-zinc-200 dark:border-zinc-800`,children:Ot??kt(!1)}),(0,N.jsx)(`div`,{className:`min-w-0 flex-1 overflow-auto`,"data-testid":`file-split-rendering`,children:pe&&!xe?(0,N.jsx)(`div`,{className:`prose-chat p-4 text-zinc-700 dark:text-zinc-300`,children:jt(Ie)}):P&&!xe?(0,N.jsx)(Km,{xml:Ie,serverUrl:h,title:e.path}):ge&&!xe?(0,N.jsx)(cU,{source:Ie,path:e.path,load:At,onOpen:p}):(0,N.jsxs)(N.Fragment,{children:[Be&&(0,N.jsx)(`p`,{"data-testid":`file-split-stale`,className:`flex flex-wrap items-center gap-2 border-b border-amber-300 bg-amber-50 px-3 py-1.5 text-xs text-amber-900 dark:border-amber-700 dark:bg-amber-950/40 dark:text-amber-200`,children:(0,N.jsxs)(`span`,{children:[`Showing the document as it last stood.`,` `,He??`The text beside it does not satisfy the schema it declares.`]})}),Ve!==void 0&&(0,N.jsxs)(`ul`,{"data-testid":`file-split-issues`,className:`space-y-0.5 border-b border-zinc-200 px-3 py-1.5 text-xs text-zinc-500 dark:border-zinc-800 dark:text-zinc-400`,children:[Ve.slice(0,6).map((e,t)=>(0,N.jsxs)(`li`,{children:[(0,N.jsx)(`span`,{className:`font-mono opacity-70`,children:e.path===``?`(document)`:e.path}),` `,e.message]},t)),Ve.length>6&&(0,N.jsxs)(`li`,{className:`opacity-70`,children:[`…and `,Ve.length-6,` more`]})]}),Re===void 0?(0,N.jsxs)(`p`,{className:`p-4 text-sm text-zinc-400 dark:text-zinc-600`,"data-testid":`file-split-nothing`,children:[`Nothing to draw yet. `,He??`This document does not satisfy the schema it declares.`]}):(0,N.jsx)(Og,{label:`This diagram`,children:(0,N.jsx)(`div`,{className:`p-4`,"data-testid":`file-structured-exchange`,children:(0,N.jsx)(Tg,{envelope:Re,source:Fe,exportRef:Ge,file:{path:e.path,writable:Ee}})})})]})})]}),M&&k===null&&!Ue&&!O&&be&&!Ce&&ye?.status===`valid`&&(0,N.jsx)(Og,{label:`This diagram`,children:(0,N.jsx)(`div`,{className:`mx-auto max-w-5xl p-4`,"data-testid":`file-structured-exchange`,children:(0,N.jsx)(Tg,{envelope:ye.envelope,source:M.content,exportRef:Ge,file:{path:e.path,writable:Ee}})})}),M&&k===null&&!Ue&&!O&&ye?.status===`invalid`&&(0,N.jsxs)(`div`,{"data-testid":`file-structured-exchange-invalid`,className:`mx-4 mt-4 rounded-lg border border-amber-300 bg-amber-50 px-3 py-2 text-sm text-amber-900 dark:border-amber-800 dark:bg-amber-950/40 dark:text-amber-200`,children:[(0,N.jsx)(`p`,{className:`font-medium`,children:`This declares a structured-exchange document and does not satisfy the schema.`}),(0,N.jsxs)(`ul`,{className:`mt-1 space-y-0.5 text-xs`,children:[(M.documentIssues??ye.issues).slice(0,8).map((e,t)=>(0,N.jsxs)(`li`,{children:[(0,N.jsx)(`span`,{className:`font-mono opacity-70`,children:e.path===``?`(document)`:e.path}),` `,e.message]},t)),(M.documentIssues??ye.issues).length>8&&(0,N.jsxs)(`li`,{className:`opacity-70`,children:[`…and `,(M.documentIssues??ye.issues).length-8,` more`]})]})]}),M&&k===null&&!Ue&&!O&&ye?.status===`unsupported-version`&&(0,N.jsxs)(`div`,{"data-testid":`file-structured-exchange-unsupported`,className:`mx-4 mt-4 rounded-lg border border-zinc-300 bg-zinc-50 px-3 py-2 text-sm text-zinc-600 dark:border-zinc-700 dark:bg-zinc-900 dark:text-zinc-400`,children:[`This document declares `,(0,N.jsx)(`span`,{className:`font-mono`,children:ye.schema}),`, which this version does not render. Shown as text.`]}),qe&&kt(!0)]}),A!==`idle`&&(0,N.jsxs)(`button`,{type:`button`,onClick:Nt,"aria-live":`polite`,className:`flex items-center gap-2 border-t border-zinc-200 px-3 py-2 text-left text-sm hover:bg-zinc-50 dark:border-zinc-800 dark:hover:bg-zinc-900`,children:[A===`streaming`?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`span`,{"aria-hidden":!0,className:`h-2 w-2 animate-pulse motion-reduce:animate-none rounded-full bg-amber-500`}),(0,N.jsx)(`span`,{className:`text-amber-700 dark:text-amber-400`,children:`π is replying…`})]}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`span`,{"aria-hidden":!0,className:`h-2 w-2 rounded-full bg-emerald-500`}),(0,N.jsx)(`span`,{className:`text-emerald-700 dark:text-emerald-400`,children:`π replied`})]}),(0,N.jsx)(`span`,{className:`ml-auto text-xs text-zinc-400 dark:text-zinc-500`,children:`show conversation →`})]})]})}function OU(e,t){let n=0;for(let r=1;r<t;r++){let t=e.indexOf(`
867
+ `,n);if(t===-1)return e.length;n=t+1}return n}function kU(e){return e.split(`
868
+ `).map(e=>e.startsWith(`diff --git `)?{kind:`file`,text:e.slice(11)}:e.startsWith(`@@`)||e.startsWith(`+++`)||e.startsWith(`---`)||e.startsWith(`index `)?{kind:`hunk`,text:e}:e.startsWith(`+`)?{kind:`add`,text:e.slice(1)}:e.startsWith(`-`)?{kind:`del`,text:e.slice(1)}:{kind:`context`,text:e.startsWith(` `)?e.slice(1):e})}function AU({show:e,onClose:t}){return(0,v.useEffect)(()=>{function e(e){e.key===`Escape`&&(e.stopImmediatePropagation(),t())}return document.addEventListener(`keydown`,e,!0),()=>document.removeEventListener(`keydown`,e,!0)},[t]),(0,N.jsxs)(`div`,{className:`absolute inset-0 z-30 flex flex-col bg-white dark:bg-zinc-950`,children:[(0,N.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-zinc-200 px-3 py-2 dark:border-zinc-800`,children:[(0,N.jsx)(`span`,{className:`font-mono text-xs text-amber-600 dark:text-amber-500`,children:e.sha.slice(0,12)}),(0,N.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm text-zinc-500 dark:text-zinc-400`,children:`commit diff`}),(0,N.jsx)(`button`,{type:`button`,onClick:t,title:`Close (Esc)`,"aria-label":`Close commit diff`,className:`shrink-0 px-1 text-sm text-zinc-400 hover:text-zinc-600 dark:text-zinc-600 dark:hover:text-zinc-300`,children:`✕`})]}),e.truncated&&(0,N.jsx)(`div`,{className:`border-b border-amber-300 bg-amber-50 px-3 py-1.5 text-xs text-amber-800 dark:border-amber-900/60 dark:bg-amber-950/30 dark:text-amber-300`,children:`Patch truncated — showing the first 256 KiB.`}),(0,N.jsx)(`pre`,{className:`min-h-0 flex-1 overflow-auto p-3 font-mono text-xs leading-relaxed`,children:kU(e.patch).map((e,t)=>(0,N.jsxs)(`div`,{className:e.kind===`file`?`mt-3 border-t border-zinc-200 pt-2 font-bold text-zinc-700 first:mt-0 first:border-t-0 first:pt-0 dark:border-zinc-800 dark:text-zinc-200`:e.kind===`hunk`?`text-sky-600 dark:text-sky-400`:e.kind===`add`?`bg-emerald-50 text-emerald-800 dark:bg-emerald-950/40 dark:text-emerald-300`:e.kind===`del`?`bg-red-50 text-red-700 dark:bg-red-950/40 dark:text-red-300`:`text-zinc-500 dark:text-zinc-500`,children:[e.kind===`add`?`+ `:e.kind===`del`?`− `:``,e.text||` `]},t))})]})}var jU=[`off`,`minimal`,`low`,`medium`,`high`,`xhigh`],MU=`worktree`,NU={defaultWidth:288,minWidth:224,maxWidth:640,keyboardStep:16,storageKey:`pi-outpost.files-sidebar-width.v1`},PU={defaultWidth:416,minWidth:224,maxWidth:640,keyboardStep:16,storageKey:`pi-outpost.history-list-width.v1`},FU={defaultWidth:288,minWidth:160,maxWidth:640,keyboardStep:16,storageKey:`pi-outpost.terminal-height.v1`};function IU(e,t){return Number.isFinite(e)?Math.min(t.maxWidth,Math.max(t.minWidth,Math.round(e))):t.defaultWidth}function LU(e,t){return e===null||e.trim()===``?t.defaultWidth:IU(Number(e),t)}function RU(e,t){try{return LU((t??window.localStorage).getItem(e.storageKey),e)}catch{return e.defaultWidth}}function zU(e,t,n){try{(n??window.localStorage).setItem(t.storageKey,String(IU(e,t)))}catch{}}function BU(e,t=`x`){let[n,r]=(0,v.useState)(()=>RU(e)),i=(0,v.useRef)(n),a=(0,v.useRef)(null),o=(0,v.useCallback)(t=>{let n=IU(t,e);return i.current=n,r(n),n},[e]),s=(0,v.useCallback)(()=>{a.current!==null&&(a.current=null,zU(i.current,e))},[e]);return{width:n,separatorProps:{onPointerDown:e=>{e.isPrimary!==!1&&(e.button??0)===0&&(e.preventDefault(),e.currentTarget.setPointerCapture?.(e.pointerId),a.current={pointerId:e.pointerId,startX:t===`y`?e.clientY:e.clientX,startWidth:i.current})},onPointerMove:e=>{let n=a.current;n!==null&&n.pointerId===e.pointerId&&o(n.startWidth+(t===`y`?n.startX-e.clientY:e.clientX-n.startX))},onPointerUp:e=>{a.current?.pointerId===e.pointerId&&s()},onPointerCancel:e=>{let t=a.current;t!==null&&t.pointerId===e.pointerId&&(a.current=null,o(t.startWidth))},onLostPointerCapture:s,onKeyDown:n=>{let r=null;n.key===(t===`y`?`ArrowDown`:`ArrowLeft`)?r=i.current-e.keyboardStep:n.key===(t===`y`?`ArrowUp`:`ArrowRight`)?r=i.current+e.keyboardStep:n.key===`Home`&&(r=e.defaultWidth),r!==null&&(n.preventDefault(),zU(o(r),e))}}}}function VU({axis:e=`x`,label:t,width:n,config:r,separatorProps:i,className:a=``}){return(0,N.jsx)(`div`,{...i,role:`separator`,"aria-label":t,"aria-orientation":e===`y`?`horizontal`:`vertical`,"aria-valuemin":r.minWidth,"aria-valuemax":r.maxWidth,"aria-valuenow":n,tabIndex:0,title:t,className:`group absolute z-20 touch-none outline-none ${e===`y`?`inset-x-0 -top-1 h-2 cursor-row-resize`:`inset-y-0 -right-1 w-2 cursor-col-resize`} ${a}`,children:(0,N.jsx)(`span`,{className:`pointer-events-none absolute ${e===`y`?`inset-x-0 top-1/2 h-px`:`inset-y-0 left-1/2 w-px`} bg-transparent transition-colors group-hover:bg-blue-400 group-focus-visible:bg-blue-500 group-active:bg-blue-500 dark:group-hover:bg-blue-500`})})}var HU=`#10b981`,UU=[`#8b5cf6`,`#f59e0b`,`#0ea5e9`,`#f43f5e`,`#14b8a6`,`#d946ef`];function WU(e){return e===0?HU:UU[(e-1)%UU.length]}function GU(e){return UU[e%UU.length]}function KU(e){return e*14+7+1}function qU(e){return e*14+2}function JU({row:e,laneCount:t,colorOf:n=WU}){let r=qU(t),i=KU(e.lane),a=e.highlight?HU:n(e.lane),o=e.dashed?`3 3`:void 0;return(0,N.jsxs)(`svg`,{width:r,height:36,viewBox:`0 0 ${r} 36`,"aria-hidden":!0,className:`shrink-0`,children:[e.through.map(e=>(0,N.jsx)(`line`,{x1:KU(e),y1:0,x2:KU(e),y2:36,stroke:n(e),strokeWidth:2,opacity:.55},e)),e.lineAbove&&(0,N.jsx)(`line`,{x1:i,y1:0,x2:i,y2:18,stroke:a,strokeWidth:2,strokeDasharray:o}),e.lineBelow&&(0,N.jsx)(`line`,{x1:i,y1:18,x2:i,y2:36,stroke:a,strokeWidth:2,strokeDasharray:o}),e.forkTo.map(e=>(0,N.jsx)(`path`,{d:`M ${i} 18 C ${i} 36, ${KU(e)} 18, ${KU(e)} 36`,fill:`none`,stroke:n(e),strokeWidth:2,opacity:.75},`fork-${e}`)),(e.mergeFrom??[]).map(e=>(0,N.jsx)(`path`,{d:`M ${i} 18 C ${i} 0, ${KU(e)} 18, ${KU(e)} 0`,fill:`none`,stroke:n(e),strokeWidth:2,opacity:.75},`merge-${e}`)),e.emphasis===`current`?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`circle`,{cx:i,cy:18,r:6,fill:`none`,stroke:a,strokeWidth:2}),(0,N.jsx)(`circle`,{cx:i,cy:18,r:2.5,fill:a})]}):(0,N.jsx)(`circle`,{cx:i,cy:18,r:4,fill:e.emphasis===`filled`?a:`var(--tree-off, #d4d4d8)`,stroke:a,strokeWidth:e.emphasis===`filled`?0:1.5})]})}function YU(e,t){let n=[],r=t===void 0?[]:[t],i=r.length,a=t!==void 0,o=()=>{let e=r.indexOf(null);return e===-1?(r.push(null),i=Math.max(i,r.length),r.length-1):e};for(let s of e){let e=r.reduce((e,t,n)=>t===s.sha?[...e,n]:e,[]),c=e[0]??o();s.sha===t&&(a=!1);let l=(s.sha===t?e.length-1:e.length)===0,u=e.slice(1);for(let e of u)r[e]=null;i=Math.max(i,c+1);let[d,...f]=s.parents;r[c]=d??null;let p=f.map(e=>{let t=o();return r[t]=e,t});n.push({lane:c,through:r.reduce((e,t,n)=>t!==null&&n!==c&&!p.includes(n)&&!(a&&n===0)?[...e,n]:e,[]),forkTo:p,mergeFrom:u,tip:l})}return{lanes:n,laneCount:Math.max(i,1)}}function XU(e){let t=e.find(e=>e.head)?.sha,{lanes:n,laneCount:r}=YU(e,t);return{rows:e.map((e,t)=>{let{lane:r,through:i,forkTo:a,mergeFrom:o,tip:s}=n[t];return{lane:r,through:i,forkTo:a,mergeFrom:o,entry:e,lineAbove:!s,lineBelow:e.parents.length>0,emphasis:e.head?`current`:`filled`}}),laneCount:r}}function ZU(e,t={}){let{lanes:n,laneCount:r}=YU(e),i=e.map((e,t)=>{let{lane:r,through:i,forkTo:a,mergeFrom:o}=n[t];return{lane:r,through:i,forkTo:a,mergeFrom:o,rev:e.sha,path:e.path,entry:e,lineAbove:!0,lineBelow:e.parents.length>0,emphasis:`filled`}}),a=i[0];return i.unshift({rev:MU,path:a?.path??``,lane:a?.lane??0,through:a?.through??[],forkTo:[],mergeFrom:[],lineAbove:!1,lineBelow:i.length>0,emphasis:`current`,dashed:!t.dirty}),i[1]&&(i[1].lineAbove=!0),{rows:i,laneCount:r}}var QU=20;function $U(e){let t=(Date.now()-new Date(e).getTime())/1e3;return t<90?`now`:t<3600?`${Math.round(t/60)}m ago`:t<86400?`${Math.round(t/3600)}h ago`:`${Math.round(t/86400)}d ago`}function eW(e){return e.rev===`worktree`?`working tree`:e.rev.slice(0,7)}function tW(e,t){return e!==null&&t!==null&&e.rev===t.rev&&e.path===t.path}function nW(e){return{rev:e.rev,path:e.path}}function rW({history:e,diff:t,dirty:n,onFetchDiff:r,onClearDiff:i,onClose:a}){let[o,s]=(0,v.useState)({base:null,target:null}),{base:c,target:l}=o,[u,d]=(0,v.useState)(0),f=(0,v.useRef)([]),p=BU(PU),{rows:m,laneCount:h}=(0,v.useMemo)(()=>ZU(e.entries,{dirty:n}),[e.entries,n]),g=(0,v.useRef)({onFetchDiff:r,onClose:a});g.current={onFetchDiff:r,onClose:a},(0,v.useEffect)(()=>{function e(e){e.key===`Escape`&&(e.stopImmediatePropagation(),g.current.onClose())}return document.addEventListener(`keydown`,e,!0),()=>document.removeEventListener(`keydown`,e,!0)},[]),(0,v.useEffect)(()=>{c===null||l===null||tW(c,l)||g.current.onFetchDiff(c,l)},[c,l]);let _=(0,v.useCallback)((e,t)=>{let n=nW(e);s(r=>{if(t===`base`)return{base:n,target:tW(n,r.target)?r.base:r.target};if(t===`target`)return{base:tW(n,r.base)?r.target:r.base,target:n};if(r.base===null&&r.target===null){let t=e.entry?.parents[0],r=t===void 0?void 0:m.find(e=>e.rev===t);return{base:r?nW(r):null,target:n}}return{base:tW(n,r.base)?r.target:r.base,target:n}})},[m]),y=(0,v.useCallback)(()=>{s({base:null,target:null}),i()},[i]),b=(0,v.useCallback)(()=>s(e=>({base:e.target,target:e.base})),[]),x=(0,v.useCallback)(e=>{d(t=>{let n=Math.max(0,Math.min(m.length-1,t+e));return f.current[n]?.focus(),n})},[m.length]),S=e=>{let t=nW(e);return tW(t,c)?`base`:tW(t,l)?`target`:null},C=m.findIndex(e=>tW(nW(e),c)),w=m.findIndex(e=>tW(nW(e),l)),T=C>=0&&w>=0?{top:Math.min(C,w)*36+18,height:Math.abs(w-C)*36}:null;return(0,N.jsxs)(`div`,{className:`absolute inset-0 z-30 flex flex-col bg-white dark:bg-zinc-950`,children:[(0,N.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-zinc-200 px-3 py-2 dark:border-zinc-800`,children:[(0,N.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-xs text-zinc-500 dark:text-zinc-400`,title:e.path,children:e.path}),c!==null&&l!==null&&(0,N.jsxs)(`span`,{className:`shrink-0 font-mono text-xs text-zinc-500 dark:text-zinc-400`,"aria-label":`Comparing ${eW(c)} to ${eW(l)}`,children:[(0,N.jsx)(`span`,{className:`text-amber-600 dark:text-amber-500`,children:eW(c)}),` → `,(0,N.jsx)(`span`,{className:`text-amber-600 dark:text-amber-500`,children:eW(l)})]}),c!==null&&l!==null&&(0,N.jsx)(`button`,{type:`button`,onClick:b,title:`Compare the other way round`,className:`shrink-0 rounded px-1.5 py-0.5 text-xs text-zinc-400 hover:bg-zinc-100 hover:text-zinc-700 dark:text-zinc-500 dark:hover:bg-zinc-800 dark:hover:text-zinc-200`,children:`⇄ swap`}),(c!==null||l!==null)&&(0,N.jsx)(`button`,{type:`button`,onClick:y,className:`shrink-0 rounded px-1.5 py-0.5 text-xs text-zinc-400 hover:bg-zinc-100 hover:text-zinc-700 dark:text-zinc-500 dark:hover:bg-zinc-800 dark:hover:text-zinc-200`,children:`clear`}),(0,N.jsx)(`button`,{type:`button`,onClick:a,title:`Close (Esc)`,"aria-label":`Close file history`,className:`shrink-0 px-1 text-sm text-zinc-400 hover:text-zinc-600 dark:text-zinc-600 dark:hover:text-zinc-300`,children:`✕`})]}),(0,N.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col md:flex-row`,children:[(0,N.jsxs)(`div`,{role:`region`,"aria-label":`Commit history`,style:{"--history-list-width":`${p.width}px`},className:`relative flex max-h-[40%] w-full shrink-0 flex-col border-b border-zinc-200 md:max-h-none md:w-[var(--history-list-width)] md:border-b-0 md:border-r dark:border-zinc-800`,children:[(0,N.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,onKeyDown:e=>{e.key===`ArrowDown`?(e.preventDefault(),x(1)):e.key===`ArrowUp`&&(e.preventDefault(),x(-1))},children:[e.status===`loading`&&(0,N.jsx)(`div`,{className:`px-3 py-2 text-xs text-zinc-500`,children:`Reading history…`}),e.status===`error`&&(0,N.jsx)(`div`,{className:`m-3 rounded-lg border border-red-300 bg-red-50 px-3 py-2 text-sm text-red-700 dark:border-red-900/60 dark:bg-red-950/30 dark:text-red-300`,children:e.error}),e.status===`loaded`&&e.entries.length===0&&(0,N.jsx)(`div`,{className:`px-3 py-2 text-xs text-zinc-500`,children:`No commits touch this file yet.`}),e.status===`loaded`&&e.entries.length>0&&(0,N.jsxs)(`div`,{className:`relative`,role:`group`,"aria-label":`Commits`,children:[T&&(0,N.jsx)(iW,{top:T.top,height:T.height,baseFirst:C<w}),m.map((e,t)=>(0,N.jsx)(sW,{ref:e=>{f.current[t]=e},row:e,laneCount:h,role:S(e),isFocused:t===u,onSelect:t=>_(e,t),onFocus:()=>d(t)},e.rev))]})]}),(0,N.jsx)(VU,{label:`Resize History commit list`,width:p.width,config:PU,separatorProps:p.separatorProps,className:`hidden md:block`})]}),(0,N.jsx)(`div`,{role:`region`,"aria-label":`History diff`,className:`min-h-0 min-w-0 flex-1 overflow-auto p-3`,children:(0,N.jsx)(cW,{diff:t,base:c,target:l})})]})]})}function iW({top:e,height:t,baseFirst:n}){return(0,N.jsxs)(`div`,{"aria-hidden":!0,className:`pointer-events-none absolute left-0 z-10 motion-safe:transition-all motion-safe:duration-150 motion-safe:ease-out`,style:{top:e,height:t,width:QU},children:[(0,N.jsx)(`div`,{className:`absolute inset-y-0 left-2 w-px bg-zinc-400 dark:bg-zinc-500`}),(0,N.jsx)(aW,{label:n?`base`:`target`,className:`top-0`}),(0,N.jsx)(aW,{label:n?`target`:`base`,className:`bottom-0`})]})}function aW({label:e,className:t}){return(0,N.jsx)(`div`,{className:`absolute left-2 flex h-px w-2.5 items-center bg-zinc-400 dark:bg-zinc-500 ${t}`,children:(0,N.jsx)(`span`,{className:`absolute -left-1 -top-1.5 rotate-180 text-[9px] leading-none text-zinc-500 [writing-mode:vertical-rl] dark:text-zinc-400`,children:e})})}var oW=`shrink-0 rounded px-1 py-0.5 text-[10px] text-zinc-400 opacity-0 hover:bg-zinc-200 hover:text-zinc-700 focus-visible:opacity-100 group-hover:opacity-100 aria-disabled:cursor-default aria-disabled:opacity-30 dark:text-zinc-500 dark:hover:bg-zinc-700 dark:hover:text-zinc-200`;function sW({row:e,laneCount:t,role:n,isFocused:r,onSelect:i,onFocus:a,ref:o}){let s=e.entry,c=s?`${s.sha.slice(0,7)} ${s.subject}`:`Working tree`;return(0,N.jsxs)(`div`,{ref:o,role:`button`,tabIndex:r?0:-1,"aria-label":c,"aria-current":n===null?void 0:`true`,onFocus:a,onClick:()=>i(),onKeyDown:e=>{e.target===e.currentTarget&&(e.key===`Enter`||e.key===` `?(e.preventDefault(),i()):e.key===`b`?i(`base`):e.key===`t`&&i(`target`))},style:{height:36,paddingLeft:QU},className:`group flex cursor-pointer items-center gap-2 pr-2 focus:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-zinc-400 hover:bg-zinc-100 dark:hover:bg-zinc-800/70 ${n===null?``:`bg-zinc-100 dark:bg-zinc-800/60`}`,children:[(0,N.jsx)(JU,{row:e,laneCount:t}),s?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`span`,{className:`shrink-0 font-mono text-xs text-amber-600 dark:text-amber-500`,children:s.sha.slice(0,7)}),(0,N.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm text-zinc-700 dark:text-zinc-300`,title:s.subject,children:s.subject}),(0,N.jsxs)(`span`,{className:`shrink-0 text-[10px] text-zinc-400 dark:text-zinc-600`,children:[s.author,` · `,$U(s.date)]}),(0,N.jsxs)(`span`,{className:`shrink-0 font-mono text-[10px] tabular-nums`,"aria-label":`${s.added} lines added, ${s.deleted} removed`,children:[(0,N.jsxs)(`span`,{className:`text-emerald-600 dark:text-emerald-500`,children:[`+`,s.added]}),` `,(0,N.jsxs)(`span`,{className:`text-red-600 dark:text-red-400`,children:[`−`,s.deleted]})]})]}):(0,N.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm text-zinc-500 dark:text-zinc-400`,children:`working tree`}),(0,N.jsxs)(`span`,{className:`flex shrink-0 gap-0.5`,children:[(0,N.jsx)(`button`,{type:`button`,title:n===`target`?`Make this the base (swaps the two)`:`Compare from this version`,onClick:e=>{e.stopPropagation(),i(`base`)},className:oW,children:`base`}),(0,N.jsx)(`button`,{type:`button`,title:n===`base`?`Make this the target (swaps the two)`:`Compare to this version`,onClick:e=>{e.stopPropagation(),i(`target`)},className:oW,children:`target`})]})]})}function cW({diff:e,base:t,target:n}){return t===null&&n===null?(0,N.jsx)(`p`,{className:`text-sm text-zinc-400 dark:text-zinc-600`,children:`Pick a commit to see what changed.`}):t===null||n===null?(0,N.jsx)(`p`,{className:`text-sm text-zinc-400 dark:text-zinc-600`,children:`Now pick the version to compare it against.`}):e?.status===`error`?(0,N.jsx)(`div`,{className:`rounded-lg border border-red-300 bg-red-50 px-3 py-2 text-sm text-red-700 dark:border-red-900/60 dark:bg-red-950/30 dark:text-red-300`,children:e.error}):e===null?(0,N.jsx)(`p`,{className:`text-sm text-zinc-400 dark:text-zinc-600`,children:`Loading…`}):e.status===`loaded`&&e.beforeText===e.afterText?(0,N.jsx)(`p`,{className:`text-sm text-zinc-400 dark:text-zinc-600`,children:`These two versions are identical.`}):e.status===`loaded`&&O(e.beforeText,e.afterText)?(0,N.jsx)(`p`,{className:`text-sm text-zinc-400 dark:text-zinc-600`,children:`These two versions differ only in their line endings.`}):(0,N.jsx)(`div`,{className:e.status===`loading`?`opacity-40`:void 0,children:(0,N.jsx)(Ze,{fill:!0,lines:ee(e.beforeText,e.afterText)})})}var lW=`inline-flex h-7 shrink-0 items-center gap-1 whitespace-nowrap rounded-md border px-2 text-xs leading-none`,uW=`inline-flex h-7 min-w-0 items-center gap-1 whitespace-nowrap rounded-md border px-2 text-xs leading-none`;function dW(e){let t=e.filter(e=>!e.sideOf).flatMap(t=>[t,...e.filter(e=>e.sideOf===t.root)]);return[...t,...e.filter(e=>!t.includes(e))]}var fW={stopped:`stopped`,starting:`starting…`,idle:`idle`,working:`working`,waiting:`waiting for you`,"ready-for-review":`ready for review`};function pW({activity:e}){switch(e){case`stopped`:return(0,N.jsx)(`span`,{className:`h-2 w-2 shrink-0 rounded-full border border-dashed border-zinc-400 dark:border-zinc-600`});case`starting`:return(0,N.jsx)(`svg`,{className:`h-2.5 w-2.5 shrink-0 animate-spin text-zinc-500 dark:text-zinc-400`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`3.5`,strokeLinecap:`round`,children:(0,N.jsx)(`path`,{d:`M12 3a9 9 0 0 1 9 9`})});case`working`:return(0,N.jsxs)(`span`,{className:`relative flex h-2 w-2 shrink-0 items-center justify-center`,children:[(0,N.jsx)(`span`,{className:`absolute h-2 w-2 animate-ping rounded-full bg-blue-700 opacity-60 dark:bg-blue-400`}),(0,N.jsx)(`span`,{className:`relative h-2 w-2 rounded-full bg-blue-700 dark:bg-blue-400`})]});case`waiting`:return(0,N.jsx)(`span`,{className:`h-2 w-2 shrink-0 rounded-full bg-amber-500`});case`ready-for-review`:return(0,N.jsx)(`span`,{className:`h-2 w-2 shrink-0 rotate-45 rounded-[1px] border-2 border-violet-600 bg-violet-100 dark:border-violet-400 dark:bg-violet-950`});default:return(0,N.jsx)(`span`,{className:`h-1.5 w-1.5 shrink-0 rounded-full bg-zinc-400 dark:bg-zinc-600`})}}function mW({className:e}){return(0,N.jsxs)(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,"aria-hidden":`true`,children:[(0,N.jsx)(`path`,{d:`M12 6v7`}),(0,N.jsx)(`path`,{d:`M12 18h.01`})]})}function hW({className:e}){return(0,N.jsxs)(`svg`,{className:e,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,N.jsx)(`path`,{d:`M7 3h10v18H7z`}),(0,N.jsx)(`path`,{d:`m9.5 12 1.7 1.7 3.5-3.7`})]})}function gW(e){let{workspace:t,workspaces:n,locked:r}=e,[i,a]=(0,v.useState)(!1),o=(0,v.useRef)(null);if((0,v.useEffect)(()=>{if(!i)return;let e=e=>{aH(e,o.current)||a(!1)},t=e=>{e.key===`Escape`&&a(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[i]),r||!t)return null;let s=n.filter(e=>GB(e)!==GB(t)),c=n.filter(e=>!e.sideOf).length,l=n.filter(e=>e.needsAttention);return(0,N.jsxs)(`div`,{ref:o,className:`relative min-w-[4rem] max-w-[16rem]`,children:[(0,N.jsxs)(`button`,{type:`button`,onClick:()=>a(e=>!e),"aria-expanded":i,"aria-haspopup":`menu`,title:`Project: ${t.name} (${fW[t.activity]})`,className:`${uW} max-w-full gap-1.5 ${l.length>0?`border-amber-500 bg-amber-50 text-zinc-700 dark:bg-amber-950/40 dark:text-zinc-200`:`border-zinc-400 bg-zinc-100 text-zinc-700 dark:border-zinc-600 dark:bg-zinc-800 dark:text-zinc-200`}`,children:[(0,N.jsx)(pW,{activity:t.activity}),(0,N.jsx)(`span`,{className:`truncate font-medium`,children:t.name}),l.length>0?(0,N.jsxs)(`span`,{className:`flex items-center gap-1 text-amber-600 dark:text-amber-500`,children:[(0,N.jsx)(mW,{className:`h-3 w-3`}),(0,N.jsx)(`span`,{className:`font-semibold`,children:l.length})]}):s.some(e=>e.activity===`working`)&&(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`span`,{className:`h-3 w-px bg-zinc-300 dark:bg-zinc-600`}),(0,N.jsx)(`span`,{className:`flex items-center gap-1`,children:s.map(e=>e.activity===`working`?(0,N.jsxs)(`span`,{className:`relative flex h-1.5 w-1.5 items-center justify-center`,children:[(0,N.jsx)(`span`,{className:`absolute h-1.5 w-1.5 animate-ping rounded-full bg-blue-700 opacity-60 dark:bg-blue-400`}),(0,N.jsx)(`span`,{className:`relative h-1.5 w-1.5 rounded-full bg-blue-700 dark:bg-blue-400`})]},GB(e)):(0,N.jsx)(`span`,{className:`h-1 w-1 rounded-full bg-zinc-300 dark:bg-zinc-600`},GB(e)))})]}),(0,N.jsx)(`svg`,{className:`h-3 w-3 text-zinc-500`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,N.jsx)(`path`,{d:`m6 9 6 6 6-6`})})]}),i&&(0,N.jsxs)(`div`,{role:`menu`,className:`absolute left-0 top-full z-40 mt-1 w-87 rounded-md border border-zinc-300 bg-white p-1 shadow-lg dark:border-zinc-700 dark:bg-zinc-900`,children:[dW(n).map(n=>{let r=GB(n),i=r===GB(t),o=n.sideOf!==void 0;return(0,N.jsxs)(`div`,{"data-testid":o?`side-session-row`:`project-row`,className:`group flex items-center gap-2.5 rounded-md py-2 pr-2.5 ${o?`pl-7`:`pl-2.5`} ${i?`bg-zinc-100 dark:bg-zinc-800`:`hover:bg-zinc-50 dark:hover:bg-zinc-800/50`}`,children:[(0,N.jsxs)(`button`,{type:`button`,role:`menuitem`,onClick:()=>{a(!1),o?e.onSwitch(n.root,n.id):e.onSwitch(n.root)},className:`flex min-w-0 flex-1 items-center gap-2.5 text-left`,children:[(0,N.jsx)(pW,{activity:n.activity}),(0,N.jsxs)(`span`,{className:`flex min-w-0 flex-col gap-0.5`,children:[(0,N.jsx)(`span`,{className:`truncate text-[13px] ${i?`font-semibold text-zinc-900 dark:text-zinc-100`:`font-medium text-zinc-900 dark:text-zinc-100`}`,children:o?n.label??n.name:n.name}),!o&&(0,N.jsx)(`span`,{className:`truncate font-mono text-[11px] text-zinc-400 dark:text-zinc-500`,children:n.root})]})]}),(0,N.jsxs)(`span`,{className:`flex shrink-0 items-center gap-1.5`,children:[n.needsAttention?(0,N.jsxs)(`span`,{className:`flex items-center gap-1 text-[11px] font-medium ${n.activity===`ready-for-review`?`text-violet-700 dark:text-violet-400`:`text-amber-600 dark:text-amber-500`}`,children:[n.activity===`ready-for-review`?(0,N.jsx)(hW,{className:`h-3 w-3`}):(0,N.jsx)(mW,{className:`h-3 w-3`}),fW[n.activity]]}):(0,N.jsx)(`span`,{className:`text-[11px] ${n.activity===`working`?`text-blue-700 dark:text-blue-400`:`text-zinc-400 dark:text-zinc-500`}`,children:fW[n.activity]}),!o&&e.onOpenSide&&(0,N.jsx)(`button`,{type:`button`,title:`New side session on ${n.name}`,"aria-label":`New side session on ${n.name}`,onClick:t=>{t.stopPropagation(),a(!1),e.onOpenSide?.(n.root)},className:`flex h-5 w-5 items-center justify-center rounded border border-zinc-300 text-zinc-500 hover:border-zinc-400 hover:text-zinc-800 dark:border-zinc-600 dark:text-zinc-400 dark:hover:border-zinc-500 dark:hover:text-zinc-100`,children:(0,N.jsxs)(`svg`,{className:`h-2.5 w-2.5`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,children:[(0,N.jsx)(`path`,{d:`M12 5v14`}),(0,N.jsx)(`path`,{d:`M5 12h14`})]})}),(o||c>1)&&(0,N.jsx)(`button`,{type:`button`,title:`Close ${o?n.label??n.name:n.name}`,"aria-label":`Close ${o?n.label??n.name:n.name}`,onClick:t=>{t.stopPropagation(),o?e.onClose(n.root,n.id):e.onClose(n.root)},className:`flex h-5 w-5 items-center justify-center rounded border border-transparent text-zinc-400 opacity-0 group-hover:border-zinc-300 group-hover:opacity-100 hover:text-zinc-700 dark:group-hover:border-zinc-600 dark:hover:text-zinc-200`,children:(0,N.jsxs)(`svg`,{className:`h-2.5 w-2.5`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,children:[(0,N.jsx)(`path`,{d:`M18 6 6 18`}),(0,N.jsx)(`path`,{d:`m6 6 12 12`})]})})]})]},r)}),(0,N.jsx)(`div`,{className:`my-1 h-px bg-zinc-200 dark:bg-zinc-700`}),(0,N.jsxs)(`button`,{type:`button`,role:`menuitem`,onClick:()=>{a(!1),e.onOpen()},className:`flex w-full items-center gap-2.5 rounded-md px-2.5 py-2 text-left text-[13px] text-zinc-700 hover:bg-zinc-50 dark:text-zinc-300 dark:hover:bg-zinc-800/50`,children:[(0,N.jsxs)(`svg`,{className:`h-3.5 w-3.5 text-zinc-500`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,N.jsx)(`path`,{d:`M12 5v14`}),(0,N.jsx)(`path`,{d:`M5 12h14`})]}),`Open a project…`]})]})]})}function _W({label:e,browse:t,onBrowse:n,onSelect:r,onCancel:i}){let a=t?.path??`/`,o=t?.entries??[],s=t?.status===`loading`,[c,l]=(0,v.useState)(a);return(0,v.useEffect)(()=>{l(a)},[a]),(0,N.jsxs)(`div`,{className:`rounded-md border border-zinc-300 p-2 dark:border-zinc-700`,"data-testid":`server-path-picker`,children:[(0,N.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[(0,N.jsx)(`span`,{className:`text-xs font-semibold text-zinc-600 dark:text-zinc-300`,children:e}),(0,N.jsx)(`button`,{type:`button`,onClick:i,className:`text-xs text-zinc-500 hover:text-zinc-800 dark:text-zinc-400 dark:hover:text-zinc-200`,children:`Cancel`})]}),(0,N.jsxs)(`form`,{className:`mb-2 flex gap-1`,onSubmit:e=>{e.preventDefault();let t=c.trim();t&&n(t)},children:[(0,N.jsx)(`input`,{value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Escape`&&(e.stopPropagation(),l(a))},spellCheck:!1,autoCapitalize:`off`,autoCorrect:`off`,"aria-label":`Current directory`,"data-testid":`picker-path`,className:`min-w-0 flex-1 rounded border border-zinc-300 px-2 py-1 font-mono text-xs text-zinc-700 focus:border-zinc-500 focus:outline-none dark:border-zinc-700 dark:bg-zinc-900 dark:text-zinc-200`}),(0,N.jsx)(`button`,{type:`submit`,disabled:c.trim()===``||c===a,className:`rounded border border-zinc-300 px-2 py-1 text-xs text-zinc-600 hover:border-zinc-400 disabled:cursor-not-allowed disabled:opacity-40 dark:border-zinc-700 dark:text-zinc-300`,children:`Go`})]}),t?.status===`error`&&(0,N.jsx)(`p`,{role:`alert`,className:`mb-2 text-xs text-red-600 dark:text-red-400`,children:t.error}),(0,N.jsxs)(`div`,{className:`mb-2 flex gap-2`,children:[(0,N.jsx)(`button`,{type:`button`,disabled:!t?.parent,onClick:()=>t?.parent&&n(t.parent),className:`rounded border border-zinc-300 px-2 py-1 text-xs text-zinc-600 hover:border-zinc-400 disabled:cursor-not-allowed disabled:opacity-40 dark:border-zinc-700 dark:text-zinc-300`,children:`Up`}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>r(a),className:`rounded bg-zinc-800 px-2 py-1 text-xs font-medium text-white hover:bg-zinc-700 dark:bg-zinc-200 dark:text-zinc-900`,children:`Use this directory`})]}),(0,N.jsxs)(`ul`,{className:`max-h-40 overflow-y-auto`,children:[s&&o.length===0&&(0,N.jsx)(`li`,{className:`px-2 py-1 text-xs text-zinc-400`,children:`Loading…`}),!s&&o.length===0&&t?.status!==`error`&&(0,N.jsx)(`li`,{className:`px-2 py-1 text-xs text-zinc-400 dark:text-zinc-500`,children:`No subdirectories`}),o.map(e=>(0,N.jsx)(`li`,{children:(0,N.jsxs)(`button`,{type:`button`,onClick:()=>n(e.path),className:`w-full truncate rounded px-2 py-1 text-left font-mono text-xs text-zinc-600 hover:bg-zinc-100 dark:text-zinc-300 dark:hover:bg-zinc-800`,title:e.path,children:[e.name,e.name.endsWith(`:`)?`\\`:`/`]})},e.path))]})]})}function vW(e){return e.split(/[\\/]/).filter(Boolean).at(-1)??e}function yW(e){let{sandbox:t,applyState:n,blocked:r=!1,onCloseBrowser:i}=e,[a,o]=(0,v.useState)(!1),s=(0,v.useRef)(!1);if((0,v.useEffect)(()=>{r&&a&&(s.current=!1,o(!1))},[r,a]),(0,v.useEffect)(()=>{s.current&&n?.status!==`applying`&&(n?.status===`error`?s.current=!1:(s.current=!1,o(!1),i()))},[n,i]),!t)return(0,N.jsx)(`span`,{className:`${lW} border-dashed border-zinc-300 text-zinc-400 dark:border-zinc-700 dark:text-zinc-500`,title:`This server runs without a sandbox, so there is no root to move`,children:`No sandbox`});let c=t.locks?.root===!0,l=vW(t.root);return(0,N.jsxs)(`div`,{className:`relative min-w-[4rem] max-w-[14rem]`,children:[(0,N.jsxs)(`button`,{type:`button`,disabled:c,"aria-label":c?`Sandbox root: ${t.root} (locked)`:`Sandbox root: ${t.root}`,title:c?`${t.root} — locked by the server's configuration`:t.root,onClick:()=>{e.onOpened(),o(!0),e.onBrowse(t.root)},className:`${uW} max-w-full gap-1.5 ${c?`cursor-not-allowed border-zinc-200 text-zinc-400 dark:border-zinc-800 dark:text-zinc-500`:`border-zinc-300 text-zinc-600 hover:border-zinc-400 hover:text-zinc-800 dark:border-zinc-700 dark:text-zinc-300 dark:hover:border-zinc-500 dark:hover:text-zinc-100`}`,children:[(0,N.jsx)(`span`,{className:`truncate font-mono`,children:l}),c?(0,N.jsx)(`span`,{className:`text-zinc-400`,children:`(locked)`}):(0,N.jsx)(`span`,{"aria-hidden":`true`,children:`▾`})]}),a&&!r&&(0,N.jsxs)(`div`,{className:`absolute left-0 top-full z-20 mt-1 w-[380px] rounded-lg border border-zinc-200 bg-white p-2 shadow-xl dark:border-zinc-700 dark:bg-zinc-900`,children:[n?.status===`error`&&(0,N.jsx)(`p`,{role:`alert`,className:`mb-2 text-xs text-red-600 dark:text-red-400`,children:n.message}),(0,N.jsx)(_W,{label:`Choose the sandbox root`,browse:e.browse,onBrowse:e.onBrowse,onSelect:t=>{s.current=!0,e.onSelect(t)},onCancel:()=>{s.current=!1,o(!1),i()}})]})]})}function bW(e){let t=(Date.now()-new Date(e).getTime())/1e3;return t<90?`now`:t<3600?`${Math.round(t/60)}m ago`:t<86400?`${Math.round(t/3600)}h ago`:`${Math.round(t/86400)}d ago`}function xW(e){return e.slice(e.lastIndexOf(`/`)+1)}function SW({status:e,selected:t,log:n,onFetchLog:r,onCloseLog:i,onShowCommit:a}){let[o,s]=(0,v.useState)(!1),c=()=>{s(!1),i()},l=oH(()=>{o&&c()}),u=e?.repos??[],d=(t===null?null:NV(u,t))??(t===null&&u.length===1?u[0]:null),f=d&&(d.ahead>0||d.behind>0)?` ${d.ahead>0?`↑${d.ahead}`:``}${d.behind>0?`↓${d.behind}`:``}`:``,p=u.length>1&&d!==null&&d.repo!==``?`${xW(d.repo)} `:``,m=e===null?`…`:d?.branch??`—`,h=d!==null&&n?.repo===d.repo?n:null,g=h?.entries??null,_=h?.error??null,y=(0,v.useMemo)(()=>g===null?null:XU(g),[g]);return(0,v.useEffect)(()=>{o&&d!==null&&n?.repo!==d.repo&&r(d.repo)},[o,d?.repo,r]),(0,N.jsxs)(`div`,{className:`relative min-w-[4rem] max-w-[14rem] shrink-[2]`,ref:l,children:[(0,N.jsxs)(`button`,{type:`button`,disabled:d===null,onClick:()=>{if(d!==null){if(o)return c();s(!0),r(d.repo)}},title:d===null?`no repository selected`:`git history — ${d.repo===``?`this project`:d.repo}`,className:`${uW} max-w-full border-zinc-300 font-mono text-zinc-500 hover:border-zinc-400 hover:text-zinc-700 disabled:cursor-default disabled:hover:border-zinc-300 disabled:hover:text-zinc-500 dark:border-zinc-800 dark:text-zinc-400 dark:hover:border-zinc-600 dark:hover:text-zinc-200 dark:disabled:hover:border-zinc-800 dark:disabled:hover:text-zinc-400`,children:[(0,N.jsxs)(`span`,{className:`truncate`,children:[p,`⎇ `,m]}),f]}),o&&d!==null&&(0,N.jsxs)(`div`,{className:`absolute left-0 top-full z-20 mt-1 max-h-96 w-[26rem] max-w-[80vw] overflow-y-auto rounded-lg border border-zinc-200 bg-white py-1 shadow-xl dark:border-zinc-700 dark:bg-zinc-900`,children:[_!==null&&(0,N.jsxs)(`div`,{role:`alert`,className:`px-3 py-2 text-xs text-red-600 dark:text-red-400`,children:[`history unavailable: `,_]}),g===null&&_===null&&(0,N.jsx)(`div`,{className:`px-3 py-2 text-xs text-zinc-500`,children:`loading…`}),g?.length===0&&(0,N.jsx)(`div`,{className:`px-3 py-2 text-xs text-zinc-500`,children:`no commits`}),y?.rows.map(e=>{let{entry:t}=e;return(0,N.jsxs)(`button`,{type:`button`,onClick:()=>{a(d.repo,t.sha),c()},style:{height:36},className:`flex w-full items-center gap-2 pl-2 pr-3 text-left text-sm hover:bg-zinc-100 dark:hover:bg-zinc-800`,children:[(0,N.jsx)(JU,{row:e,laneCount:y.laneCount}),(0,N.jsx)(`span`,{className:`shrink-0 font-mono text-xs text-amber-600 dark:text-amber-500`,children:t.sha.slice(0,7)}),t.refs.map(t=>{let n=t===d.branch?`#10b981`:WU(e.lane);return(0,N.jsx)(`span`,{style:{borderColor:n,color:n},className:`max-w-[8rem] shrink-0 truncate rounded-full border px-1.5 font-mono text-[10px] leading-4 ${t===d.branch?`font-semibold`:``}`,children:t},t)}),t.tags.map(e=>(0,N.jsxs)(`span`,{title:`tag ${e}`,className:`max-w-[8rem] shrink-0 truncate rounded border border-zinc-300 px-1 font-mono text-[10px] leading-4 text-zinc-500 dark:border-zinc-600 dark:text-zinc-400`,children:[`◆ `,e]},`tag-${e}`)),(0,N.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-zinc-700 dark:text-zinc-300`,title:t.subject,children:t.subject}),(0,N.jsxs)(`span`,{className:`shrink-0 text-xs text-zinc-400 dark:text-zinc-600`,children:[t.author,` · `,bW(t.date)]})]},t.sha)})]})]})}var CW=[{name:`draw.io / diagrams.net`,website:`https://www.drawio.com/`,license:`Apache-2.0`,text:` Apache License
869
869
  Version 2.0, January 2004
870
870
  http://www.apache.org/licenses/
871
871
 
@@ -1487,7 +1487,7 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1487
1487
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1488
1488
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1489
1489
  SOFTWARE.
1490
- `}],CW=`MIT License
1490
+ `}],wW=`MIT License
1491
1491
 
1492
1492
  Copyright (c) 2026 Laurent Francoise
1493
1493
 
@@ -1508,29 +1508,30 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1508
1508
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1509
1509
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1510
1510
  SOFTWARE.
1511
- `,wW=[[`draw.io / diagrams.net`,`Diagram viewer and editor`],[`GrapesJS`,`Poster editor`],[`React`,`User interface`],[`CodeMirror · xterm.js · node-pty`,`Code editor and terminal`],[`PDF.js · docx`,`Document tools`],[`Mermaid · KaTeX`,`Diagrams and mathematical notation`]],TW=[{name:`pi-outpost`,license:`MIT`,text:CW},...SW];function EW(){let[e,t]=(0,v.useState)(!1),n=(0,v.useRef)(null);return(0,v.useLayoutEffect)(()=>{n.current?.focus({preventScroll:!0});let e=n.current?.closest(`.overflow-y-auto`);e&&(e.scrollTop=0)},[e]),e?(0,N.jsxs)(`div`,{className:`text-zinc-700 dark:text-zinc-300`,children:[(0,N.jsx)(`button`,{type:`button`,onClick:()=>t(!1),className:`mb-3 text-xs text-zinc-500 hover:underline dark:text-zinc-400`,children:`← Back to credits`}),(0,N.jsx)(`h3`,{ref:n,tabIndex:-1,className:`text-sm font-semibold outline-none`,children:`Third-party notices`}),(0,N.jsx)(`p`,{className:`mt-2 text-xs text-zinc-500 dark:text-zinc-400`,children:`License texts and attributions for pi-outpost and the components acknowledged here.`}),TW.map(e=>(0,N.jsxs)(`section`,{className:`mt-5 border-t border-zinc-200 pt-3 dark:border-zinc-700`,children:[(0,N.jsxs)(`h4`,{className:`text-sm font-semibold`,children:[e.name,` `,(0,N.jsxs)(`span`,{className:`font-normal text-zinc-500 dark:text-zinc-400`,children:[`· `,e.license]})]}),(0,N.jsx)(`pre`,{className:`mt-2 whitespace-pre-wrap break-words font-mono text-[11px] leading-relaxed`,children:e.text})]},e.name))]}):(0,N.jsxs)(`div`,{className:`text-sm text-zinc-700 dark:text-zinc-300`,children:[(0,N.jsxs)(`section`,{className:`pb-5`,children:[(0,N.jsx)(`h3`,{ref:n,tabIndex:-1,className:`text-xl font-semibold tracking-tight outline-none`,children:`pi-outpost`}),(0,N.jsx)(`p`,{className:`mt-1 text-xs text-zinc-500 dark:text-zinc-400`,children:`Created by Laurent Francoise · MIT license`}),(0,N.jsxs)(`a`,{className:`mt-3 inline-flex items-center gap-2 text-xs underline underline-offset-4`,href:`https://laurentftech.github.io/pi-outpost/`,target:`_blank`,rel:`noopener noreferrer`,children:[`Project website `,(0,N.jsx)(`span`,{"aria-hidden":`true`,children:`↗`})]})]}),(0,N.jsxs)(`section`,{className:`border-t border-zinc-200 pt-4 dark:border-zinc-700`,children:[(0,N.jsx)(`h3`,{className:`text-xs font-semibold uppercase tracking-wider text-zinc-500 dark:text-zinc-400`,children:`Open-source acknowledgements`}),(0,N.jsx)(`p`,{className:`mt-2 text-xs text-zinc-500 dark:text-zinc-400`,children:`Thanks to the authors and contributors of these projects.`}),(0,N.jsx)(`dl`,{className:`mt-3 space-y-3`,children:wW.map(([e,t])=>(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`dt`,{className:`text-xs font-medium`,children:e}),(0,N.jsx)(`dd`,{className:`mt-0.5 text-xs text-zinc-500 dark:text-zinc-400`,children:t})]},e))}),(0,N.jsxs)(`button`,{type:`button`,onClick:()=>t(!0),className:`mt-4 flex w-full items-center justify-between rounded-md border border-zinc-300 px-3 py-2 text-xs hover:bg-zinc-100 dark:border-zinc-700 dark:hover:bg-zinc-800`,children:[`Third-party notices `,(0,N.jsx)(`span`,{"aria-hidden":`true`,children:`→`})]})]})]})}function DW(e){if(e.installed===void 0)return`not installed`;if(e.restartNeeded)return`${e.installed} installed — restart to use it`;if(e.pinned!==void 0)return`${e.installed}, pinned`;let t=e.check;if(!t)return e.installed;switch(t.state){case`checking`:return`${e.installed}, checking…`;case`newer`:return`${e.installed} — ${t.latest} available`;case`current`:return`${e.installed}, up to date`;case`failed`:return`${e.installed}, not checked: ${t.reason}`;case`off`:return`${e.installed}, not checked: ${t.reason}`}}function OW({packages:e,update:t,locked:n,onCheck:r,onUpdate:i}){let[a,o]=(0,v.useState)(null);if(e===null||e.length===0)return null;let s=t?.status===`pending`?t.source:null;return(0,N.jsxs)(`div`,{className:`mt-3`,"data-testid":`pi-packages`,children:[(0,N.jsxs)(`div`,{className:`mb-1 flex items-center justify-between`,children:[(0,N.jsx)(`span`,{className:`text-xs font-medium text-zinc-600 dark:text-zinc-400`,children:`Packages`}),(0,N.jsx)(`button`,{type:`button`,onClick:r,className:`text-xs text-zinc-500 underline hover:text-zinc-800 dark:hover:text-zinc-200`,children:`check for updates`})]}),(0,N.jsx)(`ul`,{className:`space-y-1`,children:e.map(e=>{let r=e.check?.state===`newer`&&!e.restartNeeded?e.check.latest:void 0;return(0,N.jsxs)(`li`,{"data-testid":`pi-package`,className:`rounded bg-zinc-50 px-2 py-1 text-xs dark:bg-zinc-800`,children:[(0,N.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,N.jsx)(`span`,{className:`min-w-0 truncate font-mono text-zinc-700 dark:text-zinc-300`,title:e.source,children:e.name}),r&&!n&&a!==e.source&&(0,N.jsx)(`button`,{type:`button`,disabled:s!==null,onClick:()=>o(e.source),className:`shrink-0 rounded border border-zinc-300 px-1.5 py-0.5 text-zinc-700 hover:bg-zinc-100 disabled:opacity-50 dark:border-zinc-600 dark:text-zinc-200 dark:hover:bg-zinc-700`,children:s===e.source?`updating…`:`Update`})]}),(0,N.jsx)(`div`,{className:`line-clamp-2 text-zinc-500 dark:text-zinc-400`,"data-testid":`pi-package-status`,title:DW(e),children:DW(e)}),r&&a===e.source&&(0,N.jsxs)(`div`,{className:`mt-1 rounded border border-amber-300 bg-amber-50 p-2 text-amber-900 dark:border-amber-700 dark:bg-amber-950/40 dark:text-amber-200`,"data-testid":`pi-package-confirm`,children:[(0,N.jsxs)(`p`,{children:[`This replaces code that runs with the agent's privileges: `,e.name,` `,e.installed,` → `,r,`. It takes effect when pi-outpost restarts.`]}),(0,N.jsxs)(`div`,{className:`mt-1 flex gap-2`,children:[(0,N.jsxs)(`button`,{type:`button`,onClick:()=>{o(null),i(e.source)},className:`rounded bg-amber-600 px-2 py-0.5 text-white hover:bg-amber-700`,children:[`Install `,r]}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>o(null),className:`rounded px-2 py-0.5 hover:bg-amber-100 dark:hover:bg-amber-900/40`,children:`Cancel`})]})]}),t&&t.status!==`pending`&&t.source===e.source&&(0,N.jsx)(`p`,{"data-testid":`pi-package-result`,className:`mt-1 ${t.status===`installed`?`text-emerald-700 dark:text-emerald-400`:`text-amber-700 dark:text-amber-400`}`,children:t.message})]},e.source)})})]})}function kW({reasons:e,canRestart:t,restarting:n,onRestart:r}){let[i,a]=(0,v.useState)(!1);return e.length===0?null:(0,N.jsxs)(`div`,{className:`mt-3 rounded border border-sky-200 bg-sky-50 p-2 text-xs text-sky-900 dark:border-sky-900 dark:bg-sky-950/40 dark:text-sky-200`,"data-testid":`restart-needed`,children:[(0,N.jsxs)(`p`,{children:[`Installed and waiting on a restart to run: `,e.join(`, `),`.`]}),t?n?(0,N.jsx)(`p`,{className:`mt-1`,children:`Restarting pi-outpost…`}):i?(0,N.jsxs)(`div`,{className:`mt-1`,children:[(0,N.jsx)(`p`,{children:`pi-outpost stops and starts again in the same terminal. Every open window reconnects by itself, and conversations are kept.`}),(0,N.jsxs)(`div`,{className:`mt-1 flex gap-2`,children:[(0,N.jsx)(`button`,{type:`button`,onClick:()=>{a(!1),r()},className:`rounded bg-sky-700 px-2 py-0.5 text-white hover:bg-sky-800`,children:`Restart now`}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>a(!1),className:`rounded px-2 py-0.5 hover:bg-sky-100 dark:hover:bg-sky-900/50`,children:`Cancel`})]})]}):(0,N.jsx)(`button`,{type:`button`,onClick:()=>a(!0),className:`mt-1 rounded border border-sky-300 px-2 py-0.5 hover:bg-sky-100 dark:border-sky-700 dark:hover:bg-sky-900/50`,children:`Restart pi-outpost`}):null]})}var AW=30,jW={display:`-webkit-box`,WebkitLineClamp:2,WebkitBoxOrient:`vertical`,overflow:`hidden`};function MW({skills:e,groups:t,enabled:n,onChange:r,disabled:i=!1,bound:a}){let[o,s]=(0,v.useState)(()=>e.length>40?new Set(e.filter(e=>n.has(e.relativePath)).map(e=>e.group)):new Set(t.map(e=>e.path))),[c,l]=(0,v.useState)(``),[u,d]=(0,v.useState)(!1),f=c.trim().toLocaleLowerCase(),p=f!==``||u,m=e=>(!u||n.has(e.relativePath))&&(!f||`${e.name} ${e.relativePath} ${e.description??``}`.toLocaleLowerCase().includes(f)),h=new Map;for(let t of e)h.set(t.group,[...h.get(t.group)??[],t]);let g=e.filter(e=>n.has(e.relativePath)).length,_=p?e.filter(m).length:e.length,y=(e,t)=>{let i=new Set(n);for(let n of e)t?i.add(n.relativePath):i.delete(n.relativePath);r(i)},b=e=>{let t=new Set(n);t.has(e)?t.delete(e):t.add(e),r(t)},x=e=>s(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n});return(0,N.jsxs)(`section`,{className:`rounded-xl border border-zinc-200 p-4 dark:border-zinc-800`,"aria-label":`Collection skills`,children:[(0,N.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,N.jsxs)(`h3`,{className:`text-sm font-semibold text-zinc-800 dark:text-zinc-200`,children:[`Skills `,(0,N.jsxs)(`span`,{className:`font-normal text-zinc-500`,children:[`· `,g,` of `,e.length,` on`]})]}),(0,N.jsxs)(`div`,{className:`flex gap-2`,children:[(0,N.jsx)(`button`,{type:`button`,disabled:i||g===e.length,onClick:()=>y(e,!0),className:`rounded-md border px-2.5 py-1 text-xs disabled:opacity-50`,children:`All on`}),(0,N.jsx)(`button`,{type:`button`,disabled:i||g===0,onClick:()=>y(e,!1),className:`rounded-md border px-2.5 py-1 text-xs disabled:opacity-50`,children:`All off`})]})]}),a?(0,N.jsx)(`p`,{className:`mt-2 rounded border border-amber-200 bg-amber-50 p-2 text-xs text-amber-800`,children:a.kind===`count`?`This repository holds more skills than the ${a.limit} listed here.`:`Folders deeper than ${a.limit} levels were not searched for skills.`}):null,e.length>0?(0,N.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-2`,children:[(0,N.jsx)(`input`,{type:`search`,"aria-label":`Search skills`,placeholder:`Search skills by name or folder`,value:c,onChange:e=>l(e.target.value),className:`min-w-0 flex-1 rounded-md border bg-transparent px-2.5 py-1 text-xs`}),(0,N.jsxs)(`button`,{type:`button`,"aria-pressed":u,onClick:()=>d(e=>!e),className:`rounded-md px-2.5 py-1 text-xs ${u?`bg-zinc-900 text-white dark:bg-zinc-100 dark:text-zinc-900`:`border`}`,children:[`Only on (`,g,`)`]})]}):null,!p&&g>0&&g<=AW?(0,N.jsxs)(`div`,{role:`region`,"aria-label":`Skills that are on`,className:`mt-3 rounded-lg border border-emerald-200 bg-emerald-50/60 p-2 dark:border-emerald-900 dark:bg-emerald-950/30`,children:[(0,N.jsx)(`p`,{className:`px-1 text-[11px] font-medium text-emerald-800 dark:text-emerald-300`,children:`Turned on`}),(0,N.jsx)(`ul`,{className:`mt-1 space-y-1`,children:e.filter(e=>n.has(e.relativePath)).map(e=>(0,N.jsxs)(`li`,{className:`flex items-start justify-between gap-2 px-1`,children:[(0,N.jsxs)(`span`,{className:`min-w-0 text-xs`,children:[(0,N.jsx)(`span`,{className:`font-medium text-zinc-800 dark:text-zinc-100`,children:e.name}),` `,(0,N.jsx)(`span`,{className:`font-mono text-[11px] text-zinc-500`,children:e.group||`(repository root)`}),(0,N.jsx)(NW,{skill:e,checked:!0})]}),(0,N.jsx)(`button`,{type:`button`,"aria-label":`Turn off ${e.name} (${e.relativePath})`,disabled:i,onClick:()=>b(e.relativePath),className:`shrink-0 rounded border bg-white px-2 py-0.5 text-[11px] disabled:opacity-50 dark:bg-zinc-900`,children:`Turn off`})]},e.relativePath))})]}):null,e.length===0?(0,N.jsx)(`p`,{className:`mt-4 text-xs text-zinc-400`,children:`This repository holds no skills.`}):null,p&&_===0?(0,N.jsx)(`p`,{className:`mt-4 text-xs text-zinc-400`,children:u&&!f?`No skill is on.`:`No skill matches.`}):null,(0,N.jsx)(`ul`,{className:`mt-3 space-y-2`,children:t.map(e=>{let t=h.get(e.path)??[],r=p?t.filter(m):t;if(p&&r.length===0)return null;let a=r.filter(e=>n.has(e.relativePath)).length,s=p||o.has(e.path);return(0,N.jsxs)(`li`,{className:`rounded-lg border border-zinc-100 dark:border-zinc-800`,children:[(0,N.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-3 py-2`,children:[(0,N.jsxs)(`button`,{type:`button`,"aria-expanded":s,onClick:()=>x(e.path),className:`flex min-w-0 flex-1 items-center gap-2 text-left`,children:[(0,N.jsx)(`span`,{"aria-hidden":`true`,className:`text-xs text-zinc-400`,children:s?`▾`:`▸`}),(0,N.jsx)(`span`,{className:`truncate font-mono text-xs font-medium text-zinc-700 dark:text-zinc-200`,children:e.label}),(0,N.jsxs)(`span`,{className:`shrink-0 text-[11px] text-zinc-500`,children:[a,`/`,r.length,` on`]})]}),(0,N.jsxs)(`div`,{className:`flex shrink-0 gap-1`,children:[(0,N.jsx)(`button`,{type:`button`,"aria-label":`All on in ${e.label}`,disabled:i||a===r.length,onClick:()=>y(r,!0),className:`rounded border px-2 py-0.5 text-[11px] disabled:opacity-50`,children:`All on`}),(0,N.jsx)(`button`,{type:`button`,"aria-label":`All off in ${e.label}`,disabled:i||a===0,onClick:()=>y(r,!1),className:`rounded border px-2 py-0.5 text-[11px] disabled:opacity-50`,children:`All off`})]})]}),s?(0,N.jsx)(`ul`,{className:`space-y-1 border-t border-zinc-100 px-3 py-2 dark:border-zinc-800`,children:r.map(e=>{let t=n.has(e.relativePath);return(0,N.jsx)(`li`,{children:(0,N.jsxs)(`label`,{className:`flex items-start gap-2 rounded px-1 py-1 ${i?`opacity-60`:`cursor-pointer hover:bg-zinc-50 dark:hover:bg-zinc-800/60`}`,children:[(0,N.jsx)(`input`,{type:`checkbox`,role:`switch`,"aria-checked":t,"aria-label":`${e.name} (${e.relativePath})`,checked:t,disabled:i,onChange:()=>b(e.relativePath),className:`mt-0.5`}),(0,N.jsxs)(`span`,{className:`min-w-0`,children:[(0,N.jsx)(`span`,{className:`block truncate text-sm text-zinc-800 dark:text-zinc-100`,children:e.name}),e.description?(0,N.jsx)(`span`,{title:e.description,style:jW,className:`text-[11px] text-zinc-500`,children:e.description}):null,(0,N.jsx)(NW,{skill:e,checked:t})]})]})},e.relativePath)})}):null]},e.path)})})]})}function NW({skill:e,checked:t}){return t===(e.state!==`off`)?e.state===`on-loaded`?(0,N.jsx)(`span`,{className:`block text-[11px] text-emerald-700 dark:text-emerald-400`,children:`Loaded`}):e.state===`on-not-loaded`?(0,N.jsxs)(`span`,{className:`block text-[11px] text-amber-700 dark:text-amber-400`,children:[`Not loaded — `,e.reason]}):e.state===`on-missing`?(0,N.jsxs)(`span`,{className:`block text-[11px] text-rose-700 dark:text-rose-400`,children:[`Missing — `,e.reason]}):null:(0,N.jsx)(`span`,{className:`block text-[11px] font-medium text-sky-700 dark:text-sky-300`,children:t?`Pending: on`:`Pending: off`})}function PW(e,t){return[...new Set(e.map(e=>e.group))].sort().map(e=>({path:e,label:e||t}))}function FW(e){return e.skills.filter(e=>e.state!==`off`).map(e=>e.relativePath)}function IW(e,t){let n=new Set(e),r=new Set(t);return n.size===r.size&&[...n].every(e=>r.has(e))}function LW(e,t){if(t.status===`loading`)return`Removing ${e}…`;if(t.status===`error`)return t.message??`Could not remove ${e}`;let n=t.result;return n?n.status===`removed`?`Removed ${e} and deleted ${n.path}.`:n.status===`removed-files-kept`?`Removed ${e}. ${n.reason??`Its files were kept`} (${n.path}).`:`Removed ${e}, but not every file could be deleted${n.reason?` — ${n.reason}`:``}. What remains is at ${n.path}.`:`Removed ${e}.`}var RW={unchecked:`Not checked`,checking:`Checking…`,current:`Up to date`,updateable:`Update available`,dirty:`Local changes`,detached:`Detached HEAD`,ahead:`Local branch ahead`,diverged:`Histories diverged`,"no-upstream":`No upstream`,locked:`Locked`,busy:`Workspace busy`,unavailable:`Unavailable`,failed:`Check failed`};function zW(e){if(!e)return[];let t=new Map(e.resources.map(e=>[e.id,e])),n=new Set(e.repositories.flatMap(e=>e.resourceIds)),r=e.repositories.map(e=>({id:e.id,name:e.name,path:e.path,repository:e,resources:e.resourceIds.flatMap(e=>t.get(e)?[t.get(e)]:[])})),i=e.resources.filter(e=>!n.has(e.id)),a=i.filter(e=>e.unavailableReason),o=i.filter(e=>!e.unavailableReason);return o.length&&r.push({id:`local`,name:`Local and built in`,reason:`Not backed by an updateable Git repository`,resources:o}),a.length&&r.push({id:`unavailable`,name:`Provenance unavailable`,reason:`The active runtime did not report enough filesystem provenance`,resources:a}),r}function BW(e){let t=e.length;for(;t>0&&(e[t-1]===`/`||e[t-1]===`\\`);)--t;return t===e.length?e:e.slice(0,t)}function VW(e){let t=BW(e),n=Math.max(t.lastIndexOf(`/`),t.lastIndexOf(`\\`));return n<=0?`/`:t.slice(0,n)}function HW(e,t){let n=BW(t),r=Math.max(n.lastIndexOf(`/`),n.lastIndexOf(`\\`)),i=r>=0?n.slice(r+1):n;return`${BW(e)}/${i||`agent-resources`}`}function UW({kind:e,resources:t,removalLocked:n=!1,onRemove:r}){return(0,N.jsxs)(`section`,{className:`rounded-xl border border-zinc-200 p-4 dark:border-zinc-800`,children:[(0,N.jsxs)(`h3`,{className:`flex items-center justify-between text-sm font-semibold capitalize text-zinc-800 dark:text-zinc-200`,children:[(0,N.jsxs)(`span`,{children:[e,`s`]}),(0,N.jsx)(`span`,{className:`text-xs font-normal text-zinc-400`,children:t.length})]}),t.length===0?(0,N.jsx)(`p`,{className:`mt-4 text-xs text-zinc-400`,children:`None in this group`}):(0,N.jsx)(`ul`,{className:`mt-3 space-y-2`,children:t.map(e=>(0,N.jsxs)(`li`,{className:`rounded-lg bg-zinc-50 px-3 py-2 dark:bg-zinc-800/70`,children:[(0,N.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,N.jsx)(`p`,{className:`truncate text-sm font-medium text-zinc-700 dark:text-zinc-200`,children:e.name}),e.userRoot&&!n?(0,N.jsx)(`button`,{type:`button`,"aria-label":`Remove ${e.userRoot}`,onClick:()=>r(e),className:`text-xs text-zinc-500 hover:text-red-600`,children:`Remove`}):null]}),(0,N.jsx)(`p`,{className:`mt-0.5 truncate font-mono text-[11px] text-zinc-400`,title:e.path,children:e.path??e.unavailableReason??`Path unavailable`})]},e.id))})]})}function WW({preview:e,busy:t,error:n,onApply:r,onCancel:i}){let[a,o]=(0,v.useState)(()=>new Set(e.roots.filter(e=>!e.locked).map(e=>`${e.kind}:${e.path}`))),[s,c]=(0,v.useState)(!1),[l,u]=(0,v.useState)(()=>new Set),d=e.mode===`collection`,f=(0,v.useMemo)(()=>e.skills.map(e=>({...e,state:`off`})),[e.skills]),p=(0,v.useMemo)(()=>PW(e.skills,e.repositoryName),[e.skills,e.repositoryName]),m=e.roots.filter(e=>e.kind===`extension`&&a.has(`extension:${e.path}`)),h=m.length>0&&!s,g=t||!d&&a.size===0||h,_=()=>{let t=m.map(e=>e.path);d?r([],t,[...l]):r(e.roots.filter(e=>e.kind===`skill`&&a.has(`skill:${e.path}`)).map(e=>e.path),t)},y=e=>{c(!1),o(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return(0,N.jsxs)(`div`,{className:`space-y-3`,"data-testid":`resource-preview`,children:[(0,N.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,N.jsxs)(`div`,{className:`min-w-0`,children:[(0,N.jsx)(`h3`,{className:`truncate text-xl font-semibold text-zinc-900 dark:text-zinc-100`,children:e.repositoryName}),(0,N.jsx)(`p`,{className:`mt-0.5 truncate font-mono text-[11px] text-zinc-500`,title:e.repositoryPath,children:e.repositoryPath})]}),(0,N.jsxs)(`div`,{className:`flex shrink-0 gap-2`,children:[(0,N.jsx)(`button`,{type:`button`,onClick:i,className:`rounded-md border px-3 py-1.5 text-xs`,children:`Cancel`}),(0,N.jsx)(`button`,{type:`button`,disabled:g,onClick:_,className:`rounded-md bg-zinc-900 px-3 py-1.5 text-xs font-medium text-white disabled:opacity-50 dark:bg-zinc-100 dark:text-zinc-900`,children:t?`Saving…`:`Save`})]})]}),h?(0,N.jsx)(`p`,{className:`text-xs text-amber-700`,children:`Confirm the extension warning below to save.`}):null,n?(0,N.jsx)(`p`,{role:`alert`,className:`text-xs text-red-600`,children:n}):null,d?(0,N.jsx)(MW,{skills:f,groups:p,enabled:l,onChange:u,disabled:t,...e.bound?{bound:e.bound}:{}}):null,e.roots.map(e=>{let t=`${e.kind}:${e.path}`;return(0,N.jsxs)(`label`,{className:`flex items-start gap-2 rounded border p-2 ${e.locked?`opacity-50`:`cursor-pointer`}`,children:[(0,N.jsx)(`input`,{type:`checkbox`,checked:a.has(t),disabled:e.locked,onChange:()=>y(t)}),(0,N.jsxs)(`span`,{children:[(0,N.jsxs)(`span`,{className:`block text-sm`,children:[e.name,` · `,e.kind]}),(0,N.jsx)(`span`,{className:`font-mono text-[11px] text-zinc-500`,children:e.path}),e.locked?(0,N.jsx)(`span`,{className:`block text-xs text-amber-700`,children:`Extension paths are locked`}):null]})]},t)}),m.length>0?(0,N.jsxs)(`label`,{className:`flex gap-2 rounded-md border border-amber-300 bg-amber-50 p-3 text-xs text-amber-900`,children:[(0,N.jsx)(`input`,{type:`checkbox`,checked:s,onChange:e=>c(e.target.checked)}),(0,N.jsx)(`span`,{children:`Extensions execute code with the agent's privileges. I trust the selected extension roots in this repository.`})]}):null]})}function GW(e){let t=(0,v.useRef)(null),n=(0,v.useRef)(e.onClose),r=(0,v.useRef)(!1),[i,a]=(0,v.useState)(null),[o,s]=(0,v.useState)(``),[c,l]=(0,v.useState)(`all`),[u,d]=(0,v.useState)(!1),[f,p]=(0,v.useState)(null),[m,h]=(0,v.useState)(null),[g,_]=(0,v.useState)(`skill`),[y,b]=(0,v.useState)(``),[x,S]=(0,v.useState)(!1),[C,w]=(0,v.useState)(``),[T,E]=(0,v.useState)(``),[D,O]=(0,v.useState)(!1),[ee,te]=(0,v.useState)(``),[k,ne]=(0,v.useState)(null),[A,re]=(0,v.useState)({}),[j,ie]=(0,v.useState)(null),[ae,oe]=(0,v.useState)(null),se=(0,v.useMemo)(()=>zW(e.inventory),[e.inventory]),ce=(0,v.useMemo)(()=>{let e=o.trim().toLocaleLowerCase();return se.flatMap(t=>{let n=`repository`in t?t.repository.collection:void 0,r=n?t.resources.filter(e=>e.kind!==`skill`):t.resources,i=c===`all`?r:r.filter(e=>e.kind===c),a=n&&c!==`extension`?n.skills:[],o=i.length+a.length;if(o===0&&!(n&&c===`all`)||u&&(!(`repository`in t)||![`updateable`,`dirty`,`failed`,`unavailable`,`busy`].includes(t.repository.assessment.status)))return[];let s=`${t.name} ${`path`in t?t.path??``:``} ${i.map(e=>`${e.name} ${e.path??``}`).join(` `)} ${a.map(e=>`${e.name} ${e.relativePath}`).join(` `)}`.toLocaleLowerCase(),l=n?n.skills.filter(e=>e.state!==`off`).length:void 0;return!e||s.includes(e)?[{...t,resources:i,count:o,...l===void 0?{}:{onCount:l}}]:[]})},[se,u,c,o]),le=ce.find(e=>e.id===i)??ce[0]??null;if((0,v.useEffect)(()=>{n.current=e.onClose},[e.onClose]),(0,v.useEffect)(()=>{re(t=>{let n={},r=!1;for(let[i,a]of Object.entries(t)){let t=e.inventory?.repositories.find(e=>e.id===i)?.collection;!t||IW(a,FW(t))?r=!0:n[i]=a}return r?n:t})},[e.inventory]),(0,v.useEffect)(()=>{e.open&&t.current?.focus()},[e.open]),(0,v.useEffect)(()=>{if(!e.open)return;let t=e=>{e.key===`Escape`&&n.current()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e.open]),(0,v.useEffect)(()=>{let t=e.operations.clonePath;t?.status===`ready`&&t.path&&!D&&E(t.path)},[D,e.operations.clonePath]),(0,v.useEffect)(()=>{e.operations.enrollment?.status===`ready`&&p(null)},[e.operations.enrollment]),(0,v.useEffect)(()=>{e.applyState?.status===`applying`?r.current=!0:r.current&&e.applyState===null&&(r.current=!1,p(null),h(null),S(!1))},[e.applyState]),!e.open)return null;let ue=le&&`repository`in le?le.repository:null,de=ue?e.operations.updates[ue.id]:void 0,fe=ue?.assessment,M=fe?.status===`updateable`&&fe.token&&fe.localRevision&&fe.upstreamRevision,pe=()=>{let t=y.trim();t&&(g===`skill`?e.onUpdateConfig({userSkillPaths:[...new Set([...e.userSkillPaths,t])]}):e.onUpdateConfig({userExtensionPaths:[...new Set([...e.userExtensionPaths,t])]}))},me=t=>{t.userRoot&&(t.kind===`skill`?e.onUpdateConfig({userSkillPaths:e.userSkillPaths.filter(e=>e!==t.userRoot)}):e.onUpdateConfig({userExtensionPaths:e.userExtensionPaths.filter(e=>e!==t.userRoot)}))},he=(t,n=!1)=>{let r=t.assessment;r.token&&r.localRevision&&r.upstreamRevision&&e.onUpdate(t.id,r.token,r.localRevision,r.upstreamRevision,n)},ge=ue?.collection,P=ge?FW(ge):[],_e=new Set(ue&&A[ue.id]?A[ue.id]:P),ve=ge?[...new Set([..._e,...P])].filter(e=>_e.has(e)!==P.includes(e)).length:0,ye=ue?e.operations.skills?.[ue.id]:void 0,be=e=>{if(!ue)return;let t=ue.id;re(n=>{let r={...n};return IW(e,P)?delete r[t]:r[t]=[...e],r})},xe=()=>{if(!ue)return;let e=ue.id;re(t=>{let n={...t};return delete n[e],n})},Se=()=>{if(!ue||!ge)return;let t=new Set(ge.skills.filter(e=>e.state!==`on-missing`).map(e=>e.relativePath));e.onSetSkills(ue.id,[..._e].filter(e=>t.has(e)))},Ce=ae?e.operations.removals?.[ae.id]:void 0,we=Ce?.status===`error`||Ce?.result?.status===`removed-delete-failed`;return(0,N.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/45 p-4`,role:`presentation`,onMouseDown:t=>{t.currentTarget===t.target&&e.onClose()},children:[(0,N.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-labelledby":`agent-resources-title`,className:`flex h-[min(760px,92vh)] w-[min(1120px,96vw)] flex-col overflow-hidden rounded-2xl border border-zinc-200 bg-white shadow-2xl dark:border-zinc-700 dark:bg-zinc-900`,children:[(0,N.jsxs)(`header`,{className:`flex items-center justify-between border-b border-zinc-200 px-5 py-4 dark:border-zinc-800`,children:[(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`h2`,{id:`agent-resources-title`,className:`text-lg font-semibold text-zinc-900 dark:text-zinc-100`,children:`Agent resources`}),(0,N.jsx)(`p`,{className:`text-xs text-zinc-500`,children:`Skills and extensions, grouped by repository`})]}),(0,N.jsxs)(`div`,{className:`flex gap-2`,children:[(0,N.jsx)(`button`,{type:`button`,disabled:e.operations.refresh?.status===`loading`,onClick:()=>e.onRefresh(),className:`rounded-md border px-3 py-1.5 text-xs disabled:opacity-50`,children:`Refresh all`}),(0,N.jsx)(`button`,{ref:t,type:`button`,"aria-label":`Close agent resources`,onClick:e.onClose,className:`rounded-md border px-2 py-1 text-sm`,children:`✕`})]})]}),(0,N.jsxs)(`div`,{className:`grid min-h-0 flex-1 grid-cols-[300px_1fr]`,children:[(0,N.jsxs)(`aside`,{className:`flex min-h-0 flex-col border-r border-zinc-200 bg-zinc-50/80 p-3 dark:border-zinc-800 dark:bg-zinc-950/40`,children:[(0,N.jsx)(`input`,{"aria-label":`Search resources`,value:o,onChange:e=>s(e.target.value),placeholder:`Search repositories or resources`,className:`rounded-md border bg-white px-3 py-2 text-xs dark:bg-zinc-900`}),(0,N.jsxs)(`div`,{className:`mt-2 flex flex-wrap gap-1`,children:[[`all`,`skill`,`extension`].map(e=>(0,N.jsx)(`button`,{type:`button`,"aria-pressed":c===e,onClick:()=>l(e),className:`rounded px-2 py-1 text-[11px] ${c===e?`bg-zinc-900 text-white dark:bg-zinc-100 dark:text-zinc-900`:`border`}`,children:e===`all`?`All`:`${e}s`},e)),(0,N.jsx)(`button`,{type:`button`,"aria-pressed":u,onClick:()=>d(e=>!e),className:`rounded px-2 py-1 text-[11px] ${u?`bg-amber-600 text-white`:`border`}`,children:`Needs attention`})]}),(0,N.jsxs)(`div`,{className:`mt-3 min-h-0 flex-1 space-y-1 overflow-y-auto`,children:[ce.map(e=>(0,N.jsxs)(`button`,{type:`button`,onClick:()=>a(e.id),className:`w-full rounded-lg px-3 py-2.5 text-left ${le?.id===e.id?`bg-white shadow-sm ring-1 ring-zinc-200 dark:bg-zinc-800 dark:ring-zinc-700`:`hover:bg-white/70 dark:hover:bg-zinc-900`}`,children:[(0,N.jsxs)(`span`,{className:`flex items-center justify-between gap-2 text-sm font-medium`,children:[(0,N.jsx)(`span`,{className:`truncate`,children:e.name}),(0,N.jsx)(`span`,{className:`shrink-0 text-xs text-zinc-400`,children:e.onCount===void 0?e.count??e.resources.length:`${e.onCount} on · ${e.count}`})]}),(0,N.jsx)(`span`,{className:`mt-1 block text-xs text-zinc-500`,children:`repository`in e?RW[e.repository.assessment.status]:e.reason})]},e.id)),ce.length===0?(0,N.jsx)(`p`,{className:`px-2 py-4 text-xs text-zinc-500`,children:`No matching resources`}):null]}),(0,N.jsxs)(`div`,{className:`mt-3 grid gap-2 border-t pt-3`,children:[(0,N.jsx)(`button`,{type:`button`,onClick:()=>{S(!1),p(`local`),h(`local`),e.onBrowseServerPath(y||`/`)},className:`rounded-md border bg-white px-3 py-2 text-xs font-medium dark:bg-zinc-900`,children:`Add local folder…`}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>p(`git`),className:`rounded-md bg-zinc-900 px-3 py-2 text-xs font-medium text-white dark:bg-zinc-100 dark:text-zinc-900`,children:`Add Git repository…`})]})]}),(0,N.jsxs)(`main`,{className:`min-w-0 overflow-y-auto p-6`,children:[ae&&Ce?(0,N.jsxs)(`div`,{role:we?`alert`:`status`,className:`mb-4 flex items-start justify-between gap-3 rounded-lg border p-3 text-sm ${we?`border-rose-200 bg-rose-50 text-rose-800`:`border-zinc-200 bg-zinc-50 text-zinc-700`}`,children:[(0,N.jsx)(`p`,{className:`min-w-0 break-words`,children:LW(ae.name,Ce)}),Ce.status===`loading`?null:(0,N.jsx)(`button`,{type:`button`,onClick:()=>oe(null),className:`shrink-0 text-xs underline`,children:`Dismiss`})]}):null,f===`local`?(0,N.jsxs)(`div`,{className:`max-w-xl space-y-4`,"data-testid":`add-local-folder`,children:[(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`h3`,{className:`text-lg font-semibold`,children:`Add local folder`}),(0,N.jsx)(`p`,{className:`text-xs text-zinc-500`,children:`Choose an existing folder on the server and how the agent should load it.`})]}),(0,N.jsx)(`div`,{className:`flex gap-2`,children:[`skill`,`extension`].map(t=>(0,N.jsx)(`button`,{type:`button`,"aria-pressed":g===t,disabled:t===`extension`&&e.extensionLock,onClick:()=>{_(t),S(!1)},className:`rounded-md px-3 py-1.5 text-xs ${g===t?`bg-zinc-900 text-white dark:bg-zinc-100 dark:text-zinc-900`:`border`}`,children:t===`skill`?`Skill folder`:`Extension folder`},t))}),(0,N.jsxs)(`div`,{className:`flex gap-2`,children:[(0,N.jsx)(`input`,{"aria-label":`Local resource folder`,value:y,onChange:e=>{S(!1),b(e.target.value)},className:`min-w-0 flex-1 rounded-md border bg-transparent px-3 py-2 text-sm`}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>{h(`local`),e.onBrowseServerPath(y||`/`)},className:`rounded-md border px-3 text-xs`,children:`Browse…`})]}),m===`local`?(0,N.jsx)(gW,{label:`Choose a local resource folder`,browse:e.serverBrowse,onBrowse:e.onBrowseServerPath,onSelect:t=>{S(!1),b(t),h(null),e.onCloseServerBrowser()},onCancel:()=>{h(null),e.onCloseServerBrowser()}}):null,g===`extension`?(0,N.jsxs)(`label`,{className:`flex gap-2 rounded-md border border-amber-300 bg-amber-50 p-3 text-xs text-amber-900`,children:[(0,N.jsx)(`input`,{type:`checkbox`,checked:x,onChange:e=>S(e.target.checked)}),(0,N.jsx)(`span`,{children:`Extensions execute code with the agent's privileges. I trust every extension in this folder.`})]}):null,e.extensionLock?(0,N.jsx)(`p`,{className:`text-xs text-zinc-500`,children:`Extension paths are locked by this deployment.`}):null,e.applyState?.status===`error`?(0,N.jsx)(`p`,{role:`alert`,className:`text-xs text-red-600`,children:e.applyState.message}):null,(0,N.jsxs)(`div`,{className:`flex gap-2`,children:[(0,N.jsx)(`button`,{type:`button`,onClick:()=>{S(!1),p(null),h(null),e.onCloseServerBrowser()},className:`rounded-md border px-3 py-1.5 text-xs`,children:`Cancel`}),(0,N.jsx)(`button`,{type:`button`,disabled:!y.trim()||e.applyState?.status===`applying`||g===`extension`&&(!x||e.extensionLock),onClick:pe,className:`rounded-md bg-zinc-900 px-3 py-1.5 text-xs text-white disabled:opacity-50`,children:e.applyState?.status===`applying`?`Applying…`:`Add folder`})]})]}):f===`git`?(0,N.jsx)(`div`,{className:`max-w-2xl space-y-4`,"data-testid":`add-git-repository`,children:e.operations.preview?.status===`ready`&&e.operations.preview.preview?(0,N.jsx)(WW,{onCancel:()=>{p(null),h(null),e.onCloseServerBrowser()},preview:e.operations.preview.preview,busy:e.operations.enrollment?.status===`loading`,error:e.operations.enrollment?.status===`error`?e.operations.enrollment.message:void 0,onApply:(t,n,r)=>r?e.onEnrollRepository(e.operations.preview.preview.token,t,n,r):e.onEnrollRepository(e.operations.preview.preview.token,t,n)}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`h3`,{className:`text-lg font-semibold`,children:`Add Git repository`}),(0,N.jsx)(`p`,{className:`text-xs text-zinc-500`,children:`Clone it to a local folder, then choose what to turn on.`})]}),(0,N.jsxs)(`label`,{className:`block`,children:[(0,N.jsx)(`span`,{className:`text-xs font-medium`,children:`Repository address`}),(0,N.jsx)(`input`,{"aria-label":`Repository address`,value:C,onChange:e=>w(e.target.value),onBlur:()=>{let t=C.trim();t&&(O(!1),te(t),e.onSuggestClonePath(C))},placeholder:`https://github.com/team/resources.git`,className:`mt-1 w-full rounded-md border bg-transparent px-3 py-2 text-sm`})]}),(0,N.jsxs)(`label`,{className:`block`,children:[(0,N.jsx)(`span`,{className:`text-xs font-medium`,children:`Local folder`}),(0,N.jsxs)(`div`,{className:`mt-1 flex gap-2`,children:[(0,N.jsx)(`input`,{"aria-label":`Local clone folder`,value:T,onChange:e=>{O(!0),E(e.target.value)},placeholder:`/path/to/resource-repositories/team-resources-ab12cd`,className:`min-w-0 flex-1 rounded-md border bg-transparent px-3 py-2 text-sm`}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>{h(`clone-parent`),e.onBrowseServerPath(VW(T))},className:`rounded-md border px-3 text-xs`,children:`Choose parent…`})]})]}),e.operations.clonePath?.status===`loading`?(0,N.jsx)(`p`,{className:`text-xs text-zinc-500`,children:`Suggesting a managed folder…`}):null,e.operations.clonePath?.status===`error`&&C.trim()===ee?(0,N.jsx)(`p`,{role:`alert`,className:`text-xs text-red-600`,children:e.operations.clonePath.message}):null,m===`clone-parent`?(0,N.jsx)(gW,{label:`Choose the clone's parent folder`,browse:e.serverBrowse,onBrowse:e.onBrowseServerPath,onSelect:t=>{E(HW(t,T)),h(null),e.onCloseServerBrowser()},onCancel:()=>{h(null),e.onCloseServerBrowser()}}):null,e.operations.preview?.status===`error`?(0,N.jsx)(`p`,{role:`alert`,className:`text-xs text-red-600`,children:e.operations.preview.message}):null,(0,N.jsxs)(`div`,{className:`flex gap-2`,children:[(0,N.jsx)(`button`,{type:`button`,onClick:()=>{p(null),h(null),e.onCloseServerBrowser()},className:`rounded-md border px-3 py-1.5 text-xs`,children:`Cancel`}),(0,N.jsx)(`button`,{type:`button`,disabled:!C.trim()||!T.trim()||e.operations.preview?.status===`loading`,onClick:()=>e.onCloneRepository(C,T),className:`rounded-md bg-zinc-900 px-3 py-1.5 text-xs text-white disabled:opacity-50`,children:e.operations.preview?.status===`loading`?`Cloning…`:`Clone and inspect`})]})]})}):le?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,N.jsxs)(`div`,{className:`min-w-0`,children:[(0,N.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,N.jsx)(`h3`,{className:`text-xl font-semibold`,children:le.name}),ue?(0,N.jsx)(`span`,{className:`rounded-full border px-2 py-0.5 text-[11px]`,children:RW[ue.assessment.status]}):null]}),(0,N.jsx)(`p`,{className:`mt-1 truncate font-mono text-xs text-zinc-500`,children:`repository`in le?le.path:le.reason}),fe?.branch?(0,N.jsxs)(`p`,{className:`mt-1 text-xs text-zinc-400`,children:[fe.branch,fe.upstream?` → ${fe.upstream}`:``]}):null,ue?.removal&&!ue.removal.allowed?(0,N.jsx)(`p`,{className:`mt-1 text-xs text-zinc-500`,children:ue.removal.reason}):null]}),ue?(0,N.jsxs)(`div`,{className:`flex gap-2`,children:[ue.removal?.allowed?(0,N.jsx)(`button`,{type:`button`,disabled:e.operations.removals?.[ue.id]?.status===`loading`,onClick:()=>ie(ue),className:`rounded-md border border-red-200 px-3 py-1.5 text-xs text-red-700 disabled:opacity-50 dark:border-red-900 dark:text-red-400`,children:`Remove repository`}):null,(0,N.jsx)(`button`,{type:`button`,disabled:e.operations.refresh?.status===`loading`,onClick:()=>e.onRefresh(ue.id),className:`rounded-md border px-3 py-1.5 text-xs`,children:`Check`}),M||de?.status===`loading`?(0,N.jsx)(`button`,{type:`button`,disabled:de?.status===`loading`,onClick:()=>ue.containsExtensions?ne(ue):he(ue),className:`rounded-md bg-zinc-900 px-3 py-1.5 text-xs text-white disabled:opacity-50`,children:de?.status===`loading`?`Updating…`:`Update repository`}):null]}):null]}),fe?.reason?(0,N.jsxs)(`div`,{className:`mt-5 rounded-lg border p-3 text-sm ${fe.status===`dirty`?`border-rose-200 bg-rose-50 text-rose-800`:`border-zinc-200 bg-zinc-50 text-zinc-700`}`,children:[fe.reason,fe.status===`dirty`?(0,N.jsx)(`p`,{className:`mt-1 text-xs`,children:`Review and resolve these local changes in an external terminal, then check again. This updater never commits, stashes, discards, rebases, or merges them.`}):null]}):null,fe?.hasSubmodules?(0,N.jsx)(`p`,{className:`mt-3 rounded border border-amber-200 bg-amber-50 p-2 text-xs text-amber-800`,children:`This repository declares submodules. Their working trees will not be initialized or updated.`}):null,de?.status===`ready`?(0,N.jsx)(`p`,{role:`status`,className:`mt-3 text-xs text-zinc-600`,children:de.result?.status===`updated`&&de.result.reloads.some(e=>e.status===`restart-required`)?`Repository updated. Its skills are reloaded; its extension code runs after pi-outpost restarts — restart it from Settings.`:de.result?.status===`updated`?`Repository updated and runtimes reloaded.`:de.result?.status===`updated-reload-failed`?`Repository updated on disk, but at least one runtime failed to reload.`:de.result?.reason}):null,de?.status===`error`?(0,N.jsx)(`p`,{role:`alert`,className:`mt-3 text-xs text-red-600`,children:de.message}):null,ge&&ue&&c!==`extension`?(0,N.jsxs)(`div`,{className:`mt-6 space-y-4`,children:[ve>0||ye?.status===`loading`?(0,N.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-lg border border-sky-200 bg-sky-50 px-3 py-2 text-xs text-sky-900 dark:border-sky-900 dark:bg-sky-950/40 dark:text-sky-200`,children:[(0,N.jsx)(`span`,{children:ye?.status===`loading`?`Applying…`:`${ve} pending change${ve===1?``:`s`} — applying replaces the session`}),(0,N.jsxs)(`div`,{className:`flex gap-2`,children:[(0,N.jsx)(`button`,{type:`button`,disabled:ye?.status===`loading`,onClick:xe,className:`rounded border bg-white px-2.5 py-1 disabled:opacity-50 dark:bg-zinc-900`,children:`Discard`}),(0,N.jsx)(`button`,{type:`button`,disabled:ye?.status===`loading`||ve===0,onClick:Se,className:`rounded bg-zinc-900 px-2.5 py-1 font-medium text-white disabled:opacity-50 dark:bg-zinc-100 dark:text-zinc-900`,children:`Apply`})]})]}):null,ye?.status===`error`?(0,N.jsx)(`p`,{role:`alert`,className:`text-xs text-red-600`,children:ye.message}):null,(0,N.jsx)(MW,{skills:ge.skills,groups:ge.groups,enabled:_e,onChange:be,disabled:ye?.status===`loading`,...ge.bound?{bound:ge.bound}:{}},ue.id),le.resources.some(e=>e.kind===`extension`)?(0,N.jsx)(UW,{kind:`extension`,resources:le.resources.filter(e=>e.kind===`extension`),removalLocked:e.extensionLock,onRemove:me}):null]}):(0,N.jsxs)(`div`,{className:`mt-6 grid grid-cols-2 gap-4`,children:[(0,N.jsx)(UW,{kind:`skill`,resources:le.resources.filter(e=>e.kind===`skill`),onRemove:me}),(0,N.jsx)(UW,{kind:`extension`,resources:le.resources.filter(e=>e.kind===`extension`),removalLocked:e.extensionLock,onRemove:me})]})]}):(0,N.jsx)(`p`,{className:`text-sm text-zinc-500`,children:`No resources are reported by this runtime.`})]})]})]}),k?(0,N.jsx)(`div`,{className:`fixed inset-0 z-[60] flex items-center justify-center bg-black/55 p-4`,children:(0,N.jsxs)(`div`,{role:`alertdialog`,"aria-modal":`true`,"aria-labelledby":`extension-update-title`,className:`w-full max-w-md rounded-xl bg-white p-5 shadow-2xl dark:bg-zinc-900`,children:[(0,N.jsx)(`h3`,{id:`extension-update-title`,className:`font-semibold`,children:`Update executable extensions?`}),(0,N.jsxs)(`p`,{className:`mt-2 text-sm text-zinc-600 dark:text-zinc-300`,children:[k.name,` contains extensions that run with the agent's privileges. Confirm updating `,k.assessment.localRevision?.slice(0,8),` to `,k.assessment.upstreamRevision?.slice(0,8),`.`]}),(0,N.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2`,children:[(0,N.jsx)(`button`,{type:`button`,onClick:()=>ne(null),className:`rounded border px-3 py-1.5 text-xs`,children:`Cancel`}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>{he(k,!0),ne(null)},className:`rounded bg-amber-600 px-3 py-1.5 text-xs font-medium text-white`,children:`Confirm executable update`})]})]})}):null,j?(0,N.jsx)(`div`,{className:`fixed inset-0 z-[60] flex items-center justify-center bg-black/55 p-4`,children:(0,N.jsxs)(`div`,{role:`alertdialog`,"aria-modal":`true`,"aria-labelledby":`remove-repository-title`,"aria-describedby":`remove-repository-detail`,className:`w-full max-w-md rounded-xl bg-white p-5 shadow-2xl dark:bg-zinc-900`,children:[(0,N.jsxs)(`h3`,{id:`remove-repository-title`,className:`font-semibold`,children:[`Remove `,j.name,`?`]}),(0,N.jsx)(`p`,{id:`remove-repository-detail`,className:`mt-2 break-words text-sm text-zinc-600 dark:text-zinc-300`,children:j.removal?.deletesFiles?(0,N.jsxs)(N.Fragment,{children:[`This stops loading everything from `,j.name,` and deletes `,(0,N.jsx)(`span`,{className:`font-mono`,children:j.removal.path}),` from disk, with any local changes in it. This cannot be undone.`]}):(0,N.jsxs)(N.Fragment,{children:[`This stops loading everything from `,j.name,`. pi-outpost does not manage `,(0,N.jsx)(`span`,{className:`font-mono`,children:j.removal?.path??j.path}),`, so its files will be kept.`]})}),(0,N.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2`,children:[(0,N.jsx)(`button`,{type:`button`,onClick:()=>ie(null),className:`rounded border px-3 py-1.5 text-xs`,children:`Cancel`}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>{e.onRemoveRepository(j.id),oe({id:j.id,name:j.name}),ie(null)},className:`rounded bg-red-600 px-3 py-1.5 text-xs font-medium text-white`,children:j.removal?.deletesFiles?`Delete and remove`:`Remove repository`})]})]})}):null]})}var KW=`w-full rounded-md border border-zinc-300 bg-white px-3 py-2 text-sm text-zinc-800 placeholder:text-zinc-400 focus:border-zinc-400 focus:outline-none dark:border-zinc-700 dark:bg-zinc-900 dark:text-zinc-100 dark:placeholder:text-zinc-600`,qW=`rounded-md border border-zinc-300 px-3 py-1.5 text-xs font-medium text-zinc-700 hover:bg-zinc-50 disabled:opacity-50 dark:border-zinc-700 dark:text-zinc-200 dark:hover:bg-zinc-800`;function JW({event:e}){switch(e.type){case`auth_url`:return(0,N.jsxs)(`div`,{"data-testid":`login-auth-url`,className:`space-y-1`,children:[(0,N.jsx)(`p`,{className:`text-sm text-zinc-700 dark:text-zinc-200`,children:e.instructions??`Open this page to sign in:`}),(0,N.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,N.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,className:`truncate text-sm text-sky-700 underline dark:text-sky-400`,children:e.url}),(0,N.jsx)(`button`,{type:`button`,className:qW,onClick:()=>void navigator.clipboard?.writeText(e.url),children:`Copy`})]})]});case`device_code`:return(0,N.jsxs)(`div`,{"data-testid":`login-device-code`,className:`space-y-1`,children:[(0,N.jsxs)(`p`,{className:`text-sm text-zinc-700 dark:text-zinc-200`,children:[`Enter this code at`,` `,(0,N.jsx)(`a`,{href:e.verificationUri,target:`_blank`,rel:`noopener noreferrer`,className:`text-sky-700 underline dark:text-sky-400`,children:e.verificationUri}),`:`]}),(0,N.jsx)(`p`,{className:`select-all font-mono text-2xl tracking-widest text-zinc-900 dark:text-zinc-50`,children:e.userCode})]});case`info`:return(0,N.jsxs)(`p`,{className:`text-sm text-zinc-700 dark:text-zinc-200`,children:[e.message,e.links?.map(e=>(0,N.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,className:`ml-2 text-sky-700 underline dark:text-sky-400`,children:e.label??e.url},e.url))]});case`progress`:return(0,N.jsx)(`p`,{className:`text-xs text-zinc-500 dark:text-zinc-400`,children:e.message})}}function YW({prompt:e,onAnswer:t}){let[n,r]=(0,v.useState)(``),i=e.type===`manual_code`&&/^http:\/\/(?:localhost|127\.0\.0\.1):1455\/auth\/callback\/?$/.test(e.placeholder??``);return e.type===`select`?(0,N.jsxs)(`div`,{"data-testid":`login-prompt`,className:`space-y-2`,children:[(0,N.jsx)(`p`,{className:`text-sm text-zinc-700 dark:text-zinc-200`,children:e.message}),(0,N.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:e.options.map(e=>(0,N.jsx)(`button`,{type:`button`,className:qW,title:e.description,onClick:()=>t(e.id),children:e.label},e.id))})]}):(0,N.jsxs)(`div`,{"data-testid":`login-prompt`,className:`space-y-2`,children:[(0,N.jsxs)(`label`,{className:`block text-sm text-zinc-700 dark:text-zinc-200`,children:[e.type===`manual_code`?`${e.message} — or the whole address the browser was sent to`:e.message,(0,N.jsx)(`input`,{className:`${KW} mt-1`,type:e.type===`secret`?`password`:`text`,name:`provider-auth-response`,placeholder:e.placeholder,autoComplete:`off`,spellCheck:e.type!==`manual_code`,autoFocus:!0,value:n,onChange:e=>r(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.stopPropagation(),n.trim()&&t(n.trim()))}})]}),i&&(0,N.jsx)(`p`,{className:`text-xs text-zinc-600 dark:text-zinc-300`,children:`If Pi Outpost runs on another computer, your browser may say it cannot connect to localhost. Copy the full address from that browser page and paste it above to finish signing in.`}),(0,N.jsx)(`button`,{type:`button`,className:qW,disabled:!n.trim(),onClick:()=>t(n.trim()),children:`Continue`})]})}function XW({login:e,providerName:t,onAnswer:n,onCancel:r,onDismiss:i}){return(0,N.jsxs)(`div`,{"data-testid":`login-flow`,className:`space-y-3 rounded-md border border-zinc-200 p-3 dark:border-zinc-700`,children:[(0,N.jsxs)(`p`,{className:`text-xs font-semibold uppercase tracking-wider text-zinc-500 dark:text-zinc-400`,children:[`Signing in to `,t]}),(0,N.jsxs)(`div`,{"aria-live":`polite`,"aria-atomic":`false`,children:[e.events.map((e,t)=>(0,N.jsx)(JW,{event:e},t)),e.prompt&&(0,N.jsx)(YW,{prompt:e.prompt.prompt,onAnswer:n},e.prompt.promptId),!e.done&&!e.prompt&&e.events.length===0&&(0,N.jsx)(`p`,{className:`text-xs text-zinc-500 dark:text-zinc-400`,children:`Starting…`}),e.done?(0,N.jsxs)(`div`,{"data-testid":`login-done`,"data-ok":e.done.ok?`true`:`false`,className:`space-y-2`,children:[(0,N.jsx)(`p`,{className:`text-sm ${e.done.ok?`text-emerald-700 dark:text-emerald-400`:`text-red-700 dark:text-red-400`}`,children:e.done.ok?`Signed in to ${t}.`:e.done.cancelled?`Sign-in cancelled.`:`Sign-in failed: ${e.done.message??`unknown error`}`}),(0,N.jsx)(`button`,{type:`button`,className:qW,onClick:i,children:`Close`})]}):(0,N.jsx)(`button`,{type:`button`,className:qW,onClick:r,children:`Cancel`})]})]})}function ZW(e){return[...e].sort((e,t)=>e.localeCompare(t))}function QW(e,t){return e===`models_json_key`?`This key is managed in models.json. Remove it from that provider configuration.`:e===`environment`?`This key comes from ${t??`the server environment`}. Remove it from there.`:`This key is managed by ${t??e??`the provider runtime`}. Remove it from that source.`}function $W(e,t){return e===`models_json_key`?`models.json`:t??e}function eG({credentials:e,login:t,onStartLogin:n,onAnswerLogin:r,onCancelLogin:i,onDismissLogin:a,onLogoutProvider:o,extensionPaths:s,configuredExtensionPaths:c,userExtensionPaths:l,extensionLock:u,piPackages:d=null,piPackageUpdate:f=null,canRestartServer:p=!1,serverRestarting:m=!1,onCheckPiPackages:h,onUpdatePiPackage:g,onRestartServer:_,onRestartSession:y,restartNeeded:b=[],tools:x,commands:S,sandbox:C,showRoots:w=!0,gitUnavailable:T,userSkillPaths:E,serverBrowse:D,pickerBlocked:O=!1,onPickerOpened:ee,applyState:te,agentResources:k=null,agentResourceOperations:ne={clonePath:null,preview:null,enrollment:null,refresh:null,updates:{},skills:{},removals:{}},versions:A,onBrowseServerPath:re,onCloseServerBrowser:j,onUpdateConfig:ie,onSuggestAgentResourceClonePath:ae=()=>{},onCloneAgentResourceRepository:oe=()=>{},onEnrollAgentResourceRepository:se=()=>{},onSetAgentResourceSkills:ce=()=>{},onRemoveAgentResourceRepository:le=()=>{},onRefreshAgentResourceRepositories:ue=()=>{},onUpdateAgentResourceRepository:de=()=>{}}){let[fe,M]=(0,v.useState)(!1),[pe,me]=(0,v.useState)(!1),he=(0,v.useRef)(new Map),[ge,P]=(0,v.useState)(!1),_e=(0,v.useRef)(null),[ve,ye]=(0,v.useState)(``),[be,xe]=(0,v.useState)(``),[Se,Ce]=(0,v.useState)(!1),[we,Te]=(0,v.useState)(!1),[Ee,De]=(0,v.useState)(null),Oe=(e,r)=>{if(t&&!t.done){i?.(),a?.();let e=he.current.get(t.provider);e&&(e.open=!1)}else n?.(e,r)};(0,v.useEffect)(()=>{O&&Ee!==null&&De(null)},[O,Ee]);let ke=aH(()=>{(fe||Ee!==null)&&Le()}),Ae=x.filter(e=>e.active),je=x.filter(e=>!e.active),Me=S.filter(e=>e.source===`skill`),Ne=[...x].sort((e,t)=>e.name.localeCompare(t.name)||Number(t.active)-Number(e.active)),Pe=te?.status===`applying`,Fe=te?.status===`error`?te.message:null;(0,v.useEffect)(()=>{C&&(ye(C.root),xe(C.writableRoot??``),Ce(C.allowWrite),Te(C.allowBash))},[C]);let Ie=(0,v.useRef)(!1);(0,v.useEffect)(()=>{Ie.current&&te===null&&Le(),Ie.current=Pe},[te,Pe]);function Le(){me(!1),M(!1),De(null),j()}function Re(e,t){ee?.(),De(e),re(t.trim()||`/`)}function ze(e){Ee===`root`?ye(e):Ee===`writableRoot`&&xe(e),De(null),j()}let Be=C!==null&&(ve!==C.root||(be.trim()||void 0)!==(C.writableRoot||void 0)||Se!==C.allowWrite||we!==C.allowBash);function Ve(){C&&Be&&ie({sandbox:{root:ve,allowWrite:Se,allowBash:we,writableRoot:be.trim()||void 0}})}let He=w&&C?.rootEditable!==!1,Ue=Ee!==null&&!O&&(0,N.jsx)(gW,{label:Ee===`root`?`Choose the sandbox root`:`Choose the writable root`,browse:D,onBrowse:re,onSelect:ze,onCancel:()=>{De(null),j()}});return(0,N.jsxs)(`div`,{className:`relative`,ref:ke,children:[(0,N.jsx)(`button`,{ref:_e,type:`button`,onClick:()=>{me(!1),fe?Le():M(!0)},title:`Settings`,"aria-label":`Settings`,className:`${cW} border-zinc-300 text-zinc-500 hover:border-zinc-400 hover:text-zinc-700 dark:border-zinc-800 dark:text-zinc-400 dark:hover:border-zinc-600 dark:hover:text-zinc-200`,children:`⚙`}),fe&&(0,N.jsxs)(`div`,{className:`absolute right-0 top-full z-20 mt-1 flex max-h-[80vh] w-[380px] flex-col rounded-lg border border-zinc-200 bg-white shadow-xl dark:border-zinc-700 dark:bg-zinc-900`,children:[(0,N.jsxs)(`div`,{className:`border-b border-zinc-200 px-4 py-3 dark:border-zinc-800`,children:[pe&&(0,N.jsx)(`button`,{type:`button`,onClick:()=>me(!1),className:`mb-2 text-xs text-zinc-600 hover:underline dark:text-zinc-400`,children:`← Back to settings`}),(0,N.jsx)(`h2`,{className:`text-sm font-semibold text-zinc-800 dark:text-zinc-200`,children:pe?`Credits`:`Settings`})]}),(0,N.jsx)(`div`,{className:`min-h-0 overflow-y-auto p-4`,children:pe?(0,N.jsx)(EW,{}):(0,N.jsxs)(N.Fragment,{children:[T&&(0,N.jsxs)(`section`,{className:`mb-4`,"data-testid":`git-unavailable`,children:[(0,N.jsx)(`h3`,{className:`mb-2 text-xs font-semibold uppercase tracking-wider text-zinc-500 dark:text-zinc-400`,children:`Version control`}),T.reason===`no-repository`?(0,N.jsx)(`p`,{className:`text-xs text-zinc-500 dark:text-zinc-400`,children:`This project is not in a git repository.`}):(0,N.jsxs)(`div`,{className:`rounded border border-amber-300 bg-amber-50 px-2 py-1.5 dark:border-amber-900 dark:bg-amber-950/40`,children:[(0,N.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-300`,children:T.reason===`no-executable`?`Git is unavailable: its executable could not be run.`:`Git is unavailable: it refused this repository.`}),(0,N.jsx)(`p`,{className:`mt-1 break-all font-mono text-[11px] text-amber-700 dark:text-amber-400`,children:T.message}),T.reason===`no-executable`&&(0,N.jsxs)(`p`,{className:`mt-1 text-xs text-amber-700 dark:text-amber-400`,children:[`Install git, add it to PATH, or name it with `,(0,N.jsx)(`span`,{className:`font-mono`,children:`gitPath`}),` in the configuration.`]})]})]}),e&&(0,N.jsxs)(`details`,{className:`mb-4`,"data-testid":`accounts-panel`,children:[(0,N.jsxs)(`summary`,{className:`cursor-pointer text-xs font-semibold uppercase tracking-wider text-zinc-500 dark:text-zinc-400`,children:[`Accounts · `,(0,N.jsxs)(`span`,{className:`text-emerald-700 dark:text-emerald-400`,children:[e.providers.filter(e=>e.configured).length,` providers configured`]})]}),(0,N.jsxs)(`div`,{className:`mt-2`,children:[(0,N.jsx)(`ul`,{className:`space-y-2`,children:e.providers.map(n=>(0,N.jsx)(`li`,{className:`rounded border border-zinc-200 p-2 dark:border-zinc-700`,children:(0,N.jsxs)(`details`,{ref:e=>{e?he.current.set(n.id,e):he.current.delete(n.id)},"data-testid":`account-${n.id}`,children:[(0,N.jsxs)(`summary`,{className:`cursor-pointer`,children:[(0,N.jsx)(`span`,{className:`text-xs font-medium text-zinc-800 dark:text-zinc-200`,children:n.name}),(0,N.jsx)(`span`,{className:`ml-2 text-[11px] ${n.configured?`text-emerald-700 dark:text-emerald-400`:`text-zinc-500 dark:text-zinc-400`}`,children:n.configured?`${n.auth??`Authenticated`}${n.source?` · ${$W(n.source,n.label)}`:``}`:`Not signed in`})]}),(0,N.jsxs)(`div`,{className:`mt-2`,children:[n.configured&&n.auth===`api_key`&&n.source!==`stored`&&(0,N.jsx)(`p`,{className:`mb-2 text-[11px] text-zinc-500 dark:text-zinc-400`,children:QW(n.source,n.label)}),!e.locked&&(0,N.jsxs)(`div`,{className:`flex flex-wrap gap-1`,children:[n.methods?.includes(`oauth`)&&(0,N.jsx)(`button`,{type:`button`,className:`rounded border px-2 py-1 text-[11px]`,onClick:()=>Oe(n.id,`oauth`),children:`Sign in`}),n.methods?.includes(`api_key`)&&(0,N.jsx)(`button`,{type:`button`,className:`rounded border px-2 py-1 text-[11px]`,onClick:()=>Oe(n.id,`api_key`),children:`API key`}),n.configured&&n.source===`stored`&&(0,N.jsx)(`button`,{type:`button`,className:`rounded border px-2 py-1 text-[11px]`,onClick:()=>o?.(n.id),children:n.auth===`api_key`?`Remove API key`:`Sign out`})]}),t?.provider===n.id&&(0,N.jsx)(`div`,{className:`mt-2`,children:(0,N.jsx)(XW,{login:t,providerName:n.name,onAnswer:e=>r?.(e),onCancel:()=>i?.(),onDismiss:()=>a?.()})})]})]})},n.id))}),e.locked&&(0,N.jsx)(`p`,{className:`mt-2 text-xs text-zinc-500 dark:text-zinc-400`,children:`Credentials are locked by this server.`})]})]}),(0,N.jsxs)(`section`,{className:`mb-4`,children:[(0,N.jsx)(`h3`,{className:`mb-2 text-xs font-semibold uppercase tracking-wider text-zinc-500 dark:text-zinc-400`,children:`Agent resources`}),x.length===0?(0,N.jsx)(`p`,{className:`text-xs text-zinc-400 dark:text-zinc-500`,children:`Tool inventory unavailable for this runtime`}):(0,N.jsxs)(`details`,{"data-testid":`tools-loaded`,children:[(0,N.jsxs)(`summary`,{className:`cursor-pointer text-xs text-zinc-600 dark:text-zinc-400`,children:[Ae.length,` tools active`,je.length?` · ${je.length} inactive`:``]}),(0,N.jsx)(`ul`,{className:`mt-2 space-y-1`,children:Ne.map(e=>(0,N.jsxs)(`li`,{className:`flex justify-between rounded bg-zinc-50 px-2 py-1 font-mono text-xs text-zinc-600 dark:bg-zinc-800 dark:text-zinc-400`,children:[(0,N.jsx)(`span`,{children:e.name}),(0,N.jsx)(`span`,{children:e.active?`active`:`inactive`})]},e.name))})]}),Me.length===0?(0,N.jsx)(`p`,{className:`mt-2 text-xs text-zinc-400 dark:text-zinc-500`,children:`No skills loaded`}):(0,N.jsxs)(`details`,{className:`mt-2`,"data-testid":`skills-loaded`,children:[(0,N.jsxs)(`summary`,{className:`cursor-pointer text-xs text-zinc-600 dark:text-zinc-400`,children:[Me.length,` skills loaded`]}),(0,N.jsx)(`ul`,{className:`mt-2 space-y-1`,children:ZW(Me.map(e=>e.name)).map(e=>(0,N.jsx)(`li`,{className:`rounded bg-zinc-50 px-2 py-1 font-mono text-xs text-zinc-600 dark:bg-zinc-800 dark:text-zinc-400`,children:e},e))})]}),(0,N.jsx)(`button`,{type:`button`,"aria-label":`Manage agent resources`,onClick:()=>{M(!1),P(!0)},className:`mt-3 w-full rounded-md border border-zinc-300 px-3 py-2 text-xs font-medium text-zinc-700 hover:bg-zinc-50 dark:border-zinc-700 dark:text-zinc-200 dark:hover:bg-zinc-800`,children:`Manage resources…`})]}),(0,N.jsxs)(`section`,{className:`mb-4`,children:[(0,N.jsx)(`h3`,{className:`mb-2 text-xs font-semibold uppercase tracking-wider text-zinc-500 dark:text-zinc-400`,children:`Extensions`}),s===null?(0,N.jsx)(`p`,{className:`text-xs text-zinc-400 dark:text-zinc-500`,"data-testid":`extensions-unknown`,children:`Not reported by this runtime`}):s.length===0?(0,N.jsx)(`p`,{className:`text-xs text-zinc-400 dark:text-zinc-500`,children:`No extensions loaded`}):(0,N.jsxs)(`details`,{"data-testid":`extensions-loaded`,children:[(0,N.jsxs)(`summary`,{className:`cursor-pointer text-xs text-zinc-600 dark:text-zinc-400`,children:[s.length,` `,s.length===1?`extension`:`extensions`,` loaded`]}),(0,N.jsx)(`ul`,{className:`mt-2 space-y-1`,children:ZW(s).map(e=>(0,N.jsx)(`li`,{className:`truncate rounded bg-zinc-50 px-2 py-1 font-mono text-xs text-zinc-600 dark:bg-zinc-800 dark:text-zinc-400`,title:e,children:e},e))})]}),c.length>0&&(0,N.jsxs)(`details`,{className:`mt-2`,"data-testid":`extensions-configured`,children:[(0,N.jsxs)(`summary`,{className:`cursor-pointer text-xs text-zinc-600 dark:text-zinc-400`,children:[c.length,` configured by this deployment`]}),(0,N.jsx)(`p`,{className:`mt-1 text-xs text-zinc-400 dark:text-zinc-500`,children:`Declared in the configuration file. They load either way, and nothing here can remove them.`}),(0,N.jsx)(`ul`,{className:`mt-1 space-y-1`,children:ZW(c).map(e=>(0,N.jsx)(`li`,{className:`truncate rounded bg-zinc-50 px-2 py-1 font-mono text-xs text-zinc-600 dark:bg-zinc-800 dark:text-zinc-400`,title:e,children:e},e))})]}),u?(0,N.jsx)(`p`,{className:`mt-2 text-xs text-zinc-400 dark:text-zinc-500`,"data-testid":`extensions-locked`,children:`Extension paths and repository updates that contain extensions are locked by this deployment.`}):null,(0,N.jsx)(OW,{packages:d,update:f,locked:u,onCheck:()=>h?.(),onUpdate:e=>g?.(e)}),(0,N.jsx)(kW,{reasons:b,canRestart:p,restarting:m,onRestart:()=>_?.()})]}),C&&(0,N.jsxs)(`section`,{children:[(0,N.jsx)(`h3`,{className:`mb-2 text-xs font-semibold uppercase tracking-wider text-zinc-500 dark:text-zinc-400`,children:He?`Sandbox`:`Agent permissions`}),(0,N.jsxs)(`div`,{className:`space-y-3`,children:[!He&&(0,N.jsxs)(`p`,{"data-testid":`sandbox-project-root`,className:`text-xs text-zinc-600 dark:text-zinc-400`,children:[`This project is confined to its own folder,`,` `,(0,N.jsx)(`span`,{className:`break-all font-mono text-zinc-800 dark:text-zinc-200`,children:C.projectRoot??C.root}),`. Each open project is confined to its own. A change here applies to this project now, and to projects opened after.`]}),He&&(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`label`,{className:`block`,children:[(0,N.jsxs)(`span`,{className:`text-xs text-zinc-600 dark:text-zinc-400`,children:[`Root `,C.locks?.root?(0,N.jsx)(`span`,{className:`text-zinc-400`,children:`(locked)`}):null]}),(0,N.jsxs)(`div`,{className:`mt-1 flex gap-2`,children:[(0,N.jsx)(`input`,{type:`text`,value:ve,onChange:e=>ye(e.target.value),disabled:C.locks?.root,className:`w-full rounded-md border border-zinc-300 bg-transparent px-2 py-1 text-sm outline-none focus:border-zinc-500 disabled:cursor-not-allowed disabled:opacity-50 dark:border-zinc-700 dark:focus:border-zinc-500`}),(0,N.jsx)(`button`,{type:`button`,"aria-label":`Browse for sandbox root`,disabled:C.locks?.root,onClick:()=>Re(`root`,ve),className:`shrink-0 rounded-md border border-zinc-300 px-2 py-1 text-xs text-zinc-600 hover:border-zinc-400 disabled:cursor-not-allowed disabled:opacity-50 dark:border-zinc-700 dark:text-zinc-300`,children:`Browse…`})]})]}),Ee===`root`&&Ue,(0,N.jsxs)(`label`,{className:`block`,children:[(0,N.jsxs)(`span`,{className:`text-xs text-zinc-600 dark:text-zinc-400`,children:[`Writable root (optional) `,C.locks?.writableRoot?(0,N.jsx)(`span`,{className:`text-zinc-400`,children:`(locked)`}):null]}),(0,N.jsxs)(`div`,{className:`mt-1 flex gap-2`,children:[(0,N.jsx)(`input`,{type:`text`,value:be,onChange:e=>xe(e.target.value),disabled:C.locks?.writableRoot,placeholder:`Same as root`,className:`w-full rounded-md border border-zinc-300 bg-transparent px-2 py-1 text-sm outline-none placeholder:text-zinc-400 focus:border-zinc-500 disabled:cursor-not-allowed disabled:opacity-50 dark:border-zinc-700 dark:placeholder:text-zinc-600 dark:focus:border-zinc-500`}),(0,N.jsx)(`button`,{type:`button`,"aria-label":`Browse for writable root`,disabled:C.locks?.writableRoot,onClick:()=>Re(`writableRoot`,be||ve),className:`shrink-0 rounded-md border border-zinc-300 px-2 py-1 text-xs text-zinc-600 hover:border-zinc-400 disabled:cursor-not-allowed disabled:opacity-50 dark:border-zinc-700 dark:text-zinc-300`,children:`Browse…`})]})]}),Ee===`writableRoot`&&Ue]}),(0,N.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,N.jsx)(`input`,{type:`checkbox`,checked:Se,onChange:e=>Ce(e.target.checked),disabled:C.locks?.allowWrite,className:`rounded border-zinc-300 text-zinc-700 focus:ring-zinc-500 disabled:cursor-not-allowed disabled:opacity-50 dark:border-zinc-700 dark:bg-zinc-800 dark:text-zinc-300`}),(0,N.jsxs)(`span`,{className:`text-xs text-zinc-600 dark:text-zinc-400`,children:[`Allow write `,C.locks?.allowWrite?(0,N.jsx)(`span`,{className:`text-zinc-400`,children:`(locked)`}):null]})]}),(0,N.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,N.jsx)(`input`,{type:`checkbox`,checked:we,onChange:e=>Te(e.target.checked),disabled:C.locks?.allowBash,className:`rounded border-zinc-300 text-zinc-700 focus:ring-zinc-500 disabled:cursor-not-allowed disabled:opacity-50 dark:border-zinc-700 dark:bg-zinc-800 dark:text-zinc-300`}),(0,N.jsxs)(`span`,{className:`text-xs text-zinc-600 dark:text-zinc-400`,children:[`Allow bash `,C.locks?.allowBash?(0,N.jsx)(`span`,{className:`text-zinc-400`,children:`(locked)`}):null]})]})]})]}),!C&&(0,N.jsx)(`p`,{className:`text-xs text-zinc-400 dark:text-zinc-500`,children:`No sandbox configured`}),(0,N.jsxs)(`div`,{className:`mt-4 space-y-2`,children:[Fe&&(0,N.jsx)(`p`,{role:`alert`,className:`rounded-md border border-red-300 bg-red-50 px-2 py-1 text-xs text-red-700 dark:border-red-900/60 dark:bg-red-950/30 dark:text-red-300`,children:Fe}),(0,N.jsx)(`button`,{type:`button`,disabled:Pe||Be&&!ve.trim(),onClick:Be?Ve:y,className:`w-full rounded-md bg-zinc-800 px-3 py-1.5 text-xs font-medium text-white hover:bg-zinc-700 disabled:cursor-not-allowed disabled:opacity-50 dark:bg-zinc-200 dark:text-zinc-900 dark:hover:bg-zinc-300`,children:Pe?`Restarting…`:Be?`Apply & restart session`:`Restart session`}),(0,N.jsx)(`p`,{className:`text-[11px] text-zinc-400 dark:text-zinc-500`,children:Be?`Saved to the server's configuration file, then the session is rebuilt — the change survives a restart.`:`Start a fresh session to reload extensions and MCP connections. Settings are kept.`})]}),A&&(0,N.jsxs)(`section`,{className:`mt-4`,children:[(0,N.jsx)(`h3`,{className:`mb-2 text-xs font-semibold uppercase tracking-wider text-zinc-500 dark:text-zinc-400`,children:`Versions`}),(0,N.jsxs)(`div`,{className:`space-y-1 text-xs text-zinc-600 dark:text-zinc-400`,children:[(0,N.jsxs)(`p`,{children:[`pi-outpost: `,(0,N.jsx)(`span`,{className:`font-mono text-zinc-800 dark:text-zinc-200`,children:A.piOutpost})]}),A.piSdk&&(0,N.jsxs)(`p`,{children:[`pi SDK: `,(0,N.jsx)(`span`,{className:`font-mono text-zinc-800 dark:text-zinc-200`,children:A.piSdk})]}),A.agent&&(0,N.jsxs)(`p`,{children:[`agent: `,(0,N.jsx)(`span`,{className:`font-mono text-zinc-800 dark:text-zinc-200`,children:A.agent})]})]})]}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>me(!0),className:`mt-4 w-full border-t border-zinc-200 pt-3 text-left text-sm text-zinc-600 hover:text-zinc-900 dark:border-zinc-700 dark:text-zinc-400 dark:hover:text-zinc-100`,children:`Credits →`})]})})]}),(0,N.jsx)(GW,{open:ge,inventory:k,operations:ne,extensionLock:u,userSkillPaths:E,userExtensionPaths:l,serverBrowse:D,applyState:te,onClose:()=>{P(!1),j(),_e.current?.focus()},onBrowseServerPath:e=>{ee?.(),re(e)},onCloseServerBrowser:j,onUpdateConfig:ie,onSuggestClonePath:ae,onCloneRepository:oe,onEnrollRepository:se,onSetSkills:ce,onRemoveRepository:le,onRefresh:ue,onUpdate:de})]})}function tG(e){let t=[],n=new Set,r=0,i=0;function a(e,o,s,c){let l=e.children,u=l.slice(1).map(e=>[e,r++]);u.length>0&&i++;let d=e.onPath&&!l.some(e=>e.onPath);if(t.push({node:e,lane:o,through:[...n].filter(e=>e!==o),forkTo:u.map(([,e])=>e),lineAbove:s,lineBelow:l.length>0,branchIndex:c,isCurrent:d,emphasis:d?`current`:e.onPath?`filled`:`hollow`,highlight:e.onPath}),l.length===0)n.delete(o);else{for(let[,e]of u)n.add(e);a(l[0],o,!0,u.length>0?1:void 0),u.forEach(([e,t],n)=>a(e,t,!0,n+2))}}return e.length>1&&i++,e.forEach((t,i)=>{let o=r++;n.add(o),a(t,o,!1,e.length>1?i+1:void 0)}),{rows:t,laneCount:r,branchPoints:i}}function nG(e){return e.flatMap(e=>[e,...nG(e.children)])}function rG({children:e,tone:t}){let n={current:`border-emerald-300 bg-emerald-50 text-emerald-700 dark:border-emerald-800 dark:bg-emerald-950/50 dark:text-emerald-300`,branch:`border-zinc-300 text-zinc-500 dark:border-zinc-700 dark:text-zinc-400`,label:`border-violet-300 bg-violet-50 text-violet-700 dark:border-violet-900 dark:bg-violet-950/50 dark:text-violet-300`}[t];return(0,N.jsx)(`span`,{className:`shrink-0 rounded-full border px-1.5 py-px text-[10px] leading-4 ${n}`,children:e})}var iG=`shrink-0 rounded px-1.5 py-0.5 text-xs text-zinc-400 opacity-0 hover:bg-zinc-200 hover:text-zinc-700 focus-visible:opacity-100 group-hover:opacity-100 dark:text-zinc-500 dark:hover:bg-zinc-700 dark:hover:text-zinc-200`;function aG({row:e,laneCount:t,isStreaming:n,onNavigate:r,onFork:i,onClose:a}){let{node:o}=e,s=o.tipId??o.entryId;return(0,N.jsxs)(`div`,{className:`group flex items-center gap-1 pr-2 hover:bg-zinc-100 dark:hover:bg-zinc-800/70 ${e.isCurrent?`bg-emerald-50/60 dark:bg-emerald-950/20`:``}`,style:{height:36},children:[(0,N.jsxs)(`button`,{type:`button`,disabled:n,onClick:()=>{r(s),a()},title:n?`unavailable while the agent is running`:o.tipId?`restore the conversation at this point (reply included)`:`go back to this point`,className:`flex h-full min-w-0 flex-1 items-center gap-2 pl-2 text-left text-sm disabled:opacity-50`,children:[(0,N.jsx)(qU,{row:e,laneCount:t,colorOf:WU}),(0,N.jsx)(`span`,{className:`min-w-0 truncate ${o.onPath?`text-zinc-800 dark:text-zinc-200`:`text-zinc-600 dark:text-zinc-400`}`,children:o.text||`(empty)`}),e.forkTo.length>0&&(0,N.jsxs)(rG,{tone:`branch`,children:[e.forkTo.length+1,` branches`]}),e.branchIndex!==void 0&&(0,N.jsxs)(rG,{tone:`branch`,children:[`branch `,e.branchIndex,o.onPath&&!e.isCurrent?` · current`:``]}),e.isCurrent&&(0,N.jsx)(rG,{tone:`current`,children:`current`}),o.label&&(0,N.jsx)(rG,{tone:`label`,children:o.label})]}),(0,N.jsx)(`button`,{type:`button`,disabled:n,onClick:()=>{r(o.entryId),a()},title:`rewind to just before this message (its text comes back in the composer)`,"aria-label":`Rewind to before this message`,className:iG,children:`↺ redo`}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>{i(o.entryId),a()},title:`fork a new session from this point`,className:iG,children:`⑂ fork`})]})}function oG({tree:e,isStreaming:t,onListTree:n,onNavigate:r,onFork:i}){let[a,o]=(0,v.useState)(!1),[s,c]=(0,v.useState)(``),l=aH(()=>o(!1));(0,v.useEffect)(()=>{a&&e===null&&n()},[a,e]);let u=(0,v.useMemo)(()=>e&&e.length>0?tG(e):null,[e]),d=(0,v.useMemo)(()=>{if(!e||!s.trim())return null;let t=s.trim().toLowerCase();return nG(e).filter(e=>e.text.toLowerCase().includes(t)||e.label?.toLowerCase().includes(t))},[e,s]);return(0,N.jsxs)(`div`,{className:`relative`,ref:l,children:[(0,N.jsx)(`button`,{type:`button`,onClick:()=>{o(!a),a||(c(``),n())},title:`conversation tree: go back to an earlier point or fork`,className:`${cW} border-zinc-300 text-zinc-500 hover:border-zinc-400 hover:text-zinc-700 dark:border-zinc-800 dark:text-zinc-400 dark:hover:border-zinc-600 dark:hover:text-zinc-200`,children:`tree`}),a&&(0,N.jsxs)(`div`,{className:`absolute right-0 top-full z-20 mt-1 flex max-h-[70vh] w-[32rem] max-w-[90vw] flex-col rounded-lg border border-zinc-200 bg-white shadow-xl [--tree-off:#e4e4e7] dark:border-zinc-700 dark:bg-zinc-900 dark:[--tree-off:#3f3f46]`,children:[e===null&&(0,N.jsx)(`div`,{className:`px-3 py-2 text-xs text-zinc-500`,children:`loading…`}),e?.length===0&&(0,N.jsx)(`div`,{className:`px-3 py-2 text-xs text-zinc-500`,children:`no messages yet`}),e&&e.length>0&&u&&(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`div`,{className:`border-b border-zinc-200 px-3 py-2 dark:border-zinc-800`,children:[(0,N.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,N.jsx)(`span`,{className:`text-sm font-semibold text-zinc-800 dark:text-zinc-200`,children:`Conversation tree`}),(0,N.jsxs)(`span`,{className:`text-xs text-zinc-400 dark:text-zinc-500`,children:[u.rows.length,` turn`,u.rows.length===1?``:`s`,` · `,u.branchPoints,` branch point`,u.branchPoints===1?``:`s`]})]}),(0,N.jsx)(`input`,{type:`search`,value:s,onChange:e=>c(e.target.value),placeholder:`Search tree`,"aria-label":`Search conversation tree`,className:`mt-2 w-full rounded-md border border-zinc-300 bg-transparent px-2 py-1 text-sm outline-none placeholder:text-zinc-400 focus:border-zinc-500 dark:border-zinc-700 dark:placeholder:text-zinc-600 dark:focus:border-zinc-500`}),(0,N.jsx)(`p`,{className:`mt-1.5 text-[11px] text-zinc-400 dark:text-zinc-500`,children:`Follow the colored lines — the current branch is highlighted. Click a turn to restore the conversation there · ↺ to send it again · ⑂ to fork a session`})]}),(0,N.jsx)(`div`,{className:`min-h-0 overflow-y-auto py-1`,children:d===null?u.rows.map(e=>(0,N.jsx)(aG,{row:e,laneCount:u.laneCount,isStreaming:t,onNavigate:r,onFork:i,onClose:()=>o(!1)},e.node.entryId)):d.length===0?(0,N.jsx)(`div`,{className:`px-3 py-2 text-xs text-zinc-500`,children:`no matches`}):d.map(e=>(0,N.jsxs)(`div`,{className:`group flex items-center gap-1 pr-2 hover:bg-zinc-100 dark:hover:bg-zinc-800/70`,children:[(0,N.jsxs)(`button`,{type:`button`,disabled:t,onClick:()=>{r(e.tipId??e.entryId),o(!1)},title:e.tipId?`restore the conversation at this point (reply included)`:`go back to this point`,className:`flex min-w-0 flex-1 items-center gap-2 px-3 py-1.5 text-left text-sm disabled:opacity-50`,children:[(0,N.jsx)(`span`,{"aria-hidden":!0,className:e.onPath?`text-emerald-500`:`text-zinc-300 dark:text-zinc-600`,children:`●`}),(0,N.jsx)(`span`,{className:`min-w-0 truncate text-zinc-700 dark:text-zinc-300`,children:e.text||`(empty)`}),e.onPath&&(0,N.jsx)(rG,{tone:`current`,children:`on current branch`}),e.label&&(0,N.jsx)(rG,{tone:`label`,children:e.label})]}),(0,N.jsx)(`button`,{type:`button`,disabled:t,onClick:()=>{r(e.entryId),o(!1)},title:`rewind to just before this message (its text comes back in the composer)`,"aria-label":`Rewind to before this message`,className:iG,children:`↺ redo`}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>{i(e.entryId),o(!1)},title:`fork a new session from this point`,className:iG,children:`⑂ fork`})]},e.entryId))})]})]})]})}var sG=200;function cG({initial:e,onCommit:t,onCancel:n}){let[r,i]=(0,v.useState)(e);return(0,N.jsx)(`input`,{autoFocus:!0,value:r,onChange:e=>i(e.target.value),onBlur:n,onKeyDown:e=>{e.key===`Enter`?t(r):e.key===`Escape`&&n()},placeholder:`Session name (empty to clear)`,"aria-label":`Session name`,className:`w-full rounded-md border border-zinc-400 bg-transparent px-2 py-1 text-sm outline-none placeholder:text-zinc-400 dark:border-zinc-600 dark:placeholder:text-zinc-600`})}function lG({session:e,isCurrent:t,renaming:n,onSwitch:r,onDelete:i,onStartRename:a,onRename:o,onCancelRename:s}){return n?(0,N.jsx)(`div`,{className:`px-3 py-2`,children:(0,N.jsx)(cG,{initial:e.name??``,onCommit:o,onCancel:s})}):(0,N.jsxs)(`div`,{className:`group flex items-start gap-1 hover:bg-zinc-100 dark:hover:bg-zinc-800 ${t?`bg-zinc-100 dark:bg-zinc-800/60`:``}`,children:[(0,N.jsxs)(`button`,{type:`button`,onClick:r,className:`min-w-0 flex-1 px-3 py-2 text-left text-sm`,children:[(0,N.jsx)(`div`,{className:`truncate text-zinc-700 dark:text-zinc-300`,children:e.name||e.firstMessage||`(empty)`}),e.snippet&&(0,N.jsx)(`div`,{className:`mt-0.5 truncate text-xs text-zinc-500 dark:text-zinc-500`,children:e.snippet}),(0,N.jsxs)(`div`,{className:`mt-0.5 text-xs text-zinc-400 dark:text-zinc-600`,children:[new Date(e.modified).toLocaleString(),` · `,e.messageCount,` messages`,t?` · current`:``,!t&&e.liveIn?(0,N.jsxs)(`span`,{"data-testid":`session-live-in`,children:[` · open in `,e.liveIn]}):null]})]}),(0,N.jsx)(`button`,{type:`button`,onClick:a,title:`rename session`,"aria-label":`Rename session`,className:`mt-2 rounded px-1.5 py-0.5 text-xs text-zinc-400 opacity-0 hover:bg-zinc-200 hover:text-zinc-700 focus-visible:opacity-100 group-hover:opacity-100 dark:text-zinc-600 dark:hover:bg-zinc-700 dark:hover:text-zinc-200`,children:`✎`}),!t&&!e.liveIn&&(0,N.jsx)(`button`,{type:`button`,onClick:i,title:`delete session`,"aria-label":`Delete session`,className:`mr-2 mt-2 rounded px-1.5 py-0.5 text-xs text-zinc-400 opacity-0 hover:bg-red-100 hover:text-red-600 focus-visible:opacity-100 group-hover:opacity-100 dark:text-zinc-600 dark:hover:bg-red-950/60 dark:hover:text-red-400`,children:`✕`})]})}function uG({sessions:e,sessionSearch:t,sessionId:n,onSwitchSession:r,onDeleteSession:i,onListSessions:a,onRenameSession:o,onSearchSessions:s,onClearSessionSearch:c}){let[l,u]=(0,v.useState)(!1),[d,f]=(0,v.useState)(``),[p,m]=(0,v.useState)(null),h=aH(()=>u(!1)),g=d.trim(),_=g.length>=2;(0,v.useEffect)(()=>{if(!l)return;if(!_){c();return}let e=setTimeout(()=>s(g),sG);return()=>clearTimeout(e)},[l,g,_]);function y(){u(!1),m(null)}let b=_&&(t?.status!==`loaded`||t.query!==g),x=_?b?null:t?.results??null:e;return(0,N.jsxs)(`div`,{className:`relative`,ref:h,children:[(0,N.jsx)(`button`,{type:`button`,onClick:()=>{l?y():(u(!0),f(``),m(null),c(),a())},className:`${cW} border-zinc-300 text-zinc-500 hover:border-zinc-400 hover:text-zinc-700 dark:border-zinc-800 dark:text-zinc-400 dark:hover:border-zinc-600 dark:hover:text-zinc-200`,children:`sessions`}),l&&(0,N.jsxs)(`div`,{className:`absolute right-0 top-full z-20 mt-1 flex max-h-96 w-96 flex-col rounded-lg border border-zinc-200 bg-white shadow-xl dark:border-zinc-700 dark:bg-zinc-900`,children:[(0,N.jsxs)(`div`,{className:`border-b border-zinc-200 px-3 py-2 dark:border-zinc-800`,children:[(0,N.jsx)(`input`,{type:`search`,value:d,onChange:e=>f(e.target.value),placeholder:`Search sessions`,"aria-label":`Search sessions`,className:`w-full rounded-md border border-zinc-300 bg-transparent px-2 py-1 text-sm outline-none placeholder:text-zinc-400 focus:border-zinc-500 dark:border-zinc-700 dark:placeholder:text-zinc-600 dark:focus:border-zinc-500`}),(0,N.jsx)(`p`,{className:`mt-1.5 text-[11px] text-zinc-400 dark:text-zinc-500`,children:`Searches names and everything said in a session · ✎ to rename`})]}),(0,N.jsxs)(`div`,{className:`min-h-0 overflow-y-auto`,children:[x===null&&(0,N.jsx)(`div`,{className:`px-3 py-2 text-xs text-zinc-500`,children:`loading…`}),x?.length===0&&(0,N.jsx)(`div`,{className:`px-3 py-2 text-xs text-zinc-500`,children:_?`no matches`:`no saved sessions`}),x?.map(e=>(0,N.jsx)(lG,{session:e,isCurrent:e.id===n,renaming:p===e.path,onSwitch:()=>{r(e.path),y()},onDelete:()=>{window.confirm(`Delete this session?`)&&i(e.path)},onStartRename:()=>m(e.path),onRename:t=>{o(e.path,t),m(null),_&&s(d.trim())},onCancelRename:()=>m(null)},e.path))]})]})]})}function dG({filters:e,onFilterChange:t}){let[n,r]=(0,v.useState)(!1),i=aH(()=>r(!1)),a=MV(e),o=a>0?`Filter · ${a} hidden`:`Filter`;return(0,N.jsxs)(`div`,{className:`relative`,ref:i,onKeyDown:e=>{e.key===`Escape`&&n&&(e.stopPropagation(),r(!1))},children:[(0,N.jsx)(`button`,{type:`button`,onClick:()=>r(!n),"aria-haspopup":`menu`,"aria-expanded":n,title:`Choose what the conversation shows`,className:`${cW} ${a>0?`border-zinc-400 bg-zinc-100 text-zinc-700 dark:border-zinc-600 dark:bg-zinc-800 dark:text-zinc-200`:`border-zinc-300 text-zinc-500 hover:border-zinc-400 hover:text-zinc-700 dark:border-zinc-800 dark:text-zinc-400 dark:hover:border-zinc-600 dark:hover:text-zinc-200`}`,children:o}),n&&(0,N.jsx)(`div`,{role:`menu`,className:`absolute right-0 z-30 mt-1 w-48 rounded-md border border-zinc-200 bg-white py-1 shadow-lg dark:border-zinc-700 dark:bg-zinc-900`,children:DV.map(n=>(0,N.jsxs)(`button`,{type:`button`,role:`menuitemcheckbox`,"aria-checked":e[n],onClick:()=>t(n,!e[n]),className:`flex w-full items-center gap-2 px-3 py-1.5 text-left text-xs text-zinc-600 hover:bg-zinc-100 dark:text-zinc-300 dark:hover:bg-zinc-800`,children:[(0,N.jsx)(`span`,{"aria-hidden":!0,className:`w-3`,children:e[n]?`✓`:``}),(0,N.jsx)(`span`,{children:OV[n]})]},n))})]})}function fG({statuses:e,bar:t}){let n=Object.entries(e).filter(([,e])=>FH(e).trim()!==``),r=n.map(([e,t])=>`${e}\u0000${t}`).join(``),[i,a]=(0,v.useState)(!1),o=(0,v.useRef)(null),s=(0,v.useRef)(null),[c,l]=(0,v.useState)(!1),u=aH(()=>l(!1));if((0,v.useLayoutEffect)(()=>{o.current=null,a(!1),l(!1)},[r]),(0,v.useLayoutEffect)(()=>{let e=t;if(e===null)return;let n=()=>{o.current===null?(Array.from(s.current?.querySelectorAll(`[data-status-text]`)??[]).some(e=>e.scrollWidth>e.clientWidth+1)||e.scrollWidth>e.clientWidth+1)&&(o.current=e.clientWidth,a(!0)):e.clientWidth>o.current+64&&(o.current=null,a(!1),l(!1))};if(n(),typeof ResizeObserver>`u`)return;let r=new ResizeObserver(n);return r.observe(e),()=>r.disconnect()},[t,i,r]),n.length===0)return null;if(!i)return(0,N.jsx)(`div`,{ref:s,className:`flex shrink-0 items-center gap-1.5`,children:n.map(([e,t])=>(0,N.jsx)(`span`,{title:FH(t),className:`${cW} max-w-[16rem] border-zinc-200 text-zinc-500 dark:border-zinc-800 dark:text-zinc-400`,children:(0,N.jsx)(`span`,{"data-status-text":!0,className:`truncate`,children:(0,N.jsx)(IH,{text:t})})},e))});let d=`${n.length} ${n.length===1?`status`:`statuses`}`;return(0,N.jsxs)(`div`,{ref:u,className:`relative shrink-0`,onKeyDown:e=>{e.key===`Escape`&&c&&(e.stopPropagation(),l(!1))},children:[(0,N.jsxs)(`button`,{type:`button`,onClick:()=>l(!c),"aria-expanded":c,title:n.map(([,e])=>FH(e)).join(`
1512
- `),className:`${cW} border-zinc-200 text-zinc-500 hover:border-zinc-400 hover:text-zinc-700 dark:border-zinc-800 dark:text-zinc-400 dark:hover:border-zinc-600 dark:hover:text-zinc-200`,children:[d,` ▾`]}),c&&(0,N.jsx)(`ul`,{"aria-label":`Extension statuses`,className:`absolute left-0 top-full z-20 mt-1 w-max max-w-[24rem] rounded-md border border-zinc-200 bg-white py-1 shadow-lg dark:border-zinc-700 dark:bg-zinc-900`,children:n.map(([e,t])=>(0,N.jsx)(`li`,{className:`break-words px-3 py-1.5 text-xs text-zinc-600 dark:text-zinc-300`,children:(0,N.jsx)(IH,{text:t})},e))})]})}function pG({theme:e,preference:t=e,onToggle:n,onSetTheme:r}){let[i,a]=(0,v.useState)(!1),o=(0,v.useRef)(null),s=aH(()=>a(!1));(0,v.useEffect)(()=>{i&&s.current?.querySelector(`[aria-checked="true"]`)?.focus()},[i]);let c={light:`Light`,dark:`Dark`,system:`System`}[t];return(0,N.jsxs)(`div`,{ref:s,className:`relative`,onKeyDown:e=>{if(e.key===`Escape`&&(e.stopPropagation(),a(!1),o.current?.focus()),i&&[`ArrowDown`,`ArrowUp`,`Home`,`End`].includes(e.key)){e.preventDefault();let t=Array.from(s.current?.querySelectorAll(`[role="menuitemradio"]`)??[]),n=t.findIndex(e=>e.matches(`:focus`));t[e.key===`Home`?0:e.key===`End`?t.length-1:(n+(e.key===`ArrowDown`?1:-1)+t.length)%t.length]?.focus()}},children:[(0,N.jsx)(`button`,{ref:o,type:`button`,onClick:()=>a(e=>!e),title:`Theme: ${c}`,"aria-label":`Theme: ${c}`,"aria-haspopup":`menu`,"aria-expanded":i,className:`${cW} border-zinc-300 text-zinc-500 hover:border-zinc-400 hover:text-zinc-700 dark:border-zinc-800 dark:text-zinc-400 dark:hover:border-zinc-600 dark:hover:text-zinc-200`,children:t===`system`?`◐`:e===`dark`?`☾`:`☀`}),i&&(0,N.jsx)(`div`,{role:`menu`,"aria-label":`Theme`,className:`absolute right-0 top-full z-40 mt-2 min-w-32 rounded-lg border border-zinc-300 bg-white p-1 shadow-lg dark:border-zinc-700 dark:bg-zinc-900`,children:[`light`,`dark`,`system`].map(i=>(0,N.jsx)(`button`,{role:`menuitemradio`,"aria-checked":t===i,type:`button`,className:`block w-full rounded px-3 py-1.5 text-left text-xs text-zinc-700 hover:bg-zinc-100 focus:bg-zinc-100 dark:text-zinc-200 dark:hover:bg-zinc-800 dark:focus:bg-zinc-800`,onClick:()=>{r?r(i):i!==e&&n(),a(!1),o.current?.focus()},children:i===`light`?`Light`:i===`dark`?`Dark`:`System`},i))})]})}function mG(e){let{isStreaming:t,connected:n}=e,[r,i]=(0,v.useState)(null);return(0,N.jsxs)(`header`,{ref:i,className:`relative z-30 flex min-w-0 items-center gap-1.5 border-b border-zinc-200 px-4 py-2 dark:border-zinc-800`,children:[e.workspaceControl===`projects`&&(0,N.jsx)(hW,{workspace:e.workspace,workspaces:e.workspaces,locked:e.workspaceLocked,onSwitch:e.onSwitchWorkspace,onOpen:e.onOpenProject,onClose:e.onCloseProject,onOpenSide:e.onOpenSideSession}),e.workspaceControl===`root`&&e.rootControl&&(0,N.jsx)(vW,{sandbox:e.rootControl.sandbox,browse:e.rootControl.browse,applyState:e.rootControl.applyState,blocked:e.rootControl.blocked,onBrowse:e.rootControl.onBrowse,onCloseBrowser:e.rootControl.onCloseBrowser,onOpened:e.rootControl.onOpened,onSelect:e.rootControl.onSelect}),(0,N.jsxs)(`button`,{type:`button`,onClick:e.onToggleSidebar,title:e.sidebarOpen?`Hide files (panel opens on the left)`:`Show files`,"aria-pressed":e.sidebarOpen,className:`${cW} ${e.sidebarOpen?`border-zinc-400 bg-zinc-100 text-zinc-700 dark:border-zinc-600 dark:bg-zinc-800 dark:text-zinc-200`:`border-zinc-300 text-zinc-500 hover:border-zinc-400 hover:text-zinc-700 dark:border-zinc-800 dark:text-zinc-400 dark:hover:border-zinc-600 dark:hover:text-zinc-200`}`,children:[e.sidebarOpen?`◧`:`◨`,` files`]}),(0,N.jsxs)(`button`,{type:`button`,onClick:e.onToggleOutcome,"aria-pressed":e.outcomeOpen,title:`Review structured workspace Outcome`,className:`${cW} ${e.outcomeOpen?`border-zinc-400 bg-zinc-100 text-zinc-700 dark:border-zinc-600 dark:bg-zinc-800 dark:text-zinc-200`:e.workspace?.activity===`ready-for-review`?`border-amber-400 text-amber-700 dark:text-amber-300`:`border-zinc-300 text-zinc-500 hover:border-zinc-400 dark:border-zinc-800 dark:text-zinc-400`}`,children:[`Outcome`,e.workspace?.activity===`ready-for-review`?` •`:``]}),e.gitAvailable&&(0,N.jsx)(xW,{status:e.gitStatus,selected:e.gitSelectedPath,log:e.gitLog,onFetchLog:e.onFetchGitLog,onCloseLog:e.onCloseGitLog,onShowCommit:e.onShowCommit}),(0,N.jsx)(`span`,{title:e.title??void 0,className:`min-w-[2.25rem] shrink-[4] truncate whitespace-nowrap text-lg font-semibold leading-tight tracking-tight`,style:{color:`var(--accent, inherit)`},children:e.title??`π`}),(0,N.jsx)(fG,{statuses:e.statuses,bar:r}),(0,N.jsxs)(`div`,{className:`ml-auto flex shrink-0 items-center gap-1.5`,children:[(0,N.jsx)(dG,{filters:e.filters,onFilterChange:e.onFilterChange}),e.onExportConversation&&(0,N.jsx)(`button`,{type:`button`,onClick:e.onExportConversation,disabled:!!e.exportProgress,"aria-busy":!!e.exportProgress,title:`Save the whole conversation as one HTML file`,"aria-label":`Export the conversation as HTML`,className:`inline-flex h-7 shrink-0 items-center gap-1 whitespace-nowrap rounded-md border px-2 text-xs leading-none border-zinc-300 text-zinc-500 hover:border-zinc-400 hover:text-zinc-700 disabled:cursor-progress disabled:opacity-60 dark:border-zinc-800 dark:text-zinc-400 dark:hover:border-zinc-600 dark:hover:text-zinc-200`,children:e.exportProgress??`↓ html`}),e.onToggleTerminal&&(0,N.jsx)(`button`,{type:`button`,onClick:e.onToggleTerminal,title:e.terminalOpen?"Close Terminal (Ctrl+`)":"Open Terminal (Ctrl+`)","aria-pressed":e.terminalOpen,className:`inline-flex h-7 shrink-0 items-center gap-1 whitespace-nowrap rounded-md border px-2 text-xs leading-none ${e.terminalOpen?`border-zinc-400 bg-zinc-100 text-zinc-700 dark:border-zinc-600 dark:bg-zinc-800 dark:text-zinc-200`:`border-zinc-300 text-zinc-500 hover:border-zinc-400 hover:text-zinc-700 dark:border-zinc-800 dark:text-zinc-400 dark:hover:border-zinc-600 dark:hover:text-zinc-200`}`,children:`>_ terminal`}),e.showThemeToggle&&(0,N.jsx)(pG,{theme:e.theme,preference:e.themePreference,onSetTheme:e.onSetTheme,onToggle:e.onToggleTheme}),(0,N.jsx)(`button`,{type:`button`,onClick:e.onNewSession,title:`new session`,className:`${cW} border-emerald-300 text-emerald-700 hover:border-emerald-500 hover:text-emerald-600 dark:border-emerald-900 dark:text-emerald-400 dark:hover:border-emerald-600 dark:hover:text-emerald-300`,children:`+ new`}),(0,N.jsx)(oG,{tree:e.tree,isStreaming:t,onListTree:e.onListTree,onNavigate:e.onNavigateTree,onFork:e.onForkSession}),(0,N.jsx)(uG,{sessions:e.sessions,sessionSearch:e.sessionSearch,sessionId:e.sessionId,onSwitchSession:e.onSwitchSession,onDeleteSession:e.onDeleteSession,onListSessions:e.onListSessions,onRenameSession:e.onRenameSession,onSearchSessions:e.onSearchSessions,onClearSessionSearch:e.onClearSessionSearch}),(0,N.jsx)(eG,{credentials:e.credentials,login:e.login,onStartLogin:e.onStartLogin,onAnswerLogin:e.onAnswerLogin,onCancelLogin:e.onCancelLogin,onDismissLogin:e.onDismissLogin,onLogoutProvider:e.onLogoutProvider,extensionPaths:e.extensionPaths,configuredExtensionPaths:e.configuredExtensionPaths,userExtensionPaths:e.userExtensionPaths,extensionLock:e.extensionLock,piPackages:e.piPackages??null,piPackageUpdate:e.piPackageUpdate??null,canRestartServer:e.canRestartServer??!1,serverRestarting:e.serverRestarting??!1,...e.onCheckPiPackages?{onCheckPiPackages:e.onCheckPiPackages}:{},...e.onUpdatePiPackage?{onUpdatePiPackage:e.onUpdatePiPackage}:{},...e.onRestartServer?{onRestartServer:e.onRestartServer}:{},restartNeeded:e.restartNeeded??[],tools:e.tools??[],commands:e.commands??[],sandbox:e.sandbox,showRoots:!(e.workspaceControl===`projects`&&e.workspaces.filter(e=>!e.sideOf).length>1),gitUnavailable:e.gitUnavailable,userSkillPaths:e.userSkillPaths,serverBrowse:e.serverBrowse,applyState:e.settingsApply,agentResources:e.agentResources,agentResourceOperations:e.agentResourceOperations,versions:e.versions,onBrowseServerPath:e.onBrowseServerPath,onCloseServerBrowser:e.onCloseServerBrowser,pickerBlocked:e.settingsPickerBlocked,onPickerOpened:e.onSettingsPickerOpened,onRestartSession:e.onRestartSession,onUpdateConfig:e.onUpdateConfig,onSuggestAgentResourceClonePath:e.onSuggestAgentResourceClonePath,onCloneAgentResourceRepository:e.onCloneAgentResourceRepository,onEnrollAgentResourceRepository:e.onEnrollAgentResourceRepository,onSetAgentResourceSkills:e.onSetAgentResourceSkills,onRemoveAgentResourceRepository:e.onRemoveAgentResourceRepository,onRefreshAgentResourceRepositories:e.onRefreshAgentResourceRepositories,onUpdateAgentResourceRepository:e.onUpdateAgentResourceRepository}),(0,N.jsx)(`span`,{className:`h-2 w-2 rounded-full ${n?`bg-emerald-500`:`bg-red-500`}`,title:n?`connected`:`disconnected`})]})]})}function hG(e,t){let n=(0,v.useRef)(new Map);(0,v.useEffect)(()=>{if(typeof Notification>`u`)return;let r=e.filter(e=>e.needsAttention),i=r.filter(e=>GB(e)!==t);for(let e of[...n.current.keys()])r.some(t=>GB(t)===e)||n.current.delete(e);if(Notification.permission===`granted`&&(typeof document>`u`||document.visibilityState!==`visible`)){for(let e of i)if(n.current.get(GB(e))!==e.activity){n.current.set(GB(e),e.activity);try{let t=e.activity===`ready-for-review`;new Notification(t?`${e.name} is ready for review`:`${e.name} needs you`,{body:t?`Background work is ready for review.`:`The agent needs an answer to continue.`,tag:`pi-outpost:${GB(e)}`})}catch{}}}},[e,t])}var gG={"agent-directory":`read the agent directory (the provider keys)`,"beside-root":`read a file beside the root`,"write-beside-root":`write beside the root`,"signal-process":`signal another process of the server's user`,"server-environment":`inherit the server's environment`,"server-process-environment":`read the server's process environment (/proc)`,"unlisted-host":`reach a host not in sandbox.allowedHosts`,"direct-connection":`connect around the proxy`},_G=e=>e.map(e=>gG[e]??e),vG=e=>{let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleTimeString()};function yG(e,t){let n=t===`shell`?`The agent's shell`:`This terminal`;switch(e.state){case`checking`:return`${n} runs under ${e.runner||`a sandbox runner`}; its confinement is being checked.`;case`verified`:return[`${n} is confined by ${e.runner}, checked at ${vG(e.checkedAt)}. A command could not:`,..._G(e.refused).map(e=>`• ${e}`),...e.environmentReadable?[`The server's process environment is readable, and holds no secret.`]:[],...e.notChecked.length?[`Not checked:`,...e.notChecked.map(e=>`• ${gG[e.attempt]??e.attempt} — ${e.why}`)]:[]].join(`
1513
- `);case`partial`:return[`${n} is confined by ${e.runner}, checked at ${vG(e.checkedAt)}, except one thing: a command can read the server's process environment, which holds ${e.exposed.join(`, `)}.`,`Move these out of the server's environment — provider keys belong in the agent directory.`,`A command could not:`,..._G(e.refused).map(e=>`• ${e}`)].join(`
1514
- `);case`leaking`:return[`${n} is NOT confined as configured: under ${e.runner}, checked at ${vG(e.checkedAt)}, a command could:`,..._G(e.reached).map(e=>`• ${e}`),`The configuration is unchanged: fix the runner or its host, or stop using it.`].join(`
1515
- `);case`failed`:return`${n}'s confinement could not be checked (${e.runner}, ${vG(e.checkedAt)}): ${e.reason}`;case`unavailable`:return e.reason||`${n} refuses every command.`;case`unconfined`:return e.available?[`${n} is NOT confined: a command runs with every right of the server's account.`,`${e.available.label} can confine it on this machine. To confine it, run:`,` pi-outpost config --confine`,`It checks ${e.available.label} first, then sets "sandbox.bashRunner": "auto" in the configuration file.`].join(`
1516
- `):e.reason?`${n} is not confined, as configured: nothing can confine it on this machine — ${e.reason}`:`${n} is not confined, as configured.`}}function bG(e){let t=[...e.hosts.map(e=>`• host ${e}`),...e.directories.map(e=>`• ${e.access===`write`?`read and write`:`read`} ${e.path}`)];return t.length?[`Granted by you for this session:`,...t]:[]}function xG({verdict:e,surface:t,root:n,grants:r}){let i=n?` to ${n}`:``,a=r?r.hosts.length+r.directories.length:0,o=a>0?` · ${a} grant${a>1?`s`:``}`:``,s=e.state===`verified`?{icon:`🔒`,text:`confined${i}`,tone:`bg-emerald-100 text-emerald-800 dark:bg-emerald-900/50 dark:text-emerald-200`}:e.state===`partial`?{icon:`🔐`,text:`partly confined`,tone:`bg-amber-100 text-amber-800 dark:bg-amber-900/50 dark:text-amber-200`}:e.state===`leaking`?{icon:`🔓`,text:`not confined`,tone:`bg-red-100 text-red-800 dark:bg-red-900/50 dark:text-red-200`}:e.state===`failed`?{icon:`⚠`,text:`confinement unchecked`,tone:`bg-amber-100 text-amber-800 dark:bg-amber-900/50 dark:text-amber-200`}:e.state===`unavailable`?{icon:`⛔`,text:`unavailable`,tone:`bg-red-100 text-red-800 dark:bg-red-900/50 dark:text-red-200`}:e.state===`unconfined`?e.available?{icon:`🔓`,text:`not confined`,tone:`bg-amber-100 text-amber-800 ring-1 ring-amber-400 dark:bg-amber-900/50 dark:text-amber-200 dark:ring-amber-500`}:{icon:`🔓`,text:`not confined`,tone:`bg-zinc-100 text-zinc-600 dark:bg-zinc-800 dark:text-zinc-300`}:{icon:`…`,text:`checking confinement`,tone:`bg-zinc-100 text-zinc-600 dark:bg-zinc-800 dark:text-zinc-300`};return(0,N.jsxs)(`span`,{"data-testid":t===`shell`?`shell-confinement`:`terminal-confined`,"data-state":e.state,"data-nudge":e.state===`unconfined`&&e.available?`true`:void 0,"data-grants":a,title:[yG(e,t),...r?bG(r):[]].join(`
1517
- `),className:`shrink-0 whitespace-nowrap rounded px-1.5 py-0.5 font-sans text-[11px] ${s.tone}`,children:[s.icon,` `,t===`shell`?`shell ${s.text}`:s.text,o]})}function SG(e){return!e||e.percent===null?`text-zinc-400 dark:text-zinc-600`:e.percent>=85?`text-red-500`:e.percent>=60?`text-amber-500 dark:text-amber-400`:`text-emerald-500`}function CG({usage:e,analysisOpen:t,onToggleAnalysis:n}){if(e.turns===0)return null;let r=e.turns-e.unpriced,i=[`${e.turns} turn${e.turns===1?``:`s`}`,`input ${e.input.toLocaleString()}`,`output ${e.output.toLocaleString()}`,`cache read ${e.cacheRead.toLocaleString()}`,`cache write ${e.cacheWrite.toLocaleString()}`,...e.unpriced>0&&r>0?[`${e.unpriced} unpriced`]:[]].join(` · `),a=(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`span`,{children:[QB(e.totalTokens),` tok`]}),r>0&&(0,N.jsxs)(`span`,{className:`text-zinc-400 dark:text-zinc-500`,children:[ZB(e.cost),e.unpriced>0&&`*`]})]}),o=`flex items-center gap-1.5 rounded-md border px-2 py-1 font-mono text-xs text-zinc-500 dark:text-zinc-400`;return n?(0,N.jsx)(`button`,{type:`button`,onClick:n,title:`${i} — click for the session analysis`,"aria-haspopup":`dialog`,"aria-expanded":t??!1,className:`${o} ${t?`border-zinc-400 dark:border-zinc-600`:`border-zinc-300 hover:border-zinc-400 dark:border-zinc-800 dark:hover:border-zinc-600`}`,children:a}):(0,N.jsx)(`span`,{title:i,className:`${o} border-zinc-300 dark:border-zinc-800`,children:a})}function wG({usage:e}){let t=15.9155,n=2*Math.PI*t,r=e?.percent??0,i=Math.min(100,Math.max(0,r))/100*n;return(0,N.jsxs)(`svg`,{width:18,height:18,viewBox:`0 0 36 36`,className:`-rotate-90 shrink-0`,children:[(0,N.jsx)(`circle`,{cx:`18`,cy:`18`,r:t,fill:`none`,stroke:`currentColor`,strokeWidth:`4`,className:`text-zinc-200 dark:text-zinc-800`}),e&&e.percent!==null&&(0,N.jsx)(`circle`,{cx:`18`,cy:`18`,r:t,fill:`none`,stroke:`currentColor`,strokeWidth:`4`,strokeLinecap:`round`,strokeDasharray:`${i} ${n-i}`,className:SG(e)})]})}function TG({thinkingLevel:e,thinkingLevels:t,isStreaming:n,onSetThinking:r}){let[i,a]=(0,v.useState)(!1),o=(0,v.useRef)(null),s=e!==`off`,c=t&&t.length>0?t:AU,l=c.indexOf(e),u=c.length>1;return(0,v.useEffect)(()=>{if(!i)return;function e(e){o.current&&!iH(e,o.current)&&a(!1)}function t(e){e.key===`Escape`&&a(!1)}return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[i]),(0,N.jsxs)(`div`,{className:`relative`,ref:o,children:[(0,N.jsxs)(`button`,{type:`button`,onClick:()=>a(!i),disabled:n,title:`thinking level`,"aria-haspopup":`true`,"aria-expanded":i,className:`flex items-center gap-1.5 rounded-md border px-2 py-1 font-mono text-xs disabled:opacity-50 ${s?`border-amber-300 text-amber-700 hover:border-amber-400 dark:border-amber-900 dark:text-amber-400 dark:hover:border-amber-700`:`border-zinc-300 text-zinc-500 hover:border-zinc-400 dark:border-zinc-800 dark:text-zinc-400 dark:hover:border-zinc-600`}`,children:[(0,N.jsx)(`span`,{"aria-hidden":!0,className:`text-sm leading-none ${s?``:`opacity-40 grayscale`}`,children:`🧠`}),e]}),i&&(0,N.jsxs)(`div`,{className:`absolute bottom-full left-0 z-20 mb-1 w-48 rounded-lg border border-zinc-200 bg-white p-3 shadow-xl dark:border-zinc-700 dark:bg-zinc-900`,children:[(0,N.jsxs)(`div`,{className:`mb-1 flex items-baseline justify-between text-xs`,children:[(0,N.jsx)(`span`,{className:`text-zinc-500 dark:text-zinc-400`,children:`thinking`}),(0,N.jsx)(`span`,{className:`font-mono text-zinc-700 dark:text-zinc-200`,children:e})]}),u?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`input`,{type:`range`,min:0,max:c.length-1,step:1,value:l===-1?0:l,onChange:e=>r(c[Number(e.target.value)]),"aria-label":`Thinking level`,"aria-valuetext":e,className:`w-full accent-amber-500`}),(0,N.jsxs)(`div`,{className:`mt-0.5 flex justify-between font-mono text-[9px] text-zinc-400 dark:text-zinc-600`,children:[(0,N.jsx)(`span`,{children:c[0]}),(0,N.jsx)(`span`,{children:c[c.length-1]})]})]}):(0,N.jsxs)(`p`,{className:`text-[11px] text-zinc-500 dark:text-zinc-400`,children:[`this model accepts `,(0,N.jsx)(`span`,{className:`font-mono`,children:c[0]}),` only`]})]})]})}function EG(e){let{model:t,models:n,thinkingLevel:r,modelSupportsReasoning:i,isStreaming:a,contextUsage:o,sessionUsage:s,isCompacting:c}=e;return(0,N.jsxs)(`div`,{className:`mt-2 flex items-center gap-2`,children:[(0,N.jsxs)(`select`,{value:t,onChange:t=>{let r=n.find(e=>`${e.provider}/${e.id}`===t.target.value);r&&e.onSetModel(r.provider,r.id)},disabled:a,className:`max-w-64 rounded-md border border-zinc-300 bg-white px-2 py-1 font-mono text-xs text-zinc-700 outline-none hover:border-zinc-400 disabled:opacity-50 dark:border-zinc-800 dark:bg-zinc-900 dark:text-zinc-300 dark:hover:border-zinc-600`,children:[!n.some(e=>`${e.provider}/${e.id}`===t)&&(0,N.jsx)(`option`,{value:t,children:t}),n.map(e=>(0,N.jsxs)(`option`,{value:`${e.provider}/${e.id}`,children:[e.provider,`/`,e.id]},`${e.provider}/${e.id}`))]}),i&&(0,N.jsx)(TG,{thinkingLevel:r,thinkingLevels:e.thinkingLevels,isStreaming:a,onSetThinking:e.onSetThinking}),e.shellConfinement&&(0,N.jsx)(`span`,{className:`ml-auto`,children:(0,N.jsx)(xG,{verdict:e.shellConfinement,surface:`shell`,grants:e.shellGrants})}),(0,N.jsxs)(`button`,{type:`button`,onClick:e.onCompact,disabled:a||c,title:o?.tokens==null?`Click to compact the conversation context`:`${o.tokens.toLocaleString()} / ${o.contextWindow.toLocaleString()} tokens — click to compact`,className:`${e.shellConfinement?``:`ml-auto `}flex items-center gap-1.5 rounded-md border border-zinc-300 px-2 py-1 font-mono text-xs text-zinc-500 hover:border-zinc-400 disabled:opacity-50 dark:border-zinc-800 dark:text-zinc-400 dark:hover:border-zinc-600`,children:[(0,N.jsx)(wG,{usage:o}),c?`compacting…`:o?.percent==null?`context`:`${Math.round(o.percent)}%`]}),(0,N.jsx)(CG,{usage:s,analysisOpen:e.analysisOpen,onToggleAnalysis:e.onToggleAnalysis})]})}var DG=`w-full rounded-md border border-zinc-300 bg-white px-3 py-2 text-sm text-zinc-800 placeholder:text-zinc-400 focus:border-zinc-400 focus:outline-none dark:border-zinc-700 dark:bg-zinc-900 dark:text-zinc-100 dark:placeholder:text-zinc-600`,OG=`mb-1 block text-xs font-medium text-zinc-600 dark:text-zinc-400`;function kG({title:e,credentials:t,onSetCredential:n,onStartLogin:r,login:i,onAnswerLogin:a,onCancelLogin:o,onDismissLogin:s,onDeclareProvider:c,errors:l}){let u=t.providers,[d,f]=(0,v.useState)(u.length>0?`known`:`custom`),[p,m]=(0,v.useState)(u[0]?.id??``),[h,g]=(0,v.useState)(``),[_,y]=(0,v.useState)(``),[b,x]=(0,v.useState)(``),[S,C]=(0,v.useState)(``),[w,T]=(0,v.useState)(!0),[E,D]=(0,v.useState)(!0);function O(e){i?.provider===e?(i.done||o(),s()):(i&&(i.done||o(),s()),r(e,`oauth`))}let ee=u.some(e=>e.configured)&&!t.usableModel;function te(e){e.preventDefault(),!ee&&(d===`known`?p&&h.trim()&&n(p,h.trim()):_.trim()&&b.trim()&&h.trim()&&S.trim()&&c({provider:_.trim(),baseUrl:b.trim(),apiKey:h.trim(),models:[S.trim()],compat:{supportsDeveloperRole:w,supportsReasoningEffort:E}}))}return(0,N.jsx)(`div`,{className:`flex h-full items-center justify-center overflow-auto p-6`,children:(0,N.jsxs)(`form`,{onSubmit:te,className:`w-full max-w-md rounded-xl border border-zinc-200 p-6 shadow-sm dark:border-zinc-800`,children:[(0,N.jsx)(`div`,{className:`mb-1 text-center text-3xl`,children:e??`π`}),ee?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`h1`,{className:`mb-3 text-center text-sm text-zinc-500 dark:text-zinc-400`,children:`No model is available.`}),(0,N.jsxs)(`p`,{className:`text-sm text-zinc-600 dark:text-zinc-400`,children:[`Credentials are configured, so this is not a missing key: `,(0,N.jsx)(`code`,{children:`allowedModels`}),` in your configuration leaves nothing to choose from. Widen it, or remove it, then restart.`]})]}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`h1`,{className:`mb-4 text-center text-sm text-zinc-500 dark:text-zinc-400`,children:`No model provider is set up yet. Add one to start chatting.`}),(0,N.jsx)(`div`,{className:`mb-4 flex gap-1 rounded-lg bg-zinc-100 p-1 text-xs dark:bg-zinc-800`,children:[`known`,`custom`].map(e=>(0,N.jsx)(`button`,{type:`button`,onClick:()=>f(e),className:`flex-1 rounded-md px-2 py-1.5 ${d===e?`bg-white font-medium text-zinc-800 shadow-sm dark:bg-zinc-900 dark:text-zinc-100`:`text-zinc-500 dark:text-zinc-400`}`,children:e===`known`?`Provider API key`:`OpenAI-compatible endpoint`},e))}),t.signIn&&u.some(e=>e.methods?.includes(`oauth`))&&(0,N.jsxs)(`section`,{className:`mb-4 rounded-lg border border-zinc-200 p-3 dark:border-zinc-800`,"data-testid":`onboarding-account-signin`,children:[(0,N.jsx)(`h2`,{className:`mb-2 text-xs font-medium text-zinc-700 dark:text-zinc-300`,children:`Sign in with an account`}),(0,N.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:u.filter(e=>e.methods?.includes(`oauth`)).map(e=>{let t=i?.provider===e.id;return(0,N.jsx)(`button`,{type:`button`,"aria-expanded":t,"aria-controls":`onboarding-login-flow-${e.id}`,className:`rounded border px-3 py-2 text-xs ${t?`border-sky-500 bg-sky-50 text-sky-800 dark:bg-sky-950/40 dark:text-sky-200`:``}`,onClick:()=>O(e.id),children:e.name},e.id)})}),i&&(0,N.jsx)(`div`,{id:`onboarding-login-flow-${i.provider}`,className:`mt-3`,children:(0,N.jsx)(XW,{login:i,providerName:u.find(e=>e.id===i.provider)?.name??i.provider,onAnswer:a,onCancel:o,onDismiss:s})})]}),d===`known`?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`label`,{htmlFor:`onboarding-provider`,className:OG,children:`Provider`}),(0,N.jsx)(`select`,{id:`onboarding-provider`,value:p,onChange:e=>m(e.target.value),className:`${DG} mb-3`,children:u.map(e=>(0,N.jsxs)(`option`,{value:e.id,children:[e.name,e.configured?` (already configured)`:``]},e.id))})]}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`label`,{htmlFor:`onboarding-name`,className:OG,children:`Name`}),(0,N.jsx)(`input`,{id:`onboarding-name`,value:_,onChange:e=>y(e.target.value),placeholder:`corp`,className:`${DG} mb-3`}),(0,N.jsx)(`label`,{htmlFor:`onboarding-url`,className:OG,children:`Base URL`}),(0,N.jsx)(`input`,{id:`onboarding-url`,value:b,onChange:e=>x(e.target.value),placeholder:`https://llm.corp.example/v1`,className:`${DG} mb-3`}),(0,N.jsx)(`label`,{htmlFor:`onboarding-model`,className:OG,children:`Model id`}),(0,N.jsx)(`input`,{id:`onboarding-model`,value:S,onChange:e=>C(e.target.value),placeholder:`gpt-oss-120b`,className:`${DG} mb-3`})]}),(0,N.jsx)(`label`,{htmlFor:`onboarding-key`,className:OG,children:`API key`}),(0,N.jsx)(`input`,{id:`onboarding-key`,type:`password`,autoComplete:`off`,value:h,onChange:e=>g(e.target.value),placeholder:`sk-…`,className:DG}),d===`custom`&&(0,N.jsxs)(`fieldset`,{className:`mt-4 rounded-lg border border-zinc-200 p-3 dark:border-zinc-800`,children:[(0,N.jsx)(`legend`,{className:`px-1 text-xs text-zinc-500 dark:text-zinc-400`,children:`Compatibility`}),(0,N.jsxs)(`label`,{className:`flex items-start gap-2 text-xs text-zinc-600 dark:text-zinc-400`,children:[(0,N.jsx)(`input`,{type:`checkbox`,checked:w,onChange:e=>T(e.target.checked),className:`mt-0.5`}),(0,N.jsxs)(`span`,{children:[`Server understands the `,(0,N.jsx)(`code`,{children:`developer`}),` role. Uncheck for vLLM, SGLang and most corporate gateways — the system prompt is then sent as a `,(0,N.jsx)(`code`,{children:`system`}),` message.`]})]}),(0,N.jsxs)(`label`,{className:`mt-2 flex items-start gap-2 text-xs text-zinc-600 dark:text-zinc-400`,children:[(0,N.jsx)(`input`,{type:`checkbox`,checked:E,onChange:e=>D(e.target.checked),className:`mt-0.5`}),(0,N.jsxs)(`span`,{children:[`Server accepts `,(0,N.jsx)(`code`,{children:`reasoning_effort`}),`. Uncheck if it rejects unknown fields.`]})]})]}),(0,N.jsx)(`button`,{type:`submit`,className:`mt-4 w-full rounded-md bg-zinc-800 px-3 py-2 text-sm font-medium text-white hover:bg-zinc-700 dark:bg-zinc-100 dark:text-zinc-900 dark:hover:bg-white`,children:`Save and start`})]}),l.map((e,t)=>(0,N.jsx)(`p`,{className:`mt-3 rounded-md border border-amber-300 bg-amber-50 px-3 py-2 text-xs text-amber-700 dark:border-amber-900/60 dark:bg-amber-950/30 dark:text-amber-300`,children:e},t)),(0,N.jsxs)(`p`,{className:`mt-4 text-center text-xs text-zinc-400 dark:text-zinc-600`,children:[t.agentDir?`Stored in ${t.agentDir}. `:``,`Provider environment variables work too, as does `,(0,N.jsx)(`code`,{children:`pi-outpost login`}),`.`]})]})})}function AG({query:e,onQueryChange:t,search:n,onSearch:r,onOpenHit:i,onClose:a}){let o=(0,v.useRef)(null);(0,v.useEffect)(()=>{o.current?.focus()},[]);let s=MG(n?.hits??[]);return(0,N.jsxs)(`div`,{className:`flex flex-col gap-2`,"data-content-search":!0,children:[(0,N.jsxs)(`form`,{role:`search`,"aria-label":`Search in files`,className:`flex items-center gap-1`,onSubmit:t=>{t.preventDefault(),r(e)},children:[(0,N.jsx)(`input`,{ref:o,type:`search`,value:e,onChange:e=>t(e.target.value),onKeyDown:e=>{e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),a())},placeholder:`Search in files`,"aria-label":`Text to search for in files`,className:`min-w-0 flex-1 rounded border border-zinc-300 bg-white px-2 py-1 text-xs text-zinc-800 outline-none focus:border-zinc-500 dark:border-zinc-700 dark:bg-zinc-900 dark:text-zinc-200`}),(0,N.jsx)(`button`,{type:`button`,onClick:a,title:`Back to the file tree`,"aria-label":`Close the search`,className:`rounded px-1 py-0.5 text-xs text-zinc-400 hover:bg-zinc-100 hover:text-zinc-600 dark:text-zinc-600 dark:hover:bg-zinc-800 dark:hover:text-zinc-400`,children:`×`})]}),n&&(0,N.jsx)(jG,{search:n,fileCount:s.length}),n?.status===`loaded`&&s.length>0&&(0,N.jsx)(`ul`,{"aria-label":`Search results`,className:`flex flex-col gap-2`,children:s.map(([e,t])=>(0,N.jsxs)(`li`,{children:[(0,N.jsxs)(`div`,{className:`flex items-baseline gap-1 px-1 text-xs font-medium text-zinc-700 dark:text-zinc-300`,title:e,children:[(0,N.jsx)(`span`,{className:`min-w-0 truncate`,children:e}),(0,N.jsx)(`span`,{className:`shrink-0 text-zinc-400 dark:text-zinc-600`,children:t.length})]}),(0,N.jsx)(`ul`,{children:t.map(t=>(0,N.jsx)(`li`,{children:(0,N.jsxs)(`button`,{type:`button`,onClick:()=>i(t,n.query),"aria-label":`${e}, ${t.kind===`line`?`line ${t.line}`:`page ${t.page}`}`,className:`flex w-full gap-2 rounded px-1 py-0.5 text-left text-xs hover:bg-zinc-100 dark:hover:bg-zinc-800`,children:[(0,N.jsx)(`span`,{className:`w-10 shrink-0 text-right tabular-nums text-zinc-400 dark:text-zinc-600`,children:t.kind===`line`?t.line:`p. ${t.page}`}),(0,N.jsx)(`span`,{className:`min-w-0 break-words font-mono text-zinc-600 dark:text-zinc-400`,children:NG(t.excerpt,n.query)})]})},t.kind===`line`?`l${t.line}`:`p${t.page}`))})]},e))})]})}function jG({search:e,fileCount:t}){if(e.status===`loading`)return(0,N.jsx)(`p`,{role:`status`,className:`px-1 text-xs text-zinc-500`,children:`Searching…`});let n=[];return e.truncated&&n.push(`The search stopped early: these are partial results. Narrow the query to see everything.`),e.skipped>0&&n.push(`${e.skipped} PDF${e.skipped===1?``:`s`} could not be read.`),(0,N.jsxs)(`div`,{role:`status`,className:`flex flex-col gap-1 px-1 text-xs text-zinc-500`,children:[(0,N.jsx)(`p`,{children:e.hits.length===0?`No matches`:`${e.hits.length} match${e.hits.length===1?``:`es`} in ${t} file${t===1?``:`s`}`}),n.map(e=>(0,N.jsx)(`p`,{className:`text-amber-700 dark:text-amber-400`,children:e},e))]})}function MG(e){let t=new Map;for(let n of e){let e=t.get(n.path);e?e.push(n):t.set(n.path,[n])}return[...t]}function NG(e,t){let n=t.trim().toLowerCase();if(n===``)return e;let r=e.toLowerCase(),i=[],a=0;for(let t=r.indexOf(n);t!==-1;t=r.indexOf(n,a))t>a&&i.push(e.slice(a,t)),i.push((0,N.jsx)(`mark`,{className:`rounded-sm bg-amber-200 text-zinc-900 dark:bg-amber-700/60 dark:text-zinc-100`,children:e.slice(t,t+n.length)},t)),a=t+n.length;return a<e.length&&i.push(e.slice(a)),i}var PG=`application/x-pi-outpost-file`,FG=`application/x-pi-outpost-read-only-file`,IG=`mr-1 shrink-0 rounded px-1 text-xs text-zinc-400 hover:bg-zinc-200 group-hover:opacity-100 focus-visible:opacity-100 dark:text-zinc-600 dark:hover:bg-zinc-700 [@media(hover:hover)]:opacity-0`,LG={modified:{label:`M`,className:`text-amber-600 dark:text-amber-400`},added:{label:`A`,className:`text-emerald-600 dark:text-emerald-400`},untracked:{label:`U`,className:`text-emerald-600 dark:text-emerald-400`},deleted:{label:`D`,className:`text-red-600 dark:text-red-400`},conflicted:{label:`C`,className:`text-purple-600 dark:text-purple-400`}};function RG(e,t){return t?Object.keys(t).filter(t=>t.startsWith(`${e}/`)).length:0}function zG(e){return e===`directory`||e===`symlink-directory`}function BG(e,t){return t===void 0?!1:t===null||t!==``&&e!==t&&!e.startsWith(`${t}/`)}function VG({dir:e,depth:t,creation:n}){let[r,i]=(0,v.useState)(``),a=(0,v.useRef)(null),o=n.localError??n.serverError;return(0,v.useEffect)(()=>{a.current?.focus()},[]),(0,N.jsxs)(`div`,{style:{paddingLeft:t*12+4},className:`py-0.5`,children:[(0,N.jsx)(`input`,{ref:a,value:r,onChange:e=>i(e.target.value),onKeyDown:t=>{t.key===`Enter`?(t.preventDefault(),n.submit(e,r)):t.key===`Escape`&&(t.preventDefault(),n.cancel())},onBlur:()=>{o===null&&n.cancel()},placeholder:`name, or name/ for a folder`,"aria-label":`New file or folder in ${e===``?`the workspace root`:e}`,spellCheck:!1,className:`w-full rounded border border-zinc-300 bg-white px-1 py-0.5 text-xs text-zinc-800 outline-none focus:border-zinc-400 dark:border-zinc-700 dark:bg-zinc-900 dark:text-zinc-200`}),o!==null&&(0,N.jsx)(`p`,{className:`px-1 pt-0.5 text-xs text-red-600 dark:text-red-400`,children:o})]})}function HG({path:e,name:t,depth:n,rename:r}){let[i,a]=(0,v.useState)(t),o=(0,v.useRef)(null),s=r.localError??r.serverError;return(0,v.useEffect)(()=>{o.current?.focus(),o.current?.select()},[]),(0,N.jsxs)(`div`,{style:{paddingLeft:n*12+16},className:`py-0.5`,children:[(0,N.jsx)(`input`,{ref:o,value:i,disabled:r.pending,onChange:e=>a(e.target.value),onKeyDown:t=>{t.key===`Enter`&&!r.pending?(t.preventDefault(),r.submit(e,i)):t.key===`Escape`&&(t.preventDefault(),r.cancel())},onBlur:()=>{s===null&&r.cancel()},"aria-label":`Rename ${t}`,spellCheck:!1,className:`w-full rounded border border-zinc-300 bg-white px-1 py-0.5 text-xs text-zinc-800 outline-none focus:border-zinc-400 dark:border-zinc-700 dark:bg-zinc-900 dark:text-zinc-200`}),s!==null&&(0,N.jsx)(`p`,{className:`px-1 pt-0.5 text-xs text-red-600 dark:text-red-400`,children:s})]})}function UG({path:e,depth:t,...n}){let r=n.tree[e],i=n.creation?.openIn===e?(0,N.jsx)(VG,{dir:e,depth:t,creation:n.creation}):null;return r===void 0?i:r===`loading`?(0,N.jsxs)(N.Fragment,{children:[i,(0,N.jsx)(`div`,{style:{paddingLeft:t*12+4},className:`py-0.5 text-xs text-zinc-400 dark:text-zinc-600`,children:`loading…`})]}):`error`in r?(0,N.jsxs)(N.Fragment,{children:[i,(0,N.jsx)(`div`,{style:{paddingLeft:t*12+4},className:`py-0.5 text-xs text-red-600 dark:text-red-400`,children:r.error})]}):r.length===0?(0,N.jsxs)(N.Fragment,{children:[i,i===null&&(0,N.jsx)(`div`,{style:{paddingLeft:t*12+4},className:`py-0.5 text-xs text-zinc-400 dark:text-zinc-600`,children:`empty`})]}):(0,N.jsxs)(N.Fragment,{children:[i,r.map(r=>(0,N.jsx)(WG,{parentPath:e,entry:r,depth:t,...n},r.name))]})}function WG({parentPath:e,entry:t,depth:n,...r}){let[i,a]=(0,v.useState)(!1),[o,s]=(0,v.useState)(!1),c=e?`${e}/${t.name}`:t.name,l=BG(c,r.writableRoot),u=r.fileOperation?.status===`pending`;if(zG(t.type)){let e=!l&&!u&&!r.imports?.pending,d=e=>e.includes(FG)?r.onCopyFile===void 0?null:`copy`:r.onMoveFile===void 0?null:`move`;return(0,N.jsxs)(`div`,{children:[(0,N.jsxs)(`div`,{className:`group flex w-full items-center rounded hover:bg-zinc-100 dark:hover:bg-zinc-800 ${o&&e?`bg-blue-50 ring-1 ring-blue-400 dark:bg-blue-950/40`:``}`,"data-drop-directory":c,onDragOver:t=>{let n=Array.from(t.dataTransfer.types);if(n.includes(`Files`)&&!n.includes(PG)&&r.imports){t.preventDefault(),t.stopPropagation(),t.dataTransfer.dropEffect=e?`copy`:`none`,s(e);return}if(!e||!Array.from(t.dataTransfer.types).includes(PG))return;let i=d(Array.from(t.dataTransfer.types));i!==null&&(t.preventDefault(),t.stopPropagation(),t.dataTransfer.dropEffect=i,s(!0))},onDragLeave:e=>{e.currentTarget.contains(e.relatedTarget)||s(!1)},onDrop:t=>{let n=Array.from(t.dataTransfer.types);if(n.includes(`Files`)&&!n.includes(PG)&&r.imports){t.preventDefault(),t.stopPropagation(),s(!1),e&&(a(!0),r.tree[c]===void 0&&r.onExpand(c),r.imports.start(c,t.dataTransfer));return}if(!e)return;let i=t.dataTransfer.getData(PG),o=i?d(Array.from(t.dataTransfer.types)):null;o!==null&&(t.preventDefault(),t.stopPropagation(),s(!1),o===`copy`?r.onCopyFile?.(i,c):r.onMoveFile?.(i,c))},children:[(0,N.jsxs)(`button`,{type:`button`,onClick:()=>{let e=!i;a(e),e&&r.tree[c]===void 0&&r.onExpand(c),r.onSelectDirectory?.(c)},style:{paddingLeft:n*12},className:`flex min-w-0 flex-1 items-center gap-1 rounded py-0.5 text-left`,children:[(0,N.jsx)(`span`,{className:`w-3 shrink-0 text-xs text-zinc-400 dark:text-zinc-600`,children:i?`▾`:`▸`}),(0,N.jsx)(`span`,{title:t.name,className:`truncate ${l?`text-zinc-400 dark:text-zinc-600`:`text-zinc-700 dark:text-zinc-300`}`,children:t.name}),!i&&RG(c,r.gitFiles)>0&&(0,N.jsx)(`span`,{className:`ml-1 shrink-0 rounded bg-amber-100 px-1 font-mono text-[10px] font-bold text-amber-700 dark:bg-amber-950/60 dark:text-amber-400`,title:`${RG(c,r.gitFiles)} changed file(s) inside`,children:RG(c,r.gitFiles)})]}),r.onRevealNative&&(0,N.jsx)(`button`,{type:`button`,disabled:u,onClick:()=>r.onRevealNative?.(c),title:`Show in the file manager`,"aria-label":`Show ${t.name} in the file manager`,className:IG,children:`⌂`}),r.creation&&!l&&(0,N.jsx)(`button`,{type:`button`,onClick:()=>{a(!0),r.tree[c]===void 0&&r.onExpand(c),r.creation?.start(c)},title:`New file or folder here`,"aria-label":`New file or folder in ${t.name}`,className:`mr-1 shrink-0 rounded px-1 font-mono text-xs text-zinc-400 hover:bg-zinc-200 group-hover:opacity-100 focus-visible:opacity-100 dark:text-zinc-600 dark:hover:bg-zinc-700 [@media(hover:hover)]:opacity-0`,children:`+`})]}),i&&(0,N.jsx)(UG,{path:c,depth:n+1,...r})]})}let d=c===r.openFilePath,f=r.gitFiles?.[c],p=r.attachedPaths?.includes(c)??!1,m=t.type===`file`,h=m||t.type===`symlink-file`,g=m&&!l,_=m&&(l?r.onCopyFile!==void 0:r.onMoveFile!==void 0);return r.rename?.path===c?(0,N.jsx)(HG,{path:c,name:t.name,depth:n,rename:r.rename}):(0,N.jsxs)(`div`,{className:`group flex w-full items-center rounded hover:bg-zinc-100 dark:hover:bg-zinc-800 ${d?`bg-zinc-100 dark:bg-zinc-800`:``}`,children:[(0,N.jsx)(`button`,{type:`button`,draggable:_&&!u,onDragStart:e=>{_&&!u&&(e.dataTransfer.effectAllowed=l?`copy`:`move`,e.dataTransfer.setData(PG,c),l&&e.dataTransfer.setData(FG,`copy`))},onClick:()=>r.onSelectFile(c),style:{paddingLeft:n*12+16},className:`flex min-w-0 flex-1 items-center py-0.5 text-left`,children:(0,N.jsx)(`span`,{title:t.name,className:`truncate ${l?`text-zinc-400 dark:text-zinc-600`:`text-zinc-600 dark:text-zinc-400`}`,children:t.name})}),h&&r.onOpenNative&&(0,N.jsx)(`button`,{type:`button`,disabled:u,onClick:()=>r.onOpenNative?.(c),title:`Open with the associated application`,"aria-label":`Open ${t.name} with the associated application`,className:IG,children:`↗`}),r.onRevealNative&&(0,N.jsx)(`button`,{type:`button`,disabled:u,onClick:()=>r.onRevealNative?.(c),title:`Show in the file manager`,"aria-label":`Show ${t.name} in the file manager`,className:IG,children:`⌂`}),g&&r.onRenameFile&&(0,N.jsx)(`button`,{type:`button`,disabled:u,onClick:()=>r.rename?.start(c),title:`Rename file`,"aria-label":`Rename ${t.name}`,className:IG,children:`✎`}),g&&r.onDeleteFile&&(0,N.jsx)(`button`,{type:`button`,disabled:u,onClick:()=>{window.confirm(`Delete "${t.name}" permanently?`)&&r.onDeleteFile?.(c)},title:`Delete file`,"aria-label":`Delete ${t.name}`,className:`${IG} hover:text-red-600 dark:hover:text-red-400`,children:`×`}),r.onToggleAttachPath&&(0,N.jsx)(`button`,{type:`button`,onClick:()=>r.onToggleAttachPath?.(c),title:p?`Remove this file from the prompt`:`Reference this file in the prompt`,"aria-label":`${p?`Remove`:`Reference`} ${t.name} in the prompt`,"aria-pressed":p,className:`mr-1 shrink-0 rounded px-1 font-mono text-xs hover:bg-zinc-200 group-hover:opacity-100 focus-visible:opacity-100 dark:hover:bg-zinc-700 ${p?`font-bold text-blue-600 dark:text-blue-400`:`text-zinc-400 dark:text-zinc-600 [@media(hover:hover)]:opacity-0`}`,children:`@`}),f&&(0,N.jsx)(`button`,{type:`button`,onClick:()=>(r.onSelectDiff??r.onSelectFile)(c),title:`Show uncommitted diff`,"aria-label":`Show diff of ${t.name}`,className:`mr-1 shrink-0 rounded px-1 font-mono text-xs font-bold hover:bg-zinc-200 dark:hover:bg-zinc-700 ${LG[f].className}`,children:LG[f].label})]})}function GG(e){let t=e.trim();if(t===``)return{error:`A name is required`};let n=t.endsWith(`/`),r=n?t.slice(0,-1).trim():t;return r===``?{error:`A name is required`}:r.includes(`/`)||r.includes(`\\`)?{error:`That is a path, not a name`}:r===`.`||r===`..`?{error:`"${r}" is not a name`}:{kind:n?`directory`:`file`,name:r}}function KG(e){let t=GG(e);return`error`in t?t:t.kind===`directory`?{error:`That is a folder name`}:{name:t.name}}function qG(e){let t=(0,v.useRef)(!1),[n,r]=(0,v.useState)(!1),[i,a]=(0,v.useState)([]),[o,s]=(0,v.useState)([]),[c,l]=(0,v.useState)(!1),u=e.onUploadFile?{pending:n,start:(n,i)=>{if(t.current)return;let o=Array.from(i.items??[]).filter(e=>e.kind===`file`),c=!1,l=o.length>0?o.flatMap(e=>{if(e.webkitGetAsEntry?.()?.isDirectory)return c=!0,[];let t=e.getAsFile();return t?[t]:[]}):Array.from(i.files);if(a([]),s(c?[`Folders cannot be imported here; drop files instead.`]:[]),l.length===0)return;t.current=!0,r(!0);let u=e.onUploadFile;(async()=>{try{for(let e of l)try{let t=await BV(e),r=await u(e.name,t,n);a(e=>[...e,r])}catch(t){if(s(n=>[...n,`${e.name}: ${t instanceof Error?t.message:String(t)}`]),t instanceof zV)break}}finally{t.current=!1,r(!1)}})()}}:void 0,[d,f]=(0,v.useState)(null),[p,m]=(0,v.useState)(null),[h,g]=(0,v.useState)(null),[_,y]=(0,v.useState)(null),[b,x]=(0,v.useState)(null),[S,C]=(0,v.useState)(null),w=e.onCreateFile!==void 0||e.onCreateDirectory!==void 0,T=e.createError&&h&&e.createError.path===JG(h.dir,h.name)?e.createError.message:null,E=e.created??null;(0,v.useEffect)(()=>{h!==null&&E!==null&&E===JG(h.dir,h.name)&&(f(null),g(null),m(null))},[h,E]);let D=e.fileOperation?.status===`error`&&e.fileOperation.operation===`rename_file`&&S===e.fileOperation.path?e.fileOperation.message:null;(0,v.useEffect)(()=>{let t=e.fileOperation;t?.status===`succeeded`&&t.operation===`rename_file`&&S===t.path&&(y(null),C(null),x(null))},[S,e.fileOperation]);let O=w?{openIn:d,localError:p,serverError:T,start:e=>{f(e),m(null),g(null)},cancel:()=>{f(null),m(null),g(null)},submit:(t,n)=>{let r=GG(n);if(`error`in r){m(r.error);return}m(null),g({dir:t,name:r.name});let i=JG(t,r.name);r.kind===`directory`?e.onCreateDirectory?.(i):e.onCreateFile?.(i)}}:void 0,ee=e.onRenameFile?{path:_,pending:S!==null&&e.fileOperation?.status===`pending`&&e.fileOperation.operation===`rename_file`&&e.fileOperation.path===S,localError:b,serverError:D,start:e=>{y(e),C(null),x(null)},cancel:()=>{y(null),C(null),x(null)},submit:(t,n)=>{if(n.trim()===``){y(null),C(null),x(null);return}let r=KG(n);`error`in r?x(r.error):(x(null),C(t),e.onRenameFile?.(t,r.name))}}:void 0,te=!BG(``,e.writableRoot);return(0,N.jsxs)(`div`,{className:`text-sm`,children:[u&&(0,N.jsx)(`div`,{"data-drop-directory":``,title:te?`Drop files here to import into the workspace root`:`The workspace root is read-only`,className:`mb-1 rounded border border-dashed px-2 py-1 text-xs ${te?`text-zinc-500 dark:text-zinc-400`:`text-zinc-400 dark:text-zinc-600`} ${c&&te&&!n?`bg-blue-50 ring-1 ring-blue-400 dark:bg-blue-950/40`:`border-zinc-200 dark:border-zinc-800`}`,onDragOver:e=>{Array.from(e.dataTransfer.types).includes(`Files`)&&(e.preventDefault(),e.stopPropagation(),e.dataTransfer.dropEffect=te&&!n?`copy`:`none`,l(te&&!n))},onDragLeave:e=>{e.currentTarget.contains(e.relatedTarget)||l(!1)},onDrop:e=>{Array.from(e.dataTransfer.types).includes(`Files`)&&(e.preventDefault(),e.stopPropagation(),l(!1),te&&!t.current&&u.start(``,e.dataTransfer))},children:`Workspace root`}),n&&(0,N.jsx)(`p`,{role:`status`,className:`mb-1 px-2 text-xs text-zinc-500`,children:`Importing files…`}),i.length>0&&(0,N.jsxs)(`p`,{role:`status`,className:`mb-1 break-words px-2 text-xs text-emerald-700 dark:text-emerald-400`,children:[`Imported: `,i.join(`, `)]}),o.map((e,t)=>(0,N.jsx)(`p`,{role:`alert`,className:`mb-1 break-words px-2 text-xs text-red-600 dark:text-red-400`,children:e},t)),e.fileOperation?.status===`error`&&e.fileOperation.operation!==`rename_file`&&(0,N.jsx)(`p`,{role:`alert`,className:`mb-1 rounded bg-red-50 px-2 py-1 text-xs text-red-700 dark:bg-red-950/40 dark:text-red-300`,children:e.fileOperation.message}),(O&&te||e.onRefresh)&&(0,N.jsxs)(`div`,{className:`mb-1 flex items-center`,children:[O&&te&&(0,N.jsx)(`button`,{type:`button`,onClick:()=>O.start(``),"aria-label":`New file or folder in the workspace root`,className:`rounded px-1 py-0.5 text-xs text-zinc-400 hover:bg-zinc-100 hover:text-zinc-600 dark:text-zinc-600 dark:hover:bg-zinc-800 dark:hover:text-zinc-400`,children:`+ new`}),e.onRefresh&&(0,N.jsx)(`button`,{type:`button`,onClick:e.onRefresh,title:`Refresh the file tree`,"aria-label":`Refresh the file tree`,className:`ml-auto rounded px-1 py-0.5 text-xs text-zinc-400 hover:bg-zinc-100 hover:text-zinc-600 dark:text-zinc-600 dark:hover:bg-zinc-800 dark:hover:text-zinc-400`,children:`↻`})]}),(0,N.jsx)(UG,{path:``,depth:0,...e,imports:u,...O?{creation:O}:{},...ee?{rename:ee}:{}})]})}function JG(e,t){return e===``?t:`${e}/${t}`}function YG({hidden:e,tree:t,openFile:n,writableRoot:r,gitFiles:i,attachedPaths:a,onExpand:o,onSelectDirectory:s,onRefresh:c,onSelectFile:l,onSelectDiff:u,onToggleAttachPath:d,onCreateFile:f,onCreateDirectory:p,onOpenNative:m,onRevealNative:h,onRenameFile:g,onDeleteFile:_,onMoveFile:y,onCopyFile:b,onUploadFile:x,onExternalDragEnter:S,fileOperation:C,createError:w,created:T,contentSearch:E=null,onSearchContent:D,onOpenSearchHit:O}){let ee=zU(MU),[te,k]=(0,v.useState)(!1),[ne,A]=(0,v.useState)(E?.query??``),re=e=>x!==void 0&&Array.from(e.types).includes(`Files`);return(0,v.useEffect)(()=>{t[``]===void 0&&o(``)},[]),(0,N.jsxs)(`aside`,{"aria-label":`Files`,onDragEnterCapture:e=>{re(e.dataTransfer)&&S?.()},onDragEnter:e=>{re(e.dataTransfer)&&e.stopPropagation()},onDragLeave:e=>{re(e.dataTransfer)&&e.stopPropagation()},onDragOver:e=>{re(e.dataTransfer)&&(e.preventDefault(),e.stopPropagation(),e.dataTransfer.dropEffect=`none`)},onDropCapture:e=>{re(e.dataTransfer)&&S?.()},onDrop:e=>{re(e.dataTransfer)&&(e.preventDefault(),e.stopPropagation())},style:{width:ee.width,display:e?`none`:void 0},className:`relative flex shrink-0 flex-col border-r border-zinc-200 dark:border-zinc-800`,children:[(0,N.jsxs)(`div`,{className:`flex items-center border-b border-zinc-200 px-3 py-2 text-xs font-semibold uppercase text-zinc-400 dark:border-zinc-800 dark:text-zinc-600`,children:[`Files`,D&&(0,N.jsx)(`button`,{type:`button`,onClick:()=>k(e=>!e),"aria-pressed":te,title:`Search in files`,"aria-label":`Search in files`,className:`ml-auto rounded p-0.5 normal-case hover:bg-zinc-100 hover:text-zinc-600 dark:hover:bg-zinc-800 dark:hover:text-zinc-400 ${te?`text-zinc-700 dark:text-zinc-300`:``}`,children:(0,N.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,"aria-hidden":!0,className:`h-3.5 w-3.5`,children:[(0,N.jsx)(`circle`,{cx:`11`,cy:`11`,r:`7`}),(0,N.jsx)(`path`,{d:`m20 20-3.5-3.5`})]})})]}),te&&D&&(0,N.jsx)(`div`,{className:`flex-1 overflow-auto p-2`,children:(0,N.jsx)(AG,{query:ne,onQueryChange:A,search:E,onSearch:D,onOpenHit:(e,t)=>O?.(e,t),onClose:()=>k(!1)})}),(0,N.jsx)(`div`,{className:`flex-1 overflow-auto p-2`,style:te&&D?{display:`none`}:void 0,children:(0,N.jsx)(qG,{tree:t,openFilePath:n?.path,writableRoot:r,gitFiles:i,attachedPaths:a,onExpand:o,onSelectDirectory:s,onRefresh:c,onSelectFile:l,onSelectDiff:u,onToggleAttachPath:d,onCreateFile:f,onCreateDirectory:p,onOpenNative:m,onRevealNative:h,onRenameFile:g,onDeleteFile:_,onMoveFile:y,onCopyFile:b,onUploadFile:x,fileOperation:C,createError:w,created:T})}),(0,N.jsx)(BU,{label:`Resize Files sidebar`,width:ee.width,config:MU,separatorProps:ee.separatorProps})]})}function XG({title:e,onSubmit:t}){let[n,r]=(0,v.useState)(``);return(0,N.jsx)(`div`,{className:`flex h-full items-center justify-center p-6`,children:(0,N.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),n.trim()&&t(n.trim())},className:`w-full max-w-sm rounded-xl border border-zinc-200 p-6 shadow-sm dark:border-zinc-800`,children:[(0,N.jsx)(`div`,{className:`mb-1 text-center text-3xl`,children:e??`π`}),(0,N.jsx)(`h1`,{className:`mb-4 text-center text-sm text-zinc-500 dark:text-zinc-400`,children:`This server requires an access token.`}),(0,N.jsx)(`label`,{htmlFor:`pi-outpost-token`,className:`mb-1 block text-xs font-medium text-zinc-600 dark:text-zinc-400`,children:`Access token`}),(0,N.jsx)(`input`,{id:`pi-outpost-token`,name:`token`,type:`password`,autoComplete:`off`,spellCheck:!1,value:n,onChange:e=>r(e.target.value),placeholder:`paste the token…`,className:`mb-3 w-full rounded-md border border-zinc-300 bg-white px-2 py-1.5 font-mono text-sm outline-none focus:border-zinc-500 dark:border-zinc-700 dark:bg-zinc-950 dark:focus:border-zinc-500`}),(0,N.jsx)(`button`,{type:`submit`,disabled:!n.trim(),className:`w-full rounded-md border border-emerald-300 px-2 py-1.5 text-sm text-emerald-700 hover:border-emerald-500 disabled:opacity-50 dark:border-emerald-900 dark:text-emerald-400 dark:hover:border-emerald-600`,children:`Connect`}),(0,N.jsxs)(`p`,{className:`mt-3 text-center text-xs text-zinc-400 dark:text-zinc-600`,children:[`Ask the operator for the token, or open the link containing `,(0,N.jsx)(`code`,{children:`?token=…`})]})]})})}var ZG={todo:{icon:`○`,label:`To do`,className:`text-zinc-500`},in_progress:{icon:`●`,label:`In progress`,className:`text-blue-600 dark:text-blue-400`},done:{icon:`✓`,label:`Done`,className:`text-emerald-600 dark:text-emerald-400`},blocked:{icon:`!`,label:`Blocked`,className:`text-red-600 dark:text-red-400`},needs_review:{icon:`?`,label:`Needs review`,className:`text-amber-600 dark:text-amber-400`}},QG=8;function $G(e){let t=e.uri.startsWith(`workspace:`)?e.uri.slice(10):/^[a-z][a-z0-9+.-]*:/i.test(e.uri)?null:e.uri;return t===null||t===``||/^(?:[\\/]|[a-z]:[\\/])/i.test(t)||t.replaceAll(`\\`,`/`).split(`/`).includes(`..`)?null:t}function eK({plan:e,open:t,onToggle:n,onOpenWorkspace:r,requestedTaskId:i,onTaskRequestHandled:a}){let o=(0,v.useId)(),[s,c]=(0,v.useState)(!1),[l,u]=(0,v.useState)(null),[d,f]=(0,v.useState)(null);(0,v.useEffect)(()=>{i&&(e.tasks.some(e=>e.id===i)?(u(i),f(null)):(u(null),f(i)),a?.())},[e.tasks,i,a]),(0,v.useEffect)(()=>{l!==null&&!e.tasks.some(e=>e.id===l)&&u(null)},[e,l]),(0,v.useEffect)(()=>{if(!s)return;let e=e=>{e.key===`Escape`&&c(!1)};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[s]);let p=(0,v.useMemo)(()=>{let t=new Map;for(let n of e.tasks)t.set(n.parentId,[...t.get(n.parentId)??[],n]);return t},[e.tasks]),m=(0,v.useMemo)(()=>new Map(e.tasks.map(e=>[e.id,e])),[e.tasks]),h=(0,v.useMemo)(()=>{let e=[],t=(n,r)=>{for(let i of p.get(n)??[])e.push({task:i,depth:r}),t(i.id,r+1)};return t(void 0,0),e.slice(0,QG)},[p]),g=l?m.get(l):void 0,_=e.tasks.filter(e=>e.status===`done`).length,y=(e,t=0)=>(p.get(e)??[]).flatMap(e=>{let n=ZG[e.status];return[(0,N.jsxs)(`button`,{type:`button`,role:`treeitem`,"aria-level":t+1,"aria-selected":l===e.id,onClick:()=>u(e.id),"aria-current":e.status===`in_progress`?`step`:void 0,className:`flex w-full items-start gap-2 rounded px-2 py-1.5 text-left text-sm hover:bg-zinc-100 dark:hover:bg-zinc-800 ${l===e.id?`bg-zinc-100 dark:bg-zinc-800`:``}`,style:{paddingLeft:`${.5+t*.85}rem`},children:[(0,N.jsx)(`span`,{className:`mt-px w-4 shrink-0 text-center font-semibold ${n.className}`,"aria-label":n.label,children:n.icon}),(0,N.jsx)(`span`,{className:e.status===`done`?`text-zinc-500 line-through`:`text-zinc-800 dark:text-zinc-200`,children:e.title})]},e.id),...y(e.id,t+1)]});return t?(0,N.jsxs)(`aside`,{"aria-label":`Work Plan`,className:`absolute inset-y-0 right-0 z-10 flex w-full flex-col border-l border-zinc-200 bg-white/95 shadow-lg backdrop-blur md:w-[23rem] dark:border-zinc-800 dark:bg-zinc-950/95`,children:[(0,N.jsxs)(`header`,{className:`border-b border-zinc-200 px-3 py-3 dark:border-zinc-800`,children:[(0,N.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,N.jsxs)(`div`,{className:`min-w-0`,children:[(0,N.jsx)(`div`,{className:`text-[11px] font-semibold uppercase tracking-wide text-zinc-500`,children:`Work Plan`}),(0,N.jsx)(`h2`,{className:`truncate text-sm font-semibold text-zinc-900 dark:text-zinc-100`,children:e.title})]}),(0,N.jsx)(`button`,{type:`button`,onClick:n,className:`rounded px-2 py-1 text-xs text-zinc-500 hover:bg-zinc-100 dark:hover:bg-zinc-800`,"aria-label":`Close Work Plan`,children:`×`})]}),(0,N.jsxs)(`div`,{className:`mt-2 text-xs text-zinc-500`,children:[`Progress: `,_,` / `,e.tasks.length]}),(0,N.jsx)(`div`,{className:`mt-1 h-1.5 overflow-hidden rounded-full bg-zinc-200 dark:bg-zinc-800`,"aria-hidden":!0,children:(0,N.jsx)(`div`,{className:`h-full bg-emerald-500`,style:{width:`${e.tasks.length===0?0:_/e.tasks.length*100}%`}})})]}),(0,N.jsx)(`div`,{role:`tree`,"aria-label":`Work Plan tasks`,className:`min-h-0 flex-1 overflow-y-auto p-2`,children:y(void 0)}),d&&(0,N.jsx)(`div`,{role:`status`,className:`border-t border-amber-200 bg-amber-50 p-3 text-xs text-amber-800 dark:border-amber-900 dark:bg-amber-950/30 dark:text-amber-300`,children:`That Outcome task no longer exists in the current Work Plan.`}),g&&(0,N.jsxs)(`section`,{"aria-label":`Task details`,className:`max-h-[45%] overflow-y-auto border-t border-zinc-200 p-3 text-xs dark:border-zinc-800`,children:[(0,N.jsx)(`div`,{className:`font-semibold ${ZG[g.status].className}`,children:ZG[g.status].label}),(0,N.jsx)(`h3`,{className:`mt-1 text-sm font-semibold text-zinc-900 dark:text-zinc-100`,children:g.title}),g.description&&(0,N.jsx)(`p`,{className:`mt-2 whitespace-pre-wrap text-zinc-600 dark:text-zinc-300`,children:g.description}),g.statusReason&&(0,N.jsx)(`p`,{className:`mt-2 rounded bg-zinc-100 p-2 text-zinc-700 dark:bg-zinc-900 dark:text-zinc-300`,children:g.statusReason}),g.dependsOn.length>0&&(0,N.jsxs)(`div`,{className:`mt-3`,children:[(0,N.jsx)(`span`,{className:`font-semibold`,children:`Depends on:`}),` `,g.dependsOn.map(e=>m.get(e)?.title??e).join(`, `)]}),g.resources.length>0&&(0,N.jsxs)(`div`,{className:`mt-3 space-y-1`,children:[(0,N.jsx)(`div`,{className:`font-semibold`,children:`Resources`}),g.resources.map(e=>{let t=$G(e),n=e.label??e.uri;return t===null?/^https?:/i.test(e.uri)?(0,N.jsx)(`a`,{href:e.uri,target:`_blank`,rel:`noreferrer`,className:`block truncate text-blue-600 hover:underline dark:text-blue-400`,children:n},e.uri):(0,N.jsx)(`span`,{className:`block truncate text-zinc-500`,title:`No navigator is available for this resource`,children:n},e.uri):(0,N.jsx)(`button`,{type:`button`,className:`block max-w-full truncate text-left text-blue-600 hover:underline dark:text-blue-400`,onClick:()=>r(t),children:n},e.uri)})]})]})]}):(0,N.jsxs)(`div`,{className:`absolute right-3 top-3 z-20`,onMouseEnter:()=>c(!0),onMouseLeave:()=>c(!1),onFocusCapture:()=>c(!0),onBlurCapture:()=>c(!1),children:[(0,N.jsxs)(`button`,{type:`button`,onClick:()=>{c(!1),n()},className:`rounded-md border border-zinc-300 bg-white px-2 py-1 text-xs shadow-sm dark:border-zinc-700 dark:bg-zinc-900`,"aria-label":`Open Work Plan`,"aria-describedby":o,children:[`Plan `,_,`/`,e.tasks.length]}),(0,N.jsx)(`div`,{id:o,role:`tooltip`,className:`absolute right-0 top-full w-72 pt-2 ${s?`block`:`hidden`}`,children:(0,N.jsxs)(`div`,{className:`rounded-md border border-zinc-200 bg-white p-2 shadow-lg dark:border-zinc-700 dark:bg-zinc-900`,children:[(0,N.jsx)(`ul`,{className:`space-y-1`,children:h.map(({task:e,depth:t})=>(0,N.jsxs)(`li`,{className:`flex min-w-0 items-start gap-1.5 text-xs`,style:{paddingLeft:`${t*.75}rem`},children:[(0,N.jsx)(`span`,{"aria-label":ZG[e.status].label,className:`shrink-0 font-semibold ${ZG[e.status].className}`,children:e.status===`done`?`☑`:`☐`}),(0,N.jsx)(`span`,{className:`truncate ${e.status===`done`?`text-zinc-500 line-through`:`text-zinc-800 dark:text-zinc-200`}`,children:e.title})]},e.id))}),e.tasks.length>h.length&&(0,N.jsxs)(`div`,{className:`mt-1 text-[11px] text-zinc-500`,children:[`+`,e.tasks.length-h.length,` more`]})]})})]})}var tK=Object.defineProperty,nK=Object.getOwnPropertyDescriptor,rK=(e,t)=>{for(var n in t)tK(e,n,{get:t[n],enumerable:!0})},iK=(e,t,n,r)=>{for(var i=r>1?void 0:r?nK(t,n):t,a=e.length-1,o;a>=0;a--)(o=e[a])&&(i=(r?o(t,n,i):o(i))||i);return r&&i&&tK(t,n,i),i},aK=(e,t)=>(n,r)=>t(n,r,e),oK=`Terminal input`,sK={get:()=>oK,set:e=>oK=e},cK=`Too much output to announce, navigate to rows manually to read`,lK={get:()=>cK,set:e=>cK=e};function uK(e){return e.replace(/\r?\n/g,`\r`)}function dK(e,t){return t?`\x1B[200~`+e+`\x1B[201~`:e}function fK(e,t){e.clipboardData&&e.clipboardData.setData(`text/plain`,t.selectionText),e.preventDefault()}function pK(e,t,n,r){e.stopPropagation(),e.clipboardData&&mK(e.clipboardData.getData(`text/plain`),t,n,r)}function mK(e,t,n,r){e=uK(e),e=dK(e,n.decPrivateModes.bracketedPasteMode&&r.rawOptions.ignoreBracketedPasteMode!==!0),n.triggerDataEvent(e,!0),t.value=``}function hK(e,t,n){let r=n.getBoundingClientRect(),i=e.clientX-r.left-10,a=e.clientY-r.top-10;t.style.width=`20px`,t.style.height=`20px`,t.style.left=`${i}px`,t.style.top=`${a}px`,t.style.zIndex=`1000`,t.focus()}function gK(e,t,n,r,i){hK(e,t,n),i&&r.rightClickSelect(e),t.value=r.selectionText,t.select()}function _K(e){return e>65535?(e-=65536,String.fromCharCode((e>>10)+55296)+String.fromCharCode(e%1024+56320)):String.fromCharCode(e)}function vK(e,t=0,n=e.length){let r=``;for(let i=t;i<n;++i){let t=e[i];t>65535?(t-=65536,r+=String.fromCharCode((t>>10)+55296)+String.fromCharCode(t%1024+56320)):r+=String.fromCharCode(t)}return r}var yK=class{constructor(){this._interim=0}clear(){this._interim=0}decode(e,t){let n=e.length;if(!n)return 0;let r=0,i=0;if(this._interim){let n=e.charCodeAt(i++);56320<=n&&n<=57343?t[r++]=(this._interim-55296)*1024+n-56320+65536:(t[r++]=this._interim,t[r++]=n),this._interim=0}for(let a=i;a<n;++a){let i=e.charCodeAt(a);if(55296<=i&&i<=56319){if(++a>=n)return this._interim=i,r;let o=e.charCodeAt(a);56320<=o&&o<=57343?t[r++]=(i-55296)*1024+o-56320+65536:(t[r++]=i,t[r++]=o)}else i!==65279&&(t[r++]=i)}return r}},bK=class{constructor(){this.interim=new Uint8Array(3)}clear(){this.interim.fill(0)}decode(e,t){let n=e.length;if(!n)return 0;let r=0,i,a,o,s,c=0,l=0;if(this.interim[0]){let i=!1,a=this.interim[0];a&=(a&224)==192?31:(a&240)==224?15:7;let o=0,s;for(;(s=this.interim[++o]&63)&&o<4;)a<<=6,a|=s;let c=(this.interim[0]&224)==192?2:(this.interim[0]&240)==224?3:4,u=c-o;for(;l<u;){if(l>=n)return 0;if(s=e[l++],(s&192)!=128){l--,i=!0;break}this.interim[o++]=s,a<<=6,a|=s&63}i||(c===2?a<128?l--:t[r++]=a:c===3?a<2048||a>=55296&&a<=57343||a===65279||(t[r++]=a):a<65536||a>1114111||(t[r++]=a)),this.interim.fill(0)}let u=n-4,d=l;for(;d<n;){for(;d<u&&!((i=e[d])&128)&&!((a=e[d+1])&128)&&!((o=e[d+2])&128)&&!((s=e[d+3])&128);)t[r++]=i,t[r++]=a,t[r++]=o,t[r++]=s,d+=4;if(i=e[d++],i<128)t[r++]=i;else if((i&224)==192){if(d>=n)return this.interim[0]=i,r;if(a=e[d++],(a&192)!=128||(c=(i&31)<<6|a&63,c<128)){d--;continue}t[r++]=c}else if((i&240)==224){if(d>=n)return this.interim[0]=i,r;if(a=e[d++],(a&192)!=128){d--;continue}if(d>=n)return this.interim[0]=i,this.interim[1]=a,r;if(o=e[d++],(o&192)!=128){d--;continue}if(c=(i&15)<<12|(a&63)<<6|o&63,c<2048||c>=55296&&c<=57343||c===65279)continue;t[r++]=c}else if((i&248)==240){if(d>=n)return this.interim[0]=i,r;if(a=e[d++],(a&192)!=128){d--;continue}if(d>=n)return this.interim[0]=i,this.interim[1]=a,r;if(o=e[d++],(o&192)!=128){d--;continue}if(d>=n)return this.interim[0]=i,this.interim[1]=a,this.interim[2]=o,r;if(s=e[d++],(s&192)!=128){d--;continue}if(c=(i&7)<<18|(a&63)<<12|(o&63)<<6|s&63,c<65536||c>1114111)continue;t[r++]=c}}return r}},xK=``,SK=` `,CK=class e{constructor(){this.fg=0,this.bg=0,this.extended=new wK}static toColorRGB(e){return[e>>>16&255,e>>>8&255,e&255]}static fromColorRGB(e){return(e[0]&255)<<16|(e[1]&255)<<8|e[2]&255}clone(){let t=new e;return t.fg=this.fg,t.bg=this.bg,t.extended=this.extended.clone(),t}isInverse(){return this.fg&67108864}isBold(){return this.fg&134217728}isUnderline(){return this.hasExtendedAttrs()&&this.extended.underlineStyle!==0?1:this.fg&268435456}isBlink(){return this.fg&536870912}isInvisible(){return this.fg&1073741824}isItalic(){return this.bg&67108864}isDim(){return this.bg&134217728}isStrikethrough(){return this.fg&2147483648}isProtected(){return this.bg&536870912}isOverline(){return this.bg&1073741824}getFgColorMode(){return this.fg&50331648}getBgColorMode(){return this.bg&50331648}isFgRGB(){return(this.fg&50331648)==50331648}isBgRGB(){return(this.bg&50331648)==50331648}isFgPalette(){return(this.fg&50331648)==16777216||(this.fg&50331648)==33554432}isBgPalette(){return(this.bg&50331648)==16777216||(this.bg&50331648)==33554432}isFgDefault(){return!(this.fg&50331648)}isBgDefault(){return!(this.bg&50331648)}isAttributeDefault(){return this.fg===0&&this.bg===0}getFgColor(){switch(this.fg&50331648){case 16777216:case 33554432:return this.fg&255;case 50331648:return this.fg&16777215;default:return-1}}getBgColor(){switch(this.bg&50331648){case 16777216:case 33554432:return this.bg&255;case 50331648:return this.bg&16777215;default:return-1}}hasExtendedAttrs(){return this.bg&268435456}updateExtended(){this.extended.isEmpty()?this.bg&=-268435457:this.bg|=268435456}getUnderlineColor(){if(this.bg&268435456&&~this.extended.underlineColor)switch(this.extended.underlineColor&50331648){case 16777216:case 33554432:return this.extended.underlineColor&255;case 50331648:return this.extended.underlineColor&16777215;default:return this.getFgColor()}return this.getFgColor()}getUnderlineColorMode(){return this.bg&268435456&&~this.extended.underlineColor?this.extended.underlineColor&50331648:this.getFgColorMode()}isUnderlineColorRGB(){return this.bg&268435456&&~this.extended.underlineColor?(this.extended.underlineColor&50331648)==50331648:this.isFgRGB()}isUnderlineColorPalette(){return this.bg&268435456&&~this.extended.underlineColor?(this.extended.underlineColor&50331648)==16777216||(this.extended.underlineColor&50331648)==33554432:this.isFgPalette()}isUnderlineColorDefault(){return this.bg&268435456&&~this.extended.underlineColor?!(this.extended.underlineColor&50331648):this.isFgDefault()}getUnderlineStyle(){return this.fg&268435456?this.bg&268435456?this.extended.underlineStyle:1:0}getUnderlineVariantOffset(){return this.extended.underlineVariantOffset}},wK=class e{constructor(e=0,t=0){this._ext=0,this._urlId=0,this._ext=e,this._urlId=t}get ext(){return this._urlId?this._ext&-469762049|this.underlineStyle<<26:this._ext}set ext(e){this._ext=e}get underlineStyle(){return this._urlId?5:(this._ext&469762048)>>26}set underlineStyle(e){this._ext&=-469762049,this._ext|=e<<26&469762048}get underlineColor(){return this._ext&67108863}set underlineColor(e){this._ext&=-67108864,this._ext|=e&67108863}get urlId(){return this._urlId}set urlId(e){this._urlId=e}get underlineVariantOffset(){let e=(this._ext&3758096384)>>29;return e<0?e^4294967288:e}set underlineVariantOffset(e){this._ext&=536870911,this._ext|=e<<29&3758096384}clone(){return new e(this._ext,this._urlId)}isEmpty(){return this.underlineStyle===0&&this._urlId===0}},TK=class e extends CK{constructor(){super(...arguments),this.content=0,this.fg=0,this.bg=0,this.extended=new wK,this.combinedData=``}static fromCharData(t){let n=new e;return n.setFromCharData(t),n}isCombined(){return this.content&2097152}getWidth(){return this.content>>22}getChars(){return this.content&2097152?this.combinedData:this.content&2097151?_K(this.content&2097151):``}getCode(){return this.isCombined()?this.combinedData.charCodeAt(this.combinedData.length-1):this.content&2097151}setFromCharData(e){this.fg=e[0],this.bg=0;let t=!1;if(e[1].length>2)t=!0;else if(e[1].length===2){let n=e[1].charCodeAt(0);if(55296<=n&&n<=56319){let r=e[1].charCodeAt(1);56320<=r&&r<=57343?this.content=(n-55296)*1024+r-56320+65536|e[2]<<22:t=!0}else t=!0}else this.content=e[1].charCodeAt(0)|e[2]<<22;t&&(this.combinedData=e[1],this.content=2097152|e[2]<<22)}getAsCharData(){return[this.fg,this.getChars(),this.getWidth(),this.getCode()]}},EK=`di$target`,DK=`di$dependencies`,OK=new Map;function kK(e){return e[DK]||[]}function AK(e){if(OK.has(e))return OK.get(e);let t=function(e,n,r){if(arguments.length!==3)throw Error(`@IServiceName-decorator can only be used to decorate a parameter`);jK(t,e,r)};return t._id=e,OK.set(e,t),t}function jK(e,t,n){t[EK]===t?t[DK].push({id:e,index:n}):(t[DK]=[{id:e,index:n}],t[EK]=t)}var MK=AK(`BufferService`),NK=AK(`CoreMouseService`),PK=AK(`CoreService`),FK=AK(`CharsetService`),IK=AK(`InstantiationService`),LK=AK(`LogService`),RK=AK(`OptionsService`),zK=AK(`OscLinkService`),BK=AK(`UnicodeService`),VK=AK(`DecorationService`),HK=class{constructor(e,t,n){this._bufferService=e,this._optionsService=t,this._oscLinkService=n}provideLinks(e,t){let n=this._bufferService.buffer.lines.get(e-1);if(!n){t(void 0);return}let r=[],i=this._optionsService.rawOptions.linkHandler,a=new TK,o=n.getTrimmedLength(),s=-1,c=-1,l=!1;for(let t=0;t<o;t++)if(c!==-1||n.hasContent(t)){if(n.loadCell(t,a),a.hasExtendedAttrs()&&a.extended.urlId){if(c===-1){c=t,s=a.extended.urlId;continue}l=a.extended.urlId!==s}else c!==-1&&(l=!0);if(l||c!==-1&&t===o-1){let n=this._oscLinkService.getLinkData(s)?.uri;if(n){let a={start:{x:c+1,y:e},end:{x:t+ +(!l&&t===o-1),y:e}},s=!1;if(!i?.allowNonHttpProtocols)try{let e=new URL(n);[`http:`,`https:`].includes(e.protocol)||(s=!0)}catch{s=!0}s||r.push({text:n,range:a,activate:(e,t)=>i?i.activate(e,t,a):UK(e,t),hover:(e,t)=>i?.hover?.(e,t,a),leave:(e,t)=>i?.leave?.(e,t,a)})}l=!1,a.hasExtendedAttrs()&&a.extended.urlId?(c=t,s=a.extended.urlId):(c=-1,s=-1)}}t(r)}};HK=iK([aK(0,MK),aK(1,RK),aK(2,zK)],HK);function UK(e,t){if(confirm(`Do you want to navigate to ${t}?
1511
+ `,TW=[[`draw.io / diagrams.net`,`Diagram viewer and editor`],[`GrapesJS`,`Poster editor`],[`React`,`User interface`],[`CodeMirror · xterm.js · node-pty`,`Code editor and terminal`],[`PDF.js · docx`,`Document tools`],[`Mermaid · KaTeX`,`Diagrams and mathematical notation`]],EW=[{name:`pi-outpost`,license:`MIT`,text:wW},...CW];function DW(){let[e,t]=(0,v.useState)(!1),n=(0,v.useRef)(null);return(0,v.useLayoutEffect)(()=>{n.current?.focus({preventScroll:!0});let e=n.current?.closest(`.overflow-y-auto`);e&&(e.scrollTop=0)},[e]),e?(0,N.jsxs)(`div`,{className:`text-zinc-700 dark:text-zinc-300`,children:[(0,N.jsx)(`button`,{type:`button`,onClick:()=>t(!1),className:`mb-3 text-xs text-zinc-500 hover:underline dark:text-zinc-400`,children:`← Back to credits`}),(0,N.jsx)(`h3`,{ref:n,tabIndex:-1,className:`text-sm font-semibold outline-none`,children:`Third-party notices`}),(0,N.jsx)(`p`,{className:`mt-2 text-xs text-zinc-500 dark:text-zinc-400`,children:`License texts and attributions for pi-outpost and the components acknowledged here.`}),EW.map(e=>(0,N.jsxs)(`section`,{className:`mt-5 border-t border-zinc-200 pt-3 dark:border-zinc-700`,children:[(0,N.jsxs)(`h4`,{className:`text-sm font-semibold`,children:[e.name,` `,(0,N.jsxs)(`span`,{className:`font-normal text-zinc-500 dark:text-zinc-400`,children:[`· `,e.license]})]}),(0,N.jsx)(`pre`,{className:`mt-2 whitespace-pre-wrap break-words font-mono text-[11px] leading-relaxed`,children:e.text})]},e.name))]}):(0,N.jsxs)(`div`,{className:`text-sm text-zinc-700 dark:text-zinc-300`,children:[(0,N.jsxs)(`section`,{className:`pb-5`,children:[(0,N.jsx)(`h3`,{ref:n,tabIndex:-1,className:`text-xl font-semibold tracking-tight outline-none`,children:`pi-outpost`}),(0,N.jsx)(`p`,{className:`mt-1 text-xs text-zinc-500 dark:text-zinc-400`,children:`Created by Laurent Francoise · MIT license`}),(0,N.jsxs)(`a`,{className:`mt-3 inline-flex items-center gap-2 text-xs underline underline-offset-4`,href:`https://laurentftech.github.io/pi-outpost/`,target:`_blank`,rel:`noopener noreferrer`,children:[`Project website `,(0,N.jsx)(`span`,{"aria-hidden":`true`,children:`↗`})]})]}),(0,N.jsxs)(`section`,{className:`border-t border-zinc-200 pt-4 dark:border-zinc-700`,children:[(0,N.jsx)(`h3`,{className:`text-xs font-semibold uppercase tracking-wider text-zinc-500 dark:text-zinc-400`,children:`Open-source acknowledgements`}),(0,N.jsx)(`p`,{className:`mt-2 text-xs text-zinc-500 dark:text-zinc-400`,children:`Thanks to the authors and contributors of these projects.`}),(0,N.jsx)(`dl`,{className:`mt-3 space-y-3`,children:TW.map(([e,t])=>(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`dt`,{className:`text-xs font-medium`,children:e}),(0,N.jsx)(`dd`,{className:`mt-0.5 text-xs text-zinc-500 dark:text-zinc-400`,children:t})]},e))}),(0,N.jsxs)(`button`,{type:`button`,onClick:()=>t(!0),className:`mt-4 flex w-full items-center justify-between rounded-md border border-zinc-300 px-3 py-2 text-xs hover:bg-zinc-100 dark:border-zinc-700 dark:hover:bg-zinc-800`,children:[`Third-party notices `,(0,N.jsx)(`span`,{"aria-hidden":`true`,children:`→`})]})]})]})}function OW(e){if(e.installed===void 0)return`not installed`;if(e.restartNeeded)return`${e.installed} installed — restart to use it`;if(e.pinned!==void 0)return`${e.installed}, pinned`;let t=e.check;if(!t)return e.installed;switch(t.state){case`checking`:return`${e.installed}, checking…`;case`newer`:return`${e.installed} — ${t.latest} available`;case`current`:return`${e.installed}, up to date`;case`failed`:return`${e.installed}, not checked: ${t.reason}`;case`off`:return`${e.installed}, not checked: ${t.reason}`}}function kW({packages:e,update:t,locked:n,onCheck:r,onUpdate:i}){let[a,o]=(0,v.useState)(null);if(e===null||e.length===0)return null;let s=t?.status===`pending`?t.source:null;return(0,N.jsxs)(`div`,{className:`mt-3`,"data-testid":`pi-packages`,children:[(0,N.jsxs)(`div`,{className:`mb-1 flex items-center justify-between`,children:[(0,N.jsx)(`span`,{className:`text-xs font-medium text-zinc-600 dark:text-zinc-400`,children:`Packages`}),(0,N.jsx)(`button`,{type:`button`,onClick:r,className:`text-xs text-zinc-500 underline hover:text-zinc-800 dark:hover:text-zinc-200`,children:`check for updates`})]}),(0,N.jsx)(`ul`,{className:`space-y-1`,children:e.map(e=>{let r=e.check?.state===`newer`&&!e.restartNeeded?e.check.latest:void 0;return(0,N.jsxs)(`li`,{"data-testid":`pi-package`,className:`rounded bg-zinc-50 px-2 py-1 text-xs dark:bg-zinc-800`,children:[(0,N.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,N.jsx)(`span`,{className:`min-w-0 truncate font-mono text-zinc-700 dark:text-zinc-300`,title:e.source,children:e.name}),r&&!n&&a!==e.source&&(0,N.jsx)(`button`,{type:`button`,disabled:s!==null,onClick:()=>o(e.source),className:`shrink-0 rounded border border-zinc-300 px-1.5 py-0.5 text-zinc-700 hover:bg-zinc-100 disabled:opacity-50 dark:border-zinc-600 dark:text-zinc-200 dark:hover:bg-zinc-700`,children:s===e.source?`updating…`:`Update`})]}),(0,N.jsx)(`div`,{className:`line-clamp-2 text-zinc-500 dark:text-zinc-400`,"data-testid":`pi-package-status`,title:OW(e),children:OW(e)}),r&&a===e.source&&(0,N.jsxs)(`div`,{className:`mt-1 rounded border border-amber-300 bg-amber-50 p-2 text-amber-900 dark:border-amber-700 dark:bg-amber-950/40 dark:text-amber-200`,"data-testid":`pi-package-confirm`,children:[(0,N.jsxs)(`p`,{children:[`This replaces code that runs with the agent's privileges: `,e.name,` `,e.installed,` → `,r,`. It takes effect when pi-outpost restarts.`]}),(0,N.jsxs)(`div`,{className:`mt-1 flex gap-2`,children:[(0,N.jsxs)(`button`,{type:`button`,onClick:()=>{o(null),i(e.source)},className:`rounded bg-amber-600 px-2 py-0.5 text-white hover:bg-amber-700`,children:[`Install `,r]}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>o(null),className:`rounded px-2 py-0.5 hover:bg-amber-100 dark:hover:bg-amber-900/40`,children:`Cancel`})]})]}),t&&t.status!==`pending`&&t.source===e.source&&(0,N.jsx)(`p`,{"data-testid":`pi-package-result`,className:`mt-1 ${t.status===`installed`?`text-emerald-700 dark:text-emerald-400`:`text-amber-700 dark:text-amber-400`}`,children:t.message})]},e.source)})})]})}function AW({reasons:e,canRestart:t,restarting:n,onRestart:r}){let[i,a]=(0,v.useState)(!1);return e.length===0?null:(0,N.jsxs)(`div`,{className:`mt-3 rounded border border-sky-200 bg-sky-50 p-2 text-xs text-sky-900 dark:border-sky-900 dark:bg-sky-950/40 dark:text-sky-200`,"data-testid":`restart-needed`,children:[(0,N.jsxs)(`p`,{children:[`Installed and waiting on a restart to run: `,e.join(`, `),`.`]}),t?n?(0,N.jsx)(`p`,{className:`mt-1`,children:`Restarting pi-outpost…`}):i?(0,N.jsxs)(`div`,{className:`mt-1`,children:[(0,N.jsx)(`p`,{children:`pi-outpost stops and starts again in the same terminal. Every open window reconnects by itself, and conversations are kept.`}),(0,N.jsxs)(`div`,{className:`mt-1 flex gap-2`,children:[(0,N.jsx)(`button`,{type:`button`,onClick:()=>{a(!1),r()},className:`rounded bg-sky-700 px-2 py-0.5 text-white hover:bg-sky-800`,children:`Restart now`}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>a(!1),className:`rounded px-2 py-0.5 hover:bg-sky-100 dark:hover:bg-sky-900/50`,children:`Cancel`})]})]}):(0,N.jsx)(`button`,{type:`button`,onClick:()=>a(!0),className:`mt-1 rounded border border-sky-300 px-2 py-0.5 hover:bg-sky-100 dark:border-sky-700 dark:hover:bg-sky-900/50`,children:`Restart pi-outpost`}):null]})}var jW=30,MW={display:`-webkit-box`,WebkitLineClamp:2,WebkitBoxOrient:`vertical`,overflow:`hidden`};function NW({skills:e,groups:t,enabled:n,onChange:r,disabled:i=!1,bound:a}){let[o,s]=(0,v.useState)(()=>e.length>40?new Set(e.filter(e=>n.has(e.relativePath)).map(e=>e.group)):new Set(t.map(e=>e.path))),[c,l]=(0,v.useState)(``),[u,d]=(0,v.useState)(!1),f=c.trim().toLocaleLowerCase(),p=f!==``||u,m=e=>(!u||n.has(e.relativePath))&&(!f||`${e.name} ${e.relativePath} ${e.description??``}`.toLocaleLowerCase().includes(f)),h=new Map;for(let t of e)h.set(t.group,[...h.get(t.group)??[],t]);let g=e.filter(e=>n.has(e.relativePath)).length,_=p?e.filter(m).length:e.length,y=(e,t)=>{let i=new Set(n);for(let n of e)t?i.add(n.relativePath):i.delete(n.relativePath);r(i)},b=e=>{let t=new Set(n);t.has(e)?t.delete(e):t.add(e),r(t)},x=e=>s(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n});return(0,N.jsxs)(`section`,{className:`rounded-xl border border-zinc-200 p-4 dark:border-zinc-800`,"aria-label":`Collection skills`,children:[(0,N.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,N.jsxs)(`h3`,{className:`text-sm font-semibold text-zinc-800 dark:text-zinc-200`,children:[`Skills `,(0,N.jsxs)(`span`,{className:`font-normal text-zinc-500`,children:[`· `,g,` of `,e.length,` on`]})]}),(0,N.jsxs)(`div`,{className:`flex gap-2`,children:[(0,N.jsx)(`button`,{type:`button`,disabled:i||g===e.length,onClick:()=>y(e,!0),className:`rounded-md border px-2.5 py-1 text-xs disabled:opacity-50`,children:`All on`}),(0,N.jsx)(`button`,{type:`button`,disabled:i||g===0,onClick:()=>y(e,!1),className:`rounded-md border px-2.5 py-1 text-xs disabled:opacity-50`,children:`All off`})]})]}),a?(0,N.jsx)(`p`,{className:`mt-2 rounded border border-amber-200 bg-amber-50 p-2 text-xs text-amber-800`,children:a.kind===`count`?`This repository holds more skills than the ${a.limit} listed here.`:`Folders deeper than ${a.limit} levels were not searched for skills.`}):null,e.length>0?(0,N.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-2`,children:[(0,N.jsx)(`input`,{type:`search`,"aria-label":`Search skills`,placeholder:`Search skills by name or folder`,value:c,onChange:e=>l(e.target.value),className:`min-w-0 flex-1 rounded-md border bg-transparent px-2.5 py-1 text-xs`}),(0,N.jsxs)(`button`,{type:`button`,"aria-pressed":u,onClick:()=>d(e=>!e),className:`rounded-md px-2.5 py-1 text-xs ${u?`bg-zinc-900 text-white dark:bg-zinc-100 dark:text-zinc-900`:`border`}`,children:[`Only on (`,g,`)`]})]}):null,!p&&g>0&&g<=jW?(0,N.jsxs)(`div`,{role:`region`,"aria-label":`Skills that are on`,className:`mt-3 rounded-lg border border-emerald-200 bg-emerald-50/60 p-2 dark:border-emerald-900 dark:bg-emerald-950/30`,children:[(0,N.jsx)(`p`,{className:`px-1 text-[11px] font-medium text-emerald-800 dark:text-emerald-300`,children:`Turned on`}),(0,N.jsx)(`ul`,{className:`mt-1 space-y-1`,children:e.filter(e=>n.has(e.relativePath)).map(e=>(0,N.jsxs)(`li`,{className:`flex items-start justify-between gap-2 px-1`,children:[(0,N.jsxs)(`span`,{className:`min-w-0 text-xs`,children:[(0,N.jsx)(`span`,{className:`font-medium text-zinc-800 dark:text-zinc-100`,children:e.name}),` `,(0,N.jsx)(`span`,{className:`font-mono text-[11px] text-zinc-500`,children:e.group||`(repository root)`}),(0,N.jsx)(PW,{skill:e,checked:!0})]}),(0,N.jsx)(`button`,{type:`button`,"aria-label":`Turn off ${e.name} (${e.relativePath})`,disabled:i,onClick:()=>b(e.relativePath),className:`shrink-0 rounded border bg-white px-2 py-0.5 text-[11px] disabled:opacity-50 dark:bg-zinc-900`,children:`Turn off`})]},e.relativePath))})]}):null,e.length===0?(0,N.jsx)(`p`,{className:`mt-4 text-xs text-zinc-400`,children:`This repository holds no skills.`}):null,p&&_===0?(0,N.jsx)(`p`,{className:`mt-4 text-xs text-zinc-400`,children:u&&!f?`No skill is on.`:`No skill matches.`}):null,(0,N.jsx)(`ul`,{className:`mt-3 space-y-2`,children:t.map(e=>{let t=h.get(e.path)??[],r=p?t.filter(m):t;if(p&&r.length===0)return null;let a=r.filter(e=>n.has(e.relativePath)).length,s=p||o.has(e.path);return(0,N.jsxs)(`li`,{className:`rounded-lg border border-zinc-100 dark:border-zinc-800`,children:[(0,N.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-3 py-2`,children:[(0,N.jsxs)(`button`,{type:`button`,"aria-expanded":s,onClick:()=>x(e.path),className:`flex min-w-0 flex-1 items-center gap-2 text-left`,children:[(0,N.jsx)(`span`,{"aria-hidden":`true`,className:`text-xs text-zinc-400`,children:s?`▾`:`▸`}),(0,N.jsx)(`span`,{className:`truncate font-mono text-xs font-medium text-zinc-700 dark:text-zinc-200`,children:e.label}),(0,N.jsxs)(`span`,{className:`shrink-0 text-[11px] text-zinc-500`,children:[a,`/`,r.length,` on`]})]}),(0,N.jsxs)(`div`,{className:`flex shrink-0 gap-1`,children:[(0,N.jsx)(`button`,{type:`button`,"aria-label":`All on in ${e.label}`,disabled:i||a===r.length,onClick:()=>y(r,!0),className:`rounded border px-2 py-0.5 text-[11px] disabled:opacity-50`,children:`All on`}),(0,N.jsx)(`button`,{type:`button`,"aria-label":`All off in ${e.label}`,disabled:i||a===0,onClick:()=>y(r,!1),className:`rounded border px-2 py-0.5 text-[11px] disabled:opacity-50`,children:`All off`})]})]}),s?(0,N.jsx)(`ul`,{className:`space-y-1 border-t border-zinc-100 px-3 py-2 dark:border-zinc-800`,children:r.map(e=>{let t=n.has(e.relativePath);return(0,N.jsx)(`li`,{children:(0,N.jsxs)(`label`,{className:`flex items-start gap-2 rounded px-1 py-1 ${i?`opacity-60`:`cursor-pointer hover:bg-zinc-50 dark:hover:bg-zinc-800/60`}`,children:[(0,N.jsx)(`input`,{type:`checkbox`,role:`switch`,"aria-checked":t,"aria-label":`${e.name} (${e.relativePath})`,checked:t,disabled:i,onChange:()=>b(e.relativePath),className:`mt-0.5`}),(0,N.jsxs)(`span`,{className:`min-w-0`,children:[(0,N.jsx)(`span`,{className:`block truncate text-sm text-zinc-800 dark:text-zinc-100`,children:e.name}),e.description?(0,N.jsx)(`span`,{title:e.description,style:MW,className:`text-[11px] text-zinc-500`,children:e.description}):null,(0,N.jsx)(PW,{skill:e,checked:t})]})]})},e.relativePath)})}):null]},e.path)})})]})}function PW({skill:e,checked:t}){return t===(e.state!==`off`)?e.state===`on-loaded`?(0,N.jsx)(`span`,{className:`block text-[11px] text-emerald-700 dark:text-emerald-400`,children:`Loaded`}):e.state===`on-not-loaded`?(0,N.jsxs)(`span`,{className:`block text-[11px] text-amber-700 dark:text-amber-400`,children:[`Not loaded — `,e.reason]}):e.state===`on-missing`?(0,N.jsxs)(`span`,{className:`block text-[11px] text-rose-700 dark:text-rose-400`,children:[`Missing — `,e.reason]}):null:(0,N.jsx)(`span`,{className:`block text-[11px] font-medium text-sky-700 dark:text-sky-300`,children:t?`Pending: on`:`Pending: off`})}function FW(e,t){return[...new Set(e.map(e=>e.group))].sort().map(e=>({path:e,label:e||t}))}function IW(e){return e.skills.filter(e=>e.state!==`off`).map(e=>e.relativePath)}function LW(e,t){let n=new Set(e),r=new Set(t);return n.size===r.size&&[...n].every(e=>r.has(e))}function RW(e,t){if(t.status===`loading`)return`Removing ${e}…`;if(t.status===`error`)return t.message??`Could not remove ${e}`;let n=t.result;return n?n.status===`removed`?`Removed ${e} and deleted ${n.path}.`:n.status===`removed-files-kept`?`Removed ${e}. ${n.reason??`Its files were kept`} (${n.path}).`:`Removed ${e}, but not every file could be deleted${n.reason?` — ${n.reason}`:``}. What remains is at ${n.path}.`:`Removed ${e}.`}var zW={unchecked:`Not checked`,checking:`Checking…`,current:`Up to date`,updateable:`Update available`,dirty:`Local changes`,detached:`Detached HEAD`,ahead:`Local branch ahead`,diverged:`Histories diverged`,"no-upstream":`No upstream`,locked:`Locked`,busy:`Workspace busy`,unavailable:`Unavailable`,failed:`Check failed`};function BW(e){if(!e)return[];let t=new Map(e.resources.map(e=>[e.id,e])),n=new Set(e.repositories.flatMap(e=>e.resourceIds)),r=e.repositories.map(e=>({id:e.id,name:e.name,path:e.path,repository:e,resources:e.resourceIds.flatMap(e=>t.get(e)?[t.get(e)]:[])})),i=e.resources.filter(e=>!n.has(e.id)),a=i.filter(e=>e.unavailableReason),o=i.filter(e=>!e.unavailableReason);return o.length&&r.push({id:`local`,name:`Local and built in`,reason:`Not backed by an updateable Git repository`,resources:o}),a.length&&r.push({id:`unavailable`,name:`Provenance unavailable`,reason:`The active runtime did not report enough filesystem provenance`,resources:a}),r}function VW(e){let t=e.length;for(;t>0&&(e[t-1]===`/`||e[t-1]===`\\`);)--t;return t===e.length?e:e.slice(0,t)}function HW(e){let t=VW(e),n=Math.max(t.lastIndexOf(`/`),t.lastIndexOf(`\\`));return n<=0?`/`:t.slice(0,n)}function UW(e,t){let n=VW(t),r=Math.max(n.lastIndexOf(`/`),n.lastIndexOf(`\\`)),i=r>=0?n.slice(r+1):n;return`${VW(e)}/${i||`agent-resources`}`}function WW({kind:e,resources:t,removalLocked:n=!1,onRemove:r}){return(0,N.jsxs)(`section`,{className:`rounded-xl border border-zinc-200 p-4 dark:border-zinc-800`,children:[(0,N.jsxs)(`h3`,{className:`flex items-center justify-between text-sm font-semibold capitalize text-zinc-800 dark:text-zinc-200`,children:[(0,N.jsxs)(`span`,{children:[e,`s`]}),(0,N.jsx)(`span`,{className:`text-xs font-normal text-zinc-400`,children:t.length})]}),t.length===0?(0,N.jsx)(`p`,{className:`mt-4 text-xs text-zinc-400`,children:`None in this group`}):(0,N.jsx)(`ul`,{className:`mt-3 space-y-2`,children:t.map(e=>(0,N.jsxs)(`li`,{className:`rounded-lg bg-zinc-50 px-3 py-2 dark:bg-zinc-800/70`,children:[(0,N.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,N.jsx)(`p`,{className:`truncate text-sm font-medium text-zinc-700 dark:text-zinc-200`,children:e.name}),e.userRoot&&!n?(0,N.jsx)(`button`,{type:`button`,"aria-label":`Remove ${e.userRoot}`,onClick:()=>r(e),className:`text-xs text-zinc-500 hover:text-red-600`,children:`Remove`}):null]}),(0,N.jsx)(`p`,{className:`mt-0.5 truncate font-mono text-[11px] text-zinc-400`,title:e.path,children:e.path??e.unavailableReason??`Path unavailable`})]},e.id))})]})}function GW({preview:e,busy:t,error:n,onApply:r,onCancel:i}){let[a,o]=(0,v.useState)(()=>new Set(e.roots.filter(e=>!e.locked).map(e=>`${e.kind}:${e.path}`))),[s,c]=(0,v.useState)(!1),[l,u]=(0,v.useState)(()=>new Set),d=e.mode===`collection`,f=(0,v.useMemo)(()=>e.skills.map(e=>({...e,state:`off`})),[e.skills]),p=(0,v.useMemo)(()=>FW(e.skills,e.repositoryName),[e.skills,e.repositoryName]),m=e.roots.filter(e=>e.kind===`extension`&&a.has(`extension:${e.path}`)),h=m.length>0&&!s,g=t||!d&&a.size===0||h,_=()=>{let t=m.map(e=>e.path);d?r([],t,[...l]):r(e.roots.filter(e=>e.kind===`skill`&&a.has(`skill:${e.path}`)).map(e=>e.path),t)},y=e=>{c(!1),o(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return(0,N.jsxs)(`div`,{className:`space-y-3`,"data-testid":`resource-preview`,children:[(0,N.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,N.jsxs)(`div`,{className:`min-w-0`,children:[(0,N.jsx)(`h3`,{className:`truncate text-xl font-semibold text-zinc-900 dark:text-zinc-100`,children:e.repositoryName}),(0,N.jsx)(`p`,{className:`mt-0.5 truncate font-mono text-[11px] text-zinc-500`,title:e.repositoryPath,children:e.repositoryPath})]}),(0,N.jsxs)(`div`,{className:`flex shrink-0 gap-2`,children:[(0,N.jsx)(`button`,{type:`button`,onClick:i,className:`rounded-md border px-3 py-1.5 text-xs`,children:`Cancel`}),(0,N.jsx)(`button`,{type:`button`,disabled:g,onClick:_,className:`rounded-md bg-zinc-900 px-3 py-1.5 text-xs font-medium text-white disabled:opacity-50 dark:bg-zinc-100 dark:text-zinc-900`,children:t?`Saving…`:`Save`})]})]}),h?(0,N.jsx)(`p`,{className:`text-xs text-amber-700`,children:`Confirm the extension warning below to save.`}):null,n?(0,N.jsx)(`p`,{role:`alert`,className:`text-xs text-red-600`,children:n}):null,d?(0,N.jsx)(NW,{skills:f,groups:p,enabled:l,onChange:u,disabled:t,...e.bound?{bound:e.bound}:{}}):null,e.roots.map(e=>{let t=`${e.kind}:${e.path}`;return(0,N.jsxs)(`label`,{className:`flex items-start gap-2 rounded border p-2 ${e.locked?`opacity-50`:`cursor-pointer`}`,children:[(0,N.jsx)(`input`,{type:`checkbox`,checked:a.has(t),disabled:e.locked,onChange:()=>y(t)}),(0,N.jsxs)(`span`,{children:[(0,N.jsxs)(`span`,{className:`block text-sm`,children:[e.name,` · `,e.kind]}),(0,N.jsx)(`span`,{className:`font-mono text-[11px] text-zinc-500`,children:e.path}),e.locked?(0,N.jsx)(`span`,{className:`block text-xs text-amber-700`,children:`Extension paths are locked`}):null]})]},t)}),m.length>0?(0,N.jsxs)(`label`,{className:`flex gap-2 rounded-md border border-amber-300 bg-amber-50 p-3 text-xs text-amber-900`,children:[(0,N.jsx)(`input`,{type:`checkbox`,checked:s,onChange:e=>c(e.target.checked)}),(0,N.jsx)(`span`,{children:`Extensions execute code with the agent's privileges. I trust the selected extension roots in this repository.`})]}):null]})}function KW(e){let t=(0,v.useRef)(null),n=(0,v.useRef)(e.onClose),r=(0,v.useRef)(!1),[i,a]=(0,v.useState)(null),[o,s]=(0,v.useState)(``),[c,l]=(0,v.useState)(`all`),[u,d]=(0,v.useState)(!1),[f,p]=(0,v.useState)(null),[m,h]=(0,v.useState)(null),[g,_]=(0,v.useState)(`skill`),[y,b]=(0,v.useState)(``),[x,S]=(0,v.useState)(!1),[C,w]=(0,v.useState)(``),[T,E]=(0,v.useState)(``),[D,O]=(0,v.useState)(!1),[ee,te]=(0,v.useState)(``),[k,ne]=(0,v.useState)(null),[A,re]=(0,v.useState)({}),[j,ie]=(0,v.useState)(null),[ae,oe]=(0,v.useState)(null),se=(0,v.useMemo)(()=>BW(e.inventory),[e.inventory]),ce=(0,v.useMemo)(()=>{let e=o.trim().toLocaleLowerCase();return se.flatMap(t=>{let n=`repository`in t?t.repository.collection:void 0,r=n?t.resources.filter(e=>e.kind!==`skill`):t.resources,i=c===`all`?r:r.filter(e=>e.kind===c),a=n&&c!==`extension`?n.skills:[],o=i.length+a.length;if(o===0&&!(n&&c===`all`)||u&&(!(`repository`in t)||![`updateable`,`dirty`,`failed`,`unavailable`,`busy`].includes(t.repository.assessment.status)))return[];let s=`${t.name} ${`path`in t?t.path??``:``} ${i.map(e=>`${e.name} ${e.path??``}`).join(` `)} ${a.map(e=>`${e.name} ${e.relativePath}`).join(` `)}`.toLocaleLowerCase(),l=n?n.skills.filter(e=>e.state!==`off`).length:void 0;return!e||s.includes(e)?[{...t,resources:i,count:o,...l===void 0?{}:{onCount:l}}]:[]})},[se,u,c,o]),le=ce.find(e=>e.id===i)??ce[0]??null;if((0,v.useEffect)(()=>{n.current=e.onClose},[e.onClose]),(0,v.useEffect)(()=>{re(t=>{let n={},r=!1;for(let[i,a]of Object.entries(t)){let t=e.inventory?.repositories.find(e=>e.id===i)?.collection;!t||LW(a,IW(t))?r=!0:n[i]=a}return r?n:t})},[e.inventory]),(0,v.useEffect)(()=>{e.open&&t.current?.focus()},[e.open]),(0,v.useEffect)(()=>{if(!e.open)return;let t=e=>{e.key===`Escape`&&n.current()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e.open]),(0,v.useEffect)(()=>{let t=e.operations.clonePath;t?.status===`ready`&&t.path&&!D&&E(t.path)},[D,e.operations.clonePath]),(0,v.useEffect)(()=>{e.operations.enrollment?.status===`ready`&&p(null)},[e.operations.enrollment]),(0,v.useEffect)(()=>{e.applyState?.status===`applying`?r.current=!0:r.current&&e.applyState===null&&(r.current=!1,p(null),h(null),S(!1))},[e.applyState]),!e.open)return null;let ue=le&&`repository`in le?le.repository:null,de=ue?e.operations.updates[ue.id]:void 0,fe=ue?.assessment,M=fe?.status===`updateable`&&fe.token&&fe.localRevision&&fe.upstreamRevision,pe=()=>{let t=y.trim();t&&(g===`skill`?e.onUpdateConfig({userSkillPaths:[...new Set([...e.userSkillPaths,t])]}):e.onUpdateConfig({userExtensionPaths:[...new Set([...e.userExtensionPaths,t])]}))},me=t=>{t.userRoot&&(t.kind===`skill`?e.onUpdateConfig({userSkillPaths:e.userSkillPaths.filter(e=>e!==t.userRoot)}):e.onUpdateConfig({userExtensionPaths:e.userExtensionPaths.filter(e=>e!==t.userRoot)}))},he=(t,n=!1)=>{let r=t.assessment;r.token&&r.localRevision&&r.upstreamRevision&&e.onUpdate(t.id,r.token,r.localRevision,r.upstreamRevision,n)},ge=ue?.collection,P=ge?IW(ge):[],_e=new Set(ue&&A[ue.id]?A[ue.id]:P),ve=ge?[...new Set([..._e,...P])].filter(e=>_e.has(e)!==P.includes(e)).length:0,ye=ue?e.operations.skills?.[ue.id]:void 0,be=e=>{if(!ue)return;let t=ue.id;re(n=>{let r={...n};return LW(e,P)?delete r[t]:r[t]=[...e],r})},xe=()=>{if(!ue)return;let e=ue.id;re(t=>{let n={...t};return delete n[e],n})},Se=()=>{if(!ue||!ge)return;let t=new Set(ge.skills.filter(e=>e.state!==`on-missing`).map(e=>e.relativePath));e.onSetSkills(ue.id,[..._e].filter(e=>t.has(e)))},Ce=ae?e.operations.removals?.[ae.id]:void 0,we=Ce?.status===`error`||Ce?.result?.status===`removed-delete-failed`;return(0,N.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/45 p-4`,role:`presentation`,onMouseDown:t=>{t.currentTarget===t.target&&e.onClose()},children:[(0,N.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-labelledby":`agent-resources-title`,className:`flex h-[min(760px,92vh)] w-[min(1120px,96vw)] flex-col overflow-hidden rounded-2xl border border-zinc-200 bg-white shadow-2xl dark:border-zinc-700 dark:bg-zinc-900`,children:[(0,N.jsxs)(`header`,{className:`flex items-center justify-between border-b border-zinc-200 px-5 py-4 dark:border-zinc-800`,children:[(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`h2`,{id:`agent-resources-title`,className:`text-lg font-semibold text-zinc-900 dark:text-zinc-100`,children:`Agent resources`}),(0,N.jsx)(`p`,{className:`text-xs text-zinc-500`,children:`Skills and extensions, grouped by repository`})]}),(0,N.jsxs)(`div`,{className:`flex gap-2`,children:[(0,N.jsx)(`button`,{type:`button`,disabled:e.operations.refresh?.status===`loading`,onClick:()=>e.onRefresh(),className:`rounded-md border px-3 py-1.5 text-xs disabled:opacity-50`,children:`Refresh all`}),(0,N.jsx)(`button`,{ref:t,type:`button`,"aria-label":`Close agent resources`,onClick:e.onClose,className:`rounded-md border px-2 py-1 text-sm`,children:`✕`})]})]}),(0,N.jsxs)(`div`,{className:`grid min-h-0 flex-1 grid-cols-[300px_1fr]`,children:[(0,N.jsxs)(`aside`,{className:`flex min-h-0 flex-col border-r border-zinc-200 bg-zinc-50/80 p-3 dark:border-zinc-800 dark:bg-zinc-950/40`,children:[(0,N.jsx)(`input`,{"aria-label":`Search resources`,value:o,onChange:e=>s(e.target.value),placeholder:`Search repositories or resources`,className:`rounded-md border bg-white px-3 py-2 text-xs dark:bg-zinc-900`}),(0,N.jsxs)(`div`,{className:`mt-2 flex flex-wrap gap-1`,children:[[`all`,`skill`,`extension`].map(e=>(0,N.jsx)(`button`,{type:`button`,"aria-pressed":c===e,onClick:()=>l(e),className:`rounded px-2 py-1 text-[11px] ${c===e?`bg-zinc-900 text-white dark:bg-zinc-100 dark:text-zinc-900`:`border`}`,children:e===`all`?`All`:`${e}s`},e)),(0,N.jsx)(`button`,{type:`button`,"aria-pressed":u,onClick:()=>d(e=>!e),className:`rounded px-2 py-1 text-[11px] ${u?`bg-amber-600 text-white`:`border`}`,children:`Needs attention`})]}),(0,N.jsxs)(`div`,{className:`mt-3 min-h-0 flex-1 space-y-1 overflow-y-auto`,children:[ce.map(e=>(0,N.jsxs)(`button`,{type:`button`,onClick:()=>a(e.id),className:`w-full rounded-lg px-3 py-2.5 text-left ${le?.id===e.id?`bg-white shadow-sm ring-1 ring-zinc-200 dark:bg-zinc-800 dark:ring-zinc-700`:`hover:bg-white/70 dark:hover:bg-zinc-900`}`,children:[(0,N.jsxs)(`span`,{className:`flex items-center justify-between gap-2 text-sm font-medium`,children:[(0,N.jsx)(`span`,{className:`truncate`,children:e.name}),(0,N.jsx)(`span`,{className:`shrink-0 text-xs text-zinc-400`,children:e.onCount===void 0?e.count??e.resources.length:`${e.onCount} on · ${e.count}`})]}),(0,N.jsx)(`span`,{className:`mt-1 block text-xs text-zinc-500`,children:`repository`in e?zW[e.repository.assessment.status]:e.reason})]},e.id)),ce.length===0?(0,N.jsx)(`p`,{className:`px-2 py-4 text-xs text-zinc-500`,children:`No matching resources`}):null]}),(0,N.jsxs)(`div`,{className:`mt-3 grid gap-2 border-t pt-3`,children:[(0,N.jsx)(`button`,{type:`button`,onClick:()=>{S(!1),p(`local`),h(`local`),e.onBrowseServerPath(y||`/`)},className:`rounded-md border bg-white px-3 py-2 text-xs font-medium dark:bg-zinc-900`,children:`Add local folder…`}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>p(`git`),className:`rounded-md bg-zinc-900 px-3 py-2 text-xs font-medium text-white dark:bg-zinc-100 dark:text-zinc-900`,children:`Add Git repository…`})]})]}),(0,N.jsxs)(`main`,{className:`min-w-0 overflow-y-auto p-6`,children:[ae&&Ce?(0,N.jsxs)(`div`,{role:we?`alert`:`status`,className:`mb-4 flex items-start justify-between gap-3 rounded-lg border p-3 text-sm ${we?`border-rose-200 bg-rose-50 text-rose-800`:`border-zinc-200 bg-zinc-50 text-zinc-700`}`,children:[(0,N.jsx)(`p`,{className:`min-w-0 break-words`,children:RW(ae.name,Ce)}),Ce.status===`loading`?null:(0,N.jsx)(`button`,{type:`button`,onClick:()=>oe(null),className:`shrink-0 text-xs underline`,children:`Dismiss`})]}):null,f===`local`?(0,N.jsxs)(`div`,{className:`max-w-xl space-y-4`,"data-testid":`add-local-folder`,children:[(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`h3`,{className:`text-lg font-semibold`,children:`Add local folder`}),(0,N.jsx)(`p`,{className:`text-xs text-zinc-500`,children:`Choose an existing folder on the server and how the agent should load it.`})]}),(0,N.jsx)(`div`,{className:`flex gap-2`,children:[`skill`,`extension`].map(t=>(0,N.jsx)(`button`,{type:`button`,"aria-pressed":g===t,disabled:t===`extension`&&e.extensionLock,onClick:()=>{_(t),S(!1)},className:`rounded-md px-3 py-1.5 text-xs ${g===t?`bg-zinc-900 text-white dark:bg-zinc-100 dark:text-zinc-900`:`border`}`,children:t===`skill`?`Skill folder`:`Extension folder`},t))}),(0,N.jsxs)(`div`,{className:`flex gap-2`,children:[(0,N.jsx)(`input`,{"aria-label":`Local resource folder`,value:y,onChange:e=>{S(!1),b(e.target.value)},className:`min-w-0 flex-1 rounded-md border bg-transparent px-3 py-2 text-sm`}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>{h(`local`),e.onBrowseServerPath(y||`/`)},className:`rounded-md border px-3 text-xs`,children:`Browse…`})]}),m===`local`?(0,N.jsx)(_W,{label:`Choose a local resource folder`,browse:e.serverBrowse,onBrowse:e.onBrowseServerPath,onSelect:t=>{S(!1),b(t),h(null),e.onCloseServerBrowser()},onCancel:()=>{h(null),e.onCloseServerBrowser()}}):null,g===`extension`?(0,N.jsxs)(`label`,{className:`flex gap-2 rounded-md border border-amber-300 bg-amber-50 p-3 text-xs text-amber-900`,children:[(0,N.jsx)(`input`,{type:`checkbox`,checked:x,onChange:e=>S(e.target.checked)}),(0,N.jsx)(`span`,{children:`Extensions execute code with the agent's privileges. I trust every extension in this folder.`})]}):null,e.extensionLock?(0,N.jsx)(`p`,{className:`text-xs text-zinc-500`,children:`Extension paths are locked by this deployment.`}):null,e.applyState?.status===`error`?(0,N.jsx)(`p`,{role:`alert`,className:`text-xs text-red-600`,children:e.applyState.message}):null,(0,N.jsxs)(`div`,{className:`flex gap-2`,children:[(0,N.jsx)(`button`,{type:`button`,onClick:()=>{S(!1),p(null),h(null),e.onCloseServerBrowser()},className:`rounded-md border px-3 py-1.5 text-xs`,children:`Cancel`}),(0,N.jsx)(`button`,{type:`button`,disabled:!y.trim()||e.applyState?.status===`applying`||g===`extension`&&(!x||e.extensionLock),onClick:pe,className:`rounded-md bg-zinc-900 px-3 py-1.5 text-xs text-white disabled:opacity-50`,children:e.applyState?.status===`applying`?`Applying…`:`Add folder`})]})]}):f===`git`?(0,N.jsx)(`div`,{className:`max-w-2xl space-y-4`,"data-testid":`add-git-repository`,children:e.operations.preview?.status===`ready`&&e.operations.preview.preview?(0,N.jsx)(GW,{onCancel:()=>{p(null),h(null),e.onCloseServerBrowser()},preview:e.operations.preview.preview,busy:e.operations.enrollment?.status===`loading`,error:e.operations.enrollment?.status===`error`?e.operations.enrollment.message:void 0,onApply:(t,n,r)=>r?e.onEnrollRepository(e.operations.preview.preview.token,t,n,r):e.onEnrollRepository(e.operations.preview.preview.token,t,n)}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`h3`,{className:`text-lg font-semibold`,children:`Add Git repository`}),(0,N.jsx)(`p`,{className:`text-xs text-zinc-500`,children:`Clone it to a local folder, then choose what to turn on.`})]}),(0,N.jsxs)(`label`,{className:`block`,children:[(0,N.jsx)(`span`,{className:`text-xs font-medium`,children:`Repository address`}),(0,N.jsx)(`input`,{"aria-label":`Repository address`,value:C,onChange:e=>w(e.target.value),onBlur:()=>{let t=C.trim();t&&(O(!1),te(t),e.onSuggestClonePath(C))},placeholder:`https://github.com/team/resources.git`,className:`mt-1 w-full rounded-md border bg-transparent px-3 py-2 text-sm`})]}),(0,N.jsxs)(`label`,{className:`block`,children:[(0,N.jsx)(`span`,{className:`text-xs font-medium`,children:`Local folder`}),(0,N.jsxs)(`div`,{className:`mt-1 flex gap-2`,children:[(0,N.jsx)(`input`,{"aria-label":`Local clone folder`,value:T,onChange:e=>{O(!0),E(e.target.value)},placeholder:`/path/to/resource-repositories/team-resources-ab12cd`,className:`min-w-0 flex-1 rounded-md border bg-transparent px-3 py-2 text-sm`}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>{h(`clone-parent`),e.onBrowseServerPath(HW(T))},className:`rounded-md border px-3 text-xs`,children:`Choose parent…`})]})]}),e.operations.clonePath?.status===`loading`?(0,N.jsx)(`p`,{className:`text-xs text-zinc-500`,children:`Suggesting a managed folder…`}):null,e.operations.clonePath?.status===`error`&&C.trim()===ee?(0,N.jsx)(`p`,{role:`alert`,className:`text-xs text-red-600`,children:e.operations.clonePath.message}):null,m===`clone-parent`?(0,N.jsx)(_W,{label:`Choose the clone's parent folder`,browse:e.serverBrowse,onBrowse:e.onBrowseServerPath,onSelect:t=>{E(UW(t,T)),h(null),e.onCloseServerBrowser()},onCancel:()=>{h(null),e.onCloseServerBrowser()}}):null,e.operations.preview?.status===`error`?(0,N.jsx)(`p`,{role:`alert`,className:`text-xs text-red-600`,children:e.operations.preview.message}):null,(0,N.jsxs)(`div`,{className:`flex gap-2`,children:[(0,N.jsx)(`button`,{type:`button`,onClick:()=>{p(null),h(null),e.onCloseServerBrowser()},className:`rounded-md border px-3 py-1.5 text-xs`,children:`Cancel`}),(0,N.jsx)(`button`,{type:`button`,disabled:!C.trim()||!T.trim()||e.operations.preview?.status===`loading`,onClick:()=>e.onCloneRepository(C,T),className:`rounded-md bg-zinc-900 px-3 py-1.5 text-xs text-white disabled:opacity-50`,children:e.operations.preview?.status===`loading`?`Cloning…`:`Clone and inspect`})]})]})}):le?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,N.jsxs)(`div`,{className:`min-w-0`,children:[(0,N.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,N.jsx)(`h3`,{className:`text-xl font-semibold`,children:le.name}),ue?(0,N.jsx)(`span`,{className:`rounded-full border px-2 py-0.5 text-[11px]`,children:zW[ue.assessment.status]}):null]}),(0,N.jsx)(`p`,{className:`mt-1 truncate font-mono text-xs text-zinc-500`,children:`repository`in le?le.path:le.reason}),fe?.branch?(0,N.jsxs)(`p`,{className:`mt-1 text-xs text-zinc-400`,children:[fe.branch,fe.upstream?` → ${fe.upstream}`:``]}):null,ue?.removal&&!ue.removal.allowed?(0,N.jsx)(`p`,{className:`mt-1 text-xs text-zinc-500`,children:ue.removal.reason}):null]}),ue?(0,N.jsxs)(`div`,{className:`flex gap-2`,children:[ue.removal?.allowed?(0,N.jsx)(`button`,{type:`button`,disabled:e.operations.removals?.[ue.id]?.status===`loading`,onClick:()=>ie(ue),className:`rounded-md border border-red-200 px-3 py-1.5 text-xs text-red-700 disabled:opacity-50 dark:border-red-900 dark:text-red-400`,children:`Remove repository`}):null,(0,N.jsx)(`button`,{type:`button`,disabled:e.operations.refresh?.status===`loading`,onClick:()=>e.onRefresh(ue.id),className:`rounded-md border px-3 py-1.5 text-xs`,children:`Check`}),M||de?.status===`loading`?(0,N.jsx)(`button`,{type:`button`,disabled:de?.status===`loading`,onClick:()=>ue.containsExtensions?ne(ue):he(ue),className:`rounded-md bg-zinc-900 px-3 py-1.5 text-xs text-white disabled:opacity-50`,children:de?.status===`loading`?`Updating…`:`Update repository`}):null]}):null]}),fe?.reason?(0,N.jsxs)(`div`,{className:`mt-5 rounded-lg border p-3 text-sm ${fe.status===`dirty`?`border-rose-200 bg-rose-50 text-rose-800`:`border-zinc-200 bg-zinc-50 text-zinc-700`}`,children:[fe.reason,fe.status===`dirty`?(0,N.jsx)(`p`,{className:`mt-1 text-xs`,children:`Review and resolve these local changes in an external terminal, then check again. This updater never commits, stashes, discards, rebases, or merges them.`}):null]}):null,fe?.hasSubmodules?(0,N.jsx)(`p`,{className:`mt-3 rounded border border-amber-200 bg-amber-50 p-2 text-xs text-amber-800`,children:`This repository declares submodules. Their working trees will not be initialized or updated.`}):null,de?.status===`ready`?(0,N.jsx)(`p`,{role:`status`,className:`mt-3 text-xs text-zinc-600`,children:de.result?.status===`updated`&&de.result.reloads.some(e=>e.status===`restart-required`)?`Repository updated. Its skills are reloaded; its extension code runs after pi-outpost restarts — restart it from Settings.`:de.result?.status===`updated`?`Repository updated and runtimes reloaded.`:de.result?.status===`updated-reload-failed`?`Repository updated on disk, but at least one runtime failed to reload.`:de.result?.reason}):null,de?.status===`error`?(0,N.jsx)(`p`,{role:`alert`,className:`mt-3 text-xs text-red-600`,children:de.message}):null,ge&&ue&&c!==`extension`?(0,N.jsxs)(`div`,{className:`mt-6 space-y-4`,children:[ve>0||ye?.status===`loading`?(0,N.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-lg border border-sky-200 bg-sky-50 px-3 py-2 text-xs text-sky-900 dark:border-sky-900 dark:bg-sky-950/40 dark:text-sky-200`,children:[(0,N.jsx)(`span`,{children:ye?.status===`loading`?`Applying…`:`${ve} pending change${ve===1?``:`s`} — applying replaces the session`}),(0,N.jsxs)(`div`,{className:`flex gap-2`,children:[(0,N.jsx)(`button`,{type:`button`,disabled:ye?.status===`loading`,onClick:xe,className:`rounded border bg-white px-2.5 py-1 disabled:opacity-50 dark:bg-zinc-900`,children:`Discard`}),(0,N.jsx)(`button`,{type:`button`,disabled:ye?.status===`loading`||ve===0,onClick:Se,className:`rounded bg-zinc-900 px-2.5 py-1 font-medium text-white disabled:opacity-50 dark:bg-zinc-100 dark:text-zinc-900`,children:`Apply`})]})]}):null,ye?.status===`error`?(0,N.jsx)(`p`,{role:`alert`,className:`text-xs text-red-600`,children:ye.message}):null,(0,N.jsx)(NW,{skills:ge.skills,groups:ge.groups,enabled:_e,onChange:be,disabled:ye?.status===`loading`,...ge.bound?{bound:ge.bound}:{}},ue.id),le.resources.some(e=>e.kind===`extension`)?(0,N.jsx)(WW,{kind:`extension`,resources:le.resources.filter(e=>e.kind===`extension`),removalLocked:e.extensionLock,onRemove:me}):null]}):(0,N.jsxs)(`div`,{className:`mt-6 grid grid-cols-2 gap-4`,children:[(0,N.jsx)(WW,{kind:`skill`,resources:le.resources.filter(e=>e.kind===`skill`),onRemove:me}),(0,N.jsx)(WW,{kind:`extension`,resources:le.resources.filter(e=>e.kind===`extension`),removalLocked:e.extensionLock,onRemove:me})]})]}):(0,N.jsx)(`p`,{className:`text-sm text-zinc-500`,children:`No resources are reported by this runtime.`})]})]})]}),k?(0,N.jsx)(`div`,{className:`fixed inset-0 z-[60] flex items-center justify-center bg-black/55 p-4`,children:(0,N.jsxs)(`div`,{role:`alertdialog`,"aria-modal":`true`,"aria-labelledby":`extension-update-title`,className:`w-full max-w-md rounded-xl bg-white p-5 shadow-2xl dark:bg-zinc-900`,children:[(0,N.jsx)(`h3`,{id:`extension-update-title`,className:`font-semibold`,children:`Update executable extensions?`}),(0,N.jsxs)(`p`,{className:`mt-2 text-sm text-zinc-600 dark:text-zinc-300`,children:[k.name,` contains extensions that run with the agent's privileges. Confirm updating `,k.assessment.localRevision?.slice(0,8),` to `,k.assessment.upstreamRevision?.slice(0,8),`.`]}),(0,N.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2`,children:[(0,N.jsx)(`button`,{type:`button`,onClick:()=>ne(null),className:`rounded border px-3 py-1.5 text-xs`,children:`Cancel`}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>{he(k,!0),ne(null)},className:`rounded bg-amber-600 px-3 py-1.5 text-xs font-medium text-white`,children:`Confirm executable update`})]})]})}):null,j?(0,N.jsx)(`div`,{className:`fixed inset-0 z-[60] flex items-center justify-center bg-black/55 p-4`,children:(0,N.jsxs)(`div`,{role:`alertdialog`,"aria-modal":`true`,"aria-labelledby":`remove-repository-title`,"aria-describedby":`remove-repository-detail`,className:`w-full max-w-md rounded-xl bg-white p-5 shadow-2xl dark:bg-zinc-900`,children:[(0,N.jsxs)(`h3`,{id:`remove-repository-title`,className:`font-semibold`,children:[`Remove `,j.name,`?`]}),(0,N.jsx)(`p`,{id:`remove-repository-detail`,className:`mt-2 break-words text-sm text-zinc-600 dark:text-zinc-300`,children:j.removal?.deletesFiles?(0,N.jsxs)(N.Fragment,{children:[`This stops loading everything from `,j.name,` and deletes `,(0,N.jsx)(`span`,{className:`font-mono`,children:j.removal.path}),` from disk, with any local changes in it. This cannot be undone.`]}):(0,N.jsxs)(N.Fragment,{children:[`This stops loading everything from `,j.name,`. pi-outpost does not manage `,(0,N.jsx)(`span`,{className:`font-mono`,children:j.removal?.path??j.path}),`, so its files will be kept.`]})}),(0,N.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2`,children:[(0,N.jsx)(`button`,{type:`button`,onClick:()=>ie(null),className:`rounded border px-3 py-1.5 text-xs`,children:`Cancel`}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>{e.onRemoveRepository(j.id),oe({id:j.id,name:j.name}),ie(null)},className:`rounded bg-red-600 px-3 py-1.5 text-xs font-medium text-white`,children:j.removal?.deletesFiles?`Delete and remove`:`Remove repository`})]})]})}):null]})}var qW=`w-full rounded-md border border-zinc-300 bg-white px-3 py-2 text-sm text-zinc-800 placeholder:text-zinc-400 focus:border-zinc-400 focus:outline-none dark:border-zinc-700 dark:bg-zinc-900 dark:text-zinc-100 dark:placeholder:text-zinc-600`,JW=`rounded-md border border-zinc-300 px-3 py-1.5 text-xs font-medium text-zinc-700 hover:bg-zinc-50 disabled:opacity-50 dark:border-zinc-700 dark:text-zinc-200 dark:hover:bg-zinc-800`;function YW({event:e}){switch(e.type){case`auth_url`:return(0,N.jsxs)(`div`,{"data-testid":`login-auth-url`,className:`space-y-1`,children:[(0,N.jsx)(`p`,{className:`text-sm text-zinc-700 dark:text-zinc-200`,children:e.instructions??`Open this page to sign in:`}),(0,N.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,N.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,className:`truncate text-sm text-sky-700 underline dark:text-sky-400`,children:e.url}),(0,N.jsx)(`button`,{type:`button`,className:JW,onClick:()=>void navigator.clipboard?.writeText(e.url),children:`Copy`})]})]});case`device_code`:return(0,N.jsxs)(`div`,{"data-testid":`login-device-code`,className:`space-y-1`,children:[(0,N.jsxs)(`p`,{className:`text-sm text-zinc-700 dark:text-zinc-200`,children:[`Enter this code at`,` `,(0,N.jsx)(`a`,{href:e.verificationUri,target:`_blank`,rel:`noopener noreferrer`,className:`text-sky-700 underline dark:text-sky-400`,children:e.verificationUri}),`:`]}),(0,N.jsx)(`p`,{className:`select-all font-mono text-2xl tracking-widest text-zinc-900 dark:text-zinc-50`,children:e.userCode})]});case`info`:return(0,N.jsxs)(`p`,{className:`text-sm text-zinc-700 dark:text-zinc-200`,children:[e.message,e.links?.map(e=>(0,N.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,className:`ml-2 text-sky-700 underline dark:text-sky-400`,children:e.label??e.url},e.url))]});case`progress`:return(0,N.jsx)(`p`,{className:`text-xs text-zinc-500 dark:text-zinc-400`,children:e.message})}}function XW({prompt:e,onAnswer:t}){let[n,r]=(0,v.useState)(``),i=e.type===`manual_code`&&/^http:\/\/(?:localhost|127\.0\.0\.1):1455\/auth\/callback\/?$/.test(e.placeholder??``);return e.type===`select`?(0,N.jsxs)(`div`,{"data-testid":`login-prompt`,className:`space-y-2`,children:[(0,N.jsx)(`p`,{className:`text-sm text-zinc-700 dark:text-zinc-200`,children:e.message}),(0,N.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:e.options.map(e=>(0,N.jsx)(`button`,{type:`button`,className:JW,title:e.description,onClick:()=>t(e.id),children:e.label},e.id))})]}):(0,N.jsxs)(`div`,{"data-testid":`login-prompt`,className:`space-y-2`,children:[(0,N.jsxs)(`label`,{className:`block text-sm text-zinc-700 dark:text-zinc-200`,children:[e.type===`manual_code`?`${e.message} — or the whole address the browser was sent to`:e.message,(0,N.jsx)(`input`,{className:`${qW} mt-1`,type:e.type===`secret`?`password`:`text`,name:`provider-auth-response`,placeholder:e.placeholder,autoComplete:`off`,spellCheck:e.type!==`manual_code`,autoFocus:!0,value:n,onChange:e=>r(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.stopPropagation(),n.trim()&&t(n.trim()))}})]}),i&&(0,N.jsx)(`p`,{className:`text-xs text-zinc-600 dark:text-zinc-300`,children:`If Pi Outpost runs on another computer, your browser may say it cannot connect to localhost. Copy the full address from that browser page and paste it above to finish signing in.`}),(0,N.jsx)(`button`,{type:`button`,className:JW,disabled:!n.trim(),onClick:()=>t(n.trim()),children:`Continue`})]})}function ZW({login:e,providerName:t,onAnswer:n,onCancel:r,onDismiss:i}){return(0,N.jsxs)(`div`,{"data-testid":`login-flow`,className:`space-y-3 rounded-md border border-zinc-200 p-3 dark:border-zinc-700`,children:[(0,N.jsxs)(`p`,{className:`text-xs font-semibold uppercase tracking-wider text-zinc-500 dark:text-zinc-400`,children:[`Signing in to `,t]}),(0,N.jsxs)(`div`,{"aria-live":`polite`,"aria-atomic":`false`,children:[e.events.map((e,t)=>(0,N.jsx)(YW,{event:e},t)),e.prompt&&(0,N.jsx)(XW,{prompt:e.prompt.prompt,onAnswer:n},e.prompt.promptId),!e.done&&!e.prompt&&e.events.length===0&&(0,N.jsx)(`p`,{className:`text-xs text-zinc-500 dark:text-zinc-400`,children:`Starting…`}),e.done?(0,N.jsxs)(`div`,{"data-testid":`login-done`,"data-ok":e.done.ok?`true`:`false`,className:`space-y-2`,children:[(0,N.jsx)(`p`,{className:`text-sm ${e.done.ok?`text-emerald-700 dark:text-emerald-400`:`text-red-700 dark:text-red-400`}`,children:e.done.ok?`Signed in to ${t}.`:e.done.cancelled?`Sign-in cancelled.`:`Sign-in failed: ${e.done.message??`unknown error`}`}),(0,N.jsx)(`button`,{type:`button`,className:JW,onClick:i,children:`Close`})]}):(0,N.jsx)(`button`,{type:`button`,className:JW,onClick:r,children:`Cancel`})]})]})}function QW(e){return[...e].sort((e,t)=>e.localeCompare(t))}function $W(e,t){return e===`models_json_key`?`This key is managed in models.json. Remove it from that provider configuration.`:e===`environment`?`This key comes from ${t??`the server environment`}. Remove it from there.`:`This key is managed by ${t??e??`the provider runtime`}. Remove it from that source.`}function eG(e,t){return e===`models_json_key`?`models.json`:t??e}function tG({credentials:e,login:t,onStartLogin:n,onAnswerLogin:r,onCancelLogin:i,onDismissLogin:a,onLogoutProvider:o,extensionPaths:s,configuredExtensionPaths:c,userExtensionPaths:l,extensionLock:u,piPackages:d=null,piPackageUpdate:f=null,canRestartServer:p=!1,serverRestarting:m=!1,onCheckPiPackages:h,onUpdatePiPackage:g,onRestartServer:_,onRestartSession:y,restartNeeded:b=[],tools:x,commands:S,sandbox:C,showRoots:w=!0,gitUnavailable:T,userSkillPaths:E,serverBrowse:D,pickerBlocked:O=!1,onPickerOpened:ee,applyState:te,agentResources:k=null,agentResourceOperations:ne={clonePath:null,preview:null,enrollment:null,refresh:null,updates:{},skills:{},removals:{}},versions:A,onBrowseServerPath:re,onCloseServerBrowser:j,onUpdateConfig:ie,onSuggestAgentResourceClonePath:ae=()=>{},onCloneAgentResourceRepository:oe=()=>{},onEnrollAgentResourceRepository:se=()=>{},onSetAgentResourceSkills:ce=()=>{},onRemoveAgentResourceRepository:le=()=>{},onRefreshAgentResourceRepositories:ue=()=>{},onUpdateAgentResourceRepository:de=()=>{}}){let[fe,M]=(0,v.useState)(!1),[pe,me]=(0,v.useState)(!1),he=(0,v.useRef)(new Map),[ge,P]=(0,v.useState)(!1),_e=(0,v.useRef)(null),[ve,ye]=(0,v.useState)(``),[be,xe]=(0,v.useState)(``),[Se,Ce]=(0,v.useState)(!1),[we,Te]=(0,v.useState)(!1),[Ee,De]=(0,v.useState)(null),Oe=(e,r)=>{if(t&&!t.done){i?.(),a?.();let e=he.current.get(t.provider);e&&(e.open=!1)}else n?.(e,r)};(0,v.useEffect)(()=>{O&&Ee!==null&&De(null)},[O,Ee]);let ke=oH(()=>{(fe||Ee!==null)&&Le()}),Ae=x.filter(e=>e.active),je=x.filter(e=>!e.active),Me=S.filter(e=>e.source===`skill`),Ne=[...x].sort((e,t)=>e.name.localeCompare(t.name)||Number(t.active)-Number(e.active)),Pe=te?.status===`applying`,Fe=te?.status===`error`?te.message:null;(0,v.useEffect)(()=>{C&&(ye(C.root),xe(C.writableRoot??``),Ce(C.allowWrite),Te(C.allowBash))},[C]);let Ie=(0,v.useRef)(!1);(0,v.useEffect)(()=>{Ie.current&&te===null&&Le(),Ie.current=Pe},[te,Pe]);function Le(){me(!1),M(!1),De(null),j()}function Re(e,t){ee?.(),De(e),re(t.trim()||`/`)}function ze(e){Ee===`root`?ye(e):Ee===`writableRoot`&&xe(e),De(null),j()}let Be=C!==null&&(ve!==C.root||(be.trim()||void 0)!==(C.writableRoot||void 0)||Se!==C.allowWrite||we!==C.allowBash);function Ve(){C&&Be&&ie({sandbox:{root:ve,allowWrite:Se,allowBash:we,writableRoot:be.trim()||void 0}})}let He=w&&C?.rootEditable!==!1,Ue=Ee!==null&&!O&&(0,N.jsx)(_W,{label:Ee===`root`?`Choose the sandbox root`:`Choose the writable root`,browse:D,onBrowse:re,onSelect:ze,onCancel:()=>{De(null),j()}});return(0,N.jsxs)(`div`,{className:`relative`,ref:ke,children:[(0,N.jsx)(`button`,{ref:_e,type:`button`,onClick:()=>{me(!1),fe?Le():M(!0)},title:`Settings`,"aria-label":`Settings`,className:`${lW} border-zinc-300 text-zinc-500 hover:border-zinc-400 hover:text-zinc-700 dark:border-zinc-800 dark:text-zinc-400 dark:hover:border-zinc-600 dark:hover:text-zinc-200`,children:`⚙`}),fe&&(0,N.jsxs)(`div`,{className:`absolute right-0 top-full z-20 mt-1 flex max-h-[80vh] w-[380px] flex-col rounded-lg border border-zinc-200 bg-white shadow-xl dark:border-zinc-700 dark:bg-zinc-900`,children:[(0,N.jsxs)(`div`,{className:`border-b border-zinc-200 px-4 py-3 dark:border-zinc-800`,children:[pe&&(0,N.jsx)(`button`,{type:`button`,onClick:()=>me(!1),className:`mb-2 text-xs text-zinc-600 hover:underline dark:text-zinc-400`,children:`← Back to settings`}),(0,N.jsx)(`h2`,{className:`text-sm font-semibold text-zinc-800 dark:text-zinc-200`,children:pe?`Credits`:`Settings`})]}),(0,N.jsx)(`div`,{className:`min-h-0 overflow-y-auto p-4`,children:pe?(0,N.jsx)(DW,{}):(0,N.jsxs)(N.Fragment,{children:[T&&(0,N.jsxs)(`section`,{className:`mb-4`,"data-testid":`git-unavailable`,children:[(0,N.jsx)(`h3`,{className:`mb-2 text-xs font-semibold uppercase tracking-wider text-zinc-500 dark:text-zinc-400`,children:`Version control`}),T.reason===`no-repository`?(0,N.jsx)(`p`,{className:`text-xs text-zinc-500 dark:text-zinc-400`,children:`This project is not in a git repository.`}):(0,N.jsxs)(`div`,{className:`rounded border border-amber-300 bg-amber-50 px-2 py-1.5 dark:border-amber-900 dark:bg-amber-950/40`,children:[(0,N.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-300`,children:T.reason===`no-executable`?`Git is unavailable: its executable could not be run.`:`Git is unavailable: it refused this repository.`}),(0,N.jsx)(`p`,{className:`mt-1 break-all font-mono text-[11px] text-amber-700 dark:text-amber-400`,children:T.message}),T.reason===`no-executable`&&(0,N.jsxs)(`p`,{className:`mt-1 text-xs text-amber-700 dark:text-amber-400`,children:[`Install git, add it to PATH, or name it with `,(0,N.jsx)(`span`,{className:`font-mono`,children:`gitPath`}),` in the configuration.`]})]})]}),e&&(0,N.jsxs)(`details`,{className:`mb-4`,"data-testid":`accounts-panel`,children:[(0,N.jsxs)(`summary`,{className:`cursor-pointer text-xs font-semibold uppercase tracking-wider text-zinc-500 dark:text-zinc-400`,children:[`Accounts · `,(0,N.jsxs)(`span`,{className:`text-emerald-700 dark:text-emerald-400`,children:[e.providers.filter(e=>e.configured).length,` providers configured`]})]}),(0,N.jsxs)(`div`,{className:`mt-2`,children:[(0,N.jsx)(`ul`,{className:`space-y-2`,children:e.providers.map(n=>(0,N.jsx)(`li`,{className:`rounded border border-zinc-200 p-2 dark:border-zinc-700`,children:(0,N.jsxs)(`details`,{ref:e=>{e?he.current.set(n.id,e):he.current.delete(n.id)},"data-testid":`account-${n.id}`,children:[(0,N.jsxs)(`summary`,{className:`cursor-pointer`,children:[(0,N.jsx)(`span`,{className:`text-xs font-medium text-zinc-800 dark:text-zinc-200`,children:n.name}),(0,N.jsx)(`span`,{className:`ml-2 text-[11px] ${n.configured?`text-emerald-700 dark:text-emerald-400`:`text-zinc-500 dark:text-zinc-400`}`,children:n.configured?`${n.auth??`Authenticated`}${n.source?` · ${eG(n.source,n.label)}`:``}`:`Not signed in`})]}),(0,N.jsxs)(`div`,{className:`mt-2`,children:[n.configured&&n.auth===`api_key`&&n.source!==`stored`&&(0,N.jsx)(`p`,{className:`mb-2 text-[11px] text-zinc-500 dark:text-zinc-400`,children:$W(n.source,n.label)}),!e.locked&&(0,N.jsxs)(`div`,{className:`flex flex-wrap gap-1`,children:[n.methods?.includes(`oauth`)&&(0,N.jsx)(`button`,{type:`button`,className:`rounded border px-2 py-1 text-[11px]`,onClick:()=>Oe(n.id,`oauth`),children:`Sign in`}),n.methods?.includes(`api_key`)&&(0,N.jsx)(`button`,{type:`button`,className:`rounded border px-2 py-1 text-[11px]`,onClick:()=>Oe(n.id,`api_key`),children:`API key`}),n.configured&&n.source===`stored`&&(0,N.jsx)(`button`,{type:`button`,className:`rounded border px-2 py-1 text-[11px]`,onClick:()=>o?.(n.id),children:n.auth===`api_key`?`Remove API key`:`Sign out`})]}),t?.provider===n.id&&(0,N.jsx)(`div`,{className:`mt-2`,children:(0,N.jsx)(ZW,{login:t,providerName:n.name,onAnswer:e=>r?.(e),onCancel:()=>i?.(),onDismiss:()=>a?.()})})]})]})},n.id))}),e.locked&&(0,N.jsx)(`p`,{className:`mt-2 text-xs text-zinc-500 dark:text-zinc-400`,children:`Credentials are locked by this server.`})]})]}),(0,N.jsxs)(`section`,{className:`mb-4`,children:[(0,N.jsx)(`h3`,{className:`mb-2 text-xs font-semibold uppercase tracking-wider text-zinc-500 dark:text-zinc-400`,children:`Agent resources`}),x.length===0?(0,N.jsx)(`p`,{className:`text-xs text-zinc-400 dark:text-zinc-500`,children:`Tool inventory unavailable for this runtime`}):(0,N.jsxs)(`details`,{"data-testid":`tools-loaded`,children:[(0,N.jsxs)(`summary`,{className:`cursor-pointer text-xs text-zinc-600 dark:text-zinc-400`,children:[Ae.length,` tools active`,je.length?` · ${je.length} inactive`:``]}),(0,N.jsx)(`ul`,{className:`mt-2 space-y-1`,children:Ne.map(e=>(0,N.jsxs)(`li`,{className:`flex justify-between rounded bg-zinc-50 px-2 py-1 font-mono text-xs text-zinc-600 dark:bg-zinc-800 dark:text-zinc-400`,children:[(0,N.jsx)(`span`,{children:e.name}),(0,N.jsx)(`span`,{children:e.active?`active`:`inactive`})]},e.name))})]}),Me.length===0?(0,N.jsx)(`p`,{className:`mt-2 text-xs text-zinc-400 dark:text-zinc-500`,children:`No skills loaded`}):(0,N.jsxs)(`details`,{className:`mt-2`,"data-testid":`skills-loaded`,children:[(0,N.jsxs)(`summary`,{className:`cursor-pointer text-xs text-zinc-600 dark:text-zinc-400`,children:[Me.length,` skills loaded`]}),(0,N.jsx)(`ul`,{className:`mt-2 space-y-1`,children:QW(Me.map(e=>e.name)).map(e=>(0,N.jsx)(`li`,{className:`rounded bg-zinc-50 px-2 py-1 font-mono text-xs text-zinc-600 dark:bg-zinc-800 dark:text-zinc-400`,children:e},e))})]}),(0,N.jsx)(`button`,{type:`button`,"aria-label":`Manage agent resources`,onClick:()=>{M(!1),P(!0)},className:`mt-3 w-full rounded-md border border-zinc-300 px-3 py-2 text-xs font-medium text-zinc-700 hover:bg-zinc-50 dark:border-zinc-700 dark:text-zinc-200 dark:hover:bg-zinc-800`,children:`Manage resources…`})]}),(0,N.jsxs)(`section`,{className:`mb-4`,children:[(0,N.jsx)(`h3`,{className:`mb-2 text-xs font-semibold uppercase tracking-wider text-zinc-500 dark:text-zinc-400`,children:`Extensions`}),s===null?(0,N.jsx)(`p`,{className:`text-xs text-zinc-400 dark:text-zinc-500`,"data-testid":`extensions-unknown`,children:`Not reported by this runtime`}):s.length===0?(0,N.jsx)(`p`,{className:`text-xs text-zinc-400 dark:text-zinc-500`,children:`No extensions loaded`}):(0,N.jsxs)(`details`,{"data-testid":`extensions-loaded`,children:[(0,N.jsxs)(`summary`,{className:`cursor-pointer text-xs text-zinc-600 dark:text-zinc-400`,children:[s.length,` `,s.length===1?`extension`:`extensions`,` loaded`]}),(0,N.jsx)(`ul`,{className:`mt-2 space-y-1`,children:QW(s).map(e=>(0,N.jsx)(`li`,{className:`truncate rounded bg-zinc-50 px-2 py-1 font-mono text-xs text-zinc-600 dark:bg-zinc-800 dark:text-zinc-400`,title:e,children:e},e))})]}),c.length>0&&(0,N.jsxs)(`details`,{className:`mt-2`,"data-testid":`extensions-configured`,children:[(0,N.jsxs)(`summary`,{className:`cursor-pointer text-xs text-zinc-600 dark:text-zinc-400`,children:[c.length,` configured by this deployment`]}),(0,N.jsx)(`p`,{className:`mt-1 text-xs text-zinc-400 dark:text-zinc-500`,children:`Declared in the configuration file. They load either way, and nothing here can remove them.`}),(0,N.jsx)(`ul`,{className:`mt-1 space-y-1`,children:QW(c).map(e=>(0,N.jsx)(`li`,{className:`truncate rounded bg-zinc-50 px-2 py-1 font-mono text-xs text-zinc-600 dark:bg-zinc-800 dark:text-zinc-400`,title:e,children:e},e))})]}),u?(0,N.jsx)(`p`,{className:`mt-2 text-xs text-zinc-400 dark:text-zinc-500`,"data-testid":`extensions-locked`,children:`Extension paths and repository updates that contain extensions are locked by this deployment.`}):null,(0,N.jsx)(kW,{packages:d,update:f,locked:u,onCheck:()=>h?.(),onUpdate:e=>g?.(e)}),(0,N.jsx)(AW,{reasons:b,canRestart:p,restarting:m,onRestart:()=>_?.()})]}),C&&(0,N.jsxs)(`section`,{children:[(0,N.jsx)(`h3`,{className:`mb-2 text-xs font-semibold uppercase tracking-wider text-zinc-500 dark:text-zinc-400`,children:He?`Sandbox`:`Agent permissions`}),(0,N.jsxs)(`div`,{className:`space-y-3`,children:[!He&&(0,N.jsxs)(`p`,{"data-testid":`sandbox-project-root`,className:`text-xs text-zinc-600 dark:text-zinc-400`,children:[`This project is confined to its own folder,`,` `,(0,N.jsx)(`span`,{className:`break-all font-mono text-zinc-800 dark:text-zinc-200`,children:C.projectRoot??C.root}),`. Each open project is confined to its own. A change here applies to this project now, and to projects opened after.`]}),He&&(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`label`,{className:`block`,children:[(0,N.jsxs)(`span`,{className:`text-xs text-zinc-600 dark:text-zinc-400`,children:[`Root `,C.locks?.root?(0,N.jsx)(`span`,{className:`text-zinc-400`,children:`(locked)`}):null]}),(0,N.jsxs)(`div`,{className:`mt-1 flex gap-2`,children:[(0,N.jsx)(`input`,{type:`text`,value:ve,onChange:e=>ye(e.target.value),disabled:C.locks?.root,className:`w-full rounded-md border border-zinc-300 bg-transparent px-2 py-1 text-sm outline-none focus:border-zinc-500 disabled:cursor-not-allowed disabled:opacity-50 dark:border-zinc-700 dark:focus:border-zinc-500`}),(0,N.jsx)(`button`,{type:`button`,"aria-label":`Browse for sandbox root`,disabled:C.locks?.root,onClick:()=>Re(`root`,ve),className:`shrink-0 rounded-md border border-zinc-300 px-2 py-1 text-xs text-zinc-600 hover:border-zinc-400 disabled:cursor-not-allowed disabled:opacity-50 dark:border-zinc-700 dark:text-zinc-300`,children:`Browse…`})]})]}),Ee===`root`&&Ue,(0,N.jsxs)(`label`,{className:`block`,children:[(0,N.jsxs)(`span`,{className:`text-xs text-zinc-600 dark:text-zinc-400`,children:[`Writable root (optional) `,C.locks?.writableRoot?(0,N.jsx)(`span`,{className:`text-zinc-400`,children:`(locked)`}):null]}),(0,N.jsxs)(`div`,{className:`mt-1 flex gap-2`,children:[(0,N.jsx)(`input`,{type:`text`,value:be,onChange:e=>xe(e.target.value),disabled:C.locks?.writableRoot,placeholder:`Same as root`,className:`w-full rounded-md border border-zinc-300 bg-transparent px-2 py-1 text-sm outline-none placeholder:text-zinc-400 focus:border-zinc-500 disabled:cursor-not-allowed disabled:opacity-50 dark:border-zinc-700 dark:placeholder:text-zinc-600 dark:focus:border-zinc-500`}),(0,N.jsx)(`button`,{type:`button`,"aria-label":`Browse for writable root`,disabled:C.locks?.writableRoot,onClick:()=>Re(`writableRoot`,be||ve),className:`shrink-0 rounded-md border border-zinc-300 px-2 py-1 text-xs text-zinc-600 hover:border-zinc-400 disabled:cursor-not-allowed disabled:opacity-50 dark:border-zinc-700 dark:text-zinc-300`,children:`Browse…`})]})]}),Ee===`writableRoot`&&Ue]}),(0,N.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,N.jsx)(`input`,{type:`checkbox`,checked:Se,onChange:e=>Ce(e.target.checked),disabled:C.locks?.allowWrite,className:`rounded border-zinc-300 text-zinc-700 focus:ring-zinc-500 disabled:cursor-not-allowed disabled:opacity-50 dark:border-zinc-700 dark:bg-zinc-800 dark:text-zinc-300`}),(0,N.jsxs)(`span`,{className:`text-xs text-zinc-600 dark:text-zinc-400`,children:[`Allow write `,C.locks?.allowWrite?(0,N.jsx)(`span`,{className:`text-zinc-400`,children:`(locked)`}):null]})]}),(0,N.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,N.jsx)(`input`,{type:`checkbox`,checked:we,onChange:e=>Te(e.target.checked),disabled:C.locks?.allowBash,className:`rounded border-zinc-300 text-zinc-700 focus:ring-zinc-500 disabled:cursor-not-allowed disabled:opacity-50 dark:border-zinc-700 dark:bg-zinc-800 dark:text-zinc-300`}),(0,N.jsxs)(`span`,{className:`text-xs text-zinc-600 dark:text-zinc-400`,children:[`Allow bash `,C.locks?.allowBash?(0,N.jsx)(`span`,{className:`text-zinc-400`,children:`(locked)`}):null]})]})]})]}),!C&&(0,N.jsx)(`p`,{className:`text-xs text-zinc-400 dark:text-zinc-500`,children:`No sandbox configured`}),(0,N.jsxs)(`div`,{className:`mt-4 space-y-2`,children:[Fe&&(0,N.jsx)(`p`,{role:`alert`,className:`rounded-md border border-red-300 bg-red-50 px-2 py-1 text-xs text-red-700 dark:border-red-900/60 dark:bg-red-950/30 dark:text-red-300`,children:Fe}),(0,N.jsx)(`button`,{type:`button`,disabled:Pe||Be&&!ve.trim(),onClick:Be?Ve:y,className:`w-full rounded-md bg-zinc-800 px-3 py-1.5 text-xs font-medium text-white hover:bg-zinc-700 disabled:cursor-not-allowed disabled:opacity-50 dark:bg-zinc-200 dark:text-zinc-900 dark:hover:bg-zinc-300`,children:Pe?`Restarting…`:Be?`Apply & restart session`:`Restart session`}),(0,N.jsx)(`p`,{className:`text-[11px] text-zinc-400 dark:text-zinc-500`,children:Be?`Saved to the server's configuration file, then the session is rebuilt — the change survives a restart.`:`Start a fresh session to reload extensions and MCP connections. Settings are kept.`})]}),A&&(0,N.jsxs)(`section`,{className:`mt-4`,children:[(0,N.jsx)(`h3`,{className:`mb-2 text-xs font-semibold uppercase tracking-wider text-zinc-500 dark:text-zinc-400`,children:`Versions`}),(0,N.jsxs)(`div`,{className:`space-y-1 text-xs text-zinc-600 dark:text-zinc-400`,children:[(0,N.jsxs)(`p`,{children:[`pi-outpost: `,(0,N.jsx)(`span`,{className:`font-mono text-zinc-800 dark:text-zinc-200`,children:A.piOutpost})]}),A.piSdk&&(0,N.jsxs)(`p`,{children:[`pi SDK: `,(0,N.jsx)(`span`,{className:`font-mono text-zinc-800 dark:text-zinc-200`,children:A.piSdk})]}),A.agent&&(0,N.jsxs)(`p`,{children:[`agent: `,(0,N.jsx)(`span`,{className:`font-mono text-zinc-800 dark:text-zinc-200`,children:A.agent})]})]})]}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>me(!0),className:`mt-4 w-full border-t border-zinc-200 pt-3 text-left text-sm text-zinc-600 hover:text-zinc-900 dark:border-zinc-700 dark:text-zinc-400 dark:hover:text-zinc-100`,children:`Credits →`})]})})]}),(0,N.jsx)(KW,{open:ge,inventory:k,operations:ne,extensionLock:u,userSkillPaths:E,userExtensionPaths:l,serverBrowse:D,applyState:te,onClose:()=>{P(!1),j(),_e.current?.focus()},onBrowseServerPath:e=>{ee?.(),re(e)},onCloseServerBrowser:j,onUpdateConfig:ie,onSuggestClonePath:ae,onCloneRepository:oe,onEnrollRepository:se,onSetSkills:ce,onRemoveRepository:le,onRefresh:ue,onUpdate:de})]})}function nG(e){let t=[],n=new Set,r=0,i=0;function a(e,o,s,c){let l=e.children,u=l.slice(1).map(e=>[e,r++]);u.length>0&&i++;let d=e.onPath&&!l.some(e=>e.onPath);if(t.push({node:e,lane:o,through:[...n].filter(e=>e!==o),forkTo:u.map(([,e])=>e),lineAbove:s,lineBelow:l.length>0,branchIndex:c,isCurrent:d,emphasis:d?`current`:e.onPath?`filled`:`hollow`,highlight:e.onPath}),l.length===0)n.delete(o);else{for(let[,e]of u)n.add(e);a(l[0],o,!0,u.length>0?1:void 0),u.forEach(([e,t],n)=>a(e,t,!0,n+2))}}return e.length>1&&i++,e.forEach((t,i)=>{let o=r++;n.add(o),a(t,o,!1,e.length>1?i+1:void 0)}),{rows:t,laneCount:r,branchPoints:i}}function rG(e){return e.flatMap(e=>[e,...rG(e.children)])}function iG({children:e,tone:t}){let n={current:`border-emerald-300 bg-emerald-50 text-emerald-700 dark:border-emerald-800 dark:bg-emerald-950/50 dark:text-emerald-300`,branch:`border-zinc-300 text-zinc-500 dark:border-zinc-700 dark:text-zinc-400`,label:`border-violet-300 bg-violet-50 text-violet-700 dark:border-violet-900 dark:bg-violet-950/50 dark:text-violet-300`}[t];return(0,N.jsx)(`span`,{className:`shrink-0 rounded-full border px-1.5 py-px text-[10px] leading-4 ${n}`,children:e})}var aG=`shrink-0 rounded px-1.5 py-0.5 text-xs text-zinc-400 opacity-0 hover:bg-zinc-200 hover:text-zinc-700 focus-visible:opacity-100 group-hover:opacity-100 dark:text-zinc-500 dark:hover:bg-zinc-700 dark:hover:text-zinc-200`;function oG({row:e,laneCount:t,isStreaming:n,onNavigate:r,onFork:i,onClose:a}){let{node:o}=e,s=o.tipId??o.entryId;return(0,N.jsxs)(`div`,{className:`group flex items-center gap-1 pr-2 hover:bg-zinc-100 dark:hover:bg-zinc-800/70 ${e.isCurrent?`bg-emerald-50/60 dark:bg-emerald-950/20`:``}`,style:{height:36},children:[(0,N.jsxs)(`button`,{type:`button`,disabled:n,onClick:()=>{r(s),a()},title:n?`unavailable while the agent is running`:o.tipId?`restore the conversation at this point (reply included)`:`go back to this point`,className:`flex h-full min-w-0 flex-1 items-center gap-2 pl-2 text-left text-sm disabled:opacity-50`,children:[(0,N.jsx)(JU,{row:e,laneCount:t,colorOf:GU}),(0,N.jsx)(`span`,{className:`min-w-0 truncate ${o.onPath?`text-zinc-800 dark:text-zinc-200`:`text-zinc-600 dark:text-zinc-400`}`,children:o.text||`(empty)`}),e.forkTo.length>0&&(0,N.jsxs)(iG,{tone:`branch`,children:[e.forkTo.length+1,` branches`]}),e.branchIndex!==void 0&&(0,N.jsxs)(iG,{tone:`branch`,children:[`branch `,e.branchIndex,o.onPath&&!e.isCurrent?` · current`:``]}),e.isCurrent&&(0,N.jsx)(iG,{tone:`current`,children:`current`}),o.label&&(0,N.jsx)(iG,{tone:`label`,children:o.label})]}),(0,N.jsx)(`button`,{type:`button`,disabled:n,onClick:()=>{r(o.entryId),a()},title:`rewind to just before this message (its text comes back in the composer)`,"aria-label":`Rewind to before this message`,className:aG,children:`↺ redo`}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>{i(o.entryId),a()},title:`fork a new session from this point`,className:aG,children:`⑂ fork`})]})}function sG({tree:e,isStreaming:t,onListTree:n,onNavigate:r,onFork:i}){let[a,o]=(0,v.useState)(!1),[s,c]=(0,v.useState)(``),l=oH(()=>o(!1));(0,v.useEffect)(()=>{a&&e===null&&n()},[a,e]);let u=(0,v.useMemo)(()=>e&&e.length>0?nG(e):null,[e]),d=(0,v.useMemo)(()=>{if(!e||!s.trim())return null;let t=s.trim().toLowerCase();return rG(e).filter(e=>e.text.toLowerCase().includes(t)||e.label?.toLowerCase().includes(t))},[e,s]);return(0,N.jsxs)(`div`,{className:`relative`,ref:l,children:[(0,N.jsx)(`button`,{type:`button`,onClick:()=>{o(!a),a||(c(``),n())},title:`conversation tree: go back to an earlier point or fork`,className:`${lW} border-zinc-300 text-zinc-500 hover:border-zinc-400 hover:text-zinc-700 dark:border-zinc-800 dark:text-zinc-400 dark:hover:border-zinc-600 dark:hover:text-zinc-200`,children:`tree`}),a&&(0,N.jsxs)(`div`,{className:`absolute right-0 top-full z-20 mt-1 flex max-h-[70vh] w-[32rem] max-w-[90vw] flex-col rounded-lg border border-zinc-200 bg-white shadow-xl [--tree-off:#e4e4e7] dark:border-zinc-700 dark:bg-zinc-900 dark:[--tree-off:#3f3f46]`,children:[e===null&&(0,N.jsx)(`div`,{className:`px-3 py-2 text-xs text-zinc-500`,children:`loading…`}),e?.length===0&&(0,N.jsx)(`div`,{className:`px-3 py-2 text-xs text-zinc-500`,children:`no messages yet`}),e&&e.length>0&&u&&(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`div`,{className:`border-b border-zinc-200 px-3 py-2 dark:border-zinc-800`,children:[(0,N.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,N.jsx)(`span`,{className:`text-sm font-semibold text-zinc-800 dark:text-zinc-200`,children:`Conversation tree`}),(0,N.jsxs)(`span`,{className:`text-xs text-zinc-400 dark:text-zinc-500`,children:[u.rows.length,` turn`,u.rows.length===1?``:`s`,` · `,u.branchPoints,` branch point`,u.branchPoints===1?``:`s`]})]}),(0,N.jsx)(`input`,{type:`search`,value:s,onChange:e=>c(e.target.value),placeholder:`Search tree`,"aria-label":`Search conversation tree`,className:`mt-2 w-full rounded-md border border-zinc-300 bg-transparent px-2 py-1 text-sm outline-none placeholder:text-zinc-400 focus:border-zinc-500 dark:border-zinc-700 dark:placeholder:text-zinc-600 dark:focus:border-zinc-500`}),(0,N.jsx)(`p`,{className:`mt-1.5 text-[11px] text-zinc-400 dark:text-zinc-500`,children:`Follow the colored lines — the current branch is highlighted. Click a turn to restore the conversation there · ↺ to send it again · ⑂ to fork a session`})]}),(0,N.jsx)(`div`,{className:`min-h-0 overflow-y-auto py-1`,children:d===null?u.rows.map(e=>(0,N.jsx)(oG,{row:e,laneCount:u.laneCount,isStreaming:t,onNavigate:r,onFork:i,onClose:()=>o(!1)},e.node.entryId)):d.length===0?(0,N.jsx)(`div`,{className:`px-3 py-2 text-xs text-zinc-500`,children:`no matches`}):d.map(e=>(0,N.jsxs)(`div`,{className:`group flex items-center gap-1 pr-2 hover:bg-zinc-100 dark:hover:bg-zinc-800/70`,children:[(0,N.jsxs)(`button`,{type:`button`,disabled:t,onClick:()=>{r(e.tipId??e.entryId),o(!1)},title:e.tipId?`restore the conversation at this point (reply included)`:`go back to this point`,className:`flex min-w-0 flex-1 items-center gap-2 px-3 py-1.5 text-left text-sm disabled:opacity-50`,children:[(0,N.jsx)(`span`,{"aria-hidden":!0,className:e.onPath?`text-emerald-500`:`text-zinc-300 dark:text-zinc-600`,children:`●`}),(0,N.jsx)(`span`,{className:`min-w-0 truncate text-zinc-700 dark:text-zinc-300`,children:e.text||`(empty)`}),e.onPath&&(0,N.jsx)(iG,{tone:`current`,children:`on current branch`}),e.label&&(0,N.jsx)(iG,{tone:`label`,children:e.label})]}),(0,N.jsx)(`button`,{type:`button`,disabled:t,onClick:()=>{r(e.entryId),o(!1)},title:`rewind to just before this message (its text comes back in the composer)`,"aria-label":`Rewind to before this message`,className:aG,children:`↺ redo`}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>{i(e.entryId),o(!1)},title:`fork a new session from this point`,className:aG,children:`⑂ fork`})]},e.entryId))})]})]})]})}var cG=200;function lG({initial:e,onCommit:t,onCancel:n}){let[r,i]=(0,v.useState)(e);return(0,N.jsx)(`input`,{autoFocus:!0,value:r,onChange:e=>i(e.target.value),onBlur:n,onKeyDown:e=>{e.key===`Enter`?t(r):e.key===`Escape`&&n()},placeholder:`Session name (empty to clear)`,"aria-label":`Session name`,className:`w-full rounded-md border border-zinc-400 bg-transparent px-2 py-1 text-sm outline-none placeholder:text-zinc-400 dark:border-zinc-600 dark:placeholder:text-zinc-600`})}function uG({session:e,isCurrent:t,renaming:n,onSwitch:r,onDelete:i,onStartRename:a,onRename:o,onCancelRename:s}){return n?(0,N.jsx)(`div`,{className:`px-3 py-2`,children:(0,N.jsx)(lG,{initial:e.name??``,onCommit:o,onCancel:s})}):(0,N.jsxs)(`div`,{className:`group flex items-start gap-1 hover:bg-zinc-100 dark:hover:bg-zinc-800 ${t?`bg-zinc-100 dark:bg-zinc-800/60`:``}`,children:[(0,N.jsxs)(`button`,{type:`button`,onClick:r,className:`min-w-0 flex-1 px-3 py-2 text-left text-sm`,children:[(0,N.jsx)(`div`,{className:`truncate text-zinc-700 dark:text-zinc-300`,children:e.name||e.firstMessage||`(empty)`}),e.snippet&&(0,N.jsx)(`div`,{className:`mt-0.5 truncate text-xs text-zinc-500 dark:text-zinc-500`,children:e.snippet}),(0,N.jsxs)(`div`,{className:`mt-0.5 text-xs text-zinc-400 dark:text-zinc-600`,children:[new Date(e.modified).toLocaleString(),` · `,e.messageCount,` messages`,t?` · current`:``,!t&&e.liveIn?(0,N.jsxs)(`span`,{"data-testid":`session-live-in`,children:[` · open in `,e.liveIn]}):null]})]}),(0,N.jsx)(`button`,{type:`button`,onClick:a,title:`rename session`,"aria-label":`Rename session`,className:`mt-2 rounded px-1.5 py-0.5 text-xs text-zinc-400 opacity-0 hover:bg-zinc-200 hover:text-zinc-700 focus-visible:opacity-100 group-hover:opacity-100 dark:text-zinc-600 dark:hover:bg-zinc-700 dark:hover:text-zinc-200`,children:`✎`}),!t&&!e.liveIn&&(0,N.jsx)(`button`,{type:`button`,onClick:i,title:`delete session`,"aria-label":`Delete session`,className:`mr-2 mt-2 rounded px-1.5 py-0.5 text-xs text-zinc-400 opacity-0 hover:bg-red-100 hover:text-red-600 focus-visible:opacity-100 group-hover:opacity-100 dark:text-zinc-600 dark:hover:bg-red-950/60 dark:hover:text-red-400`,children:`✕`})]})}function dG({sessions:e,sessionSearch:t,sessionId:n,onSwitchSession:r,onDeleteSession:i,onListSessions:a,onRenameSession:o,onSearchSessions:s,onClearSessionSearch:c}){let[l,u]=(0,v.useState)(!1),[d,f]=(0,v.useState)(``),[p,m]=(0,v.useState)(null),h=oH(()=>u(!1)),g=d.trim(),_=g.length>=2;(0,v.useEffect)(()=>{if(!l)return;if(!_){c();return}let e=setTimeout(()=>s(g),cG);return()=>clearTimeout(e)},[l,g,_]);function y(){u(!1),m(null)}let b=_&&(t?.status!==`loaded`||t.query!==g),x=_?b?null:t?.results??null:e;return(0,N.jsxs)(`div`,{className:`relative`,ref:h,children:[(0,N.jsx)(`button`,{type:`button`,onClick:()=>{l?y():(u(!0),f(``),m(null),c(),a())},className:`${lW} border-zinc-300 text-zinc-500 hover:border-zinc-400 hover:text-zinc-700 dark:border-zinc-800 dark:text-zinc-400 dark:hover:border-zinc-600 dark:hover:text-zinc-200`,children:`sessions`}),l&&(0,N.jsxs)(`div`,{className:`absolute right-0 top-full z-20 mt-1 flex max-h-96 w-96 flex-col rounded-lg border border-zinc-200 bg-white shadow-xl dark:border-zinc-700 dark:bg-zinc-900`,children:[(0,N.jsxs)(`div`,{className:`border-b border-zinc-200 px-3 py-2 dark:border-zinc-800`,children:[(0,N.jsx)(`input`,{type:`search`,value:d,onChange:e=>f(e.target.value),placeholder:`Search sessions`,"aria-label":`Search sessions`,className:`w-full rounded-md border border-zinc-300 bg-transparent px-2 py-1 text-sm outline-none placeholder:text-zinc-400 focus:border-zinc-500 dark:border-zinc-700 dark:placeholder:text-zinc-600 dark:focus:border-zinc-500`}),(0,N.jsx)(`p`,{className:`mt-1.5 text-[11px] text-zinc-400 dark:text-zinc-500`,children:`Searches names and everything said in a session · ✎ to rename`})]}),(0,N.jsxs)(`div`,{className:`min-h-0 overflow-y-auto`,children:[x===null&&(0,N.jsx)(`div`,{className:`px-3 py-2 text-xs text-zinc-500`,children:`loading…`}),x?.length===0&&(0,N.jsx)(`div`,{className:`px-3 py-2 text-xs text-zinc-500`,children:_?`no matches`:`no saved sessions`}),x?.map(e=>(0,N.jsx)(uG,{session:e,isCurrent:e.id===n,renaming:p===e.path,onSwitch:()=>{r(e.path),y()},onDelete:()=>{window.confirm(`Delete this session?`)&&i(e.path)},onStartRename:()=>m(e.path),onRename:t=>{o(e.path,t),m(null),_&&s(d.trim())},onCancelRename:()=>m(null)},e.path))]})]})]})}function fG({filters:e,onFilterChange:t}){let[n,r]=(0,v.useState)(!1),i=oH(()=>r(!1)),a=MV(e),o=a>0?`Filter · ${a} hidden`:`Filter`;return(0,N.jsxs)(`div`,{className:`relative`,ref:i,onKeyDown:e=>{e.key===`Escape`&&n&&(e.stopPropagation(),r(!1))},children:[(0,N.jsx)(`button`,{type:`button`,onClick:()=>r(!n),"aria-haspopup":`menu`,"aria-expanded":n,title:`Choose what the conversation shows`,className:`${lW} ${a>0?`border-zinc-400 bg-zinc-100 text-zinc-700 dark:border-zinc-600 dark:bg-zinc-800 dark:text-zinc-200`:`border-zinc-300 text-zinc-500 hover:border-zinc-400 hover:text-zinc-700 dark:border-zinc-800 dark:text-zinc-400 dark:hover:border-zinc-600 dark:hover:text-zinc-200`}`,children:o}),n&&(0,N.jsx)(`div`,{role:`menu`,className:`absolute right-0 z-30 mt-1 w-48 rounded-md border border-zinc-200 bg-white py-1 shadow-lg dark:border-zinc-700 dark:bg-zinc-900`,children:DV.map(n=>(0,N.jsxs)(`button`,{type:`button`,role:`menuitemcheckbox`,"aria-checked":e[n],onClick:()=>t(n,!e[n]),className:`flex w-full items-center gap-2 px-3 py-1.5 text-left text-xs text-zinc-600 hover:bg-zinc-100 dark:text-zinc-300 dark:hover:bg-zinc-800`,children:[(0,N.jsx)(`span`,{"aria-hidden":!0,className:`w-3`,children:e[n]?`✓`:``}),(0,N.jsx)(`span`,{children:OV[n]})]},n))})]})}function pG({statuses:e,bar:t}){let n=Object.entries(e).filter(([,e])=>IH(e).trim()!==``),r=n.map(([e,t])=>`${e}\u0000${t}`).join(``),[i,a]=(0,v.useState)(!1),o=(0,v.useRef)(null),s=(0,v.useRef)(null),[c,l]=(0,v.useState)(!1),u=oH(()=>l(!1));if((0,v.useLayoutEffect)(()=>{o.current=null,a(!1),l(!1)},[r]),(0,v.useLayoutEffect)(()=>{let e=t;if(e===null)return;let n=()=>{o.current===null?(Array.from(s.current?.querySelectorAll(`[data-status-text]`)??[]).some(e=>e.scrollWidth>e.clientWidth+1)||e.scrollWidth>e.clientWidth+1)&&(o.current=e.clientWidth,a(!0)):e.clientWidth>o.current+64&&(o.current=null,a(!1),l(!1))};if(n(),typeof ResizeObserver>`u`)return;let r=new ResizeObserver(n);return r.observe(e),()=>r.disconnect()},[t,i,r]),n.length===0)return null;if(!i)return(0,N.jsx)(`div`,{ref:s,className:`flex shrink-0 items-center gap-1.5`,children:n.map(([e,t])=>(0,N.jsx)(`span`,{title:IH(t),className:`${lW} max-w-[16rem] border-zinc-200 text-zinc-500 dark:border-zinc-800 dark:text-zinc-400`,children:(0,N.jsx)(`span`,{"data-status-text":!0,className:`truncate`,children:(0,N.jsx)(LH,{text:t})})},e))});let d=`${n.length} ${n.length===1?`status`:`statuses`}`;return(0,N.jsxs)(`div`,{ref:u,className:`relative shrink-0`,onKeyDown:e=>{e.key===`Escape`&&c&&(e.stopPropagation(),l(!1))},children:[(0,N.jsxs)(`button`,{type:`button`,onClick:()=>l(!c),"aria-expanded":c,title:n.map(([,e])=>IH(e)).join(`
1512
+ `),className:`${lW} border-zinc-200 text-zinc-500 hover:border-zinc-400 hover:text-zinc-700 dark:border-zinc-800 dark:text-zinc-400 dark:hover:border-zinc-600 dark:hover:text-zinc-200`,children:[d,` ▾`]}),c&&(0,N.jsx)(`ul`,{"aria-label":`Extension statuses`,className:`absolute left-0 top-full z-20 mt-1 w-max max-w-[24rem] rounded-md border border-zinc-200 bg-white py-1 shadow-lg dark:border-zinc-700 dark:bg-zinc-900`,children:n.map(([e,t])=>(0,N.jsx)(`li`,{className:`break-words px-3 py-1.5 text-xs text-zinc-600 dark:text-zinc-300`,children:(0,N.jsx)(LH,{text:t})},e))})]})}function mG({theme:e,preference:t=e,onToggle:n,onSetTheme:r}){let[i,a]=(0,v.useState)(!1),o=(0,v.useRef)(null),s=oH(()=>a(!1));(0,v.useEffect)(()=>{i&&s.current?.querySelector(`[aria-checked="true"]`)?.focus()},[i]);let c={light:`Light`,dark:`Dark`,system:`System`}[t];return(0,N.jsxs)(`div`,{ref:s,className:`relative`,onKeyDown:e=>{if(e.key===`Escape`&&(e.stopPropagation(),a(!1),o.current?.focus()),i&&[`ArrowDown`,`ArrowUp`,`Home`,`End`].includes(e.key)){e.preventDefault();let t=Array.from(s.current?.querySelectorAll(`[role="menuitemradio"]`)??[]),n=t.findIndex(e=>e.matches(`:focus`));t[e.key===`Home`?0:e.key===`End`?t.length-1:(n+(e.key===`ArrowDown`?1:-1)+t.length)%t.length]?.focus()}},children:[(0,N.jsx)(`button`,{ref:o,type:`button`,onClick:()=>a(e=>!e),title:`Theme: ${c}`,"aria-label":`Theme: ${c}`,"aria-haspopup":`menu`,"aria-expanded":i,className:`${lW} border-zinc-300 text-zinc-500 hover:border-zinc-400 hover:text-zinc-700 dark:border-zinc-800 dark:text-zinc-400 dark:hover:border-zinc-600 dark:hover:text-zinc-200`,children:t===`system`?`◐`:e===`dark`?`☾`:`☀`}),i&&(0,N.jsx)(`div`,{role:`menu`,"aria-label":`Theme`,className:`absolute right-0 top-full z-40 mt-2 min-w-32 rounded-lg border border-zinc-300 bg-white p-1 shadow-lg dark:border-zinc-700 dark:bg-zinc-900`,children:[`light`,`dark`,`system`].map(i=>(0,N.jsx)(`button`,{role:`menuitemradio`,"aria-checked":t===i,type:`button`,className:`block w-full rounded px-3 py-1.5 text-left text-xs text-zinc-700 hover:bg-zinc-100 focus:bg-zinc-100 dark:text-zinc-200 dark:hover:bg-zinc-800 dark:focus:bg-zinc-800`,onClick:()=>{r?r(i):i!==e&&n(),a(!1),o.current?.focus()},children:i===`light`?`Light`:i===`dark`?`Dark`:`System`},i))})]})}function hG(e){let{isStreaming:t,connected:n}=e,[r,i]=(0,v.useState)(null);return(0,N.jsxs)(`header`,{ref:i,className:`relative z-30 flex min-w-0 items-center gap-1.5 border-b border-zinc-200 px-4 py-2 dark:border-zinc-800`,children:[e.workspaceControl===`projects`&&(0,N.jsx)(gW,{workspace:e.workspace,workspaces:e.workspaces,locked:e.workspaceLocked,onSwitch:e.onSwitchWorkspace,onOpen:e.onOpenProject,onClose:e.onCloseProject,onOpenSide:e.onOpenSideSession}),e.workspaceControl===`root`&&e.rootControl&&(0,N.jsx)(yW,{sandbox:e.rootControl.sandbox,browse:e.rootControl.browse,applyState:e.rootControl.applyState,blocked:e.rootControl.blocked,onBrowse:e.rootControl.onBrowse,onCloseBrowser:e.rootControl.onCloseBrowser,onOpened:e.rootControl.onOpened,onSelect:e.rootControl.onSelect}),(0,N.jsxs)(`button`,{type:`button`,onClick:e.onToggleSidebar,title:e.sidebarOpen?`Hide files (panel opens on the left)`:`Show files`,"aria-pressed":e.sidebarOpen,className:`${lW} ${e.sidebarOpen?`border-zinc-400 bg-zinc-100 text-zinc-700 dark:border-zinc-600 dark:bg-zinc-800 dark:text-zinc-200`:`border-zinc-300 text-zinc-500 hover:border-zinc-400 hover:text-zinc-700 dark:border-zinc-800 dark:text-zinc-400 dark:hover:border-zinc-600 dark:hover:text-zinc-200`}`,children:[e.sidebarOpen?`◧`:`◨`,` files`]}),(0,N.jsxs)(`button`,{type:`button`,onClick:e.onToggleOutcome,"aria-pressed":e.outcomeOpen,title:`Review structured workspace Outcome`,className:`${lW} ${e.outcomeOpen?`border-zinc-400 bg-zinc-100 text-zinc-700 dark:border-zinc-600 dark:bg-zinc-800 dark:text-zinc-200`:e.workspace?.activity===`ready-for-review`?`border-amber-400 text-amber-700 dark:text-amber-300`:`border-zinc-300 text-zinc-500 hover:border-zinc-400 dark:border-zinc-800 dark:text-zinc-400`}`,children:[`Outcome`,e.workspace?.activity===`ready-for-review`?` •`:``]}),e.gitAvailable&&(0,N.jsx)(SW,{status:e.gitStatus,selected:e.gitSelectedPath,log:e.gitLog,onFetchLog:e.onFetchGitLog,onCloseLog:e.onCloseGitLog,onShowCommit:e.onShowCommit}),(0,N.jsx)(`span`,{title:e.title??void 0,className:`min-w-[2.25rem] shrink-[4] truncate whitespace-nowrap text-lg font-semibold leading-tight tracking-tight`,style:{color:`var(--accent, inherit)`},children:e.title??`π`}),(0,N.jsx)(pG,{statuses:e.statuses,bar:r}),(0,N.jsxs)(`div`,{className:`ml-auto flex shrink-0 items-center gap-1.5`,children:[(0,N.jsx)(fG,{filters:e.filters,onFilterChange:e.onFilterChange}),e.onExportConversation&&(0,N.jsx)(`button`,{type:`button`,onClick:e.onExportConversation,disabled:!!e.exportProgress,"aria-busy":!!e.exportProgress,title:`Save the whole conversation as one HTML file`,"aria-label":`Export the conversation as HTML`,className:`inline-flex h-7 shrink-0 items-center gap-1 whitespace-nowrap rounded-md border px-2 text-xs leading-none border-zinc-300 text-zinc-500 hover:border-zinc-400 hover:text-zinc-700 disabled:cursor-progress disabled:opacity-60 dark:border-zinc-800 dark:text-zinc-400 dark:hover:border-zinc-600 dark:hover:text-zinc-200`,children:e.exportProgress??`↓ html`}),e.onToggleTerminal&&(0,N.jsx)(`button`,{type:`button`,onClick:e.onToggleTerminal,title:e.terminalOpen?"Close Terminal (Ctrl+`)":"Open Terminal (Ctrl+`)","aria-pressed":e.terminalOpen,className:`inline-flex h-7 shrink-0 items-center gap-1 whitespace-nowrap rounded-md border px-2 text-xs leading-none ${e.terminalOpen?`border-zinc-400 bg-zinc-100 text-zinc-700 dark:border-zinc-600 dark:bg-zinc-800 dark:text-zinc-200`:`border-zinc-300 text-zinc-500 hover:border-zinc-400 hover:text-zinc-700 dark:border-zinc-800 dark:text-zinc-400 dark:hover:border-zinc-600 dark:hover:text-zinc-200`}`,children:`>_ terminal`}),e.showThemeToggle&&(0,N.jsx)(mG,{theme:e.theme,preference:e.themePreference,onSetTheme:e.onSetTheme,onToggle:e.onToggleTheme}),(0,N.jsx)(`button`,{type:`button`,onClick:e.onNewSession,title:`new session`,className:`${lW} border-emerald-300 text-emerald-700 hover:border-emerald-500 hover:text-emerald-600 dark:border-emerald-900 dark:text-emerald-400 dark:hover:border-emerald-600 dark:hover:text-emerald-300`,children:`+ new`}),(0,N.jsx)(sG,{tree:e.tree,isStreaming:t,onListTree:e.onListTree,onNavigate:e.onNavigateTree,onFork:e.onForkSession}),(0,N.jsx)(dG,{sessions:e.sessions,sessionSearch:e.sessionSearch,sessionId:e.sessionId,onSwitchSession:e.onSwitchSession,onDeleteSession:e.onDeleteSession,onListSessions:e.onListSessions,onRenameSession:e.onRenameSession,onSearchSessions:e.onSearchSessions,onClearSessionSearch:e.onClearSessionSearch}),(0,N.jsx)(tG,{credentials:e.credentials,login:e.login,onStartLogin:e.onStartLogin,onAnswerLogin:e.onAnswerLogin,onCancelLogin:e.onCancelLogin,onDismissLogin:e.onDismissLogin,onLogoutProvider:e.onLogoutProvider,extensionPaths:e.extensionPaths,configuredExtensionPaths:e.configuredExtensionPaths,userExtensionPaths:e.userExtensionPaths,extensionLock:e.extensionLock,piPackages:e.piPackages??null,piPackageUpdate:e.piPackageUpdate??null,canRestartServer:e.canRestartServer??!1,serverRestarting:e.serverRestarting??!1,...e.onCheckPiPackages?{onCheckPiPackages:e.onCheckPiPackages}:{},...e.onUpdatePiPackage?{onUpdatePiPackage:e.onUpdatePiPackage}:{},...e.onRestartServer?{onRestartServer:e.onRestartServer}:{},restartNeeded:e.restartNeeded??[],tools:e.tools??[],commands:e.commands??[],sandbox:e.sandbox,showRoots:!(e.workspaceControl===`projects`&&e.workspaces.filter(e=>!e.sideOf).length>1),gitUnavailable:e.gitUnavailable,userSkillPaths:e.userSkillPaths,serverBrowse:e.serverBrowse,applyState:e.settingsApply,agentResources:e.agentResources,agentResourceOperations:e.agentResourceOperations,versions:e.versions,onBrowseServerPath:e.onBrowseServerPath,onCloseServerBrowser:e.onCloseServerBrowser,pickerBlocked:e.settingsPickerBlocked,onPickerOpened:e.onSettingsPickerOpened,onRestartSession:e.onRestartSession,onUpdateConfig:e.onUpdateConfig,onSuggestAgentResourceClonePath:e.onSuggestAgentResourceClonePath,onCloneAgentResourceRepository:e.onCloneAgentResourceRepository,onEnrollAgentResourceRepository:e.onEnrollAgentResourceRepository,onSetAgentResourceSkills:e.onSetAgentResourceSkills,onRemoveAgentResourceRepository:e.onRemoveAgentResourceRepository,onRefreshAgentResourceRepositories:e.onRefreshAgentResourceRepositories,onUpdateAgentResourceRepository:e.onUpdateAgentResourceRepository}),(0,N.jsx)(`span`,{className:`h-2 w-2 rounded-full ${n?`bg-emerald-500`:`bg-red-500`}`,title:n?`connected`:`disconnected`})]})]})}function gG(e,t){let n=(0,v.useRef)(new Map);(0,v.useEffect)(()=>{if(typeof Notification>`u`)return;let r=e.filter(e=>e.needsAttention),i=r.filter(e=>GB(e)!==t);for(let e of[...n.current.keys()])r.some(t=>GB(t)===e)||n.current.delete(e);if(Notification.permission===`granted`&&(typeof document>`u`||document.visibilityState!==`visible`)){for(let e of i)if(n.current.get(GB(e))!==e.activity){n.current.set(GB(e),e.activity);try{let t=e.activity===`ready-for-review`;new Notification(t?`${e.name} is ready for review`:`${e.name} needs you`,{body:t?`Background work is ready for review.`:`The agent needs an answer to continue.`,tag:`pi-outpost:${GB(e)}`})}catch{}}}},[e,t])}var _G={"agent-directory":`read the agent directory (the provider keys)`,"beside-root":`read a file beside the root`,"write-beside-root":`write beside the root`,"signal-process":`signal another process of the server's user`,"server-environment":`inherit the server's environment`,"server-process-environment":`read the server's process environment (/proc)`,"unlisted-host":`reach a host not in sandbox.allowedHosts`,"direct-connection":`connect around the proxy`},vG=e=>e.map(e=>_G[e]??e),yG=e=>{let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleTimeString()};function bG(e,t){let n=t===`shell`?`The agent's shell`:`This terminal`;switch(e.state){case`checking`:return`${n} runs under ${e.runner||`a sandbox runner`}; its confinement is being checked.`;case`verified`:return[`${n} is confined by ${e.runner}, checked at ${yG(e.checkedAt)}. A command could not:`,...vG(e.refused).map(e=>`• ${e}`),...e.environmentReadable?[`The server's process environment is readable, and holds no secret.`]:[],...e.notChecked.length?[`Not checked:`,...e.notChecked.map(e=>`• ${_G[e.attempt]??e.attempt} — ${e.why}`)]:[]].join(`
1513
+ `);case`partial`:return[`${n} is confined by ${e.runner}, checked at ${yG(e.checkedAt)}, except one thing: a command can read the server's process environment, which holds ${e.exposed.join(`, `)}.`,`Move these out of the server's environment — provider keys belong in the agent directory.`,`A command could not:`,...vG(e.refused).map(e=>`• ${e}`)].join(`
1514
+ `);case`leaking`:return[`${n} is NOT confined as configured: under ${e.runner}, checked at ${yG(e.checkedAt)}, a command could:`,...vG(e.reached).map(e=>`• ${e}`),`The configuration is unchanged: fix the runner or its host, or stop using it.`].join(`
1515
+ `);case`failed`:return`${n}'s confinement could not be checked (${e.runner}, ${yG(e.checkedAt)}): ${e.reason}`;case`unavailable`:return e.reason||`${n} refuses every command.`;case`unconfined`:return e.sandboxOff?[`${n} is not confined by pi-outpost: the sandbox is turned off ("sandbox": false).`,`Unless an extension confines it, a command runs with every right of the server's account, and the file tools reach beyond the project.`,...e.available?[`${e.available.label} can confine it on this machine. To turn the sandbox back on, run:`,` pi-outpost config --confine`,`It checks ${e.available.label} first, then writes the default sandbox, which also limits the agent's file tools to the project.`]:[]].join(`
1516
+ `):e.available?[`${n} is NOT confined: a command runs with every right of the server's account.`,`${e.available.label} can confine it on this machine. To confine it, run:`,` pi-outpost config --confine`,`It checks ${e.available.label} first, then sets "sandbox.bashRunner": "auto" in the configuration file.`].join(`
1517
+ `):e.reason?`${n} is not confined, as configured: nothing can confine it on this machine — ${e.reason}`:`${n} is not confined, as configured.`}}function xG(e){let t=[...e.hosts.map(e=>`• host ${e}`),...e.directories.map(e=>`• ${e.access===`write`?`read and write`:`read`} ${e.path}`)];return t.length?[`Granted by you for this session:`,...t]:[]}function SG({verdict:e,surface:t,root:n,grants:r}){let i=n?` to ${n}`:``,a=r?r.hosts.length+r.directories.length:0,o=a>0?` · ${a} grant${a>1?`s`:``}`:``,s=e.state===`verified`?{icon:`🔒`,text:`confined${i}`,tone:`bg-emerald-100 text-emerald-800 dark:bg-emerald-900/50 dark:text-emerald-200`}:e.state===`partial`?{icon:`🔐`,text:`partly confined`,tone:`bg-amber-100 text-amber-800 dark:bg-amber-900/50 dark:text-amber-200`}:e.state===`leaking`?{icon:`🔓`,text:`not confined`,tone:`bg-red-100 text-red-800 dark:bg-red-900/50 dark:text-red-200`}:e.state===`failed`?{icon:`⚠`,text:`confinement unchecked`,tone:`bg-amber-100 text-amber-800 dark:bg-amber-900/50 dark:text-amber-200`}:e.state===`unavailable`?{icon:`⛔`,text:`unavailable`,tone:`bg-red-100 text-red-800 dark:bg-red-900/50 dark:text-red-200`}:e.state===`unconfined`?e.available?{icon:`🔓`,text:`not confined`,tone:`bg-amber-100 text-amber-800 ring-1 ring-amber-400 dark:bg-amber-900/50 dark:text-amber-200 dark:ring-amber-500`}:{icon:`🔓`,text:`not confined`,tone:`bg-zinc-100 text-zinc-600 dark:bg-zinc-800 dark:text-zinc-300`}:{icon:`…`,text:`checking confinement`,tone:`bg-zinc-100 text-zinc-600 dark:bg-zinc-800 dark:text-zinc-300`};return(0,N.jsxs)(`span`,{"data-testid":t===`shell`?`shell-confinement`:`terminal-confined`,"data-state":e.state,"data-nudge":e.state===`unconfined`&&e.available?`true`:void 0,"data-grants":a,title:[bG(e,t),...r?xG(r):[]].join(`
1518
+ `),className:`shrink-0 whitespace-nowrap rounded px-1.5 py-0.5 font-sans text-[11px] ${s.tone}`,children:[s.icon,` `,t===`shell`?`shell ${s.text}`:s.text,o]})}function CG(e){return!e||e.percent===null?`text-zinc-400 dark:text-zinc-600`:e.percent>=85?`text-red-500`:e.percent>=60?`text-amber-500 dark:text-amber-400`:`text-emerald-500`}function wG({usage:e,analysisOpen:t,onToggleAnalysis:n}){if(e.turns===0)return null;let r=e.turns-e.unpriced,i=[`${e.turns} turn${e.turns===1?``:`s`}`,`input ${e.input.toLocaleString()}`,`output ${e.output.toLocaleString()}`,`cache read ${e.cacheRead.toLocaleString()}`,`cache write ${e.cacheWrite.toLocaleString()}`,...e.unpriced>0&&r>0?[`${e.unpriced} unpriced`]:[]].join(` · `),a=(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`span`,{children:[QB(e.totalTokens),` tok`]}),r>0&&(0,N.jsxs)(`span`,{className:`text-zinc-400 dark:text-zinc-500`,children:[ZB(e.cost),e.unpriced>0&&`*`]})]}),o=`flex items-center gap-1.5 rounded-md border px-2 py-1 font-mono text-xs text-zinc-500 dark:text-zinc-400`;return n?(0,N.jsx)(`button`,{type:`button`,onClick:n,title:`${i} — click for the session analysis`,"aria-haspopup":`dialog`,"aria-expanded":t??!1,className:`${o} ${t?`border-zinc-400 dark:border-zinc-600`:`border-zinc-300 hover:border-zinc-400 dark:border-zinc-800 dark:hover:border-zinc-600`}`,children:a}):(0,N.jsx)(`span`,{title:i,className:`${o} border-zinc-300 dark:border-zinc-800`,children:a})}function TG({usage:e}){let t=15.9155,n=2*Math.PI*t,r=e?.percent??0,i=Math.min(100,Math.max(0,r))/100*n;return(0,N.jsxs)(`svg`,{width:18,height:18,viewBox:`0 0 36 36`,className:`-rotate-90 shrink-0`,children:[(0,N.jsx)(`circle`,{cx:`18`,cy:`18`,r:t,fill:`none`,stroke:`currentColor`,strokeWidth:`4`,className:`text-zinc-200 dark:text-zinc-800`}),e&&e.percent!==null&&(0,N.jsx)(`circle`,{cx:`18`,cy:`18`,r:t,fill:`none`,stroke:`currentColor`,strokeWidth:`4`,strokeLinecap:`round`,strokeDasharray:`${i} ${n-i}`,className:CG(e)})]})}function EG({thinkingLevel:e,thinkingLevels:t,isStreaming:n,onSetThinking:r}){let[i,a]=(0,v.useState)(!1),o=(0,v.useRef)(null),s=e!==`off`,c=t&&t.length>0?t:jU,l=c.indexOf(e),u=c.length>1;return(0,v.useEffect)(()=>{if(!i)return;function e(e){o.current&&!aH(e,o.current)&&a(!1)}function t(e){e.key===`Escape`&&a(!1)}return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[i]),(0,N.jsxs)(`div`,{className:`relative`,ref:o,children:[(0,N.jsxs)(`button`,{type:`button`,onClick:()=>a(!i),disabled:n,title:`thinking level`,"aria-haspopup":`true`,"aria-expanded":i,className:`flex items-center gap-1.5 rounded-md border px-2 py-1 font-mono text-xs disabled:opacity-50 ${s?`border-amber-300 text-amber-700 hover:border-amber-400 dark:border-amber-900 dark:text-amber-400 dark:hover:border-amber-700`:`border-zinc-300 text-zinc-500 hover:border-zinc-400 dark:border-zinc-800 dark:text-zinc-400 dark:hover:border-zinc-600`}`,children:[(0,N.jsx)(`span`,{"aria-hidden":!0,className:`text-sm leading-none ${s?``:`opacity-40 grayscale`}`,children:`🧠`}),e]}),i&&(0,N.jsxs)(`div`,{className:`absolute bottom-full left-0 z-20 mb-1 w-48 rounded-lg border border-zinc-200 bg-white p-3 shadow-xl dark:border-zinc-700 dark:bg-zinc-900`,children:[(0,N.jsxs)(`div`,{className:`mb-1 flex items-baseline justify-between text-xs`,children:[(0,N.jsx)(`span`,{className:`text-zinc-500 dark:text-zinc-400`,children:`thinking`}),(0,N.jsx)(`span`,{className:`font-mono text-zinc-700 dark:text-zinc-200`,children:e})]}),u?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`input`,{type:`range`,min:0,max:c.length-1,step:1,value:l===-1?0:l,onChange:e=>r(c[Number(e.target.value)]),"aria-label":`Thinking level`,"aria-valuetext":e,className:`w-full accent-amber-500`}),(0,N.jsxs)(`div`,{className:`mt-0.5 flex justify-between font-mono text-[9px] text-zinc-400 dark:text-zinc-600`,children:[(0,N.jsx)(`span`,{children:c[0]}),(0,N.jsx)(`span`,{children:c[c.length-1]})]})]}):(0,N.jsxs)(`p`,{className:`text-[11px] text-zinc-500 dark:text-zinc-400`,children:[`this model accepts `,(0,N.jsx)(`span`,{className:`font-mono`,children:c[0]}),` only`]})]})]})}function DG(e){let{model:t,models:n,thinkingLevel:r,modelSupportsReasoning:i,isStreaming:a,contextUsage:o,sessionUsage:s,isCompacting:c}=e;return(0,N.jsxs)(`div`,{className:`mt-2 flex items-center gap-2`,children:[(0,N.jsxs)(`select`,{value:t,onChange:t=>{let r=n.find(e=>`${e.provider}/${e.id}`===t.target.value);r&&e.onSetModel(r.provider,r.id)},disabled:a,className:`max-w-64 rounded-md border border-zinc-300 bg-white px-2 py-1 font-mono text-xs text-zinc-700 outline-none hover:border-zinc-400 disabled:opacity-50 dark:border-zinc-800 dark:bg-zinc-900 dark:text-zinc-300 dark:hover:border-zinc-600`,children:[!n.some(e=>`${e.provider}/${e.id}`===t)&&(0,N.jsx)(`option`,{value:t,children:t}),n.map(e=>(0,N.jsxs)(`option`,{value:`${e.provider}/${e.id}`,children:[e.provider,`/`,e.id]},`${e.provider}/${e.id}`))]}),i&&(0,N.jsx)(EG,{thinkingLevel:r,thinkingLevels:e.thinkingLevels,isStreaming:a,onSetThinking:e.onSetThinking}),e.shellConfinement&&(0,N.jsx)(`span`,{className:`ml-auto`,children:(0,N.jsx)(SG,{verdict:e.shellConfinement,surface:`shell`,grants:e.shellGrants})}),(0,N.jsxs)(`button`,{type:`button`,onClick:e.onCompact,disabled:a||c,title:o?.tokens==null?`Click to compact the conversation context`:`${o.tokens.toLocaleString()} / ${o.contextWindow.toLocaleString()} tokens — click to compact`,className:`${e.shellConfinement?``:`ml-auto `}flex items-center gap-1.5 rounded-md border border-zinc-300 px-2 py-1 font-mono text-xs text-zinc-500 hover:border-zinc-400 disabled:opacity-50 dark:border-zinc-800 dark:text-zinc-400 dark:hover:border-zinc-600`,children:[(0,N.jsx)(TG,{usage:o}),c?`compacting…`:o?.percent==null?`context`:`${Math.round(o.percent)}%`]}),(0,N.jsx)(wG,{usage:s,analysisOpen:e.analysisOpen,onToggleAnalysis:e.onToggleAnalysis})]})}var OG=`w-full rounded-md border border-zinc-300 bg-white px-3 py-2 text-sm text-zinc-800 placeholder:text-zinc-400 focus:border-zinc-400 focus:outline-none dark:border-zinc-700 dark:bg-zinc-900 dark:text-zinc-100 dark:placeholder:text-zinc-600`,kG=`mb-1 block text-xs font-medium text-zinc-600 dark:text-zinc-400`;function AG({title:e,credentials:t,onSetCredential:n,onStartLogin:r,login:i,onAnswerLogin:a,onCancelLogin:o,onDismissLogin:s,onDeclareProvider:c,errors:l}){let u=t.providers,[d,f]=(0,v.useState)(u.length>0?`known`:`custom`),[p,m]=(0,v.useState)(u[0]?.id??``),[h,g]=(0,v.useState)(``),[_,y]=(0,v.useState)(``),[b,x]=(0,v.useState)(``),[S,C]=(0,v.useState)(``),[w,T]=(0,v.useState)(!0),[E,D]=(0,v.useState)(!0);function O(e){i?.provider===e?(i.done||o(),s()):(i&&(i.done||o(),s()),r(e,`oauth`))}let ee=u.some(e=>e.configured)&&!t.usableModel;function te(e){e.preventDefault(),!ee&&(d===`known`?p&&h.trim()&&n(p,h.trim()):_.trim()&&b.trim()&&h.trim()&&S.trim()&&c({provider:_.trim(),baseUrl:b.trim(),apiKey:h.trim(),models:[S.trim()],compat:{supportsDeveloperRole:w,supportsReasoningEffort:E}}))}return(0,N.jsx)(`div`,{className:`flex h-full items-center justify-center overflow-auto p-6`,children:(0,N.jsxs)(`form`,{onSubmit:te,className:`w-full max-w-md rounded-xl border border-zinc-200 p-6 shadow-sm dark:border-zinc-800`,children:[(0,N.jsx)(`div`,{className:`mb-1 text-center text-3xl`,children:e??`π`}),ee?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`h1`,{className:`mb-3 text-center text-sm text-zinc-500 dark:text-zinc-400`,children:`No model is available.`}),(0,N.jsxs)(`p`,{className:`text-sm text-zinc-600 dark:text-zinc-400`,children:[`Credentials are configured, so this is not a missing key: `,(0,N.jsx)(`code`,{children:`allowedModels`}),` in your configuration leaves nothing to choose from. Widen it, or remove it, then restart.`]})]}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`h1`,{className:`mb-4 text-center text-sm text-zinc-500 dark:text-zinc-400`,children:`No model provider is set up yet. Add one to start chatting.`}),(0,N.jsx)(`div`,{className:`mb-4 flex gap-1 rounded-lg bg-zinc-100 p-1 text-xs dark:bg-zinc-800`,children:[`known`,`custom`].map(e=>(0,N.jsx)(`button`,{type:`button`,onClick:()=>f(e),className:`flex-1 rounded-md px-2 py-1.5 ${d===e?`bg-white font-medium text-zinc-800 shadow-sm dark:bg-zinc-900 dark:text-zinc-100`:`text-zinc-500 dark:text-zinc-400`}`,children:e===`known`?`Provider API key`:`OpenAI-compatible endpoint`},e))}),t.signIn&&u.some(e=>e.methods?.includes(`oauth`))&&(0,N.jsxs)(`section`,{className:`mb-4 rounded-lg border border-zinc-200 p-3 dark:border-zinc-800`,"data-testid":`onboarding-account-signin`,children:[(0,N.jsx)(`h2`,{className:`mb-2 text-xs font-medium text-zinc-700 dark:text-zinc-300`,children:`Sign in with an account`}),(0,N.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:u.filter(e=>e.methods?.includes(`oauth`)).map(e=>{let t=i?.provider===e.id;return(0,N.jsx)(`button`,{type:`button`,"aria-expanded":t,"aria-controls":`onboarding-login-flow-${e.id}`,className:`rounded border px-3 py-2 text-xs ${t?`border-sky-500 bg-sky-50 text-sky-800 dark:bg-sky-950/40 dark:text-sky-200`:``}`,onClick:()=>O(e.id),children:e.name},e.id)})}),i&&(0,N.jsx)(`div`,{id:`onboarding-login-flow-${i.provider}`,className:`mt-3`,children:(0,N.jsx)(ZW,{login:i,providerName:u.find(e=>e.id===i.provider)?.name??i.provider,onAnswer:a,onCancel:o,onDismiss:s})})]}),d===`known`?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`label`,{htmlFor:`onboarding-provider`,className:kG,children:`Provider`}),(0,N.jsx)(`select`,{id:`onboarding-provider`,value:p,onChange:e=>m(e.target.value),className:`${OG} mb-3`,children:u.map(e=>(0,N.jsxs)(`option`,{value:e.id,children:[e.name,e.configured?` (already configured)`:``]},e.id))})]}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`label`,{htmlFor:`onboarding-name`,className:kG,children:`Name`}),(0,N.jsx)(`input`,{id:`onboarding-name`,value:_,onChange:e=>y(e.target.value),placeholder:`corp`,className:`${OG} mb-3`}),(0,N.jsx)(`label`,{htmlFor:`onboarding-url`,className:kG,children:`Base URL`}),(0,N.jsx)(`input`,{id:`onboarding-url`,value:b,onChange:e=>x(e.target.value),placeholder:`https://llm.corp.example/v1`,className:`${OG} mb-3`}),(0,N.jsx)(`label`,{htmlFor:`onboarding-model`,className:kG,children:`Model id`}),(0,N.jsx)(`input`,{id:`onboarding-model`,value:S,onChange:e=>C(e.target.value),placeholder:`gpt-oss-120b`,className:`${OG} mb-3`})]}),(0,N.jsx)(`label`,{htmlFor:`onboarding-key`,className:kG,children:`API key`}),(0,N.jsx)(`input`,{id:`onboarding-key`,type:`password`,autoComplete:`off`,value:h,onChange:e=>g(e.target.value),placeholder:`sk-…`,className:OG}),d===`custom`&&(0,N.jsxs)(`fieldset`,{className:`mt-4 rounded-lg border border-zinc-200 p-3 dark:border-zinc-800`,children:[(0,N.jsx)(`legend`,{className:`px-1 text-xs text-zinc-500 dark:text-zinc-400`,children:`Compatibility`}),(0,N.jsxs)(`label`,{className:`flex items-start gap-2 text-xs text-zinc-600 dark:text-zinc-400`,children:[(0,N.jsx)(`input`,{type:`checkbox`,checked:w,onChange:e=>T(e.target.checked),className:`mt-0.5`}),(0,N.jsxs)(`span`,{children:[`Server understands the `,(0,N.jsx)(`code`,{children:`developer`}),` role. Uncheck for vLLM, SGLang and most corporate gateways — the system prompt is then sent as a `,(0,N.jsx)(`code`,{children:`system`}),` message.`]})]}),(0,N.jsxs)(`label`,{className:`mt-2 flex items-start gap-2 text-xs text-zinc-600 dark:text-zinc-400`,children:[(0,N.jsx)(`input`,{type:`checkbox`,checked:E,onChange:e=>D(e.target.checked),className:`mt-0.5`}),(0,N.jsxs)(`span`,{children:[`Server accepts `,(0,N.jsx)(`code`,{children:`reasoning_effort`}),`. Uncheck if it rejects unknown fields.`]})]})]}),(0,N.jsx)(`button`,{type:`submit`,className:`mt-4 w-full rounded-md bg-zinc-800 px-3 py-2 text-sm font-medium text-white hover:bg-zinc-700 dark:bg-zinc-100 dark:text-zinc-900 dark:hover:bg-white`,children:`Save and start`})]}),l.map((e,t)=>(0,N.jsx)(`p`,{className:`mt-3 rounded-md border border-amber-300 bg-amber-50 px-3 py-2 text-xs text-amber-700 dark:border-amber-900/60 dark:bg-amber-950/30 dark:text-amber-300`,children:e},t)),(0,N.jsxs)(`p`,{className:`mt-4 text-center text-xs text-zinc-400 dark:text-zinc-600`,children:[t.agentDir?`Stored in ${t.agentDir}. `:``,`Provider environment variables work too, as does `,(0,N.jsx)(`code`,{children:`pi-outpost login`}),`.`]})]})})}function jG({query:e,onQueryChange:t,search:n,onSearch:r,onOpenHit:i,onClose:a}){let o=(0,v.useRef)(null);(0,v.useEffect)(()=>{o.current?.focus()},[]);let s=NG(n?.hits??[]);return(0,N.jsxs)(`div`,{className:`flex flex-col gap-2`,"data-content-search":!0,children:[(0,N.jsxs)(`form`,{role:`search`,"aria-label":`Search in files`,className:`flex items-center gap-1`,onSubmit:t=>{t.preventDefault(),r(e)},children:[(0,N.jsx)(`input`,{ref:o,type:`search`,value:e,onChange:e=>t(e.target.value),onKeyDown:e=>{e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),a())},placeholder:`Search in files`,"aria-label":`Text to search for in files`,className:`min-w-0 flex-1 rounded border border-zinc-300 bg-white px-2 py-1 text-xs text-zinc-800 outline-none focus:border-zinc-500 dark:border-zinc-700 dark:bg-zinc-900 dark:text-zinc-200`}),(0,N.jsx)(`button`,{type:`button`,onClick:a,title:`Back to the file tree`,"aria-label":`Close the search`,className:`rounded px-1 py-0.5 text-xs text-zinc-400 hover:bg-zinc-100 hover:text-zinc-600 dark:text-zinc-600 dark:hover:bg-zinc-800 dark:hover:text-zinc-400`,children:`×`})]}),n&&(0,N.jsx)(MG,{search:n,fileCount:s.length}),n?.status===`loaded`&&s.length>0&&(0,N.jsx)(`ul`,{"aria-label":`Search results`,className:`flex flex-col gap-2`,children:s.map(([e,t])=>(0,N.jsxs)(`li`,{children:[(0,N.jsxs)(`div`,{className:`flex items-baseline gap-1 px-1 text-xs font-medium text-zinc-700 dark:text-zinc-300`,title:e,children:[(0,N.jsx)(`span`,{className:`min-w-0 truncate`,children:e}),(0,N.jsx)(`span`,{className:`shrink-0 text-zinc-400 dark:text-zinc-600`,children:t.length})]}),(0,N.jsx)(`ul`,{children:t.map(t=>(0,N.jsx)(`li`,{children:(0,N.jsxs)(`button`,{type:`button`,onClick:()=>i(t,n.query),"aria-label":`${e}, ${t.kind===`line`?`line ${t.line}`:`page ${t.page}`}`,className:`flex w-full gap-2 rounded px-1 py-0.5 text-left text-xs hover:bg-zinc-100 dark:hover:bg-zinc-800`,children:[(0,N.jsx)(`span`,{className:`w-10 shrink-0 text-right tabular-nums text-zinc-400 dark:text-zinc-600`,children:t.kind===`line`?t.line:`p. ${t.page}`}),(0,N.jsx)(`span`,{className:`min-w-0 break-words font-mono text-zinc-600 dark:text-zinc-400`,children:PG(t.excerpt,n.query)})]})},t.kind===`line`?`l${t.line}`:`p${t.page}`))})]},e))})]})}function MG({search:e,fileCount:t}){if(e.status===`loading`)return(0,N.jsx)(`p`,{role:`status`,className:`px-1 text-xs text-zinc-500`,children:`Searching…`});let n=[];return e.truncated&&n.push(`The search stopped early: these are partial results. Narrow the query to see everything.`),e.skipped>0&&n.push(`${e.skipped} PDF${e.skipped===1?``:`s`} could not be read.`),(0,N.jsxs)(`div`,{role:`status`,className:`flex flex-col gap-1 px-1 text-xs text-zinc-500`,children:[(0,N.jsx)(`p`,{children:e.hits.length===0?`No matches`:`${e.hits.length} match${e.hits.length===1?``:`es`} in ${t} file${t===1?``:`s`}`}),n.map(e=>(0,N.jsx)(`p`,{className:`text-amber-700 dark:text-amber-400`,children:e},e))]})}function NG(e){let t=new Map;for(let n of e){let e=t.get(n.path);e?e.push(n):t.set(n.path,[n])}return[...t]}function PG(e,t){let n=t.trim().toLowerCase();if(n===``)return e;let r=e.toLowerCase(),i=[],a=0;for(let t=r.indexOf(n);t!==-1;t=r.indexOf(n,a))t>a&&i.push(e.slice(a,t)),i.push((0,N.jsx)(`mark`,{className:`rounded-sm bg-amber-200 text-zinc-900 dark:bg-amber-700/60 dark:text-zinc-100`,children:e.slice(t,t+n.length)},t)),a=t+n.length;return a<e.length&&i.push(e.slice(a)),i}var FG=`application/x-pi-outpost-file`,IG=`application/x-pi-outpost-read-only-file`,LG=`mr-1 shrink-0 rounded px-1 text-xs text-zinc-400 hover:bg-zinc-200 group-hover:opacity-100 focus-visible:opacity-100 dark:text-zinc-600 dark:hover:bg-zinc-700 [@media(hover:hover)]:opacity-0`,RG={modified:{label:`M`,className:`text-amber-600 dark:text-amber-400`},added:{label:`A`,className:`text-emerald-600 dark:text-emerald-400`},untracked:{label:`U`,className:`text-emerald-600 dark:text-emerald-400`},deleted:{label:`D`,className:`text-red-600 dark:text-red-400`},conflicted:{label:`C`,className:`text-purple-600 dark:text-purple-400`}};function zG(e,t){return t?Object.keys(t).filter(t=>t.startsWith(`${e}/`)).length:0}function BG(e){return e===`directory`||e===`symlink-directory`}function VG(e,t){return t===void 0?!1:t===null||t!==``&&e!==t&&!e.startsWith(`${t}/`)}function HG({dir:e,depth:t,creation:n}){let[r,i]=(0,v.useState)(``),a=(0,v.useRef)(null),o=n.localError??n.serverError;return(0,v.useEffect)(()=>{a.current?.focus()},[]),(0,N.jsxs)(`div`,{style:{paddingLeft:t*12+4},className:`py-0.5`,children:[(0,N.jsx)(`input`,{ref:a,value:r,onChange:e=>i(e.target.value),onKeyDown:t=>{t.key===`Enter`?(t.preventDefault(),n.submit(e,r)):t.key===`Escape`&&(t.preventDefault(),n.cancel())},onBlur:()=>{o===null&&n.cancel()},placeholder:`name, or name/ for a folder`,"aria-label":`New file or folder in ${e===``?`the workspace root`:e}`,spellCheck:!1,className:`w-full rounded border border-zinc-300 bg-white px-1 py-0.5 text-xs text-zinc-800 outline-none focus:border-zinc-400 dark:border-zinc-700 dark:bg-zinc-900 dark:text-zinc-200`}),o!==null&&(0,N.jsx)(`p`,{className:`px-1 pt-0.5 text-xs text-red-600 dark:text-red-400`,children:o})]})}function UG({path:e,name:t,depth:n,rename:r}){let[i,a]=(0,v.useState)(t),o=(0,v.useRef)(null),s=r.localError??r.serverError;return(0,v.useEffect)(()=>{o.current?.focus(),o.current?.select()},[]),(0,N.jsxs)(`div`,{style:{paddingLeft:n*12+16},className:`py-0.5`,children:[(0,N.jsx)(`input`,{ref:o,value:i,disabled:r.pending,onChange:e=>a(e.target.value),onKeyDown:t=>{t.key===`Enter`&&!r.pending?(t.preventDefault(),r.submit(e,i)):t.key===`Escape`&&(t.preventDefault(),r.cancel())},onBlur:()=>{s===null&&r.cancel()},"aria-label":`Rename ${t}`,spellCheck:!1,className:`w-full rounded border border-zinc-300 bg-white px-1 py-0.5 text-xs text-zinc-800 outline-none focus:border-zinc-400 dark:border-zinc-700 dark:bg-zinc-900 dark:text-zinc-200`}),s!==null&&(0,N.jsx)(`p`,{className:`px-1 pt-0.5 text-xs text-red-600 dark:text-red-400`,children:s})]})}function WG({path:e,depth:t,...n}){let r=n.tree[e],i=n.creation?.openIn===e?(0,N.jsx)(HG,{dir:e,depth:t,creation:n.creation}):null;return r===void 0?i:r===`loading`?(0,N.jsxs)(N.Fragment,{children:[i,(0,N.jsx)(`div`,{style:{paddingLeft:t*12+4},className:`py-0.5 text-xs text-zinc-400 dark:text-zinc-600`,children:`loading…`})]}):`error`in r?(0,N.jsxs)(N.Fragment,{children:[i,(0,N.jsx)(`div`,{style:{paddingLeft:t*12+4},className:`py-0.5 text-xs text-red-600 dark:text-red-400`,children:r.error})]}):r.length===0?(0,N.jsxs)(N.Fragment,{children:[i,i===null&&(0,N.jsx)(`div`,{style:{paddingLeft:t*12+4},className:`py-0.5 text-xs text-zinc-400 dark:text-zinc-600`,children:`empty`})]}):(0,N.jsxs)(N.Fragment,{children:[i,r.map(r=>(0,N.jsx)(GG,{parentPath:e,entry:r,depth:t,...n},r.name))]})}function GG({parentPath:e,entry:t,depth:n,...r}){let[i,a]=(0,v.useState)(!1),[o,s]=(0,v.useState)(!1),c=e?`${e}/${t.name}`:t.name,l=VG(c,r.writableRoot),u=r.fileOperation?.status===`pending`;if(BG(t.type)){let e=!l&&!u&&!r.imports?.pending,d=e=>e.includes(IG)?r.onCopyFile===void 0?null:`copy`:r.onMoveFile===void 0?null:`move`;return(0,N.jsxs)(`div`,{children:[(0,N.jsxs)(`div`,{className:`group flex w-full items-center rounded hover:bg-zinc-100 dark:hover:bg-zinc-800 ${o&&e?`bg-blue-50 ring-1 ring-blue-400 dark:bg-blue-950/40`:``}`,"data-drop-directory":c,onDragOver:t=>{let n=Array.from(t.dataTransfer.types);if(n.includes(`Files`)&&!n.includes(FG)&&r.imports){t.preventDefault(),t.stopPropagation(),t.dataTransfer.dropEffect=e?`copy`:`none`,s(e);return}if(!e||!Array.from(t.dataTransfer.types).includes(FG))return;let i=d(Array.from(t.dataTransfer.types));i!==null&&(t.preventDefault(),t.stopPropagation(),t.dataTransfer.dropEffect=i,s(!0))},onDragLeave:e=>{e.currentTarget.contains(e.relatedTarget)||s(!1)},onDrop:t=>{let n=Array.from(t.dataTransfer.types);if(n.includes(`Files`)&&!n.includes(FG)&&r.imports){t.preventDefault(),t.stopPropagation(),s(!1),e&&(a(!0),r.tree[c]===void 0&&r.onExpand(c),r.imports.start(c,t.dataTransfer));return}if(!e)return;let i=t.dataTransfer.getData(FG),o=i?d(Array.from(t.dataTransfer.types)):null;o!==null&&(t.preventDefault(),t.stopPropagation(),s(!1),o===`copy`?r.onCopyFile?.(i,c):r.onMoveFile?.(i,c))},children:[(0,N.jsxs)(`button`,{type:`button`,onClick:()=>{let e=!i;a(e),e&&r.tree[c]===void 0&&r.onExpand(c),r.onSelectDirectory?.(c)},style:{paddingLeft:n*12},className:`flex min-w-0 flex-1 items-center gap-1 rounded py-0.5 text-left`,children:[(0,N.jsx)(`span`,{className:`w-3 shrink-0 text-xs text-zinc-400 dark:text-zinc-600`,children:i?`▾`:`▸`}),(0,N.jsx)(`span`,{title:t.name,className:`truncate ${l?`text-zinc-400 dark:text-zinc-600`:`text-zinc-700 dark:text-zinc-300`}`,children:t.name}),!i&&zG(c,r.gitFiles)>0&&(0,N.jsx)(`span`,{className:`ml-1 shrink-0 rounded bg-amber-100 px-1 font-mono text-[10px] font-bold text-amber-700 dark:bg-amber-950/60 dark:text-amber-400`,title:`${zG(c,r.gitFiles)} changed file(s) inside`,children:zG(c,r.gitFiles)})]}),r.onRevealNative&&(0,N.jsx)(`button`,{type:`button`,disabled:u,onClick:()=>r.onRevealNative?.(c),title:`Show in the file manager`,"aria-label":`Show ${t.name} in the file manager`,className:LG,children:`⌂`}),r.creation&&!l&&(0,N.jsx)(`button`,{type:`button`,onClick:()=>{a(!0),r.tree[c]===void 0&&r.onExpand(c),r.creation?.start(c)},title:`New file or folder here`,"aria-label":`New file or folder in ${t.name}`,className:`mr-1 shrink-0 rounded px-1 font-mono text-xs text-zinc-400 hover:bg-zinc-200 group-hover:opacity-100 focus-visible:opacity-100 dark:text-zinc-600 dark:hover:bg-zinc-700 [@media(hover:hover)]:opacity-0`,children:`+`})]}),i&&(0,N.jsx)(WG,{path:c,depth:n+1,...r})]})}let d=c===r.openFilePath,f=r.gitFiles?.[c],p=r.attachedPaths?.includes(c)??!1,m=t.type===`file`,h=m||t.type===`symlink-file`,g=m&&!l,_=m&&(l?r.onCopyFile!==void 0:r.onMoveFile!==void 0);return r.rename?.path===c?(0,N.jsx)(UG,{path:c,name:t.name,depth:n,rename:r.rename}):(0,N.jsxs)(`div`,{className:`group flex w-full items-center rounded hover:bg-zinc-100 dark:hover:bg-zinc-800 ${d?`bg-zinc-100 dark:bg-zinc-800`:``}`,children:[(0,N.jsx)(`button`,{type:`button`,draggable:_&&!u,onDragStart:e=>{_&&!u&&(e.dataTransfer.effectAllowed=l?`copy`:`move`,e.dataTransfer.setData(FG,c),l&&e.dataTransfer.setData(IG,`copy`))},onClick:()=>r.onSelectFile(c),style:{paddingLeft:n*12+16},className:`flex min-w-0 flex-1 items-center py-0.5 text-left`,children:(0,N.jsx)(`span`,{title:t.name,className:`truncate ${l?`text-zinc-400 dark:text-zinc-600`:`text-zinc-600 dark:text-zinc-400`}`,children:t.name})}),h&&r.onOpenNative&&(0,N.jsx)(`button`,{type:`button`,disabled:u,onClick:()=>r.onOpenNative?.(c),title:`Open with the associated application`,"aria-label":`Open ${t.name} with the associated application`,className:LG,children:`↗`}),r.onRevealNative&&(0,N.jsx)(`button`,{type:`button`,disabled:u,onClick:()=>r.onRevealNative?.(c),title:`Show in the file manager`,"aria-label":`Show ${t.name} in the file manager`,className:LG,children:`⌂`}),g&&r.onRenameFile&&(0,N.jsx)(`button`,{type:`button`,disabled:u,onClick:()=>r.rename?.start(c),title:`Rename file`,"aria-label":`Rename ${t.name}`,className:LG,children:`✎`}),g&&r.onDeleteFile&&(0,N.jsx)(`button`,{type:`button`,disabled:u,onClick:()=>{window.confirm(`Delete "${t.name}" permanently?`)&&r.onDeleteFile?.(c)},title:`Delete file`,"aria-label":`Delete ${t.name}`,className:`${LG} hover:text-red-600 dark:hover:text-red-400`,children:`×`}),r.onToggleAttachPath&&(0,N.jsx)(`button`,{type:`button`,onClick:()=>r.onToggleAttachPath?.(c),title:p?`Remove this file from the prompt`:`Reference this file in the prompt`,"aria-label":`${p?`Remove`:`Reference`} ${t.name} in the prompt`,"aria-pressed":p,className:`mr-1 shrink-0 rounded px-1 font-mono text-xs hover:bg-zinc-200 group-hover:opacity-100 focus-visible:opacity-100 dark:hover:bg-zinc-700 ${p?`font-bold text-blue-600 dark:text-blue-400`:`text-zinc-400 dark:text-zinc-600 [@media(hover:hover)]:opacity-0`}`,children:`@`}),f&&(0,N.jsx)(`button`,{type:`button`,onClick:()=>(r.onSelectDiff??r.onSelectFile)(c),title:`Show uncommitted diff`,"aria-label":`Show diff of ${t.name}`,className:`mr-1 shrink-0 rounded px-1 font-mono text-xs font-bold hover:bg-zinc-200 dark:hover:bg-zinc-700 ${RG[f].className}`,children:RG[f].label})]})}function KG(e){let t=e.trim();if(t===``)return{error:`A name is required`};let n=t.endsWith(`/`),r=n?t.slice(0,-1).trim():t;return r===``?{error:`A name is required`}:r.includes(`/`)||r.includes(`\\`)?{error:`That is a path, not a name`}:r===`.`||r===`..`?{error:`"${r}" is not a name`}:{kind:n?`directory`:`file`,name:r}}function qG(e){let t=KG(e);return`error`in t?t:t.kind===`directory`?{error:`That is a folder name`}:{name:t.name}}function JG(e){let t=(0,v.useRef)(!1),[n,r]=(0,v.useState)(!1),[i,a]=(0,v.useState)([]),[o,s]=(0,v.useState)([]),[c,l]=(0,v.useState)(!1),u=e.onUploadFile?{pending:n,start:(n,i)=>{if(t.current)return;let o=Array.from(i.items??[]).filter(e=>e.kind===`file`),c=!1,l=o.length>0?o.flatMap(e=>{if(e.webkitGetAsEntry?.()?.isDirectory)return c=!0,[];let t=e.getAsFile();return t?[t]:[]}):Array.from(i.files);if(a([]),s(c?[`Folders cannot be imported here; drop files instead.`]:[]),l.length===0)return;t.current=!0,r(!0);let u=e.onUploadFile;(async()=>{try{for(let e of l)try{let t=await VV(e),r=await u(e.name,t,n);a(e=>[...e,r])}catch(t){if(s(n=>[...n,`${e.name}: ${t instanceof Error?t.message:String(t)}`]),t instanceof BV)break}}finally{t.current=!1,r(!1)}})()}}:void 0,[d,f]=(0,v.useState)(null),[p,m]=(0,v.useState)(null),[h,g]=(0,v.useState)(null),[_,y]=(0,v.useState)(null),[b,x]=(0,v.useState)(null),[S,C]=(0,v.useState)(null),w=e.onCreateFile!==void 0||e.onCreateDirectory!==void 0,T=e.createError&&h&&e.createError.path===YG(h.dir,h.name)?e.createError.message:null,E=e.created??null;(0,v.useEffect)(()=>{h!==null&&E!==null&&E===YG(h.dir,h.name)&&(f(null),g(null),m(null))},[h,E]);let D=e.fileOperation?.status===`error`&&e.fileOperation.operation===`rename_file`&&S===e.fileOperation.path?e.fileOperation.message:null;(0,v.useEffect)(()=>{let t=e.fileOperation;t?.status===`succeeded`&&t.operation===`rename_file`&&S===t.path&&(y(null),C(null),x(null))},[S,e.fileOperation]);let O=w?{openIn:d,localError:p,serverError:T,start:e=>{f(e),m(null),g(null)},cancel:()=>{f(null),m(null),g(null)},submit:(t,n)=>{let r=KG(n);if(`error`in r){m(r.error);return}m(null),g({dir:t,name:r.name});let i=YG(t,r.name);r.kind===`directory`?e.onCreateDirectory?.(i):e.onCreateFile?.(i)}}:void 0,ee=e.onRenameFile?{path:_,pending:S!==null&&e.fileOperation?.status===`pending`&&e.fileOperation.operation===`rename_file`&&e.fileOperation.path===S,localError:b,serverError:D,start:e=>{y(e),C(null),x(null)},cancel:()=>{y(null),C(null),x(null)},submit:(t,n)=>{if(n.trim()===``){y(null),C(null),x(null);return}let r=qG(n);`error`in r?x(r.error):(x(null),C(t),e.onRenameFile?.(t,r.name))}}:void 0,te=!VG(``,e.writableRoot);return(0,N.jsxs)(`div`,{className:`text-sm`,children:[u&&(0,N.jsx)(`div`,{"data-drop-directory":``,title:te?`Drop files here to import into the workspace root`:`The workspace root is read-only`,className:`mb-1 rounded border border-dashed px-2 py-1 text-xs ${te?`text-zinc-500 dark:text-zinc-400`:`text-zinc-400 dark:text-zinc-600`} ${c&&te&&!n?`bg-blue-50 ring-1 ring-blue-400 dark:bg-blue-950/40`:`border-zinc-200 dark:border-zinc-800`}`,onDragOver:e=>{Array.from(e.dataTransfer.types).includes(`Files`)&&(e.preventDefault(),e.stopPropagation(),e.dataTransfer.dropEffect=te&&!n?`copy`:`none`,l(te&&!n))},onDragLeave:e=>{e.currentTarget.contains(e.relatedTarget)||l(!1)},onDrop:e=>{Array.from(e.dataTransfer.types).includes(`Files`)&&(e.preventDefault(),e.stopPropagation(),l(!1),te&&!t.current&&u.start(``,e.dataTransfer))},children:`Workspace root`}),n&&(0,N.jsx)(`p`,{role:`status`,className:`mb-1 px-2 text-xs text-zinc-500`,children:`Importing files…`}),i.length>0&&(0,N.jsxs)(`p`,{role:`status`,className:`mb-1 break-words px-2 text-xs text-emerald-700 dark:text-emerald-400`,children:[`Imported: `,i.join(`, `)]}),o.map((e,t)=>(0,N.jsx)(`p`,{role:`alert`,className:`mb-1 break-words px-2 text-xs text-red-600 dark:text-red-400`,children:e},t)),e.fileOperation?.status===`error`&&e.fileOperation.operation!==`rename_file`&&(0,N.jsx)(`p`,{role:`alert`,className:`mb-1 rounded bg-red-50 px-2 py-1 text-xs text-red-700 dark:bg-red-950/40 dark:text-red-300`,children:e.fileOperation.message}),(O&&te||e.onRefresh)&&(0,N.jsxs)(`div`,{className:`mb-1 flex items-center`,children:[O&&te&&(0,N.jsx)(`button`,{type:`button`,onClick:()=>O.start(``),"aria-label":`New file or folder in the workspace root`,className:`rounded px-1 py-0.5 text-xs text-zinc-400 hover:bg-zinc-100 hover:text-zinc-600 dark:text-zinc-600 dark:hover:bg-zinc-800 dark:hover:text-zinc-400`,children:`+ new`}),e.onRefresh&&(0,N.jsx)(`button`,{type:`button`,onClick:e.onRefresh,title:`Refresh the file tree`,"aria-label":`Refresh the file tree`,className:`ml-auto rounded px-1 py-0.5 text-xs text-zinc-400 hover:bg-zinc-100 hover:text-zinc-600 dark:text-zinc-600 dark:hover:bg-zinc-800 dark:hover:text-zinc-400`,children:`↻`})]}),(0,N.jsx)(WG,{path:``,depth:0,...e,imports:u,...O?{creation:O}:{},...ee?{rename:ee}:{}})]})}function YG(e,t){return e===``?t:`${e}/${t}`}function XG({hidden:e,tree:t,openFile:n,writableRoot:r,gitFiles:i,attachedPaths:a,onExpand:o,onSelectDirectory:s,onRefresh:c,onSelectFile:l,onSelectDiff:u,onToggleAttachPath:d,onCreateFile:f,onCreateDirectory:p,onOpenNative:m,onRevealNative:h,onRenameFile:g,onDeleteFile:_,onMoveFile:y,onCopyFile:b,onUploadFile:x,onExternalDragEnter:S,fileOperation:C,createError:w,created:T,contentSearch:E=null,onSearchContent:D,onOpenSearchHit:O}){let ee=BU(NU),[te,k]=(0,v.useState)(!1),[ne,A]=(0,v.useState)(E?.query??``),re=e=>x!==void 0&&Array.from(e.types).includes(`Files`);return(0,v.useEffect)(()=>{t[``]===void 0&&o(``)},[]),(0,N.jsxs)(`aside`,{"aria-label":`Files`,onDragEnterCapture:e=>{re(e.dataTransfer)&&S?.()},onDragEnter:e=>{re(e.dataTransfer)&&e.stopPropagation()},onDragLeave:e=>{re(e.dataTransfer)&&e.stopPropagation()},onDragOver:e=>{re(e.dataTransfer)&&(e.preventDefault(),e.stopPropagation(),e.dataTransfer.dropEffect=`none`)},onDropCapture:e=>{re(e.dataTransfer)&&S?.()},onDrop:e=>{re(e.dataTransfer)&&(e.preventDefault(),e.stopPropagation())},style:{width:ee.width,display:e?`none`:void 0},className:`relative flex shrink-0 flex-col border-r border-zinc-200 dark:border-zinc-800`,children:[(0,N.jsxs)(`div`,{className:`flex items-center border-b border-zinc-200 px-3 py-2 text-xs font-semibold uppercase text-zinc-400 dark:border-zinc-800 dark:text-zinc-600`,children:[`Files`,D&&(0,N.jsx)(`button`,{type:`button`,onClick:()=>k(e=>!e),"aria-pressed":te,title:`Search in files`,"aria-label":`Search in files`,className:`ml-auto rounded p-0.5 normal-case hover:bg-zinc-100 hover:text-zinc-600 dark:hover:bg-zinc-800 dark:hover:text-zinc-400 ${te?`text-zinc-700 dark:text-zinc-300`:``}`,children:(0,N.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,"aria-hidden":!0,className:`h-3.5 w-3.5`,children:[(0,N.jsx)(`circle`,{cx:`11`,cy:`11`,r:`7`}),(0,N.jsx)(`path`,{d:`m20 20-3.5-3.5`})]})})]}),te&&D&&(0,N.jsx)(`div`,{className:`flex-1 overflow-auto p-2`,children:(0,N.jsx)(jG,{query:ne,onQueryChange:A,search:E,onSearch:D,onOpenHit:(e,t)=>O?.(e,t),onClose:()=>k(!1)})}),(0,N.jsx)(`div`,{className:`flex-1 overflow-auto p-2`,style:te&&D?{display:`none`}:void 0,children:(0,N.jsx)(JG,{tree:t,openFilePath:n?.path,writableRoot:r,gitFiles:i,attachedPaths:a,onExpand:o,onSelectDirectory:s,onRefresh:c,onSelectFile:l,onSelectDiff:u,onToggleAttachPath:d,onCreateFile:f,onCreateDirectory:p,onOpenNative:m,onRevealNative:h,onRenameFile:g,onDeleteFile:_,onMoveFile:y,onCopyFile:b,onUploadFile:x,fileOperation:C,createError:w,created:T})}),(0,N.jsx)(VU,{label:`Resize Files sidebar`,width:ee.width,config:NU,separatorProps:ee.separatorProps})]})}function ZG({title:e,onSubmit:t}){let[n,r]=(0,v.useState)(``);return(0,N.jsx)(`div`,{className:`flex h-full items-center justify-center p-6`,children:(0,N.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),n.trim()&&t(n.trim())},className:`w-full max-w-sm rounded-xl border border-zinc-200 p-6 shadow-sm dark:border-zinc-800`,children:[(0,N.jsx)(`div`,{className:`mb-1 text-center text-3xl`,children:e??`π`}),(0,N.jsx)(`h1`,{className:`mb-4 text-center text-sm text-zinc-500 dark:text-zinc-400`,children:`This server requires an access token.`}),(0,N.jsx)(`label`,{htmlFor:`pi-outpost-token`,className:`mb-1 block text-xs font-medium text-zinc-600 dark:text-zinc-400`,children:`Access token`}),(0,N.jsx)(`input`,{id:`pi-outpost-token`,name:`token`,type:`password`,autoComplete:`off`,spellCheck:!1,value:n,onChange:e=>r(e.target.value),placeholder:`paste the token…`,className:`mb-3 w-full rounded-md border border-zinc-300 bg-white px-2 py-1.5 font-mono text-sm outline-none focus:border-zinc-500 dark:border-zinc-700 dark:bg-zinc-950 dark:focus:border-zinc-500`}),(0,N.jsx)(`button`,{type:`submit`,disabled:!n.trim(),className:`w-full rounded-md border border-emerald-300 px-2 py-1.5 text-sm text-emerald-700 hover:border-emerald-500 disabled:opacity-50 dark:border-emerald-900 dark:text-emerald-400 dark:hover:border-emerald-600`,children:`Connect`}),(0,N.jsxs)(`p`,{className:`mt-3 text-center text-xs text-zinc-400 dark:text-zinc-600`,children:[`Ask the operator for the token, or open the link containing `,(0,N.jsx)(`code`,{children:`?token=…`})]})]})})}var QG={todo:{icon:`○`,label:`To do`,className:`text-zinc-500`},in_progress:{icon:`●`,label:`In progress`,className:`text-blue-600 dark:text-blue-400`},done:{icon:`✓`,label:`Done`,className:`text-emerald-600 dark:text-emerald-400`},blocked:{icon:`!`,label:`Blocked`,className:`text-red-600 dark:text-red-400`},needs_review:{icon:`?`,label:`Needs review`,className:`text-amber-600 dark:text-amber-400`}},$G=8;function eK(e){let t=e.uri.startsWith(`workspace:`)?e.uri.slice(10):/^[a-z][a-z0-9+.-]*:/i.test(e.uri)?null:e.uri;return t===null||t===``||/^(?:[\\/]|[a-z]:[\\/])/i.test(t)||t.replaceAll(`\\`,`/`).split(`/`).includes(`..`)?null:t}function tK({plan:e,open:t,onToggle:n,onOpenWorkspace:r,requestedTaskId:i,onTaskRequestHandled:a}){let o=(0,v.useId)(),[s,c]=(0,v.useState)(!1),[l,u]=(0,v.useState)(null),[d,f]=(0,v.useState)(null);(0,v.useEffect)(()=>{i&&(e.tasks.some(e=>e.id===i)?(u(i),f(null)):(u(null),f(i)),a?.())},[e.tasks,i,a]),(0,v.useEffect)(()=>{l!==null&&!e.tasks.some(e=>e.id===l)&&u(null)},[e,l]),(0,v.useEffect)(()=>{if(!s)return;let e=e=>{e.key===`Escape`&&c(!1)};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[s]);let p=(0,v.useMemo)(()=>{let t=new Map;for(let n of e.tasks)t.set(n.parentId,[...t.get(n.parentId)??[],n]);return t},[e.tasks]),m=(0,v.useMemo)(()=>new Map(e.tasks.map(e=>[e.id,e])),[e.tasks]),h=(0,v.useMemo)(()=>{let e=[],t=(n,r)=>{for(let i of p.get(n)??[])e.push({task:i,depth:r}),t(i.id,r+1)};return t(void 0,0),e.slice(0,$G)},[p]),g=l?m.get(l):void 0,_=e.tasks.filter(e=>e.status===`done`).length,y=(e,t=0)=>(p.get(e)??[]).flatMap(e=>{let n=QG[e.status];return[(0,N.jsxs)(`button`,{type:`button`,role:`treeitem`,"aria-level":t+1,"aria-selected":l===e.id,onClick:()=>u(e.id),"aria-current":e.status===`in_progress`?`step`:void 0,className:`flex w-full items-start gap-2 rounded px-2 py-1.5 text-left text-sm hover:bg-zinc-100 dark:hover:bg-zinc-800 ${l===e.id?`bg-zinc-100 dark:bg-zinc-800`:``}`,style:{paddingLeft:`${.5+t*.85}rem`},children:[(0,N.jsx)(`span`,{className:`mt-px w-4 shrink-0 text-center font-semibold ${n.className}`,"aria-label":n.label,children:n.icon}),(0,N.jsx)(`span`,{className:e.status===`done`?`text-zinc-500 line-through`:`text-zinc-800 dark:text-zinc-200`,children:e.title})]},e.id),...y(e.id,t+1)]});return t?(0,N.jsxs)(`aside`,{"aria-label":`Work Plan`,className:`absolute inset-y-0 right-0 z-10 flex w-full flex-col border-l border-zinc-200 bg-white/95 shadow-lg backdrop-blur md:w-[23rem] dark:border-zinc-800 dark:bg-zinc-950/95`,children:[(0,N.jsxs)(`header`,{className:`border-b border-zinc-200 px-3 py-3 dark:border-zinc-800`,children:[(0,N.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,N.jsxs)(`div`,{className:`min-w-0`,children:[(0,N.jsx)(`div`,{className:`text-[11px] font-semibold uppercase tracking-wide text-zinc-500`,children:`Work Plan`}),(0,N.jsx)(`h2`,{className:`truncate text-sm font-semibold text-zinc-900 dark:text-zinc-100`,children:e.title})]}),(0,N.jsx)(`button`,{type:`button`,onClick:n,className:`rounded px-2 py-1 text-xs text-zinc-500 hover:bg-zinc-100 dark:hover:bg-zinc-800`,"aria-label":`Close Work Plan`,children:`×`})]}),(0,N.jsxs)(`div`,{className:`mt-2 text-xs text-zinc-500`,children:[`Progress: `,_,` / `,e.tasks.length]}),(0,N.jsx)(`div`,{className:`mt-1 h-1.5 overflow-hidden rounded-full bg-zinc-200 dark:bg-zinc-800`,"aria-hidden":!0,children:(0,N.jsx)(`div`,{className:`h-full bg-emerald-500`,style:{width:`${e.tasks.length===0?0:_/e.tasks.length*100}%`}})})]}),(0,N.jsx)(`div`,{role:`tree`,"aria-label":`Work Plan tasks`,className:`min-h-0 flex-1 overflow-y-auto p-2`,children:y(void 0)}),d&&(0,N.jsx)(`div`,{role:`status`,className:`border-t border-amber-200 bg-amber-50 p-3 text-xs text-amber-800 dark:border-amber-900 dark:bg-amber-950/30 dark:text-amber-300`,children:`That Outcome task no longer exists in the current Work Plan.`}),g&&(0,N.jsxs)(`section`,{"aria-label":`Task details`,className:`max-h-[45%] overflow-y-auto border-t border-zinc-200 p-3 text-xs dark:border-zinc-800`,children:[(0,N.jsx)(`div`,{className:`font-semibold ${QG[g.status].className}`,children:QG[g.status].label}),(0,N.jsx)(`h3`,{className:`mt-1 text-sm font-semibold text-zinc-900 dark:text-zinc-100`,children:g.title}),g.description&&(0,N.jsx)(`p`,{className:`mt-2 whitespace-pre-wrap text-zinc-600 dark:text-zinc-300`,children:g.description}),g.statusReason&&(0,N.jsx)(`p`,{className:`mt-2 rounded bg-zinc-100 p-2 text-zinc-700 dark:bg-zinc-900 dark:text-zinc-300`,children:g.statusReason}),g.dependsOn.length>0&&(0,N.jsxs)(`div`,{className:`mt-3`,children:[(0,N.jsx)(`span`,{className:`font-semibold`,children:`Depends on:`}),` `,g.dependsOn.map(e=>m.get(e)?.title??e).join(`, `)]}),g.resources.length>0&&(0,N.jsxs)(`div`,{className:`mt-3 space-y-1`,children:[(0,N.jsx)(`div`,{className:`font-semibold`,children:`Resources`}),g.resources.map(e=>{let t=eK(e),n=e.label??e.uri;return t===null?/^https?:/i.test(e.uri)?(0,N.jsx)(`a`,{href:e.uri,target:`_blank`,rel:`noreferrer`,className:`block truncate text-blue-600 hover:underline dark:text-blue-400`,children:n},e.uri):(0,N.jsx)(`span`,{className:`block truncate text-zinc-500`,title:`No navigator is available for this resource`,children:n},e.uri):(0,N.jsx)(`button`,{type:`button`,className:`block max-w-full truncate text-left text-blue-600 hover:underline dark:text-blue-400`,onClick:()=>r(t),children:n},e.uri)})]})]})]}):(0,N.jsxs)(`div`,{className:`absolute right-3 top-3 z-20`,onMouseEnter:()=>c(!0),onMouseLeave:()=>c(!1),onFocusCapture:()=>c(!0),onBlurCapture:()=>c(!1),children:[(0,N.jsxs)(`button`,{type:`button`,onClick:()=>{c(!1),n()},className:`rounded-md border border-zinc-300 bg-white px-2 py-1 text-xs shadow-sm dark:border-zinc-700 dark:bg-zinc-900`,"aria-label":`Open Work Plan`,"aria-describedby":o,children:[`Plan `,_,`/`,e.tasks.length]}),(0,N.jsx)(`div`,{id:o,role:`tooltip`,className:`absolute right-0 top-full w-72 pt-2 ${s?`block`:`hidden`}`,children:(0,N.jsxs)(`div`,{className:`rounded-md border border-zinc-200 bg-white p-2 shadow-lg dark:border-zinc-700 dark:bg-zinc-900`,children:[(0,N.jsx)(`ul`,{className:`space-y-1`,children:h.map(({task:e,depth:t})=>(0,N.jsxs)(`li`,{className:`flex min-w-0 items-start gap-1.5 text-xs`,style:{paddingLeft:`${t*.75}rem`},children:[(0,N.jsx)(`span`,{"aria-label":QG[e.status].label,className:`shrink-0 font-semibold ${QG[e.status].className}`,children:e.status===`done`?`☑`:`☐`}),(0,N.jsx)(`span`,{className:`truncate ${e.status===`done`?`text-zinc-500 line-through`:`text-zinc-800 dark:text-zinc-200`}`,children:e.title})]},e.id))}),e.tasks.length>h.length&&(0,N.jsxs)(`div`,{className:`mt-1 text-[11px] text-zinc-500`,children:[`+`,e.tasks.length-h.length,` more`]})]})})]})}var nK=Object.defineProperty,rK=Object.getOwnPropertyDescriptor,iK=(e,t)=>{for(var n in t)nK(e,n,{get:t[n],enumerable:!0})},aK=(e,t,n,r)=>{for(var i=r>1?void 0:r?rK(t,n):t,a=e.length-1,o;a>=0;a--)(o=e[a])&&(i=(r?o(t,n,i):o(i))||i);return r&&i&&nK(t,n,i),i},oK=(e,t)=>(n,r)=>t(n,r,e),sK=`Terminal input`,cK={get:()=>sK,set:e=>sK=e},lK=`Too much output to announce, navigate to rows manually to read`,uK={get:()=>lK,set:e=>lK=e};function dK(e){return e.replace(/\r?\n/g,`\r`)}function fK(e,t){return t?`\x1B[200~`+e+`\x1B[201~`:e}function pK(e,t){e.clipboardData&&e.clipboardData.setData(`text/plain`,t.selectionText),e.preventDefault()}function mK(e,t,n,r){e.stopPropagation(),e.clipboardData&&hK(e.clipboardData.getData(`text/plain`),t,n,r)}function hK(e,t,n,r){e=dK(e),e=fK(e,n.decPrivateModes.bracketedPasteMode&&r.rawOptions.ignoreBracketedPasteMode!==!0),n.triggerDataEvent(e,!0),t.value=``}function gK(e,t,n){let r=n.getBoundingClientRect(),i=e.clientX-r.left-10,a=e.clientY-r.top-10;t.style.width=`20px`,t.style.height=`20px`,t.style.left=`${i}px`,t.style.top=`${a}px`,t.style.zIndex=`1000`,t.focus()}function _K(e,t,n,r,i){gK(e,t,n),i&&r.rightClickSelect(e),t.value=r.selectionText,t.select()}function vK(e){return e>65535?(e-=65536,String.fromCharCode((e>>10)+55296)+String.fromCharCode(e%1024+56320)):String.fromCharCode(e)}function yK(e,t=0,n=e.length){let r=``;for(let i=t;i<n;++i){let t=e[i];t>65535?(t-=65536,r+=String.fromCharCode((t>>10)+55296)+String.fromCharCode(t%1024+56320)):r+=String.fromCharCode(t)}return r}var bK=class{constructor(){this._interim=0}clear(){this._interim=0}decode(e,t){let n=e.length;if(!n)return 0;let r=0,i=0;if(this._interim){let n=e.charCodeAt(i++);56320<=n&&n<=57343?t[r++]=(this._interim-55296)*1024+n-56320+65536:(t[r++]=this._interim,t[r++]=n),this._interim=0}for(let a=i;a<n;++a){let i=e.charCodeAt(a);if(55296<=i&&i<=56319){if(++a>=n)return this._interim=i,r;let o=e.charCodeAt(a);56320<=o&&o<=57343?t[r++]=(i-55296)*1024+o-56320+65536:(t[r++]=i,t[r++]=o)}else i!==65279&&(t[r++]=i)}return r}},xK=class{constructor(){this.interim=new Uint8Array(3)}clear(){this.interim.fill(0)}decode(e,t){let n=e.length;if(!n)return 0;let r=0,i,a,o,s,c=0,l=0;if(this.interim[0]){let i=!1,a=this.interim[0];a&=(a&224)==192?31:(a&240)==224?15:7;let o=0,s;for(;(s=this.interim[++o]&63)&&o<4;)a<<=6,a|=s;let c=(this.interim[0]&224)==192?2:(this.interim[0]&240)==224?3:4,u=c-o;for(;l<u;){if(l>=n)return 0;if(s=e[l++],(s&192)!=128){l--,i=!0;break}this.interim[o++]=s,a<<=6,a|=s&63}i||(c===2?a<128?l--:t[r++]=a:c===3?a<2048||a>=55296&&a<=57343||a===65279||(t[r++]=a):a<65536||a>1114111||(t[r++]=a)),this.interim.fill(0)}let u=n-4,d=l;for(;d<n;){for(;d<u&&!((i=e[d])&128)&&!((a=e[d+1])&128)&&!((o=e[d+2])&128)&&!((s=e[d+3])&128);)t[r++]=i,t[r++]=a,t[r++]=o,t[r++]=s,d+=4;if(i=e[d++],i<128)t[r++]=i;else if((i&224)==192){if(d>=n)return this.interim[0]=i,r;if(a=e[d++],(a&192)!=128||(c=(i&31)<<6|a&63,c<128)){d--;continue}t[r++]=c}else if((i&240)==224){if(d>=n)return this.interim[0]=i,r;if(a=e[d++],(a&192)!=128){d--;continue}if(d>=n)return this.interim[0]=i,this.interim[1]=a,r;if(o=e[d++],(o&192)!=128){d--;continue}if(c=(i&15)<<12|(a&63)<<6|o&63,c<2048||c>=55296&&c<=57343||c===65279)continue;t[r++]=c}else if((i&248)==240){if(d>=n)return this.interim[0]=i,r;if(a=e[d++],(a&192)!=128){d--;continue}if(d>=n)return this.interim[0]=i,this.interim[1]=a,r;if(o=e[d++],(o&192)!=128){d--;continue}if(d>=n)return this.interim[0]=i,this.interim[1]=a,this.interim[2]=o,r;if(s=e[d++],(s&192)!=128){d--;continue}if(c=(i&7)<<18|(a&63)<<12|(o&63)<<6|s&63,c<65536||c>1114111)continue;t[r++]=c}}return r}},SK=``,CK=` `,wK=class e{constructor(){this.fg=0,this.bg=0,this.extended=new TK}static toColorRGB(e){return[e>>>16&255,e>>>8&255,e&255]}static fromColorRGB(e){return(e[0]&255)<<16|(e[1]&255)<<8|e[2]&255}clone(){let t=new e;return t.fg=this.fg,t.bg=this.bg,t.extended=this.extended.clone(),t}isInverse(){return this.fg&67108864}isBold(){return this.fg&134217728}isUnderline(){return this.hasExtendedAttrs()&&this.extended.underlineStyle!==0?1:this.fg&268435456}isBlink(){return this.fg&536870912}isInvisible(){return this.fg&1073741824}isItalic(){return this.bg&67108864}isDim(){return this.bg&134217728}isStrikethrough(){return this.fg&2147483648}isProtected(){return this.bg&536870912}isOverline(){return this.bg&1073741824}getFgColorMode(){return this.fg&50331648}getBgColorMode(){return this.bg&50331648}isFgRGB(){return(this.fg&50331648)==50331648}isBgRGB(){return(this.bg&50331648)==50331648}isFgPalette(){return(this.fg&50331648)==16777216||(this.fg&50331648)==33554432}isBgPalette(){return(this.bg&50331648)==16777216||(this.bg&50331648)==33554432}isFgDefault(){return!(this.fg&50331648)}isBgDefault(){return!(this.bg&50331648)}isAttributeDefault(){return this.fg===0&&this.bg===0}getFgColor(){switch(this.fg&50331648){case 16777216:case 33554432:return this.fg&255;case 50331648:return this.fg&16777215;default:return-1}}getBgColor(){switch(this.bg&50331648){case 16777216:case 33554432:return this.bg&255;case 50331648:return this.bg&16777215;default:return-1}}hasExtendedAttrs(){return this.bg&268435456}updateExtended(){this.extended.isEmpty()?this.bg&=-268435457:this.bg|=268435456}getUnderlineColor(){if(this.bg&268435456&&~this.extended.underlineColor)switch(this.extended.underlineColor&50331648){case 16777216:case 33554432:return this.extended.underlineColor&255;case 50331648:return this.extended.underlineColor&16777215;default:return this.getFgColor()}return this.getFgColor()}getUnderlineColorMode(){return this.bg&268435456&&~this.extended.underlineColor?this.extended.underlineColor&50331648:this.getFgColorMode()}isUnderlineColorRGB(){return this.bg&268435456&&~this.extended.underlineColor?(this.extended.underlineColor&50331648)==50331648:this.isFgRGB()}isUnderlineColorPalette(){return this.bg&268435456&&~this.extended.underlineColor?(this.extended.underlineColor&50331648)==16777216||(this.extended.underlineColor&50331648)==33554432:this.isFgPalette()}isUnderlineColorDefault(){return this.bg&268435456&&~this.extended.underlineColor?!(this.extended.underlineColor&50331648):this.isFgDefault()}getUnderlineStyle(){return this.fg&268435456?this.bg&268435456?this.extended.underlineStyle:1:0}getUnderlineVariantOffset(){return this.extended.underlineVariantOffset}},TK=class e{constructor(e=0,t=0){this._ext=0,this._urlId=0,this._ext=e,this._urlId=t}get ext(){return this._urlId?this._ext&-469762049|this.underlineStyle<<26:this._ext}set ext(e){this._ext=e}get underlineStyle(){return this._urlId?5:(this._ext&469762048)>>26}set underlineStyle(e){this._ext&=-469762049,this._ext|=e<<26&469762048}get underlineColor(){return this._ext&67108863}set underlineColor(e){this._ext&=-67108864,this._ext|=e&67108863}get urlId(){return this._urlId}set urlId(e){this._urlId=e}get underlineVariantOffset(){let e=(this._ext&3758096384)>>29;return e<0?e^4294967288:e}set underlineVariantOffset(e){this._ext&=536870911,this._ext|=e<<29&3758096384}clone(){return new e(this._ext,this._urlId)}isEmpty(){return this.underlineStyle===0&&this._urlId===0}},EK=class e extends wK{constructor(){super(...arguments),this.content=0,this.fg=0,this.bg=0,this.extended=new TK,this.combinedData=``}static fromCharData(t){let n=new e;return n.setFromCharData(t),n}isCombined(){return this.content&2097152}getWidth(){return this.content>>22}getChars(){return this.content&2097152?this.combinedData:this.content&2097151?vK(this.content&2097151):``}getCode(){return this.isCombined()?this.combinedData.charCodeAt(this.combinedData.length-1):this.content&2097151}setFromCharData(e){this.fg=e[0],this.bg=0;let t=!1;if(e[1].length>2)t=!0;else if(e[1].length===2){let n=e[1].charCodeAt(0);if(55296<=n&&n<=56319){let r=e[1].charCodeAt(1);56320<=r&&r<=57343?this.content=(n-55296)*1024+r-56320+65536|e[2]<<22:t=!0}else t=!0}else this.content=e[1].charCodeAt(0)|e[2]<<22;t&&(this.combinedData=e[1],this.content=2097152|e[2]<<22)}getAsCharData(){return[this.fg,this.getChars(),this.getWidth(),this.getCode()]}},DK=`di$target`,OK=`di$dependencies`,kK=new Map;function AK(e){return e[OK]||[]}function jK(e){if(kK.has(e))return kK.get(e);let t=function(e,n,r){if(arguments.length!==3)throw Error(`@IServiceName-decorator can only be used to decorate a parameter`);MK(t,e,r)};return t._id=e,kK.set(e,t),t}function MK(e,t,n){t[DK]===t?t[OK].push({id:e,index:n}):(t[OK]=[{id:e,index:n}],t[DK]=t)}var NK=jK(`BufferService`),PK=jK(`CoreMouseService`),FK=jK(`CoreService`),IK=jK(`CharsetService`),LK=jK(`InstantiationService`),RK=jK(`LogService`),zK=jK(`OptionsService`),BK=jK(`OscLinkService`),VK=jK(`UnicodeService`),HK=jK(`DecorationService`),UK=class{constructor(e,t,n){this._bufferService=e,this._optionsService=t,this._oscLinkService=n}provideLinks(e,t){let n=this._bufferService.buffer.lines.get(e-1);if(!n){t(void 0);return}let r=[],i=this._optionsService.rawOptions.linkHandler,a=new EK,o=n.getTrimmedLength(),s=-1,c=-1,l=!1;for(let t=0;t<o;t++)if(c!==-1||n.hasContent(t)){if(n.loadCell(t,a),a.hasExtendedAttrs()&&a.extended.urlId){if(c===-1){c=t,s=a.extended.urlId;continue}l=a.extended.urlId!==s}else c!==-1&&(l=!0);if(l||c!==-1&&t===o-1){let n=this._oscLinkService.getLinkData(s)?.uri;if(n){let a={start:{x:c+1,y:e},end:{x:t+ +(!l&&t===o-1),y:e}},s=!1;if(!i?.allowNonHttpProtocols)try{let e=new URL(n);[`http:`,`https:`].includes(e.protocol)||(s=!0)}catch{s=!0}s||r.push({text:n,range:a,activate:(e,t)=>i?i.activate(e,t,a):WK(e,t),hover:(e,t)=>i?.hover?.(e,t,a),leave:(e,t)=>i?.leave?.(e,t,a)})}l=!1,a.hasExtendedAttrs()&&a.extended.urlId?(c=t,s=a.extended.urlId):(c=-1,s=-1)}}t(r)}};UK=aK([oK(0,NK),oK(1,zK),oK(2,BK)],UK);function WK(e,t){if(confirm(`Do you want to navigate to ${t}?
1518
1519
 
1519
- WARNING: This link could potentially be dangerous`)){let e=window.open();if(e){try{e.opener=null}catch{}e.location.href=t}else console.warn(`Opening link blocked as opener could not be cleared`)}}var WK=AK(`CharSizeService`),GK=AK(`CoreBrowserService`),KK=AK(`MouseService`),qK=AK(`RenderService`),JK=AK(`SelectionService`),YK=AK(`CharacterJoinerService`),XK=AK(`ThemeService`),ZK=AK(`LinkProviderService`),QK=new class{constructor(){this.listeners=[],this.unexpectedErrorHandler=function(e){setTimeout(()=>{throw e.stack?iq.isErrorNoTelemetry(e)?new iq(e.message+`
1520
+ WARNING: This link could potentially be dangerous`)){let e=window.open();if(e){try{e.opener=null}catch{}e.location.href=t}else console.warn(`Opening link blocked as opener could not be cleared`)}}var GK=jK(`CharSizeService`),KK=jK(`CoreBrowserService`),qK=jK(`MouseService`),JK=jK(`RenderService`),YK=jK(`SelectionService`),XK=jK(`CharacterJoinerService`),ZK=jK(`ThemeService`),QK=jK(`LinkProviderService`),$K=new class{constructor(){this.listeners=[],this.unexpectedErrorHandler=function(e){setTimeout(()=>{throw e.stack?aq.isErrorNoTelemetry(e)?new aq(e.message+`
1520
1521
 
1521
1522
  `+e.stack):Error(e.message+`
1522
1523
 
1523
- `+e.stack):e},0)}}addListener(e){return this.listeners.push(e),()=>{this._removeListener(e)}}emit(e){this.listeners.forEach(t=>{t(e)})}_removeListener(e){this.listeners.splice(this.listeners.indexOf(e),1)}setUnexpectedErrorHandler(e){this.unexpectedErrorHandler=e}getUnexpectedErrorHandler(){return this.unexpectedErrorHandler}onUnexpectedError(e){this.unexpectedErrorHandler(e),this.emit(e)}onUnexpectedExternalError(e){this.unexpectedErrorHandler(e)}};function $K(e){tq(e)||QK.onUnexpectedError(e)}var eq=`Canceled`;function tq(e){return e instanceof nq||e instanceof Error&&e.name===eq&&e.message===eq}var nq=class extends Error{constructor(){super(eq),this.name=this.message}};function rq(e){return Error(e?`Illegal argument: ${e}`:`Illegal argument`)}var iq=class e extends Error{constructor(e){super(e),this.name=`CodeExpectedError`}static fromError(t){if(t instanceof e)return t;let n=new e;return n.message=t.message,n.stack=t.stack,n}static isErrorNoTelemetry(e){return e.name===`CodeExpectedError`}},aq=class e extends Error{constructor(t){super(t||`An unexpected bug occurred.`),Object.setPrototypeOf(this,e.prototype)}};function oq(e,t=0){return e[e.length-(1+t)]}var sq;(e=>{function t(e){return e<0}e.isLessThan=t;function n(e){return e<=0}e.isLessThanOrEqual=n;function r(e){return e>0}e.isGreaterThan=r;function i(e){return e===0}e.isNeitherLessOrGreaterThan=i,e.greaterThan=1,e.lessThan=-1,e.neitherLessOrGreaterThan=0})(sq||={});var cq=class e{constructor(e){this.iterate=e}forEach(e){this.iterate(t=>(e(t),!0))}toArray(){let e=[];return this.iterate(t=>(e.push(t),!0)),e}filter(t){return new e(e=>this.iterate(n=>!t(n)||e(n)))}map(t){return new e(e=>this.iterate(n=>e(t(n))))}some(e){let t=!1;return this.iterate(n=>(t=e(n),!t)),t}findFirst(e){let t;return this.iterate(n=>!e(n)||(t=n,!1)),t}findLast(e){let t;return this.iterate(n=>(e(n)&&(t=n),!0)),t}findLastMaxBy(e){let t,n=!0;return this.iterate(r=>((n||sq.isGreaterThan(e(r,t)))&&(n=!1,t=r),!0)),t}};cq.empty=new cq(e=>{});function lq(e,t){let n=this,r=!1,i;return function(){if(r)return i;if(r=!0,t)try{i=e.apply(n,arguments)}finally{t()}else i=e.apply(n,arguments);return i}}var uq;(e=>{function t(e){return e&&typeof e==`object`&&typeof e[Symbol.iterator]==`function`}e.is=t;let n=Object.freeze([]);function r(){return n}e.empty=r;function*i(e){yield e}e.single=i;function a(e){return t(e)?e:i(e)}e.wrap=a;function o(e){return e||n}e.from=o;function*s(e){for(let t=e.length-1;t>=0;t--)yield e[t]}e.reverse=s;function c(e){return!e||e[Symbol.iterator]().next().done===!0}e.isEmpty=c;function l(e){return e[Symbol.iterator]().next().value}e.first=l;function u(e,t){let n=0;for(let r of e)if(t(r,n++))return!0;return!1}e.some=u;function d(e,t){for(let n of e)if(t(n))return n}e.find=d;function*f(e,t){for(let n of e)t(n)&&(yield n)}e.filter=f;function*p(e,t){let n=0;for(let r of e)yield t(r,n++)}e.map=p;function*m(e,t){let n=0;for(let r of e)yield*t(r,n++)}e.flatMap=m;function*h(...e){for(let t of e)yield*t}e.concat=h;function g(e,t,n){let r=n;for(let n of e)r=t(r,n);return r}e.reduce=g;function*_(e,t,n=e.length){for(t<0&&(t+=e.length),n<0?n+=e.length:n>e.length&&(n=e.length);t<n;t++)yield e[t]}e.slice=_;function v(t,n=1/0){let r=[];if(n===0)return[r,t];let i=t[Symbol.iterator]();for(let t=0;t<n;t++){let t=i.next();if(t.done)return[r,e.empty()];r.push(t.value)}return[r,{[Symbol.iterator](){return i}}]}e.consume=v;async function y(e){let t=[];for await(let n of e)t.push(n);return Promise.resolve(t)}e.asyncToArray=y})(uq||={});var dq=null;function fq(e){return dq?.trackDisposable(e),e}function pq(e){dq?.markAsDisposed(e)}function mq(e,t){dq?.setParent(e,t)}function hq(e){return dq?.markAsSingleton(e),e}function gq(e){if(uq.is(e)){let t=[];for(let n of e)if(n)try{n.dispose()}catch(e){t.push(e)}if(t.length===1)throw t[0];if(t.length>1)throw AggregateError(t,`Encountered errors while disposing of store`);return Array.isArray(e)?[]:e}if(e)return e.dispose(),e}function _q(...e){return vq(()=>gq(e))}function vq(e){let t=fq({dispose:lq(()=>{pq(t),e()})});return t}var yq=class e{constructor(){this._toDispose=new Set,this._isDisposed=!1,fq(this)}dispose(){this._isDisposed||(pq(this),this._isDisposed=!0,this.clear())}get isDisposed(){return this._isDisposed}clear(){if(this._toDispose.size!==0)try{gq(this._toDispose)}finally{this._toDispose.clear()}}add(t){if(!t)return t;if(t===this)throw Error(`Cannot register a disposable on itself!`);return mq(t,this),this._isDisposed?e.DISABLE_DISPOSED_WARNING||console.warn(Error(`Trying to add a disposable to a DisposableStore that has already been disposed of. The added object will be leaked!`).stack):this._toDispose.add(t),t}delete(e){if(e){if(e===this)throw Error(`Cannot dispose a disposable on itself!`);this._toDispose.delete(e),e.dispose()}}deleteAndLeak(e){e&&this._toDispose.has(e)&&(this._toDispose.delete(e),mq(e,null))}};yq.DISABLE_DISPOSED_WARNING=!1;var bq=yq,xq=class{constructor(){this._store=new bq,fq(this),mq(this._store,this)}dispose(){pq(this),this._store.dispose()}_register(e){if(e===this)throw Error(`Cannot register a disposable on itself!`);return this._store.add(e)}};xq.None=Object.freeze({dispose(){}});var Sq=class{constructor(){this._isDisposed=!1,fq(this)}get value(){return this._isDisposed?void 0:this._value}set value(e){this._isDisposed||e===this._value||(this._value?.dispose(),e&&mq(e,this),this._value=e)}clear(){this.value=void 0}dispose(){this._isDisposed=!0,pq(this),this._value?.dispose(),this._value=void 0}clearAndLeak(){let e=this._value;return this._value=void 0,e&&mq(e,null),e}},Cq=typeof window==`object`?window:globalThis,wq=class e{constructor(t){this.element=t,this.next=e.Undefined,this.prev=e.Undefined}};wq.Undefined=new wq(void 0);var Tq=wq,Eq=class{constructor(){this._first=Tq.Undefined,this._last=Tq.Undefined,this._size=0}get size(){return this._size}isEmpty(){return this._first===Tq.Undefined}clear(){let e=this._first;for(;e!==Tq.Undefined;){let t=e.next;e.prev=Tq.Undefined,e.next=Tq.Undefined,e=t}this._first=Tq.Undefined,this._last=Tq.Undefined,this._size=0}unshift(e){return this._insert(e,!1)}push(e){return this._insert(e,!0)}_insert(e,t){let n=new Tq(e);if(this._first===Tq.Undefined)this._first=n,this._last=n;else if(t){let e=this._last;this._last=n,n.prev=e,e.next=n}else{let e=this._first;this._first=n,n.next=e,e.prev=n}this._size+=1;let r=!1;return()=>{r||(r=!0,this._remove(n))}}shift(){if(this._first!==Tq.Undefined){let e=this._first.element;return this._remove(this._first),e}}pop(){if(this._last!==Tq.Undefined){let e=this._last.element;return this._remove(this._last),e}}_remove(e){if(e.prev!==Tq.Undefined&&e.next!==Tq.Undefined){let t=e.prev;t.next=e.next,e.next.prev=t}else e.prev===Tq.Undefined&&e.next===Tq.Undefined?(this._first=Tq.Undefined,this._last=Tq.Undefined):e.next===Tq.Undefined?(this._last=this._last.prev,this._last.next=Tq.Undefined):e.prev===Tq.Undefined&&(this._first=this._first.next,this._first.prev=Tq.Undefined);--this._size}*[Symbol.iterator](){let e=this._first;for(;e!==Tq.Undefined;)yield e.element,e=e.next}},Dq=globalThis.performance&&typeof globalThis.performance.now==`function`,Oq=class e{static create(t){return new e(t)}constructor(e){this._now=Dq&&e===!1?Date.now:globalThis.performance.now.bind(globalThis.performance),this._startTime=this._now(),this._stopTime=-1}stop(){this._stopTime=this._now()}reset(){this._startTime=this._now(),this._stopTime=-1}elapsed(){return this._stopTime===-1?this._now()-this._startTime:this._stopTime-this._startTime}},kq;(e=>{e.None=()=>xq.None;function t(e,t){return d(e,()=>{},0,void 0,!0,void 0,t)}e.defer=t;function n(e){return(t,n=null,r)=>{let i=!1,a;return a=e(e=>{if(!i)return a?a.dispose():i=!0,t.call(n,e)},null,r),i&&a.dispose(),a}}e.once=n;function r(e,t,n){return l((n,r=null,i)=>e(e=>n.call(r,t(e)),null,i),n)}e.map=r;function i(e,t,n){return l((n,r=null,i)=>e(e=>{t(e),n.call(r,e)},null,i),n)}e.forEach=i;function a(e,t,n){return l((n,r=null,i)=>e(e=>t(e)&&n.call(r,e),null,i),n)}e.filter=a;function o(e){return e}e.signal=o;function s(...e){return(t,n=null,r)=>u(_q(...e.map(e=>e(e=>t.call(n,e)))),r)}e.any=s;function c(e,t,n,i){let a=n;return r(e,e=>(a=t(a,e),a),i)}e.reduce=c;function l(e,t){let n,r=new Vq({onWillAddFirstListener(){n=e(r.fire,r)},onDidRemoveLastListener(){n?.dispose()}});return t?.add(r),r.event}function u(e,t){return t instanceof Array?t.push(e):t&&t.add(e),e}function d(e,t,n=100,r=!1,i=!1,a,o){let s,c,l,u=0,d,f=new Vq({leakWarningThreshold:a,onWillAddFirstListener(){s=e(e=>{u++,c=t(c,e),r&&!l&&(f.fire(c),c=void 0),d=()=>{let e=c;c=void 0,l=void 0,(!r||u>1)&&f.fire(e),u=0},typeof n==`number`?(clearTimeout(l),l=setTimeout(d,n)):l===void 0&&(l=0,queueMicrotask(d))})},onWillRemoveListener(){i&&u>0&&d?.()},onDidRemoveLastListener(){d=void 0,s.dispose()}});return o?.add(f),f.event}e.debounce=d;function f(t,n=0,r){return e.debounce(t,(e,t)=>e?(e.push(t),e):[t],n,void 0,!0,void 0,r)}e.accumulate=f;function p(e,t=(e,t)=>e===t,n){let r=!0,i;return a(e,e=>{let n=r||!t(e,i);return r=!1,i=e,n},n)}e.latch=p;function m(t,n,r){return[e.filter(t,n,r),e.filter(t,e=>!n(e),r)]}e.split=m;function h(e,t=!1,n=[],r){let i=n.slice(),a=e(e=>{i?i.push(e):s.fire(e)});r&&r.add(a);let o=()=>{i?.forEach(e=>s.fire(e)),i=null},s=new Vq({onWillAddFirstListener(){a||(a=e(e=>s.fire(e)),r&&r.add(a))},onDidAddFirstListener(){i&&(t?setTimeout(o):o())},onDidRemoveLastListener(){a&&a.dispose(),a=null}});return r&&r.add(s),s.event}e.buffer=h;function g(e,t){return(n,r,i)=>{let a=t(new v);return e(function(e){let t=a.evaluate(e);t!==_&&n.call(r,t)},void 0,i)}}e.chain=g;let _=Symbol(`HaltChainable`);class v{constructor(){this.steps=[]}map(e){return this.steps.push(e),this}forEach(e){return this.steps.push(t=>(e(t),t)),this}filter(e){return this.steps.push(t=>e(t)?t:_),this}reduce(e,t){let n=t;return this.steps.push(t=>(n=e(n,t),n)),this}latch(e=(e,t)=>e===t){let t=!0,n;return this.steps.push(r=>{let i=t||!e(r,n);return t=!1,n=r,i?r:_}),this}evaluate(e){for(let t of this.steps)if(e=t(e),e===_)break;return e}}function y(e,t,n=e=>e){let r=(...e)=>i.fire(n(...e)),i=new Vq({onWillAddFirstListener:()=>e.on(t,r),onDidRemoveLastListener:()=>e.removeListener(t,r)});return i.event}e.fromNodeEventEmitter=y;function b(e,t,n=e=>e){let r=(...e)=>i.fire(n(...e)),i=new Vq({onWillAddFirstListener:()=>e.addEventListener(t,r),onDidRemoveLastListener:()=>e.removeEventListener(t,r)});return i.event}e.fromDOMEventEmitter=b;function x(e){return new Promise(t=>n(e)(t))}e.toPromise=x;function S(e){let t=new Vq;return e.then(e=>{t.fire(e)},()=>{t.fire(void 0)}).finally(()=>{t.dispose()}),t.event}e.fromPromise=S;function C(e,t){return e(e=>t.fire(e))}e.forward=C;function w(e,t,n){return t(n),e(e=>t(e))}e.runAndSubscribe=w;class T{constructor(e,t){this._observable=e,this._counter=0,this._hasChanged=!1;let n={onWillAddFirstListener:()=>{e.addObserver(this)},onDidRemoveLastListener:()=>{e.removeObserver(this)}};this.emitter=new Vq(n),t&&t.add(this.emitter)}beginUpdate(e){this._counter++}handlePossibleChange(e){}handleChange(e,t){this._hasChanged=!0}endUpdate(e){this._counter--,this._counter===0&&(this._observable.reportChanges(),this._hasChanged&&(this._hasChanged=!1,this.emitter.fire(this._observable.get())))}}function E(e,t){return new T(e,t).emitter.event}e.fromObservable=E;function D(e){return(t,n,r)=>{let i=0,a=!1,o={beginUpdate(){i++},endUpdate(){i--,i===0&&(e.reportChanges(),a&&(a=!1,t.call(n)))},handlePossibleChange(){},handleChange(){a=!0}};e.addObserver(o),e.reportChanges();let s={dispose(){e.removeObserver(o)}};return r instanceof bq?r.add(s):Array.isArray(r)&&r.push(s),s}}e.fromObservableLight=D})(kq||={});var Aq=class e{constructor(t){this.listenerCount=0,this.invocationCount=0,this.elapsedOverall=0,this.durations=[],this.name=`${t}_${e._idPool++}`,e.all.add(this)}start(e){this._stopWatch=new Oq,this.listenerCount=e}stop(){if(this._stopWatch){let e=this._stopWatch.elapsed();this.durations.push(e),this.elapsedOverall+=e,this.invocationCount+=1,this._stopWatch=void 0}}};Aq.all=new Set,Aq._idPool=0;var jq=Aq,Mq=-1,Nq=class e{constructor(t,n,r=(e._idPool++).toString(16).padStart(3,`0`)){this._errorHandler=t,this.threshold=n,this.name=r,this._warnCountdown=0}dispose(){this._stacks?.clear()}check(e,t){let n=this.threshold;if(n<=0||t<n)return;this._stacks||=new Map;let r=this._stacks.get(e.value)||0;if(this._stacks.set(e.value,r+1),--this._warnCountdown,this._warnCountdown<=0){this._warnCountdown=n*.5;let[e,r]=this.getMostFrequentStack(),i=`[${this.name}] potential listener LEAK detected, having ${t} listeners already. MOST frequent listener (${r}):`;console.warn(i),console.warn(e);let a=new Iq(i,e);this._errorHandler(a)}return()=>{let t=this._stacks.get(e.value)||0;this._stacks.set(e.value,t-1)}}getMostFrequentStack(){if(!this._stacks)return;let e,t=0;for(let[n,r]of this._stacks)(!e||t<r)&&(e=[n,r],t=r);return e}};Nq._idPool=1;var Pq=Nq,Fq=class e{constructor(e){this.value=e}static create(){return new e(Error().stack??``)}print(){console.warn(this.value.split(`
1524
+ `+e.stack):e},0)}}addListener(e){return this.listeners.push(e),()=>{this._removeListener(e)}}emit(e){this.listeners.forEach(t=>{t(e)})}_removeListener(e){this.listeners.splice(this.listeners.indexOf(e),1)}setUnexpectedErrorHandler(e){this.unexpectedErrorHandler=e}getUnexpectedErrorHandler(){return this.unexpectedErrorHandler}onUnexpectedError(e){this.unexpectedErrorHandler(e),this.emit(e)}onUnexpectedExternalError(e){this.unexpectedErrorHandler(e)}};function eq(e){nq(e)||$K.onUnexpectedError(e)}var tq=`Canceled`;function nq(e){return e instanceof rq||e instanceof Error&&e.name===tq&&e.message===tq}var rq=class extends Error{constructor(){super(tq),this.name=this.message}};function iq(e){return Error(e?`Illegal argument: ${e}`:`Illegal argument`)}var aq=class e extends Error{constructor(e){super(e),this.name=`CodeExpectedError`}static fromError(t){if(t instanceof e)return t;let n=new e;return n.message=t.message,n.stack=t.stack,n}static isErrorNoTelemetry(e){return e.name===`CodeExpectedError`}},oq=class e extends Error{constructor(t){super(t||`An unexpected bug occurred.`),Object.setPrototypeOf(this,e.prototype)}};function sq(e,t=0){return e[e.length-(1+t)]}var cq;(e=>{function t(e){return e<0}e.isLessThan=t;function n(e){return e<=0}e.isLessThanOrEqual=n;function r(e){return e>0}e.isGreaterThan=r;function i(e){return e===0}e.isNeitherLessOrGreaterThan=i,e.greaterThan=1,e.lessThan=-1,e.neitherLessOrGreaterThan=0})(cq||={});var lq=class e{constructor(e){this.iterate=e}forEach(e){this.iterate(t=>(e(t),!0))}toArray(){let e=[];return this.iterate(t=>(e.push(t),!0)),e}filter(t){return new e(e=>this.iterate(n=>!t(n)||e(n)))}map(t){return new e(e=>this.iterate(n=>e(t(n))))}some(e){let t=!1;return this.iterate(n=>(t=e(n),!t)),t}findFirst(e){let t;return this.iterate(n=>!e(n)||(t=n,!1)),t}findLast(e){let t;return this.iterate(n=>(e(n)&&(t=n),!0)),t}findLastMaxBy(e){let t,n=!0;return this.iterate(r=>((n||cq.isGreaterThan(e(r,t)))&&(n=!1,t=r),!0)),t}};lq.empty=new lq(e=>{});function uq(e,t){let n=this,r=!1,i;return function(){if(r)return i;if(r=!0,t)try{i=e.apply(n,arguments)}finally{t()}else i=e.apply(n,arguments);return i}}var dq;(e=>{function t(e){return e&&typeof e==`object`&&typeof e[Symbol.iterator]==`function`}e.is=t;let n=Object.freeze([]);function r(){return n}e.empty=r;function*i(e){yield e}e.single=i;function a(e){return t(e)?e:i(e)}e.wrap=a;function o(e){return e||n}e.from=o;function*s(e){for(let t=e.length-1;t>=0;t--)yield e[t]}e.reverse=s;function c(e){return!e||e[Symbol.iterator]().next().done===!0}e.isEmpty=c;function l(e){return e[Symbol.iterator]().next().value}e.first=l;function u(e,t){let n=0;for(let r of e)if(t(r,n++))return!0;return!1}e.some=u;function d(e,t){for(let n of e)if(t(n))return n}e.find=d;function*f(e,t){for(let n of e)t(n)&&(yield n)}e.filter=f;function*p(e,t){let n=0;for(let r of e)yield t(r,n++)}e.map=p;function*m(e,t){let n=0;for(let r of e)yield*t(r,n++)}e.flatMap=m;function*h(...e){for(let t of e)yield*t}e.concat=h;function g(e,t,n){let r=n;for(let n of e)r=t(r,n);return r}e.reduce=g;function*_(e,t,n=e.length){for(t<0&&(t+=e.length),n<0?n+=e.length:n>e.length&&(n=e.length);t<n;t++)yield e[t]}e.slice=_;function v(t,n=1/0){let r=[];if(n===0)return[r,t];let i=t[Symbol.iterator]();for(let t=0;t<n;t++){let t=i.next();if(t.done)return[r,e.empty()];r.push(t.value)}return[r,{[Symbol.iterator](){return i}}]}e.consume=v;async function y(e){let t=[];for await(let n of e)t.push(n);return Promise.resolve(t)}e.asyncToArray=y})(dq||={});var fq=null;function pq(e){return fq?.trackDisposable(e),e}function mq(e){fq?.markAsDisposed(e)}function hq(e,t){fq?.setParent(e,t)}function gq(e){return fq?.markAsSingleton(e),e}function _q(e){if(dq.is(e)){let t=[];for(let n of e)if(n)try{n.dispose()}catch(e){t.push(e)}if(t.length===1)throw t[0];if(t.length>1)throw AggregateError(t,`Encountered errors while disposing of store`);return Array.isArray(e)?[]:e}if(e)return e.dispose(),e}function vq(...e){return yq(()=>_q(e))}function yq(e){let t=pq({dispose:uq(()=>{mq(t),e()})});return t}var bq=class e{constructor(){this._toDispose=new Set,this._isDisposed=!1,pq(this)}dispose(){this._isDisposed||(mq(this),this._isDisposed=!0,this.clear())}get isDisposed(){return this._isDisposed}clear(){if(this._toDispose.size!==0)try{_q(this._toDispose)}finally{this._toDispose.clear()}}add(t){if(!t)return t;if(t===this)throw Error(`Cannot register a disposable on itself!`);return hq(t,this),this._isDisposed?e.DISABLE_DISPOSED_WARNING||console.warn(Error(`Trying to add a disposable to a DisposableStore that has already been disposed of. The added object will be leaked!`).stack):this._toDispose.add(t),t}delete(e){if(e){if(e===this)throw Error(`Cannot dispose a disposable on itself!`);this._toDispose.delete(e),e.dispose()}}deleteAndLeak(e){e&&this._toDispose.has(e)&&(this._toDispose.delete(e),hq(e,null))}};bq.DISABLE_DISPOSED_WARNING=!1;var xq=bq,Sq=class{constructor(){this._store=new xq,pq(this),hq(this._store,this)}dispose(){mq(this),this._store.dispose()}_register(e){if(e===this)throw Error(`Cannot register a disposable on itself!`);return this._store.add(e)}};Sq.None=Object.freeze({dispose(){}});var Cq=class{constructor(){this._isDisposed=!1,pq(this)}get value(){return this._isDisposed?void 0:this._value}set value(e){this._isDisposed||e===this._value||(this._value?.dispose(),e&&hq(e,this),this._value=e)}clear(){this.value=void 0}dispose(){this._isDisposed=!0,mq(this),this._value?.dispose(),this._value=void 0}clearAndLeak(){let e=this._value;return this._value=void 0,e&&hq(e,null),e}},wq=typeof window==`object`?window:globalThis,Tq=class e{constructor(t){this.element=t,this.next=e.Undefined,this.prev=e.Undefined}};Tq.Undefined=new Tq(void 0);var Eq=Tq,Dq=class{constructor(){this._first=Eq.Undefined,this._last=Eq.Undefined,this._size=0}get size(){return this._size}isEmpty(){return this._first===Eq.Undefined}clear(){let e=this._first;for(;e!==Eq.Undefined;){let t=e.next;e.prev=Eq.Undefined,e.next=Eq.Undefined,e=t}this._first=Eq.Undefined,this._last=Eq.Undefined,this._size=0}unshift(e){return this._insert(e,!1)}push(e){return this._insert(e,!0)}_insert(e,t){let n=new Eq(e);if(this._first===Eq.Undefined)this._first=n,this._last=n;else if(t){let e=this._last;this._last=n,n.prev=e,e.next=n}else{let e=this._first;this._first=n,n.next=e,e.prev=n}this._size+=1;let r=!1;return()=>{r||(r=!0,this._remove(n))}}shift(){if(this._first!==Eq.Undefined){let e=this._first.element;return this._remove(this._first),e}}pop(){if(this._last!==Eq.Undefined){let e=this._last.element;return this._remove(this._last),e}}_remove(e){if(e.prev!==Eq.Undefined&&e.next!==Eq.Undefined){let t=e.prev;t.next=e.next,e.next.prev=t}else e.prev===Eq.Undefined&&e.next===Eq.Undefined?(this._first=Eq.Undefined,this._last=Eq.Undefined):e.next===Eq.Undefined?(this._last=this._last.prev,this._last.next=Eq.Undefined):e.prev===Eq.Undefined&&(this._first=this._first.next,this._first.prev=Eq.Undefined);--this._size}*[Symbol.iterator](){let e=this._first;for(;e!==Eq.Undefined;)yield e.element,e=e.next}},Oq=globalThis.performance&&typeof globalThis.performance.now==`function`,kq=class e{static create(t){return new e(t)}constructor(e){this._now=Oq&&e===!1?Date.now:globalThis.performance.now.bind(globalThis.performance),this._startTime=this._now(),this._stopTime=-1}stop(){this._stopTime=this._now()}reset(){this._startTime=this._now(),this._stopTime=-1}elapsed(){return this._stopTime===-1?this._now()-this._startTime:this._stopTime-this._startTime}},Aq;(e=>{e.None=()=>Sq.None;function t(e,t){return d(e,()=>{},0,void 0,!0,void 0,t)}e.defer=t;function n(e){return(t,n=null,r)=>{let i=!1,a;return a=e(e=>{if(!i)return a?a.dispose():i=!0,t.call(n,e)},null,r),i&&a.dispose(),a}}e.once=n;function r(e,t,n){return l((n,r=null,i)=>e(e=>n.call(r,t(e)),null,i),n)}e.map=r;function i(e,t,n){return l((n,r=null,i)=>e(e=>{t(e),n.call(r,e)},null,i),n)}e.forEach=i;function a(e,t,n){return l((n,r=null,i)=>e(e=>t(e)&&n.call(r,e),null,i),n)}e.filter=a;function o(e){return e}e.signal=o;function s(...e){return(t,n=null,r)=>u(vq(...e.map(e=>e(e=>t.call(n,e)))),r)}e.any=s;function c(e,t,n,i){let a=n;return r(e,e=>(a=t(a,e),a),i)}e.reduce=c;function l(e,t){let n,r=new Hq({onWillAddFirstListener(){n=e(r.fire,r)},onDidRemoveLastListener(){n?.dispose()}});return t?.add(r),r.event}function u(e,t){return t instanceof Array?t.push(e):t&&t.add(e),e}function d(e,t,n=100,r=!1,i=!1,a,o){let s,c,l,u=0,d,f=new Hq({leakWarningThreshold:a,onWillAddFirstListener(){s=e(e=>{u++,c=t(c,e),r&&!l&&(f.fire(c),c=void 0),d=()=>{let e=c;c=void 0,l=void 0,(!r||u>1)&&f.fire(e),u=0},typeof n==`number`?(clearTimeout(l),l=setTimeout(d,n)):l===void 0&&(l=0,queueMicrotask(d))})},onWillRemoveListener(){i&&u>0&&d?.()},onDidRemoveLastListener(){d=void 0,s.dispose()}});return o?.add(f),f.event}e.debounce=d;function f(t,n=0,r){return e.debounce(t,(e,t)=>e?(e.push(t),e):[t],n,void 0,!0,void 0,r)}e.accumulate=f;function p(e,t=(e,t)=>e===t,n){let r=!0,i;return a(e,e=>{let n=r||!t(e,i);return r=!1,i=e,n},n)}e.latch=p;function m(t,n,r){return[e.filter(t,n,r),e.filter(t,e=>!n(e),r)]}e.split=m;function h(e,t=!1,n=[],r){let i=n.slice(),a=e(e=>{i?i.push(e):s.fire(e)});r&&r.add(a);let o=()=>{i?.forEach(e=>s.fire(e)),i=null},s=new Hq({onWillAddFirstListener(){a||(a=e(e=>s.fire(e)),r&&r.add(a))},onDidAddFirstListener(){i&&(t?setTimeout(o):o())},onDidRemoveLastListener(){a&&a.dispose(),a=null}});return r&&r.add(s),s.event}e.buffer=h;function g(e,t){return(n,r,i)=>{let a=t(new v);return e(function(e){let t=a.evaluate(e);t!==_&&n.call(r,t)},void 0,i)}}e.chain=g;let _=Symbol(`HaltChainable`);class v{constructor(){this.steps=[]}map(e){return this.steps.push(e),this}forEach(e){return this.steps.push(t=>(e(t),t)),this}filter(e){return this.steps.push(t=>e(t)?t:_),this}reduce(e,t){let n=t;return this.steps.push(t=>(n=e(n,t),n)),this}latch(e=(e,t)=>e===t){let t=!0,n;return this.steps.push(r=>{let i=t||!e(r,n);return t=!1,n=r,i?r:_}),this}evaluate(e){for(let t of this.steps)if(e=t(e),e===_)break;return e}}function y(e,t,n=e=>e){let r=(...e)=>i.fire(n(...e)),i=new Hq({onWillAddFirstListener:()=>e.on(t,r),onDidRemoveLastListener:()=>e.removeListener(t,r)});return i.event}e.fromNodeEventEmitter=y;function b(e,t,n=e=>e){let r=(...e)=>i.fire(n(...e)),i=new Hq({onWillAddFirstListener:()=>e.addEventListener(t,r),onDidRemoveLastListener:()=>e.removeEventListener(t,r)});return i.event}e.fromDOMEventEmitter=b;function x(e){return new Promise(t=>n(e)(t))}e.toPromise=x;function S(e){let t=new Hq;return e.then(e=>{t.fire(e)},()=>{t.fire(void 0)}).finally(()=>{t.dispose()}),t.event}e.fromPromise=S;function C(e,t){return e(e=>t.fire(e))}e.forward=C;function w(e,t,n){return t(n),e(e=>t(e))}e.runAndSubscribe=w;class T{constructor(e,t){this._observable=e,this._counter=0,this._hasChanged=!1;let n={onWillAddFirstListener:()=>{e.addObserver(this)},onDidRemoveLastListener:()=>{e.removeObserver(this)}};this.emitter=new Hq(n),t&&t.add(this.emitter)}beginUpdate(e){this._counter++}handlePossibleChange(e){}handleChange(e,t){this._hasChanged=!0}endUpdate(e){this._counter--,this._counter===0&&(this._observable.reportChanges(),this._hasChanged&&(this._hasChanged=!1,this.emitter.fire(this._observable.get())))}}function E(e,t){return new T(e,t).emitter.event}e.fromObservable=E;function D(e){return(t,n,r)=>{let i=0,a=!1,o={beginUpdate(){i++},endUpdate(){i--,i===0&&(e.reportChanges(),a&&(a=!1,t.call(n)))},handlePossibleChange(){},handleChange(){a=!0}};e.addObserver(o),e.reportChanges();let s={dispose(){e.removeObserver(o)}};return r instanceof xq?r.add(s):Array.isArray(r)&&r.push(s),s}}e.fromObservableLight=D})(Aq||={});var jq=class e{constructor(t){this.listenerCount=0,this.invocationCount=0,this.elapsedOverall=0,this.durations=[],this.name=`${t}_${e._idPool++}`,e.all.add(this)}start(e){this._stopWatch=new kq,this.listenerCount=e}stop(){if(this._stopWatch){let e=this._stopWatch.elapsed();this.durations.push(e),this.elapsedOverall+=e,this.invocationCount+=1,this._stopWatch=void 0}}};jq.all=new Set,jq._idPool=0;var Mq=jq,Nq=-1,Pq=class e{constructor(t,n,r=(e._idPool++).toString(16).padStart(3,`0`)){this._errorHandler=t,this.threshold=n,this.name=r,this._warnCountdown=0}dispose(){this._stacks?.clear()}check(e,t){let n=this.threshold;if(n<=0||t<n)return;this._stacks||=new Map;let r=this._stacks.get(e.value)||0;if(this._stacks.set(e.value,r+1),--this._warnCountdown,this._warnCountdown<=0){this._warnCountdown=n*.5;let[e,r]=this.getMostFrequentStack(),i=`[${this.name}] potential listener LEAK detected, having ${t} listeners already. MOST frequent listener (${r}):`;console.warn(i),console.warn(e);let a=new Lq(i,e);this._errorHandler(a)}return()=>{let t=this._stacks.get(e.value)||0;this._stacks.set(e.value,t-1)}}getMostFrequentStack(){if(!this._stacks)return;let e,t=0;for(let[n,r]of this._stacks)(!e||t<r)&&(e=[n,r],t=r);return e}};Pq._idPool=1;var Fq=Pq,Iq=class e{constructor(e){this.value=e}static create(){return new e(Error().stack??``)}print(){console.warn(this.value.split(`
1524
1525
  `).slice(2).join(`
1525
- `))}},Iq=class extends Error{constructor(e,t){super(e),this.name=`ListenerLeakError`,this.stack=t}},Lq=class extends Error{constructor(e,t){super(e),this.name=`ListenerRefusalError`,this.stack=t}},Rq=0,zq=class{constructor(e){this.value=e,this.id=Rq++}},Bq=2,Vq=class{constructor(e){this._size=0,this._options=e,this._leakageMon=Mq>0||this._options?.leakWarningThreshold?new Pq(e?.onListenerError??$K,this._options?.leakWarningThreshold??Mq):void 0,this._perfMon=this._options?._profName?new jq(this._options._profName):void 0,this._deliveryQueue=this._options?.deliveryQueue}dispose(){this._disposed||(this._disposed=!0,this._deliveryQueue?.current===this&&this._deliveryQueue.reset(),this._listeners&&(this._listeners=void 0,this._size=0),this._options?.onDidRemoveLastListener?.(),this._leakageMon?.dispose())}get event(){return this._event??=(e,t,n)=>{if(this._leakageMon&&this._size>this._leakageMon.threshold**2){let e=`[${this._leakageMon.name}] REFUSES to accept new listeners because it exceeded its threshold by far (${this._size} vs ${this._leakageMon.threshold})`;console.warn(e);let t=this._leakageMon.getMostFrequentStack()??[`UNKNOWN stack`,-1],n=new Lq(`${e}. HINT: Stack shows most frequent listener (${t[1]}-times)`,t[0]);return(this._options?.onListenerError||$K)(n),xq.None}if(this._disposed)return xq.None;t&&(e=e.bind(t));let r=new zq(e),i;this._leakageMon&&this._size>=Math.ceil(this._leakageMon.threshold*.2)&&(r.stack=Fq.create(),i=this._leakageMon.check(r.stack,this._size+1)),this._listeners?this._listeners instanceof zq?(this._deliveryQueue??=new Hq,this._listeners=[this._listeners,r]):this._listeners.push(r):(this._options?.onWillAddFirstListener?.(this),this._listeners=r,this._options?.onDidAddFirstListener?.(this)),this._size++;let a=vq(()=>{i?.(),this._removeListener(r)});return n instanceof bq?n.add(a):Array.isArray(n)&&n.push(a),a},this._event}_removeListener(e){if(this._options?.onWillRemoveListener?.(this),!this._listeners)return;if(this._size===1){this._listeners=void 0,this._options?.onDidRemoveLastListener?.(this),this._size=0;return}let t=this._listeners,n=t.indexOf(e);if(n===-1)throw console.log(`disposed?`,this._disposed),console.log(`size?`,this._size),console.log(`arr?`,JSON.stringify(this._listeners)),Error(`Attempted to dispose unknown listener`);this._size--,t[n]=void 0;let r=this._deliveryQueue.current===this;if(this._size*Bq<=t.length){let e=0;for(let n=0;n<t.length;n++)t[n]?t[e++]=t[n]:r&&(this._deliveryQueue.end--,e<this._deliveryQueue.i&&this._deliveryQueue.i--);t.length=e}}_deliver(e,t){if(!e)return;let n=this._options?.onListenerError||$K;if(!n)e.value(t);else try{e.value(t)}catch(e){n(e)}}_deliverQueue(e){let t=e.current._listeners;for(;e.i<e.end;)this._deliver(t[e.i++],e.value);e.reset()}fire(e){if(this._deliveryQueue?.current&&(this._deliverQueue(this._deliveryQueue),this._perfMon?.stop()),this._perfMon?.start(this._size),this._listeners){if(this._listeners instanceof zq)this._deliver(this._listeners,e);else{let t=this._deliveryQueue;t.enqueue(this,e,this._listeners.length),this._deliverQueue(t)}}this._perfMon?.stop()}hasListeners(){return this._size>0}},Hq=class{constructor(){this.i=-1,this.end=0}enqueue(e,t,n){this.i=0,this.end=n,this.current=e,this.value=t}reset(){this.i=this.end,this.current=void 0,this.value=void 0}},Uq=class{constructor(){this.mapWindowIdToZoomLevel=new Map,this._onDidChangeZoomLevel=new Vq,this.onDidChangeZoomLevel=this._onDidChangeZoomLevel.event,this.mapWindowIdToZoomFactor=new Map,this._onDidChangeFullscreen=new Vq,this.onDidChangeFullscreen=this._onDidChangeFullscreen.event,this.mapWindowIdToFullScreen=new Map}getZoomLevel(e){return this.mapWindowIdToZoomLevel.get(this.getWindowId(e))??0}setZoomLevel(e,t){if(this.getZoomLevel(t)===e)return;let n=this.getWindowId(t);this.mapWindowIdToZoomLevel.set(n,e),this._onDidChangeZoomLevel.fire(n)}getZoomFactor(e){return this.mapWindowIdToZoomFactor.get(this.getWindowId(e))??1}setZoomFactor(e,t){this.mapWindowIdToZoomFactor.set(this.getWindowId(t),e)}setFullscreen(e,t){if(this.isFullscreen(t)===e)return;let n=this.getWindowId(t);this.mapWindowIdToFullScreen.set(n,e),this._onDidChangeFullscreen.fire(n)}isFullscreen(e){return!!this.mapWindowIdToFullScreen.get(this.getWindowId(e))}getWindowId(e){return e.vscodeWindowId}};Uq.INSTANCE=new Uq;var Wq=Uq;function Gq(e,t,n){typeof t==`string`&&(t=e.matchMedia(t)),t.addEventListener(`change`,n)}Wq.INSTANCE.onDidChangeZoomLevel;function Kq(e){return Wq.INSTANCE.getZoomFactor(e)}Wq.INSTANCE.onDidChangeFullscreen;var qq=typeof navigator==`object`?navigator.userAgent:``,Jq=qq.indexOf(`Firefox`)>=0,Yq=qq.indexOf(`AppleWebKit`)>=0,Xq=qq.indexOf(`Chrome`)>=0,Zq=!Xq&&qq.indexOf(`Safari`)>=0;qq.indexOf(`Electron/`),qq.indexOf(`Android`);var Qq=!1;if(typeof Cq.matchMedia==`function`){let e=Cq.matchMedia(`(display-mode: standalone) or (display-mode: window-controls-overlay)`),t=Cq.matchMedia(`(display-mode: fullscreen)`);Qq=e.matches,Gq(Cq,e,({matches:e})=>{Qq&&t.matches||(Qq=e)})}function $q(){return Qq}var eJ=`en`,tJ=!1,nJ=!1,rJ=!1,iJ=!1,aJ=!1,oJ=eJ,sJ,cJ=globalThis,lJ;typeof cJ.vscode<`u`&&typeof cJ.vscode.process<`u`?lJ=cJ.vscode.process:typeof process<`u`&&typeof process?.versions?.node==`string`&&(lJ=process);var uJ=typeof lJ?.versions?.electron==`string`&&lJ?.type===`renderer`;if(typeof lJ==`object`){tJ=lJ.platform===`win32`,nJ=lJ.platform===`darwin`,rJ=lJ.platform===`linux`,rJ&&lJ.env.SNAP&&lJ.env.SNAP_REVISION,lJ.env.CI||lJ.env.BUILD_ARTIFACTSTAGINGDIRECTORY,oJ=eJ;let e=lJ.env.VSCODE_NLS_CONFIG;if(e)try{let t=JSON.parse(e);t.userLocale,t.osLocale,oJ=t.resolvedLanguage||eJ,t.languagePack?.translationsConfigFile}catch{}iJ=!0}else typeof navigator==`object`&&!uJ?(sJ=navigator.userAgent,tJ=sJ.indexOf(`Windows`)>=0,nJ=sJ.indexOf(`Macintosh`)>=0,(sJ.indexOf(`Macintosh`)>=0||sJ.indexOf(`iPad`)>=0||sJ.indexOf(`iPhone`)>=0)&&navigator.maxTouchPoints&&navigator.maxTouchPoints,rJ=sJ.indexOf(`Linux`)>=0,sJ?.indexOf(`Mobi`),aJ=!0,oJ=globalThis._VSCODE_NLS_LANGUAGE||eJ,navigator.language.toLowerCase()):console.error(`Unable to resolve platform.`);var dJ=tJ,fJ=nJ,pJ=rJ,mJ=iJ;aJ&&typeof cJ.importScripts==`function`&&cJ.origin;var hJ=sJ,gJ=oJ,_J;(e=>{function t(){return gJ}e.value=t;function n(){return gJ.length===2?gJ===`en`:gJ.length>=3&&gJ[0]===`e`&&gJ[1]===`n`&&gJ[2]===`-`}e.isDefaultVariant=n;function r(){return gJ===`en`}e.isDefault=r})(_J||={});var vJ=typeof cJ.postMessage==`function`&&!cJ.importScripts;(()=>{if(vJ){let e=[];cJ.addEventListener(`message`,t=>{if(t.data&&t.data.vscodeScheduleAsyncWork)for(let n=0,r=e.length;n<r;n++){let r=e[n];if(r.id===t.data.vscodeScheduleAsyncWork){e.splice(n,1),r.callback();return}}});let t=0;return n=>{let r=++t;e.push({id:r,callback:n}),cJ.postMessage({vscodeScheduleAsyncWork:r},`*`)}}return e=>setTimeout(e)})();var yJ=!!(hJ&&hJ.indexOf(`Chrome`)>=0);hJ&&hJ.indexOf(`Firefox`),!yJ&&hJ&&hJ.indexOf(`Safari`),hJ&&hJ.indexOf(`Edg/`),hJ&&hJ.indexOf(`Android`);var bJ=typeof navigator==`object`?navigator:{};mJ||document.queryCommandSupported&&document.queryCommandSupported(`copy`)||bJ&&bJ.clipboard&&bJ.clipboard.writeText,mJ||bJ&&bJ.clipboard&&bJ.clipboard.readText,mJ||$q()||bJ.keyboard,`ontouchstart`in Cq||bJ.maxTouchPoints,Cq.PointerEvent&&(`ontouchstart`in Cq||navigator.maxTouchPoints);var xJ=class{constructor(){this._keyCodeToStr=[],this._strToKeyCode=Object.create(null)}define(e,t){this._keyCodeToStr[e]=t,this._strToKeyCode[t.toLowerCase()]=e}keyCodeToStr(e){return this._keyCodeToStr[e]}strToKeyCode(e){return this._strToKeyCode[e.toLowerCase()]||0}},SJ=new xJ,CJ=new xJ,wJ=new xJ,TJ=Array(230),EJ;(e=>{function t(e){return SJ.keyCodeToStr(e)}e.toString=t;function n(e){return SJ.strToKeyCode(e)}e.fromString=n;function r(e){return CJ.keyCodeToStr(e)}e.toUserSettingsUS=r;function i(e){return wJ.keyCodeToStr(e)}e.toUserSettingsGeneral=i;function a(e){return CJ.strToKeyCode(e)||wJ.strToKeyCode(e)}e.fromUserSettings=a;function o(e){if(e>=98&&e<=113)return null;switch(e){case 16:return`Up`;case 18:return`Down`;case 15:return`Left`;case 17:return`Right`}return SJ.keyCodeToStr(e)}e.toElectronAccelerator=o})(EJ||={});var DJ=class e{constructor(e,t,n,r,i){this.ctrlKey=e,this.shiftKey=t,this.altKey=n,this.metaKey=r,this.keyCode=i}equals(t){return t instanceof e&&this.ctrlKey===t.ctrlKey&&this.shiftKey===t.shiftKey&&this.altKey===t.altKey&&this.metaKey===t.metaKey&&this.keyCode===t.keyCode}getHashCode(){return`K${this.ctrlKey?`1`:`0`}${this.shiftKey?`1`:`0`}${this.altKey?`1`:`0`}${this.metaKey?`1`:`0`}${this.keyCode}`}isModifierKey(){return this.keyCode===0||this.keyCode===5||this.keyCode===57||this.keyCode===6||this.keyCode===4}toKeybinding(){return new OJ([this])}isDuplicateModifierCase(){return this.ctrlKey&&this.keyCode===5||this.shiftKey&&this.keyCode===4||this.altKey&&this.keyCode===6||this.metaKey&&this.keyCode===57}},OJ=class{constructor(e){if(e.length===0)throw rq(`chords`);this.chords=e}getHashCode(){let e=``;for(let t=0,n=this.chords.length;t<n;t++)t!==0&&(e+=`;`),e+=this.chords[t].getHashCode();return e}equals(e){if(e===null||this.chords.length!==e.chords.length)return!1;for(let t=0;t<this.chords.length;t++)if(!this.chords[t].equals(e.chords[t]))return!1;return!0}};function kJ(e){if(e.charCode){let t=String.fromCharCode(e.charCode).toUpperCase();return EJ.fromString(t)}let t=e.keyCode;if(t===3)return 7;if(Jq)switch(t){case 59:return 85;case 60:if(pJ)return 97;break;case 61:return 86;case 107:return 109;case 109:return 111;case 173:return 88;case 224:if(fJ)return 57}else if(Yq&&(fJ&&t===93||!fJ&&t===92))return 57;return TJ[t]||0}var AJ=fJ?256:2048,jJ=512,MJ=1024,NJ=fJ?2048:256,PJ=class{constructor(e){this._standardKeyboardEventBrand=!0;let t=e;this.browserEvent=t,this.target=t.target,this.ctrlKey=t.ctrlKey,this.shiftKey=t.shiftKey,this.altKey=t.altKey,this.metaKey=t.metaKey,this.altGraphKey=t.getModifierState?.(`AltGraph`),this.keyCode=kJ(t),this.code=t.code,this.ctrlKey=this.ctrlKey||this.keyCode===5,this.altKey=this.altKey||this.keyCode===6,this.shiftKey=this.shiftKey||this.keyCode===4,this.metaKey=this.metaKey||this.keyCode===57,this._asKeybinding=this._computeKeybinding(),this._asKeyCodeChord=this._computeKeyCodeChord()}preventDefault(){this.browserEvent&&this.browserEvent.preventDefault&&this.browserEvent.preventDefault()}stopPropagation(){this.browserEvent&&this.browserEvent.stopPropagation&&this.browserEvent.stopPropagation()}toKeyCodeChord(){return this._asKeyCodeChord}equals(e){return this._asKeybinding===e}_computeKeybinding(){let e=0;this.keyCode!==5&&this.keyCode!==4&&this.keyCode!==6&&this.keyCode!==57&&(e=this.keyCode);let t=0;return this.ctrlKey&&(t|=AJ),this.altKey&&(t|=jJ),this.shiftKey&&(t|=MJ),this.metaKey&&(t|=NJ),t|=e,t}_computeKeyCodeChord(){let e=0;return this.keyCode!==5&&this.keyCode!==4&&this.keyCode!==6&&this.keyCode!==57&&(e=this.keyCode),new DJ(this.ctrlKey,this.shiftKey,this.altKey,this.metaKey,e)}},FJ=new WeakMap;function IJ(e){if(!e.parent||e.parent===e)return null;try{let t=e.location,n=e.parent.location;if(t.origin!==`null`&&n.origin!==`null`&&t.origin!==n.origin)return null}catch{return null}return e.parent}var LJ=class{static getSameOriginWindowChain(e){let t=FJ.get(e);if(!t){t=[],FJ.set(e,t);let n=e,r;do r=IJ(n),r?t.push({window:new WeakRef(n),iframeElement:n.frameElement||null}):t.push({window:new WeakRef(n),iframeElement:null}),n=r;while(n)}return t.slice(0)}static getPositionOfChildWindowRelativeToAncestorWindow(e,t){if(!t||e===t)return{top:0,left:0};let n=0,r=0,i=this.getSameOriginWindowChain(e);for(let e of i){let i=e.window.deref();if(n+=i?.scrollY??0,r+=i?.scrollX??0,i===t||!e.iframeElement)break;let a=e.iframeElement.getBoundingClientRect();n+=a.top,r+=a.left}return{top:n,left:r}}},RJ=class{constructor(e,t){this.timestamp=Date.now(),this.browserEvent=t,this.leftButton=t.button===0,this.middleButton=t.button===1,this.rightButton=t.button===2,this.buttons=t.buttons,this.target=t.target,this.detail=t.detail||1,t.type===`dblclick`&&(this.detail=2),this.ctrlKey=t.ctrlKey,this.shiftKey=t.shiftKey,this.altKey=t.altKey,this.metaKey=t.metaKey,typeof t.pageX==`number`?(this.posx=t.pageX,this.posy=t.pageY):(this.posx=t.clientX+this.target.ownerDocument.body.scrollLeft+this.target.ownerDocument.documentElement.scrollLeft,this.posy=t.clientY+this.target.ownerDocument.body.scrollTop+this.target.ownerDocument.documentElement.scrollTop);let n=LJ.getPositionOfChildWindowRelativeToAncestorWindow(e,t.view);this.posx-=n.left,this.posy-=n.top}preventDefault(){this.browserEvent.preventDefault()}stopPropagation(){this.browserEvent.stopPropagation()}},zJ=class{constructor(e,t=0,n=0){this.browserEvent=e||null,this.target=e?e.target||e.targetNode||e.srcElement:null,this.deltaY=n,this.deltaX=t;let r=!1;if(Xq){let e=navigator.userAgent.match(/Chrome\/(\d+)/);r=(e?parseInt(e[1]):123)<=122}if(e){let t=e,n=e,i=e.view?.devicePixelRatio||1;if(typeof t.wheelDeltaY<`u`)this.deltaY=r?t.wheelDeltaY/(120*i):t.wheelDeltaY/120;else if(typeof n.VERTICAL_AXIS<`u`&&n.axis===n.VERTICAL_AXIS)this.deltaY=-n.detail/3;else if(e.type===`wheel`){let t=e;this.deltaY=t.deltaMode===t.DOM_DELTA_LINE?Jq&&!fJ?-e.deltaY/3:-e.deltaY:-e.deltaY/40}if(typeof t.wheelDeltaX<`u`)this.deltaX=Zq&&dJ?-(t.wheelDeltaX/120):r?t.wheelDeltaX/(120*i):t.wheelDeltaX/120;else if(typeof n.HORIZONTAL_AXIS<`u`&&n.axis===n.HORIZONTAL_AXIS)this.deltaX=-e.detail/3;else if(e.type===`wheel`){let t=e;this.deltaX=t.deltaMode===t.DOM_DELTA_LINE?Jq&&!fJ?-e.deltaX/3:-e.deltaX:-e.deltaX/40}this.deltaY===0&&this.deltaX===0&&e.wheelDelta&&(this.deltaY=r?e.wheelDelta/(120*i):e.wheelDelta/120)}}preventDefault(){this.browserEvent?.preventDefault()}stopPropagation(){this.browserEvent?.stopPropagation()}},BJ=Object.freeze(function(e,t){let n=setTimeout(e.bind(t),0);return{dispose(){clearTimeout(n)}}}),VJ;(e=>{function t(t){return t===e.None||t===e.Cancelled||t instanceof HJ?!0:!t||typeof t!=`object`?!1:typeof t.isCancellationRequested==`boolean`&&typeof t.onCancellationRequested==`function`}e.isCancellationToken=t,e.None=Object.freeze({isCancellationRequested:!1,onCancellationRequested:kq.None}),e.Cancelled=Object.freeze({isCancellationRequested:!0,onCancellationRequested:BJ})})(VJ||={});var HJ=class{constructor(){this._isCancelled=!1,this._emitter=null}cancel(){this._isCancelled||(this._isCancelled=!0,this._emitter&&(this._emitter.fire(void 0),this.dispose()))}get isCancellationRequested(){return this._isCancelled}get onCancellationRequested(){return this._isCancelled?BJ:(this._emitter||=new Vq,this._emitter.event)}dispose(){this._emitter&&=(this._emitter.dispose(),null)}},UJ=class{constructor(e,t){this._isDisposed=!1,this._token=-1,typeof e==`function`&&typeof t==`number`&&this.setIfNotSet(e,t)}dispose(){this.cancel(),this._isDisposed=!0}cancel(){this._token!==-1&&(clearTimeout(this._token),this._token=-1)}cancelAndSet(e,t){if(this._isDisposed)throw new aq(`Calling 'cancelAndSet' on a disposed TimeoutTimer`);this.cancel(),this._token=setTimeout(()=>{this._token=-1,e()},t)}setIfNotSet(e,t){if(this._isDisposed)throw new aq(`Calling 'setIfNotSet' on a disposed TimeoutTimer`);this._token===-1&&(this._token=setTimeout(()=>{this._token=-1,e()},t))}},WJ=class{constructor(){this.disposable=void 0,this.isDisposed=!1}cancel(){this.disposable?.dispose(),this.disposable=void 0}cancelAndSet(e,t,n=globalThis){if(this.isDisposed)throw new aq(`Calling 'cancelAndSet' on a disposed IntervalTimer`);this.cancel();let r=n.setInterval(()=>{e()},t);this.disposable=vq(()=>{n.clearInterval(r),this.disposable=void 0})}dispose(){this.cancel(),this.isDisposed=!0}};(function(){typeof globalThis.requestIdleCallback!=`function`||globalThis.cancelIdleCallback})();var GJ;(e=>{async function t(e){let t,n=await Promise.all(e.map(e=>e.then(e=>e,e=>{t||=e})));if(typeof t<`u`)throw t;return n}e.settled=t;function n(e){return new Promise(async(t,n)=>{try{await e(t,n)}catch(e){n(e)}})}e.withAsyncBody=n})(GJ||={});var KJ=class e{static fromArray(t){return new e(e=>{e.emitMany(t)})}static fromPromise(t){return new e(async e=>{e.emitMany(await t)})}static fromPromises(t){return new e(async e=>{await Promise.all(t.map(async t=>e.emitOne(await t)))})}static merge(t){return new e(async e=>{await Promise.all(t.map(async t=>{for await(let n of t)e.emitOne(n)}))})}constructor(e,t){this._state=0,this._results=[],this._error=null,this._onReturn=t,this._onStateChanged=new Vq,queueMicrotask(async()=>{let t={emitOne:e=>this.emitOne(e),emitMany:e=>this.emitMany(e),reject:e=>this.reject(e)};try{await Promise.resolve(e(t)),this.resolve()}catch(e){this.reject(e)}finally{t.emitOne=void 0,t.emitMany=void 0,t.reject=void 0}})}[Symbol.asyncIterator](){let e=0;return{next:async()=>{do{if(this._state===2)throw this._error;if(e<this._results.length)return{done:!1,value:this._results[e++]};if(this._state===1)return{done:!0,value:void 0};await kq.toPromise(this._onStateChanged.event)}while(1)},return:async()=>(this._onReturn?.(),{done:!0,value:void 0})}}static map(t,n){return new e(async e=>{for await(let r of t)e.emitOne(n(r))})}map(t){return e.map(this,t)}static filter(t,n){return new e(async e=>{for await(let r of t)n(r)&&e.emitOne(r)})}filter(t){return e.filter(this,t)}static coalesce(t){return e.filter(t,e=>!!e)}coalesce(){return e.coalesce(this)}static async toPromise(e){let t=[];for await(let n of e)t.push(n);return t}toPromise(){return e.toPromise(this)}emitOne(e){this._state===0&&(this._results.push(e),this._onStateChanged.fire())}emitMany(e){this._state===0&&(this._results=this._results.concat(e),this._onStateChanged.fire())}resolve(){this._state===0&&(this._state=1,this._onStateChanged.fire())}reject(e){this._state===0&&(this._state=2,this._error=e,this._onStateChanged.fire())}};KJ.EMPTY=KJ.fromArray([]);function qJ(e){return JJ(e,0)}function JJ(e,t){switch(typeof e){case`object`:return e===null?YJ(349,t):Array.isArray(e)?QJ(e,t):$J(e,t);case`string`:return ZJ(e,t);case`boolean`:return XJ(e,t);case`number`:return YJ(e,t);case`undefined`:return YJ(937,t);default:return YJ(617,t)}}function YJ(e,t){return(t<<5)-t+e|0}function XJ(e,t){return YJ(e?433:863,t)}function ZJ(e,t){t=YJ(149417,t);for(let n=0,r=e.length;n<r;n++)t=YJ(e.charCodeAt(n),t);return t}function QJ(e,t){return t=YJ(104579,t),e.reduce((e,t)=>JJ(t,e),t)}function $J(e,t){return t=YJ(181387,t),Object.keys(e).sort().reduce((t,n)=>(t=ZJ(n,t),JJ(e[n],t)),t)}var{registerWindow:eY,getWindow:tY,getDocument:nY,getWindows:rY,getWindowsCount:iY,getWindowId:aY,getWindowById:oY,hasWindow:sY,onDidRegisterWindow:cY,onWillUnregisterWindow:lY,onDidUnregisterWindow:uY}=function(){let e=new Map,t={window:Cq,disposables:new bq};e.set(Cq.vscodeWindowId,t);let n=new Vq,r=new Vq,i=new Vq;function a(n,r){return(typeof n==`number`?e.get(n):void 0)??(r?t:void 0)}return{onDidRegisterWindow:n.event,onWillUnregisterWindow:i.event,onDidUnregisterWindow:r.event,registerWindow(t){if(e.has(t.vscodeWindowId))return xq.None;let a=new bq,o={window:t,disposables:a.add(new bq)};return e.set(t.vscodeWindowId,o),a.add(vq(()=>{e.delete(t.vscodeWindowId),r.fire(t)})),a.add(fY(t,xY.BEFORE_UNLOAD,()=>{i.fire(t)})),n.fire(o),a},getWindows(){return e.values()},getWindowsCount(){return e.size},getWindowId(e){return e.vscodeWindowId},hasWindow(t){return e.has(t)},getWindowById:a,getWindow(e){let t=e;if(t?.ownerDocument?.defaultView)return t.ownerDocument.defaultView.window;let n=e;return n?.view?n.view.window:Cq},getDocument(e){return tY(e).document}}}(),dY=class{constructor(e,t,n,r){this._node=e,this._type=t,this._handler=n,this._options=r||!1,this._node.addEventListener(this._type,this._handler,this._options)}dispose(){this._handler&&=(this._node.removeEventListener(this._type,this._handler,this._options),this._node=null,null)}};function fY(e,t,n,r){return new dY(e,t,n,r)}function pY(e,t){return function(n){return t(new RJ(e,n))}}function mY(e){return function(t){return e(new PJ(t))}}var hY=function(e,t,n,r){let i=n;return t===`click`||t===`mousedown`||t===`contextmenu`?i=pY(tY(e),n):(t===`keydown`||t===`keypress`||t===`keyup`)&&(i=mY(n)),fY(e,t,i,r)},gY,_Y=class extends WJ{constructor(e){super(),this.defaultTarget=e&&tY(e)}cancelAndSet(e,t,n){return super.cancelAndSet(e,t,n??this.defaultTarget)}},vY=class{constructor(e,t=0){this._runner=e,this.priority=t,this._canceled=!1}dispose(){this._canceled=!0}execute(){if(!this._canceled)try{this._runner()}catch(e){$K(e)}}static sort(e,t){return t.priority-e.priority}};(function(){let e=new Map,t=new Map,n=new Map,r=new Map,i=i=>{n.set(i,!1);let a=e.get(i)??[];for(t.set(i,a),e.set(i,[]),r.set(i,!0);a.length>0;)a.sort(vY.sort),a.shift().execute();r.set(i,!1)};gY=(t,r,a=0)=>{let o=aY(t),s=new vY(r,a),c=e.get(o);return c||(c=[],e.set(o,c)),c.push(s),n.get(o)||(n.set(o,!0),t.requestAnimationFrame(()=>i(o))),s}})();var yY=class e{constructor(e,t){this.width=e,this.height=t}with(t=this.width,n=this.height){return t!==this.width||n!==this.height?new e(t,n):this}static is(e){return typeof e==`object`&&typeof e.height==`number`&&typeof e.width==`number`}static lift(t){return t instanceof e?t:new e(t.width,t.height)}static equals(e,t){return e===t?!0:!e||!t?!1:e.width===t.width&&e.height===t.height}};yY.None=new yY(0,0);function bY(e){let t=e.getBoundingClientRect(),n=tY(e);return{left:t.left+n.scrollX,top:t.top+n.scrollY,width:t.width,height:t.height}}new class{constructor(){this.mutationObservers=new Map}observe(e,t,n){let r=this.mutationObservers.get(e);r||(r=new Map,this.mutationObservers.set(e,r));let i=qJ(n),a=r.get(i);if(a)a.users+=1;else{let o=new Vq,s=new MutationObserver(e=>o.fire(e));s.observe(e,n);let c=a={users:1,observer:s,onDidMutate:o.event};t.add(vq(()=>{--c.users,c.users===0&&(o.dispose(),s.disconnect(),r?.delete(i),r?.size===0&&this.mutationObservers.delete(e))})),r.set(i,a)}return a.onDidMutate}};var xY={CLICK:`click`,AUXCLICK:`auxclick`,DBLCLICK:`dblclick`,MOUSE_UP:`mouseup`,MOUSE_DOWN:`mousedown`,MOUSE_OVER:`mouseover`,MOUSE_MOVE:`mousemove`,MOUSE_OUT:`mouseout`,MOUSE_ENTER:`mouseenter`,MOUSE_LEAVE:`mouseleave`,MOUSE_WHEEL:`wheel`,POINTER_UP:`pointerup`,POINTER_DOWN:`pointerdown`,POINTER_MOVE:`pointermove`,POINTER_LEAVE:`pointerleave`,CONTEXT_MENU:`contextmenu`,WHEEL:`wheel`,KEY_DOWN:`keydown`,KEY_PRESS:`keypress`,KEY_UP:`keyup`,LOAD:`load`,BEFORE_UNLOAD:`beforeunload`,UNLOAD:`unload`,PAGE_SHOW:`pageshow`,PAGE_HIDE:`pagehide`,PASTE:`paste`,ABORT:`abort`,ERROR:`error`,RESIZE:`resize`,SCROLL:`scroll`,FULLSCREEN_CHANGE:`fullscreenchange`,WK_FULLSCREEN_CHANGE:`webkitfullscreenchange`,SELECT:`select`,CHANGE:`change`,SUBMIT:`submit`,RESET:`reset`,FOCUS:`focus`,FOCUS_IN:`focusin`,FOCUS_OUT:`focusout`,BLUR:`blur`,INPUT:`input`,STORAGE:`storage`,DRAG_START:`dragstart`,DRAG:`drag`,DRAG_ENTER:`dragenter`,DRAG_LEAVE:`dragleave`,DRAG_OVER:`dragover`,DROP:`drop`,DRAG_END:`dragend`,ANIMATION_START:Yq?`webkitAnimationStart`:`animationstart`,ANIMATION_END:Yq?`webkitAnimationEnd`:`animationend`,ANIMATION_ITERATION:Yq?`webkitAnimationIteration`:`animationiteration`},SY=class{constructor(e){this.domNode=e,this._maxWidth=``,this._width=``,this._height=``,this._top=``,this._left=``,this._bottom=``,this._right=``,this._paddingTop=``,this._paddingLeft=``,this._paddingBottom=``,this._paddingRight=``,this._fontFamily=``,this._fontWeight=``,this._fontSize=``,this._fontStyle=``,this._fontFeatureSettings=``,this._fontVariationSettings=``,this._textDecoration=``,this._lineHeight=``,this._letterSpacing=``,this._className=``,this._display=``,this._position=``,this._visibility=``,this._color=``,this._backgroundColor=``,this._layerHint=!1,this._contain=`none`,this._boxShadow=``}setMaxWidth(e){let t=CY(e);this._maxWidth!==t&&(this._maxWidth=t,this.domNode.style.maxWidth=this._maxWidth)}setWidth(e){let t=CY(e);this._width!==t&&(this._width=t,this.domNode.style.width=this._width)}setHeight(e){let t=CY(e);this._height!==t&&(this._height=t,this.domNode.style.height=this._height)}setTop(e){let t=CY(e);this._top!==t&&(this._top=t,this.domNode.style.top=this._top)}setLeft(e){let t=CY(e);this._left!==t&&(this._left=t,this.domNode.style.left=this._left)}setBottom(e){let t=CY(e);this._bottom!==t&&(this._bottom=t,this.domNode.style.bottom=this._bottom)}setRight(e){let t=CY(e);this._right!==t&&(this._right=t,this.domNode.style.right=this._right)}setPaddingTop(e){let t=CY(e);this._paddingTop!==t&&(this._paddingTop=t,this.domNode.style.paddingTop=this._paddingTop)}setPaddingLeft(e){let t=CY(e);this._paddingLeft!==t&&(this._paddingLeft=t,this.domNode.style.paddingLeft=this._paddingLeft)}setPaddingBottom(e){let t=CY(e);this._paddingBottom!==t&&(this._paddingBottom=t,this.domNode.style.paddingBottom=this._paddingBottom)}setPaddingRight(e){let t=CY(e);this._paddingRight!==t&&(this._paddingRight=t,this.domNode.style.paddingRight=this._paddingRight)}setFontFamily(e){this._fontFamily!==e&&(this._fontFamily=e,this.domNode.style.fontFamily=this._fontFamily)}setFontWeight(e){this._fontWeight!==e&&(this._fontWeight=e,this.domNode.style.fontWeight=this._fontWeight)}setFontSize(e){let t=CY(e);this._fontSize!==t&&(this._fontSize=t,this.domNode.style.fontSize=this._fontSize)}setFontStyle(e){this._fontStyle!==e&&(this._fontStyle=e,this.domNode.style.fontStyle=this._fontStyle)}setFontFeatureSettings(e){this._fontFeatureSettings!==e&&(this._fontFeatureSettings=e,this.domNode.style.fontFeatureSettings=this._fontFeatureSettings)}setFontVariationSettings(e){this._fontVariationSettings!==e&&(this._fontVariationSettings=e,this.domNode.style.fontVariationSettings=this._fontVariationSettings)}setTextDecoration(e){this._textDecoration!==e&&(this._textDecoration=e,this.domNode.style.textDecoration=this._textDecoration)}setLineHeight(e){let t=CY(e);this._lineHeight!==t&&(this._lineHeight=t,this.domNode.style.lineHeight=this._lineHeight)}setLetterSpacing(e){let t=CY(e);this._letterSpacing!==t&&(this._letterSpacing=t,this.domNode.style.letterSpacing=this._letterSpacing)}setClassName(e){this._className!==e&&(this._className=e,this.domNode.className=this._className)}toggleClassName(e,t){this.domNode.classList.toggle(e,t),this._className=this.domNode.className}setDisplay(e){this._display!==e&&(this._display=e,this.domNode.style.display=this._display)}setPosition(e){this._position!==e&&(this._position=e,this.domNode.style.position=this._position)}setVisibility(e){this._visibility!==e&&(this._visibility=e,this.domNode.style.visibility=this._visibility)}setColor(e){this._color!==e&&(this._color=e,this.domNode.style.color=this._color)}setBackgroundColor(e){this._backgroundColor!==e&&(this._backgroundColor=e,this.domNode.style.backgroundColor=this._backgroundColor)}setLayerHinting(e){this._layerHint!==e&&(this._layerHint=e,this.domNode.style.transform=this._layerHint?`translate3d(0px, 0px, 0px)`:``)}setBoxShadow(e){this._boxShadow!==e&&(this._boxShadow=e,this.domNode.style.boxShadow=e)}setContain(e){this._contain!==e&&(this._contain=e,this.domNode.style.contain=this._contain)}setAttribute(e,t){this.domNode.setAttribute(e,t)}removeAttribute(e){this.domNode.removeAttribute(e)}appendChild(e){this.domNode.appendChild(e.domNode)}removeChild(e){this.domNode.removeChild(e.domNode)}};function CY(e){return typeof e==`number`?`${e}px`:e}function wY(e){return new SY(e)}var TY=class{constructor(){this._hooks=new bq,this._pointerMoveCallback=null,this._onStopCallback=null}dispose(){this.stopMonitoring(!1),this._hooks.dispose()}stopMonitoring(e,t){if(!this.isMonitoring())return;this._hooks.clear(),this._pointerMoveCallback=null;let n=this._onStopCallback;this._onStopCallback=null,e&&n&&n(t)}isMonitoring(){return!!this._pointerMoveCallback}startMonitoring(e,t,n,r,i){this.isMonitoring()&&this.stopMonitoring(!1),this._pointerMoveCallback=r,this._onStopCallback=i;let a=e;try{e.setPointerCapture(t),this._hooks.add(vq(()=>{try{e.releasePointerCapture(t)}catch{}}))}catch{a=tY(e)}this._hooks.add(fY(a,xY.POINTER_MOVE,e=>{e.buttons===n?(e.preventDefault(),this._pointerMoveCallback(e)):this.stopMonitoring(!0)})),this._hooks.add(fY(a,xY.POINTER_UP,e=>this.stopMonitoring(!0)))}};function EY(e,t,n){let r=null,i=null;if(typeof n.value==`function`?(r=`value`,i=n.value,i.length!==0&&console.warn(`Memoize should only be used in functions with zero parameters`)):typeof n.get==`function`&&(r=`get`,i=n.get),!i)throw Error(`not supported`);let a=`$memoize$${t}`;n[r]=function(...e){return this.hasOwnProperty(a)||Object.defineProperty(this,a,{configurable:!1,enumerable:!1,writable:!1,value:i.apply(this,e)}),this[a]}}var DY;(e=>(e.Tap=`-xterm-gesturetap`,e.Change=`-xterm-gesturechange`,e.Start=`-xterm-gesturestart`,e.End=`-xterm-gesturesend`,e.Contextmenu=`-xterm-gesturecontextmenu`))(DY||={});var OY=class e extends xq{constructor(){super(),this.dispatched=!1,this.targets=new Eq,this.ignoreTargets=new Eq,this.activeTouches={},this.handle=null,this._lastSetTapCountTime=0,this._register(kq.runAndSubscribe(cY,({window:e,disposables:t})=>{t.add(fY(e.document,`touchstart`,e=>this.onTouchStart(e),{passive:!1})),t.add(fY(e.document,`touchend`,t=>this.onTouchEnd(e,t))),t.add(fY(e.document,`touchmove`,e=>this.onTouchMove(e),{passive:!1}))},{window:Cq,disposables:this._store}))}static addTarget(t){return e.isTouchDevice()?(e.INSTANCE||=hq(new e),vq(e.INSTANCE.targets.push(t))):xq.None}static ignoreTarget(t){return e.isTouchDevice()?(e.INSTANCE||=hq(new e),vq(e.INSTANCE.ignoreTargets.push(t))):xq.None}static isTouchDevice(){return`ontouchstart`in Cq||navigator.maxTouchPoints>0}dispose(){this.handle&&=(this.handle.dispose(),null),super.dispose()}onTouchStart(e){let t=Date.now();this.handle&&=(this.handle.dispose(),null);for(let n=0,r=e.targetTouches.length;n<r;n++){let r=e.targetTouches.item(n);this.activeTouches[r.identifier]={id:r.identifier,initialTarget:r.target,initialTimeStamp:t,initialPageX:r.pageX,initialPageY:r.pageY,rollingTimestamps:[t],rollingPageX:[r.pageX],rollingPageY:[r.pageY]};let i=this.newGestureEvent(DY.Start,r.target);i.pageX=r.pageX,i.pageY=r.pageY,this.dispatchEvent(i)}this.dispatched&&=(e.preventDefault(),e.stopPropagation(),!1)}onTouchEnd(t,n){let r=Date.now(),i=Object.keys(this.activeTouches).length;for(let a=0,o=n.changedTouches.length;a<o;a++){let o=n.changedTouches.item(a);if(!this.activeTouches.hasOwnProperty(String(o.identifier))){console.warn(`move of an UNKNOWN touch`,o);continue}let s=this.activeTouches[o.identifier],c=Date.now()-s.initialTimeStamp;if(c<e.HOLD_DELAY&&Math.abs(s.initialPageX-oq(s.rollingPageX))<30&&Math.abs(s.initialPageY-oq(s.rollingPageY))<30){let e=this.newGestureEvent(DY.Tap,s.initialTarget);e.pageX=oq(s.rollingPageX),e.pageY=oq(s.rollingPageY),this.dispatchEvent(e)}else if(c>=e.HOLD_DELAY&&Math.abs(s.initialPageX-oq(s.rollingPageX))<30&&Math.abs(s.initialPageY-oq(s.rollingPageY))<30){let e=this.newGestureEvent(DY.Contextmenu,s.initialTarget);e.pageX=oq(s.rollingPageX),e.pageY=oq(s.rollingPageY),this.dispatchEvent(e)}else if(i===1){let e=oq(s.rollingPageX),n=oq(s.rollingPageY),i=oq(s.rollingTimestamps)-s.rollingTimestamps[0],a=e-s.rollingPageX[0],o=n-s.rollingPageY[0],c=[...this.targets].filter(e=>s.initialTarget instanceof Node&&e.contains(s.initialTarget));this.inertia(t,c,r,Math.abs(a)/i,a>0?1:-1,e,Math.abs(o)/i,o>0?1:-1,n)}this.dispatchEvent(this.newGestureEvent(DY.End,s.initialTarget)),delete this.activeTouches[o.identifier]}this.dispatched&&=(n.preventDefault(),n.stopPropagation(),!1)}newGestureEvent(e,t){let n=document.createEvent(`CustomEvent`);return n.initEvent(e,!1,!0),n.initialTarget=t,n.tapCount=0,n}dispatchEvent(t){if(t.type===DY.Tap){let n=new Date().getTime(),r=0;r=n-this._lastSetTapCountTime>e.CLEAR_TAP_COUNT_TIME?1:2,this._lastSetTapCountTime=n,t.tapCount=r}else(t.type===DY.Change||t.type===DY.Contextmenu)&&(this._lastSetTapCountTime=0);if(t.initialTarget instanceof Node){for(let e of this.ignoreTargets)if(e.contains(t.initialTarget))return;let e=[];for(let n of this.targets)if(n.contains(t.initialTarget)){let r=0,i=t.initialTarget;for(;i&&i!==n;)r++,i=i.parentElement;e.push([r,n])}e.sort((e,t)=>e[0]-t[0]);for(let[n,r]of e)r.dispatchEvent(t),this.dispatched=!0}}inertia(t,n,r,i,a,o,s,c,l){this.handle=gY(t,()=>{let u=Date.now(),d=u-r,f=0,p=0,m=!0;i+=e.SCROLL_FRICTION*d,s+=e.SCROLL_FRICTION*d,i>0&&(m=!1,f=a*i*d),s>0&&(m=!1,p=c*s*d);let h=this.newGestureEvent(DY.Change);h.translationX=f,h.translationY=p,n.forEach(e=>e.dispatchEvent(h)),m||this.inertia(t,n,u,i,a,o+f,s,c,l+p)})}onTouchMove(e){let t=Date.now();for(let n=0,r=e.changedTouches.length;n<r;n++){let r=e.changedTouches.item(n);if(!this.activeTouches.hasOwnProperty(String(r.identifier))){console.warn(`end of an UNKNOWN touch`,r);continue}let i=this.activeTouches[r.identifier],a=this.newGestureEvent(DY.Change,i.initialTarget);a.translationX=r.pageX-oq(i.rollingPageX),a.translationY=r.pageY-oq(i.rollingPageY),a.pageX=r.pageX,a.pageY=r.pageY,this.dispatchEvent(a),i.rollingPageX.length>3&&(i.rollingPageX.shift(),i.rollingPageY.shift(),i.rollingTimestamps.shift()),i.rollingPageX.push(r.pageX),i.rollingPageY.push(r.pageY),i.rollingTimestamps.push(t)}this.dispatched&&=(e.preventDefault(),e.stopPropagation(),!1)}};OY.SCROLL_FRICTION=-.005,OY.HOLD_DELAY=700,OY.CLEAR_TAP_COUNT_TIME=400,iK([EY],OY,`isTouchDevice`,1);var kY=OY,AY=class extends xq{onclick(e,t){this._register(fY(e,xY.CLICK,n=>t(new RJ(tY(e),n))))}onmousedown(e,t){this._register(fY(e,xY.MOUSE_DOWN,n=>t(new RJ(tY(e),n))))}onmouseover(e,t){this._register(fY(e,xY.MOUSE_OVER,n=>t(new RJ(tY(e),n))))}onmouseleave(e,t){this._register(fY(e,xY.MOUSE_LEAVE,n=>t(new RJ(tY(e),n))))}onkeydown(e,t){this._register(fY(e,xY.KEY_DOWN,e=>t(new PJ(e))))}onkeyup(e,t){this._register(fY(e,xY.KEY_UP,e=>t(new PJ(e))))}oninput(e,t){this._register(fY(e,xY.INPUT,t))}onblur(e,t){this._register(fY(e,xY.BLUR,t))}onfocus(e,t){this._register(fY(e,xY.FOCUS,t))}onchange(e,t){this._register(fY(e,xY.CHANGE,t))}ignoreGesture(e){return kY.ignoreTarget(e)}},jY=11,MY=class extends AY{constructor(e){super(),this._onActivate=e.onActivate,this.bgDomNode=document.createElement(`div`),this.bgDomNode.className=`arrow-background`,this.bgDomNode.style.position=`absolute`,this.bgDomNode.style.width=e.bgWidth+`px`,this.bgDomNode.style.height=e.bgHeight+`px`,typeof e.top<`u`&&(this.bgDomNode.style.top=`0px`),typeof e.left<`u`&&(this.bgDomNode.style.left=`0px`),typeof e.bottom<`u`&&(this.bgDomNode.style.bottom=`0px`),typeof e.right<`u`&&(this.bgDomNode.style.right=`0px`),this.domNode=document.createElement(`div`),this.domNode.className=e.className,this.domNode.style.position=`absolute`,this.domNode.style.width=jY+`px`,this.domNode.style.height=jY+`px`,typeof e.top<`u`&&(this.domNode.style.top=e.top+`px`),typeof e.left<`u`&&(this.domNode.style.left=e.left+`px`),typeof e.bottom<`u`&&(this.domNode.style.bottom=e.bottom+`px`),typeof e.right<`u`&&(this.domNode.style.right=e.right+`px`),this._pointerMoveMonitor=this._register(new TY),this._register(hY(this.bgDomNode,xY.POINTER_DOWN,e=>this._arrowPointerDown(e))),this._register(hY(this.domNode,xY.POINTER_DOWN,e=>this._arrowPointerDown(e))),this._pointerdownRepeatTimer=this._register(new _Y),this._pointerdownScheduleRepeatTimer=this._register(new UJ)}_arrowPointerDown(e){e.target&&e.target instanceof Element&&(this._onActivate(),this._pointerdownRepeatTimer.cancel(),this._pointerdownScheduleRepeatTimer.cancelAndSet(()=>{this._pointerdownRepeatTimer.cancelAndSet(()=>this._onActivate(),1e3/24,tY(e))},200),this._pointerMoveMonitor.startMonitoring(e.target,e.pointerId,e.buttons,e=>{},()=>{this._pointerdownRepeatTimer.cancel(),this._pointerdownScheduleRepeatTimer.cancel()}),e.preventDefault())}},NY=class e{constructor(e,t,n,r,i,a,o){this._forceIntegerValues=e,this._scrollStateBrand=void 0,this._forceIntegerValues&&(t|=0,n|=0,r|=0,i|=0,a|=0,o|=0),this.rawScrollLeft=r,this.rawScrollTop=o,t<0&&(t=0),r+t>n&&(r=n-t),r<0&&(r=0),i<0&&(i=0),o+i>a&&(o=a-i),o<0&&(o=0),this.width=t,this.scrollWidth=n,this.scrollLeft=r,this.height=i,this.scrollHeight=a,this.scrollTop=o}equals(e){return this.rawScrollLeft===e.rawScrollLeft&&this.rawScrollTop===e.rawScrollTop&&this.width===e.width&&this.scrollWidth===e.scrollWidth&&this.scrollLeft===e.scrollLeft&&this.height===e.height&&this.scrollHeight===e.scrollHeight&&this.scrollTop===e.scrollTop}withScrollDimensions(t,n){return new e(this._forceIntegerValues,typeof t.width<`u`?t.width:this.width,typeof t.scrollWidth<`u`?t.scrollWidth:this.scrollWidth,n?this.rawScrollLeft:this.scrollLeft,typeof t.height<`u`?t.height:this.height,typeof t.scrollHeight<`u`?t.scrollHeight:this.scrollHeight,n?this.rawScrollTop:this.scrollTop)}withScrollPosition(t){return new e(this._forceIntegerValues,this.width,this.scrollWidth,typeof t.scrollLeft<`u`?t.scrollLeft:this.rawScrollLeft,this.height,this.scrollHeight,typeof t.scrollTop<`u`?t.scrollTop:this.rawScrollTop)}createScrollEvent(e,t){let n=this.width!==e.width,r=this.scrollWidth!==e.scrollWidth,i=this.scrollLeft!==e.scrollLeft,a=this.height!==e.height,o=this.scrollHeight!==e.scrollHeight,s=this.scrollTop!==e.scrollTop;return{inSmoothScrolling:t,oldWidth:e.width,oldScrollWidth:e.scrollWidth,oldScrollLeft:e.scrollLeft,width:this.width,scrollWidth:this.scrollWidth,scrollLeft:this.scrollLeft,oldHeight:e.height,oldScrollHeight:e.scrollHeight,oldScrollTop:e.scrollTop,height:this.height,scrollHeight:this.scrollHeight,scrollTop:this.scrollTop,widthChanged:n,scrollWidthChanged:r,scrollLeftChanged:i,heightChanged:a,scrollHeightChanged:o,scrollTopChanged:s}}},PY=class extends xq{constructor(e){super(),this._scrollableBrand=void 0,this._onScroll=this._register(new Vq),this.onScroll=this._onScroll.event,this._smoothScrollDuration=e.smoothScrollDuration,this._scheduleAtNextAnimationFrame=e.scheduleAtNextAnimationFrame,this._state=new NY(e.forceIntegerValues,0,0,0,0,0,0),this._smoothScrolling=null}dispose(){this._smoothScrolling&&=(this._smoothScrolling.dispose(),null),super.dispose()}setSmoothScrollDuration(e){this._smoothScrollDuration=e}validateScrollPosition(e){return this._state.withScrollPosition(e)}getScrollDimensions(){return this._state}setScrollDimensions(e,t){let n=this._state.withScrollDimensions(e,t);this._setState(n,!!this._smoothScrolling),this._smoothScrolling?.acceptScrollDimensions(this._state)}getFutureScrollPosition(){return this._smoothScrolling?this._smoothScrolling.to:this._state}getCurrentScrollPosition(){return this._state}setScrollPositionNow(e){let t=this._state.withScrollPosition(e);this._smoothScrolling&&=(this._smoothScrolling.dispose(),null),this._setState(t,!1)}setScrollPositionSmooth(e,t){if(this._smoothScrollDuration===0)return this.setScrollPositionNow(e);if(this._smoothScrolling){e={scrollLeft:typeof e.scrollLeft>`u`?this._smoothScrolling.to.scrollLeft:e.scrollLeft,scrollTop:typeof e.scrollTop>`u`?this._smoothScrolling.to.scrollTop:e.scrollTop};let n=this._state.withScrollPosition(e);if(this._smoothScrolling.to.scrollLeft===n.scrollLeft&&this._smoothScrolling.to.scrollTop===n.scrollTop)return;let r;r=t?new RY(this._smoothScrolling.from,n,this._smoothScrolling.startTime,this._smoothScrolling.duration):this._smoothScrolling.combine(this._state,n,this._smoothScrollDuration),this._smoothScrolling.dispose(),this._smoothScrolling=r}else{let t=this._state.withScrollPosition(e);this._smoothScrolling=RY.start(this._state,t,this._smoothScrollDuration)}this._smoothScrolling.animationFrameDisposable=this._scheduleAtNextAnimationFrame(()=>{this._smoothScrolling&&(this._smoothScrolling.animationFrameDisposable=null,this._performSmoothScrolling())})}hasPendingScrollAnimation(){return!!this._smoothScrolling}_performSmoothScrolling(){if(!this._smoothScrolling)return;let e=this._smoothScrolling.tick(),t=this._state.withScrollPosition(e);if(this._setState(t,!0),this._smoothScrolling){if(e.isDone){this._smoothScrolling.dispose(),this._smoothScrolling=null;return}this._smoothScrolling.animationFrameDisposable=this._scheduleAtNextAnimationFrame(()=>{this._smoothScrolling&&(this._smoothScrolling.animationFrameDisposable=null,this._performSmoothScrolling())})}}_setState(e,t){let n=this._state;n.equals(e)||(this._state=e,this._onScroll.fire(this._state.createScrollEvent(n,t)))}},FY=class{constructor(e,t,n){this.scrollLeft=e,this.scrollTop=t,this.isDone=n}};function IY(e,t){let n=t-e;return function(t){return e+n*BY(t)}}function LY(e,t,n){return function(r){return r<n?e(r/n):t((r-n)/(1-n))}}var RY=class e{constructor(e,t,n,r){this.from=e,this.to=t,this.duration=r,this.startTime=n,this.animationFrameDisposable=null,this._initAnimations()}_initAnimations(){this.scrollLeft=this._initAnimation(this.from.scrollLeft,this.to.scrollLeft,this.to.width),this.scrollTop=this._initAnimation(this.from.scrollTop,this.to.scrollTop,this.to.height)}_initAnimation(e,t,n){if(Math.abs(e-t)>2.5*n){let r,i;return e<t?(r=e+.75*n,i=t-.75*n):(r=e-.75*n,i=t+.75*n),LY(IY(e,r),IY(i,t),.33)}return IY(e,t)}dispose(){this.animationFrameDisposable!==null&&(this.animationFrameDisposable.dispose(),this.animationFrameDisposable=null)}acceptScrollDimensions(e){this.to=e.withScrollPosition(this.to),this._initAnimations()}tick(){return this._tick(Date.now())}_tick(e){let t=(e-this.startTime)/this.duration;return t<1?new FY(this.scrollLeft(t),this.scrollTop(t),!1):new FY(this.to.scrollLeft,this.to.scrollTop,!0)}combine(t,n,r){return e.start(t,n,r)}static start(t,n,r){r+=10;let i=Date.now()-10;return new e(t,n,i,r)}};function zY(e){return e**3}function BY(e){return 1-zY(1-e)}var VY=class extends xq{constructor(e,t,n){super(),this._visibility=e,this._visibleClassName=t,this._invisibleClassName=n,this._domNode=null,this._isVisible=!1,this._isNeeded=!1,this._rawShouldBeVisible=!1,this._shouldBeVisible=!1,this._revealTimer=this._register(new UJ)}setVisibility(e){this._visibility!==e&&(this._visibility=e,this._updateShouldBeVisible())}setShouldBeVisible(e){this._rawShouldBeVisible=e,this._updateShouldBeVisible()}_applyVisibilitySetting(){return this._visibility===2?!1:this._visibility===3||this._rawShouldBeVisible}_updateShouldBeVisible(){let e=this._applyVisibilitySetting();this._shouldBeVisible!==e&&(this._shouldBeVisible=e,this.ensureVisibility())}setIsNeeded(e){this._isNeeded!==e&&(this._isNeeded=e,this.ensureVisibility())}setDomNode(e){this._domNode=e,this._domNode.setClassName(this._invisibleClassName),this.setShouldBeVisible(!1)}ensureVisibility(){this._isNeeded?this._shouldBeVisible?this._reveal():this._hide(!0):this._hide(!1)}_reveal(){this._isVisible||(this._isVisible=!0,this._revealTimer.setIfNotSet(()=>{this._domNode?.setClassName(this._visibleClassName)},0))}_hide(e){this._revealTimer.cancel(),this._isVisible&&(this._isVisible=!1,this._domNode?.setClassName(this._invisibleClassName+(e?` fade`:``)))}},HY=140,UY=class extends AY{constructor(e){super(),this._lazyRender=e.lazyRender,this._host=e.host,this._scrollable=e.scrollable,this._scrollByPage=e.scrollByPage,this._scrollbarState=e.scrollbarState,this._visibilityController=this._register(new VY(e.visibility,`visible scrollbar `+e.extraScrollbarClassName,`invisible scrollbar `+e.extraScrollbarClassName)),this._visibilityController.setIsNeeded(this._scrollbarState.isNeeded()),this._pointerMoveMonitor=this._register(new TY),this._shouldRender=!0,this.domNode=wY(document.createElement(`div`)),this.domNode.setAttribute(`role`,`presentation`),this.domNode.setAttribute(`aria-hidden`,`true`),this._visibilityController.setDomNode(this.domNode),this.domNode.setPosition(`absolute`),this._register(fY(this.domNode.domNode,xY.POINTER_DOWN,e=>this._domNodePointerDown(e)))}_createArrow(e){let t=this._register(new MY(e));this.domNode.domNode.appendChild(t.bgDomNode),this.domNode.domNode.appendChild(t.domNode)}_createSlider(e,t,n,r){this.slider=wY(document.createElement(`div`)),this.slider.setClassName(`slider`),this.slider.setPosition(`absolute`),this.slider.setTop(e),this.slider.setLeft(t),typeof n==`number`&&this.slider.setWidth(n),typeof r==`number`&&this.slider.setHeight(r),this.slider.setLayerHinting(!0),this.slider.setContain(`strict`),this.domNode.domNode.appendChild(this.slider.domNode),this._register(fY(this.slider.domNode,xY.POINTER_DOWN,e=>{e.button===0&&(e.preventDefault(),this._sliderPointerDown(e))})),this.onclick(this.slider.domNode,e=>{e.leftButton&&e.stopPropagation()})}_onElementSize(e){return this._scrollbarState.setVisibleSize(e)&&(this._visibilityController.setIsNeeded(this._scrollbarState.isNeeded()),this._shouldRender=!0,this._lazyRender||this.render()),this._shouldRender}_onElementScrollSize(e){return this._scrollbarState.setScrollSize(e)&&(this._visibilityController.setIsNeeded(this._scrollbarState.isNeeded()),this._shouldRender=!0,this._lazyRender||this.render()),this._shouldRender}_onElementScrollPosition(e){return this._scrollbarState.setScrollPosition(e)&&(this._visibilityController.setIsNeeded(this._scrollbarState.isNeeded()),this._shouldRender=!0,this._lazyRender||this.render()),this._shouldRender}beginReveal(){this._visibilityController.setShouldBeVisible(!0)}beginHide(){this._visibilityController.setShouldBeVisible(!1)}render(){this._shouldRender&&(this._shouldRender=!1,this._renderDomNode(this._scrollbarState.getRectangleLargeSize(),this._scrollbarState.getRectangleSmallSize()),this._updateSlider(this._scrollbarState.getSliderSize(),this._scrollbarState.getArrowSize()+this._scrollbarState.getSliderPosition()))}_domNodePointerDown(e){e.target===this.domNode.domNode&&this._onPointerDown(e)}delegatePointerDown(e){let t=this.domNode.domNode.getClientRects()[0].top,n=t+this._scrollbarState.getSliderPosition(),r=t+this._scrollbarState.getSliderPosition()+this._scrollbarState.getSliderSize(),i=this._sliderPointerPosition(e);n<=i&&i<=r?e.button===0&&(e.preventDefault(),this._sliderPointerDown(e)):this._onPointerDown(e)}_onPointerDown(e){let t,n;if(e.target===this.domNode.domNode&&typeof e.offsetX==`number`&&typeof e.offsetY==`number`)t=e.offsetX,n=e.offsetY;else{let r=bY(this.domNode.domNode);t=e.pageX-r.left,n=e.pageY-r.top}let r=this._pointerDownRelativePosition(t,n);this._setDesiredScrollPositionNow(this._scrollByPage?this._scrollbarState.getDesiredScrollPositionFromOffsetPaged(r):this._scrollbarState.getDesiredScrollPositionFromOffset(r)),e.button===0&&(e.preventDefault(),this._sliderPointerDown(e))}_sliderPointerDown(e){if(!e.target||!(e.target instanceof Element))return;let t=this._sliderPointerPosition(e),n=this._sliderOrthogonalPointerPosition(e),r=this._scrollbarState.clone();this.slider.toggleClassName(`active`,!0),this._pointerMoveMonitor.startMonitoring(e.target,e.pointerId,e.buttons,e=>{let i=this._sliderOrthogonalPointerPosition(e),a=Math.abs(i-n);if(dJ&&a>HY){this._setDesiredScrollPositionNow(r.getScrollPosition());return}let o=this._sliderPointerPosition(e)-t;this._setDesiredScrollPositionNow(r.getDesiredScrollPositionFromDelta(o))},()=>{this.slider.toggleClassName(`active`,!1),this._host.onDragEnd()}),this._host.onDragStart()}_setDesiredScrollPositionNow(e){let t={};this.writeScrollPosition(t,e),this._scrollable.setScrollPositionNow(t)}updateScrollbarSize(e){this._updateScrollbarSize(e),this._scrollbarState.setScrollbarSize(e),this._shouldRender=!0,this._lazyRender||this.render()}isNeeded(){return this._scrollbarState.isNeeded()}},WY=class e{constructor(e,t,n,r,i,a){this._scrollbarSize=Math.round(t),this._oppositeScrollbarSize=Math.round(n),this._arrowSize=Math.round(e),this._visibleSize=r,this._scrollSize=i,this._scrollPosition=a,this._computedAvailableSize=0,this._computedIsNeeded=!1,this._computedSliderSize=0,this._computedSliderRatio=0,this._computedSliderPosition=0,this._refreshComputedValues()}clone(){return new e(this._arrowSize,this._scrollbarSize,this._oppositeScrollbarSize,this._visibleSize,this._scrollSize,this._scrollPosition)}setVisibleSize(e){let t=Math.round(e);return this._visibleSize!==t&&(this._visibleSize=t,this._refreshComputedValues(),!0)}setScrollSize(e){let t=Math.round(e);return this._scrollSize!==t&&(this._scrollSize=t,this._refreshComputedValues(),!0)}setScrollPosition(e){let t=Math.round(e);return this._scrollPosition!==t&&(this._scrollPosition=t,this._refreshComputedValues(),!0)}setScrollbarSize(e){this._scrollbarSize=Math.round(e)}setOppositeScrollbarSize(e){this._oppositeScrollbarSize=Math.round(e)}static _computeValues(e,t,n,r,i){let a=Math.max(0,n-e),o=Math.max(0,a-2*t),s=r>0&&r>n;if(!s)return{computedAvailableSize:Math.round(a),computedIsNeeded:s,computedSliderSize:Math.round(o),computedSliderRatio:0,computedSliderPosition:0};let c=Math.round(Math.max(20,Math.floor(n*o/r))),l=(o-c)/(r-n),u=i*l;return{computedAvailableSize:Math.round(a),computedIsNeeded:s,computedSliderSize:Math.round(c),computedSliderRatio:l,computedSliderPosition:Math.round(u)}}_refreshComputedValues(){let t=e._computeValues(this._oppositeScrollbarSize,this._arrowSize,this._visibleSize,this._scrollSize,this._scrollPosition);this._computedAvailableSize=t.computedAvailableSize,this._computedIsNeeded=t.computedIsNeeded,this._computedSliderSize=t.computedSliderSize,this._computedSliderRatio=t.computedSliderRatio,this._computedSliderPosition=t.computedSliderPosition}getArrowSize(){return this._arrowSize}getScrollPosition(){return this._scrollPosition}getRectangleLargeSize(){return this._computedAvailableSize}getRectangleSmallSize(){return this._scrollbarSize}isNeeded(){return this._computedIsNeeded}getSliderSize(){return this._computedSliderSize}getSliderPosition(){return this._computedSliderPosition}getDesiredScrollPositionFromOffset(e){if(!this._computedIsNeeded)return 0;let t=e-this._arrowSize-this._computedSliderSize/2;return Math.round(t/this._computedSliderRatio)}getDesiredScrollPositionFromOffsetPaged(e){if(!this._computedIsNeeded)return 0;let t=e-this._arrowSize,n=this._scrollPosition;return t<this._computedSliderPosition?n-=this._visibleSize:n+=this._visibleSize,n}getDesiredScrollPositionFromDelta(e){if(!this._computedIsNeeded)return 0;let t=this._computedSliderPosition+e;return Math.round(t/this._computedSliderRatio)}},GY=class extends UY{constructor(e,t,n){let r=e.getScrollDimensions(),i=e.getCurrentScrollPosition();if(super({lazyRender:t.lazyRender,host:n,scrollbarState:new WY(t.horizontalHasArrows?t.arrowSize:0,t.horizontal===2?0:t.horizontalScrollbarSize,t.vertical===2?0:t.verticalScrollbarSize,r.width,r.scrollWidth,i.scrollLeft),visibility:t.horizontal,extraScrollbarClassName:`horizontal`,scrollable:e,scrollByPage:t.scrollByPage}),t.horizontalHasArrows)throw Error(`horizontalHasArrows is not supported in xterm.js`);this._createSlider(Math.floor((t.horizontalScrollbarSize-t.horizontalSliderSize)/2),0,void 0,t.horizontalSliderSize)}_updateSlider(e,t){this.slider.setWidth(e),this.slider.setLeft(t)}_renderDomNode(e,t){this.domNode.setWidth(e),this.domNode.setHeight(t),this.domNode.setLeft(0),this.domNode.setBottom(0)}onDidScroll(e){return this._shouldRender=this._onElementScrollSize(e.scrollWidth)||this._shouldRender,this._shouldRender=this._onElementScrollPosition(e.scrollLeft)||this._shouldRender,this._shouldRender=this._onElementSize(e.width)||this._shouldRender,this._shouldRender}_pointerDownRelativePosition(e,t){return e}_sliderPointerPosition(e){return e.pageX}_sliderOrthogonalPointerPosition(e){return e.pageY}_updateScrollbarSize(e){this.slider.setHeight(e)}writeScrollPosition(e,t){e.scrollLeft=t}updateOptions(e){this.updateScrollbarSize(e.horizontal===2?0:e.horizontalScrollbarSize),this._scrollbarState.setOppositeScrollbarSize(e.vertical===2?0:e.verticalScrollbarSize),this._visibilityController.setVisibility(e.horizontal),this._scrollByPage=e.scrollByPage}},KY=class extends UY{constructor(e,t,n){let r=e.getScrollDimensions(),i=e.getCurrentScrollPosition();if(super({lazyRender:t.lazyRender,host:n,scrollbarState:new WY(t.verticalHasArrows?t.arrowSize:0,t.vertical===2?0:t.verticalScrollbarSize,0,r.height,r.scrollHeight,i.scrollTop),visibility:t.vertical,extraScrollbarClassName:`vertical`,scrollable:e,scrollByPage:t.scrollByPage}),t.verticalHasArrows)throw Error(`horizontalHasArrows is not supported in xterm.js`);this._createSlider(0,Math.floor((t.verticalScrollbarSize-t.verticalSliderSize)/2),t.verticalSliderSize,void 0)}_updateSlider(e,t){this.slider.setHeight(e),this.slider.setTop(t)}_renderDomNode(e,t){this.domNode.setWidth(t),this.domNode.setHeight(e),this.domNode.setRight(0),this.domNode.setTop(0)}onDidScroll(e){return this._shouldRender=this._onElementScrollSize(e.scrollHeight)||this._shouldRender,this._shouldRender=this._onElementScrollPosition(e.scrollTop)||this._shouldRender,this._shouldRender=this._onElementSize(e.height)||this._shouldRender,this._shouldRender}_pointerDownRelativePosition(e,t){return t}_sliderPointerPosition(e){return e.pageY}_sliderOrthogonalPointerPosition(e){return e.pageX}_updateScrollbarSize(e){this.slider.setWidth(e)}writeScrollPosition(e,t){e.scrollTop=t}updateOptions(e){this.updateScrollbarSize(e.vertical===2?0:e.verticalScrollbarSize),this._scrollbarState.setOppositeScrollbarSize(0),this._visibilityController.setVisibility(e.vertical),this._scrollByPage=e.scrollByPage}},qY=500,JY=50,YY=!0,XY=class{constructor(e,t,n){this.timestamp=e,this.deltaX=t,this.deltaY=n,this.score=0}},ZY=class{constructor(){this._capacity=5,this._memory=[],this._front=-1,this._rear=-1}isPhysicalMouseWheel(){if(this._front===-1&&this._rear===-1)return!1;let e=1,t=0,n=1,r=this._rear;do{let i=r===this._front?e:2**-n;if(e-=i,t+=this._memory[r].score*i,r===this._front)break;r=(this._capacity+r-1)%this._capacity,n++}while(1);return t<=.5}acceptStandardWheelEvent(e){if(Xq){let t=Kq(tY(e.browserEvent));this.accept(Date.now(),e.deltaX*t,e.deltaY*t)}else this.accept(Date.now(),e.deltaX,e.deltaY)}accept(e,t,n){let r=null,i=new XY(e,t,n);this._front===-1&&this._rear===-1?(this._memory[0]=i,this._front=0,this._rear=0):(r=this._memory[this._rear],this._rear=(this._rear+1)%this._capacity,this._rear===this._front&&(this._front=(this._front+1)%this._capacity),this._memory[this._rear]=i),i.score=this._computeScore(i,r)}_computeScore(e,t){if(Math.abs(e.deltaX)>0&&Math.abs(e.deltaY)>0)return 1;let n=.5;if((!this._isAlmostInt(e.deltaX)||!this._isAlmostInt(e.deltaY))&&(n+=.25),t){let r=Math.abs(e.deltaX),i=Math.abs(e.deltaY),a=Math.abs(t.deltaX),o=Math.abs(t.deltaY),s=Math.max(Math.min(r,a),1),c=Math.max(Math.min(i,o),1),l=Math.max(r,a),u=Math.max(i,o);l%s===0&&u%c===0&&(n-=.5)}return Math.min(Math.max(n,0),1)}_isAlmostInt(e){return Math.abs(Math.round(e)-e)<.01}};ZY.INSTANCE=new ZY;var QY=ZY,$Y=class extends AY{constructor(e,t,n){super(),this._onScroll=this._register(new Vq),this.onScroll=this._onScroll.event,this._onWillScroll=this._register(new Vq),this.onWillScroll=this._onWillScroll.event,this._options=tX(t),this._scrollable=n,this._register(this._scrollable.onScroll(e=>{this._onWillScroll.fire(e),this._onDidScroll(e),this._onScroll.fire(e)}));let r={onMouseWheel:e=>this._onMouseWheel(e),onDragStart:()=>this._onDragStart(),onDragEnd:()=>this._onDragEnd()};this._verticalScrollbar=this._register(new KY(this._scrollable,this._options,r)),this._horizontalScrollbar=this._register(new GY(this._scrollable,this._options,r)),this._domNode=document.createElement(`div`),this._domNode.className=`xterm-scrollable-element `+this._options.className,this._domNode.setAttribute(`role`,`presentation`),this._domNode.style.position=`relative`,this._domNode.appendChild(e),this._domNode.appendChild(this._horizontalScrollbar.domNode.domNode),this._domNode.appendChild(this._verticalScrollbar.domNode.domNode),this._options.useShadows?(this._leftShadowDomNode=wY(document.createElement(`div`)),this._leftShadowDomNode.setClassName(`shadow`),this._domNode.appendChild(this._leftShadowDomNode.domNode),this._topShadowDomNode=wY(document.createElement(`div`)),this._topShadowDomNode.setClassName(`shadow`),this._domNode.appendChild(this._topShadowDomNode.domNode),this._topLeftShadowDomNode=wY(document.createElement(`div`)),this._topLeftShadowDomNode.setClassName(`shadow`),this._domNode.appendChild(this._topLeftShadowDomNode.domNode)):(this._leftShadowDomNode=null,this._topShadowDomNode=null,this._topLeftShadowDomNode=null),this._listenOnDomNode=this._options.listenOnDomNode||this._domNode,this._mouseWheelToDispose=[],this._setListeningToMouseWheel(this._options.handleMouseWheel),this.onmouseover(this._listenOnDomNode,e=>this._onMouseOver(e)),this.onmouseleave(this._listenOnDomNode,e=>this._onMouseLeave(e)),this._hideTimeout=this._register(new UJ),this._isDragging=!1,this._mouseIsOver=!1,this._shouldRender=!0,this._revealOnScroll=!0}get options(){return this._options}dispose(){this._mouseWheelToDispose=gq(this._mouseWheelToDispose),super.dispose()}getDomNode(){return this._domNode}getOverviewRulerLayoutInfo(){return{parent:this._domNode,insertBefore:this._verticalScrollbar.domNode.domNode}}delegateVerticalScrollbarPointerDown(e){this._verticalScrollbar.delegatePointerDown(e)}getScrollDimensions(){return this._scrollable.getScrollDimensions()}setScrollDimensions(e){this._scrollable.setScrollDimensions(e,!1)}updateClassName(e){this._options.className=e,fJ&&(this._options.className+=` mac`),this._domNode.className=`xterm-scrollable-element `+this._options.className}updateOptions(e){typeof e.handleMouseWheel<`u`&&(this._options.handleMouseWheel=e.handleMouseWheel,this._setListeningToMouseWheel(this._options.handleMouseWheel)),typeof e.mouseWheelScrollSensitivity<`u`&&(this._options.mouseWheelScrollSensitivity=e.mouseWheelScrollSensitivity),typeof e.fastScrollSensitivity<`u`&&(this._options.fastScrollSensitivity=e.fastScrollSensitivity),typeof e.scrollPredominantAxis<`u`&&(this._options.scrollPredominantAxis=e.scrollPredominantAxis),typeof e.horizontal<`u`&&(this._options.horizontal=e.horizontal),typeof e.vertical<`u`&&(this._options.vertical=e.vertical),typeof e.horizontalScrollbarSize<`u`&&(this._options.horizontalScrollbarSize=e.horizontalScrollbarSize),typeof e.verticalScrollbarSize<`u`&&(this._options.verticalScrollbarSize=e.verticalScrollbarSize),typeof e.scrollByPage<`u`&&(this._options.scrollByPage=e.scrollByPage),this._horizontalScrollbar.updateOptions(this._options),this._verticalScrollbar.updateOptions(this._options),this._options.lazyRender||this._render()}setRevealOnScroll(e){this._revealOnScroll=e}delegateScrollFromMouseWheelEvent(e){this._onMouseWheel(new zJ(e))}_setListeningToMouseWheel(e){this._mouseWheelToDispose.length>0!==e&&(this._mouseWheelToDispose=gq(this._mouseWheelToDispose),e)&&this._mouseWheelToDispose.push(fY(this._listenOnDomNode,xY.MOUSE_WHEEL,e=>{this._onMouseWheel(new zJ(e))},{passive:!1}))}_onMouseWheel(e){if(e.browserEvent?.defaultPrevented)return;let t=QY.INSTANCE;YY&&t.acceptStandardWheelEvent(e);let n=!1;if(e.deltaY||e.deltaX){let r=e.deltaY*this._options.mouseWheelScrollSensitivity,i=e.deltaX*this._options.mouseWheelScrollSensitivity;this._options.scrollPredominantAxis&&(this._options.scrollYToX&&i+r===0?i=r=0:Math.abs(r)>=Math.abs(i)?i=0:r=0),this._options.flipAxes&&([r,i]=[i,r]);let a=!fJ&&e.browserEvent&&e.browserEvent.shiftKey;(this._options.scrollYToX||a)&&!i&&(i=r,r=0),e.browserEvent&&e.browserEvent.altKey&&(i*=this._options.fastScrollSensitivity,r*=this._options.fastScrollSensitivity);let o=this._scrollable.getFutureScrollPosition(),s={};if(r){let e=JY*r,t=o.scrollTop-(e<0?Math.floor(e):Math.ceil(e));this._verticalScrollbar.writeScrollPosition(s,t)}if(i){let e=JY*i,t=o.scrollLeft-(e<0?Math.floor(e):Math.ceil(e));this._horizontalScrollbar.writeScrollPosition(s,t)}s=this._scrollable.validateScrollPosition(s),(o.scrollLeft!==s.scrollLeft||o.scrollTop!==s.scrollTop)&&(YY&&this._options.mouseWheelSmoothScroll&&t.isPhysicalMouseWheel()?this._scrollable.setScrollPositionSmooth(s):this._scrollable.setScrollPositionNow(s),n=!0)}let r=n;!r&&this._options.alwaysConsumeMouseWheel&&(r=!0),!r&&this._options.consumeMouseWheelIfScrollbarIsNeeded&&(this._verticalScrollbar.isNeeded()||this._horizontalScrollbar.isNeeded())&&(r=!0),r&&(e.preventDefault(),e.stopPropagation())}_onDidScroll(e){this._shouldRender=this._horizontalScrollbar.onDidScroll(e)||this._shouldRender,this._shouldRender=this._verticalScrollbar.onDidScroll(e)||this._shouldRender,this._options.useShadows&&(this._shouldRender=!0),this._revealOnScroll&&this._reveal(),this._options.lazyRender||this._render()}renderNow(){if(!this._options.lazyRender)throw Error("Please use `lazyRender` together with `renderNow`!");this._render()}_render(){if(this._shouldRender&&(this._shouldRender=!1,this._horizontalScrollbar.render(),this._verticalScrollbar.render(),this._options.useShadows)){let e=this._scrollable.getCurrentScrollPosition(),t=e.scrollTop>0,n=e.scrollLeft>0,r=n?` left`:``,i=t?` top`:``,a=n||t?` top-left-corner`:``;this._leftShadowDomNode.setClassName(`shadow${r}`),this._topShadowDomNode.setClassName(`shadow${i}`),this._topLeftShadowDomNode.setClassName(`shadow${a}${i}${r}`)}}_onDragStart(){this._isDragging=!0,this._reveal()}_onDragEnd(){this._isDragging=!1,this._hide()}_onMouseLeave(e){this._mouseIsOver=!1,this._hide()}_onMouseOver(e){this._mouseIsOver=!0,this._reveal()}_reveal(){this._verticalScrollbar.beginReveal(),this._horizontalScrollbar.beginReveal(),this._scheduleHide()}_hide(){!this._mouseIsOver&&!this._isDragging&&(this._verticalScrollbar.beginHide(),this._horizontalScrollbar.beginHide())}_scheduleHide(){!this._mouseIsOver&&!this._isDragging&&this._hideTimeout.cancelAndSet(()=>this._hide(),qY)}},eX=class extends $Y{constructor(e,t,n){super(e,t,n)}setScrollPosition(e){e.reuseAnimation?this._scrollable.setScrollPositionSmooth(e,e.reuseAnimation):this._scrollable.setScrollPositionNow(e)}getScrollPosition(){return this._scrollable.getCurrentScrollPosition()}};function tX(e){let t={lazyRender:typeof e.lazyRender<`u`&&e.lazyRender,className:typeof e.className<`u`?e.className:``,useShadows:typeof e.useShadows<`u`?e.useShadows:!0,handleMouseWheel:typeof e.handleMouseWheel<`u`?e.handleMouseWheel:!0,flipAxes:typeof e.flipAxes<`u`&&e.flipAxes,consumeMouseWheelIfScrollbarIsNeeded:typeof e.consumeMouseWheelIfScrollbarIsNeeded<`u`&&e.consumeMouseWheelIfScrollbarIsNeeded,alwaysConsumeMouseWheel:typeof e.alwaysConsumeMouseWheel<`u`&&e.alwaysConsumeMouseWheel,scrollYToX:typeof e.scrollYToX<`u`&&e.scrollYToX,mouseWheelScrollSensitivity:typeof e.mouseWheelScrollSensitivity<`u`?e.mouseWheelScrollSensitivity:1,fastScrollSensitivity:typeof e.fastScrollSensitivity<`u`?e.fastScrollSensitivity:5,scrollPredominantAxis:typeof e.scrollPredominantAxis<`u`?e.scrollPredominantAxis:!0,mouseWheelSmoothScroll:typeof e.mouseWheelSmoothScroll<`u`?e.mouseWheelSmoothScroll:!0,arrowSize:typeof e.arrowSize<`u`?e.arrowSize:11,listenOnDomNode:typeof e.listenOnDomNode<`u`?e.listenOnDomNode:null,horizontal:typeof e.horizontal<`u`?e.horizontal:1,horizontalScrollbarSize:typeof e.horizontalScrollbarSize<`u`?e.horizontalScrollbarSize:10,horizontalSliderSize:typeof e.horizontalSliderSize<`u`?e.horizontalSliderSize:0,horizontalHasArrows:typeof e.horizontalHasArrows<`u`&&e.horizontalHasArrows,vertical:typeof e.vertical<`u`?e.vertical:1,verticalScrollbarSize:typeof e.verticalScrollbarSize<`u`?e.verticalScrollbarSize:10,verticalHasArrows:typeof e.verticalHasArrows<`u`&&e.verticalHasArrows,verticalSliderSize:typeof e.verticalSliderSize<`u`?e.verticalSliderSize:0,scrollByPage:typeof e.scrollByPage<`u`&&e.scrollByPage};return t.horizontalSliderSize=typeof e.horizontalSliderSize<`u`?e.horizontalSliderSize:t.horizontalScrollbarSize,t.verticalSliderSize=typeof e.verticalSliderSize<`u`?e.verticalSliderSize:t.verticalScrollbarSize,fJ&&(t.className+=` mac`),t}var nX=class extends xq{constructor(e,t,n,r,i,a,o,s){super(),this._bufferService=n,this._optionsService=o,this._renderService=s,this._onRequestScrollLines=this._register(new Vq),this.onRequestScrollLines=this._onRequestScrollLines.event,this._isSyncing=!1,this._isHandlingScroll=!1,this._suppressOnScrollHandler=!1;let c=this._register(new PY({forceIntegerValues:!1,smoothScrollDuration:this._optionsService.rawOptions.smoothScrollDuration,scheduleAtNextAnimationFrame:e=>gY(r.window,e)}));this._register(this._optionsService.onSpecificOptionChange(`smoothScrollDuration`,()=>{c.setSmoothScrollDuration(this._optionsService.rawOptions.smoothScrollDuration)})),this._scrollableElement=this._register(new eX(t,{vertical:1,horizontal:2,useShadows:!1,mouseWheelSmoothScroll:!0,...this._getChangeOptions()},c)),this._register(this._optionsService.onMultipleOptionChange([`scrollSensitivity`,`fastScrollSensitivity`,`overviewRuler`],()=>this._scrollableElement.updateOptions(this._getChangeOptions()))),this._register(i.onProtocolChange(e=>{this._scrollableElement.updateOptions({handleMouseWheel:!(e&16)})})),this._scrollableElement.setScrollDimensions({height:0,scrollHeight:0}),this._register(kq.runAndSubscribe(a.onChangeColors,()=>{this._scrollableElement.getDomNode().style.backgroundColor=a.colors.background.css})),e.appendChild(this._scrollableElement.getDomNode()),this._register(vq(()=>this._scrollableElement.getDomNode().remove())),this._styleElement=r.mainDocument.createElement(`style`),t.appendChild(this._styleElement),this._register(vq(()=>this._styleElement.remove())),this._register(kq.runAndSubscribe(a.onChangeColors,()=>{this._styleElement.textContent=[`.xterm .xterm-scrollable-element > .scrollbar > .slider {`,` background: ${a.colors.scrollbarSliderBackground.css};`,`}`,`.xterm .xterm-scrollable-element > .scrollbar > .slider:hover {`,` background: ${a.colors.scrollbarSliderHoverBackground.css};`,`}`,`.xterm .xterm-scrollable-element > .scrollbar > .slider.active {`,` background: ${a.colors.scrollbarSliderActiveBackground.css};`,`}`].join(`
1526
- `)})),this._register(this._bufferService.onResize(()=>this.queueSync())),this._register(this._bufferService.buffers.onBufferActivate(()=>{this._latestYDisp=void 0,this.queueSync()})),this._register(this._bufferService.onScroll(()=>this._sync())),this._register(this._scrollableElement.onScroll(e=>this._handleScroll(e)))}scrollLines(e){let t=this._scrollableElement.getScrollPosition();this._scrollableElement.setScrollPosition({reuseAnimation:!0,scrollTop:t.scrollTop+e*this._renderService.dimensions.css.cell.height})}scrollToLine(e,t){t&&(this._latestYDisp=e),this._scrollableElement.setScrollPosition({reuseAnimation:!t,scrollTop:e*this._renderService.dimensions.css.cell.height})}_getChangeOptions(){return{mouseWheelScrollSensitivity:this._optionsService.rawOptions.scrollSensitivity,fastScrollSensitivity:this._optionsService.rawOptions.fastScrollSensitivity,verticalScrollbarSize:this._optionsService.rawOptions.overviewRuler?.width||14}}queueSync(e){e!==void 0&&(this._latestYDisp=e),this._queuedAnimationFrame===void 0&&(this._queuedAnimationFrame=this._renderService.addRefreshCallback(()=>{this._queuedAnimationFrame=void 0,this._sync(this._latestYDisp)}))}_sync(e=this._bufferService.buffer.ydisp){!this._renderService||this._isSyncing||(this._isSyncing=!0,this._suppressOnScrollHandler=!0,this._scrollableElement.setScrollDimensions({height:this._renderService.dimensions.css.canvas.height,scrollHeight:this._renderService.dimensions.css.cell.height*this._bufferService.buffer.lines.length}),this._suppressOnScrollHandler=!1,e!==this._latestYDisp&&this._scrollableElement.setScrollPosition({scrollTop:e*this._renderService.dimensions.css.cell.height}),this._isSyncing=!1)}_handleScroll(e){if(!this._renderService||this._isHandlingScroll||this._suppressOnScrollHandler)return;this._isHandlingScroll=!0;let t=Math.round(e.scrollTop/this._renderService.dimensions.css.cell.height),n=t-this._bufferService.buffer.ydisp;n!==0&&(this._latestYDisp=t,this._onRequestScrollLines.fire(n)),this._isHandlingScroll=!1}};nX=iK([aK(2,MK),aK(3,GK),aK(4,NK),aK(5,XK),aK(6,RK),aK(7,qK)],nX);var rX=class extends xq{constructor(e,t,n,r,i){super(),this._screenElement=e,this._bufferService=t,this._coreBrowserService=n,this._decorationService=r,this._renderService=i,this._decorationElements=new Map,this._altBufferIsActive=!1,this._dimensionsChanged=!1,this._container=document.createElement(`div`),this._container.classList.add(`xterm-decoration-container`),this._screenElement.appendChild(this._container),this._register(this._renderService.onRenderedViewportChange(()=>this._doRefreshDecorations())),this._register(this._renderService.onDimensionsChange(()=>{this._dimensionsChanged=!0,this._queueRefresh()})),this._register(this._coreBrowserService.onDprChange(()=>this._queueRefresh())),this._register(this._bufferService.buffers.onBufferActivate(()=>{this._altBufferIsActive=this._bufferService.buffer===this._bufferService.buffers.alt})),this._register(this._decorationService.onDecorationRegistered(()=>this._queueRefresh())),this._register(this._decorationService.onDecorationRemoved(e=>this._removeDecoration(e))),this._register(vq(()=>{this._container.remove(),this._decorationElements.clear()}))}_queueRefresh(){this._animationFrame===void 0&&(this._animationFrame=this._renderService.addRefreshCallback(()=>{this._doRefreshDecorations(),this._animationFrame=void 0}))}_doRefreshDecorations(){for(let e of this._decorationService.decorations)this._renderDecoration(e);this._dimensionsChanged=!1}_renderDecoration(e){this._refreshStyle(e),this._dimensionsChanged&&this._refreshXPosition(e)}_createElement(e){let t=this._coreBrowserService.mainDocument.createElement(`div`);t.classList.add(`xterm-decoration`),t.classList.toggle(`xterm-decoration-top-layer`,e?.options?.layer===`top`),t.style.width=`${Math.round((e.options.width||1)*this._renderService.dimensions.css.cell.width)}px`,t.style.height=`${(e.options.height||1)*this._renderService.dimensions.css.cell.height}px`,t.style.top=`${(e.marker.line-this._bufferService.buffers.active.ydisp)*this._renderService.dimensions.css.cell.height}px`,t.style.lineHeight=`${this._renderService.dimensions.css.cell.height}px`;let n=e.options.x??0;return n&&n>this._bufferService.cols&&(t.style.display=`none`),this._refreshXPosition(e,t),t}_refreshStyle(e){let t=e.marker.line-this._bufferService.buffers.active.ydisp;if(t<0||t>=this._bufferService.rows)e.element&&(e.element.style.display=`none`,e.onRenderEmitter.fire(e.element));else{let n=this._decorationElements.get(e);n||(n=this._createElement(e),e.element=n,this._decorationElements.set(e,n),this._container.appendChild(n),e.onDispose(()=>{this._decorationElements.delete(e),n.remove()})),n.style.display=this._altBufferIsActive?`none`:`block`,this._altBufferIsActive||(n.style.width=`${Math.round((e.options.width||1)*this._renderService.dimensions.css.cell.width)}px`,n.style.height=`${(e.options.height||1)*this._renderService.dimensions.css.cell.height}px`,n.style.top=`${t*this._renderService.dimensions.css.cell.height}px`,n.style.lineHeight=`${this._renderService.dimensions.css.cell.height}px`),e.onRenderEmitter.fire(n)}}_refreshXPosition(e,t=e.element){if(!t)return;let n=e.options.x??0;(e.options.anchor||`left`)===`right`?t.style.right=n?`${n*this._renderService.dimensions.css.cell.width}px`:``:t.style.left=n?`${n*this._renderService.dimensions.css.cell.width}px`:``}_removeDecoration(e){this._decorationElements.get(e)?.remove(),this._decorationElements.delete(e),e.dispose()}};rX=iK([aK(1,MK),aK(2,GK),aK(3,VK),aK(4,qK)],rX);var iX=class{constructor(){this._zones=[],this._zonePool=[],this._zonePoolIndex=0,this._linePadding={full:0,left:0,center:0,right:0}}get zones(){return this._zonePool.length=Math.min(this._zonePool.length,this._zones.length),this._zones}clear(){this._zones.length=0,this._zonePoolIndex=0}addDecoration(e){if(e.options.overviewRulerOptions){for(let t of this._zones)if(t.color===e.options.overviewRulerOptions.color&&t.position===e.options.overviewRulerOptions.position){if(this._lineIntersectsZone(t,e.marker.line))return;if(this._lineAdjacentToZone(t,e.marker.line,e.options.overviewRulerOptions.position)){this._addLineToZone(t,e.marker.line);return}}if(this._zonePoolIndex<this._zonePool.length){this._zonePool[this._zonePoolIndex].color=e.options.overviewRulerOptions.color,this._zonePool[this._zonePoolIndex].position=e.options.overviewRulerOptions.position,this._zonePool[this._zonePoolIndex].startBufferLine=e.marker.line,this._zonePool[this._zonePoolIndex].endBufferLine=e.marker.line,this._zones.push(this._zonePool[this._zonePoolIndex++]);return}this._zones.push({color:e.options.overviewRulerOptions.color,position:e.options.overviewRulerOptions.position,startBufferLine:e.marker.line,endBufferLine:e.marker.line}),this._zonePool.push(this._zones[this._zones.length-1]),this._zonePoolIndex++}}setPadding(e){this._linePadding=e}_lineIntersectsZone(e,t){return t>=e.startBufferLine&&t<=e.endBufferLine}_lineAdjacentToZone(e,t,n){return t>=e.startBufferLine-this._linePadding[n||`full`]&&t<=e.endBufferLine+this._linePadding[n||`full`]}_addLineToZone(e,t){e.startBufferLine=Math.min(e.startBufferLine,t),e.endBufferLine=Math.max(e.endBufferLine,t)}},aX={full:0,left:0,center:0,right:0},oX={full:0,left:0,center:0,right:0},sX={full:0,left:0,center:0,right:0},cX=class extends xq{constructor(e,t,n,r,i,a,o,s){super(),this._viewportElement=e,this._screenElement=t,this._bufferService=n,this._decorationService=r,this._renderService=i,this._optionsService=a,this._themeService=o,this._coreBrowserService=s,this._colorZoneStore=new iX,this._shouldUpdateDimensions=!0,this._shouldUpdateAnchor=!0,this._lastKnownBufferLength=0,this._canvas=this._coreBrowserService.mainDocument.createElement(`canvas`),this._canvas.classList.add(`xterm-decoration-overview-ruler`),this._refreshCanvasDimensions(),this._viewportElement.parentElement?.insertBefore(this._canvas,this._viewportElement),this._register(vq(()=>this._canvas?.remove()));let c=this._canvas.getContext(`2d`);if(c)this._ctx=c;else throw Error(`Ctx cannot be null`);this._register(this._decorationService.onDecorationRegistered(()=>this._queueRefresh(void 0,!0))),this._register(this._decorationService.onDecorationRemoved(()=>this._queueRefresh(void 0,!0))),this._register(this._renderService.onRenderedViewportChange(()=>this._queueRefresh())),this._register(this._bufferService.buffers.onBufferActivate(()=>{this._canvas.style.display=this._bufferService.buffer===this._bufferService.buffers.alt?`none`:`block`})),this._register(this._bufferService.onScroll(()=>{this._lastKnownBufferLength!==this._bufferService.buffers.normal.lines.length&&(this._refreshDrawHeightConstants(),this._refreshColorZonePadding())})),this._register(this._renderService.onRender(()=>{(!this._containerHeight||this._containerHeight!==this._screenElement.clientHeight)&&(this._queueRefresh(!0),this._containerHeight=this._screenElement.clientHeight)})),this._register(this._coreBrowserService.onDprChange(()=>this._queueRefresh(!0))),this._register(this._optionsService.onSpecificOptionChange(`overviewRuler`,()=>this._queueRefresh(!0))),this._register(this._themeService.onChangeColors(()=>this._queueRefresh())),this._queueRefresh(!0)}get _width(){return this._optionsService.options.overviewRuler?.width||0}_refreshDrawConstants(){let e=Math.floor((this._canvas.width-1)/3),t=Math.ceil((this._canvas.width-1)/3);oX.full=this._canvas.width,oX.left=e,oX.center=t,oX.right=e,this._refreshDrawHeightConstants(),sX.full=1,sX.left=1,sX.center=1+oX.left,sX.right=1+oX.left+oX.center}_refreshDrawHeightConstants(){aX.full=Math.round(2*this._coreBrowserService.dpr);let e=this._canvas.height/this._bufferService.buffer.lines.length,t=Math.round(Math.max(Math.min(e,12),6)*this._coreBrowserService.dpr);aX.left=t,aX.center=t,aX.right=t}_refreshColorZonePadding(){this._colorZoneStore.setPadding({full:Math.floor(this._bufferService.buffers.active.lines.length/(this._canvas.height-1)*aX.full),left:Math.floor(this._bufferService.buffers.active.lines.length/(this._canvas.height-1)*aX.left),center:Math.floor(this._bufferService.buffers.active.lines.length/(this._canvas.height-1)*aX.center),right:Math.floor(this._bufferService.buffers.active.lines.length/(this._canvas.height-1)*aX.right)}),this._lastKnownBufferLength=this._bufferService.buffers.normal.lines.length}_refreshCanvasDimensions(){this._canvas.style.width=`${this._width}px`,this._canvas.width=Math.round(this._width*this._coreBrowserService.dpr),this._canvas.style.height=`${this._screenElement.clientHeight}px`,this._canvas.height=Math.round(this._screenElement.clientHeight*this._coreBrowserService.dpr),this._refreshDrawConstants(),this._refreshColorZonePadding()}_refreshDecorations(){this._shouldUpdateDimensions&&this._refreshCanvasDimensions(),this._ctx.clearRect(0,0,this._canvas.width,this._canvas.height),this._colorZoneStore.clear();for(let e of this._decorationService.decorations)this._colorZoneStore.addDecoration(e);this._ctx.lineWidth=1,this._renderRulerOutline();let e=this._colorZoneStore.zones;for(let t of e)t.position!==`full`&&this._renderColorZone(t);for(let t of e)t.position===`full`&&this._renderColorZone(t);this._shouldUpdateDimensions=!1,this._shouldUpdateAnchor=!1}_renderRulerOutline(){this._ctx.fillStyle=this._themeService.colors.overviewRulerBorder.css,this._ctx.fillRect(0,0,1,this._canvas.height),this._optionsService.rawOptions.overviewRuler.showTopBorder&&this._ctx.fillRect(1,0,this._canvas.width-1,1),this._optionsService.rawOptions.overviewRuler.showBottomBorder&&this._ctx.fillRect(1,this._canvas.height-1,this._canvas.width-1,this._canvas.height)}_renderColorZone(e){this._ctx.fillStyle=e.color,this._ctx.fillRect(sX[e.position||`full`],Math.round((this._canvas.height-1)*(e.startBufferLine/this._bufferService.buffers.active.lines.length)-aX[e.position||`full`]/2),oX[e.position||`full`],Math.round((this._canvas.height-1)*((e.endBufferLine-e.startBufferLine)/this._bufferService.buffers.active.lines.length)+aX[e.position||`full`]))}_queueRefresh(e,t){this._shouldUpdateDimensions=e||this._shouldUpdateDimensions,this._shouldUpdateAnchor=t||this._shouldUpdateAnchor,this._animationFrame===void 0&&(this._animationFrame=this._coreBrowserService.window.requestAnimationFrame(()=>{this._refreshDecorations(),this._animationFrame=void 0}))}};cX=iK([aK(2,MK),aK(3,VK),aK(4,qK),aK(5,RK),aK(6,XK),aK(7,GK)],cX);var $;(e=>(e.NUL=`\0`,e.SOH=``,e.STX=``,e.ETX=``,e.EOT=``,e.ENQ=``,e.ACK=``,e.BEL=`\x07`,e.BS=`\b`,e.HT=` `,e.LF=`
1527
- `,e.VT=`\v`,e.FF=`\f`,e.CR=`\r`,e.SO=``,e.SI=``,e.DLE=``,e.DC1=``,e.DC2=``,e.DC3=``,e.DC4=``,e.NAK=``,e.SYN=``,e.ETB=``,e.CAN=``,e.EM=``,e.SUB=``,e.ESC=`\x1B`,e.FS=``,e.GS=``,e.RS=``,e.US=``,e.SP=` `,e.DEL=``))($||={});var lX;(e=>(e.PAD=`€`,e.HOP=``,e.BPH=`‚`,e.NBH=`ƒ`,e.IND=`„`,e.NEL=`…`,e.SSA=`†`,e.ESA=`‡`,e.HTS=`ˆ`,e.HTJ=`‰`,e.VTS=`Š`,e.PLD=`‹`,e.PLU=`Œ`,e.RI=``,e.SS2=`Ž`,e.SS3=``,e.DCS=``,e.PU1=`‘`,e.PU2=`’`,e.STS=`“`,e.CCH=`”`,e.MW=`•`,e.SPA=`–`,e.EPA=`—`,e.SOS=`˜`,e.SGCI=`™`,e.SCI=`š`,e.CSI=`›`,e.ST=`œ`,e.OSC=``,e.PM=`ž`,e.APC=`Ÿ`))(lX||={});var uX;(e=>e.ST=`${$.ESC}\\`)(uX||={});var dX=class{constructor(e,t,n,r,i,a){this._textarea=e,this._compositionView=t,this._bufferService=n,this._optionsService=r,this._coreService=i,this._renderService=a,this._isComposing=!1,this._isSendingComposition=!1,this._compositionPosition={start:0,end:0},this._dataAlreadySent=``}get isComposing(){return this._isComposing}compositionstart(){this._isComposing=!0,this._compositionPosition.start=this._textarea.value.length,this._compositionView.textContent=``,this._dataAlreadySent=``,this._compositionView.classList.add(`active`)}compositionupdate(e){this._compositionView.textContent=e.data,this.updateCompositionElements(),setTimeout(()=>{this._compositionPosition.end=this._textarea.value.length},0)}compositionend(){this._finalizeComposition(!0)}keydown(e){if(this._isComposing||this._isSendingComposition){if(e.keyCode===20||e.keyCode===229||e.keyCode===16||e.keyCode===17||e.keyCode===18)return!1;this._finalizeComposition(!1)}return e.keyCode!==229||(this._handleAnyTextareaChanges(),!1)}_finalizeComposition(e){if(this._compositionView.classList.remove(`active`),this._isComposing=!1,e){let e={start:this._compositionPosition.start,end:this._compositionPosition.end};this._isSendingComposition=!0,setTimeout(()=>{if(this._isSendingComposition){this._isSendingComposition=!1;let t;e.start+=this._dataAlreadySent.length,t=this._isComposing?this._textarea.value.substring(e.start,this._compositionPosition.start):this._textarea.value.substring(e.start),t.length>0&&this._coreService.triggerDataEvent(t,!0)}},0)}else{this._isSendingComposition=!1;let e=this._textarea.value.substring(this._compositionPosition.start,this._compositionPosition.end);this._coreService.triggerDataEvent(e,!0)}}_handleAnyTextareaChanges(){let e=this._textarea.value;setTimeout(()=>{if(!this._isComposing){let t=this._textarea.value,n=t.replace(e,``);this._dataAlreadySent=n,t.length>e.length?this._coreService.triggerDataEvent(n,!0):t.length<e.length?this._coreService.triggerDataEvent(`${$.DEL}`,!0):t.length===e.length&&t!==e&&this._coreService.triggerDataEvent(t,!0)}},0)}updateCompositionElements(e){if(this._isComposing){if(this._bufferService.buffer.isCursorInViewport){let e=Math.min(this._bufferService.buffer.x,this._bufferService.cols-1),t=this._renderService.dimensions.css.cell.height,n=this._bufferService.buffer.y*this._renderService.dimensions.css.cell.height,r=e*this._renderService.dimensions.css.cell.width;this._compositionView.style.left=r+`px`,this._compositionView.style.top=n+`px`,this._compositionView.style.height=t+`px`,this._compositionView.style.lineHeight=t+`px`,this._compositionView.style.fontFamily=this._optionsService.rawOptions.fontFamily,this._compositionView.style.fontSize=this._optionsService.rawOptions.fontSize+`px`;let i=this._compositionView.getBoundingClientRect();this._textarea.style.left=r+`px`,this._textarea.style.top=n+`px`,this._textarea.style.width=Math.max(i.width,1)+`px`,this._textarea.style.height=Math.max(i.height,1)+`px`,this._textarea.style.lineHeight=i.height+`px`}e||setTimeout(()=>this.updateCompositionElements(!0),0)}}};dX=iK([aK(2,MK),aK(3,RK),aK(4,PK),aK(5,qK)],dX);var fX=0,pX=0,mX=0,hX=0,gX={css:`#00000000`,rgba:0},_X;(e=>{function t(e,t,n,r){return r===void 0?`#${SX(e)}${SX(t)}${SX(n)}`:`#${SX(e)}${SX(t)}${SX(n)}${SX(r)}`}e.toCss=t;function n(e,t,n,r=255){return(e<<24|t<<16|n<<8|r)>>>0}e.toRgba=n;function r(t,n,r,i){return{css:e.toCss(t,n,r,i),rgba:e.toRgba(t,n,r,i)}}e.toColor=r})(_X||={});var vX;(e=>{function t(e,t){if(hX=(t.rgba&255)/255,hX===1)return{css:t.css,rgba:t.rgba};let n=t.rgba>>24&255,r=t.rgba>>16&255,i=t.rgba>>8&255,a=e.rgba>>24&255,o=e.rgba>>16&255,s=e.rgba>>8&255;return fX=a+Math.round((n-a)*hX),pX=o+Math.round((r-o)*hX),mX=s+Math.round((i-s)*hX),{css:_X.toCss(fX,pX,mX),rgba:_X.toRgba(fX,pX,mX)}}e.blend=t;function n(e){return(e.rgba&255)==255}e.isOpaque=n;function r(e,t,n){let r=xX.ensureContrastRatio(e.rgba,t.rgba,n);if(r)return _X.toColor(r>>24&255,r>>16&255,r>>8&255)}e.ensureContrastRatio=r;function i(e){let t=(e.rgba|255)>>>0;return[fX,pX,mX]=xX.toChannels(t),{css:_X.toCss(fX,pX,mX),rgba:t}}e.opaque=i;function a(e,t){return hX=Math.round(t*255),[fX,pX,mX]=xX.toChannels(e.rgba),{css:_X.toCss(fX,pX,mX,hX),rgba:_X.toRgba(fX,pX,mX,hX)}}e.opacity=a;function o(e,t){return hX=e.rgba&255,a(e,hX*t/255)}e.multiplyOpacity=o;function s(e){return[e.rgba>>24&255,e.rgba>>16&255,e.rgba>>8&255]}e.toColorRGB=s})(vX||={});var yX;(e=>{let t,n;try{let e=document.createElement(`canvas`);e.width=1,e.height=1;let r=e.getContext(`2d`,{willReadFrequently:!0});r&&(t=r,t.globalCompositeOperation=`copy`,n=t.createLinearGradient(0,0,1,1))}catch{}function r(e){if(e.match(/#[\da-f]{3,8}/i))switch(e.length){case 4:return fX=parseInt(e.slice(1,2).repeat(2),16),pX=parseInt(e.slice(2,3).repeat(2),16),mX=parseInt(e.slice(3,4).repeat(2),16),_X.toColor(fX,pX,mX);case 5:return fX=parseInt(e.slice(1,2).repeat(2),16),pX=parseInt(e.slice(2,3).repeat(2),16),mX=parseInt(e.slice(3,4).repeat(2),16),hX=parseInt(e.slice(4,5).repeat(2),16),_X.toColor(fX,pX,mX,hX);case 7:return{css:e,rgba:(parseInt(e.slice(1),16)<<8|255)>>>0};case 9:return{css:e,rgba:parseInt(e.slice(1),16)>>>0}}let r=e.match(/rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(,\s*(0|1|\d?\.(\d+))\s*)?\)/);if(r)return fX=parseInt(r[1]),pX=parseInt(r[2]),mX=parseInt(r[3]),hX=Math.round((r[5]===void 0?1:parseFloat(r[5]))*255),_X.toColor(fX,pX,mX,hX);if(!t||!n||(t.fillStyle=n,t.fillStyle=e,typeof t.fillStyle!=`string`)||(t.fillRect(0,0,1,1),[fX,pX,mX,hX]=t.getImageData(0,0,1,1).data,hX!==255))throw Error(`css.toColor: Unsupported css format`);return{rgba:_X.toRgba(fX,pX,mX,hX),css:e}}e.toColor=r})(yX||={});var bX;(e=>{function t(e){return n(e>>16&255,e>>8&255,e&255)}e.relativeLuminance=t;function n(e,t,n){let r=e/255,i=t/255,a=n/255,o=r<=.03928?r/12.92:((r+.055)/1.055)**2.4,s=i<=.03928?i/12.92:((i+.055)/1.055)**2.4,c=a<=.03928?a/12.92:((a+.055)/1.055)**2.4;return o*.2126+s*.7152+c*.0722}e.relativeLuminance2=n})(bX||={});var xX;(e=>{function t(e,t){if(hX=(t&255)/255,hX===1)return t;let n=t>>24&255,r=t>>16&255,i=t>>8&255,a=e>>24&255,o=e>>16&255,s=e>>8&255;return fX=a+Math.round((n-a)*hX),pX=o+Math.round((r-o)*hX),mX=s+Math.round((i-s)*hX),_X.toRgba(fX,pX,mX)}e.blend=t;function n(e,t,n){let a=bX.relativeLuminance(e>>8),o=bX.relativeLuminance(t>>8);if(CX(a,o)<n){if(o<a){let o=r(e,t,n),s=CX(a,bX.relativeLuminance(o>>8));if(s<n){let r=i(e,t,n);return s>CX(a,bX.relativeLuminance(r>>8))?o:r}return o}let s=i(e,t,n),c=CX(a,bX.relativeLuminance(s>>8));if(c<n){let i=r(e,t,n);return c>CX(a,bX.relativeLuminance(i>>8))?s:i}return s}}e.ensureContrastRatio=n;function r(e,t,n){let r=e>>24&255,i=e>>16&255,a=e>>8&255,o=t>>24&255,s=t>>16&255,c=t>>8&255,l=CX(bX.relativeLuminance2(o,s,c),bX.relativeLuminance2(r,i,a));for(;l<n&&(o>0||s>0||c>0);)o-=Math.max(0,Math.ceil(o*.1)),s-=Math.max(0,Math.ceil(s*.1)),c-=Math.max(0,Math.ceil(c*.1)),l=CX(bX.relativeLuminance2(o,s,c),bX.relativeLuminance2(r,i,a));return(o<<24|s<<16|c<<8|255)>>>0}e.reduceLuminance=r;function i(e,t,n){let r=e>>24&255,i=e>>16&255,a=e>>8&255,o=t>>24&255,s=t>>16&255,c=t>>8&255,l=CX(bX.relativeLuminance2(o,s,c),bX.relativeLuminance2(r,i,a));for(;l<n&&(o<255||s<255||c<255);)o=Math.min(255,o+Math.ceil((255-o)*.1)),s=Math.min(255,s+Math.ceil((255-s)*.1)),c=Math.min(255,c+Math.ceil((255-c)*.1)),l=CX(bX.relativeLuminance2(o,s,c),bX.relativeLuminance2(r,i,a));return(o<<24|s<<16|c<<8|255)>>>0}e.increaseLuminance=i;function a(e){return[e>>24&255,e>>16&255,e>>8&255,e&255]}e.toChannels=a})(xX||={});function SX(e){let t=e.toString(16);return t.length<2?`0`+t:t}function CX(e,t){return e<t?(t+.05)/(e+.05):(e+.05)/(t+.05)}var wX=class extends CK{constructor(e,t,n){super(),this.content=0,this.combinedData=``,this.fg=e.fg,this.bg=e.bg,this.combinedData=t,this._width=n}isCombined(){return 2097152}getWidth(){return this._width}getChars(){return this.combinedData}getCode(){return 2097151}setFromCharData(e){throw Error(`not implemented`)}getAsCharData(){return[this.fg,this.getChars(),this.getWidth(),this.getCode()]}},TX=class{constructor(e){this._bufferService=e,this._characterJoiners=[],this._nextCharacterJoinerId=0,this._workCell=new TK}register(e){let t={id:this._nextCharacterJoinerId++,handler:e};return this._characterJoiners.push(t),t.id}deregister(e){for(let t=0;t<this._characterJoiners.length;t++)if(this._characterJoiners[t].id===e)return this._characterJoiners.splice(t,1),!0;return!1}getJoinedCharacters(e){if(this._characterJoiners.length===0)return[];let t=this._bufferService.buffer.lines.get(e);if(!t||t.length===0)return[];let n=[],r=t.translateToString(!0),i=0,a=0,o=0,s=t.getFg(0),c=t.getBg(0);for(let e=0;e<t.getTrimmedLength();e++)if(t.loadCell(e,this._workCell),this._workCell.getWidth()!==0){if(this._workCell.fg!==s||this._workCell.bg!==c){if(e-i>1){let e=this._getJoinedRanges(r,o,a,t,i);for(let t=0;t<e.length;t++)n.push(e[t])}i=e,o=a,s=this._workCell.fg,c=this._workCell.bg}a+=this._workCell.getChars().length||SK.length}if(this._bufferService.cols-i>1){let e=this._getJoinedRanges(r,o,a,t,i);for(let t=0;t<e.length;t++)n.push(e[t])}return n}_getJoinedRanges(e,t,n,r,i){let a=e.substring(t,n),o=[];try{o=this._characterJoiners[0].handler(a)}catch(e){console.error(e)}for(let e=1;e<this._characterJoiners.length;e++)try{let t=this._characterJoiners[e].handler(a);for(let e=0;e<t.length;e++)TX._mergeRanges(o,t[e])}catch(e){console.error(e)}return this._stringRangesToCellRanges(o,r,i),o}_stringRangesToCellRanges(e,t,n){let r=0,i=!1,a=0,o=e[r];if(o){for(let s=n;s<this._bufferService.cols;s++){let n=t.getWidth(s),c=t.getString(s).length||SK.length;if(n!==0){if(!i&&o[0]<=a&&(o[0]=s,i=!0),o[1]<=a){if(o[1]=s,o=e[++r],!o)break;o[0]<=a?(o[0]=s,i=!0):i=!1}a+=c}}o&&(o[1]=this._bufferService.cols)}}static _mergeRanges(e,t){let n=!1;for(let r=0;r<e.length;r++){let i=e[r];if(n){if(t[1]<=i[0])return e[r-1][1]=t[1],e;if(t[1]<=i[1])return e[r-1][1]=Math.max(t[1],i[1]),e.splice(r,1),e;e.splice(r,1),r--}else{if(t[1]<=i[0])return e.splice(r,0,t),e;if(t[1]<=i[1])return i[0]=Math.min(t[0],i[0]),e;t[0]<i[1]&&(i[0]=Math.min(t[0],i[0]),n=!0);continue}}return n?e[e.length-1][1]=t[1]:e.push(t),e}};TX=iK([aK(0,MK)],TX);function EX(e){return 57508<=e&&e<=57558}function DX(e){return 9472<=e&&e<=9631}function OX(e){return EX(e)||DX(e)}function kX(){return{css:{canvas:AX(),cell:AX()},device:{canvas:AX(),cell:AX(),char:{width:0,height:0,left:0,top:0}}}}function AX(){return{width:0,height:0}}var jX=class{constructor(e,t,n,r,i,a,o){this._document=e,this._characterJoinerService=t,this._optionsService=n,this._coreBrowserService=r,this._coreService=i,this._decorationService=a,this._themeService=o,this._workCell=new TK,this._columnSelectMode=!1,this.defaultSpacing=0}handleSelectionChanged(e,t,n){this._selectionStart=e,this._selectionEnd=t,this._columnSelectMode=n}createRow(e,t,n,r,i,a,o,s,c,l,u){let d=[],f=this._characterJoinerService.getJoinedCharacters(t),p=this._themeService.colors,m=e.getNoBgTrimmedLength();n&&m<a+1&&(m=a+1);let h,g=0,_=``,v=0,y=0,b=0,x=0,S=!1,C=0,w=!1,T=0,E=0,D=[],O=l!==-1&&u!==-1;for(let ee=0;ee<m;ee++){e.loadCell(ee,this._workCell);let m=this._workCell.getWidth();if(m===0)continue;let te=!1,k=ee>=E,ne=ee,A=this._workCell;if(f.length>0&&ee===f[0][0]&&k){let r=f.shift(),i=this._isCellInSelection(r[0],t);for(v=r[0]+1;v<r[1];v++)k&&=i===this._isCellInSelection(v,t);k&&=!n||a<r[0]||a>=r[1],k?(te=!0,A=new wX(this._workCell,e.translateToString(!0,r[0],r[1]),r[1]-r[0]),ne=r[1]-1,m=A.getWidth()):E=r[1]}let re=this._isCellInSelection(ee,t),j=n&&ee===a,ie=O&&ee>=l&&ee<=u,ae=!1;this._decorationService.forEachDecorationAtCell(ee,t,void 0,e=>{ae=!0});let oe=A.getChars()||SK;if(oe===` `&&(A.isUnderline()||A.isOverline())&&(oe=`\xA0`),T=m*s-c.get(oe,A.isBold(),A.isItalic()),!h)h=this._document.createElement(`span`);else if(g&&(re&&w||!re&&!w&&A.bg===y)&&(re&&w&&p.selectionForeground||A.fg===b)&&A.extended.ext===x&&ie===S&&T===C&&!j&&!te&&!ae&&k){A.isInvisible()?_+=SK:_+=oe,g++;continue}else g&&(h.textContent=_),h=this._document.createElement(`span`),g=0,_=``;if(y=A.bg,b=A.fg,x=A.extended.ext,S=ie,C=T,w=re,te&&a>=ee&&a<=ne&&(a=ee),!this._coreService.isCursorHidden&&j&&this._coreService.isCursorInitialized){if(D.push(`xterm-cursor`),this._coreBrowserService.isFocused)o&&D.push(`xterm-cursor-blink`),D.push(r===`bar`?`xterm-cursor-bar`:r===`underline`?`xterm-cursor-underline`:`xterm-cursor-block`);else if(i)switch(i){case`outline`:D.push(`xterm-cursor-outline`);break;case`block`:D.push(`xterm-cursor-block`);break;case`bar`:D.push(`xterm-cursor-bar`);break;case`underline`:D.push(`xterm-cursor-underline`)}}if(A.isBold()&&D.push(`xterm-bold`),A.isItalic()&&D.push(`xterm-italic`),A.isDim()&&D.push(`xterm-dim`),_=A.isInvisible()?SK:A.getChars()||SK,A.isUnderline()&&(D.push(`xterm-underline-${A.extended.underlineStyle}`),_===` `&&(_=`\xA0`),!A.isUnderlineColorDefault())){if(A.isUnderlineColorRGB())h.style.textDecorationColor=`rgb(${CK.toColorRGB(A.getUnderlineColor()).join(`,`)})`;else{let e=A.getUnderlineColor();this._optionsService.rawOptions.drawBoldTextInBrightColors&&A.isBold()&&e<8&&(e+=8),h.style.textDecorationColor=p.ansi[e].css}}A.isOverline()&&(D.push(`xterm-overline`),_===` `&&(_=`\xA0`)),A.isStrikethrough()&&D.push(`xterm-strikethrough`),ie&&(h.style.textDecoration=`underline`);let se=A.getFgColor(),ce=A.getFgColorMode(),le=A.getBgColor(),ue=A.getBgColorMode(),de=!!A.isInverse();if(de){let e=se;se=le,le=e;let t=ce;ce=ue,ue=t}let fe,M,pe=!1;this._decorationService.forEachDecorationAtCell(ee,t,void 0,e=>{e.options.layer!==`top`&&pe||(e.backgroundColorRGB&&(ue=50331648,le=e.backgroundColorRGB.rgba>>8&16777215,fe=e.backgroundColorRGB),e.foregroundColorRGB&&(ce=50331648,se=e.foregroundColorRGB.rgba>>8&16777215,M=e.foregroundColorRGB),pe=e.options.layer===`top`)}),!pe&&re&&(fe=this._coreBrowserService.isFocused?p.selectionBackgroundOpaque:p.selectionInactiveBackgroundOpaque,le=fe.rgba>>8&16777215,ue=50331648,pe=!0,p.selectionForeground&&(ce=50331648,se=p.selectionForeground.rgba>>8&16777215,M=p.selectionForeground)),pe&&D.push(`xterm-decoration-top`);let N;switch(ue){case 16777216:case 33554432:N=p.ansi[le],D.push(`xterm-bg-${le}`);break;case 50331648:N=_X.toColor(le>>16,le>>8&255,le&255),this._addStyle(h,`background-color:#${MX((le>>>0).toString(16),`0`,6)}`);break;default:de?(N=p.foreground,D.push(`xterm-bg-257`)):N=p.background}switch(fe||A.isDim()&&(fe=vX.multiplyOpacity(N,.5)),ce){case 16777216:case 33554432:A.isBold()&&se<8&&this._optionsService.rawOptions.drawBoldTextInBrightColors&&(se+=8),this._applyMinimumContrast(h,N,p.ansi[se],A,fe,void 0)||D.push(`xterm-fg-${se}`);break;case 50331648:let e=_X.toColor(se>>16&255,se>>8&255,se&255);this._applyMinimumContrast(h,N,e,A,fe,M)||this._addStyle(h,`color:#${MX(se.toString(16),`0`,6)}`);break;default:this._applyMinimumContrast(h,N,p.foreground,A,fe,M)||de&&D.push(`xterm-fg-257`)}D.length&&=(h.className=D.join(` `),0),!j&&!te&&!ae&&k?g++:h.textContent=_,T!==this.defaultSpacing&&(h.style.letterSpacing=`${T}px`),d.push(h),ee=ne}return h&&g&&(h.textContent=_),d}_applyMinimumContrast(e,t,n,r,i,a){if(this._optionsService.rawOptions.minimumContrastRatio===1||OX(r.getCode()))return!1;let o=this._getContrastCache(r),s;if(!i&&!a&&(s=o.getColor(t.rgba,n.rgba)),s===void 0){let e=this._optionsService.rawOptions.minimumContrastRatio/(r.isDim()?2:1);s=vX.ensureContrastRatio(i||t,a||n,e),o.setColor((i||t).rgba,(a||n).rgba,s??null)}return s?(this._addStyle(e,`color:${s.css}`),!0):!1}_getContrastCache(e){return e.isDim()?this._themeService.colors.halfContrastCache:this._themeService.colors.contrastCache}_addStyle(e,t){e.setAttribute(`style`,`${e.getAttribute(`style`)||``}${t};`)}_isCellInSelection(e,t){let n=this._selectionStart,r=this._selectionEnd;return!n||!r?!1:this._columnSelectMode?n[0]<=r[0]?e>=n[0]&&t>=n[1]&&e<r[0]&&t<=r[1]:e<n[0]&&t>=n[1]&&e>=r[0]&&t<=r[1]:t>n[1]&&t<r[1]||n[1]===r[1]&&t===n[1]&&e>=n[0]&&e<r[0]||n[1]<r[1]&&t===r[1]&&e<r[0]||n[1]<r[1]&&t===n[1]&&e>=n[0]}};jX=iK([aK(1,YK),aK(2,RK),aK(3,GK),aK(4,PK),aK(5,VK),aK(6,XK)],jX);function MX(e,t,n){for(;e.length<n;)e=t+e;return e}var NX=class{constructor(e,t){this._flat=new Float32Array(256),this._font=``,this._fontSize=0,this._weight=`normal`,this._weightBold=`bold`,this._measureElements=[],this._container=e.createElement(`div`),this._container.classList.add(`xterm-width-cache-measure-container`),this._container.setAttribute(`aria-hidden`,`true`),this._container.style.whiteSpace=`pre`,this._container.style.fontKerning=`none`;let n=e.createElement(`span`);n.classList.add(`xterm-char-measure-element`);let r=e.createElement(`span`);r.classList.add(`xterm-char-measure-element`),r.style.fontWeight=`bold`;let i=e.createElement(`span`);i.classList.add(`xterm-char-measure-element`),i.style.fontStyle=`italic`;let a=e.createElement(`span`);a.classList.add(`xterm-char-measure-element`),a.style.fontWeight=`bold`,a.style.fontStyle=`italic`,this._measureElements=[n,r,i,a],this._container.appendChild(n),this._container.appendChild(r),this._container.appendChild(i),this._container.appendChild(a),t.appendChild(this._container),this.clear()}dispose(){this._container.remove(),this._measureElements.length=0,this._holey=void 0}clear(){this._flat.fill(-9999),this._holey=new Map}setFont(e,t,n,r){e===this._font&&t===this._fontSize&&n===this._weight&&r===this._weightBold||(this._font=e,this._fontSize=t,this._weight=n,this._weightBold=r,this._container.style.fontFamily=this._font,this._container.style.fontSize=`${this._fontSize}px`,this._measureElements[0].style.fontWeight=`${n}`,this._measureElements[1].style.fontWeight=`${r}`,this._measureElements[2].style.fontWeight=`${n}`,this._measureElements[3].style.fontWeight=`${r}`,this.clear())}get(e,t,n){let r=0;if(!t&&!n&&e.length===1&&(r=e.charCodeAt(0))<256){if(this._flat[r]!==-9999)return this._flat[r];let t=this._measure(e,0);return t>0&&(this._flat[r]=t),t}let i=e;t&&(i+=`B`),n&&(i+=`I`);let a=this._holey.get(i);if(a===void 0){let r=0;t&&(r|=1),n&&(r|=2),a=this._measure(e,r),a>0&&this._holey.set(i,a)}return a}_measure(e,t){let n=this._measureElements[t];return n.textContent=e.repeat(32),n.offsetWidth/32}},PX=class{constructor(){this.clear()}clear(){this.hasSelection=!1,this.columnSelectMode=!1,this.viewportStartRow=0,this.viewportEndRow=0,this.viewportCappedStartRow=0,this.viewportCappedEndRow=0,this.startCol=0,this.endCol=0,this.selectionStart=void 0,this.selectionEnd=void 0}update(e,t,n,r=!1){if(this.selectionStart=t,this.selectionEnd=n,!t||!n||t[0]===n[0]&&t[1]===n[1]){this.clear();return}let i=e.buffers.active.ydisp,a=t[1]-i,o=n[1]-i,s=Math.max(a,0),c=Math.min(o,e.rows-1);s>=e.rows||c<0?this.clear():(this.hasSelection=!0,this.columnSelectMode=r,this.viewportStartRow=a,this.viewportEndRow=o,this.viewportCappedStartRow=s,this.viewportCappedEndRow=c,this.startCol=t[0],this.endCol=n[0])}isCellSelected(e,t,n){return this.hasSelection?(n-=e.buffer.active.viewportY,this.columnSelectMode?this.startCol<=this.endCol?t>=this.startCol&&n>=this.viewportCappedStartRow&&t<this.endCol&&n<=this.viewportCappedEndRow:t<this.startCol&&n>=this.viewportCappedStartRow&&t>=this.endCol&&n<=this.viewportCappedEndRow:n>this.viewportStartRow&&n<this.viewportEndRow||this.viewportStartRow===this.viewportEndRow&&n===this.viewportStartRow&&t>=this.startCol&&t<this.endCol||this.viewportStartRow<this.viewportEndRow&&n===this.viewportEndRow&&t<this.endCol||this.viewportStartRow<this.viewportEndRow&&n===this.viewportStartRow&&t>=this.startCol):!1}};function FX(){return new PX}var IX=`xterm-dom-renderer-owner-`,LX=`xterm-rows`,RX=`xterm-fg-`,zX=`xterm-bg-`,BX=`xterm-focus`,VX=`xterm-selection`,HX=1,UX=class extends xq{constructor(e,t,n,r,i,a,o,s,c,l,u,d,f,p){super(),this._terminal=e,this._document=t,this._element=n,this._screenElement=r,this._viewportElement=i,this._helperContainer=a,this._linkifier2=o,this._charSizeService=c,this._optionsService=l,this._bufferService=u,this._coreService=d,this._coreBrowserService=f,this._themeService=p,this._terminalClass=HX++,this._rowElements=[],this._selectionRenderModel=FX(),this.onRequestRedraw=this._register(new Vq).event,this._rowContainer=this._document.createElement(`div`),this._rowContainer.classList.add(LX),this._rowContainer.style.lineHeight=`normal`,this._rowContainer.setAttribute(`aria-hidden`,`true`),this._refreshRowElements(this._bufferService.cols,this._bufferService.rows),this._selectionContainer=this._document.createElement(`div`),this._selectionContainer.classList.add(VX),this._selectionContainer.setAttribute(`aria-hidden`,`true`),this.dimensions=kX(),this._updateDimensions(),this._register(this._optionsService.onOptionChange(()=>this._handleOptionsChanged())),this._register(this._themeService.onChangeColors(e=>this._injectCss(e))),this._injectCss(this._themeService.colors),this._rowFactory=s.createInstance(jX,document),this._element.classList.add(IX+this._terminalClass),this._screenElement.appendChild(this._rowContainer),this._screenElement.appendChild(this._selectionContainer),this._register(this._linkifier2.onShowLinkUnderline(e=>this._handleLinkHover(e))),this._register(this._linkifier2.onHideLinkUnderline(e=>this._handleLinkLeave(e))),this._register(vq(()=>{this._element.classList.remove(IX+this._terminalClass),this._rowContainer.remove(),this._selectionContainer.remove(),this._widthCache.dispose(),this._themeStyleElement.remove(),this._dimensionsStyleElement.remove()})),this._widthCache=new NX(this._document,this._helperContainer),this._widthCache.setFont(this._optionsService.rawOptions.fontFamily,this._optionsService.rawOptions.fontSize,this._optionsService.rawOptions.fontWeight,this._optionsService.rawOptions.fontWeightBold),this._setDefaultSpacing()}_updateDimensions(){let e=this._coreBrowserService.dpr;this.dimensions.device.char.width=this._charSizeService.width*e,this.dimensions.device.char.height=Math.ceil(this._charSizeService.height*e),this.dimensions.device.cell.width=this.dimensions.device.char.width+Math.round(this._optionsService.rawOptions.letterSpacing),this.dimensions.device.cell.height=Math.floor(this.dimensions.device.char.height*this._optionsService.rawOptions.lineHeight),this.dimensions.device.char.left=0,this.dimensions.device.char.top=0,this.dimensions.device.canvas.width=this.dimensions.device.cell.width*this._bufferService.cols,this.dimensions.device.canvas.height=this.dimensions.device.cell.height*this._bufferService.rows,this.dimensions.css.canvas.width=Math.round(this.dimensions.device.canvas.width/e),this.dimensions.css.canvas.height=Math.round(this.dimensions.device.canvas.height/e),this.dimensions.css.cell.width=this.dimensions.css.canvas.width/this._bufferService.cols,this.dimensions.css.cell.height=this.dimensions.css.canvas.height/this._bufferService.rows;for(let e of this._rowElements)e.style.width=`${this.dimensions.css.canvas.width}px`,e.style.height=`${this.dimensions.css.cell.height}px`,e.style.lineHeight=`${this.dimensions.css.cell.height}px`,e.style.overflow=`hidden`;this._dimensionsStyleElement||(this._dimensionsStyleElement=this._document.createElement(`style`),this._screenElement.appendChild(this._dimensionsStyleElement));let t=`${this._terminalSelector} .${LX} span { display: inline-block; height: 100%; vertical-align: top;}`;this._dimensionsStyleElement.textContent=t,this._selectionContainer.style.height=this._viewportElement.style.height,this._screenElement.style.width=`${this.dimensions.css.canvas.width}px`,this._screenElement.style.height=`${this.dimensions.css.canvas.height}px`}_injectCss(e){this._themeStyleElement||(this._themeStyleElement=this._document.createElement(`style`),this._screenElement.appendChild(this._themeStyleElement));let t=`${this._terminalSelector} .${LX} { pointer-events: none; color: ${e.foreground.css}; font-family: ${this._optionsService.rawOptions.fontFamily}; font-size: ${this._optionsService.rawOptions.fontSize}px; font-kerning: none; white-space: pre}`;t+=`${this._terminalSelector} .${LX} .xterm-dim { color: ${vX.multiplyOpacity(e.foreground,.5).css};}`,t+=`${this._terminalSelector} span:not(.xterm-bold) { font-weight: ${this._optionsService.rawOptions.fontWeight};}${this._terminalSelector} span.xterm-bold { font-weight: ${this._optionsService.rawOptions.fontWeightBold};}${this._terminalSelector} span.xterm-italic { font-style: italic;}`;let n=`blink_underline_${this._terminalClass}`,r=`blink_bar_${this._terminalClass}`,i=`blink_block_${this._terminalClass}`;t+=`@keyframes ${n} { 50% { border-bottom-style: hidden; }}`,t+=`@keyframes ${r} { 50% { box-shadow: none; }}`,t+=`@keyframes ${i} { 0% { background-color: ${e.cursor.css}; color: ${e.cursorAccent.css}; } 50% { background-color: inherit; color: ${e.cursor.css}; }}`,t+=`${this._terminalSelector} .${LX}.${BX} .xterm-cursor.xterm-cursor-blink.xterm-cursor-underline { animation: ${n} 1s step-end infinite;}${this._terminalSelector} .${LX}.${BX} .xterm-cursor.xterm-cursor-blink.xterm-cursor-bar { animation: ${r} 1s step-end infinite;}${this._terminalSelector} .${LX}.${BX} .xterm-cursor.xterm-cursor-blink.xterm-cursor-block { animation: ${i} 1s step-end infinite;}${this._terminalSelector} .${LX} .xterm-cursor.xterm-cursor-block { background-color: ${e.cursor.css}; color: ${e.cursorAccent.css};}${this._terminalSelector} .${LX} .xterm-cursor.xterm-cursor-block:not(.xterm-cursor-blink) { background-color: ${e.cursor.css} !important; color: ${e.cursorAccent.css} !important;}${this._terminalSelector} .${LX} .xterm-cursor.xterm-cursor-outline { outline: 1px solid ${e.cursor.css}; outline-offset: -1px;}${this._terminalSelector} .${LX} .xterm-cursor.xterm-cursor-bar { box-shadow: ${this._optionsService.rawOptions.cursorWidth}px 0 0 ${e.cursor.css} inset;}${this._terminalSelector} .${LX} .xterm-cursor.xterm-cursor-underline { border-bottom: 1px ${e.cursor.css}; border-bottom-style: solid; height: calc(100% - 1px);}`,t+=`${this._terminalSelector} .${VX} { position: absolute; top: 0; left: 0; z-index: 1; pointer-events: none;}${this._terminalSelector}.focus .${VX} div { position: absolute; background-color: ${e.selectionBackgroundOpaque.css};}${this._terminalSelector} .${VX} div { position: absolute; background-color: ${e.selectionInactiveBackgroundOpaque.css};}`;for(let[n,r]of e.ansi.entries())t+=`${this._terminalSelector} .${RX}${n} { color: ${r.css}; }${this._terminalSelector} .${RX}${n}.xterm-dim { color: ${vX.multiplyOpacity(r,.5).css}; }${this._terminalSelector} .${zX}${n} { background-color: ${r.css}; }`;t+=`${this._terminalSelector} .${RX}257 { color: ${vX.opaque(e.background).css}; }${this._terminalSelector} .${RX}257.xterm-dim { color: ${vX.multiplyOpacity(vX.opaque(e.background),.5).css}; }${this._terminalSelector} .${zX}257 { background-color: ${e.foreground.css}; }`,this._themeStyleElement.textContent=t}_setDefaultSpacing(){let e=this.dimensions.css.cell.width-this._widthCache.get(`W`,!1,!1);this._rowContainer.style.letterSpacing=`${e}px`,this._rowFactory.defaultSpacing=e}handleDevicePixelRatioChange(){this._updateDimensions(),this._widthCache.clear(),this._setDefaultSpacing()}_refreshRowElements(e,t){for(let e=this._rowElements.length;e<=t;e++){let e=this._document.createElement(`div`);this._rowContainer.appendChild(e),this._rowElements.push(e)}for(;this._rowElements.length>t;)this._rowContainer.removeChild(this._rowElements.pop())}handleResize(e,t){this._refreshRowElements(e,t),this._updateDimensions(),this.handleSelectionChanged(this._selectionRenderModel.selectionStart,this._selectionRenderModel.selectionEnd,this._selectionRenderModel.columnSelectMode)}handleCharSizeChanged(){this._updateDimensions(),this._widthCache.clear(),this._setDefaultSpacing()}handleBlur(){this._rowContainer.classList.remove(BX),this.renderRows(0,this._bufferService.rows-1)}handleFocus(){this._rowContainer.classList.add(BX),this.renderRows(this._bufferService.buffer.y,this._bufferService.buffer.y)}handleSelectionChanged(e,t,n){if(this._selectionContainer.replaceChildren(),this._rowFactory.handleSelectionChanged(e,t,n),this.renderRows(0,this._bufferService.rows-1),!e||!t||(this._selectionRenderModel.update(this._terminal,e,t,n),!this._selectionRenderModel.hasSelection))return;let r=this._selectionRenderModel.viewportStartRow,i=this._selectionRenderModel.viewportEndRow,a=this._selectionRenderModel.viewportCappedStartRow,o=this._selectionRenderModel.viewportCappedEndRow,s=this._document.createDocumentFragment();if(n){let n=e[0]>t[0];s.appendChild(this._createSelectionElement(a,n?t[0]:e[0],n?e[0]:t[0],o-a+1))}else{let n=r===a?e[0]:0,c=a===i?t[0]:this._bufferService.cols;s.appendChild(this._createSelectionElement(a,n,c));let l=o-a-1;if(s.appendChild(this._createSelectionElement(a+1,0,this._bufferService.cols,l)),a!==o){let e=i===o?t[0]:this._bufferService.cols;s.appendChild(this._createSelectionElement(o,0,e))}}this._selectionContainer.appendChild(s)}_createSelectionElement(e,t,n,r=1){let i=this._document.createElement(`div`),a=t*this.dimensions.css.cell.width,o=this.dimensions.css.cell.width*(n-t);return a+o>this.dimensions.css.canvas.width&&(o=this.dimensions.css.canvas.width-a),i.style.height=`${r*this.dimensions.css.cell.height}px`,i.style.top=`${e*this.dimensions.css.cell.height}px`,i.style.left=`${a}px`,i.style.width=`${o}px`,i}handleCursorMove(){}_handleOptionsChanged(){this._updateDimensions(),this._injectCss(this._themeService.colors),this._widthCache.setFont(this._optionsService.rawOptions.fontFamily,this._optionsService.rawOptions.fontSize,this._optionsService.rawOptions.fontWeight,this._optionsService.rawOptions.fontWeightBold),this._setDefaultSpacing()}clear(){for(let e of this._rowElements)e.replaceChildren()}renderRows(e,t){let n=this._bufferService.buffer,r=n.ybase+n.y,i=Math.min(n.x,this._bufferService.cols-1),a=this._coreService.decPrivateModes.cursorBlink??this._optionsService.rawOptions.cursorBlink,o=this._coreService.decPrivateModes.cursorStyle??this._optionsService.rawOptions.cursorStyle,s=this._optionsService.rawOptions.cursorInactiveStyle;for(let c=e;c<=t;c++){let e=c+n.ydisp,t=this._rowElements[c],l=n.lines.get(e);if(!t||!l)break;t.replaceChildren(...this._rowFactory.createRow(l,e,e===r,o,s,i,a,this.dimensions.css.cell.width,this._widthCache,-1,-1))}}get _terminalSelector(){return`.${IX}${this._terminalClass}`}_handleLinkHover(e){this._setCellUnderline(e.x1,e.x2,e.y1,e.y2,e.cols,!0)}_handleLinkLeave(e){this._setCellUnderline(e.x1,e.x2,e.y1,e.y2,e.cols,!1)}_setCellUnderline(e,t,n,r,i,a){n<0&&(e=0),r<0&&(t=0);let o=this._bufferService.rows-1;n=Math.max(Math.min(n,o),0),r=Math.max(Math.min(r,o),0),i=Math.min(i,this._bufferService.cols);let s=this._bufferService.buffer,c=s.ybase+s.y,l=Math.min(s.x,i-1),u=this._optionsService.rawOptions.cursorBlink,d=this._optionsService.rawOptions.cursorStyle,f=this._optionsService.rawOptions.cursorInactiveStyle;for(let o=n;o<=r;++o){let p=o+s.ydisp,m=this._rowElements[o],h=s.lines.get(p);if(!m||!h)break;m.replaceChildren(...this._rowFactory.createRow(h,p,p===c,d,f,l,u,this.dimensions.css.cell.width,this._widthCache,a?o===n?e:0:-1,a?(o===r?t:i)-1:-1))}}};UX=iK([aK(7,IK),aK(8,WK),aK(9,RK),aK(10,MK),aK(11,PK),aK(12,GK),aK(13,XK)],UX);var WX=class extends xq{constructor(e,t,n){super(),this._optionsService=n,this.width=0,this.height=0,this._onCharSizeChange=this._register(new Vq),this.onCharSizeChange=this._onCharSizeChange.event;try{this._measureStrategy=this._register(new qX(this._optionsService))}catch{this._measureStrategy=this._register(new KX(e,t,this._optionsService))}this._register(this._optionsService.onMultipleOptionChange([`fontFamily`,`fontSize`],()=>this.measure()))}get hasValidSize(){return this.width>0&&this.height>0}measure(){let e=this._measureStrategy.measure();(e.width!==this.width||e.height!==this.height)&&(this.width=e.width,this.height=e.height,this._onCharSizeChange.fire())}};WX=iK([aK(2,RK)],WX);var GX=class extends xq{constructor(){super(...arguments),this._result={width:0,height:0}}_validateAndSet(e,t){e!==void 0&&e>0&&t!==void 0&&t>0&&(this._result.width=e,this._result.height=t)}},KX=class extends GX{constructor(e,t,n){super(),this._document=e,this._parentElement=t,this._optionsService=n,this._measureElement=this._document.createElement(`span`),this._measureElement.classList.add(`xterm-char-measure-element`),this._measureElement.textContent=`W`.repeat(32),this._measureElement.setAttribute(`aria-hidden`,`true`),this._measureElement.style.whiteSpace=`pre`,this._measureElement.style.fontKerning=`none`,this._parentElement.appendChild(this._measureElement)}measure(){return this._measureElement.style.fontFamily=this._optionsService.rawOptions.fontFamily,this._measureElement.style.fontSize=`${this._optionsService.rawOptions.fontSize}px`,this._validateAndSet(Number(this._measureElement.offsetWidth)/32,Number(this._measureElement.offsetHeight)),this._result}},qX=class extends GX{constructor(e){super(),this._optionsService=e,this._canvas=new OffscreenCanvas(100,100),this._ctx=this._canvas.getContext(`2d`);let t=this._ctx.measureText(`W`);if(!(`width`in t&&`fontBoundingBoxAscent`in t&&`fontBoundingBoxDescent`in t))throw Error(`Required font metrics not supported`)}measure(){this._ctx.font=`${this._optionsService.rawOptions.fontSize}px ${this._optionsService.rawOptions.fontFamily}`;let e=this._ctx.measureText(`W`);return this._validateAndSet(e.width,e.fontBoundingBoxAscent+e.fontBoundingBoxDescent),this._result}},JX=class extends xq{constructor(e,t,n){super(),this._textarea=e,this._window=t,this.mainDocument=n,this._isFocused=!1,this._cachedIsFocused=void 0,this._screenDprMonitor=this._register(new YX(this._window)),this._onDprChange=this._register(new Vq),this.onDprChange=this._onDprChange.event,this._onWindowChange=this._register(new Vq),this.onWindowChange=this._onWindowChange.event,this._register(this.onWindowChange(e=>this._screenDprMonitor.setWindow(e))),this._register(kq.forward(this._screenDprMonitor.onDprChange,this._onDprChange)),this._register(fY(this._textarea,`focus`,()=>this._isFocused=!0)),this._register(fY(this._textarea,`blur`,()=>this._isFocused=!1))}get window(){return this._window}set window(e){this._window!==e&&(this._window=e,this._onWindowChange.fire(this._window))}get dpr(){return this.window.devicePixelRatio}get isFocused(){return this._cachedIsFocused===void 0&&(this._cachedIsFocused=this._isFocused&&this._textarea.ownerDocument.hasFocus(),queueMicrotask(()=>this._cachedIsFocused=void 0)),this._cachedIsFocused}},YX=class extends xq{constructor(e){super(),this._parentWindow=e,this._windowResizeListener=this._register(new Sq),this._onDprChange=this._register(new Vq),this.onDprChange=this._onDprChange.event,this._outerListener=()=>this._setDprAndFireIfDiffers(),this._currentDevicePixelRatio=this._parentWindow.devicePixelRatio,this._updateDpr(),this._setWindowResizeListener(),this._register(vq(()=>this.clearListener()))}setWindow(e){this._parentWindow=e,this._setWindowResizeListener(),this._setDprAndFireIfDiffers()}_setWindowResizeListener(){this._windowResizeListener.value=fY(this._parentWindow,`resize`,()=>this._setDprAndFireIfDiffers())}_setDprAndFireIfDiffers(){this._parentWindow.devicePixelRatio!==this._currentDevicePixelRatio&&this._onDprChange.fire(this._parentWindow.devicePixelRatio),this._updateDpr()}_updateDpr(){this._outerListener&&(this._resolutionMediaMatchList?.removeListener(this._outerListener),this._currentDevicePixelRatio=this._parentWindow.devicePixelRatio,this._resolutionMediaMatchList=this._parentWindow.matchMedia(`screen and (resolution: ${this._parentWindow.devicePixelRatio}dppx)`),this._resolutionMediaMatchList.addListener(this._outerListener))}clearListener(){!this._resolutionMediaMatchList||!this._outerListener||(this._resolutionMediaMatchList.removeListener(this._outerListener),this._resolutionMediaMatchList=void 0,this._outerListener=void 0)}},XX=class extends xq{constructor(){super(),this.linkProviders=[],this._register(vq(()=>this.linkProviders.length=0))}registerLinkProvider(e){return this.linkProviders.push(e),{dispose:()=>{let t=this.linkProviders.indexOf(e);t!==-1&&this.linkProviders.splice(t,1)}}}};function ZX(e,t,n){let r=n.getBoundingClientRect(),i=e.getComputedStyle(n),a=parseInt(i.getPropertyValue(`padding-left`)),o=parseInt(i.getPropertyValue(`padding-top`));return[t.clientX-r.left-a,t.clientY-r.top-o]}function QX(e,t,n,r,i,a,o,s,c){if(!a)return;let l=ZX(e,t,n);if(l)return l[0]=Math.ceil((l[0]+(c?o/2:0))/o),l[1]=Math.ceil(l[1]/s),l[0]=Math.min(Math.max(l[0],1),r+ +!!c),l[1]=Math.min(Math.max(l[1],1),i),l}var $X=class{constructor(e,t){this._renderService=e,this._charSizeService=t}getCoords(e,t,n,r,i){return QX(window,e,t,n,r,this._charSizeService.hasValidSize,this._renderService.dimensions.css.cell.width,this._renderService.dimensions.css.cell.height,i)}getMouseReportCoords(e,t){let n=ZX(window,e,t);if(this._charSizeService.hasValidSize)return n[0]=Math.min(Math.max(n[0],0),this._renderService.dimensions.css.canvas.width-1),n[1]=Math.min(Math.max(n[1],0),this._renderService.dimensions.css.canvas.height-1),{col:Math.floor(n[0]/this._renderService.dimensions.css.cell.width),row:Math.floor(n[1]/this._renderService.dimensions.css.cell.height),x:Math.floor(n[0]),y:Math.floor(n[1])}}};$X=iK([aK(0,qK),aK(1,WK)],$X);var eZ=class{constructor(e,t){this._renderCallback=e,this._coreBrowserService=t,this._refreshCallbacks=[]}dispose(){this._animationFrame&&=(this._coreBrowserService.window.cancelAnimationFrame(this._animationFrame),void 0)}addRefreshCallback(e){return this._refreshCallbacks.push(e),this._animationFrame||=this._coreBrowserService.window.requestAnimationFrame(()=>this._innerRefresh()),this._animationFrame}refresh(e,t,n){this._rowCount=n,e=e===void 0?0:e,t=t===void 0?this._rowCount-1:t,this._rowStart=this._rowStart===void 0?e:Math.min(this._rowStart,e),this._rowEnd=this._rowEnd===void 0?t:Math.max(this._rowEnd,t),!this._animationFrame&&(this._animationFrame=this._coreBrowserService.window.requestAnimationFrame(()=>this._innerRefresh()))}_innerRefresh(){if(this._animationFrame=void 0,this._rowStart===void 0||this._rowEnd===void 0||this._rowCount===void 0){this._runRefreshCallbacks();return}let e=Math.max(this._rowStart,0),t=Math.min(this._rowEnd,this._rowCount-1);this._rowStart=void 0,this._rowEnd=void 0,this._renderCallback(e,t),this._runRefreshCallbacks()}_runRefreshCallbacks(){for(let e of this._refreshCallbacks)e(0);this._refreshCallbacks=[]}},tZ={};rK(tZ,{getSafariVersion:()=>cZ,isChromeOS:()=>mZ,isFirefox:()=>aZ,isIpad:()=>uZ,isIphone:()=>dZ,isLegacyEdge:()=>oZ,isLinux:()=>pZ,isMac:()=>lZ,isNode:()=>nZ,isSafari:()=>sZ,isWindows:()=>fZ});var nZ=typeof process<`u`&&`title`in process,rZ=nZ?`node`:navigator.userAgent,iZ=nZ?`node`:navigator.platform,aZ=rZ.includes(`Firefox`),oZ=rZ.includes(`Edge`),sZ=/^((?!chrome|android).)*safari/i.test(rZ);function cZ(){if(!sZ)return 0;let e=rZ.match(/Version\/(\d+)/);return e===null||e.length<2?0:parseInt(e[1])}var lZ=[`Macintosh`,`MacIntel`,`MacPPC`,`Mac68K`].includes(iZ),uZ=iZ===`iPad`,dZ=iZ===`iPhone`,fZ=[`Windows`,`Win16`,`Win32`,`WinCE`].includes(iZ),pZ=iZ.indexOf(`Linux`)>=0,mZ=/\bCrOS\b/.test(rZ),hZ=class{constructor(){this._tasks=[],this._i=0}enqueue(e){this._tasks.push(e),this._start()}flush(){for(;this._i<this._tasks.length;)this._tasks[this._i]()||this._i++;this.clear()}clear(){this._idleCallback&&=(this._cancelCallback(this._idleCallback),void 0),this._i=0,this._tasks.length=0}_start(){this._idleCallback||=this._requestCallback(this._process.bind(this))}_process(e){this._idleCallback=void 0;let t=0,n=0,r=e.timeRemaining(),i=0;for(;this._i<this._tasks.length;){if(t=performance.now(),this._tasks[this._i]()||this._i++,t=Math.max(1,performance.now()-t),n=Math.max(t,n),i=e.timeRemaining(),n*1.5>i){r-t<-20&&console.warn(`task queue exceeded allotted deadline by ${Math.abs(Math.round(r-t))}ms`),this._start();return}r=i}this.clear()}},gZ=class extends hZ{_requestCallback(e){return setTimeout(()=>e(this._createDeadline(16)))}_cancelCallback(e){clearTimeout(e)}_createDeadline(e){let t=performance.now()+e;return{timeRemaining:()=>Math.max(0,t-performance.now())}}},_Z=class extends hZ{_requestCallback(e){return requestIdleCallback(e)}_cancelCallback(e){cancelIdleCallback(e)}},vZ=!nZ&&`requestIdleCallback`in window?_Z:gZ,yZ=class{constructor(){this._queue=new vZ}set(e){this._queue.clear(),this._queue.enqueue(e)}flush(){this._queue.flush()}},bZ=class extends xq{constructor(e,t,n,r,i,a,o,s,c){super(),this._rowCount=e,this._optionsService=n,this._charSizeService=r,this._coreService=i,this._coreBrowserService=s,this._renderer=this._register(new Sq),this._pausedResizeTask=new yZ,this._observerDisposable=this._register(new Sq),this._isPaused=!1,this._needsFullRefresh=!1,this._isNextRenderRedrawOnly=!0,this._needsSelectionRefresh=!1,this._canvasWidth=0,this._canvasHeight=0,this._selectionState={start:void 0,end:void 0,columnSelectMode:!1},this._onDimensionsChange=this._register(new Vq),this.onDimensionsChange=this._onDimensionsChange.event,this._onRenderedViewportChange=this._register(new Vq),this.onRenderedViewportChange=this._onRenderedViewportChange.event,this._onRender=this._register(new Vq),this.onRender=this._onRender.event,this._onRefreshRequest=this._register(new Vq),this.onRefreshRequest=this._onRefreshRequest.event,this._renderDebouncer=new eZ((e,t)=>this._renderRows(e,t),this._coreBrowserService),this._register(this._renderDebouncer),this._syncOutputHandler=new xZ(this._coreBrowserService,this._coreService,()=>this._fullRefresh()),this._register(vq(()=>this._syncOutputHandler.dispose())),this._register(this._coreBrowserService.onDprChange(()=>this.handleDevicePixelRatioChange())),this._register(o.onResize(()=>this._fullRefresh())),this._register(o.buffers.onBufferActivate(()=>this._renderer.value?.clear())),this._register(this._optionsService.onOptionChange(()=>this._handleOptionsChanged())),this._register(this._charSizeService.onCharSizeChange(()=>this.handleCharSizeChanged())),this._register(a.onDecorationRegistered(()=>this._fullRefresh())),this._register(a.onDecorationRemoved(()=>this._fullRefresh())),this._register(this._optionsService.onMultipleOptionChange([`customGlyphs`,`drawBoldTextInBrightColors`,`letterSpacing`,`lineHeight`,`fontFamily`,`fontSize`,`fontWeight`,`fontWeightBold`,`minimumContrastRatio`,`rescaleOverlappingGlyphs`],()=>{this.clear(),this.handleResize(o.cols,o.rows),this._fullRefresh()})),this._register(this._optionsService.onMultipleOptionChange([`cursorBlink`,`cursorStyle`],()=>this.refreshRows(o.buffer.y,o.buffer.y,!0))),this._register(c.onChangeColors(()=>this._fullRefresh())),this._registerIntersectionObserver(this._coreBrowserService.window,t),this._register(this._coreBrowserService.onWindowChange(e=>this._registerIntersectionObserver(e,t)))}get dimensions(){return this._renderer.value.dimensions}_registerIntersectionObserver(e,t){if(`IntersectionObserver`in e){let n=new e.IntersectionObserver(e=>this._handleIntersectionChange(e[e.length-1]),{threshold:0});n.observe(t),this._observerDisposable.value=vq(()=>n.disconnect())}}_handleIntersectionChange(e){this._isPaused=e.isIntersecting===void 0?e.intersectionRatio===0:!e.isIntersecting,!this._isPaused&&!this._charSizeService.hasValidSize&&this._charSizeService.measure(),!this._isPaused&&this._needsFullRefresh&&(this._pausedResizeTask.flush(),this.refreshRows(0,this._rowCount-1),this._needsFullRefresh=!1)}refreshRows(e,t,n=!1){if(this._isPaused){this._needsFullRefresh=!0;return}if(this._coreService.decPrivateModes.synchronizedOutput){this._syncOutputHandler.bufferRows(e,t);return}let r=this._syncOutputHandler.flush();r&&(e=Math.min(e,r.start),t=Math.max(t,r.end)),n||(this._isNextRenderRedrawOnly=!1),this._renderDebouncer.refresh(e,t,this._rowCount)}_renderRows(e,t){if(this._renderer.value){if(this._coreService.decPrivateModes.synchronizedOutput){this._syncOutputHandler.bufferRows(e,t);return}e=Math.min(e,this._rowCount-1),t=Math.min(t,this._rowCount-1),this._renderer.value.renderRows(e,t),this._needsSelectionRefresh&&=(this._renderer.value.handleSelectionChanged(this._selectionState.start,this._selectionState.end,this._selectionState.columnSelectMode),!1),this._isNextRenderRedrawOnly||this._onRenderedViewportChange.fire({start:e,end:t}),this._onRender.fire({start:e,end:t}),this._isNextRenderRedrawOnly=!0}}resize(e,t){this._rowCount=t,this._fireOnCanvasResize()}_handleOptionsChanged(){this._renderer.value&&(this.refreshRows(0,this._rowCount-1),this._fireOnCanvasResize())}_fireOnCanvasResize(){this._renderer.value&&(this._renderer.value.dimensions.css.canvas.width===this._canvasWidth&&this._renderer.value.dimensions.css.canvas.height===this._canvasHeight||this._onDimensionsChange.fire(this._renderer.value.dimensions))}hasRenderer(){return!!this._renderer.value}setRenderer(e){this._renderer.value=e,this._renderer.value&&(this._renderer.value.onRequestRedraw(e=>this.refreshRows(e.start,e.end,!0)),this._needsSelectionRefresh=!0,this._fullRefresh())}addRefreshCallback(e){return this._renderDebouncer.addRefreshCallback(e)}_fullRefresh(){this._isPaused?this._needsFullRefresh=!0:this.refreshRows(0,this._rowCount-1)}clearTextureAtlas(){this._renderer.value&&(this._renderer.value.clearTextureAtlas?.(),this._fullRefresh())}handleDevicePixelRatioChange(){this._charSizeService.measure(),this._renderer.value&&(this._renderer.value.handleDevicePixelRatioChange(),this.refreshRows(0,this._rowCount-1))}handleResize(e,t){this._renderer.value&&(this._isPaused?this._pausedResizeTask.set(()=>this._renderer.value?.handleResize(e,t)):this._renderer.value.handleResize(e,t),this._fullRefresh())}handleCharSizeChanged(){this._renderer.value?.handleCharSizeChanged()}handleBlur(){this._renderer.value?.handleBlur()}handleFocus(){this._renderer.value?.handleFocus()}handleSelectionChanged(e,t,n){this._selectionState.start=e,this._selectionState.end=t,this._selectionState.columnSelectMode=n,this._renderer.value?.handleSelectionChanged(e,t,n)}handleCursorMove(){this._renderer.value?.handleCursorMove()}clear(){this._renderer.value?.clear()}};bZ=iK([aK(2,RK),aK(3,WK),aK(4,PK),aK(5,VK),aK(6,MK),aK(7,GK),aK(8,XK)],bZ);var xZ=class{constructor(e,t,n){this._coreBrowserService=e,this._coreService=t,this._onTimeout=n,this._start=0,this._end=0,this._isBuffering=!1}bufferRows(e,t){this._isBuffering?(this._start=Math.min(this._start,e),this._end=Math.max(this._end,t)):(this._start=e,this._end=t,this._isBuffering=!0),this._timeout===void 0&&(this._timeout=this._coreBrowserService.window.setTimeout(()=>{this._timeout=void 0,this._coreService.decPrivateModes.synchronizedOutput=!1,this._onTimeout()},1e3))}flush(){if(this._timeout!==void 0&&(this._coreBrowserService.window.clearTimeout(this._timeout),this._timeout=void 0),!this._isBuffering)return;let e={start:this._start,end:this._end};return this._isBuffering=!1,e}dispose(){this._timeout!==void 0&&(this._coreBrowserService.window.clearTimeout(this._timeout),this._timeout=void 0)}};function SZ(e,t,n,r){let i=n.buffer.x,a=n.buffer.y;if(!n.buffer.hasScrollback)return TZ(i,a,e,t,n,r)+EZ(a,t,n,r)+DZ(i,a,e,t,n,r);let o;if(a===t)return o=i>e?`D`:`C`,PZ(Math.abs(i-e),NZ(o,r));o=a>t?`D`:`C`;let s=Math.abs(a-t);return PZ(wZ(a>t?e:i,n)+(s-1)*n.cols+1+CZ(a>t?i:e,n),NZ(o,r))}function CZ(e,t){return e-1}function wZ(e,t){return t.cols-e}function TZ(e,t,n,r,i,a){return EZ(t,r,i,a).length===0?``:PZ(MZ(e,t,e,t-kZ(t,i),!1,i).length,NZ(`D`,a))}function EZ(e,t,n,r){let i=e-kZ(e,n),a=t-kZ(t,n);return PZ(Math.abs(i-a)-OZ(e,t,n),NZ(jZ(e,t),r))}function DZ(e,t,n,r,i,a){let o;o=EZ(t,r,i,a).length>0?r-kZ(r,i):t;let s=r,c=AZ(e,t,n,r,i,a);return PZ(MZ(e,o,n,s,c===`C`,i).length,NZ(c,a))}function OZ(e,t,n){let r=0,i=e-kZ(e,n),a=t-kZ(t,n);for(let o=0;o<Math.abs(i-a);o++){let a=jZ(e,t)===`A`?-1:1;n.buffer.lines.get(i+a*o)?.isWrapped&&r++}return r}function kZ(e,t){let n=0,r=t.buffer.lines.get(e),i=r?.isWrapped;for(;i&&e>=0&&e<t.rows;)n++,r=t.buffer.lines.get(--e),i=r?.isWrapped;return n}function AZ(e,t,n,r,i,a){let o;return o=EZ(n,r,i,a).length>0?r-kZ(r,i):t,e<n&&o<=r||e>=n&&o<r?`C`:`D`}function jZ(e,t){return e>t?`A`:`B`}function MZ(e,t,n,r,i,a){let o=e,s=t,c=``;for(;(o!==n||s!==r)&&s>=0&&s<a.buffer.lines.length;)o+=i?1:-1,i&&o>a.cols-1?(c+=a.buffer.translateBufferLineToString(s,!1,e,o),o=0,e=0,s++):!i&&o<0&&(c+=a.buffer.translateBufferLineToString(s,!1,0,e+1),o=a.cols-1,e=o,s--);return c+a.buffer.translateBufferLineToString(s,!1,e,o)}function NZ(e,t){let n=t?`O`:`[`;return $.ESC+n+e}function PZ(e,t){e=Math.floor(e);let n=``;for(let r=0;r<e;r++)n+=t;return n}var FZ=class{constructor(e){this._bufferService=e,this.isSelectAllActive=!1,this.selectionStartLength=0}clearSelection(){this.selectionStart=void 0,this.selectionEnd=void 0,this.isSelectAllActive=!1,this.selectionStartLength=0}get finalSelectionStart(){return this.isSelectAllActive?[0,0]:!this.selectionEnd||!this.selectionStart?this.selectionStart:this.areSelectionValuesReversed()?this.selectionEnd:this.selectionStart}get finalSelectionEnd(){if(this.isSelectAllActive)return[this._bufferService.cols,this._bufferService.buffer.ybase+this._bufferService.rows-1];if(this.selectionStart){if(!this.selectionEnd||this.areSelectionValuesReversed()){let e=this.selectionStart[0]+this.selectionStartLength;return e>this._bufferService.cols?e%this._bufferService.cols===0?[this._bufferService.cols,this.selectionStart[1]+Math.floor(e/this._bufferService.cols)-1]:[e%this._bufferService.cols,this.selectionStart[1]+Math.floor(e/this._bufferService.cols)]:[e,this.selectionStart[1]]}if(this.selectionStartLength&&this.selectionEnd[1]===this.selectionStart[1]){let e=this.selectionStart[0]+this.selectionStartLength;return e>this._bufferService.cols?[e%this._bufferService.cols,this.selectionStart[1]+Math.floor(e/this._bufferService.cols)]:[Math.max(e,this.selectionEnd[0]),this.selectionEnd[1]]}return this.selectionEnd}}areSelectionValuesReversed(){let e=this.selectionStart,t=this.selectionEnd;return!e||!t?!1:e[1]>t[1]||e[1]===t[1]&&e[0]>t[0]}handleTrim(e){return this.selectionStart&&(this.selectionStart[1]-=e),this.selectionEnd&&(this.selectionEnd[1]-=e),this.selectionEnd&&this.selectionEnd[1]<0?(this.clearSelection(),!0):(this.selectionStart&&this.selectionStart[1]<0&&(this.selectionStart[1]=0),!1)}};function IZ(e,t){if(e.start.y>e.end.y)throw Error(`Buffer range end (${e.end.x}, ${e.end.y}) cannot be before start (${e.start.x}, ${e.start.y})`);return t*(e.end.y-e.start.y)+(e.end.x-e.start.x+1)}var LZ=50,RZ=15,zZ=50,BZ=500,VZ=RegExp(`\xA0`,`g`),HZ=class extends xq{constructor(e,t,n,r,i,a,o,s,c){super(),this._element=e,this._screenElement=t,this._linkifier=n,this._bufferService=r,this._coreService=i,this._mouseService=a,this._optionsService=o,this._renderService=s,this._coreBrowserService=c,this._dragScrollAmount=0,this._enabled=!0,this._workCell=new TK,this._mouseDownTimeStamp=0,this._oldHasSelection=!1,this._oldSelectionStart=void 0,this._oldSelectionEnd=void 0,this._onLinuxMouseSelection=this._register(new Vq),this.onLinuxMouseSelection=this._onLinuxMouseSelection.event,this._onRedrawRequest=this._register(new Vq),this.onRequestRedraw=this._onRedrawRequest.event,this._onSelectionChange=this._register(new Vq),this.onSelectionChange=this._onSelectionChange.event,this._onRequestScrollLines=this._register(new Vq),this.onRequestScrollLines=this._onRequestScrollLines.event,this._mouseMoveListener=e=>this._handleMouseMove(e),this._mouseUpListener=e=>this._handleMouseUp(e),this._coreService.onUserInput(()=>{this.hasSelection&&this.clearSelection()}),this._trimListener=this._bufferService.buffer.lines.onTrim(e=>this._handleTrim(e)),this._register(this._bufferService.buffers.onBufferActivate(e=>this._handleBufferActivate(e))),this.enable(),this._model=new FZ(this._bufferService),this._activeSelectionMode=0,this._register(vq(()=>{this._removeMouseDownListeners()})),this._register(this._bufferService.onResize(e=>{e.rowsChanged&&this.clearSelection()}))}reset(){this.clearSelection()}disable(){this.clearSelection(),this._enabled=!1}enable(){this._enabled=!0}get selectionStart(){return this._model.finalSelectionStart}get selectionEnd(){return this._model.finalSelectionEnd}get hasSelection(){let e=this._model.finalSelectionStart,t=this._model.finalSelectionEnd;return!e||!t?!1:e[0]!==t[0]||e[1]!==t[1]}get selectionText(){let e=this._model.finalSelectionStart,t=this._model.finalSelectionEnd;if(!e||!t)return``;let n=this._bufferService.buffer,r=[];if(this._activeSelectionMode===3){if(e[0]===t[0])return``;let i=e[0]<t[0]?e[0]:t[0],a=e[0]<t[0]?t[0]:e[0];for(let o=e[1];o<=t[1];o++){let e=n.translateBufferLineToString(o,!0,i,a);r.push(e)}}else{let i=e[1]===t[1]?t[0]:void 0;r.push(n.translateBufferLineToString(e[1],!0,e[0],i));for(let i=e[1]+1;i<=t[1]-1;i++){let e=n.lines.get(i),t=n.translateBufferLineToString(i,!0);e?.isWrapped?r[r.length-1]+=t:r.push(t)}if(e[1]!==t[1]){let e=n.lines.get(t[1]),i=n.translateBufferLineToString(t[1],!0,0,t[0]);e&&e.isWrapped?r[r.length-1]+=i:r.push(i)}}return r.map(e=>e.replace(VZ,` `)).join(fZ?`\r
1526
+ `))}},Lq=class extends Error{constructor(e,t){super(e),this.name=`ListenerLeakError`,this.stack=t}},Rq=class extends Error{constructor(e,t){super(e),this.name=`ListenerRefusalError`,this.stack=t}},zq=0,Bq=class{constructor(e){this.value=e,this.id=zq++}},Vq=2,Hq=class{constructor(e){this._size=0,this._options=e,this._leakageMon=Nq>0||this._options?.leakWarningThreshold?new Fq(e?.onListenerError??eq,this._options?.leakWarningThreshold??Nq):void 0,this._perfMon=this._options?._profName?new Mq(this._options._profName):void 0,this._deliveryQueue=this._options?.deliveryQueue}dispose(){this._disposed||(this._disposed=!0,this._deliveryQueue?.current===this&&this._deliveryQueue.reset(),this._listeners&&(this._listeners=void 0,this._size=0),this._options?.onDidRemoveLastListener?.(),this._leakageMon?.dispose())}get event(){return this._event??=(e,t,n)=>{if(this._leakageMon&&this._size>this._leakageMon.threshold**2){let e=`[${this._leakageMon.name}] REFUSES to accept new listeners because it exceeded its threshold by far (${this._size} vs ${this._leakageMon.threshold})`;console.warn(e);let t=this._leakageMon.getMostFrequentStack()??[`UNKNOWN stack`,-1],n=new Rq(`${e}. HINT: Stack shows most frequent listener (${t[1]}-times)`,t[0]);return(this._options?.onListenerError||eq)(n),Sq.None}if(this._disposed)return Sq.None;t&&(e=e.bind(t));let r=new Bq(e),i;this._leakageMon&&this._size>=Math.ceil(this._leakageMon.threshold*.2)&&(r.stack=Iq.create(),i=this._leakageMon.check(r.stack,this._size+1)),this._listeners?this._listeners instanceof Bq?(this._deliveryQueue??=new Uq,this._listeners=[this._listeners,r]):this._listeners.push(r):(this._options?.onWillAddFirstListener?.(this),this._listeners=r,this._options?.onDidAddFirstListener?.(this)),this._size++;let a=yq(()=>{i?.(),this._removeListener(r)});return n instanceof xq?n.add(a):Array.isArray(n)&&n.push(a),a},this._event}_removeListener(e){if(this._options?.onWillRemoveListener?.(this),!this._listeners)return;if(this._size===1){this._listeners=void 0,this._options?.onDidRemoveLastListener?.(this),this._size=0;return}let t=this._listeners,n=t.indexOf(e);if(n===-1)throw console.log(`disposed?`,this._disposed),console.log(`size?`,this._size),console.log(`arr?`,JSON.stringify(this._listeners)),Error(`Attempted to dispose unknown listener`);this._size--,t[n]=void 0;let r=this._deliveryQueue.current===this;if(this._size*Vq<=t.length){let e=0;for(let n=0;n<t.length;n++)t[n]?t[e++]=t[n]:r&&(this._deliveryQueue.end--,e<this._deliveryQueue.i&&this._deliveryQueue.i--);t.length=e}}_deliver(e,t){if(!e)return;let n=this._options?.onListenerError||eq;if(!n)e.value(t);else try{e.value(t)}catch(e){n(e)}}_deliverQueue(e){let t=e.current._listeners;for(;e.i<e.end;)this._deliver(t[e.i++],e.value);e.reset()}fire(e){if(this._deliveryQueue?.current&&(this._deliverQueue(this._deliveryQueue),this._perfMon?.stop()),this._perfMon?.start(this._size),this._listeners){if(this._listeners instanceof Bq)this._deliver(this._listeners,e);else{let t=this._deliveryQueue;t.enqueue(this,e,this._listeners.length),this._deliverQueue(t)}}this._perfMon?.stop()}hasListeners(){return this._size>0}},Uq=class{constructor(){this.i=-1,this.end=0}enqueue(e,t,n){this.i=0,this.end=n,this.current=e,this.value=t}reset(){this.i=this.end,this.current=void 0,this.value=void 0}},Wq=class{constructor(){this.mapWindowIdToZoomLevel=new Map,this._onDidChangeZoomLevel=new Hq,this.onDidChangeZoomLevel=this._onDidChangeZoomLevel.event,this.mapWindowIdToZoomFactor=new Map,this._onDidChangeFullscreen=new Hq,this.onDidChangeFullscreen=this._onDidChangeFullscreen.event,this.mapWindowIdToFullScreen=new Map}getZoomLevel(e){return this.mapWindowIdToZoomLevel.get(this.getWindowId(e))??0}setZoomLevel(e,t){if(this.getZoomLevel(t)===e)return;let n=this.getWindowId(t);this.mapWindowIdToZoomLevel.set(n,e),this._onDidChangeZoomLevel.fire(n)}getZoomFactor(e){return this.mapWindowIdToZoomFactor.get(this.getWindowId(e))??1}setZoomFactor(e,t){this.mapWindowIdToZoomFactor.set(this.getWindowId(t),e)}setFullscreen(e,t){if(this.isFullscreen(t)===e)return;let n=this.getWindowId(t);this.mapWindowIdToFullScreen.set(n,e),this._onDidChangeFullscreen.fire(n)}isFullscreen(e){return!!this.mapWindowIdToFullScreen.get(this.getWindowId(e))}getWindowId(e){return e.vscodeWindowId}};Wq.INSTANCE=new Wq;var Gq=Wq;function Kq(e,t,n){typeof t==`string`&&(t=e.matchMedia(t)),t.addEventListener(`change`,n)}Gq.INSTANCE.onDidChangeZoomLevel;function qq(e){return Gq.INSTANCE.getZoomFactor(e)}Gq.INSTANCE.onDidChangeFullscreen;var Jq=typeof navigator==`object`?navigator.userAgent:``,Yq=Jq.indexOf(`Firefox`)>=0,Xq=Jq.indexOf(`AppleWebKit`)>=0,Zq=Jq.indexOf(`Chrome`)>=0,Qq=!Zq&&Jq.indexOf(`Safari`)>=0;Jq.indexOf(`Electron/`),Jq.indexOf(`Android`);var $q=!1;if(typeof wq.matchMedia==`function`){let e=wq.matchMedia(`(display-mode: standalone) or (display-mode: window-controls-overlay)`),t=wq.matchMedia(`(display-mode: fullscreen)`);$q=e.matches,Kq(wq,e,({matches:e})=>{$q&&t.matches||($q=e)})}function eJ(){return $q}var tJ=`en`,nJ=!1,rJ=!1,iJ=!1,aJ=!1,oJ=!1,sJ=tJ,cJ,lJ=globalThis,uJ;typeof lJ.vscode<`u`&&typeof lJ.vscode.process<`u`?uJ=lJ.vscode.process:typeof process<`u`&&typeof process?.versions?.node==`string`&&(uJ=process);var dJ=typeof uJ?.versions?.electron==`string`&&uJ?.type===`renderer`;if(typeof uJ==`object`){nJ=uJ.platform===`win32`,rJ=uJ.platform===`darwin`,iJ=uJ.platform===`linux`,iJ&&uJ.env.SNAP&&uJ.env.SNAP_REVISION,uJ.env.CI||uJ.env.BUILD_ARTIFACTSTAGINGDIRECTORY,sJ=tJ;let e=uJ.env.VSCODE_NLS_CONFIG;if(e)try{let t=JSON.parse(e);t.userLocale,t.osLocale,sJ=t.resolvedLanguage||tJ,t.languagePack?.translationsConfigFile}catch{}aJ=!0}else typeof navigator==`object`&&!dJ?(cJ=navigator.userAgent,nJ=cJ.indexOf(`Windows`)>=0,rJ=cJ.indexOf(`Macintosh`)>=0,(cJ.indexOf(`Macintosh`)>=0||cJ.indexOf(`iPad`)>=0||cJ.indexOf(`iPhone`)>=0)&&navigator.maxTouchPoints&&navigator.maxTouchPoints,iJ=cJ.indexOf(`Linux`)>=0,cJ?.indexOf(`Mobi`),oJ=!0,sJ=globalThis._VSCODE_NLS_LANGUAGE||tJ,navigator.language.toLowerCase()):console.error(`Unable to resolve platform.`);var fJ=nJ,pJ=rJ,mJ=iJ,hJ=aJ;oJ&&typeof lJ.importScripts==`function`&&lJ.origin;var gJ=cJ,_J=sJ,vJ;(e=>{function t(){return _J}e.value=t;function n(){return _J.length===2?_J===`en`:_J.length>=3&&_J[0]===`e`&&_J[1]===`n`&&_J[2]===`-`}e.isDefaultVariant=n;function r(){return _J===`en`}e.isDefault=r})(vJ||={});var yJ=typeof lJ.postMessage==`function`&&!lJ.importScripts;(()=>{if(yJ){let e=[];lJ.addEventListener(`message`,t=>{if(t.data&&t.data.vscodeScheduleAsyncWork)for(let n=0,r=e.length;n<r;n++){let r=e[n];if(r.id===t.data.vscodeScheduleAsyncWork){e.splice(n,1),r.callback();return}}});let t=0;return n=>{let r=++t;e.push({id:r,callback:n}),lJ.postMessage({vscodeScheduleAsyncWork:r},`*`)}}return e=>setTimeout(e)})();var bJ=!!(gJ&&gJ.indexOf(`Chrome`)>=0);gJ&&gJ.indexOf(`Firefox`),!bJ&&gJ&&gJ.indexOf(`Safari`),gJ&&gJ.indexOf(`Edg/`),gJ&&gJ.indexOf(`Android`);var xJ=typeof navigator==`object`?navigator:{};hJ||document.queryCommandSupported&&document.queryCommandSupported(`copy`)||xJ&&xJ.clipboard&&xJ.clipboard.writeText,hJ||xJ&&xJ.clipboard&&xJ.clipboard.readText,hJ||eJ()||xJ.keyboard,`ontouchstart`in wq||xJ.maxTouchPoints,wq.PointerEvent&&(`ontouchstart`in wq||navigator.maxTouchPoints);var SJ=class{constructor(){this._keyCodeToStr=[],this._strToKeyCode=Object.create(null)}define(e,t){this._keyCodeToStr[e]=t,this._strToKeyCode[t.toLowerCase()]=e}keyCodeToStr(e){return this._keyCodeToStr[e]}strToKeyCode(e){return this._strToKeyCode[e.toLowerCase()]||0}},CJ=new SJ,wJ=new SJ,TJ=new SJ,EJ=Array(230),DJ;(e=>{function t(e){return CJ.keyCodeToStr(e)}e.toString=t;function n(e){return CJ.strToKeyCode(e)}e.fromString=n;function r(e){return wJ.keyCodeToStr(e)}e.toUserSettingsUS=r;function i(e){return TJ.keyCodeToStr(e)}e.toUserSettingsGeneral=i;function a(e){return wJ.strToKeyCode(e)||TJ.strToKeyCode(e)}e.fromUserSettings=a;function o(e){if(e>=98&&e<=113)return null;switch(e){case 16:return`Up`;case 18:return`Down`;case 15:return`Left`;case 17:return`Right`}return CJ.keyCodeToStr(e)}e.toElectronAccelerator=o})(DJ||={});var OJ=class e{constructor(e,t,n,r,i){this.ctrlKey=e,this.shiftKey=t,this.altKey=n,this.metaKey=r,this.keyCode=i}equals(t){return t instanceof e&&this.ctrlKey===t.ctrlKey&&this.shiftKey===t.shiftKey&&this.altKey===t.altKey&&this.metaKey===t.metaKey&&this.keyCode===t.keyCode}getHashCode(){return`K${this.ctrlKey?`1`:`0`}${this.shiftKey?`1`:`0`}${this.altKey?`1`:`0`}${this.metaKey?`1`:`0`}${this.keyCode}`}isModifierKey(){return this.keyCode===0||this.keyCode===5||this.keyCode===57||this.keyCode===6||this.keyCode===4}toKeybinding(){return new kJ([this])}isDuplicateModifierCase(){return this.ctrlKey&&this.keyCode===5||this.shiftKey&&this.keyCode===4||this.altKey&&this.keyCode===6||this.metaKey&&this.keyCode===57}},kJ=class{constructor(e){if(e.length===0)throw iq(`chords`);this.chords=e}getHashCode(){let e=``;for(let t=0,n=this.chords.length;t<n;t++)t!==0&&(e+=`;`),e+=this.chords[t].getHashCode();return e}equals(e){if(e===null||this.chords.length!==e.chords.length)return!1;for(let t=0;t<this.chords.length;t++)if(!this.chords[t].equals(e.chords[t]))return!1;return!0}};function AJ(e){if(e.charCode){let t=String.fromCharCode(e.charCode).toUpperCase();return DJ.fromString(t)}let t=e.keyCode;if(t===3)return 7;if(Yq)switch(t){case 59:return 85;case 60:if(mJ)return 97;break;case 61:return 86;case 107:return 109;case 109:return 111;case 173:return 88;case 224:if(pJ)return 57}else if(Xq&&(pJ&&t===93||!pJ&&t===92))return 57;return EJ[t]||0}var jJ=pJ?256:2048,MJ=512,NJ=1024,PJ=pJ?2048:256,FJ=class{constructor(e){this._standardKeyboardEventBrand=!0;let t=e;this.browserEvent=t,this.target=t.target,this.ctrlKey=t.ctrlKey,this.shiftKey=t.shiftKey,this.altKey=t.altKey,this.metaKey=t.metaKey,this.altGraphKey=t.getModifierState?.(`AltGraph`),this.keyCode=AJ(t),this.code=t.code,this.ctrlKey=this.ctrlKey||this.keyCode===5,this.altKey=this.altKey||this.keyCode===6,this.shiftKey=this.shiftKey||this.keyCode===4,this.metaKey=this.metaKey||this.keyCode===57,this._asKeybinding=this._computeKeybinding(),this._asKeyCodeChord=this._computeKeyCodeChord()}preventDefault(){this.browserEvent&&this.browserEvent.preventDefault&&this.browserEvent.preventDefault()}stopPropagation(){this.browserEvent&&this.browserEvent.stopPropagation&&this.browserEvent.stopPropagation()}toKeyCodeChord(){return this._asKeyCodeChord}equals(e){return this._asKeybinding===e}_computeKeybinding(){let e=0;this.keyCode!==5&&this.keyCode!==4&&this.keyCode!==6&&this.keyCode!==57&&(e=this.keyCode);let t=0;return this.ctrlKey&&(t|=jJ),this.altKey&&(t|=MJ),this.shiftKey&&(t|=NJ),this.metaKey&&(t|=PJ),t|=e,t}_computeKeyCodeChord(){let e=0;return this.keyCode!==5&&this.keyCode!==4&&this.keyCode!==6&&this.keyCode!==57&&(e=this.keyCode),new OJ(this.ctrlKey,this.shiftKey,this.altKey,this.metaKey,e)}},IJ=new WeakMap;function LJ(e){if(!e.parent||e.parent===e)return null;try{let t=e.location,n=e.parent.location;if(t.origin!==`null`&&n.origin!==`null`&&t.origin!==n.origin)return null}catch{return null}return e.parent}var RJ=class{static getSameOriginWindowChain(e){let t=IJ.get(e);if(!t){t=[],IJ.set(e,t);let n=e,r;do r=LJ(n),r?t.push({window:new WeakRef(n),iframeElement:n.frameElement||null}):t.push({window:new WeakRef(n),iframeElement:null}),n=r;while(n)}return t.slice(0)}static getPositionOfChildWindowRelativeToAncestorWindow(e,t){if(!t||e===t)return{top:0,left:0};let n=0,r=0,i=this.getSameOriginWindowChain(e);for(let e of i){let i=e.window.deref();if(n+=i?.scrollY??0,r+=i?.scrollX??0,i===t||!e.iframeElement)break;let a=e.iframeElement.getBoundingClientRect();n+=a.top,r+=a.left}return{top:n,left:r}}},zJ=class{constructor(e,t){this.timestamp=Date.now(),this.browserEvent=t,this.leftButton=t.button===0,this.middleButton=t.button===1,this.rightButton=t.button===2,this.buttons=t.buttons,this.target=t.target,this.detail=t.detail||1,t.type===`dblclick`&&(this.detail=2),this.ctrlKey=t.ctrlKey,this.shiftKey=t.shiftKey,this.altKey=t.altKey,this.metaKey=t.metaKey,typeof t.pageX==`number`?(this.posx=t.pageX,this.posy=t.pageY):(this.posx=t.clientX+this.target.ownerDocument.body.scrollLeft+this.target.ownerDocument.documentElement.scrollLeft,this.posy=t.clientY+this.target.ownerDocument.body.scrollTop+this.target.ownerDocument.documentElement.scrollTop);let n=RJ.getPositionOfChildWindowRelativeToAncestorWindow(e,t.view);this.posx-=n.left,this.posy-=n.top}preventDefault(){this.browserEvent.preventDefault()}stopPropagation(){this.browserEvent.stopPropagation()}},BJ=class{constructor(e,t=0,n=0){this.browserEvent=e||null,this.target=e?e.target||e.targetNode||e.srcElement:null,this.deltaY=n,this.deltaX=t;let r=!1;if(Zq){let e=navigator.userAgent.match(/Chrome\/(\d+)/);r=(e?parseInt(e[1]):123)<=122}if(e){let t=e,n=e,i=e.view?.devicePixelRatio||1;if(typeof t.wheelDeltaY<`u`)this.deltaY=r?t.wheelDeltaY/(120*i):t.wheelDeltaY/120;else if(typeof n.VERTICAL_AXIS<`u`&&n.axis===n.VERTICAL_AXIS)this.deltaY=-n.detail/3;else if(e.type===`wheel`){let t=e;this.deltaY=t.deltaMode===t.DOM_DELTA_LINE?Yq&&!pJ?-e.deltaY/3:-e.deltaY:-e.deltaY/40}if(typeof t.wheelDeltaX<`u`)this.deltaX=Qq&&fJ?-(t.wheelDeltaX/120):r?t.wheelDeltaX/(120*i):t.wheelDeltaX/120;else if(typeof n.HORIZONTAL_AXIS<`u`&&n.axis===n.HORIZONTAL_AXIS)this.deltaX=-e.detail/3;else if(e.type===`wheel`){let t=e;this.deltaX=t.deltaMode===t.DOM_DELTA_LINE?Yq&&!pJ?-e.deltaX/3:-e.deltaX:-e.deltaX/40}this.deltaY===0&&this.deltaX===0&&e.wheelDelta&&(this.deltaY=r?e.wheelDelta/(120*i):e.wheelDelta/120)}}preventDefault(){this.browserEvent?.preventDefault()}stopPropagation(){this.browserEvent?.stopPropagation()}},VJ=Object.freeze(function(e,t){let n=setTimeout(e.bind(t),0);return{dispose(){clearTimeout(n)}}}),HJ;(e=>{function t(t){return t===e.None||t===e.Cancelled||t instanceof UJ?!0:!t||typeof t!=`object`?!1:typeof t.isCancellationRequested==`boolean`&&typeof t.onCancellationRequested==`function`}e.isCancellationToken=t,e.None=Object.freeze({isCancellationRequested:!1,onCancellationRequested:Aq.None}),e.Cancelled=Object.freeze({isCancellationRequested:!0,onCancellationRequested:VJ})})(HJ||={});var UJ=class{constructor(){this._isCancelled=!1,this._emitter=null}cancel(){this._isCancelled||(this._isCancelled=!0,this._emitter&&(this._emitter.fire(void 0),this.dispose()))}get isCancellationRequested(){return this._isCancelled}get onCancellationRequested(){return this._isCancelled?VJ:(this._emitter||=new Hq,this._emitter.event)}dispose(){this._emitter&&=(this._emitter.dispose(),null)}},WJ=class{constructor(e,t){this._isDisposed=!1,this._token=-1,typeof e==`function`&&typeof t==`number`&&this.setIfNotSet(e,t)}dispose(){this.cancel(),this._isDisposed=!0}cancel(){this._token!==-1&&(clearTimeout(this._token),this._token=-1)}cancelAndSet(e,t){if(this._isDisposed)throw new oq(`Calling 'cancelAndSet' on a disposed TimeoutTimer`);this.cancel(),this._token=setTimeout(()=>{this._token=-1,e()},t)}setIfNotSet(e,t){if(this._isDisposed)throw new oq(`Calling 'setIfNotSet' on a disposed TimeoutTimer`);this._token===-1&&(this._token=setTimeout(()=>{this._token=-1,e()},t))}},GJ=class{constructor(){this.disposable=void 0,this.isDisposed=!1}cancel(){this.disposable?.dispose(),this.disposable=void 0}cancelAndSet(e,t,n=globalThis){if(this.isDisposed)throw new oq(`Calling 'cancelAndSet' on a disposed IntervalTimer`);this.cancel();let r=n.setInterval(()=>{e()},t);this.disposable=yq(()=>{n.clearInterval(r),this.disposable=void 0})}dispose(){this.cancel(),this.isDisposed=!0}};(function(){typeof globalThis.requestIdleCallback!=`function`||globalThis.cancelIdleCallback})();var KJ;(e=>{async function t(e){let t,n=await Promise.all(e.map(e=>e.then(e=>e,e=>{t||=e})));if(typeof t<`u`)throw t;return n}e.settled=t;function n(e){return new Promise(async(t,n)=>{try{await e(t,n)}catch(e){n(e)}})}e.withAsyncBody=n})(KJ||={});var qJ=class e{static fromArray(t){return new e(e=>{e.emitMany(t)})}static fromPromise(t){return new e(async e=>{e.emitMany(await t)})}static fromPromises(t){return new e(async e=>{await Promise.all(t.map(async t=>e.emitOne(await t)))})}static merge(t){return new e(async e=>{await Promise.all(t.map(async t=>{for await(let n of t)e.emitOne(n)}))})}constructor(e,t){this._state=0,this._results=[],this._error=null,this._onReturn=t,this._onStateChanged=new Hq,queueMicrotask(async()=>{let t={emitOne:e=>this.emitOne(e),emitMany:e=>this.emitMany(e),reject:e=>this.reject(e)};try{await Promise.resolve(e(t)),this.resolve()}catch(e){this.reject(e)}finally{t.emitOne=void 0,t.emitMany=void 0,t.reject=void 0}})}[Symbol.asyncIterator](){let e=0;return{next:async()=>{do{if(this._state===2)throw this._error;if(e<this._results.length)return{done:!1,value:this._results[e++]};if(this._state===1)return{done:!0,value:void 0};await Aq.toPromise(this._onStateChanged.event)}while(1)},return:async()=>(this._onReturn?.(),{done:!0,value:void 0})}}static map(t,n){return new e(async e=>{for await(let r of t)e.emitOne(n(r))})}map(t){return e.map(this,t)}static filter(t,n){return new e(async e=>{for await(let r of t)n(r)&&e.emitOne(r)})}filter(t){return e.filter(this,t)}static coalesce(t){return e.filter(t,e=>!!e)}coalesce(){return e.coalesce(this)}static async toPromise(e){let t=[];for await(let n of e)t.push(n);return t}toPromise(){return e.toPromise(this)}emitOne(e){this._state===0&&(this._results.push(e),this._onStateChanged.fire())}emitMany(e){this._state===0&&(this._results=this._results.concat(e),this._onStateChanged.fire())}resolve(){this._state===0&&(this._state=1,this._onStateChanged.fire())}reject(e){this._state===0&&(this._state=2,this._error=e,this._onStateChanged.fire())}};qJ.EMPTY=qJ.fromArray([]);function JJ(e){return YJ(e,0)}function YJ(e,t){switch(typeof e){case`object`:return e===null?XJ(349,t):Array.isArray(e)?$J(e,t):eY(e,t);case`string`:return QJ(e,t);case`boolean`:return ZJ(e,t);case`number`:return XJ(e,t);case`undefined`:return XJ(937,t);default:return XJ(617,t)}}function XJ(e,t){return(t<<5)-t+e|0}function ZJ(e,t){return XJ(e?433:863,t)}function QJ(e,t){t=XJ(149417,t);for(let n=0,r=e.length;n<r;n++)t=XJ(e.charCodeAt(n),t);return t}function $J(e,t){return t=XJ(104579,t),e.reduce((e,t)=>YJ(t,e),t)}function eY(e,t){return t=XJ(181387,t),Object.keys(e).sort().reduce((t,n)=>(t=QJ(n,t),YJ(e[n],t)),t)}var{registerWindow:tY,getWindow:nY,getDocument:rY,getWindows:iY,getWindowsCount:aY,getWindowId:oY,getWindowById:sY,hasWindow:cY,onDidRegisterWindow:lY,onWillUnregisterWindow:uY,onDidUnregisterWindow:dY}=function(){let e=new Map,t={window:wq,disposables:new xq};e.set(wq.vscodeWindowId,t);let n=new Hq,r=new Hq,i=new Hq;function a(n,r){return(typeof n==`number`?e.get(n):void 0)??(r?t:void 0)}return{onDidRegisterWindow:n.event,onWillUnregisterWindow:i.event,onDidUnregisterWindow:r.event,registerWindow(t){if(e.has(t.vscodeWindowId))return Sq.None;let a=new xq,o={window:t,disposables:a.add(new xq)};return e.set(t.vscodeWindowId,o),a.add(yq(()=>{e.delete(t.vscodeWindowId),r.fire(t)})),a.add(pY(t,SY.BEFORE_UNLOAD,()=>{i.fire(t)})),n.fire(o),a},getWindows(){return e.values()},getWindowsCount(){return e.size},getWindowId(e){return e.vscodeWindowId},hasWindow(t){return e.has(t)},getWindowById:a,getWindow(e){let t=e;if(t?.ownerDocument?.defaultView)return t.ownerDocument.defaultView.window;let n=e;return n?.view?n.view.window:wq},getDocument(e){return nY(e).document}}}(),fY=class{constructor(e,t,n,r){this._node=e,this._type=t,this._handler=n,this._options=r||!1,this._node.addEventListener(this._type,this._handler,this._options)}dispose(){this._handler&&=(this._node.removeEventListener(this._type,this._handler,this._options),this._node=null,null)}};function pY(e,t,n,r){return new fY(e,t,n,r)}function mY(e,t){return function(n){return t(new zJ(e,n))}}function hY(e){return function(t){return e(new FJ(t))}}var gY=function(e,t,n,r){let i=n;return t===`click`||t===`mousedown`||t===`contextmenu`?i=mY(nY(e),n):(t===`keydown`||t===`keypress`||t===`keyup`)&&(i=hY(n)),pY(e,t,i,r)},_Y,vY=class extends GJ{constructor(e){super(),this.defaultTarget=e&&nY(e)}cancelAndSet(e,t,n){return super.cancelAndSet(e,t,n??this.defaultTarget)}},yY=class{constructor(e,t=0){this._runner=e,this.priority=t,this._canceled=!1}dispose(){this._canceled=!0}execute(){if(!this._canceled)try{this._runner()}catch(e){eq(e)}}static sort(e,t){return t.priority-e.priority}};(function(){let e=new Map,t=new Map,n=new Map,r=new Map,i=i=>{n.set(i,!1);let a=e.get(i)??[];for(t.set(i,a),e.set(i,[]),r.set(i,!0);a.length>0;)a.sort(yY.sort),a.shift().execute();r.set(i,!1)};_Y=(t,r,a=0)=>{let o=oY(t),s=new yY(r,a),c=e.get(o);return c||(c=[],e.set(o,c)),c.push(s),n.get(o)||(n.set(o,!0),t.requestAnimationFrame(()=>i(o))),s}})();var bY=class e{constructor(e,t){this.width=e,this.height=t}with(t=this.width,n=this.height){return t!==this.width||n!==this.height?new e(t,n):this}static is(e){return typeof e==`object`&&typeof e.height==`number`&&typeof e.width==`number`}static lift(t){return t instanceof e?t:new e(t.width,t.height)}static equals(e,t){return e===t?!0:!e||!t?!1:e.width===t.width&&e.height===t.height}};bY.None=new bY(0,0);function xY(e){let t=e.getBoundingClientRect(),n=nY(e);return{left:t.left+n.scrollX,top:t.top+n.scrollY,width:t.width,height:t.height}}new class{constructor(){this.mutationObservers=new Map}observe(e,t,n){let r=this.mutationObservers.get(e);r||(r=new Map,this.mutationObservers.set(e,r));let i=JJ(n),a=r.get(i);if(a)a.users+=1;else{let o=new Hq,s=new MutationObserver(e=>o.fire(e));s.observe(e,n);let c=a={users:1,observer:s,onDidMutate:o.event};t.add(yq(()=>{--c.users,c.users===0&&(o.dispose(),s.disconnect(),r?.delete(i),r?.size===0&&this.mutationObservers.delete(e))})),r.set(i,a)}return a.onDidMutate}};var SY={CLICK:`click`,AUXCLICK:`auxclick`,DBLCLICK:`dblclick`,MOUSE_UP:`mouseup`,MOUSE_DOWN:`mousedown`,MOUSE_OVER:`mouseover`,MOUSE_MOVE:`mousemove`,MOUSE_OUT:`mouseout`,MOUSE_ENTER:`mouseenter`,MOUSE_LEAVE:`mouseleave`,MOUSE_WHEEL:`wheel`,POINTER_UP:`pointerup`,POINTER_DOWN:`pointerdown`,POINTER_MOVE:`pointermove`,POINTER_LEAVE:`pointerleave`,CONTEXT_MENU:`contextmenu`,WHEEL:`wheel`,KEY_DOWN:`keydown`,KEY_PRESS:`keypress`,KEY_UP:`keyup`,LOAD:`load`,BEFORE_UNLOAD:`beforeunload`,UNLOAD:`unload`,PAGE_SHOW:`pageshow`,PAGE_HIDE:`pagehide`,PASTE:`paste`,ABORT:`abort`,ERROR:`error`,RESIZE:`resize`,SCROLL:`scroll`,FULLSCREEN_CHANGE:`fullscreenchange`,WK_FULLSCREEN_CHANGE:`webkitfullscreenchange`,SELECT:`select`,CHANGE:`change`,SUBMIT:`submit`,RESET:`reset`,FOCUS:`focus`,FOCUS_IN:`focusin`,FOCUS_OUT:`focusout`,BLUR:`blur`,INPUT:`input`,STORAGE:`storage`,DRAG_START:`dragstart`,DRAG:`drag`,DRAG_ENTER:`dragenter`,DRAG_LEAVE:`dragleave`,DRAG_OVER:`dragover`,DROP:`drop`,DRAG_END:`dragend`,ANIMATION_START:Xq?`webkitAnimationStart`:`animationstart`,ANIMATION_END:Xq?`webkitAnimationEnd`:`animationend`,ANIMATION_ITERATION:Xq?`webkitAnimationIteration`:`animationiteration`},CY=class{constructor(e){this.domNode=e,this._maxWidth=``,this._width=``,this._height=``,this._top=``,this._left=``,this._bottom=``,this._right=``,this._paddingTop=``,this._paddingLeft=``,this._paddingBottom=``,this._paddingRight=``,this._fontFamily=``,this._fontWeight=``,this._fontSize=``,this._fontStyle=``,this._fontFeatureSettings=``,this._fontVariationSettings=``,this._textDecoration=``,this._lineHeight=``,this._letterSpacing=``,this._className=``,this._display=``,this._position=``,this._visibility=``,this._color=``,this._backgroundColor=``,this._layerHint=!1,this._contain=`none`,this._boxShadow=``}setMaxWidth(e){let t=wY(e);this._maxWidth!==t&&(this._maxWidth=t,this.domNode.style.maxWidth=this._maxWidth)}setWidth(e){let t=wY(e);this._width!==t&&(this._width=t,this.domNode.style.width=this._width)}setHeight(e){let t=wY(e);this._height!==t&&(this._height=t,this.domNode.style.height=this._height)}setTop(e){let t=wY(e);this._top!==t&&(this._top=t,this.domNode.style.top=this._top)}setLeft(e){let t=wY(e);this._left!==t&&(this._left=t,this.domNode.style.left=this._left)}setBottom(e){let t=wY(e);this._bottom!==t&&(this._bottom=t,this.domNode.style.bottom=this._bottom)}setRight(e){let t=wY(e);this._right!==t&&(this._right=t,this.domNode.style.right=this._right)}setPaddingTop(e){let t=wY(e);this._paddingTop!==t&&(this._paddingTop=t,this.domNode.style.paddingTop=this._paddingTop)}setPaddingLeft(e){let t=wY(e);this._paddingLeft!==t&&(this._paddingLeft=t,this.domNode.style.paddingLeft=this._paddingLeft)}setPaddingBottom(e){let t=wY(e);this._paddingBottom!==t&&(this._paddingBottom=t,this.domNode.style.paddingBottom=this._paddingBottom)}setPaddingRight(e){let t=wY(e);this._paddingRight!==t&&(this._paddingRight=t,this.domNode.style.paddingRight=this._paddingRight)}setFontFamily(e){this._fontFamily!==e&&(this._fontFamily=e,this.domNode.style.fontFamily=this._fontFamily)}setFontWeight(e){this._fontWeight!==e&&(this._fontWeight=e,this.domNode.style.fontWeight=this._fontWeight)}setFontSize(e){let t=wY(e);this._fontSize!==t&&(this._fontSize=t,this.domNode.style.fontSize=this._fontSize)}setFontStyle(e){this._fontStyle!==e&&(this._fontStyle=e,this.domNode.style.fontStyle=this._fontStyle)}setFontFeatureSettings(e){this._fontFeatureSettings!==e&&(this._fontFeatureSettings=e,this.domNode.style.fontFeatureSettings=this._fontFeatureSettings)}setFontVariationSettings(e){this._fontVariationSettings!==e&&(this._fontVariationSettings=e,this.domNode.style.fontVariationSettings=this._fontVariationSettings)}setTextDecoration(e){this._textDecoration!==e&&(this._textDecoration=e,this.domNode.style.textDecoration=this._textDecoration)}setLineHeight(e){let t=wY(e);this._lineHeight!==t&&(this._lineHeight=t,this.domNode.style.lineHeight=this._lineHeight)}setLetterSpacing(e){let t=wY(e);this._letterSpacing!==t&&(this._letterSpacing=t,this.domNode.style.letterSpacing=this._letterSpacing)}setClassName(e){this._className!==e&&(this._className=e,this.domNode.className=this._className)}toggleClassName(e,t){this.domNode.classList.toggle(e,t),this._className=this.domNode.className}setDisplay(e){this._display!==e&&(this._display=e,this.domNode.style.display=this._display)}setPosition(e){this._position!==e&&(this._position=e,this.domNode.style.position=this._position)}setVisibility(e){this._visibility!==e&&(this._visibility=e,this.domNode.style.visibility=this._visibility)}setColor(e){this._color!==e&&(this._color=e,this.domNode.style.color=this._color)}setBackgroundColor(e){this._backgroundColor!==e&&(this._backgroundColor=e,this.domNode.style.backgroundColor=this._backgroundColor)}setLayerHinting(e){this._layerHint!==e&&(this._layerHint=e,this.domNode.style.transform=this._layerHint?`translate3d(0px, 0px, 0px)`:``)}setBoxShadow(e){this._boxShadow!==e&&(this._boxShadow=e,this.domNode.style.boxShadow=e)}setContain(e){this._contain!==e&&(this._contain=e,this.domNode.style.contain=this._contain)}setAttribute(e,t){this.domNode.setAttribute(e,t)}removeAttribute(e){this.domNode.removeAttribute(e)}appendChild(e){this.domNode.appendChild(e.domNode)}removeChild(e){this.domNode.removeChild(e.domNode)}};function wY(e){return typeof e==`number`?`${e}px`:e}function TY(e){return new CY(e)}var EY=class{constructor(){this._hooks=new xq,this._pointerMoveCallback=null,this._onStopCallback=null}dispose(){this.stopMonitoring(!1),this._hooks.dispose()}stopMonitoring(e,t){if(!this.isMonitoring())return;this._hooks.clear(),this._pointerMoveCallback=null;let n=this._onStopCallback;this._onStopCallback=null,e&&n&&n(t)}isMonitoring(){return!!this._pointerMoveCallback}startMonitoring(e,t,n,r,i){this.isMonitoring()&&this.stopMonitoring(!1),this._pointerMoveCallback=r,this._onStopCallback=i;let a=e;try{e.setPointerCapture(t),this._hooks.add(yq(()=>{try{e.releasePointerCapture(t)}catch{}}))}catch{a=nY(e)}this._hooks.add(pY(a,SY.POINTER_MOVE,e=>{e.buttons===n?(e.preventDefault(),this._pointerMoveCallback(e)):this.stopMonitoring(!0)})),this._hooks.add(pY(a,SY.POINTER_UP,e=>this.stopMonitoring(!0)))}};function DY(e,t,n){let r=null,i=null;if(typeof n.value==`function`?(r=`value`,i=n.value,i.length!==0&&console.warn(`Memoize should only be used in functions with zero parameters`)):typeof n.get==`function`&&(r=`get`,i=n.get),!i)throw Error(`not supported`);let a=`$memoize$${t}`;n[r]=function(...e){return this.hasOwnProperty(a)||Object.defineProperty(this,a,{configurable:!1,enumerable:!1,writable:!1,value:i.apply(this,e)}),this[a]}}var OY;(e=>(e.Tap=`-xterm-gesturetap`,e.Change=`-xterm-gesturechange`,e.Start=`-xterm-gesturestart`,e.End=`-xterm-gesturesend`,e.Contextmenu=`-xterm-gesturecontextmenu`))(OY||={});var kY=class e extends Sq{constructor(){super(),this.dispatched=!1,this.targets=new Dq,this.ignoreTargets=new Dq,this.activeTouches={},this.handle=null,this._lastSetTapCountTime=0,this._register(Aq.runAndSubscribe(lY,({window:e,disposables:t})=>{t.add(pY(e.document,`touchstart`,e=>this.onTouchStart(e),{passive:!1})),t.add(pY(e.document,`touchend`,t=>this.onTouchEnd(e,t))),t.add(pY(e.document,`touchmove`,e=>this.onTouchMove(e),{passive:!1}))},{window:wq,disposables:this._store}))}static addTarget(t){return e.isTouchDevice()?(e.INSTANCE||=gq(new e),yq(e.INSTANCE.targets.push(t))):Sq.None}static ignoreTarget(t){return e.isTouchDevice()?(e.INSTANCE||=gq(new e),yq(e.INSTANCE.ignoreTargets.push(t))):Sq.None}static isTouchDevice(){return`ontouchstart`in wq||navigator.maxTouchPoints>0}dispose(){this.handle&&=(this.handle.dispose(),null),super.dispose()}onTouchStart(e){let t=Date.now();this.handle&&=(this.handle.dispose(),null);for(let n=0,r=e.targetTouches.length;n<r;n++){let r=e.targetTouches.item(n);this.activeTouches[r.identifier]={id:r.identifier,initialTarget:r.target,initialTimeStamp:t,initialPageX:r.pageX,initialPageY:r.pageY,rollingTimestamps:[t],rollingPageX:[r.pageX],rollingPageY:[r.pageY]};let i=this.newGestureEvent(OY.Start,r.target);i.pageX=r.pageX,i.pageY=r.pageY,this.dispatchEvent(i)}this.dispatched&&=(e.preventDefault(),e.stopPropagation(),!1)}onTouchEnd(t,n){let r=Date.now(),i=Object.keys(this.activeTouches).length;for(let a=0,o=n.changedTouches.length;a<o;a++){let o=n.changedTouches.item(a);if(!this.activeTouches.hasOwnProperty(String(o.identifier))){console.warn(`move of an UNKNOWN touch`,o);continue}let s=this.activeTouches[o.identifier],c=Date.now()-s.initialTimeStamp;if(c<e.HOLD_DELAY&&Math.abs(s.initialPageX-sq(s.rollingPageX))<30&&Math.abs(s.initialPageY-sq(s.rollingPageY))<30){let e=this.newGestureEvent(OY.Tap,s.initialTarget);e.pageX=sq(s.rollingPageX),e.pageY=sq(s.rollingPageY),this.dispatchEvent(e)}else if(c>=e.HOLD_DELAY&&Math.abs(s.initialPageX-sq(s.rollingPageX))<30&&Math.abs(s.initialPageY-sq(s.rollingPageY))<30){let e=this.newGestureEvent(OY.Contextmenu,s.initialTarget);e.pageX=sq(s.rollingPageX),e.pageY=sq(s.rollingPageY),this.dispatchEvent(e)}else if(i===1){let e=sq(s.rollingPageX),n=sq(s.rollingPageY),i=sq(s.rollingTimestamps)-s.rollingTimestamps[0],a=e-s.rollingPageX[0],o=n-s.rollingPageY[0],c=[...this.targets].filter(e=>s.initialTarget instanceof Node&&e.contains(s.initialTarget));this.inertia(t,c,r,Math.abs(a)/i,a>0?1:-1,e,Math.abs(o)/i,o>0?1:-1,n)}this.dispatchEvent(this.newGestureEvent(OY.End,s.initialTarget)),delete this.activeTouches[o.identifier]}this.dispatched&&=(n.preventDefault(),n.stopPropagation(),!1)}newGestureEvent(e,t){let n=document.createEvent(`CustomEvent`);return n.initEvent(e,!1,!0),n.initialTarget=t,n.tapCount=0,n}dispatchEvent(t){if(t.type===OY.Tap){let n=new Date().getTime(),r=0;r=n-this._lastSetTapCountTime>e.CLEAR_TAP_COUNT_TIME?1:2,this._lastSetTapCountTime=n,t.tapCount=r}else(t.type===OY.Change||t.type===OY.Contextmenu)&&(this._lastSetTapCountTime=0);if(t.initialTarget instanceof Node){for(let e of this.ignoreTargets)if(e.contains(t.initialTarget))return;let e=[];for(let n of this.targets)if(n.contains(t.initialTarget)){let r=0,i=t.initialTarget;for(;i&&i!==n;)r++,i=i.parentElement;e.push([r,n])}e.sort((e,t)=>e[0]-t[0]);for(let[n,r]of e)r.dispatchEvent(t),this.dispatched=!0}}inertia(t,n,r,i,a,o,s,c,l){this.handle=_Y(t,()=>{let u=Date.now(),d=u-r,f=0,p=0,m=!0;i+=e.SCROLL_FRICTION*d,s+=e.SCROLL_FRICTION*d,i>0&&(m=!1,f=a*i*d),s>0&&(m=!1,p=c*s*d);let h=this.newGestureEvent(OY.Change);h.translationX=f,h.translationY=p,n.forEach(e=>e.dispatchEvent(h)),m||this.inertia(t,n,u,i,a,o+f,s,c,l+p)})}onTouchMove(e){let t=Date.now();for(let n=0,r=e.changedTouches.length;n<r;n++){let r=e.changedTouches.item(n);if(!this.activeTouches.hasOwnProperty(String(r.identifier))){console.warn(`end of an UNKNOWN touch`,r);continue}let i=this.activeTouches[r.identifier],a=this.newGestureEvent(OY.Change,i.initialTarget);a.translationX=r.pageX-sq(i.rollingPageX),a.translationY=r.pageY-sq(i.rollingPageY),a.pageX=r.pageX,a.pageY=r.pageY,this.dispatchEvent(a),i.rollingPageX.length>3&&(i.rollingPageX.shift(),i.rollingPageY.shift(),i.rollingTimestamps.shift()),i.rollingPageX.push(r.pageX),i.rollingPageY.push(r.pageY),i.rollingTimestamps.push(t)}this.dispatched&&=(e.preventDefault(),e.stopPropagation(),!1)}};kY.SCROLL_FRICTION=-.005,kY.HOLD_DELAY=700,kY.CLEAR_TAP_COUNT_TIME=400,aK([DY],kY,`isTouchDevice`,1);var AY=kY,jY=class extends Sq{onclick(e,t){this._register(pY(e,SY.CLICK,n=>t(new zJ(nY(e),n))))}onmousedown(e,t){this._register(pY(e,SY.MOUSE_DOWN,n=>t(new zJ(nY(e),n))))}onmouseover(e,t){this._register(pY(e,SY.MOUSE_OVER,n=>t(new zJ(nY(e),n))))}onmouseleave(e,t){this._register(pY(e,SY.MOUSE_LEAVE,n=>t(new zJ(nY(e),n))))}onkeydown(e,t){this._register(pY(e,SY.KEY_DOWN,e=>t(new FJ(e))))}onkeyup(e,t){this._register(pY(e,SY.KEY_UP,e=>t(new FJ(e))))}oninput(e,t){this._register(pY(e,SY.INPUT,t))}onblur(e,t){this._register(pY(e,SY.BLUR,t))}onfocus(e,t){this._register(pY(e,SY.FOCUS,t))}onchange(e,t){this._register(pY(e,SY.CHANGE,t))}ignoreGesture(e){return AY.ignoreTarget(e)}},MY=11,NY=class extends jY{constructor(e){super(),this._onActivate=e.onActivate,this.bgDomNode=document.createElement(`div`),this.bgDomNode.className=`arrow-background`,this.bgDomNode.style.position=`absolute`,this.bgDomNode.style.width=e.bgWidth+`px`,this.bgDomNode.style.height=e.bgHeight+`px`,typeof e.top<`u`&&(this.bgDomNode.style.top=`0px`),typeof e.left<`u`&&(this.bgDomNode.style.left=`0px`),typeof e.bottom<`u`&&(this.bgDomNode.style.bottom=`0px`),typeof e.right<`u`&&(this.bgDomNode.style.right=`0px`),this.domNode=document.createElement(`div`),this.domNode.className=e.className,this.domNode.style.position=`absolute`,this.domNode.style.width=MY+`px`,this.domNode.style.height=MY+`px`,typeof e.top<`u`&&(this.domNode.style.top=e.top+`px`),typeof e.left<`u`&&(this.domNode.style.left=e.left+`px`),typeof e.bottom<`u`&&(this.domNode.style.bottom=e.bottom+`px`),typeof e.right<`u`&&(this.domNode.style.right=e.right+`px`),this._pointerMoveMonitor=this._register(new EY),this._register(gY(this.bgDomNode,SY.POINTER_DOWN,e=>this._arrowPointerDown(e))),this._register(gY(this.domNode,SY.POINTER_DOWN,e=>this._arrowPointerDown(e))),this._pointerdownRepeatTimer=this._register(new vY),this._pointerdownScheduleRepeatTimer=this._register(new WJ)}_arrowPointerDown(e){e.target&&e.target instanceof Element&&(this._onActivate(),this._pointerdownRepeatTimer.cancel(),this._pointerdownScheduleRepeatTimer.cancelAndSet(()=>{this._pointerdownRepeatTimer.cancelAndSet(()=>this._onActivate(),1e3/24,nY(e))},200),this._pointerMoveMonitor.startMonitoring(e.target,e.pointerId,e.buttons,e=>{},()=>{this._pointerdownRepeatTimer.cancel(),this._pointerdownScheduleRepeatTimer.cancel()}),e.preventDefault())}},PY=class e{constructor(e,t,n,r,i,a,o){this._forceIntegerValues=e,this._scrollStateBrand=void 0,this._forceIntegerValues&&(t|=0,n|=0,r|=0,i|=0,a|=0,o|=0),this.rawScrollLeft=r,this.rawScrollTop=o,t<0&&(t=0),r+t>n&&(r=n-t),r<0&&(r=0),i<0&&(i=0),o+i>a&&(o=a-i),o<0&&(o=0),this.width=t,this.scrollWidth=n,this.scrollLeft=r,this.height=i,this.scrollHeight=a,this.scrollTop=o}equals(e){return this.rawScrollLeft===e.rawScrollLeft&&this.rawScrollTop===e.rawScrollTop&&this.width===e.width&&this.scrollWidth===e.scrollWidth&&this.scrollLeft===e.scrollLeft&&this.height===e.height&&this.scrollHeight===e.scrollHeight&&this.scrollTop===e.scrollTop}withScrollDimensions(t,n){return new e(this._forceIntegerValues,typeof t.width<`u`?t.width:this.width,typeof t.scrollWidth<`u`?t.scrollWidth:this.scrollWidth,n?this.rawScrollLeft:this.scrollLeft,typeof t.height<`u`?t.height:this.height,typeof t.scrollHeight<`u`?t.scrollHeight:this.scrollHeight,n?this.rawScrollTop:this.scrollTop)}withScrollPosition(t){return new e(this._forceIntegerValues,this.width,this.scrollWidth,typeof t.scrollLeft<`u`?t.scrollLeft:this.rawScrollLeft,this.height,this.scrollHeight,typeof t.scrollTop<`u`?t.scrollTop:this.rawScrollTop)}createScrollEvent(e,t){let n=this.width!==e.width,r=this.scrollWidth!==e.scrollWidth,i=this.scrollLeft!==e.scrollLeft,a=this.height!==e.height,o=this.scrollHeight!==e.scrollHeight,s=this.scrollTop!==e.scrollTop;return{inSmoothScrolling:t,oldWidth:e.width,oldScrollWidth:e.scrollWidth,oldScrollLeft:e.scrollLeft,width:this.width,scrollWidth:this.scrollWidth,scrollLeft:this.scrollLeft,oldHeight:e.height,oldScrollHeight:e.scrollHeight,oldScrollTop:e.scrollTop,height:this.height,scrollHeight:this.scrollHeight,scrollTop:this.scrollTop,widthChanged:n,scrollWidthChanged:r,scrollLeftChanged:i,heightChanged:a,scrollHeightChanged:o,scrollTopChanged:s}}},FY=class extends Sq{constructor(e){super(),this._scrollableBrand=void 0,this._onScroll=this._register(new Hq),this.onScroll=this._onScroll.event,this._smoothScrollDuration=e.smoothScrollDuration,this._scheduleAtNextAnimationFrame=e.scheduleAtNextAnimationFrame,this._state=new PY(e.forceIntegerValues,0,0,0,0,0,0),this._smoothScrolling=null}dispose(){this._smoothScrolling&&=(this._smoothScrolling.dispose(),null),super.dispose()}setSmoothScrollDuration(e){this._smoothScrollDuration=e}validateScrollPosition(e){return this._state.withScrollPosition(e)}getScrollDimensions(){return this._state}setScrollDimensions(e,t){let n=this._state.withScrollDimensions(e,t);this._setState(n,!!this._smoothScrolling),this._smoothScrolling?.acceptScrollDimensions(this._state)}getFutureScrollPosition(){return this._smoothScrolling?this._smoothScrolling.to:this._state}getCurrentScrollPosition(){return this._state}setScrollPositionNow(e){let t=this._state.withScrollPosition(e);this._smoothScrolling&&=(this._smoothScrolling.dispose(),null),this._setState(t,!1)}setScrollPositionSmooth(e,t){if(this._smoothScrollDuration===0)return this.setScrollPositionNow(e);if(this._smoothScrolling){e={scrollLeft:typeof e.scrollLeft>`u`?this._smoothScrolling.to.scrollLeft:e.scrollLeft,scrollTop:typeof e.scrollTop>`u`?this._smoothScrolling.to.scrollTop:e.scrollTop};let n=this._state.withScrollPosition(e);if(this._smoothScrolling.to.scrollLeft===n.scrollLeft&&this._smoothScrolling.to.scrollTop===n.scrollTop)return;let r;r=t?new zY(this._smoothScrolling.from,n,this._smoothScrolling.startTime,this._smoothScrolling.duration):this._smoothScrolling.combine(this._state,n,this._smoothScrollDuration),this._smoothScrolling.dispose(),this._smoothScrolling=r}else{let t=this._state.withScrollPosition(e);this._smoothScrolling=zY.start(this._state,t,this._smoothScrollDuration)}this._smoothScrolling.animationFrameDisposable=this._scheduleAtNextAnimationFrame(()=>{this._smoothScrolling&&(this._smoothScrolling.animationFrameDisposable=null,this._performSmoothScrolling())})}hasPendingScrollAnimation(){return!!this._smoothScrolling}_performSmoothScrolling(){if(!this._smoothScrolling)return;let e=this._smoothScrolling.tick(),t=this._state.withScrollPosition(e);if(this._setState(t,!0),this._smoothScrolling){if(e.isDone){this._smoothScrolling.dispose(),this._smoothScrolling=null;return}this._smoothScrolling.animationFrameDisposable=this._scheduleAtNextAnimationFrame(()=>{this._smoothScrolling&&(this._smoothScrolling.animationFrameDisposable=null,this._performSmoothScrolling())})}}_setState(e,t){let n=this._state;n.equals(e)||(this._state=e,this._onScroll.fire(this._state.createScrollEvent(n,t)))}},IY=class{constructor(e,t,n){this.scrollLeft=e,this.scrollTop=t,this.isDone=n}};function LY(e,t){let n=t-e;return function(t){return e+n*VY(t)}}function RY(e,t,n){return function(r){return r<n?e(r/n):t((r-n)/(1-n))}}var zY=class e{constructor(e,t,n,r){this.from=e,this.to=t,this.duration=r,this.startTime=n,this.animationFrameDisposable=null,this._initAnimations()}_initAnimations(){this.scrollLeft=this._initAnimation(this.from.scrollLeft,this.to.scrollLeft,this.to.width),this.scrollTop=this._initAnimation(this.from.scrollTop,this.to.scrollTop,this.to.height)}_initAnimation(e,t,n){if(Math.abs(e-t)>2.5*n){let r,i;return e<t?(r=e+.75*n,i=t-.75*n):(r=e-.75*n,i=t+.75*n),RY(LY(e,r),LY(i,t),.33)}return LY(e,t)}dispose(){this.animationFrameDisposable!==null&&(this.animationFrameDisposable.dispose(),this.animationFrameDisposable=null)}acceptScrollDimensions(e){this.to=e.withScrollPosition(this.to),this._initAnimations()}tick(){return this._tick(Date.now())}_tick(e){let t=(e-this.startTime)/this.duration;return t<1?new IY(this.scrollLeft(t),this.scrollTop(t),!1):new IY(this.to.scrollLeft,this.to.scrollTop,!0)}combine(t,n,r){return e.start(t,n,r)}static start(t,n,r){r+=10;let i=Date.now()-10;return new e(t,n,i,r)}};function BY(e){return e**3}function VY(e){return 1-BY(1-e)}var HY=class extends Sq{constructor(e,t,n){super(),this._visibility=e,this._visibleClassName=t,this._invisibleClassName=n,this._domNode=null,this._isVisible=!1,this._isNeeded=!1,this._rawShouldBeVisible=!1,this._shouldBeVisible=!1,this._revealTimer=this._register(new WJ)}setVisibility(e){this._visibility!==e&&(this._visibility=e,this._updateShouldBeVisible())}setShouldBeVisible(e){this._rawShouldBeVisible=e,this._updateShouldBeVisible()}_applyVisibilitySetting(){return this._visibility===2?!1:this._visibility===3||this._rawShouldBeVisible}_updateShouldBeVisible(){let e=this._applyVisibilitySetting();this._shouldBeVisible!==e&&(this._shouldBeVisible=e,this.ensureVisibility())}setIsNeeded(e){this._isNeeded!==e&&(this._isNeeded=e,this.ensureVisibility())}setDomNode(e){this._domNode=e,this._domNode.setClassName(this._invisibleClassName),this.setShouldBeVisible(!1)}ensureVisibility(){this._isNeeded?this._shouldBeVisible?this._reveal():this._hide(!0):this._hide(!1)}_reveal(){this._isVisible||(this._isVisible=!0,this._revealTimer.setIfNotSet(()=>{this._domNode?.setClassName(this._visibleClassName)},0))}_hide(e){this._revealTimer.cancel(),this._isVisible&&(this._isVisible=!1,this._domNode?.setClassName(this._invisibleClassName+(e?` fade`:``)))}},UY=140,WY=class extends jY{constructor(e){super(),this._lazyRender=e.lazyRender,this._host=e.host,this._scrollable=e.scrollable,this._scrollByPage=e.scrollByPage,this._scrollbarState=e.scrollbarState,this._visibilityController=this._register(new HY(e.visibility,`visible scrollbar `+e.extraScrollbarClassName,`invisible scrollbar `+e.extraScrollbarClassName)),this._visibilityController.setIsNeeded(this._scrollbarState.isNeeded()),this._pointerMoveMonitor=this._register(new EY),this._shouldRender=!0,this.domNode=TY(document.createElement(`div`)),this.domNode.setAttribute(`role`,`presentation`),this.domNode.setAttribute(`aria-hidden`,`true`),this._visibilityController.setDomNode(this.domNode),this.domNode.setPosition(`absolute`),this._register(pY(this.domNode.domNode,SY.POINTER_DOWN,e=>this._domNodePointerDown(e)))}_createArrow(e){let t=this._register(new NY(e));this.domNode.domNode.appendChild(t.bgDomNode),this.domNode.domNode.appendChild(t.domNode)}_createSlider(e,t,n,r){this.slider=TY(document.createElement(`div`)),this.slider.setClassName(`slider`),this.slider.setPosition(`absolute`),this.slider.setTop(e),this.slider.setLeft(t),typeof n==`number`&&this.slider.setWidth(n),typeof r==`number`&&this.slider.setHeight(r),this.slider.setLayerHinting(!0),this.slider.setContain(`strict`),this.domNode.domNode.appendChild(this.slider.domNode),this._register(pY(this.slider.domNode,SY.POINTER_DOWN,e=>{e.button===0&&(e.preventDefault(),this._sliderPointerDown(e))})),this.onclick(this.slider.domNode,e=>{e.leftButton&&e.stopPropagation()})}_onElementSize(e){return this._scrollbarState.setVisibleSize(e)&&(this._visibilityController.setIsNeeded(this._scrollbarState.isNeeded()),this._shouldRender=!0,this._lazyRender||this.render()),this._shouldRender}_onElementScrollSize(e){return this._scrollbarState.setScrollSize(e)&&(this._visibilityController.setIsNeeded(this._scrollbarState.isNeeded()),this._shouldRender=!0,this._lazyRender||this.render()),this._shouldRender}_onElementScrollPosition(e){return this._scrollbarState.setScrollPosition(e)&&(this._visibilityController.setIsNeeded(this._scrollbarState.isNeeded()),this._shouldRender=!0,this._lazyRender||this.render()),this._shouldRender}beginReveal(){this._visibilityController.setShouldBeVisible(!0)}beginHide(){this._visibilityController.setShouldBeVisible(!1)}render(){this._shouldRender&&(this._shouldRender=!1,this._renderDomNode(this._scrollbarState.getRectangleLargeSize(),this._scrollbarState.getRectangleSmallSize()),this._updateSlider(this._scrollbarState.getSliderSize(),this._scrollbarState.getArrowSize()+this._scrollbarState.getSliderPosition()))}_domNodePointerDown(e){e.target===this.domNode.domNode&&this._onPointerDown(e)}delegatePointerDown(e){let t=this.domNode.domNode.getClientRects()[0].top,n=t+this._scrollbarState.getSliderPosition(),r=t+this._scrollbarState.getSliderPosition()+this._scrollbarState.getSliderSize(),i=this._sliderPointerPosition(e);n<=i&&i<=r?e.button===0&&(e.preventDefault(),this._sliderPointerDown(e)):this._onPointerDown(e)}_onPointerDown(e){let t,n;if(e.target===this.domNode.domNode&&typeof e.offsetX==`number`&&typeof e.offsetY==`number`)t=e.offsetX,n=e.offsetY;else{let r=xY(this.domNode.domNode);t=e.pageX-r.left,n=e.pageY-r.top}let r=this._pointerDownRelativePosition(t,n);this._setDesiredScrollPositionNow(this._scrollByPage?this._scrollbarState.getDesiredScrollPositionFromOffsetPaged(r):this._scrollbarState.getDesiredScrollPositionFromOffset(r)),e.button===0&&(e.preventDefault(),this._sliderPointerDown(e))}_sliderPointerDown(e){if(!e.target||!(e.target instanceof Element))return;let t=this._sliderPointerPosition(e),n=this._sliderOrthogonalPointerPosition(e),r=this._scrollbarState.clone();this.slider.toggleClassName(`active`,!0),this._pointerMoveMonitor.startMonitoring(e.target,e.pointerId,e.buttons,e=>{let i=this._sliderOrthogonalPointerPosition(e),a=Math.abs(i-n);if(fJ&&a>UY){this._setDesiredScrollPositionNow(r.getScrollPosition());return}let o=this._sliderPointerPosition(e)-t;this._setDesiredScrollPositionNow(r.getDesiredScrollPositionFromDelta(o))},()=>{this.slider.toggleClassName(`active`,!1),this._host.onDragEnd()}),this._host.onDragStart()}_setDesiredScrollPositionNow(e){let t={};this.writeScrollPosition(t,e),this._scrollable.setScrollPositionNow(t)}updateScrollbarSize(e){this._updateScrollbarSize(e),this._scrollbarState.setScrollbarSize(e),this._shouldRender=!0,this._lazyRender||this.render()}isNeeded(){return this._scrollbarState.isNeeded()}},GY=class e{constructor(e,t,n,r,i,a){this._scrollbarSize=Math.round(t),this._oppositeScrollbarSize=Math.round(n),this._arrowSize=Math.round(e),this._visibleSize=r,this._scrollSize=i,this._scrollPosition=a,this._computedAvailableSize=0,this._computedIsNeeded=!1,this._computedSliderSize=0,this._computedSliderRatio=0,this._computedSliderPosition=0,this._refreshComputedValues()}clone(){return new e(this._arrowSize,this._scrollbarSize,this._oppositeScrollbarSize,this._visibleSize,this._scrollSize,this._scrollPosition)}setVisibleSize(e){let t=Math.round(e);return this._visibleSize!==t&&(this._visibleSize=t,this._refreshComputedValues(),!0)}setScrollSize(e){let t=Math.round(e);return this._scrollSize!==t&&(this._scrollSize=t,this._refreshComputedValues(),!0)}setScrollPosition(e){let t=Math.round(e);return this._scrollPosition!==t&&(this._scrollPosition=t,this._refreshComputedValues(),!0)}setScrollbarSize(e){this._scrollbarSize=Math.round(e)}setOppositeScrollbarSize(e){this._oppositeScrollbarSize=Math.round(e)}static _computeValues(e,t,n,r,i){let a=Math.max(0,n-e),o=Math.max(0,a-2*t),s=r>0&&r>n;if(!s)return{computedAvailableSize:Math.round(a),computedIsNeeded:s,computedSliderSize:Math.round(o),computedSliderRatio:0,computedSliderPosition:0};let c=Math.round(Math.max(20,Math.floor(n*o/r))),l=(o-c)/(r-n),u=i*l;return{computedAvailableSize:Math.round(a),computedIsNeeded:s,computedSliderSize:Math.round(c),computedSliderRatio:l,computedSliderPosition:Math.round(u)}}_refreshComputedValues(){let t=e._computeValues(this._oppositeScrollbarSize,this._arrowSize,this._visibleSize,this._scrollSize,this._scrollPosition);this._computedAvailableSize=t.computedAvailableSize,this._computedIsNeeded=t.computedIsNeeded,this._computedSliderSize=t.computedSliderSize,this._computedSliderRatio=t.computedSliderRatio,this._computedSliderPosition=t.computedSliderPosition}getArrowSize(){return this._arrowSize}getScrollPosition(){return this._scrollPosition}getRectangleLargeSize(){return this._computedAvailableSize}getRectangleSmallSize(){return this._scrollbarSize}isNeeded(){return this._computedIsNeeded}getSliderSize(){return this._computedSliderSize}getSliderPosition(){return this._computedSliderPosition}getDesiredScrollPositionFromOffset(e){if(!this._computedIsNeeded)return 0;let t=e-this._arrowSize-this._computedSliderSize/2;return Math.round(t/this._computedSliderRatio)}getDesiredScrollPositionFromOffsetPaged(e){if(!this._computedIsNeeded)return 0;let t=e-this._arrowSize,n=this._scrollPosition;return t<this._computedSliderPosition?n-=this._visibleSize:n+=this._visibleSize,n}getDesiredScrollPositionFromDelta(e){if(!this._computedIsNeeded)return 0;let t=this._computedSliderPosition+e;return Math.round(t/this._computedSliderRatio)}},KY=class extends WY{constructor(e,t,n){let r=e.getScrollDimensions(),i=e.getCurrentScrollPosition();if(super({lazyRender:t.lazyRender,host:n,scrollbarState:new GY(t.horizontalHasArrows?t.arrowSize:0,t.horizontal===2?0:t.horizontalScrollbarSize,t.vertical===2?0:t.verticalScrollbarSize,r.width,r.scrollWidth,i.scrollLeft),visibility:t.horizontal,extraScrollbarClassName:`horizontal`,scrollable:e,scrollByPage:t.scrollByPage}),t.horizontalHasArrows)throw Error(`horizontalHasArrows is not supported in xterm.js`);this._createSlider(Math.floor((t.horizontalScrollbarSize-t.horizontalSliderSize)/2),0,void 0,t.horizontalSliderSize)}_updateSlider(e,t){this.slider.setWidth(e),this.slider.setLeft(t)}_renderDomNode(e,t){this.domNode.setWidth(e),this.domNode.setHeight(t),this.domNode.setLeft(0),this.domNode.setBottom(0)}onDidScroll(e){return this._shouldRender=this._onElementScrollSize(e.scrollWidth)||this._shouldRender,this._shouldRender=this._onElementScrollPosition(e.scrollLeft)||this._shouldRender,this._shouldRender=this._onElementSize(e.width)||this._shouldRender,this._shouldRender}_pointerDownRelativePosition(e,t){return e}_sliderPointerPosition(e){return e.pageX}_sliderOrthogonalPointerPosition(e){return e.pageY}_updateScrollbarSize(e){this.slider.setHeight(e)}writeScrollPosition(e,t){e.scrollLeft=t}updateOptions(e){this.updateScrollbarSize(e.horizontal===2?0:e.horizontalScrollbarSize),this._scrollbarState.setOppositeScrollbarSize(e.vertical===2?0:e.verticalScrollbarSize),this._visibilityController.setVisibility(e.horizontal),this._scrollByPage=e.scrollByPage}},qY=class extends WY{constructor(e,t,n){let r=e.getScrollDimensions(),i=e.getCurrentScrollPosition();if(super({lazyRender:t.lazyRender,host:n,scrollbarState:new GY(t.verticalHasArrows?t.arrowSize:0,t.vertical===2?0:t.verticalScrollbarSize,0,r.height,r.scrollHeight,i.scrollTop),visibility:t.vertical,extraScrollbarClassName:`vertical`,scrollable:e,scrollByPage:t.scrollByPage}),t.verticalHasArrows)throw Error(`horizontalHasArrows is not supported in xterm.js`);this._createSlider(0,Math.floor((t.verticalScrollbarSize-t.verticalSliderSize)/2),t.verticalSliderSize,void 0)}_updateSlider(e,t){this.slider.setHeight(e),this.slider.setTop(t)}_renderDomNode(e,t){this.domNode.setWidth(t),this.domNode.setHeight(e),this.domNode.setRight(0),this.domNode.setTop(0)}onDidScroll(e){return this._shouldRender=this._onElementScrollSize(e.scrollHeight)||this._shouldRender,this._shouldRender=this._onElementScrollPosition(e.scrollTop)||this._shouldRender,this._shouldRender=this._onElementSize(e.height)||this._shouldRender,this._shouldRender}_pointerDownRelativePosition(e,t){return t}_sliderPointerPosition(e){return e.pageY}_sliderOrthogonalPointerPosition(e){return e.pageX}_updateScrollbarSize(e){this.slider.setWidth(e)}writeScrollPosition(e,t){e.scrollTop=t}updateOptions(e){this.updateScrollbarSize(e.vertical===2?0:e.verticalScrollbarSize),this._scrollbarState.setOppositeScrollbarSize(0),this._visibilityController.setVisibility(e.vertical),this._scrollByPage=e.scrollByPage}},JY=500,YY=50,XY=!0,ZY=class{constructor(e,t,n){this.timestamp=e,this.deltaX=t,this.deltaY=n,this.score=0}},QY=class{constructor(){this._capacity=5,this._memory=[],this._front=-1,this._rear=-1}isPhysicalMouseWheel(){if(this._front===-1&&this._rear===-1)return!1;let e=1,t=0,n=1,r=this._rear;do{let i=r===this._front?e:2**-n;if(e-=i,t+=this._memory[r].score*i,r===this._front)break;r=(this._capacity+r-1)%this._capacity,n++}while(1);return t<=.5}acceptStandardWheelEvent(e){if(Zq){let t=qq(nY(e.browserEvent));this.accept(Date.now(),e.deltaX*t,e.deltaY*t)}else this.accept(Date.now(),e.deltaX,e.deltaY)}accept(e,t,n){let r=null,i=new ZY(e,t,n);this._front===-1&&this._rear===-1?(this._memory[0]=i,this._front=0,this._rear=0):(r=this._memory[this._rear],this._rear=(this._rear+1)%this._capacity,this._rear===this._front&&(this._front=(this._front+1)%this._capacity),this._memory[this._rear]=i),i.score=this._computeScore(i,r)}_computeScore(e,t){if(Math.abs(e.deltaX)>0&&Math.abs(e.deltaY)>0)return 1;let n=.5;if((!this._isAlmostInt(e.deltaX)||!this._isAlmostInt(e.deltaY))&&(n+=.25),t){let r=Math.abs(e.deltaX),i=Math.abs(e.deltaY),a=Math.abs(t.deltaX),o=Math.abs(t.deltaY),s=Math.max(Math.min(r,a),1),c=Math.max(Math.min(i,o),1),l=Math.max(r,a),u=Math.max(i,o);l%s===0&&u%c===0&&(n-=.5)}return Math.min(Math.max(n,0),1)}_isAlmostInt(e){return Math.abs(Math.round(e)-e)<.01}};QY.INSTANCE=new QY;var $Y=QY,eX=class extends jY{constructor(e,t,n){super(),this._onScroll=this._register(new Hq),this.onScroll=this._onScroll.event,this._onWillScroll=this._register(new Hq),this.onWillScroll=this._onWillScroll.event,this._options=nX(t),this._scrollable=n,this._register(this._scrollable.onScroll(e=>{this._onWillScroll.fire(e),this._onDidScroll(e),this._onScroll.fire(e)}));let r={onMouseWheel:e=>this._onMouseWheel(e),onDragStart:()=>this._onDragStart(),onDragEnd:()=>this._onDragEnd()};this._verticalScrollbar=this._register(new qY(this._scrollable,this._options,r)),this._horizontalScrollbar=this._register(new KY(this._scrollable,this._options,r)),this._domNode=document.createElement(`div`),this._domNode.className=`xterm-scrollable-element `+this._options.className,this._domNode.setAttribute(`role`,`presentation`),this._domNode.style.position=`relative`,this._domNode.appendChild(e),this._domNode.appendChild(this._horizontalScrollbar.domNode.domNode),this._domNode.appendChild(this._verticalScrollbar.domNode.domNode),this._options.useShadows?(this._leftShadowDomNode=TY(document.createElement(`div`)),this._leftShadowDomNode.setClassName(`shadow`),this._domNode.appendChild(this._leftShadowDomNode.domNode),this._topShadowDomNode=TY(document.createElement(`div`)),this._topShadowDomNode.setClassName(`shadow`),this._domNode.appendChild(this._topShadowDomNode.domNode),this._topLeftShadowDomNode=TY(document.createElement(`div`)),this._topLeftShadowDomNode.setClassName(`shadow`),this._domNode.appendChild(this._topLeftShadowDomNode.domNode)):(this._leftShadowDomNode=null,this._topShadowDomNode=null,this._topLeftShadowDomNode=null),this._listenOnDomNode=this._options.listenOnDomNode||this._domNode,this._mouseWheelToDispose=[],this._setListeningToMouseWheel(this._options.handleMouseWheel),this.onmouseover(this._listenOnDomNode,e=>this._onMouseOver(e)),this.onmouseleave(this._listenOnDomNode,e=>this._onMouseLeave(e)),this._hideTimeout=this._register(new WJ),this._isDragging=!1,this._mouseIsOver=!1,this._shouldRender=!0,this._revealOnScroll=!0}get options(){return this._options}dispose(){this._mouseWheelToDispose=_q(this._mouseWheelToDispose),super.dispose()}getDomNode(){return this._domNode}getOverviewRulerLayoutInfo(){return{parent:this._domNode,insertBefore:this._verticalScrollbar.domNode.domNode}}delegateVerticalScrollbarPointerDown(e){this._verticalScrollbar.delegatePointerDown(e)}getScrollDimensions(){return this._scrollable.getScrollDimensions()}setScrollDimensions(e){this._scrollable.setScrollDimensions(e,!1)}updateClassName(e){this._options.className=e,pJ&&(this._options.className+=` mac`),this._domNode.className=`xterm-scrollable-element `+this._options.className}updateOptions(e){typeof e.handleMouseWheel<`u`&&(this._options.handleMouseWheel=e.handleMouseWheel,this._setListeningToMouseWheel(this._options.handleMouseWheel)),typeof e.mouseWheelScrollSensitivity<`u`&&(this._options.mouseWheelScrollSensitivity=e.mouseWheelScrollSensitivity),typeof e.fastScrollSensitivity<`u`&&(this._options.fastScrollSensitivity=e.fastScrollSensitivity),typeof e.scrollPredominantAxis<`u`&&(this._options.scrollPredominantAxis=e.scrollPredominantAxis),typeof e.horizontal<`u`&&(this._options.horizontal=e.horizontal),typeof e.vertical<`u`&&(this._options.vertical=e.vertical),typeof e.horizontalScrollbarSize<`u`&&(this._options.horizontalScrollbarSize=e.horizontalScrollbarSize),typeof e.verticalScrollbarSize<`u`&&(this._options.verticalScrollbarSize=e.verticalScrollbarSize),typeof e.scrollByPage<`u`&&(this._options.scrollByPage=e.scrollByPage),this._horizontalScrollbar.updateOptions(this._options),this._verticalScrollbar.updateOptions(this._options),this._options.lazyRender||this._render()}setRevealOnScroll(e){this._revealOnScroll=e}delegateScrollFromMouseWheelEvent(e){this._onMouseWheel(new BJ(e))}_setListeningToMouseWheel(e){this._mouseWheelToDispose.length>0!==e&&(this._mouseWheelToDispose=_q(this._mouseWheelToDispose),e)&&this._mouseWheelToDispose.push(pY(this._listenOnDomNode,SY.MOUSE_WHEEL,e=>{this._onMouseWheel(new BJ(e))},{passive:!1}))}_onMouseWheel(e){if(e.browserEvent?.defaultPrevented)return;let t=$Y.INSTANCE;XY&&t.acceptStandardWheelEvent(e);let n=!1;if(e.deltaY||e.deltaX){let r=e.deltaY*this._options.mouseWheelScrollSensitivity,i=e.deltaX*this._options.mouseWheelScrollSensitivity;this._options.scrollPredominantAxis&&(this._options.scrollYToX&&i+r===0?i=r=0:Math.abs(r)>=Math.abs(i)?i=0:r=0),this._options.flipAxes&&([r,i]=[i,r]);let a=!pJ&&e.browserEvent&&e.browserEvent.shiftKey;(this._options.scrollYToX||a)&&!i&&(i=r,r=0),e.browserEvent&&e.browserEvent.altKey&&(i*=this._options.fastScrollSensitivity,r*=this._options.fastScrollSensitivity);let o=this._scrollable.getFutureScrollPosition(),s={};if(r){let e=YY*r,t=o.scrollTop-(e<0?Math.floor(e):Math.ceil(e));this._verticalScrollbar.writeScrollPosition(s,t)}if(i){let e=YY*i,t=o.scrollLeft-(e<0?Math.floor(e):Math.ceil(e));this._horizontalScrollbar.writeScrollPosition(s,t)}s=this._scrollable.validateScrollPosition(s),(o.scrollLeft!==s.scrollLeft||o.scrollTop!==s.scrollTop)&&(XY&&this._options.mouseWheelSmoothScroll&&t.isPhysicalMouseWheel()?this._scrollable.setScrollPositionSmooth(s):this._scrollable.setScrollPositionNow(s),n=!0)}let r=n;!r&&this._options.alwaysConsumeMouseWheel&&(r=!0),!r&&this._options.consumeMouseWheelIfScrollbarIsNeeded&&(this._verticalScrollbar.isNeeded()||this._horizontalScrollbar.isNeeded())&&(r=!0),r&&(e.preventDefault(),e.stopPropagation())}_onDidScroll(e){this._shouldRender=this._horizontalScrollbar.onDidScroll(e)||this._shouldRender,this._shouldRender=this._verticalScrollbar.onDidScroll(e)||this._shouldRender,this._options.useShadows&&(this._shouldRender=!0),this._revealOnScroll&&this._reveal(),this._options.lazyRender||this._render()}renderNow(){if(!this._options.lazyRender)throw Error("Please use `lazyRender` together with `renderNow`!");this._render()}_render(){if(this._shouldRender&&(this._shouldRender=!1,this._horizontalScrollbar.render(),this._verticalScrollbar.render(),this._options.useShadows)){let e=this._scrollable.getCurrentScrollPosition(),t=e.scrollTop>0,n=e.scrollLeft>0,r=n?` left`:``,i=t?` top`:``,a=n||t?` top-left-corner`:``;this._leftShadowDomNode.setClassName(`shadow${r}`),this._topShadowDomNode.setClassName(`shadow${i}`),this._topLeftShadowDomNode.setClassName(`shadow${a}${i}${r}`)}}_onDragStart(){this._isDragging=!0,this._reveal()}_onDragEnd(){this._isDragging=!1,this._hide()}_onMouseLeave(e){this._mouseIsOver=!1,this._hide()}_onMouseOver(e){this._mouseIsOver=!0,this._reveal()}_reveal(){this._verticalScrollbar.beginReveal(),this._horizontalScrollbar.beginReveal(),this._scheduleHide()}_hide(){!this._mouseIsOver&&!this._isDragging&&(this._verticalScrollbar.beginHide(),this._horizontalScrollbar.beginHide())}_scheduleHide(){!this._mouseIsOver&&!this._isDragging&&this._hideTimeout.cancelAndSet(()=>this._hide(),JY)}},tX=class extends eX{constructor(e,t,n){super(e,t,n)}setScrollPosition(e){e.reuseAnimation?this._scrollable.setScrollPositionSmooth(e,e.reuseAnimation):this._scrollable.setScrollPositionNow(e)}getScrollPosition(){return this._scrollable.getCurrentScrollPosition()}};function nX(e){let t={lazyRender:typeof e.lazyRender<`u`&&e.lazyRender,className:typeof e.className<`u`?e.className:``,useShadows:typeof e.useShadows<`u`?e.useShadows:!0,handleMouseWheel:typeof e.handleMouseWheel<`u`?e.handleMouseWheel:!0,flipAxes:typeof e.flipAxes<`u`&&e.flipAxes,consumeMouseWheelIfScrollbarIsNeeded:typeof e.consumeMouseWheelIfScrollbarIsNeeded<`u`&&e.consumeMouseWheelIfScrollbarIsNeeded,alwaysConsumeMouseWheel:typeof e.alwaysConsumeMouseWheel<`u`&&e.alwaysConsumeMouseWheel,scrollYToX:typeof e.scrollYToX<`u`&&e.scrollYToX,mouseWheelScrollSensitivity:typeof e.mouseWheelScrollSensitivity<`u`?e.mouseWheelScrollSensitivity:1,fastScrollSensitivity:typeof e.fastScrollSensitivity<`u`?e.fastScrollSensitivity:5,scrollPredominantAxis:typeof e.scrollPredominantAxis<`u`?e.scrollPredominantAxis:!0,mouseWheelSmoothScroll:typeof e.mouseWheelSmoothScroll<`u`?e.mouseWheelSmoothScroll:!0,arrowSize:typeof e.arrowSize<`u`?e.arrowSize:11,listenOnDomNode:typeof e.listenOnDomNode<`u`?e.listenOnDomNode:null,horizontal:typeof e.horizontal<`u`?e.horizontal:1,horizontalScrollbarSize:typeof e.horizontalScrollbarSize<`u`?e.horizontalScrollbarSize:10,horizontalSliderSize:typeof e.horizontalSliderSize<`u`?e.horizontalSliderSize:0,horizontalHasArrows:typeof e.horizontalHasArrows<`u`&&e.horizontalHasArrows,vertical:typeof e.vertical<`u`?e.vertical:1,verticalScrollbarSize:typeof e.verticalScrollbarSize<`u`?e.verticalScrollbarSize:10,verticalHasArrows:typeof e.verticalHasArrows<`u`&&e.verticalHasArrows,verticalSliderSize:typeof e.verticalSliderSize<`u`?e.verticalSliderSize:0,scrollByPage:typeof e.scrollByPage<`u`&&e.scrollByPage};return t.horizontalSliderSize=typeof e.horizontalSliderSize<`u`?e.horizontalSliderSize:t.horizontalScrollbarSize,t.verticalSliderSize=typeof e.verticalSliderSize<`u`?e.verticalSliderSize:t.verticalScrollbarSize,pJ&&(t.className+=` mac`),t}var rX=class extends Sq{constructor(e,t,n,r,i,a,o,s){super(),this._bufferService=n,this._optionsService=o,this._renderService=s,this._onRequestScrollLines=this._register(new Hq),this.onRequestScrollLines=this._onRequestScrollLines.event,this._isSyncing=!1,this._isHandlingScroll=!1,this._suppressOnScrollHandler=!1;let c=this._register(new FY({forceIntegerValues:!1,smoothScrollDuration:this._optionsService.rawOptions.smoothScrollDuration,scheduleAtNextAnimationFrame:e=>_Y(r.window,e)}));this._register(this._optionsService.onSpecificOptionChange(`smoothScrollDuration`,()=>{c.setSmoothScrollDuration(this._optionsService.rawOptions.smoothScrollDuration)})),this._scrollableElement=this._register(new tX(t,{vertical:1,horizontal:2,useShadows:!1,mouseWheelSmoothScroll:!0,...this._getChangeOptions()},c)),this._register(this._optionsService.onMultipleOptionChange([`scrollSensitivity`,`fastScrollSensitivity`,`overviewRuler`],()=>this._scrollableElement.updateOptions(this._getChangeOptions()))),this._register(i.onProtocolChange(e=>{this._scrollableElement.updateOptions({handleMouseWheel:!(e&16)})})),this._scrollableElement.setScrollDimensions({height:0,scrollHeight:0}),this._register(Aq.runAndSubscribe(a.onChangeColors,()=>{this._scrollableElement.getDomNode().style.backgroundColor=a.colors.background.css})),e.appendChild(this._scrollableElement.getDomNode()),this._register(yq(()=>this._scrollableElement.getDomNode().remove())),this._styleElement=r.mainDocument.createElement(`style`),t.appendChild(this._styleElement),this._register(yq(()=>this._styleElement.remove())),this._register(Aq.runAndSubscribe(a.onChangeColors,()=>{this._styleElement.textContent=[`.xterm .xterm-scrollable-element > .scrollbar > .slider {`,` background: ${a.colors.scrollbarSliderBackground.css};`,`}`,`.xterm .xterm-scrollable-element > .scrollbar > .slider:hover {`,` background: ${a.colors.scrollbarSliderHoverBackground.css};`,`}`,`.xterm .xterm-scrollable-element > .scrollbar > .slider.active {`,` background: ${a.colors.scrollbarSliderActiveBackground.css};`,`}`].join(`
1527
+ `)})),this._register(this._bufferService.onResize(()=>this.queueSync())),this._register(this._bufferService.buffers.onBufferActivate(()=>{this._latestYDisp=void 0,this.queueSync()})),this._register(this._bufferService.onScroll(()=>this._sync())),this._register(this._scrollableElement.onScroll(e=>this._handleScroll(e)))}scrollLines(e){let t=this._scrollableElement.getScrollPosition();this._scrollableElement.setScrollPosition({reuseAnimation:!0,scrollTop:t.scrollTop+e*this._renderService.dimensions.css.cell.height})}scrollToLine(e,t){t&&(this._latestYDisp=e),this._scrollableElement.setScrollPosition({reuseAnimation:!t,scrollTop:e*this._renderService.dimensions.css.cell.height})}_getChangeOptions(){return{mouseWheelScrollSensitivity:this._optionsService.rawOptions.scrollSensitivity,fastScrollSensitivity:this._optionsService.rawOptions.fastScrollSensitivity,verticalScrollbarSize:this._optionsService.rawOptions.overviewRuler?.width||14}}queueSync(e){e!==void 0&&(this._latestYDisp=e),this._queuedAnimationFrame===void 0&&(this._queuedAnimationFrame=this._renderService.addRefreshCallback(()=>{this._queuedAnimationFrame=void 0,this._sync(this._latestYDisp)}))}_sync(e=this._bufferService.buffer.ydisp){!this._renderService||this._isSyncing||(this._isSyncing=!0,this._suppressOnScrollHandler=!0,this._scrollableElement.setScrollDimensions({height:this._renderService.dimensions.css.canvas.height,scrollHeight:this._renderService.dimensions.css.cell.height*this._bufferService.buffer.lines.length}),this._suppressOnScrollHandler=!1,e!==this._latestYDisp&&this._scrollableElement.setScrollPosition({scrollTop:e*this._renderService.dimensions.css.cell.height}),this._isSyncing=!1)}_handleScroll(e){if(!this._renderService||this._isHandlingScroll||this._suppressOnScrollHandler)return;this._isHandlingScroll=!0;let t=Math.round(e.scrollTop/this._renderService.dimensions.css.cell.height),n=t-this._bufferService.buffer.ydisp;n!==0&&(this._latestYDisp=t,this._onRequestScrollLines.fire(n)),this._isHandlingScroll=!1}};rX=aK([oK(2,NK),oK(3,KK),oK(4,PK),oK(5,ZK),oK(6,zK),oK(7,JK)],rX);var iX=class extends Sq{constructor(e,t,n,r,i){super(),this._screenElement=e,this._bufferService=t,this._coreBrowserService=n,this._decorationService=r,this._renderService=i,this._decorationElements=new Map,this._altBufferIsActive=!1,this._dimensionsChanged=!1,this._container=document.createElement(`div`),this._container.classList.add(`xterm-decoration-container`),this._screenElement.appendChild(this._container),this._register(this._renderService.onRenderedViewportChange(()=>this._doRefreshDecorations())),this._register(this._renderService.onDimensionsChange(()=>{this._dimensionsChanged=!0,this._queueRefresh()})),this._register(this._coreBrowserService.onDprChange(()=>this._queueRefresh())),this._register(this._bufferService.buffers.onBufferActivate(()=>{this._altBufferIsActive=this._bufferService.buffer===this._bufferService.buffers.alt})),this._register(this._decorationService.onDecorationRegistered(()=>this._queueRefresh())),this._register(this._decorationService.onDecorationRemoved(e=>this._removeDecoration(e))),this._register(yq(()=>{this._container.remove(),this._decorationElements.clear()}))}_queueRefresh(){this._animationFrame===void 0&&(this._animationFrame=this._renderService.addRefreshCallback(()=>{this._doRefreshDecorations(),this._animationFrame=void 0}))}_doRefreshDecorations(){for(let e of this._decorationService.decorations)this._renderDecoration(e);this._dimensionsChanged=!1}_renderDecoration(e){this._refreshStyle(e),this._dimensionsChanged&&this._refreshXPosition(e)}_createElement(e){let t=this._coreBrowserService.mainDocument.createElement(`div`);t.classList.add(`xterm-decoration`),t.classList.toggle(`xterm-decoration-top-layer`,e?.options?.layer===`top`),t.style.width=`${Math.round((e.options.width||1)*this._renderService.dimensions.css.cell.width)}px`,t.style.height=`${(e.options.height||1)*this._renderService.dimensions.css.cell.height}px`,t.style.top=`${(e.marker.line-this._bufferService.buffers.active.ydisp)*this._renderService.dimensions.css.cell.height}px`,t.style.lineHeight=`${this._renderService.dimensions.css.cell.height}px`;let n=e.options.x??0;return n&&n>this._bufferService.cols&&(t.style.display=`none`),this._refreshXPosition(e,t),t}_refreshStyle(e){let t=e.marker.line-this._bufferService.buffers.active.ydisp;if(t<0||t>=this._bufferService.rows)e.element&&(e.element.style.display=`none`,e.onRenderEmitter.fire(e.element));else{let n=this._decorationElements.get(e);n||(n=this._createElement(e),e.element=n,this._decorationElements.set(e,n),this._container.appendChild(n),e.onDispose(()=>{this._decorationElements.delete(e),n.remove()})),n.style.display=this._altBufferIsActive?`none`:`block`,this._altBufferIsActive||(n.style.width=`${Math.round((e.options.width||1)*this._renderService.dimensions.css.cell.width)}px`,n.style.height=`${(e.options.height||1)*this._renderService.dimensions.css.cell.height}px`,n.style.top=`${t*this._renderService.dimensions.css.cell.height}px`,n.style.lineHeight=`${this._renderService.dimensions.css.cell.height}px`),e.onRenderEmitter.fire(n)}}_refreshXPosition(e,t=e.element){if(!t)return;let n=e.options.x??0;(e.options.anchor||`left`)===`right`?t.style.right=n?`${n*this._renderService.dimensions.css.cell.width}px`:``:t.style.left=n?`${n*this._renderService.dimensions.css.cell.width}px`:``}_removeDecoration(e){this._decorationElements.get(e)?.remove(),this._decorationElements.delete(e),e.dispose()}};iX=aK([oK(1,NK),oK(2,KK),oK(3,HK),oK(4,JK)],iX);var aX=class{constructor(){this._zones=[],this._zonePool=[],this._zonePoolIndex=0,this._linePadding={full:0,left:0,center:0,right:0}}get zones(){return this._zonePool.length=Math.min(this._zonePool.length,this._zones.length),this._zones}clear(){this._zones.length=0,this._zonePoolIndex=0}addDecoration(e){if(e.options.overviewRulerOptions){for(let t of this._zones)if(t.color===e.options.overviewRulerOptions.color&&t.position===e.options.overviewRulerOptions.position){if(this._lineIntersectsZone(t,e.marker.line))return;if(this._lineAdjacentToZone(t,e.marker.line,e.options.overviewRulerOptions.position)){this._addLineToZone(t,e.marker.line);return}}if(this._zonePoolIndex<this._zonePool.length){this._zonePool[this._zonePoolIndex].color=e.options.overviewRulerOptions.color,this._zonePool[this._zonePoolIndex].position=e.options.overviewRulerOptions.position,this._zonePool[this._zonePoolIndex].startBufferLine=e.marker.line,this._zonePool[this._zonePoolIndex].endBufferLine=e.marker.line,this._zones.push(this._zonePool[this._zonePoolIndex++]);return}this._zones.push({color:e.options.overviewRulerOptions.color,position:e.options.overviewRulerOptions.position,startBufferLine:e.marker.line,endBufferLine:e.marker.line}),this._zonePool.push(this._zones[this._zones.length-1]),this._zonePoolIndex++}}setPadding(e){this._linePadding=e}_lineIntersectsZone(e,t){return t>=e.startBufferLine&&t<=e.endBufferLine}_lineAdjacentToZone(e,t,n){return t>=e.startBufferLine-this._linePadding[n||`full`]&&t<=e.endBufferLine+this._linePadding[n||`full`]}_addLineToZone(e,t){e.startBufferLine=Math.min(e.startBufferLine,t),e.endBufferLine=Math.max(e.endBufferLine,t)}},oX={full:0,left:0,center:0,right:0},sX={full:0,left:0,center:0,right:0},cX={full:0,left:0,center:0,right:0},lX=class extends Sq{constructor(e,t,n,r,i,a,o,s){super(),this._viewportElement=e,this._screenElement=t,this._bufferService=n,this._decorationService=r,this._renderService=i,this._optionsService=a,this._themeService=o,this._coreBrowserService=s,this._colorZoneStore=new aX,this._shouldUpdateDimensions=!0,this._shouldUpdateAnchor=!0,this._lastKnownBufferLength=0,this._canvas=this._coreBrowserService.mainDocument.createElement(`canvas`),this._canvas.classList.add(`xterm-decoration-overview-ruler`),this._refreshCanvasDimensions(),this._viewportElement.parentElement?.insertBefore(this._canvas,this._viewportElement),this._register(yq(()=>this._canvas?.remove()));let c=this._canvas.getContext(`2d`);if(c)this._ctx=c;else throw Error(`Ctx cannot be null`);this._register(this._decorationService.onDecorationRegistered(()=>this._queueRefresh(void 0,!0))),this._register(this._decorationService.onDecorationRemoved(()=>this._queueRefresh(void 0,!0))),this._register(this._renderService.onRenderedViewportChange(()=>this._queueRefresh())),this._register(this._bufferService.buffers.onBufferActivate(()=>{this._canvas.style.display=this._bufferService.buffer===this._bufferService.buffers.alt?`none`:`block`})),this._register(this._bufferService.onScroll(()=>{this._lastKnownBufferLength!==this._bufferService.buffers.normal.lines.length&&(this._refreshDrawHeightConstants(),this._refreshColorZonePadding())})),this._register(this._renderService.onRender(()=>{(!this._containerHeight||this._containerHeight!==this._screenElement.clientHeight)&&(this._queueRefresh(!0),this._containerHeight=this._screenElement.clientHeight)})),this._register(this._coreBrowserService.onDprChange(()=>this._queueRefresh(!0))),this._register(this._optionsService.onSpecificOptionChange(`overviewRuler`,()=>this._queueRefresh(!0))),this._register(this._themeService.onChangeColors(()=>this._queueRefresh())),this._queueRefresh(!0)}get _width(){return this._optionsService.options.overviewRuler?.width||0}_refreshDrawConstants(){let e=Math.floor((this._canvas.width-1)/3),t=Math.ceil((this._canvas.width-1)/3);sX.full=this._canvas.width,sX.left=e,sX.center=t,sX.right=e,this._refreshDrawHeightConstants(),cX.full=1,cX.left=1,cX.center=1+sX.left,cX.right=1+sX.left+sX.center}_refreshDrawHeightConstants(){oX.full=Math.round(2*this._coreBrowserService.dpr);let e=this._canvas.height/this._bufferService.buffer.lines.length,t=Math.round(Math.max(Math.min(e,12),6)*this._coreBrowserService.dpr);oX.left=t,oX.center=t,oX.right=t}_refreshColorZonePadding(){this._colorZoneStore.setPadding({full:Math.floor(this._bufferService.buffers.active.lines.length/(this._canvas.height-1)*oX.full),left:Math.floor(this._bufferService.buffers.active.lines.length/(this._canvas.height-1)*oX.left),center:Math.floor(this._bufferService.buffers.active.lines.length/(this._canvas.height-1)*oX.center),right:Math.floor(this._bufferService.buffers.active.lines.length/(this._canvas.height-1)*oX.right)}),this._lastKnownBufferLength=this._bufferService.buffers.normal.lines.length}_refreshCanvasDimensions(){this._canvas.style.width=`${this._width}px`,this._canvas.width=Math.round(this._width*this._coreBrowserService.dpr),this._canvas.style.height=`${this._screenElement.clientHeight}px`,this._canvas.height=Math.round(this._screenElement.clientHeight*this._coreBrowserService.dpr),this._refreshDrawConstants(),this._refreshColorZonePadding()}_refreshDecorations(){this._shouldUpdateDimensions&&this._refreshCanvasDimensions(),this._ctx.clearRect(0,0,this._canvas.width,this._canvas.height),this._colorZoneStore.clear();for(let e of this._decorationService.decorations)this._colorZoneStore.addDecoration(e);this._ctx.lineWidth=1,this._renderRulerOutline();let e=this._colorZoneStore.zones;for(let t of e)t.position!==`full`&&this._renderColorZone(t);for(let t of e)t.position===`full`&&this._renderColorZone(t);this._shouldUpdateDimensions=!1,this._shouldUpdateAnchor=!1}_renderRulerOutline(){this._ctx.fillStyle=this._themeService.colors.overviewRulerBorder.css,this._ctx.fillRect(0,0,1,this._canvas.height),this._optionsService.rawOptions.overviewRuler.showTopBorder&&this._ctx.fillRect(1,0,this._canvas.width-1,1),this._optionsService.rawOptions.overviewRuler.showBottomBorder&&this._ctx.fillRect(1,this._canvas.height-1,this._canvas.width-1,this._canvas.height)}_renderColorZone(e){this._ctx.fillStyle=e.color,this._ctx.fillRect(cX[e.position||`full`],Math.round((this._canvas.height-1)*(e.startBufferLine/this._bufferService.buffers.active.lines.length)-oX[e.position||`full`]/2),sX[e.position||`full`],Math.round((this._canvas.height-1)*((e.endBufferLine-e.startBufferLine)/this._bufferService.buffers.active.lines.length)+oX[e.position||`full`]))}_queueRefresh(e,t){this._shouldUpdateDimensions=e||this._shouldUpdateDimensions,this._shouldUpdateAnchor=t||this._shouldUpdateAnchor,this._animationFrame===void 0&&(this._animationFrame=this._coreBrowserService.window.requestAnimationFrame(()=>{this._refreshDecorations(),this._animationFrame=void 0}))}};lX=aK([oK(2,NK),oK(3,HK),oK(4,JK),oK(5,zK),oK(6,ZK),oK(7,KK)],lX);var $;(e=>(e.NUL=`\0`,e.SOH=``,e.STX=``,e.ETX=``,e.EOT=``,e.ENQ=``,e.ACK=``,e.BEL=`\x07`,e.BS=`\b`,e.HT=` `,e.LF=`
1528
+ `,e.VT=`\v`,e.FF=`\f`,e.CR=`\r`,e.SO=``,e.SI=``,e.DLE=``,e.DC1=``,e.DC2=``,e.DC3=``,e.DC4=``,e.NAK=``,e.SYN=``,e.ETB=``,e.CAN=``,e.EM=``,e.SUB=``,e.ESC=`\x1B`,e.FS=``,e.GS=``,e.RS=``,e.US=``,e.SP=` `,e.DEL=``))($||={});var uX;(e=>(e.PAD=`€`,e.HOP=``,e.BPH=`‚`,e.NBH=`ƒ`,e.IND=`„`,e.NEL=`…`,e.SSA=`†`,e.ESA=`‡`,e.HTS=`ˆ`,e.HTJ=`‰`,e.VTS=`Š`,e.PLD=`‹`,e.PLU=`Œ`,e.RI=``,e.SS2=`Ž`,e.SS3=``,e.DCS=``,e.PU1=`‘`,e.PU2=`’`,e.STS=`“`,e.CCH=`”`,e.MW=`•`,e.SPA=`–`,e.EPA=`—`,e.SOS=`˜`,e.SGCI=`™`,e.SCI=`š`,e.CSI=`›`,e.ST=`œ`,e.OSC=``,e.PM=`ž`,e.APC=`Ÿ`))(uX||={});var dX;(e=>e.ST=`${$.ESC}\\`)(dX||={});var fX=class{constructor(e,t,n,r,i,a){this._textarea=e,this._compositionView=t,this._bufferService=n,this._optionsService=r,this._coreService=i,this._renderService=a,this._isComposing=!1,this._isSendingComposition=!1,this._compositionPosition={start:0,end:0},this._dataAlreadySent=``}get isComposing(){return this._isComposing}compositionstart(){this._isComposing=!0,this._compositionPosition.start=this._textarea.value.length,this._compositionView.textContent=``,this._dataAlreadySent=``,this._compositionView.classList.add(`active`)}compositionupdate(e){this._compositionView.textContent=e.data,this.updateCompositionElements(),setTimeout(()=>{this._compositionPosition.end=this._textarea.value.length},0)}compositionend(){this._finalizeComposition(!0)}keydown(e){if(this._isComposing||this._isSendingComposition){if(e.keyCode===20||e.keyCode===229||e.keyCode===16||e.keyCode===17||e.keyCode===18)return!1;this._finalizeComposition(!1)}return e.keyCode!==229||(this._handleAnyTextareaChanges(),!1)}_finalizeComposition(e){if(this._compositionView.classList.remove(`active`),this._isComposing=!1,e){let e={start:this._compositionPosition.start,end:this._compositionPosition.end};this._isSendingComposition=!0,setTimeout(()=>{if(this._isSendingComposition){this._isSendingComposition=!1;let t;e.start+=this._dataAlreadySent.length,t=this._isComposing?this._textarea.value.substring(e.start,this._compositionPosition.start):this._textarea.value.substring(e.start),t.length>0&&this._coreService.triggerDataEvent(t,!0)}},0)}else{this._isSendingComposition=!1;let e=this._textarea.value.substring(this._compositionPosition.start,this._compositionPosition.end);this._coreService.triggerDataEvent(e,!0)}}_handleAnyTextareaChanges(){let e=this._textarea.value;setTimeout(()=>{if(!this._isComposing){let t=this._textarea.value,n=t.replace(e,``);this._dataAlreadySent=n,t.length>e.length?this._coreService.triggerDataEvent(n,!0):t.length<e.length?this._coreService.triggerDataEvent(`${$.DEL}`,!0):t.length===e.length&&t!==e&&this._coreService.triggerDataEvent(t,!0)}},0)}updateCompositionElements(e){if(this._isComposing){if(this._bufferService.buffer.isCursorInViewport){let e=Math.min(this._bufferService.buffer.x,this._bufferService.cols-1),t=this._renderService.dimensions.css.cell.height,n=this._bufferService.buffer.y*this._renderService.dimensions.css.cell.height,r=e*this._renderService.dimensions.css.cell.width;this._compositionView.style.left=r+`px`,this._compositionView.style.top=n+`px`,this._compositionView.style.height=t+`px`,this._compositionView.style.lineHeight=t+`px`,this._compositionView.style.fontFamily=this._optionsService.rawOptions.fontFamily,this._compositionView.style.fontSize=this._optionsService.rawOptions.fontSize+`px`;let i=this._compositionView.getBoundingClientRect();this._textarea.style.left=r+`px`,this._textarea.style.top=n+`px`,this._textarea.style.width=Math.max(i.width,1)+`px`,this._textarea.style.height=Math.max(i.height,1)+`px`,this._textarea.style.lineHeight=i.height+`px`}e||setTimeout(()=>this.updateCompositionElements(!0),0)}}};fX=aK([oK(2,NK),oK(3,zK),oK(4,FK),oK(5,JK)],fX);var pX=0,mX=0,hX=0,gX=0,_X={css:`#00000000`,rgba:0},vX;(e=>{function t(e,t,n,r){return r===void 0?`#${CX(e)}${CX(t)}${CX(n)}`:`#${CX(e)}${CX(t)}${CX(n)}${CX(r)}`}e.toCss=t;function n(e,t,n,r=255){return(e<<24|t<<16|n<<8|r)>>>0}e.toRgba=n;function r(t,n,r,i){return{css:e.toCss(t,n,r,i),rgba:e.toRgba(t,n,r,i)}}e.toColor=r})(vX||={});var yX;(e=>{function t(e,t){if(gX=(t.rgba&255)/255,gX===1)return{css:t.css,rgba:t.rgba};let n=t.rgba>>24&255,r=t.rgba>>16&255,i=t.rgba>>8&255,a=e.rgba>>24&255,o=e.rgba>>16&255,s=e.rgba>>8&255;return pX=a+Math.round((n-a)*gX),mX=o+Math.round((r-o)*gX),hX=s+Math.round((i-s)*gX),{css:vX.toCss(pX,mX,hX),rgba:vX.toRgba(pX,mX,hX)}}e.blend=t;function n(e){return(e.rgba&255)==255}e.isOpaque=n;function r(e,t,n){let r=SX.ensureContrastRatio(e.rgba,t.rgba,n);if(r)return vX.toColor(r>>24&255,r>>16&255,r>>8&255)}e.ensureContrastRatio=r;function i(e){let t=(e.rgba|255)>>>0;return[pX,mX,hX]=SX.toChannels(t),{css:vX.toCss(pX,mX,hX),rgba:t}}e.opaque=i;function a(e,t){return gX=Math.round(t*255),[pX,mX,hX]=SX.toChannels(e.rgba),{css:vX.toCss(pX,mX,hX,gX),rgba:vX.toRgba(pX,mX,hX,gX)}}e.opacity=a;function o(e,t){return gX=e.rgba&255,a(e,gX*t/255)}e.multiplyOpacity=o;function s(e){return[e.rgba>>24&255,e.rgba>>16&255,e.rgba>>8&255]}e.toColorRGB=s})(yX||={});var bX;(e=>{let t,n;try{let e=document.createElement(`canvas`);e.width=1,e.height=1;let r=e.getContext(`2d`,{willReadFrequently:!0});r&&(t=r,t.globalCompositeOperation=`copy`,n=t.createLinearGradient(0,0,1,1))}catch{}function r(e){if(e.match(/#[\da-f]{3,8}/i))switch(e.length){case 4:return pX=parseInt(e.slice(1,2).repeat(2),16),mX=parseInt(e.slice(2,3).repeat(2),16),hX=parseInt(e.slice(3,4).repeat(2),16),vX.toColor(pX,mX,hX);case 5:return pX=parseInt(e.slice(1,2).repeat(2),16),mX=parseInt(e.slice(2,3).repeat(2),16),hX=parseInt(e.slice(3,4).repeat(2),16),gX=parseInt(e.slice(4,5).repeat(2),16),vX.toColor(pX,mX,hX,gX);case 7:return{css:e,rgba:(parseInt(e.slice(1),16)<<8|255)>>>0};case 9:return{css:e,rgba:parseInt(e.slice(1),16)>>>0}}let r=e.match(/rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(,\s*(0|1|\d?\.(\d+))\s*)?\)/);if(r)return pX=parseInt(r[1]),mX=parseInt(r[2]),hX=parseInt(r[3]),gX=Math.round((r[5]===void 0?1:parseFloat(r[5]))*255),vX.toColor(pX,mX,hX,gX);if(!t||!n||(t.fillStyle=n,t.fillStyle=e,typeof t.fillStyle!=`string`)||(t.fillRect(0,0,1,1),[pX,mX,hX,gX]=t.getImageData(0,0,1,1).data,gX!==255))throw Error(`css.toColor: Unsupported css format`);return{rgba:vX.toRgba(pX,mX,hX,gX),css:e}}e.toColor=r})(bX||={});var xX;(e=>{function t(e){return n(e>>16&255,e>>8&255,e&255)}e.relativeLuminance=t;function n(e,t,n){let r=e/255,i=t/255,a=n/255,o=r<=.03928?r/12.92:((r+.055)/1.055)**2.4,s=i<=.03928?i/12.92:((i+.055)/1.055)**2.4,c=a<=.03928?a/12.92:((a+.055)/1.055)**2.4;return o*.2126+s*.7152+c*.0722}e.relativeLuminance2=n})(xX||={});var SX;(e=>{function t(e,t){if(gX=(t&255)/255,gX===1)return t;let n=t>>24&255,r=t>>16&255,i=t>>8&255,a=e>>24&255,o=e>>16&255,s=e>>8&255;return pX=a+Math.round((n-a)*gX),mX=o+Math.round((r-o)*gX),hX=s+Math.round((i-s)*gX),vX.toRgba(pX,mX,hX)}e.blend=t;function n(e,t,n){let a=xX.relativeLuminance(e>>8),o=xX.relativeLuminance(t>>8);if(wX(a,o)<n){if(o<a){let o=r(e,t,n),s=wX(a,xX.relativeLuminance(o>>8));if(s<n){let r=i(e,t,n);return s>wX(a,xX.relativeLuminance(r>>8))?o:r}return o}let s=i(e,t,n),c=wX(a,xX.relativeLuminance(s>>8));if(c<n){let i=r(e,t,n);return c>wX(a,xX.relativeLuminance(i>>8))?s:i}return s}}e.ensureContrastRatio=n;function r(e,t,n){let r=e>>24&255,i=e>>16&255,a=e>>8&255,o=t>>24&255,s=t>>16&255,c=t>>8&255,l=wX(xX.relativeLuminance2(o,s,c),xX.relativeLuminance2(r,i,a));for(;l<n&&(o>0||s>0||c>0);)o-=Math.max(0,Math.ceil(o*.1)),s-=Math.max(0,Math.ceil(s*.1)),c-=Math.max(0,Math.ceil(c*.1)),l=wX(xX.relativeLuminance2(o,s,c),xX.relativeLuminance2(r,i,a));return(o<<24|s<<16|c<<8|255)>>>0}e.reduceLuminance=r;function i(e,t,n){let r=e>>24&255,i=e>>16&255,a=e>>8&255,o=t>>24&255,s=t>>16&255,c=t>>8&255,l=wX(xX.relativeLuminance2(o,s,c),xX.relativeLuminance2(r,i,a));for(;l<n&&(o<255||s<255||c<255);)o=Math.min(255,o+Math.ceil((255-o)*.1)),s=Math.min(255,s+Math.ceil((255-s)*.1)),c=Math.min(255,c+Math.ceil((255-c)*.1)),l=wX(xX.relativeLuminance2(o,s,c),xX.relativeLuminance2(r,i,a));return(o<<24|s<<16|c<<8|255)>>>0}e.increaseLuminance=i;function a(e){return[e>>24&255,e>>16&255,e>>8&255,e&255]}e.toChannels=a})(SX||={});function CX(e){let t=e.toString(16);return t.length<2?`0`+t:t}function wX(e,t){return e<t?(t+.05)/(e+.05):(e+.05)/(t+.05)}var TX=class extends wK{constructor(e,t,n){super(),this.content=0,this.combinedData=``,this.fg=e.fg,this.bg=e.bg,this.combinedData=t,this._width=n}isCombined(){return 2097152}getWidth(){return this._width}getChars(){return this.combinedData}getCode(){return 2097151}setFromCharData(e){throw Error(`not implemented`)}getAsCharData(){return[this.fg,this.getChars(),this.getWidth(),this.getCode()]}},EX=class{constructor(e){this._bufferService=e,this._characterJoiners=[],this._nextCharacterJoinerId=0,this._workCell=new EK}register(e){let t={id:this._nextCharacterJoinerId++,handler:e};return this._characterJoiners.push(t),t.id}deregister(e){for(let t=0;t<this._characterJoiners.length;t++)if(this._characterJoiners[t].id===e)return this._characterJoiners.splice(t,1),!0;return!1}getJoinedCharacters(e){if(this._characterJoiners.length===0)return[];let t=this._bufferService.buffer.lines.get(e);if(!t||t.length===0)return[];let n=[],r=t.translateToString(!0),i=0,a=0,o=0,s=t.getFg(0),c=t.getBg(0);for(let e=0;e<t.getTrimmedLength();e++)if(t.loadCell(e,this._workCell),this._workCell.getWidth()!==0){if(this._workCell.fg!==s||this._workCell.bg!==c){if(e-i>1){let e=this._getJoinedRanges(r,o,a,t,i);for(let t=0;t<e.length;t++)n.push(e[t])}i=e,o=a,s=this._workCell.fg,c=this._workCell.bg}a+=this._workCell.getChars().length||CK.length}if(this._bufferService.cols-i>1){let e=this._getJoinedRanges(r,o,a,t,i);for(let t=0;t<e.length;t++)n.push(e[t])}return n}_getJoinedRanges(e,t,n,r,i){let a=e.substring(t,n),o=[];try{o=this._characterJoiners[0].handler(a)}catch(e){console.error(e)}for(let e=1;e<this._characterJoiners.length;e++)try{let t=this._characterJoiners[e].handler(a);for(let e=0;e<t.length;e++)EX._mergeRanges(o,t[e])}catch(e){console.error(e)}return this._stringRangesToCellRanges(o,r,i),o}_stringRangesToCellRanges(e,t,n){let r=0,i=!1,a=0,o=e[r];if(o){for(let s=n;s<this._bufferService.cols;s++){let n=t.getWidth(s),c=t.getString(s).length||CK.length;if(n!==0){if(!i&&o[0]<=a&&(o[0]=s,i=!0),o[1]<=a){if(o[1]=s,o=e[++r],!o)break;o[0]<=a?(o[0]=s,i=!0):i=!1}a+=c}}o&&(o[1]=this._bufferService.cols)}}static _mergeRanges(e,t){let n=!1;for(let r=0;r<e.length;r++){let i=e[r];if(n){if(t[1]<=i[0])return e[r-1][1]=t[1],e;if(t[1]<=i[1])return e[r-1][1]=Math.max(t[1],i[1]),e.splice(r,1),e;e.splice(r,1),r--}else{if(t[1]<=i[0])return e.splice(r,0,t),e;if(t[1]<=i[1])return i[0]=Math.min(t[0],i[0]),e;t[0]<i[1]&&(i[0]=Math.min(t[0],i[0]),n=!0);continue}}return n?e[e.length-1][1]=t[1]:e.push(t),e}};EX=aK([oK(0,NK)],EX);function DX(e){return 57508<=e&&e<=57558}function OX(e){return 9472<=e&&e<=9631}function kX(e){return DX(e)||OX(e)}function AX(){return{css:{canvas:jX(),cell:jX()},device:{canvas:jX(),cell:jX(),char:{width:0,height:0,left:0,top:0}}}}function jX(){return{width:0,height:0}}var MX=class{constructor(e,t,n,r,i,a,o){this._document=e,this._characterJoinerService=t,this._optionsService=n,this._coreBrowserService=r,this._coreService=i,this._decorationService=a,this._themeService=o,this._workCell=new EK,this._columnSelectMode=!1,this.defaultSpacing=0}handleSelectionChanged(e,t,n){this._selectionStart=e,this._selectionEnd=t,this._columnSelectMode=n}createRow(e,t,n,r,i,a,o,s,c,l,u){let d=[],f=this._characterJoinerService.getJoinedCharacters(t),p=this._themeService.colors,m=e.getNoBgTrimmedLength();n&&m<a+1&&(m=a+1);let h,g=0,_=``,v=0,y=0,b=0,x=0,S=!1,C=0,w=!1,T=0,E=0,D=[],O=l!==-1&&u!==-1;for(let ee=0;ee<m;ee++){e.loadCell(ee,this._workCell);let m=this._workCell.getWidth();if(m===0)continue;let te=!1,k=ee>=E,ne=ee,A=this._workCell;if(f.length>0&&ee===f[0][0]&&k){let r=f.shift(),i=this._isCellInSelection(r[0],t);for(v=r[0]+1;v<r[1];v++)k&&=i===this._isCellInSelection(v,t);k&&=!n||a<r[0]||a>=r[1],k?(te=!0,A=new TX(this._workCell,e.translateToString(!0,r[0],r[1]),r[1]-r[0]),ne=r[1]-1,m=A.getWidth()):E=r[1]}let re=this._isCellInSelection(ee,t),j=n&&ee===a,ie=O&&ee>=l&&ee<=u,ae=!1;this._decorationService.forEachDecorationAtCell(ee,t,void 0,e=>{ae=!0});let oe=A.getChars()||CK;if(oe===` `&&(A.isUnderline()||A.isOverline())&&(oe=`\xA0`),T=m*s-c.get(oe,A.isBold(),A.isItalic()),!h)h=this._document.createElement(`span`);else if(g&&(re&&w||!re&&!w&&A.bg===y)&&(re&&w&&p.selectionForeground||A.fg===b)&&A.extended.ext===x&&ie===S&&T===C&&!j&&!te&&!ae&&k){A.isInvisible()?_+=CK:_+=oe,g++;continue}else g&&(h.textContent=_),h=this._document.createElement(`span`),g=0,_=``;if(y=A.bg,b=A.fg,x=A.extended.ext,S=ie,C=T,w=re,te&&a>=ee&&a<=ne&&(a=ee),!this._coreService.isCursorHidden&&j&&this._coreService.isCursorInitialized){if(D.push(`xterm-cursor`),this._coreBrowserService.isFocused)o&&D.push(`xterm-cursor-blink`),D.push(r===`bar`?`xterm-cursor-bar`:r===`underline`?`xterm-cursor-underline`:`xterm-cursor-block`);else if(i)switch(i){case`outline`:D.push(`xterm-cursor-outline`);break;case`block`:D.push(`xterm-cursor-block`);break;case`bar`:D.push(`xterm-cursor-bar`);break;case`underline`:D.push(`xterm-cursor-underline`)}}if(A.isBold()&&D.push(`xterm-bold`),A.isItalic()&&D.push(`xterm-italic`),A.isDim()&&D.push(`xterm-dim`),_=A.isInvisible()?CK:A.getChars()||CK,A.isUnderline()&&(D.push(`xterm-underline-${A.extended.underlineStyle}`),_===` `&&(_=`\xA0`),!A.isUnderlineColorDefault())){if(A.isUnderlineColorRGB())h.style.textDecorationColor=`rgb(${wK.toColorRGB(A.getUnderlineColor()).join(`,`)})`;else{let e=A.getUnderlineColor();this._optionsService.rawOptions.drawBoldTextInBrightColors&&A.isBold()&&e<8&&(e+=8),h.style.textDecorationColor=p.ansi[e].css}}A.isOverline()&&(D.push(`xterm-overline`),_===` `&&(_=`\xA0`)),A.isStrikethrough()&&D.push(`xterm-strikethrough`),ie&&(h.style.textDecoration=`underline`);let se=A.getFgColor(),ce=A.getFgColorMode(),le=A.getBgColor(),ue=A.getBgColorMode(),de=!!A.isInverse();if(de){let e=se;se=le,le=e;let t=ce;ce=ue,ue=t}let fe,M,pe=!1;this._decorationService.forEachDecorationAtCell(ee,t,void 0,e=>{e.options.layer!==`top`&&pe||(e.backgroundColorRGB&&(ue=50331648,le=e.backgroundColorRGB.rgba>>8&16777215,fe=e.backgroundColorRGB),e.foregroundColorRGB&&(ce=50331648,se=e.foregroundColorRGB.rgba>>8&16777215,M=e.foregroundColorRGB),pe=e.options.layer===`top`)}),!pe&&re&&(fe=this._coreBrowserService.isFocused?p.selectionBackgroundOpaque:p.selectionInactiveBackgroundOpaque,le=fe.rgba>>8&16777215,ue=50331648,pe=!0,p.selectionForeground&&(ce=50331648,se=p.selectionForeground.rgba>>8&16777215,M=p.selectionForeground)),pe&&D.push(`xterm-decoration-top`);let N;switch(ue){case 16777216:case 33554432:N=p.ansi[le],D.push(`xterm-bg-${le}`);break;case 50331648:N=vX.toColor(le>>16,le>>8&255,le&255),this._addStyle(h,`background-color:#${NX((le>>>0).toString(16),`0`,6)}`);break;default:de?(N=p.foreground,D.push(`xterm-bg-257`)):N=p.background}switch(fe||A.isDim()&&(fe=yX.multiplyOpacity(N,.5)),ce){case 16777216:case 33554432:A.isBold()&&se<8&&this._optionsService.rawOptions.drawBoldTextInBrightColors&&(se+=8),this._applyMinimumContrast(h,N,p.ansi[se],A,fe,void 0)||D.push(`xterm-fg-${se}`);break;case 50331648:let e=vX.toColor(se>>16&255,se>>8&255,se&255);this._applyMinimumContrast(h,N,e,A,fe,M)||this._addStyle(h,`color:#${NX(se.toString(16),`0`,6)}`);break;default:this._applyMinimumContrast(h,N,p.foreground,A,fe,M)||de&&D.push(`xterm-fg-257`)}D.length&&=(h.className=D.join(` `),0),!j&&!te&&!ae&&k?g++:h.textContent=_,T!==this.defaultSpacing&&(h.style.letterSpacing=`${T}px`),d.push(h),ee=ne}return h&&g&&(h.textContent=_),d}_applyMinimumContrast(e,t,n,r,i,a){if(this._optionsService.rawOptions.minimumContrastRatio===1||kX(r.getCode()))return!1;let o=this._getContrastCache(r),s;if(!i&&!a&&(s=o.getColor(t.rgba,n.rgba)),s===void 0){let e=this._optionsService.rawOptions.minimumContrastRatio/(r.isDim()?2:1);s=yX.ensureContrastRatio(i||t,a||n,e),o.setColor((i||t).rgba,(a||n).rgba,s??null)}return s?(this._addStyle(e,`color:${s.css}`),!0):!1}_getContrastCache(e){return e.isDim()?this._themeService.colors.halfContrastCache:this._themeService.colors.contrastCache}_addStyle(e,t){e.setAttribute(`style`,`${e.getAttribute(`style`)||``}${t};`)}_isCellInSelection(e,t){let n=this._selectionStart,r=this._selectionEnd;return!n||!r?!1:this._columnSelectMode?n[0]<=r[0]?e>=n[0]&&t>=n[1]&&e<r[0]&&t<=r[1]:e<n[0]&&t>=n[1]&&e>=r[0]&&t<=r[1]:t>n[1]&&t<r[1]||n[1]===r[1]&&t===n[1]&&e>=n[0]&&e<r[0]||n[1]<r[1]&&t===r[1]&&e<r[0]||n[1]<r[1]&&t===n[1]&&e>=n[0]}};MX=aK([oK(1,XK),oK(2,zK),oK(3,KK),oK(4,FK),oK(5,HK),oK(6,ZK)],MX);function NX(e,t,n){for(;e.length<n;)e=t+e;return e}var PX=class{constructor(e,t){this._flat=new Float32Array(256),this._font=``,this._fontSize=0,this._weight=`normal`,this._weightBold=`bold`,this._measureElements=[],this._container=e.createElement(`div`),this._container.classList.add(`xterm-width-cache-measure-container`),this._container.setAttribute(`aria-hidden`,`true`),this._container.style.whiteSpace=`pre`,this._container.style.fontKerning=`none`;let n=e.createElement(`span`);n.classList.add(`xterm-char-measure-element`);let r=e.createElement(`span`);r.classList.add(`xterm-char-measure-element`),r.style.fontWeight=`bold`;let i=e.createElement(`span`);i.classList.add(`xterm-char-measure-element`),i.style.fontStyle=`italic`;let a=e.createElement(`span`);a.classList.add(`xterm-char-measure-element`),a.style.fontWeight=`bold`,a.style.fontStyle=`italic`,this._measureElements=[n,r,i,a],this._container.appendChild(n),this._container.appendChild(r),this._container.appendChild(i),this._container.appendChild(a),t.appendChild(this._container),this.clear()}dispose(){this._container.remove(),this._measureElements.length=0,this._holey=void 0}clear(){this._flat.fill(-9999),this._holey=new Map}setFont(e,t,n,r){e===this._font&&t===this._fontSize&&n===this._weight&&r===this._weightBold||(this._font=e,this._fontSize=t,this._weight=n,this._weightBold=r,this._container.style.fontFamily=this._font,this._container.style.fontSize=`${this._fontSize}px`,this._measureElements[0].style.fontWeight=`${n}`,this._measureElements[1].style.fontWeight=`${r}`,this._measureElements[2].style.fontWeight=`${n}`,this._measureElements[3].style.fontWeight=`${r}`,this.clear())}get(e,t,n){let r=0;if(!t&&!n&&e.length===1&&(r=e.charCodeAt(0))<256){if(this._flat[r]!==-9999)return this._flat[r];let t=this._measure(e,0);return t>0&&(this._flat[r]=t),t}let i=e;t&&(i+=`B`),n&&(i+=`I`);let a=this._holey.get(i);if(a===void 0){let r=0;t&&(r|=1),n&&(r|=2),a=this._measure(e,r),a>0&&this._holey.set(i,a)}return a}_measure(e,t){let n=this._measureElements[t];return n.textContent=e.repeat(32),n.offsetWidth/32}},FX=class{constructor(){this.clear()}clear(){this.hasSelection=!1,this.columnSelectMode=!1,this.viewportStartRow=0,this.viewportEndRow=0,this.viewportCappedStartRow=0,this.viewportCappedEndRow=0,this.startCol=0,this.endCol=0,this.selectionStart=void 0,this.selectionEnd=void 0}update(e,t,n,r=!1){if(this.selectionStart=t,this.selectionEnd=n,!t||!n||t[0]===n[0]&&t[1]===n[1]){this.clear();return}let i=e.buffers.active.ydisp,a=t[1]-i,o=n[1]-i,s=Math.max(a,0),c=Math.min(o,e.rows-1);s>=e.rows||c<0?this.clear():(this.hasSelection=!0,this.columnSelectMode=r,this.viewportStartRow=a,this.viewportEndRow=o,this.viewportCappedStartRow=s,this.viewportCappedEndRow=c,this.startCol=t[0],this.endCol=n[0])}isCellSelected(e,t,n){return this.hasSelection?(n-=e.buffer.active.viewportY,this.columnSelectMode?this.startCol<=this.endCol?t>=this.startCol&&n>=this.viewportCappedStartRow&&t<this.endCol&&n<=this.viewportCappedEndRow:t<this.startCol&&n>=this.viewportCappedStartRow&&t>=this.endCol&&n<=this.viewportCappedEndRow:n>this.viewportStartRow&&n<this.viewportEndRow||this.viewportStartRow===this.viewportEndRow&&n===this.viewportStartRow&&t>=this.startCol&&t<this.endCol||this.viewportStartRow<this.viewportEndRow&&n===this.viewportEndRow&&t<this.endCol||this.viewportStartRow<this.viewportEndRow&&n===this.viewportStartRow&&t>=this.startCol):!1}};function IX(){return new FX}var LX=`xterm-dom-renderer-owner-`,RX=`xterm-rows`,zX=`xterm-fg-`,BX=`xterm-bg-`,VX=`xterm-focus`,HX=`xterm-selection`,UX=1,WX=class extends Sq{constructor(e,t,n,r,i,a,o,s,c,l,u,d,f,p){super(),this._terminal=e,this._document=t,this._element=n,this._screenElement=r,this._viewportElement=i,this._helperContainer=a,this._linkifier2=o,this._charSizeService=c,this._optionsService=l,this._bufferService=u,this._coreService=d,this._coreBrowserService=f,this._themeService=p,this._terminalClass=UX++,this._rowElements=[],this._selectionRenderModel=IX(),this.onRequestRedraw=this._register(new Hq).event,this._rowContainer=this._document.createElement(`div`),this._rowContainer.classList.add(RX),this._rowContainer.style.lineHeight=`normal`,this._rowContainer.setAttribute(`aria-hidden`,`true`),this._refreshRowElements(this._bufferService.cols,this._bufferService.rows),this._selectionContainer=this._document.createElement(`div`),this._selectionContainer.classList.add(HX),this._selectionContainer.setAttribute(`aria-hidden`,`true`),this.dimensions=AX(),this._updateDimensions(),this._register(this._optionsService.onOptionChange(()=>this._handleOptionsChanged())),this._register(this._themeService.onChangeColors(e=>this._injectCss(e))),this._injectCss(this._themeService.colors),this._rowFactory=s.createInstance(MX,document),this._element.classList.add(LX+this._terminalClass),this._screenElement.appendChild(this._rowContainer),this._screenElement.appendChild(this._selectionContainer),this._register(this._linkifier2.onShowLinkUnderline(e=>this._handleLinkHover(e))),this._register(this._linkifier2.onHideLinkUnderline(e=>this._handleLinkLeave(e))),this._register(yq(()=>{this._element.classList.remove(LX+this._terminalClass),this._rowContainer.remove(),this._selectionContainer.remove(),this._widthCache.dispose(),this._themeStyleElement.remove(),this._dimensionsStyleElement.remove()})),this._widthCache=new PX(this._document,this._helperContainer),this._widthCache.setFont(this._optionsService.rawOptions.fontFamily,this._optionsService.rawOptions.fontSize,this._optionsService.rawOptions.fontWeight,this._optionsService.rawOptions.fontWeightBold),this._setDefaultSpacing()}_updateDimensions(){let e=this._coreBrowserService.dpr;this.dimensions.device.char.width=this._charSizeService.width*e,this.dimensions.device.char.height=Math.ceil(this._charSizeService.height*e),this.dimensions.device.cell.width=this.dimensions.device.char.width+Math.round(this._optionsService.rawOptions.letterSpacing),this.dimensions.device.cell.height=Math.floor(this.dimensions.device.char.height*this._optionsService.rawOptions.lineHeight),this.dimensions.device.char.left=0,this.dimensions.device.char.top=0,this.dimensions.device.canvas.width=this.dimensions.device.cell.width*this._bufferService.cols,this.dimensions.device.canvas.height=this.dimensions.device.cell.height*this._bufferService.rows,this.dimensions.css.canvas.width=Math.round(this.dimensions.device.canvas.width/e),this.dimensions.css.canvas.height=Math.round(this.dimensions.device.canvas.height/e),this.dimensions.css.cell.width=this.dimensions.css.canvas.width/this._bufferService.cols,this.dimensions.css.cell.height=this.dimensions.css.canvas.height/this._bufferService.rows;for(let e of this._rowElements)e.style.width=`${this.dimensions.css.canvas.width}px`,e.style.height=`${this.dimensions.css.cell.height}px`,e.style.lineHeight=`${this.dimensions.css.cell.height}px`,e.style.overflow=`hidden`;this._dimensionsStyleElement||(this._dimensionsStyleElement=this._document.createElement(`style`),this._screenElement.appendChild(this._dimensionsStyleElement));let t=`${this._terminalSelector} .${RX} span { display: inline-block; height: 100%; vertical-align: top;}`;this._dimensionsStyleElement.textContent=t,this._selectionContainer.style.height=this._viewportElement.style.height,this._screenElement.style.width=`${this.dimensions.css.canvas.width}px`,this._screenElement.style.height=`${this.dimensions.css.canvas.height}px`}_injectCss(e){this._themeStyleElement||(this._themeStyleElement=this._document.createElement(`style`),this._screenElement.appendChild(this._themeStyleElement));let t=`${this._terminalSelector} .${RX} { pointer-events: none; color: ${e.foreground.css}; font-family: ${this._optionsService.rawOptions.fontFamily}; font-size: ${this._optionsService.rawOptions.fontSize}px; font-kerning: none; white-space: pre}`;t+=`${this._terminalSelector} .${RX} .xterm-dim { color: ${yX.multiplyOpacity(e.foreground,.5).css};}`,t+=`${this._terminalSelector} span:not(.xterm-bold) { font-weight: ${this._optionsService.rawOptions.fontWeight};}${this._terminalSelector} span.xterm-bold { font-weight: ${this._optionsService.rawOptions.fontWeightBold};}${this._terminalSelector} span.xterm-italic { font-style: italic;}`;let n=`blink_underline_${this._terminalClass}`,r=`blink_bar_${this._terminalClass}`,i=`blink_block_${this._terminalClass}`;t+=`@keyframes ${n} { 50% { border-bottom-style: hidden; }}`,t+=`@keyframes ${r} { 50% { box-shadow: none; }}`,t+=`@keyframes ${i} { 0% { background-color: ${e.cursor.css}; color: ${e.cursorAccent.css}; } 50% { background-color: inherit; color: ${e.cursor.css}; }}`,t+=`${this._terminalSelector} .${RX}.${VX} .xterm-cursor.xterm-cursor-blink.xterm-cursor-underline { animation: ${n} 1s step-end infinite;}${this._terminalSelector} .${RX}.${VX} .xterm-cursor.xterm-cursor-blink.xterm-cursor-bar { animation: ${r} 1s step-end infinite;}${this._terminalSelector} .${RX}.${VX} .xterm-cursor.xterm-cursor-blink.xterm-cursor-block { animation: ${i} 1s step-end infinite;}${this._terminalSelector} .${RX} .xterm-cursor.xterm-cursor-block { background-color: ${e.cursor.css}; color: ${e.cursorAccent.css};}${this._terminalSelector} .${RX} .xterm-cursor.xterm-cursor-block:not(.xterm-cursor-blink) { background-color: ${e.cursor.css} !important; color: ${e.cursorAccent.css} !important;}${this._terminalSelector} .${RX} .xterm-cursor.xterm-cursor-outline { outline: 1px solid ${e.cursor.css}; outline-offset: -1px;}${this._terminalSelector} .${RX} .xterm-cursor.xterm-cursor-bar { box-shadow: ${this._optionsService.rawOptions.cursorWidth}px 0 0 ${e.cursor.css} inset;}${this._terminalSelector} .${RX} .xterm-cursor.xterm-cursor-underline { border-bottom: 1px ${e.cursor.css}; border-bottom-style: solid; height: calc(100% - 1px);}`,t+=`${this._terminalSelector} .${HX} { position: absolute; top: 0; left: 0; z-index: 1; pointer-events: none;}${this._terminalSelector}.focus .${HX} div { position: absolute; background-color: ${e.selectionBackgroundOpaque.css};}${this._terminalSelector} .${HX} div { position: absolute; background-color: ${e.selectionInactiveBackgroundOpaque.css};}`;for(let[n,r]of e.ansi.entries())t+=`${this._terminalSelector} .${zX}${n} { color: ${r.css}; }${this._terminalSelector} .${zX}${n}.xterm-dim { color: ${yX.multiplyOpacity(r,.5).css}; }${this._terminalSelector} .${BX}${n} { background-color: ${r.css}; }`;t+=`${this._terminalSelector} .${zX}257 { color: ${yX.opaque(e.background).css}; }${this._terminalSelector} .${zX}257.xterm-dim { color: ${yX.multiplyOpacity(yX.opaque(e.background),.5).css}; }${this._terminalSelector} .${BX}257 { background-color: ${e.foreground.css}; }`,this._themeStyleElement.textContent=t}_setDefaultSpacing(){let e=this.dimensions.css.cell.width-this._widthCache.get(`W`,!1,!1);this._rowContainer.style.letterSpacing=`${e}px`,this._rowFactory.defaultSpacing=e}handleDevicePixelRatioChange(){this._updateDimensions(),this._widthCache.clear(),this._setDefaultSpacing()}_refreshRowElements(e,t){for(let e=this._rowElements.length;e<=t;e++){let e=this._document.createElement(`div`);this._rowContainer.appendChild(e),this._rowElements.push(e)}for(;this._rowElements.length>t;)this._rowContainer.removeChild(this._rowElements.pop())}handleResize(e,t){this._refreshRowElements(e,t),this._updateDimensions(),this.handleSelectionChanged(this._selectionRenderModel.selectionStart,this._selectionRenderModel.selectionEnd,this._selectionRenderModel.columnSelectMode)}handleCharSizeChanged(){this._updateDimensions(),this._widthCache.clear(),this._setDefaultSpacing()}handleBlur(){this._rowContainer.classList.remove(VX),this.renderRows(0,this._bufferService.rows-1)}handleFocus(){this._rowContainer.classList.add(VX),this.renderRows(this._bufferService.buffer.y,this._bufferService.buffer.y)}handleSelectionChanged(e,t,n){if(this._selectionContainer.replaceChildren(),this._rowFactory.handleSelectionChanged(e,t,n),this.renderRows(0,this._bufferService.rows-1),!e||!t||(this._selectionRenderModel.update(this._terminal,e,t,n),!this._selectionRenderModel.hasSelection))return;let r=this._selectionRenderModel.viewportStartRow,i=this._selectionRenderModel.viewportEndRow,a=this._selectionRenderModel.viewportCappedStartRow,o=this._selectionRenderModel.viewportCappedEndRow,s=this._document.createDocumentFragment();if(n){let n=e[0]>t[0];s.appendChild(this._createSelectionElement(a,n?t[0]:e[0],n?e[0]:t[0],o-a+1))}else{let n=r===a?e[0]:0,c=a===i?t[0]:this._bufferService.cols;s.appendChild(this._createSelectionElement(a,n,c));let l=o-a-1;if(s.appendChild(this._createSelectionElement(a+1,0,this._bufferService.cols,l)),a!==o){let e=i===o?t[0]:this._bufferService.cols;s.appendChild(this._createSelectionElement(o,0,e))}}this._selectionContainer.appendChild(s)}_createSelectionElement(e,t,n,r=1){let i=this._document.createElement(`div`),a=t*this.dimensions.css.cell.width,o=this.dimensions.css.cell.width*(n-t);return a+o>this.dimensions.css.canvas.width&&(o=this.dimensions.css.canvas.width-a),i.style.height=`${r*this.dimensions.css.cell.height}px`,i.style.top=`${e*this.dimensions.css.cell.height}px`,i.style.left=`${a}px`,i.style.width=`${o}px`,i}handleCursorMove(){}_handleOptionsChanged(){this._updateDimensions(),this._injectCss(this._themeService.colors),this._widthCache.setFont(this._optionsService.rawOptions.fontFamily,this._optionsService.rawOptions.fontSize,this._optionsService.rawOptions.fontWeight,this._optionsService.rawOptions.fontWeightBold),this._setDefaultSpacing()}clear(){for(let e of this._rowElements)e.replaceChildren()}renderRows(e,t){let n=this._bufferService.buffer,r=n.ybase+n.y,i=Math.min(n.x,this._bufferService.cols-1),a=this._coreService.decPrivateModes.cursorBlink??this._optionsService.rawOptions.cursorBlink,o=this._coreService.decPrivateModes.cursorStyle??this._optionsService.rawOptions.cursorStyle,s=this._optionsService.rawOptions.cursorInactiveStyle;for(let c=e;c<=t;c++){let e=c+n.ydisp,t=this._rowElements[c],l=n.lines.get(e);if(!t||!l)break;t.replaceChildren(...this._rowFactory.createRow(l,e,e===r,o,s,i,a,this.dimensions.css.cell.width,this._widthCache,-1,-1))}}get _terminalSelector(){return`.${LX}${this._terminalClass}`}_handleLinkHover(e){this._setCellUnderline(e.x1,e.x2,e.y1,e.y2,e.cols,!0)}_handleLinkLeave(e){this._setCellUnderline(e.x1,e.x2,e.y1,e.y2,e.cols,!1)}_setCellUnderline(e,t,n,r,i,a){n<0&&(e=0),r<0&&(t=0);let o=this._bufferService.rows-1;n=Math.max(Math.min(n,o),0),r=Math.max(Math.min(r,o),0),i=Math.min(i,this._bufferService.cols);let s=this._bufferService.buffer,c=s.ybase+s.y,l=Math.min(s.x,i-1),u=this._optionsService.rawOptions.cursorBlink,d=this._optionsService.rawOptions.cursorStyle,f=this._optionsService.rawOptions.cursorInactiveStyle;for(let o=n;o<=r;++o){let p=o+s.ydisp,m=this._rowElements[o],h=s.lines.get(p);if(!m||!h)break;m.replaceChildren(...this._rowFactory.createRow(h,p,p===c,d,f,l,u,this.dimensions.css.cell.width,this._widthCache,a?o===n?e:0:-1,a?(o===r?t:i)-1:-1))}}};WX=aK([oK(7,LK),oK(8,GK),oK(9,zK),oK(10,NK),oK(11,FK),oK(12,KK),oK(13,ZK)],WX);var GX=class extends Sq{constructor(e,t,n){super(),this._optionsService=n,this.width=0,this.height=0,this._onCharSizeChange=this._register(new Hq),this.onCharSizeChange=this._onCharSizeChange.event;try{this._measureStrategy=this._register(new JX(this._optionsService))}catch{this._measureStrategy=this._register(new qX(e,t,this._optionsService))}this._register(this._optionsService.onMultipleOptionChange([`fontFamily`,`fontSize`],()=>this.measure()))}get hasValidSize(){return this.width>0&&this.height>0}measure(){let e=this._measureStrategy.measure();(e.width!==this.width||e.height!==this.height)&&(this.width=e.width,this.height=e.height,this._onCharSizeChange.fire())}};GX=aK([oK(2,zK)],GX);var KX=class extends Sq{constructor(){super(...arguments),this._result={width:0,height:0}}_validateAndSet(e,t){e!==void 0&&e>0&&t!==void 0&&t>0&&(this._result.width=e,this._result.height=t)}},qX=class extends KX{constructor(e,t,n){super(),this._document=e,this._parentElement=t,this._optionsService=n,this._measureElement=this._document.createElement(`span`),this._measureElement.classList.add(`xterm-char-measure-element`),this._measureElement.textContent=`W`.repeat(32),this._measureElement.setAttribute(`aria-hidden`,`true`),this._measureElement.style.whiteSpace=`pre`,this._measureElement.style.fontKerning=`none`,this._parentElement.appendChild(this._measureElement)}measure(){return this._measureElement.style.fontFamily=this._optionsService.rawOptions.fontFamily,this._measureElement.style.fontSize=`${this._optionsService.rawOptions.fontSize}px`,this._validateAndSet(Number(this._measureElement.offsetWidth)/32,Number(this._measureElement.offsetHeight)),this._result}},JX=class extends KX{constructor(e){super(),this._optionsService=e,this._canvas=new OffscreenCanvas(100,100),this._ctx=this._canvas.getContext(`2d`);let t=this._ctx.measureText(`W`);if(!(`width`in t&&`fontBoundingBoxAscent`in t&&`fontBoundingBoxDescent`in t))throw Error(`Required font metrics not supported`)}measure(){this._ctx.font=`${this._optionsService.rawOptions.fontSize}px ${this._optionsService.rawOptions.fontFamily}`;let e=this._ctx.measureText(`W`);return this._validateAndSet(e.width,e.fontBoundingBoxAscent+e.fontBoundingBoxDescent),this._result}},YX=class extends Sq{constructor(e,t,n){super(),this._textarea=e,this._window=t,this.mainDocument=n,this._isFocused=!1,this._cachedIsFocused=void 0,this._screenDprMonitor=this._register(new XX(this._window)),this._onDprChange=this._register(new Hq),this.onDprChange=this._onDprChange.event,this._onWindowChange=this._register(new Hq),this.onWindowChange=this._onWindowChange.event,this._register(this.onWindowChange(e=>this._screenDprMonitor.setWindow(e))),this._register(Aq.forward(this._screenDprMonitor.onDprChange,this._onDprChange)),this._register(pY(this._textarea,`focus`,()=>this._isFocused=!0)),this._register(pY(this._textarea,`blur`,()=>this._isFocused=!1))}get window(){return this._window}set window(e){this._window!==e&&(this._window=e,this._onWindowChange.fire(this._window))}get dpr(){return this.window.devicePixelRatio}get isFocused(){return this._cachedIsFocused===void 0&&(this._cachedIsFocused=this._isFocused&&this._textarea.ownerDocument.hasFocus(),queueMicrotask(()=>this._cachedIsFocused=void 0)),this._cachedIsFocused}},XX=class extends Sq{constructor(e){super(),this._parentWindow=e,this._windowResizeListener=this._register(new Cq),this._onDprChange=this._register(new Hq),this.onDprChange=this._onDprChange.event,this._outerListener=()=>this._setDprAndFireIfDiffers(),this._currentDevicePixelRatio=this._parentWindow.devicePixelRatio,this._updateDpr(),this._setWindowResizeListener(),this._register(yq(()=>this.clearListener()))}setWindow(e){this._parentWindow=e,this._setWindowResizeListener(),this._setDprAndFireIfDiffers()}_setWindowResizeListener(){this._windowResizeListener.value=pY(this._parentWindow,`resize`,()=>this._setDprAndFireIfDiffers())}_setDprAndFireIfDiffers(){this._parentWindow.devicePixelRatio!==this._currentDevicePixelRatio&&this._onDprChange.fire(this._parentWindow.devicePixelRatio),this._updateDpr()}_updateDpr(){this._outerListener&&(this._resolutionMediaMatchList?.removeListener(this._outerListener),this._currentDevicePixelRatio=this._parentWindow.devicePixelRatio,this._resolutionMediaMatchList=this._parentWindow.matchMedia(`screen and (resolution: ${this._parentWindow.devicePixelRatio}dppx)`),this._resolutionMediaMatchList.addListener(this._outerListener))}clearListener(){!this._resolutionMediaMatchList||!this._outerListener||(this._resolutionMediaMatchList.removeListener(this._outerListener),this._resolutionMediaMatchList=void 0,this._outerListener=void 0)}},ZX=class extends Sq{constructor(){super(),this.linkProviders=[],this._register(yq(()=>this.linkProviders.length=0))}registerLinkProvider(e){return this.linkProviders.push(e),{dispose:()=>{let t=this.linkProviders.indexOf(e);t!==-1&&this.linkProviders.splice(t,1)}}}};function QX(e,t,n){let r=n.getBoundingClientRect(),i=e.getComputedStyle(n),a=parseInt(i.getPropertyValue(`padding-left`)),o=parseInt(i.getPropertyValue(`padding-top`));return[t.clientX-r.left-a,t.clientY-r.top-o]}function $X(e,t,n,r,i,a,o,s,c){if(!a)return;let l=QX(e,t,n);if(l)return l[0]=Math.ceil((l[0]+(c?o/2:0))/o),l[1]=Math.ceil(l[1]/s),l[0]=Math.min(Math.max(l[0],1),r+ +!!c),l[1]=Math.min(Math.max(l[1],1),i),l}var eZ=class{constructor(e,t){this._renderService=e,this._charSizeService=t}getCoords(e,t,n,r,i){return $X(window,e,t,n,r,this._charSizeService.hasValidSize,this._renderService.dimensions.css.cell.width,this._renderService.dimensions.css.cell.height,i)}getMouseReportCoords(e,t){let n=QX(window,e,t);if(this._charSizeService.hasValidSize)return n[0]=Math.min(Math.max(n[0],0),this._renderService.dimensions.css.canvas.width-1),n[1]=Math.min(Math.max(n[1],0),this._renderService.dimensions.css.canvas.height-1),{col:Math.floor(n[0]/this._renderService.dimensions.css.cell.width),row:Math.floor(n[1]/this._renderService.dimensions.css.cell.height),x:Math.floor(n[0]),y:Math.floor(n[1])}}};eZ=aK([oK(0,JK),oK(1,GK)],eZ);var tZ=class{constructor(e,t){this._renderCallback=e,this._coreBrowserService=t,this._refreshCallbacks=[]}dispose(){this._animationFrame&&=(this._coreBrowserService.window.cancelAnimationFrame(this._animationFrame),void 0)}addRefreshCallback(e){return this._refreshCallbacks.push(e),this._animationFrame||=this._coreBrowserService.window.requestAnimationFrame(()=>this._innerRefresh()),this._animationFrame}refresh(e,t,n){this._rowCount=n,e=e===void 0?0:e,t=t===void 0?this._rowCount-1:t,this._rowStart=this._rowStart===void 0?e:Math.min(this._rowStart,e),this._rowEnd=this._rowEnd===void 0?t:Math.max(this._rowEnd,t),!this._animationFrame&&(this._animationFrame=this._coreBrowserService.window.requestAnimationFrame(()=>this._innerRefresh()))}_innerRefresh(){if(this._animationFrame=void 0,this._rowStart===void 0||this._rowEnd===void 0||this._rowCount===void 0){this._runRefreshCallbacks();return}let e=Math.max(this._rowStart,0),t=Math.min(this._rowEnd,this._rowCount-1);this._rowStart=void 0,this._rowEnd=void 0,this._renderCallback(e,t),this._runRefreshCallbacks()}_runRefreshCallbacks(){for(let e of this._refreshCallbacks)e(0);this._refreshCallbacks=[]}},nZ={};iK(nZ,{getSafariVersion:()=>lZ,isChromeOS:()=>hZ,isFirefox:()=>oZ,isIpad:()=>dZ,isIphone:()=>fZ,isLegacyEdge:()=>sZ,isLinux:()=>mZ,isMac:()=>uZ,isNode:()=>rZ,isSafari:()=>cZ,isWindows:()=>pZ});var rZ=typeof process<`u`&&`title`in process,iZ=rZ?`node`:navigator.userAgent,aZ=rZ?`node`:navigator.platform,oZ=iZ.includes(`Firefox`),sZ=iZ.includes(`Edge`),cZ=/^((?!chrome|android).)*safari/i.test(iZ);function lZ(){if(!cZ)return 0;let e=iZ.match(/Version\/(\d+)/);return e===null||e.length<2?0:parseInt(e[1])}var uZ=[`Macintosh`,`MacIntel`,`MacPPC`,`Mac68K`].includes(aZ),dZ=aZ===`iPad`,fZ=aZ===`iPhone`,pZ=[`Windows`,`Win16`,`Win32`,`WinCE`].includes(aZ),mZ=aZ.indexOf(`Linux`)>=0,hZ=/\bCrOS\b/.test(iZ),gZ=class{constructor(){this._tasks=[],this._i=0}enqueue(e){this._tasks.push(e),this._start()}flush(){for(;this._i<this._tasks.length;)this._tasks[this._i]()||this._i++;this.clear()}clear(){this._idleCallback&&=(this._cancelCallback(this._idleCallback),void 0),this._i=0,this._tasks.length=0}_start(){this._idleCallback||=this._requestCallback(this._process.bind(this))}_process(e){this._idleCallback=void 0;let t=0,n=0,r=e.timeRemaining(),i=0;for(;this._i<this._tasks.length;){if(t=performance.now(),this._tasks[this._i]()||this._i++,t=Math.max(1,performance.now()-t),n=Math.max(t,n),i=e.timeRemaining(),n*1.5>i){r-t<-20&&console.warn(`task queue exceeded allotted deadline by ${Math.abs(Math.round(r-t))}ms`),this._start();return}r=i}this.clear()}},_Z=class extends gZ{_requestCallback(e){return setTimeout(()=>e(this._createDeadline(16)))}_cancelCallback(e){clearTimeout(e)}_createDeadline(e){let t=performance.now()+e;return{timeRemaining:()=>Math.max(0,t-performance.now())}}},vZ=class extends gZ{_requestCallback(e){return requestIdleCallback(e)}_cancelCallback(e){cancelIdleCallback(e)}},yZ=!rZ&&`requestIdleCallback`in window?vZ:_Z,bZ=class{constructor(){this._queue=new yZ}set(e){this._queue.clear(),this._queue.enqueue(e)}flush(){this._queue.flush()}},xZ=class extends Sq{constructor(e,t,n,r,i,a,o,s,c){super(),this._rowCount=e,this._optionsService=n,this._charSizeService=r,this._coreService=i,this._coreBrowserService=s,this._renderer=this._register(new Cq),this._pausedResizeTask=new bZ,this._observerDisposable=this._register(new Cq),this._isPaused=!1,this._needsFullRefresh=!1,this._isNextRenderRedrawOnly=!0,this._needsSelectionRefresh=!1,this._canvasWidth=0,this._canvasHeight=0,this._selectionState={start:void 0,end:void 0,columnSelectMode:!1},this._onDimensionsChange=this._register(new Hq),this.onDimensionsChange=this._onDimensionsChange.event,this._onRenderedViewportChange=this._register(new Hq),this.onRenderedViewportChange=this._onRenderedViewportChange.event,this._onRender=this._register(new Hq),this.onRender=this._onRender.event,this._onRefreshRequest=this._register(new Hq),this.onRefreshRequest=this._onRefreshRequest.event,this._renderDebouncer=new tZ((e,t)=>this._renderRows(e,t),this._coreBrowserService),this._register(this._renderDebouncer),this._syncOutputHandler=new SZ(this._coreBrowserService,this._coreService,()=>this._fullRefresh()),this._register(yq(()=>this._syncOutputHandler.dispose())),this._register(this._coreBrowserService.onDprChange(()=>this.handleDevicePixelRatioChange())),this._register(o.onResize(()=>this._fullRefresh())),this._register(o.buffers.onBufferActivate(()=>this._renderer.value?.clear())),this._register(this._optionsService.onOptionChange(()=>this._handleOptionsChanged())),this._register(this._charSizeService.onCharSizeChange(()=>this.handleCharSizeChanged())),this._register(a.onDecorationRegistered(()=>this._fullRefresh())),this._register(a.onDecorationRemoved(()=>this._fullRefresh())),this._register(this._optionsService.onMultipleOptionChange([`customGlyphs`,`drawBoldTextInBrightColors`,`letterSpacing`,`lineHeight`,`fontFamily`,`fontSize`,`fontWeight`,`fontWeightBold`,`minimumContrastRatio`,`rescaleOverlappingGlyphs`],()=>{this.clear(),this.handleResize(o.cols,o.rows),this._fullRefresh()})),this._register(this._optionsService.onMultipleOptionChange([`cursorBlink`,`cursorStyle`],()=>this.refreshRows(o.buffer.y,o.buffer.y,!0))),this._register(c.onChangeColors(()=>this._fullRefresh())),this._registerIntersectionObserver(this._coreBrowserService.window,t),this._register(this._coreBrowserService.onWindowChange(e=>this._registerIntersectionObserver(e,t)))}get dimensions(){return this._renderer.value.dimensions}_registerIntersectionObserver(e,t){if(`IntersectionObserver`in e){let n=new e.IntersectionObserver(e=>this._handleIntersectionChange(e[e.length-1]),{threshold:0});n.observe(t),this._observerDisposable.value=yq(()=>n.disconnect())}}_handleIntersectionChange(e){this._isPaused=e.isIntersecting===void 0?e.intersectionRatio===0:!e.isIntersecting,!this._isPaused&&!this._charSizeService.hasValidSize&&this._charSizeService.measure(),!this._isPaused&&this._needsFullRefresh&&(this._pausedResizeTask.flush(),this.refreshRows(0,this._rowCount-1),this._needsFullRefresh=!1)}refreshRows(e,t,n=!1){if(this._isPaused){this._needsFullRefresh=!0;return}if(this._coreService.decPrivateModes.synchronizedOutput){this._syncOutputHandler.bufferRows(e,t);return}let r=this._syncOutputHandler.flush();r&&(e=Math.min(e,r.start),t=Math.max(t,r.end)),n||(this._isNextRenderRedrawOnly=!1),this._renderDebouncer.refresh(e,t,this._rowCount)}_renderRows(e,t){if(this._renderer.value){if(this._coreService.decPrivateModes.synchronizedOutput){this._syncOutputHandler.bufferRows(e,t);return}e=Math.min(e,this._rowCount-1),t=Math.min(t,this._rowCount-1),this._renderer.value.renderRows(e,t),this._needsSelectionRefresh&&=(this._renderer.value.handleSelectionChanged(this._selectionState.start,this._selectionState.end,this._selectionState.columnSelectMode),!1),this._isNextRenderRedrawOnly||this._onRenderedViewportChange.fire({start:e,end:t}),this._onRender.fire({start:e,end:t}),this._isNextRenderRedrawOnly=!0}}resize(e,t){this._rowCount=t,this._fireOnCanvasResize()}_handleOptionsChanged(){this._renderer.value&&(this.refreshRows(0,this._rowCount-1),this._fireOnCanvasResize())}_fireOnCanvasResize(){this._renderer.value&&(this._renderer.value.dimensions.css.canvas.width===this._canvasWidth&&this._renderer.value.dimensions.css.canvas.height===this._canvasHeight||this._onDimensionsChange.fire(this._renderer.value.dimensions))}hasRenderer(){return!!this._renderer.value}setRenderer(e){this._renderer.value=e,this._renderer.value&&(this._renderer.value.onRequestRedraw(e=>this.refreshRows(e.start,e.end,!0)),this._needsSelectionRefresh=!0,this._fullRefresh())}addRefreshCallback(e){return this._renderDebouncer.addRefreshCallback(e)}_fullRefresh(){this._isPaused?this._needsFullRefresh=!0:this.refreshRows(0,this._rowCount-1)}clearTextureAtlas(){this._renderer.value&&(this._renderer.value.clearTextureAtlas?.(),this._fullRefresh())}handleDevicePixelRatioChange(){this._charSizeService.measure(),this._renderer.value&&(this._renderer.value.handleDevicePixelRatioChange(),this.refreshRows(0,this._rowCount-1))}handleResize(e,t){this._renderer.value&&(this._isPaused?this._pausedResizeTask.set(()=>this._renderer.value?.handleResize(e,t)):this._renderer.value.handleResize(e,t),this._fullRefresh())}handleCharSizeChanged(){this._renderer.value?.handleCharSizeChanged()}handleBlur(){this._renderer.value?.handleBlur()}handleFocus(){this._renderer.value?.handleFocus()}handleSelectionChanged(e,t,n){this._selectionState.start=e,this._selectionState.end=t,this._selectionState.columnSelectMode=n,this._renderer.value?.handleSelectionChanged(e,t,n)}handleCursorMove(){this._renderer.value?.handleCursorMove()}clear(){this._renderer.value?.clear()}};xZ=aK([oK(2,zK),oK(3,GK),oK(4,FK),oK(5,HK),oK(6,NK),oK(7,KK),oK(8,ZK)],xZ);var SZ=class{constructor(e,t,n){this._coreBrowserService=e,this._coreService=t,this._onTimeout=n,this._start=0,this._end=0,this._isBuffering=!1}bufferRows(e,t){this._isBuffering?(this._start=Math.min(this._start,e),this._end=Math.max(this._end,t)):(this._start=e,this._end=t,this._isBuffering=!0),this._timeout===void 0&&(this._timeout=this._coreBrowserService.window.setTimeout(()=>{this._timeout=void 0,this._coreService.decPrivateModes.synchronizedOutput=!1,this._onTimeout()},1e3))}flush(){if(this._timeout!==void 0&&(this._coreBrowserService.window.clearTimeout(this._timeout),this._timeout=void 0),!this._isBuffering)return;let e={start:this._start,end:this._end};return this._isBuffering=!1,e}dispose(){this._timeout!==void 0&&(this._coreBrowserService.window.clearTimeout(this._timeout),this._timeout=void 0)}};function CZ(e,t,n,r){let i=n.buffer.x,a=n.buffer.y;if(!n.buffer.hasScrollback)return EZ(i,a,e,t,n,r)+DZ(a,t,n,r)+OZ(i,a,e,t,n,r);let o;if(a===t)return o=i>e?`D`:`C`,FZ(Math.abs(i-e),PZ(o,r));o=a>t?`D`:`C`;let s=Math.abs(a-t);return FZ(TZ(a>t?e:i,n)+(s-1)*n.cols+1+wZ(a>t?i:e,n),PZ(o,r))}function wZ(e,t){return e-1}function TZ(e,t){return t.cols-e}function EZ(e,t,n,r,i,a){return DZ(t,r,i,a).length===0?``:FZ(NZ(e,t,e,t-AZ(t,i),!1,i).length,PZ(`D`,a))}function DZ(e,t,n,r){let i=e-AZ(e,n),a=t-AZ(t,n);return FZ(Math.abs(i-a)-kZ(e,t,n),PZ(MZ(e,t),r))}function OZ(e,t,n,r,i,a){let o;o=DZ(t,r,i,a).length>0?r-AZ(r,i):t;let s=r,c=jZ(e,t,n,r,i,a);return FZ(NZ(e,o,n,s,c===`C`,i).length,PZ(c,a))}function kZ(e,t,n){let r=0,i=e-AZ(e,n),a=t-AZ(t,n);for(let o=0;o<Math.abs(i-a);o++){let a=MZ(e,t)===`A`?-1:1;n.buffer.lines.get(i+a*o)?.isWrapped&&r++}return r}function AZ(e,t){let n=0,r=t.buffer.lines.get(e),i=r?.isWrapped;for(;i&&e>=0&&e<t.rows;)n++,r=t.buffer.lines.get(--e),i=r?.isWrapped;return n}function jZ(e,t,n,r,i,a){let o;return o=DZ(n,r,i,a).length>0?r-AZ(r,i):t,e<n&&o<=r||e>=n&&o<r?`C`:`D`}function MZ(e,t){return e>t?`A`:`B`}function NZ(e,t,n,r,i,a){let o=e,s=t,c=``;for(;(o!==n||s!==r)&&s>=0&&s<a.buffer.lines.length;)o+=i?1:-1,i&&o>a.cols-1?(c+=a.buffer.translateBufferLineToString(s,!1,e,o),o=0,e=0,s++):!i&&o<0&&(c+=a.buffer.translateBufferLineToString(s,!1,0,e+1),o=a.cols-1,e=o,s--);return c+a.buffer.translateBufferLineToString(s,!1,e,o)}function PZ(e,t){let n=t?`O`:`[`;return $.ESC+n+e}function FZ(e,t){e=Math.floor(e);let n=``;for(let r=0;r<e;r++)n+=t;return n}var IZ=class{constructor(e){this._bufferService=e,this.isSelectAllActive=!1,this.selectionStartLength=0}clearSelection(){this.selectionStart=void 0,this.selectionEnd=void 0,this.isSelectAllActive=!1,this.selectionStartLength=0}get finalSelectionStart(){return this.isSelectAllActive?[0,0]:!this.selectionEnd||!this.selectionStart?this.selectionStart:this.areSelectionValuesReversed()?this.selectionEnd:this.selectionStart}get finalSelectionEnd(){if(this.isSelectAllActive)return[this._bufferService.cols,this._bufferService.buffer.ybase+this._bufferService.rows-1];if(this.selectionStart){if(!this.selectionEnd||this.areSelectionValuesReversed()){let e=this.selectionStart[0]+this.selectionStartLength;return e>this._bufferService.cols?e%this._bufferService.cols===0?[this._bufferService.cols,this.selectionStart[1]+Math.floor(e/this._bufferService.cols)-1]:[e%this._bufferService.cols,this.selectionStart[1]+Math.floor(e/this._bufferService.cols)]:[e,this.selectionStart[1]]}if(this.selectionStartLength&&this.selectionEnd[1]===this.selectionStart[1]){let e=this.selectionStart[0]+this.selectionStartLength;return e>this._bufferService.cols?[e%this._bufferService.cols,this.selectionStart[1]+Math.floor(e/this._bufferService.cols)]:[Math.max(e,this.selectionEnd[0]),this.selectionEnd[1]]}return this.selectionEnd}}areSelectionValuesReversed(){let e=this.selectionStart,t=this.selectionEnd;return!e||!t?!1:e[1]>t[1]||e[1]===t[1]&&e[0]>t[0]}handleTrim(e){return this.selectionStart&&(this.selectionStart[1]-=e),this.selectionEnd&&(this.selectionEnd[1]-=e),this.selectionEnd&&this.selectionEnd[1]<0?(this.clearSelection(),!0):(this.selectionStart&&this.selectionStart[1]<0&&(this.selectionStart[1]=0),!1)}};function LZ(e,t){if(e.start.y>e.end.y)throw Error(`Buffer range end (${e.end.x}, ${e.end.y}) cannot be before start (${e.start.x}, ${e.start.y})`);return t*(e.end.y-e.start.y)+(e.end.x-e.start.x+1)}var RZ=50,zZ=15,BZ=50,VZ=500,HZ=RegExp(`\xA0`,`g`),UZ=class extends Sq{constructor(e,t,n,r,i,a,o,s,c){super(),this._element=e,this._screenElement=t,this._linkifier=n,this._bufferService=r,this._coreService=i,this._mouseService=a,this._optionsService=o,this._renderService=s,this._coreBrowserService=c,this._dragScrollAmount=0,this._enabled=!0,this._workCell=new EK,this._mouseDownTimeStamp=0,this._oldHasSelection=!1,this._oldSelectionStart=void 0,this._oldSelectionEnd=void 0,this._onLinuxMouseSelection=this._register(new Hq),this.onLinuxMouseSelection=this._onLinuxMouseSelection.event,this._onRedrawRequest=this._register(new Hq),this.onRequestRedraw=this._onRedrawRequest.event,this._onSelectionChange=this._register(new Hq),this.onSelectionChange=this._onSelectionChange.event,this._onRequestScrollLines=this._register(new Hq),this.onRequestScrollLines=this._onRequestScrollLines.event,this._mouseMoveListener=e=>this._handleMouseMove(e),this._mouseUpListener=e=>this._handleMouseUp(e),this._coreService.onUserInput(()=>{this.hasSelection&&this.clearSelection()}),this._trimListener=this._bufferService.buffer.lines.onTrim(e=>this._handleTrim(e)),this._register(this._bufferService.buffers.onBufferActivate(e=>this._handleBufferActivate(e))),this.enable(),this._model=new IZ(this._bufferService),this._activeSelectionMode=0,this._register(yq(()=>{this._removeMouseDownListeners()})),this._register(this._bufferService.onResize(e=>{e.rowsChanged&&this.clearSelection()}))}reset(){this.clearSelection()}disable(){this.clearSelection(),this._enabled=!1}enable(){this._enabled=!0}get selectionStart(){return this._model.finalSelectionStart}get selectionEnd(){return this._model.finalSelectionEnd}get hasSelection(){let e=this._model.finalSelectionStart,t=this._model.finalSelectionEnd;return!e||!t?!1:e[0]!==t[0]||e[1]!==t[1]}get selectionText(){let e=this._model.finalSelectionStart,t=this._model.finalSelectionEnd;if(!e||!t)return``;let n=this._bufferService.buffer,r=[];if(this._activeSelectionMode===3){if(e[0]===t[0])return``;let i=e[0]<t[0]?e[0]:t[0],a=e[0]<t[0]?t[0]:e[0];for(let o=e[1];o<=t[1];o++){let e=n.translateBufferLineToString(o,!0,i,a);r.push(e)}}else{let i=e[1]===t[1]?t[0]:void 0;r.push(n.translateBufferLineToString(e[1],!0,e[0],i));for(let i=e[1]+1;i<=t[1]-1;i++){let e=n.lines.get(i),t=n.translateBufferLineToString(i,!0);e?.isWrapped?r[r.length-1]+=t:r.push(t)}if(e[1]!==t[1]){let e=n.lines.get(t[1]),i=n.translateBufferLineToString(t[1],!0,0,t[0]);e&&e.isWrapped?r[r.length-1]+=i:r.push(i)}}return r.map(e=>e.replace(HZ,` `)).join(pZ?`\r
1528
1529
  `:`
1529
- `)}clearSelection(){this._model.clearSelection(),this._removeMouseDownListeners(),this.refresh(),this._onSelectionChange.fire()}refresh(e){this._refreshAnimationFrame||=this._coreBrowserService.window.requestAnimationFrame(()=>this._refresh()),pZ&&e&&this.selectionText.length&&this._onLinuxMouseSelection.fire(this.selectionText)}_refresh(){this._refreshAnimationFrame=void 0,this._onRedrawRequest.fire({start:this._model.finalSelectionStart,end:this._model.finalSelectionEnd,columnSelectMode:this._activeSelectionMode===3})}_isClickInSelection(e){let t=this._getMouseBufferCoords(e),n=this._model.finalSelectionStart,r=this._model.finalSelectionEnd;return!n||!r||!t?!1:this._areCoordsInSelection(t,n,r)}isCellInSelection(e,t){let n=this._model.finalSelectionStart,r=this._model.finalSelectionEnd;return!n||!r?!1:this._areCoordsInSelection([e,t],n,r)}_areCoordsInSelection(e,t,n){return e[1]>t[1]&&e[1]<n[1]||t[1]===n[1]&&e[1]===t[1]&&e[0]>=t[0]&&e[0]<n[0]||t[1]<n[1]&&e[1]===n[1]&&e[0]<n[0]||t[1]<n[1]&&e[1]===t[1]&&e[0]>=t[0]}_selectWordAtCursor(e,t){let n=this._linkifier.currentLink?.link?.range;if(n)return this._model.selectionStart=[n.start.x-1,n.start.y-1],this._model.selectionStartLength=IZ(n,this._bufferService.cols),this._model.selectionEnd=void 0,!0;let r=this._getMouseBufferCoords(e);return r?(this._selectWordAt(r,t),this._model.selectionEnd=void 0,!0):!1}selectAll(){this._model.isSelectAllActive=!0,this.refresh(),this._onSelectionChange.fire()}selectLines(e,t){this._model.clearSelection(),e=Math.max(e,0),t=Math.min(t,this._bufferService.buffer.lines.length-1),this._model.selectionStart=[0,e],this._model.selectionEnd=[this._bufferService.cols,t],this.refresh(),this._onSelectionChange.fire()}_handleTrim(e){this._model.handleTrim(e)&&this.refresh()}_getMouseBufferCoords(e){let t=this._mouseService.getCoords(e,this._screenElement,this._bufferService.cols,this._bufferService.rows,!0);if(t)return t[0]--,t[1]--,t[1]+=this._bufferService.buffer.ydisp,t}_getMouseEventScrollAmount(e){let t=ZX(this._coreBrowserService.window,e,this._screenElement)[1],n=this._renderService.dimensions.css.canvas.height;return t>=0&&t<=n?0:(t>n&&(t-=n),t=Math.min(Math.max(t,-LZ),LZ),t/=LZ,t/Math.abs(t)+Math.round(t*(RZ-1)))}shouldForceSelection(e){return lZ?e.altKey&&this._optionsService.rawOptions.macOptionClickForcesSelection:e.shiftKey}handleMouseDown(e){if(this._mouseDownTimeStamp=e.timeStamp,!(e.button===2&&this.hasSelection)&&e.button===0){if(!this._enabled){if(!this.shouldForceSelection(e))return;e.stopPropagation()}e.preventDefault(),this._dragScrollAmount=0,this._enabled&&e.shiftKey?this._handleIncrementalClick(e):e.detail===1?this._handleSingleClick(e):e.detail===2?this._handleDoubleClick(e):e.detail===3&&this._handleTripleClick(e),this._addMouseDownListeners(),this.refresh(!0)}}_addMouseDownListeners(){this._screenElement.ownerDocument&&(this._screenElement.ownerDocument.addEventListener(`mousemove`,this._mouseMoveListener),this._screenElement.ownerDocument.addEventListener(`mouseup`,this._mouseUpListener)),this._dragScrollIntervalTimer=this._coreBrowserService.window.setInterval(()=>this._dragScroll(),zZ)}_removeMouseDownListeners(){this._screenElement.ownerDocument&&(this._screenElement.ownerDocument.removeEventListener(`mousemove`,this._mouseMoveListener),this._screenElement.ownerDocument.removeEventListener(`mouseup`,this._mouseUpListener)),this._coreBrowserService.window.clearInterval(this._dragScrollIntervalTimer),this._dragScrollIntervalTimer=void 0}_handleIncrementalClick(e){this._model.selectionStart&&(this._model.selectionEnd=this._getMouseBufferCoords(e))}_handleSingleClick(e){if(this._model.selectionStartLength=0,this._model.isSelectAllActive=!1,this._activeSelectionMode=this.shouldColumnSelect(e)?3:0,this._model.selectionStart=this._getMouseBufferCoords(e),!this._model.selectionStart)return;this._model.selectionEnd=void 0;let t=this._bufferService.buffer.lines.get(this._model.selectionStart[1]);t&&t.length!==this._model.selectionStart[0]&&t.hasWidth(this._model.selectionStart[0])===0&&this._model.selectionStart[0]++}_handleDoubleClick(e){this._selectWordAtCursor(e,!0)&&(this._activeSelectionMode=1)}_handleTripleClick(e){let t=this._getMouseBufferCoords(e);t&&(this._activeSelectionMode=2,this._selectLineAt(t[1]))}shouldColumnSelect(e){return e.altKey&&!(lZ&&this._optionsService.rawOptions.macOptionClickForcesSelection)}_handleMouseMove(e){if(e.stopImmediatePropagation(),!this._model.selectionStart)return;let t=this._model.selectionEnd?[this._model.selectionEnd[0],this._model.selectionEnd[1]]:null;if(this._model.selectionEnd=this._getMouseBufferCoords(e),!this._model.selectionEnd){this.refresh(!0);return}this._activeSelectionMode===2?this._model.selectionEnd[1]<this._model.selectionStart[1]?this._model.selectionEnd[0]=0:this._model.selectionEnd[0]=this._bufferService.cols:this._activeSelectionMode===1&&this._selectToWordAt(this._model.selectionEnd),this._dragScrollAmount=this._getMouseEventScrollAmount(e),this._activeSelectionMode!==3&&(this._dragScrollAmount>0?this._model.selectionEnd[0]=this._bufferService.cols:this._dragScrollAmount<0&&(this._model.selectionEnd[0]=0));let n=this._bufferService.buffer;if(this._model.selectionEnd[1]<n.lines.length){let e=n.lines.get(this._model.selectionEnd[1]);e&&e.hasWidth(this._model.selectionEnd[0])===0&&this._model.selectionEnd[0]<this._bufferService.cols&&this._model.selectionEnd[0]++}(!t||t[0]!==this._model.selectionEnd[0]||t[1]!==this._model.selectionEnd[1])&&this.refresh(!0)}_dragScroll(){if(this._model.selectionEnd&&this._model.selectionStart&&this._dragScrollAmount){this._onRequestScrollLines.fire({amount:this._dragScrollAmount,suppressScrollEvent:!1});let e=this._bufferService.buffer;this._dragScrollAmount>0?(this._activeSelectionMode!==3&&(this._model.selectionEnd[0]=this._bufferService.cols),this._model.selectionEnd[1]=Math.min(e.ydisp+this._bufferService.rows,e.lines.length-1)):(this._activeSelectionMode!==3&&(this._model.selectionEnd[0]=0),this._model.selectionEnd[1]=e.ydisp),this.refresh()}}_handleMouseUp(e){let t=e.timeStamp-this._mouseDownTimeStamp;if(this._removeMouseDownListeners(),this.selectionText.length<=1&&t<BZ&&e.altKey&&this._optionsService.rawOptions.altClickMovesCursor){if(this._bufferService.buffer.ybase===this._bufferService.buffer.ydisp){let t=this._mouseService.getCoords(e,this._element,this._bufferService.cols,this._bufferService.rows,!1);if(t&&t[0]!==void 0&&t[1]!==void 0){let e=SZ(t[0]-1,t[1]-1,this._bufferService,this._coreService.decPrivateModes.applicationCursorKeys);this._coreService.triggerDataEvent(e,!0)}}}else this._fireEventIfSelectionChanged()}_fireEventIfSelectionChanged(){let e=this._model.finalSelectionStart,t=this._model.finalSelectionEnd,n=!!e&&!!t&&(e[0]!==t[0]||e[1]!==t[1]);n?!e||!t||(!this._oldSelectionStart||!this._oldSelectionEnd||e[0]!==this._oldSelectionStart[0]||e[1]!==this._oldSelectionStart[1]||t[0]!==this._oldSelectionEnd[0]||t[1]!==this._oldSelectionEnd[1])&&this._fireOnSelectionChange(e,t,n):this._oldHasSelection&&this._fireOnSelectionChange(e,t,n)}_fireOnSelectionChange(e,t,n){this._oldSelectionStart=e,this._oldSelectionEnd=t,this._oldHasSelection=n,this._onSelectionChange.fire()}_handleBufferActivate(e){this.clearSelection(),this._trimListener.dispose(),this._trimListener=e.activeBuffer.lines.onTrim(e=>this._handleTrim(e))}_convertViewportColToCharacterIndex(e,t){let n=t;for(let r=0;t>=r;r++){let i=e.loadCell(r,this._workCell).getChars().length;this._workCell.getWidth()===0?n--:i>1&&t!==r&&(n+=i-1)}return n}setSelection(e,t,n){this._model.clearSelection(),this._removeMouseDownListeners(),this._model.selectionStart=[e,t],this._model.selectionStartLength=n,this.refresh(),this._fireEventIfSelectionChanged()}rightClickSelect(e){this._isClickInSelection(e)||(this._selectWordAtCursor(e,!1)&&this.refresh(!0),this._fireEventIfSelectionChanged())}_getWordAt(e,t,n=!0,r=!0){if(e[0]>=this._bufferService.cols)return;let i=this._bufferService.buffer,a=i.lines.get(e[1]);if(!a)return;let o=i.translateBufferLineToString(e[1],!1),s=this._convertViewportColToCharacterIndex(a,e[0]),c=s,l=e[0]-s,u=0,d=0,f=0,p=0;if(o.charAt(s)===` `){for(;s>0&&o.charAt(s-1)===` `;)s--;for(;c<o.length&&o.charAt(c+1)===` `;)c++}else{let t=e[0],n=e[0];a.getWidth(t)===0&&(u++,t--),a.getWidth(n)===2&&(d++,n++);let r=a.getString(n).length;for(r>1&&(p+=r-1,c+=r-1);t>0&&s>0&&!this._isCharWordSeparator(a.loadCell(t-1,this._workCell));){a.loadCell(t-1,this._workCell);let e=this._workCell.getChars().length;this._workCell.getWidth()===0?(u++,t--):e>1&&(f+=e-1,s-=e-1),s--,t--}for(;n<a.length&&c+1<o.length&&!this._isCharWordSeparator(a.loadCell(n+1,this._workCell));){a.loadCell(n+1,this._workCell);let e=this._workCell.getChars().length;this._workCell.getWidth()===2?(d++,n++):e>1&&(p+=e-1,c+=e-1),c++,n++}}c++;let m=s+l-u+f,h=Math.min(this._bufferService.cols,c-s+u+d-f-p);if(t||o.slice(s,c).trim()!==``){if(n&&m===0&&a.getCodePoint(0)!==32){let t=i.lines.get(e[1]-1);if(t&&a.isWrapped&&t.getCodePoint(this._bufferService.cols-1)!==32){let t=this._getWordAt([this._bufferService.cols-1,e[1]-1],!1,!0,!1);if(t){let e=this._bufferService.cols-t.start;m-=e,h+=e}}}if(r&&m+h===this._bufferService.cols&&a.getCodePoint(this._bufferService.cols-1)!==32){let t=i.lines.get(e[1]+1);if(t?.isWrapped&&t.getCodePoint(0)!==32){let t=this._getWordAt([0,e[1]+1],!1,!1,!0);t&&(h+=t.length)}}return{start:m,length:h}}}_selectWordAt(e,t){let n=this._getWordAt(e,t);if(n){for(;n.start<0;)n.start+=this._bufferService.cols,e[1]--;this._model.selectionStart=[n.start,e[1]],this._model.selectionStartLength=n.length}}_selectToWordAt(e){let t=this._getWordAt(e,!0);if(t){let n=e[1];for(;t.start<0;)t.start+=this._bufferService.cols,n--;if(!this._model.areSelectionValuesReversed())for(;t.start+t.length>this._bufferService.cols;)t.length-=this._bufferService.cols,n++;this._model.selectionEnd=[this._model.areSelectionValuesReversed()?t.start:t.start+t.length,n]}}_isCharWordSeparator(e){return e.getWidth()!==0&&this._optionsService.rawOptions.wordSeparator.indexOf(e.getChars())>=0}_selectLineAt(e){let t=this._bufferService.buffer.getWrappedRangeForLine(e),n={start:{x:0,y:t.first},end:{x:this._bufferService.cols-1,y:t.last}};this._model.selectionStart=[0,t.first],this._model.selectionEnd=void 0,this._model.selectionStartLength=IZ(n,this._bufferService.cols)}};HZ=iK([aK(3,MK),aK(4,PK),aK(5,KK),aK(6,RK),aK(7,qK),aK(8,GK)],HZ);var UZ=class{constructor(){this._data={}}set(e,t,n){this._data[e]||(this._data[e]={}),this._data[e][t]=n}get(e,t){return this._data[e]?this._data[e][t]:void 0}clear(){this._data={}}},WZ=class{constructor(){this._color=new UZ,this._css=new UZ}setCss(e,t,n){this._css.set(e,t,n)}getCss(e,t){return this._css.get(e,t)}setColor(e,t,n){this._color.set(e,t,n)}getColor(e,t){return this._color.get(e,t)}clear(){this._color.clear(),this._css.clear()}},GZ=Object.freeze((()=>{let e=[yX.toColor(`#2e3436`),yX.toColor(`#cc0000`),yX.toColor(`#4e9a06`),yX.toColor(`#c4a000`),yX.toColor(`#3465a4`),yX.toColor(`#75507b`),yX.toColor(`#06989a`),yX.toColor(`#d3d7cf`),yX.toColor(`#555753`),yX.toColor(`#ef2929`),yX.toColor(`#8ae234`),yX.toColor(`#fce94f`),yX.toColor(`#729fcf`),yX.toColor(`#ad7fa8`),yX.toColor(`#34e2e2`),yX.toColor(`#eeeeec`)],t=[0,95,135,175,215,255];for(let n=0;n<216;n++){let r=t[n/36%6|0],i=t[n/6%6|0],a=t[n%6];e.push({css:_X.toCss(r,i,a),rgba:_X.toRgba(r,i,a)})}for(let t=0;t<24;t++){let n=8+t*10;e.push({css:_X.toCss(n,n,n),rgba:_X.toRgba(n,n,n)})}return e})()),KZ=yX.toColor(`#ffffff`),qZ=yX.toColor(`#000000`),JZ=yX.toColor(`#ffffff`),YZ=qZ,XZ={css:`rgba(255, 255, 255, 0.3)`,rgba:4294967117},ZZ=KZ,QZ=class extends xq{constructor(e){super(),this._optionsService=e,this._contrastCache=new WZ,this._halfContrastCache=new WZ,this._onChangeColors=this._register(new Vq),this.onChangeColors=this._onChangeColors.event,this._colors={foreground:KZ,background:qZ,cursor:JZ,cursorAccent:YZ,selectionForeground:void 0,selectionBackgroundTransparent:XZ,selectionBackgroundOpaque:vX.blend(qZ,XZ),selectionInactiveBackgroundTransparent:XZ,selectionInactiveBackgroundOpaque:vX.blend(qZ,XZ),scrollbarSliderBackground:vX.opacity(KZ,.2),scrollbarSliderHoverBackground:vX.opacity(KZ,.4),scrollbarSliderActiveBackground:vX.opacity(KZ,.5),overviewRulerBorder:KZ,ansi:GZ.slice(),contrastCache:this._contrastCache,halfContrastCache:this._halfContrastCache},this._updateRestoreColors(),this._setTheme(this._optionsService.rawOptions.theme),this._register(this._optionsService.onSpecificOptionChange(`minimumContrastRatio`,()=>this._contrastCache.clear())),this._register(this._optionsService.onSpecificOptionChange(`theme`,()=>this._setTheme(this._optionsService.rawOptions.theme)))}get colors(){return this._colors}_setTheme(e={}){let t=this._colors;if(t.foreground=$Z(e.foreground,KZ),t.background=$Z(e.background,qZ),t.cursor=vX.blend(t.background,$Z(e.cursor,JZ)),t.cursorAccent=vX.blend(t.background,$Z(e.cursorAccent,YZ)),t.selectionBackgroundTransparent=$Z(e.selectionBackground,XZ),t.selectionBackgroundOpaque=vX.blend(t.background,t.selectionBackgroundTransparent),t.selectionInactiveBackgroundTransparent=$Z(e.selectionInactiveBackground,t.selectionBackgroundTransparent),t.selectionInactiveBackgroundOpaque=vX.blend(t.background,t.selectionInactiveBackgroundTransparent),t.selectionForeground=e.selectionForeground?$Z(e.selectionForeground,gX):void 0,t.selectionForeground===gX&&(t.selectionForeground=void 0),vX.isOpaque(t.selectionBackgroundTransparent)&&(t.selectionBackgroundTransparent=vX.opacity(t.selectionBackgroundTransparent,.3)),vX.isOpaque(t.selectionInactiveBackgroundTransparent)&&(t.selectionInactiveBackgroundTransparent=vX.opacity(t.selectionInactiveBackgroundTransparent,.3)),t.scrollbarSliderBackground=$Z(e.scrollbarSliderBackground,vX.opacity(t.foreground,.2)),t.scrollbarSliderHoverBackground=$Z(e.scrollbarSliderHoverBackground,vX.opacity(t.foreground,.4)),t.scrollbarSliderActiveBackground=$Z(e.scrollbarSliderActiveBackground,vX.opacity(t.foreground,.5)),t.overviewRulerBorder=$Z(e.overviewRulerBorder,ZZ),t.ansi=GZ.slice(),t.ansi[0]=$Z(e.black,GZ[0]),t.ansi[1]=$Z(e.red,GZ[1]),t.ansi[2]=$Z(e.green,GZ[2]),t.ansi[3]=$Z(e.yellow,GZ[3]),t.ansi[4]=$Z(e.blue,GZ[4]),t.ansi[5]=$Z(e.magenta,GZ[5]),t.ansi[6]=$Z(e.cyan,GZ[6]),t.ansi[7]=$Z(e.white,GZ[7]),t.ansi[8]=$Z(e.brightBlack,GZ[8]),t.ansi[9]=$Z(e.brightRed,GZ[9]),t.ansi[10]=$Z(e.brightGreen,GZ[10]),t.ansi[11]=$Z(e.brightYellow,GZ[11]),t.ansi[12]=$Z(e.brightBlue,GZ[12]),t.ansi[13]=$Z(e.brightMagenta,GZ[13]),t.ansi[14]=$Z(e.brightCyan,GZ[14]),t.ansi[15]=$Z(e.brightWhite,GZ[15]),e.extendedAnsi){let n=Math.min(t.ansi.length-16,e.extendedAnsi.length);for(let r=0;r<n;r++)t.ansi[r+16]=$Z(e.extendedAnsi[r],GZ[r+16])}this._contrastCache.clear(),this._halfContrastCache.clear(),this._updateRestoreColors(),this._onChangeColors.fire(this.colors)}restoreColor(e){this._restoreColor(e),this._onChangeColors.fire(this.colors)}_restoreColor(e){if(e===void 0)for(let e=0;e<this._restoreColors.ansi.length;++e)this._colors.ansi[e]=this._restoreColors.ansi[e];else switch(e){case 256:this._colors.foreground=this._restoreColors.foreground;break;case 257:this._colors.background=this._restoreColors.background;break;case 258:this._colors.cursor=this._restoreColors.cursor;break;default:this._colors.ansi[e]=this._restoreColors.ansi[e]}}modifyColors(e){e(this._colors),this._onChangeColors.fire(this.colors)}_updateRestoreColors(){this._restoreColors={foreground:this._colors.foreground,background:this._colors.background,cursor:this._colors.cursor,ansi:this._colors.ansi.slice()}}};QZ=iK([aK(0,RK)],QZ);function $Z(e,t){if(e!==void 0)try{return yX.toColor(e)}catch{}return t}var eQ=class{constructor(...e){this._entries=new Map;for(let[t,n]of e)this.set(t,n)}set(e,t){let n=this._entries.get(e);return this._entries.set(e,t),n}forEach(e){for(let[t,n]of this._entries.entries())e(t,n)}has(e){return this._entries.has(e)}get(e){return this._entries.get(e)}},tQ=class{constructor(){this._services=new eQ,this._services.set(IK,this)}setService(e,t){this._services.set(e,t)}getService(e){return this._services.get(e)}createInstance(e,...t){let n=kK(e).sort((e,t)=>e.index-t.index),r=[];for(let t of n){let n=this._services.get(t.id);if(!n)throw Error(`[createInstance] ${e.name} depends on UNKNOWN service ${t.id._id}.`);r.push(n)}let i=n.length>0?n[0].index:t.length;if(t.length!==i)throw Error(`[createInstance] First service dependency of ${e.name} at position ${i+1} conflicts with ${t.length} static arguments`);return new e(...t,...r)}},nQ={trace:0,debug:1,info:2,warn:3,error:4,off:5},rQ=`xterm.js: `,iQ=class extends xq{constructor(e){super(),this._optionsService=e,this._logLevel=5,this._updateLogLevel(),this._register(this._optionsService.onSpecificOptionChange(`logLevel`,()=>this._updateLogLevel())),aQ=this}get logLevel(){return this._logLevel}_updateLogLevel(){this._logLevel=nQ[this._optionsService.rawOptions.logLevel]}_evalLazyOptionalParams(e){for(let t=0;t<e.length;t++)typeof e[t]==`function`&&(e[t]=e[t]())}_log(e,t,n){this._evalLazyOptionalParams(n),e.call(console,(this._optionsService.options.logger?``:rQ)+t,...n)}trace(e,...t){this._logLevel<=0&&this._log(this._optionsService.options.logger?.trace.bind(this._optionsService.options.logger)??console.log,e,t)}debug(e,...t){this._logLevel<=1&&this._log(this._optionsService.options.logger?.debug.bind(this._optionsService.options.logger)??console.log,e,t)}info(e,...t){this._logLevel<=2&&this._log(this._optionsService.options.logger?.info.bind(this._optionsService.options.logger)??console.info,e,t)}warn(e,...t){this._logLevel<=3&&this._log(this._optionsService.options.logger?.warn.bind(this._optionsService.options.logger)??console.warn,e,t)}error(e,...t){this._logLevel<=4&&this._log(this._optionsService.options.logger?.error.bind(this._optionsService.options.logger)??console.error,e,t)}};iQ=iK([aK(0,RK)],iQ);var aQ,oQ=class extends xq{constructor(e){super(),this._maxLength=e,this.onDeleteEmitter=this._register(new Vq),this.onDelete=this.onDeleteEmitter.event,this.onInsertEmitter=this._register(new Vq),this.onInsert=this.onInsertEmitter.event,this.onTrimEmitter=this._register(new Vq),this.onTrim=this.onTrimEmitter.event,this._array=Array(this._maxLength),this._startIndex=0,this._length=0}get maxLength(){return this._maxLength}set maxLength(e){if(this._maxLength===e)return;let t=Array(e);for(let n=0;n<Math.min(e,this.length);n++)t[n]=this._array[this._getCyclicIndex(n)];this._array=t,this._maxLength=e,this._startIndex=0}get length(){return this._length}set length(e){if(e>this._length)for(let t=this._length;t<e;t++)this._array[t]=void 0;this._length=e}get(e){return this._array[this._getCyclicIndex(e)]}set(e,t){this._array[this._getCyclicIndex(e)]=t}push(e){this._array[this._getCyclicIndex(this._length)]=e,this._length===this._maxLength?(this._startIndex=++this._startIndex%this._maxLength,this.onTrimEmitter.fire(1)):this._length++}recycle(){if(this._length!==this._maxLength)throw Error(`Can only recycle when the buffer is full`);return this._startIndex=++this._startIndex%this._maxLength,this.onTrimEmitter.fire(1),this._array[this._getCyclicIndex(this._length-1)]}get isFull(){return this._length===this._maxLength}pop(){return this._array[this._getCyclicIndex(this._length---1)]}splice(e,t,...n){if(t){for(let n=e;n<this._length-t;n++)this._array[this._getCyclicIndex(n)]=this._array[this._getCyclicIndex(n+t)];this._length-=t,this.onDeleteEmitter.fire({index:e,amount:t})}for(let t=this._length-1;t>=e;t--)this._array[this._getCyclicIndex(t+n.length)]=this._array[this._getCyclicIndex(t)];for(let t=0;t<n.length;t++)this._array[this._getCyclicIndex(e+t)]=n[t];if(n.length&&this.onInsertEmitter.fire({index:e,amount:n.length}),this._length+n.length>this._maxLength){let e=this._length+n.length-this._maxLength;this._startIndex+=e,this._length=this._maxLength,this.onTrimEmitter.fire(e)}else this._length+=n.length}trimStart(e){e>this._length&&(e=this._length),this._startIndex+=e,this._length-=e,this.onTrimEmitter.fire(e)}shiftElements(e,t,n){if(!(t<=0)){if(e<0||e>=this._length)throw Error(`start argument out of range`);if(e+n<0)throw Error(`Cannot shift elements in list beyond index 0`);if(n>0){for(let r=t-1;r>=0;r--)this.set(e+r+n,this.get(e+r));let r=e+t+n-this._length;if(r>0)for(this._length+=r;this._length>this._maxLength;)this._length--,this._startIndex++,this.onTrimEmitter.fire(1)}else for(let r=0;r<t;r++)this.set(e+r+n,this.get(e+r))}}_getCyclicIndex(e){return(this._startIndex+e)%this._maxLength}},sQ=3,cQ=Object.freeze(new CK),lQ=0,uQ=2,dQ=class e{constructor(e,t,n=!1){this.isWrapped=n,this._combined={},this._extendedAttrs={},this._data=new Uint32Array(e*sQ);let r=t||TK.fromCharData([0,xK,1,0]);for(let t=0;t<e;++t)this.setCell(t,r);this.length=e}get(e){let t=this._data[e*sQ+0],n=t&2097151;return[this._data[e*sQ+1],t&2097152?this._combined[e]:n?_K(n):``,t>>22,t&2097152?this._combined[e].charCodeAt(this._combined[e].length-1):n]}set(e,t){this._data[e*sQ+1]=t[0],t[1].length>1?(this._combined[e]=t[1],this._data[e*sQ+0]=e|2097152|t[2]<<22):this._data[e*sQ+0]=t[1].charCodeAt(0)|t[2]<<22}getWidth(e){return this._data[e*sQ+0]>>22}hasWidth(e){return this._data[e*sQ+0]&12582912}getFg(e){return this._data[e*sQ+1]}getBg(e){return this._data[e*sQ+2]}hasContent(e){return this._data[e*sQ+0]&4194303}getCodePoint(e){let t=this._data[e*sQ+0];return t&2097152?this._combined[e].charCodeAt(this._combined[e].length-1):t&2097151}isCombined(e){return this._data[e*sQ+0]&2097152}getString(e){let t=this._data[e*sQ+0];return t&2097152?this._combined[e]:t&2097151?_K(t&2097151):``}isProtected(e){return this._data[e*sQ+2]&536870912}loadCell(e,t){return lQ=e*sQ,t.content=this._data[lQ+0],t.fg=this._data[lQ+1],t.bg=this._data[lQ+2],t.content&2097152&&(t.combinedData=this._combined[e]),t.bg&268435456&&(t.extended=this._extendedAttrs[e]),t}setCell(e,t){t.content&2097152&&(this._combined[e]=t.combinedData),t.bg&268435456&&(this._extendedAttrs[e]=t.extended),this._data[e*sQ+0]=t.content,this._data[e*sQ+1]=t.fg,this._data[e*sQ+2]=t.bg}setCellFromCodepoint(e,t,n,r){r.bg&268435456&&(this._extendedAttrs[e]=r.extended),this._data[e*sQ+0]=t|n<<22,this._data[e*sQ+1]=r.fg,this._data[e*sQ+2]=r.bg}addCodepointToCell(e,t,n){let r=this._data[e*sQ+0];r&2097152?this._combined[e]+=_K(t):r&2097151?(this._combined[e]=_K(r&2097151)+_K(t),r&=-2097152,r|=2097152):r=t|1<<22,n&&(r&=-12582913,r|=n<<22),this._data[e*sQ+0]=r}insertCells(e,t,n){if(e%=this.length,e&&this.getWidth(e-1)===2&&this.setCellFromCodepoint(e-1,0,1,n),t<this.length-e){let r=new TK;for(let n=this.length-e-t-1;n>=0;--n)this.setCell(e+t+n,this.loadCell(e+n,r));for(let r=0;r<t;++r)this.setCell(e+r,n)}else for(let t=e;t<this.length;++t)this.setCell(t,n);this.getWidth(this.length-1)===2&&this.setCellFromCodepoint(this.length-1,0,1,n)}deleteCells(e,t,n){if(e%=this.length,t<this.length-e){let r=new TK;for(let n=0;n<this.length-e-t;++n)this.setCell(e+n,this.loadCell(e+t+n,r));for(let e=this.length-t;e<this.length;++e)this.setCell(e,n)}else for(let t=e;t<this.length;++t)this.setCell(t,n);e&&this.getWidth(e-1)===2&&this.setCellFromCodepoint(e-1,0,1,n),this.getWidth(e)===0&&!this.hasContent(e)&&this.setCellFromCodepoint(e,0,1,n)}replaceCells(e,t,n,r=!1){if(r)for(e&&this.getWidth(e-1)===2&&!this.isProtected(e-1)&&this.setCellFromCodepoint(e-1,0,1,n),t<this.length&&this.getWidth(t-1)===2&&!this.isProtected(t)&&this.setCellFromCodepoint(t,0,1,n);e<t&&e<this.length;)this.isProtected(e)||this.setCell(e,n),e++;else for(e&&this.getWidth(e-1)===2&&this.setCellFromCodepoint(e-1,0,1,n),t<this.length&&this.getWidth(t-1)===2&&this.setCellFromCodepoint(t,0,1,n);e<t&&e<this.length;)this.setCell(e++,n)}resize(e,t){if(e===this.length)return this._data.length*4*uQ<this._data.buffer.byteLength;let n=e*sQ;if(e>this.length){if(this._data.buffer.byteLength>=n*4)this._data=new Uint32Array(this._data.buffer,0,n);else{let e=new Uint32Array(n);e.set(this._data),this._data=e}for(let n=this.length;n<e;++n)this.setCell(n,t)}else{this._data=this._data.subarray(0,n);let t=Object.keys(this._combined);for(let n=0;n<t.length;n++){let r=parseInt(t[n],10);r>=e&&delete this._combined[r]}let r=Object.keys(this._extendedAttrs);for(let t=0;t<r.length;t++){let n=parseInt(r[t],10);n>=e&&delete this._extendedAttrs[n]}}return this.length=e,n*4*uQ<this._data.buffer.byteLength}cleanupMemory(){if(this._data.length*4*uQ<this._data.buffer.byteLength){let e=new Uint32Array(this._data.length);return e.set(this._data),this._data=e,1}return 0}fill(e,t=!1){if(t)for(let t=0;t<this.length;++t)this.isProtected(t)||this.setCell(t,e);else{this._combined={},this._extendedAttrs={};for(let t=0;t<this.length;++t)this.setCell(t,e)}}copyFrom(e){this.length===e.length?this._data.set(e._data):this._data=new Uint32Array(e._data),this.length=e.length,this._combined={};for(let t in e._combined)this._combined[t]=e._combined[t];this._extendedAttrs={};for(let t in e._extendedAttrs)this._extendedAttrs[t]=e._extendedAttrs[t];this.isWrapped=e.isWrapped}clone(){let t=new e(0);t._data=new Uint32Array(this._data),t.length=this.length;for(let e in this._combined)t._combined[e]=this._combined[e];for(let e in this._extendedAttrs)t._extendedAttrs[e]=this._extendedAttrs[e];return t.isWrapped=this.isWrapped,t}getTrimmedLength(){for(let e=this.length-1;e>=0;--e)if(this._data[e*sQ+0]&4194303)return e+(this._data[e*sQ+0]>>22);return 0}getNoBgTrimmedLength(){for(let e=this.length-1;e>=0;--e)if(this._data[e*sQ+0]&4194303||this._data[e*sQ+2]&50331648)return e+(this._data[e*sQ+0]>>22);return 0}copyCellsFrom(e,t,n,r,i){let a=e._data;if(i)for(let i=r-1;i>=0;i--){for(let e=0;e<sQ;e++)this._data[(n+i)*sQ+e]=a[(t+i)*sQ+e];a[(t+i)*sQ+2]&268435456&&(this._extendedAttrs[n+i]=e._extendedAttrs[t+i])}else for(let i=0;i<r;i++){for(let e=0;e<sQ;e++)this._data[(n+i)*sQ+e]=a[(t+i)*sQ+e];a[(t+i)*sQ+2]&268435456&&(this._extendedAttrs[n+i]=e._extendedAttrs[t+i])}let o=Object.keys(e._combined);for(let r=0;r<o.length;r++){let i=parseInt(o[r],10);i>=t&&(this._combined[i-t+n]=e._combined[i])}}translateToString(e,t,n,r){t??=0,n??=this.length,e&&(n=Math.min(n,this.getTrimmedLength())),r&&(r.length=0);let i=``;for(;t<n;){let e=this._data[t*sQ+0],n=e&2097151,a=e&2097152?this._combined[t]:n?_K(n):SK;if(i+=a,r)for(let e=0;e<a.length;++e)r.push(t);t+=e>>22||1}return r&&r.push(t),i}};function fQ(e,t,n,r,i,a){let o=[];for(let s=0;s<e.length-1;s++){let c=s,l=e.get(++c);if(!l.isWrapped)continue;let u=[e.get(s)];for(;c<e.length&&l.isWrapped;)u.push(l),l=e.get(++c);if(!a&&r>=s&&r<c){s+=u.length-1;continue}let d=0,f=gQ(u,d,t),p=1,m=0;for(;p<u.length;){let e=gQ(u,p,t),r=e-m,a=n-f,o=Math.min(r,a);u[d].copyCellsFrom(u[p],m,f,o,!1),f+=o,f===n&&(d++,f=0),m+=o,m===e&&(p++,m=0),f===0&&d!==0&&u[d-1].getWidth(n-1)===2&&(u[d].copyCellsFrom(u[d-1],n-1,f++,1,!1),u[d-1].setCell(n-1,i))}u[d].replaceCells(f,n,i);let h=0;for(let e=u.length-1;e>0&&(e>d||u[e].getTrimmedLength()===0);e--)h++;h>0&&(o.push(s+u.length-h),o.push(h)),s+=u.length-1}return o}function pQ(e,t){let n=[],r=0,i=t[r],a=0;for(let o=0;o<e.length;o++)if(i===o){let n=t[++r];e.onDeleteEmitter.fire({index:o-a,amount:n}),o+=n-1,a+=n,i=t[++r]}else n.push(o);return{layout:n,countRemoved:a}}function mQ(e,t){let n=[];for(let r=0;r<t.length;r++)n.push(e.get(t[r]));for(let t=0;t<n.length;t++)e.set(t,n[t]);e.length=t.length}function hQ(e,t,n){let r=[],i=e.map((n,r)=>gQ(e,r,t)).reduce((e,t)=>e+t),a=0,o=0,s=0;for(;s<i;){if(i-s<n){r.push(i-s);break}a+=n;let c=gQ(e,o,t);a>c&&(a-=c,o++);let l=e[o].getWidth(a-1)===2;l&&a--;let u=l?n-1:n;r.push(u),s+=u}return r}function gQ(e,t,n){if(t===e.length-1)return e[t].getTrimmedLength();let r=!e[t].hasContent(n-1)&&e[t].getWidth(n-1)===1,i=e[t+1].getWidth(0)===2;return r&&i?n-1:n}var _Q=class e{constructor(t){this.line=t,this.isDisposed=!1,this._disposables=[],this._id=e._nextId++,this._onDispose=this.register(new Vq),this.onDispose=this._onDispose.event}get id(){return this._id}dispose(){this.isDisposed||(this.isDisposed=!0,this.line=-1,this._onDispose.fire(),gq(this._disposables),this._disposables.length=0)}register(e){return this._disposables.push(e),e}};_Q._nextId=1;var vQ=_Q,yQ={},bQ=yQ.B;yQ[0]={"`":`◆`,a:`▒`,b:`␉`,c:`␌`,d:`␍`,e:`␊`,f:`°`,g:`±`,h:`␤`,i:`␋`,j:`┘`,k:`┐`,l:`┌`,m:`└`,n:`┼`,o:`⎺`,p:`⎻`,q:`─`,r:`⎼`,s:`⎽`,t:`├`,u:`┤`,v:`┴`,w:`┬`,x:`│`,y:`≤`,z:`≥`,"{":`π`,"|":`≠`,"}":`£`,"~":`·`},yQ.A={"#":`£`},yQ.B=void 0,yQ[4]={"#":`£`,"@":`¾`,"[":`ij`,"\\":`½`,"]":`|`,"{":`¨`,"|":`f`,"}":`¼`,"~":`´`},yQ.C=yQ[5]={"[":`Ä`,"\\":`Ö`,"]":`Å`,"^":`Ü`,"`":`é`,"{":`ä`,"|":`ö`,"}":`å`,"~":`ü`},yQ.R={"#":`£`,"@":`à`,"[":`°`,"\\":`ç`,"]":`§`,"{":`é`,"|":`ù`,"}":`è`,"~":`¨`},yQ.Q={"@":`à`,"[":`â`,"\\":`ç`,"]":`ê`,"^":`î`,"`":`ô`,"{":`é`,"|":`ù`,"}":`è`,"~":`û`},yQ.K={"@":`§`,"[":`Ä`,"\\":`Ö`,"]":`Ü`,"{":`ä`,"|":`ö`,"}":`ü`,"~":`ß`},yQ.Y={"#":`£`,"@":`§`,"[":`°`,"\\":`ç`,"]":`é`,"`":`ù`,"{":`à`,"|":`ò`,"}":`è`,"~":`ì`},yQ.E=yQ[6]={"@":`Ä`,"[":`Æ`,"\\":`Ø`,"]":`Å`,"^":`Ü`,"`":`ä`,"{":`æ`,"|":`ø`,"}":`å`,"~":`ü`},yQ.Z={"#":`£`,"@":`§`,"[":`¡`,"\\":`Ñ`,"]":`¿`,"{":`°`,"|":`ñ`,"}":`ç`},yQ.H=yQ[7]={"@":`É`,"[":`Ä`,"\\":`Ö`,"]":`Å`,"^":`Ü`,"`":`é`,"{":`ä`,"|":`ö`,"}":`å`,"~":`ü`},yQ[`=`]={"#":`ù`,"@":`à`,"[":`é`,"\\":`ç`,"]":`ê`,"^":`î`,_:`è`,"`":`ô`,"{":`ä`,"|":`ö`,"}":`ü`,"~":`û`};var xQ=4294967295,SQ=class{constructor(e,t,n){this._hasScrollback=e,this._optionsService=t,this._bufferService=n,this.ydisp=0,this.ybase=0,this.y=0,this.x=0,this.tabs={},this.savedY=0,this.savedX=0,this.savedCurAttrData=cQ.clone(),this.savedCharset=bQ,this.markers=[],this._nullCell=TK.fromCharData([0,xK,1,0]),this._whitespaceCell=TK.fromCharData([0,SK,1,32]),this._isClearing=!1,this._memoryCleanupQueue=new vZ,this._memoryCleanupPosition=0,this._cols=this._bufferService.cols,this._rows=this._bufferService.rows,this.lines=new oQ(this._getCorrectBufferLength(this._rows)),this.scrollTop=0,this.scrollBottom=this._rows-1,this.setupTabStops()}getNullCell(e){return e?(this._nullCell.fg=e.fg,this._nullCell.bg=e.bg,this._nullCell.extended=e.extended):(this._nullCell.fg=0,this._nullCell.bg=0,this._nullCell.extended=new wK),this._nullCell}getWhitespaceCell(e){return e?(this._whitespaceCell.fg=e.fg,this._whitespaceCell.bg=e.bg,this._whitespaceCell.extended=e.extended):(this._whitespaceCell.fg=0,this._whitespaceCell.bg=0,this._whitespaceCell.extended=new wK),this._whitespaceCell}getBlankLine(e,t){return new dQ(this._bufferService.cols,this.getNullCell(e),t)}get hasScrollback(){return this._hasScrollback&&this.lines.maxLength>this._rows}get isCursorInViewport(){let e=this.ybase+this.y-this.ydisp;return e>=0&&e<this._rows}_getCorrectBufferLength(e){if(!this._hasScrollback)return e;let t=e+this._optionsService.rawOptions.scrollback;return t>xQ?xQ:t}fillViewportRows(e){if(this.lines.length===0){e===void 0&&(e=cQ);let t=this._rows;for(;t--;)this.lines.push(this.getBlankLine(e))}}clear(){this.ydisp=0,this.ybase=0,this.y=0,this.x=0,this.lines=new oQ(this._getCorrectBufferLength(this._rows)),this.scrollTop=0,this.scrollBottom=this._rows-1,this.setupTabStops()}resize(e,t){let n=this.getNullCell(cQ),r=0,i=this._getCorrectBufferLength(t);if(i>this.lines.maxLength&&(this.lines.maxLength=i),this.lines.length>0){if(this._cols<e)for(let t=0;t<this.lines.length;t++)r+=+this.lines.get(t).resize(e,n);let a=0;if(this._rows<t)for(let r=this._rows;r<t;r++)this.lines.length<t+this.ybase&&(this._optionsService.rawOptions.windowsMode||this._optionsService.rawOptions.windowsPty.backend!==void 0||this._optionsService.rawOptions.windowsPty.buildNumber!==void 0?this.lines.push(new dQ(e,n)):this.ybase>0&&this.lines.length<=this.ybase+this.y+a+1?(this.ybase--,a++,this.ydisp>0&&this.ydisp--):this.lines.push(new dQ(e,n)));else for(let e=this._rows;e>t;e--)this.lines.length>t+this.ybase&&(this.lines.length>this.ybase+this.y+1?this.lines.pop():(this.ybase++,this.ydisp++));if(i<this.lines.maxLength){let e=this.lines.length-i;e>0&&(this.lines.trimStart(e),this.ybase=Math.max(this.ybase-e,0),this.ydisp=Math.max(this.ydisp-e,0),this.savedY=Math.max(this.savedY-e,0)),this.lines.maxLength=i}this.x=Math.min(this.x,e-1),this.y=Math.min(this.y,t-1),a&&(this.y+=a),this.savedX=Math.min(this.savedX,e-1),this.scrollTop=0}if(this.scrollBottom=t-1,this._isReflowEnabled&&(this._reflow(e,t),this._cols>e))for(let t=0;t<this.lines.length;t++)r+=+this.lines.get(t).resize(e,n);this._cols=e,this._rows=t,this._memoryCleanupQueue.clear(),r>.1*this.lines.length&&(this._memoryCleanupPosition=0,this._memoryCleanupQueue.enqueue(()=>this._batchedMemoryCleanup()))}_batchedMemoryCleanup(){let e=!0;this._memoryCleanupPosition>=this.lines.length&&(this._memoryCleanupPosition=0,e=!1);let t=0;for(;this._memoryCleanupPosition<this.lines.length;)if(t+=this.lines.get(this._memoryCleanupPosition++).cleanupMemory(),t>100)return!0;return e}get _isReflowEnabled(){let e=this._optionsService.rawOptions.windowsPty;return e&&e.buildNumber?this._hasScrollback&&e.backend===`conpty`&&e.buildNumber>=21376:this._hasScrollback&&!this._optionsService.rawOptions.windowsMode}_reflow(e,t){this._cols!==e&&(e>this._cols?this._reflowLarger(e,t):this._reflowSmaller(e,t))}_reflowLarger(e,t){let n=this._optionsService.rawOptions.reflowCursorLine,r=fQ(this.lines,this._cols,e,this.ybase+this.y,this.getNullCell(cQ),n);if(r.length>0){let n=pQ(this.lines,r);mQ(this.lines,n.layout),this._reflowLargerAdjustViewport(e,t,n.countRemoved)}}_reflowLargerAdjustViewport(e,t,n){let r=this.getNullCell(cQ),i=n;for(;i-->0;)this.ybase===0?(this.y>0&&this.y--,this.lines.length<t&&this.lines.push(new dQ(e,r))):(this.ydisp===this.ybase&&this.ydisp--,this.ybase--);this.savedY=Math.max(this.savedY-n,0)}_reflowSmaller(e,t){let n=this._optionsService.rawOptions.reflowCursorLine,r=this.getNullCell(cQ),i=[],a=0;for(let o=this.lines.length-1;o>=0;o--){let s=this.lines.get(o);if(!s||!s.isWrapped&&s.getTrimmedLength()<=e)continue;let c=[s];for(;s.isWrapped&&o>0;)s=this.lines.get(--o),c.unshift(s);if(!n){let e=this.ybase+this.y;if(e>=o&&e<o+c.length)continue}let l=c[c.length-1].getTrimmedLength(),u=hQ(c,this._cols,e),d=u.length-c.length,f;f=this.ybase===0&&this.y!==this.lines.length-1?Math.max(0,this.y-this.lines.maxLength+d):Math.max(0,this.lines.length-this.lines.maxLength+d);let p=[];for(let e=0;e<d;e++){let e=this.getBlankLine(cQ,!0);p.push(e)}p.length>0&&(i.push({start:o+c.length+a,newLines:p}),a+=p.length),c.push(...p);let m=u.length-1,h=u[m];h===0&&(m--,h=u[m]);let g=c.length-d-1,_=l;for(;g>=0;){let e=Math.min(_,h);if(c[m]===void 0)break;c[m].copyCellsFrom(c[g],_-e,h-e,e,!0),h-=e,h===0&&(m--,h=u[m]),_-=e,_===0&&(g--,_=gQ(c,Math.max(g,0),this._cols))}for(let t=0;t<c.length;t++)u[t]<e&&c[t].setCell(u[t],r);let v=d-f;for(;v-->0;)this.ybase===0?this.y<t-1?(this.y++,this.lines.pop()):(this.ybase++,this.ydisp++):this.ybase<Math.min(this.lines.maxLength,this.lines.length+a)-t&&(this.ybase===this.ydisp&&this.ydisp++,this.ybase++);this.savedY=Math.min(this.savedY+d,this.ybase+t-1)}if(i.length>0){let e=[],t=[];for(let e=0;e<this.lines.length;e++)t.push(this.lines.get(e));let n=this.lines.length,r=n-1,o=0,s=i[o];this.lines.length=Math.min(this.lines.maxLength,this.lines.length+a);let c=0;for(let l=Math.min(this.lines.maxLength-1,n+a-1);l>=0;l--)if(s&&s.start>r+c){for(let e=s.newLines.length-1;e>=0;e--)this.lines.set(l--,s.newLines[e]);l++,e.push({index:r+1,amount:s.newLines.length}),c+=s.newLines.length,s=i[++o]}else this.lines.set(l,t[r--]);let l=0;for(let t=e.length-1;t>=0;t--)e[t].index+=l,this.lines.onInsertEmitter.fire(e[t]),l+=e[t].amount;let u=Math.max(0,n+a-this.lines.maxLength);u>0&&this.lines.onTrimEmitter.fire(u)}}translateBufferLineToString(e,t,n=0,r){let i=this.lines.get(e);return i?i.translateToString(t,n,r):``}getWrappedRangeForLine(e){let t=e,n=e;for(;t>0&&this.lines.get(t).isWrapped;)t--;for(;n+1<this.lines.length&&this.lines.get(n+1).isWrapped;)n++;return{first:t,last:n}}setupTabStops(e){for(e==null?(this.tabs={},e=0):this.tabs[e]||(e=this.prevStop(e));e<this._cols;e+=this._optionsService.rawOptions.tabStopWidth)this.tabs[e]=!0}prevStop(e){for(e??=this.x;!this.tabs[--e]&&e>0;);return e>=this._cols?this._cols-1:e<0?0:e}nextStop(e){for(e??=this.x;!this.tabs[++e]&&e<this._cols;);return e>=this._cols?this._cols-1:e<0?0:e}clearMarkers(e){this._isClearing=!0;for(let t=0;t<this.markers.length;t++)this.markers[t].line===e&&(this.markers[t].dispose(),this.markers.splice(t--,1));this._isClearing=!1}clearAllMarkers(){this._isClearing=!0;for(let e=0;e<this.markers.length;e++)this.markers[e].dispose();this.markers.length=0,this._isClearing=!1}addMarker(e){let t=new vQ(e);return this.markers.push(t),t.register(this.lines.onTrim(e=>{t.line-=e,t.line<0&&t.dispose()})),t.register(this.lines.onInsert(e=>{t.line>=e.index&&(t.line+=e.amount)})),t.register(this.lines.onDelete(e=>{t.line>=e.index&&t.line<e.index+e.amount&&t.dispose(),t.line>e.index&&(t.line-=e.amount)})),t.register(t.onDispose(()=>this._removeMarker(t))),t}_removeMarker(e){this._isClearing||this.markers.splice(this.markers.indexOf(e),1)}},CQ=class extends xq{constructor(e,t){super(),this._optionsService=e,this._bufferService=t,this._onBufferActivate=this._register(new Vq),this.onBufferActivate=this._onBufferActivate.event,this.reset(),this._register(this._optionsService.onSpecificOptionChange(`scrollback`,()=>this.resize(this._bufferService.cols,this._bufferService.rows))),this._register(this._optionsService.onSpecificOptionChange(`tabStopWidth`,()=>this.setupTabStops()))}reset(){this._normal=new SQ(!0,this._optionsService,this._bufferService),this._normal.fillViewportRows(),this._alt=new SQ(!1,this._optionsService,this._bufferService),this._activeBuffer=this._normal,this._onBufferActivate.fire({activeBuffer:this._normal,inactiveBuffer:this._alt}),this.setupTabStops()}get alt(){return this._alt}get active(){return this._activeBuffer}get normal(){return this._normal}activateNormalBuffer(){this._activeBuffer!==this._normal&&(this._normal.x=this._alt.x,this._normal.y=this._alt.y,this._alt.clearAllMarkers(),this._alt.clear(),this._activeBuffer=this._normal,this._onBufferActivate.fire({activeBuffer:this._normal,inactiveBuffer:this._alt}))}activateAltBuffer(e){this._activeBuffer!==this._alt&&(this._alt.fillViewportRows(e),this._alt.x=this._normal.x,this._alt.y=this._normal.y,this._activeBuffer=this._alt,this._onBufferActivate.fire({activeBuffer:this._alt,inactiveBuffer:this._normal}))}resize(e,t){this._normal.resize(e,t),this._alt.resize(e,t),this.setupTabStops(e)}setupTabStops(e){this._normal.setupTabStops(e),this._alt.setupTabStops(e)}},wQ=2,TQ=1,EQ=class extends xq{constructor(e){super(),this.isUserScrolling=!1,this._onResize=this._register(new Vq),this.onResize=this._onResize.event,this._onScroll=this._register(new Vq),this.onScroll=this._onScroll.event,this.cols=Math.max(e.rawOptions.cols||0,wQ),this.rows=Math.max(e.rawOptions.rows||0,TQ),this.buffers=this._register(new CQ(e,this)),this._register(this.buffers.onBufferActivate(e=>{this._onScroll.fire(e.activeBuffer.ydisp)}))}get buffer(){return this.buffers.active}resize(e,t){let n=this.cols!==e,r=this.rows!==t;this.cols=e,this.rows=t,this.buffers.resize(e,t),this._onResize.fire({cols:e,rows:t,colsChanged:n,rowsChanged:r})}reset(){this.buffers.reset(),this.isUserScrolling=!1}scroll(e,t=!1){let n=this.buffer,r;r=this._cachedBlankLine,(!r||r.length!==this.cols||r.getFg(0)!==e.fg||r.getBg(0)!==e.bg)&&(r=n.getBlankLine(e,t),this._cachedBlankLine=r),r.isWrapped=t;let i=n.ybase+n.scrollTop,a=n.ybase+n.scrollBottom;if(n.scrollTop===0){let e=n.lines.isFull;a===n.lines.length-1?e?n.lines.recycle().copyFrom(r):n.lines.push(r.clone()):n.lines.splice(a+1,0,r.clone()),e?this.isUserScrolling&&(n.ydisp=Math.max(n.ydisp-1,0)):(n.ybase++,this.isUserScrolling||n.ydisp++)}else{let e=a-i+1;n.lines.shiftElements(i+1,e-1,-1),n.lines.set(a,r.clone())}this.isUserScrolling||(n.ydisp=n.ybase),this._onScroll.fire(n.ydisp)}scrollLines(e,t){let n=this.buffer;if(e<0){if(n.ydisp===0)return;this.isUserScrolling=!0}else e+n.ydisp>=n.ybase&&(this.isUserScrolling=!1);let r=n.ydisp;n.ydisp=Math.max(Math.min(n.ydisp+e,n.ybase),0),r!==n.ydisp&&(t||this._onScroll.fire(n.ydisp))}};EQ=iK([aK(0,RK)],EQ);var DQ={cols:80,rows:24,cursorBlink:!1,cursorStyle:`block`,cursorWidth:1,cursorInactiveStyle:`outline`,customGlyphs:!0,drawBoldTextInBrightColors:!0,documentOverride:null,fastScrollModifier:`alt`,fastScrollSensitivity:5,fontFamily:`monospace`,fontSize:15,fontWeight:`normal`,fontWeightBold:`bold`,ignoreBracketedPasteMode:!1,lineHeight:1,letterSpacing:0,linkHandler:null,logLevel:`info`,logger:null,scrollback:1e3,scrollOnEraseInDisplay:!1,scrollOnUserInput:!0,scrollSensitivity:1,screenReaderMode:!1,smoothScrollDuration:0,macOptionIsMeta:!1,macOptionClickForcesSelection:!1,minimumContrastRatio:1,disableStdin:!1,allowProposedApi:!1,allowTransparency:!1,tabStopWidth:8,theme:{},reflowCursorLine:!1,rescaleOverlappingGlyphs:!1,rightClickSelectsWord:lZ,windowOptions:{},windowsMode:!1,windowsPty:{},wordSeparator:` ()[]{}',"\``,altClickMovesCursor:!0,convertEol:!1,termName:`xterm`,cancelEvents:!1,overviewRuler:{}},OQ=[`normal`,`bold`,`100`,`200`,`300`,`400`,`500`,`600`,`700`,`800`,`900`],kQ=class extends xq{constructor(e){super(),this._onOptionChange=this._register(new Vq),this.onOptionChange=this._onOptionChange.event;let t={...DQ};for(let n in e)if(n in t)try{let r=e[n];t[n]=this._sanitizeAndValidateOption(n,r)}catch(e){console.error(e)}this.rawOptions=t,this.options={...t},this._setupOptions(),this._register(vq(()=>{this.rawOptions.linkHandler=null,this.rawOptions.documentOverride=null}))}onSpecificOptionChange(e,t){return this.onOptionChange(n=>{n===e&&t(this.rawOptions[e])})}onMultipleOptionChange(e,t){return this.onOptionChange(n=>{e.indexOf(n)!==-1&&t()})}_setupOptions(){let e=e=>{if(!(e in DQ))throw Error(`No option with key "${e}"`);return this.rawOptions[e]},t=(e,t)=>{if(!(e in DQ))throw Error(`No option with key "${e}"`);t=this._sanitizeAndValidateOption(e,t),this.rawOptions[e]!==t&&(this.rawOptions[e]=t,this._onOptionChange.fire(e))};for(let n in this.rawOptions){let r={get:e.bind(this,n),set:t.bind(this,n)};Object.defineProperty(this.options,n,r)}}_sanitizeAndValidateOption(e,t){switch(e){case`cursorStyle`:if(t||=DQ[e],!AQ(t))throw Error(`"${t}" is not a valid value for ${e}`);break;case`wordSeparator`:t||=DQ[e];break;case`fontWeight`:case`fontWeightBold`:if(typeof t==`number`&&1<=t&&t<=1e3)break;t=OQ.includes(t)?t:DQ[e];break;case`cursorWidth`:t=Math.floor(t);case`lineHeight`:case`tabStopWidth`:if(t<1)throw Error(`${e} cannot be less than 1, value: ${t}`);break;case`minimumContrastRatio`:t=Math.max(1,Math.min(21,Math.round(t*10)/10));break;case`scrollback`:if(t=Math.min(t,4294967295),t<0)throw Error(`${e} cannot be less than 0, value: ${t}`);break;case`fastScrollSensitivity`:case`scrollSensitivity`:if(t<=0)throw Error(`${e} cannot be less than or equal to 0, value: ${t}`);break;case`rows`:case`cols`:if(!t&&t!==0)throw Error(`${e} must be numeric, value: ${t}`);break;case`windowsPty`:t??={}}return t}};function AQ(e){return e===`block`||e===`underline`||e===`bar`}function jQ(e,t=5){if(typeof e!=`object`)return e;let n=Array.isArray(e)?[]:{};for(let r in e)n[r]=t<=1?e[r]:e[r]&&jQ(e[r],t-1);return n}var MQ=Object.freeze({insertMode:!1}),NQ=Object.freeze({applicationCursorKeys:!1,applicationKeypad:!1,bracketedPasteMode:!1,cursorBlink:void 0,cursorStyle:void 0,origin:!1,reverseWraparound:!1,sendFocus:!1,synchronizedOutput:!1,wraparound:!0}),PQ=class extends xq{constructor(e,t,n){super(),this._bufferService=e,this._logService=t,this._optionsService=n,this.isCursorInitialized=!1,this.isCursorHidden=!1,this._onData=this._register(new Vq),this.onData=this._onData.event,this._onUserInput=this._register(new Vq),this.onUserInput=this._onUserInput.event,this._onBinary=this._register(new Vq),this.onBinary=this._onBinary.event,this._onRequestScrollToBottom=this._register(new Vq),this.onRequestScrollToBottom=this._onRequestScrollToBottom.event,this.modes=jQ(MQ),this.decPrivateModes=jQ(NQ)}reset(){this.modes=jQ(MQ),this.decPrivateModes=jQ(NQ)}triggerDataEvent(e,t=!1){if(this._optionsService.rawOptions.disableStdin)return;let n=this._bufferService.buffer;t&&this._optionsService.rawOptions.scrollOnUserInput&&n.ybase!==n.ydisp&&this._onRequestScrollToBottom.fire(),t&&this._onUserInput.fire(),this._logService.debug(`sending data "${e}"`),this._logService.trace(`sending data (codes)`,()=>e.split(``).map(e=>e.charCodeAt(0))),this._onData.fire(e)}triggerBinaryEvent(e){this._optionsService.rawOptions.disableStdin||(this._logService.debug(`sending binary "${e}"`),this._logService.trace(`sending binary (codes)`,()=>e.split(``).map(e=>e.charCodeAt(0))),this._onBinary.fire(e))}};PQ=iK([aK(0,MK),aK(1,LK),aK(2,RK)],PQ);var FQ={NONE:{events:0,restrict:()=>!1},X10:{events:1,restrict:e=>e.button===4||e.action!==1?!1:(e.ctrl=!1,e.alt=!1,e.shift=!1,!0)},VT200:{events:19,restrict:e=>e.action!==32},DRAG:{events:23,restrict:e=>e.action!==32||e.button!==3},ANY:{events:31,restrict:e=>!0}};function IQ(e,t){let n=(e.ctrl?16:0)|(e.shift?4:0)|(e.alt?8:0);return e.button===4?(n|=64,n|=e.action):(n|=e.button&3,e.button&4&&(n|=64),e.button&8&&(n|=128),e.action===32?n|=32:e.action===0&&!t&&(n|=3)),n}var LQ=String.fromCharCode,RQ={DEFAULT:e=>{let t=[IQ(e,!1)+32,e.col+32,e.row+32];return t[0]>255||t[1]>255||t[2]>255?``:`\x1B[M${LQ(t[0])}${LQ(t[1])}${LQ(t[2])}`},SGR:e=>{let t=e.action===0&&e.button!==4?`m`:`M`;return`\x1B[<${IQ(e,!0)};${e.col};${e.row}${t}`},SGR_PIXELS:e=>{let t=e.action===0&&e.button!==4?`m`:`M`;return`\x1B[<${IQ(e,!0)};${e.x};${e.y}${t}`}},zQ=class extends xq{constructor(e,t,n){super(),this._bufferService=e,this._coreService=t,this._optionsService=n,this._protocols={},this._encodings={},this._activeProtocol=``,this._activeEncoding=``,this._lastEvent=null,this._wheelPartialScroll=0,this._onProtocolChange=this._register(new Vq),this.onProtocolChange=this._onProtocolChange.event;for(let e of Object.keys(FQ))this.addProtocol(e,FQ[e]);for(let e of Object.keys(RQ))this.addEncoding(e,RQ[e]);this.reset()}addProtocol(e,t){this._protocols[e]=t}addEncoding(e,t){this._encodings[e]=t}get activeProtocol(){return this._activeProtocol}get areMouseEventsActive(){return this._protocols[this._activeProtocol].events!==0}set activeProtocol(e){if(!this._protocols[e])throw Error(`unknown protocol "${e}"`);this._activeProtocol=e,this._onProtocolChange.fire(this._protocols[e].events)}get activeEncoding(){return this._activeEncoding}set activeEncoding(e){if(!this._encodings[e])throw Error(`unknown encoding "${e}"`);this._activeEncoding=e}reset(){this.activeProtocol=`NONE`,this.activeEncoding=`DEFAULT`,this._lastEvent=null,this._wheelPartialScroll=0}consumeWheelEvent(e,t,n){if(e.deltaY===0||e.shiftKey||t===void 0||n===void 0)return 0;let r=t/n,i=this._applyScrollModifier(e.deltaY,e);return e.deltaMode===WheelEvent.DOM_DELTA_PIXEL?(i/=r+0,Math.abs(e.deltaY)<50&&(i*=.3),this._wheelPartialScroll+=i,i=Math.floor(Math.abs(this._wheelPartialScroll))*(this._wheelPartialScroll>0?1:-1),this._wheelPartialScroll%=1):e.deltaMode===WheelEvent.DOM_DELTA_PAGE&&(i*=this._bufferService.rows),i}_applyScrollModifier(e,t){return t.altKey||t.ctrlKey||t.shiftKey?e*this._optionsService.rawOptions.fastScrollSensitivity*this._optionsService.rawOptions.scrollSensitivity:e*this._optionsService.rawOptions.scrollSensitivity}triggerMouseEvent(e){if(e.col<0||e.col>=this._bufferService.cols||e.row<0||e.row>=this._bufferService.rows||e.button===4&&e.action===32||e.button===3&&e.action!==32||e.button!==4&&(e.action===2||e.action===3)||(e.col++,e.row++,e.action===32&&this._lastEvent&&this._equalEvents(this._lastEvent,e,this._activeEncoding===`SGR_PIXELS`))||!this._protocols[this._activeProtocol].restrict(e))return!1;let t=this._encodings[this._activeEncoding](e);return t&&(this._activeEncoding===`DEFAULT`?this._coreService.triggerBinaryEvent(t):this._coreService.triggerDataEvent(t,!0)),this._lastEvent=e,!0}explainEvents(e){return{down:!!(e&1),up:!!(e&2),drag:!!(e&4),move:!!(e&8),wheel:!!(e&16)}}_equalEvents(e,t,n){if(n){if(e.x!==t.x||e.y!==t.y)return!1}else if(e.col!==t.col||e.row!==t.row)return!1;return e.button===t.button&&e.action===t.action&&e.ctrl===t.ctrl&&e.alt===t.alt&&e.shift===t.shift}};zQ=iK([aK(0,MK),aK(1,PK),aK(2,RK)],zQ);var BQ=[[768,879],[1155,1158],[1160,1161],[1425,1469],[1471,1471],[1473,1474],[1476,1477],[1479,1479],[1536,1539],[1552,1557],[1611,1630],[1648,1648],[1750,1764],[1767,1768],[1770,1773],[1807,1807],[1809,1809],[1840,1866],[1958,1968],[2027,2035],[2305,2306],[2364,2364],[2369,2376],[2381,2381],[2385,2388],[2402,2403],[2433,2433],[2492,2492],[2497,2500],[2509,2509],[2530,2531],[2561,2562],[2620,2620],[2625,2626],[2631,2632],[2635,2637],[2672,2673],[2689,2690],[2748,2748],[2753,2757],[2759,2760],[2765,2765],[2786,2787],[2817,2817],[2876,2876],[2879,2879],[2881,2883],[2893,2893],[2902,2902],[2946,2946],[3008,3008],[3021,3021],[3134,3136],[3142,3144],[3146,3149],[3157,3158],[3260,3260],[3263,3263],[3270,3270],[3276,3277],[3298,3299],[3393,3395],[3405,3405],[3530,3530],[3538,3540],[3542,3542],[3633,3633],[3636,3642],[3655,3662],[3761,3761],[3764,3769],[3771,3772],[3784,3789],[3864,3865],[3893,3893],[3895,3895],[3897,3897],[3953,3966],[3968,3972],[3974,3975],[3984,3991],[3993,4028],[4038,4038],[4141,4144],[4146,4146],[4150,4151],[4153,4153],[4184,4185],[4448,4607],[4959,4959],[5906,5908],[5938,5940],[5970,5971],[6002,6003],[6068,6069],[6071,6077],[6086,6086],[6089,6099],[6109,6109],[6155,6157],[6313,6313],[6432,6434],[6439,6440],[6450,6450],[6457,6459],[6679,6680],[6912,6915],[6964,6964],[6966,6970],[6972,6972],[6978,6978],[7019,7027],[7616,7626],[7678,7679],[8203,8207],[8234,8238],[8288,8291],[8298,8303],[8400,8431],[12330,12335],[12441,12442],[43014,43014],[43019,43019],[43045,43046],[64286,64286],[65024,65039],[65056,65059],[65279,65279],[65529,65531]],VQ=[[68097,68099],[68101,68102],[68108,68111],[68152,68154],[68159,68159],[119143,119145],[119155,119170],[119173,119179],[119210,119213],[119362,119364],[917505,917505],[917536,917631],[917760,917999]],HQ;function UQ(e,t){let n=0,r=t.length-1,i;if(e<t[0][0]||e>t[r][1])return!1;for(;r>=n;)if(i=n+r>>1,e>t[i][1])n=i+1;else if(e<t[i][0])r=i-1;else return!0;return!1}var WQ=class{constructor(){if(this.version=`6`,!HQ){HQ=new Uint8Array(65536),HQ.fill(1),HQ[0]=0,HQ.fill(0,1,32),HQ.fill(0,127,160),HQ.fill(2,4352,4448),HQ[9001]=2,HQ[9002]=2,HQ.fill(2,11904,42192),HQ[12351]=1,HQ.fill(2,44032,55204),HQ.fill(2,63744,64256),HQ.fill(2,65040,65050),HQ.fill(2,65072,65136),HQ.fill(2,65280,65377),HQ.fill(2,65504,65511);for(let e=0;e<BQ.length;++e)HQ.fill(0,BQ[e][0],BQ[e][1]+1)}}wcwidth(e){return e<32?0:e<127?1:e<65536?HQ[e]:UQ(e,VQ)?0:e>=131072&&e<=196605||e>=196608&&e<=262141?2:1}charProperties(e,t){let n=this.wcwidth(e),r=n===0&&t!==0;if(r){let e=GQ.extractWidth(t);e===0?r=!1:e>n&&(n=e)}return GQ.createPropertyValue(0,n,r)}},GQ=class e{constructor(){this._providers=Object.create(null),this._active=``,this._onChange=new Vq,this.onChange=this._onChange.event;let e=new WQ;this.register(e),this._active=e.version,this._activeProvider=e}static extractShouldJoin(e){return!!(e&1)}static extractWidth(e){return e>>1&3}static extractCharKind(e){return e>>3}static createPropertyValue(e,t,n=!1){return(e&16777215)<<3|(t&3)<<1|!!n}dispose(){this._onChange.dispose()}get versions(){return Object.keys(this._providers)}get activeVersion(){return this._active}set activeVersion(e){if(!this._providers[e])throw Error(`unknown Unicode version "${e}"`);this._active=e,this._activeProvider=this._providers[e],this._onChange.fire(e)}register(e){this._providers[e.version]=e}wcwidth(e){return this._activeProvider.wcwidth(e)}getStringCellWidth(t){let n=0,r=0,i=t.length;for(let a=0;a<i;++a){let o=t.charCodeAt(a);if(55296<=o&&o<=56319){if(++a>=i)return n+this.wcwidth(o);let e=t.charCodeAt(a);56320<=e&&e<=57343?o=(o-55296)*1024+e-56320+65536:n+=this.wcwidth(e)}let s=this.charProperties(o,r),c=e.extractWidth(s);e.extractShouldJoin(s)&&(c-=e.extractWidth(r)),n+=c,r=s}return n}charProperties(e,t){return this._activeProvider.charProperties(e,t)}},KQ=class{constructor(){this.glevel=0,this._charsets=[]}reset(){this.charset=void 0,this._charsets=[],this.glevel=0}setgLevel(e){this.glevel=e,this.charset=this._charsets[e]}setgCharset(e,t){this._charsets[e]=t,this.glevel===e&&(this.charset=t)}};function qQ(e){let t=e.buffer.lines.get(e.buffer.ybase+e.buffer.y-1)?.get(e.cols-1),n=e.buffer.lines.get(e.buffer.ybase+e.buffer.y);n&&t&&(n.isWrapped=t[3]!==0&&t[3]!==32)}var JQ=2147483647,YQ=256,XQ=class e{constructor(e=32,t=32){if(this.maxLength=e,this.maxSubParamsLength=t,t>YQ)throw Error(`maxSubParamsLength must not be greater than 256`);this.params=new Int32Array(e),this.length=0,this._subParams=new Int32Array(t),this._subParamsLength=0,this._subParamsIdx=new Uint16Array(e),this._rejectDigits=!1,this._rejectSubDigits=!1,this._digitIsSub=!1}static fromArray(t){let n=new e;if(!t.length)return n;for(let e=+!!Array.isArray(t[0]);e<t.length;++e){let r=t[e];if(Array.isArray(r))for(let e=0;e<r.length;++e)n.addSubParam(r[e]);else n.addParam(r)}return n}clone(){let t=new e(this.maxLength,this.maxSubParamsLength);return t.params.set(this.params),t.length=this.length,t._subParams.set(this._subParams),t._subParamsLength=this._subParamsLength,t._subParamsIdx.set(this._subParamsIdx),t._rejectDigits=this._rejectDigits,t._rejectSubDigits=this._rejectSubDigits,t._digitIsSub=this._digitIsSub,t}toArray(){let e=[];for(let t=0;t<this.length;++t){e.push(this.params[t]);let n=this._subParamsIdx[t]>>8,r=this._subParamsIdx[t]&255;r-n>0&&e.push(Array.prototype.slice.call(this._subParams,n,r))}return e}reset(){this.length=0,this._subParamsLength=0,this._rejectDigits=!1,this._rejectSubDigits=!1,this._digitIsSub=!1}addParam(e){if(this._digitIsSub=!1,this.length>=this.maxLength)this._rejectDigits=!0;else{if(e<-1)throw Error(`values lesser than -1 are not allowed`);this._subParamsIdx[this.length]=this._subParamsLength<<8|this._subParamsLength,this.params[this.length++]=e>JQ?JQ:e}}addSubParam(e){if(this._digitIsSub=!0,this.length){if(this._rejectDigits||this._subParamsLength>=this.maxSubParamsLength){this._rejectSubDigits=!0;return}if(e<-1)throw Error(`values lesser than -1 are not allowed`);this._subParams[this._subParamsLength++]=e>JQ?JQ:e,this._subParamsIdx[this.length-1]++}}hasSubParams(e){return(this._subParamsIdx[e]&255)-(this._subParamsIdx[e]>>8)>0}getSubParams(e){let t=this._subParamsIdx[e]>>8,n=this._subParamsIdx[e]&255;return n-t>0?this._subParams.subarray(t,n):null}getSubParamsAll(){let e={};for(let t=0;t<this.length;++t){let n=this._subParamsIdx[t]>>8,r=this._subParamsIdx[t]&255;r-n>0&&(e[t]=this._subParams.slice(n,r))}return e}addDigit(e){let t;if(this._rejectDigits||!(t=this._digitIsSub?this._subParamsLength:this.length)||this._digitIsSub&&this._rejectSubDigits)return;let n=this._digitIsSub?this._subParams:this.params,r=n[t-1];n[t-1]=~r?Math.min(r*10+e,JQ):e}},ZQ=[],QQ=class{constructor(){this._state=0,this._active=ZQ,this._id=-1,this._handlers=Object.create(null),this._handlerFb=()=>{},this._stack={paused:!1,loopPosition:0,fallThrough:!1}}registerHandler(e,t){this._handlers[e]===void 0&&(this._handlers[e]=[]);let n=this._handlers[e];return n.push(t),{dispose:()=>{let e=n.indexOf(t);e!==-1&&n.splice(e,1)}}}clearHandler(e){this._handlers[e]&&delete this._handlers[e]}setHandlerFallback(e){this._handlerFb=e}dispose(){this._handlers=Object.create(null),this._handlerFb=()=>{},this._active=ZQ}reset(){if(this._state===2)for(let e=this._stack.paused?this._stack.loopPosition-1:this._active.length-1;e>=0;--e)this._active[e].end(!1);this._stack.paused=!1,this._active=ZQ,this._id=-1,this._state=0}_start(){if(this._active=this._handlers[this._id]||ZQ,!this._active.length)this._handlerFb(this._id,`START`);else for(let e=this._active.length-1;e>=0;e--)this._active[e].start()}_put(e,t,n){if(!this._active.length)this._handlerFb(this._id,`PUT`,vK(e,t,n));else for(let r=this._active.length-1;r>=0;r--)this._active[r].put(e,t,n)}start(){this.reset(),this._state=1}put(e,t,n){if(this._state!==3){if(this._state===1)for(;t<n;){let n=e[t++];if(n===59){this._state=2,this._start();break}if(n<48||57<n){this._state=3;return}this._id===-1&&(this._id=0),this._id=this._id*10+n-48}this._state===2&&n-t>0&&this._put(e,t,n)}}end(e,t=!0){if(this._state!==0){if(this._state!==3){if(this._state===1&&this._start(),!this._active.length)this._handlerFb(this._id,`END`,e);else{let n=!1,r=this._active.length-1,i=!1;if(this._stack.paused&&(r=this._stack.loopPosition-1,n=t,i=this._stack.fallThrough,this._stack.paused=!1),!i&&n===!1){for(;r>=0&&(n=this._active[r].end(e),n!==!0);r--)if(n instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=r,this._stack.fallThrough=!1,n;r--}for(;r>=0;r--)if(n=this._active[r].end(!1),n instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=r,this._stack.fallThrough=!0,n}}this._active=ZQ,this._id=-1,this._state=0}}},$Q=class{constructor(e){this._handler=e,this._data=``,this._hitLimit=!1}start(){this._data=``,this._hitLimit=!1}put(e,t,n){this._hitLimit||(this._data+=vK(e,t,n),this._data.length>1e7&&(this._data=``,this._hitLimit=!0))}end(e){let t=!1;if(this._hitLimit)t=!1;else if(e&&(t=this._handler(this._data),t instanceof Promise))return t.then(e=>(this._data=``,this._hitLimit=!1,e));return this._data=``,this._hitLimit=!1,t}},e$=[],t$=class{constructor(){this._handlers=Object.create(null),this._active=e$,this._ident=0,this._handlerFb=()=>{},this._stack={paused:!1,loopPosition:0,fallThrough:!1}}dispose(){this._handlers=Object.create(null),this._handlerFb=()=>{},this._active=e$}registerHandler(e,t){this._handlers[e]===void 0&&(this._handlers[e]=[]);let n=this._handlers[e];return n.push(t),{dispose:()=>{let e=n.indexOf(t);e!==-1&&n.splice(e,1)}}}clearHandler(e){this._handlers[e]&&delete this._handlers[e]}setHandlerFallback(e){this._handlerFb=e}reset(){if(this._active.length)for(let e=this._stack.paused?this._stack.loopPosition-1:this._active.length-1;e>=0;--e)this._active[e].unhook(!1);this._stack.paused=!1,this._active=e$,this._ident=0}hook(e,t){if(this.reset(),this._ident=e,this._active=this._handlers[e]||e$,!this._active.length)this._handlerFb(this._ident,`HOOK`,t);else for(let e=this._active.length-1;e>=0;e--)this._active[e].hook(t)}put(e,t,n){if(!this._active.length)this._handlerFb(this._ident,`PUT`,vK(e,t,n));else for(let r=this._active.length-1;r>=0;r--)this._active[r].put(e,t,n)}unhook(e,t=!0){if(!this._active.length)this._handlerFb(this._ident,`UNHOOK`,e);else{let n=!1,r=this._active.length-1,i=!1;if(this._stack.paused&&(r=this._stack.loopPosition-1,n=t,i=this._stack.fallThrough,this._stack.paused=!1),!i&&n===!1){for(;r>=0&&(n=this._active[r].unhook(e),n!==!0);r--)if(n instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=r,this._stack.fallThrough=!1,n;r--}for(;r>=0;r--)if(n=this._active[r].unhook(!1),n instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=r,this._stack.fallThrough=!0,n}this._active=e$,this._ident=0}},n$=new XQ;n$.addParam(0);var r$=class{constructor(e){this._handler=e,this._data=``,this._params=n$,this._hitLimit=!1}hook(e){this._params=e.length>1||e.params[0]?e.clone():n$,this._data=``,this._hitLimit=!1}put(e,t,n){this._hitLimit||(this._data+=vK(e,t,n),this._data.length>1e7&&(this._data=``,this._hitLimit=!0))}unhook(e){let t=!1;if(this._hitLimit)t=!1;else if(e&&(t=this._handler(this._data,this._params),t instanceof Promise))return t.then(e=>(this._params=n$,this._data=``,this._hitLimit=!1,e));return this._params=n$,this._data=``,this._hitLimit=!1,t}},i$=class{constructor(e){this.table=new Uint8Array(e)}setDefault(e,t){this.table.fill(e<<4|t)}add(e,t,n,r){this.table[t<<8|e]=n<<4|r}addMany(e,t,n,r){for(let i=0;i<e.length;i++)this.table[t<<8|e[i]]=n<<4|r}},a$=160,o$=function(){let e=new i$(4095),t=Array.apply(null,Array(256)).map((e,t)=>t),n=(e,n)=>t.slice(e,n),r=n(32,127),i=n(0,24);i.push(25),i.push.apply(i,n(28,32));let a=n(0,14),o;for(o in e.setDefault(1,0),e.addMany(r,0,2,0),a)e.addMany([24,26,153,154],o,3,0),e.addMany(n(128,144),o,3,0),e.addMany(n(144,152),o,3,0),e.add(156,o,0,0),e.add(27,o,11,1),e.add(157,o,4,8),e.addMany([152,158,159],o,0,7),e.add(155,o,11,3),e.add(144,o,11,9);return e.addMany(i,0,3,0),e.addMany(i,1,3,1),e.add(127,1,0,1),e.addMany(i,8,0,8),e.addMany(i,3,3,3),e.add(127,3,0,3),e.addMany(i,4,3,4),e.add(127,4,0,4),e.addMany(i,6,3,6),e.addMany(i,5,3,5),e.add(127,5,0,5),e.addMany(i,2,3,2),e.add(127,2,0,2),e.add(93,1,4,8),e.addMany(r,8,5,8),e.add(127,8,5,8),e.addMany([156,27,24,26,7],8,6,0),e.addMany(n(28,32),8,0,8),e.addMany([88,94,95],1,0,7),e.addMany(r,7,0,7),e.addMany(i,7,0,7),e.add(156,7,0,0),e.add(127,7,0,7),e.add(91,1,11,3),e.addMany(n(64,127),3,7,0),e.addMany(n(48,60),3,8,4),e.addMany([60,61,62,63],3,9,4),e.addMany(n(48,60),4,8,4),e.addMany(n(64,127),4,7,0),e.addMany([60,61,62,63],4,0,6),e.addMany(n(32,64),6,0,6),e.add(127,6,0,6),e.addMany(n(64,127),6,0,0),e.addMany(n(32,48),3,9,5),e.addMany(n(32,48),5,9,5),e.addMany(n(48,64),5,0,6),e.addMany(n(64,127),5,7,0),e.addMany(n(32,48),4,9,5),e.addMany(n(32,48),1,9,2),e.addMany(n(32,48),2,9,2),e.addMany(n(48,127),2,10,0),e.addMany(n(48,80),1,10,0),e.addMany(n(81,88),1,10,0),e.addMany([89,90,92],1,10,0),e.addMany(n(96,127),1,10,0),e.add(80,1,11,9),e.addMany(i,9,0,9),e.add(127,9,0,9),e.addMany(n(28,32),9,0,9),e.addMany(n(32,48),9,9,12),e.addMany(n(48,60),9,8,10),e.addMany([60,61,62,63],9,9,10),e.addMany(i,11,0,11),e.addMany(n(32,128),11,0,11),e.addMany(n(28,32),11,0,11),e.addMany(i,10,0,10),e.add(127,10,0,10),e.addMany(n(28,32),10,0,10),e.addMany(n(48,60),10,8,10),e.addMany([60,61,62,63],10,0,11),e.addMany(n(32,48),10,9,12),e.addMany(i,12,0,12),e.add(127,12,0,12),e.addMany(n(28,32),12,0,12),e.addMany(n(32,48),12,9,12),e.addMany(n(48,64),12,0,11),e.addMany(n(64,127),12,12,13),e.addMany(n(64,127),10,12,13),e.addMany(n(64,127),9,12,13),e.addMany(i,13,13,13),e.addMany(r,13,13,13),e.add(127,13,0,13),e.addMany([27,156,24,26],13,14,0),e.add(a$,0,2,0),e.add(a$,8,5,8),e.add(a$,6,0,6),e.add(a$,11,0,11),e.add(a$,13,13,13),e}(),s$=class extends xq{constructor(e=o$){super(),this._transitions=e,this._parseStack={state:0,handlers:[],handlerPos:0,transition:0,chunkPos:0},this.initialState=0,this.currentState=this.initialState,this._params=new XQ,this._params.addParam(0),this._collect=0,this.precedingJoinState=0,this._printHandlerFb=(e,t,n)=>{},this._executeHandlerFb=e=>{},this._csiHandlerFb=(e,t)=>{},this._escHandlerFb=e=>{},this._errorHandlerFb=e=>e,this._printHandler=this._printHandlerFb,this._executeHandlers=Object.create(null),this._csiHandlers=Object.create(null),this._escHandlers=Object.create(null),this._register(vq(()=>{this._csiHandlers=Object.create(null),this._executeHandlers=Object.create(null),this._escHandlers=Object.create(null)})),this._oscParser=this._register(new QQ),this._dcsParser=this._register(new t$),this._errorHandler=this._errorHandlerFb,this.registerEscHandler({final:`\\`},()=>!0)}_identifier(e,t=[64,126]){let n=0;if(e.prefix){if(e.prefix.length>1)throw Error(`only one byte as prefix supported`);if(n=e.prefix.charCodeAt(0),n&&60>n||n>63)throw Error(`prefix must be in range 0x3c .. 0x3f`)}if(e.intermediates){if(e.intermediates.length>2)throw Error(`only two bytes as intermediates are supported`);for(let t=0;t<e.intermediates.length;++t){let r=e.intermediates.charCodeAt(t);if(32>r||r>47)throw Error(`intermediate must be in range 0x20 .. 0x2f`);n<<=8,n|=r}}if(e.final.length!==1)throw Error(`final must be a single byte`);let r=e.final.charCodeAt(0);if(t[0]>r||r>t[1])throw Error(`final must be in range ${t[0]} .. ${t[1]}`);return n<<=8,n|=r,n}identToString(e){let t=[];for(;e;)t.push(String.fromCharCode(e&255)),e>>=8;return t.reverse().join(``)}setPrintHandler(e){this._printHandler=e}clearPrintHandler(){this._printHandler=this._printHandlerFb}registerEscHandler(e,t){let n=this._identifier(e,[48,126]);this._escHandlers[n]===void 0&&(this._escHandlers[n]=[]);let r=this._escHandlers[n];return r.push(t),{dispose:()=>{let e=r.indexOf(t);e!==-1&&r.splice(e,1)}}}clearEscHandler(e){this._escHandlers[this._identifier(e,[48,126])]&&delete this._escHandlers[this._identifier(e,[48,126])]}setEscHandlerFallback(e){this._escHandlerFb=e}setExecuteHandler(e,t){this._executeHandlers[e.charCodeAt(0)]=t}clearExecuteHandler(e){this._executeHandlers[e.charCodeAt(0)]&&delete this._executeHandlers[e.charCodeAt(0)]}setExecuteHandlerFallback(e){this._executeHandlerFb=e}registerCsiHandler(e,t){let n=this._identifier(e);this._csiHandlers[n]===void 0&&(this._csiHandlers[n]=[]);let r=this._csiHandlers[n];return r.push(t),{dispose:()=>{let e=r.indexOf(t);e!==-1&&r.splice(e,1)}}}clearCsiHandler(e){this._csiHandlers[this._identifier(e)]&&delete this._csiHandlers[this._identifier(e)]}setCsiHandlerFallback(e){this._csiHandlerFb=e}registerDcsHandler(e,t){return this._dcsParser.registerHandler(this._identifier(e),t)}clearDcsHandler(e){this._dcsParser.clearHandler(this._identifier(e))}setDcsHandlerFallback(e){this._dcsParser.setHandlerFallback(e)}registerOscHandler(e,t){return this._oscParser.registerHandler(e,t)}clearOscHandler(e){this._oscParser.clearHandler(e)}setOscHandlerFallback(e){this._oscParser.setHandlerFallback(e)}setErrorHandler(e){this._errorHandler=e}clearErrorHandler(){this._errorHandler=this._errorHandlerFb}reset(){this.currentState=this.initialState,this._oscParser.reset(),this._dcsParser.reset(),this._params.reset(),this._params.addParam(0),this._collect=0,this.precedingJoinState=0,this._parseStack.state!==0&&(this._parseStack.state=2,this._parseStack.handlers=[])}_preserveStack(e,t,n,r,i){this._parseStack.state=e,this._parseStack.handlers=t,this._parseStack.handlerPos=n,this._parseStack.transition=r,this._parseStack.chunkPos=i}parse(e,t,n){let r=0,i=0,a=0,o;if(this._parseStack.state){if(this._parseStack.state===2)this._parseStack.state=0,a=this._parseStack.chunkPos+1;else{if(n===void 0||this._parseStack.state===1)throw this._parseStack.state=1,Error(`improper continuation due to previous async handler, giving up parsing`);let t=this._parseStack.handlers,i=this._parseStack.handlerPos-1;switch(this._parseStack.state){case 3:if(n===!1&&i>-1){for(;i>=0&&(o=t[i](this._params),o!==!0);i--)if(o instanceof Promise)return this._parseStack.handlerPos=i,o}this._parseStack.handlers=[];break;case 4:if(n===!1&&i>-1){for(;i>=0&&(o=t[i](),o!==!0);i--)if(o instanceof Promise)return this._parseStack.handlerPos=i,o}this._parseStack.handlers=[];break;case 6:if(r=e[this._parseStack.chunkPos],o=this._dcsParser.unhook(r!==24&&r!==26,n),o)return o;r===27&&(this._parseStack.transition|=1),this._params.reset(),this._params.addParam(0),this._collect=0;break;case 5:if(r=e[this._parseStack.chunkPos],o=this._oscParser.end(r!==24&&r!==26,n),o)return o;r===27&&(this._parseStack.transition|=1),this._params.reset(),this._params.addParam(0),this._collect=0}this._parseStack.state=0,a=this._parseStack.chunkPos+1,this.precedingJoinState=0,this.currentState=this._parseStack.transition&15}}for(let n=a;n<t;++n){switch(r=e[n],i=this._transitions.table[this.currentState<<8|(r<160?r:a$)],i>>4){case 2:for(let i=n+1;;++i)if(i>=t||(r=e[i])<32||r>126&&r<a$||++i>=t||(r=e[i])<32||r>126&&r<a$||++i>=t||(r=e[i])<32||r>126&&r<a$||++i>=t||(r=e[i])<32||r>126&&r<a$){this._printHandler(e,n,i),n=i-1;break}break;case 3:this._executeHandlers[r]?this._executeHandlers[r]():this._executeHandlerFb(r),this.precedingJoinState=0;break;case 0:break;case 1:if(this._errorHandler({position:n,code:r,currentState:this.currentState,collect:this._collect,params:this._params,abort:!1}).abort)return;break;case 7:let a=this._csiHandlers[this._collect<<8|r],s=a?a.length-1:-1;for(;s>=0&&(o=a[s](this._params),o!==!0);s--)if(o instanceof Promise)return this._preserveStack(3,a,s,i,n),o;s<0&&this._csiHandlerFb(this._collect<<8|r,this._params),this.precedingJoinState=0;break;case 8:do switch(r){case 59:this._params.addParam(0);break;case 58:this._params.addSubParam(-1);break;default:this._params.addDigit(r-48)}while(++n<t&&(r=e[n])>47&&r<60);n--;break;case 9:this._collect<<=8,this._collect|=r;break;case 10:let c=this._escHandlers[this._collect<<8|r],l=c?c.length-1:-1;for(;l>=0&&(o=c[l](),o!==!0);l--)if(o instanceof Promise)return this._preserveStack(4,c,l,i,n),o;l<0&&this._escHandlerFb(this._collect<<8|r),this.precedingJoinState=0;break;case 11:this._params.reset(),this._params.addParam(0),this._collect=0;break;case 12:this._dcsParser.hook(this._collect<<8|r,this._params);break;case 13:for(let i=n+1;;++i)if(i>=t||(r=e[i])===24||r===26||r===27||r>127&&r<a$){this._dcsParser.put(e,n,i),n=i-1;break}break;case 14:if(o=this._dcsParser.unhook(r!==24&&r!==26),o)return this._preserveStack(6,[],0,i,n),o;r===27&&(i|=1),this._params.reset(),this._params.addParam(0),this._collect=0,this.precedingJoinState=0;break;case 4:this._oscParser.start();break;case 5:for(let i=n+1;;i++)if(i>=t||(r=e[i])<32||r>127&&r<a$){this._oscParser.put(e,n,i),n=i-1;break}break;case 6:if(o=this._oscParser.end(r!==24&&r!==26),o)return this._preserveStack(5,[],0,i,n),o;r===27&&(i|=1),this._params.reset(),this._params.addParam(0),this._collect=0,this.precedingJoinState=0}this.currentState=i&15}}},c$=/^([\da-f])\/([\da-f])\/([\da-f])$|^([\da-f]{2})\/([\da-f]{2})\/([\da-f]{2})$|^([\da-f]{3})\/([\da-f]{3})\/([\da-f]{3})$|^([\da-f]{4})\/([\da-f]{4})\/([\da-f]{4})$/,l$=/^[\da-f]+$/;function u$(e){if(!e)return;let t=e.toLowerCase();if(t.indexOf(`rgb:`)===0){t=t.slice(4);let e=c$.exec(t);if(e){let t=e[1]?15:e[4]?255:e[7]?4095:65535;return[Math.round(parseInt(e[1]||e[4]||e[7]||e[10],16)/t*255),Math.round(parseInt(e[2]||e[5]||e[8]||e[11],16)/t*255),Math.round(parseInt(e[3]||e[6]||e[9]||e[12],16)/t*255)]}}else if(t.indexOf(`#`)===0&&(t=t.slice(1),l$.exec(t)&&[3,6,9,12].includes(t.length))){let e=t.length/3,n=[0,0,0];for(let r=0;r<3;++r){let i=parseInt(t.slice(e*r,e*r+e),16);n[r]=e===1?i<<4:e===2?i:e===3?i>>4:i>>8}return n}}function d$(e,t){let n=e.toString(16),r=n.length<2?`0`+n:n;switch(t){case 4:return n[0];case 8:return r;case 12:return(r+r).slice(0,3);default:return r+r}}function f$(e,t=16){let[n,r,i]=e;return`rgb:${d$(n,t)}/${d$(r,t)}/${d$(i,t)}`}var p$={"(":0,")":1,"*":2,"+":3,"-":1,".":2},m$=131072,h$=10;function g$(e,t){if(e>24)return t.setWinLines||!1;switch(e){case 1:return!!t.restoreWin;case 2:return!!t.minimizeWin;case 3:return!!t.setWinPosition;case 4:return!!t.setWinSizePixels;case 5:return!!t.raiseWin;case 6:return!!t.lowerWin;case 7:return!!t.refreshWin;case 8:return!!t.setWinSizeChars;case 9:return!!t.maximizeWin;case 10:return!!t.fullscreenWin;case 11:return!!t.getWinState;case 13:return!!t.getWinPosition;case 14:return!!t.getWinSizePixels;case 15:return!!t.getScreenSizePixels;case 16:return!!t.getCellSizePixels;case 18:return!!t.getWinSizeChars;case 19:return!!t.getScreenSizeChars;case 20:return!!t.getIconTitle;case 21:return!!t.getWinTitle;case 22:return!!t.pushTitle;case 23:return!!t.popTitle;case 24:return!!t.setWinLines}return!1}var _$=5e3,v$=0,y$=class extends xq{constructor(e,t,n,r,i,a,o,s,c=new s$){super(),this._bufferService=e,this._charsetService=t,this._coreService=n,this._logService=r,this._optionsService=i,this._oscLinkService=a,this._coreMouseService=o,this._unicodeService=s,this._parser=c,this._parseBuffer=new Uint32Array(4096),this._stringDecoder=new yK,this._utf8Decoder=new bK,this._windowTitle=``,this._iconName=``,this._windowTitleStack=[],this._iconNameStack=[],this._curAttrData=cQ.clone(),this._eraseAttrDataInternal=cQ.clone(),this._onRequestBell=this._register(new Vq),this.onRequestBell=this._onRequestBell.event,this._onRequestRefreshRows=this._register(new Vq),this.onRequestRefreshRows=this._onRequestRefreshRows.event,this._onRequestReset=this._register(new Vq),this.onRequestReset=this._onRequestReset.event,this._onRequestSendFocus=this._register(new Vq),this.onRequestSendFocus=this._onRequestSendFocus.event,this._onRequestSyncScrollBar=this._register(new Vq),this.onRequestSyncScrollBar=this._onRequestSyncScrollBar.event,this._onRequestWindowsOptionsReport=this._register(new Vq),this.onRequestWindowsOptionsReport=this._onRequestWindowsOptionsReport.event,this._onA11yChar=this._register(new Vq),this.onA11yChar=this._onA11yChar.event,this._onA11yTab=this._register(new Vq),this.onA11yTab=this._onA11yTab.event,this._onCursorMove=this._register(new Vq),this.onCursorMove=this._onCursorMove.event,this._onLineFeed=this._register(new Vq),this.onLineFeed=this._onLineFeed.event,this._onScroll=this._register(new Vq),this.onScroll=this._onScroll.event,this._onTitleChange=this._register(new Vq),this.onTitleChange=this._onTitleChange.event,this._onColor=this._register(new Vq),this.onColor=this._onColor.event,this._parseStack={paused:!1,cursorStartX:0,cursorStartY:0,decodedLength:0,position:0},this._specialColors=[256,257,258],this._register(this._parser),this._dirtyRowTracker=new b$(this._bufferService),this._activeBuffer=this._bufferService.buffer,this._register(this._bufferService.buffers.onBufferActivate(e=>this._activeBuffer=e.activeBuffer)),this._parser.setCsiHandlerFallback((e,t)=>{this._logService.debug(`Unknown CSI code: `,{identifier:this._parser.identToString(e),params:t.toArray()})}),this._parser.setEscHandlerFallback(e=>{this._logService.debug(`Unknown ESC code: `,{identifier:this._parser.identToString(e)})}),this._parser.setExecuteHandlerFallback(e=>{this._logService.debug(`Unknown EXECUTE code: `,{code:e})}),this._parser.setOscHandlerFallback((e,t,n)=>{this._logService.debug(`Unknown OSC code: `,{identifier:e,action:t,data:n})}),this._parser.setDcsHandlerFallback((e,t,n)=>{t===`HOOK`&&(n=n.toArray()),this._logService.debug(`Unknown DCS code: `,{identifier:this._parser.identToString(e),action:t,payload:n})}),this._parser.setPrintHandler((e,t,n)=>this.print(e,t,n)),this._parser.registerCsiHandler({final:`@`},e=>this.insertChars(e)),this._parser.registerCsiHandler({intermediates:` `,final:`@`},e=>this.scrollLeft(e)),this._parser.registerCsiHandler({final:`A`},e=>this.cursorUp(e)),this._parser.registerCsiHandler({intermediates:` `,final:`A`},e=>this.scrollRight(e)),this._parser.registerCsiHandler({final:`B`},e=>this.cursorDown(e)),this._parser.registerCsiHandler({final:`C`},e=>this.cursorForward(e)),this._parser.registerCsiHandler({final:`D`},e=>this.cursorBackward(e)),this._parser.registerCsiHandler({final:`E`},e=>this.cursorNextLine(e)),this._parser.registerCsiHandler({final:`F`},e=>this.cursorPrecedingLine(e)),this._parser.registerCsiHandler({final:`G`},e=>this.cursorCharAbsolute(e)),this._parser.registerCsiHandler({final:`H`},e=>this.cursorPosition(e)),this._parser.registerCsiHandler({final:`I`},e=>this.cursorForwardTab(e)),this._parser.registerCsiHandler({final:`J`},e=>this.eraseInDisplay(e,!1)),this._parser.registerCsiHandler({prefix:`?`,final:`J`},e=>this.eraseInDisplay(e,!0)),this._parser.registerCsiHandler({final:`K`},e=>this.eraseInLine(e,!1)),this._parser.registerCsiHandler({prefix:`?`,final:`K`},e=>this.eraseInLine(e,!0)),this._parser.registerCsiHandler({final:`L`},e=>this.insertLines(e)),this._parser.registerCsiHandler({final:`M`},e=>this.deleteLines(e)),this._parser.registerCsiHandler({final:`P`},e=>this.deleteChars(e)),this._parser.registerCsiHandler({final:`S`},e=>this.scrollUp(e)),this._parser.registerCsiHandler({final:`T`},e=>this.scrollDown(e)),this._parser.registerCsiHandler({final:`X`},e=>this.eraseChars(e)),this._parser.registerCsiHandler({final:`Z`},e=>this.cursorBackwardTab(e)),this._parser.registerCsiHandler({final:"`"},e=>this.charPosAbsolute(e)),this._parser.registerCsiHandler({final:`a`},e=>this.hPositionRelative(e)),this._parser.registerCsiHandler({final:`b`},e=>this.repeatPrecedingCharacter(e)),this._parser.registerCsiHandler({final:`c`},e=>this.sendDeviceAttributesPrimary(e)),this._parser.registerCsiHandler({prefix:`>`,final:`c`},e=>this.sendDeviceAttributesSecondary(e)),this._parser.registerCsiHandler({final:`d`},e=>this.linePosAbsolute(e)),this._parser.registerCsiHandler({final:`e`},e=>this.vPositionRelative(e)),this._parser.registerCsiHandler({final:`f`},e=>this.hVPosition(e)),this._parser.registerCsiHandler({final:`g`},e=>this.tabClear(e)),this._parser.registerCsiHandler({final:`h`},e=>this.setMode(e)),this._parser.registerCsiHandler({prefix:`?`,final:`h`},e=>this.setModePrivate(e)),this._parser.registerCsiHandler({final:`l`},e=>this.resetMode(e)),this._parser.registerCsiHandler({prefix:`?`,final:`l`},e=>this.resetModePrivate(e)),this._parser.registerCsiHandler({final:`m`},e=>this.charAttributes(e)),this._parser.registerCsiHandler({final:`n`},e=>this.deviceStatus(e)),this._parser.registerCsiHandler({prefix:`?`,final:`n`},e=>this.deviceStatusPrivate(e)),this._parser.registerCsiHandler({intermediates:`!`,final:`p`},e=>this.softReset(e)),this._parser.registerCsiHandler({intermediates:` `,final:`q`},e=>this.setCursorStyle(e)),this._parser.registerCsiHandler({final:`r`},e=>this.setScrollRegion(e)),this._parser.registerCsiHandler({final:`s`},e=>this.saveCursor(e)),this._parser.registerCsiHandler({final:`t`},e=>this.windowOptions(e)),this._parser.registerCsiHandler({final:`u`},e=>this.restoreCursor(e)),this._parser.registerCsiHandler({intermediates:`'`,final:`}`},e=>this.insertColumns(e)),this._parser.registerCsiHandler({intermediates:`'`,final:`~`},e=>this.deleteColumns(e)),this._parser.registerCsiHandler({intermediates:`"`,final:`q`},e=>this.selectProtected(e)),this._parser.registerCsiHandler({intermediates:`$`,final:`p`},e=>this.requestMode(e,!0)),this._parser.registerCsiHandler({prefix:`?`,intermediates:`$`,final:`p`},e=>this.requestMode(e,!1)),this._parser.setExecuteHandler($.BEL,()=>this.bell()),this._parser.setExecuteHandler($.LF,()=>this.lineFeed()),this._parser.setExecuteHandler($.VT,()=>this.lineFeed()),this._parser.setExecuteHandler($.FF,()=>this.lineFeed()),this._parser.setExecuteHandler($.CR,()=>this.carriageReturn()),this._parser.setExecuteHandler($.BS,()=>this.backspace()),this._parser.setExecuteHandler($.HT,()=>this.tab()),this._parser.setExecuteHandler($.SO,()=>this.shiftOut()),this._parser.setExecuteHandler($.SI,()=>this.shiftIn()),this._parser.setExecuteHandler(lX.IND,()=>this.index()),this._parser.setExecuteHandler(lX.NEL,()=>this.nextLine()),this._parser.setExecuteHandler(lX.HTS,()=>this.tabSet()),this._parser.registerOscHandler(0,new $Q(e=>(this.setTitle(e),this.setIconName(e),!0))),this._parser.registerOscHandler(1,new $Q(e=>this.setIconName(e))),this._parser.registerOscHandler(2,new $Q(e=>this.setTitle(e))),this._parser.registerOscHandler(4,new $Q(e=>this.setOrReportIndexedColor(e))),this._parser.registerOscHandler(8,new $Q(e=>this.setHyperlink(e))),this._parser.registerOscHandler(10,new $Q(e=>this.setOrReportFgColor(e))),this._parser.registerOscHandler(11,new $Q(e=>this.setOrReportBgColor(e))),this._parser.registerOscHandler(12,new $Q(e=>this.setOrReportCursorColor(e))),this._parser.registerOscHandler(104,new $Q(e=>this.restoreIndexedColor(e))),this._parser.registerOscHandler(110,new $Q(e=>this.restoreFgColor(e))),this._parser.registerOscHandler(111,new $Q(e=>this.restoreBgColor(e))),this._parser.registerOscHandler(112,new $Q(e=>this.restoreCursorColor(e))),this._parser.registerEscHandler({final:`7`},()=>this.saveCursor()),this._parser.registerEscHandler({final:`8`},()=>this.restoreCursor()),this._parser.registerEscHandler({final:`D`},()=>this.index()),this._parser.registerEscHandler({final:`E`},()=>this.nextLine()),this._parser.registerEscHandler({final:`H`},()=>this.tabSet()),this._parser.registerEscHandler({final:`M`},()=>this.reverseIndex()),this._parser.registerEscHandler({final:`=`},()=>this.keypadApplicationMode()),this._parser.registerEscHandler({final:`>`},()=>this.keypadNumericMode()),this._parser.registerEscHandler({final:`c`},()=>this.fullReset()),this._parser.registerEscHandler({final:`n`},()=>this.setgLevel(2)),this._parser.registerEscHandler({final:`o`},()=>this.setgLevel(3)),this._parser.registerEscHandler({final:`|`},()=>this.setgLevel(3)),this._parser.registerEscHandler({final:`}`},()=>this.setgLevel(2)),this._parser.registerEscHandler({final:`~`},()=>this.setgLevel(1)),this._parser.registerEscHandler({intermediates:`%`,final:`@`},()=>this.selectDefaultCharset()),this._parser.registerEscHandler({intermediates:`%`,final:`G`},()=>this.selectDefaultCharset());for(let e in yQ)this._parser.registerEscHandler({intermediates:`(`,final:e},()=>this.selectCharset(`(`+e)),this._parser.registerEscHandler({intermediates:`)`,final:e},()=>this.selectCharset(`)`+e)),this._parser.registerEscHandler({intermediates:`*`,final:e},()=>this.selectCharset(`*`+e)),this._parser.registerEscHandler({intermediates:`+`,final:e},()=>this.selectCharset(`+`+e)),this._parser.registerEscHandler({intermediates:`-`,final:e},()=>this.selectCharset(`-`+e)),this._parser.registerEscHandler({intermediates:`.`,final:e},()=>this.selectCharset(`.`+e)),this._parser.registerEscHandler({intermediates:`/`,final:e},()=>this.selectCharset(`/`+e));this._parser.registerEscHandler({intermediates:`#`,final:`8`},()=>this.screenAlignmentPattern()),this._parser.setErrorHandler(e=>(this._logService.error(`Parsing error: `,e),e)),this._parser.registerDcsHandler({intermediates:`$`,final:`q`},new r$((e,t)=>this.requestStatusString(e,t)))}getAttrData(){return this._curAttrData}_preserveStack(e,t,n,r){this._parseStack.paused=!0,this._parseStack.cursorStartX=e,this._parseStack.cursorStartY=t,this._parseStack.decodedLength=n,this._parseStack.position=r}_logSlowResolvingAsync(e){this._logService.logLevel<=3&&Promise.race([e,new Promise((e,t)=>setTimeout(()=>t(`#SLOW_TIMEOUT`),_$))]).catch(e=>{if(e!==`#SLOW_TIMEOUT`)throw e;console.warn(`async parser handler taking longer than ${_$} ms`)})}_getCurrentLinkId(){return this._curAttrData.extended.urlId}parse(e,t){let n,r=this._activeBuffer.x,i=this._activeBuffer.y,a=0,o=this._parseStack.paused;if(o){if(n=this._parser.parse(this._parseBuffer,this._parseStack.decodedLength,t))return this._logSlowResolvingAsync(n),n;r=this._parseStack.cursorStartX,i=this._parseStack.cursorStartY,this._parseStack.paused=!1,e.length>m$&&(a=this._parseStack.position+m$)}if(this._logService.logLevel<=1&&this._logService.debug(`parsing data ${typeof e==`string`?` "${e}"`:` "${Array.prototype.map.call(e,e=>String.fromCharCode(e)).join(``)}"`}`),this._logService.logLevel===0&&this._logService.trace(`parsing data (codes)`,typeof e==`string`?e.split(``).map(e=>e.charCodeAt(0)):e),this._parseBuffer.length<e.length&&this._parseBuffer.length<m$&&(this._parseBuffer=new Uint32Array(Math.min(e.length,m$))),o||this._dirtyRowTracker.clearRange(),e.length>m$)for(let t=a;t<e.length;t+=m$){let a=t+m$<e.length?t+m$:e.length,o=typeof e==`string`?this._stringDecoder.decode(e.substring(t,a),this._parseBuffer):this._utf8Decoder.decode(e.subarray(t,a),this._parseBuffer);if(n=this._parser.parse(this._parseBuffer,o))return this._preserveStack(r,i,o,t),this._logSlowResolvingAsync(n),n}else if(!o){let t=typeof e==`string`?this._stringDecoder.decode(e,this._parseBuffer):this._utf8Decoder.decode(e,this._parseBuffer);if(n=this._parser.parse(this._parseBuffer,t))return this._preserveStack(r,i,t,0),this._logSlowResolvingAsync(n),n}(this._activeBuffer.x!==r||this._activeBuffer.y!==i)&&this._onCursorMove.fire();let s=this._dirtyRowTracker.end+(this._bufferService.buffer.ybase-this._bufferService.buffer.ydisp),c=this._dirtyRowTracker.start+(this._bufferService.buffer.ybase-this._bufferService.buffer.ydisp);c<this._bufferService.rows&&this._onRequestRefreshRows.fire({start:Math.min(c,this._bufferService.rows-1),end:Math.min(s,this._bufferService.rows-1)})}print(e,t,n){let r,i,a=this._charsetService.charset,o=this._optionsService.rawOptions.screenReaderMode,s=this._bufferService.cols,c=this._coreService.decPrivateModes.wraparound,l=this._coreService.modes.insertMode,u=this._curAttrData,d=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y);this._dirtyRowTracker.markDirty(this._activeBuffer.y),this._activeBuffer.x&&n-t>0&&d.getWidth(this._activeBuffer.x-1)===2&&d.setCellFromCodepoint(this._activeBuffer.x-1,0,1,u);let f=this._parser.precedingJoinState;for(let p=t;p<n;++p){if(r=e[p],r<127&&a){let e=a[String.fromCharCode(r)];e&&(r=e.charCodeAt(0))}let t=this._unicodeService.charProperties(r,f);i=GQ.extractWidth(t);let n=GQ.extractShouldJoin(t),m=n?GQ.extractWidth(f):0;if(f=t,o&&this._onA11yChar.fire(_K(r)),this._getCurrentLinkId()&&this._oscLinkService.addLineToLink(this._getCurrentLinkId(),this._activeBuffer.ybase+this._activeBuffer.y),this._activeBuffer.x+i-m>s){if(c){let e=d,t=this._activeBuffer.x-m;for(this._activeBuffer.x=m,this._activeBuffer.y++,this._activeBuffer.y===this._activeBuffer.scrollBottom+1?(this._activeBuffer.y--,this._bufferService.scroll(this._eraseAttrData(),!0)):(this._activeBuffer.y>=this._bufferService.rows&&(this._activeBuffer.y=this._bufferService.rows-1),this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y).isWrapped=!0),d=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y),m>0&&d instanceof dQ&&d.copyCellsFrom(e,t,0,m,!1);t<s;)e.setCellFromCodepoint(t++,0,1,u)}else if(this._activeBuffer.x=s-1,i===2)continue}if(n&&this._activeBuffer.x){let e=d.getWidth(this._activeBuffer.x-1)?1:2;d.addCodepointToCell(this._activeBuffer.x-e,r,i);for(let e=i-m;--e>=0;)d.setCellFromCodepoint(this._activeBuffer.x++,0,0,u)}else if(l&&(d.insertCells(this._activeBuffer.x,i-m,this._activeBuffer.getNullCell(u)),d.getWidth(s-1)===2&&d.setCellFromCodepoint(s-1,0,1,u)),d.setCellFromCodepoint(this._activeBuffer.x++,r,i,u),i>0)for(;--i;)d.setCellFromCodepoint(this._activeBuffer.x++,0,0,u)}this._parser.precedingJoinState=f,this._activeBuffer.x<s&&n-t>0&&d.getWidth(this._activeBuffer.x)===0&&!d.hasContent(this._activeBuffer.x)&&d.setCellFromCodepoint(this._activeBuffer.x,0,1,u),this._dirtyRowTracker.markDirty(this._activeBuffer.y)}registerCsiHandler(e,t){return e.final===`t`&&!e.prefix&&!e.intermediates?this._parser.registerCsiHandler(e,e=>!g$(e.params[0],this._optionsService.rawOptions.windowOptions)||t(e)):this._parser.registerCsiHandler(e,t)}registerDcsHandler(e,t){return this._parser.registerDcsHandler(e,new r$(t))}registerEscHandler(e,t){return this._parser.registerEscHandler(e,t)}registerOscHandler(e,t){return this._parser.registerOscHandler(e,new $Q(t))}bell(){return this._onRequestBell.fire(),!0}lineFeed(){return this._dirtyRowTracker.markDirty(this._activeBuffer.y),this._optionsService.rawOptions.convertEol&&(this._activeBuffer.x=0),this._activeBuffer.y++,this._activeBuffer.y===this._activeBuffer.scrollBottom+1?(this._activeBuffer.y--,this._bufferService.scroll(this._eraseAttrData())):this._activeBuffer.y>=this._bufferService.rows?this._activeBuffer.y=this._bufferService.rows-1:this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y).isWrapped=!1,this._activeBuffer.x>=this._bufferService.cols&&this._activeBuffer.x--,this._dirtyRowTracker.markDirty(this._activeBuffer.y),this._onLineFeed.fire(),!0}carriageReturn(){return this._activeBuffer.x=0,!0}backspace(){if(!this._coreService.decPrivateModes.reverseWraparound)return this._restrictCursor(),this._activeBuffer.x>0&&this._activeBuffer.x--,!0;if(this._restrictCursor(this._bufferService.cols),this._activeBuffer.x>0)this._activeBuffer.x--;else if(this._activeBuffer.x===0&&this._activeBuffer.y>this._activeBuffer.scrollTop&&this._activeBuffer.y<=this._activeBuffer.scrollBottom&&this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y)?.isWrapped){this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y).isWrapped=!1,this._activeBuffer.y--,this._activeBuffer.x=this._bufferService.cols-1;let e=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y);e.hasWidth(this._activeBuffer.x)&&!e.hasContent(this._activeBuffer.x)&&this._activeBuffer.x--}return this._restrictCursor(),!0}tab(){if(this._activeBuffer.x>=this._bufferService.cols)return!0;let e=this._activeBuffer.x;return this._activeBuffer.x=this._activeBuffer.nextStop(),this._optionsService.rawOptions.screenReaderMode&&this._onA11yTab.fire(this._activeBuffer.x-e),!0}shiftOut(){return this._charsetService.setgLevel(1),!0}shiftIn(){return this._charsetService.setgLevel(0),!0}_restrictCursor(e=this._bufferService.cols-1){this._activeBuffer.x=Math.min(e,Math.max(0,this._activeBuffer.x)),this._activeBuffer.y=this._coreService.decPrivateModes.origin?Math.min(this._activeBuffer.scrollBottom,Math.max(this._activeBuffer.scrollTop,this._activeBuffer.y)):Math.min(this._bufferService.rows-1,Math.max(0,this._activeBuffer.y)),this._dirtyRowTracker.markDirty(this._activeBuffer.y)}_setCursor(e,t){this._dirtyRowTracker.markDirty(this._activeBuffer.y),this._coreService.decPrivateModes.origin?(this._activeBuffer.x=e,this._activeBuffer.y=this._activeBuffer.scrollTop+t):(this._activeBuffer.x=e,this._activeBuffer.y=t),this._restrictCursor(),this._dirtyRowTracker.markDirty(this._activeBuffer.y)}_moveCursor(e,t){this._restrictCursor(),this._setCursor(this._activeBuffer.x+e,this._activeBuffer.y+t)}cursorUp(e){let t=this._activeBuffer.y-this._activeBuffer.scrollTop;return t>=0?this._moveCursor(0,-Math.min(t,e.params[0]||1)):this._moveCursor(0,-(e.params[0]||1)),!0}cursorDown(e){let t=this._activeBuffer.scrollBottom-this._activeBuffer.y;return t>=0?this._moveCursor(0,Math.min(t,e.params[0]||1)):this._moveCursor(0,e.params[0]||1),!0}cursorForward(e){return this._moveCursor(e.params[0]||1,0),!0}cursorBackward(e){return this._moveCursor(-(e.params[0]||1),0),!0}cursorNextLine(e){return this.cursorDown(e),this._activeBuffer.x=0,!0}cursorPrecedingLine(e){return this.cursorUp(e),this._activeBuffer.x=0,!0}cursorCharAbsolute(e){return this._setCursor((e.params[0]||1)-1,this._activeBuffer.y),!0}cursorPosition(e){return this._setCursor(e.length>=2?(e.params[1]||1)-1:0,(e.params[0]||1)-1),!0}charPosAbsolute(e){return this._setCursor((e.params[0]||1)-1,this._activeBuffer.y),!0}hPositionRelative(e){return this._moveCursor(e.params[0]||1,0),!0}linePosAbsolute(e){return this._setCursor(this._activeBuffer.x,(e.params[0]||1)-1),!0}vPositionRelative(e){return this._moveCursor(0,e.params[0]||1),!0}hVPosition(e){return this.cursorPosition(e),!0}tabClear(e){let t=e.params[0];return t===0?delete this._activeBuffer.tabs[this._activeBuffer.x]:t===3&&(this._activeBuffer.tabs={}),!0}cursorForwardTab(e){if(this._activeBuffer.x>=this._bufferService.cols)return!0;let t=e.params[0]||1;for(;t--;)this._activeBuffer.x=this._activeBuffer.nextStop();return!0}cursorBackwardTab(e){if(this._activeBuffer.x>=this._bufferService.cols)return!0;let t=e.params[0]||1;for(;t--;)this._activeBuffer.x=this._activeBuffer.prevStop();return!0}selectProtected(e){let t=e.params[0];return t===1&&(this._curAttrData.bg|=536870912),(t===2||t===0)&&(this._curAttrData.bg&=-536870913),!0}_eraseInBufferLine(e,t,n,r=!1,i=!1){let a=this._activeBuffer.lines.get(this._activeBuffer.ybase+e);a.replaceCells(t,n,this._activeBuffer.getNullCell(this._eraseAttrData()),i),r&&(a.isWrapped=!1)}_resetBufferLine(e,t=!1){let n=this._activeBuffer.lines.get(this._activeBuffer.ybase+e);n&&(n.fill(this._activeBuffer.getNullCell(this._eraseAttrData()),t),this._bufferService.buffer.clearMarkers(this._activeBuffer.ybase+e),n.isWrapped=!1)}eraseInDisplay(e,t=!1){this._restrictCursor(this._bufferService.cols);let n;switch(e.params[0]){case 0:for(n=this._activeBuffer.y,this._dirtyRowTracker.markDirty(n),this._eraseInBufferLine(n++,this._activeBuffer.x,this._bufferService.cols,this._activeBuffer.x===0,t);n<this._bufferService.rows;n++)this._resetBufferLine(n,t);this._dirtyRowTracker.markDirty(n);break;case 1:for(n=this._activeBuffer.y,this._dirtyRowTracker.markDirty(n),this._eraseInBufferLine(n,0,this._activeBuffer.x+1,!0,t),this._activeBuffer.x+1>=this._bufferService.cols&&(this._activeBuffer.lines.get(n+1).isWrapped=!1);n--;)this._resetBufferLine(n,t);this._dirtyRowTracker.markDirty(0);break;case 2:if(this._optionsService.rawOptions.scrollOnEraseInDisplay){for(n=this._bufferService.rows,this._dirtyRowTracker.markRangeDirty(0,n-1);n--&&!this._activeBuffer.lines.get(this._activeBuffer.ybase+n)?.getTrimmedLength(););for(;n>=0;n--)this._bufferService.scroll(this._eraseAttrData())}else{for(n=this._bufferService.rows,this._dirtyRowTracker.markDirty(n-1);n--;)this._resetBufferLine(n,t);this._dirtyRowTracker.markDirty(0)}break;case 3:let e=this._activeBuffer.lines.length-this._bufferService.rows;e>0&&(this._activeBuffer.lines.trimStart(e),this._activeBuffer.ybase=Math.max(this._activeBuffer.ybase-e,0),this._activeBuffer.ydisp=Math.max(this._activeBuffer.ydisp-e,0),this._onScroll.fire(0))}return!0}eraseInLine(e,t=!1){switch(this._restrictCursor(this._bufferService.cols),e.params[0]){case 0:this._eraseInBufferLine(this._activeBuffer.y,this._activeBuffer.x,this._bufferService.cols,this._activeBuffer.x===0,t);break;case 1:this._eraseInBufferLine(this._activeBuffer.y,0,this._activeBuffer.x+1,!1,t);break;case 2:this._eraseInBufferLine(this._activeBuffer.y,0,this._bufferService.cols,!0,t)}return this._dirtyRowTracker.markDirty(this._activeBuffer.y),!0}insertLines(e){this._restrictCursor();let t=e.params[0]||1;if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.y<this._activeBuffer.scrollTop)return!0;let n=this._activeBuffer.ybase+this._activeBuffer.y,r=this._bufferService.rows-1-this._activeBuffer.scrollBottom,i=this._bufferService.rows-1+this._activeBuffer.ybase-r+1;for(;t--;)this._activeBuffer.lines.splice(i-1,1),this._activeBuffer.lines.splice(n,0,this._activeBuffer.getBlankLine(this._eraseAttrData()));return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.y,this._activeBuffer.scrollBottom),this._activeBuffer.x=0,!0}deleteLines(e){this._restrictCursor();let t=e.params[0]||1;if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.y<this._activeBuffer.scrollTop)return!0;let n=this._activeBuffer.ybase+this._activeBuffer.y,r;for(r=this._bufferService.rows-1-this._activeBuffer.scrollBottom,r=this._bufferService.rows-1+this._activeBuffer.ybase-r;t--;)this._activeBuffer.lines.splice(n,1),this._activeBuffer.lines.splice(r,0,this._activeBuffer.getBlankLine(this._eraseAttrData()));return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.y,this._activeBuffer.scrollBottom),this._activeBuffer.x=0,!0}insertChars(e){this._restrictCursor();let t=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y);return t&&(t.insertCells(this._activeBuffer.x,e.params[0]||1,this._activeBuffer.getNullCell(this._eraseAttrData())),this._dirtyRowTracker.markDirty(this._activeBuffer.y)),!0}deleteChars(e){this._restrictCursor();let t=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y);return t&&(t.deleteCells(this._activeBuffer.x,e.params[0]||1,this._activeBuffer.getNullCell(this._eraseAttrData())),this._dirtyRowTracker.markDirty(this._activeBuffer.y)),!0}scrollUp(e){let t=e.params[0]||1;for(;t--;)this._activeBuffer.lines.splice(this._activeBuffer.ybase+this._activeBuffer.scrollTop,1),this._activeBuffer.lines.splice(this._activeBuffer.ybase+this._activeBuffer.scrollBottom,0,this._activeBuffer.getBlankLine(this._eraseAttrData()));return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom),!0}scrollDown(e){let t=e.params[0]||1;for(;t--;)this._activeBuffer.lines.splice(this._activeBuffer.ybase+this._activeBuffer.scrollBottom,1),this._activeBuffer.lines.splice(this._activeBuffer.ybase+this._activeBuffer.scrollTop,0,this._activeBuffer.getBlankLine(cQ));return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom),!0}scrollLeft(e){if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.y<this._activeBuffer.scrollTop)return!0;let t=e.params[0]||1;for(let e=this._activeBuffer.scrollTop;e<=this._activeBuffer.scrollBottom;++e){let n=this._activeBuffer.lines.get(this._activeBuffer.ybase+e);n.deleteCells(0,t,this._activeBuffer.getNullCell(this._eraseAttrData())),n.isWrapped=!1}return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom),!0}scrollRight(e){if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.y<this._activeBuffer.scrollTop)return!0;let t=e.params[0]||1;for(let e=this._activeBuffer.scrollTop;e<=this._activeBuffer.scrollBottom;++e){let n=this._activeBuffer.lines.get(this._activeBuffer.ybase+e);n.insertCells(0,t,this._activeBuffer.getNullCell(this._eraseAttrData())),n.isWrapped=!1}return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom),!0}insertColumns(e){if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.y<this._activeBuffer.scrollTop)return!0;let t=e.params[0]||1;for(let e=this._activeBuffer.scrollTop;e<=this._activeBuffer.scrollBottom;++e){let n=this._activeBuffer.lines.get(this._activeBuffer.ybase+e);n.insertCells(this._activeBuffer.x,t,this._activeBuffer.getNullCell(this._eraseAttrData())),n.isWrapped=!1}return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom),!0}deleteColumns(e){if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.y<this._activeBuffer.scrollTop)return!0;let t=e.params[0]||1;for(let e=this._activeBuffer.scrollTop;e<=this._activeBuffer.scrollBottom;++e){let n=this._activeBuffer.lines.get(this._activeBuffer.ybase+e);n.deleteCells(this._activeBuffer.x,t,this._activeBuffer.getNullCell(this._eraseAttrData())),n.isWrapped=!1}return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom),!0}eraseChars(e){this._restrictCursor();let t=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y);return t&&(t.replaceCells(this._activeBuffer.x,this._activeBuffer.x+(e.params[0]||1),this._activeBuffer.getNullCell(this._eraseAttrData())),this._dirtyRowTracker.markDirty(this._activeBuffer.y)),!0}repeatPrecedingCharacter(e){let t=this._parser.precedingJoinState;if(!t)return!0;let n=e.params[0]||1,r=GQ.extractWidth(t),i=this._activeBuffer.x-r,a=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y).getString(i),o=new Uint32Array(a.length*n),s=0;for(let e=0;e<a.length;){let t=a.codePointAt(e)||0;o[s++]=t,e+=t>65535?2:1}let c=s;for(let e=1;e<n;++e)o.copyWithin(c,0,s),c+=s;return this.print(o,0,c),!0}sendDeviceAttributesPrimary(e){return e.params[0]>0||(this._is(`xterm`)||this._is(`rxvt-unicode`)||this._is(`screen`)?this._coreService.triggerDataEvent($.ESC+`[?1;2c`):this._is(`linux`)&&this._coreService.triggerDataEvent($.ESC+`[?6c`)),!0}sendDeviceAttributesSecondary(e){return e.params[0]>0||(this._is(`xterm`)?this._coreService.triggerDataEvent($.ESC+`[>0;276;0c`):this._is(`rxvt-unicode`)?this._coreService.triggerDataEvent($.ESC+`[>85;95;0c`):this._is(`linux`)?this._coreService.triggerDataEvent(e.params[0]+`c`):this._is(`screen`)&&this._coreService.triggerDataEvent($.ESC+`[>83;40003;0c`)),!0}_is(e){return(this._optionsService.rawOptions.termName+``).indexOf(e)===0}setMode(e){for(let t=0;t<e.length;t++)switch(e.params[t]){case 4:this._coreService.modes.insertMode=!0;break;case 20:this._optionsService.options.convertEol=!0}return!0}setModePrivate(e){for(let t=0;t<e.length;t++)switch(e.params[t]){case 1:this._coreService.decPrivateModes.applicationCursorKeys=!0;break;case 2:this._charsetService.setgCharset(0,bQ),this._charsetService.setgCharset(1,bQ),this._charsetService.setgCharset(2,bQ),this._charsetService.setgCharset(3,bQ);break;case 3:this._optionsService.rawOptions.windowOptions.setWinLines&&(this._bufferService.resize(132,this._bufferService.rows),this._onRequestReset.fire());break;case 6:this._coreService.decPrivateModes.origin=!0,this._setCursor(0,0);break;case 7:this._coreService.decPrivateModes.wraparound=!0;break;case 12:this._optionsService.options.cursorBlink=!0;break;case 45:this._coreService.decPrivateModes.reverseWraparound=!0;break;case 66:this._logService.debug(`Serial port requested application keypad.`),this._coreService.decPrivateModes.applicationKeypad=!0,this._onRequestSyncScrollBar.fire();break;case 9:this._coreMouseService.activeProtocol=`X10`;break;case 1e3:this._coreMouseService.activeProtocol=`VT200`;break;case 1002:this._coreMouseService.activeProtocol=`DRAG`;break;case 1003:this._coreMouseService.activeProtocol=`ANY`;break;case 1004:this._coreService.decPrivateModes.sendFocus=!0,this._onRequestSendFocus.fire();break;case 1005:this._logService.debug(`DECSET 1005 not supported (see #2507)`);break;case 1006:this._coreMouseService.activeEncoding=`SGR`;break;case 1015:this._logService.debug(`DECSET 1015 not supported (see #2507)`);break;case 1016:this._coreMouseService.activeEncoding=`SGR_PIXELS`;break;case 25:this._coreService.isCursorHidden=!1;break;case 1048:this.saveCursor();break;case 1049:this.saveCursor();case 47:case 1047:this._bufferService.buffers.activateAltBuffer(this._eraseAttrData()),this._coreService.isCursorInitialized=!0,this._onRequestRefreshRows.fire(void 0),this._onRequestSyncScrollBar.fire();break;case 2004:this._coreService.decPrivateModes.bracketedPasteMode=!0;break;case 2026:this._coreService.decPrivateModes.synchronizedOutput=!0}return!0}resetMode(e){for(let t=0;t<e.length;t++)switch(e.params[t]){case 4:this._coreService.modes.insertMode=!1;break;case 20:this._optionsService.options.convertEol=!1}return!0}resetModePrivate(e){for(let t=0;t<e.length;t++)switch(e.params[t]){case 1:this._coreService.decPrivateModes.applicationCursorKeys=!1;break;case 3:this._optionsService.rawOptions.windowOptions.setWinLines&&(this._bufferService.resize(80,this._bufferService.rows),this._onRequestReset.fire());break;case 6:this._coreService.decPrivateModes.origin=!1,this._setCursor(0,0);break;case 7:this._coreService.decPrivateModes.wraparound=!1;break;case 12:this._optionsService.options.cursorBlink=!1;break;case 45:this._coreService.decPrivateModes.reverseWraparound=!1;break;case 66:this._logService.debug(`Switching back to normal keypad.`),this._coreService.decPrivateModes.applicationKeypad=!1,this._onRequestSyncScrollBar.fire();break;case 9:case 1e3:case 1002:case 1003:this._coreMouseService.activeProtocol=`NONE`;break;case 1004:this._coreService.decPrivateModes.sendFocus=!1;break;case 1005:this._logService.debug(`DECRST 1005 not supported (see #2507)`);break;case 1006:this._coreMouseService.activeEncoding=`DEFAULT`;break;case 1015:this._logService.debug(`DECRST 1015 not supported (see #2507)`);break;case 1016:this._coreMouseService.activeEncoding=`DEFAULT`;break;case 25:this._coreService.isCursorHidden=!0;break;case 1048:this.restoreCursor();break;case 1049:case 47:case 1047:this._bufferService.buffers.activateNormalBuffer(),e.params[t]===1049&&this.restoreCursor(),this._coreService.isCursorInitialized=!0,this._onRequestRefreshRows.fire(void 0),this._onRequestSyncScrollBar.fire();break;case 2004:this._coreService.decPrivateModes.bracketedPasteMode=!1;break;case 2026:this._coreService.decPrivateModes.synchronizedOutput=!1,this._onRequestRefreshRows.fire(void 0)}return!0}requestMode(e,t){let n;(e=>(e[e.NOT_RECOGNIZED=0]=`NOT_RECOGNIZED`,e[e.SET=1]=`SET`,e[e.RESET=2]=`RESET`,e[e.PERMANENTLY_SET=3]=`PERMANENTLY_SET`,e[e.PERMANENTLY_RESET=4]=`PERMANENTLY_RESET`))(n||={});let r=this._coreService.decPrivateModes,{activeProtocol:i,activeEncoding:a}=this._coreMouseService,o=this._coreService,{buffers:s,cols:c}=this._bufferService,{active:l,alt:u}=s,d=this._optionsService.rawOptions,f=(e,n)=>(o.triggerDataEvent(`${$.ESC}[${t?``:`?`}${e};${n}$y`),!0),p=e=>e?1:2,m=e.params[0];return t?m===2?f(m,4):m===4?f(m,p(o.modes.insertMode)):m===12?f(m,3):m===20?f(m,p(d.convertEol)):f(m,0):m===1?f(m,p(r.applicationCursorKeys)):m===3?f(m,d.windowOptions.setWinLines?c===80?2:+(c===132):0):m===6?f(m,p(r.origin)):m===7?f(m,p(r.wraparound)):m===8?f(m,3):m===9?f(m,p(i===`X10`)):m===12?f(m,p(d.cursorBlink)):m===25?f(m,p(!o.isCursorHidden)):m===45?f(m,p(r.reverseWraparound)):m===66?f(m,p(r.applicationKeypad)):m===67?f(m,4):m===1e3?f(m,p(i===`VT200`)):m===1002?f(m,p(i===`DRAG`)):m===1003?f(m,p(i===`ANY`)):m===1004?f(m,p(r.sendFocus)):m===1005?f(m,4):m===1006?f(m,p(a===`SGR`)):m===1015?f(m,4):m===1016?f(m,p(a===`SGR_PIXELS`)):m===1048?f(m,1):m===47||m===1047||m===1049?f(m,p(l===u)):m===2004?f(m,p(r.bracketedPasteMode)):m===2026?f(m,p(r.synchronizedOutput)):f(m,0)}_updateAttrColor(e,t,n,r,i){return t===2?(e|=50331648,e&=-16777216,e|=CK.fromColorRGB([n,r,i])):t===5&&(e&=-50331904,e|=33554432|n&255),e}_extractColor(e,t,n){let r=[0,0,-1,0,0,0],i=0,a=0;do{if(r[a+i]=e.params[t+a],e.hasSubParams(t+a)){let n=e.getSubParams(t+a),o=0;do r[1]===5&&(i=1),r[a+o+1+i]=n[o];while(++o<n.length&&o+a+1+i<r.length);break}if(r[1]===5&&a+i>=2||r[1]===2&&a+i>=5)break;r[1]&&(i=1)}while(++a+t<e.length&&a+i<r.length);for(let e=2;e<r.length;++e)r[e]===-1&&(r[e]=0);switch(r[0]){case 38:n.fg=this._updateAttrColor(n.fg,r[1],r[3],r[4],r[5]);break;case 48:n.bg=this._updateAttrColor(n.bg,r[1],r[3],r[4],r[5]);break;case 58:n.extended=n.extended.clone(),n.extended.underlineColor=this._updateAttrColor(n.extended.underlineColor,r[1],r[3],r[4],r[5])}return a}_processUnderline(e,t){t.extended=t.extended.clone(),(!~e||e>5)&&(e=1),t.extended.underlineStyle=e,t.fg|=268435456,e===0&&(t.fg&=-268435457),t.updateExtended()}_processSGR0(e){e.fg=cQ.fg,e.bg=cQ.bg,e.extended=e.extended.clone(),e.extended.underlineStyle=0,e.extended.underlineColor&=-67108864,e.updateExtended()}charAttributes(e){if(e.length===1&&e.params[0]===0)return this._processSGR0(this._curAttrData),!0;let t=e.length,n,r=this._curAttrData;for(let i=0;i<t;i++)n=e.params[i],n>=30&&n<=37?(r.fg&=-50331904,r.fg|=16777216|n-30):n>=40&&n<=47?(r.bg&=-50331904,r.bg|=16777216|n-40):n>=90&&n<=97?(r.fg&=-50331904,r.fg|=n-90|16777224):n>=100&&n<=107?(r.bg&=-50331904,r.bg|=n-100|16777224):n===0?this._processSGR0(r):n===1?r.fg|=134217728:n===3?r.bg|=67108864:n===4?(r.fg|=268435456,this._processUnderline(e.hasSubParams(i)?e.getSubParams(i)[0]:1,r)):n===5?r.fg|=536870912:n===7?r.fg|=67108864:n===8?r.fg|=1073741824:n===9?r.fg|=2147483648:n===2?r.bg|=134217728:n===21?this._processUnderline(2,r):n===22?(r.fg&=-134217729,r.bg&=-134217729):n===23?r.bg&=-67108865:n===24?(r.fg&=-268435457,this._processUnderline(0,r)):n===25?r.fg&=-536870913:n===27?r.fg&=-67108865:n===28?r.fg&=-1073741825:n===29?r.fg&=2147483647:n===39?(r.fg&=-67108864,r.fg|=cQ.fg&16777215):n===49?(r.bg&=-67108864,r.bg|=cQ.bg&16777215):n===38||n===48||n===58?i+=this._extractColor(e,i,r):n===53?r.bg|=1073741824:n===55?r.bg&=-1073741825:n===59?(r.extended=r.extended.clone(),r.extended.underlineColor=-1,r.updateExtended()):n===100?(r.fg&=-67108864,r.fg|=cQ.fg&16777215,r.bg&=-67108864,r.bg|=cQ.bg&16777215):this._logService.debug(`Unknown SGR attribute: %d.`,n);return!0}deviceStatus(e){switch(e.params[0]){case 5:this._coreService.triggerDataEvent(`${$.ESC}[0n`);break;case 6:let e=this._activeBuffer.y+1,t=this._activeBuffer.x+1;this._coreService.triggerDataEvent(`${$.ESC}[${e};${t}R`)}return!0}deviceStatusPrivate(e){if(e.params[0]===6){let e=this._activeBuffer.y+1,t=this._activeBuffer.x+1;this._coreService.triggerDataEvent(`${$.ESC}[?${e};${t}R`)}return!0}softReset(e){return this._coreService.isCursorHidden=!1,this._onRequestSyncScrollBar.fire(),this._activeBuffer.scrollTop=0,this._activeBuffer.scrollBottom=this._bufferService.rows-1,this._curAttrData=cQ.clone(),this._coreService.reset(),this._charsetService.reset(),this._activeBuffer.savedX=0,this._activeBuffer.savedY=this._activeBuffer.ybase,this._activeBuffer.savedCurAttrData.fg=this._curAttrData.fg,this._activeBuffer.savedCurAttrData.bg=this._curAttrData.bg,this._activeBuffer.savedCharset=this._charsetService.charset,this._coreService.decPrivateModes.origin=!1,!0}setCursorStyle(e){let t=e.length===0?1:e.params[0];if(t===0)this._coreService.decPrivateModes.cursorStyle=void 0,this._coreService.decPrivateModes.cursorBlink=void 0;else{switch(t){case 1:case 2:this._coreService.decPrivateModes.cursorStyle=`block`;break;case 3:case 4:this._coreService.decPrivateModes.cursorStyle=`underline`;break;case 5:case 6:this._coreService.decPrivateModes.cursorStyle=`bar`}let e=t%2==1;this._coreService.decPrivateModes.cursorBlink=e}return!0}setScrollRegion(e){let t=e.params[0]||1,n;return(e.length<2||(n=e.params[1])>this._bufferService.rows||n===0)&&(n=this._bufferService.rows),n>t&&(this._activeBuffer.scrollTop=t-1,this._activeBuffer.scrollBottom=n-1,this._setCursor(0,0)),!0}windowOptions(e){if(!g$(e.params[0],this._optionsService.rawOptions.windowOptions))return!0;let t=e.length>1?e.params[1]:0;switch(e.params[0]){case 14:t!==2&&this._onRequestWindowsOptionsReport.fire(0);break;case 16:this._onRequestWindowsOptionsReport.fire(1);break;case 18:this._bufferService&&this._coreService.triggerDataEvent(`${$.ESC}[8;${this._bufferService.rows};${this._bufferService.cols}t`);break;case 22:(t===0||t===2)&&(this._windowTitleStack.push(this._windowTitle),this._windowTitleStack.length>h$&&this._windowTitleStack.shift()),(t===0||t===1)&&(this._iconNameStack.push(this._iconName),this._iconNameStack.length>h$&&this._iconNameStack.shift());break;case 23:(t===0||t===2)&&this._windowTitleStack.length&&this.setTitle(this._windowTitleStack.pop()),(t===0||t===1)&&this._iconNameStack.length&&this.setIconName(this._iconNameStack.pop())}return!0}saveCursor(e){return this._activeBuffer.savedX=this._activeBuffer.x,this._activeBuffer.savedY=this._activeBuffer.ybase+this._activeBuffer.y,this._activeBuffer.savedCurAttrData.fg=this._curAttrData.fg,this._activeBuffer.savedCurAttrData.bg=this._curAttrData.bg,this._activeBuffer.savedCharset=this._charsetService.charset,!0}restoreCursor(e){return this._activeBuffer.x=this._activeBuffer.savedX||0,this._activeBuffer.y=Math.max(this._activeBuffer.savedY-this._activeBuffer.ybase,0),this._curAttrData.fg=this._activeBuffer.savedCurAttrData.fg,this._curAttrData.bg=this._activeBuffer.savedCurAttrData.bg,this._charsetService.charset=this._savedCharset,this._activeBuffer.savedCharset&&(this._charsetService.charset=this._activeBuffer.savedCharset),this._restrictCursor(),!0}setTitle(e){return this._windowTitle=e,this._onTitleChange.fire(e),!0}setIconName(e){return this._iconName=e,!0}setOrReportIndexedColor(e){let t=[],n=e.split(`;`);for(;n.length>1;){let e=n.shift(),r=n.shift();if(/^\d+$/.exec(e)){let n=parseInt(e);if(x$(n)){if(r===`?`)t.push({type:0,index:n});else{let e=u$(r);e&&t.push({type:1,index:n,color:e})}}}}return t.length&&this._onColor.fire(t),!0}setHyperlink(e){let t=e.indexOf(`;`);if(t===-1)return!0;let n=e.slice(0,t).trim(),r=e.slice(t+1);return r?this._createHyperlink(n,r):!n.trim()&&this._finishHyperlink()}_createHyperlink(e,t){this._getCurrentLinkId()&&this._finishHyperlink();let n=e.split(`:`),r,i=n.findIndex(e=>e.startsWith(`id=`));return i!==-1&&(r=n[i].slice(3)||void 0),this._curAttrData.extended=this._curAttrData.extended.clone(),this._curAttrData.extended.urlId=this._oscLinkService.registerLink({id:r,uri:t}),this._curAttrData.updateExtended(),!0}_finishHyperlink(){return this._curAttrData.extended=this._curAttrData.extended.clone(),this._curAttrData.extended.urlId=0,this._curAttrData.updateExtended(),!0}_setOrReportSpecialColor(e,t){let n=e.split(`;`);for(let e=0;e<n.length&&!(t>=this._specialColors.length);++e,++t)if(n[e]===`?`)this._onColor.fire([{type:0,index:this._specialColors[t]}]);else{let r=u$(n[e]);r&&this._onColor.fire([{type:1,index:this._specialColors[t],color:r}])}return!0}setOrReportFgColor(e){return this._setOrReportSpecialColor(e,0)}setOrReportBgColor(e){return this._setOrReportSpecialColor(e,1)}setOrReportCursorColor(e){return this._setOrReportSpecialColor(e,2)}restoreIndexedColor(e){if(!e)return this._onColor.fire([{type:2}]),!0;let t=[],n=e.split(`;`);for(let e=0;e<n.length;++e)if(/^\d+$/.exec(n[e])){let r=parseInt(n[e]);x$(r)&&t.push({type:2,index:r})}return t.length&&this._onColor.fire(t),!0}restoreFgColor(e){return this._onColor.fire([{type:2,index:256}]),!0}restoreBgColor(e){return this._onColor.fire([{type:2,index:257}]),!0}restoreCursorColor(e){return this._onColor.fire([{type:2,index:258}]),!0}nextLine(){return this._activeBuffer.x=0,this.index(),!0}keypadApplicationMode(){return this._logService.debug(`Serial port requested application keypad.`),this._coreService.decPrivateModes.applicationKeypad=!0,this._onRequestSyncScrollBar.fire(),!0}keypadNumericMode(){return this._logService.debug(`Switching back to normal keypad.`),this._coreService.decPrivateModes.applicationKeypad=!1,this._onRequestSyncScrollBar.fire(),!0}selectDefaultCharset(){return this._charsetService.setgLevel(0),this._charsetService.setgCharset(0,bQ),!0}selectCharset(e){return e.length===2?(e[0]===`/`||this._charsetService.setgCharset(p$[e[0]],yQ[e[1]]||bQ),!0):(this.selectDefaultCharset(),!0)}index(){return this._restrictCursor(),this._activeBuffer.y++,this._activeBuffer.y===this._activeBuffer.scrollBottom+1?(this._activeBuffer.y--,this._bufferService.scroll(this._eraseAttrData())):this._activeBuffer.y>=this._bufferService.rows&&(this._activeBuffer.y=this._bufferService.rows-1),this._restrictCursor(),!0}tabSet(){return this._activeBuffer.tabs[this._activeBuffer.x]=!0,!0}reverseIndex(){if(this._restrictCursor(),this._activeBuffer.y===this._activeBuffer.scrollTop){let e=this._activeBuffer.scrollBottom-this._activeBuffer.scrollTop;this._activeBuffer.lines.shiftElements(this._activeBuffer.ybase+this._activeBuffer.y,e,1),this._activeBuffer.lines.set(this._activeBuffer.ybase+this._activeBuffer.y,this._activeBuffer.getBlankLine(this._eraseAttrData())),this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom)}else this._activeBuffer.y--,this._restrictCursor();return!0}fullReset(){return this._parser.reset(),this._onRequestReset.fire(),!0}reset(){this._curAttrData=cQ.clone(),this._eraseAttrDataInternal=cQ.clone()}_eraseAttrData(){return this._eraseAttrDataInternal.bg&=-67108864,this._eraseAttrDataInternal.bg|=this._curAttrData.bg&67108863,this._eraseAttrDataInternal}setgLevel(e){return this._charsetService.setgLevel(e),!0}screenAlignmentPattern(){let e=new TK;e.content=4194373,e.fg=this._curAttrData.fg,e.bg=this._curAttrData.bg,this._setCursor(0,0);for(let t=0;t<this._bufferService.rows;++t){let n=this._activeBuffer.ybase+this._activeBuffer.y+t,r=this._activeBuffer.lines.get(n);r&&(r.fill(e),r.isWrapped=!1)}return this._dirtyRowTracker.markAllDirty(),this._setCursor(0,0),!0}requestStatusString(e,t){let n=e=>(this._coreService.triggerDataEvent(`${$.ESC}${e}${$.ESC}\\`),!0),r=this._bufferService.buffer,i=this._optionsService.rawOptions;return n(e===`"q`?`P1$r${+!!this._curAttrData.isProtected()}"q`:e===`"p`?`P1$r61;1"p`:e===`r`?`P1$r${r.scrollTop+1};${r.scrollBottom+1}r`:e===`m`?`P1$r0m`:e===` q`?`P1$r${{block:2,underline:4,bar:6}[i.cursorStyle]-+!!i.cursorBlink} q`:`P0$r`)}markRangeDirty(e,t){this._dirtyRowTracker.markRangeDirty(e,t)}},b$=class{constructor(e){this._bufferService=e,this.clearRange()}clearRange(){this.start=this._bufferService.buffer.y,this.end=this._bufferService.buffer.y}markDirty(e){e<this.start?this.start=e:e>this.end&&(this.end=e)}markRangeDirty(e,t){e>t&&(v$=e,e=t,t=v$),e<this.start&&(this.start=e),t>this.end&&(this.end=t)}markAllDirty(){this.markRangeDirty(0,this._bufferService.rows-1)}};b$=iK([aK(0,MK)],b$);function x$(e){return 0<=e&&e<256}var S$=5e7,C$=12,w$=50,T$=class extends xq{constructor(e){super(),this._action=e,this._writeBuffer=[],this._callbacks=[],this._pendingData=0,this._bufferOffset=0,this._isSyncWriting=!1,this._syncCalls=0,this._didUserInput=!1,this._onWriteParsed=this._register(new Vq),this.onWriteParsed=this._onWriteParsed.event}handleUserInput(){this._didUserInput=!0}writeSync(e,t){if(t!==void 0&&this._syncCalls>t){this._syncCalls=0;return}if(this._pendingData+=e.length,this._writeBuffer.push(e),this._callbacks.push(void 0),this._syncCalls++,this._isSyncWriting)return;this._isSyncWriting=!0;let n;for(;n=this._writeBuffer.shift();){this._action(n);let e=this._callbacks.shift();e&&e()}this._pendingData=0,this._bufferOffset=2147483647,this._isSyncWriting=!1,this._syncCalls=0}write(e,t){if(this._pendingData>S$)throw Error(`write data discarded, use flow control to avoid losing data`);if(!this._writeBuffer.length){if(this._bufferOffset=0,this._didUserInput){this._didUserInput=!1,this._pendingData+=e.length,this._writeBuffer.push(e),this._callbacks.push(t),this._innerWrite();return}setTimeout(()=>this._innerWrite())}this._pendingData+=e.length,this._writeBuffer.push(e),this._callbacks.push(t)}_innerWrite(e=0,t=!0){let n=e||performance.now();for(;this._writeBuffer.length>this._bufferOffset;){let e=this._writeBuffer[this._bufferOffset],r=this._action(e,t);if(r){r.catch(e=>(queueMicrotask(()=>{throw e}),Promise.resolve(!1))).then(e=>performance.now()-n>=C$?setTimeout(()=>this._innerWrite(0,e)):this._innerWrite(n,e));return}let i=this._callbacks[this._bufferOffset];if(i&&i(),this._bufferOffset++,this._pendingData-=e.length,performance.now()-n>=C$)break}this._writeBuffer.length>this._bufferOffset?(this._bufferOffset>w$&&(this._writeBuffer=this._writeBuffer.slice(this._bufferOffset),this._callbacks=this._callbacks.slice(this._bufferOffset),this._bufferOffset=0),setTimeout(()=>this._innerWrite())):(this._writeBuffer.length=0,this._callbacks.length=0,this._pendingData=0,this._bufferOffset=0),this._onWriteParsed.fire()}},E$=class{constructor(e){this._bufferService=e,this._nextId=1,this._entriesWithId=new Map,this._dataByLinkId=new Map}registerLink(e){let t=this._bufferService.buffer;if(e.id===void 0){let n=t.addMarker(t.ybase+t.y),r={data:e,id:this._nextId++,lines:[n]};return n.onDispose(()=>this._removeMarkerFromLink(r,n)),this._dataByLinkId.set(r.id,r),r.id}let n=e,r=this._getEntryIdKey(n),i=this._entriesWithId.get(r);if(i)return this.addLineToLink(i.id,t.ybase+t.y),i.id;let a=t.addMarker(t.ybase+t.y),o={id:this._nextId++,key:this._getEntryIdKey(n),data:n,lines:[a]};return a.onDispose(()=>this._removeMarkerFromLink(o,a)),this._entriesWithId.set(o.key,o),this._dataByLinkId.set(o.id,o),o.id}addLineToLink(e,t){let n=this._dataByLinkId.get(e);if(n&&n.lines.every(e=>e.line!==t)){let e=this._bufferService.buffer.addMarker(t);n.lines.push(e),e.onDispose(()=>this._removeMarkerFromLink(n,e))}}getLinkData(e){return this._dataByLinkId.get(e)?.data}_getEntryIdKey(e){return`${e.id};;${e.uri}`}_removeMarkerFromLink(e,t){let n=e.lines.indexOf(t);n!==-1&&(e.lines.splice(n,1),e.lines.length===0&&(e.data.id!==void 0&&this._entriesWithId.delete(e.key),this._dataByLinkId.delete(e.id)))}};E$=iK([aK(0,MK)],E$);var D$=!1,O$=class extends xq{constructor(e){super(),this._windowsWrappingHeuristics=this._register(new Sq),this._onBinary=this._register(new Vq),this.onBinary=this._onBinary.event,this._onData=this._register(new Vq),this.onData=this._onData.event,this._onLineFeed=this._register(new Vq),this.onLineFeed=this._onLineFeed.event,this._onResize=this._register(new Vq),this.onResize=this._onResize.event,this._onWriteParsed=this._register(new Vq),this.onWriteParsed=this._onWriteParsed.event,this._onScroll=this._register(new Vq),this._instantiationService=new tQ,this.optionsService=this._register(new kQ(e)),this._instantiationService.setService(RK,this.optionsService),this._bufferService=this._register(this._instantiationService.createInstance(EQ)),this._instantiationService.setService(MK,this._bufferService),this._logService=this._register(this._instantiationService.createInstance(iQ)),this._instantiationService.setService(LK,this._logService),this.coreService=this._register(this._instantiationService.createInstance(PQ)),this._instantiationService.setService(PK,this.coreService),this.coreMouseService=this._register(this._instantiationService.createInstance(zQ)),this._instantiationService.setService(NK,this.coreMouseService),this.unicodeService=this._register(this._instantiationService.createInstance(GQ)),this._instantiationService.setService(BK,this.unicodeService),this._charsetService=this._instantiationService.createInstance(KQ),this._instantiationService.setService(FK,this._charsetService),this._oscLinkService=this._instantiationService.createInstance(E$),this._instantiationService.setService(zK,this._oscLinkService),this._inputHandler=this._register(new y$(this._bufferService,this._charsetService,this.coreService,this._logService,this.optionsService,this._oscLinkService,this.coreMouseService,this.unicodeService)),this._register(kq.forward(this._inputHandler.onLineFeed,this._onLineFeed)),this._register(this._inputHandler),this._register(kq.forward(this._bufferService.onResize,this._onResize)),this._register(kq.forward(this.coreService.onData,this._onData)),this._register(kq.forward(this.coreService.onBinary,this._onBinary)),this._register(this.coreService.onRequestScrollToBottom(()=>this.scrollToBottom(!0))),this._register(this.coreService.onUserInput(()=>this._writeBuffer.handleUserInput())),this._register(this.optionsService.onMultipleOptionChange([`windowsMode`,`windowsPty`],()=>this._handleWindowsPtyOptionChange())),this._register(this._bufferService.onScroll(()=>{this._onScroll.fire({position:this._bufferService.buffer.ydisp}),this._inputHandler.markRangeDirty(this._bufferService.buffer.scrollTop,this._bufferService.buffer.scrollBottom)})),this._writeBuffer=this._register(new T$((e,t)=>this._inputHandler.parse(e,t))),this._register(kq.forward(this._writeBuffer.onWriteParsed,this._onWriteParsed))}get onScroll(){return this._onScrollApi||(this._onScrollApi=this._register(new Vq),this._onScroll.event(e=>{this._onScrollApi?.fire(e.position)})),this._onScrollApi.event}get cols(){return this._bufferService.cols}get rows(){return this._bufferService.rows}get buffers(){return this._bufferService.buffers}get options(){return this.optionsService.options}set options(e){for(let t in e)this.optionsService.options[t]=e[t]}write(e,t){this._writeBuffer.write(e,t)}writeSync(e,t){this._logService.logLevel<=3&&!D$&&(this._logService.warn(`writeSync is unreliable and will be removed soon.`),D$=!0),this._writeBuffer.writeSync(e,t)}input(e,t=!0){this.coreService.triggerDataEvent(e,t)}resize(e,t){isNaN(e)||isNaN(t)||(e=Math.max(e,wQ),t=Math.max(t,TQ),this._bufferService.resize(e,t))}scroll(e,t=!1){this._bufferService.scroll(e,t)}scrollLines(e,t){this._bufferService.scrollLines(e,t)}scrollPages(e){this.scrollLines(e*(this.rows-1))}scrollToTop(){this.scrollLines(-this._bufferService.buffer.ydisp)}scrollToBottom(e){this.scrollLines(this._bufferService.buffer.ybase-this._bufferService.buffer.ydisp)}scrollToLine(e){let t=e-this._bufferService.buffer.ydisp;t!==0&&this.scrollLines(t)}registerEscHandler(e,t){return this._inputHandler.registerEscHandler(e,t)}registerDcsHandler(e,t){return this._inputHandler.registerDcsHandler(e,t)}registerCsiHandler(e,t){return this._inputHandler.registerCsiHandler(e,t)}registerOscHandler(e,t){return this._inputHandler.registerOscHandler(e,t)}_setup(){this._handleWindowsPtyOptionChange()}reset(){this._inputHandler.reset(),this._bufferService.reset(),this._charsetService.reset(),this.coreService.reset(),this.coreMouseService.reset()}_handleWindowsPtyOptionChange(){let e=!1,t=this.optionsService.rawOptions.windowsPty;t&&t.buildNumber!==void 0&&t.buildNumber!==void 0?e=t.backend===`conpty`&&t.buildNumber<21376:this.optionsService.rawOptions.windowsMode&&(e=!0),e?this._enableWindowsWrappingHeuristics():this._windowsWrappingHeuristics.clear()}_enableWindowsWrappingHeuristics(){if(!this._windowsWrappingHeuristics.value){let e=[];e.push(this.onLineFeed(qQ.bind(null,this._bufferService))),e.push(this.registerCsiHandler({final:`H`},()=>(qQ(this._bufferService),!1))),this._windowsWrappingHeuristics.value=vq(()=>{for(let t of e)t.dispose()})}}},k$={48:[`0`,`)`],49:[`1`,`!`],50:[`2`,`@`],51:[`3`,`#`],52:[`4`,`$`],53:[`5`,`%`],54:[`6`,`^`],55:[`7`,`&`],56:[`8`,`*`],57:[`9`,`(`],186:[`;`,`:`],187:[`=`,`+`],188:[`,`,`<`],189:[`-`,`_`],190:[`.`,`>`],191:[`/`,`?`],192:["`",`~`],219:[`[`,`{`],220:[`\\`,`|`],221:[`]`,`}`],222:[`'`,`"`]};function A$(e,t,n,r){let i={type:0,cancel:!1,key:void 0},a=+!!e.shiftKey|(e.altKey?2:0)|(e.ctrlKey?4:0)|(e.metaKey?8:0);switch(e.keyCode){case 0:e.key===`UIKeyInputUpArrow`?i.key=t?$.ESC+`OA`:$.ESC+`[A`:e.key===`UIKeyInputLeftArrow`?i.key=t?$.ESC+`OD`:$.ESC+`[D`:e.key===`UIKeyInputRightArrow`?i.key=t?$.ESC+`OC`:$.ESC+`[C`:e.key===`UIKeyInputDownArrow`&&(i.key=t?$.ESC+`OB`:$.ESC+`[B`);break;case 8:i.key=e.ctrlKey?`\b`:$.DEL,e.altKey&&(i.key=$.ESC+i.key);break;case 9:if(e.shiftKey){i.key=$.ESC+`[Z`;break}i.key=$.HT,i.cancel=!0;break;case 13:i.key=e.altKey?$.ESC+$.CR:$.CR,i.cancel=!0;break;case 27:i.key=$.ESC,e.altKey&&(i.key=$.ESC+$.ESC),i.cancel=!0;break;case 37:if(e.metaKey)break;i.key=a?$.ESC+`[1;`+(a+1)+`D`:t?$.ESC+`OD`:$.ESC+`[D`;break;case 39:if(e.metaKey)break;i.key=a?$.ESC+`[1;`+(a+1)+`C`:t?$.ESC+`OC`:$.ESC+`[C`;break;case 38:if(e.metaKey)break;i.key=a?$.ESC+`[1;`+(a+1)+`A`:t?$.ESC+`OA`:$.ESC+`[A`;break;case 40:if(e.metaKey)break;i.key=a?$.ESC+`[1;`+(a+1)+`B`:t?$.ESC+`OB`:$.ESC+`[B`;break;case 45:!e.shiftKey&&!e.ctrlKey&&(i.key=$.ESC+`[2~`);break;case 46:i.key=a?$.ESC+`[3;`+(a+1)+`~`:$.ESC+`[3~`;break;case 36:i.key=a?$.ESC+`[1;`+(a+1)+`H`:t?$.ESC+`OH`:$.ESC+`[H`;break;case 35:i.key=a?$.ESC+`[1;`+(a+1)+`F`:t?$.ESC+`OF`:$.ESC+`[F`;break;case 33:e.shiftKey?i.type=2:i.key=e.ctrlKey?$.ESC+`[5;`+(a+1)+`~`:$.ESC+`[5~`;break;case 34:e.shiftKey?i.type=3:i.key=e.ctrlKey?$.ESC+`[6;`+(a+1)+`~`:$.ESC+`[6~`;break;case 112:i.key=a?$.ESC+`[1;`+(a+1)+`P`:$.ESC+`OP`;break;case 113:i.key=a?$.ESC+`[1;`+(a+1)+`Q`:$.ESC+`OQ`;break;case 114:i.key=a?$.ESC+`[1;`+(a+1)+`R`:$.ESC+`OR`;break;case 115:i.key=a?$.ESC+`[1;`+(a+1)+`S`:$.ESC+`OS`;break;case 116:i.key=a?$.ESC+`[15;`+(a+1)+`~`:$.ESC+`[15~`;break;case 117:i.key=a?$.ESC+`[17;`+(a+1)+`~`:$.ESC+`[17~`;break;case 118:i.key=a?$.ESC+`[18;`+(a+1)+`~`:$.ESC+`[18~`;break;case 119:i.key=a?$.ESC+`[19;`+(a+1)+`~`:$.ESC+`[19~`;break;case 120:i.key=a?$.ESC+`[20;`+(a+1)+`~`:$.ESC+`[20~`;break;case 121:i.key=a?$.ESC+`[21;`+(a+1)+`~`:$.ESC+`[21~`;break;case 122:i.key=a?$.ESC+`[23;`+(a+1)+`~`:$.ESC+`[23~`;break;case 123:i.key=a?$.ESC+`[24;`+(a+1)+`~`:$.ESC+`[24~`;break;default:if(e.ctrlKey&&!e.shiftKey&&!e.altKey&&!e.metaKey)e.keyCode>=65&&e.keyCode<=90?i.key=String.fromCharCode(e.keyCode-64):e.keyCode===32?i.key=$.NUL:e.keyCode>=51&&e.keyCode<=55?i.key=String.fromCharCode(e.keyCode-51+27):e.keyCode===56?i.key=$.DEL:e.keyCode===219?i.key=$.ESC:e.keyCode===220?i.key=$.FS:e.keyCode===221&&(i.key=$.GS);else if((!n||r)&&e.altKey&&!e.metaKey){let t=k$[e.keyCode]?.[+!!e.shiftKey];if(t)i.key=$.ESC+t;else if(e.keyCode>=65&&e.keyCode<=90){let t=e.ctrlKey?e.keyCode-64:e.keyCode+32,n=String.fromCharCode(t);e.shiftKey&&(n=n.toUpperCase()),i.key=$.ESC+n}else if(e.keyCode===32)i.key=$.ESC+(e.ctrlKey?$.NUL:` `);else if(e.key===`Dead`&&e.code.startsWith(`Key`)){let t=e.code.slice(3,4);e.shiftKey||(t=t.toLowerCase()),i.key=$.ESC+t,i.cancel=!0}}else n&&!e.altKey&&!e.ctrlKey&&!e.shiftKey&&e.metaKey?e.keyCode===65&&(i.type=1):e.key&&!e.ctrlKey&&!e.altKey&&!e.metaKey&&e.keyCode>=48&&e.key.length===1?i.key=e.key:e.key&&e.ctrlKey&&(e.key===`_`&&(i.key=$.US),e.key===`@`&&(i.key=$.NUL))}return i}var j$=0,M$=class{constructor(e){this._getKey=e,this._array=[],this._insertedValues=[],this._flushInsertedTask=new vZ,this._isFlushingInserted=!1,this._deletedIndices=[],this._flushDeletedTask=new vZ,this._isFlushingDeleted=!1}clear(){this._array.length=0,this._insertedValues.length=0,this._flushInsertedTask.clear(),this._isFlushingInserted=!1,this._deletedIndices.length=0,this._flushDeletedTask.clear(),this._isFlushingDeleted=!1}insert(e){this._flushCleanupDeleted(),this._insertedValues.length===0&&this._flushInsertedTask.enqueue(()=>this._flushInserted()),this._insertedValues.push(e)}_flushInserted(){let e=this._insertedValues.sort((e,t)=>this._getKey(e)-this._getKey(t)),t=0,n=0,r=Array(this._array.length+this._insertedValues.length);for(let i=0;i<r.length;i++)n>=this._array.length||this._getKey(e[t])<=this._getKey(this._array[n])?(r[i]=e[t],t++):r[i]=this._array[n++];this._array=r,this._insertedValues.length=0}_flushCleanupInserted(){!this._isFlushingInserted&&this._insertedValues.length>0&&this._flushInsertedTask.flush()}delete(e){if(this._flushCleanupInserted(),this._array.length===0)return!1;let t=this._getKey(e);if(t===void 0||(j$=this._search(t),j$===-1)||this._getKey(this._array[j$])!==t)return!1;do if(this._array[j$]===e)return this._deletedIndices.length===0&&this._flushDeletedTask.enqueue(()=>this._flushDeleted()),this._deletedIndices.push(j$),!0;while(++j$<this._array.length&&this._getKey(this._array[j$])===t);return!1}_flushDeleted(){this._isFlushingDeleted=!0;let e=this._deletedIndices.sort((e,t)=>e-t),t=0,n=Array(this._array.length-e.length),r=0;for(let i=0;i<this._array.length;i++)e[t]===i?t++:n[r++]=this._array[i];this._array=n,this._deletedIndices.length=0,this._isFlushingDeleted=!1}_flushCleanupDeleted(){!this._isFlushingDeleted&&this._deletedIndices.length>0&&this._flushDeletedTask.flush()}*getKeyIterator(e){if(this._flushCleanupInserted(),this._flushCleanupDeleted(),this._array.length!==0&&(j$=this._search(e),!(j$<0||j$>=this._array.length)&&this._getKey(this._array[j$])===e))do yield this._array[j$];while(++j$<this._array.length&&this._getKey(this._array[j$])===e)}forEachByKey(e,t){if(this._flushCleanupInserted(),this._flushCleanupDeleted(),this._array.length!==0&&(j$=this._search(e),!(j$<0||j$>=this._array.length)&&this._getKey(this._array[j$])===e))do t(this._array[j$]);while(++j$<this._array.length&&this._getKey(this._array[j$])===e)}values(){return this._flushCleanupInserted(),this._flushCleanupDeleted(),[...this._array].values()}_search(e){let t=0,n=this._array.length-1;for(;n>=t;){let r=t+n>>1,i=this._getKey(this._array[r]);if(i>e)n=r-1;else if(i<e)t=r+1;else{for(;r>0&&this._getKey(this._array[r-1])===e;)r--;return r}}return t}},N$=0,P$=0,F$=class extends xq{constructor(){super(),this._decorations=new M$(e=>e?.marker.line),this._onDecorationRegistered=this._register(new Vq),this.onDecorationRegistered=this._onDecorationRegistered.event,this._onDecorationRemoved=this._register(new Vq),this.onDecorationRemoved=this._onDecorationRemoved.event,this._register(vq(()=>this.reset()))}get decorations(){return this._decorations.values()}registerDecoration(e){if(e.marker.isDisposed)return;let t=new I$(e);if(t){let e=t.marker.onDispose(()=>t.dispose()),n=t.onDispose(()=>{n.dispose(),t&&(this._decorations.delete(t)&&this._onDecorationRemoved.fire(t),e.dispose())});this._decorations.insert(t),this._onDecorationRegistered.fire(t)}return t}reset(){for(let e of this._decorations.values())e.dispose();this._decorations.clear()}*getDecorationsAtCell(e,t,n){let r=0,i=0;for(let a of this._decorations.getKeyIterator(t))r=a.options.x??0,i=r+(a.options.width??1),e>=r&&e<i&&(!n||(a.options.layer??`bottom`)===n)&&(yield a)}forEachDecorationAtCell(e,t,n,r){this._decorations.forEachByKey(t,t=>{N$=t.options.x??0,P$=N$+(t.options.width??1),e>=N$&&e<P$&&(!n||(t.options.layer??`bottom`)===n)&&r(t)})}},I$=class extends bq{constructor(e){super(),this.options=e,this.onRenderEmitter=this.add(new Vq),this.onRender=this.onRenderEmitter.event,this._onDispose=this.add(new Vq),this.onDispose=this._onDispose.event,this._cachedBg=null,this._cachedFg=null,this.marker=e.marker,this.options.overviewRulerOptions&&!this.options.overviewRulerOptions.position&&(this.options.overviewRulerOptions.position=`full`)}get backgroundColorRGB(){return this._cachedBg===null&&(this._cachedBg=this.options.backgroundColor?yX.toColor(this.options.backgroundColor):void 0),this._cachedBg}get foregroundColorRGB(){return this._cachedFg===null&&(this._cachedFg=this.options.foregroundColor?yX.toColor(this.options.foregroundColor):void 0),this._cachedFg}dispose(){this._onDispose.fire(),super.dispose()}},L$=1e3,R$=class{constructor(e,t=L$){this._renderCallback=e,this._debounceThresholdMS=t,this._lastRefreshMs=0,this._additionalRefreshRequested=!1}dispose(){this._refreshTimeoutID&&clearTimeout(this._refreshTimeoutID)}refresh(e,t,n){this._rowCount=n,e=e===void 0?0:e,t=t===void 0?this._rowCount-1:t,this._rowStart=this._rowStart===void 0?e:Math.min(this._rowStart,e),this._rowEnd=this._rowEnd===void 0?t:Math.max(this._rowEnd,t);let r=performance.now();if(r-this._lastRefreshMs>=this._debounceThresholdMS)this._lastRefreshMs=r,this._innerRefresh();else if(!this._additionalRefreshRequested){let e=r-this._lastRefreshMs,t=this._debounceThresholdMS-e;this._additionalRefreshRequested=!0,this._refreshTimeoutID=window.setTimeout(()=>{this._lastRefreshMs=performance.now(),this._innerRefresh(),this._additionalRefreshRequested=!1,this._refreshTimeoutID=void 0},t)}}_innerRefresh(){if(this._rowStart===void 0||this._rowEnd===void 0||this._rowCount===void 0)return;let e=Math.max(this._rowStart,0),t=Math.min(this._rowEnd,this._rowCount-1);this._rowStart=void 0,this._rowEnd=void 0,this._renderCallback(e,t)}},z$=20,B$=class extends xq{constructor(e,t,n,r){super(),this._terminal=e,this._coreBrowserService=n,this._renderService=r,this._rowColumns=new WeakMap,this._liveRegionLineCount=0,this._charsToConsume=[],this._charsToAnnounce=``;let i=this._coreBrowserService.mainDocument;this._accessibilityContainer=i.createElement(`div`),this._accessibilityContainer.classList.add(`xterm-accessibility`),this._rowContainer=i.createElement(`div`),this._rowContainer.setAttribute(`role`,`list`),this._rowContainer.classList.add(`xterm-accessibility-tree`),this._rowElements=[];for(let e=0;e<this._terminal.rows;e++)this._rowElements[e]=this._createAccessibilityTreeNode(),this._rowContainer.appendChild(this._rowElements[e]);if(this._topBoundaryFocusListener=e=>this._handleBoundaryFocus(e,0),this._bottomBoundaryFocusListener=e=>this._handleBoundaryFocus(e,1),this._rowElements[0].addEventListener(`focus`,this._topBoundaryFocusListener),this._rowElements[this._rowElements.length-1].addEventListener(`focus`,this._bottomBoundaryFocusListener),this._accessibilityContainer.appendChild(this._rowContainer),this._liveRegion=i.createElement(`div`),this._liveRegion.classList.add(`live-region`),this._liveRegion.setAttribute(`aria-live`,`assertive`),this._accessibilityContainer.appendChild(this._liveRegion),this._liveRegionDebouncer=this._register(new R$(this._renderRows.bind(this))),!this._terminal.element)throw Error(`Cannot enable accessibility before Terminal.open`);this._terminal.element.insertAdjacentElement(`afterbegin`,this._accessibilityContainer),this._register(this._terminal.onResize(e=>this._handleResize(e.rows))),this._register(this._terminal.onRender(e=>this._refreshRows(e.start,e.end))),this._register(this._terminal.onScroll(()=>this._refreshRows())),this._register(this._terminal.onA11yChar(e=>this._handleChar(e))),this._register(this._terminal.onLineFeed(()=>this._handleChar(`
1530
- `))),this._register(this._terminal.onA11yTab(e=>this._handleTab(e))),this._register(this._terminal.onKey(e=>this._handleKey(e.key))),this._register(this._terminal.onBlur(()=>this._clearLiveRegion())),this._register(this._renderService.onDimensionsChange(()=>this._refreshRowsDimensions())),this._register(fY(i,`selectionchange`,()=>this._handleSelectionChange())),this._register(this._coreBrowserService.onDprChange(()=>this._refreshRowsDimensions())),this._refreshRowsDimensions(),this._refreshRows(),this._register(vq(()=>{this._accessibilityContainer.remove(),this._rowElements.length=0}))}_handleTab(e){for(let t=0;t<e;t++)this._handleChar(` `)}_handleChar(e){this._liveRegionLineCount<z$+1&&(this._charsToConsume.length>0?this._charsToConsume.shift()!==e&&(this._charsToAnnounce+=e):this._charsToAnnounce+=e,e===`
1531
- `&&(this._liveRegionLineCount++,this._liveRegionLineCount===z$+1&&(this._liveRegion.textContent+=lK.get())))}_clearLiveRegion(){this._liveRegion.textContent=``,this._liveRegionLineCount=0}_handleKey(e){this._clearLiveRegion(),/\p{Control}/u.test(e)||this._charsToConsume.push(e)}_refreshRows(e,t){this._liveRegionDebouncer.refresh(e,t,this._terminal.rows)}_renderRows(e,t){let n=this._terminal.buffer,r=n.lines.length.toString();for(let i=e;i<=t;i++){let e=n.lines.get(n.ydisp+i),t=[],a=e?.translateToString(!0,void 0,void 0,t)||``,o=(n.ydisp+i+1).toString(),s=this._rowElements[i];s&&(a.length===0?(s.textContent=`\xA0`,this._rowColumns.set(s,[0,1])):(s.textContent=a,this._rowColumns.set(s,t)),s.setAttribute(`aria-posinset`,o),s.setAttribute(`aria-setsize`,r),this._alignRowWidth(s))}this._announceCharacters()}_announceCharacters(){this._charsToAnnounce.length!==0&&(this._liveRegion.textContent+=this._charsToAnnounce,this._charsToAnnounce=``)}_handleBoundaryFocus(e,t){let n=e.target,r=this._rowElements[t===0?1:this._rowElements.length-2];if(n.getAttribute(`aria-posinset`)===(t===0?`1`:`${this._terminal.buffer.lines.length}`)||e.relatedTarget!==r)return;let i,a;if(t===0?(i=n,a=this._rowElements.pop(),this._rowContainer.removeChild(a)):(i=this._rowElements.shift(),a=n,this._rowContainer.removeChild(i)),i.removeEventListener(`focus`,this._topBoundaryFocusListener),a.removeEventListener(`focus`,this._bottomBoundaryFocusListener),t===0){let e=this._createAccessibilityTreeNode();this._rowElements.unshift(e),this._rowContainer.insertAdjacentElement(`afterbegin`,e)}else{let e=this._createAccessibilityTreeNode();this._rowElements.push(e),this._rowContainer.appendChild(e)}this._rowElements[0].addEventListener(`focus`,this._topBoundaryFocusListener),this._rowElements[this._rowElements.length-1].addEventListener(`focus`,this._bottomBoundaryFocusListener),this._terminal.scrollLines(t===0?-1:1),this._rowElements[t===0?1:this._rowElements.length-2].focus(),e.preventDefault(),e.stopImmediatePropagation()}_handleSelectionChange(){if(this._rowElements.length===0)return;let e=this._coreBrowserService.mainDocument.getSelection();if(!e)return;if(e.isCollapsed){this._rowContainer.contains(e.anchorNode)&&this._terminal.clearSelection();return}if(!e.anchorNode||!e.focusNode){console.error(`anchorNode and/or focusNode are null`);return}let t={node:e.anchorNode,offset:e.anchorOffset},n={node:e.focusNode,offset:e.focusOffset};if((t.node.compareDocumentPosition(n.node)&Node.DOCUMENT_POSITION_PRECEDING||t.node===n.node&&t.offset>n.offset)&&([t,n]=[n,t]),t.node.compareDocumentPosition(this._rowElements[0])&(Node.DOCUMENT_POSITION_CONTAINED_BY|Node.DOCUMENT_POSITION_FOLLOWING)&&(t={node:this._rowElements[0].childNodes[0],offset:0}),!this._rowContainer.contains(t.node))return;let r=this._rowElements.slice(-1)[0];if(n.node.compareDocumentPosition(r)&(Node.DOCUMENT_POSITION_CONTAINED_BY|Node.DOCUMENT_POSITION_PRECEDING)&&(n={node:r,offset:r.textContent?.length??0}),!this._rowContainer.contains(n.node))return;let i=({node:e,offset:t})=>{let n=e instanceof Text?e.parentNode:e,r=parseInt(n?.getAttribute(`aria-posinset`),10)-1;if(isNaN(r))return console.warn(`row is invalid. Race condition?`),null;let i=this._rowColumns.get(n);if(!i)return console.warn(`columns is null. Race condition?`),null;let a=t<i.length?i[t]:i.slice(-1)[0]+1;return a>=this._terminal.cols&&(++r,a=0),{row:r,column:a}},a=i(t),o=i(n);if(a&&o){if(a.row>o.row||a.row===o.row&&a.column>=o.column)throw Error(`invalid range`);this._terminal.select(a.column,a.row,(o.row-a.row)*this._terminal.cols-a.column+o.column)}}_handleResize(e){this._rowElements[this._rowElements.length-1].removeEventListener(`focus`,this._bottomBoundaryFocusListener);for(let e=this._rowContainer.children.length;e<this._terminal.rows;e++)this._rowElements[e]=this._createAccessibilityTreeNode(),this._rowContainer.appendChild(this._rowElements[e]);for(;this._rowElements.length>e;)this._rowContainer.removeChild(this._rowElements.pop());this._rowElements[this._rowElements.length-1].addEventListener(`focus`,this._bottomBoundaryFocusListener),this._refreshRowsDimensions()}_createAccessibilityTreeNode(){let e=this._coreBrowserService.mainDocument.createElement(`div`);return e.setAttribute(`role`,`listitem`),e.tabIndex=-1,this._refreshRowDimensions(e),e}_refreshRowsDimensions(){if(this._renderService.dimensions.css.cell.height){Object.assign(this._accessibilityContainer.style,{width:`${this._renderService.dimensions.css.canvas.width}px`,fontSize:`${this._terminal.options.fontSize}px`}),this._rowElements.length!==this._terminal.rows&&this._handleResize(this._terminal.rows);for(let e=0;e<this._terminal.rows;e++)this._refreshRowDimensions(this._rowElements[e]),this._alignRowWidth(this._rowElements[e])}}_refreshRowDimensions(e){e.style.height=`${this._renderService.dimensions.css.cell.height}px`}_alignRowWidth(e){e.style.transform=``;let t=e.getBoundingClientRect().width,n=this._rowColumns.get(e)?.slice(-1)?.[0];if(!n)return;let r=n*this._renderService.dimensions.css.cell.width;e.style.transform=`scaleX(${r/t})`}};B$=iK([aK(1,IK),aK(2,GK),aK(3,qK)],B$);var V$=class extends xq{constructor(e,t,n,r,i){super(),this._element=e,this._mouseService=t,this._renderService=n,this._bufferService=r,this._linkProviderService=i,this._linkCacheDisposables=[],this._isMouseOut=!0,this._wasResized=!1,this._activeLine=-1,this._onShowLinkUnderline=this._register(new Vq),this.onShowLinkUnderline=this._onShowLinkUnderline.event,this._onHideLinkUnderline=this._register(new Vq),this.onHideLinkUnderline=this._onHideLinkUnderline.event,this._register(vq(()=>{gq(this._linkCacheDisposables),this._linkCacheDisposables.length=0,this._lastMouseEvent=void 0,this._activeProviderReplies?.clear()})),this._register(this._bufferService.onResize(()=>{this._clearCurrentLink(),this._wasResized=!0})),this._register(fY(this._element,`mouseleave`,()=>{this._isMouseOut=!0,this._clearCurrentLink()})),this._register(fY(this._element,`mousemove`,this._handleMouseMove.bind(this))),this._register(fY(this._element,`mousedown`,this._handleMouseDown.bind(this))),this._register(fY(this._element,`mouseup`,this._handleMouseUp.bind(this)))}get currentLink(){return this._currentLink}_handleMouseMove(e){this._lastMouseEvent=e;let t=this._positionFromMouseEvent(e,this._element,this._mouseService);if(!t)return;this._isMouseOut=!1;let n=e.composedPath();for(let e=0;e<n.length;e++){let t=n[e];if(t.classList.contains(`xterm`))break;if(t.classList.contains(`xterm-hover`))return}(!this._lastBufferCell||t.x!==this._lastBufferCell.x||t.y!==this._lastBufferCell.y)&&(this._handleHover(t),this._lastBufferCell=t)}_handleHover(e){this._activeLine!==e.y||this._wasResized?(this._clearCurrentLink(),this._askForLink(e,!1),this._wasResized=!1):this._currentLink&&this._linkAtPosition(this._currentLink.link,e)||(this._clearCurrentLink(),this._askForLink(e,!0))}_askForLink(e,t){(!this._activeProviderReplies||!t)&&(this._activeProviderReplies?.forEach(e=>{e?.forEach(e=>{e.link.dispose&&e.link.dispose()})}),this._activeProviderReplies=new Map,this._activeLine=e.y);let n=!1;for(let[r,i]of this._linkProviderService.linkProviders.entries())t?this._activeProviderReplies?.get(r)&&(n=this._checkLinkProviderResult(r,e,n)):i.provideLinks(e.y,t=>{if(this._isMouseOut)return;let i=t?.map(e=>({link:e}));this._activeProviderReplies?.set(r,i),n=this._checkLinkProviderResult(r,e,n),this._activeProviderReplies?.size===this._linkProviderService.linkProviders.length&&this._removeIntersectingLinks(e.y,this._activeProviderReplies)})}_removeIntersectingLinks(e,t){let n=new Set;for(let r=0;r<t.size;r++){let i=t.get(r);if(i)for(let t=0;t<i.length;t++){let r=i[t],a=r.link.range.start.y<e?0:r.link.range.start.x,o=r.link.range.end.y>e?this._bufferService.cols:r.link.range.end.x;for(let e=a;e<=o;e++){if(n.has(e)){i.splice(t--,1);break}n.add(e)}}}}_checkLinkProviderResult(e,t,n){if(!this._activeProviderReplies)return n;let r=this._activeProviderReplies.get(e),i=!1;for(let t=0;t<e;t++)(!this._activeProviderReplies.has(t)||this._activeProviderReplies.get(t))&&(i=!0);if(!i&&r){let e=r.find(e=>this._linkAtPosition(e.link,t));e&&(n=!0,this._handleNewLink(e))}if(this._activeProviderReplies.size===this._linkProviderService.linkProviders.length&&!n)for(let e=0;e<this._activeProviderReplies.size;e++){let r=this._activeProviderReplies.get(e)?.find(e=>this._linkAtPosition(e.link,t));if(r){n=!0,this._handleNewLink(r);break}}return n}_handleMouseDown(){this._mouseDownLink=this._currentLink}_handleMouseUp(e){if(!this._currentLink)return;let t=this._positionFromMouseEvent(e,this._element,this._mouseService);t&&this._mouseDownLink&&H$(this._mouseDownLink.link,this._currentLink.link)&&this._linkAtPosition(this._currentLink.link,t)&&this._currentLink.link.activate(e,this._currentLink.link.text)}_clearCurrentLink(e,t){!this._currentLink||!this._lastMouseEvent||(!e||!t||this._currentLink.link.range.start.y>=e&&this._currentLink.link.range.end.y<=t)&&(this._linkLeave(this._element,this._currentLink.link,this._lastMouseEvent),this._currentLink=void 0,gq(this._linkCacheDisposables),this._linkCacheDisposables.length=0)}_handleNewLink(e){if(!this._lastMouseEvent)return;let t=this._positionFromMouseEvent(this._lastMouseEvent,this._element,this._mouseService);t&&this._linkAtPosition(e.link,t)&&(this._currentLink=e,this._currentLink.state={decorations:{underline:e.link.decorations===void 0||e.link.decorations.underline,pointerCursor:e.link.decorations===void 0||e.link.decorations.pointerCursor},isHovered:!0},this._linkHover(this._element,e.link,this._lastMouseEvent),e.link.decorations={},Object.defineProperties(e.link.decorations,{pointerCursor:{get:()=>this._currentLink?.state?.decorations.pointerCursor,set:e=>{this._currentLink?.state&&this._currentLink.state.decorations.pointerCursor!==e&&(this._currentLink.state.decorations.pointerCursor=e,this._currentLink.state.isHovered&&this._element.classList.toggle(`xterm-cursor-pointer`,e))}},underline:{get:()=>this._currentLink?.state?.decorations.underline,set:t=>{this._currentLink?.state&&this._currentLink?.state?.decorations.underline!==t&&(this._currentLink.state.decorations.underline=t,this._currentLink.state.isHovered&&this._fireUnderlineEvent(e.link,t))}}}),this._linkCacheDisposables.push(this._renderService.onRenderedViewportChange(e=>{if(!this._currentLink)return;let t=e.start===0?0:e.start+1+this._bufferService.buffer.ydisp,n=this._bufferService.buffer.ydisp+1+e.end;if(this._currentLink.link.range.start.y>=t&&this._currentLink.link.range.end.y<=n&&(this._clearCurrentLink(t,n),this._lastMouseEvent)){let e=this._positionFromMouseEvent(this._lastMouseEvent,this._element,this._mouseService);e&&this._askForLink(e,!1)}})))}_linkHover(e,t,n){this._currentLink?.state&&(this._currentLink.state.isHovered=!0,this._currentLink.state.decorations.underline&&this._fireUnderlineEvent(t,!0),this._currentLink.state.decorations.pointerCursor&&e.classList.add(`xterm-cursor-pointer`)),t.hover&&t.hover(n,t.text)}_fireUnderlineEvent(e,t){let n=e.range,r=this._bufferService.buffer.ydisp,i=this._createLinkUnderlineEvent(n.start.x-1,n.start.y-r-1,n.end.x,n.end.y-r-1,void 0);(t?this._onShowLinkUnderline:this._onHideLinkUnderline).fire(i)}_linkLeave(e,t,n){this._currentLink?.state&&(this._currentLink.state.isHovered=!1,this._currentLink.state.decorations.underline&&this._fireUnderlineEvent(t,!1),this._currentLink.state.decorations.pointerCursor&&e.classList.remove(`xterm-cursor-pointer`)),t.leave&&t.leave(n,t.text)}_linkAtPosition(e,t){let n=e.range.start.y*this._bufferService.cols+e.range.start.x,r=e.range.end.y*this._bufferService.cols+e.range.end.x,i=t.y*this._bufferService.cols+t.x;return n<=i&&i<=r}_positionFromMouseEvent(e,t,n){let r=n.getCoords(e,t,this._bufferService.cols,this._bufferService.rows);if(r)return{x:r[0],y:r[1]+this._bufferService.buffer.ydisp}}_createLinkUnderlineEvent(e,t,n,r,i){return{x1:e,y1:t,x2:n,y2:r,cols:this._bufferService.cols,fg:i}}};V$=iK([aK(1,KK),aK(2,qK),aK(3,MK),aK(4,ZK)],V$);function H$(e,t){return e.text===t.text&&e.range.start.x===t.range.start.x&&e.range.start.y===t.range.start.y&&e.range.end.x===t.range.end.x&&e.range.end.y===t.range.end.y}var U$=class extends O${constructor(e={}){super(e),this._linkifier=this._register(new Sq),this.browser=tZ,this._keyDownHandled=!1,this._keyDownSeen=!1,this._keyPressHandled=!1,this._unprocessedDeadKey=!1,this._accessibilityManager=this._register(new Sq),this._onCursorMove=this._register(new Vq),this.onCursorMove=this._onCursorMove.event,this._onKey=this._register(new Vq),this.onKey=this._onKey.event,this._onRender=this._register(new Vq),this.onRender=this._onRender.event,this._onSelectionChange=this._register(new Vq),this.onSelectionChange=this._onSelectionChange.event,this._onTitleChange=this._register(new Vq),this.onTitleChange=this._onTitleChange.event,this._onBell=this._register(new Vq),this.onBell=this._onBell.event,this._onFocus=this._register(new Vq),this._onBlur=this._register(new Vq),this._onA11yCharEmitter=this._register(new Vq),this._onA11yTabEmitter=this._register(new Vq),this._onWillOpen=this._register(new Vq),this._setup(),this._decorationService=this._instantiationService.createInstance(F$),this._instantiationService.setService(VK,this._decorationService),this._linkProviderService=this._instantiationService.createInstance(XX),this._instantiationService.setService(ZK,this._linkProviderService),this._linkProviderService.registerLinkProvider(this._instantiationService.createInstance(HK)),this._register(this._inputHandler.onRequestBell(()=>this._onBell.fire())),this._register(this._inputHandler.onRequestRefreshRows(e=>this.refresh(e?.start??0,e?.end??this.rows-1))),this._register(this._inputHandler.onRequestSendFocus(()=>this._reportFocus())),this._register(this._inputHandler.onRequestReset(()=>this.reset())),this._register(this._inputHandler.onRequestWindowsOptionsReport(e=>this._reportWindowsOptions(e))),this._register(this._inputHandler.onColor(e=>this._handleColorEvent(e))),this._register(kq.forward(this._inputHandler.onCursorMove,this._onCursorMove)),this._register(kq.forward(this._inputHandler.onTitleChange,this._onTitleChange)),this._register(kq.forward(this._inputHandler.onA11yChar,this._onA11yCharEmitter)),this._register(kq.forward(this._inputHandler.onA11yTab,this._onA11yTabEmitter)),this._register(this._bufferService.onResize(e=>this._afterResize(e.cols,e.rows))),this._register(vq(()=>{this._customKeyEventHandler=void 0,this.element?.parentNode?.removeChild(this.element)}))}get linkifier(){return this._linkifier.value}get onFocus(){return this._onFocus.event}get onBlur(){return this._onBlur.event}get onA11yChar(){return this._onA11yCharEmitter.event}get onA11yTab(){return this._onA11yTabEmitter.event}get onWillOpen(){return this._onWillOpen.event}_handleColorEvent(e){if(this._themeService)for(let t of e){let e,n=``;switch(t.index){case 256:e=`foreground`,n=`10`;break;case 257:e=`background`,n=`11`;break;case 258:e=`cursor`,n=`12`;break;default:e=`ansi`,n=`4;`+t.index}switch(t.type){case 0:let r=vX.toColorRGB(e===`ansi`?this._themeService.colors.ansi[t.index]:this._themeService.colors[e]);this.coreService.triggerDataEvent(`${$.ESC}]${n};${f$(r)}${uX.ST}`);break;case 1:if(e===`ansi`)this._themeService.modifyColors(e=>e.ansi[t.index]=_X.toColor(...t.color));else{let n=e;this._themeService.modifyColors(e=>e[n]=_X.toColor(...t.color))}break;case 2:this._themeService.restoreColor(t.index)}}}_setup(){super._setup(),this._customKeyEventHandler=void 0}get buffer(){return this.buffers.active}focus(){this.textarea&&this.textarea.focus({preventScroll:!0})}_handleScreenReaderModeOptionChange(e){e?!this._accessibilityManager.value&&this._renderService&&(this._accessibilityManager.value=this._instantiationService.createInstance(B$,this)):this._accessibilityManager.clear()}_handleTextAreaFocus(e){this.coreService.decPrivateModes.sendFocus&&this.coreService.triggerDataEvent($.ESC+`[I`),this.element.classList.add(`focus`),this._showCursor(),this._onFocus.fire()}blur(){return this.textarea?.blur()}_handleTextAreaBlur(){this.textarea.value=``,this.refresh(this.buffer.y,this.buffer.y),this.coreService.decPrivateModes.sendFocus&&this.coreService.triggerDataEvent($.ESC+`[O`),this.element.classList.remove(`focus`),this._onBlur.fire()}_syncTextArea(){if(!this.textarea||!this.buffer.isCursorInViewport||this._compositionHelper.isComposing||!this._renderService)return;let e=this.buffer.ybase+this.buffer.y,t=this.buffer.lines.get(e);if(!t)return;let n=Math.min(this.buffer.x,this.cols-1),r=this._renderService.dimensions.css.cell.height,i=t.getWidth(n),a=this._renderService.dimensions.css.cell.width*i,o=this.buffer.y*this._renderService.dimensions.css.cell.height,s=n*this._renderService.dimensions.css.cell.width;this.textarea.style.left=s+`px`,this.textarea.style.top=o+`px`,this.textarea.style.width=a+`px`,this.textarea.style.height=r+`px`,this.textarea.style.lineHeight=r+`px`,this.textarea.style.zIndex=`-5`}_initGlobal(){this._bindKeys(),this._register(fY(this.element,`copy`,e=>{this.hasSelection()&&fK(e,this._selectionService)}));let e=e=>pK(e,this.textarea,this.coreService,this.optionsService);this._register(fY(this.textarea,`paste`,e)),this._register(fY(this.element,`paste`,e)),aZ?this._register(fY(this.element,`mousedown`,e=>{e.button===2&&gK(e,this.textarea,this.screenElement,this._selectionService,this.options.rightClickSelectsWord)})):this._register(fY(this.element,`contextmenu`,e=>{gK(e,this.textarea,this.screenElement,this._selectionService,this.options.rightClickSelectsWord)})),pZ&&this._register(fY(this.element,`auxclick`,e=>{e.button===1&&hK(e,this.textarea,this.screenElement)}))}_bindKeys(){this._register(fY(this.textarea,`keyup`,e=>this._keyUp(e),!0)),this._register(fY(this.textarea,`keydown`,e=>this._keyDown(e),!0)),this._register(fY(this.textarea,`keypress`,e=>this._keyPress(e),!0)),this._register(fY(this.textarea,`compositionstart`,()=>this._compositionHelper.compositionstart())),this._register(fY(this.textarea,`compositionupdate`,e=>this._compositionHelper.compositionupdate(e))),this._register(fY(this.textarea,`compositionend`,()=>this._compositionHelper.compositionend())),this._register(fY(this.textarea,`input`,e=>this._inputEvent(e),!0)),this._register(this.onRender(()=>this._compositionHelper.updateCompositionElements()))}open(e){if(!e)throw Error(`Terminal requires a parent element.`);if(e.isConnected||this._logService.debug(`Terminal.open was called on an element that was not attached to the DOM`),this.element?.ownerDocument.defaultView&&this._coreBrowserService){this.element.ownerDocument.defaultView!==this._coreBrowserService.window&&(this._coreBrowserService.window=this.element.ownerDocument.defaultView);return}this._document=e.ownerDocument,this.options.documentOverride&&this.options.documentOverride instanceof Document&&(this._document=this.optionsService.rawOptions.documentOverride),this.element=this._document.createElement(`div`),this.element.dir=`ltr`,this.element.classList.add(`terminal`),this.element.classList.add(`xterm`),e.appendChild(this.element);let t=this._document.createDocumentFragment();this._viewportElement=this._document.createElement(`div`),this._viewportElement.classList.add(`xterm-viewport`),t.appendChild(this._viewportElement),this.screenElement=this._document.createElement(`div`),this.screenElement.classList.add(`xterm-screen`),this._register(fY(this.screenElement,`mousemove`,e=>this.updateCursorStyle(e))),this._helperContainer=this._document.createElement(`div`),this._helperContainer.classList.add(`xterm-helpers`),this.screenElement.appendChild(this._helperContainer),t.appendChild(this.screenElement);let n=this.textarea=this._document.createElement(`textarea`);this.textarea.classList.add(`xterm-helper-textarea`),this.textarea.setAttribute(`aria-label`,sK.get()),mZ||this.textarea.setAttribute(`aria-multiline`,`false`),this.textarea.setAttribute(`autocorrect`,`off`),this.textarea.setAttribute(`autocapitalize`,`off`),this.textarea.setAttribute(`spellcheck`,`false`),this.textarea.tabIndex=0,this._register(this.optionsService.onSpecificOptionChange(`disableStdin`,()=>n.readOnly=this.optionsService.rawOptions.disableStdin)),this.textarea.readOnly=this.optionsService.rawOptions.disableStdin,this._coreBrowserService=this._register(this._instantiationService.createInstance(JX,this.textarea,e.ownerDocument.defaultView??window,this._document??typeof window<`u`?window.document:null)),this._instantiationService.setService(GK,this._coreBrowserService),this._register(fY(this.textarea,`focus`,e=>this._handleTextAreaFocus(e))),this._register(fY(this.textarea,`blur`,()=>this._handleTextAreaBlur())),this._helperContainer.appendChild(this.textarea),this._charSizeService=this._instantiationService.createInstance(WX,this._document,this._helperContainer),this._instantiationService.setService(WK,this._charSizeService),this._themeService=this._instantiationService.createInstance(QZ),this._instantiationService.setService(XK,this._themeService),this._characterJoinerService=this._instantiationService.createInstance(TX),this._instantiationService.setService(YK,this._characterJoinerService),this._renderService=this._register(this._instantiationService.createInstance(bZ,this.rows,this.screenElement)),this._instantiationService.setService(qK,this._renderService),this._register(this._renderService.onRenderedViewportChange(e=>this._onRender.fire(e))),this.onResize(e=>this._renderService.resize(e.cols,e.rows)),this._compositionView=this._document.createElement(`div`),this._compositionView.classList.add(`composition-view`),this._compositionHelper=this._instantiationService.createInstance(dX,this.textarea,this._compositionView),this._helperContainer.appendChild(this._compositionView),this._mouseService=this._instantiationService.createInstance($X),this._instantiationService.setService(KK,this._mouseService);let r=this._linkifier.value=this._register(this._instantiationService.createInstance(V$,this.screenElement));this.element.appendChild(t);try{this._onWillOpen.fire(this.element)}catch{}this._renderService.hasRenderer()||this._renderService.setRenderer(this._createRenderer()),this._register(this.onCursorMove(()=>{this._renderService.handleCursorMove(),this._syncTextArea()})),this._register(this.onResize(()=>this._renderService.handleResize(this.cols,this.rows))),this._register(this.onBlur(()=>this._renderService.handleBlur())),this._register(this.onFocus(()=>this._renderService.handleFocus())),this._viewport=this._register(this._instantiationService.createInstance(nX,this.element,this.screenElement)),this._register(this._viewport.onRequestScrollLines(e=>{super.scrollLines(e,!1),this.refresh(0,this.rows-1)})),this._selectionService=this._register(this._instantiationService.createInstance(HZ,this.element,this.screenElement,r)),this._instantiationService.setService(JK,this._selectionService),this._register(this._selectionService.onRequestScrollLines(e=>this.scrollLines(e.amount,e.suppressScrollEvent))),this._register(this._selectionService.onSelectionChange(()=>this._onSelectionChange.fire())),this._register(this._selectionService.onRequestRedraw(e=>this._renderService.handleSelectionChanged(e.start,e.end,e.columnSelectMode))),this._register(this._selectionService.onLinuxMouseSelection(e=>{this.textarea.value=e,this.textarea.focus(),this.textarea.select()})),this._register(kq.any(this._onScroll.event,this._inputHandler.onScroll)(()=>{this._selectionService.refresh(),this._viewport?.queueSync()})),this._register(this._instantiationService.createInstance(rX,this.screenElement)),this._register(fY(this.element,`mousedown`,e=>this._selectionService.handleMouseDown(e))),this.coreMouseService.areMouseEventsActive?(this._selectionService.disable(),this.element.classList.add(`enable-mouse-events`)):this._selectionService.enable(),this.options.screenReaderMode&&(this._accessibilityManager.value=this._instantiationService.createInstance(B$,this)),this._register(this.optionsService.onSpecificOptionChange(`screenReaderMode`,e=>this._handleScreenReaderModeOptionChange(e))),this.options.overviewRuler.width&&(this._overviewRulerRenderer=this._register(this._instantiationService.createInstance(cX,this._viewportElement,this.screenElement))),this.optionsService.onSpecificOptionChange(`overviewRuler`,e=>{!this._overviewRulerRenderer&&e&&this._viewportElement&&this.screenElement&&(this._overviewRulerRenderer=this._register(this._instantiationService.createInstance(cX,this._viewportElement,this.screenElement)))}),this._charSizeService.measure(),this.refresh(0,this.rows-1),this._initGlobal(),this.bindMouse()}_createRenderer(){return this._instantiationService.createInstance(UX,this,this._document,this.element,this.screenElement,this._viewportElement,this._helperContainer,this.linkifier)}bindMouse(){let e=this,t=this.element;function n(t){let n=e._mouseService.getMouseReportCoords(t,e.screenElement);if(!n)return!1;let r,i;switch(t.overrideType||t.type){case`mousemove`:i=32,t.buttons===void 0?(r=3,t.button!==void 0&&(r=t.button<3?t.button:3)):r=t.buttons&1?0:t.buttons&4?1:t.buttons&2?2:3;break;case`mouseup`:i=0,r=t.button<3?t.button:3;break;case`mousedown`:i=1,r=t.button<3?t.button:3;break;case`wheel`:if(e._customWheelEventHandler&&e._customWheelEventHandler(t)===!1)return!1;let n=t.deltaY;if(n===0||e.coreMouseService.consumeWheelEvent(t,e._renderService?.dimensions?.device?.cell?.height,e._coreBrowserService?.dpr)===0)return!1;i=n<0?0:1,r=4;break;default:return!1}return i===void 0||r===void 0||r>4?!1:e.coreMouseService.triggerMouseEvent({col:n.col,row:n.row,x:n.x,y:n.y,button:r,action:i,ctrl:t.ctrlKey,alt:t.altKey,shift:t.shiftKey})}let r={mouseup:null,wheel:null,mousedrag:null,mousemove:null},i={mouseup:e=>(n(e),e.buttons||(this._document.removeEventListener(`mouseup`,r.mouseup),r.mousedrag&&this._document.removeEventListener(`mousemove`,r.mousedrag)),this.cancel(e)),wheel:e=>(n(e),this.cancel(e,!0)),mousedrag:e=>{e.buttons&&n(e)},mousemove:e=>{e.buttons||n(e)}};this._register(this.coreMouseService.onProtocolChange(e=>{e?(this.optionsService.rawOptions.logLevel===`debug`&&this._logService.debug(`Binding to mouse events:`,this.coreMouseService.explainEvents(e)),this.element.classList.add(`enable-mouse-events`),this._selectionService.disable()):(this._logService.debug(`Unbinding from mouse events.`),this.element.classList.remove(`enable-mouse-events`),this._selectionService.enable()),e&8?r.mousemove||=(t.addEventListener(`mousemove`,i.mousemove),i.mousemove):(t.removeEventListener(`mousemove`,r.mousemove),r.mousemove=null),e&16?r.wheel||=(t.addEventListener(`wheel`,i.wheel,{passive:!1}),i.wheel):(t.removeEventListener(`wheel`,r.wheel),r.wheel=null),e&2?r.mouseup||=i.mouseup:(this._document.removeEventListener(`mouseup`,r.mouseup),r.mouseup=null),e&4?r.mousedrag||=i.mousedrag:(this._document.removeEventListener(`mousemove`,r.mousedrag),r.mousedrag=null)})),this.coreMouseService.activeProtocol=this.coreMouseService.activeProtocol,this._register(fY(t,`mousedown`,e=>{if(e.preventDefault(),this.focus(),this.coreMouseService.areMouseEventsActive&&!this._selectionService.shouldForceSelection(e))return n(e),r.mouseup&&this._document.addEventListener(`mouseup`,r.mouseup),r.mousedrag&&this._document.addEventListener(`mousemove`,r.mousedrag),this.cancel(e)})),this._register(fY(t,`wheel`,t=>{if(!r.wheel){if(this._customWheelEventHandler&&this._customWheelEventHandler(t)===!1)return!1;if(!this.buffer.hasScrollback){if(t.deltaY===0)return!1;if(e.coreMouseService.consumeWheelEvent(t,e._renderService?.dimensions?.device?.cell?.height,e._coreBrowserService?.dpr)===0)return this.cancel(t,!0);let n=$.ESC+(this.coreService.decPrivateModes.applicationCursorKeys?`O`:`[`)+(t.deltaY<0?`A`:`B`);return this.coreService.triggerDataEvent(n,!0),this.cancel(t,!0)}}},{passive:!1}))}refresh(e,t){this._renderService?.refreshRows(e,t)}updateCursorStyle(e){this._selectionService?.shouldColumnSelect(e)?this.element.classList.add(`column-select`):this.element.classList.remove(`column-select`)}_showCursor(){this.coreService.isCursorInitialized||(this.coreService.isCursorInitialized=!0,this.refresh(this.buffer.y,this.buffer.y))}scrollLines(e,t){this._viewport?this._viewport.scrollLines(e):super.scrollLines(e,t),this.refresh(0,this.rows-1)}scrollPages(e){this.scrollLines(e*(this.rows-1))}scrollToTop(){this.scrollLines(-this._bufferService.buffer.ydisp)}scrollToBottom(e){e&&this._viewport?this._viewport.scrollToLine(this.buffer.ybase,!0):this.scrollLines(this._bufferService.buffer.ybase-this._bufferService.buffer.ydisp)}scrollToLine(e){let t=e-this._bufferService.buffer.ydisp;t!==0&&this.scrollLines(t)}paste(e){mK(e,this.textarea,this.coreService,this.optionsService)}attachCustomKeyEventHandler(e){this._customKeyEventHandler=e}attachCustomWheelEventHandler(e){this._customWheelEventHandler=e}registerLinkProvider(e){return this._linkProviderService.registerLinkProvider(e)}registerCharacterJoiner(e){if(!this._characterJoinerService)throw Error(`Terminal must be opened first`);let t=this._characterJoinerService.register(e);return this.refresh(0,this.rows-1),t}deregisterCharacterJoiner(e){if(!this._characterJoinerService)throw Error(`Terminal must be opened first`);this._characterJoinerService.deregister(e)&&this.refresh(0,this.rows-1)}get markers(){return this.buffer.markers}registerMarker(e){return this.buffer.addMarker(this.buffer.ybase+this.buffer.y+e)}registerDecoration(e){return this._decorationService.registerDecoration(e)}hasSelection(){return this._selectionService?this._selectionService.hasSelection:!1}select(e,t,n){this._selectionService.setSelection(e,t,n)}getSelection(){return this._selectionService?this._selectionService.selectionText:``}getSelectionPosition(){if(this._selectionService&&this._selectionService.hasSelection)return{start:{x:this._selectionService.selectionStart[0],y:this._selectionService.selectionStart[1]},end:{x:this._selectionService.selectionEnd[0],y:this._selectionService.selectionEnd[1]}}}clearSelection(){this._selectionService?.clearSelection()}selectAll(){this._selectionService?.selectAll()}selectLines(e,t){this._selectionService?.selectLines(e,t)}_keyDown(e){if(this._keyDownHandled=!1,this._keyDownSeen=!0,this._customKeyEventHandler&&this._customKeyEventHandler(e)===!1)return!1;let t=this.browser.isMac&&this.options.macOptionIsMeta&&e.altKey;if(!t&&!this._compositionHelper.keydown(e))return this.options.scrollOnUserInput&&this.buffer.ybase!==this.buffer.ydisp&&this.scrollToBottom(!0),!1;!t&&(e.key===`Dead`||e.key===`AltGraph`)&&(this._unprocessedDeadKey=!0);let n=A$(e,this.coreService.decPrivateModes.applicationCursorKeys,this.browser.isMac,this.options.macOptionIsMeta);if(this.updateCursorStyle(e),n.type===3||n.type===2){let t=this.rows-1;return this.scrollLines(n.type===2?-t:t),this.cancel(e,!0)}if(n.type===1&&this.selectAll(),this._isThirdLevelShift(this.browser,e)||(n.cancel&&this.cancel(e,!0),!n.key)||e.key&&!e.ctrlKey&&!e.altKey&&!e.metaKey&&e.key.length===1&&e.key.charCodeAt(0)>=65&&e.key.charCodeAt(0)<=90)return!0;if(this._unprocessedDeadKey)return this._unprocessedDeadKey=!1,!0;if((n.key===$.ETX||n.key===$.CR)&&(this.textarea.value=``),this._onKey.fire({key:n.key,domEvent:e}),this._showCursor(),this.coreService.triggerDataEvent(n.key,!0),!this.optionsService.rawOptions.screenReaderMode||e.altKey||e.ctrlKey)return this.cancel(e,!0);this._keyDownHandled=!0}_isThirdLevelShift(e,t){let n=e.isMac&&!this.options.macOptionIsMeta&&t.altKey&&!t.ctrlKey&&!t.metaKey||e.isWindows&&t.altKey&&t.ctrlKey&&!t.metaKey||e.isWindows&&t.getModifierState(`AltGraph`);return t.type===`keypress`?n:n&&(!t.keyCode||t.keyCode>47)}_keyUp(e){this._keyDownSeen=!1,!(this._customKeyEventHandler&&this._customKeyEventHandler(e)===!1)&&(W$(e)||this.focus(),this.updateCursorStyle(e),this._keyPressHandled=!1)}_keyPress(e){let t;if(this._keyPressHandled=!1,this._keyDownHandled||this._customKeyEventHandler&&this._customKeyEventHandler(e)===!1)return!1;if(this.cancel(e),e.charCode)t=e.charCode;else if(e.which===null||e.which===void 0)t=e.keyCode;else if(e.which!==0&&e.charCode!==0)t=e.which;else return!1;return!t||(e.altKey||e.ctrlKey||e.metaKey)&&!this._isThirdLevelShift(this.browser,e)?!1:(t=String.fromCharCode(t),this._onKey.fire({key:t,domEvent:e}),this._showCursor(),this.coreService.triggerDataEvent(t,!0),this._keyPressHandled=!0,this._unprocessedDeadKey=!1,!0)}_inputEvent(e){if(e.data&&e.inputType===`insertText`&&(!e.composed||!this._keyDownSeen)&&!this.optionsService.rawOptions.screenReaderMode){if(this._keyPressHandled)return!1;this._unprocessedDeadKey=!1;let t=e.data;return this.coreService.triggerDataEvent(t,!0),this.cancel(e),!0}return!1}resize(e,t){e===this.cols&&t===this.rows?this._charSizeService&&!this._charSizeService.hasValidSize&&this._charSizeService.measure():super.resize(e,t)}_afterResize(e,t){this._charSizeService?.measure()}clear(){if(this.buffer.ybase!==0||this.buffer.y!==0){this.buffer.clearAllMarkers(),this.buffer.lines.set(0,this.buffer.lines.get(this.buffer.ybase+this.buffer.y)),this.buffer.lines.length=1,this.buffer.ydisp=0,this.buffer.ybase=0,this.buffer.y=0;for(let e=1;e<this.rows;e++)this.buffer.lines.push(this.buffer.getBlankLine(cQ));this._onScroll.fire({position:this.buffer.ydisp}),this.refresh(0,this.rows-1)}}reset(){this.options.rows=this.rows,this.options.cols=this.cols;let e=this._customKeyEventHandler;this._setup(),super.reset(),this._selectionService?.reset(),this._decorationService.reset(),this._customKeyEventHandler=e,this.refresh(0,this.rows-1)}clearTextureAtlas(){this._renderService?.clearTextureAtlas()}_reportFocus(){this.element?.classList.contains(`focus`)?this.coreService.triggerDataEvent($.ESC+`[I`):this.coreService.triggerDataEvent($.ESC+`[O`)}_reportWindowsOptions(e){if(this._renderService)switch(e){case 0:let e=this._renderService.dimensions.css.canvas.width.toFixed(0),t=this._renderService.dimensions.css.canvas.height.toFixed(0);this.coreService.triggerDataEvent(`${$.ESC}[4;${t};${e}t`);break;case 1:let n=this._renderService.dimensions.css.cell.width.toFixed(0),r=this._renderService.dimensions.css.cell.height.toFixed(0);this.coreService.triggerDataEvent(`${$.ESC}[6;${r};${n}t`)}}cancel(e,t){if(this.options.cancelEvents||t)return e.preventDefault(),e.stopPropagation(),!1}};function W$(e){return e.keyCode===16||e.keyCode===17||e.keyCode===18}var G$=class{constructor(){this._addons=[]}dispose(){for(let e=this._addons.length-1;e>=0;e--)this._addons[e].instance.dispose()}loadAddon(e,t){let n={instance:t,dispose:t.dispose,isDisposed:!1};this._addons.push(n),t.dispose=()=>this._wrappedAddonDispose(n),t.activate(e)}_wrappedAddonDispose(e){if(e.isDisposed)return;let t=-1;for(let n=0;n<this._addons.length;n++)if(this._addons[n]===e){t=n;break}if(t===-1)throw Error(`Could not dispose an addon that has not been loaded`);e.isDisposed=!0,e.dispose.apply(e.instance),this._addons.splice(t,1)}},K$=class{constructor(e){this._line=e}get isWrapped(){return this._line.isWrapped}get length(){return this._line.length}getCell(e,t){if(!(e<0||e>=this._line.length))return t?(this._line.loadCell(e,t),t):this._line.loadCell(e,new TK)}translateToString(e,t,n){return this._line.translateToString(e,t,n)}},q$=class{constructor(e,t){this._buffer=e,this.type=t}init(e){return this._buffer=e,this}get cursorY(){return this._buffer.y}get cursorX(){return this._buffer.x}get viewportY(){return this._buffer.ydisp}get baseY(){return this._buffer.ybase}get length(){return this._buffer.lines.length}getLine(e){let t=this._buffer.lines.get(e);if(t)return new K$(t)}getNullCell(){return new TK}},J$=class extends xq{constructor(e){super(),this._core=e,this._onBufferChange=this._register(new Vq),this.onBufferChange=this._onBufferChange.event,this._normal=new q$(this._core.buffers.normal,`normal`),this._alternate=new q$(this._core.buffers.alt,`alternate`),this._core.buffers.onBufferActivate(()=>this._onBufferChange.fire(this.active))}get active(){if(this._core.buffers.active===this._core.buffers.normal)return this.normal;if(this._core.buffers.active===this._core.buffers.alt)return this.alternate;throw Error(`Active buffer is neither normal nor alternate`)}get normal(){return this._normal.init(this._core.buffers.normal)}get alternate(){return this._alternate.init(this._core.buffers.alt)}},Y$=class{constructor(e){this._core=e}registerCsiHandler(e,t){return this._core.registerCsiHandler(e,e=>t(e.toArray()))}addCsiHandler(e,t){return this.registerCsiHandler(e,t)}registerDcsHandler(e,t){return this._core.registerDcsHandler(e,(e,n)=>t(e,n.toArray()))}addDcsHandler(e,t){return this.registerDcsHandler(e,t)}registerEscHandler(e,t){return this._core.registerEscHandler(e,t)}addEscHandler(e,t){return this.registerEscHandler(e,t)}registerOscHandler(e,t){return this._core.registerOscHandler(e,t)}addOscHandler(e,t){return this.registerOscHandler(e,t)}},X$=class{constructor(e){this._core=e}register(e){this._core.unicodeService.register(e)}get versions(){return this._core.unicodeService.versions}get activeVersion(){return this._core.unicodeService.activeVersion}set activeVersion(e){this._core.unicodeService.activeVersion=e}},Z$=[`cols`,`rows`],Q$=0,$$=class extends xq{constructor(e){super(),this._core=this._register(new U$(e)),this._addonManager=this._register(new G$),this._publicOptions={...this._core.options};let t=e=>this._core.options[e],n=(e,t)=>{this._checkReadonlyOptions(e),this._core.options[e]=t};for(let e in this._core.options){let r={get:t.bind(this,e),set:n.bind(this,e)};Object.defineProperty(this._publicOptions,e,r)}}_checkReadonlyOptions(e){if(Z$.includes(e))throw Error(`Option "${e}" can only be set in the constructor`)}_checkProposedApi(){if(!this._core.optionsService.rawOptions.allowProposedApi)throw Error(`You must set the allowProposedApi option to true to use proposed API`)}get onBell(){return this._core.onBell}get onBinary(){return this._core.onBinary}get onCursorMove(){return this._core.onCursorMove}get onData(){return this._core.onData}get onKey(){return this._core.onKey}get onLineFeed(){return this._core.onLineFeed}get onRender(){return this._core.onRender}get onResize(){return this._core.onResize}get onScroll(){return this._core.onScroll}get onSelectionChange(){return this._core.onSelectionChange}get onTitleChange(){return this._core.onTitleChange}get onWriteParsed(){return this._core.onWriteParsed}get element(){return this._core.element}get parser(){return this._parser||=new Y$(this._core),this._parser}get unicode(){return this._checkProposedApi(),new X$(this._core)}get textarea(){return this._core.textarea}get rows(){return this._core.rows}get cols(){return this._core.cols}get buffer(){return this._buffer||=this._register(new J$(this._core)),this._buffer}get markers(){return this._checkProposedApi(),this._core.markers}get modes(){let e=this._core.coreService.decPrivateModes,t=`none`;switch(this._core.coreMouseService.activeProtocol){case`X10`:t=`x10`;break;case`VT200`:t=`vt200`;break;case`DRAG`:t=`drag`;break;case`ANY`:t=`any`}return{applicationCursorKeysMode:e.applicationCursorKeys,applicationKeypadMode:e.applicationKeypad,bracketedPasteMode:e.bracketedPasteMode,insertMode:this._core.coreService.modes.insertMode,mouseTrackingMode:t,originMode:e.origin,reverseWraparoundMode:e.reverseWraparound,sendFocusMode:e.sendFocus,synchronizedOutputMode:e.synchronizedOutput,wraparoundMode:e.wraparound}}get options(){return this._publicOptions}set options(e){for(let t in e)this._publicOptions[t]=e[t]}blur(){this._core.blur()}focus(){this._core.focus()}input(e,t=!0){this._core.input(e,t)}resize(e,t){this._verifyIntegers(e,t),this._core.resize(e,t)}open(e){this._core.open(e)}attachCustomKeyEventHandler(e){this._core.attachCustomKeyEventHandler(e)}attachCustomWheelEventHandler(e){this._core.attachCustomWheelEventHandler(e)}registerLinkProvider(e){return this._core.registerLinkProvider(e)}registerCharacterJoiner(e){return this._checkProposedApi(),this._core.registerCharacterJoiner(e)}deregisterCharacterJoiner(e){this._checkProposedApi(),this._core.deregisterCharacterJoiner(e)}registerMarker(e=0){return this._verifyIntegers(e),this._core.registerMarker(e)}registerDecoration(e){return this._checkProposedApi(),this._verifyPositiveIntegers(e.x??0,e.width??0,e.height??0),this._core.registerDecoration(e)}hasSelection(){return this._core.hasSelection()}select(e,t,n){this._verifyIntegers(e,t,n),this._core.select(e,t,n)}getSelection(){return this._core.getSelection()}getSelectionPosition(){return this._core.getSelectionPosition()}clearSelection(){this._core.clearSelection()}selectAll(){this._core.selectAll()}selectLines(e,t){this._verifyIntegers(e,t),this._core.selectLines(e,t)}dispose(){super.dispose()}scrollLines(e){this._verifyIntegers(e),this._core.scrollLines(e)}scrollPages(e){this._verifyIntegers(e),this._core.scrollPages(e)}scrollToTop(){this._core.scrollToTop()}scrollToBottom(){this._core.scrollToBottom()}scrollToLine(e){this._verifyIntegers(e),this._core.scrollToLine(e)}clear(){this._core.clear()}write(e,t){this._core.write(e,t)}writeln(e,t){this._core.write(e),this._core.write(`\r
1532
- `,t)}paste(e){this._core.paste(e)}refresh(e,t){this._verifyIntegers(e,t),this._core.refresh(e,t)}reset(){this._core.reset()}clearTextureAtlas(){this._core.clearTextureAtlas()}loadAddon(e){this._addonManager.loadAddon(this,e)}static get strings(){return{get promptLabel(){return sK.get()},set promptLabel(e){sK.set(e)},get tooMuchOutput(){return lK.get()},set tooMuchOutput(e){lK.set(e)}}}_verifyIntegers(...e){for(Q$ of e)if(Q$===1/0||isNaN(Q$)||Q$%1!=0)throw Error(`This API only accepts integers`)}_verifyPositiveIntegers(...e){for(Q$ of e)if(Q$&&(Q$===1/0||isNaN(Q$)||Q$%1!=0||Q$<0))throw Error(`This API only accepts positive integers`)}},e1=2,t1=1,n1=class{activate(e){this._terminal=e}dispose(){}fit(){let e=this.proposeDimensions();if(!e||!this._terminal||isNaN(e.cols)||isNaN(e.rows))return;let t=this._terminal._core;(this._terminal.rows!==e.rows||this._terminal.cols!==e.cols)&&(t._renderService.clear(),this._terminal.resize(e.cols,e.rows))}proposeDimensions(){if(!this._terminal||!this._terminal.element||!this._terminal.element.parentElement)return;let e=this._terminal._core._renderService.dimensions;if(e.css.cell.width===0||e.css.cell.height===0)return;let t=this._terminal.options.scrollback===0?0:this._terminal.options.overviewRuler?.width||14,n=window.getComputedStyle(this._terminal.element.parentElement),r=parseInt(n.getPropertyValue(`height`)),i=Math.max(0,parseInt(n.getPropertyValue(`width`))),a=window.getComputedStyle(this._terminal.element),o={top:parseInt(a.getPropertyValue(`padding-top`)),bottom:parseInt(a.getPropertyValue(`padding-bottom`)),right:parseInt(a.getPropertyValue(`padding-right`)),left:parseInt(a.getPropertyValue(`padding-left`))},s=o.top+o.bottom,c=o.right+o.left,l=r-s,u=i-c-t;return{cols:Math.max(e1,Math.floor(u/e.css.cell.width)),rows:Math.max(t1,Math.floor(l/e.css.cell.height))}}},r1=class{constructor(e,t,n,r={}){this._terminal=e,this._regex=t,this._handler=n,this._options=r}provideLinks(e,t){let n=a1.computeLink(e,this._regex,this._terminal,this._handler);t(this._addCallbacks(n))}_addCallbacks(e){return e.map(e=>(e.leave=this._options.leave,e.hover=(t,n)=>{if(this._options.hover){let{range:r}=e;this._options.hover(t,n,r)}},e))}};function i1(e){try{let t=new URL(e),n=t.password&&t.username?`${t.protocol}//${t.username}:${t.password}@${t.host}`:t.username?`${t.protocol}//${t.username}@${t.host}`:`${t.protocol}//${t.host}`;return e.toLocaleLowerCase().startsWith(n.toLocaleLowerCase())}catch{return!1}}var a1=class e{static computeLink(t,n,r,i){let a=new RegExp(n.source,(n.flags||``)+`g`),[o,s]=e._getWindowedLineStrings(t-1,r),c=o.join(``),l,u=[];for(;l=a.exec(c);){let t=l[0];if(!i1(t))continue;let[n,a]=e._mapStrIdx(r,s,0,l.index),[o,c]=e._mapStrIdx(r,n,a,t.length);if(n===-1||a===-1||o===-1||c===-1)continue;let d={start:{x:a+1,y:n+1},end:{x:c,y:o+1}};u.push({range:d,text:t,activate:i})}return u}static _getWindowedLineStrings(e,t){let n,r=e,i=e,a=0,o=``,s=[];if(n=t.buffer.active.getLine(e)){let e=n.translateToString(!0);if(n.isWrapped&&e[0]!==` `){for(a=0;(n=t.buffer.active.getLine(--r))&&a<2048&&(o=n.translateToString(!0),a+=o.length,s.push(o),n.isWrapped&&o.indexOf(` `)===-1););s.reverse()}for(s.push(e),a=0;(n=t.buffer.active.getLine(++i))&&n.isWrapped&&a<2048&&(o=n.translateToString(!0),a+=o.length,s.push(o),o.indexOf(` `)===-1););}return[s,r]}static _mapStrIdx(e,t,n,r){let i=e.buffer.active,a=i.getNullCell(),o=n;for(;r;){let e=i.getLine(t);if(!e)return[-1,-1];for(let n=o;n<e.length;++n){e.getCell(n,a);let o=a.getChars();if(a.getWidth()&&(r-=o.length||1,n===e.length-1&&o===``)){let e=i.getLine(t+1);e&&e.isWrapped&&(e.getCell(0,a),a.getWidth()===2&&(r+=1))}if(r<0)return[t,n]}t++,o=0}return[t,o]}},o1=/(https?|HTTPS?):[/]{2}[^\s"'!*(){}|\\\^<>`]*[^\s"':,.!?{}|\\\^~\[\]`()<>]/;function s1(e,t){let n=window.open();if(n){try{n.opener=null}catch{}n.location.href=t}else console.warn(`Opening link blocked as opener could not be cleared`)}var c1=class{constructor(e=s1,t={}){this._handler=e,this._options=t}activate(e){this._terminal=e;let t=this._options,n=t.urlRegex||o1;this._linkProvider=this._terminal.registerLinkProvider(new r1(this._terminal,n,this._handler,t))}dispose(){this._linkProvider?.dispose()}};function l1(e,t,n){return r=>{let i=r.key.toLowerCase();if(!r.ctrlKey&&!r.metaKey||r.altKey)return!0;if(i===`c`&&e.hasSelection()){if(r.type===`keydown`){r.preventDefault();let i=e.getSelection();Promise.resolve().then(()=>t(i)).catch(n)}return!1}return i!==`v`}}var u1={background:`#09090b`,foreground:`#f4f4f5`,cursor:`#38bdf8`,cursorAccent:`#09090b`,selectionBackground:`rgba(56, 189, 248, 0.3)`,black:`#27272a`,red:`#f87171`,green:`#4ade80`,yellow:`#facc15`,blue:`#60a5fa`,magenta:`#c084fc`,cyan:`#38bdf8`,white:`#f4f4f5`,brightBlack:`#52525b`,brightRed:`#ef4444`,brightGreen:`#22c55e`,brightYellow:`#eab308`,brightBlue:`#3b82f6`,brightMagenta:`#a855f7`,brightCyan:`#06b6d4`,brightWhite:`#ffffff`},d1={background:`#ffffff`,foreground:`#18181b`,cursor:`#0284c7`,cursorAccent:`#ffffff`,selectionBackground:`rgba(2, 132, 199, 0.2)`,black:`#18181b`,red:`#dc2626`,green:`#16a34a`,yellow:`#ca8a04`,blue:`#2563eb`,magenta:`#9333ea`,cyan:`#0891b2`,white:`#e4e4e7`,brightBlack:`#71717a`,brightRed:`#b91c1c`,brightGreen:`#15803d`,brightYellow:`#a16207`,brightBlue:`#1d4ed8`,brightMagenta:`#7e22ce`,brightCyan:`#0e7490`,brightWhite:`#27272a`};function f1(e){if(!e)return``;let t=e.split(/[\\/]/).filter(Boolean);return t.length<=3?e:`…/`+t.slice(-3).join(`/`)}function p1({id:e,shellId:t,cwd:n,isActive:r,isPanelOpen:i,renaming:a,openTerminal:o,sendTerminalInput:s,getTerminalCwd:c,resizeTerminal:l,closeTerminal:u,subscribeTerminal:d,onCwdUpdate:f,registerClear:p}){let m=(0,v.useRef)(null),h=(0,v.useRef)(null),g=(0,v.useRef)(null),_=(0,v.useContext)(b)===`dark`,y=(0,v.useRef)({cwd:n,openTerminal:o,sendTerminalInput:s,getTerminalCwd:c,resizeTerminal:l,closeTerminal:u,subscribeTerminal:d,onCwdUpdate:f,registerClear:p});return y.current={cwd:n,openTerminal:o,sendTerminalInput:s,getTerminalCwd:c,resizeTerminal:l,closeTerminal:u,subscribeTerminal:d,onCwdUpdate:f,registerClear:p},(0,v.useEffect)(()=>{h.current&&(h.current.options.theme=_?u1:d1)},[_]),(0,v.useEffect)(()=>{if(!m.current)return;let n=new $$({cursorBlink:!0,cursorStyle:`block`,fontSize:13,fontFamily:`'JetBrains Mono', 'Fira Code', ui-monospace, Menlo, Monaco, 'Courier New', monospace`,lineHeight:1.2,theme:_?u1:d1}),r=new n1;n.loadAddon(r),n.loadAddon(new c1),n.open(m.current),r.fit(),n.attachCustomKeyEventHandler(l1(n,e=>navigator.clipboard.writeText(e),()=>n.writeln(`\r
1530
+ `)}clearSelection(){this._model.clearSelection(),this._removeMouseDownListeners(),this.refresh(),this._onSelectionChange.fire()}refresh(e){this._refreshAnimationFrame||=this._coreBrowserService.window.requestAnimationFrame(()=>this._refresh()),mZ&&e&&this.selectionText.length&&this._onLinuxMouseSelection.fire(this.selectionText)}_refresh(){this._refreshAnimationFrame=void 0,this._onRedrawRequest.fire({start:this._model.finalSelectionStart,end:this._model.finalSelectionEnd,columnSelectMode:this._activeSelectionMode===3})}_isClickInSelection(e){let t=this._getMouseBufferCoords(e),n=this._model.finalSelectionStart,r=this._model.finalSelectionEnd;return!n||!r||!t?!1:this._areCoordsInSelection(t,n,r)}isCellInSelection(e,t){let n=this._model.finalSelectionStart,r=this._model.finalSelectionEnd;return!n||!r?!1:this._areCoordsInSelection([e,t],n,r)}_areCoordsInSelection(e,t,n){return e[1]>t[1]&&e[1]<n[1]||t[1]===n[1]&&e[1]===t[1]&&e[0]>=t[0]&&e[0]<n[0]||t[1]<n[1]&&e[1]===n[1]&&e[0]<n[0]||t[1]<n[1]&&e[1]===t[1]&&e[0]>=t[0]}_selectWordAtCursor(e,t){let n=this._linkifier.currentLink?.link?.range;if(n)return this._model.selectionStart=[n.start.x-1,n.start.y-1],this._model.selectionStartLength=LZ(n,this._bufferService.cols),this._model.selectionEnd=void 0,!0;let r=this._getMouseBufferCoords(e);return r?(this._selectWordAt(r,t),this._model.selectionEnd=void 0,!0):!1}selectAll(){this._model.isSelectAllActive=!0,this.refresh(),this._onSelectionChange.fire()}selectLines(e,t){this._model.clearSelection(),e=Math.max(e,0),t=Math.min(t,this._bufferService.buffer.lines.length-1),this._model.selectionStart=[0,e],this._model.selectionEnd=[this._bufferService.cols,t],this.refresh(),this._onSelectionChange.fire()}_handleTrim(e){this._model.handleTrim(e)&&this.refresh()}_getMouseBufferCoords(e){let t=this._mouseService.getCoords(e,this._screenElement,this._bufferService.cols,this._bufferService.rows,!0);if(t)return t[0]--,t[1]--,t[1]+=this._bufferService.buffer.ydisp,t}_getMouseEventScrollAmount(e){let t=QX(this._coreBrowserService.window,e,this._screenElement)[1],n=this._renderService.dimensions.css.canvas.height;return t>=0&&t<=n?0:(t>n&&(t-=n),t=Math.min(Math.max(t,-RZ),RZ),t/=RZ,t/Math.abs(t)+Math.round(t*(zZ-1)))}shouldForceSelection(e){return uZ?e.altKey&&this._optionsService.rawOptions.macOptionClickForcesSelection:e.shiftKey}handleMouseDown(e){if(this._mouseDownTimeStamp=e.timeStamp,!(e.button===2&&this.hasSelection)&&e.button===0){if(!this._enabled){if(!this.shouldForceSelection(e))return;e.stopPropagation()}e.preventDefault(),this._dragScrollAmount=0,this._enabled&&e.shiftKey?this._handleIncrementalClick(e):e.detail===1?this._handleSingleClick(e):e.detail===2?this._handleDoubleClick(e):e.detail===3&&this._handleTripleClick(e),this._addMouseDownListeners(),this.refresh(!0)}}_addMouseDownListeners(){this._screenElement.ownerDocument&&(this._screenElement.ownerDocument.addEventListener(`mousemove`,this._mouseMoveListener),this._screenElement.ownerDocument.addEventListener(`mouseup`,this._mouseUpListener)),this._dragScrollIntervalTimer=this._coreBrowserService.window.setInterval(()=>this._dragScroll(),BZ)}_removeMouseDownListeners(){this._screenElement.ownerDocument&&(this._screenElement.ownerDocument.removeEventListener(`mousemove`,this._mouseMoveListener),this._screenElement.ownerDocument.removeEventListener(`mouseup`,this._mouseUpListener)),this._coreBrowserService.window.clearInterval(this._dragScrollIntervalTimer),this._dragScrollIntervalTimer=void 0}_handleIncrementalClick(e){this._model.selectionStart&&(this._model.selectionEnd=this._getMouseBufferCoords(e))}_handleSingleClick(e){if(this._model.selectionStartLength=0,this._model.isSelectAllActive=!1,this._activeSelectionMode=this.shouldColumnSelect(e)?3:0,this._model.selectionStart=this._getMouseBufferCoords(e),!this._model.selectionStart)return;this._model.selectionEnd=void 0;let t=this._bufferService.buffer.lines.get(this._model.selectionStart[1]);t&&t.length!==this._model.selectionStart[0]&&t.hasWidth(this._model.selectionStart[0])===0&&this._model.selectionStart[0]++}_handleDoubleClick(e){this._selectWordAtCursor(e,!0)&&(this._activeSelectionMode=1)}_handleTripleClick(e){let t=this._getMouseBufferCoords(e);t&&(this._activeSelectionMode=2,this._selectLineAt(t[1]))}shouldColumnSelect(e){return e.altKey&&!(uZ&&this._optionsService.rawOptions.macOptionClickForcesSelection)}_handleMouseMove(e){if(e.stopImmediatePropagation(),!this._model.selectionStart)return;let t=this._model.selectionEnd?[this._model.selectionEnd[0],this._model.selectionEnd[1]]:null;if(this._model.selectionEnd=this._getMouseBufferCoords(e),!this._model.selectionEnd){this.refresh(!0);return}this._activeSelectionMode===2?this._model.selectionEnd[1]<this._model.selectionStart[1]?this._model.selectionEnd[0]=0:this._model.selectionEnd[0]=this._bufferService.cols:this._activeSelectionMode===1&&this._selectToWordAt(this._model.selectionEnd),this._dragScrollAmount=this._getMouseEventScrollAmount(e),this._activeSelectionMode!==3&&(this._dragScrollAmount>0?this._model.selectionEnd[0]=this._bufferService.cols:this._dragScrollAmount<0&&(this._model.selectionEnd[0]=0));let n=this._bufferService.buffer;if(this._model.selectionEnd[1]<n.lines.length){let e=n.lines.get(this._model.selectionEnd[1]);e&&e.hasWidth(this._model.selectionEnd[0])===0&&this._model.selectionEnd[0]<this._bufferService.cols&&this._model.selectionEnd[0]++}(!t||t[0]!==this._model.selectionEnd[0]||t[1]!==this._model.selectionEnd[1])&&this.refresh(!0)}_dragScroll(){if(this._model.selectionEnd&&this._model.selectionStart&&this._dragScrollAmount){this._onRequestScrollLines.fire({amount:this._dragScrollAmount,suppressScrollEvent:!1});let e=this._bufferService.buffer;this._dragScrollAmount>0?(this._activeSelectionMode!==3&&(this._model.selectionEnd[0]=this._bufferService.cols),this._model.selectionEnd[1]=Math.min(e.ydisp+this._bufferService.rows,e.lines.length-1)):(this._activeSelectionMode!==3&&(this._model.selectionEnd[0]=0),this._model.selectionEnd[1]=e.ydisp),this.refresh()}}_handleMouseUp(e){let t=e.timeStamp-this._mouseDownTimeStamp;if(this._removeMouseDownListeners(),this.selectionText.length<=1&&t<VZ&&e.altKey&&this._optionsService.rawOptions.altClickMovesCursor){if(this._bufferService.buffer.ybase===this._bufferService.buffer.ydisp){let t=this._mouseService.getCoords(e,this._element,this._bufferService.cols,this._bufferService.rows,!1);if(t&&t[0]!==void 0&&t[1]!==void 0){let e=CZ(t[0]-1,t[1]-1,this._bufferService,this._coreService.decPrivateModes.applicationCursorKeys);this._coreService.triggerDataEvent(e,!0)}}}else this._fireEventIfSelectionChanged()}_fireEventIfSelectionChanged(){let e=this._model.finalSelectionStart,t=this._model.finalSelectionEnd,n=!!e&&!!t&&(e[0]!==t[0]||e[1]!==t[1]);n?!e||!t||(!this._oldSelectionStart||!this._oldSelectionEnd||e[0]!==this._oldSelectionStart[0]||e[1]!==this._oldSelectionStart[1]||t[0]!==this._oldSelectionEnd[0]||t[1]!==this._oldSelectionEnd[1])&&this._fireOnSelectionChange(e,t,n):this._oldHasSelection&&this._fireOnSelectionChange(e,t,n)}_fireOnSelectionChange(e,t,n){this._oldSelectionStart=e,this._oldSelectionEnd=t,this._oldHasSelection=n,this._onSelectionChange.fire()}_handleBufferActivate(e){this.clearSelection(),this._trimListener.dispose(),this._trimListener=e.activeBuffer.lines.onTrim(e=>this._handleTrim(e))}_convertViewportColToCharacterIndex(e,t){let n=t;for(let r=0;t>=r;r++){let i=e.loadCell(r,this._workCell).getChars().length;this._workCell.getWidth()===0?n--:i>1&&t!==r&&(n+=i-1)}return n}setSelection(e,t,n){this._model.clearSelection(),this._removeMouseDownListeners(),this._model.selectionStart=[e,t],this._model.selectionStartLength=n,this.refresh(),this._fireEventIfSelectionChanged()}rightClickSelect(e){this._isClickInSelection(e)||(this._selectWordAtCursor(e,!1)&&this.refresh(!0),this._fireEventIfSelectionChanged())}_getWordAt(e,t,n=!0,r=!0){if(e[0]>=this._bufferService.cols)return;let i=this._bufferService.buffer,a=i.lines.get(e[1]);if(!a)return;let o=i.translateBufferLineToString(e[1],!1),s=this._convertViewportColToCharacterIndex(a,e[0]),c=s,l=e[0]-s,u=0,d=0,f=0,p=0;if(o.charAt(s)===` `){for(;s>0&&o.charAt(s-1)===` `;)s--;for(;c<o.length&&o.charAt(c+1)===` `;)c++}else{let t=e[0],n=e[0];a.getWidth(t)===0&&(u++,t--),a.getWidth(n)===2&&(d++,n++);let r=a.getString(n).length;for(r>1&&(p+=r-1,c+=r-1);t>0&&s>0&&!this._isCharWordSeparator(a.loadCell(t-1,this._workCell));){a.loadCell(t-1,this._workCell);let e=this._workCell.getChars().length;this._workCell.getWidth()===0?(u++,t--):e>1&&(f+=e-1,s-=e-1),s--,t--}for(;n<a.length&&c+1<o.length&&!this._isCharWordSeparator(a.loadCell(n+1,this._workCell));){a.loadCell(n+1,this._workCell);let e=this._workCell.getChars().length;this._workCell.getWidth()===2?(d++,n++):e>1&&(p+=e-1,c+=e-1),c++,n++}}c++;let m=s+l-u+f,h=Math.min(this._bufferService.cols,c-s+u+d-f-p);if(t||o.slice(s,c).trim()!==``){if(n&&m===0&&a.getCodePoint(0)!==32){let t=i.lines.get(e[1]-1);if(t&&a.isWrapped&&t.getCodePoint(this._bufferService.cols-1)!==32){let t=this._getWordAt([this._bufferService.cols-1,e[1]-1],!1,!0,!1);if(t){let e=this._bufferService.cols-t.start;m-=e,h+=e}}}if(r&&m+h===this._bufferService.cols&&a.getCodePoint(this._bufferService.cols-1)!==32){let t=i.lines.get(e[1]+1);if(t?.isWrapped&&t.getCodePoint(0)!==32){let t=this._getWordAt([0,e[1]+1],!1,!1,!0);t&&(h+=t.length)}}return{start:m,length:h}}}_selectWordAt(e,t){let n=this._getWordAt(e,t);if(n){for(;n.start<0;)n.start+=this._bufferService.cols,e[1]--;this._model.selectionStart=[n.start,e[1]],this._model.selectionStartLength=n.length}}_selectToWordAt(e){let t=this._getWordAt(e,!0);if(t){let n=e[1];for(;t.start<0;)t.start+=this._bufferService.cols,n--;if(!this._model.areSelectionValuesReversed())for(;t.start+t.length>this._bufferService.cols;)t.length-=this._bufferService.cols,n++;this._model.selectionEnd=[this._model.areSelectionValuesReversed()?t.start:t.start+t.length,n]}}_isCharWordSeparator(e){return e.getWidth()!==0&&this._optionsService.rawOptions.wordSeparator.indexOf(e.getChars())>=0}_selectLineAt(e){let t=this._bufferService.buffer.getWrappedRangeForLine(e),n={start:{x:0,y:t.first},end:{x:this._bufferService.cols-1,y:t.last}};this._model.selectionStart=[0,t.first],this._model.selectionEnd=void 0,this._model.selectionStartLength=LZ(n,this._bufferService.cols)}};UZ=aK([oK(3,NK),oK(4,FK),oK(5,qK),oK(6,zK),oK(7,JK),oK(8,KK)],UZ);var WZ=class{constructor(){this._data={}}set(e,t,n){this._data[e]||(this._data[e]={}),this._data[e][t]=n}get(e,t){return this._data[e]?this._data[e][t]:void 0}clear(){this._data={}}},GZ=class{constructor(){this._color=new WZ,this._css=new WZ}setCss(e,t,n){this._css.set(e,t,n)}getCss(e,t){return this._css.get(e,t)}setColor(e,t,n){this._color.set(e,t,n)}getColor(e,t){return this._color.get(e,t)}clear(){this._color.clear(),this._css.clear()}},KZ=Object.freeze((()=>{let e=[bX.toColor(`#2e3436`),bX.toColor(`#cc0000`),bX.toColor(`#4e9a06`),bX.toColor(`#c4a000`),bX.toColor(`#3465a4`),bX.toColor(`#75507b`),bX.toColor(`#06989a`),bX.toColor(`#d3d7cf`),bX.toColor(`#555753`),bX.toColor(`#ef2929`),bX.toColor(`#8ae234`),bX.toColor(`#fce94f`),bX.toColor(`#729fcf`),bX.toColor(`#ad7fa8`),bX.toColor(`#34e2e2`),bX.toColor(`#eeeeec`)],t=[0,95,135,175,215,255];for(let n=0;n<216;n++){let r=t[n/36%6|0],i=t[n/6%6|0],a=t[n%6];e.push({css:vX.toCss(r,i,a),rgba:vX.toRgba(r,i,a)})}for(let t=0;t<24;t++){let n=8+t*10;e.push({css:vX.toCss(n,n,n),rgba:vX.toRgba(n,n,n)})}return e})()),qZ=bX.toColor(`#ffffff`),JZ=bX.toColor(`#000000`),YZ=bX.toColor(`#ffffff`),XZ=JZ,ZZ={css:`rgba(255, 255, 255, 0.3)`,rgba:4294967117},QZ=qZ,$Z=class extends Sq{constructor(e){super(),this._optionsService=e,this._contrastCache=new GZ,this._halfContrastCache=new GZ,this._onChangeColors=this._register(new Hq),this.onChangeColors=this._onChangeColors.event,this._colors={foreground:qZ,background:JZ,cursor:YZ,cursorAccent:XZ,selectionForeground:void 0,selectionBackgroundTransparent:ZZ,selectionBackgroundOpaque:yX.blend(JZ,ZZ),selectionInactiveBackgroundTransparent:ZZ,selectionInactiveBackgroundOpaque:yX.blend(JZ,ZZ),scrollbarSliderBackground:yX.opacity(qZ,.2),scrollbarSliderHoverBackground:yX.opacity(qZ,.4),scrollbarSliderActiveBackground:yX.opacity(qZ,.5),overviewRulerBorder:qZ,ansi:KZ.slice(),contrastCache:this._contrastCache,halfContrastCache:this._halfContrastCache},this._updateRestoreColors(),this._setTheme(this._optionsService.rawOptions.theme),this._register(this._optionsService.onSpecificOptionChange(`minimumContrastRatio`,()=>this._contrastCache.clear())),this._register(this._optionsService.onSpecificOptionChange(`theme`,()=>this._setTheme(this._optionsService.rawOptions.theme)))}get colors(){return this._colors}_setTheme(e={}){let t=this._colors;if(t.foreground=eQ(e.foreground,qZ),t.background=eQ(e.background,JZ),t.cursor=yX.blend(t.background,eQ(e.cursor,YZ)),t.cursorAccent=yX.blend(t.background,eQ(e.cursorAccent,XZ)),t.selectionBackgroundTransparent=eQ(e.selectionBackground,ZZ),t.selectionBackgroundOpaque=yX.blend(t.background,t.selectionBackgroundTransparent),t.selectionInactiveBackgroundTransparent=eQ(e.selectionInactiveBackground,t.selectionBackgroundTransparent),t.selectionInactiveBackgroundOpaque=yX.blend(t.background,t.selectionInactiveBackgroundTransparent),t.selectionForeground=e.selectionForeground?eQ(e.selectionForeground,_X):void 0,t.selectionForeground===_X&&(t.selectionForeground=void 0),yX.isOpaque(t.selectionBackgroundTransparent)&&(t.selectionBackgroundTransparent=yX.opacity(t.selectionBackgroundTransparent,.3)),yX.isOpaque(t.selectionInactiveBackgroundTransparent)&&(t.selectionInactiveBackgroundTransparent=yX.opacity(t.selectionInactiveBackgroundTransparent,.3)),t.scrollbarSliderBackground=eQ(e.scrollbarSliderBackground,yX.opacity(t.foreground,.2)),t.scrollbarSliderHoverBackground=eQ(e.scrollbarSliderHoverBackground,yX.opacity(t.foreground,.4)),t.scrollbarSliderActiveBackground=eQ(e.scrollbarSliderActiveBackground,yX.opacity(t.foreground,.5)),t.overviewRulerBorder=eQ(e.overviewRulerBorder,QZ),t.ansi=KZ.slice(),t.ansi[0]=eQ(e.black,KZ[0]),t.ansi[1]=eQ(e.red,KZ[1]),t.ansi[2]=eQ(e.green,KZ[2]),t.ansi[3]=eQ(e.yellow,KZ[3]),t.ansi[4]=eQ(e.blue,KZ[4]),t.ansi[5]=eQ(e.magenta,KZ[5]),t.ansi[6]=eQ(e.cyan,KZ[6]),t.ansi[7]=eQ(e.white,KZ[7]),t.ansi[8]=eQ(e.brightBlack,KZ[8]),t.ansi[9]=eQ(e.brightRed,KZ[9]),t.ansi[10]=eQ(e.brightGreen,KZ[10]),t.ansi[11]=eQ(e.brightYellow,KZ[11]),t.ansi[12]=eQ(e.brightBlue,KZ[12]),t.ansi[13]=eQ(e.brightMagenta,KZ[13]),t.ansi[14]=eQ(e.brightCyan,KZ[14]),t.ansi[15]=eQ(e.brightWhite,KZ[15]),e.extendedAnsi){let n=Math.min(t.ansi.length-16,e.extendedAnsi.length);for(let r=0;r<n;r++)t.ansi[r+16]=eQ(e.extendedAnsi[r],KZ[r+16])}this._contrastCache.clear(),this._halfContrastCache.clear(),this._updateRestoreColors(),this._onChangeColors.fire(this.colors)}restoreColor(e){this._restoreColor(e),this._onChangeColors.fire(this.colors)}_restoreColor(e){if(e===void 0)for(let e=0;e<this._restoreColors.ansi.length;++e)this._colors.ansi[e]=this._restoreColors.ansi[e];else switch(e){case 256:this._colors.foreground=this._restoreColors.foreground;break;case 257:this._colors.background=this._restoreColors.background;break;case 258:this._colors.cursor=this._restoreColors.cursor;break;default:this._colors.ansi[e]=this._restoreColors.ansi[e]}}modifyColors(e){e(this._colors),this._onChangeColors.fire(this.colors)}_updateRestoreColors(){this._restoreColors={foreground:this._colors.foreground,background:this._colors.background,cursor:this._colors.cursor,ansi:this._colors.ansi.slice()}}};$Z=aK([oK(0,zK)],$Z);function eQ(e,t){if(e!==void 0)try{return bX.toColor(e)}catch{}return t}var tQ=class{constructor(...e){this._entries=new Map;for(let[t,n]of e)this.set(t,n)}set(e,t){let n=this._entries.get(e);return this._entries.set(e,t),n}forEach(e){for(let[t,n]of this._entries.entries())e(t,n)}has(e){return this._entries.has(e)}get(e){return this._entries.get(e)}},nQ=class{constructor(){this._services=new tQ,this._services.set(LK,this)}setService(e,t){this._services.set(e,t)}getService(e){return this._services.get(e)}createInstance(e,...t){let n=AK(e).sort((e,t)=>e.index-t.index),r=[];for(let t of n){let n=this._services.get(t.id);if(!n)throw Error(`[createInstance] ${e.name} depends on UNKNOWN service ${t.id._id}.`);r.push(n)}let i=n.length>0?n[0].index:t.length;if(t.length!==i)throw Error(`[createInstance] First service dependency of ${e.name} at position ${i+1} conflicts with ${t.length} static arguments`);return new e(...t,...r)}},rQ={trace:0,debug:1,info:2,warn:3,error:4,off:5},iQ=`xterm.js: `,aQ=class extends Sq{constructor(e){super(),this._optionsService=e,this._logLevel=5,this._updateLogLevel(),this._register(this._optionsService.onSpecificOptionChange(`logLevel`,()=>this._updateLogLevel())),oQ=this}get logLevel(){return this._logLevel}_updateLogLevel(){this._logLevel=rQ[this._optionsService.rawOptions.logLevel]}_evalLazyOptionalParams(e){for(let t=0;t<e.length;t++)typeof e[t]==`function`&&(e[t]=e[t]())}_log(e,t,n){this._evalLazyOptionalParams(n),e.call(console,(this._optionsService.options.logger?``:iQ)+t,...n)}trace(e,...t){this._logLevel<=0&&this._log(this._optionsService.options.logger?.trace.bind(this._optionsService.options.logger)??console.log,e,t)}debug(e,...t){this._logLevel<=1&&this._log(this._optionsService.options.logger?.debug.bind(this._optionsService.options.logger)??console.log,e,t)}info(e,...t){this._logLevel<=2&&this._log(this._optionsService.options.logger?.info.bind(this._optionsService.options.logger)??console.info,e,t)}warn(e,...t){this._logLevel<=3&&this._log(this._optionsService.options.logger?.warn.bind(this._optionsService.options.logger)??console.warn,e,t)}error(e,...t){this._logLevel<=4&&this._log(this._optionsService.options.logger?.error.bind(this._optionsService.options.logger)??console.error,e,t)}};aQ=aK([oK(0,zK)],aQ);var oQ,sQ=class extends Sq{constructor(e){super(),this._maxLength=e,this.onDeleteEmitter=this._register(new Hq),this.onDelete=this.onDeleteEmitter.event,this.onInsertEmitter=this._register(new Hq),this.onInsert=this.onInsertEmitter.event,this.onTrimEmitter=this._register(new Hq),this.onTrim=this.onTrimEmitter.event,this._array=Array(this._maxLength),this._startIndex=0,this._length=0}get maxLength(){return this._maxLength}set maxLength(e){if(this._maxLength===e)return;let t=Array(e);for(let n=0;n<Math.min(e,this.length);n++)t[n]=this._array[this._getCyclicIndex(n)];this._array=t,this._maxLength=e,this._startIndex=0}get length(){return this._length}set length(e){if(e>this._length)for(let t=this._length;t<e;t++)this._array[t]=void 0;this._length=e}get(e){return this._array[this._getCyclicIndex(e)]}set(e,t){this._array[this._getCyclicIndex(e)]=t}push(e){this._array[this._getCyclicIndex(this._length)]=e,this._length===this._maxLength?(this._startIndex=++this._startIndex%this._maxLength,this.onTrimEmitter.fire(1)):this._length++}recycle(){if(this._length!==this._maxLength)throw Error(`Can only recycle when the buffer is full`);return this._startIndex=++this._startIndex%this._maxLength,this.onTrimEmitter.fire(1),this._array[this._getCyclicIndex(this._length-1)]}get isFull(){return this._length===this._maxLength}pop(){return this._array[this._getCyclicIndex(this._length---1)]}splice(e,t,...n){if(t){for(let n=e;n<this._length-t;n++)this._array[this._getCyclicIndex(n)]=this._array[this._getCyclicIndex(n+t)];this._length-=t,this.onDeleteEmitter.fire({index:e,amount:t})}for(let t=this._length-1;t>=e;t--)this._array[this._getCyclicIndex(t+n.length)]=this._array[this._getCyclicIndex(t)];for(let t=0;t<n.length;t++)this._array[this._getCyclicIndex(e+t)]=n[t];if(n.length&&this.onInsertEmitter.fire({index:e,amount:n.length}),this._length+n.length>this._maxLength){let e=this._length+n.length-this._maxLength;this._startIndex+=e,this._length=this._maxLength,this.onTrimEmitter.fire(e)}else this._length+=n.length}trimStart(e){e>this._length&&(e=this._length),this._startIndex+=e,this._length-=e,this.onTrimEmitter.fire(e)}shiftElements(e,t,n){if(!(t<=0)){if(e<0||e>=this._length)throw Error(`start argument out of range`);if(e+n<0)throw Error(`Cannot shift elements in list beyond index 0`);if(n>0){for(let r=t-1;r>=0;r--)this.set(e+r+n,this.get(e+r));let r=e+t+n-this._length;if(r>0)for(this._length+=r;this._length>this._maxLength;)this._length--,this._startIndex++,this.onTrimEmitter.fire(1)}else for(let r=0;r<t;r++)this.set(e+r+n,this.get(e+r))}}_getCyclicIndex(e){return(this._startIndex+e)%this._maxLength}},cQ=3,lQ=Object.freeze(new wK),uQ=0,dQ=2,fQ=class e{constructor(e,t,n=!1){this.isWrapped=n,this._combined={},this._extendedAttrs={},this._data=new Uint32Array(e*cQ);let r=t||EK.fromCharData([0,SK,1,0]);for(let t=0;t<e;++t)this.setCell(t,r);this.length=e}get(e){let t=this._data[e*cQ+0],n=t&2097151;return[this._data[e*cQ+1],t&2097152?this._combined[e]:n?vK(n):``,t>>22,t&2097152?this._combined[e].charCodeAt(this._combined[e].length-1):n]}set(e,t){this._data[e*cQ+1]=t[0],t[1].length>1?(this._combined[e]=t[1],this._data[e*cQ+0]=e|2097152|t[2]<<22):this._data[e*cQ+0]=t[1].charCodeAt(0)|t[2]<<22}getWidth(e){return this._data[e*cQ+0]>>22}hasWidth(e){return this._data[e*cQ+0]&12582912}getFg(e){return this._data[e*cQ+1]}getBg(e){return this._data[e*cQ+2]}hasContent(e){return this._data[e*cQ+0]&4194303}getCodePoint(e){let t=this._data[e*cQ+0];return t&2097152?this._combined[e].charCodeAt(this._combined[e].length-1):t&2097151}isCombined(e){return this._data[e*cQ+0]&2097152}getString(e){let t=this._data[e*cQ+0];return t&2097152?this._combined[e]:t&2097151?vK(t&2097151):``}isProtected(e){return this._data[e*cQ+2]&536870912}loadCell(e,t){return uQ=e*cQ,t.content=this._data[uQ+0],t.fg=this._data[uQ+1],t.bg=this._data[uQ+2],t.content&2097152&&(t.combinedData=this._combined[e]),t.bg&268435456&&(t.extended=this._extendedAttrs[e]),t}setCell(e,t){t.content&2097152&&(this._combined[e]=t.combinedData),t.bg&268435456&&(this._extendedAttrs[e]=t.extended),this._data[e*cQ+0]=t.content,this._data[e*cQ+1]=t.fg,this._data[e*cQ+2]=t.bg}setCellFromCodepoint(e,t,n,r){r.bg&268435456&&(this._extendedAttrs[e]=r.extended),this._data[e*cQ+0]=t|n<<22,this._data[e*cQ+1]=r.fg,this._data[e*cQ+2]=r.bg}addCodepointToCell(e,t,n){let r=this._data[e*cQ+0];r&2097152?this._combined[e]+=vK(t):r&2097151?(this._combined[e]=vK(r&2097151)+vK(t),r&=-2097152,r|=2097152):r=t|1<<22,n&&(r&=-12582913,r|=n<<22),this._data[e*cQ+0]=r}insertCells(e,t,n){if(e%=this.length,e&&this.getWidth(e-1)===2&&this.setCellFromCodepoint(e-1,0,1,n),t<this.length-e){let r=new EK;for(let n=this.length-e-t-1;n>=0;--n)this.setCell(e+t+n,this.loadCell(e+n,r));for(let r=0;r<t;++r)this.setCell(e+r,n)}else for(let t=e;t<this.length;++t)this.setCell(t,n);this.getWidth(this.length-1)===2&&this.setCellFromCodepoint(this.length-1,0,1,n)}deleteCells(e,t,n){if(e%=this.length,t<this.length-e){let r=new EK;for(let n=0;n<this.length-e-t;++n)this.setCell(e+n,this.loadCell(e+t+n,r));for(let e=this.length-t;e<this.length;++e)this.setCell(e,n)}else for(let t=e;t<this.length;++t)this.setCell(t,n);e&&this.getWidth(e-1)===2&&this.setCellFromCodepoint(e-1,0,1,n),this.getWidth(e)===0&&!this.hasContent(e)&&this.setCellFromCodepoint(e,0,1,n)}replaceCells(e,t,n,r=!1){if(r)for(e&&this.getWidth(e-1)===2&&!this.isProtected(e-1)&&this.setCellFromCodepoint(e-1,0,1,n),t<this.length&&this.getWidth(t-1)===2&&!this.isProtected(t)&&this.setCellFromCodepoint(t,0,1,n);e<t&&e<this.length;)this.isProtected(e)||this.setCell(e,n),e++;else for(e&&this.getWidth(e-1)===2&&this.setCellFromCodepoint(e-1,0,1,n),t<this.length&&this.getWidth(t-1)===2&&this.setCellFromCodepoint(t,0,1,n);e<t&&e<this.length;)this.setCell(e++,n)}resize(e,t){if(e===this.length)return this._data.length*4*dQ<this._data.buffer.byteLength;let n=e*cQ;if(e>this.length){if(this._data.buffer.byteLength>=n*4)this._data=new Uint32Array(this._data.buffer,0,n);else{let e=new Uint32Array(n);e.set(this._data),this._data=e}for(let n=this.length;n<e;++n)this.setCell(n,t)}else{this._data=this._data.subarray(0,n);let t=Object.keys(this._combined);for(let n=0;n<t.length;n++){let r=parseInt(t[n],10);r>=e&&delete this._combined[r]}let r=Object.keys(this._extendedAttrs);for(let t=0;t<r.length;t++){let n=parseInt(r[t],10);n>=e&&delete this._extendedAttrs[n]}}return this.length=e,n*4*dQ<this._data.buffer.byteLength}cleanupMemory(){if(this._data.length*4*dQ<this._data.buffer.byteLength){let e=new Uint32Array(this._data.length);return e.set(this._data),this._data=e,1}return 0}fill(e,t=!1){if(t)for(let t=0;t<this.length;++t)this.isProtected(t)||this.setCell(t,e);else{this._combined={},this._extendedAttrs={};for(let t=0;t<this.length;++t)this.setCell(t,e)}}copyFrom(e){this.length===e.length?this._data.set(e._data):this._data=new Uint32Array(e._data),this.length=e.length,this._combined={};for(let t in e._combined)this._combined[t]=e._combined[t];this._extendedAttrs={};for(let t in e._extendedAttrs)this._extendedAttrs[t]=e._extendedAttrs[t];this.isWrapped=e.isWrapped}clone(){let t=new e(0);t._data=new Uint32Array(this._data),t.length=this.length;for(let e in this._combined)t._combined[e]=this._combined[e];for(let e in this._extendedAttrs)t._extendedAttrs[e]=this._extendedAttrs[e];return t.isWrapped=this.isWrapped,t}getTrimmedLength(){for(let e=this.length-1;e>=0;--e)if(this._data[e*cQ+0]&4194303)return e+(this._data[e*cQ+0]>>22);return 0}getNoBgTrimmedLength(){for(let e=this.length-1;e>=0;--e)if(this._data[e*cQ+0]&4194303||this._data[e*cQ+2]&50331648)return e+(this._data[e*cQ+0]>>22);return 0}copyCellsFrom(e,t,n,r,i){let a=e._data;if(i)for(let i=r-1;i>=0;i--){for(let e=0;e<cQ;e++)this._data[(n+i)*cQ+e]=a[(t+i)*cQ+e];a[(t+i)*cQ+2]&268435456&&(this._extendedAttrs[n+i]=e._extendedAttrs[t+i])}else for(let i=0;i<r;i++){for(let e=0;e<cQ;e++)this._data[(n+i)*cQ+e]=a[(t+i)*cQ+e];a[(t+i)*cQ+2]&268435456&&(this._extendedAttrs[n+i]=e._extendedAttrs[t+i])}let o=Object.keys(e._combined);for(let r=0;r<o.length;r++){let i=parseInt(o[r],10);i>=t&&(this._combined[i-t+n]=e._combined[i])}}translateToString(e,t,n,r){t??=0,n??=this.length,e&&(n=Math.min(n,this.getTrimmedLength())),r&&(r.length=0);let i=``;for(;t<n;){let e=this._data[t*cQ+0],n=e&2097151,a=e&2097152?this._combined[t]:n?vK(n):CK;if(i+=a,r)for(let e=0;e<a.length;++e)r.push(t);t+=e>>22||1}return r&&r.push(t),i}};function pQ(e,t,n,r,i,a){let o=[];for(let s=0;s<e.length-1;s++){let c=s,l=e.get(++c);if(!l.isWrapped)continue;let u=[e.get(s)];for(;c<e.length&&l.isWrapped;)u.push(l),l=e.get(++c);if(!a&&r>=s&&r<c){s+=u.length-1;continue}let d=0,f=_Q(u,d,t),p=1,m=0;for(;p<u.length;){let e=_Q(u,p,t),r=e-m,a=n-f,o=Math.min(r,a);u[d].copyCellsFrom(u[p],m,f,o,!1),f+=o,f===n&&(d++,f=0),m+=o,m===e&&(p++,m=0),f===0&&d!==0&&u[d-1].getWidth(n-1)===2&&(u[d].copyCellsFrom(u[d-1],n-1,f++,1,!1),u[d-1].setCell(n-1,i))}u[d].replaceCells(f,n,i);let h=0;for(let e=u.length-1;e>0&&(e>d||u[e].getTrimmedLength()===0);e--)h++;h>0&&(o.push(s+u.length-h),o.push(h)),s+=u.length-1}return o}function mQ(e,t){let n=[],r=0,i=t[r],a=0;for(let o=0;o<e.length;o++)if(i===o){let n=t[++r];e.onDeleteEmitter.fire({index:o-a,amount:n}),o+=n-1,a+=n,i=t[++r]}else n.push(o);return{layout:n,countRemoved:a}}function hQ(e,t){let n=[];for(let r=0;r<t.length;r++)n.push(e.get(t[r]));for(let t=0;t<n.length;t++)e.set(t,n[t]);e.length=t.length}function gQ(e,t,n){let r=[],i=e.map((n,r)=>_Q(e,r,t)).reduce((e,t)=>e+t),a=0,o=0,s=0;for(;s<i;){if(i-s<n){r.push(i-s);break}a+=n;let c=_Q(e,o,t);a>c&&(a-=c,o++);let l=e[o].getWidth(a-1)===2;l&&a--;let u=l?n-1:n;r.push(u),s+=u}return r}function _Q(e,t,n){if(t===e.length-1)return e[t].getTrimmedLength();let r=!e[t].hasContent(n-1)&&e[t].getWidth(n-1)===1,i=e[t+1].getWidth(0)===2;return r&&i?n-1:n}var vQ=class e{constructor(t){this.line=t,this.isDisposed=!1,this._disposables=[],this._id=e._nextId++,this._onDispose=this.register(new Hq),this.onDispose=this._onDispose.event}get id(){return this._id}dispose(){this.isDisposed||(this.isDisposed=!0,this.line=-1,this._onDispose.fire(),_q(this._disposables),this._disposables.length=0)}register(e){return this._disposables.push(e),e}};vQ._nextId=1;var yQ=vQ,bQ={},xQ=bQ.B;bQ[0]={"`":`◆`,a:`▒`,b:`␉`,c:`␌`,d:`␍`,e:`␊`,f:`°`,g:`±`,h:`␤`,i:`␋`,j:`┘`,k:`┐`,l:`┌`,m:`└`,n:`┼`,o:`⎺`,p:`⎻`,q:`─`,r:`⎼`,s:`⎽`,t:`├`,u:`┤`,v:`┴`,w:`┬`,x:`│`,y:`≤`,z:`≥`,"{":`π`,"|":`≠`,"}":`£`,"~":`·`},bQ.A={"#":`£`},bQ.B=void 0,bQ[4]={"#":`£`,"@":`¾`,"[":`ij`,"\\":`½`,"]":`|`,"{":`¨`,"|":`f`,"}":`¼`,"~":`´`},bQ.C=bQ[5]={"[":`Ä`,"\\":`Ö`,"]":`Å`,"^":`Ü`,"`":`é`,"{":`ä`,"|":`ö`,"}":`å`,"~":`ü`},bQ.R={"#":`£`,"@":`à`,"[":`°`,"\\":`ç`,"]":`§`,"{":`é`,"|":`ù`,"}":`è`,"~":`¨`},bQ.Q={"@":`à`,"[":`â`,"\\":`ç`,"]":`ê`,"^":`î`,"`":`ô`,"{":`é`,"|":`ù`,"}":`è`,"~":`û`},bQ.K={"@":`§`,"[":`Ä`,"\\":`Ö`,"]":`Ü`,"{":`ä`,"|":`ö`,"}":`ü`,"~":`ß`},bQ.Y={"#":`£`,"@":`§`,"[":`°`,"\\":`ç`,"]":`é`,"`":`ù`,"{":`à`,"|":`ò`,"}":`è`,"~":`ì`},bQ.E=bQ[6]={"@":`Ä`,"[":`Æ`,"\\":`Ø`,"]":`Å`,"^":`Ü`,"`":`ä`,"{":`æ`,"|":`ø`,"}":`å`,"~":`ü`},bQ.Z={"#":`£`,"@":`§`,"[":`¡`,"\\":`Ñ`,"]":`¿`,"{":`°`,"|":`ñ`,"}":`ç`},bQ.H=bQ[7]={"@":`É`,"[":`Ä`,"\\":`Ö`,"]":`Å`,"^":`Ü`,"`":`é`,"{":`ä`,"|":`ö`,"}":`å`,"~":`ü`},bQ[`=`]={"#":`ù`,"@":`à`,"[":`é`,"\\":`ç`,"]":`ê`,"^":`î`,_:`è`,"`":`ô`,"{":`ä`,"|":`ö`,"}":`ü`,"~":`û`};var SQ=4294967295,CQ=class{constructor(e,t,n){this._hasScrollback=e,this._optionsService=t,this._bufferService=n,this.ydisp=0,this.ybase=0,this.y=0,this.x=0,this.tabs={},this.savedY=0,this.savedX=0,this.savedCurAttrData=lQ.clone(),this.savedCharset=xQ,this.markers=[],this._nullCell=EK.fromCharData([0,SK,1,0]),this._whitespaceCell=EK.fromCharData([0,CK,1,32]),this._isClearing=!1,this._memoryCleanupQueue=new yZ,this._memoryCleanupPosition=0,this._cols=this._bufferService.cols,this._rows=this._bufferService.rows,this.lines=new sQ(this._getCorrectBufferLength(this._rows)),this.scrollTop=0,this.scrollBottom=this._rows-1,this.setupTabStops()}getNullCell(e){return e?(this._nullCell.fg=e.fg,this._nullCell.bg=e.bg,this._nullCell.extended=e.extended):(this._nullCell.fg=0,this._nullCell.bg=0,this._nullCell.extended=new TK),this._nullCell}getWhitespaceCell(e){return e?(this._whitespaceCell.fg=e.fg,this._whitespaceCell.bg=e.bg,this._whitespaceCell.extended=e.extended):(this._whitespaceCell.fg=0,this._whitespaceCell.bg=0,this._whitespaceCell.extended=new TK),this._whitespaceCell}getBlankLine(e,t){return new fQ(this._bufferService.cols,this.getNullCell(e),t)}get hasScrollback(){return this._hasScrollback&&this.lines.maxLength>this._rows}get isCursorInViewport(){let e=this.ybase+this.y-this.ydisp;return e>=0&&e<this._rows}_getCorrectBufferLength(e){if(!this._hasScrollback)return e;let t=e+this._optionsService.rawOptions.scrollback;return t>SQ?SQ:t}fillViewportRows(e){if(this.lines.length===0){e===void 0&&(e=lQ);let t=this._rows;for(;t--;)this.lines.push(this.getBlankLine(e))}}clear(){this.ydisp=0,this.ybase=0,this.y=0,this.x=0,this.lines=new sQ(this._getCorrectBufferLength(this._rows)),this.scrollTop=0,this.scrollBottom=this._rows-1,this.setupTabStops()}resize(e,t){let n=this.getNullCell(lQ),r=0,i=this._getCorrectBufferLength(t);if(i>this.lines.maxLength&&(this.lines.maxLength=i),this.lines.length>0){if(this._cols<e)for(let t=0;t<this.lines.length;t++)r+=+this.lines.get(t).resize(e,n);let a=0;if(this._rows<t)for(let r=this._rows;r<t;r++)this.lines.length<t+this.ybase&&(this._optionsService.rawOptions.windowsMode||this._optionsService.rawOptions.windowsPty.backend!==void 0||this._optionsService.rawOptions.windowsPty.buildNumber!==void 0?this.lines.push(new fQ(e,n)):this.ybase>0&&this.lines.length<=this.ybase+this.y+a+1?(this.ybase--,a++,this.ydisp>0&&this.ydisp--):this.lines.push(new fQ(e,n)));else for(let e=this._rows;e>t;e--)this.lines.length>t+this.ybase&&(this.lines.length>this.ybase+this.y+1?this.lines.pop():(this.ybase++,this.ydisp++));if(i<this.lines.maxLength){let e=this.lines.length-i;e>0&&(this.lines.trimStart(e),this.ybase=Math.max(this.ybase-e,0),this.ydisp=Math.max(this.ydisp-e,0),this.savedY=Math.max(this.savedY-e,0)),this.lines.maxLength=i}this.x=Math.min(this.x,e-1),this.y=Math.min(this.y,t-1),a&&(this.y+=a),this.savedX=Math.min(this.savedX,e-1),this.scrollTop=0}if(this.scrollBottom=t-1,this._isReflowEnabled&&(this._reflow(e,t),this._cols>e))for(let t=0;t<this.lines.length;t++)r+=+this.lines.get(t).resize(e,n);this._cols=e,this._rows=t,this._memoryCleanupQueue.clear(),r>.1*this.lines.length&&(this._memoryCleanupPosition=0,this._memoryCleanupQueue.enqueue(()=>this._batchedMemoryCleanup()))}_batchedMemoryCleanup(){let e=!0;this._memoryCleanupPosition>=this.lines.length&&(this._memoryCleanupPosition=0,e=!1);let t=0;for(;this._memoryCleanupPosition<this.lines.length;)if(t+=this.lines.get(this._memoryCleanupPosition++).cleanupMemory(),t>100)return!0;return e}get _isReflowEnabled(){let e=this._optionsService.rawOptions.windowsPty;return e&&e.buildNumber?this._hasScrollback&&e.backend===`conpty`&&e.buildNumber>=21376:this._hasScrollback&&!this._optionsService.rawOptions.windowsMode}_reflow(e,t){this._cols!==e&&(e>this._cols?this._reflowLarger(e,t):this._reflowSmaller(e,t))}_reflowLarger(e,t){let n=this._optionsService.rawOptions.reflowCursorLine,r=pQ(this.lines,this._cols,e,this.ybase+this.y,this.getNullCell(lQ),n);if(r.length>0){let n=mQ(this.lines,r);hQ(this.lines,n.layout),this._reflowLargerAdjustViewport(e,t,n.countRemoved)}}_reflowLargerAdjustViewport(e,t,n){let r=this.getNullCell(lQ),i=n;for(;i-->0;)this.ybase===0?(this.y>0&&this.y--,this.lines.length<t&&this.lines.push(new fQ(e,r))):(this.ydisp===this.ybase&&this.ydisp--,this.ybase--);this.savedY=Math.max(this.savedY-n,0)}_reflowSmaller(e,t){let n=this._optionsService.rawOptions.reflowCursorLine,r=this.getNullCell(lQ),i=[],a=0;for(let o=this.lines.length-1;o>=0;o--){let s=this.lines.get(o);if(!s||!s.isWrapped&&s.getTrimmedLength()<=e)continue;let c=[s];for(;s.isWrapped&&o>0;)s=this.lines.get(--o),c.unshift(s);if(!n){let e=this.ybase+this.y;if(e>=o&&e<o+c.length)continue}let l=c[c.length-1].getTrimmedLength(),u=gQ(c,this._cols,e),d=u.length-c.length,f;f=this.ybase===0&&this.y!==this.lines.length-1?Math.max(0,this.y-this.lines.maxLength+d):Math.max(0,this.lines.length-this.lines.maxLength+d);let p=[];for(let e=0;e<d;e++){let e=this.getBlankLine(lQ,!0);p.push(e)}p.length>0&&(i.push({start:o+c.length+a,newLines:p}),a+=p.length),c.push(...p);let m=u.length-1,h=u[m];h===0&&(m--,h=u[m]);let g=c.length-d-1,_=l;for(;g>=0;){let e=Math.min(_,h);if(c[m]===void 0)break;c[m].copyCellsFrom(c[g],_-e,h-e,e,!0),h-=e,h===0&&(m--,h=u[m]),_-=e,_===0&&(g--,_=_Q(c,Math.max(g,0),this._cols))}for(let t=0;t<c.length;t++)u[t]<e&&c[t].setCell(u[t],r);let v=d-f;for(;v-->0;)this.ybase===0?this.y<t-1?(this.y++,this.lines.pop()):(this.ybase++,this.ydisp++):this.ybase<Math.min(this.lines.maxLength,this.lines.length+a)-t&&(this.ybase===this.ydisp&&this.ydisp++,this.ybase++);this.savedY=Math.min(this.savedY+d,this.ybase+t-1)}if(i.length>0){let e=[],t=[];for(let e=0;e<this.lines.length;e++)t.push(this.lines.get(e));let n=this.lines.length,r=n-1,o=0,s=i[o];this.lines.length=Math.min(this.lines.maxLength,this.lines.length+a);let c=0;for(let l=Math.min(this.lines.maxLength-1,n+a-1);l>=0;l--)if(s&&s.start>r+c){for(let e=s.newLines.length-1;e>=0;e--)this.lines.set(l--,s.newLines[e]);l++,e.push({index:r+1,amount:s.newLines.length}),c+=s.newLines.length,s=i[++o]}else this.lines.set(l,t[r--]);let l=0;for(let t=e.length-1;t>=0;t--)e[t].index+=l,this.lines.onInsertEmitter.fire(e[t]),l+=e[t].amount;let u=Math.max(0,n+a-this.lines.maxLength);u>0&&this.lines.onTrimEmitter.fire(u)}}translateBufferLineToString(e,t,n=0,r){let i=this.lines.get(e);return i?i.translateToString(t,n,r):``}getWrappedRangeForLine(e){let t=e,n=e;for(;t>0&&this.lines.get(t).isWrapped;)t--;for(;n+1<this.lines.length&&this.lines.get(n+1).isWrapped;)n++;return{first:t,last:n}}setupTabStops(e){for(e==null?(this.tabs={},e=0):this.tabs[e]||(e=this.prevStop(e));e<this._cols;e+=this._optionsService.rawOptions.tabStopWidth)this.tabs[e]=!0}prevStop(e){for(e??=this.x;!this.tabs[--e]&&e>0;);return e>=this._cols?this._cols-1:e<0?0:e}nextStop(e){for(e??=this.x;!this.tabs[++e]&&e<this._cols;);return e>=this._cols?this._cols-1:e<0?0:e}clearMarkers(e){this._isClearing=!0;for(let t=0;t<this.markers.length;t++)this.markers[t].line===e&&(this.markers[t].dispose(),this.markers.splice(t--,1));this._isClearing=!1}clearAllMarkers(){this._isClearing=!0;for(let e=0;e<this.markers.length;e++)this.markers[e].dispose();this.markers.length=0,this._isClearing=!1}addMarker(e){let t=new yQ(e);return this.markers.push(t),t.register(this.lines.onTrim(e=>{t.line-=e,t.line<0&&t.dispose()})),t.register(this.lines.onInsert(e=>{t.line>=e.index&&(t.line+=e.amount)})),t.register(this.lines.onDelete(e=>{t.line>=e.index&&t.line<e.index+e.amount&&t.dispose(),t.line>e.index&&(t.line-=e.amount)})),t.register(t.onDispose(()=>this._removeMarker(t))),t}_removeMarker(e){this._isClearing||this.markers.splice(this.markers.indexOf(e),1)}},wQ=class extends Sq{constructor(e,t){super(),this._optionsService=e,this._bufferService=t,this._onBufferActivate=this._register(new Hq),this.onBufferActivate=this._onBufferActivate.event,this.reset(),this._register(this._optionsService.onSpecificOptionChange(`scrollback`,()=>this.resize(this._bufferService.cols,this._bufferService.rows))),this._register(this._optionsService.onSpecificOptionChange(`tabStopWidth`,()=>this.setupTabStops()))}reset(){this._normal=new CQ(!0,this._optionsService,this._bufferService),this._normal.fillViewportRows(),this._alt=new CQ(!1,this._optionsService,this._bufferService),this._activeBuffer=this._normal,this._onBufferActivate.fire({activeBuffer:this._normal,inactiveBuffer:this._alt}),this.setupTabStops()}get alt(){return this._alt}get active(){return this._activeBuffer}get normal(){return this._normal}activateNormalBuffer(){this._activeBuffer!==this._normal&&(this._normal.x=this._alt.x,this._normal.y=this._alt.y,this._alt.clearAllMarkers(),this._alt.clear(),this._activeBuffer=this._normal,this._onBufferActivate.fire({activeBuffer:this._normal,inactiveBuffer:this._alt}))}activateAltBuffer(e){this._activeBuffer!==this._alt&&(this._alt.fillViewportRows(e),this._alt.x=this._normal.x,this._alt.y=this._normal.y,this._activeBuffer=this._alt,this._onBufferActivate.fire({activeBuffer:this._alt,inactiveBuffer:this._normal}))}resize(e,t){this._normal.resize(e,t),this._alt.resize(e,t),this.setupTabStops(e)}setupTabStops(e){this._normal.setupTabStops(e),this._alt.setupTabStops(e)}},TQ=2,EQ=1,DQ=class extends Sq{constructor(e){super(),this.isUserScrolling=!1,this._onResize=this._register(new Hq),this.onResize=this._onResize.event,this._onScroll=this._register(new Hq),this.onScroll=this._onScroll.event,this.cols=Math.max(e.rawOptions.cols||0,TQ),this.rows=Math.max(e.rawOptions.rows||0,EQ),this.buffers=this._register(new wQ(e,this)),this._register(this.buffers.onBufferActivate(e=>{this._onScroll.fire(e.activeBuffer.ydisp)}))}get buffer(){return this.buffers.active}resize(e,t){let n=this.cols!==e,r=this.rows!==t;this.cols=e,this.rows=t,this.buffers.resize(e,t),this._onResize.fire({cols:e,rows:t,colsChanged:n,rowsChanged:r})}reset(){this.buffers.reset(),this.isUserScrolling=!1}scroll(e,t=!1){let n=this.buffer,r;r=this._cachedBlankLine,(!r||r.length!==this.cols||r.getFg(0)!==e.fg||r.getBg(0)!==e.bg)&&(r=n.getBlankLine(e,t),this._cachedBlankLine=r),r.isWrapped=t;let i=n.ybase+n.scrollTop,a=n.ybase+n.scrollBottom;if(n.scrollTop===0){let e=n.lines.isFull;a===n.lines.length-1?e?n.lines.recycle().copyFrom(r):n.lines.push(r.clone()):n.lines.splice(a+1,0,r.clone()),e?this.isUserScrolling&&(n.ydisp=Math.max(n.ydisp-1,0)):(n.ybase++,this.isUserScrolling||n.ydisp++)}else{let e=a-i+1;n.lines.shiftElements(i+1,e-1,-1),n.lines.set(a,r.clone())}this.isUserScrolling||(n.ydisp=n.ybase),this._onScroll.fire(n.ydisp)}scrollLines(e,t){let n=this.buffer;if(e<0){if(n.ydisp===0)return;this.isUserScrolling=!0}else e+n.ydisp>=n.ybase&&(this.isUserScrolling=!1);let r=n.ydisp;n.ydisp=Math.max(Math.min(n.ydisp+e,n.ybase),0),r!==n.ydisp&&(t||this._onScroll.fire(n.ydisp))}};DQ=aK([oK(0,zK)],DQ);var OQ={cols:80,rows:24,cursorBlink:!1,cursorStyle:`block`,cursorWidth:1,cursorInactiveStyle:`outline`,customGlyphs:!0,drawBoldTextInBrightColors:!0,documentOverride:null,fastScrollModifier:`alt`,fastScrollSensitivity:5,fontFamily:`monospace`,fontSize:15,fontWeight:`normal`,fontWeightBold:`bold`,ignoreBracketedPasteMode:!1,lineHeight:1,letterSpacing:0,linkHandler:null,logLevel:`info`,logger:null,scrollback:1e3,scrollOnEraseInDisplay:!1,scrollOnUserInput:!0,scrollSensitivity:1,screenReaderMode:!1,smoothScrollDuration:0,macOptionIsMeta:!1,macOptionClickForcesSelection:!1,minimumContrastRatio:1,disableStdin:!1,allowProposedApi:!1,allowTransparency:!1,tabStopWidth:8,theme:{},reflowCursorLine:!1,rescaleOverlappingGlyphs:!1,rightClickSelectsWord:uZ,windowOptions:{},windowsMode:!1,windowsPty:{},wordSeparator:` ()[]{}',"\``,altClickMovesCursor:!0,convertEol:!1,termName:`xterm`,cancelEvents:!1,overviewRuler:{}},kQ=[`normal`,`bold`,`100`,`200`,`300`,`400`,`500`,`600`,`700`,`800`,`900`],AQ=class extends Sq{constructor(e){super(),this._onOptionChange=this._register(new Hq),this.onOptionChange=this._onOptionChange.event;let t={...OQ};for(let n in e)if(n in t)try{let r=e[n];t[n]=this._sanitizeAndValidateOption(n,r)}catch(e){console.error(e)}this.rawOptions=t,this.options={...t},this._setupOptions(),this._register(yq(()=>{this.rawOptions.linkHandler=null,this.rawOptions.documentOverride=null}))}onSpecificOptionChange(e,t){return this.onOptionChange(n=>{n===e&&t(this.rawOptions[e])})}onMultipleOptionChange(e,t){return this.onOptionChange(n=>{e.indexOf(n)!==-1&&t()})}_setupOptions(){let e=e=>{if(!(e in OQ))throw Error(`No option with key "${e}"`);return this.rawOptions[e]},t=(e,t)=>{if(!(e in OQ))throw Error(`No option with key "${e}"`);t=this._sanitizeAndValidateOption(e,t),this.rawOptions[e]!==t&&(this.rawOptions[e]=t,this._onOptionChange.fire(e))};for(let n in this.rawOptions){let r={get:e.bind(this,n),set:t.bind(this,n)};Object.defineProperty(this.options,n,r)}}_sanitizeAndValidateOption(e,t){switch(e){case`cursorStyle`:if(t||=OQ[e],!jQ(t))throw Error(`"${t}" is not a valid value for ${e}`);break;case`wordSeparator`:t||=OQ[e];break;case`fontWeight`:case`fontWeightBold`:if(typeof t==`number`&&1<=t&&t<=1e3)break;t=kQ.includes(t)?t:OQ[e];break;case`cursorWidth`:t=Math.floor(t);case`lineHeight`:case`tabStopWidth`:if(t<1)throw Error(`${e} cannot be less than 1, value: ${t}`);break;case`minimumContrastRatio`:t=Math.max(1,Math.min(21,Math.round(t*10)/10));break;case`scrollback`:if(t=Math.min(t,4294967295),t<0)throw Error(`${e} cannot be less than 0, value: ${t}`);break;case`fastScrollSensitivity`:case`scrollSensitivity`:if(t<=0)throw Error(`${e} cannot be less than or equal to 0, value: ${t}`);break;case`rows`:case`cols`:if(!t&&t!==0)throw Error(`${e} must be numeric, value: ${t}`);break;case`windowsPty`:t??={}}return t}};function jQ(e){return e===`block`||e===`underline`||e===`bar`}function MQ(e,t=5){if(typeof e!=`object`)return e;let n=Array.isArray(e)?[]:{};for(let r in e)n[r]=t<=1?e[r]:e[r]&&MQ(e[r],t-1);return n}var NQ=Object.freeze({insertMode:!1}),PQ=Object.freeze({applicationCursorKeys:!1,applicationKeypad:!1,bracketedPasteMode:!1,cursorBlink:void 0,cursorStyle:void 0,origin:!1,reverseWraparound:!1,sendFocus:!1,synchronizedOutput:!1,wraparound:!0}),FQ=class extends Sq{constructor(e,t,n){super(),this._bufferService=e,this._logService=t,this._optionsService=n,this.isCursorInitialized=!1,this.isCursorHidden=!1,this._onData=this._register(new Hq),this.onData=this._onData.event,this._onUserInput=this._register(new Hq),this.onUserInput=this._onUserInput.event,this._onBinary=this._register(new Hq),this.onBinary=this._onBinary.event,this._onRequestScrollToBottom=this._register(new Hq),this.onRequestScrollToBottom=this._onRequestScrollToBottom.event,this.modes=MQ(NQ),this.decPrivateModes=MQ(PQ)}reset(){this.modes=MQ(NQ),this.decPrivateModes=MQ(PQ)}triggerDataEvent(e,t=!1){if(this._optionsService.rawOptions.disableStdin)return;let n=this._bufferService.buffer;t&&this._optionsService.rawOptions.scrollOnUserInput&&n.ybase!==n.ydisp&&this._onRequestScrollToBottom.fire(),t&&this._onUserInput.fire(),this._logService.debug(`sending data "${e}"`),this._logService.trace(`sending data (codes)`,()=>e.split(``).map(e=>e.charCodeAt(0))),this._onData.fire(e)}triggerBinaryEvent(e){this._optionsService.rawOptions.disableStdin||(this._logService.debug(`sending binary "${e}"`),this._logService.trace(`sending binary (codes)`,()=>e.split(``).map(e=>e.charCodeAt(0))),this._onBinary.fire(e))}};FQ=aK([oK(0,NK),oK(1,RK),oK(2,zK)],FQ);var IQ={NONE:{events:0,restrict:()=>!1},X10:{events:1,restrict:e=>e.button===4||e.action!==1?!1:(e.ctrl=!1,e.alt=!1,e.shift=!1,!0)},VT200:{events:19,restrict:e=>e.action!==32},DRAG:{events:23,restrict:e=>e.action!==32||e.button!==3},ANY:{events:31,restrict:e=>!0}};function LQ(e,t){let n=(e.ctrl?16:0)|(e.shift?4:0)|(e.alt?8:0);return e.button===4?(n|=64,n|=e.action):(n|=e.button&3,e.button&4&&(n|=64),e.button&8&&(n|=128),e.action===32?n|=32:e.action===0&&!t&&(n|=3)),n}var RQ=String.fromCharCode,zQ={DEFAULT:e=>{let t=[LQ(e,!1)+32,e.col+32,e.row+32];return t[0]>255||t[1]>255||t[2]>255?``:`\x1B[M${RQ(t[0])}${RQ(t[1])}${RQ(t[2])}`},SGR:e=>{let t=e.action===0&&e.button!==4?`m`:`M`;return`\x1B[<${LQ(e,!0)};${e.col};${e.row}${t}`},SGR_PIXELS:e=>{let t=e.action===0&&e.button!==4?`m`:`M`;return`\x1B[<${LQ(e,!0)};${e.x};${e.y}${t}`}},BQ=class extends Sq{constructor(e,t,n){super(),this._bufferService=e,this._coreService=t,this._optionsService=n,this._protocols={},this._encodings={},this._activeProtocol=``,this._activeEncoding=``,this._lastEvent=null,this._wheelPartialScroll=0,this._onProtocolChange=this._register(new Hq),this.onProtocolChange=this._onProtocolChange.event;for(let e of Object.keys(IQ))this.addProtocol(e,IQ[e]);for(let e of Object.keys(zQ))this.addEncoding(e,zQ[e]);this.reset()}addProtocol(e,t){this._protocols[e]=t}addEncoding(e,t){this._encodings[e]=t}get activeProtocol(){return this._activeProtocol}get areMouseEventsActive(){return this._protocols[this._activeProtocol].events!==0}set activeProtocol(e){if(!this._protocols[e])throw Error(`unknown protocol "${e}"`);this._activeProtocol=e,this._onProtocolChange.fire(this._protocols[e].events)}get activeEncoding(){return this._activeEncoding}set activeEncoding(e){if(!this._encodings[e])throw Error(`unknown encoding "${e}"`);this._activeEncoding=e}reset(){this.activeProtocol=`NONE`,this.activeEncoding=`DEFAULT`,this._lastEvent=null,this._wheelPartialScroll=0}consumeWheelEvent(e,t,n){if(e.deltaY===0||e.shiftKey||t===void 0||n===void 0)return 0;let r=t/n,i=this._applyScrollModifier(e.deltaY,e);return e.deltaMode===WheelEvent.DOM_DELTA_PIXEL?(i/=r+0,Math.abs(e.deltaY)<50&&(i*=.3),this._wheelPartialScroll+=i,i=Math.floor(Math.abs(this._wheelPartialScroll))*(this._wheelPartialScroll>0?1:-1),this._wheelPartialScroll%=1):e.deltaMode===WheelEvent.DOM_DELTA_PAGE&&(i*=this._bufferService.rows),i}_applyScrollModifier(e,t){return t.altKey||t.ctrlKey||t.shiftKey?e*this._optionsService.rawOptions.fastScrollSensitivity*this._optionsService.rawOptions.scrollSensitivity:e*this._optionsService.rawOptions.scrollSensitivity}triggerMouseEvent(e){if(e.col<0||e.col>=this._bufferService.cols||e.row<0||e.row>=this._bufferService.rows||e.button===4&&e.action===32||e.button===3&&e.action!==32||e.button!==4&&(e.action===2||e.action===3)||(e.col++,e.row++,e.action===32&&this._lastEvent&&this._equalEvents(this._lastEvent,e,this._activeEncoding===`SGR_PIXELS`))||!this._protocols[this._activeProtocol].restrict(e))return!1;let t=this._encodings[this._activeEncoding](e);return t&&(this._activeEncoding===`DEFAULT`?this._coreService.triggerBinaryEvent(t):this._coreService.triggerDataEvent(t,!0)),this._lastEvent=e,!0}explainEvents(e){return{down:!!(e&1),up:!!(e&2),drag:!!(e&4),move:!!(e&8),wheel:!!(e&16)}}_equalEvents(e,t,n){if(n){if(e.x!==t.x||e.y!==t.y)return!1}else if(e.col!==t.col||e.row!==t.row)return!1;return e.button===t.button&&e.action===t.action&&e.ctrl===t.ctrl&&e.alt===t.alt&&e.shift===t.shift}};BQ=aK([oK(0,NK),oK(1,FK),oK(2,zK)],BQ);var VQ=[[768,879],[1155,1158],[1160,1161],[1425,1469],[1471,1471],[1473,1474],[1476,1477],[1479,1479],[1536,1539],[1552,1557],[1611,1630],[1648,1648],[1750,1764],[1767,1768],[1770,1773],[1807,1807],[1809,1809],[1840,1866],[1958,1968],[2027,2035],[2305,2306],[2364,2364],[2369,2376],[2381,2381],[2385,2388],[2402,2403],[2433,2433],[2492,2492],[2497,2500],[2509,2509],[2530,2531],[2561,2562],[2620,2620],[2625,2626],[2631,2632],[2635,2637],[2672,2673],[2689,2690],[2748,2748],[2753,2757],[2759,2760],[2765,2765],[2786,2787],[2817,2817],[2876,2876],[2879,2879],[2881,2883],[2893,2893],[2902,2902],[2946,2946],[3008,3008],[3021,3021],[3134,3136],[3142,3144],[3146,3149],[3157,3158],[3260,3260],[3263,3263],[3270,3270],[3276,3277],[3298,3299],[3393,3395],[3405,3405],[3530,3530],[3538,3540],[3542,3542],[3633,3633],[3636,3642],[3655,3662],[3761,3761],[3764,3769],[3771,3772],[3784,3789],[3864,3865],[3893,3893],[3895,3895],[3897,3897],[3953,3966],[3968,3972],[3974,3975],[3984,3991],[3993,4028],[4038,4038],[4141,4144],[4146,4146],[4150,4151],[4153,4153],[4184,4185],[4448,4607],[4959,4959],[5906,5908],[5938,5940],[5970,5971],[6002,6003],[6068,6069],[6071,6077],[6086,6086],[6089,6099],[6109,6109],[6155,6157],[6313,6313],[6432,6434],[6439,6440],[6450,6450],[6457,6459],[6679,6680],[6912,6915],[6964,6964],[6966,6970],[6972,6972],[6978,6978],[7019,7027],[7616,7626],[7678,7679],[8203,8207],[8234,8238],[8288,8291],[8298,8303],[8400,8431],[12330,12335],[12441,12442],[43014,43014],[43019,43019],[43045,43046],[64286,64286],[65024,65039],[65056,65059],[65279,65279],[65529,65531]],HQ=[[68097,68099],[68101,68102],[68108,68111],[68152,68154],[68159,68159],[119143,119145],[119155,119170],[119173,119179],[119210,119213],[119362,119364],[917505,917505],[917536,917631],[917760,917999]],UQ;function WQ(e,t){let n=0,r=t.length-1,i;if(e<t[0][0]||e>t[r][1])return!1;for(;r>=n;)if(i=n+r>>1,e>t[i][1])n=i+1;else if(e<t[i][0])r=i-1;else return!0;return!1}var GQ=class{constructor(){if(this.version=`6`,!UQ){UQ=new Uint8Array(65536),UQ.fill(1),UQ[0]=0,UQ.fill(0,1,32),UQ.fill(0,127,160),UQ.fill(2,4352,4448),UQ[9001]=2,UQ[9002]=2,UQ.fill(2,11904,42192),UQ[12351]=1,UQ.fill(2,44032,55204),UQ.fill(2,63744,64256),UQ.fill(2,65040,65050),UQ.fill(2,65072,65136),UQ.fill(2,65280,65377),UQ.fill(2,65504,65511);for(let e=0;e<VQ.length;++e)UQ.fill(0,VQ[e][0],VQ[e][1]+1)}}wcwidth(e){return e<32?0:e<127?1:e<65536?UQ[e]:WQ(e,HQ)?0:e>=131072&&e<=196605||e>=196608&&e<=262141?2:1}charProperties(e,t){let n=this.wcwidth(e),r=n===0&&t!==0;if(r){let e=KQ.extractWidth(t);e===0?r=!1:e>n&&(n=e)}return KQ.createPropertyValue(0,n,r)}},KQ=class e{constructor(){this._providers=Object.create(null),this._active=``,this._onChange=new Hq,this.onChange=this._onChange.event;let e=new GQ;this.register(e),this._active=e.version,this._activeProvider=e}static extractShouldJoin(e){return!!(e&1)}static extractWidth(e){return e>>1&3}static extractCharKind(e){return e>>3}static createPropertyValue(e,t,n=!1){return(e&16777215)<<3|(t&3)<<1|!!n}dispose(){this._onChange.dispose()}get versions(){return Object.keys(this._providers)}get activeVersion(){return this._active}set activeVersion(e){if(!this._providers[e])throw Error(`unknown Unicode version "${e}"`);this._active=e,this._activeProvider=this._providers[e],this._onChange.fire(e)}register(e){this._providers[e.version]=e}wcwidth(e){return this._activeProvider.wcwidth(e)}getStringCellWidth(t){let n=0,r=0,i=t.length;for(let a=0;a<i;++a){let o=t.charCodeAt(a);if(55296<=o&&o<=56319){if(++a>=i)return n+this.wcwidth(o);let e=t.charCodeAt(a);56320<=e&&e<=57343?o=(o-55296)*1024+e-56320+65536:n+=this.wcwidth(e)}let s=this.charProperties(o,r),c=e.extractWidth(s);e.extractShouldJoin(s)&&(c-=e.extractWidth(r)),n+=c,r=s}return n}charProperties(e,t){return this._activeProvider.charProperties(e,t)}},qQ=class{constructor(){this.glevel=0,this._charsets=[]}reset(){this.charset=void 0,this._charsets=[],this.glevel=0}setgLevel(e){this.glevel=e,this.charset=this._charsets[e]}setgCharset(e,t){this._charsets[e]=t,this.glevel===e&&(this.charset=t)}};function JQ(e){let t=e.buffer.lines.get(e.buffer.ybase+e.buffer.y-1)?.get(e.cols-1),n=e.buffer.lines.get(e.buffer.ybase+e.buffer.y);n&&t&&(n.isWrapped=t[3]!==0&&t[3]!==32)}var YQ=2147483647,XQ=256,ZQ=class e{constructor(e=32,t=32){if(this.maxLength=e,this.maxSubParamsLength=t,t>XQ)throw Error(`maxSubParamsLength must not be greater than 256`);this.params=new Int32Array(e),this.length=0,this._subParams=new Int32Array(t),this._subParamsLength=0,this._subParamsIdx=new Uint16Array(e),this._rejectDigits=!1,this._rejectSubDigits=!1,this._digitIsSub=!1}static fromArray(t){let n=new e;if(!t.length)return n;for(let e=+!!Array.isArray(t[0]);e<t.length;++e){let r=t[e];if(Array.isArray(r))for(let e=0;e<r.length;++e)n.addSubParam(r[e]);else n.addParam(r)}return n}clone(){let t=new e(this.maxLength,this.maxSubParamsLength);return t.params.set(this.params),t.length=this.length,t._subParams.set(this._subParams),t._subParamsLength=this._subParamsLength,t._subParamsIdx.set(this._subParamsIdx),t._rejectDigits=this._rejectDigits,t._rejectSubDigits=this._rejectSubDigits,t._digitIsSub=this._digitIsSub,t}toArray(){let e=[];for(let t=0;t<this.length;++t){e.push(this.params[t]);let n=this._subParamsIdx[t]>>8,r=this._subParamsIdx[t]&255;r-n>0&&e.push(Array.prototype.slice.call(this._subParams,n,r))}return e}reset(){this.length=0,this._subParamsLength=0,this._rejectDigits=!1,this._rejectSubDigits=!1,this._digitIsSub=!1}addParam(e){if(this._digitIsSub=!1,this.length>=this.maxLength)this._rejectDigits=!0;else{if(e<-1)throw Error(`values lesser than -1 are not allowed`);this._subParamsIdx[this.length]=this._subParamsLength<<8|this._subParamsLength,this.params[this.length++]=e>YQ?YQ:e}}addSubParam(e){if(this._digitIsSub=!0,this.length){if(this._rejectDigits||this._subParamsLength>=this.maxSubParamsLength){this._rejectSubDigits=!0;return}if(e<-1)throw Error(`values lesser than -1 are not allowed`);this._subParams[this._subParamsLength++]=e>YQ?YQ:e,this._subParamsIdx[this.length-1]++}}hasSubParams(e){return(this._subParamsIdx[e]&255)-(this._subParamsIdx[e]>>8)>0}getSubParams(e){let t=this._subParamsIdx[e]>>8,n=this._subParamsIdx[e]&255;return n-t>0?this._subParams.subarray(t,n):null}getSubParamsAll(){let e={};for(let t=0;t<this.length;++t){let n=this._subParamsIdx[t]>>8,r=this._subParamsIdx[t]&255;r-n>0&&(e[t]=this._subParams.slice(n,r))}return e}addDigit(e){let t;if(this._rejectDigits||!(t=this._digitIsSub?this._subParamsLength:this.length)||this._digitIsSub&&this._rejectSubDigits)return;let n=this._digitIsSub?this._subParams:this.params,r=n[t-1];n[t-1]=~r?Math.min(r*10+e,YQ):e}},QQ=[],$Q=class{constructor(){this._state=0,this._active=QQ,this._id=-1,this._handlers=Object.create(null),this._handlerFb=()=>{},this._stack={paused:!1,loopPosition:0,fallThrough:!1}}registerHandler(e,t){this._handlers[e]===void 0&&(this._handlers[e]=[]);let n=this._handlers[e];return n.push(t),{dispose:()=>{let e=n.indexOf(t);e!==-1&&n.splice(e,1)}}}clearHandler(e){this._handlers[e]&&delete this._handlers[e]}setHandlerFallback(e){this._handlerFb=e}dispose(){this._handlers=Object.create(null),this._handlerFb=()=>{},this._active=QQ}reset(){if(this._state===2)for(let e=this._stack.paused?this._stack.loopPosition-1:this._active.length-1;e>=0;--e)this._active[e].end(!1);this._stack.paused=!1,this._active=QQ,this._id=-1,this._state=0}_start(){if(this._active=this._handlers[this._id]||QQ,!this._active.length)this._handlerFb(this._id,`START`);else for(let e=this._active.length-1;e>=0;e--)this._active[e].start()}_put(e,t,n){if(!this._active.length)this._handlerFb(this._id,`PUT`,yK(e,t,n));else for(let r=this._active.length-1;r>=0;r--)this._active[r].put(e,t,n)}start(){this.reset(),this._state=1}put(e,t,n){if(this._state!==3){if(this._state===1)for(;t<n;){let n=e[t++];if(n===59){this._state=2,this._start();break}if(n<48||57<n){this._state=3;return}this._id===-1&&(this._id=0),this._id=this._id*10+n-48}this._state===2&&n-t>0&&this._put(e,t,n)}}end(e,t=!0){if(this._state!==0){if(this._state!==3){if(this._state===1&&this._start(),!this._active.length)this._handlerFb(this._id,`END`,e);else{let n=!1,r=this._active.length-1,i=!1;if(this._stack.paused&&(r=this._stack.loopPosition-1,n=t,i=this._stack.fallThrough,this._stack.paused=!1),!i&&n===!1){for(;r>=0&&(n=this._active[r].end(e),n!==!0);r--)if(n instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=r,this._stack.fallThrough=!1,n;r--}for(;r>=0;r--)if(n=this._active[r].end(!1),n instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=r,this._stack.fallThrough=!0,n}}this._active=QQ,this._id=-1,this._state=0}}},e$=class{constructor(e){this._handler=e,this._data=``,this._hitLimit=!1}start(){this._data=``,this._hitLimit=!1}put(e,t,n){this._hitLimit||(this._data+=yK(e,t,n),this._data.length>1e7&&(this._data=``,this._hitLimit=!0))}end(e){let t=!1;if(this._hitLimit)t=!1;else if(e&&(t=this._handler(this._data),t instanceof Promise))return t.then(e=>(this._data=``,this._hitLimit=!1,e));return this._data=``,this._hitLimit=!1,t}},t$=[],n$=class{constructor(){this._handlers=Object.create(null),this._active=t$,this._ident=0,this._handlerFb=()=>{},this._stack={paused:!1,loopPosition:0,fallThrough:!1}}dispose(){this._handlers=Object.create(null),this._handlerFb=()=>{},this._active=t$}registerHandler(e,t){this._handlers[e]===void 0&&(this._handlers[e]=[]);let n=this._handlers[e];return n.push(t),{dispose:()=>{let e=n.indexOf(t);e!==-1&&n.splice(e,1)}}}clearHandler(e){this._handlers[e]&&delete this._handlers[e]}setHandlerFallback(e){this._handlerFb=e}reset(){if(this._active.length)for(let e=this._stack.paused?this._stack.loopPosition-1:this._active.length-1;e>=0;--e)this._active[e].unhook(!1);this._stack.paused=!1,this._active=t$,this._ident=0}hook(e,t){if(this.reset(),this._ident=e,this._active=this._handlers[e]||t$,!this._active.length)this._handlerFb(this._ident,`HOOK`,t);else for(let e=this._active.length-1;e>=0;e--)this._active[e].hook(t)}put(e,t,n){if(!this._active.length)this._handlerFb(this._ident,`PUT`,yK(e,t,n));else for(let r=this._active.length-1;r>=0;r--)this._active[r].put(e,t,n)}unhook(e,t=!0){if(!this._active.length)this._handlerFb(this._ident,`UNHOOK`,e);else{let n=!1,r=this._active.length-1,i=!1;if(this._stack.paused&&(r=this._stack.loopPosition-1,n=t,i=this._stack.fallThrough,this._stack.paused=!1),!i&&n===!1){for(;r>=0&&(n=this._active[r].unhook(e),n!==!0);r--)if(n instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=r,this._stack.fallThrough=!1,n;r--}for(;r>=0;r--)if(n=this._active[r].unhook(!1),n instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=r,this._stack.fallThrough=!0,n}this._active=t$,this._ident=0}},r$=new ZQ;r$.addParam(0);var i$=class{constructor(e){this._handler=e,this._data=``,this._params=r$,this._hitLimit=!1}hook(e){this._params=e.length>1||e.params[0]?e.clone():r$,this._data=``,this._hitLimit=!1}put(e,t,n){this._hitLimit||(this._data+=yK(e,t,n),this._data.length>1e7&&(this._data=``,this._hitLimit=!0))}unhook(e){let t=!1;if(this._hitLimit)t=!1;else if(e&&(t=this._handler(this._data,this._params),t instanceof Promise))return t.then(e=>(this._params=r$,this._data=``,this._hitLimit=!1,e));return this._params=r$,this._data=``,this._hitLimit=!1,t}},a$=class{constructor(e){this.table=new Uint8Array(e)}setDefault(e,t){this.table.fill(e<<4|t)}add(e,t,n,r){this.table[t<<8|e]=n<<4|r}addMany(e,t,n,r){for(let i=0;i<e.length;i++)this.table[t<<8|e[i]]=n<<4|r}},o$=160,s$=function(){let e=new a$(4095),t=Array.apply(null,Array(256)).map((e,t)=>t),n=(e,n)=>t.slice(e,n),r=n(32,127),i=n(0,24);i.push(25),i.push.apply(i,n(28,32));let a=n(0,14),o;for(o in e.setDefault(1,0),e.addMany(r,0,2,0),a)e.addMany([24,26,153,154],o,3,0),e.addMany(n(128,144),o,3,0),e.addMany(n(144,152),o,3,0),e.add(156,o,0,0),e.add(27,o,11,1),e.add(157,o,4,8),e.addMany([152,158,159],o,0,7),e.add(155,o,11,3),e.add(144,o,11,9);return e.addMany(i,0,3,0),e.addMany(i,1,3,1),e.add(127,1,0,1),e.addMany(i,8,0,8),e.addMany(i,3,3,3),e.add(127,3,0,3),e.addMany(i,4,3,4),e.add(127,4,0,4),e.addMany(i,6,3,6),e.addMany(i,5,3,5),e.add(127,5,0,5),e.addMany(i,2,3,2),e.add(127,2,0,2),e.add(93,1,4,8),e.addMany(r,8,5,8),e.add(127,8,5,8),e.addMany([156,27,24,26,7],8,6,0),e.addMany(n(28,32),8,0,8),e.addMany([88,94,95],1,0,7),e.addMany(r,7,0,7),e.addMany(i,7,0,7),e.add(156,7,0,0),e.add(127,7,0,7),e.add(91,1,11,3),e.addMany(n(64,127),3,7,0),e.addMany(n(48,60),3,8,4),e.addMany([60,61,62,63],3,9,4),e.addMany(n(48,60),4,8,4),e.addMany(n(64,127),4,7,0),e.addMany([60,61,62,63],4,0,6),e.addMany(n(32,64),6,0,6),e.add(127,6,0,6),e.addMany(n(64,127),6,0,0),e.addMany(n(32,48),3,9,5),e.addMany(n(32,48),5,9,5),e.addMany(n(48,64),5,0,6),e.addMany(n(64,127),5,7,0),e.addMany(n(32,48),4,9,5),e.addMany(n(32,48),1,9,2),e.addMany(n(32,48),2,9,2),e.addMany(n(48,127),2,10,0),e.addMany(n(48,80),1,10,0),e.addMany(n(81,88),1,10,0),e.addMany([89,90,92],1,10,0),e.addMany(n(96,127),1,10,0),e.add(80,1,11,9),e.addMany(i,9,0,9),e.add(127,9,0,9),e.addMany(n(28,32),9,0,9),e.addMany(n(32,48),9,9,12),e.addMany(n(48,60),9,8,10),e.addMany([60,61,62,63],9,9,10),e.addMany(i,11,0,11),e.addMany(n(32,128),11,0,11),e.addMany(n(28,32),11,0,11),e.addMany(i,10,0,10),e.add(127,10,0,10),e.addMany(n(28,32),10,0,10),e.addMany(n(48,60),10,8,10),e.addMany([60,61,62,63],10,0,11),e.addMany(n(32,48),10,9,12),e.addMany(i,12,0,12),e.add(127,12,0,12),e.addMany(n(28,32),12,0,12),e.addMany(n(32,48),12,9,12),e.addMany(n(48,64),12,0,11),e.addMany(n(64,127),12,12,13),e.addMany(n(64,127),10,12,13),e.addMany(n(64,127),9,12,13),e.addMany(i,13,13,13),e.addMany(r,13,13,13),e.add(127,13,0,13),e.addMany([27,156,24,26],13,14,0),e.add(o$,0,2,0),e.add(o$,8,5,8),e.add(o$,6,0,6),e.add(o$,11,0,11),e.add(o$,13,13,13),e}(),c$=class extends Sq{constructor(e=s$){super(),this._transitions=e,this._parseStack={state:0,handlers:[],handlerPos:0,transition:0,chunkPos:0},this.initialState=0,this.currentState=this.initialState,this._params=new ZQ,this._params.addParam(0),this._collect=0,this.precedingJoinState=0,this._printHandlerFb=(e,t,n)=>{},this._executeHandlerFb=e=>{},this._csiHandlerFb=(e,t)=>{},this._escHandlerFb=e=>{},this._errorHandlerFb=e=>e,this._printHandler=this._printHandlerFb,this._executeHandlers=Object.create(null),this._csiHandlers=Object.create(null),this._escHandlers=Object.create(null),this._register(yq(()=>{this._csiHandlers=Object.create(null),this._executeHandlers=Object.create(null),this._escHandlers=Object.create(null)})),this._oscParser=this._register(new $Q),this._dcsParser=this._register(new n$),this._errorHandler=this._errorHandlerFb,this.registerEscHandler({final:`\\`},()=>!0)}_identifier(e,t=[64,126]){let n=0;if(e.prefix){if(e.prefix.length>1)throw Error(`only one byte as prefix supported`);if(n=e.prefix.charCodeAt(0),n&&60>n||n>63)throw Error(`prefix must be in range 0x3c .. 0x3f`)}if(e.intermediates){if(e.intermediates.length>2)throw Error(`only two bytes as intermediates are supported`);for(let t=0;t<e.intermediates.length;++t){let r=e.intermediates.charCodeAt(t);if(32>r||r>47)throw Error(`intermediate must be in range 0x20 .. 0x2f`);n<<=8,n|=r}}if(e.final.length!==1)throw Error(`final must be a single byte`);let r=e.final.charCodeAt(0);if(t[0]>r||r>t[1])throw Error(`final must be in range ${t[0]} .. ${t[1]}`);return n<<=8,n|=r,n}identToString(e){let t=[];for(;e;)t.push(String.fromCharCode(e&255)),e>>=8;return t.reverse().join(``)}setPrintHandler(e){this._printHandler=e}clearPrintHandler(){this._printHandler=this._printHandlerFb}registerEscHandler(e,t){let n=this._identifier(e,[48,126]);this._escHandlers[n]===void 0&&(this._escHandlers[n]=[]);let r=this._escHandlers[n];return r.push(t),{dispose:()=>{let e=r.indexOf(t);e!==-1&&r.splice(e,1)}}}clearEscHandler(e){this._escHandlers[this._identifier(e,[48,126])]&&delete this._escHandlers[this._identifier(e,[48,126])]}setEscHandlerFallback(e){this._escHandlerFb=e}setExecuteHandler(e,t){this._executeHandlers[e.charCodeAt(0)]=t}clearExecuteHandler(e){this._executeHandlers[e.charCodeAt(0)]&&delete this._executeHandlers[e.charCodeAt(0)]}setExecuteHandlerFallback(e){this._executeHandlerFb=e}registerCsiHandler(e,t){let n=this._identifier(e);this._csiHandlers[n]===void 0&&(this._csiHandlers[n]=[]);let r=this._csiHandlers[n];return r.push(t),{dispose:()=>{let e=r.indexOf(t);e!==-1&&r.splice(e,1)}}}clearCsiHandler(e){this._csiHandlers[this._identifier(e)]&&delete this._csiHandlers[this._identifier(e)]}setCsiHandlerFallback(e){this._csiHandlerFb=e}registerDcsHandler(e,t){return this._dcsParser.registerHandler(this._identifier(e),t)}clearDcsHandler(e){this._dcsParser.clearHandler(this._identifier(e))}setDcsHandlerFallback(e){this._dcsParser.setHandlerFallback(e)}registerOscHandler(e,t){return this._oscParser.registerHandler(e,t)}clearOscHandler(e){this._oscParser.clearHandler(e)}setOscHandlerFallback(e){this._oscParser.setHandlerFallback(e)}setErrorHandler(e){this._errorHandler=e}clearErrorHandler(){this._errorHandler=this._errorHandlerFb}reset(){this.currentState=this.initialState,this._oscParser.reset(),this._dcsParser.reset(),this._params.reset(),this._params.addParam(0),this._collect=0,this.precedingJoinState=0,this._parseStack.state!==0&&(this._parseStack.state=2,this._parseStack.handlers=[])}_preserveStack(e,t,n,r,i){this._parseStack.state=e,this._parseStack.handlers=t,this._parseStack.handlerPos=n,this._parseStack.transition=r,this._parseStack.chunkPos=i}parse(e,t,n){let r=0,i=0,a=0,o;if(this._parseStack.state){if(this._parseStack.state===2)this._parseStack.state=0,a=this._parseStack.chunkPos+1;else{if(n===void 0||this._parseStack.state===1)throw this._parseStack.state=1,Error(`improper continuation due to previous async handler, giving up parsing`);let t=this._parseStack.handlers,i=this._parseStack.handlerPos-1;switch(this._parseStack.state){case 3:if(n===!1&&i>-1){for(;i>=0&&(o=t[i](this._params),o!==!0);i--)if(o instanceof Promise)return this._parseStack.handlerPos=i,o}this._parseStack.handlers=[];break;case 4:if(n===!1&&i>-1){for(;i>=0&&(o=t[i](),o!==!0);i--)if(o instanceof Promise)return this._parseStack.handlerPos=i,o}this._parseStack.handlers=[];break;case 6:if(r=e[this._parseStack.chunkPos],o=this._dcsParser.unhook(r!==24&&r!==26,n),o)return o;r===27&&(this._parseStack.transition|=1),this._params.reset(),this._params.addParam(0),this._collect=0;break;case 5:if(r=e[this._parseStack.chunkPos],o=this._oscParser.end(r!==24&&r!==26,n),o)return o;r===27&&(this._parseStack.transition|=1),this._params.reset(),this._params.addParam(0),this._collect=0}this._parseStack.state=0,a=this._parseStack.chunkPos+1,this.precedingJoinState=0,this.currentState=this._parseStack.transition&15}}for(let n=a;n<t;++n){switch(r=e[n],i=this._transitions.table[this.currentState<<8|(r<160?r:o$)],i>>4){case 2:for(let i=n+1;;++i)if(i>=t||(r=e[i])<32||r>126&&r<o$||++i>=t||(r=e[i])<32||r>126&&r<o$||++i>=t||(r=e[i])<32||r>126&&r<o$||++i>=t||(r=e[i])<32||r>126&&r<o$){this._printHandler(e,n,i),n=i-1;break}break;case 3:this._executeHandlers[r]?this._executeHandlers[r]():this._executeHandlerFb(r),this.precedingJoinState=0;break;case 0:break;case 1:if(this._errorHandler({position:n,code:r,currentState:this.currentState,collect:this._collect,params:this._params,abort:!1}).abort)return;break;case 7:let a=this._csiHandlers[this._collect<<8|r],s=a?a.length-1:-1;for(;s>=0&&(o=a[s](this._params),o!==!0);s--)if(o instanceof Promise)return this._preserveStack(3,a,s,i,n),o;s<0&&this._csiHandlerFb(this._collect<<8|r,this._params),this.precedingJoinState=0;break;case 8:do switch(r){case 59:this._params.addParam(0);break;case 58:this._params.addSubParam(-1);break;default:this._params.addDigit(r-48)}while(++n<t&&(r=e[n])>47&&r<60);n--;break;case 9:this._collect<<=8,this._collect|=r;break;case 10:let c=this._escHandlers[this._collect<<8|r],l=c?c.length-1:-1;for(;l>=0&&(o=c[l](),o!==!0);l--)if(o instanceof Promise)return this._preserveStack(4,c,l,i,n),o;l<0&&this._escHandlerFb(this._collect<<8|r),this.precedingJoinState=0;break;case 11:this._params.reset(),this._params.addParam(0),this._collect=0;break;case 12:this._dcsParser.hook(this._collect<<8|r,this._params);break;case 13:for(let i=n+1;;++i)if(i>=t||(r=e[i])===24||r===26||r===27||r>127&&r<o$){this._dcsParser.put(e,n,i),n=i-1;break}break;case 14:if(o=this._dcsParser.unhook(r!==24&&r!==26),o)return this._preserveStack(6,[],0,i,n),o;r===27&&(i|=1),this._params.reset(),this._params.addParam(0),this._collect=0,this.precedingJoinState=0;break;case 4:this._oscParser.start();break;case 5:for(let i=n+1;;i++)if(i>=t||(r=e[i])<32||r>127&&r<o$){this._oscParser.put(e,n,i),n=i-1;break}break;case 6:if(o=this._oscParser.end(r!==24&&r!==26),o)return this._preserveStack(5,[],0,i,n),o;r===27&&(i|=1),this._params.reset(),this._params.addParam(0),this._collect=0,this.precedingJoinState=0}this.currentState=i&15}}},l$=/^([\da-f])\/([\da-f])\/([\da-f])$|^([\da-f]{2})\/([\da-f]{2})\/([\da-f]{2})$|^([\da-f]{3})\/([\da-f]{3})\/([\da-f]{3})$|^([\da-f]{4})\/([\da-f]{4})\/([\da-f]{4})$/,u$=/^[\da-f]+$/;function d$(e){if(!e)return;let t=e.toLowerCase();if(t.indexOf(`rgb:`)===0){t=t.slice(4);let e=l$.exec(t);if(e){let t=e[1]?15:e[4]?255:e[7]?4095:65535;return[Math.round(parseInt(e[1]||e[4]||e[7]||e[10],16)/t*255),Math.round(parseInt(e[2]||e[5]||e[8]||e[11],16)/t*255),Math.round(parseInt(e[3]||e[6]||e[9]||e[12],16)/t*255)]}}else if(t.indexOf(`#`)===0&&(t=t.slice(1),u$.exec(t)&&[3,6,9,12].includes(t.length))){let e=t.length/3,n=[0,0,0];for(let r=0;r<3;++r){let i=parseInt(t.slice(e*r,e*r+e),16);n[r]=e===1?i<<4:e===2?i:e===3?i>>4:i>>8}return n}}function f$(e,t){let n=e.toString(16),r=n.length<2?`0`+n:n;switch(t){case 4:return n[0];case 8:return r;case 12:return(r+r).slice(0,3);default:return r+r}}function p$(e,t=16){let[n,r,i]=e;return`rgb:${f$(n,t)}/${f$(r,t)}/${f$(i,t)}`}var m$={"(":0,")":1,"*":2,"+":3,"-":1,".":2},h$=131072,g$=10;function _$(e,t){if(e>24)return t.setWinLines||!1;switch(e){case 1:return!!t.restoreWin;case 2:return!!t.minimizeWin;case 3:return!!t.setWinPosition;case 4:return!!t.setWinSizePixels;case 5:return!!t.raiseWin;case 6:return!!t.lowerWin;case 7:return!!t.refreshWin;case 8:return!!t.setWinSizeChars;case 9:return!!t.maximizeWin;case 10:return!!t.fullscreenWin;case 11:return!!t.getWinState;case 13:return!!t.getWinPosition;case 14:return!!t.getWinSizePixels;case 15:return!!t.getScreenSizePixels;case 16:return!!t.getCellSizePixels;case 18:return!!t.getWinSizeChars;case 19:return!!t.getScreenSizeChars;case 20:return!!t.getIconTitle;case 21:return!!t.getWinTitle;case 22:return!!t.pushTitle;case 23:return!!t.popTitle;case 24:return!!t.setWinLines}return!1}var v$=5e3,y$=0,b$=class extends Sq{constructor(e,t,n,r,i,a,o,s,c=new c$){super(),this._bufferService=e,this._charsetService=t,this._coreService=n,this._logService=r,this._optionsService=i,this._oscLinkService=a,this._coreMouseService=o,this._unicodeService=s,this._parser=c,this._parseBuffer=new Uint32Array(4096),this._stringDecoder=new bK,this._utf8Decoder=new xK,this._windowTitle=``,this._iconName=``,this._windowTitleStack=[],this._iconNameStack=[],this._curAttrData=lQ.clone(),this._eraseAttrDataInternal=lQ.clone(),this._onRequestBell=this._register(new Hq),this.onRequestBell=this._onRequestBell.event,this._onRequestRefreshRows=this._register(new Hq),this.onRequestRefreshRows=this._onRequestRefreshRows.event,this._onRequestReset=this._register(new Hq),this.onRequestReset=this._onRequestReset.event,this._onRequestSendFocus=this._register(new Hq),this.onRequestSendFocus=this._onRequestSendFocus.event,this._onRequestSyncScrollBar=this._register(new Hq),this.onRequestSyncScrollBar=this._onRequestSyncScrollBar.event,this._onRequestWindowsOptionsReport=this._register(new Hq),this.onRequestWindowsOptionsReport=this._onRequestWindowsOptionsReport.event,this._onA11yChar=this._register(new Hq),this.onA11yChar=this._onA11yChar.event,this._onA11yTab=this._register(new Hq),this.onA11yTab=this._onA11yTab.event,this._onCursorMove=this._register(new Hq),this.onCursorMove=this._onCursorMove.event,this._onLineFeed=this._register(new Hq),this.onLineFeed=this._onLineFeed.event,this._onScroll=this._register(new Hq),this.onScroll=this._onScroll.event,this._onTitleChange=this._register(new Hq),this.onTitleChange=this._onTitleChange.event,this._onColor=this._register(new Hq),this.onColor=this._onColor.event,this._parseStack={paused:!1,cursorStartX:0,cursorStartY:0,decodedLength:0,position:0},this._specialColors=[256,257,258],this._register(this._parser),this._dirtyRowTracker=new x$(this._bufferService),this._activeBuffer=this._bufferService.buffer,this._register(this._bufferService.buffers.onBufferActivate(e=>this._activeBuffer=e.activeBuffer)),this._parser.setCsiHandlerFallback((e,t)=>{this._logService.debug(`Unknown CSI code: `,{identifier:this._parser.identToString(e),params:t.toArray()})}),this._parser.setEscHandlerFallback(e=>{this._logService.debug(`Unknown ESC code: `,{identifier:this._parser.identToString(e)})}),this._parser.setExecuteHandlerFallback(e=>{this._logService.debug(`Unknown EXECUTE code: `,{code:e})}),this._parser.setOscHandlerFallback((e,t,n)=>{this._logService.debug(`Unknown OSC code: `,{identifier:e,action:t,data:n})}),this._parser.setDcsHandlerFallback((e,t,n)=>{t===`HOOK`&&(n=n.toArray()),this._logService.debug(`Unknown DCS code: `,{identifier:this._parser.identToString(e),action:t,payload:n})}),this._parser.setPrintHandler((e,t,n)=>this.print(e,t,n)),this._parser.registerCsiHandler({final:`@`},e=>this.insertChars(e)),this._parser.registerCsiHandler({intermediates:` `,final:`@`},e=>this.scrollLeft(e)),this._parser.registerCsiHandler({final:`A`},e=>this.cursorUp(e)),this._parser.registerCsiHandler({intermediates:` `,final:`A`},e=>this.scrollRight(e)),this._parser.registerCsiHandler({final:`B`},e=>this.cursorDown(e)),this._parser.registerCsiHandler({final:`C`},e=>this.cursorForward(e)),this._parser.registerCsiHandler({final:`D`},e=>this.cursorBackward(e)),this._parser.registerCsiHandler({final:`E`},e=>this.cursorNextLine(e)),this._parser.registerCsiHandler({final:`F`},e=>this.cursorPrecedingLine(e)),this._parser.registerCsiHandler({final:`G`},e=>this.cursorCharAbsolute(e)),this._parser.registerCsiHandler({final:`H`},e=>this.cursorPosition(e)),this._parser.registerCsiHandler({final:`I`},e=>this.cursorForwardTab(e)),this._parser.registerCsiHandler({final:`J`},e=>this.eraseInDisplay(e,!1)),this._parser.registerCsiHandler({prefix:`?`,final:`J`},e=>this.eraseInDisplay(e,!0)),this._parser.registerCsiHandler({final:`K`},e=>this.eraseInLine(e,!1)),this._parser.registerCsiHandler({prefix:`?`,final:`K`},e=>this.eraseInLine(e,!0)),this._parser.registerCsiHandler({final:`L`},e=>this.insertLines(e)),this._parser.registerCsiHandler({final:`M`},e=>this.deleteLines(e)),this._parser.registerCsiHandler({final:`P`},e=>this.deleteChars(e)),this._parser.registerCsiHandler({final:`S`},e=>this.scrollUp(e)),this._parser.registerCsiHandler({final:`T`},e=>this.scrollDown(e)),this._parser.registerCsiHandler({final:`X`},e=>this.eraseChars(e)),this._parser.registerCsiHandler({final:`Z`},e=>this.cursorBackwardTab(e)),this._parser.registerCsiHandler({final:"`"},e=>this.charPosAbsolute(e)),this._parser.registerCsiHandler({final:`a`},e=>this.hPositionRelative(e)),this._parser.registerCsiHandler({final:`b`},e=>this.repeatPrecedingCharacter(e)),this._parser.registerCsiHandler({final:`c`},e=>this.sendDeviceAttributesPrimary(e)),this._parser.registerCsiHandler({prefix:`>`,final:`c`},e=>this.sendDeviceAttributesSecondary(e)),this._parser.registerCsiHandler({final:`d`},e=>this.linePosAbsolute(e)),this._parser.registerCsiHandler({final:`e`},e=>this.vPositionRelative(e)),this._parser.registerCsiHandler({final:`f`},e=>this.hVPosition(e)),this._parser.registerCsiHandler({final:`g`},e=>this.tabClear(e)),this._parser.registerCsiHandler({final:`h`},e=>this.setMode(e)),this._parser.registerCsiHandler({prefix:`?`,final:`h`},e=>this.setModePrivate(e)),this._parser.registerCsiHandler({final:`l`},e=>this.resetMode(e)),this._parser.registerCsiHandler({prefix:`?`,final:`l`},e=>this.resetModePrivate(e)),this._parser.registerCsiHandler({final:`m`},e=>this.charAttributes(e)),this._parser.registerCsiHandler({final:`n`},e=>this.deviceStatus(e)),this._parser.registerCsiHandler({prefix:`?`,final:`n`},e=>this.deviceStatusPrivate(e)),this._parser.registerCsiHandler({intermediates:`!`,final:`p`},e=>this.softReset(e)),this._parser.registerCsiHandler({intermediates:` `,final:`q`},e=>this.setCursorStyle(e)),this._parser.registerCsiHandler({final:`r`},e=>this.setScrollRegion(e)),this._parser.registerCsiHandler({final:`s`},e=>this.saveCursor(e)),this._parser.registerCsiHandler({final:`t`},e=>this.windowOptions(e)),this._parser.registerCsiHandler({final:`u`},e=>this.restoreCursor(e)),this._parser.registerCsiHandler({intermediates:`'`,final:`}`},e=>this.insertColumns(e)),this._parser.registerCsiHandler({intermediates:`'`,final:`~`},e=>this.deleteColumns(e)),this._parser.registerCsiHandler({intermediates:`"`,final:`q`},e=>this.selectProtected(e)),this._parser.registerCsiHandler({intermediates:`$`,final:`p`},e=>this.requestMode(e,!0)),this._parser.registerCsiHandler({prefix:`?`,intermediates:`$`,final:`p`},e=>this.requestMode(e,!1)),this._parser.setExecuteHandler($.BEL,()=>this.bell()),this._parser.setExecuteHandler($.LF,()=>this.lineFeed()),this._parser.setExecuteHandler($.VT,()=>this.lineFeed()),this._parser.setExecuteHandler($.FF,()=>this.lineFeed()),this._parser.setExecuteHandler($.CR,()=>this.carriageReturn()),this._parser.setExecuteHandler($.BS,()=>this.backspace()),this._parser.setExecuteHandler($.HT,()=>this.tab()),this._parser.setExecuteHandler($.SO,()=>this.shiftOut()),this._parser.setExecuteHandler($.SI,()=>this.shiftIn()),this._parser.setExecuteHandler(uX.IND,()=>this.index()),this._parser.setExecuteHandler(uX.NEL,()=>this.nextLine()),this._parser.setExecuteHandler(uX.HTS,()=>this.tabSet()),this._parser.registerOscHandler(0,new e$(e=>(this.setTitle(e),this.setIconName(e),!0))),this._parser.registerOscHandler(1,new e$(e=>this.setIconName(e))),this._parser.registerOscHandler(2,new e$(e=>this.setTitle(e))),this._parser.registerOscHandler(4,new e$(e=>this.setOrReportIndexedColor(e))),this._parser.registerOscHandler(8,new e$(e=>this.setHyperlink(e))),this._parser.registerOscHandler(10,new e$(e=>this.setOrReportFgColor(e))),this._parser.registerOscHandler(11,new e$(e=>this.setOrReportBgColor(e))),this._parser.registerOscHandler(12,new e$(e=>this.setOrReportCursorColor(e))),this._parser.registerOscHandler(104,new e$(e=>this.restoreIndexedColor(e))),this._parser.registerOscHandler(110,new e$(e=>this.restoreFgColor(e))),this._parser.registerOscHandler(111,new e$(e=>this.restoreBgColor(e))),this._parser.registerOscHandler(112,new e$(e=>this.restoreCursorColor(e))),this._parser.registerEscHandler({final:`7`},()=>this.saveCursor()),this._parser.registerEscHandler({final:`8`},()=>this.restoreCursor()),this._parser.registerEscHandler({final:`D`},()=>this.index()),this._parser.registerEscHandler({final:`E`},()=>this.nextLine()),this._parser.registerEscHandler({final:`H`},()=>this.tabSet()),this._parser.registerEscHandler({final:`M`},()=>this.reverseIndex()),this._parser.registerEscHandler({final:`=`},()=>this.keypadApplicationMode()),this._parser.registerEscHandler({final:`>`},()=>this.keypadNumericMode()),this._parser.registerEscHandler({final:`c`},()=>this.fullReset()),this._parser.registerEscHandler({final:`n`},()=>this.setgLevel(2)),this._parser.registerEscHandler({final:`o`},()=>this.setgLevel(3)),this._parser.registerEscHandler({final:`|`},()=>this.setgLevel(3)),this._parser.registerEscHandler({final:`}`},()=>this.setgLevel(2)),this._parser.registerEscHandler({final:`~`},()=>this.setgLevel(1)),this._parser.registerEscHandler({intermediates:`%`,final:`@`},()=>this.selectDefaultCharset()),this._parser.registerEscHandler({intermediates:`%`,final:`G`},()=>this.selectDefaultCharset());for(let e in bQ)this._parser.registerEscHandler({intermediates:`(`,final:e},()=>this.selectCharset(`(`+e)),this._parser.registerEscHandler({intermediates:`)`,final:e},()=>this.selectCharset(`)`+e)),this._parser.registerEscHandler({intermediates:`*`,final:e},()=>this.selectCharset(`*`+e)),this._parser.registerEscHandler({intermediates:`+`,final:e},()=>this.selectCharset(`+`+e)),this._parser.registerEscHandler({intermediates:`-`,final:e},()=>this.selectCharset(`-`+e)),this._parser.registerEscHandler({intermediates:`.`,final:e},()=>this.selectCharset(`.`+e)),this._parser.registerEscHandler({intermediates:`/`,final:e},()=>this.selectCharset(`/`+e));this._parser.registerEscHandler({intermediates:`#`,final:`8`},()=>this.screenAlignmentPattern()),this._parser.setErrorHandler(e=>(this._logService.error(`Parsing error: `,e),e)),this._parser.registerDcsHandler({intermediates:`$`,final:`q`},new i$((e,t)=>this.requestStatusString(e,t)))}getAttrData(){return this._curAttrData}_preserveStack(e,t,n,r){this._parseStack.paused=!0,this._parseStack.cursorStartX=e,this._parseStack.cursorStartY=t,this._parseStack.decodedLength=n,this._parseStack.position=r}_logSlowResolvingAsync(e){this._logService.logLevel<=3&&Promise.race([e,new Promise((e,t)=>setTimeout(()=>t(`#SLOW_TIMEOUT`),v$))]).catch(e=>{if(e!==`#SLOW_TIMEOUT`)throw e;console.warn(`async parser handler taking longer than ${v$} ms`)})}_getCurrentLinkId(){return this._curAttrData.extended.urlId}parse(e,t){let n,r=this._activeBuffer.x,i=this._activeBuffer.y,a=0,o=this._parseStack.paused;if(o){if(n=this._parser.parse(this._parseBuffer,this._parseStack.decodedLength,t))return this._logSlowResolvingAsync(n),n;r=this._parseStack.cursorStartX,i=this._parseStack.cursorStartY,this._parseStack.paused=!1,e.length>h$&&(a=this._parseStack.position+h$)}if(this._logService.logLevel<=1&&this._logService.debug(`parsing data ${typeof e==`string`?` "${e}"`:` "${Array.prototype.map.call(e,e=>String.fromCharCode(e)).join(``)}"`}`),this._logService.logLevel===0&&this._logService.trace(`parsing data (codes)`,typeof e==`string`?e.split(``).map(e=>e.charCodeAt(0)):e),this._parseBuffer.length<e.length&&this._parseBuffer.length<h$&&(this._parseBuffer=new Uint32Array(Math.min(e.length,h$))),o||this._dirtyRowTracker.clearRange(),e.length>h$)for(let t=a;t<e.length;t+=h$){let a=t+h$<e.length?t+h$:e.length,o=typeof e==`string`?this._stringDecoder.decode(e.substring(t,a),this._parseBuffer):this._utf8Decoder.decode(e.subarray(t,a),this._parseBuffer);if(n=this._parser.parse(this._parseBuffer,o))return this._preserveStack(r,i,o,t),this._logSlowResolvingAsync(n),n}else if(!o){let t=typeof e==`string`?this._stringDecoder.decode(e,this._parseBuffer):this._utf8Decoder.decode(e,this._parseBuffer);if(n=this._parser.parse(this._parseBuffer,t))return this._preserveStack(r,i,t,0),this._logSlowResolvingAsync(n),n}(this._activeBuffer.x!==r||this._activeBuffer.y!==i)&&this._onCursorMove.fire();let s=this._dirtyRowTracker.end+(this._bufferService.buffer.ybase-this._bufferService.buffer.ydisp),c=this._dirtyRowTracker.start+(this._bufferService.buffer.ybase-this._bufferService.buffer.ydisp);c<this._bufferService.rows&&this._onRequestRefreshRows.fire({start:Math.min(c,this._bufferService.rows-1),end:Math.min(s,this._bufferService.rows-1)})}print(e,t,n){let r,i,a=this._charsetService.charset,o=this._optionsService.rawOptions.screenReaderMode,s=this._bufferService.cols,c=this._coreService.decPrivateModes.wraparound,l=this._coreService.modes.insertMode,u=this._curAttrData,d=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y);this._dirtyRowTracker.markDirty(this._activeBuffer.y),this._activeBuffer.x&&n-t>0&&d.getWidth(this._activeBuffer.x-1)===2&&d.setCellFromCodepoint(this._activeBuffer.x-1,0,1,u);let f=this._parser.precedingJoinState;for(let p=t;p<n;++p){if(r=e[p],r<127&&a){let e=a[String.fromCharCode(r)];e&&(r=e.charCodeAt(0))}let t=this._unicodeService.charProperties(r,f);i=KQ.extractWidth(t);let n=KQ.extractShouldJoin(t),m=n?KQ.extractWidth(f):0;if(f=t,o&&this._onA11yChar.fire(vK(r)),this._getCurrentLinkId()&&this._oscLinkService.addLineToLink(this._getCurrentLinkId(),this._activeBuffer.ybase+this._activeBuffer.y),this._activeBuffer.x+i-m>s){if(c){let e=d,t=this._activeBuffer.x-m;for(this._activeBuffer.x=m,this._activeBuffer.y++,this._activeBuffer.y===this._activeBuffer.scrollBottom+1?(this._activeBuffer.y--,this._bufferService.scroll(this._eraseAttrData(),!0)):(this._activeBuffer.y>=this._bufferService.rows&&(this._activeBuffer.y=this._bufferService.rows-1),this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y).isWrapped=!0),d=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y),m>0&&d instanceof fQ&&d.copyCellsFrom(e,t,0,m,!1);t<s;)e.setCellFromCodepoint(t++,0,1,u)}else if(this._activeBuffer.x=s-1,i===2)continue}if(n&&this._activeBuffer.x){let e=d.getWidth(this._activeBuffer.x-1)?1:2;d.addCodepointToCell(this._activeBuffer.x-e,r,i);for(let e=i-m;--e>=0;)d.setCellFromCodepoint(this._activeBuffer.x++,0,0,u)}else if(l&&(d.insertCells(this._activeBuffer.x,i-m,this._activeBuffer.getNullCell(u)),d.getWidth(s-1)===2&&d.setCellFromCodepoint(s-1,0,1,u)),d.setCellFromCodepoint(this._activeBuffer.x++,r,i,u),i>0)for(;--i;)d.setCellFromCodepoint(this._activeBuffer.x++,0,0,u)}this._parser.precedingJoinState=f,this._activeBuffer.x<s&&n-t>0&&d.getWidth(this._activeBuffer.x)===0&&!d.hasContent(this._activeBuffer.x)&&d.setCellFromCodepoint(this._activeBuffer.x,0,1,u),this._dirtyRowTracker.markDirty(this._activeBuffer.y)}registerCsiHandler(e,t){return e.final===`t`&&!e.prefix&&!e.intermediates?this._parser.registerCsiHandler(e,e=>!_$(e.params[0],this._optionsService.rawOptions.windowOptions)||t(e)):this._parser.registerCsiHandler(e,t)}registerDcsHandler(e,t){return this._parser.registerDcsHandler(e,new i$(t))}registerEscHandler(e,t){return this._parser.registerEscHandler(e,t)}registerOscHandler(e,t){return this._parser.registerOscHandler(e,new e$(t))}bell(){return this._onRequestBell.fire(),!0}lineFeed(){return this._dirtyRowTracker.markDirty(this._activeBuffer.y),this._optionsService.rawOptions.convertEol&&(this._activeBuffer.x=0),this._activeBuffer.y++,this._activeBuffer.y===this._activeBuffer.scrollBottom+1?(this._activeBuffer.y--,this._bufferService.scroll(this._eraseAttrData())):this._activeBuffer.y>=this._bufferService.rows?this._activeBuffer.y=this._bufferService.rows-1:this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y).isWrapped=!1,this._activeBuffer.x>=this._bufferService.cols&&this._activeBuffer.x--,this._dirtyRowTracker.markDirty(this._activeBuffer.y),this._onLineFeed.fire(),!0}carriageReturn(){return this._activeBuffer.x=0,!0}backspace(){if(!this._coreService.decPrivateModes.reverseWraparound)return this._restrictCursor(),this._activeBuffer.x>0&&this._activeBuffer.x--,!0;if(this._restrictCursor(this._bufferService.cols),this._activeBuffer.x>0)this._activeBuffer.x--;else if(this._activeBuffer.x===0&&this._activeBuffer.y>this._activeBuffer.scrollTop&&this._activeBuffer.y<=this._activeBuffer.scrollBottom&&this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y)?.isWrapped){this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y).isWrapped=!1,this._activeBuffer.y--,this._activeBuffer.x=this._bufferService.cols-1;let e=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y);e.hasWidth(this._activeBuffer.x)&&!e.hasContent(this._activeBuffer.x)&&this._activeBuffer.x--}return this._restrictCursor(),!0}tab(){if(this._activeBuffer.x>=this._bufferService.cols)return!0;let e=this._activeBuffer.x;return this._activeBuffer.x=this._activeBuffer.nextStop(),this._optionsService.rawOptions.screenReaderMode&&this._onA11yTab.fire(this._activeBuffer.x-e),!0}shiftOut(){return this._charsetService.setgLevel(1),!0}shiftIn(){return this._charsetService.setgLevel(0),!0}_restrictCursor(e=this._bufferService.cols-1){this._activeBuffer.x=Math.min(e,Math.max(0,this._activeBuffer.x)),this._activeBuffer.y=this._coreService.decPrivateModes.origin?Math.min(this._activeBuffer.scrollBottom,Math.max(this._activeBuffer.scrollTop,this._activeBuffer.y)):Math.min(this._bufferService.rows-1,Math.max(0,this._activeBuffer.y)),this._dirtyRowTracker.markDirty(this._activeBuffer.y)}_setCursor(e,t){this._dirtyRowTracker.markDirty(this._activeBuffer.y),this._coreService.decPrivateModes.origin?(this._activeBuffer.x=e,this._activeBuffer.y=this._activeBuffer.scrollTop+t):(this._activeBuffer.x=e,this._activeBuffer.y=t),this._restrictCursor(),this._dirtyRowTracker.markDirty(this._activeBuffer.y)}_moveCursor(e,t){this._restrictCursor(),this._setCursor(this._activeBuffer.x+e,this._activeBuffer.y+t)}cursorUp(e){let t=this._activeBuffer.y-this._activeBuffer.scrollTop;return t>=0?this._moveCursor(0,-Math.min(t,e.params[0]||1)):this._moveCursor(0,-(e.params[0]||1)),!0}cursorDown(e){let t=this._activeBuffer.scrollBottom-this._activeBuffer.y;return t>=0?this._moveCursor(0,Math.min(t,e.params[0]||1)):this._moveCursor(0,e.params[0]||1),!0}cursorForward(e){return this._moveCursor(e.params[0]||1,0),!0}cursorBackward(e){return this._moveCursor(-(e.params[0]||1),0),!0}cursorNextLine(e){return this.cursorDown(e),this._activeBuffer.x=0,!0}cursorPrecedingLine(e){return this.cursorUp(e),this._activeBuffer.x=0,!0}cursorCharAbsolute(e){return this._setCursor((e.params[0]||1)-1,this._activeBuffer.y),!0}cursorPosition(e){return this._setCursor(e.length>=2?(e.params[1]||1)-1:0,(e.params[0]||1)-1),!0}charPosAbsolute(e){return this._setCursor((e.params[0]||1)-1,this._activeBuffer.y),!0}hPositionRelative(e){return this._moveCursor(e.params[0]||1,0),!0}linePosAbsolute(e){return this._setCursor(this._activeBuffer.x,(e.params[0]||1)-1),!0}vPositionRelative(e){return this._moveCursor(0,e.params[0]||1),!0}hVPosition(e){return this.cursorPosition(e),!0}tabClear(e){let t=e.params[0];return t===0?delete this._activeBuffer.tabs[this._activeBuffer.x]:t===3&&(this._activeBuffer.tabs={}),!0}cursorForwardTab(e){if(this._activeBuffer.x>=this._bufferService.cols)return!0;let t=e.params[0]||1;for(;t--;)this._activeBuffer.x=this._activeBuffer.nextStop();return!0}cursorBackwardTab(e){if(this._activeBuffer.x>=this._bufferService.cols)return!0;let t=e.params[0]||1;for(;t--;)this._activeBuffer.x=this._activeBuffer.prevStop();return!0}selectProtected(e){let t=e.params[0];return t===1&&(this._curAttrData.bg|=536870912),(t===2||t===0)&&(this._curAttrData.bg&=-536870913),!0}_eraseInBufferLine(e,t,n,r=!1,i=!1){let a=this._activeBuffer.lines.get(this._activeBuffer.ybase+e);a.replaceCells(t,n,this._activeBuffer.getNullCell(this._eraseAttrData()),i),r&&(a.isWrapped=!1)}_resetBufferLine(e,t=!1){let n=this._activeBuffer.lines.get(this._activeBuffer.ybase+e);n&&(n.fill(this._activeBuffer.getNullCell(this._eraseAttrData()),t),this._bufferService.buffer.clearMarkers(this._activeBuffer.ybase+e),n.isWrapped=!1)}eraseInDisplay(e,t=!1){this._restrictCursor(this._bufferService.cols);let n;switch(e.params[0]){case 0:for(n=this._activeBuffer.y,this._dirtyRowTracker.markDirty(n),this._eraseInBufferLine(n++,this._activeBuffer.x,this._bufferService.cols,this._activeBuffer.x===0,t);n<this._bufferService.rows;n++)this._resetBufferLine(n,t);this._dirtyRowTracker.markDirty(n);break;case 1:for(n=this._activeBuffer.y,this._dirtyRowTracker.markDirty(n),this._eraseInBufferLine(n,0,this._activeBuffer.x+1,!0,t),this._activeBuffer.x+1>=this._bufferService.cols&&(this._activeBuffer.lines.get(n+1).isWrapped=!1);n--;)this._resetBufferLine(n,t);this._dirtyRowTracker.markDirty(0);break;case 2:if(this._optionsService.rawOptions.scrollOnEraseInDisplay){for(n=this._bufferService.rows,this._dirtyRowTracker.markRangeDirty(0,n-1);n--&&!this._activeBuffer.lines.get(this._activeBuffer.ybase+n)?.getTrimmedLength(););for(;n>=0;n--)this._bufferService.scroll(this._eraseAttrData())}else{for(n=this._bufferService.rows,this._dirtyRowTracker.markDirty(n-1);n--;)this._resetBufferLine(n,t);this._dirtyRowTracker.markDirty(0)}break;case 3:let e=this._activeBuffer.lines.length-this._bufferService.rows;e>0&&(this._activeBuffer.lines.trimStart(e),this._activeBuffer.ybase=Math.max(this._activeBuffer.ybase-e,0),this._activeBuffer.ydisp=Math.max(this._activeBuffer.ydisp-e,0),this._onScroll.fire(0))}return!0}eraseInLine(e,t=!1){switch(this._restrictCursor(this._bufferService.cols),e.params[0]){case 0:this._eraseInBufferLine(this._activeBuffer.y,this._activeBuffer.x,this._bufferService.cols,this._activeBuffer.x===0,t);break;case 1:this._eraseInBufferLine(this._activeBuffer.y,0,this._activeBuffer.x+1,!1,t);break;case 2:this._eraseInBufferLine(this._activeBuffer.y,0,this._bufferService.cols,!0,t)}return this._dirtyRowTracker.markDirty(this._activeBuffer.y),!0}insertLines(e){this._restrictCursor();let t=e.params[0]||1;if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.y<this._activeBuffer.scrollTop)return!0;let n=this._activeBuffer.ybase+this._activeBuffer.y,r=this._bufferService.rows-1-this._activeBuffer.scrollBottom,i=this._bufferService.rows-1+this._activeBuffer.ybase-r+1;for(;t--;)this._activeBuffer.lines.splice(i-1,1),this._activeBuffer.lines.splice(n,0,this._activeBuffer.getBlankLine(this._eraseAttrData()));return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.y,this._activeBuffer.scrollBottom),this._activeBuffer.x=0,!0}deleteLines(e){this._restrictCursor();let t=e.params[0]||1;if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.y<this._activeBuffer.scrollTop)return!0;let n=this._activeBuffer.ybase+this._activeBuffer.y,r;for(r=this._bufferService.rows-1-this._activeBuffer.scrollBottom,r=this._bufferService.rows-1+this._activeBuffer.ybase-r;t--;)this._activeBuffer.lines.splice(n,1),this._activeBuffer.lines.splice(r,0,this._activeBuffer.getBlankLine(this._eraseAttrData()));return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.y,this._activeBuffer.scrollBottom),this._activeBuffer.x=0,!0}insertChars(e){this._restrictCursor();let t=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y);return t&&(t.insertCells(this._activeBuffer.x,e.params[0]||1,this._activeBuffer.getNullCell(this._eraseAttrData())),this._dirtyRowTracker.markDirty(this._activeBuffer.y)),!0}deleteChars(e){this._restrictCursor();let t=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y);return t&&(t.deleteCells(this._activeBuffer.x,e.params[0]||1,this._activeBuffer.getNullCell(this._eraseAttrData())),this._dirtyRowTracker.markDirty(this._activeBuffer.y)),!0}scrollUp(e){let t=e.params[0]||1;for(;t--;)this._activeBuffer.lines.splice(this._activeBuffer.ybase+this._activeBuffer.scrollTop,1),this._activeBuffer.lines.splice(this._activeBuffer.ybase+this._activeBuffer.scrollBottom,0,this._activeBuffer.getBlankLine(this._eraseAttrData()));return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom),!0}scrollDown(e){let t=e.params[0]||1;for(;t--;)this._activeBuffer.lines.splice(this._activeBuffer.ybase+this._activeBuffer.scrollBottom,1),this._activeBuffer.lines.splice(this._activeBuffer.ybase+this._activeBuffer.scrollTop,0,this._activeBuffer.getBlankLine(lQ));return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom),!0}scrollLeft(e){if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.y<this._activeBuffer.scrollTop)return!0;let t=e.params[0]||1;for(let e=this._activeBuffer.scrollTop;e<=this._activeBuffer.scrollBottom;++e){let n=this._activeBuffer.lines.get(this._activeBuffer.ybase+e);n.deleteCells(0,t,this._activeBuffer.getNullCell(this._eraseAttrData())),n.isWrapped=!1}return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom),!0}scrollRight(e){if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.y<this._activeBuffer.scrollTop)return!0;let t=e.params[0]||1;for(let e=this._activeBuffer.scrollTop;e<=this._activeBuffer.scrollBottom;++e){let n=this._activeBuffer.lines.get(this._activeBuffer.ybase+e);n.insertCells(0,t,this._activeBuffer.getNullCell(this._eraseAttrData())),n.isWrapped=!1}return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom),!0}insertColumns(e){if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.y<this._activeBuffer.scrollTop)return!0;let t=e.params[0]||1;for(let e=this._activeBuffer.scrollTop;e<=this._activeBuffer.scrollBottom;++e){let n=this._activeBuffer.lines.get(this._activeBuffer.ybase+e);n.insertCells(this._activeBuffer.x,t,this._activeBuffer.getNullCell(this._eraseAttrData())),n.isWrapped=!1}return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom),!0}deleteColumns(e){if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.y<this._activeBuffer.scrollTop)return!0;let t=e.params[0]||1;for(let e=this._activeBuffer.scrollTop;e<=this._activeBuffer.scrollBottom;++e){let n=this._activeBuffer.lines.get(this._activeBuffer.ybase+e);n.deleteCells(this._activeBuffer.x,t,this._activeBuffer.getNullCell(this._eraseAttrData())),n.isWrapped=!1}return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom),!0}eraseChars(e){this._restrictCursor();let t=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y);return t&&(t.replaceCells(this._activeBuffer.x,this._activeBuffer.x+(e.params[0]||1),this._activeBuffer.getNullCell(this._eraseAttrData())),this._dirtyRowTracker.markDirty(this._activeBuffer.y)),!0}repeatPrecedingCharacter(e){let t=this._parser.precedingJoinState;if(!t)return!0;let n=e.params[0]||1,r=KQ.extractWidth(t),i=this._activeBuffer.x-r,a=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y).getString(i),o=new Uint32Array(a.length*n),s=0;for(let e=0;e<a.length;){let t=a.codePointAt(e)||0;o[s++]=t,e+=t>65535?2:1}let c=s;for(let e=1;e<n;++e)o.copyWithin(c,0,s),c+=s;return this.print(o,0,c),!0}sendDeviceAttributesPrimary(e){return e.params[0]>0||(this._is(`xterm`)||this._is(`rxvt-unicode`)||this._is(`screen`)?this._coreService.triggerDataEvent($.ESC+`[?1;2c`):this._is(`linux`)&&this._coreService.triggerDataEvent($.ESC+`[?6c`)),!0}sendDeviceAttributesSecondary(e){return e.params[0]>0||(this._is(`xterm`)?this._coreService.triggerDataEvent($.ESC+`[>0;276;0c`):this._is(`rxvt-unicode`)?this._coreService.triggerDataEvent($.ESC+`[>85;95;0c`):this._is(`linux`)?this._coreService.triggerDataEvent(e.params[0]+`c`):this._is(`screen`)&&this._coreService.triggerDataEvent($.ESC+`[>83;40003;0c`)),!0}_is(e){return(this._optionsService.rawOptions.termName+``).indexOf(e)===0}setMode(e){for(let t=0;t<e.length;t++)switch(e.params[t]){case 4:this._coreService.modes.insertMode=!0;break;case 20:this._optionsService.options.convertEol=!0}return!0}setModePrivate(e){for(let t=0;t<e.length;t++)switch(e.params[t]){case 1:this._coreService.decPrivateModes.applicationCursorKeys=!0;break;case 2:this._charsetService.setgCharset(0,xQ),this._charsetService.setgCharset(1,xQ),this._charsetService.setgCharset(2,xQ),this._charsetService.setgCharset(3,xQ);break;case 3:this._optionsService.rawOptions.windowOptions.setWinLines&&(this._bufferService.resize(132,this._bufferService.rows),this._onRequestReset.fire());break;case 6:this._coreService.decPrivateModes.origin=!0,this._setCursor(0,0);break;case 7:this._coreService.decPrivateModes.wraparound=!0;break;case 12:this._optionsService.options.cursorBlink=!0;break;case 45:this._coreService.decPrivateModes.reverseWraparound=!0;break;case 66:this._logService.debug(`Serial port requested application keypad.`),this._coreService.decPrivateModes.applicationKeypad=!0,this._onRequestSyncScrollBar.fire();break;case 9:this._coreMouseService.activeProtocol=`X10`;break;case 1e3:this._coreMouseService.activeProtocol=`VT200`;break;case 1002:this._coreMouseService.activeProtocol=`DRAG`;break;case 1003:this._coreMouseService.activeProtocol=`ANY`;break;case 1004:this._coreService.decPrivateModes.sendFocus=!0,this._onRequestSendFocus.fire();break;case 1005:this._logService.debug(`DECSET 1005 not supported (see #2507)`);break;case 1006:this._coreMouseService.activeEncoding=`SGR`;break;case 1015:this._logService.debug(`DECSET 1015 not supported (see #2507)`);break;case 1016:this._coreMouseService.activeEncoding=`SGR_PIXELS`;break;case 25:this._coreService.isCursorHidden=!1;break;case 1048:this.saveCursor();break;case 1049:this.saveCursor();case 47:case 1047:this._bufferService.buffers.activateAltBuffer(this._eraseAttrData()),this._coreService.isCursorInitialized=!0,this._onRequestRefreshRows.fire(void 0),this._onRequestSyncScrollBar.fire();break;case 2004:this._coreService.decPrivateModes.bracketedPasteMode=!0;break;case 2026:this._coreService.decPrivateModes.synchronizedOutput=!0}return!0}resetMode(e){for(let t=0;t<e.length;t++)switch(e.params[t]){case 4:this._coreService.modes.insertMode=!1;break;case 20:this._optionsService.options.convertEol=!1}return!0}resetModePrivate(e){for(let t=0;t<e.length;t++)switch(e.params[t]){case 1:this._coreService.decPrivateModes.applicationCursorKeys=!1;break;case 3:this._optionsService.rawOptions.windowOptions.setWinLines&&(this._bufferService.resize(80,this._bufferService.rows),this._onRequestReset.fire());break;case 6:this._coreService.decPrivateModes.origin=!1,this._setCursor(0,0);break;case 7:this._coreService.decPrivateModes.wraparound=!1;break;case 12:this._optionsService.options.cursorBlink=!1;break;case 45:this._coreService.decPrivateModes.reverseWraparound=!1;break;case 66:this._logService.debug(`Switching back to normal keypad.`),this._coreService.decPrivateModes.applicationKeypad=!1,this._onRequestSyncScrollBar.fire();break;case 9:case 1e3:case 1002:case 1003:this._coreMouseService.activeProtocol=`NONE`;break;case 1004:this._coreService.decPrivateModes.sendFocus=!1;break;case 1005:this._logService.debug(`DECRST 1005 not supported (see #2507)`);break;case 1006:this._coreMouseService.activeEncoding=`DEFAULT`;break;case 1015:this._logService.debug(`DECRST 1015 not supported (see #2507)`);break;case 1016:this._coreMouseService.activeEncoding=`DEFAULT`;break;case 25:this._coreService.isCursorHidden=!0;break;case 1048:this.restoreCursor();break;case 1049:case 47:case 1047:this._bufferService.buffers.activateNormalBuffer(),e.params[t]===1049&&this.restoreCursor(),this._coreService.isCursorInitialized=!0,this._onRequestRefreshRows.fire(void 0),this._onRequestSyncScrollBar.fire();break;case 2004:this._coreService.decPrivateModes.bracketedPasteMode=!1;break;case 2026:this._coreService.decPrivateModes.synchronizedOutput=!1,this._onRequestRefreshRows.fire(void 0)}return!0}requestMode(e,t){let n;(e=>(e[e.NOT_RECOGNIZED=0]=`NOT_RECOGNIZED`,e[e.SET=1]=`SET`,e[e.RESET=2]=`RESET`,e[e.PERMANENTLY_SET=3]=`PERMANENTLY_SET`,e[e.PERMANENTLY_RESET=4]=`PERMANENTLY_RESET`))(n||={});let r=this._coreService.decPrivateModes,{activeProtocol:i,activeEncoding:a}=this._coreMouseService,o=this._coreService,{buffers:s,cols:c}=this._bufferService,{active:l,alt:u}=s,d=this._optionsService.rawOptions,f=(e,n)=>(o.triggerDataEvent(`${$.ESC}[${t?``:`?`}${e};${n}$y`),!0),p=e=>e?1:2,m=e.params[0];return t?m===2?f(m,4):m===4?f(m,p(o.modes.insertMode)):m===12?f(m,3):m===20?f(m,p(d.convertEol)):f(m,0):m===1?f(m,p(r.applicationCursorKeys)):m===3?f(m,d.windowOptions.setWinLines?c===80?2:+(c===132):0):m===6?f(m,p(r.origin)):m===7?f(m,p(r.wraparound)):m===8?f(m,3):m===9?f(m,p(i===`X10`)):m===12?f(m,p(d.cursorBlink)):m===25?f(m,p(!o.isCursorHidden)):m===45?f(m,p(r.reverseWraparound)):m===66?f(m,p(r.applicationKeypad)):m===67?f(m,4):m===1e3?f(m,p(i===`VT200`)):m===1002?f(m,p(i===`DRAG`)):m===1003?f(m,p(i===`ANY`)):m===1004?f(m,p(r.sendFocus)):m===1005?f(m,4):m===1006?f(m,p(a===`SGR`)):m===1015?f(m,4):m===1016?f(m,p(a===`SGR_PIXELS`)):m===1048?f(m,1):m===47||m===1047||m===1049?f(m,p(l===u)):m===2004?f(m,p(r.bracketedPasteMode)):m===2026?f(m,p(r.synchronizedOutput)):f(m,0)}_updateAttrColor(e,t,n,r,i){return t===2?(e|=50331648,e&=-16777216,e|=wK.fromColorRGB([n,r,i])):t===5&&(e&=-50331904,e|=33554432|n&255),e}_extractColor(e,t,n){let r=[0,0,-1,0,0,0],i=0,a=0;do{if(r[a+i]=e.params[t+a],e.hasSubParams(t+a)){let n=e.getSubParams(t+a),o=0;do r[1]===5&&(i=1),r[a+o+1+i]=n[o];while(++o<n.length&&o+a+1+i<r.length);break}if(r[1]===5&&a+i>=2||r[1]===2&&a+i>=5)break;r[1]&&(i=1)}while(++a+t<e.length&&a+i<r.length);for(let e=2;e<r.length;++e)r[e]===-1&&(r[e]=0);switch(r[0]){case 38:n.fg=this._updateAttrColor(n.fg,r[1],r[3],r[4],r[5]);break;case 48:n.bg=this._updateAttrColor(n.bg,r[1],r[3],r[4],r[5]);break;case 58:n.extended=n.extended.clone(),n.extended.underlineColor=this._updateAttrColor(n.extended.underlineColor,r[1],r[3],r[4],r[5])}return a}_processUnderline(e,t){t.extended=t.extended.clone(),(!~e||e>5)&&(e=1),t.extended.underlineStyle=e,t.fg|=268435456,e===0&&(t.fg&=-268435457),t.updateExtended()}_processSGR0(e){e.fg=lQ.fg,e.bg=lQ.bg,e.extended=e.extended.clone(),e.extended.underlineStyle=0,e.extended.underlineColor&=-67108864,e.updateExtended()}charAttributes(e){if(e.length===1&&e.params[0]===0)return this._processSGR0(this._curAttrData),!0;let t=e.length,n,r=this._curAttrData;for(let i=0;i<t;i++)n=e.params[i],n>=30&&n<=37?(r.fg&=-50331904,r.fg|=16777216|n-30):n>=40&&n<=47?(r.bg&=-50331904,r.bg|=16777216|n-40):n>=90&&n<=97?(r.fg&=-50331904,r.fg|=n-90|16777224):n>=100&&n<=107?(r.bg&=-50331904,r.bg|=n-100|16777224):n===0?this._processSGR0(r):n===1?r.fg|=134217728:n===3?r.bg|=67108864:n===4?(r.fg|=268435456,this._processUnderline(e.hasSubParams(i)?e.getSubParams(i)[0]:1,r)):n===5?r.fg|=536870912:n===7?r.fg|=67108864:n===8?r.fg|=1073741824:n===9?r.fg|=2147483648:n===2?r.bg|=134217728:n===21?this._processUnderline(2,r):n===22?(r.fg&=-134217729,r.bg&=-134217729):n===23?r.bg&=-67108865:n===24?(r.fg&=-268435457,this._processUnderline(0,r)):n===25?r.fg&=-536870913:n===27?r.fg&=-67108865:n===28?r.fg&=-1073741825:n===29?r.fg&=2147483647:n===39?(r.fg&=-67108864,r.fg|=lQ.fg&16777215):n===49?(r.bg&=-67108864,r.bg|=lQ.bg&16777215):n===38||n===48||n===58?i+=this._extractColor(e,i,r):n===53?r.bg|=1073741824:n===55?r.bg&=-1073741825:n===59?(r.extended=r.extended.clone(),r.extended.underlineColor=-1,r.updateExtended()):n===100?(r.fg&=-67108864,r.fg|=lQ.fg&16777215,r.bg&=-67108864,r.bg|=lQ.bg&16777215):this._logService.debug(`Unknown SGR attribute: %d.`,n);return!0}deviceStatus(e){switch(e.params[0]){case 5:this._coreService.triggerDataEvent(`${$.ESC}[0n`);break;case 6:let e=this._activeBuffer.y+1,t=this._activeBuffer.x+1;this._coreService.triggerDataEvent(`${$.ESC}[${e};${t}R`)}return!0}deviceStatusPrivate(e){if(e.params[0]===6){let e=this._activeBuffer.y+1,t=this._activeBuffer.x+1;this._coreService.triggerDataEvent(`${$.ESC}[?${e};${t}R`)}return!0}softReset(e){return this._coreService.isCursorHidden=!1,this._onRequestSyncScrollBar.fire(),this._activeBuffer.scrollTop=0,this._activeBuffer.scrollBottom=this._bufferService.rows-1,this._curAttrData=lQ.clone(),this._coreService.reset(),this._charsetService.reset(),this._activeBuffer.savedX=0,this._activeBuffer.savedY=this._activeBuffer.ybase,this._activeBuffer.savedCurAttrData.fg=this._curAttrData.fg,this._activeBuffer.savedCurAttrData.bg=this._curAttrData.bg,this._activeBuffer.savedCharset=this._charsetService.charset,this._coreService.decPrivateModes.origin=!1,!0}setCursorStyle(e){let t=e.length===0?1:e.params[0];if(t===0)this._coreService.decPrivateModes.cursorStyle=void 0,this._coreService.decPrivateModes.cursorBlink=void 0;else{switch(t){case 1:case 2:this._coreService.decPrivateModes.cursorStyle=`block`;break;case 3:case 4:this._coreService.decPrivateModes.cursorStyle=`underline`;break;case 5:case 6:this._coreService.decPrivateModes.cursorStyle=`bar`}let e=t%2==1;this._coreService.decPrivateModes.cursorBlink=e}return!0}setScrollRegion(e){let t=e.params[0]||1,n;return(e.length<2||(n=e.params[1])>this._bufferService.rows||n===0)&&(n=this._bufferService.rows),n>t&&(this._activeBuffer.scrollTop=t-1,this._activeBuffer.scrollBottom=n-1,this._setCursor(0,0)),!0}windowOptions(e){if(!_$(e.params[0],this._optionsService.rawOptions.windowOptions))return!0;let t=e.length>1?e.params[1]:0;switch(e.params[0]){case 14:t!==2&&this._onRequestWindowsOptionsReport.fire(0);break;case 16:this._onRequestWindowsOptionsReport.fire(1);break;case 18:this._bufferService&&this._coreService.triggerDataEvent(`${$.ESC}[8;${this._bufferService.rows};${this._bufferService.cols}t`);break;case 22:(t===0||t===2)&&(this._windowTitleStack.push(this._windowTitle),this._windowTitleStack.length>g$&&this._windowTitleStack.shift()),(t===0||t===1)&&(this._iconNameStack.push(this._iconName),this._iconNameStack.length>g$&&this._iconNameStack.shift());break;case 23:(t===0||t===2)&&this._windowTitleStack.length&&this.setTitle(this._windowTitleStack.pop()),(t===0||t===1)&&this._iconNameStack.length&&this.setIconName(this._iconNameStack.pop())}return!0}saveCursor(e){return this._activeBuffer.savedX=this._activeBuffer.x,this._activeBuffer.savedY=this._activeBuffer.ybase+this._activeBuffer.y,this._activeBuffer.savedCurAttrData.fg=this._curAttrData.fg,this._activeBuffer.savedCurAttrData.bg=this._curAttrData.bg,this._activeBuffer.savedCharset=this._charsetService.charset,!0}restoreCursor(e){return this._activeBuffer.x=this._activeBuffer.savedX||0,this._activeBuffer.y=Math.max(this._activeBuffer.savedY-this._activeBuffer.ybase,0),this._curAttrData.fg=this._activeBuffer.savedCurAttrData.fg,this._curAttrData.bg=this._activeBuffer.savedCurAttrData.bg,this._charsetService.charset=this._savedCharset,this._activeBuffer.savedCharset&&(this._charsetService.charset=this._activeBuffer.savedCharset),this._restrictCursor(),!0}setTitle(e){return this._windowTitle=e,this._onTitleChange.fire(e),!0}setIconName(e){return this._iconName=e,!0}setOrReportIndexedColor(e){let t=[],n=e.split(`;`);for(;n.length>1;){let e=n.shift(),r=n.shift();if(/^\d+$/.exec(e)){let n=parseInt(e);if(S$(n)){if(r===`?`)t.push({type:0,index:n});else{let e=d$(r);e&&t.push({type:1,index:n,color:e})}}}}return t.length&&this._onColor.fire(t),!0}setHyperlink(e){let t=e.indexOf(`;`);if(t===-1)return!0;let n=e.slice(0,t).trim(),r=e.slice(t+1);return r?this._createHyperlink(n,r):!n.trim()&&this._finishHyperlink()}_createHyperlink(e,t){this._getCurrentLinkId()&&this._finishHyperlink();let n=e.split(`:`),r,i=n.findIndex(e=>e.startsWith(`id=`));return i!==-1&&(r=n[i].slice(3)||void 0),this._curAttrData.extended=this._curAttrData.extended.clone(),this._curAttrData.extended.urlId=this._oscLinkService.registerLink({id:r,uri:t}),this._curAttrData.updateExtended(),!0}_finishHyperlink(){return this._curAttrData.extended=this._curAttrData.extended.clone(),this._curAttrData.extended.urlId=0,this._curAttrData.updateExtended(),!0}_setOrReportSpecialColor(e,t){let n=e.split(`;`);for(let e=0;e<n.length&&!(t>=this._specialColors.length);++e,++t)if(n[e]===`?`)this._onColor.fire([{type:0,index:this._specialColors[t]}]);else{let r=d$(n[e]);r&&this._onColor.fire([{type:1,index:this._specialColors[t],color:r}])}return!0}setOrReportFgColor(e){return this._setOrReportSpecialColor(e,0)}setOrReportBgColor(e){return this._setOrReportSpecialColor(e,1)}setOrReportCursorColor(e){return this._setOrReportSpecialColor(e,2)}restoreIndexedColor(e){if(!e)return this._onColor.fire([{type:2}]),!0;let t=[],n=e.split(`;`);for(let e=0;e<n.length;++e)if(/^\d+$/.exec(n[e])){let r=parseInt(n[e]);S$(r)&&t.push({type:2,index:r})}return t.length&&this._onColor.fire(t),!0}restoreFgColor(e){return this._onColor.fire([{type:2,index:256}]),!0}restoreBgColor(e){return this._onColor.fire([{type:2,index:257}]),!0}restoreCursorColor(e){return this._onColor.fire([{type:2,index:258}]),!0}nextLine(){return this._activeBuffer.x=0,this.index(),!0}keypadApplicationMode(){return this._logService.debug(`Serial port requested application keypad.`),this._coreService.decPrivateModes.applicationKeypad=!0,this._onRequestSyncScrollBar.fire(),!0}keypadNumericMode(){return this._logService.debug(`Switching back to normal keypad.`),this._coreService.decPrivateModes.applicationKeypad=!1,this._onRequestSyncScrollBar.fire(),!0}selectDefaultCharset(){return this._charsetService.setgLevel(0),this._charsetService.setgCharset(0,xQ),!0}selectCharset(e){return e.length===2?(e[0]===`/`||this._charsetService.setgCharset(m$[e[0]],bQ[e[1]]||xQ),!0):(this.selectDefaultCharset(),!0)}index(){return this._restrictCursor(),this._activeBuffer.y++,this._activeBuffer.y===this._activeBuffer.scrollBottom+1?(this._activeBuffer.y--,this._bufferService.scroll(this._eraseAttrData())):this._activeBuffer.y>=this._bufferService.rows&&(this._activeBuffer.y=this._bufferService.rows-1),this._restrictCursor(),!0}tabSet(){return this._activeBuffer.tabs[this._activeBuffer.x]=!0,!0}reverseIndex(){if(this._restrictCursor(),this._activeBuffer.y===this._activeBuffer.scrollTop){let e=this._activeBuffer.scrollBottom-this._activeBuffer.scrollTop;this._activeBuffer.lines.shiftElements(this._activeBuffer.ybase+this._activeBuffer.y,e,1),this._activeBuffer.lines.set(this._activeBuffer.ybase+this._activeBuffer.y,this._activeBuffer.getBlankLine(this._eraseAttrData())),this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom)}else this._activeBuffer.y--,this._restrictCursor();return!0}fullReset(){return this._parser.reset(),this._onRequestReset.fire(),!0}reset(){this._curAttrData=lQ.clone(),this._eraseAttrDataInternal=lQ.clone()}_eraseAttrData(){return this._eraseAttrDataInternal.bg&=-67108864,this._eraseAttrDataInternal.bg|=this._curAttrData.bg&67108863,this._eraseAttrDataInternal}setgLevel(e){return this._charsetService.setgLevel(e),!0}screenAlignmentPattern(){let e=new EK;e.content=4194373,e.fg=this._curAttrData.fg,e.bg=this._curAttrData.bg,this._setCursor(0,0);for(let t=0;t<this._bufferService.rows;++t){let n=this._activeBuffer.ybase+this._activeBuffer.y+t,r=this._activeBuffer.lines.get(n);r&&(r.fill(e),r.isWrapped=!1)}return this._dirtyRowTracker.markAllDirty(),this._setCursor(0,0),!0}requestStatusString(e,t){let n=e=>(this._coreService.triggerDataEvent(`${$.ESC}${e}${$.ESC}\\`),!0),r=this._bufferService.buffer,i=this._optionsService.rawOptions;return n(e===`"q`?`P1$r${+!!this._curAttrData.isProtected()}"q`:e===`"p`?`P1$r61;1"p`:e===`r`?`P1$r${r.scrollTop+1};${r.scrollBottom+1}r`:e===`m`?`P1$r0m`:e===` q`?`P1$r${{block:2,underline:4,bar:6}[i.cursorStyle]-+!!i.cursorBlink} q`:`P0$r`)}markRangeDirty(e,t){this._dirtyRowTracker.markRangeDirty(e,t)}},x$=class{constructor(e){this._bufferService=e,this.clearRange()}clearRange(){this.start=this._bufferService.buffer.y,this.end=this._bufferService.buffer.y}markDirty(e){e<this.start?this.start=e:e>this.end&&(this.end=e)}markRangeDirty(e,t){e>t&&(y$=e,e=t,t=y$),e<this.start&&(this.start=e),t>this.end&&(this.end=t)}markAllDirty(){this.markRangeDirty(0,this._bufferService.rows-1)}};x$=aK([oK(0,NK)],x$);function S$(e){return 0<=e&&e<256}var C$=5e7,w$=12,T$=50,E$=class extends Sq{constructor(e){super(),this._action=e,this._writeBuffer=[],this._callbacks=[],this._pendingData=0,this._bufferOffset=0,this._isSyncWriting=!1,this._syncCalls=0,this._didUserInput=!1,this._onWriteParsed=this._register(new Hq),this.onWriteParsed=this._onWriteParsed.event}handleUserInput(){this._didUserInput=!0}writeSync(e,t){if(t!==void 0&&this._syncCalls>t){this._syncCalls=0;return}if(this._pendingData+=e.length,this._writeBuffer.push(e),this._callbacks.push(void 0),this._syncCalls++,this._isSyncWriting)return;this._isSyncWriting=!0;let n;for(;n=this._writeBuffer.shift();){this._action(n);let e=this._callbacks.shift();e&&e()}this._pendingData=0,this._bufferOffset=2147483647,this._isSyncWriting=!1,this._syncCalls=0}write(e,t){if(this._pendingData>C$)throw Error(`write data discarded, use flow control to avoid losing data`);if(!this._writeBuffer.length){if(this._bufferOffset=0,this._didUserInput){this._didUserInput=!1,this._pendingData+=e.length,this._writeBuffer.push(e),this._callbacks.push(t),this._innerWrite();return}setTimeout(()=>this._innerWrite())}this._pendingData+=e.length,this._writeBuffer.push(e),this._callbacks.push(t)}_innerWrite(e=0,t=!0){let n=e||performance.now();for(;this._writeBuffer.length>this._bufferOffset;){let e=this._writeBuffer[this._bufferOffset],r=this._action(e,t);if(r){r.catch(e=>(queueMicrotask(()=>{throw e}),Promise.resolve(!1))).then(e=>performance.now()-n>=w$?setTimeout(()=>this._innerWrite(0,e)):this._innerWrite(n,e));return}let i=this._callbacks[this._bufferOffset];if(i&&i(),this._bufferOffset++,this._pendingData-=e.length,performance.now()-n>=w$)break}this._writeBuffer.length>this._bufferOffset?(this._bufferOffset>T$&&(this._writeBuffer=this._writeBuffer.slice(this._bufferOffset),this._callbacks=this._callbacks.slice(this._bufferOffset),this._bufferOffset=0),setTimeout(()=>this._innerWrite())):(this._writeBuffer.length=0,this._callbacks.length=0,this._pendingData=0,this._bufferOffset=0),this._onWriteParsed.fire()}},D$=class{constructor(e){this._bufferService=e,this._nextId=1,this._entriesWithId=new Map,this._dataByLinkId=new Map}registerLink(e){let t=this._bufferService.buffer;if(e.id===void 0){let n=t.addMarker(t.ybase+t.y),r={data:e,id:this._nextId++,lines:[n]};return n.onDispose(()=>this._removeMarkerFromLink(r,n)),this._dataByLinkId.set(r.id,r),r.id}let n=e,r=this._getEntryIdKey(n),i=this._entriesWithId.get(r);if(i)return this.addLineToLink(i.id,t.ybase+t.y),i.id;let a=t.addMarker(t.ybase+t.y),o={id:this._nextId++,key:this._getEntryIdKey(n),data:n,lines:[a]};return a.onDispose(()=>this._removeMarkerFromLink(o,a)),this._entriesWithId.set(o.key,o),this._dataByLinkId.set(o.id,o),o.id}addLineToLink(e,t){let n=this._dataByLinkId.get(e);if(n&&n.lines.every(e=>e.line!==t)){let e=this._bufferService.buffer.addMarker(t);n.lines.push(e),e.onDispose(()=>this._removeMarkerFromLink(n,e))}}getLinkData(e){return this._dataByLinkId.get(e)?.data}_getEntryIdKey(e){return`${e.id};;${e.uri}`}_removeMarkerFromLink(e,t){let n=e.lines.indexOf(t);n!==-1&&(e.lines.splice(n,1),e.lines.length===0&&(e.data.id!==void 0&&this._entriesWithId.delete(e.key),this._dataByLinkId.delete(e.id)))}};D$=aK([oK(0,NK)],D$);var O$=!1,k$=class extends Sq{constructor(e){super(),this._windowsWrappingHeuristics=this._register(new Cq),this._onBinary=this._register(new Hq),this.onBinary=this._onBinary.event,this._onData=this._register(new Hq),this.onData=this._onData.event,this._onLineFeed=this._register(new Hq),this.onLineFeed=this._onLineFeed.event,this._onResize=this._register(new Hq),this.onResize=this._onResize.event,this._onWriteParsed=this._register(new Hq),this.onWriteParsed=this._onWriteParsed.event,this._onScroll=this._register(new Hq),this._instantiationService=new nQ,this.optionsService=this._register(new AQ(e)),this._instantiationService.setService(zK,this.optionsService),this._bufferService=this._register(this._instantiationService.createInstance(DQ)),this._instantiationService.setService(NK,this._bufferService),this._logService=this._register(this._instantiationService.createInstance(aQ)),this._instantiationService.setService(RK,this._logService),this.coreService=this._register(this._instantiationService.createInstance(FQ)),this._instantiationService.setService(FK,this.coreService),this.coreMouseService=this._register(this._instantiationService.createInstance(BQ)),this._instantiationService.setService(PK,this.coreMouseService),this.unicodeService=this._register(this._instantiationService.createInstance(KQ)),this._instantiationService.setService(VK,this.unicodeService),this._charsetService=this._instantiationService.createInstance(qQ),this._instantiationService.setService(IK,this._charsetService),this._oscLinkService=this._instantiationService.createInstance(D$),this._instantiationService.setService(BK,this._oscLinkService),this._inputHandler=this._register(new b$(this._bufferService,this._charsetService,this.coreService,this._logService,this.optionsService,this._oscLinkService,this.coreMouseService,this.unicodeService)),this._register(Aq.forward(this._inputHandler.onLineFeed,this._onLineFeed)),this._register(this._inputHandler),this._register(Aq.forward(this._bufferService.onResize,this._onResize)),this._register(Aq.forward(this.coreService.onData,this._onData)),this._register(Aq.forward(this.coreService.onBinary,this._onBinary)),this._register(this.coreService.onRequestScrollToBottom(()=>this.scrollToBottom(!0))),this._register(this.coreService.onUserInput(()=>this._writeBuffer.handleUserInput())),this._register(this.optionsService.onMultipleOptionChange([`windowsMode`,`windowsPty`],()=>this._handleWindowsPtyOptionChange())),this._register(this._bufferService.onScroll(()=>{this._onScroll.fire({position:this._bufferService.buffer.ydisp}),this._inputHandler.markRangeDirty(this._bufferService.buffer.scrollTop,this._bufferService.buffer.scrollBottom)})),this._writeBuffer=this._register(new E$((e,t)=>this._inputHandler.parse(e,t))),this._register(Aq.forward(this._writeBuffer.onWriteParsed,this._onWriteParsed))}get onScroll(){return this._onScrollApi||(this._onScrollApi=this._register(new Hq),this._onScroll.event(e=>{this._onScrollApi?.fire(e.position)})),this._onScrollApi.event}get cols(){return this._bufferService.cols}get rows(){return this._bufferService.rows}get buffers(){return this._bufferService.buffers}get options(){return this.optionsService.options}set options(e){for(let t in e)this.optionsService.options[t]=e[t]}write(e,t){this._writeBuffer.write(e,t)}writeSync(e,t){this._logService.logLevel<=3&&!O$&&(this._logService.warn(`writeSync is unreliable and will be removed soon.`),O$=!0),this._writeBuffer.writeSync(e,t)}input(e,t=!0){this.coreService.triggerDataEvent(e,t)}resize(e,t){isNaN(e)||isNaN(t)||(e=Math.max(e,TQ),t=Math.max(t,EQ),this._bufferService.resize(e,t))}scroll(e,t=!1){this._bufferService.scroll(e,t)}scrollLines(e,t){this._bufferService.scrollLines(e,t)}scrollPages(e){this.scrollLines(e*(this.rows-1))}scrollToTop(){this.scrollLines(-this._bufferService.buffer.ydisp)}scrollToBottom(e){this.scrollLines(this._bufferService.buffer.ybase-this._bufferService.buffer.ydisp)}scrollToLine(e){let t=e-this._bufferService.buffer.ydisp;t!==0&&this.scrollLines(t)}registerEscHandler(e,t){return this._inputHandler.registerEscHandler(e,t)}registerDcsHandler(e,t){return this._inputHandler.registerDcsHandler(e,t)}registerCsiHandler(e,t){return this._inputHandler.registerCsiHandler(e,t)}registerOscHandler(e,t){return this._inputHandler.registerOscHandler(e,t)}_setup(){this._handleWindowsPtyOptionChange()}reset(){this._inputHandler.reset(),this._bufferService.reset(),this._charsetService.reset(),this.coreService.reset(),this.coreMouseService.reset()}_handleWindowsPtyOptionChange(){let e=!1,t=this.optionsService.rawOptions.windowsPty;t&&t.buildNumber!==void 0&&t.buildNumber!==void 0?e=t.backend===`conpty`&&t.buildNumber<21376:this.optionsService.rawOptions.windowsMode&&(e=!0),e?this._enableWindowsWrappingHeuristics():this._windowsWrappingHeuristics.clear()}_enableWindowsWrappingHeuristics(){if(!this._windowsWrappingHeuristics.value){let e=[];e.push(this.onLineFeed(JQ.bind(null,this._bufferService))),e.push(this.registerCsiHandler({final:`H`},()=>(JQ(this._bufferService),!1))),this._windowsWrappingHeuristics.value=yq(()=>{for(let t of e)t.dispose()})}}},A$={48:[`0`,`)`],49:[`1`,`!`],50:[`2`,`@`],51:[`3`,`#`],52:[`4`,`$`],53:[`5`,`%`],54:[`6`,`^`],55:[`7`,`&`],56:[`8`,`*`],57:[`9`,`(`],186:[`;`,`:`],187:[`=`,`+`],188:[`,`,`<`],189:[`-`,`_`],190:[`.`,`>`],191:[`/`,`?`],192:["`",`~`],219:[`[`,`{`],220:[`\\`,`|`],221:[`]`,`}`],222:[`'`,`"`]};function j$(e,t,n,r){let i={type:0,cancel:!1,key:void 0},a=+!!e.shiftKey|(e.altKey?2:0)|(e.ctrlKey?4:0)|(e.metaKey?8:0);switch(e.keyCode){case 0:e.key===`UIKeyInputUpArrow`?i.key=t?$.ESC+`OA`:$.ESC+`[A`:e.key===`UIKeyInputLeftArrow`?i.key=t?$.ESC+`OD`:$.ESC+`[D`:e.key===`UIKeyInputRightArrow`?i.key=t?$.ESC+`OC`:$.ESC+`[C`:e.key===`UIKeyInputDownArrow`&&(i.key=t?$.ESC+`OB`:$.ESC+`[B`);break;case 8:i.key=e.ctrlKey?`\b`:$.DEL,e.altKey&&(i.key=$.ESC+i.key);break;case 9:if(e.shiftKey){i.key=$.ESC+`[Z`;break}i.key=$.HT,i.cancel=!0;break;case 13:i.key=e.altKey?$.ESC+$.CR:$.CR,i.cancel=!0;break;case 27:i.key=$.ESC,e.altKey&&(i.key=$.ESC+$.ESC),i.cancel=!0;break;case 37:if(e.metaKey)break;i.key=a?$.ESC+`[1;`+(a+1)+`D`:t?$.ESC+`OD`:$.ESC+`[D`;break;case 39:if(e.metaKey)break;i.key=a?$.ESC+`[1;`+(a+1)+`C`:t?$.ESC+`OC`:$.ESC+`[C`;break;case 38:if(e.metaKey)break;i.key=a?$.ESC+`[1;`+(a+1)+`A`:t?$.ESC+`OA`:$.ESC+`[A`;break;case 40:if(e.metaKey)break;i.key=a?$.ESC+`[1;`+(a+1)+`B`:t?$.ESC+`OB`:$.ESC+`[B`;break;case 45:!e.shiftKey&&!e.ctrlKey&&(i.key=$.ESC+`[2~`);break;case 46:i.key=a?$.ESC+`[3;`+(a+1)+`~`:$.ESC+`[3~`;break;case 36:i.key=a?$.ESC+`[1;`+(a+1)+`H`:t?$.ESC+`OH`:$.ESC+`[H`;break;case 35:i.key=a?$.ESC+`[1;`+(a+1)+`F`:t?$.ESC+`OF`:$.ESC+`[F`;break;case 33:e.shiftKey?i.type=2:i.key=e.ctrlKey?$.ESC+`[5;`+(a+1)+`~`:$.ESC+`[5~`;break;case 34:e.shiftKey?i.type=3:i.key=e.ctrlKey?$.ESC+`[6;`+(a+1)+`~`:$.ESC+`[6~`;break;case 112:i.key=a?$.ESC+`[1;`+(a+1)+`P`:$.ESC+`OP`;break;case 113:i.key=a?$.ESC+`[1;`+(a+1)+`Q`:$.ESC+`OQ`;break;case 114:i.key=a?$.ESC+`[1;`+(a+1)+`R`:$.ESC+`OR`;break;case 115:i.key=a?$.ESC+`[1;`+(a+1)+`S`:$.ESC+`OS`;break;case 116:i.key=a?$.ESC+`[15;`+(a+1)+`~`:$.ESC+`[15~`;break;case 117:i.key=a?$.ESC+`[17;`+(a+1)+`~`:$.ESC+`[17~`;break;case 118:i.key=a?$.ESC+`[18;`+(a+1)+`~`:$.ESC+`[18~`;break;case 119:i.key=a?$.ESC+`[19;`+(a+1)+`~`:$.ESC+`[19~`;break;case 120:i.key=a?$.ESC+`[20;`+(a+1)+`~`:$.ESC+`[20~`;break;case 121:i.key=a?$.ESC+`[21;`+(a+1)+`~`:$.ESC+`[21~`;break;case 122:i.key=a?$.ESC+`[23;`+(a+1)+`~`:$.ESC+`[23~`;break;case 123:i.key=a?$.ESC+`[24;`+(a+1)+`~`:$.ESC+`[24~`;break;default:if(e.ctrlKey&&!e.shiftKey&&!e.altKey&&!e.metaKey)e.keyCode>=65&&e.keyCode<=90?i.key=String.fromCharCode(e.keyCode-64):e.keyCode===32?i.key=$.NUL:e.keyCode>=51&&e.keyCode<=55?i.key=String.fromCharCode(e.keyCode-51+27):e.keyCode===56?i.key=$.DEL:e.keyCode===219?i.key=$.ESC:e.keyCode===220?i.key=$.FS:e.keyCode===221&&(i.key=$.GS);else if((!n||r)&&e.altKey&&!e.metaKey){let t=A$[e.keyCode]?.[+!!e.shiftKey];if(t)i.key=$.ESC+t;else if(e.keyCode>=65&&e.keyCode<=90){let t=e.ctrlKey?e.keyCode-64:e.keyCode+32,n=String.fromCharCode(t);e.shiftKey&&(n=n.toUpperCase()),i.key=$.ESC+n}else if(e.keyCode===32)i.key=$.ESC+(e.ctrlKey?$.NUL:` `);else if(e.key===`Dead`&&e.code.startsWith(`Key`)){let t=e.code.slice(3,4);e.shiftKey||(t=t.toLowerCase()),i.key=$.ESC+t,i.cancel=!0}}else n&&!e.altKey&&!e.ctrlKey&&!e.shiftKey&&e.metaKey?e.keyCode===65&&(i.type=1):e.key&&!e.ctrlKey&&!e.altKey&&!e.metaKey&&e.keyCode>=48&&e.key.length===1?i.key=e.key:e.key&&e.ctrlKey&&(e.key===`_`&&(i.key=$.US),e.key===`@`&&(i.key=$.NUL))}return i}var M$=0,N$=class{constructor(e){this._getKey=e,this._array=[],this._insertedValues=[],this._flushInsertedTask=new yZ,this._isFlushingInserted=!1,this._deletedIndices=[],this._flushDeletedTask=new yZ,this._isFlushingDeleted=!1}clear(){this._array.length=0,this._insertedValues.length=0,this._flushInsertedTask.clear(),this._isFlushingInserted=!1,this._deletedIndices.length=0,this._flushDeletedTask.clear(),this._isFlushingDeleted=!1}insert(e){this._flushCleanupDeleted(),this._insertedValues.length===0&&this._flushInsertedTask.enqueue(()=>this._flushInserted()),this._insertedValues.push(e)}_flushInserted(){let e=this._insertedValues.sort((e,t)=>this._getKey(e)-this._getKey(t)),t=0,n=0,r=Array(this._array.length+this._insertedValues.length);for(let i=0;i<r.length;i++)n>=this._array.length||this._getKey(e[t])<=this._getKey(this._array[n])?(r[i]=e[t],t++):r[i]=this._array[n++];this._array=r,this._insertedValues.length=0}_flushCleanupInserted(){!this._isFlushingInserted&&this._insertedValues.length>0&&this._flushInsertedTask.flush()}delete(e){if(this._flushCleanupInserted(),this._array.length===0)return!1;let t=this._getKey(e);if(t===void 0||(M$=this._search(t),M$===-1)||this._getKey(this._array[M$])!==t)return!1;do if(this._array[M$]===e)return this._deletedIndices.length===0&&this._flushDeletedTask.enqueue(()=>this._flushDeleted()),this._deletedIndices.push(M$),!0;while(++M$<this._array.length&&this._getKey(this._array[M$])===t);return!1}_flushDeleted(){this._isFlushingDeleted=!0;let e=this._deletedIndices.sort((e,t)=>e-t),t=0,n=Array(this._array.length-e.length),r=0;for(let i=0;i<this._array.length;i++)e[t]===i?t++:n[r++]=this._array[i];this._array=n,this._deletedIndices.length=0,this._isFlushingDeleted=!1}_flushCleanupDeleted(){!this._isFlushingDeleted&&this._deletedIndices.length>0&&this._flushDeletedTask.flush()}*getKeyIterator(e){if(this._flushCleanupInserted(),this._flushCleanupDeleted(),this._array.length!==0&&(M$=this._search(e),!(M$<0||M$>=this._array.length)&&this._getKey(this._array[M$])===e))do yield this._array[M$];while(++M$<this._array.length&&this._getKey(this._array[M$])===e)}forEachByKey(e,t){if(this._flushCleanupInserted(),this._flushCleanupDeleted(),this._array.length!==0&&(M$=this._search(e),!(M$<0||M$>=this._array.length)&&this._getKey(this._array[M$])===e))do t(this._array[M$]);while(++M$<this._array.length&&this._getKey(this._array[M$])===e)}values(){return this._flushCleanupInserted(),this._flushCleanupDeleted(),[...this._array].values()}_search(e){let t=0,n=this._array.length-1;for(;n>=t;){let r=t+n>>1,i=this._getKey(this._array[r]);if(i>e)n=r-1;else if(i<e)t=r+1;else{for(;r>0&&this._getKey(this._array[r-1])===e;)r--;return r}}return t}},P$=0,F$=0,I$=class extends Sq{constructor(){super(),this._decorations=new N$(e=>e?.marker.line),this._onDecorationRegistered=this._register(new Hq),this.onDecorationRegistered=this._onDecorationRegistered.event,this._onDecorationRemoved=this._register(new Hq),this.onDecorationRemoved=this._onDecorationRemoved.event,this._register(yq(()=>this.reset()))}get decorations(){return this._decorations.values()}registerDecoration(e){if(e.marker.isDisposed)return;let t=new L$(e);if(t){let e=t.marker.onDispose(()=>t.dispose()),n=t.onDispose(()=>{n.dispose(),t&&(this._decorations.delete(t)&&this._onDecorationRemoved.fire(t),e.dispose())});this._decorations.insert(t),this._onDecorationRegistered.fire(t)}return t}reset(){for(let e of this._decorations.values())e.dispose();this._decorations.clear()}*getDecorationsAtCell(e,t,n){let r=0,i=0;for(let a of this._decorations.getKeyIterator(t))r=a.options.x??0,i=r+(a.options.width??1),e>=r&&e<i&&(!n||(a.options.layer??`bottom`)===n)&&(yield a)}forEachDecorationAtCell(e,t,n,r){this._decorations.forEachByKey(t,t=>{P$=t.options.x??0,F$=P$+(t.options.width??1),e>=P$&&e<F$&&(!n||(t.options.layer??`bottom`)===n)&&r(t)})}},L$=class extends xq{constructor(e){super(),this.options=e,this.onRenderEmitter=this.add(new Hq),this.onRender=this.onRenderEmitter.event,this._onDispose=this.add(new Hq),this.onDispose=this._onDispose.event,this._cachedBg=null,this._cachedFg=null,this.marker=e.marker,this.options.overviewRulerOptions&&!this.options.overviewRulerOptions.position&&(this.options.overviewRulerOptions.position=`full`)}get backgroundColorRGB(){return this._cachedBg===null&&(this._cachedBg=this.options.backgroundColor?bX.toColor(this.options.backgroundColor):void 0),this._cachedBg}get foregroundColorRGB(){return this._cachedFg===null&&(this._cachedFg=this.options.foregroundColor?bX.toColor(this.options.foregroundColor):void 0),this._cachedFg}dispose(){this._onDispose.fire(),super.dispose()}},R$=1e3,z$=class{constructor(e,t=R$){this._renderCallback=e,this._debounceThresholdMS=t,this._lastRefreshMs=0,this._additionalRefreshRequested=!1}dispose(){this._refreshTimeoutID&&clearTimeout(this._refreshTimeoutID)}refresh(e,t,n){this._rowCount=n,e=e===void 0?0:e,t=t===void 0?this._rowCount-1:t,this._rowStart=this._rowStart===void 0?e:Math.min(this._rowStart,e),this._rowEnd=this._rowEnd===void 0?t:Math.max(this._rowEnd,t);let r=performance.now();if(r-this._lastRefreshMs>=this._debounceThresholdMS)this._lastRefreshMs=r,this._innerRefresh();else if(!this._additionalRefreshRequested){let e=r-this._lastRefreshMs,t=this._debounceThresholdMS-e;this._additionalRefreshRequested=!0,this._refreshTimeoutID=window.setTimeout(()=>{this._lastRefreshMs=performance.now(),this._innerRefresh(),this._additionalRefreshRequested=!1,this._refreshTimeoutID=void 0},t)}}_innerRefresh(){if(this._rowStart===void 0||this._rowEnd===void 0||this._rowCount===void 0)return;let e=Math.max(this._rowStart,0),t=Math.min(this._rowEnd,this._rowCount-1);this._rowStart=void 0,this._rowEnd=void 0,this._renderCallback(e,t)}},B$=20,V$=class extends Sq{constructor(e,t,n,r){super(),this._terminal=e,this._coreBrowserService=n,this._renderService=r,this._rowColumns=new WeakMap,this._liveRegionLineCount=0,this._charsToConsume=[],this._charsToAnnounce=``;let i=this._coreBrowserService.mainDocument;this._accessibilityContainer=i.createElement(`div`),this._accessibilityContainer.classList.add(`xterm-accessibility`),this._rowContainer=i.createElement(`div`),this._rowContainer.setAttribute(`role`,`list`),this._rowContainer.classList.add(`xterm-accessibility-tree`),this._rowElements=[];for(let e=0;e<this._terminal.rows;e++)this._rowElements[e]=this._createAccessibilityTreeNode(),this._rowContainer.appendChild(this._rowElements[e]);if(this._topBoundaryFocusListener=e=>this._handleBoundaryFocus(e,0),this._bottomBoundaryFocusListener=e=>this._handleBoundaryFocus(e,1),this._rowElements[0].addEventListener(`focus`,this._topBoundaryFocusListener),this._rowElements[this._rowElements.length-1].addEventListener(`focus`,this._bottomBoundaryFocusListener),this._accessibilityContainer.appendChild(this._rowContainer),this._liveRegion=i.createElement(`div`),this._liveRegion.classList.add(`live-region`),this._liveRegion.setAttribute(`aria-live`,`assertive`),this._accessibilityContainer.appendChild(this._liveRegion),this._liveRegionDebouncer=this._register(new z$(this._renderRows.bind(this))),!this._terminal.element)throw Error(`Cannot enable accessibility before Terminal.open`);this._terminal.element.insertAdjacentElement(`afterbegin`,this._accessibilityContainer),this._register(this._terminal.onResize(e=>this._handleResize(e.rows))),this._register(this._terminal.onRender(e=>this._refreshRows(e.start,e.end))),this._register(this._terminal.onScroll(()=>this._refreshRows())),this._register(this._terminal.onA11yChar(e=>this._handleChar(e))),this._register(this._terminal.onLineFeed(()=>this._handleChar(`
1531
+ `))),this._register(this._terminal.onA11yTab(e=>this._handleTab(e))),this._register(this._terminal.onKey(e=>this._handleKey(e.key))),this._register(this._terminal.onBlur(()=>this._clearLiveRegion())),this._register(this._renderService.onDimensionsChange(()=>this._refreshRowsDimensions())),this._register(pY(i,`selectionchange`,()=>this._handleSelectionChange())),this._register(this._coreBrowserService.onDprChange(()=>this._refreshRowsDimensions())),this._refreshRowsDimensions(),this._refreshRows(),this._register(yq(()=>{this._accessibilityContainer.remove(),this._rowElements.length=0}))}_handleTab(e){for(let t=0;t<e;t++)this._handleChar(` `)}_handleChar(e){this._liveRegionLineCount<B$+1&&(this._charsToConsume.length>0?this._charsToConsume.shift()!==e&&(this._charsToAnnounce+=e):this._charsToAnnounce+=e,e===`
1532
+ `&&(this._liveRegionLineCount++,this._liveRegionLineCount===B$+1&&(this._liveRegion.textContent+=uK.get())))}_clearLiveRegion(){this._liveRegion.textContent=``,this._liveRegionLineCount=0}_handleKey(e){this._clearLiveRegion(),/\p{Control}/u.test(e)||this._charsToConsume.push(e)}_refreshRows(e,t){this._liveRegionDebouncer.refresh(e,t,this._terminal.rows)}_renderRows(e,t){let n=this._terminal.buffer,r=n.lines.length.toString();for(let i=e;i<=t;i++){let e=n.lines.get(n.ydisp+i),t=[],a=e?.translateToString(!0,void 0,void 0,t)||``,o=(n.ydisp+i+1).toString(),s=this._rowElements[i];s&&(a.length===0?(s.textContent=`\xA0`,this._rowColumns.set(s,[0,1])):(s.textContent=a,this._rowColumns.set(s,t)),s.setAttribute(`aria-posinset`,o),s.setAttribute(`aria-setsize`,r),this._alignRowWidth(s))}this._announceCharacters()}_announceCharacters(){this._charsToAnnounce.length!==0&&(this._liveRegion.textContent+=this._charsToAnnounce,this._charsToAnnounce=``)}_handleBoundaryFocus(e,t){let n=e.target,r=this._rowElements[t===0?1:this._rowElements.length-2];if(n.getAttribute(`aria-posinset`)===(t===0?`1`:`${this._terminal.buffer.lines.length}`)||e.relatedTarget!==r)return;let i,a;if(t===0?(i=n,a=this._rowElements.pop(),this._rowContainer.removeChild(a)):(i=this._rowElements.shift(),a=n,this._rowContainer.removeChild(i)),i.removeEventListener(`focus`,this._topBoundaryFocusListener),a.removeEventListener(`focus`,this._bottomBoundaryFocusListener),t===0){let e=this._createAccessibilityTreeNode();this._rowElements.unshift(e),this._rowContainer.insertAdjacentElement(`afterbegin`,e)}else{let e=this._createAccessibilityTreeNode();this._rowElements.push(e),this._rowContainer.appendChild(e)}this._rowElements[0].addEventListener(`focus`,this._topBoundaryFocusListener),this._rowElements[this._rowElements.length-1].addEventListener(`focus`,this._bottomBoundaryFocusListener),this._terminal.scrollLines(t===0?-1:1),this._rowElements[t===0?1:this._rowElements.length-2].focus(),e.preventDefault(),e.stopImmediatePropagation()}_handleSelectionChange(){if(this._rowElements.length===0)return;let e=this._coreBrowserService.mainDocument.getSelection();if(!e)return;if(e.isCollapsed){this._rowContainer.contains(e.anchorNode)&&this._terminal.clearSelection();return}if(!e.anchorNode||!e.focusNode){console.error(`anchorNode and/or focusNode are null`);return}let t={node:e.anchorNode,offset:e.anchorOffset},n={node:e.focusNode,offset:e.focusOffset};if((t.node.compareDocumentPosition(n.node)&Node.DOCUMENT_POSITION_PRECEDING||t.node===n.node&&t.offset>n.offset)&&([t,n]=[n,t]),t.node.compareDocumentPosition(this._rowElements[0])&(Node.DOCUMENT_POSITION_CONTAINED_BY|Node.DOCUMENT_POSITION_FOLLOWING)&&(t={node:this._rowElements[0].childNodes[0],offset:0}),!this._rowContainer.contains(t.node))return;let r=this._rowElements.slice(-1)[0];if(n.node.compareDocumentPosition(r)&(Node.DOCUMENT_POSITION_CONTAINED_BY|Node.DOCUMENT_POSITION_PRECEDING)&&(n={node:r,offset:r.textContent?.length??0}),!this._rowContainer.contains(n.node))return;let i=({node:e,offset:t})=>{let n=e instanceof Text?e.parentNode:e,r=parseInt(n?.getAttribute(`aria-posinset`),10)-1;if(isNaN(r))return console.warn(`row is invalid. Race condition?`),null;let i=this._rowColumns.get(n);if(!i)return console.warn(`columns is null. Race condition?`),null;let a=t<i.length?i[t]:i.slice(-1)[0]+1;return a>=this._terminal.cols&&(++r,a=0),{row:r,column:a}},a=i(t),o=i(n);if(a&&o){if(a.row>o.row||a.row===o.row&&a.column>=o.column)throw Error(`invalid range`);this._terminal.select(a.column,a.row,(o.row-a.row)*this._terminal.cols-a.column+o.column)}}_handleResize(e){this._rowElements[this._rowElements.length-1].removeEventListener(`focus`,this._bottomBoundaryFocusListener);for(let e=this._rowContainer.children.length;e<this._terminal.rows;e++)this._rowElements[e]=this._createAccessibilityTreeNode(),this._rowContainer.appendChild(this._rowElements[e]);for(;this._rowElements.length>e;)this._rowContainer.removeChild(this._rowElements.pop());this._rowElements[this._rowElements.length-1].addEventListener(`focus`,this._bottomBoundaryFocusListener),this._refreshRowsDimensions()}_createAccessibilityTreeNode(){let e=this._coreBrowserService.mainDocument.createElement(`div`);return e.setAttribute(`role`,`listitem`),e.tabIndex=-1,this._refreshRowDimensions(e),e}_refreshRowsDimensions(){if(this._renderService.dimensions.css.cell.height){Object.assign(this._accessibilityContainer.style,{width:`${this._renderService.dimensions.css.canvas.width}px`,fontSize:`${this._terminal.options.fontSize}px`}),this._rowElements.length!==this._terminal.rows&&this._handleResize(this._terminal.rows);for(let e=0;e<this._terminal.rows;e++)this._refreshRowDimensions(this._rowElements[e]),this._alignRowWidth(this._rowElements[e])}}_refreshRowDimensions(e){e.style.height=`${this._renderService.dimensions.css.cell.height}px`}_alignRowWidth(e){e.style.transform=``;let t=e.getBoundingClientRect().width,n=this._rowColumns.get(e)?.slice(-1)?.[0];if(!n)return;let r=n*this._renderService.dimensions.css.cell.width;e.style.transform=`scaleX(${r/t})`}};V$=aK([oK(1,LK),oK(2,KK),oK(3,JK)],V$);var H$=class extends Sq{constructor(e,t,n,r,i){super(),this._element=e,this._mouseService=t,this._renderService=n,this._bufferService=r,this._linkProviderService=i,this._linkCacheDisposables=[],this._isMouseOut=!0,this._wasResized=!1,this._activeLine=-1,this._onShowLinkUnderline=this._register(new Hq),this.onShowLinkUnderline=this._onShowLinkUnderline.event,this._onHideLinkUnderline=this._register(new Hq),this.onHideLinkUnderline=this._onHideLinkUnderline.event,this._register(yq(()=>{_q(this._linkCacheDisposables),this._linkCacheDisposables.length=0,this._lastMouseEvent=void 0,this._activeProviderReplies?.clear()})),this._register(this._bufferService.onResize(()=>{this._clearCurrentLink(),this._wasResized=!0})),this._register(pY(this._element,`mouseleave`,()=>{this._isMouseOut=!0,this._clearCurrentLink()})),this._register(pY(this._element,`mousemove`,this._handleMouseMove.bind(this))),this._register(pY(this._element,`mousedown`,this._handleMouseDown.bind(this))),this._register(pY(this._element,`mouseup`,this._handleMouseUp.bind(this)))}get currentLink(){return this._currentLink}_handleMouseMove(e){this._lastMouseEvent=e;let t=this._positionFromMouseEvent(e,this._element,this._mouseService);if(!t)return;this._isMouseOut=!1;let n=e.composedPath();for(let e=0;e<n.length;e++){let t=n[e];if(t.classList.contains(`xterm`))break;if(t.classList.contains(`xterm-hover`))return}(!this._lastBufferCell||t.x!==this._lastBufferCell.x||t.y!==this._lastBufferCell.y)&&(this._handleHover(t),this._lastBufferCell=t)}_handleHover(e){this._activeLine!==e.y||this._wasResized?(this._clearCurrentLink(),this._askForLink(e,!1),this._wasResized=!1):this._currentLink&&this._linkAtPosition(this._currentLink.link,e)||(this._clearCurrentLink(),this._askForLink(e,!0))}_askForLink(e,t){(!this._activeProviderReplies||!t)&&(this._activeProviderReplies?.forEach(e=>{e?.forEach(e=>{e.link.dispose&&e.link.dispose()})}),this._activeProviderReplies=new Map,this._activeLine=e.y);let n=!1;for(let[r,i]of this._linkProviderService.linkProviders.entries())t?this._activeProviderReplies?.get(r)&&(n=this._checkLinkProviderResult(r,e,n)):i.provideLinks(e.y,t=>{if(this._isMouseOut)return;let i=t?.map(e=>({link:e}));this._activeProviderReplies?.set(r,i),n=this._checkLinkProviderResult(r,e,n),this._activeProviderReplies?.size===this._linkProviderService.linkProviders.length&&this._removeIntersectingLinks(e.y,this._activeProviderReplies)})}_removeIntersectingLinks(e,t){let n=new Set;for(let r=0;r<t.size;r++){let i=t.get(r);if(i)for(let t=0;t<i.length;t++){let r=i[t],a=r.link.range.start.y<e?0:r.link.range.start.x,o=r.link.range.end.y>e?this._bufferService.cols:r.link.range.end.x;for(let e=a;e<=o;e++){if(n.has(e)){i.splice(t--,1);break}n.add(e)}}}}_checkLinkProviderResult(e,t,n){if(!this._activeProviderReplies)return n;let r=this._activeProviderReplies.get(e),i=!1;for(let t=0;t<e;t++)(!this._activeProviderReplies.has(t)||this._activeProviderReplies.get(t))&&(i=!0);if(!i&&r){let e=r.find(e=>this._linkAtPosition(e.link,t));e&&(n=!0,this._handleNewLink(e))}if(this._activeProviderReplies.size===this._linkProviderService.linkProviders.length&&!n)for(let e=0;e<this._activeProviderReplies.size;e++){let r=this._activeProviderReplies.get(e)?.find(e=>this._linkAtPosition(e.link,t));if(r){n=!0,this._handleNewLink(r);break}}return n}_handleMouseDown(){this._mouseDownLink=this._currentLink}_handleMouseUp(e){if(!this._currentLink)return;let t=this._positionFromMouseEvent(e,this._element,this._mouseService);t&&this._mouseDownLink&&U$(this._mouseDownLink.link,this._currentLink.link)&&this._linkAtPosition(this._currentLink.link,t)&&this._currentLink.link.activate(e,this._currentLink.link.text)}_clearCurrentLink(e,t){!this._currentLink||!this._lastMouseEvent||(!e||!t||this._currentLink.link.range.start.y>=e&&this._currentLink.link.range.end.y<=t)&&(this._linkLeave(this._element,this._currentLink.link,this._lastMouseEvent),this._currentLink=void 0,_q(this._linkCacheDisposables),this._linkCacheDisposables.length=0)}_handleNewLink(e){if(!this._lastMouseEvent)return;let t=this._positionFromMouseEvent(this._lastMouseEvent,this._element,this._mouseService);t&&this._linkAtPosition(e.link,t)&&(this._currentLink=e,this._currentLink.state={decorations:{underline:e.link.decorations===void 0||e.link.decorations.underline,pointerCursor:e.link.decorations===void 0||e.link.decorations.pointerCursor},isHovered:!0},this._linkHover(this._element,e.link,this._lastMouseEvent),e.link.decorations={},Object.defineProperties(e.link.decorations,{pointerCursor:{get:()=>this._currentLink?.state?.decorations.pointerCursor,set:e=>{this._currentLink?.state&&this._currentLink.state.decorations.pointerCursor!==e&&(this._currentLink.state.decorations.pointerCursor=e,this._currentLink.state.isHovered&&this._element.classList.toggle(`xterm-cursor-pointer`,e))}},underline:{get:()=>this._currentLink?.state?.decorations.underline,set:t=>{this._currentLink?.state&&this._currentLink?.state?.decorations.underline!==t&&(this._currentLink.state.decorations.underline=t,this._currentLink.state.isHovered&&this._fireUnderlineEvent(e.link,t))}}}),this._linkCacheDisposables.push(this._renderService.onRenderedViewportChange(e=>{if(!this._currentLink)return;let t=e.start===0?0:e.start+1+this._bufferService.buffer.ydisp,n=this._bufferService.buffer.ydisp+1+e.end;if(this._currentLink.link.range.start.y>=t&&this._currentLink.link.range.end.y<=n&&(this._clearCurrentLink(t,n),this._lastMouseEvent)){let e=this._positionFromMouseEvent(this._lastMouseEvent,this._element,this._mouseService);e&&this._askForLink(e,!1)}})))}_linkHover(e,t,n){this._currentLink?.state&&(this._currentLink.state.isHovered=!0,this._currentLink.state.decorations.underline&&this._fireUnderlineEvent(t,!0),this._currentLink.state.decorations.pointerCursor&&e.classList.add(`xterm-cursor-pointer`)),t.hover&&t.hover(n,t.text)}_fireUnderlineEvent(e,t){let n=e.range,r=this._bufferService.buffer.ydisp,i=this._createLinkUnderlineEvent(n.start.x-1,n.start.y-r-1,n.end.x,n.end.y-r-1,void 0);(t?this._onShowLinkUnderline:this._onHideLinkUnderline).fire(i)}_linkLeave(e,t,n){this._currentLink?.state&&(this._currentLink.state.isHovered=!1,this._currentLink.state.decorations.underline&&this._fireUnderlineEvent(t,!1),this._currentLink.state.decorations.pointerCursor&&e.classList.remove(`xterm-cursor-pointer`)),t.leave&&t.leave(n,t.text)}_linkAtPosition(e,t){let n=e.range.start.y*this._bufferService.cols+e.range.start.x,r=e.range.end.y*this._bufferService.cols+e.range.end.x,i=t.y*this._bufferService.cols+t.x;return n<=i&&i<=r}_positionFromMouseEvent(e,t,n){let r=n.getCoords(e,t,this._bufferService.cols,this._bufferService.rows);if(r)return{x:r[0],y:r[1]+this._bufferService.buffer.ydisp}}_createLinkUnderlineEvent(e,t,n,r,i){return{x1:e,y1:t,x2:n,y2:r,cols:this._bufferService.cols,fg:i}}};H$=aK([oK(1,qK),oK(2,JK),oK(3,NK),oK(4,QK)],H$);function U$(e,t){return e.text===t.text&&e.range.start.x===t.range.start.x&&e.range.start.y===t.range.start.y&&e.range.end.x===t.range.end.x&&e.range.end.y===t.range.end.y}var W$=class extends k${constructor(e={}){super(e),this._linkifier=this._register(new Cq),this.browser=nZ,this._keyDownHandled=!1,this._keyDownSeen=!1,this._keyPressHandled=!1,this._unprocessedDeadKey=!1,this._accessibilityManager=this._register(new Cq),this._onCursorMove=this._register(new Hq),this.onCursorMove=this._onCursorMove.event,this._onKey=this._register(new Hq),this.onKey=this._onKey.event,this._onRender=this._register(new Hq),this.onRender=this._onRender.event,this._onSelectionChange=this._register(new Hq),this.onSelectionChange=this._onSelectionChange.event,this._onTitleChange=this._register(new Hq),this.onTitleChange=this._onTitleChange.event,this._onBell=this._register(new Hq),this.onBell=this._onBell.event,this._onFocus=this._register(new Hq),this._onBlur=this._register(new Hq),this._onA11yCharEmitter=this._register(new Hq),this._onA11yTabEmitter=this._register(new Hq),this._onWillOpen=this._register(new Hq),this._setup(),this._decorationService=this._instantiationService.createInstance(I$),this._instantiationService.setService(HK,this._decorationService),this._linkProviderService=this._instantiationService.createInstance(ZX),this._instantiationService.setService(QK,this._linkProviderService),this._linkProviderService.registerLinkProvider(this._instantiationService.createInstance(UK)),this._register(this._inputHandler.onRequestBell(()=>this._onBell.fire())),this._register(this._inputHandler.onRequestRefreshRows(e=>this.refresh(e?.start??0,e?.end??this.rows-1))),this._register(this._inputHandler.onRequestSendFocus(()=>this._reportFocus())),this._register(this._inputHandler.onRequestReset(()=>this.reset())),this._register(this._inputHandler.onRequestWindowsOptionsReport(e=>this._reportWindowsOptions(e))),this._register(this._inputHandler.onColor(e=>this._handleColorEvent(e))),this._register(Aq.forward(this._inputHandler.onCursorMove,this._onCursorMove)),this._register(Aq.forward(this._inputHandler.onTitleChange,this._onTitleChange)),this._register(Aq.forward(this._inputHandler.onA11yChar,this._onA11yCharEmitter)),this._register(Aq.forward(this._inputHandler.onA11yTab,this._onA11yTabEmitter)),this._register(this._bufferService.onResize(e=>this._afterResize(e.cols,e.rows))),this._register(yq(()=>{this._customKeyEventHandler=void 0,this.element?.parentNode?.removeChild(this.element)}))}get linkifier(){return this._linkifier.value}get onFocus(){return this._onFocus.event}get onBlur(){return this._onBlur.event}get onA11yChar(){return this._onA11yCharEmitter.event}get onA11yTab(){return this._onA11yTabEmitter.event}get onWillOpen(){return this._onWillOpen.event}_handleColorEvent(e){if(this._themeService)for(let t of e){let e,n=``;switch(t.index){case 256:e=`foreground`,n=`10`;break;case 257:e=`background`,n=`11`;break;case 258:e=`cursor`,n=`12`;break;default:e=`ansi`,n=`4;`+t.index}switch(t.type){case 0:let r=yX.toColorRGB(e===`ansi`?this._themeService.colors.ansi[t.index]:this._themeService.colors[e]);this.coreService.triggerDataEvent(`${$.ESC}]${n};${p$(r)}${dX.ST}`);break;case 1:if(e===`ansi`)this._themeService.modifyColors(e=>e.ansi[t.index]=vX.toColor(...t.color));else{let n=e;this._themeService.modifyColors(e=>e[n]=vX.toColor(...t.color))}break;case 2:this._themeService.restoreColor(t.index)}}}_setup(){super._setup(),this._customKeyEventHandler=void 0}get buffer(){return this.buffers.active}focus(){this.textarea&&this.textarea.focus({preventScroll:!0})}_handleScreenReaderModeOptionChange(e){e?!this._accessibilityManager.value&&this._renderService&&(this._accessibilityManager.value=this._instantiationService.createInstance(V$,this)):this._accessibilityManager.clear()}_handleTextAreaFocus(e){this.coreService.decPrivateModes.sendFocus&&this.coreService.triggerDataEvent($.ESC+`[I`),this.element.classList.add(`focus`),this._showCursor(),this._onFocus.fire()}blur(){return this.textarea?.blur()}_handleTextAreaBlur(){this.textarea.value=``,this.refresh(this.buffer.y,this.buffer.y),this.coreService.decPrivateModes.sendFocus&&this.coreService.triggerDataEvent($.ESC+`[O`),this.element.classList.remove(`focus`),this._onBlur.fire()}_syncTextArea(){if(!this.textarea||!this.buffer.isCursorInViewport||this._compositionHelper.isComposing||!this._renderService)return;let e=this.buffer.ybase+this.buffer.y,t=this.buffer.lines.get(e);if(!t)return;let n=Math.min(this.buffer.x,this.cols-1),r=this._renderService.dimensions.css.cell.height,i=t.getWidth(n),a=this._renderService.dimensions.css.cell.width*i,o=this.buffer.y*this._renderService.dimensions.css.cell.height,s=n*this._renderService.dimensions.css.cell.width;this.textarea.style.left=s+`px`,this.textarea.style.top=o+`px`,this.textarea.style.width=a+`px`,this.textarea.style.height=r+`px`,this.textarea.style.lineHeight=r+`px`,this.textarea.style.zIndex=`-5`}_initGlobal(){this._bindKeys(),this._register(pY(this.element,`copy`,e=>{this.hasSelection()&&pK(e,this._selectionService)}));let e=e=>mK(e,this.textarea,this.coreService,this.optionsService);this._register(pY(this.textarea,`paste`,e)),this._register(pY(this.element,`paste`,e)),oZ?this._register(pY(this.element,`mousedown`,e=>{e.button===2&&_K(e,this.textarea,this.screenElement,this._selectionService,this.options.rightClickSelectsWord)})):this._register(pY(this.element,`contextmenu`,e=>{_K(e,this.textarea,this.screenElement,this._selectionService,this.options.rightClickSelectsWord)})),mZ&&this._register(pY(this.element,`auxclick`,e=>{e.button===1&&gK(e,this.textarea,this.screenElement)}))}_bindKeys(){this._register(pY(this.textarea,`keyup`,e=>this._keyUp(e),!0)),this._register(pY(this.textarea,`keydown`,e=>this._keyDown(e),!0)),this._register(pY(this.textarea,`keypress`,e=>this._keyPress(e),!0)),this._register(pY(this.textarea,`compositionstart`,()=>this._compositionHelper.compositionstart())),this._register(pY(this.textarea,`compositionupdate`,e=>this._compositionHelper.compositionupdate(e))),this._register(pY(this.textarea,`compositionend`,()=>this._compositionHelper.compositionend())),this._register(pY(this.textarea,`input`,e=>this._inputEvent(e),!0)),this._register(this.onRender(()=>this._compositionHelper.updateCompositionElements()))}open(e){if(!e)throw Error(`Terminal requires a parent element.`);if(e.isConnected||this._logService.debug(`Terminal.open was called on an element that was not attached to the DOM`),this.element?.ownerDocument.defaultView&&this._coreBrowserService){this.element.ownerDocument.defaultView!==this._coreBrowserService.window&&(this._coreBrowserService.window=this.element.ownerDocument.defaultView);return}this._document=e.ownerDocument,this.options.documentOverride&&this.options.documentOverride instanceof Document&&(this._document=this.optionsService.rawOptions.documentOverride),this.element=this._document.createElement(`div`),this.element.dir=`ltr`,this.element.classList.add(`terminal`),this.element.classList.add(`xterm`),e.appendChild(this.element);let t=this._document.createDocumentFragment();this._viewportElement=this._document.createElement(`div`),this._viewportElement.classList.add(`xterm-viewport`),t.appendChild(this._viewportElement),this.screenElement=this._document.createElement(`div`),this.screenElement.classList.add(`xterm-screen`),this._register(pY(this.screenElement,`mousemove`,e=>this.updateCursorStyle(e))),this._helperContainer=this._document.createElement(`div`),this._helperContainer.classList.add(`xterm-helpers`),this.screenElement.appendChild(this._helperContainer),t.appendChild(this.screenElement);let n=this.textarea=this._document.createElement(`textarea`);this.textarea.classList.add(`xterm-helper-textarea`),this.textarea.setAttribute(`aria-label`,cK.get()),hZ||this.textarea.setAttribute(`aria-multiline`,`false`),this.textarea.setAttribute(`autocorrect`,`off`),this.textarea.setAttribute(`autocapitalize`,`off`),this.textarea.setAttribute(`spellcheck`,`false`),this.textarea.tabIndex=0,this._register(this.optionsService.onSpecificOptionChange(`disableStdin`,()=>n.readOnly=this.optionsService.rawOptions.disableStdin)),this.textarea.readOnly=this.optionsService.rawOptions.disableStdin,this._coreBrowserService=this._register(this._instantiationService.createInstance(YX,this.textarea,e.ownerDocument.defaultView??window,this._document??typeof window<`u`?window.document:null)),this._instantiationService.setService(KK,this._coreBrowserService),this._register(pY(this.textarea,`focus`,e=>this._handleTextAreaFocus(e))),this._register(pY(this.textarea,`blur`,()=>this._handleTextAreaBlur())),this._helperContainer.appendChild(this.textarea),this._charSizeService=this._instantiationService.createInstance(GX,this._document,this._helperContainer),this._instantiationService.setService(GK,this._charSizeService),this._themeService=this._instantiationService.createInstance($Z),this._instantiationService.setService(ZK,this._themeService),this._characterJoinerService=this._instantiationService.createInstance(EX),this._instantiationService.setService(XK,this._characterJoinerService),this._renderService=this._register(this._instantiationService.createInstance(xZ,this.rows,this.screenElement)),this._instantiationService.setService(JK,this._renderService),this._register(this._renderService.onRenderedViewportChange(e=>this._onRender.fire(e))),this.onResize(e=>this._renderService.resize(e.cols,e.rows)),this._compositionView=this._document.createElement(`div`),this._compositionView.classList.add(`composition-view`),this._compositionHelper=this._instantiationService.createInstance(fX,this.textarea,this._compositionView),this._helperContainer.appendChild(this._compositionView),this._mouseService=this._instantiationService.createInstance(eZ),this._instantiationService.setService(qK,this._mouseService);let r=this._linkifier.value=this._register(this._instantiationService.createInstance(H$,this.screenElement));this.element.appendChild(t);try{this._onWillOpen.fire(this.element)}catch{}this._renderService.hasRenderer()||this._renderService.setRenderer(this._createRenderer()),this._register(this.onCursorMove(()=>{this._renderService.handleCursorMove(),this._syncTextArea()})),this._register(this.onResize(()=>this._renderService.handleResize(this.cols,this.rows))),this._register(this.onBlur(()=>this._renderService.handleBlur())),this._register(this.onFocus(()=>this._renderService.handleFocus())),this._viewport=this._register(this._instantiationService.createInstance(rX,this.element,this.screenElement)),this._register(this._viewport.onRequestScrollLines(e=>{super.scrollLines(e,!1),this.refresh(0,this.rows-1)})),this._selectionService=this._register(this._instantiationService.createInstance(UZ,this.element,this.screenElement,r)),this._instantiationService.setService(YK,this._selectionService),this._register(this._selectionService.onRequestScrollLines(e=>this.scrollLines(e.amount,e.suppressScrollEvent))),this._register(this._selectionService.onSelectionChange(()=>this._onSelectionChange.fire())),this._register(this._selectionService.onRequestRedraw(e=>this._renderService.handleSelectionChanged(e.start,e.end,e.columnSelectMode))),this._register(this._selectionService.onLinuxMouseSelection(e=>{this.textarea.value=e,this.textarea.focus(),this.textarea.select()})),this._register(Aq.any(this._onScroll.event,this._inputHandler.onScroll)(()=>{this._selectionService.refresh(),this._viewport?.queueSync()})),this._register(this._instantiationService.createInstance(iX,this.screenElement)),this._register(pY(this.element,`mousedown`,e=>this._selectionService.handleMouseDown(e))),this.coreMouseService.areMouseEventsActive?(this._selectionService.disable(),this.element.classList.add(`enable-mouse-events`)):this._selectionService.enable(),this.options.screenReaderMode&&(this._accessibilityManager.value=this._instantiationService.createInstance(V$,this)),this._register(this.optionsService.onSpecificOptionChange(`screenReaderMode`,e=>this._handleScreenReaderModeOptionChange(e))),this.options.overviewRuler.width&&(this._overviewRulerRenderer=this._register(this._instantiationService.createInstance(lX,this._viewportElement,this.screenElement))),this.optionsService.onSpecificOptionChange(`overviewRuler`,e=>{!this._overviewRulerRenderer&&e&&this._viewportElement&&this.screenElement&&(this._overviewRulerRenderer=this._register(this._instantiationService.createInstance(lX,this._viewportElement,this.screenElement)))}),this._charSizeService.measure(),this.refresh(0,this.rows-1),this._initGlobal(),this.bindMouse()}_createRenderer(){return this._instantiationService.createInstance(WX,this,this._document,this.element,this.screenElement,this._viewportElement,this._helperContainer,this.linkifier)}bindMouse(){let e=this,t=this.element;function n(t){let n=e._mouseService.getMouseReportCoords(t,e.screenElement);if(!n)return!1;let r,i;switch(t.overrideType||t.type){case`mousemove`:i=32,t.buttons===void 0?(r=3,t.button!==void 0&&(r=t.button<3?t.button:3)):r=t.buttons&1?0:t.buttons&4?1:t.buttons&2?2:3;break;case`mouseup`:i=0,r=t.button<3?t.button:3;break;case`mousedown`:i=1,r=t.button<3?t.button:3;break;case`wheel`:if(e._customWheelEventHandler&&e._customWheelEventHandler(t)===!1)return!1;let n=t.deltaY;if(n===0||e.coreMouseService.consumeWheelEvent(t,e._renderService?.dimensions?.device?.cell?.height,e._coreBrowserService?.dpr)===0)return!1;i=n<0?0:1,r=4;break;default:return!1}return i===void 0||r===void 0||r>4?!1:e.coreMouseService.triggerMouseEvent({col:n.col,row:n.row,x:n.x,y:n.y,button:r,action:i,ctrl:t.ctrlKey,alt:t.altKey,shift:t.shiftKey})}let r={mouseup:null,wheel:null,mousedrag:null,mousemove:null},i={mouseup:e=>(n(e),e.buttons||(this._document.removeEventListener(`mouseup`,r.mouseup),r.mousedrag&&this._document.removeEventListener(`mousemove`,r.mousedrag)),this.cancel(e)),wheel:e=>(n(e),this.cancel(e,!0)),mousedrag:e=>{e.buttons&&n(e)},mousemove:e=>{e.buttons||n(e)}};this._register(this.coreMouseService.onProtocolChange(e=>{e?(this.optionsService.rawOptions.logLevel===`debug`&&this._logService.debug(`Binding to mouse events:`,this.coreMouseService.explainEvents(e)),this.element.classList.add(`enable-mouse-events`),this._selectionService.disable()):(this._logService.debug(`Unbinding from mouse events.`),this.element.classList.remove(`enable-mouse-events`),this._selectionService.enable()),e&8?r.mousemove||=(t.addEventListener(`mousemove`,i.mousemove),i.mousemove):(t.removeEventListener(`mousemove`,r.mousemove),r.mousemove=null),e&16?r.wheel||=(t.addEventListener(`wheel`,i.wheel,{passive:!1}),i.wheel):(t.removeEventListener(`wheel`,r.wheel),r.wheel=null),e&2?r.mouseup||=i.mouseup:(this._document.removeEventListener(`mouseup`,r.mouseup),r.mouseup=null),e&4?r.mousedrag||=i.mousedrag:(this._document.removeEventListener(`mousemove`,r.mousedrag),r.mousedrag=null)})),this.coreMouseService.activeProtocol=this.coreMouseService.activeProtocol,this._register(pY(t,`mousedown`,e=>{if(e.preventDefault(),this.focus(),this.coreMouseService.areMouseEventsActive&&!this._selectionService.shouldForceSelection(e))return n(e),r.mouseup&&this._document.addEventListener(`mouseup`,r.mouseup),r.mousedrag&&this._document.addEventListener(`mousemove`,r.mousedrag),this.cancel(e)})),this._register(pY(t,`wheel`,t=>{if(!r.wheel){if(this._customWheelEventHandler&&this._customWheelEventHandler(t)===!1)return!1;if(!this.buffer.hasScrollback){if(t.deltaY===0)return!1;if(e.coreMouseService.consumeWheelEvent(t,e._renderService?.dimensions?.device?.cell?.height,e._coreBrowserService?.dpr)===0)return this.cancel(t,!0);let n=$.ESC+(this.coreService.decPrivateModes.applicationCursorKeys?`O`:`[`)+(t.deltaY<0?`A`:`B`);return this.coreService.triggerDataEvent(n,!0),this.cancel(t,!0)}}},{passive:!1}))}refresh(e,t){this._renderService?.refreshRows(e,t)}updateCursorStyle(e){this._selectionService?.shouldColumnSelect(e)?this.element.classList.add(`column-select`):this.element.classList.remove(`column-select`)}_showCursor(){this.coreService.isCursorInitialized||(this.coreService.isCursorInitialized=!0,this.refresh(this.buffer.y,this.buffer.y))}scrollLines(e,t){this._viewport?this._viewport.scrollLines(e):super.scrollLines(e,t),this.refresh(0,this.rows-1)}scrollPages(e){this.scrollLines(e*(this.rows-1))}scrollToTop(){this.scrollLines(-this._bufferService.buffer.ydisp)}scrollToBottom(e){e&&this._viewport?this._viewport.scrollToLine(this.buffer.ybase,!0):this.scrollLines(this._bufferService.buffer.ybase-this._bufferService.buffer.ydisp)}scrollToLine(e){let t=e-this._bufferService.buffer.ydisp;t!==0&&this.scrollLines(t)}paste(e){hK(e,this.textarea,this.coreService,this.optionsService)}attachCustomKeyEventHandler(e){this._customKeyEventHandler=e}attachCustomWheelEventHandler(e){this._customWheelEventHandler=e}registerLinkProvider(e){return this._linkProviderService.registerLinkProvider(e)}registerCharacterJoiner(e){if(!this._characterJoinerService)throw Error(`Terminal must be opened first`);let t=this._characterJoinerService.register(e);return this.refresh(0,this.rows-1),t}deregisterCharacterJoiner(e){if(!this._characterJoinerService)throw Error(`Terminal must be opened first`);this._characterJoinerService.deregister(e)&&this.refresh(0,this.rows-1)}get markers(){return this.buffer.markers}registerMarker(e){return this.buffer.addMarker(this.buffer.ybase+this.buffer.y+e)}registerDecoration(e){return this._decorationService.registerDecoration(e)}hasSelection(){return this._selectionService?this._selectionService.hasSelection:!1}select(e,t,n){this._selectionService.setSelection(e,t,n)}getSelection(){return this._selectionService?this._selectionService.selectionText:``}getSelectionPosition(){if(this._selectionService&&this._selectionService.hasSelection)return{start:{x:this._selectionService.selectionStart[0],y:this._selectionService.selectionStart[1]},end:{x:this._selectionService.selectionEnd[0],y:this._selectionService.selectionEnd[1]}}}clearSelection(){this._selectionService?.clearSelection()}selectAll(){this._selectionService?.selectAll()}selectLines(e,t){this._selectionService?.selectLines(e,t)}_keyDown(e){if(this._keyDownHandled=!1,this._keyDownSeen=!0,this._customKeyEventHandler&&this._customKeyEventHandler(e)===!1)return!1;let t=this.browser.isMac&&this.options.macOptionIsMeta&&e.altKey;if(!t&&!this._compositionHelper.keydown(e))return this.options.scrollOnUserInput&&this.buffer.ybase!==this.buffer.ydisp&&this.scrollToBottom(!0),!1;!t&&(e.key===`Dead`||e.key===`AltGraph`)&&(this._unprocessedDeadKey=!0);let n=j$(e,this.coreService.decPrivateModes.applicationCursorKeys,this.browser.isMac,this.options.macOptionIsMeta);if(this.updateCursorStyle(e),n.type===3||n.type===2){let t=this.rows-1;return this.scrollLines(n.type===2?-t:t),this.cancel(e,!0)}if(n.type===1&&this.selectAll(),this._isThirdLevelShift(this.browser,e)||(n.cancel&&this.cancel(e,!0),!n.key)||e.key&&!e.ctrlKey&&!e.altKey&&!e.metaKey&&e.key.length===1&&e.key.charCodeAt(0)>=65&&e.key.charCodeAt(0)<=90)return!0;if(this._unprocessedDeadKey)return this._unprocessedDeadKey=!1,!0;if((n.key===$.ETX||n.key===$.CR)&&(this.textarea.value=``),this._onKey.fire({key:n.key,domEvent:e}),this._showCursor(),this.coreService.triggerDataEvent(n.key,!0),!this.optionsService.rawOptions.screenReaderMode||e.altKey||e.ctrlKey)return this.cancel(e,!0);this._keyDownHandled=!0}_isThirdLevelShift(e,t){let n=e.isMac&&!this.options.macOptionIsMeta&&t.altKey&&!t.ctrlKey&&!t.metaKey||e.isWindows&&t.altKey&&t.ctrlKey&&!t.metaKey||e.isWindows&&t.getModifierState(`AltGraph`);return t.type===`keypress`?n:n&&(!t.keyCode||t.keyCode>47)}_keyUp(e){this._keyDownSeen=!1,!(this._customKeyEventHandler&&this._customKeyEventHandler(e)===!1)&&(G$(e)||this.focus(),this.updateCursorStyle(e),this._keyPressHandled=!1)}_keyPress(e){let t;if(this._keyPressHandled=!1,this._keyDownHandled||this._customKeyEventHandler&&this._customKeyEventHandler(e)===!1)return!1;if(this.cancel(e),e.charCode)t=e.charCode;else if(e.which===null||e.which===void 0)t=e.keyCode;else if(e.which!==0&&e.charCode!==0)t=e.which;else return!1;return!t||(e.altKey||e.ctrlKey||e.metaKey)&&!this._isThirdLevelShift(this.browser,e)?!1:(t=String.fromCharCode(t),this._onKey.fire({key:t,domEvent:e}),this._showCursor(),this.coreService.triggerDataEvent(t,!0),this._keyPressHandled=!0,this._unprocessedDeadKey=!1,!0)}_inputEvent(e){if(e.data&&e.inputType===`insertText`&&(!e.composed||!this._keyDownSeen)&&!this.optionsService.rawOptions.screenReaderMode){if(this._keyPressHandled)return!1;this._unprocessedDeadKey=!1;let t=e.data;return this.coreService.triggerDataEvent(t,!0),this.cancel(e),!0}return!1}resize(e,t){e===this.cols&&t===this.rows?this._charSizeService&&!this._charSizeService.hasValidSize&&this._charSizeService.measure():super.resize(e,t)}_afterResize(e,t){this._charSizeService?.measure()}clear(){if(this.buffer.ybase!==0||this.buffer.y!==0){this.buffer.clearAllMarkers(),this.buffer.lines.set(0,this.buffer.lines.get(this.buffer.ybase+this.buffer.y)),this.buffer.lines.length=1,this.buffer.ydisp=0,this.buffer.ybase=0,this.buffer.y=0;for(let e=1;e<this.rows;e++)this.buffer.lines.push(this.buffer.getBlankLine(lQ));this._onScroll.fire({position:this.buffer.ydisp}),this.refresh(0,this.rows-1)}}reset(){this.options.rows=this.rows,this.options.cols=this.cols;let e=this._customKeyEventHandler;this._setup(),super.reset(),this._selectionService?.reset(),this._decorationService.reset(),this._customKeyEventHandler=e,this.refresh(0,this.rows-1)}clearTextureAtlas(){this._renderService?.clearTextureAtlas()}_reportFocus(){this.element?.classList.contains(`focus`)?this.coreService.triggerDataEvent($.ESC+`[I`):this.coreService.triggerDataEvent($.ESC+`[O`)}_reportWindowsOptions(e){if(this._renderService)switch(e){case 0:let e=this._renderService.dimensions.css.canvas.width.toFixed(0),t=this._renderService.dimensions.css.canvas.height.toFixed(0);this.coreService.triggerDataEvent(`${$.ESC}[4;${t};${e}t`);break;case 1:let n=this._renderService.dimensions.css.cell.width.toFixed(0),r=this._renderService.dimensions.css.cell.height.toFixed(0);this.coreService.triggerDataEvent(`${$.ESC}[6;${r};${n}t`)}}cancel(e,t){if(this.options.cancelEvents||t)return e.preventDefault(),e.stopPropagation(),!1}};function G$(e){return e.keyCode===16||e.keyCode===17||e.keyCode===18}var K$=class{constructor(){this._addons=[]}dispose(){for(let e=this._addons.length-1;e>=0;e--)this._addons[e].instance.dispose()}loadAddon(e,t){let n={instance:t,dispose:t.dispose,isDisposed:!1};this._addons.push(n),t.dispose=()=>this._wrappedAddonDispose(n),t.activate(e)}_wrappedAddonDispose(e){if(e.isDisposed)return;let t=-1;for(let n=0;n<this._addons.length;n++)if(this._addons[n]===e){t=n;break}if(t===-1)throw Error(`Could not dispose an addon that has not been loaded`);e.isDisposed=!0,e.dispose.apply(e.instance),this._addons.splice(t,1)}},q$=class{constructor(e){this._line=e}get isWrapped(){return this._line.isWrapped}get length(){return this._line.length}getCell(e,t){if(!(e<0||e>=this._line.length))return t?(this._line.loadCell(e,t),t):this._line.loadCell(e,new EK)}translateToString(e,t,n){return this._line.translateToString(e,t,n)}},J$=class{constructor(e,t){this._buffer=e,this.type=t}init(e){return this._buffer=e,this}get cursorY(){return this._buffer.y}get cursorX(){return this._buffer.x}get viewportY(){return this._buffer.ydisp}get baseY(){return this._buffer.ybase}get length(){return this._buffer.lines.length}getLine(e){let t=this._buffer.lines.get(e);if(t)return new q$(t)}getNullCell(){return new EK}},Y$=class extends Sq{constructor(e){super(),this._core=e,this._onBufferChange=this._register(new Hq),this.onBufferChange=this._onBufferChange.event,this._normal=new J$(this._core.buffers.normal,`normal`),this._alternate=new J$(this._core.buffers.alt,`alternate`),this._core.buffers.onBufferActivate(()=>this._onBufferChange.fire(this.active))}get active(){if(this._core.buffers.active===this._core.buffers.normal)return this.normal;if(this._core.buffers.active===this._core.buffers.alt)return this.alternate;throw Error(`Active buffer is neither normal nor alternate`)}get normal(){return this._normal.init(this._core.buffers.normal)}get alternate(){return this._alternate.init(this._core.buffers.alt)}},X$=class{constructor(e){this._core=e}registerCsiHandler(e,t){return this._core.registerCsiHandler(e,e=>t(e.toArray()))}addCsiHandler(e,t){return this.registerCsiHandler(e,t)}registerDcsHandler(e,t){return this._core.registerDcsHandler(e,(e,n)=>t(e,n.toArray()))}addDcsHandler(e,t){return this.registerDcsHandler(e,t)}registerEscHandler(e,t){return this._core.registerEscHandler(e,t)}addEscHandler(e,t){return this.registerEscHandler(e,t)}registerOscHandler(e,t){return this._core.registerOscHandler(e,t)}addOscHandler(e,t){return this.registerOscHandler(e,t)}},Z$=class{constructor(e){this._core=e}register(e){this._core.unicodeService.register(e)}get versions(){return this._core.unicodeService.versions}get activeVersion(){return this._core.unicodeService.activeVersion}set activeVersion(e){this._core.unicodeService.activeVersion=e}},Q$=[`cols`,`rows`],$$=0,e1=class extends Sq{constructor(e){super(),this._core=this._register(new W$(e)),this._addonManager=this._register(new K$),this._publicOptions={...this._core.options};let t=e=>this._core.options[e],n=(e,t)=>{this._checkReadonlyOptions(e),this._core.options[e]=t};for(let e in this._core.options){let r={get:t.bind(this,e),set:n.bind(this,e)};Object.defineProperty(this._publicOptions,e,r)}}_checkReadonlyOptions(e){if(Q$.includes(e))throw Error(`Option "${e}" can only be set in the constructor`)}_checkProposedApi(){if(!this._core.optionsService.rawOptions.allowProposedApi)throw Error(`You must set the allowProposedApi option to true to use proposed API`)}get onBell(){return this._core.onBell}get onBinary(){return this._core.onBinary}get onCursorMove(){return this._core.onCursorMove}get onData(){return this._core.onData}get onKey(){return this._core.onKey}get onLineFeed(){return this._core.onLineFeed}get onRender(){return this._core.onRender}get onResize(){return this._core.onResize}get onScroll(){return this._core.onScroll}get onSelectionChange(){return this._core.onSelectionChange}get onTitleChange(){return this._core.onTitleChange}get onWriteParsed(){return this._core.onWriteParsed}get element(){return this._core.element}get parser(){return this._parser||=new X$(this._core),this._parser}get unicode(){return this._checkProposedApi(),new Z$(this._core)}get textarea(){return this._core.textarea}get rows(){return this._core.rows}get cols(){return this._core.cols}get buffer(){return this._buffer||=this._register(new Y$(this._core)),this._buffer}get markers(){return this._checkProposedApi(),this._core.markers}get modes(){let e=this._core.coreService.decPrivateModes,t=`none`;switch(this._core.coreMouseService.activeProtocol){case`X10`:t=`x10`;break;case`VT200`:t=`vt200`;break;case`DRAG`:t=`drag`;break;case`ANY`:t=`any`}return{applicationCursorKeysMode:e.applicationCursorKeys,applicationKeypadMode:e.applicationKeypad,bracketedPasteMode:e.bracketedPasteMode,insertMode:this._core.coreService.modes.insertMode,mouseTrackingMode:t,originMode:e.origin,reverseWraparoundMode:e.reverseWraparound,sendFocusMode:e.sendFocus,synchronizedOutputMode:e.synchronizedOutput,wraparoundMode:e.wraparound}}get options(){return this._publicOptions}set options(e){for(let t in e)this._publicOptions[t]=e[t]}blur(){this._core.blur()}focus(){this._core.focus()}input(e,t=!0){this._core.input(e,t)}resize(e,t){this._verifyIntegers(e,t),this._core.resize(e,t)}open(e){this._core.open(e)}attachCustomKeyEventHandler(e){this._core.attachCustomKeyEventHandler(e)}attachCustomWheelEventHandler(e){this._core.attachCustomWheelEventHandler(e)}registerLinkProvider(e){return this._core.registerLinkProvider(e)}registerCharacterJoiner(e){return this._checkProposedApi(),this._core.registerCharacterJoiner(e)}deregisterCharacterJoiner(e){this._checkProposedApi(),this._core.deregisterCharacterJoiner(e)}registerMarker(e=0){return this._verifyIntegers(e),this._core.registerMarker(e)}registerDecoration(e){return this._checkProposedApi(),this._verifyPositiveIntegers(e.x??0,e.width??0,e.height??0),this._core.registerDecoration(e)}hasSelection(){return this._core.hasSelection()}select(e,t,n){this._verifyIntegers(e,t,n),this._core.select(e,t,n)}getSelection(){return this._core.getSelection()}getSelectionPosition(){return this._core.getSelectionPosition()}clearSelection(){this._core.clearSelection()}selectAll(){this._core.selectAll()}selectLines(e,t){this._verifyIntegers(e,t),this._core.selectLines(e,t)}dispose(){super.dispose()}scrollLines(e){this._verifyIntegers(e),this._core.scrollLines(e)}scrollPages(e){this._verifyIntegers(e),this._core.scrollPages(e)}scrollToTop(){this._core.scrollToTop()}scrollToBottom(){this._core.scrollToBottom()}scrollToLine(e){this._verifyIntegers(e),this._core.scrollToLine(e)}clear(){this._core.clear()}write(e,t){this._core.write(e,t)}writeln(e,t){this._core.write(e),this._core.write(`\r
1533
+ `,t)}paste(e){this._core.paste(e)}refresh(e,t){this._verifyIntegers(e,t),this._core.refresh(e,t)}reset(){this._core.reset()}clearTextureAtlas(){this._core.clearTextureAtlas()}loadAddon(e){this._addonManager.loadAddon(this,e)}static get strings(){return{get promptLabel(){return cK.get()},set promptLabel(e){cK.set(e)},get tooMuchOutput(){return uK.get()},set tooMuchOutput(e){uK.set(e)}}}_verifyIntegers(...e){for($$ of e)if($$===1/0||isNaN($$)||$$%1!=0)throw Error(`This API only accepts integers`)}_verifyPositiveIntegers(...e){for($$ of e)if($$&&($$===1/0||isNaN($$)||$$%1!=0||$$<0))throw Error(`This API only accepts positive integers`)}},t1=2,n1=1,r1=class{activate(e){this._terminal=e}dispose(){}fit(){let e=this.proposeDimensions();if(!e||!this._terminal||isNaN(e.cols)||isNaN(e.rows))return;let t=this._terminal._core;(this._terminal.rows!==e.rows||this._terminal.cols!==e.cols)&&(t._renderService.clear(),this._terminal.resize(e.cols,e.rows))}proposeDimensions(){if(!this._terminal||!this._terminal.element||!this._terminal.element.parentElement)return;let e=this._terminal._core._renderService.dimensions;if(e.css.cell.width===0||e.css.cell.height===0)return;let t=this._terminal.options.scrollback===0?0:this._terminal.options.overviewRuler?.width||14,n=window.getComputedStyle(this._terminal.element.parentElement),r=parseInt(n.getPropertyValue(`height`)),i=Math.max(0,parseInt(n.getPropertyValue(`width`))),a=window.getComputedStyle(this._terminal.element),o={top:parseInt(a.getPropertyValue(`padding-top`)),bottom:parseInt(a.getPropertyValue(`padding-bottom`)),right:parseInt(a.getPropertyValue(`padding-right`)),left:parseInt(a.getPropertyValue(`padding-left`))},s=o.top+o.bottom,c=o.right+o.left,l=r-s,u=i-c-t;return{cols:Math.max(t1,Math.floor(u/e.css.cell.width)),rows:Math.max(n1,Math.floor(l/e.css.cell.height))}}},i1=class{constructor(e,t,n,r={}){this._terminal=e,this._regex=t,this._handler=n,this._options=r}provideLinks(e,t){let n=o1.computeLink(e,this._regex,this._terminal,this._handler);t(this._addCallbacks(n))}_addCallbacks(e){return e.map(e=>(e.leave=this._options.leave,e.hover=(t,n)=>{if(this._options.hover){let{range:r}=e;this._options.hover(t,n,r)}},e))}};function a1(e){try{let t=new URL(e),n=t.password&&t.username?`${t.protocol}//${t.username}:${t.password}@${t.host}`:t.username?`${t.protocol}//${t.username}@${t.host}`:`${t.protocol}//${t.host}`;return e.toLocaleLowerCase().startsWith(n.toLocaleLowerCase())}catch{return!1}}var o1=class e{static computeLink(t,n,r,i){let a=new RegExp(n.source,(n.flags||``)+`g`),[o,s]=e._getWindowedLineStrings(t-1,r),c=o.join(``),l,u=[];for(;l=a.exec(c);){let t=l[0];if(!a1(t))continue;let[n,a]=e._mapStrIdx(r,s,0,l.index),[o,c]=e._mapStrIdx(r,n,a,t.length);if(n===-1||a===-1||o===-1||c===-1)continue;let d={start:{x:a+1,y:n+1},end:{x:c,y:o+1}};u.push({range:d,text:t,activate:i})}return u}static _getWindowedLineStrings(e,t){let n,r=e,i=e,a=0,o=``,s=[];if(n=t.buffer.active.getLine(e)){let e=n.translateToString(!0);if(n.isWrapped&&e[0]!==` `){for(a=0;(n=t.buffer.active.getLine(--r))&&a<2048&&(o=n.translateToString(!0),a+=o.length,s.push(o),n.isWrapped&&o.indexOf(` `)===-1););s.reverse()}for(s.push(e),a=0;(n=t.buffer.active.getLine(++i))&&n.isWrapped&&a<2048&&(o=n.translateToString(!0),a+=o.length,s.push(o),o.indexOf(` `)===-1););}return[s,r]}static _mapStrIdx(e,t,n,r){let i=e.buffer.active,a=i.getNullCell(),o=n;for(;r;){let e=i.getLine(t);if(!e)return[-1,-1];for(let n=o;n<e.length;++n){e.getCell(n,a);let o=a.getChars();if(a.getWidth()&&(r-=o.length||1,n===e.length-1&&o===``)){let e=i.getLine(t+1);e&&e.isWrapped&&(e.getCell(0,a),a.getWidth()===2&&(r+=1))}if(r<0)return[t,n]}t++,o=0}return[t,o]}},s1=/(https?|HTTPS?):[/]{2}[^\s"'!*(){}|\\\^<>`]*[^\s"':,.!?{}|\\\^~\[\]`()<>]/;function c1(e,t){let n=window.open();if(n){try{n.opener=null}catch{}n.location.href=t}else console.warn(`Opening link blocked as opener could not be cleared`)}var l1=class{constructor(e=c1,t={}){this._handler=e,this._options=t}activate(e){this._terminal=e;let t=this._options,n=t.urlRegex||s1;this._linkProvider=this._terminal.registerLinkProvider(new i1(this._terminal,n,this._handler,t))}dispose(){this._linkProvider?.dispose()}};function u1(e,t,n){return r=>{let i=r.key.toLowerCase();if(!r.ctrlKey&&!r.metaKey||r.altKey)return!0;if(i===`c`&&e.hasSelection()){if(r.type===`keydown`){r.preventDefault();let i=e.getSelection();Promise.resolve().then(()=>t(i)).catch(n)}return!1}return i!==`v`}}var d1={background:`#09090b`,foreground:`#f4f4f5`,cursor:`#38bdf8`,cursorAccent:`#09090b`,selectionBackground:`rgba(56, 189, 248, 0.3)`,black:`#27272a`,red:`#f87171`,green:`#4ade80`,yellow:`#facc15`,blue:`#60a5fa`,magenta:`#c084fc`,cyan:`#38bdf8`,white:`#f4f4f5`,brightBlack:`#52525b`,brightRed:`#ef4444`,brightGreen:`#22c55e`,brightYellow:`#eab308`,brightBlue:`#3b82f6`,brightMagenta:`#a855f7`,brightCyan:`#06b6d4`,brightWhite:`#ffffff`},f1={background:`#ffffff`,foreground:`#18181b`,cursor:`#0284c7`,cursorAccent:`#ffffff`,selectionBackground:`rgba(2, 132, 199, 0.2)`,black:`#18181b`,red:`#dc2626`,green:`#16a34a`,yellow:`#ca8a04`,blue:`#2563eb`,magenta:`#9333ea`,cyan:`#0891b2`,white:`#e4e4e7`,brightBlack:`#71717a`,brightRed:`#b91c1c`,brightGreen:`#15803d`,brightYellow:`#a16207`,brightBlue:`#1d4ed8`,brightMagenta:`#7e22ce`,brightCyan:`#0e7490`,brightWhite:`#27272a`};function p1(e){if(!e)return``;let t=e.split(/[\\/]/).filter(Boolean);return t.length<=3?e:`…/`+t.slice(-3).join(`/`)}function m1({id:e,shellId:t,cwd:n,isActive:r,isPanelOpen:i,renaming:a,openTerminal:o,sendTerminalInput:s,getTerminalCwd:c,resizeTerminal:l,closeTerminal:u,subscribeTerminal:d,onCwdUpdate:f,registerClear:p}){let m=(0,v.useRef)(null),h=(0,v.useRef)(null),g=(0,v.useRef)(null),_=(0,v.useContext)(b)===`dark`,y=(0,v.useRef)({cwd:n,openTerminal:o,sendTerminalInput:s,getTerminalCwd:c,resizeTerminal:l,closeTerminal:u,subscribeTerminal:d,onCwdUpdate:f,registerClear:p});return y.current={cwd:n,openTerminal:o,sendTerminalInput:s,getTerminalCwd:c,resizeTerminal:l,closeTerminal:u,subscribeTerminal:d,onCwdUpdate:f,registerClear:p},(0,v.useEffect)(()=>{h.current&&(h.current.options.theme=_?d1:f1)},[_]),(0,v.useEffect)(()=>{if(!m.current)return;let n=new e1({cursorBlink:!0,cursorStyle:`block`,fontSize:13,fontFamily:`'JetBrains Mono', 'Fira Code', ui-monospace, Menlo, Monaco, 'Courier New', monospace`,lineHeight:1.2,theme:_?d1:f1}),r=new r1;n.loadAddon(r),n.loadAddon(new l1),n.open(m.current),r.fit(),n.attachCustomKeyEventHandler(u1(n,e=>navigator.clipboard.writeText(e),()=>n.writeln(`\r
1533
1534
  [Clipboard copy was refused by the browser.]`))),h.current=n,g.current=r,y.current.registerClear(e,()=>{n.clear()}),y.current.openTerminal?.(e,y.current.cwd,n.cols,n.rows,...t?[t]:[]);let i=null,a=0,o=()=>{let t=Date.now();t-a<1e3?i||=setTimeout(()=>{i=null,a=Date.now(),y.current.getTerminalCwd?.(e)},1e3-(t-a)):(a=t,y.current.getTerminalCwd?.(e))},s=n.onData(t=>{y.current.sendTerminalInput?.(e,t),(t.includes(`\r`)||t.includes(`
1534
- `))&&o()}),c=y.current.subscribeTerminal?.(e,{onData:t=>{n.write(t);let r=t.match(/\x1b\]7;file:\/\/[^/]*([^\x07\x1b]+)(?:\x07|\x1b\\)/);if(r&&r[1])try{let t=decodeURIComponent(r[1]);y.current.onCwdUpdate(e,t)}catch{}},onCwd:t=>{y.current.onCwdUpdate(e,t)},onExit:e=>{n.writeln(`\r\n\x1b[90m[Process completed (exit code ${e??0})]\x1b[0m`)},onError:e=>{n.writeln(`\r\n\x1b[31m[Terminal error: ${e}]\x1b[0m`)}})??(()=>{}),l=new ResizeObserver(()=>{if(m.current&&m.current.clientWidth>0&&m.current.clientHeight>0)try{r.fit(),n.cols>0&&n.rows>0&&y.current.resizeTerminal?.(e,n.cols,n.rows)}catch{}});return l.observe(m.current),()=>{s.dispose(),c(),l.disconnect(),n.dispose(),y.current.closeTerminal?.(e)}},[e]),(0,v.useEffect)(()=>{if(!a&&i&&r&&g.current&&h.current&&m.current){y.current.getTerminalCwd?.(e);let t=setTimeout(()=>{try{g.current?.fit(),h.current?.focus()}catch{}},50);return()=>clearTimeout(t)}},[i,r,e,a]),(0,N.jsx)(`div`,{ref:m,className:`h-full w-full p-2 bg-white dark:bg-zinc-950 overflow-hidden ${r?`block`:`hidden`}`})}function m1({shells:e,open:t,onClose:n,cwd:r,confinedRoot:i,confinement:a,unavailable:o,onSetWorkspaceRoot:s,openTerminal:c,sendTerminalInput:l,getTerminalCwd:u,resizeTerminal:d,closeTerminal:f,subscribeTerminal:p}){let[m,h]=(0,v.useState)(``),g=e?.some(e=>e.id===m)?m:``,[_,y]=(0,v.useState)(t);(0,v.useEffect)(()=>{t&&y(!0)},[t]);let[b,x]=(0,v.useState)([{id:`term-1`,title:`terminal 1`}]),[S,C]=(0,v.useState)(`term-1`),[w,T]=(0,v.useState)(null),[E,D]=(0,v.useState)(``),[O,ee]=(0,v.useState)({}),[te,k]=(0,v.useState)(!1),ne=zU(PU,`y`),[A,re]=(0,v.useState)(!1),j=(0,v.useRef)(new Map),ie=(0,v.useCallback)((e,t)=>{j.current.set(e,t)},[]),ae=(0,v.useCallback)((e,t)=>{ee(n=>({...n,[e]:t}))},[]),oe=(0,v.useCallback)(()=>{let e=b.length+1,t=`term-${crypto.randomUUID()}`,n={id:t,title:`terminal ${e}`,...g?{shellId:g}:{}};x(e=>[...e,n]),C(t)},[b.length,g]),se=(0,v.useCallback)((e,t)=>{t.stopPropagation(),b.length<=1?n():(x(t=>{let n=t.filter(t=>t.id!==e);if(S===e){let r=t.findIndex(t=>t.id===e),i=n[Math.max(0,r-1)]?.id??n[0]?.id;C(i)}return n}),j.current.delete(e),ee(t=>{let n={...t};return delete n[e],n}))},[b.length,S,n]),ce=(e,t)=>{t.stopPropagation(),T(e.id),D(e.title)},le=()=>{if(w){let e=E.trim();e&&x(t=>t.map(t=>t.id===w?{...t,title:e}:t)),T(null)}},ue=e=>{e.key===`Enter`?le():e.key===`Escape`&&T(null)},de=(0,v.useCallback)(()=>{let e=j.current.get(S);e&&e()},[S]),fe=O[S]||r||``;return _?(0,N.jsxs)(`div`,{style:{height:te?`85vh`:ne.width,maxHeight:te?`85vh`:`65vh`},className:`flex-col shrink-0 border-t border-zinc-200 dark:border-zinc-800 bg-zinc-100 dark:bg-zinc-900 ${t?`flex`:`hidden`} relative z-20`,children:[!te&&(0,N.jsx)(BU,{axis:`y`,label:`Resize Terminal panel`,width:ne.width,config:PU,separatorProps:ne.separatorProps}),(0,N.jsxs)(`div`,{className:`flex items-center justify-between px-2 py-1 border-b border-zinc-200 dark:border-zinc-800 select-none bg-zinc-50 dark:bg-zinc-950 text-xs`,children:[(0,N.jsxs)(`div`,{className:`flex items-center space-x-1 overflow-x-auto min-w-0`,children:[(0,N.jsx)(`div`,{className:`flex items-center space-x-1`,children:b.map(e=>{let t=e.id===S,n=e.id===w;return(0,N.jsxs)(`div`,{onClick:()=>C(e.id),onDoubleClick:t=>ce(e,t),title:`Double-click to rename tab`,className:`flex items-center space-x-1 px-2.5 py-1 rounded text-xs cursor-pointer transition-colors ${t?`bg-zinc-200 dark:bg-zinc-800 text-zinc-900 dark:text-zinc-100 font-medium shadow-sm`:`text-zinc-500 hover:text-zinc-800 dark:text-zinc-400 dark:hover:text-zinc-200 hover:bg-zinc-200/50 dark:hover:bg-zinc-800/50`}`,children:[n?(0,N.jsx)(`input`,{type:`text`,"data-testid":`terminal-tab-rename-input`,value:E,autoFocus:!0,onChange:e=>D(e.target.value),onBlur:le,onKeyDown:ue,className:`bg-transparent border border-sky-500 rounded px-1 py-0 text-xs font-mono outline-none text-zinc-900 dark:text-zinc-100 w-24`}):(0,N.jsx)(`span`,{children:e.title}),b.length>1&&(0,N.jsx)(`span`,{onClick:t=>se(e.id,t),role:`button`,tabIndex:0,"aria-label":`Close terminal tab`,className:`ml-1 hover:text-red-500 rounded p-0.5 hover:bg-zinc-200 dark:hover:bg-zinc-700`,children:(0,N.jsx)(`svg`,{className:`w-3 h-3`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,N.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M6 18L18 6M6 6l12 12`})})})]},e.id)})}),e&&e.length>0&&(0,N.jsxs)(`select`,{"aria-label":`Shell for new terminal`,value:g,onChange:e=>h(e.target.value),disabled:!!o,className:`min-w-0 max-w-40 rounded border border-zinc-300 bg-zinc-50 text-xs text-zinc-800 dark:border-zinc-700 dark:bg-zinc-950 dark:text-zinc-200`,children:[(0,N.jsx)(`option`,{value:``,children:`Default shell`}),e.map(e=>(0,N.jsx)(`option`,{value:e.id,children:e.label},e.id))]}),(0,N.jsx)(`button`,{onClick:oe,type:`button`,title:`New Terminal Tab`,className:`p-1 rounded text-zinc-500 hover:text-zinc-800 dark:text-zinc-400 dark:hover:text-zinc-200 hover:bg-zinc-200/60 dark:hover:bg-zinc-800/60`,children:(0,N.jsx)(`svg`,{className:`w-3.5 h-3.5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,N.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M12 4v16m8-8H4`})})})]}),i&&!o&&(0,N.jsx)(xG,{verdict:a??{state:`checking`,runner:``},surface:`terminal`,root:f1(i)}),fe&&(0,N.jsx)(`div`,{className:`hidden md:flex items-center space-x-1.5 px-2 text-xs font-mono text-zinc-500 dark:text-zinc-400`,children:s&&(0,N.jsx)(`button`,{onClick:()=>{if(fe&&s){if((fe===`/`||fe===`\\`||/^[A-Za-z]:[\\/]?$/.test(fe))&&!window.confirm(`Open root filesystem "${fe}" as the workspace project?`))return;s(fe),re(!0),setTimeout(()=>re(!1),2e3)}},type:`button`,title:`Open "${fe}" as the workspace project and reposition the LLM agent`,className:`flex items-center space-x-1 px-1.5 py-0.5 rounded text-[11px] font-sans transition-colors ${A?`bg-emerald-500 text-white font-medium`:`bg-zinc-200/80 hover:bg-sky-500 hover:text-white dark:bg-zinc-800 dark:hover:bg-sky-600 dark:hover:text-white text-zinc-700 dark:text-zinc-300`}`,children:(0,N.jsx)(`span`,{children:A?`✓ Project opened`:`📁 ${f1(fe)} → open as project`})})}),(0,N.jsxs)(`div`,{className:`flex items-center space-x-1 text-zinc-500 dark:text-zinc-400`,children:[(0,N.jsx)(`button`,{onClick:de,type:`button`,title:`Clear Terminal Output`,className:`p-1 rounded hover:text-zinc-800 dark:hover:text-zinc-200 hover:bg-zinc-200/60 dark:hover:bg-zinc-800/60`,children:(0,N.jsx)(`svg`,{className:`w-3.5 h-3.5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,N.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16`})})}),(0,N.jsx)(`button`,{onClick:()=>k(e=>!e),type:`button`,title:te?`Restore Terminal Panel`:`Maximize Terminal Panel`,className:`p-1 rounded hover:text-zinc-800 dark:hover:text-zinc-200 hover:bg-zinc-200/60 dark:hover:bg-zinc-800/60`,children:te?(0,N.jsx)(`svg`,{className:`w-3.5 h-3.5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,N.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M19 9l-7 7-7-7`})}):(0,N.jsx)(`svg`,{className:`w-3.5 h-3.5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,N.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M5 15l7-7 7 7`})})}),(0,N.jsx)(`button`,{onClick:n,type:`button`,title:"Minimize Terminal Panel (Ctrl+`)",className:`p-1 rounded hover:text-zinc-800 dark:hover:text-zinc-200 hover:bg-zinc-200/60 dark:hover:bg-zinc-800/60`,children:(0,N.jsx)(`svg`,{className:`w-3.5 h-3.5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,N.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M6 18L18 6M6 6l12 12`})})})]})]}),(0,N.jsx)(`div`,{className:`flex-1 min-h-0 relative`,children:o?(0,N.jsxs)(`div`,{role:`status`,"data-testid":`terminal-unavailable`,className:`p-3 text-xs text-amber-700 dark:text-amber-300`,children:[(0,N.jsx)(`p`,{className:`font-medium`,children:`The terminal is unavailable.`}),(0,N.jsx)(`p`,{className:`mt-1 break-words font-mono`,children:o})]}):b.map(e=>(0,N.jsx)(p1,{id:e.id,shellId:e.shellId,cwd:r,isActive:e.id===S,isPanelOpen:t,renaming:w!==null,openTerminal:c,sendTerminalInput:l,getTerminalCwd:u,resizeTerminal:d,closeTerminal:f,subscribeTerminal:p,onCwdUpdate:ae,registerClear:ie},e.id))})]}):null}var h1={todo:{label:`To do`,className:`text-zinc-500`},in_progress:{label:`In progress`,className:`text-blue-600 dark:text-blue-400`},done:{label:`Done`,className:`text-emerald-600 dark:text-emerald-400`},blocked:{label:`Blocked`,className:`text-red-600 dark:text-red-400`},needs_review:{label:`Needs review`,className:`text-amber-600 dark:text-amber-400`},passed:{label:`Passed`,className:`text-emerald-600 dark:text-emerald-400`},failed:{label:`Failed`,className:`text-red-600 dark:text-red-400`},inconclusive:{label:`Inconclusive`,className:`text-amber-600 dark:text-amber-400`},informational:{label:`Informational`,className:`text-zinc-500`},modified:{label:`Modified`,className:`text-blue-600 dark:text-blue-400`},added:{label:`Added`,className:`text-emerald-600 dark:text-emerald-400`},deleted:{label:`Deleted`,className:`text-red-600 dark:text-red-400`},untracked:{label:`Untracked`,className:`text-zinc-600 dark:text-zinc-300`},conflicted:{label:`Conflicted`,className:`text-red-600 dark:text-red-400`},unavailable:{label:`Unavailable`,className:`text-red-600 dark:text-red-400`},"not-recorded":{label:`Not recorded`,className:`text-zinc-500`}};function g1(e){return h1[e]??{label:e,className:`text-zinc-500`}}function _1({entry:e,onTarget:t}){let n=g1(e.status),r=(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,N.jsx)(`span`,{className:`min-w-0 break-words text-sm font-medium text-zinc-900 dark:text-zinc-100`,children:e.title}),(0,N.jsx)(`span`,{className:`shrink-0 text-[11px] font-semibold uppercase tracking-wide ${n.className}`,children:n.label})]}),e.group&&(0,N.jsx)(`div`,{className:`mt-0.5 text-[11px] text-zinc-500`,children:e.group}),e.detail&&(0,N.jsx)(`p`,{className:`mt-1 whitespace-pre-wrap text-xs text-zinc-600 dark:text-zinc-300`,children:e.detail}),e.reference&&(0,N.jsx)(`div`,{className:`mt-1 truncate text-xs text-zinc-500`,children:e.reference}),(0,N.jsx)(`div`,{className:`mt-1 text-[10px] uppercase tracking-wide text-zinc-400`,children:e.source})]}),i=`block w-full rounded-md border border-zinc-200 p-2 text-left hover:bg-zinc-50 dark:border-zinc-800 dark:hover:bg-zinc-900`;return e.target?.kind===`external-url`?(0,N.jsx)(`a`,{href:e.target.url,target:`_blank`,rel:`noreferrer`,className:i,children:r}):e.target?(0,N.jsx)(`button`,{type:`button`,onClick:()=>t(e.target),className:i,children:r}):(0,N.jsx)(`div`,{className:`rounded-md border border-zinc-200 p-2 dark:border-zinc-800`,children:r})}function v1({state:e,onClose:t,onRefresh:n,onTarget:r}){return(0,N.jsxs)(`aside`,{"aria-label":`Workspace Outcome`,className:`absolute inset-y-0 right-0 z-10 flex w-full flex-col border-l border-zinc-200 bg-white/95 shadow-lg backdrop-blur md:w-[26rem] dark:border-zinc-800 dark:bg-zinc-950/95`,children:[(0,N.jsxs)(`header`,{className:`flex items-start justify-between gap-2 border-b border-zinc-200 px-3 py-3 dark:border-zinc-800`,children:[(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`div`,{className:`text-[11px] font-semibold uppercase tracking-wide text-zinc-500`,children:`Workspace review`}),(0,N.jsx)(`h2`,{className:`text-sm font-semibold text-zinc-900 dark:text-zinc-100`,children:`Outcome`})]}),(0,N.jsxs)(`div`,{className:`flex gap-1`,children:[(0,N.jsx)(`button`,{type:`button`,onClick:n,className:`rounded px-2 py-1 text-xs text-zinc-500 hover:bg-zinc-100 dark:hover:bg-zinc-800`,children:`Refresh`}),(0,N.jsx)(`button`,{type:`button`,onClick:t,className:`rounded px-2 py-1 text-xs text-zinc-500 hover:bg-zinc-100 dark:hover:bg-zinc-800`,"aria-label":`Close Outcome`,children:`×`})]})]}),(0,N.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-3`,children:e===null||e.status===`loading`?(0,N.jsx)(`div`,{role:`status`,className:`text-sm text-zinc-500`,children:`Loading Outcome…`}):e.status===`error`?(0,N.jsx)(`div`,{role:`alert`,className:`rounded-md border border-red-200 bg-red-50 p-3 text-sm text-red-700 dark:border-red-900 dark:bg-red-950/30 dark:text-red-300`,children:e.message}):(0,N.jsx)(`div`,{className:`space-y-4`,children:e.outcome.sections.map(e=>(0,N.jsxs)(`section`,{"aria-labelledby":`outcome-${e.id}`,className:`rounded-lg border border-zinc-200 p-3 dark:border-zinc-800`,children:[(0,N.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,N.jsx)(`h3`,{id:`outcome-${e.id}`,className:`text-sm font-semibold text-zinc-900 dark:text-zinc-100`,children:e.title}),e.availability===`partial`||e.availability===`unavailable`?(0,N.jsx)(`span`,{className:`text-[11px] font-semibold uppercase text-red-600 dark:text-red-400`,children:e.availability}):null]}),e.summary&&(0,N.jsx)(`p`,{className:`mt-1 text-xs text-zinc-600 dark:text-zinc-300`,children:e.summary}),e.entries.length>0&&(0,N.jsx)(`div`,{className:`mt-3 space-y-2`,children:e.entries.map(e=>(0,N.jsx)(_1,{entry:e,onTarget:r},e.id))})]},e.id))})})]})}function y1(){if(typeof crypto.randomUUID==`function`)return crypto.randomUUID();let e=crypto.getRandomValues(new Uint8Array(16));e[6]=e[6]&15|64,e[8]=e[8]&63|128;let t=Array.from(e,e=>e.toString(16).padStart(2,`0`));return`${t.slice(0,4).join(``)}-${t.slice(4,6).join(``)}-${t.slice(6,8).join(``)}-${t.slice(8,10).join(``)}-${t.slice(10).join(``)}`}var b1=`pi-outpost:token`;function x1(){let e=null;try{let t=new URL(window.location.href);return e=t.searchParams.get(`token`),e&&(localStorage.setItem(b1,e),t.searchParams.delete(`token`),window.history.replaceState(null,``,`${t.pathname}${t.search}${t.hash}`)),localStorage.getItem(b1)}catch{return e}}function S1(){try{return localStorage.getItem(b1)}catch{return null}}function C1(e){try{localStorage.setItem(b1,e)}catch{}}var w1=class extends Error{kind;constructor(e,t){super(e),this.name=`HistoryError`,this.kind=t}};async function T1(e,t){let n=[];for(;;){let r=await e(n.length,50);if(r.items.length===0||(n.unshift(...r.items),t?.(n.length),r.remaining===0))return n}}function E1(e){let t=e.lastIndexOf(`/`);return t<0?``:e.slice(0,t)}function D1(e,t){return e.base.rev===t.base.rev&&e.base.path===t.base.path&&e.target.rev===t.target.rev&&e.target.path===t.target.path}function O1(){return{clonePath:null,preview:null,enrollment:null,refresh:null,updates:{},skills:{},removals:{}}}var k1={login:null,connected:!1,workspace:null,workspaces:[],workspaceLocked:!1,embedWorkspaceControls:`settings`,switching:!1,agentStarting:!1,authRequired:!1,brandingReady:!1,branding:{},sessionId:``,sessionName:null,model:``,thinkingLevel:`off`,modelSupportsReasoning:!1,models:[],commands:[],extensionsBinding:!1,sessions:null,sessionSearch:null,tree:null,isStreaming:!1,items:[],olderHistory:null,pendingPrompt:null,workPlan:null,replyConformance:{},structuredAppearance:null,outpostUpdate:null,outpostChanges:null,piPackages:null,piPackageUpdate:null,serverRestarting:!1,restartNeeded:[],outcome:null,queue:{steering:[],followUp:[]},errors:[],contextUsage:null,isCompacting:!1,dialogQueue:[],sandboxGrants:null,notifications:[],statuses:{},widgets:{},editorPrefill:null,fileTree:{},directoryRequests:{},openFile:null,previewRevision:0,fileSearch:null,contentSearch:null,createError:null,created:null,fileOperation:null,extensionPaths:null,configuredExtensionPaths:[],userExtensionPaths:[],extensionLock:!1,tools:[],sandbox:null,terminal:null,userSkillPaths:[],serverBrowse:null,settingsApply:null,agentResources:null,agentResourceOperations:O1(),versions:null,gitAvailable:!1,gitUnavailable:null,credentials:null,gitStatus:null,gitDiff:null,gitBaseline:null,gitLog:null,gitShow:null,gitFileHistory:null,gitFileDiff:null};function A1(e,t){if(!e.startsWith(`/`))return!1;let n=e.indexOf(` `),r=n===-1?e.slice(1):e.slice(1,n);return t.some(e=>e.source===`extension`&&e.name===r)}function j1(e,t){for(let n=e.length-1;n>=0;n--){let r=e[n];if(r.kind===`assistant`&&r.streaming){let i=[...e];return i[n]=t(r),i}}return[...e,t({kind:`assistant`,blocks:[],streaming:!0})]}function M1(e,t,n,r){for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.kind===`tool`&&i.toolCallId===t){let t=[...e];return t[n]={...i,...r},t}}return[...e,{kind:`tool`,toolCallId:t,toolName:n,args:{},output:``,running:!0,...r}]}function N1(e,t,n){for(let r=e.length-1;r>=0;r--){let i=e[r];if(i.kind===`tool`&&i.toolCallId===t){let t=[...e];return t[r]={...i,...n},t}}return e}function P1(e,t){if(t.type!==`hello`&&t.type!==`session_replaced`&&t.type!==`update_config_ack`&&t.type!==`workspace_switched`&&t.type!==`workspace_starting`)return e;let n=t.models.find(e=>`${e.provider}/${e.id}`===t.model);return{...e,replyConformance:{},structuredAppearance:t.type===`workspace_switched`||t.type===`workspace_starting`?null:e.structuredAppearance,agentStarting:t.agentStarting===!0,outpostUpdate:t.outpostUpdate??e.outpostUpdate,outpostChanges:t.outpostChanges??e.outpostChanges,piPackages:t.piPackages??e.piPackages,serverRestarting:!1,restartNeeded:t.restartNeeded??[],connected:!0,brandingReady:!0,workspace:t.workspace??null,workspaces:t.workspaces??[],workspaceLocked:t.workspaceLocked===!0,embedWorkspaceControls:t.embedWorkspaceControls??`settings`,switching:!1,branding:t.branding,sessionId:t.sessionId,sessionName:t.sessionName??null,model:t.model,thinkingLevel:t.thinkingLevel,thinkingLevels:t.thinkingLevels,modelSupportsReasoning:n?.reasoning??!1,models:t.models,commands:t.commands,extensionsBinding:t.extensionsBinding===!0,isStreaming:t.isStreaming,items:t.items,olderHistory:t.olderItems?{remaining:t.olderItems,have:0,loading:!1,error:null}:null,pendingPrompt:null,workPlan:t.workPlan??null,outcome:null,queue:{steering:[],followUp:[]},errors:[],contextUsage:t.contextUsage??null,isCompacting:!1,dialogQueue:[],notifications:[],statuses:{},widgets:{},extensionTitle:void 0,editorPrefill:null,tree:null,fileTree:{},directoryRequests:{},fileOperation:null,writableRoot:t.writableRoot,docxTemplate:t.docxTemplate,gitAvailable:t.gitAvailable===!0,gitUnavailable:t.gitUnavailable??null,credentials:t.credentials??null,extensionPaths:t.extensionPaths??null,configuredExtensionPaths:t.configuredExtensionPaths??[],userExtensionPaths:t.userExtensionPaths??[],extensionLock:t.extensionLock===!0,tools:t.tools??[],sandbox:t.sandbox??null,terminal:t.terminal??null,confinement:t.confinement??null,sandboxGrants:t.sandboxGrants??null,userSkillPaths:t.userSkillPaths??[],serverBrowse:null,settingsApply:null,versions:t.versions??null,agentResources:t.agentResources??null,agentResourceOperations:t.type===`hello`||t.type===`workspace_switched`||t.type===`workspace_starting`?O1():e.agentResourceOperations}}function F1(e,t){if(t.type===`connected`)return{...e,connected:!0,authRequired:!1};if(t.type===`workspace_switching`)return{...e,switching:!0};if(t.type===`pi_package_update_started`)return{...e,piPackageUpdate:{requestId:t.requestId,source:t.source,status:`pending`}};if(t.type===`auth_required`)return{...e,connected:!1,authRequired:!0};if(t.type===`auth_retrying`)return{...e,authRequired:!1};if(t.type===`login_started`)return{...e,login:{flowId:t.flowId,provider:t.provider,method:t.method,events:[],prompt:null,done:null}};if(t.type===`login_answered`)return e.login?{...e,login:{...e.login,prompt:null}}:e;if(t.type===`login_dismissed`)return{...e,login:null};if(t.type===`disconnected`&&e.login&&!e.login.done&&(e={...e,login:{...e.login,prompt:null,done:{ok:!1,message:`Connection lost — the sign-in was stopped. Start it again.`}}}),t.type===`disconnected`){let t=e.openFile,n=t?.status===`loaded`&&t.pendingSave!==void 0?{...t,pendingSave:void 0,saveError:{message:`Connection lost while saving — try again`,conflict:!1}}:e.openFile,r=e.outcome?.status===`loading`?{...e.outcome,status:`error`,message:`Connection lost while loading Outcome.`}:e.outcome;return{...e,connected:!1,openFile:n,outcome:r}}if(t.type===`branding_settled`)return{...e,brandingReady:!0};if(t.type===`branding_loaded`)return{...e,brandingReady:!0,branding:t.branding};if(t.type===`prompt_sent`)return A1(t.text,e.commands)?e:{...e,pendingPrompt:{text:t.text,...t.images?.length?{images:t.images}:{}}};if(t.type===`pending_prompt_cancelled`)return!t.restoreText||!e.pendingPrompt?e:{...e,editorPrefill:{text:e.pendingPrompt.text,nonce:e.editorPrefill?e.editorPrefill.nonce+1:1}};if(t.type===`dismiss_notification`)return{...e,notifications:e.notifications.filter(e=>e.id!==t.id)};if(t.type===`dialog_answered`)return{...e,dialogQueue:e.dialogQueue.slice(1)};if(t.type===`dir_list_started`){let n=e.fileTree[t.path];return{...e,fileTree:{...e.fileTree,[t.path]:t.preserveEntries&&Array.isArray(n)?n:`loading`},directoryRequests:{...e.directoryRequests,[t.path]:t.requestId}}}if(t.type===`raw_preview_changed`)return e.openFile?.path===t.path?{...e,previewRevision:e.previewRevision+1}:e;if(t.type===`file_read_started`){let n=e.openFile;return t.preserveContent&&n?.status===`loaded`&&n.path===t.path?{...e,openFile:{...n,refreshRequestId:t.requestId}}:{...e,openFile:{status:`loading`,path:t.path,requestId:t.requestId,...t.reveal?{reveal:t.reveal}:{}}}}if(t.type===`file_save_started`){let n=e.openFile;return!e.connected||n?.status!==`loaded`||n.path!==t.path?e:{...e,openFile:{...n,pendingSave:{requestId:t.requestId,content:t.content},saveError:void 0}}}if(t.type===`close_file_preview`)return{...e,openFile:null};if(t.type===`file_search_started`)return{...e,fileSearch:{status:`loading`,query:t.query,requestId:t.requestId,results:[]}};if(t.type===`file_search_cleared`)return{...e,fileSearch:null};if(t.type===`content_search_started`)return{...e,contentSearch:{status:`loading`,query:t.query,requestId:t.requestId,hits:[],truncated:!1,skipped:0}};if(t.type===`content_search_cleared`)return{...e,contentSearch:null};if(t.type===`file_create_started`)return{...e,createError:null,created:null};if(t.type===`file_operation_started`)return{...e,fileOperation:{status:`pending`,operation:t.operation,path:t.path,requestId:t.requestId}};if(t.type===`session_search_started`)return{...e,sessionSearch:{status:`loading`,query:t.query,requestId:t.requestId,results:[]}};if(t.type===`session_search_cleared`)return{...e,sessionSearch:null};if(t.type===`history_load_started`)return e.olderHistory?{...e,olderHistory:{...e.olderHistory,loading:!0,error:null}}:e;if(t.type===`history_loaded`)return e.olderHistory?{...e,items:[...t.items,...e.items],olderHistory:{remaining:t.remaining,have:e.olderHistory.have+t.items.length,loading:!1,error:null}}:e;if(t.type===`history_load_failed`)return e.olderHistory?{...e,olderHistory:{...e.olderHistory,loading:!1,error:t.message}}:e;if(t.type===`git_diff_started`||t.type===`git_diff_cleared`)return{...e,gitDiff:null};if(t.type===`git_baseline_started`){let n=e.gitBaseline?.path===t.path?e.gitBaseline.text:void 0;return{...e,gitBaseline:{path:t.path,requestId:t.requestId,...n===void 0?{}:{text:n}}}}if(t.type===`git_baseline_cleared`)return{...e,gitBaseline:null};if(t.type===`git_show_cleared`)return{...e,gitShow:null,gitLog:e.gitLog};if(t.type===`git_log_started`){let n=e.gitLog?.repo===t.repo?e.gitLog.entries:null;return{...e,gitLog:{repo:t.repo,entries:n,error:null,requestId:t.requestId}}}if(t.type===`git_log_closed`)return e.gitLog===null?e:{...e,gitLog:null};if(t.type===`git_file_history_started`)return{...e,gitFileHistory:{path:t.path,status:`loading`,entries:[],requestId:t.requestId},gitFileDiff:null};if(t.type===`git_file_history_closed`)return{...e,gitFileHistory:null,gitFileDiff:null};if(t.type===`git_file_diff_started`)return{...e,gitFileDiff:{base:t.base,target:t.target,status:`loading`,beforeText:e.gitFileDiff?.beforeText??``,afterText:e.gitFileDiff?.afterText??``,requestId:t.requestId}};if(t.type===`git_file_diff_cleared`)return{...e,gitFileDiff:null};if(t.type===`server_browse_started`)return{...e,serverBrowse:{status:`loading`,path:e.serverBrowse?.path??t.path,parent:e.serverBrowse?.parent??null,entries:e.serverBrowse?.entries??[],requestId:t.requestId}};if(t.type===`server_browse_closed`)return{...e,serverBrowse:null};if(t.type===`settings_apply_started`)return{...e,settingsApply:{status:`applying`}};if(t.type===`resource_clone_path_started`)return{...e,agentResourceOperations:{...e.agentResourceOperations,clonePath:{requestId:t.requestId,status:`loading`}}};if(t.type===`resource_preview_started`)return{...e,agentResourceOperations:{...e.agentResourceOperations,preview:{requestId:t.requestId,status:`loading`}}};if(t.type===`resource_enrollment_started`)return{...e,agentResourceOperations:{...e.agentResourceOperations,enrollment:{requestId:t.requestId,status:`loading`}}};if(t.type===`resource_refresh_started`)return{...e,agentResourceOperations:{...e.agentResourceOperations,refresh:{requestId:t.requestId,status:`loading`,...t.repositoryId?{repositoryId:t.repositoryId}:{}}}};if(t.type===`resource_update_started`)return{...e,agentResourceOperations:{...e.agentResourceOperations,updates:{...e.agentResourceOperations.updates,[t.repositoryId]:{requestId:t.requestId,status:`loading`}}}};if(t.type===`resource_skills_started`){let n=e.agentResourceOperations;return{...e,agentResourceOperations:{...n,skills:{...n.skills,[t.repositoryId]:{requestId:t.requestId,status:`loading`}}}}}if(t.type===`resource_removal_started`){let n=e.agentResourceOperations;return{...e,agentResourceOperations:{...n,removals:{...n.removals,[t.repositoryId]:{requestId:t.requestId,status:`loading`}}}}}if(t.type===`outcome_started`)return{...e,outcome:{status:`loading`,requestId:t.requestId,workspaceRoot:t.workspaceRoot,sessionId:t.sessionId}};if(t.type===`outcome_failed`){let n=e.outcome;return n===null||n.status!==`loading`||n.requestId!==t.requestId?e:{...e,outcome:{...n,status:`error`,message:t.message}}}let n=t.message;if(n.type===`workspace_switched`&&e.agentStarting&&e.workspace&&n.workspace&&GB(n.workspace)===GB(e.workspace))return{...P1(e,n),openFile:e.openFile,gitDiff:e.gitDiff,gitBaseline:e.gitBaseline,fileTree:e.fileTree,directoryRequests:e.directoryRequests,contentSearch:e.contentSearch};switch(n.type){case`workspace_switched`:case`hello`:case`session_replaced`:case`update_config_ack`:case`workspace_starting`:return{...P1(e,n),openFile:null,gitDiff:null,gitBaseline:null,fileTree:{},directoryRequests:{},contentSearch:n.type===`session_replaced`?e.contentSearch:null};case`workspace_activity`:return{...e,workspaces:n.workspaces,workspace:(e.workspace&&n.workspaces.find(t=>GB(t)===GB(e.workspace)))??e.workspace};case`agent_resource_clone_path`:{let t=e.agentResourceOperations.clonePath;return t?.requestId===n.requestId?{...e,agentResourceOperations:{...e.agentResourceOperations,clonePath:{...t,status:`ready`,path:n.path}}}:e}case`agent_resource_preview`:{let t=e.agentResourceOperations.preview;return t?.requestId===n.requestId?{...e,agentResourceOperations:{...e.agentResourceOperations,preview:{...t,status:`ready`,preview:n.preview}}}:e}case`agent_resource_enrolled`:{let t=e.agentResourceOperations.enrollment;return t?.requestId===n.requestId?{...e,agentResources:n.inventory,agentResourceOperations:{...e.agentResourceOperations,preview:null,enrollment:{...t,status:`ready`}}}:e}case`agent_resource_assessments`:{let t=e.agentResourceOperations.refresh;if(t?.requestId!==n.requestId||!e.agentResources)return e;let r=new Map(n.assessments.map(e=>[e.repositoryId,e]));return{...e,agentResources:{...e.agentResources,repositories:e.agentResources.repositories.map(e=>({...e,assessment:r.get(e.id)??e.assessment}))},agentResourceOperations:{...e.agentResourceOperations,refresh:{...t,status:`ready`}}}}case`agent_resource_inventory`:return{...e,agentResources:n.inventory};case`agent_resource_update_result`:{let t=n.result.repositoryId;if(!t)return e;let r=e.agentResourceOperations.updates[t];return r?.requestId===n.requestId?{...e,agentResources:n.inventory,agentResourceOperations:{...e.agentResourceOperations,updates:{...e.agentResourceOperations.updates,[t]:{...r,status:`ready`,result:n.result}}}}:e}case`agent_resource_skills_applied`:{let t=e.agentResourceOperations,r=t.skills[n.repositoryId];return r?.requestId===n.requestId?{...e,agentResources:n.inventory,agentResourceOperations:{...t,skills:{...t.skills,[n.repositoryId]:{...r,status:`ready`}}}}:e}case`agent_resource_removed`:{let t=e.agentResourceOperations,r=t.removals[n.repositoryId];return r?.requestId===n.requestId?{...e,agentResources:n.inventory,agentResourceOperations:{...t,removals:{...t.removals,[n.repositoryId]:{...r,status:`ready`,result:n.result}}}}:e}case`agent_resource_error`:{let t=e=>e?.requestId===n.requestId?{...e,status:`error`,message:n.message}:null,r=t(e.agentResourceOperations.clonePath),i=t(e.agentResourceOperations.preview),a=t(e.agentResourceOperations.enrollment),o=t(e.agentResourceOperations.refresh),s=e=>{let t=Object.entries(e).find(([,e])=>e.requestId===n.requestId);return t?{...e,[t[0]]:{...t[1],status:`error`,message:n.message}}:null},c=s(e.agentResourceOperations.updates),l=s(e.agentResourceOperations.skills),u=s(e.agentResourceOperations.removals);return!r&&!i&&!a&&!o&&!c&&!l&&!u?e:{...e,agentResourceOperations:{...e.agentResourceOperations,...r?{clonePath:r}:{},...i?{preview:i}:{},...a?{enrollment:a}:{},...o?{refresh:o}:{},...c?{updates:c}:{},...l?{skills:l}:{},...u?{removals:u}:{}}}}case`workspace_error`:return{...e,switching:!1,errors:[...e.errors,n.message]};case`sessions`:return{...e,sessions:n.sessions};case`session_search_results`:return e.sessionSearch?.requestId===n.requestId?{...e,sessionSearch:{...e.sessionSearch,status:`loaded`,results:n.sessions}}:e;case`tree`:return{...e,tree:n.roots};case`editor_prefill`:return{...e,editorPrefill:{text:n.text,nonce:e.editorPrefill?e.editorPrefill.nonce+1:1}};case`model_changed`:return{...e,model:n.model,modelSupportsReasoning:n.reasoning,thinkingLevels:n.thinkingLevels};case`login_event`:return e.login?.flowId===n.flowId?{...e,login:{...e.login,events:[...e.login.events,n.event]}}:e;case`login_prompt`:return e.login?.flowId===n.flowId?{...e,login:{...e.login,prompt:{promptId:n.promptId,prompt:n.prompt}}}:e;case`login_prompt_cancelled`:return e.login?.flowId!==n.flowId||e.login.prompt?.promptId!==n.promptId?e:{...e,login:{...e.login,prompt:null}};case`login_done`:return e.login?.flowId===n.flowId?{...e,login:{...e.login,prompt:null,done:{ok:n.ok,...n.cancelled?{cancelled:!0}:{},...n.message?{message:n.message}:{}}}}:e;case`credentials_changed`:{let t=n.models.find(e=>`${e.provider}/${e.id}`===n.model);return{...e,models:n.models,model:n.model,modelSupportsReasoning:t?.reasoning??!1,thinkingLevels:void 0,credentials:n.credentials}}case`extensions_bound`:return{...e,commands:n.commands,tools:n.tools??e.tools,extensionsBinding:!1};case`thinking_changed`:return{...e,thinkingLevel:n.level};case`work_plan_changed`:return{...e,workPlan:n.workPlan};case`workspace_outcome`:{let t=e.outcome;return t===null||t.requestId!==n.requestId||t.sessionId!==e.sessionId||n.outcome.sessionId!==e.sessionId||t.workspaceRoot!==null&&n.outcome.workspaceRoot!==t.workspaceRoot?e:{...e,outcome:{...t,status:`loaded`,outcome:n.outcome}}}case`workspace_outcome_error`:{let t=e.outcome;return t===null||t.status!==`loading`||t.requestId!==n.requestId?e:{...e,outcome:{...t,status:`error`,message:n.message}}}case`user`:return{...e,pendingPrompt:null,items:[...e.items,{kind:`user`,text:n.text,...n.images?{images:n.images}:{}}]};case`user_entries`:{let{entries:t}=n,r=e.items.flatMap((e,t)=>e.kind===`user`?[t]:[]),i=new Map;for(let n=r.length-1,a=t.length-1;n>=0&&a>=0;n--,a--){let o=e.items[r[n]];if(o.kind!==`user`||o.text!==t[a].text)break;i.set(r[n],t[a].entryId)}return{...e,items:e.items.map((e,t)=>{if(e.kind!==`user`)return e;let n=i.get(t);if(n===e.entryId)return e;if(n===void 0){let{entryId:t,...n}=e;return n}return{...e,entryId:n}})}}case`agent_start`:return{...e,isStreaming:!0,errors:[]};case`agent_end`:return{...e,isStreaming:!1,queue:{steering:[],followUp:[]},items:e.items.map(e=>e.kind===`tool`&&e.running?{...e,running:!1}:e.kind===`assistant`&&e.streaming?{...e,streaming:!1}:e)};case`assistant_start`:return{...e,items:[...e.items,{kind:`assistant`,blocks:[],streaming:!0}]};case`block_delta`:return{...e,items:j1(e.items,e=>{let t=[...e.blocks],r=t.findIndex(e=>e.contentIndex===n.contentIndex);return r>=0?t[r]={...t[r],text:t[r].text+n.delta}:t.push({type:n.block,text:n.delta,contentIndex:n.contentIndex}),{...e,blocks:t,streaming:!0}})};case`assistant_end`:return{...e,items:j1(e.items,()=>n.item)};case`custom_message`:return{...e,items:[...e.items,n.item]};case`tool_start`:return{...e,items:M1(e.items,n.toolCallId,n.toolName,{toolName:n.toolName,args:n.args,running:!0,callHtml:n.callHtml})};case`tool_update`:return{...e,items:M1(e.items,n.toolCallId,`tool`,{output:n.text,...n.outputHtml===void 0?{}:{outputHtml:n.outputHtml,outputHtmlCollapsed:n.outputHtmlCollapsed},...typeof n.progress==`number`?{progress:n.progress}:{}})};case`tool_end`:return{...e,items:M1(e.items,n.toolCallId,`tool`,{output:n.text,isError:n.isError,running:!1,outputHtml:n.outputHtml,outputHtmlCollapsed:n.outputHtmlCollapsed,structured:n.structured})};case`structured_conformance`:return{...e,items:N1(e.items,n.toolCallId,{structuredConformance:n.conformance})};case`structured_appearance`:return{...e,structuredAppearance:n.appearance};case`outpost_update`:return{...e,outpostUpdate:n.notice};case`outpost_changes`:return{...e,outpostChanges:n.changes};case`pi_packages`:return{...e,piPackages:n.packages};case`pi_package_update_result`:{let t=e.piPackageUpdate;return t?.requestId===n.requestId?{...e,piPackageUpdate:{requestId:n.requestId,source:t.source,status:n.outcome,message:n.message}}:e}case`restart_needed`:return{...e,restartNeeded:n.reasons};case`server_restarting`:return{...e,serverRestarting:!0,piPackageUpdate:null};case`reply_structured_conformance`:return{...e,replyConformance:{...e.replyConformance,[n.key]:n.conformance}};case`queue`:return{...e,queue:{steering:n.steering,followUp:n.followUp}};case`context_usage`:return{...e,contextUsage:n.usage};case`confinement`:return{...e,confinement:n.confinement};case`sandbox_grant_request`:{let t=e.sandboxGrants??{pending:[],active:{hosts:[],directories:[]}};return t.pending.some(e=>e.id===n.request.id)?e:{...e,sandboxGrants:{...t,pending:[...t.pending,n.request]}}}case`sandbox_grant_resolved`:return e.sandboxGrants?{...e,sandboxGrants:{...e.sandboxGrants,pending:e.sandboxGrants.pending.filter(e=>e.id!==n.id)}}:e;case`sandbox_grants`:return{...e,sandboxGrants:{pending:e.sandboxGrants?.pending??[],active:n.active}};case`compaction_start`:return{...e,isCompacting:!0};case`compaction_end`:return{...e,isCompacting:!1,errors:n.errorMessage?[...e.errors,n.errorMessage]:e.errors};case`error`:return{...e,errors:[...e.errors,n.message],pendingPrompt:null,settingsApply:e.settingsApply?.status===`applying`?{status:`error`,message:n.message}:e.settingsApply};case`server_directory`:return e.serverBrowse?.requestId===n.requestId?{...e,serverBrowse:{status:`loaded`,path:n.path,parent:n.parent,entries:n.entries,requestId:n.requestId}}:e;case`server_directory_error`:return e.serverBrowse?.requestId===n.requestId?{...e,serverBrowse:{...e.serverBrowse,status:`error`,error:n.message}}:e;case`directory_listing`:return n.requestId.startsWith(`dir:`)&&e.directoryRequests[n.path]!==n.requestId?e:{...e,fileTree:{...e.fileTree,[n.path]:n.entries},...n.requestId.startsWith(`create:`)?{created:n.path,createError:null}:{}};case`file_content`:{let t=e.openFile,r=t?.status===`loading`&&t.requestId===n.requestId,i=t?.status===`loaded`&&t.refreshRequestId===n.requestId;return!r&&!i?e:{...e,openFile:{status:`loaded`,path:n.path,content:n.content,size:n.size,mtimeMs:n.mtimeMs,...n.documentIssues===void 0?{}:{documentIssues:n.documentIssues},...r&&t.reveal?{reveal:t.reveal}:{}}}}case`file_written`:{if(n.requestId.startsWith(`create:`))return{...e,createError:null,created:n.path,openFile:{status:`loaded`,path:n.path,content:``,size:n.size,mtimeMs:n.mtimeMs,justCreated:!0}};let t=e.openFile;return t?.status!==`loaded`||t.pendingSave?.requestId!==n.requestId?e:{...e,openFile:{status:`loaded`,path:t.path,content:t.pendingSave.content,size:n.size,mtimeMs:n.mtimeMs}}}case`file_operation_result`:{if(e.fileOperation?.status!==`pending`||e.fileOperation.requestId!==n.requestId)return e;let t=n.previousPath??n.path,r=n.operation===`delete_file`&&e.openFile?.path===n.path?null:e.openFile?.path===t?{...e.openFile,path:n.path}:e.openFile,i=e.gitFileHistory?.path===t||e.gitFileHistory?.path===n.path,a=e.gitDiff?.path===t||e.gitDiff?.path===n.path,o=e.gitBaseline?.path===t||e.gitBaseline?.path===n.path;return{...e,openFile:r,gitFileHistory:i?null:e.gitFileHistory,gitFileDiff:i?null:e.gitFileDiff,gitDiff:a?null:e.gitDiff,gitBaseline:o?null:e.gitBaseline,fileOperation:{status:`succeeded`,operation:n.operation,path:e.fileOperation.path,resultPath:n.path,requestId:n.requestId}}}case`file_browser_error`:if(n.requestId.startsWith(`dir:`))return e.directoryRequests[n.path]===n.requestId?{...e,fileTree:{...e.fileTree,[n.path]:{error:n.message}}}:e;if(n.requestId.startsWith(`create:`))return{...e,createError:{path:n.path,message:n.message}};if(n.requestId.startsWith(`write:`)){let t=e.openFile;return t?.status!==`loaded`||t.pendingSave?.requestId!==n.requestId?e:{...e,openFile:{...t,pendingSave:void 0,saveError:{message:n.message,conflict:n.reason===`conflict`}}}}return n.requestId.startsWith(`fileop:`)?e.fileOperation?.status!==`pending`||e.fileOperation.requestId!==n.requestId?e:{...e,fileOperation:{status:`error`,operation:e.fileOperation.operation,path:e.fileOperation.path,message:n.message,requestId:n.requestId}}:e.openFile?.status===`loading`&&e.openFile.requestId===n.requestId?{...e,openFile:{status:`error`,path:n.path,message:n.message}}:e.openFile?.status===`loaded`&&e.openFile.refreshRequestId===n.requestId?{...e,openFile:{...e.openFile,refreshRequestId:void 0}}:e;case`file_search_results`:return e.fileSearch?.requestId===n.requestId?{...e,fileSearch:{...e.fileSearch,status:`loaded`,results:n.results}}:e;case`content_search_results`:return e.contentSearch?.requestId===n.requestId?{...e,contentSearch:{...e.contentSearch,status:`loaded`,hits:n.hits,truncated:n.truncated,skipped:n.skipped}}:e;case`git_status`:{let t={};for(let e of n.files)t[e.path]=e.status;let r=e.gitStatus;if(n.repo===void 0||r===null)return{...e,gitStatus:{repos:n.repos,files:t}};let i={};for(let[e,t]of Object.entries(r.files))NV(r.repos,e)?.repo!==n.repo&&(i[e]=t);let a=r.repos.map(e=>n.repos.find(t=>t.repo===e.repo)??e);return{...e,gitStatus:{repos:a,files:{...i,...t}}}}case`git_repositories_changed`:return{...e,gitAvailable:n.available,gitUnavailable:n.available?null:n.unavailable??null,gitStatus:n.available?e.gitStatus:null};case`git_diff`:return n.requestId.startsWith(`gitbase:`)?e.gitBaseline?.requestId===n.requestId?{...e,gitBaseline:{...e.gitBaseline,text:n.before}}:e:{...e,gitDiff:{path:n.path,before:n.before,after:n.after}};case`git_log`:return e.gitLog===null?e:{...e,gitLog:{...e.gitLog,repo:n.repo,entries:n.entries,error:null}};case`git_show`:return{...e,gitShow:{sha:n.sha,patch:n.patch,truncated:n.truncated}};case`git_file_log`:return e.gitFileHistory?.requestId===n.requestId?{...e,gitFileHistory:{...e.gitFileHistory,status:`loaded`,entries:n.entries}}:e;case`git_file_diff`:return e.gitFileDiff===null||!D1(e.gitFileDiff,n)?e:{...e,gitFileDiff:{...e.gitFileDiff,status:`loaded`,beforeText:n.beforeText,afterText:n.afterText}};case`git_error`:return n.requestId.startsWith(`gitbase:`)?e.gitBaseline?.requestId===n.requestId?{...e,gitBaseline:null}:e:n.requestId.startsWith(`gitdiff:`)?{...e,gitDiff:e.openFile?{path:e.openFile.path,error:n.message}:null}:n.requestId===e.gitFileHistory?.requestId?{...e,gitFileHistory:{...e.gitFileHistory,status:`error`,error:n.message}}:n.requestId===e.gitFileDiff?.requestId?{...e,gitFileDiff:{...e.gitFileDiff,status:`error`,error:n.message}}:n.requestId.startsWith(`gitlog:`)?n.requestId===e.gitLog?.requestId?{...e,gitLog:{...e.gitLog,entries:null,error:n.message}}:e:{...e,errors:[...e.errors,`git: ${n.message}`]};case`extension_ui_request`:switch(n.method){case`select`:case`confirm`:case`input`:case`editor`:return{...e,dialogQueue:[...e.dialogQueue,n]};case`notify`:return{...e,notifications:[...e.notifications,{id:n.id,message:n.message,notifyType:n.notifyType}]};case`setStatus`:{let t={...e.statuses};return n.statusText===void 0?delete t[n.statusKey]:t[n.statusKey]=n.statusText,{...e,statuses:t}}case`setWidget`:{let t={...e.widgets};return n.widgetLines===void 0?delete t[n.widgetKey]:t[n.widgetKey]={lines:n.widgetLines,placement:n.widgetPlacement??`aboveEditor`},{...e,widgets:t}}case`setTitle`:return{...e,extensionTitle:n.title};case`set_editor_text`:return{...e,editorPrefill:{text:n.text,nonce:e.editorPrefill?e.editorPrefill.nonce+1:1}};default:return e}default:return e}}function I1(e,t,n){let r=e?`${e.replace(/^http/,`ws`)}/ws`:`${location.protocol===`https:`?`wss`:`ws`}://${location.host}/ws`,i=new URLSearchParams;t&&i.set(`token`,t),n&&i.set(`workspace`,n);let a=i.toString();return a?`${r}?${a}`:r}var L1=12e4,R1=3e4,z1=2e4,B1=45e3,V1=4401,H1=1e3;function U1(e=``,t,n=!1,r){let[i,a]=(0,v.useReducer)(F1,k1),o=(0,v.useRef)(null),[s,c]=(0,v.useState)(0),l=(0,v.useRef)(null),u=(0,v.useRef)(null);s===0&&l.current===null&&(l.current=t??(n?S1():x1()));let d=(0,v.useRef)(i.fileTree),f=(0,v.useRef)(i.openFile);(0,v.useEffect)(()=>{d.current=i.fileTree},[i.fileTree]),(0,v.useEffect)(()=>{f.current=i.openFile},[i.openFile]);let p=(0,v.useRef)(null);(0,v.useEffect)(()=>{p.current=i.gitDiff?.path??null},[i.gitDiff]);let m=(0,v.useRef)(new Map),h=(0,v.useRef)(new Map),g=(0,v.useRef)(new Map),_=(0,v.useRef)(new Map),y=(0,v.useRef)(i.sessionId);(0,v.useEffect)(()=>{y.current=i.sessionId},[i.sessionId]);let b=(0,v.useRef)(!1),x=(0,v.useRef)(i.olderHistory);(0,v.useEffect)(()=>{x.current=i.olderHistory},[i.olderHistory]);let S=(0,v.useRef)(i.writableRoot);(0,v.useEffect)(()=>{S.current=i.writableRoot},[i.writableRoot]);let C=(0,v.useRef)(!1),w=(0,v.useRef)(new Map),T=(0,v.useRef)(new Map),E=i.workspace?GB(i.workspace):null,D=(0,v.useRef)({key:E,root:i.sandbox?.projectRoot??i.sandbox?.root,writableRoot:i.writableRoot}),O=(0,v.useRef)(0),ee=O.current,te=(0,v.useRef)({workspaceRoot:E,sessionId:i.sessionId});(0,v.useEffect)(()=>{te.current={workspaceRoot:E,sessionId:i.sessionId}},[E,i.sessionId]);let k=(0,v.useCallback)(e=>{[`switch_workspace`,`open_project`,`close_project`,`open_side_session`].includes(e.type)&&O.current++;let t=o.current;t&&t.readyState===WebSocket.OPEN&&t.send(JSON.stringify(e))},[]),ne=(0,v.useRef)(!1),A=(0,v.useRef)(null),re=(0,v.useRef)(!1),j=(0,v.useRef)(null),ie=(0,v.useRef)(()=>{}),ae=(0,v.useCallback)(()=>{A.current=null,j.current!==null&&(clearTimeout(j.current),j.current=null)},[]),oe=(0,v.useCallback)(()=>{let e=o.current;if(!e||e.readyState!==WebSocket.OPEN)return;if(A.current!==null){re.current=!0;return}let t=`outcome:${y1()}`;A.current=t;let n=te.current;a({type:`outcome_started`,requestId:t,...n}),k({type:`get_outcome`,requestId:t}),j.current=setTimeout(()=>{A.current===t&&(ae(),re.current=!1,a({type:`outcome_failed`,requestId:t,message:`The Outcome took too long to answer — try again.`}))},B1)},[k,ae]);ie.current=oe;let ce=(0,v.useCallback)(()=>{ne.current&&ie.current()},[]),ue=(0,v.useCallback)(e=>{ne.current=e,e?oe():re.current=!1},[oe]),de=(0,v.useCallback)((e,t=!1)=>{e===``&&(C.current=!0);let n=`dir:${y1()}`;a({type:`dir_list_started`,path:e,requestId:n,preserveEntries:t}),k({type:`list_directory`,path:e,requestId:n})},[k]),fe=(0,v.useRef)(!1),M=(0,v.useRef)(null),pe=(0,v.useCallback)((e,t)=>{let n=`gitlog:${y1()}`;a({type:`git_log_started`,repo:e,requestId:n}),k({type:`git_log`,repo:e,...t?{limit:t}:{},requestId:n})},[k]),N=(0,v.useRef)([]);(0,v.useEffect)(()=>{N.current=i.gitStatus?.repos??[]},[i.gitStatus]);let me=(0,v.useRef)(new Set),he=(0,v.useRef)(new Set),ge=(0,v.useRef)(new Map),P=(0,v.useCallback)(e=>{if(!fe.current)return;let t=e??``;if(me.current.has(t)){he.current.add(t);return}me.current.add(t);let n=`git:${y1()}`;ge.current.set(n,t),k({type:`git_status`,...e===void 0?{}:{repo:e},requestId:n})},[k]),_e=(0,v.useCallback)(e=>{let t=ge.current.get(e)??``;ge.current.delete(e),me.current.delete(t),he.current.delete(t)&&P(t===``?void 0:t)},[P]),ve=(0,v.useCallback)(e=>{d.current[e]!==void 0&&de(e,!0)},[de]),ye=(0,v.useCallback)(()=>{de(``,!0);for(let e of Object.keys(d.current))e!==``&&ve(e)},[ve,de]);(0,v.useEffect)(()=>{i.connected&&C.current&&d.current[``]===void 0&&de(``)},[i.connected,i.fileTree,de]),(0,v.useEffect)(()=>{i.connected&&ne.current&&A.current===null&&ie.current()},[i.connected]);let be=i.openFile?.path??null,xe=be===null?void 0:i.gitStatus?.files[be],Se=i.gitBaseline!==null;(0,v.useEffect)(()=>{let e=xe===`modified`||xe===`added`||xe===`conflicted`;if(!i.connected||be===null||!e){Se&&a({type:`git_baseline_cleared`});return}let t=`gitbase:${y1()}`;a({type:`git_baseline_started`,path:be,requestId:t}),k({type:`git_diff`,path:be,requestId:t})},[i.connected,be,xe,i.gitStatus,k]),(0,v.useEffect)(()=>{let t=!1;return fetch(`${e}/branding`,{headers:l.current?{Authorization:`Bearer ${l.current}`}:{}}).then(e=>e.ok?e.json():null).then(e=>{t||a(e?{type:`branding_loaded`,branding:e}:{type:`branding_settled`})}).catch(()=>{t||a({type:`branding_settled`})}),()=>{t=!0}},[e,s]),(0,v.useEffect)(()=>{let t,n=!1;function i(){let s=new WebSocket(I1(e,l.current,r));o.current=s,s.onopen=()=>{o.current===s&&a({type:`connected`})},s.onmessage=e=>{if(o.current!==s)return;let t;try{t=JSON.parse(e.data)}catch{return}if(t.type===`hello`){for(let e of T.current.values())if(e.socket!==s){for(let t of w.current.get(e.message.terminalId)?.onData??[])t(`\r
1535
+ `))&&o()}),c=y.current.subscribeTerminal?.(e,{onData:t=>{n.write(t);let r=t.match(/\x1b\]7;file:\/\/[^/]*([^\x07\x1b]+)(?:\x07|\x1b\\)/);if(r&&r[1])try{let t=decodeURIComponent(r[1]);y.current.onCwdUpdate(e,t)}catch{}},onCwd:t=>{y.current.onCwdUpdate(e,t)},onExit:e=>{n.writeln(`\r\n\x1b[90m[Process completed (exit code ${e??0})]\x1b[0m`)},onError:e=>{n.writeln(`\r\n\x1b[31m[Terminal error: ${e}]\x1b[0m`)}})??(()=>{}),l=new ResizeObserver(()=>{if(m.current&&m.current.clientWidth>0&&m.current.clientHeight>0)try{r.fit(),n.cols>0&&n.rows>0&&y.current.resizeTerminal?.(e,n.cols,n.rows)}catch{}});return l.observe(m.current),()=>{s.dispose(),c(),l.disconnect(),n.dispose(),y.current.closeTerminal?.(e)}},[e]),(0,v.useEffect)(()=>{if(!a&&i&&r&&g.current&&h.current&&m.current){y.current.getTerminalCwd?.(e);let t=setTimeout(()=>{try{g.current?.fit(),h.current?.focus()}catch{}},50);return()=>clearTimeout(t)}},[i,r,e,a]),(0,N.jsx)(`div`,{ref:m,className:`h-full w-full p-2 bg-white dark:bg-zinc-950 overflow-hidden ${r?`block`:`hidden`}`})}function h1({shells:e,open:t,onClose:n,cwd:r,confinedRoot:i,confinement:a,unavailable:o,onSetWorkspaceRoot:s,openTerminal:c,sendTerminalInput:l,getTerminalCwd:u,resizeTerminal:d,closeTerminal:f,subscribeTerminal:p}){let[m,h]=(0,v.useState)(``),g=e?.some(e=>e.id===m)?m:``,[_,y]=(0,v.useState)(t);(0,v.useEffect)(()=>{t&&y(!0)},[t]);let[b,x]=(0,v.useState)([{id:`term-1`,title:`terminal 1`}]),[S,C]=(0,v.useState)(`term-1`),[w,T]=(0,v.useState)(null),[E,D]=(0,v.useState)(``),[O,ee]=(0,v.useState)({}),[te,k]=(0,v.useState)(!1),ne=BU(FU,`y`),[A,re]=(0,v.useState)(!1),j=(0,v.useRef)(new Map),ie=(0,v.useCallback)((e,t)=>{j.current.set(e,t)},[]),ae=(0,v.useCallback)((e,t)=>{ee(n=>({...n,[e]:t}))},[]),oe=(0,v.useCallback)(()=>{let e=b.length+1,t=`term-${crypto.randomUUID()}`,n={id:t,title:`terminal ${e}`,...g?{shellId:g}:{}};x(e=>[...e,n]),C(t)},[b.length,g]),se=(0,v.useCallback)((e,t)=>{t.stopPropagation(),b.length<=1?n():(x(t=>{let n=t.filter(t=>t.id!==e);if(S===e){let r=t.findIndex(t=>t.id===e),i=n[Math.max(0,r-1)]?.id??n[0]?.id;C(i)}return n}),j.current.delete(e),ee(t=>{let n={...t};return delete n[e],n}))},[b.length,S,n]),ce=(e,t)=>{t.stopPropagation(),T(e.id),D(e.title)},le=()=>{if(w){let e=E.trim();e&&x(t=>t.map(t=>t.id===w?{...t,title:e}:t)),T(null)}},ue=e=>{e.key===`Enter`?le():e.key===`Escape`&&T(null)},de=(0,v.useCallback)(()=>{let e=j.current.get(S);e&&e()},[S]),fe=O[S]||r||``;return _?(0,N.jsxs)(`div`,{style:{height:te?`85vh`:ne.width,maxHeight:te?`85vh`:`65vh`},className:`flex-col shrink-0 border-t border-zinc-200 dark:border-zinc-800 bg-zinc-100 dark:bg-zinc-900 ${t?`flex`:`hidden`} relative z-20`,children:[!te&&(0,N.jsx)(VU,{axis:`y`,label:`Resize Terminal panel`,width:ne.width,config:FU,separatorProps:ne.separatorProps}),(0,N.jsxs)(`div`,{className:`flex items-center justify-between px-2 py-1 border-b border-zinc-200 dark:border-zinc-800 select-none bg-zinc-50 dark:bg-zinc-950 text-xs`,children:[(0,N.jsxs)(`div`,{className:`flex items-center space-x-1 overflow-x-auto min-w-0`,children:[(0,N.jsx)(`div`,{className:`flex items-center space-x-1`,children:b.map(e=>{let t=e.id===S,n=e.id===w;return(0,N.jsxs)(`div`,{onClick:()=>C(e.id),onDoubleClick:t=>ce(e,t),title:`Double-click to rename tab`,className:`flex items-center space-x-1 px-2.5 py-1 rounded text-xs cursor-pointer transition-colors ${t?`bg-zinc-200 dark:bg-zinc-800 text-zinc-900 dark:text-zinc-100 font-medium shadow-sm`:`text-zinc-500 hover:text-zinc-800 dark:text-zinc-400 dark:hover:text-zinc-200 hover:bg-zinc-200/50 dark:hover:bg-zinc-800/50`}`,children:[n?(0,N.jsx)(`input`,{type:`text`,"data-testid":`terminal-tab-rename-input`,value:E,autoFocus:!0,onChange:e=>D(e.target.value),onBlur:le,onKeyDown:ue,className:`bg-transparent border border-sky-500 rounded px-1 py-0 text-xs font-mono outline-none text-zinc-900 dark:text-zinc-100 w-24`}):(0,N.jsx)(`span`,{children:e.title}),b.length>1&&(0,N.jsx)(`span`,{onClick:t=>se(e.id,t),role:`button`,tabIndex:0,"aria-label":`Close terminal tab`,className:`ml-1 hover:text-red-500 rounded p-0.5 hover:bg-zinc-200 dark:hover:bg-zinc-700`,children:(0,N.jsx)(`svg`,{className:`w-3 h-3`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,N.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M6 18L18 6M6 6l12 12`})})})]},e.id)})}),e&&e.length>0&&(0,N.jsxs)(`select`,{"aria-label":`Shell for new terminal`,value:g,onChange:e=>h(e.target.value),disabled:!!o,className:`min-w-0 max-w-40 rounded border border-zinc-300 bg-zinc-50 text-xs text-zinc-800 dark:border-zinc-700 dark:bg-zinc-950 dark:text-zinc-200`,children:[(0,N.jsx)(`option`,{value:``,children:`Default shell`}),e.map(e=>(0,N.jsx)(`option`,{value:e.id,children:e.label},e.id))]}),(0,N.jsx)(`button`,{onClick:oe,type:`button`,title:`New Terminal Tab`,className:`p-1 rounded text-zinc-500 hover:text-zinc-800 dark:text-zinc-400 dark:hover:text-zinc-200 hover:bg-zinc-200/60 dark:hover:bg-zinc-800/60`,children:(0,N.jsx)(`svg`,{className:`w-3.5 h-3.5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,N.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M12 4v16m8-8H4`})})})]}),i&&!o&&(0,N.jsx)(SG,{verdict:a??{state:`checking`,runner:``},surface:`terminal`,root:p1(i)}),fe&&(0,N.jsx)(`div`,{className:`hidden md:flex items-center space-x-1.5 px-2 text-xs font-mono text-zinc-500 dark:text-zinc-400`,children:s&&(0,N.jsx)(`button`,{onClick:()=>{if(fe&&s){if((fe===`/`||fe===`\\`||/^[A-Za-z]:[\\/]?$/.test(fe))&&!window.confirm(`Open root filesystem "${fe}" as the workspace project?`))return;s(fe),re(!0),setTimeout(()=>re(!1),2e3)}},type:`button`,title:`Open "${fe}" as the workspace project and reposition the LLM agent`,className:`flex items-center space-x-1 px-1.5 py-0.5 rounded text-[11px] font-sans transition-colors ${A?`bg-emerald-500 text-white font-medium`:`bg-zinc-200/80 hover:bg-sky-500 hover:text-white dark:bg-zinc-800 dark:hover:bg-sky-600 dark:hover:text-white text-zinc-700 dark:text-zinc-300`}`,children:(0,N.jsx)(`span`,{children:A?`✓ Project opened`:`📁 ${p1(fe)} → open as project`})})}),(0,N.jsxs)(`div`,{className:`flex items-center space-x-1 text-zinc-500 dark:text-zinc-400`,children:[(0,N.jsx)(`button`,{onClick:de,type:`button`,title:`Clear Terminal Output`,className:`p-1 rounded hover:text-zinc-800 dark:hover:text-zinc-200 hover:bg-zinc-200/60 dark:hover:bg-zinc-800/60`,children:(0,N.jsx)(`svg`,{className:`w-3.5 h-3.5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,N.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16`})})}),(0,N.jsx)(`button`,{onClick:()=>k(e=>!e),type:`button`,title:te?`Restore Terminal Panel`:`Maximize Terminal Panel`,className:`p-1 rounded hover:text-zinc-800 dark:hover:text-zinc-200 hover:bg-zinc-200/60 dark:hover:bg-zinc-800/60`,children:te?(0,N.jsx)(`svg`,{className:`w-3.5 h-3.5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,N.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M19 9l-7 7-7-7`})}):(0,N.jsx)(`svg`,{className:`w-3.5 h-3.5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,N.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M5 15l7-7 7 7`})})}),(0,N.jsx)(`button`,{onClick:n,type:`button`,title:"Minimize Terminal Panel (Ctrl+`)",className:`p-1 rounded hover:text-zinc-800 dark:hover:text-zinc-200 hover:bg-zinc-200/60 dark:hover:bg-zinc-800/60`,children:(0,N.jsx)(`svg`,{className:`w-3.5 h-3.5`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,N.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M6 18L18 6M6 6l12 12`})})})]})]}),(0,N.jsx)(`div`,{className:`flex-1 min-h-0 relative`,children:o?(0,N.jsxs)(`div`,{role:`status`,"data-testid":`terminal-unavailable`,className:`p-3 text-xs text-amber-700 dark:text-amber-300`,children:[(0,N.jsx)(`p`,{className:`font-medium`,children:`The terminal is unavailable.`}),(0,N.jsx)(`p`,{className:`mt-1 break-words font-mono`,children:o})]}):b.map(e=>(0,N.jsx)(m1,{id:e.id,shellId:e.shellId,cwd:r,isActive:e.id===S,isPanelOpen:t,renaming:w!==null,openTerminal:c,sendTerminalInput:l,getTerminalCwd:u,resizeTerminal:d,closeTerminal:f,subscribeTerminal:p,onCwdUpdate:ae,registerClear:ie},e.id))})]}):null}var g1={todo:{label:`To do`,className:`text-zinc-500`},in_progress:{label:`In progress`,className:`text-blue-600 dark:text-blue-400`},done:{label:`Done`,className:`text-emerald-600 dark:text-emerald-400`},blocked:{label:`Blocked`,className:`text-red-600 dark:text-red-400`},needs_review:{label:`Needs review`,className:`text-amber-600 dark:text-amber-400`},passed:{label:`Passed`,className:`text-emerald-600 dark:text-emerald-400`},failed:{label:`Failed`,className:`text-red-600 dark:text-red-400`},inconclusive:{label:`Inconclusive`,className:`text-amber-600 dark:text-amber-400`},informational:{label:`Informational`,className:`text-zinc-500`},modified:{label:`Modified`,className:`text-blue-600 dark:text-blue-400`},added:{label:`Added`,className:`text-emerald-600 dark:text-emerald-400`},deleted:{label:`Deleted`,className:`text-red-600 dark:text-red-400`},untracked:{label:`Untracked`,className:`text-zinc-600 dark:text-zinc-300`},conflicted:{label:`Conflicted`,className:`text-red-600 dark:text-red-400`},unavailable:{label:`Unavailable`,className:`text-red-600 dark:text-red-400`},"not-recorded":{label:`Not recorded`,className:`text-zinc-500`}};function _1(e){return g1[e]??{label:e,className:`text-zinc-500`}}function v1({entry:e,onTarget:t}){let n=_1(e.status),r=(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,N.jsx)(`span`,{className:`min-w-0 break-words text-sm font-medium text-zinc-900 dark:text-zinc-100`,children:e.title}),(0,N.jsx)(`span`,{className:`shrink-0 text-[11px] font-semibold uppercase tracking-wide ${n.className}`,children:n.label})]}),e.group&&(0,N.jsx)(`div`,{className:`mt-0.5 text-[11px] text-zinc-500`,children:e.group}),e.detail&&(0,N.jsx)(`p`,{className:`mt-1 whitespace-pre-wrap text-xs text-zinc-600 dark:text-zinc-300`,children:e.detail}),e.reference&&(0,N.jsx)(`div`,{className:`mt-1 truncate text-xs text-zinc-500`,children:e.reference}),(0,N.jsx)(`div`,{className:`mt-1 text-[10px] uppercase tracking-wide text-zinc-400`,children:e.source})]}),i=`block w-full rounded-md border border-zinc-200 p-2 text-left hover:bg-zinc-50 dark:border-zinc-800 dark:hover:bg-zinc-900`;return e.target?.kind===`external-url`?(0,N.jsx)(`a`,{href:e.target.url,target:`_blank`,rel:`noreferrer`,className:i,children:r}):e.target?(0,N.jsx)(`button`,{type:`button`,onClick:()=>t(e.target),className:i,children:r}):(0,N.jsx)(`div`,{className:`rounded-md border border-zinc-200 p-2 dark:border-zinc-800`,children:r})}function y1({state:e,onClose:t,onRefresh:n,onTarget:r}){return(0,N.jsxs)(`aside`,{"aria-label":`Workspace Outcome`,className:`absolute inset-y-0 right-0 z-10 flex w-full flex-col border-l border-zinc-200 bg-white/95 shadow-lg backdrop-blur md:w-[26rem] dark:border-zinc-800 dark:bg-zinc-950/95`,children:[(0,N.jsxs)(`header`,{className:`flex items-start justify-between gap-2 border-b border-zinc-200 px-3 py-3 dark:border-zinc-800`,children:[(0,N.jsxs)(`div`,{children:[(0,N.jsx)(`div`,{className:`text-[11px] font-semibold uppercase tracking-wide text-zinc-500`,children:`Workspace review`}),(0,N.jsx)(`h2`,{className:`text-sm font-semibold text-zinc-900 dark:text-zinc-100`,children:`Outcome`})]}),(0,N.jsxs)(`div`,{className:`flex gap-1`,children:[(0,N.jsx)(`button`,{type:`button`,onClick:n,className:`rounded px-2 py-1 text-xs text-zinc-500 hover:bg-zinc-100 dark:hover:bg-zinc-800`,children:`Refresh`}),(0,N.jsx)(`button`,{type:`button`,onClick:t,className:`rounded px-2 py-1 text-xs text-zinc-500 hover:bg-zinc-100 dark:hover:bg-zinc-800`,"aria-label":`Close Outcome`,children:`×`})]})]}),(0,N.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-3`,children:e===null||e.status===`loading`?(0,N.jsx)(`div`,{role:`status`,className:`text-sm text-zinc-500`,children:`Loading Outcome…`}):e.status===`error`?(0,N.jsx)(`div`,{role:`alert`,className:`rounded-md border border-red-200 bg-red-50 p-3 text-sm text-red-700 dark:border-red-900 dark:bg-red-950/30 dark:text-red-300`,children:e.message}):(0,N.jsx)(`div`,{className:`space-y-4`,children:e.outcome.sections.map(e=>(0,N.jsxs)(`section`,{"aria-labelledby":`outcome-${e.id}`,className:`rounded-lg border border-zinc-200 p-3 dark:border-zinc-800`,children:[(0,N.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,N.jsx)(`h3`,{id:`outcome-${e.id}`,className:`text-sm font-semibold text-zinc-900 dark:text-zinc-100`,children:e.title}),e.availability===`partial`||e.availability===`unavailable`?(0,N.jsx)(`span`,{className:`text-[11px] font-semibold uppercase text-red-600 dark:text-red-400`,children:e.availability}):null]}),e.summary&&(0,N.jsx)(`p`,{className:`mt-1 text-xs text-zinc-600 dark:text-zinc-300`,children:e.summary}),e.entries.length>0&&(0,N.jsx)(`div`,{className:`mt-3 space-y-2`,children:e.entries.map(e=>(0,N.jsx)(v1,{entry:e,onTarget:r},e.id))})]},e.id))})})]})}function b1(){if(typeof crypto.randomUUID==`function`)return crypto.randomUUID();let e=crypto.getRandomValues(new Uint8Array(16));e[6]=e[6]&15|64,e[8]=e[8]&63|128;let t=Array.from(e,e=>e.toString(16).padStart(2,`0`));return`${t.slice(0,4).join(``)}-${t.slice(4,6).join(``)}-${t.slice(6,8).join(``)}-${t.slice(8,10).join(``)}-${t.slice(10).join(``)}`}var x1=`pi-outpost:token`;function S1(){let e=null;try{let t=new URL(window.location.href);return e=t.searchParams.get(`token`),e&&(localStorage.setItem(x1,e),t.searchParams.delete(`token`),window.history.replaceState(null,``,`${t.pathname}${t.search}${t.hash}`)),localStorage.getItem(x1)}catch{return e}}function C1(){try{return localStorage.getItem(x1)}catch{return null}}function w1(e){try{localStorage.setItem(x1,e)}catch{}}var T1=class extends Error{kind;constructor(e,t){super(e),this.name=`HistoryError`,this.kind=t}};async function E1(e,t){let n=[];for(;;){let r=await e(n.length,50);if(r.items.length===0||(n.unshift(...r.items),t?.(n.length),r.remaining===0))return n}}function D1(e){let t=e.lastIndexOf(`/`);return t<0?``:e.slice(0,t)}function O1(e,t){return e.base.rev===t.base.rev&&e.base.path===t.base.path&&e.target.rev===t.target.rev&&e.target.path===t.target.path}function k1(){return{clonePath:null,preview:null,enrollment:null,refresh:null,updates:{},skills:{},removals:{}}}var A1={login:null,connected:!1,workspace:null,workspaces:[],workspaceLocked:!1,embedWorkspaceControls:`settings`,switching:!1,agentStarting:!1,authRequired:!1,brandingReady:!1,branding:{},sessionId:``,sessionName:null,model:``,thinkingLevel:`off`,modelSupportsReasoning:!1,models:[],commands:[],extensionsBinding:!1,sessions:null,sessionSearch:null,tree:null,isStreaming:!1,items:[],olderHistory:null,pendingPrompt:null,workPlan:null,replyConformance:{},structuredAppearance:null,outpostUpdate:null,outpostChanges:null,piPackages:null,piPackageUpdate:null,serverRestarting:!1,restartNeeded:[],outcome:null,queue:[],queuedEditRefused:null,errors:[],contextUsage:null,isCompacting:!1,dialogQueue:[],sandboxGrants:null,notifications:[],statuses:{},widgets:{},editorPrefill:null,fileTree:{},directoryRequests:{},openFile:null,previewRevision:0,fileSearch:null,contentSearch:null,createError:null,created:null,fileOperation:null,extensionPaths:null,configuredExtensionPaths:[],userExtensionPaths:[],extensionLock:!1,tools:[],sandbox:null,terminal:null,userSkillPaths:[],serverBrowse:null,settingsApply:null,agentResources:null,agentResourceOperations:k1(),versions:null,gitAvailable:!1,gitUnavailable:null,credentials:null,gitStatus:null,gitDiff:null,gitBaseline:null,gitLog:null,gitShow:null,gitFileHistory:null,gitFileDiff:null};function j1(e,t){if(!e.startsWith(`/`))return!1;let n=e.indexOf(` `),r=n===-1?e.slice(1):e.slice(1,n);return t.some(e=>e.source===`extension`&&e.name===r)}function M1(e,t){for(let n=e.length-1;n>=0;n--){let r=e[n];if(r.kind===`assistant`&&r.streaming){let i=[...e];return i[n]=t(r),i}}return[...e,t({kind:`assistant`,blocks:[],streaming:!0})]}function N1(e,t,n,r){for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.kind===`tool`&&i.toolCallId===t){let t=[...e];return t[n]={...i,...r},t}}return[...e,{kind:`tool`,toolCallId:t,toolName:n,args:{},output:``,running:!0,...r}]}function P1(e,t,n){for(let r=e.length-1;r>=0;r--){let i=e[r];if(i.kind===`tool`&&i.toolCallId===t){let t=[...e];return t[r]={...i,...n},t}}return e}function F1(e,t){if(t.type!==`hello`&&t.type!==`session_replaced`&&t.type!==`update_config_ack`&&t.type!==`workspace_switched`&&t.type!==`workspace_starting`)return e;let n=t.models.find(e=>`${e.provider}/${e.id}`===t.model);return{...e,replyConformance:{},structuredAppearance:t.type===`workspace_switched`||t.type===`workspace_starting`?null:e.structuredAppearance,agentStarting:t.agentStarting===!0,outpostUpdate:t.outpostUpdate??e.outpostUpdate,outpostChanges:t.outpostChanges??e.outpostChanges,piPackages:t.piPackages??e.piPackages,serverRestarting:!1,restartNeeded:t.restartNeeded??[],connected:!0,brandingReady:!0,workspace:t.workspace??null,workspaces:t.workspaces??[],workspaceLocked:t.workspaceLocked===!0,embedWorkspaceControls:t.embedWorkspaceControls??`settings`,switching:!1,branding:t.branding,sessionId:t.sessionId,sessionName:t.sessionName??null,model:t.model,thinkingLevel:t.thinkingLevel,thinkingLevels:t.thinkingLevels,modelSupportsReasoning:n?.reasoning??!1,models:t.models,commands:t.commands,extensionsBinding:t.extensionsBinding===!0,isStreaming:t.isStreaming,items:t.items,olderHistory:t.olderItems?{remaining:t.olderItems,have:0,loading:!1,error:null}:null,pendingPrompt:null,workPlan:t.workPlan??null,outcome:null,queue:t.queuedPrompts??[],errors:[],contextUsage:t.contextUsage??null,isCompacting:!1,dialogQueue:[],notifications:[],statuses:{},widgets:{},extensionTitle:void 0,editorPrefill:null,tree:null,fileTree:{},directoryRequests:{},fileOperation:null,writableRoot:t.writableRoot,docxTemplate:t.docxTemplate,gitAvailable:t.gitAvailable===!0,gitUnavailable:t.gitUnavailable??null,credentials:t.credentials??null,extensionPaths:t.extensionPaths??null,configuredExtensionPaths:t.configuredExtensionPaths??[],userExtensionPaths:t.userExtensionPaths??[],extensionLock:t.extensionLock===!0,tools:t.tools??[],sandbox:t.sandbox??null,terminal:t.terminal??null,confinement:t.confinement??null,sandboxGrants:t.sandboxGrants??null,userSkillPaths:t.userSkillPaths??[],serverBrowse:null,settingsApply:null,versions:t.versions??null,agentResources:t.agentResources??null,agentResourceOperations:t.type===`hello`||t.type===`workspace_switched`||t.type===`workspace_starting`?k1():e.agentResourceOperations}}function I1(e,t){if(t.type===`connected`)return{...e,connected:!0,authRequired:!1};if(t.type===`workspace_switching`)return{...e,switching:!0};if(t.type===`pi_package_update_started`)return{...e,piPackageUpdate:{requestId:t.requestId,source:t.source,status:`pending`}};if(t.type===`auth_required`)return{...e,connected:!1,authRequired:!0};if(t.type===`auth_retrying`)return{...e,authRequired:!1};if(t.type===`login_started`)return{...e,login:{flowId:t.flowId,provider:t.provider,method:t.method,events:[],prompt:null,done:null}};if(t.type===`login_answered`)return e.login?{...e,login:{...e.login,prompt:null}}:e;if(t.type===`login_dismissed`)return{...e,login:null};if(t.type===`disconnected`&&e.login&&!e.login.done&&(e={...e,login:{...e.login,prompt:null,done:{ok:!1,message:`Connection lost — the sign-in was stopped. Start it again.`}}}),t.type===`disconnected`){let t=e.openFile,n=t?.status===`loaded`&&t.pendingSave!==void 0?{...t,pendingSave:void 0,saveError:{message:`Connection lost while saving — try again`,conflict:!1}}:e.openFile,r=e.outcome?.status===`loading`?{...e.outcome,status:`error`,message:`Connection lost while loading Outcome.`}:e.outcome;return{...e,connected:!1,openFile:n,outcome:r}}if(t.type===`branding_settled`)return{...e,brandingReady:!0};if(t.type===`branding_loaded`)return{...e,brandingReady:!0,branding:t.branding};if(t.type===`composer_prefilled`)return{...e,editorPrefill:{text:t.text,nonce:e.editorPrefill?e.editorPrefill.nonce+1:1},...t.notice?{errors:[...e.errors,t.notice]}:{}};if(t.type===`prompt_sent`)return j1(t.text,e.commands)?e:{...e,pendingPrompt:{text:t.text,...t.images?.length?{images:t.images}:{}}};if(t.type===`pending_prompt_cancelled`)return!t.restoreText||!e.pendingPrompt?e:{...e,editorPrefill:{text:e.pendingPrompt.text,nonce:e.editorPrefill?e.editorPrefill.nonce+1:1}};if(t.type===`dismiss_notification`)return{...e,notifications:e.notifications.filter(e=>e.id!==t.id)};if(t.type===`dialog_answered`)return{...e,dialogQueue:e.dialogQueue.slice(1)};if(t.type===`dir_list_started`){let n=e.fileTree[t.path];return{...e,fileTree:{...e.fileTree,[t.path]:t.preserveEntries&&Array.isArray(n)?n:`loading`},directoryRequests:{...e.directoryRequests,[t.path]:t.requestId}}}if(t.type===`raw_preview_changed`)return e.openFile?.path===t.path?{...e,previewRevision:e.previewRevision+1}:e;if(t.type===`file_read_started`){let n=e.openFile;return t.preserveContent&&n?.status===`loaded`&&n.path===t.path?{...e,openFile:{...n,refreshRequestId:t.requestId}}:{...e,openFile:{status:`loading`,path:t.path,requestId:t.requestId,...t.reveal?{reveal:t.reveal}:{}}}}if(t.type===`file_save_started`){let n=e.openFile;return!e.connected||n?.status!==`loaded`||n.path!==t.path?e:{...e,openFile:{...n,pendingSave:{requestId:t.requestId,content:t.content},saveError:void 0}}}if(t.type===`close_file_preview`)return{...e,openFile:null};if(t.type===`file_search_started`)return{...e,fileSearch:{status:`loading`,query:t.query,requestId:t.requestId,results:[]}};if(t.type===`file_search_cleared`)return{...e,fileSearch:null};if(t.type===`content_search_started`)return{...e,contentSearch:{status:`loading`,query:t.query,requestId:t.requestId,hits:[],truncated:!1,skipped:0}};if(t.type===`content_search_cleared`)return{...e,contentSearch:null};if(t.type===`file_create_started`)return{...e,createError:null,created:null};if(t.type===`file_operation_started`)return{...e,fileOperation:{status:`pending`,operation:t.operation,path:t.path,requestId:t.requestId}};if(t.type===`session_search_started`)return{...e,sessionSearch:{status:`loading`,query:t.query,requestId:t.requestId,results:[]}};if(t.type===`session_search_cleared`)return{...e,sessionSearch:null};if(t.type===`history_load_started`)return e.olderHistory?{...e,olderHistory:{...e.olderHistory,loading:!0,error:null}}:e;if(t.type===`history_loaded`)return e.olderHistory?{...e,items:[...t.items,...e.items],olderHistory:{remaining:t.remaining,have:e.olderHistory.have+t.items.length,loading:!1,error:null}}:e;if(t.type===`history_load_failed`)return e.olderHistory?{...e,olderHistory:{...e.olderHistory,loading:!1,error:t.message}}:e;if(t.type===`git_diff_started`||t.type===`git_diff_cleared`)return{...e,gitDiff:null};if(t.type===`git_baseline_started`){let n=e.gitBaseline?.path===t.path?e.gitBaseline.text:void 0;return{...e,gitBaseline:{path:t.path,requestId:t.requestId,...n===void 0?{}:{text:n}}}}if(t.type===`git_baseline_cleared`)return{...e,gitBaseline:null};if(t.type===`git_show_cleared`)return{...e,gitShow:null,gitLog:e.gitLog};if(t.type===`git_log_started`){let n=e.gitLog?.repo===t.repo?e.gitLog.entries:null;return{...e,gitLog:{repo:t.repo,entries:n,error:null,requestId:t.requestId}}}if(t.type===`git_log_closed`)return e.gitLog===null?e:{...e,gitLog:null};if(t.type===`git_file_history_started`)return{...e,gitFileHistory:{path:t.path,status:`loading`,entries:[],requestId:t.requestId},gitFileDiff:null};if(t.type===`git_file_history_closed`)return{...e,gitFileHistory:null,gitFileDiff:null};if(t.type===`git_file_diff_started`)return{...e,gitFileDiff:{base:t.base,target:t.target,status:`loading`,beforeText:e.gitFileDiff?.beforeText??``,afterText:e.gitFileDiff?.afterText??``,requestId:t.requestId}};if(t.type===`git_file_diff_cleared`)return{...e,gitFileDiff:null};if(t.type===`server_browse_started`)return{...e,serverBrowse:{status:`loading`,path:e.serverBrowse?.path??t.path,parent:e.serverBrowse?.parent??null,entries:e.serverBrowse?.entries??[],requestId:t.requestId}};if(t.type===`server_browse_closed`)return{...e,serverBrowse:null};if(t.type===`settings_apply_started`)return{...e,settingsApply:{status:`applying`}};if(t.type===`resource_clone_path_started`)return{...e,agentResourceOperations:{...e.agentResourceOperations,clonePath:{requestId:t.requestId,status:`loading`}}};if(t.type===`resource_preview_started`)return{...e,agentResourceOperations:{...e.agentResourceOperations,preview:{requestId:t.requestId,status:`loading`}}};if(t.type===`resource_enrollment_started`)return{...e,agentResourceOperations:{...e.agentResourceOperations,enrollment:{requestId:t.requestId,status:`loading`}}};if(t.type===`resource_refresh_started`)return{...e,agentResourceOperations:{...e.agentResourceOperations,refresh:{requestId:t.requestId,status:`loading`,...t.repositoryId?{repositoryId:t.repositoryId}:{}}}};if(t.type===`resource_update_started`)return{...e,agentResourceOperations:{...e.agentResourceOperations,updates:{...e.agentResourceOperations.updates,[t.repositoryId]:{requestId:t.requestId,status:`loading`}}}};if(t.type===`resource_skills_started`){let n=e.agentResourceOperations;return{...e,agentResourceOperations:{...n,skills:{...n.skills,[t.repositoryId]:{requestId:t.requestId,status:`loading`}}}}}if(t.type===`resource_removal_started`){let n=e.agentResourceOperations;return{...e,agentResourceOperations:{...n,removals:{...n.removals,[t.repositoryId]:{requestId:t.requestId,status:`loading`}}}}}if(t.type===`outcome_started`)return{...e,outcome:{status:`loading`,requestId:t.requestId,workspaceRoot:t.workspaceRoot,sessionId:t.sessionId}};if(t.type===`outcome_failed`){let n=e.outcome;return n===null||n.status!==`loading`||n.requestId!==t.requestId?e:{...e,outcome:{...n,status:`error`,message:t.message}}}let n=t.message;if(n.type===`workspace_switched`&&e.agentStarting&&e.workspace&&n.workspace&&GB(n.workspace)===GB(e.workspace))return{...F1(e,n),openFile:e.openFile,gitDiff:e.gitDiff,gitBaseline:e.gitBaseline,fileTree:e.fileTree,directoryRequests:e.directoryRequests,contentSearch:e.contentSearch};switch(n.type){case`workspace_switched`:case`hello`:case`session_replaced`:case`update_config_ack`:case`workspace_starting`:return{...F1(e,n),openFile:null,gitDiff:null,gitBaseline:null,fileTree:{},directoryRequests:{},contentSearch:n.type===`session_replaced`?e.contentSearch:null};case`workspace_activity`:return{...e,workspaces:n.workspaces,workspace:(e.workspace&&n.workspaces.find(t=>GB(t)===GB(e.workspace)))??e.workspace};case`agent_resource_clone_path`:{let t=e.agentResourceOperations.clonePath;return t?.requestId===n.requestId?{...e,agentResourceOperations:{...e.agentResourceOperations,clonePath:{...t,status:`ready`,path:n.path}}}:e}case`agent_resource_preview`:{let t=e.agentResourceOperations.preview;return t?.requestId===n.requestId?{...e,agentResourceOperations:{...e.agentResourceOperations,preview:{...t,status:`ready`,preview:n.preview}}}:e}case`agent_resource_enrolled`:{let t=e.agentResourceOperations.enrollment;return t?.requestId===n.requestId?{...e,agentResources:n.inventory,agentResourceOperations:{...e.agentResourceOperations,preview:null,enrollment:{...t,status:`ready`}}}:e}case`agent_resource_assessments`:{let t=e.agentResourceOperations.refresh;if(t?.requestId!==n.requestId||!e.agentResources)return e;let r=new Map(n.assessments.map(e=>[e.repositoryId,e]));return{...e,agentResources:{...e.agentResources,repositories:e.agentResources.repositories.map(e=>({...e,assessment:r.get(e.id)??e.assessment}))},agentResourceOperations:{...e.agentResourceOperations,refresh:{...t,status:`ready`}}}}case`agent_resource_inventory`:return{...e,agentResources:n.inventory};case`agent_resource_update_result`:{let t=n.result.repositoryId;if(!t)return e;let r=e.agentResourceOperations.updates[t];return r?.requestId===n.requestId?{...e,agentResources:n.inventory,agentResourceOperations:{...e.agentResourceOperations,updates:{...e.agentResourceOperations.updates,[t]:{...r,status:`ready`,result:n.result}}}}:e}case`agent_resource_skills_applied`:{let t=e.agentResourceOperations,r=t.skills[n.repositoryId];return r?.requestId===n.requestId?{...e,agentResources:n.inventory,agentResourceOperations:{...t,skills:{...t.skills,[n.repositoryId]:{...r,status:`ready`}}}}:e}case`agent_resource_removed`:{let t=e.agentResourceOperations,r=t.removals[n.repositoryId];return r?.requestId===n.requestId?{...e,agentResources:n.inventory,agentResourceOperations:{...t,removals:{...t.removals,[n.repositoryId]:{...r,status:`ready`,result:n.result}}}}:e}case`agent_resource_error`:{let t=e=>e?.requestId===n.requestId?{...e,status:`error`,message:n.message}:null,r=t(e.agentResourceOperations.clonePath),i=t(e.agentResourceOperations.preview),a=t(e.agentResourceOperations.enrollment),o=t(e.agentResourceOperations.refresh),s=e=>{let t=Object.entries(e).find(([,e])=>e.requestId===n.requestId);return t?{...e,[t[0]]:{...t[1],status:`error`,message:n.message}}:null},c=s(e.agentResourceOperations.updates),l=s(e.agentResourceOperations.skills),u=s(e.agentResourceOperations.removals);return!r&&!i&&!a&&!o&&!c&&!l&&!u?e:{...e,agentResourceOperations:{...e.agentResourceOperations,...r?{clonePath:r}:{},...i?{preview:i}:{},...a?{enrollment:a}:{},...o?{refresh:o}:{},...c?{updates:c}:{},...l?{skills:l}:{},...u?{removals:u}:{}}}}case`workspace_error`:return{...e,switching:!1,errors:[...e.errors,n.message]};case`sessions`:return{...e,sessions:n.sessions};case`session_search_results`:return e.sessionSearch?.requestId===n.requestId?{...e,sessionSearch:{...e.sessionSearch,status:`loaded`,results:n.sessions}}:e;case`tree`:return{...e,tree:n.roots};case`editor_prefill`:return{...e,editorPrefill:{text:n.text,nonce:e.editorPrefill?e.editorPrefill.nonce+1:1}};case`model_changed`:return{...e,model:n.model,modelSupportsReasoning:n.reasoning,thinkingLevels:n.thinkingLevels};case`login_event`:return e.login?.flowId===n.flowId?{...e,login:{...e.login,events:[...e.login.events,n.event]}}:e;case`login_prompt`:return e.login?.flowId===n.flowId?{...e,login:{...e.login,prompt:{promptId:n.promptId,prompt:n.prompt}}}:e;case`login_prompt_cancelled`:return e.login?.flowId!==n.flowId||e.login.prompt?.promptId!==n.promptId?e:{...e,login:{...e.login,prompt:null}};case`login_done`:return e.login?.flowId===n.flowId?{...e,login:{...e.login,prompt:null,done:{ok:n.ok,...n.cancelled?{cancelled:!0}:{},...n.message?{message:n.message}:{}}}}:e;case`credentials_changed`:{let t=n.models.find(e=>`${e.provider}/${e.id}`===n.model);return{...e,models:n.models,model:n.model,modelSupportsReasoning:t?.reasoning??!1,thinkingLevels:void 0,credentials:n.credentials}}case`extensions_bound`:return{...e,commands:n.commands,tools:n.tools??e.tools,extensionsBinding:!1};case`thinking_changed`:return{...e,thinkingLevel:n.level};case`work_plan_changed`:return{...e,workPlan:n.workPlan};case`workspace_outcome`:{let t=e.outcome;return t===null||t.requestId!==n.requestId||t.sessionId!==e.sessionId||n.outcome.sessionId!==e.sessionId||t.workspaceRoot!==null&&n.outcome.workspaceRoot!==t.workspaceRoot?e:{...e,outcome:{...t,status:`loaded`,outcome:n.outcome}}}case`workspace_outcome_error`:{let t=e.outcome;return t===null||t.status!==`loading`||t.requestId!==n.requestId?e:{...e,outcome:{...t,status:`error`,message:n.message}}}case`user`:return{...e,pendingPrompt:null,items:[...e.items,{kind:`user`,text:n.text,...n.images?{images:n.images}:{}}]};case`user_entries`:{let{entries:t}=n,r=e.items.flatMap((e,t)=>e.kind===`user`?[t]:[]),i=new Map;for(let n=r.length-1,a=t.length-1;n>=0&&a>=0;n--,a--){let o=e.items[r[n]];if(o.kind!==`user`||o.text!==t[a].text)break;i.set(r[n],t[a].entryId)}return{...e,items:e.items.map((e,t)=>{if(e.kind!==`user`)return e;let n=i.get(t);if(n===e.entryId)return e;if(n===void 0){let{entryId:t,...n}=e;return n}return{...e,entryId:n}})}}case`agent_start`:return{...e,isStreaming:!0,errors:[]};case`agent_end`:return{...e,isStreaming:!1,items:e.items.map(e=>e.kind===`tool`&&e.running?{...e,running:!1}:e.kind===`assistant`&&e.streaming?{...e,streaming:!1}:e)};case`assistant_start`:return{...e,items:[...e.items,{kind:`assistant`,blocks:[],streaming:!0}]};case`block_delta`:return{...e,items:M1(e.items,e=>{let t=[...e.blocks],r=t.findIndex(e=>e.contentIndex===n.contentIndex);return r>=0?t[r]={...t[r],text:t[r].text+n.delta}:t.push({type:n.block,text:n.delta,contentIndex:n.contentIndex}),{...e,blocks:t,streaming:!0}})};case`assistant_end`:return{...e,items:M1(e.items,()=>n.item)};case`custom_message`:return{...e,items:[...e.items,n.item]};case`tool_start`:return{...e,items:N1(e.items,n.toolCallId,n.toolName,{toolName:n.toolName,args:n.args,running:!0,callHtml:n.callHtml})};case`tool_update`:return{...e,items:N1(e.items,n.toolCallId,`tool`,{output:n.text,...n.outputHtml===void 0?{}:{outputHtml:n.outputHtml,outputHtmlCollapsed:n.outputHtmlCollapsed},...typeof n.progress==`number`?{progress:n.progress}:{}})};case`tool_end`:return{...e,items:N1(e.items,n.toolCallId,`tool`,{output:n.text,isError:n.isError,running:!1,outputHtml:n.outputHtml,outputHtmlCollapsed:n.outputHtmlCollapsed,structured:n.structured})};case`structured_conformance`:return{...e,items:P1(e.items,n.toolCallId,{structuredConformance:n.conformance})};case`structured_appearance`:return{...e,structuredAppearance:n.appearance};case`outpost_update`:return{...e,outpostUpdate:n.notice};case`outpost_changes`:return{...e,outpostChanges:n.changes};case`pi_packages`:return{...e,piPackages:n.packages};case`pi_package_update_result`:{let t=e.piPackageUpdate;return t?.requestId===n.requestId?{...e,piPackageUpdate:{requestId:n.requestId,source:t.source,status:n.outcome,message:n.message}}:e}case`restart_needed`:return{...e,restartNeeded:n.reasons};case`server_restarting`:return{...e,serverRestarting:!0,piPackageUpdate:null};case`reply_structured_conformance`:return{...e,replyConformance:{...e.replyConformance,[n.key]:n.conformance}};case`queue`:return{...e,queue:n.prompts,pendingPrompt:n.prompts.length>e.queue.length?null:e.pendingPrompt};case`queued_prompt_refused`:return{...e,errors:[...e.errors,n.message],queuedEditRefused:n.text===void 0?e.queuedEditRefused:{text:n.text,nonce:(e.queuedEditRefused?.nonce??0)+1}};case`context_usage`:return{...e,contextUsage:n.usage};case`confinement`:return{...e,confinement:n.confinement};case`sandbox_grant_request`:{let t=e.sandboxGrants??{pending:[],active:{hosts:[],directories:[]}};return t.pending.some(e=>e.id===n.request.id)?e:{...e,sandboxGrants:{...t,pending:[...t.pending,n.request]}}}case`sandbox_grant_resolved`:return e.sandboxGrants?{...e,sandboxGrants:{...e.sandboxGrants,pending:e.sandboxGrants.pending.filter(e=>e.id!==n.id)}}:e;case`sandbox_grants`:return{...e,sandboxGrants:{pending:e.sandboxGrants?.pending??[],active:n.active}};case`compaction_start`:return{...e,isCompacting:!0};case`compaction_end`:return{...e,isCompacting:!1,errors:n.errorMessage?[...e.errors,n.errorMessage]:e.errors};case`error`:return{...e,errors:[...e.errors,n.message],pendingPrompt:null,settingsApply:e.settingsApply?.status===`applying`?{status:`error`,message:n.message}:e.settingsApply};case`server_directory`:return e.serverBrowse?.requestId===n.requestId?{...e,serverBrowse:{status:`loaded`,path:n.path,parent:n.parent,entries:n.entries,requestId:n.requestId}}:e;case`server_directory_error`:return e.serverBrowse?.requestId===n.requestId?{...e,serverBrowse:{...e.serverBrowse,status:`error`,error:n.message}}:e;case`directory_listing`:return n.requestId.startsWith(`dir:`)&&e.directoryRequests[n.path]!==n.requestId?e:{...e,fileTree:{...e.fileTree,[n.path]:n.entries},...n.requestId.startsWith(`create:`)?{created:n.path,createError:null}:{}};case`file_content`:{let t=e.openFile,r=t?.status===`loading`&&t.requestId===n.requestId,i=t?.status===`loaded`&&t.refreshRequestId===n.requestId;return!r&&!i?e:{...e,openFile:{status:`loaded`,path:n.path,content:n.content,size:n.size,mtimeMs:n.mtimeMs,...n.documentIssues===void 0?{}:{documentIssues:n.documentIssues},...r&&t.reveal?{reveal:t.reveal}:{}}}}case`file_written`:{if(n.requestId.startsWith(`create:`))return{...e,createError:null,created:n.path,openFile:{status:`loaded`,path:n.path,content:``,size:n.size,mtimeMs:n.mtimeMs,justCreated:!0}};let t=e.openFile;return t?.status!==`loaded`||t.pendingSave?.requestId!==n.requestId?e:{...e,openFile:{status:`loaded`,path:t.path,content:t.pendingSave.content,size:n.size,mtimeMs:n.mtimeMs}}}case`file_operation_result`:{if(e.fileOperation?.status!==`pending`||e.fileOperation.requestId!==n.requestId)return e;let t=n.previousPath??n.path,r=n.operation===`delete_file`&&e.openFile?.path===n.path?null:e.openFile?.path===t?{...e.openFile,path:n.path}:e.openFile,i=e.gitFileHistory?.path===t||e.gitFileHistory?.path===n.path,a=e.gitDiff?.path===t||e.gitDiff?.path===n.path,o=e.gitBaseline?.path===t||e.gitBaseline?.path===n.path;return{...e,openFile:r,gitFileHistory:i?null:e.gitFileHistory,gitFileDiff:i?null:e.gitFileDiff,gitDiff:a?null:e.gitDiff,gitBaseline:o?null:e.gitBaseline,fileOperation:{status:`succeeded`,operation:n.operation,path:e.fileOperation.path,resultPath:n.path,requestId:n.requestId}}}case`file_browser_error`:if(n.requestId.startsWith(`dir:`))return e.directoryRequests[n.path]===n.requestId?{...e,fileTree:{...e.fileTree,[n.path]:{error:n.message}}}:e;if(n.requestId.startsWith(`create:`))return{...e,createError:{path:n.path,message:n.message}};if(n.requestId.startsWith(`write:`)){let t=e.openFile;return t?.status!==`loaded`||t.pendingSave?.requestId!==n.requestId?e:{...e,openFile:{...t,pendingSave:void 0,saveError:{message:n.message,conflict:n.reason===`conflict`}}}}return n.requestId.startsWith(`fileop:`)?e.fileOperation?.status!==`pending`||e.fileOperation.requestId!==n.requestId?e:{...e,fileOperation:{status:`error`,operation:e.fileOperation.operation,path:e.fileOperation.path,message:n.message,requestId:n.requestId}}:e.openFile?.status===`loading`&&e.openFile.requestId===n.requestId?{...e,openFile:{status:`error`,path:n.path,message:n.message}}:e.openFile?.status===`loaded`&&e.openFile.refreshRequestId===n.requestId?{...e,openFile:{...e.openFile,refreshRequestId:void 0}}:e;case`file_search_results`:return e.fileSearch?.requestId===n.requestId?{...e,fileSearch:{...e.fileSearch,status:`loaded`,results:n.results}}:e;case`content_search_results`:return e.contentSearch?.requestId===n.requestId?{...e,contentSearch:{...e.contentSearch,status:`loaded`,hits:n.hits,truncated:n.truncated,skipped:n.skipped}}:e;case`git_status`:{let t={};for(let e of n.files)t[e.path]=e.status;let r=e.gitStatus;if(n.repo===void 0||r===null)return{...e,gitStatus:{repos:n.repos,files:t}};let i={};for(let[e,t]of Object.entries(r.files))NV(r.repos,e)?.repo!==n.repo&&(i[e]=t);let a=r.repos.map(e=>n.repos.find(t=>t.repo===e.repo)??e);return{...e,gitStatus:{repos:a,files:{...i,...t}}}}case`git_repositories_changed`:return{...e,gitAvailable:n.available,gitUnavailable:n.available?null:n.unavailable??null,gitStatus:n.available?e.gitStatus:null};case`git_diff`:return n.requestId.startsWith(`gitbase:`)?e.gitBaseline?.requestId===n.requestId?{...e,gitBaseline:{...e.gitBaseline,text:n.before}}:e:{...e,gitDiff:{path:n.path,before:n.before,after:n.after}};case`git_log`:return e.gitLog===null?e:{...e,gitLog:{...e.gitLog,repo:n.repo,entries:n.entries,error:null}};case`git_show`:return{...e,gitShow:{sha:n.sha,patch:n.patch,truncated:n.truncated}};case`git_file_log`:return e.gitFileHistory?.requestId===n.requestId?{...e,gitFileHistory:{...e.gitFileHistory,status:`loaded`,entries:n.entries}}:e;case`git_file_diff`:return e.gitFileDiff===null||!O1(e.gitFileDiff,n)?e:{...e,gitFileDiff:{...e.gitFileDiff,status:`loaded`,beforeText:n.beforeText,afterText:n.afterText}};case`git_error`:return n.requestId.startsWith(`gitbase:`)?e.gitBaseline?.requestId===n.requestId?{...e,gitBaseline:null}:e:n.requestId.startsWith(`gitdiff:`)?{...e,gitDiff:e.openFile?{path:e.openFile.path,error:n.message}:null}:n.requestId===e.gitFileHistory?.requestId?{...e,gitFileHistory:{...e.gitFileHistory,status:`error`,error:n.message}}:n.requestId===e.gitFileDiff?.requestId?{...e,gitFileDiff:{...e.gitFileDiff,status:`error`,error:n.message}}:n.requestId.startsWith(`gitlog:`)?n.requestId===e.gitLog?.requestId?{...e,gitLog:{...e.gitLog,entries:null,error:n.message}}:e:{...e,errors:[...e.errors,`git: ${n.message}`]};case`extension_ui_request`:switch(n.method){case`select`:case`confirm`:case`input`:case`editor`:return{...e,dialogQueue:[...e.dialogQueue,n]};case`notify`:return{...e,notifications:[...e.notifications,{id:n.id,message:n.message,notifyType:n.notifyType}]};case`setStatus`:{let t={...e.statuses};return n.statusText===void 0?delete t[n.statusKey]:t[n.statusKey]=n.statusText,{...e,statuses:t}}case`setWidget`:{let t={...e.widgets};return n.widgetLines===void 0?delete t[n.widgetKey]:t[n.widgetKey]={lines:n.widgetLines,placement:n.widgetPlacement??`aboveEditor`},{...e,widgets:t}}case`setTitle`:return{...e,extensionTitle:n.title};case`set_editor_text`:return{...e,editorPrefill:{text:n.text,nonce:e.editorPrefill?e.editorPrefill.nonce+1:1}};default:return e}default:return e}}function L1(e,t,n){let r=e?`${e.replace(/^http/,`ws`)}/ws`:`${location.protocol===`https:`?`wss`:`ws`}://${location.host}/ws`,i=new URLSearchParams;t&&i.set(`token`,t),n&&i.set(`workspace`,n);let a=i.toString();return a?`${r}?${a}`:r}var R1=12e4,z1=3e4,B1=2e4,V1=45e3,H1=4401,U1=1e3;function W1(e=``,t,n=!1,r){let[i,a]=(0,v.useReducer)(I1,A1),o=(0,v.useRef)(null),[s,c]=(0,v.useState)(0),l=(0,v.useRef)(null),u=(0,v.useRef)(null);s===0&&l.current===null&&(l.current=t??(n?C1():S1()));let d=(0,v.useRef)(i.fileTree),f=(0,v.useRef)(i.openFile);(0,v.useEffect)(()=>{d.current=i.fileTree},[i.fileTree]),(0,v.useEffect)(()=>{f.current=i.openFile},[i.openFile]);let p=(0,v.useRef)(null);(0,v.useEffect)(()=>{p.current=i.gitDiff?.path??null},[i.gitDiff]);let m=(0,v.useRef)(new Map),h=(0,v.useRef)(new Map),g=(0,v.useRef)(new Map),_=(0,v.useRef)(new Map),y=(0,v.useRef)(i.sessionId);(0,v.useEffect)(()=>{y.current=i.sessionId},[i.sessionId]);let b=(0,v.useRef)(!1),x=(0,v.useRef)(i.olderHistory);(0,v.useEffect)(()=>{x.current=i.olderHistory},[i.olderHistory]);let S=(0,v.useRef)(i.writableRoot);(0,v.useEffect)(()=>{S.current=i.writableRoot},[i.writableRoot]);let C=(0,v.useRef)(!1),w=(0,v.useRef)(new Map),T=(0,v.useRef)(new Map),E=i.workspace?GB(i.workspace):null,D=(0,v.useRef)({key:E,root:i.sandbox?.projectRoot??i.sandbox?.root,writableRoot:i.writableRoot}),O=(0,v.useRef)(0),ee=O.current,te=(0,v.useRef)({workspaceRoot:E,sessionId:i.sessionId});(0,v.useEffect)(()=>{te.current={workspaceRoot:E,sessionId:i.sessionId}},[E,i.sessionId]);let k=(0,v.useCallback)(e=>{[`switch_workspace`,`open_project`,`close_project`,`open_side_session`].includes(e.type)&&O.current++;let t=o.current;t&&t.readyState===WebSocket.OPEN&&t.send(JSON.stringify(e))},[]),ne=(0,v.useRef)(!1),A=(0,v.useRef)(null),re=(0,v.useRef)(!1),j=(0,v.useRef)(null),ie=(0,v.useRef)(()=>{}),ae=(0,v.useCallback)(()=>{A.current=null,j.current!==null&&(clearTimeout(j.current),j.current=null)},[]),oe=(0,v.useCallback)(()=>{let e=o.current;if(!e||e.readyState!==WebSocket.OPEN)return;if(A.current!==null){re.current=!0;return}let t=`outcome:${b1()}`;A.current=t;let n=te.current;a({type:`outcome_started`,requestId:t,...n}),k({type:`get_outcome`,requestId:t}),j.current=setTimeout(()=>{A.current===t&&(ae(),re.current=!1,a({type:`outcome_failed`,requestId:t,message:`The Outcome took too long to answer — try again.`}))},V1)},[k,ae]);ie.current=oe;let ce=(0,v.useCallback)(()=>{ne.current&&ie.current()},[]),ue=(0,v.useCallback)(e=>{ne.current=e,e?oe():re.current=!1},[oe]),de=(0,v.useCallback)((e,t=!1)=>{e===``&&(C.current=!0);let n=`dir:${b1()}`;a({type:`dir_list_started`,path:e,requestId:n,preserveEntries:t}),k({type:`list_directory`,path:e,requestId:n})},[k]),fe=(0,v.useRef)(!1),M=(0,v.useRef)(null),pe=(0,v.useCallback)((e,t)=>{let n=`gitlog:${b1()}`;a({type:`git_log_started`,repo:e,requestId:n}),k({type:`git_log`,repo:e,...t?{limit:t}:{},requestId:n})},[k]),N=(0,v.useRef)([]);(0,v.useEffect)(()=>{N.current=i.gitStatus?.repos??[]},[i.gitStatus]);let me=(0,v.useRef)(new Set),he=(0,v.useRef)(new Set),ge=(0,v.useRef)(new Map),P=(0,v.useCallback)(e=>{if(!fe.current)return;let t=e??``;if(me.current.has(t)){he.current.add(t);return}me.current.add(t);let n=`git:${b1()}`;ge.current.set(n,t),k({type:`git_status`,...e===void 0?{}:{repo:e},requestId:n})},[k]),_e=(0,v.useCallback)(e=>{let t=ge.current.get(e)??``;ge.current.delete(e),me.current.delete(t),he.current.delete(t)&&P(t===``?void 0:t)},[P]),ve=(0,v.useCallback)(e=>{d.current[e]!==void 0&&de(e,!0)},[de]),ye=(0,v.useCallback)(()=>{de(``,!0);for(let e of Object.keys(d.current))e!==``&&ve(e)},[ve,de]);(0,v.useEffect)(()=>{i.connected&&C.current&&d.current[``]===void 0&&de(``)},[i.connected,i.fileTree,de]),(0,v.useEffect)(()=>{i.connected&&ne.current&&A.current===null&&ie.current()},[i.connected]);let be=i.openFile?.path??null,xe=be===null?void 0:i.gitStatus?.files[be],Se=i.gitBaseline!==null;(0,v.useEffect)(()=>{let e=xe===`modified`||xe===`added`||xe===`conflicted`;if(!i.connected||be===null||!e){Se&&a({type:`git_baseline_cleared`});return}let t=`gitbase:${b1()}`;a({type:`git_baseline_started`,path:be,requestId:t}),k({type:`git_diff`,path:be,requestId:t})},[i.connected,be,xe,i.gitStatus,k]),(0,v.useEffect)(()=>{let t=!1;return fetch(`${e}/branding`,{headers:l.current?{Authorization:`Bearer ${l.current}`}:{}}).then(e=>e.ok?e.json():null).then(e=>{t||a(e?{type:`branding_loaded`,branding:e}:{type:`branding_settled`})}).catch(()=>{t||a({type:`branding_settled`})}),()=>{t=!0}},[e,s]),(0,v.useEffect)(()=>{let t,n=!1;function i(){let s=new WebSocket(L1(e,l.current,r));o.current=s,s.onopen=()=>{o.current===s&&a({type:`connected`})},s.onmessage=e=>{if(o.current!==s)return;let t;try{t=JSON.parse(e.data)}catch{return}if(t.type===`hello`){for(let e of T.current.values())if(e.socket!==s){for(let t of w.current.get(e.message.terminalId)?.onData??[])t(`\r
1535
1536
  [Connection restored; starting a new terminal session.]\r
1536
- `);e.socket=s,s.send(JSON.stringify(e.message))}}if(t.type===`terminal_data`){let e=w.current.get(t.terminalId);if(e)for(let n of e.onData)n(t.data)}else if(t.type===`terminal_cwd`){let e=T.current.get(t.terminalId);e&&(e.message.cwd=t.cwd);let n=w.current.get(t.terminalId);if(n)for(let e of n.onCwd)e(t.cwd)}else if(t.type===`terminal_exit`){T.current.delete(t.terminalId);let e=w.current.get(t.terminalId);if(e)for(let n of e.onExit)n(t.exitCode)}else if(t.type===`terminal_error`){T.current.delete(t.terminalId);let e=w.current.get(t.terminalId);if(e)for(let n of e.onError)n(t.message)}else if(t.type===`history_items`){let e=_.current.get(t.requestId);e&&(_.current.delete(t.requestId),e.resolve({items:t.items,remaining:t.remaining}))}else if(t.type===`history_unavailable`){let e=_.current.get(t.requestId);e&&(_.current.delete(t.requestId),e.reject(new w1(t.reason,t.kind)))}else if((t.type===`file_content`||t.type===`file_written`||t.type===`arrangement_saved`||t.type===`file_browser_error`)&&h.current.has(t.requestId)){let e=h.current.get(t.requestId);h.current.delete(t.requestId),t.type===`file_browser_error`?e.reject(new wz(t.message,t.reason)):t.type===`file_content`?e.resolve({content:t.content,mtimeMs:t.mtimeMs}):t.type===`arrangement_saved`?e.resolve({path:t.path}):e.resolve({mtimeMs:t.mtimeMs})}else if(t.type===`file_search_results`&&h.current.has(t.requestId)){let e=h.current.get(t.requestId);h.current.delete(t.requestId),e.resolve({results:t.results})}else{if(t.type===`hello`||t.type===`workspace_switched`||t.type===`workspace_starting`||t.type===`session_replaced`||t.type===`update_config_ack`){let e={key:t.workspace?GB(t.workspace):null,root:t.sandbox?.projectRoot??t.sandbox?.root,writableRoot:t.writableRoot},n=D.current;(t.type===`hello`||n.key!==e.key||n.root!==e.root||n.writableRoot!==e.writableRoot)&&O.current++,D.current=e,S.current=t.writableRoot}if(t.type===`file_uploaded`){let e=m.current.get(t.requestId);e&&(m.current.delete(t.requestId),e.resolve(t.path))}else if(t.type===`file_browser_error`&&m.current.has(t.requestId)){let e=m.current.get(t.requestId);m.current.delete(t.requestId),e.reject(new RV(t.message,t.reason))}else if(t.type===`file_changed`){ce();for(let e of g.current.get(t.path)??[])e();ve(E1(t.path));let e=f.current;if(e?.status===`loaded`&&e.path===t.path){let e=`file:${y1()}`;a({type:`file_read_started`,path:t.path,requestId:e,preserveContent:!0}),k({type:`read_file`,path:t.path,requestId:e})}p.current===t.path&&k({type:`git_diff`,path:t.path,requestId:`gitdiff:${y1()}`}),P(NV(N.current,t.path)?.repo)}else if(t.type===`directory_changed`){ce();for(let[e,n]of g.current)if(E1(e)===t.path)for(let e of n)e();ve(t.path);let e=f.current;if(e!==null&&E1(e.path)===t.path){if(se(e.path)||le(e.path))a({type:`raw_preview_changed`,path:e.path});else if(e.status===`loaded`){let t=`file:${y1()}`;a({type:`file_read_started`,path:e.path,requestId:t,preserveContent:!0}),k({type:`read_file`,path:e.path,requestId:t})}}let n=p.current;n!==null&&E1(n)===t.path&&k({type:`git_diff`,path:n,requestId:`gitdiff:${y1()}`}),P()}else{if((t.type===`hello`||t.type===`session_replaced`||t.type===`workspace_switched`||t.type===`workspace_starting`)&&(fe.current=t.gitAvailable===!0,t.type!==`session_replaced`&&P()),t.type===`agent_end`&&(P(),ce()),t.type===`git_repositories_changed`&&(ce(),fe.current=t.available,t.available&&P()),t.type===`git_changed`){ce(),P(t.repo===``?void 0:t.repo);let e=M.current;e!==null&&e.repo===t.repo&&pe(e.repo,e.limit)}if((t.type===`git_status`||t.type===`git_error`&&t.requestId.startsWith(`git:`))&&_e(t.requestId),t.type===`work_plan_changed`&&ce(),(t.type===`workspace_outcome`||t.type===`workspace_outcome_error`)&&A.current===t.requestId&&(ae(),re.current&&(re.current=!1,queueMicrotask(()=>ie.current()))),t.type===`hello`||t.type===`session_replaced`||t.type===`workspace_switched`||t.type===`workspace_starting`||t.type===`update_config_ack`){ae(),re.current=!1;let e=te.current,n=t.sessionId===e.sessionId,r=(t.workspace?GB(t.workspace):null)===e.workspaceRoot;ne.current&&n&&r&&queueMicrotask(()=>ie.current())}if(t.type===`file_operation_result`){let e=t.previousPath??t.path,n=f.current;t.operation===`delete_file`&&n?.path===t.path?f.current=null:n?.path===e&&(f.current={...n,path:t.path})}a({type:`server`,message:t}),t.type===`session_replaced`&&de(``)}}},s.onclose=e=>{if(o.current===s){O.current++,me.current.clear(),he.current.clear(),ge.current.clear(),ae(),re.current=!1;for(let e of m.current.values())e.reject(new RV(`The connection dropped before the upload finished`));m.current.clear();for(let e of h.current.values())e.reject(new wz(`The connection dropped before the server answered`));h.current.clear();for(let e of _.current.values())e.reject(new w1(`the connection dropped before the older messages arrived`,`failed`));_.current.clear(),e.code===V1?a({type:`auth_required`}):(a({type:`disconnected`}),n||(t=window.setTimeout(i,1500)))}}}return i(),()=>{n=!0,t!==void 0&&clearTimeout(t);let e=o.current;o.current=null,e?.close()}},[k,e,P,_e,ve,de,ce,ae,s,r,pe]);let Ce=(0,v.useCallback)((e,t)=>{let n=o.current;if(!n||n.readyState!==WebSocket.OPEN)return Promise.reject(new w1(`not connected to the server`,`failed`));let r=`history:${y1()}`;return new Promise((n,i)=>{let a=window.setTimeout(()=>{_.current.delete(r)&&i(new w1(`the older messages did not arrive`,`failed`))},z1),o=e=>t=>{clearTimeout(a),e(t)};_.current.set(r,{resolve:o(n),reject:o(i)}),k({type:`history_before`,sessionId:y.current,have:e,count:t,requestId:r})})},[k]),we=(0,v.useCallback)(async()=>{let e=x.current;if(!(!e||e.loading||b.current||e.remaining<=0)){b.current=!0,a({type:`history_load_started`});try{let t=await Ce(e.have,50);a({type:`history_loaded`,items:t.items,remaining:t.remaining})}catch(e){if(e instanceof w1&&e.kind===`stale`){a({type:`history_load_failed`,message:``});return}a({type:`history_load_failed`,message:e instanceof Error?e.message:`the older messages could not be loaded`})}finally{b.current=!1}}},[Ce]);return{state:i,fileIo:(0,v.useMemo)(()=>{function e(e,t){let n=o.current;if(!n||n.readyState!==WebSocket.OPEN)return Promise.reject(new wz(`not connected to the server`));let r=`${e}:${y1()}`;return new Promise((e,n)=>{let i=window.setTimeout(()=>{h.current.delete(r)&&n(new wz(`the server did not answer`))},R1);h.current.set(r,{resolve:t=>{clearTimeout(i),e(t)},reject:e=>{clearTimeout(i),n(e)}}),k(t(r))})}return{read:t=>e(`fileio-read`,e=>({type:`read_file`,path:t,requestId:e})),write:(t,n,r)=>e(`fileio-write`,e=>({type:`write_file`,path:t,content:n,expectedMtimeMs:r,requestId:e})),find:async t=>(await e(`fileio-find`,e=>({type:`search_files`,query:t,requestId:e}))).results,keepArrangement:async(t,n)=>(await e(`fileio-arrangement`,e=>({type:`save_arrangement`,documentPath:t,content:n,requestId:e}))).path,onChanged:(e,t)=>{let n=g.current.get(e)??new Set;return n.add(t),g.current.set(e,n),()=>{n.delete(t),n.size===0&&g.current.delete(e)}}}},[k]),setOutcomeActive:ue,refreshOutcome:oe,authToken:l.current,switchWorkspace:(e,t)=>{((t??e)!==E||i.switching)&&(a({type:`workspace_switching`}),k({type:`switch_workspace`,root:e,...t!==void 0&&t!==e?{id:t}:{}}))},openProject:e=>{a({type:`workspace_switching`}),k({type:`open_project`,root:e})},closeProject:(e,t)=>k({type:`close_project`,root:e,...t!==void 0&&t!==e?{id:t}:{}}),checkPiPackages:()=>k({type:`check_pi_packages`}),updatePiPackage:e=>{let t=`pkg:${y1()}`;a({type:`pi_package_update_started`,requestId:t,source:e}),k({type:`update_pi_package`,source:e,requestId:t})},restartServer:()=>k({type:`restart_server`}),restartSession:()=>{a({type:`settings_apply_started`}),k({type:`restart_session`})},openSideSession:e=>{a({type:`workspace_switching`}),k({type:`open_side_session`,root:e})},submitToken:e=>{C1(e),l.current=e,a({type:`auth_retrying`}),c(e=>e+1)},prompt:(e,t)=>{a({type:`prompt_sent`,text:e,...t?.length?{images:t}:{}}),k({type:`prompt`,text:e,...t?.length?{images:t}:{}})},abort:()=>k({type:`abort`}),cancelPendingPrompt:e=>{a({type:`pending_prompt_cancelled`,restoreText:e}),k({type:`abort`})},setModel:(e,t)=>k({type:`set_model`,provider:e,id:t}),setThinking:e=>k({type:`set_thinking`,level:e}),newSession:()=>k({type:`new_session`}),switchSession:e=>k({type:`switch_session`,path:e}),deleteSession:e=>k({type:`delete_session`,path:e}),listSessions:()=>k({type:`list_sessions`}),renameSession:(e,t)=>k({type:`rename_session`,path:e,name:t}),searchSessions:e=>{let t=`sessions:${y1()}`;a({type:`session_search_started`,query:e,requestId:t}),k({type:`search_sessions`,query:e,requestId:t})},clearSessionSearch:()=>a({type:`session_search_cleared`}),listTree:()=>k({type:`list_tree`}),navigateTree:e=>k({type:`navigate_tree`,entryId:e}),forkSession:e=>k({type:`fork_session`,entryId:e}),editPrompt:(e,t,n)=>k({type:`edit_prompt`,entryId:e,text:t,...n?.length?{images:n}:{}}),compact:()=>k({type:`compact`}),fetchOlderItems:Ce,loadOlderItems:we,respondToDialog:e=>{k({type:`extension_ui_response`,...e}),a({type:`dialog_answered`})},respondToGrant:(e,t)=>k({type:`sandbox_grant_response`,id:e,decision:t}),dismissNotification:e=>a({type:`dismiss_notification`,id:e}),listDirectory:e=>de(e),refreshFileTree:ye,readFile:(e,t,n)=>{let r=`file:${y1()}`;a({type:`file_read_started`,path:e,requestId:r,...n?{reveal:n}:{}}),k({type:`read_file`,path:e,requestId:r,...t===void 0?{}:{sha256:t}})},closeFilePreview:()=>a({type:`close_file_preview`}),writeFile:(e,t,n,r=!1)=>{let i=`write:${y1()}`;a({type:`file_save_started`,path:e,requestId:i,content:t}),k({type:`write_file`,path:e,content:t,expectedMtimeMs:n,...r?{force:r}:{},requestId:i})},createFile:e=>{a({type:`file_create_started`}),k({type:`create_file`,path:e,requestId:`create:${y1()}`})},uploadFile:(e,t,n)=>{if(n!==void 0&&(i.switching||ee!==O.current))return Promise.reject(new zV);let r=S.current;if(r===null)return Promise.reject(new RV(`the workspace is read-only`,`denied`));let a=o.current;if(!a||a.readyState!==WebSocket.OPEN)return Promise.reject(new RV(`not connected to the server`));let s=n??(r?`${r}/uploads`:`uploads`),c=`upload:${y1()}`;return new Promise((r,i)=>{let a=window.setTimeout(()=>{m.current.delete(c)&&i(new RV(`the upload timed out`))},L1),o=e=>t=>{clearTimeout(a),e(t)};m.current.set(c,{resolve:o(e=>{if(n!==void 0){if(ee!==O.current){i(new zV);return}de(n,!0)}r(e)}),reject:o(i)}),k({type:`upload_file`,destinationDirectory:s,name:e,contentBase64:t,requestId:c,...n===void 0?{}:{existingDirectory:!0,workspaceId:E??void 0}})})},createDirectory:e=>{a({type:`file_create_started`}),k({type:`create_directory`,path:e,requestId:`create:${y1()}`})},openNative:e=>{let t=`fileop:${y1()}`;a({type:`file_operation_started`,operation:`open_native`,path:e,requestId:t}),k({type:`open_native`,path:e,requestId:t})},revealNative:e=>{let t=Date.now();if(u.current?.path===e&&t-u.current.at<H1)return;u.current={path:e,at:t};let n=`fileop:${y1()}`;a({type:`file_operation_started`,operation:`reveal_native`,path:e,requestId:n}),k({type:`reveal_native`,path:e,requestId:n})},renameFile:(e,t)=>{let n=`fileop:${y1()}`;a({type:`file_operation_started`,operation:`rename_file`,path:e,requestId:n}),k({type:`rename_file`,path:e,name:t,requestId:n})},deleteFile:e=>{let t=`fileop:${y1()}`;a({type:`file_operation_started`,operation:`delete_file`,path:e,requestId:t}),k({type:`delete_file`,path:e,requestId:t})},moveFile:(e,t)=>{let n=`fileop:${y1()}`;a({type:`file_operation_started`,operation:`move_file`,path:e,requestId:n}),k({type:`move_file`,path:e,destinationDirectory:t,requestId:n})},copyFile:(e,t)=>{let n=`fileop:${y1()}`;a({type:`file_operation_started`,operation:`copy_file`,path:e,requestId:n}),k({type:`copy_file`,path:e,destinationDirectory:t,requestId:n})},searchFiles:e=>{let t=`search:${y1()}`;a({type:`file_search_started`,query:e,requestId:t}),k({type:`search_files`,query:e,requestId:t})},clearFileSearch:()=>a({type:`file_search_cleared`}),searchContent:e=>{if(e.trim()===``){a({type:`content_search_cleared`});return}let t=`content:${y1()}`;a({type:`content_search_started`,query:e,requestId:t}),k({type:`search_content`,query:e,requestId:t})},clearContentSearch:()=>a({type:`content_search_cleared`}),fetchGitStatus:()=>P(),fetchGitDiff:e=>{let t=`gitdiff:${y1()}`;a({type:`git_diff_started`,path:e,requestId:t}),k({type:`git_diff`,path:e,requestId:t})},clearGitDiff:()=>a({type:`git_diff_cleared`}),fetchGitLog:(e,t)=>{M.current={repo:e,limit:t},pe(e,t)},closeGitLog:()=>{M.current=null,a({type:`git_log_closed`})},fetchGitShow:(e,t)=>k({type:`git_show`,repo:e,sha:t,requestId:`gitshow:${y1()}`}),clearGitShow:()=>a({type:`git_show_cleared`}),fetchGitFileHistory:(e,t)=>{let n=`gitfilelog:${y1()}`;a({type:`git_file_history_started`,path:e,requestId:n}),k({type:`git_file_log`,path:e,...t?{limit:t}:{},requestId:n})},closeGitFileHistory:()=>a({type:`git_file_history_closed`}),fetchGitFileDiff:(e,t)=>{let n=`gitfilediff:${y1()}`;a({type:`git_file_diff_started`,base:e,target:t,requestId:n}),k({type:`git_file_diff`,base:e,target:t,requestId:n})},clearGitFileDiff:()=>a({type:`git_file_diff_cleared`}),setCredential:(e,t)=>k({type:`set_credential`,provider:e,apiKey:t}),startLogin:(e,t)=>{let n=y1();a({type:`login_started`,flowId:n,provider:e,method:t}),k({type:`start_login`,flowId:n,provider:e,method:t})},answerLogin:e=>{let t=i.login;t?.prompt&&(k({type:`login_answer`,flowId:t.flowId,promptId:t.prompt.promptId,value:e}),a({type:`login_answered`}))},cancelLogin:()=>{let e=i.login;e&&!e.done&&k({type:`cancel_login`,flowId:e.flowId})},dismissLogin:()=>a({type:`login_dismissed`}),logoutProvider:e=>k({type:`logout_provider`,provider:e}),declareProvider:e=>k({type:`declare_provider`,...e}),browseServerDirectory:e=>{let t=`serverdir:${y1()}`;a({type:`server_browse_started`,path:e,requestId:t}),k({type:`browse_server_directory`,path:e,requestId:t})},closeServerBrowser:()=>a({type:`server_browse_closed`}),suggestAgentResourceClonePath:e=>{let t=`resource-clone-path:${y1()}`;a({type:`resource_clone_path_started`,requestId:t}),k({type:`suggest_agent_resource_clone_path`,repositoryUrl:e,requestId:t})},cloneAgentResourceRepository:(e,t)=>{let n=`resource-preview:${y1()}`;a({type:`resource_preview_started`,requestId:n}),k({type:`clone_agent_resource_repository`,repositoryUrl:e,destinationPath:t,requestId:n})},enrollAgentResourceRepository:(e,t,n,r)=>{let i=`resource-enroll:${y1()}`;a({type:`resource_enrollment_started`,requestId:i}),k({type:`enroll_agent_resource_repository`,previewToken:e,skillRoots:t,extensionRoots:n,...r?{enabledSkills:r}:{},requestId:i})},setAgentResourceSkills:(e,t)=>{let n=`resource-skills:${y1()}`;a({type:`resource_skills_started`,requestId:n,repositoryId:e}),k({type:`set_agent_resource_skills`,repositoryId:e,enabledSkills:t,requestId:n})},removeAgentResourceRepository:e=>{let t=`resource-remove:${y1()}`;a({type:`resource_removal_started`,requestId:t,repositoryId:e}),k({type:`remove_agent_resource_repository`,repositoryId:e,requestId:t})},refreshAgentResourceRepositories:e=>{let t=`resource-refresh:${y1()}`;a({type:`resource_refresh_started`,requestId:t,...e?{repositoryId:e}:{}}),k({type:`refresh_agent_resource_repositories`,...e?{repositoryId:e}:{},requestId:t})},updateAgentResourceRepository:(e,t,n,r,i=!1)=>{let o=`resource-update:${y1()}`;a({type:`resource_update_started`,requestId:o,repositoryId:e}),k({type:`update_agent_resource_repository`,repositoryId:e,assessmentToken:t,localRevision:n,upstreamRevision:r,...i?{allowExecutableChanges:!0}:{},requestId:o})},updateConfig:e=>{a({type:`settings_apply_started`}),k({type:`update_config`,...e})},openTerminal:(e,t,n,r,i)=>{let a={type:`terminal_open`,terminalId:e,cwd:t,cols:n,rows:r,...i?{shellId:i}:{}};T.current.set(e,{message:a,socket:o.current?.readyState===WebSocket.OPEN?o.current:null}),k(a)},sendTerminalInput:(e,t)=>k({type:`terminal_input`,terminalId:e,data:t}),getTerminalCwd:e=>k({type:`terminal_get_cwd`,terminalId:e}),resizeTerminal:(e,t,n)=>{let r=T.current.get(e);r&&Object.assign(r.message,{cols:t,rows:n}),k({type:`terminal_resize`,terminalId:e,cols:t,rows:n})},closeTerminal:e=>{T.current.delete(e),k({type:`terminal_close`,terminalId:e}),w.current.delete(e)},subscribeTerminal:(e,t)=>{let n=w.current.get(e);return n||(n={onData:new Set,onCwd:new Set,onExit:new Set,onError:new Set},w.current.set(e,n)),t.onData&&n.onData.add(t.onData),t.onCwd&&n.onCwd.add(t.onCwd),t.onExit&&n.onExit.add(t.onExit),t.onError&&n.onError.add(t.onError),()=>{t.onData&&n?.onData.delete(t.onData),t.onCwd&&n?.onCwd.delete(t.onCwd),t.onExit&&n?.onExit.delete(t.onExit),t.onError&&n?.onError.delete(t.onError)}}}}var W1=120;function G1({label:e}){return(0,N.jsx)(`div`,{className:`flex justify-end px-4`,role:`status`,"aria-live":`polite`,children:(0,N.jsxs)(`div`,{className:`flex items-center gap-2 py-1`,children:[(0,N.jsx)(`span`,{className:`inline-block h-4 w-4 animate-spin rounded-full border-[3px] border-zinc-300 border-t-blue-500 dark:border-zinc-600 dark:border-t-blue-400 motion-reduce:animate-pulse`}),(0,N.jsx)(`span`,{className:`text-xs text-zinc-400 dark:text-zinc-500`,children:e})]})})}var K1=(0,v.forwardRef)(function({serverUrl:e=``,rootElement:t,initialTheme:n,token:r,workspace:i},a){let o=t!==void 0,s=t??document.documentElement,{state:c,authToken:l,submitToken:u,prompt:d,abort:f,cancelPendingPrompt:p,setModel:m,setThinking:h,newSession:g,switchSession:_,deleteSession:y,listSessions:x,renameSession:S,searchSessions:C,clearSessionSearch:w,listTree:T,navigateTree:D,forkSession:O,editPrompt:ee,compact:te,loadOlderItems:k,fetchOlderItems:ne,respondToDialog:A,respondToGrant:re,dismissNotification:j,listDirectory:ie,refreshFileTree:ae,readFile:oe,searchContent:se,writeFile:ce,createFile:le,createDirectory:ue,uploadFile:de,openNative:M,revealNative:pe,renameFile:me,deleteFile:he,moveFile:ge,copyFile:P,closeFilePreview:_e,searchFiles:ve,clearFileSearch:be,fetchGitDiff:xe,clearGitDiff:Se,fetchGitLog:Ce,closeGitLog:we,fetchGitShow:Te,clearGitShow:Ee,fetchGitFileHistory:De,closeGitFileHistory:Oe,fetchGitFileDiff:ke,clearGitFileDiff:Ae,setCredential:je,startLogin:Me,answerLogin:Ne,cancelLogin:Pe,dismissLogin:Fe,logoutProvider:Ie,declareProvider:Le,updateConfig:Re,suggestAgentResourceClonePath:ze,cloneAgentResourceRepository:Be,enrollAgentResourceRepository:Ve,setAgentResourceSkills:He,removeAgentResourceRepository:Ue,refreshAgentResourceRepositories:We,updateAgentResourceRepository:Ge,browseServerDirectory:Ke,closeServerBrowser:qe,switchWorkspace:Je,openProject:Ye,closeProject:Xe,openSideSession:Ze,checkPiPackages:Qe,updatePiPackage:et,restartServer:tt,restartSession:nt,openTerminal:rt,sendTerminalInput:it,getTerminalCwd:at,resizeTerminal:ot,closeTerminal:st,subscribeTerminal:ct,setOutcomeActive:lt,refreshOutcome:ut,fileIo:dt}=U1(e,r,o,i),ft=fe(c.workspace);hG(c.workspaces,c.workspace?GB(c.workspace):null);let pt=c.workspace?GB(c.workspace):null;(0,v.useEffect)(()=>{yt([]),an([]),Sn.current&&(Sn.current.scrollTop=0)},[pt]);let[mt,ht]=(0,v.useState)(!1),[gt,_t]=(0,v.useState)(!1),[vt,yt]=(0,v.useState)([]),[bt,xt]=(0,v.useState)([]),[St,Ct]=(0,v.useState)(!1),[wt,Tt]=(0,v.useState)(null),[Et,Dt]=(0,v.useState)(null),Ot=wt===`project`,kt=e=>Tt(e?`project`:null),At=c.embedWorkspaceControls===`projects`?`projects`:c.embedWorkspaceControls===`root`?`root`:`none`,jt=(0,v.useRef)({}),Mt=(0,v.useRef)([]),[Nt,Pt]=(0,v.useState)(!1),Ft=(0,v.useRef)({readFile:oe,openNative:M});Ft.current={readFile:oe,openNative:M};let It=(0,v.useMemo)(()=>({serverUrl:e,fileIo:dt,onOpenFile:e=>{Pt(!1),Ft.current.readFile(e)},onOpenNative:e=>Ft.current.openNative(e)}),[e,dt]),[Lt,Rt]=(0,v.useState)(AV),zt=(0,v.useCallback)((e,t)=>{jV(e,t),Rt(n=>({...n,[e]:t}))},[]),[Bt,Vt]=(0,v.useState)(!1),[Ht,Ut]=(0,v.useState)(!0),[Wt,Gt]=(0,v.useState)(!1),Kt=c.terminal?.enabled??!1;(0,v.useEffect)(()=>{let e=e=>{Kt&&(e.ctrlKey||e.metaKey)&&e.key==="`"&&(e.preventDefault(),Gt(e=>!e))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[Kt]);let[qt,Jt]=(0,v.useState)(!1),[Yt,Xt]=(0,v.useState)(null),Zt=(0,v.useCallback)(()=>Xt(null),[]);function Qt(){let e=!Bt;Vt(e),e&&(Ut(!1),Jt(!1))}function $t(){let e=!Ht;Ut(e),e&&(Vt(!1),Jt(!1))}function en(){let e=!qt;Jt(e),e&&(Vt(!1),Ut(!1))}(0,v.useEffect)(()=>(lt(qt),()=>lt(!1)),[qt,lt,c.sessionId,pt]),(0,v.useEffect)(()=>{Jt(!1),Xt(null)},[pt]);let[tn,nn]=(0,v.useState)([]),[rn,an]=(0,v.useState)([]),on=(0,v.useRef)(0),sn=(0,v.useRef)(0),[cn,ln]=(0,v.useState)(0);async function un(e){let t=[...e],n=t.filter(UV).map(e=>({id:`${on.current++}`,name:e.name}));n.length>0&&an(e=>[...e,...n]),sn.current===0&&nn([]),sn.current++;try{let{attachments:e,errors:n}=await ZV(t,de);e.length>0&&yt(t=>[...t,...e]),n.length>0&&nn(e=>[...e,...n])}finally{if(sn.current--,n.length>0){let e=new Set(n.map(e=>e.id));an(t=>t.filter(t=>!e.has(t.id)))}}}(0,v.useEffect)(()=>{Mt.current=vt},[vt]);function dn(){_e()}let fn=(0,v.useMemo)(()=>[...vt.filter(e=>e.kind===`path`).map(e=>e.data),...bt],[vt,bt]);function pn(e){let t=Mt.current.findIndex(t=>t.kind===`path`&&t.data===e);t>=0?mn(t):bt.includes(e)||yt(t=>nH(t,e))}function mn(e){yt(t=>rH(t,e))}let hn=(0,v.useMemo)(()=>({btw:{region:`Side answer`,pinnedLines:1,anchor:e=>e.findLastIndex(e=>e.startsWith(`› `)),close:{label:`Close side answer`,run:()=>d(`/btw`)}}}),[d]);function gn(e,t){d(e,t),yt([]),nn([]),St||dn()}function _n(e){e.preventDefault(),ln(0),e.dataTransfer.files.length>0&&un(Array.from(e.dataTransfer.files))}let{theme:vn,preference:yn,toggle:bn,setTheme:xn}=E(c.branding.defaultTheme??`system`,c.branding.allowThemeToggle!==!1,s,n);(0,v.useImperativeHandle)(a,()=>({setTheme:xn}),[xn]);let Sn=(0,v.useRef)(null),[Cn,wn]=(0,v.useState)(null),Tn=(0,v.useCallback)(e=>{Sn.current=e,wn(e)},[]),En=(0,v.useRef)(null),Dn=(0,v.useRef)(!0),[On,kn]=(0,v.useState)(!0),An=(0,v.useCallback)(e=>{e!==Dn.current&&kn(e),Dn.current=e},[]),jn=(0,v.useCallback)(()=>{let e=Sn.current;e&&An(e.scrollHeight-e.scrollTop-e.clientHeight<W1)},[An]),Mn=(0,v.useRef)(null),Nn=(0,v.useCallback)(()=>{let e=Sn.current;e&&(e.scrollHeight-e.scrollTop-e.clientHeight<W1||(Mn.current=e.scrollTop))},[]),Pn=(0,v.useCallback)(()=>{let e=Sn.current;if(!e)return;let t=e.scrollHeight-e.scrollTop-e.clientHeight<W1,n=Mn.current;if(n!==null){if(e.scrollTop<n)Mn.current=null;else if(Mn.current=t?null:e.scrollTop,!t)return}An(t)},[An]);function Fn(){Mn.current=null}(0,v.useEffect)(()=>{let e=Cn;if(!e)return;let t=()=>{Mn.current=null,Pn()};e.addEventListener(`scrollend`,t);let n;return typeof ResizeObserver<`u`&&(n=new ResizeObserver(()=>{Dn.current?(Nn(),En.current?.scrollIntoView({behavior:`auto`})):Pn()}),n.observe(e),e.firstElementChild&&n.observe(e.firstElementChild)),()=>{e.removeEventListener(`scrollend`,t),n?.disconnect()}},[Cn,Pn,Nn]);let In=(0,v.useCallback)(()=>{An(!0),Nn();let e=window.matchMedia?.(`(prefers-reduced-motion: reduce)`).matches??!1;En.current?.scrollIntoView({behavior:e?`auto`:`smooth`})},[An,Nn]);(0,v.useEffect)(()=>{Dn.current?(Nn(),En.current?.scrollIntoView({behavior:`smooth`})):jn()},[c.items,jn,Nn]);let Ln=(0,v.useMemo)(()=>XB(c.items),[c.items]),Rn=(0,v.useMemo)(()=>Bt?oV(c.items):null,[Bt,c.items]),zn=(0,v.useMemo)(()=>tB({readFile:(e,t)=>{Pt(!1),oe(e,t)},fetchGitFileHistory:e=>De(e),fetchGitDiff:e=>{Pt(!0),oe(e)},searchFiles:e=>ve(e)}),[oe,De,ve]),Bn=(0,v.useCallback)(()=>zt(`tools`,!0),[zt]),Vn=(0,v.useCallback)(e=>{let t=Sn.current;if(t){let n=t.getBoundingClientRect(),r=e.getBoundingClientRect(),i=r.top>=n.top&&r.bottom<=n.bottom,a=t.scrollHeight-t.scrollTop-t.clientHeight<W1;if(i&&a)return}An(!1)},[An]),[Hn,Un]=(0,v.useState)(null),[Wn,Gn]=(0,v.useState)(null),Kn=(0,v.useMemo)(()=>{let e=c.sessions?.find(e=>e.id===c.sessionId);return c.sessionName?.trim()||e?.name?.trim()||e?.firstMessage?.trim()||c.sessionId},[c.sessionName,c.sessions,c.sessionId]),qn=(0,v.useCallback)(async()=>{Gn(null),Un(`preparing…`);try{let{exportConversation:t}=await ye(async()=>{let{exportConversation:e}=await import(`./conversationExport-CxC-uGG5.js`);return{exportConversation:e}},__vite__mapDeps([26,21,1,25]));await t({items:c.items,olderItems:c.olderHistory?.remaining??0,...c.olderHistory?{fetchOlderItems:ne}:{},connection:{serverUrl:e,token:l,workspace:ft},meta:{...c.workspace?{project:c.workspace.name}:{},session:Kn,model:c.model,exportedAt:new Date},onProgress:(e,t,n)=>Un(e===`collecting`?`reading ${t}/${n}…`:`writing ${t}/${n}…`)})}catch(e){Gn(e instanceof Error?e.message:`the conversation could not be exported`)}finally{Un(null)}},[c.items,c.olderHistory,c.workspace,c.model,Kn,ne,e,l,ft]),{jumpToItem:Jn,highlightIndex:Yn}=TV({items:c.items,scrollerRef:Sn,hideTools:!Lt.tools,onShowTools:Bn,onJump:Vn}),Xn=(0,v.useRef)(null),Zn=(0,v.useRef)(c.olderHistory?.have??0),Qn=(0,v.useCallback)(()=>{let e=Sn.current;e&&(Xn.current={height:e.scrollHeight,top:e.scrollTop}),k()},[k]);return(0,v.useLayoutEffect)(()=>{let e=c.olderHistory?.have??0,t=Zn.current;Zn.current=e;let n=Xn.current;if(Xn.current=null,!n||e<=t)return;let r=Sn.current;r&&(r.scrollTop=n.top+(r.scrollHeight-n.height))},[c.olderHistory?.have]),(0,v.useEffect)(()=>{if(!o){let e=c.extensionTitle??c.branding.title??`pi`;document.title=c.workspace?`${c.workspace.name} — ${e}`:e}c.branding.accentColor&&s.style.setProperty(`--accent`,c.branding.accentColor)},[c.branding,c.extensionTitle,c.workspace?.name,o,s]),o&&!c.brandingReady?null:c.authRequired?(0,N.jsx)(b.Provider,{value:vn,children:(0,N.jsx)(XG,{title:c.branding.title,onSubmit:u})}):c.credentials&&!c.credentials.usableModel?(0,N.jsx)(b.Provider,{value:vn,children:(0,N.jsx)(kG,{title:c.branding.title,credentials:c.credentials,onSetCredential:je,onStartLogin:Me,login:c.login,onAnswerLogin:Ne,onCancelLogin:Pe,onDismissLogin:Fe,onDeclareProvider:Le,errors:c.errors})}):(0,N.jsx)(b.Provider,{value:vn,children:(0,N.jsx)(kg.Provider,{value:c.replyConformance,children:(0,N.jsx)(ng.Provider,{value:c.structuredAppearance,children:(0,N.jsxs)(Pm.Provider,{value:It,children:[(0,N.jsxs)(`div`,{className:`relative flex h-full`,onDragEnter:e=>{e.dataTransfer.types.includes(`Files`)&&ln(e=>e+1)},onDragLeave:()=>ln(e=>Math.max(0,e-1)),onDragOver:e=>e.preventDefault(),onDrop:_n,children:[cn>0&&(0,N.jsx)(`div`,{className:`pointer-events-none absolute inset-0 z-40 flex items-center justify-center border-2 border-dashed bg-white/70 backdrop-blur-sm dark:bg-zinc-950/70`,style:{borderColor:`var(--accent, #3b82f6)`},children:(0,N.jsx)(`p`,{className:`text-lg font-medium text-zinc-700 dark:text-zinc-200`,children:`Drop files to attach (images, documents & text)`})}),(mt||gt)&&(0,N.jsx)(YG,{hidden:!mt,onUploadFile:de,onExternalDragEnter:()=>ln(0),tree:c.fileTree,openFile:c.openFile,writableRoot:c.writableRoot,gitFiles:c.gitStatus?.files,attachedPaths:fn,onExpand:ie,onSelectDirectory:Dt,onRefresh:ae,onSelectFile:e=>{Pt(!1),Dt(e),oe(e)},onSelectDiff:e=>{Pt(!0),Dt(e),oe(e)},onToggleAttachPath:pn,onCreateFile:e=>{Pt(!1),le(e)},onCreateDirectory:ue,onOpenNative:M,onRevealNative:pe,onRenameFile:me,onDeleteFile:he,onMoveFile:ge,onCopyFile:P,fileOperation:c.fileOperation,createError:c.createError,created:c.created,contentSearch:c.contentSearch,onSearchContent:se,onOpenSearchHit:(e,t)=>{Pt(!1),Dt(e.path),oe(e.path,void 0,e.kind===`line`?{query:t,line:e.line}:{query:t,page:e.page})}},JSON.stringify([pt,c.sandbox?.projectRoot??c.sandbox?.root])),(0,N.jsxs)(`div`,{className:`flex h-full min-w-0 flex-1 flex-col`,children:[Ot&&(0,N.jsx)(gW,{label:`Choose a project directory`,browse:c.serverBrowse,onBrowse:Ke,onSelect:e=>{kt(!1),qe(),Ye(e)},onCancel:()=>{kt(!1),qe()}}),!o&&c.outpostUpdate&&(0,N.jsx)(BB,{notice:c.outpostUpdate}),!o&&c.outpostChanges&&(0,N.jsx)(WB,{changes:c.outpostChanges}),(0,N.jsx)(mG,{workspace:c.workspace,workspaces:c.workspaces,workspaceLocked:c.workspaceLocked,workspaceControl:o?At:`projects`,rootControl:{sandbox:c.sandbox,browse:c.serverBrowse,applyState:c.settingsApply,blocked:wt!==null&&wt!==`root`,onBrowse:Ke,onCloseBrowser:()=>{Tt(null),qe()},onOpened:()=>Tt(`root`),onSelect:e=>Re({sandbox:{root:e,allowWrite:c.sandbox?.allowWrite??!1,allowBash:c.sandbox?.allowBash??!1,...c.sandbox?.writableRoot?{writableRoot:c.sandbox.writableRoot}:{}}})},onSwitchWorkspace:Je,onOpenProject:()=>{kt(!0),Ke(``)},onCloseProject:Xe,onOpenSideSession:Ze,piPackages:c.piPackages,piPackageUpdate:c.piPackageUpdate,canRestartServer:!o,serverRestarting:c.serverRestarting,onCheckPiPackages:Qe,onUpdatePiPackage:et,onRestartServer:tt,restartNeeded:c.restartNeeded,title:c.branding.title,credentials:c.credentials,login:c.login,onStartLogin:Me,onAnswerLogin:Ne,onCancelLogin:Pe,onDismissLogin:Fe,onLogoutProvider:Ie,sessions:c.sessions,sessionSearch:c.sessionSearch,sessionId:c.sessionId,tree:c.tree,isStreaming:c.isStreaming,connected:c.connected,theme:vn,showThemeToggle:c.branding.allowThemeToggle!==!1,statuses:c.statuses,sidebarOpen:mt,outcomeOpen:qt,filters:Lt,onToggleSidebar:()=>{_t(!0),ht(e=>!e)},onToggleOutcome:en,onFilterChange:zt,...c.items.length>0?{onExportConversation:()=>void qn()}:{},exportProgress:Hn,onToggleTheme:bn,themePreference:yn,onSetTheme:xn,onNewSession:g,onSwitchSession:_,onDeleteSession:y,onListSessions:x,onRenameSession:S,onSearchSessions:C,onClearSessionSearch:w,onListTree:T,onNavigateTree:D,onForkSession:O,gitAvailable:c.gitAvailable,gitStatus:c.gitStatus,gitSelectedPath:Et,gitLog:c.gitLog,extensionPaths:c.extensionPaths,configuredExtensionPaths:c.configuredExtensionPaths,userExtensionPaths:c.userExtensionPaths,extensionLock:c.extensionLock,tools:c.tools,commands:c.commands,sandbox:c.sandbox,gitUnavailable:c.gitUnavailable,userSkillPaths:c.userSkillPaths,serverBrowse:c.serverBrowse,settingsApply:c.settingsApply,agentResources:c.agentResources,agentResourceOperations:c.agentResourceOperations,versions:c.versions,onBrowseServerPath:Ke,onCloseServerBrowser:qe,settingsPickerBlocked:wt!==null&&wt!==`settings`,onSettingsPickerOpened:()=>Tt(`settings`),onRestartSession:nt,onUpdateConfig:Re,onSuggestAgentResourceClonePath:ze,onCloneAgentResourceRepository:Be,onEnrollAgentResourceRepository:Ve,onSetAgentResourceSkills:He,onRemoveAgentResourceRepository:Ue,onRefreshAgentResourceRepositories:We,onUpdateAgentResourceRepository:Ge,onFetchGitLog:Ce,onCloseGitLog:we,onShowCommit:Te,terminalOpen:Wt,onToggleTerminal:Kt?()=>Gt(e=>!e):void 0}),(0,N.jsxs)(`div`,{className:`relative z-0 flex min-h-0 flex-1 flex-col`,children:[c.workPlan&&(0,N.jsx)(eK,{plan:c.workPlan,open:Ht,onToggle:$t,onOpenWorkspace:e=>{Pt(!1),oe(e)},requestedTaskId:Yt,onTaskRequestHandled:Zt}),qt&&(0,N.jsx)(v1,{state:c.outcome,onClose:()=>Jt(!1),onRefresh:ut,onTarget:e=>{e.kind===`work-plan-task`?(Xt(e.taskId),Jt(!1),Vt(!1),Ut(!0)):e.kind===`workspace-file`?(Pt(!1),oe(e.path)):e.kind===`workspace-diff`&&(Pt(!0),oe(e.path))}}),c.openFile&&(0,N.jsx)(EU,{file:c.openFile,writableRoot:c.writableRoot,docxTemplate:c.docxTemplate,isStreaming:c.isStreaming,onDirtyChange:Ct,gitState:c.gitStatus?.files[c.openFile.path],initialShowGitDiff:Nt,gitDiff:c.gitDiff,gitBaseline:c.gitBaseline?.path===c.openFile.path?c.gitBaseline.text??null:null,onFetchGitDiff:xe,onClearGitDiff:Se,inRepository:NV(c.gitStatus?.repos??[],c.openFile.path)!==null,onOpenGitHistory:De,onClose:dn,onReload:oe,onSave:ce,serverUrl:e,token:l,workspace:ft,onOpenNative:M,rawRevision:c.previewRevision},c.openFile.path),c.gitFileHistory&&(0,N.jsx)(nW,{history:c.gitFileHistory,diff:c.gitFileDiff,dirty:c.gitStatus?.files[c.gitFileHistory.path]!==void 0,onFetchDiff:ke,onClearDiff:Ae,onClose:Oe}),c.gitShow&&(0,N.jsx)(kU,{show:c.gitShow,onClose:Ee}),Rn&&(0,N.jsx)(CV,{analysis:Rn,onJump:Jn,onClose:()=>Vt(!1)}),(0,N.jsx)(`main`,{ref:Tn,onScroll:Pn,onWheel:Fn,onTouchStart:Fn,onKeyDown:Fn,className:`flex-1 overflow-y-auto transition-opacity duration-150 ${c.switching?`opacity-40`:`opacity-100`} ${Bt?`md:pr-[26rem]`:c.workPlan&&Ht?`md:pr-[23rem]`:``}`,children:(0,N.jsxs)(`div`,{className:`mx-auto flex max-w-3xl flex-col gap-3 px-4 py-6`,children:[c.items.length===0&&(0,N.jsxs)(`div`,{className:`mt-24 text-center text-zinc-500 dark:text-zinc-600`,children:[(0,N.jsx)(`div`,{className:`mb-2 text-4xl`,children:c.branding.title??`π`}),c.agentStarting?(0,N.jsx)(`p`,{className:`text-sm`,role:`status`,"data-testid":`agent-starting`,children:`Starting the agent… The project's files are ready.`}):(0,N.jsx)(`p`,{className:`text-sm`,children:c.branding.welcome??`Send a message to start the agent.`})]}),c.olderHistory&&(0,N.jsx)(JB,{older:c.olderHistory,onLoad:Qn}),c.items.map((t,n)=>{let r=`${c.sessionId}:${n}`,i=(e,t=r)=>(0,N.jsx)(`div`,{"data-item-index":n,className:`flex flex-col gap-3 rounded-lg transition-shadow ${Yn===n?`ring-2 ring-blue-400 dark:ring-blue-500`:``}`,children:e},t);return t.kind===`user`?i((0,N.jsx)($e,{item:t,canEdit:!t.readOnly&&!c.isStreaming&&c.connected,onEdit:ee})):t.kind===`compaction`?i((0,N.jsx)(qB,{item:t})):t.kind===`tool`?Lt.tools?i((0,N.jsx)(IB,{item:t,dispatch:zn}),t.toolCallId?`${c.sessionId}:${t.toolCallId}`:r):null:t.kind===`custom`?i((0,N.jsx)(LB,{item:t})):(Lt.reasoning?t.blocks:t.blocks.filter(e=>e.type!==`thinking`)).length===0&&!t.errorMessage?(0,N.jsx)(`div`,{"data-item-index":n,className:`sr-only`,"aria-hidden":!0},r):i((0,N.jsx)(Qz,{item:t,hideReasoning:!Lt.reasoning,serverUrl:e,token:l,workspace:ft,onOpenFile:e=>{Pt(!1),oe(e)}}))}),c.pendingPrompt&&(0,N.jsxs)(`div`,{className:`flex flex-col gap-3 opacity-60`,"data-pending-prompt":!0,children:[(0,N.jsx)($e,{item:{kind:`user`,...c.pendingPrompt},canEdit:!1,onEdit:()=>{}}),c.extensionsBinding?(0,N.jsxs)(`div`,{className:`flex items-center gap-3`,"data-testid":`prompt-waiting-for-extensions`,children:[(0,N.jsx)(G1,{label:`waiting for extensions to start…`}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>p(!jt.current[pt??``]),className:`text-xs text-zinc-500 underline hover:text-zinc-700 dark:hover:text-zinc-300`,children:`cancel`})]}):(0,N.jsx)(G1,{label:`sending…`})]}),c.isStreaming&&!c.pendingPrompt&&(0,N.jsx)(G1,{label:`working…`}),(c.queue.steering.length>0||c.queue.followUp.length>0)&&(0,N.jsxs)(`div`,{className:`rounded-lg border border-dashed border-zinc-300 px-3 py-2 text-xs text-zinc-500 dark:border-zinc-700`,children:[c.queue.steering.map((e,t)=>(0,N.jsxs)(`div`,{children:[`⏩ steering: `,e]},`s${t}`)),c.queue.followUp.map((e,t)=>(0,N.jsxs)(`div`,{children:[`⏭ follow-up: `,e]},`f${t}`))]}),tn.map((e,t)=>(0,N.jsx)(`div`,{className:`rounded-lg border border-amber-300 bg-amber-50 px-3 py-2 text-sm text-amber-700 dark:border-amber-900/60 dark:bg-amber-950/30 dark:text-amber-300`,children:e},`att${t}`)),Wn&&(0,N.jsx)(`div`,{className:`rounded-lg border border-red-300 bg-red-50 px-3 py-2 text-sm text-red-700 dark:border-red-900/60 dark:bg-red-950/30 dark:text-red-300`,children:Wn}),c.errors.map((e,t)=>(0,N.jsx)(`div`,{className:`rounded-lg border border-red-300 bg-red-50 px-3 py-2 text-sm text-red-700 dark:border-red-900/60 dark:bg-red-950/30 dark:text-red-300`,children:e},t)),(0,N.jsx)(`div`,{ref:En})]})}),(0,N.jsx)(`div`,{className:`pointer-events-none absolute inset-x-0 bottom-4 z-0 flex justify-center ${Bt||qt?`md:pr-[26rem]`:c.workPlan&&Ht?`md:pr-[23rem]`:``}`,children:!On&&(0,N.jsxs)(`button`,{type:`button`,onClick:In,"aria-label":`Scroll to the latest message`,className:`pointer-events-auto flex items-center gap-1.5 rounded-full border border-zinc-300 bg-white/95 px-3 py-1.5 text-xs text-zinc-600 shadow-lg backdrop-blur transition-colors hover:bg-zinc-50 motion-reduce:transition-none dark:border-zinc-700 dark:bg-zinc-900/95 dark:text-zinc-300 dark:hover:bg-zinc-800`,children:[(0,N.jsx)(`span`,{"aria-hidden":!0,children:`↓`}),`Latest`]})})]}),Kt&&(0,N.jsx)(m1,{open:Wt,onClose:()=>Gt(!1),cwd:c.workspace?.root,confinedRoot:c.terminal?.confined?c.sandbox?.root??c.workspace?.root:void 0,confinement:c.confinement?.terminal,unavailable:c.terminal?.unavailable,onSetWorkspaceRoot:e=>{Ye&&!o?Ye(e):c.sandbox?Re({sandbox:{root:e,allowWrite:c.sandbox.allowWrite,allowBash:c.sandbox.allowBash,...c.sandbox.writableRoot?{writableRoot:c.sandbox.writableRoot}:{}}}):Re({sandbox:{root:e,allowWrite:!0,allowBash:!0}})},shells:c.terminal?.shells,openTerminal:rt,sendTerminalInput:it,getTerminalCwd:at,resizeTerminal:ot,closeTerminal:st,subscribeTerminal:ct}),(0,N.jsx)(`footer`,{className:`border-t border-zinc-200 px-4 py-3 dark:border-zinc-800`,children:(0,N.jsxs)(`div`,{className:`mx-auto max-w-3xl`,children:[(0,N.jsx)(LH,{widgets:c.widgets,placement:`aboveEditor`,controls:hn}),(0,N.jsx)(dH,{initialDraft:jt.current[pt??``]??``,onDraftChange:e=>{jt.current[pt??``]=e},isStreaming:c.isStreaming,connected:c.connected,commands:c.commands,fileSearch:c.fileSearch,prefill:c.editorPrefill,attachments:vt,pendingUploads:rn,onAttach:e=>void un(e),onMentionPaths:xt,onRemoveAttachment:mn,onSend:gn,onAbort:f,onSearchFiles:ve,onClearFileSearch:be},pt??``),(0,N.jsx)(LH,{widgets:c.widgets,placement:`belowEditor`}),(0,N.jsx)(EG,{model:c.model,models:c.models,thinkingLevel:c.thinkingLevel,thinkingLevels:c.thinkingLevels,modelSupportsReasoning:c.modelSupportsReasoning,isStreaming:c.isStreaming,contextUsage:c.contextUsage,shellConfinement:c.confinement?.bash,shellGrants:c.sandboxGrants?.active,sessionUsage:Ln,analysisOpen:Bt,onToggleAnalysis:Qt,isCompacting:c.isCompacting,onSetModel:m,onSetThinking:h,onCompact:te})]})})]})]}),c.dialogQueue[0]&&(0,N.jsx)(xH,{request:c.dialogQueue[0],onRespond:A}),!c.dialogQueue[0]&&c.sandboxGrants?.pending[0]&&(0,N.jsx)(TH,{request:c.sandboxGrants.pending[0],onRespond:re}),(0,N.jsx)(kH,{notifications:c.notifications,onDismiss:j})]})})})})});(0,y.createRoot)(document.getElementById(`root`)).render((0,N.jsx)(v.StrictMode,{children:(0,N.jsx)(K1,{})}));export{oe as A,Pg as C,pe as D,ye as E,d as M,ae as O,Bg as S,Be as T,gx as _,Cz as a,S_ as b,lI as c,ij as d,WA as f,PS as g,cC as h,Kz as i,re as j,de as k,WF as l,Cw as m,dU as n,dz as o,VA as p,pU as r,uI as s,T1 as t,vj as u,w_ as v,oh as w,v_ as x,x_ as y};
1537
+ `);e.socket=s,s.send(JSON.stringify(e.message))}}if(t.type===`terminal_data`){let e=w.current.get(t.terminalId);if(e)for(let n of e.onData)n(t.data)}else if(t.type===`terminal_cwd`){let e=T.current.get(t.terminalId);e&&(e.message.cwd=t.cwd);let n=w.current.get(t.terminalId);if(n)for(let e of n.onCwd)e(t.cwd)}else if(t.type===`terminal_exit`){T.current.delete(t.terminalId);let e=w.current.get(t.terminalId);if(e)for(let n of e.onExit)n(t.exitCode)}else if(t.type===`terminal_error`){T.current.delete(t.terminalId);let e=w.current.get(t.terminalId);if(e)for(let n of e.onError)n(t.message)}else if(t.type===`history_items`){let e=_.current.get(t.requestId);e&&(_.current.delete(t.requestId),e.resolve({items:t.items,remaining:t.remaining}))}else if(t.type===`history_unavailable`){let e=_.current.get(t.requestId);e&&(_.current.delete(t.requestId),e.reject(new T1(t.reason,t.kind)))}else if((t.type===`file_content`||t.type===`file_written`||t.type===`arrangement_saved`||t.type===`file_browser_error`)&&h.current.has(t.requestId)){let e=h.current.get(t.requestId);h.current.delete(t.requestId),t.type===`file_browser_error`?e.reject(new wz(t.message,t.reason)):t.type===`file_content`?e.resolve({content:t.content,mtimeMs:t.mtimeMs}):t.type===`arrangement_saved`?e.resolve({path:t.path}):e.resolve({mtimeMs:t.mtimeMs})}else if(t.type===`file_search_results`&&h.current.has(t.requestId)){let e=h.current.get(t.requestId);h.current.delete(t.requestId),e.resolve({results:t.results})}else{if(t.type===`hello`||t.type===`workspace_switched`||t.type===`workspace_starting`||t.type===`session_replaced`||t.type===`update_config_ack`){let e={key:t.workspace?GB(t.workspace):null,root:t.sandbox?.projectRoot??t.sandbox?.root,writableRoot:t.writableRoot},n=D.current;(t.type===`hello`||n.key!==e.key||n.root!==e.root||n.writableRoot!==e.writableRoot)&&O.current++,D.current=e,S.current=t.writableRoot}if(t.type===`file_uploaded`){let e=m.current.get(t.requestId);e&&(m.current.delete(t.requestId),e.resolve(t.path))}else if(t.type===`file_browser_error`&&m.current.has(t.requestId)){let e=m.current.get(t.requestId);m.current.delete(t.requestId),e.reject(new zV(t.message,t.reason))}else if(t.type===`file_changed`){ce();for(let e of g.current.get(t.path)??[])e();ve(D1(t.path));let e=f.current;if(e?.status===`loaded`&&e.path===t.path){let e=`file:${b1()}`;a({type:`file_read_started`,path:t.path,requestId:e,preserveContent:!0}),k({type:`read_file`,path:t.path,requestId:e})}p.current===t.path&&k({type:`git_diff`,path:t.path,requestId:`gitdiff:${b1()}`}),P(NV(N.current,t.path)?.repo)}else if(t.type===`directory_changed`){ce();for(let[e,n]of g.current)if(D1(e)===t.path)for(let e of n)e();ve(t.path);let e=f.current;if(e!==null&&D1(e.path)===t.path){if(se(e.path)||le(e.path))a({type:`raw_preview_changed`,path:e.path});else if(e.status===`loaded`){let t=`file:${b1()}`;a({type:`file_read_started`,path:e.path,requestId:t,preserveContent:!0}),k({type:`read_file`,path:e.path,requestId:t})}}let n=p.current;n!==null&&D1(n)===t.path&&k({type:`git_diff`,path:n,requestId:`gitdiff:${b1()}`}),P()}else{if((t.type===`hello`||t.type===`session_replaced`||t.type===`workspace_switched`||t.type===`workspace_starting`)&&(fe.current=t.gitAvailable===!0,t.type!==`session_replaced`&&P()),t.type===`agent_end`&&(P(),ce()),t.type===`git_repositories_changed`&&(ce(),fe.current=t.available,t.available&&P()),t.type===`git_changed`){ce(),P(t.repo===``?void 0:t.repo);let e=M.current;e!==null&&e.repo===t.repo&&pe(e.repo,e.limit)}if((t.type===`git_status`||t.type===`git_error`&&t.requestId.startsWith(`git:`))&&_e(t.requestId),t.type===`work_plan_changed`&&ce(),(t.type===`workspace_outcome`||t.type===`workspace_outcome_error`)&&A.current===t.requestId&&(ae(),re.current&&(re.current=!1,queueMicrotask(()=>ie.current()))),t.type===`hello`||t.type===`session_replaced`||t.type===`workspace_switched`||t.type===`workspace_starting`||t.type===`update_config_ack`){ae(),re.current=!1;let e=te.current,n=t.sessionId===e.sessionId,r=(t.workspace?GB(t.workspace):null)===e.workspaceRoot;ne.current&&n&&r&&queueMicrotask(()=>ie.current())}if(t.type===`file_operation_result`){let e=t.previousPath??t.path,n=f.current;t.operation===`delete_file`&&n?.path===t.path?f.current=null:n?.path===e&&(f.current={...n,path:t.path})}a({type:`server`,message:t}),t.type===`session_replaced`&&de(``)}}},s.onclose=e=>{if(o.current===s){O.current++,me.current.clear(),he.current.clear(),ge.current.clear(),ae(),re.current=!1;for(let e of m.current.values())e.reject(new zV(`The connection dropped before the upload finished`));m.current.clear();for(let e of h.current.values())e.reject(new wz(`The connection dropped before the server answered`));h.current.clear();for(let e of _.current.values())e.reject(new T1(`the connection dropped before the older messages arrived`,`failed`));_.current.clear(),e.code===H1?a({type:`auth_required`}):(a({type:`disconnected`}),n||(t=window.setTimeout(i,1500)))}}}return i(),()=>{n=!0,t!==void 0&&clearTimeout(t);let e=o.current;o.current=null,e?.close()}},[k,e,P,_e,ve,de,ce,ae,s,r,pe]);let Ce=(0,v.useCallback)((e,t)=>{let n=o.current;if(!n||n.readyState!==WebSocket.OPEN)return Promise.reject(new T1(`not connected to the server`,`failed`));let r=`history:${b1()}`;return new Promise((n,i)=>{let a=window.setTimeout(()=>{_.current.delete(r)&&i(new T1(`the older messages did not arrive`,`failed`))},B1),o=e=>t=>{clearTimeout(a),e(t)};_.current.set(r,{resolve:o(n),reject:o(i)}),k({type:`history_before`,sessionId:y.current,have:e,count:t,requestId:r})})},[k]),we=(0,v.useCallback)(async()=>{let e=x.current;if(!(!e||e.loading||b.current||e.remaining<=0)){b.current=!0,a({type:`history_load_started`});try{let t=await Ce(e.have,50);a({type:`history_loaded`,items:t.items,remaining:t.remaining})}catch(e){if(e instanceof T1&&e.kind===`stale`){a({type:`history_load_failed`,message:``});return}a({type:`history_load_failed`,message:e instanceof Error?e.message:`the older messages could not be loaded`})}finally{b.current=!1}}},[Ce]);return{state:i,fileIo:(0,v.useMemo)(()=>{function e(e,t){let n=o.current;if(!n||n.readyState!==WebSocket.OPEN)return Promise.reject(new wz(`not connected to the server`));let r=`${e}:${b1()}`;return new Promise((e,n)=>{let i=window.setTimeout(()=>{h.current.delete(r)&&n(new wz(`the server did not answer`))},z1);h.current.set(r,{resolve:t=>{clearTimeout(i),e(t)},reject:e=>{clearTimeout(i),n(e)}}),k(t(r))})}return{read:t=>e(`fileio-read`,e=>({type:`read_file`,path:t,requestId:e})),write:(t,n,r)=>e(`fileio-write`,e=>({type:`write_file`,path:t,content:n,expectedMtimeMs:r,requestId:e})),find:async t=>(await e(`fileio-find`,e=>({type:`search_files`,query:t,requestId:e}))).results,keepArrangement:async(t,n)=>(await e(`fileio-arrangement`,e=>({type:`save_arrangement`,documentPath:t,content:n,requestId:e}))).path,onChanged:(e,t)=>{let n=g.current.get(e)??new Set;return n.add(t),g.current.set(e,n),()=>{n.delete(t),n.size===0&&g.current.delete(e)}}}},[k]),setOutcomeActive:ue,refreshOutcome:oe,authToken:l.current,switchWorkspace:(e,t)=>{((t??e)!==E||i.switching)&&(a({type:`workspace_switching`}),k({type:`switch_workspace`,root:e,...t!==void 0&&t!==e?{id:t}:{}}))},openProject:e=>{a({type:`workspace_switching`}),k({type:`open_project`,root:e})},closeProject:(e,t)=>k({type:`close_project`,root:e,...t!==void 0&&t!==e?{id:t}:{}}),checkPiPackages:()=>k({type:`check_pi_packages`}),updatePiPackage:e=>{let t=`pkg:${b1()}`;a({type:`pi_package_update_started`,requestId:t,source:e}),k({type:`update_pi_package`,source:e,requestId:t})},restartServer:()=>k({type:`restart_server`}),restartSession:()=>{a({type:`settings_apply_started`}),k({type:`restart_session`})},openSideSession:e=>{a({type:`workspace_switching`}),k({type:`open_side_session`,root:e})},submitToken:e=>{w1(e),l.current=e,a({type:`auth_retrying`}),c(e=>e+1)},prompt:(e,t)=>{a({type:`prompt_sent`,text:e,...t?.length?{images:t}:{}}),k({type:`prompt`,text:e,...t?.length?{images:t}:{}})},abort:()=>k({type:`abort`}),cancelPendingPrompt:e=>{a({type:`pending_prompt_cancelled`,restoreText:e}),k({type:`abort`})},setModel:(e,t)=>k({type:`set_model`,provider:e,id:t}),setThinking:e=>k({type:`set_thinking`,level:e}),newSession:()=>k({type:`new_session`}),switchSession:e=>k({type:`switch_session`,path:e}),deleteSession:e=>k({type:`delete_session`,path:e}),listSessions:()=>k({type:`list_sessions`}),renameSession:(e,t)=>k({type:`rename_session`,path:e,name:t}),searchSessions:e=>{let t=`sessions:${b1()}`;a({type:`session_search_started`,query:e,requestId:t}),k({type:`search_sessions`,query:e,requestId:t})},clearSessionSearch:()=>a({type:`session_search_cleared`}),listTree:()=>k({type:`list_tree`}),navigateTree:e=>k({type:`navigate_tree`,entryId:e}),forkSession:e=>k({type:`fork_session`,entryId:e}),prefillComposer:(e,t)=>a({type:`composer_prefilled`,text:e,...t?{notice:t}:{}}),editQueuedPrompt:(e,t)=>k({type:`edit_queued_prompt`,id:e,text:t}),removeQueuedPrompt:e=>k({type:`remove_queued_prompt`,id:e}),sendQueueNow:()=>k({type:`send_queue_now`}),editPrompt:(e,t,n)=>k({type:`edit_prompt`,entryId:e,text:t,...n?.length?{images:n}:{}}),compact:()=>k({type:`compact`}),fetchOlderItems:Ce,loadOlderItems:we,respondToDialog:e=>{k({type:`extension_ui_response`,...e}),a({type:`dialog_answered`})},respondToGrant:(e,t)=>k({type:`sandbox_grant_response`,id:e,decision:t}),dismissNotification:e=>a({type:`dismiss_notification`,id:e}),listDirectory:e=>de(e),refreshFileTree:ye,readFile:(e,t,n)=>{let r=`file:${b1()}`;a({type:`file_read_started`,path:e,requestId:r,...n?{reveal:n}:{}}),k({type:`read_file`,path:e,requestId:r,...t===void 0?{}:{sha256:t}})},closeFilePreview:()=>a({type:`close_file_preview`}),writeFile:(e,t,n,r=!1)=>{let i=`write:${b1()}`;a({type:`file_save_started`,path:e,requestId:i,content:t}),k({type:`write_file`,path:e,content:t,expectedMtimeMs:n,...r?{force:r}:{},requestId:i})},createFile:e=>{a({type:`file_create_started`}),k({type:`create_file`,path:e,requestId:`create:${b1()}`})},uploadFile:(e,t,n)=>{if(n!==void 0&&(i.switching||ee!==O.current))return Promise.reject(new BV);let r=S.current;if(r===null)return Promise.reject(new zV(`the workspace is read-only`,`denied`));let a=o.current;if(!a||a.readyState!==WebSocket.OPEN)return Promise.reject(new zV(`not connected to the server`));let s=n??(r?`${r}/uploads`:`uploads`),c=`upload:${b1()}`;return new Promise((r,i)=>{let a=window.setTimeout(()=>{m.current.delete(c)&&i(new zV(`the upload timed out`))},R1),o=e=>t=>{clearTimeout(a),e(t)};m.current.set(c,{resolve:o(e=>{if(n!==void 0){if(ee!==O.current){i(new BV);return}de(n,!0)}r(e)}),reject:o(i)}),k({type:`upload_file`,destinationDirectory:s,name:e,contentBase64:t,requestId:c,...n===void 0?{}:{existingDirectory:!0,workspaceId:E??void 0}})})},createDirectory:e=>{a({type:`file_create_started`}),k({type:`create_directory`,path:e,requestId:`create:${b1()}`})},openNative:e=>{let t=`fileop:${b1()}`;a({type:`file_operation_started`,operation:`open_native`,path:e,requestId:t}),k({type:`open_native`,path:e,requestId:t})},revealNative:e=>{let t=Date.now();if(u.current?.path===e&&t-u.current.at<U1)return;u.current={path:e,at:t};let n=`fileop:${b1()}`;a({type:`file_operation_started`,operation:`reveal_native`,path:e,requestId:n}),k({type:`reveal_native`,path:e,requestId:n})},renameFile:(e,t)=>{let n=`fileop:${b1()}`;a({type:`file_operation_started`,operation:`rename_file`,path:e,requestId:n}),k({type:`rename_file`,path:e,name:t,requestId:n})},deleteFile:e=>{let t=`fileop:${b1()}`;a({type:`file_operation_started`,operation:`delete_file`,path:e,requestId:t}),k({type:`delete_file`,path:e,requestId:t})},moveFile:(e,t)=>{let n=`fileop:${b1()}`;a({type:`file_operation_started`,operation:`move_file`,path:e,requestId:n}),k({type:`move_file`,path:e,destinationDirectory:t,requestId:n})},copyFile:(e,t)=>{let n=`fileop:${b1()}`;a({type:`file_operation_started`,operation:`copy_file`,path:e,requestId:n}),k({type:`copy_file`,path:e,destinationDirectory:t,requestId:n})},searchFiles:e=>{let t=`search:${b1()}`;a({type:`file_search_started`,query:e,requestId:t}),k({type:`search_files`,query:e,requestId:t})},clearFileSearch:()=>a({type:`file_search_cleared`}),searchContent:e=>{if(e.trim()===``){a({type:`content_search_cleared`});return}let t=`content:${b1()}`;a({type:`content_search_started`,query:e,requestId:t}),k({type:`search_content`,query:e,requestId:t})},clearContentSearch:()=>a({type:`content_search_cleared`}),fetchGitStatus:()=>P(),fetchGitDiff:e=>{let t=`gitdiff:${b1()}`;a({type:`git_diff_started`,path:e,requestId:t}),k({type:`git_diff`,path:e,requestId:t})},clearGitDiff:()=>a({type:`git_diff_cleared`}),fetchGitLog:(e,t)=>{M.current={repo:e,limit:t},pe(e,t)},closeGitLog:()=>{M.current=null,a({type:`git_log_closed`})},fetchGitShow:(e,t)=>k({type:`git_show`,repo:e,sha:t,requestId:`gitshow:${b1()}`}),clearGitShow:()=>a({type:`git_show_cleared`}),fetchGitFileHistory:(e,t)=>{let n=`gitfilelog:${b1()}`;a({type:`git_file_history_started`,path:e,requestId:n}),k({type:`git_file_log`,path:e,...t?{limit:t}:{},requestId:n})},closeGitFileHistory:()=>a({type:`git_file_history_closed`}),fetchGitFileDiff:(e,t)=>{let n=`gitfilediff:${b1()}`;a({type:`git_file_diff_started`,base:e,target:t,requestId:n}),k({type:`git_file_diff`,base:e,target:t,requestId:n})},clearGitFileDiff:()=>a({type:`git_file_diff_cleared`}),setCredential:(e,t)=>k({type:`set_credential`,provider:e,apiKey:t}),startLogin:(e,t)=>{let n=b1();a({type:`login_started`,flowId:n,provider:e,method:t}),k({type:`start_login`,flowId:n,provider:e,method:t})},answerLogin:e=>{let t=i.login;t?.prompt&&(k({type:`login_answer`,flowId:t.flowId,promptId:t.prompt.promptId,value:e}),a({type:`login_answered`}))},cancelLogin:()=>{let e=i.login;e&&!e.done&&k({type:`cancel_login`,flowId:e.flowId})},dismissLogin:()=>a({type:`login_dismissed`}),logoutProvider:e=>k({type:`logout_provider`,provider:e}),declareProvider:e=>k({type:`declare_provider`,...e}),browseServerDirectory:e=>{let t=`serverdir:${b1()}`;a({type:`server_browse_started`,path:e,requestId:t}),k({type:`browse_server_directory`,path:e,requestId:t})},closeServerBrowser:()=>a({type:`server_browse_closed`}),suggestAgentResourceClonePath:e=>{let t=`resource-clone-path:${b1()}`;a({type:`resource_clone_path_started`,requestId:t}),k({type:`suggest_agent_resource_clone_path`,repositoryUrl:e,requestId:t})},cloneAgentResourceRepository:(e,t)=>{let n=`resource-preview:${b1()}`;a({type:`resource_preview_started`,requestId:n}),k({type:`clone_agent_resource_repository`,repositoryUrl:e,destinationPath:t,requestId:n})},enrollAgentResourceRepository:(e,t,n,r)=>{let i=`resource-enroll:${b1()}`;a({type:`resource_enrollment_started`,requestId:i}),k({type:`enroll_agent_resource_repository`,previewToken:e,skillRoots:t,extensionRoots:n,...r?{enabledSkills:r}:{},requestId:i})},setAgentResourceSkills:(e,t)=>{let n=`resource-skills:${b1()}`;a({type:`resource_skills_started`,requestId:n,repositoryId:e}),k({type:`set_agent_resource_skills`,repositoryId:e,enabledSkills:t,requestId:n})},removeAgentResourceRepository:e=>{let t=`resource-remove:${b1()}`;a({type:`resource_removal_started`,requestId:t,repositoryId:e}),k({type:`remove_agent_resource_repository`,repositoryId:e,requestId:t})},refreshAgentResourceRepositories:e=>{let t=`resource-refresh:${b1()}`;a({type:`resource_refresh_started`,requestId:t,...e?{repositoryId:e}:{}}),k({type:`refresh_agent_resource_repositories`,...e?{repositoryId:e}:{},requestId:t})},updateAgentResourceRepository:(e,t,n,r,i=!1)=>{let o=`resource-update:${b1()}`;a({type:`resource_update_started`,requestId:o,repositoryId:e}),k({type:`update_agent_resource_repository`,repositoryId:e,assessmentToken:t,localRevision:n,upstreamRevision:r,...i?{allowExecutableChanges:!0}:{},requestId:o})},updateConfig:e=>{a({type:`settings_apply_started`}),k({type:`update_config`,...e})},openTerminal:(e,t,n,r,i)=>{let a={type:`terminal_open`,terminalId:e,cwd:t,cols:n,rows:r,...i?{shellId:i}:{}};T.current.set(e,{message:a,socket:o.current?.readyState===WebSocket.OPEN?o.current:null}),k(a)},sendTerminalInput:(e,t)=>k({type:`terminal_input`,terminalId:e,data:t}),getTerminalCwd:e=>k({type:`terminal_get_cwd`,terminalId:e}),resizeTerminal:(e,t,n)=>{let r=T.current.get(e);r&&Object.assign(r.message,{cols:t,rows:n}),k({type:`terminal_resize`,terminalId:e,cols:t,rows:n})},closeTerminal:e=>{T.current.delete(e),k({type:`terminal_close`,terminalId:e}),w.current.delete(e)},subscribeTerminal:(e,t)=>{let n=w.current.get(e);return n||(n={onData:new Set,onCwd:new Set,onExit:new Set,onError:new Set},w.current.set(e,n)),t.onData&&n.onData.add(t.onData),t.onCwd&&n.onCwd.add(t.onCwd),t.onExit&&n.onExit.add(t.onExit),t.onError&&n.onError.add(t.onError),()=>{t.onData&&n?.onData.delete(t.onData),t.onCwd&&n?.onCwd.delete(t.onCwd),t.onExit&&n?.onExit.delete(t.onExit),t.onError&&n?.onError.delete(t.onError)}}}}var G1=120;function K1({label:e}){return(0,N.jsx)(`div`,{className:`flex justify-end px-4`,role:`status`,"aria-live":`polite`,children:(0,N.jsxs)(`div`,{className:`flex items-center gap-2 py-1`,children:[(0,N.jsx)(`span`,{className:`inline-block h-4 w-4 animate-spin rounded-full border-[3px] border-zinc-300 border-t-blue-500 dark:border-zinc-600 dark:border-t-blue-400 motion-reduce:animate-pulse`}),(0,N.jsx)(`span`,{className:`text-xs text-zinc-400 dark:text-zinc-500`,children:e})]})})}var q1=(0,v.forwardRef)(function({serverUrl:e=``,rootElement:t,initialTheme:n,token:r,workspace:i},a){let o=t!==void 0,s=t??document.documentElement,{state:c,authToken:l,submitToken:u,prompt:d,abort:f,cancelPendingPrompt:p,setModel:m,setThinking:h,newSession:g,switchSession:_,deleteSession:y,listSessions:x,renameSession:S,searchSessions:C,clearSessionSearch:w,listTree:T,navigateTree:D,forkSession:O,editPrompt:ee,editQueuedPrompt:te,removeQueuedPrompt:k,sendQueueNow:ne,prefillComposer:A,compact:re,loadOlderItems:j,fetchOlderItems:ie,respondToDialog:ae,respondToGrant:oe,dismissNotification:se,listDirectory:ce,refreshFileTree:le,readFile:ue,searchContent:de,writeFile:M,createFile:pe,createDirectory:me,uploadFile:he,openNative:ge,revealNative:P,renameFile:_e,deleteFile:ve,moveFile:be,copyFile:xe,closeFilePreview:Se,searchFiles:Ce,clearFileSearch:we,fetchGitDiff:Te,clearGitDiff:Ee,fetchGitLog:De,closeGitLog:Oe,fetchGitShow:ke,clearGitShow:Ae,fetchGitFileHistory:je,closeGitFileHistory:Me,fetchGitFileDiff:Ne,clearGitFileDiff:Pe,setCredential:Fe,startLogin:Ie,answerLogin:Le,cancelLogin:Re,dismissLogin:ze,logoutProvider:Be,declareProvider:Ve,updateConfig:He,suggestAgentResourceClonePath:Ue,cloneAgentResourceRepository:We,enrollAgentResourceRepository:Ge,setAgentResourceSkills:Ke,removeAgentResourceRepository:qe,refreshAgentResourceRepositories:Je,updateAgentResourceRepository:Ye,browseServerDirectory:Xe,closeServerBrowser:Ze,switchWorkspace:Qe,openProject:et,closeProject:tt,openSideSession:nt,checkPiPackages:rt,updatePiPackage:it,restartServer:at,restartSession:ot,openTerminal:st,sendTerminalInput:ct,getTerminalCwd:lt,resizeTerminal:ut,closeTerminal:dt,subscribeTerminal:ft,setOutcomeActive:pt,refreshOutcome:mt,fileIo:ht}=W1(e,r,o,i),gt=fe(c.workspace);gG(c.workspaces,c.workspace?GB(c.workspace):null);let _t=c.workspace?GB(c.workspace):null;(0,v.useEffect)(()=>{Ct([]),pn([]),An.current&&(An.current.scrollTop=0)},[_t]);let[vt,yt]=(0,v.useState)(!1),[bt,xt]=(0,v.useState)(!1),[St,Ct]=(0,v.useState)([]),[wt,Tt]=(0,v.useState)([]),[Et,Dt]=(0,v.useState)(!1),[Ot,kt]=(0,v.useState)(null),[At,jt]=(0,v.useState)(null),Mt=Ot===`project`,Nt=e=>kt(e?`project`:null),Pt=c.embedWorkspaceControls===`projects`?`projects`:c.embedWorkspaceControls===`root`?`root`:`none`,Ft=(0,v.useRef)({}),It=(e,t)=>{let n=Ft.current[_t??``]?.trim(),r=n?`${n}\n\n${e}`:e;t?A(r,t):A(r)},Lt=c.queuedEditRefused;(0,v.useEffect)(()=>{Lt&&It(Lt.text)},[Lt?.nonce]);let Rt=(0,v.useRef)({key:null,drafts:new Map});(0,v.useEffect)(()=>{let e=Rt.current;if(e.key!==_t){Rt.current={key:_t,drafts:new Map};return}let t=new Set(c.queue.map(e=>e.id));for(let[n,{original:r,draft:i}]of e.drafts)t.has(n)||(e.drafts.delete(n),i.trim()&&i.trim()!==r&&It(i.trim(),`The agent read that message before your edit was saved — your edit is in the composer`))},[c.queue,_t]);let zt=(e,t)=>n=>{Rt.current.key!==_t&&(Rt.current={key:_t,drafts:new Map}),n===null?Rt.current.drafts.delete(e):Rt.current.drafts.set(e,{original:t,draft:n})},Bt=(0,v.useRef)([]),[Vt,Ht]=(0,v.useState)(!1),Ut=(0,v.useRef)({readFile:ue,openNative:ge});Ut.current={readFile:ue,openNative:ge};let Wt=(0,v.useMemo)(()=>({serverUrl:e,fileIo:ht,onOpenFile:e=>{Ht(!1),Ut.current.readFile(e)},onOpenNative:e=>Ut.current.openNative(e)}),[e,ht]),[Gt,Kt]=(0,v.useState)(AV),qt=(0,v.useCallback)((e,t)=>{jV(e,t),Kt(n=>({...n,[e]:t}))},[]),[Jt,Yt]=(0,v.useState)(!1),[Xt,Zt]=(0,v.useState)(!0),[Qt,$t]=(0,v.useState)(!1),en=c.terminal?.enabled??!1;(0,v.useEffect)(()=>{let e=e=>{en&&(e.ctrlKey||e.metaKey)&&e.key==="`"&&(e.preventDefault(),$t(e=>!e))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[en]);let[tn,nn]=(0,v.useState)(!1),[rn,an]=(0,v.useState)(null),on=(0,v.useCallback)(()=>an(null),[]);function sn(){let e=!Jt;Yt(e),e&&(Zt(!1),nn(!1))}function cn(){let e=!Xt;Zt(e),e&&(Yt(!1),nn(!1))}function ln(){let e=!tn;nn(e),e&&(Yt(!1),Zt(!1))}(0,v.useEffect)(()=>(pt(tn),()=>pt(!1)),[tn,pt,c.sessionId,_t]),(0,v.useEffect)(()=>{nn(!1),an(null)},[_t]);let[un,dn]=(0,v.useState)([]),[fn,pn]=(0,v.useState)([]),mn=(0,v.useRef)(0),hn=(0,v.useRef)(0),[gn,_n]=(0,v.useState)(0);async function vn(e){let t=[...e],n=t.filter(WV).map(e=>({id:`${mn.current++}`,name:e.name}));n.length>0&&pn(e=>[...e,...n]),hn.current===0&&dn([]),hn.current++;try{let{attachments:e,errors:n}=await QV(t,he);e.length>0&&Ct(t=>[...t,...e]),n.length>0&&dn(e=>[...e,...n])}finally{if(hn.current--,n.length>0){let e=new Set(n.map(e=>e.id));pn(t=>t.filter(t=>!e.has(t.id)))}}}(0,v.useEffect)(()=>{Bt.current=St},[St]);function yn(){Se()}let bn=(0,v.useMemo)(()=>[...St.filter(e=>e.kind===`path`).map(e=>e.data),...wt],[St,wt]);function xn(e){let t=Bt.current.findIndex(t=>t.kind===`path`&&t.data===e);t>=0?Sn(t):wt.includes(e)||Ct(t=>rH(t,e))}function Sn(e){Ct(t=>iH(t,e))}let Cn=(0,v.useMemo)(()=>({btw:{region:`Side answer`,pinnedLines:1,anchor:e=>e.findLastIndex(e=>e.startsWith(`› `)),close:{label:`Close side answer`,run:()=>d(`/btw`)}}}),[d]);function wn(e,t){d(e,t),Ct([]),dn([]),Et||yn()}function Tn(e){e.preventDefault(),_n(0),e.dataTransfer.files.length>0&&vn(Array.from(e.dataTransfer.files))}let{theme:En,preference:Dn,toggle:On,setTheme:kn}=E(c.branding.defaultTheme??`system`,c.branding.allowThemeToggle!==!1,s,n);(0,v.useImperativeHandle)(a,()=>({setTheme:kn}),[kn]);let An=(0,v.useRef)(null),[jn,Mn]=(0,v.useState)(null),Nn=(0,v.useCallback)(e=>{An.current=e,Mn(e)},[]),Pn=(0,v.useRef)(null),Fn=(0,v.useRef)(!0),[In,Ln]=(0,v.useState)(!0),Rn=(0,v.useCallback)(e=>{e!==Fn.current&&Ln(e),Fn.current=e},[]),zn=(0,v.useCallback)(()=>{let e=An.current;e&&Rn(e.scrollHeight-e.scrollTop-e.clientHeight<G1)},[Rn]),Bn=(0,v.useRef)(null),Vn=(0,v.useCallback)(()=>{let e=An.current;e&&(e.scrollHeight-e.scrollTop-e.clientHeight<G1||(Bn.current=e.scrollTop))},[]),Hn=(0,v.useCallback)(()=>{let e=An.current;if(!e)return;let t=e.scrollHeight-e.scrollTop-e.clientHeight<G1,n=Bn.current;if(n!==null){if(e.scrollTop<n)Bn.current=null;else if(Bn.current=t?null:e.scrollTop,!t)return}Rn(t)},[Rn]);function Un(){Bn.current=null}(0,v.useEffect)(()=>{let e=jn;if(!e)return;let t=()=>{Bn.current=null,Hn()};e.addEventListener(`scrollend`,t);let n;return typeof ResizeObserver<`u`&&(n=new ResizeObserver(()=>{Fn.current?(Vn(),Pn.current?.scrollIntoView({behavior:`auto`})):Hn()}),n.observe(e),e.firstElementChild&&n.observe(e.firstElementChild)),()=>{e.removeEventListener(`scrollend`,t),n?.disconnect()}},[jn,Hn,Vn]);let Wn=(0,v.useCallback)(()=>{Rn(!0),Vn();let e=window.matchMedia?.(`(prefers-reduced-motion: reduce)`).matches??!1;Pn.current?.scrollIntoView({behavior:e?`auto`:`smooth`})},[Rn,Vn]);(0,v.useEffect)(()=>{Fn.current?(Vn(),Pn.current?.scrollIntoView({behavior:`smooth`})):zn()},[c.items,zn,Vn]);let Gn=(0,v.useMemo)(()=>XB(c.items),[c.items]),Kn=(0,v.useMemo)(()=>Jt?oV(c.items):null,[Jt,c.items]),qn=(0,v.useMemo)(()=>tB({readFile:(e,t)=>{Ht(!1),ue(e,t)},fetchGitFileHistory:e=>je(e),fetchGitDiff:e=>{Ht(!0),ue(e)},searchFiles:e=>Ce(e)}),[ue,je,Ce]),Jn=(0,v.useCallback)(()=>qt(`tools`,!0),[qt]),Yn=(0,v.useCallback)(e=>{let t=An.current;if(t){let n=t.getBoundingClientRect(),r=e.getBoundingClientRect(),i=r.top>=n.top&&r.bottom<=n.bottom,a=t.scrollHeight-t.scrollTop-t.clientHeight<G1;if(i&&a)return}Rn(!1)},[Rn]),[Xn,Zn]=(0,v.useState)(null),[Qn,$n]=(0,v.useState)(null),er=(0,v.useMemo)(()=>{let e=c.sessions?.find(e=>e.id===c.sessionId);return c.sessionName?.trim()||e?.name?.trim()||e?.firstMessage?.trim()||c.sessionId},[c.sessionName,c.sessions,c.sessionId]),tr=(0,v.useCallback)(async()=>{$n(null),Zn(`preparing…`);try{let{exportConversation:t}=await ye(async()=>{let{exportConversation:e}=await import(`./conversationExport-0nyaeKNF.js`);return{exportConversation:e}},__vite__mapDeps([26,21,1,25]));await t({items:c.items,olderItems:c.olderHistory?.remaining??0,...c.olderHistory?{fetchOlderItems:ie}:{},connection:{serverUrl:e,token:l,workspace:gt},meta:{...c.workspace?{project:c.workspace.name}:{},session:er,model:c.model,exportedAt:new Date},onProgress:(e,t,n)=>Zn(e===`collecting`?`reading ${t}/${n}…`:`writing ${t}/${n}…`)})}catch(e){$n(e instanceof Error?e.message:`the conversation could not be exported`)}finally{Zn(null)}},[c.items,c.olderHistory,c.workspace,c.model,er,ie,e,l,gt]),{jumpToItem:nr,highlightIndex:rr}=TV({items:c.items,scrollerRef:An,hideTools:!Gt.tools,onShowTools:Jn,onJump:Yn}),ir=(0,v.useRef)(null),ar=(0,v.useRef)(c.olderHistory?.have??0),or=(0,v.useCallback)(()=>{let e=An.current;e&&(ir.current={height:e.scrollHeight,top:e.scrollTop}),j()},[j]);return(0,v.useLayoutEffect)(()=>{let e=c.olderHistory?.have??0,t=ar.current;ar.current=e;let n=ir.current;if(ir.current=null,!n||e<=t)return;let r=An.current;r&&(r.scrollTop=n.top+(r.scrollHeight-n.height))},[c.olderHistory?.have]),(0,v.useEffect)(()=>{if(!o){let e=c.extensionTitle??c.branding.title??`pi`;document.title=c.workspace?`${c.workspace.name} — ${e}`:e}c.branding.accentColor&&s.style.setProperty(`--accent`,c.branding.accentColor)},[c.branding,c.extensionTitle,c.workspace?.name,o,s]),o&&!c.brandingReady?null:c.authRequired?(0,N.jsx)(b.Provider,{value:En,children:(0,N.jsx)(ZG,{title:c.branding.title,onSubmit:u})}):c.credentials&&!c.credentials.usableModel?(0,N.jsx)(b.Provider,{value:En,children:(0,N.jsx)(AG,{title:c.branding.title,credentials:c.credentials,onSetCredential:Fe,onStartLogin:Ie,login:c.login,onAnswerLogin:Le,onCancelLogin:Re,onDismissLogin:ze,onDeclareProvider:Ve,errors:c.errors})}):(0,N.jsx)(b.Provider,{value:En,children:(0,N.jsx)(kg.Provider,{value:c.replyConformance,children:(0,N.jsx)(ng.Provider,{value:c.structuredAppearance,children:(0,N.jsxs)(Pm.Provider,{value:Wt,children:[(0,N.jsxs)(`div`,{className:`relative flex h-full`,onDragEnter:e=>{e.dataTransfer.types.includes(`Files`)&&_n(e=>e+1)},onDragLeave:()=>_n(e=>Math.max(0,e-1)),onDragOver:e=>e.preventDefault(),onDrop:Tn,children:[gn>0&&(0,N.jsx)(`div`,{className:`pointer-events-none absolute inset-0 z-40 flex items-center justify-center border-2 border-dashed bg-white/70 backdrop-blur-sm dark:bg-zinc-950/70`,style:{borderColor:`var(--accent, #3b82f6)`},children:(0,N.jsx)(`p`,{className:`text-lg font-medium text-zinc-700 dark:text-zinc-200`,children:`Drop files to attach (images, documents & text)`})}),(vt||bt)&&(0,N.jsx)(XG,{hidden:!vt,onUploadFile:he,onExternalDragEnter:()=>_n(0),tree:c.fileTree,openFile:c.openFile,writableRoot:c.writableRoot,gitFiles:c.gitStatus?.files,attachedPaths:bn,onExpand:ce,onSelectDirectory:jt,onRefresh:le,onSelectFile:e=>{Ht(!1),jt(e),ue(e)},onSelectDiff:e=>{Ht(!0),jt(e),ue(e)},onToggleAttachPath:xn,onCreateFile:e=>{Ht(!1),pe(e)},onCreateDirectory:me,onOpenNative:ge,onRevealNative:P,onRenameFile:_e,onDeleteFile:ve,onMoveFile:be,onCopyFile:xe,fileOperation:c.fileOperation,createError:c.createError,created:c.created,contentSearch:c.contentSearch,onSearchContent:de,onOpenSearchHit:(e,t)=>{Ht(!1),jt(e.path),ue(e.path,void 0,e.kind===`line`?{query:t,line:e.line}:{query:t,page:e.page})}},JSON.stringify([_t,c.sandbox?.projectRoot??c.sandbox?.root])),(0,N.jsxs)(`div`,{className:`flex h-full min-w-0 flex-1 flex-col`,children:[Mt&&(0,N.jsx)(_W,{label:`Choose a project directory`,browse:c.serverBrowse,onBrowse:Xe,onSelect:e=>{Nt(!1),Ze(),et(e)},onCancel:()=>{Nt(!1),Ze()}}),!o&&c.outpostUpdate&&(0,N.jsx)(BB,{notice:c.outpostUpdate}),!o&&c.outpostChanges&&(0,N.jsx)(WB,{changes:c.outpostChanges}),(0,N.jsx)(hG,{workspace:c.workspace,workspaces:c.workspaces,workspaceLocked:c.workspaceLocked,workspaceControl:o?Pt:`projects`,rootControl:{sandbox:c.sandbox,browse:c.serverBrowse,applyState:c.settingsApply,blocked:Ot!==null&&Ot!==`root`,onBrowse:Xe,onCloseBrowser:()=>{kt(null),Ze()},onOpened:()=>kt(`root`),onSelect:e=>He({sandbox:{root:e,allowWrite:c.sandbox?.allowWrite??!1,allowBash:c.sandbox?.allowBash??!1,...c.sandbox?.writableRoot?{writableRoot:c.sandbox.writableRoot}:{}}})},onSwitchWorkspace:Qe,onOpenProject:()=>{Nt(!0),Xe(``)},onCloseProject:tt,onOpenSideSession:nt,piPackages:c.piPackages,piPackageUpdate:c.piPackageUpdate,canRestartServer:!o,serverRestarting:c.serverRestarting,onCheckPiPackages:rt,onUpdatePiPackage:it,onRestartServer:at,restartNeeded:c.restartNeeded,title:c.branding.title,credentials:c.credentials,login:c.login,onStartLogin:Ie,onAnswerLogin:Le,onCancelLogin:Re,onDismissLogin:ze,onLogoutProvider:Be,sessions:c.sessions,sessionSearch:c.sessionSearch,sessionId:c.sessionId,tree:c.tree,isStreaming:c.isStreaming,connected:c.connected,theme:En,showThemeToggle:c.branding.allowThemeToggle!==!1,statuses:c.statuses,sidebarOpen:vt,outcomeOpen:tn,filters:Gt,onToggleSidebar:()=>{xt(!0),yt(e=>!e)},onToggleOutcome:ln,onFilterChange:qt,...c.items.length>0?{onExportConversation:()=>void tr()}:{},exportProgress:Xn,onToggleTheme:On,themePreference:Dn,onSetTheme:kn,onNewSession:g,onSwitchSession:_,onDeleteSession:y,onListSessions:x,onRenameSession:S,onSearchSessions:C,onClearSessionSearch:w,onListTree:T,onNavigateTree:D,onForkSession:O,gitAvailable:c.gitAvailable,gitStatus:c.gitStatus,gitSelectedPath:At,gitLog:c.gitLog,extensionPaths:c.extensionPaths,configuredExtensionPaths:c.configuredExtensionPaths,userExtensionPaths:c.userExtensionPaths,extensionLock:c.extensionLock,tools:c.tools,commands:c.commands,sandbox:c.sandbox,gitUnavailable:c.gitUnavailable,userSkillPaths:c.userSkillPaths,serverBrowse:c.serverBrowse,settingsApply:c.settingsApply,agentResources:c.agentResources,agentResourceOperations:c.agentResourceOperations,versions:c.versions,onBrowseServerPath:Xe,onCloseServerBrowser:Ze,settingsPickerBlocked:Ot!==null&&Ot!==`settings`,onSettingsPickerOpened:()=>kt(`settings`),onRestartSession:ot,onUpdateConfig:He,onSuggestAgentResourceClonePath:Ue,onCloneAgentResourceRepository:We,onEnrollAgentResourceRepository:Ge,onSetAgentResourceSkills:Ke,onRemoveAgentResourceRepository:qe,onRefreshAgentResourceRepositories:Je,onUpdateAgentResourceRepository:Ye,onFetchGitLog:De,onCloseGitLog:Oe,onShowCommit:ke,terminalOpen:Qt,onToggleTerminal:en?()=>$t(e=>!e):void 0}),(0,N.jsxs)(`div`,{className:`relative z-0 flex min-h-0 flex-1 flex-col`,children:[c.workPlan&&(0,N.jsx)(tK,{plan:c.workPlan,open:Xt,onToggle:cn,onOpenWorkspace:e=>{Ht(!1),ue(e)},requestedTaskId:rn,onTaskRequestHandled:on}),tn&&(0,N.jsx)(y1,{state:c.outcome,onClose:()=>nn(!1),onRefresh:mt,onTarget:e=>{e.kind===`work-plan-task`?(an(e.taskId),nn(!1),Yt(!1),Zt(!0)):e.kind===`workspace-file`?(Ht(!1),ue(e.path)):e.kind===`workspace-diff`&&(Ht(!0),ue(e.path))}}),c.openFile&&(0,N.jsx)(DU,{file:c.openFile,writableRoot:c.writableRoot,docxTemplate:c.docxTemplate,isStreaming:c.isStreaming,onDirtyChange:Dt,gitState:c.gitStatus?.files[c.openFile.path],initialShowGitDiff:Vt,gitDiff:c.gitDiff,gitBaseline:c.gitBaseline?.path===c.openFile.path?c.gitBaseline.text??null:null,onFetchGitDiff:Te,onClearGitDiff:Ee,inRepository:NV(c.gitStatus?.repos??[],c.openFile.path)!==null,onOpenGitHistory:je,onClose:yn,onReload:ue,onSave:M,serverUrl:e,token:l,workspace:gt,onOpenNative:ge,rawRevision:c.previewRevision},c.openFile.path),c.gitFileHistory&&(0,N.jsx)(rW,{history:c.gitFileHistory,diff:c.gitFileDiff,dirty:c.gitStatus?.files[c.gitFileHistory.path]!==void 0,onFetchDiff:Ne,onClearDiff:Pe,onClose:Me}),c.gitShow&&(0,N.jsx)(AU,{show:c.gitShow,onClose:Ae}),Kn&&(0,N.jsx)(CV,{analysis:Kn,onJump:nr,onClose:()=>Yt(!1)}),(0,N.jsx)(`main`,{ref:Nn,onScroll:Hn,onWheel:Un,onTouchStart:Un,onKeyDown:Un,className:`flex-1 overflow-y-auto transition-opacity duration-150 ${c.switching?`opacity-40`:`opacity-100`} ${Jt?`md:pr-[26rem]`:c.workPlan&&Xt?`md:pr-[23rem]`:``}`,children:(0,N.jsxs)(`div`,{className:`mx-auto flex max-w-3xl flex-col gap-3 px-4 py-6`,children:[c.items.length===0&&(0,N.jsxs)(`div`,{className:`mt-24 text-center text-zinc-500 dark:text-zinc-600`,children:[(0,N.jsx)(`div`,{className:`mb-2 text-4xl`,children:c.branding.title??`π`}),c.agentStarting?(0,N.jsx)(`p`,{className:`text-sm`,role:`status`,"data-testid":`agent-starting`,children:`Starting the agent… The project's files are ready.`}):(0,N.jsx)(`p`,{className:`text-sm`,children:c.branding.welcome??`Send a message to start the agent.`})]}),c.olderHistory&&(0,N.jsx)(JB,{older:c.olderHistory,onLoad:or}),c.items.map((t,n)=>{let r=`${c.sessionId}:${n}`,i=(e,t=r)=>(0,N.jsx)(`div`,{"data-item-index":n,className:`flex flex-col gap-3 rounded-lg transition-shadow ${rr===n?`ring-2 ring-blue-400 dark:ring-blue-500`:``}`,children:e},t);return t.kind===`user`?i((0,N.jsx)($e,{item:t,canEdit:!t.readOnly&&!c.isStreaming&&c.connected,onEdit:ee})):t.kind===`compaction`?i((0,N.jsx)(qB,{item:t})):t.kind===`tool`?Gt.tools?i((0,N.jsx)(IB,{item:t,dispatch:qn}),t.toolCallId?`${c.sessionId}:${t.toolCallId}`:r):null:t.kind===`custom`?i((0,N.jsx)(LB,{item:t})):(Gt.reasoning?t.blocks:t.blocks.filter(e=>e.type!==`thinking`)).length===0&&!t.errorMessage?(0,N.jsx)(`div`,{"data-item-index":n,className:`sr-only`,"aria-hidden":!0},r):i((0,N.jsx)(Qz,{item:t,hideReasoning:!Gt.reasoning,serverUrl:e,token:l,workspace:gt,onOpenFile:e=>{Ht(!1),ue(e)}}))}),c.pendingPrompt&&(0,N.jsxs)(`div`,{className:`flex flex-col gap-3 opacity-60`,"data-pending-prompt":!0,children:[(0,N.jsx)($e,{item:{kind:`user`,...c.pendingPrompt},canEdit:!1,onEdit:()=>{}}),c.extensionsBinding?(0,N.jsxs)(`div`,{className:`flex items-center gap-3`,"data-testid":`prompt-waiting-for-extensions`,children:[(0,N.jsx)(K1,{label:`waiting for extensions to start…`}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>p(!Ft.current[_t??``]),className:`text-xs text-zinc-500 underline hover:text-zinc-700 dark:hover:text-zinc-300`,children:`cancel`})]}):(0,N.jsx)(K1,{label:`sending…`})]}),c.isStreaming&&!c.pendingPrompt&&(0,N.jsx)(K1,{label:`working…`}),c.queue.map(e=>(0,N.jsx)($e,{item:{kind:`user`,text:e.text,entryId:e.id,...e.images?{images:e.images}:{}},canEdit:e.editable&&c.connected,onEdit:(e,t)=>te(e,t),queued:{onRemove:()=>k(e.id),onDraftChange:zt(e.id,e.text)}},e.id)),c.queue.length>0&&c.queue.every(e=>e.editable)&&c.connected&&(0,N.jsx)(PV,{isStreaming:c.isStreaming,count:c.queue.length,onSend:ne}),un.map((e,t)=>(0,N.jsx)(`div`,{className:`rounded-lg border border-amber-300 bg-amber-50 px-3 py-2 text-sm text-amber-700 dark:border-amber-900/60 dark:bg-amber-950/30 dark:text-amber-300`,children:e},`att${t}`)),Qn&&(0,N.jsx)(`div`,{className:`rounded-lg border border-red-300 bg-red-50 px-3 py-2 text-sm text-red-700 dark:border-red-900/60 dark:bg-red-950/30 dark:text-red-300`,children:Qn}),c.errors.map((e,t)=>(0,N.jsx)(`div`,{className:`rounded-lg border border-red-300 bg-red-50 px-3 py-2 text-sm text-red-700 dark:border-red-900/60 dark:bg-red-950/30 dark:text-red-300`,children:e},t)),(0,N.jsx)(`div`,{ref:Pn})]})}),(0,N.jsx)(`div`,{className:`pointer-events-none absolute inset-x-0 bottom-4 z-0 flex justify-center ${Jt||tn?`md:pr-[26rem]`:c.workPlan&&Xt?`md:pr-[23rem]`:``}`,children:!In&&(0,N.jsxs)(`button`,{type:`button`,onClick:Wn,"aria-label":`Scroll to the latest message`,className:`pointer-events-auto flex items-center gap-1.5 rounded-full border border-zinc-300 bg-white/95 px-3 py-1.5 text-xs text-zinc-600 shadow-lg backdrop-blur transition-colors hover:bg-zinc-50 motion-reduce:transition-none dark:border-zinc-700 dark:bg-zinc-900/95 dark:text-zinc-300 dark:hover:bg-zinc-800`,children:[(0,N.jsx)(`span`,{"aria-hidden":!0,children:`↓`}),`Latest`]})})]}),en&&(0,N.jsx)(h1,{open:Qt,onClose:()=>$t(!1),cwd:c.workspace?.root,confinedRoot:c.terminal?.confined?c.sandbox?.root??c.workspace?.root:void 0,confinement:c.confinement?.terminal,unavailable:c.terminal?.unavailable,onSetWorkspaceRoot:e=>{et&&!o?et(e):c.sandbox?He({sandbox:{root:e,allowWrite:c.sandbox.allowWrite,allowBash:c.sandbox.allowBash,...c.sandbox.writableRoot?{writableRoot:c.sandbox.writableRoot}:{}}}):He({sandbox:{root:e,allowWrite:!0,allowBash:!0}})},shells:c.terminal?.shells,openTerminal:st,sendTerminalInput:ct,getTerminalCwd:lt,resizeTerminal:ut,closeTerminal:dt,subscribeTerminal:ft}),(0,N.jsx)(`footer`,{className:`border-t border-zinc-200 px-4 py-3 dark:border-zinc-800`,children:(0,N.jsxs)(`div`,{className:`mx-auto max-w-3xl`,children:[(0,N.jsx)(RH,{widgets:c.widgets,placement:`aboveEditor`,controls:Cn}),(0,N.jsx)(fH,{initialDraft:Ft.current[_t??``]??``,onDraftChange:e=>{Ft.current[_t??``]=e},isStreaming:c.isStreaming,connected:c.connected,commands:c.commands,fileSearch:c.fileSearch,prefill:c.editorPrefill,attachments:St,pendingUploads:fn,onAttach:e=>void vn(e),onMentionPaths:Tt,onRemoveAttachment:Sn,onSend:wn,onAbort:f,onSearchFiles:Ce,onClearFileSearch:we},_t??``),(0,N.jsx)(RH,{widgets:c.widgets,placement:`belowEditor`}),(0,N.jsx)(DG,{model:c.model,models:c.models,thinkingLevel:c.thinkingLevel,thinkingLevels:c.thinkingLevels,modelSupportsReasoning:c.modelSupportsReasoning,isStreaming:c.isStreaming,contextUsage:c.contextUsage,shellConfinement:c.confinement?.bash,shellGrants:c.sandboxGrants?.active,sessionUsage:Gn,analysisOpen:Jt,onToggleAnalysis:sn,isCompacting:c.isCompacting,onSetModel:m,onSetThinking:h,onCompact:re})]})})]})]}),c.dialogQueue[0]&&(0,N.jsx)(SH,{request:c.dialogQueue[0],onRespond:ae}),!c.dialogQueue[0]&&c.sandboxGrants?.pending[0]&&(0,N.jsx)(EH,{request:c.sandboxGrants.pending[0],onRespond:oe}),(0,N.jsx)(AH,{notifications:c.notifications,onDismiss:se})]})})})})});(0,y.createRoot)(document.getElementById(`root`)).render((0,N.jsx)(v.StrictMode,{children:(0,N.jsx)(q1,{})}));export{oe as A,Pg as C,pe as D,ye as E,d as M,ae as O,Bg as S,Be as T,gx as _,Cz as a,S_ as b,lI as c,ij as d,WA as f,PS as g,cC as h,Kz as i,re as j,de as k,WF as l,Cw as m,fU as n,dz as o,VA as p,mU as r,uI as s,E1 as t,vj as u,w_ as v,oh as w,v_ as x,x_ as y};