@rudderhq/server 0.2.2-canary.2 → 0.2.2-canary.3

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 (77) hide show
  1. package/package.json +13 -13
  2. package/ui-dist/assets/{_basePickBy-BHVn4M9N.js → _basePickBy-Rd6MYPtk.js} +1 -1
  3. package/ui-dist/assets/{_baseUniq-rpIUa-eX.js → _baseUniq-DXrnWrq3.js} +1 -1
  4. package/ui-dist/assets/{arc-De0Y9szt.js → arc-COmb7bpt.js} +1 -1
  5. package/ui-dist/assets/{architectureDiagram-2XIMDMQ5-BC6QPWuc.js → architectureDiagram-2XIMDMQ5-DZ6etNEj.js} +1 -1
  6. package/ui-dist/assets/{blockDiagram-WCTKOSBZ-CamgqwaY.js → blockDiagram-WCTKOSBZ-BqRRrlZ5.js} +1 -1
  7. package/ui-dist/assets/{c4Diagram-IC4MRINW-CXYqMexk.js → c4Diagram-IC4MRINW-BlOYlTft.js} +1 -1
  8. package/ui-dist/assets/channel-BjOW-5aO.js +1 -0
  9. package/ui-dist/assets/{chunk-4BX2VUAB-BFWykUQf.js → chunk-4BX2VUAB-Dc1fgOhJ.js} +1 -1
  10. package/ui-dist/assets/{chunk-55IACEB6-CKZnwZS-.js → chunk-55IACEB6-CjYYt7QO.js} +1 -1
  11. package/ui-dist/assets/{chunk-FMBD7UC4-BQ33_Iah.js → chunk-FMBD7UC4-BWOFAynz.js} +1 -1
  12. package/ui-dist/assets/{chunk-JSJVCQXG-BIOfqD0H.js → chunk-JSJVCQXG-Ch1lsjaX.js} +1 -1
  13. package/ui-dist/assets/{chunk-KX2RTZJC-Cja9vHnk.js → chunk-KX2RTZJC-C6BDBDZs.js} +1 -1
  14. package/ui-dist/assets/{chunk-NQ4KR5QH-DOjbOIbA.js → chunk-NQ4KR5QH-CFEa1XvV.js} +1 -1
  15. package/ui-dist/assets/{chunk-QZHKN3VN-7Jje-AdT.js → chunk-QZHKN3VN-h_P4GFiA.js} +1 -1
  16. package/ui-dist/assets/{chunk-WL4C6EOR-DCbYaL8p.js → chunk-WL4C6EOR-FbrTk2R3.js} +1 -1
  17. package/ui-dist/assets/classDiagram-VBA2DB6C-B4xbBrJI.js +1 -0
  18. package/ui-dist/assets/classDiagram-v2-RAHNMMFH-B4xbBrJI.js +1 -0
  19. package/ui-dist/assets/clone-Cq7F8Gzl.js +1 -0
  20. package/ui-dist/assets/{cose-bilkent-S5V4N54A-BNuHuIn6.js → cose-bilkent-S5V4N54A-C4UsBXst.js} +1 -1
  21. package/ui-dist/assets/{dagre-KLK3FWXG-BbU6smn4.js → dagre-KLK3FWXG-C-bzZ-RX.js} +1 -1
  22. package/ui-dist/assets/{diagram-E7M64L7V-QorhwM5z.js → diagram-E7M64L7V-TaZgE69c.js} +1 -1
  23. package/ui-dist/assets/{diagram-IFDJBPK2-DXzEJCm0.js → diagram-IFDJBPK2-BLU9TNG7.js} +1 -1
  24. package/ui-dist/assets/{diagram-P4PSJMXO-BY6OYVcc.js → diagram-P4PSJMXO-CuiXNw8_.js} +1 -1
  25. package/ui-dist/assets/{erDiagram-INFDFZHY-cLJMfH3Z.js → erDiagram-INFDFZHY-RZi1Q5ND.js} +1 -1
  26. package/ui-dist/assets/{flowDiagram-PKNHOUZH-QKiVGEHs.js → flowDiagram-PKNHOUZH-fDXk12CS.js} +1 -1
  27. package/ui-dist/assets/{ganttDiagram-A5KZAMGK-B3V-fCAZ.js → ganttDiagram-A5KZAMGK-DRA3w0pK.js} +1 -1
  28. package/ui-dist/assets/{gitGraphDiagram-K3NZZRJ6-C0qU5oFU.js → gitGraphDiagram-K3NZZRJ6-CA33A0P0.js} +1 -1
  29. package/ui-dist/assets/{graph-Dm6iCnis.js → graph-CLBrLUGH.js} +1 -1
  30. package/ui-dist/assets/{index-C3puStO3.js → index-2KxI7xgS.js} +1 -1
  31. package/ui-dist/assets/{index-C7Cmw8dX.js → index-2fpQE_AC.js} +1 -1
  32. package/ui-dist/assets/{index-BmcxJrjx.js → index-37v_vD1F.js} +1 -1
  33. package/ui-dist/assets/{index-BJSp5aCY.js → index-5WtC-lYX.js} +1 -1
  34. package/ui-dist/assets/{index-WuWP8I5T.js → index-6CbWISCh.js} +1 -1
  35. package/ui-dist/assets/{index-2VLdrule.js → index-BEIANN3j.js} +1 -1
  36. package/ui-dist/assets/{index-NgDP54Ta.js → index-BUBHt44A.js} +1 -1
  37. package/ui-dist/assets/{index-DmZZmv9g.js → index-C-Fleuj8.js} +1 -1
  38. package/ui-dist/assets/{index-D_cP5U44.js → index-CB1hG4Kq.js} +1 -1
  39. package/ui-dist/assets/{index-DuqLiAIL.js → index-CGVwjOWT.js} +1 -1
  40. package/ui-dist/assets/{index-Dndw5aiH.js → index-CShHgd9H.js} +1 -1
  41. package/ui-dist/assets/{index-BABkBYsI.js → index-CxdGyiXd.js} +1 -1
  42. package/ui-dist/assets/{index-B2EnQtkM.js → index-D5l562f1.js} +1 -1
  43. package/ui-dist/assets/{index-C2FQ4k2x.js → index-D8uEkAY_.js} +1 -1
  44. package/ui-dist/assets/{index-DptZkFjs.js → index-DC4tbOtF.js} +1 -1
  45. package/ui-dist/assets/{index-D9D4KyAP.js → index-DCMV2c1v.js} +1 -1
  46. package/ui-dist/assets/{index-CmRex7R0.js → index-DFmuhhef.js} +4 -4
  47. package/ui-dist/assets/{index-B1de0GcS.js → index-DLTnS5K4.js} +1 -1
  48. package/ui-dist/assets/{index-Cfn-GmgI.js → index-DO0UFbrH.js} +1 -1
  49. package/ui-dist/assets/{index-B8i0_qWK.js → index-DuBWRTfm.js} +1 -1
  50. package/ui-dist/assets/{index-C_8Z518O.js → index-MBC8Ql6F.js} +1 -1
  51. package/ui-dist/assets/{index-CPrGAvvf.js → index-P9kFtvbc.js} +1 -1
  52. package/ui-dist/assets/{index-BSI5T_q4.js → index-oHpvPar-.js} +1 -1
  53. package/ui-dist/assets/{infoDiagram-LFFYTUFH-Bpdi2Qw3.js → infoDiagram-LFFYTUFH-B1x_tqKw.js} +1 -1
  54. package/ui-dist/assets/{ishikawaDiagram-PHBUUO56-CbTyZjQo.js → ishikawaDiagram-PHBUUO56-hYnFwVpx.js} +1 -1
  55. package/ui-dist/assets/{journeyDiagram-4ABVD52K-DP6QVWsj.js → journeyDiagram-4ABVD52K-eDzUr_iE.js} +1 -1
  56. package/ui-dist/assets/{kanban-definition-K7BYSVSG-Y5Go4cdI.js → kanban-definition-K7BYSVSG-CfPXRBG_.js} +1 -1
  57. package/ui-dist/assets/{layout-DPuoI3gW.js → layout-BAc2slDk.js} +1 -1
  58. package/ui-dist/assets/{linear-0MSnTjD6.js → linear-BnfVqPnw.js} +1 -1
  59. package/ui-dist/assets/{mermaid.core-BlSfPv1h.js → mermaid.core-CfGzrCcV.js} +4 -4
  60. package/ui-dist/assets/{mindmap-definition-YRQLILUH-DUcSzqJI.js → mindmap-definition-YRQLILUH-DFcU8k3f.js} +1 -1
  61. package/ui-dist/assets/{pieDiagram-SKSYHLDU-7jPcehlQ.js → pieDiagram-SKSYHLDU-DRwHOHJu.js} +1 -1
  62. package/ui-dist/assets/{quadrantDiagram-337W2JSQ-C-lAjJhI.js → quadrantDiagram-337W2JSQ-DE0S3ICE.js} +1 -1
  63. package/ui-dist/assets/{requirementDiagram-Z7DCOOCP-wd_b7SAX.js → requirementDiagram-Z7DCOOCP-DCfENVUg.js} +1 -1
  64. package/ui-dist/assets/{sankeyDiagram-WA2Y5GQK-CeZSQHmZ.js → sankeyDiagram-WA2Y5GQK-Bl6QDRP8.js} +1 -1
  65. package/ui-dist/assets/{sequenceDiagram-2WXFIKYE-Bx9Si8DF.js → sequenceDiagram-2WXFIKYE-pMte85t7.js} +1 -1
  66. package/ui-dist/assets/{stateDiagram-RAJIS63D-Csjcftqp.js → stateDiagram-RAJIS63D-DEtxxbIp.js} +1 -1
  67. package/ui-dist/assets/stateDiagram-v2-FVOUBMTO-BoEztILX.js +1 -0
  68. package/ui-dist/assets/{timeline-definition-YZTLITO2-oKT-IT_u.js → timeline-definition-YZTLITO2-fGdyRhdn.js} +1 -1
  69. package/ui-dist/assets/{treemap-KZPCXAKY-BVi-fd5H.js → treemap-KZPCXAKY-CwAp1_Hr.js} +1 -1
  70. package/ui-dist/assets/{vennDiagram-LZ73GAT5-Ds0sLzE5.js → vennDiagram-LZ73GAT5-DbeqMPD4.js} +1 -1
  71. package/ui-dist/assets/{xychartDiagram-JWTSCODW-BQgvUx6p.js → xychartDiagram-JWTSCODW-C-xeFM6j.js} +1 -1
  72. package/ui-dist/index.html +1 -1
  73. package/ui-dist/assets/channel-3VU9frM2.js +0 -1
  74. package/ui-dist/assets/classDiagram-VBA2DB6C-B9dOhlUc.js +0 -1
  75. package/ui-dist/assets/classDiagram-v2-RAHNMMFH-B9dOhlUc.js +0 -1
  76. package/ui-dist/assets/clone-7JViJz9J.js +0 -1
  77. package/ui-dist/assets/stateDiagram-v2-FVOUBMTO-D_86FTuW.js +0 -1
@@ -1,4 +1,4 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-DuqLiAIL.js","assets/index-C_8Z518O.js","assets/index-BSI5T_q4.js","assets/index-C7Cmw8dX.js","assets/index-Cfn-GmgI.js","assets/index-B1de0GcS.js","assets/index-C3puStO3.js","assets/index-BABkBYsI.js","assets/index-DmZZmv9g.js","assets/index-WuWP8I5T.js","assets/index-B8i0_qWK.js","assets/index-D9D4KyAP.js","assets/index-CPrGAvvf.js","assets/index-BmcxJrjx.js","assets/index-NgDP54Ta.js","assets/index-DptZkFjs.js","assets/index-Dndw5aiH.js","assets/index-D_cP5U44.js","assets/index-BJSp5aCY.js","assets/index-B2EnQtkM.js","assets/dockerfile-BKs6k2Af.js","assets/simple-mode-GW_nhZxv.js","assets/factor-kuTfRLto.js","assets/nsis-LdVXkNf5.js","assets/pug-DeIclll2.js","assets/javascript-iXu5QeM3.js","assets/index-C2FQ4k2x.js","assets/index-2VLdrule.js"])))=>i.map(i=>d[i]);
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-CGVwjOWT.js","assets/index-MBC8Ql6F.js","assets/index-oHpvPar-.js","assets/index-2fpQE_AC.js","assets/index-DO0UFbrH.js","assets/index-DLTnS5K4.js","assets/index-2KxI7xgS.js","assets/index-CxdGyiXd.js","assets/index-C-Fleuj8.js","assets/index-6CbWISCh.js","assets/index-DuBWRTfm.js","assets/index-DCMV2c1v.js","assets/index-P9kFtvbc.js","assets/index-37v_vD1F.js","assets/index-BUBHt44A.js","assets/index-DC4tbOtF.js","assets/index-CShHgd9H.js","assets/index-CB1hG4Kq.js","assets/index-5WtC-lYX.js","assets/index-D5l562f1.js","assets/dockerfile-BKs6k2Af.js","assets/simple-mode-GW_nhZxv.js","assets/factor-kuTfRLto.js","assets/nsis-LdVXkNf5.js","assets/pug-DeIclll2.js","assets/javascript-iXu5QeM3.js","assets/index-D8uEkAY_.js","assets/index-BEIANN3j.js"])))=>i.map(i=>d[i]);
2
2
  var ASe=Object.defineProperty;var VK=e=>{throw TypeError(e)};var ESe=(e,t,n)=>t in e?ASe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var Ai=(e,t,n)=>ESe(e,typeof t!="symbol"?t+"":t,n),x4=(e,t,n)=>t.has(e)||VK("Cannot "+n);var Le=(e,t,n)=>(x4(e,t,"read from private field"),n?n.call(e):t.get(e)),vn=(e,t,n)=>t.has(e)?VK("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),Wt=(e,t,n,r)=>(x4(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),ir=(e,t,n)=>(x4(e,t,"access private method"),n);var O2=(e,t,n,r)=>({set _(s){Wt(e,t,s,n)},get _(){return Le(e,t,r)}});function Qse(e,t){for(var n=0;n<t.length;n++){const r=t[n];if(typeof r!="string"&&!Array.isArray(r)){for(const s in r)if(s!=="default"&&!(s in e)){const a=Object.getOwnPropertyDescriptor(r,s);a&&Object.defineProperty(e,s,a.get?a:{enumerable:!0,get:()=>r[s]})}}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))r(s);new MutationObserver(s=>{for(const a of s)if(a.type==="childList")for(const o of a.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&r(o)}).observe(document,{childList:!0,subtree:!0});function n(s){const a={};return s.integrity&&(a.integrity=s.integrity),s.referrerPolicy&&(a.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?a.credentials="include":s.crossOrigin==="anonymous"?a.credentials="omit":a.credentials="same-origin",a}function r(s){if(s.ep)return;s.ep=!0;const a=n(s);fetch(s.href,a)}})();var HK=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function s1(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function UAt(e){if(Object.prototype.hasOwnProperty.call(e,"__esModule"))return e;var t=e.default;if(typeof t=="function"){var n=function r(){return this instanceof r?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach(function(r){var s=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(n,r,s.get?s:{enumerable:!0,get:function(){return e[r]}})}),n}var b4={exports:{}},Ww={};/**
3
3
  * @license React
4
4
  * react-jsx-runtime.production.js
@@ -1279,7 +1279,7 @@ When you submit the join request, use:
1279
1279
  `))};if((Qt.mac||Qt.android)&&h.from==o-1&&/^\. ?$/.test(r.text)&&t.contentDOM.getAttribute("autocorrect")=="off"&&(h={from:l,to:c,insert:ts.of([r.text.replace("."," ")])}),this.pendingContextChange=h,!t.state.readOnly){let m=this.to-this.from+(h.to-h.from+h.insert.length);PB(t,h,xt.single(this.toEditorPos(r.selectionStart,m),this.toEditorPos(r.selectionEnd,m)))}this.pendingContextChange&&(this.revertPending(t.state),this.setSelection(t.state)),h.from<h.to&&!h.insert.length&&t.inputState.composing>=0&&!/[\\p{Alphabetic}\\p{Number}_]/.test(n.text.slice(Math.max(0,r.updateRangeStart-1),Math.min(n.text.length,r.updateRangeStart+1)))&&this.handlers.compositionend(r)},this.handlers.characterboundsupdate=r=>{let s=[],a=null;for(let o=this.toEditorPos(r.rangeStart),l=this.toEditorPos(r.rangeEnd);o<l;o++){let c=t.coordsForChar(o);a=c&&new DOMRect(c.left,c.top,c.right-c.left,c.bottom-c.top)||a||new DOMRect,s.push(a)}n.updateCharacterBounds(r.rangeStart,s)},this.handlers.textformatupdate=r=>{let s=[];for(let a of r.getTextFormats()){let o=a.underlineStyle,l=a.underlineThickness;if(!/none/i.test(o)&&!/none/i.test(l)){let c=this.toEditorPos(a.rangeStart),u=this.toEditorPos(a.rangeEnd);if(c<u){let d=`text-decoration: underline ${/^[a-z]/.test(o)?o+" ":o=="Dashed"?"dashed ":o=="Squiggle"?"wavy ":""}${/thin/i.test(l)?1:2}px`;s.push(En.mark({attributes:{style:d}}).range(c,u))}}}t.dispatch({effects:rye.of(En.set(s))})},this.handlers.compositionstart=()=>{t.inputState.composing<0&&(t.inputState.composing=0,t.inputState.compositionFirstChange=!0)},this.handlers.compositionend=()=>{if(t.inputState.composing=-1,t.inputState.compositionFirstChange=null,this.composing){let{drifted:r}=this.composing;this.composing=null,r&&this.reset(t.state)}};for(let r in this.handlers)n.addEventListener(r,this.handlers[r]);this.measureReq={read:r=>{this.editContext.updateControlBounds(r.contentDOM.getBoundingClientRect());let s=AN(r.root);s&&s.rangeCount&&this.editContext.updateSelectionBounds(s.getRangeAt(0).getBoundingClientRect())}}}applyEdits(t){let n=0,r=!1,s=this.pendingContextChange;return t.changes.iterChanges((a,o,l,c,u)=>{if(r)return;let d=u.length-(o-a);if(s&&o>=s.to)if(s.from==a&&s.to==o&&s.insert.eq(u)){s=this.pendingContextChange=null,n+=d,this.to+=d;return}else s=null,this.revertPending(t.state);if(a+=n,o+=n,o<=this.from)this.from+=d,this.to+=d;else if(a<this.to){if(a<this.from||o>this.to||this.to-this.from+u.length>3e4){r=!0;return}this.editContext.updateText(this.toContextPos(a),this.toContextPos(o),u.toString()),this.to+=d}n+=d}),s&&!r&&this.revertPending(t.state),!r}update(t){let n=this.pendingContextChange,r=t.startState.selection.main;this.composing&&(this.composing.drifted||!t.changes.touchesRange(r.from,r.to)&&t.transactions.some(s=>!s.isUserEvent("input.type")&&s.changes.touchesRange(this.from,this.to)))?(this.composing.drifted=!0,this.composing.editorBase=t.changes.mapPos(this.composing.editorBase)):!this.applyEdits(t)||!this.rangeIsValid(t.state)?(this.pendingContextChange=null,this.reset(t.state)):(t.docChanged||t.selectionSet||n)&&this.setSelection(t.state),(t.geometryChanged||t.docChanged||t.selectionSet)&&t.view.requestMeasure(this.measureReq)}resetRange(t){let{head:n}=t.selection.main;this.from=Math.max(0,n-1e4),this.to=Math.min(t.doc.length,n+1e4)}reset(t){this.resetRange(t),this.editContext.updateText(0,this.editContext.text.length,t.doc.sliceString(this.from,this.to)),this.setSelection(t)}revertPending(t){let n=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(n.from),this.toContextPos(n.from+n.insert.length),t.doc.sliceString(n.from,n.to))}setSelection(t){let{main:n}=t.selection,r=this.toContextPos(Math.max(this.from,Math.min(this.to,n.anchor))),s=this.toContextPos(n.head);(this.editContext.selectionStart!=r||this.editContext.selectionEnd!=s)&&this.editContext.updateSelection(r,s)}rangeIsValid(t){let{head:n}=t.selection.main;return!(this.from>0&&n-this.from<500||this.to<t.doc.length&&this.to-n<500||this.to-this.from>1e4*3)}toEditorPos(t,n=this.to-this.from){t=Math.min(t,n);let r=this.composing;return r&&r.drifted?r.editorBase+(t-r.contextBase):t+this.from}toContextPos(t){let n=this.composing;return n&&n.drifted?n.contextBase+(t-n.editorBase):t-this.from}destroy(){for(let t in this.handlers)this.editContext.removeEventListener(t,this.handlers[t])}}class Yt{get state(){return this.viewState.state}get viewport(){return this.viewState.viewport}get visibleRanges(){return this.viewState.visibleRanges}get inView(){return this.viewState.inView}get composing(){return!!this.inputState&&this.inputState.composing>0}get compositionStarted(){return!!this.inputState&&this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}constructor(t={}){var n;this.plugins=[],this.pluginMap=new Map,this.editorAttrs={},this.contentAttrs={},this.bidiCache=[],this.destroyed=!1,this.updateState=2,this.measureScheduled=-1,this.measureRequests=[],this.contentDOM=document.createElement("div"),this.scrollDOM=document.createElement("div"),this.scrollDOM.tabIndex=-1,this.scrollDOM.className="cm-scroller",this.scrollDOM.appendChild(this.contentDOM),this.announceDOM=document.createElement("div"),this.announceDOM.className="cm-announced",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM),t.parent&&t.parent.appendChild(this.dom);let{dispatch:r}=t;this.dispatchTransactions=t.dispatchTransactions||r&&(s=>s.forEach(a=>r(a,this)))||(s=>this.update(s)),this.dispatch=this.dispatch.bind(this),this._root=t.root||Rtt(t.parent)||document,this.viewState=new XZ(this,t.state||Ur.create(t)),t.scrollTo&&t.scrollTo.is(m_)&&(this.viewState.scrollTarget=t.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(R0).map(s=>new JO(s));for(let s of this.plugins)s.update(this);this.observer=new trt(this),this.inputState=new Nnt(this),this.inputState.ensureHandlers(this.plugins),this.docView=new zZ(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),!((n=document.fonts)===null||n===void 0)&&n.ready&&document.fonts.ready.then(()=>{this.viewState.mustMeasureContent="refresh",this.requestMeasure()})}dispatch(...t){let n=t.length==1&&t[0]instanceof fa?t:t.length==1&&Array.isArray(t[0])?t[0]:[this.state.update(...t)];this.dispatchTransactions(n,this)}update(t){if(this.updateState!=0)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let n=!1,r=!1,s,a=this.state;for(let m of t){if(m.startState!=a)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");a=m.state}if(this.destroyed){this.viewState.state=a;return}let o=this.hasFocus,l=0,c=null;t.some(m=>m.annotation(yye))?(this.inputState.notifiedFocused=o,l=1):o!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=o,c=vye(a,o),c||(l=1));let u=this.observer.delayedAndroidKey,d=null;if(u?(this.observer.clearDelayedAndroidKey(),d=this.observer.readChange(),(d&&!this.state.doc.eq(a.doc)||!this.state.selection.eq(a.selection))&&(d=null)):this.observer.clear(),a.facet(Ur.phrases)!=this.state.facet(Ur.phrases))return this.setState(a);s=EE.create(this,a,t),s.flags|=l;let h=this.viewState.scrollTarget;try{this.updateState=2;for(let m of t){if(h&&(h=h.map(m.changes)),m.scrollIntoView){let{main:g}=m.state.selection;h=new G0(g.empty?g:xt.cursor(g.head,g.head>g.anchor?-1:1))}for(let g of m.effects)g.is(m_)&&(h=g.value.clip(this.state))}this.viewState.update(s,h),this.bidiCache=OE.update(this.bidiCache,s.changes),s.empty||(this.updatePlugins(s),this.inputState.update(s)),n=this.docView.update(s),this.state.facet(Wk)!=this.styleModules&&this.mountStyles(),r=this.updateAttrs(),this.showAnnouncements(t),this.docView.updateSelection(n,t.some(m=>m.isUserEvent("select.pointer")))}finally{this.updateState=0}if(s.startState.facet(v_)!=s.state.facet(v_)&&(this.viewState.mustMeasureContent=!0),(n||r||h||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),n&&this.docViewUpdate(),!s.empty)for(let m of this.state.facet(Y6))try{m(s)}catch(g){Ul(this.state,g,"update listener")}(c||d)&&Promise.resolve().then(()=>{c&&this.state==c.startState&&this.dispatch(c),d&&!fye(this,d)&&u.force&&W0(this.contentDOM,u.key,u.keyCode)})}setState(t){if(this.updateState!=0)throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");if(this.destroyed){this.viewState.state=t;return}this.updateState=2;let n=this.hasFocus;try{for(let r of this.plugins)r.destroy(this);this.viewState=new XZ(this,t),this.plugins=t.facet(R0).map(r=>new JO(r)),this.pluginMap.clear();for(let r of this.plugins)r.update(this);this.docView.destroy(),this.docView=new zZ(this),this.inputState.ensureHandlers(this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}n&&this.focus(),this.requestMeasure()}updatePlugins(t){let n=t.startState.facet(R0),r=t.state.facet(R0);if(n!=r){let s=[];for(let a of r){let o=n.indexOf(a);if(o<0)s.push(new JO(a));else{let l=this.plugins[o];l.mustUpdate=t,s.push(l)}}for(let a of this.plugins)a.mustUpdate!=t&&a.destroy(this);this.plugins=s,this.pluginMap.clear()}else for(let s of this.plugins)s.mustUpdate=t;for(let s=0;s<this.plugins.length;s++)this.plugins[s].update(this);n!=r&&this.inputState.ensureHandlers(this.plugins)}docViewUpdate(){for(let t of this.plugins){let n=t.value;if(n&&n.docViewUpdate)try{n.docViewUpdate(this)}catch(r){Ul(this.state,r,"doc view update listener")}}}measure(t=!0){if(this.destroyed)return;if(this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.observer.delayedAndroidKey){this.measureScheduled=-1,this.requestMeasure();return}this.measureScheduled=0,t&&this.observer.forceFlush();let n=null,r=this.viewState.scrollParent,s=this.viewState.getScrollOffset(),{scrollAnchorPos:a,scrollAnchorHeight:o}=this.viewState;Math.abs(s-this.viewState.scrollOffset)>1&&(o=-1),this.viewState.scrollAnchorHeight=-1;try{for(let l=0;;l++){if(o<0)if(zbe(r||this.win))a=-1,o=this.viewState.heightMap.height;else{let g=this.viewState.scrollAnchorAt(s);a=g.from,o=g.top}this.updateState=1;let c=this.viewState.measure();if(!c&&!this.measureRequests.length&&this.viewState.scrollTarget==null)break;if(l>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let u=[];c&4||([this.measureRequests,u]=[u,this.measureRequests]);let d=u.map(g=>{try{return g.read(this)}catch(b){return Ul(this.state,b),sX}}),h=EE.create(this,this.state,[]),m=!1;h.flags|=c,n?n.flags|=c:n=h,this.updateState=2,h.empty||(this.updatePlugins(h),this.inputState.update(h),this.updateAttrs(),m=this.docView.update(h),m&&this.docViewUpdate());for(let g=0;g<u.length;g++)if(d[g]!=sX)try{let b=u[g];b.write&&b.write(d[g],this)}catch(b){Ul(this.state,b)}if(m&&this.docView.updateSelection(!0),!h.viewportChanged&&this.measureRequests.length==0){if(this.viewState.editorHeight)if(this.viewState.scrollTarget){this.docView.scrollIntoView(this.viewState.scrollTarget),this.viewState.scrollTarget=null,o=-1;continue}else{let b=((a<0?this.viewState.heightMap.height:this.viewState.lineBlockAt(a).top)-o)/this.scaleY;if((b>1||b<-1)&&(r==this.scrollDOM||this.hasFocus||Math.max(this.inputState.lastWheelEvent,this.inputState.lastTouchTime)>Date.now()-100)){s=s+b,r?r.scrollTop+=b:this.win.scrollBy(0,b),o=-1;continue}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(n&&!n.empty)for(let l of this.state.facet(Y6))l(n)}get themeClasses(){return n$+" "+(this.state.facet(t$)?Nye:jye)+" "+this.state.facet(v_)}updateAttrs(){let t=iX(this,sye,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),n={spellcheck:"false",autocorrect:"off",autocapitalize:"off",writingsuggestions:"false",translate:"no",contenteditable:this.state.facet(Sh)?"true":"false",class:"cm-content",style:`${Qt.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(n["aria-readonly"]="true"),iX(this,MB,n);let r=this.observer.ignore(()=>{let s=OZ(this.contentDOM,this.contentAttrs,n),a=OZ(this.dom,this.editorAttrs,t);return s||a});return this.editorAttrs=t,this.contentAttrs=n,r}showAnnouncements(t){let n=!0;for(let r of t)for(let s of r.effects)if(s.is(Yt.announce)){n&&(this.announceDOM.textContent=""),n=!1;let a=this.announceDOM.appendChild(document.createElement("div"));a.textContent=s.value}}mountStyles(){this.styleModules=this.state.facet(Wk);let t=this.state.facet(Yt.cspNonce);vg.mount(this.root,this.styleModules.concat(Xnt).reverse(),t?{nonce:t}:void 0)}readMeasured(){if(this.updateState==2)throw new Error("Reading the editor layout isn't allowed during an update");this.updateState==0&&this.measureScheduled>-1&&this.measure(!1)}requestMeasure(t){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame(()=>this.measure())),t){if(this.measureRequests.indexOf(t)>-1)return;if(t.key!=null){for(let n=0;n<this.measureRequests.length;n++)if(this.measureRequests[n].key===t.key){this.measureRequests[n]=t;return}}this.measureRequests.push(t)}}plugin(t){let n=this.pluginMap.get(t);return(n===void 0||n&&n.plugin!=t)&&this.pluginMap.set(t,n=this.plugins.find(r=>r.plugin==t)||null),n&&n.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}get scaleX(){return this.viewState.scaleX}get scaleY(){return this.viewState.scaleY}elementAtHeight(t){return this.readMeasured(),this.viewState.elementAtHeight(t)}lineBlockAtHeight(t){return this.readMeasured(),this.viewState.lineBlockAtHeight(t)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(t){return this.viewState.lineBlockAt(t)}get contentHeight(){return this.viewState.contentHeight}moveByChar(t,n,r){return tD(this,t,BZ(this,t,n,r))}moveByGroup(t,n){return tD(this,t,BZ(this,t,n,r=>mnt(this,t.head,r)))}visualLineSide(t,n){let r=this.bidiSpans(t),s=this.textDirectionAt(t.from),a=r[n?r.length-1:0];return xt.cursor(a.side(n,s)+t.from,a.forward(!n,s)?1:-1)}moveToLineBoundary(t,n,r=!0){return hnt(this,t,n,r)}moveVertically(t,n,r){return tD(this,t,pnt(this,t,n,r))}domAtPos(t,n=1){return this.docView.domAtPos(t,n)}posAtDOM(t,n=0){return this.docView.posFromDOM(t,n)}posAtCoords(t,n=!0){this.readMeasured();let r=X6(this,t,n);return r&&r.pos}posAndSideAtCoords(t,n=!0){return this.readMeasured(),X6(this,t,n)}coordsAtPos(t,n=1){this.readMeasured();let r=this.docView.coordsAt(t,n);if(!r||r.left==r.right)return r;let s=this.state.doc.lineAt(t),a=this.bidiSpans(s),o=a[lf.find(a,t-s.from,-1,n)];return AE(r,o.dir==Fs.LTR==n>0)}coordsForChar(t){return this.readMeasured(),this.docView.coordsForChar(t)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.defaultTextDirection}textDirectionAt(t){return!this.state.facet(eye)||t<this.viewport.from||t>this.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(t))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(t){if(t.length>srt)return Kbe(t.length);let n=this.textDirectionAt(t.from),r;for(let a of this.bidiCache)if(a.from==t.from&&a.dir==n&&(a.fresh||Hbe(a.isolates,r=LZ(this,t))))return a.order;r||(r=LZ(this,t));let s=ztt(t.text,n,r);return this.bidiCache.push(new OE(t.from,t.to,n,r,!0,s)),s}get hasFocus(){var t;return(this.dom.ownerDocument.hasFocus()||Qt.safari&&((t=this.inputState)===null||t===void 0?void 0:t.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{Fbe(this.contentDOM),this.docView.updateSelection()})}setRoot(t){this._root!=t&&(this._root=t,this.observer.setWindow((t.nodeType==9?t:t.ownerDocument).defaultView||window),this.mountStyles())}destroy(){this.root.activeElement==this.contentDOM&&this.contentDOM.blur();for(let t of this.plugins)t.destroy(this);this.plugins=[],this.inputState.destroy(),this.docView.destroy(),this.dom.remove(),this.observer.destroy(),this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(t,n={}){return m_.of(new G0(typeof t=="number"?xt.cursor(t):t,n.y,n.x,n.yMargin,n.xMargin))}scrollSnapshot(){let{scrollTop:t,scrollLeft:n}=this.scrollDOM,r=this.viewState.scrollAnchorAt(t);return m_.of(new G0(xt.cursor(r.from),"start","start",r.top-t,n,!0))}setTabFocusMode(t){t==null?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:typeof t=="boolean"?this.inputState.tabFocusMode=t?0:-1:this.inputState.tabFocusMode!=0&&(this.inputState.tabFocusMode=Date.now()+t)}static domEventHandlers(t){return Vi.define(()=>({}),{eventHandlers:t})}static domEventObservers(t){return Vi.define(()=>({}),{eventObservers:t})}static theme(t,n){let r=vg.newName(),s=[v_.of(r),Wk.of(r$(`.${r}`,t))];return n&&n.dark&&s.push(t$.of(!0)),s}static baseTheme(t){return Bg.lowest(Wk.of(r$("."+n$,t,Cye)))}static findFromDOM(t){var n;let r=t.querySelector(".cm-content"),s=r&&Mi.get(r)||Mi.get(t);return((n=s==null?void 0:s.root)===null||n===void 0?void 0:n.view)||null}}Yt.styleModule=Wk;Yt.inputHandler=Zbe;Yt.clipboardInputFilter=IB;Yt.clipboardOutputFilter=RB;Yt.scrollHandler=nye;Yt.focusChangeEffect=Xbe;Yt.perLineTextDirection=eye;Yt.exceptionSink=Jbe;Yt.updateListener=Y6;Yt.editable=Sh;Yt.mouseSelectionStyle=Ybe;Yt.dragMovesSelection=Qbe;Yt.clickAddsSelectionRange=Gbe;Yt.decorations=AI;Yt.blockWrappers=iye;Yt.outerDecorations=OB;Yt.atomicRanges=WC;Yt.bidiIsolatedRanges=aye;Yt.scrollMargins=oye;Yt.darkTheme=t$;Yt.cspNonce=Zt.define({combine:e=>e.length?e[0]:""});Yt.contentAttributes=MB;Yt.editorAttributes=sye;Yt.lineWrapping=Yt.contentAttributes.of({class:"cm-lineWrapping"});Yt.announce=Yn.define();const srt=4096,sX={};class OE{constructor(t,n,r,s,a,o){this.from=t,this.to=n,this.dir=r,this.isolates=s,this.fresh=a,this.order=o}static update(t,n){if(n.empty&&!t.some(a=>a.fresh))return t;let r=[],s=t.length?t[t.length-1].dir:Fs.LTR;for(let a=Math.max(0,t.length-10);a<t.length;a++){let o=t[a];o.dir==s&&!n.touchesRange(o.from,o.to)&&r.push(new OE(n.mapPos(o.from,1),n.mapPos(o.to,-1),o.dir,o.isolates,!1,o.order))}return r}}function iX(e,t,n){for(let r=e.state.facet(t),s=r.length-1;s>=0;s--){let a=r[s],o=typeof a=="function"?a(e):a;o&&AB(o,n)}return n}const irt=Qt.mac?"mac":Qt.windows?"win":Qt.linux?"linux":"key";function art(e,t){const n=e.split(/-(?!$)/);let r=n[n.length-1];r=="Space"&&(r=" ");let s,a,o,l;for(let c=0;c<n.length-1;++c){const u=n[c];if(/^(cmd|meta|m)$/i.test(u))l=!0;else if(/^a(lt)?$/i.test(u))s=!0;else if(/^(c|ctrl|control)$/i.test(u))a=!0;else if(/^s(hift)?$/i.test(u))o=!0;else if(/^mod$/i.test(u))t=="mac"?l=!0:a=!0;else throw new Error("Unrecognized modifier name: "+u)}return s&&(r="Alt-"+r),a&&(r="Ctrl-"+r),l&&(r="Meta-"+r),o&&(r="Shift-"+r),r}function w_(e,t,n){return t.altKey&&(e="Alt-"+e),t.ctrlKey&&(e="Ctrl-"+e),t.metaKey&&(e="Meta-"+e),n!==!1&&t.shiftKey&&(e="Shift-"+e),e}const ort=Bg.default(Yt.domEventHandlers({keydown(e,t){return _ye(Sye(t.state),e,t,"editor")}})),GC=Zt.define({enables:ort}),aX=new WeakMap;function Sye(e){let t=e.facet(GC),n=aX.get(t);return n||aX.set(t,n=urt(t.reduce((r,s)=>r.concat(s),[]))),n}function lrt(e,t,n){return _ye(Sye(e.state),t,e,n)}let dp=null;const crt=4e3;function urt(e,t=irt){let n=Object.create(null),r=Object.create(null),s=(o,l)=>{let c=r[o];if(c==null)r[o]=l;else if(c!=l)throw new Error("Key binding "+o+" is used both as a regular binding and as a multi-stroke prefix")},a=(o,l,c,u,d)=>{var h,m;let g=n[o]||(n[o]=Object.create(null)),b=l.split(/ (?!$)/).map(k=>art(k,t));for(let k=1;k<b.length;k++){let w=b.slice(0,k).join(" ");s(w,!0),g[w]||(g[w]={preventDefault:!0,stopPropagation:!1,run:[N=>{let S=dp={view:N,prefix:w,scope:o};return setTimeout(()=>{dp==S&&(dp=null)},crt),!0}]})}let v=b.join(" ");s(v,!1);let j=g[v]||(g[v]={preventDefault:!1,stopPropagation:!1,run:((m=(h=g._any)===null||h===void 0?void 0:h.run)===null||m===void 0?void 0:m.slice())||[]});c&&j.run.push(c),u&&(j.preventDefault=!0),d&&(j.stopPropagation=!0)};for(let o of e){let l=o.scope?o.scope.split(" "):["editor"];if(o.any)for(let u of l){let d=n[u]||(n[u]=Object.create(null));d._any||(d._any={preventDefault:!1,stopPropagation:!1,run:[]});let{any:h}=o;for(let m in d)d[m].run.push(g=>h(g,s$))}let c=o[t]||o.key;if(c)for(let u of l)a(u,c,o.run,o.preventDefault,o.stopPropagation),o.shift&&a(u,"Shift-"+c,o.shift,o.preventDefault,o.stopPropagation)}return n}let s$=null;function _ye(e,t,n,r){s$=t;let s=Ntt(t),a=Fl(s,0),o=ef(a)==s.length&&s!=" ",l="",c=!1,u=!1,d=!1;dp&&dp.view==n&&dp.scope==r&&(l=dp.prefix+" ",pye.indexOf(t.keyCode)<0&&(u=!0,dp=null));let h=new Set,m=j=>{if(j){for(let k of j.run)if(!h.has(k)&&(h.add(k),k(n)))return j.stopPropagation&&(d=!0),!0;j.preventDefault&&(j.stopPropagation&&(d=!0),u=!0)}return!1},g=e[r],b,v;return g&&(m(g[l+w_(s,t,!o)])?c=!0:o&&(t.altKey||t.metaKey||t.ctrlKey)&&!(Qt.windows&&t.ctrlKey&&t.altKey)&&!(Qt.mac&&t.altKey&&!(t.ctrlKey||t.metaKey))&&(b=wg[t.keyCode])&&b!=s?(m(g[l+w_(b,t,!0)])||t.shiftKey&&(v=SN[t.keyCode])!=s&&v!=b&&m(g[l+w_(v,t,!1)]))&&(c=!0):o&&t.shiftKey&&m(g[l+w_(s,t,!0)])&&(c=!0),!c&&m(g._any)&&(c=!0)),u&&(c=!0),c&&d&&t.stopPropagation(),s$=null,c}class ab{constructor(t,n,r,s,a){this.className=t,this.left=n,this.top=r,this.width=s,this.height=a}draw(){let t=document.createElement("div");return t.className=this.className,this.adjust(t),t}update(t,n){return n.className!=this.className?!1:(this.adjust(t),!0)}adjust(t){t.style.left=this.left+"px",t.style.top=this.top+"px",this.width!=null&&(t.style.width=this.width+"px"),t.style.height=this.height+"px"}eq(t){return this.left==t.left&&this.top==t.top&&this.width==t.width&&this.height==t.height&&this.className==t.className}static forRange(t,n,r){if(r.empty){let s=t.coordsAtPos(r.head,r.assoc||1);if(!s)return[];let a=Aye(t);return[new ab(n,s.left-a.left,s.top-a.top,null,s.bottom-s.top)]}else return drt(t,n,r)}}function Aye(e){let t=e.scrollDOM.getBoundingClientRect();return{left:(e.textDirection==Fs.LTR?t.left:t.right-e.scrollDOM.clientWidth*e.scaleX)-e.scrollDOM.scrollLeft*e.scaleX,top:t.top-e.scrollDOM.scrollTop*e.scaleY}}function oX(e,t,n,r){let s=e.coordsAtPos(t,n*2);if(!s)return r;let a=e.dom.getBoundingClientRect(),o=(s.top+s.bottom)/2,l=e.posAtCoords({x:a.left+1,y:o}),c=e.posAtCoords({x:a.right-1,y:o});return l==null||c==null?r:{from:Math.max(r.from,Math.min(l,c)),to:Math.min(r.to,Math.max(l,c))}}function drt(e,t,n){if(n.to<=e.viewport.from||n.from>=e.viewport.to)return[];let r=Math.max(n.from,e.viewport.from),s=Math.min(n.to,e.viewport.to),a=e.textDirection==Fs.LTR,o=e.contentDOM,l=o.getBoundingClientRect(),c=Aye(e),u=o.querySelector(".cm-line"),d=u&&window.getComputedStyle(u),h=l.left+(d?parseInt(d.paddingLeft)+Math.min(0,parseInt(d.textIndent)):0),m=l.right-(d?parseInt(d.paddingRight):0),g=Z6(e,r,1),b=Z6(e,s,-1),v=g.type==go.Text?g:null,j=b.type==go.Text?b:null;if(v&&(e.lineWrapping||g.widgetLineBreaks)&&(v=oX(e,r,1,v)),j&&(e.lineWrapping||b.widgetLineBreaks)&&(j=oX(e,s,-1,j)),v&&j&&v.from==j.from&&v.to==j.to)return w(N(n.from,n.to,v));{let A=v?N(n.from,null,v):S(g,!1),_=j?N(null,n.to,j):S(b,!0),E=[];return(v||g).to<(j||b).from-(v&&j?1:0)||g.widgetLineBreaks>1&&A.bottom+e.defaultLineHeight/2<_.top?E.push(k(h,A.bottom,m,_.top)):A.bottom<_.top&&e.elementAtHeight((A.bottom+_.top)/2).type==go.Text&&(A.bottom=_.top=(A.bottom+_.top)/2),w(A).concat(E).concat(w(_))}function k(A,_,E,I){return new ab(t,A-c.left,_-c.top,Math.max(0,E-A),I-_)}function w({top:A,bottom:_,horizontal:E}){let I=[];for(let O=0;O<E.length;O+=2)I.push(k(E[O],A,E[O+1],_));return I}function N(A,_,E){let I=1e9,O=-1e9,M=[];function D(K,J,$,L,H){let W=e.coordsAtPos(K,K==E.to?-2:2),B=e.coordsAtPos($,$==E.from?2:-2);!W||!B||(I=Math.min(W.top,B.top,I),O=Math.max(W.bottom,B.bottom,O),H==Fs.LTR?M.push(a&&J?h:W.left,a&&L?m:B.right):M.push(!a&&L?h:B.left,!a&&J?m:W.right))}let z=A??E.from,F=_??E.to;for(let K of e.visibleRanges)if(K.to>z&&K.from<F)for(let J=Math.max(K.from,z),$=Math.min(K.to,F);;){let L=e.state.doc.lineAt(J);for(let H of e.bidiSpans(L)){let W=H.from+L.from,B=H.to+L.from;if(W>=$)break;B>J&&D(Math.max(W,J),A==null&&W<=z,Math.min(B,$),_==null&&B>=F,H.dir)}if(J=L.to+1,J>=$)break}return M.length==0&&D(z,A==null,F,_==null,e.textDirection),{top:I,bottom:O,horizontal:M}}function S(A,_){let E=l.top+(_?A.top:A.bottom);return{top:E,bottom:E,horizontal:[]}}}function frt(e,t){return e.constructor==t.constructor&&e.eq(t)}class hrt{constructor(t,n){this.view=t,this.layer=n,this.drawn=[],this.scaleX=1,this.scaleY=1,this.measureReq={read:this.measure.bind(this),write:this.draw.bind(this)},this.dom=t.scrollDOM.appendChild(document.createElement("div")),this.dom.classList.add("cm-layer"),n.above&&this.dom.classList.add("cm-layer-above"),n.class&&this.dom.classList.add(n.class),this.scale(),this.dom.setAttribute("aria-hidden","true"),this.setOrder(t.state),t.requestMeasure(this.measureReq),n.mount&&n.mount(this.dom,t)}update(t){t.startState.facet(K5)!=t.state.facet(K5)&&this.setOrder(t.state),(this.layer.update(t,this.dom)||t.geometryChanged)&&(this.scale(),t.view.requestMeasure(this.measureReq))}docViewUpdate(t){this.layer.updateOnDocViewUpdate!==!1&&t.requestMeasure(this.measureReq)}setOrder(t){let n=0,r=t.facet(K5);for(;n<r.length&&r[n]!=this.layer;)n++;this.dom.style.zIndex=String((this.layer.above?150:-1)-n)}measure(){return this.layer.markers(this.view)}scale(){let{scaleX:t,scaleY:n}=this.view;(t!=this.scaleX||n!=this.scaleY)&&(this.scaleX=t,this.scaleY=n,this.dom.style.transform=`scale(${1/t}, ${1/n})`)}draw(t){if(t.length!=this.drawn.length||t.some((n,r)=>!frt(n,this.drawn[r]))){let n=this.dom.firstChild,r=0;for(let s of t)s.update&&n&&s.constructor&&this.drawn[r].constructor&&s.update(n,this.drawn[r])?(n=n.nextSibling,r++):this.dom.insertBefore(s.draw(),n);for(;n;){let s=n.nextSibling;n.remove(),n=s}this.drawn=t,Qt.safari&&Qt.safari_version>=26&&(this.dom.style.display=this.dom.firstChild?"":"none")}}destroy(){this.layer.destroy&&this.layer.destroy(this.dom,this.view),this.dom.remove()}}const K5=Zt.define();function Eye(e){return[Vi.define(t=>new hrt(t,e)),K5.of(e)]}const Wv=Zt.define({combine(e){return Pf(e,{cursorBlinkRate:1200,drawRangeCursor:!0,iosSelectionHandles:!0},{cursorBlinkRate:(t,n)=>Math.min(t,n),drawRangeCursor:(t,n)=>t||n})}});function mrt(e={}){return[Wv.of(e),prt,grt,xrt,tye.of(!0)]}function Tye(e){return e.startState.facet(Wv)!=e.state.facet(Wv)}const prt=Eye({above:!0,markers(e){let{state:t}=e,n=t.facet(Wv),r=[];for(let s of t.selection.ranges){let a=s==t.selection.main;if(s.empty||n.drawRangeCursor&&!(a&&Qt.ios&&n.iosSelectionHandles)){let o=a?"cm-cursor cm-cursor-primary":"cm-cursor cm-cursor-secondary",l=s.empty?s:xt.cursor(s.head,s.assoc);for(let c of ab.forRange(e,o,l))r.push(c)}}return r},update(e,t){e.transactions.some(r=>r.selection)&&(t.style.animationName=t.style.animationName=="cm-blink"?"cm-blink2":"cm-blink");let n=Tye(e);return n&&lX(e.state,t),e.docChanged||e.selectionSet||n},mount(e,t){lX(t.state,e)},class:"cm-cursorLayer"});function lX(e,t){t.style.animationDuration=e.facet(Wv).cursorBlinkRate+"ms"}const grt=Eye({above:!1,markers(e){let t=[],{main:n,ranges:r}=e.state.selection;for(let s of r)if(!s.empty)for(let a of ab.forRange(e,"cm-selectionBackground",s))t.push(a);if(Qt.ios&&!n.empty&&e.state.facet(Wv).iosSelectionHandles){for(let s of ab.forRange(e,"cm-selectionHandle cm-selectionHandle-start",xt.cursor(n.from,1)))t.push(s);for(let s of ab.forRange(e,"cm-selectionHandle cm-selectionHandle-end",xt.cursor(n.to,1)))t.push(s)}return t},update(e,t){return e.docChanged||e.selectionSet||e.viewportChanged||Tye(e)},class:"cm-selectionLayer"}),xrt=Bg.highest(Yt.theme({".cm-line":{"& ::selection, &::selection":{backgroundColor:"transparent !important"},caretColor:"transparent !important"},".cm-content":{caretColor:"transparent !important","& :focus":{caretColor:"initial !important","&::selection, & ::selection":{backgroundColor:"Highlight !important"}}}})),Iye=Yn.define({map(e,t){return e==null?null:t.mapPos(e)}}),Qk=ko.define({create(){return null},update(e,t){return e!=null&&(e=t.changes.mapPos(e)),t.effects.reduce((n,r)=>r.is(Iye)?r.value:n,e)}}),brt=Vi.fromClass(class{constructor(e){this.view=e,this.cursor=null,this.measureReq={read:this.readPos.bind(this),write:this.drawCursor.bind(this)}}update(e){var t;let n=e.state.field(Qk);n==null?this.cursor!=null&&((t=this.cursor)===null||t===void 0||t.remove(),this.cursor=null):(this.cursor||(this.cursor=this.view.scrollDOM.appendChild(document.createElement("div")),this.cursor.className="cm-dropCursor"),(e.startState.field(Qk)!=n||e.docChanged||e.geometryChanged)&&this.view.requestMeasure(this.measureReq))}readPos(){let{view:e}=this,t=e.state.field(Qk),n=t!=null&&e.coordsAtPos(t);if(!n)return null;let r=e.scrollDOM.getBoundingClientRect();return{left:n.left-r.left+e.scrollDOM.scrollLeft*e.scaleX,top:n.top-r.top+e.scrollDOM.scrollTop*e.scaleY,height:n.bottom-n.top}}drawCursor(e){if(this.cursor){let{scaleX:t,scaleY:n}=this.view;e?(this.cursor.style.left=e.left/t+"px",this.cursor.style.top=e.top/n+"px",this.cursor.style.height=e.height/n+"px"):this.cursor.style.left="-100000px"}}destroy(){this.cursor&&this.cursor.remove()}setDropPos(e){this.view.state.field(Qk)!=e&&this.view.dispatch({effects:Iye.of(e)})}},{eventObservers:{dragover(e){this.setDropPos(this.view.posAtCoords({x:e.clientX,y:e.clientY}))},dragleave(e){(e.target==this.view.contentDOM||!this.view.contentDOM.contains(e.relatedTarget))&&this.setDropPos(null)},dragend(){this.setDropPos(null)},drop(){this.setDropPos(null)}}});function yrt(){return[Qk,brt]}function cX(e,t,n,r,s){t.lastIndex=0;for(let a=e.iterRange(n,r),o=n,l;!a.next().done;o+=a.value.length)if(!a.lineBreak)for(;l=t.exec(a.value);)s(o+l.index,l)}function vrt(e,t){let n=e.visibleRanges;if(n.length==1&&n[0].from==e.viewport.from&&n[0].to==e.viewport.to)return n;let r=[];for(let{from:s,to:a}of n)s=Math.max(e.state.doc.lineAt(s).from,s-t),a=Math.min(e.state.doc.lineAt(a).to,a+t),r.length&&r[r.length-1].to>=s?r[r.length-1].to=a:r.push({from:s,to:a});return r}class wrt{constructor(t){const{regexp:n,decoration:r,decorate:s,boundary:a,maxLength:o=1e3}=t;if(!n.global)throw new RangeError("The regular expression given to MatchDecorator should have its 'g' flag set");if(this.regexp=n,s)this.addMatch=(l,c,u,d)=>s(d,u,u+l[0].length,l,c);else if(typeof r=="function")this.addMatch=(l,c,u,d)=>{let h=r(l,c,u);h&&d(u,u+l[0].length,h)};else if(r)this.addMatch=(l,c,u,d)=>d(u,u+l[0].length,r);else throw new RangeError("Either 'decorate' or 'decoration' should be provided to MatchDecorator");this.boundary=a,this.maxLength=o}createDeco(t){let n=new tm,r=n.add.bind(n);for(let{from:s,to:a}of vrt(t,this.maxLength))cX(t.state.doc,this.regexp,s,a,(o,l)=>this.addMatch(l,t,o,r));return n.finish()}updateDeco(t,n){let r=1e9,s=-1;return t.docChanged&&t.changes.iterChanges((a,o,l,c)=>{c>=t.view.viewport.from&&l<=t.view.viewport.to&&(r=Math.min(l,r),s=Math.max(c,s))}),t.viewportMoved||s-r>1e3?this.createDeco(t.view):s>-1?this.updateRange(t.view,n.map(t.changes),r,s):n}updateRange(t,n,r,s){for(let a of t.visibleRanges){let o=Math.max(a.from,r),l=Math.min(a.to,s);if(l>=o){let c=t.state.doc.lineAt(o),u=c.to<l?t.state.doc.lineAt(l):c,d=Math.max(a.from,c.from),h=Math.min(a.to,u.to);if(this.boundary){for(;o>c.from;o--)if(this.boundary.test(c.text[o-1-c.from])){d=o;break}for(;l<u.to;l++)if(this.boundary.test(u.text[l-u.from])){h=l;break}}let m=[],g,b=(v,j,k)=>m.push(k.range(v,j));if(c==u)for(this.regexp.lastIndex=d-c.from;(g=this.regexp.exec(c.text))&&g.index<h-c.from;)this.addMatch(g,t,g.index+c.from,b);else cX(t.state.doc,this.regexp,d,h,(v,j)=>this.addMatch(j,t,v,b));n=n.update({filterFrom:d,filterTo:h,filter:(v,j)=>v<d||j>h,add:m})}}return n}}const i$=/x/.unicode!=null?"gu":"g",krt=new RegExp(`[\0-\b
1280
1280
  --Ÿ­؜​‎‏\u2028\u2029‭‮⁦⁧⁩\uFEFF-]`,i$),jrt={0:"null",7:"bell",8:"backspace",10:"newline",11:"vertical tab",13:"carriage return",27:"escape",8203:"zero width space",8204:"zero width non-joiner",8205:"zero width joiner",8206:"left-to-right mark",8207:"right-to-left mark",8232:"line separator",8237:"left-to-right override",8238:"right-to-left override",8294:"left-to-right isolate",8295:"right-to-left isolate",8297:"pop directional isolate",8233:"paragraph separator",65279:"zero width no-break space",65532:"object replacement"};let sD=null;function Nrt(){var e;if(sD==null&&typeof document<"u"&&document.body){let t=document.body.style;sD=((e=t.tabSize)!==null&&e!==void 0?e:t.MozTabSize)!=null}return sD||!1}const W5=Zt.define({combine(e){let t=Pf(e,{render:null,specialChars:krt,addSpecialChars:null});return(t.replaceTabs=!Nrt())&&(t.specialChars=new RegExp(" |"+t.specialChars.source,i$)),t.addSpecialChars&&(t.specialChars=new RegExp(t.specialChars.source+"|"+t.addSpecialChars.source,i$)),t}});function Crt(e={}){return[W5.of(e),Srt()]}let uX=null;function Srt(){return uX||(uX=Vi.fromClass(class{constructor(e){this.view=e,this.decorations=En.none,this.decorationCache=Object.create(null),this.decorator=this.makeDecorator(e.state.facet(W5)),this.decorations=this.decorator.createDeco(e)}makeDecorator(e){return new wrt({regexp:e.specialChars,decoration:(t,n,r)=>{let{doc:s}=n.state,a=Fl(t[0],0);if(a==9){let o=s.lineAt(r),l=n.state.tabSize,c=U1(o.text,l,r-o.from);return En.replace({widget:new Trt((l-c%l)*this.view.defaultCharacterWidth/this.view.scaleX)})}return this.decorationCache[a]||(this.decorationCache[a]=En.replace({widget:new Ert(e,a)}))},boundary:e.replaceTabs?void 0:/[^]/})}update(e){let t=e.state.facet(W5);e.startState.facet(W5)!=t?(this.decorator=this.makeDecorator(t),this.decorations=this.decorator.createDeco(e.view)):this.decorations=this.decorator.updateDeco(e,this.decorations)}},{decorations:e=>e.decorations}))}const _rt="•";function Art(e){return e>=32?_rt:e==10?"␤":String.fromCharCode(9216+e)}class Ert extends Lf{constructor(t,n){super(),this.options=t,this.code=n}eq(t){return t.code==this.code}toDOM(t){let n=Art(this.code),r=t.state.phrase("Control character")+" "+(jrt[this.code]||"0x"+this.code.toString(16)),s=this.options.render&&this.options.render(this.code,r,n);if(s)return s;let a=document.createElement("span");return a.textContent=n,a.title=r,a.setAttribute("aria-label",r),a.className="cm-specialChar",a}ignoreEvent(){return!1}}class Trt extends Lf{constructor(t){super(),this.width=t}eq(t){return t.width==this.width}toDOM(){let t=document.createElement("span");return t.textContent=" ",t.className="cm-tab",t.style.width=this.width+"px",t}ignoreEvent(){return!1}}function Irt(){return Mrt}const Rrt=En.line({class:"cm-activeLine"}),Mrt=Vi.fromClass(class{constructor(e){this.decorations=this.getDeco(e)}update(e){(e.docChanged||e.selectionSet)&&(this.decorations=this.getDeco(e.view))}getDeco(e){let t=-1,n=[];for(let r of e.state.selection.ranges){let s=e.lineBlockAt(r.head);s.from>t&&(n.push(Rrt.range(s.from)),t=s.from)}return En.set(n)}},{decorations:e=>e.decorations}),a$=2e3;function Ort(e,t,n){let r=Math.min(t.line,n.line),s=Math.max(t.line,n.line),a=[];if(t.off>a$||n.off>a$||t.col<0||n.col<0){let o=Math.min(t.off,n.off),l=Math.max(t.off,n.off);for(let c=r;c<=s;c++){let u=e.doc.line(c);u.length<=l&&a.push(xt.range(u.from+o,u.to+l))}}else{let o=Math.min(t.col,n.col),l=Math.max(t.col,n.col);for(let c=r;c<=s;c++){let u=e.doc.line(c),d=F6(u.text,o,e.tabSize,!0);if(d<0)a.push(xt.cursor(u.to));else{let h=F6(u.text,l,e.tabSize);a.push(xt.range(u.from+d,u.from+h))}}}return a}function Drt(e,t){let n=e.coordsAtPos(e.viewport.from);return n?Math.round(Math.abs((n.left-t)/e.defaultCharacterWidth)):-1}function dX(e,t){let n=e.posAtCoords({x:t.clientX,y:t.clientY},!1),r=e.state.doc.lineAt(n),s=n-r.from,a=s>a$?-1:s==r.length?Drt(e,t.clientX):U1(r.text,e.state.tabSize,n-r.from);return{line:r.number,col:a,off:s}}function Prt(e,t){let n=dX(e,t),r=e.state.selection;return n?{update(s){if(s.docChanged){let a=s.changes.mapPos(s.startState.doc.line(n.line).from),o=s.state.doc.lineAt(a);n={line:o.number,col:n.col,off:Math.min(n.off,o.length)},r=r.map(s.changes)}},get(s,a,o){let l=dX(e,s);if(!l)return r;let c=Ort(e.state,n,l);return c.length?o?xt.create(c.concat(r.ranges)):xt.create(c):r}}:null}function Lrt(e){let t=(n=>n.altKey&&n.button==0);return Yt.mouseSelectionStyle.of((n,r)=>t(r)?Prt(n,r):null)}const $rt={Alt:[18,e=>!!e.altKey],Control:[17,e=>!!e.ctrlKey],Shift:[16,e=>!!e.shiftKey],Meta:[91,e=>!!e.metaKey]},Frt={style:"cursor: crosshair"};function zrt(e={}){let[t,n]=$rt[e.key||"Alt"],r=Vi.fromClass(class{constructor(s){this.view=s,this.isDown=!1}set(s){this.isDown!=s&&(this.isDown=s,this.view.update([]))}},{eventObservers:{keydown(s){this.set(s.keyCode==t||n(s))},keyup(s){(s.keyCode==t||!n(s))&&this.set(!1)},mousemove(s){this.set(n(s))}}});return[r,Yt.contentAttributes.of(s=>{var a;return!((a=s.plugin(r))===null||a===void 0)&&a.isDown?Frt:null})]}const k_="-10000px";class Rye{constructor(t,n,r,s){this.facet=n,this.createTooltipView=r,this.removeTooltipView=s,this.input=t.state.facet(n),this.tooltips=this.input.filter(o=>o);let a=null;this.tooltipViews=this.tooltips.map(o=>a=r(o,a))}update(t,n){var r;let s=t.state.facet(this.facet),a=s.filter(c=>c);if(s===this.input){for(let c of this.tooltipViews)c.update&&c.update(t);return!1}let o=[],l=n?[]:null;for(let c=0;c<a.length;c++){let u=a[c],d=-1;if(u){for(let h=0;h<this.tooltips.length;h++){let m=this.tooltips[h];m&&m.create==u.create&&(d=h)}if(d<0)o[c]=this.createTooltipView(u,c?o[c-1]:null),l&&(l[c]=!!u.above);else{let h=o[c]=this.tooltipViews[d];l&&(l[c]=n[d]),h.update&&h.update(t)}}}for(let c of this.tooltipViews)o.indexOf(c)<0&&(this.removeTooltipView(c),(r=c.destroy)===null||r===void 0||r.call(c));return n&&(l.forEach((c,u)=>n[u]=c),n.length=l.length),this.input=s,this.tooltips=a,this.tooltipViews=o,!0}}function Brt(e){let t=e.dom.ownerDocument.documentElement;return{top:0,left:0,bottom:t.clientHeight,right:t.clientWidth}}const iD=Zt.define({combine:e=>{var t,n,r;return{position:Qt.ios?"absolute":((t=e.find(s=>s.position))===null||t===void 0?void 0:t.position)||"fixed",parent:((n=e.find(s=>s.parent))===null||n===void 0?void 0:n.parent)||null,tooltipSpace:((r=e.find(s=>s.tooltipSpace))===null||r===void 0?void 0:r.tooltipSpace)||Brt}}}),fX=new WeakMap,FB=Vi.fromClass(class{constructor(e){this.view=e,this.above=[],this.inView=!0,this.madeAbsolute=!1,this.lastTransaction=0,this.measureTimeout=-1;let t=e.state.facet(iD);this.position=t.position,this.parent=t.parent,this.classes=e.themeClasses,this.createContainer(),this.measureReq={read:this.readMeasure.bind(this),write:this.writeMeasure.bind(this),key:this},this.resizeObserver=typeof ResizeObserver=="function"?new ResizeObserver(()=>this.measureSoon()):null,this.manager=new Rye(e,zB,(n,r)=>this.createTooltip(n,r),n=>{this.resizeObserver&&this.resizeObserver.unobserve(n.dom),n.dom.remove()}),this.above=this.manager.tooltips.map(n=>!!n.above),this.intersectionObserver=typeof IntersectionObserver=="function"?new IntersectionObserver(n=>{Date.now()>this.lastTransaction-50&&n.length>0&&n[n.length-1].intersectionRatio<1&&this.measureSoon()},{threshold:[1]}):null,this.observeIntersection(),e.win.addEventListener("resize",this.measureSoon=this.measureSoon.bind(this)),this.maybeMeasure()}createContainer(){this.parent?(this.container=document.createElement("div"),this.container.style.position="relative",this.container.className=this.view.themeClasses,this.parent.appendChild(this.container)):this.container=this.view.dom}observeIntersection(){if(this.intersectionObserver){this.intersectionObserver.disconnect();for(let e of this.manager.tooltipViews)this.intersectionObserver.observe(e.dom)}}measureSoon(){this.measureTimeout<0&&(this.measureTimeout=setTimeout(()=>{this.measureTimeout=-1,this.maybeMeasure()},50))}update(e){e.transactions.length&&(this.lastTransaction=Date.now());let t=this.manager.update(e,this.above);t&&this.observeIntersection();let n=t||e.geometryChanged,r=e.state.facet(iD);if(r.position!=this.position&&!this.madeAbsolute){this.position=r.position;for(let s of this.manager.tooltipViews)s.dom.style.position=this.position;n=!0}if(r.parent!=this.parent){this.parent&&this.container.remove(),this.parent=r.parent,this.createContainer();for(let s of this.manager.tooltipViews)this.container.appendChild(s.dom);n=!0}else this.parent&&this.view.themeClasses!=this.classes&&(this.classes=this.container.className=this.view.themeClasses);n&&this.maybeMeasure()}createTooltip(e,t){let n=e.create(this.view),r=t?t.dom:null;if(n.dom.classList.add("cm-tooltip"),e.arrow&&!n.dom.querySelector(".cm-tooltip > .cm-tooltip-arrow")){let s=document.createElement("div");s.className="cm-tooltip-arrow",n.dom.appendChild(s)}return n.dom.style.position=this.position,n.dom.style.top=k_,n.dom.style.left="0px",this.container.insertBefore(n.dom,r),n.mount&&n.mount(this.view),this.resizeObserver&&this.resizeObserver.observe(n.dom),n}destroy(){var e,t,n;this.view.win.removeEventListener("resize",this.measureSoon);for(let r of this.manager.tooltipViews)r.dom.remove(),(e=r.destroy)===null||e===void 0||e.call(r);this.parent&&this.container.remove(),(t=this.resizeObserver)===null||t===void 0||t.disconnect(),(n=this.intersectionObserver)===null||n===void 0||n.disconnect(),clearTimeout(this.measureTimeout)}readMeasure(){let e=1,t=1,n=!1;if(this.position=="fixed"&&this.manager.tooltipViews.length){let{dom:a}=this.manager.tooltipViews[0];if(Qt.safari){let o=a.getBoundingClientRect();n=Math.abs(o.top+1e4)>1||Math.abs(o.left)>1}else n=!!a.offsetParent&&a.offsetParent!=this.container.ownerDocument.body}if(n||this.position=="absolute")if(this.parent){let a=this.parent.getBoundingClientRect();a.width&&a.height&&(e=a.width/this.parent.offsetWidth,t=a.height/this.parent.offsetHeight)}else({scaleX:e,scaleY:t}=this.view.viewState);let r=this.view.scrollDOM.getBoundingClientRect(),s=DB(this.view);return{visible:{left:r.left+s.left,top:r.top+s.top,right:r.right-s.right,bottom:r.bottom-s.bottom},parent:this.parent?this.container.getBoundingClientRect():this.view.dom.getBoundingClientRect(),pos:this.manager.tooltips.map((a,o)=>{let l=this.manager.tooltipViews[o];return l.getCoords?l.getCoords(a.pos):this.view.coordsAtPos(a.pos)}),size:this.manager.tooltipViews.map(({dom:a})=>a.getBoundingClientRect()),space:this.view.state.facet(iD).tooltipSpace(this.view),scaleX:e,scaleY:t,makeAbsolute:n}}writeMeasure(e){var t;if(e.makeAbsolute){this.madeAbsolute=!0,this.position="absolute";for(let l of this.manager.tooltipViews)l.dom.style.position="absolute"}let{visible:n,space:r,scaleX:s,scaleY:a}=e,o=[];for(let l=0;l<this.manager.tooltips.length;l++){let c=this.manager.tooltips[l],u=this.manager.tooltipViews[l],{dom:d}=u,h=e.pos[l],m=e.size[l];if(!h||c.clip!==!1&&(h.bottom<=Math.max(n.top,r.top)||h.top>=Math.min(n.bottom,r.bottom)||h.right<Math.max(n.left,r.left)-.1||h.left>Math.min(n.right,r.right)+.1)){d.style.top=k_;continue}let g=c.arrow?u.dom.querySelector(".cm-tooltip-arrow"):null,b=g?7:0,v=m.right-m.left,j=(t=fX.get(u))!==null&&t!==void 0?t:m.bottom-m.top,k=u.offset||qrt,w=this.view.textDirection==Fs.LTR,N=m.width>r.right-r.left?w?r.left:r.right-m.width:w?Math.max(r.left,Math.min(h.left-(g?14:0)+k.x,r.right-v)):Math.min(Math.max(r.left,h.left-v+(g?14:0)-k.x),r.right-v),S=this.above[l];!c.strictSide&&(S?h.top-j-b-k.y<r.top:h.bottom+j+b+k.y>r.bottom)&&S==r.bottom-h.bottom>h.top-r.top&&(S=this.above[l]=!S);let A=(S?h.top-r.top:r.bottom-h.bottom)-b;if(A<j&&u.resize!==!1){if(A<this.view.defaultLineHeight){d.style.top=k_;continue}fX.set(u,j),d.style.height=(j=A)/a+"px"}else d.style.height&&(d.style.height="");let _=S?h.top-j-b-k.y:h.bottom+b+k.y,E=N+v;if(u.overlap!==!0)for(let I of o)I.left<E&&I.right>N&&I.top<_+j&&I.bottom>_&&(_=S?I.top-j-2-b:I.bottom+b+2);if(this.position=="absolute"?(d.style.top=(_-e.parent.top)/a+"px",hX(d,(N-e.parent.left)/s)):(d.style.top=_/a+"px",hX(d,N/s)),g){let I=h.left+(w?k.x:-k.x)-(N+14-7);g.style.left=I/s+"px"}u.overlap!==!0&&o.push({left:N,top:_,right:E,bottom:_+j}),d.classList.toggle("cm-tooltip-above",S),d.classList.toggle("cm-tooltip-below",!S),u.positioned&&u.positioned(e.space)}}maybeMeasure(){if(this.manager.tooltips.length&&(this.view.inView&&this.view.requestMeasure(this.measureReq),this.inView!=this.view.inView&&(this.inView=this.view.inView,!this.inView)))for(let e of this.manager.tooltipViews)e.dom.style.top=k_}},{eventObservers:{scroll(){this.maybeMeasure()}}});function hX(e,t){let n=parseInt(e.style.left,10);(isNaN(n)||Math.abs(t-n)>1)&&(e.style.left=t+"px")}const Urt=Yt.baseTheme({".cm-tooltip":{zIndex:500,boxSizing:"border-box"},"&light .cm-tooltip":{border:"1px solid #bbb",backgroundColor:"#f5f5f5"},"&light .cm-tooltip-section:not(:first-child)":{borderTop:"1px solid #bbb"},"&dark .cm-tooltip":{backgroundColor:"#333338",color:"white"},".cm-tooltip-arrow":{height:"7px",width:"14px",position:"absolute",zIndex:-1,overflow:"hidden","&:before, &:after":{content:"''",position:"absolute",width:0,height:0,borderLeft:"7px solid transparent",borderRight:"7px solid transparent"},".cm-tooltip-above &":{bottom:"-7px","&:before":{borderTop:"7px solid #bbb"},"&:after":{borderTop:"7px solid #f5f5f5",bottom:"1px"}},".cm-tooltip-below &":{top:"-7px","&:before":{borderBottom:"7px solid #bbb"},"&:after":{borderBottom:"7px solid #f5f5f5",top:"1px"}}},"&dark .cm-tooltip .cm-tooltip-arrow":{"&:before":{borderTopColor:"#333338",borderBottomColor:"#333338"},"&:after":{borderTopColor:"transparent",borderBottomColor:"transparent"}}}),qrt={x:0,y:0},zB=Zt.define({enables:[FB,Urt]}),DE=Zt.define({combine:e=>e.reduce((t,n)=>t.concat(n),[])});class RI{static create(t){return new RI(t)}constructor(t){this.view=t,this.mounted=!1,this.dom=document.createElement("div"),this.dom.classList.add("cm-tooltip-hover"),this.manager=new Rye(t,DE,(n,r)=>this.createHostedView(n,r),n=>n.dom.remove())}createHostedView(t,n){let r=t.create(this.view);return r.dom.classList.add("cm-tooltip-section"),this.dom.insertBefore(r.dom,n?n.dom.nextSibling:this.dom.firstChild),this.mounted&&r.mount&&r.mount(this.view),r}mount(t){for(let n of this.manager.tooltipViews)n.mount&&n.mount(t);this.mounted=!0}positioned(t){for(let n of this.manager.tooltipViews)n.positioned&&n.positioned(t)}update(t){this.manager.update(t)}destroy(){var t;for(let n of this.manager.tooltipViews)(t=n.destroy)===null||t===void 0||t.call(n)}passProp(t){let n;for(let r of this.manager.tooltipViews){let s=r[t];if(s!==void 0){if(n===void 0)n=s;else if(n!==s)return}}return n}get offset(){return this.passProp("offset")}get getCoords(){return this.passProp("getCoords")}get overlap(){return this.passProp("overlap")}get resize(){return this.passProp("resize")}}const Vrt=zB.compute([DE],e=>{let t=e.facet(DE);return t.length===0?null:{pos:Math.min(...t.map(n=>n.pos)),end:Math.max(...t.map(n=>{var r;return(r=n.end)!==null&&r!==void 0?r:n.pos})),create:RI.create,above:t[0].above,arrow:t.some(n=>n.arrow)}});class Hrt{constructor(t,n,r,s,a){this.view=t,this.source=n,this.field=r,this.setHover=s,this.hoverTime=a,this.hoverTimeout=-1,this.restartTimeout=-1,this.pending=null,this.lastMove={x:0,y:0,target:t.dom,time:0},this.checkHover=this.checkHover.bind(this),t.dom.addEventListener("mouseleave",this.mouseleave=this.mouseleave.bind(this)),t.dom.addEventListener("mousemove",this.mousemove=this.mousemove.bind(this))}update(){this.pending&&(this.pending=null,clearTimeout(this.restartTimeout),this.restartTimeout=setTimeout(()=>this.startHover(),20))}get active(){return this.view.state.field(this.field)}checkHover(){if(this.hoverTimeout=-1,this.active.length)return;let t=Date.now()-this.lastMove.time;t<this.hoverTime?this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime-t):this.startHover()}startHover(){clearTimeout(this.restartTimeout);let{view:t,lastMove:n}=this,r=t.docView.tile.nearest(n.target);if(!r)return;let s,a=1;if(r.isWidget())s=r.posAtStart;else{if(s=t.posAtCoords(n),s==null)return;let l=t.coordsAtPos(s);if(!l||n.y<l.top||n.y>l.bottom||n.x<l.left-t.defaultCharacterWidth||n.x>l.right+t.defaultCharacterWidth)return;let c=t.bidiSpans(t.state.doc.lineAt(s)).find(d=>d.from<=s&&d.to>=s),u=c&&c.dir==Fs.RTL?-1:1;a=n.x<l.left?-u:u}let o=this.source(t,s,a);if(o!=null&&o.then){let l=this.pending={pos:s};o.then(c=>{this.pending==l&&(this.pending=null,c&&!(Array.isArray(c)&&!c.length)&&t.dispatch({effects:this.setHover.of(Array.isArray(c)?c:[c])}))},c=>Ul(t.state,c,"hover tooltip"))}else o&&!(Array.isArray(o)&&!o.length)&&t.dispatch({effects:this.setHover.of(Array.isArray(o)?o:[o])})}get tooltip(){let t=this.view.plugin(FB),n=t?t.manager.tooltips.findIndex(r=>r.create==RI.create):-1;return n>-1?t.manager.tooltipViews[n]:null}mousemove(t){var n,r;this.lastMove={x:t.clientX,y:t.clientY,target:t.target,time:Date.now()},this.hoverTimeout<0&&(this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime));let{active:s,tooltip:a}=this;if(s.length&&a&&!Krt(a.dom,t)||this.pending){let{pos:o}=s[0]||this.pending,l=(r=(n=s[0])===null||n===void 0?void 0:n.end)!==null&&r!==void 0?r:o;(o==l?this.view.posAtCoords(this.lastMove)!=o:!Wrt(this.view,o,l,t.clientX,t.clientY))&&(this.view.dispatch({effects:this.setHover.of([])}),this.pending=null)}}mouseleave(t){clearTimeout(this.hoverTimeout),this.hoverTimeout=-1;let{active:n}=this;if(n.length){let{tooltip:r}=this;r&&r.dom.contains(t.relatedTarget)?this.watchTooltipLeave(r.dom):this.view.dispatch({effects:this.setHover.of([])})}}watchTooltipLeave(t){let n=r=>{t.removeEventListener("mouseleave",n),this.active.length&&!this.view.dom.contains(r.relatedTarget)&&this.view.dispatch({effects:this.setHover.of([])})};t.addEventListener("mouseleave",n)}destroy(){clearTimeout(this.hoverTimeout),clearTimeout(this.restartTimeout),this.view.dom.removeEventListener("mouseleave",this.mouseleave),this.view.dom.removeEventListener("mousemove",this.mousemove)}}const j_=4;function Krt(e,t){let{left:n,right:r,top:s,bottom:a}=e.getBoundingClientRect(),o;if(o=e.querySelector(".cm-tooltip-arrow")){let l=o.getBoundingClientRect();s=Math.min(l.top,s),a=Math.max(l.bottom,a)}return t.clientX>=n-j_&&t.clientX<=r+j_&&t.clientY>=s-j_&&t.clientY<=a+j_}function Wrt(e,t,n,r,s,a){let o=e.scrollDOM.getBoundingClientRect(),l=e.documentTop+e.documentPadding.top+e.contentHeight;if(o.left>r||o.right<r||o.top>s||Math.min(o.bottom,l)<s)return!1;let c=e.posAtCoords({x:r,y:s},!1);return c>=t&&c<=n}function Grt(e,t={}){let n=Yn.define(),r=ko.define({create(){return[]},update(s,a){if(s.length&&(t.hideOnChange&&(a.docChanged||a.selection)?s=[]:t.hideOn&&(s=s.filter(o=>!t.hideOn(a,o))),a.docChanged)){let o=[];for(let l of s){let c=a.changes.mapPos(l.pos,-1,co.TrackDel);if(c!=null){let u=Object.assign(Object.create(null),l);u.pos=c,u.end!=null&&(u.end=a.changes.mapPos(u.end)),o.push(u)}}s=o}for(let o of a.effects)o.is(n)&&(s=o.value),o.is(Qrt)&&(s=[]);return s},provide:s=>DE.from(s)});return{active:r,extension:[r,Vi.define(s=>new Hrt(s,e,r,n,t.hoverTime||300)),Vrt]}}function Mye(e,t){let n=e.plugin(FB);if(!n)return null;let r=n.manager.tooltips.indexOf(t);return r<0?null:n.manager.tooltipViews[r]}const Qrt=Yn.define(),mX=Zt.define({combine(e){let t,n;for(let r of e)t=t||r.topContainer,n=n||r.bottomContainer;return{topContainer:t,bottomContainer:n}}});function BB(e,t){let n=e.plugin(Oye),r=n?n.specs.indexOf(t):-1;return r>-1?n.panels[r]:null}const Oye=Vi.fromClass(class{constructor(e){this.input=e.state.facet(TN),this.specs=this.input.filter(n=>n),this.panels=this.specs.map(n=>n(e));let t=e.state.facet(mX);this.top=new N_(e,!0,t.topContainer),this.bottom=new N_(e,!1,t.bottomContainer),this.top.sync(this.panels.filter(n=>n.top)),this.bottom.sync(this.panels.filter(n=>!n.top));for(let n of this.panels)n.dom.classList.add("cm-panel"),n.mount&&n.mount()}update(e){let t=e.state.facet(mX);this.top.container!=t.topContainer&&(this.top.sync([]),this.top=new N_(e.view,!0,t.topContainer)),this.bottom.container!=t.bottomContainer&&(this.bottom.sync([]),this.bottom=new N_(e.view,!1,t.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let n=e.state.facet(TN);if(n!=this.input){let r=n.filter(c=>c),s=[],a=[],o=[],l=[];for(let c of r){let u=this.specs.indexOf(c),d;u<0?(d=c(e.view),l.push(d)):(d=this.panels[u],d.update&&d.update(e)),s.push(d),(d.top?a:o).push(d)}this.specs=r,this.panels=s,this.top.sync(a),this.bottom.sync(o);for(let c of l)c.dom.classList.add("cm-panel"),c.mount&&c.mount()}else for(let r of this.panels)r.update&&r.update(e)}destroy(){this.top.sync([]),this.bottom.sync([])}},{provide:e=>Yt.scrollMargins.of(t=>{let n=t.plugin(e);return n&&{top:n.top.scrollMargin(),bottom:n.bottom.scrollMargin()}})});class N_{constructor(t,n,r){this.view=t,this.top=n,this.container=r,this.dom=void 0,this.classes="",this.panels=[],this.syncClasses()}sync(t){for(let n of this.panels)n.destroy&&t.indexOf(n)<0&&n.destroy();this.panels=t,this.syncDOM()}syncDOM(){if(this.panels.length==0){this.dom&&(this.dom.remove(),this.dom=void 0);return}if(!this.dom){this.dom=document.createElement("div"),this.dom.className=this.top?"cm-panels cm-panels-top":"cm-panels cm-panels-bottom",this.dom.style[this.top?"top":"bottom"]="0";let n=this.container||this.view.dom;n.insertBefore(this.dom,this.top?n.firstChild:null)}let t=this.dom.firstChild;for(let n of this.panels)if(n.dom.parentNode==this.dom){for(;t!=n.dom;)t=pX(t);t=t.nextSibling}else this.dom.insertBefore(n.dom,t);for(;t;)t=pX(t)}scrollMargin(){return!this.dom||this.container?0:Math.max(0,this.top?this.dom.getBoundingClientRect().bottom-Math.max(0,this.view.scrollDOM.getBoundingClientRect().top):Math.min(innerHeight,this.view.scrollDOM.getBoundingClientRect().bottom)-this.dom.getBoundingClientRect().top)}syncClasses(){if(!(!this.container||this.classes==this.view.themeClasses)){for(let t of this.classes.split(" "))t&&this.container.classList.remove(t);for(let t of(this.classes=this.view.themeClasses).split(" "))t&&this.container.classList.add(t)}}}function pX(e){let t=e.nextSibling;return e.remove(),t}const TN=Zt.define({enables:Oye});function Yrt(e,t){let n,r=new Promise(o=>n=o),s=o=>Jrt(o,t,n);e.state.field(aD,!1)?e.dispatch({effects:Dye.of(s)}):e.dispatch({effects:Yn.appendConfig.of(aD.init(()=>[s]))});let a=Pye.of(s);return{close:a,result:r.then(o=>((e.win.queueMicrotask||(c=>e.win.setTimeout(c,10)))(()=>{e.state.field(aD).indexOf(s)>-1&&e.dispatch({effects:a})}),o))}}const aD=ko.define({create(){return[]},update(e,t){for(let n of t.effects)n.is(Dye)?e=[n.value].concat(e):n.is(Pye)&&(e=e.filter(r=>r!=n.value));return e},provide:e=>TN.computeN([e],t=>t.field(e))}),Dye=Yn.define(),Pye=Yn.define();function Jrt(e,t,n){let r=t.content?t.content(e,()=>o(null)):null;if(!r){if(r=Es("form"),t.input){let l=Es("input",t.input);/^(text|password|number|email|tel|url)$/.test(l.type)&&l.classList.add("cm-textfield"),l.name||(l.name="input"),r.appendChild(Es("label",(t.label||"")+": ",l))}else r.appendChild(document.createTextNode(t.label||""));r.appendChild(document.createTextNode(" ")),r.appendChild(Es("button",{class:"cm-button",type:"submit"},t.submitLabel||"OK"))}let s=r.nodeName=="FORM"?[r]:r.querySelectorAll("form");for(let l=0;l<s.length;l++){let c=s[l];c.addEventListener("keydown",u=>{u.keyCode==27?(u.preventDefault(),o(null)):u.keyCode==13&&(u.preventDefault(),o(c))}),c.addEventListener("submit",u=>{u.preventDefault(),o(c)})}let a=Es("div",r,Es("button",{onclick:()=>o(null),"aria-label":e.state.phrase("close"),class:"cm-dialog-close",type:"button"},["×"]));t.class&&(a.className=t.class),a.classList.add("cm-dialog");function o(l){a.contains(a.ownerDocument.activeElement)&&e.focus(),n(l)}return{dom:a,top:t.top,mount:()=>{if(t.focus){let l;typeof t.focus=="string"?l=r.querySelector(t.focus):l=r.querySelector("input")||r.querySelector("button"),l&&"select"in l?l.select():l&&"focus"in l&&l.focus()}}}}class rm extends yg{compare(t){return this==t||this.constructor==t.constructor&&this.eq(t)}eq(t){return!1}destroy(t){}}rm.prototype.elementClass="";rm.prototype.toDOM=void 0;rm.prototype.mapMode=co.TrackBefore;rm.prototype.startSide=rm.prototype.endSide=-1;rm.prototype.point=!0;const G5=Zt.define(),Zrt=Zt.define(),Xrt={class:"",renderEmptyElements:!1,elementStyle:"",markers:()=>_r.empty,lineMarker:()=>null,widgetMarker:()=>null,lineMarkerChange:null,initialSpacer:null,updateSpacer:null,domEventHandlers:{},side:"before"},_j=Zt.define();function est(e){return[Lye(),_j.of({...Xrt,...e})]}const gX=Zt.define({combine:e=>e.some(t=>t)});function Lye(e){return[tst]}const tst=Vi.fromClass(class{constructor(e){this.view=e,this.domAfter=null,this.prevViewport=e.viewport,this.dom=document.createElement("div"),this.dom.className="cm-gutters cm-gutters-before",this.dom.setAttribute("aria-hidden","true"),this.dom.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.gutters=e.state.facet(_j).map(t=>new bX(e,t)),this.fixed=!e.state.facet(gX);for(let t of this.gutters)t.config.side=="after"?this.getDOMAfter().appendChild(t.dom):this.dom.appendChild(t.dom);this.fixed&&(this.dom.style.position="sticky"),this.syncGutters(!1),e.scrollDOM.insertBefore(this.dom,e.contentDOM)}getDOMAfter(){return this.domAfter||(this.domAfter=document.createElement("div"),this.domAfter.className="cm-gutters cm-gutters-after",this.domAfter.setAttribute("aria-hidden","true"),this.domAfter.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.domAfter.style.position=this.fixed?"sticky":"",this.view.scrollDOM.appendChild(this.domAfter)),this.domAfter}update(e){if(this.updateGutters(e)){let t=this.prevViewport,n=e.view.viewport,r=Math.min(t.to,n.to)-Math.max(t.from,n.from);this.syncGutters(r<(n.to-n.from)*.8)}if(e.geometryChanged){let t=this.view.contentHeight/this.view.scaleY+"px";this.dom.style.minHeight=t,this.domAfter&&(this.domAfter.style.minHeight=t)}this.view.state.facet(gX)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?"sticky":"",this.domAfter&&(this.domAfter.style.position=this.fixed?"sticky":"")),this.prevViewport=e.view.viewport}syncGutters(e){let t=this.dom.nextSibling;e&&(this.dom.remove(),this.domAfter&&this.domAfter.remove());let n=_r.iter(this.view.state.facet(G5),this.view.viewport.from),r=[],s=this.gutters.map(a=>new nst(a,this.view.viewport,-this.view.documentPadding.top));for(let a of this.view.viewportLineBlocks)if(r.length&&(r=[]),Array.isArray(a.type)){let o=!0;for(let l of a.type)if(l.type==go.Text&&o){o$(n,r,l.from);for(let c of s)c.line(this.view,l,r);o=!1}else if(l.widget)for(let c of s)c.widget(this.view,l)}else if(a.type==go.Text){o$(n,r,a.from);for(let o of s)o.line(this.view,a,r)}else if(a.widget)for(let o of s)o.widget(this.view,a);for(let a of s)a.finish();e&&(this.view.scrollDOM.insertBefore(this.dom,t),this.domAfter&&this.view.scrollDOM.appendChild(this.domAfter))}updateGutters(e){let t=e.startState.facet(_j),n=e.state.facet(_j),r=e.docChanged||e.heightChanged||e.viewportChanged||!_r.eq(e.startState.facet(G5),e.state.facet(G5),e.view.viewport.from,e.view.viewport.to);if(t==n)for(let s of this.gutters)s.update(e)&&(r=!0);else{r=!0;let s=[];for(let a of n){let o=t.indexOf(a);o<0?s.push(new bX(this.view,a)):(this.gutters[o].update(e),s.push(this.gutters[o]))}for(let a of this.gutters)a.dom.remove(),s.indexOf(a)<0&&a.destroy();for(let a of s)a.config.side=="after"?this.getDOMAfter().appendChild(a.dom):this.dom.appendChild(a.dom);this.gutters=s}return r}destroy(){for(let e of this.gutters)e.destroy();this.dom.remove(),this.domAfter&&this.domAfter.remove()}},{provide:e=>Yt.scrollMargins.of(t=>{let n=t.plugin(e);if(!n||n.gutters.length==0||!n.fixed)return null;let r=n.dom.offsetWidth*t.scaleX,s=n.domAfter?n.domAfter.offsetWidth*t.scaleX:0;return t.textDirection==Fs.LTR?{left:r,right:s}:{right:r,left:s}})});function xX(e){return Array.isArray(e)?e:[e]}function o$(e,t,n){for(;e.value&&e.from<=n;)e.from==n&&t.push(e.value),e.next()}class nst{constructor(t,n,r){this.gutter=t,this.height=r,this.i=0,this.cursor=_r.iter(t.markers,n.from)}addElement(t,n,r){let{gutter:s}=this,a=(n.top-this.height)/t.scaleY,o=n.height/t.scaleY;if(this.i==s.elements.length){let l=new $ye(t,o,a,r);s.elements.push(l),s.dom.appendChild(l.dom)}else s.elements[this.i].update(t,o,a,r);this.height=n.bottom,this.i++}line(t,n,r){let s=[];o$(this.cursor,s,n.from),r.length&&(s=s.concat(r));let a=this.gutter.config.lineMarker(t,n,s);a&&s.unshift(a);let o=this.gutter;s.length==0&&!o.config.renderEmptyElements||this.addElement(t,n,s)}widget(t,n){let r=this.gutter.config.widgetMarker(t,n.widget,n),s=r?[r]:null;for(let a of t.state.facet(Zrt)){let o=a(t,n.widget,n);o&&(s||(s=[])).push(o)}s&&this.addElement(t,n,s)}finish(){let t=this.gutter;for(;t.elements.length>this.i;){let n=t.elements.pop();t.dom.removeChild(n.dom),n.destroy()}}}class bX{constructor(t,n){this.view=t,this.config=n,this.elements=[],this.spacer=null,this.dom=document.createElement("div"),this.dom.className="cm-gutter"+(this.config.class?" "+this.config.class:"");for(let r in n.domEventHandlers)this.dom.addEventListener(r,s=>{let a=s.target,o;if(a!=this.dom&&this.dom.contains(a)){for(;a.parentNode!=this.dom;)a=a.parentNode;let c=a.getBoundingClientRect();o=(c.top+c.bottom)/2}else o=s.clientY;let l=t.lineBlockAtHeight(o-t.documentTop);n.domEventHandlers[r](t,l,s)&&s.preventDefault()});this.markers=xX(n.markers(t)),n.initialSpacer&&(this.spacer=new $ye(t,0,0,[n.initialSpacer(t)]),this.dom.appendChild(this.spacer.dom),this.spacer.dom.style.cssText+="visibility: hidden; pointer-events: none")}update(t){let n=this.markers;if(this.markers=xX(this.config.markers(t.view)),this.spacer&&this.config.updateSpacer){let s=this.config.updateSpacer(this.spacer.markers[0],t);s!=this.spacer.markers[0]&&this.spacer.update(t.view,0,0,[s])}let r=t.view.viewport;return!_r.eq(this.markers,n,r.from,r.to)||(this.config.lineMarkerChange?this.config.lineMarkerChange(t):!1)}destroy(){for(let t of this.elements)t.destroy()}}class $ye{constructor(t,n,r,s){this.height=-1,this.above=0,this.markers=[],this.dom=document.createElement("div"),this.dom.className="cm-gutterElement",this.update(t,n,r,s)}update(t,n,r,s){this.height!=n&&(this.height=n,this.dom.style.height=n+"px"),this.above!=r&&(this.dom.style.marginTop=(this.above=r)?r+"px":""),rst(this.markers,s)||this.setMarkers(t,s)}setMarkers(t,n){let r="cm-gutterElement",s=this.dom.firstChild;for(let a=0,o=0;;){let l=o,c=a<n.length?n[a++]:null,u=!1;if(c){let d=c.elementClass;d&&(r+=" "+d);for(let h=o;h<this.markers.length;h++)if(this.markers[h].compare(c)){l=h,u=!0;break}}else l=this.markers.length;for(;o<l;){let d=this.markers[o++];if(d.toDOM){d.destroy(s);let h=s.nextSibling;s.remove(),s=h}}if(!c)break;c.toDOM&&(u?s=s.nextSibling:this.dom.insertBefore(c.toDOM(t),s)),u&&o++}this.dom.className=r,this.markers=n}destroy(){this.setMarkers(null,[])}}function rst(e,t){if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++)if(!e[n].compare(t[n]))return!1;return!0}const sst=Zt.define(),ist=Zt.define(),M0=Zt.define({combine(e){return Pf(e,{formatNumber:String,domEventHandlers:{}},{domEventHandlers(t,n){let r=Object.assign({},t);for(let s in n){let a=r[s],o=n[s];r[s]=a?(l,c,u)=>a(l,c,u)||o(l,c,u):o}return r}})}});class oD extends rm{constructor(t){super(),this.number=t}eq(t){return this.number==t.number}toDOM(){return document.createTextNode(this.number)}}function lD(e,t){return e.state.facet(M0).formatNumber(t,e.state)}const ast=_j.compute([M0],e=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers(t){return t.state.facet(sst)},lineMarker(t,n,r){return r.some(s=>s.toDOM)?null:new oD(lD(t,t.state.doc.lineAt(n.from).number))},widgetMarker:(t,n,r)=>{for(let s of t.state.facet(ist)){let a=s(t,n,r);if(a)return a}return null},lineMarkerChange:t=>t.startState.facet(M0)!=t.state.facet(M0),initialSpacer(t){return new oD(lD(t,yX(t.state.doc.lines)))},updateSpacer(t,n){let r=lD(n.view,yX(n.view.state.doc.lines));return r==t.number?t:new oD(r)},domEventHandlers:e.facet(M0).domEventHandlers,side:"before"}));function Fye(e={}){return[M0.of(e),Lye(),ast]}function yX(e){let t=9;for(;t<e;)t=t*10+9;return t}const ost=new class extends rm{constructor(){super(...arguments),this.elementClass="cm-activeLineGutter"}},lst=G5.compute(["selection"],e=>{let t=[],n=-1;for(let r of e.selection.ranges){let s=e.doc.lineAt(r.head).from;s>n&&(n=s,t.push(ost.range(s)))}return _r.of(t)});function cst(){return lst}const ust=1024;let dst=0,tu=class{constructor(t,n){this.from=t,this.to=n}};class jr{constructor(t={}){this.id=dst++,this.perNode=!!t.perNode,this.deserialize=t.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")}),this.combine=t.combine||null}add(t){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return typeof t!="function"&&(t=jl.match(t)),n=>{let r=t(n);return r===void 0?null:[this,r]}}}jr.closedBy=new jr({deserialize:e=>e.split(" ")});jr.openedBy=new jr({deserialize:e=>e.split(" ")});jr.group=new jr({deserialize:e=>e.split(" ")});jr.isolate=new jr({deserialize:e=>{if(e&&e!="rtl"&&e!="ltr"&&e!="auto")throw new RangeError("Invalid value for isolate: "+e);return e||"auto"}});jr.contextHash=new jr({perNode:!0});jr.lookAhead=new jr({perNode:!0});jr.mounted=new jr({perNode:!0});class Q0{constructor(t,n,r,s=!1){this.tree=t,this.overlay=n,this.parser=r,this.bracketed=s}static get(t){return t&&t.props&&t.props[jr.mounted.id]}}const fst=Object.create(null);class jl{constructor(t,n,r,s=0){this.name=t,this.props=n,this.id=r,this.flags=s}static define(t){let n=t.props&&t.props.length?Object.create(null):fst,r=(t.top?1:0)|(t.skipped?2:0)|(t.error?4:0)|(t.name==null?8:0),s=new jl(t.name||"",n,t.id,r);if(t.props){for(let a of t.props)if(Array.isArray(a)||(a=a(s)),a){if(a[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");n[a[0].id]=a[1]}}return s}prop(t){return this.props[t.id]}get isTop(){return(this.flags&1)>0}get isSkipped(){return(this.flags&2)>0}get isError(){return(this.flags&4)>0}get isAnonymous(){return(this.flags&8)>0}is(t){if(typeof t=="string"){if(this.name==t)return!0;let n=this.prop(jr.group);return n?n.indexOf(t)>-1:!1}return this.id==t}static match(t){let n=Object.create(null);for(let r in t)for(let s of r.split(" "))n[s]=t[r];return r=>{for(let s=r.prop(jr.group),a=-1;a<(s?s.length:0);a++){let o=n[a<0?r.name:s[a]];if(o)return o}}}}jl.none=new jl("",Object.create(null),0,8);class UB{constructor(t){this.types=t;for(let n=0;n<t.length;n++)if(t[n].id!=n)throw new RangeError("Node type ids should correspond to array positions when creating a node set")}extend(...t){let n=[];for(let r of this.types){let s=null;for(let a of t){let o=a(r);if(o){s||(s=Object.assign({},r.props));let l=o[1],c=o[0];c.combine&&c.id in s&&(l=c.combine(s[c.id],l)),s[c.id]=l}}n.push(s?new jl(r.name,s,r.id,r.flags):r)}return new UB(n)}}const C_=new WeakMap,vX=new WeakMap;var $s;(function(e){e[e.ExcludeBuffers=1]="ExcludeBuffers",e[e.IncludeAnonymous=2]="IncludeAnonymous",e[e.IgnoreMounts=4]="IgnoreMounts",e[e.IgnoreOverlays=8]="IgnoreOverlays",e[e.EnterBracketed=16]="EnterBracketed"})($s||($s={}));class zs{constructor(t,n,r,s,a){if(this.type=t,this.children=n,this.positions=r,this.length=s,this.props=null,a&&a.length){this.props=Object.create(null);for(let[o,l]of a)this.props[typeof o=="number"?o:o.id]=l}}toString(){let t=Q0.get(this);if(t&&!t.overlay)return t.tree.toString();let n="";for(let r of this.children){let s=r.toString();s&&(n&&(n+=","),n+=s)}return this.type.name?(/\W/.test(this.type.name)&&!this.type.isError?JSON.stringify(this.type.name):this.type.name)+(n.length?"("+n+")":""):n}cursor(t=0){return new PE(this.topNode,t)}cursorAt(t,n=0,r=0){let s=C_.get(this)||this.topNode,a=new PE(s);return a.moveTo(t,n),C_.set(this,a._tree),a}get topNode(){return new qo(this,0,0,null)}resolve(t,n=0){let r=IN(C_.get(this)||this.topNode,t,n,!1);return C_.set(this,r),r}resolveInner(t,n=0){let r=IN(vX.get(this)||this.topNode,t,n,!0);return vX.set(this,r),r}resolveStack(t,n=0){return pst(this,t,n)}iterate(t){let{enter:n,leave:r,from:s=0,to:a=this.length}=t,o=t.mode||0,l=(o&$s.IncludeAnonymous)>0;for(let c=this.cursor(o|$s.IncludeAnonymous);;){let u=!1;if(c.from<=a&&c.to>=s&&(!l&&c.type.isAnonymous||n(c)!==!1)){if(c.firstChild())continue;u=!0}for(;u&&r&&(l||!c.type.isAnonymous)&&r(c),!c.nextSibling();){if(!c.parent())return;u=!0}}}prop(t){return t.perNode?this.props?this.props[t.id]:void 0:this.type.prop(t)}get propValues(){let t=[];if(this.props)for(let n in this.props)t.push([+n,this.props[n]]);return t}balance(t={}){return this.children.length<=8?this:HB(jl.none,this.children,this.positions,0,this.children.length,0,this.length,(n,r,s)=>new zs(this.type,n,r,s,this.propValues),t.makeTree||((n,r,s)=>new zs(jl.none,n,r,s)))}static build(t){return gst(t)}}zs.empty=new zs(jl.none,[],[],0);class qB{constructor(t,n){this.buffer=t,this.index=n}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}get pos(){return this.index}next(){this.index-=4}fork(){return new qB(this.buffer,this.index)}}class jg{constructor(t,n,r){this.buffer=t,this.length=n,this.set=r}get type(){return jl.none}toString(){let t=[];for(let n=0;n<this.buffer.length;)t.push(this.childString(n)),n=this.buffer[n+3];return t.join(",")}childString(t){let n=this.buffer[t],r=this.buffer[t+3],s=this.set.types[n],a=s.name;if(/\W/.test(a)&&!s.isError&&(a=JSON.stringify(a)),t+=4,r==t)return a;let o=[];for(;t<r;)o.push(this.childString(t)),t=this.buffer[t+3];return a+"("+o.join(",")+")"}findChild(t,n,r,s,a){let{buffer:o}=this,l=-1;for(let c=t;c!=n&&!(zye(a,s,o[c+1],o[c+2])&&(l=c,r>0));c=o[c+3]);return l}slice(t,n,r){let s=this.buffer,a=new Uint16Array(n-t),o=0;for(let l=t,c=0;l<n;){a[c++]=s[l++],a[c++]=s[l++]-r;let u=a[c++]=s[l++]-r;a[c++]=s[l++]-t,o=Math.max(o,u)}return new jg(a,o,this.set)}}function zye(e,t,n,r){switch(e){case-2:return n<t;case-1:return r>=t&&n<t;case 0:return n<t&&r>t;case 1:return n<=t&&r>t;case 2:return r>t;case 4:return!0}}function IN(e,t,n,r){for(var s;e.from==e.to||(n<1?e.from>=t:e.from>t)||(n>-1?e.to<=t:e.to<t);){let o=!r&&e instanceof qo&&e.index<0?null:e.parent;if(!o)return e;e=o}let a=r?0:$s.IgnoreOverlays;if(r)for(let o=e,l=o.parent;l;o=l,l=o.parent)o instanceof qo&&o.index<0&&((s=l.enter(t,n,a))===null||s===void 0?void 0:s.from)!=o.from&&(e=l);for(;;){let o=e.enter(t,n,a);if(!o)return e;e=o}}class Bye{cursor(t=0){return new PE(this,t)}getChild(t,n=null,r=null){let s=wX(this,t,n,r);return s.length?s[0]:null}getChildren(t,n=null,r=null){return wX(this,t,n,r)}resolve(t,n=0){return IN(this,t,n,!1)}resolveInner(t,n=0){return IN(this,t,n,!0)}matchContext(t){return l$(this.parent,t)}enterUnfinishedNodesBefore(t){let n=this.childBefore(t),r=this;for(;n;){let s=n.lastChild;if(!s||s.to!=n.to)break;s.type.isError&&s.from==s.to?(r=n,n=s.prevSibling):n=s}return r}get node(){return this}get next(){return this.parent}}class qo extends Bye{constructor(t,n,r,s){super(),this._tree=t,this.from=n,this.index=r,this._parent=s}get type(){return this._tree.type}get name(){return this._tree.type.name}get to(){return this.from+this._tree.length}nextChild(t,n,r,s,a=0){for(let o=this;;){for(let{children:l,positions:c}=o._tree,u=n>0?l.length:-1;t!=u;t+=n){let d=l[t],h=c[t]+o.from,m;if(!(!(a&$s.EnterBracketed&&d instanceof zs&&(m=Q0.get(d))&&!m.overlay&&m.bracketed&&r>=h&&r<=h+d.length)&&!zye(s,r,h,h+d.length))){if(d instanceof jg){if(a&$s.ExcludeBuffers)continue;let g=d.findChild(0,d.buffer.length,n,r-h,s);if(g>-1)return new cf(new hst(o,d,t,h),null,g)}else if(a&$s.IncludeAnonymous||!d.type.isAnonymous||VB(d)){let g;if(!(a&$s.IgnoreMounts)&&(g=Q0.get(d))&&!g.overlay)return new qo(g.tree,h,t,o);let b=new qo(d,h,t,o);return a&$s.IncludeAnonymous||!b.type.isAnonymous?b:b.nextChild(n<0?d.children.length-1:0,n,r,s,a)}}}if(a&$s.IncludeAnonymous||!o.type.isAnonymous||(o.index>=0?t=o.index+n:t=n<0?-1:o._parent._tree.children.length,o=o._parent,!o))return null}}get firstChild(){return this.nextChild(0,1,0,4)}get lastChild(){return this.nextChild(this._tree.children.length-1,-1,0,4)}childAfter(t){return this.nextChild(0,1,t,2)}childBefore(t){return this.nextChild(this._tree.children.length-1,-1,t,-2)}prop(t){return this._tree.prop(t)}enter(t,n,r=0){let s;if(!(r&$s.IgnoreOverlays)&&(s=Q0.get(this._tree))&&s.overlay){let a=t-this.from,o=r&$s.EnterBracketed&&s.bracketed;for(let{from:l,to:c}of s.overlay)if((n>0||o?l<=a:l<a)&&(n<0||o?c>=a:c>a))return new qo(s.tree,s.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,t,n,r)}nextSignificantParent(){let t=this;for(;t.type.isAnonymous&&t._parent;)t=t._parent;return t}get parent(){return this._parent?this._parent.nextSignificantParent():null}get nextSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index+1,1,0,4):null}get prevSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index-1,-1,0,4):null}get tree(){return this._tree}toTree(){return this._tree}toString(){return this._tree.toString()}}function wX(e,t,n,r){let s=e.cursor(),a=[];if(!s.firstChild())return a;if(n!=null){for(let o=!1;!o;)if(o=s.type.is(n),!s.nextSibling())return a}for(;;){if(r!=null&&s.type.is(r))return a;if(s.type.is(t)&&a.push(s.node),!s.nextSibling())return r==null?a:[]}}function l$(e,t,n=t.length-1){for(let r=e;n>=0;r=r.parent){if(!r)return!1;if(!r.type.isAnonymous){if(t[n]&&t[n]!=r.name)return!1;n--}}return!0}class hst{constructor(t,n,r,s){this.parent=t,this.buffer=n,this.index=r,this.start=s}}class cf extends Bye{get name(){return this.type.name}get from(){return this.context.start+this.context.buffer.buffer[this.index+1]}get to(){return this.context.start+this.context.buffer.buffer[this.index+2]}constructor(t,n,r){super(),this.context=t,this._parent=n,this.index=r,this.type=t.buffer.set.types[t.buffer.buffer[r]]}child(t,n,r){let{buffer:s}=this.context,a=s.findChild(this.index+4,s.buffer[this.index+3],t,n-this.context.start,r);return a<0?null:new cf(this.context,this,a)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(t){return this.child(1,t,2)}childBefore(t){return this.child(-1,t,-2)}prop(t){return this.type.prop(t)}enter(t,n,r=0){if(r&$s.ExcludeBuffers)return null;let{buffer:s}=this.context,a=s.findChild(this.index+4,s.buffer[this.index+3],n>0?1:-1,t-this.context.start,n);return a<0?null:new cf(this.context,this,a)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(t){return this._parent?null:this.context.parent.nextChild(this.context.index+t,t,0,4)}get nextSibling(){let{buffer:t}=this.context,n=t.buffer[this.index+3];return n<(this._parent?t.buffer[this._parent.index+3]:t.buffer.length)?new cf(this.context,this._parent,n):this.externalSibling(1)}get prevSibling(){let{buffer:t}=this.context,n=this._parent?this._parent.index+4:0;return this.index==n?this.externalSibling(-1):new cf(this.context,this._parent,t.findChild(n,this.index,-1,0,4))}get tree(){return null}toTree(){let t=[],n=[],{buffer:r}=this.context,s=this.index+4,a=r.buffer[this.index+3];if(a>s){let o=r.buffer[this.index+1];t.push(r.slice(s,a,o)),n.push(0)}return new zs(this.type,t,n,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}}function Uye(e){if(!e.length)return null;let t=0,n=e[0];for(let a=1;a<e.length;a++){let o=e[a];(o.from>n.from||o.to<n.to)&&(n=o,t=a)}let r=n instanceof qo&&n.index<0?null:n.parent,s=e.slice();return r?s[t]=r:s.splice(t,1),new mst(s,n)}class mst{constructor(t,n){this.heads=t,this.node=n}get next(){return Uye(this.heads)}}function pst(e,t,n){let r=e.resolveInner(t,n),s=null;for(let a=r instanceof qo?r:r.context.parent;a;a=a.parent)if(a.index<0){let o=a.parent;(s||(s=[r])).push(o.resolve(t,n)),a=o}else{let o=Q0.get(a.tree);if(o&&o.overlay&&o.overlay[0].from<=t&&o.overlay[o.overlay.length-1].to>=t){let l=new qo(o.tree,o.overlay[0].from+a.from,-1,a);(s||(s=[r])).push(IN(l,t,n,!1))}}return s?Uye(s):r}class PE{get name(){return this.type.name}constructor(t,n=0){if(this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,this.mode=n&~$s.EnterBracketed,t instanceof qo)this.yieldNode(t);else{this._tree=t.context.parent,this.buffer=t.context;for(let r=t._parent;r;r=r._parent)this.stack.unshift(r.index);this.bufferNode=t,this.yieldBuf(t.index)}}yieldNode(t){return t?(this._tree=t,this.type=t.type,this.from=t.from,this.to=t.to,!0):!1}yieldBuf(t,n){this.index=t;let{start:r,buffer:s}=this.buffer;return this.type=n||s.set.types[s.buffer[t]],this.from=r+s.buffer[t+1],this.to=r+s.buffer[t+2],!0}yield(t){return t?t instanceof qo?(this.buffer=null,this.yieldNode(t)):(this.buffer=t.context,this.yieldBuf(t.index,t.type)):!1}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(t,n,r){if(!this.buffer)return this.yield(this._tree.nextChild(t<0?this._tree._tree.children.length-1:0,t,n,r,this.mode));let{buffer:s}=this.buffer,a=s.findChild(this.index+4,s.buffer[this.index+3],t,n-this.buffer.start,r);return a<0?!1:(this.stack.push(this.index),this.yieldBuf(a))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(t){return this.enterChild(1,t,2)}childBefore(t){return this.enterChild(-1,t,-2)}enter(t,n,r=this.mode){return this.buffer?r&$s.ExcludeBuffers?!1:this.enterChild(1,t,n):this.yield(this._tree.enter(t,n,r))}parent(){if(!this.buffer)return this.yieldNode(this.mode&$s.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let t=this.mode&$s.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(t)}sibling(t){if(!this.buffer)return this._tree._parent?this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+t,t,0,4,this.mode)):!1;let{buffer:n}=this.buffer,r=this.stack.length-1;if(t<0){let s=r<0?0:this.stack[r]+4;if(this.index!=s)return this.yieldBuf(n.findChild(s,this.index,-1,0,4))}else{let s=n.buffer[this.index+3];if(s<(r<0?n.buffer.length:n.buffer[this.stack[r]+3]))return this.yieldBuf(s)}return r<0?this.yield(this.buffer.parent.nextChild(this.buffer.index+t,t,0,4,this.mode)):!1}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(t){let n,r,{buffer:s}=this;if(s){if(t>0){if(this.index<s.buffer.buffer.length)return!1}else for(let a=0;a<this.index;a++)if(s.buffer.buffer[a+3]<this.index)return!1;({index:n,parent:r}=s)}else({index:n,_parent:r}=this._tree);for(;r;{index:n,_parent:r}=r)if(n>-1)for(let a=n+t,o=t<0?-1:r._tree.children.length;a!=o;a+=t){let l=r._tree.children[a];if(this.mode&$s.IncludeAnonymous||l instanceof jg||!l.type.isAnonymous||VB(l))return!1}return!0}move(t,n){if(n&&this.enterChild(t,0,4))return!0;for(;;){if(this.sibling(t))return!0;if(this.atLastNode(t)||!this.parent())return!1}}next(t=!0){return this.move(1,t)}prev(t=!0){return this.move(-1,t)}moveTo(t,n=0){for(;(this.from==this.to||(n<1?this.from>=t:this.from>t)||(n>-1?this.to<=t:this.to<t))&&this.parent(););for(;this.enterChild(1,t,n););return this}get node(){if(!this.buffer)return this._tree;let t=this.bufferNode,n=null,r=0;if(t&&t.context==this.buffer)e:for(let s=this.index,a=this.stack.length;a>=0;){for(let o=t;o;o=o._parent)if(o.index==s){if(s==this.index)return o;n=o,r=a+1;break e}s=this.stack[--a]}for(let s=r;s<this.stack.length;s++)n=new cf(this.buffer,n,this.stack[s]);return this.bufferNode=new cf(this.buffer,n,this.index)}get tree(){return this.buffer?null:this._tree._tree}iterate(t,n){for(let r=0;;){let s=!1;if(this.type.isAnonymous||t(this)!==!1){if(this.firstChild()){r++;continue}this.type.isAnonymous||(s=!0)}for(;;){if(s&&n&&n(this),s=this.type.isAnonymous,!r)return;if(this.nextSibling())break;this.parent(),r--,s=!0}}}matchContext(t){if(!this.buffer)return l$(this.node.parent,t);let{buffer:n}=this.buffer,{types:r}=n.set;for(let s=t.length-1,a=this.stack.length-1;s>=0;a--){if(a<0)return l$(this._tree,t,s);let o=r[n.buffer[this.stack[a]]];if(!o.isAnonymous){if(t[s]&&t[s]!=o.name)return!1;s--}}return!0}}function VB(e){return e.children.some(t=>t instanceof jg||!t.type.isAnonymous||VB(t))}function gst(e){var t;let{buffer:n,nodeSet:r,maxBufferLength:s=ust,reused:a=[],minRepeatType:o=r.types.length}=e,l=Array.isArray(n)?new qB(n,n.length):n,c=r.types,u=0,d=0;function h(A,_,E,I,O,M){let{id:D,start:z,end:F,size:K}=l,J=d,$=u;if(K<0)if(l.next(),K==-1){let Y=a[D];E.push(Y),I.push(z-A);return}else if(K==-3){u=D;return}else if(K==-4){d=D;return}else throw new RangeError(`Unrecognized record size: ${K}`);let L=c[D],H,W,B=z-A;if(F-z<=s&&(W=j(l.pos-_,O))){let Y=new Uint16Array(W.size-W.skip),P=l.pos-W.size,V=Y.length;for(;l.pos>P;)V=k(W.start,Y,V);H=new jg(Y,F-W.start,r),B=W.start-A}else{let Y=l.pos-K;l.next();let P=[],V=[],ce=D>=o?D:-1,le=0,G=F;for(;l.pos>Y;)ce>=0&&l.id==ce&&l.size>=0?(l.end<=G-s&&(b(P,V,z,le,l.end,G,ce,J,$),le=P.length,G=l.end),l.next()):M>2500?m(z,Y,P,V):h(z,Y,P,V,ce,M+1);if(ce>=0&&le>0&&le<P.length&&b(P,V,z,le,z,G,ce,J,$),P.reverse(),V.reverse(),ce>-1&&le>0){let te=g(L,$);H=HB(L,P,V,0,P.length,0,F-z,te,te)}else H=v(L,P,V,F-z,J-F,$)}E.push(H),I.push(B)}function m(A,_,E,I){let O=[],M=0,D=-1;for(;l.pos>_;){let{id:z,start:F,end:K,size:J}=l;if(J>4)l.next();else{if(D>-1&&F<D)break;D<0&&(D=K-s),O.push(z,F,K),M++,l.next()}}if(M){let z=new Uint16Array(M*4),F=O[O.length-2];for(let K=O.length-3,J=0;K>=0;K-=3)z[J++]=O[K],z[J++]=O[K+1]-F,z[J++]=O[K+2]-F,z[J++]=J;E.push(new jg(z,O[2]-F,r)),I.push(F-A)}}function g(A,_){return(E,I,O)=>{let M=0,D=E.length-1,z,F;if(D>=0&&(z=E[D])instanceof zs){if(!D&&z.type==A&&z.length==O)return z;(F=z.prop(jr.lookAhead))&&(M=I[D]+z.length+F)}return v(A,E,I,O,M,_)}}function b(A,_,E,I,O,M,D,z,F){let K=[],J=[];for(;A.length>I;)K.push(A.pop()),J.push(_.pop()+E-O);A.push(v(r.types[D],K,J,M-O,z-M,F)),_.push(O-E)}function v(A,_,E,I,O,M,D){if(M){let z=[jr.contextHash,M];D=D?[z].concat(D):[z]}if(O>25){let z=[jr.lookAhead,O];D=D?[z].concat(D):[z]}return new zs(A,_,E,I,D)}function j(A,_){let E=l.fork(),I=0,O=0,M=0,D=E.end-s,z={size:0,start:0,skip:0};e:for(let F=E.pos-A;E.pos>F;){let K=E.size;if(E.id==_&&K>=0){z.size=I,z.start=O,z.skip=M,M+=4,I+=4,E.next();continue}let J=E.pos-K;if(K<0||J<F||E.start<D)break;let $=E.id>=o?4:0,L=E.start;for(E.next();E.pos>J;){if(E.size<0)if(E.size==-3||E.size==-4)$+=4;else break e;else E.id>=o&&($+=4);E.next()}O=L,I+=K,M+=$}return(_<0||I==A)&&(z.size=I,z.start=O,z.skip=M),z.size>4?z:void 0}function k(A,_,E){let{id:I,start:O,end:M,size:D}=l;if(l.next(),D>=0&&I<o){let z=E;if(D>4){let F=l.pos-(D-4);for(;l.pos>F;)E=k(A,_,E)}_[--E]=z,_[--E]=M-A,_[--E]=O-A,_[--E]=I}else D==-3?u=I:D==-4&&(d=I);return E}let w=[],N=[];for(;l.pos>0;)h(e.start||0,e.bufferStart||0,w,N,-1,0);let S=(t=e.length)!==null&&t!==void 0?t:w.length?N[0]+w[0].length:0;return new zs(c[e.topID],w.reverse(),N.reverse(),S)}const kX=new WeakMap;function Q5(e,t){if(!e.isAnonymous||t instanceof jg||t.type!=e)return 1;let n=kX.get(t);if(n==null){n=1;for(let r of t.children){if(r.type!=e||!(r instanceof zs)){n=1;break}n+=Q5(e,r)}kX.set(t,n)}return n}function HB(e,t,n,r,s,a,o,l,c){let u=0;for(let b=r;b<s;b++)u+=Q5(e,t[b]);let d=Math.ceil(u*1.5/8),h=[],m=[];function g(b,v,j,k,w){for(let N=j;N<k;){let S=N,A=v[N],_=Q5(e,b[N]);for(N++;N<k;N++){let E=Q5(e,b[N]);if(_+E>=d)break;_+=E}if(N==S+1){if(_>d){let E=b[S];g(E.children,E.positions,0,E.children.length,v[S]+w);continue}h.push(b[S])}else{let E=v[N-1]+b[N-1].length-A;h.push(HB(e,b,v,S,N,A,E,null,c))}m.push(A+w-a)}}return g(t,n,r,s,0),(l||c)(h,m,o)}class ZAt{constructor(){this.map=new WeakMap}setBuffer(t,n,r){let s=this.map.get(t);s||this.map.set(t,s=new Map),s.set(n,r)}getBuffer(t,n){let r=this.map.get(t);return r&&r.get(n)}set(t,n){t instanceof cf?this.setBuffer(t.context.buffer,t.index,n):t instanceof qo&&this.map.set(t.tree,n)}get(t){return t instanceof cf?this.getBuffer(t.context.buffer,t.index):t instanceof qo?this.map.get(t.tree):void 0}cursorSet(t,n){t.buffer?this.setBuffer(t.buffer.buffer,t.index,n):this.map.set(t.tree,n)}cursorGet(t){return t.buffer?this.getBuffer(t.buffer.buffer,t.index):this.map.get(t.tree)}}class $h{constructor(t,n,r,s,a=!1,o=!1){this.from=t,this.to=n,this.tree=r,this.offset=s,this.open=(a?1:0)|(o?2:0)}get openStart(){return(this.open&1)>0}get openEnd(){return(this.open&2)>0}static addTree(t,n=[],r=!1){let s=[new $h(0,t.length,t,0,!1,r)];for(let a of n)a.to>t.length&&s.push(a);return s}static applyChanges(t,n,r=128){if(!n.length)return t;let s=[],a=1,o=t.length?t[0]:null;for(let l=0,c=0,u=0;;l++){let d=l<n.length?n[l]:null,h=d?d.fromA:1e9;if(h-c>=r)for(;o&&o.from<h;){let m=o;if(c>=m.from||h<=m.to||u){let g=Math.max(m.from,c)-u,b=Math.min(m.to,h)-u;m=g>=b?null:new $h(g,b,m.tree,m.offset+u,l>0,!!d)}if(m&&s.push(m),o.to>h)break;o=a<t.length?t[a++]:null}if(!d)break;c=d.toA,u=d.toA-d.toB}return s}}class qye{startParse(t,n,r){return typeof t=="string"&&(t=new xst(t)),r=r?r.length?r.map(s=>new tu(s.from,s.to)):[new tu(0,0)]:[new tu(0,t.length)],this.createParse(t,n||[],r)}parse(t,n,r){let s=this.startParse(t,n,r);for(;;){let a=s.advance();if(a)return a}}}class xst{constructor(t){this.string=t}get length(){return this.string.length}chunk(t){return this.string.slice(t)}get lineChunks(){return!1}read(t,n){return this.string.slice(t,n)}}function XAt(e){return(t,n,r,s)=>new yst(t,e,n,r,s)}class jX{constructor(t,n,r,s,a,o){this.parser=t,this.parse=n,this.overlay=r,this.bracketed=s,this.target=a,this.from=o}}function NX(e){if(!e.length||e.some(t=>t.from>=t.to))throw new RangeError("Invalid inner parse ranges given: "+JSON.stringify(e))}class bst{constructor(t,n,r,s,a,o,l,c){this.parser=t,this.predicate=n,this.mounts=r,this.index=s,this.start=a,this.bracketed=o,this.target=l,this.prev=c,this.depth=0,this.ranges=[]}}const c$=new jr({perNode:!0});class yst{constructor(t,n,r,s,a){this.nest=n,this.input=r,this.fragments=s,this.ranges=a,this.inner=[],this.innerDone=0,this.baseTree=null,this.stoppedAt=null,this.baseParse=t}advance(){if(this.baseParse){let r=this.baseParse.advance();if(!r)return null;if(this.baseParse=null,this.baseTree=r,this.startInner(),this.stoppedAt!=null)for(let s of this.inner)s.parse.stopAt(this.stoppedAt)}if(this.innerDone==this.inner.length){let r=this.baseTree;return this.stoppedAt!=null&&(r=new zs(r.type,r.children,r.positions,r.length,r.propValues.concat([[c$,this.stoppedAt]]))),r}let t=this.inner[this.innerDone],n=t.parse.advance();if(n){this.innerDone++;let r=Object.assign(Object.create(null),t.target.props);r[jr.mounted.id]=new Q0(n,t.overlay,t.parser,t.bracketed),t.target.props=r}return null}get parsedPos(){if(this.baseParse)return 0;let t=this.input.length;for(let n=this.innerDone;n<this.inner.length;n++)this.inner[n].from<t&&(t=Math.min(t,this.inner[n].parse.parsedPos));return t}stopAt(t){if(this.stoppedAt=t,this.baseParse)this.baseParse.stopAt(t);else for(let n=this.innerDone;n<this.inner.length;n++)this.inner[n].parse.stopAt(t)}startInner(){let t=new kst(this.fragments),n=null,r=null,s=new PE(new qo(this.baseTree,this.ranges[0].from,0,null),$s.IncludeAnonymous|$s.IgnoreMounts);e:for(let a,o;;){let l=!0,c;if(this.stoppedAt!=null&&s.from>=this.stoppedAt)l=!1;else if(t.hasNode(s)){if(n){let u=n.mounts.find(d=>d.frag.from<=s.from&&d.frag.to>=s.to&&d.mount.overlay);if(u)for(let d of u.mount.overlay){let h=d.from+u.pos,m=d.to+u.pos;h>=s.from&&m<=s.to&&!n.ranges.some(g=>g.from<m&&g.to>h)&&n.ranges.push({from:h,to:m})}}l=!1}else if(r&&(o=vst(r.ranges,s.from,s.to)))l=o!=2;else if(!s.type.isAnonymous&&(a=this.nest(s,this.input))&&(s.from<s.to||!a.overlay)){s.tree||(wst(s),n&&n.depth++,r&&r.depth++);let u=t.findMounts(s.from,a.parser);if(typeof a.overlay=="function")n=new bst(a.parser,a.overlay,u,this.inner.length,s.from,!!a.bracketed,s.tree,n);else{let d=_X(this.ranges,a.overlay||(s.from<s.to?[new tu(s.from,s.to)]:[]));d.length&&NX(d),(d.length||!a.overlay)&&this.inner.push(new jX(a.parser,d.length?a.parser.startParse(this.input,AX(u,d),d):a.parser.startParse(""),a.overlay?a.overlay.map(h=>new tu(h.from-s.from,h.to-s.from)):null,!!a.bracketed,s.tree,d.length?d[0].from:s.from)),a.overlay?d.length&&(r={ranges:d,depth:0,prev:r}):l=!1}}else if(n&&(c=n.predicate(s))&&(c===!0&&(c=new tu(s.from,s.to)),c.from<c.to)){let u=n.ranges.length-1;u>=0&&n.ranges[u].to==c.from?n.ranges[u]={from:n.ranges[u].from,to:c.to}:n.ranges.push(c)}if(l&&s.firstChild())n&&n.depth++,r&&r.depth++;else for(;!s.nextSibling();){if(!s.parent())break e;if(n&&!--n.depth){let u=_X(this.ranges,n.ranges);u.length&&(NX(u),this.inner.splice(n.index,0,new jX(n.parser,n.parser.startParse(this.input,AX(n.mounts,u),u),n.ranges.map(d=>new tu(d.from-n.start,d.to-n.start)),n.bracketed,n.target,u[0].from))),n=n.prev}r&&!--r.depth&&(r=r.prev)}}}}function vst(e,t,n){for(let r of e){if(r.from>=n)break;if(r.to>t)return r.from<=t&&r.to>=n?2:1}return 0}function CX(e,t,n,r,s,a){if(t<n){let o=e.buffer[t+1];r.push(e.slice(t,n,o)),s.push(o-a)}}function wst(e){let{node:t}=e,n=[],r=t.context.buffer;do n.push(e.index),e.parent();while(!e.tree);let s=e.tree,a=s.children.indexOf(r),o=s.children[a],l=o.buffer,c=[a];function u(d,h,m,g,b,v){let j=n[v],k=[],w=[];CX(o,d,j,k,w,g);let N=l[j+1],S=l[j+2];c.push(k.length);let A=v?u(j+4,l[j+3],o.set.types[l[j]],N,S-N,v-1):t.toTree();return k.push(A),w.push(N-g),CX(o,l[j+3],h,k,w,g),new zs(m,k,w,b)}s.children[a]=u(0,l.length,jl.none,0,o.length,n.length-1);for(let d of c){let h=e.tree.children[d],m=e.tree.positions[d];e.yield(new qo(h,m+e.from,d,e._tree))}}class SX{constructor(t,n){this.offset=n,this.done=!1,this.cursor=t.cursor($s.IncludeAnonymous|$s.IgnoreMounts)}moveTo(t){let{cursor:n}=this,r=t-this.offset;for(;!this.done&&n.from<r;)n.to>=t&&n.enter(r,1,$s.IgnoreOverlays|$s.ExcludeBuffers)||n.next(!1)||(this.done=!0)}hasNode(t){if(this.moveTo(t.from),!this.done&&this.cursor.from+this.offset==t.from&&this.cursor.tree)for(let n=this.cursor.tree;;){if(n==t.tree)return!0;if(n.children.length&&n.positions[0]==0&&n.children[0]instanceof zs)n=n.children[0];else break}return!1}}class kst{constructor(t){var n;if(this.fragments=t,this.curTo=0,this.fragI=0,t.length){let r=this.curFrag=t[0];this.curTo=(n=r.tree.prop(c$))!==null&&n!==void 0?n:r.to,this.inner=new SX(r.tree,-r.offset)}else this.curFrag=this.inner=null}hasNode(t){for(;this.curFrag&&t.from>=this.curTo;)this.nextFrag();return this.curFrag&&this.curFrag.from<=t.from&&this.curTo>=t.to&&this.inner.hasNode(t)}nextFrag(){var t;if(this.fragI++,this.fragI==this.fragments.length)this.curFrag=this.inner=null;else{let n=this.curFrag=this.fragments[this.fragI];this.curTo=(t=n.tree.prop(c$))!==null&&t!==void 0?t:n.to,this.inner=new SX(n.tree,-n.offset)}}findMounts(t,n){var r;let s=[];if(this.inner){this.inner.cursor.moveTo(t,1);for(let a=this.inner.cursor.node;a;a=a.parent){let o=(r=a.tree)===null||r===void 0?void 0:r.prop(jr.mounted);if(o&&o.parser==n)for(let l=this.fragI;l<this.fragments.length;l++){let c=this.fragments[l];if(c.from>=a.to)break;c.tree==this.curFrag.tree&&s.push({frag:c,pos:a.from-c.offset,mount:o})}}}return s}}function _X(e,t){let n=null,r=t;for(let s=1,a=0;s<e.length;s++){let o=e[s-1].to,l=e[s].from;for(;a<r.length;a++){let c=r[a];if(c.from>=l)break;c.to<=o||(n||(r=n=t.slice()),c.from<o?(n[a]=new tu(c.from,o),c.to>l&&n.splice(a+1,0,new tu(l,c.to))):c.to>l?n[a--]=new tu(l,c.to):n.splice(a--,1))}}return r}function jst(e,t,n,r){let s=0,a=0,o=!1,l=!1,c=-1e9,u=[];for(;;){let d=s==e.length?1e9:o?e[s].to:e[s].from,h=a==t.length?1e9:l?t[a].to:t[a].from;if(o!=l){let m=Math.max(c,n),g=Math.min(d,h,r);m<g&&u.push(new tu(m,g))}if(c=Math.min(d,h),c==1e9)break;d==c&&(o?(o=!1,s++):o=!0),h==c&&(l?(l=!1,a++):l=!0)}return u}function AX(e,t){let n=[];for(let{pos:r,mount:s,frag:a}of e){let o=r+(s.overlay?s.overlay[0].from:0),l=o+s.tree.length,c=Math.max(a.from,o),u=Math.min(a.to,l);if(s.overlay){let d=s.overlay.map(m=>new tu(m.from+r,m.to+r)),h=jst(t,d,c,u);for(let m=0,g=c;;m++){let b=m==h.length,v=b?u:h[m].from;if(v>g&&n.push(new $h(g,v,s.tree,-o,a.from>=g||a.openStart,a.to<=v||a.openEnd)),b)break;g=h[m].to}}else n.push(new $h(c,u,s.tree,-o,a.from>=o||a.openStart,a.to<=l||a.openEnd))}return n}let Nst=0;class Qc{constructor(t,n,r,s){this.name=t,this.set=n,this.base=r,this.modified=s,this.id=Nst++}toString(){let{name:t}=this;for(let n of this.modified)n.name&&(t=`${n.name}(${t})`);return t}static define(t,n){let r=typeof t=="string"?t:"?";if(t instanceof Qc&&(n=t),n!=null&&n.base)throw new Error("Can not derive from a modified tag");let s=new Qc(r,[],null,[]);if(s.set.push(s),n)for(let a of n.set)s.set.push(a);return s}static defineModifier(t){let n=new LE(t);return r=>r.modified.indexOf(n)>-1?r:LE.get(r.base||r,r.modified.concat(n).sort((s,a)=>s.id-a.id))}}let Cst=0;class LE{constructor(t){this.name=t,this.instances=[],this.id=Cst++}static get(t,n){if(!n.length)return t;let r=n[0].instances.find(l=>l.base==t&&Sst(n,l.modified));if(r)return r;let s=[],a=new Qc(t.name,s,t,n);for(let l of n)l.instances.push(a);let o=_st(n);for(let l of t.set)if(!l.modified.length)for(let c of o)s.push(LE.get(l,c));return a}}function Sst(e,t){return e.length==t.length&&e.every((n,r)=>n==t[r])}function _st(e){let t=[[]];for(let n=0;n<e.length;n++)for(let r=0,s=t.length;r<s;r++)t.push(t[r].concat(e[n]));return t.sort((n,r)=>r.length-n.length)}function Ast(e){let t=Object.create(null);for(let n in e){let r=e[n];Array.isArray(r)||(r=[r]);for(let s of n.split(" "))if(s){let a=[],o=2,l=s;for(let h=0;;){if(l=="..."&&h>0&&h+3==s.length){o=1;break}let m=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(l);if(!m)throw new RangeError("Invalid path: "+s);if(a.push(m[0]=="*"?"":m[0][0]=='"'?JSON.parse(m[0]):m[0]),h+=m[0].length,h==s.length)break;let g=s[h++];if(h==s.length&&g=="!"){o=0;break}if(g!="/")throw new RangeError("Invalid path: "+s);l=s.slice(h)}let c=a.length-1,u=a[c];if(!u)throw new RangeError("Invalid path: "+s);let d=new RN(r,o,c>0?a.slice(0,c):null);t[u]=d.sort(t[u])}}return Vye.add(t)}const Vye=new jr({combine(e,t){let n,r,s;for(;e||t;){if(!e||t&&e.depth>=t.depth?(s=t,t=t.next):(s=e,e=e.next),n&&n.mode==s.mode&&!s.context&&!n.context)continue;let a=new RN(s.tags,s.mode,s.context);n?n.next=a:r=a,n=a}return r}});class RN{constructor(t,n,r,s){this.tags=t,this.mode=n,this.context=r,this.next=s}get opaque(){return this.mode==0}get inherit(){return this.mode==1}sort(t){return!t||t.depth<this.depth?(this.next=t,this):(t.next=this.sort(t.next),t)}get depth(){return this.context?this.context.length:0}}RN.empty=new RN([],2,null);function Hye(e,t){let n=Object.create(null);for(let a of e)if(!Array.isArray(a.tag))n[a.tag.id]=a.class;else for(let o of a.tag)n[o.id]=a.class;let{scope:r,all:s=null}=t||{};return{style:a=>{let o=s;for(let l of a)for(let c of l.set){let u=n[c.id];if(u){o=o?o+" "+u:u;break}}return o},scope:r}}function Est(e,t){let n=null;for(let r of e){let s=r.style(t);s&&(n=n?n+" "+s:s)}return n}function Tst(e,t,n,r=0,s=e.length){let a=new Ist(r,Array.isArray(t)?t:[t],n);a.highlightRange(e.cursor(),r,s,"",a.highlighters),a.flush(s)}class Ist{constructor(t,n,r){this.at=t,this.highlighters=n,this.span=r,this.class=""}startSpan(t,n){n!=this.class&&(this.flush(t),t>this.at&&(this.at=t),this.class=n)}flush(t){t>this.at&&this.class&&this.span(this.at,t,this.class)}highlightRange(t,n,r,s,a){let{type:o,from:l,to:c}=t;if(l>=r||c<=n)return;o.isTop&&(a=this.highlighters.filter(g=>!g.scope||g.scope(o)));let u=s,d=Rst(t)||RN.empty,h=Est(a,d.tags);if(h&&(u&&(u+=" "),u+=h,d.mode==1&&(s+=(s?" ":"")+h)),this.startSpan(Math.max(n,l),u),d.opaque)return;let m=t.tree&&t.tree.prop(jr.mounted);if(m&&m.overlay){let g=t.node.enter(m.overlay[0].from+l,1),b=this.highlighters.filter(j=>!j.scope||j.scope(m.tree.type)),v=t.firstChild();for(let j=0,k=l;;j++){let w=j<m.overlay.length?m.overlay[j]:null,N=w?w.from+l:c,S=Math.max(n,k),A=Math.min(r,N);if(S<A&&v)for(;t.from<A&&(this.highlightRange(t,S,A,s,a),this.startSpan(Math.min(A,t.to),u),!(t.to>=N||!t.nextSibling())););if(!w||N>r)break;k=w.to+l,k>n&&(this.highlightRange(g.cursor(),Math.max(n,w.from+l),Math.min(r,k),"",b),this.startSpan(Math.min(r,k),u))}v&&t.parent()}else if(t.firstChild()){m&&(s="");do if(!(t.to<=n)){if(t.from>=r)break;this.highlightRange(t,n,r,s,a),this.startSpan(Math.min(r,t.to),u)}while(t.nextSibling());t.parent()}}}function Rst(e){let t=e.type.prop(Vye);for(;t&&t.context&&!e.matchContext(t.context);)t=t.next;return t||null}const Bt=Qc.define,S_=Bt(),op=Bt(),EX=Bt(op),TX=Bt(op),lp=Bt(),__=Bt(lp),cD=Bt(lp),Fd=Bt(),mx=Bt(Fd),Rd=Bt(),Md=Bt(),u$=Bt(),dk=Bt(u$),A_=Bt(),ct={comment:S_,lineComment:Bt(S_),blockComment:Bt(S_),docComment:Bt(S_),name:op,variableName:Bt(op),typeName:EX,tagName:Bt(EX),propertyName:TX,attributeName:Bt(TX),className:Bt(op),labelName:Bt(op),namespace:Bt(op),macroName:Bt(op),literal:lp,string:__,docString:Bt(__),character:Bt(__),attributeValue:Bt(__),number:cD,integer:Bt(cD),float:Bt(cD),bool:Bt(lp),regexp:Bt(lp),escape:Bt(lp),color:Bt(lp),url:Bt(lp),keyword:Rd,self:Bt(Rd),null:Bt(Rd),atom:Bt(Rd),unit:Bt(Rd),modifier:Bt(Rd),operatorKeyword:Bt(Rd),controlKeyword:Bt(Rd),definitionKeyword:Bt(Rd),moduleKeyword:Bt(Rd),operator:Md,derefOperator:Bt(Md),arithmeticOperator:Bt(Md),logicOperator:Bt(Md),bitwiseOperator:Bt(Md),compareOperator:Bt(Md),updateOperator:Bt(Md),definitionOperator:Bt(Md),typeOperator:Bt(Md),controlOperator:Bt(Md),punctuation:u$,separator:Bt(u$),bracket:dk,angleBracket:Bt(dk),squareBracket:Bt(dk),paren:Bt(dk),brace:Bt(dk),content:Fd,heading:mx,heading1:Bt(mx),heading2:Bt(mx),heading3:Bt(mx),heading4:Bt(mx),heading5:Bt(mx),heading6:Bt(mx),contentSeparator:Bt(Fd),list:Bt(Fd),quote:Bt(Fd),emphasis:Bt(Fd),strong:Bt(Fd),link:Bt(Fd),monospace:Bt(Fd),strikethrough:Bt(Fd),inserted:Bt(),deleted:Bt(),changed:Bt(),invalid:Bt(),meta:A_,documentMeta:Bt(A_),annotation:Bt(A_),processingInstruction:Bt(A_),definition:Qc.defineModifier("definition"),constant:Qc.defineModifier("constant"),function:Qc.defineModifier("function"),standard:Qc.defineModifier("standard"),local:Qc.defineModifier("local"),special:Qc.defineModifier("special")};for(let e in ct){let t=ct[e];t instanceof Qc&&(t.name=e)}Hye([{tag:ct.link,class:"tok-link"},{tag:ct.heading,class:"tok-heading"},{tag:ct.emphasis,class:"tok-emphasis"},{tag:ct.strong,class:"tok-strong"},{tag:ct.keyword,class:"tok-keyword"},{tag:ct.atom,class:"tok-atom"},{tag:ct.bool,class:"tok-bool"},{tag:ct.url,class:"tok-url"},{tag:ct.labelName,class:"tok-labelName"},{tag:ct.inserted,class:"tok-inserted"},{tag:ct.deleted,class:"tok-deleted"},{tag:ct.literal,class:"tok-literal"},{tag:ct.string,class:"tok-string"},{tag:ct.number,class:"tok-number"},{tag:[ct.regexp,ct.escape,ct.special(ct.string)],class:"tok-string2"},{tag:ct.variableName,class:"tok-variableName"},{tag:ct.local(ct.variableName),class:"tok-variableName tok-local"},{tag:ct.definition(ct.variableName),class:"tok-variableName tok-definition"},{tag:ct.special(ct.variableName),class:"tok-variableName2"},{tag:ct.definition(ct.propertyName),class:"tok-propertyName tok-definition"},{tag:ct.typeName,class:"tok-typeName"},{tag:ct.namespace,class:"tok-namespace"},{tag:ct.className,class:"tok-className"},{tag:ct.macroName,class:"tok-macroName"},{tag:ct.propertyName,class:"tok-propertyName"},{tag:ct.operator,class:"tok-operator"},{tag:ct.comment,class:"tok-comment"},{tag:ct.meta,class:"tok-meta"},{tag:ct.invalid,class:"tok-invalid"},{tag:ct.punctuation,class:"tok-punctuation"}]);var uD;const $x=new jr;function Kye(e){return Zt.define({combine:e?t=>t.concat(e):void 0})}const Mst=new jr;class nu{constructor(t,n,r=[],s=""){this.data=t,this.name=s,Ur.prototype.hasOwnProperty("tree")||Object.defineProperty(Ur.prototype,"tree",{get(){return wo(this)}}),this.parser=n,this.extension=[Ng.of(this),Ur.languageData.of((a,o,l)=>{let c=IX(a,o,l),u=c.type.prop($x);if(!u)return[];let d=a.facet(u),h=c.type.prop(Mst);if(h){let m=c.resolve(o-c.from,l);for(let g of h)if(g.test(m,a)){let b=a.facet(g.facet);return g.type=="replace"?b:b.concat(d)}}return d})].concat(r)}isActiveAt(t,n,r=-1){return IX(t,n,r).type.prop($x)==this.data}findRegions(t){let n=t.facet(Ng);if((n==null?void 0:n.data)==this.data)return[{from:0,to:t.doc.length}];if(!n||!n.allowsNesting)return[];let r=[],s=(a,o)=>{if(a.prop($x)==this.data){r.push({from:o,to:o+a.length});return}let l=a.prop(jr.mounted);if(l){if(l.tree.prop($x)==this.data){if(l.overlay)for(let c of l.overlay)r.push({from:c.from+o,to:c.to+o});else r.push({from:o,to:o+a.length});return}else if(l.overlay){let c=r.length;if(s(l.tree,l.overlay[0].from+o),r.length>c)return}}for(let c=0;c<a.children.length;c++){let u=a.children[c];u instanceof zs&&s(u,a.positions[c]+o)}};return s(wo(t),0),r}get allowsNesting(){return!0}}nu.setState=Yn.define();function IX(e,t,n){let r=e.facet(Ng),s=wo(e).topNode;if(!r||r.allowsNesting)for(let a=s;a;a=a.enter(t,n,$s.ExcludeBuffers|$s.EnterBracketed))a.type.isTop&&(s=a);return s}class d$ extends nu{constructor(t,n,r){super(t,n,[],r),this.parser=n}static define(t){let n=Kye(t.languageData);return new d$(n,t.parser.configure({props:[$x.add(r=>r.isTop?n:void 0)]}),t.name)}configure(t,n){return new d$(this.data,this.parser.configure(t),n||this.name)}get allowsNesting(){return this.parser.hasWrappers()}}function wo(e){let t=e.field(nu.state,!1);return t?t.tree:zs.empty}class Ost{constructor(t){this.doc=t,this.cursorPos=0,this.string="",this.cursor=t.iter()}get length(){return this.doc.length}syncTo(t){return this.string=this.cursor.next(t-this.cursorPos).value,this.cursorPos=t+this.string.length,this.cursorPos-this.string.length}chunk(t){return this.syncTo(t),this.string}get lineChunks(){return!0}read(t,n){let r=this.cursorPos-this.string.length;return t<r||n>=this.cursorPos?this.doc.sliceString(t,n):this.string.slice(t-r,n-r)}}let fk=null;class Gv{constructor(t,n,r=[],s,a,o,l,c){this.parser=t,this.state=n,this.fragments=r,this.tree=s,this.treeLen=a,this.viewport=o,this.skipped=l,this.scheduleOn=c,this.parse=null,this.tempSkipped=[]}static create(t,n,r){return new Gv(t,n,[],zs.empty,0,r,[],null)}startParse(){return this.parser.startParse(new Ost(this.state.doc),this.fragments)}work(t,n){return n!=null&&n>=this.state.doc.length&&(n=void 0),this.tree!=zs.empty&&this.isDone(n??this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var r;if(typeof t=="number"){let s=Date.now()+t;t=()=>Date.now()>s}for(this.parse||(this.parse=this.startParse()),n!=null&&(this.parse.stoppedAt==null||this.parse.stoppedAt>n)&&n<this.state.doc.length&&this.parse.stopAt(n);;){let s=this.parse.advance();if(s)if(this.fragments=this.withoutTempSkipped($h.addTree(s,this.fragments,this.parse.stoppedAt!=null)),this.treeLen=(r=this.parse.stoppedAt)!==null&&r!==void 0?r:this.state.doc.length,this.tree=s,this.parse=null,this.treeLen<(n??this.state.doc.length))this.parse=this.startParse();else return!0;if(t())return!1}})}takeTree(){let t,n;this.parse&&(t=this.parse.parsedPos)>=this.treeLen&&((this.parse.stoppedAt==null||this.parse.stoppedAt>t)&&this.parse.stopAt(t),this.withContext(()=>{for(;!(n=this.parse.advance()););}),this.treeLen=t,this.tree=n,this.fragments=this.withoutTempSkipped($h.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(t){let n=fk;fk=this;try{return t()}finally{fk=n}}withoutTempSkipped(t){for(let n;n=this.tempSkipped.pop();)t=RX(t,n.from,n.to);return t}changes(t,n){let{fragments:r,tree:s,treeLen:a,viewport:o,skipped:l}=this;if(this.takeTree(),!t.empty){let c=[];if(t.iterChangedRanges((u,d,h,m)=>c.push({fromA:u,toA:d,fromB:h,toB:m})),r=$h.applyChanges(r,c),s=zs.empty,a=0,o={from:t.mapPos(o.from,-1),to:t.mapPos(o.to,1)},this.skipped.length){l=[];for(let u of this.skipped){let d=t.mapPos(u.from,1),h=t.mapPos(u.to,-1);d<h&&l.push({from:d,to:h})}}}return new Gv(this.parser,n,r,s,a,o,l,this.scheduleOn)}updateViewport(t){if(this.viewport.from==t.from&&this.viewport.to==t.to)return!1;this.viewport=t;let n=this.skipped.length;for(let r=0;r<this.skipped.length;r++){let{from:s,to:a}=this.skipped[r];s<t.to&&a>t.from&&(this.fragments=RX(this.fragments,s,a),this.skipped.splice(r--,1))}return this.skipped.length>=n?!1:(this.reset(),!0)}reset(){this.parse&&(this.takeTree(),this.parse=null)}skipUntilInView(t,n){this.skipped.push({from:t,to:n})}static getSkippingParser(t){return new class extends qye{createParse(n,r,s){let a=s[0].from,o=s[s.length-1].to;return{parsedPos:a,advance(){let c=fk;if(c){for(let u of s)c.tempSkipped.push(u);t&&(c.scheduleOn=c.scheduleOn?Promise.all([c.scheduleOn,t]):t)}return this.parsedPos=o,new zs(jl.none,[],[],o-a)},stoppedAt:null,stopAt(){}}}}}isDone(t){t=Math.min(t,this.state.doc.length);let n=this.fragments;return this.treeLen>=t&&n.length&&n[0].from==0&&n[0].to>=t}static get(){return fk}}function RX(e,t,n){return $h.applyChanges(e,[{fromA:t,toA:n,fromB:t,toB:n}])}class Qv{constructor(t){this.context=t,this.tree=t.tree}apply(t){if(!t.docChanged&&this.tree==this.context.tree)return this;let n=this.context.changes(t.changes,t.state),r=this.context.treeLen==t.startState.doc.length?void 0:Math.max(t.changes.mapPos(this.context.treeLen),n.viewport.to);return n.work(20,r)||n.takeTree(),new Qv(n)}static init(t){let n=Math.min(3e3,t.doc.length),r=Gv.create(t.facet(Ng).parser,t,{from:0,to:n});return r.work(20,n)||r.takeTree(),new Qv(r)}}nu.state=ko.define({create:Qv.init,update(e,t){for(let n of t.effects)if(n.is(nu.setState))return n.value;return t.startState.facet(Ng)!=t.state.facet(Ng)?Qv.init(t.state):e.apply(t)}});let Wye=e=>{let t=setTimeout(()=>e(),500);return()=>clearTimeout(t)};typeof requestIdleCallback<"u"&&(Wye=e=>{let t=-1,n=setTimeout(()=>{t=requestIdleCallback(e,{timeout:400})},100);return()=>t<0?clearTimeout(n):cancelIdleCallback(t)});const dD=typeof navigator<"u"&&(!((uD=navigator.scheduling)===null||uD===void 0)&&uD.isInputPending)?()=>navigator.scheduling.isInputPending():null,Dst=Vi.fromClass(class{constructor(t){this.view=t,this.working=null,this.workScheduled=0,this.chunkEnd=-1,this.chunkBudget=-1,this.work=this.work.bind(this),this.scheduleWork()}update(t){let n=this.view.state.field(nu.state).context;(n.updateViewport(t.view.viewport)||this.view.viewport.to>n.treeLen)&&this.scheduleWork(),(t.docChanged||t.selectionSet)&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(n)}scheduleWork(){if(this.working)return;let{state:t}=this.view,n=t.field(nu.state);(n.tree!=n.context.tree||!n.context.isDone(t.doc.length))&&(this.working=Wye(this.work))}work(t){this.working=null;let n=Date.now();if(this.chunkEnd<n&&(this.chunkEnd<0||this.view.hasFocus)&&(this.chunkEnd=n+3e4,this.chunkBudget=3e3),this.chunkBudget<=0)return;let{state:r,viewport:{to:s}}=this.view,a=r.field(nu.state);if(a.tree==a.context.tree&&a.context.isDone(s+1e5))return;let o=Date.now()+Math.min(this.chunkBudget,100,t&&!dD?Math.max(25,t.timeRemaining()-5):1e9),l=a.context.treeLen<s&&r.doc.length>s+1e3,c=a.context.work(()=>dD&&dD()||Date.now()>o,s+(l?0:1e5));this.chunkBudget-=Date.now()-n,(c||this.chunkBudget<=0)&&(a.context.takeTree(),this.view.dispatch({effects:nu.setState.of(new Qv(a.context))})),this.chunkBudget>0&&!(c&&!l)&&this.scheduleWork(),this.checkAsyncSchedule(a.context)}checkAsyncSchedule(t){t.scheduleOn&&(this.workScheduled++,t.scheduleOn.then(()=>this.scheduleWork()).catch(n=>Ul(this.view.state,n)).then(()=>this.workScheduled--),t.scheduleOn=null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),Ng=Zt.define({combine(e){return e.length?e[0]:null},enables:e=>[nu.state,Dst,Yt.contentAttributes.compute([e],t=>{let n=t.facet(e);return n&&n.name?{"data-language":n.name}:{}})]});class Pst{constructor(t,n=[]){this.language=t,this.support=n,this.extension=[t,n]}}class st{constructor(t,n,r,s,a,o=void 0){this.name=t,this.alias=n,this.extensions=r,this.filename=s,this.loadFunc=a,this.support=o,this.loading=null}load(){return this.loading||(this.loading=this.loadFunc().then(t=>this.support=t,t=>{throw this.loading=null,t}))}static of(t){let{load:n,support:r}=t;if(!n){if(!r)throw new RangeError("Must pass either 'load' or 'support' to LanguageDescription.of");n=()=>Promise.resolve(r)}return new st(t.name,(t.alias||[]).concat(t.name).map(s=>s.toLowerCase()),t.extensions||[],t.filename,n,r)}static matchFilename(t,n){for(let s of t)if(s.filename&&s.filename.test(n))return s;let r=/\.([^.]+)$/.exec(n);if(r){for(let s of t)if(s.extensions.indexOf(r[1])>-1)return s}return null}static matchLanguageName(t,n,r=!0){n=n.toLowerCase();for(let s of t)if(s.alias.some(a=>a==n))return s;if(r)for(let s of t)for(let a of s.alias){let o=n.indexOf(a);if(o>-1&&(a.length>2||!/\w/.test(n[o-1])&&!/\w/.test(n[o+a.length])))return s}return null}}const Lst=Zt.define(),MI=Zt.define({combine:e=>{if(!e.length)return" ";let t=e[0];if(!t||/\S/.test(t)||Array.from(t).some(n=>n!=t[0]))throw new Error("Invalid indent unit: "+JSON.stringify(e[0]));return t}});function Wb(e){let t=e.facet(MI);return t.charCodeAt(0)==9?e.tabSize*t.length:t.length}function MN(e,t){let n="",r=e.tabSize,s=e.facet(MI)[0];if(s==" "){for(;t>=r;)n+=" ",t-=r;s=" "}for(let a=0;a<t;a++)n+=s;return n}function KB(e,t){e instanceof Ur&&(e=new OI(e));for(let r of e.state.facet(Lst)){let s=r(e,t);if(s!==void 0)return s}let n=wo(e.state);return n.length>=t?$st(e,n,t):null}class OI{constructor(t,n={}){this.state=t,this.options=n,this.unit=Wb(t)}lineAt(t,n=1){let r=this.state.doc.lineAt(t),{simulateBreak:s,simulateDoubleBreak:a}=this.options;return s!=null&&s>=r.from&&s<=r.to?a&&s==t?{text:"",from:t}:(n<0?s<t:s<=t)?{text:r.text.slice(s-r.from),from:s}:{text:r.text.slice(0,s-r.from),from:r.from}:r}textAfterPos(t,n=1){if(this.options.simulateDoubleBreak&&t==this.options.simulateBreak)return"";let{text:r,from:s}=this.lineAt(t,n);return r.slice(t-s,Math.min(r.length,t+100-s))}column(t,n=1){let{text:r,from:s}=this.lineAt(t,n),a=this.countColumn(r,t-s),o=this.options.overrideIndentation?this.options.overrideIndentation(s):-1;return o>-1&&(a+=o-this.countColumn(r,r.search(/\S|$/))),a}countColumn(t,n=t.length){return U1(t,this.state.tabSize,n)}lineIndent(t,n=1){let{text:r,from:s}=this.lineAt(t,n),a=this.options.overrideIndentation;if(a){let o=a(s);if(o>-1)return o}return this.countColumn(r,r.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}}const Gye=new jr;function $st(e,t,n){let r=t.resolveStack(n),s=t.resolveInner(n,-1).resolve(n,0).enterUnfinishedNodesBefore(n);if(s!=r.node){let a=[];for(let o=s;o&&!(o.from<r.node.from||o.to>r.node.to||o.from==r.node.from&&o.type==r.node.type);o=o.parent)a.push(o);for(let o=a.length-1;o>=0;o--)r={node:a[o],next:r}}return Qye(r,e,n)}function Qye(e,t,n){for(let r=e;r;r=r.next){let s=zst(r.node);if(s)return s(WB.create(t,n,r))}return 0}function Fst(e){return e.pos==e.options.simulateBreak&&e.options.simulateDoubleBreak}function zst(e){let t=e.type.prop(Gye);if(t)return t;let n=e.firstChild,r;if(n&&(r=n.type.prop(jr.closedBy))){let s=e.lastChild,a=s&&r.indexOf(s.name)>-1;return o=>Yye(o,!0,1,void 0,a&&!Fst(o)?s.from:void 0)}return e.parent==null?Bst:null}function Bst(){return 0}class WB extends OI{constructor(t,n,r){super(t.state,t.options),this.base=t,this.pos=n,this.context=r}get node(){return this.context.node}static create(t,n,r){return new WB(t,n,r)}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){return this.baseIndentFor(this.node)}baseIndentFor(t){let n=this.state.doc.lineAt(t.from);for(;;){let r=t.resolve(n.from);for(;r.parent&&r.parent.from==r.from;)r=r.parent;if(Ust(r,t))break;n=this.state.doc.lineAt(r.from)}return this.lineIndent(n.from)}continue(){return Qye(this.context.next,this.base,this.pos)}}function Ust(e,t){for(let n=t;n;n=n.parent)if(e==n)return!0;return!1}function qst(e){let t=e.node,n=t.childAfter(t.from),r=t.lastChild;if(!n)return null;let s=e.options.simulateBreak,a=e.state.doc.lineAt(n.from),o=s==null||s<=a.from?a.to:Math.min(a.to,s);for(let l=n.to;;){let c=t.childAfter(l);if(!c||c==r)return null;if(!c.type.isSkipped){if(c.from>=o)return null;let u=/^ */.exec(a.text.slice(n.to-a.from))[0].length;return{from:n.from,to:n.to+u}}l=c.to}}function tEt({closing:e,align:t=!0,units:n=1}){return r=>Yye(r,t,n,e)}function Yye(e,t,n,r,s){let a=e.textAfter,o=a.match(/^\s*/)[0].length,l=r&&a.slice(o,o+r.length)==r||s==e.pos+o,c=t?qst(e):null;return c?l?e.column(c.from):e.column(c.to):e.baseIndent+(l?0:e.unit*n)}const nEt=e=>e.baseIndent;function rEt({except:e,units:t=1}={}){return n=>{let r=e&&e.test(n.textAfter);return n.baseIndent+(r?0:t*n.unit)}}const Vst=200;function Hst(){return Ur.transactionFilter.of(e=>{if(!e.docChanged||!e.isUserEvent("input.type")&&!e.isUserEvent("input.complete"))return e;let t=e.startState.languageDataAt("indentOnInput",e.startState.selection.main.head);if(!t.length)return e;let n=e.newDoc,{head:r}=e.newSelection.main,s=n.lineAt(r);if(r>s.from+Vst)return e;let a=n.sliceString(s.from,r);if(!t.some(u=>u.test(a)))return e;let{state:o}=e,l=-1,c=[];for(let{head:u}of o.selection.ranges){let d=o.doc.lineAt(u);if(d.from==l)continue;l=d.from;let h=KB(o,d.from);if(h==null)continue;let m=/^\s*/.exec(d.text)[0],g=MN(o,h);m!=g&&c.push({from:d.from,to:d.from+m.length,insert:g})}return c.length?[e,{changes:c,sequential:!0}]:e})}const Kst=Zt.define(),Wst=new jr;function sEt(e){let t=e.firstChild,n=e.lastChild;return t&&t.to<n.from?{from:t.to,to:n.type.isError?e.to:n.from}:null}function Gst(e,t,n){let r=wo(e);if(r.length<n)return null;let s=r.resolveStack(n,1),a=null;for(let o=s;o;o=o.next){let l=o.node;if(l.to<=n||l.from>n)continue;if(a&&l.from<t)break;let c=l.type.prop(Wst);if(c&&(l.to<r.length-50||r.length==e.doc.length||!Qst(l))){let u=c(l,e);u&&u.from<=n&&u.from>=t&&u.to>n&&(a=u)}}return a}function Qst(e){let t=e.lastChild;return t&&t.to==e.to&&t.type.isError}function $E(e,t,n){for(let r of e.facet(Kst)){let s=r(e,t,n);if(s)return s}return Gst(e,t,n)}function Jye(e,t){let n=t.mapPos(e.from,1),r=t.mapPos(e.to,-1);return n>=r?void 0:{from:n,to:r}}const DI=Yn.define({map:Jye}),QC=Yn.define({map:Jye});function Zye(e){let t=[];for(let{head:n}of e.state.selection.ranges)t.some(r=>r.from<=n&&r.to>=n)||t.push(e.lineBlockAt(n));return t}const Gb=ko.define({create(){return En.none},update(e,t){t.isUserEvent("delete")&&t.changes.iterChangedRanges((n,r)=>e=MX(e,n,r)),e=e.map(t.changes);for(let n of t.effects)if(n.is(DI)&&!Yst(e,n.value.from,n.value.to)){let{preparePlaceholder:r}=t.state.facet(t0e),s=r?En.replace({widget:new rit(r(t.state,n.value))}):OX;e=e.update({add:[s.range(n.value.from,n.value.to)]})}else n.is(QC)&&(e=e.update({filter:(r,s)=>n.value.from!=r||n.value.to!=s,filterFrom:n.value.from,filterTo:n.value.to}));return t.selection&&(e=MX(e,t.selection.main.head)),e},provide:e=>Yt.decorations.from(e),toJSON(e,t){let n=[];return e.between(0,t.doc.length,(r,s)=>{n.push(r,s)}),n},fromJSON(e){if(!Array.isArray(e)||e.length%2)throw new RangeError("Invalid JSON for fold state");let t=[];for(let n=0;n<e.length;){let r=e[n++],s=e[n++];if(typeof r!="number"||typeof s!="number")throw new RangeError("Invalid JSON for fold state");t.push(OX.range(r,s))}return En.set(t,!0)}});function MX(e,t,n=t){let r=!1;return e.between(t,n,(s,a)=>{s<n&&a>t&&(r=!0)}),r?e.update({filterFrom:t,filterTo:n,filter:(s,a)=>s>=n||a<=t}):e}function FE(e,t,n){var r;let s=null;return(r=e.field(Gb,!1))===null||r===void 0||r.between(t,n,(a,o)=>{(!s||s.from>a)&&(s={from:a,to:o})}),s}function Yst(e,t,n){let r=!1;return e.between(t,t,(s,a)=>{s==t&&a==n&&(r=!0)}),r}function Xye(e,t){return e.field(Gb,!1)?t:t.concat(Yn.appendConfig.of(n0e()))}const Jst=e=>{for(let t of Zye(e)){let n=$E(e.state,t.from,t.to);if(n)return e.dispatch({effects:Xye(e.state,[DI.of(n),e0e(e,n)])}),!0}return!1},Zst=e=>{if(!e.state.field(Gb,!1))return!1;let t=[];for(let n of Zye(e)){let r=FE(e.state,n.from,n.to);r&&t.push(QC.of(r),e0e(e,r,!1))}return t.length&&e.dispatch({effects:t}),t.length>0};function e0e(e,t,n=!0){let r=e.state.doc.lineAt(t.from).number,s=e.state.doc.lineAt(t.to).number;return Yt.announce.of(`${e.state.phrase(n?"Folded lines":"Unfolded lines")} ${r} ${e.state.phrase("to")} ${s}.`)}const Xst=e=>{let{state:t}=e,n=[];for(let r=0;r<t.doc.length;){let s=e.lineBlockAt(r),a=$E(t,s.from,s.to);a&&n.push(DI.of(a)),r=(a?e.lineBlockAt(a.to):s).to+1}return n.length&&e.dispatch({effects:Xye(e.state,n)}),!!n.length},eit=e=>{let t=e.state.field(Gb,!1);if(!t||!t.size)return!1;let n=[];return t.between(0,e.state.doc.length,(r,s)=>{n.push(QC.of({from:r,to:s}))}),e.dispatch({effects:n}),!0},tit=[{key:"Ctrl-Shift-[",mac:"Cmd-Alt-[",run:Jst},{key:"Ctrl-Shift-]",mac:"Cmd-Alt-]",run:Zst},{key:"Ctrl-Alt-[",run:Xst},{key:"Ctrl-Alt-]",run:eit}],nit={placeholderDOM:null,preparePlaceholder:null,placeholderText:"…"},t0e=Zt.define({combine(e){return Pf(e,nit)}});function n0e(e){return[Gb,ait]}function r0e(e,t){let{state:n}=e,r=n.facet(t0e),s=o=>{let l=e.lineBlockAt(e.posAtDOM(o.target)),c=FE(e.state,l.from,l.to);c&&e.dispatch({effects:QC.of(c)}),o.preventDefault()};if(r.placeholderDOM)return r.placeholderDOM(e,s,t);let a=document.createElement("span");return a.textContent=r.placeholderText,a.setAttribute("aria-label",n.phrase("folded code")),a.title=n.phrase("unfold"),a.className="cm-foldPlaceholder",a.onclick=s,a}const OX=En.replace({widget:new class extends Lf{toDOM(e){return r0e(e,null)}}});class rit extends Lf{constructor(t){super(),this.value=t}eq(t){return this.value==t.value}toDOM(t){return r0e(t,this.value)}}const sit={openText:"⌄",closedText:"›",markerDOM:null,domEventHandlers:{},foldingChanged:()=>!1};class fD extends rm{constructor(t,n){super(),this.config=t,this.open=n}eq(t){return this.config==t.config&&this.open==t.open}toDOM(t){if(this.config.markerDOM)return this.config.markerDOM(this.open);let n=document.createElement("span");return n.textContent=this.open?this.config.openText:this.config.closedText,n.title=t.state.phrase(this.open?"Fold line":"Unfold line"),n}}function iit(e={}){let t={...sit,...e},n=new fD(t,!0),r=new fD(t,!1),s=Vi.fromClass(class{constructor(o){this.from=o.viewport.from,this.markers=this.buildMarkers(o)}update(o){(o.docChanged||o.viewportChanged||o.startState.facet(Ng)!=o.state.facet(Ng)||o.startState.field(Gb,!1)!=o.state.field(Gb,!1)||wo(o.startState)!=wo(o.state)||t.foldingChanged(o))&&(this.markers=this.buildMarkers(o.view))}buildMarkers(o){let l=new tm;for(let c of o.viewportLineBlocks){let u=FE(o.state,c.from,c.to)?r:$E(o.state,c.from,c.to)?n:null;u&&l.add(c.from,c.from,u)}return l.finish()}}),{domEventHandlers:a}=t;return[s,est({class:"cm-foldGutter",markers(o){var l;return((l=o.plugin(s))===null||l===void 0?void 0:l.markers)||_r.empty},initialSpacer(){return new fD(t,!1)},domEventHandlers:{...a,click:(o,l,c)=>{if(a.click&&a.click(o,l,c))return!0;let u=FE(o.state,l.from,l.to);if(u)return o.dispatch({effects:QC.of(u)}),!0;let d=$E(o.state,l.from,l.to);return d?(o.dispatch({effects:DI.of(d)}),!0):!1}}}),n0e()]}const ait=Yt.baseTheme({".cm-foldPlaceholder":{backgroundColor:"#eee",border:"1px solid #ddd",color:"#888",borderRadius:".2em",margin:"0 1px",padding:"0 1px",cursor:"pointer"},".cm-foldGutter span":{padding:"0 1px",cursor:"pointer"}});class YC{constructor(t,n){this.specs=t;let r;function s(l){let c=vg.newName();return(r||(r=Object.create(null)))["."+c]=l,c}const a=typeof n.all=="string"?n.all:n.all?s(n.all):void 0,o=n.scope;this.scope=o instanceof nu?l=>l.prop($x)==o.data:o?l=>l==o:void 0,this.style=Hye(t.map(l=>({tag:l.tag,class:l.class||s(Object.assign({},l,{tag:null}))})),{all:a}).style,this.module=r?new vg(r):null,this.themeType=n.themeType}static define(t,n){return new YC(t,n||{})}}const f$=Zt.define(),s0e=Zt.define({combine(e){return e.length?[e[0]]:null}});function hD(e){let t=e.facet(f$);return t.length?t:e.facet(s0e)}function i0e(e,t){let n=[lit],r;return e instanceof YC&&(e.module&&n.push(Yt.styleModule.of(e.module)),r=e.themeType),t!=null&&t.fallback?n.push(s0e.of(e)):r?n.push(f$.computeN([Yt.darkTheme],s=>s.facet(Yt.darkTheme)==(r=="dark")?[e]:[])):n.push(f$.of(e)),n}class oit{constructor(t){this.markCache=Object.create(null),this.tree=wo(t.state),this.decorations=this.buildDeco(t,hD(t.state)),this.decoratedTo=t.viewport.to}update(t){let n=wo(t.state),r=hD(t.state),s=r!=hD(t.startState),{viewport:a}=t.view,o=t.changes.mapPos(this.decoratedTo,1);n.length<a.to&&!s&&n.type==this.tree.type&&o>=a.to?(this.decorations=this.decorations.map(t.changes),this.decoratedTo=o):(n!=this.tree||t.viewportChanged||s)&&(this.tree=n,this.decorations=this.buildDeco(t.view,r),this.decoratedTo=a.to)}buildDeco(t,n){if(!n||!this.tree.length)return En.none;let r=new tm;for(let{from:s,to:a}of t.visibleRanges)Tst(this.tree,n,(o,l,c)=>{r.add(o,l,this.markCache[c]||(this.markCache[c]=En.mark({class:c})))},s,a);return r.finish()}}const lit=Bg.high(Vi.fromClass(oit,{decorations:e=>e.decorations})),cit=YC.define([{tag:ct.meta,color:"#404740"},{tag:ct.link,textDecoration:"underline"},{tag:ct.heading,textDecoration:"underline",fontWeight:"bold"},{tag:ct.emphasis,fontStyle:"italic"},{tag:ct.strong,fontWeight:"bold"},{tag:ct.strikethrough,textDecoration:"line-through"},{tag:ct.keyword,color:"#708"},{tag:[ct.atom,ct.bool,ct.url,ct.contentSeparator,ct.labelName],color:"#219"},{tag:[ct.literal,ct.inserted],color:"#164"},{tag:[ct.string,ct.deleted],color:"#a11"},{tag:[ct.regexp,ct.escape,ct.special(ct.string)],color:"#e40"},{tag:ct.definition(ct.variableName),color:"#00f"},{tag:ct.local(ct.variableName),color:"#30a"},{tag:[ct.typeName,ct.namespace],color:"#085"},{tag:ct.className,color:"#167"},{tag:[ct.special(ct.variableName),ct.macroName],color:"#256"},{tag:ct.definition(ct.propertyName),color:"#00c"},{tag:ct.comment,color:"#940"},{tag:ct.invalid,color:"#f00"}]),uit=Yt.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}}),a0e=1e4,o0e="()[]{}",l0e=Zt.define({combine(e){return Pf(e,{afterCursor:!0,brackets:o0e,maxScanDistance:a0e,renderMatch:hit})}}),dit=En.mark({class:"cm-matchingBracket"}),fit=En.mark({class:"cm-nonmatchingBracket"});function hit(e){let t=[],n=e.matched?dit:fit;return t.push(n.range(e.start.from,e.start.to)),e.end&&t.push(n.range(e.end.from,e.end.to)),t}function DX(e){let t=[],n=e.facet(l0e);for(let r of e.selection.ranges){if(!r.empty)continue;let s=uf(e,r.head,-1,n)||r.head>0&&uf(e,r.head-1,1,n)||n.afterCursor&&(uf(e,r.head,1,n)||r.head<e.doc.length&&uf(e,r.head+1,-1,n));s&&(t=t.concat(n.renderMatch(s,e)))}return En.set(t,!0)}const mit=Vi.fromClass(class{constructor(e){this.paused=!1,this.decorations=DX(e.state)}update(e){(e.docChanged||e.selectionSet||this.paused)&&(e.view.composing?(this.decorations=this.decorations.map(e.changes),this.paused=!0):(this.decorations=DX(e.state),this.paused=!1))}},{decorations:e=>e.decorations}),pit=[mit,uit];function git(e={}){return[l0e.of(e),pit]}const xit=new jr;function h$(e,t,n){let r=e.prop(t<0?jr.openedBy:jr.closedBy);if(r)return r;if(e.name.length==1){let s=n.indexOf(e.name);if(s>-1&&s%2==(t<0?1:0))return[n[s+t]]}return null}function m$(e){let t=e.type.prop(xit);return t?t(e.node):e}function uf(e,t,n,r={}){let s=r.maxScanDistance||a0e,a=r.brackets||o0e,o=wo(e),l=o.resolveInner(t,n);for(let c=l;c;c=c.parent){let u=h$(c.type,n,a);if(u&&c.from<c.to){let d=m$(c);if(d&&(n>0?t>=d.from&&t<d.to:t>d.from&&t<=d.to))return bit(e,t,n,c,d,u,a)}}return yit(e,t,n,o,l.type,s,a)}function bit(e,t,n,r,s,a,o){let l=r.parent,c={from:s.from,to:s.to},u=0,d=l==null?void 0:l.cursor();if(d&&(n<0?d.childBefore(r.from):d.childAfter(r.to)))do if(n<0?d.to<=r.from:d.from>=r.to){if(u==0&&a.indexOf(d.type.name)>-1&&d.from<d.to){let h=m$(d);return{start:c,end:h?{from:h.from,to:h.to}:void 0,matched:!0}}else if(h$(d.type,n,o))u++;else if(h$(d.type,-n,o)){if(u==0){let h=m$(d);return{start:c,end:h&&h.from<h.to?{from:h.from,to:h.to}:void 0,matched:!1}}u--}}while(n<0?d.prevSibling():d.nextSibling());return{start:c,matched:!1}}function yit(e,t,n,r,s,a,o){let l=n<0?e.sliceDoc(t-1,t):e.sliceDoc(t,t+1),c=o.indexOf(l);if(c<0||c%2==0!=n>0)return null;let u={from:n<0?t-1:t,to:n>0?t+1:t},d=e.doc.iterRange(t,n>0?e.doc.length:0),h=0;for(let m=0;!d.next().done&&m<=a;){let g=d.value;n<0&&(m+=g.length);let b=t+m*n;for(let v=n>0?0:g.length-1,j=n>0?g.length:-1;v!=j;v+=n){let k=o.indexOf(g[v]);if(!(k<0||r.resolveInner(b+v,1).type!=s))if(k%2==0==n>0)h++;else{if(h==1)return{start:u,end:{from:b+v,to:b+v+1},matched:k>>1==c>>1};h--}}n>0&&(m+=g.length)}return d.done?{start:u,matched:!1}:null}function PX(e,t,n,r=0,s=0){t==null&&(t=e.search(/[^\s\u00a0]/),t==-1&&(t=e.length));let a=s;for(let o=r;o<t;o++)e.charCodeAt(o)==9?a+=n-a%n:a++;return a}class c0e{constructor(t,n,r,s){this.string=t,this.tabSize=n,this.indentUnit=r,this.overrideIndent=s,this.pos=0,this.start=0,this.lastColumnPos=0,this.lastColumnValue=0}eol(){return this.pos>=this.string.length}sol(){return this.pos==0}peek(){return this.string.charAt(this.pos)||void 0}next(){if(this.pos<this.string.length)return this.string.charAt(this.pos++)}eat(t){let n=this.string.charAt(this.pos),r;if(typeof t=="string"?r=n==t:r=n&&(t instanceof RegExp?t.test(n):t(n)),r)return++this.pos,n}eatWhile(t){let n=this.pos;for(;this.eat(t););return this.pos>n}eatSpace(){let t=this.pos;for(;/[\s\u00a0]/.test(this.string.charAt(this.pos));)++this.pos;return this.pos>t}skipToEnd(){this.pos=this.string.length}skipTo(t){let n=this.string.indexOf(t,this.pos);if(n>-1)return this.pos=n,!0}backUp(t){this.pos-=t}column(){return this.lastColumnPos<this.start&&(this.lastColumnValue=PX(this.string,this.start,this.tabSize,this.lastColumnPos,this.lastColumnValue),this.lastColumnPos=this.start),this.lastColumnValue}indentation(){var t;return(t=this.overrideIndent)!==null&&t!==void 0?t:PX(this.string,null,this.tabSize)}match(t,n,r){if(typeof t=="string"){let s=o=>r?o.toLowerCase():o,a=this.string.substr(this.pos,t.length);return s(a)==s(t)?(n!==!1&&(this.pos+=t.length),!0):null}else{let s=this.string.slice(this.pos).match(t);return s&&s.index>0?null:(s&&n!==!1&&(this.pos+=s[0].length),s)}}current(){return this.string.slice(this.start,this.pos)}}function vit(e){return{name:e.name||"",token:e.token,blankLine:e.blankLine||(()=>{}),startState:e.startState||(()=>!0),copyState:e.copyState||wit,indent:e.indent||(()=>null),languageData:e.languageData||{},tokenTable:e.tokenTable||YB,mergeTokens:e.mergeTokens!==!1}}function wit(e){if(typeof e!="object")return e;let t={};for(let n in e){let r=e[n];t[n]=r instanceof Array?r.slice():r}return t}const LX=new WeakMap;class GB extends nu{constructor(t){let n=Kye(t.languageData),r=vit(t),s,a=new class extends qye{createParse(o,l,c){return new jit(s,o,l,c)}};super(n,a,[],t.name),this.topNode=Sit(n,this),s=this,this.streamParser=r,this.stateAfter=new jr({perNode:!0}),this.tokenTable=t.tokenTable?new h0e(r.tokenTable):Cit}static define(t){return new GB(t)}getIndent(t){let n,{overrideIndentation:r}=t.options;r&&(n=LX.get(t.state),n!=null&&n<t.pos-1e4&&(n=void 0));let s=QB(this,t.node.tree,t.node.from,t.node.from,n??t.pos),a,o;if(s?(o=s.state,a=s.pos+1):(o=this.streamParser.startState(t.unit),a=t.node.from),t.pos-a>1e4)return null;for(;a<t.pos;){let c=t.state.doc.lineAt(a),u=Math.min(t.pos,c.to);if(c.length){let d=r?r(c.from):-1,h=new c0e(c.text,t.state.tabSize,t.unit,d<0?void 0:d);for(;h.pos<u-c.from;)d0e(this.streamParser.token,h,o)}else this.streamParser.blankLine(o,t.unit);if(u==t.pos)break;a=c.to+1}let l=t.lineAt(t.pos);return r&&n==null&&LX.set(t.state,l.from),this.streamParser.indent(o,/^\s*(.*)/.exec(l.text)[1],t)}get allowsNesting(){return!1}}function QB(e,t,n,r,s){let a=n>=r&&n+t.length<=s&&t.prop(e.stateAfter);if(a)return{state:e.streamParser.copyState(a),pos:n+t.length};for(let o=t.children.length-1;o>=0;o--){let l=t.children[o],c=n+t.positions[o],u=l instanceof zs&&c<s&&QB(e,l,c,r,s);if(u)return u}return null}function u0e(e,t,n,r,s){if(s&&n<=0&&r>=t.length)return t;!s&&n==0&&t.type==e.topNode&&(s=!0);for(let a=t.children.length-1;a>=0;a--){let o=t.positions[a],l=t.children[a],c;if(o<r&&l instanceof zs){if(!(c=u0e(e,l,n-o,r-o,s)))break;return s?new zs(t.type,t.children.slice(0,a).concat(c),t.positions.slice(0,a+1),o+c.length):c}}return null}function kit(e,t,n,r,s){for(let a of t){let o=a.from+(a.openStart?25:0),l=a.to-(a.openEnd?25:0),c=o<=n&&l>n&&QB(e,a.tree,0-a.offset,n,l),u;if(c&&c.pos<=r&&(u=u0e(e,a.tree,n+a.offset,c.pos+a.offset,!1)))return{state:c.state,tree:u}}return{state:e.streamParser.startState(s?Wb(s):4),tree:zs.empty}}class jit{constructor(t,n,r,s){this.lang=t,this.input=n,this.fragments=r,this.ranges=s,this.stoppedAt=null,this.chunks=[],this.chunkPos=[],this.chunk=[],this.chunkReused=void 0,this.rangeIndex=0,this.to=s[s.length-1].to;let a=Gv.get(),o=s[0].from,{state:l,tree:c}=kit(t,r,o,this.to,a==null?void 0:a.state);this.state=l,this.parsedPos=this.chunkStart=o+c.length;for(let u=0;u<c.children.length;u++)this.chunks.push(c.children[u]),this.chunkPos.push(c.positions[u]);a&&this.parsedPos<a.viewport.from-1e5&&s.some(u=>u.from<=a.viewport.from&&u.to>=a.viewport.from)&&(this.state=this.lang.streamParser.startState(Wb(a.state)),a.skipUntilInView(this.parsedPos,a.viewport.from),this.parsedPos=a.viewport.from),this.moveRangeIndex()}advance(){let t=Gv.get(),n=this.stoppedAt==null?this.to:Math.min(this.to,this.stoppedAt),r=Math.min(n,this.chunkStart+512);for(t&&(r=Math.min(r,t.viewport.to));this.parsedPos<r;)this.parseLine(t);return this.chunkStart<this.parsedPos&&this.finishChunk(),this.parsedPos>=n?this.finish():t&&this.parsedPos>=t.viewport.to?(t.skipUntilInView(this.parsedPos,n),this.finish()):null}stopAt(t){this.stoppedAt=t}lineAfter(t){let n=this.input.chunk(t);if(this.input.lineChunks)n==`
1281
1281
  `&&(n="");else{let r=n.indexOf(`
1282
- `);r>-1&&(n=n.slice(0,r))}return t+n.length<=this.to?n:n.slice(0,this.to-t)}nextLine(){let t=this.parsedPos,n=this.lineAfter(t),r=t+n.length;for(let s=this.rangeIndex;;){let a=this.ranges[s].to;if(a>=r||(n=n.slice(0,a-(r-n.length)),s++,s==this.ranges.length))break;let o=this.ranges[s].from,l=this.lineAfter(o);n+=l,r=o+l.length}return{line:n,end:r}}skipGapsTo(t,n,r){for(;;){let s=this.ranges[this.rangeIndex].to,a=t+n;if(r>0?s>a:s>=a)break;let o=this.ranges[++this.rangeIndex].from;n+=o-s}return n}moveRangeIndex(){for(;this.ranges[this.rangeIndex].to<this.parsedPos;)this.rangeIndex++}emitToken(t,n,r,s){let a=4;if(this.ranges.length>1){s=this.skipGapsTo(n,s,1),n+=s;let l=this.chunk.length;s=this.skipGapsTo(r,s,-1),r+=s,a+=this.chunk.length-l}let o=this.chunk.length-4;return this.lang.streamParser.mergeTokens&&a==4&&o>=0&&this.chunk[o]==t&&this.chunk[o+2]==n?this.chunk[o+2]=r:this.chunk.push(t,n,r,a),s}parseLine(t){let{line:n,end:r}=this.nextLine(),s=0,{streamParser:a}=this.lang,o=new c0e(n,t?t.state.tabSize:4,t?Wb(t.state):2);if(o.eol())a.blankLine(this.state,o.indentUnit);else for(;!o.eol();){let l=d0e(a.token,o,this.state);if(l&&(s=this.emitToken(this.lang.tokenTable.resolve(l),this.parsedPos+o.start,this.parsedPos+o.pos,s)),o.start>1e4)break}this.parsedPos=r,this.moveRangeIndex(),this.parsedPos<this.to&&this.parsedPos++}finishChunk(){let t=zs.build({buffer:this.chunk,start:this.chunkStart,length:this.parsedPos-this.chunkStart,nodeSet:Nit,topID:0,maxBufferLength:512,reused:this.chunkReused});t=new zs(t.type,t.children,t.positions,t.length,[[this.lang.stateAfter,this.lang.streamParser.copyState(this.state)]]),this.chunks.push(t),this.chunkPos.push(this.chunkStart-this.ranges[0].from),this.chunk=[],this.chunkReused=void 0,this.chunkStart=this.parsedPos}finish(){return new zs(this.lang.topNode,this.chunks,this.chunkPos,this.parsedPos-this.ranges[0].from).balance()}}function d0e(e,t,n){t.start=t.pos;for(let r=0;r<10;r++){let s=e(t,n);if(t.pos>t.start)return s}throw new Error("Stream parser failed to advance stream.")}const YB=Object.create(null),ON=[jl.none],Nit=new UB(ON),$X=[],FX=Object.create(null),f0e=Object.create(null);for(let[e,t]of[["variable","variableName"],["variable-2","variableName.special"],["string-2","string.special"],["def","variableName.definition"],["tag","tagName"],["attribute","attributeName"],["type","typeName"],["builtin","variableName.standard"],["qualifier","modifier"],["error","invalid"],["header","heading"],["property","propertyName"]])f0e[e]=m0e(YB,t);class h0e{constructor(t){this.extra=t,this.table=Object.assign(Object.create(null),f0e)}resolve(t){return t?this.table[t]||(this.table[t]=m0e(this.extra,t)):0}}const Cit=new h0e(YB);function mD(e,t){$X.indexOf(e)>-1||($X.push(e),console.warn(t))}function m0e(e,t){let n=[];for(let l of t.split(" ")){let c=[];for(let u of l.split(".")){let d=e[u]||ct[u];d?typeof d=="function"?c.length?c=c.map(d):mD(u,`Modifier ${u} used at start of tag`):c.length?mD(u,`Tag ${u} used as modifier`):c=Array.isArray(d)?d:[d]:mD(u,`Unknown highlighting tag ${u}`)}for(let u of c)n.push(u)}if(!n.length)return 0;let r=t.replace(/ /g,"_"),s=r+" "+n.map(l=>l.id),a=FX[s];if(a)return a.id;let o=FX[s]=jl.define({id:ON.length,name:r,props:[Ast({[r]:n})]});return ON.push(o),o.id}function Sit(e,t){let n=jl.define({id:ON.length,name:"Document",props:[$x.add(()=>e),Gye.add(()=>r=>t.getIndent(r))],top:!0});return ON.push(n),n}Fs.RTL,Fs.LTR;class p0e{constructor(t,n,r,s){this.state=t,this.pos=n,this.explicit=r,this.view=s,this.abortListeners=[],this.abortOnDocChange=!1}tokenBefore(t){let n=wo(this.state).resolveInner(this.pos,-1);for(;n&&t.indexOf(n.name)<0;)n=n.parent;return n?{from:n.from,to:this.pos,text:this.state.sliceDoc(n.from,this.pos),type:n.type}:null}matchBefore(t){let n=this.state.doc.lineAt(this.pos),r=Math.max(n.from,this.pos-250),s=n.text.slice(r-n.from,this.pos-n.from),a=s.search(g0e(t,!1));return a<0?null:{from:r+a,to:this.pos,text:s.slice(a)}}get aborted(){return this.abortListeners==null}addEventListener(t,n,r){t=="abort"&&this.abortListeners&&(this.abortListeners.push(n),r&&r.onDocChange&&(this.abortOnDocChange=!0))}}function zX(e){let t=Object.keys(e).join(""),n=/\w/.test(t);return n&&(t=t.replace(/\w/g,"")),`[${n?"\\w":""}${t.replace(/[^\w\s]/g,"\\$&")}]`}function _it(e){let t=Object.create(null),n=Object.create(null);for(let{label:s}of e){t[s[0]]=!0;for(let a=1;a<s.length;a++)n[s[a]]=!0}let r=zX(t)+zX(n)+"*$";return[new RegExp("^"+r),new RegExp(r)]}function Ait(e){let t=e.map(s=>typeof s=="string"?{label:s}:s),[n,r]=t.every(s=>/^\w+$/.test(s.label))?[/\w*$/,/\w+$/]:_it(t);return s=>{let a=s.matchBefore(r);return a||s.explicit?{from:a?a.from:s.pos,options:t,validFor:n}:null}}function iEt(e,t){return n=>{for(let r=wo(n.state).resolveInner(n.pos,-1);r;r=r.parent){if(e.indexOf(r.name)>-1)return null;if(r.type.isTop)break}return t(n)}}class BX{constructor(t,n,r,s){this.completion=t,this.source=n,this.match=r,this.score=s}}function ob(e){return e.selection.main.from}function g0e(e,t){var n;let{source:r}=e,s=t&&r[0]!="^",a=r[r.length-1]!="$";return!s&&!a?e:new RegExp(`${s?"^":""}(?:${r})${a?"$":""}`,(n=e.flags)!==null&&n!==void 0?n:e.ignoreCase?"i":"")}const JB=gm.define();function Eit(e,t,n,r){let{main:s}=e.selection,a=n-s.from,o=r-s.from;return{...e.changeByRange(l=>{if(l!=s&&n!=r&&e.sliceDoc(l.from+a,l.from+o)!=e.sliceDoc(n,r))return{range:l};let c=e.toText(t);return{changes:{from:l.from+a,to:r==s.from?l.to:l.from+o,insert:c},range:xt.cursor(l.from+a+c.length)}}),scrollIntoView:!0,userEvent:"input.complete"}}const UX=new WeakMap;function Tit(e){if(!Array.isArray(e))return e;let t=UX.get(e);return t||UX.set(e,t=Ait(e)),t}const zE=Yn.define(),DN=Yn.define();class Iit{constructor(t){this.pattern=t,this.chars=[],this.folded=[],this.any=[],this.precise=[],this.byWord=[],this.score=0,this.matched=[];for(let n=0;n<t.length;){let r=Fl(t,n),s=ef(r);this.chars.push(r);let a=t.slice(n,n+s),o=a.toUpperCase();this.folded.push(Fl(o==a?a.toLowerCase():o,0)),n+=s}this.astral=t.length!=this.chars.length}ret(t,n){return this.score=t,this.matched=n,this}match(t){if(this.pattern.length==0)return this.ret(-100,[]);if(t.length<this.pattern.length)return null;let{chars:n,folded:r,any:s,precise:a,byWord:o}=this;if(n.length==1){let w=Fl(t,0),N=ef(w),S=N==t.length?0:-100;if(w!=n[0])if(w==r[0])S+=-200;else return null;return this.ret(S,[0,N])}let l=t.indexOf(this.pattern);if(l==0)return this.ret(t.length==this.pattern.length?0:-100,[0,this.pattern.length]);let c=n.length,u=0;if(l<0){for(let w=0,N=Math.min(t.length,200);w<N&&u<c;){let S=Fl(t,w);(S==n[u]||S==r[u])&&(s[u++]=w),w+=ef(S)}if(u<c)return null}let d=0,h=0,m=!1,g=0,b=-1,v=-1,j=/[a-z]/.test(t),k=!0;for(let w=0,N=Math.min(t.length,200),S=0;w<N&&h<c;){let A=Fl(t,w);l<0&&(d<c&&A==n[d]&&(a[d++]=w),g<c&&(A==n[g]||A==r[g]?(g==0&&(b=w),v=w+1,g++):g=0));let _,E=A<255?A>=48&&A<=57||A>=97&&A<=122?2:A>=65&&A<=90?1:0:(_=jB(A))!=_.toLowerCase()?1:_!=_.toUpperCase()?2:0;(!w||E==1&&j||S==0&&E!=0)&&(n[h]==A||r[h]==A&&(m=!0)?o[h++]=w:o.length&&(k=!1)),S=E,w+=ef(A)}return h==c&&o[0]==0&&k?this.result(-100+(m?-200:0),o,t):g==c&&b==0?this.ret(-200-t.length+(v==t.length?0:-100),[0,v]):l>-1?this.ret(-700-t.length,[l,l+this.pattern.length]):g==c?this.ret(-900-t.length,[b,v]):h==c?this.result(-100+(m?-200:0)+-700+(k?0:-1100),o,t):n.length==2?null:this.result((s[0]?-700:0)+-200+-1100,s,t)}result(t,n,r){let s=[],a=0;for(let o of n){let l=o+(this.astral?ef(Fl(r,o)):1);a&&s[a-1]==o?s[a-1]=l:(s[a++]=o,s[a++]=l)}return this.ret(t-r.length,s)}}class Rit{constructor(t){this.pattern=t,this.matched=[],this.score=0,this.folded=t.toLowerCase()}match(t){if(t.length<this.pattern.length)return null;let n=t.slice(0,this.pattern.length),r=n==this.pattern?0:n.toLowerCase()==this.folded?-200:null;return r==null?null:(this.matched=[0,n.length],this.score=r+(t.length==this.pattern.length?0:-100),this)}}const $a=Zt.define({combine(e){return Pf(e,{activateOnTyping:!0,activateOnCompletion:()=>!1,activateOnTypingDelay:100,selectOnOpen:!0,override:null,closeOnBlur:!0,maxRenderedOptions:100,defaultKeymap:!0,tooltipClass:()=>"",optionClass:()=>"",aboveCursor:!1,icons:!0,addToOptions:[],positionInfo:Mit,filterStrict:!1,compareCompletions:(t,n)=>(t.sortText||t.label).localeCompare(n.sortText||n.label),interactionDelay:75,updateSyncTime:100},{defaultKeymap:(t,n)=>t&&n,closeOnBlur:(t,n)=>t&&n,icons:(t,n)=>t&&n,tooltipClass:(t,n)=>r=>qX(t(r),n(r)),optionClass:(t,n)=>r=>qX(t(r),n(r)),addToOptions:(t,n)=>t.concat(n),filterStrict:(t,n)=>t||n})}});function qX(e,t){return e?t?e+" "+t:e:t}function Mit(e,t,n,r,s,a){let o=e.textDirection==Fs.RTL,l=o,c=!1,u="top",d,h,m=t.left-s.left,g=s.right-t.right,b=r.right-r.left,v=r.bottom-r.top;if(l&&m<Math.min(b,g)?l=!1:!l&&g<Math.min(b,m)&&(l=!0),b<=(l?m:g))d=Math.max(s.top,Math.min(n.top,s.bottom-v))-t.top,h=Math.min(400,l?m:g);else{c=!0,h=Math.min(400,(o?t.right:s.right-t.left)-30);let w=s.bottom-t.bottom;w>=v||w>t.top?d=n.bottom-t.top:(u="bottom",d=t.bottom-n.top)}let j=(t.bottom-t.top)/a.offsetHeight,k=(t.right-t.left)/a.offsetWidth;return{style:`${u}: ${d/j}px; max-width: ${h/k}px`,class:"cm-completionInfo-"+(c?o?"left-narrow":"right-narrow":l?"left":"right")}}const ZB=Yn.define();function Oit(e){let t=e.addToOptions.slice();return e.icons&&t.push({render(n){let r=document.createElement("div");return r.classList.add("cm-completionIcon"),n.type&&r.classList.add(...n.type.split(/\s+/g).map(s=>"cm-completionIcon-"+s)),r.setAttribute("aria-hidden","true"),r},position:20}),t.push({render(n,r,s,a){let o=document.createElement("span");o.className="cm-completionLabel";let l=n.displayLabel||n.label,c=0;for(let u=0;u<a.length;){let d=a[u++],h=a[u++];d>c&&o.appendChild(document.createTextNode(l.slice(c,d)));let m=o.appendChild(document.createElement("span"));m.appendChild(document.createTextNode(l.slice(d,h))),m.className="cm-completionMatchedText",c=h}return c<l.length&&o.appendChild(document.createTextNode(l.slice(c))),o},position:50},{render(n){if(!n.detail)return null;let r=document.createElement("span");return r.className="cm-completionDetail",r.textContent=n.detail,r},position:80}),t.sort((n,r)=>n.position-r.position).map(n=>n.render)}function pD(e,t,n){if(e<=n)return{from:0,to:e};if(t<0&&(t=0),t<=e>>1){let s=Math.floor(t/n);return{from:s*n,to:(s+1)*n}}let r=Math.floor((e-t)/n);return{from:e-(r+1)*n,to:e-r*n}}class Dit{constructor(t,n,r){this.view=t,this.stateField=n,this.applyCompletion=r,this.info=null,this.infoDestroy=null,this.placeInfoReq={read:()=>this.measureInfo(),write:c=>this.placeInfo(c),key:this},this.space=null,this.currentClass="";let s=t.state.field(n),{options:a,selected:o}=s.open,l=t.state.facet($a);this.optionContent=Oit(l),this.optionClass=l.optionClass,this.tooltipClass=l.tooltipClass,this.range=pD(a.length,o,l.maxRenderedOptions),this.dom=document.createElement("div"),this.dom.className="cm-tooltip-autocomplete",this.updateTooltipClass(t.state),this.dom.addEventListener("mousedown",c=>{let{options:u}=t.state.field(n).open;for(let d=c.target,h;d&&d!=this.dom;d=d.parentNode)if(d.nodeName=="LI"&&(h=/-(\d+)$/.exec(d.id))&&+h[1]<u.length){this.applyCompletion(t,u[+h[1]]),c.preventDefault();return}if(c.target==this.list){let d=this.list.classList.contains("cm-completionListIncompleteTop")&&c.clientY<this.list.firstChild.getBoundingClientRect().top?this.range.from-1:this.list.classList.contains("cm-completionListIncompleteBottom")&&c.clientY>this.list.lastChild.getBoundingClientRect().bottom?this.range.to:null;d!=null&&(t.dispatch({effects:ZB.of(d)}),c.preventDefault())}}),this.dom.addEventListener("focusout",c=>{let u=t.state.field(this.stateField,!1);u&&u.tooltip&&t.state.facet($a).closeOnBlur&&c.relatedTarget!=t.contentDOM&&t.dispatch({effects:DN.of(null)})}),this.showOptions(a,s.id)}mount(){this.updateSel()}showOptions(t,n){this.list&&this.list.remove(),this.list=this.dom.appendChild(this.createListBox(t,n,this.range)),this.list.addEventListener("scroll",()=>{this.info&&this.view.requestMeasure(this.placeInfoReq)})}update(t){var n;let r=t.state.field(this.stateField),s=t.startState.field(this.stateField);if(this.updateTooltipClass(t.state),r!=s){let{options:a,selected:o,disabled:l}=r.open;(!s.open||s.open.options!=a)&&(this.range=pD(a.length,o,t.state.facet($a).maxRenderedOptions),this.showOptions(a,r.id)),this.updateSel(),l!=((n=s.open)===null||n===void 0?void 0:n.disabled)&&this.dom.classList.toggle("cm-tooltip-autocomplete-disabled",!!l)}}updateTooltipClass(t){let n=this.tooltipClass(t);if(n!=this.currentClass){for(let r of this.currentClass.split(" "))r&&this.dom.classList.remove(r);for(let r of n.split(" "))r&&this.dom.classList.add(r);this.currentClass=n}}positioned(t){this.space=t,this.info&&this.view.requestMeasure(this.placeInfoReq)}updateSel(){let t=this.view.state.field(this.stateField),n=t.open;(n.selected>-1&&n.selected<this.range.from||n.selected>=this.range.to)&&(this.range=pD(n.options.length,n.selected,this.view.state.facet($a).maxRenderedOptions),this.showOptions(n.options,t.id));let r=this.updateSelectedOption(n.selected);if(r){this.destroyInfo();let{completion:s}=n.options[n.selected],{info:a}=s;if(!a)return;let o=typeof a=="string"?document.createTextNode(a):a(s);if(!o)return;"then"in o?o.then(l=>{l&&this.view.state.field(this.stateField,!1)==t&&this.addInfoPane(l,s)}).catch(l=>Ul(this.view.state,l,"completion info")):(this.addInfoPane(o,s),r.setAttribute("aria-describedby",this.info.id))}}addInfoPane(t,n){this.destroyInfo();let r=this.info=document.createElement("div");if(r.className="cm-tooltip cm-completionInfo",r.id="cm-completionInfo-"+Math.floor(Math.random()*65535).toString(16),t.nodeType!=null)r.appendChild(t),this.infoDestroy=null;else{let{dom:s,destroy:a}=t;r.appendChild(s),this.infoDestroy=a||null}this.dom.appendChild(r),this.view.requestMeasure(this.placeInfoReq)}updateSelectedOption(t){let n=null;for(let r=this.list.firstChild,s=this.range.from;r;r=r.nextSibling,s++)r.nodeName!="LI"||!r.id?s--:s==t?r.hasAttribute("aria-selected")||(r.setAttribute("aria-selected","true"),n=r):r.hasAttribute("aria-selected")&&(r.removeAttribute("aria-selected"),r.removeAttribute("aria-describedby"));return n&&Lit(this.list,n),n}measureInfo(){let t=this.dom.querySelector("[aria-selected]");if(!t||!this.info)return null;let n=this.dom.getBoundingClientRect(),r=this.info.getBoundingClientRect(),s=t.getBoundingClientRect(),a=this.space;if(!a){let o=this.dom.ownerDocument.documentElement;a={left:0,top:0,right:o.clientWidth,bottom:o.clientHeight}}return s.top>Math.min(a.bottom,n.bottom)-10||s.bottom<Math.max(a.top,n.top)+10?null:this.view.state.facet($a).positionInfo(this.view,n,s,r,a,this.dom)}placeInfo(t){this.info&&(t?(t.style&&(this.info.style.cssText=t.style),this.info.className="cm-tooltip cm-completionInfo "+(t.class||"")):this.info.style.cssText="top: -1e6px")}createListBox(t,n,r){const s=document.createElement("ul");s.id=n,s.setAttribute("role","listbox"),s.setAttribute("aria-expanded","true"),s.setAttribute("aria-label",this.view.state.phrase("Completions")),s.addEventListener("mousedown",o=>{o.target==s&&o.preventDefault()});let a=null;for(let o=r.from;o<r.to;o++){let{completion:l,match:c}=t[o],{section:u}=l;if(u){let m=typeof u=="string"?u:u.name;if(m!=a&&(o>r.from||r.from==0))if(a=m,typeof u!="string"&&u.header)s.appendChild(u.header(u));else{let g=s.appendChild(document.createElement("completion-section"));g.textContent=m}}const d=s.appendChild(document.createElement("li"));d.id=n+"-"+o,d.setAttribute("role","option");let h=this.optionClass(l);h&&(d.className=h);for(let m of this.optionContent){let g=m(l,this.view.state,this.view,c);g&&d.appendChild(g)}}return r.from&&s.classList.add("cm-completionListIncompleteTop"),r.to<t.length&&s.classList.add("cm-completionListIncompleteBottom"),s}destroyInfo(){this.info&&(this.infoDestroy&&this.infoDestroy(),this.info.remove(),this.info=null)}destroy(){this.destroyInfo()}}function Pit(e,t){return n=>new Dit(n,e,t)}function Lit(e,t){let n=e.getBoundingClientRect(),r=t.getBoundingClientRect(),s=n.height/e.offsetHeight;r.top<n.top?e.scrollTop-=(n.top-r.top)/s:r.bottom>n.bottom&&(e.scrollTop+=(r.bottom-n.bottom)/s)}function VX(e){return(e.boost||0)*100+(e.apply?10:0)+(e.info?5:0)+(e.type?1:0)}function $it(e,t){let n=[],r=null,s=null,a=d=>{n.push(d);let{section:h}=d.completion;if(h){r||(r=[]);let m=typeof h=="string"?h:h.name;r.some(g=>g.name==m)||r.push(typeof h=="string"?{name:m}:h)}},o=t.facet($a);for(let d of e)if(d.hasResult()){let h=d.result.getMatch;if(d.result.filter===!1)for(let m of d.result.options)a(new BX(m,d.source,h?h(m):[],1e9-n.length));else{let m=t.sliceDoc(d.from,d.to),g,b=o.filterStrict?new Rit(m):new Iit(m);for(let v of d.result.options)if(g=b.match(v.label)){let j=v.displayLabel?h?h(v,g.matched):[]:g.matched,k=g.score+(v.boost||0);if(a(new BX(v,d.source,j,k)),typeof v.section=="object"&&v.section.rank==="dynamic"){let{name:w}=v.section;s||(s=Object.create(null)),s[w]=Math.max(k,s[w]||-1e9)}}}}if(r){let d=Object.create(null),h=0,m=(g,b)=>(g.rank==="dynamic"&&b.rank==="dynamic"?s[b.name]-s[g.name]:0)||(typeof g.rank=="number"?g.rank:1e9)-(typeof b.rank=="number"?b.rank:1e9)||(g.name<b.name?-1:1);for(let g of r.sort(m))h-=1e5,d[g.name]=h;for(let g of n){let{section:b}=g.completion;b&&(g.score+=d[typeof b=="string"?b:b.name])}}let l=[],c=null,u=o.compareCompletions;for(let d of n.sort((h,m)=>m.score-h.score||u(h.completion,m.completion))){let h=d.completion;!c||c.label!=h.label||c.detail!=h.detail||c.type!=null&&h.type!=null&&c.type!=h.type||c.apply!=h.apply||c.boost!=h.boost?l.push(d):VX(d.completion)>VX(c)&&(l[l.length-1]=d),c=d.completion}return l}class O0{constructor(t,n,r,s,a,o){this.options=t,this.attrs=n,this.tooltip=r,this.timestamp=s,this.selected=a,this.disabled=o}setSelected(t,n){return t==this.selected||t>=this.options.length?this:new O0(this.options,HX(n,t),this.tooltip,this.timestamp,t,this.disabled)}static build(t,n,r,s,a,o){if(s&&!o&&t.some(u=>u.isPending))return s.setDisabled();let l=$it(t,n);if(!l.length)return s&&t.some(u=>u.isPending)?s.setDisabled():null;let c=n.facet($a).selectOnOpen?0:-1;if(s&&s.selected!=c&&s.selected!=-1){let u=s.options[s.selected].completion;for(let d=0;d<l.length;d++)if(l[d].completion==u){c=d;break}}return new O0(l,HX(r,c),{pos:t.reduce((u,d)=>d.hasResult()?Math.min(u,d.from):u,1e8),create:Vit,above:a.aboveCursor},s?s.timestamp:Date.now(),c,!1)}map(t){return new O0(this.options,this.attrs,{...this.tooltip,pos:t.mapPos(this.tooltip.pos)},this.timestamp,this.selected,this.disabled)}setDisabled(){return new O0(this.options,this.attrs,this.tooltip,this.timestamp,this.selected,!0)}}class BE{constructor(t,n,r){this.active=t,this.id=n,this.open=r}static start(){return new BE(Uit,"cm-ac-"+Math.floor(Math.random()*2e6).toString(36),null)}update(t){let{state:n}=t,r=n.facet($a),a=(r.override||n.languageDataAt("autocomplete",ob(n)).map(Tit)).map(c=>(this.active.find(d=>d.source==c)||new ru(c,this.active.some(d=>d.state!=0)?1:0)).update(t,r));a.length==this.active.length&&a.every((c,u)=>c==this.active[u])&&(a=this.active);let o=this.open,l=t.effects.some(c=>c.is(XB));o&&t.docChanged&&(o=o.map(t.changes)),t.selection||a.some(c=>c.hasResult()&&t.changes.touchesRange(c.from,c.to))||!Fit(a,this.active)||l?o=O0.build(a,n,this.id,o,r,l):o&&o.disabled&&!a.some(c=>c.isPending)&&(o=null),!o&&a.every(c=>!c.isPending)&&a.some(c=>c.hasResult())&&(a=a.map(c=>c.hasResult()?new ru(c.source,0):c));for(let c of t.effects)c.is(ZB)&&(o=o&&o.setSelected(c.value,this.id));return a==this.active&&o==this.open?this:new BE(a,this.id,o)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:this.active.length?zit:Bit}}function Fit(e,t){if(e==t)return!0;for(let n=0,r=0;;){for(;n<e.length&&!e[n].hasResult();)n++;for(;r<t.length&&!t[r].hasResult();)r++;let s=n==e.length,a=r==t.length;if(s||a)return s==a;if(e[n++].result!=t[r++].result)return!1}}const zit={"aria-autocomplete":"list"},Bit={};function HX(e,t){let n={"aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":e};return t>-1&&(n["aria-activedescendant"]=e+"-"+t),n}const Uit=[];function x0e(e,t){if(e.isUserEvent("input.complete")){let r=e.annotation(JB);if(r&&t.activateOnCompletion(r))return 12}let n=e.isUserEvent("input.type");return n&&t.activateOnTyping?5:n?1:e.isUserEvent("delete.backward")?2:e.selection?8:e.docChanged?16:0}class ru{constructor(t,n,r=!1){this.source=t,this.state=n,this.explicit=r}hasResult(){return!1}get isPending(){return this.state==1}update(t,n){let r=x0e(t,n),s=this;(r&8||r&16&&this.touches(t))&&(s=new ru(s.source,0)),r&4&&s.state==0&&(s=new ru(this.source,1)),s=s.updateFor(t,r);for(let a of t.effects)if(a.is(zE))s=new ru(s.source,1,a.value);else if(a.is(DN))s=new ru(s.source,0);else if(a.is(XB))for(let o of a.value)o.source==s.source&&(s=o);return s}updateFor(t,n){return this.map(t.changes)}map(t){return this}touches(t){return t.changes.touchesRange(ob(t.state))}}class Y0 extends ru{constructor(t,n,r,s,a,o){super(t,3,n),this.limit=r,this.result=s,this.from=a,this.to=o}hasResult(){return!0}updateFor(t,n){var r;if(!(n&3))return this.map(t.changes);let s=this.result;s.map&&!t.changes.empty&&(s=s.map(s,t.changes));let a=t.changes.mapPos(this.from),o=t.changes.mapPos(this.to,1),l=ob(t.state);if(l>o||!s||n&2&&(ob(t.startState)==this.from||l<this.limit))return new ru(this.source,n&4?1:0);let c=t.changes.mapPos(this.limit);return qit(s.validFor,t.state,a,o)?new Y0(this.source,this.explicit,c,s,a,o):s.update&&(s=s.update(s,a,o,new p0e(t.state,l,!1)))?new Y0(this.source,this.explicit,c,s,s.from,(r=s.to)!==null&&r!==void 0?r:ob(t.state)):new ru(this.source,1,this.explicit)}map(t){return t.empty?this:(this.result.map?this.result.map(this.result,t):this.result)?new Y0(this.source,this.explicit,t.mapPos(this.limit),this.result,t.mapPos(this.from),t.mapPos(this.to,1)):new ru(this.source,0)}touches(t){return t.changes.touchesRange(this.from,this.to)}}function qit(e,t,n,r){if(!e)return!1;let s=t.sliceDoc(n,r);return typeof e=="function"?e(s,n,r,t):g0e(e,!0).test(s)}const XB=Yn.define({map(e,t){return e.map(n=>n.map(t))}}),zl=ko.define({create(){return BE.start()},update(e,t){return e.update(t)},provide:e=>[zB.from(e,t=>t.tooltip),Yt.contentAttributes.from(e,t=>t.attrs)]});function eU(e,t){const n=t.completion.apply||t.completion.label;let r=e.state.field(zl).active.find(s=>s.source==t.source);return r instanceof Y0?(typeof n=="string"?e.dispatch({...Eit(e.state,n,r.from,r.to),annotations:JB.of(t.completion)}):n(e,t.completion,r.from,r.to),!0):!1}const Vit=Pit(zl,eU);function E_(e,t="option"){return n=>{let r=n.state.field(zl,!1);if(!r||!r.open||r.open.disabled||Date.now()-r.open.timestamp<n.state.facet($a).interactionDelay)return!1;let s=1,a;t=="page"&&(a=Mye(n,r.open.tooltip))&&(s=Math.max(2,Math.floor(a.dom.offsetHeight/a.dom.querySelector("li").offsetHeight)-1));let{length:o}=r.open.options,l=r.open.selected>-1?r.open.selected+s*(e?1:-1):e?0:o-1;return l<0?l=t=="page"?0:o-1:l>=o&&(l=t=="page"?o-1:0),n.dispatch({effects:ZB.of(l)}),!0}}const Hit=e=>{let t=e.state.field(zl,!1);return e.state.readOnly||!t||!t.open||t.open.selected<0||t.open.disabled||Date.now()-t.open.timestamp<e.state.facet($a).interactionDelay?!1:eU(e,t.open.options[t.open.selected])},gD=e=>e.state.field(zl,!1)?(e.dispatch({effects:zE.of(!0)}),!0):!1,Kit=e=>{let t=e.state.field(zl,!1);return!t||!t.active.some(n=>n.state!=0)?!1:(e.dispatch({effects:DN.of(null)}),!0)};class Wit{constructor(t,n){this.active=t,this.context=n,this.time=Date.now(),this.updates=[],this.done=void 0}}const Git=50,Qit=1e3,Yit=Vi.fromClass(class{constructor(e){this.view=e,this.debounceUpdate=-1,this.running=[],this.debounceAccept=-1,this.pendingStart=!1,this.composing=0;for(let t of e.state.field(zl).active)t.isPending&&this.startQuery(t)}update(e){let t=e.state.field(zl),n=e.state.facet($a);if(!e.selectionSet&&!e.docChanged&&e.startState.field(zl)==t)return;let r=e.transactions.some(a=>{let o=x0e(a,n);return o&8||(a.selection||a.docChanged)&&!(o&3)});for(let a=0;a<this.running.length;a++){let o=this.running[a];if(r||o.context.abortOnDocChange&&e.docChanged||o.updates.length+e.transactions.length>Git&&Date.now()-o.time>Qit){for(let l of o.context.abortListeners)try{l()}catch(c){Ul(this.view.state,c)}o.context.abortListeners=null,this.running.splice(a--,1)}else o.updates.push(...e.transactions)}this.debounceUpdate>-1&&clearTimeout(this.debounceUpdate),e.transactions.some(a=>a.effects.some(o=>o.is(zE)))&&(this.pendingStart=!0);let s=this.pendingStart?50:n.activateOnTypingDelay;if(this.debounceUpdate=t.active.some(a=>a.isPending&&!this.running.some(o=>o.active.source==a.source))?setTimeout(()=>this.startUpdate(),s):-1,this.composing!=0)for(let a of e.transactions)a.isUserEvent("input.type")?this.composing=2:this.composing==2&&a.selection&&(this.composing=3)}startUpdate(){this.debounceUpdate=-1,this.pendingStart=!1;let{state:e}=this.view,t=e.field(zl);for(let n of t.active)n.isPending&&!this.running.some(r=>r.active.source==n.source)&&this.startQuery(n);this.running.length&&t.open&&t.open.disabled&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet($a).updateSyncTime))}startQuery(e){let{state:t}=this.view,n=ob(t),r=new p0e(t,n,e.explicit,this.view),s=new Wit(e,r);this.running.push(s),Promise.resolve(e.source(r)).then(a=>{s.context.aborted||(s.done=a||null,this.scheduleAccept())},a=>{this.view.dispatch({effects:DN.of(null)}),Ul(this.view.state,a)})}scheduleAccept(){this.running.every(e=>e.done!==void 0)?this.accept():this.debounceAccept<0&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet($a).updateSyncTime))}accept(){var e;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let t=[],n=this.view.state.facet($a),r=this.view.state.field(zl);for(let s=0;s<this.running.length;s++){let a=this.running[s];if(a.done===void 0)continue;if(this.running.splice(s--,1),a.done){let l=ob(a.updates.length?a.updates[0].startState:this.view.state),c=Math.min(l,a.done.from+(a.active.explicit?0:1)),u=new Y0(a.active.source,a.active.explicit,c,a.done,a.done.from,(e=a.done.to)!==null&&e!==void 0?e:l);for(let d of a.updates)u=u.update(d,n);if(u.hasResult()){t.push(u);continue}}let o=r.active.find(l=>l.source==a.active.source);if(o&&o.isPending)if(a.done==null){let l=new ru(a.active.source,0);for(let c of a.updates)l=l.update(c,n);l.isPending||t.push(l)}else this.startQuery(o)}(t.length||r.open&&r.open.disabled)&&this.view.dispatch({effects:XB.of(t)})}},{eventHandlers:{blur(e){let t=this.view.state.field(zl,!1);if(t&&t.tooltip&&this.view.state.facet($a).closeOnBlur){let n=t.open&&Mye(this.view,t.open.tooltip);(!n||!n.dom.contains(e.relatedTarget))&&setTimeout(()=>this.view.dispatch({effects:DN.of(null)}),10)}},compositionstart(){this.composing=1},compositionend(){this.composing==3&&setTimeout(()=>this.view.dispatch({effects:zE.of(!1)}),20),this.composing=0}}}),Jit=typeof navigator=="object"&&/Win/.test(navigator.platform),Zit=Bg.highest(Yt.domEventHandlers({keydown(e,t){let n=t.state.field(zl,!1);if(!n||!n.open||n.open.disabled||n.open.selected<0||e.key.length>1||e.ctrlKey&&!(Jit&&e.altKey)||e.metaKey)return!1;let r=n.open.options[n.open.selected],s=n.active.find(o=>o.source==r.source),a=r.completion.commitCharacters||s.result.commitCharacters;return a&&a.indexOf(e.key)>-1&&eU(t,r),!1}})),b0e=Yt.baseTheme({".cm-tooltip.cm-tooltip-autocomplete":{"& > ul":{fontFamily:"monospace",whiteSpace:"nowrap",overflow:"hidden auto",maxWidth_fallback:"700px",maxWidth:"min(700px, 95vw)",minWidth:"250px",maxHeight:"10em",height:"100%",listStyle:"none",margin:0,padding:0,"& > li, & > completion-section":{padding:"1px 3px",lineHeight:1.2},"& > li":{overflowX:"hidden",textOverflow:"ellipsis",cursor:"pointer"},"& > completion-section":{display:"list-item",borderBottom:"1px solid silver",paddingLeft:"0.5em",opacity:.7}}},"&light .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#17c",color:"white"},"&light .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#777"},"&dark .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#347",color:"white"},"&dark .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#444"},".cm-completionListIncompleteTop:before, .cm-completionListIncompleteBottom:after":{content:'"···"',opacity:.5,display:"block",textAlign:"center"},".cm-tooltip.cm-completionInfo":{position:"absolute",padding:"3px 9px",width:"max-content",maxWidth:"400px",boxSizing:"border-box",whiteSpace:"pre-line"},".cm-completionInfo.cm-completionInfo-left":{right:"100%"},".cm-completionInfo.cm-completionInfo-right":{left:"100%"},".cm-completionInfo.cm-completionInfo-left-narrow":{right:"30px"},".cm-completionInfo.cm-completionInfo-right-narrow":{left:"30px"},"&light .cm-snippetField":{backgroundColor:"#00000022"},"&dark .cm-snippetField":{backgroundColor:"#ffffff22"},".cm-snippetFieldPosition":{verticalAlign:"text-top",width:0,height:"1.15em",display:"inline-block",margin:"0 -0.7px -.7em",borderLeft:"1.4px dotted #888"},".cm-completionMatchedText":{textDecoration:"underline"},".cm-completionDetail":{marginLeft:"0.5em",fontStyle:"italic"},".cm-completionIcon":{fontSize:"90%",width:".8em",display:"inline-block",textAlign:"center",paddingRight:".6em",opacity:"0.6",boxSizing:"content-box"},".cm-completionIcon-function, .cm-completionIcon-method":{"&:after":{content:"'ƒ'"}},".cm-completionIcon-class":{"&:after":{content:"'○'"}},".cm-completionIcon-interface":{"&:after":{content:"'◌'"}},".cm-completionIcon-variable":{"&:after":{content:"'𝑥'"}},".cm-completionIcon-constant":{"&:after":{content:"'𝐶'"}},".cm-completionIcon-type":{"&:after":{content:"'𝑡'"}},".cm-completionIcon-enum":{"&:after":{content:"'∪'"}},".cm-completionIcon-property":{"&:after":{content:"'□'"}},".cm-completionIcon-keyword":{"&:after":{content:"'🔑︎'"}},".cm-completionIcon-namespace":{"&:after":{content:"'▢'"}},".cm-completionIcon-text":{"&:after":{content:"'abc'",fontSize:"50%",verticalAlign:"middle"}}});class Xit{constructor(t,n,r,s){this.field=t,this.line=n,this.from=r,this.to=s}}class tU{constructor(t,n,r){this.field=t,this.from=n,this.to=r}map(t){let n=t.mapPos(this.from,-1,co.TrackDel),r=t.mapPos(this.to,1,co.TrackDel);return n==null||r==null?null:new tU(this.field,n,r)}}class nU{constructor(t,n){this.lines=t,this.fieldPositions=n}instantiate(t,n){let r=[],s=[n],a=t.doc.lineAt(n),o=/^\s*/.exec(a.text)[0];for(let c of this.lines){if(r.length){let u=o,d=/^\t*/.exec(c)[0].length;for(let h=0;h<d;h++)u+=t.facet(MI);s.push(n+u.length-d),c=u+c.slice(d)}r.push(c),n+=c.length+1}let l=this.fieldPositions.map(c=>new tU(c.field,s[c.line]+c.from,s[c.line]+c.to));return{text:r,ranges:l}}static parse(t){let n=[],r=[],s=[],a;for(let o of t.split(/\r\n?|\n/)){for(;a=/[#$]\{(?:(\d+)(?::([^{}]*))?|((?:\\[{}]|[^{}])*))\}/.exec(o);){let l=a[1]?+a[1]:null,c=a[2]||a[3]||"",u=-1,d=c.replace(/\\[{}]/g,h=>h[1]);for(let h=0;h<n.length;h++)(l!=null?n[h].seq==l:d&&n[h].name==d)&&(u=h);if(u<0){let h=0;for(;h<n.length&&(l==null||n[h].seq!=null&&n[h].seq<l);)h++;n.splice(h,0,{seq:l,name:d}),u=h;for(let m of s)m.field>=u&&m.field++}for(let h of s)if(h.line==r.length&&h.from>a.index){let m=a[2]?3+(a[1]||"").length:2;h.from-=m,h.to-=m}s.push(new Xit(u,r.length,a.index,a.index+d.length)),o=o.slice(0,a.index)+c+o.slice(a.index+a[0].length)}o=o.replace(/\\([{}])/g,(l,c,u)=>{for(let d of s)d.line==r.length&&d.from>u&&(d.from--,d.to--);return c}),r.push(o)}return new nU(r,s)}}let eat=En.widget({widget:new class extends Lf{toDOM(){let e=document.createElement("span");return e.className="cm-snippetFieldPosition",e}ignoreEvent(){return!1}}}),tat=En.mark({class:"cm-snippetField"});class q1{constructor(t,n){this.ranges=t,this.active=n,this.deco=En.set(t.map(r=>(r.from==r.to?eat:tat).range(r.from,r.to)),!0)}map(t){let n=[];for(let r of this.ranges){let s=r.map(t);if(!s)return null;n.push(s)}return new q1(n,this.active)}selectionInsideField(t){return t.ranges.every(n=>this.ranges.some(r=>r.field==this.active&&r.from<=n.from&&r.to>=n.to))}}const JC=Yn.define({map(e,t){return e&&e.map(t)}}),nat=Yn.define(),PN=ko.define({create(){return null},update(e,t){for(let n of t.effects){if(n.is(JC))return n.value;if(n.is(nat)&&e)return new q1(e.ranges,n.value)}return e&&t.docChanged&&(e=e.map(t.changes)),e&&t.selection&&!e.selectionInsideField(t.selection)&&(e=null),e},provide:e=>Yt.decorations.from(e,t=>t?t.deco:En.none)});function rU(e,t){return xt.create(e.filter(n=>n.field==t).map(n=>xt.range(n.from,n.to)))}function rat(e){let t=nU.parse(e);return(n,r,s,a)=>{let{text:o,ranges:l}=t.instantiate(n.state,s),{main:c}=n.state.selection,u={changes:{from:s,to:a==c.from?c.to:a,insert:ts.of(o)},scrollIntoView:!0,annotations:r?[JB.of(r),fa.userEvent.of("input.complete")]:void 0};if(l.length&&(u.selection=rU(l,0)),l.some(d=>d.field>0)){let d=new q1(l,0),h=u.effects=[JC.of(d)];n.state.field(PN,!1)===void 0&&h.push(Yn.appendConfig.of([PN,lat,cat,b0e]))}n.dispatch(n.state.update(u))}}function y0e(e){return({state:t,dispatch:n})=>{let r=t.field(PN,!1);if(!r||e<0&&r.active==0)return!1;let s=r.active+e,a=e>0&&!r.ranges.some(o=>o.field==s+e);return n(t.update({selection:rU(r.ranges,s),effects:JC.of(a?null:new q1(r.ranges,s)),scrollIntoView:!0})),!0}}const sat=({state:e,dispatch:t})=>e.field(PN,!1)?(t(e.update({effects:JC.of(null)})),!0):!1,iat=y0e(1),aat=y0e(-1),oat=[{key:"Tab",run:iat,shift:aat},{key:"Escape",run:sat}],KX=Zt.define({combine(e){return e.length?e[0]:oat}}),lat=Bg.highest(GC.compute([KX],e=>e.facet(KX)));function aEt(e,t){return{...t,apply:rat(e)}}const cat=Yt.domEventHandlers({mousedown(e,t){let n=t.state.field(PN,!1),r;if(!n||(r=t.posAtCoords({x:e.clientX,y:e.clientY}))==null)return!1;let s=n.ranges.find(a=>a.from<=r&&a.to>=r);return!s||s.field==n.active?!1:(t.dispatch({selection:rU(n.ranges,s.field),effects:JC.of(n.ranges.some(a=>a.field>s.field)?new q1(n.ranges,s.field):null),scrollIntoView:!0}),!0)}}),LN={brackets:["(","[","{","'",'"'],before:")]}:;>",stringPrefixes:[]},Fx=Yn.define({map(e,t){let n=t.mapPos(e,-1,co.TrackAfter);return n??void 0}}),sU=new class extends yg{};sU.startSide=1;sU.endSide=-1;const v0e=ko.define({create(){return _r.empty},update(e,t){if(e=e.map(t.changes),t.selection){let n=t.state.doc.lineAt(t.selection.main.head);e=e.update({filter:r=>r>=n.from&&r<=n.to})}for(let n of t.effects)n.is(Fx)&&(e=e.update({add:[sU.range(n.value,n.value+1)]}));return e}});function uat(){return[fat,v0e]}const xD="()[]{}<>«»»«[]{}";function w0e(e){for(let t=0;t<xD.length;t+=2)if(xD.charCodeAt(t)==e)return xD.charAt(t+1);return jB(e<128?e:e+1)}function k0e(e,t){return e.languageDataAt("closeBrackets",t)[0]||LN}const dat=typeof navigator=="object"&&/Android\b/.test(navigator.userAgent),fat=Yt.inputHandler.of((e,t,n,r)=>{if((dat?e.composing:e.compositionStarted)||e.state.readOnly)return!1;let s=e.state.selection.main;if(r.length>2||r.length==2&&ef(Fl(r,0))==1||t!=s.from||n!=s.to)return!1;let a=pat(e.state,r);return a?(e.dispatch(a),!0):!1}),hat=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let r=k0e(e,e.selection.main.head).brackets||LN.brackets,s=null,a=e.changeByRange(o=>{if(o.empty){let l=gat(e.doc,o.head);for(let c of r)if(c==l&&PI(e.doc,o.head)==w0e(Fl(c,0)))return{changes:{from:o.head-c.length,to:o.head+c.length},range:xt.cursor(o.head-c.length)}}return{range:s=o}});return s||t(e.update(a,{scrollIntoView:!0,userEvent:"delete.backward"})),!s},mat=[{key:"Backspace",run:hat}];function pat(e,t){let n=k0e(e,e.selection.main.head),r=n.brackets||LN.brackets;for(let s of r){let a=w0e(Fl(s,0));if(t==s)return a==s?yat(e,s,r.indexOf(s+s+s)>-1,n):xat(e,s,a,n.before||LN.before);if(t==a&&j0e(e,e.selection.main.from))return bat(e,s,a)}return null}function j0e(e,t){let n=!1;return e.field(v0e).between(0,e.doc.length,r=>{r==t&&(n=!0)}),n}function PI(e,t){let n=e.sliceString(t,t+2);return n.slice(0,ef(Fl(n,0)))}function gat(e,t){let n=e.sliceString(t-2,t);return ef(Fl(n,0))==n.length?n:n.slice(1)}function xat(e,t,n,r){let s=null,a=e.changeByRange(o=>{if(!o.empty)return{changes:[{insert:t,from:o.from},{insert:n,from:o.to}],effects:Fx.of(o.to+t.length),range:xt.range(o.anchor+t.length,o.head+t.length)};let l=PI(e.doc,o.head);return!l||/\s/.test(l)||r.indexOf(l)>-1?{changes:{insert:t+n,from:o.head},effects:Fx.of(o.head+t.length),range:xt.cursor(o.head+t.length)}:{range:s=o}});return s?null:e.update(a,{scrollIntoView:!0,userEvent:"input.type"})}function bat(e,t,n){let r=null,s=e.changeByRange(a=>a.empty&&PI(e.doc,a.head)==n?{changes:{from:a.head,to:a.head+n.length,insert:n},range:xt.cursor(a.head+n.length)}:r={range:a});return r?null:e.update(s,{scrollIntoView:!0,userEvent:"input.type"})}function yat(e,t,n,r){let s=r.stringPrefixes||LN.stringPrefixes,a=null,o=e.changeByRange(l=>{if(!l.empty)return{changes:[{insert:t,from:l.from},{insert:t,from:l.to}],effects:Fx.of(l.to+t.length),range:xt.range(l.anchor+t.length,l.head+t.length)};let c=l.head,u=PI(e.doc,c),d;if(u==t){if(WX(e,c))return{changes:{insert:t+t,from:c},effects:Fx.of(c+t.length),range:xt.cursor(c+t.length)};if(j0e(e,c)){let m=n&&e.sliceDoc(c,c+t.length*3)==t+t+t?t+t+t:t;return{changes:{from:c,to:c+m.length,insert:m},range:xt.cursor(c+m.length)}}}else{if(n&&e.sliceDoc(c-2*t.length,c)==t+t&&(d=GX(e,c-2*t.length,s))>-1&&WX(e,d))return{changes:{insert:t+t+t+t,from:c},effects:Fx.of(c+t.length),range:xt.cursor(c+t.length)};if(e.charCategorizer(c)(u)!=hi.Word&&GX(e,c,s)>-1&&!vat(e,c,t,s))return{changes:{insert:t+t,from:c},effects:Fx.of(c+t.length),range:xt.cursor(c+t.length)}}return{range:a=l}});return a?null:e.update(o,{scrollIntoView:!0,userEvent:"input.type"})}function WX(e,t){let n=wo(e).resolveInner(t+1);return n.parent&&n.from==t}function vat(e,t,n,r){let s=wo(e).resolveInner(t,-1),a=r.reduce((o,l)=>Math.max(o,l.length),0);for(let o=0;o<5;o++){let l=e.sliceDoc(s.from,Math.min(s.to,s.from+n.length+a)),c=l.indexOf(n);if(!c||c>-1&&r.indexOf(l.slice(0,c))>-1){let d=s.firstChild;for(;d&&d.from==s.from&&d.to-d.from>n.length+c;){if(e.sliceDoc(d.to-n.length,d.to)==n)return!1;d=d.firstChild}return!0}let u=s.to==t&&s.parent;if(!u)break;s=u}return!1}function GX(e,t,n){let r=e.charCategorizer(t);if(r(e.sliceDoc(t-1,t))!=hi.Word)return t;for(let s of n){let a=t-s.length;if(e.sliceDoc(a,t)==s&&r(e.sliceDoc(a-1,a))!=hi.Word)return a}return-1}function wat(e={}){return[Zit,zl,$a.of(e),Yit,kat,b0e]}const N0e=[{key:"Ctrl-Space",run:gD},{mac:"Alt-`",run:gD},{mac:"Alt-i",run:gD},{key:"Escape",run:Kit},{key:"ArrowDown",run:E_(!0)},{key:"ArrowUp",run:E_(!1)},{key:"PageDown",run:E_(!0,"page")},{key:"PageUp",run:E_(!1,"page")},{key:"Enter",run:Hit}],kat=Bg.highest(GC.computeN([$a],e=>e.facet($a).defaultKeymap?[N0e]:[])),jat=e=>{let{state:t}=e,n=t.doc.lineAt(t.selection.main.from),r=aU(e.state,n.from);return r.line?Nat(e):r.block?Sat(e):!1};function iU(e,t){return({state:n,dispatch:r})=>{if(n.readOnly)return!1;let s=e(t,n);return s?(r(n.update(s)),!0):!1}}const Nat=iU(Eat,0),Cat=iU(C0e,0),Sat=iU((e,t)=>C0e(e,t,Aat(t)),0);function aU(e,t){let n=e.languageDataAt("commentTokens",t,1);return n.length?n[0]:{}}const hk=50;function _at(e,{open:t,close:n},r,s){let a=e.sliceDoc(r-hk,r),o=e.sliceDoc(s,s+hk),l=/\s*$/.exec(a)[0].length,c=/^\s*/.exec(o)[0].length,u=a.length-l;if(a.slice(u-t.length,u)==t&&o.slice(c,c+n.length)==n)return{open:{pos:r-l,margin:l&&1},close:{pos:s+c,margin:c&&1}};let d,h;s-r<=2*hk?d=h=e.sliceDoc(r,s):(d=e.sliceDoc(r,r+hk),h=e.sliceDoc(s-hk,s));let m=/^\s*/.exec(d)[0].length,g=/\s*$/.exec(h)[0].length,b=h.length-g-n.length;return d.slice(m,m+t.length)==t&&h.slice(b,b+n.length)==n?{open:{pos:r+m+t.length,margin:/\s/.test(d.charAt(m+t.length))?1:0},close:{pos:s-g-n.length,margin:/\s/.test(h.charAt(b-1))?1:0}}:null}function Aat(e){let t=[];for(let n of e.selection.ranges){let r=e.doc.lineAt(n.from),s=n.to<=r.to?r:e.doc.lineAt(n.to);s.from>r.from&&s.from==n.to&&(s=n.to==r.to+1?r:e.doc.lineAt(n.to-1));let a=t.length-1;a>=0&&t[a].to>r.from?t[a].to=s.to:t.push({from:r.from+/^\s*/.exec(r.text)[0].length,to:s.to})}return t}function C0e(e,t,n=t.selection.ranges){let r=n.map(a=>aU(t,a.from).block);if(!r.every(a=>a))return null;let s=n.map((a,o)=>_at(t,r[o],a.from,a.to));if(e!=2&&!s.every(a=>a))return{changes:t.changes(n.map((a,o)=>s[o]?[]:[{from:a.from,insert:r[o].open+" "},{from:a.to,insert:" "+r[o].close}]))};if(e!=1&&s.some(a=>a)){let a=[];for(let o=0,l;o<s.length;o++)if(l=s[o]){let c=r[o],{open:u,close:d}=l;a.push({from:u.pos-c.open.length,to:u.pos+u.margin},{from:d.pos-d.margin,to:d.pos+c.close.length})}return{changes:a}}return null}function Eat(e,t,n=t.selection.ranges){let r=[],s=-1;e:for(let{from:a,to:o}of n){let l=r.length,c=1e9,u;for(let d=a;d<=o;){let h=t.doc.lineAt(d);if(u==null&&(u=aU(t,h.from).line,!u))continue e;if(h.from>s&&(a==o||o>h.from)){s=h.from;let m=/^\s*/.exec(h.text)[0].length,g=m==h.length,b=h.text.slice(m,m+u.length)==u?m:-1;m<h.text.length&&m<c&&(c=m),r.push({line:h,comment:b,token:u,indent:m,empty:g,single:!1})}d=h.to+1}if(c<1e9)for(let d=l;d<r.length;d++)r[d].indent<r[d].line.text.length&&(r[d].indent=c);r.length==l+1&&(r[l].single=!0)}if(e!=2&&r.some(a=>a.comment<0&&(!a.empty||a.single))){let a=[];for(let{line:l,token:c,indent:u,empty:d,single:h}of r)(h||!d)&&a.push({from:l.from+u,insert:c+" "});let o=t.changes(a);return{changes:o,selection:t.selection.map(o,1)}}else if(e!=1&&r.some(a=>a.comment>=0)){let a=[];for(let{line:o,comment:l,token:c}of r)if(l>=0){let u=o.from+l,d=u+c.length;o.text[d-o.from]==" "&&d++,a.push({from:u,to:d})}return{changes:a}}return null}const p$=gm.define(),Tat=gm.define(),Iat=Zt.define(),S0e=Zt.define({combine(e){return Pf(e,{minDepth:100,newGroupDelay:500,joinToEvent:(t,n)=>n},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(t,n)=>(r,s)=>t(r,s)||n(r,s)})}}),_0e=ko.define({create(){return df.empty},update(e,t){let n=t.state.facet(S0e),r=t.annotation(p$);if(r){let c=ql.fromTransaction(t,r.selection),u=r.side,d=u==0?e.undone:e.done;return c?d=UE(d,d.length,n.minDepth,c):d=T0e(d,t.startState.selection),new df(u==0?r.rest:d,u==0?d:r.rest)}let s=t.annotation(Tat);if((s=="full"||s=="before")&&(e=e.isolate()),t.annotation(fa.addToHistory)===!1)return t.changes.empty?e:e.addMapping(t.changes.desc);let a=ql.fromTransaction(t),o=t.annotation(fa.time),l=t.annotation(fa.userEvent);return a?e=e.addChanges(a,o,l,n,t):t.selection&&(e=e.addSelection(t.startState.selection,o,l,n.newGroupDelay)),(s=="full"||s=="after")&&(e=e.isolate()),e},toJSON(e){return{done:e.done.map(t=>t.toJSON()),undone:e.undone.map(t=>t.toJSON())}},fromJSON(e){return new df(e.done.map(ql.fromJSON),e.undone.map(ql.fromJSON))}});function Rat(e={}){return[_0e,S0e.of(e),Yt.domEventHandlers({beforeinput(t,n){let r=t.inputType=="historyUndo"?A0e:t.inputType=="historyRedo"?g$:null;return r?(t.preventDefault(),r(n)):!1}})]}function LI(e,t){return function({state:n,dispatch:r}){if(!t&&n.readOnly)return!1;let s=n.field(_0e,!1);if(!s)return!1;let a=s.pop(e,n,t);return a?(r(a),!0):!1}}const A0e=LI(0,!1),g$=LI(1,!1),Mat=LI(0,!0),Oat=LI(1,!0);class ql{constructor(t,n,r,s,a){this.changes=t,this.effects=n,this.mapped=r,this.startSelection=s,this.selectionsAfter=a}setSelAfter(t){return new ql(this.changes,this.effects,this.mapped,this.startSelection,t)}toJSON(){var t,n,r;return{changes:(t=this.changes)===null||t===void 0?void 0:t.toJSON(),mapped:(n=this.mapped)===null||n===void 0?void 0:n.toJSON(),startSelection:(r=this.startSelection)===null||r===void 0?void 0:r.toJSON(),selectionsAfter:this.selectionsAfter.map(s=>s.toJSON())}}static fromJSON(t){return new ql(t.changes&&va.fromJSON(t.changes),[],t.mapped&&gf.fromJSON(t.mapped),t.startSelection&&xt.fromJSON(t.startSelection),t.selectionsAfter.map(xt.fromJSON))}static fromTransaction(t,n){let r=su;for(let s of t.startState.facet(Iat)){let a=s(t);a.length&&(r=r.concat(a))}return!r.length&&t.changes.empty?null:new ql(t.changes.invert(t.startState.doc),r,void 0,n||t.startState.selection,su)}static selection(t){return new ql(void 0,su,void 0,void 0,t)}}function UE(e,t,n,r){let s=t+1>n+20?t-n-1:0,a=e.slice(s,t);return a.push(r),a}function Dat(e,t){let n=[],r=!1;return e.iterChangedRanges((s,a)=>n.push(s,a)),t.iterChangedRanges((s,a,o,l)=>{for(let c=0;c<n.length;){let u=n[c++],d=n[c++];l>=u&&o<=d&&(r=!0)}}),r}function Pat(e,t){return e.ranges.length==t.ranges.length&&e.ranges.filter((n,r)=>n.empty!=t.ranges[r].empty).length===0}function E0e(e,t){return e.length?t.length?e.concat(t):e:t}const su=[],Lat=200;function T0e(e,t){if(e.length){let n=e[e.length-1],r=n.selectionsAfter.slice(Math.max(0,n.selectionsAfter.length-Lat));return r.length&&r[r.length-1].eq(t)?e:(r.push(t),UE(e,e.length-1,1e9,n.setSelAfter(r)))}else return[ql.selection([t])]}function $at(e){let t=e[e.length-1],n=e.slice();return n[e.length-1]=t.setSelAfter(t.selectionsAfter.slice(0,t.selectionsAfter.length-1)),n}function bD(e,t){if(!e.length)return e;let n=e.length,r=su;for(;n;){let s=Fat(e[n-1],t,r);if(s.changes&&!s.changes.empty||s.effects.length){let a=e.slice(0,n);return a[n-1]=s,a}else t=s.mapped,n--,r=s.selectionsAfter}return r.length?[ql.selection(r)]:su}function Fat(e,t,n){let r=E0e(e.selectionsAfter.length?e.selectionsAfter.map(l=>l.map(t)):su,n);if(!e.changes)return ql.selection(r);let s=e.changes.map(t),a=t.mapDesc(e.changes,!0),o=e.mapped?e.mapped.composeDesc(a):a;return new ql(s,Yn.mapEffects(e.effects,t),o,e.startSelection.map(a),r)}const zat=/^(input\.type|delete)($|\.)/;class df{constructor(t,n,r=0,s=void 0){this.done=t,this.undone=n,this.prevTime=r,this.prevUserEvent=s}isolate(){return this.prevTime?new df(this.done,this.undone):this}addChanges(t,n,r,s,a){let o=this.done,l=o[o.length-1];return l&&l.changes&&!l.changes.empty&&t.changes&&(!r||zat.test(r))&&(!l.selectionsAfter.length&&n-this.prevTime<s.newGroupDelay&&s.joinToEvent(a,Dat(l.changes,t.changes))||r=="input.type.compose")?o=UE(o,o.length-1,s.minDepth,new ql(t.changes.compose(l.changes),E0e(Yn.mapEffects(t.effects,l.changes),l.effects),l.mapped,l.startSelection,su)):o=UE(o,o.length,s.minDepth,t),new df(o,su,n,r)}addSelection(t,n,r,s){let a=this.done.length?this.done[this.done.length-1].selectionsAfter:su;return a.length>0&&n-this.prevTime<s&&r==this.prevUserEvent&&r&&/^select($|\.)/.test(r)&&Pat(a[a.length-1],t)?this:new df(T0e(this.done,t),this.undone,n,r)}addMapping(t){return new df(bD(this.done,t),bD(this.undone,t),this.prevTime,this.prevUserEvent)}pop(t,n,r){let s=t==0?this.done:this.undone;if(s.length==0)return null;let a=s[s.length-1],o=a.selectionsAfter[0]||(a.startSelection?a.startSelection.map(a.changes.invertedDesc,1):n.selection);if(r&&a.selectionsAfter.length)return n.update({selection:a.selectionsAfter[a.selectionsAfter.length-1],annotations:p$.of({side:t,rest:$at(s),selection:o}),userEvent:t==0?"select.undo":"select.redo",scrollIntoView:!0});if(a.changes){let l=s.length==1?su:s.slice(0,s.length-1);return a.mapped&&(l=bD(l,a.mapped)),n.update({changes:a.changes,selection:a.startSelection,effects:a.effects,annotations:p$.of({side:t,rest:l,selection:o}),filter:!1,userEvent:t==0?"undo":"redo",scrollIntoView:!0})}else return null}}df.empty=new df(su,su);const Bat=[{key:"Mod-z",run:A0e,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:g$,preventDefault:!0},{linux:"Ctrl-Shift-z",run:g$,preventDefault:!0},{key:"Mod-u",run:Mat,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:Oat,preventDefault:!0}];function V1(e,t){return xt.create(e.ranges.map(t),e.mainIndex)}function wd(e,t){return e.update({selection:t,scrollIntoView:!0,userEvent:"select"})}function kd({state:e,dispatch:t},n){let r=V1(e.selection,n);return r.eq(e.selection,!0)?!1:(t(wd(e,r)),!0)}function $I(e,t){return xt.cursor(t?e.to:e.from)}function I0e(e,t){return kd(e,n=>n.empty?e.moveByChar(n,t):$I(n,t))}function Jo(e){return e.textDirectionAt(e.state.selection.main.head)==Fs.LTR}const R0e=e=>I0e(e,!Jo(e)),M0e=e=>I0e(e,Jo(e));function O0e(e,t){return kd(e,n=>n.empty?e.moveByGroup(n,t):$I(n,t))}const Uat=e=>O0e(e,!Jo(e)),qat=e=>O0e(e,Jo(e));function Vat(e,t,n){if(t.type.prop(n))return!0;let r=t.to-t.from;return r&&(r>2||/[^\s,.;:]/.test(e.sliceDoc(t.from,t.to)))||t.firstChild}function FI(e,t,n){let r=wo(e).resolveInner(t.head),s=n?jr.closedBy:jr.openedBy;for(let c=t.head;;){let u=n?r.childAfter(c):r.childBefore(c);if(!u)break;Vat(e,u,s)?r=u:c=n?u.to:u.from}let a=r.type.prop(s),o,l;return a&&(o=n?uf(e,r.from,1):uf(e,r.to,-1))&&o.matched?l=n?o.end.to:o.end.from:l=n?r.to:r.from,xt.cursor(l,n?-1:1)}const Hat=e=>kd(e,t=>FI(e.state,t,!Jo(e))),Kat=e=>kd(e,t=>FI(e.state,t,Jo(e)));function D0e(e,t){return kd(e,n=>{if(!n.empty)return $I(n,t);let r=e.moveVertically(n,t);return r.head!=n.head?r:e.moveToLineBoundary(n,t)})}const P0e=e=>D0e(e,!1),L0e=e=>D0e(e,!0);function $0e(e){let t=e.scrollDOM.clientHeight<e.scrollDOM.scrollHeight-2,n=0,r=0,s;if(t){for(let a of e.state.facet(Yt.scrollMargins)){let o=a(e);o!=null&&o.top&&(n=Math.max(o==null?void 0:o.top,n)),o!=null&&o.bottom&&(r=Math.max(o==null?void 0:o.bottom,r))}s=e.scrollDOM.clientHeight-n-r}else s=(e.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:n,marginBottom:r,selfScroll:t,height:Math.max(e.defaultLineHeight,s-5)}}function F0e(e,t){let n=$0e(e),{state:r}=e,s=V1(r.selection,o=>o.empty?e.moveVertically(o,t,n.height):$I(o,t));if(s.eq(r.selection))return!1;let a;if(n.selfScroll){let o=e.coordsAtPos(r.selection.main.head),l=e.scrollDOM.getBoundingClientRect(),c=l.top+n.marginTop,u=l.bottom-n.marginBottom;o&&o.top>c&&o.bottom<u&&(a=Yt.scrollIntoView(s.main.head,{y:"start",yMargin:o.top-c}))}return e.dispatch(wd(r,s),{effects:a}),!0}const QX=e=>F0e(e,!1),x$=e=>F0e(e,!0);function Ug(e,t,n){let r=e.lineBlockAt(t.head),s=e.moveToLineBoundary(t,n);if(s.head==t.head&&s.head!=(n?r.to:r.from)&&(s=e.moveToLineBoundary(t,n,!1)),!n&&s.head==r.from&&r.length){let a=/^\s*/.exec(e.state.sliceDoc(r.from,Math.min(r.from+100,r.to)))[0].length;a&&t.head!=r.from+a&&(s=xt.cursor(r.from+a))}return s}const Wat=e=>kd(e,t=>Ug(e,t,!0)),Gat=e=>kd(e,t=>Ug(e,t,!1)),Qat=e=>kd(e,t=>Ug(e,t,!Jo(e))),Yat=e=>kd(e,t=>Ug(e,t,Jo(e))),Jat=e=>kd(e,t=>xt.cursor(e.lineBlockAt(t.head).from,1)),Zat=e=>kd(e,t=>xt.cursor(e.lineBlockAt(t.head).to,-1));function Xat(e,t,n){let r=!1,s=V1(e.selection,a=>{let o=uf(e,a.head,-1)||uf(e,a.head,1)||a.head>0&&uf(e,a.head-1,1)||a.head<e.doc.length&&uf(e,a.head+1,-1);if(!o||!o.end)return a;r=!0;let l=o.start.from==a.head?o.end.to:o.end.from;return xt.cursor(l)});return r?(t(wd(e,s)),!0):!1}const eot=({state:e,dispatch:t})=>Xat(e,t);function ku(e,t){let n=V1(e.state.selection,r=>{let s=t(r);return xt.range(r.anchor,s.head,s.goalColumn,s.bidiLevel||void 0,s.assoc)});return n.eq(e.state.selection)?!1:(e.dispatch(wd(e.state,n)),!0)}function z0e(e,t){return ku(e,n=>e.moveByChar(n,t))}const B0e=e=>z0e(e,!Jo(e)),U0e=e=>z0e(e,Jo(e));function q0e(e,t){return ku(e,n=>e.moveByGroup(n,t))}const tot=e=>q0e(e,!Jo(e)),not=e=>q0e(e,Jo(e)),rot=e=>ku(e,t=>FI(e.state,t,!Jo(e))),sot=e=>ku(e,t=>FI(e.state,t,Jo(e)));function V0e(e,t){return ku(e,n=>e.moveVertically(n,t))}const H0e=e=>V0e(e,!1),K0e=e=>V0e(e,!0);function W0e(e,t){return ku(e,n=>e.moveVertically(n,t,$0e(e).height))}const YX=e=>W0e(e,!1),JX=e=>W0e(e,!0),iot=e=>ku(e,t=>Ug(e,t,!0)),aot=e=>ku(e,t=>Ug(e,t,!1)),oot=e=>ku(e,t=>Ug(e,t,!Jo(e))),lot=e=>ku(e,t=>Ug(e,t,Jo(e))),cot=e=>ku(e,t=>xt.cursor(e.lineBlockAt(t.head).from)),uot=e=>ku(e,t=>xt.cursor(e.lineBlockAt(t.head).to)),ZX=({state:e,dispatch:t})=>(t(wd(e,{anchor:0})),!0),XX=({state:e,dispatch:t})=>(t(wd(e,{anchor:e.doc.length})),!0),eee=({state:e,dispatch:t})=>(t(wd(e,{anchor:e.selection.main.anchor,head:0})),!0),tee=({state:e,dispatch:t})=>(t(wd(e,{anchor:e.selection.main.anchor,head:e.doc.length})),!0),dot=({state:e,dispatch:t})=>(t(e.update({selection:{anchor:0,head:e.doc.length},userEvent:"select"})),!0),fot=({state:e,dispatch:t})=>{let n=zI(e).map(({from:r,to:s})=>xt.range(r,Math.min(s+1,e.doc.length)));return t(e.update({selection:xt.create(n),userEvent:"select"})),!0},hot=({state:e,dispatch:t})=>{let n=V1(e.selection,r=>{let s=wo(e),a=s.resolveStack(r.from,1);if(r.empty){let o=s.resolveStack(r.from,-1);o.node.from>=a.node.from&&o.node.to<=a.node.to&&(a=o)}for(let o=a;o;o=o.next){let{node:l}=o;if((l.from<r.from&&l.to>=r.to||l.to>r.to&&l.from<=r.from)&&o.next)return xt.range(l.to,l.from)}return r});return n.eq(e.selection)?!1:(t(wd(e,n)),!0)};function G0e(e,t){let{state:n}=e,r=n.selection,s=n.selection.ranges.slice();for(let a of n.selection.ranges){let o=n.doc.lineAt(a.head);if(t?o.to<e.state.doc.length:o.from>0)for(let l=a;;){let c=e.moveVertically(l,t);if(c.head<o.from||c.head>o.to){s.some(u=>u.head==c.head)||s.push(c);break}else{if(c.head==l.head)break;l=c}}}return s.length==r.ranges.length?!1:(e.dispatch(wd(n,xt.create(s,s.length-1))),!0)}const mot=e=>G0e(e,!1),pot=e=>G0e(e,!0),got=({state:e,dispatch:t})=>{let n=e.selection,r=null;return n.ranges.length>1?r=xt.create([n.main]):n.main.empty||(r=xt.create([xt.cursor(n.main.head)])),r?(t(wd(e,r)),!0):!1};function ZC(e,t){if(e.state.readOnly)return!1;let n="delete.selection",{state:r}=e,s=r.changeByRange(a=>{let{from:o,to:l}=a;if(o==l){let c=t(a);c<o?(n="delete.backward",c=T_(e,c,!1)):c>o&&(n="delete.forward",c=T_(e,c,!0)),o=Math.min(o,c),l=Math.max(l,c)}else o=T_(e,o,!1),l=T_(e,l,!0);return o==l?{range:a}:{changes:{from:o,to:l},range:xt.cursor(o,o<a.head?-1:1)}});return s.changes.empty?!1:(e.dispatch(r.update(s,{scrollIntoView:!0,userEvent:n,effects:n=="delete.selection"?Yt.announce.of(r.phrase("Selection deleted")):void 0})),!0)}function T_(e,t,n){if(e instanceof Yt)for(let r of e.state.facet(Yt.atomicRanges).map(s=>s(e)))r.between(t,t,(s,a)=>{s<t&&a>t&&(t=n?a:s)});return t}const Q0e=(e,t,n)=>ZC(e,r=>{let s=r.from,{state:a}=e,o=a.doc.lineAt(s),l,c;if(n&&!t&&s>o.from&&s<o.from+200&&!/[^ \t]/.test(l=o.text.slice(0,s-o.from))){if(l[l.length-1]==" ")return s-1;let u=U1(l,a.tabSize),d=u%Wb(a)||Wb(a);for(let h=0;h<d&&l[l.length-1-h]==" ";h++)s--;c=s}else c=za(o.text,s-o.from,t,t)+o.from,c==s&&o.number!=(t?a.doc.lines:1)?c+=t?1:-1:!t&&/[\ufe00-\ufe0f]/.test(o.text.slice(c-o.from,s-o.from))&&(c=za(o.text,c-o.from,!1,!1)+o.from);return c}),b$=e=>Q0e(e,!1,!0),Y0e=e=>Q0e(e,!0,!1),J0e=(e,t)=>ZC(e,n=>{let r=n.head,{state:s}=e,a=s.doc.lineAt(r),o=s.charCategorizer(r);for(let l=null;;){if(r==(t?a.to:a.from)){r==n.head&&a.number!=(t?s.doc.lines:1)&&(r+=t?1:-1);break}let c=za(a.text,r-a.from,t)+a.from,u=a.text.slice(Math.min(r,c)-a.from,Math.max(r,c)-a.from),d=o(u);if(l!=null&&d!=l)break;(u!=" "||r!=n.head)&&(l=d),r=c}return r}),Z0e=e=>J0e(e,!1),xot=e=>J0e(e,!0),bot=e=>ZC(e,t=>{let n=e.lineBlockAt(t.head).to;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}),yot=e=>ZC(e,t=>{let n=e.moveToLineBoundary(t,!1).head;return t.head>n?n:Math.max(0,t.head-1)}),vot=e=>ZC(e,t=>{let n=e.moveToLineBoundary(t,!0).head;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}),wot=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(r=>({changes:{from:r.from,to:r.to,insert:ts.of(["",""])},range:xt.cursor(r.from)}));return t(e.update(n,{scrollIntoView:!0,userEvent:"input"})),!0},kot=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(r=>{if(!r.empty||r.from==0||r.from==e.doc.length)return{range:r};let s=r.from,a=e.doc.lineAt(s),o=s==a.from?s-1:za(a.text,s-a.from,!1)+a.from,l=s==a.to?s+1:za(a.text,s-a.from,!0)+a.from;return{changes:{from:o,to:l,insert:e.doc.slice(s,l).append(e.doc.slice(o,s))},range:xt.cursor(l)}});return n.changes.empty?!1:(t(e.update(n,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function zI(e){let t=[],n=-1;for(let r of e.selection.ranges){let s=e.doc.lineAt(r.from),a=e.doc.lineAt(r.to);if(!r.empty&&r.to==a.from&&(a=e.doc.lineAt(r.to-1)),n>=s.number){let o=t[t.length-1];o.to=a.to,o.ranges.push(r)}else t.push({from:s.from,to:a.to,ranges:[r]});n=a.number+1}return t}function X0e(e,t,n){if(e.readOnly)return!1;let r=[],s=[];for(let a of zI(e)){if(n?a.to==e.doc.length:a.from==0)continue;let o=e.doc.lineAt(n?a.to+1:a.from-1),l=o.length+1;if(n){r.push({from:a.to,to:o.to},{from:a.from,insert:o.text+e.lineBreak});for(let c of a.ranges)s.push(xt.range(Math.min(e.doc.length,c.anchor+l),Math.min(e.doc.length,c.head+l)))}else{r.push({from:o.from,to:a.from},{from:a.to,insert:e.lineBreak+o.text});for(let c of a.ranges)s.push(xt.range(c.anchor-l,c.head-l))}}return r.length?(t(e.update({changes:r,scrollIntoView:!0,selection:xt.create(s,e.selection.mainIndex),userEvent:"move.line"})),!0):!1}const jot=({state:e,dispatch:t})=>X0e(e,t,!1),Not=({state:e,dispatch:t})=>X0e(e,t,!0);function eve(e,t,n){if(e.readOnly)return!1;let r=[];for(let a of zI(e))n?r.push({from:a.from,insert:e.doc.slice(a.from,a.to)+e.lineBreak}):r.push({from:a.to,insert:e.lineBreak+e.doc.slice(a.from,a.to)});let s=e.changes(r);return t(e.update({changes:s,selection:e.selection.map(s,n?1:-1),scrollIntoView:!0,userEvent:"input.copyline"})),!0}const Cot=({state:e,dispatch:t})=>eve(e,t,!1),Sot=({state:e,dispatch:t})=>eve(e,t,!0),_ot=e=>{if(e.state.readOnly)return!1;let{state:t}=e,n=t.changes(zI(t).map(({from:s,to:a})=>(s>0?s--:a<t.doc.length&&a++,{from:s,to:a}))),r=V1(t.selection,s=>{let a;if(e.lineWrapping){let o=e.lineBlockAt(s.head),l=e.coordsAtPos(s.head,s.assoc||1);l&&(a=o.bottom+e.documentTop-l.bottom+e.defaultLineHeight/2)}return e.moveVertically(s,!0,a)}).map(n);return e.dispatch({changes:n,selection:r,scrollIntoView:!0,userEvent:"delete.line"}),!0};function Aot(e,t){if(/\(\)|\[\]|\{\}/.test(e.sliceDoc(t-1,t+1)))return{from:t,to:t};let n=wo(e).resolveInner(t),r=n.childBefore(t),s=n.childAfter(t),a;return r&&s&&r.to<=t&&s.from>=t&&(a=r.type.prop(jr.closedBy))&&a.indexOf(s.name)>-1&&e.doc.lineAt(r.to).from==e.doc.lineAt(s.from).from&&!/\S/.test(e.sliceDoc(r.to,s.from))?{from:r.to,to:s.from}:null}const nee=tve(!1),Eot=tve(!0);function tve(e){return({state:t,dispatch:n})=>{if(t.readOnly)return!1;let r=t.changeByRange(s=>{let{from:a,to:o}=s,l=t.doc.lineAt(a),c=!e&&a==o&&Aot(t,a);e&&(a=o=(o<=l.to?l:t.doc.lineAt(o)).to);let u=new OI(t,{simulateBreak:a,simulateDoubleBreak:!!c}),d=KB(u,a);for(d==null&&(d=U1(/^\s*/.exec(t.doc.lineAt(a).text)[0],t.tabSize));o<l.to&&/\s/.test(l.text[o-l.from]);)o++;c?{from:a,to:o}=c:a>l.from&&a<l.from+100&&!/\S/.test(l.text.slice(0,a))&&(a=l.from);let h=["",MN(t,d)];return c&&h.push(MN(t,u.lineIndent(l.from,-1))),{changes:{from:a,to:o,insert:ts.of(h)},range:xt.cursor(a+1+h[1].length)}});return n(t.update(r,{scrollIntoView:!0,userEvent:"input"})),!0}}function oU(e,t){let n=-1;return e.changeByRange(r=>{let s=[];for(let o=r.from;o<=r.to;){let l=e.doc.lineAt(o);l.number>n&&(r.empty||r.to>l.from)&&(t(l,s,r),n=l.number),o=l.to+1}let a=e.changes(s);return{changes:s,range:xt.range(a.mapPos(r.anchor,1),a.mapPos(r.head,1))}})}const Tot=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=Object.create(null),r=new OI(e,{overrideIndentation:a=>{let o=n[a];return o??-1}}),s=oU(e,(a,o,l)=>{let c=KB(r,a.from);if(c==null)return;/\S/.test(a.text)||(c=0);let u=/^\s*/.exec(a.text)[0],d=MN(e,c);(u!=d||l.from<a.from+u.length)&&(n[a.from]=c,o.push({from:a.from,to:a.from+u.length,insert:d}))});return s.changes.empty||t(e.update(s,{userEvent:"indent"})),!0},nve=({state:e,dispatch:t})=>e.readOnly?!1:(t(e.update(oU(e,(n,r)=>{r.push({from:n.from,insert:e.facet(MI)})}),{userEvent:"input.indent"})),!0),rve=({state:e,dispatch:t})=>e.readOnly?!1:(t(e.update(oU(e,(n,r)=>{let s=/^\s*/.exec(n.text)[0];if(!s)return;let a=U1(s,e.tabSize),o=0,l=MN(e,Math.max(0,a-Wb(e)));for(;o<s.length&&o<l.length&&s.charCodeAt(o)==l.charCodeAt(o);)o++;r.push({from:n.from+o,to:n.from+s.length,insert:l.slice(o)})}),{userEvent:"delete.dedent"})),!0),Iot=e=>(e.setTabFocusMode(),!0),Rot=[{key:"Ctrl-b",run:R0e,shift:B0e,preventDefault:!0},{key:"Ctrl-f",run:M0e,shift:U0e},{key:"Ctrl-p",run:P0e,shift:H0e},{key:"Ctrl-n",run:L0e,shift:K0e},{key:"Ctrl-a",run:Jat,shift:cot},{key:"Ctrl-e",run:Zat,shift:uot},{key:"Ctrl-d",run:Y0e},{key:"Ctrl-h",run:b$},{key:"Ctrl-k",run:bot},{key:"Ctrl-Alt-h",run:Z0e},{key:"Ctrl-o",run:wot},{key:"Ctrl-t",run:kot},{key:"Ctrl-v",run:x$}],Mot=[{key:"ArrowLeft",run:R0e,shift:B0e,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:Uat,shift:tot,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:Qat,shift:oot,preventDefault:!0},{key:"ArrowRight",run:M0e,shift:U0e,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:qat,shift:not,preventDefault:!0},{mac:"Cmd-ArrowRight",run:Yat,shift:lot,preventDefault:!0},{key:"ArrowUp",run:P0e,shift:H0e,preventDefault:!0},{mac:"Cmd-ArrowUp",run:ZX,shift:eee},{mac:"Ctrl-ArrowUp",run:QX,shift:YX},{key:"ArrowDown",run:L0e,shift:K0e,preventDefault:!0},{mac:"Cmd-ArrowDown",run:XX,shift:tee},{mac:"Ctrl-ArrowDown",run:x$,shift:JX},{key:"PageUp",run:QX,shift:YX},{key:"PageDown",run:x$,shift:JX},{key:"Home",run:Gat,shift:aot,preventDefault:!0},{key:"Mod-Home",run:ZX,shift:eee},{key:"End",run:Wat,shift:iot,preventDefault:!0},{key:"Mod-End",run:XX,shift:tee},{key:"Enter",run:nee,shift:nee},{key:"Mod-a",run:dot},{key:"Backspace",run:b$,shift:b$,preventDefault:!0},{key:"Delete",run:Y0e,preventDefault:!0},{key:"Mod-Backspace",mac:"Alt-Backspace",run:Z0e,preventDefault:!0},{key:"Mod-Delete",mac:"Alt-Delete",run:xot,preventDefault:!0},{mac:"Mod-Backspace",run:yot,preventDefault:!0},{mac:"Mod-Delete",run:vot,preventDefault:!0}].concat(Rot.map(e=>({mac:e.key,run:e.run,shift:e.shift}))),Oot=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:Hat,shift:rot},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:Kat,shift:sot},{key:"Alt-ArrowUp",run:jot},{key:"Shift-Alt-ArrowUp",run:Cot},{key:"Alt-ArrowDown",run:Not},{key:"Shift-Alt-ArrowDown",run:Sot},{key:"Mod-Alt-ArrowUp",run:mot},{key:"Mod-Alt-ArrowDown",run:pot},{key:"Escape",run:got},{key:"Mod-Enter",run:Eot},{key:"Alt-l",mac:"Ctrl-l",run:fot},{key:"Mod-i",run:hot,preventDefault:!0},{key:"Mod-[",run:rve},{key:"Mod-]",run:nve},{key:"Mod-Alt-\\",run:Tot},{key:"Shift-Mod-k",run:_ot},{key:"Shift-Mod-\\",run:eot},{key:"Mod-/",run:jat},{key:"Alt-A",run:Cat},{key:"Ctrl-m",mac:"Shift-Alt-m",run:Iot}].concat(Mot),Dot={key:"Tab",run:nve,shift:rve};function Pot(e,t,n,r){const s=Cf(fi),a=kc($ge),o=se.useRef(null),{lexicalNode:l}=S6(),c=se.useRef(!1),u=se.useRef(!1),d=se.useCallback(()=>{a({editorType:t,rootNode:l,editorRef:o.current})},[t,l,a]),h=se.useCallback(m=>{var g,b,v,j,k,w;if(m.key==="ArrowDown"){const N=(b=(g=o.current)==null?void 0:g.getCodemirror())==null?void 0:b.state;if(N){const S=N.doc.length,A=N.selection.ranges[0].to;S===A&&(c.current?(s==null||s.update(()=>{var _,E;const I=pf(e);I.getNextSibling()?((E=(_=o.current)==null?void 0:_.getCodemirror())==null||E.contentDOM.blur(),I.selectNext()):I.insertAfter(Js())}),c.current=!1):c.current=!0)}}else if(m.key==="ArrowUp"){const N=(j=(v=o.current)==null?void 0:v.getCodemirror())==null?void 0:j.state;N&&N.selection.ranges[0].from===0&&(u.current?(s==null||s.update(()=>{var A,_;const E=pf(e);E.getPreviousSibling()&&((_=(A=o.current)==null?void 0:A.getCodemirror())==null||_.contentDOM.blur(),E.selectPrevious())}),u.current=!1):u.current=!0)}else if(m.key==="Enter")m.stopPropagation();else if(m.key==="Backspace"||m.key==="Delete"){const N=(w=(k=o.current)==null?void 0:k.getCodemirror())==null?void 0:w.state;(N==null?void 0:N.doc.length)===0&&(s==null||s.update(()=>{pf(e).remove()}))}},[s,e]);return se.useEffect(()=>{const m=o.current;return setTimeout(()=>{var g,b;(g=m==null?void 0:m.getCodemirror())==null||g.contentDOM.addEventListener("focus",d),(b=m==null?void 0:m.getCodemirror())==null||b.contentDOM.addEventListener("keydown",h)},300),()=>{var g,b;(g=m==null?void 0:m.getCodemirror())==null||g.contentDOM.removeEventListener("focus",d),(b=m==null?void 0:m.getCodemirror())==null||b.contentDOM.removeEventListener("keydown",h)}},[o,d,h,n]),se.useEffect(()=>{r.subscribe(()=>{var m,g;(g=(m=o.current)==null?void 0:m.getCodemirror())==null||g.focus(),d()})},[r,o,e,d]),o}function St(e){return new Pst(GB.define(e))}function Ym(e){return ut(()=>import("./index-DuqLiAIL.js"),__vite__mapDeps([0,1])).then(t=>t.sql({dialect:t[e]}))}const Lot=[st.of({name:"C",extensions:["c","h","ino"],load(){return ut(()=>import("./index-BSI5T_q4.js"),__vite__mapDeps([2,1])).then(e=>e.cpp())}}),st.of({name:"C++",alias:["cpp"],extensions:["cpp","c++","cc","cxx","hpp","h++","hh","hxx"],load(){return ut(()=>import("./index-BSI5T_q4.js"),__vite__mapDeps([2,1])).then(e=>e.cpp())}}),st.of({name:"CQL",alias:["cassandra"],extensions:["cql"],load(){return Ym("Cassandra")}}),st.of({name:"CSS",extensions:["css"],load(){return ut(()=>import("./index-C7Cmw8dX.js"),__vite__mapDeps([3,1])).then(e=>e.css())}}),st.of({name:"Go",extensions:["go"],load(){return ut(()=>import("./index-Cfn-GmgI.js"),__vite__mapDeps([4,1])).then(e=>e.go())}}),st.of({name:"HTML",alias:["xhtml"],extensions:["html","htm","handlebars","hbs"],load(){return ut(()=>import("./index-B1de0GcS.js"),__vite__mapDeps([5,1,3,6])).then(e=>e.html())}}),st.of({name:"Java",extensions:["java"],load(){return ut(()=>import("./index-BABkBYsI.js"),__vite__mapDeps([7,1])).then(e=>e.java())}}),st.of({name:"JavaScript",alias:["ecmascript","js","node"],extensions:["js","mjs","cjs"],load(){return ut(()=>import("./index-C3puStO3.js"),__vite__mapDeps([6,1])).then(e=>e.javascript())}}),st.of({name:"Jinja",extensions:["j2","jinja","jinja2"],load(){return ut(()=>import("./index-DmZZmv9g.js"),__vite__mapDeps([8,5,1,3,6])).then(e=>e.jinja())}}),st.of({name:"JSON",alias:["json5"],extensions:["json","map"],load(){return ut(()=>import("./index-WuWP8I5T.js"),__vite__mapDeps([9,1])).then(e=>e.json())}}),st.of({name:"JSX",extensions:["jsx"],load(){return ut(()=>import("./index-C3puStO3.js"),__vite__mapDeps([6,1])).then(e=>e.javascript({jsx:!0}))}}),st.of({name:"LESS",extensions:["less"],load(){return ut(()=>import("./index-B8i0_qWK.js"),__vite__mapDeps([10,3,1])).then(e=>e.less())}}),st.of({name:"Liquid",extensions:["liquid"],load(){return ut(()=>import("./index-D9D4KyAP.js"),__vite__mapDeps([11,5,1,3,6])).then(e=>e.liquid())}}),st.of({name:"MariaDB SQL",load(){return Ym("MariaSQL")}}),st.of({name:"Markdown",extensions:["md","markdown","mkd"],load(){return ut(()=>import("./index-CPrGAvvf.js"),__vite__mapDeps([12,5,1,3,6])).then(e=>e.markdown())}}),st.of({name:"MS SQL",load(){return Ym("MSSQL")}}),st.of({name:"MySQL",load(){return Ym("MySQL")}}),st.of({name:"PHP",extensions:["php","php3","php4","php5","php7","phtml"],load(){return ut(()=>import("./index-BmcxJrjx.js"),__vite__mapDeps([13,1,5,3,6])).then(e=>e.php())}}),st.of({name:"PLSQL",extensions:["pls"],load(){return Ym("PLSQL")}}),st.of({name:"PostgreSQL",load(){return Ym("PostgreSQL")}}),st.of({name:"Python",extensions:["BUILD","bzl","py","pyw"],filename:/^(BUCK|BUILD)$/,load(){return ut(()=>import("./index-NgDP54Ta.js"),__vite__mapDeps([14,1])).then(e=>e.python())}}),st.of({name:"Rust",extensions:["rs"],load(){return ut(()=>import("./index-DptZkFjs.js"),__vite__mapDeps([15,1])).then(e=>e.rust())}}),st.of({name:"Sass",extensions:["sass"],load(){return ut(()=>import("./index-Dndw5aiH.js"),__vite__mapDeps([16,1,3])).then(e=>e.sass({indented:!0}))}}),st.of({name:"SCSS",extensions:["scss"],load(){return ut(()=>import("./index-Dndw5aiH.js"),__vite__mapDeps([16,1,3])).then(e=>e.sass())}}),st.of({name:"SQL",extensions:["sql"],load(){return Ym("StandardSQL")}}),st.of({name:"SQLite",load(){return Ym("SQLite")}}),st.of({name:"TSX",extensions:["tsx"],load(){return ut(()=>import("./index-C3puStO3.js"),__vite__mapDeps([6,1])).then(e=>e.javascript({jsx:!0,typescript:!0}))}}),st.of({name:"TypeScript",alias:["ts"],extensions:["ts","mts","cts"],load(){return ut(()=>import("./index-C3puStO3.js"),__vite__mapDeps([6,1])).then(e=>e.javascript({typescript:!0}))}}),st.of({name:"WebAssembly",extensions:["wat","wast"],load(){return ut(()=>import("./index-D_cP5U44.js"),__vite__mapDeps([17,1])).then(e=>e.wast())}}),st.of({name:"XML",alias:["rss","wsdl","xsd"],extensions:["xml","xsl","xsd","svg"],load(){return ut(()=>import("./index-BJSp5aCY.js"),__vite__mapDeps([18,1])).then(e=>e.xml())}}),st.of({name:"YAML",alias:["yml"],extensions:["yaml","yml"],load(){return ut(()=>import("./index-B2EnQtkM.js"),__vite__mapDeps([19,1])).then(e=>e.yaml())}}),st.of({name:"APL",extensions:["dyalog","apl"],load(){return ut(()=>import("./apl-B4CMkyY2.js"),[]).then(e=>St(e.apl))}}),st.of({name:"PGP",alias:["asciiarmor"],extensions:["asc","pgp","sig"],load(){return ut(()=>import("./asciiarmor-Df11BRmG.js"),[]).then(e=>St(e.asciiArmor))}}),st.of({name:"ASN.1",extensions:["asn","asn1"],load(){return ut(()=>import("./asn1-EdZsLKOL.js"),[]).then(e=>St(e.asn1({})))}}),st.of({name:"Asterisk",filename:/^extensions\.conf$/i,load(){return ut(()=>import("./asterisk-B-8jnY81.js"),[]).then(e=>St(e.asterisk))}}),st.of({name:"Brainfuck",extensions:["b","bf"],load(){return ut(()=>import("./brainfuck-C4LP7Hcl.js"),[]).then(e=>St(e.brainfuck))}}),st.of({name:"Cobol",extensions:["cob","cpy"],load(){return ut(()=>import("./cobol-CWcv1MsR.js"),[]).then(e=>St(e.cobol))}}),st.of({name:"C#",alias:["csharp","cs"],extensions:["cs"],load(){return ut(()=>import("./clike-B9uivgTg.js"),[]).then(e=>St(e.csharp))}}),st.of({name:"Clojure",extensions:["clj","cljc","cljx"],load(){return ut(()=>import("./clojure-BMjYHr_A.js"),[]).then(e=>St(e.clojure))}}),st.of({name:"ClojureScript",extensions:["cljs"],load(){return ut(()=>import("./clojure-BMjYHr_A.js"),[]).then(e=>St(e.clojure))}}),st.of({name:"Closure Stylesheets (GSS)",extensions:["gss"],load(){return ut(()=>import("./css-BnMrqG3P.js"),[]).then(e=>St(e.gss))}}),st.of({name:"CMake",extensions:["cmake","cmake.in"],filename:/^CMakeLists\.txt$/,load(){return ut(()=>import("./cmake-BQqOBYOt.js"),[]).then(e=>St(e.cmake))}}),st.of({name:"CoffeeScript",alias:["coffee","coffee-script"],extensions:["coffee"],load(){return ut(()=>import("./coffeescript-S37ZYGWr.js"),[]).then(e=>St(e.coffeeScript))}}),st.of({name:"Common Lisp",alias:["lisp"],extensions:["cl","lisp","el"],load(){return ut(()=>import("./commonlisp-DBKNyK5s.js"),[]).then(e=>St(e.commonLisp))}}),st.of({name:"Cypher",extensions:["cyp","cypher"],load(){return ut(()=>import("./cypher-C_CwsFkJ.js"),[]).then(e=>St(e.cypher))}}),st.of({name:"Cython",extensions:["pyx","pxd","pxi"],load(){return ut(()=>import("./python-BuPzkPfP.js"),[]).then(e=>St(e.cython))}}),st.of({name:"Crystal",extensions:["cr"],load(){return ut(()=>import("./crystal-SjHAIU92.js"),[]).then(e=>St(e.crystal))}}),st.of({name:"D",extensions:["d"],load(){return ut(()=>import("./d-pRatUO7H.js"),[]).then(e=>St(e.d))}}),st.of({name:"Dart",extensions:["dart"],load(){return ut(()=>import("./clike-B9uivgTg.js"),[]).then(e=>St(e.dart))}}),st.of({name:"diff",extensions:["diff","patch"],load(){return ut(()=>import("./diff-DbItnlRl.js"),[]).then(e=>St(e.diff))}}),st.of({name:"Dockerfile",filename:/^Dockerfile$/,load(){return ut(()=>import("./dockerfile-BKs6k2Af.js"),__vite__mapDeps([20,21])).then(e=>St(e.dockerFile))}}),st.of({name:"DTD",extensions:["dtd"],load(){return ut(()=>import("./dtd-DF_7sFjM.js"),[]).then(e=>St(e.dtd))}}),st.of({name:"Dylan",extensions:["dylan","dyl","intr"],load(){return ut(()=>import("./dylan-DwRh75JA.js"),[]).then(e=>St(e.dylan))}}),st.of({name:"EBNF",load(){return ut(()=>import("./ebnf-CDyGwa7X.js"),[]).then(e=>St(e.ebnf))}}),st.of({name:"ECL",extensions:["ecl"],load(){return ut(()=>import("./ecl-Cabwm37j.js"),[]).then(e=>St(e.ecl))}}),st.of({name:"edn",extensions:["edn"],load(){return ut(()=>import("./clojure-BMjYHr_A.js"),[]).then(e=>St(e.clojure))}}),st.of({name:"Eiffel",extensions:["e"],load(){return ut(()=>import("./eiffel-CnydiIhH.js"),[]).then(e=>St(e.eiffel))}}),st.of({name:"Elm",extensions:["elm"],load(){return ut(()=>import("./elm-vLlmbW-K.js"),[]).then(e=>St(e.elm))}}),st.of({name:"Erlang",extensions:["erl"],load(){return ut(()=>import("./erlang-BNw1qcRV.js"),[]).then(e=>St(e.erlang))}}),st.of({name:"Esper",load(){return ut(()=>import("./sql-D0XecflT.js"),[]).then(e=>St(e.esper))}}),st.of({name:"Factor",extensions:["factor"],load(){return ut(()=>import("./factor-kuTfRLto.js"),__vite__mapDeps([22,21])).then(e=>St(e.factor))}}),st.of({name:"FCL",load(){return ut(()=>import("./fcl-Kvtd6kyn.js"),[]).then(e=>St(e.fcl))}}),st.of({name:"Forth",extensions:["forth","fth","4th"],load(){return ut(()=>import("./forth-Ffai-XNe.js"),[]).then(e=>St(e.forth))}}),st.of({name:"Fortran",extensions:["f","for","f77","f90","f95"],load(){return ut(()=>import("./fortran-DYz_wnZ1.js"),[]).then(e=>St(e.fortran))}}),st.of({name:"F#",alias:["fsharp"],extensions:["fs"],load(){return ut(()=>import("./mllike-CXdrOF99.js"),[]).then(e=>St(e.fSharp))}}),st.of({name:"Gas",extensions:["s"],load(){return ut(()=>import("./gas-Bneqetm1.js"),[]).then(e=>St(e.gas))}}),st.of({name:"Gherkin",extensions:["feature"],load(){return ut(()=>import("./gherkin-heZmZLOM.js"),[]).then(e=>St(e.gherkin))}}),st.of({name:"Groovy",extensions:["groovy","gradle"],filename:/^Jenkinsfile$/,load(){return ut(()=>import("./groovy-D9Dt4D0W.js"),[]).then(e=>St(e.groovy))}}),st.of({name:"Haskell",extensions:["hs"],load(){return ut(()=>import("./haskell-Cw1EW3IL.js"),[]).then(e=>St(e.haskell))}}),st.of({name:"Haxe",extensions:["hx"],load(){return ut(()=>import("./haxe-H-WmDvRZ.js"),[]).then(e=>St(e.haxe))}}),st.of({name:"HXML",extensions:["hxml"],load(){return ut(()=>import("./haxe-H-WmDvRZ.js"),[]).then(e=>St(e.hxml))}}),st.of({name:"HTTP",load(){return ut(()=>import("./http-DBlCnlav.js"),[]).then(e=>St(e.http))}}),st.of({name:"IDL",extensions:["pro"],load(){return ut(()=>import("./idl-BEugSyMb.js"),[]).then(e=>St(e.idl))}}),st.of({name:"JSON-LD",alias:["jsonld"],extensions:["jsonld"],load(){return ut(()=>import("./javascript-iXu5QeM3.js"),[]).then(e=>St(e.jsonld))}}),st.of({name:"Julia",extensions:["jl"],load(){return ut(()=>import("./julia-DuME0IfC.js"),[]).then(e=>St(e.julia))}}),st.of({name:"Kotlin",extensions:["kt","kts"],load(){return ut(()=>import("./clike-B9uivgTg.js"),[]).then(e=>St(e.kotlin))}}),st.of({name:"LiveScript",alias:["ls"],extensions:["ls"],load(){return ut(()=>import("./livescript-BwQOo05w.js"),[]).then(e=>St(e.liveScript))}}),st.of({name:"Lua",extensions:["lua"],load(){return ut(()=>import("./lua-BgMRiT3U.js"),[]).then(e=>St(e.lua))}}),st.of({name:"mIRC",extensions:["mrc"],load(){return ut(()=>import("./mirc-CjQqDB4T.js"),[]).then(e=>St(e.mirc))}}),st.of({name:"Mathematica",extensions:["m","nb","wl","wls"],load(){return ut(()=>import("./mathematica-DTrFuWx2.js"),[]).then(e=>St(e.mathematica))}}),st.of({name:"Modelica",extensions:["mo"],load(){return ut(()=>import("./modelica-Dc1JOy9r.js"),[]).then(e=>St(e.modelica))}}),st.of({name:"MUMPS",extensions:["mps"],load(){return ut(()=>import("./mumps-BT43cFF4.js"),[]).then(e=>St(e.mumps))}}),st.of({name:"Mbox",extensions:["mbox"],load(){return ut(()=>import("./mbox-CNhZ1qSd.js"),[]).then(e=>St(e.mbox))}}),st.of({name:"Nginx",filename:/nginx.*\.conf$/i,load(){return ut(()=>import("./nginx-DdIZxoE0.js"),[]).then(e=>St(e.nginx))}}),st.of({name:"NSIS",extensions:["nsh","nsi"],load(){return ut(()=>import("./nsis-LdVXkNf5.js"),__vite__mapDeps([23,21])).then(e=>St(e.nsis))}}),st.of({name:"NTriples",extensions:["nt","nq"],load(){return ut(()=>import("./ntriples-BfvgReVJ.js"),[]).then(e=>St(e.ntriples))}}),st.of({name:"Objective-C",alias:["objective-c","objc"],extensions:["m"],load(){return ut(()=>import("./clike-B9uivgTg.js"),[]).then(e=>St(e.objectiveC))}}),st.of({name:"Objective-C++",alias:["objective-c++","objc++"],extensions:["mm"],load(){return ut(()=>import("./clike-B9uivgTg.js"),[]).then(e=>St(e.objectiveCpp))}}),st.of({name:"OCaml",extensions:["ml","mli","mll","mly"],load(){return ut(()=>import("./mllike-CXdrOF99.js"),[]).then(e=>St(e.oCaml))}}),st.of({name:"Octave",extensions:["m"],load(){return ut(()=>import("./octave-Ck1zUtKM.js"),[]).then(e=>St(e.octave))}}),st.of({name:"Oz",extensions:["oz"],load(){return ut(()=>import("./oz-BzwKVEFT.js"),[]).then(e=>St(e.oz))}}),st.of({name:"Pascal",extensions:["p","pas"],load(){return ut(()=>import("./pascal--L3eBynH.js"),[]).then(e=>St(e.pascal))}}),st.of({name:"Perl",extensions:["pl","pm"],load(){return ut(()=>import("./perl-CdXCOZ3F.js"),[]).then(e=>St(e.perl))}}),st.of({name:"Pig",extensions:["pig"],load(){return ut(()=>import("./pig-CevX1Tat.js"),[]).then(e=>St(e.pig))}}),st.of({name:"PowerShell",extensions:["ps1","psd1","psm1"],load(){return ut(()=>import("./powershell-CFHJl5sT.js"),[]).then(e=>St(e.powerShell))}}),st.of({name:"Properties files",alias:["ini","properties"],extensions:["properties","ini","in"],load(){return ut(()=>import("./properties-C78fOPTZ.js"),[]).then(e=>St(e.properties))}}),st.of({name:"ProtoBuf",extensions:["proto"],load(){return ut(()=>import("./protobuf-ChK-085T.js"),[]).then(e=>St(e.protobuf))}}),st.of({name:"Pug",alias:["jade"],extensions:["pug","jade"],load(){return ut(()=>import("./pug-DeIclll2.js"),__vite__mapDeps([24,25])).then(e=>St(e.pug))}}),st.of({name:"Puppet",extensions:["pp"],load(){return ut(()=>import("./puppet-DMA9R1ak.js"),[]).then(e=>St(e.puppet))}}),st.of({name:"Q",extensions:["q"],load(){return ut(()=>import("./q-pXgVlZs6.js"),[]).then(e=>St(e.q))}}),st.of({name:"R",alias:["rscript"],extensions:["r","R"],load(){return ut(()=>import("./r-B6wPVr8A.js"),[]).then(e=>St(e.r))}}),st.of({name:"RPM Changes",load(){return ut(()=>import("./rpm-CTu-6PCP.js"),[]).then(e=>St(e.rpmChanges))}}),st.of({name:"RPM Spec",extensions:["spec"],load(){return ut(()=>import("./rpm-CTu-6PCP.js"),[]).then(e=>St(e.rpmSpec))}}),st.of({name:"Ruby",alias:["jruby","macruby","rake","rb","rbx"],extensions:["rb"],filename:/^(Gemfile|Rakefile)$/,load(){return ut(()=>import("./ruby-B2Rjki9n.js"),[]).then(e=>St(e.ruby))}}),st.of({name:"SAS",extensions:["sas"],load(){return ut(()=>import("./sas-B4kiWyti.js"),[]).then(e=>St(e.sas))}}),st.of({name:"Scala",extensions:["scala"],load(){return ut(()=>import("./clike-B9uivgTg.js"),[]).then(e=>St(e.scala))}}),st.of({name:"Scheme",extensions:["scm","ss"],load(){return ut(()=>import("./scheme-C41bIUwD.js"),[]).then(e=>St(e.scheme))}}),st.of({name:"Shell",alias:["bash","sh","zsh"],extensions:["sh","ksh","bash"],filename:/^PKGBUILD$/,load(){return ut(()=>import("./shell-CjFT_Tl9.js"),[]).then(e=>St(e.shell))}}),st.of({name:"Sieve",extensions:["siv","sieve"],load(){return ut(()=>import("./sieve-C3Gn_uJK.js"),[]).then(e=>St(e.sieve))}}),st.of({name:"Smalltalk",extensions:["st"],load(){return ut(()=>import("./smalltalk-CnHTOXQT.js"),[]).then(e=>St(e.smalltalk))}}),st.of({name:"Solr",load(){return ut(()=>import("./solr-DehyRSwq.js"),[]).then(e=>St(e.solr))}}),st.of({name:"SML",extensions:["sml","sig","fun","smackspec"],load(){return ut(()=>import("./mllike-CXdrOF99.js"),[]).then(e=>St(e.sml))}}),st.of({name:"SPARQL",alias:["sparul"],extensions:["rq","sparql"],load(){return ut(()=>import("./sparql-DkYu6x3z.js"),[]).then(e=>St(e.sparql))}}),st.of({name:"Spreadsheet",alias:["excel","formula"],load(){return ut(()=>import("./spreadsheet-BCZA_wO0.js"),[]).then(e=>St(e.spreadsheet))}}),st.of({name:"Squirrel",extensions:["nut"],load(){return ut(()=>import("./clike-B9uivgTg.js"),[]).then(e=>St(e.squirrel))}}),st.of({name:"Stylus",extensions:["styl"],load(){return ut(()=>import("./stylus-B533Al4x.js"),[]).then(e=>St(e.stylus))}}),st.of({name:"Swift",extensions:["swift"],load(){return ut(()=>import("./swift-BzpIVaGY.js"),[]).then(e=>St(e.swift))}}),st.of({name:"sTeX",load(){return ut(()=>import("./stex-C3f8Ysf7.js"),[]).then(e=>St(e.stex))}}),st.of({name:"LaTeX",alias:["tex"],extensions:["text","ltx","tex"],load(){return ut(()=>import("./stex-C3f8Ysf7.js"),[]).then(e=>St(e.stex))}}),st.of({name:"SystemVerilog",extensions:["v","sv","svh"],load(){return ut(()=>import("./verilog-C6RDOZhf.js"),[]).then(e=>St(e.verilog))}}),st.of({name:"Tcl",extensions:["tcl"],load(){return ut(()=>import("./tcl-DVfN8rqt.js"),[]).then(e=>St(e.tcl))}}),st.of({name:"Textile",extensions:["textile"],load(){return ut(()=>import("./textile-CnDTJFAw.js"),[]).then(e=>St(e.textile))}}),st.of({name:"TiddlyWiki",load(){return ut(()=>import("./tiddlywiki-DO-Gjzrf.js"),[]).then(e=>St(e.tiddlyWiki))}}),st.of({name:"Tiki wiki",load(){return ut(()=>import("./tiki-DGYXhP31.js"),[]).then(e=>St(e.tiki))}}),st.of({name:"TOML",extensions:["toml"],load(){return ut(()=>import("./toml-Bm5Em-hy.js"),[]).then(e=>St(e.toml))}}),st.of({name:"Troff",extensions:["1","2","3","4","5","6","7","8","9"],load(){return ut(()=>import("./troff-wAsdV37c.js"),[]).then(e=>St(e.troff))}}),st.of({name:"TTCN",extensions:["ttcn","ttcn3","ttcnpp"],load(){return ut(()=>import("./ttcn-CfJYG6tj.js"),[]).then(e=>St(e.ttcn))}}),st.of({name:"TTCN_CFG",extensions:["cfg"],load(){return ut(()=>import("./ttcn-cfg-B9xdYoR4.js"),[]).then(e=>St(e.ttcnCfg))}}),st.of({name:"Turtle",extensions:["ttl"],load(){return ut(()=>import("./turtle-B1tBg_DP.js"),[]).then(e=>St(e.turtle))}}),st.of({name:"Web IDL",extensions:["webidl"],load(){return ut(()=>import("./webidl-ZXfAyPTL.js"),[]).then(e=>St(e.webIDL))}}),st.of({name:"VB.NET",extensions:["vb"],load(){return ut(()=>import("./vb-CmGdzxic.js"),[]).then(e=>St(e.vb))}}),st.of({name:"VBScript",extensions:["vbs"],load(){return ut(()=>import("./vbscript-BuJXcnF6.js"),[]).then(e=>St(e.vbScript))}}),st.of({name:"Velocity",extensions:["vtl"],load(){return ut(()=>import("./velocity-D8B20fx6.js"),[]).then(e=>St(e.velocity))}}),st.of({name:"Verilog",extensions:["v"],load(){return ut(()=>import("./verilog-C6RDOZhf.js"),[]).then(e=>St(e.verilog))}}),st.of({name:"VHDL",extensions:["vhd","vhdl"],load(){return ut(()=>import("./vhdl-lSbBsy5d.js"),[]).then(e=>St(e.vhdl))}}),st.of({name:"XQuery",extensions:["xy","xquery","xq","xqm","xqy"],load(){return ut(()=>import("./xquery-DzFWVndE.js"),[]).then(e=>St(e.xQuery))}}),st.of({name:"Yacas",extensions:["ys"],load(){return ut(()=>import("./yacas-BJ4BC0dw.js"),[]).then(e=>St(e.yacas))}}),st.of({name:"Z80",extensions:["z80"],load(){return ut(()=>import("./z80-Hz9HOZM7.js"),[]).then(e=>St(e.z80))}}),st.of({name:"MscGen",extensions:["mscgen","mscin","msc"],load(){return ut(()=>import("./mscgen-BA5vi2Kp.js"),[]).then(e=>St(e.mscgen))}}),st.of({name:"Xù",extensions:["xu"],load(){return ut(()=>import("./mscgen-BA5vi2Kp.js"),[]).then(e=>St(e.xu))}}),st.of({name:"MsGenny",extensions:["msgenny"],load(){return ut(()=>import("./mscgen-BA5vi2Kp.js"),[]).then(e=>St(e.msgenny))}}),st.of({name:"Vue",extensions:["vue"],load(){return ut(()=>import("./index-C2FQ4k2x.js"),__vite__mapDeps([26,5,1,3,6])).then(e=>e.vue())}}),st.of({name:"Angular Template",load(){return ut(()=>import("./index-2VLdrule.js"),__vite__mapDeps([27,5,1,3,6])).then(e=>e.angular())}})],ree="#2e3440",lU="#3b4252",see="#434c5e",I_="#4c566a",iee="#e5e9f0",y$="#eceff4",yD="#8fbcbb",aee="#88c0d0",$ot="#81a1c1",Eu="#5e81ac",Fot="#bf616a",o0="#d08770",vD="#ebcb8b",oee="#a3be8c",zot="#b48ead",lee="#d30102",cU=y$,wD=cU,Bot="#ffffff",kD=lU,Uot=cU,cee=lU,qot=Yt.theme({"&":{color:ree,backgroundColor:Bot},".cm-content":{caretColor:cee},".cm-cursor, .cm-dropCursor":{borderLeftColor:cee},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection":{backgroundColor:Uot},".cm-panels":{backgroundColor:cU,color:I_},".cm-panels.cm-panels-top":{borderBottom:"2px solid black"},".cm-panels.cm-panels-bottom":{borderTop:"2px solid black"},".cm-searchMatch":{backgroundColor:"#72a1ff59",outline:`1px solid ${I_}`},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:iee},".cm-activeLine":{backgroundColor:wD},".cm-selectionMatch":{backgroundColor:iee},"&.cm-focused .cm-matchingBracket, &.cm-focused .cm-nonmatchingBracket":{outline:`1px solid ${I_}`},"&.cm-focused .cm-matchingBracket":{backgroundColor:y$},".cm-gutters":{backgroundColor:y$,color:ree,border:"none"},".cm-activeLineGutter":{backgroundColor:wD},".cm-foldPlaceholder":{backgroundColor:"transparent",border:"none",color:"#ddd"},".cm-tooltip":{border:"none",backgroundColor:kD},".cm-tooltip .cm-tooltip-arrow:before":{borderTopColor:"transparent",borderBottomColor:"transparent"},".cm-tooltip .cm-tooltip-arrow:after":{borderTopColor:kD,borderBottomColor:kD},".cm-tooltip-autocomplete":{"& > ul > li[aria-selected]":{backgroundColor:wD,color:I_}}},{dark:!1}),Vot=YC.define([{tag:ct.keyword,color:Eu},{tag:[ct.name,ct.deleted,ct.character,ct.propertyName,ct.macroName],color:o0},{tag:[ct.variableName],color:o0},{tag:[ct.function(ct.variableName)],color:Eu},{tag:[ct.labelName],color:$ot},{tag:[ct.color,ct.constant(ct.name),ct.standard(ct.name)],color:Eu},{tag:[ct.definition(ct.name),ct.separator],color:oee},{tag:[ct.brace],color:yD},{tag:[ct.annotation],color:lee},{tag:[ct.number,ct.changed,ct.annotation,ct.modifier,ct.self,ct.namespace],color:aee},{tag:[ct.typeName,ct.className],color:vD},{tag:[ct.operator,ct.operatorKeyword],color:oee},{tag:[ct.tagName],color:zot},{tag:[ct.squareBracket],color:Fot},{tag:[ct.angleBracket],color:o0},{tag:[ct.attributeName],color:vD},{tag:[ct.regexp],color:Eu},{tag:[ct.quote],color:lU},{tag:[ct.string],color:o0},{tag:ct.link,color:yD,textDecoration:"underline",textUnderlinePosition:"under"},{tag:[ct.url,ct.escape,ct.special(ct.string)],color:o0},{tag:[ct.meta],color:aee},{tag:[ct.comment],color:see,fontStyle:"italic"},{tag:ct.strong,fontWeight:"bold",color:Eu},{tag:ct.emphasis,fontStyle:"italic",color:Eu},{tag:ct.strikethrough,textDecoration:"line-through"},{tag:ct.heading,fontWeight:"bold",color:Eu},{tag:ct.special(ct.heading1),fontWeight:"bold",color:Eu},{tag:ct.heading1,fontWeight:"bold",color:Eu},{tag:[ct.heading2,ct.heading3,ct.heading4],fontWeight:"bold",color:Eu},{tag:[ct.heading5,ct.heading6],color:Eu},{tag:[ct.atom,ct.bool,ct.special(ct.variableName)],color:o0},{tag:[ct.processingInstruction,ct.inserted],color:yD},{tag:[ct.contentSeparator],color:vD},{tag:ct.invalid,color:see,borderBottom:`1px dotted ${lee}`}]),Hot=[qot,i0e(Vot)],uee=typeof String.prototype.normalize=="function"?e=>e.normalize("NFKD"):e=>e;class Yv{constructor(t,n,r=0,s=t.length,a,o){this.test=o,this.value={from:0,to:0},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=t.iterRange(r,s),this.bufferStart=r,this.normalize=a?l=>a(uee(l)):uee,this.query=this.normalize(n)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return Fl(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let t=this.peek();if(t<0)return this.done=!0,this;let n=jB(t),r=this.bufferStart+this.bufferPos;this.bufferPos+=ef(t);let s=this.normalize(n);if(s.length)for(let a=0,o=r;;a++){let l=s.charCodeAt(a),c=this.match(l,o,this.bufferPos+this.bufferStart);if(a==s.length-1){if(c)return this.value=c,this;break}o==r&&a<n.length&&n.charCodeAt(a)==l&&o++}}}match(t,n,r){let s=null;for(let a=0;a<this.matches.length;a+=2){let o=this.matches[a],l=!1;this.query.charCodeAt(o)==t&&(o==this.query.length-1?s={from:this.matches[a+1],to:r}:(this.matches[a]++,l=!0)),l||(this.matches.splice(a,2),a-=2)}return this.query.charCodeAt(0)==t&&(this.query.length==1?s={from:n,to:r}:this.matches.push(1,n)),s&&this.test&&!this.test(s.from,s.to,this.buffer,this.bufferStart)&&(s=null),s}}typeof Symbol<"u"&&(Yv.prototype[Symbol.iterator]=function(){return this});const sve={from:-1,to:-1,match:/.*/.exec("")},uU="gm"+(/x/.unicode==null?"":"u");class ive{constructor(t,n,r,s=0,a=t.length){if(this.text=t,this.to=a,this.curLine="",this.done=!1,this.value=sve,/\\[sWDnr]|\n|\r|\[\^/.test(n))return new ave(t,n,r,s,a);this.re=new RegExp(n,uU+(r!=null&&r.ignoreCase?"i":"")),this.test=r==null?void 0:r.test,this.iter=t.iter();let o=t.lineAt(s);this.curLineStart=o.from,this.matchPos=qE(t,s),this.getLine(this.curLineStart)}getLine(t){this.iter.next(t),this.iter.lineBreak?this.curLine="":(this.curLine=this.iter.value,this.curLineStart+this.curLine.length>this.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart)),this.iter.next())}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1,this.curLineStart>this.to?this.curLine="":this.getLine(0)}next(){for(let t=this.matchPos-this.curLineStart;;){this.re.lastIndex=t;let n=this.matchPos<=this.to&&this.re.exec(this.curLine);if(n){let r=this.curLineStart+n.index,s=r+n[0].length;if(this.matchPos=qE(this.text,s+(r==s?1:0)),r==this.curLineStart+this.curLine.length&&this.nextLine(),(r<s||r>this.value.to)&&(!this.test||this.test(r,s,n)))return this.value={from:r,to:s,match:n},this;t=this.matchPos-this.curLineStart}else if(this.curLineStart+this.curLine.length<this.to)this.nextLine(),t=0;else return this.done=!0,this}}}const jD=new WeakMap;class J0{constructor(t,n){this.from=t,this.text=n}get to(){return this.from+this.text.length}static get(t,n,r){let s=jD.get(t);if(!s||s.from>=r||s.to<=n){let l=new J0(n,t.sliceString(n,r));return jD.set(t,l),l}if(s.from==n&&s.to==r)return s;let{text:a,from:o}=s;return o>n&&(a=t.sliceString(n,o)+a,o=n),s.to<r&&(a+=t.sliceString(s.to,r)),jD.set(t,new J0(o,a)),new J0(n,a.slice(n-o,r-o))}}class ave{constructor(t,n,r,s,a){this.text=t,this.to=a,this.done=!1,this.value=sve,this.matchPos=qE(t,s),this.re=new RegExp(n,uU+(r!=null&&r.ignoreCase?"i":"")),this.test=r==null?void 0:r.test,this.flat=J0.get(t,s,this.chunkEnd(s+5e3))}chunkEnd(t){return t>=this.to?this.to:this.text.lineAt(t).to}next(){for(;;){let t=this.re.lastIndex=this.matchPos-this.flat.from,n=this.re.exec(this.flat.text);if(n&&!n[0]&&n.index==t&&(this.re.lastIndex=t+1,n=this.re.exec(this.flat.text)),n){let r=this.flat.from+n.index,s=r+n[0].length;if((this.flat.to>=this.to||n.index+n[0].length<=this.flat.text.length-10)&&(!this.test||this.test(r,s,n)))return this.value={from:r,to:s,match:n},this.matchPos=qE(this.text,s+(r==s?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=J0.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}}typeof Symbol<"u"&&(ive.prototype[Symbol.iterator]=ave.prototype[Symbol.iterator]=function(){return this});function Kot(e){try{return new RegExp(e,uU),!0}catch{return!1}}function qE(e,t){if(t>=e.length)return t;let n=e.lineAt(t),r;for(;t<n.to&&(r=n.text.charCodeAt(t-n.from))>=56320&&r<57344;)t++;return t}const Wot=e=>{let{state:t}=e,n=String(t.doc.lineAt(e.state.selection.main.head).number),{close:r,result:s}=Yrt(e,{label:t.phrase("Go to line"),input:{type:"text",name:"line",value:n},focus:!0,submitLabel:t.phrase("go")});return s.then(a=>{let o=a&&/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(a.elements.line.value);if(!o){e.dispatch({effects:r});return}let l=t.doc.lineAt(t.selection.main.head),[,c,u,d,h]=o,m=d?+d.slice(1):0,g=u?+u:l.number;if(u&&h){let j=g/100;c&&(j=j*(c=="-"?-1:1)+l.number/t.doc.lines),g=Math.round(t.doc.lines*j)}else u&&c&&(g=g*(c=="-"?-1:1)+l.number);let b=t.doc.line(Math.max(1,Math.min(t.doc.lines,g))),v=xt.cursor(b.from+Math.max(0,Math.min(m,b.length)));e.dispatch({effects:[r,Yt.scrollIntoView(v.from,{y:"center"})],selection:v})}),!0},Got={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},Qot=Zt.define({combine(e){return Pf(e,Got,{highlightWordAroundCursor:(t,n)=>t||n,minSelectionLength:Math.min,maxMatches:Math.min})}});function Yot(e){return[tlt,elt]}const Jot=En.mark({class:"cm-selectionMatch"}),Zot=En.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function dee(e,t,n,r){return(n==0||e(t.sliceDoc(n-1,n))!=hi.Word)&&(r==t.doc.length||e(t.sliceDoc(r,r+1))!=hi.Word)}function Xot(e,t,n,r){return e(t.sliceDoc(n,n+1))==hi.Word&&e(t.sliceDoc(r-1,r))==hi.Word}const elt=Vi.fromClass(class{constructor(e){this.decorations=this.getDeco(e)}update(e){(e.selectionSet||e.docChanged||e.viewportChanged)&&(this.decorations=this.getDeco(e.view))}getDeco(e){let t=e.state.facet(Qot),{state:n}=e,r=n.selection;if(r.ranges.length>1)return En.none;let s=r.main,a,o=null;if(s.empty){if(!t.highlightWordAroundCursor)return En.none;let c=n.wordAt(s.head);if(!c)return En.none;o=n.charCategorizer(s.head),a=n.sliceDoc(c.from,c.to)}else{let c=s.to-s.from;if(c<t.minSelectionLength||c>200)return En.none;if(t.wholeWords){if(a=n.sliceDoc(s.from,s.to),o=n.charCategorizer(s.head),!(dee(o,n,s.from,s.to)&&Xot(o,n,s.from,s.to)))return En.none}else if(a=n.sliceDoc(s.from,s.to),!a)return En.none}let l=[];for(let c of e.visibleRanges){let u=new Yv(n.doc,a,c.from,c.to);for(;!u.next().done;){let{from:d,to:h}=u.value;if((!o||dee(o,n,d,h))&&(s.empty&&d<=s.from&&h>=s.to?l.push(Zot.range(d,h)):(d>=s.to||h<=s.from)&&l.push(Jot.range(d,h)),l.length>t.maxMatches))return En.none}}return En.set(l)}},{decorations:e=>e.decorations}),tlt=Yt.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}}),nlt=({state:e,dispatch:t})=>{let{selection:n}=e,r=xt.create(n.ranges.map(s=>e.wordAt(s.head)||xt.cursor(s.head)),n.mainIndex);return r.eq(n)?!1:(t(e.update({selection:r})),!0)};function rlt(e,t){let{main:n,ranges:r}=e.selection,s=e.wordAt(n.head),a=s&&s.from==n.from&&s.to==n.to;for(let o=!1,l=new Yv(e.doc,t,r[r.length-1].to);;)if(l.next(),l.done){if(o)return null;l=new Yv(e.doc,t,0,Math.max(0,r[r.length-1].from-1)),o=!0}else{if(o&&r.some(c=>c.from==l.value.from))continue;if(a){let c=e.wordAt(l.value.from);if(!c||c.from!=l.value.from||c.to!=l.value.to)continue}return l.value}}const slt=({state:e,dispatch:t})=>{let{ranges:n}=e.selection;if(n.some(a=>a.from===a.to))return nlt({state:e,dispatch:t});let r=e.sliceDoc(n[0].from,n[0].to);if(e.selection.ranges.some(a=>e.sliceDoc(a.from,a.to)!=r))return!1;let s=rlt(e,r);return s?(t(e.update({selection:e.selection.addRange(xt.range(s.from,s.to),!1),effects:Yt.scrollIntoView(s.to)})),!0):!1},H1=Zt.define({combine(e){return Pf(e,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:t=>new blt(t),scrollToMatch:t=>Yt.scrollIntoView(t)})}});class ove{constructor(t){this.search=t.search,this.caseSensitive=!!t.caseSensitive,this.literal=!!t.literal,this.regexp=!!t.regexp,this.replace=t.replace||"",this.valid=!!this.search&&(!this.regexp||Kot(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!t.wholeWord,this.test=t.test}unquote(t){return this.literal?t:t.replace(/\\([nrt\\])/g,(n,r)=>r=="n"?`
1282
+ `);r>-1&&(n=n.slice(0,r))}return t+n.length<=this.to?n:n.slice(0,this.to-t)}nextLine(){let t=this.parsedPos,n=this.lineAfter(t),r=t+n.length;for(let s=this.rangeIndex;;){let a=this.ranges[s].to;if(a>=r||(n=n.slice(0,a-(r-n.length)),s++,s==this.ranges.length))break;let o=this.ranges[s].from,l=this.lineAfter(o);n+=l,r=o+l.length}return{line:n,end:r}}skipGapsTo(t,n,r){for(;;){let s=this.ranges[this.rangeIndex].to,a=t+n;if(r>0?s>a:s>=a)break;let o=this.ranges[++this.rangeIndex].from;n+=o-s}return n}moveRangeIndex(){for(;this.ranges[this.rangeIndex].to<this.parsedPos;)this.rangeIndex++}emitToken(t,n,r,s){let a=4;if(this.ranges.length>1){s=this.skipGapsTo(n,s,1),n+=s;let l=this.chunk.length;s=this.skipGapsTo(r,s,-1),r+=s,a+=this.chunk.length-l}let o=this.chunk.length-4;return this.lang.streamParser.mergeTokens&&a==4&&o>=0&&this.chunk[o]==t&&this.chunk[o+2]==n?this.chunk[o+2]=r:this.chunk.push(t,n,r,a),s}parseLine(t){let{line:n,end:r}=this.nextLine(),s=0,{streamParser:a}=this.lang,o=new c0e(n,t?t.state.tabSize:4,t?Wb(t.state):2);if(o.eol())a.blankLine(this.state,o.indentUnit);else for(;!o.eol();){let l=d0e(a.token,o,this.state);if(l&&(s=this.emitToken(this.lang.tokenTable.resolve(l),this.parsedPos+o.start,this.parsedPos+o.pos,s)),o.start>1e4)break}this.parsedPos=r,this.moveRangeIndex(),this.parsedPos<this.to&&this.parsedPos++}finishChunk(){let t=zs.build({buffer:this.chunk,start:this.chunkStart,length:this.parsedPos-this.chunkStart,nodeSet:Nit,topID:0,maxBufferLength:512,reused:this.chunkReused});t=new zs(t.type,t.children,t.positions,t.length,[[this.lang.stateAfter,this.lang.streamParser.copyState(this.state)]]),this.chunks.push(t),this.chunkPos.push(this.chunkStart-this.ranges[0].from),this.chunk=[],this.chunkReused=void 0,this.chunkStart=this.parsedPos}finish(){return new zs(this.lang.topNode,this.chunks,this.chunkPos,this.parsedPos-this.ranges[0].from).balance()}}function d0e(e,t,n){t.start=t.pos;for(let r=0;r<10;r++){let s=e(t,n);if(t.pos>t.start)return s}throw new Error("Stream parser failed to advance stream.")}const YB=Object.create(null),ON=[jl.none],Nit=new UB(ON),$X=[],FX=Object.create(null),f0e=Object.create(null);for(let[e,t]of[["variable","variableName"],["variable-2","variableName.special"],["string-2","string.special"],["def","variableName.definition"],["tag","tagName"],["attribute","attributeName"],["type","typeName"],["builtin","variableName.standard"],["qualifier","modifier"],["error","invalid"],["header","heading"],["property","propertyName"]])f0e[e]=m0e(YB,t);class h0e{constructor(t){this.extra=t,this.table=Object.assign(Object.create(null),f0e)}resolve(t){return t?this.table[t]||(this.table[t]=m0e(this.extra,t)):0}}const Cit=new h0e(YB);function mD(e,t){$X.indexOf(e)>-1||($X.push(e),console.warn(t))}function m0e(e,t){let n=[];for(let l of t.split(" ")){let c=[];for(let u of l.split(".")){let d=e[u]||ct[u];d?typeof d=="function"?c.length?c=c.map(d):mD(u,`Modifier ${u} used at start of tag`):c.length?mD(u,`Tag ${u} used as modifier`):c=Array.isArray(d)?d:[d]:mD(u,`Unknown highlighting tag ${u}`)}for(let u of c)n.push(u)}if(!n.length)return 0;let r=t.replace(/ /g,"_"),s=r+" "+n.map(l=>l.id),a=FX[s];if(a)return a.id;let o=FX[s]=jl.define({id:ON.length,name:r,props:[Ast({[r]:n})]});return ON.push(o),o.id}function Sit(e,t){let n=jl.define({id:ON.length,name:"Document",props:[$x.add(()=>e),Gye.add(()=>r=>t.getIndent(r))],top:!0});return ON.push(n),n}Fs.RTL,Fs.LTR;class p0e{constructor(t,n,r,s){this.state=t,this.pos=n,this.explicit=r,this.view=s,this.abortListeners=[],this.abortOnDocChange=!1}tokenBefore(t){let n=wo(this.state).resolveInner(this.pos,-1);for(;n&&t.indexOf(n.name)<0;)n=n.parent;return n?{from:n.from,to:this.pos,text:this.state.sliceDoc(n.from,this.pos),type:n.type}:null}matchBefore(t){let n=this.state.doc.lineAt(this.pos),r=Math.max(n.from,this.pos-250),s=n.text.slice(r-n.from,this.pos-n.from),a=s.search(g0e(t,!1));return a<0?null:{from:r+a,to:this.pos,text:s.slice(a)}}get aborted(){return this.abortListeners==null}addEventListener(t,n,r){t=="abort"&&this.abortListeners&&(this.abortListeners.push(n),r&&r.onDocChange&&(this.abortOnDocChange=!0))}}function zX(e){let t=Object.keys(e).join(""),n=/\w/.test(t);return n&&(t=t.replace(/\w/g,"")),`[${n?"\\w":""}${t.replace(/[^\w\s]/g,"\\$&")}]`}function _it(e){let t=Object.create(null),n=Object.create(null);for(let{label:s}of e){t[s[0]]=!0;for(let a=1;a<s.length;a++)n[s[a]]=!0}let r=zX(t)+zX(n)+"*$";return[new RegExp("^"+r),new RegExp(r)]}function Ait(e){let t=e.map(s=>typeof s=="string"?{label:s}:s),[n,r]=t.every(s=>/^\w+$/.test(s.label))?[/\w*$/,/\w+$/]:_it(t);return s=>{let a=s.matchBefore(r);return a||s.explicit?{from:a?a.from:s.pos,options:t,validFor:n}:null}}function iEt(e,t){return n=>{for(let r=wo(n.state).resolveInner(n.pos,-1);r;r=r.parent){if(e.indexOf(r.name)>-1)return null;if(r.type.isTop)break}return t(n)}}class BX{constructor(t,n,r,s){this.completion=t,this.source=n,this.match=r,this.score=s}}function ob(e){return e.selection.main.from}function g0e(e,t){var n;let{source:r}=e,s=t&&r[0]!="^",a=r[r.length-1]!="$";return!s&&!a?e:new RegExp(`${s?"^":""}(?:${r})${a?"$":""}`,(n=e.flags)!==null&&n!==void 0?n:e.ignoreCase?"i":"")}const JB=gm.define();function Eit(e,t,n,r){let{main:s}=e.selection,a=n-s.from,o=r-s.from;return{...e.changeByRange(l=>{if(l!=s&&n!=r&&e.sliceDoc(l.from+a,l.from+o)!=e.sliceDoc(n,r))return{range:l};let c=e.toText(t);return{changes:{from:l.from+a,to:r==s.from?l.to:l.from+o,insert:c},range:xt.cursor(l.from+a+c.length)}}),scrollIntoView:!0,userEvent:"input.complete"}}const UX=new WeakMap;function Tit(e){if(!Array.isArray(e))return e;let t=UX.get(e);return t||UX.set(e,t=Ait(e)),t}const zE=Yn.define(),DN=Yn.define();class Iit{constructor(t){this.pattern=t,this.chars=[],this.folded=[],this.any=[],this.precise=[],this.byWord=[],this.score=0,this.matched=[];for(let n=0;n<t.length;){let r=Fl(t,n),s=ef(r);this.chars.push(r);let a=t.slice(n,n+s),o=a.toUpperCase();this.folded.push(Fl(o==a?a.toLowerCase():o,0)),n+=s}this.astral=t.length!=this.chars.length}ret(t,n){return this.score=t,this.matched=n,this}match(t){if(this.pattern.length==0)return this.ret(-100,[]);if(t.length<this.pattern.length)return null;let{chars:n,folded:r,any:s,precise:a,byWord:o}=this;if(n.length==1){let w=Fl(t,0),N=ef(w),S=N==t.length?0:-100;if(w!=n[0])if(w==r[0])S+=-200;else return null;return this.ret(S,[0,N])}let l=t.indexOf(this.pattern);if(l==0)return this.ret(t.length==this.pattern.length?0:-100,[0,this.pattern.length]);let c=n.length,u=0;if(l<0){for(let w=0,N=Math.min(t.length,200);w<N&&u<c;){let S=Fl(t,w);(S==n[u]||S==r[u])&&(s[u++]=w),w+=ef(S)}if(u<c)return null}let d=0,h=0,m=!1,g=0,b=-1,v=-1,j=/[a-z]/.test(t),k=!0;for(let w=0,N=Math.min(t.length,200),S=0;w<N&&h<c;){let A=Fl(t,w);l<0&&(d<c&&A==n[d]&&(a[d++]=w),g<c&&(A==n[g]||A==r[g]?(g==0&&(b=w),v=w+1,g++):g=0));let _,E=A<255?A>=48&&A<=57||A>=97&&A<=122?2:A>=65&&A<=90?1:0:(_=jB(A))!=_.toLowerCase()?1:_!=_.toUpperCase()?2:0;(!w||E==1&&j||S==0&&E!=0)&&(n[h]==A||r[h]==A&&(m=!0)?o[h++]=w:o.length&&(k=!1)),S=E,w+=ef(A)}return h==c&&o[0]==0&&k?this.result(-100+(m?-200:0),o,t):g==c&&b==0?this.ret(-200-t.length+(v==t.length?0:-100),[0,v]):l>-1?this.ret(-700-t.length,[l,l+this.pattern.length]):g==c?this.ret(-900-t.length,[b,v]):h==c?this.result(-100+(m?-200:0)+-700+(k?0:-1100),o,t):n.length==2?null:this.result((s[0]?-700:0)+-200+-1100,s,t)}result(t,n,r){let s=[],a=0;for(let o of n){let l=o+(this.astral?ef(Fl(r,o)):1);a&&s[a-1]==o?s[a-1]=l:(s[a++]=o,s[a++]=l)}return this.ret(t-r.length,s)}}class Rit{constructor(t){this.pattern=t,this.matched=[],this.score=0,this.folded=t.toLowerCase()}match(t){if(t.length<this.pattern.length)return null;let n=t.slice(0,this.pattern.length),r=n==this.pattern?0:n.toLowerCase()==this.folded?-200:null;return r==null?null:(this.matched=[0,n.length],this.score=r+(t.length==this.pattern.length?0:-100),this)}}const $a=Zt.define({combine(e){return Pf(e,{activateOnTyping:!0,activateOnCompletion:()=>!1,activateOnTypingDelay:100,selectOnOpen:!0,override:null,closeOnBlur:!0,maxRenderedOptions:100,defaultKeymap:!0,tooltipClass:()=>"",optionClass:()=>"",aboveCursor:!1,icons:!0,addToOptions:[],positionInfo:Mit,filterStrict:!1,compareCompletions:(t,n)=>(t.sortText||t.label).localeCompare(n.sortText||n.label),interactionDelay:75,updateSyncTime:100},{defaultKeymap:(t,n)=>t&&n,closeOnBlur:(t,n)=>t&&n,icons:(t,n)=>t&&n,tooltipClass:(t,n)=>r=>qX(t(r),n(r)),optionClass:(t,n)=>r=>qX(t(r),n(r)),addToOptions:(t,n)=>t.concat(n),filterStrict:(t,n)=>t||n})}});function qX(e,t){return e?t?e+" "+t:e:t}function Mit(e,t,n,r,s,a){let o=e.textDirection==Fs.RTL,l=o,c=!1,u="top",d,h,m=t.left-s.left,g=s.right-t.right,b=r.right-r.left,v=r.bottom-r.top;if(l&&m<Math.min(b,g)?l=!1:!l&&g<Math.min(b,m)&&(l=!0),b<=(l?m:g))d=Math.max(s.top,Math.min(n.top,s.bottom-v))-t.top,h=Math.min(400,l?m:g);else{c=!0,h=Math.min(400,(o?t.right:s.right-t.left)-30);let w=s.bottom-t.bottom;w>=v||w>t.top?d=n.bottom-t.top:(u="bottom",d=t.bottom-n.top)}let j=(t.bottom-t.top)/a.offsetHeight,k=(t.right-t.left)/a.offsetWidth;return{style:`${u}: ${d/j}px; max-width: ${h/k}px`,class:"cm-completionInfo-"+(c?o?"left-narrow":"right-narrow":l?"left":"right")}}const ZB=Yn.define();function Oit(e){let t=e.addToOptions.slice();return e.icons&&t.push({render(n){let r=document.createElement("div");return r.classList.add("cm-completionIcon"),n.type&&r.classList.add(...n.type.split(/\s+/g).map(s=>"cm-completionIcon-"+s)),r.setAttribute("aria-hidden","true"),r},position:20}),t.push({render(n,r,s,a){let o=document.createElement("span");o.className="cm-completionLabel";let l=n.displayLabel||n.label,c=0;for(let u=0;u<a.length;){let d=a[u++],h=a[u++];d>c&&o.appendChild(document.createTextNode(l.slice(c,d)));let m=o.appendChild(document.createElement("span"));m.appendChild(document.createTextNode(l.slice(d,h))),m.className="cm-completionMatchedText",c=h}return c<l.length&&o.appendChild(document.createTextNode(l.slice(c))),o},position:50},{render(n){if(!n.detail)return null;let r=document.createElement("span");return r.className="cm-completionDetail",r.textContent=n.detail,r},position:80}),t.sort((n,r)=>n.position-r.position).map(n=>n.render)}function pD(e,t,n){if(e<=n)return{from:0,to:e};if(t<0&&(t=0),t<=e>>1){let s=Math.floor(t/n);return{from:s*n,to:(s+1)*n}}let r=Math.floor((e-t)/n);return{from:e-(r+1)*n,to:e-r*n}}class Dit{constructor(t,n,r){this.view=t,this.stateField=n,this.applyCompletion=r,this.info=null,this.infoDestroy=null,this.placeInfoReq={read:()=>this.measureInfo(),write:c=>this.placeInfo(c),key:this},this.space=null,this.currentClass="";let s=t.state.field(n),{options:a,selected:o}=s.open,l=t.state.facet($a);this.optionContent=Oit(l),this.optionClass=l.optionClass,this.tooltipClass=l.tooltipClass,this.range=pD(a.length,o,l.maxRenderedOptions),this.dom=document.createElement("div"),this.dom.className="cm-tooltip-autocomplete",this.updateTooltipClass(t.state),this.dom.addEventListener("mousedown",c=>{let{options:u}=t.state.field(n).open;for(let d=c.target,h;d&&d!=this.dom;d=d.parentNode)if(d.nodeName=="LI"&&(h=/-(\d+)$/.exec(d.id))&&+h[1]<u.length){this.applyCompletion(t,u[+h[1]]),c.preventDefault();return}if(c.target==this.list){let d=this.list.classList.contains("cm-completionListIncompleteTop")&&c.clientY<this.list.firstChild.getBoundingClientRect().top?this.range.from-1:this.list.classList.contains("cm-completionListIncompleteBottom")&&c.clientY>this.list.lastChild.getBoundingClientRect().bottom?this.range.to:null;d!=null&&(t.dispatch({effects:ZB.of(d)}),c.preventDefault())}}),this.dom.addEventListener("focusout",c=>{let u=t.state.field(this.stateField,!1);u&&u.tooltip&&t.state.facet($a).closeOnBlur&&c.relatedTarget!=t.contentDOM&&t.dispatch({effects:DN.of(null)})}),this.showOptions(a,s.id)}mount(){this.updateSel()}showOptions(t,n){this.list&&this.list.remove(),this.list=this.dom.appendChild(this.createListBox(t,n,this.range)),this.list.addEventListener("scroll",()=>{this.info&&this.view.requestMeasure(this.placeInfoReq)})}update(t){var n;let r=t.state.field(this.stateField),s=t.startState.field(this.stateField);if(this.updateTooltipClass(t.state),r!=s){let{options:a,selected:o,disabled:l}=r.open;(!s.open||s.open.options!=a)&&(this.range=pD(a.length,o,t.state.facet($a).maxRenderedOptions),this.showOptions(a,r.id)),this.updateSel(),l!=((n=s.open)===null||n===void 0?void 0:n.disabled)&&this.dom.classList.toggle("cm-tooltip-autocomplete-disabled",!!l)}}updateTooltipClass(t){let n=this.tooltipClass(t);if(n!=this.currentClass){for(let r of this.currentClass.split(" "))r&&this.dom.classList.remove(r);for(let r of n.split(" "))r&&this.dom.classList.add(r);this.currentClass=n}}positioned(t){this.space=t,this.info&&this.view.requestMeasure(this.placeInfoReq)}updateSel(){let t=this.view.state.field(this.stateField),n=t.open;(n.selected>-1&&n.selected<this.range.from||n.selected>=this.range.to)&&(this.range=pD(n.options.length,n.selected,this.view.state.facet($a).maxRenderedOptions),this.showOptions(n.options,t.id));let r=this.updateSelectedOption(n.selected);if(r){this.destroyInfo();let{completion:s}=n.options[n.selected],{info:a}=s;if(!a)return;let o=typeof a=="string"?document.createTextNode(a):a(s);if(!o)return;"then"in o?o.then(l=>{l&&this.view.state.field(this.stateField,!1)==t&&this.addInfoPane(l,s)}).catch(l=>Ul(this.view.state,l,"completion info")):(this.addInfoPane(o,s),r.setAttribute("aria-describedby",this.info.id))}}addInfoPane(t,n){this.destroyInfo();let r=this.info=document.createElement("div");if(r.className="cm-tooltip cm-completionInfo",r.id="cm-completionInfo-"+Math.floor(Math.random()*65535).toString(16),t.nodeType!=null)r.appendChild(t),this.infoDestroy=null;else{let{dom:s,destroy:a}=t;r.appendChild(s),this.infoDestroy=a||null}this.dom.appendChild(r),this.view.requestMeasure(this.placeInfoReq)}updateSelectedOption(t){let n=null;for(let r=this.list.firstChild,s=this.range.from;r;r=r.nextSibling,s++)r.nodeName!="LI"||!r.id?s--:s==t?r.hasAttribute("aria-selected")||(r.setAttribute("aria-selected","true"),n=r):r.hasAttribute("aria-selected")&&(r.removeAttribute("aria-selected"),r.removeAttribute("aria-describedby"));return n&&Lit(this.list,n),n}measureInfo(){let t=this.dom.querySelector("[aria-selected]");if(!t||!this.info)return null;let n=this.dom.getBoundingClientRect(),r=this.info.getBoundingClientRect(),s=t.getBoundingClientRect(),a=this.space;if(!a){let o=this.dom.ownerDocument.documentElement;a={left:0,top:0,right:o.clientWidth,bottom:o.clientHeight}}return s.top>Math.min(a.bottom,n.bottom)-10||s.bottom<Math.max(a.top,n.top)+10?null:this.view.state.facet($a).positionInfo(this.view,n,s,r,a,this.dom)}placeInfo(t){this.info&&(t?(t.style&&(this.info.style.cssText=t.style),this.info.className="cm-tooltip cm-completionInfo "+(t.class||"")):this.info.style.cssText="top: -1e6px")}createListBox(t,n,r){const s=document.createElement("ul");s.id=n,s.setAttribute("role","listbox"),s.setAttribute("aria-expanded","true"),s.setAttribute("aria-label",this.view.state.phrase("Completions")),s.addEventListener("mousedown",o=>{o.target==s&&o.preventDefault()});let a=null;for(let o=r.from;o<r.to;o++){let{completion:l,match:c}=t[o],{section:u}=l;if(u){let m=typeof u=="string"?u:u.name;if(m!=a&&(o>r.from||r.from==0))if(a=m,typeof u!="string"&&u.header)s.appendChild(u.header(u));else{let g=s.appendChild(document.createElement("completion-section"));g.textContent=m}}const d=s.appendChild(document.createElement("li"));d.id=n+"-"+o,d.setAttribute("role","option");let h=this.optionClass(l);h&&(d.className=h);for(let m of this.optionContent){let g=m(l,this.view.state,this.view,c);g&&d.appendChild(g)}}return r.from&&s.classList.add("cm-completionListIncompleteTop"),r.to<t.length&&s.classList.add("cm-completionListIncompleteBottom"),s}destroyInfo(){this.info&&(this.infoDestroy&&this.infoDestroy(),this.info.remove(),this.info=null)}destroy(){this.destroyInfo()}}function Pit(e,t){return n=>new Dit(n,e,t)}function Lit(e,t){let n=e.getBoundingClientRect(),r=t.getBoundingClientRect(),s=n.height/e.offsetHeight;r.top<n.top?e.scrollTop-=(n.top-r.top)/s:r.bottom>n.bottom&&(e.scrollTop+=(r.bottom-n.bottom)/s)}function VX(e){return(e.boost||0)*100+(e.apply?10:0)+(e.info?5:0)+(e.type?1:0)}function $it(e,t){let n=[],r=null,s=null,a=d=>{n.push(d);let{section:h}=d.completion;if(h){r||(r=[]);let m=typeof h=="string"?h:h.name;r.some(g=>g.name==m)||r.push(typeof h=="string"?{name:m}:h)}},o=t.facet($a);for(let d of e)if(d.hasResult()){let h=d.result.getMatch;if(d.result.filter===!1)for(let m of d.result.options)a(new BX(m,d.source,h?h(m):[],1e9-n.length));else{let m=t.sliceDoc(d.from,d.to),g,b=o.filterStrict?new Rit(m):new Iit(m);for(let v of d.result.options)if(g=b.match(v.label)){let j=v.displayLabel?h?h(v,g.matched):[]:g.matched,k=g.score+(v.boost||0);if(a(new BX(v,d.source,j,k)),typeof v.section=="object"&&v.section.rank==="dynamic"){let{name:w}=v.section;s||(s=Object.create(null)),s[w]=Math.max(k,s[w]||-1e9)}}}}if(r){let d=Object.create(null),h=0,m=(g,b)=>(g.rank==="dynamic"&&b.rank==="dynamic"?s[b.name]-s[g.name]:0)||(typeof g.rank=="number"?g.rank:1e9)-(typeof b.rank=="number"?b.rank:1e9)||(g.name<b.name?-1:1);for(let g of r.sort(m))h-=1e5,d[g.name]=h;for(let g of n){let{section:b}=g.completion;b&&(g.score+=d[typeof b=="string"?b:b.name])}}let l=[],c=null,u=o.compareCompletions;for(let d of n.sort((h,m)=>m.score-h.score||u(h.completion,m.completion))){let h=d.completion;!c||c.label!=h.label||c.detail!=h.detail||c.type!=null&&h.type!=null&&c.type!=h.type||c.apply!=h.apply||c.boost!=h.boost?l.push(d):VX(d.completion)>VX(c)&&(l[l.length-1]=d),c=d.completion}return l}class O0{constructor(t,n,r,s,a,o){this.options=t,this.attrs=n,this.tooltip=r,this.timestamp=s,this.selected=a,this.disabled=o}setSelected(t,n){return t==this.selected||t>=this.options.length?this:new O0(this.options,HX(n,t),this.tooltip,this.timestamp,t,this.disabled)}static build(t,n,r,s,a,o){if(s&&!o&&t.some(u=>u.isPending))return s.setDisabled();let l=$it(t,n);if(!l.length)return s&&t.some(u=>u.isPending)?s.setDisabled():null;let c=n.facet($a).selectOnOpen?0:-1;if(s&&s.selected!=c&&s.selected!=-1){let u=s.options[s.selected].completion;for(let d=0;d<l.length;d++)if(l[d].completion==u){c=d;break}}return new O0(l,HX(r,c),{pos:t.reduce((u,d)=>d.hasResult()?Math.min(u,d.from):u,1e8),create:Vit,above:a.aboveCursor},s?s.timestamp:Date.now(),c,!1)}map(t){return new O0(this.options,this.attrs,{...this.tooltip,pos:t.mapPos(this.tooltip.pos)},this.timestamp,this.selected,this.disabled)}setDisabled(){return new O0(this.options,this.attrs,this.tooltip,this.timestamp,this.selected,!0)}}class BE{constructor(t,n,r){this.active=t,this.id=n,this.open=r}static start(){return new BE(Uit,"cm-ac-"+Math.floor(Math.random()*2e6).toString(36),null)}update(t){let{state:n}=t,r=n.facet($a),a=(r.override||n.languageDataAt("autocomplete",ob(n)).map(Tit)).map(c=>(this.active.find(d=>d.source==c)||new ru(c,this.active.some(d=>d.state!=0)?1:0)).update(t,r));a.length==this.active.length&&a.every((c,u)=>c==this.active[u])&&(a=this.active);let o=this.open,l=t.effects.some(c=>c.is(XB));o&&t.docChanged&&(o=o.map(t.changes)),t.selection||a.some(c=>c.hasResult()&&t.changes.touchesRange(c.from,c.to))||!Fit(a,this.active)||l?o=O0.build(a,n,this.id,o,r,l):o&&o.disabled&&!a.some(c=>c.isPending)&&(o=null),!o&&a.every(c=>!c.isPending)&&a.some(c=>c.hasResult())&&(a=a.map(c=>c.hasResult()?new ru(c.source,0):c));for(let c of t.effects)c.is(ZB)&&(o=o&&o.setSelected(c.value,this.id));return a==this.active&&o==this.open?this:new BE(a,this.id,o)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:this.active.length?zit:Bit}}function Fit(e,t){if(e==t)return!0;for(let n=0,r=0;;){for(;n<e.length&&!e[n].hasResult();)n++;for(;r<t.length&&!t[r].hasResult();)r++;let s=n==e.length,a=r==t.length;if(s||a)return s==a;if(e[n++].result!=t[r++].result)return!1}}const zit={"aria-autocomplete":"list"},Bit={};function HX(e,t){let n={"aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":e};return t>-1&&(n["aria-activedescendant"]=e+"-"+t),n}const Uit=[];function x0e(e,t){if(e.isUserEvent("input.complete")){let r=e.annotation(JB);if(r&&t.activateOnCompletion(r))return 12}let n=e.isUserEvent("input.type");return n&&t.activateOnTyping?5:n?1:e.isUserEvent("delete.backward")?2:e.selection?8:e.docChanged?16:0}class ru{constructor(t,n,r=!1){this.source=t,this.state=n,this.explicit=r}hasResult(){return!1}get isPending(){return this.state==1}update(t,n){let r=x0e(t,n),s=this;(r&8||r&16&&this.touches(t))&&(s=new ru(s.source,0)),r&4&&s.state==0&&(s=new ru(this.source,1)),s=s.updateFor(t,r);for(let a of t.effects)if(a.is(zE))s=new ru(s.source,1,a.value);else if(a.is(DN))s=new ru(s.source,0);else if(a.is(XB))for(let o of a.value)o.source==s.source&&(s=o);return s}updateFor(t,n){return this.map(t.changes)}map(t){return this}touches(t){return t.changes.touchesRange(ob(t.state))}}class Y0 extends ru{constructor(t,n,r,s,a,o){super(t,3,n),this.limit=r,this.result=s,this.from=a,this.to=o}hasResult(){return!0}updateFor(t,n){var r;if(!(n&3))return this.map(t.changes);let s=this.result;s.map&&!t.changes.empty&&(s=s.map(s,t.changes));let a=t.changes.mapPos(this.from),o=t.changes.mapPos(this.to,1),l=ob(t.state);if(l>o||!s||n&2&&(ob(t.startState)==this.from||l<this.limit))return new ru(this.source,n&4?1:0);let c=t.changes.mapPos(this.limit);return qit(s.validFor,t.state,a,o)?new Y0(this.source,this.explicit,c,s,a,o):s.update&&(s=s.update(s,a,o,new p0e(t.state,l,!1)))?new Y0(this.source,this.explicit,c,s,s.from,(r=s.to)!==null&&r!==void 0?r:ob(t.state)):new ru(this.source,1,this.explicit)}map(t){return t.empty?this:(this.result.map?this.result.map(this.result,t):this.result)?new Y0(this.source,this.explicit,t.mapPos(this.limit),this.result,t.mapPos(this.from),t.mapPos(this.to,1)):new ru(this.source,0)}touches(t){return t.changes.touchesRange(this.from,this.to)}}function qit(e,t,n,r){if(!e)return!1;let s=t.sliceDoc(n,r);return typeof e=="function"?e(s,n,r,t):g0e(e,!0).test(s)}const XB=Yn.define({map(e,t){return e.map(n=>n.map(t))}}),zl=ko.define({create(){return BE.start()},update(e,t){return e.update(t)},provide:e=>[zB.from(e,t=>t.tooltip),Yt.contentAttributes.from(e,t=>t.attrs)]});function eU(e,t){const n=t.completion.apply||t.completion.label;let r=e.state.field(zl).active.find(s=>s.source==t.source);return r instanceof Y0?(typeof n=="string"?e.dispatch({...Eit(e.state,n,r.from,r.to),annotations:JB.of(t.completion)}):n(e,t.completion,r.from,r.to),!0):!1}const Vit=Pit(zl,eU);function E_(e,t="option"){return n=>{let r=n.state.field(zl,!1);if(!r||!r.open||r.open.disabled||Date.now()-r.open.timestamp<n.state.facet($a).interactionDelay)return!1;let s=1,a;t=="page"&&(a=Mye(n,r.open.tooltip))&&(s=Math.max(2,Math.floor(a.dom.offsetHeight/a.dom.querySelector("li").offsetHeight)-1));let{length:o}=r.open.options,l=r.open.selected>-1?r.open.selected+s*(e?1:-1):e?0:o-1;return l<0?l=t=="page"?0:o-1:l>=o&&(l=t=="page"?o-1:0),n.dispatch({effects:ZB.of(l)}),!0}}const Hit=e=>{let t=e.state.field(zl,!1);return e.state.readOnly||!t||!t.open||t.open.selected<0||t.open.disabled||Date.now()-t.open.timestamp<e.state.facet($a).interactionDelay?!1:eU(e,t.open.options[t.open.selected])},gD=e=>e.state.field(zl,!1)?(e.dispatch({effects:zE.of(!0)}),!0):!1,Kit=e=>{let t=e.state.field(zl,!1);return!t||!t.active.some(n=>n.state!=0)?!1:(e.dispatch({effects:DN.of(null)}),!0)};class Wit{constructor(t,n){this.active=t,this.context=n,this.time=Date.now(),this.updates=[],this.done=void 0}}const Git=50,Qit=1e3,Yit=Vi.fromClass(class{constructor(e){this.view=e,this.debounceUpdate=-1,this.running=[],this.debounceAccept=-1,this.pendingStart=!1,this.composing=0;for(let t of e.state.field(zl).active)t.isPending&&this.startQuery(t)}update(e){let t=e.state.field(zl),n=e.state.facet($a);if(!e.selectionSet&&!e.docChanged&&e.startState.field(zl)==t)return;let r=e.transactions.some(a=>{let o=x0e(a,n);return o&8||(a.selection||a.docChanged)&&!(o&3)});for(let a=0;a<this.running.length;a++){let o=this.running[a];if(r||o.context.abortOnDocChange&&e.docChanged||o.updates.length+e.transactions.length>Git&&Date.now()-o.time>Qit){for(let l of o.context.abortListeners)try{l()}catch(c){Ul(this.view.state,c)}o.context.abortListeners=null,this.running.splice(a--,1)}else o.updates.push(...e.transactions)}this.debounceUpdate>-1&&clearTimeout(this.debounceUpdate),e.transactions.some(a=>a.effects.some(o=>o.is(zE)))&&(this.pendingStart=!0);let s=this.pendingStart?50:n.activateOnTypingDelay;if(this.debounceUpdate=t.active.some(a=>a.isPending&&!this.running.some(o=>o.active.source==a.source))?setTimeout(()=>this.startUpdate(),s):-1,this.composing!=0)for(let a of e.transactions)a.isUserEvent("input.type")?this.composing=2:this.composing==2&&a.selection&&(this.composing=3)}startUpdate(){this.debounceUpdate=-1,this.pendingStart=!1;let{state:e}=this.view,t=e.field(zl);for(let n of t.active)n.isPending&&!this.running.some(r=>r.active.source==n.source)&&this.startQuery(n);this.running.length&&t.open&&t.open.disabled&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet($a).updateSyncTime))}startQuery(e){let{state:t}=this.view,n=ob(t),r=new p0e(t,n,e.explicit,this.view),s=new Wit(e,r);this.running.push(s),Promise.resolve(e.source(r)).then(a=>{s.context.aborted||(s.done=a||null,this.scheduleAccept())},a=>{this.view.dispatch({effects:DN.of(null)}),Ul(this.view.state,a)})}scheduleAccept(){this.running.every(e=>e.done!==void 0)?this.accept():this.debounceAccept<0&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet($a).updateSyncTime))}accept(){var e;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let t=[],n=this.view.state.facet($a),r=this.view.state.field(zl);for(let s=0;s<this.running.length;s++){let a=this.running[s];if(a.done===void 0)continue;if(this.running.splice(s--,1),a.done){let l=ob(a.updates.length?a.updates[0].startState:this.view.state),c=Math.min(l,a.done.from+(a.active.explicit?0:1)),u=new Y0(a.active.source,a.active.explicit,c,a.done,a.done.from,(e=a.done.to)!==null&&e!==void 0?e:l);for(let d of a.updates)u=u.update(d,n);if(u.hasResult()){t.push(u);continue}}let o=r.active.find(l=>l.source==a.active.source);if(o&&o.isPending)if(a.done==null){let l=new ru(a.active.source,0);for(let c of a.updates)l=l.update(c,n);l.isPending||t.push(l)}else this.startQuery(o)}(t.length||r.open&&r.open.disabled)&&this.view.dispatch({effects:XB.of(t)})}},{eventHandlers:{blur(e){let t=this.view.state.field(zl,!1);if(t&&t.tooltip&&this.view.state.facet($a).closeOnBlur){let n=t.open&&Mye(this.view,t.open.tooltip);(!n||!n.dom.contains(e.relatedTarget))&&setTimeout(()=>this.view.dispatch({effects:DN.of(null)}),10)}},compositionstart(){this.composing=1},compositionend(){this.composing==3&&setTimeout(()=>this.view.dispatch({effects:zE.of(!1)}),20),this.composing=0}}}),Jit=typeof navigator=="object"&&/Win/.test(navigator.platform),Zit=Bg.highest(Yt.domEventHandlers({keydown(e,t){let n=t.state.field(zl,!1);if(!n||!n.open||n.open.disabled||n.open.selected<0||e.key.length>1||e.ctrlKey&&!(Jit&&e.altKey)||e.metaKey)return!1;let r=n.open.options[n.open.selected],s=n.active.find(o=>o.source==r.source),a=r.completion.commitCharacters||s.result.commitCharacters;return a&&a.indexOf(e.key)>-1&&eU(t,r),!1}})),b0e=Yt.baseTheme({".cm-tooltip.cm-tooltip-autocomplete":{"& > ul":{fontFamily:"monospace",whiteSpace:"nowrap",overflow:"hidden auto",maxWidth_fallback:"700px",maxWidth:"min(700px, 95vw)",minWidth:"250px",maxHeight:"10em",height:"100%",listStyle:"none",margin:0,padding:0,"& > li, & > completion-section":{padding:"1px 3px",lineHeight:1.2},"& > li":{overflowX:"hidden",textOverflow:"ellipsis",cursor:"pointer"},"& > completion-section":{display:"list-item",borderBottom:"1px solid silver",paddingLeft:"0.5em",opacity:.7}}},"&light .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#17c",color:"white"},"&light .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#777"},"&dark .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#347",color:"white"},"&dark .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#444"},".cm-completionListIncompleteTop:before, .cm-completionListIncompleteBottom:after":{content:'"···"',opacity:.5,display:"block",textAlign:"center"},".cm-tooltip.cm-completionInfo":{position:"absolute",padding:"3px 9px",width:"max-content",maxWidth:"400px",boxSizing:"border-box",whiteSpace:"pre-line"},".cm-completionInfo.cm-completionInfo-left":{right:"100%"},".cm-completionInfo.cm-completionInfo-right":{left:"100%"},".cm-completionInfo.cm-completionInfo-left-narrow":{right:"30px"},".cm-completionInfo.cm-completionInfo-right-narrow":{left:"30px"},"&light .cm-snippetField":{backgroundColor:"#00000022"},"&dark .cm-snippetField":{backgroundColor:"#ffffff22"},".cm-snippetFieldPosition":{verticalAlign:"text-top",width:0,height:"1.15em",display:"inline-block",margin:"0 -0.7px -.7em",borderLeft:"1.4px dotted #888"},".cm-completionMatchedText":{textDecoration:"underline"},".cm-completionDetail":{marginLeft:"0.5em",fontStyle:"italic"},".cm-completionIcon":{fontSize:"90%",width:".8em",display:"inline-block",textAlign:"center",paddingRight:".6em",opacity:"0.6",boxSizing:"content-box"},".cm-completionIcon-function, .cm-completionIcon-method":{"&:after":{content:"'ƒ'"}},".cm-completionIcon-class":{"&:after":{content:"'○'"}},".cm-completionIcon-interface":{"&:after":{content:"'◌'"}},".cm-completionIcon-variable":{"&:after":{content:"'𝑥'"}},".cm-completionIcon-constant":{"&:after":{content:"'𝐶'"}},".cm-completionIcon-type":{"&:after":{content:"'𝑡'"}},".cm-completionIcon-enum":{"&:after":{content:"'∪'"}},".cm-completionIcon-property":{"&:after":{content:"'□'"}},".cm-completionIcon-keyword":{"&:after":{content:"'🔑︎'"}},".cm-completionIcon-namespace":{"&:after":{content:"'▢'"}},".cm-completionIcon-text":{"&:after":{content:"'abc'",fontSize:"50%",verticalAlign:"middle"}}});class Xit{constructor(t,n,r,s){this.field=t,this.line=n,this.from=r,this.to=s}}class tU{constructor(t,n,r){this.field=t,this.from=n,this.to=r}map(t){let n=t.mapPos(this.from,-1,co.TrackDel),r=t.mapPos(this.to,1,co.TrackDel);return n==null||r==null?null:new tU(this.field,n,r)}}class nU{constructor(t,n){this.lines=t,this.fieldPositions=n}instantiate(t,n){let r=[],s=[n],a=t.doc.lineAt(n),o=/^\s*/.exec(a.text)[0];for(let c of this.lines){if(r.length){let u=o,d=/^\t*/.exec(c)[0].length;for(let h=0;h<d;h++)u+=t.facet(MI);s.push(n+u.length-d),c=u+c.slice(d)}r.push(c),n+=c.length+1}let l=this.fieldPositions.map(c=>new tU(c.field,s[c.line]+c.from,s[c.line]+c.to));return{text:r,ranges:l}}static parse(t){let n=[],r=[],s=[],a;for(let o of t.split(/\r\n?|\n/)){for(;a=/[#$]\{(?:(\d+)(?::([^{}]*))?|((?:\\[{}]|[^{}])*))\}/.exec(o);){let l=a[1]?+a[1]:null,c=a[2]||a[3]||"",u=-1,d=c.replace(/\\[{}]/g,h=>h[1]);for(let h=0;h<n.length;h++)(l!=null?n[h].seq==l:d&&n[h].name==d)&&(u=h);if(u<0){let h=0;for(;h<n.length&&(l==null||n[h].seq!=null&&n[h].seq<l);)h++;n.splice(h,0,{seq:l,name:d}),u=h;for(let m of s)m.field>=u&&m.field++}for(let h of s)if(h.line==r.length&&h.from>a.index){let m=a[2]?3+(a[1]||"").length:2;h.from-=m,h.to-=m}s.push(new Xit(u,r.length,a.index,a.index+d.length)),o=o.slice(0,a.index)+c+o.slice(a.index+a[0].length)}o=o.replace(/\\([{}])/g,(l,c,u)=>{for(let d of s)d.line==r.length&&d.from>u&&(d.from--,d.to--);return c}),r.push(o)}return new nU(r,s)}}let eat=En.widget({widget:new class extends Lf{toDOM(){let e=document.createElement("span");return e.className="cm-snippetFieldPosition",e}ignoreEvent(){return!1}}}),tat=En.mark({class:"cm-snippetField"});class q1{constructor(t,n){this.ranges=t,this.active=n,this.deco=En.set(t.map(r=>(r.from==r.to?eat:tat).range(r.from,r.to)),!0)}map(t){let n=[];for(let r of this.ranges){let s=r.map(t);if(!s)return null;n.push(s)}return new q1(n,this.active)}selectionInsideField(t){return t.ranges.every(n=>this.ranges.some(r=>r.field==this.active&&r.from<=n.from&&r.to>=n.to))}}const JC=Yn.define({map(e,t){return e&&e.map(t)}}),nat=Yn.define(),PN=ko.define({create(){return null},update(e,t){for(let n of t.effects){if(n.is(JC))return n.value;if(n.is(nat)&&e)return new q1(e.ranges,n.value)}return e&&t.docChanged&&(e=e.map(t.changes)),e&&t.selection&&!e.selectionInsideField(t.selection)&&(e=null),e},provide:e=>Yt.decorations.from(e,t=>t?t.deco:En.none)});function rU(e,t){return xt.create(e.filter(n=>n.field==t).map(n=>xt.range(n.from,n.to)))}function rat(e){let t=nU.parse(e);return(n,r,s,a)=>{let{text:o,ranges:l}=t.instantiate(n.state,s),{main:c}=n.state.selection,u={changes:{from:s,to:a==c.from?c.to:a,insert:ts.of(o)},scrollIntoView:!0,annotations:r?[JB.of(r),fa.userEvent.of("input.complete")]:void 0};if(l.length&&(u.selection=rU(l,0)),l.some(d=>d.field>0)){let d=new q1(l,0),h=u.effects=[JC.of(d)];n.state.field(PN,!1)===void 0&&h.push(Yn.appendConfig.of([PN,lat,cat,b0e]))}n.dispatch(n.state.update(u))}}function y0e(e){return({state:t,dispatch:n})=>{let r=t.field(PN,!1);if(!r||e<0&&r.active==0)return!1;let s=r.active+e,a=e>0&&!r.ranges.some(o=>o.field==s+e);return n(t.update({selection:rU(r.ranges,s),effects:JC.of(a?null:new q1(r.ranges,s)),scrollIntoView:!0})),!0}}const sat=({state:e,dispatch:t})=>e.field(PN,!1)?(t(e.update({effects:JC.of(null)})),!0):!1,iat=y0e(1),aat=y0e(-1),oat=[{key:"Tab",run:iat,shift:aat},{key:"Escape",run:sat}],KX=Zt.define({combine(e){return e.length?e[0]:oat}}),lat=Bg.highest(GC.compute([KX],e=>e.facet(KX)));function aEt(e,t){return{...t,apply:rat(e)}}const cat=Yt.domEventHandlers({mousedown(e,t){let n=t.state.field(PN,!1),r;if(!n||(r=t.posAtCoords({x:e.clientX,y:e.clientY}))==null)return!1;let s=n.ranges.find(a=>a.from<=r&&a.to>=r);return!s||s.field==n.active?!1:(t.dispatch({selection:rU(n.ranges,s.field),effects:JC.of(n.ranges.some(a=>a.field>s.field)?new q1(n.ranges,s.field):null),scrollIntoView:!0}),!0)}}),LN={brackets:["(","[","{","'",'"'],before:")]}:;>",stringPrefixes:[]},Fx=Yn.define({map(e,t){let n=t.mapPos(e,-1,co.TrackAfter);return n??void 0}}),sU=new class extends yg{};sU.startSide=1;sU.endSide=-1;const v0e=ko.define({create(){return _r.empty},update(e,t){if(e=e.map(t.changes),t.selection){let n=t.state.doc.lineAt(t.selection.main.head);e=e.update({filter:r=>r>=n.from&&r<=n.to})}for(let n of t.effects)n.is(Fx)&&(e=e.update({add:[sU.range(n.value,n.value+1)]}));return e}});function uat(){return[fat,v0e]}const xD="()[]{}<>«»»«[]{}";function w0e(e){for(let t=0;t<xD.length;t+=2)if(xD.charCodeAt(t)==e)return xD.charAt(t+1);return jB(e<128?e:e+1)}function k0e(e,t){return e.languageDataAt("closeBrackets",t)[0]||LN}const dat=typeof navigator=="object"&&/Android\b/.test(navigator.userAgent),fat=Yt.inputHandler.of((e,t,n,r)=>{if((dat?e.composing:e.compositionStarted)||e.state.readOnly)return!1;let s=e.state.selection.main;if(r.length>2||r.length==2&&ef(Fl(r,0))==1||t!=s.from||n!=s.to)return!1;let a=pat(e.state,r);return a?(e.dispatch(a),!0):!1}),hat=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let r=k0e(e,e.selection.main.head).brackets||LN.brackets,s=null,a=e.changeByRange(o=>{if(o.empty){let l=gat(e.doc,o.head);for(let c of r)if(c==l&&PI(e.doc,o.head)==w0e(Fl(c,0)))return{changes:{from:o.head-c.length,to:o.head+c.length},range:xt.cursor(o.head-c.length)}}return{range:s=o}});return s||t(e.update(a,{scrollIntoView:!0,userEvent:"delete.backward"})),!s},mat=[{key:"Backspace",run:hat}];function pat(e,t){let n=k0e(e,e.selection.main.head),r=n.brackets||LN.brackets;for(let s of r){let a=w0e(Fl(s,0));if(t==s)return a==s?yat(e,s,r.indexOf(s+s+s)>-1,n):xat(e,s,a,n.before||LN.before);if(t==a&&j0e(e,e.selection.main.from))return bat(e,s,a)}return null}function j0e(e,t){let n=!1;return e.field(v0e).between(0,e.doc.length,r=>{r==t&&(n=!0)}),n}function PI(e,t){let n=e.sliceString(t,t+2);return n.slice(0,ef(Fl(n,0)))}function gat(e,t){let n=e.sliceString(t-2,t);return ef(Fl(n,0))==n.length?n:n.slice(1)}function xat(e,t,n,r){let s=null,a=e.changeByRange(o=>{if(!o.empty)return{changes:[{insert:t,from:o.from},{insert:n,from:o.to}],effects:Fx.of(o.to+t.length),range:xt.range(o.anchor+t.length,o.head+t.length)};let l=PI(e.doc,o.head);return!l||/\s/.test(l)||r.indexOf(l)>-1?{changes:{insert:t+n,from:o.head},effects:Fx.of(o.head+t.length),range:xt.cursor(o.head+t.length)}:{range:s=o}});return s?null:e.update(a,{scrollIntoView:!0,userEvent:"input.type"})}function bat(e,t,n){let r=null,s=e.changeByRange(a=>a.empty&&PI(e.doc,a.head)==n?{changes:{from:a.head,to:a.head+n.length,insert:n},range:xt.cursor(a.head+n.length)}:r={range:a});return r?null:e.update(s,{scrollIntoView:!0,userEvent:"input.type"})}function yat(e,t,n,r){let s=r.stringPrefixes||LN.stringPrefixes,a=null,o=e.changeByRange(l=>{if(!l.empty)return{changes:[{insert:t,from:l.from},{insert:t,from:l.to}],effects:Fx.of(l.to+t.length),range:xt.range(l.anchor+t.length,l.head+t.length)};let c=l.head,u=PI(e.doc,c),d;if(u==t){if(WX(e,c))return{changes:{insert:t+t,from:c},effects:Fx.of(c+t.length),range:xt.cursor(c+t.length)};if(j0e(e,c)){let m=n&&e.sliceDoc(c,c+t.length*3)==t+t+t?t+t+t:t;return{changes:{from:c,to:c+m.length,insert:m},range:xt.cursor(c+m.length)}}}else{if(n&&e.sliceDoc(c-2*t.length,c)==t+t&&(d=GX(e,c-2*t.length,s))>-1&&WX(e,d))return{changes:{insert:t+t+t+t,from:c},effects:Fx.of(c+t.length),range:xt.cursor(c+t.length)};if(e.charCategorizer(c)(u)!=hi.Word&&GX(e,c,s)>-1&&!vat(e,c,t,s))return{changes:{insert:t+t,from:c},effects:Fx.of(c+t.length),range:xt.cursor(c+t.length)}}return{range:a=l}});return a?null:e.update(o,{scrollIntoView:!0,userEvent:"input.type"})}function WX(e,t){let n=wo(e).resolveInner(t+1);return n.parent&&n.from==t}function vat(e,t,n,r){let s=wo(e).resolveInner(t,-1),a=r.reduce((o,l)=>Math.max(o,l.length),0);for(let o=0;o<5;o++){let l=e.sliceDoc(s.from,Math.min(s.to,s.from+n.length+a)),c=l.indexOf(n);if(!c||c>-1&&r.indexOf(l.slice(0,c))>-1){let d=s.firstChild;for(;d&&d.from==s.from&&d.to-d.from>n.length+c;){if(e.sliceDoc(d.to-n.length,d.to)==n)return!1;d=d.firstChild}return!0}let u=s.to==t&&s.parent;if(!u)break;s=u}return!1}function GX(e,t,n){let r=e.charCategorizer(t);if(r(e.sliceDoc(t-1,t))!=hi.Word)return t;for(let s of n){let a=t-s.length;if(e.sliceDoc(a,t)==s&&r(e.sliceDoc(a-1,a))!=hi.Word)return a}return-1}function wat(e={}){return[Zit,zl,$a.of(e),Yit,kat,b0e]}const N0e=[{key:"Ctrl-Space",run:gD},{mac:"Alt-`",run:gD},{mac:"Alt-i",run:gD},{key:"Escape",run:Kit},{key:"ArrowDown",run:E_(!0)},{key:"ArrowUp",run:E_(!1)},{key:"PageDown",run:E_(!0,"page")},{key:"PageUp",run:E_(!1,"page")},{key:"Enter",run:Hit}],kat=Bg.highest(GC.computeN([$a],e=>e.facet($a).defaultKeymap?[N0e]:[])),jat=e=>{let{state:t}=e,n=t.doc.lineAt(t.selection.main.from),r=aU(e.state,n.from);return r.line?Nat(e):r.block?Sat(e):!1};function iU(e,t){return({state:n,dispatch:r})=>{if(n.readOnly)return!1;let s=e(t,n);return s?(r(n.update(s)),!0):!1}}const Nat=iU(Eat,0),Cat=iU(C0e,0),Sat=iU((e,t)=>C0e(e,t,Aat(t)),0);function aU(e,t){let n=e.languageDataAt("commentTokens",t,1);return n.length?n[0]:{}}const hk=50;function _at(e,{open:t,close:n},r,s){let a=e.sliceDoc(r-hk,r),o=e.sliceDoc(s,s+hk),l=/\s*$/.exec(a)[0].length,c=/^\s*/.exec(o)[0].length,u=a.length-l;if(a.slice(u-t.length,u)==t&&o.slice(c,c+n.length)==n)return{open:{pos:r-l,margin:l&&1},close:{pos:s+c,margin:c&&1}};let d,h;s-r<=2*hk?d=h=e.sliceDoc(r,s):(d=e.sliceDoc(r,r+hk),h=e.sliceDoc(s-hk,s));let m=/^\s*/.exec(d)[0].length,g=/\s*$/.exec(h)[0].length,b=h.length-g-n.length;return d.slice(m,m+t.length)==t&&h.slice(b,b+n.length)==n?{open:{pos:r+m+t.length,margin:/\s/.test(d.charAt(m+t.length))?1:0},close:{pos:s-g-n.length,margin:/\s/.test(h.charAt(b-1))?1:0}}:null}function Aat(e){let t=[];for(let n of e.selection.ranges){let r=e.doc.lineAt(n.from),s=n.to<=r.to?r:e.doc.lineAt(n.to);s.from>r.from&&s.from==n.to&&(s=n.to==r.to+1?r:e.doc.lineAt(n.to-1));let a=t.length-1;a>=0&&t[a].to>r.from?t[a].to=s.to:t.push({from:r.from+/^\s*/.exec(r.text)[0].length,to:s.to})}return t}function C0e(e,t,n=t.selection.ranges){let r=n.map(a=>aU(t,a.from).block);if(!r.every(a=>a))return null;let s=n.map((a,o)=>_at(t,r[o],a.from,a.to));if(e!=2&&!s.every(a=>a))return{changes:t.changes(n.map((a,o)=>s[o]?[]:[{from:a.from,insert:r[o].open+" "},{from:a.to,insert:" "+r[o].close}]))};if(e!=1&&s.some(a=>a)){let a=[];for(let o=0,l;o<s.length;o++)if(l=s[o]){let c=r[o],{open:u,close:d}=l;a.push({from:u.pos-c.open.length,to:u.pos+u.margin},{from:d.pos-d.margin,to:d.pos+c.close.length})}return{changes:a}}return null}function Eat(e,t,n=t.selection.ranges){let r=[],s=-1;e:for(let{from:a,to:o}of n){let l=r.length,c=1e9,u;for(let d=a;d<=o;){let h=t.doc.lineAt(d);if(u==null&&(u=aU(t,h.from).line,!u))continue e;if(h.from>s&&(a==o||o>h.from)){s=h.from;let m=/^\s*/.exec(h.text)[0].length,g=m==h.length,b=h.text.slice(m,m+u.length)==u?m:-1;m<h.text.length&&m<c&&(c=m),r.push({line:h,comment:b,token:u,indent:m,empty:g,single:!1})}d=h.to+1}if(c<1e9)for(let d=l;d<r.length;d++)r[d].indent<r[d].line.text.length&&(r[d].indent=c);r.length==l+1&&(r[l].single=!0)}if(e!=2&&r.some(a=>a.comment<0&&(!a.empty||a.single))){let a=[];for(let{line:l,token:c,indent:u,empty:d,single:h}of r)(h||!d)&&a.push({from:l.from+u,insert:c+" "});let o=t.changes(a);return{changes:o,selection:t.selection.map(o,1)}}else if(e!=1&&r.some(a=>a.comment>=0)){let a=[];for(let{line:o,comment:l,token:c}of r)if(l>=0){let u=o.from+l,d=u+c.length;o.text[d-o.from]==" "&&d++,a.push({from:u,to:d})}return{changes:a}}return null}const p$=gm.define(),Tat=gm.define(),Iat=Zt.define(),S0e=Zt.define({combine(e){return Pf(e,{minDepth:100,newGroupDelay:500,joinToEvent:(t,n)=>n},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(t,n)=>(r,s)=>t(r,s)||n(r,s)})}}),_0e=ko.define({create(){return df.empty},update(e,t){let n=t.state.facet(S0e),r=t.annotation(p$);if(r){let c=ql.fromTransaction(t,r.selection),u=r.side,d=u==0?e.undone:e.done;return c?d=UE(d,d.length,n.minDepth,c):d=T0e(d,t.startState.selection),new df(u==0?r.rest:d,u==0?d:r.rest)}let s=t.annotation(Tat);if((s=="full"||s=="before")&&(e=e.isolate()),t.annotation(fa.addToHistory)===!1)return t.changes.empty?e:e.addMapping(t.changes.desc);let a=ql.fromTransaction(t),o=t.annotation(fa.time),l=t.annotation(fa.userEvent);return a?e=e.addChanges(a,o,l,n,t):t.selection&&(e=e.addSelection(t.startState.selection,o,l,n.newGroupDelay)),(s=="full"||s=="after")&&(e=e.isolate()),e},toJSON(e){return{done:e.done.map(t=>t.toJSON()),undone:e.undone.map(t=>t.toJSON())}},fromJSON(e){return new df(e.done.map(ql.fromJSON),e.undone.map(ql.fromJSON))}});function Rat(e={}){return[_0e,S0e.of(e),Yt.domEventHandlers({beforeinput(t,n){let r=t.inputType=="historyUndo"?A0e:t.inputType=="historyRedo"?g$:null;return r?(t.preventDefault(),r(n)):!1}})]}function LI(e,t){return function({state:n,dispatch:r}){if(!t&&n.readOnly)return!1;let s=n.field(_0e,!1);if(!s)return!1;let a=s.pop(e,n,t);return a?(r(a),!0):!1}}const A0e=LI(0,!1),g$=LI(1,!1),Mat=LI(0,!0),Oat=LI(1,!0);class ql{constructor(t,n,r,s,a){this.changes=t,this.effects=n,this.mapped=r,this.startSelection=s,this.selectionsAfter=a}setSelAfter(t){return new ql(this.changes,this.effects,this.mapped,this.startSelection,t)}toJSON(){var t,n,r;return{changes:(t=this.changes)===null||t===void 0?void 0:t.toJSON(),mapped:(n=this.mapped)===null||n===void 0?void 0:n.toJSON(),startSelection:(r=this.startSelection)===null||r===void 0?void 0:r.toJSON(),selectionsAfter:this.selectionsAfter.map(s=>s.toJSON())}}static fromJSON(t){return new ql(t.changes&&va.fromJSON(t.changes),[],t.mapped&&gf.fromJSON(t.mapped),t.startSelection&&xt.fromJSON(t.startSelection),t.selectionsAfter.map(xt.fromJSON))}static fromTransaction(t,n){let r=su;for(let s of t.startState.facet(Iat)){let a=s(t);a.length&&(r=r.concat(a))}return!r.length&&t.changes.empty?null:new ql(t.changes.invert(t.startState.doc),r,void 0,n||t.startState.selection,su)}static selection(t){return new ql(void 0,su,void 0,void 0,t)}}function UE(e,t,n,r){let s=t+1>n+20?t-n-1:0,a=e.slice(s,t);return a.push(r),a}function Dat(e,t){let n=[],r=!1;return e.iterChangedRanges((s,a)=>n.push(s,a)),t.iterChangedRanges((s,a,o,l)=>{for(let c=0;c<n.length;){let u=n[c++],d=n[c++];l>=u&&o<=d&&(r=!0)}}),r}function Pat(e,t){return e.ranges.length==t.ranges.length&&e.ranges.filter((n,r)=>n.empty!=t.ranges[r].empty).length===0}function E0e(e,t){return e.length?t.length?e.concat(t):e:t}const su=[],Lat=200;function T0e(e,t){if(e.length){let n=e[e.length-1],r=n.selectionsAfter.slice(Math.max(0,n.selectionsAfter.length-Lat));return r.length&&r[r.length-1].eq(t)?e:(r.push(t),UE(e,e.length-1,1e9,n.setSelAfter(r)))}else return[ql.selection([t])]}function $at(e){let t=e[e.length-1],n=e.slice();return n[e.length-1]=t.setSelAfter(t.selectionsAfter.slice(0,t.selectionsAfter.length-1)),n}function bD(e,t){if(!e.length)return e;let n=e.length,r=su;for(;n;){let s=Fat(e[n-1],t,r);if(s.changes&&!s.changes.empty||s.effects.length){let a=e.slice(0,n);return a[n-1]=s,a}else t=s.mapped,n--,r=s.selectionsAfter}return r.length?[ql.selection(r)]:su}function Fat(e,t,n){let r=E0e(e.selectionsAfter.length?e.selectionsAfter.map(l=>l.map(t)):su,n);if(!e.changes)return ql.selection(r);let s=e.changes.map(t),a=t.mapDesc(e.changes,!0),o=e.mapped?e.mapped.composeDesc(a):a;return new ql(s,Yn.mapEffects(e.effects,t),o,e.startSelection.map(a),r)}const zat=/^(input\.type|delete)($|\.)/;class df{constructor(t,n,r=0,s=void 0){this.done=t,this.undone=n,this.prevTime=r,this.prevUserEvent=s}isolate(){return this.prevTime?new df(this.done,this.undone):this}addChanges(t,n,r,s,a){let o=this.done,l=o[o.length-1];return l&&l.changes&&!l.changes.empty&&t.changes&&(!r||zat.test(r))&&(!l.selectionsAfter.length&&n-this.prevTime<s.newGroupDelay&&s.joinToEvent(a,Dat(l.changes,t.changes))||r=="input.type.compose")?o=UE(o,o.length-1,s.minDepth,new ql(t.changes.compose(l.changes),E0e(Yn.mapEffects(t.effects,l.changes),l.effects),l.mapped,l.startSelection,su)):o=UE(o,o.length,s.minDepth,t),new df(o,su,n,r)}addSelection(t,n,r,s){let a=this.done.length?this.done[this.done.length-1].selectionsAfter:su;return a.length>0&&n-this.prevTime<s&&r==this.prevUserEvent&&r&&/^select($|\.)/.test(r)&&Pat(a[a.length-1],t)?this:new df(T0e(this.done,t),this.undone,n,r)}addMapping(t){return new df(bD(this.done,t),bD(this.undone,t),this.prevTime,this.prevUserEvent)}pop(t,n,r){let s=t==0?this.done:this.undone;if(s.length==0)return null;let a=s[s.length-1],o=a.selectionsAfter[0]||(a.startSelection?a.startSelection.map(a.changes.invertedDesc,1):n.selection);if(r&&a.selectionsAfter.length)return n.update({selection:a.selectionsAfter[a.selectionsAfter.length-1],annotations:p$.of({side:t,rest:$at(s),selection:o}),userEvent:t==0?"select.undo":"select.redo",scrollIntoView:!0});if(a.changes){let l=s.length==1?su:s.slice(0,s.length-1);return a.mapped&&(l=bD(l,a.mapped)),n.update({changes:a.changes,selection:a.startSelection,effects:a.effects,annotations:p$.of({side:t,rest:l,selection:o}),filter:!1,userEvent:t==0?"undo":"redo",scrollIntoView:!0})}else return null}}df.empty=new df(su,su);const Bat=[{key:"Mod-z",run:A0e,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:g$,preventDefault:!0},{linux:"Ctrl-Shift-z",run:g$,preventDefault:!0},{key:"Mod-u",run:Mat,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:Oat,preventDefault:!0}];function V1(e,t){return xt.create(e.ranges.map(t),e.mainIndex)}function wd(e,t){return e.update({selection:t,scrollIntoView:!0,userEvent:"select"})}function kd({state:e,dispatch:t},n){let r=V1(e.selection,n);return r.eq(e.selection,!0)?!1:(t(wd(e,r)),!0)}function $I(e,t){return xt.cursor(t?e.to:e.from)}function I0e(e,t){return kd(e,n=>n.empty?e.moveByChar(n,t):$I(n,t))}function Jo(e){return e.textDirectionAt(e.state.selection.main.head)==Fs.LTR}const R0e=e=>I0e(e,!Jo(e)),M0e=e=>I0e(e,Jo(e));function O0e(e,t){return kd(e,n=>n.empty?e.moveByGroup(n,t):$I(n,t))}const Uat=e=>O0e(e,!Jo(e)),qat=e=>O0e(e,Jo(e));function Vat(e,t,n){if(t.type.prop(n))return!0;let r=t.to-t.from;return r&&(r>2||/[^\s,.;:]/.test(e.sliceDoc(t.from,t.to)))||t.firstChild}function FI(e,t,n){let r=wo(e).resolveInner(t.head),s=n?jr.closedBy:jr.openedBy;for(let c=t.head;;){let u=n?r.childAfter(c):r.childBefore(c);if(!u)break;Vat(e,u,s)?r=u:c=n?u.to:u.from}let a=r.type.prop(s),o,l;return a&&(o=n?uf(e,r.from,1):uf(e,r.to,-1))&&o.matched?l=n?o.end.to:o.end.from:l=n?r.to:r.from,xt.cursor(l,n?-1:1)}const Hat=e=>kd(e,t=>FI(e.state,t,!Jo(e))),Kat=e=>kd(e,t=>FI(e.state,t,Jo(e)));function D0e(e,t){return kd(e,n=>{if(!n.empty)return $I(n,t);let r=e.moveVertically(n,t);return r.head!=n.head?r:e.moveToLineBoundary(n,t)})}const P0e=e=>D0e(e,!1),L0e=e=>D0e(e,!0);function $0e(e){let t=e.scrollDOM.clientHeight<e.scrollDOM.scrollHeight-2,n=0,r=0,s;if(t){for(let a of e.state.facet(Yt.scrollMargins)){let o=a(e);o!=null&&o.top&&(n=Math.max(o==null?void 0:o.top,n)),o!=null&&o.bottom&&(r=Math.max(o==null?void 0:o.bottom,r))}s=e.scrollDOM.clientHeight-n-r}else s=(e.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:n,marginBottom:r,selfScroll:t,height:Math.max(e.defaultLineHeight,s-5)}}function F0e(e,t){let n=$0e(e),{state:r}=e,s=V1(r.selection,o=>o.empty?e.moveVertically(o,t,n.height):$I(o,t));if(s.eq(r.selection))return!1;let a;if(n.selfScroll){let o=e.coordsAtPos(r.selection.main.head),l=e.scrollDOM.getBoundingClientRect(),c=l.top+n.marginTop,u=l.bottom-n.marginBottom;o&&o.top>c&&o.bottom<u&&(a=Yt.scrollIntoView(s.main.head,{y:"start",yMargin:o.top-c}))}return e.dispatch(wd(r,s),{effects:a}),!0}const QX=e=>F0e(e,!1),x$=e=>F0e(e,!0);function Ug(e,t,n){let r=e.lineBlockAt(t.head),s=e.moveToLineBoundary(t,n);if(s.head==t.head&&s.head!=(n?r.to:r.from)&&(s=e.moveToLineBoundary(t,n,!1)),!n&&s.head==r.from&&r.length){let a=/^\s*/.exec(e.state.sliceDoc(r.from,Math.min(r.from+100,r.to)))[0].length;a&&t.head!=r.from+a&&(s=xt.cursor(r.from+a))}return s}const Wat=e=>kd(e,t=>Ug(e,t,!0)),Gat=e=>kd(e,t=>Ug(e,t,!1)),Qat=e=>kd(e,t=>Ug(e,t,!Jo(e))),Yat=e=>kd(e,t=>Ug(e,t,Jo(e))),Jat=e=>kd(e,t=>xt.cursor(e.lineBlockAt(t.head).from,1)),Zat=e=>kd(e,t=>xt.cursor(e.lineBlockAt(t.head).to,-1));function Xat(e,t,n){let r=!1,s=V1(e.selection,a=>{let o=uf(e,a.head,-1)||uf(e,a.head,1)||a.head>0&&uf(e,a.head-1,1)||a.head<e.doc.length&&uf(e,a.head+1,-1);if(!o||!o.end)return a;r=!0;let l=o.start.from==a.head?o.end.to:o.end.from;return xt.cursor(l)});return r?(t(wd(e,s)),!0):!1}const eot=({state:e,dispatch:t})=>Xat(e,t);function ku(e,t){let n=V1(e.state.selection,r=>{let s=t(r);return xt.range(r.anchor,s.head,s.goalColumn,s.bidiLevel||void 0,s.assoc)});return n.eq(e.state.selection)?!1:(e.dispatch(wd(e.state,n)),!0)}function z0e(e,t){return ku(e,n=>e.moveByChar(n,t))}const B0e=e=>z0e(e,!Jo(e)),U0e=e=>z0e(e,Jo(e));function q0e(e,t){return ku(e,n=>e.moveByGroup(n,t))}const tot=e=>q0e(e,!Jo(e)),not=e=>q0e(e,Jo(e)),rot=e=>ku(e,t=>FI(e.state,t,!Jo(e))),sot=e=>ku(e,t=>FI(e.state,t,Jo(e)));function V0e(e,t){return ku(e,n=>e.moveVertically(n,t))}const H0e=e=>V0e(e,!1),K0e=e=>V0e(e,!0);function W0e(e,t){return ku(e,n=>e.moveVertically(n,t,$0e(e).height))}const YX=e=>W0e(e,!1),JX=e=>W0e(e,!0),iot=e=>ku(e,t=>Ug(e,t,!0)),aot=e=>ku(e,t=>Ug(e,t,!1)),oot=e=>ku(e,t=>Ug(e,t,!Jo(e))),lot=e=>ku(e,t=>Ug(e,t,Jo(e))),cot=e=>ku(e,t=>xt.cursor(e.lineBlockAt(t.head).from)),uot=e=>ku(e,t=>xt.cursor(e.lineBlockAt(t.head).to)),ZX=({state:e,dispatch:t})=>(t(wd(e,{anchor:0})),!0),XX=({state:e,dispatch:t})=>(t(wd(e,{anchor:e.doc.length})),!0),eee=({state:e,dispatch:t})=>(t(wd(e,{anchor:e.selection.main.anchor,head:0})),!0),tee=({state:e,dispatch:t})=>(t(wd(e,{anchor:e.selection.main.anchor,head:e.doc.length})),!0),dot=({state:e,dispatch:t})=>(t(e.update({selection:{anchor:0,head:e.doc.length},userEvent:"select"})),!0),fot=({state:e,dispatch:t})=>{let n=zI(e).map(({from:r,to:s})=>xt.range(r,Math.min(s+1,e.doc.length)));return t(e.update({selection:xt.create(n),userEvent:"select"})),!0},hot=({state:e,dispatch:t})=>{let n=V1(e.selection,r=>{let s=wo(e),a=s.resolveStack(r.from,1);if(r.empty){let o=s.resolveStack(r.from,-1);o.node.from>=a.node.from&&o.node.to<=a.node.to&&(a=o)}for(let o=a;o;o=o.next){let{node:l}=o;if((l.from<r.from&&l.to>=r.to||l.to>r.to&&l.from<=r.from)&&o.next)return xt.range(l.to,l.from)}return r});return n.eq(e.selection)?!1:(t(wd(e,n)),!0)};function G0e(e,t){let{state:n}=e,r=n.selection,s=n.selection.ranges.slice();for(let a of n.selection.ranges){let o=n.doc.lineAt(a.head);if(t?o.to<e.state.doc.length:o.from>0)for(let l=a;;){let c=e.moveVertically(l,t);if(c.head<o.from||c.head>o.to){s.some(u=>u.head==c.head)||s.push(c);break}else{if(c.head==l.head)break;l=c}}}return s.length==r.ranges.length?!1:(e.dispatch(wd(n,xt.create(s,s.length-1))),!0)}const mot=e=>G0e(e,!1),pot=e=>G0e(e,!0),got=({state:e,dispatch:t})=>{let n=e.selection,r=null;return n.ranges.length>1?r=xt.create([n.main]):n.main.empty||(r=xt.create([xt.cursor(n.main.head)])),r?(t(wd(e,r)),!0):!1};function ZC(e,t){if(e.state.readOnly)return!1;let n="delete.selection",{state:r}=e,s=r.changeByRange(a=>{let{from:o,to:l}=a;if(o==l){let c=t(a);c<o?(n="delete.backward",c=T_(e,c,!1)):c>o&&(n="delete.forward",c=T_(e,c,!0)),o=Math.min(o,c),l=Math.max(l,c)}else o=T_(e,o,!1),l=T_(e,l,!0);return o==l?{range:a}:{changes:{from:o,to:l},range:xt.cursor(o,o<a.head?-1:1)}});return s.changes.empty?!1:(e.dispatch(r.update(s,{scrollIntoView:!0,userEvent:n,effects:n=="delete.selection"?Yt.announce.of(r.phrase("Selection deleted")):void 0})),!0)}function T_(e,t,n){if(e instanceof Yt)for(let r of e.state.facet(Yt.atomicRanges).map(s=>s(e)))r.between(t,t,(s,a)=>{s<t&&a>t&&(t=n?a:s)});return t}const Q0e=(e,t,n)=>ZC(e,r=>{let s=r.from,{state:a}=e,o=a.doc.lineAt(s),l,c;if(n&&!t&&s>o.from&&s<o.from+200&&!/[^ \t]/.test(l=o.text.slice(0,s-o.from))){if(l[l.length-1]==" ")return s-1;let u=U1(l,a.tabSize),d=u%Wb(a)||Wb(a);for(let h=0;h<d&&l[l.length-1-h]==" ";h++)s--;c=s}else c=za(o.text,s-o.from,t,t)+o.from,c==s&&o.number!=(t?a.doc.lines:1)?c+=t?1:-1:!t&&/[\ufe00-\ufe0f]/.test(o.text.slice(c-o.from,s-o.from))&&(c=za(o.text,c-o.from,!1,!1)+o.from);return c}),b$=e=>Q0e(e,!1,!0),Y0e=e=>Q0e(e,!0,!1),J0e=(e,t)=>ZC(e,n=>{let r=n.head,{state:s}=e,a=s.doc.lineAt(r),o=s.charCategorizer(r);for(let l=null;;){if(r==(t?a.to:a.from)){r==n.head&&a.number!=(t?s.doc.lines:1)&&(r+=t?1:-1);break}let c=za(a.text,r-a.from,t)+a.from,u=a.text.slice(Math.min(r,c)-a.from,Math.max(r,c)-a.from),d=o(u);if(l!=null&&d!=l)break;(u!=" "||r!=n.head)&&(l=d),r=c}return r}),Z0e=e=>J0e(e,!1),xot=e=>J0e(e,!0),bot=e=>ZC(e,t=>{let n=e.lineBlockAt(t.head).to;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}),yot=e=>ZC(e,t=>{let n=e.moveToLineBoundary(t,!1).head;return t.head>n?n:Math.max(0,t.head-1)}),vot=e=>ZC(e,t=>{let n=e.moveToLineBoundary(t,!0).head;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}),wot=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(r=>({changes:{from:r.from,to:r.to,insert:ts.of(["",""])},range:xt.cursor(r.from)}));return t(e.update(n,{scrollIntoView:!0,userEvent:"input"})),!0},kot=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(r=>{if(!r.empty||r.from==0||r.from==e.doc.length)return{range:r};let s=r.from,a=e.doc.lineAt(s),o=s==a.from?s-1:za(a.text,s-a.from,!1)+a.from,l=s==a.to?s+1:za(a.text,s-a.from,!0)+a.from;return{changes:{from:o,to:l,insert:e.doc.slice(s,l).append(e.doc.slice(o,s))},range:xt.cursor(l)}});return n.changes.empty?!1:(t(e.update(n,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function zI(e){let t=[],n=-1;for(let r of e.selection.ranges){let s=e.doc.lineAt(r.from),a=e.doc.lineAt(r.to);if(!r.empty&&r.to==a.from&&(a=e.doc.lineAt(r.to-1)),n>=s.number){let o=t[t.length-1];o.to=a.to,o.ranges.push(r)}else t.push({from:s.from,to:a.to,ranges:[r]});n=a.number+1}return t}function X0e(e,t,n){if(e.readOnly)return!1;let r=[],s=[];for(let a of zI(e)){if(n?a.to==e.doc.length:a.from==0)continue;let o=e.doc.lineAt(n?a.to+1:a.from-1),l=o.length+1;if(n){r.push({from:a.to,to:o.to},{from:a.from,insert:o.text+e.lineBreak});for(let c of a.ranges)s.push(xt.range(Math.min(e.doc.length,c.anchor+l),Math.min(e.doc.length,c.head+l)))}else{r.push({from:o.from,to:a.from},{from:a.to,insert:e.lineBreak+o.text});for(let c of a.ranges)s.push(xt.range(c.anchor-l,c.head-l))}}return r.length?(t(e.update({changes:r,scrollIntoView:!0,selection:xt.create(s,e.selection.mainIndex),userEvent:"move.line"})),!0):!1}const jot=({state:e,dispatch:t})=>X0e(e,t,!1),Not=({state:e,dispatch:t})=>X0e(e,t,!0);function eve(e,t,n){if(e.readOnly)return!1;let r=[];for(let a of zI(e))n?r.push({from:a.from,insert:e.doc.slice(a.from,a.to)+e.lineBreak}):r.push({from:a.to,insert:e.lineBreak+e.doc.slice(a.from,a.to)});let s=e.changes(r);return t(e.update({changes:s,selection:e.selection.map(s,n?1:-1),scrollIntoView:!0,userEvent:"input.copyline"})),!0}const Cot=({state:e,dispatch:t})=>eve(e,t,!1),Sot=({state:e,dispatch:t})=>eve(e,t,!0),_ot=e=>{if(e.state.readOnly)return!1;let{state:t}=e,n=t.changes(zI(t).map(({from:s,to:a})=>(s>0?s--:a<t.doc.length&&a++,{from:s,to:a}))),r=V1(t.selection,s=>{let a;if(e.lineWrapping){let o=e.lineBlockAt(s.head),l=e.coordsAtPos(s.head,s.assoc||1);l&&(a=o.bottom+e.documentTop-l.bottom+e.defaultLineHeight/2)}return e.moveVertically(s,!0,a)}).map(n);return e.dispatch({changes:n,selection:r,scrollIntoView:!0,userEvent:"delete.line"}),!0};function Aot(e,t){if(/\(\)|\[\]|\{\}/.test(e.sliceDoc(t-1,t+1)))return{from:t,to:t};let n=wo(e).resolveInner(t),r=n.childBefore(t),s=n.childAfter(t),a;return r&&s&&r.to<=t&&s.from>=t&&(a=r.type.prop(jr.closedBy))&&a.indexOf(s.name)>-1&&e.doc.lineAt(r.to).from==e.doc.lineAt(s.from).from&&!/\S/.test(e.sliceDoc(r.to,s.from))?{from:r.to,to:s.from}:null}const nee=tve(!1),Eot=tve(!0);function tve(e){return({state:t,dispatch:n})=>{if(t.readOnly)return!1;let r=t.changeByRange(s=>{let{from:a,to:o}=s,l=t.doc.lineAt(a),c=!e&&a==o&&Aot(t,a);e&&(a=o=(o<=l.to?l:t.doc.lineAt(o)).to);let u=new OI(t,{simulateBreak:a,simulateDoubleBreak:!!c}),d=KB(u,a);for(d==null&&(d=U1(/^\s*/.exec(t.doc.lineAt(a).text)[0],t.tabSize));o<l.to&&/\s/.test(l.text[o-l.from]);)o++;c?{from:a,to:o}=c:a>l.from&&a<l.from+100&&!/\S/.test(l.text.slice(0,a))&&(a=l.from);let h=["",MN(t,d)];return c&&h.push(MN(t,u.lineIndent(l.from,-1))),{changes:{from:a,to:o,insert:ts.of(h)},range:xt.cursor(a+1+h[1].length)}});return n(t.update(r,{scrollIntoView:!0,userEvent:"input"})),!0}}function oU(e,t){let n=-1;return e.changeByRange(r=>{let s=[];for(let o=r.from;o<=r.to;){let l=e.doc.lineAt(o);l.number>n&&(r.empty||r.to>l.from)&&(t(l,s,r),n=l.number),o=l.to+1}let a=e.changes(s);return{changes:s,range:xt.range(a.mapPos(r.anchor,1),a.mapPos(r.head,1))}})}const Tot=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=Object.create(null),r=new OI(e,{overrideIndentation:a=>{let o=n[a];return o??-1}}),s=oU(e,(a,o,l)=>{let c=KB(r,a.from);if(c==null)return;/\S/.test(a.text)||(c=0);let u=/^\s*/.exec(a.text)[0],d=MN(e,c);(u!=d||l.from<a.from+u.length)&&(n[a.from]=c,o.push({from:a.from,to:a.from+u.length,insert:d}))});return s.changes.empty||t(e.update(s,{userEvent:"indent"})),!0},nve=({state:e,dispatch:t})=>e.readOnly?!1:(t(e.update(oU(e,(n,r)=>{r.push({from:n.from,insert:e.facet(MI)})}),{userEvent:"input.indent"})),!0),rve=({state:e,dispatch:t})=>e.readOnly?!1:(t(e.update(oU(e,(n,r)=>{let s=/^\s*/.exec(n.text)[0];if(!s)return;let a=U1(s,e.tabSize),o=0,l=MN(e,Math.max(0,a-Wb(e)));for(;o<s.length&&o<l.length&&s.charCodeAt(o)==l.charCodeAt(o);)o++;r.push({from:n.from+o,to:n.from+s.length,insert:l.slice(o)})}),{userEvent:"delete.dedent"})),!0),Iot=e=>(e.setTabFocusMode(),!0),Rot=[{key:"Ctrl-b",run:R0e,shift:B0e,preventDefault:!0},{key:"Ctrl-f",run:M0e,shift:U0e},{key:"Ctrl-p",run:P0e,shift:H0e},{key:"Ctrl-n",run:L0e,shift:K0e},{key:"Ctrl-a",run:Jat,shift:cot},{key:"Ctrl-e",run:Zat,shift:uot},{key:"Ctrl-d",run:Y0e},{key:"Ctrl-h",run:b$},{key:"Ctrl-k",run:bot},{key:"Ctrl-Alt-h",run:Z0e},{key:"Ctrl-o",run:wot},{key:"Ctrl-t",run:kot},{key:"Ctrl-v",run:x$}],Mot=[{key:"ArrowLeft",run:R0e,shift:B0e,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:Uat,shift:tot,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:Qat,shift:oot,preventDefault:!0},{key:"ArrowRight",run:M0e,shift:U0e,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:qat,shift:not,preventDefault:!0},{mac:"Cmd-ArrowRight",run:Yat,shift:lot,preventDefault:!0},{key:"ArrowUp",run:P0e,shift:H0e,preventDefault:!0},{mac:"Cmd-ArrowUp",run:ZX,shift:eee},{mac:"Ctrl-ArrowUp",run:QX,shift:YX},{key:"ArrowDown",run:L0e,shift:K0e,preventDefault:!0},{mac:"Cmd-ArrowDown",run:XX,shift:tee},{mac:"Ctrl-ArrowDown",run:x$,shift:JX},{key:"PageUp",run:QX,shift:YX},{key:"PageDown",run:x$,shift:JX},{key:"Home",run:Gat,shift:aot,preventDefault:!0},{key:"Mod-Home",run:ZX,shift:eee},{key:"End",run:Wat,shift:iot,preventDefault:!0},{key:"Mod-End",run:XX,shift:tee},{key:"Enter",run:nee,shift:nee},{key:"Mod-a",run:dot},{key:"Backspace",run:b$,shift:b$,preventDefault:!0},{key:"Delete",run:Y0e,preventDefault:!0},{key:"Mod-Backspace",mac:"Alt-Backspace",run:Z0e,preventDefault:!0},{key:"Mod-Delete",mac:"Alt-Delete",run:xot,preventDefault:!0},{mac:"Mod-Backspace",run:yot,preventDefault:!0},{mac:"Mod-Delete",run:vot,preventDefault:!0}].concat(Rot.map(e=>({mac:e.key,run:e.run,shift:e.shift}))),Oot=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:Hat,shift:rot},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:Kat,shift:sot},{key:"Alt-ArrowUp",run:jot},{key:"Shift-Alt-ArrowUp",run:Cot},{key:"Alt-ArrowDown",run:Not},{key:"Shift-Alt-ArrowDown",run:Sot},{key:"Mod-Alt-ArrowUp",run:mot},{key:"Mod-Alt-ArrowDown",run:pot},{key:"Escape",run:got},{key:"Mod-Enter",run:Eot},{key:"Alt-l",mac:"Ctrl-l",run:fot},{key:"Mod-i",run:hot,preventDefault:!0},{key:"Mod-[",run:rve},{key:"Mod-]",run:nve},{key:"Mod-Alt-\\",run:Tot},{key:"Shift-Mod-k",run:_ot},{key:"Shift-Mod-\\",run:eot},{key:"Mod-/",run:jat},{key:"Alt-A",run:Cat},{key:"Ctrl-m",mac:"Shift-Alt-m",run:Iot}].concat(Mot),Dot={key:"Tab",run:nve,shift:rve};function Pot(e,t,n,r){const s=Cf(fi),a=kc($ge),o=se.useRef(null),{lexicalNode:l}=S6(),c=se.useRef(!1),u=se.useRef(!1),d=se.useCallback(()=>{a({editorType:t,rootNode:l,editorRef:o.current})},[t,l,a]),h=se.useCallback(m=>{var g,b,v,j,k,w;if(m.key==="ArrowDown"){const N=(b=(g=o.current)==null?void 0:g.getCodemirror())==null?void 0:b.state;if(N){const S=N.doc.length,A=N.selection.ranges[0].to;S===A&&(c.current?(s==null||s.update(()=>{var _,E;const I=pf(e);I.getNextSibling()?((E=(_=o.current)==null?void 0:_.getCodemirror())==null||E.contentDOM.blur(),I.selectNext()):I.insertAfter(Js())}),c.current=!1):c.current=!0)}}else if(m.key==="ArrowUp"){const N=(j=(v=o.current)==null?void 0:v.getCodemirror())==null?void 0:j.state;N&&N.selection.ranges[0].from===0&&(u.current?(s==null||s.update(()=>{var A,_;const E=pf(e);E.getPreviousSibling()&&((_=(A=o.current)==null?void 0:A.getCodemirror())==null||_.contentDOM.blur(),E.selectPrevious())}),u.current=!1):u.current=!0)}else if(m.key==="Enter")m.stopPropagation();else if(m.key==="Backspace"||m.key==="Delete"){const N=(w=(k=o.current)==null?void 0:k.getCodemirror())==null?void 0:w.state;(N==null?void 0:N.doc.length)===0&&(s==null||s.update(()=>{pf(e).remove()}))}},[s,e]);return se.useEffect(()=>{const m=o.current;return setTimeout(()=>{var g,b;(g=m==null?void 0:m.getCodemirror())==null||g.contentDOM.addEventListener("focus",d),(b=m==null?void 0:m.getCodemirror())==null||b.contentDOM.addEventListener("keydown",h)},300),()=>{var g,b;(g=m==null?void 0:m.getCodemirror())==null||g.contentDOM.removeEventListener("focus",d),(b=m==null?void 0:m.getCodemirror())==null||b.contentDOM.removeEventListener("keydown",h)}},[o,d,h,n]),se.useEffect(()=>{r.subscribe(()=>{var m,g;(g=(m=o.current)==null?void 0:m.getCodemirror())==null||g.focus(),d()})},[r,o,e,d]),o}function St(e){return new Pst(GB.define(e))}function Ym(e){return ut(()=>import("./index-CGVwjOWT.js"),__vite__mapDeps([0,1])).then(t=>t.sql({dialect:t[e]}))}const Lot=[st.of({name:"C",extensions:["c","h","ino"],load(){return ut(()=>import("./index-oHpvPar-.js"),__vite__mapDeps([2,1])).then(e=>e.cpp())}}),st.of({name:"C++",alias:["cpp"],extensions:["cpp","c++","cc","cxx","hpp","h++","hh","hxx"],load(){return ut(()=>import("./index-oHpvPar-.js"),__vite__mapDeps([2,1])).then(e=>e.cpp())}}),st.of({name:"CQL",alias:["cassandra"],extensions:["cql"],load(){return Ym("Cassandra")}}),st.of({name:"CSS",extensions:["css"],load(){return ut(()=>import("./index-2fpQE_AC.js"),__vite__mapDeps([3,1])).then(e=>e.css())}}),st.of({name:"Go",extensions:["go"],load(){return ut(()=>import("./index-DO0UFbrH.js"),__vite__mapDeps([4,1])).then(e=>e.go())}}),st.of({name:"HTML",alias:["xhtml"],extensions:["html","htm","handlebars","hbs"],load(){return ut(()=>import("./index-DLTnS5K4.js"),__vite__mapDeps([5,1,3,6])).then(e=>e.html())}}),st.of({name:"Java",extensions:["java"],load(){return ut(()=>import("./index-CxdGyiXd.js"),__vite__mapDeps([7,1])).then(e=>e.java())}}),st.of({name:"JavaScript",alias:["ecmascript","js","node"],extensions:["js","mjs","cjs"],load(){return ut(()=>import("./index-2KxI7xgS.js"),__vite__mapDeps([6,1])).then(e=>e.javascript())}}),st.of({name:"Jinja",extensions:["j2","jinja","jinja2"],load(){return ut(()=>import("./index-C-Fleuj8.js"),__vite__mapDeps([8,5,1,3,6])).then(e=>e.jinja())}}),st.of({name:"JSON",alias:["json5"],extensions:["json","map"],load(){return ut(()=>import("./index-6CbWISCh.js"),__vite__mapDeps([9,1])).then(e=>e.json())}}),st.of({name:"JSX",extensions:["jsx"],load(){return ut(()=>import("./index-2KxI7xgS.js"),__vite__mapDeps([6,1])).then(e=>e.javascript({jsx:!0}))}}),st.of({name:"LESS",extensions:["less"],load(){return ut(()=>import("./index-DuBWRTfm.js"),__vite__mapDeps([10,3,1])).then(e=>e.less())}}),st.of({name:"Liquid",extensions:["liquid"],load(){return ut(()=>import("./index-DCMV2c1v.js"),__vite__mapDeps([11,5,1,3,6])).then(e=>e.liquid())}}),st.of({name:"MariaDB SQL",load(){return Ym("MariaSQL")}}),st.of({name:"Markdown",extensions:["md","markdown","mkd"],load(){return ut(()=>import("./index-P9kFtvbc.js"),__vite__mapDeps([12,5,1,3,6])).then(e=>e.markdown())}}),st.of({name:"MS SQL",load(){return Ym("MSSQL")}}),st.of({name:"MySQL",load(){return Ym("MySQL")}}),st.of({name:"PHP",extensions:["php","php3","php4","php5","php7","phtml"],load(){return ut(()=>import("./index-37v_vD1F.js"),__vite__mapDeps([13,1,5,3,6])).then(e=>e.php())}}),st.of({name:"PLSQL",extensions:["pls"],load(){return Ym("PLSQL")}}),st.of({name:"PostgreSQL",load(){return Ym("PostgreSQL")}}),st.of({name:"Python",extensions:["BUILD","bzl","py","pyw"],filename:/^(BUCK|BUILD)$/,load(){return ut(()=>import("./index-BUBHt44A.js"),__vite__mapDeps([14,1])).then(e=>e.python())}}),st.of({name:"Rust",extensions:["rs"],load(){return ut(()=>import("./index-DC4tbOtF.js"),__vite__mapDeps([15,1])).then(e=>e.rust())}}),st.of({name:"Sass",extensions:["sass"],load(){return ut(()=>import("./index-CShHgd9H.js"),__vite__mapDeps([16,1,3])).then(e=>e.sass({indented:!0}))}}),st.of({name:"SCSS",extensions:["scss"],load(){return ut(()=>import("./index-CShHgd9H.js"),__vite__mapDeps([16,1,3])).then(e=>e.sass())}}),st.of({name:"SQL",extensions:["sql"],load(){return Ym("StandardSQL")}}),st.of({name:"SQLite",load(){return Ym("SQLite")}}),st.of({name:"TSX",extensions:["tsx"],load(){return ut(()=>import("./index-2KxI7xgS.js"),__vite__mapDeps([6,1])).then(e=>e.javascript({jsx:!0,typescript:!0}))}}),st.of({name:"TypeScript",alias:["ts"],extensions:["ts","mts","cts"],load(){return ut(()=>import("./index-2KxI7xgS.js"),__vite__mapDeps([6,1])).then(e=>e.javascript({typescript:!0}))}}),st.of({name:"WebAssembly",extensions:["wat","wast"],load(){return ut(()=>import("./index-CB1hG4Kq.js"),__vite__mapDeps([17,1])).then(e=>e.wast())}}),st.of({name:"XML",alias:["rss","wsdl","xsd"],extensions:["xml","xsl","xsd","svg"],load(){return ut(()=>import("./index-5WtC-lYX.js"),__vite__mapDeps([18,1])).then(e=>e.xml())}}),st.of({name:"YAML",alias:["yml"],extensions:["yaml","yml"],load(){return ut(()=>import("./index-D5l562f1.js"),__vite__mapDeps([19,1])).then(e=>e.yaml())}}),st.of({name:"APL",extensions:["dyalog","apl"],load(){return ut(()=>import("./apl-B4CMkyY2.js"),[]).then(e=>St(e.apl))}}),st.of({name:"PGP",alias:["asciiarmor"],extensions:["asc","pgp","sig"],load(){return ut(()=>import("./asciiarmor-Df11BRmG.js"),[]).then(e=>St(e.asciiArmor))}}),st.of({name:"ASN.1",extensions:["asn","asn1"],load(){return ut(()=>import("./asn1-EdZsLKOL.js"),[]).then(e=>St(e.asn1({})))}}),st.of({name:"Asterisk",filename:/^extensions\.conf$/i,load(){return ut(()=>import("./asterisk-B-8jnY81.js"),[]).then(e=>St(e.asterisk))}}),st.of({name:"Brainfuck",extensions:["b","bf"],load(){return ut(()=>import("./brainfuck-C4LP7Hcl.js"),[]).then(e=>St(e.brainfuck))}}),st.of({name:"Cobol",extensions:["cob","cpy"],load(){return ut(()=>import("./cobol-CWcv1MsR.js"),[]).then(e=>St(e.cobol))}}),st.of({name:"C#",alias:["csharp","cs"],extensions:["cs"],load(){return ut(()=>import("./clike-B9uivgTg.js"),[]).then(e=>St(e.csharp))}}),st.of({name:"Clojure",extensions:["clj","cljc","cljx"],load(){return ut(()=>import("./clojure-BMjYHr_A.js"),[]).then(e=>St(e.clojure))}}),st.of({name:"ClojureScript",extensions:["cljs"],load(){return ut(()=>import("./clojure-BMjYHr_A.js"),[]).then(e=>St(e.clojure))}}),st.of({name:"Closure Stylesheets (GSS)",extensions:["gss"],load(){return ut(()=>import("./css-BnMrqG3P.js"),[]).then(e=>St(e.gss))}}),st.of({name:"CMake",extensions:["cmake","cmake.in"],filename:/^CMakeLists\.txt$/,load(){return ut(()=>import("./cmake-BQqOBYOt.js"),[]).then(e=>St(e.cmake))}}),st.of({name:"CoffeeScript",alias:["coffee","coffee-script"],extensions:["coffee"],load(){return ut(()=>import("./coffeescript-S37ZYGWr.js"),[]).then(e=>St(e.coffeeScript))}}),st.of({name:"Common Lisp",alias:["lisp"],extensions:["cl","lisp","el"],load(){return ut(()=>import("./commonlisp-DBKNyK5s.js"),[]).then(e=>St(e.commonLisp))}}),st.of({name:"Cypher",extensions:["cyp","cypher"],load(){return ut(()=>import("./cypher-C_CwsFkJ.js"),[]).then(e=>St(e.cypher))}}),st.of({name:"Cython",extensions:["pyx","pxd","pxi"],load(){return ut(()=>import("./python-BuPzkPfP.js"),[]).then(e=>St(e.cython))}}),st.of({name:"Crystal",extensions:["cr"],load(){return ut(()=>import("./crystal-SjHAIU92.js"),[]).then(e=>St(e.crystal))}}),st.of({name:"D",extensions:["d"],load(){return ut(()=>import("./d-pRatUO7H.js"),[]).then(e=>St(e.d))}}),st.of({name:"Dart",extensions:["dart"],load(){return ut(()=>import("./clike-B9uivgTg.js"),[]).then(e=>St(e.dart))}}),st.of({name:"diff",extensions:["diff","patch"],load(){return ut(()=>import("./diff-DbItnlRl.js"),[]).then(e=>St(e.diff))}}),st.of({name:"Dockerfile",filename:/^Dockerfile$/,load(){return ut(()=>import("./dockerfile-BKs6k2Af.js"),__vite__mapDeps([20,21])).then(e=>St(e.dockerFile))}}),st.of({name:"DTD",extensions:["dtd"],load(){return ut(()=>import("./dtd-DF_7sFjM.js"),[]).then(e=>St(e.dtd))}}),st.of({name:"Dylan",extensions:["dylan","dyl","intr"],load(){return ut(()=>import("./dylan-DwRh75JA.js"),[]).then(e=>St(e.dylan))}}),st.of({name:"EBNF",load(){return ut(()=>import("./ebnf-CDyGwa7X.js"),[]).then(e=>St(e.ebnf))}}),st.of({name:"ECL",extensions:["ecl"],load(){return ut(()=>import("./ecl-Cabwm37j.js"),[]).then(e=>St(e.ecl))}}),st.of({name:"edn",extensions:["edn"],load(){return ut(()=>import("./clojure-BMjYHr_A.js"),[]).then(e=>St(e.clojure))}}),st.of({name:"Eiffel",extensions:["e"],load(){return ut(()=>import("./eiffel-CnydiIhH.js"),[]).then(e=>St(e.eiffel))}}),st.of({name:"Elm",extensions:["elm"],load(){return ut(()=>import("./elm-vLlmbW-K.js"),[]).then(e=>St(e.elm))}}),st.of({name:"Erlang",extensions:["erl"],load(){return ut(()=>import("./erlang-BNw1qcRV.js"),[]).then(e=>St(e.erlang))}}),st.of({name:"Esper",load(){return ut(()=>import("./sql-D0XecflT.js"),[]).then(e=>St(e.esper))}}),st.of({name:"Factor",extensions:["factor"],load(){return ut(()=>import("./factor-kuTfRLto.js"),__vite__mapDeps([22,21])).then(e=>St(e.factor))}}),st.of({name:"FCL",load(){return ut(()=>import("./fcl-Kvtd6kyn.js"),[]).then(e=>St(e.fcl))}}),st.of({name:"Forth",extensions:["forth","fth","4th"],load(){return ut(()=>import("./forth-Ffai-XNe.js"),[]).then(e=>St(e.forth))}}),st.of({name:"Fortran",extensions:["f","for","f77","f90","f95"],load(){return ut(()=>import("./fortran-DYz_wnZ1.js"),[]).then(e=>St(e.fortran))}}),st.of({name:"F#",alias:["fsharp"],extensions:["fs"],load(){return ut(()=>import("./mllike-CXdrOF99.js"),[]).then(e=>St(e.fSharp))}}),st.of({name:"Gas",extensions:["s"],load(){return ut(()=>import("./gas-Bneqetm1.js"),[]).then(e=>St(e.gas))}}),st.of({name:"Gherkin",extensions:["feature"],load(){return ut(()=>import("./gherkin-heZmZLOM.js"),[]).then(e=>St(e.gherkin))}}),st.of({name:"Groovy",extensions:["groovy","gradle"],filename:/^Jenkinsfile$/,load(){return ut(()=>import("./groovy-D9Dt4D0W.js"),[]).then(e=>St(e.groovy))}}),st.of({name:"Haskell",extensions:["hs"],load(){return ut(()=>import("./haskell-Cw1EW3IL.js"),[]).then(e=>St(e.haskell))}}),st.of({name:"Haxe",extensions:["hx"],load(){return ut(()=>import("./haxe-H-WmDvRZ.js"),[]).then(e=>St(e.haxe))}}),st.of({name:"HXML",extensions:["hxml"],load(){return ut(()=>import("./haxe-H-WmDvRZ.js"),[]).then(e=>St(e.hxml))}}),st.of({name:"HTTP",load(){return ut(()=>import("./http-DBlCnlav.js"),[]).then(e=>St(e.http))}}),st.of({name:"IDL",extensions:["pro"],load(){return ut(()=>import("./idl-BEugSyMb.js"),[]).then(e=>St(e.idl))}}),st.of({name:"JSON-LD",alias:["jsonld"],extensions:["jsonld"],load(){return ut(()=>import("./javascript-iXu5QeM3.js"),[]).then(e=>St(e.jsonld))}}),st.of({name:"Julia",extensions:["jl"],load(){return ut(()=>import("./julia-DuME0IfC.js"),[]).then(e=>St(e.julia))}}),st.of({name:"Kotlin",extensions:["kt","kts"],load(){return ut(()=>import("./clike-B9uivgTg.js"),[]).then(e=>St(e.kotlin))}}),st.of({name:"LiveScript",alias:["ls"],extensions:["ls"],load(){return ut(()=>import("./livescript-BwQOo05w.js"),[]).then(e=>St(e.liveScript))}}),st.of({name:"Lua",extensions:["lua"],load(){return ut(()=>import("./lua-BgMRiT3U.js"),[]).then(e=>St(e.lua))}}),st.of({name:"mIRC",extensions:["mrc"],load(){return ut(()=>import("./mirc-CjQqDB4T.js"),[]).then(e=>St(e.mirc))}}),st.of({name:"Mathematica",extensions:["m","nb","wl","wls"],load(){return ut(()=>import("./mathematica-DTrFuWx2.js"),[]).then(e=>St(e.mathematica))}}),st.of({name:"Modelica",extensions:["mo"],load(){return ut(()=>import("./modelica-Dc1JOy9r.js"),[]).then(e=>St(e.modelica))}}),st.of({name:"MUMPS",extensions:["mps"],load(){return ut(()=>import("./mumps-BT43cFF4.js"),[]).then(e=>St(e.mumps))}}),st.of({name:"Mbox",extensions:["mbox"],load(){return ut(()=>import("./mbox-CNhZ1qSd.js"),[]).then(e=>St(e.mbox))}}),st.of({name:"Nginx",filename:/nginx.*\.conf$/i,load(){return ut(()=>import("./nginx-DdIZxoE0.js"),[]).then(e=>St(e.nginx))}}),st.of({name:"NSIS",extensions:["nsh","nsi"],load(){return ut(()=>import("./nsis-LdVXkNf5.js"),__vite__mapDeps([23,21])).then(e=>St(e.nsis))}}),st.of({name:"NTriples",extensions:["nt","nq"],load(){return ut(()=>import("./ntriples-BfvgReVJ.js"),[]).then(e=>St(e.ntriples))}}),st.of({name:"Objective-C",alias:["objective-c","objc"],extensions:["m"],load(){return ut(()=>import("./clike-B9uivgTg.js"),[]).then(e=>St(e.objectiveC))}}),st.of({name:"Objective-C++",alias:["objective-c++","objc++"],extensions:["mm"],load(){return ut(()=>import("./clike-B9uivgTg.js"),[]).then(e=>St(e.objectiveCpp))}}),st.of({name:"OCaml",extensions:["ml","mli","mll","mly"],load(){return ut(()=>import("./mllike-CXdrOF99.js"),[]).then(e=>St(e.oCaml))}}),st.of({name:"Octave",extensions:["m"],load(){return ut(()=>import("./octave-Ck1zUtKM.js"),[]).then(e=>St(e.octave))}}),st.of({name:"Oz",extensions:["oz"],load(){return ut(()=>import("./oz-BzwKVEFT.js"),[]).then(e=>St(e.oz))}}),st.of({name:"Pascal",extensions:["p","pas"],load(){return ut(()=>import("./pascal--L3eBynH.js"),[]).then(e=>St(e.pascal))}}),st.of({name:"Perl",extensions:["pl","pm"],load(){return ut(()=>import("./perl-CdXCOZ3F.js"),[]).then(e=>St(e.perl))}}),st.of({name:"Pig",extensions:["pig"],load(){return ut(()=>import("./pig-CevX1Tat.js"),[]).then(e=>St(e.pig))}}),st.of({name:"PowerShell",extensions:["ps1","psd1","psm1"],load(){return ut(()=>import("./powershell-CFHJl5sT.js"),[]).then(e=>St(e.powerShell))}}),st.of({name:"Properties files",alias:["ini","properties"],extensions:["properties","ini","in"],load(){return ut(()=>import("./properties-C78fOPTZ.js"),[]).then(e=>St(e.properties))}}),st.of({name:"ProtoBuf",extensions:["proto"],load(){return ut(()=>import("./protobuf-ChK-085T.js"),[]).then(e=>St(e.protobuf))}}),st.of({name:"Pug",alias:["jade"],extensions:["pug","jade"],load(){return ut(()=>import("./pug-DeIclll2.js"),__vite__mapDeps([24,25])).then(e=>St(e.pug))}}),st.of({name:"Puppet",extensions:["pp"],load(){return ut(()=>import("./puppet-DMA9R1ak.js"),[]).then(e=>St(e.puppet))}}),st.of({name:"Q",extensions:["q"],load(){return ut(()=>import("./q-pXgVlZs6.js"),[]).then(e=>St(e.q))}}),st.of({name:"R",alias:["rscript"],extensions:["r","R"],load(){return ut(()=>import("./r-B6wPVr8A.js"),[]).then(e=>St(e.r))}}),st.of({name:"RPM Changes",load(){return ut(()=>import("./rpm-CTu-6PCP.js"),[]).then(e=>St(e.rpmChanges))}}),st.of({name:"RPM Spec",extensions:["spec"],load(){return ut(()=>import("./rpm-CTu-6PCP.js"),[]).then(e=>St(e.rpmSpec))}}),st.of({name:"Ruby",alias:["jruby","macruby","rake","rb","rbx"],extensions:["rb"],filename:/^(Gemfile|Rakefile)$/,load(){return ut(()=>import("./ruby-B2Rjki9n.js"),[]).then(e=>St(e.ruby))}}),st.of({name:"SAS",extensions:["sas"],load(){return ut(()=>import("./sas-B4kiWyti.js"),[]).then(e=>St(e.sas))}}),st.of({name:"Scala",extensions:["scala"],load(){return ut(()=>import("./clike-B9uivgTg.js"),[]).then(e=>St(e.scala))}}),st.of({name:"Scheme",extensions:["scm","ss"],load(){return ut(()=>import("./scheme-C41bIUwD.js"),[]).then(e=>St(e.scheme))}}),st.of({name:"Shell",alias:["bash","sh","zsh"],extensions:["sh","ksh","bash"],filename:/^PKGBUILD$/,load(){return ut(()=>import("./shell-CjFT_Tl9.js"),[]).then(e=>St(e.shell))}}),st.of({name:"Sieve",extensions:["siv","sieve"],load(){return ut(()=>import("./sieve-C3Gn_uJK.js"),[]).then(e=>St(e.sieve))}}),st.of({name:"Smalltalk",extensions:["st"],load(){return ut(()=>import("./smalltalk-CnHTOXQT.js"),[]).then(e=>St(e.smalltalk))}}),st.of({name:"Solr",load(){return ut(()=>import("./solr-DehyRSwq.js"),[]).then(e=>St(e.solr))}}),st.of({name:"SML",extensions:["sml","sig","fun","smackspec"],load(){return ut(()=>import("./mllike-CXdrOF99.js"),[]).then(e=>St(e.sml))}}),st.of({name:"SPARQL",alias:["sparul"],extensions:["rq","sparql"],load(){return ut(()=>import("./sparql-DkYu6x3z.js"),[]).then(e=>St(e.sparql))}}),st.of({name:"Spreadsheet",alias:["excel","formula"],load(){return ut(()=>import("./spreadsheet-BCZA_wO0.js"),[]).then(e=>St(e.spreadsheet))}}),st.of({name:"Squirrel",extensions:["nut"],load(){return ut(()=>import("./clike-B9uivgTg.js"),[]).then(e=>St(e.squirrel))}}),st.of({name:"Stylus",extensions:["styl"],load(){return ut(()=>import("./stylus-B533Al4x.js"),[]).then(e=>St(e.stylus))}}),st.of({name:"Swift",extensions:["swift"],load(){return ut(()=>import("./swift-BzpIVaGY.js"),[]).then(e=>St(e.swift))}}),st.of({name:"sTeX",load(){return ut(()=>import("./stex-C3f8Ysf7.js"),[]).then(e=>St(e.stex))}}),st.of({name:"LaTeX",alias:["tex"],extensions:["text","ltx","tex"],load(){return ut(()=>import("./stex-C3f8Ysf7.js"),[]).then(e=>St(e.stex))}}),st.of({name:"SystemVerilog",extensions:["v","sv","svh"],load(){return ut(()=>import("./verilog-C6RDOZhf.js"),[]).then(e=>St(e.verilog))}}),st.of({name:"Tcl",extensions:["tcl"],load(){return ut(()=>import("./tcl-DVfN8rqt.js"),[]).then(e=>St(e.tcl))}}),st.of({name:"Textile",extensions:["textile"],load(){return ut(()=>import("./textile-CnDTJFAw.js"),[]).then(e=>St(e.textile))}}),st.of({name:"TiddlyWiki",load(){return ut(()=>import("./tiddlywiki-DO-Gjzrf.js"),[]).then(e=>St(e.tiddlyWiki))}}),st.of({name:"Tiki wiki",load(){return ut(()=>import("./tiki-DGYXhP31.js"),[]).then(e=>St(e.tiki))}}),st.of({name:"TOML",extensions:["toml"],load(){return ut(()=>import("./toml-Bm5Em-hy.js"),[]).then(e=>St(e.toml))}}),st.of({name:"Troff",extensions:["1","2","3","4","5","6","7","8","9"],load(){return ut(()=>import("./troff-wAsdV37c.js"),[]).then(e=>St(e.troff))}}),st.of({name:"TTCN",extensions:["ttcn","ttcn3","ttcnpp"],load(){return ut(()=>import("./ttcn-CfJYG6tj.js"),[]).then(e=>St(e.ttcn))}}),st.of({name:"TTCN_CFG",extensions:["cfg"],load(){return ut(()=>import("./ttcn-cfg-B9xdYoR4.js"),[]).then(e=>St(e.ttcnCfg))}}),st.of({name:"Turtle",extensions:["ttl"],load(){return ut(()=>import("./turtle-B1tBg_DP.js"),[]).then(e=>St(e.turtle))}}),st.of({name:"Web IDL",extensions:["webidl"],load(){return ut(()=>import("./webidl-ZXfAyPTL.js"),[]).then(e=>St(e.webIDL))}}),st.of({name:"VB.NET",extensions:["vb"],load(){return ut(()=>import("./vb-CmGdzxic.js"),[]).then(e=>St(e.vb))}}),st.of({name:"VBScript",extensions:["vbs"],load(){return ut(()=>import("./vbscript-BuJXcnF6.js"),[]).then(e=>St(e.vbScript))}}),st.of({name:"Velocity",extensions:["vtl"],load(){return ut(()=>import("./velocity-D8B20fx6.js"),[]).then(e=>St(e.velocity))}}),st.of({name:"Verilog",extensions:["v"],load(){return ut(()=>import("./verilog-C6RDOZhf.js"),[]).then(e=>St(e.verilog))}}),st.of({name:"VHDL",extensions:["vhd","vhdl"],load(){return ut(()=>import("./vhdl-lSbBsy5d.js"),[]).then(e=>St(e.vhdl))}}),st.of({name:"XQuery",extensions:["xy","xquery","xq","xqm","xqy"],load(){return ut(()=>import("./xquery-DzFWVndE.js"),[]).then(e=>St(e.xQuery))}}),st.of({name:"Yacas",extensions:["ys"],load(){return ut(()=>import("./yacas-BJ4BC0dw.js"),[]).then(e=>St(e.yacas))}}),st.of({name:"Z80",extensions:["z80"],load(){return ut(()=>import("./z80-Hz9HOZM7.js"),[]).then(e=>St(e.z80))}}),st.of({name:"MscGen",extensions:["mscgen","mscin","msc"],load(){return ut(()=>import("./mscgen-BA5vi2Kp.js"),[]).then(e=>St(e.mscgen))}}),st.of({name:"Xù",extensions:["xu"],load(){return ut(()=>import("./mscgen-BA5vi2Kp.js"),[]).then(e=>St(e.xu))}}),st.of({name:"MsGenny",extensions:["msgenny"],load(){return ut(()=>import("./mscgen-BA5vi2Kp.js"),[]).then(e=>St(e.msgenny))}}),st.of({name:"Vue",extensions:["vue"],load(){return ut(()=>import("./index-D8uEkAY_.js"),__vite__mapDeps([26,5,1,3,6])).then(e=>e.vue())}}),st.of({name:"Angular Template",load(){return ut(()=>import("./index-BEIANN3j.js"),__vite__mapDeps([27,5,1,3,6])).then(e=>e.angular())}})],ree="#2e3440",lU="#3b4252",see="#434c5e",I_="#4c566a",iee="#e5e9f0",y$="#eceff4",yD="#8fbcbb",aee="#88c0d0",$ot="#81a1c1",Eu="#5e81ac",Fot="#bf616a",o0="#d08770",vD="#ebcb8b",oee="#a3be8c",zot="#b48ead",lee="#d30102",cU=y$,wD=cU,Bot="#ffffff",kD=lU,Uot=cU,cee=lU,qot=Yt.theme({"&":{color:ree,backgroundColor:Bot},".cm-content":{caretColor:cee},".cm-cursor, .cm-dropCursor":{borderLeftColor:cee},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection":{backgroundColor:Uot},".cm-panels":{backgroundColor:cU,color:I_},".cm-panels.cm-panels-top":{borderBottom:"2px solid black"},".cm-panels.cm-panels-bottom":{borderTop:"2px solid black"},".cm-searchMatch":{backgroundColor:"#72a1ff59",outline:`1px solid ${I_}`},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:iee},".cm-activeLine":{backgroundColor:wD},".cm-selectionMatch":{backgroundColor:iee},"&.cm-focused .cm-matchingBracket, &.cm-focused .cm-nonmatchingBracket":{outline:`1px solid ${I_}`},"&.cm-focused .cm-matchingBracket":{backgroundColor:y$},".cm-gutters":{backgroundColor:y$,color:ree,border:"none"},".cm-activeLineGutter":{backgroundColor:wD},".cm-foldPlaceholder":{backgroundColor:"transparent",border:"none",color:"#ddd"},".cm-tooltip":{border:"none",backgroundColor:kD},".cm-tooltip .cm-tooltip-arrow:before":{borderTopColor:"transparent",borderBottomColor:"transparent"},".cm-tooltip .cm-tooltip-arrow:after":{borderTopColor:kD,borderBottomColor:kD},".cm-tooltip-autocomplete":{"& > ul > li[aria-selected]":{backgroundColor:wD,color:I_}}},{dark:!1}),Vot=YC.define([{tag:ct.keyword,color:Eu},{tag:[ct.name,ct.deleted,ct.character,ct.propertyName,ct.macroName],color:o0},{tag:[ct.variableName],color:o0},{tag:[ct.function(ct.variableName)],color:Eu},{tag:[ct.labelName],color:$ot},{tag:[ct.color,ct.constant(ct.name),ct.standard(ct.name)],color:Eu},{tag:[ct.definition(ct.name),ct.separator],color:oee},{tag:[ct.brace],color:yD},{tag:[ct.annotation],color:lee},{tag:[ct.number,ct.changed,ct.annotation,ct.modifier,ct.self,ct.namespace],color:aee},{tag:[ct.typeName,ct.className],color:vD},{tag:[ct.operator,ct.operatorKeyword],color:oee},{tag:[ct.tagName],color:zot},{tag:[ct.squareBracket],color:Fot},{tag:[ct.angleBracket],color:o0},{tag:[ct.attributeName],color:vD},{tag:[ct.regexp],color:Eu},{tag:[ct.quote],color:lU},{tag:[ct.string],color:o0},{tag:ct.link,color:yD,textDecoration:"underline",textUnderlinePosition:"under"},{tag:[ct.url,ct.escape,ct.special(ct.string)],color:o0},{tag:[ct.meta],color:aee},{tag:[ct.comment],color:see,fontStyle:"italic"},{tag:ct.strong,fontWeight:"bold",color:Eu},{tag:ct.emphasis,fontStyle:"italic",color:Eu},{tag:ct.strikethrough,textDecoration:"line-through"},{tag:ct.heading,fontWeight:"bold",color:Eu},{tag:ct.special(ct.heading1),fontWeight:"bold",color:Eu},{tag:ct.heading1,fontWeight:"bold",color:Eu},{tag:[ct.heading2,ct.heading3,ct.heading4],fontWeight:"bold",color:Eu},{tag:[ct.heading5,ct.heading6],color:Eu},{tag:[ct.atom,ct.bool,ct.special(ct.variableName)],color:o0},{tag:[ct.processingInstruction,ct.inserted],color:yD},{tag:[ct.contentSeparator],color:vD},{tag:ct.invalid,color:see,borderBottom:`1px dotted ${lee}`}]),Hot=[qot,i0e(Vot)],uee=typeof String.prototype.normalize=="function"?e=>e.normalize("NFKD"):e=>e;class Yv{constructor(t,n,r=0,s=t.length,a,o){this.test=o,this.value={from:0,to:0},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=t.iterRange(r,s),this.bufferStart=r,this.normalize=a?l=>a(uee(l)):uee,this.query=this.normalize(n)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return Fl(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let t=this.peek();if(t<0)return this.done=!0,this;let n=jB(t),r=this.bufferStart+this.bufferPos;this.bufferPos+=ef(t);let s=this.normalize(n);if(s.length)for(let a=0,o=r;;a++){let l=s.charCodeAt(a),c=this.match(l,o,this.bufferPos+this.bufferStart);if(a==s.length-1){if(c)return this.value=c,this;break}o==r&&a<n.length&&n.charCodeAt(a)==l&&o++}}}match(t,n,r){let s=null;for(let a=0;a<this.matches.length;a+=2){let o=this.matches[a],l=!1;this.query.charCodeAt(o)==t&&(o==this.query.length-1?s={from:this.matches[a+1],to:r}:(this.matches[a]++,l=!0)),l||(this.matches.splice(a,2),a-=2)}return this.query.charCodeAt(0)==t&&(this.query.length==1?s={from:n,to:r}:this.matches.push(1,n)),s&&this.test&&!this.test(s.from,s.to,this.buffer,this.bufferStart)&&(s=null),s}}typeof Symbol<"u"&&(Yv.prototype[Symbol.iterator]=function(){return this});const sve={from:-1,to:-1,match:/.*/.exec("")},uU="gm"+(/x/.unicode==null?"":"u");class ive{constructor(t,n,r,s=0,a=t.length){if(this.text=t,this.to=a,this.curLine="",this.done=!1,this.value=sve,/\\[sWDnr]|\n|\r|\[\^/.test(n))return new ave(t,n,r,s,a);this.re=new RegExp(n,uU+(r!=null&&r.ignoreCase?"i":"")),this.test=r==null?void 0:r.test,this.iter=t.iter();let o=t.lineAt(s);this.curLineStart=o.from,this.matchPos=qE(t,s),this.getLine(this.curLineStart)}getLine(t){this.iter.next(t),this.iter.lineBreak?this.curLine="":(this.curLine=this.iter.value,this.curLineStart+this.curLine.length>this.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart)),this.iter.next())}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1,this.curLineStart>this.to?this.curLine="":this.getLine(0)}next(){for(let t=this.matchPos-this.curLineStart;;){this.re.lastIndex=t;let n=this.matchPos<=this.to&&this.re.exec(this.curLine);if(n){let r=this.curLineStart+n.index,s=r+n[0].length;if(this.matchPos=qE(this.text,s+(r==s?1:0)),r==this.curLineStart+this.curLine.length&&this.nextLine(),(r<s||r>this.value.to)&&(!this.test||this.test(r,s,n)))return this.value={from:r,to:s,match:n},this;t=this.matchPos-this.curLineStart}else if(this.curLineStart+this.curLine.length<this.to)this.nextLine(),t=0;else return this.done=!0,this}}}const jD=new WeakMap;class J0{constructor(t,n){this.from=t,this.text=n}get to(){return this.from+this.text.length}static get(t,n,r){let s=jD.get(t);if(!s||s.from>=r||s.to<=n){let l=new J0(n,t.sliceString(n,r));return jD.set(t,l),l}if(s.from==n&&s.to==r)return s;let{text:a,from:o}=s;return o>n&&(a=t.sliceString(n,o)+a,o=n),s.to<r&&(a+=t.sliceString(s.to,r)),jD.set(t,new J0(o,a)),new J0(n,a.slice(n-o,r-o))}}class ave{constructor(t,n,r,s,a){this.text=t,this.to=a,this.done=!1,this.value=sve,this.matchPos=qE(t,s),this.re=new RegExp(n,uU+(r!=null&&r.ignoreCase?"i":"")),this.test=r==null?void 0:r.test,this.flat=J0.get(t,s,this.chunkEnd(s+5e3))}chunkEnd(t){return t>=this.to?this.to:this.text.lineAt(t).to}next(){for(;;){let t=this.re.lastIndex=this.matchPos-this.flat.from,n=this.re.exec(this.flat.text);if(n&&!n[0]&&n.index==t&&(this.re.lastIndex=t+1,n=this.re.exec(this.flat.text)),n){let r=this.flat.from+n.index,s=r+n[0].length;if((this.flat.to>=this.to||n.index+n[0].length<=this.flat.text.length-10)&&(!this.test||this.test(r,s,n)))return this.value={from:r,to:s,match:n},this.matchPos=qE(this.text,s+(r==s?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=J0.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}}typeof Symbol<"u"&&(ive.prototype[Symbol.iterator]=ave.prototype[Symbol.iterator]=function(){return this});function Kot(e){try{return new RegExp(e,uU),!0}catch{return!1}}function qE(e,t){if(t>=e.length)return t;let n=e.lineAt(t),r;for(;t<n.to&&(r=n.text.charCodeAt(t-n.from))>=56320&&r<57344;)t++;return t}const Wot=e=>{let{state:t}=e,n=String(t.doc.lineAt(e.state.selection.main.head).number),{close:r,result:s}=Yrt(e,{label:t.phrase("Go to line"),input:{type:"text",name:"line",value:n},focus:!0,submitLabel:t.phrase("go")});return s.then(a=>{let o=a&&/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(a.elements.line.value);if(!o){e.dispatch({effects:r});return}let l=t.doc.lineAt(t.selection.main.head),[,c,u,d,h]=o,m=d?+d.slice(1):0,g=u?+u:l.number;if(u&&h){let j=g/100;c&&(j=j*(c=="-"?-1:1)+l.number/t.doc.lines),g=Math.round(t.doc.lines*j)}else u&&c&&(g=g*(c=="-"?-1:1)+l.number);let b=t.doc.line(Math.max(1,Math.min(t.doc.lines,g))),v=xt.cursor(b.from+Math.max(0,Math.min(m,b.length)));e.dispatch({effects:[r,Yt.scrollIntoView(v.from,{y:"center"})],selection:v})}),!0},Got={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},Qot=Zt.define({combine(e){return Pf(e,Got,{highlightWordAroundCursor:(t,n)=>t||n,minSelectionLength:Math.min,maxMatches:Math.min})}});function Yot(e){return[tlt,elt]}const Jot=En.mark({class:"cm-selectionMatch"}),Zot=En.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function dee(e,t,n,r){return(n==0||e(t.sliceDoc(n-1,n))!=hi.Word)&&(r==t.doc.length||e(t.sliceDoc(r,r+1))!=hi.Word)}function Xot(e,t,n,r){return e(t.sliceDoc(n,n+1))==hi.Word&&e(t.sliceDoc(r-1,r))==hi.Word}const elt=Vi.fromClass(class{constructor(e){this.decorations=this.getDeco(e)}update(e){(e.selectionSet||e.docChanged||e.viewportChanged)&&(this.decorations=this.getDeco(e.view))}getDeco(e){let t=e.state.facet(Qot),{state:n}=e,r=n.selection;if(r.ranges.length>1)return En.none;let s=r.main,a,o=null;if(s.empty){if(!t.highlightWordAroundCursor)return En.none;let c=n.wordAt(s.head);if(!c)return En.none;o=n.charCategorizer(s.head),a=n.sliceDoc(c.from,c.to)}else{let c=s.to-s.from;if(c<t.minSelectionLength||c>200)return En.none;if(t.wholeWords){if(a=n.sliceDoc(s.from,s.to),o=n.charCategorizer(s.head),!(dee(o,n,s.from,s.to)&&Xot(o,n,s.from,s.to)))return En.none}else if(a=n.sliceDoc(s.from,s.to),!a)return En.none}let l=[];for(let c of e.visibleRanges){let u=new Yv(n.doc,a,c.from,c.to);for(;!u.next().done;){let{from:d,to:h}=u.value;if((!o||dee(o,n,d,h))&&(s.empty&&d<=s.from&&h>=s.to?l.push(Zot.range(d,h)):(d>=s.to||h<=s.from)&&l.push(Jot.range(d,h)),l.length>t.maxMatches))return En.none}}return En.set(l)}},{decorations:e=>e.decorations}),tlt=Yt.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}}),nlt=({state:e,dispatch:t})=>{let{selection:n}=e,r=xt.create(n.ranges.map(s=>e.wordAt(s.head)||xt.cursor(s.head)),n.mainIndex);return r.eq(n)?!1:(t(e.update({selection:r})),!0)};function rlt(e,t){let{main:n,ranges:r}=e.selection,s=e.wordAt(n.head),a=s&&s.from==n.from&&s.to==n.to;for(let o=!1,l=new Yv(e.doc,t,r[r.length-1].to);;)if(l.next(),l.done){if(o)return null;l=new Yv(e.doc,t,0,Math.max(0,r[r.length-1].from-1)),o=!0}else{if(o&&r.some(c=>c.from==l.value.from))continue;if(a){let c=e.wordAt(l.value.from);if(!c||c.from!=l.value.from||c.to!=l.value.to)continue}return l.value}}const slt=({state:e,dispatch:t})=>{let{ranges:n}=e.selection;if(n.some(a=>a.from===a.to))return nlt({state:e,dispatch:t});let r=e.sliceDoc(n[0].from,n[0].to);if(e.selection.ranges.some(a=>e.sliceDoc(a.from,a.to)!=r))return!1;let s=rlt(e,r);return s?(t(e.update({selection:e.selection.addRange(xt.range(s.from,s.to),!1),effects:Yt.scrollIntoView(s.to)})),!0):!1},H1=Zt.define({combine(e){return Pf(e,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:t=>new blt(t),scrollToMatch:t=>Yt.scrollIntoView(t)})}});class ove{constructor(t){this.search=t.search,this.caseSensitive=!!t.caseSensitive,this.literal=!!t.literal,this.regexp=!!t.regexp,this.replace=t.replace||"",this.valid=!!this.search&&(!this.regexp||Kot(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!t.wholeWord,this.test=t.test}unquote(t){return this.literal?t:t.replace(/\\([nrt\\])/g,(n,r)=>r=="n"?`
1283
1283
  `:r=="r"?"\r":r=="t"?" ":"\\")}eq(t){return this.search==t.search&&this.replace==t.replace&&this.caseSensitive==t.caseSensitive&&this.regexp==t.regexp&&this.wholeWord==t.wholeWord&&this.test==t.test}create(){return this.regexp?new ult(this):new olt(this)}getCursor(t,n=0,r){let s=t.doc?t:Ur.create({doc:t});return r==null&&(r=s.doc.length),this.regexp?S0(this,s,n,r):C0(this,s,n,r)}}class lve{constructor(t){this.spec=t}}function ilt(e,t,n){return(r,s,a,o)=>{if(n&&!n(r,s,a,o))return!1;let l=r>=o&&s<=o+a.length?a.slice(r-o,s-o):t.doc.sliceString(r,s);return e(l,t,r,s)}}function C0(e,t,n,r){let s;return e.wholeWord&&(s=alt(t.doc,t.charCategorizer(t.selection.main.head))),e.test&&(s=ilt(e.test,t,s)),new Yv(t.doc,e.unquoted,n,r,e.caseSensitive?void 0:a=>a.toLowerCase(),s)}function alt(e,t){return(n,r,s,a)=>((a>n||a+s.length<r)&&(a=Math.max(0,n-2),s=e.sliceString(a,Math.min(e.length,r+2))),(t(VE(s,n-a))!=hi.Word||t(HE(s,n-a))!=hi.Word)&&(t(HE(s,r-a))!=hi.Word||t(VE(s,r-a))!=hi.Word))}class olt extends lve{constructor(t){super(t)}nextMatch(t,n,r){let s=C0(this.spec,t,r,t.doc.length).nextOverlapping();if(s.done){let a=Math.min(t.doc.length,n+this.spec.unquoted.length);s=C0(this.spec,t,0,a).nextOverlapping()}return s.done||s.value.from==n&&s.value.to==r?null:s.value}prevMatchInRange(t,n,r){for(let s=r;;){let a=Math.max(n,s-1e4-this.spec.unquoted.length),o=C0(this.spec,t,a,s),l=null;for(;!o.nextOverlapping().done;)l=o.value;if(l)return l;if(a==n)return null;s-=1e4}}prevMatch(t,n,r){let s=this.prevMatchInRange(t,0,n);return s||(s=this.prevMatchInRange(t,Math.max(0,r-this.spec.unquoted.length),t.doc.length)),s&&(s.from!=n||s.to!=r)?s:null}getReplacement(t){return this.spec.unquote(this.spec.replace)}matchAll(t,n){let r=C0(this.spec,t,0,t.doc.length),s=[];for(;!r.next().done;){if(s.length>=n)return null;s.push(r.value)}return s}highlight(t,n,r,s){let a=C0(this.spec,t,Math.max(0,n-this.spec.unquoted.length),Math.min(r+this.spec.unquoted.length,t.doc.length));for(;!a.next().done;)s(a.value.from,a.value.to)}}function llt(e,t,n){return(r,s,a)=>(!n||n(r,s,a))&&e(a[0],t,r,s)}function S0(e,t,n,r){let s;return e.wholeWord&&(s=clt(t.charCategorizer(t.selection.main.head))),e.test&&(s=llt(e.test,t,s)),new ive(t.doc,e.search,{ignoreCase:!e.caseSensitive,test:s},n,r)}function VE(e,t){return e.slice(za(e,t,!1),t)}function HE(e,t){return e.slice(t,za(e,t))}function clt(e){return(t,n,r)=>!r[0].length||(e(VE(r.input,r.index))!=hi.Word||e(HE(r.input,r.index))!=hi.Word)&&(e(HE(r.input,r.index+r[0].length))!=hi.Word||e(VE(r.input,r.index+r[0].length))!=hi.Word)}class ult extends lve{nextMatch(t,n,r){let s=S0(this.spec,t,r,t.doc.length).next();return s.done&&(s=S0(this.spec,t,0,n).next()),s.done?null:s.value}prevMatchInRange(t,n,r){for(let s=1;;s++){let a=Math.max(n,r-s*1e4),o=S0(this.spec,t,a,r),l=null;for(;!o.next().done;)l=o.value;if(l&&(a==n||l.from>a+10))return l;if(a==n)return null}}prevMatch(t,n,r){return this.prevMatchInRange(t,0,n)||this.prevMatchInRange(t,r,t.doc.length)}getReplacement(t){return this.spec.unquote(this.spec.replace).replace(/\$([$&]|\d+)/g,(n,r)=>{if(r=="&")return t.match[0];if(r=="$")return"$";for(let s=r.length;s>0;s--){let a=+r.slice(0,s);if(a>0&&a<t.match.length)return t.match[a]+r.slice(s)}return n})}matchAll(t,n){let r=S0(this.spec,t,0,t.doc.length),s=[];for(;!r.next().done;){if(s.length>=n)return null;s.push(r.value)}return s}highlight(t,n,r,s){let a=S0(this.spec,t,Math.max(0,n-250),Math.min(r+250,t.doc.length));for(;!a.next().done;)s(a.value.from,a.value.to)}}const $N=Yn.define(),dU=Yn.define(),Wp=ko.define({create(e){return new ND(v$(e).create(),null)},update(e,t){for(let n of t.effects)n.is($N)?e=new ND(n.value.create(),e.panel):n.is(dU)&&(e=new ND(e.query,n.value?fU:null));return e},provide:e=>TN.from(e,t=>t.panel)});class ND{constructor(t,n){this.query=t,this.panel=n}}const dlt=En.mark({class:"cm-searchMatch"}),flt=En.mark({class:"cm-searchMatch cm-searchMatch-selected"}),hlt=Vi.fromClass(class{constructor(e){this.view=e,this.decorations=this.highlight(e.state.field(Wp))}update(e){let t=e.state.field(Wp);(t!=e.startState.field(Wp)||e.docChanged||e.selectionSet||e.viewportChanged)&&(this.decorations=this.highlight(t))}highlight({query:e,panel:t}){if(!t||!e.spec.valid)return En.none;let{view:n}=this,r=new tm;for(let s=0,a=n.visibleRanges,o=a.length;s<o;s++){let{from:l,to:c}=a[s];for(;s<o-1&&c>a[s+1].from-500;)c=a[++s].to;e.highlight(n.state,l,c,(u,d)=>{let h=n.state.selection.ranges.some(m=>m.from==u&&m.to==d);r.add(u,d,h?flt:dlt)})}return r.finish()}},{decorations:e=>e.decorations});function XC(e){return t=>{let n=t.state.field(Wp,!1);return n&&n.query.spec.valid?e(t,n):dve(t)}}const KE=XC((e,{query:t})=>{let{to:n}=e.state.selection.main,r=t.nextMatch(e.state,n,n);if(!r)return!1;let s=xt.single(r.from,r.to),a=e.state.facet(H1);return e.dispatch({selection:s,effects:[hU(e,r),a.scrollToMatch(s.main,e)],userEvent:"select.search"}),uve(e),!0}),WE=XC((e,{query:t})=>{let{state:n}=e,{from:r}=n.selection.main,s=t.prevMatch(n,r,r);if(!s)return!1;let a=xt.single(s.from,s.to),o=e.state.facet(H1);return e.dispatch({selection:a,effects:[hU(e,s),o.scrollToMatch(a.main,e)],userEvent:"select.search"}),uve(e),!0}),mlt=XC((e,{query:t})=>{let n=t.matchAll(e.state,1e3);return!n||!n.length?!1:(e.dispatch({selection:xt.create(n.map(r=>xt.range(r.from,r.to))),userEvent:"select.search.matches"}),!0)}),plt=({state:e,dispatch:t})=>{let n=e.selection;if(n.ranges.length>1||n.main.empty)return!1;let{from:r,to:s}=n.main,a=[],o=0;for(let l=new Yv(e.doc,e.sliceDoc(r,s));!l.next().done;){if(a.length>1e3)return!1;l.value.from==r&&(o=a.length),a.push(xt.range(l.value.from,l.value.to))}return t(e.update({selection:xt.create(a,o),userEvent:"select.search.matches"})),!0},fee=XC((e,{query:t})=>{let{state:n}=e,{from:r,to:s}=n.selection.main;if(n.readOnly)return!1;let a=t.nextMatch(n,r,r);if(!a)return!1;let o=a,l=[],c,u,d=[];o.from==r&&o.to==s&&(u=n.toText(t.getReplacement(o)),l.push({from:o.from,to:o.to,insert:u}),o=t.nextMatch(n,o.from,o.to),d.push(Yt.announce.of(n.phrase("replaced match on line $",n.doc.lineAt(r).number)+".")));let h=e.state.changes(l);return o&&(c=xt.single(o.from,o.to).map(h),d.push(hU(e,o)),d.push(n.facet(H1).scrollToMatch(c.main,e))),e.dispatch({changes:h,selection:c,effects:d,userEvent:"input.replace"}),!0}),glt=XC((e,{query:t})=>{if(e.state.readOnly)return!1;let n=t.matchAll(e.state,1e9).map(s=>{let{from:a,to:o}=s;return{from:a,to:o,insert:t.getReplacement(s)}});if(!n.length)return!1;let r=e.state.phrase("replaced $ matches",n.length)+".";return e.dispatch({changes:n,effects:Yt.announce.of(r),userEvent:"input.replace.all"}),!0});function fU(e){return e.state.facet(H1).createPanel(e)}function v$(e,t){var n,r,s,a,o;let l=e.selection.main,c=l.empty||l.to>l.from+100?"":e.sliceDoc(l.from,l.to);if(t&&!c)return t;let u=e.facet(H1);return new ove({search:((n=t==null?void 0:t.literal)!==null&&n!==void 0?n:u.literal)?c:c.replace(/\n/g,"\\n"),caseSensitive:(r=t==null?void 0:t.caseSensitive)!==null&&r!==void 0?r:u.caseSensitive,literal:(s=t==null?void 0:t.literal)!==null&&s!==void 0?s:u.literal,regexp:(a=t==null?void 0:t.regexp)!==null&&a!==void 0?a:u.regexp,wholeWord:(o=t==null?void 0:t.wholeWord)!==null&&o!==void 0?o:u.wholeWord})}function cve(e){let t=BB(e,fU);return t&&t.dom.querySelector("[main-field]")}function uve(e){let t=cve(e);t&&t==e.root.activeElement&&t.select()}const dve=e=>{let t=e.state.field(Wp,!1);if(t&&t.panel){let n=cve(e);if(n&&n!=e.root.activeElement){let r=v$(e.state,t.query.spec);r.valid&&e.dispatch({effects:$N.of(r)}),n.focus(),n.select()}}else e.dispatch({effects:[dU.of(!0),t?$N.of(v$(e.state,t.query.spec)):Yn.appendConfig.of(vlt)]});return!0},fve=e=>{let t=e.state.field(Wp,!1);if(!t||!t.panel)return!1;let n=BB(e,fU);return n&&n.dom.contains(e.root.activeElement)&&e.focus(),e.dispatch({effects:dU.of(!1)}),!0},xlt=[{key:"Mod-f",run:dve,scope:"editor search-panel"},{key:"F3",run:KE,shift:WE,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:KE,shift:WE,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:fve,scope:"editor search-panel"},{key:"Mod-Shift-l",run:plt},{key:"Mod-Alt-g",run:Wot},{key:"Mod-d",run:slt,preventDefault:!0}];class blt{constructor(t){this.view=t;let n=this.query=t.state.field(Wp).query.spec;this.commit=this.commit.bind(this),this.searchField=Es("input",{value:n.search,placeholder:fc(t,"Find"),"aria-label":fc(t,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=Es("input",{value:n.replace,placeholder:fc(t,"Replace"),"aria-label":fc(t,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit}),this.caseField=Es("input",{type:"checkbox",name:"case",form:"",checked:n.caseSensitive,onchange:this.commit}),this.reField=Es("input",{type:"checkbox",name:"re",form:"",checked:n.regexp,onchange:this.commit}),this.wordField=Es("input",{type:"checkbox",name:"word",form:"",checked:n.wholeWord,onchange:this.commit});function r(s,a,o){return Es("button",{class:"cm-button",name:s,onclick:a,type:"button"},o)}this.dom=Es("div",{onkeydown:s=>this.keydown(s),class:"cm-search"},[this.searchField,r("next",()=>KE(t),[fc(t,"next")]),r("prev",()=>WE(t),[fc(t,"previous")]),r("select",()=>mlt(t),[fc(t,"all")]),Es("label",null,[this.caseField,fc(t,"match case")]),Es("label",null,[this.reField,fc(t,"regexp")]),Es("label",null,[this.wordField,fc(t,"by word")]),...t.state.readOnly?[]:[Es("br"),this.replaceField,r("replace",()=>fee(t),[fc(t,"replace")]),r("replaceAll",()=>glt(t),[fc(t,"replace all")])],Es("button",{name:"close",onclick:()=>fve(t),"aria-label":fc(t,"close"),type:"button"},["×"])])}commit(){let t=new ove({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,wholeWord:this.wordField.checked,replace:this.replaceField.value});t.eq(this.query)||(this.query=t,this.view.dispatch({effects:$N.of(t)}))}keydown(t){lrt(this.view,t,"search-panel")?t.preventDefault():t.keyCode==13&&t.target==this.searchField?(t.preventDefault(),(t.shiftKey?WE:KE)(this.view)):t.keyCode==13&&t.target==this.replaceField&&(t.preventDefault(),fee(this.view))}update(t){for(let n of t.transactions)for(let r of n.effects)r.is($N)&&!r.value.eq(this.query)&&this.setQuery(r.value)}setQuery(t){this.query=t,this.searchField.value=t.search,this.replaceField.value=t.replace,this.caseField.checked=t.caseSensitive,this.reField.checked=t.regexp,this.wordField.checked=t.wholeWord}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(H1).top}}function fc(e,t){return e.state.phrase(t)}const R_=30,M_=/[\s\.,:;?!]/;function hU(e,{from:t,to:n}){let r=e.state.doc.lineAt(t),s=e.state.doc.lineAt(n).to,a=Math.max(r.from,t-R_),o=Math.min(s,n+R_),l=e.state.sliceDoc(a,o);if(a!=r.from){for(let c=0;c<R_;c++)if(!M_.test(l[c+1])&&M_.test(l[c])){l=l.slice(c);break}}if(o!=s){for(let c=l.length-1;c>l.length-R_;c--)if(!M_.test(l[c-1])&&M_.test(l[c])){l=l.slice(0,c);break}}return Yt.announce.of(`${e.state.phrase("current match")}. ${l} ${e.state.phrase("on line")} ${r.number}.`)}const ylt=Yt.baseTheme({".cm-panel.cm-search":{padding:"2px 6px 4px",position:"relative","& [name=close]":{position:"absolute",top:"0",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",padding:0,margin:0},"& input, & button, & label":{margin:".2em .6em .2em 0"},"& input[type=checkbox]":{marginRight:".2em"},"& label":{fontSize:"80%",whiteSpace:"pre"}},"&light .cm-searchMatch":{backgroundColor:"#ffff0054"},"&dark .cm-searchMatch":{backgroundColor:"#00ffff8a"},"&light .cm-searchMatch-selected":{backgroundColor:"#ff6a0054"},"&dark .cm-searchMatch-selected":{backgroundColor:"#ff00ff8a"}}),vlt=[Wp,Bg.low(hlt),ylt];class hee{constructor(t,n,r){this.from=t,this.to=n,this.diagnostic=r}}class Ax{constructor(t,n,r){this.diagnostics=t,this.panel=n,this.selected=r}static init(t,n,r){let s=r.facet(FN).markerFilter;s&&(t=s(t,r));let a=t.slice().sort((g,b)=>g.from-b.from||g.to-b.to),o=new tm,l=[],c=0,u=r.doc.iter(),d=0,h=r.doc.length;for(let g=0;;){let b=g==a.length?null:a[g];if(!b&&!l.length)break;let v,j;if(l.length)v=c,j=l.reduce((N,S)=>Math.min(N,S.to),b&&b.from>v?b.from:1e8);else{if(v=b.from,v>h)break;j=b.to,l.push(b),g++}for(;g<a.length;){let N=a[g];if(N.from==v&&(N.to>N.from||N.to==v))l.push(N),g++,j=Math.min(N.to,j);else{j=Math.min(N.from,j);break}}j=Math.min(j,h);let k=!1;if(l.some(N=>N.from==v&&(N.to==j||j==h))&&(k=v==j,!k&&j-v<10)){let N=v-(d+u.value.length);N>0&&(u.next(N),d=v);for(let S=v;;){if(S>=j){k=!0;break}if(!u.lineBreak&&d+u.value.length>S)break;S=d+u.value.length,d+=u.value.length,u.next()}}let w=Mlt(l);if(k)o.add(v,v,En.widget({widget:new Elt(w),diagnostics:l.slice()}));else{let N=l.reduce((S,A)=>A.markClass?S+" "+A.markClass:S,"");o.add(v,j,En.mark({class:"cm-lintRange cm-lintRange-"+w+N,diagnostics:l.slice(),inclusiveEnd:l.some(S=>S.to>j)}))}if(c=j,c==h)break;for(let N=0;N<l.length;N++)l[N].to<=c&&l.splice(N--,1)}let m=o.finish();return new Ax(m,n,Cg(m))}}function Cg(e,t=null,n=0){let r=null;return e.between(n,1e9,(s,a,{spec:o})=>{if(!(t&&o.diagnostics.indexOf(t)<0))if(!r)r=new hee(s,a,t||o.diagnostics[0]);else{if(o.diagnostics.indexOf(r.diagnostic)<0)return!1;r=new hee(r.from,a,r.diagnostic)}}),r}function wlt(e,t){let n=t.pos,r=t.end||n,s=e.state.facet(FN).hideOn(e,n,r);if(s!=null)return s;let a=e.startState.doc.lineAt(t.pos);return!!(e.effects.some(o=>o.is(hve))||e.changes.touchesRange(a.from,Math.max(a.to,r)))}function klt(e,t){return e.field(Nc,!1)?t:t.concat(Yn.appendConfig.of(Olt))}const hve=Yn.define(),mU=Yn.define(),mve=Yn.define(),Nc=ko.define({create(){return new Ax(En.none,null,null)},update(e,t){if(t.docChanged&&e.diagnostics.size){let n=e.diagnostics.map(t.changes),r=null,s=e.panel;if(e.selected){let a=t.changes.mapPos(e.selected.from,1);r=Cg(n,e.selected.diagnostic,a)||Cg(n,null,a)}!n.size&&s&&t.state.facet(FN).autoPanel&&(s=null),e=new Ax(n,s,r)}for(let n of t.effects)if(n.is(hve)){let r=t.state.facet(FN).autoPanel?n.value.length?zN.open:null:e.panel;e=Ax.init(n.value,r,t.state)}else n.is(mU)?e=new Ax(e.diagnostics,n.value?zN.open:null,e.selected):n.is(mve)&&(e=new Ax(e.diagnostics,e.panel,n.value));return e},provide:e=>[TN.from(e,t=>t.panel),Yt.decorations.from(e,t=>t.diagnostics)]}),jlt=En.mark({class:"cm-lintRange cm-lintRange-active"});function Nlt(e,t,n){let{diagnostics:r}=e.state.field(Nc),s,a=-1,o=-1;r.between(t-(n<0?1:0),t+(n>0?1:0),(c,u,{spec:d})=>{if(t>=c&&t<=u&&(c==u||(t>c||n>0)&&(t<u||n<0)))return s=d.diagnostics,a=c,o=u,!1});let l=e.state.facet(FN).tooltipFilter;return s&&l&&(s=l(s,e.state)),s?{pos:a,end:o,above:e.state.doc.lineAt(a).to<o,create(){return{dom:Clt(e,s)}}}:null}function Clt(e,t){return Es("ul",{class:"cm-tooltip-lint"},t.map(n=>gve(e,n,!1)))}const Slt=e=>{let t=e.state.field(Nc,!1);(!t||!t.panel)&&e.dispatch({effects:klt(e.state,[mU.of(!0)])});let n=BB(e,zN.open);return n&&n.dom.querySelector(".cm-panel-lint ul").focus(),!0},mee=e=>{let t=e.state.field(Nc,!1);return!t||!t.panel?!1:(e.dispatch({effects:mU.of(!1)}),!0)},_lt=e=>{let t=e.state.field(Nc,!1);if(!t)return!1;let n=e.state.selection.main,r=Cg(t.diagnostics,null,n.to+1);return!r&&(r=Cg(t.diagnostics,null,0),!r||r.from==n.from&&r.to==n.to)?!1:(e.dispatch({selection:{anchor:r.from,head:r.to},scrollIntoView:!0}),!0)},Alt=[{key:"Mod-Shift-m",run:Slt,preventDefault:!0},{key:"F8",run:_lt}],FN=Zt.define({combine(e){return{sources:e.map(t=>t.source).filter(t=>t!=null),...Pf(e.map(t=>t.config),{delay:750,markerFilter:null,tooltipFilter:null,needsRefresh:null,hideOn:()=>null},{delay:Math.max,markerFilter:pee,tooltipFilter:pee,needsRefresh:(t,n)=>t?n?r=>t(r)||n(r):t:n,hideOn:(t,n)=>t?n?(r,s,a)=>t(r,s,a)||n(r,s,a):t:n,autoPanel:(t,n)=>t||n})}}});function pee(e,t){return e?t?(n,r)=>t(e(n,r),r):e:t}function pve(e){let t=[];if(e)e:for(let{name:n}of e){for(let r=0;r<n.length;r++){let s=n[r];if(/[a-zA-Z]/.test(s)&&!t.some(a=>a.toLowerCase()==s.toLowerCase())){t.push(s);continue e}}t.push("")}return t}function gve(e,t,n){var r;let s=n?pve(t.actions):[];return Es("li",{class:"cm-diagnostic cm-diagnostic-"+t.severity},Es("span",{class:"cm-diagnosticText"},t.renderMessage?t.renderMessage(e):t.message),(r=t.actions)===null||r===void 0?void 0:r.map((a,o)=>{let l=!1,c=g=>{if(g.preventDefault(),l)return;l=!0;let b=Cg(e.state.field(Nc).diagnostics,t);b&&a.apply(e,b.from,b.to)},{name:u}=a,d=s[o]?u.indexOf(s[o]):-1,h=d<0?u:[u.slice(0,d),Es("u",u.slice(d,d+1)),u.slice(d+1)],m=a.markClass?" "+a.markClass:"";return Es("button",{type:"button",class:"cm-diagnosticAction"+m,onclick:c,onmousedown:c,"aria-label":` Action: ${u}${d<0?"":` (access key "${s[o]})"`}.`},h)}),t.source&&Es("div",{class:"cm-diagnosticSource"},t.source))}class Elt extends Lf{constructor(t){super(),this.sev=t}eq(t){return t.sev==this.sev}toDOM(){return Es("span",{class:"cm-lintPoint cm-lintPoint-"+this.sev})}}class gee{constructor(t,n){this.diagnostic=n,this.id="item_"+Math.floor(Math.random()*4294967295).toString(16),this.dom=gve(t,n,!0),this.dom.id=this.id,this.dom.setAttribute("role","option")}}class zN{constructor(t){this.view=t,this.items=[];let n=s=>{if(!(s.ctrlKey||s.altKey||s.metaKey)){if(s.keyCode==27)mee(this.view),this.view.focus();else if(s.keyCode==38||s.keyCode==33)this.moveSelection((this.selectedIndex-1+this.items.length)%this.items.length);else if(s.keyCode==40||s.keyCode==34)this.moveSelection((this.selectedIndex+1)%this.items.length);else if(s.keyCode==36)this.moveSelection(0);else if(s.keyCode==35)this.moveSelection(this.items.length-1);else if(s.keyCode==13)this.view.focus();else if(s.keyCode>=65&&s.keyCode<=90&&this.selectedIndex>=0){let{diagnostic:a}=this.items[this.selectedIndex],o=pve(a.actions);for(let l=0;l<o.length;l++)if(o[l].toUpperCase().charCodeAt(0)==s.keyCode){let c=Cg(this.view.state.field(Nc).diagnostics,a);c&&a.actions[l].apply(t,c.from,c.to)}}else return;s.preventDefault()}},r=s=>{for(let a=0;a<this.items.length;a++)this.items[a].dom.contains(s.target)&&this.moveSelection(a)};this.list=Es("ul",{tabIndex:0,role:"listbox","aria-label":this.view.state.phrase("Diagnostics"),onkeydown:n,onclick:r}),this.dom=Es("div",{class:"cm-panel-lint"},this.list,Es("button",{type:"button",name:"close","aria-label":this.view.state.phrase("close"),onclick:()=>mee(this.view)},"×")),this.update()}get selectedIndex(){let t=this.view.state.field(Nc).selected;if(!t)return-1;for(let n=0;n<this.items.length;n++)if(this.items[n].diagnostic==t.diagnostic)return n;return-1}update(){let{diagnostics:t,selected:n}=this.view.state.field(Nc),r=0,s=!1,a=null,o=new Set;for(t.between(0,this.view.state.doc.length,(l,c,{spec:u})=>{for(let d of u.diagnostics){if(o.has(d))continue;o.add(d);let h=-1,m;for(let g=r;g<this.items.length;g++)if(this.items[g].diagnostic==d){h=g;break}h<0?(m=new gee(this.view,d),this.items.splice(r,0,m),s=!0):(m=this.items[h],h>r&&(this.items.splice(r,h-r),s=!0)),n&&m.diagnostic==n.diagnostic?m.dom.hasAttribute("aria-selected")||(m.dom.setAttribute("aria-selected","true"),a=m):m.dom.hasAttribute("aria-selected")&&m.dom.removeAttribute("aria-selected"),r++}});r<this.items.length&&!(this.items.length==1&&this.items[0].diagnostic.from<0);)s=!0,this.items.pop();this.items.length==0&&(this.items.push(new gee(this.view,{from:-1,to:-1,severity:"info",message:this.view.state.phrase("No diagnostics")})),s=!0),a?(this.list.setAttribute("aria-activedescendant",a.id),this.view.requestMeasure({key:this,read:()=>({sel:a.dom.getBoundingClientRect(),panel:this.list.getBoundingClientRect()}),write:({sel:l,panel:c})=>{let u=c.height/this.list.offsetHeight;l.top<c.top?this.list.scrollTop-=(c.top-l.top)/u:l.bottom>c.bottom&&(this.list.scrollTop+=(l.bottom-c.bottom)/u)}})):this.selectedIndex<0&&this.list.removeAttribute("aria-activedescendant"),s&&this.sync()}sync(){let t=this.list.firstChild;function n(){let r=t;t=r.nextSibling,r.remove()}for(let r of this.items)if(r.dom.parentNode==this.list){for(;t!=r.dom;)n();t=r.dom.nextSibling}else this.list.insertBefore(r.dom,t);for(;t;)n()}moveSelection(t){if(this.selectedIndex<0)return;let n=this.view.state.field(Nc),r=Cg(n.diagnostics,this.items[t].diagnostic);r&&this.view.dispatch({selection:{anchor:r.from,head:r.to},scrollIntoView:!0,effects:mve.of(r)})}static open(t){return new zN(t)}}function Tlt(e,t='viewBox="0 0 40 40"'){return`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" ${t}>${encodeURIComponent(e)}</svg>')`}function O_(e){return Tlt(`<path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="${e}" fill="none" stroke-width=".7"/>`,'width="6" height="3"')}const Ilt=Yt.baseTheme({".cm-diagnostic":{padding:"3px 6px 3px 8px",marginLeft:"-1px",display:"block",whiteSpace:"pre-wrap"},".cm-diagnostic-error":{borderLeft:"5px solid #d11"},".cm-diagnostic-warning":{borderLeft:"5px solid orange"},".cm-diagnostic-info":{borderLeft:"5px solid #999"},".cm-diagnostic-hint":{borderLeft:"5px solid #66d"},".cm-diagnosticAction":{font:"inherit",border:"none",padding:"2px 4px",backgroundColor:"#444",color:"white",borderRadius:"3px",marginLeft:"8px",cursor:"pointer"},".cm-diagnosticSource":{fontSize:"70%",opacity:.7},".cm-lintRange":{backgroundPosition:"left bottom",backgroundRepeat:"repeat-x",paddingBottom:"0.7px"},".cm-lintRange-error":{backgroundImage:O_("#d11")},".cm-lintRange-warning":{backgroundImage:O_("orange")},".cm-lintRange-info":{backgroundImage:O_("#999")},".cm-lintRange-hint":{backgroundImage:O_("#66d")},".cm-lintRange-active":{backgroundColor:"#ffdd9980"},".cm-tooltip-lint":{padding:0,margin:0},".cm-lintPoint":{position:"relative","&:after":{content:'""',position:"absolute",bottom:0,left:"-2px",borderLeft:"3px solid transparent",borderRight:"3px solid transparent",borderBottom:"4px solid #d11"}},".cm-lintPoint-warning":{"&:after":{borderBottomColor:"orange"}},".cm-lintPoint-info":{"&:after":{borderBottomColor:"#999"}},".cm-lintPoint-hint":{"&:after":{borderBottomColor:"#66d"}},".cm-panel.cm-panel-lint":{position:"relative","& ul":{maxHeight:"100px",overflowY:"auto","& [aria-selected]":{backgroundColor:"#ddd","& u":{textDecoration:"underline"}},"&:focus [aria-selected]":{background_fallback:"#bdf",backgroundColor:"Highlight",color_fallback:"white",color:"HighlightText"},"& u":{textDecoration:"none"},padding:0,margin:0},"& [name=close]":{position:"absolute",top:"0",right:"2px",background:"inherit",border:"none",font:"inherit",padding:0,margin:0}},"&dark .cm-lintRange-active":{backgroundColor:"#86714a80"},"&dark .cm-panel.cm-panel-lint ul":{"& [aria-selected]":{backgroundColor:"#2e343e"}}});function Rlt(e){return e=="error"?4:e=="warning"?3:e=="info"?2:1}function Mlt(e){let t="hint",n=1;for(let r of e){let s=Rlt(r.severity);s>n&&(n=s,t=r.severity)}return t}const Olt=[Nc,Yt.decorations.compute([Nc],e=>{let{selected:t,panel:n}=e.field(Nc);return!t||!n||t.from==t.to?En.none:En.set([jlt.range(t.from,t.to)])}),Grt(Nlt,{hideOn:wlt}),Ilt],Dlt=[Fye(),cst(),Crt(),Rat(),iit(),mrt(),yrt(),Ur.allowMultipleSelections.of(!0),Hst(),i0e(cit,{fallback:!0}),git(),uat(),wat(),Lrt(),zrt(),Irt(),Yot(),GC.of([...mat,...Oot,...xlt,...Bat,...tit,...N0e,...Alt])],Plt=se.forwardRef(({title:e,children:t},n)=>{const r=Cf(cy);return se.createElement(w7,{delayDuration:100},se.createElement(k7,null,se.createElement(j7,{ref:n,asChild:!0},se.createElement("span",{className:Tt.tooltipTrigger},t)),se.createElement(N7,{container:r==null?void 0:r.current},se.createElement(C7,{className:Ts(Tt.tooltipContent),sideOffset:10},e))))}),Llt=se.forwardRef(({children:e,className:t,...n},r)=>se.createElement(Jle,{...n,ref:r,className:Ts(t,Tt.selectItem)},se.createElement(Zle,null,e))),$lt=({title:e,placeholder:t,className:n})=>{const[r,s]=gd(cd,fm);return se.createElement(Plt,{title:e},se.createElement(Hle,{"aria-label":t,className:Ts(Tt.selectTrigger,n),"data-toolbar-item":!0,disabled:r},se.createElement(Kle,{placeholder:t}),se.createElement(Wle,{className:Tt.selectDropdownArrow},s("arrow_drop_down"))))},Flt=({children:e,className:t=Tt.selectContainer})=>{const n=Cf(cy);return se.createElement(Gle,{container:n==null?void 0:n.current},se.createElement(Qle,{className:Ts(t,"mdxeditor-select-content"),onCloseAutoFocus:r=>{r.preventDefault()},position:"popper"},se.createElement(Yle,{"data-editor-dropdown":!0,style:{maxHeight:"var(--radix-select-content-available-height)"}},e)))},zlt=e=>se.createElement(Vle,{value:e.value||"",onValueChange:e.onChange,disabled:e.disabled},se.createElement($lt,{title:e.triggerTitle,placeholder:e.placeholder}),se.createElement(Flt,null,e.items.map((t,n)=>t==="separator"?se.createElement(LIe,{key:n}):se.createElement(Llt,{key:n,value:t.value},t.label)))),xve=({language:e,nodeKey:t,code:n,focusEmitter:r})=>{const s=hm(),{parentEditor:a,lexicalNode:o}=S6(),[l,c,u,d,h]=gd(cd,N$,C$,fm,j$),m=Pot(t,"codeblock",e,r),{setCode:g}=S6(),b=se.useRef(null),v=se.useRef(null),j=se.useRef(g);return j.current=g,m.current={getCodemirror:()=>b.current},se.useEffect(()=>{const k=v.current;return(async()=>{const w=[...c,Dlt,Hot,Fye(),GC.of([Dot]),Yt.lineWrapping,Yt.updateListener.of(({state:N})=>{j.current(N.doc.toString())}),Yt.domEventHandlers({focus:()=>{a.update(()=>{wu(null)})}})];if(l&&w.push(Ur.readOnly.of(!0)),e!==""&&u){const N=Lot.find(S=>S.name===e||S.alias.includes(e)||S.extensions.includes(e));if(N)try{const S=await N.load();w.push(S.extension)}catch{console.warn("failed to load language support for",e)}}k.innerHTML="",b.current=new Yt({parent:k,state:Ur.create({doc:n,extensions:w})}),k.addEventListener("keydown",xee)})(),()=>{var w;(w=b.current)==null||w.destroy(),b.current=null,k.removeEventListener("keydown",xee)}},[l,e,...c]),se.createElement("div",{className:Tt.codeMirrorWrapper},se.createElement("div",{className:Tt.codeMirrorToolbar},se.createElement(zlt,{disabled:l,value:h.keyMap[e]??e,onChange:k=>{a.update(()=>{o.setLanguage(k===w$?"":k),setTimeout(()=>{a.update(()=>{o.getLatest().select()})})})},triggerTitle:s("codeBlock.selectLanguage","Select code block language"),placeholder:s("codeBlock.inlineLanguage","Language"),items:h.items}),se.createElement("button",{className:Tt.iconButton,type:"button",disabled:l,title:s("codeblock.delete","Delete code block"),onClick:k=>{k.preventDefault(),a.update(()=>{o.remove()})}},d("delete_small"))),se.createElement("div",{ref:v}))};function xee(e){e.stopPropagation()}const w$="__EMPTY_VALUE__";function k$(e){var t;const n=[],r={};if(Array.isArray(e))for(const s of e){const a=((t=s.alias)==null?void 0:t[0])??s.name.toLowerCase();if(n.push({value:a,label:s.name}),r[a]=a,s.alias)for(const o of s.alias)r[o]=a;if(s.extensions)for(const o of s.extensions)r[o]=a;r[s.name.toLowerCase()]=a}else{const s={};for(const[a,o]of Object.entries(e))o in s||(s[o]=a,n.push({value:a||w$,label:o})),r[a]=s[o]||w$}return{items:n,keyMap:r}}const j$=en(k$({js:"JavaScript",ts:"TypeScript",tsx:"TypeScript (React)",jsx:"JavaScript (React)",css:"CSS"})),Blt=Ki(e=>{e.link(e.pipe(Blt,dg(({language:t,code:n})=>({code:n,language:t,meta:""}))),hbe)}),N$=en([]),C$=en(!0),Ult=Go({update(e,t){e.pubIn({[j$]:k$((t==null?void 0:t.codeBlockLanguages)??{}),[N$]:(t==null?void 0:t.codeMirrorExtensions)??[],[C$]:(t==null?void 0:t.autoLoadLanguageSupport)??!0})},init(e,t){const n=k$((t==null?void 0:t.codeBlockLanguages)??{});e.pubIn({[j$]:n,[N$]:(t==null?void 0:t.codeMirrorExtensions)??[],[Zet]:qlt(n),[C$]:(t==null?void 0:t.autoLoadLanguageSupport)??!0})}});function qlt(e){return{match(t,n){return Object.hasOwn(e.keyMap,t??"")&&!n},priority:1,Editor:xve}}function Vlt({url:e,title:t,text:n,onSubmit:r,onCancel:s,linkAutocompleteSuggestions:a,showLinkTitleField:o,showAnchorTextField:l}){const{register:c,handleSubmit:u,control:d,setValue:h,reset:m}=Uxe({values:{url:e,title:t,text:n}}),g=hm();return se.createElement("form",{onSubmit:b=>{u(r)(b),b.stopPropagation(),b.preventDefault()},onReset:b=>{b.stopPropagation(),s()},onKeyDown:b=>{b.key==="Escape"&&(b.stopPropagation(),s())},className:Ts(Tt.multiFieldForm,Tt.linkDialogEditForm)},se.createElement("div",{className:Tt.formField},se.createElement("label",{htmlFor:"link-url"},g("createLink.url","URL")),se.createElement(abe,{register:c,initialInputValue:e,inputName:"url",suggestions:a,setValue:h,control:d,placeholder:g("createLink.urlPlaceholder","Select or paste an URL"),autofocus:!0})),l?se.createElement("div",{className:Tt.formField},se.createElement("label",{htmlFor:"link-text",title:g("createLink.textTooltip","The text to be displayed for the link")},g("createLink.text","Anchor text")),se.createElement("input",{id:"link-text",className:Tt.textInput,size:40,...c("text")})):null,o?se.createElement("div",{className:Tt.formField},se.createElement("label",{htmlFor:"link-title",title:g("createLink.titleTooltip","The link's title attribute, shown on hover")},g("createLink.title","Link title")),se.createElement("input",{id:"link-title",className:Tt.textInput,size:40,...c("title")})):null,se.createElement("div",{style:{display:"flex",justifyContent:"flex-end",gap:"var(--spacing-2)"}},se.createElement("button",{type:"submit",title:g("createLink.saveTooltip","Set URL"),"aria-label":g("createLink.saveTooltip","Set URL"),className:Ts(Tt.primaryButton)},g("dialogControls.save","Save")),se.createElement("button",{type:"reset",title:g("createLink.cancelTooltip","Cancel change"),"aria-label":g("createLink.cancelTooltip","Cancel change"),className:Ts(Tt.secondaryButton)},g("dialogControls.cancel","Cancel"))))}const Hlt=()=>{const[e,t,n,r,s,a,o]=gd(cy,fi,fm,Ol,Nve,Cve,_ve),l=kc(bve),c=kc(yve),u=kc(vve),d=kc(wve),h=kc(kve);se.useEffect(()=>{const k=()=>{t==null||t.getEditorState().read(()=>{l(!0)})};return window.addEventListener("resize",k),window.addEventListener("scroll",k),()=>{window.removeEventListener("resize",k),window.removeEventListener("scroll",k)}},[t,l]);const[m,g]=se.useState(!1),b=hm();if(r.type==="inactive")return null;const v=r.rectangle,j=r.type==="preview"&&r.url.startsWith("http");return se.createElement(g3,{open:!0},se.createElement(nle,{"data-visible":r.type==="edit",className:Tt.linkDialogAnchor,style:{top:`${v.top}px`,left:`${v.left}px`,width:`${v.width}px`,height:`${v.height}px`}}),se.createElement(x3,{container:e==null?void 0:e.current},se.createElement(rle,{className:Ts(Tt.linkDialogPopoverContent),sideOffset:5,onOpenAutoFocus:k=>{k.preventDefault()},key:r.linkNodeKey},r.type==="edit"&&se.createElement(Vlt,{url:r.url,title:r.title,text:r.text,onSubmit:c,onCancel:u.bind(null),linkAutocompleteSuggestions:s,showLinkTitleField:o,showAnchorTextField:r.withAnchorText}),r.type==="preview"&&se.createElement(se.Fragment,null,se.createElement("a",{className:Tt.linkDialogPreviewAnchor,href:r.url,...j?{target:"_blank",rel:"noreferrer"}:{},onClick:k=>{a!==null&&(k.preventDefault(),a(r.url))},title:j?b("linkPreview.open","Open {{url}} in new window",{url:r.url}):r.url},se.createElement("span",null,r.url),j&&n("open_in_new")),se.createElement(CD,{onClick:()=>{d()},title:b("linkPreview.edit","Edit link URL"),"aria-label":b("linkPreview.edit","Edit link URL")},n("edit")),se.createElement(w7,null,se.createElement(k7,{open:m},se.createElement(j7,{asChild:!0},se.createElement(CD,{title:b("linkPreview.copyToClipboard","Copy to clipboard"),"aria-label":b("linkPreview.copyToClipboard","Copy to clipboard"),onClick:()=>{window.navigator.clipboard.writeText(r.url).then(()=>{g(!0),setTimeout(()=>{g(!1)},1e3)})}},n(m?"check":"content_copy"))),se.createElement(N7,{container:e==null?void 0:e.current},se.createElement(C7,{className:Ts(Tt.tooltipContent),sideOffset:5},b("linkPreview.copied","Copied!"),se.createElement($ce,null))))),se.createElement(CD,{title:b("linkPreview.remove","Remove link"),"aria-label":b("linkPreview.remove","Remove link"),onClick:()=>{h()}},n("link_off"))),se.createElement(c7,{className:Tt.popoverArrow}))))},CD=se.forwardRef(({className:e,...t},n)=>se.createElement("button",{className:Ts(Tt.actionButton,e),ref:n,...t}));function S$(e){if(!e)return null;const t=jJe(e);if(t===null)return null;const n=t.getParent();return ll(n)?n:ll(t)?t:null}const bve=Ki(),Ol=en({type:"inactive"},e=>{e.pub(bN,t=>t.registerCommand(dI,()=>e.getValue(Ol).type==="preview"?(e.pub(Ol,{type:"inactive"}),!0):!1,Gs)),e.sub(e.pipe(yN),t=>{t!=="rich-text"&&e.pub(Ol,{type:"inactive"})}),e.pub(bN,t=>t.registerCommand(epe,n=>{if(n.key==="k"&&(dxe?n.metaKey:n.ctrlKey)&&!e.getValue(cd)){const r=nn();return un(r)?(e.pub(jve),n.stopPropagation(),n.preventDefault(),!0):!1}return!1},hN)),e.sub(e.pipe(wve,vi(Ol,fi)),([,t,n])=>{if(t.type==="preview")setTimeout(()=>{n==null||n.getEditorState().read(()=>{const r=pf(t.linkNodeKey),s=ll(r)?r.getTextContent().length>0&&r.getChildrenSize()<=1:!1,a=s&&r?r.getTextContent():"";e.pub(Ol,{type:"edit",initialUrl:t.url,url:t.url,title:t.title,text:a,withAnchorText:s,linkNodeKey:t.linkNodeKey,rectangle:t.rectangle})})});else throw new Error("Cannot switch to edit mode when not in preview mode")}),e.sub(e.pipe(yve,vi(fi,Ol,zv)),([t,n,r,s])=>{var a,o,l;const c=((a=t.text)==null?void 0:a.trim())??"",u=((o=t.url)==null?void 0:o.trim())??"",d=((l=t.title)==null?void 0:l.trim())??"";if(u!==""){if(s!=null&&s.isCollapsed()){const h=c||d||u;n==null||n.update(()=>{const m=S$(s);if(m)if(zu(m)){const g=em(u,{title:d});g.append(od(c)),m.replace(g),g.select()}else m.setURL(u),m.setTitle(d),bee(m.getFirstChild(),c);else{const g=em(u,{title:d});g.append(od(h)),O1([g]),g.select()}},{discrete:!0})}else n==null||n.update(()=>{bee(s==null?void 0:s.anchor.getNode(),c)}),n==null||n.dispatchCommand(Bv,{url:u,title:d});e.pub(Ol,{type:"preview",linkNodeKey:r.linkNodeKey,rectangle:r.rectangle,title:d,url:u})}else r.type==="edit"&&r.initialUrl!==""&&(n==null||n.dispatchCommand(Bv,null)),e.pub(Ol,{type:"inactive"})}),e.link(e.pipe(vve,vi(Ol,fi),dg(([,t,n])=>{if(t.type==="edit")return n==null||n.focus(),t.initialUrl===""?{type:"inactive"}:{type:"preview",url:t.initialUrl,linkNodeKey:t.linkNodeKey,rectangle:t.rectangle};throw new Error("Cannot cancel edit when not in edit mode")})),Ol),e.link(e.pipe(e.combine(zv,bve),vi(fi,Ol,cd),dg(([[t],n,r,s])=>{if(un(t)&&n&&!s){const a=S$(t);if(!t.isCollapsed())return{type:"inactive"};if(a){const o=lxe(n);return o?{type:"preview",url:a.getURL(),linkNodeKey:a.getKey(),title:a.getTitle(),rectangle:o}:{type:"inactive"}}else return{type:"inactive"}}else return{type:"inactive"}})),Ol)}),yve=Ki(),vve=Pg();Pg();const wve=Pg(),kve=Pg(e=>{e.sub(e.pipe(kve,vi(fi)),([,t])=>{t==null||t.dispatchCommand(Bv,null)})}),jve=Pg(e=>{e.sub(e.pipe(jve,vi(zv,fi),EC(([,t])=>un(t))),([,t,n])=>{n==null||n.focus(()=>{setTimeout(()=>{n.getEditorState().read(()=>{const r=S$(t),s=lxe(n),a=(r==null?void 0:r.getURL())??"",o=(r==null?void 0:r.getURL())??"",l=(r==null?void 0:r.getTitle())??"",c=(r==null?void 0:r.getKey())??"",u=r?r.getTextContent().length>0&&r.getChildrenSize()<=1:!!(t!=null&&t.isCollapsed()),d=u&&r?r.getTextContent():"";e.pub(Ol,{type:"edit",initialUrl:a,url:o,title:l,text:d,withAnchorText:u,linkNodeKey:c,rectangle:s})})})})})}),Nve=en([]),Cve=en(null),Sve=en(null,e=>{e.pub(bN,t=>{function n(r){const[s,a]=e.getValues([cd,Sve]);!s||a===null||t.update(()=>{const o=Bb(r.target);if(o!==null){const l=Ju(o,c=>c instanceof vd);l!==null&&a(r,l,l.getURL())}})}return t.registerRootListener((r,s)=>{r&&r.addEventListener("click",n),s&&s.removeEventListener("click",n)})})});function bee(e,t){ns(e)&&t&&(e.setTextContent(t),e.selectStart())}const _ve=en(!0),Klt=Go({init(e,t){e.pub(uy,(t==null?void 0:t.LinkDialog)??Hlt),e.pub(Cve,(t==null?void 0:t.onClickLinkCallback)??null),e.pub(Sve,(t==null?void 0:t.onReadOnlyClickLinkCallback)??null),e.pub(_ve,(t==null?void 0:t.showLinkTitleField)??!0)},update(e,t={}){e.pub(Nve,t.linkAutocompleteSuggestions??[])}});var SD={exports:{}},yee;function Wlt(){return yee||(yee=1,(function(e){var t=typeof window<"u"?window:typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope?self:{};/**
1284
1284
  * Prism: Lightweight, robust, elegant syntax highlighting
1285
1285
  *
@@ -1344,7 +1344,7 @@ You are agent {{ agent.name }}. Your role is {{ agent.role }}...`,contentClassNa
1344
1344
  `}),n.push(e[r]);return t&&e.length>0&&n.push({type:"text",value:`
1345
1345
  `}),n}function Kte(e){let t=0,n=e.charCodeAt(t);for(;n===9||n===32;)t++,n=e.charCodeAt(t);return e.slice(t)}function Wte(e,t){const n=hbt(e,t),r=n.one(e,void 0),s=dbt(n),a=Array.isArray(r)?{type:"root",children:r}:r||{type:"root",children:[]};return s&&a.children.push({type:"text",value:`
1346
1346
  `},s),a}function bbt(e,t){return e&&"run"in e?async function(n,r){const s=Wte(n,{file:r,...t});await e.run(s,r)}:function(n,r){return Wte(n,{file:r,...e||t})}}function Gte(e){if(e)throw e}var eP,Qte;function ybt(){if(Qte)return eP;Qte=1;var e=Object.prototype.hasOwnProperty,t=Object.prototype.toString,n=Object.defineProperty,r=Object.getOwnPropertyDescriptor,s=function(u){return typeof Array.isArray=="function"?Array.isArray(u):t.call(u)==="[object Array]"},a=function(u){if(!u||t.call(u)!=="[object Object]")return!1;var d=e.call(u,"constructor"),h=u.constructor&&u.constructor.prototype&&e.call(u.constructor.prototype,"isPrototypeOf");if(u.constructor&&!d&&!h)return!1;var m;for(m in u);return typeof m>"u"||e.call(u,m)},o=function(u,d){n&&d.name==="__proto__"?n(u,d.name,{enumerable:!0,configurable:!0,value:d.newValue,writable:!0}):u[d.name]=d.newValue},l=function(u,d){if(d==="__proto__")if(e.call(u,d)){if(r)return r(u,d).value}else return;return u[d]};return eP=function c(){var u,d,h,m,g,b,v=arguments[0],j=1,k=arguments.length,w=!1;for(typeof v=="boolean"&&(w=v,v=arguments[1]||{},j=2),(v==null||typeof v!="object"&&typeof v!="function")&&(v={});j<k;++j)if(u=arguments[j],u!=null)for(d in u)h=l(v,d),m=l(u,d),v!==m&&(w&&m&&(a(m)||(g=s(m)))?(g?(g=!1,b=h&&s(h)?h:[]):b=h&&a(h)?h:{},o(v,{name:d,newValue:c(w,b,m)})):typeof m<"u"&&o(v,{name:d,newValue:m}));return v},eP}var vbt=ybt();const tP=s1(vbt);function Q$(e){if(typeof e!="object"||e===null)return!1;const t=Object.getPrototypeOf(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Symbol.toStringTag in e)&&!(Symbol.iterator in e)}function wbt(){const e=[],t={run:n,use:r};return t;function n(...s){let a=-1;const o=s.pop();if(typeof o!="function")throw new TypeError("Expected function as last argument, not "+o);l(null,...s);function l(c,...u){const d=e[++a];let h=-1;if(c){o(c);return}for(;++h<s.length;)(u[h]===null||u[h]===void 0)&&(u[h]=s[h]);s=u,d?kbt(d,l)(...u):o(null,...u)}}function r(s){if(typeof s!="function")throw new TypeError("Expected `middelware` to be a function, not "+s);return e.push(s),t}}function kbt(e,t){let n;return r;function r(...o){const l=e.length>o.length;let c;l&&o.push(s);try{c=e.apply(this,o)}catch(u){const d=u;if(l&&n)throw d;return s(d)}l||(c&&c.then&&typeof c.then=="function"?c.then(a,s):c instanceof Error?s(c):a(c))}function s(o,...l){n||(n=!0,t(o,...l))}function a(o){s(null,o)}}const qd={basename:jbt,dirname:Nbt,extname:Cbt,join:Sbt,sep:"/"};function jbt(e,t){if(t!==void 0&&typeof t!="string")throw new TypeError('"ext" argument must be a string');uS(e);let n=0,r=-1,s=e.length,a;if(t===void 0||t.length===0||t.length>e.length){for(;s--;)if(e.codePointAt(s)===47){if(a){n=s+1;break}}else r<0&&(a=!0,r=s+1);return r<0?"":e.slice(n,r)}if(t===e)return"";let o=-1,l=t.length-1;for(;s--;)if(e.codePointAt(s)===47){if(a){n=s+1;break}}else o<0&&(a=!0,o=s+1),l>-1&&(e.codePointAt(s)===t.codePointAt(l--)?l<0&&(r=s):(l=-1,r=o));return n===r?r=o:r<0&&(r=e.length),e.slice(n,r)}function Nbt(e){if(uS(e),e.length===0)return".";let t=-1,n=e.length,r;for(;--n;)if(e.codePointAt(n)===47){if(r){t=n;break}}else r||(r=!0);return t<0?e.codePointAt(0)===47?"/":".":t===1&&e.codePointAt(0)===47?"//":e.slice(0,t)}function Cbt(e){uS(e);let t=e.length,n=-1,r=0,s=-1,a=0,o;for(;t--;){const l=e.codePointAt(t);if(l===47){if(o){r=t+1;break}continue}n<0&&(o=!0,n=t+1),l===46?s<0?s=t:a!==1&&(a=1):s>-1&&(a=-1)}return s<0||n<0||a===0||a===1&&s===n-1&&s===r+1?"":e.slice(s,n)}function Sbt(...e){let t=-1,n;for(;++t<e.length;)uS(e[t]),e[t]&&(n=n===void 0?e[t]:n+"/"+e[t]);return n===void 0?".":_bt(n)}function _bt(e){uS(e);const t=e.codePointAt(0)===47;let n=Abt(e,!t);return n.length===0&&!t&&(n="."),n.length>0&&e.codePointAt(e.length-1)===47&&(n+="/"),t?"/"+n:n}function Abt(e,t){let n="",r=0,s=-1,a=0,o=-1,l,c;for(;++o<=e.length;){if(o<e.length)l=e.codePointAt(o);else{if(l===47)break;l=47}if(l===47){if(!(s===o-1||a===1))if(s!==o-1&&a===2){if(n.length<2||r!==2||n.codePointAt(n.length-1)!==46||n.codePointAt(n.length-2)!==46){if(n.length>2){if(c=n.lastIndexOf("/"),c!==n.length-1){c<0?(n="",r=0):(n=n.slice(0,c),r=n.length-1-n.lastIndexOf("/")),s=o,a=0;continue}}else if(n.length>0){n="",r=0,s=o,a=0;continue}}t&&(n=n.length>0?n+"/..":"..",r=2)}else n.length>0?n+="/"+e.slice(s+1,o):n=e.slice(s+1,o),r=o-s-1;s=o,a=0}else l===46&&a>-1?a++:a=-1}return n}function uS(e){if(typeof e!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(e))}const Ebt={cwd:Tbt};function Tbt(){return"/"}function Y$(e){return!!(e!==null&&typeof e=="object"&&"href"in e&&e.href&&"protocol"in e&&e.protocol&&e.auth===void 0)}function Ibt(e){if(typeof e=="string")e=new URL(e);else if(!Y$(e)){const t=new TypeError('The "path" argument must be of type string or an instance of URL. Received `'+e+"`");throw t.code="ERR_INVALID_ARG_TYPE",t}if(e.protocol!=="file:"){const t=new TypeError("The URL must be of scheme file");throw t.code="ERR_INVALID_URL_SCHEME",t}return Rbt(e)}function Rbt(e){if(e.hostname!==""){const r=new TypeError('File URL host must be "localhost" or empty on darwin');throw r.code="ERR_INVALID_FILE_URL_HOST",r}const t=e.pathname;let n=-1;for(;++n<t.length;)if(t.codePointAt(n)===37&&t.codePointAt(n+1)===50){const r=t.codePointAt(n+2);if(r===70||r===102){const s=new TypeError("File URL path must not include encoded / characters");throw s.code="ERR_INVALID_FILE_URL_PATH",s}}return decodeURIComponent(t)}const nP=["history","path","basename","stem","extname","dirname"];class tke{constructor(t){let n;t?Y$(t)?n={path:t}:typeof t=="string"||Mbt(t)?n={value:t}:n=t:n={},this.cwd="cwd"in n?"":Ebt.cwd(),this.data={},this.history=[],this.messages=[],this.value,this.map,this.result,this.stored;let r=-1;for(;++r<nP.length;){const a=nP[r];a in n&&n[a]!==void 0&&n[a]!==null&&(this[a]=a==="history"?[...n[a]]:n[a])}let s;for(s in n)nP.includes(s)||(this[s]=n[s])}get basename(){return typeof this.path=="string"?qd.basename(this.path):void 0}set basename(t){sP(t,"basename"),rP(t,"basename"),this.path=qd.join(this.dirname||"",t)}get dirname(){return typeof this.path=="string"?qd.dirname(this.path):void 0}set dirname(t){Yte(this.basename,"dirname"),this.path=qd.join(t||"",this.basename)}get extname(){return typeof this.path=="string"?qd.extname(this.path):void 0}set extname(t){if(rP(t,"extname"),Yte(this.dirname,"extname"),t){if(t.codePointAt(0)!==46)throw new Error("`extname` must start with `.`");if(t.includes(".",1))throw new Error("`extname` cannot contain multiple dots")}this.path=qd.join(this.dirname,this.stem+(t||""))}get path(){return this.history[this.history.length-1]}set path(t){Y$(t)&&(t=Ibt(t)),sP(t,"path"),this.path!==t&&this.history.push(t)}get stem(){return typeof this.path=="string"?qd.basename(this.path,this.extname):void 0}set stem(t){sP(t,"stem"),rP(t,"stem"),this.path=qd.join(this.dirname||"",t+(this.extname||""))}fail(t,n,r){const s=this.message(t,n,r);throw s.fatal=!0,s}info(t,n,r){const s=this.message(t,n,r);return s.fatal=void 0,s}message(t,n,r){const s=new cs(t,n,r);return this.path&&(s.name=this.path+":"+s.name,s.file=this.path),s.fatal=!1,this.messages.push(s),s}toString(t){return this.value===void 0?"":typeof this.value=="string"?this.value:new TextDecoder(t||void 0).decode(this.value)}}function rP(e,t){if(e&&e.includes(qd.sep))throw new Error("`"+t+"` cannot be a path: did not expect `"+qd.sep+"`")}function sP(e,t){if(!e)throw new Error("`"+t+"` cannot be empty")}function Yte(e,t){if(!e)throw new Error("Setting `"+t+"` requires `path` to be set too")}function Mbt(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const Obt=(function(e){const r=this.constructor.prototype,s=r[e],a=function(){return s.apply(a,arguments)};return Object.setPrototypeOf(a,r),a}),Dbt={}.hasOwnProperty;class eq extends Obt{constructor(){super("copy"),this.Compiler=void 0,this.Parser=void 0,this.attachers=[],this.compiler=void 0,this.freezeIndex=-1,this.frozen=void 0,this.namespace={},this.parser=void 0,this.transformers=wbt()}copy(){const t=new eq;let n=-1;for(;++n<this.attachers.length;){const r=this.attachers[n];t.use(...r)}return t.data(tP(!0,{},this.namespace)),t}data(t,n){return typeof t=="string"?arguments.length===2?(oP("data",this.frozen),this.namespace[t]=n,this):Dbt.call(this.namespace,t)&&this.namespace[t]||void 0:t?(oP("data",this.frozen),this.namespace=t,this):this.namespace}freeze(){if(this.frozen)return this;const t=this;for(;++this.freezeIndex<this.attachers.length;){const[n,...r]=this.attachers[this.freezeIndex];if(r[0]===!1)continue;r[0]===!0&&(r[0]=void 0);const s=n.call(t,...r);typeof s=="function"&&this.transformers.use(s)}return this.frozen=!0,this.freezeIndex=Number.POSITIVE_INFINITY,this}parse(t){this.freeze();const n=Q_(t),r=this.parser||this.Parser;return iP("parse",r),r(String(n),n)}process(t,n){const r=this;return this.freeze(),iP("process",this.parser||this.Parser),aP("process",this.compiler||this.Compiler),n?s(void 0,n):new Promise(s);function s(a,o){const l=Q_(t),c=r.parse(l);r.run(c,l,function(d,h,m){if(d||!h||!m)return u(d);const g=h,b=r.stringify(g,m);$bt(b)?m.value=b:m.result=b,u(d,m)});function u(d,h){d||!h?o(d):a?a(h):n(void 0,h)}}}processSync(t){let n=!1,r;return this.freeze(),iP("processSync",this.parser||this.Parser),aP("processSync",this.compiler||this.Compiler),this.process(t,s),Zte("processSync","process",n),r;function s(a,o){n=!0,Gte(a),r=o}}run(t,n,r){Jte(t),this.freeze();const s=this.transformers;return!r&&typeof n=="function"&&(r=n,n=void 0),r?a(void 0,r):new Promise(a);function a(o,l){const c=Q_(n);s.run(t,c,u);function u(d,h,m){const g=h||t;d?l(d):o?o(g):r(void 0,g,m)}}}runSync(t,n){let r=!1,s;return this.run(t,n,a),Zte("runSync","run",r),s;function a(o,l){Gte(o),s=l,r=!0}}stringify(t,n){this.freeze();const r=Q_(n),s=this.compiler||this.Compiler;return aP("stringify",s),Jte(t),s(t,r)}use(t,...n){const r=this.attachers,s=this.namespace;if(oP("use",this.frozen),t!=null)if(typeof t=="function")c(t,n);else if(typeof t=="object")Array.isArray(t)?l(t):o(t);else throw new TypeError("Expected usable value, not `"+t+"`");return this;function a(u){if(typeof u=="function")c(u,[]);else if(typeof u=="object")if(Array.isArray(u)){const[d,...h]=u;c(d,h)}else o(u);else throw new TypeError("Expected usable value, not `"+u+"`")}function o(u){if(!("plugins"in u)&&!("settings"in u))throw new Error("Expected usable value but received an empty preset, which is probably a mistake: presets typically come with `plugins` and sometimes with `settings`, but this has neither");l(u.plugins),u.settings&&(s.settings=tP(!0,s.settings,u.settings))}function l(u){let d=-1;if(u!=null)if(Array.isArray(u))for(;++d<u.length;){const h=u[d];a(h)}else throw new TypeError("Expected a list of plugins, not `"+u+"`")}function c(u,d){let h=-1,m=-1;for(;++h<r.length;)if(r[h][0]===u){m=h;break}if(m===-1)r.push([u,...d]);else if(d.length>0){let[g,...b]=d;const v=r[m][1];Q$(v)&&Q$(g)&&(g=tP(!0,v,g)),r[m]=[u,g,...b]}}}}const Pbt=new eq().freeze();function iP(e,t){if(typeof t!="function")throw new TypeError("Cannot `"+e+"` without `parser`")}function aP(e,t){if(typeof t!="function")throw new TypeError("Cannot `"+e+"` without `compiler`")}function oP(e,t){if(t)throw new Error("Cannot call `"+e+"` on a frozen processor.\nCreate a new processor first, by calling it: use `processor()` instead of `processor`.")}function Jte(e){if(!Q$(e)||typeof e.type!="string")throw new TypeError("Expected node, got `"+e+"`")}function Zte(e,t,n){if(!n)throw new Error("`"+e+"` finished async. Use `"+t+"` instead")}function Q_(e){return Lbt(e)?e:new tke(e)}function Lbt(e){return!!(e&&typeof e=="object"&&"message"in e&&"messages"in e)}function $bt(e){return typeof e=="string"||Fbt(e)}function Fbt(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const zbt="https://github.com/remarkjs/react-markdown/blob/main/changelog.md",Xte=[],ene={allowDangerousHtml:!0},Bbt=/^(https?|ircs?|mailto|xmpp)$/i,Ubt=[{from:"astPlugins",id:"remove-buggy-html-in-markdown-parser"},{from:"allowDangerousHtml",id:"remove-buggy-html-in-markdown-parser"},{from:"allowNode",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"allowElement"},{from:"allowedTypes",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"allowedElements"},{from:"className",id:"remove-classname"},{from:"disallowedTypes",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"disallowedElements"},{from:"escapeHtml",id:"remove-buggy-html-in-markdown-parser"},{from:"includeElementIndex",id:"#remove-includeelementindex"},{from:"includeNodeIndex",id:"change-includenodeindex-to-includeelementindex"},{from:"linkTarget",id:"remove-linktarget"},{from:"plugins",id:"change-plugins-to-remarkplugins",to:"remarkPlugins"},{from:"rawSourcePos",id:"#remove-rawsourcepos"},{from:"renderers",id:"change-renderers-to-components",to:"components"},{from:"source",id:"change-source-to-children",to:"children"},{from:"sourcePos",id:"#remove-sourcepos"},{from:"transformImageUri",id:"#add-urltransform",to:"urlTransform"},{from:"transformLinkUri",id:"#add-urltransform",to:"urlTransform"}];function qbt(e){const t=Vbt(e),n=Hbt(e);return Kbt(t.runSync(t.parse(n),n),e)}function Vbt(e){const t=e.rehypePlugins||Xte,n=e.remarkPlugins||Xte,r=e.remarkRehypeOptions?{...e.remarkRehypeOptions,...ene}:ene;return Pbt().use(Rxt).use(n).use(bbt,r).use(t)}function Hbt(e){const t=e.children||"",n=new tke;return typeof t=="string"&&(n.value=t),n}function Kbt(e,t){const n=t.allowedElements,r=t.allowElement,s=t.components,a=t.disallowedElements,o=t.skipHtml,l=t.unwrapDisallowed,c=t.urlTransform||Wbt;for(const d of Ubt)Object.hasOwn(t,d.from)&&(""+d.from+(d.to?"use `"+d.to+"` instead":"remove it")+zbt+d.id,void 0);return Oz(e,u),gxt(e,{Fragment:i.Fragment,components:s,ignoreInvalidStyle:!0,jsx:i.jsx,jsxs:i.jsxs,passKeys:!0,passNode:!0});function u(d,h,m){if(d.type==="raw"&&m&&typeof h=="number")return o?m.children.splice(h,1):m.children[h]={type:"text",value:d.value},h;if(d.type==="element"){let g;for(g in XD)if(Object.hasOwn(XD,g)&&Object.hasOwn(d.properties,g)){const b=d.properties[g],v=XD[g];(v===null||v.includes(d.tagName))&&(d.properties[g]=c(String(b||""),g,d))}}if(d.type==="element"){let g=n?!n.includes(d.tagName):a?a.includes(d.tagName):!1;if(!g&&r&&typeof h=="number"&&(g=!r(d,h,m)),g&&m&&typeof h=="number")return l&&d.children?m.children.splice(h,1,...d.children):m.children.splice(h,1),h}}}function Wbt(e){const t=e.indexOf(":"),n=e.indexOf("?"),r=e.indexOf("#"),s=e.indexOf("/");return t===-1||s!==-1&&t>s||n!==-1&&t>n||r!==-1&&t>r||Bbt.test(e.slice(0,t))?e:""}function Gbt(e,t,n){const s=xI((n||{}).ignore||[]),a=Qbt(t);let o=-1;for(;++o<a.length;)Qpe(e,"text",l);function l(u,d){let h=-1,m;for(;++h<d.length;){const g=d[h],b=m?m.children:void 0;if(s(g,b?b.indexOf(g):void 0,m))return;m=g}if(m)return c(u,d)}function c(u,d){const h=d[d.length-1],m=a[o][0],g=a[o][1];let b=0;const j=h.children.indexOf(u);let k=!1,w=[];m.lastIndex=0;let N=m.exec(u.value);for(;N;){const S=N.index,A={index:N.index,input:N.input,stack:[...d,u]};let _=g(...N,A);if(typeof _=="string"&&(_=_.length>0?{type:"text",value:_}:void 0),_===!1?m.lastIndex=S+1:(b!==S&&w.push({type:"text",value:u.value.slice(b,S)}),Array.isArray(_)?w.push(..._):_&&w.push(_),b=S+N[0].length,k=!0),!m.global)break;N=m.exec(u.value)}return k?(b<u.value.length&&w.push({type:"text",value:u.value.slice(b)}),h.children.splice(j,1,...w)):w=[u],j+w.length}}function Qbt(e){const t=[];if(!Array.isArray(e))throw new TypeError("Expected find and replace tuple or list of tuples");const n=!e[0]||Array.isArray(e[0])?e:[e];let r=-1;for(;++r<n.length;){const s=n[r];t.push([Ybt(s[0]),Jbt(s[1])])}return t}function Ybt(e){return typeof e=="string"?new RegExp(zet(e),"g"):e}function Jbt(e){return typeof e=="function"?e:function(){return e}}const lP="phrasing",cP=["autolink","link","image","label"];function Zbt(){return{transforms:[iyt],enter:{literalAutolink:eyt,literalAutolinkEmail:uP,literalAutolinkHttp:uP,literalAutolinkWww:uP},exit:{literalAutolink:syt,literalAutolinkEmail:ryt,literalAutolinkHttp:tyt,literalAutolinkWww:nyt}}}function Xbt(){return{unsafe:[{character:"@",before:"[+\\-.\\w]",after:"[\\-.\\w]",inConstruct:lP,notInConstruct:cP},{character:".",before:"[Ww]",after:"[\\-.\\w]",inConstruct:lP,notInConstruct:cP},{character:":",before:"[ps]",after:"\\/",inConstruct:lP,notInConstruct:cP}]}}function eyt(e){this.enter({type:"link",title:null,url:"",children:[]},e)}function uP(e){this.config.enter.autolinkProtocol.call(this,e)}function tyt(e){this.config.exit.autolinkProtocol.call(this,e)}function nyt(e){this.config.exit.data.call(this,e);const t=this.stack[this.stack.length-1];t.type,t.url="http://"+this.sliceSerialize(e)}function ryt(e){this.config.exit.autolinkEmail.call(this,e)}function syt(e){this.exit(e)}function iyt(e){Gbt(e,[[/(https?:\/\/|www(?=\.))([-.\w]+)([^ \t\r\n]*)/gi,ayt],[new RegExp("(?<=^|\\s|\\p{P}|\\p{S})([-.\\w+]+)@([-\\w]+(?:\\.[-\\w]+)+)","gu"),oyt]],{ignore:["link","linkReference"]})}function ayt(e,t,n,r,s){let a="";if(!nke(s)||(/^w/i.test(t)&&(n=t+n,t="",a="http://"),!lyt(n)))return!1;const o=cyt(n+r);if(!o[0])return!1;const l={type:"link",title:null,url:a+t+o[0],children:[{type:"text",value:t+o[0]}]};return o[1]?[l,{type:"text",value:o[1]}]:l}function oyt(e,t,n,r){return!nke(r,!0)||/[-\d_]$/.test(n)?!1:{type:"link",title:null,url:"mailto:"+t+"@"+n,children:[{type:"text",value:t+"@"+n}]}}function lyt(e){const t=e.split(".");return!(t.length<2||t[t.length-1]&&(/_/.test(t[t.length-1])||!/[a-zA-Z\d]/.test(t[t.length-1]))||t[t.length-2]&&(/_/.test(t[t.length-2])||!/[a-zA-Z\d]/.test(t[t.length-2])))}function cyt(e){const t=/[!"&'),.:;<>?\]}]+$/.exec(e);if(!t)return[e,void 0];e=e.slice(0,t.index);let n=t[0],r=n.indexOf(")");const s=cE(e,"(");let a=cE(e,")");for(;r!==-1&&s>a;)e+=n.slice(0,r+1),n=n.slice(r+1),r=n.indexOf(")"),a++;return[e,n]}function nke(e,t){const n=e.input.charCodeAt(e.index-1);return(e.index===0||ol(n)||gI(n))&&(!t||n!==47)}rke.peek=byt;function uyt(){this.buffer()}function dyt(e){this.enter({type:"footnoteReference",identifier:"",label:""},e)}function fyt(){this.buffer()}function hyt(e){this.enter({type:"footnoteDefinition",identifier:"",label:"",children:[]},e)}function myt(e){const t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=Zu(this.sliceSerialize(e)).toLowerCase(),n.label=t}function pyt(e){this.exit(e)}function gyt(e){const t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=Zu(this.sliceSerialize(e)).toLowerCase(),n.label=t}function xyt(e){this.exit(e)}function byt(){return"["}function rke(e,t,n,r){const s=n.createTracker(r);let a=s.move("[^");const o=n.enter("footnoteReference"),l=n.enter("reference");return a+=s.move(n.safe(n.associationId(e),{after:"]",before:a})),l(),o(),a+=s.move("]"),a}function yyt(){return{enter:{gfmFootnoteCallString:uyt,gfmFootnoteCall:dyt,gfmFootnoteDefinitionLabelString:fyt,gfmFootnoteDefinition:hyt},exit:{gfmFootnoteCallString:myt,gfmFootnoteCall:pyt,gfmFootnoteDefinitionLabelString:gyt,gfmFootnoteDefinition:xyt}}}function vyt(e){let t=!1;return e&&e.firstLineBlank&&(t=!0),{handlers:{footnoteDefinition:n,footnoteReference:rke},unsafe:[{character:"[",inConstruct:["label","phrasing","reference"]}]};function n(r,s,a,o){const l=a.createTracker(o);let c=l.move("[^");const u=a.enter("footnoteDefinition"),d=a.enter("label");return c+=l.move(a.safe(a.associationId(r),{before:c,after:"]"})),d(),c+=l.move("]:"),r.children&&r.children.length>0&&(l.shift(4),c+=l.move((t?`
1347
- `:" ")+a.indentLines(a.containerFlow(r,l.current()),t?ske:wyt))),u(),c}}function wyt(e,t,n){return t===0?e:ske(e,t,n)}function ske(e,t,n){return(n?"":" ")+e}function kyt(){return[Zbt(),yyt(),Epe(),yxe(),xxe()]}function jyt(e){return{extensions:[Xbt(),vyt(e),Tpe(),vxe(e),bxe()]}}const Nyt={tokenize:Tyt,partial:!0},ike={tokenize:Iyt,partial:!0},ake={tokenize:Ryt,partial:!0},oke={tokenize:Myt,partial:!0},Cyt={tokenize:Oyt,partial:!0},lke={name:"wwwAutolink",tokenize:Ayt,previous:uke},cke={name:"protocolAutolink",tokenize:Eyt,previous:dke},xm={name:"emailAutolink",tokenize:_yt,previous:fke},$f={};function Syt(){return{text:$f}}let gx=48;for(;gx<123;)$f[gx]=xm,gx++,gx===58?gx=65:gx===91&&(gx=97);$f[43]=xm;$f[45]=xm;$f[46]=xm;$f[95]=xm;$f[72]=[xm,cke];$f[104]=[xm,cke];$f[87]=[xm,lke];$f[119]=[xm,lke];function _yt(e,t,n){const r=this;let s,a;return o;function o(h){return!J$(h)||!fke.call(r,r.previous)||tq(r.events)?n(h):(e.enter("literalAutolink"),e.enter("literalAutolinkEmail"),l(h))}function l(h){return J$(h)?(e.consume(h),l):h===64?(e.consume(h),c):n(h)}function c(h){return h===46?e.check(Cyt,d,u)(h):h===45||h===95||Lo(h)?(a=!0,e.consume(h),c):d(h)}function u(h){return e.consume(h),s=!0,c}function d(h){return a&&s&&dl(r.previous)?(e.exit("literalAutolinkEmail"),e.exit("literalAutolink"),t(h)):n(h)}}function Ayt(e,t,n){const r=this;return s;function s(o){return o!==87&&o!==119||!uke.call(r,r.previous)||tq(r.events)?n(o):(e.enter("literalAutolink"),e.enter("literalAutolinkWww"),e.check(Nyt,e.attempt(ike,e.attempt(ake,a),n),n)(o))}function a(o){return e.exit("literalAutolinkWww"),e.exit("literalAutolink"),t(o)}}function Eyt(e,t,n){const r=this;let s="",a=!1;return o;function o(h){return(h===72||h===104)&&dke.call(r,r.previous)&&!tq(r.events)?(e.enter("literalAutolink"),e.enter("literalAutolinkHttp"),s+=String.fromCodePoint(h),e.consume(h),l):n(h)}function l(h){if(dl(h)&&s.length<5)return s+=String.fromCodePoint(h),e.consume(h),l;if(h===58){const m=s.toLowerCase();if(m==="http"||m==="https")return e.consume(h),c}return n(h)}function c(h){return h===47?(e.consume(h),a?u:(a=!0,c)):n(h)}function u(h){return h===null||lE(h)||qr(h)||ol(h)||gI(h)?n(h):e.attempt(ike,e.attempt(ake,d),n)(h)}function d(h){return e.exit("literalAutolinkHttp"),e.exit("literalAutolink"),t(h)}}function Tyt(e,t,n){let r=0;return s;function s(o){return(o===87||o===119)&&r<3?(r++,e.consume(o),s):o===46&&r===3?(e.consume(o),a):n(o)}function a(o){return o===null?n(o):t(o)}}function Iyt(e,t,n){let r,s,a;return o;function o(u){return u===46||u===95?e.check(oke,c,l)(u):u===null||qr(u)||ol(u)||u!==45&&gI(u)?c(u):(a=!0,e.consume(u),o)}function l(u){return u===95?r=!0:(s=r,r=void 0),e.consume(u),o}function c(u){return s||r||!a?n(u):t(u)}}function Ryt(e,t){let n=0,r=0;return s;function s(o){return o===40?(n++,e.consume(o),s):o===41&&r<n?a(o):o===33||o===34||o===38||o===39||o===41||o===42||o===44||o===46||o===58||o===59||o===60||o===63||o===93||o===95||o===126?e.check(oke,t,a)(o):o===null||qr(o)||ol(o)?t(o):(e.consume(o),s)}function a(o){return o===41&&r++,e.consume(o),s}}function Myt(e,t,n){return r;function r(l){return l===33||l===34||l===39||l===41||l===42||l===44||l===46||l===58||l===59||l===63||l===95||l===126?(e.consume(l),r):l===38?(e.consume(l),a):l===93?(e.consume(l),s):l===60||l===null||qr(l)||ol(l)?t(l):n(l)}function s(l){return l===null||l===40||l===91||qr(l)||ol(l)?t(l):r(l)}function a(l){return dl(l)?o(l):n(l)}function o(l){return l===59?(e.consume(l),r):dl(l)?(e.consume(l),o):n(l)}}function Oyt(e,t,n){return r;function r(a){return e.consume(a),s}function s(a){return Lo(a)?n(a):t(a)}}function uke(e){return e===null||e===40||e===42||e===95||e===91||e===93||e===126||qr(e)}function dke(e){return!dl(e)}function fke(e){return!(e===47||J$(e))}function J$(e){return e===43||e===45||e===46||e===95||Lo(e)}function tq(e){let t=e.length,n=!1;for(;t--;){const r=e[t][1];if((r.type==="labelLink"||r.type==="labelImage")&&!r._balanced){n=!0;break}if(r._gfmAutolinkLiteralWalkedInto){n=!1;break}}return e.length>0&&!n&&(e[e.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),n}const Dyt={tokenize:qyt,partial:!0};function Pyt(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:zyt,continuation:{tokenize:Byt},exit:Uyt}},text:{91:{name:"gfmFootnoteCall",tokenize:Fyt},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:Lyt,resolveTo:$yt}}}}function Lyt(e,t,n){const r=this;let s=r.events.length;const a=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let o;for(;s--;){const c=r.events[s][1];if(c.type==="labelImage"){o=c;break}if(c.type==="gfmFootnoteCall"||c.type==="labelLink"||c.type==="label"||c.type==="image"||c.type==="link")break}return l;function l(c){if(!o||!o._balanced)return n(c);const u=Zu(r.sliceSerialize({start:o.end,end:r.now()}));return u.codePointAt(0)!==94||!a.includes(u.slice(1))?n(c):(e.enter("gfmFootnoteCallLabelMarker"),e.consume(c),e.exit("gfmFootnoteCallLabelMarker"),t(c))}}function $yt(e,t){let n=e.length;for(;n--;)if(e[n][1].type==="labelImage"&&e[n][0]==="enter"){e[n][1];break}e[n+1][1].type="data",e[n+3][1].type="gfmFootnoteCallLabelMarker";const r={type:"gfmFootnoteCall",start:Object.assign({},e[n+3][1].start),end:Object.assign({},e[e.length-1][1].end)},s={type:"gfmFootnoteCallMarker",start:Object.assign({},e[n+3][1].end),end:Object.assign({},e[n+3][1].end)};s.end.column++,s.end.offset++,s.end._bufferIndex++;const a={type:"gfmFootnoteCallString",start:Object.assign({},s.end),end:Object.assign({},e[e.length-1][1].start)},o={type:"chunkString",contentType:"string",start:Object.assign({},a.start),end:Object.assign({},a.end)},l=[e[n+1],e[n+2],["enter",r,t],e[n+3],e[n+4],["enter",s,t],["exit",s,t],["enter",a,t],["enter",o,t],["exit",o,t],["exit",a,t],e[e.length-2],e[e.length-1],["exit",r,t]];return e.splice(n,e.length-n+1,...l),e}function Fyt(e,t,n){const r=this,s=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let a=0,o;return l;function l(h){return e.enter("gfmFootnoteCall"),e.enter("gfmFootnoteCallLabelMarker"),e.consume(h),e.exit("gfmFootnoteCallLabelMarker"),c}function c(h){return h!==94?n(h):(e.enter("gfmFootnoteCallMarker"),e.consume(h),e.exit("gfmFootnoteCallMarker"),e.enter("gfmFootnoteCallString"),e.enter("chunkString").contentType="string",u)}function u(h){if(a>999||h===93&&!o||h===null||h===91||qr(h))return n(h);if(h===93){e.exit("chunkString");const m=e.exit("gfmFootnoteCallString");return s.includes(Zu(r.sliceSerialize(m)))?(e.enter("gfmFootnoteCallLabelMarker"),e.consume(h),e.exit("gfmFootnoteCallLabelMarker"),e.exit("gfmFootnoteCall"),t):n(h)}return qr(h)||(o=!0),a++,e.consume(h),h===92?d:u}function d(h){return h===91||h===92||h===93?(e.consume(h),a++,u):u(h)}}function zyt(e,t,n){const r=this,s=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let a,o=0,l;return c;function c(b){return e.enter("gfmFootnoteDefinition")._container=!0,e.enter("gfmFootnoteDefinitionLabel"),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(b),e.exit("gfmFootnoteDefinitionLabelMarker"),u}function u(b){return b===94?(e.enter("gfmFootnoteDefinitionMarker"),e.consume(b),e.exit("gfmFootnoteDefinitionMarker"),e.enter("gfmFootnoteDefinitionLabelString"),e.enter("chunkString").contentType="string",d):n(b)}function d(b){if(o>999||b===93&&!l||b===null||b===91||qr(b))return n(b);if(b===93){e.exit("chunkString");const v=e.exit("gfmFootnoteDefinitionLabelString");return a=Zu(r.sliceSerialize(v)),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(b),e.exit("gfmFootnoteDefinitionLabelMarker"),e.exit("gfmFootnoteDefinitionLabel"),m}return qr(b)||(l=!0),o++,e.consume(b),b===92?h:d}function h(b){return b===91||b===92||b===93?(e.consume(b),o++,d):d(b)}function m(b){return b===58?(e.enter("definitionMarker"),e.consume(b),e.exit("definitionMarker"),s.includes(a)||s.push(a),Ar(e,g,"gfmFootnoteDefinitionWhitespace")):n(b)}function g(b){return t(b)}}function Byt(e,t,n){return e.check($C,t,e.attempt(Dyt,t,n))}function Uyt(e){e.exit("gfmFootnoteDefinition")}function qyt(e,t,n){const r=this;return Ar(e,s,"gfmFootnoteDefinitionIndent",5);function s(a){const o=r.events[r.events.length-1];return o&&o[1].type==="gfmFootnoteDefinitionIndent"&&o[2].sliceSerialize(o[1],!0).length===4?t(a):n(a)}}function Vyt(e){return mge([Syt(),Pyt(),Ape(e),wxe(),gxe()])}const Hyt={};function Kyt(e){const t=this,n=e||Hyt,r=t.data(),s=r.micromarkExtensions||(r.micromarkExtensions=[]),a=r.fromMarkdownExtensions||(r.fromMarkdownExtensions=[]),o=r.toMarkdownExtensions||(r.toMarkdownExtensions=[]);s.push(Vyt(n)),a.push(kyt()),o.push(jyt(n))}const hke="rudder.theme",tne="#1f1f1d",nne="#f1f0ef",mke=x.createContext(void 0);function Wyt(){return typeof window>"u"?null:window.desktopShell??null}function pke(){return typeof window>"u"||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}function rne(){if(typeof window>"u")return"system";try{const e=window.localStorage.getItem(hke);if(e==="light"||e==="dark"||e==="system")return e}catch{}return"system"}function X5(e){return e==="system"?pke():e}function sne(e){var a,o;if(typeof document>"u")return;const n=X5(e)==="dark",r=document.documentElement;r.classList.toggle("dark",n),r.style.colorScheme=n?"dark":"light",r.style.backgroundColor=r.classList.contains("desktop-shell-macos")?"transparent":n?tne:nne;const s=document.querySelector('meta[name="theme-color"]');s instanceof HTMLMetaElement&&s.setAttribute("content",n?tne:nne),(o=(a=Wyt())==null?void 0:a.setAppearance)==null||o.call(a,e)}function Gyt({children:e}){const[t,n]=x.useState(()=>rne()),[r,s]=x.useState(()=>X5(rne())),a=x.useCallback(c=>{n(c)},[]),o=x.useCallback(()=>{n(c=>X5(c)==="dark"?"light":"dark")},[]);x.useEffect(()=>{sne(t),s(X5(t));try{localStorage.setItem(hke,t)}catch{}},[t]),x.useEffect(()=>{if(typeof window>"u")return;const c=window.matchMedia("(prefers-color-scheme: dark)"),u=()=>{if(t!=="system")return;const d=pke();s(d),sne("system")};return c.addEventListener("change",u),()=>{c.removeEventListener("change",u)}},[t]);const l=x.useMemo(()=>({theme:t,resolvedTheme:r,setTheme:a,toggleTheme:o}),[t,r,a,o]);return i.jsx(mke.Provider,{value:l,children:e})}function gke(){const e=x.useContext(mke);if(!e)throw new Error("useTheme must be used within ThemeProvider");return e}const Qyt=190,Yyt=178;function Jyt(e,t){return typeof window>"u"?{left:e,top:t}:{left:Math.min(e,Math.max(8,window.innerWidth-Qyt)),top:Math.min(t,Math.max(8,window.innerHeight-Yyt))}}function Zyt(e){return e instanceof Error?e.message:String(e)}function Xyt(){try{return gr()}catch{return null}}function e0t({alt:e,className:t,name:n,onInspect:r,src:s,...a}){const o=Xyt(),l=x.useRef(null),c=x.useRef(null),[u,d]=x.useState(null),h=jU();x.useEffect(()=>{if(!u)return;const v=k=>{var w;(w=l.current)!=null&&w.contains(k.target)||d(null)},j=k=>{k.key==="Escape"&&d(null)};return document.addEventListener("pointerdown",v),document.addEventListener("keydown",j),()=>{document.removeEventListener("pointerdown",v),document.removeEventListener("keydown",j)}},[u]);const m=()=>{const v=c.current;!v||!r||r(v)},g=v=>{v.preventDefault(),v.stopPropagation(),d(Jyt(v.clientX,v.clientY))},b=async(v,j,k)=>{d(null);try{await j(),k&&(o==null||o.pushToast({title:k,tone:"success"}))}catch(w){o==null||o.pushToast({title:v,body:Zyt(w),tone:"error"})}};return i.jsxs("span",{className:"rudder-inspectable-image",children:[i.jsxs("button",{type:"button",className:"rudder-inspectable-image-trigger","aria-label":`Open image preview: ${n}`,title:"Open image preview",onClick:m,onDoubleClick:m,onContextMenu:g,children:[i.jsx("img",{...a,ref:c,src:s,alt:e??"",className:t,onContextMenu:g}),i.jsx("span",{className:"rudder-inspectable-image-overlay","aria-hidden":"true",children:i.jsx(Wh,{className:"size-3.5"})})]}),u&&typeof document<"u"?Fa.createPortal(i.jsxs("div",{ref:l,"data-testid":"markdown-image-context-menu",role:"menu",className:"motion-chat-composer-menu-pop surface-overlay fixed z-50 min-w-[190px] rounded-[var(--radius-lg)] border p-1.5 text-foreground shadow-[var(--shadow-lg)]",style:u,children:[i.jsxs("button",{type:"button",role:"menuitem",className:"chat-composer-menu-row w-full",onClick:()=>b("Open Image failed",()=>Yve(s)),children:[i.jsx(Kl,{className:"h-3.5 w-3.5 shrink-0"}),i.jsx("span",{className:"min-w-0 flex-1 truncate",children:"Open Image"})]}),i.jsxs("button",{type:"button",role:"menuitem",className:"chat-composer-menu-row w-full",onClick:()=>b("Copy Image failed",()=>wU(s,n),"Image copied"),children:[i.jsx(xi,{className:"h-3.5 w-3.5 shrink-0"}),i.jsx("span",{className:"min-w-0 flex-1 truncate",children:"Copy Image"})]}),i.jsxs("button",{type:"button",role:"menuitem",className:"chat-composer-menu-row w-full",onClick:()=>b("Download Image failed",()=>Jve(s,n)),children:[i.jsx(wf,{className:"h-3.5 w-3.5 shrink-0"}),i.jsx("span",{className:"min-w-0 flex-1 truncate",children:"Download Image"})]}),h?i.jsxs("button",{type:"button",role:"menuitem",className:"chat-composer-menu-row w-full",onClick:()=>b("Open in Finder failed",()=>kU(s,n)),children:[i.jsx(Ic,{className:"h-3.5 w-3.5 shrink-0"}),i.jsx("span",{className:"min-w-0 flex-1 truncate",children:"Open in Finder"})]}):null]}),document.body):null]})}function t0t({label:e,preview:t}){var c,u,d,h,m;const n=((c=t==null?void 0:t.displayName)==null?void 0:c.trim())||e,r=((u=t==null?void 0:t.description)==null?void 0:u.trim())||null,s=((d=t==null?void 0:t.categoryLabel)==null?void 0:d.trim())||null,a=((h=t==null?void 0:t.locationLabel)==null?void 0:h.trim())||null,o=((m=t==null?void 0:t.detailsHref)==null?void 0:m.trim())||null,l=!!(r||s||a||o);return i.jsxs("span",{className:Q("rudder-skill-token-wrap",l&&"rudder-skill-token-wrap--preview"),children:[i.jsx("span",{className:"rudder-skill-token","data-skill-token":"true",tabIndex:l?0:void 0,"aria-label":l?`${n} skill`:void 0,children:e}),l?i.jsxs("span",{className:"rudder-skill-hover-card",role:"tooltip",children:[i.jsxs("span",{className:"flex items-start gap-3",children:[i.jsx("span",{className:"mt-0.5 flex h-7 w-7 shrink-0 items-center justify-center rounded-[var(--radius-md)] bg-[#2f80ed]/10 text-[#2f80ed]",children:i.jsx(mu,{className:"h-4 w-4","aria-hidden":!0})}),i.jsxs("span",{className:"min-w-0 flex-1",children:[i.jsx("span",{className:"block truncate text-sm font-medium text-foreground",children:n}),s||a?i.jsxs("span",{className:"mt-1.5 flex min-w-0 flex-wrap items-center gap-1.5",children:[s?i.jsx("span",{className:"inline-flex items-center rounded-[var(--radius-sm)] border border-border/70 bg-muted/50 px-1.5 py-0.5 text-[11px] font-medium leading-none text-muted-foreground",children:s}):null,a?i.jsx("span",{className:"min-w-0 truncate text-[11px] leading-none text-muted-foreground",children:a}):null]}):null,r?i.jsx("span",{className:"mt-1 block text-xs leading-5 text-muted-foreground",children:r}):null]})]}),o?i.jsxs("a",{className:"rudder-skill-hover-card-action",href:o,children:[i.jsx("span",{children:"View details"}),i.jsx(ig,{className:"h-3.5 w-3.5","aria-hidden":!0})]}):null]}):null]})}let dP=null;function n0t(){return dP||(dP=ut(()=>import("./mermaid.core-BlSfPv1h.js").then(e=>e.bF),[]).then(e=>e.default)),dP}function Rj(e){return e==null?"":typeof e=="string"||typeof e=="number"?String(e):Array.isArray(e)?e.map(t=>Rj(t)).join(""):""}function Y_(e){return(e==null?void 0:e.trim().replace(/\/+$/u,"").toLowerCase())??""}function r0t(e){const t=(e==null?void 0:e.trim())??"";if(!t)return!1;if(t.startsWith("//"))return!0;if(!/^[a-z][a-z\d+.-]*:/iu.test(t))return!1;try{const n=new URL(t);return n.protocol==="http:"||n.protocol==="https:"||n.protocol==="mailto:"}catch{return!1}}function s0t(e){const t=e.trim();return/^(?:https?:\/\/|www\.|\/\/)/iu.test(t)}function i0t(e){if(!x.isValidElement(e))return null;const t=e.props;return typeof t.className!="string"||!/\blanguage-mermaid\b/i.test(t.className)?null:Rj(t.children).replace(/\n$/,"")}function a0t(e){const t=e.alt.trim();if(t)return t;const n=e.currentSrc||e.src;try{const s=new URL(n,window.location.href).pathname.split("/").filter(Boolean).at(-1);return s?decodeURIComponent(s):"Image preview"}catch{return"Image preview"}}function o0t(e){var o,l;if(!e.includes("\\n"))return e;const t=((o=e.match(/\\n/g))==null?void 0:o.length)??0;if(t===0)return e;const n=((l=e.match(/\n/g))==null?void 0:l.length)??0,r=e.includes("\\n\\n"),s=/\\n\s*(?:[-*+]\s|\d+\.\s)/.test(e),a=n===0&&t>=3;return!r&&!s&&!a?e:e.replace(/\\r\\n/g,`
1347
+ `:" ")+a.indentLines(a.containerFlow(r,l.current()),t?ske:wyt))),u(),c}}function wyt(e,t,n){return t===0?e:ske(e,t,n)}function ske(e,t,n){return(n?"":" ")+e}function kyt(){return[Zbt(),yyt(),Epe(),yxe(),xxe()]}function jyt(e){return{extensions:[Xbt(),vyt(e),Tpe(),vxe(e),bxe()]}}const Nyt={tokenize:Tyt,partial:!0},ike={tokenize:Iyt,partial:!0},ake={tokenize:Ryt,partial:!0},oke={tokenize:Myt,partial:!0},Cyt={tokenize:Oyt,partial:!0},lke={name:"wwwAutolink",tokenize:Ayt,previous:uke},cke={name:"protocolAutolink",tokenize:Eyt,previous:dke},xm={name:"emailAutolink",tokenize:_yt,previous:fke},$f={};function Syt(){return{text:$f}}let gx=48;for(;gx<123;)$f[gx]=xm,gx++,gx===58?gx=65:gx===91&&(gx=97);$f[43]=xm;$f[45]=xm;$f[46]=xm;$f[95]=xm;$f[72]=[xm,cke];$f[104]=[xm,cke];$f[87]=[xm,lke];$f[119]=[xm,lke];function _yt(e,t,n){const r=this;let s,a;return o;function o(h){return!J$(h)||!fke.call(r,r.previous)||tq(r.events)?n(h):(e.enter("literalAutolink"),e.enter("literalAutolinkEmail"),l(h))}function l(h){return J$(h)?(e.consume(h),l):h===64?(e.consume(h),c):n(h)}function c(h){return h===46?e.check(Cyt,d,u)(h):h===45||h===95||Lo(h)?(a=!0,e.consume(h),c):d(h)}function u(h){return e.consume(h),s=!0,c}function d(h){return a&&s&&dl(r.previous)?(e.exit("literalAutolinkEmail"),e.exit("literalAutolink"),t(h)):n(h)}}function Ayt(e,t,n){const r=this;return s;function s(o){return o!==87&&o!==119||!uke.call(r,r.previous)||tq(r.events)?n(o):(e.enter("literalAutolink"),e.enter("literalAutolinkWww"),e.check(Nyt,e.attempt(ike,e.attempt(ake,a),n),n)(o))}function a(o){return e.exit("literalAutolinkWww"),e.exit("literalAutolink"),t(o)}}function Eyt(e,t,n){const r=this;let s="",a=!1;return o;function o(h){return(h===72||h===104)&&dke.call(r,r.previous)&&!tq(r.events)?(e.enter("literalAutolink"),e.enter("literalAutolinkHttp"),s+=String.fromCodePoint(h),e.consume(h),l):n(h)}function l(h){if(dl(h)&&s.length<5)return s+=String.fromCodePoint(h),e.consume(h),l;if(h===58){const m=s.toLowerCase();if(m==="http"||m==="https")return e.consume(h),c}return n(h)}function c(h){return h===47?(e.consume(h),a?u:(a=!0,c)):n(h)}function u(h){return h===null||lE(h)||qr(h)||ol(h)||gI(h)?n(h):e.attempt(ike,e.attempt(ake,d),n)(h)}function d(h){return e.exit("literalAutolinkHttp"),e.exit("literalAutolink"),t(h)}}function Tyt(e,t,n){let r=0;return s;function s(o){return(o===87||o===119)&&r<3?(r++,e.consume(o),s):o===46&&r===3?(e.consume(o),a):n(o)}function a(o){return o===null?n(o):t(o)}}function Iyt(e,t,n){let r,s,a;return o;function o(u){return u===46||u===95?e.check(oke,c,l)(u):u===null||qr(u)||ol(u)||u!==45&&gI(u)?c(u):(a=!0,e.consume(u),o)}function l(u){return u===95?r=!0:(s=r,r=void 0),e.consume(u),o}function c(u){return s||r||!a?n(u):t(u)}}function Ryt(e,t){let n=0,r=0;return s;function s(o){return o===40?(n++,e.consume(o),s):o===41&&r<n?a(o):o===33||o===34||o===38||o===39||o===41||o===42||o===44||o===46||o===58||o===59||o===60||o===63||o===93||o===95||o===126?e.check(oke,t,a)(o):o===null||qr(o)||ol(o)?t(o):(e.consume(o),s)}function a(o){return o===41&&r++,e.consume(o),s}}function Myt(e,t,n){return r;function r(l){return l===33||l===34||l===39||l===41||l===42||l===44||l===46||l===58||l===59||l===63||l===95||l===126?(e.consume(l),r):l===38?(e.consume(l),a):l===93?(e.consume(l),s):l===60||l===null||qr(l)||ol(l)?t(l):n(l)}function s(l){return l===null||l===40||l===91||qr(l)||ol(l)?t(l):r(l)}function a(l){return dl(l)?o(l):n(l)}function o(l){return l===59?(e.consume(l),r):dl(l)?(e.consume(l),o):n(l)}}function Oyt(e,t,n){return r;function r(a){return e.consume(a),s}function s(a){return Lo(a)?n(a):t(a)}}function uke(e){return e===null||e===40||e===42||e===95||e===91||e===93||e===126||qr(e)}function dke(e){return!dl(e)}function fke(e){return!(e===47||J$(e))}function J$(e){return e===43||e===45||e===46||e===95||Lo(e)}function tq(e){let t=e.length,n=!1;for(;t--;){const r=e[t][1];if((r.type==="labelLink"||r.type==="labelImage")&&!r._balanced){n=!0;break}if(r._gfmAutolinkLiteralWalkedInto){n=!1;break}}return e.length>0&&!n&&(e[e.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),n}const Dyt={tokenize:qyt,partial:!0};function Pyt(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:zyt,continuation:{tokenize:Byt},exit:Uyt}},text:{91:{name:"gfmFootnoteCall",tokenize:Fyt},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:Lyt,resolveTo:$yt}}}}function Lyt(e,t,n){const r=this;let s=r.events.length;const a=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let o;for(;s--;){const c=r.events[s][1];if(c.type==="labelImage"){o=c;break}if(c.type==="gfmFootnoteCall"||c.type==="labelLink"||c.type==="label"||c.type==="image"||c.type==="link")break}return l;function l(c){if(!o||!o._balanced)return n(c);const u=Zu(r.sliceSerialize({start:o.end,end:r.now()}));return u.codePointAt(0)!==94||!a.includes(u.slice(1))?n(c):(e.enter("gfmFootnoteCallLabelMarker"),e.consume(c),e.exit("gfmFootnoteCallLabelMarker"),t(c))}}function $yt(e,t){let n=e.length;for(;n--;)if(e[n][1].type==="labelImage"&&e[n][0]==="enter"){e[n][1];break}e[n+1][1].type="data",e[n+3][1].type="gfmFootnoteCallLabelMarker";const r={type:"gfmFootnoteCall",start:Object.assign({},e[n+3][1].start),end:Object.assign({},e[e.length-1][1].end)},s={type:"gfmFootnoteCallMarker",start:Object.assign({},e[n+3][1].end),end:Object.assign({},e[n+3][1].end)};s.end.column++,s.end.offset++,s.end._bufferIndex++;const a={type:"gfmFootnoteCallString",start:Object.assign({},s.end),end:Object.assign({},e[e.length-1][1].start)},o={type:"chunkString",contentType:"string",start:Object.assign({},a.start),end:Object.assign({},a.end)},l=[e[n+1],e[n+2],["enter",r,t],e[n+3],e[n+4],["enter",s,t],["exit",s,t],["enter",a,t],["enter",o,t],["exit",o,t],["exit",a,t],e[e.length-2],e[e.length-1],["exit",r,t]];return e.splice(n,e.length-n+1,...l),e}function Fyt(e,t,n){const r=this,s=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let a=0,o;return l;function l(h){return e.enter("gfmFootnoteCall"),e.enter("gfmFootnoteCallLabelMarker"),e.consume(h),e.exit("gfmFootnoteCallLabelMarker"),c}function c(h){return h!==94?n(h):(e.enter("gfmFootnoteCallMarker"),e.consume(h),e.exit("gfmFootnoteCallMarker"),e.enter("gfmFootnoteCallString"),e.enter("chunkString").contentType="string",u)}function u(h){if(a>999||h===93&&!o||h===null||h===91||qr(h))return n(h);if(h===93){e.exit("chunkString");const m=e.exit("gfmFootnoteCallString");return s.includes(Zu(r.sliceSerialize(m)))?(e.enter("gfmFootnoteCallLabelMarker"),e.consume(h),e.exit("gfmFootnoteCallLabelMarker"),e.exit("gfmFootnoteCall"),t):n(h)}return qr(h)||(o=!0),a++,e.consume(h),h===92?d:u}function d(h){return h===91||h===92||h===93?(e.consume(h),a++,u):u(h)}}function zyt(e,t,n){const r=this,s=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let a,o=0,l;return c;function c(b){return e.enter("gfmFootnoteDefinition")._container=!0,e.enter("gfmFootnoteDefinitionLabel"),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(b),e.exit("gfmFootnoteDefinitionLabelMarker"),u}function u(b){return b===94?(e.enter("gfmFootnoteDefinitionMarker"),e.consume(b),e.exit("gfmFootnoteDefinitionMarker"),e.enter("gfmFootnoteDefinitionLabelString"),e.enter("chunkString").contentType="string",d):n(b)}function d(b){if(o>999||b===93&&!l||b===null||b===91||qr(b))return n(b);if(b===93){e.exit("chunkString");const v=e.exit("gfmFootnoteDefinitionLabelString");return a=Zu(r.sliceSerialize(v)),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(b),e.exit("gfmFootnoteDefinitionLabelMarker"),e.exit("gfmFootnoteDefinitionLabel"),m}return qr(b)||(l=!0),o++,e.consume(b),b===92?h:d}function h(b){return b===91||b===92||b===93?(e.consume(b),o++,d):d(b)}function m(b){return b===58?(e.enter("definitionMarker"),e.consume(b),e.exit("definitionMarker"),s.includes(a)||s.push(a),Ar(e,g,"gfmFootnoteDefinitionWhitespace")):n(b)}function g(b){return t(b)}}function Byt(e,t,n){return e.check($C,t,e.attempt(Dyt,t,n))}function Uyt(e){e.exit("gfmFootnoteDefinition")}function qyt(e,t,n){const r=this;return Ar(e,s,"gfmFootnoteDefinitionIndent",5);function s(a){const o=r.events[r.events.length-1];return o&&o[1].type==="gfmFootnoteDefinitionIndent"&&o[2].sliceSerialize(o[1],!0).length===4?t(a):n(a)}}function Vyt(e){return mge([Syt(),Pyt(),Ape(e),wxe(),gxe()])}const Hyt={};function Kyt(e){const t=this,n=e||Hyt,r=t.data(),s=r.micromarkExtensions||(r.micromarkExtensions=[]),a=r.fromMarkdownExtensions||(r.fromMarkdownExtensions=[]),o=r.toMarkdownExtensions||(r.toMarkdownExtensions=[]);s.push(Vyt(n)),a.push(kyt()),o.push(jyt(n))}const hke="rudder.theme",tne="#1f1f1d",nne="#f1f0ef",mke=x.createContext(void 0);function Wyt(){return typeof window>"u"?null:window.desktopShell??null}function pke(){return typeof window>"u"||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}function rne(){if(typeof window>"u")return"system";try{const e=window.localStorage.getItem(hke);if(e==="light"||e==="dark"||e==="system")return e}catch{}return"system"}function X5(e){return e==="system"?pke():e}function sne(e){var a,o;if(typeof document>"u")return;const n=X5(e)==="dark",r=document.documentElement;r.classList.toggle("dark",n),r.style.colorScheme=n?"dark":"light",r.style.backgroundColor=r.classList.contains("desktop-shell-macos")?"transparent":n?tne:nne;const s=document.querySelector('meta[name="theme-color"]');s instanceof HTMLMetaElement&&s.setAttribute("content",n?tne:nne),(o=(a=Wyt())==null?void 0:a.setAppearance)==null||o.call(a,e)}function Gyt({children:e}){const[t,n]=x.useState(()=>rne()),[r,s]=x.useState(()=>X5(rne())),a=x.useCallback(c=>{n(c)},[]),o=x.useCallback(()=>{n(c=>X5(c)==="dark"?"light":"dark")},[]);x.useEffect(()=>{sne(t),s(X5(t));try{localStorage.setItem(hke,t)}catch{}},[t]),x.useEffect(()=>{if(typeof window>"u")return;const c=window.matchMedia("(prefers-color-scheme: dark)"),u=()=>{if(t!=="system")return;const d=pke();s(d),sne("system")};return c.addEventListener("change",u),()=>{c.removeEventListener("change",u)}},[t]);const l=x.useMemo(()=>({theme:t,resolvedTheme:r,setTheme:a,toggleTheme:o}),[t,r,a,o]);return i.jsx(mke.Provider,{value:l,children:e})}function gke(){const e=x.useContext(mke);if(!e)throw new Error("useTheme must be used within ThemeProvider");return e}const Qyt=190,Yyt=178;function Jyt(e,t){return typeof window>"u"?{left:e,top:t}:{left:Math.min(e,Math.max(8,window.innerWidth-Qyt)),top:Math.min(t,Math.max(8,window.innerHeight-Yyt))}}function Zyt(e){return e instanceof Error?e.message:String(e)}function Xyt(){try{return gr()}catch{return null}}function e0t({alt:e,className:t,name:n,onInspect:r,src:s,...a}){const o=Xyt(),l=x.useRef(null),c=x.useRef(null),[u,d]=x.useState(null),h=jU();x.useEffect(()=>{if(!u)return;const v=k=>{var w;(w=l.current)!=null&&w.contains(k.target)||d(null)},j=k=>{k.key==="Escape"&&d(null)};return document.addEventListener("pointerdown",v),document.addEventListener("keydown",j),()=>{document.removeEventListener("pointerdown",v),document.removeEventListener("keydown",j)}},[u]);const m=()=>{const v=c.current;!v||!r||r(v)},g=v=>{v.preventDefault(),v.stopPropagation(),d(Jyt(v.clientX,v.clientY))},b=async(v,j,k)=>{d(null);try{await j(),k&&(o==null||o.pushToast({title:k,tone:"success"}))}catch(w){o==null||o.pushToast({title:v,body:Zyt(w),tone:"error"})}};return i.jsxs("span",{className:"rudder-inspectable-image",children:[i.jsxs("button",{type:"button",className:"rudder-inspectable-image-trigger","aria-label":`Open image preview: ${n}`,title:"Open image preview",onClick:m,onDoubleClick:m,onContextMenu:g,children:[i.jsx("img",{...a,ref:c,src:s,alt:e??"",className:t,onContextMenu:g}),i.jsx("span",{className:"rudder-inspectable-image-overlay","aria-hidden":"true",children:i.jsx(Wh,{className:"size-3.5"})})]}),u&&typeof document<"u"?Fa.createPortal(i.jsxs("div",{ref:l,"data-testid":"markdown-image-context-menu",role:"menu",className:"motion-chat-composer-menu-pop surface-overlay fixed z-50 min-w-[190px] rounded-[var(--radius-lg)] border p-1.5 text-foreground shadow-[var(--shadow-lg)]",style:u,children:[i.jsxs("button",{type:"button",role:"menuitem",className:"chat-composer-menu-row w-full",onClick:()=>b("Open Image failed",()=>Yve(s)),children:[i.jsx(Kl,{className:"h-3.5 w-3.5 shrink-0"}),i.jsx("span",{className:"min-w-0 flex-1 truncate",children:"Open Image"})]}),i.jsxs("button",{type:"button",role:"menuitem",className:"chat-composer-menu-row w-full",onClick:()=>b("Copy Image failed",()=>wU(s,n),"Image copied"),children:[i.jsx(xi,{className:"h-3.5 w-3.5 shrink-0"}),i.jsx("span",{className:"min-w-0 flex-1 truncate",children:"Copy Image"})]}),i.jsxs("button",{type:"button",role:"menuitem",className:"chat-composer-menu-row w-full",onClick:()=>b("Download Image failed",()=>Jve(s,n)),children:[i.jsx(wf,{className:"h-3.5 w-3.5 shrink-0"}),i.jsx("span",{className:"min-w-0 flex-1 truncate",children:"Download Image"})]}),h?i.jsxs("button",{type:"button",role:"menuitem",className:"chat-composer-menu-row w-full",onClick:()=>b("Open in Finder failed",()=>kU(s,n)),children:[i.jsx(Ic,{className:"h-3.5 w-3.5 shrink-0"}),i.jsx("span",{className:"min-w-0 flex-1 truncate",children:"Open in Finder"})]}):null]}),document.body):null]})}function t0t({label:e,preview:t}){var c,u,d,h,m;const n=((c=t==null?void 0:t.displayName)==null?void 0:c.trim())||e,r=((u=t==null?void 0:t.description)==null?void 0:u.trim())||null,s=((d=t==null?void 0:t.categoryLabel)==null?void 0:d.trim())||null,a=((h=t==null?void 0:t.locationLabel)==null?void 0:h.trim())||null,o=((m=t==null?void 0:t.detailsHref)==null?void 0:m.trim())||null,l=!!(r||s||a||o);return i.jsxs("span",{className:Q("rudder-skill-token-wrap",l&&"rudder-skill-token-wrap--preview"),children:[i.jsx("span",{className:"rudder-skill-token","data-skill-token":"true",tabIndex:l?0:void 0,"aria-label":l?`${n} skill`:void 0,children:e}),l?i.jsxs("span",{className:"rudder-skill-hover-card",role:"tooltip",children:[i.jsxs("span",{className:"flex items-start gap-3",children:[i.jsx("span",{className:"mt-0.5 flex h-7 w-7 shrink-0 items-center justify-center rounded-[var(--radius-md)] bg-[#2f80ed]/10 text-[#2f80ed]",children:i.jsx(mu,{className:"h-4 w-4","aria-hidden":!0})}),i.jsxs("span",{className:"min-w-0 flex-1",children:[i.jsx("span",{className:"block truncate text-sm font-medium text-foreground",children:n}),s||a?i.jsxs("span",{className:"mt-1.5 flex min-w-0 flex-wrap items-center gap-1.5",children:[s?i.jsx("span",{className:"inline-flex items-center rounded-[var(--radius-sm)] border border-border/70 bg-muted/50 px-1.5 py-0.5 text-[11px] font-medium leading-none text-muted-foreground",children:s}):null,a?i.jsx("span",{className:"min-w-0 truncate text-[11px] leading-none text-muted-foreground",children:a}):null]}):null,r?i.jsx("span",{className:"mt-1 block text-xs leading-5 text-muted-foreground",children:r}):null]})]}),o?i.jsxs("a",{className:"rudder-skill-hover-card-action",href:o,children:[i.jsx("span",{children:"View details"}),i.jsx(ig,{className:"h-3.5 w-3.5","aria-hidden":!0})]}):null]}):null]})}let dP=null;function n0t(){return dP||(dP=ut(()=>import("./mermaid.core-CfGzrCcV.js").then(e=>e.bF),[]).then(e=>e.default)),dP}function Rj(e){return e==null?"":typeof e=="string"||typeof e=="number"?String(e):Array.isArray(e)?e.map(t=>Rj(t)).join(""):""}function Y_(e){return(e==null?void 0:e.trim().replace(/\/+$/u,"").toLowerCase())??""}function r0t(e){const t=(e==null?void 0:e.trim())??"";if(!t)return!1;if(t.startsWith("//"))return!0;if(!/^[a-z][a-z\d+.-]*:/iu.test(t))return!1;try{const n=new URL(t);return n.protocol==="http:"||n.protocol==="https:"||n.protocol==="mailto:"}catch{return!1}}function s0t(e){const t=e.trim();return/^(?:https?:\/\/|www\.|\/\/)/iu.test(t)}function i0t(e){if(!x.isValidElement(e))return null;const t=e.props;return typeof t.className!="string"||!/\blanguage-mermaid\b/i.test(t.className)?null:Rj(t.children).replace(/\n$/,"")}function a0t(e){const t=e.alt.trim();if(t)return t;const n=e.currentSrc||e.src;try{const s=new URL(n,window.location.href).pathname.split("/").filter(Boolean).at(-1);return s?decodeURIComponent(s):"Image preview"}catch{return"Image preview"}}function o0t(e){var o,l;if(!e.includes("\\n"))return e;const t=((o=e.match(/\\n/g))==null?void 0:o.length)??0;if(t===0)return e;const n=((l=e.match(/\n/g))==null?void 0:l.length)??0,r=e.includes("\\n\\n"),s=/\\n\s*(?:[-*+]\s|\d+\.\s)/.test(e),a=n===0&&t>=3;return!r&&!s&&!a?e:e.replace(/\\r\\n/g,`
1348
1348
  `).replace(/\\n/g,`
1349
1349
  `)}function l0t({source:e,darkMode:t}){const n=x.useId().replace(/[^a-zA-Z0-9_-]/g,""),[r,s]=x.useState(null),[a,o]=x.useState(null);return x.useEffect(()=>{let l=!0;return s(null),o(null),n0t().then(async c=>{c.initialize({startOnLoad:!1,securityLevel:"strict",theme:t?"dark":"default",fontFamily:"inherit",suppressErrorRendering:!0});const u=await c.render(`rudder-mermaid-${n}`,e);l&&s(u.svg)}).catch(c=>{if(!l)return;const u=c instanceof Error&&c.message?c.message:"Failed to render Mermaid diagram.";o(u)}),()=>{l=!1}},[t,n,e]),i.jsx("div",{className:"rudder-mermaid",children:r?i.jsx("div",{dangerouslySetInnerHTML:{__html:r}}):i.jsxs(i.Fragment,{children:[i.jsx("p",{className:Q("rudder-mermaid-status",a&&"rudder-mermaid-status-error"),children:a?`Unable to render Mermaid diagram: ${a}`:"Rendering Mermaid diagram..."}),i.jsx("pre",{className:"rudder-mermaid-source",children:i.jsx("code",{className:"language-mermaid",children:e})})]})})}function gi({children:e,className:t,resolveImageSrc:n,onLinkClick:r,skillReferences:s,enableImagePreview:a=!0}){const{resolvedTheme:o}=gke(),[l,c]=x.useState(null),u=new Map((s??[]).map(b=>[Y_(b.href),b]).filter(([b])=>b.length>0)),d=new Map((s??[]).map(b=>[Y_(b.label),b]).filter(([b])=>b.length>0)),h=o0t(e),m=b=>{if(!a)return;const v=b.currentSrc||b.src;v&&c({alt:b.alt,name:a0t(b),src:v,naturalSize:b.naturalWidth>0&&b.naturalHeight>0?{width:b.naturalWidth,height:b.naturalHeight}:null})},g={pre:({node:b,children:v,...j})=>{const k=i0t(v);return k?i.jsx(l0t,{source:k,darkMode:o==="dark"}):i.jsx("pre",{...j,children:v})},a:({href:b,children:v})=>{const j=b?K1(b):null;if(j){const A=tS(Rj(v)),_=j.kind==="project"?`/projects/${j.projectId}`:j.kind==="issue"?`/issues/${j.ref??j.issueId}`:`/agents/${j.agentId}`;return i.jsx("a",{href:_,className:Q("rudder-mention-chip",`rudder-mention-chip--${j.kind}`,j.kind==="project"&&"rudder-project-mention-chip"),"data-mention-kind":j.kind,style:Zve(j),children:A})}const k=q3(b,Rj(v));if(k){const A=u.get(Y_(k.href))??d.get(Y_(k.label))??null;return i.jsx(t0t,{label:k.label,preview:A})}const w=Rj(v),N=r0t(b),S=N&&s0t(w);return i.jsx("a",{href:b,target:N?"_blank":void 0,rel:N?"noreferrer noopener":"noreferrer",title:S?b:void 0,onClick:A=>{!b||!r||r({event:A,href:b,label:w})},children:v})}};return g.img=({node:b,src:v,alt:j,...k})=>{const N=(v&&n?n(v):null)??v??"";return a&&N?i.jsx(e0t,{...k,src:N,alt:j??"",name:(j==null?void 0:j.trim())||"Markdown image",onInspect:m}):i.jsx("img",{...k,src:N,alt:j??""})},i.jsxs(i.Fragment,{children:[i.jsx("div",{className:Q("rudder-markdown prose prose-sm max-w-none break-words overflow-hidden",o==="dark"&&"prose-invert",t),children:i.jsx(qbt,{remarkPlugins:[Kyt],components:g,urlTransform:b=>b,children:h})}),a?i.jsx(NU,{preview:l,onOpenChange:b=>{b||c(null)},testId:"markdown-body-image-preview-dialog",titleFallback:"Image preview"}):null]})}const c0t=new Set(["README","README.md","package.json","pnpm-lock.yaml","tsconfig.json","vite.config.ts","vitest.config.ts","playwright.config.ts","Dockerfile","Makefile","LICENSE"]),u0t=new Set(["apply_patch","patch","ed","tee","mv","cp","rm","mkdir","touch"]),d0t=900,f0t=8,h0t=["/Users/","/home/","/Volumes/","/tmp/","/var/","/opt/","/mnt/","/private/"];function $i(e){return typeof e!="object"||e===null||Array.isArray(e)?null:e}function m0t(e){try{const t=new URL(e);if(t.protocol!=="file:")return null;const n=decodeURIComponent(t.pathname);return/^\/[A-Za-z]:\//.test(n)?n.slice(1):n}catch{return null}}function p0t(e){const t=e==null?void 0:e.trim();if(!t)return null;const n=/^file:/i.test(t)?m0t(t):null;return n||(/^[A-Za-z]:[\\/]/.test(t)||/^\\\\[^\\]+\\[^\\]+/.test(t)?t:/^[a-z][a-z0-9+.-]*:/i.test(t)||t.startsWith("//")?null:h0t.some(r=>t.startsWith(r))?t:null)}function g0t(e){return e.button===0&&!e.altKey&&!e.ctrlKey&&!e.metaKey&&!e.shiftKey}function Oi(e){return e.replace(/\s+/g," ").trim()}function x0t(e){return Oi(e).toLowerCase()==="turn started"}function b0t(e){return!!(/^\[rudder\] Prepared local CLI credential shim(?:s)? for: .+$/.test(e)||/^\[rudder\] Agent workspace ".+" is now the canonical run workspace\. Attempting to resume session ".+" .+$/.test(e)||/^\[rudder\] .+ session ".+" was saved for cwd ".+" and will not be resumed in ".+"\.$/.test(e))}function y0t(e,t){return t?e.trim():e.split(/\r?\n/).filter(n=>{const r=n.trim();return!(b0t(r)||/^\[rudder\] Using Rudder-managed .+ home ".+"(?: \(seeded from ".+"\))?\.$/.test(r)||/^\[rudder\] Prepared isolated Git config at .+ with user\.useConfigOnly=true \(.+\)\.$/.test(r)||/^\[rudder\] Prepared repository Git config in .+ with user\.useConfigOnly=true \(.+\)\.$/.test(r)||/^\[rudder\] Realized \d+ Rudder-managed .+ skill entries in .+$/.test(r)||/^\[rudder\] Loaded agent (?:instructions|soul instructions|tool notes|memory instructions) file: .+$/.test(r))}).join(`
1350
1350
  `).trim()}function v0t(e){const t=e.trim();return/^WARN\b/i.test(t)||/^\d{4}-\d{2}-\d{2}T[^\s]+\s+WARN\s+/i.test(t)}function w0t(e){return/WARN\s+codex_analytics::analytics_client:\s+events failed with status 403 Forbidden:\s+<html>/i.test(e.trim())}function k0t(e,t){if(t!=null&&t.showDeveloperDiagnostics)return e;let n=!1;const r=[];for(const s of e){if(s.kind==="init")continue;if(s.kind!=="stderr"){r.push(s);continue}const a=[];for(const l of s.text.split(/\r?\n/)){const c=l.trim();if(n){/^<\/html>$/i.test(c)&&(n=!1);continue}if(w0t(c)){n=!0;continue}v0t(c)||a.push(l)}const o=a.join(`
@@ -1372,7 +1372,7 @@ ${Qn(r.inputTokens)} / ${Qn(r.outputTokens)} / $${r.costUsd.toFixed(6)}`:r.kind=
1372
1372
  `)){const r=n.trim();if(r)try{const s=JSON.parse(r),a=s.stream==="stderr"||s.stream==="system"?s.stream:"stdout",o=typeof s.chunk=="string"?s.chunk:"",l=typeof s.ts=="string"?s.ts:new Date().toISOString();if(!o)continue;t.push({ts:l,stream:a,chunk:o})}catch{}}return t}function V1t({events:e,censorUsernameInLogs:t}){if(e.length===0)return null;const n={info:"text-foreground",warn:"text-yellow-600 dark:text-yellow-400",error:"text-red-600 dark:text-red-400"},r={stdout:"text-foreground",stderr:"text-red-600 dark:text-red-300",system:"text-blue-600 dark:text-blue-300"};return i.jsxs("div",{children:[i.jsxs("div",{className:"mb-2 text-xs font-medium text-muted-foreground",children:["Events (",e.length,")"]}),i.jsx("div",{className:"rounded-lg bg-neutral-100 p-3 font-mono text-xs space-y-0.5 dark:bg-neutral-950",children:e.map(s=>{const a=s.color??(s.level?n[s.level]:null)??(s.stream?r[s.stream]:null)??"text-foreground",o=hje(s,{redactText:l=>iu(l,t),redactValue:l=>fp(l,t)});return i.jsxs("div",{className:"flex gap-2",children:[i.jsx("span",{className:"text-neutral-400 dark:text-neutral-600 shrink-0 select-none w-16",children:new Date(s.createdAt).toLocaleTimeString("en-US",{hourCycle:"h23"})}),i.jsx("span",{className:Q("shrink-0 w-14",s.stream?r[s.stream]??"text-neutral-500":"text-neutral-500"),children:s.stream?`[${s.stream}]`:""}),i.jsx("span",{className:Q("break-all",a),children:o})]},s.id)})})]})}function H1t(e){switch(e){case"worktree_prepare":return"Worktree setup";case"workspace_provision":return"Provision";case"workspace_teardown":return"Teardown";case"worktree_cleanup":return"Worktree cleanup";default:return e}}function K1t(e){switch(e){case"succeeded":return"border-green-500/20 bg-green-500/10 text-green-700 dark:text-green-300";case"failed":return"border-red-500/20 bg-red-500/10 text-red-700 dark:text-red-300";case"running":return"border-cyan-500/20 bg-cyan-500/10 text-cyan-700 dark:text-cyan-300";case"skipped":return"border-yellow-500/20 bg-yellow-500/10 text-yellow-700 dark:text-yellow-300";default:return"border-border bg-muted/40 text-muted-foreground"}}function W1t({status:e}){return i.jsx("span",{className:Q("inline-flex items-center rounded-full border px-2 py-0.5 text-[11px] font-medium capitalize",K1t(e)),children:e.replace("_"," ")})}function G1t({operation:e,censorUsernameInLogs:t}){const[n,r]=x.useState(!1),{data:s,isLoading:a,error:o}=ke({queryKey:["workspace-operation-log",e.id],queryFn:()=>us.workspaceOperationLog(e.id),enabled:n&&!!e.logRef,refetchInterval:n&&e.status==="running"?2e3:!1}),l=x.useMemo(()=>s!=null&&s.content?q1t(s.content):[],[s==null?void 0:s.content]);return i.jsxs("div",{className:"space-y-2",children:[i.jsx("button",{type:"button",className:"text-[11px] text-muted-foreground underline underline-offset-2 hover:text-foreground",onClick:()=>r(c=>!c),children:n?"Hide full log":"Show full log"}),n&&i.jsxs("div",{className:"rounded-md border border-border bg-background/70 p-2",children:[a&&i.jsx("div",{className:"text-xs text-muted-foreground",children:"Loading log..."}),o&&i.jsx("div",{className:"text-xs text-destructive",children:o instanceof Error?o.message:"Failed to load workspace operation log"}),!a&&!o&&l.length===0&&i.jsx("div",{className:"text-xs text-muted-foreground",children:"No persisted log lines."}),l.length>0&&i.jsx("div",{className:"max-h-64 overflow-y-auto rounded bg-neutral-100 p-2 font-mono text-xs dark:bg-neutral-950",children:l.map((c,u)=>i.jsxs("div",{className:"flex gap-2",children:[i.jsx("span",{className:"shrink-0 text-neutral-500",children:new Date(c.ts).toLocaleTimeString("en-US",{hourCycle:"h23"})}),i.jsxs("span",{className:Q("shrink-0 w-14",c.stream==="stderr"?"text-red-600 dark:text-red-300":c.stream==="system"?"text-blue-600 dark:text-blue-300":"text-muted-foreground"),children:["[",c.stream,"]"]}),i.jsx("span",{className:"whitespace-pre-wrap break-all",children:iu(c.chunk,t)})]},`${c.ts}-${u}`))})]})]})}function Q1t({operations:e,censorUsernameInLogs:t}){return e.length===0?null:i.jsxs("div",{className:"rounded-lg border border-border bg-background/60 p-3 space-y-3",children:[i.jsxs("div",{className:"text-xs font-medium text-muted-foreground",children:["Workspace (",e.length,")"]}),i.jsx("div",{className:"space-y-3",children:e.map(n=>{const r=Ku(n.metadata);return i.jsxs("div",{className:"rounded-md border border-border/70 bg-background/70 p-3 space-y-2",children:[i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i.jsx("div",{className:"text-sm font-medium",children:H1t(n.phase)}),i.jsx(W1t,{status:n.status}),i.jsxs("div",{className:"text-[11px] text-muted-foreground",children:[hs(n.startedAt),n.finishedAt&&` to ${hs(n.finishedAt)}`]})]}),n.command&&i.jsxs("div",{className:"text-xs break-all",children:[i.jsx("span",{className:"text-muted-foreground",children:"Command: "}),i.jsx("span",{className:"font-mono",children:n.command})]}),n.cwd&&i.jsxs("div",{className:"text-xs break-all",children:[i.jsx("span",{className:"text-muted-foreground",children:"Working dir: "}),i.jsx("span",{className:"font-mono",children:n.cwd})]}),(os(r==null?void 0:r.branchName)||os(r==null?void 0:r.baseRef)||os(r==null?void 0:r.worktreePath)||os(r==null?void 0:r.repoRoot)||os(r==null?void 0:r.cleanupAction))&&i.jsxs("div",{className:"grid gap-1 text-xs sm:grid-cols-2",children:[os(r==null?void 0:r.branchName)&&i.jsxs("div",{children:[i.jsx("span",{className:"text-muted-foreground",children:"Branch: "}),i.jsx("span",{className:"font-mono",children:r==null?void 0:r.branchName})]}),os(r==null?void 0:r.baseRef)&&i.jsxs("div",{children:[i.jsx("span",{className:"text-muted-foreground",children:"Base ref: "}),i.jsx("span",{className:"font-mono",children:r==null?void 0:r.baseRef})]}),os(r==null?void 0:r.worktreePath)&&i.jsxs("div",{className:"break-all",children:[i.jsx("span",{className:"text-muted-foreground",children:"Worktree: "}),i.jsx("span",{className:"font-mono",children:r==null?void 0:r.worktreePath})]}),os(r==null?void 0:r.repoRoot)&&i.jsxs("div",{className:"break-all",children:[i.jsx("span",{className:"text-muted-foreground",children:"Repo root: "}),i.jsx("span",{className:"font-mono",children:r==null?void 0:r.repoRoot})]}),os(r==null?void 0:r.cleanupAction)&&i.jsxs("div",{children:[i.jsx("span",{className:"text-muted-foreground",children:"Cleanup: "}),i.jsx("span",{className:"font-mono",children:r==null?void 0:r.cleanupAction})]})]}),typeof(r==null?void 0:r.created)=="boolean"&&i.jsx("div",{className:"text-xs text-muted-foreground",children:r.created?"Created by this run":"Reused existing workspace"}),n.stderrExcerpt&&n.stderrExcerpt.trim()&&i.jsxs("div",{children:[i.jsx("div",{className:"mb-1 text-xs text-red-700 dark:text-red-300",children:"stderr excerpt"}),i.jsx("pre",{className:"rounded-md bg-red-50 p-2 text-xs whitespace-pre-wrap break-all text-red-800 dark:bg-neutral-950 dark:text-red-100",children:iu(n.stderrExcerpt,t)})]}),n.stdoutExcerpt&&n.stdoutExcerpt.trim()&&i.jsxs("div",{children:[i.jsx("div",{className:"mb-1 text-xs text-muted-foreground",children:"stdout excerpt"}),i.jsx("pre",{className:"rounded-md bg-neutral-100 p-2 text-xs whitespace-pre-wrap break-all dark:bg-neutral-950",children:iu(n.stdoutExcerpt,t)})]}),n.logRef&&i.jsx(G1t,{operation:n,censorUsernameInLogs:t})]},n.id)})})]})}function kP(){const{orgPrefix:e,agentId:t,tab:n,runId:r}=ki(),{organizations:s,selectedOrganizationId:a,setSelectedOrganizationId:o}=bn(),{closePanel:l}=VI(),{openNewIssue:c}=Gr(),{setBreadcrumbs:u}=Nr(),d=xn(),h=Dr(),[m,g]=x.useState(null),[b,v]=x.useState(!1),[j,k]=x.useState(!1),w=r?"runs":L1t(n??null),N=w==="dashboard",A=N||(w==="runs"||!!r),[_,E]=x.useState("7d"),[I,O]=x.useState(!1),[M,D]=x.useState(""),[z,F]=x.useState(""),[K,J]=x.useState(!1),[$,L]=x.useState(!1),H=x.useRef(null),W=x.useRef(null),{isMobile:B}=Hi(),Y=t??"",V=x.useMemo(()=>{var We;return e?((We=u1({organizations:s,organizationPrefix:e}))==null?void 0:We.id)??null:null},[s,e])??a??void 0,ce=Y.length>0&&(F7(Y)||!!V),le=x.useCallback(We=>{H.current=We},[]),G=x.useCallback(We=>{W.current=We},[]),{data:te,isLoading:ge,error:ie}=ke({queryKey:[...U.agents.detail(Y),V??null],queryFn:()=>$t.get(Y,V),enabled:ce}),ae=(te==null?void 0:te.orgId)??a,he=te?Oh(te):Y,me=(te==null?void 0:te.id)??Y,ye=(te==null?void 0:te.id)??null,{data:Me}=ke({queryKey:U.agents.runtimeState(ye??Y),queryFn:()=>$t.runtimeState(ye,ae??void 0),enabled:!!ye&&N}),{from:$e,to:Re,customReady:Ue}=x.useMemo(()=>{const We=new Date;if(_==="custom"){const Lt=M?new Date(`${M}T00:00:00`):null,He=z?new Date(`${z}T23:59:59.999`):null;return{from:Lt?Lt.toISOString():"",to:He?He.toISOString():"",customReady:!!M&&!!z}}const Ct=_==="7d"?7:_==="15d"?15:30;return{from:new Date(We.getFullYear(),We.getMonth(),We.getDate()-(Ct-1),0,0,0,0).toISOString(),to:We.toISOString(),customReady:!0}},[M,z,_]),we=x.useMemo(()=>_==="7d"?vP(7):_==="15d"?vP(15):_==="30d"?vP(30):j1t(M,z),[M,z,_]),ze=x.useMemo(()=>N1t(_,M,z),[M,z,_]),{data:oe}=ke({queryKey:[...U.agents.skillsAnalytics(ye??Y),_,M,z],queryFn:()=>$t.skillsAnalytics(ye,{orgId:ae??void 0,..._==="custom"&&Ue?{startDate:M,endDate:z}:{windowDays:_==="7d"?7:_==="15d"?15:30}}),enabled:!!ye&&N&&(_!=="custom"||Ue)}),{data:xe}=ke({queryKey:U.heartbeats(ae,(te==null?void 0:te.id)??void 0),queryFn:()=>us.list(ae,(te==null?void 0:te.id)??void 0),enabled:!!ae&&!!(te!=null&&te.id)&&A}),{data:X}=ke({queryKey:[...U.issues.list(ae),"participant-agent",ye??"__none__"],queryFn:()=>fn.list(ae,{participantAgentId:ye}),enabled:!!ae&&!!ye&&N}),{data:q}=ke({queryKey:U.agents.list(ae),queryFn:()=>$t.list(ae),enabled:!!ae&&N}),{data:ue}=ke({queryKey:U.budgets.overview(ae??"__none__"),queryFn:()=>db.overview(ae),enabled:!!ae,refetchInterval:3e4,staleTime:5e3}),je=(X??[]).sort((We,Ct)=>new Date(Ct.updatedAt).getTime()-new Date(We.updatedAt).getTime()),re=x.useMemo(()=>(xe??[]).filter(We=>Nne(We.createdAt,$e,Re)),[$e,xe,Re]),fe=x.useMemo(()=>je.filter(We=>Nne(We.createdAt,$e,Re)),[je,$e,Re]),ne=x.useCallback(We=>{if(We==="custom"){if(!M||!z){const Ct=new Date,Dt=new Date(Ct.getFullYear(),Ct.getMonth(),Ct.getDate()-6);D(gT(Dt)),F(gT(Ct))}E("custom"),O(!0);return}O(!1),E(We)},[M,z]);(q??[]).find(We=>We.id===(te==null?void 0:te.reportsTo)),(q??[]).filter(We=>We.reportsTo===(te==null?void 0:te.id)&&We.status!=="terminated");const Fe=x.useMemo(()=>{const We=ue==null?void 0:ue.policies.find(Lt=>Lt.scopeType==="agent"&&Lt.scopeId===((te==null?void 0:te.id)??Y));if(We)return We;const Ct=(te==null?void 0:te.budgetMonthlyCents)??0,Dt=(te==null?void 0:te.spentMonthlyCents)??0;return{policyId:"",orgId:ae??"",scopeType:"agent",scopeId:(te==null?void 0:te.id)??Y,scopeName:(te==null?void 0:te.name)??"Agent",metric:"billed_cents",windowKind:"calendar_month_utc",amount:Ct,observedAmount:Dt,remainingAmount:Math.max(0,Ct-Dt),utilizationPercent:Ct>0?Number((Dt/Ct*100).toFixed(2)):0,warnPercent:80,hardStopEnabled:!0,notifyEnabled:!0,isActive:Ct>0,status:Ct>0&&Dt>=Ct?"hard_stop":"ok",paused:(te==null?void 0:te.status)==="paused",pauseReason:(te==null?void 0:te.pauseReason)??null,windowStart:new Date,windowEnd:new Date}},[te,ue==null?void 0:ue.policies,ae,Y]),Ce=x.useMemo(()=>(xe??[]).find(We=>We.status==="running"||We.status==="queued")??null,[xe]);x.useEffect(()=>{if(!te)return;if(r){Y!==he&&h(`/agents/${he}/runs/${r}`,{replace:!0});return}const We=w==="instructions"?"instructions":w==="configuration"?"configuration":w==="skills"?"skills":w==="runs"?"runs":w==="budget"?"budget":"dashboard";if(Y!==he||n!==We){h(`/agents/${he}/${We}`,{replace:!0});return}},[te,Y,he,r,n,w,h]),x.useEffect(()=>{!(te!=null&&te.orgId)||te.orgId===a||o(te.orgId,{source:"route_sync"})},[te==null?void 0:te.orgId,a,o]);const tt=nt({mutationFn:async We=>{if(!me)return Promise.reject(new Error("No agent reference"));switch(We){case"invoke":return $t.invoke(me,ae??void 0);case"pause":return $t.pause(me,ae??void 0);case"resume":return $t.resume(me,ae??void 0);case"terminate":return $t.terminate(me,ae??void 0)}},onSuccess:(We,Ct)=>{g(null),Ct==="terminate"&&k(!1),d.invalidateQueries({queryKey:U.agents.detail(Y)}),d.invalidateQueries({queryKey:U.agents.detail(me)}),d.invalidateQueries({queryKey:U.agents.runtimeState(me)}),d.invalidateQueries({queryKey:U.agents.taskSessions(me)}),ae&&(d.invalidateQueries({queryKey:U.agents.list(ae)}),te!=null&&te.id&&d.invalidateQueries({queryKey:U.heartbeats(ae,te.id)})),Ct==="invoke"&&We&&typeof We=="object"&&"id"in We&&h(`/agents/${he}/runs/${We.id}`)},onError:We=>{g(We instanceof Error?We.message:"Action failed")}}),Qe=nt({mutationFn:We=>db.upsertPolicy(ae,{scopeType:"agent",scopeId:(te==null?void 0:te.id)??Y,amount:We,windowKind:"calendar_month_utc"}),onSuccess:()=>{ae&&(d.invalidateQueries({queryKey:U.budgets.overview(ae)}),d.invalidateQueries({queryKey:U.agents.detail(Y)}),d.invalidateQueries({queryKey:U.agents.detail(me)}),d.invalidateQueries({queryKey:U.agents.list(ae)}),d.invalidateQueries({queryKey:U.dashboard(ae)}))}}),pt=nt({mutationFn:We=>$t.update(me,{icon:We},ae??void 0),onSuccess:()=>{g(null),d.invalidateQueries({queryKey:U.agents.detail(Y)}),d.invalidateQueries({queryKey:U.agents.detail(me)}),ae&&d.invalidateQueries({queryKey:U.agents.list(ae)})},onError:We=>{g(We instanceof Error?We.message:"Failed to update avatar")}}),Se=nt({mutationFn:We=>$t.uploadAvatar(me,We,ae??void 0),onSuccess:()=>{g(null),d.invalidateQueries({queryKey:U.agents.detail(Y)}),d.invalidateQueries({queryKey:U.agents.detail(me)}),ae&&d.invalidateQueries({queryKey:U.agents.list(ae)})},onError:We=>{g(We instanceof Error?We.message:"Failed to upload avatar")}}),Be=nt({mutationFn:We=>$t.resetSession(me,We,ae??void 0),onSuccess:()=>{g(null),d.invalidateQueries({queryKey:U.agents.runtimeState(me)}),d.invalidateQueries({queryKey:U.agents.taskSessions(me)})},onError:We=>{g(We instanceof Error?We.message:"Failed to reset session")}}),Ae=nt({mutationFn:We=>$t.updatePermissions(me,We,ae??void 0),onSuccess:()=>{g(null),d.invalidateQueries({queryKey:U.agents.detail(Y)}),d.invalidateQueries({queryKey:U.agents.detail(me)}),ae&&d.invalidateQueries({queryKey:U.agents.list(ae)})},onError:We=>{g(We instanceof Error?We.message:"Failed to update permissions")}});if(x.useEffect(()=>{const We=[{label:"Agents",href:"/agents"}],Ct=(te==null?void 0:te.name)??Y??"Agent";w==="dashboard"&&!r?We.push({label:Ct}):(We.push({label:Ct,href:`/agents/${he}/dashboard`}),r?(We.push({label:"Runs",href:`/agents/${he}/runs`}),We.push({label:`Run ${r.slice(0,8)}`})):w==="instructions"?We.push({label:"Instructions"}):w==="configuration"?We.push({label:"Configuration"}):w==="runs"?We.push({label:"Runs"}):w==="budget"?We.push({label:"Budget"}):We.push({label:"Dashboard"})),u(We)},[u,te,Y,he,w,r]),x.useEffect(()=>(l(),()=>l()),[l]),b_e(x.useCallback(We=>{K&&(We.preventDefault(),We.returnValue="")},[K])),ge)return i.jsx(Is,{variant:"detail"});if(ie)return i.jsx("p",{className:"text-sm text-destructive",children:ie.message});if(!te)return null;if(!r&&!n)return i.jsx(ls,{to:`/agents/${he}/dashboard`,replace:!0});const it=te.status==="pending_approval",Je=(w==="configuration"||w==="instructions")&&(K||$),jt=jC(te.icon);return i.jsxs(i.Fragment,{children:[i.jsx(Bs,{open:j,onOpenChange:k,children:i.jsxs(Ys,{className:"sm:max-w-md",children:[i.jsxs(ma,{children:[i.jsx(Ui,{children:"Terminate agent"}),i.jsx(Ba,{children:"Stop this agent permanently. This action cannot be undone."})]}),i.jsxs("div",{className:"space-y-3 text-sm text-muted-foreground",children:[i.jsxs("p",{children:[i.jsx("span",{className:"font-medium text-foreground",children:te.name})," will be marked as terminated and can no longer run or resume."]}),i.jsx("p",{children:"Future heartbeats will stay disabled until you create or replace it."})]}),i.jsxs(Fo,{children:[i.jsx(de,{variant:"ghost",onClick:()=>k(!1),disabled:tt.isPending,children:"Cancel"}),i.jsx(de,{variant:"destructive",onClick:()=>tt.mutate("terminate"),disabled:tt.isPending,children:tt.isPending?"Terminating...":"Terminate"})]})]})}),i.jsxs("div",{className:Q("space-y-6",B&&Je&&"pb-24"),children:[i.jsxs("div",{className:"flex items-center justify-between gap-2",children:[i.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[i.jsx(S7e,{value:te.icon,onChange:We=>pt.mutate(We),onUpload:We=>Se.mutate(We),uploadPending:Se.isPending,uploadError:Se.error instanceof Error?Se.error.message:null,children:i.jsx("button",{className:Q("shrink-0 flex h-12 w-12 items-center justify-center transition-colors",jt?"overflow-hidden rounded-full hover:opacity-85":"rounded-lg bg-accent hover:bg-accent/80"),"aria-label":"Change agent avatar",children:i.jsx(ks,{icon:te.icon,role:te.role,className:jt?"h-full w-full":"h-7 w-7"})})}),i.jsxs("div",{className:"min-w-0",children:[i.jsx("h2",{className:"text-2xl font-bold truncate",children:te.name}),i.jsxs("p",{className:"text-sm text-muted-foreground truncate",children:[oT[te.role]??te.role,te.title?` - ${te.title}`:""]})]})]}),i.jsxs("div",{className:"flex items-center gap-1 sm:gap-2 shrink-0",children:[i.jsxs(de,{variant:"outline",size:"sm",onClick:()=>c({assigneeAgentId:te.id}),children:[i.jsx(Hn,{className:"h-3.5 w-3.5 sm:mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:"Assign Task"})]}),i.jsx(de,{variant:"outline",size:"sm",asChild:!0,children:i.jsxs(Nt,{to:{pathname:"/messenger/chat",search:`?agentId=${encodeURIComponent(te.id)}`},children:[i.jsx(Ko,{className:"h-3.5 w-3.5 sm:mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:"Chat"})]})}),i.jsx(o1t,{onClick:()=>tt.mutate("invoke"),disabled:tt.isPending||it,label:"Run Heartbeat"}),i.jsx(l1t,{isPaused:te.status==="paused",onPause:()=>tt.mutate("pause"),onResume:()=>tt.mutate("resume"),disabled:tt.isPending||it}),i.jsx("span",{className:"hidden sm:inline",children:i.jsx(yr,{status:te.status})}),Ce&&i.jsxs(Nt,{to:`/agents/${he}/runs/${Ce.id}`,className:"sm:hidden flex items-center gap-1.5 px-2 py-0.5 rounded-full bg-blue-500/10 hover:bg-blue-500/20 transition-colors no-underline",children:[i.jsxs("span",{className:"relative flex h-2 w-2",children:[i.jsx("span",{className:"animate-pulse absolute inline-flex h-full w-full rounded-full bg-blue-400 opacity-75"}),i.jsx("span",{className:"relative inline-flex rounded-full h-2 w-2 bg-blue-500"})]}),i.jsx("span",{className:"text-[11px] font-medium text-blue-600 dark:text-blue-400",children:"Live"})]}),i.jsxs(cr,{open:b,onOpenChange:v,children:[i.jsx(mr,{asChild:!0,children:i.jsx(de,{variant:"ghost",size:"icon-xs","aria-label":"Agent actions",children:i.jsx(Ac,{className:"h-4 w-4"})})}),i.jsxs(ur,{className:"w-44 p-1",align:"end",children:[i.jsxs("button",{className:"flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50",onClick:()=>{navigator.clipboard.writeText(te.id),v(!1)},children:[i.jsx(xi,{className:"h-3 w-3"}),"Copy Agent ID"]}),i.jsxs("button",{className:"flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50",onClick:()=>{Be.mutate(null),v(!1)},children:[i.jsx(Ev,{className:"h-3 w-3"}),"Reset Sessions"]}),i.jsxs("button",{className:"flex items-center gap-2 w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50 text-destructive",onClick:()=>{v(!1),k(!0)},children:[i.jsx(ha,{className:"h-3 w-3"}),"Terminate"]})]})]})]})]}),!r&&i.jsx(Xu,{value:w,onValueChange:We=>h(`/agents/${he}/${We}`),children:i.jsxs("div",{className:"flex items-start justify-between gap-4",children:[i.jsx(Jp,{items:[{value:"dashboard",label:"Dashboard"},{value:"instructions",label:"Instructions"},{value:"skills",label:"Skills"},{value:"configuration",label:"Configuration"},{value:"runs",label:"Runs"},{value:"budget",label:"Budget"}],value:w,onValueChange:We=>h(`/agents/${he}/${We}`)}),w==="dashboard"?i.jsx("div",{className:"hidden lg:block shrink-0",children:i.jsx(e9,{preset:_,customFrom:M,customTo:z,customOpen:I,onCustomOpenChange:O,onPresetSelect:ne,onCustomFromChange:D,onCustomToChange:F})}):null]})}),m&&i.jsx("p",{className:"text-sm text-destructive",children:m}),it&&i.jsx("p",{className:"text-sm text-amber-500",children:"This agent is pending board approval and cannot be invoked yet."}),!B&&i.jsx("div",{className:Q("sticky top-6 z-10 float-right transition-opacity duration-150",Je?"opacity-100":"opacity-0 pointer-events-none"),children:i.jsxs("div",{className:"flex items-center gap-2 bg-background/90 backdrop-blur-sm border border-border rounded-lg px-3 py-1.5 shadow-lg",children:[i.jsx(de,{variant:"ghost",size:"sm",onClick:()=>{var We;return(We=W.current)==null?void 0:We.call(W)},disabled:$,children:"Cancel"}),i.jsx(de,{size:"sm",onClick:()=>{var We;return(We=H.current)==null?void 0:We.call(H)},disabled:$,children:$?"Saving…":"Save"})]})}),B&&Je&&i.jsx("div",{className:"fixed inset-x-0 bottom-0 z-30 border-t border-border bg-background/95 backdrop-blur-sm",children:i.jsxs("div",{className:"flex items-center justify-end gap-2 px-3 py-2",style:{paddingBottom:"max(env(safe-area-inset-bottom), 0.5rem)"},children:[i.jsx(de,{variant:"ghost",size:"sm",onClick:()=>{var We;return(We=W.current)==null?void 0:We.call(W)},disabled:$,children:"Cancel"}),i.jsx(de,{size:"sm",onClick:()=>{var We;return(We=H.current)==null?void 0:We.call(H)},disabled:$,children:$?"Saving…":"Save"})]})}),w==="dashboard"&&i.jsx(J1t,{agent:te,runs:xe??[],chartRuns:re,assignedIssues:je,chartIssues:fe,runtimeState:Me,skillAnalytics:oe,agentId:te.id,agentRouteId:he,rangeLabel:ze,chartDays:we,showDashboardFilters:_!=="custom"||Ue,dateFilterControl:i.jsx("div",{className:"lg:hidden",children:i.jsx(e9,{preset:_,customFrom:M,customTo:z,customOpen:I,onCustomOpenChange:O,onPresetSelect:ne,onCustomFromChange:D,onCustomToChange:F})})}),w==="instructions"&&i.jsx(twt,{agent:te,orgId:ae??void 0,onDirtyChange:J,onSaveActionChange:le,onCancelActionChange:G,onSavingChange:L}),w==="configuration"&&i.jsx(X1t,{agent:te,agentId:te.id,orgId:ae??void 0,onDirtyChange:J,onSaveActionChange:le,onCancelActionChange:G,onSavingChange:L,updatePermissions:Ae}),w==="skills"&&i.jsx(rwt,{agent:te,orgId:ae??void 0}),w==="runs"&&i.jsx(swt,{runs:xe??[],orgId:ae,agentId:te.id,agentRouteId:he,selectedRunId:r??null,agentRuntimeType:te.agentRuntimeType}),w==="budget"&&ae?i.jsx("div",{className:"max-w-3xl",children:i.jsx(lq,{summary:Fe,isSaving:Qe.isPending,onSave:We=>Qe.mutate(We),variant:"plain"})}):null]})]})}function hq(e){const[t,n]=x.useState(()=>Date.now());return x.useEffect(()=>{if(!e)return;const r=window.setInterval(()=>n(Date.now()),1e3);return()=>window.clearInterval(r)},[e]),t}function Y1t({runs:e,agentId:t}){const n=hq(e.some(g=>g.status==="running"||g.status==="queued"));if(e.length===0)return null;const r=[...e].sort((g,b)=>new Date(b.createdAt).getTime()-new Date(g.createdAt).getTime()),a=r.find(g=>g.status==="running"||g.status==="queued")??r[0],o=a.status==="running"||a.status==="queued",l=mje[a.status]??{icon:R3,color:"text-neutral-400"},c=l.icon,u=lje(a),d=uq(a,n)??hs(a.createdAt),h=dq(a),m=a.resultJson?String(a.resultJson.summary??a.resultJson.result??""):a.error??"";return i.jsxs("div",{className:"space-y-3",children:[i.jsxs("div",{className:"flex w-full items-center justify-between",children:[i.jsxs("h3",{className:"flex items-center gap-2 text-sm font-medium",children:[o&&i.jsxs("span",{className:"relative flex h-2 w-2",children:[i.jsx("span",{className:"animate-pulse absolute inline-flex h-full w-full rounded-full bg-cyan-400 opacity-75"}),i.jsx("span",{className:"relative inline-flex rounded-full h-2 w-2 bg-cyan-400"})]}),o?"Live Run":"Latest Run"]}),i.jsx(Nt,{to:`/agents/${t}/runs/${a.id}`,className:"shrink-0 text-xs text-muted-foreground hover:text-foreground transition-colors no-underline",children:"View details →"})]}),i.jsxs(Nt,{to:`/agents/${t}/runs/${a.id}`,className:Q("block border rounded-lg p-4 space-y-2 w-full no-underline transition-colors hover:bg-muted/50 cursor-pointer",o?"border-cyan-500/30 shadow-[0_0_12px_rgba(6,182,212,0.08)]":"border-border"),children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(c,{className:Q("h-3.5 w-3.5",l.color,a.status==="running"&&"animate-spin")}),i.jsx(yr,{status:a.status}),i.jsx("span",{className:"font-mono text-xs text-muted-foreground",children:a.id.slice(0,8)}),i.jsx("span",{className:Q("inline-flex items-center rounded-full px-1.5 py-0.5 text-[10px] font-medium",cje(u.tone)),title:u.description,children:u.label}),i.jsx("span",{className:"ml-auto shrink-0 text-xs font-medium tabular-nums text-foreground",title:h||void 0,children:d})]}),m&&i.jsx("div",{className:"overflow-hidden max-h-16",children:i.jsx(gi,{className:"[&>*:first-child]:mt-0 [&>*:last-child]:mb-0",children:m})})]})]})}function J1t({agent:e,runs:t,chartRuns:n,assignedIssues:r,chartIssues:s,runtimeState:a,skillAnalytics:o,agentId:l,agentRouteId:c,rangeLabel:u,chartDays:d,showDashboardFilters:h,dateFilterControl:m}){const g=o&&o.totalRunsWithSkills>0?o:null,b=g!==null;return i.jsxs("div",{className:"space-y-8",children:[m,i.jsx(Y1t,{runs:t,agentId:c}),i.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4",children:[i.jsx(Op,{title:"Run Activity",subtitle:`${u} · relative daily run volume · hover for details`,children:i.jsx(Jke,{runs:n,days:d})}),i.jsx(Op,{title:"Issues by Priority",subtitle:`${u} · relative daily issue volume · hover for details`,children:i.jsx(Zke,{issues:s,days:d})}),i.jsx(Op,{title:"Issues by Status",subtitle:`${u} · relative daily issue volume · hover for details`,children:i.jsx(Xke,{issues:s,days:d})}),i.jsx(Op,{title:"Success Rate",subtitle:`${u} · daily success rate · hover for details`,children:i.jsx(eje,{runs:n,days:d})})]}),h&&b?i.jsxs("div",{className:"space-y-3",children:[i.jsxs("div",{className:"flex items-end justify-between gap-3",children:[i.jsxs("div",{children:[i.jsx("h3",{className:"text-sm font-medium",children:"Skills"}),i.jsxs("p",{className:"mt-0.5 text-xs text-muted-foreground",children:["Skill usage per run for ",u,". Hover a day to inspect the breakdown."]})]}),i.jsxs("div",{className:"text-right text-[11px] text-muted-foreground tabular-nums",children:[i.jsxs("div",{children:[g.totalCount," skill uses"]}),i.jsxs("div",{children:[g.totalRunsWithSkills," runs with skill usage"]})]})]}),i.jsx(tje,{analytics:g})]}):null,i.jsxs("div",{className:"space-y-3",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("h3",{className:"text-sm font-medium",children:"Recent Issues"}),i.jsx(Nt,{to:`/issues?participantAgentId=${l}`,className:"text-xs text-muted-foreground hover:text-foreground transition-colors",children:"See All →"})]}),r.length===0?i.jsx("p",{className:"text-sm text-muted-foreground",children:"No recent issues."}):i.jsxs("div",{className:"border border-border rounded-lg",children:[r.slice(0,10).map(v=>i.jsx(Yd,{identifier:v.identifier??v.id.slice(0,8),title:v.title,to:`/issues/${v.identifier??v.id}`,trailing:i.jsx(yr,{status:v.status})},v.id)),r.length>10&&i.jsxs("div",{className:"px-3 py-2 text-xs text-muted-foreground text-center border-t border-border",children:["+",r.length-10," more issues"]})]})]}),i.jsxs("div",{className:"space-y-3",children:[i.jsx("h3",{className:"text-sm font-medium",children:"Costs"}),i.jsx(Z1t,{runtimeState:a,runs:t,agentRouteId:c})]})]})}function Z1t({runtimeState:e,runs:t,agentRouteId:n}){const r=t.map(d=>({run:d,metrics:fq(d)})).filter(({metrics:d})=>d.cost>0||d.input>0||d.output>0||d.cached>0).sort((d,h)=>new Date(h.run.createdAt).getTime()-new Date(d.run.createdAt).getTime()).slice(0,10),s=Math.max(1,...r.map(({metrics:d})=>d.totalTokens)),[a,o]=x.useState(null),l=Math.round(s/2),c=e?ul({inputTokens:e.totalInputTokens,cachedInputTokens:e.totalCachedInputTokens,outputTokens:e.totalOutputTokens}):null,u=e?z1t(e.totalCachedInputTokens,e.totalInputTokens):"—";return i.jsxs("div",{className:"space-y-4",children:[e&&i.jsx("div",{className:"border border-border rounded-lg p-4",children:i.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-5 gap-4 tabular-nums",children:[i.jsxs("div",{children:[i.jsx("span",{className:"text-xs text-muted-foreground block",children:"Prompt input"}),i.jsx("span",{className:"text-lg font-semibold",children:Qn((c==null?void 0:c.promptTokens)??e.totalInputTokens)})]}),i.jsxs("div",{children:[i.jsx("span",{className:"text-xs text-muted-foreground block",children:"Output tokens"}),i.jsx("span",{className:"text-lg font-semibold",children:Qn(e.totalOutputTokens)})]}),i.jsxs("div",{children:[i.jsx("span",{className:"text-xs text-muted-foreground block",children:"Cached input"}),i.jsx("span",{className:"text-lg font-semibold",children:Qn(e.totalCachedInputTokens)})]}),i.jsxs("div",{title:"Cached input tokens divided by total prompt input tokens.",children:[i.jsx("span",{className:"text-xs text-muted-foreground block",children:"Cache ratio"}),i.jsx("span",{className:"text-lg font-semibold",children:u})]}),i.jsxs("div",{children:[i.jsx("span",{className:"text-xs text-muted-foreground block",children:"Total cost"}),i.jsx("span",{className:"text-lg font-semibold",children:Nn(e.totalCostCents)})]})]})}),r.length>0?i.jsxs("div",{className:"overflow-hidden rounded-lg border border-border","data-testid":"agent-run-cost-chart",children:[i.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 border-b border-border bg-accent/20 px-3 py-2 text-xs text-muted-foreground",children:[i.jsx("span",{children:"Recent run token mix"}),i.jsxs("div",{className:"flex items-center gap-3","data-testid":"agent-run-cost-legend",children:[i.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[i.jsx("span",{className:"h-2 w-2 rounded-sm bg-sky-500"}),"Uncached input"]}),i.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[i.jsx("span",{className:"h-2 w-2 rounded-sm bg-violet-500"}),"Cached input"]}),i.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[i.jsx("span",{className:"h-2 w-2 rounded-sm bg-emerald-500"}),"Output"]})]})]}),i.jsx("div",{className:"divide-y divide-border",children:r.map(({run:d,metrics:h})=>{const m=h.totalTokens,g=m>0?Math.max(7,m/s*100):0,b=m>0?h.uncachedInput/m*100:0,v=m>0?h.cached/m*100:0,j=m>0?h.output/m*100:0,k=wP(h.uncachedInput,s),w=wP(h.cached,s),N=wP(h.output,s),S=d.id.slice(0,8),A=B1t(h.cost),_=`Run ${S} cost and token usage: ${Pd(m)} total, ${Pd(h.promptTokens)} prompt input, ${Pd(h.uncachedInput)} uncached input, ${Pd(h.cached)} cached input, ${Pd(h.output)} output, ${A} cost`;return i.jsx(Mf,{delayDuration:120,children:i.jsxs(ca,{open:a===d.id,children:[i.jsx(ua,{asChild:!0,children:i.jsxs(Nt,{to:`/agents/${n}/runs/${d.id}`,"aria-label":_,"data-testid":"agent-run-cost-row",onFocus:()=>o(d.id),onBlur:()=>o(E=>E===d.id?null:E),onMouseEnter:()=>o(d.id),onMouseLeave:E=>{E.currentTarget!==document.activeElement&&o(I=>I===d.id?null:I)},className:"group grid grid-cols-[minmax(5.5rem,7rem)_minmax(0,1fr)_auto] items-center gap-3 px-3 py-3 text-xs no-underline text-inherit outline-none transition-colors hover:bg-accent/25 focus-visible:bg-accent/25 focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",children:[i.jsxs("span",{className:"min-w-0 space-y-0.5",children:[i.jsx("span",{className:"block truncate text-muted-foreground",children:po(d.createdAt)}),i.jsx("span",{className:"block font-mono tabular-nums text-foreground",children:S})]}),i.jsx("span",{className:"relative h-9 rounded-sm bg-muted/45",style:{backgroundImage:"linear-gradient(to right, hsl(var(--border) / 0.75) 1px, transparent 1px)",backgroundSize:"25% 100%"},children:i.jsxs("span",{className:"relative z-10 flex h-full overflow-hidden rounded-sm border border-background/50 shadow-sm transition-opacity group-hover:opacity-95 group-focus-visible:opacity-95",style:{width:`${g}%`},children:[h.uncachedInput>0?i.jsx("span",{className:"flex h-full min-w-0 items-center justify-center bg-sky-500/80 px-1 font-mono text-[11px] font-semibold tabular-nums text-white",style:{width:`${b}%`},children:k?Qn(h.uncachedInput):null}):null,h.cached>0?i.jsx("span",{className:"flex h-full min-w-0 items-center justify-center bg-violet-500/80 px-1 font-mono text-[11px] font-semibold tabular-nums text-white",style:{width:`${v}%`},children:w?Qn(h.cached):null}):null,h.output>0?i.jsx("span",{className:"flex h-full min-w-0 items-center justify-center bg-emerald-500/80 px-1 font-mono text-[11px] font-semibold tabular-nums text-white",style:{width:`${j}%`},children:N?Qn(h.output):null}):null]})}),i.jsxs("span",{className:"min-w-[8.75rem] text-right tabular-nums",children:[i.jsx("span",{className:"block font-medium text-foreground",children:gje(m)}),i.jsxs("span",{className:"block font-mono text-[10px] text-muted-foreground",children:["in ",Qn(h.promptTokens)," · cache ",Qn(h.cached)," · out ",Qn(h.output)]}),h.cost>0?i.jsx("span",{className:"block font-mono text-[11px] text-muted-foreground",children:A}):null]})]})}),i.jsx(da,{side:"top",align:"end",sideOffset:8,className:"w-72 p-3 text-xs",children:i.jsxs("div",{className:"space-y-2",children:[i.jsxs("div",{children:[i.jsxs("div",{className:"font-medium text-background",children:["Run ",S]}),i.jsx("div",{className:"font-mono text-[11px] text-background/70",children:d.id}),i.jsx("div",{className:"text-background/70",children:pi(d.createdAt)})]}),i.jsxs("dl",{className:"grid grid-cols-[1fr_auto] gap-x-4 gap-y-1.5",children:[i.jsx("dt",{className:"text-background/70",children:"Total tokens"}),i.jsx("dd",{className:"font-mono tabular-nums",children:Pd(m)}),i.jsx("dt",{className:"text-background/70",children:"Prompt input"}),i.jsx("dd",{className:"font-mono tabular-nums",children:Pd(h.promptTokens)}),i.jsx("dt",{className:"text-background/70",children:"Uncached input"}),i.jsx("dd",{className:"font-mono tabular-nums",children:Pd(h.uncachedInput)}),i.jsx("dt",{className:"text-background/70",children:"Cached input"}),i.jsx("dd",{className:"font-mono tabular-nums",children:Pd(h.cached)}),i.jsx("dt",{className:"text-background/70",children:"Output"}),i.jsx("dd",{className:"font-mono tabular-nums",children:Pd(h.output)}),i.jsx("dt",{className:"text-background/70",children:"Cost"}),i.jsx("dd",{className:"font-mono tabular-nums",children:A})]})]})})]})},d.id)})}),i.jsxs("div",{className:"grid grid-cols-[minmax(5.5rem,7rem)_minmax(0,1fr)_minmax(7rem,auto)] gap-3 border-t border-border px-3 py-2 text-[10px] text-muted-foreground",children:[i.jsx("span",{}),i.jsxs("div",{className:"flex justify-between tabular-nums",children:[i.jsx("span",{children:"0"}),i.jsx("span",{children:Qn(l)}),i.jsx("span",{children:Qn(s)})]}),i.jsx("span",{className:"text-right",children:"Token scale"})]})]}):i.jsx("p",{className:"rounded-lg border border-dashed border-border px-3 py-4 text-sm text-muted-foreground",children:"No run cost or token data yet."})]})}function X1t({agent:e,agentId:t,orgId:n,onDirtyChange:r,onSaveActionChange:s,onCancelActionChange:a,onSavingChange:o,updatePermissions:l}){const c=xn(),[u,d]=x.useState(!1),{data:h}=ke({queryKey:U.agents.configRevisions(e.id),queryFn:()=>$t.listConfigRevisions(e.id,n)}),m=nt({mutationFn:g=>$t.rollbackConfigRevision(e.id,g,n),onSuccess:()=>{c.invalidateQueries({queryKey:U.agents.detail(e.id)}),c.invalidateQueries({queryKey:U.agents.detail(e.urlKey)}),c.invalidateQueries({queryKey:U.agents.configRevisions(e.id)})}});return i.jsxs("div",{className:"max-w-3xl space-y-6",children:[i.jsx(ewt,{agent:e,onDirtyChange:r,onSaveActionChange:s,onCancelActionChange:a,onSavingChange:o,updatePermissions:l,orgId:n,hidePromptTemplate:!0,hideInstructionsFile:!0}),i.jsxs("div",{children:[i.jsx("h3",{className:"text-sm font-medium mb-3",children:"API Keys"}),i.jsx(awt,{agentId:t,orgId:n})]}),i.jsxs("div",{children:[i.jsxs("button",{className:"flex items-center gap-2 text-sm font-medium hover:text-foreground transition-colors",onClick:()=>d(g=>!g),children:[u?i.jsx(Vr,{className:"h-3.5 w-3.5 text-muted-foreground"}):i.jsx(Us,{className:"h-3.5 w-3.5 text-muted-foreground"}),"Configuration Revisions",i.jsx("span",{className:"text-xs font-normal text-muted-foreground",children:(h==null?void 0:h.length)??0})]}),u&&i.jsx("div",{className:"mt-3",children:(h??[]).length===0?i.jsx("p",{className:"text-sm text-muted-foreground",children:"No configuration revisions yet."}):i.jsx("div",{className:"space-y-2",children:(h??[]).slice(0,10).map(g=>i.jsxs("div",{className:"border border-border/70 rounded-md p-3 space-y-2",children:[i.jsxs("div",{className:"flex items-center justify-between gap-3",children:[i.jsxs("div",{className:"text-xs text-muted-foreground",children:[i.jsx("span",{className:"font-mono",children:g.id.slice(0,8)}),i.jsx("span",{className:"mx-1",children:"·"}),i.jsx("span",{children:po(g.createdAt)}),i.jsx("span",{className:"mx-1",children:"·"}),i.jsx("span",{children:g.source})]}),i.jsx(de,{size:"sm",variant:"outline",className:"h-7 px-2.5 text-xs",onClick:()=>m.mutate(g.id),disabled:m.isPending,children:"Restore"})]}),i.jsxs("p",{className:"text-xs text-muted-foreground",children:["Changed:"," ",g.changedKeys.length>0?g.changedKeys.join(", "):"no tracked changes"]})]},g.id))})})]})]})}function ewt({agent:e,orgId:t,onDirtyChange:n,onSaveActionChange:r,onCancelActionChange:s,onSavingChange:a,updatePermissions:o,hidePromptTemplate:l,hideInstructionsFile:c}){var _,E,I;const u=xn(),{pushToast:d}=gr(),[h,m]=x.useState(!1),g=x.useRef(e),{data:b}=ke({queryKey:t?U.agents.adapterModels(t,e.agentRuntimeType):["agents","none","adapter-models",e.agentRuntimeType],queryFn:()=>$t.adapterModels(t,e.agentRuntimeType),enabled:!!t}),v=nt({mutationFn:O=>$t.update(e.id,O,t),onMutate:()=>{m(!0)},onSuccess:()=>{u.invalidateQueries({queryKey:U.agents.detail(e.id)}),u.invalidateQueries({queryKey:U.agents.detail(e.urlKey)}),u.invalidateQueries({queryKey:U.agents.configRevisions(e.id)}),u.invalidateQueries({queryKey:U.agents.list(e.orgId)})},onError:O=>{m(!1);const M=O instanceof bl||O instanceof Error?O.message:"Could not save agent";d({title:"Save failed",body:M,tone:"error"})}});x.useEffect(()=>{h&&e!==g.current&&m(!1),g.current=e},[e,h]);const j=v.isPending||h;x.useEffect(()=>{a(j)},[a,j]);const k=!!((_=e.permissions)!=null&&_.canCreateAgents),w=!!((E=e.access)!=null&&E.canAssignTasks),N=((I=e.access)==null?void 0:I.taskAssignSource)??"none",S=e.role==="ceo"||k,A=N==="ceo_role"?"Enabled automatically for CEO agents.":N==="agent_creator"?"Enabled automatically while this agent can create new agents.":N==="explicit_grant"?"Enabled via explicit organization permission grant.":"Disabled unless explicitly granted.";return i.jsxs("div",{className:"space-y-6",children:[i.jsx(UU,{mode:"edit",agent:e,onSave:O=>v.mutate(O),isSaving:j,adapterModels:b,onDirtyChange:n,onSaveActionChange:r,onCancelActionChange:s,hideInlineSave:!0,hidePromptTemplate:l,hideInstructionsFile:c,sectionLayout:"cards"}),i.jsxs("div",{children:[i.jsx("h3",{className:"text-sm font-medium mb-3",children:"Permissions"}),i.jsxs("div",{className:"border border-border rounded-lg p-4 space-y-4",children:[i.jsxs("div",{className:"flex items-center justify-between gap-4 text-sm",children:[i.jsxs("div",{className:"space-y-1",children:[i.jsx("div",{children:"Can create new agents"}),i.jsx("p",{className:"text-xs text-muted-foreground",children:"Lets this agent create or hire agents and implicitly assign tasks."})]}),i.jsx(ug,{checked:k,size:"sm",tone:"success","aria-label":"Can create new agents",className:"shrink-0",onClick:()=>o.mutate({canCreateAgents:!k,canAssignTasks:k?w:!0}),disabled:o.isPending})]}),i.jsxs("div",{className:"flex items-center justify-between gap-4 text-sm",children:[i.jsxs("div",{className:"space-y-1",children:[i.jsx("div",{children:"Can assign tasks"}),i.jsx("p",{className:"text-xs text-muted-foreground",children:A})]}),i.jsx(ug,{checked:w,size:"sm",tone:"success","aria-label":"Can assign tasks",className:"shrink-0",onClick:()=>o.mutate({canCreateAgents:k,canAssignTasks:!w}),disabled:o.isPending||S})]})]})]})]})}const xx="SOUL.md";function twt({agent:e,orgId:t,onDirtyChange:n,onSaveActionChange:r,onCancelActionChange:s,onSavingChange:a}){const o=xn(),{selectedOrganizationId:l}=bn(),{isMobile:c}=Hi(),[u,d]=x.useState(xx),[h,m]=x.useState(!1),[g,b]=x.useState(null),[v,j]=x.useState(null),[k,w]=x.useState(""),[N,S]=x.useState(!1),[A,_]=x.useState([]),[E,I]=x.useState(new Set),[O,M]=x.useState(260),D=x.useRef(null),[z,F]=x.useState(!1),K=x.useRef(null),J=x.useRef(null);x.useEffect(()=>{d(xx),m(!1),b(null),j(null),w(""),S(!1),_([]),I(new Set),F(!1),K.current=null,J.current=null},[e.id]);const $=e.agentRuntimeType==="claude_local"||e.agentRuntimeType==="codex_local"||e.agentRuntimeType==="opencode_local"||e.agentRuntimeType==="pi_local"||e.agentRuntimeType==="hermes_local"||e.agentRuntimeType==="cursor",{data:L,isLoading:H}=ke({queryKey:U.agents.instructionsBundle(e.id),queryFn:()=>$t.instructionsBundle(e.id,t),enabled:!!(t&&$)}),W=(L==null?void 0:L.mode)??"managed",B=W==="managed"?(L==null?void 0:L.managedRootPath)??(L==null?void 0:L.rootPath)??"":(L==null?void 0:L.rootPath)??"",Y=(v==null?void 0:v.mode)??W,P=(v==null?void 0:v.entryFile)??(L==null?void 0:L.entryFile)??xx,V=(v==null?void 0:v.rootPath)??B,ce=x.useMemo(()=>(L==null?void 0:L.files.map(q=>q.path))??[],[L]),le=!!(L&&Y===W&&P===L.entryFile&&V===B),G=x.useMemo(()=>le?[...new Set([P,...ce,...A])]:[P,...A],[le,P,ce,A]),te=x.useMemo(()=>fb(Object.fromEntries(G.map(q=>[q,""]))),[G]),ge=u||P,ie=le&&ce.includes(ge),ae=(L==null?void 0:L.files.find(q=>q.path===ge))??null,{data:he,isLoading:me}=ke({queryKey:U.agents.instructionsFile(e.id,ge),queryFn:()=>$t.instructionsFile(e.id,ge,t),enabled:!!(t&&$&&ie)}),ye=nt({mutationFn:q=>$t.updateInstructionsBundle(e.id,q,t),onMutate:()=>F(!0),onSuccess:()=>{o.invalidateQueries({queryKey:U.agents.instructionsBundle(e.id)}),o.invalidateQueries({queryKey:U.agents.detail(e.id)}),o.invalidateQueries({queryKey:U.agents.detail(e.urlKey)})},onError:()=>F(!1)}),Me=nt({mutationFn:q=>$t.saveInstructionsFile(e.id,q,t),onMutate:()=>F(!0),onSuccess:(q,ue)=>{_(je=>je.filter(re=>re!==ue.path)),o.invalidateQueries({queryKey:U.agents.instructionsBundle(e.id)}),o.invalidateQueries({queryKey:U.agents.instructionsFile(e.id,ue.path)}),o.invalidateQueries({queryKey:U.agents.detail(e.id)}),o.invalidateQueries({queryKey:U.agents.detail(e.urlKey)})},onError:()=>F(!1)}),$e=nt({mutationFn:async({file:q,namespace:ue})=>{if(!l)throw new Error("Select a organization to upload images");return sy.uploadImage(l,q,ue)}});x.useEffect(()=>{if(!L)return;if(!le){u!==P&&d(P);return}const q=L.files.map(ue=>ue.path);if(q.length===0){u!==L.entryFile&&d(L.entryFile);return}!q.includes(u)&&u!==P&&!A.includes(u)&&d(q.includes(L.entryFile)?L.entryFile:q[0])},[L,le,P,A,u]),x.useEffect(()=>{const q=new Set;for(const ue of G){const je=ue.split("/");let re="";for(let fe=0;fe<je.length-1;fe++)re=re?`${re}/${je[fe]}`:je[fe],q.add(re)}I(ue=>$1t(ue,q)?ue:q)},[G]),x.useEffect(()=>{const q=ie&&he?`${he.path}:${he.content}`:`draft:${Y}:${V}:${ge}`;if(z){F(!1),j(null),b(null),K.current=q;return}K.current!==q&&(b(null),K.current=q)},[z,Y,V,he,ie,ge]),x.useEffect(()=>{L&&j(q=>q||{mode:W,rootPath:B,entryFile:L.entryFile})},[L,W,B]),x.useEffect(()=>{!L||Y!=="external"||(J.current={rootPath:V,entryFile:P,selectedFile:ge})},[L,P,Y,V,ge]);const Re=ie?(he==null?void 0:he.content)??"":"",Ue=g??Re,we=!!(v&&(v.mode!==W||v.rootPath!==B||v.entryFile!==((L==null?void 0:L.entryFile)??xx))),ze=g!==null&&g!==Re,oe=we||ze,xe=ye.isPending||Me.isPending||z;x.useEffect(()=>{a(xe)},[a,xe]),x.useEffect(()=>{n(oe)},[n,oe]),x.useEffect(()=>{r(oe?()=>{(async()=>{const ue=!!(L!=null&&L.legacyPromptTemplateActive)||!!(L!=null&&L.legacyBootstrapPromptTemplateActive);we&&v&&await ye.mutateAsync({mode:v.mode,rootPath:v.mode==="external"?v.rootPath:null,entryFile:v.entryFile}),ze&&await Me.mutateAsync({path:ge,content:Ue,clearLegacyPromptTemplate:ue})})().catch(()=>{})}:null)},[L,we,v,Ue,ze,oe,r,Me,ge,ye]),x.useEffect(()=>{s(oe?()=>{b(null),L&&j({mode:W,rootPath:B,entryFile:L.entryFile})}:null)},[L,oe,s,W,B]);const X=x.useCallback(q=>{q.preventDefault();const ue=q.clientX,je=O,re=ne=>{const Fe=ne.clientX-ue,Ce=Math.max(180,Math.min(500,je+Fe));M(Ce)},fe=()=>{document.removeEventListener("mousemove",re),document.removeEventListener("mouseup",fe),document.body.style.cursor="",document.body.style.userSelect=""};document.addEventListener("mousemove",re),document.addEventListener("mouseup",fe),document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[O]);return $?H&&!L?i.jsx(nwt,{}):i.jsxs("div",{className:"max-w-6xl space-y-6",children:[((L==null?void 0:L.warnings)??[]).length>0&&i.jsx("div",{className:"space-y-2",children:((L==null?void 0:L.warnings)??[]).map(q=>i.jsx("div",{className:Q("rounded-md border px-3 py-2 text-xs",eR.info),children:q},q))}),i.jsxs(fy,{defaultOpen:Y==="external",children:[i.jsxs(ZI,{className:"flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors group",children:[i.jsx(Us,{className:"h-3 w-3 transition-transform group-data-[state=open]:rotate-90"}),"Advanced"]}),i.jsx(hy,{className:"pt-4 pb-6",children:i.jsx(Mf,{children:i.jsxs("div",{className:"grid gap-x-6 gap-y-4 sm:grid-cols-[auto_1fr_1fr]",children:[i.jsxs("label",{className:"space-y-1.5",children:[i.jsxs("span",{className:"text-xs font-medium text-muted-foreground flex items-center gap-1",children:["Mode",i.jsxs(ca,{children:[i.jsx(ua,{asChild:!0,children:i.jsx(eb,{className:"h-3 w-3 text-muted-foreground cursor-help"})}),i.jsx(da,{side:"right",sideOffset:4,children:"Managed: Rudder stores and serves the instructions bundle. External: you provide a path on disk where the instructions live."})]})]}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx(de,{type:"button",size:"sm",variant:Y==="managed"?"default":"outline",onClick:()=>{Y==="external"&&(J.current={rootPath:V,entryFile:P,selectedFile:ge});const q=P||xx;j({mode:"managed",rootPath:(L==null?void 0:L.managedRootPath)??V,entryFile:q}),d(q)},children:"Managed"}),i.jsx(de,{type:"button",size:"sm",variant:Y==="external"?"default":"outline",onClick:()=>{const q=J.current,ue=(q==null?void 0:q.entryFile)??P??xx;j({mode:"external",rootPath:(q==null?void 0:q.rootPath)??((L==null?void 0:L.mode)==="external"?L.rootPath??"":""),entryFile:ue}),d((q==null?void 0:q.selectedFile)??ue)},children:"External"})]})]}),i.jsxs("label",{className:"space-y-1.5 min-w-0",children:[i.jsxs("span",{className:"text-xs font-medium text-muted-foreground flex items-center gap-1",children:["Root path",i.jsxs(ca,{children:[i.jsx(ua,{asChild:!0,children:i.jsx(eb,{className:"h-3 w-3 text-muted-foreground cursor-help"})}),i.jsx(da,{side:"right",sideOffset:4,children:"The absolute directory on disk where the instructions bundle lives. In managed mode this is set by Rudder automatically."})]})]}),Y==="managed"?i.jsxs("div",{className:"flex items-center gap-1.5 font-mono text-xs text-muted-foreground pt-1.5",children:[i.jsx("span",{className:"min-w-0 truncate",title:V||void 0,children:V||"(managed)"}),V&&i.jsx(sv,{text:V,className:"shrink-0",children:i.jsx(xi,{className:"h-3.5 w-3.5"})})]}):i.jsxs("div",{className:"flex items-center gap-1.5",children:[i.jsx(An,{value:V,onChange:q=>{const ue=q.target.value;J.current={rootPath:ue,entryFile:P,selectedFile:ge},j({mode:"external",rootPath:ue,entryFile:P})},className:"font-mono text-sm",placeholder:"/absolute/path/to/agent/prompts"}),V&&i.jsx(sv,{text:V,className:"shrink-0",children:i.jsx(xi,{className:"h-3.5 w-3.5"})})]})]}),i.jsxs("label",{className:"space-y-1.5",children:[i.jsxs("span",{className:"text-xs font-medium text-muted-foreground flex items-center gap-1",children:["Entry file",i.jsxs(ca,{children:[i.jsx(ua,{asChild:!0,children:i.jsx(eb,{className:"h-3 w-3 text-muted-foreground cursor-help"})}),i.jsx(da,{side:"right",sideOffset:4,children:"The main file the agent reads first when loading role and persona instructions. Defaults to SOUL.md."})]})]}),i.jsx(An,{value:P,onChange:q=>{const ue=q.target.value||xx,je=ge===P?ue:ge;Y==="external"&&(J.current={rootPath:V,entryFile:ue,selectedFile:je}),ge===P&&d(ue),j({mode:Y,rootPath:V,entryFile:ue})},className:"font-mono text-sm"})]})]})})})]}),i.jsxs("div",{ref:D,className:Q("flex gap-0",c&&"flex-col gap-3"),children:[i.jsxs("div",{className:Q("border border-border rounded-lg p-3 space-y-3 shrink-0",c&&h&&"block",c&&!h&&"hidden"),style:c?void 0:{width:O},children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("h4",{className:"text-sm font-medium",children:"Files"}),i.jsxs("div",{className:"flex items-center gap-1",children:[!N&&i.jsx(de,{type:"button",size:"icon",variant:"outline",className:"h-7 w-7",onClick:()=>S(!0),children:"+"}),c&&i.jsx(de,{type:"button",size:"icon",variant:"ghost",className:"h-7 w-7",onClick:()=>m(!1),children:"✕"})]})]}),N&&i.jsxs("div",{className:"space-y-2",children:[i.jsx(An,{value:k,onChange:q=>w(q.target.value),placeholder:"TOOLS.md",className:"font-mono text-sm",autoFocus:!0,onKeyDown:q=>{q.key==="Escape"&&(S(!1),w(""))}}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx(de,{type:"button",size:"sm",variant:"default",className:"flex-1",disabled:!k.trim()||k.includes(".."),onClick:()=>{const q=k.trim();!q||q.includes("..")||(_(ue=>ue.includes(q)?ue:[...ue,q]),d(q),b(""),w(""),S(!1))},children:"Create"}),i.jsx(de,{type:"button",size:"sm",variant:"outline",className:"flex-1",onClick:()=>{S(!1),w("")},children:"Cancel"})]})]}),i.jsx(pS,{nodes:te,selectedFile:ge,expandedDirs:E,checkedFiles:new Set,onToggleDir:q=>I(ue=>{const je=new Set(ue);return je.has(q)?je.delete(q):je.add(q),je}),onSelectFile:q=>{d(q),ce.includes(q)||b(""),c&&m(!1)},onToggleCheck:()=>{},showCheckboxes:!1,renderFileExtra:q=>{const ue=L==null?void 0:L.files.find(je=>je.path===q.path);return ue?ue.deprecated?i.jsxs(ca,{children:[i.jsx(ua,{asChild:!0,children:i.jsx("span",{className:Q("ml-3 shrink-0 rounded border px-1.5 py-0.5 text-[10px] uppercase tracking-wide cursor-help",tR.warn),children:"virtual file"})}),i.jsx(da,{side:"right",sideOffset:4,children:"Legacy inline prompt — this deprecated virtual file preserves the old promptTemplate content"})]}):i.jsx("span",{className:"ml-3 shrink-0 rounded border border-border text-muted-foreground px-1.5 py-0.5 text-[10px] uppercase tracking-wide",children:ue.isEntryFile?"entry":`${ue.size}b`}):null}})]}),!c&&i.jsx("div",{className:"w-1 shrink-0 cursor-col-resize hover:bg-border active:bg-primary/50 rounded transition-colors mx-1",onMouseDown:X}),i.jsxs("div",{className:Q("border border-border rounded-lg p-4 space-y-3 min-w-0 flex-1",c&&h&&"hidden"),children:[i.jsx("div",{className:"flex items-center justify-between gap-3",children:i.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[c&&i.jsx(de,{type:"button",size:"icon",variant:"outline",className:"h-7 w-7 shrink-0",onClick:()=>m(!0),children:i.jsx(ny,{className:"h-3.5 w-3.5"})}),i.jsxs("div",{className:"min-w-0",children:[i.jsx("h4",{className:"text-sm font-medium font-mono truncate",children:ge}),i.jsx("p",{className:"text-xs text-muted-foreground",children:ie?ae!=null&&ae.deprecated?"Deprecated virtual file":`${(he==null?void 0:he.language)??"text"} file`:"New file in this bundle"})]})]})}),ie&&me&&!he?i.jsx(xje,{}):M1t(ge)?i.jsx(Vo,{value:Ue,onChange:q=>b(q??""),placeholder:"# Agent instructions",contentClassName:"min-h-[420px] text-sm font-mono",imageUploadHandler:async q=>{const ue=`agents/${e.id}/instructions/${ge.replaceAll("/","-")}`;return(await $e.mutateAsync({file:q,namespace:ue})).contentPath}},ge):i.jsx("textarea",{value:Ue,onChange:q=>b(q.target.value),className:"min-h-[420px] w-full rounded-md border border-border bg-transparent px-3 py-2 font-mono text-sm outline-none",placeholder:"File contents"})]})]})]}):i.jsx("div",{className:"max-w-3xl",children:i.jsx("p",{className:"text-sm text-muted-foreground",children:"Instructions bundles are only available for local adapters."})})}function nwt(){return i.jsxs("div",{className:"max-w-5xl space-y-4",children:[i.jsxs("div",{className:"rounded-lg border border-border p-4 space-y-4",children:[i.jsxs("div",{className:"flex items-start justify-between gap-4",children:[i.jsxs("div",{className:"space-y-2",children:[i.jsx(Ft,{className:"h-4 w-40"}),i.jsx(Ft,{className:"h-4 w-[30rem] max-w-full"})]}),i.jsx(Ft,{className:"h-4 w-16"})]}),i.jsx("div",{className:"grid gap-3 md:grid-cols-3",children:Array.from({length:3}).map((e,t)=>i.jsxs("div",{className:"space-y-2",children:[i.jsx(Ft,{className:"h-3 w-20"}),i.jsx(Ft,{className:"h-10 w-full"})]},t))})]}),i.jsxs("div",{className:"grid gap-4 lg:grid-cols-[260px_minmax(0,1fr)]",children:[i.jsxs("div",{className:"rounded-lg border border-border p-3 space-y-3",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx(Ft,{className:"h-4 w-12"}),i.jsx(Ft,{className:"h-8 w-16"})]}),i.jsx(Ft,{className:"h-10 w-full"}),i.jsx("div",{className:"space-y-2",children:Array.from({length:5}).map((e,t)=>i.jsx(Ft,{className:"h-9 w-full rounded-none"},t))})]}),i.jsxs("div",{className:"rounded-lg border border-border p-4 space-y-3",children:[i.jsxs("div",{className:"space-y-2",children:[i.jsx(Ft,{className:"h-4 w-48"}),i.jsx(Ft,{className:"h-3 w-28"})]}),i.jsx(xje,{})]})]})]})}function xje(){return i.jsxs("div",{className:"space-y-3",children:[i.jsx(Ft,{className:"h-10 w-full"}),i.jsx(Ft,{className:"h-[420px] w-full"})]})}function rwt({agent:e,orgId:t}){const n=xn(),{pushToast:r}=gr(),[s,a]=x.useState([]),[o,l]=x.useState([]),[c,u]=x.useState(""),[d,h]=x.useState(!1),[m,g]=x.useState(!1),b=x.useRef([]),v=x.useRef([]),j=x.useRef(!1),k=x.useRef(null),w=x.useRef(null),{data:N,isLoading:S}=ke({queryKey:U.agents.skills(e.id),queryFn:()=>$t.skills(e.id,t),enabled:!!t}),{data:A,isLoading:_}=ke({queryKey:U.organizationSkills.list(t??""),queryFn:()=>ro.list(t),enabled:!!t});w.current!==e.id&&(w.current=e.id,k.current=null),k.current===null&&N&&(k.current=Oj(N.desiredSkills));const E=nt({mutationFn:q=>$t.syncSkills(e.id,q,t),onSuccess:async q=>{n.setQueryData(U.agents.skills(e.id),q),v.current=q.desiredSkills,l(q.desiredSkills),await Promise.all([n.invalidateQueries({queryKey:U.agents.detail(e.id)}),n.invalidateQueries({queryKey:U.agents.detail(e.urlKey)})])}}),I=nt({mutationFn:q=>$t.createPrivateSkill(e.id,q,t),onSuccess:async q=>{g(!1),u(""),r({title:`Created ${q.key}`,body:"Enable it from the Agent skills section when you want Rudder to load it."}),await n.invalidateQueries({queryKey:U.agents.skills(e.id)})}});x.useEffect(()=>{a([]),b.current=[],l([]),u(""),h(!1),v.current=[],j.current=!1},[e.id]),x.useEffect(()=>{b.current=s},[s]),x.useEffect(()=>{if(!N)return;const q=Oj(N.desiredSkills),ue=b.current,je=v.current,re=!j.current||Sk(ue,je);j.current=!0,v.current=q,l(fe=>Sk(fe,q)?fe:q),re&&(b.current=q,a(fe=>Sk(fe,q)?fe:q))},[N]);const O=(N==null?void 0:N.entries)??[],M=x.useMemo(()=>new Map(O.map(q=>[q.selectionKey,q])),[O]),D=x.useCallback(q=>PL(q)?`bundled:${q}`:`org:${q}`,[]),z=x.useCallback((q,ue)=>{if(ue)return"Bundled by Rudder";switch(q){case"community":return"Community preset";case"github":return"GitHub";case"local":return"Local";case"url":return"URL";case"skills_sh":return"skills.sh";case"catalog":return"Catalog";case"rudder":return"Rudder workspace";default:return null}},[]),F=x.useCallback(q=>{const ue=PL(q.key)!==null;return{key:q.slug,selectionKey:D(q.key),runtimeName:q.slug,description:q.description??null,desired:ue,configurable:!ue,alwaysEnabled:ue,managed:!0,state:ue?"configured":"available",sourceClass:ue?"bundled":"organization"}},[D]),K=x.useMemo(()=>new Set(k.current??[]),[e.id,N]),J=x.useMemo(()=>X_((A??[]).map(q=>{const ue=M.get(D(q.key))??F(q),je=z(q.sourceBadge,ue.alwaysEnabled);return{id:ue.selectionKey,selectionKey:ue.selectionKey,key:ue.key,name:q.name,description:Jk(q.description??ue.description??null),detail:Jk(ue.detail??null),locationLabel:ue.locationLabel??null,badgeLabel:je,metadataTokens:[q.sourceLabel].filter(re=>!!re).filter(re=>re!==je),linkTo:`/skills/${q.id}`,workspaceEditPath:q.workspaceEditPath,alwaysEnabled:ue.alwaysEnabled,configurable:kne(ue),entry:ue}}),K),[F,M,z,D,A,K]),$=x.useMemo(()=>O.filter(q=>y1t(q)).filter(q=>!E1t(q)).map(q=>({id:q.selectionKey,selectionKey:q.selectionKey,key:q.key,name:q.runtimeName??q.key,description:Jk(q.description??null),detail:Jk(q.detail??(q.sourceClass==="agent_home"?"Installed, not enabled. Future runs will not load it until enabled.":q.sourceClass==="global"?"Discovered in ~/.agents/skills. Enable it here to load it for this agent.":"Discovered in the current runtime adapter home. Enable it here to load it for this agent.")),locationLabel:q.locationLabel??null,badgeLabel:q.sourceClass==="agent_home"?q.desired?"Agent skill":"Installed, not enabled":q.sourceClass==="global"?"Global skill":"Adapter skill",metadataTokens:[q.locationLabel].filter(ue=>!!ue),linkTo:null,workspaceEditPath:q.workspaceEditPath??null,alwaysEnabled:q.alwaysEnabled,configurable:kne(q),entry:q})).sort((q,ue)=>q.name.localeCompare(ue.name)||q.selectionKey.localeCompare(ue.selectionKey)),[O]),L=x.useMemo(()=>X_($.filter(q=>q.entry.sourceClass==="agent_home"),K),[$,K]),H=x.useMemo(()=>$.filter(q=>q.entry.sourceClass!=="agent_home"),[$]),W=x.useMemo(()=>X_(H.filter(q=>q.entry.sourceClass==="global"),K),[H,K]),B=x.useMemo(()=>X_(H.filter(q=>q.entry.sourceClass==="adapter_home"),K),[H,K]),Y=x.useMemo(()=>{const q=c.trim().toLowerCase();return J.filter(ue=>q?[ue.name,ue.key,ue.description??"",ue.detail??"",...ue.metadataTokens].join(" ").toLowerCase().includes(q):!0)},[J,c]),P=x.useCallback(q=>{const ue=c.trim().toLowerCase();return q.filter(je=>ue?[je.name,je.key,je.description??"",je.detail??"",...je.metadataTokens].join(" ").toLowerCase().includes(ue):!0)},[c]),V=x.useMemo(()=>P(W),[P,W]),ce=x.useMemo(()=>P(L),[L,P]),le=x.useMemo(()=>P(B),[B,P]),G=x.useMemo(()=>[...Y.filter(q=>!q.alwaysEnabled).map(q=>q.selectionKey),...ce.filter(q=>q.configurable).map(q=>q.selectionKey),...d?[...V,...le].filter(q=>q.configurable).map(q=>q.selectionKey):[]],[d,le,ce,V,Y]),te=x.useMemo(()=>new Set(O.map(q=>q.selectionKey)),[O]),ge=x.useMemo(()=>s.filter(q=>!te.has(q)),[te,s]),ie=x.useMemo(()=>(N==null?void 0:N.mode)!=="unsupported"?null:e.agentRuntimeType==="openclaw_gateway"?"Rudder cannot manage OpenClaw skills here. Visit your OpenClaw instance to manage this agent's skills.":"Rudder cannot manage skills for this runtime yet. Manage them in the runtime directly.",[e.agentRuntimeType,N==null?void 0:N.mode]),ae=x.useMemo(()=>H.some(q=>s.includes(q.selectionKey)),[H,s]),he=S||_,me=E.isPending?"Saving...":null,ye="Rudder always loads the bundled Rudder skills. Agent, organization, global, and adapter skills load only when enabled on this page.",Me="Agent-private skills belong to this agent only. Edit them in Workspaces, then enable them here when you want Rudder to load them.",$e="Bundled Rudder skills are locked on. Community presets and other organization skills stay optional; workspace-backed skills can be edited from Workspaces.",Re="Global and adapter skills are discovered from ~/.agents/skills and the current runtime adapter home. Discovery does not enable them; only the selections on this page determine runtime loading.",Ue=x.useCallback(q=>{const ue=b.current,je=Oj(q(ue));Sk(ue,je)||(b.current=je,a(je),Sk(je,v.current)||E.mutate(je))},[E]),we=x.useCallback((q,ue)=>{Ue(je=>jne(je,q.entry,ue,O))},[O,Ue]),ze=x.useCallback((q,ue)=>{q.length!==0&&Ue(je=>q.reduce((re,fe)=>jne(re,fe.entry,ue,O),je))},[O,Ue]),oe=x.useCallback(()=>{const q=[...Y.filter(ue=>!ue.alwaysEnabled),...ce,...d?[...V,...le]:[]];ze(q,!0)},[d,le,ce,V,Y,ze]),xe=x.useCallback(()=>{const q=[...Y.filter(ue=>!ue.alwaysEnabled),...ce,...d?[...V,...le]:[]];ze(q,!1)},[d,le,ce,V,Y,ze]);x.useEffect(()=>{if(ae){h(!0);return}c.trim().length>0&&Y.length===0&&ce.length===0&&(V.length>0||le.length>0)&&h(!0)},[le.length,ce.length,V.length,Y.length,ae,c]);const X=x.useCallback(q=>{const ue=q.alwaysEnabled||s.includes(q.selectionKey),je=q.alwaysEnabled||!q.configurable||!!(ie&&!q.alwaysEnabled),re=q.workspaceEditPath?`/workspaces?path=${encodeURIComponent(q.workspaceEditPath)}`:null,fe=C1t(q.description,Cne(q.detail)?null:q.detail),ne=q.detail&&q.detail!==q.description&&!Cne(q.detail)?q.detail:null,Fe=[S1t(q.locationLabel)?null:q.locationLabel,...q.metadataTokens].filter(Ce=>!!Ce).filter(Ce=>Ce!==q.badgeLabel&&Ce!=="Bundled by Rudder");return i.jsxs("div",{className:Q("flex h-full flex-col gap-2.5 rounded-lg border p-3 transition-colors",q.alwaysEnabled?"border-sky-200 bg-sky-50/50 dark:border-sky-500/30 dark:bg-sky-950/15":ue?"border-border bg-background":"border-border/70 bg-muted/35 text-muted-foreground"),children:[i.jsxs("div",{className:"flex items-start justify-between gap-3",children:[i.jsx("div",{className:"min-w-0 space-y-1",children:i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[q.linkTo?i.jsx(Nt,{to:q.linkTo,className:Q("truncate text-sm font-semibold no-underline transition-colors hover:text-foreground",q.alwaysEnabled||ue?"text-foreground":"text-foreground/80"),children:q.name}):i.jsx("span",{className:Q("truncate text-sm font-semibold",q.alwaysEnabled||ue?"text-foreground":"text-foreground/80"),children:q.name}),q.badgeLabel?i.jsx("span",{className:"rounded-md border border-border bg-muted/40 px-1.5 py-0.5 text-[11px] font-medium text-muted-foreground",children:q.badgeLabel}):null]})}),i.jsx(_1t,{checked:ue,disabled:je,label:q.name,onCheckedChange:Ce=>we(q,Ce)})]}),i.jsx("p",{className:Q("line-clamp-2 text-xs leading-[1.15rem]",q.alwaysEnabled||ue?"text-muted-foreground":"text-muted-foreground/90"),children:fe}),ne?i.jsx("p",{className:"line-clamp-2 text-[11px] leading-[1.05rem] text-muted-foreground/90",children:ne}):null,Fe.length>0||re?i.jsxs("div",{className:"mt-auto space-y-2",children:[Fe.length>0?i.jsx("div",{className:"flex flex-wrap items-center gap-1.5 text-[11px] text-muted-foreground",children:Fe.map(Ce=>i.jsx("span",{className:"max-w-full truncate rounded-md border border-border bg-muted/20 px-1.5 py-0.5",title:Ce,children:Ce},`${q.id}:${Ce}`))}):null,re?i.jsx("div",{className:"flex items-center gap-2",children:i.jsx(de,{asChild:!0,variant:"outline",size:"sm",className:"h-7 gap-1.5 px-2 text-xs",children:i.jsxs(Nt,{to:re,children:[i.jsx(ny,{className:"h-3.5 w-3.5"}),i.jsx("span",{children:"Edit in workspaces"})]})})}):null]}):null]},q.id)},[we,s,ie]);return i.jsxs("div",{className:"max-w-6xl space-y-3",children:[i.jsxs("section",{className:"space-y-3",children:[i.jsx("div",{className:"space-y-1",children:i.jsxs("div",{className:"min-w-0",children:[i.jsx("p",{className:"text-sm font-semibold text-foreground",children:"Skills"}),i.jsx("p",{className:"max-w-3xl text-xs leading-5 text-muted-foreground",children:ye})]})}),i.jsxs("div",{className:"flex flex-wrap items-center gap-2.5",children:[i.jsxs("div",{className:"relative min-w-[16rem] max-w-md flex-1",children:[i.jsx(Ro,{className:"pointer-events-none absolute left-3 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),i.jsx(An,{value:c,onChange:q=>u(q.target.value),placeholder:"Search skills","aria-label":"Search skills",className:"h-9 pl-9"})]}),i.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[i.jsxs(de,{variant:"outline",size:"sm",className:"gap-2",onClick:()=>g(!0),disabled:(N==null?void 0:N.mode)==="unsupported"||I.isPending,children:[i.jsx(Hn,{className:"h-3.5 w-3.5"}),i.jsx("span",{children:"Create agent skill"})]}),me?i.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[E.isPending?i.jsx(or,{className:"h-3.5 w-3.5 animate-spin"}):null,i.jsx("span",{children:me})]}):null,i.jsxs(bo,{children:[i.jsx(yo,{asChild:!0,children:i.jsx(de,{variant:"ghost",size:"icon-sm","aria-label":"More skill actions",children:i.jsx(Ac,{className:"h-4 w-4"})})}),i.jsxs(vo,{align:"end",className:"surface-overlay text-foreground",children:[i.jsx($n,{onClick:oe,disabled:G.length===0||(N==null?void 0:N.mode)==="unsupported",children:"Enable visible"}),i.jsx($n,{onClick:xe,disabled:G.length===0||(N==null?void 0:N.mode)==="unsupported",children:"Disable visible"})]})]})]})]})]}),N!=null&&N.warnings.length?i.jsx("div",{className:"space-y-1 rounded-xl border border-amber-300/60 bg-amber-50/60 px-4 py-3 text-sm text-amber-800 dark:border-amber-500/30 dark:bg-amber-950/20 dark:text-amber-200",children:N.warnings.map(q=>i.jsx("div",{children:q},q))}):null,ie?i.jsx("div",{className:"rounded-xl border border-border px-4 py-3 text-sm text-muted-foreground",children:ie}):null,he?i.jsx(Is,{variant:"list"}):i.jsxs(i.Fragment,{children:[J.length===0&&L.length===0&&H.length===0?i.jsx("section",{className:"rounded-xl border border-border bg-[color:var(--surface-elevated)]",children:i.jsx("div",{className:"px-4 py-6 text-sm text-muted-foreground",children:"Import or scan skills into the organization library first, then enable them here."})}):i.jsxs(i.Fragment,{children:[L.length>0?i.jsxs("section",{className:"overflow-hidden rounded-xl border border-border bg-[color:var(--surface-elevated)]",children:[i.jsxs("div",{className:"border-b border-border px-4 py-3",children:[i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i.jsx("p",{className:"text-sm font-semibold text-foreground",children:"Agent skills"}),i.jsx("span",{className:"text-xs text-muted-foreground",children:L.length})]}),i.jsx("p",{className:"mt-1 max-w-3xl text-xs leading-5 text-muted-foreground",children:Me})]}),i.jsx("div",{className:"px-3.5 py-3.5",children:ce.length===0?i.jsx("div",{className:"px-0.5 py-1 text-sm text-muted-foreground",children:"No skills match this search."}):i.jsx("div",{className:"grid gap-2.5 md:grid-cols-2",children:ce.map(q=>X(q))})})]}):null,i.jsxs("section",{className:"overflow-hidden rounded-xl border border-border bg-[color:var(--surface-elevated)]",children:[i.jsxs("div",{className:"border-b border-border px-4 py-3",children:[i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i.jsx("p",{className:"text-sm font-semibold text-foreground",children:"Organization skills"}),i.jsx("span",{className:"text-xs text-muted-foreground",children:J.length})]}),i.jsx("p",{className:"mt-1 max-w-3xl text-xs leading-5 text-muted-foreground",children:$e})]}),i.jsx("div",{className:"px-3.5 py-3.5",children:Y.length===0?i.jsx("div",{className:"px-0.5 py-1 text-sm text-muted-foreground",children:"No skills match this search."}):i.jsx("div",{className:"grid gap-2.5 md:grid-cols-2",children:Y.map(q=>X(q))})})]}),H.length>0?i.jsxs("section",{className:"overflow-hidden rounded-xl border border-border bg-[color:var(--surface-elevated)]",children:[i.jsxs("button",{type:"button",className:Q("flex w-full items-start justify-between gap-3 px-4 py-3 text-left",d&&"border-b border-border"),onClick:()=>h(q=>!q),children:[i.jsxs("div",{className:"min-w-0",children:[i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i.jsx("span",{className:"text-sm font-semibold text-foreground",children:"External skills"}),i.jsx("span",{className:"text-xs text-muted-foreground",children:H.length})]}),i.jsx("p",{className:"mt-1 max-w-3xl text-xs leading-5 text-muted-foreground",children:Re})]}),d?i.jsx(Vr,{className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}):i.jsx(Us,{className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"})]}),d?V.length===0&&le.length===0?i.jsx("div",{className:"px-4 py-3 text-sm text-muted-foreground",children:"No external skills match this search."}):i.jsxs("div",{className:"space-y-4 px-3.5 py-3.5",children:[V.length>0?i.jsxs("div",{className:"space-y-2",children:[i.jsxs("div",{className:"flex items-center gap-2 px-0.5",children:[i.jsx("span",{className:"text-xs font-semibold uppercase tracking-[0.08em] text-muted-foreground",children:"Global skills"}),i.jsx("span",{className:"text-[11px] text-muted-foreground",children:V.length})]}),i.jsx("div",{className:"grid gap-2.5 md:grid-cols-2",children:V.map(q=>X(q))})]}):null,le.length>0?i.jsxs("div",{className:"space-y-2",children:[i.jsxs("div",{className:"flex items-center gap-2 px-0.5",children:[i.jsx("span",{className:"text-xs font-semibold uppercase tracking-[0.08em] text-muted-foreground",children:"Adapter skills"}),i.jsx("span",{className:"text-[11px] text-muted-foreground",children:le.length})]}),i.jsx("div",{className:"grid gap-2.5 md:grid-cols-2",children:le.map(q=>X(q))})]}):null]}):null]}):null]}),ge.length>0?i.jsxs("div",{className:"rounded-xl border border-amber-300/60 bg-amber-50/60 px-4 py-3 text-sm text-amber-800 dark:border-amber-500/30 dark:bg-amber-950/20 dark:text-amber-200",children:[i.jsx("div",{className:"font-medium",children:"Enabled skills currently unavailable"}),i.jsx("div",{className:"mt-1 text-xs",children:ge.join(", ")})]}):null,E.isError?i.jsx("p",{className:"text-xs text-destructive",children:E.error instanceof Error?E.error.message:"Failed to update skills"}):null]}),i.jsx(A1t,{open:m,onOpenChange:g,onCreate:q=>I.mutate(q),isPending:I.isPending,error:I.error instanceof Error?I.error.message:null})]})}function jP({run:e,isSelected:t,agentId:n}){const r=Dr(),{pushToast:s}=gr(),a=mje[e.status]??{icon:R3,color:"text-neutral-400"},o=a.icon,l=fq(e),c=e.resultJson?String(e.resultJson.summary??e.resultJson.result??""):e.error??"",u=e.id.slice(0,8),d=lje(e),h=t?`/agents/${n}/runs`:`/agents/${n}/runs/${e.id}`,m=e.status==="running"||e.status==="queued",g=hq(m),b=uq(e,g)??hs(e.createdAt),v=dq(e),j=()=>{r(h)},k=N=>{N.target===N.currentTarget&&(N.key!=="Enter"&&N.key!==" "||(N.preventDefault(),j()))},w=async N=>{N.preventDefault(),N.stopPropagation();try{await navigator.clipboard.writeText(e.id),s({title:"Run ID copied",body:"The full agent run ID is now in your clipboard.",tone:"success"})}catch(S){s({title:"Could not copy run ID",body:S instanceof Error?S.message:"Clipboard access was denied.",tone:"error"})}};return i.jsxs("div",{role:"link",tabIndex:0,"aria-label":`Open run ${u}`,className:Q("flex flex-col gap-1 w-full px-3 py-2.5 text-left border-b border-border last:border-b-0 transition-colors no-underline text-inherit",t?"bg-accent/40":"hover:bg-accent/20"),onClick:j,onKeyDown:k,children:[i.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[i.jsx(o,{className:Q("h-3.5 w-3.5 shrink-0",a.color,e.status==="running"&&"animate-spin")}),i.jsx("button",{type:"button",className:"min-w-0 truncate font-mono text-xs text-muted-foreground hover:text-foreground transition-colors cursor-copy","aria-label":`Copy run ID ${u}`,title:"Copy run ID",onClick:w,children:u}),i.jsx("span",{className:Q("inline-flex items-center rounded-full px-1.5 py-0.5 text-[10px] font-medium shrink-0",cje(d.tone)),title:d.description,children:d.label}),i.jsx("span",{className:"ml-auto shrink-0 text-[11px] font-medium tabular-nums text-foreground",title:v||void 0,children:b})]}),c&&i.jsx("span",{className:"text-xs text-muted-foreground truncate pl-5.5",children:c.slice(0,60)}),(l.totalTokens>0||l.cost>0)&&i.jsxs("div",{className:"flex items-center gap-2 pl-5.5 text-[11px] text-muted-foreground tabular-nums",children:[l.totalTokens>0&&i.jsx("span",{children:gje(l.totalTokens)}),l.cost>0&&i.jsxs("span",{children:["$",l.cost.toFixed(3)]})]})]})}function swt({runs:e,orgId:t,agentId:n,agentRouteId:r,selectedRunId:s,agentRuntimeType:a}){var d;const{isMobile:o}=Hi();if(e.length===0)return i.jsx("p",{className:"text-sm text-muted-foreground",children:"No runs yet."});const l=[...e].sort((h,m)=>new Date(m.createdAt).getTime()-new Date(h.createdAt).getTime()),c=o?s:s??((d=l[0])==null?void 0:d.id)??null,u=l.find(h=>h.id===c)??null;return o?u?i.jsxs("div",{className:"space-y-3 min-w-0 overflow-x-hidden",children:[i.jsxs(Nt,{to:`/agents/${r}/runs`,className:"flex items-center gap-1.5 text-sm text-muted-foreground hover:text-foreground transition-colors no-underline",children:[i.jsx(lm,{className:"h-3.5 w-3.5"}),"Back to runs"]}),i.jsx(Ine,{run:u,agentRouteId:r,agentRuntimeType:a},u.id)]}):i.jsx("div",{className:"border border-border rounded-lg overflow-x-hidden",children:l.map(h=>i.jsx(jP,{run:h,isSelected:!1,agentId:r},h.id))}):u?i.jsxs("div",{className:"flex min-w-0 items-start gap-4",children:[i.jsx("div",{className:"min-w-0 flex-1 basis-0","data-testid":"agent-runs-detail-pane",children:i.jsx(Ine,{run:u,agentRouteId:r,agentRuntimeType:a},u.id)}),i.jsx("div",{className:"w-[14rem] shrink-0 border border-border rounded-lg xl:w-[14.5rem] 2xl:w-[15rem]","data-testid":"agent-runs-list-pane",children:i.jsx("div",{className:"sticky top-4 overflow-y-auto",style:{maxHeight:"calc(100vh - 2rem)"},children:l.map(h=>i.jsx(jP,{run:h,isSelected:h.id===c,agentId:r},h.id))})})]}):i.jsx("div",{className:"border border-border rounded-lg overflow-x-hidden",children:l.map(h=>i.jsx(jP,{run:h,isSelected:!1,agentId:r},h.id))})}function Ine({run:e,agentRouteId:t,agentRuntimeType:n}){var ie,ae;const r=xn(),s=Dr(),{confirm:a}=Gr(),{data:o}=ke({queryKey:U.runDetail(e.id),queryFn:()=>us.get(e.id),enabled:!!e.id}),l=o??e,c=fq(l),[u,d]=x.useState(!1),[h,m]=x.useState(null);x.useEffect(()=>{m(null)},[l.id]);const g=nt({mutationFn:()=>us.cancel(l.id),onSuccess:()=>{r.invalidateQueries({queryKey:U.heartbeats(l.orgId,l.agentId)})}}),b=l.errorCode==="process_lost"&&l.status==="failed",v=l.status==="failed"||l.status==="timed_out"||l.status==="cancelled",j=nt({mutationFn:async()=>a1t(l),onSuccess:he=>{r.invalidateQueries({queryKey:U.heartbeats(l.orgId,l.agentId)}),s(`/agents/${t}/runs/${he.id}`)}}),{data:k}=ke({queryKey:U.runIssues(l.id),queryFn:()=>Fh.issuesForRun(l.id)}),w=x.useMemo(()=>Array.from(new Set((k??[]).map(he=>he.issueId))),[k]),N=nt({mutationFn:async()=>w.length===0?0:(await Promise.all(w.map(he=>$t.resetSession(l.agentId,he,l.orgId))),w.length),onSuccess:()=>{r.invalidateQueries({queryKey:U.agents.runtimeState(l.agentId)}),r.invalidateQueries({queryKey:U.agents.taskSessions(l.agentId)}),r.invalidateQueries({queryKey:U.runIssues(l.id)})}}),S=nt({mutationFn:()=>$t.loginWithClaude(l.agentId,l.orgId),onSuccess:he=>{m(he)}}),A=l.status==="queued"||l.status==="running"&&!l.finishedAt,_=hq(A),E=uq(l,_),I=dq(l),O={hour:"2-digit",minute:"2-digit",second:"2-digit",hourCycle:"h23"},M=l.startedAt?new Date(l.startedAt).toLocaleTimeString("en-US",O):null,D=l.finishedAt?new Date(l.finishedAt).toLocaleTimeString("en-US",O):null,z=c.input>0||c.output>0||c.cached>0||c.cost>0,F=!!(l.sessionIdBefore||l.sessionIdAfter),K=l.sessionIdBefore&&l.sessionIdAfter&&l.sessionIdBefore!==l.sessionIdAfter,J=l.exitCode!==null&&l.exitCode!==0,$=Ku((ie=Ku(l.contextSnapshot))==null?void 0:ie.recovery),L=os($==null?void 0:$.originalRunId)??l.retryOfRunId,H=os($==null?void 0:$.failureKind),W=os($==null?void 0:$.failureSummary),B=os($==null?void 0:$.recoveryTrigger),Y=os($==null?void 0:$.recoveryMode),P=Ku((ae=Ku(l.contextSnapshot))==null?void 0:ae.passiveFollowup),V=os(P==null?void 0:P.originRunId),ce=os(P==null?void 0:P.previousRunId),le=os(P==null?void 0:P.reason),G=typeof(P==null?void 0:P.attempt)=="number"?P.attempt:null,te=typeof(P==null?void 0:P.maxAttempts)=="number"?P.maxAttempts:null,ge=l.status==="running"||l.status==="queued"?i.jsx(de,{variant:"outline",size:"sm",className:"h-8 px-3 text-xs text-destructive hover:text-destructive",onClick:()=>g.mutate(),disabled:g.isPending,children:g.isPending?"Cancelling...":"Cancel"}):b?i.jsxs(de,{variant:"outline",size:"sm",className:"h-8 px-3 text-xs",onClick:()=>j.mutate(),disabled:j.isPending,"data-testid":"run-detail-retry",children:[i.jsx(Ev,{className:"h-3.5 w-3.5 mr-1"}),j.isPending?"Resuming...":"Resume"]}):v?i.jsxs(de,{variant:"outline",size:"sm",className:"h-8 px-3 text-xs",onClick:()=>j.mutate(),disabled:j.isPending,"data-testid":"run-detail-retry",children:[i.jsx(Ev,{className:"h-3.5 w-3.5 mr-1"}),j.isPending?"Retrying...":"Retry"]}):null;return i.jsxs("div",{className:"space-y-4 min-w-0",children:[i.jsxs("div",{className:"border border-border rounded-lg overflow-hidden","data-testid":"run-summary-card",children:[i.jsxs("div",{className:"flex flex-col sm:flex-row",children:[i.jsxs("div",{className:"min-w-0 flex-1 p-4 space-y-3",children:[i.jsxs("div",{className:"flex items-start justify-between gap-3",children:[i.jsx("div",{className:"flex min-w-0 items-center gap-2",children:i.jsx(yr,{status:l.status})}),ge&&i.jsx("div",{className:"shrink-0",children:ge})]}),j.isError&&i.jsx("div",{className:"text-xs text-destructive",children:j.error instanceof Error?j.error.message:"Failed to recover run"}),(E||M)&&i.jsxs("div",{className:"space-y-0.5",children:[E&&i.jsx("div",{className:"text-sm font-medium tabular-nums",children:E}),M&&i.jsxs("div",{className:"text-[11px] text-muted-foreground",title:I||void 0,children:[i.jsx("span",{className:"font-mono",children:M}),D&&i.jsxs(i.Fragment,{children:[i.jsx("span",{children:" → "}),i.jsx("span",{className:"font-mono",children:D})]})]})]}),l.error&&i.jsxs("div",{className:"text-xs",children:[i.jsx("span",{className:"text-red-600 dark:text-red-400",children:l.error}),l.errorCode&&i.jsxs("span",{className:"text-muted-foreground ml-1",children:["(",l.errorCode,")"]})]}),l.errorCode==="claude_auth_required"&&n==="claude_local"&&i.jsxs("div",{className:"space-y-2",children:[i.jsx(de,{variant:"outline",size:"sm",className:"h-7 px-2 text-xs",onClick:()=>S.mutate(),disabled:S.isPending,children:S.isPending?"Running claude login...":"Login to Claude Code"}),S.isError&&i.jsx("p",{className:"text-xs text-destructive",children:S.error instanceof Error?S.error.message:"Failed to run Claude login"}),(h==null?void 0:h.loginUrl)&&i.jsxs("p",{className:"text-xs",children:["Login URL:",i.jsx("a",{href:h.loginUrl,className:"text-blue-600 underline underline-offset-2 ml-1 break-all dark:text-blue-400",target:"_blank",rel:"noreferrer",children:h.loginUrl})]}),h&&i.jsxs(i.Fragment,{children:[!!h.stdout&&i.jsx("pre",{className:"min-w-0 max-w-full bg-neutral-100 dark:bg-neutral-950 rounded-md p-3 text-xs font-mono text-foreground overflow-x-auto whitespace-pre-wrap break-words",children:h.stdout}),!!h.stderr&&i.jsx("pre",{className:"min-w-0 max-w-full bg-neutral-100 dark:bg-neutral-950 rounded-md p-3 text-xs font-mono text-red-700 dark:text-red-300 overflow-x-auto whitespace-pre-wrap break-words",children:h.stderr})]})]}),J&&i.jsxs("div",{className:"text-xs text-red-600 dark:text-red-400",children:["Exit code ",l.exitCode,l.signal&&i.jsxs("span",{className:"text-muted-foreground ml-1",children:["(signal: ",l.signal,")"]})]}),L&&i.jsxs("div",{className:"rounded-md border border-border/60 bg-muted/30 px-3 py-2 text-xs space-y-1",children:[i.jsx("div",{className:"font-medium text-foreground",children:"Recovery"}),i.jsxs("div",{className:"text-muted-foreground",children:["From run"," ",i.jsx(Nt,{className:"underline underline-offset-2",to:`/agents/${l.agentId}/runs/${L}`,children:L})]}),(B||Y)&&i.jsx("div",{className:"text-muted-foreground",children:[B,Y].filter(Boolean).join(" · ")}),(H||W)&&i.jsx("div",{className:"text-muted-foreground",children:[H,W].filter(Boolean).join(": ")})]}),V&&i.jsxs("div",{className:"rounded-md border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-xs space-y-1",children:[i.jsx("div",{className:"font-medium text-foreground",children:"Passive follow-up"}),i.jsxs("div",{className:"text-muted-foreground",children:["Origin run"," ",i.jsx(Nt,{className:"underline underline-offset-2",to:`/agents/${l.agentId}/runs/${V}`,children:V})]}),ce&&i.jsxs("div",{className:"text-muted-foreground",children:["Previous run"," ",i.jsx(Nt,{className:"underline underline-offset-2",to:`/agents/${l.agentId}/runs/${ce}`,children:ce})]}),(G||le)&&i.jsx("div",{className:"text-muted-foreground",children:[G&&te?`attempt ${G}/${te}`:null,le].filter(Boolean).join(" · ")})]})]}),z&&i.jsxs("div",{className:"border-t sm:border-t-0 sm:border-l border-border p-4 grid grid-cols-2 gap-x-4 sm:gap-x-8 gap-y-3 content-center tabular-nums",children:[i.jsxs("div",{children:[i.jsx("div",{className:"text-xs text-muted-foreground",children:"Prompt input"}),i.jsx("div",{className:"text-sm font-medium font-mono",children:Qn(c.promptTokens)})]}),i.jsxs("div",{children:[i.jsx("div",{className:"text-xs text-muted-foreground",children:"Output"}),i.jsx("div",{className:"text-sm font-medium font-mono",children:Qn(c.output)})]}),i.jsxs("div",{children:[i.jsx("div",{className:"text-xs text-muted-foreground",children:"Cached input"}),i.jsx("div",{className:"text-sm font-medium font-mono",children:Qn(c.cached)})]}),i.jsxs("div",{children:[i.jsx("div",{className:"text-xs text-muted-foreground",children:"Cost"}),i.jsx("div",{className:"text-sm font-medium font-mono",children:c.cost>0?`$${c.cost.toFixed(4)}`:"-"})]})]})]}),F&&i.jsxs("div",{className:"border-t border-border",children:[i.jsxs("button",{className:"flex items-center gap-1.5 w-full px-4 py-2 text-xs text-muted-foreground hover:text-foreground transition-colors",onClick:()=>d(he=>!he),children:[i.jsx(Us,{className:Q("h-3 w-3 transition-transform",u&&"rotate-90")}),"Session",K&&i.jsx("span",{className:"text-yellow-400 ml-1",children:"(changed)"})]}),u&&i.jsxs("div",{className:"px-4 pb-3 space-y-1 text-xs",children:[i.jsxs("div",{className:"flex items-start gap-2",children:[i.jsx("span",{className:"text-muted-foreground w-12 shrink-0",children:"Run ID"}),i.jsx(sv,{text:l.id,ariaLabel:`Copy run ID ${l.id.slice(0,8)}`,title:"Copy run ID",containerClassName:"min-w-0 max-w-full",className:"block min-w-0 break-all text-left font-mono"})]}),l.sessionIdBefore&&i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-muted-foreground w-12",children:K?"Before":"ID"}),i.jsx(sv,{text:l.sessionIdBefore,className:"font-mono"})]}),K&&l.sessionIdAfter&&i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"text-muted-foreground w-12",children:"After"}),i.jsx(sv,{text:l.sessionIdAfter,className:"font-mono"})]}),w.length>0&&i.jsxs("div",{className:"pt-1",children:[i.jsx("button",{type:"button",className:"text-[11px] text-muted-foreground underline underline-offset-2 hover:text-foreground disabled:opacity-60",disabled:N.isPending,onClick:async()=>{const he=w.length;await a({title:`Clear session for ${he} issue${he===1?"":"s"} touched by this run?`,confirmLabel:"Clear session",tone:"destructive"})&&N.mutate()},children:N.isPending?"clearing session...":"clear session for these issues"}),N.isError&&i.jsx("p",{className:"text-[11px] text-destructive mt-1",children:N.error instanceof Error?N.error.message:"Failed to clear sessions"})]})]})]})]}),k&&k.length>0&&i.jsxs("div",{className:"space-y-2",children:[i.jsxs("span",{className:"text-xs font-medium text-muted-foreground",children:["Issues Touched (",k.length,")"]}),i.jsx("div",{className:"border border-border rounded-lg divide-y divide-border",children:k.map(he=>i.jsxs(Nt,{to:`/issues/${he.identifier??he.issueId}`,className:"flex items-center justify-between w-full px-3 py-2 text-xs hover:bg-accent/20 transition-colors text-left no-underline text-inherit",children:[i.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[i.jsx(yr,{status:he.status}),i.jsx("span",{className:"truncate",children:he.title})]}),i.jsx("span",{className:"font-mono text-muted-foreground shrink-0 ml-2",children:he.identifier??he.issueId.slice(0,8)})]},he.issueId))})]}),l.stderrExcerpt&&i.jsxs("div",{className:"space-y-1",children:[i.jsx("span",{className:"text-xs font-medium text-red-600 dark:text-red-400",children:"stderr"}),i.jsx("pre",{"data-testid":"run-stderr-excerpt",className:"min-w-0 max-w-full bg-neutral-100 dark:bg-neutral-950 rounded-md p-3 text-xs font-mono text-red-700 dark:text-red-300 overflow-x-auto whitespace-pre-wrap break-words",children:l.stderrExcerpt})]}),l.stdoutExcerpt&&!l.logRef&&i.jsxs("div",{className:"space-y-1",children:[i.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"stdout"}),i.jsx("pre",{"data-testid":"run-stdout-excerpt",className:"min-w-0 max-w-full bg-neutral-100 dark:bg-neutral-950 rounded-md p-3 text-xs font-mono text-foreground overflow-x-auto whitespace-pre-wrap break-words",children:l.stdoutExcerpt})]}),i.jsx(iwt,{run:l,agentRuntimeType:n}),i.jsx(fje,{})]})}function NP(e){return e?typeof e=="string"?e:e.toISOString():null}function iwt({run:e,agentRuntimeType:t}){var ze;const[n,r]=x.useState([]),[s,a]=x.useState([]),[o,l]=x.useState(!0),[c,u]=x.useState(!!e.logRef),[d,h]=x.useState(null),[m,g]=x.useState(0),[b,v]=x.useState(!1),[j,k]=x.useState(!1),[w,N]=x.useState("nice"),[S,A]=x.useState("transcript"),[_,E]=x.useState(!1),[I,O]=x.useState({fromX:"0px",fromY:"-16px",settleX:"0px",settleY:"0px",fromScaleX:"0.96",fromScaleY:"0.96"}),M=S==="transcript",D=x.useRef(null),z=x.useRef(null),F=x.useRef(""),K=x.useRef(new Set),J=x.useRef(null),$=x.useRef(!1),L=x.useRef({scrollHeight:0,distanceFromBottom:Number.POSITIVE_INFINITY}),H=e.status==="running"||e.status==="queued",W=x.useMemo(()=>H?[{id:e.id,status:e.status,invocationSource:e.invocationSource,triggerDetail:e.triggerDetail,startedAt:NP(e.startedAt),finishedAt:NP(e.finishedAt),createdAt:NP(e.createdAt)??new Date().toISOString(),agentId:e.agentId,agentName:"",agentRuntimeType:t,issueId:null}]:[],[t,H,e.agentId,e.createdAt,e.finishedAt,e.id,e.invocationSource,e.startedAt,e.status,e.triggerDetail]),{transcriptByRun:B}=lS({runs:W,orgId:e.orgId,maxChunksPerRun:500,includeRunEvents:!1}),{data:Y=[]}=ke({queryKey:U.runWorkspaceOperations(e.id),queryFn:()=>us.workspaceOperations(e.id),refetchInterval:H?2e3:!1});function P(oe){return oe instanceof bl&&oe.status===404}function V(oe,xe=!1){if(!oe&&!xe)return;const q=`${F.current}${oe}`.split(`
1373
1373
  `);F.current=q.pop()??"",xe&&F.current&&(q.push(F.current),F.current="");const ue=[];for(const je of q){const re=je.trim();if(re)try{const fe=JSON.parse(re),ne=fe.stream==="stderr"||fe.stream==="system"?fe.stream:"stdout",Fe=typeof fe.chunk=="string"?fe.chunk:"",Ce=typeof fe.ts=="string"?fe.ts:new Date().toISOString();if(!Fe)continue;ue.push({ts:Ce,stream:ne,chunk:Fe})}catch{}}ue.length>0&&ce(ue)}function ce(oe){oe.length!==0&&a(xe=>{const X=[];for(const q of oe){const ue=Tne(q);K.current.has(ue)||(K.current.add(ue),X.push(q))}return X.length===0?xe:(K.current.size>12e3&&(K.current=new Set(X.map(Tne))),[...xe,...X])})}const{data:le}=ke({queryKey:["run-events",e.id],queryFn:()=>us.events(e.id,0,200)});x.useEffect(()=>{le&&(r(le),l(!1))},[le]);const G=x.useCallback(()=>{if(J.current)return J.current;const oe=P1t(D.current);return J.current=oe,oe},[]),te=x.useCallback(()=>{const oe=G(),xe=e5(oe);L.current=xe;const X=xe.distanceFromBottom<=Sne;$.current=X,v(q=>q===X?q:X)},[G]);x.useEffect(()=>{if(J.current=null,L.current={scrollHeight:0,distanceFromBottom:Number.POSITIVE_INFINITY},!H||!M){$.current=!1,v(!1);return}te()},[H,e.id,M,te]),x.useEffect(()=>{if(!H||!M)return;const oe=G();return te(),oe===window?window.addEventListener("scroll",te,{passive:!0}):oe.addEventListener("scroll",te,{passive:!0}),window.addEventListener("resize",te),()=>{oe===window?window.removeEventListener("scroll",te):oe.removeEventListener("scroll",te),window.removeEventListener("resize",te)}},[H,e.id,M,G,te]),x.useEffect(()=>{if(!H||!M||!$.current)return;const oe=G(),xe=L.current,X=e5(oe),q=Math.max(0,X.scrollHeight-xe.scrollHeight),ue=xe.distanceFromBottom+q;if(X.distanceFromBottom-ue>Sne){$.current=!1,v(!1),L.current=X;return}_ne(oe,"auto");const re=e5(oe);L.current=re,$.current||($.current=!0),v(fe=>fe||!0)},[n.length,s.length,H,M,G]),x.useEffect(()=>{let oe=!1;if(F.current="",K.current.clear(),a([]),g(0),h(null),!e.logRef&&!H)return u(!1),()=>{oe=!0};u(!0);const xe=typeof e.logBytes=="number"&&e.logBytes>0?Math.min(Math.max(e.logBytes+1024,256e3),2e6):256e3;return(async()=>{try{let q=0,ue=!0;for(;!oe;){const je=await us.log(e.id,q,ue?xe:256e3);if(oe)break;V(je.content,je.nextOffset===void 0);const re=je.nextOffset??je.endOffset??q+Ene(je.content);if(g(re),q=re,ue=!1,je.nextOffset===void 0||H)break}}catch(q){if(!oe){if(H&&P(q)){u(!1);return}h(q instanceof Error?q.message:"Failed to load run log")}}finally{oe||u(!1)}})(),()=>{oe=!0}},[e.id,e.logRef,e.logBytes,H]),x.useEffect(()=>{if(!wne({isLive:H}))return;const oe=setInterval(async()=>{const xe=n.length>0?Math.max(...n.map(X=>X.seq)):0;try{const X=await us.events(e.id,xe,100);X.length>0&&r(q=>[...q,...X])}catch{}},2e3);return()=>clearInterval(oe)},[e.id,H,j,n]),x.useEffect(()=>{if(!wne({isLive:H}))return;const oe=setInterval(async()=>{try{const xe=await us.log(e.id,m,256e3);xe.content&&V(xe.content,xe.nextOffset===void 0),xe.nextOffset!==void 0?g(xe.nextOffset):xe.endOffset!==void 0?g(xe.endOffset):xe.content.length>0&&g(X=>X+Ene(xe.content))}catch(xe){if(P(xe))return}},2e3);return()=>clearInterval(oe)},[e.id,H,j,m]),x.useEffect(()=>{if(!H)return;let oe=!1,xe=null,X=null;const q=()=>{oe||(xe=window.setTimeout(ue,1500))},ue=()=>{if(oe)return;const re=`${window.location.protocol==="https:"?"wss":"ws"}://${window.location.host}/api/orgs/${encodeURIComponent(e.orgId)}/events/ws`;X=new WebSocket(re),X.onopen=()=>{k(!0)},X.onmessage=fe=>{const ne=typeof fe.data=="string"?fe.data:"";if(!ne)return;let Fe;try{Fe=JSON.parse(ne)}catch{return}if(Fe.orgId!==e.orgId)return;const Ce=Ku(Fe.payload),tt=os(Ce==null?void 0:Ce.runId);if(!Ce||tt!==e.id)return;if(Fe.type==="heartbeat.run.log"){if(Ce.truncated===!0)return;const Je=typeof Ce.chunk=="string"?Ce.chunk:"";if(!Je)return;const jt=os(Ce.stream),We=jt==="stderr"||jt==="system"?jt:"stdout",Ct=os(Ce.ts)??Fe.createdAt;ce([{ts:Ct,stream:We,chunk:Je}]);return}if(Fe.type!=="heartbeat.run.event")return;const Qe=typeof Ce.seq=="number"?Ce.seq:null;if(Qe===null||!Number.isFinite(Qe))return;const pt=os(Ce.stream),Se=pt==="stdout"||pt==="stderr"||pt==="system"?pt:null,Be=os(Ce.level),Ae=Be==="info"||Be==="warn"||Be==="error"?Be:null,it={id:Qe,orgId:e.orgId,runId:e.id,agentId:e.agentId,seq:Qe,eventType:os(Ce.eventType)??"event",stream:Se,level:Ae,color:os(Ce.color),message:os(Ce.message),payload:Ku(Ce.payload),createdAt:new Date(Fe.createdAt)};r(Je=>Je.some(jt=>jt.seq===Qe)?Je:[...Je,it])},X.onerror=()=>{X==null||X.close()},X.onclose=()=>{k(!1),q()}};return ue(),()=>{oe=!0,k(!1),xe!==null&&window.clearTimeout(xe),X&&(X.onopen=null,X.onmessage=null,X.onerror=null,X.onclose=null,X.close(1e3,"run_detail_unmount"))}},[H,e.orgId,e.id,e.agentId]);const ge=((ze=ke({queryKey:U.instance.generalSettings,queryFn:()=>la.getGeneral()}).data)==null?void 0:ze.censorUsernameInLogs)===!0,ie=x.useMemo(()=>{const oe=n.find(xe=>xe.eventType==="adapter.invoke");return fp(Ku((oe==null?void 0:oe.payload)??null),ge)},[ge,n]),ae=x.useMemo(()=>{const oe=n.find(xe=>xe.eventType==="adapter.skill_usage");return fp(Ku((oe==null?void 0:oe.payload)??null),ge)},[ge,n]),he=x.useMemo(()=>im(t),[t]),me=x.useMemo(()=>{const oe=Swe(s,he.parseStdoutLine,{censorUsernameInLogs:ge}),xe=B.get(e.id)??[],X=xe.length>oe.length?xe:oe,q=n.map(ue=>x1t(ue,{redactText:je=>iu(je,ge),redactValue:je=>fp(je,ge)}));return b1t(X,q)},[he,ge,n,B,s,e.id]),ye=!!ie,Me=(ie==null?void 0:ie.prompt)!==void 0?T1t(ie.prompt,ge):null,$e=`${me.length} ${me.length===1?"entry":"entries"}`,Re=x.useCallback(()=>{var xe;const oe=(xe=z.current)==null?void 0:xe.getBoundingClientRect();if(oe&&window.innerWidth>0&&window.innerHeight>0){const X=Number.parseFloat(window.getComputedStyle(document.documentElement).fontSize)||16,q=Math.min(window.innerWidth-24,window.innerWidth*.96,X*88),ue=Math.min(window.innerHeight*.92,X*54),je=oe.left+oe.width/2,re=oe.top+oe.height/2,fe=Math.round(je-window.innerWidth/2),ne=Math.round(re-window.innerHeight/2);O({fromX:`${fe}px`,fromY:`${ne}px`,settleX:`${Math.round(fe*-.025)}px`,settleY:`${Math.round(ne*-.025)}px`,fromScaleX:`${Math.max(.035,Math.min(.18,oe.width/q)).toFixed(3)}`,fromScaleY:`${Math.max(.045,Math.min(.18,oe.height/ue)).toFixed(3)}`})}E(!0)},[]),Ue={"--transcript-dialog-from-x":I.fromX,"--transcript-dialog-from-y":I.fromY,"--transcript-dialog-settle-x":I.settleX,"--transcript-dialog-settle-y":I.settleY,"--transcript-dialog-from-scale-x":I.fromScaleX,"--transcript-dialog-from-scale-y":I.fromScaleY},we=()=>i.jsx("div",{className:"inline-flex rounded-lg border border-border/70 bg-background/70 p-0.5",children:["nice","raw"].map(oe=>i.jsx("button",{type:"button",className:Q("rounded-md px-2.5 py-1 text-[11px] font-medium capitalize transition-colors",w===oe?"bg-accent text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),onClick:()=>N(oe),children:oe},oe))});return x.useEffect(()=>{N("nice"),A("transcript"),E(!1)},[e.id]),x.useEffect(()=>{!ye&&S==="invocation"&&A("transcript")},[S,ye]),o&&c?i.jsx("p",{className:"text-xs text-muted-foreground",children:"Loading run logs..."}):n.length===0&&s.length===0&&!d?i.jsx("p",{className:"text-xs text-muted-foreground",children:"No log events."}):i.jsxs("div",{className:"space-y-3",children:[i.jsx(Q1t,{operations:Y,censorUsernameInLogs:ge}),i.jsxs("div",{className:"rounded-2xl border border-border/70 bg-background/40",children:[i.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 border-b border-border/70 px-3 py-2 sm:px-4",children:[ye?i.jsx(Xu,{value:S,onValueChange:oe=>A(oe),children:i.jsx(Jp,{items:[{value:"transcript",label:"Transcript"},{value:"invocation",label:"Invocation",mobileLabel:"Invocation",tooltip:"Exact adapter invoke payload"}],value:S,onValueChange:oe=>A(oe),align:"start",triggerClassName:"px-2 py-1 text-xs"})}):i.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"Transcript"}),M?i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i.jsx("span",{className:"text-xs text-muted-foreground",children:$e}),we(),i.jsxs(de,{ref:z,variant:"ghost",size:"icon-sm",className:"group relative overflow-hidden text-muted-foreground transition-[background-color,border-color,color,box-shadow,transform] duration-200 hover:scale-[1.03] hover:shadow-sm active:scale-95",onClick:Re,"aria-label":"Expand transcript",title:"Expand transcript",children:[i.jsx("span",{className:"absolute inset-0 rounded-[inherit] bg-accent/0 transition-colors duration-200 group-hover:bg-accent/70","aria-hidden":!0}),i.jsx(_v,{className:"relative h-4 w-4 transition-transform duration-200 ease-out group-hover:scale-110"})]}),H&&!b&&i.jsx(de,{variant:"ghost",size:"xs",onClick:()=>{const oe=G();$.current=!0,v(!0),_ne(oe,"auto"),L.current=e5(oe)},children:"Jump to live"}),H&&i.jsxs("span",{className:"flex items-center gap-1 text-xs text-cyan-400",children:[i.jsxs("span",{className:"relative flex h-2 w-2",children:[i.jsx("span",{className:"animate-pulse absolute inline-flex h-full w-full rounded-full bg-cyan-400 opacity-75"}),i.jsx("span",{className:"relative inline-flex rounded-full h-2 w-2 bg-cyan-400"})]}),"Live"]})]}):null]}),M?i.jsxs("div",{className:"max-h-[38rem] overflow-y-auto p-3 sm:p-4",children:[i.jsx(Af,{entries:me,mode:w,streaming:H,collapseStdout:!0,emptyMessage:e.logRef?"Waiting for transcript...":"No persisted transcript for this run.",presentation:"detail"}),d&&i.jsx("div",{className:"mt-3 rounded-xl border border-red-500/20 bg-red-500/[0.06] px-3 py-2 text-xs text-red-700 dark:text-red-300",children:d}),i.jsx("div",{ref:D})]}):i.jsx("div",{className:"max-h-[38rem] overflow-y-auto p-3 sm:p-4",children:i.jsxs("div",{className:"space-y-3",children:[typeof(ie==null?void 0:ie.agentRuntimeType)=="string"&&i.jsxs("div",{className:"text-xs",children:[i.jsx("span",{className:"text-muted-foreground",children:"Runtime: "}),ie.agentRuntimeType]}),typeof(ie==null?void 0:ie.cwd)=="string"&&i.jsxs("div",{className:"text-xs break-all",children:[i.jsx("span",{className:"text-muted-foreground",children:"Working dir: "}),i.jsx("span",{className:"font-mono",children:ie.cwd})]}),typeof(ie==null?void 0:ie.command)=="string"&&i.jsxs("div",{className:"text-xs break-all",children:[i.jsx("span",{className:"text-muted-foreground",children:"Command: "}),i.jsx("span",{className:"font-mono",children:[ie.command,...Array.isArray(ie.commandArgs)?ie.commandArgs.filter(oe=>typeof oe=="string"):[]].join(" ")})]}),Array.isArray(ie==null?void 0:ie.commandNotes)&&ie.commandNotes.length>0&&i.jsxs("div",{children:[i.jsx("div",{className:"mb-1 text-xs text-muted-foreground",children:"Command notes"}),i.jsx("ul",{className:"list-disc space-y-1 pl-5",children:ie.commandNotes.filter(oe=>typeof oe=="string"&&oe.trim().length>0).map((oe,xe)=>i.jsx("li",{className:"text-xs break-all font-mono",children:oe},`${xe}-${oe}`))})]}),i.jsx(U1t,{invocationPayload:ie,usagePayload:ae}),Me!==null&&i.jsxs("div",{children:[i.jsx("div",{className:"mb-1 text-xs text-muted-foreground",children:"Prompt"}),i.jsxs("div",{className:"relative",children:[i.jsx(sv,{text:Me,ariaLabel:"Copy invocation prompt",title:"Copy prompt",containerClassName:"absolute right-2 top-2",className:"inline-flex h-7 w-7 items-center justify-center rounded-md border border-border/70 bg-background/80 text-muted-foreground shadow-sm hover:bg-muted/80 hover:text-foreground",children:i.jsx(xi,{className:"h-3.5 w-3.5"})}),i.jsx("pre",{"data-testid":"invocation-prompt",className:"rounded-md bg-neutral-100 p-2 pr-11 text-xs whitespace-pre-wrap overflow-x-auto dark:bg-neutral-950",children:Me})]})]}),(ie==null?void 0:ie.context)!==void 0&&i.jsxs("div",{children:[i.jsx("div",{className:"mb-1 text-xs text-muted-foreground",children:"Context"}),i.jsx("pre",{className:"rounded-md bg-neutral-100 p-2 text-xs whitespace-pre-wrap overflow-x-auto dark:bg-neutral-950",children:JSON.stringify(fp(ie.context,ge),null,2)})]}),(ie==null?void 0:ie.env)!==void 0&&i.jsxs("div",{children:[i.jsx("div",{className:"mb-1 text-xs text-muted-foreground",children:"Environment"}),i.jsx("pre",{className:"rounded-md bg-neutral-100 p-2 text-xs font-mono whitespace-pre-wrap overflow-x-auto dark:bg-neutral-950",children:O1t(ie.env,ge)})]}),n.length>0&&i.jsx(V1t,{events:n,censorUsernameInLogs:ge})]})})]}),i.jsx(Bs,{open:_,onOpenChange:E,children:i.jsxs(Ys,{overlayClassName:"transcript-modal-overlay",style:Ue,className:"transcript-modal-content grid h-[min(92dvh,54rem)] max-w-[min(96vw,88rem)] grid-rows-[auto_minmax(0,1fr)] gap-0 overflow-hidden rounded-2xl p-0 sm:max-w-[min(96vw,88rem)]",children:[i.jsx(ma,{className:"transcript-modal-header border-b border-border/70 px-4 py-3 pr-12 text-left",children:i.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[i.jsxs("div",{className:"min-w-0",children:[i.jsx(Ui,{className:"text-sm",children:"Transcript"}),i.jsxs(Ba,{className:"sr-only",children:["Expanded transcript for run ",e.id,"."]})]}),i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i.jsx("span",{className:"text-xs text-muted-foreground",children:$e}),we(),H&&i.jsxs("span",{className:"flex items-center gap-1 text-xs text-cyan-400",children:[i.jsxs("span",{className:"relative flex h-2 w-2",children:[i.jsx("span",{className:"absolute inline-flex h-full w-full animate-pulse rounded-full bg-cyan-400 opacity-75"}),i.jsx("span",{className:"relative inline-flex h-2 w-2 rounded-full bg-cyan-400"})]}),"Live"]})]})]})}),i.jsxs("div",{className:"transcript-modal-body min-h-0 overflow-y-auto p-3 sm:p-4",children:[i.jsx(Af,{entries:me,mode:w,streaming:H,collapseStdout:!0,emptyMessage:e.logRef?"Waiting for transcript...":"No persisted transcript for this run.",presentation:"detail"}),d&&i.jsx("div",{className:"mt-3 rounded-xl border border-red-500/20 bg-red-500/[0.06] px-3 py-2 text-xs text-red-700 dark:text-red-300",children:d})]})]})}),(e.status==="failed"||e.status==="timed_out")&&i.jsxs("div",{className:"rounded-lg border border-red-300 dark:border-red-500/30 bg-red-50 dark:bg-red-950/20 p-3 space-y-2",children:[i.jsx("div",{className:"text-xs font-medium text-red-700 dark:text-red-300",children:"Failure details"}),e.error&&i.jsxs("div",{className:"text-xs text-red-600 dark:text-red-200",children:[i.jsx("span",{className:"text-red-700 dark:text-red-300",children:"Error: "}),iu(e.error,ge)]}),e.stderrExcerpt&&e.stderrExcerpt.trim()&&i.jsxs("div",{children:[i.jsx("div",{className:"text-xs text-red-700 dark:text-red-300 mb-1",children:"stderr excerpt"}),i.jsx("pre",{className:"min-w-0 max-w-full bg-red-50 dark:bg-neutral-950 rounded-md p-2 text-xs overflow-x-auto whitespace-pre-wrap break-words text-red-800 dark:text-red-100",children:iu(e.stderrExcerpt,ge)})]}),e.resultJson&&i.jsxs("div",{children:[i.jsx("div",{className:"text-xs text-red-700 dark:text-red-300 mb-1",children:"runtime result JSON"}),i.jsx("pre",{className:"min-w-0 max-w-full bg-red-50 dark:bg-neutral-950 rounded-md p-2 text-xs overflow-x-auto whitespace-pre-wrap break-words text-red-800 dark:text-red-100",children:JSON.stringify(fp(e.resultJson,ge),null,2)})]}),e.stdoutExcerpt&&e.stdoutExcerpt.trim()&&!e.resultJson&&i.jsxs("div",{children:[i.jsx("div",{className:"text-xs text-red-700 dark:text-red-300 mb-1",children:"stdout excerpt"}),i.jsx("pre",{className:"min-w-0 max-w-full bg-red-50 dark:bg-neutral-950 rounded-md p-2 text-xs overflow-x-auto whitespace-pre-wrap break-words text-red-800 dark:text-red-100",children:iu(e.stdoutExcerpt,ge)})]})]})]})}function awt({agentId:e,orgId:t}){const n=xn(),[r,s]=x.useState(""),[a,o]=x.useState(null),[l,c]=x.useState(!1),[u,d]=x.useState(!1),{data:h,isLoading:m}=ke({queryKey:U.agents.keys(e),queryFn:()=>$t.listKeys(e,t)}),g=nt({mutationFn:()=>$t.createKey(e,r.trim()||"Default",t),onSuccess:w=>{o(w.token),c(!0),s(""),n.invalidateQueries({queryKey:U.agents.keys(e)})}}),b=nt({mutationFn:w=>$t.revokeKey(e,w,t),onSuccess:()=>{n.invalidateQueries({queryKey:U.agents.keys(e)})}});function v(){a&&(navigator.clipboard.writeText(a),d(!0),setTimeout(()=>d(!1),2e3))}const j=(h??[]).filter(w=>!w.revokedAt),k=(h??[]).filter(w=>w.revokedAt);return i.jsxs("div",{className:"space-y-6",children:[a&&i.jsxs("div",{className:"border border-yellow-300 dark:border-yellow-600/40 bg-yellow-50 dark:bg-yellow-500/5 rounded-lg p-4 space-y-2",children:[i.jsx("p",{className:"text-sm font-medium text-yellow-700 dark:text-yellow-400",children:"API key created — copy it now, it will not be shown again."}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("code",{className:"flex-1 bg-neutral-100 dark:bg-neutral-950 rounded px-3 py-1.5 text-xs font-mono text-green-700 dark:text-green-300 truncate",children:l?a:a.replace(/./g,"•")}),i.jsx(de,{variant:"ghost",size:"icon-sm",onClick:()=>c(w=>!w),title:l?"Hide":"Show",children:l?i.jsx(ag,{className:"h-3.5 w-3.5"}):i.jsx(Wh,{className:"h-3.5 w-3.5"})}),i.jsx(de,{variant:"ghost",size:"icon-sm",onClick:v,title:"Copy",children:i.jsx(xi,{className:"h-3.5 w-3.5"})}),u&&i.jsx("span",{className:"text-xs text-green-400",children:"Copied!"})]}),i.jsx(de,{variant:"ghost",size:"sm",className:"text-muted-foreground text-xs",onClick:()=>o(null),children:"Dismiss"})]}),i.jsxs("div",{className:"border border-border rounded-lg p-4 space-y-3",children:[i.jsxs("h3",{className:"text-xs font-medium text-muted-foreground flex items-center gap-2",children:[i.jsx(I8e,{className:"h-3.5 w-3.5"}),"Create API Key"]}),i.jsx("p",{className:"text-xs text-muted-foreground",children:"API keys allow this agent to authenticate calls to the Rudder server."}),i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(An,{placeholder:"Key name (e.g. production)",value:r,onChange:w=>s(w.target.value),className:"h-8 text-sm",onKeyDown:w=>{w.key==="Enter"&&g.mutate()}}),i.jsxs(de,{size:"sm",onClick:()=>g.mutate(),disabled:g.isPending,children:[i.jsx(Hn,{className:"h-3.5 w-3.5 mr-1"}),"Create"]})]})]}),m&&i.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading keys..."}),!m&&j.length===0&&!a&&i.jsx("p",{className:"text-sm text-muted-foreground",children:"No active API keys."}),j.length>0&&i.jsxs("div",{children:[i.jsx("h3",{className:"text-xs font-medium text-muted-foreground mb-2",children:"Active Keys"}),i.jsx("div",{className:"border border-border rounded-lg divide-y divide-border",children:j.map(w=>i.jsxs("div",{className:"flex items-center justify-between px-4 py-2.5",children:[i.jsxs("div",{children:[i.jsx("span",{className:"text-sm font-medium",children:w.name}),i.jsxs("span",{className:"text-xs text-muted-foreground ml-3",children:["Created ",po(w.createdAt)]})]}),i.jsx(de,{variant:"ghost",size:"sm",className:"text-destructive hover:text-destructive text-xs",onClick:()=>b.mutate(w.id),disabled:b.isPending,children:"Revoke"})]},w.id))})]}),k.length>0&&i.jsxs("div",{children:[i.jsx("h3",{className:"text-xs font-medium text-muted-foreground mb-2",children:"Revoked Keys"}),i.jsx("div",{className:"border border-border rounded-lg divide-y divide-border opacity-50",children:k.map(w=>i.jsx("div",{className:"flex items-center justify-between px-4 py-2.5",children:i.jsxs("div",{children:[i.jsx("span",{className:"text-sm line-through",children:w.name}),i.jsxs("span",{className:"text-xs text-muted-foreground ml-3",children:["Revoked ",w.revokedAt?po(w.revokedAt):""]})]})},w.id))})]})]})}function owt(){const{selectedOrganizationId:e}=bn(),{openNewProject:t}=Gr(),{setBreadcrumbs:n}=Nr();x.useEffect(()=>{n([{label:"Projects"}])},[n]);const{data:r,isLoading:s,error:a}=ke({queryKey:U.projects.list(e),queryFn:()=>gs.list(e),enabled:!!e}),o=x.useMemo(()=>(r??[]).filter(l=>!l.archivedAt),[r]);return e?s?i.jsx(Is,{variant:"list"}):o.length>0?i.jsx(ls,{to:Hj(o[0]),replace:!0}):i.jsxs("div",{className:"space-y-4",children:[a&&i.jsx("p",{className:"text-sm text-destructive",children:a.message}),!s&&o.length===0&&i.jsx(Er,{icon:og,message:"No projects yet.",action:"Add Project",onAction:t}),o.length>0&&i.jsx("div",{className:"border border-border",children:o.map(l=>i.jsx(Yd,{title:l.name,subtitle:l.description??void 0,to:Hj(l),trailing:i.jsxs("div",{className:"flex items-center gap-3",children:[l.targetDate&&i.jsx("span",{className:"text-xs text-muted-foreground",children:po(l.targetDate)}),i.jsx(yr,{status:l.status})]})},l.id))})]}):i.jsx(Er,{icon:og,message:"Select a organization to view projects."})}function ed({className:e,orientation:t="horizontal",decorative:n=!0,...r}){return i.jsx(ece,{"data-slot":"separator",decorative:n,orientation:t,className:Q("bg-border shrink-0 data-[orientation=horizontal]:h-px data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-px",e),...r})}const lwt=250,cwt=1600;function mq(){const[e,t]=x.useState("idle"),n=x.useRef(0),r=x.useRef(null),s=x.useRef(null),a=x.useCallback(()=>{r.current&&(clearTimeout(r.current),r.current=null),s.current&&(clearTimeout(s.current),s.current=null)},[]);x.useEffect(()=>a,[a]);const o=x.useCallback(()=>{n.current+=1,a(),t("idle")},[a]),l=x.useCallback(()=>{a(),t("idle")},[a]),c=x.useCallback(async u=>{const d=n.current+1;n.current=d,a(),r.current=setTimeout(()=>{n.current===d&&t("saving")},lwt);try{if(await u(),n.current!==d)return;a(),t("saved"),s.current=setTimeout(()=>{n.current===d&&t("idle")},cwt)}catch(h){throw n.current!==d||(a(),t("error")),h}},[a]);return{state:e,markDirty:l,reset:o,runSave:c}}const Rne="px-1 -mx-1",uwt="px-1",dwt=900;function fwt(e){return e instanceof HTMLElement?e:e instanceof Node?e.parentElement:null}function zh({value:e,onSave:t,as:n="span",className:r,placeholder:s="Click to edit...",multiline:a=!1,imageUploadHandler:o,mentions:l}){const[c,u]=x.useState(!1),[d,h]=x.useState(!1),[m,g]=x.useState(e),b=x.useRef(null),v=x.useRef(null),j=x.useRef(null),{state:k,markDirty:w,reset:N,runSave:S}=mq();x.useEffect(()=>{a&&d||g(e)},[e,a,d]),x.useEffect(()=>()=>{j.current&&clearTimeout(j.current)},[]);const A=x.useCallback(O=>{O&&(O.style.height="auto",O.style.height=`${O.scrollHeight}px`)},[]);x.useEffect(()=>{c&&b.current&&(b.current.focus(),b.current.select(),b.current instanceof HTMLTextAreaElement&&A(b.current))},[c,A]),x.useEffect(()=>{if(!c||!a)return;const O=requestAnimationFrame(()=>{var M;(M=v.current)==null||M.focus()});return()=>cancelAnimationFrame(O)},[c,a]);const _=x.useCallback(async(O=m)=>{const M=O.trim();M&&M!==e?await Promise.resolve(t(M)):g(e),a||u(!1)},[m,a,t,e]);function E(O){O.key==="Enter"&&!a&&(O.preventDefault(),_()),O.key==="Escape"&&(j.current&&clearTimeout(j.current),N(),g(e),a?(h(!1),u(!1),document.activeElement instanceof HTMLElement&&document.activeElement.blur()):u(!1))}if(x.useEffect(()=>{if(!a||!d)return;const O=m.trim();if(!O||O===e){k!=="saved"&&N();return}return w(),j.current&&clearTimeout(j.current),j.current=setTimeout(()=>{S(()=>_(O))},dwt),()=>{j.current&&clearTimeout(j.current)}},[k,_,m,w,a,d,N,S,e]),a&&c)return i.jsxs("div",{className:Q(uwt,"rounded"),onFocusCapture:()=>h(!0),onBlurCapture:O=>{if(O.currentTarget.contains(O.relatedTarget))return;j.current&&clearTimeout(j.current),h(!1),u(!1);const M=m.trim();if(!M||M===e){N(),_();return}S(()=>_())},onKeyDown:E,children:[i.jsx(Vo,{ref:v,value:m,onChange:g,placeholder:s,bordered:!1,className:"bg-transparent",contentClassName:Q("rudder-edit-in-place-content",r),imageUploadHandler:o,mentions:l,onSubmit:()=>{const O=m.trim();if(!O||O===e){N(),_();return}S(()=>_())}}),i.jsx("div",{className:"flex min-h-4 items-center justify-end pr-1",children:i.jsx("span",{className:Q("text-[11px] transition-opacity duration-150",k==="error"?"text-destructive":"text-muted-foreground",k==="idle"?"opacity-0":"opacity-100"),children:k==="saving"?"Autosaving...":k==="saved"?"Saved":k==="error"?"Could not save":"Idle"})})]});if(c)return i.jsx("textarea",{ref:b,value:m,rows:1,onChange:O=>{g(O.target.value),A(O.target)},onBlur:()=>{_()},onKeyDown:E,className:Q("w-full bg-transparent rounded outline-none resize-none overflow-hidden",Rne,r)});const I=e&&a?"div":n;return i.jsx(I,{className:Q("rounded overflow-hidden",a?"cursor-text":"cursor-pointer transition-colors hover:bg-accent/50",Rne,!e&&"text-muted-foreground italic",r),onClick:O=>{var M;(M=fwt(O.target))!=null&&M.closest("a")||u(!0)},children:e&&a?i.jsx(gi,{onLinkClick:({event:O})=>{O.stopPropagation()},children:e}):e||s})}const hwt=[{value:"backlog",label:"Backlog"},{value:"planned",label:"Planned"},{value:"in_progress",label:"In Progress"},{value:"completed",label:"Completed"},{value:"cancelled",label:"Cancelled"}];function mwt({state:e}){return e==="saving"?i.jsxs("span",{className:"inline-flex items-center gap-1 text-[11px] text-muted-foreground",children:[i.jsx(or,{className:"h-3 w-3 animate-spin"}),"Saving"]}):e==="saved"?i.jsxs("span",{className:"inline-flex items-center gap-1 text-[11px] text-green-600 dark:text-green-400",children:[i.jsx(ws,{className:"h-3 w-3"}),"Saved"]}):e==="error"?i.jsxs("span",{className:"inline-flex items-center gap-1 text-[11px] text-destructive",children:[i.jsx(Kh,{className:"h-3 w-3"}),"Failed"]}):null}function bx({label:e,state:t}){return i.jsxs("div",{className:"flex items-center gap-1.5",children:[i.jsx("span",{className:"text-xs text-muted-foreground",children:e}),i.jsx(mwt,{state:t})]})}function Zm({label:e,children:t,alignStart:n=!1,valueClassName:r=""}){return i.jsxs("div",{className:Q("flex gap-3 py-1.5",n?"items-start":"items-center"),children:[i.jsx("div",{className:"shrink-0 w-20",children:e}),i.jsx("div",{className:Q("min-w-0 flex-1",n?"pt-0.5":"flex items-center gap-1.5",r),children:t})]})}function pwt({status:e,onChange:t}){const[n,r]=x.useState(!1),s=sfe[e]??ife;return i.jsxs(cr,{open:n,onOpenChange:r,children:[i.jsx(mr,{asChild:!0,children:i.jsx("button",{className:Q("inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-medium whitespace-nowrap shrink-0 cursor-pointer hover:opacity-80 transition-opacity",s),children:e.replace("_"," ")})}),i.jsx(ur,{className:"w-40 p-1",align:"start",children:hwt.map(a=>i.jsx(de,{variant:"ghost",size:"sm",className:Q("w-full justify-start gap-2 text-xs",a.value===e&&"bg-accent"),onClick:()=>{t(a.value),r(!1)},children:a.label},a.value))})]})}function gwt({project:e,onArchive:t,archivePending:n}){const[r,s]=x.useState(!1),a=!e.archivedAt,o=a?"Archive":"Unarchive";return i.jsxs("div",{className:"space-y-3 rounded-md border border-destructive/40 bg-destructive/5 px-4 py-4",children:[i.jsx("p",{className:"text-sm text-muted-foreground",children:a?"Archive this project to hide it from the sidebar and project selectors.":"Unarchive this project to restore it in the sidebar and project selectors."}),n?i.jsxs(de,{size:"sm",variant:"destructive",disabled:!0,children:[i.jsx(or,{className:"h-3 w-3 animate-spin mr-1"}),a?"Archiving...":"Unarchiving..."]}):r?i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("span",{className:"text-sm text-destructive font-medium",children:[o," “",e.name,"”?"]}),i.jsx(de,{size:"sm",variant:"destructive",onClick:()=>{s(!1),t(a)},children:"Confirm"}),i.jsx(de,{size:"sm",variant:"outline",onClick:()=>s(!1),children:"Cancel"})]}):i.jsx(de,{size:"sm",variant:"destructive",onClick:()=>s(!0),children:a?i.jsxs(i.Fragment,{children:[i.jsx(Cv,{className:"h-3 w-3 mr-1"}),o," project"]}):i.jsxs(i.Fragment,{children:[i.jsx(Bue,{className:"h-3 w-3 mr-1"}),o," project"]})})]})}function xwt({project:e,onUpdate:t,onFieldUpdate:n,getFieldSaveState:r,onArchive:s,archivePending:a}){var k;const{selectedOrganizationId:o}=bn(),[l,c]=x.useState(!1),u=(w,N)=>{if(n){n(w,N);return}t==null||t(N)},d=w=>(r==null?void 0:r(w))??"idle",{data:h}=ke({queryKey:U.goals.list(o),queryFn:()=>ml.list(o),enabled:!!o}),m=e.goalIds.length>0?e.goalIds:e.goalId?[e.goalId]:[],g=e.goals.length>0?e.goals:m.map(w=>{var N;return{id:w,title:((N=h==null?void 0:h.find(S=>S.id===w))==null?void 0:N.title)??w.slice(0,8)}}),b=(h??[]).filter(w=>!m.includes(w.id)),v=w=>{!t&&!n||u("goals",{goalIds:m.filter(N=>N!==w)})},j=w=>{!t&&!n||m.includes(w)||(u("goals",{goalIds:[...m,w]}),c(!1))};return i.jsxs("div",{children:[i.jsxs("div",{className:"space-y-1 pb-4",children:[i.jsx(Zm,{label:i.jsx(bx,{label:"Name",state:d("name")}),children:t||n?i.jsx(Ti,{value:e.name,onCommit:w=>u("name",{name:w}),immediate:!0,className:"w-full rounded border border-border bg-transparent px-2 py-1 text-sm outline-none",placeholder:"Project name"}):i.jsx("span",{className:"text-sm",children:e.name})}),i.jsx(Zm,{label:i.jsx(bx,{label:"Description",state:d("description")}),alignStart:!0,valueClassName:"space-y-0.5",children:t||n?i.jsx(zh,{value:e.description??"",onSave:w=>u("description",{description:w}),as:"p",className:"text-sm text-muted-foreground",placeholder:"Add a description...",multiline:!0}):i.jsx("p",{className:"text-sm text-muted-foreground",children:((k=e.description)==null?void 0:k.trim())||"No description"})}),i.jsx(Zm,{label:i.jsx(bx,{label:"Status",state:d("status")}),children:t||n?i.jsx(pwt,{status:e.status,onChange:w=>u("status",{status:w})}):i.jsx(yr,{status:e.status})}),e.leadAgentId&&i.jsx(Zm,{label:"Lead",children:i.jsx("span",{className:"text-sm font-mono",children:e.leadAgentId.slice(0,8)})}),i.jsxs(Zm,{label:i.jsx(bx,{label:"Goals",state:d("goals")}),alignStart:!0,valueClassName:"space-y-2",children:[g.length>0&&i.jsx("div",{className:"flex flex-wrap gap-1.5",children:g.map(w=>i.jsxs("span",{className:"inline-flex items-center gap-1 rounded-md border border-border px-2 py-1 text-xs",children:[i.jsx(Nt,{to:`/goals/${w.id}`,className:"hover:underline max-w-[220px] truncate",children:w.title}),(t||n)&&i.jsx("button",{className:"text-muted-foreground hover:text-foreground",type:"button",onClick:()=>v(w.id),"aria-label":`Remove goal ${w.title}`,children:i.jsx(ti,{className:"h-3 w-3"})})]},w.id))}),(t||n)&&i.jsxs(cr,{open:l,onOpenChange:c,children:[i.jsx(mr,{asChild:!0,children:i.jsxs(de,{variant:"outline",size:"xs",className:Q("h-6 w-fit px-2",g.length>0&&"ml-1"),disabled:b.length===0,children:[i.jsx(Hn,{className:"h-3 w-3 mr-1"}),"Goal"]})}),i.jsx(ur,{className:"w-56 p-1",align:"start",children:b.length===0?i.jsx("div",{className:"px-2 py-1.5 text-xs text-muted-foreground",children:"All goals linked."}):b.map(w=>i.jsx("button",{className:"flex items-center w-full px-2 py-1.5 text-xs rounded hover:bg-accent/50",onClick:()=>j(w.id),children:w.title},w.id))})]})]}),i.jsx(Zm,{label:i.jsx(bx,{label:"Created",state:"idle"}),children:i.jsx("span",{className:"text-sm",children:po(e.createdAt)})}),i.jsx(Zm,{label:i.jsx(bx,{label:"Updated",state:"idle"}),children:i.jsx("span",{className:"text-sm",children:po(e.updatedAt)})}),e.targetDate&&i.jsx(Zm,{label:i.jsx(bx,{label:"Target Date",state:"idle"}),children:i.jsx("span",{className:"text-sm",children:po(e.targetDate)})})]}),s&&i.jsxs(i.Fragment,{children:[i.jsx(ed,{className:"my-4"}),i.jsxs("div",{className:"space-y-4 py-4",children:[i.jsx("div",{className:"text-xs font-medium text-destructive uppercase tracking-wide",children:"Danger Zone"}),i.jsx(gwt,{project:e,onArchive:s,archivePending:a})]})]})]})}function Mne(){return{name:"",kind:"directory",locator:"",description:"",role:"working_set",note:""}}function One(e){switch(e){case"directory":return Ic;case"file":return kf;case"connector_object":return mu;case"url":default:return Sb}}function Dne(e,t){return e.filter(n=>n.role===t).length}function bwt({project:e}){const{organizations:t}=bn(),{pushToast:n}=gr(),r=xn(),[s,a]=x.useState(!1),[o,l]=x.useState(!1),[c,u]=x.useState(Mne()),d=t.find(S=>S.id===e.orgId)??null,h=Jd("/resources",(d==null?void 0:d.issuePrefix)??null),m=x.useMemo(()=>[...e.resources].sort((S,A)=>S.sortOrder-A.sortOrder),[e.resources]),{data:g}=ke({queryKey:U.organizations.resources(e.orgId),queryFn:()=>Fn.listResources(e.orgId),enabled:!!e.orgId}),b=x.useMemo(()=>(g??[]).filter(S=>!e.resources.some(A=>A.resourceId===S.id)),[g,e.resources]),v=()=>{r.invalidateQueries({queryKey:["projects","detail"]}),r.invalidateQueries({queryKey:U.projects.list(e.orgId)}),r.invalidateQueries({queryKey:U.projects.resources(e.id)}),r.invalidateQueries({queryKey:U.organizations.resources(e.orgId)})},j=nt({mutationFn:S=>gs.attachResource(e.id,S,e.orgId),onSuccess:()=>{v(),n({title:"Project resource attached",tone:"success"})},onError:S=>{n({title:S instanceof Error?S.message:"Failed to attach project resource",tone:"error"})}}),k=nt({mutationFn:S=>gs.updateResourceAttachment(e.id,S.attachmentId,{role:S.role,note:S.note,sortOrder:S.sortOrder},e.orgId),onSuccess:()=>{v()},onError:S=>{n({title:S instanceof Error?S.message:"Failed to update project resource",tone:"error"})}}),w=nt({mutationFn:S=>gs.removeResourceAttachment(e.id,S,e.orgId),onSuccess:()=>{v(),n({title:"Project resource removed",tone:"success"})},onError:S=>{n({title:S instanceof Error?S.message:"Failed to remove project resource",tone:"error"})}}),N=nt({mutationFn:async()=>{const S=await Fn.createResource(e.orgId,{name:c.name.trim(),kind:c.kind,locator:c.locator.trim(),description:c.description.trim()||void 0});return gs.attachResource(e.id,{resourceId:S.id,role:c.role,note:c.note.trim()||void 0,sortOrder:e.resources.length},e.orgId)},onSuccess:()=>{v(),u(Mne()),l(!1),n({title:"Org resource created and attached",tone:"success"})},onError:S=>{n({title:S instanceof Error?S.message:"Failed to create and attach resource",tone:"error"})}});return i.jsxs("div",{className:"space-y-5",children:[i.jsxs("section",{className:"rounded-[var(--radius-lg)] border border-border bg-card",children:[i.jsxs("div",{className:"flex flex-col gap-4 border-b border-border px-5 py-4 md:flex-row md:items-start md:justify-between",children:[i.jsxs("div",{className:"space-y-1.5",children:[i.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-[0.12em] text-muted-foreground",children:"Project Context"}),i.jsx("div",{className:"text-base font-semibold text-foreground",children:"Resources"}),i.jsx("p",{className:"max-w-2xl text-sm text-muted-foreground",children:"Choose the repos, docs, URLs, and connector objects agents should actually use on this project. The org catalog stays canonical; this tab decides what matters here."})]}),i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i.jsxs(cr,{open:s,onOpenChange:a,children:[i.jsx(mr,{asChild:!0,children:i.jsxs(de,{variant:"outline",size:"sm",disabled:b.length===0||j.isPending,children:[i.jsx(Sb,{className:"mr-1.5 h-3.5 w-3.5"}),"Attach existing"]})}),i.jsxs(ur,{align:"end",className:"w-[22rem] p-2",children:[i.jsxs("div",{className:"px-2 pb-2 pt-1",children:[i.jsx("div",{className:"text-sm font-medium text-foreground",children:"Attach from org catalog"}),i.jsx("div",{className:"text-xs text-muted-foreground",children:"Pick an existing shared resource, then add project-specific role and note below."})]}),b.length===0?i.jsx("div",{className:"px-2 py-3 text-sm text-muted-foreground",children:"All org resources are already attached to this project."}):i.jsx("div",{className:"space-y-1",children:b.map(S=>{const A=One(S.kind);return i.jsxs("button",{type:"button",className:"flex w-full items-start gap-3 rounded-[calc(var(--radius-sm)-1px)] border border-transparent px-2 py-2 text-left transition-colors hover:border-border hover:bg-accent/35",onClick:()=>{j.mutate({resourceId:S.id,role:"reference",sortOrder:e.resources.length}),a(!1)},children:[i.jsx("div",{className:"mt-0.5 rounded-md border border-border/70 bg-background/80 p-1.5 text-muted-foreground",children:i.jsx(A,{className:"h-3.5 w-3.5"})}),i.jsxs("div",{className:"min-w-0",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("span",{className:"truncate text-sm font-medium text-foreground",children:S.name}),i.jsx("span",{className:"rounded-[calc(var(--radius-sm)-1px)] border border-border/70 px-1.5 py-0.5 text-[10px] uppercase tracking-[0.08em] text-muted-foreground",children:UN(S.kind)})]}),i.jsx("div",{className:"truncate font-mono text-[11px] text-muted-foreground",children:S.locator}),S.description?i.jsx("div",{className:"mt-1 line-clamp-2 text-xs text-muted-foreground",children:S.description}):null]})]},S.id)})})]})]}),i.jsxs(de,{size:"sm",onClick:()=>l(!0),children:[i.jsx(n8e,{className:"mr-1.5 h-3.5 w-3.5"}),"Add resource"]}),i.jsx(de,{asChild:!0,variant:"outline",size:"sm",children:i.jsxs(Nt,{to:h,children:[i.jsx(tF,{className:"mr-1.5 h-3.5 w-3.5"}),"Org catalog"]})})]})]}),i.jsxs("div",{className:"grid gap-3 px-5 py-4 md:grid-cols-3",children:[i.jsxs("div",{className:"rounded-[var(--radius-md)] border border-border/70 bg-background/45 px-4 py-3",children:[i.jsx("div",{className:"text-[11px] uppercase tracking-[0.08em] text-muted-foreground",children:"Attached"}),i.jsx("div",{className:"mt-1 text-2xl font-semibold text-foreground",children:m.length}),i.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:"Resources visible to agents on this project."})]}),i.jsxs("div",{className:"rounded-[var(--radius-md)] border border-border/70 bg-background/45 px-4 py-3",children:[i.jsx("div",{className:"text-[11px] uppercase tracking-[0.08em] text-muted-foreground",children:"Working Set"}),i.jsx("div",{className:"mt-1 text-2xl font-semibold text-foreground",children:Dne(m,"working_set")}),i.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:"The resources agents should actively work inside."})]}),i.jsxs("div",{className:"rounded-[var(--radius-md)] border border-border/70 bg-background/45 px-4 py-3",children:[i.jsx("div",{className:"text-[11px] uppercase tracking-[0.08em] text-muted-foreground",children:"Reference"}),i.jsx("div",{className:"mt-1 text-2xl font-semibold text-foreground",children:Dne(m,"reference")}),i.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:"Background material that frames decisions and output."})]})]})]}),i.jsxs("section",{className:"rounded-[var(--radius-lg)] border border-border bg-card",children:[i.jsx("div",{className:"flex items-center justify-between gap-3 border-b border-border px-5 py-4",children:i.jsxs("div",{children:[i.jsx("div",{className:"text-sm font-medium text-foreground",children:"Attached resources"}),i.jsx("div",{className:"text-xs text-muted-foreground",children:"Roles and notes here are project-local. They do not change the shared org catalog."})]})}),i.jsx("div",{className:"space-y-3 px-5 py-4",children:m.length===0?i.jsx("div",{className:"rounded-[var(--radius-md)] border border-dashed border-border/80 bg-background/35 px-4 py-5 text-sm text-muted-foreground",children:"No resources attached yet. Start with the repo, spec, tracking system, or any reference agents should not miss when working on this project."}):m.map(S=>{const A=One(S.resource.kind);return i.jsxs("div",{className:"rounded-[var(--radius-md)] border border-border/75 bg-[color:color-mix(in_oklab,var(--surface-elevated)_92%,transparent)] px-4 py-4",children:[i.jsxs("div",{className:"flex items-start justify-between gap-4",children:[i.jsxs("div",{className:"min-w-0",children:[i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i.jsx("div",{className:"rounded-md border border-border/70 bg-background/85 p-1.5 text-muted-foreground",children:i.jsx(A,{className:"h-3.5 w-3.5"})}),i.jsxs("div",{className:"min-w-0",children:[i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i.jsx("span",{className:"truncate text-sm font-medium text-foreground",children:S.resource.name}),i.jsx("span",{className:"rounded-[calc(var(--radius-sm)-1px)] border border-border/70 px-1.5 py-0.5 text-[10px] uppercase tracking-[0.08em] text-muted-foreground",children:UN(S.resource.kind)}),i.jsx("span",{className:"rounded-[calc(var(--radius-sm)-1px)] border border-emerald-300/50 bg-emerald-500/8 px-1.5 py-0.5 text-[10px] uppercase tracking-[0.08em] text-emerald-700 dark:text-emerald-300",children:Gut(S.role)})]}),i.jsx("div",{className:"mt-1 truncate font-mono text-[11px] text-muted-foreground",children:S.resource.locator})]})]}),S.resource.description?i.jsx("p",{className:"mt-3 text-sm text-muted-foreground",children:S.resource.description}):null]}),i.jsx(de,{type:"button",variant:"ghost",size:"icon-xs",className:"text-muted-foreground",onClick:()=>w.mutate(S.id),disabled:w.isPending,children:i.jsx(ha,{className:"h-3.5 w-3.5"})})]}),i.jsxs("div",{className:"mt-4 grid gap-3 md:grid-cols-[180px_minmax(0,1fr)]",children:[i.jsxs("label",{className:"space-y-1.5",children:[i.jsx("span",{className:"text-[11px] uppercase tracking-[0.08em] text-muted-foreground",children:"Project role"}),i.jsx("select",{value:S.role,onChange:_=>k.mutate({attachmentId:S.id,role:_.target.value,note:S.note,sortOrder:S.sortOrder}),className:"h-10 w-full rounded-[calc(var(--radius-sm)-1px)] border border-[color:var(--border-base)] bg-[color:color-mix(in_oklab,var(--surface-elevated)_98%,transparent)] px-3 text-sm outline-none transition-[border-color,box-shadow] focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50",children:YE.map(_=>i.jsx("option",{value:_.value,children:_.label},_.value))})]}),i.jsxs("div",{className:"space-y-1.5",children:[i.jsx("span",{className:"text-[11px] uppercase tracking-[0.08em] text-muted-foreground",children:"Project note"}),i.jsx(Ti,{value:S.note??"",onCommit:_=>k.mutate({attachmentId:S.id,role:S.role,note:_,sortOrder:S.sortOrder}),immediate:!0,className:"h-10 w-full rounded-[calc(var(--radius-sm)-1px)] border border-[color:var(--border-base)] bg-[color:color-mix(in_oklab,var(--surface-elevated)_98%,transparent)] px-3 text-sm outline-none transition-[border-color,box-shadow] focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50",placeholder:"Optional project-specific guidance for agents"})]})]})]},S.id)})})]}),i.jsx(Bs,{open:o,onOpenChange:l,children:i.jsxs(Ys,{className:"sm:max-w-2xl",children:[i.jsxs(ma,{children:[i.jsx(Ui,{children:"Add resource"}),i.jsx(Ba,{children:"Create a new org resource and attach it to this project in one step. Keep the description concrete so agents know when this resource matters."})]}),i.jsxs("div",{className:"grid gap-4 py-1 md:grid-cols-2",children:[i.jsxs("label",{className:"space-y-1.5",children:[i.jsx("span",{className:"text-xs text-muted-foreground",children:"Name"}),i.jsx(An,{value:c.name,onChange:S=>u(A=>({...A,name:S.target.value})),placeholder:"Rudder app repo"})]}),i.jsxs("label",{className:"space-y-1.5",children:[i.jsx("span",{className:"text-xs text-muted-foreground",children:"Kind"}),i.jsxs("select",{value:c.kind,onChange:S=>u(A=>({...A,kind:S.target.value})),className:"h-10 w-full rounded-[calc(var(--radius-sm)-1px)] border border-[color:var(--border-base)] bg-[color:color-mix(in_oklab,var(--surface-elevated)_98%,transparent)] px-3 text-sm outline-none transition-[border-color,box-shadow] focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50",children:[i.jsx("option",{value:"directory",children:"Directory"}),i.jsx("option",{value:"file",children:"File"}),i.jsx("option",{value:"url",children:"URL"}),i.jsx("option",{value:"connector_object",children:"Connector object"})]})]}),i.jsxs("label",{className:"space-y-1.5 md:col-span-2",children:[i.jsx("span",{className:"text-xs text-muted-foreground",children:"Locator"}),i.jsx(AU,{kind:c.kind,value:c.locator,onChange:S=>u(A=>({...A,locator:S})),onPickedPath:S=>u(A=>({...A,locator:S,name:A.name.trim()?A.name:_U(S)})),disabled:N.isPending})]}),i.jsxs("label",{className:"space-y-1.5 md:col-span-2",children:[i.jsx("span",{className:"text-xs text-muted-foreground",children:"Description"}),i.jsx(Sa,{value:c.description,onChange:S=>u(A=>({...A,description:S.target.value})),placeholder:"What this resource contains and when agents should use it."})]}),i.jsxs("label",{className:"space-y-1.5",children:[i.jsx("span",{className:"text-xs text-muted-foreground",children:"Project role"}),i.jsx("select",{value:c.role,onChange:S=>u(A=>({...A,role:S.target.value})),className:"h-10 w-full rounded-[calc(var(--radius-sm)-1px)] border border-[color:var(--border-base)] bg-[color:color-mix(in_oklab,var(--surface-elevated)_98%,transparent)] px-3 text-sm outline-none transition-[border-color,box-shadow] focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50",children:YE.map(S=>i.jsx("option",{value:S.value,children:S.label},S.value))})]}),i.jsxs("label",{className:"space-y-1.5",children:[i.jsx("span",{className:"text-xs text-muted-foreground",children:"Project note"}),i.jsx(An,{value:c.note,onChange:S=>u(A=>({...A,note:S.target.value})),placeholder:"Optional guidance for this project"})]})]}),i.jsxs(Fo,{children:[i.jsx(de,{variant:"outline",onClick:()=>l(!1),children:"Cancel"}),i.jsxs(de,{onClick:()=>N.mutate(),disabled:N.isPending||!c.name.trim()||!c.locator.trim(),children:[N.isPending?i.jsx(or,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}):null,"Create and attach"]})]})]})})]})}function n5(e){return typeof e=="string"&&e.startsWith("plugin:")}function ywt(e,t){const n=e.split("/").filter(Boolean),r=n.indexOf("projects");if(r===-1||n[r+1]!==t)return null;const s=n[r+2];return s==="overview"?"configuration":s==="resources"?"resources":s==="configuration"?"configuration":s==="budget"?"budget":s==="issues"?"issues":null}function vwt({currentColor:e,onSelect:t}){const[n,r]=x.useState(!1),s=x.useRef(null);return x.useEffect(()=>{if(!n)return;function a(o){s.current&&!s.current.contains(o.target)&&r(!1)}return document.addEventListener("mousedown",a),()=>document.removeEventListener("mousedown",a)},[n]),i.jsxs("div",{className:"relative",ref:s,children:[i.jsx("button",{onClick:()=>r(!n),className:"shrink-0 h-5 w-5 rounded-md cursor-pointer shadow-[inset_0_0_0_1px_color-mix(in_oklab,white_24%,transparent),0_0_0_1px_color-mix(in_oklab,var(--border-base)_76%,transparent)] transition-[box-shadow] hover:ring-2 hover:ring-foreground/20",style:Vl(e),"aria-label":"Change project color"}),n&&i.jsx("div",{className:"absolute top-full left-0 mt-2 p-2 bg-popover border border-border rounded-lg shadow-lg z-50 w-max",children:i.jsx("div",{className:"grid grid-cols-5 gap-1.5",children:qj.map(a=>i.jsx("button",{onClick:()=>{t(a),r(!1)},className:`h-6 w-6 rounded-md cursor-pointer transition-[transform,box-shadow] duration-150 hover:scale-110 ${a===e?"ring-2 ring-foreground ring-offset-1 ring-offset-background":"hover:ring-2 hover:ring-foreground/30"}`,style:Vl(a),"aria-label":`Select color ${a}`},a))})})]})}function yx(){const{orgPrefix:e,projectId:t}=ki(),{organizations:n,selectedOrganizationId:r,setSelectedOrganizationId:s}=bn(),{closePanel:a}=VI(),{setBreadcrumbs:o}=Nr(),{pushToast:l}=gr(),c=xn(),u=Dr(),d=Tn(),[h,m]=x.useState({}),g=x.useRef({}),b=x.useRef({}),v=t??"",k=x.useMemo(()=>{var ie;return e?((ie=u1({organizations:n,organizationPrefix:e}))==null?void 0:ie.id)??null:null},[n,e])??r??void 0,w=v.length>0&&(F7(v)||!!k),N=v?ywt(d.pathname,v):null,S=x.useMemo(()=>{const ie=new URLSearchParams(d.search).get("tab");return n5(ie)?ie:null},[d.search]),A=N??S,{data:_,isLoading:E,error:I}=ke({queryKey:[...U.projects.detail(v),k??null],queryFn:()=>gs.get(v,k),enabled:w}),O=_?sg(_):v,M=(_==null?void 0:_.id)??v,D=(_==null?void 0:_.orgId)??r,z=x.useMemo(()=>{var ie;return((ie=n.find(ae=>ae.id===D))==null?void 0:ie.issuePrefix)??e??null},[n,e,D]),F=x.useMemo(()=>_?Jd(`/issues?projectId=${encodeURIComponent(_.id)}`,z):null,[_,z]),{slots:K,isLoading:J}=j1({slotTypes:["detailTab"],entityType:"project",enabled:!!D}),$=x.useMemo(()=>K.map(ie=>({value:`plugin:${ie.pluginKey}:${ie.id}`,label:ie.displayName,slot:ie})),[K]),L=$.find(ie=>ie.value===A)??null;x.useEffect(()=>{!(_!=null&&_.orgId)||_.orgId===r||s(_.orgId,{source:"route_sync"})},[_==null?void 0:_.orgId,r,s]);const H=()=>{c.invalidateQueries({queryKey:U.projects.detail(v)}),c.invalidateQueries({queryKey:U.projects.detail(M)}),D&&c.invalidateQueries({queryKey:U.projects.list(D)})},W=nt({mutationFn:ie=>gs.update(M,ie,D??k),onSuccess:H}),B=nt({mutationFn:ie=>gs.update(M,{archivedAt:ie?new Date().toISOString():null},D??k),onSuccess:(ie,ae)=>{H();const he=(ie==null?void 0:ie.name)??(_==null?void 0:_.name)??"Project";ae?(l({title:`"${he}" has been archived`,tone:"success"}),u("/dashboard")):l({title:`"${he}" has been unarchived`,tone:"success"})},onError:(ie,ae)=>{l({title:ae?"Failed to archive project":"Failed to unarchive project",tone:"error"})}}),Y=nt({mutationFn:async()=>{if(!D||!_)throw new Error("Project is not ready");return Kr.create(D,{title:`Discuss ${_.name}`,contextLinks:[{entityType:"project",entityId:_.id}]})},onSuccess:ie=>{c.invalidateQueries({queryKey:U.chats.list(D??"__none__")}),u(`/chat/${ie.id}`)},onError:ie=>{l({title:ie instanceof Error?ie.message:"Failed to open chat",tone:"error"})}}),{data:P}=ke({queryKey:U.budgets.overview(D??"__none__"),queryFn:()=>db.overview(D),enabled:!!D,refetchInterval:3e4,staleTime:5e3});x.useEffect(()=>{o([{label:"Projects",href:"/projects"},{label:(_==null?void 0:_.name)??v??"Project"}])},[o,_,v]),x.useEffect(()=>{if(_&&v!==O){if(n5(A)){u(`/projects/${O}?tab=${encodeURIComponent(A)}`,{replace:!0});return}if(A==="configuration"){u(`/projects/${O}/configuration`,{replace:!0});return}if(A==="resources"){u(`/projects/${O}/resources`,{replace:!0});return}if(A==="budget"){u(`/projects/${O}/budget`,{replace:!0});return}if(A==="issues"&&F){u(F,{replace:!0});return}u(`/projects/${O}`,{replace:!0})}},[_,v,O,A,u,F]),x.useEffect(()=>(a(),()=>a()),[a]),x.useEffect(()=>()=>{Object.values(b.current).forEach(ie=>{ie&&clearTimeout(ie)})},[]);const V=x.useCallback((ie,ae)=>{m(he=>({...he,[ie]:ae}))},[]),ce=x.useCallback((ie,ae)=>{const he=b.current[ie];he&&clearTimeout(he),b.current[ie]=setTimeout(()=>{m(me=>{const ye={...me};return delete ye[ie],ye}),delete b.current[ie]},ae)},[]),le=x.useCallback(async(ie,ae)=>{const he=(g.current[ie]??0)+1;g.current[ie]=he,V(ie,"saving");try{if(await gs.update(M,ae,D??k),H(),g.current[ie]!==he)return;V(ie,"saved"),ce(ie,1800)}catch(me){if(g.current[ie]!==he)return;throw V(ie,"error"),ce(ie,3e3),me}},[H,k,M,D,ce,V]),G=x.useMemo(()=>{const ie=P==null?void 0:P.policies.find(ae=>ae.scopeType==="project"&&ae.scopeId===((_==null?void 0:_.id)??v));return ie||{policyId:"",orgId:D??"",scopeType:"project",scopeId:(_==null?void 0:_.id)??v,scopeName:(_==null?void 0:_.name)??"Project",metric:"billed_cents",windowKind:"lifetime",amount:0,observedAmount:0,remainingAmount:0,utilizationPercent:0,warnPercent:80,hardStopEnabled:!0,notifyEnabled:!0,isActive:!1,status:"ok",paused:!!(_!=null&&_.pausedAt),pauseReason:(_==null?void 0:_.pauseReason)??null,windowStart:new Date,windowEnd:new Date}},[P==null?void 0:P.policies,_,D,v]),te=nt({mutationFn:ie=>db.upsertPolicy(D,{scopeType:"project",scopeId:(_==null?void 0:_.id)??v,amount:ie,windowKind:"lifetime"}),onSuccess:()=>{D&&(c.invalidateQueries({queryKey:U.budgets.overview(D)}),c.invalidateQueries({queryKey:U.projects.detail(v)}),c.invalidateQueries({queryKey:U.projects.detail(M)}),c.invalidateQueries({queryKey:U.projects.list(D)}),c.invalidateQueries({queryKey:U.dashboard(D)}))}});if(S&&!J&&!L)return i.jsx(ls,{to:`/projects/${O}/configuration`,replace:!0});if(v&&A===null){let ie=null;if(_!=null&&_.id)try{ie=localStorage.getItem(`rudder:project-tab:${_.id}`)}catch{}return ie==="configuration"?i.jsx(ls,{to:`/projects/${O}/configuration`,replace:!0}):ie==="resources"?i.jsx(ls,{to:`/projects/${O}/resources`,replace:!0}):ie==="budget"?i.jsx(ls,{to:`/projects/${O}/budget`,replace:!0}):(ie==="issues"||ie==="list")&&F?i.jsx(ls,{to:F,replace:!0}):n5(ie)?i.jsx(ls,{to:`/projects/${O}?tab=${encodeURIComponent(ie)}`,replace:!0}):i.jsx(ls,{to:`/projects/${O}/configuration`,replace:!0})}if(E)return i.jsx(Is,{variant:"detail"});if(I)return i.jsx("p",{className:"text-sm text-destructive",children:I.message});if(!_)return null;const ge=ie=>{if(ie==="issues"){F&&u(F);return}if(_!=null&&_.id)try{localStorage.setItem(`rudder:project-tab:${_.id}`,ie)}catch{}if(n5(ie)){u(`/projects/${O}?tab=${encodeURIComponent(ie)}`);return}u(ie==="resources"?`/projects/${O}/resources`:ie==="budget"?`/projects/${O}/budget`:ie==="configuration"?`/projects/${O}/configuration`:`/projects/${O}/configuration`)};return i.jsxs("div",{className:"space-y-6",children:[i.jsxs("div",{className:"flex items-start justify-between gap-3",children:[i.jsxs("div",{className:"flex items-start gap-3",children:[i.jsx("div",{className:"h-7 flex items-center",children:i.jsx(vwt,{currentColor:_.color??"#6366f1",onSelect:ie=>W.mutate({color:ie})})}),i.jsxs("div",{className:"min-w-0 space-y-2",children:[i.jsx(zh,{value:_.name,onSave:ie=>W.mutate({name:ie}),as:"h2",className:"text-xl font-bold"}),_.pauseReason==="budget"?i.jsxs("div",{className:Q("inline-flex items-center gap-2 rounded-full border px-3 py-1 text-[11px] font-medium uppercase tracking-[0.18em]",tR.error),children:[i.jsx("span",{className:"h-2 w-2 rounded-full bg-red-400"}),"Paused by budget hard stop"]}):null]})]}),i.jsxs(de,{size:"sm",variant:"outline",className:"shrink-0",onClick:()=>Y.mutate(),disabled:Y.isPending,children:[i.jsx(Ko,{className:"mr-1.5 h-3.5 w-3.5"}),"Chat"]})]}),i.jsx(Gh,{slotTypes:["toolbarButton","contextMenuItem"],entityType:"project",context:{orgId:D??null,orgPrefix:e??null,projectId:_.id,projectRef:O,entityId:_.id,entityType:"project"},className:"flex flex-wrap gap-2",itemClassName:"inline-flex",missingBehavior:"placeholder"}),i.jsx(EF,{placementZones:["toolbarButton"],entityType:"project",context:{orgId:D??null,orgPrefix:e??null,projectId:_.id,projectRef:O,entityId:_.id,entityType:"project"},className:"flex flex-wrap gap-2",itemClassName:"inline-flex"}),i.jsx(Xu,{value:A??"configuration",onValueChange:ie=>ge(ie),children:i.jsx(Jp,{items:[{value:"configuration",label:"Configuration"},{value:"resources",label:"Resources"},{value:"budget",label:"Budget"},{value:"issues",label:"Issues"},...$.map(ie=>({value:ie.value,label:ie.label}))],align:"start",value:A??"configuration",onValueChange:ie=>ge(ie)})}),A==="configuration"&&i.jsx("div",{className:"max-w-4xl",children:i.jsx(xwt,{project:_,onUpdate:ie=>W.mutate(ie),onFieldUpdate:le,getFieldSaveState:ie=>h[ie]??"idle",onArchive:ie=>B.mutate(ie),archivePending:B.isPending})}),A==="resources"&&i.jsx("div",{className:"max-w-5xl",children:i.jsx(bwt,{project:_})}),A==="budget"&&D?i.jsx("div",{className:"max-w-3xl",children:i.jsx(lq,{summary:G,variant:"plain",isSaving:te.isPending,onSave:ie=>te.mutate(ie)})}):null,L&&i.jsx(N1,{slot:L.slot,context:{orgId:D,orgPrefix:e??null,projectId:_.id,projectRef:O,entityId:_.id,entityType:"project"},missingBehavior:"placeholder"})]})}function Ak(e,t){const n={};for(const r of e){const s=t(r);n[s]||(n[s]=[]),n[s].push(r)}return n}function wwt({issue:e,issueLinkState:t,mobileLeading:n,desktopMetaLeading:r,desktopLeadingSpacer:s=!1,mobileMeta:a,desktopTrailing:o,trailingMeta:l,unreadState:c=null,onMarkRead:u,onOpen:d,className:h}){const m=e.identifier??e.id,g=e.identifier??e.id.slice(0,8),b=c!==null,v=c==="visible"||c==="fading";return i.jsxs(Nt,{to:`/issues/${m}`,state:t,onClick:d,className:Q("flex items-start gap-2 border-b panel-divider py-3 pl-3 pr-3 text-sm no-underline text-inherit transition-[background-color,border-color] hover:bg-[color:color-mix(in_oklab,var(--surface-active)_56%,transparent)] last:border-b-0 sm:items-center sm:py-2.5 sm:pl-2",h),children:[i.jsx("span",{className:"shrink-0 pt-px sm:hidden",children:n??i.jsx(Ws,{status:e.status})}),i.jsxs("span",{className:"flex min-w-0 flex-1 flex-col gap-1 sm:contents",children:[i.jsx("span",{className:"line-clamp-2 text-sm font-medium text-foreground sm:order-2 sm:min-w-0 sm:flex-1 sm:truncate sm:line-clamp-none",children:e.title}),i.jsxs("span",{className:"flex items-center gap-2 sm:order-1 sm:shrink-0",children:[s?i.jsx("span",{className:"hidden w-3.5 shrink-0 sm:block"}):null,r??i.jsxs(i.Fragment,{children:[i.jsx("span",{className:"hidden shrink-0 sm:inline-flex",children:i.jsx(Ws,{status:e.status})}),i.jsx("span",{className:"shrink-0 font-mono text-xs text-muted-foreground",children:g})]}),a?i.jsxs(i.Fragment,{children:[i.jsx("span",{className:"text-xs text-muted-foreground sm:hidden","aria-hidden":"true",children:"·"}),i.jsx("span",{className:"text-xs text-muted-foreground sm:hidden",children:a})]}):null]})]}),o||l?i.jsxs("span",{className:"ml-auto hidden shrink-0 items-center gap-2 sm:order-3 sm:flex sm:gap-3",children:[o,l?i.jsx("span",{className:"text-xs text-muted-foreground",children:l}):null]}):null,b?i.jsx("span",{className:"inline-flex h-4 w-4 shrink-0 items-center justify-center self-center",children:v?i.jsx("button",{type:"button",onClick:j=>{j.preventDefault(),j.stopPropagation(),u==null||u()},onKeyDown:j=>{(j.key==="Enter"||j.key===" ")&&(j.preventDefault(),j.stopPropagation(),u==null||u())},className:"inline-flex h-4 w-4 items-center justify-center rounded-full transition-colors hover:bg-blue-500/20","aria-label":"Mark as read",children:i.jsx("span",{className:Q("block h-2 w-2 rounded-full bg-blue-600 transition-opacity duration-300 dark:bg-blue-400",c==="fading"?"opacity-0":"opacity-100")})}):i.jsx("span",{className:"inline-flex h-4 w-4","aria-hidden":"true"})}):null]})}const bT=["in_progress","todo","backlog","in_review","blocked","done","cancelled"],yT=["critical","high","medium","low"],kwt=[{value:"manual",label:"Manual"},{value:"status",label:"Status"},{value:"priority",label:"Priority"},{value:"title",label:"Title"},{value:"created",label:"Created"},{value:"updated",label:"Updated"}];function r5(e,t){const n=e.indexOf(t);return n===-1?e.length:n}function Dp(e){return e?new Date(e).getTime():0}function jwt(e,t,n){switch(n){case"manual":return(e.boardOrder??0)-(t.boardOrder??0);case"status":return r5(bT,e.status)-r5(bT,t.status);case"priority":return r5(yT,e.priority)-r5(yT,t.priority);case"title":return e.title.localeCompare(t.title);case"created":return Dp(e.createdAt)-Dp(t.createdAt);case"updated":return Dp(e.updatedAt)-Dp(t.updatedAt)}}function bje(e,t){const n=t.sortDir==="asc"?1:-1;return[...e].sort((r,s)=>{const a=jwt(r,s,t.sortField);if(a!==0)return n*a;const o=Dp(s.updatedAt)-Dp(r.updatedAt);if(o!==0)return o;const l=Dp(s.createdAt)-Dp(r.createdAt);return l!==0?l:(r.identifier??r.id).localeCompare(s.identifier??s.id)})}const Tx=["backlog","todo","in_progress","in_review","blocked","done","cancelled"],vT={backlog:{base:"border-[color:color-mix(in_oklab,var(--border-soft)_88%,transparent)] bg-[color:color-mix(in_oklab,var(--surface-inset)_88%,transparent)]",over:"border-[color:var(--border-strong)] bg-[color:color-mix(in_oklab,var(--surface-active)_86%,var(--surface-inset))]"},todo:{base:"border-blue-200/75 bg-blue-50/70 dark:border-blue-900/55 dark:bg-blue-950/24",over:"border-blue-300/90 bg-blue-100/82 dark:border-blue-700/70 dark:bg-blue-900/34"},in_progress:{base:"border-amber-200/75 bg-amber-50/70 dark:border-amber-900/55 dark:bg-amber-950/24",over:"border-amber-300/90 bg-amber-100/82 dark:border-amber-700/70 dark:bg-amber-900/34"},in_review:{base:"border-violet-200/75 bg-violet-50/70 dark:border-violet-900/55 dark:bg-violet-950/24",over:"border-violet-300/90 bg-violet-100/82 dark:border-violet-700/70 dark:bg-violet-900/34"},blocked:{base:"border-red-200/75 bg-red-50/70 dark:border-red-900/55 dark:bg-red-950/24",over:"border-red-300/90 bg-red-100/82 dark:border-red-700/70 dark:bg-red-900/34"},done:{base:"border-emerald-200/75 bg-emerald-50/70 dark:border-emerald-900/55 dark:bg-emerald-950/24",over:"border-emerald-300/90 bg-emerald-100/82 dark:border-emerald-700/70 dark:bg-emerald-900/34"},cancelled:{base:"border-neutral-200/75 bg-neutral-50/70 dark:border-neutral-800/60 dark:bg-neutral-900/26",over:"border-neutral-300/85 bg-neutral-100/82 dark:border-neutral-700/75 dark:bg-neutral-800/36"}};function pq(e){return e.replace(/_/g," ").replace(/\b\w/g,t=>t.toUpperCase())}function Nwt(){const e={};for(const t of Tx)e[t]=[];return e}function Cwt(e,t){return e.length!==t.length?!1:e.every((n,r)=>n.id===t[r])}function Swt(e,t,n){if(!n)return e;const r=new Map(t.map(a=>[a.id,a])),s=Object.fromEntries(Tx.map(a=>[a,[...e[a]]]));for(const[a,o]of Object.entries(n.laneIdsByStatus))s[a]=o.map(l=>{const c=r.get(l);return c?c.status===a?c:{...c,status:a}:null}).filter(l=>!!l);return s}function _wt(e,t){return Object.entries(t.laneIdsByStatus).every(([n,r])=>Cwt(e[n]??[],r))}const gq=["identifier","priority","assignee","reviewer","labels","project","created"];function yje({status:e,onCreateIssue:t}){return t?i.jsx(de,{type:"button",variant:"ghost",size:"icon-xs",className:"text-muted-foreground","data-testid":`kanban-column-add-${e}`,"aria-label":`Create ${pq(e)} issue`,onClick:()=>t(e),children:i.jsx(Hn,{className:"h-3 w-3"})}):null}function Pne({relationship:e,agent:t,userId:n,fallbackId:r,currentUserId:s}){const a=e==="assignee"?"Assignee":"Reviewer",o=t?zo(t):n?Ec(n,s)??"User":r?r.slice(0,8):null;if(!o)return null;const l=e==="assignee"?Nf:D$e;return i.jsxs("span",{"data-slot":`kanban-card-${e}`,title:`${a}: ${o}`,className:"inline-flex min-w-0 items-center gap-1.5 rounded-sm bg-muted/35 px-1.5 py-1 text-muted-foreground ring-1 ring-border/35",children:[i.jsx("span",{"data-slot":"kanban-card-person-role",className:"shrink-0 text-[10px] font-medium leading-none text-muted-foreground/75",children:a}),t?i.jsxs("span",{className:"inline-flex min-w-0 flex-1 items-center gap-1 text-xs",children:[i.jsx(c8,{icon:t.icon,role:t.role,className:"h-3 w-3 shrink-0"}),i.jsx("span",{className:"truncate",children:o})]}):i.jsxs("span",{className:"inline-flex min-w-0 flex-1 items-center gap-1 text-xs",children:[i.jsx(l,{className:"h-3 w-3 shrink-0"}),i.jsx("span",{className:Q("truncate",r&&"font-mono"),children:o})]})]})}function Awt({status:e,issues:t,agents:n,currentUserId:r,displayProperties:s=gq,liveIssueIds:a,recentlyDroppedIssueIds:o,projects:l,onCreateIssue:c,onOpenIssue:u}){const{setNodeRef:d,isOver:h}=$U({id:e}),m=di(),g=vT[e]??vT.backlog,b=x.useCallback(v=>{d(v),m(v)},[m,d]);return i.jsxs("div",{className:"flex h-full min-h-0 w-[260px] min-w-[260px] shrink-0 flex-col",children:[i.jsxs("div",{className:"flex items-center gap-2 px-2 py-2 mb-1",children:[i.jsx(Ws,{status:e}),i.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:pq(e)}),i.jsxs("div",{className:"ml-auto flex items-center gap-1",children:[i.jsx("span",{className:"text-xs text-muted-foreground/60 tabular-nums",children:t.length}),i.jsx(yje,{status:e,onCreateIssue:c})]})]}),i.jsx("div",{"data-testid":`kanban-column-${e}`,"data-over":h?"true":"false",ref:b,className:Q("motion-kanban-lane scrollbar-auto-hide flex-1 min-h-[120px] overflow-y-auto rounded-[calc(var(--radius-sm)-1px)] border p-1.5 space-y-1.5",h?g.over:g.base),children:i.jsx(twe,{items:t.map(v=>v.id),strategy:Z1e,children:t.map(v=>i.jsx(vje,{issue:v,agents:n,currentUserId:r,displayProperties:s,isLive:a==null?void 0:a.has(v.id),justDropped:o==null?void 0:o.has(v.id),projects:l,onOpenIssue:u},v.id))})})]})}function Ewt({status:e,issueCount:t,onCreateIssue:n}){const{setNodeRef:r,isOver:s}=$U({id:e}),a=vT[e]??vT.backlog;return i.jsxs("div",{ref:r,"data-testid":`kanban-hidden-column-${e}`,"data-over":s?"true":"false",className:Q("motion-kanban-lane flex items-center gap-2 rounded-[calc(var(--radius-sm)-1px)] border px-2 py-2",s?a.over:a.base),children:[i.jsx(Ws,{status:e}),i.jsx("span",{className:"min-w-0 flex-1 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:pq(e)}),i.jsx("span",{className:"text-xs text-muted-foreground/60 tabular-nums",children:t}),i.jsx(yje,{status:e,onCreateIssue:n})]})}function vje({issue:e,agents:t,currentUserId:n,displayProperties:r=gq,isLive:s,isOverlay:a,justDropped:o,projects:l,onOpenIssue:c}){var J,$;const{attributes:u,listeners:d,setNodeRef:h,transform:m,transition:g,isDragging:b}=rwe({id:e.id,data:{issue:e}}),v={transform:sm.Transform.toString(m),transition:g},j=new Set(r),k=e.assigneeAgentId?(t==null?void 0:t.find(L=>L.id===e.assigneeAgentId))??null:null,w=e.reviewerAgentId?(t==null?void 0:t.find(L=>L.id===e.reviewerAgentId))??null:null,N=e.projectId?((J=l==null?void 0:l.find(L=>L.id===e.projectId))==null?void 0:J.name)??(($=e.project)==null?void 0:$.name)??null:null,S=j.has("identifier"),A=j.has("priority"),_=j.has("assignee"),E=j.has("reviewer")&&!!(e.reviewerAgentId||e.reviewerUserId),I=j.has("labels")&&(e.labels??[]).length>0,O=j.has("project")&&!!N,M=j.has("updated"),D=j.has("created"),z=_?i.jsx(Pne,{relationship:"assignee",agent:k,userId:e.assigneeUserId,fallbackId:!k&&e.assigneeAgentId?e.assigneeAgentId:null,currentUserId:n}):null,F=E?i.jsx(Pne,{relationship:"reviewer",agent:w,userId:e.reviewerUserId,fallbackId:!w&&e.reviewerAgentId?e.reviewerAgentId:null,currentUserId:n}):null,K=!!(z||F);return i.jsx("div",{ref:h,style:v,...u,...d,"data-testid":`kanban-card-${e.identifier??e.id}`,"data-dragging":b&&!a?"true":"false","data-overlay":a?"true":"false","data-live":s?"true":"false","data-just-dropped":o?"true":"false",className:Q("motion-kanban-card overflow-hidden rounded-[calc(var(--radius-sm)-1px)] border bg-card p-2.5 cursor-grab active:cursor-grabbing",b&&!a?"opacity-30":"",a?"shadow-lg ring-1 ring-primary/20":"hover:shadow-sm"),children:i.jsxs(Nt,{to:`/issues/${e.identifier??e.id}`,className:"block min-w-0 no-underline text-inherit",onClick:L=>{if(b){L.preventDefault();return}c==null||c(e)},children:[S||s?i.jsxs("div",{className:"flex items-start gap-1.5 mb-1.5",children:[S?i.jsx("span",{className:"text-xs text-muted-foreground font-mono shrink-0",children:e.identifier??e.id.slice(0,8)}):null,s&&i.jsx("span",{className:"motion-live-dot relative flex h-2 w-2 shrink-0 mt-0.5 text-blue-500",children:i.jsx("span",{className:"relative inline-flex rounded-full h-2 w-2 bg-blue-500"})})]}):null,i.jsx("p",{className:"text-sm leading-snug line-clamp-2 mb-2",children:e.title}),(A||K)&&i.jsxs("div",{"data-slot":"kanban-card-metadata",className:"flex min-w-0 items-start gap-1.5 overflow-hidden",children:[A?i.jsx("span",{className:"shrink-0 pt-1",children:i.jsx(gc,{priority:e.priority})}):null,K?i.jsxs("span",{"data-slot":"kanban-card-people",className:"grid min-w-0 flex-1 gap-1.5 [grid-template-columns:repeat(auto-fit,minmax(6rem,1fr))]",children:[z,F]}):null]}),I?i.jsxs("div",{className:"mt-2 flex flex-wrap gap-1",children:[(e.labels??[]).slice(0,3).map(L=>i.jsx(UI,{label:L},L.id)),(e.labels??[]).length>3?i.jsxs("span",{className:"text-[10px] text-muted-foreground",children:["+",(e.labels??[]).length-3]}):null]}):null,O||M||D?i.jsxs("div",{className:"mt-2 space-y-1 text-xs text-muted-foreground",children:[O?i.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[i.jsx(v1,{className:"h-3 w-3 shrink-0"}),i.jsx("span",{className:"truncate",children:N})]}):null,M?i.jsxs("span",{className:"flex items-center gap-1.5",children:[i.jsx(BL,{className:"h-3 w-3 shrink-0"}),i.jsxs("span",{children:["Updated ",du(e.updatedAt)]})]}):null,D?i.jsxs("span",{className:"flex items-center gap-1.5",children:[i.jsx(BL,{className:"h-3 w-3 shrink-0"}),i.jsxs("span",{children:["Created ",du(e.createdAt)]})]}):null]}):null]})})}function Twt({issues:e,agents:t,currentUserId:n,displayProperties:r,sortState:s,liveIssueIds:a,projects:o,onCreateIssue:l,onOpenIssue:c,onUpdateIssue:u,onReorderIssue:d}){const[h,m]=x.useState(null),[g,b]=x.useState(new Set),[v,j]=x.useState(null),k=di(),w=x.useRef([]),N=R1e(I1e(QI,{activationConstraint:{distance:5}})),S=x.useMemo(()=>{const z=Nwt();for(const F of e)z[F.status]&&z[F.status].push(F);if(s)for(const F of Tx)z[F]=bje(z[F]??[],s);return z},[e,s]),A=x.useMemo(()=>Swt(S,e,v),[S,e,v]),_=x.useMemo(()=>Tx.filter(z=>{var F;return(((F=A[z])==null?void 0:F.length)??0)>0}),[A]),E=x.useMemo(()=>Tx.filter(z=>{var F;return(((F=A[z])==null?void 0:F.length)??0)===0}),[A]),I=x.useMemo(()=>h?e.find(z=>z.id===h):null,[h,e]);x.useEffect(()=>()=>{for(const z of w.current)window.clearTimeout(z);w.current=[]},[]),x.useEffect(()=>{if(!v)return;if(_wt(S,v)){j(null);return}const z=window.setTimeout(()=>{j(null)},3e3);return()=>window.clearTimeout(z)},[S,v]);function O(z){m(z.active.id)}function M(z){var ge,ie;m(null);const{active:F,over:K}=z;if(!K)return;const J=F.id,$=e.find(ae=>ae.id===J);if(!$)return;let L=null;if(Tx.includes(K.id))L=K.id;else{const ae=e.find(he=>he.id===K.id);ae&&(L=ae.status)}if(!L)return;const H=A[L]??[],W=H.filter(ae=>ae.id!==J);let B=W.length;if(!Tx.includes(K.id)){const ae=H.findIndex(he=>he.id===K.id);ae>=0&&(B=ae)}const Y=[...W];Y.splice(B,0,{...$,status:L});const P=Y.findIndex(ae=>ae.id===J),V=P>0?(ge=Y[P-1])==null?void 0:ge.id:null,ce=P>=0&&P<Y.length-1?(ie=Y[P+1])==null?void 0:ie.id:null,le=V?ce?void 0:"end":"start",G=H.map(ae=>ae.id).join(`
1374
1374
  `),te=Y.map(ae=>ae.id).join(`
1375
- `);if(L!==$.status||G!==te){const ae={[L]:Y.map(me=>me.id)};L!==$.status&&(ae[$.status]=(A[$.status]??[]).filter(me=>me.id!==J).map(me=>me.id)),j({laneIdsByStatus:ae}),b(me=>{const ye=new Set(me);return ye.add(J),ye});const he=window.setTimeout(()=>{b(me=>{const ye=new Set(me);return ye.delete(J),ye}),w.current=w.current.filter(me=>me!==he)},520);w.current.push(he),d?d({issueId:J,targetStatus:L,previousIssueId:V,nextIssueId:ce,...le?{position:le}:{}}):L!==$.status&&u(J,{status:L})}}function D(z){}return i.jsxs(Q1e,{sensors:N,onDragStart:O,onDragOver:D,onDragEnd:M,children:[i.jsx("div",{className:"flex h-full min-h-0 flex-col",children:i.jsx("div",{ref:k,className:"scrollbar-auto-hide min-h-0 flex-1 overflow-x-auto overflow-y-hidden pb-3",children:i.jsxs("div",{className:"flex h-full min-h-full min-w-max items-stretch gap-3 pr-2",children:[_.map(z=>i.jsx(Awt,{status:z,issues:A[z]??[],agents:t,currentUserId:n,displayProperties:r,liveIssueIds:a,recentlyDroppedIssueIds:g,projects:o,onCreateIssue:l,onOpenIssue:c},z)),E.length>0?i.jsxs("div",{"data-testid":"kanban-hidden-columns",className:"flex h-full min-h-0 w-[228px] min-w-[228px] shrink-0 flex-col rounded-[calc(var(--radius-sm)+1px)] border border-[color:var(--border-base)] bg-[color:color-mix(in_oklab,var(--surface-inset)_78%,transparent)] p-2",children:[i.jsxs("div",{className:"mb-2 flex items-center gap-2 px-1",children:[i.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:"Hidden columns"}),i.jsx("span",{className:"ml-auto text-xs text-muted-foreground/60 tabular-nums",children:E.length})]}),i.jsx("div",{className:"space-y-2",children:E.map(z=>{var F;return i.jsx(Ewt,{status:z,issueCount:((F=A[z])==null?void 0:F.length)??0,onCreateIssue:l},z)})})]}):null]})})}),i.jsx(tht,{children:I?i.jsx(vje,{issue:I,agents:t,currentUserId:n,displayProperties:r,isOverlay:!0,projects:o}):null})]})}function Lne(e){return e.replace(/_/g," ").replace(/\b\w/g,t=>t.toUpperCase())}const wje=[{value:"identifier",label:"Identifier"},{value:"priority",label:"Priority"},{value:"assignee",label:"Assignee"},{value:"reviewer",label:"Reviewer"},{value:"labels",label:"Labels"},{value:"project",label:"Project"},{value:"updated",label:"Updated"},{value:"created",label:"Created"}],Iwt=new Set(wje.map(e=>e.value)),kje=[...gq],xq={statuses:[],priorities:[],assignees:[],labels:[],projects:[],displayProperties:kje,sortField:"updated",sortDir:"desc",groupBy:"none",viewMode:"list",collapsedGroups:[]},Rwt=[{label:"All",statuses:[]},{label:"Active",statuses:["todo","in_progress","in_review","blocked"]},{label:"Backlog",statuses:["backlog"]},{label:"Done",statuses:["done","cancelled"]}],Mwt="Getting Started",Owt=["welcome","core","recommended","advanced","other"],$ne={welcome:{label:"Welcome",description:"Reference issue for Rudder’s collaboration model."},core:{label:"Core loop",description:"Complete these issues to experience chat → issue → execution → review → project context."},recommended:{label:"Recommended next",description:"Bring real context and one real task into Rudder."},advanced:{label:"Advanced",description:"Optional next steps for goals, reusable workflows, agent roles, and recurring loops."},other:{label:"Other",description:"Additional issues in this project."}};function Dwt(e){return e.title.startsWith("👋 Welcome to Rudder")?"welcome":/^[1-5]\./.test(e.title)?"core":/^[6-7]\./.test(e.title)?"recommended":/^(?:[8-9]|10|11)\./.test(e.title)?"advanced":"other"}function Fne(e){if(e.title.startsWith("👋 Welcome to Rudder"))return 0;const t=/^(\d+)\./.exec(e.title);return t?Number(t[1]):99}function Pwt(e){return[...e].sort((t,n)=>{const r=Fne(t)-Fne(n);return r!==0?r:t.title.localeCompare(n.title)})}function Lwt(e){try{const t=localStorage.getItem(e);if(t){const n=JSON.parse(t);return zwt(n)}}catch{}return{...xq}}function $wt(e,t){localStorage.setItem(e,JSON.stringify(t))}function Fwt(e){if(!Array.isArray(e))return[...kje];const t=new Set,n=[];for(const r of e){if(!Iwt.has(r))continue;const s=r;t.has(s)||(t.add(s),n.push(s))}return n}function zwt(e){return{...xq,...e,statuses:Array.isArray(e.statuses)?[...e.statuses]:[],priorities:Array.isArray(e.priorities)?[...e.priorities]:[],assignees:Array.isArray(e.assignees)?[...e.assignees]:[],labels:Array.isArray(e.labels)?[...e.labels]:[],projects:Array.isArray(e.projects)?[...e.projects]:[],collapsedGroups:Array.isArray(e.collapsedGroups)?[...e.collapsedGroups]:[],displayProperties:Fwt(e.displayProperties)}}function Bwt(e,t){if(e.length!==t.length)return!1;const n=[...e].sort(),r=[...t].sort();return n.every((s,a)=>s===r[a])}function Xm(e,t){return e.includes(t)?e.filter(n=>n!==t):[...e,t]}function Uwt(e,t,n){let r=e;return t.statuses.length>0&&(r=r.filter(s=>t.statuses.includes(s.status))),t.priorities.length>0&&(r=r.filter(s=>t.priorities.includes(s.priority))),t.assignees.length>0&&(r=r.filter(s=>{for(const a of t.assignees)if(a==="__unassigned"&&!s.assigneeAgentId&&!s.assigneeUserId||a==="__me"&&n&&s.assigneeUserId===n||s.assigneeAgentId===a)return!0;return!1})),t.labels.length>0&&(r=r.filter(s=>(s.labelIds??[]).some(a=>t.labels.includes(a)))),t.projects.length>0&&(r=r.filter(s=>s.projectId!=null&&t.projects.includes(s.projectId))),r}function qwt(e){let t=0;return e.statuses.length>0&&t++,e.priorities.length>0&&t++,e.assignees.length>0&&t++,e.labels.length>0&&t++,e.projects.length>0&&t++,t}function Vwt({issues:e,isLoading:t,error:n,agents:r,projects:s,liveIssueIds:a,projectId:o,viewStateKey:l,issueLinkState:c,initialAssignees:u,initialSearch:d,initialGroupBy:h,toolbarMode:m="full",starredIssueIds:g=[],onToggleStarredIssue:b,onOpenIssue:v,searchFilters:j,onSearchChange:k,onUpdateIssue:w,onReorderIssue:N}){var ue,je;const{selectedOrganizationId:S}=bn(),{openNewIssue:A}=Gr(),{data:_}=ke({queryKey:U.auth.session,queryFn:()=>Ri.getSession()}),E=((ue=_==null?void 0:_.user)==null?void 0:ue.id)??((je=_==null?void 0:_.session)==null?void 0:je.userId)??null,I=S?`${l}:${S}`:l,O=x.useCallback(()=>{const re=u?{...xq,assignees:u,statuses:[]}:Lwt(I);return h?{...re,groupBy:h}:re},[u,h,I]),[M,D]=x.useState(()=>O()),[z,F]=x.useState(null),[K,J]=x.useState(""),[$,L]=x.useState(d??""),[H,W]=x.useState($),B=di(),Y=di(),P=di(),V=di(),ce=H.trim();x.useEffect(()=>{L(d??"")},[d]),x.useEffect(()=>{const re=window.setTimeout(()=>{W($)},300);return()=>window.clearTimeout(re)},[$]);const le=x.useRef(I);x.useEffect(()=>{le.current!==I&&(le.current=I,D(O()))},[O,I]);const G=x.useCallback(re=>{D(fe=>{const ne={...fe,...re};return $wt(I,ne),ne})},[I]),{data:te=[]}=ke({queryKey:[...U.issues.search(S,ce,o),j??{}],queryFn:()=>fn.list(S,{q:ce,projectId:o,...j}),enabled:!!S&&ce.length>0}),ge=x.useMemo(()=>new Map((r??[]).map(re=>[re.id,re])),[r]),ie=x.useCallback(re=>{if(!re)return null;const fe=ge.get(re);return fe?zo(fe):null},[ge]),ae=x.useMemo(()=>{const re=ce.length>0?te:e,fe=Uwt(re,M,E);return bje(fe,M)},[e,te,M,ce,E]),{data:he}=ke({queryKey:U.issues.labels(S),queryFn:()=>fn.listLabels(S),enabled:!!S}),me=qwt(M),ye=x.useMemo(()=>{var re;return((re=s==null?void 0:s.find(fe=>fe.id===o))==null?void 0:re.name)??null},[o,s]),Me=ye===Mwt,$e=x.useMemo(()=>ce.length>0?`No issues match “${ce}”. Try a different search or clear some filters.`:me>0?"No issues match the current filters. Adjust the filters or clear them to see more work.":ye?`${ye} does not have any issues yet. Create the first issue for this project.`:"There are no issues yet. Create one to start tracking work here.",[me,ce,ye]),Re=ce.length===0&&me===0?"New Issue":void 0,Ue=x.useMemo(()=>ye&&ce.length===0&&me===0?`${ye} does not have any issues yet. Use a lane + button to create the first one in the right status.`:ce.length>0||me>0?"No issues match the current board. Use a lane + button to create a new issue in the right status. Clear search or filters if it does not appear.":"No issues match the current board. Use a lane + button to create a new issue in the right status.",[me,ce,ye]),we=x.useMemo(()=>{var fe;if(Me&&M.groupBy==="none"){const ne=Ak(ae,Dwt);return Owt.filter(Fe=>{var Ce;return(Ce=ne[Fe])==null?void 0:Ce.length}).map(Fe=>({key:`onboarding:${Fe}`,label:$ne[Fe].label,description:$ne[Fe].description,items:Pwt(ne[Fe])}))}if(M.groupBy==="none")return[{key:"__all",label:null,items:ae}];if(M.groupBy==="status"){const ne=Ak(ae,Fe=>Fe.status);return bT.filter(Fe=>{var Ce;return(Ce=ne[Fe])==null?void 0:Ce.length}).map(Fe=>({key:Fe,label:Lne(Fe),items:ne[Fe]}))}if(M.groupBy==="priority"){const ne=Ak(ae,Fe=>Fe.priority);return yT.filter(Fe=>{var Ce;return(Ce=ne[Fe])==null?void 0:Ce.length}).map(Fe=>({key:Fe,label:Ho(Fe),items:ne[Fe]}))}if(M.groupBy==="project"){const ne=Ak(ae,Ce=>Ce.projectId??"__no_project"),Fe=(s??[]).filter(Ce=>{var tt;return(tt=ne[Ce.id])==null?void 0:tt.length}).map(Ce=>({key:Ce.id,label:Ce.name,items:ne[Ce.id]}));return(fe=ne.__no_project)!=null&&fe.length&&Fe.push({key:"__no_project",label:"Unscoped",items:ne.__no_project}),Fe}const re=Ak(ae,ne=>ne.assigneeAgentId??(ne.assigneeUserId?`__user:${ne.assigneeUserId}`:"__unassigned"));return Object.keys(re).map(ne=>({key:ne,label:ne==="__unassigned"?"Unassigned":ne.startsWith("__user:")?Ec(ne.slice(7),E)??"User":ie(ne)??ne.slice(0,8),items:re[ne]}))},[ie,E,ae,Me,s,M.groupBy]),ze=x.useMemo(()=>{const re={};if(o?re.projectId=o:M.projects.length===1&&(re.projectId=M.projects[0]),M.priorities.length===1&&(re.priority=M.priorities[0]),M.labels.length>0&&(re.labelIds=[...M.labels]),M.assignees.length===1){const fe=M.assignees[0];fe==="__me"&&E?re.assigneeUserId=E:fe!=="__unassigned"&&(re.assigneeAgentId=fe)}return re},[E,o,M.assignees,M.labels,M.priorities,M.projects]),oe=re=>{const fe={...ze};return re&&(M.groupBy==="status"?fe.status=re:M.groupBy==="priority"?fe.priority=re:M.groupBy==="project"&&re!=="__no_project"?fe.projectId=re:M.groupBy==="assignee"&&re!=="__unassigned"&&(re.startsWith("__user:")?fe.assigneeUserId=re.slice(7):fe.assigneeAgentId=re)),fe},xe=(re,fe,ne=null)=>{w(re,{assigneeAgentId:fe,assigneeUserId:ne}),F(null),J("")},X=re=>{if(!N){w(re.issueId,{status:re.targetStatus});return}(M.sortField!=="manual"||M.sortDir!=="asc")&&G({sortField:"manual",sortDir:"asc"}),N(re)},q=re=>{F(fe=>fe===re?null:re),J("")};return i.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-4",children:[m!=="hidden"&&i.jsxs("div",{"data-testid":"issues-view-toolbar",className:"surface-panel flex items-center justify-between gap-2 rounded-[calc(var(--radius-sm)+1px)] px-3 py-3 sm:gap-3",children:[i.jsx("div",{className:"flex min-w-0 items-center gap-2 sm:gap-3",children:m==="full"?i.jsxs(i.Fragment,{children:[i.jsxs(de,{size:"sm",variant:"outline",onClick:()=>A(oe()),children:[i.jsx(Hn,{className:"h-4 w-4 sm:mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:"New Issue"})]}),i.jsxs("div",{className:"relative w-48 sm:w-64 md:w-80",children:[i.jsx(Ro,{className:"pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),i.jsx(An,{value:$,onChange:re=>{L(re.target.value),k==null||k(re.target.value)},placeholder:"Search issues...",className:"pl-7 text-xs sm:text-sm","aria-label":"Search issues"})]})]}):i.jsx("div",{className:"flex min-w-0 items-center gap-2",children:i.jsx("div",{className:"truncate text-xs font-medium uppercase tracking-[0.18em] text-muted-foreground",children:"Issues"})})}),i.jsxs("div",{className:"flex items-center gap-0.5 sm:gap-1 shrink-0",children:[i.jsxs("div",{className:"mr-1 flex items-center overflow-hidden rounded-[var(--radius-sm)] border border-[color:var(--border-base)] bg-[color:color-mix(in_oklab,var(--surface-inset)_82%,transparent)]",children:[i.jsx("button",{className:`p-1.5 transition-colors ${M.viewMode==="list"?"bg-[color:var(--surface-active)] text-foreground":"text-muted-foreground hover:text-foreground"}`,onClick:()=>G({viewMode:"list"}),title:"List view",children:i.jsx(J7,{className:"h-3.5 w-3.5"})}),i.jsx("button",{className:`p-1.5 transition-colors ${M.viewMode==="board"?"bg-[color:var(--surface-active)] text-foreground":"text-muted-foreground hover:text-foreground"}`,onClick:()=>G({viewMode:"board"}),title:"Board view",children:i.jsx(Gue,{className:"h-3.5 w-3.5"})})]}),i.jsxs(cr,{children:[i.jsx(mr,{asChild:!0,children:i.jsxs(de,{variant:"ghost",size:"sm",className:`text-xs ${me>0?"text-[color:var(--accent-strong)]":""}`,children:[i.jsx(VL,{className:"h-3.5 w-3.5 sm:h-3 sm:w-3 sm:mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:me>0?`Filters: ${me}`:"Filter"}),me>0&&i.jsx("span",{className:"sm:hidden text-[10px] font-medium ml-0.5",children:me}),me>0&&i.jsx(ti,{className:"h-3 w-3 ml-1 hidden sm:block",onClick:re=>{re.stopPropagation(),G({statuses:[],priorities:[],assignees:[],labels:[],projects:[]})}})]})}),i.jsx(ur,{align:"end",className:"w-[min(480px,calc(100vw-2rem))] p-0",children:i.jsxs("div",{className:"p-3 space-y-3",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("span",{className:"text-sm font-medium",children:"Filters"}),me>0&&i.jsx("button",{className:"text-xs text-muted-foreground hover:text-foreground",onClick:()=>G({statuses:[],priorities:[],assignees:[],labels:[],projects:[]}),children:"Clear"})]}),i.jsxs("div",{className:"space-y-1.5",children:[i.jsx("span",{className:"text-xs text-muted-foreground",children:"Quick filters"}),i.jsx("div",{className:"flex flex-wrap gap-1.5",children:Rwt.map(re=>{const fe=Bwt(M.statuses,re.statuses);return i.jsx("button",{className:`px-2.5 py-1 text-xs rounded-[calc(var(--radius-sm)-1px)] border transition-colors ${fe?"bg-primary text-primary-foreground border-primary":"border-[color:var(--border-base)] text-muted-foreground hover:text-foreground hover:border-[color:var(--border-strong)]"}`,onClick:()=>G({statuses:fe?[]:[...re.statuses]}),children:re.label},re.label)})})]}),i.jsx("div",{className:"border-t panel-divider"}),i.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-x-4 gap-y-3",children:[i.jsxs("div",{className:"space-y-1",children:[i.jsx("span",{className:"text-xs text-muted-foreground",children:"Status"}),i.jsx("div",{className:"space-y-0.5",children:bT.map(re=>i.jsxs("label",{className:"flex items-center gap-2 px-2 py-1 rounded-sm hover:bg-accent/50 cursor-pointer",children:[i.jsx(To,{checked:M.statuses.includes(re),onCheckedChange:()=>G({statuses:Xm(M.statuses,re)})}),i.jsx(Ws,{status:re}),i.jsx("span",{className:"text-sm",children:Lne(re)})]},re))})]}),i.jsxs("div",{className:"space-y-3",children:[i.jsxs("div",{className:"space-y-1",children:[i.jsx("span",{className:"text-xs text-muted-foreground",children:"Priority"}),i.jsx("div",{className:"space-y-0.5",children:yT.map(re=>i.jsxs("label",{className:"flex items-center gap-2 px-2 py-1 rounded-sm hover:bg-accent/50 cursor-pointer",children:[i.jsx(To,{checked:M.priorities.includes(re),onCheckedChange:()=>G({priorities:Xm(M.priorities,re)})}),i.jsx(gc,{priority:re}),i.jsx("span",{className:"text-sm",children:Ho(re)})]},re))})]}),i.jsxs("div",{className:"space-y-1",children:[i.jsx("span",{className:"text-xs text-muted-foreground",children:"Assignee"}),i.jsxs("div",{ref:B,"data-testid":"issues-filter-assignee-scroll",className:"scrollbar-auto-hide space-y-0.5 max-h-32 overflow-y-auto",children:[i.jsxs("label",{className:"flex items-center gap-2 px-2 py-1 rounded-sm hover:bg-accent/50 cursor-pointer",children:[i.jsx(To,{checked:M.assignees.includes("__unassigned"),onCheckedChange:()=>G({assignees:Xm(M.assignees,"__unassigned")})}),i.jsx("span",{className:"text-sm",children:"No assignee"})]}),E&&i.jsxs("label",{className:"flex items-center gap-2 px-2 py-1 rounded-sm hover:bg-accent/50 cursor-pointer",children:[i.jsx(To,{checked:M.assignees.includes("__me"),onCheckedChange:()=>G({assignees:Xm(M.assignees,"__me")})}),i.jsx(Nf,{className:"h-3.5 w-3.5 text-muted-foreground"}),i.jsx("span",{className:"text-sm",children:"Me"})]}),(r??[]).map(re=>i.jsxs("label",{className:"flex items-center gap-2 px-2 py-1 rounded-sm hover:bg-accent/50 cursor-pointer",children:[i.jsx(To,{checked:M.assignees.includes(re.id),onCheckedChange:()=>G({assignees:Xm(M.assignees,re.id)})}),i.jsx(ks,{icon:re.icon,role:re.role,className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),i.jsx("span",{className:"text-sm",children:zo(re)})]},re.id))]})]}),he&&he.length>0&&i.jsxs("div",{className:"space-y-1",children:[i.jsx("span",{className:"text-xs text-muted-foreground",children:"Labels"}),i.jsx("div",{ref:Y,"data-testid":"issues-filter-labels-scroll",className:"scrollbar-auto-hide space-y-0.5 max-h-32 overflow-y-auto",children:he.map(re=>i.jsxs("label",{className:"flex items-center gap-2 px-2 py-1 rounded-sm hover:bg-accent/50 cursor-pointer",children:[i.jsx(To,{checked:M.labels.includes(re.id),onCheckedChange:()=>G({labels:Xm(M.labels,re.id)})}),i.jsx("span",{className:"h-2.5 w-2.5 rounded-full",style:{backgroundColor:re.color}}),i.jsx("span",{className:"text-sm",children:re.name})]},re.id))})]}),s&&s.length>0&&i.jsxs("div",{className:"space-y-1",children:[i.jsx("span",{className:"text-xs text-muted-foreground",children:"Project"}),i.jsx("div",{ref:P,"data-testid":"issues-filter-projects-scroll",className:"scrollbar-auto-hide space-y-0.5 max-h-32 overflow-y-auto",children:s.map(re=>i.jsxs("label",{className:"flex items-center gap-2 px-2 py-1 rounded-sm hover:bg-accent/50 cursor-pointer",children:[i.jsx(To,{checked:M.projects.includes(re.id),onCheckedChange:()=>G({projects:Xm(M.projects,re.id)})}),i.jsx("span",{className:"text-sm",children:re.name})]},re.id))})]})]})]})]})})]}),i.jsxs(cr,{children:[i.jsx(mr,{asChild:!0,children:i.jsxs(de,{variant:"ghost",size:"sm",className:"text-xs",children:[i.jsx(zL,{className:"h-3.5 w-3.5 sm:h-3 sm:w-3 sm:mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:"Sort"})]})}),i.jsx(ur,{align:"end",className:"w-48 p-0",children:i.jsx("div",{className:"p-2 space-y-0.5",children:kwt.map(re=>i.jsxs("button",{className:`flex items-center justify-between w-full px-2 py-1.5 text-sm rounded-sm ${M.sortField===re.value?"bg-accent/50 text-foreground":"hover:bg-accent/50 text-muted-foreground"}`,onClick:()=>{M.sortField===re.value?G({sortDir:M.sortDir==="asc"?"desc":"asc"}):G({sortField:re.value,sortDir:"asc"})},children:[i.jsx("span",{children:re.label}),M.sortField===re.value&&i.jsx("span",{className:"text-xs text-muted-foreground",children:M.sortDir==="asc"?"↑":"↓"})]},re.value))})})]}),M.viewMode==="board"&&i.jsxs(cr,{children:[i.jsx(mr,{asChild:!0,children:i.jsxs(de,{variant:"ghost",size:"sm",className:"text-xs",children:[i.jsx(yC,{className:"h-3.5 w-3.5 sm:h-3 sm:w-3 sm:mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:"Display"})]})}),i.jsx(ur,{align:"end",className:"w-52 p-0",children:i.jsx("div",{className:"p-2 space-y-0.5",children:wje.map(re=>i.jsxs("label",{className:"flex cursor-pointer items-center gap-2 rounded-sm px-2 py-1.5 text-sm hover:bg-accent/50",children:[i.jsx(To,{checked:M.displayProperties.includes(re.value),onCheckedChange:()=>G({displayProperties:Xm(M.displayProperties,re.value)})}),i.jsx("span",{children:re.label})]},re.value))})})]}),M.viewMode==="list"&&i.jsxs(cr,{children:[i.jsx(mr,{asChild:!0,children:i.jsxs(de,{variant:"ghost",size:"sm",className:"text-xs",children:[i.jsx(Q7,{className:"h-3.5 w-3.5 sm:h-3 sm:w-3 sm:mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:"Group"})]})}),i.jsx(ur,{align:"end",className:"w-44 p-0",children:i.jsx("div",{className:"p-2 space-y-0.5",children:[["status","Status"],["priority","Priority"],["assignee","Assignee"],["project","Project"],["none","None"]].map(([re,fe])=>i.jsxs("button",{className:`flex items-center justify-between w-full px-2 py-1.5 text-sm rounded-sm ${M.groupBy===re?"bg-accent/50 text-foreground":"hover:bg-accent/50 text-muted-foreground"}`,onClick:()=>G({groupBy:re}),children:[i.jsx("span",{children:fe}),M.groupBy===re&&i.jsx(ws,{className:"h-3.5 w-3.5"})]},re))})})]})]})]}),t&&i.jsx(Is,{variant:"issues-list"}),n&&i.jsx("p",{className:"text-sm text-destructive",children:n.message}),!t&&ae.length===0&&M.viewMode!=="board"&&i.jsx("div",{className:"flex min-h-[58vh] items-center justify-center",children:i.jsx(Er,{icon:pl,message:$e,action:Re,onAction:Re?()=>A(oe()):void 0})}),!t&&M.viewMode==="board"&&i.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[ae.length===0?i.jsx("div",{className:"mb-3 rounded-[calc(var(--radius-sm)+1px)] border border-dashed border-[color:var(--border-base)] bg-[color:color-mix(in_oklab,var(--surface-inset)_82%,transparent)] px-4 py-3 text-sm text-muted-foreground",children:Ue}):null,i.jsx(Twt,{issues:ae,agents:r,currentUserId:E,displayProperties:M.displayProperties,sortState:{sortField:M.sortField,sortDir:M.sortDir},liveIssueIds:a,projects:s,onCreateIssue:re=>A({...ze,status:re}),onOpenIssue:v,onUpdateIssue:w,onReorderIssue:X})]}),!t&&ae.length>0&&M.viewMode!=="board"&&we.map(re=>i.jsxs(fy,{open:!M.collapsedGroups.includes(re.key),onOpenChange:fe=>{G({collapsedGroups:fe?M.collapsedGroups.filter(ne=>ne!==re.key):[...M.collapsedGroups,re.key]})},children:[re.label&&i.jsxs("div",{className:"flex items-center py-1.5 pl-1 pr-3",children:[i.jsxs(ZI,{className:"flex items-center gap-1.5",children:[i.jsx(Us,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground transition-transform [[data-state=open]>&]:rotate-90"}),i.jsxs("span",{className:"flex flex-col items-start gap-0.5 text-left",children:[i.jsx("span",{className:"text-sm font-semibold uppercase tracking-[0.18em] text-muted-foreground",children:re.label}),re.description?i.jsx("span",{className:"max-w-[68ch] text-xs font-normal normal-case tracking-normal text-muted-foreground/80",children:re.description}):null]})]}),i.jsx(de,{variant:"ghost",size:"icon-xs",className:"ml-auto text-muted-foreground",onClick:()=>A(oe(re.key)),children:i.jsx(Hn,{className:"h-3 w-3"})})]}),i.jsx(hy,{children:re.items.map(fe=>{var ne,Fe;return i.jsx(wwt,{issue:fe,issueLinkState:c,desktopLeadingSpacer:!0,mobileLeading:i.jsx("span",{onClick:Ce=>{Ce.preventDefault(),Ce.stopPropagation()},children:i.jsx(Ws,{status:fe.status,onChange:Ce=>w(fe.id,{status:Ce})})}),desktopMetaLeading:i.jsxs(i.Fragment,{children:[i.jsx("span",{className:"hidden shrink-0 sm:inline-flex",onClick:Ce=>{Ce.preventDefault(),Ce.stopPropagation()},children:i.jsx(Ws,{status:fe.status,onChange:Ce=>w(fe.id,{status:Ce})})}),i.jsx("span",{className:"shrink-0 font-mono text-xs text-muted-foreground",children:fe.identifier??fe.id.slice(0,8)}),(a==null?void 0:a.has(fe.id))&&i.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full border border-[color:var(--border-soft)] bg-[color:color-mix(in_oklab,var(--surface-proposal)_80%,transparent)] px-1.5 py-0.5 sm:gap-1.5 sm:px-2",children:[i.jsxs("span",{className:"relative flex h-2 w-2",children:[i.jsx("span",{className:"absolute inline-flex h-full w-full animate-pulse rounded-full bg-[color:var(--accent-base)] opacity-75"}),i.jsx("span",{className:"relative inline-flex h-2 w-2 rounded-full bg-[color:var(--accent-strong)]"})]}),i.jsx("span",{className:"hidden text-[11px] font-medium text-[color:var(--accent-strong)] sm:inline",children:"Live"})]})]}),mobileMeta:du(fe.updatedAt),desktopTrailing:i.jsxs(i.Fragment,{children:[b?i.jsx("button",{type:"button",className:"rounded p-1 text-muted-foreground transition-colors hover:bg-accent/50 hover:text-foreground",onClick:Ce=>{Ce.preventDefault(),Ce.stopPropagation(),b(fe.id)},title:g.includes(fe.id)?"Unstar issue":"Star issue",children:i.jsx(fde,{className:Q("h-3.5 w-3.5",g.includes(fe.id)&&"fill-current text-amber-500")})}):null,(fe.labels??[]).length>0&&i.jsxs("span",{className:"hidden items-center gap-1 overflow-hidden md:flex md:max-w-[240px]",children:[(fe.labels??[]).slice(0,3).map(Ce=>i.jsx(UI,{label:Ce},Ce.id)),(fe.labels??[]).length>3&&i.jsxs("span",{className:"text-[10px] text-muted-foreground",children:["+",(fe.labels??[]).length-3]})]}),i.jsxs(cr,{open:z===fe.id,onOpenChange:Ce=>{F(Ce?fe.id:null),Ce||J("")},children:[i.jsx(k7e,{asChild:!0,children:i.jsx("button",{type:"button",className:"flex w-[180px] shrink-0 items-center rounded-md px-2 py-1 transition-colors hover:bg-accent/50",onClick:Ce=>{Ce.preventDefault(),Ce.stopPropagation(),q(fe.id)},children:fe.assigneeAgentId&&ge.get(fe.assigneeAgentId)?i.jsx(no,{kind:"agent",label:ge.get(fe.assigneeAgentId).name,badgeLabel:Eb(ge.get(fe.assigneeAgentId)),agentIcon:(ne=ge.get(fe.assigneeAgentId))==null?void 0:ne.icon,agentRole:(Fe=ge.get(fe.assigneeAgentId))==null?void 0:Fe.role}):fe.assigneeUserId?i.jsx(no,{kind:"user",label:Ec(fe.assigneeUserId,E)??"User"}):i.jsx(no,{kind:"unassigned",label:"Assignee",muted:!0})})}),i.jsxs(ur,{className:"w-56 p-1",align:"end",onClick:Ce=>Ce.stopPropagation(),onPointerDownOutside:()=>J(""),children:[i.jsx("input",{className:"mb-1 w-full border-b border-border bg-transparent px-2 py-1.5 text-xs outline-none placeholder:text-muted-foreground/50",placeholder:"Search assignees...",value:K,onChange:Ce=>J(Ce.target.value),autoFocus:!0}),i.jsxs("div",{ref:V,"data-testid":"issue-row-assignee-picker-scroll",className:"scrollbar-auto-hide max-h-48 overflow-y-auto overscroll-contain",children:[i.jsx("button",{className:Q("flex w-full items-center gap-2 rounded px-2 py-1.5 text-xs hover:bg-accent/50",!fe.assigneeAgentId&&!fe.assigneeUserId&&"bg-accent"),onClick:Ce=>{Ce.preventDefault(),Ce.stopPropagation(),xe(fe.id,null,null)},children:i.jsx(no,{kind:"unassigned",label:"No assignee"})}),E&&i.jsx("button",{className:Q("flex w-full items-center gap-2 rounded px-2 py-1.5 text-left text-xs hover:bg-accent/50",fe.assigneeUserId===E&&"bg-accent"),onClick:Ce=>{Ce.preventDefault(),Ce.stopPropagation(),xe(fe.id,null,E)},children:i.jsx(no,{kind:"user",label:"Me"})}),(r??[]).filter(Ce=>K.trim()?`${zo(Ce)} ${Ce.name} ${Ce.role} ${Ce.title??""}`.toLowerCase().includes(K.toLowerCase()):!0).map(Ce=>i.jsx("button",{className:Q("flex w-full items-center gap-2 rounded px-2 py-1.5 text-left text-xs hover:bg-accent/50",fe.assigneeAgentId===Ce.id&&"bg-accent"),onClick:tt=>{tt.preventDefault(),tt.stopPropagation(),xe(fe.id,Ce.id,null)},children:i.jsx(no,{kind:"agent",label:Ce.name,badgeLabel:Eb(Ce),agentIcon:Ce.icon,agentRole:Ce.role,className:"min-w-0"})},Ce.id))]})]})]})]}),trailingMeta:po(fe.createdAt),onOpen:()=>v==null?void 0:v(fe)},fe.id)})})]},re.key))]})}const Zk="rudder.linear",zne="page-bootstrap",Bne="linear-catalog",CP="linear-issues",Hwt="import-linear-issues",Kwt=50,SP=["backlog","todo","in_progress","in_review","blocked","done","cancelled"],jje={backlog:"border-[color:color-mix(in_oklab,var(--border-soft)_88%,transparent)] bg-[color:color-mix(in_oklab,var(--surface-inset)_88%,transparent)]",todo:"border-blue-200/75 bg-blue-50/70 dark:border-blue-900/55 dark:bg-blue-950/24",in_progress:"border-amber-200/75 bg-amber-50/70 dark:border-amber-900/55 dark:bg-amber-950/24",in_review:"border-violet-200/75 bg-violet-50/70 dark:border-violet-900/55 dark:bg-violet-950/24",blocked:"border-red-200/75 bg-red-50/70 dark:border-red-900/55 dark:bg-red-950/24",done:"border-emerald-200/75 bg-emerald-50/70 dark:border-emerald-900/55 dark:bg-emerald-950/24",cancelled:"border-neutral-200/75 bg-neutral-50/70 dark:border-neutral-800/60 dark:bg-neutral-900/26"};function Wwt(e){return(e==null?void 0:e.find(t=>t.pluginKey===Zk))??null}function Nje(e){return e.replace(/_/g," ").replace(/\b\w/g,t=>t.toUpperCase())}function Gwt(e){const t=[`Imported ${e.importedCount}`];return e.duplicateCount>0&&t.push(`${e.duplicateCount} duplicate`),e.fallbackCount>0&&t.push(`${e.fallbackCount} fallback`),e.adjustedCount>0&&t.push(`${e.adjustedCount} adjusted`),t.join(" / ")}function s5(e){return Q("h-9 min-w-0 rounded-[calc(var(--radius-sm)-1px)] border border-[color:var(--border-base)] bg-[color:var(--surface-elevated)] px-2.5 text-sm text-foreground outline-none transition-[border-color,box-shadow] focus:border-ring focus:ring-[3px] focus:ring-ring/40 disabled:cursor-not-allowed disabled:opacity-50",e)}function Qwt(){if(typeof window>"u")return"board";const e=window.localStorage.getItem("rudder:linear-source-view-mode");return e==="list"||e==="board"?e:"board"}function Ywt(e,t){var r;const n=t==null?void 0:t.find(s=>s.teamId===e.team.id);return((r=n==null?void 0:n.stateMappings.find(s=>s.linearStateId===e.state.id))==null?void 0:r.rudderStatus)??"backlog"}function Une(e,t){const n=e?Date.parse(e):0,r=t?Date.parse(t):0;return n-r}function Jwt(e){const t=e.importedRudderIssueIdentifier??e.importedRudderIssueId;return t?`/issues/${t}`:null}function _P({label:e,children:t,className:n}){return i.jsxs("label",{className:Q("flex min-w-0 flex-col gap-1",n),children:[i.jsx("span",{className:"text-[11px] font-medium text-muted-foreground",children:e}),t]})}function Cje(){return i.jsxs("span",{className:"inline-flex items-center gap-1 rounded-[calc(var(--radius-sm)-2px)] border border-emerald-300/60 bg-emerald-50 px-1.5 py-0.5 text-[11px] font-medium text-emerald-700 dark:border-emerald-900/60 dark:bg-emerald-950/28 dark:text-emerald-300",children:[i.jsx(ws,{className:"h-3 w-3"}),"Imported"]})}function Zwt({row:e}){var t,n;return i.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-x-3 gap-y-1 text-xs text-muted-foreground",children:[i.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1",children:[i.jsx(Ws,{status:Sje(e.state.type)}),i.jsx("span",{className:"truncate",children:e.state.name})]}),i.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1",children:[i.jsx(v1,{className:"h-3 w-3 shrink-0"}),i.jsx("span",{className:"truncate",children:((t=e.project)==null?void 0:t.name)??"No Linear project"})]}),i.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1",children:[i.jsx(Iv,{className:"h-3 w-3 shrink-0"}),i.jsx("span",{className:"truncate",children:((n=e.assignee)==null?void 0:n.name)??"Unassigned"})]}),i.jsxs("span",{children:["Updated ",du(e.updatedAt)]})]})}function Sje(e){return e==="started"?"in_progress":e==="completed"?"done":e==="canceled"?"cancelled":e==="backlog"?"backlog":"todo"}function _je({row:e,orgId:t}){if(!e.imported)return null;const n=Jwt(e),r=!e.importedOrgId||e.importedOrgId===t;return n&&r?i.jsx(de,{asChild:!0,variant:"ghost",size:"sm",children:i.jsx(Nt,{to:n,children:"Open issue"})}):i.jsx("span",{className:"text-xs text-muted-foreground",children:"Imported elsewhere"})}function Xwt({rows:e,selectedIssueIds:t,orgId:n,importing:r,onToggleSelected:s}){return i.jsx("div",{className:"min-h-0 overflow-hidden rounded-[calc(var(--radius-sm)+1px)] border border-[color:var(--border-base)] bg-[color:var(--surface-elevated)]",children:e.map(a=>{const o=t.includes(a.id);return i.jsxs("article",{"data-testid":`linear-source-row-${a.id}`,className:"grid min-h-16 grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-3 border-b border-[color:var(--border-soft)] px-3 py-3 last:border-b-0",children:[i.jsx("input",{type:"checkbox","data-testid":`linear-source-row-checkbox-${a.id}`,className:"h-4 w-4 rounded border-[color:var(--border-base)]",checked:o,disabled:a.imported||r,"aria-label":`Select ${a.identifier}`,onChange:()=>s(a.id)}),i.jsxs("div",{className:"min-w-0",children:[i.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[i.jsxs("a",{href:a.url,target:"_blank",rel:"noreferrer",className:"min-w-0 truncate text-sm font-medium text-foreground no-underline hover:underline",children:[i.jsx("span",{className:"font-mono text-xs text-muted-foreground",children:a.identifier})," ",a.title]}),a.imported?i.jsx(Cje,{}):null]}),i.jsx(Zwt,{row:a})]}),i.jsx("div",{className:"flex shrink-0 items-center",children:i.jsx(_je,{row:a,orgId:n})})]},a.id)})})}function ekt({status:e,issueCount:t}){return i.jsxs("div",{"data-testid":`linear-source-hidden-column-${e}`,className:Q("flex items-center gap-2 rounded-[calc(var(--radius-sm)-1px)] border px-2 py-2",jje[e]),children:[i.jsx(Ws,{status:e}),i.jsx("span",{className:"min-w-0 flex-1 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:Nje(e)}),i.jsx("span",{className:"text-xs text-muted-foreground/60 tabular-nums",children:t})]})}function tkt({rows:e,teamMappings:t,selectedIssueIds:n,orgId:r,importing:s,onToggleSelected:a}){const o=x.useMemo(()=>{var d;const u=new Map;for(const h of SP)u.set(h,[]);for(const h of e){const m=Ywt(h,t);(d=u.get(m))==null||d.push(h)}return u},[e,t]),l=SP.filter(u=>{var d;return(((d=o.get(u))==null?void 0:d.length)??0)>0}),c=SP.filter(u=>{var d;return(((d=o.get(u))==null?void 0:d.length)??0)===0});return i.jsx("div",{className:"scrollbar-auto-hide min-h-0 flex-1 overflow-x-auto overflow-y-hidden pb-3",children:i.jsxs("div",{className:"flex h-full min-h-full min-w-max items-stretch gap-3 pr-2",children:[l.map(u=>{const d=o.get(u)??[];return i.jsxs("section",{className:"flex h-full min-h-0 w-[272px] min-w-[272px] shrink-0 flex-col",children:[i.jsxs("div",{className:"mb-1 flex items-center gap-2 px-2 py-2",children:[i.jsx(Ws,{status:u}),i.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:Nje(u)}),i.jsx("span",{className:"ml-auto text-xs text-muted-foreground/60 tabular-nums",children:d.length})]}),i.jsx("div",{"data-testid":`linear-source-kanban-column-${u}`,className:Q("scrollbar-auto-hide flex-1 space-y-1.5 overflow-y-auto rounded-[calc(var(--radius-sm)-1px)] border p-1.5",jje[u]),children:d.map(h=>{var m,g;return i.jsxs("article",{"data-testid":`linear-source-board-card-${h.id}`,className:"overflow-hidden rounded-[calc(var(--radius-sm)-1px)] border bg-card p-2.5",children:[i.jsxs("div",{className:"mb-1.5 flex min-w-0 items-start gap-2",children:[i.jsx("input",{type:"checkbox",className:"mt-0.5 h-4 w-4 rounded border-[color:var(--border-base)]",checked:n.includes(h.id),disabled:h.imported||s,"aria-label":`Select ${h.identifier}`,onChange:()=>a(h.id)}),i.jsx("a",{href:h.url,target:"_blank",rel:"noreferrer",className:"min-w-0 flex-1 truncate font-mono text-xs text-muted-foreground no-underline hover:underline",children:h.identifier}),h.imported?i.jsx(Cje,{}):null]}),i.jsx("p",{className:"mb-2 line-clamp-2 text-sm leading-snug",children:h.title}),i.jsxs("div",{className:"space-y-1.5 text-xs text-muted-foreground",children:[i.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[i.jsx(Ws,{status:Sje(h.state.type)}),i.jsx("span",{className:"truncate",children:h.state.name})]}),i.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[i.jsx(v1,{className:"h-3 w-3 shrink-0"}),i.jsx("span",{className:"truncate",children:((m=h.project)==null?void 0:m.name)??"No Linear project"})]}),i.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[i.jsx(Iv,{className:"h-3 w-3 shrink-0"}),i.jsx("span",{className:"truncate",children:((g=h.assignee)==null?void 0:g.name)??"Unassigned"})]}),i.jsxs("span",{children:["Updated ",du(h.updatedAt)]})]}),h.imported?i.jsx("div",{className:"mt-3 flex justify-end",children:i.jsx(_je,{row:h,orgId:r})}):null]},h.id)})})]},u)}),c.length>0?i.jsxs("div",{"data-testid":"linear-source-hidden-columns",className:"flex h-full min-h-0 w-[228px] min-w-[228px] shrink-0 flex-col rounded-[calc(var(--radius-sm)+1px)] border border-[color:var(--border-base)] bg-[color:color-mix(in_oklab,var(--surface-inset)_78%,transparent)] p-2",children:[i.jsxs("div",{className:"mb-2 flex items-center gap-2 px-1",children:[i.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:"Hidden columns"}),i.jsx("span",{className:"ml-auto text-xs text-muted-foreground/60 tabular-nums",children:c.length})]}),i.jsx("div",{className:"space-y-2",children:c.map(u=>{var d;return i.jsx(ekt,{status:u,issueCount:((d=o.get(u))==null?void 0:d.length)??0},u)})})]}):null]})})}function nkt({orgId:e,orgName:t,projects:n,linearTeamId:r="",linearProjectId:s="",initialSearch:a=""}){var Qe,pt;const o=xn(),{pushToast:l}=gr(),[c,u]=x.useState(()=>Qwt()),[d,h]=x.useState(!1),[m,g]=x.useState("selected"),[b,v]=x.useState(""),[j,k]=x.useState(""),[w,N]=x.useState(""),[S,A]=x.useState("updated"),[_,E]=x.useState("desc"),[I,O]=x.useState(a),[M,D]=x.useState(a),[z,F]=x.useState([]),K=x.useRef(null),J=(t==null?void 0:t.trim())||"this organization";x.useEffect(()=>{O(a),D(a)},[a]),x.useEffect(()=>{const Se=window.setTimeout(()=>D(I.trim()),300);return()=>window.clearTimeout(Se)},[I]),x.useEffect(()=>{F([])},[r,s,j,w,M]),x.useEffect(()=>{typeof window<"u"&&window.localStorage.setItem("rudder:linear-source-view-mode",c)},[c]);const{data:$,isLoading:L}=ke({queryKey:U.plugins.uiContributions,queryFn:()=>vs.listUiContributions()}),H=x.useMemo(()=>Wwt($),[$]),W=(H==null?void 0:H.pluginId)??"",{data:B,isLoading:Y,error:P}=ke({queryKey:["plugins",Zk,zne,e,W],queryFn:async()=>(await vs.bridgeGetData(W,zne,{orgId:e},e)).data,enabled:!!e&&!!W}),{data:V,isLoading:ce}=ke({queryKey:["plugins",Zk,Bne,e,W],queryFn:async()=>(await vs.bridgeGetData(W,Bne,{orgId:e},e)).data,enabled:!!e&&!!W&&(B==null?void 0:B.configured)!==!1}),le=["plugins",Zk,CP,e,W,r||"__all__",s||"__all__",j||"__all__",w||"__all__",M||"__none__"],{data:G,isLoading:te,error:ge,hasNextPage:ie,fetchNextPage:ae,isFetchingNextPage:he}=r5e({queryKey:le,initialPageParam:null,queryFn:async({pageParam:Se})=>{const Be=typeof Se=="string"&&Se?Se:void 0;return(await vs.bridgeGetData(W,CP,{orgId:e,limit:Kwt,after:Be,teamId:r||void 0,projectId:s||void 0,stateId:j||void 0,assigneeId:w||void 0,query:M||void 0},e)).data},getNextPageParam:Se=>Se.hasNextPage&&Se.endCursor?Se.endCursor:void 0,enabled:!!e&&!!W&&(B==null?void 0:B.configured)===!0}),me=nt({mutationFn:async({mode:Se,issueIds:Be})=>{if(!b)throw new Error(`Choose a project in ${J} before importing.`);return(await vs.bridgePerformAction(W,Hwt,{orgId:e,targetProjectId:b,mode:Se,issueIds:Be,filters:{teamId:r||void 0,stateId:j||void 0,projectId:s||void 0,assigneeId:w||void 0,query:M||void 0}},e)).data},onSuccess:async Se=>{l({title:"Linear import complete",body:Gwt(Se),tone:"success"}),F([]),h(!1),await Promise.all([o.invalidateQueries({queryKey:["plugins",Zk,CP,e]}),o.invalidateQueries({queryKey:U.issues.list(e)})])},onError:Se=>{l({title:"Linear import failed",body:Se instanceof Error?Se.message:String(Se),tone:"error"})}}),ye=x.useMemo(()=>{const Se=[...(G==null?void 0:G.pages.flatMap(Be=>Be.rows))??[]];return Se.sort((Be,Ae)=>{let it=0;return S==="updated"?it=Une(Be.updatedAt,Ae.updatedAt):S==="created"?it=Une(Be.createdAt,Ae.createdAt):it=Be.identifier.localeCompare(Ae.identifier),_==="asc"?it:-it}),Se},[G==null?void 0:G.pages,_,S]);x.useEffect(()=>{const Se=new Set(ye.map(Be=>Be.id));F(Be=>Be.filter(Ae=>Se.has(Ae)))},[ye]);const Me=x.useMemo(()=>(V==null?void 0:V.teams.find(Se=>Se.id===r))??null,[V==null?void 0:V.teams,r]),$e=x.useMemo(()=>(V==null?void 0:V.projects.find(Se=>Se.id===s))??null,[V==null?void 0:V.projects,s]),Re=$e?`${$e.name}${Me?` / ${Me.name}`:""}`:(Me==null?void 0:Me.name)??"All Linear teams",Ue=x.useMemo(()=>{var Be;return((Be=B==null?void 0:B.projects)!=null&&Be.length?B.projects:n??[]).filter(Ae=>!("archivedAt"in Ae)||!Ae.archivedAt)},[B==null?void 0:B.projects,n]);x.useEffect(()=>{if(Ue.length===0){b&&v("");return}Ue.some(Se=>Se.id===b)||v(Ue.length===1?Ue[0].id:"")},[b,Ue]);const we=x.useMemo(()=>{const Se=r?((V==null?void 0:V.teams)??[]).filter(Ae=>Ae.id===r):(V==null?void 0:V.teams)??[],Be=new Map;for(const Ae of Se)for(const it of Ae.states??[])Be.set(it.id,it.name);return[...Be.entries()].map(([Ae,it])=>({id:Ae,name:it}))},[V==null?void 0:V.teams,r]),ze=ye.filter(Se=>Se.imported).length,oe=ye.filter(Se=>!Se.imported),xe=me.isPending,X=L||Y||ce||te,q=P??ge,ue=z.length,je=Ue.find(Se=>Se.id===b)??null,re=ye.length,fe=+!!j+ +!!w,ne=((Qe=we.find(Se=>Se.id===j))==null?void 0:Qe.name)??"All states",Fe=((pt=V==null?void 0:V.users.find(Se=>Se.id===w))==null?void 0:pt.name)??"Anyone",Ce=x.useCallback(Se=>{F(Be=>Be.includes(Se)?Be.filter(Ae=>Ae!==Se):[...Be,Se])},[]),tt=x.useCallback(Se=>{g(Se),h(!0)},[]);return x.useEffect(()=>{const Se=K.current;if(!Se||!ie||X||xe||he||typeof IntersectionObserver>"u")return;const Be=new IntersectionObserver(Ae=>{!Ae.some(Je=>Je.isIntersecting)||!ie||he||xe||ae()},{root:null,rootMargin:"280px 0px"});return Be.observe(Se),()=>Be.disconnect()},[ae,ie,xe,he,X,re]),!L&&!H?i.jsx("div",{className:"flex min-h-[58vh] items-center justify-center","data-testid":"linear-source-board",children:i.jsx(Er,{icon:Kl,message:"Linear is not installed or ready."})}):!Y&&(B==null?void 0:B.configured)===!1?i.jsx("div",{className:"flex h-full min-h-0 flex-col px-1","data-testid":"linear-source-board",children:i.jsxs("div",{className:"rounded-[calc(var(--radius-sm)+1px)] border border-dashed border-[color:var(--border-base)] bg-[color:color-mix(in_oklab,var(--surface-inset)_82%,transparent)] px-4 py-4 text-sm text-muted-foreground",children:[i.jsx("div",{className:"font-medium text-foreground",children:"Linear is not configured for this organization."}),i.jsx("div",{className:"mt-1",children:B.message??"Connect Linear and choose teams in plugin settings."}),i.jsx(de,{asChild:!0,variant:"outline",size:"sm",className:"mt-3",children:i.jsx(Nt,{to:"/instance/settings/plugins",children:"Open plugin settings"})})]})}):i.jsxs("div",{"data-testid":"linear-source-board",className:"flex h-full min-h-0 flex-col gap-4",children:[i.jsxs("div",{"data-testid":"linear-source-toolbar",className:"surface-panel flex items-center justify-between gap-2 rounded-[calc(var(--radius-sm)+1px)] px-3 py-3 sm:gap-3",children:[i.jsxs("div",{className:"flex min-w-0 items-baseline gap-3",children:[i.jsx("div",{className:"truncate text-xs font-medium uppercase tracking-[0.18em] text-muted-foreground",children:Re}),i.jsxs("div",{className:"hidden min-w-0 items-center gap-2 text-xs text-muted-foreground md:flex",children:[i.jsxs("span",{children:[re," loaded"]}),ze>0?i.jsxs("span",{children:[ze," imported"]}):null,ie?i.jsx("span",{children:"Loads as you scroll"}):null]})]}),i.jsxs("div",{className:"flex shrink-0 items-center gap-0.5 sm:gap-1",children:[i.jsxs("div",{className:"flex items-center overflow-hidden rounded-[var(--radius-sm)] border border-[color:var(--border-base)] bg-[color:color-mix(in_oklab,var(--surface-inset)_82%,transparent)]",children:[i.jsx("button",{className:Q("p-1.5 transition-colors",c==="list"?"bg-[color:var(--surface-active)] text-foreground":"text-muted-foreground hover:text-foreground"),onClick:()=>u("list"),title:"List view","data-testid":"linear-source-view-list",children:i.jsx(J7,{className:"h-3.5 w-3.5"})}),i.jsx("button",{className:Q("p-1.5 transition-colors",c==="board"?"bg-[color:var(--surface-active)] text-foreground":"text-muted-foreground hover:text-foreground"),onClick:()=>u("board"),title:"Board view","data-testid":"linear-source-view-board",children:i.jsx(Gue,{className:"h-3.5 w-3.5"})})]}),i.jsxs(cr,{children:[i.jsx(mr,{asChild:!0,children:i.jsxs(de,{variant:"ghost",size:"sm",className:Q("text-xs",fe>0&&"text-[color:var(--accent-strong)]"),children:[i.jsx(VL,{className:"h-3.5 w-3.5 sm:h-3 sm:w-3 sm:mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:fe>0?`Filters: ${fe}`:"Filter"})]})}),i.jsx(ur,{align:"end",className:"w-72 p-3",children:i.jsxs("div",{className:"space-y-3",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("span",{className:"text-sm font-medium",children:"Filters"}),fe>0?i.jsx("button",{type:"button",className:"text-xs text-muted-foreground hover:text-foreground",onClick:()=>{k(""),N("")},children:"Clear"}):null]}),i.jsx(_P,{label:"State",children:i.jsxs("select",{className:s5("h-8 w-full"),value:j,"aria-label":"Filter by Linear state",onChange:Se=>k(Se.target.value),children:[i.jsx("option",{value:"",children:"All states"}),we.map(Se=>i.jsx("option",{value:Se.id,children:Se.name},Se.id))]})}),i.jsx(_P,{label:"Assignee",children:i.jsxs("select",{className:s5("h-8 w-full"),value:w,"aria-label":"Filter by Linear assignee",onChange:Se=>N(Se.target.value),children:[i.jsx("option",{value:"",children:"Anyone"}),((V==null?void 0:V.users)??[]).map(Se=>i.jsx("option",{value:Se.id,children:Se.name},Se.id))]})}),i.jsxs("div",{className:"rounded-[calc(var(--radius-sm)-1px)] border border-[color:var(--border-soft)] bg-[color:var(--surface-inset)] px-2.5 py-2 text-xs text-muted-foreground",children:[ne," / ",Fe]})]})})]}),i.jsxs(cr,{children:[i.jsx(mr,{asChild:!0,children:i.jsxs(de,{variant:"ghost",size:"sm",className:"text-xs",children:[i.jsx(zL,{className:"h-3.5 w-3.5 sm:h-3 sm:w-3 sm:mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:"Sort"})]})}),i.jsx(ur,{align:"end",className:"w-56 p-3",children:i.jsxs("div",{className:"space-y-3",children:[i.jsx(_P,{label:"Sort by",children:i.jsxs("select",{className:s5("h-8 w-full"),value:S,"aria-label":"Sort Linear issues",onChange:Se=>A(Se.target.value),children:[i.jsx("option",{value:"updated",children:"Updated"}),i.jsx("option",{value:"created",children:"Created"}),i.jsx("option",{value:"identifier",children:"Identifier"})]})}),i.jsxs(de,{type:"button",variant:"ghost",size:"sm",className:"h-8 w-full justify-start",title:`Sort ${_==="asc"?"ascending":"descending"}`,onClick:()=>E(Se=>Se==="asc"?"desc":"asc"),children:[i.jsx(zL,{className:"h-3.5 w-3.5"}),i.jsx("span",{children:_==="asc"?"Ascending":"Descending"})]})]})})]})]})]}),i.jsxs("div",{className:"surface-panel flex flex-col gap-3 rounded-[calc(var(--radius-sm)+1px)] px-3 py-2.5 md:flex-row md:items-center md:justify-between",children:[i.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[i.jsxs(de,{type:"button",variant:"ghost",size:"sm",disabled:oe.length===0||xe,onClick:()=>F(oe.map(Se=>Se.id)),children:[i.jsx(VL,{className:"h-3.5 w-3.5"}),"Select loaded"]}),i.jsx(de,{type:"button",variant:"ghost",size:"sm",disabled:z.length===0||xe,onClick:()=>F([]),children:"Clear"})]}),i.jsxs("div",{className:"flex min-w-0 flex-wrap items-center justify-end gap-2",children:[i.jsxs("span",{className:"text-xs text-muted-foreground",children:[ue," selected"]}),i.jsxs(de,{type:"button",variant:"outline",size:"sm","data-testid":"linear-source-import-selected",disabled:ue===0||xe,onClick:()=>tt("selected"),children:[i.jsx(kG,{className:"h-3.5 w-3.5"}),"Import selected"]}),i.jsx(de,{type:"button",size:"sm",disabled:re===0||xe,onClick:()=>tt("allMatching"),children:"Import matching"})]})]}),X?i.jsx(Is,{variant:"issues-list"}):null,q?i.jsx("p",{className:"text-sm text-destructive",children:q instanceof Error?q.message:String(q)}):null,!X&&!q&&ye.length===0?i.jsx("div",{className:"flex min-h-[48vh] items-center justify-center",children:i.jsx(Er,{icon:Kl,message:"No Linear issues match this source."})}):null,!X&&!q&&ye.length>0&&c==="list"?i.jsx(Xwt,{rows:ye,selectedIssueIds:z,orgId:e,importing:xe,onToggleSelected:Ce}):null,!X&&!q&&ye.length>0&&c==="board"?i.jsx(tkt,{rows:ye,teamMappings:B==null?void 0:B.teamMappings,selectedIssueIds:z,orgId:e,importing:xe,onToggleSelected:Ce}):null,!X&&!q&&ye.length>0?i.jsx("div",{ref:K,"data-testid":"linear-source-load-more-sentinel",className:"flex min-h-8 items-center justify-between gap-3 text-xs text-muted-foreground",children:i.jsxs("span",{children:["Loaded ",re," issue",re===1?"":"s",he?" - loading more":ie?" - more load as you scroll":" - all matching issues loaded"]})}):null,i.jsx(Bs,{open:d,onOpenChange:h,children:i.jsxs(Ys,{className:"sm:max-w-md",children:[i.jsxs(ma,{children:[i.jsx(Ui,{children:m==="selected"?"Import selected Linear issues":"Import matching Linear issues"}),i.jsxs(Ba,{children:["Choose the project in ",J," where these issues should land."]})]}),i.jsxs("div",{className:"space-y-3",children:[i.jsxs("label",{className:"flex flex-col gap-1.5",children:[i.jsxs("span",{className:"text-xs font-medium text-muted-foreground",children:["Project in ",J]}),i.jsxs("select",{"data-testid":"linear-source-import-project",className:s5("w-full"),value:b,"aria-label":`Project in ${J}`,onChange:Se=>v(Se.target.value),children:[i.jsxs("option",{value:"",children:["Choose a project in ",J]}),Ue.map(Se=>i.jsx("option",{value:Se.id,children:Se.name},Se.id))]})]}),i.jsxs("div",{className:"rounded-[calc(var(--radius-sm)-1px)] border border-[color:var(--border-soft)] bg-[color:var(--surface-inset)] px-3 py-2 text-xs text-muted-foreground",children:[m==="selected"?`${ue} selected Linear issue${ue===1?"":"s"}`:`All matching Linear issues from ${Re}`,je?` -> ${je.name}`:""]})]}),i.jsxs(Fo,{children:[i.jsx(de,{type:"button",variant:"outline",onClick:()=>h(!1),children:"Cancel"}),i.jsxs(de,{type:"button","data-testid":"linear-source-confirm-import",disabled:!b||xe||m==="selected"&&ue===0,onClick:()=>{me.mutate({mode:m,issueIds:m==="selected"?z:void 0})},children:[i.jsx(kG,{className:"h-3.5 w-3.5"}),xe?"Importing":"Import"]})]})]})})]})}const Aje="rudder:starred-issues";function rkt(){if(typeof window>"u")return[];try{const e=window.localStorage.getItem(Aje);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t.filter(n=>typeof n=="string"&&n.length>0):[]}catch{return[]}}function qne(){if(!(typeof window>"u"))try{window.localStorage.removeItem(Aje)}catch{}}function skt(e){const t=xn(),n=x.useRef(null),r=x.useRef(null),s=ke({queryKey:U.issues.follows(e??"__none__"),queryFn:()=>fn.listFollows(e),enabled:!!e}),a=x.useMemo(()=>new Set((s.data??[]).map(l=>l.issueId)),[s.data]);x.useEffect(()=>{if(!e||!s.isSuccess||n.current===e||r.current===e)return;const l=rkt();if(l.length===0){n.current=e;return}const c=l.filter(u=>!a.has(u));if(c.length===0){qne(),n.current=e;return}r.current=e,Promise.allSettled(c.map(u=>fn.follow(u))).then(async u=>{r.current=null,!u.some(h=>h.status==="rejected")&&(qne(),n.current=e,await t.invalidateQueries({queryKey:U.issues.follows(e)}),await t.invalidateQueries({queryKey:U.issues.list(e)}),await t.invalidateQueries({queryKey:U.messenger.threads(e)}),await t.invalidateQueries({queryKey:U.messenger.issues(e)}))})},[a,s.isSuccess,e,t]);const o=x.useCallback(async l=>{e&&(a.has(l)?await fn.unfollow(l):await fn.follow(l),await t.invalidateQueries({queryKey:U.issues.follows(e)}),await t.invalidateQueries({queryKey:U.issues.list(e)}),await t.invalidateQueries({queryKey:U.messenger.threads(e)}),await t.invalidateQueries({queryKey:U.messenger.issues(e)}))},[a,e,t]);return{follows:s.data??[],followedIssueIds:a,isLoading:s.isLoading,error:s.error instanceof Error?s.error:null,toggleFollowIssue:o}}function ikt(e){return e.replace(/[-_]+/g," ").replace(/\b\w/g,t=>t.toUpperCase())}function akt(e,t){var n;return e.projectId?((n=t==null?void 0:t.find(r=>r.id===e.projectId))==null?void 0:n.name)??null:null}function okt(e,t,n){var s;const r=hh(e.assigneeValue||e.assigneeId||"");return r.assigneeAgentId?((s=t==null?void 0:t.find(a=>a.id===r.assigneeAgentId))==null?void 0:s.name)??null:r.assigneeUserId?Ec(r.assigneeUserId,n):null}const lkt=220;function ckt(){var e,t;return typeof window>"u"?!1:((t=(e=window.matchMedia)==null?void 0:e.call(window,"(prefers-reduced-motion: reduce)"))==null?void 0:t.matches)??!1}function ukt({description:e}){return e?i.jsx("div",{"data-testid":"issue-draft-description-preview",className:"mt-5 max-h-[4.5rem] w-full min-w-0 overflow-hidden",children:i.jsx(gi,{className:"text-sm leading-6 text-muted-foreground [&_blockquote]:my-0 [&_h1]:my-0 [&_h1]:text-sm [&_h1]:leading-6 [&_h2]:my-0 [&_h2]:text-sm [&_h2]:leading-6 [&_h3]:my-0 [&_h3]:text-sm [&_h3]:leading-6 [&_img]:my-0 [&_img]:max-h-[4.5rem] [&_img]:w-full [&_img]:rounded-[calc(var(--radius-sm)-2px)] [&_img]:object-cover [&_ol]:my-0 [&_p]:my-0 [&_pre]:my-0 [&_ul]:my-0",children:e})}):i.jsx("p",{className:"mt-5 text-sm leading-6 text-muted-foreground",children:"Add description..."})}function dkt({drafts:e,agents:t,projects:n,currentUserId:r,deletingDraftIds:s,onOpenDraft:a,onDeleteDraft:o}){return e.length===0?i.jsx("div",{"data-testid":"issue-drafts-view",className:"flex h-full min-h-0 flex-col",children:i.jsx(Er,{icon:tb,message:"No draft issues."})}):i.jsxs("div",{"data-testid":"issue-drafts-view",className:"flex h-full min-h-0 flex-col overflow-y-auto px-6 py-5",children:[i.jsx("div",{className:"mb-4 flex items-center justify-between gap-3",children:i.jsxs("div",{children:[i.jsx("h1",{className:"text-lg font-semibold text-foreground",children:"Draft Issues"}),i.jsxs("p",{className:"mt-1 text-sm text-muted-foreground",children:[e.length," saved draft",e.length===1?"":"s"]})]})}),i.jsx("section",{"aria-label":"Draft issues",className:"grid max-w-5xl grid-cols-1 gap-3 md:grid-cols-2 xl:grid-cols-3",children:e.map(l=>{const c=(s==null?void 0:s.has(l.id))??!1,u=akt(l,n),d=okt(l,t,r),h=[l.status?{key:"status",icon:i.jsx(pl,{className:"h-3 w-3 shrink-0"}),label:ikt(l.status)}:null,l.priority?{key:"priority",icon:i.jsx(qI,{priority:l.priority,className:"h-3.5 w-4 shrink-0"}),label:Ho(l.priority)}:null,u?{key:"project",icon:i.jsx(v1,{className:"h-3 w-3 shrink-0"}),label:u}:null,d?{key:"assignee",icon:i.jsx(Iv,{className:"h-3 w-3 shrink-0"}),label:d}:null,{key:"updated",icon:i.jsx(vf,{className:"h-3 w-3 shrink-0"}),label:hs(l.updatedAt)}].filter(m=>!!m);return i.jsxs("article",{"data-testid":"issue-draft-card","data-deleting":c?"true":void 0,"aria-busy":c?"true":void 0,className:"motion-draft-issue-card group relative min-h-36 rounded-[var(--radius-sm)] border border-[color:var(--border-soft)] bg-[color:color-mix(in_oklab,var(--surface-elevated)_88%,transparent)] hover:border-[color:var(--border-strong)] hover:bg-[color:var(--surface-elevated)]",children:[i.jsx("button",{type:"button",disabled:c,"aria-label":`Open draft ${l.title}`,className:"absolute inset-0 z-10 rounded-[var(--radius-sm)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",onClick:()=>a(l)}),i.jsxs("div",{className:"pointer-events-none flex h-full min-h-36 w-full flex-col items-start px-4 py-3 text-left",children:[i.jsxs("div",{className:"flex w-full min-w-0 items-start gap-2 pr-9",children:[i.jsx(tb,{className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}),i.jsxs("div",{className:"min-w-0",children:[i.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:l.title}),i.jsx("div",{className:"mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-muted-foreground",children:h.map(m=>i.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1",children:[m.icon,i.jsx("span",{className:"max-w-[11rem] truncate",children:m.label})]},`${l.id}-${m.key}`))})]})]}),i.jsx(ukt,{description:l.description})]}),i.jsx("button",{type:"button","data-testid":"issue-draft-delete-button",disabled:c,"aria-label":`Delete draft ${l.title}`,onClick:m=>{m.preventDefault(),m.stopPropagation(),o(l)},className:"absolute right-3 top-3 z-20 inline-flex h-7 w-7 items-center justify-center rounded-[calc(var(--radius-sm)-2px)] text-muted-foreground opacity-100 transition-colors hover:bg-[color:color-mix(in_oklab,var(--destructive)_16%,transparent)] hover:text-destructive",children:i.jsx(ha,{className:"h-3.5 w-3.5"})})]},l.id)})})]})}function fkt(){var ie,ae;const{selectedOrganizationId:e,selectedOrganization:t}=bn(),{setBreadcrumbs:n}=Nr(),{openNewIssue:r,confirm:s}=Gr(),{pushToast:a}=gr(),o=Tn(),[l]=md(),c=xn(),u=l.get("q")??"",d=l.get("source")??"",h=l.get("scope")??"",m=h==="recent"?"":h,g=m==="drafts",b=d==="linear"&&!g,v=l.get("linearTeamId")??void 0,j=l.get("linearProjectId")??void 0,k=l.get("projectId")??void 0,w=l.get("participantAgentId")??void 0,N=l.get("groupBy"),S=N==="status"||N==="priority"||N==="assignee"||N==="project"||N==="none"?N:void 0,A=x.useRef(void 0),_=x.useCallback(he=>{clearTimeout(A.current),A.current=setTimeout(()=>{const me=he.trim();if((new URLSearchParams(window.location.search).get("q")??"")===me)return;const Me=new URL(window.location.href);me?Me.searchParams.set("q",me):Me.searchParams.delete("q");const $e=`${Me.pathname}${Me.search}${Me.hash}`;window.history.replaceState(window.history.state,"",$e)},300)},[]);x.useEffect(()=>()=>clearTimeout(A.current),[]),x.useEffect(()=>{if(h!=="recent"||typeof window>"u")return;const he=new URLSearchParams(o.search);he.delete("scope");const me=he.toString(),ye=`${o.pathname}${me?`?${me}`:""}${o.hash}`;window.history.replaceState(window.history.state,"",ye)},[h,o.hash,o.pathname,o.search]),x.useEffect(()=>{if(!l.has("view")||typeof window>"u")return;const he=new URLSearchParams(o.search);he.delete("view");const me=he.toString(),ye=`${o.pathname}${me?`?${me}`:""}${o.hash}`;window.history.replaceState(window.history.state,"",ye)},[o.hash,o.pathname,o.search,l]);const{data:E}=ke({queryKey:U.agents.list(e),queryFn:()=>$t.list(e),enabled:!!e}),{data:I}=ke({queryKey:U.auth.session,queryFn:()=>Ri.getSession()}),O=((ie=I==null?void 0:I.user)==null?void 0:ie.id)??((ae=I==null?void 0:I.session)==null?void 0:ae.userId)??null,[M,D]=x.useState(()=>LA(e)),[z,F]=x.useState(()=>new Set),K=x.useRef(new Set),{followedIssueIds:J,toggleFollowIssue:$}=skt(e),L=x.useCallback((he,me)=>{const ye=new Set(K.current);me?ye.add(he):ye.delete(he),K.current=ye,F(ye)},[]),{data:H}=ke({queryKey:U.projects.list(e),queryFn:()=>gs.list(e),enabled:!!e}),{data:W}=ke({queryKey:U.liveRuns(e),queryFn:()=>us.liveRunsForCompany(e),enabled:!!e,refetchInterval:5e3}),B=x.useMemo(()=>{const he=new Set;for(const me of W??[])me.issueId&&he.add(me.issueId);return he},[W]),Y=x.useMemo(()=>f8("Issues",`${o.pathname}${o.search}${o.hash}`),[o.pathname,o.search,o.hash]);x.useEffect(()=>{n([{label:g?"Draft Issues":b?"Linear Issues":"Issue Tracker"}])},[g,b,n]),x.useEffect(()=>{const he=()=>{D(LA(e))};if(he(),!(typeof window>"u"))return window.addEventListener(eN,he),window.addEventListener("storage",he),()=>{window.removeEventListener(eN,he),window.removeEventListener("storage",he)}},[e]),x.useEffect(()=>{!e||w||g||b||O9e(e,{scope:m||void 0,projectId:k})},[m,g,b,w,k,e]);const P=x.useMemo(()=>f7e(m,O),[O,m]),{data:V,isLoading:ce,error:le}=ke({queryKey:[...U.issues.list(e),"participant-agent",w??"__all__","scope",m||"__default__","user",O??"__none__","project",k??"__all__"],queryFn:()=>fn.list(e,{participantAgentId:w,projectId:k,...P}),enabled:!!e&&!g&&!b}),G=x.useMemo(()=>{const he=V??[];return m==="starred"?he.filter(me=>J.has(me.id)):m==="following"&&O?he.filter(me=>Bde(me,O)):he},[O,m,J,V]),te=nt({mutationFn:({id:he,data:me})=>fn.update(he,me),onSuccess:()=>{c.invalidateQueries({queryKey:U.issues.list(e)})}}),ge=nt({mutationFn:he=>fn.reorder(e,he),onSuccess:()=>{c.invalidateQueries({queryKey:U.issues.list(e)})}});return e?g?i.jsx(dkt,{drafts:M,agents:E,projects:H,currentUserId:O,deletingDraftIds:z,onOpenDraft:he=>{r({draftId:he.id})},onDeleteDraft:async he=>{if(!await s({title:`Delete draft issue "${he.title}"?`,description:"This cannot be undone.",confirmLabel:"Delete",tone:"destructive"})||K.current.has(he.id))return;L(he.id,!0);const ye=()=>{t8(he.id),L(he.id,!1),a({title:"Draft issue deleted",tone:"success"})};if(ckt()){ye();return}window.setTimeout(ye,lkt)}}):b?i.jsx("div",{className:"flex h-full min-h-0 flex-col",children:i.jsx(nkt,{orgId:e,orgName:t==null?void 0:t.name,projects:H,linearTeamId:v,linearProjectId:j,initialSearch:u})}):i.jsx("div",{className:"flex h-full min-h-0 flex-col",children:i.jsx(Vwt,{issues:G,isLoading:ce,error:le,agents:E,projects:H,liveIssueIds:B,projectId:k,viewStateKey:"rudder:issues-view",issueLinkState:Y,initialAssignees:l.get("assignee")?[l.get("assignee")]:void 0,initialSearch:u,initialGroupBy:S,toolbarMode:"controls-only",starredIssueIds:[...J],onToggleStarredIssue:he=>{$(he)},onOpenIssue:he=>{e&&fF(e,he.id,E0(e))},onSearchChange:_,onUpdateIssue:(he,me)=>te.mutate({id:he,data:me}),onReorderIssue:he=>ge.mutate(he),searchFilters:w?{participantAgentId:w}:void 0})}):i.jsx(Er,{icon:pl,message:"Select a organization to view issues."})}const hkt="image/*,application/pdf,text/plain,text/markdown,application/json,text/csv,text/html,.md,.markdown",mkt=800;function pkt(e){return e==="done"}function gkt(e){try{return localStorage.getItem(e)??""}catch{return""}}function xkt(e,t){try{t.trim()?localStorage.setItem(e,t):localStorage.removeItem(e)}catch{}}function bkt(e){try{localStorage.removeItem(e)}catch{}}function Vne(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)?e:null}function ykt(e){var s;const t=Vne((s=Vne(e))==null?void 0:s.passiveFollowup),n=typeof(t==null?void 0:t.attempt)=="number"?t.attempt:null,r=typeof(t==null?void 0:t.maxAttempts)=="number"?t.maxAttempts:null;return t?n&&r?`Passive follow-up ${n}/${r}`:"Passive follow-up":null}function vkt(e){if(!e||e==="__none__")return{assigneeAgentId:null,assigneeUserId:null};if(e.startsWith("agent:")){const t=e.slice(6);return t?{assigneeAgentId:t,assigneeUserId:null}:null}if(e.startsWith("user:")){const t=e.slice(5);return t?{assigneeAgentId:null,assigneeUserId:t}:null}return null}function wkt({text:e}){const[t,n]=x.useState(!1);return i.jsx("button",{type:"button",className:"text-muted-foreground hover:text-foreground transition-colors",title:"Copy as markdown",onClick:()=>{navigator.clipboard.writeText(e).then(()=>{n(!0),setTimeout(()=>n(!1),2e3)})},children:t?i.jsx(ws,{className:"h-3 w-3"}):i.jsx(xi,{className:"h-3 w-3"})})}const kkt=x.memo(function({timeline:t,agentMap:n,orgId:r,projectId:s,highlightCommentId:a,runTranscriptById:o,runHasOutput:l,operatorDisplayName:c,skillReferences:u,emptyMessage:d}){return t.length===0?i.jsx("p",{className:"text-sm text-muted-foreground",children:d}):i.jsx("div",{className:"space-y-3",children:t.map(h=>{var b,v,j,k,w,N;if(h.kind==="activity")return i.jsx("div",{children:h.activity.node},`activity:${h.id}`);if(h.kind==="run"){const S=h.run,A=S.status==="queued"||S.status==="running",_=o.get(S.runId)??[],E=l(S.runId),I=ykt(S.contextSnapshot);return i.jsxs("div",{className:"overflow-hidden rounded-sm border border-border bg-accent/20 p-3",children:[i.jsxs("div",{className:"mb-3 flex items-start justify-between gap-3",children:[i.jsx(Rx,{to:`/agents/${S.agentId}`,className:"hover:underline",children:i.jsx(vl,{name:((b=n==null?void 0:n.get(S.agentId))==null?void 0:b.name)??S.agentId.slice(0,8),icon:(v=n==null?void 0:n.get(S.agentId))==null?void 0:v.icon,role:(j=n==null?void 0:n.get(S.agentId))==null?void 0:j.role,size:"sm"})}),i.jsx("div",{className:"shrink-0 text-right",children:i.jsx("span",{className:"block text-xs text-muted-foreground",children:pi(S.startedAt??S.createdAt)})})]}),i.jsxs("div",{className:"mb-3 flex flex-wrap items-center gap-2 text-xs",children:[i.jsx("span",{className:"text-muted-foreground",children:"Execution"}),i.jsx(Rx,{to:`/agents/${S.agentId}/runs/${S.runId}`,className:"inline-flex items-center rounded-md border border-border bg-accent/40 px-2 py-1 font-mono text-muted-foreground hover:bg-accent/60 hover:text-foreground transition-colors",children:S.runId.slice(0,8)}),i.jsx(yr,{status:S.status}),I&&i.jsx("span",{className:"rounded-md border border-amber-500/30 bg-amber-500/10 px-2 py-1 text-[11px] font-medium text-amber-700 dark:text-amber-300",children:I})]}),i.jsx("div",{className:"max-h-56 overflow-y-auto pr-1",children:i.jsx(Af,{entries:_,density:"compact",limit:4,streaming:A,collapseStdout:!0,emptyMessage:E?"Waiting for transcript parsing...":A?`Run ${S.status}. Waiting for output...`:"No run output captured."})})]},`run:${S.runId}`)}const m=h.comment,g=a===m.id;return i.jsxs("div",{id:`comment-${m.id}`,className:`border p-3 overflow-hidden min-w-0 rounded-sm transition-colors duration-1000 ${g?"border-primary/50 bg-primary/5":"border-border"}`,children:[i.jsxs("div",{className:"flex items-center justify-between mb-1",children:[m.authorAgentId?i.jsx(Rx,{to:`/agents/${m.authorAgentId}`,className:"hover:underline",children:i.jsx(vl,{name:((k=n==null?void 0:n.get(m.authorAgentId))==null?void 0:k.name)??m.authorAgentId.slice(0,8),icon:(w=n==null?void 0:n.get(m.authorAgentId))==null?void 0:w.icon,role:(N=n==null?void 0:n.get(m.authorAgentId))==null?void 0:N.role,size:"sm"})}):i.jsx(ao,{name:qU(c),size:"sm"}),i.jsxs("span",{className:"flex items-center gap-1.5",children:[r?i.jsx(Gh,{slotTypes:["commentContextMenuItem"],entityType:"comment",context:{orgId:r,projectId:s??null,entityId:m.id,entityType:"comment",parentEntityId:m.issueId},className:"flex flex-wrap items-center gap-1.5",itemClassName:"inline-flex",missingBehavior:"placeholder"}):null,i.jsx("a",{href:`#comment-${m.id}`,className:"text-xs text-muted-foreground hover:text-foreground hover:underline transition-colors",children:pi(m.createdAt)}),i.jsx(wkt,{text:m.body})]})]}),i.jsx(gi,{className:"text-sm",skillReferences:u,children:m.body}),r?i.jsx("div",{className:"mt-2 space-y-2",children:i.jsx(Gh,{slotTypes:["commentAnnotation"],entityType:"comment",context:{orgId:r,projectId:s??null,entityId:m.id,entityType:"comment",parentEntityId:m.issueId},className:"space-y-2",itemClassName:"rounded-md",missingBehavior:"placeholder"})}):null,m.runId&&i.jsx("div",{className:"mt-2 pt-2 border-t border-border/60",children:m.runAgentId?i.jsxs(Rx,{to:`/agents/${m.runAgentId}/runs/${m.runId}`,className:"inline-flex items-center rounded-md border border-border bg-accent/30 px-2 py-1 text-[10px] font-mono text-muted-foreground hover:text-foreground hover:bg-accent/50 transition-colors",children:["run ",m.runId.slice(0,8)]}):i.jsxs("span",{className:"inline-flex items-center rounded-md border border-border bg-accent/30 px-2 py-1 text-[10px] font-mono text-muted-foreground",children:["run ",m.runId.slice(0,8)]})})]},m.id)})})});function jkt({comments:e,linkedRuns:t=[],activityItems:n=[],orgId:r,projectId:s,onAdd:a,issueStatus:o,agentMap:l,imageUploadHandler:c,onAttachImage:u,draftKey:d,liveRunSlot:h,enableReassign:m=!1,reassignOptions:g=[],currentAssigneeValue:b="",suggestedAssigneeValue:v,mentions:j,operatorDisplayName:k,heading:w,hideHeading:N=!1,emptyMessage:S="No comments or runs yet.",escapeBackWhenEmpty:A=!1}){const[_,E]=x.useState(""),I=pkt(o),[O,M]=x.useState(I),[D,z]=x.useState(!1),[F,K]=x.useState(!1),J=v??b,[$,L]=x.useState(J),[H,W]=x.useState(null),B=x.useRef(null),Y=x.useRef(null),P=x.useRef(null),V=x.useRef(null),ce=Tn(),le=x.useRef(null),G=x.useRef(null),te=x.useMemo(()=>{const Re=e.map(oe=>({kind:"comment",id:oe.id,createdAtMs:new Date(oe.createdAt).getTime(),comment:oe})),Ue=t.map(oe=>({kind:"run",id:oe.runId,createdAtMs:new Date(oe.startedAt??oe.createdAt).getTime(),run:oe})),we=n.map(oe=>({kind:"activity",id:oe.id,createdAtMs:new Date(oe.createdAt).getTime(),activity:oe})),ze={activity:0,comment:1,run:2};return[...Re,...Ue,...we].sort((oe,xe)=>oe.createdAtMs!==xe.createdAtMs?oe.createdAtMs-xe.createdAtMs:oe.kind!==xe.kind?ze[oe.kind]-ze[xe.kind]:oe.kind===xe.kind?oe.id.localeCompare(xe.id):0)},[n,e,t]),ge=x.useMemo(()=>t.map(Re=>{var we;const Ue=l==null?void 0:l.get(Re.agentId);return{id:Re.runId,status:Re.status,invocationSource:"issue_timeline",triggerDetail:null,startedAt:typeof Re.startedAt=="string"?Re.startedAt:((we=Re.startedAt)==null?void 0:we.toISOString())??null,finishedAt:null,createdAt:typeof Re.createdAt=="string"?Re.createdAt:Re.createdAt.toISOString(),agentId:Re.agentId,agentName:(Ue==null?void 0:Ue.name)??Re.agentId.slice(0,8),agentRuntimeType:(Ue==null?void 0:Ue.agentRuntimeType)??"process",issueId:null}}),[l,t]),{transcriptByRun:ie,hasOutputForRun:ae}=lS({runs:ge,orgId:r,maxChunksPerRun:120}),he=x.useMemo(()=>j||(l?Array.from(l.values()).filter(Re=>Re.status!=="terminated").map(Re=>({id:`agent:${Re.id}`,name:zo(Re),kind:"agent",agentId:Re.id,agentIcon:Re.icon,agentRole:Re.role})):[]),[l,j]),me=x.useMemo(()=>he.filter(Re=>Re.kind==="skill"&&Re.skillMarkdownTarget).map(Re=>({href:Re.skillMarkdownTarget,label:Re.skillRefLabel??Re.name,displayName:Re.skillDisplayName??Re.name,description:Re.skillDescription,categoryLabel:Re.skillCategoryLabel,locationLabel:Re.skillLocationLabel,detailsHref:Re.skillDetailsHref})),[he]);x.useEffect(()=>{d&&E(gkt(d))},[d]),x.useEffect(()=>{d&&(V.current&&clearTimeout(V.current),V.current=setTimeout(()=>{xkt(d,_)},mkt))},[_,d]),x.useEffect(()=>()=>{V.current&&clearTimeout(V.current),G.current&&clearTimeout(G.current)},[]),x.useEffect(()=>{L(J)},[J]),x.useEffect(()=>{M(I)},[I]),x.useEffect(()=>{const Re=ce.hash;if(!Re.startsWith("#comment-")||e.length===0)return;const Ue=Re.slice(9),we=`${ce.key}:${Re}`;if(le.current===we)return;const ze=document.getElementById(`comment-${Ue}`);ze&&(le.current=we,G.current&&clearTimeout(G.current),W(Ue),ze.scrollIntoView({behavior:"smooth",block:"center"}),G.current=setTimeout(()=>{W(null),G.current=null},3e3))},[ce.hash,ce.key,e.length]);async function ye(){const Re=_.trim();if(!Re)return;const we=m&&$!==b?vkt($):null,ze=I&&O?!0:void 0;z(!0);try{await a(Re,ze,we??void 0),E(""),d&&bkt(d),M(I),L(J)}finally{z(!1)}}async function Me(Re){var we;const Ue=(we=Re.target.files)==null?void 0:we[0];if(Ue){K(!0);try{if(c){const ze=await c(Ue),oe=Ue.name.replace(/[[\]]/g,"\\$&"),xe=Ue.type.startsWith("image/")?`![${oe}](${ze})`:`[${oe}](${ze})`;E(X=>X?`${X}
1375
+ `);if(L!==$.status||G!==te){const ae={[L]:Y.map(me=>me.id)};L!==$.status&&(ae[$.status]=(A[$.status]??[]).filter(me=>me.id!==J).map(me=>me.id)),j({laneIdsByStatus:ae}),b(me=>{const ye=new Set(me);return ye.add(J),ye});const he=window.setTimeout(()=>{b(me=>{const ye=new Set(me);return ye.delete(J),ye}),w.current=w.current.filter(me=>me!==he)},520);w.current.push(he),d?d({issueId:J,targetStatus:L,previousIssueId:V,nextIssueId:ce,...le?{position:le}:{}}):L!==$.status&&u(J,{status:L})}}function D(z){}return i.jsxs(Q1e,{sensors:N,onDragStart:O,onDragOver:D,onDragEnd:M,children:[i.jsx("div",{className:"flex h-full min-h-0 flex-col",children:i.jsx("div",{ref:k,className:"scrollbar-auto-hide min-h-0 flex-1 overflow-x-auto overflow-y-hidden pb-3",children:i.jsxs("div",{className:"flex h-full min-h-full min-w-max items-stretch gap-3 pr-2",children:[_.map(z=>i.jsx(Awt,{status:z,issues:A[z]??[],agents:t,currentUserId:n,displayProperties:r,liveIssueIds:a,recentlyDroppedIssueIds:g,projects:o,onCreateIssue:l,onOpenIssue:c},z)),E.length>0?i.jsxs("div",{"data-testid":"kanban-hidden-columns",className:"flex h-full min-h-0 w-[228px] min-w-[228px] shrink-0 flex-col rounded-[calc(var(--radius-sm)+1px)] border border-[color:var(--border-base)] bg-[color:color-mix(in_oklab,var(--surface-inset)_78%,transparent)] p-2",children:[i.jsxs("div",{className:"mb-2 flex items-center gap-2 px-1",children:[i.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:"Hidden columns"}),i.jsx("span",{className:"ml-auto text-xs text-muted-foreground/60 tabular-nums",children:E.length})]}),i.jsx("div",{className:"space-y-2",children:E.map(z=>{var F;return i.jsx(Ewt,{status:z,issueCount:((F=A[z])==null?void 0:F.length)??0,onCreateIssue:l},z)})})]}):null]})})}),i.jsx(tht,{children:I?i.jsx(vje,{issue:I,agents:t,currentUserId:n,displayProperties:r,isOverlay:!0,projects:o}):null})]})}function Lne(e){return e.replace(/_/g," ").replace(/\b\w/g,t=>t.toUpperCase())}const wje=[{value:"identifier",label:"Identifier"},{value:"priority",label:"Priority"},{value:"assignee",label:"Assignee"},{value:"reviewer",label:"Reviewer"},{value:"labels",label:"Labels"},{value:"project",label:"Project"},{value:"updated",label:"Updated"},{value:"created",label:"Created"}],Iwt=new Set(wje.map(e=>e.value)),kje=[...gq],xq={statuses:[],priorities:[],assignees:[],labels:[],projects:[],displayProperties:kje,sortField:"updated",sortDir:"desc",groupBy:"none",viewMode:"board",collapsedGroups:[]},Rwt=[{label:"All",statuses:[]},{label:"Active",statuses:["todo","in_progress","in_review","blocked"]},{label:"Backlog",statuses:["backlog"]},{label:"Done",statuses:["done","cancelled"]}],Mwt="Getting Started",Owt=["welcome","core","recommended","advanced","other"],$ne={welcome:{label:"Welcome",description:"Reference issue for Rudder’s collaboration model."},core:{label:"Core loop",description:"Complete these issues to experience chat → issue → execution → review → project context."},recommended:{label:"Recommended next",description:"Bring real context and one real task into Rudder."},advanced:{label:"Advanced",description:"Optional next steps for goals, reusable workflows, agent roles, and recurring loops."},other:{label:"Other",description:"Additional issues in this project."}};function Dwt(e){return e.title.startsWith("👋 Welcome to Rudder")?"welcome":/^[1-5]\./.test(e.title)?"core":/^[6-7]\./.test(e.title)?"recommended":/^(?:[8-9]|10|11)\./.test(e.title)?"advanced":"other"}function Fne(e){if(e.title.startsWith("👋 Welcome to Rudder"))return 0;const t=/^(\d+)\./.exec(e.title);return t?Number(t[1]):99}function Pwt(e){return[...e].sort((t,n)=>{const r=Fne(t)-Fne(n);return r!==0?r:t.title.localeCompare(n.title)})}function Lwt(e){try{const t=localStorage.getItem(e);if(t){const n=JSON.parse(t);return zwt(n)}}catch{}return{...xq}}function $wt(e,t){localStorage.setItem(e,JSON.stringify(t))}function Fwt(e){if(!Array.isArray(e))return[...kje];const t=new Set,n=[];for(const r of e){if(!Iwt.has(r))continue;const s=r;t.has(s)||(t.add(s),n.push(s))}return n}function zwt(e){return{...xq,...e,statuses:Array.isArray(e.statuses)?[...e.statuses]:[],priorities:Array.isArray(e.priorities)?[...e.priorities]:[],assignees:Array.isArray(e.assignees)?[...e.assignees]:[],labels:Array.isArray(e.labels)?[...e.labels]:[],projects:Array.isArray(e.projects)?[...e.projects]:[],collapsedGroups:Array.isArray(e.collapsedGroups)?[...e.collapsedGroups]:[],displayProperties:Fwt(e.displayProperties)}}function Bwt(e,t){if(e.length!==t.length)return!1;const n=[...e].sort(),r=[...t].sort();return n.every((s,a)=>s===r[a])}function Xm(e,t){return e.includes(t)?e.filter(n=>n!==t):[...e,t]}function Uwt(e,t,n){let r=e;return t.statuses.length>0&&(r=r.filter(s=>t.statuses.includes(s.status))),t.priorities.length>0&&(r=r.filter(s=>t.priorities.includes(s.priority))),t.assignees.length>0&&(r=r.filter(s=>{for(const a of t.assignees)if(a==="__unassigned"&&!s.assigneeAgentId&&!s.assigneeUserId||a==="__me"&&n&&s.assigneeUserId===n||s.assigneeAgentId===a)return!0;return!1})),t.labels.length>0&&(r=r.filter(s=>(s.labelIds??[]).some(a=>t.labels.includes(a)))),t.projects.length>0&&(r=r.filter(s=>s.projectId!=null&&t.projects.includes(s.projectId))),r}function qwt(e){let t=0;return e.statuses.length>0&&t++,e.priorities.length>0&&t++,e.assignees.length>0&&t++,e.labels.length>0&&t++,e.projects.length>0&&t++,t}function Vwt({issues:e,isLoading:t,error:n,agents:r,projects:s,liveIssueIds:a,projectId:o,viewStateKey:l,issueLinkState:c,initialAssignees:u,initialSearch:d,initialGroupBy:h,toolbarMode:m="full",starredIssueIds:g=[],onToggleStarredIssue:b,onOpenIssue:v,searchFilters:j,onSearchChange:k,onUpdateIssue:w,onReorderIssue:N}){var ue,je;const{selectedOrganizationId:S}=bn(),{openNewIssue:A}=Gr(),{data:_}=ke({queryKey:U.auth.session,queryFn:()=>Ri.getSession()}),E=((ue=_==null?void 0:_.user)==null?void 0:ue.id)??((je=_==null?void 0:_.session)==null?void 0:je.userId)??null,I=S?`${l}:${S}`:l,O=x.useCallback(()=>{const re=u?{...xq,assignees:u,statuses:[]}:Lwt(I);return h?{...re,groupBy:h}:re},[u,h,I]),[M,D]=x.useState(()=>O()),[z,F]=x.useState(null),[K,J]=x.useState(""),[$,L]=x.useState(d??""),[H,W]=x.useState($),B=di(),Y=di(),P=di(),V=di(),ce=H.trim();x.useEffect(()=>{L(d??"")},[d]),x.useEffect(()=>{const re=window.setTimeout(()=>{W($)},300);return()=>window.clearTimeout(re)},[$]);const le=x.useRef(I);x.useEffect(()=>{le.current!==I&&(le.current=I,D(O()))},[O,I]);const G=x.useCallback(re=>{D(fe=>{const ne={...fe,...re};return $wt(I,ne),ne})},[I]),{data:te=[]}=ke({queryKey:[...U.issues.search(S,ce,o),j??{}],queryFn:()=>fn.list(S,{q:ce,projectId:o,...j}),enabled:!!S&&ce.length>0}),ge=x.useMemo(()=>new Map((r??[]).map(re=>[re.id,re])),[r]),ie=x.useCallback(re=>{if(!re)return null;const fe=ge.get(re);return fe?zo(fe):null},[ge]),ae=x.useMemo(()=>{const re=ce.length>0?te:e,fe=Uwt(re,M,E);return bje(fe,M)},[e,te,M,ce,E]),{data:he}=ke({queryKey:U.issues.labels(S),queryFn:()=>fn.listLabels(S),enabled:!!S}),me=qwt(M),ye=x.useMemo(()=>{var re;return((re=s==null?void 0:s.find(fe=>fe.id===o))==null?void 0:re.name)??null},[o,s]),Me=ye===Mwt,$e=x.useMemo(()=>ce.length>0?`No issues match “${ce}”. Try a different search or clear some filters.`:me>0?"No issues match the current filters. Adjust the filters or clear them to see more work.":ye?`${ye} does not have any issues yet. Create the first issue for this project.`:"There are no issues yet. Create one to start tracking work here.",[me,ce,ye]),Re=ce.length===0&&me===0?"New Issue":void 0,Ue=x.useMemo(()=>ye&&ce.length===0&&me===0?`${ye} does not have any issues yet. Use a lane + button to create the first one in the right status.`:ce.length>0||me>0?"No issues match the current board. Use a lane + button to create a new issue in the right status. Clear search or filters if it does not appear.":"No issues match the current board. Use a lane + button to create a new issue in the right status.",[me,ce,ye]),we=x.useMemo(()=>{var fe;if(Me&&M.groupBy==="none"){const ne=Ak(ae,Dwt);return Owt.filter(Fe=>{var Ce;return(Ce=ne[Fe])==null?void 0:Ce.length}).map(Fe=>({key:`onboarding:${Fe}`,label:$ne[Fe].label,description:$ne[Fe].description,items:Pwt(ne[Fe])}))}if(M.groupBy==="none")return[{key:"__all",label:null,items:ae}];if(M.groupBy==="status"){const ne=Ak(ae,Fe=>Fe.status);return bT.filter(Fe=>{var Ce;return(Ce=ne[Fe])==null?void 0:Ce.length}).map(Fe=>({key:Fe,label:Lne(Fe),items:ne[Fe]}))}if(M.groupBy==="priority"){const ne=Ak(ae,Fe=>Fe.priority);return yT.filter(Fe=>{var Ce;return(Ce=ne[Fe])==null?void 0:Ce.length}).map(Fe=>({key:Fe,label:Ho(Fe),items:ne[Fe]}))}if(M.groupBy==="project"){const ne=Ak(ae,Ce=>Ce.projectId??"__no_project"),Fe=(s??[]).filter(Ce=>{var tt;return(tt=ne[Ce.id])==null?void 0:tt.length}).map(Ce=>({key:Ce.id,label:Ce.name,items:ne[Ce.id]}));return(fe=ne.__no_project)!=null&&fe.length&&Fe.push({key:"__no_project",label:"Unscoped",items:ne.__no_project}),Fe}const re=Ak(ae,ne=>ne.assigneeAgentId??(ne.assigneeUserId?`__user:${ne.assigneeUserId}`:"__unassigned"));return Object.keys(re).map(ne=>({key:ne,label:ne==="__unassigned"?"Unassigned":ne.startsWith("__user:")?Ec(ne.slice(7),E)??"User":ie(ne)??ne.slice(0,8),items:re[ne]}))},[ie,E,ae,Me,s,M.groupBy]),ze=x.useMemo(()=>{const re={};if(o?re.projectId=o:M.projects.length===1&&(re.projectId=M.projects[0]),M.priorities.length===1&&(re.priority=M.priorities[0]),M.labels.length>0&&(re.labelIds=[...M.labels]),M.assignees.length===1){const fe=M.assignees[0];fe==="__me"&&E?re.assigneeUserId=E:fe!=="__unassigned"&&(re.assigneeAgentId=fe)}return re},[E,o,M.assignees,M.labels,M.priorities,M.projects]),oe=re=>{const fe={...ze};return re&&(M.groupBy==="status"?fe.status=re:M.groupBy==="priority"?fe.priority=re:M.groupBy==="project"&&re!=="__no_project"?fe.projectId=re:M.groupBy==="assignee"&&re!=="__unassigned"&&(re.startsWith("__user:")?fe.assigneeUserId=re.slice(7):fe.assigneeAgentId=re)),fe},xe=(re,fe,ne=null)=>{w(re,{assigneeAgentId:fe,assigneeUserId:ne}),F(null),J("")},X=re=>{if(!N){w(re.issueId,{status:re.targetStatus});return}(M.sortField!=="manual"||M.sortDir!=="asc")&&G({sortField:"manual",sortDir:"asc"}),N(re)},q=re=>{F(fe=>fe===re?null:re),J("")};return i.jsxs("div",{className:"flex h-full min-h-0 flex-col gap-4",children:[m!=="hidden"&&i.jsxs("div",{"data-testid":"issues-view-toolbar",className:"surface-panel flex items-center justify-between gap-2 rounded-[calc(var(--radius-sm)+1px)] px-3 py-3 sm:gap-3",children:[i.jsx("div",{className:"flex min-w-0 items-center gap-2 sm:gap-3",children:m==="full"?i.jsxs(i.Fragment,{children:[i.jsxs(de,{size:"sm",variant:"outline",onClick:()=>A(oe()),children:[i.jsx(Hn,{className:"h-4 w-4 sm:mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:"New Issue"})]}),i.jsxs("div",{className:"relative w-48 sm:w-64 md:w-80",children:[i.jsx(Ro,{className:"pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),i.jsx(An,{value:$,onChange:re=>{L(re.target.value),k==null||k(re.target.value)},placeholder:"Search issues...",className:"pl-7 text-xs sm:text-sm","aria-label":"Search issues"})]})]}):i.jsx("div",{className:"flex min-w-0 items-center gap-2",children:i.jsx("div",{className:"truncate text-xs font-medium uppercase tracking-[0.18em] text-muted-foreground",children:"Issues"})})}),i.jsxs("div",{className:"flex items-center gap-0.5 sm:gap-1 shrink-0",children:[i.jsxs("div",{className:"mr-1 flex items-center overflow-hidden rounded-[var(--radius-sm)] border border-[color:var(--border-base)] bg-[color:color-mix(in_oklab,var(--surface-inset)_82%,transparent)]",children:[i.jsx("button",{className:`p-1.5 transition-colors ${M.viewMode==="list"?"bg-[color:var(--surface-active)] text-foreground":"text-muted-foreground hover:text-foreground"}`,onClick:()=>G({viewMode:"list"}),title:"List view",children:i.jsx(J7,{className:"h-3.5 w-3.5"})}),i.jsx("button",{className:`p-1.5 transition-colors ${M.viewMode==="board"?"bg-[color:var(--surface-active)] text-foreground":"text-muted-foreground hover:text-foreground"}`,onClick:()=>G({viewMode:"board"}),title:"Board view",children:i.jsx(Gue,{className:"h-3.5 w-3.5"})})]}),i.jsxs(cr,{children:[i.jsx(mr,{asChild:!0,children:i.jsxs(de,{variant:"ghost",size:"sm",className:`text-xs ${me>0?"text-[color:var(--accent-strong)]":""}`,children:[i.jsx(VL,{className:"h-3.5 w-3.5 sm:h-3 sm:w-3 sm:mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:me>0?`Filters: ${me}`:"Filter"}),me>0&&i.jsx("span",{className:"sm:hidden text-[10px] font-medium ml-0.5",children:me}),me>0&&i.jsx(ti,{className:"h-3 w-3 ml-1 hidden sm:block",onClick:re=>{re.stopPropagation(),G({statuses:[],priorities:[],assignees:[],labels:[],projects:[]})}})]})}),i.jsx(ur,{align:"end",className:"w-[min(480px,calc(100vw-2rem))] p-0",children:i.jsxs("div",{className:"p-3 space-y-3",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("span",{className:"text-sm font-medium",children:"Filters"}),me>0&&i.jsx("button",{className:"text-xs text-muted-foreground hover:text-foreground",onClick:()=>G({statuses:[],priorities:[],assignees:[],labels:[],projects:[]}),children:"Clear"})]}),i.jsxs("div",{className:"space-y-1.5",children:[i.jsx("span",{className:"text-xs text-muted-foreground",children:"Quick filters"}),i.jsx("div",{className:"flex flex-wrap gap-1.5",children:Rwt.map(re=>{const fe=Bwt(M.statuses,re.statuses);return i.jsx("button",{className:`px-2.5 py-1 text-xs rounded-[calc(var(--radius-sm)-1px)] border transition-colors ${fe?"bg-primary text-primary-foreground border-primary":"border-[color:var(--border-base)] text-muted-foreground hover:text-foreground hover:border-[color:var(--border-strong)]"}`,onClick:()=>G({statuses:fe?[]:[...re.statuses]}),children:re.label},re.label)})})]}),i.jsx("div",{className:"border-t panel-divider"}),i.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-x-4 gap-y-3",children:[i.jsxs("div",{className:"space-y-1",children:[i.jsx("span",{className:"text-xs text-muted-foreground",children:"Status"}),i.jsx("div",{className:"space-y-0.5",children:bT.map(re=>i.jsxs("label",{className:"flex items-center gap-2 px-2 py-1 rounded-sm hover:bg-accent/50 cursor-pointer",children:[i.jsx(To,{checked:M.statuses.includes(re),onCheckedChange:()=>G({statuses:Xm(M.statuses,re)})}),i.jsx(Ws,{status:re}),i.jsx("span",{className:"text-sm",children:Lne(re)})]},re))})]}),i.jsxs("div",{className:"space-y-3",children:[i.jsxs("div",{className:"space-y-1",children:[i.jsx("span",{className:"text-xs text-muted-foreground",children:"Priority"}),i.jsx("div",{className:"space-y-0.5",children:yT.map(re=>i.jsxs("label",{className:"flex items-center gap-2 px-2 py-1 rounded-sm hover:bg-accent/50 cursor-pointer",children:[i.jsx(To,{checked:M.priorities.includes(re),onCheckedChange:()=>G({priorities:Xm(M.priorities,re)})}),i.jsx(gc,{priority:re}),i.jsx("span",{className:"text-sm",children:Ho(re)})]},re))})]}),i.jsxs("div",{className:"space-y-1",children:[i.jsx("span",{className:"text-xs text-muted-foreground",children:"Assignee"}),i.jsxs("div",{ref:B,"data-testid":"issues-filter-assignee-scroll",className:"scrollbar-auto-hide space-y-0.5 max-h-32 overflow-y-auto",children:[i.jsxs("label",{className:"flex items-center gap-2 px-2 py-1 rounded-sm hover:bg-accent/50 cursor-pointer",children:[i.jsx(To,{checked:M.assignees.includes("__unassigned"),onCheckedChange:()=>G({assignees:Xm(M.assignees,"__unassigned")})}),i.jsx("span",{className:"text-sm",children:"No assignee"})]}),E&&i.jsxs("label",{className:"flex items-center gap-2 px-2 py-1 rounded-sm hover:bg-accent/50 cursor-pointer",children:[i.jsx(To,{checked:M.assignees.includes("__me"),onCheckedChange:()=>G({assignees:Xm(M.assignees,"__me")})}),i.jsx(Nf,{className:"h-3.5 w-3.5 text-muted-foreground"}),i.jsx("span",{className:"text-sm",children:"Me"})]}),(r??[]).map(re=>i.jsxs("label",{className:"flex items-center gap-2 px-2 py-1 rounded-sm hover:bg-accent/50 cursor-pointer",children:[i.jsx(To,{checked:M.assignees.includes(re.id),onCheckedChange:()=>G({assignees:Xm(M.assignees,re.id)})}),i.jsx(ks,{icon:re.icon,role:re.role,className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),i.jsx("span",{className:"text-sm",children:zo(re)})]},re.id))]})]}),he&&he.length>0&&i.jsxs("div",{className:"space-y-1",children:[i.jsx("span",{className:"text-xs text-muted-foreground",children:"Labels"}),i.jsx("div",{ref:Y,"data-testid":"issues-filter-labels-scroll",className:"scrollbar-auto-hide space-y-0.5 max-h-32 overflow-y-auto",children:he.map(re=>i.jsxs("label",{className:"flex items-center gap-2 px-2 py-1 rounded-sm hover:bg-accent/50 cursor-pointer",children:[i.jsx(To,{checked:M.labels.includes(re.id),onCheckedChange:()=>G({labels:Xm(M.labels,re.id)})}),i.jsx("span",{className:"h-2.5 w-2.5 rounded-full",style:{backgroundColor:re.color}}),i.jsx("span",{className:"text-sm",children:re.name})]},re.id))})]}),s&&s.length>0&&i.jsxs("div",{className:"space-y-1",children:[i.jsx("span",{className:"text-xs text-muted-foreground",children:"Project"}),i.jsx("div",{ref:P,"data-testid":"issues-filter-projects-scroll",className:"scrollbar-auto-hide space-y-0.5 max-h-32 overflow-y-auto",children:s.map(re=>i.jsxs("label",{className:"flex items-center gap-2 px-2 py-1 rounded-sm hover:bg-accent/50 cursor-pointer",children:[i.jsx(To,{checked:M.projects.includes(re.id),onCheckedChange:()=>G({projects:Xm(M.projects,re.id)})}),i.jsx("span",{className:"text-sm",children:re.name})]},re.id))})]})]})]})]})})]}),i.jsxs(cr,{children:[i.jsx(mr,{asChild:!0,children:i.jsxs(de,{variant:"ghost",size:"sm",className:"text-xs",children:[i.jsx(zL,{className:"h-3.5 w-3.5 sm:h-3 sm:w-3 sm:mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:"Sort"})]})}),i.jsx(ur,{align:"end",className:"w-48 p-0",children:i.jsx("div",{className:"p-2 space-y-0.5",children:kwt.map(re=>i.jsxs("button",{className:`flex items-center justify-between w-full px-2 py-1.5 text-sm rounded-sm ${M.sortField===re.value?"bg-accent/50 text-foreground":"hover:bg-accent/50 text-muted-foreground"}`,onClick:()=>{M.sortField===re.value?G({sortDir:M.sortDir==="asc"?"desc":"asc"}):G({sortField:re.value,sortDir:"asc"})},children:[i.jsx("span",{children:re.label}),M.sortField===re.value&&i.jsx("span",{className:"text-xs text-muted-foreground",children:M.sortDir==="asc"?"↑":"↓"})]},re.value))})})]}),M.viewMode==="board"&&i.jsxs(cr,{children:[i.jsx(mr,{asChild:!0,children:i.jsxs(de,{variant:"ghost",size:"sm",className:"text-xs",children:[i.jsx(yC,{className:"h-3.5 w-3.5 sm:h-3 sm:w-3 sm:mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:"Display"})]})}),i.jsx(ur,{align:"end",className:"w-52 p-0",children:i.jsx("div",{className:"p-2 space-y-0.5",children:wje.map(re=>i.jsxs("label",{className:"flex cursor-pointer items-center gap-2 rounded-sm px-2 py-1.5 text-sm hover:bg-accent/50",children:[i.jsx(To,{checked:M.displayProperties.includes(re.value),onCheckedChange:()=>G({displayProperties:Xm(M.displayProperties,re.value)})}),i.jsx("span",{children:re.label})]},re.value))})})]}),M.viewMode==="list"&&i.jsxs(cr,{children:[i.jsx(mr,{asChild:!0,children:i.jsxs(de,{variant:"ghost",size:"sm",className:"text-xs",children:[i.jsx(Q7,{className:"h-3.5 w-3.5 sm:h-3 sm:w-3 sm:mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:"Group"})]})}),i.jsx(ur,{align:"end",className:"w-44 p-0",children:i.jsx("div",{className:"p-2 space-y-0.5",children:[["status","Status"],["priority","Priority"],["assignee","Assignee"],["project","Project"],["none","None"]].map(([re,fe])=>i.jsxs("button",{className:`flex items-center justify-between w-full px-2 py-1.5 text-sm rounded-sm ${M.groupBy===re?"bg-accent/50 text-foreground":"hover:bg-accent/50 text-muted-foreground"}`,onClick:()=>G({groupBy:re}),children:[i.jsx("span",{children:fe}),M.groupBy===re&&i.jsx(ws,{className:"h-3.5 w-3.5"})]},re))})})]})]})]}),t&&i.jsx(Is,{variant:"issues-list"}),n&&i.jsx("p",{className:"text-sm text-destructive",children:n.message}),!t&&ae.length===0&&M.viewMode!=="board"&&i.jsx("div",{className:"flex min-h-[58vh] items-center justify-center",children:i.jsx(Er,{icon:pl,message:$e,action:Re,onAction:Re?()=>A(oe()):void 0})}),!t&&M.viewMode==="board"&&i.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[ae.length===0?i.jsx("div",{className:"mb-3 rounded-[calc(var(--radius-sm)+1px)] border border-dashed border-[color:var(--border-base)] bg-[color:color-mix(in_oklab,var(--surface-inset)_82%,transparent)] px-4 py-3 text-sm text-muted-foreground",children:Ue}):null,i.jsx(Twt,{issues:ae,agents:r,currentUserId:E,displayProperties:M.displayProperties,sortState:{sortField:M.sortField,sortDir:M.sortDir},liveIssueIds:a,projects:s,onCreateIssue:re=>A({...ze,status:re}),onOpenIssue:v,onUpdateIssue:w,onReorderIssue:X})]}),!t&&ae.length>0&&M.viewMode!=="board"&&we.map(re=>i.jsxs(fy,{open:!M.collapsedGroups.includes(re.key),onOpenChange:fe=>{G({collapsedGroups:fe?M.collapsedGroups.filter(ne=>ne!==re.key):[...M.collapsedGroups,re.key]})},children:[re.label&&i.jsxs("div",{className:"flex items-center py-1.5 pl-1 pr-3",children:[i.jsxs(ZI,{className:"flex items-center gap-1.5",children:[i.jsx(Us,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground transition-transform [[data-state=open]>&]:rotate-90"}),i.jsxs("span",{className:"flex flex-col items-start gap-0.5 text-left",children:[i.jsx("span",{className:"text-sm font-semibold uppercase tracking-[0.18em] text-muted-foreground",children:re.label}),re.description?i.jsx("span",{className:"max-w-[68ch] text-xs font-normal normal-case tracking-normal text-muted-foreground/80",children:re.description}):null]})]}),i.jsx(de,{variant:"ghost",size:"icon-xs",className:"ml-auto text-muted-foreground",onClick:()=>A(oe(re.key)),children:i.jsx(Hn,{className:"h-3 w-3"})})]}),i.jsx(hy,{children:re.items.map(fe=>{var ne,Fe;return i.jsx(wwt,{issue:fe,issueLinkState:c,desktopLeadingSpacer:!0,mobileLeading:i.jsx("span",{onClick:Ce=>{Ce.preventDefault(),Ce.stopPropagation()},children:i.jsx(Ws,{status:fe.status,onChange:Ce=>w(fe.id,{status:Ce})})}),desktopMetaLeading:i.jsxs(i.Fragment,{children:[i.jsx("span",{className:"hidden shrink-0 sm:inline-flex",onClick:Ce=>{Ce.preventDefault(),Ce.stopPropagation()},children:i.jsx(Ws,{status:fe.status,onChange:Ce=>w(fe.id,{status:Ce})})}),i.jsx("span",{className:"shrink-0 font-mono text-xs text-muted-foreground",children:fe.identifier??fe.id.slice(0,8)}),(a==null?void 0:a.has(fe.id))&&i.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full border border-[color:var(--border-soft)] bg-[color:color-mix(in_oklab,var(--surface-proposal)_80%,transparent)] px-1.5 py-0.5 sm:gap-1.5 sm:px-2",children:[i.jsxs("span",{className:"relative flex h-2 w-2",children:[i.jsx("span",{className:"absolute inline-flex h-full w-full animate-pulse rounded-full bg-[color:var(--accent-base)] opacity-75"}),i.jsx("span",{className:"relative inline-flex h-2 w-2 rounded-full bg-[color:var(--accent-strong)]"})]}),i.jsx("span",{className:"hidden text-[11px] font-medium text-[color:var(--accent-strong)] sm:inline",children:"Live"})]})]}),mobileMeta:du(fe.updatedAt),desktopTrailing:i.jsxs(i.Fragment,{children:[b?i.jsx("button",{type:"button",className:"rounded p-1 text-muted-foreground transition-colors hover:bg-accent/50 hover:text-foreground",onClick:Ce=>{Ce.preventDefault(),Ce.stopPropagation(),b(fe.id)},title:g.includes(fe.id)?"Unstar issue":"Star issue",children:i.jsx(fde,{className:Q("h-3.5 w-3.5",g.includes(fe.id)&&"fill-current text-amber-500")})}):null,(fe.labels??[]).length>0&&i.jsxs("span",{className:"hidden items-center gap-1 overflow-hidden md:flex md:max-w-[240px]",children:[(fe.labels??[]).slice(0,3).map(Ce=>i.jsx(UI,{label:Ce},Ce.id)),(fe.labels??[]).length>3&&i.jsxs("span",{className:"text-[10px] text-muted-foreground",children:["+",(fe.labels??[]).length-3]})]}),i.jsxs(cr,{open:z===fe.id,onOpenChange:Ce=>{F(Ce?fe.id:null),Ce||J("")},children:[i.jsx(k7e,{asChild:!0,children:i.jsx("button",{type:"button",className:"flex w-[180px] shrink-0 items-center rounded-md px-2 py-1 transition-colors hover:bg-accent/50",onClick:Ce=>{Ce.preventDefault(),Ce.stopPropagation(),q(fe.id)},children:fe.assigneeAgentId&&ge.get(fe.assigneeAgentId)?i.jsx(no,{kind:"agent",label:ge.get(fe.assigneeAgentId).name,badgeLabel:Eb(ge.get(fe.assigneeAgentId)),agentIcon:(ne=ge.get(fe.assigneeAgentId))==null?void 0:ne.icon,agentRole:(Fe=ge.get(fe.assigneeAgentId))==null?void 0:Fe.role}):fe.assigneeUserId?i.jsx(no,{kind:"user",label:Ec(fe.assigneeUserId,E)??"User"}):i.jsx(no,{kind:"unassigned",label:"Assignee",muted:!0})})}),i.jsxs(ur,{className:"w-56 p-1",align:"end",onClick:Ce=>Ce.stopPropagation(),onPointerDownOutside:()=>J(""),children:[i.jsx("input",{className:"mb-1 w-full border-b border-border bg-transparent px-2 py-1.5 text-xs outline-none placeholder:text-muted-foreground/50",placeholder:"Search assignees...",value:K,onChange:Ce=>J(Ce.target.value),autoFocus:!0}),i.jsxs("div",{ref:V,"data-testid":"issue-row-assignee-picker-scroll",className:"scrollbar-auto-hide max-h-48 overflow-y-auto overscroll-contain",children:[i.jsx("button",{className:Q("flex w-full items-center gap-2 rounded px-2 py-1.5 text-xs hover:bg-accent/50",!fe.assigneeAgentId&&!fe.assigneeUserId&&"bg-accent"),onClick:Ce=>{Ce.preventDefault(),Ce.stopPropagation(),xe(fe.id,null,null)},children:i.jsx(no,{kind:"unassigned",label:"No assignee"})}),E&&i.jsx("button",{className:Q("flex w-full items-center gap-2 rounded px-2 py-1.5 text-left text-xs hover:bg-accent/50",fe.assigneeUserId===E&&"bg-accent"),onClick:Ce=>{Ce.preventDefault(),Ce.stopPropagation(),xe(fe.id,null,E)},children:i.jsx(no,{kind:"user",label:"Me"})}),(r??[]).filter(Ce=>K.trim()?`${zo(Ce)} ${Ce.name} ${Ce.role} ${Ce.title??""}`.toLowerCase().includes(K.toLowerCase()):!0).map(Ce=>i.jsx("button",{className:Q("flex w-full items-center gap-2 rounded px-2 py-1.5 text-left text-xs hover:bg-accent/50",fe.assigneeAgentId===Ce.id&&"bg-accent"),onClick:tt=>{tt.preventDefault(),tt.stopPropagation(),xe(fe.id,Ce.id,null)},children:i.jsx(no,{kind:"agent",label:Ce.name,badgeLabel:Eb(Ce),agentIcon:Ce.icon,agentRole:Ce.role,className:"min-w-0"})},Ce.id))]})]})]})]}),trailingMeta:po(fe.createdAt),onOpen:()=>v==null?void 0:v(fe)},fe.id)})})]},re.key))]})}const Zk="rudder.linear",zne="page-bootstrap",Bne="linear-catalog",CP="linear-issues",Hwt="import-linear-issues",Kwt=50,SP=["backlog","todo","in_progress","in_review","blocked","done","cancelled"],jje={backlog:"border-[color:color-mix(in_oklab,var(--border-soft)_88%,transparent)] bg-[color:color-mix(in_oklab,var(--surface-inset)_88%,transparent)]",todo:"border-blue-200/75 bg-blue-50/70 dark:border-blue-900/55 dark:bg-blue-950/24",in_progress:"border-amber-200/75 bg-amber-50/70 dark:border-amber-900/55 dark:bg-amber-950/24",in_review:"border-violet-200/75 bg-violet-50/70 dark:border-violet-900/55 dark:bg-violet-950/24",blocked:"border-red-200/75 bg-red-50/70 dark:border-red-900/55 dark:bg-red-950/24",done:"border-emerald-200/75 bg-emerald-50/70 dark:border-emerald-900/55 dark:bg-emerald-950/24",cancelled:"border-neutral-200/75 bg-neutral-50/70 dark:border-neutral-800/60 dark:bg-neutral-900/26"};function Wwt(e){return(e==null?void 0:e.find(t=>t.pluginKey===Zk))??null}function Nje(e){return e.replace(/_/g," ").replace(/\b\w/g,t=>t.toUpperCase())}function Gwt(e){const t=[`Imported ${e.importedCount}`];return e.duplicateCount>0&&t.push(`${e.duplicateCount} duplicate`),e.fallbackCount>0&&t.push(`${e.fallbackCount} fallback`),e.adjustedCount>0&&t.push(`${e.adjustedCount} adjusted`),t.join(" / ")}function s5(e){return Q("h-9 min-w-0 rounded-[calc(var(--radius-sm)-1px)] border border-[color:var(--border-base)] bg-[color:var(--surface-elevated)] px-2.5 text-sm text-foreground outline-none transition-[border-color,box-shadow] focus:border-ring focus:ring-[3px] focus:ring-ring/40 disabled:cursor-not-allowed disabled:opacity-50",e)}function Qwt(){if(typeof window>"u")return"board";const e=window.localStorage.getItem("rudder:linear-source-view-mode");return e==="list"||e==="board"?e:"board"}function Ywt(e,t){var r;const n=t==null?void 0:t.find(s=>s.teamId===e.team.id);return((r=n==null?void 0:n.stateMappings.find(s=>s.linearStateId===e.state.id))==null?void 0:r.rudderStatus)??"backlog"}function Une(e,t){const n=e?Date.parse(e):0,r=t?Date.parse(t):0;return n-r}function Jwt(e){const t=e.importedRudderIssueIdentifier??e.importedRudderIssueId;return t?`/issues/${t}`:null}function _P({label:e,children:t,className:n}){return i.jsxs("label",{className:Q("flex min-w-0 flex-col gap-1",n),children:[i.jsx("span",{className:"text-[11px] font-medium text-muted-foreground",children:e}),t]})}function Cje(){return i.jsxs("span",{className:"inline-flex items-center gap-1 rounded-[calc(var(--radius-sm)-2px)] border border-emerald-300/60 bg-emerald-50 px-1.5 py-0.5 text-[11px] font-medium text-emerald-700 dark:border-emerald-900/60 dark:bg-emerald-950/28 dark:text-emerald-300",children:[i.jsx(ws,{className:"h-3 w-3"}),"Imported"]})}function Zwt({row:e}){var t,n;return i.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-x-3 gap-y-1 text-xs text-muted-foreground",children:[i.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1",children:[i.jsx(Ws,{status:Sje(e.state.type)}),i.jsx("span",{className:"truncate",children:e.state.name})]}),i.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1",children:[i.jsx(v1,{className:"h-3 w-3 shrink-0"}),i.jsx("span",{className:"truncate",children:((t=e.project)==null?void 0:t.name)??"No Linear project"})]}),i.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1",children:[i.jsx(Iv,{className:"h-3 w-3 shrink-0"}),i.jsx("span",{className:"truncate",children:((n=e.assignee)==null?void 0:n.name)??"Unassigned"})]}),i.jsxs("span",{children:["Updated ",du(e.updatedAt)]})]})}function Sje(e){return e==="started"?"in_progress":e==="completed"?"done":e==="canceled"?"cancelled":e==="backlog"?"backlog":"todo"}function _je({row:e,orgId:t}){if(!e.imported)return null;const n=Jwt(e),r=!e.importedOrgId||e.importedOrgId===t;return n&&r?i.jsx(de,{asChild:!0,variant:"ghost",size:"sm",children:i.jsx(Nt,{to:n,children:"Open issue"})}):i.jsx("span",{className:"text-xs text-muted-foreground",children:"Imported elsewhere"})}function Xwt({rows:e,selectedIssueIds:t,orgId:n,importing:r,onToggleSelected:s}){return i.jsx("div",{className:"min-h-0 overflow-hidden rounded-[calc(var(--radius-sm)+1px)] border border-[color:var(--border-base)] bg-[color:var(--surface-elevated)]",children:e.map(a=>{const o=t.includes(a.id);return i.jsxs("article",{"data-testid":`linear-source-row-${a.id}`,className:"grid min-h-16 grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-3 border-b border-[color:var(--border-soft)] px-3 py-3 last:border-b-0",children:[i.jsx("input",{type:"checkbox","data-testid":`linear-source-row-checkbox-${a.id}`,className:"h-4 w-4 rounded border-[color:var(--border-base)]",checked:o,disabled:a.imported||r,"aria-label":`Select ${a.identifier}`,onChange:()=>s(a.id)}),i.jsxs("div",{className:"min-w-0",children:[i.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[i.jsxs("a",{href:a.url,target:"_blank",rel:"noreferrer",className:"min-w-0 truncate text-sm font-medium text-foreground no-underline hover:underline",children:[i.jsx("span",{className:"font-mono text-xs text-muted-foreground",children:a.identifier})," ",a.title]}),a.imported?i.jsx(Cje,{}):null]}),i.jsx(Zwt,{row:a})]}),i.jsx("div",{className:"flex shrink-0 items-center",children:i.jsx(_je,{row:a,orgId:n})})]},a.id)})})}function ekt({status:e,issueCount:t}){return i.jsxs("div",{"data-testid":`linear-source-hidden-column-${e}`,className:Q("flex items-center gap-2 rounded-[calc(var(--radius-sm)-1px)] border px-2 py-2",jje[e]),children:[i.jsx(Ws,{status:e}),i.jsx("span",{className:"min-w-0 flex-1 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:Nje(e)}),i.jsx("span",{className:"text-xs text-muted-foreground/60 tabular-nums",children:t})]})}function tkt({rows:e,teamMappings:t,selectedIssueIds:n,orgId:r,importing:s,onToggleSelected:a}){const o=x.useMemo(()=>{var d;const u=new Map;for(const h of SP)u.set(h,[]);for(const h of e){const m=Ywt(h,t);(d=u.get(m))==null||d.push(h)}return u},[e,t]),l=SP.filter(u=>{var d;return(((d=o.get(u))==null?void 0:d.length)??0)>0}),c=SP.filter(u=>{var d;return(((d=o.get(u))==null?void 0:d.length)??0)===0});return i.jsx("div",{className:"scrollbar-auto-hide min-h-0 flex-1 overflow-x-auto overflow-y-hidden pb-3",children:i.jsxs("div",{className:"flex h-full min-h-full min-w-max items-stretch gap-3 pr-2",children:[l.map(u=>{const d=o.get(u)??[];return i.jsxs("section",{className:"flex h-full min-h-0 w-[272px] min-w-[272px] shrink-0 flex-col",children:[i.jsxs("div",{className:"mb-1 flex items-center gap-2 px-2 py-2",children:[i.jsx(Ws,{status:u}),i.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:Nje(u)}),i.jsx("span",{className:"ml-auto text-xs text-muted-foreground/60 tabular-nums",children:d.length})]}),i.jsx("div",{"data-testid":`linear-source-kanban-column-${u}`,className:Q("scrollbar-auto-hide flex-1 space-y-1.5 overflow-y-auto rounded-[calc(var(--radius-sm)-1px)] border p-1.5",jje[u]),children:d.map(h=>{var m,g;return i.jsxs("article",{"data-testid":`linear-source-board-card-${h.id}`,className:"overflow-hidden rounded-[calc(var(--radius-sm)-1px)] border bg-card p-2.5",children:[i.jsxs("div",{className:"mb-1.5 flex min-w-0 items-start gap-2",children:[i.jsx("input",{type:"checkbox",className:"mt-0.5 h-4 w-4 rounded border-[color:var(--border-base)]",checked:n.includes(h.id),disabled:h.imported||s,"aria-label":`Select ${h.identifier}`,onChange:()=>a(h.id)}),i.jsx("a",{href:h.url,target:"_blank",rel:"noreferrer",className:"min-w-0 flex-1 truncate font-mono text-xs text-muted-foreground no-underline hover:underline",children:h.identifier}),h.imported?i.jsx(Cje,{}):null]}),i.jsx("p",{className:"mb-2 line-clamp-2 text-sm leading-snug",children:h.title}),i.jsxs("div",{className:"space-y-1.5 text-xs text-muted-foreground",children:[i.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[i.jsx(Ws,{status:Sje(h.state.type)}),i.jsx("span",{className:"truncate",children:h.state.name})]}),i.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[i.jsx(v1,{className:"h-3 w-3 shrink-0"}),i.jsx("span",{className:"truncate",children:((m=h.project)==null?void 0:m.name)??"No Linear project"})]}),i.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[i.jsx(Iv,{className:"h-3 w-3 shrink-0"}),i.jsx("span",{className:"truncate",children:((g=h.assignee)==null?void 0:g.name)??"Unassigned"})]}),i.jsxs("span",{children:["Updated ",du(h.updatedAt)]})]}),h.imported?i.jsx("div",{className:"mt-3 flex justify-end",children:i.jsx(_je,{row:h,orgId:r})}):null]},h.id)})})]},u)}),c.length>0?i.jsxs("div",{"data-testid":"linear-source-hidden-columns",className:"flex h-full min-h-0 w-[228px] min-w-[228px] shrink-0 flex-col rounded-[calc(var(--radius-sm)+1px)] border border-[color:var(--border-base)] bg-[color:color-mix(in_oklab,var(--surface-inset)_78%,transparent)] p-2",children:[i.jsxs("div",{className:"mb-2 flex items-center gap-2 px-1",children:[i.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:"Hidden columns"}),i.jsx("span",{className:"ml-auto text-xs text-muted-foreground/60 tabular-nums",children:c.length})]}),i.jsx("div",{className:"space-y-2",children:c.map(u=>{var d;return i.jsx(ekt,{status:u,issueCount:((d=o.get(u))==null?void 0:d.length)??0},u)})})]}):null]})})}function nkt({orgId:e,orgName:t,projects:n,linearTeamId:r="",linearProjectId:s="",initialSearch:a=""}){var Qe,pt;const o=xn(),{pushToast:l}=gr(),[c,u]=x.useState(()=>Qwt()),[d,h]=x.useState(!1),[m,g]=x.useState("selected"),[b,v]=x.useState(""),[j,k]=x.useState(""),[w,N]=x.useState(""),[S,A]=x.useState("updated"),[_,E]=x.useState("desc"),[I,O]=x.useState(a),[M,D]=x.useState(a),[z,F]=x.useState([]),K=x.useRef(null),J=(t==null?void 0:t.trim())||"this organization";x.useEffect(()=>{O(a),D(a)},[a]),x.useEffect(()=>{const Se=window.setTimeout(()=>D(I.trim()),300);return()=>window.clearTimeout(Se)},[I]),x.useEffect(()=>{F([])},[r,s,j,w,M]),x.useEffect(()=>{typeof window<"u"&&window.localStorage.setItem("rudder:linear-source-view-mode",c)},[c]);const{data:$,isLoading:L}=ke({queryKey:U.plugins.uiContributions,queryFn:()=>vs.listUiContributions()}),H=x.useMemo(()=>Wwt($),[$]),W=(H==null?void 0:H.pluginId)??"",{data:B,isLoading:Y,error:P}=ke({queryKey:["plugins",Zk,zne,e,W],queryFn:async()=>(await vs.bridgeGetData(W,zne,{orgId:e},e)).data,enabled:!!e&&!!W}),{data:V,isLoading:ce}=ke({queryKey:["plugins",Zk,Bne,e,W],queryFn:async()=>(await vs.bridgeGetData(W,Bne,{orgId:e},e)).data,enabled:!!e&&!!W&&(B==null?void 0:B.configured)!==!1}),le=["plugins",Zk,CP,e,W,r||"__all__",s||"__all__",j||"__all__",w||"__all__",M||"__none__"],{data:G,isLoading:te,error:ge,hasNextPage:ie,fetchNextPage:ae,isFetchingNextPage:he}=r5e({queryKey:le,initialPageParam:null,queryFn:async({pageParam:Se})=>{const Be=typeof Se=="string"&&Se?Se:void 0;return(await vs.bridgeGetData(W,CP,{orgId:e,limit:Kwt,after:Be,teamId:r||void 0,projectId:s||void 0,stateId:j||void 0,assigneeId:w||void 0,query:M||void 0},e)).data},getNextPageParam:Se=>Se.hasNextPage&&Se.endCursor?Se.endCursor:void 0,enabled:!!e&&!!W&&(B==null?void 0:B.configured)===!0}),me=nt({mutationFn:async({mode:Se,issueIds:Be})=>{if(!b)throw new Error(`Choose a project in ${J} before importing.`);return(await vs.bridgePerformAction(W,Hwt,{orgId:e,targetProjectId:b,mode:Se,issueIds:Be,filters:{teamId:r||void 0,stateId:j||void 0,projectId:s||void 0,assigneeId:w||void 0,query:M||void 0}},e)).data},onSuccess:async Se=>{l({title:"Linear import complete",body:Gwt(Se),tone:"success"}),F([]),h(!1),await Promise.all([o.invalidateQueries({queryKey:["plugins",Zk,CP,e]}),o.invalidateQueries({queryKey:U.issues.list(e)})])},onError:Se=>{l({title:"Linear import failed",body:Se instanceof Error?Se.message:String(Se),tone:"error"})}}),ye=x.useMemo(()=>{const Se=[...(G==null?void 0:G.pages.flatMap(Be=>Be.rows))??[]];return Se.sort((Be,Ae)=>{let it=0;return S==="updated"?it=Une(Be.updatedAt,Ae.updatedAt):S==="created"?it=Une(Be.createdAt,Ae.createdAt):it=Be.identifier.localeCompare(Ae.identifier),_==="asc"?it:-it}),Se},[G==null?void 0:G.pages,_,S]);x.useEffect(()=>{const Se=new Set(ye.map(Be=>Be.id));F(Be=>Be.filter(Ae=>Se.has(Ae)))},[ye]);const Me=x.useMemo(()=>(V==null?void 0:V.teams.find(Se=>Se.id===r))??null,[V==null?void 0:V.teams,r]),$e=x.useMemo(()=>(V==null?void 0:V.projects.find(Se=>Se.id===s))??null,[V==null?void 0:V.projects,s]),Re=$e?`${$e.name}${Me?` / ${Me.name}`:""}`:(Me==null?void 0:Me.name)??"All Linear teams",Ue=x.useMemo(()=>{var Be;return((Be=B==null?void 0:B.projects)!=null&&Be.length?B.projects:n??[]).filter(Ae=>!("archivedAt"in Ae)||!Ae.archivedAt)},[B==null?void 0:B.projects,n]);x.useEffect(()=>{if(Ue.length===0){b&&v("");return}Ue.some(Se=>Se.id===b)||v(Ue.length===1?Ue[0].id:"")},[b,Ue]);const we=x.useMemo(()=>{const Se=r?((V==null?void 0:V.teams)??[]).filter(Ae=>Ae.id===r):(V==null?void 0:V.teams)??[],Be=new Map;for(const Ae of Se)for(const it of Ae.states??[])Be.set(it.id,it.name);return[...Be.entries()].map(([Ae,it])=>({id:Ae,name:it}))},[V==null?void 0:V.teams,r]),ze=ye.filter(Se=>Se.imported).length,oe=ye.filter(Se=>!Se.imported),xe=me.isPending,X=L||Y||ce||te,q=P??ge,ue=z.length,je=Ue.find(Se=>Se.id===b)??null,re=ye.length,fe=+!!j+ +!!w,ne=((Qe=we.find(Se=>Se.id===j))==null?void 0:Qe.name)??"All states",Fe=((pt=V==null?void 0:V.users.find(Se=>Se.id===w))==null?void 0:pt.name)??"Anyone",Ce=x.useCallback(Se=>{F(Be=>Be.includes(Se)?Be.filter(Ae=>Ae!==Se):[...Be,Se])},[]),tt=x.useCallback(Se=>{g(Se),h(!0)},[]);return x.useEffect(()=>{const Se=K.current;if(!Se||!ie||X||xe||he||typeof IntersectionObserver>"u")return;const Be=new IntersectionObserver(Ae=>{!Ae.some(Je=>Je.isIntersecting)||!ie||he||xe||ae()},{root:null,rootMargin:"280px 0px"});return Be.observe(Se),()=>Be.disconnect()},[ae,ie,xe,he,X,re]),!L&&!H?i.jsx("div",{className:"flex min-h-[58vh] items-center justify-center","data-testid":"linear-source-board",children:i.jsx(Er,{icon:Kl,message:"Linear is not installed or ready."})}):!Y&&(B==null?void 0:B.configured)===!1?i.jsx("div",{className:"flex h-full min-h-0 flex-col px-1","data-testid":"linear-source-board",children:i.jsxs("div",{className:"rounded-[calc(var(--radius-sm)+1px)] border border-dashed border-[color:var(--border-base)] bg-[color:color-mix(in_oklab,var(--surface-inset)_82%,transparent)] px-4 py-4 text-sm text-muted-foreground",children:[i.jsx("div",{className:"font-medium text-foreground",children:"Linear is not configured for this organization."}),i.jsx("div",{className:"mt-1",children:B.message??"Connect Linear and choose teams in plugin settings."}),i.jsx(de,{asChild:!0,variant:"outline",size:"sm",className:"mt-3",children:i.jsx(Nt,{to:"/instance/settings/plugins",children:"Open plugin settings"})})]})}):i.jsxs("div",{"data-testid":"linear-source-board",className:"flex h-full min-h-0 flex-col gap-4",children:[i.jsxs("div",{"data-testid":"linear-source-toolbar",className:"surface-panel flex items-center justify-between gap-2 rounded-[calc(var(--radius-sm)+1px)] px-3 py-3 sm:gap-3",children:[i.jsxs("div",{className:"flex min-w-0 items-baseline gap-3",children:[i.jsx("div",{className:"truncate text-xs font-medium uppercase tracking-[0.18em] text-muted-foreground",children:Re}),i.jsxs("div",{className:"hidden min-w-0 items-center gap-2 text-xs text-muted-foreground md:flex",children:[i.jsxs("span",{children:[re," loaded"]}),ze>0?i.jsxs("span",{children:[ze," imported"]}):null,ie?i.jsx("span",{children:"Loads as you scroll"}):null]})]}),i.jsxs("div",{className:"flex shrink-0 items-center gap-0.5 sm:gap-1",children:[i.jsxs("div",{className:"flex items-center overflow-hidden rounded-[var(--radius-sm)] border border-[color:var(--border-base)] bg-[color:color-mix(in_oklab,var(--surface-inset)_82%,transparent)]",children:[i.jsx("button",{className:Q("p-1.5 transition-colors",c==="list"?"bg-[color:var(--surface-active)] text-foreground":"text-muted-foreground hover:text-foreground"),onClick:()=>u("list"),title:"List view","data-testid":"linear-source-view-list",children:i.jsx(J7,{className:"h-3.5 w-3.5"})}),i.jsx("button",{className:Q("p-1.5 transition-colors",c==="board"?"bg-[color:var(--surface-active)] text-foreground":"text-muted-foreground hover:text-foreground"),onClick:()=>u("board"),title:"Board view","data-testid":"linear-source-view-board",children:i.jsx(Gue,{className:"h-3.5 w-3.5"})})]}),i.jsxs(cr,{children:[i.jsx(mr,{asChild:!0,children:i.jsxs(de,{variant:"ghost",size:"sm",className:Q("text-xs",fe>0&&"text-[color:var(--accent-strong)]"),children:[i.jsx(VL,{className:"h-3.5 w-3.5 sm:h-3 sm:w-3 sm:mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:fe>0?`Filters: ${fe}`:"Filter"})]})}),i.jsx(ur,{align:"end",className:"w-72 p-3",children:i.jsxs("div",{className:"space-y-3",children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("span",{className:"text-sm font-medium",children:"Filters"}),fe>0?i.jsx("button",{type:"button",className:"text-xs text-muted-foreground hover:text-foreground",onClick:()=>{k(""),N("")},children:"Clear"}):null]}),i.jsx(_P,{label:"State",children:i.jsxs("select",{className:s5("h-8 w-full"),value:j,"aria-label":"Filter by Linear state",onChange:Se=>k(Se.target.value),children:[i.jsx("option",{value:"",children:"All states"}),we.map(Se=>i.jsx("option",{value:Se.id,children:Se.name},Se.id))]})}),i.jsx(_P,{label:"Assignee",children:i.jsxs("select",{className:s5("h-8 w-full"),value:w,"aria-label":"Filter by Linear assignee",onChange:Se=>N(Se.target.value),children:[i.jsx("option",{value:"",children:"Anyone"}),((V==null?void 0:V.users)??[]).map(Se=>i.jsx("option",{value:Se.id,children:Se.name},Se.id))]})}),i.jsxs("div",{className:"rounded-[calc(var(--radius-sm)-1px)] border border-[color:var(--border-soft)] bg-[color:var(--surface-inset)] px-2.5 py-2 text-xs text-muted-foreground",children:[ne," / ",Fe]})]})})]}),i.jsxs(cr,{children:[i.jsx(mr,{asChild:!0,children:i.jsxs(de,{variant:"ghost",size:"sm",className:"text-xs",children:[i.jsx(zL,{className:"h-3.5 w-3.5 sm:h-3 sm:w-3 sm:mr-1"}),i.jsx("span",{className:"hidden sm:inline",children:"Sort"})]})}),i.jsx(ur,{align:"end",className:"w-56 p-3",children:i.jsxs("div",{className:"space-y-3",children:[i.jsx(_P,{label:"Sort by",children:i.jsxs("select",{className:s5("h-8 w-full"),value:S,"aria-label":"Sort Linear issues",onChange:Se=>A(Se.target.value),children:[i.jsx("option",{value:"updated",children:"Updated"}),i.jsx("option",{value:"created",children:"Created"}),i.jsx("option",{value:"identifier",children:"Identifier"})]})}),i.jsxs(de,{type:"button",variant:"ghost",size:"sm",className:"h-8 w-full justify-start",title:`Sort ${_==="asc"?"ascending":"descending"}`,onClick:()=>E(Se=>Se==="asc"?"desc":"asc"),children:[i.jsx(zL,{className:"h-3.5 w-3.5"}),i.jsx("span",{children:_==="asc"?"Ascending":"Descending"})]})]})})]})]})]}),i.jsxs("div",{className:"surface-panel flex flex-col gap-3 rounded-[calc(var(--radius-sm)+1px)] px-3 py-2.5 md:flex-row md:items-center md:justify-between",children:[i.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[i.jsxs(de,{type:"button",variant:"ghost",size:"sm",disabled:oe.length===0||xe,onClick:()=>F(oe.map(Se=>Se.id)),children:[i.jsx(VL,{className:"h-3.5 w-3.5"}),"Select loaded"]}),i.jsx(de,{type:"button",variant:"ghost",size:"sm",disabled:z.length===0||xe,onClick:()=>F([]),children:"Clear"})]}),i.jsxs("div",{className:"flex min-w-0 flex-wrap items-center justify-end gap-2",children:[i.jsxs("span",{className:"text-xs text-muted-foreground",children:[ue," selected"]}),i.jsxs(de,{type:"button",variant:"outline",size:"sm","data-testid":"linear-source-import-selected",disabled:ue===0||xe,onClick:()=>tt("selected"),children:[i.jsx(kG,{className:"h-3.5 w-3.5"}),"Import selected"]}),i.jsx(de,{type:"button",size:"sm",disabled:re===0||xe,onClick:()=>tt("allMatching"),children:"Import matching"})]})]}),X?i.jsx(Is,{variant:"issues-list"}):null,q?i.jsx("p",{className:"text-sm text-destructive",children:q instanceof Error?q.message:String(q)}):null,!X&&!q&&ye.length===0?i.jsx("div",{className:"flex min-h-[48vh] items-center justify-center",children:i.jsx(Er,{icon:Kl,message:"No Linear issues match this source."})}):null,!X&&!q&&ye.length>0&&c==="list"?i.jsx(Xwt,{rows:ye,selectedIssueIds:z,orgId:e,importing:xe,onToggleSelected:Ce}):null,!X&&!q&&ye.length>0&&c==="board"?i.jsx(tkt,{rows:ye,teamMappings:B==null?void 0:B.teamMappings,selectedIssueIds:z,orgId:e,importing:xe,onToggleSelected:Ce}):null,!X&&!q&&ye.length>0?i.jsx("div",{ref:K,"data-testid":"linear-source-load-more-sentinel",className:"flex min-h-8 items-center justify-between gap-3 text-xs text-muted-foreground",children:i.jsxs("span",{children:["Loaded ",re," issue",re===1?"":"s",he?" - loading more":ie?" - more load as you scroll":" - all matching issues loaded"]})}):null,i.jsx(Bs,{open:d,onOpenChange:h,children:i.jsxs(Ys,{className:"sm:max-w-md",children:[i.jsxs(ma,{children:[i.jsx(Ui,{children:m==="selected"?"Import selected Linear issues":"Import matching Linear issues"}),i.jsxs(Ba,{children:["Choose the project in ",J," where these issues should land."]})]}),i.jsxs("div",{className:"space-y-3",children:[i.jsxs("label",{className:"flex flex-col gap-1.5",children:[i.jsxs("span",{className:"text-xs font-medium text-muted-foreground",children:["Project in ",J]}),i.jsxs("select",{"data-testid":"linear-source-import-project",className:s5("w-full"),value:b,"aria-label":`Project in ${J}`,onChange:Se=>v(Se.target.value),children:[i.jsxs("option",{value:"",children:["Choose a project in ",J]}),Ue.map(Se=>i.jsx("option",{value:Se.id,children:Se.name},Se.id))]})]}),i.jsxs("div",{className:"rounded-[calc(var(--radius-sm)-1px)] border border-[color:var(--border-soft)] bg-[color:var(--surface-inset)] px-3 py-2 text-xs text-muted-foreground",children:[m==="selected"?`${ue} selected Linear issue${ue===1?"":"s"}`:`All matching Linear issues from ${Re}`,je?` -> ${je.name}`:""]})]}),i.jsxs(Fo,{children:[i.jsx(de,{type:"button",variant:"outline",onClick:()=>h(!1),children:"Cancel"}),i.jsxs(de,{type:"button","data-testid":"linear-source-confirm-import",disabled:!b||xe||m==="selected"&&ue===0,onClick:()=>{me.mutate({mode:m,issueIds:m==="selected"?z:void 0})},children:[i.jsx(kG,{className:"h-3.5 w-3.5"}),xe?"Importing":"Import"]})]})]})})]})}const Aje="rudder:starred-issues";function rkt(){if(typeof window>"u")return[];try{const e=window.localStorage.getItem(Aje);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t.filter(n=>typeof n=="string"&&n.length>0):[]}catch{return[]}}function qne(){if(!(typeof window>"u"))try{window.localStorage.removeItem(Aje)}catch{}}function skt(e){const t=xn(),n=x.useRef(null),r=x.useRef(null),s=ke({queryKey:U.issues.follows(e??"__none__"),queryFn:()=>fn.listFollows(e),enabled:!!e}),a=x.useMemo(()=>new Set((s.data??[]).map(l=>l.issueId)),[s.data]);x.useEffect(()=>{if(!e||!s.isSuccess||n.current===e||r.current===e)return;const l=rkt();if(l.length===0){n.current=e;return}const c=l.filter(u=>!a.has(u));if(c.length===0){qne(),n.current=e;return}r.current=e,Promise.allSettled(c.map(u=>fn.follow(u))).then(async u=>{r.current=null,!u.some(h=>h.status==="rejected")&&(qne(),n.current=e,await t.invalidateQueries({queryKey:U.issues.follows(e)}),await t.invalidateQueries({queryKey:U.issues.list(e)}),await t.invalidateQueries({queryKey:U.messenger.threads(e)}),await t.invalidateQueries({queryKey:U.messenger.issues(e)}))})},[a,s.isSuccess,e,t]);const o=x.useCallback(async l=>{e&&(a.has(l)?await fn.unfollow(l):await fn.follow(l),await t.invalidateQueries({queryKey:U.issues.follows(e)}),await t.invalidateQueries({queryKey:U.issues.list(e)}),await t.invalidateQueries({queryKey:U.messenger.threads(e)}),await t.invalidateQueries({queryKey:U.messenger.issues(e)}))},[a,e,t]);return{follows:s.data??[],followedIssueIds:a,isLoading:s.isLoading,error:s.error instanceof Error?s.error:null,toggleFollowIssue:o}}function ikt(e){return e.replace(/[-_]+/g," ").replace(/\b\w/g,t=>t.toUpperCase())}function akt(e,t){var n;return e.projectId?((n=t==null?void 0:t.find(r=>r.id===e.projectId))==null?void 0:n.name)??null:null}function okt(e,t,n){var s;const r=hh(e.assigneeValue||e.assigneeId||"");return r.assigneeAgentId?((s=t==null?void 0:t.find(a=>a.id===r.assigneeAgentId))==null?void 0:s.name)??null:r.assigneeUserId?Ec(r.assigneeUserId,n):null}const lkt=220;function ckt(){var e,t;return typeof window>"u"?!1:((t=(e=window.matchMedia)==null?void 0:e.call(window,"(prefers-reduced-motion: reduce)"))==null?void 0:t.matches)??!1}function ukt({description:e}){return e?i.jsx("div",{"data-testid":"issue-draft-description-preview",className:"mt-5 max-h-[4.5rem] w-full min-w-0 overflow-hidden",children:i.jsx(gi,{className:"text-sm leading-6 text-muted-foreground [&_blockquote]:my-0 [&_h1]:my-0 [&_h1]:text-sm [&_h1]:leading-6 [&_h2]:my-0 [&_h2]:text-sm [&_h2]:leading-6 [&_h3]:my-0 [&_h3]:text-sm [&_h3]:leading-6 [&_img]:my-0 [&_img]:max-h-[4.5rem] [&_img]:w-full [&_img]:rounded-[calc(var(--radius-sm)-2px)] [&_img]:object-cover [&_ol]:my-0 [&_p]:my-0 [&_pre]:my-0 [&_ul]:my-0",children:e})}):i.jsx("p",{className:"mt-5 text-sm leading-6 text-muted-foreground",children:"Add description..."})}function dkt({drafts:e,agents:t,projects:n,currentUserId:r,deletingDraftIds:s,onOpenDraft:a,onDeleteDraft:o}){return e.length===0?i.jsx("div",{"data-testid":"issue-drafts-view",className:"flex h-full min-h-0 flex-col",children:i.jsx(Er,{icon:tb,message:"No draft issues."})}):i.jsxs("div",{"data-testid":"issue-drafts-view",className:"flex h-full min-h-0 flex-col overflow-y-auto px-6 py-5",children:[i.jsx("div",{className:"mb-4 flex items-center justify-between gap-3",children:i.jsxs("div",{children:[i.jsx("h1",{className:"text-lg font-semibold text-foreground",children:"Draft Issues"}),i.jsxs("p",{className:"mt-1 text-sm text-muted-foreground",children:[e.length," saved draft",e.length===1?"":"s"]})]})}),i.jsx("section",{"aria-label":"Draft issues",className:"grid max-w-5xl grid-cols-1 gap-3 md:grid-cols-2 xl:grid-cols-3",children:e.map(l=>{const c=(s==null?void 0:s.has(l.id))??!1,u=akt(l,n),d=okt(l,t,r),h=[l.status?{key:"status",icon:i.jsx(pl,{className:"h-3 w-3 shrink-0"}),label:ikt(l.status)}:null,l.priority?{key:"priority",icon:i.jsx(qI,{priority:l.priority,className:"h-3.5 w-4 shrink-0"}),label:Ho(l.priority)}:null,u?{key:"project",icon:i.jsx(v1,{className:"h-3 w-3 shrink-0"}),label:u}:null,d?{key:"assignee",icon:i.jsx(Iv,{className:"h-3 w-3 shrink-0"}),label:d}:null,{key:"updated",icon:i.jsx(vf,{className:"h-3 w-3 shrink-0"}),label:hs(l.updatedAt)}].filter(m=>!!m);return i.jsxs("article",{"data-testid":"issue-draft-card","data-deleting":c?"true":void 0,"aria-busy":c?"true":void 0,className:"motion-draft-issue-card group relative min-h-36 rounded-[var(--radius-sm)] border border-[color:var(--border-soft)] bg-[color:color-mix(in_oklab,var(--surface-elevated)_88%,transparent)] hover:border-[color:var(--border-strong)] hover:bg-[color:var(--surface-elevated)]",children:[i.jsx("button",{type:"button",disabled:c,"aria-label":`Open draft ${l.title}`,className:"absolute inset-0 z-10 rounded-[var(--radius-sm)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",onClick:()=>a(l)}),i.jsxs("div",{className:"pointer-events-none flex h-full min-h-36 w-full flex-col items-start px-4 py-3 text-left",children:[i.jsxs("div",{className:"flex w-full min-w-0 items-start gap-2 pr-9",children:[i.jsx(tb,{className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}),i.jsxs("div",{className:"min-w-0",children:[i.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:l.title}),i.jsx("div",{className:"mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-muted-foreground",children:h.map(m=>i.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1",children:[m.icon,i.jsx("span",{className:"max-w-[11rem] truncate",children:m.label})]},`${l.id}-${m.key}`))})]})]}),i.jsx(ukt,{description:l.description})]}),i.jsx("button",{type:"button","data-testid":"issue-draft-delete-button",disabled:c,"aria-label":`Delete draft ${l.title}`,onClick:m=>{m.preventDefault(),m.stopPropagation(),o(l)},className:"absolute right-3 top-3 z-20 inline-flex h-7 w-7 items-center justify-center rounded-[calc(var(--radius-sm)-2px)] text-muted-foreground opacity-100 transition-colors hover:bg-[color:color-mix(in_oklab,var(--destructive)_16%,transparent)] hover:text-destructive",children:i.jsx(ha,{className:"h-3.5 w-3.5"})})]},l.id)})})]})}function fkt(){var ie,ae;const{selectedOrganizationId:e,selectedOrganization:t}=bn(),{setBreadcrumbs:n}=Nr(),{openNewIssue:r,confirm:s}=Gr(),{pushToast:a}=gr(),o=Tn(),[l]=md(),c=xn(),u=l.get("q")??"",d=l.get("source")??"",h=l.get("scope")??"",m=h==="recent"?"":h,g=m==="drafts",b=d==="linear"&&!g,v=l.get("linearTeamId")??void 0,j=l.get("linearProjectId")??void 0,k=l.get("projectId")??void 0,w=l.get("participantAgentId")??void 0,N=l.get("groupBy"),S=N==="status"||N==="priority"||N==="assignee"||N==="project"||N==="none"?N:void 0,A=x.useRef(void 0),_=x.useCallback(he=>{clearTimeout(A.current),A.current=setTimeout(()=>{const me=he.trim();if((new URLSearchParams(window.location.search).get("q")??"")===me)return;const Me=new URL(window.location.href);me?Me.searchParams.set("q",me):Me.searchParams.delete("q");const $e=`${Me.pathname}${Me.search}${Me.hash}`;window.history.replaceState(window.history.state,"",$e)},300)},[]);x.useEffect(()=>()=>clearTimeout(A.current),[]),x.useEffect(()=>{if(h!=="recent"||typeof window>"u")return;const he=new URLSearchParams(o.search);he.delete("scope");const me=he.toString(),ye=`${o.pathname}${me?`?${me}`:""}${o.hash}`;window.history.replaceState(window.history.state,"",ye)},[h,o.hash,o.pathname,o.search]),x.useEffect(()=>{if(!l.has("view")||typeof window>"u")return;const he=new URLSearchParams(o.search);he.delete("view");const me=he.toString(),ye=`${o.pathname}${me?`?${me}`:""}${o.hash}`;window.history.replaceState(window.history.state,"",ye)},[o.hash,o.pathname,o.search,l]);const{data:E}=ke({queryKey:U.agents.list(e),queryFn:()=>$t.list(e),enabled:!!e}),{data:I}=ke({queryKey:U.auth.session,queryFn:()=>Ri.getSession()}),O=((ie=I==null?void 0:I.user)==null?void 0:ie.id)??((ae=I==null?void 0:I.session)==null?void 0:ae.userId)??null,[M,D]=x.useState(()=>LA(e)),[z,F]=x.useState(()=>new Set),K=x.useRef(new Set),{followedIssueIds:J,toggleFollowIssue:$}=skt(e),L=x.useCallback((he,me)=>{const ye=new Set(K.current);me?ye.add(he):ye.delete(he),K.current=ye,F(ye)},[]),{data:H}=ke({queryKey:U.projects.list(e),queryFn:()=>gs.list(e),enabled:!!e}),{data:W}=ke({queryKey:U.liveRuns(e),queryFn:()=>us.liveRunsForCompany(e),enabled:!!e,refetchInterval:5e3}),B=x.useMemo(()=>{const he=new Set;for(const me of W??[])me.issueId&&he.add(me.issueId);return he},[W]),Y=x.useMemo(()=>f8("Issues",`${o.pathname}${o.search}${o.hash}`),[o.pathname,o.search,o.hash]);x.useEffect(()=>{n([{label:g?"Draft Issues":b?"Linear Issues":"Issue Tracker"}])},[g,b,n]),x.useEffect(()=>{const he=()=>{D(LA(e))};if(he(),!(typeof window>"u"))return window.addEventListener(eN,he),window.addEventListener("storage",he),()=>{window.removeEventListener(eN,he),window.removeEventListener("storage",he)}},[e]),x.useEffect(()=>{!e||w||g||b||O9e(e,{scope:m||void 0,projectId:k})},[m,g,b,w,k,e]);const P=x.useMemo(()=>f7e(m,O),[O,m]),{data:V,isLoading:ce,error:le}=ke({queryKey:[...U.issues.list(e),"participant-agent",w??"__all__","scope",m||"__default__","user",O??"__none__","project",k??"__all__"],queryFn:()=>fn.list(e,{participantAgentId:w,projectId:k,...P}),enabled:!!e&&!g&&!b}),G=x.useMemo(()=>{const he=V??[];return m==="starred"?he.filter(me=>J.has(me.id)):m==="following"&&O?he.filter(me=>Bde(me,O)):he},[O,m,J,V]),te=nt({mutationFn:({id:he,data:me})=>fn.update(he,me),onSuccess:()=>{c.invalidateQueries({queryKey:U.issues.list(e)})}}),ge=nt({mutationFn:he=>fn.reorder(e,he),onSuccess:()=>{c.invalidateQueries({queryKey:U.issues.list(e)})}});return e?g?i.jsx(dkt,{drafts:M,agents:E,projects:H,currentUserId:O,deletingDraftIds:z,onOpenDraft:he=>{r({draftId:he.id})},onDeleteDraft:async he=>{if(!await s({title:`Delete draft issue "${he.title}"?`,description:"This cannot be undone.",confirmLabel:"Delete",tone:"destructive"})||K.current.has(he.id))return;L(he.id,!0);const ye=()=>{t8(he.id),L(he.id,!1),a({title:"Draft issue deleted",tone:"success"})};if(ckt()){ye();return}window.setTimeout(ye,lkt)}}):b?i.jsx("div",{className:"flex h-full min-h-0 flex-col",children:i.jsx(nkt,{orgId:e,orgName:t==null?void 0:t.name,projects:H,linearTeamId:v,linearProjectId:j,initialSearch:u})}):i.jsx("div",{className:"flex h-full min-h-0 flex-col",children:i.jsx(Vwt,{issues:G,isLoading:ce,error:le,agents:E,projects:H,liveIssueIds:B,projectId:k,viewStateKey:"rudder:issues-view",issueLinkState:Y,initialAssignees:l.get("assignee")?[l.get("assignee")]:void 0,initialSearch:u,initialGroupBy:S,toolbarMode:"controls-only",starredIssueIds:[...J],onToggleStarredIssue:he=>{$(he)},onOpenIssue:he=>{e&&fF(e,he.id,E0(e))},onSearchChange:_,onUpdateIssue:(he,me)=>te.mutate({id:he,data:me}),onReorderIssue:he=>ge.mutate(he),searchFilters:w?{participantAgentId:w}:void 0})}):i.jsx(Er,{icon:pl,message:"Select a organization to view issues."})}const hkt="image/*,application/pdf,text/plain,text/markdown,application/json,text/csv,text/html,.md,.markdown",mkt=800;function pkt(e){return e==="done"}function gkt(e){try{return localStorage.getItem(e)??""}catch{return""}}function xkt(e,t){try{t.trim()?localStorage.setItem(e,t):localStorage.removeItem(e)}catch{}}function bkt(e){try{localStorage.removeItem(e)}catch{}}function Vne(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)?e:null}function ykt(e){var s;const t=Vne((s=Vne(e))==null?void 0:s.passiveFollowup),n=typeof(t==null?void 0:t.attempt)=="number"?t.attempt:null,r=typeof(t==null?void 0:t.maxAttempts)=="number"?t.maxAttempts:null;return t?n&&r?`Passive follow-up ${n}/${r}`:"Passive follow-up":null}function vkt(e){if(!e||e==="__none__")return{assigneeAgentId:null,assigneeUserId:null};if(e.startsWith("agent:")){const t=e.slice(6);return t?{assigneeAgentId:t,assigneeUserId:null}:null}if(e.startsWith("user:")){const t=e.slice(5);return t?{assigneeAgentId:null,assigneeUserId:t}:null}return null}function wkt({text:e}){const[t,n]=x.useState(!1);return i.jsx("button",{type:"button",className:"text-muted-foreground hover:text-foreground transition-colors",title:"Copy as markdown",onClick:()=>{navigator.clipboard.writeText(e).then(()=>{n(!0),setTimeout(()=>n(!1),2e3)})},children:t?i.jsx(ws,{className:"h-3 w-3"}):i.jsx(xi,{className:"h-3 w-3"})})}const kkt=x.memo(function({timeline:t,agentMap:n,orgId:r,projectId:s,highlightCommentId:a,runTranscriptById:o,runHasOutput:l,operatorDisplayName:c,skillReferences:u,emptyMessage:d}){return t.length===0?i.jsx("p",{className:"text-sm text-muted-foreground",children:d}):i.jsx("div",{className:"space-y-3",children:t.map(h=>{var b,v,j,k,w,N;if(h.kind==="activity")return i.jsx("div",{children:h.activity.node},`activity:${h.id}`);if(h.kind==="run"){const S=h.run,A=S.status==="queued"||S.status==="running",_=o.get(S.runId)??[],E=l(S.runId),I=ykt(S.contextSnapshot);return i.jsxs("div",{className:"overflow-hidden rounded-sm border border-border bg-accent/20 p-3",children:[i.jsxs("div",{className:"mb-3 flex items-start justify-between gap-3",children:[i.jsx(Rx,{to:`/agents/${S.agentId}`,className:"hover:underline",children:i.jsx(vl,{name:((b=n==null?void 0:n.get(S.agentId))==null?void 0:b.name)??S.agentId.slice(0,8),icon:(v=n==null?void 0:n.get(S.agentId))==null?void 0:v.icon,role:(j=n==null?void 0:n.get(S.agentId))==null?void 0:j.role,size:"sm"})}),i.jsx("div",{className:"shrink-0 text-right",children:i.jsx("span",{className:"block text-xs text-muted-foreground",children:pi(S.startedAt??S.createdAt)})})]}),i.jsxs("div",{className:"mb-3 flex flex-wrap items-center gap-2 text-xs",children:[i.jsx("span",{className:"text-muted-foreground",children:"Execution"}),i.jsx(Rx,{to:`/agents/${S.agentId}/runs/${S.runId}`,className:"inline-flex items-center rounded-md border border-border bg-accent/40 px-2 py-1 font-mono text-muted-foreground hover:bg-accent/60 hover:text-foreground transition-colors",children:S.runId.slice(0,8)}),i.jsx(yr,{status:S.status}),I&&i.jsx("span",{className:"rounded-md border border-amber-500/30 bg-amber-500/10 px-2 py-1 text-[11px] font-medium text-amber-700 dark:text-amber-300",children:I})]}),i.jsx("div",{className:"max-h-56 overflow-y-auto pr-1",children:i.jsx(Af,{entries:_,density:"compact",limit:4,streaming:A,collapseStdout:!0,emptyMessage:E?"Waiting for transcript parsing...":A?`Run ${S.status}. Waiting for output...`:"No run output captured."})})]},`run:${S.runId}`)}const m=h.comment,g=a===m.id;return i.jsxs("div",{id:`comment-${m.id}`,className:`border p-3 overflow-hidden min-w-0 rounded-sm transition-colors duration-1000 ${g?"border-primary/50 bg-primary/5":"border-border"}`,children:[i.jsxs("div",{className:"flex items-center justify-between mb-1",children:[m.authorAgentId?i.jsx(Rx,{to:`/agents/${m.authorAgentId}`,className:"hover:underline",children:i.jsx(vl,{name:((k=n==null?void 0:n.get(m.authorAgentId))==null?void 0:k.name)??m.authorAgentId.slice(0,8),icon:(w=n==null?void 0:n.get(m.authorAgentId))==null?void 0:w.icon,role:(N=n==null?void 0:n.get(m.authorAgentId))==null?void 0:N.role,size:"sm"})}):i.jsx(ao,{name:qU(c),size:"sm"}),i.jsxs("span",{className:"flex items-center gap-1.5",children:[r?i.jsx(Gh,{slotTypes:["commentContextMenuItem"],entityType:"comment",context:{orgId:r,projectId:s??null,entityId:m.id,entityType:"comment",parentEntityId:m.issueId},className:"flex flex-wrap items-center gap-1.5",itemClassName:"inline-flex",missingBehavior:"placeholder"}):null,i.jsx("a",{href:`#comment-${m.id}`,className:"text-xs text-muted-foreground hover:text-foreground hover:underline transition-colors",children:pi(m.createdAt)}),i.jsx(wkt,{text:m.body})]})]}),i.jsx(gi,{className:"text-sm",skillReferences:u,children:m.body}),r?i.jsx("div",{className:"mt-2 space-y-2",children:i.jsx(Gh,{slotTypes:["commentAnnotation"],entityType:"comment",context:{orgId:r,projectId:s??null,entityId:m.id,entityType:"comment",parentEntityId:m.issueId},className:"space-y-2",itemClassName:"rounded-md",missingBehavior:"placeholder"})}):null,m.runId&&i.jsx("div",{className:"mt-2 pt-2 border-t border-border/60",children:m.runAgentId?i.jsxs(Rx,{to:`/agents/${m.runAgentId}/runs/${m.runId}`,className:"inline-flex items-center rounded-md border border-border bg-accent/30 px-2 py-1 text-[10px] font-mono text-muted-foreground hover:text-foreground hover:bg-accent/50 transition-colors",children:["run ",m.runId.slice(0,8)]}):i.jsxs("span",{className:"inline-flex items-center rounded-md border border-border bg-accent/30 px-2 py-1 text-[10px] font-mono text-muted-foreground",children:["run ",m.runId.slice(0,8)]})})]},m.id)})})});function jkt({comments:e,linkedRuns:t=[],activityItems:n=[],orgId:r,projectId:s,onAdd:a,issueStatus:o,agentMap:l,imageUploadHandler:c,onAttachImage:u,draftKey:d,liveRunSlot:h,enableReassign:m=!1,reassignOptions:g=[],currentAssigneeValue:b="",suggestedAssigneeValue:v,mentions:j,operatorDisplayName:k,heading:w,hideHeading:N=!1,emptyMessage:S="No comments or runs yet.",escapeBackWhenEmpty:A=!1}){const[_,E]=x.useState(""),I=pkt(o),[O,M]=x.useState(I),[D,z]=x.useState(!1),[F,K]=x.useState(!1),J=v??b,[$,L]=x.useState(J),[H,W]=x.useState(null),B=x.useRef(null),Y=x.useRef(null),P=x.useRef(null),V=x.useRef(null),ce=Tn(),le=x.useRef(null),G=x.useRef(null),te=x.useMemo(()=>{const Re=e.map(oe=>({kind:"comment",id:oe.id,createdAtMs:new Date(oe.createdAt).getTime(),comment:oe})),Ue=t.map(oe=>({kind:"run",id:oe.runId,createdAtMs:new Date(oe.startedAt??oe.createdAt).getTime(),run:oe})),we=n.map(oe=>({kind:"activity",id:oe.id,createdAtMs:new Date(oe.createdAt).getTime(),activity:oe})),ze={activity:0,comment:1,run:2};return[...Re,...Ue,...we].sort((oe,xe)=>oe.createdAtMs!==xe.createdAtMs?oe.createdAtMs-xe.createdAtMs:oe.kind!==xe.kind?ze[oe.kind]-ze[xe.kind]:oe.kind===xe.kind?oe.id.localeCompare(xe.id):0)},[n,e,t]),ge=x.useMemo(()=>t.map(Re=>{var we;const Ue=l==null?void 0:l.get(Re.agentId);return{id:Re.runId,status:Re.status,invocationSource:"issue_timeline",triggerDetail:null,startedAt:typeof Re.startedAt=="string"?Re.startedAt:((we=Re.startedAt)==null?void 0:we.toISOString())??null,finishedAt:null,createdAt:typeof Re.createdAt=="string"?Re.createdAt:Re.createdAt.toISOString(),agentId:Re.agentId,agentName:(Ue==null?void 0:Ue.name)??Re.agentId.slice(0,8),agentRuntimeType:(Ue==null?void 0:Ue.agentRuntimeType)??"process",issueId:null}}),[l,t]),{transcriptByRun:ie,hasOutputForRun:ae}=lS({runs:ge,orgId:r,maxChunksPerRun:120}),he=x.useMemo(()=>j||(l?Array.from(l.values()).filter(Re=>Re.status!=="terminated").map(Re=>({id:`agent:${Re.id}`,name:zo(Re),kind:"agent",agentId:Re.id,agentIcon:Re.icon,agentRole:Re.role})):[]),[l,j]),me=x.useMemo(()=>he.filter(Re=>Re.kind==="skill"&&Re.skillMarkdownTarget).map(Re=>({href:Re.skillMarkdownTarget,label:Re.skillRefLabel??Re.name,displayName:Re.skillDisplayName??Re.name,description:Re.skillDescription,categoryLabel:Re.skillCategoryLabel,locationLabel:Re.skillLocationLabel,detailsHref:Re.skillDetailsHref})),[he]);x.useEffect(()=>{d&&E(gkt(d))},[d]),x.useEffect(()=>{d&&(V.current&&clearTimeout(V.current),V.current=setTimeout(()=>{xkt(d,_)},mkt))},[_,d]),x.useEffect(()=>()=>{V.current&&clearTimeout(V.current),G.current&&clearTimeout(G.current)},[]),x.useEffect(()=>{L(J)},[J]),x.useEffect(()=>{M(I)},[I]),x.useEffect(()=>{const Re=ce.hash;if(!Re.startsWith("#comment-")||e.length===0)return;const Ue=Re.slice(9),we=`${ce.key}:${Re}`;if(le.current===we)return;const ze=document.getElementById(`comment-${Ue}`);ze&&(le.current=we,G.current&&clearTimeout(G.current),W(Ue),ze.scrollIntoView({behavior:"smooth",block:"center"}),G.current=setTimeout(()=>{W(null),G.current=null},3e3))},[ce.hash,ce.key,e.length]);async function ye(){const Re=_.trim();if(!Re)return;const we=m&&$!==b?vkt($):null,ze=I&&O?!0:void 0;z(!0);try{await a(Re,ze,we??void 0),E(""),d&&bkt(d),M(I),L(J)}finally{z(!1)}}async function Me(Re){var we;const Ue=(we=Re.target.files)==null?void 0:we[0];if(Ue){K(!0);try{if(c){const ze=await c(Ue),oe=Ue.name.replace(/[[\]]/g,"\\$&"),xe=Ue.type.startsWith("image/")?`![${oe}](${ze})`:`[${oe}](${ze})`;E(X=>X?`${X}
1376
1376
 
1377
1377
  ${xe}`:xe)}else u&&await u(Ue)}finally{K(!1),P.current&&(P.current.value="")}}}const $e=!D&&!!_.trim();return i.jsxs("div",{className:"space-y-4",children:[!N&&(w??i.jsxs("h3",{className:"text-sm font-semibold",children:["Comments & Runs (",te.length,")"]})),i.jsx(kkt,{timeline:te,agentMap:l,orgId:r,projectId:s,highlightCommentId:H,runTranscriptById:ie,runHasOutput:ae,operatorDisplayName:k,skillReferences:me,emptyMessage:S}),h,i.jsxs("div",{ref:Y,className:"chat-composer rounded-[var(--radius-lg)] p-3","data-issue-detail-escape-back":A?_.trim()?"dirty":"empty":void 0,children:[i.jsx(Vo,{ref:B,value:_,onChange:E,placeholder:"Leave a comment...",mentions:he,mentionMenuAnchorRef:Y,mentionMenuPlacement:"container",onSubmit:ye,imageUploadHandler:c,className:"rounded-[var(--radius-md)] bg-transparent",contentClassName:"min-h-[64px] bg-transparent text-sm leading-6 text-foreground",bordered:!1}),i.jsxs("div",{className:"mt-3 flex items-center justify-end gap-3",children:[(c||u)&&i.jsxs("div",{className:"mr-auto flex items-center gap-3",children:[i.jsx("input",{ref:P,type:"file",accept:hkt,className:"hidden",onChange:Me}),i.jsx(de,{variant:"ghost",size:"icon-sm",onClick:()=>{var Re;return(Re=P.current)==null?void 0:Re.click()},disabled:F,title:"Attach file",children:i.jsx(_b,{className:"h-4 w-4"})})]}),I?i.jsxs("label",{className:"flex items-center gap-1.5 text-xs text-muted-foreground cursor-pointer select-none",children:[i.jsx("input",{type:"checkbox",checked:O,onChange:Re=>M(Re.target.checked),className:"rounded border-border"}),"Re-open"]}):null,m&&g.length>0&&i.jsx(Ih,{value:$,options:g,placeholder:"Assignee",noneLabel:"No assignee",searchPlaceholder:"Search assignees...",emptyMessage:"No assignees found.",onChange:L,className:"text-xs h-8",renderTriggerValue:Re=>{if(!Re)return i.jsx("span",{className:"text-muted-foreground",children:"Assignee"});const Ue=Re.id.startsWith("agent:")?Re.id.slice(6):null,we=Ue?l==null?void 0:l.get(Ue):null;return i.jsxs(i.Fragment,{children:[we?i.jsx(ks,{icon:we.icon,role:we.role,className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}):null,i.jsx("span",{className:"truncate",children:Re.label})]})},renderOption:Re=>{if(!Re.id)return i.jsx("span",{className:"truncate",children:Re.label});const Ue=Re.id.startsWith("agent:")?Re.id.slice(6):null,we=Ue?l==null?void 0:l.get(Ue):null;return i.jsxs(i.Fragment,{children:[we?i.jsx(ks,{icon:we.icon,role:we.role,className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}):null,i.jsx("span",{className:"truncate",children:Re.label})]})}}),i.jsx(de,{size:"sm",disabled:!$e,onClick:ye,children:D?"Posting...":"Comment"})]})]})]})}function Nkt(e){return e.replace(/`([^`]+)`/g,"$1").replace(/\[([^\]]+)\]\([^)]+\)/g,"$1").replace(/!\[([^\]]*)\]\([^)]+\)/g,"$1").replace(/<[^>]+>/g,"").replace(/[*_~]/g,"").trim()}function Ckt(e){return e.trim().toLowerCase().replace(/[^\p{L}\p{N}]+/gu,"-").replace(/^-+|-+$/g,"")}function Skt(e){var a;const t=[],n=new Map,r=e.replace(/\r\n?/g,`
1378
1378
  `).split(`