dsh-remote-vs 0.30.0 → 0.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/README.en.md +40 -18
  2. package/README.md +32 -17
  3. package/THIRD-PARTY-NOTICES.md +6 -6
  4. package/cordis.patch.yml +31 -76
  5. package/lib/client.js +61 -9
  6. package/lib/index.js +25 -3
  7. package/lib/p2-router-fs.js +15 -1
  8. package/lib/types/client/WorkspacesView.d.ts +2 -0
  9. package/lib/types/client/composer.d.ts +8 -1
  10. package/lib/types/client/selection-popup.d.ts +1 -1
  11. package/lib/types/client/ui.d.ts +7 -4
  12. package/lib/types/p2/router-fs.d.ts +9 -1
  13. package/lib/types/p2/worlds.d.ts +23 -0
  14. package/lib/{worlds-CRRZMZhg.js → worlds-BdxLeKul.js} +49 -1
  15. package/package.json +46 -46
  16. package/src/client/DirectoryFlow.tsx +8 -0
  17. package/src/client/EditorPane.tsx +5 -1
  18. package/src/client/HostsView.tsx +2 -0
  19. package/src/client/RemoteExplorer.tsx +11 -2
  20. package/src/client/RemoteRoot.tsx +1 -0
  21. package/src/client/SettingsHosts.tsx +1 -0
  22. package/src/client/WorkspaceWizard.tsx +1 -0
  23. package/src/client/WorkspacesView.tsx +21 -1
  24. package/src/client/composer.ts +8 -1
  25. package/src/client/scm/DiffView.tsx +5 -2
  26. package/src/client/selection-popup.ts +1 -1
  27. package/src/client/ui.tsx +9 -7
  28. package/src/client/vsc/vsc.css +55 -3
  29. package/src/index.ts +31 -0
  30. package/src/p2/router-fs.ts +29 -1
  31. package/src/p2/worlds.ts +68 -1
  32. package/src/routes.ts +19 -13
  33. package/vendor/dsh-remote-helpers/dsh-ssh-helper-0.2.3-alpha.3-linux-x64.helper.json +20 -0
  34. package/vendor/dsh-remote-helpers/dsh-ssh-helper-0.2.3-alpha.3-linux-x64.tar.gz +4 -0
  35. package/vendor/dsh-remote-helpers/dsh-ssh-helper-0.2.3-alpha.3-linux-x64.tar.gz.sha256 +1 -0
  36. package/vendor/dsh-remote-helpers/pkg-sea-bare-import.patch +30 -0
  37. package/vendor/dsh-remote-helpers/ssh-helper-runtime-deps.patch +4 -3
  38. package/vendor/dsh-remote-helpers/dsh-ssh-helper-0.2.2-rc.4-linux-x64.helper.json +0 -19
  39. package/vendor/dsh-remote-helpers/dsh-ssh-helper-0.2.2-rc.4-linux-x64.tar.gz +0 -4
  40. package/vendor/dsh-remote-helpers/dsh-ssh-helper-0.2.2-rc.4-linux-x64.tar.gz.sha256 +0 -1
package/lib/client.js CHANGED
@@ -12,6 +12,54 @@ window.__ModuleLoader__.load({id:`dsh-remote-vs`,factory:e=>{var t={exports:{}},
12
12
  * scheme gets the GitHub-Light set from the \`body:not(...)\` block below).
13
13
  */
14
14
 
15
+ /**
16
+ * Native \`<select>\` popups are painted by the browser from each \`<option>\`'s
17
+ * own computed colors. \`Canvas\`/\`CanvasText\` resolve against the PAGE's
18
+ * \`color-scheme\`, and DSH never switches that — it marks the theme on <body>
19
+ * (\`body[data-ds-dark-theme]\`) — so the open list stayed white in dark mode
20
+ * while the closed control was dark.
21
+ *
22
+ * The tokens live on <body>, NOT on \`.rvs-root\`, because the plugin also
23
+ * renders selects on the host Settings page (Remote hosts), outside the
24
+ * Workbench root. Values are OPAQUE on purpose — a popup cannot composite a
25
+ * translucent surface over the page — and measured with the WCAG formula:
26
+ * light #1f1f1f on #ffffff ≈ 15.7:1
27
+ * dark #cccccc on #3c3c3c ≈ 7.1:1
28
+ */
29
+ body {
30
+ --rvs-option-bg: #ffffff;
31
+ --rvs-option-fg: #1f1f1f;
32
+ }
33
+
34
+ body[data-ds-dark-theme] {
35
+ --rvs-option-bg: #3c3c3c;
36
+ --rvs-option-fg: #cccccc;
37
+ }
38
+
39
+ /**
40
+ * Selects whose popup needs theming: \`.rvs-select\` is the workbench's own
41
+ * dropdown, \`.rvs-dropdown\` marks the inline-styled native selects (Settings,
42
+ * host forms, workspace wizard). \`color-scheme\` is stated per theme so the
43
+ * popup's own chrome (scrollbar, focus ring) follows it too — \`light dark\`
44
+ * kept the UA on the page scheme, which never turns dark.
45
+ */
46
+ .rvs-select,
47
+ .rvs-dropdown {
48
+ color-scheme: light;
49
+ }
50
+
51
+ body[data-ds-dark-theme] .rvs-select,
52
+ body[data-ds-dark-theme] .rvs-dropdown {
53
+ color-scheme: dark;
54
+ }
55
+
56
+ .rvs-select option,
57
+ .rvs-dropdown option {
58
+ background-color: var(--rvs-option-bg);
59
+ color: var(--rvs-option-fg);
60
+ }
61
+
62
+
15
63
  .rvs-root {
16
64
  --rvs-fg: var(--dsw-alias-label-primary, #e6e6e6);
17
65
  --rvs-fg2: var(--dsw-alias-label-secondary, #b9b9b9);
@@ -1000,12 +1048,16 @@ body:not([data-ds-dark-theme]) .rvs-fi {
1000
1048
  font: inherit;
1001
1049
  font-size: 12px;
1002
1050
  outline: none;
1003
- color-scheme: light dark;
1051
+ color-scheme: light;
1052
+ }
1053
+
1054
+ body[data-ds-dark-theme] .rvs-select {
1055
+ color-scheme: dark;
1004
1056
  }
1005
1057
 
1006
1058
  .rvs-select option {
1007
- background: Canvas;
1008
- color: CanvasText;
1059
+ background-color: var(--rvs-option-bg);
1060
+ color: var(--rvs-option-fg);
1009
1061
  }
1010
1062
 
1011
1063
  /* ------------------------------------------------- conversation-view mount */
@@ -7037,7 +7089,7 @@ try type typeof var void while with yield as declare namespace readonly keyof in
7037
7089
  object undefined NaN Infinity`.split(/\s+/).filter(e=>e!==``),FI=`and as assert async await break class continue def del elif else except finally for from global if import in is lambda nonlocal not or
7038
7090
  pass raise return try while with yield match case None True False self cls print`.split(/\s+/).filter(e=>e!==``),II=`if then else elif fi for while until do done case esac function return break continue local export readonly declare unset set
7039
7091
  shift source alias echo printf cd exit test trap eval exec`.split(/\s+/).filter(e=>e!==``),LI=`true false null yes no on off True False Null`.split(/\s+/).filter(e=>e!==``),RI=`string number boolean any void unknown never object Array Promise Record Map Set Partial Readonly Pick Omit String Number Boolean Object
7040
- Integer Float Double Long Int32 Int64 Uint8 uint32_t int32_t uint64_t int64_t size_t FILE std string vector map set unique_ptr shared_ptr auto`.split(/\s+/).filter(e=>e!==``),zI={js:{lineComment:[`//`],block:[`/*`,`*/`],strings:[{open:"`",close:"`",escape:!0,kind:`string`},{open:`'`,close:`'`,escape:!0},{open:`"`,close:`"`,escape:!0}],keywords:new Set(PI),types:new Set(RI),callIsFunc:!0},ts:{lineComment:[`//`],block:[`/*`,`*/`],strings:[{open:"`",close:"`",escape:!0,kind:`string`},{open:`'`,close:`'`,escape:!0},{open:`"`,close:`"`,escape:!0}],keywords:new Set(PI),types:new Set(RI),callIsFunc:!0,at:!0},json:{lineComment:[],strings:[{open:`"`,close:`"`,escape:!0}],keywords:new Set([`true`,`false`,`null`]),callIsFunc:!1},python:{lineComment:[`#`],strings:[{open:`'''`,close:`'''`,escape:!1,kind:`string`},{open:`"""`,close:`"""`,escape:!1,kind:`string`},{open:`'`,close:`'`,escape:!0},{open:`"`,close:`"`,escape:!0}],keywords:new Set(FI),types:new Set(RI),callIsFunc:!0,at:!0},shell:{lineComment:[`#`],strings:[{open:`'`,close:`'`,escape:!1},{open:`"`,close:`"`,escape:!0}],keywords:new Set(II),callIsFunc:!1,backticks:!0},yaml:{lineComment:[`#`],strings:[{open:`'`,close:`'`,escape:!1},{open:`"`,close:`"`,escape:!0}],keywords:new Set(LI),callIsFunc:!1},xml:{lineComment:[],block:[`<!--`,`-->`],strings:[{open:`"`,close:`"`,escape:!1,kind:`string`},{open:`'`,close:`'`,escape:!1,kind:`string`}],keywords:new Set,callIsFunc:!1},css:{lineComment:[],block:[`/*`,`*/`],strings:[{open:`"`,close:`"`,escape:!0},{open:`'`,close:`'`,escape:!0}],keywords:new Set([`important`,`media`,`supports`,`root`,`import`,`keyframes`,`from`,`to`,`and`,`not`]),callIsFunc:!1,at:!0,hash:`attr`},markdown:{lineComment:[],block:[`<!--`,`-->`],strings:[{open:"`",close:"`",escape:!1,kind:`string`}],keywords:new Set,callIsFunc:!1},clike:{lineComment:[`//`],block:[`/*`,`*/`],strings:[{open:`"`,close:`"`,escape:!0},{open:`'`,close:`'`,escape:!0}],keywords:new Set(NI),types:new Set(RI),callIsFunc:!0,at:!0},diff:{lineComment:[],strings:[],keywords:new Set,callIsFunc:!1}},BI={js:`js`,jsx:`js`,mjs:`js`,cjs:`js`,vue:`js`,svelte:`js`,ts:`ts`,tsx:`ts`,mts:`ts`,cts:`ts`,json:`json`,jsonc:`json`,json5:`json`,lock:`json`,py:`python`,pyi:`python`,sh:`shell`,bash:`shell`,zsh:`shell`,ksh:`shell`,fish:`shell`,ps1:`shell`,yml:`yaml`,yaml:`yaml`,html:`xml`,htm:`xml`,xml:`xml`,svg:`xml`,xhtml:`xml`,css:`css`,scss:`css`,less:`css`,sass:`css`,md:`markdown`,markdown:`markdown`,mdx:`markdown`,c:`clike`,h:`clike`,cc:`clike`,cpp:`clike`,cxx:`clike`,hpp:`clike`,hh:`clike`,hxx:`clike`,java:`clike`,cs:`clike`,go:`clike`,rs:`clike`,kt:`clike`,kts:`clike`,swift:`clike`,m:`clike`,mm:`clike`,php:`clike`,scala:`clike`,groovy:`clike`,sql:`clike`,diff:`diff`,patch:`diff`};function VI(e){let t=e.replace(/\\/g,`/`).split(`/`).pop()??``,n=t.lastIndexOf(`.`);if(!(n<0||n===t.length-1))return BI[t.slice(n+1).toLowerCase()]}function HI(e){switch(e){case`js`:return`JavaScript`;case`ts`:return`TypeScript`;case`json`:return`JSON`;case`python`:return`Python`;case`shell`:return`Shell`;case`yaml`:return`YAML`;case`xml`:return`HTML/XML`;case`css`:return`CSS`;case`markdown`:return`Markdown`;case`clike`:return`C-family`;case`diff`:return`Diff`;default:return`Text`}}let UI=/[A-Za-z_$]/,WI=/[A-Za-z0-9_$]/,GI=/[0-9]/;function KI(){return{blockEnd:void 0}}function qI(e,t,n){if(t===void 0)return e===``?[]:[{text:e,kind:`plain`}];if(t===`diff`)return JI(e);if(t===`markdown`)return YI(e);let r=zI[t],i=[],a=0,o=(e,t)=>{if(e===``)return;let n=i[i.length-1];n!==void 0&&n.kind===t?n.text+=e:i.push({text:e,kind:t})};for(;a<e.length;){if(n.blockEnd!==void 0){let t=e.indexOf(n.blockEnd,a);if(t<0)return o(e.slice(a),`comment`),i;o(e.slice(a,t+n.blockEnd.length),`comment`),a=t+n.blockEnd.length,n.blockEnd=void 0;continue}let s=e[a],c=e.slice(a);if(r.lineComment?.find(e=>c.startsWith(e))!==void 0){if(t===`shell`&&a>0&&WI.test(e[a-1])){o(s,`plain`),a+=1;continue}return o(c,`comment`),i}if(r.block!==void 0&&c.startsWith(r.block[0])){n.blockEnd=r.block[1];continue}if(t===`python`&&(c.startsWith(`"""`)||c.startsWith(`'''`))){let t=c.slice(0,3),n=e.indexOf(t,a+3);if(n<0)return o(c,`string`),i;o(e.slice(a,n+3),`string`),a=n+3;continue}let l=r.strings.find(e=>c.startsWith(e.open));if(l!==void 0){let t=a+l.open.length,n=!1;for(;t<e.length;){if(l.escape&&e[t]===`\\`){t+=2;continue}if(e.startsWith(l.close,t)){t+=l.close.length,n=!0;break}t+=1}o(e.slice(a,n?t:e.length),l.kind??`string`),a=n?t:e.length;continue}if(GI.test(s)&&!WI.test(e[a-1]??``)){let t=a;for(;t<e.length&&/[0-9a-fA-FxXbBoO._eE+-]/.test(e[t]);){let n=e[t];if((n===`+`||n===`-`)&&!/[eE]/.test(e[t-1]))break;t+=1}o(e.slice(a,t),`number`),a=t;continue}if(UI.test(s)){let t=a+1;for(;t<e.length&&WI.test(e[t]);)t+=1;let n=e.slice(a,t),i=t;for(;i<e.length&&e[i]===` `;)i+=1;o(n,r.keywords.has(n)?`keyword`:r.types?.has(n)===!0?`type`:r.callIsFunc===!0&&e[i]===`(`?`func`:`plain`),a=t;continue}if(r.at===!0&&s===`@`){let t=a+1;for(;t<e.length&&WI.test(e[t]);)t+=1;o(e.slice(a,t),`meta`),a=t;continue}if(r.hash===`attr`&&s===`#`){let t=a+1;for(;t<e.length&&/[A-Za-z0-9_-]/.test(e[t]);)t+=1;o(e.slice(a,t),`attr`),a=t;continue}if(r.backticks===!0&&s==="`"){let t=e.indexOf("`",a+1),n=t<0?e.length:t+1;o(e.slice(a,n),`string`),a=n;continue}if(t===`xml`&&(s===`<`||s===`>`)){o(s,`punct`),a+=1;continue}if(/[{}()[\].,;:]/.test(s)){o(s,`punct`),a+=1;continue}if(/[+\-*/%=<>!&|^~?]/.test(s)){let t=a+1;for(;t<e.length&&/[+\-*/%=<>!&|^~?]/.test(e[t]);)t+=1;o(e.slice(a,t),`operator`),a=t;continue}o(s,`plain`),a+=1}return i}function JI(e){return e.startsWith(`@@`)||e.startsWith(`+++`)||e.startsWith(`---`)?[{text:e,kind:`meta`}]:e.startsWith(`+`)?[{text:e,kind:`insert`}]:e.startsWith(`-`)?[{text:e,kind:`delete`}]:[{text:e,kind:`plain`}]}function YI(e){let t=/^(#{1,6}\s)(.*)$/.exec(e);if(t!==null)return[{text:t[1],kind:`meta`},{text:t[2],kind:`keyword`}];let n=/^(\s*)([-*+]|\d+\.)(\s)(.*)$/.exec(e);if(n!==null)return[{text:n[1],kind:`plain`},{text:n[2],kind:`operator`},{text:n[3],kind:`plain`},{text:n[4],kind:`plain`}];if(/^\s*>/.test(e))return[{text:e,kind:`comment`}];if(/^\s*(```|~~~)/.test(e))return[{text:e,kind:`meta`}];let r=[],i=/(`[^`]*`)|(\*\*[^*]+\*\*)|(\[[^\]]*\]\([^)]*\))/g,a=0;for(let t=i.exec(e);t!==null;t=i.exec(e))t.index>a&&r.push({text:e.slice(a,t.index),kind:`plain`}),r.push({text:t[0],kind:t[1]===void 0?t[2]===void 0?`func`:`keyword`:`string`}),a=t.index+t[0].length;return a<e.length&&r.push({text:e.slice(a),kind:`plain`}),r}var XI=class{lines=[];tokensCache=void 0;source=void 0;lang;constructor(e){this.lang=e}get tokens(){return this.tokensCache===void 0&&(this.tokensCache=this.lines.map(e=>e.tokens)),this.tokensCache}lastTokenizedCount=0;refresh(e){if(e===this.source){this.lastTokenizedCount=0;return}let t=[],n=0,r;for(let i=0;i<e.lines;i+=1){let a=e.line(i+1).text,o=this.lines[i];if(o!==void 0&&o.text===a&&o.entry===r){t.push(o),r=o.exit;continue}let s=KI();s.blockEnd=r;let c=qI(a,this.lang,s);t.push({text:a,tokens:c,entry:r,exit:s.blockEnd}),r=s.blockEnd,n+=1}this.lines=t,this.tokensCache=void 0,this.source=e,this.lastTokenizedCount=n}};let ZI=new Map;function QI(e){let t=ZI.get(e);return t===void 0&&(t=bm.mark({class:`rvs-t-${e}`}),ZI.set(e,t)),t}function $I(e,t){let n=VI(e);class r{decorations=bm.none;cache=new XI(n);view;primary=!1;probedAt=0;constructor(e){this.view=e,this.rebuild()}update(e){if(this.primary)return;let n=Date.now();if((e.docChanged||n-this.probedAt>=80)&&(this.probedAt=n,this.primary=t(),this.primary)){this.decorations!==bm.none&&(this.decorations=bm.none);return}(e.docChanged||e.viewportChanged)&&this.rebuild()}rebuild(){let e=this.view.state.doc;this.cache.refresh(e);let t=this.cache.tokens;if(t.length===0){this.decorations=bm.none;return}let n=new Dp;for(let r of this.view.visibleRanges){let i=e.lineAt(r.from).number,a=e.lineAt(r.to).number;for(let r=i;r<=a&&r<=t.length;r+=1){let i=e.line(r),a=t[r-1]??[],o=i.from;for(let e of a){let t=e.text.length;e.kind!==`plain`&&t>0&&o+t<=i.to&&n.add(o,o+t,QI(e.kind)),o+=t}}}this.decorations=n.finish()}}return Kh.fromClass(r,{decorations:e=>e.decorations})}function eL(e){return VI(e)!==void 0}let tL=np.define(),nL=Ff.define({create:()=>bm.none,update(e,t){let n=e.map(t.changes);for(let e of t.effects)e.is(tL)&&(n=e.value===null?bm.none:bm.set([bm.line({class:`rvs-reveal-line`}).range(e.value)]));return n},provide:e=>Y.decorations.from(e)}),rL=new WeakMap;function iL(e,t){let n=rL.get(e);n!==void 0&&window.clearTimeout(n);let r=window.setTimeout(()=>{rL.delete(e);try{t(null)}catch{}},2600);rL.set(e,r)}function aL(e,t,n){let r=0;try{let i=Math.min(Math.max(1,Math.round(t)),e.state.doc.lines);r=e.state.doc.line(i).number;let a=e.state.doc.line(r).from;e.dispatch({selection:{anchor:a},effects:Y.scrollIntoView(a,{y:`center`})}),n(a)}catch{return}e.focus(),window.setTimeout(()=>{try{oL(e,r)?.scrollIntoView({block:`center`,inline:`nearest`})}catch{}},30),iL(e,n)}function oL(e,t){let n=e.state.doc.line(t).from;if(n<e.viewport.from||n>e.viewport.to)return null;let r=e.domAtPos(n).node;for(;r!==null&&r!==e.dom;){if(r instanceof HTMLElement&&r.classList.contains(`cm-line`))return r;r=r.parentNode}return null}function sL(e,t,n,r){let i=0;try{let a=e.state.doc.lines,o=Math.min(Math.max(1,Math.round(Math.min(t,n))),a),s=Math.min(Math.max(o,Math.round(Math.max(t,n))),a),c=e.state.doc.line(o),l=e.state.doc.line(s);i=o,e.dispatch({selection:K.range(c.from,l.to),effects:Y.scrollIntoView(c.from,{y:`center`})}),r?.(c.from)}catch{return}e.focus(),window.setTimeout(()=>{try{oL(e,i)?.scrollIntoView({block:`center`,inline:`nearest`})}catch{}},30),r!==void 0&&iL(e,r)}let cL=np.define(),lL={add:0,mod:1,del:2},uL={add:`+`,mod:`●`,del:`−`},dL=new Dp().finish(),fL=new Map;function pL(e){let t=fL.get(e);return t===void 0&&(t=bm.line({class:`rvs-change-line rvs-change-${e}`}),fL.set(e,t)),t}let mL=bm.mark({class:`rvs-change-word-add`});var hL=class e extends vm{text;truncated;count;chipTitle;blockTitle;removedLines;constructor(e,t,n,r){super(),this.text=e,this.truncated=t,this.count=n,this.chipTitle=r(`changes.deletedChip`),this.blockTitle=r(`changes.deletedBlock`),this.removedLines=r(`changes.deletedLines`)}eq(t){return t instanceof e&&t.text===this.text&&t.truncated===this.truncated&&t.count===this.count&&t.chipTitle===this.chipTitle&&t.blockTitle===this.blockTitle&&t.removedLines===this.removedLines}toDOM(){let e=document.createElement(`span`),t=this.count>1;return e.className=t?`rvs-change-word-del rvs-change-block-del`:`rvs-change-word-del`,e.textContent=t?this.removedLines.replace(`{count}`,String(this.count)):this.truncated?`${this.text}…`:this.text,e.title=t?`${this.blockTitle.replace(`{count}`,String(this.count))}\n${this.text}`:this.chipTitle,e.setAttribute(`aria-label`,e.title),e}};function gL(e,t){return bm.widget({widget:new hL(e.text,e.truncated,e.count??0,t),side:-1})}function _L(e,t){let n=new Map;if(e===null)return n;let r=t.lines,i=e=>{let t=n.get(e);return t===void 0&&(t={ranges:[],chips:[]},n.set(e,t)),t};for(let t of e.marks){let e=xL(t.from,r);for(let n of t.inline??[]){let t=Math.max(0,Math.round(n.from)),a=Math.max(t,Math.round(n.to));a!==t&&i(xL(n.line??e,r)).ranges.push({from:t,to:a})}for(let n of t.removed??[])n.text!==``&&i(xL(n.line??e,r)).chips.push({at:Math.max(0,Math.round(n.at)),text:n.text,truncated:n.truncated===!0,...n.count===void 0?{}:{count:n.count}})}for(let e of n.values()){e.ranges.sort((e,t)=>e.from-t.from||e.to-t.to);let t=[];for(let n of e.ranges){let e=t[t.length-1];e!==void 0&&n.from<=e.to?e.to=Math.max(e.to,n.to):t.push({from:n.from,to:n.to})}e.ranges=t}return n}var vL=class e extends By{kind;elementClass;label;constructor(e,t){super(),this.kind=e,this.elementClass=`rvs-change-gutter-${e}`,this.label=t}eq(t){return t instanceof e&&t.kind===this.kind}toDOM(){let e=document.createElement(`span`);return e.className=`rvs-change-mark rvs-change-mark-${this.kind}`,e.textContent=uL[this.kind],e.title=this.label,e.setAttribute(`aria-label`,this.label),e}};function yL(e){return{add:new vL(`add`,e(`changes.markAdd`)),mod:new vL(`mod`,e(`changes.markMod`)),del:new vL(`del`,e(`changes.markDel`))}}let bL=new class extends By{toDOM(){let e=document.createElement(`span`);return e.className=`rvs-change-mark rvs-change-spacer`,e.textContent=`+`,e.setAttribute(`aria-hidden`,`true`),e}};function xL(e,t){return Number.isFinite(e)?Math.min(Math.max(1,Math.round(e)),t):1}function SL(e,t){if(e===null||e.marks.length===0)return[];let n=t.lines,r=[];for(let t of e.marks){let e=t.kind;if(e!==`add`&&e!==`mod`&&e!==`del`)continue;let i=xL(t.from,n),a=Math.min(Math.max(i,xL(t.to,n)),n);r.push({first:i,last:a,kind:e})}r.sort((e,t)=>e.first-t.first||lL[e.kind]-lL[t.kind]);let i=[];for(let e of r){let t=i[i.length-1],n=t===void 0?e.first:Math.max(e.first,t.last+1);n>e.last||i.push({first:n,last:e.last,kind:e.kind})}return i}let CL={set:null,spans:[],inline:new Map};function wL(e,t){for(let e of t.effects)if(e.is(cL))return e.value;return t.docChanged?null:e}let TL=Ff.define({create:()=>CL,update(e,t){let n=wL(e.set,t);return n===e.set?e:n===null?CL:{set:n,spans:SL(n,t.newDoc),inline:_L(n,t.newDoc)}}}),EL=Ff.define({create:()=>!1,update(e,t){for(let e of t.effects)if(e.is(cL))return!1;return t.docChanged?!0:e}});function DL(e){return e.field(TL,!1)?.set??null}function OL(e,t){let n=e.field(TL,!1)?.spans??[],r=Math.max(1,Math.round(t));for(let e of n)if(r>=e.first&&r<=e.last)return{from:e.first,to:e.last};return{from:r,to:r}}function kL(e,t){let n=0,r=e.length;for(;n<r;){let i=n+r>>>1;e[i].last<t?n=i+1:r=i}return n}var AL=class{decorations=bm.none;view;t;constructor(e,t){this.view=e,this.t=t,this.rebuild()}update(e){(e.docChanged||e.viewportChanged||e.startState.field(TL,!1)!==e.state.field(TL,!1))&&this.rebuild()}rebuild(){let e=this.view.state,t=e.field(TL,!1),n=t?.spans??[],r=t?.inline;if(n.length===0&&(r===void 0||r.size===0)){this.decorations=bm.none;return}let i=e.doc,a=new Dp;for(let e of this.view.visibleRanges){let t=i.lineAt(e.from).number,o=i.lineAt(e.to).number,s=kL(n,t);for(let e=t;e<=o;e+=1){let t=i.line(e);for(;s<n.length&&n[s].last<e;)s+=1;let o=s<n.length&&n[s].first<=e?n[s]:void 0,c=r?.get(e);if(o===void 0&&c===void 0)continue;let l=[];if(o!==void 0&&l.push({from:t.from,to:t.from,decoration:pL(o.kind)}),c!==void 0){for(let e of c.chips){let n=t.from+Math.min(e.at,t.length);l.push({from:n,to:n,decoration:gL(e,this.t)})}for(let e of c.ranges){let n=t.from+Math.min(e.from,t.length),r=t.from+Math.min(e.to,t.length);r>n&&l.push({from:n,to:r,decoration:mL})}}l.sort((e,t)=>e.from-t.from||e.decoration.startSide-t.decoration.startSide);for(let e of l)a.add(e.from,e.to,e.decoration)}}this.decorations=a.finish()}};function jL(e){return Kh.fromClass(class extends AL{constructor(t){super(t,e)}},{decorations:e=>e.decorations})}let ML;function NL(e,t){let n=e.state.field(TL,!1)??CL,r=e.viewport.from,i=e.viewport.to,a=ML;if(a!==void 0&&a.state===n&&a.from===r&&a.to===i&&a.owner===t)return a.markers;let o=dL;if(n.spans.length>0){let a=e.state.doc,s=a.lineAt(r).number,c=a.lineAt(i).number,l=new Dp;for(let e=kL(n.spans,s);e<n.spans.length;e+=1){let r=n.spans[e];if(r.first>c)break;let i=Math.max(r.first,s),o=Math.min(r.last,c),u=t[r.kind];for(let e=i;e<=o;e+=1){let t=a.line(e);l.add(t.from,t.to,u)}}o=l.finish()}return ML={state:n,from:r,to:i,owner:t,markers:o},o}function PL(e){let t=yL(e);return[TL,EL,Gy({class:`rvs-change-gutter`,markers:e=>NL(e,t),initialSpacer:()=>bL,lineMarkerChange:e=>e.startState.field(TL,!1)!==e.state.field(TL,!1)}),jL(e)]}var FL=class e extends By{text;title;committed;constructor(e,t,n){super(),this.text=e,this.title=t,this.committed=n}toDOM(){let e=document.createElement(`span`);return e.className=this.text===``?`rvs-blame-cont`:`rvs-blame-chip${this.committed?``:` rvs-blame-uncommitted`}`,e.textContent=this.text,this.title!==``&&(e.title=this.title),e}eq(t){return t instanceof e&&t.text===this.text&&t.title===this.title}};let IL=new Dp().finish(),LL=new class extends By{toDOM(){let e=document.createElement(`span`);return e.className=`rvs-blame-spacer`,e.textContent=`author · 00y`,e}};function RL(e,t,n){let r=e.state.doc,i=Math.max(1,r.lineAt(e.viewport.from).number),a=Math.min(r.lines,r.lineAt(e.viewport.to).number);if(t.size===0||a<i)return IL;let o=new Set(ai([...t.values()].sort((e,t)=>e.line-t.line)).map(e=>e.from)),s=new Dp;for(let e=i;e<=a;e+=1){let i=t.get(e);if(i===void 0)continue;let a=o.has(e)?new FL(ci(i,n),li(i),ui(i.hash)):new FL(``,``,!0),c=r.line(e);s.add(c.from,c.to,a)}return s.finish()}function zL(e){let t=t=>{let n=t.state.doc;e(n.lineAt(t.viewport.from).number,n.lineAt(t.viewport.to).number)};return Kh.fromClass(class{constructor(e){t(e)}update(e){!e.viewportChanged&&!e.docChanged||t(e.view)}})}function BL(e,t){let n=Math.floor(Date.now()/1e3),r=(n,r,i)=>{let a=n.state.doc.lineAt(r.from).number,o=e.get(a);return o===void 0||!ui(o.hash)?!1:(i.preventDefault(),t?.(o),!0)};return[Gy({class:`rvs-blame-gutter`,markers:t=>RL(t,e,n),initialSpacer:()=>LL,domEventHandlers:t===void 0?{}:{mousedown(e,t,n){return r(e,t,n)}}})]}function VL(e){return zL(e)}let HL=`2100`;function UL(e,t){let n=DL(e);if(n===null)return;let r;for(let e of n.marks)if(!(t<e.from||t>e.to)){if(e.kind!==`del`)return e;r??=e}return r}function WL(e){return e.state.readOnly}function GL(e,t){let n=t.target instanceof Node?t.target:null;return n===null||!e.contentDOM.contains(n)?null:(n instanceof Element?n:n.parentElement)?.closest(`.cm-line`)??null}function KL(e,t){let n=GL(e,t);if(n!==null)try{return e.state.doc.lineAt(e.posAtDOM(n,0)).number}catch{}try{let n=e.posAtCoords({x:t.clientX,y:t.clientY});return n===null?null:e.state.doc.lineAt(n).number}catch{return null}}var qL=class{rvsUndoAffordance=!0;view;onUndo;label;triggerLabel;hoverTime;confirm;trigger;menu;undoItem;confirmItem;menuOpen=!1;timer;leaveTimer;hovered;shown;onGlobalMouseDown=e=>{if(this.shown===void 0)return;let t=e.target instanceof Node?e.target:null;for(let e of[this.trigger,this.menu])if(e!==void 0&&t!==null&&e.contains(t))return;this.reset()};onGlobalKeyDown=e=>{e.key!==`Escape`||this.shown===void 0||this.reset()};onWindowBlur=()=>this.reset();onVisibilityChange=()=>{document.hidden&&this.reset()};constructor(e,t){this.view=e,this.onUndo=t.onUndo??(()=>{}),this.label=t.label??(()=>`撤销这处改动`),this.triggerLabel=t.triggerLabel??(()=>`改动操作`),this.hoverTime=t.hoverTime??300,this.confirm=t.confirm,document.addEventListener(`mousedown`,this.onGlobalMouseDown,!0),document.addEventListener(`keydown`,this.onGlobalKeyDown,!0),document.addEventListener(`visibilitychange`,this.onVisibilityChange),window.addEventListener(`blur`,this.onWindowBlur)}handleMove(e){if(this.cancelLeave(),this.menuHasFocus())return;if(WL(this.view)){this.reset();return}if(e.buttons!==0){this.reset();return}let t=KL(this.view,e),n=t===null?void 0:UL(this.view.state,t);if(t===null||n===void 0){this.reset();return}let r=this.hovered;r!==void 0&&r.line===t&&r.mark===n||(this.reset(),this.hovered={mark:n,line:t,element:GL(this.view,e)},this.timer=window.setTimeout(()=>{this.arm()},this.hoverTime))}handleLeave(){if(this.shown===void 0){this.reset();return}this.scheduleLeave()}arm(){this.timer=void 0;let e=this.hovered;if(e!==void 0){if(WL(this.view)){this.reset();return}if(UL(this.view.state,e.line)!==e.mark){this.reset();return}this.shown=e,this.show(e)}}ensureTrigger(){let e=this.trigger;if(e!==void 0)return e;let t=document.createElement(`button`);return t.type=`button`,t.className=`rvs-change-actions`,t.textContent=`⋯`,t.setAttribute(`aria-haspopup`,`menu`),t.setAttribute(`aria-expanded`,`false`),t.style.position=`fixed`,t.style.zIndex=HL,t.addEventListener(`mousedown`,e=>{e.preventDefault()}),t.addEventListener(`mouseenter`,()=>{this.cancelLeave()}),t.addEventListener(`mouseleave`,()=>{this.scheduleLeave()}),t.addEventListener(`click`,()=>{this.shown!==void 0&&(this.menuOpen?this.closeMenu():this.openMenu())}),this.trigger=t,t}ensureMenu(){let e=this.menu;if(e!==void 0)return e;let t=document.createElement(`div`);t.className=`rvs-change-actions-menu`,t.setAttribute(`role`,`menu`),t.style.position=`fixed`,t.style.zIndex=HL,t.hidden=!0,t.addEventListener(`mouseenter`,()=>{this.cancelLeave()}),t.addEventListener(`mouseleave`,()=>{this.scheduleLeave()}),t.addEventListener(`mousedown`,e=>{e.preventDefault()});let n=document.createElement(`button`);n.type=`button`,n.className=`rvs-change-actions-undo`,n.setAttribute(`role`,`menuitem`),n.addEventListener(`click`,()=>{let e=this.shown;this.reset(),e!==void 0&&this.onUndo(e.mark)}),t.appendChild(n);let r=this.confirm;if(r!==void 0){let e=document.createElement(`button`);e.type=`button`,e.className=`rvs-change-actions-confirm`,e.setAttribute(`role`,`menuitem`),e.addEventListener(`click`,()=>{let e=this.shown;e!==void 0&&(r.onToggle(e.mark),this.syncConfirm(e.mark),this.placeMenu())}),t.appendChild(e),this.confirmItem=e}return this.undoItem=n,this.menu=t,t}syncItems(e){let t=this.undoItem;if(t!==void 0){let n=this.label(e);t.textContent!==n&&(t.textContent=n),t.title=n,t.setAttribute(`aria-label`,n),t.dataset.kind=e.kind,t.dataset.hunk=String(e.hunk??-1)}this.syncConfirm(e)}syncConfirm(e){let t=this.confirm,n=this.confirmItem;if(t===void 0||n===void 0)return;let r=t.isConfirmed(e),i=r?t.pressedLabel?.(e)??t.label(e):t.label(e);n.textContent!==i&&(n.textContent=i),n.title=i,n.setAttribute(`aria-label`,i),n.setAttribute(`aria-pressed`,r?`true`:`false`),n.dataset.confirmed=r?`1`:`0`,n.classList.toggle(`is-on`,r)}cancelLeave(){this.leaveTimer!==void 0&&(window.clearTimeout(this.leaveTimer),this.leaveTimer=void 0)}scheduleLeave(){this.cancelLeave(),this.leaveTimer=window.setTimeout(()=>{this.leaveTimer=void 0,!this.menuHasFocus()&&this.reset()},150)}menuHasFocus(){let e=this.menu;return e===void 0||!this.menuOpen?!1:e.contains(document.activeElement)}show(e){let t=this.ensureTrigger(),n=this.triggerLabel();t.title=n,t.setAttribute(`aria-label`,n),t.parentNode===null&&document.body.appendChild(t);let r=this.ensureMenu();r.parentNode===null&&document.body.appendChild(r),this.syncItems(e.mark),this.placeTrigger(e)||(t.remove(),r.remove())}placeTrigger(e){let t=this.trigger;if(t===void 0)return!1;let n=this.rectFor(e);if(n===null)return!1;let r=t.getBoundingClientRect().width,i=window.innerWidth-8,a=n.right+8;return a=r>0&&a+r>i?Math.max(8,i-r):Math.min(a,i),t.style.left=`${Math.round(a)}px`,t.style.top=`${Math.round((n.top+n.bottom)/2)}px`,this.menuOpen&&this.placeMenu(),!0}placeMenu(){let e=this.menu,t=this.trigger;if(e===void 0||t===void 0)return;let n=t.getBoundingClientRect(),r=e.getBoundingClientRect(),i=window.innerWidth-4,a=window.innerHeight-4,o=r.width,s=n.right-o;s=Math.max(4,Math.min(s,i-o));let c=n.bottom,l=`below`;r.height>0&&c+r.height>a&&(c=n.top-r.height,l=`above`),e.dataset.side=l,e.style.left=`${Math.round(s)}px`,e.style.top=`${Math.round(c)}px`}openMenu(){let e=this.ensureMenu();e.parentNode===null&&document.body.appendChild(e),this.menuOpen=!0,this.trigger?.setAttribute(`aria-expanded`,`true`),e.hidden=!1,this.placeMenu()}closeMenu(){this.menuOpen=!1,this.trigger?.setAttribute(`aria-expanded`,`false`);let e=this.menu;e!==void 0&&(e.hidden=!0)}rectFor(e){let t=this.view.state.doc,n=t.line(Math.min(Math.max(1,e.line),t.lines));try{let e=this.view.coordsAtPos(n.to);if(e!==null&&Number.isFinite(e.top)&&Number.isFinite(e.right))return e}catch{}let r=e.element?.getBoundingClientRect();return r===void 0?null:{left:r.left,right:r.right,top:r.top,bottom:r.bottom}}reset(){this.timer!==void 0&&(window.clearTimeout(this.timer),this.timer=void 0),this.cancelLeave(),this.hovered=void 0,this.shown=void 0,this.closeMenu();let e=this.trigger;e!==void 0&&e.parentNode!==null&&e.remove();let t=this.menu;t!==void 0&&t.parentNode!==null&&t.remove()}update(e){if(e.docChanged||e.viewportChanged||e.geometryChanged){this.reset();return}DL(e.startState)!==DL(e.state)&&this.reset()}destroy(){this.reset(),this.trigger?.remove(),this.trigger=void 0,this.menu?.remove(),this.menu=void 0,this.undoItem=void 0,this.confirmItem=void 0,document.removeEventListener(`mousedown`,this.onGlobalMouseDown,!0),document.removeEventListener(`keydown`,this.onGlobalKeyDown,!0),document.removeEventListener(`visibilitychange`,this.onVisibilityChange),window.removeEventListener(`blur`,this.onWindowBlur)}};function JL(e={}){return e.onUndo===void 0||typeof document>`u`?[]:Kh.define(t=>new qL(t,e),{eventHandlers:{mousemove(e){return this.handleMove(e),!1},mouseleave(){return this.handleLeave(),!1}}})}let YL=new Bf,XL=new Bf,ZL=new Bf,QL=new Bf,$L=new Bf;function eR(e){return e.querySelector(`[class*="rvs-ck-"]`)!==null}let tR=(0,i.forwardRef)(function(e,t){let n=(0,i.useRef)(null),r=(0,i.useRef)(void 0),s=(0,i.useRef)(e.initial),c=(0,i.useRef)(void 0),l=(0,i.useRef)(!1),u=(0,i.useRef)(e);u.current=e;let d=(0,i.useMemo)(()=>fe(de()),[]),f=e.t??d,p=(0,i.useRef)({sessionId:e.sessionId,remoteRoot:e.remoteRoot,chatEnabled:e.chatEnabled,path:e.path});p.current={sessionId:e.sessionId,remoteRoot:e.remoteRoot,chatEnabled:e.chatEnabled,path:e.path};let m=(0,i.useRef)(e.ctx);m.current=e.ctx;let h=(0,i.useRef)(e.viewState),g=yI({onCommit:e=>{let t=m.current,n=p.current.sessionId;t!==void 0&&n!==void 0&&dI(t,n,e)},getSurface:()=>n.current}),_=(0,i.useRef)(g);_.current=g;let[v,y]=(0,i.useState)(!1),b=(0,i.useRef)(!1);b.current=v;let[x,S]=(0,i.useState)({text:``,id:0}),[C,w]=(0,i.useState)(0),[T,E]=(0,i.useState)(void 0),[D,O]=(0,i.useState)(null);(0,i.useEffect)(()=>{let e=r.current;if(e!==void 0)try{e.dispatch({effects:tL.of(D)})}catch{}},[D,T]),(0,i.useEffect)(()=>{let t=e.revealLine;if(t===void 0||t<=0)return;let n=r.current;if(n===void 0)return;let i=window.setTimeout(()=>aL(n,t,O),60);return()=>window.clearTimeout(i)},[e.revealLine,e.revealNonce,T]);let k=(0,i.useRef)(``),A=(0,i.useRef)(void 0),j=(0,i.useRef)(f),M=e.onUndoChange!==void 0,N=e.blockConfirm!==void 0;(0,i.useEffect)(()=>{let t=r.current;if(t===void 0)return;j.current!==f&&(j.current=f,k.current=``);let n=e.changeSet,i=n!==void 0,a=`${i?`m`:``}${M?`u`:``}${N?`c`:``}`;if(a!==k.current){k.current=a,A.current=void 0;let e=[...i?[PL(f)]:[],...M?[JL({onUndo:e=>{u.current.onUndoChange?.(e)},label:e=>u.current.undoLabel?.(e)??`撤销这处改动`,triggerLabel:()=>u.current.undoTriggerLabel?.()??`改动操作`,...N?{confirm:{isConfirmed:e=>u.current.blockConfirm?.isConfirmed(e)===!0,onToggle:e=>{u.current.blockConfirm?.onToggle(e)},label:e=>u.current.blockConfirm?.label(e)??`确认保留`,pressedLabel:e=>u.current.blockConfirm?.pressedLabel?.(e)??u.current.blockConfirm?.label(e)??`已确认保留`}}:{}})]:[]];try{t.dispatch({effects:QL.reconfigure(e)})}catch{return}}if(n!==void 0&&n!==A.current){A.current=n;try{t.dispatch({effects:cL.of(n)})}catch{}}},[e.changeSet,M,N,T,f]),(0,i.useEffect)(()=>{let t=r.current;if(t===void 0)return;let n=e.blame,i=n!=null&&n.size>0?BL(n,e=>{u.current.onOpenBlame?.(e)}):[];try{t.dispatch({effects:$L.reconfigure(i)})}catch{}},[e.blame]),(0,i.useEffect)(()=>{let t=e.revealHunkLine;if(t===void 0||t<=0)return;let n=r.current;if(n===void 0)return;let i=window.setTimeout(()=>{let e=OL(n.state,t);aL(n,e.from,O)},40);return()=>window.clearTimeout(i)},[e.revealHunkLine,e.revealHunkNonce,T]);let[ee,P]=(0,i.useState)(void 0);(0,i.useEffect)(()=>{if(!v){P(void 0);let e=r.current;e!==void 0&&zD(e);return}let e=()=>{let e=n.current;if(e===null)return;let t=e.getBoundingClientRect();if(t.width===0||t.height===0){y(!1);return}let r={top:Math.max(4,t.top+6),right:Math.max(8,window.innerWidth-t.right+18)};P(e=>e!==void 0&&e.top===r.top&&e.right===r.right?e:r)};e(),window.addEventListener(`resize`,e),window.addEventListener(`scroll`,e,!0);let t=window.setInterval(e,350);return()=>{window.removeEventListener(`resize`,e),window.removeEventListener(`scroll`,e,!0),window.clearInterval(t)}},[v]),(0,i.useEffect)(()=>{if(!v)return;if(e.visible===!1){y(!1);return}let t=n.current;if(t===null)return;let r=t.getBoundingClientRect();if(r.width===0||r.height===0){y(!1);return}if(typeof IntersectionObserver>`u`)return;let i=new IntersectionObserver(e=>{e.some(e=>!e.isIntersecting)&&y(!1)});return i.observe(t),()=>{i.disconnect()}},[v,e.visible]),(0,i.useImperativeHandle)(t,()=>({getContent:()=>r.current?.state.doc.toString()??s.current,isDirty:()=>l.current,markSaved:(e,t)=>{let n=r.current;if(n===void 0||u.current.tabId!==t)return;s.current=e;let i=_p.create({doc:e}).doc;c.current=i;let a=n.state.doc!==i&&!n.state.doc.eq(i);a!==l.current&&(l.current=a,u.current.onDirty(a))},getViewState:()=>{let e=r.current;if(e===void 0)return;let t=e.scrollDOM;return{scrollTop:t.scrollTop,scrollLeft:t.scrollLeft,cursor:e.state.selection.main.head,ranges:e.state.selection.ranges.map(e=>({anchor:e.anchor,head:e.head}))}},applyViewState:e=>{let t=r.current;if(t===void 0)return;let n=t.state.doc.length,i=e=>Math.max(0,Math.min(e,n)),a=e.ranges.map(e=>({anchor:i(e.anchor),head:i(e.head)})).filter(e=>e.anchor>=0);if(a.length>0)try{t.dispatch({selection:K.create(a.map(e=>K.range(e.anchor,e.head)))})}catch{t.dispatch({selection:{anchor:i(e.cursor)}})}let o=t.scrollDOM;o.scrollTop=e.scrollTop,o.scrollLeft=e.scrollLeft},revealRange:(e,t)=>{let n=r.current;n!==void 0&&sL(n,e,t,O)},getChangeStale:()=>r.current?.state.field(EL,!1)===!0}),[]),(0,i.useEffect)(()=>{let t=r.current;t!==void 0&&t.dispatch({effects:XL.reconfigure(_p.readOnly.of(e.readOnly===!0))})},[e.readOnly]),(0,i.useEffect)(()=>{let t=r.current;t!==void 0&&t.dispatch({effects:ZL.reconfigure(e.wrap===!1?[]:Y.lineWrapping)})},[e.wrap]),(0,i.useEffect)(()=>{e.visible!==!1&&r.current?.requestMeasure()},[e.visible]),(0,i.useEffect)(()=>{let t=r.current,n=e.savedText;if(t===void 0||n===void 0)return;let i=_p.create({doc:n}).doc,a=c.current;if(a!==void 0&&a.eq(i))return;c.current=i,s.current=n;let o=t.state.doc!==i&&!t.state.doc.eq(i);o!==l.current&&(l.current=o,u.current.onDirty(o))},[e.savedText]);let F=e.chatEnabled===!0&&e.sessionId!==void 0&&e.remoteRoot!==void 0;(0,i.useEffect)(()=>{F||_.current.hide()},[F]),(0,i.useEffect)(()=>{let e=n.current;if(e===null)return;let t=[EC(),_p.allowMultipleSelections.of(!0),wy(),oy.of(UD({save:()=>{qD()||u.current.onSave()},openFindForSelection:e=>{let t=e.state.selection.main;if(!t.empty){let n=e.state.sliceDoc(t.from,t.to);n!==``&&n.length<=200&&S(e=>({text:n,id:e.id+1}))}y(!0)},stepFind:(e,t)=>{BD(e,t)},stepHunk:e=>{let t=u.current.onStepHunk;return t===void 0?!1:(t(e),!0)},closeFind:()=>b.current?(y(!1),!0):!1,gotoLine:e=>{(async()=>{let t=u.current.t??d,n=e.state.doc.lines,i=e.state.doc.lineAt(e.state.selection.main.head).number,a=await gc({title:t(`editor.gotoLine`),text:t(`editor.gotoLineText`).replace(`{total}`,String(n)),initial:String(i)});if(a===void 0)return;let o=HD(a,n);if(o===void 0){H(t(`editor.gotoLineInvalid`),!0);return}r.current===e&&aL(e,o,O)})()},selectNextOccurrence:e=>IE({state:e.state,dispatch:t=>e.dispatch(t)})})),sb(),jy(),vS(),RS(),lE(),RE({top:!0}),PD,DI(),ES(xD()),YL.of([]),nL,QL.of([]),$L.of([]),VL((e,t)=>{u.current.onViewport?.(e,t)}),ZL.of(u.current.wrap===!1?[]:Y.lineWrapping),XL.of(_p.readOnly.of(u.current.readOnly===!0)),...jI(u.current.path),Y.updateListener.of(e=>{if(!e.docChanged)return;let t=c.current,n=t!==void 0&&e.state.doc!==t&&!e.state.doc.eq(t);n!==l.current&&(l.current=n,u.current.onDirty(n))}),Y.updateListener.of(e=>{let t=_.current,n=p.current;if(n.chatEnabled!==!0||n.sessionId===void 0||n.remoteRoot===void 0){t.hide();return}if(e.geometryChanged||e.viewportChanged){t.hide();return}if(!e.view.hasFocus){t.hide();return}if(!(e.selectionSet||e.docChanged||e.focusChanged))return;let r=e.state.selection.main;if(r.empty){t.hide();return}let i=e.state.sliceDoc(r.from,r.to);if(i.trim()===``){t.hide();return}let a=e.view.coordsAtPos(r.head);if(a===null){t.hide();return}let o=e.state.doc;t.show(vI(n.path,n.remoteRoot,{start:o.lineAt(r.from).number,end:o.lineAt(r.to).number},i),a.left-window.scrollX+(a.right-a.left)/2,a.top-window.scrollY)}),Y.updateListener.of(e=>{if(!e.docChanged)return;let t=e.startState.field(EL,!1),n=e.state.field(EL,!1);t===!1&&n===!0&&u.current.onChangeStale?.()}),Y.updateListener.of(e=>{if(!e.selectionSet)return;b.current&&w(e=>e+1);let t=u.current.onCaretChange;t!==void 0&&t(kI(e.state));let n=u.current.onViewState,i=u.current.tabId;if(n===void 0||i===void 0)return;let a=r.current;a!==void 0&&n(i,{scrollTop:a.scrollDOM.scrollTop,scrollLeft:a.scrollDOM.scrollLeft,cursor:a.state.selection.main.head,ranges:a.state.selection.ranges.map(e=>({anchor:e.anchor,head:e.head}))})})],i=new Y({doc:u.current.initial,extensions:t,parent:e});r.current=i;let a=u.current.savedText,o=a===void 0?i.state.doc:_p.create({doc:a}).doc;if(c.current=o,a!==void 0){s.current=a;let e=i.state.doc!==o&&!i.state.doc.eq(o);e!==l.current&&(l.current=e,u.current.onDirty(e))}E(i);let f=u.current.onCaretChange;f!==void 0&&f(kI(i.state));let m=h.current,g;if(m!==void 0){h.current=void 0;let e=i.state.doc.length,t=t=>Math.max(0,Math.min(t,e)),n=m.ranges.map(e=>K.range(t(e.anchor),t(e.head))).filter(t=>t.anchor<=e);try{let e=n.length>0?K.create(n,Math.min(n.length-1,0)):K.single(t(m.cursor));i.dispatch({selection:e})}catch{}let a=0,o=()=>{let e=r.current?.scrollDOM;e!==void 0&&(e.scrollTop!==m.scrollTop&&(e.scrollTop=m.scrollTop),e.scrollLeft!==m.scrollLeft&&(e.scrollLeft=m.scrollLeft),a+=1,a<8&&e.scrollTop!==m.scrollTop&&(g=window.requestAnimationFrame(o)))};g=window.requestAnimationFrame(o)}let v={scrollTop:0,scrollLeft:0,cursor:0,ranges:[]},x=()=>{v.scrollTop=i.scrollDOM.scrollTop,v.scrollLeft=i.scrollDOM.scrollLeft,v.cursor=i.state.selection.main.head,v.ranges=i.state.selection.ranges.map(e=>({anchor:e.anchor,head:e.head}))},C=e=>{let t=u.current.onViewState,n=u.current.tabId;if(!(t===void 0||n===void 0)){if(e===`unmount`){t(n,{...v,ranges:v.ranges.map(e=>({...e}))});return}x(),t(n,{...v,ranges:v.ranges.map(e=>({...e}))})}},T,D=()=>{v.scrollTop=i.scrollDOM.scrollTop,v.scrollLeft=i.scrollDOM.scrollLeft,T===void 0&&(T=window.requestAnimationFrame(()=>{T=void 0,C(`scroll-rAF`)}))};i.scrollDOM.addEventListener(`scroll`,D),C(`mount`);let k=()=>{i.scrollDOM.removeEventListener(`scroll`,D),T!==void 0&&window.cancelAnimationFrame(T),C(`unmount`)},A,j=t=>{if(r.current!==i)return;let n=e.querySelectorAll(`[class*="rvs-ck-"]`).length,a=e.querySelectorAll(`span[class^="rvs-t-"]`).length,o=n>0?n:a;console.info(`[dsh-remote-vs] build 1130-1443 · ${t} · colored tokens: ${o} (${u.current.path})`),u.current.onTokens?.(o)},M=window.setTimeout(()=>{let t=!eR(e)&&eL(u.current.path);if(t)try{i.dispatch({effects:YL.reconfigure($I(u.current.path,()=>eR(e)))})}catch{}A=window.setTimeout(()=>j(t?`fallback`:`grammar`),120)},250),N=window.setTimeout(()=>{try{Vx(i.state,i.viewport.to,300),i.dispatch({})}catch{}},120),ee=OI(i);return()=>{g!==void 0&&window.cancelAnimationFrame(g),window.clearTimeout(M),window.clearTimeout(N),window.clearTimeout(A),_.current.hide(),ee(),k();let e=u.current.onBuffer,t=u.current.tabId;if(l.current&&e!==void 0&&t!==void 0)try{e(t,i.state.doc.toString())}catch{}i.destroy(),r.current=void 0}},[]);let I=g.popup;return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(`div`,{style:{position:`relative`,height:`100%`,minHeight:0,overflow:`hidden`},children:(0,o.jsx)(`div`,{ref:n,className:`rvs-edge`,style:{height:`100%`}})}),v&&typeof document<`u`&&(0,a.createPortal)((0,o.jsx)(VD,{view:T,open:v,t:f,seed:x,tick:C,anchor:ee,onClose:()=>{y(!1),T?.focus()}}),document.body),I!==null&&typeof document<`u`&&(0,a.createPortal)((0,o.jsx)(`button`,{ref:g.buttonRef,type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>g.commit(),style:{position:`fixed`,left:I.left,top:I.top,transform:`translate(-50%, calc(-100% - 8px))`,zIndex:1e3,background:`rgba(30,32,44,.95)`,color:`#fff`,border:`1px solid rgba(77,107,254,.6)`,borderRadius:6,fontSize:12,padding:`4px 10px`,cursor:`pointer`,boxShadow:`0 4px 14px rgba(0,0,0,.35)`,whiteSpace:`nowrap`},children:e.addLabel??`添加到对话`}),document.body)]})});function nR(e){return typeof e==`function`?e:void 0}function rR(e){try{let t=e.get;if(typeof t!=`function`)return;let n=t.call(e,`sidebarRight`)?.mounted,r=typeof n?.getSnapshot==`function`?n.getSnapshot.call(n):void 0;return typeof r==`string`?r:void 0}catch{return}}function iR(e,t){try{let n=e.get;if(typeof n!=`function`)return;let r=n.call(e,`workspaces`)?.list;if(typeof r?.getSnapshot!=`function`)return;let i=r.getSnapshot.call(r);if(i?.phase!==`ready`||i?.state!==`idle`||!Array.isArray(i.items))return;let a=i.items.find(e=>Array.isArray(e.sessionIds)&&e.sessionIds.includes(t));return typeof a?.path==`string`?a.path:void 0}catch{return}}function aR(e){let t=rR(e);return t===void 0?{sessionId:void 0,sessionWorkspacePath:void 0}:{sessionId:t,sessionWorkspacePath:iR(e,t)}}function oR(e,t){let n=[],r=()=>{try{let r=e.get(`sessions`)?.list;typeof r?.subscribe==`function`&&n.push(r.subscribe.bind(r)(t))}catch{}};try{let i=e.get,a=typeof i==`function`?i.call(e,`sidebarRight`)?.mounted:void 0,o=typeof a?.subscribe==`function`?nR(a.subscribe.bind(a)):void 0;o===void 0?r():n.push(o(t))}catch{r()}try{let r=e.get,i=typeof r==`function`?r.call(e,`workspaces`)?.list:void 0;typeof i?.subscribe==`function`&&n.push(i.subscribe.call(i,t))}catch{}return()=>{for(let e of n)try{e()}catch{}}}function sR(e){let t=(0,i.useRef)({sessionId:void 0,sessionWorkspacePath:void 0}),n=(0,i.useCallback)(t=>e===void 0?()=>{}:oR(e,t),[e]),r=(0,i.useCallback)(()=>{if(e===void 0)return t.current;let n=aR(e),r=t.current;return r.sessionId===n.sessionId&&r.sessionWorkspacePath===n.sessionWorkspacePath?r:(t.current=n,n)},[e]);return(0,i.useSyncExternalStore)(n,r,r)}function cR(e,t){if(e===void 0)return;let n=t.hunk;if(!(n===void 0||n<0))return e[n]}function lR(e,t){return e[t]===1}function uR(e,t){let n={...e};if(n[t]===1)return delete n[t],n;let r=Object.keys(n);if(r.length>=2e3){let e=r[0];e!==void 0&&delete n[e]}return n[t]=1,n}function dR(e){if(typeof e!=`string`||e===``)return{};let t;try{t=JSON.parse(e)}catch{return{}}if(typeof t!=`object`||!t||Array.isArray(t))return{};let n={},r=0;for(let[e,i]of Object.entries(t))if(!(i!==1||e===``)&&(n[e]=1,r+=1,r>=2e3))break;return n}function fR(e){return JSON.stringify(e)}function pR(e){return`rvs.changes.confirmed.${e}`}function mR(e,t){if(t===``)return{};try{return dR(e.getItem(pR(t)))}catch{return{}}}function hR(e,t,n){if(t!==``)try{e.setItem(pR(t),fR(n))}catch{}}function gR(e,t,n){if(t===``||n===``)return!1;let r=uR(mR(e,t),n);return hR(e,t,r),lR(r,n)}function _R(e,t,n){return t===``||n===``?!1:lR(mR(e,t),n)}let vR=32*1024;function yR(e){return new TextEncoder().encode(e).length}function bR(e,t){return t===void 0?e?`staged`:`worktree`:`commit`}function xR(e){return e.hasDiff?e.capped?`summary`:e.bytes<=32768?`full`:`summary`:`pathOnly`}function SR(e){let t=0;for(let n of e.matchAll(/`+/g))n[0].length>t&&(t=n[0].length);return t}function CR(e){return"`".repeat(Math.max(3,SR(e)+1))}function wR(e){return e.split(`
7092
+ Integer Float Double Long Int32 Int64 Uint8 uint32_t int32_t uint64_t int64_t size_t FILE std string vector map set unique_ptr shared_ptr auto`.split(/\s+/).filter(e=>e!==``),zI={js:{lineComment:[`//`],block:[`/*`,`*/`],strings:[{open:"`",close:"`",escape:!0,kind:`string`},{open:`'`,close:`'`,escape:!0},{open:`"`,close:`"`,escape:!0}],keywords:new Set(PI),types:new Set(RI),callIsFunc:!0},ts:{lineComment:[`//`],block:[`/*`,`*/`],strings:[{open:"`",close:"`",escape:!0,kind:`string`},{open:`'`,close:`'`,escape:!0},{open:`"`,close:`"`,escape:!0}],keywords:new Set(PI),types:new Set(RI),callIsFunc:!0,at:!0},json:{lineComment:[],strings:[{open:`"`,close:`"`,escape:!0}],keywords:new Set([`true`,`false`,`null`]),callIsFunc:!1},python:{lineComment:[`#`],strings:[{open:`'''`,close:`'''`,escape:!1,kind:`string`},{open:`"""`,close:`"""`,escape:!1,kind:`string`},{open:`'`,close:`'`,escape:!0},{open:`"`,close:`"`,escape:!0}],keywords:new Set(FI),types:new Set(RI),callIsFunc:!0,at:!0},shell:{lineComment:[`#`],strings:[{open:`'`,close:`'`,escape:!1},{open:`"`,close:`"`,escape:!0}],keywords:new Set(II),callIsFunc:!1,backticks:!0},yaml:{lineComment:[`#`],strings:[{open:`'`,close:`'`,escape:!1},{open:`"`,close:`"`,escape:!0}],keywords:new Set(LI),callIsFunc:!1},xml:{lineComment:[],block:[`<!--`,`-->`],strings:[{open:`"`,close:`"`,escape:!1,kind:`string`},{open:`'`,close:`'`,escape:!1,kind:`string`}],keywords:new Set,callIsFunc:!1},css:{lineComment:[],block:[`/*`,`*/`],strings:[{open:`"`,close:`"`,escape:!0},{open:`'`,close:`'`,escape:!0}],keywords:new Set([`important`,`media`,`supports`,`root`,`import`,`keyframes`,`from`,`to`,`and`,`not`]),callIsFunc:!1,at:!0,hash:`attr`},markdown:{lineComment:[],block:[`<!--`,`-->`],strings:[{open:"`",close:"`",escape:!1,kind:`string`}],keywords:new Set,callIsFunc:!1},clike:{lineComment:[`//`],block:[`/*`,`*/`],strings:[{open:`"`,close:`"`,escape:!0},{open:`'`,close:`'`,escape:!0}],keywords:new Set(NI),types:new Set(RI),callIsFunc:!0,at:!0},diff:{lineComment:[],strings:[],keywords:new Set,callIsFunc:!1}},BI={js:`js`,jsx:`js`,mjs:`js`,cjs:`js`,vue:`js`,svelte:`js`,ts:`ts`,tsx:`ts`,mts:`ts`,cts:`ts`,json:`json`,jsonc:`json`,json5:`json`,lock:`json`,py:`python`,pyi:`python`,sh:`shell`,bash:`shell`,zsh:`shell`,ksh:`shell`,fish:`shell`,ps1:`shell`,yml:`yaml`,yaml:`yaml`,html:`xml`,htm:`xml`,xml:`xml`,svg:`xml`,xhtml:`xml`,css:`css`,scss:`css`,less:`css`,sass:`css`,md:`markdown`,markdown:`markdown`,mdx:`markdown`,c:`clike`,h:`clike`,cc:`clike`,cpp:`clike`,cxx:`clike`,hpp:`clike`,hh:`clike`,hxx:`clike`,java:`clike`,cs:`clike`,go:`clike`,rs:`clike`,kt:`clike`,kts:`clike`,swift:`clike`,m:`clike`,mm:`clike`,php:`clike`,scala:`clike`,groovy:`clike`,sql:`clike`,diff:`diff`,patch:`diff`};function VI(e){let t=e.replace(/\\/g,`/`).split(`/`).pop()??``,n=t.lastIndexOf(`.`);if(!(n<0||n===t.length-1))return BI[t.slice(n+1).toLowerCase()]}function HI(e){switch(e){case`js`:return`JavaScript`;case`ts`:return`TypeScript`;case`json`:return`JSON`;case`python`:return`Python`;case`shell`:return`Shell`;case`yaml`:return`YAML`;case`xml`:return`HTML/XML`;case`css`:return`CSS`;case`markdown`:return`Markdown`;case`clike`:return`C-family`;case`diff`:return`Diff`;default:return`Text`}}let UI=/[A-Za-z_$]/,WI=/[A-Za-z0-9_$]/,GI=/[0-9]/;function KI(){return{blockEnd:void 0}}function qI(e,t,n){if(t===void 0)return e===``?[]:[{text:e,kind:`plain`}];if(t===`diff`)return JI(e);if(t===`markdown`)return YI(e);let r=zI[t],i=[],a=0,o=(e,t)=>{if(e===``)return;let n=i[i.length-1];n!==void 0&&n.kind===t?n.text+=e:i.push({text:e,kind:t})};for(;a<e.length;){if(n.blockEnd!==void 0){let t=e.indexOf(n.blockEnd,a);if(t<0)return o(e.slice(a),`comment`),i;o(e.slice(a,t+n.blockEnd.length),`comment`),a=t+n.blockEnd.length,n.blockEnd=void 0;continue}let s=e[a],c=e.slice(a);if(r.lineComment?.find(e=>c.startsWith(e))!==void 0){if(t===`shell`&&a>0&&WI.test(e[a-1])){o(s,`plain`),a+=1;continue}return o(c,`comment`),i}if(r.block!==void 0&&c.startsWith(r.block[0])){n.blockEnd=r.block[1];continue}if(t===`python`&&(c.startsWith(`"""`)||c.startsWith(`'''`))){let t=c.slice(0,3),n=e.indexOf(t,a+3);if(n<0)return o(c,`string`),i;o(e.slice(a,n+3),`string`),a=n+3;continue}let l=r.strings.find(e=>c.startsWith(e.open));if(l!==void 0){let t=a+l.open.length,n=!1;for(;t<e.length;){if(l.escape&&e[t]===`\\`){t+=2;continue}if(e.startsWith(l.close,t)){t+=l.close.length,n=!0;break}t+=1}o(e.slice(a,n?t:e.length),l.kind??`string`),a=n?t:e.length;continue}if(GI.test(s)&&!WI.test(e[a-1]??``)){let t=a;for(;t<e.length&&/[0-9a-fA-FxXbBoO._eE+-]/.test(e[t]);){let n=e[t];if((n===`+`||n===`-`)&&!/[eE]/.test(e[t-1]))break;t+=1}o(e.slice(a,t),`number`),a=t;continue}if(UI.test(s)){let t=a+1;for(;t<e.length&&WI.test(e[t]);)t+=1;let n=e.slice(a,t),i=t;for(;i<e.length&&e[i]===` `;)i+=1;o(n,r.keywords.has(n)?`keyword`:r.types?.has(n)===!0?`type`:r.callIsFunc===!0&&e[i]===`(`?`func`:`plain`),a=t;continue}if(r.at===!0&&s===`@`){let t=a+1;for(;t<e.length&&WI.test(e[t]);)t+=1;o(e.slice(a,t),`meta`),a=t;continue}if(r.hash===`attr`&&s===`#`){let t=a+1;for(;t<e.length&&/[A-Za-z0-9_-]/.test(e[t]);)t+=1;o(e.slice(a,t),`attr`),a=t;continue}if(r.backticks===!0&&s==="`"){let t=e.indexOf("`",a+1),n=t<0?e.length:t+1;o(e.slice(a,n),`string`),a=n;continue}if(t===`xml`&&(s===`<`||s===`>`)){o(s,`punct`),a+=1;continue}if(/[{}()[\].,;:]/.test(s)){o(s,`punct`),a+=1;continue}if(/[+\-*/%=<>!&|^~?]/.test(s)){let t=a+1;for(;t<e.length&&/[+\-*/%=<>!&|^~?]/.test(e[t]);)t+=1;o(e.slice(a,t),`operator`),a=t;continue}o(s,`plain`),a+=1}return i}function JI(e){return e.startsWith(`@@`)||e.startsWith(`+++`)||e.startsWith(`---`)?[{text:e,kind:`meta`}]:e.startsWith(`+`)?[{text:e,kind:`insert`}]:e.startsWith(`-`)?[{text:e,kind:`delete`}]:[{text:e,kind:`plain`}]}function YI(e){let t=/^(#{1,6}\s)(.*)$/.exec(e);if(t!==null)return[{text:t[1],kind:`meta`},{text:t[2],kind:`keyword`}];let n=/^(\s*)([-*+]|\d+\.)(\s)(.*)$/.exec(e);if(n!==null)return[{text:n[1],kind:`plain`},{text:n[2],kind:`operator`},{text:n[3],kind:`plain`},{text:n[4],kind:`plain`}];if(/^\s*>/.test(e))return[{text:e,kind:`comment`}];if(/^\s*(```|~~~)/.test(e))return[{text:e,kind:`meta`}];let r=[],i=/(`[^`]*`)|(\*\*[^*]+\*\*)|(\[[^\]]*\]\([^)]*\))/g,a=0;for(let t=i.exec(e);t!==null;t=i.exec(e))t.index>a&&r.push({text:e.slice(a,t.index),kind:`plain`}),r.push({text:t[0],kind:t[1]===void 0?t[2]===void 0?`func`:`keyword`:`string`}),a=t.index+t[0].length;return a<e.length&&r.push({text:e.slice(a),kind:`plain`}),r}var XI=class{lines=[];tokensCache=void 0;source=void 0;lang;constructor(e){this.lang=e}get tokens(){return this.tokensCache===void 0&&(this.tokensCache=this.lines.map(e=>e.tokens)),this.tokensCache}lastTokenizedCount=0;refresh(e){if(e===this.source){this.lastTokenizedCount=0;return}let t=[],n=0,r;for(let i=0;i<e.lines;i+=1){let a=e.line(i+1).text,o=this.lines[i];if(o!==void 0&&o.text===a&&o.entry===r){t.push(o),r=o.exit;continue}let s=KI();s.blockEnd=r;let c=qI(a,this.lang,s);t.push({text:a,tokens:c,entry:r,exit:s.blockEnd}),r=s.blockEnd,n+=1}this.lines=t,this.tokensCache=void 0,this.source=e,this.lastTokenizedCount=n}};let ZI=new Map;function QI(e){let t=ZI.get(e);return t===void 0&&(t=bm.mark({class:`rvs-t-${e}`}),ZI.set(e,t)),t}function $I(e,t){let n=VI(e);class r{decorations=bm.none;cache=new XI(n);view;primary=!1;probedAt=0;constructor(e){this.view=e,this.rebuild()}update(e){if(this.primary)return;let n=Date.now();if((e.docChanged||n-this.probedAt>=80)&&(this.probedAt=n,this.primary=t(),this.primary)){this.decorations!==bm.none&&(this.decorations=bm.none);return}(e.docChanged||e.viewportChanged)&&this.rebuild()}rebuild(){let e=this.view.state.doc;this.cache.refresh(e);let t=this.cache.tokens;if(t.length===0){this.decorations=bm.none;return}let n=new Dp;for(let r of this.view.visibleRanges){let i=e.lineAt(r.from).number,a=e.lineAt(r.to).number;for(let r=i;r<=a&&r<=t.length;r+=1){let i=e.line(r),a=t[r-1]??[],o=i.from;for(let e of a){let t=e.text.length;e.kind!==`plain`&&t>0&&o+t<=i.to&&n.add(o,o+t,QI(e.kind)),o+=t}}}this.decorations=n.finish()}}return Kh.fromClass(r,{decorations:e=>e.decorations})}function eL(e){return VI(e)!==void 0}let tL=np.define(),nL=Ff.define({create:()=>bm.none,update(e,t){let n=e.map(t.changes);for(let e of t.effects)e.is(tL)&&(n=e.value===null?bm.none:bm.set([bm.line({class:`rvs-reveal-line`}).range(e.value)]));return n},provide:e=>Y.decorations.from(e)}),rL=new WeakMap;function iL(e,t){let n=rL.get(e);n!==void 0&&window.clearTimeout(n);let r=window.setTimeout(()=>{rL.delete(e);try{t(null)}catch{}},2600);rL.set(e,r)}function aL(e,t,n){let r=0;try{let i=Math.min(Math.max(1,Math.round(t)),e.state.doc.lines);r=e.state.doc.line(i).number;let a=e.state.doc.line(r).from;e.dispatch({selection:{anchor:a},effects:Y.scrollIntoView(a,{y:`center`})}),n(a)}catch{return}e.focus(),window.setTimeout(()=>{try{oL(e,r)?.scrollIntoView({block:`center`,inline:`nearest`})}catch{}},30),iL(e,n)}function oL(e,t){let n=e.state.doc.line(t).from;if(n<e.viewport.from||n>e.viewport.to)return null;let r=e.domAtPos(n).node;for(;r!==null&&r!==e.dom;){if(r instanceof HTMLElement&&r.classList.contains(`cm-line`))return r;r=r.parentNode}return null}function sL(e,t,n,r){let i=0;try{let a=e.state.doc.lines,o=Math.min(Math.max(1,Math.round(Math.min(t,n))),a),s=Math.min(Math.max(o,Math.round(Math.max(t,n))),a),c=e.state.doc.line(o),l=e.state.doc.line(s);i=o,e.dispatch({selection:K.range(c.from,l.to),effects:Y.scrollIntoView(c.from,{y:`center`})}),r?.(c.from)}catch{return}e.focus(),window.setTimeout(()=>{try{oL(e,i)?.scrollIntoView({block:`center`,inline:`nearest`})}catch{}},30),r!==void 0&&iL(e,r)}let cL=np.define(),lL={add:0,mod:1,del:2},uL={add:`+`,mod:`●`,del:`−`},dL=new Dp().finish(),fL=new Map;function pL(e){let t=fL.get(e);return t===void 0&&(t=bm.line({class:`rvs-change-line rvs-change-${e}`}),fL.set(e,t)),t}let mL=bm.mark({class:`rvs-change-word-add`});var hL=class e extends vm{text;truncated;count;chipTitle;blockTitle;removedLines;constructor(e,t,n,r){super(),this.text=e,this.truncated=t,this.count=n,this.chipTitle=r(`changes.deletedChip`),this.blockTitle=r(`changes.deletedBlock`),this.removedLines=r(`changes.deletedLines`)}eq(t){return t instanceof e&&t.text===this.text&&t.truncated===this.truncated&&t.count===this.count&&t.chipTitle===this.chipTitle&&t.blockTitle===this.blockTitle&&t.removedLines===this.removedLines}toDOM(){let e=document.createElement(`span`),t=this.count>1;return e.className=t?`rvs-change-word-del rvs-change-block-del`:`rvs-change-word-del`,e.textContent=t?this.removedLines.replace(`{count}`,String(this.count)):this.truncated?`${this.text}…`:this.text,e.title=t?`${this.blockTitle.replace(`{count}`,String(this.count))}\n${this.text}`:this.chipTitle,e.setAttribute(`aria-label`,e.title),e}};function gL(e,t){return bm.widget({widget:new hL(e.text,e.truncated,e.count??0,t),side:-1})}function _L(e,t){let n=new Map;if(e===null)return n;let r=t.lines,i=e=>{let t=n.get(e);return t===void 0&&(t={ranges:[],chips:[]},n.set(e,t)),t};for(let t of e.marks){let e=xL(t.from,r);for(let n of t.inline??[]){let t=Math.max(0,Math.round(n.from)),a=Math.max(t,Math.round(n.to));a!==t&&i(xL(n.line??e,r)).ranges.push({from:t,to:a})}for(let n of t.removed??[])n.text!==``&&i(xL(n.line??e,r)).chips.push({at:Math.max(0,Math.round(n.at)),text:n.text,truncated:n.truncated===!0,...n.count===void 0?{}:{count:n.count}})}for(let e of n.values()){e.ranges.sort((e,t)=>e.from-t.from||e.to-t.to);let t=[];for(let n of e.ranges){let e=t[t.length-1];e!==void 0&&n.from<=e.to?e.to=Math.max(e.to,n.to):t.push({from:n.from,to:n.to})}e.ranges=t}return n}var vL=class e extends By{kind;elementClass;label;constructor(e,t){super(),this.kind=e,this.elementClass=`rvs-change-gutter-${e}`,this.label=t}eq(t){return t instanceof e&&t.kind===this.kind}toDOM(){let e=document.createElement(`span`);return e.className=`rvs-change-mark rvs-change-mark-${this.kind}`,e.textContent=uL[this.kind],e.title=this.label,e.setAttribute(`aria-label`,this.label),e}};function yL(e){return{add:new vL(`add`,e(`changes.markAdd`)),mod:new vL(`mod`,e(`changes.markMod`)),del:new vL(`del`,e(`changes.markDel`))}}let bL=new class extends By{toDOM(){let e=document.createElement(`span`);return e.className=`rvs-change-mark rvs-change-spacer`,e.textContent=`+`,e.setAttribute(`aria-hidden`,`true`),e}};function xL(e,t){return Number.isFinite(e)?Math.min(Math.max(1,Math.round(e)),t):1}function SL(e,t){if(e===null||e.marks.length===0)return[];let n=t.lines,r=[];for(let t of e.marks){let e=t.kind;if(e!==`add`&&e!==`mod`&&e!==`del`)continue;let i=xL(t.from,n),a=Math.min(Math.max(i,xL(t.to,n)),n);r.push({first:i,last:a,kind:e})}r.sort((e,t)=>e.first-t.first||lL[e.kind]-lL[t.kind]);let i=[];for(let e of r){let t=i[i.length-1],n=t===void 0?e.first:Math.max(e.first,t.last+1);n>e.last||i.push({first:n,last:e.last,kind:e.kind})}return i}let CL={set:null,spans:[],inline:new Map};function wL(e,t){for(let e of t.effects)if(e.is(cL))return e.value;return t.docChanged?null:e}let TL=Ff.define({create:()=>CL,update(e,t){let n=wL(e.set,t);return n===e.set?e:n===null?CL:{set:n,spans:SL(n,t.newDoc),inline:_L(n,t.newDoc)}}}),EL=Ff.define({create:()=>!1,update(e,t){for(let e of t.effects)if(e.is(cL))return!1;return t.docChanged?!0:e}});function DL(e){return e.field(TL,!1)?.set??null}function OL(e,t){let n=e.field(TL,!1)?.spans??[],r=Math.max(1,Math.round(t));for(let e of n)if(r>=e.first&&r<=e.last)return{from:e.first,to:e.last};return{from:r,to:r}}function kL(e,t){let n=0,r=e.length;for(;n<r;){let i=n+r>>>1;e[i].last<t?n=i+1:r=i}return n}var AL=class{decorations=bm.none;view;t;constructor(e,t){this.view=e,this.t=t,this.rebuild()}update(e){(e.docChanged||e.viewportChanged||e.startState.field(TL,!1)!==e.state.field(TL,!1))&&this.rebuild()}rebuild(){let e=this.view.state,t=e.field(TL,!1),n=t?.spans??[],r=t?.inline;if(n.length===0&&(r===void 0||r.size===0)){this.decorations=bm.none;return}let i=e.doc,a=new Dp;for(let e of this.view.visibleRanges){let t=i.lineAt(e.from).number,o=i.lineAt(e.to).number,s=kL(n,t);for(let e=t;e<=o;e+=1){let t=i.line(e);for(;s<n.length&&n[s].last<e;)s+=1;let o=s<n.length&&n[s].first<=e?n[s]:void 0,c=r?.get(e);if(o===void 0&&c===void 0)continue;let l=[];if(o!==void 0&&l.push({from:t.from,to:t.from,decoration:pL(o.kind)}),c!==void 0){for(let e of c.chips){let n=t.from+Math.min(e.at,t.length);l.push({from:n,to:n,decoration:gL(e,this.t)})}for(let e of c.ranges){let n=t.from+Math.min(e.from,t.length),r=t.from+Math.min(e.to,t.length);r>n&&l.push({from:n,to:r,decoration:mL})}}l.sort((e,t)=>e.from-t.from||e.decoration.startSide-t.decoration.startSide);for(let e of l)a.add(e.from,e.to,e.decoration)}}this.decorations=a.finish()}};function jL(e){return Kh.fromClass(class extends AL{constructor(t){super(t,e)}},{decorations:e=>e.decorations})}let ML;function NL(e,t){let n=e.state.field(TL,!1)??CL,r=e.viewport.from,i=e.viewport.to,a=ML;if(a!==void 0&&a.state===n&&a.from===r&&a.to===i&&a.owner===t)return a.markers;let o=dL;if(n.spans.length>0){let a=e.state.doc,s=a.lineAt(r).number,c=a.lineAt(i).number,l=new Dp;for(let e=kL(n.spans,s);e<n.spans.length;e+=1){let r=n.spans[e];if(r.first>c)break;let i=Math.max(r.first,s),o=Math.min(r.last,c),u=t[r.kind];for(let e=i;e<=o;e+=1){let t=a.line(e);l.add(t.from,t.to,u)}}o=l.finish()}return ML={state:n,from:r,to:i,owner:t,markers:o},o}function PL(e){let t=yL(e);return[TL,EL,Gy({class:`rvs-change-gutter`,markers:e=>NL(e,t),initialSpacer:()=>bL,lineMarkerChange:e=>e.startState.field(TL,!1)!==e.state.field(TL,!1)}),jL(e)]}var FL=class e extends By{text;title;committed;constructor(e,t,n){super(),this.text=e,this.title=t,this.committed=n}toDOM(){let e=document.createElement(`span`);return e.className=this.text===``?`rvs-blame-cont`:`rvs-blame-chip${this.committed?``:` rvs-blame-uncommitted`}`,e.textContent=this.text,this.title!==``&&(e.title=this.title),e}eq(t){return t instanceof e&&t.text===this.text&&t.title===this.title}};let IL=new Dp().finish(),LL=new class extends By{toDOM(){let e=document.createElement(`span`);return e.className=`rvs-blame-spacer`,e.textContent=`author · 00y`,e}};function RL(e,t,n){let r=e.state.doc,i=Math.max(1,r.lineAt(e.viewport.from).number),a=Math.min(r.lines,r.lineAt(e.viewport.to).number);if(t.size===0||a<i)return IL;let o=new Set(ai([...t.values()].sort((e,t)=>e.line-t.line)).map(e=>e.from)),s=new Dp;for(let e=i;e<=a;e+=1){let i=t.get(e);if(i===void 0)continue;let a=o.has(e)?new FL(ci(i,n),li(i),ui(i.hash)):new FL(``,``,!0),c=r.line(e);s.add(c.from,c.to,a)}return s.finish()}function zL(e){let t=t=>{let n=t.state.doc;e(n.lineAt(t.viewport.from).number,n.lineAt(t.viewport.to).number)};return Kh.fromClass(class{constructor(e){t(e)}update(e){!e.viewportChanged&&!e.docChanged||t(e.view)}})}function BL(e,t){let n=Math.floor(Date.now()/1e3),r=(n,r,i)=>{let a=n.state.doc.lineAt(r.from).number,o=e.get(a);return o===void 0||!ui(o.hash)?!1:(i.preventDefault(),t?.(o),!0)};return[Gy({class:`rvs-blame-gutter`,markers:t=>RL(t,e,n),initialSpacer:()=>LL,domEventHandlers:t===void 0?{}:{mousedown(e,t,n){return r(e,t,n)}}})]}function VL(e){return zL(e)}let HL=`2100`;function UL(e,t){let n=DL(e);if(n===null)return;let r;for(let e of n.marks)if(!(t<e.from||t>e.to)){if(e.kind!==`del`)return e;r??=e}return r}function WL(e){return e.state.readOnly}function GL(e,t){let n=t.target instanceof Node?t.target:null;return n===null||!e.contentDOM.contains(n)?null:(n instanceof Element?n:n.parentElement)?.closest(`.cm-line`)??null}function KL(e,t){let n=GL(e,t);if(n!==null)try{return e.state.doc.lineAt(e.posAtDOM(n,0)).number}catch{}try{let n=e.posAtCoords({x:t.clientX,y:t.clientY});return n===null?null:e.state.doc.lineAt(n).number}catch{return null}}var qL=class{rvsUndoAffordance=!0;view;onUndo;label;triggerLabel;hoverTime;confirm;trigger;menu;undoItem;confirmItem;menuOpen=!1;timer;leaveTimer;hovered;shown;onGlobalMouseDown=e=>{if(this.shown===void 0)return;let t=e.target instanceof Node?e.target:null;for(let e of[this.trigger,this.menu])if(e!==void 0&&t!==null&&e.contains(t))return;this.reset()};onGlobalKeyDown=e=>{e.key!==`Escape`||this.shown===void 0||this.reset()};onWindowBlur=()=>this.reset();onVisibilityChange=()=>{document.hidden&&this.reset()};constructor(e,t){this.view=e,this.onUndo=t.onUndo??(()=>{}),this.label=t.label??(()=>`撤销这处改动`),this.triggerLabel=t.triggerLabel??(()=>`改动操作`),this.hoverTime=t.hoverTime??300,this.confirm=t.confirm,document.addEventListener(`mousedown`,this.onGlobalMouseDown,!0),document.addEventListener(`keydown`,this.onGlobalKeyDown,!0),document.addEventListener(`visibilitychange`,this.onVisibilityChange),window.addEventListener(`blur`,this.onWindowBlur)}handleMove(e){if(this.cancelLeave(),this.menuHasFocus())return;if(WL(this.view)){this.reset();return}if(e.buttons!==0){this.reset();return}let t=KL(this.view,e),n=t===null?void 0:UL(this.view.state,t);if(t===null||n===void 0){this.reset();return}let r=this.hovered;r!==void 0&&r.line===t&&r.mark===n||(this.reset(),this.hovered={mark:n,line:t,element:GL(this.view,e)},this.timer=window.setTimeout(()=>{this.arm()},this.hoverTime))}handleLeave(){if(this.shown===void 0){this.reset();return}this.scheduleLeave()}arm(){this.timer=void 0;let e=this.hovered;if(e!==void 0){if(WL(this.view)){this.reset();return}if(UL(this.view.state,e.line)!==e.mark){this.reset();return}this.shown=e,this.show(e)}}ensureTrigger(){let e=this.trigger;if(e!==void 0)return e;let t=document.createElement(`button`);return t.type=`button`,t.className=`rvs-change-actions`,t.textContent=`⋯`,t.setAttribute(`aria-haspopup`,`menu`),t.setAttribute(`aria-expanded`,`false`),t.style.position=`fixed`,t.style.zIndex=HL,t.addEventListener(`mousedown`,e=>{e.preventDefault()}),t.addEventListener(`mouseenter`,()=>{this.cancelLeave()}),t.addEventListener(`mouseleave`,()=>{this.scheduleLeave()}),t.addEventListener(`click`,()=>{this.shown!==void 0&&(this.menuOpen?this.closeMenu():this.openMenu())}),this.trigger=t,t}ensureMenu(){let e=this.menu;if(e!==void 0)return e;let t=document.createElement(`div`);t.className=`rvs-change-actions-menu`,t.setAttribute(`role`,`menu`),t.style.position=`fixed`,t.style.zIndex=HL,t.hidden=!0,t.addEventListener(`mouseenter`,()=>{this.cancelLeave()}),t.addEventListener(`mouseleave`,()=>{this.scheduleLeave()}),t.addEventListener(`mousedown`,e=>{e.preventDefault()});let n=document.createElement(`button`);n.type=`button`,n.className=`rvs-change-actions-undo`,n.setAttribute(`role`,`menuitem`),n.addEventListener(`click`,()=>{let e=this.shown;this.reset(),e!==void 0&&this.onUndo(e.mark)}),t.appendChild(n);let r=this.confirm;if(r!==void 0){let e=document.createElement(`button`);e.type=`button`,e.className=`rvs-change-actions-confirm`,e.setAttribute(`role`,`menuitem`),e.addEventListener(`click`,()=>{let e=this.shown;e!==void 0&&(r.onToggle(e.mark),this.syncConfirm(e.mark),this.placeMenu())}),t.appendChild(e),this.confirmItem=e}return this.undoItem=n,this.menu=t,t}syncItems(e){let t=this.undoItem;if(t!==void 0){let n=this.label(e);t.textContent!==n&&(t.textContent=n),t.title=n,t.setAttribute(`aria-label`,n),t.dataset.kind=e.kind,t.dataset.hunk=String(e.hunk??-1)}this.syncConfirm(e)}syncConfirm(e){let t=this.confirm,n=this.confirmItem;if(t===void 0||n===void 0)return;let r=t.isConfirmed(e),i=r?t.pressedLabel?.(e)??t.label(e):t.label(e);n.textContent!==i&&(n.textContent=i),n.title=i,n.setAttribute(`aria-label`,i),n.setAttribute(`aria-pressed`,r?`true`:`false`),n.dataset.confirmed=r?`1`:`0`,n.classList.toggle(`is-on`,r)}cancelLeave(){this.leaveTimer!==void 0&&(window.clearTimeout(this.leaveTimer),this.leaveTimer=void 0)}scheduleLeave(){this.cancelLeave(),this.leaveTimer=window.setTimeout(()=>{this.leaveTimer=void 0,!this.menuHasFocus()&&this.reset()},150)}menuHasFocus(){let e=this.menu;return e===void 0||!this.menuOpen?!1:e.contains(document.activeElement)}show(e){let t=this.ensureTrigger(),n=this.triggerLabel();t.title=n,t.setAttribute(`aria-label`,n),t.parentNode===null&&document.body.appendChild(t);let r=this.ensureMenu();r.parentNode===null&&document.body.appendChild(r),this.syncItems(e.mark),this.placeTrigger(e)||(t.remove(),r.remove())}placeTrigger(e){let t=this.trigger;if(t===void 0)return!1;let n=this.rectFor(e);if(n===null)return!1;let r=t.getBoundingClientRect().width,i=window.innerWidth-8,a=n.right+8;return a=r>0&&a+r>i?Math.max(8,i-r):Math.min(a,i),t.style.left=`${Math.round(a)}px`,t.style.top=`${Math.round((n.top+n.bottom)/2)}px`,this.menuOpen&&this.placeMenu(),!0}placeMenu(){let e=this.menu,t=this.trigger;if(e===void 0||t===void 0)return;let n=t.getBoundingClientRect(),r=e.getBoundingClientRect(),i=window.innerWidth-4,a=window.innerHeight-4,o=r.width,s=n.right-o;s=Math.max(4,Math.min(s,i-o));let c=n.bottom,l=`below`;r.height>0&&c+r.height>a&&(c=n.top-r.height,l=`above`),e.dataset.side=l,e.style.left=`${Math.round(s)}px`,e.style.top=`${Math.round(c)}px`}openMenu(){let e=this.ensureMenu();e.parentNode===null&&document.body.appendChild(e),this.menuOpen=!0,this.trigger?.setAttribute(`aria-expanded`,`true`),e.hidden=!1,this.placeMenu()}closeMenu(){this.menuOpen=!1,this.trigger?.setAttribute(`aria-expanded`,`false`);let e=this.menu;e!==void 0&&(e.hidden=!0)}rectFor(e){let t=this.view.state.doc,n=t.line(Math.min(Math.max(1,e.line),t.lines));try{let e=this.view.coordsAtPos(n.to);if(e!==null&&Number.isFinite(e.top)&&Number.isFinite(e.right))return e}catch{}let r=e.element?.getBoundingClientRect();return r===void 0?null:{left:r.left,right:r.right,top:r.top,bottom:r.bottom}}reset(){this.timer!==void 0&&(window.clearTimeout(this.timer),this.timer=void 0),this.cancelLeave(),this.hovered=void 0,this.shown=void 0,this.closeMenu();let e=this.trigger;e!==void 0&&e.parentNode!==null&&e.remove();let t=this.menu;t!==void 0&&t.parentNode!==null&&t.remove()}update(e){if(e.docChanged||e.viewportChanged||e.geometryChanged){this.reset();return}DL(e.startState)!==DL(e.state)&&this.reset()}destroy(){this.reset(),this.trigger?.remove(),this.trigger=void 0,this.menu?.remove(),this.menu=void 0,this.undoItem=void 0,this.confirmItem=void 0,document.removeEventListener(`mousedown`,this.onGlobalMouseDown,!0),document.removeEventListener(`keydown`,this.onGlobalKeyDown,!0),document.removeEventListener(`visibilitychange`,this.onVisibilityChange),window.removeEventListener(`blur`,this.onWindowBlur)}};function JL(e={}){return e.onUndo===void 0||typeof document>`u`?[]:Kh.define(t=>new qL(t,e),{eventHandlers:{mousemove(e){return this.handleMove(e),!1},mouseleave(){return this.handleLeave(),!1}}})}let YL=new Bf,XL=new Bf,ZL=new Bf,QL=new Bf,$L=new Bf;function eR(e){return e.querySelector(`[class*="rvs-ck-"]`)!==null}let tR=(0,i.forwardRef)(function(e,t){let n=(0,i.useRef)(null),r=(0,i.useRef)(void 0),s=(0,i.useRef)(e.initial),c=(0,i.useRef)(void 0),l=(0,i.useRef)(!1),u=(0,i.useRef)(e);u.current=e;let d=(0,i.useMemo)(()=>fe(de()),[]),f=e.t??d,p=(0,i.useRef)({sessionId:e.sessionId,remoteRoot:e.remoteRoot,chatEnabled:e.chatEnabled,path:e.path});p.current={sessionId:e.sessionId,remoteRoot:e.remoteRoot,chatEnabled:e.chatEnabled,path:e.path};let m=(0,i.useRef)(e.ctx);m.current=e.ctx;let h=(0,i.useRef)(e.viewState),g=yI({onCommit:e=>{let t=m.current,n=p.current.sessionId;t!==void 0&&n!==void 0&&dI(t,n,e)},getSurface:()=>n.current}),_=(0,i.useRef)(g);_.current=g;let[v,y]=(0,i.useState)(!1),b=(0,i.useRef)(!1);b.current=v;let[x,S]=(0,i.useState)({text:``,id:0}),[C,w]=(0,i.useState)(0),[T,E]=(0,i.useState)(void 0),[D,O]=(0,i.useState)(null);(0,i.useEffect)(()=>{let e=r.current;if(e!==void 0)try{e.dispatch({effects:tL.of(D)})}catch{}},[D,T]),(0,i.useEffect)(()=>{let t=e.revealLine;if(t===void 0||t<=0)return;let n=r.current;if(n===void 0)return;let i=window.setTimeout(()=>aL(n,t,O),60);return()=>window.clearTimeout(i)},[e.revealLine,e.revealNonce,T]);let k=(0,i.useRef)(``),A=(0,i.useRef)(void 0),j=(0,i.useRef)(f),M=e.onUndoChange!==void 0,N=e.blockConfirm!==void 0;(0,i.useEffect)(()=>{let t=r.current;if(t===void 0)return;j.current!==f&&(j.current=f,k.current=``);let n=e.changeSet,i=n!==void 0,a=`${i?`m`:``}${M?`u`:``}${N?`c`:``}`;if(a!==k.current){k.current=a,A.current=void 0;let e=[...i?[PL(f)]:[],...M?[JL({onUndo:e=>{u.current.onUndoChange?.(e)},label:e=>u.current.undoLabel?.(e)??`撤销这处改动`,triggerLabel:()=>u.current.undoTriggerLabel?.()??`改动操作`,...N?{confirm:{isConfirmed:e=>u.current.blockConfirm?.isConfirmed(e)===!0,onToggle:e=>{u.current.blockConfirm?.onToggle(e)},label:e=>u.current.blockConfirm?.label(e)??`确认保留`,pressedLabel:e=>u.current.blockConfirm?.pressedLabel?.(e)??u.current.blockConfirm?.label(e)??`已确认保留`}}:{}})]:[]];try{t.dispatch({effects:QL.reconfigure(e)})}catch{return}}if(n!==void 0&&n!==A.current){A.current=n;try{t.dispatch({effects:cL.of(n)})}catch{}}},[e.changeSet,M,N,T,f]),(0,i.useEffect)(()=>{let t=r.current;if(t===void 0)return;let n=e.blame,i=n!=null&&n.size>0?BL(n,e=>{u.current.onOpenBlame?.(e)}):[];try{t.dispatch({effects:$L.reconfigure(i)})}catch{}},[e.blame]),(0,i.useEffect)(()=>{let t=e.revealHunkLine;if(t===void 0||t<=0)return;let n=r.current;if(n===void 0)return;let i=window.setTimeout(()=>{let e=OL(n.state,t);aL(n,e.from,O)},40);return()=>window.clearTimeout(i)},[e.revealHunkLine,e.revealHunkNonce,T]);let[ee,P]=(0,i.useState)(void 0);(0,i.useEffect)(()=>{if(!v){P(void 0);let e=r.current;e!==void 0&&zD(e);return}let e=()=>{let e=n.current;if(e===null)return;let t=e.getBoundingClientRect();if(t.width===0||t.height===0){y(!1);return}let r={top:Math.max(4,t.top+6),right:Math.max(8,window.innerWidth-t.right+18)};P(e=>e!==void 0&&e.top===r.top&&e.right===r.right?e:r)};e(),window.addEventListener(`resize`,e),window.addEventListener(`scroll`,e,!0);let t=window.setInterval(e,350);return()=>{window.removeEventListener(`resize`,e),window.removeEventListener(`scroll`,e,!0),window.clearInterval(t)}},[v]),(0,i.useEffect)(()=>{if(!v)return;if(e.visible===!1){y(!1);return}let t=n.current;if(t===null)return;let r=t.getBoundingClientRect();if(r.width===0||r.height===0){y(!1);return}if(typeof IntersectionObserver>`u`)return;let i=new IntersectionObserver(e=>{e.some(e=>!e.isIntersecting)&&y(!1)});return i.observe(t),()=>{i.disconnect()}},[v,e.visible]),(0,i.useImperativeHandle)(t,()=>({getContent:()=>r.current?.state.doc.toString()??s.current,isDirty:()=>l.current,markSaved:(e,t)=>{let n=r.current;if(n===void 0||u.current.tabId!==t)return;s.current=e;let i=_p.create({doc:e}).doc;c.current=i;let a=n.state.doc!==i&&!n.state.doc.eq(i);a!==l.current&&(l.current=a,u.current.onDirty(a))},getViewState:()=>{let e=r.current;if(e===void 0)return;let t=e.scrollDOM;return{scrollTop:t.scrollTop,scrollLeft:t.scrollLeft,cursor:e.state.selection.main.head,ranges:e.state.selection.ranges.map(e=>({anchor:e.anchor,head:e.head}))}},applyViewState:e=>{let t=r.current;if(t===void 0)return;let n=t.state.doc.length,i=e=>Math.max(0,Math.min(e,n)),a=e.ranges.map(e=>({anchor:i(e.anchor),head:i(e.head)})).filter(e=>e.anchor>=0);if(a.length>0)try{t.dispatch({selection:K.create(a.map(e=>K.range(e.anchor,e.head)))})}catch{t.dispatch({selection:{anchor:i(e.cursor)}})}let o=t.scrollDOM;o.scrollTop=e.scrollTop,o.scrollLeft=e.scrollLeft},revealRange:(e,t)=>{let n=r.current;n!==void 0&&sL(n,e,t,O)},getChangeStale:()=>r.current?.state.field(EL,!1)===!0}),[]),(0,i.useEffect)(()=>{let t=r.current;t!==void 0&&t.dispatch({effects:XL.reconfigure(_p.readOnly.of(e.readOnly===!0))})},[e.readOnly]),(0,i.useEffect)(()=>{let t=r.current;t!==void 0&&t.dispatch({effects:ZL.reconfigure(e.wrap===!1?[]:Y.lineWrapping)})},[e.wrap]),(0,i.useEffect)(()=>{e.visible!==!1&&r.current?.requestMeasure()},[e.visible]),(0,i.useEffect)(()=>{let t=r.current,n=e.savedText;if(t===void 0||n===void 0)return;let i=_p.create({doc:n}).doc,a=c.current;if(a!==void 0&&a.eq(i))return;c.current=i,s.current=n;let o=t.state.doc!==i&&!t.state.doc.eq(i);o!==l.current&&(l.current=o,u.current.onDirty(o))},[e.savedText]);let F=e.chatEnabled===!0&&e.sessionId!==void 0&&e.remoteRoot!==void 0;(0,i.useEffect)(()=>{F||_.current.hide()},[F]),(0,i.useEffect)(()=>{let e=n.current;if(e===null)return;let t=[EC(),_p.allowMultipleSelections.of(!0),wy(),oy.of(UD({save:()=>{qD()||u.current.onSave()},openFindForSelection:e=>{let t=e.state.selection.main;if(!t.empty){let n=e.state.sliceDoc(t.from,t.to);n!==``&&n.length<=200&&S(e=>({text:n,id:e.id+1}))}y(!0)},stepFind:(e,t)=>{BD(e,t)},stepHunk:e=>{let t=u.current.onStepHunk;return t===void 0?!1:(t(e),!0)},closeFind:()=>b.current?(y(!1),!0):!1,gotoLine:e=>{(async()=>{let t=u.current.t??d,n=e.state.doc.lines,i=e.state.doc.lineAt(e.state.selection.main.head).number,a=await gc({title:t(`editor.gotoLine`),text:t(`editor.gotoLineText`).replace(`{total}`,String(n)),initial:String(i)});if(a===void 0)return;let o=HD(a,n);if(o===void 0){H(t(`editor.gotoLineInvalid`),!0);return}r.current===e&&aL(e,o,O)})()},selectNextOccurrence:e=>IE({state:e.state,dispatch:t=>e.dispatch(t)})})),sb(),jy(),vS(),RS(),lE(),RE({top:!0}),PD,DI(),ES(xD()),YL.of([]),nL,QL.of([]),$L.of([]),VL((e,t)=>{u.current.onViewport?.(e,t)}),ZL.of(u.current.wrap===!1?[]:Y.lineWrapping),XL.of(_p.readOnly.of(u.current.readOnly===!0)),...jI(u.current.path),Y.updateListener.of(e=>{if(!e.docChanged)return;let t=c.current,n=t!==void 0&&e.state.doc!==t&&!e.state.doc.eq(t);n!==l.current&&(l.current=n,u.current.onDirty(n))}),Y.updateListener.of(e=>{let t=_.current,n=p.current;if(n.chatEnabled!==!0||n.sessionId===void 0||n.remoteRoot===void 0){t.hide();return}if(e.geometryChanged||e.viewportChanged){t.hide();return}if(!e.view.hasFocus){t.hide();return}if(!(e.selectionSet||e.docChanged||e.focusChanged))return;let r=e.state.selection.main;if(r.empty){t.hide();return}let i=e.state.sliceDoc(r.from,r.to);if(i.trim()===``){t.hide();return}let a=e.view.coordsAtPos(r.head);if(a===null){t.hide();return}let o=e.state.doc;t.show(vI(n.path,n.remoteRoot,{start:o.lineAt(r.from).number,end:o.lineAt(r.to).number},i),a.left-window.scrollX+(a.right-a.left)/2,a.top-window.scrollY)}),Y.updateListener.of(e=>{if(!e.docChanged)return;let t=e.startState.field(EL,!1),n=e.state.field(EL,!1);t===!1&&n===!0&&u.current.onChangeStale?.()}),Y.updateListener.of(e=>{if(!e.selectionSet)return;b.current&&w(e=>e+1);let t=u.current.onCaretChange;t!==void 0&&t(kI(e.state));let n=u.current.onViewState,i=u.current.tabId;if(n===void 0||i===void 0)return;let a=r.current;a!==void 0&&n(i,{scrollTop:a.scrollDOM.scrollTop,scrollLeft:a.scrollDOM.scrollLeft,cursor:a.state.selection.main.head,ranges:a.state.selection.ranges.map(e=>({anchor:e.anchor,head:e.head}))})})],i=new Y({doc:u.current.initial,extensions:t,parent:e});r.current=i;let a=u.current.savedText,o=a===void 0?i.state.doc:_p.create({doc:a}).doc;if(c.current=o,a!==void 0){s.current=a;let e=i.state.doc!==o&&!i.state.doc.eq(o);e!==l.current&&(l.current=e,u.current.onDirty(e))}E(i);let f=u.current.onCaretChange;f!==void 0&&f(kI(i.state));let m=h.current,g;if(m!==void 0){h.current=void 0;let e=i.state.doc.length,t=t=>Math.max(0,Math.min(t,e)),n=m.ranges.map(e=>K.range(t(e.anchor),t(e.head))).filter(t=>t.anchor<=e);try{let e=n.length>0?K.create(n,Math.min(n.length-1,0)):K.single(t(m.cursor));i.dispatch({selection:e})}catch{}let a=0,o=()=>{let e=r.current?.scrollDOM;e!==void 0&&(e.scrollTop!==m.scrollTop&&(e.scrollTop=m.scrollTop),e.scrollLeft!==m.scrollLeft&&(e.scrollLeft=m.scrollLeft),a+=1,a<8&&e.scrollTop!==m.scrollTop&&(g=window.requestAnimationFrame(o)))};g=window.requestAnimationFrame(o)}let v={scrollTop:0,scrollLeft:0,cursor:0,ranges:[]},x=()=>{v.scrollTop=i.scrollDOM.scrollTop,v.scrollLeft=i.scrollDOM.scrollLeft,v.cursor=i.state.selection.main.head,v.ranges=i.state.selection.ranges.map(e=>({anchor:e.anchor,head:e.head}))},C=e=>{let t=u.current.onViewState,n=u.current.tabId;if(!(t===void 0||n===void 0)){if(e===`unmount`){t(n,{...v,ranges:v.ranges.map(e=>({...e}))});return}x(),t(n,{...v,ranges:v.ranges.map(e=>({...e}))})}},T,D=()=>{v.scrollTop=i.scrollDOM.scrollTop,v.scrollLeft=i.scrollDOM.scrollLeft,T===void 0&&(T=window.requestAnimationFrame(()=>{T=void 0,C(`scroll-rAF`)}))};i.scrollDOM.addEventListener(`scroll`,D),C(`mount`);let k=()=>{i.scrollDOM.removeEventListener(`scroll`,D),T!==void 0&&window.cancelAnimationFrame(T),C(`unmount`)},A,j=t=>{if(r.current!==i)return;let n=e.querySelectorAll(`[class*="rvs-ck-"]`).length,a=e.querySelectorAll(`span[class^="rvs-t-"]`).length,o=n>0?n:a;console.info(`[dsh-remote-vs] build 1201-1443 · ${t} · colored tokens: ${o} (${u.current.path})`),u.current.onTokens?.(o)},M=window.setTimeout(()=>{let t=!eR(e)&&eL(u.current.path);if(t)try{i.dispatch({effects:YL.reconfigure($I(u.current.path,()=>eR(e)))})}catch{}A=window.setTimeout(()=>j(t?`fallback`:`grammar`),120)},250),N=window.setTimeout(()=>{try{Vx(i.state,i.viewport.to,300),i.dispatch({})}catch{}},120),ee=OI(i);return()=>{g!==void 0&&window.cancelAnimationFrame(g),window.clearTimeout(M),window.clearTimeout(N),window.clearTimeout(A),_.current.hide(),ee(),k();let e=u.current.onBuffer,t=u.current.tabId;if(l.current&&e!==void 0&&t!==void 0)try{e(t,i.state.doc.toString())}catch{}i.destroy(),r.current=void 0}},[]);let I=g.popup;return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(`div`,{style:{position:`relative`,height:`100%`,minHeight:0,overflow:`hidden`},children:(0,o.jsx)(`div`,{ref:n,className:`rvs-edge`,style:{height:`100%`}})}),v&&typeof document<`u`&&(0,a.createPortal)((0,o.jsx)(VD,{view:T,open:v,t:f,seed:x,tick:C,anchor:ee,onClose:()=>{y(!1),T?.focus()}}),document.body),I!==null&&typeof document<`u`&&(0,a.createPortal)((0,o.jsx)(`button`,{ref:g.buttonRef,type:`button`,onMouseDown:e=>e.preventDefault(),onClick:()=>g.commit(),style:{position:`fixed`,left:I.left,top:I.top,transform:`translate(-50%, calc(-100% - 8px))`,zIndex:1e3,background:`rgba(30,32,44,.95)`,color:`#fff`,border:`1px solid rgba(77,107,254,.6)`,borderRadius:6,fontSize:12,padding:`4px 10px`,cursor:`pointer`,boxShadow:`0 4px 14px rgba(0,0,0,.35)`,whiteSpace:`nowrap`},children:e.addLabel??`添加到对话`}),document.body)]})});function nR(e){return typeof e==`function`?e:void 0}function rR(e){try{let t=e.get;if(typeof t!=`function`)return;let n=t.call(e,`sidebarRight`)?.mounted,r=typeof n?.getSnapshot==`function`?n.getSnapshot.call(n):void 0;return typeof r==`string`?r:void 0}catch{return}}function iR(e,t){try{let n=e.get;if(typeof n!=`function`)return;let r=n.call(e,`workspaces`)?.list;if(typeof r?.getSnapshot!=`function`)return;let i=r.getSnapshot.call(r);if(i?.phase!==`ready`||i?.state!==`idle`||!Array.isArray(i.items))return;let a=i.items.find(e=>Array.isArray(e.sessionIds)&&e.sessionIds.includes(t));return typeof a?.path==`string`?a.path:void 0}catch{return}}function aR(e){let t=rR(e);return t===void 0?{sessionId:void 0,sessionWorkspacePath:void 0}:{sessionId:t,sessionWorkspacePath:iR(e,t)}}function oR(e,t){let n=[],r=()=>{try{let r=e.get(`sessions`)?.list;typeof r?.subscribe==`function`&&n.push(r.subscribe.bind(r)(t))}catch{}};try{let i=e.get,a=typeof i==`function`?i.call(e,`sidebarRight`)?.mounted:void 0,o=typeof a?.subscribe==`function`?nR(a.subscribe.bind(a)):void 0;o===void 0?r():n.push(o(t))}catch{r()}try{let r=e.get,i=typeof r==`function`?r.call(e,`workspaces`)?.list:void 0;typeof i?.subscribe==`function`&&n.push(i.subscribe.call(i,t))}catch{}return()=>{for(let e of n)try{e()}catch{}}}function sR(e){let t=(0,i.useRef)({sessionId:void 0,sessionWorkspacePath:void 0}),n=(0,i.useCallback)(t=>e===void 0?()=>{}:oR(e,t),[e]),r=(0,i.useCallback)(()=>{if(e===void 0)return t.current;let n=aR(e),r=t.current;return r.sessionId===n.sessionId&&r.sessionWorkspacePath===n.sessionWorkspacePath?r:(t.current=n,n)},[e]);return(0,i.useSyncExternalStore)(n,r,r)}function cR(e,t){if(e===void 0)return;let n=t.hunk;if(!(n===void 0||n<0))return e[n]}function lR(e,t){return e[t]===1}function uR(e,t){let n={...e};if(n[t]===1)return delete n[t],n;let r=Object.keys(n);if(r.length>=2e3){let e=r[0];e!==void 0&&delete n[e]}return n[t]=1,n}function dR(e){if(typeof e!=`string`||e===``)return{};let t;try{t=JSON.parse(e)}catch{return{}}if(typeof t!=`object`||!t||Array.isArray(t))return{};let n={},r=0;for(let[e,i]of Object.entries(t))if(!(i!==1||e===``)&&(n[e]=1,r+=1,r>=2e3))break;return n}function fR(e){return JSON.stringify(e)}function pR(e){return`rvs.changes.confirmed.${e}`}function mR(e,t){if(t===``)return{};try{return dR(e.getItem(pR(t)))}catch{return{}}}function hR(e,t,n){if(t!==``)try{e.setItem(pR(t),fR(n))}catch{}}function gR(e,t,n){if(t===``||n===``)return!1;let r=uR(mR(e,t),n);return hR(e,t,r),lR(r,n)}function _R(e,t,n){return t===``||n===``?!1:lR(mR(e,t),n)}let vR=32*1024;function yR(e){return new TextEncoder().encode(e).length}function bR(e,t){return t===void 0?e?`staged`:`worktree`:`commit`}function xR(e){return e.hasDiff?e.capped?`summary`:e.bytes<=32768?`full`:`summary`:`pathOnly`}function SR(e){let t=0;for(let n of e.matchAll(/`+/g))n[0].length>t&&(t=n[0].length);return t}function CR(e){return"`".repeat(Math.max(3,SR(e)+1))}function wR(e){return e.split(`
7041
7093
  `).filter(e=>e.startsWith(`@@`))}let TR={zh:{worktree:`工作区未暂存的更改`,staged:`已暂存的更改`,commit:`提交`},en:{worktree:`unstaged working-tree changes`,staged:`staged changes`,commit:`commit`}};function ER(e,t,n){let r=TR[n][e];return e!==`commit`||t===void 0?r:`${r} ${t}`}function DR(e){return e===`zh`?`⚠ 这份 diff 在 ${Re} 字节处被静默截断:下面只是前缀,后面的文件与代码块可能缺失,请以远端实际内容为准。`:`⚠ This diff was silently truncated at ${Re} bytes: only a prefix is shown, so later files and hunks may be missing — rely on the real remote content.`}function OR(e){let t=ER(e.scope,e.commitRef,e.lang);return e.lang===`zh`?[`目标文件:${e.fullPath}(仓库内相对路径 ${e.rel})`,`主机:${e.alias}`,`仓库根:${e.root}`,`差异范围:${t}`]:[`Target file: ${e.fullPath} (repository-relative path ${e.rel})`,`Host: ${e.alias}`,`Repository root: ${e.root}`,`Diff scope: ${t}`]}function kR(e){return e===`zh`?[`1. 只做审查:不要修改、暂存、提交或删除任何文件,也不要运行会改变工作区的命令。`,`2. 重点看正确性、边界条件(空值 / 超大输入 / 异常路径)与错误处理(是否吞掉失败),以及与仓库既有约定不一致的地方(命名、分层、注释风格)。`,`3. 每条问题用「文件:行号」定位(变更后的行号),说明为什么是问题、建议怎么改。`,`4. 不要复述 diff 内容,直接给结论;没有发现问题就明确说「未发现问题」。`]:[`1. Review only: do not modify, stage, commit or delete any file, and do not run commands that change the working tree.`,`2. Focus on correctness, boundary conditions (empty / huge input / unusual paths), swallowed failures, and anything that breaks the repository conventions (naming, layering, comment style).`,`3. Locate every finding as "file:line" (line numbers AFTER the change) and say why it is a problem and how you would fix it.`,`4. Do not restate the diff; give conclusions only, and say "no issues found" explicitly when there are none.`]}function AR(e){let t=e.lang===`zh`?`完整 diff:`:`Complete diff:`,n=e.diff.endsWith(`
7042
7094
  `)?e.diff.slice(0,-1):e.diff,r=CR(e.diff);return[t,`${r}diff`,n,r]}function jR(e){let t=wR(e.diff),n=t.slice(0,40),r=t.length-n.length,i=[];return e.lang===`zh`?(i.push(`diff 大小:${yR(e.diff)} 字节;超过 ${vR} 字节的内嵌上限,所以没有内嵌全文(按块摘要见下)。`),i.push(``),i.push(`变更块(从 diff 的 @@ 头提取,共 ${t.length} 处,最多列出 40 处):`)):(i.push(`Diff size: ${yR(e.diff)} bytes; above the ${vR}-byte inline limit, so the body is not included (per-hunk summary below).`),i.push(``),i.push(`Changed hunks (taken from the diff's @@ headers; ${t.length} in total, at most 40 listed):`)),n.length===0&&i.push(e.lang===`zh`?`(没有解析到 @@ 头:这份 diff 可能不是标准 unified 输出)`:`(no @@ header found: the diff may not be standard unified output)`),i.push(...n),r>0&&i.push(e.lang===`zh`?`(另有 ${r} 处变更块未列出)`:`(${r} more hunks not listed)`),i.push(``),e.lang===`zh`?i.push(`获取完整内容:请读取 ${e.fullPath},或在该主机(${e.alias})的仓库根 ${e.root} 上自行执行 git diff / git show 取回完整差异,再用上面的 @@ 头定位。`):i.push(`Get the full text: read ${e.fullPath}, or run git diff / git show yourself in the repository root ${e.root} on host ${e.alias}, then use the @@ headers above as anchors.`),i}function MR(e){return e.lang===`zh`?[`没有可内嵌的 diff 文本(未跟踪文件或二进制文件没有文本差异)。`,`请在该主机上读取 ${e.fullPath} 并自行获取差异(git diff / git show),然后按下面的要求审查。`]:[`No diff text is available (an untracked or binary file has no textual diff).`,`Read ${e.fullPath} on that host and obtain the diff yourself (git diff / git show), then review it against the requirements below.`]}function NR(e){let t=e.diff===``?`pathOnly`:e.mode,n=[];e.capped&&n.push(DR(e.lang)),n.push(e.lang===`zh`?`请审查下面这个文件的改动。`:`Please review the change to the file below.`),n.push(``),n.push(...OR(e)),n.push(``);let r;return r=t===`full`?AR(e):t===`summary`?jR(e):MR(e),n.push(...r),n.push(``),n.push(e.lang===`zh`?`审查要求:`:`Review requirements:`),n.push(...kR(e.lang)),n.join(`
7043
7095
  `)}function PR(e){return e.origPath===void 0||e.origPath===e.path?`${e.status}\t${e.path}`:`${e.status}\t${e.origPath} → ${e.path}`}function FR(e){let t=[];if(e.lang===`zh`?(t.push(`提交:${e.hash}`,`标题:${e.subject}`),e.body.trim()!==``&&t.push(`提交说明:\n${e.body.trim()}`),t.push(`主机:${e.alias}`,`仓库根:${e.root}`)):(t.push(`Commit: ${e.hash}`,`Subject: ${e.subject}`),e.body.trim()!==``&&t.push(`Commit message:\n${e.body.trim()}`),t.push(`Host: ${e.alias}`,`Repository root: ${e.root}`)),e.files.length===0)return t;let n=e.files.slice(0,100),r=e.files.length-n.length;return t.push(``),t.push(e.lang===`zh`?`改动文件(${e.files.length} 个,最多列出 100 个):`:`Changed files (${e.files.length} total, at most 100 listed):`),t.push(...n.map(PR)),r>0&&t.push(e.lang===`zh`?`(另有 ${r} 个文件未列出)`:`(${r} more files not listed)`),t}function IR(e){let t=e.lang===`zh`?`完整 patch:`:`Complete patch:`,n=e.patch.endsWith(`
@@ -7045,7 +7097,7 @@ Integer Float Double Long Int32 Int64 Uint8 uint32_t int32_t uint64_t int64_t si
7045
7097
  `)}function VR(e,t,n,r=0,i=8){let a=Number.isFinite(e)?Math.max(0,Math.trunc(e)):0,o=Number.isFinite(n)?Math.max(0,n):0,s=Number.isFinite(t)?t:0,c=Math.ceil(o/18),l=Math.max(0,Math.min(Math.floor((s-r)/18),Math.max(0,a-1))),u=Math.max(0,l-i),d=Math.min(a,Math.max(u+1,l+c+i));return{from:u,to:d,before:u*18,after:Math.max(0,(a-d)*18)}}function HR(e,t,n,r,i){let a=VR(e,t,n,r),o=i.current;return o!==void 0&&o.total===e&&o.window.from===a.from&&o.window.to===a.to?o.window:(i.current={total:e,window:a},a)}function UR(e,t=0){let n=(0,i.useRef)(0),r=(0,i.useRef)(540),a=(0,i.useRef)(void 0),o=(0,i.useRef)(null),[,s]=(0,i.useState)(0),c=(0,i.useCallback)(e=>{if(o.current?.disconnect(),o.current=null,e===null)return;let t=e.scrollTop!==n.current;if(n.current=e.scrollTop,e.clientHeight>0&&e.clientHeight!==r.current&&(r.current=e.clientHeight,t=!0),t&&s(e=>e+1),typeof ResizeObserver>`u`)return;let i=new ResizeObserver(t=>{let n=t[0]?.borderBoxSize[0],i=n===void 0?e.clientHeight:n.blockSize;i>0&&i!==r.current&&(r.current=i,s(e=>e+1))});i.observe(e),o.current=i},[]),l=HR(e,n.current,r.current,t,a);return{attach:c,onScroll:(0,i.useCallback)(i=>{let o=i.currentTarget;n.current=o.scrollTop,o.clientHeight>0&&(r.current=o.clientHeight);let c=a.current?.window;HR(e,o.scrollTop,r.current,t,a)!==c&&s(e=>e+1)},[e,t]),range:l}}function WR(e){let t=UR(e.length);return{attachGrid:t.attach,onScroll:t.onScroll,rows:e.slice(t.range.from,t.range.to),range:t.range,before:t.range.before,after:t.range.after}}function GR(e){return e.empty===!0?(0,o.jsx)(`span`,{className:`rvs-row-empty`,children:`\xA0`}):(0,o.jsx)(o.Fragment,{children:e.tokens.map((e,t)=>(0,o.jsx)(`span`,{className:e.kind===`plain`?void 0:`rvs-t-${e.kind}`,children:e.text},t))})}function KR(e){return e.range.to<=e.range.from?(0,o.jsx)(`div`,{className:`rvs-empty`,children:e.emptyText}):(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(`div`,{className:`rvs-drows-blank`,style:{height:e.range.before}}),Array.from({length:e.range.to-e.range.from},(t,n)=>e.range.from+n).map(t=>(0,o.jsxs)(`div`,{className:`rvs-code-line`,children:[(0,o.jsx)(`span`,{className:`rvs-num`,children:t+1}),(0,o.jsx)(`span`,{className:`rvs-code-text`,children:(0,o.jsx)(GR,{tokens:e.tokens.at(t)??[]})})]},t)),(0,o.jsx)(`div`,{className:`rvs-drows-blank`,style:{height:e.range.after}})]})}function qR(e){let t=1;for(let n=e.indexOf(`
7046
7098
  `);n>=0;n=e.indexOf(`
7047
7099
  `,n+1))t+=1;return t}let JR={lineCount:0,at:()=>void 0};function YR(e,t){let n=qR(e),r,i=[],a=KI();return{lineCount:n,at(o){if(o<0||o>=n)return;let s=r??=e.split(`
7048
- `);for(;i.length<=o;)i.push(qI(s[i.length]??``,t,a));return i[o]}}}function XR(e){return(0,o.jsx)(`div`,{className:`rvs-hbar`,ref:e.barRef,title:e.hint,onScroll:t=>e.onScroll(t.currentTarget.scrollLeft),children:(0,o.jsx)(`div`,{className:`rvs-hbar-inner`,style:{width:e.width}})})}let ZR={stage:`scm.hunkStaged`,unstage:`scm.hunkUnstaged`,revert:`scm.hunkReverted`};function QR(e,t){if(t)return`offline`;if(e.truncated)return`truncated`}function $R(e,t,n){return e===void 0?t.dirty&&t.text!==``?t.text:n??``:e}function ez(e){let t=pl(),{t:n,lang:r}=t,a=e.tab,[s,c]=(0,i.useState)(!1),[l,u]=(0,i.useState)(void 0),[d,f]=(0,i.useState)(a.view===`before`||a.view===`after`?a.view:`split`),[p,m]=(0,i.useState)(void 0),[,h]=(0,i.useState)(0),g=(0,i.useRef)(null),_=(0,i.useRef)(null),v=(0,i.useRef)(null),y=(0,i.useRef)(null),b=(0,i.useRef)(null),[x,S]=(0,i.useState)({content:0,viewport:0}),C=WR(a.model?.rows??[]),w=(0,i.useMemo)(()=>a.model===void 0?[]:a.model.hunks.map(e=>e.startRow).sort((e,t)=>e-t),[a.model]),[T,E]=(0,i.useState)(-1),D=(0,i.useRef)(-1),O=e=>{let t=b.current;if(t===null)return;let n=Rn(w.length,T,e);if(n<0)return;let r=w[n]*18;D.current=r,t.scrollTop=r,E(n)},k=e=>{if(w.length===0||Math.abs(e.scrollTop-D.current)<1)return;let t=zn(w,e.scrollTop/18);E(e=>e===t?e:t)};(0,i.useLayoutEffect)(()=>{if(d!==`split`)return;let e=()=>{let e=Math.max(_.current?.scrollWidth??0,v.current?.scrollWidth??0),t=b.current?.clientWidth??0;S(n=>n.content===e&&n.viewport===t?n:{content:e,viewport:t})};e();let t=window.setTimeout(e,80);return window.addEventListener(`resize`,e),()=>{window.clearTimeout(t),window.removeEventListener(`resize`,e)}},[d,a.id,a.diff,C.range]);let A=(0,i.useCallback)(e=>{for(let t of[_.current,v.current])t!==null&&t.scrollLeft!==e&&(t.scrollLeft=e)},[]),j=(0,i.useCallback)(e=>{let t=e.currentTarget.scrollLeft,n=y.current;n!==null&&n.scrollLeft!==t&&(n.scrollLeft=t);for(let n of[_.current,v.current])n!==null&&n!==e.currentTarget&&n.scrollLeft!==t&&(n.scrollLeft=t)},[]),M=sR(t.ctx),N=t.workspace===void 0?void 0:t.aliasPaths[t.workspace.id],ee=M.sessionId!==void 0&&M.sessionWorkspacePath!==void 0&&N!==void 0&&hI(M.sessionWorkspacePath,N),P;t.ctx===void 0?P=n(`scm.aiReviewNoContext`):!ee||M.sessionId===void 0?P=n(`scm.aiReviewNoSession`):cI(t.ctx,M.sessionId)||(P=n(`scm.aiReviewNoChannel`)),(0,i.useEffect)(()=>{if(d!==`after`||a.staged||a.sessionDiff!==void 0||a.text!==``||a.loading)return;let e=!1;return(async()=>{try{let n=await V.fileOp.read(t.alias,a.fullPath);if(e)return;m(n.binary?``:n.text??``)}catch{e||m(``)}})(),()=>{e=!0}},[d,a.staged,a.text,a.loading,a.fullPath,t.alias]);let F=(0,i.useMemo)(()=>VI(a.rel),[a.rel]),I=a.model,te=(0,i.useMemo)(()=>I===void 0?{added:0,removed:0}:Ln(I),[I]),L=(0,i.useMemo)(()=>I===void 0?JR:YR(a.diff?.oldText??``,F),[I,a.diff?.oldText,F]),R=(0,i.useMemo)(()=>I===void 0?JR:YR(a.diff?.newText??``,F),[I,a.diff?.newText,F]),ne=d===`before`?L:d===`after`&&(a.staged||a.sessionDiff!==void 0)?R:JR,z=UR(ne.lineCount,6);(0,i.useMemo)(()=>{if(d===`split`){let e=I?.rows??[];for(let t=C.range.from;t<C.range.to;t+=1){let n=e[t];n!==void 0&&(n.old!==``&&L.at((n.oldNum??1)-1),n.inNew!==!1&&n.new!==``&&R.at((n.newNum??1)-1))}return}for(let e=z.range.from;e<z.range.to;e+=1)ne.at(e)},[d,I,L,R,ne,C.range,z.range]);let re=async(r,i)=>{let o=QR(a,e.offline===!0);if(o!==void 0){H(n(o===`offline`?`connection.saveBlocked`:`scm.hunkTruncated`),!0);return}let s=I?.hunks.find(e=>e.index===r);if(!(s===void 0||t.repoRoot===void 0)){u(r);try{await Ki(t.alias,t.repoRoot,s.patch,i),await t.afterWrite(),await t.reloadTab(a.id),H(n(ZR[i]))}catch(e){H(e instanceof mi||e instanceof Error?e.message:String(e),!0)}finally{u(void 0)}}},ie=async()=>{c(!0),await t.reloadTab(a.id),c(!1)},ae=async()=>{if(e.offline===!0){H(n(`connection.saveBlocked`),!0);return}if(a.truncated){H(n(`editor.truncatedReadOnly`),!0);return}let r=g.current?.getContent()??p;r!==void 0&&(m(r),t.updateTab(a.id,{text:r}),await t.saveTab(a.id,r)&&await t.reloadTab(a.id))},oe=()=>{let e=t.ctx,i=M.sessionId;if(P!==void 0||e===void 0||i===void 0){H(P??n(`scm.aiReviewNoSession`),!0);return}let o=a.diff?.diff??``,s=yR(o),c=s>=Re,l=xR({bytes:s,hasDiff:o!==``,capped:c});if(!uI(e,i,NR({alias:t.alias,root:t.repoRoot??t.root,rel:a.rel,fullPath:a.fullPath,scope:bR(a.staged,a.ref),...a.ref===void 0?{}:{commitRef:a.ref},diff:o,mode:l,capped:c,lang:r}))){H(n(`scm.aiReviewFailed`),!0);return}H(n(l===`full`?`scm.aiReviewAdded`:l===`summary`?`scm.aiReviewAddedSummary`:`scm.aiReviewAddedRead`))};if(a.error!==void 0)return(0,o.jsxs)(`div`,{className:`rvs-diff`,children:[(0,o.jsx)(`div`,{className:`rvs-banner error`,children:a.error}),(0,o.jsx)(`div`,{style:{padding:8},children:(0,o.jsx)(`button`,{type:`button`,className:`rvs-chip`,onClick:()=>{ie()},children:n(`scm.retry`)})})]});if(a.loading)return(0,o.jsxs)(`div`,{className:`rvs-empty`,children:[(0,o.jsx)(Tc,{}),` `,n(`common.loading`)]});if(a.binary)return(0,o.jsx)(`div`,{className:`rvs-empty`,children:n(`scm.binaryDiff`)});if(I===void 0||I.empty)return(0,o.jsx)(`div`,{className:`rvs-diff`,children:(0,o.jsx)(`div`,{className:`rvs-empty`,children:n(`scm.noDiff`)})});let se=a.sessionDiff!==void 0,ce=d===`after`&&!a.staged&&!se&&e.offline!==!0&&!a.truncated,le=e.offline===!0||a.truncated,ue=a.truncated?n(`scm.hunkTruncated`):void 0;return(0,o.jsxs)(`div`,{className:`rvs-diff`,children:[a.truncated&&(0,o.jsx)(`div`,{className:`rvs-banner warn`,children:n(`editor.truncatedReadOnly`)}),(0,o.jsxs)(`div`,{className:`rvs-diff-toolbar`,children:[(0,o.jsx)(wc,{value:d,onChange:e=>{f(e),t.updateTab(a.id,{view:e})},options:[{id:`split`,label:n(`scm.sideBySide`)},{id:`before`,label:n(`scm.before`)},{id:`after`,label:n(ce?`scm.afterEditable`:`scm.after`)}]}),(0,o.jsxs)(`span`,{style:{color:`var(--rvs-git-a)`},children:[`+`,te.added]}),(0,o.jsxs)(`span`,{style:{color:`var(--rvs-git-d)`},children:[`-`,te.removed]}),a.staged&&(0,o.jsx)(`span`,{className:`rvs-pill`,children:n(`scm.stagedReadonly`)}),(0,o.jsx)(`span`,{className:`rvs-einfo-spacer`}),d===`split`&&w.length>0&&(0,o.jsxs)(`span`,{className:`rvs-hunknav`,title:n(`scm.hunkNavHint`),children:[(0,o.jsx)(U,{title:n(`scm.prevHunk`),onClick:()=>O(-1),children:(0,o.jsx)(fs,{size:13})}),(0,o.jsx)(`span`,{className:`rvs-hunknav-pos`,children:T<0?`-/${w.length}`:`${T+1}/${w.length}`}),(0,o.jsx)(U,{title:n(`scm.nextHunk`),onClick:()=>O(1),children:(0,o.jsx)(ds,{size:13})})]}),s&&(0,o.jsx)(Tc,{}),!se&&(0,o.jsx)(U,{title:P??n(`scm.aiReview`),onClick:oe,disabled:P!==void 0,children:(0,o.jsx)(`span`,{className:`rvs-glyph`,"aria-hidden":`true`,style:{fontSize:12},children:`AI`})}),(0,o.jsx)(U,{title:n(`scm.reloadDiff`),onClick:()=>{ie()},disabled:s,children:(0,o.jsx)(hs,{size:13})}),ce&&(0,o.jsx)(U,{title:`${n(`editor.save`)} (Ctrl+S)`,onClick:()=>{ae()},children:(0,o.jsx)(Vs,{size:13})})]}),d===`split`&&(0,o.jsxs)(o.Fragment,{children:[x.content>x.viewport+1&&(0,o.jsx)(XR,{barRef:y,width:x.content,hint:n(`scm.hScrollHint`),onScroll:A}),(0,o.jsx)(`div`,{className:`rvs-diff-grid`,ref:e=>{C.attachGrid(e),b.current=e},onScroll:e=>{C.onScroll(e),k(e.currentTarget)},children:(0,o.jsxs)(`div`,{className:`rvs-diff-cols`,children:[(0,o.jsxs)(`div`,{className:`rvs-diff-col`,ref:_,onScroll:j,children:[(0,o.jsx)(`div`,{className:`rvs-drows-blank`,style:{height:C.before}}),C.rows.map(e=>(0,o.jsxs)(`div`,{className:`rvs-dline${e.oldDel?` rvs-row-del`:``}`,children:[(0,o.jsx)(`span`,{className:`rvs-dline-num`,children:e.oldNum??``}),(0,o.jsx)(`span`,{className:`rvs-dline-text`,children:e.old===``?(0,o.jsx)(`span`,{className:`rvs-row-empty`,children:`\xA0`}):(0,o.jsx)(GR,{tokens:L.at((e.oldNum??1)-1)??[{text:e.old,kind:`plain`}]})})]},e.id)),(0,o.jsx)(`div`,{className:`rvs-drows-blank`,style:{height:C.after}})]}),(0,o.jsxs)(`div`,{className:`rvs-gutter-col`,children:[(0,o.jsx)(`div`,{className:`rvs-drows-blank`,style:{height:C.before}}),C.rows.map(e=>{let t=e.hunk>=0?I.hunks[e.hunk]:void 0,r=t!==void 0&&t.startRow===e.id,i=e.oldDel||e.newAdd;return(0,o.jsxs)(`div`,{className:`rvs-gutter-line`,children:[r&&t!==void 0&&!se&&(0,o.jsx)(`span`,{className:`rvs-hunk-btns`,children:l===t.index?(0,o.jsx)(Tc,{}):(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(`button`,{type:`button`,className:`rvs-hunk-btn stage`,title:ue??(a.staged?n(`scm.unstageHunk`):n(`scm.stageHunk`)),disabled:le,onClick:()=>{re(t.index,a.staged?`unstage`:`stage`)},children:a.staged?`↧`:`⤒`}),!a.staged&&(0,o.jsx)(`button`,{type:`button`,className:`rvs-hunk-btn revert`,title:ue??n(`scm.revertHunk`),disabled:le,onClick:()=>{re(t.index,`revert`)},children:`↩`})]})}),(!r||se)&&i&&(0,o.jsx)(`span`,{className:`rvs-gutter-dot`,style:{background:e.oldDel?`var(--rvs-git-d)`:`var(--rvs-git-a)`}})]},e.id)}),(0,o.jsx)(`div`,{className:`rvs-drows-blank`,style:{height:C.after}})]}),(0,o.jsxs)(`div`,{className:`rvs-diff-col`,ref:v,onScroll:j,children:[(0,o.jsx)(`div`,{className:`rvs-drows-blank`,style:{height:C.before}}),C.rows.map(e=>(0,o.jsxs)(`div`,{className:`rvs-dline${e.newAdd?` rvs-row-add`:``}`,children:[(0,o.jsx)(`span`,{className:`rvs-dline-num`,children:e.newNum??``}),(0,o.jsx)(`span`,{className:`rvs-dline-text`,children:e.inNew===!1||e.new===``?(0,o.jsx)(`span`,{className:`rvs-row-empty`,children:`\xA0`}):(0,o.jsx)(GR,{tokens:R.at((e.newNum??1)-1)??[{text:e.new,kind:`plain`}]})})]},e.id)),(0,o.jsx)(`div`,{className:`rvs-drows-blank`,style:{height:C.after}})]})]})})]}),d===`before`&&(0,o.jsx)(`div`,{className:`rvs-code rvs-scroll`,ref:z.attach,onScroll:z.onScroll,children:(0,o.jsx)(KR,{tokens:ne,range:z.range,emptyText:n(`scm.emptySide`)})}),d===`after`&&(a.staged||se?(0,o.jsx)(`div`,{className:`rvs-code rvs-scroll`,ref:z.attach,onScroll:z.onScroll,children:(0,o.jsx)(KR,{tokens:ne,range:z.range,emptyText:n(`scm.emptySide`)})}):(0,o.jsx)(`div`,{className:`rvs-editor-host`,children:(0,o.jsx)(tR,{ref:g,initial:$R(p,a,a.diff?.newText),savedText:a.diff?.newText,path:a.fullPath,readOnly:e.offline===!0||a.truncated,visible:e.visible,tabId:a.id,ctx:t.ctx,sessionId:M.sessionId,remoteRoot:t.repoRoot??t.root,chatEnabled:ee,addLabel:n(`files.addToConversation`),onSave:()=>{ae()},onDirty:e=>{t.updateTab(a.id,{dirty:e}),h(e=>e+1)},onBuffer:(e,n)=>{m(n),t.updateTab(e,{text:n})}},`${a.id}:edit`)}))]})}let tz={borderTop:`1px solid rgba(127,127,127,.25)`},nz={background:`rgba(127,127,127,.12)`,color:`inherit`,border:`1px solid rgba(127,127,127,.35)`,borderRadius:6,padding:`4px 8px`,fontSize:13,fontFamily:`inherit`,outline:`none`,width:`100%`,boxSizing:`border-box`},rz={background:`rgba(127,127,127,.12)`,color:`inherit`,border:`1px solid rgba(127,127,127,.35)`,borderRadius:6,padding:`3px 8px`,fontSize:12,fontFamily:`inherit`,outline:`none`,colorScheme:`light dark`},iz={backgroundColor:`Canvas`,color:`CanvasText`},az={background:`rgba(127,127,127,.15)`,color:`inherit`,border:`1px solid rgba(127,127,127,.35)`,borderRadius:6,padding:`3px 10px`,fontSize:12,cursor:`pointer`,whiteSpace:`nowrap`},oz={...az,background:`rgba(77,107,254,.25)`,borderColor:`rgba(77,107,254,.6)`},sz={...az,background:`rgba(200,60,60,.15)`,borderColor:`rgba(200,60,60,.5)`};function cz(e){let t=e.kind===`primary`?oz:e.kind===`danger`?sz:az;return(0,o.jsx)(`button`,{type:`button`,onClick:e.onClick,disabled:e.disabled===!0,title:e.title,style:{...t,opacity:e.disabled===!0?.5:1},children:e.children})}function lz(e){let t=e.size??12;return(0,o.jsxs)(`svg`,{width:t,height:t,viewBox:`0 0 16 16`,"aria-hidden":`true`,style:{display:`inline-block`,verticalAlign:`-2px`},children:[(0,o.jsx)(`circle`,{cx:`8`,cy:`8`,r:`6.5`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,opacity:`0.25`}),(0,o.jsx)(`path`,{d:`M 8 1.5 A 6.5 6.5 0 0 1 14.5 8`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,children:(0,o.jsx)(`animateTransform`,{attributeName:`transform`,type:`rotate`,from:`0 8 8`,to:`360 8 8`,dur:`0.9s`,repeatCount:`indefinite`})})]})}function uz(e){return(0,o.jsx)(`div`,{role:e.kind===`error`?`alert`:`status`,style:{margin:`8px 0`,padding:`6px 10px`,borderRadius:6,fontSize:12,whiteSpace:`pre-wrap`,wordBreak:`break-word`,background:e.kind===`error`?`rgba(200,60,60,.15)`:`rgba(127,127,127,.15)`},children:e.children})}function dz(e){return(0,o.jsxs)(`label`,{style:{display:`block`,marginBottom:8,fontSize:12},children:[(0,o.jsx)(`span`,{style:{display:`block`,opacity:.75,marginBottom:3},children:e.label}),e.children]})}function fz(e){return(0,o.jsx)(`div`,{style:{display:`flex`,alignItems:`center`,gap:e.gap??8,flexWrap:`wrap`},children:e.children})}let pz=`dsh-remote-vs.recentFiles`,mz=`RV-QO-END`,hz=`RV-QO-CAP `,gz=`RV-QO-STATUS tool=`,_z=[`.git`,`node_modules`,`dist`,`build`,`out`,`coverage`,`target`,`.next`,`.nuxt`,`.turbo`,`.venv`,`__pycache__`,`.pytest_cache`,`.mypy_cache`,`.gradle`];function vz(e,t){let n=e.toLowerCase();if(n===``)return 0;if(n.length>t.length)return;let r=t.toLowerCase(),i=t.lastIndexOf(`/`),a=0,o=0,s=-2,c=-1;for(let e=0;e<r.length&&o<n.length;e+=1)r[e]===n[o]&&(c<0&&(c=e),a+=1,e===s+1&&(a+=12),e>i&&(a+=6),yz(t,e)&&(a+=10),s=e,o+=1);if(!(o<n.length))return a-Math.min(c,10)}function yz(e,t){if(t===0)return!0;let n=e[t-1];if(n===void 0)return!1;if(`/_-. `.includes(n))return!0;let r=e[t];return r!==void 0&&n===n.toLowerCase()&&r!==r.toLowerCase()}function bz(e,t,n){let r=Math.max(0,Math.floor(n)),i=e.trim();if(i===``)return{hits:t.slice(0,r),truncated:t.length>r};let a=[];for(let e of t){let t=vz(i,e);t!==void 0&&a.push({path:e,score:t})}return a.sort((e,t)=>t.score-e.score||xz(e.path,t.path)),{hits:a.slice(0,r).map(e=>e.path),truncated:a.length>r}}function xz(e,t){return e===t?0:e<t?-1:1}function Sz(e,t){let n=e.trim().toLowerCase(),r=t.toLowerCase(),i=[];if(n===``||r.length!==t.length)return i;let a=0;for(let e=0;e<r.length&&a<n.length;e+=1)r[e]===n[a]&&(i.push(e),a+=1);return a<n.length?[]:i}function Cz(e){let t=e.lastIndexOf(`/`);return t<0?{dir:``,name:e}:{dir:e.slice(0,t+1),name:e.slice(t+1)}}function wz(e,t){let n=e.replace(/\/+$/,``),r=t.replace(/^\.\//,``).replace(/^\/+/,``);return r===``?n:`${n}/${r}`}function Tz(e,t){let n=e.replace(/\/+$/,``);if(n!==``&&t!==n&&t.startsWith(`${n}/`))return t.slice(n.length+1)}function Ez(e){return e instanceof Error?e.message:String(e)}function Dz(){try{if(typeof localStorage>`u`)return{};let e=localStorage.getItem(pz);if(e===null)return{};let t=JSON.parse(e);return typeof t!=`object`||!t||Array.isArray(t)?{}:t}catch{return{}}}function Oz(e){if(e===``)return[];let t=Dz()[e];return Array.isArray(t)?t.filter(e=>typeof e==`string`&&e.startsWith(`/`)).slice(0,20):[]}function kz(e,t){if(e===``||!t.startsWith(`/`))return[];let n=Dz(),r=[t,...(Array.isArray(n[e])?n[e].filter(e=>typeof e==`string`):[]).filter(e=>e!==t)].slice(0,20);try{typeof localStorage<`u`&&localStorage.setItem(pz,JSON.stringify({...n,[e]:r}))}catch{}return r}function Az(){return{phase:`idle`,target:void 0,index:void 0,error:void 0}}function jz(e,t){return`${e}\u0000${t.replace(/\/+$/,``)}`}function Mz(e,t){return e!==void 0&&jz(e.alias,e.root)===jz(t.alias,t.root)}function Nz(e,t,n,r){if(!Mz(e.target,{alias:t,root:n}))return!0;if(e.phase===`loading`)return!1;if(e.phase===`error`)return!0;let i=e.index;return i===void 0||i.writeSeq!==r}function Pz(e,t,n){let r={alias:t,root:n};return{phase:`loading`,target:r,index:Mz(e.target,r)?e.index:void 0,error:void 0}}function Fz(e,t){return Mz(e.target,t)?{phase:`ready`,target:{alias:t.alias,root:t.root},index:t,error:void 0}:e}function Iz(e,t,n){return Mz(e.target,n)?{phase:`error`,target:n,index:e.index,error:t}:e}function Lz(e){return{phase:`error`,target:void 0,index:void 0,error:e}}let Rz=Az(),zz=new Set;function Bz(){return Rz}function Vz(e){return zz.add(e),()=>{zz.delete(e)}}function Hz(e){Rz=e;for(let e of[...zz])e()}function Uz(e){return`'${e.replace(/'/g,`'\\''`)}'`}function Wz(e,t={}){let n=Math.max(1,Math.floor(t.entries??5e4)),r=Math.max(1024,Math.floor(t.bytes??12e5)),i=Uz(e),a=_z.map(e=>`--glob ${Uz(`!**/${e}`)} --glob ${Uz(`!**/${e}/**`)}`).join(` `),o=_z.map(e=>`-name ${Uz(e)}`).join(` -o `);return[`cd ${i} || { echo ${Uz(`quick-open: cannot enter the remote workspace root`)} >&2; exit 3; }`,`export LC_ALL=C`,`{`,`rv_status=0`,`if command -v rg >/dev/null 2>&1; then`,` rg --no-config --files --no-ignore --hidden ${a} -- . || rv_status=$?`,` [ "$rv_status" -eq 1 ] && rv_status=0`,`else`,` find . -maxdepth 40 \\( ${o} \\) -prune -o -type f -print || rv_status=$?`,` printf '%s\\n' ${Uz(`${hz}depth=40`)}`,`fi`,`if [ "$rv_status" -ge 128 ]; then rv_status=0; fi`,`printf '%s\\n' ${Uz(mz)}`,`if [ "$rv_status" -ne 0 ]; then printf "RV-QO-STATUS tool=%s\\n" "$rv_status" >&2; fi`,`} | head -n ${n+1} | head -c ${r}`].join(`
7100
+ `);for(;i.length<=o;)i.push(qI(s[i.length]??``,t,a));return i[o]}}}function XR(e){return(0,o.jsx)(`div`,{className:`rvs-hbar`,ref:e.barRef,title:e.hint,onScroll:t=>e.onScroll(t.currentTarget.scrollLeft),children:(0,o.jsx)(`div`,{className:`rvs-hbar-inner`,style:{width:e.width}})})}let ZR={stage:`scm.hunkStaged`,unstage:`scm.hunkUnstaged`,revert:`scm.hunkReverted`};function QR(e,t){if(t)return`offline`;if(e.truncated)return`truncated`}function $R(e,t,n){return e===void 0?t.dirty&&t.text!==``?t.text:n??``:e}function ez(e){let t=pl(),{t:n,lang:r}=t,a=e.tab,[s,c]=(0,i.useState)(!1),[l,u]=(0,i.useState)(void 0),[d,f]=(0,i.useState)(a.view===`before`||a.view===`after`?a.view:`split`),[p,m]=(0,i.useState)(void 0),[,h]=(0,i.useState)(0),g=(0,i.useRef)(null),_=(0,i.useRef)(null),v=(0,i.useRef)(null),y=(0,i.useRef)(null),b=(0,i.useRef)(null),[x,S]=(0,i.useState)({content:0,viewport:0}),C=WR(a.model?.rows??[]),w=(0,i.useMemo)(()=>a.model===void 0?[]:a.model.hunks.map(e=>e.startRow).sort((e,t)=>e-t),[a.model]),[T,E]=(0,i.useState)(-1),D=(0,i.useRef)(-1),O=e=>{let t=b.current;if(t===null)return;let n=Rn(w.length,T,e);if(n<0)return;let r=w[n]*18;D.current=r,t.scrollTop=r,E(n)},k=e=>{if(w.length===0||Math.abs(e.scrollTop-D.current)<1)return;let t=zn(w,e.scrollTop/18);E(e=>e===t?e:t)};(0,i.useLayoutEffect)(()=>{if(d!==`split`)return;let e=()=>{let e=Math.max(_.current?.scrollWidth??0,v.current?.scrollWidth??0),t=b.current?.clientWidth??0;S(n=>n.content===e&&n.viewport===t?n:{content:e,viewport:t})};e();let t=window.setTimeout(e,80);return window.addEventListener(`resize`,e),()=>{window.clearTimeout(t),window.removeEventListener(`resize`,e)}},[d,a.id,a.diff,C.range]);let A=(0,i.useCallback)(e=>{for(let t of[_.current,v.current])t!==null&&t.scrollLeft!==e&&(t.scrollLeft=e)},[]),j=(0,i.useCallback)(e=>{let t=e.currentTarget.scrollLeft,n=y.current;n!==null&&n.scrollLeft!==t&&(n.scrollLeft=t);for(let n of[_.current,v.current])n!==null&&n!==e.currentTarget&&n.scrollLeft!==t&&(n.scrollLeft=t)},[]),M=sR(t.ctx),N=t.workspace===void 0?void 0:t.aliasPaths[t.workspace.id],ee=M.sessionId!==void 0&&M.sessionWorkspacePath!==void 0&&N!==void 0&&hI(M.sessionWorkspacePath,N),P;t.ctx===void 0?P=n(`scm.aiReviewNoContext`):!ee||M.sessionId===void 0?P=n(`scm.aiReviewNoSession`):cI(t.ctx,M.sessionId)||(P=n(`scm.aiReviewNoChannel`)),(0,i.useEffect)(()=>{if(d!==`after`||a.staged||a.sessionDiff!==void 0||a.text!==``||a.loading)return;let e=!1;return(async()=>{try{let n=await V.fileOp.read(t.alias,a.fullPath);if(e)return;m(n.binary?``:n.text??``)}catch{e||m(``)}})(),()=>{e=!0}},[d,a.staged,a.text,a.loading,a.fullPath,t.alias]);let F=(0,i.useMemo)(()=>VI(a.rel),[a.rel]),I=a.model,te=(0,i.useMemo)(()=>I===void 0?{added:0,removed:0}:Ln(I),[I]),L=(0,i.useMemo)(()=>I===void 0?JR:YR(a.diff?.oldText??``,F),[I,a.diff?.oldText,F]),R=(0,i.useMemo)(()=>I===void 0?JR:YR(a.diff?.newText??``,F),[I,a.diff?.newText,F]),ne=d===`before`?L:d===`after`&&(a.staged||a.sessionDiff!==void 0)?R:JR,z=UR(ne.lineCount,6);(0,i.useMemo)(()=>{if(d===`split`){let e=I?.rows??[];for(let t=C.range.from;t<C.range.to;t+=1){let n=e[t];n!==void 0&&(n.old!==``&&L.at((n.oldNum??1)-1),n.inNew!==!1&&n.new!==``&&R.at((n.newNum??1)-1))}return}for(let e=z.range.from;e<z.range.to;e+=1)ne.at(e)},[d,I,L,R,ne,C.range,z.range]);let re=async(r,i)=>{let o=QR(a,e.offline===!0);if(o!==void 0){H(n(o===`offline`?`connection.saveBlocked`:`scm.hunkTruncated`),!0);return}let s=I?.hunks.find(e=>e.index===r);if(!(s===void 0||t.repoRoot===void 0)){u(r);try{await Ki(t.alias,t.repoRoot,s.patch,i),await t.afterWrite(),await t.reloadTab(a.id),H(n(ZR[i]))}catch(e){H(e instanceof mi||e instanceof Error?e.message:String(e),!0)}finally{u(void 0)}}},ie=async()=>{c(!0),await t.reloadTab(a.id),c(!1)},ae=async()=>{if(e.offline===!0){H(n(`connection.saveBlocked`),!0);return}if(a.truncated){H(n(`editor.truncatedReadOnly`),!0);return}let r=g.current?.getContent()??p;r!==void 0&&(m(r),t.updateTab(a.id,{text:r}),await t.saveTab(a.id,r)&&await t.reloadTab(a.id))},oe=()=>{let e=t.ctx,i=M.sessionId;if(P!==void 0||e===void 0||i===void 0){H(P??n(`scm.aiReviewNoSession`),!0);return}let o=a.diff?.diff??``,s=yR(o),c=s>=Re,l=xR({bytes:s,hasDiff:o!==``,capped:c});if(!uI(e,i,NR({alias:t.alias,root:t.repoRoot??t.root,rel:a.rel,fullPath:a.fullPath,scope:bR(a.staged,a.ref),...a.ref===void 0?{}:{commitRef:a.ref},diff:o,mode:l,capped:c,lang:r}))){H(n(`scm.aiReviewFailed`),!0);return}H(n(l===`full`?`scm.aiReviewAdded`:l===`summary`?`scm.aiReviewAddedSummary`:`scm.aiReviewAddedRead`))};if(a.error!==void 0)return(0,o.jsxs)(`div`,{className:`rvs-diff`,children:[(0,o.jsx)(`div`,{className:`rvs-banner error`,children:a.error}),(0,o.jsx)(`div`,{style:{padding:8},children:(0,o.jsx)(`button`,{type:`button`,className:`rvs-chip`,onClick:()=>{ie()},children:n(`scm.retry`)})})]});if(a.loading)return(0,o.jsxs)(`div`,{className:`rvs-empty`,children:[(0,o.jsx)(Tc,{}),` `,n(`common.loading`)]});if(a.binary)return(0,o.jsx)(`div`,{className:`rvs-empty`,children:n(`scm.binaryDiff`)});if(I===void 0||I.empty)return(0,o.jsx)(`div`,{className:`rvs-diff`,children:(0,o.jsx)(`div`,{className:`rvs-empty`,children:n(`scm.noDiff`)})});let se=a.sessionDiff!==void 0,ce=d===`after`&&!a.staged&&!se&&e.offline!==!0&&!a.truncated,le=e.offline===!0||a.truncated,ue=a.truncated?n(`scm.hunkTruncated`):void 0;return(0,o.jsxs)(`div`,{className:`rvs-diff`,children:[a.truncated&&(0,o.jsx)(`div`,{className:`rvs-banner warn`,children:n(`editor.truncatedReadOnly`)}),(0,o.jsxs)(`div`,{className:`rvs-diff-toolbar`,children:[(0,o.jsx)(wc,{value:d,onChange:e=>{f(e),t.updateTab(a.id,{view:e})},options:[{id:`split`,label:n(`scm.sideBySide`)},{id:`before`,label:n(`scm.before`)},{id:`after`,label:n(ce?`scm.afterEditable`:`scm.after`)}]}),(0,o.jsxs)(`span`,{style:{color:`var(--rvs-git-a)`},children:[`+`,te.added]}),(0,o.jsxs)(`span`,{style:{color:`var(--rvs-git-d)`},children:[`-`,te.removed]}),a.staged&&(0,o.jsx)(`span`,{className:`rvs-pill`,children:n(`scm.stagedReadonly`)}),(0,o.jsx)(`span`,{className:`rvs-einfo-spacer`}),d===`split`&&w.length>0&&(0,o.jsxs)(`span`,{className:`rvs-hunknav`,title:n(`scm.hunkNavHint`),children:[(0,o.jsx)(U,{title:n(`scm.prevHunk`),onClick:()=>O(-1),children:(0,o.jsx)(fs,{size:13})}),(0,o.jsx)(`span`,{className:`rvs-hunknav-pos`,children:T<0?`-/${w.length}`:`${T+1}/${w.length}`}),(0,o.jsx)(U,{title:n(`scm.nextHunk`),onClick:()=>O(1),children:(0,o.jsx)(ds,{size:13})})]}),s&&(0,o.jsx)(Tc,{}),!se&&(0,o.jsx)(U,{title:P??n(`scm.aiReview`),onClick:oe,disabled:P!==void 0,children:(0,o.jsx)(`span`,{className:`rvs-glyph`,"aria-hidden":`true`,style:{fontSize:12},children:`AI`})}),(0,o.jsx)(U,{title:n(`scm.reloadDiff`),onClick:()=>{ie()},disabled:s,children:(0,o.jsx)(hs,{size:13})}),ce&&(0,o.jsx)(U,{title:`${n(`editor.save`)} (Ctrl+S)`,onClick:()=>{ae()},children:(0,o.jsx)(Vs,{size:13})})]}),d===`split`&&(0,o.jsxs)(o.Fragment,{children:[x.content>x.viewport+1&&(0,o.jsx)(XR,{barRef:y,width:x.content,hint:n(`scm.hScrollHint`),onScroll:A}),(0,o.jsx)(`div`,{className:`rvs-diff-grid`,ref:e=>{C.attachGrid(e),b.current=e},onScroll:e=>{C.onScroll(e),k(e.currentTarget)},children:(0,o.jsxs)(`div`,{className:`rvs-diff-cols`,children:[(0,o.jsxs)(`div`,{className:`rvs-diff-col`,ref:_,onScroll:j,children:[(0,o.jsx)(`div`,{className:`rvs-drows-blank`,style:{height:C.before}}),C.rows.map(e=>(0,o.jsxs)(`div`,{className:`rvs-dline${e.oldDel?` rvs-row-del`:``}`,children:[(0,o.jsx)(`span`,{className:`rvs-dline-num`,children:e.oldNum??``}),(0,o.jsx)(`span`,{className:`rvs-dline-text`,children:e.old===``?(0,o.jsx)(`span`,{className:`rvs-row-empty`,children:`\xA0`}):(0,o.jsx)(GR,{tokens:L.at((e.oldNum??1)-1)??[{text:e.old,kind:`plain`}]})})]},e.id)),(0,o.jsx)(`div`,{className:`rvs-drows-blank`,style:{height:C.after}})]}),(0,o.jsxs)(`div`,{className:`rvs-gutter-col`,children:[(0,o.jsx)(`div`,{className:`rvs-drows-blank`,style:{height:C.before}}),C.rows.map(e=>{let t=e.hunk>=0?I.hunks[e.hunk]:void 0,r=t!==void 0&&t.startRow===e.id,i=e.oldDel||e.newAdd;return(0,o.jsxs)(`div`,{className:`rvs-gutter-line`,children:[r&&t!==void 0&&!se&&(0,o.jsx)(`span`,{className:`rvs-hunk-btns`,children:l===t.index?(0,o.jsx)(Tc,{}):(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(`button`,{type:`button`,className:`rvs-hunk-btn stage`,title:ue??(a.staged?n(`scm.unstageHunk`):n(`scm.stageHunk`)),disabled:le,onClick:()=>{re(t.index,a.staged?`unstage`:`stage`)},children:a.staged?`↧`:`⤒`}),!a.staged&&(0,o.jsx)(`button`,{type:`button`,className:`rvs-hunk-btn revert`,title:ue??n(`scm.revertHunk`),disabled:le,onClick:()=>{re(t.index,`revert`)},children:`↩`})]})}),(!r||se)&&i&&(0,o.jsx)(`span`,{className:`rvs-gutter-dot`,style:{background:e.oldDel?`var(--rvs-git-d)`:`var(--rvs-git-a)`}})]},e.id)}),(0,o.jsx)(`div`,{className:`rvs-drows-blank`,style:{height:C.after}})]}),(0,o.jsxs)(`div`,{className:`rvs-diff-col`,ref:v,onScroll:j,children:[(0,o.jsx)(`div`,{className:`rvs-drows-blank`,style:{height:C.before}}),C.rows.map(e=>(0,o.jsxs)(`div`,{className:`rvs-dline${e.newAdd?` rvs-row-add`:``}`,children:[(0,o.jsx)(`span`,{className:`rvs-dline-num`,children:e.newNum??``}),(0,o.jsx)(`span`,{className:`rvs-dline-text`,children:e.inNew===!1||e.new===``?(0,o.jsx)(`span`,{className:`rvs-row-empty`,children:`\xA0`}):(0,o.jsx)(GR,{tokens:R.at((e.newNum??1)-1)??[{text:e.new,kind:`plain`}]})})]},e.id)),(0,o.jsx)(`div`,{className:`rvs-drows-blank`,style:{height:C.after}})]})]})})]}),d===`before`&&(0,o.jsx)(`div`,{className:`rvs-code rvs-scroll`,ref:z.attach,onScroll:z.onScroll,children:(0,o.jsx)(KR,{tokens:ne,range:z.range,emptyText:n(`scm.emptySide`)})}),d===`after`&&(a.staged||se?(0,o.jsx)(`div`,{className:`rvs-code rvs-scroll`,ref:z.attach,onScroll:z.onScroll,children:(0,o.jsx)(KR,{tokens:ne,range:z.range,emptyText:n(`scm.emptySide`)})}):(0,o.jsx)(`div`,{className:`rvs-editor-host`,children:(0,o.jsx)(tR,{ref:g,initial:$R(p,a,a.diff?.newText),savedText:a.diff?.newText,path:a.fullPath,readOnly:e.offline===!0||a.truncated,visible:e.visible,tabId:a.id,ctx:t.ctx,sessionId:M.sessionId,remoteRoot:t.root,chatEnabled:ee,addLabel:n(`files.addToConversation`),onSave:()=>{ae()},onDirty:e=>{t.updateTab(a.id,{dirty:e}),h(e=>e+1)},onBuffer:(e,n)=>{m(n),t.updateTab(e,{text:n})}},`${a.id}:edit`)}))]})}let tz={borderTop:`1px solid rgba(127,127,127,.25)`},nz={background:`rgba(127,127,127,.12)`,color:`inherit`,border:`1px solid rgba(127,127,127,.35)`,borderRadius:6,padding:`4px 8px`,fontSize:13,fontFamily:`inherit`,outline:`none`,width:`100%`,boxSizing:`border-box`},rz={background:`rgba(127,127,127,.12)`,color:`inherit`,border:`1px solid rgba(127,127,127,.35)`,borderRadius:6,padding:`3px 8px`,fontSize:12,fontFamily:`inherit`,outline:`none`},iz={backgroundColor:`var(--rvs-option-bg, Canvas)`,color:`var(--rvs-option-fg, CanvasText)`},az={background:`rgba(127,127,127,.15)`,color:`inherit`,border:`1px solid rgba(127,127,127,.35)`,borderRadius:6,padding:`3px 10px`,fontSize:12,cursor:`pointer`,whiteSpace:`nowrap`},oz={...az,background:`rgba(77,107,254,.25)`,borderColor:`rgba(77,107,254,.6)`},sz={...az,background:`rgba(200,60,60,.15)`,borderColor:`rgba(200,60,60,.5)`};function cz(e){let t=e.kind===`primary`?oz:e.kind===`danger`?sz:az;return(0,o.jsx)(`button`,{type:`button`,onClick:e.onClick,disabled:e.disabled===!0,title:e.title,style:{...t,opacity:e.disabled===!0?.5:1},children:e.children})}function lz(e){let t=e.size??12;return(0,o.jsxs)(`svg`,{width:t,height:t,viewBox:`0 0 16 16`,"aria-hidden":`true`,style:{display:`inline-block`,verticalAlign:`-2px`},children:[(0,o.jsx)(`circle`,{cx:`8`,cy:`8`,r:`6.5`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,opacity:`0.25`}),(0,o.jsx)(`path`,{d:`M 8 1.5 A 6.5 6.5 0 0 1 14.5 8`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,children:(0,o.jsx)(`animateTransform`,{attributeName:`transform`,type:`rotate`,from:`0 8 8`,to:`360 8 8`,dur:`0.9s`,repeatCount:`indefinite`})})]})}function uz(e){return(0,o.jsx)(`div`,{role:e.kind===`error`?`alert`:`status`,style:{margin:`8px 0`,padding:`6px 10px`,borderRadius:6,fontSize:12,whiteSpace:`pre-wrap`,wordBreak:`break-word`,background:e.kind===`error`?`rgba(200,60,60,.15)`:`rgba(127,127,127,.15)`},children:e.children})}function dz(e){return(0,o.jsxs)(`label`,{style:{display:`block`,marginBottom:8,fontSize:12},children:[(0,o.jsx)(`span`,{style:{display:`block`,opacity:.75,marginBottom:3},children:e.label}),e.children]})}function fz(e){return(0,o.jsx)(`div`,{style:{display:`flex`,alignItems:`center`,gap:e.gap??8,flexWrap:`wrap`},children:e.children})}let pz=`dsh-remote-vs.recentFiles`,mz=`RV-QO-END`,hz=`RV-QO-CAP `,gz=`RV-QO-STATUS tool=`,_z=[`.git`,`node_modules`,`dist`,`build`,`out`,`coverage`,`target`,`.next`,`.nuxt`,`.turbo`,`.venv`,`__pycache__`,`.pytest_cache`,`.mypy_cache`,`.gradle`];function vz(e,t){let n=e.toLowerCase();if(n===``)return 0;if(n.length>t.length)return;let r=t.toLowerCase(),i=t.lastIndexOf(`/`),a=0,o=0,s=-2,c=-1;for(let e=0;e<r.length&&o<n.length;e+=1)r[e]===n[o]&&(c<0&&(c=e),a+=1,e===s+1&&(a+=12),e>i&&(a+=6),yz(t,e)&&(a+=10),s=e,o+=1);if(!(o<n.length))return a-Math.min(c,10)}function yz(e,t){if(t===0)return!0;let n=e[t-1];if(n===void 0)return!1;if(`/_-. `.includes(n))return!0;let r=e[t];return r!==void 0&&n===n.toLowerCase()&&r!==r.toLowerCase()}function bz(e,t,n){let r=Math.max(0,Math.floor(n)),i=e.trim();if(i===``)return{hits:t.slice(0,r),truncated:t.length>r};let a=[];for(let e of t){let t=vz(i,e);t!==void 0&&a.push({path:e,score:t})}return a.sort((e,t)=>t.score-e.score||xz(e.path,t.path)),{hits:a.slice(0,r).map(e=>e.path),truncated:a.length>r}}function xz(e,t){return e===t?0:e<t?-1:1}function Sz(e,t){let n=e.trim().toLowerCase(),r=t.toLowerCase(),i=[];if(n===``||r.length!==t.length)return i;let a=0;for(let e=0;e<r.length&&a<n.length;e+=1)r[e]===n[a]&&(i.push(e),a+=1);return a<n.length?[]:i}function Cz(e){let t=e.lastIndexOf(`/`);return t<0?{dir:``,name:e}:{dir:e.slice(0,t+1),name:e.slice(t+1)}}function wz(e,t){let n=e.replace(/\/+$/,``),r=t.replace(/^\.\//,``).replace(/^\/+/,``);return r===``?n:`${n}/${r}`}function Tz(e,t){let n=e.replace(/\/+$/,``);if(n!==``&&t!==n&&t.startsWith(`${n}/`))return t.slice(n.length+1)}function Ez(e){return e instanceof Error?e.message:String(e)}function Dz(){try{if(typeof localStorage>`u`)return{};let e=localStorage.getItem(pz);if(e===null)return{};let t=JSON.parse(e);return typeof t!=`object`||!t||Array.isArray(t)?{}:t}catch{return{}}}function Oz(e){if(e===``)return[];let t=Dz()[e];return Array.isArray(t)?t.filter(e=>typeof e==`string`&&e.startsWith(`/`)).slice(0,20):[]}function kz(e,t){if(e===``||!t.startsWith(`/`))return[];let n=Dz(),r=[t,...(Array.isArray(n[e])?n[e].filter(e=>typeof e==`string`):[]).filter(e=>e!==t)].slice(0,20);try{typeof localStorage<`u`&&localStorage.setItem(pz,JSON.stringify({...n,[e]:r}))}catch{}return r}function Az(){return{phase:`idle`,target:void 0,index:void 0,error:void 0}}function jz(e,t){return`${e}\u0000${t.replace(/\/+$/,``)}`}function Mz(e,t){return e!==void 0&&jz(e.alias,e.root)===jz(t.alias,t.root)}function Nz(e,t,n,r){if(!Mz(e.target,{alias:t,root:n}))return!0;if(e.phase===`loading`)return!1;if(e.phase===`error`)return!0;let i=e.index;return i===void 0||i.writeSeq!==r}function Pz(e,t,n){let r={alias:t,root:n};return{phase:`loading`,target:r,index:Mz(e.target,r)?e.index:void 0,error:void 0}}function Fz(e,t){return Mz(e.target,t)?{phase:`ready`,target:{alias:t.alias,root:t.root},index:t,error:void 0}:e}function Iz(e,t,n){return Mz(e.target,n)?{phase:`error`,target:n,index:e.index,error:t}:e}function Lz(e){return{phase:`error`,target:void 0,index:void 0,error:e}}let Rz=Az(),zz=new Set;function Bz(){return Rz}function Vz(e){return zz.add(e),()=>{zz.delete(e)}}function Hz(e){Rz=e;for(let e of[...zz])e()}function Uz(e){return`'${e.replace(/'/g,`'\\''`)}'`}function Wz(e,t={}){let n=Math.max(1,Math.floor(t.entries??5e4)),r=Math.max(1024,Math.floor(t.bytes??12e5)),i=Uz(e),a=_z.map(e=>`--glob ${Uz(`!**/${e}`)} --glob ${Uz(`!**/${e}/**`)}`).join(` `),o=_z.map(e=>`-name ${Uz(e)}`).join(` -o `);return[`cd ${i} || { echo ${Uz(`quick-open: cannot enter the remote workspace root`)} >&2; exit 3; }`,`export LC_ALL=C`,`{`,`rv_status=0`,`if command -v rg >/dev/null 2>&1; then`,` rg --no-config --files --no-ignore --hidden ${a} -- . || rv_status=$?`,` [ "$rv_status" -eq 1 ] && rv_status=0`,`else`,` find . -maxdepth 40 \\( ${o} \\) -prune -o -type f -print || rv_status=$?`,` printf '%s\\n' ${Uz(`${hz}depth=40`)}`,`fi`,`if [ "$rv_status" -ge 128 ]; then rv_status=0; fi`,`printf '%s\\n' ${Uz(mz)}`,`if [ "$rv_status" -ne 0 ]; then printf "RV-QO-STATUS tool=%s\\n" "$rv_status" >&2; fi`,`} | head -n ${n+1} | head -c ${r}`].join(`
7049
7101
  `)}function Gz(e,t={root:``}){let n=Math.max(1,Math.floor(t.maxEntries??5e4)),r=e,i=!1,a,o=r.indexOf(`[... truncated: output exceeded`);o>=0&&(i=!0,r=r.slice(0,o));let s=r.split(`
7050
7102
  `).map(e=>e.endsWith(`\r`)?e.slice(0,-1):e),c=r.endsWith(`
7051
7103
  `);s.length>0&&s[s.length-1]===``&&s.pop(),s.length>0&&s[s.length-1]===mz?s.pop():(i=!0,!c&&s.length>0&&s.pop());let l=t.root.replace(/\/+$/,``),u=l===``?void 0:`${l}/`,d=new Set;for(let e of s){if(e===``||e===mz)continue;if(e.startsWith(hz)){let t=Number.parseInt(e.slice(10).replace(/^depth=/,``),10);Number.isFinite(t)&&t>0&&(a=t);continue}let t=e;t.startsWith(`./`)&&(t=t.slice(2)),u!==void 0&&t.startsWith(u)&&(t=t.slice(u.length)),t=t.replace(/^\/+/,``),t!==``&&d.add(t)}let f=Array.from(d).sort(xz);return f.length>n?{paths:f.slice(0,n),truncated:!0,depthCapped:a}:{paths:f,truncated:i,depthCapped:a}}function Kz(e){for(let t of e.split(`
@@ -7055,7 +7107,7 @@ Integer Float Double Long Int32 Int64 Uint8 uint32_t int32_t uint64_t int64_t si
7055
7107
  `);continue}if(i===`code`){let o=e[s+1];if(n.lineSlash&&c===`/`&&o===`/`){i=`line`,r.push(` `),s+=1;continue}if(n.blockSlash&&c===`/`&&o===`*`){i=`block`,r.push(` `),s+=1;continue}if(n.hash&&c===`#`){i=`line`,r.push(` `);continue}if(n.triple&&(c===`"`||c===`'`)&&e.startsWith(c.repeat(3),s)){i=`triple`,a=c,r.push(` `),s+=2;continue}if(t===`rust`&&c===`'`){let t=/^'(?:\\.|[^'\\])'/.exec(e.slice(s));if(t!==null){let e=t[0].length;r.push(` `.repeat(e)),s+=e-1;continue}}if(n.single&&c===`'`){i=`single`,r.push(` `);continue}if(n.double&&c===`"`){i=`double`,r.push(` `);continue}if(n.backtick&&c==="`"){i=`backtick`,r.push(` `);continue}r.push(c);continue}if(r.push(` `),i===`block`){c===`*`&&e[s+1]===`/`&&(i=`code`,r.push(` `),s+=1);continue}if(o){o=!1;continue}if(c===`\\`){o=!0;continue}if(i===`triple`){c===a&&e.startsWith(a.repeat(3),s)&&(i=`code`,r.push(` `),s+=2);continue}(i===`single`&&c===`'`||i===`double`&&c===`"`||i===`backtick`&&c==="`")&&(i=`code`)}return r.join(``).split(`
7056
7108
  `)}function $z(e,t,n){let r=t,i=Math.min(n,e.length);for(let t=0;t<i;t+=1){let n=e[t];n===`{`?r+=1:n===`}`&&--r}return r}function eB(e,t){return $z(e,t,e.length)}function tB(e){let t=0;for(let n of e)n===`(`?t+=1:n===`)`&&--t;return t}function nB(e){let t=0;for(let n=0;n<e.length;n+=1){let r=e[n];if(r===` `)t+=1;else if(r===` `)t+=4;else break}return t}function rB(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}let iB=new Set(`if.for.while.switch.catch.return.new.else.do.try.case.throw.delete.sizeof.typeof.await.yield.goto.assert.using.import.package.typedef.namespace.define.include.ifdef.ifndef.endif.pragma.undef.class.struct.enum.interface.func.fn.def.type.let.const.var.public.private.protected.static.final.abstract.synchronized.native.transient.volatile.default.readonly.override.declare.export.async`.split(`.`)),aB=new Set([`class`,`interface`,`struct`,`trait`,`impl`,`enum`]),oB=new Set([`class`,`interface`,`struct`,`enum`,`trait`,`impl`,`namespace`,`module`]);function sB(e,t){let n=Qz(e,t),r=[],i=[],a=0,o=0,s;for(let e=0;e<n.length;e+=1){let c=n[e],l=c.trim();if(l===``)continue;let u=a,d=i.length===0?void 0:i[i.length-1];if(!(l.startsWith(`#`)&&t!==`javascript`&&t!==`typescript`)){if(s!==void 0){if(l.startsWith(`{`)){let e=eB(c,u);i.push({name:s.name,kind:s.kind,bodyDepth:Math.max(u+1,e)}),a=Math.max(0,e),s=void 0;continue}s=void 0}if(/^extern\s*\{/.test(l)){a=u;continue}if(!(o>0)){let n=cB(t,l.replace(/^[;,]+\s*/,``),d);if(n!==void 0){let t=$z(c,u,c.length-c.trimStart().length);if(d===void 0?t===0:t===d.bodyDepth){r.push({name:n.name,kind:n.kind,line:e+1,depth:i.length,...d===void 0?{}:{container:d.name}});let a=eB(c,u);a>t&&oB.has(n.kind)?i.push({name:n.name,kind:n.kind,bodyDepth:a}):oB.has(n.kind)&&(s={name:n.name,kind:n.kind,bodyDepth:t,at:t})}}}for(o=Math.max(0,o+tB(c)),a=Math.max(0,eB(c,u));i.length>0&&i[i.length-1].bodyDepth>a;)i.pop()}}return r}function cB(e,t,n){return e===`java`?uB(t,n):e===`c`||e===`cpp`?fB(t,n):e===`go`?pB(t,n):e===`rust`?mB(t,n):_B(t,n)}let lB=/^(?:(?:@[A-Za-z_$][\w$.]*(?:\([^)]*\))?|public|private|protected|static|final|abstract|synchronized|native|transient|volatile|strictfp|sealed|non-sealed)\s+)+/;function uB(e,t){let n=e.replace(lB,``),r=/^(class|interface|enum|record)\s+([A-Za-z_$][\w$]*)/.exec(n);if(r!==null)return{name:r[2],kind:r[1]===`record`?`class`:r[1]};if(t!==void 0&&RegExp(`^${rB(t.name)}(?:\\s*<[^>]*>)?\\s*\\(`).test(n))return{name:t.name,kind:`constructor`};let i=/^(?:<[^>]+>\s*)?([A-Za-z_$][\w$.]*(?:\s*<[^>]*>)?(?:\s*\[\s*\])*)\s+([A-Za-z_$][\w$]*)\s*\(/.exec(n);if(i!==null&&!iB.has(i[1]))return{name:i[2],kind:t===void 0?`function`:`method`};let a=/^([A-Za-z_$][\w$.]*(?:\s*<[^>]*>)?(?:\s*\[\s*\])*)\s+([A-Za-z_$][\w$]*)\s*(?:=|;|,)/.exec(n);if(a!==null&&t!==void 0&&!iB.has(a[1]))return{name:a[2],kind:`field`}}let dB=/^(?:inline|static|extern|constexpr|consteval|constinit|virtual|explicit|friend|const|volatile|unsigned|signed|register|thread_local|struct|class|enum|typename)\s+/;function fB(e,t){let n=e.replace(/^template\s*<[^>]*>\s*/,``).replace(/^typedef\s+/,``),r=/^(struct|union|enum|class)\s+(?:class\s+|struct\s+)?([A-Za-z_]\w*)/.exec(n);if(r!==null){let e=r[1],t=e===`enum`?`enum`:e===`class`?`class`:`struct`;return{name:r[2],kind:t}}let i=/^(?:inline\s+)?namespace\s+([A-Za-z_]\w*)/.exec(n);if(i!==null)return{name:i[1],kind:`namespace`};let a=n;a=a.replace(/^extern\s*$/,``);for(let e=0;e<8;e+=1){let e=a.replace(dB,``);if(e===a)break;a=e}if(t!==void 0&&aB.has(t.kind)){let e=/^(~?[A-Za-z_]\w*)\s*\(/.exec(a);if(e!==null){let n=e[1];if((n===t.name||n.startsWith(`~`))&&!iB.has(n))return{name:n,kind:`constructor`}}}let o=/^([A-Za-z_][\w:<>,\s*&]*?)\s+([A-Za-z_]\w*(?:::[A-Za-z_]\w*)*|~[A-Za-z_]\w*)\s*\(/.exec(a);if(o!==null&&!iB.has(o[1].trim())&&!iB.has(o[2])){let e=o[2];return{name:e,kind:t!==void 0&&aB.has(t.kind)||e.includes(`::`)?`method`:`function`}}let s=/^([A-Za-z_][\w:<>,\s*&]*?)\s+[*&]*([A-Za-z_]\w*)\s*(?:\[[^\]]*\]\s*)*(?:=|;)/.exec(a);if(s!==null&&!iB.has(s[1]))return{name:s[2],kind:t===void 0?`variable`:`field`}}function pB(e,t){let n=/^func\s+(?:\(\s*[A-Za-z_]\w*\s+\*?\s*([A-Za-z_]\w*)\s*\)\s*)?([A-Za-z_]\w*)\s*(?:\[[^\]]*\])?\s*\(/.exec(e);if(n!==null)return{name:n[2],kind:n[1]===void 0?`function`:`method`};let r=/^type\s+([A-Za-z_]\w*)\s+(struct|interface|func|map|chan|\[|\*|[A-Za-z_])/.exec(e);if(r!==null){let e=r[2],t=e===`struct`?`struct`:e===`interface`?`interface`:`type`;return{name:r[1],kind:t}}if(t!==void 0&&(t.kind===`struct`||t.kind===`interface`)){if(t.kind===`interface`){let t=/^([A-Za-z_]\w*)\s*\(/.exec(e);if(t!==null&&!iB.has(t[1]))return{name:t[1],kind:`method`}}let n=/^([A-Za-z_]\w*)(?:\s*,\s*[A-Za-z_]\w*)*\s+[*\[]?[\w.\[\]*]+$/.exec(e);if(n!==null&&!iB.has(n[1]))return{name:n[1],kind:`field`}}}function mB(e,t){let n=/^(?:pub(?:\s*\([^)]*\))?\s+)?(?:(?:async|unsafe|const|extern|default)\s+)*fn\s+(?:<[^>]*>\s*)?([A-Za-z_]\w*)/.exec(e);if(n!==null)return{name:n[1],kind:t!==void 0&&aB.has(t.kind)?`method`:`function`};let r=/^(?:pub(?:\s*\([^)]*\))?\s+)?(?:unsafe\s+)?(?:default\s+)?impl(?:\s*<[^>]*>)?\s+(?:[\w:<>, ]+?\s+for\s+)?([A-Za-z_]\w*)/.exec(e);if(r!==null)return{name:r[1],kind:`impl`};let i=/^(?:pub(?:\s*\([^)]*\))?\s+)?(struct|enum|trait|union)\s+([A-Za-z_]\w*)/.exec(e);if(i!==null){let e=i[1],t=e===`trait`?`trait`:e===`enum`?`enum`:`struct`;return{name:i[2],kind:t}}let a=/^(?:pub(?:\s*\([^)]*\))?\s+)?mod\s+([A-Za-z_]\w*)/.exec(e);if(a!==null)return{name:a[1],kind:`module`};let o=/^(?:pub(?:\s*\([^)]*\))?\s+)?type\s+([A-Za-z_]\w*)/.exec(e);if(o!==null)return{name:o[1],kind:`type`};let s=/^(?:pub(?:\s*\([^)]*\))?\s+)?(?:const|static)\s+(?:mut\s+)?([A-Za-z_]\w*)/.exec(e);if(s!==null)return{name:s[1],kind:t===void 0?`variable`:`field`};let c=/^macro_rules!\s*([A-Za-z_]\w*)/.exec(e);if(c!==null)return{name:c[1],kind:`macro`};if(t!==void 0&&(t.kind===`struct`||t.kind===`trait`||t.kind===`enum`)){let t=/^(?:pub(?:\s*\([^)]*\))?\s+)?([A-Za-z_]\w*)\s*:\s*\S/.exec(e);if(t!==null&&!iB.has(t[1]))return{name:t[1],kind:`field`}}}let hB=/^(?:export\s+)?(?:default\s+)?(?:declare\s+)?/,gB=/^(?:(?:@[A-Za-z_$][\w$.]*(?:\([^)]*\))?|public|private|protected|static|readonly|async|get|set|override|abstract|declare|accessor)\s+)+/;function _B(e,t){let n=e.replace(hB,``),r=/^(?:abstract\s+)?(class|interface|enum|namespace|module)\s+([A-Za-z_$][\w$]*)/.exec(n);if(r!==null)return{name:r[2],kind:r[1]};let i=/^type\s+([A-Za-z_$][\w$]*)\s*[=<]/.exec(n);if(i!==null)return{name:i[1],kind:`type`};let a=/^(?:async\s+)?function\s*\*?\s*([A-Za-z_$][\w$]*)/.exec(n);if(a!==null)return{name:a[1],kind:t!==void 0&&aB.has(t.kind)?`method`:`function`};let o=/^(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*(?::[^=]*)?=\s*([\s\S]*)$/.exec(n);if(o!==null){let e=o[2],t=/^(?:async\s+)?(?:function\b|\([^()]*\)\s*(?::[^=]*)?=>|[A-Za-z_$][\w$]*\s*=>)/.test(e);return{name:o[1],kind:t?`function`:`variable`}}if(t!==void 0&&aB.has(t.kind)){let e=n.replace(gB,``),r=/^#?([A-Za-z_$][\w$]*)\s*(?:<[^>]*>)?\s*\([^;{]*\)\s*(?::[^{;]*)?[;{]/.exec(e);if(r!==null&&!iB.has(r[1])){let e=r[1];return e===`constructor`||e===t.name?{name:e,kind:`constructor`}:{name:e,kind:`method`}}let i=/^#?([A-Za-z_$][\w$]*)\s*(?:[?!])?\s*[:=]/.exec(e);if(i!==null&&!iB.has(i[1]))return{name:i[1],kind:`field`}}}let vB=new Set(`if.elif.else.for.while.return.yield.with.try.except.finally.import.from.assert.del.raise.global.nonlocal.lambda.and.or.not.print.pass.break.continue.def.class.async.await.in.is.as.match`.split(`.`));function yB(e){let t=Qz(e,`python`),n=[],r=[];for(let e=0;e<t.length;e+=1){let i=t[e],a=i.trim();if(a===``)continue;let o=nB(i);for(;r.length>0&&r[r.length-1].indent>=o;)r.pop();let s=r.length>0?r[r.length-1]:void 0;if(s===void 0||s.kind===`class`){let t=/^class\s+([A-Za-z_]\w*)/.exec(a),i=/^(?:async\s+)?def\s+([A-Za-z_]\w*)/.exec(a),c=/^([A-Za-z_]\w*)\s*(?::[^=]+)?=(?!=)/.exec(a);if(t!==null){n.push({name:t[1],kind:`class`,line:e+1,depth:r.length,...s===void 0?{}:{container:s.name}}),r.push({indent:o,name:t[1],kind:`class`});continue}if(i!==null){let t=s!==void 0&&s.kind===`class`?`method`:`function`;n.push({name:i[1],kind:t,line:e+1,depth:r.length,...s===void 0?{}:{container:s.name}}),r.push({indent:o,name:i[1],kind:`function`});continue}c!==null&&!vB.has(c[1])&&n.push({name:c[1],kind:s===void 0?`variable`:`field`,line:e+1,depth:r.length,...s===void 0?{}:{container:s.name}})}}return n}let bB=/^(?:export\s+|public\s+|private\s+|protected\s+|static\s+|final\s+|abstract\s+|pub\s+|async\s+|default\s+)*(class|interface|struct|enum|trait|impl|namespace|module)\s+([A-Za-z_$][\w$]*)/;function xB(e){let t=Qz(e,`unknown`),n=[],r=[];for(let e=0;e<t.length;e+=1){let i=t[e],a=i.trim();if(a===``||a.startsWith(`#`))continue;let o=nB(i);for(;r.length>0&&r[r.length-1].indent>=o;)r.pop();let s=r.length>0?r[r.length-1]:void 0,c=(t,i)=>{n.push({name:t,kind:i,line:e+1,depth:r.length,...s===void 0?{}:{container:s.name}}),r.push({indent:o,name:t,kind:i})},l=bB.exec(a);if(l!==null){let e=l[1],t=e===`class`?`class`:e===`interface`?`interface`:e===`struct`?`struct`:e===`enum`?`enum`:e===`trait`?`trait`:e===`impl`?`impl`:e===`namespace`?`namespace`:`module`;c(l[2],t);continue}let u=/^(?:export\s+|pub\s+|async\s+|static\s+|public\s+|private\s+)*(?:def|func|function|fn|sub|proc|method)\s+([A-Za-z_$][\w$]*)/.exec(a);if(u!==null){c(u[1],s!==void 0&&aB.has(s.kind)?`method`:`function`);continue}let d=/^([A-Za-z_$][\w$]*)\s*\([^()]*\)\s*(?::[^{]*)?\{/.exec(a);if(d!==null&&!iB.has(d[1])){c(d[1],s!==void 0&&aB.has(s.kind)?`method`:`function`);continue}let f=/^([A-Za-z_][\w$]*)\s*[:=](?!=)/.exec(a);f!==null&&!iB.has(f[1])&&n.push({name:f[1],kind:s===void 0?`variable`:`field`,line:e+1,depth:r.length,...s===void 0?{}:{container:s.name}})}return n}function SB(e,t,n){let r=t.length,i=t.slice(0,5e3);return{language:e,entries:i,total:r,truncated:r>i.length,guessed:n}}function CB(e,t){let n=Xz(t);if(n===`python`)return SB(n,yB(e),!1);if(n===`unknown`)return SB(n,xB(e),!0);let r=sB(e,n);return r.length===0&&/[{}]/.test(e)?SB(n,xB(e),!0):SB(n,r,!1)}function wB(e,t,n){let r=Math.max(0,Math.floor(n)),i=e.trim();if(i===``)return{hits:t.slice(0,r),truncated:t.length>r};let a=[];for(let e of t){let t=vz(i,e.name)??(e.container===void 0?void 0:vz(i,`${e.container}.${e.name}`));t!==void 0&&a.push({entry:e,score:t})}return a.sort((e,t)=>t.score-e.score||e.entry.line-t.entry.line),{hits:a.slice(0,r).map(e=>e.entry),truncated:a.length>r}}function TB(e){let{entry:t}=e,n=(0,i.useMemo)(()=>new Set(Sz(e.query,t.name)),[e.query,t.name]);return(0,o.jsxs)(`div`,{className:e.active?`rvs-outline-row active`:`rvs-outline-row`,role:`option`,"aria-selected":e.active,id:e.id,"data-outline-index":e.index,"data-outline-depth":t.depth,"data-outline-kind":t.kind,onMouseDown:t=>{t.preventDefault(),e.onPick()},onMouseEnter:e.onHover,children:[(0,o.jsx)(`span`,{className:`rvs-outline-kind`,"data-kind":t.kind,children:e.t(`outline.kind.${t.kind}`)}),(0,o.jsx)(`span`,{className:`rvs-outline-name`,style:{paddingLeft:`${t.depth*14}px`},title:t.container===void 0?t.name:`${t.container} › ${t.name}`,children:t.name.split(``).map((e,t)=>n.has(t)?(0,o.jsx)(`mark`,{className:`rvs-outline-hit`,children:e},t):(0,o.jsx)(`span`,{children:e},t))}),(0,o.jsx)(`span`,{className:`rvs-outline-line`,children:t.line})]})}function EB(e){let t=(0,i.useId)(),n=e=>`${t}-option-${e}`,r=e.t,s=(0,i.useMemo)(()=>CB(e.text,e.path),[e.text,e.path]),[c,l]=(0,i.useState)(``),[u,d]=(0,i.useState)(0),f=(0,i.useRef)(null),p=(0,i.useRef)(null),m=(0,i.useRef)(null),h=(0,i.useRef)(e.onClose);h.current=e.onClose;let g=(0,i.useRef)(typeof document>`u`?null:document.activeElement);(0,i.useEffect)(()=>(f.current?.focus(),()=>{let e=g.current;e!==null&&document.body.contains(e)&&e.focus()}),[]);let _=(0,i.useMemo)(()=>wB(c,s.entries,300),[c,s]),v=_.hits.length,y=v===0?-1:Math.min(u,v-1);(0,i.useEffect)(()=>{d(0)},[c]),(0,i.useEffect)(()=>{y<0||p.current?.querySelector(`[data-outline-index="${y}"]`)?.scrollIntoView?.({block:`nearest`})},[y]);let b=t=>{e.onPick(t)};return(0,i.useEffect)(()=>{let e=e=>{e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),h.current())};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[]),typeof document>`u`?null:(0,a.createPortal)((0,o.jsx)(`div`,{className:`rvs-portal`,children:(0,o.jsx)(`div`,{className:`rvs-outline-mask`,onMouseDown:t=>{t.target===t.currentTarget&&e.onClose()},children:(0,o.jsxs)(`div`,{className:`rvs-outline`,role:`dialog`,"aria-modal":`true`,"aria-label":r(`outline.title`),ref:m,onKeyDown:e=>{if(e.key!==`Tab`)return;let t=m.current;if(t===null)return;let n=Array.from(t.querySelectorAll(`input:not([disabled]), button:not([disabled]), [tabindex]:not([tabindex="-1"])`));if(n.length===0)return;let r=n[0],i=n[n.length-1],a=document.activeElement;if(!(a!==null&&t.contains(a))){e.preventDefault(),r?.focus();return}if(e.shiftKey&&a===r){e.preventDefault(),i?.focus();return}!e.shiftKey&&a===i&&(e.preventDefault(),r?.focus())},children:[(0,o.jsxs)(`div`,{className:`rvs-outline-head`,children:[(0,o.jsx)(`span`,{className:`rvs-outline-title`,children:r(`outline.title`)}),(0,o.jsx)(`span`,{className:`rvs-outline-path`,title:e.path,children:e.path}),(0,o.jsx)(`button`,{type:`button`,className:`rvs-outline-close`,title:r(`common.close`),"aria-label":r(`common.close`),onClick:e.onClose,children:`×`})]}),(0,o.jsxs)(`div`,{className:`rvs-outline-bar`,children:[(0,o.jsx)(`input`,{ref:f,className:`rvs-outline-input`,type:`text`,value:c,placeholder:r(`outline.placeholder`),spellCheck:!1,autoComplete:`off`,role:`combobox`,"aria-expanded":!0,"aria-controls":t,"aria-activedescendant":y>=0?n(y):void 0,onChange:e=>l(e.target.value),onKeyDown:e=>{if(!(e.nativeEvent.isComposing===!0||e.keyCode===229)){if(e.key===`ArrowDown`||e.key===`ArrowUp`){if(e.preventDefault(),v===0)return;d(t=>{let n=Math.min(t,v-1);return e.key===`ArrowDown`?(n+1)%v:n<=0?v-1:n-1});return}if(e.key===`Enter`){e.preventDefault();let t=y>=0?_.hits[y]:void 0;t!==void 0&&b(t)}}}}),(0,o.jsx)(`span`,{className:`rvs-outline-hint`,children:r(`outline.hint`)})]}),(0,o.jsx)(`div`,{className:`rvs-outline-list`,id:t,role:`listbox`,ref:p,children:_.hits.map((e,t)=>(0,o.jsx)(TB,{entry:e,query:c,active:t===y,index:t,id:n(t),t:r,onPick:()=>b(e),onHover:()=>d(t)},`${e.line}:${e.name}:${t}`))}),(0,o.jsxs)(`div`,{className:`rvs-outline-foot`,children:[v===0?(0,o.jsx)(`span`,{className:`rvs-outline-note`,role:`status`,children:s.entries.length===0?r(`outline.empty`):r(`outline.noResults`)}):(0,o.jsx)(`span`,{className:`rvs-outline-note`,children:_.truncated?r(`outline.more`).replace(`{count}`,String(v)).replace(`{total}`,String(s.total)):`${v} / ${s.total}`}),s.guessed&&(0,o.jsx)(`span`,{className:`rvs-outline-note warn`,role:`status`,children:r(`outline.guessed`)}),s.truncated&&(0,o.jsx)(`span`,{className:`rvs-outline-note warn`,role:`status`,children:r(`outline.truncated`).replace(`{count}`,String(s.entries.length))})]})]})})}),document.body)}function DB(e){return e.replace(/\\/g,`/`).split(`/`).filter(e=>e!==``)}function OB(e,t,n){if(t!==``)return t;let r=DB(e);return r[r.length-1]??n}function kB(e,t,n){let r=e(t);return r===void 0||r===``||r===t?n:r}function AB(e){let t=(0,i.useRef)(null),[n,r]=(0,i.useState)(void 0),[a,s]=(0,i.useState)([]),[c,l]=(0,i.useState)(!1),[u,d]=(0,i.useState)(void 0),f=(0,i.useRef)(0),p=(0,i.useRef)(null),m=(0,i.useRef)(null),h=(0,i.useRef)(!1),g=(0,i.useRef)(!1),_=e.t,v=e.root.replace(/\/+$/,``),y=v!==``&&(e.path===v||e.path.startsWith(`${v}/`)),b=(0,i.useMemo)(()=>{let t=e.path.replace(/\/+$/,``);return v!==``&&t.startsWith(`${v}/`)?DB(t.slice(v.length+1)):DB(t)},[e.path,v]),x=(0,i.useMemo)(()=>{let t=[{label:OB(v,e.rootName,kB(_,`editor.crumbRoot`,`工作区`)),path:v}];for(let[e,n]of b.entries())t.push({label:n,path:`${v}/${b.slice(0,e+1).join(`/`)}`});return t},[v,e.rootName,b,_]),S=(t,n)=>{r({dir:t,left:n}),l(!0),d(void 0),f.current+=1;let i=f.current;(async()=>{try{let n=await V.fileOp.list(e.alias,t);if(f.current!==i)return;let r=[...n].sort((e,t)=>{let n=+!e.isDir,r=+!t.isDir;return n===r?e.name.localeCompare(t.name):n-r});s(r)}catch(e){if(f.current!==i)return;s([]),d(e instanceof Error?e.message:String(e))}finally{f.current===i&&l(!1)}})()};if((0,i.useEffect)(()=>{if(n===void 0)return;let e=e=>{let n=t.current;n!==null&&e.target instanceof Node&&n.contains(e.target)||r(void 0)},i=e=>{e.isComposing||e.key===`Escape`&&(h.current=!0,r(void 0))};return document.addEventListener(`mousedown`,e,!0),document.addEventListener(`keydown`,i,!0),()=>{document.removeEventListener(`mousedown`,e,!0),document.removeEventListener(`keydown`,i,!0)}},[n]),(0,i.useEffect)(()=>{r(void 0)},[e.path]),(0,i.useEffect)(()=>{n!==void 0&&(g.current=!1,p.current?.focus())},[n]),(0,i.useEffect)(()=>{if(n===void 0||c||u!==void 0||a.length===0||g.current)return;let e=p.current;if(e===null)return;let t=document.activeElement;t!==e&&e.contains(t)||(g.current=!0,e.querySelector(`.rvs-crumb-menu-item`)?.focus())},[n,c,u,a]),(0,i.useEffect)(()=>{if(n!==void 0||!h.current)return;h.current=!1;let e=m.current;e!==null&&document.body.contains(e)&&e.focus()},[n]),!y)return(0,o.jsx)(`nav`,{className:`rvs-breadcrumb`,"aria-label":kB(_,`editor.crumbLabel`,`文件路径`),children:(0,o.jsx)(`span`,{className:`rvs-einfo-path`,title:e.path,children:e.path})});let C=(e,t,n)=>{m.current=n.currentTarget;let r=t===x.length-1?e.path.slice(0,Math.max(0,e.path.lastIndexOf(`/`))):e.path;S(r===``?`/`:r,Math.max(0,n.currentTarget.offsetLeft))},w=e=>{if(e===``||e===v||e===`/`)return;let t=DB(e);return t.pop(),t.length===0?void 0:`/${t.join(`/`)}`},T=()=>{let e=p.current;return e===null?[]:Array.from(e.querySelectorAll(`.rvs-crumb-menu-item`))};return(0,o.jsxs)(`nav`,{className:`rvs-breadcrumb`,ref:t,"aria-label":kB(_,`editor.crumbLabel`,`文件路径`),children:[x.map((t,n)=>{let r=n===x.length-1;return(0,o.jsxs)(`span`,{className:`rvs-crumb-wrap`,children:[n>0&&(0,o.jsx)(`span`,{className:`rvs-crumb-sep`,"aria-hidden":`true`,children:`›`}),(0,o.jsx)(`button`,{type:`button`,className:`rvs-crumb${r?` rvs-crumb-file`:``}`,title:r?e.path:t.path,"aria-haspopup":`menu`,onClick:e=>C(t,n,e),children:t.label})]},`${t.path}:${n}`)}),n!==void 0&&(0,o.jsxs)(`div`,{ref:p,className:`rvs-crumb-menu`,role:`menu`,"data-rvs-nonmodal":``,tabIndex:-1,onKeyDown:e=>{if(e.key!==`ArrowDown`&&e.key!==`ArrowUp`&&e.key!==`Home`&&e.key!==`End`)return;let t=T();if(t.length===0)return;e.preventDefault();let n=t.indexOf(document.activeElement);t[e.key===`Home`?0:e.key===`End`?t.length-1:e.key===`ArrowDown`?(n+1)%t.length:n<=0?t.length-1:n-1]?.focus()},style:{left:n.left},children:[(0,o.jsxs)(`div`,{className:`rvs-crumb-menu-head`,children:[(0,o.jsx)(`button`,{type:`button`,className:`rvs-crumb-menu-up`,title:kB(_,`editor.crumbUp`,`上一级`),disabled:w(n.dir)===void 0,onClick:()=>{let e=w(n.dir);e!==void 0&&S(e,n.left)},children:`↑`}),(0,o.jsx)(`span`,{className:`rvs-crumb-menu-path`,title:n.dir,children:n.dir})]}),(0,o.jsxs)(`div`,{className:`rvs-crumb-menu-list`,children:[c&&(0,o.jsx)(`div`,{className:`rvs-crumb-menu-note`,children:kB(_,`common.loading`,`加载中…`)}),!c&&u!==void 0&&(0,o.jsx)(`div`,{className:`rvs-crumb-menu-note rvs-status-error`,children:u}),!c&&u===void 0&&a.length===0&&(0,o.jsx)(`div`,{className:`rvs-crumb-menu-note`,children:kB(_,`editor.crumbEmpty`,`空目录`)}),!c&&u===void 0&&a.map(t=>(0,o.jsxs)(`button`,{type:`button`,role:`menuitem`,className:`rvs-crumb-menu-item${t.isDir?` rvs-dir`:``}`,title:t.path,onClick:()=>{if(t.isDir){S(t.path,n.left);return}e.onOpen(t.path),r(void 0)},children:[(0,o.jsx)(`span`,{className:`rvs-crumb-menu-glyph`,"aria-hidden":`true`,children:t.isDir?`▸`:`·`}),(0,o.jsx)(`span`,{className:`rvs-crumb-menu-name`,children:t.name})]},t.path))]})]})]})}function jB(e){return!Number.isFinite(e)||e<=0?`0 B`:e<1024?`${e} B`:e<1024*1024?`${Math.round(e/1024)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function MB(e,t,n){let r=e?.(t);return r===void 0||r===``||r===t?n:r}function NB(e){let[t,n]=(0,i.useState)(!1),[r,a]=(0,i.useState)(!1),[s,c]=(0,i.useState)(void 0),l=MB(e.t,`editor.imageHint`,`点击切换适应窗口 / 原始大小`),u=[jB(e.size),s===void 0?``:`${s.width} × ${s.height}`].filter(e=>e!==``).join(` · `);return e.truncated===!0?(0,o.jsxs)(`div`,{className:`rvs-editor-notice`,children:[(0,o.jsx)(`div`,{className:`rvs-editor-notice-title`,children:MB(e.t,`editor.imageTooLargeTitle`,`图片过大`)}),(0,o.jsx)(`div`,{children:e.path}),(0,o.jsx)(`div`,{children:MB(e.t,`editor.imageTooLargeHint`,`大小 {size} KiB,超出读取上限,不提供预览。`).replace(`{size}`,String(Math.max(1,Math.round(e.size/1024))))})]}):r?(0,o.jsxs)(`div`,{className:`rvs-image-preview rvs-image-preview-failed`,children:[(0,o.jsx)(`div`,{className:`rvs-editor-notice-title`,children:MB(e.t,`editor.imageFailed`,`图片读取失败。`)}),(0,o.jsx)(`div`,{children:e.path}),(0,o.jsx)(`div`,{children:MB(e.t,`editor.imageFailedHint`,`文件可能已损坏,或不是受支持的图片格式。`)})]}):(0,o.jsxs)(`div`,{className:`rvs-image-preview${t?` rvs-image-actual`:``}`,title:`${e.path}\n${l}`,role:`img`,"aria-label":e.path,onClick:()=>n(e=>!e),children:[(0,o.jsx)(`img`,{className:`rvs-image-preview-img`,src:e.src,alt:e.path,draggable:!1,onDragStart:e=>e.preventDefault(),onLoad:e=>{c({width:e.currentTarget.naturalWidth,height:e.currentTarget.naturalHeight})},onError:()=>a(!0)}),(0,o.jsxs)(`div`,{className:`rvs-image-preview-meta`,children:[(0,o.jsx)(`span`,{children:u}),(0,o.jsx)(`span`,{className:`rvs-image-preview-hint`,children:t?MB(e.t,`editor.imageFitHint`,`点击适应窗口`):l})]})]})}function PB(e){return e!==void 0&&e>67108864?`handoff`:`buffer`}function FB(e){let t=e.replace(/[\\/]+$/,``),n=Math.max(t.lastIndexOf(`/`),t.lastIndexOf(`\\`));return n<0?t:t.slice(n+1)}function IB(e,t){return`${u.download}?${new URLSearchParams({alias:e,path:t}).toString()}`}function LB(e,t){return`${u.downloadDir}?${new URLSearchParams({alias:e,path:t}).toString()}`}function RB(e,t){let n=new URLSearchParams({alias:e});for(let e of t)n.append(`path`,e);return`${u.downloadMany}?${n.toString()}`}function zB(e,t){let n=document.createElement(`a`);n.href=e,n.download=t,n.rel=`noopener`,n.style.display=`none`,document.body.append(n);try{n.click()}finally{n.remove()}}function BB(){let e=Error(`download cancelled`);return e.name=`AbortError`,e}function VB(e,t){let n=new Blob([...e]),r=URL.createObjectURL(n);zB(r,t),setTimeout(()=>{try{URL.revokeObjectURL(r)}catch{}},6e4).unref?.()}async function HB(e,t,n){let r=n.signal,i=()=>r?.aborted===!0;if(i())throw BB();if(!(typeof fetch==`function`&&typeof URL<`u`&&typeof URL.createObjectURL==`function`&&typeof Blob<`u`))return zB(e,t),`handedOff`;let a;try{a=await fetch(e,r===void 0?void 0:{signal:r})}catch(e){throw i()?BB():e}if(!a.ok||a.body===null){let e=await a.text().catch(()=>``);throw Error(e.trim()===``?`HTTP ${a.status}`:e.trim())}let o=a.headers.get(`content-length`),s=o===null?NaN:Number(o),c=Number.isFinite(s)&&s>=0?s:void 0;if(PB(c)===`handoff`){try{await a.body.cancel()}catch{}return zB(e,t),`handedOff`}let l=[],u=0,d=a.body.getReader();try{for(n.onProgress?.({loaded:u,...c===void 0?{}:{total:c}});;){if(i())throw BB();let{done:r,value:a}=await d.read();if(r)break;if(u+=a.byteLength,u>67108864){try{await d.cancel()}catch{}return zB(e,t),`handedOff`}l.push(a),n.onProgress?.({loaded:u,...c===void 0?{}:{total:c}})}}catch(e){try{await d.cancel()}catch{}throw i()?BB():e}return VB(l,t),`saved-browser`}async function UB(e){try{await e.remove?.()}catch{}}async function WB(e,t,n={}){let r=globalThis.showSaveFilePicker;if(typeof r!=`function`)return HB(e,t,n);let i;try{i=await r.call(globalThis,{suggestedName:t})}catch(r){if(r instanceof Error&&r.name===`AbortError`)throw r;if(r instanceof Error&&(r.name===`SecurityError`||r.name===`NotAllowedError`))return HB(e,t,n);throw r}let a=n.signal,o;try{o=await fetch(e,a===void 0?void 0:{signal:a})}catch(e){throw await UB(i),e}if(!o.ok||o.body===null){let e=await o.text().catch(()=>``);throw await UB(i),Error(e.trim()===``?`HTTP ${o.status}`:e.trim())}let s=o.headers.get(`content-length`),c=s===null?NaN:Number(s),l=Number.isFinite(c)&&c>=0?c:void 0,u=await i.createWritable(),d=o.body.getReader(),f=0;try{for(n.onProgress?.({loaded:f,...l===void 0?{}:{total:l}});;){if(a?.aborted===!0)throw BB();let{done:e,value:t}=await d.read();if(e)break;f+=t.byteLength,await u.write(t),n.onProgress?.({loaded:f,...l===void 0?{}:{total:l}})}await u.close()}catch(e){try{await d.cancel()}catch{}try{await u.abort()}catch{}throw await UB(i),e}return`saved-picker`}function GB(e,t,n={}){return WB(IB(e,t),FB(t),n)}function KB(e,t,n={}){let r=FB(t)||`root`;return WB(LB(e,t),`${r}.tar.gz`,n)}function qB(e,t,n={}){return WB(RB(e,t),d(t.length),n)}let JB;function YB(e){return JB=e,()=>{JB===e&&(JB=void 0)}}function XB(e){let t=JB;if(t!==void 0)try{let n=t.get(e);return typeof n==`object`&&n?n:void 0}catch{return}}function ZB(e,t){let n=`${e} ${t??``}`.toLowerCase();return n.includes(`too-large`)||n.includes(`too_large`)?`too-large`:n.includes(`workspace-file/not-found`)||n.includes(`not-regular-file`)?`not-found`:n.includes(`unavailable`)||n.includes(`missing`)?`unavailable`:`failed`}function QB(e,t){if(e===void 0)return{ok:!1,reason:`unavailable`,detail:t};if(e.ok){let t=e.value.data;return!(t instanceof Uint8Array)||t.byteLength===0?{ok:!1,reason:`failed`,detail:`empty payload`}:{ok:!0,data:t,size:typeof e.value.bytes==`number`?e.value.bytes:t.byteLength}}let n=typeof e.error.code==`string`?e.error.code:``,r=typeof e.error.message==`string`?e.error.message:``,i=e.error.details,a=typeof i==`object`&&i&&typeof i.reason==`string`?i.reason:void 0;return{ok:!1,reason:ZB(n,a),detail:[n,a,r].filter(e=>typeof e==`string`&&e!==``).join(`: `)}}async function $B(e,t,n){if(e===``)return{ok:!1,reason:`unavailable`,detail:`no session`};let r=XB(`remote.workspaceFiles`);if(typeof r?.readBytes!=`function`)return{ok:!1,reason:`unavailable`,detail:`remote.workspaceFiles is not mounted`};let i;try{i=await r.readBytes(e,t,{},n)}catch(e){return{ok:!1,reason:`failed`,detail:e instanceof Error?e.message:String(e)}}return QB(i,`remote.workspaceFiles is not mounted`)}async function eV(e,t,n){if(e===``)return{ok:!1,reason:`unavailable`,detail:`no session`};let r=XB(`remote.officeKit`);if(typeof r?.render!=`function`)return{ok:!1,reason:`unavailable`,detail:`remote.officeKit is not mounted`};let i;try{i=await r.render(e,t,`foreground`,n)}catch(e){return{ok:!1,reason:`failed`,detail:e instanceof Error?e.message:String(e)}}return QB(i,`remote.officeKit is not mounted`)}let tV=64*1024*1024;function nV(e){let t=Ho(e);return t===`doc`||t===`docx`||t===`ppt`||t===`pptx`||t===`xls`||t===`xlsx`?t:void 0}function rV(e){let t=nV(e);if(t===void 0)throw Error(`unsupported office extension`);let n=`input.${t}`;return[`tmp=$(mktemp -d) || { echo '@@RVS_FAIL mktemp'; exit 2; }`,`cp ${B(e)} "$tmp/${n}" || { rm -rf "$tmp"; echo '@@RVS_FAIL copy'; exit 3; }`,`if command -v soffice >/dev/null 2>&1; then bin=soffice;`,`elif command -v libreoffice >/dev/null 2>&1; then bin=libreoffice;`,`else rm -rf "$tmp"; echo "@@RVS_NO_SOFFICE"; exit 4; fi`,`cd "$tmp" || { rm -rf "$tmp"; echo '@@RVS_FAIL cd'; exit 5; }`,`"$bin" --headless --convert-to pdf --outdir "$tmp" "$tmp/${n}" >/dev/null 2>&1`,`if [ ! -f "$tmp/input.pdf" ]; then rm -rf "$tmp"; echo "@@RVS_FAIL convert"; exit 6; fi`,`echo "@@RVS_PDF $tmp"`].join(`
7057
7109
  `)}function iV(e){return e instanceof pn||e instanceof Error?e.message:String(e)}async function aV(e,t,n){let r=await fetch(IB(e,t),{signal:n});if(!r.ok){let e=await r.text().catch(()=>``),t=`download failed: HTTP ${r.status}`;try{let n=JSON.parse(e);typeof n.error==`string`&&(t=n.error)}catch{}throw Error(t)}let i=Number(r.headers.get(`content-length`)??`0`);if(Number.isFinite(i)&&i>67108864)throw Object.assign(Error(`file is larger than ${tV} bytes`),{previewKind:`too-large`});let a=new Uint8Array(await r.arrayBuffer());if(a.byteLength>67108864)throw Object.assign(Error(`file is larger than ${tV} bytes`),{previewKind:`too-large`});return a}async function oV(e,t,n){if(nV(t)===void 0)throw Error(`unsupported office document`);let r=await V.exec(e,rV(t),6e4,{signal:n});if(r.error!==void 0)throw Error(r.error);if(r.timedOut)throw Error(`remote LibreOffice conversion timed out`);let i=r.stdout.split(`
7058
- `).map(e=>e.trim()).find(e=>e.startsWith(`@@RVS_PDF `));if(i===void 0)throw r.stdout.includes(`@@RVS_NO_SOFFICE`)?Object.assign(Error(`LibreOffice is not installed on the remote host. Install the host kit with: npm install @deepseek-ai/libreoffice-kit@latest`),{previewKind:`unavailable`}):Error(r.stderr.trim()||`remote LibreOffice conversion failed`);let a=i.slice(10).trim();try{return await aV(e,`${a}/input.pdf`,n)}finally{V.exec(e,`rm -rf ${B(a)}`,15e3).catch(()=>void 0)}}function sV(e){return!Number.isFinite(e)||e<0?``:e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KiB`:`${(e/(1024*1024)).toFixed(1)} MiB`}function cV(e){return(0,o.jsxs)(`div`,{className:`rvs-preview-notice`,role:`alert`,children:[(0,o.jsx)(`div`,{className:`rvs-preview-notice-title`,children:e.title}),(0,o.jsx)(`div`,{className:`rvs-preview-notice-path`,children:e.path}),(0,o.jsx)(`div`,{className:`rvs-preview-notice-hint`,children:e.hint}),e.detail!==void 0&&(0,o.jsx)(`div`,{className:`rvs-preview-notice-detail`,children:e.detail}),e.onRetry!==void 0&&(0,o.jsx)(`button`,{type:`button`,className:`rvs-preview-retry`,onClick:e.onRetry,children:e.t(`common.retry`)})]})}function lV(e){let[t,n]=(0,i.useState)({status:`loading`}),[r,a]=(0,i.useState)(!1),[s,c]=(0,i.useState)(0);if((0,i.useEffect)(()=>{a(!1)},[e.path,e.kind]),(0,i.useEffect)(()=>{let t=new AbortController,r=!0,i,a=`failed`;n({status:`loading`});let o=e.kind===`office`?()=>oV(e.alias,e.path,t.signal):()=>aV(e.alias,e.path,t.signal);return(e.kind===`office`?eV(e.sessionId??``,e.path,t.signal):$B(e.sessionId??``,e.path,t.signal)).then(e=>e.ok?e.data:(a=e.reason,o())).then(t=>{if(!r)return;let a=e.kind===`media`?qo(e.path)?.mime??`application/octet-stream`:`application/pdf`;i=URL.createObjectURL(new Blob([t],{type:a})),n({status:`ready`,url:i,size:t.byteLength})}).catch(e=>{if(!r)return;let t=typeof e==`object`&&e&&`previewKind`in e?e.previewKind:a;n({status:`failed`,error:{kind:t,message:iV(e)}})}),()=>{r=!1,t.abort(),i!==void 0&&URL.revokeObjectURL(i)}},[e.alias,e.path,e.kind,e.revision,s,e.sessionId]),t.status===`loading`)return(0,o.jsxs)(`div`,{className:`rvs-preview-loading`,role:`status`,children:[(0,o.jsx)(`span`,{className:`rvs-preview-spinner`,"aria-hidden":`true`}),(0,o.jsx)(`span`,{children:e.kind===`office`?e.t(`preview.converting`):e.t(`common.loading`)}),e.kind===`office`&&(0,o.jsx)(`span`,{className:`rvs-preview-loading-hint`,children:e.t(`preview.convertingHint`)})]});if(t.status===`failed`){let n=t.error.kind===`too-large`?e.t(`preview.tooLargeTitle`):t.error.kind===`unavailable`?e.t(e.kind===`office`?`preview.officeUnavailableTitle`:`preview.unavailableTitle`):t.error.kind===`not-found`?e.t(`preview.notFoundTitle`):t.error.kind===`remote`?e.t(`preview.remoteTitle`):e.t(`preview.failedTitle`),r=t.error.kind===`too-large`?e.t(`preview.tooLargeHint`):t.error.kind===`unavailable`?e.t(e.kind===`office`?`preview.officeUnavailableHint`:`preview.unavailableHint`):t.error.kind===`not-found`?e.t(`preview.notFoundHint`):t.error.kind===`remote`?e.t(`preview.remoteHint`):e.t(`preview.failedHint`);return(0,o.jsx)(cV,{path:e.path,title:n,hint:r,detail:t.error.message,t:e.t,onRetry:()=>{c(e=>e+1)}})}if(e.kind===`media`){let n=qo(e.path);return r?(0,o.jsx)(cV,{path:e.path,title:e.t(`preview.failedTitle`),hint:e.t(`preview.mediaUnsupported`),t:e.t,onRetry:()=>{a(!1),c(e=>e+1)}}):(0,o.jsxs)(`div`,{className:`rvs-preview-media${n?.kind===`video`?` rvs-preview-media-video`:``}`,children:[n?.kind===`video`?(0,o.jsx)(`video`,{className:`rvs-preview-media-el`,src:t.url,controls:!0,onError:()=>{a(!0)}}):(0,o.jsx)(`audio`,{className:`rvs-preview-media-el`,src:t.url,controls:!0,onError:()=>{a(!0)}}),(0,o.jsxs)(`div`,{className:`rvs-preview-media-meta`,children:[sV(t.size),(0,o.jsx)(`span`,{className:`rvs-preview-media-hint`,children:e.path})]})]})}return(0,o.jsxs)(`div`,{className:`rvs-preview-document`,children:[(0,o.jsx)(`iframe`,{className:`rvs-preview-document-frame`,src:t.url,title:e.path}),(0,o.jsxs)(`div`,{className:`rvs-preview-document-meta`,children:[sV(t.size),(0,o.jsx)(`span`,{className:`rvs-preview-document-hint`,children:e.t(`preview.documentHint`)})]})]})}function uV(e){let[t,n]=(0,i.useState)(void 0),[r,a]=(0,i.useState)(!1);return(0,i.useEffect)(()=>{let t=URL.createObjectURL(new Blob([e.text],{type:`image/svg+xml`}));return n(t),()=>{URL.revokeObjectURL(t)}},[e.text]),(0,i.useEffect)(()=>{a(!1)},[t]),r?(0,o.jsx)(cV,{path:e.path,title:e.t(`preview.svgFailed`),hint:e.t(`preview.svgFailedHint`),t:e.t}):t===void 0?null:(0,o.jsxs)(`div`,{className:`rvs-preview-svg`,children:[(0,o.jsx)(`img`,{className:`rvs-preview-svg-img`,src:t,alt:e.path,onError:()=>{a(!0)}}),(0,o.jsx)(`div`,{className:`rvs-preview-svg-hint`,children:e.truncated?e.t(`preview.truncated`):e.t(`preview.svgHint`)})]})}function dV(e,t){let n=e.slice(0,t);for(;n.length<t;)n.push(``);return n}function fV(e){let t=(0,i.useMemo)(()=>Xo(e.text,Jo(e.path)),[e.text,e.path]),n=Math.min(t.columns,48),r=t.rows.slice(0,400),a=r[0],s=r.slice(1),c=t.rows.length-r.length,l=t.columns-n,u=[];return e.truncated&&u.push(e.t(`preview.truncated`)),t.truncated&&u.push(e.t(`preview.tableTruncated`).replace(`{rows}`,String(Yo.maxRows)).replace(`{cells}`,String(Yo.maxCells))),c>0&&u.push(e.t(`preview.tableHiddenRows`).replace(`{shown}`,String(r.length)).replace(`{rest}`,String(c))),l>0&&u.push(e.t(`preview.tableHiddenColumns`).replace(`{shown}`,String(n)).replace(`{rest}`,String(l))),t.rows.length===0?(0,o.jsx)(cV,{path:e.path,title:e.t(`preview.tableEmptyTitle`),hint:e.t(`preview.tableEmptyHint`),t:e.t}):(0,o.jsxs)(`div`,{className:`rvs-preview-table-wrap`,children:[u.map((e,t)=>(0,o.jsx)(`div`,{className:`rvs-preview-banner`,children:e},`${String(t)}:${e}`)),(0,o.jsx)(`div`,{className:`rvs-preview-table-scroll`,children:(0,o.jsxs)(`table`,{className:`rvs-preview-table`,children:[(0,o.jsx)(`thead`,{children:(0,o.jsxs)(`tr`,{children:[(0,o.jsx)(`th`,{className:`rvs-preview-rownum`,scope:`col`,children:`#`}),dV(a??[],n).map((e,t)=>(0,o.jsx)(`th`,{scope:`col`,children:e},t))]})}),(0,o.jsx)(`tbody`,{children:s.map((e,t)=>(0,o.jsxs)(`tr`,{children:[(0,o.jsx)(`th`,{className:`rvs-preview-rownum`,scope:`row`,children:t+2}),dV(e,n).map((e,t)=>(0,o.jsx)(`td`,{title:e,children:e},t))]},t))})]})})]})}let pV=`dsh-remote-vs.editor.settings`,mV={wrap:!1,fontSize:13};function hV(e){let t=typeof e==`number`?e:typeof e==`string`&&e.trim()!==``?Number(e):NaN;if(!Number.isFinite(t))return;let n=Math.round(t*2)/2;return Math.min(28,Math.max(9,n))}function gV(e,t){let n=hV(e)??mV.fontSize;return hV(n+t*1)??n}function _V(e){if(typeof e!=`string`||e===``)return mV;let t;try{t=JSON.parse(e)}catch{return mV}if(typeof t!=`object`||!t)return mV;let n=t,r=hV(n.fontSize)??mV.fontSize;return{wrap:typeof n.wrap==`boolean`?n.wrap:mV.wrap,fontSize:r}}function vV(e){return JSON.stringify({wrap:e.wrap,fontSize:e.fontSize})}let yV=new Set,bV;function xV(){try{return _V(localStorage.getItem(pV))}catch{return mV}}function SV(e){try{localStorage.setItem(pV,vV(e))}catch{}}function CV(){for(let e of[...yV])try{e()}catch{}}function wV(){return bV===void 0&&(bV=xV()),bV}function TV(e){return yV.add(e),()=>{yV.delete(e)}}function EV(e){let t=wV(),n=e.fontSize===void 0?t.fontSize:hV(e.fontSize)??t.fontSize,r=e.wrap===void 0?t.wrap:e.wrap;if(n===t.fontSize&&r===t.wrap)return;let i={wrap:r,fontSize:n};bV=i,SV(i),CV()}function DV(e){return e===void 0||e.kind!==`file`||e.image||e.binary||e.loading||e.error!==void 0?!1:!(e.preview&&Go(Uo(e.fullPath)))}let OV=`dsh-remote-vs.editor.blame`,kV=new Map;function AV(){try{return localStorage.getItem(OV)===`1`}catch{return!1}}function jV(e){try{localStorage.setItem(OV,e?`1`:`0`)}catch{}}function MV(e){if(e===``)return 1;let t=1;for(let n=0;n<e.length;n+=1)e.charCodeAt(n)===10&&(t+=1);return t}function NV(e,t,n){return new Promise((r,i)=>{let a=setTimeout(()=>i(Error(`${n} (${Math.round(t/1e3)}s)`)),t);a.unref?.(),e.then(e=>{clearTimeout(a),r(e)},e=>{clearTimeout(a),i(e instanceof Error?e:Error(String(e)))})})}function PV(e,t){if(t.mtime===null)return e(`editor.conflictDeleted`);let n=e(`editor.conflictBody`).replace(`{time}`,new Date(t.mtime).toLocaleString());return t.size===null?n:`${n} · ${t.size} B`}function FV(e,t){return t.error===void 0?t.hunks.length===0?e(`editor.conflictSame`):e(`editor.conflictDiffHead`):t.error}function IV(e){return e.loading?`common.loading`:e.saving?`editor.saving`:e.dirty?`editor.unsaved`:`editor.saved`}function LV(e){return e.loading||e.saving?`saving`:e.dirty?`dirty`:`saved`}function RV(e,t){return e(t===`del`?`changes.undoActionDelete`:`changes.undoAction`)}function zV(e){return e.kind===`diff`?(0,o.jsx)(Rs,{size:11}):e.image?(0,o.jsx)(`span`,{children:`▣`}):(0,o.jsx)(`span`,{children:`▪`})}function BV(e){return`${e.id}:${e.reloadNonce??0}`}function VV(e,t,n){let r={};for(let[n,i]of Object.entries(e))n!==t&&(r[n]=i);r[t]=n;let i=Object.keys(r);for(let e of i.slice(0,Math.max(0,i.length-4)))delete r[e];return r}function HV(e,t){let n=Object.keys(e).filter(n=>n!==t&&e[n].length>2097152);if(n.length===0)return e;let r={...e};for(let e of n)delete r[e];return r}function UV(e){return`${e.fullPath}@${e.reloadNonce??0}`}function WV(){return(0,i.useSyncExternalStore)(TV,wV,wV)}function GV(e){let t=`rvs-status-item${e.error===!0?` rvs-status-error`:``}`;return e.onClick===void 0?(0,o.jsx)(`span`,{className:t,title:e.title,children:e.children}):(0,o.jsx)(`button`,{type:`button`,className:`${t} rvs-status-btn`,title:e.title,onClick:e.onClick,children:e.children})}function KV(e){let t=e.caret,n=e.t,r=e.loading?n(`common.loading`):e.saving?n(`editor.statusSaving`):e.dirty?n(`editor.unsaved`):n(`editor.statusClean`);return(0,o.jsxs)(`div`,{className:`rvs-statusbar`,children:[(0,o.jsx)(`div`,{className:`rvs-status-left`,children:e.diff?(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(GV,{title:n(`editor.diffTitle`),children:n(`editor.diffTitle`)}),(0,o.jsx)(GV,{title:n(`editor.diffReadOnlyTitle`),children:n(`editor.statusReadOnly`)})]}):(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(GV,{title:n(`editor.statusLanguage`),children:e.language}),(0,o.jsx)(GV,{title:n(`editor.statusPosition`),children:n(`editor.statusPositionValue`).replace(`{line}`,String(t?.line??1)).replace(`{column}`,String(t?.column??1))}),t!==void 0&&t.selected>0&&(0,o.jsx)(GV,{title:n(`editor.statusSelected`),children:n(`editor.statusSelectedValue`).replace(`{count}`,String(t.selected))}),e.indent!==void 0&&(0,o.jsx)(GV,{title:n(`editor.statusIndent`),children:e.indent})]})}),(0,o.jsxs)(`div`,{className:`rvs-status-right`,children:[e.error!==void 0&&(0,o.jsx)(GV,{title:e.error,error:!0,children:n(`editor.statusError`)}),e.diff?null:(0,o.jsxs)(o.Fragment,{children:[e.readOnly&&(0,o.jsx)(GV,{title:n(`editor.statusReadOnlyTitle`),children:n(`editor.statusReadOnly`)}),(0,o.jsx)(GV,{title:n(`editor.statusWrapToggle`),onClick:()=>EV({wrap:!e.wrap}),children:e.wrap?n(`editor.statusWrapOn`):n(`editor.statusWrapOff`)}),(0,o.jsx)(GV,{title:n(`editor.statusFont`),children:`${e.fontSize}px`}),(0,o.jsx)(GV,{title:n(`editor.statusSaved`),children:r})]}),(0,o.jsx)(GV,{title:n(`editor.statusEncoding`),children:`UTF-8`})]})]})}function qV(e){let t=pl(),{t:n,tabs:r,activeTab:a,alias:c}=t,l=a===void 0?``:_l(t.repoRoot,a.fullPath),u=WV(),d=t.editorSurface===`center`?`center`:t.editorSurface===`float`?`float`:`sidebar`,f=d===`center`,p=d===`float`?void 0:{"--rvs-editor-font-size":`${u.fontSize}px`},m=a?.changeSet?.hunks??[],h=sR(t.ctx),g=t.workspace===void 0?void 0:t.aliasPaths[t.workspace.id],_=h.sessionId!==void 0&&h.sessionWorkspacePath!==void 0&&g!==void 0&&hI(h.sessionWorkspacePath,g),v=ce()?.state===`error`,y=(0,i.useRef)(new Map),[b,x]=(0,i.useState)({}),[S,C]=(0,i.useState)({}),[T,E]=(0,i.useState)(void 0);(0,i.useEffect)(()=>{E(void 0)},[a?.id]);let[D,O]=(0,i.useState)(void 0);(0,i.useEffect)(()=>{O(void 0)},[a?.id]);let[k,j]=(0,i.useState)(AV),[M,N]=(0,i.useState)(kV),[ee,P]=(0,i.useState)(void 0),[F,I]=(0,i.useState)(void 0),te=(0,i.useRef)(0),L=(0,i.useRef)(new Set),R=(0,i.useRef)(``),ne=(0,i.useRef)(void 0),[z,re]=(0,i.useState)(!1),[ie,ae]=(0,i.useState)([]),[oe,se]=(0,i.useState)(!1),[le,ue]=(0,i.useState)(void 0);(0,i.useEffect)(()=>{te.current+=1,L.current.clear(),R.current=``,P(void 0),N(kV),I(void 0),re(!1),ae([]),ue(void 0)},[a?.id,a?.dirty,a?.reloadNonce]);let de=(0,i.useCallback)(()=>{j(e=>{let t=!e;return jV(t),t})},[]);(0,i.useEffect)(()=>{let e=a;if(!k||e===void 0||e.kind!==`file`||e.loading||e.dirty||e.binary||e.truncated||e.preview||Wo(Uo(e.fullPath))||c===``||t.repoRoot===void 0||l===``||ee===void 0){N(kV);return}let n=MV(e.text),r=`${e.id}:${e.reloadNonce??0}:${l}:${k?`1`:`0`}`;if(R.current===r)return;let i=di(ee.from,ee.to,n,new Set(M.keys()));if(i===void 0)return;let{from:o,to:s}=i,u=`${e.id}:${e.reloadNonce??0}:${o}:${s}`;if(L.current.has(u))return;L.current.add(u);let d=++te.current,f=new AbortController;return Ii(c,t.repoRoot,l,o,s,{signal:f.signal}).then(e=>{d===te.current&&(N(t=>{let n=new Map(t);for(let t of e)n.set(t.line,t);return n}),I(void 0))}).catch(e=>{L.current.delete(u),!f.signal.aborted&&d===te.current&&(R.current=r,I(e instanceof Error?e.message:String(e)))}),()=>{f.abort()}},[a?.id,a?.dirty,a?.reloadNonce,k,M,ee?.from,ee?.to,c,l,t.repoRoot]);let fe=(0,i.useCallback)((e,t)=>{ne.current!==void 0&&window.clearTimeout(ne.current),ne.current=window.setTimeout(()=>{ne.current=void 0,P(n=>n!==void 0&&n.from===e&&n.to===t?n:{from:e,to:t})},140)},[]);(0,i.useEffect)(()=>()=>{ne.current!==void 0&&window.clearTimeout(ne.current)},[]),(0,i.useEffect)(()=>{let e=a;if(!z||e===void 0||e.kind!==`file`||c===``||t.repoRoot===void 0||l===``){ae([]),ue(void 0),se(!1);return}let n=!1;return se(!0),ue(void 0),Li(c,t.repoRoot,l,100).then(e=>{n||(ae(e),se(!1))}).catch(e=>{n||(ue(e instanceof Error?e.message:String(e)),se(!1))}),()=>{n=!0}},[z,a?.id,a?.dirty,c,l,t.repoRoot]),(0,i.useEffect)(()=>{if(!z)return;let e=e=>{e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),re(!1))};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[z]);let[pe,me]=(0,i.useState)(void 0);(0,i.useEffect)(()=>{let t=a;if(e.visible===!1||t===void 0||!t.image||c===``||t.truncated)return;let r=UV(t);if(b[r]!==void 0||S[r]!==void 0)return;let i=!1;return(async()=>{try{let e=await V.fileOp.read(c,t.fullPath);if(i)return;if(e.base64===void 0){C(e=>VV(e,r,n(`editor.imageFailed`)));return}x(n=>VV(n,r,`data:${ec(t.fullPath)};base64,${e.base64}`))}catch(e){i||C(t=>VV(t,r,e instanceof Error?e.message:String(e)))}})(),()=>{i=!0}},[a,c,b,S,n,e.visible]),(0,i.useEffect)(()=>{x(e=>HV(e,a===void 0?void 0:UV(a)))},[a?.fullPath,a?.reloadNonce]);let he=async e=>{e.dirty&&!await hc({title:n(`editor.closeDirty`),text:e.rel,danger:!0,okText:n(`editor.discardClose`)})||t.closeTab(e.id)},ge=async e=>{e.dirty&&!await hc({title:n(`editor.reloadDirty`),text:e.rel,danger:!0,okText:n(`editor.discardReload`)})||await t.reloadTab(e.id)},_e=a?.text,ve=a?.html===!0,B=a?.markdown===!0,ye=a?.preview===!0,be=a?.kind===`file`?Uo(a.fullPath):`text`,xe=Wo(be),Se=(0,i.useSyncExternalStore)(CI,bI),Ce=(0,i.useMemo)(()=>{if(!ve)return``;let e=Se;return[`<!doctype html><meta charset="utf-8">`,`<meta http-equiv="Content-Security-Policy" content="${[`default-src 'none'`,`style-src 'unsafe-inline'`,`img-src data: blob:`,`font-src data:`,`media-src data: blob:`,`form-action 'none'`,`base-uri 'none'`].join(`; `)}">`,`<style>`,`:root{color-scheme:${e?`dark`:`light`}}`,`html,body{background:${e?`#1e1e1e`:`#ffffff`};color:${e?`#d4d4d4`:`#1f1f1f`}}`,`body{margin:14px;font:14px/1.65 system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;overflow-wrap:break-word}`,`img,video,canvas{max-width:100%;height:auto}`,`table{border-collapse:collapse}`,`td,th{border:1px solid ${e?`rgba(255,255,255,.14)`:`rgba(0,0,0,.12)`};padding:4px 8px}`,`pre{overflow:auto}`,`</style>`,_e??``].join(``)},[ve,_e,Se]),we=(0,i.useMemo)(()=>({code:{copyLabel:n(`preview.copyCode`),copiedLabel:n(`preview.copied`)},footnotes:n(`preview.footnotes`)}),[n]),Te=(0,i.useMemo)(()=>!B||!ye||_e===void 0?null:(0,o.jsxs)(`div`,{className:`rvs-preview-scroll`,children:[a?.truncated===!0&&(0,o.jsx)(`div`,{className:`rvs-preview-banner`,children:n(`preview.truncated`)}),(0,o.jsx)(`div`,{className:`rvs-preview-markdown rvs-markdown`,"data-preview-path":a?.fullPath??``,children:(0,o.jsx)(s.MarkdownText,{text:_e,labels:we,variant:`body`})})]}),[B,ye,_e,we,a?.fullPath,a?.truncated,n]),Ee=(0,i.useMemo)(()=>{if(!(a===void 0||a.kind!==`file`||a.binary))return MI(a.text)},[a]),De=(0,i.useRef)(null),Oe=(0,i.useRef)(null),ke=(0,i.useCallback)((e,t)=>{ro(e,t)},[]);(0,i.useEffect)(()=>{ao(new Set(r.map(e=>e.id)))},[r]);let Ae=a!==void 0&&a.kind===`file`&&!a.image&&!a.binary&&!a.loading&&a.error===void 0;(0,i.useEffect)(()=>{if(!(!Ae||a===void 0))return Za(a.id,()=>De.current)},[Ae,a?.id]),(0,i.useEffect)(()=>{let e=Oe.current;if(e===null)return;let t=e=>{if(!(e.ctrlKey||e.metaKey))return;e.preventDefault();let t=e.deltaY<0?1:-1;EV({fontSize:gV(wV().fontSize,t)})};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[r.length]);let je=async()=>{let e=a;if(e===void 0)return;if(v){H(n(`connection.saveBlocked`),!0);return}let r=De.current?.getContent();if(r===void 0){H(n(`editor.needSource`),!0);return}await t.saveTab(e.id,r)},Me=async e=>{let r=De.current?.getContent()??(e.text===``?void 0:e.text);if(r===void 0){H(n(`editor.needSource`),!0);return}await hc({title:n(`editor.conflictOverwriteTitle`),text:e.rel,danger:!0,okText:n(`editor.conflictOverwrite`)})&&(me(void 0),await t.saveTab(e.id,r,{force:!0}))},Ne=async e=>{let t=De.current?.getContent()??e.text;try{let r=await NV(V.fileOp.read(c,e.fullPath),w(Tn()),n(`editor.readTimeout`));me({tabId:e.id,remoteMtime:r.mtime,hunks:Id(r.text??``,t).hunks})}catch(t){me({tabId:e.id,remoteMtime:null,hunks:[],error:t instanceof Error?t.message:String(t)})}},Pe=(0,i.useRef)(je);Pe.current=je;let Fe=(0,i.useRef)(a);Fe.current=a,(0,i.useEffect)(()=>{if(e.visible)return YD(()=>{if(typeof document<`u`&&document.querySelector(`.rvs-modal-mask`)!==null)return;let e=Fe.current;if(!(e===void 0||e.kind!==`file`||e.image||e.binary||Wo(Uo(e.fullPath))))return()=>{Pe.current()}})},[e.visible]);let[Ie,Le]=(0,i.useState)(void 0);(0,i.useEffect)(()=>{Le(void 0)},[a?.id,a?.reloadNonce]),(0,i.useEffect)(()=>{e.visible||Le(void 0)},[e.visible]);let Re=(0,i.useCallback)(()=>{let e=Fe.current;DV(e)&&Le({tabId:e.id,path:e.fullPath,text:De.current?.getContent()??e.text})},[]),ze=(0,i.useCallback)(()=>{Le(void 0)},[]),Be=(0,i.useCallback)(e=>{Le(void 0),window.setTimeout(()=>{De.current?.revealRange(e.line,e.line)},0)},[]),Ve=(0,i.useRef)(Re);Ve.current=Re;let He=(0,i.useRef)(ze);He.current=ze;let Ue=(0,i.useRef)(!1);if(Ue.current=Ie!==void 0,(0,i.useEffect)(()=>{if(!e.visible)return;let t=e=>{if(e.defaultPrevented)return;let t=(e.ctrlKey||e.metaKey)&&e.shiftKey&&!e.altKey,n=e.altKey&&!e.ctrlKey&&!e.metaKey&&!e.shiftKey;if(!t&&!n||e.key.toLowerCase()!==`o`||e.repeat||e.isComposing===!0)return;if(Ue.current){e.preventDefault(),He.current();return}if(qD())return;let r=document.activeElement;r instanceof HTMLElement&&r.closest(`.xterm`)!==null||r instanceof HTMLElement&&r.closest(`.xterm, textarea, input, [contenteditable="true"]`)!==null&&r.closest(`.rvs-editor-host`)===null||DV(Fe.current)&&(e.preventDefault(),Ve.current())};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e.visible]),r.length===0)return f?(0,o.jsx)(`div`,{className:`rvs-pane grow rvs-edge`,children:(0,o.jsxs)(`div`,{className:`rvs-editor-empty`,children:[(0,o.jsx)(`div`,{className:`rvs-editor-empty-glyph`,"aria-hidden":`true`,children:`✎`}),(0,o.jsx)(`div`,{className:`rvs-editor-empty-title`,children:n(`editor.centerEmptyTitle`)}),(0,o.jsx)(`div`,{className:`rvs-editor-empty-hint`,children:n(`editor.centerEmptyHint`)}),(0,o.jsx)(`div`,{className:`rvs-editor-empty-hint`,style:{opacity:.7},children:n(`editor.emptyShortcuts`)})]})}):(0,o.jsx)(`div`,{className:`rvs-pane grow rvs-edge`,children:(0,o.jsxs)(`div`,{className:`rvs-empty`,children:[(0,o.jsx)(`div`,{className:`rvs-empty-title`,children:n(`editor.dockEmptyTitle`)}),(0,o.jsx)(`div`,{className:`rvs-empty-hint`,children:n(`editor.dockEmptyHint`)})]})});let We=a?.kind===`diff`,Ge=a!==void 0&&a.kind===`diff`&&a.sessionDiff===void 0&&a.ref===void 0&&a.diff!==void 0&&!a.diff.unsupported&&!(a.diff.newText===``&&a.diff.oldText!==``),Ke=a?.fullPath??``,qe=``;a?.kind===`diff`&&(a.sessionDiff===void 0?a.ref===void 0?a.staged&&(qe=n(`scm.stagedReadonly`)):qe=`${n(`scm.commitDiff`)} ${a.ref.slice(0,7)}`:qe=n(`changes.diffTabLabel`));let Je=(()=>{let e=a?.changeSet;if(a===void 0||e==null)return;let t=e.blocks,r=Hr(a.id)?.sessionId;if(t===void 0||r===void 0||r===``)return;let i=()=>{try{return window.localStorage}catch{return}};return{isConfirmed:e=>{let n=cR(t,e),a=i();return n===void 0||a===void 0?!1:_R(a,r,n)},onToggle:e=>{let n=cR(t,e),a=i();n===void 0||a===void 0||gR(a,r,n)},label:()=>n(`changes.confirmBlock`),pressedLabel:()=>n(`changes.confirmedBlock`)}})(),Ye=We?`Diff`:a?.image===!0?`Image`:Ko(be)??HI(VI(a?.rel??``)),Xe=a===void 0?void 0:UV(a),Ze=a!==void 0&&a.image&&Xe!==void 0?b[Xe]:void 0,Qe=a!==void 0&&a.image&&Xe!==void 0?S[Xe]:void 0,$e=D===void 0?void 0:M.get(D.line);return(0,o.jsxs)(`div`,{className:`rvs-pane grow rvs-edge`,style:{...p??{},position:`relative`},children:[(0,o.jsx)(`div`,{className:`rvs-etabs`,role:`tablist`,"aria-label":n(`editor.tabsLabel`),children:r.map((e,i)=>{let a=e.id===t.activeTabId,s=e.kind===`diff`;return(0,o.jsxs)(`div`,{role:`tab`,tabIndex:a?0:-1,"aria-selected":a,ref:t=>{t===null?y.current.delete(e.id):y.current.set(e.id,t)},className:`rvs-etab${a?` active`:``}${s?` rvs-etab-diff`:``}`,title:s?`${e.rel}${n(`editor.diffSuffix`)}`:e.fullPath,onClick:()=>t.activateTab(e.id),onAuxClick:t=>{t.button===1&&(t.preventDefault(),he(e))},onKeyDown:n=>{if(n.nativeEvent.isComposing)return;if(n.key===`Enter`||n.key===` `){n.preventDefault(),t.activateTab(e.id);return}let a=n.key===`ArrowRight`?1:n.key===`ArrowLeft`?-1:void 0;if(a===void 0&&n.key!==`Home`&&n.key!==`End`)return;n.preventDefault();let o=n.key===`Home`?0:n.key===`End`?r.length-1:(i+(a??0)+r.length)%r.length,s=r[o];s!==void 0&&(t.activateTab(s.id),y.current.get(s.id)?.focus())},children:[(0,o.jsx)(`span`,{className:`rvs-etab-glyph`,children:zV(e)}),(0,o.jsxs)(`span`,{className:`rvs-etab-name`,children:[ic(e.rel),s&&(0,o.jsx)(`span`,{style:{opacity:.6},children:n(`editor.diffSuffix`)})]}),e.dirty&&(0,o.jsx)(`span`,{className:`rvs-etab-dot`,title:n(`editor.unsaved`)}),(0,o.jsx)(`button`,{type:`button`,className:`rvs-etab-close`,title:n(`common.close`),"aria-label":n(`common.close`),onClick:t=>{t.stopPropagation(),he(e)},children:(0,o.jsx)(ys,{size:11})})]},e.id)})}),a!==void 0&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(`div`,{className:`rvs-einfo`,children:[f&&a.kind===`file`?(0,o.jsx)(AB,{t:n,alias:c,root:t.root,rootName:t.workspace?.name??``,path:Ke,onOpen:e=>{t.openFile(e)}}):(0,o.jsx)(`span`,{className:`rvs-einfo-path`,title:Ke,children:Ke}),(0,o.jsxs)(`span`,{className:`rvs-einfo-actions`,children:[a.kind===`file`&&Go(be)&&(0,o.jsx)(wc,{value:a.preview?`preview`:`source`,onChange:e=>t.updateTab(a.id,{preview:e===`preview`}),options:[{id:`preview`,label:n(`editor.preview`)},{id:`source`,label:n(`editor.source`)}]}),a.kind===`diff`&&(0,o.jsx)(`span`,{style:{color:`var(--rvs-fg3)`},children:qe}),(0,o.jsx)(`span`,{style:{color:`var(--rvs-fg3)`},children:Ye}),(0,o.jsx)(jd,{compact:!0}),(0,o.jsx)(`span`,{className:`rvs-build`,title:`dsh-remote-vs build 1130-1443`,children:`1130-1443`}),T!==void 0&&!xe&&(0,o.jsxs)(`span`,{className:`rvs-build`,title:n(`editor.tokenCount`),children:[`tok `,T]}),a.kind===`file`&&(0,o.jsxs)(o.Fragment,{children:[!xe&&!a.image&&(0,o.jsx)(`span`,{className:`rvs-status ${LV(a)}`,children:n(IV(a))}),(0,o.jsx)(U,{title:n(`editor.reloadFile`),onClick:()=>{ge(a)},disabled:v||a.loading,children:(0,o.jsx)(hs,{size:13})}),!xe&&!a.image&&(0,o.jsx)(U,{title:`${n(`editor.save`)} (Ctrl+S)`,onClick:()=>{je()},disabled:v||a.loading||a.binary||a.truncated||!a.dirty,children:(0,o.jsx)(Vs,{size:13})}),!a.image&&!a.binary&&!Wo(be)&&(0,o.jsx)(U,{title:`${n(`editor.outline`)} (Ctrl+Shift+O)`,onClick:Re,disabled:!DV(a),children:(0,o.jsx)(`span`,{className:`rvs-glyph-text`,children:`≡`})})]}),a.kind===`diff`&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(U,{title:n(`scm.reloadDiff`),onClick:()=>{ge(a)},disabled:v,children:(0,o.jsx)(hs,{size:13})}),Ge&&(0,o.jsx)(U,{title:n(`editor.switchToEdit`),onClick:()=>{t.openFile(a.fullPath)},children:(0,o.jsx)(Fs,{size:13})})]}),a.kind===`file`&&!a.image&&!a.binary&&!xe&&(0,o.jsx)(U,{title:n(`editor.wrap`),onClick:()=>EV({wrap:!u.wrap}),children:(0,o.jsx)(us,{size:13})}),a.kind===`file`&&!a.image&&!a.binary&&!Wo(be)&&l!==``&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(U,{title:F===void 0?n(`editor.blameToggle`):`${n(`editor.blameToggle`)}: ${F}`,className:k?`rvs-hbtn-on`:void 0,onClick:de,children:(0,o.jsx)(`span`,{className:`rvs-glyph-text`,children:`B`})}),(0,o.jsx)(U,{title:n(`editor.fileHistory`),className:z?`rvs-hbtn-on`:void 0,onClick:()=>{re(e=>!e)},children:(0,o.jsx)(Rs,{size:13})}),k&&$e!==void 0&&ui($e.hash)&&(0,o.jsx)(U,{title:n(`editor.blameOpenCaret`),onClick:()=>{t.focusCommit($e.hash)},children:(0,o.jsx)(`span`,{className:`rvs-glyph-text`,children:`↗`})})]}),(0,o.jsx)(`span`,{className:`rvs-einfo-actions-divider`,"aria-hidden":`true`}),d!==`float`&&!xe&&!a.image&&a.kind!==`diff`&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(U,{title:n(`editor.fontSmaller`),onClick:()=>EV({fontSize:gV(u.fontSize,-1)}),children:(0,o.jsx)(`span`,{className:`rvs-font-glyph`,children:`A−`})}),(0,o.jsx)(U,{title:n(`editor.fontLarger`),onClick:()=>EV({fontSize:gV(u.fontSize,1)}),children:(0,o.jsx)(`span`,{className:`rvs-font-glyph`,children:`A+`})})]}),d!==`float`&&(0,o.jsx)(U,{title:n(`float.title`),onClick:()=>{t.openFloatingEditor()},children:(0,o.jsx)(zs,{size:13})}),d===`center`?(0,o.jsx)(U,{title:n(`editor.dockToSidebar`),onClick:()=>{t.dockEditorSidebar()},children:(0,o.jsx)(ls,{size:13})}):d===`sidebar`?(0,o.jsx)(U,{title:n(`editor.openInCenter`),onClick:()=>{t.openEditorInCenter()},children:(0,o.jsx)(cs,{size:13})}):null]})]}),z&&a.kind===`file`&&(0,o.jsxs)(`div`,{className:`rvs-file-history`,role:`dialog`,"aria-label":n(`editor.fileHistory`),children:[(0,o.jsxs)(`div`,{className:`rvs-file-history-head`,children:[(0,o.jsx)(`span`,{className:`rvs-file-history-title`,children:n(`editor.fileHistory`)}),(0,o.jsx)(`span`,{className:`rvs-file-history-path`,title:l,children:l}),(0,o.jsx)(`button`,{type:`button`,className:`rvs-file-history-close`,title:n(`common.close`),"aria-label":n(`common.close`),onClick:()=>{re(!1)},children:(0,o.jsx)(ys,{size:11})})]}),oe&&(0,o.jsx)(`div`,{className:`rvs-file-history-note`,children:n(`common.loading`)}),!oe&&le!==void 0&&(0,o.jsx)(`div`,{className:`rvs-file-history-note error`,children:le}),!oe&&le===void 0&&ie.length===0&&(0,o.jsx)(`div`,{className:`rvs-file-history-note`,children:n(`editor.fileHistoryEmpty`)}),!oe&&le===void 0&&ie.length>0&&(0,o.jsx)(`div`,{className:`rvs-file-history-list`,children:ie.map(e=>(0,o.jsxs)(`button`,{type:`button`,className:`rvs-file-history-row`,onClick:()=>{re(!1),t.openCommitFile(e.hash,e.path,e.origPath)},children:[(0,o.jsx)(`span`,{className:`rvs-file-history-hash`,children:e.hash.slice(0,7)}),(0,o.jsx)(`span`,{className:`rvs-file-history-subject`,title:e.subject,children:e.subject}),(0,o.jsxs)(`span`,{className:`rvs-file-history-meta`,children:[e.author,` · `,new Date(e.date*1e3).toLocaleDateString()]})]},e.hash))})]}),Ie!==void 0&&Ie.tabId===a.id&&(0,o.jsx)(EB,{t:n,path:Ie.path,text:Ie.text,onPick:Be,onClose:ze}),(0,o.jsxs)(`div`,{className:`rvs-body`,ref:Oe,children:[(a.kind===`file`||a.kind===`diff`)&&a.conflict!==void 0&&(0,o.jsxs)(`div`,{className:`rvs-banner warn rvs-conflict`,role:`alert`,children:[(0,o.jsxs)(`div`,{className:`rvs-conflict-text`,children:[(0,o.jsx)(`strong`,{children:n(`editor.conflictTitle`)}),` `,PV(n,a.conflict)]}),(0,o.jsxs)(`div`,{className:`rvs-conflict-actions`,children:[(0,o.jsx)(cz,{onClick:()=>{Ne(a)},children:n(`editor.conflictDiff`)}),(0,o.jsx)(cz,{onClick:()=>{ge(a)},disabled:v,children:n(`editor.conflictReload`)}),(0,o.jsx)(cz,{kind:`danger`,onClick:()=>{Me(a)},disabled:v,children:n(`editor.conflictOverwrite`)}),(0,o.jsx)(cz,{onClick:()=>{t.dismissConflict(a.id),me(void 0)},children:n(`common.close`)})]})]}),pe!==void 0&&a.conflict!==void 0&&pe.tabId===a.id&&(0,o.jsxs)(`div`,{className:`rvs-conflict-diff`,role:`region`,"aria-label":n(`editor.conflictDiff`),children:[(0,o.jsxs)(`div`,{className:`rvs-conflict-diff-head`,children:[FV(n,pe),pe.remoteMtime!==null&&` · ${new Date(pe.remoteMtime).toLocaleString()}`]}),pe.hunks.slice(0,20).map((e,t)=>(0,o.jsxs)(`div`,{className:`rvs-conflict-hunk`,children:[(0,o.jsx)(`div`,{className:`rvs-conflict-hunk-head`,children:`@@ -${e.oldStart},${e.oldLines} +${e.newStart},${e.newLines} @@`}),e.lines.map((e,t)=>(0,o.jsx)(`div`,{className:`rvs-conflict-row${e.startsWith(`+`)?` add`:``}${e.startsWith(`-`)?` del`:``}`,children:e},`line-${t}`))]},`hunk-${t}`)),pe.hunks.length>20&&(0,o.jsx)(`div`,{className:`rvs-conflict-more`,children:n(`editor.conflictMoreHunks`).replace(`{count}`,String(pe.hunks.length-20))})]}),a.kind===`file`&&m.length>0&&a.changeStale!==!0&&(0,o.jsxs)(`div`,{className:`rvs-change-nav`,role:`group`,"aria-label":n(`changes.navLabel`),children:[(0,o.jsxs)(`span`,{className:`rvs-change-nav-count`,title:n(`changes.navLabel`),children:[Math.min((a.activeHunk??0)+1,m.length),`/`,m.length]}),(0,o.jsx)(`button`,{type:`button`,className:`rvs-change-nav-btn`,title:n(`changes.prev`),"aria-label":n(`changes.prev`),onClick:()=>{_d(a.id,-1)},children:`↑`}),(0,o.jsx)(`button`,{type:`button`,className:`rvs-change-nav-btn`,title:n(`changes.next`),"aria-label":n(`changes.next`),onClick:()=>{_d(a.id,1)},children:`↓`})]}),a.loading&&(0,o.jsxs)(`div`,{className:`rvs-empty`,children:[(0,o.jsx)(Tc,{}),` `,n(`common.loading`)]}),v&&a.error===void 0&&a.loading===!1&&(0,o.jsxs)(`div`,{className:`rvs-banner warn`,children:[n(`connection.editorReadOnly`),a.kind===`file`&&a.dirty&&` ${n(`connection.editorDirty`)}`]}),!a.loading&&a.error!==void 0&&(0,o.jsx)(`div`,{className:`rvs-banner error`,children:v&&A(a.error)?n(`connection.readFailed`):a.error}),!a.loading&&a.error===void 0&&a.kind===`diff`&&(0,o.jsx)(ez,{tab:a,visible:e.visible,offline:v===!0}),!a.loading&&a.error===void 0&&a.kind===`file`&&(0,o.jsxs)(o.Fragment,{children:[a.image&&(Ze!==void 0||a.truncated)&&(0,o.jsx)(NB,{src:Ze??``,path:a.rel,size:a.remoteSize??0,...a.truncated?{truncated:!0}:{},t:n}),a.image&&Ze===void 0&&!a.truncated&&(0,o.jsx)(`div`,{className:`rvs-editor-notice`,children:(0,o.jsx)(`div`,{children:Qe??n(`common.loading`)})}),!a.image&&Wo(be)&&(0,o.jsx)(lV,{alias:c,path:a.fullPath,sessionId:_?h.sessionId:void 0,kind:be,revision:a.reloadNonce??0,t:n}),!a.image&&!a.binary&&a.preview&&be===`svg`&&(0,o.jsx)(uV,{path:a.rel,text:_e??``,truncated:a.truncated,t:n}),!a.image&&!a.binary&&a.preview&&be===`table`&&(0,o.jsx)(fV,{path:a.rel,text:_e??``,truncated:a.truncated,t:n}),!a.image&&a.binary&&(0,o.jsxs)(`div`,{className:`rvs-editor-notice`,children:[(0,o.jsx)(`div`,{className:`rvs-editor-notice-title`,children:n(`editor.binaryTitle`)}),(0,o.jsx)(`div`,{children:a.rel}),(0,o.jsx)(`div`,{children:n(`editor.binary`)})]}),!a.image&&!a.binary&&a.markdown&&a.preview&&Te,!a.image&&!a.binary&&a.html&&a.preview&&(0,o.jsxs)(`div`,{className:`rvs-preview-frame-wrap`,children:[a.truncated&&(0,o.jsx)(`div`,{className:`rvs-preview-banner`,children:n(`preview.truncated`)}),(0,o.jsx)(`iframe`,{className:`rvs-html-frame`,title:a.rel,sandbox:``,srcDoc:Ce})]}),!a.image&&!a.binary&&!Wo(be)&&(0,o.jsxs)(`div`,{className:`rvs-editor-host${a.preview&&Go(be)?` rvs-hidden`:``}`,children:[a.truncated&&(0,o.jsx)(`div`,{className:`rvs-banner warn`,children:n(`editor.truncated`)}),(0,o.jsx)(tR,{ref:De,initial:a.text,savedText:a.baseline,path:a.fullPath,tabId:a.id,readOnly:a.truncated||v,visible:e.visible,wrap:u.wrap,ctx:t.ctx,sessionId:h.sessionId,remoteRoot:t.repoRoot??t.root,chatEnabled:_,addLabel:n(`files.addToConversation`),...a.line===void 0?{}:{revealLine:a.line},...a.lineNonce===void 0?{}:{revealNonce:a.lineNonce},...a.changeSet===void 0?{}:{changeSet:a.changeSet},blame:k?M:void 0,onOpenBlame:e=>{t.focusCommit(e.hash)},onViewport:fe,...a.revealHunkLine===void 0?{}:{revealHunkLine:a.revealHunkLine},...a.revealHunkNonce===void 0?{}:{revealHunkNonce:a.revealHunkNonce},...io(a.id)===void 0?{}:{viewState:io(a.id)},onTokens:E,onCaretChange:O,onViewState:ke,onStepHunk:e=>{_d(a.id,e)},onChangeStale:()=>{vd(a.id)},onUndoChange:e=>{Ed(a.id,e)},undoLabel:e=>RV(n,e.kind),undoTriggerLabel:()=>n(`changes.actions`),...Je===void 0?{}:{blockConfirm:Je},onSave:()=>{je()},onDirty:e=>t.updateTab(a.id,{dirty:e}),onBuffer:(e,n)=>t.updateTab(e,{text:n})},BV(a))]})]})]}),f&&(0,o.jsx)(KV,{t:n,diff:We,caret:D,language:Ye,indent:Ee,wrap:u.wrap,fontSize:u.fontSize,readOnly:a.kind===`file`&&(a.binary||a.truncated||v),dirty:a.dirty,loading:a.loading,saving:a.saving,error:a.error})]})]})}function JV(e){let t=pl(),n=t.t,r=e.mode??`float`;return r===`center`?(0,o.jsxs)(`div`,{className:`rvs-float-placeholder`,children:[(0,o.jsx)(`div`,{className:`rvs-float-placeholder-title`,children:n(`float.centerElsewhere`)}),(0,o.jsx)(`div`,{className:`rvs-float-placeholder-text`,children:n(`float.centerElsewhereHint`)}),(0,o.jsx)(cz,{kind:`primary`,onClick:()=>{t.dockEditorSidebar()},children:n(`editor.dockToSidebar`)})]}):r===`sidebar`?(0,o.jsxs)(`div`,{className:`rvs-float-placeholder`,children:[(0,o.jsx)(`div`,{className:`rvs-float-placeholder-title`,children:n(`float.dockedElsewhere`)}),(0,o.jsx)(`div`,{className:`rvs-float-placeholder-text`,children:n(`float.dockedElsewhereHint`)}),(0,o.jsx)(cz,{kind:`primary`,onClick:()=>{t.openEditorInCenter()},children:n(`float.openHere`)})]}):(0,o.jsxs)(`div`,{className:`rvs-float-placeholder`,children:[(0,o.jsx)(`div`,{className:`rvs-float-placeholder-title`,children:n(`float.placeholder`)}),(0,o.jsx)(`div`,{className:`rvs-float-placeholder-text`,children:n(`float.placeholderHint`)}),(0,o.jsx)(cz,{kind:`primary`,onClick:()=>{t.dockFloatingEditor()},children:n(`float.dockBack`)})]})}function YV(e){if(!Number.isFinite(e)||e<0)return`0 B`;if(e<1024)return`${Math.round(e)} B`;let t=[`KiB`,`MiB`,`GiB`,`TiB`],n=e/1024,r=0;for(;n>=1024&&r<t.length-1;)n/=1024,r+=1;return`${n>=100?Math.round(n):n.toFixed(1)} ${t[r]}`}function XV(e,t){if(e.status===`failed`)return e.error??t(`downloads.failed`);if(e.status===`cancelled`)return t(`downloads.cancelled`);if(e.status===`handedOff`)return t(`downloads.handedOffDetail`);if(e.status===`done`)return e.via===`browserDefault`?t(`downloads.browserDefault`):t(`downloads.done`);let n=YV(e.loaded),r=e.directory||e.selection!==void 0;return e.total===void 0?`${n} · ${t(r?`downloads.indeterminate`:`downloads.sizeUnknown`)}`:`${n} / ${YV(e.total)}`}function ZV(e){if(e.total!==void 0)return e.total===0?100:Math.min(100,Math.round(e.loaded/e.total*100))}let QV=[],$V=new Set,eH=new Map,tH=0,nH,rH=()=>{for(let e of[...$V])e()},iH=()=>{nH!==void 0&&(clearTimeout(nH),nH=void 0),rH()},aH=()=>{nH===void 0&&(nH=setTimeout(()=>{nH=void 0,rH()},100))},oH=(e,t,n=!1)=>{QV=QV.map(n=>n.id===e?{...n,...t}:n),n?aH():iH()},sH={subscribe(e){return $V.add(e),()=>{$V.delete(e)}},getSnapshot(){return QV}},cH=(e,t,n)=>{(async()=>{try{let r=await n({signal:t.signal,onProgress:n=>{t.signal.aborted||oH(e,{loaded:n.loaded,...n.total===void 0?{}:{total:n.total}},!0)}});if(r===`handedOff`){oH(e,{status:`handedOff`,finishedAt:Date.now(),via:`browserDefault`});return}oH(e,{status:`done`,finishedAt:Date.now(),via:r===`saved-browser`?`browserDefault`:`picker`})}catch(n){let r=t.signal.aborted||n instanceof Error&&n.name===`AbortError`;oH(e,{status:r?`cancelled`:`failed`,finishedAt:Date.now(),...r?{}:{error:n instanceof Error?n.message:String(n)}})}finally{eH.delete(e)}})()},lH=e=>{let t=`download-${++tH}`,n=new AbortController;return eH.set(t,n),QV=[...QV,{...e,id:t,status:`running`,loaded:0,startedAt:Date.now()}],iH(),{id:t,controller:n}};function uH(e,t,n){let{id:r,controller:i}=lH({name:n.name,directory:n.directory});return cH(r,i,async n=>{let i=await V.fileOp.stat(e,t);return oH(r,i.isDir?{directory:!0}:{directory:!1,total:i.size}),i.isDir?await KB(e,t,n):await GB(e,t,n)}),r}function dH(e,t){let{id:n,controller:r}=lH({name:`selection-${t.length}`,directory:!0,selection:t.length});return cH(n,r,n=>qB(e,t,n)),n}function fH(e){eH.get(e)?.abort()}function pH(e){eH.get(e)?.abort(),eH.delete(e),QV=QV.filter(t=>t.id!==e),iH()}let mH={running:`downloads.running`,done:`downloads.done`,failed:`downloads.failed`,cancelled:`downloads.cancelled`,handedOff:`downloads.handedOff`};function hH(e){let{task:t,t:n}=e,r=ZV(t);return(0,o.jsxs)(`div`,{className:`rvs-download ${t.status}`,children:[(0,o.jsxs)(`div`,{className:`rvs-download-head`,children:[(0,o.jsx)(`span`,{className:`rvs-download-icon`,children:t.directory?(0,o.jsx)(qs,{path:t.name,open:!1,size:14}):(0,o.jsx)(Ks,{path:t.name,size:14})}),(0,o.jsxs)(`span`,{className:`rvs-download-name`,title:t.name,children:[t.name,t.directory?`.tar.gz`:``]}),(0,o.jsx)(`span`,{className:`rvs-download-status ${t.status}`,children:n(mH[t.status])}),t.status===`running`?(0,o.jsx)(U,{title:n(`downloads.cancel`),onClick:()=>fH(t.id),children:(0,o.jsx)(bs,{size:12})}):(0,o.jsx)(U,{title:n(`downloads.close`),onClick:()=>pH(t.id),children:(0,o.jsx)(ys,{size:12})})]}),t.status===`running`&&(0,o.jsx)(`div`,{className:`rvs-download-bar`,"aria-hidden":`true`,children:(0,o.jsx)(`div`,{className:`rvs-download-fill${r===void 0?` indeterminate`:``}`,style:r===void 0?void 0:{width:`${r}%`}})}),(0,o.jsx)(`div`,{className:`rvs-download-meta ${t.status}`,title:t.error,children:XV(t,n)})]})}function gH(e){let t=(0,i.useSyncExternalStore)(sH.subscribe,sH.getSnapshot,sH.getSnapshot);return typeof document>`u`||t.length===0?null:(0,a.createPortal)((0,o.jsx)(`div`,{className:`rvs-downloads`,role:`status`,"aria-live":`polite`,children:t.map(t=>(0,o.jsx)(hH,{task:t,t:e.t},t.id))}),document.body)}let _H=`dsh-remote-vs.ports.alias`,vH=`dsh-remote-vs.portForwards`,yH=`127.0.0.1`;function bH(e){let t=e.startsWith(`[`)&&e.endsWith(`]`)?e.slice(1,-1):e;return t===``||t===`*`||t===`0.0.0.0`?yH:t===`::`?`::1`:t===`127.0.0.1`?yH:t}function xH(e,t=!1){return typeof e!=`number`||!Number.isInteger(e)||e>65535?!1:e>=+!t}function SH(e){let t=e.trim();if(!/^\d{1,5}$/.test(t))return;let n=Number(t);return xH(n)?n:void 0}function CH(e){return e instanceof pn?e.message:String(e)}function wH(e,t){return e.includes(`:`)?`[${e}]:${t}`:`${e}:${t}`}function TH(){try{return localStorage.getItem(_H)??``}catch{return``}}function EH(){let e;try{let t=localStorage.getItem(vH);if(t===null)return{};e=JSON.parse(t)}catch{return{}}if(typeof e!=`object`||!e||Array.isArray(e))return{};let t={};for(let[n,r]of Object.entries(e)){if(!Array.isArray(r))continue;let e=[];for(let t of r){if(typeof t!=`object`||!t)continue;let{remoteHost:n,remotePort:r,localPort:i}=t;typeof n!=`string`||n===``||!xH(r)||!xH(i,!0)||e.push({remoteHost:n,remotePort:r,localPort:i})}e.length>0&&(t[n]=e)}return t}function DH(e){try{localStorage.setItem(vH,JSON.stringify(e))}catch{}}function OH(e,t){let n=EH(),r=n[e]??[];r.some(e=>e.remoteHost===t.remoteHost&&e.remotePort===t.remotePort&&e.localPort===t.localPort)||(n[e]=[...r,t],DH(n))}function kH(e,t){let n=EH(),r=n[e]??[],i=e=>e.remoteHost===t.remoteHost&&e.remotePort===t.remotePort,a=r.findIndex(e=>i(e)&&e.localPort===t.localPort),o=r.findIndex(e=>i(e)&&e.localPort===0),s=a>=0?a:o;if(s<0)return;let c=r.filter((e,t)=>t!==s);c.length===0?delete n[e]:n[e]=c,DH(n)}function AH(e,t){let n=EH(),r=n[e]??[],i=r.findIndex(e=>e.remoteHost===t.remoteHost&&e.remotePort===t.remotePort&&e.localPort===t.localPort);if(i<0)return;let a=r.filter((e,t)=>t!==i);a.length===0?delete n[e]:n[e]=a,DH(n)}function jH(e,t){let n=[...e??[]];for(let e of t){let t=n.findIndex(t=>t.id===e.id);t>=0?n[t]=e:n.push(e)}return n}function MH(e){let t=e.size??16;return(0,o.jsxs)(`svg`,{width:t,height:t,viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.4`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,o.jsx)(`path`,{d:`M6 1.8v2.4M10 1.8v2.4`}),(0,o.jsx)(`path`,{d:`M4 4.2h8v2a4 4 0 0 1-4 4 4 4 0 0 1-4-4Z`}),(0,o.jsx)(`path`,{d:`M8 10.2v4`})]})}function NH(e){let t=e.size??14;return(0,o.jsxs)(`svg`,{width:t,height:t,viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.4`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,o.jsx)(`path`,{d:`M6.6 3.4H3.4v9.2h9.2V9.4`}),(0,o.jsx)(`path`,{d:`M9.2 2.6h4.2v4.2M13.4 2.6 8 8`})]})}function PH(e){let t=e.t,[n,r]=(0,i.useState)(TH),[a,s]=(0,i.useState)(void 0),[c,l]=(0,i.useState)(void 0),[u,d]=(0,i.useState)(void 0),[f,p]=(0,i.useState)(void 0),[m,h]=(0,i.useState)([]),[g,_]=(0,i.useState)(void 0),[v,y]=(0,i.useState)(()=>new Set),[b,x]=(0,i.useState)(yH),[S,C]=(0,i.useState)(``),[w,T]=(0,i.useState)(``),E=(0,i.useCallback)(e=>{y(t=>{if(t.has(e))return t;let n=new Set(t);return n.add(e),n})},[]),D=(0,i.useCallback)(e=>{y(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n})},[]),O=n!==``&&e.hosts.some(e=>e.alias===n)?n:e.hosts[0]?.alias??``,k=(0,i.useRef)(!0);(0,i.useEffect)(()=>(k.current=!0,()=>{k.current=!1}),[]);let A=(0,i.useRef)(0),j=(0,i.useRef)(0),M=(0,i.useRef)(O);M.current=O,(0,i.useEffect)(()=>{try{localStorage.setItem(_H,O)}catch{}},[O]);let N=(0,i.useCallback)(async e=>{if(e===``)return;let t=++A.current;try{let n=await V.forwards(e);if(!k.current||t!==A.current)return;s(n),l(void 0)}catch(e){if(!k.current||t!==A.current)return;l(CH(e))}},[]),ee=(0,i.useCallback)(async e=>{if(e===``)return;let t=++j.current;try{let n=await V.listenPorts(e);if(!k.current||t!==j.current)return;d(n),p(void 0)}catch(e){if(!k.current||t!==j.current)return;p(CH(e))}},[]);(0,i.useEffect)(()=>{s(void 0),l(void 0),d(void 0),p(void 0),h([]),_(void 0)},[O]),(0,i.useEffect)(()=>{if(!e.visible||O===``)return;N(O);let t=window.setInterval(()=>{document.hidden||N(O)},4e3);return()=>{A.current+=1,window.clearInterval(t)}},[e.visible,O,N]),(0,i.useEffect)(()=>{if(!e.visible||O===``)return;ee(O);let t=window.setInterval(()=>{document.hidden||ee(O)},3e4);return()=>{j.current+=1,window.clearInterval(t)}},[e.visible,O,ee]);let P=(0,i.useCallback)(e=>{A.current+=1,k.current&&e.alias===M.current&&s(t=>jH(t,[e]))},[]),F=(0,i.useRef)(new Set);(0,i.useEffect)(()=>{if(!e.visible||O===``||F.current.has(O))return;F.current.add(O);let t=EH()[O]??[];if(t.length===0)return;let n=O;(async()=>{let e=[];try{if(e=await V.forwards(n),!k.current||M.current!==n)return;s(t=>jH(t,e))}catch{}let r=[];for(let i of t){if(!k.current||M.current!==n)return;if(!e.some(e=>e.remoteHost===i.remoteHost&&e.remotePort===i.remotePort&&(i.localPort===0||e.localPort===i.localPort)))try{let e=await V.startForward({alias:n,remoteHost:i.remoteHost,remotePort:i.remotePort,localPort:i.localPort});P(e)}catch{r.push(i)}}r.length>0&&k.current&&M.current===n&&h(r)})()},[e.visible,O,P]);let I=async()=>{if(O!==``){E(`refresh`);try{await Promise.all([N(O),ee(O)])}finally{k.current&&D(`refresh`)}}},te=async()=>{if(O===``)return;let e=SH(S);if(e===void 0){_(t(`ports.badPort`));return}let n=w.trim(),r=n===``?0:SH(n);if(r===void 0){_(t(`ports.badPort`));return}let i=b.trim()===``?yH:b.trim();E(`form`);try{let t=await V.startForward({alias:O,remoteHost:i,remotePort:e,localPort:r});P(t),OH(O,{remoteHost:i,remotePort:e,localPort:r}),_(void 0),C(``),T(``)}catch(e){k.current&&_(CH(e))}finally{k.current&&D(`form`)}},L=async e=>{if(O===``)return;let t=bH(e.addr),n=`listen:${e.addr}:${e.port}`;E(n);try{let n=await V.startForward({alias:O,remoteHost:t,remotePort:e.port,localPort:0});P(n),OH(O,{remoteHost:t,remotePort:e.port,localPort:0}),_(void 0)}catch(e){k.current&&_(CH(e))}finally{k.current&&D(n)}},R=async e=>{E(e.id);try{await V.stopForward(e.id),A.current+=1,k.current&&s(t=>(t??[]).filter(t=>t.id!==e.id)),kH(e.alias,e),_(void 0)}catch(e){k.current&&_(CH(e))}finally{k.current&&D(e.id)}},ne=e=>e.state===`error`?t(`ports.stateError`):t(`ports.stateListening`);return(0,o.jsxs)(`div`,{className:`rvs-pane grow`,children:[(0,o.jsxs)(`div`,{className:`rvs-header`,children:[(0,o.jsx)(`span`,{className:`rvs-title`,children:t(`tab.ports`)}),(0,o.jsx)(`select`,{className:`rvs-select`,value:O,onChange:e=>r(e.target.value),disabled:e.hosts.length===0,title:t(`ports.selectHost`),style:{flex:1,minWidth:90},children:e.hosts.map(e=>(0,o.jsxs)(`option`,{value:e.alias,style:iz,children:[e.alias,` (`,e.user,`@`,e.host,`)`]},e.alias))}),(0,o.jsx)(U,{title:t(`ports.refresh`),onClick:()=>{I()},disabled:O===``||v.has(`refresh`),children:(0,o.jsx)(hs,{size:14})})]}),e.hosts.length===0&&(0,o.jsx)(`div`,{className:`rvs-banner warn`,children:t(`ports.noHosts`)}),c!==void 0&&(0,o.jsx)(`div`,{className:`rvs-banner error`,children:c}),m.length>0&&(0,o.jsxs)(`div`,{className:`rvs-banner warn rvs-ports-restore`,children:[(0,o.jsx)(`span`,{children:t(`ports.restoreFailed`).replace(`{count}`,String(m.length))}),(0,o.jsx)(`button`,{type:`button`,className:`rvs-chip`,onClick:()=>{for(let e of m)AH(O,e);h([])},children:t(`ports.forgetFailed`)})]}),(0,o.jsxs)(`div`,{className:`rvs-ports-body`,children:[(0,o.jsxs)(`form`,{className:`rvs-ports-form`,onSubmit:e=>{e.preventDefault(),te()},children:[(0,o.jsx)(`div`,{className:`rvs-ports-hint`,children:t(`ports.remoteHostHint`)}),(0,o.jsxs)(`label`,{className:`rvs-ports-field`,children:[(0,o.jsx)(`span`,{className:`rvs-ports-label`,children:t(`ports.remoteHost`)}),(0,o.jsx)(`input`,{className:`rvs-input rvs-ports-input`,value:b,spellCheck:!1,autoComplete:`off`,onChange:e=>x(e.target.value)})]}),(0,o.jsxs)(`label`,{className:`rvs-ports-field`,children:[(0,o.jsx)(`span`,{className:`rvs-ports-label`,children:t(`ports.remotePort`)}),(0,o.jsx)(`input`,{className:`rvs-input rvs-ports-input`,value:S,inputMode:`numeric`,spellCheck:!1,autoComplete:`off`,placeholder:`5432`,onChange:e=>C(e.target.value)})]}),(0,o.jsxs)(`label`,{className:`rvs-ports-field`,children:[(0,o.jsx)(`span`,{className:`rvs-ports-label`,children:t(`ports.localPort`)}),(0,o.jsx)(`input`,{className:`rvs-input rvs-ports-input`,value:w,inputMode:`numeric`,spellCheck:!1,autoComplete:`off`,onChange:e=>T(e.target.value)})]}),(0,o.jsx)(`div`,{className:`rvs-ports-form-actions`,children:(0,o.jsx)(`button`,{type:`submit`,className:`rvs-chip primary`,disabled:O===``||v.has(`form`),children:t(`ports.add`)})})]}),g!==void 0&&(0,o.jsx)(`div`,{className:`rvs-banner error`,children:g}),(0,o.jsxs)(`div`,{className:`rvs-ports-section`,children:[(0,o.jsxs)(`div`,{className:`rvs-ports-sec-head`,children:[t(`ports.active`),a!==void 0&&(0,o.jsx)(`span`,{className:`rvs-ports-count`,children:a.length})]}),O===``?null:a===void 0?c===void 0?(0,o.jsx)(`div`,{className:`rvs-empty`,children:t(`common.loading`)}):null:a.length===0?(0,o.jsx)(`div`,{className:`rvs-empty`,children:t(`ports.emptyForwards`)}):a.map(e=>{let n=ne(e);return(0,o.jsxs)(`div`,{className:`rvs-ports-row`,children:[(0,o.jsxs)(`div`,{className:`rvs-ports-line`,children:[(0,o.jsx)(`span`,{className:`rvs-ports-dot ${e.state}`,role:`img`,"aria-label":n,title:n}),(0,o.jsxs)(`span`,{className:`rvs-ports-addr`,title:`${wH(e.remoteHost,e.remotePort)} → ${e.localUrl}`,children:[wH(e.remoteHost,e.remotePort),` → `,e.localUrl]})]}),e.lastError!==void 0&&(0,o.jsx)(`div`,{className:`rvs-ports-err`,children:e.lastError}),(0,o.jsxs)(`div`,{className:`rvs-ports-actions`,children:[e.transport!==void 0&&e.connections>0&&(0,o.jsx)(`span`,{className:`rvs-ports-transport`,"data-transport":e.transport,title:e.transport===`dedicated`?t(`ports.transportDedicatedHint`):t(`ports.transportSharedHint`),children:e.transport===`dedicated`?t(`ports.transportDedicated`):t(`ports.transportShared`)}),(0,o.jsx)(`span`,{className:`rvs-ports-conn`,children:t(`ports.connections`).replace(`{count}`,String(e.connections))}),(0,o.jsx)(`span`,{style:{flex:1}}),(0,o.jsx)(U,{title:t(`ports.copyUrl`),onClick:()=>{Cc(e.localUrl).then(()=>H(t(`ports.copied`)))},children:(0,o.jsx)(xs,{size:13})}),(0,o.jsx)(`a`,{className:`rvs-hbtn rvs-ports-open`,href:e.localUrl,target:`_blank`,rel:`noopener noreferrer`,title:t(`ports.open`),"aria-label":t(`ports.open`),children:(0,o.jsx)(NH,{size:13})}),(0,o.jsx)(U,{title:t(`ports.stop`),danger:!0,disabled:v.has(e.id),onClick:()=>{R(e)},children:(0,o.jsx)(bs,{size:13})})]})]},e.id)})]}),(0,o.jsxs)(`div`,{className:`rvs-ports-section`,children:[(0,o.jsx)(`div`,{className:`rvs-ports-sec-head`,children:t(`ports.listening`)}),O===``?null:u===void 0?f===void 0?(0,o.jsx)(`div`,{className:`rvs-empty`,children:t(`common.loading`)}):(0,o.jsx)(`div`,{className:`rvs-banner error`,children:f}):(0,o.jsxs)(o.Fragment,{children:[(e=>e.tool===`none`?(0,o.jsxs)(`div`,{className:`rvs-empty`,children:[t(`ports.listenUnavailable`),e.error!==void 0&&(0,o.jsx)(`div`,{className:`rvs-ports-hint`,children:e.error})]}):e.tool===`unknown`?(0,o.jsxs)(`div`,{className:`rvs-empty`,children:[t(`ports.listenUnknown`),e.error!==void 0&&(0,o.jsx)(`div`,{className:`rvs-ports-hint`,children:e.error})]}):e.ports.length===0?(0,o.jsx)(`div`,{className:`rvs-empty`,children:t(`ports.emptyListen`)}):(0,o.jsxs)(o.Fragment,{children:[e.ports.map(e=>{let n=`listen:${e.addr}:${e.port}`;return(0,o.jsxs)(`div`,{className:`rvs-ports-row`,children:[(0,o.jsxs)(`div`,{className:`rvs-ports-line`,children:[(0,o.jsx)(`span`,{className:`rvs-ports-addr`,children:wH(e.addr,e.port)}),e.process!==void 0&&(0,o.jsx)(`span`,{className:`rvs-ports-proc`,title:e.process,children:e.process})]}),(0,o.jsxs)(`div`,{className:`rvs-ports-actions`,children:[(0,o.jsx)(`span`,{style:{flex:1}}),(0,o.jsx)(`button`,{type:`button`,className:`rvs-chip`,disabled:v.has(n),onClick:()=>{L(e)},children:t(`ports.forward`)})]})]},`${e.addr}:${e.port}`)}),e.error!==void 0&&(0,o.jsx)(`div`,{className:`rvs-ports-hint`,children:e.error})]}))(u),f!==void 0&&(0,o.jsx)(`div`,{className:`rvs-ports-hint`,children:f})]})]})]})]})}function FH(){return{cpu:[],mem:[],netRx:[],netTx:[],temp:[]}}function IH(e,t,n,r=Date.now()){return{alias:e,state:t,reason:n,sampledAt:r,kernel:null,cpuCores:null,cpuModel:null,ip:null,uptimeSeconds:null,load1:null,load5:null,load15:null,cpuPercent:null,memUsedBytes:null,memTotalBytes:null,memPercent:null,diskUsedBytes:null,diskTotalBytes:null,diskPercent:null,temperatureC:null,netRxBps:null,netTxBps:null}}function LH(e,t){if(t===null||!Number.isFinite(t))return e;let n=[...e,t];return n.length>60&&n.splice(0,n.length-60),n}function RH(e,t){let n=LH(e.cpu,t.cpuPercent),r=LH(e.mem,t.memPercent),i=LH(e.netRx,t.netRxBps),a=LH(e.netTx,t.netTxBps),o=LH(e.temp,t.temperatureC);return n===e.cpu&&r===e.mem&&i===e.netRx&&a===e.netTx&&o===e.temp?e:{cpu:n,mem:r,netRx:i,netTx:a,temp:o}}function zH(e){return Math.round(e*100)/100}function BH(e,t=[]){let n=[...e,...t].filter(e=>Number.isFinite(e));if(n.length===0)return;let r=Math.min(...n),i=Math.max(...n);return r===i&&(--r,i+=1),{min:r,max:i}}function VH(e,t,n,r){let i=e.filter(e=>Number.isFinite(e));if(i.length===0||t<=0||n<=0)return``;let a=r===void 0?Math.min(...i):r.min,o=r===void 0?Math.max(...i):r.max;o===a&&(--a,o+=1);let s=i.length===1?0:t/(i.length-1);return`M${i.map((e,r)=>{let c=i.length===1?t:r*s,l=1-(e-a)/(o-a),u=Math.max(0,Math.min(n,l*n));return`${zH(c)},${zH(u)}`}).join(`L`)}`}let HH=[`B`,`KB`,`MB`,`GB`,`TB`];function UH(e){if(!Number.isFinite(e)||e<=0)return`0 B`;let t=e,n=0;for(;t>=1024&&n<HH.length-1;)t/=1024,n+=1;return n===0?`${Math.round(t)} ${HH[n]}`:`${t>=100?Math.round(t):Math.round(t*10)/10} ${HH[n]}`}function WH(e){let t=e,n=0;for(;t>=1024&&n<HH.length-1;)t/=1024,n+=1;return{value:t,unit:HH[n]}}function GH(e,t){if(!Number.isFinite(e)||!Number.isFinite(t)||t<=0)return``;let n=WH(t),r=e/1024**HH.indexOf(n.unit),i=e=>String(e>=100?Math.round(e):Math.round(e*10)/10);return`${i(r)} / ${i(n.value)} ${n.unit}`}function KH(e){return`${Math.round(e)}%`}function qH(e){return`${UH(e)}/s`}function JH(e){let t=Math.floor(e);if(!Number.isFinite(t)||t<=0)return`—`;let n=Math.floor(t/86400),r=Math.floor(t%86400/3600),i=Math.floor(t%3600/60);return n>0?`${n}d ${r}h`:r>0?`${r}h ${i}m`:`${i}m`}function YH(e){return`${Math.round(e*10)/10} °C`}function XH(e){let t=Math.max(0,Math.floor(e/1e3));return t<60?`${t}s`:t<3600?`${Math.floor(t/60)}m`:`${Math.floor(t/3600)}h`}function ZH(e){return e===null||!Number.isFinite(e)||e<75?`ok`:e<90?`warn`:`hot`}function QH(e,t){if(e===null||!Number.isFinite(e)||e<0)return t(`proc.unknown`);let n=Math.floor(e/86400),r=Math.floor(e%86400/3600),i=Math.floor(e%3600/60);return n>0?`${n}d ${r}h`:r>0?`${r}h ${i}m`:i>0?`${i}m`:`${Math.max(1,Math.floor(e))}s`}function $H(e){return`${e.toFixed(1)}%`}function eU(e,t){let n=[...e];if(t===`pid`)n.sort((e,t)=>e.pid-t.pid);else{let e=t===`cpu`?`cpuPercent`:`memPercent`;n.sort((t,n)=>n[e]-t[e]||t.pid-n.pid)}return n}function tU(e){let t=e.t,[n,r]=(0,i.useState)(e.aliases[0]??``),[a,s]=(0,i.useState)(!1),[c,l]=(0,i.useState)(void 0),[u,d]=(0,i.useState)(!1),[f,p]=(0,i.useState)(void 0),[m,h]=(0,i.useState)(``),[g,_]=(0,i.useState)(`cpu`),[v,y]=(0,i.useState)(void 0),[b,x]=(0,i.useState)(void 0),S=(0,i.useRef)(new Set),C=(0,i.useRef)(n);C.current=n;let w=(0,i.useRef)(!0);(0,i.useEffect)(()=>(w.current=!0,()=>{w.current=!1}),[]),(0,i.useEffect)(()=>{e.aliases.includes(n)||(r(e.aliases[0]??``),l(void 0),p(void 0))},[e.aliases,n]);let T=(0,i.useCallback)(async(e=!1,r=!1)=>{let i=n;if(!(i===``||S.current.has(i))){S.current.add(i),r&&d(!0);try{let t=await V.processes(i,e);if(!w.current||i!==C.current)return;l(t),p(t.error)}catch(e){if(!w.current)return;p(e instanceof pn&&e.status===404?t(`proc.hostTooOld`):e instanceof pn?e.message:String(e))}finally{S.current.delete(i),r&&w.current&&i===C.current&&d(!1)}}},[n]);(0,i.useEffect)(()=>{if(!a||!e.visible||e.paused||n===``)return;let t=()=>{document.hidden||T(!1,!1)};t();let r=window.setInterval(t,Math.max(2e3,e.intervalMs||5e3));return()=>window.clearInterval(r)},[a,e.visible,e.paused,n,T,e.intervalMs]),(0,i.useEffect)(()=>{if(!a||!e.visible||e.paused)return;let t=()=>{document.hidden||T(!1,!1)};return document.addEventListener(`visibilitychange`,t),()=>document.removeEventListener(`visibilitychange`,t)},[a,e.visible,e.paused,T]);let E=(0,i.useMemo)(()=>{let e=m.trim().toLowerCase(),t=c?.processes??[];return eU(e===``?t:t.filter(t=>t.command.toLowerCase().includes(e)||t.user.toLowerCase().includes(e)||String(t.pid).includes(e)),g)},[c,m,g]),D=async e=>{if(await hc({title:t(`proc.killTitle`),text:t(`proc.killText`).replace(`{host}`,n).replace(`{pid}`,String(e.pid)).replace(`{command}`,e.command.slice(0,120)),danger:!0,okText:t(`proc.kill`),cancelText:t(`common.cancel`)})){y(e.pid);try{await V.killProcess(n,e.pid,`TERM`),H(t(`proc.killSent`).replace(`{pid}`,String(e.pid))),await T(!0,!1)}catch(t){H(t instanceof pn?t.message:String(t),!0),x(e.pid)}finally{w.current&&y(void 0)}}},O=async e=>{if(await hc({title:t(`proc.killForceTitle`),text:t(`proc.killForceText`).replace(`{host}`,n).replace(`{pid}`,String(e.pid)).replace(`{command}`,e.command.slice(0,120)),danger:!0,okText:t(`proc.killForce`),cancelText:t(`common.cancel`)})){y(e.pid);try{await V.killProcess(n,e.pid,`KILL`),H(t(`proc.killForceSent`).replace(`{pid}`,String(e.pid))),x(void 0),await T(!0,!1)}catch(e){H(e instanceof pn?e.message:String(e),!0)}finally{w.current&&y(void 0)}}},k=e.hosts.find(e=>e.alias===n),A=c!==void 0&&c.tool===`unknown`;return(0,o.jsxs)(`section`,{className:a?`rvs-proc expanded`:`rvs-proc`,"aria-label":t(`proc.title`),children:[(0,o.jsxs)(`div`,{className:`rvs-proc-head`,children:[(0,o.jsx)(`button`,{type:`button`,className:`rvs-proc-toggle`,"aria-expanded":a,onClick:()=>{s(e=>!e)},title:t(a?`proc.collapse`:`proc.expand`),children:(0,o.jsx)(`span`,{"aria-hidden":`true`,children:a?`▾`:`▸`})}),(0,o.jsx)(`span`,{className:`rvs-proc-title`,children:t(`proc.title`)}),e.aliases.length>1&&(0,o.jsx)(`select`,{className:`rvs-select rvs-proc-host`,value:n,onChange:e=>{r(e.target.value),l(void 0),p(void 0)},"aria-label":t(`proc.host`),children:e.aliases.map(e=>(0,o.jsx)(`option`,{value:e,children:e},e))}),e.aliases.length===1&&k!==void 0&&(0,o.jsx)(`span`,{className:`rvs-proc-host-label`,children:k.alias}),a&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(`input`,{className:`rvs-input rvs-proc-filter`,value:m,onChange:e=>{h(e.target.value)},placeholder:t(`proc.filter`),"aria-label":t(`proc.filter`)}),(0,o.jsxs)(`select`,{className:`rvs-select rvs-proc-sort`,value:g,onChange:e=>{_(e.target.value)},"aria-label":t(`proc.sort`),children:[(0,o.jsx)(`option`,{value:`cpu`,children:t(`proc.sortCpu`)}),(0,o.jsx)(`option`,{value:`mem`,children:t(`proc.sortMem`)}),(0,o.jsx)(`option`,{value:`pid`,children:t(`proc.sortPid`)})]}),(0,o.jsx)(U,{title:t(`proc.refresh`),onClick:()=>{T(!0,!0)},disabled:u||n===``,children:u?(0,o.jsx)(Tc,{}):(0,o.jsx)(hs,{size:13})})]})]}),!a&&(0,o.jsx)(`div`,{className:`rvs-proc-collapsed`,children:t(`proc.collapsedHint`)}),a&&f!==void 0&&(0,o.jsx)(`div`,{className:`rvs-banner warn rvs-proc-banner`,children:A?t(`proc.cannotEnumerate`):f}),a&&c?.tool===`none`&&(0,o.jsx)(`div`,{className:`rvs-banner warn rvs-proc-banner`,children:t(`proc.noPs`)}),a&&c?.truncated===!0&&(0,o.jsx)(`div`,{className:`rvs-banner info rvs-proc-banner`,children:t(`proc.truncated`).replace(`{count}`,String(c.processes.length))}),a&&n===``&&(0,o.jsx)(`div`,{className:`rvs-empty`,children:t(`proc.noHost`)}),a&&n!==``&&E.length===0&&!u&&f===void 0&&c!==void 0&&c.tool!==`none`&&c.tool!==`unknown`&&(0,o.jsx)(`div`,{className:`rvs-empty`,children:t(`proc.empty`)}),a&&E.length>0&&(0,o.jsxs)(`div`,{className:`rvs-proc-table rvs-scroll`,role:`table`,"aria-label":t(`proc.title`),"aria-live":`polite`,children:[(0,o.jsxs)(`div`,{className:`rvs-proc-row rvs-proc-row-head`,role:`row`,children:[(0,o.jsx)(`span`,{role:`columnheader`,children:`PID`}),(0,o.jsx)(`span`,{role:`columnheader`,children:`PPID`}),(0,o.jsx)(`span`,{role:`columnheader`,children:`USER`}),(0,o.jsx)(`span`,{role:`columnheader`,title:t(`proc.cpuHint`),children:`CPU`}),(0,o.jsx)(`span`,{role:`columnheader`,children:`MEM`}),(0,o.jsx)(`span`,{role:`columnheader`,children:t(`proc.elapsed`)}),(0,o.jsx)(`span`,{role:`columnheader`,children:t(`proc.command`)}),(0,o.jsx)(`span`,{"aria-hidden":`true`})]}),E.map(e=>(0,o.jsxs)(`div`,{className:`rvs-proc-row`,role:`row`,children:[(0,o.jsx)(`span`,{role:`cell`,className:`rvs-proc-pid`,children:e.pid}),(0,o.jsx)(`span`,{role:`cell`,className:`rvs-proc-pid`,children:e.ppid===0?`—`:e.ppid}),(0,o.jsx)(`span`,{role:`cell`,className:`rvs-proc-user`,title:e.user,children:e.user}),(0,o.jsx)(`span`,{role:`cell`,className:`rvs-proc-num`,children:$H(e.cpuPercent)}),(0,o.jsx)(`span`,{role:`cell`,className:`rvs-proc-num`,children:$H(e.memPercent)}),(0,o.jsx)(`span`,{role:`cell`,className:`rvs-proc-elapsed`,children:QH(e.elapsedSeconds,t)}),(0,o.jsx)(`span`,{role:`cell`,className:`rvs-proc-command`,title:e.command,children:e.command}),(0,o.jsx)(`span`,{role:`cell`,children:(0,o.jsx)(`button`,{type:`button`,className:b===e.pid?`rvs-proc-kill danger`:`rvs-proc-kill`,title:b===e.pid?t(`proc.killForceTitle`):t(`proc.killTitle`),"aria-label":`${b===e.pid?t(`proc.killForceTitle`):t(`proc.killTitle`)} PID ${e.pid}`,disabled:v===e.pid,onClick:()=>{b===e.pid?O(e):D(e)},children:v===e.pid?(0,o.jsx)(Tc,{}):b===e.pid?t(`proc.killForce`):t(`proc.kill`)})})]},e.pid))]})]})}function nU(e){return e.slots.queued+(e.sftpSlots?.queued??0)+(e.netSlots?.queued??0)+(e.gitSlots?.queued??0)}function rU(e){let t=e.connections;return t.shared.channels+t.pty.channels+t.forward.channels+t.sftp.channels+(t.helper?.channels??0)}function iU(e,t=``){return[...e].sort((e,n)=>{let r=Number(n.alias===t)-Number(e.alias===t);if(r!==0)return r;let i=Number(nU(n)>0)-Number(nU(e)>0);return i===0?e.alias<n.alias?-1:+(e.alias>n.alias):i})}function aU(e){let t=e.t;return(0,o.jsxs)(`div`,{className:`rvs-pool-lane`,children:[(0,o.jsx)(`span`,{className:`rvs-pool-lane-name`,children:e.label}),(0,o.jsxs)(`span`,{className:e.lane.open?`rvs-pool-lane-state open`:`rvs-pool-lane-state`,children:[e.lane.open?t(`pool.laneOpen`):t(`pool.laneClosed`),` · `,t(`pool.channels`).replace(`{channels}`,String(e.lane.channels)),e.inFlight!==void 0&&(0,o.jsxs)(o.Fragment,{children:[` · `,e.inFlight]})]}),e.egress!==void 0&&(0,o.jsx)(`span`,{className:`rvs-pool-egress`,title:e.egress,children:e.egress}),e.fallback!==void 0&&(0,o.jsx)(`span`,{className:`rvs-pool-fallback`,title:e.fallback,children:e.fallback})]})}function oU(e){let t=e.t,n=e.host,r=nU(n),i=n.egress===void 0?void 0:O({egress:n.egress},t),a=n.sftpFallback===!0?t(`pool.sftpFallback`):void 0,s=n.connections.helper,c=s===void 0||s.held<=0?void 0:t(`pool.helperInFlight`).replace(`{count}`,String(s.held));return(0,o.jsxs)(`div`,{className:`rvs-pool-host`,role:`group`,"aria-label":n.alias,children:[(0,o.jsxs)(`div`,{className:`rvs-pool-host-head`,children:[(0,o.jsx)(`span`,{className:`rvs-pool-host-alias`,title:n.alias,children:n.alias}),r>0&&(0,o.jsx)(`span`,{className:`rvs-pool-queue`,children:t(`pool.queued`).replace(`{queued}`,String(r))})]}),(0,o.jsx)(aU,{t,label:t(`pool.shared`),lane:n.connections.shared,egress:i}),(0,o.jsx)(aU,{t,label:t(`pool.pty`),lane:n.connections.pty}),(0,o.jsx)(aU,{t,label:t(`pool.forward`),lane:n.connections.forward}),(0,o.jsx)(aU,{t,label:t(`pool.sftp`),lane:n.connections.sftp,fallback:a}),s!==void 0&&(0,o.jsx)(aU,{t,label:t(`pool.helper`),lane:s,inFlight:c}),(0,o.jsx)(`div`,{className:`rvs-pool-slots`,children:t(`pool.slots`).replace(`{active}`,String(n.slots.active)).replace(`{limit}`,String(n.slots.limit)).replace(`{queued}`,String(n.slots.queued))}),n.sftpSlots!==void 0&&(0,o.jsx)(`div`,{className:`rvs-pool-slots`,children:t(`pool.sftpSlots`).replace(`{active}`,String(n.sftpSlots.active)).replace(`{limit}`,String(n.sftpSlots.limit)).replace(`{queued}`,String(n.sftpSlots.queued))}),n.netSlots!==void 0&&(0,o.jsx)(`div`,{className:`rvs-pool-slots`,children:t(`pool.netSlots`).replace(`{active}`,String(n.netSlots.active)).replace(`{limit}`,String(n.netSlots.limit)).replace(`{queued}`,String(n.netSlots.queued))}),n.gitSlots!==void 0&&(0,o.jsx)(`div`,{className:`rvs-pool-slots`,children:t(`pool.gitSlots`).replace(`{active}`,String(n.gitSlots.active)).replace(`{limit}`,String(n.gitSlots.limit)).replace(`{queued}`,String(n.gitSlots.queued))})]})}function sU(e){let t=e.t,[n,r]=(0,i.useState)(!1),[a,s]=(0,i.useState)(void 0),[c,l]=(0,i.useState)(!1),[u,d]=(0,i.useState)(void 0),f=(0,i.useRef)(!1),p=(0,i.useRef)(!0);(0,i.useEffect)(()=>(p.current=!0,()=>{p.current=!1}),[]);let m=(0,i.useCallback)(async()=>{if(!f.current){f.current=!0;try{let e=await V.getPoolStats();if(!p.current)return;if(e===void 0){l(!0);return}s(e),d(void 0)}catch(e){if(!p.current)return;d(e instanceof pn?e.message:String(e))}finally{f.current=!1}}},[]);(0,i.useEffect)(()=>{if(!n||!e.visible||e.paused||c)return;let t=()=>{document.hidden||m()};t();let r=window.setInterval(t,Math.max(2e3,e.intervalMs||5e3));return()=>window.clearInterval(r)},[n,e.visible,e.paused,c,m,e.intervalMs]),(0,i.useEffect)(()=>{if(!n||!e.visible||e.paused||c)return;let t=()=>{document.hidden||m()};return document.addEventListener(`visibilitychange`,t),()=>document.removeEventListener(`visibilitychange`,t)},[n,e.visible,e.paused,c,m]);let h=e.currentAlias??``,g=(0,i.useMemo)(()=>iU(a?.hosts??[],h),[a,h]),_=(0,i.useMemo)(()=>{if(a!==void 0)return{hosts:g.length,connections:g.reduce((e,t)=>e+rU(t),0),queued:g.reduce((e,t)=>e+nU(t),0)}},[a,g]);if(e.hosts.length===0)return null;let v=n&&!c&&u===void 0&&a===void 0;return(0,o.jsxs)(`section`,{className:n?`rvs-pool expanded`:`rvs-pool`,"aria-label":t(`pool.title`),children:[(0,o.jsxs)(`div`,{className:`rvs-pool-head`,children:[(0,o.jsx)(`button`,{type:`button`,className:`rvs-pool-toggle`,"aria-expanded":n,onClick:()=>{r(e=>!e)},title:t(n?`pool.collapse`:`pool.expand`),children:(0,o.jsx)(`span`,{"aria-hidden":`true`,children:n?`▾`:`▸`})}),(0,o.jsx)(`span`,{className:`rvs-pool-title`,children:t(`pool.title`)}),_!==void 0&&(0,o.jsx)(`span`,{className:`rvs-pool-summary`,"aria-live":`polite`,children:t(`pool.summary`).replace(`{hosts}`,String(_.hosts)).replace(`{connections}`,String(_.connections)).replace(`{queued}`,String(_.queued))})]}),!n&&(0,o.jsx)(`div`,{className:`rvs-pool-collapsed`,children:t(`pool.collapsedHint`)}),n&&c&&(0,o.jsx)(`div`,{className:`rvs-pool-note`,children:t(`pool.unsupported`)}),n&&!c&&u!==void 0&&(0,o.jsx)(`div`,{className:`rvs-pool-note error`,children:u}),v&&(0,o.jsxs)(`div`,{className:`rvs-pool-note`,children:[(0,o.jsx)(Tc,{}),` `,t(`pool.loading`)]}),n&&!c&&a!==void 0&&g.length===0&&(0,o.jsx)(`div`,{className:`rvs-pool-note`,children:t(`pool.empty`)}),n&&g.length>0&&(0,o.jsx)(`div`,{className:`rvs-pool-list rvs-scroll`,children:g.map(e=>(0,o.jsx)(oU,{t,host:e},e.alias))})]})}let cU=`dsh-remote-vs.monitor.scope`,lU=`dsh-remote-vs.monitor.interval`,uU=[5e3,1e4,3e4];function dU(){try{let e=Number(localStorage.getItem(lU));if(uU.includes(e))return e}catch{}return 5e3}function fU(e){try{localStorage.setItem(lU,String(e))}catch{}}function pU(){try{let e=localStorage.getItem(cU);if(e===`current`||e===`all`||e!==null&&e.startsWith(`host:`)&&e.length>5)return e}catch{}return`current`}function mU(e){try{localStorage.setItem(cU,e)}catch{}}function hU(e,t){return t!==``&&e.some(e=>e.alias===t)?t:e[0]?.alias??``}function gU(e,t,n){if(e===`all`)return t.map(e=>e.alias);if(e.startsWith(`host:`)){let n=e.slice(5);if(t.some(e=>e.alias===n))return[n]}let r=hU(t,n);return r===``?[]:[r]}function _U(e){let t=e.size??16;return(0,o.jsxs)(`svg`,{width:t,height:t,viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.4`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,o.jsx)(`rect`,{x:`1.6`,y:`2.6`,width:`12.8`,height:`9`,rx:`1.4`}),(0,o.jsx)(`path`,{d:`M5.2 7.6h1.6l1.1-2.2 1.4 4 1-1.8h1.5`}),(0,o.jsx)(`path`,{d:`M5.6 14.2h4.8`})]})}function vU(e){let t=e.size??14;return(0,o.jsxs)(`svg`,{width:t,height:t,viewBox:`0 0 16 16`,fill:`currentColor`,"aria-hidden":`true`,children:[(0,o.jsx)(`rect`,{x:`4.2`,y:`3`,width:`2.4`,height:`10`,rx:`0.8`}),(0,o.jsx)(`rect`,{x:`9.4`,y:`3`,width:`2.4`,height:`10`,rx:`0.8`})]})}function yU(e){let t=e.size??14;return(0,o.jsx)(`svg`,{width:t,height:t,viewBox:`0 0 16 16`,fill:`currentColor`,"aria-hidden":`true`,children:(0,o.jsx)(`path`,{d:`M5 3.2v9.6c0 .5.6.8 1 .5l7-4.6a.6.6 0 0 0 0-1l-7-4.6c-.4-.3-1 0-1 .5Z`})})}function bU(e){let t=e.size??14;return(0,o.jsxs)(`svg`,{width:t,height:t,viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.4`,strokeLinecap:`round`,"aria-hidden":`true`,children:[(0,o.jsx)(`path`,{d:`M2.4 4.6h4.2M9.4 4.6h4.2`}),(0,o.jsx)(`path`,{d:`M2.4 8h2.2M7.4 8h6.2`}),(0,o.jsx)(`path`,{d:`M2.4 11.4h4.2M9.4 11.4h4.2`}),(0,o.jsx)(`circle`,{cx:`8`,cy:`4.6`,r:`1.3`}),(0,o.jsx)(`circle`,{cx:`6`,cy:`8`,r:`1.3`}),(0,o.jsx)(`circle`,{cx:`8`,cy:`11.4`,r:`1.3`})]})}function xU(e){return(0,o.jsxs)(`div`,{className:`rvs-monitor-tile`,children:[(0,o.jsx)(`div`,{className:`rvs-monitor-tile-label`,children:e.label}),(0,o.jsx)(`div`,{className:`rvs-monitor-tile-value`,children:e.value}),e.percent!==null&&(0,o.jsx)(`div`,{className:`rvs-monitor-bar`,"aria-hidden":`true`,children:(0,o.jsx)(`span`,{className:`rvs-monitor-bar-fill ${ZH(e.percent)}`,style:{width:`${Math.max(0,Math.min(100,e.percent))}%`}})}),e.sub!==void 0&&(0,o.jsx)(`div`,{className:`rvs-monitor-tile-sub`,children:e.sub})]})}function SU(e){return(0,o.jsxs)(`div`,{className:`rvs-monitor-fact`,title:e.title,children:[(0,o.jsx)(`div`,{className:`rvs-monitor-fact-label`,children:e.label}),(0,o.jsx)(`div`,{className:`rvs-monitor-fact-value`,children:e.value})]})}function CU(e){let t=`rvs-grad-${(0,i.useId)().replace(/[^A-Za-z0-9_-]/g,``)}`,n=e.valuesAlt??[],r=n.length===0?void 0:BH(e.values,n),a=VH(e.values,100,28,r),s=n.length===0?``:VH(n,100,28,r),c=e.values.length<2;return(0,o.jsxs)(`div`,{className:`rvs-monitor-spark ${e.tone}`,children:[(0,o.jsxs)(`div`,{className:`rvs-monitor-spark-head`,children:[(0,o.jsx)(`span`,{className:`rvs-monitor-spark-label`,children:e.label}),n.length>0&&(0,o.jsxs)(`span`,{className:`rvs-monitor-spark-legend`,"aria-hidden":`true`,children:[(0,o.jsxs)(`span`,{className:`rvs-monitor-spark-key`,children:[(0,o.jsx)(`i`,{className:`rvs-monitor-spark-line rx`}),`↓`]}),(0,o.jsxs)(`span`,{className:`rvs-monitor-spark-key`,children:[(0,o.jsx)(`i`,{className:`rvs-monitor-spark-line tx`}),`↑`]})]})]}),a===``?(0,o.jsx)(`div`,{className:`rvs-monitor-spark-empty`,children:e.empty}):(0,o.jsx)(`svg`,{viewBox:`0 0 100 28`,preserveAspectRatio:`none`,"aria-hidden":`true`,children:c?(0,o.jsx)(`circle`,{cx:`98`,cy:`14`,r:`2`,fill:`currentColor`}):(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(`defs`,{children:(0,o.jsxs)(`linearGradient`,{id:t,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,o.jsx)(`stop`,{offset:`0%`,stopColor:`currentColor`,stopOpacity:`0.22`}),(0,o.jsx)(`stop`,{offset:`100%`,stopColor:`currentColor`,stopOpacity:`0`})]})}),(0,o.jsx)(`path`,{d:`${a}L100,28L0,28Z`,fill:`url(#${t})`}),s!==``&&(0,o.jsx)(`path`,{d:s,fill:`none`,stroke:`currentColor`,strokeWidth:`1.3`,strokeDasharray:`3 3`,opacity:`0.6`,vectorEffect:`non-scaling-stroke`}),(0,o.jsx)(`path`,{d:a,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,vectorEffect:`non-scaling-stroke`})]})})]})}function wU(e,t){return t(e===`ok`?`monitor.stateOk`:e===`error`?`monitor.stateError`:`monitor.stateUnknown`)}function TU(e,t){let n=t.find(t=>t.alias===e);return n===void 0?e:`${n.user}@${n.host}:${n.port}`}function EU(e){let t=e.t,n=pl().workspace?.alias??``,[r,a]=(0,i.useState)(pU),[s,c]=(0,i.useState)(dU),[l,u]=(0,i.useState)(!1),[d,f]=(0,i.useState)({}),[p,m]=(0,i.useState)({}),[h,g]=(0,i.useState)(!1),[_,v]=(0,i.useState)(!1),y=(0,i.useRef)(new Set),b=(0,i.useRef)(!0);(0,i.useEffect)(()=>(b.current=!0,()=>{b.current=!1}),[]);let x=(0,i.useMemo)(()=>gU(r,e.hosts,n),[r,e.hosts,n]),S=x.join(`|`),C=(0,i.useRef)(x);C.current=x;let w=hU(e.hosts,n),T=(0,i.useMemo)(()=>{if(r===`all`)return`all`;if(r.startsWith(`host:`)){let t=r.slice(5);if(e.hosts.some(e=>e.alias===t))return r}return`current`},[r,e.hosts]),E=(0,i.useCallback)(async(e,t)=>{await Promise.all(e.map(async e=>{if(!y.current.has(e)){y.current.add(e);try{let n=await V.hostMetrics(e,t);if(!b.current)return;f(t=>({...t,[e]:n})),m(t=>({...t,[e]:RH(t[e]??FH(),n)}))}catch(t){if(!b.current)return;let n=t instanceof pn?t.message:String(t);f(t=>({...t,[e]:IH(e,`error`,n)}))}finally{y.current.delete(e)}}}))},[]);(0,i.useEffect)(()=>{if(!e.visible||h||C.current.length===0)return;let t=()=>{document.hidden||E(C.current,!1)};t();let n=window.setInterval(t,s),r=()=>{document.hidden||t()};return document.addEventListener(`visibilitychange`,r),()=>{document.removeEventListener(`visibilitychange`,r),window.clearInterval(n)}},[e.visible,h,S,s,E]);let D=(0,i.useCallback)(()=>{let e=C.current;e.length!==0&&(v(!0),E(e,!0).finally(()=>{b.current&&v(!1)}))},[E]),O=(0,i.useCallback)(e=>{let t=e;a(t),mU(t)},[]),k=(0,i.useCallback)(e=>{let t=Number(e);uU.includes(t)&&(c(t),fU(t))},[]),A=t(`monitor.unknown`),j=e=>wU(e,t),M=e=>{let n=Date.now()-e.sampledAt;return n<1500?t(`monitor.justNow`):t(`monitor.updatedAgo`).replace(`{age}`,XH(n))},N=n=>{let r=d[n];if(r===void 0)return(0,o.jsx)(`div`,{className:`rvs-empty`,children:e.visible?(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(Tc,{}),` `,t(`monitor.loading`)]}):t(`monitor.noData`)});let i=r.state,a=j(i),s=p[n]??FH(),c=r.memPercent,l=r.diskPercent,u=r.load1===null||r.load5===null||r.load15===null?A:[r.load1,r.load5,r.load15].map(e=>e.toFixed(2)).join(` / `),f=r.netRxBps===null&&r.netTxBps===null?A:`${r.netRxBps===null?A:qH(r.netRxBps)} ↓ / ${r.netTxBps===null?A:qH(r.netTxBps)} ↑`;return(0,o.jsxs)(`div`,{className:`rvs-monitor-card ${i}`,children:[(0,o.jsxs)(`div`,{className:`rvs-monitor-head`,children:[(0,o.jsx)(`span`,{className:`rvs-monitor-dot ${i}`,"aria-hidden":`true`}),(0,o.jsx)(`span`,{className:`rvs-monitor-title`,title:n,children:n}),(0,o.jsx)(`span`,{className:`rvs-monitor-conn`,title:TU(n,e.hosts),children:TU(n,e.hosts)})]}),(0,o.jsxs)(`div`,{className:`rvs-monitor-sub`,children:[(0,o.jsx)(`span`,{className:`rvs-monitor-state ${i}`,children:a}),(0,o.jsx)(`span`,{className:`rvs-monitor-age`,children:M(r)}),r.reason!==void 0&&(0,o.jsx)(`span`,{className:`rvs-monitor-reason`,title:r.reason,children:t(`monitor.reason`).replace(`{reason}`,r.reason)})]}),i===`ok`?(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(`div`,{className:`rvs-monitor-grid`,children:[(0,o.jsx)(xU,{label:t(`monitor.cpu`),value:r.cpuPercent===null?A:KH(r.cpuPercent),percent:r.cpuPercent,sub:r.cpuCores===null?r.cpuPercent===null?t(`monitor.warming`):void 0:t(`monitor.cores`).replace(`{count}`,String(r.cpuCores))}),(0,o.jsx)(xU,{label:t(`monitor.ram`),value:c===null?A:KH(c),percent:c,sub:r.memUsedBytes===null||r.memTotalBytes===null?void 0:GH(r.memUsedBytes,r.memTotalBytes)}),(0,o.jsx)(xU,{label:t(`monitor.disk`),value:l===null?A:KH(l),percent:l,sub:r.diskUsedBytes===null||r.diskTotalBytes===null?void 0:GH(r.diskUsedBytes,r.diskTotalBytes)})]}),(0,o.jsxs)(`div`,{className:`rvs-monitor-facts`,children:[(0,o.jsx)(SU,{label:t(`monitor.temp`),value:r.temperatureC===null?A:YH(r.temperatureC)}),(0,o.jsx)(SU,{label:t(`monitor.uptime`),value:r.uptimeSeconds===null?A:JH(r.uptimeSeconds)}),(0,o.jsx)(SU,{label:t(`monitor.load`),value:u}),(0,o.jsx)(SU,{label:t(`monitor.net`),value:f,title:r.netRxBps===null&&r.netTxBps===null?t(`monitor.warming`):void 0})]}),(0,o.jsxs)(`div`,{className:`rvs-monitor-sparks`,children:[(0,o.jsx)(CU,{label:t(`monitor.cpuHistory`),values:s.cpu,tone:`cpu`,empty:t(`monitor.warming`)}),(0,o.jsx)(CU,{label:t(`monitor.memHistory`),values:s.mem,tone:`mem`,empty:t(`monitor.warming`)}),(0,o.jsx)(CU,{label:t(`monitor.netHistory`),values:s.netRx,valuesAlt:s.netTx,tone:`net`,empty:t(`monitor.warming`)}),(0,o.jsx)(CU,{label:t(`monitor.tempHistory`),values:s.temp,tone:`temp`,empty:t(`monitor.unknown`)})]}),(0,o.jsx)(`div`,{className:`rvs-monitor-hint`,children:r.kernel===null?t(`monitor.linuxOnly`):`${r.kernel}${r.cpuModel===null?``:` · ${r.cpuModel}`}${r.ip===null?``:` · ${r.ip}`}`})]}):(0,o.jsx)(`div`,{className:`rvs-monitor-hint`,children:r.reason??t(`monitor.noData`)})]})},ee=n=>{let r=n.filter(e=>d[e]?.state===`ok`).length;return(0,o.jsxs)(`div`,{className:`rvs-monitor-list`,children:[(0,o.jsx)(`div`,{className:`rvs-monitor-summary`,children:t(`monitor.allSummary`).replace(`{ok}`,String(r)).replace(`{total}`,String(n.length))}),n.map(n=>{let r=d[n],i=r?.state??`unknown`,a=j(i),s=r?.cpuPercent??null,c=r?.memPercent??null;return(0,o.jsxs)(`button`,{type:`button`,className:`rvs-monitor-row ${i}`,onClick:()=>O(`host:${n}`),title:t(`monitor.inspect`),children:[(0,o.jsxs)(`span`,{className:`rvs-monitor-row-top`,children:[(0,o.jsx)(`span`,{className:`rvs-monitor-dot ${i}`,role:`img`,"aria-label":a}),(0,o.jsx)(`span`,{className:`rvs-monitor-row-name`,children:n}),(0,o.jsx)(`span`,{className:`rvs-monitor-row-host`,children:TU(n,e.hosts)}),r===void 0?(0,o.jsx)(Tc,{}):(0,o.jsx)(`span`,{className:`rvs-monitor-row-cpu`,children:s===null?A:KH(s)})]}),(0,o.jsxs)(`span`,{className:`rvs-monitor-row-bars`,children:[(0,o.jsx)(`span`,{className:`rvs-monitor-row-bar`,title:`${t(`monitor.cpu`)} ${s===null?A:KH(s)}`,children:(0,o.jsx)(`span`,{className:`rvs-monitor-bar-fill ${ZH(s)}`,style:{width:`${s===null?0:Math.max(0,Math.min(100,s))}%`}})}),(0,o.jsx)(`span`,{className:`rvs-monitor-row-bar`,title:`${t(`monitor.ram`)} ${c===null?A:KH(c)}`,children:(0,o.jsx)(`span`,{className:`rvs-monitor-bar-fill ${ZH(c)}`,style:{width:`${c===null?0:Math.max(0,Math.min(100,c))}%`}})})]}),(0,o.jsxs)(`span`,{className:`rvs-monitor-row-facts`,children:[(0,o.jsxs)(`span`,{children:[t(`monitor.ram`),` `,c===null?A:KH(c)]}),(0,o.jsxs)(`span`,{children:[t(`monitor.temp`),` `,r?.temperatureC===null||r?.temperatureC===void 0?A:YH(r.temperatureC)]}),(0,o.jsxs)(`span`,{children:[t(`monitor.uptime`),` `,r?.uptimeSeconds===null||r?.uptimeSeconds===void 0?A:JH(r.uptimeSeconds)]})]})]},n)}),(0,o.jsx)(`div`,{className:`rvs-monitor-hint`,children:t(`monitor.linuxOnly`)})]})},P=x.length===1?x[0]:void 0;return(0,o.jsxs)(`div`,{className:`rvs-pane grow`,children:[(0,o.jsxs)(`div`,{className:`rvs-header rvs-monitor-header`,children:[(0,o.jsx)(`span`,{className:`rvs-title`,children:t(`tab.monitor`)}),(0,o.jsxs)(`select`,{className:`rvs-select`,value:T,onChange:e=>O(e.target.value),disabled:e.hosts.length===0,title:`${t(`monitor.selectScope`)}${w===``?``:` · ${w}`}`,style:{flex:1,minWidth:90},children:[(0,o.jsx)(`option`,{value:`current`,style:iz,children:t(`monitor.scopeCurrent`)}),e.hosts.map(e=>(0,o.jsx)(`option`,{value:`host:${e.alias}`,style:iz,children:e.alias},e.alias)),(0,o.jsx)(`option`,{value:`all`,style:iz,children:t(`monitor.scopeAll`)})]}),(0,o.jsx)(U,{title:t(`monitor.settings`),onClick:()=>u(e=>!e),className:l?`active`:void 0,children:(0,o.jsx)(bU,{})}),(0,o.jsx)(U,{title:t(h?`monitor.resume`:`monitor.pause`),onClick:()=>g(e=>!e),children:h?(0,o.jsx)(yU,{}):(0,o.jsx)(vU,{})}),(0,o.jsx)(U,{title:t(`monitor.refresh`),onClick:D,disabled:x.length===0||_,children:_?(0,o.jsx)(Tc,{}):(0,o.jsx)(hs,{size:14})})]}),l&&(0,o.jsxs)(`div`,{className:`rvs-monitor-settings`,children:[(0,o.jsxs)(`div`,{className:`rvs-monitor-settings-head`,children:[(0,o.jsx)(`span`,{className:`rvs-monitor-settings-label`,children:t(`monitor.interval`)}),(0,o.jsx)(`span`,{className:`rvs-monitor-settings-hint`,children:t(`monitor.intervalHint`)})]}),(0,o.jsx)(wc,{value:String(s),onChange:k,options:[{id:`5000`,label:t(`monitor.interval5`)},{id:`10000`,label:t(`monitor.interval10`)},{id:`30000`,label:t(`monitor.interval30`)}]})]}),(0,o.jsxs)(`div`,{className:`rvs-monitor-body`,children:[(0,o.jsxs)(`div`,{className:`rvs-monitor-content rvs-scroll`,children:[e.hosts.length===0&&(0,o.jsx)(`div`,{className:`rvs-banner warn`,children:t(`monitor.noHosts`)}),e.hosts.length>0&&x.length===0&&(0,o.jsx)(`div`,{className:`rvs-empty`,children:t(`monitor.noHost`)}),h&&(0,o.jsx)(`div`,{className:`rvs-banner info`,children:t(`monitor.paused`)}),P!==void 0&&N(P),P===void 0&&x.length>1&&ee(x)]}),(0,o.jsx)(tU,{t,hosts:e.hosts,aliases:x,visible:e.visible,paused:h,intervalMs:s}),(0,o.jsx)(sU,{t,hosts:e.hosts,visible:e.visible,paused:h,intervalMs:s,currentAlias:w})]})]})}function DU(e){let{dir:t,name:n}=Cz(e.path),r=(0,i.useMemo)(()=>new Set(Sz(e.query,n)),[e.query,n]);return(0,o.jsxs)(`div`,{className:e.active?`rvs-qo-row active`:`rvs-qo-row`,role:`option`,"aria-selected":e.active,id:`rvs-qo-option-${e.index}`,"data-qo-index":e.index,onMouseDown:t=>{t.preventDefault(),e.onPick()},onMouseEnter:e.onHover,children:[t!==``&&(0,o.jsx)(`span`,{className:`rvs-qo-dir`,title:t,children:t}),(0,o.jsx)(`span`,{className:`rvs-qo-name`,children:n.split(``).map((e,t)=>r.has(t)?(0,o.jsx)(`mark`,{className:`rvs-qo-hit`,children:e},t):(0,o.jsx)(`span`,{children:e},t))})]})}function OU(e){let t=pl(),n=t.t,r=t.alias,s=t.root,c=(0,i.useSyncExternalStore)(Vz,Bz),[l,u]=(0,i.useState)(``),[d,f]=(0,i.useState)(0),p=(0,i.useRef)(null),m=(0,i.useRef)(null),h=(0,i.useRef)(null),g=(0,i.useRef)(e.onClose);g.current=e.onClose;let _=(0,i.useRef)(typeof document>`u`?null:document.activeElement);(0,i.useEffect)(()=>(p.current?.focus(),()=>{let e=_.current;e!==null&&document.body.contains(e)&&e.focus()}),[]);let v=e=>{if(e.key!==`Tab`)return;let t=h.current;if(t===null)return;let n=Array.from(t.querySelectorAll(`input:not([disabled]), button:not([disabled]), [tabindex]:not([tabindex="-1"])`));if(n.length===0)return;let r=n[0],i=n[n.length-1],a=document.activeElement;if(!(a!==null&&t.contains(a))){e.preventDefault(),r.focus();return}if(e.shiftKey&&a===r){e.preventDefault(),i.focus();return}!e.shiftKey&&a===i&&(e.preventDefault(),r.focus())};(0,i.useEffect)(()=>{let e=e=>{e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),g.current())};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[]),(0,i.useEffect)(()=>{if(r===``||s===``){Hz(Lz(n(`quickopen.noWorkspace`)));return}let e=kn();if(!Nz(Bz(),r,s,e))return;Hz(Pz(Bz(),r,s));let t={alias:r,root:s};Jz({exec:V.exec,writeSequence:kn},t).then(e=>Hz(Fz(Bz(),e)),e=>Hz(Iz(Bz(),Ez(e),t)))},[r,s,n]);let y=(0,i.useMemo)(()=>{if(r===``||s===``)return[];let e=[];for(let t of Oz(r)){let n=Tz(s,t);n!==void 0&&n!==``&&e.push(n)}return e},[r,s]),b=l.trim()===``,x=b?y:c.index?.paths??[],S=(0,i.useMemo)(()=>bz(l,x,50),[l,x]),C=S.hits.length,w=C===0?-1:Math.min(d,C-1);(0,i.useEffect)(()=>{f(0)},[l,c.phase,c.index]),(0,i.useEffect)(()=>{w<0||(m.current?.querySelector(`[data-qo-index="${w}"]`))?.scrollIntoView?.({block:`nearest`})},[w]);let T=n=>{if(r===``||s===``)return;let i=wz(s,n);kz(r,i),t.openFile(i),e.onClose()};return typeof document>`u`?null:(0,a.createPortal)((0,o.jsx)(`div`,{className:`rvs-portal`,children:(0,o.jsx)(`div`,{className:`rvs-qo-mask`,onMouseDown:t=>{t.target===t.currentTarget&&e.onClose()},children:(0,o.jsxs)(`div`,{className:`rvs-qo`,role:`dialog`,"aria-modal":`true`,"aria-label":n(`quickopen.title`),ref:h,onKeyDown:v,children:[(0,o.jsxs)(`div`,{className:`rvs-qo-bar`,children:[(0,o.jsx)(`input`,{ref:p,className:`rvs-qo-input`,type:`text`,value:l,placeholder:n(`quickopen.placeholder`),spellCheck:!1,autoComplete:`off`,role:`combobox`,"aria-expanded":!0,"aria-controls":`rvs-qo-list`,"aria-activedescendant":w>=0?`rvs-qo-option-${w}`:void 0,onChange:e=>u(e.target.value),onKeyDown:e=>{if(!(e.nativeEvent.isComposing===!0||e.keyCode===229)){if(e.key===`ArrowDown`||e.key===`ArrowUp`){if(e.preventDefault(),C===0)return;f(t=>{let n=Math.min(t,C-1);return e.key===`ArrowDown`?(n+1)%C:n<=0?C-1:n-1});return}if(e.key===`Enter`){e.preventDefault();let t=w>=0?S.hits[w]:void 0;t!==void 0&&T(t)}}}}),(0,o.jsx)(`span`,{className:`rvs-qo-hint`,children:n(`quickopen.hint`)})]}),(0,o.jsx)(`div`,{className:`rvs-qo-list`,id:`rvs-qo-list`,role:`listbox`,ref:m,children:S.hits.map((e,t)=>(0,o.jsx)(DU,{path:e,query:l,active:t===w,index:t,onPick:()=>T(e),onHover:()=>f(t)},e))}),(0,o.jsxs)(`div`,{className:`rvs-qo-foot`,children:[c.phase===`error`?(0,o.jsx)(`span`,{className:`rvs-qo-note error`,role:`status`,children:n(`quickopen.indexError`).replace(`{reason}`,c.error??``)}):c.phase===`loading`?(0,o.jsxs)(`span`,{className:`rvs-qo-note`,role:`status`,children:[(0,o.jsx)(Tc,{}),` `,n(`quickopen.indexing`)]}):b?C===0?(0,o.jsx)(`span`,{className:`rvs-qo-note`,children:n(`quickopen.emptyRecent`)}):(0,o.jsx)(`span`,{className:`rvs-qo-note`,children:n(`quickopen.recent`)}):C===0?(0,o.jsx)(`span`,{className:`rvs-qo-note`,children:n(`quickopen.noResults`)}):S.truncated?(0,o.jsx)(`span`,{className:`rvs-qo-note`,children:n(`quickopen.more`)}):null,c.index?.truncated===!0&&(0,o.jsx)(`span`,{className:`rvs-qo-note warn`,role:`status`,children:n(`quickopen.truncated`).replace(`{count}`,String(c.index.paths.length))}),c.index?.depthCapped!==void 0&&(0,o.jsx)(`span`,{className:`rvs-qo-note warn`,role:`status`,children:n(`quickopen.depthCapped`).replace(`{depth}`,String(c.index.depthCapped)).replace(`{count}`,String(c.index.paths.length))}),c.index?.warning!==void 0&&(0,o.jsx)(`span`,{className:`rvs-qo-note warn`,role:`status`,children:n(`quickopen.warning`).replace(`{detail}`,c.index.warning)})]})]})})}),document.body)}function kU(e){if(typeof e!=`string`||e===``||e.length>4096)throw Error(`invalid path: ${String(e)}`);let t=e.replace(/\\/g,`/`).replace(/\/+$/,``)||`/`;if(/[\0\n\r]/.test(t))throw Error(`path contains control characters`);if(!t.startsWith(`/`))throw Error(`path must be absolute`);if(t.split(`/`).some(e=>e===`..`))throw Error(`path must not contain ..`);return t}function AU(e,t){let n=t.replace(/\\/g,`/`).trim().replace(/^\/+/,``);if(n===``||n.split(`/`).some(e=>e===``||e===`.`||e===`..`))throw Error(`invalid name: ${t}`);return`${kU(e)}/${n}`}function jU(e,t,n){return`cp -r -- ${B(kU(e))} ${n===void 0?`${B(kU(t))}/`:B(AU(t,n))}`}function MU(e,t,n){return`mv -- ${B(kU(e))} ${n===void 0?`${B(kU(t))}/`:B(AU(t,n))}`}function NU(e){if(typeof e!=`string`||e===``)throw Error(`invalid path: empty`);if(e.length>4096)throw Error(`invalid path: too long`);if(!e.startsWith(`/`))throw Error(`invalid path: must be absolute`);if(/[\u0000-\u001f\u007f-\u009f]/.test(e))throw Error(`invalid path: control characters`);let t=e.replace(/\/{2,}/g,`/`).replace(/\/+$/,``)||`/`;if(t===`/`)throw Error(`invalid path: refusing to remove /`);if(t.split(`/`).some(e=>e===`..`||e===`.`))throw Error(`invalid path: must not contain . or ..`);return t}function PU(e){let t=[];for(let n=0;n<e.length;n+=1){let r=B(NU(e[n]));t.push(`echo 'RV_DEL_ITEM ${n}'`),t.push(`if rm -rf -- ${r}; then echo 'RV_DEL_OK ${n}'; else echo 'RV_DEL_FAIL ${n}'; fi`)}return t.push(`exit 0`),t.join(`
7110
+ `).map(e=>e.trim()).find(e=>e.startsWith(`@@RVS_PDF `));if(i===void 0)throw r.stdout.includes(`@@RVS_NO_SOFFICE`)?Object.assign(Error(`LibreOffice is not installed on the remote host. Install the host kit with: npm install @deepseek-ai/libreoffice-kit@latest`),{previewKind:`unavailable`}):Error(r.stderr.trim()||`remote LibreOffice conversion failed`);let a=i.slice(10).trim();try{return await aV(e,`${a}/input.pdf`,n)}finally{V.exec(e,`rm -rf ${B(a)}`,15e3).catch(()=>void 0)}}function sV(e){return!Number.isFinite(e)||e<0?``:e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KiB`:`${(e/(1024*1024)).toFixed(1)} MiB`}function cV(e){return(0,o.jsxs)(`div`,{className:`rvs-preview-notice`,role:`alert`,children:[(0,o.jsx)(`div`,{className:`rvs-preview-notice-title`,children:e.title}),(0,o.jsx)(`div`,{className:`rvs-preview-notice-path`,children:e.path}),(0,o.jsx)(`div`,{className:`rvs-preview-notice-hint`,children:e.hint}),e.detail!==void 0&&(0,o.jsx)(`div`,{className:`rvs-preview-notice-detail`,children:e.detail}),e.onRetry!==void 0&&(0,o.jsx)(`button`,{type:`button`,className:`rvs-preview-retry`,onClick:e.onRetry,children:e.t(`common.retry`)})]})}function lV(e){let[t,n]=(0,i.useState)({status:`loading`}),[r,a]=(0,i.useState)(!1),[s,c]=(0,i.useState)(0);if((0,i.useEffect)(()=>{a(!1)},[e.path,e.kind]),(0,i.useEffect)(()=>{let t=new AbortController,r=!0,i,a=`failed`;n({status:`loading`});let o=e.kind===`office`?()=>oV(e.alias,e.path,t.signal):()=>aV(e.alias,e.path,t.signal);return(e.kind===`office`?eV(e.sessionId??``,e.path,t.signal):$B(e.sessionId??``,e.path,t.signal)).then(e=>e.ok?e.data:(a=e.reason,o())).then(t=>{if(!r)return;let a=e.kind===`media`?qo(e.path)?.mime??`application/octet-stream`:`application/pdf`;i=URL.createObjectURL(new Blob([t],{type:a})),n({status:`ready`,url:i,size:t.byteLength})}).catch(e=>{if(!r)return;let t=typeof e==`object`&&e&&`previewKind`in e?e.previewKind:a;n({status:`failed`,error:{kind:t,message:iV(e)}})}),()=>{r=!1,t.abort(),i!==void 0&&URL.revokeObjectURL(i)}},[e.alias,e.path,e.kind,e.revision,s,e.sessionId]),t.status===`loading`)return(0,o.jsxs)(`div`,{className:`rvs-preview-loading`,role:`status`,children:[(0,o.jsx)(`span`,{className:`rvs-preview-spinner`,"aria-hidden":`true`}),(0,o.jsx)(`span`,{children:e.kind===`office`?e.t(`preview.converting`):e.t(`common.loading`)}),e.kind===`office`&&(0,o.jsx)(`span`,{className:`rvs-preview-loading-hint`,children:e.t(`preview.convertingHint`)})]});if(t.status===`failed`){let n=t.error.kind===`too-large`?e.t(`preview.tooLargeTitle`):t.error.kind===`unavailable`?e.t(e.kind===`office`?`preview.officeUnavailableTitle`:`preview.unavailableTitle`):t.error.kind===`not-found`?e.t(`preview.notFoundTitle`):t.error.kind===`remote`?e.t(`preview.remoteTitle`):e.t(`preview.failedTitle`),r=t.error.kind===`too-large`?e.t(`preview.tooLargeHint`):t.error.kind===`unavailable`?e.t(e.kind===`office`?`preview.officeUnavailableHint`:`preview.unavailableHint`):t.error.kind===`not-found`?e.t(`preview.notFoundHint`):t.error.kind===`remote`?e.t(`preview.remoteHint`):e.t(`preview.failedHint`);return(0,o.jsx)(cV,{path:e.path,title:n,hint:r,detail:t.error.message,t:e.t,onRetry:()=>{c(e=>e+1)}})}if(e.kind===`media`){let n=qo(e.path);return r?(0,o.jsx)(cV,{path:e.path,title:e.t(`preview.failedTitle`),hint:e.t(`preview.mediaUnsupported`),t:e.t,onRetry:()=>{a(!1),c(e=>e+1)}}):(0,o.jsxs)(`div`,{className:`rvs-preview-media${n?.kind===`video`?` rvs-preview-media-video`:``}`,children:[n?.kind===`video`?(0,o.jsx)(`video`,{className:`rvs-preview-media-el`,src:t.url,controls:!0,onError:()=>{a(!0)}}):(0,o.jsx)(`audio`,{className:`rvs-preview-media-el`,src:t.url,controls:!0,onError:()=>{a(!0)}}),(0,o.jsxs)(`div`,{className:`rvs-preview-media-meta`,children:[sV(t.size),(0,o.jsx)(`span`,{className:`rvs-preview-media-hint`,children:e.path})]})]})}return(0,o.jsxs)(`div`,{className:`rvs-preview-document`,children:[(0,o.jsx)(`iframe`,{className:`rvs-preview-document-frame`,src:t.url,title:e.path}),(0,o.jsxs)(`div`,{className:`rvs-preview-document-meta`,children:[sV(t.size),(0,o.jsx)(`span`,{className:`rvs-preview-document-hint`,children:e.t(`preview.documentHint`)})]})]})}function uV(e){let[t,n]=(0,i.useState)(void 0),[r,a]=(0,i.useState)(!1);return(0,i.useEffect)(()=>{let t=URL.createObjectURL(new Blob([e.text],{type:`image/svg+xml`}));return n(t),()=>{URL.revokeObjectURL(t)}},[e.text]),(0,i.useEffect)(()=>{a(!1)},[t]),r?(0,o.jsx)(cV,{path:e.path,title:e.t(`preview.svgFailed`),hint:e.t(`preview.svgFailedHint`),t:e.t}):t===void 0?null:(0,o.jsxs)(`div`,{className:`rvs-preview-svg`,children:[(0,o.jsx)(`img`,{className:`rvs-preview-svg-img`,src:t,alt:e.path,onError:()=>{a(!0)}}),(0,o.jsx)(`div`,{className:`rvs-preview-svg-hint`,children:e.truncated?e.t(`preview.truncated`):e.t(`preview.svgHint`)})]})}function dV(e,t){let n=e.slice(0,t);for(;n.length<t;)n.push(``);return n}function fV(e){let t=(0,i.useMemo)(()=>Xo(e.text,Jo(e.path)),[e.text,e.path]),n=Math.min(t.columns,48),r=t.rows.slice(0,400),a=r[0],s=r.slice(1),c=t.rows.length-r.length,l=t.columns-n,u=[];return e.truncated&&u.push(e.t(`preview.truncated`)),t.truncated&&u.push(e.t(`preview.tableTruncated`).replace(`{rows}`,String(Yo.maxRows)).replace(`{cells}`,String(Yo.maxCells))),c>0&&u.push(e.t(`preview.tableHiddenRows`).replace(`{shown}`,String(r.length)).replace(`{rest}`,String(c))),l>0&&u.push(e.t(`preview.tableHiddenColumns`).replace(`{shown}`,String(n)).replace(`{rest}`,String(l))),t.rows.length===0?(0,o.jsx)(cV,{path:e.path,title:e.t(`preview.tableEmptyTitle`),hint:e.t(`preview.tableEmptyHint`),t:e.t}):(0,o.jsxs)(`div`,{className:`rvs-preview-table-wrap`,children:[u.map((e,t)=>(0,o.jsx)(`div`,{className:`rvs-preview-banner`,children:e},`${String(t)}:${e}`)),(0,o.jsx)(`div`,{className:`rvs-preview-table-scroll`,children:(0,o.jsxs)(`table`,{className:`rvs-preview-table`,children:[(0,o.jsx)(`thead`,{children:(0,o.jsxs)(`tr`,{children:[(0,o.jsx)(`th`,{className:`rvs-preview-rownum`,scope:`col`,children:`#`}),dV(a??[],n).map((e,t)=>(0,o.jsx)(`th`,{scope:`col`,children:e},t))]})}),(0,o.jsx)(`tbody`,{children:s.map((e,t)=>(0,o.jsxs)(`tr`,{children:[(0,o.jsx)(`th`,{className:`rvs-preview-rownum`,scope:`row`,children:t+2}),dV(e,n).map((e,t)=>(0,o.jsx)(`td`,{title:e,children:e},t))]},t))})]})})]})}let pV=`dsh-remote-vs.editor.settings`,mV={wrap:!1,fontSize:13};function hV(e){let t=typeof e==`number`?e:typeof e==`string`&&e.trim()!==``?Number(e):NaN;if(!Number.isFinite(t))return;let n=Math.round(t*2)/2;return Math.min(28,Math.max(9,n))}function gV(e,t){let n=hV(e)??mV.fontSize;return hV(n+t*1)??n}function _V(e){if(typeof e!=`string`||e===``)return mV;let t;try{t=JSON.parse(e)}catch{return mV}if(typeof t!=`object`||!t)return mV;let n=t,r=hV(n.fontSize)??mV.fontSize;return{wrap:typeof n.wrap==`boolean`?n.wrap:mV.wrap,fontSize:r}}function vV(e){return JSON.stringify({wrap:e.wrap,fontSize:e.fontSize})}let yV=new Set,bV;function xV(){try{return _V(localStorage.getItem(pV))}catch{return mV}}function SV(e){try{localStorage.setItem(pV,vV(e))}catch{}}function CV(){for(let e of[...yV])try{e()}catch{}}function wV(){return bV===void 0&&(bV=xV()),bV}function TV(e){return yV.add(e),()=>{yV.delete(e)}}function EV(e){let t=wV(),n=e.fontSize===void 0?t.fontSize:hV(e.fontSize)??t.fontSize,r=e.wrap===void 0?t.wrap:e.wrap;if(n===t.fontSize&&r===t.wrap)return;let i={wrap:r,fontSize:n};bV=i,SV(i),CV()}function DV(e){return e===void 0||e.kind!==`file`||e.image||e.binary||e.loading||e.error!==void 0?!1:!(e.preview&&Go(Uo(e.fullPath)))}let OV=`dsh-remote-vs.editor.blame`,kV=new Map;function AV(){try{return localStorage.getItem(OV)===`1`}catch{return!1}}function jV(e){try{localStorage.setItem(OV,e?`1`:`0`)}catch{}}function MV(e){if(e===``)return 1;let t=1;for(let n=0;n<e.length;n+=1)e.charCodeAt(n)===10&&(t+=1);return t}function NV(e,t,n){return new Promise((r,i)=>{let a=setTimeout(()=>i(Error(`${n} (${Math.round(t/1e3)}s)`)),t);a.unref?.(),e.then(e=>{clearTimeout(a),r(e)},e=>{clearTimeout(a),i(e instanceof Error?e:Error(String(e)))})})}function PV(e,t){if(t.mtime===null)return e(`editor.conflictDeleted`);let n=e(`editor.conflictBody`).replace(`{time}`,new Date(t.mtime).toLocaleString());return t.size===null?n:`${n} · ${t.size} B`}function FV(e,t){return t.error===void 0?t.hunks.length===0?e(`editor.conflictSame`):e(`editor.conflictDiffHead`):t.error}function IV(e){return e.loading?`common.loading`:e.saving?`editor.saving`:e.dirty?`editor.unsaved`:`editor.saved`}function LV(e){return e.loading||e.saving?`saving`:e.dirty?`dirty`:`saved`}function RV(e,t){return e(t===`del`?`changes.undoActionDelete`:`changes.undoAction`)}function zV(e){return e.kind===`diff`?(0,o.jsx)(Rs,{size:11}):e.image?(0,o.jsx)(`span`,{children:`▣`}):(0,o.jsx)(`span`,{children:`▪`})}function BV(e){return`${e.id}:${e.reloadNonce??0}`}function VV(e,t,n){let r={};for(let[n,i]of Object.entries(e))n!==t&&(r[n]=i);r[t]=n;let i=Object.keys(r);for(let e of i.slice(0,Math.max(0,i.length-4)))delete r[e];return r}function HV(e,t){let n=Object.keys(e).filter(n=>n!==t&&e[n].length>2097152);if(n.length===0)return e;let r={...e};for(let e of n)delete r[e];return r}function UV(e){return`${e.fullPath}@${e.reloadNonce??0}`}function WV(){return(0,i.useSyncExternalStore)(TV,wV,wV)}function GV(e){let t=`rvs-status-item${e.error===!0?` rvs-status-error`:``}`;return e.onClick===void 0?(0,o.jsx)(`span`,{className:t,title:e.title,children:e.children}):(0,o.jsx)(`button`,{type:`button`,className:`${t} rvs-status-btn`,title:e.title,onClick:e.onClick,children:e.children})}function KV(e){let t=e.caret,n=e.t,r=e.loading?n(`common.loading`):e.saving?n(`editor.statusSaving`):e.dirty?n(`editor.unsaved`):n(`editor.statusClean`);return(0,o.jsxs)(`div`,{className:`rvs-statusbar`,children:[(0,o.jsx)(`div`,{className:`rvs-status-left`,children:e.diff?(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(GV,{title:n(`editor.diffTitle`),children:n(`editor.diffTitle`)}),(0,o.jsx)(GV,{title:n(`editor.diffReadOnlyTitle`),children:n(`editor.statusReadOnly`)})]}):(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(GV,{title:n(`editor.statusLanguage`),children:e.language}),(0,o.jsx)(GV,{title:n(`editor.statusPosition`),children:n(`editor.statusPositionValue`).replace(`{line}`,String(t?.line??1)).replace(`{column}`,String(t?.column??1))}),t!==void 0&&t.selected>0&&(0,o.jsx)(GV,{title:n(`editor.statusSelected`),children:n(`editor.statusSelectedValue`).replace(`{count}`,String(t.selected))}),e.indent!==void 0&&(0,o.jsx)(GV,{title:n(`editor.statusIndent`),children:e.indent})]})}),(0,o.jsxs)(`div`,{className:`rvs-status-right`,children:[e.error!==void 0&&(0,o.jsx)(GV,{title:e.error,error:!0,children:n(`editor.statusError`)}),e.diff?null:(0,o.jsxs)(o.Fragment,{children:[e.readOnly&&(0,o.jsx)(GV,{title:n(`editor.statusReadOnlyTitle`),children:n(`editor.statusReadOnly`)}),(0,o.jsx)(GV,{title:n(`editor.statusWrapToggle`),onClick:()=>EV({wrap:!e.wrap}),children:e.wrap?n(`editor.statusWrapOn`):n(`editor.statusWrapOff`)}),(0,o.jsx)(GV,{title:n(`editor.statusFont`),children:`${e.fontSize}px`}),(0,o.jsx)(GV,{title:n(`editor.statusSaved`),children:r})]}),(0,o.jsx)(GV,{title:n(`editor.statusEncoding`),children:`UTF-8`})]})]})}function qV(e){let t=pl(),{t:n,tabs:r,activeTab:a,alias:c}=t,l=a===void 0?``:_l(t.repoRoot,a.fullPath),u=WV(),d=t.editorSurface===`center`?`center`:t.editorSurface===`float`?`float`:`sidebar`,f=d===`center`,p=d===`float`?void 0:{"--rvs-editor-font-size":`${u.fontSize}px`},m=a?.changeSet?.hunks??[],h=sR(t.ctx),g=t.workspace===void 0?void 0:t.aliasPaths[t.workspace.id],_=h.sessionId!==void 0&&h.sessionWorkspacePath!==void 0&&g!==void 0&&hI(h.sessionWorkspacePath,g),v=ce()?.state===`error`,y=(0,i.useRef)(new Map),[b,x]=(0,i.useState)({}),[S,C]=(0,i.useState)({}),[T,E]=(0,i.useState)(void 0);(0,i.useEffect)(()=>{E(void 0)},[a?.id]);let[D,O]=(0,i.useState)(void 0);(0,i.useEffect)(()=>{O(void 0)},[a?.id]);let[k,j]=(0,i.useState)(AV),[M,N]=(0,i.useState)(kV),[ee,P]=(0,i.useState)(void 0),[F,I]=(0,i.useState)(void 0),te=(0,i.useRef)(0),L=(0,i.useRef)(new Set),R=(0,i.useRef)(``),ne=(0,i.useRef)(void 0),[z,re]=(0,i.useState)(!1),[ie,ae]=(0,i.useState)([]),[oe,se]=(0,i.useState)(!1),[le,ue]=(0,i.useState)(void 0);(0,i.useEffect)(()=>{te.current+=1,L.current.clear(),R.current=``,P(void 0),N(kV),I(void 0),re(!1),ae([]),ue(void 0)},[a?.id,a?.dirty,a?.reloadNonce]);let de=(0,i.useCallback)(()=>{j(e=>{let t=!e;return jV(t),t})},[]);(0,i.useEffect)(()=>{let e=a;if(!k||e===void 0||e.kind!==`file`||e.loading||e.dirty||e.binary||e.truncated||e.preview||Wo(Uo(e.fullPath))||c===``||t.repoRoot===void 0||l===``||ee===void 0){N(kV);return}let n=MV(e.text),r=`${e.id}:${e.reloadNonce??0}:${l}:${k?`1`:`0`}`;if(R.current===r)return;let i=di(ee.from,ee.to,n,new Set(M.keys()));if(i===void 0)return;let{from:o,to:s}=i,u=`${e.id}:${e.reloadNonce??0}:${o}:${s}`;if(L.current.has(u))return;L.current.add(u);let d=++te.current,f=new AbortController;return Ii(c,t.repoRoot,l,o,s,{signal:f.signal}).then(e=>{d===te.current&&(N(t=>{let n=new Map(t);for(let t of e)n.set(t.line,t);return n}),I(void 0))}).catch(e=>{L.current.delete(u),!f.signal.aborted&&d===te.current&&(R.current=r,I(e instanceof Error?e.message:String(e)))}),()=>{f.abort()}},[a?.id,a?.dirty,a?.reloadNonce,k,M,ee?.from,ee?.to,c,l,t.repoRoot]);let fe=(0,i.useCallback)((e,t)=>{ne.current!==void 0&&window.clearTimeout(ne.current),ne.current=window.setTimeout(()=>{ne.current=void 0,P(n=>n!==void 0&&n.from===e&&n.to===t?n:{from:e,to:t})},140)},[]);(0,i.useEffect)(()=>()=>{ne.current!==void 0&&window.clearTimeout(ne.current)},[]),(0,i.useEffect)(()=>{let e=a;if(!z||e===void 0||e.kind!==`file`||c===``||t.repoRoot===void 0||l===``){ae([]),ue(void 0),se(!1);return}let n=!1;return se(!0),ue(void 0),Li(c,t.repoRoot,l,100).then(e=>{n||(ae(e),se(!1))}).catch(e=>{n||(ue(e instanceof Error?e.message:String(e)),se(!1))}),()=>{n=!0}},[z,a?.id,a?.dirty,c,l,t.repoRoot]),(0,i.useEffect)(()=>{if(!z)return;let e=e=>{e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),re(!1))};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[z]);let[pe,me]=(0,i.useState)(void 0);(0,i.useEffect)(()=>{let t=a;if(e.visible===!1||t===void 0||!t.image||c===``||t.truncated)return;let r=UV(t);if(b[r]!==void 0||S[r]!==void 0)return;let i=!1;return(async()=>{try{let e=await V.fileOp.read(c,t.fullPath);if(i)return;if(e.base64===void 0){C(e=>VV(e,r,n(`editor.imageFailed`)));return}x(n=>VV(n,r,`data:${ec(t.fullPath)};base64,${e.base64}`))}catch(e){i||C(t=>VV(t,r,e instanceof Error?e.message:String(e)))}})(),()=>{i=!0}},[a,c,b,S,n,e.visible]),(0,i.useEffect)(()=>{x(e=>HV(e,a===void 0?void 0:UV(a)))},[a?.fullPath,a?.reloadNonce]);let he=async e=>{e.dirty&&!await hc({title:n(`editor.closeDirty`),text:e.rel,danger:!0,okText:n(`editor.discardClose`)})||t.closeTab(e.id)},ge=async e=>{e.dirty&&!await hc({title:n(`editor.reloadDirty`),text:e.rel,danger:!0,okText:n(`editor.discardReload`)})||await t.reloadTab(e.id)},_e=a?.text,ve=a?.html===!0,B=a?.markdown===!0,ye=a?.preview===!0,be=a?.kind===`file`?Uo(a.fullPath):`text`,xe=Wo(be),Se=(0,i.useSyncExternalStore)(CI,bI),Ce=(0,i.useMemo)(()=>{if(!ve)return``;let e=Se;return[`<!doctype html><meta charset="utf-8">`,`<meta http-equiv="Content-Security-Policy" content="${[`default-src 'none'`,`style-src 'unsafe-inline'`,`img-src data: blob:`,`font-src data:`,`media-src data: blob:`,`form-action 'none'`,`base-uri 'none'`].join(`; `)}">`,`<style>`,`:root{color-scheme:${e?`dark`:`light`}}`,`html,body{background:${e?`#1e1e1e`:`#ffffff`};color:${e?`#d4d4d4`:`#1f1f1f`}}`,`body{margin:14px;font:14px/1.65 system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;overflow-wrap:break-word}`,`img,video,canvas{max-width:100%;height:auto}`,`table{border-collapse:collapse}`,`td,th{border:1px solid ${e?`rgba(255,255,255,.14)`:`rgba(0,0,0,.12)`};padding:4px 8px}`,`pre{overflow:auto}`,`</style>`,_e??``].join(``)},[ve,_e,Se]),we=(0,i.useMemo)(()=>({code:{copyLabel:n(`preview.copyCode`),copiedLabel:n(`preview.copied`)},footnotes:n(`preview.footnotes`)}),[n]),Te=(0,i.useMemo)(()=>!B||!ye||_e===void 0?null:(0,o.jsxs)(`div`,{className:`rvs-preview-scroll`,children:[a?.truncated===!0&&(0,o.jsx)(`div`,{className:`rvs-preview-banner`,children:n(`preview.truncated`)}),(0,o.jsx)(`div`,{className:`rvs-preview-markdown rvs-markdown`,"data-preview-path":a?.fullPath??``,children:(0,o.jsx)(s.MarkdownText,{text:_e,labels:we,variant:`body`})})]}),[B,ye,_e,we,a?.fullPath,a?.truncated,n]),Ee=(0,i.useMemo)(()=>{if(!(a===void 0||a.kind!==`file`||a.binary))return MI(a.text)},[a]),De=(0,i.useRef)(null),Oe=(0,i.useRef)(null),ke=(0,i.useCallback)((e,t)=>{ro(e,t)},[]);(0,i.useEffect)(()=>{ao(new Set(r.map(e=>e.id)))},[r]);let Ae=a!==void 0&&a.kind===`file`&&!a.image&&!a.binary&&!a.loading&&a.error===void 0;(0,i.useEffect)(()=>{if(!(!Ae||a===void 0))return Za(a.id,()=>De.current)},[Ae,a?.id]),(0,i.useEffect)(()=>{let e=Oe.current;if(e===null)return;let t=e=>{if(!(e.ctrlKey||e.metaKey))return;e.preventDefault();let t=e.deltaY<0?1:-1;EV({fontSize:gV(wV().fontSize,t)})};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[r.length]);let je=async()=>{let e=a;if(e===void 0)return;if(v){H(n(`connection.saveBlocked`),!0);return}let r=De.current?.getContent();if(r===void 0){H(n(`editor.needSource`),!0);return}await t.saveTab(e.id,r)},Me=async e=>{let r=De.current?.getContent()??(e.text===``?void 0:e.text);if(r===void 0){H(n(`editor.needSource`),!0);return}await hc({title:n(`editor.conflictOverwriteTitle`),text:e.rel,danger:!0,okText:n(`editor.conflictOverwrite`)})&&(me(void 0),await t.saveTab(e.id,r,{force:!0}))},Ne=async e=>{let t=De.current?.getContent()??e.text;try{let r=await NV(V.fileOp.read(c,e.fullPath),w(Tn()),n(`editor.readTimeout`));me({tabId:e.id,remoteMtime:r.mtime,hunks:Id(r.text??``,t).hunks})}catch(t){me({tabId:e.id,remoteMtime:null,hunks:[],error:t instanceof Error?t.message:String(t)})}},Pe=(0,i.useRef)(je);Pe.current=je;let Fe=(0,i.useRef)(a);Fe.current=a,(0,i.useEffect)(()=>{if(e.visible)return YD(()=>{if(typeof document<`u`&&document.querySelector(`.rvs-modal-mask`)!==null)return;let e=Fe.current;if(!(e===void 0||e.kind!==`file`||e.image||e.binary||Wo(Uo(e.fullPath))))return()=>{Pe.current()}})},[e.visible]);let[Ie,Le]=(0,i.useState)(void 0);(0,i.useEffect)(()=>{Le(void 0)},[a?.id,a?.reloadNonce]),(0,i.useEffect)(()=>{e.visible||Le(void 0)},[e.visible]);let Re=(0,i.useCallback)(()=>{let e=Fe.current;DV(e)&&Le({tabId:e.id,path:e.fullPath,text:De.current?.getContent()??e.text})},[]),ze=(0,i.useCallback)(()=>{Le(void 0)},[]),Be=(0,i.useCallback)(e=>{Le(void 0),window.setTimeout(()=>{De.current?.revealRange(e.line,e.line)},0)},[]),Ve=(0,i.useRef)(Re);Ve.current=Re;let He=(0,i.useRef)(ze);He.current=ze;let Ue=(0,i.useRef)(!1);if(Ue.current=Ie!==void 0,(0,i.useEffect)(()=>{if(!e.visible)return;let t=e=>{if(e.defaultPrevented)return;let t=(e.ctrlKey||e.metaKey)&&e.shiftKey&&!e.altKey,n=e.altKey&&!e.ctrlKey&&!e.metaKey&&!e.shiftKey;if(!t&&!n||e.key.toLowerCase()!==`o`||e.repeat||e.isComposing===!0)return;if(Ue.current){e.preventDefault(),He.current();return}if(qD())return;let r=document.activeElement;r instanceof HTMLElement&&r.closest(`.xterm`)!==null||r instanceof HTMLElement&&r.closest(`.xterm, textarea, input, [contenteditable="true"]`)!==null&&r.closest(`.rvs-editor-host`)===null||DV(Fe.current)&&(e.preventDefault(),Ve.current())};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e.visible]),r.length===0)return f?(0,o.jsx)(`div`,{className:`rvs-pane grow rvs-edge`,children:(0,o.jsxs)(`div`,{className:`rvs-editor-empty`,children:[(0,o.jsx)(`div`,{className:`rvs-editor-empty-glyph`,"aria-hidden":`true`,children:`✎`}),(0,o.jsx)(`div`,{className:`rvs-editor-empty-title`,children:n(`editor.centerEmptyTitle`)}),(0,o.jsx)(`div`,{className:`rvs-editor-empty-hint`,children:n(`editor.centerEmptyHint`)}),(0,o.jsx)(`div`,{className:`rvs-editor-empty-hint`,style:{opacity:.7},children:n(`editor.emptyShortcuts`)})]})}):(0,o.jsx)(`div`,{className:`rvs-pane grow rvs-edge`,children:(0,o.jsxs)(`div`,{className:`rvs-empty`,children:[(0,o.jsx)(`div`,{className:`rvs-empty-title`,children:n(`editor.dockEmptyTitle`)}),(0,o.jsx)(`div`,{className:`rvs-empty-hint`,children:n(`editor.dockEmptyHint`)})]})});let We=a?.kind===`diff`,Ge=a!==void 0&&a.kind===`diff`&&a.sessionDiff===void 0&&a.ref===void 0&&a.diff!==void 0&&!a.diff.unsupported&&!(a.diff.newText===``&&a.diff.oldText!==``),Ke=a?.fullPath??``,qe=``;a?.kind===`diff`&&(a.sessionDiff===void 0?a.ref===void 0?a.staged&&(qe=n(`scm.stagedReadonly`)):qe=`${n(`scm.commitDiff`)} ${a.ref.slice(0,7)}`:qe=n(`changes.diffTabLabel`));let Je=(()=>{let e=a?.changeSet;if(a===void 0||e==null)return;let t=e.blocks,r=Hr(a.id)?.sessionId;if(t===void 0||r===void 0||r===``)return;let i=()=>{try{return window.localStorage}catch{return}};return{isConfirmed:e=>{let n=cR(t,e),a=i();return n===void 0||a===void 0?!1:_R(a,r,n)},onToggle:e=>{let n=cR(t,e),a=i();n===void 0||a===void 0||gR(a,r,n)},label:()=>n(`changes.confirmBlock`),pressedLabel:()=>n(`changes.confirmedBlock`)}})(),Ye=We?`Diff`:a?.image===!0?`Image`:Ko(be)??HI(VI(a?.rel??``)),Xe=a===void 0?void 0:UV(a),Ze=a!==void 0&&a.image&&Xe!==void 0?b[Xe]:void 0,Qe=a!==void 0&&a.image&&Xe!==void 0?S[Xe]:void 0,$e=D===void 0?void 0:M.get(D.line);return(0,o.jsxs)(`div`,{className:`rvs-pane grow rvs-edge`,style:{...p??{},position:`relative`},children:[(0,o.jsx)(`div`,{className:`rvs-etabs`,role:`tablist`,"aria-label":n(`editor.tabsLabel`),children:r.map((e,i)=>{let a=e.id===t.activeTabId,s=e.kind===`diff`;return(0,o.jsxs)(`div`,{role:`tab`,tabIndex:a?0:-1,"aria-selected":a,ref:t=>{t===null?y.current.delete(e.id):y.current.set(e.id,t)},className:`rvs-etab${a?` active`:``}${s?` rvs-etab-diff`:``}`,title:s?`${e.rel}${n(`editor.diffSuffix`)}`:e.fullPath,onClick:()=>t.activateTab(e.id),onAuxClick:t=>{t.button===1&&(t.preventDefault(),he(e))},onKeyDown:n=>{if(n.nativeEvent.isComposing)return;if(n.key===`Enter`||n.key===` `){n.preventDefault(),t.activateTab(e.id);return}let a=n.key===`ArrowRight`?1:n.key===`ArrowLeft`?-1:void 0;if(a===void 0&&n.key!==`Home`&&n.key!==`End`)return;n.preventDefault();let o=n.key===`Home`?0:n.key===`End`?r.length-1:(i+(a??0)+r.length)%r.length,s=r[o];s!==void 0&&(t.activateTab(s.id),y.current.get(s.id)?.focus())},children:[(0,o.jsx)(`span`,{className:`rvs-etab-glyph`,children:zV(e)}),(0,o.jsxs)(`span`,{className:`rvs-etab-name`,children:[ic(e.rel),s&&(0,o.jsx)(`span`,{style:{opacity:.6},children:n(`editor.diffSuffix`)})]}),e.dirty&&(0,o.jsx)(`span`,{className:`rvs-etab-dot`,title:n(`editor.unsaved`)}),(0,o.jsx)(`button`,{type:`button`,className:`rvs-etab-close`,title:n(`common.close`),"aria-label":n(`common.close`),onClick:t=>{t.stopPropagation(),he(e)},children:(0,o.jsx)(ys,{size:11})})]},e.id)})}),a!==void 0&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(`div`,{className:`rvs-einfo`,children:[f&&a.kind===`file`?(0,o.jsx)(AB,{t:n,alias:c,root:t.root,rootName:t.workspace?.name??``,path:Ke,onOpen:e=>{t.openFile(e)}}):(0,o.jsx)(`span`,{className:`rvs-einfo-path`,title:Ke,children:Ke}),(0,o.jsxs)(`span`,{className:`rvs-einfo-actions`,children:[a.kind===`file`&&Go(be)&&(0,o.jsx)(wc,{value:a.preview?`preview`:`source`,onChange:e=>t.updateTab(a.id,{preview:e===`preview`}),options:[{id:`preview`,label:n(`editor.preview`)},{id:`source`,label:n(`editor.source`)}]}),a.kind===`diff`&&(0,o.jsx)(`span`,{style:{color:`var(--rvs-fg3)`},children:qe}),(0,o.jsx)(`span`,{style:{color:`var(--rvs-fg3)`},children:Ye}),(0,o.jsx)(jd,{compact:!0}),(0,o.jsx)(`span`,{className:`rvs-build`,title:`dsh-remote-vs build 1201-1443`,children:`1201-1443`}),T!==void 0&&!xe&&(0,o.jsxs)(`span`,{className:`rvs-build`,title:n(`editor.tokenCount`),children:[`tok `,T]}),a.kind===`file`&&(0,o.jsxs)(o.Fragment,{children:[!xe&&!a.image&&(0,o.jsx)(`span`,{className:`rvs-status ${LV(a)}`,children:n(IV(a))}),(0,o.jsx)(U,{title:n(`editor.reloadFile`),onClick:()=>{ge(a)},disabled:v||a.loading,children:(0,o.jsx)(hs,{size:13})}),!xe&&!a.image&&(0,o.jsx)(U,{title:`${n(`editor.save`)} (Ctrl+S)`,onClick:()=>{je()},disabled:v||a.loading||a.binary||a.truncated||!a.dirty,children:(0,o.jsx)(Vs,{size:13})}),!a.image&&!a.binary&&!Wo(be)&&(0,o.jsx)(U,{title:`${n(`editor.outline`)} (Ctrl+Shift+O)`,onClick:Re,disabled:!DV(a),children:(0,o.jsx)(`span`,{className:`rvs-glyph-text`,children:`≡`})})]}),a.kind===`diff`&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(U,{title:n(`scm.reloadDiff`),onClick:()=>{ge(a)},disabled:v,children:(0,o.jsx)(hs,{size:13})}),Ge&&(0,o.jsx)(U,{title:n(`editor.switchToEdit`),onClick:()=>{t.openFile(a.fullPath)},children:(0,o.jsx)(Fs,{size:13})})]}),a.kind===`file`&&!a.image&&!a.binary&&!xe&&(0,o.jsx)(U,{title:n(`editor.wrap`),onClick:()=>EV({wrap:!u.wrap}),children:(0,o.jsx)(us,{size:13})}),a.kind===`file`&&!a.image&&!a.binary&&!Wo(be)&&l!==``&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(U,{title:F===void 0?n(`editor.blameToggle`):`${n(`editor.blameToggle`)}: ${F}`,className:k?`rvs-hbtn-on`:void 0,onClick:de,children:(0,o.jsx)(`span`,{className:`rvs-glyph-text`,children:`B`})}),(0,o.jsx)(U,{title:n(`editor.fileHistory`),className:z?`rvs-hbtn-on`:void 0,onClick:()=>{re(e=>!e)},children:(0,o.jsx)(Rs,{size:13})}),k&&$e!==void 0&&ui($e.hash)&&(0,o.jsx)(U,{title:n(`editor.blameOpenCaret`),onClick:()=>{t.focusCommit($e.hash)},children:(0,o.jsx)(`span`,{className:`rvs-glyph-text`,children:`↗`})})]}),(0,o.jsx)(`span`,{className:`rvs-einfo-actions-divider`,"aria-hidden":`true`}),d!==`float`&&!xe&&!a.image&&a.kind!==`diff`&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(U,{title:n(`editor.fontSmaller`),onClick:()=>EV({fontSize:gV(u.fontSize,-1)}),children:(0,o.jsx)(`span`,{className:`rvs-font-glyph`,children:`A−`})}),(0,o.jsx)(U,{title:n(`editor.fontLarger`),onClick:()=>EV({fontSize:gV(u.fontSize,1)}),children:(0,o.jsx)(`span`,{className:`rvs-font-glyph`,children:`A+`})})]}),d!==`float`&&(0,o.jsx)(U,{title:n(`float.title`),onClick:()=>{t.openFloatingEditor()},children:(0,o.jsx)(zs,{size:13})}),d===`center`?(0,o.jsx)(U,{title:n(`editor.dockToSidebar`),onClick:()=>{t.dockEditorSidebar()},children:(0,o.jsx)(ls,{size:13})}):d===`sidebar`?(0,o.jsx)(U,{title:n(`editor.openInCenter`),onClick:()=>{t.openEditorInCenter()},children:(0,o.jsx)(cs,{size:13})}):null]})]}),z&&a.kind===`file`&&(0,o.jsxs)(`div`,{className:`rvs-file-history`,role:`dialog`,"aria-label":n(`editor.fileHistory`),children:[(0,o.jsxs)(`div`,{className:`rvs-file-history-head`,children:[(0,o.jsx)(`span`,{className:`rvs-file-history-title`,children:n(`editor.fileHistory`)}),(0,o.jsx)(`span`,{className:`rvs-file-history-path`,title:l,children:l}),(0,o.jsx)(`button`,{type:`button`,className:`rvs-file-history-close`,title:n(`common.close`),"aria-label":n(`common.close`),onClick:()=>{re(!1)},children:(0,o.jsx)(ys,{size:11})})]}),oe&&(0,o.jsx)(`div`,{className:`rvs-file-history-note`,children:n(`common.loading`)}),!oe&&le!==void 0&&(0,o.jsx)(`div`,{className:`rvs-file-history-note error`,children:le}),!oe&&le===void 0&&ie.length===0&&(0,o.jsx)(`div`,{className:`rvs-file-history-note`,children:n(`editor.fileHistoryEmpty`)}),!oe&&le===void 0&&ie.length>0&&(0,o.jsx)(`div`,{className:`rvs-file-history-list`,children:ie.map(e=>(0,o.jsxs)(`button`,{type:`button`,className:`rvs-file-history-row`,onClick:()=>{re(!1),t.openCommitFile(e.hash,e.path,e.origPath)},children:[(0,o.jsx)(`span`,{className:`rvs-file-history-hash`,children:e.hash.slice(0,7)}),(0,o.jsx)(`span`,{className:`rvs-file-history-subject`,title:e.subject,children:e.subject}),(0,o.jsxs)(`span`,{className:`rvs-file-history-meta`,children:[e.author,` · `,new Date(e.date*1e3).toLocaleDateString()]})]},e.hash))})]}),Ie!==void 0&&Ie.tabId===a.id&&(0,o.jsx)(EB,{t:n,path:Ie.path,text:Ie.text,onPick:Be,onClose:ze}),(0,o.jsxs)(`div`,{className:`rvs-body`,ref:Oe,children:[(a.kind===`file`||a.kind===`diff`)&&a.conflict!==void 0&&(0,o.jsxs)(`div`,{className:`rvs-banner warn rvs-conflict`,role:`alert`,children:[(0,o.jsxs)(`div`,{className:`rvs-conflict-text`,children:[(0,o.jsx)(`strong`,{children:n(`editor.conflictTitle`)}),` `,PV(n,a.conflict)]}),(0,o.jsxs)(`div`,{className:`rvs-conflict-actions`,children:[(0,o.jsx)(cz,{onClick:()=>{Ne(a)},children:n(`editor.conflictDiff`)}),(0,o.jsx)(cz,{onClick:()=>{ge(a)},disabled:v,children:n(`editor.conflictReload`)}),(0,o.jsx)(cz,{kind:`danger`,onClick:()=>{Me(a)},disabled:v,children:n(`editor.conflictOverwrite`)}),(0,o.jsx)(cz,{onClick:()=>{t.dismissConflict(a.id),me(void 0)},children:n(`common.close`)})]})]}),pe!==void 0&&a.conflict!==void 0&&pe.tabId===a.id&&(0,o.jsxs)(`div`,{className:`rvs-conflict-diff`,role:`region`,"aria-label":n(`editor.conflictDiff`),children:[(0,o.jsxs)(`div`,{className:`rvs-conflict-diff-head`,children:[FV(n,pe),pe.remoteMtime!==null&&` · ${new Date(pe.remoteMtime).toLocaleString()}`]}),pe.hunks.slice(0,20).map((e,t)=>(0,o.jsxs)(`div`,{className:`rvs-conflict-hunk`,children:[(0,o.jsx)(`div`,{className:`rvs-conflict-hunk-head`,children:`@@ -${e.oldStart},${e.oldLines} +${e.newStart},${e.newLines} @@`}),e.lines.map((e,t)=>(0,o.jsx)(`div`,{className:`rvs-conflict-row${e.startsWith(`+`)?` add`:``}${e.startsWith(`-`)?` del`:``}`,children:e},`line-${t}`))]},`hunk-${t}`)),pe.hunks.length>20&&(0,o.jsx)(`div`,{className:`rvs-conflict-more`,children:n(`editor.conflictMoreHunks`).replace(`{count}`,String(pe.hunks.length-20))})]}),a.kind===`file`&&m.length>0&&a.changeStale!==!0&&(0,o.jsxs)(`div`,{className:`rvs-change-nav`,role:`group`,"aria-label":n(`changes.navLabel`),children:[(0,o.jsxs)(`span`,{className:`rvs-change-nav-count`,title:n(`changes.navLabel`),children:[Math.min((a.activeHunk??0)+1,m.length),`/`,m.length]}),(0,o.jsx)(`button`,{type:`button`,className:`rvs-change-nav-btn`,title:n(`changes.prev`),"aria-label":n(`changes.prev`),onClick:()=>{_d(a.id,-1)},children:`↑`}),(0,o.jsx)(`button`,{type:`button`,className:`rvs-change-nav-btn`,title:n(`changes.next`),"aria-label":n(`changes.next`),onClick:()=>{_d(a.id,1)},children:`↓`})]}),a.loading&&(0,o.jsxs)(`div`,{className:`rvs-empty`,children:[(0,o.jsx)(Tc,{}),` `,n(`common.loading`)]}),v&&a.error===void 0&&a.loading===!1&&(0,o.jsxs)(`div`,{className:`rvs-banner warn`,children:[n(`connection.editorReadOnly`),a.kind===`file`&&a.dirty&&` ${n(`connection.editorDirty`)}`]}),!a.loading&&a.error!==void 0&&(0,o.jsx)(`div`,{className:`rvs-banner error`,children:v&&A(a.error)?n(`connection.readFailed`):a.error}),!a.loading&&a.error===void 0&&a.kind===`diff`&&(0,o.jsx)(ez,{tab:a,visible:e.visible,offline:v===!0}),!a.loading&&a.error===void 0&&a.kind===`file`&&(0,o.jsxs)(o.Fragment,{children:[a.image&&(Ze!==void 0||a.truncated)&&(0,o.jsx)(NB,{src:Ze??``,path:a.rel,size:a.remoteSize??0,...a.truncated?{truncated:!0}:{},t:n}),a.image&&Ze===void 0&&!a.truncated&&(0,o.jsx)(`div`,{className:`rvs-editor-notice`,children:(0,o.jsx)(`div`,{children:Qe??n(`common.loading`)})}),!a.image&&Wo(be)&&(0,o.jsx)(lV,{alias:c,path:a.fullPath,sessionId:_?h.sessionId:void 0,kind:be,revision:a.reloadNonce??0,t:n}),!a.image&&!a.binary&&a.preview&&be===`svg`&&(0,o.jsx)(uV,{path:a.rel,text:_e??``,truncated:a.truncated,t:n}),!a.image&&!a.binary&&a.preview&&be===`table`&&(0,o.jsx)(fV,{path:a.rel,text:_e??``,truncated:a.truncated,t:n}),!a.image&&a.binary&&(0,o.jsxs)(`div`,{className:`rvs-editor-notice`,children:[(0,o.jsx)(`div`,{className:`rvs-editor-notice-title`,children:n(`editor.binaryTitle`)}),(0,o.jsx)(`div`,{children:a.rel}),(0,o.jsx)(`div`,{children:n(`editor.binary`)})]}),!a.image&&!a.binary&&a.markdown&&a.preview&&Te,!a.image&&!a.binary&&a.html&&a.preview&&(0,o.jsxs)(`div`,{className:`rvs-preview-frame-wrap`,children:[a.truncated&&(0,o.jsx)(`div`,{className:`rvs-preview-banner`,children:n(`preview.truncated`)}),(0,o.jsx)(`iframe`,{className:`rvs-html-frame`,title:a.rel,sandbox:``,srcDoc:Ce})]}),!a.image&&!a.binary&&!Wo(be)&&(0,o.jsxs)(`div`,{className:`rvs-editor-host${a.preview&&Go(be)?` rvs-hidden`:``}`,children:[a.truncated&&(0,o.jsx)(`div`,{className:`rvs-banner warn`,children:n(`editor.truncated`)}),(0,o.jsx)(tR,{ref:De,initial:a.text,savedText:a.baseline,path:a.fullPath,tabId:a.id,readOnly:a.truncated||v,visible:e.visible,wrap:u.wrap,ctx:t.ctx,sessionId:h.sessionId,remoteRoot:t.root,chatEnabled:_,addLabel:n(`files.addToConversation`),...a.line===void 0?{}:{revealLine:a.line},...a.lineNonce===void 0?{}:{revealNonce:a.lineNonce},...a.changeSet===void 0?{}:{changeSet:a.changeSet},blame:k?M:void 0,onOpenBlame:e=>{t.focusCommit(e.hash)},onViewport:fe,...a.revealHunkLine===void 0?{}:{revealHunkLine:a.revealHunkLine},...a.revealHunkNonce===void 0?{}:{revealHunkNonce:a.revealHunkNonce},...io(a.id)===void 0?{}:{viewState:io(a.id)},onTokens:E,onCaretChange:O,onViewState:ke,onStepHunk:e=>{_d(a.id,e)},onChangeStale:()=>{vd(a.id)},onUndoChange:e=>{Ed(a.id,e)},undoLabel:e=>RV(n,e.kind),undoTriggerLabel:()=>n(`changes.actions`),...Je===void 0?{}:{blockConfirm:Je},onSave:()=>{je()},onDirty:e=>t.updateTab(a.id,{dirty:e}),onBuffer:(e,n)=>t.updateTab(e,{text:n})},BV(a))]})]})]}),f&&(0,o.jsx)(KV,{t:n,diff:We,caret:D,language:Ye,indent:Ee,wrap:u.wrap,fontSize:u.fontSize,readOnly:a.kind===`file`&&(a.binary||a.truncated||v),dirty:a.dirty,loading:a.loading,saving:a.saving,error:a.error})]})]})}function JV(e){let t=pl(),n=t.t,r=e.mode??`float`;return r===`center`?(0,o.jsxs)(`div`,{className:`rvs-float-placeholder`,children:[(0,o.jsx)(`div`,{className:`rvs-float-placeholder-title`,children:n(`float.centerElsewhere`)}),(0,o.jsx)(`div`,{className:`rvs-float-placeholder-text`,children:n(`float.centerElsewhereHint`)}),(0,o.jsx)(cz,{kind:`primary`,onClick:()=>{t.dockEditorSidebar()},children:n(`editor.dockToSidebar`)})]}):r===`sidebar`?(0,o.jsxs)(`div`,{className:`rvs-float-placeholder`,children:[(0,o.jsx)(`div`,{className:`rvs-float-placeholder-title`,children:n(`float.dockedElsewhere`)}),(0,o.jsx)(`div`,{className:`rvs-float-placeholder-text`,children:n(`float.dockedElsewhereHint`)}),(0,o.jsx)(cz,{kind:`primary`,onClick:()=>{t.openEditorInCenter()},children:n(`float.openHere`)})]}):(0,o.jsxs)(`div`,{className:`rvs-float-placeholder`,children:[(0,o.jsx)(`div`,{className:`rvs-float-placeholder-title`,children:n(`float.placeholder`)}),(0,o.jsx)(`div`,{className:`rvs-float-placeholder-text`,children:n(`float.placeholderHint`)}),(0,o.jsx)(cz,{kind:`primary`,onClick:()=>{t.dockFloatingEditor()},children:n(`float.dockBack`)})]})}function YV(e){if(!Number.isFinite(e)||e<0)return`0 B`;if(e<1024)return`${Math.round(e)} B`;let t=[`KiB`,`MiB`,`GiB`,`TiB`],n=e/1024,r=0;for(;n>=1024&&r<t.length-1;)n/=1024,r+=1;return`${n>=100?Math.round(n):n.toFixed(1)} ${t[r]}`}function XV(e,t){if(e.status===`failed`)return e.error??t(`downloads.failed`);if(e.status===`cancelled`)return t(`downloads.cancelled`);if(e.status===`handedOff`)return t(`downloads.handedOffDetail`);if(e.status===`done`)return e.via===`browserDefault`?t(`downloads.browserDefault`):t(`downloads.done`);let n=YV(e.loaded),r=e.directory||e.selection!==void 0;return e.total===void 0?`${n} · ${t(r?`downloads.indeterminate`:`downloads.sizeUnknown`)}`:`${n} / ${YV(e.total)}`}function ZV(e){if(e.total!==void 0)return e.total===0?100:Math.min(100,Math.round(e.loaded/e.total*100))}let QV=[],$V=new Set,eH=new Map,tH=0,nH,rH=()=>{for(let e of[...$V])e()},iH=()=>{nH!==void 0&&(clearTimeout(nH),nH=void 0),rH()},aH=()=>{nH===void 0&&(nH=setTimeout(()=>{nH=void 0,rH()},100))},oH=(e,t,n=!1)=>{QV=QV.map(n=>n.id===e?{...n,...t}:n),n?aH():iH()},sH={subscribe(e){return $V.add(e),()=>{$V.delete(e)}},getSnapshot(){return QV}},cH=(e,t,n)=>{(async()=>{try{let r=await n({signal:t.signal,onProgress:n=>{t.signal.aborted||oH(e,{loaded:n.loaded,...n.total===void 0?{}:{total:n.total}},!0)}});if(r===`handedOff`){oH(e,{status:`handedOff`,finishedAt:Date.now(),via:`browserDefault`});return}oH(e,{status:`done`,finishedAt:Date.now(),via:r===`saved-browser`?`browserDefault`:`picker`})}catch(n){let r=t.signal.aborted||n instanceof Error&&n.name===`AbortError`;oH(e,{status:r?`cancelled`:`failed`,finishedAt:Date.now(),...r?{}:{error:n instanceof Error?n.message:String(n)}})}finally{eH.delete(e)}})()},lH=e=>{let t=`download-${++tH}`,n=new AbortController;return eH.set(t,n),QV=[...QV,{...e,id:t,status:`running`,loaded:0,startedAt:Date.now()}],iH(),{id:t,controller:n}};function uH(e,t,n){let{id:r,controller:i}=lH({name:n.name,directory:n.directory});return cH(r,i,async n=>{let i=await V.fileOp.stat(e,t);return oH(r,i.isDir?{directory:!0}:{directory:!1,total:i.size}),i.isDir?await KB(e,t,n):await GB(e,t,n)}),r}function dH(e,t){let{id:n,controller:r}=lH({name:`selection-${t.length}`,directory:!0,selection:t.length});return cH(n,r,n=>qB(e,t,n)),n}function fH(e){eH.get(e)?.abort()}function pH(e){eH.get(e)?.abort(),eH.delete(e),QV=QV.filter(t=>t.id!==e),iH()}let mH={running:`downloads.running`,done:`downloads.done`,failed:`downloads.failed`,cancelled:`downloads.cancelled`,handedOff:`downloads.handedOff`};function hH(e){let{task:t,t:n}=e,r=ZV(t);return(0,o.jsxs)(`div`,{className:`rvs-download ${t.status}`,children:[(0,o.jsxs)(`div`,{className:`rvs-download-head`,children:[(0,o.jsx)(`span`,{className:`rvs-download-icon`,children:t.directory?(0,o.jsx)(qs,{path:t.name,open:!1,size:14}):(0,o.jsx)(Ks,{path:t.name,size:14})}),(0,o.jsxs)(`span`,{className:`rvs-download-name`,title:t.name,children:[t.name,t.directory?`.tar.gz`:``]}),(0,o.jsx)(`span`,{className:`rvs-download-status ${t.status}`,children:n(mH[t.status])}),t.status===`running`?(0,o.jsx)(U,{title:n(`downloads.cancel`),onClick:()=>fH(t.id),children:(0,o.jsx)(bs,{size:12})}):(0,o.jsx)(U,{title:n(`downloads.close`),onClick:()=>pH(t.id),children:(0,o.jsx)(ys,{size:12})})]}),t.status===`running`&&(0,o.jsx)(`div`,{className:`rvs-download-bar`,"aria-hidden":`true`,children:(0,o.jsx)(`div`,{className:`rvs-download-fill${r===void 0?` indeterminate`:``}`,style:r===void 0?void 0:{width:`${r}%`}})}),(0,o.jsx)(`div`,{className:`rvs-download-meta ${t.status}`,title:t.error,children:XV(t,n)})]})}function gH(e){let t=(0,i.useSyncExternalStore)(sH.subscribe,sH.getSnapshot,sH.getSnapshot);return typeof document>`u`||t.length===0?null:(0,a.createPortal)((0,o.jsx)(`div`,{className:`rvs-downloads`,role:`status`,"aria-live":`polite`,children:t.map(t=>(0,o.jsx)(hH,{task:t,t:e.t},t.id))}),document.body)}let _H=`dsh-remote-vs.ports.alias`,vH=`dsh-remote-vs.portForwards`,yH=`127.0.0.1`;function bH(e){let t=e.startsWith(`[`)&&e.endsWith(`]`)?e.slice(1,-1):e;return t===``||t===`*`||t===`0.0.0.0`?yH:t===`::`?`::1`:t===`127.0.0.1`?yH:t}function xH(e,t=!1){return typeof e!=`number`||!Number.isInteger(e)||e>65535?!1:e>=+!t}function SH(e){let t=e.trim();if(!/^\d{1,5}$/.test(t))return;let n=Number(t);return xH(n)?n:void 0}function CH(e){return e instanceof pn?e.message:String(e)}function wH(e,t){return e.includes(`:`)?`[${e}]:${t}`:`${e}:${t}`}function TH(){try{return localStorage.getItem(_H)??``}catch{return``}}function EH(){let e;try{let t=localStorage.getItem(vH);if(t===null)return{};e=JSON.parse(t)}catch{return{}}if(typeof e!=`object`||!e||Array.isArray(e))return{};let t={};for(let[n,r]of Object.entries(e)){if(!Array.isArray(r))continue;let e=[];for(let t of r){if(typeof t!=`object`||!t)continue;let{remoteHost:n,remotePort:r,localPort:i}=t;typeof n!=`string`||n===``||!xH(r)||!xH(i,!0)||e.push({remoteHost:n,remotePort:r,localPort:i})}e.length>0&&(t[n]=e)}return t}function DH(e){try{localStorage.setItem(vH,JSON.stringify(e))}catch{}}function OH(e,t){let n=EH(),r=n[e]??[];r.some(e=>e.remoteHost===t.remoteHost&&e.remotePort===t.remotePort&&e.localPort===t.localPort)||(n[e]=[...r,t],DH(n))}function kH(e,t){let n=EH(),r=n[e]??[],i=e=>e.remoteHost===t.remoteHost&&e.remotePort===t.remotePort,a=r.findIndex(e=>i(e)&&e.localPort===t.localPort),o=r.findIndex(e=>i(e)&&e.localPort===0),s=a>=0?a:o;if(s<0)return;let c=r.filter((e,t)=>t!==s);c.length===0?delete n[e]:n[e]=c,DH(n)}function AH(e,t){let n=EH(),r=n[e]??[],i=r.findIndex(e=>e.remoteHost===t.remoteHost&&e.remotePort===t.remotePort&&e.localPort===t.localPort);if(i<0)return;let a=r.filter((e,t)=>t!==i);a.length===0?delete n[e]:n[e]=a,DH(n)}function jH(e,t){let n=[...e??[]];for(let e of t){let t=n.findIndex(t=>t.id===e.id);t>=0?n[t]=e:n.push(e)}return n}function MH(e){let t=e.size??16;return(0,o.jsxs)(`svg`,{width:t,height:t,viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.4`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,o.jsx)(`path`,{d:`M6 1.8v2.4M10 1.8v2.4`}),(0,o.jsx)(`path`,{d:`M4 4.2h8v2a4 4 0 0 1-4 4 4 4 0 0 1-4-4Z`}),(0,o.jsx)(`path`,{d:`M8 10.2v4`})]})}function NH(e){let t=e.size??14;return(0,o.jsxs)(`svg`,{width:t,height:t,viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.4`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,o.jsx)(`path`,{d:`M6.6 3.4H3.4v9.2h9.2V9.4`}),(0,o.jsx)(`path`,{d:`M9.2 2.6h4.2v4.2M13.4 2.6 8 8`})]})}function PH(e){let t=e.t,[n,r]=(0,i.useState)(TH),[a,s]=(0,i.useState)(void 0),[c,l]=(0,i.useState)(void 0),[u,d]=(0,i.useState)(void 0),[f,p]=(0,i.useState)(void 0),[m,h]=(0,i.useState)([]),[g,_]=(0,i.useState)(void 0),[v,y]=(0,i.useState)(()=>new Set),[b,x]=(0,i.useState)(yH),[S,C]=(0,i.useState)(``),[w,T]=(0,i.useState)(``),E=(0,i.useCallback)(e=>{y(t=>{if(t.has(e))return t;let n=new Set(t);return n.add(e),n})},[]),D=(0,i.useCallback)(e=>{y(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n})},[]),O=n!==``&&e.hosts.some(e=>e.alias===n)?n:e.hosts[0]?.alias??``,k=(0,i.useRef)(!0);(0,i.useEffect)(()=>(k.current=!0,()=>{k.current=!1}),[]);let A=(0,i.useRef)(0),j=(0,i.useRef)(0),M=(0,i.useRef)(O);M.current=O,(0,i.useEffect)(()=>{try{localStorage.setItem(_H,O)}catch{}},[O]);let N=(0,i.useCallback)(async e=>{if(e===``)return;let t=++A.current;try{let n=await V.forwards(e);if(!k.current||t!==A.current)return;s(n),l(void 0)}catch(e){if(!k.current||t!==A.current)return;l(CH(e))}},[]),ee=(0,i.useCallback)(async e=>{if(e===``)return;let t=++j.current;try{let n=await V.listenPorts(e);if(!k.current||t!==j.current)return;d(n),p(void 0)}catch(e){if(!k.current||t!==j.current)return;p(CH(e))}},[]);(0,i.useEffect)(()=>{s(void 0),l(void 0),d(void 0),p(void 0),h([]),_(void 0)},[O]),(0,i.useEffect)(()=>{if(!e.visible||O===``)return;N(O);let t=window.setInterval(()=>{document.hidden||N(O)},4e3);return()=>{A.current+=1,window.clearInterval(t)}},[e.visible,O,N]),(0,i.useEffect)(()=>{if(!e.visible||O===``)return;ee(O);let t=window.setInterval(()=>{document.hidden||ee(O)},3e4);return()=>{j.current+=1,window.clearInterval(t)}},[e.visible,O,ee]);let P=(0,i.useCallback)(e=>{A.current+=1,k.current&&e.alias===M.current&&s(t=>jH(t,[e]))},[]),F=(0,i.useRef)(new Set);(0,i.useEffect)(()=>{if(!e.visible||O===``||F.current.has(O))return;F.current.add(O);let t=EH()[O]??[];if(t.length===0)return;let n=O;(async()=>{let e=[];try{if(e=await V.forwards(n),!k.current||M.current!==n)return;s(t=>jH(t,e))}catch{}let r=[];for(let i of t){if(!k.current||M.current!==n)return;if(!e.some(e=>e.remoteHost===i.remoteHost&&e.remotePort===i.remotePort&&(i.localPort===0||e.localPort===i.localPort)))try{let e=await V.startForward({alias:n,remoteHost:i.remoteHost,remotePort:i.remotePort,localPort:i.localPort});P(e)}catch{r.push(i)}}r.length>0&&k.current&&M.current===n&&h(r)})()},[e.visible,O,P]);let I=async()=>{if(O!==``){E(`refresh`);try{await Promise.all([N(O),ee(O)])}finally{k.current&&D(`refresh`)}}},te=async()=>{if(O===``)return;let e=SH(S);if(e===void 0){_(t(`ports.badPort`));return}let n=w.trim(),r=n===``?0:SH(n);if(r===void 0){_(t(`ports.badPort`));return}let i=b.trim()===``?yH:b.trim();E(`form`);try{let t=await V.startForward({alias:O,remoteHost:i,remotePort:e,localPort:r});P(t),OH(O,{remoteHost:i,remotePort:e,localPort:r}),_(void 0),C(``),T(``)}catch(e){k.current&&_(CH(e))}finally{k.current&&D(`form`)}},L=async e=>{if(O===``)return;let t=bH(e.addr),n=`listen:${e.addr}:${e.port}`;E(n);try{let n=await V.startForward({alias:O,remoteHost:t,remotePort:e.port,localPort:0});P(n),OH(O,{remoteHost:t,remotePort:e.port,localPort:0}),_(void 0)}catch(e){k.current&&_(CH(e))}finally{k.current&&D(n)}},R=async e=>{E(e.id);try{await V.stopForward(e.id),A.current+=1,k.current&&s(t=>(t??[]).filter(t=>t.id!==e.id)),kH(e.alias,e),_(void 0)}catch(e){k.current&&_(CH(e))}finally{k.current&&D(e.id)}},ne=e=>e.state===`error`?t(`ports.stateError`):t(`ports.stateListening`);return(0,o.jsxs)(`div`,{className:`rvs-pane grow`,children:[(0,o.jsxs)(`div`,{className:`rvs-header`,children:[(0,o.jsx)(`span`,{className:`rvs-title`,children:t(`tab.ports`)}),(0,o.jsx)(`select`,{className:`rvs-select`,value:O,onChange:e=>r(e.target.value),disabled:e.hosts.length===0,title:t(`ports.selectHost`),style:{flex:1,minWidth:90},children:e.hosts.map(e=>(0,o.jsxs)(`option`,{value:e.alias,style:iz,children:[e.alias,` (`,e.user,`@`,e.host,`)`]},e.alias))}),(0,o.jsx)(U,{title:t(`ports.refresh`),onClick:()=>{I()},disabled:O===``||v.has(`refresh`),children:(0,o.jsx)(hs,{size:14})})]}),e.hosts.length===0&&(0,o.jsx)(`div`,{className:`rvs-banner warn`,children:t(`ports.noHosts`)}),c!==void 0&&(0,o.jsx)(`div`,{className:`rvs-banner error`,children:c}),m.length>0&&(0,o.jsxs)(`div`,{className:`rvs-banner warn rvs-ports-restore`,children:[(0,o.jsx)(`span`,{children:t(`ports.restoreFailed`).replace(`{count}`,String(m.length))}),(0,o.jsx)(`button`,{type:`button`,className:`rvs-chip`,onClick:()=>{for(let e of m)AH(O,e);h([])},children:t(`ports.forgetFailed`)})]}),(0,o.jsxs)(`div`,{className:`rvs-ports-body`,children:[(0,o.jsxs)(`form`,{className:`rvs-ports-form`,onSubmit:e=>{e.preventDefault(),te()},children:[(0,o.jsx)(`div`,{className:`rvs-ports-hint`,children:t(`ports.remoteHostHint`)}),(0,o.jsxs)(`label`,{className:`rvs-ports-field`,children:[(0,o.jsx)(`span`,{className:`rvs-ports-label`,children:t(`ports.remoteHost`)}),(0,o.jsx)(`input`,{className:`rvs-input rvs-ports-input`,value:b,spellCheck:!1,autoComplete:`off`,onChange:e=>x(e.target.value)})]}),(0,o.jsxs)(`label`,{className:`rvs-ports-field`,children:[(0,o.jsx)(`span`,{className:`rvs-ports-label`,children:t(`ports.remotePort`)}),(0,o.jsx)(`input`,{className:`rvs-input rvs-ports-input`,value:S,inputMode:`numeric`,spellCheck:!1,autoComplete:`off`,placeholder:`5432`,onChange:e=>C(e.target.value)})]}),(0,o.jsxs)(`label`,{className:`rvs-ports-field`,children:[(0,o.jsx)(`span`,{className:`rvs-ports-label`,children:t(`ports.localPort`)}),(0,o.jsx)(`input`,{className:`rvs-input rvs-ports-input`,value:w,inputMode:`numeric`,spellCheck:!1,autoComplete:`off`,onChange:e=>T(e.target.value)})]}),(0,o.jsx)(`div`,{className:`rvs-ports-form-actions`,children:(0,o.jsx)(`button`,{type:`submit`,className:`rvs-chip primary`,disabled:O===``||v.has(`form`),children:t(`ports.add`)})})]}),g!==void 0&&(0,o.jsx)(`div`,{className:`rvs-banner error`,children:g}),(0,o.jsxs)(`div`,{className:`rvs-ports-section`,children:[(0,o.jsxs)(`div`,{className:`rvs-ports-sec-head`,children:[t(`ports.active`),a!==void 0&&(0,o.jsx)(`span`,{className:`rvs-ports-count`,children:a.length})]}),O===``?null:a===void 0?c===void 0?(0,o.jsx)(`div`,{className:`rvs-empty`,children:t(`common.loading`)}):null:a.length===0?(0,o.jsx)(`div`,{className:`rvs-empty`,children:t(`ports.emptyForwards`)}):a.map(e=>{let n=ne(e);return(0,o.jsxs)(`div`,{className:`rvs-ports-row`,children:[(0,o.jsxs)(`div`,{className:`rvs-ports-line`,children:[(0,o.jsx)(`span`,{className:`rvs-ports-dot ${e.state}`,role:`img`,"aria-label":n,title:n}),(0,o.jsxs)(`span`,{className:`rvs-ports-addr`,title:`${wH(e.remoteHost,e.remotePort)} → ${e.localUrl}`,children:[wH(e.remoteHost,e.remotePort),` → `,e.localUrl]})]}),e.lastError!==void 0&&(0,o.jsx)(`div`,{className:`rvs-ports-err`,children:e.lastError}),(0,o.jsxs)(`div`,{className:`rvs-ports-actions`,children:[e.transport!==void 0&&e.connections>0&&(0,o.jsx)(`span`,{className:`rvs-ports-transport`,"data-transport":e.transport,title:e.transport===`dedicated`?t(`ports.transportDedicatedHint`):t(`ports.transportSharedHint`),children:e.transport===`dedicated`?t(`ports.transportDedicated`):t(`ports.transportShared`)}),(0,o.jsx)(`span`,{className:`rvs-ports-conn`,children:t(`ports.connections`).replace(`{count}`,String(e.connections))}),(0,o.jsx)(`span`,{style:{flex:1}}),(0,o.jsx)(U,{title:t(`ports.copyUrl`),onClick:()=>{Cc(e.localUrl).then(()=>H(t(`ports.copied`)))},children:(0,o.jsx)(xs,{size:13})}),(0,o.jsx)(`a`,{className:`rvs-hbtn rvs-ports-open`,href:e.localUrl,target:`_blank`,rel:`noopener noreferrer`,title:t(`ports.open`),"aria-label":t(`ports.open`),children:(0,o.jsx)(NH,{size:13})}),(0,o.jsx)(U,{title:t(`ports.stop`),danger:!0,disabled:v.has(e.id),onClick:()=>{R(e)},children:(0,o.jsx)(bs,{size:13})})]})]},e.id)})]}),(0,o.jsxs)(`div`,{className:`rvs-ports-section`,children:[(0,o.jsx)(`div`,{className:`rvs-ports-sec-head`,children:t(`ports.listening`)}),O===``?null:u===void 0?f===void 0?(0,o.jsx)(`div`,{className:`rvs-empty`,children:t(`common.loading`)}):(0,o.jsx)(`div`,{className:`rvs-banner error`,children:f}):(0,o.jsxs)(o.Fragment,{children:[(e=>e.tool===`none`?(0,o.jsxs)(`div`,{className:`rvs-empty`,children:[t(`ports.listenUnavailable`),e.error!==void 0&&(0,o.jsx)(`div`,{className:`rvs-ports-hint`,children:e.error})]}):e.tool===`unknown`?(0,o.jsxs)(`div`,{className:`rvs-empty`,children:[t(`ports.listenUnknown`),e.error!==void 0&&(0,o.jsx)(`div`,{className:`rvs-ports-hint`,children:e.error})]}):e.ports.length===0?(0,o.jsx)(`div`,{className:`rvs-empty`,children:t(`ports.emptyListen`)}):(0,o.jsxs)(o.Fragment,{children:[e.ports.map(e=>{let n=`listen:${e.addr}:${e.port}`;return(0,o.jsxs)(`div`,{className:`rvs-ports-row`,children:[(0,o.jsxs)(`div`,{className:`rvs-ports-line`,children:[(0,o.jsx)(`span`,{className:`rvs-ports-addr`,children:wH(e.addr,e.port)}),e.process!==void 0&&(0,o.jsx)(`span`,{className:`rvs-ports-proc`,title:e.process,children:e.process})]}),(0,o.jsxs)(`div`,{className:`rvs-ports-actions`,children:[(0,o.jsx)(`span`,{style:{flex:1}}),(0,o.jsx)(`button`,{type:`button`,className:`rvs-chip`,disabled:v.has(n),onClick:()=>{L(e)},children:t(`ports.forward`)})]})]},`${e.addr}:${e.port}`)}),e.error!==void 0&&(0,o.jsx)(`div`,{className:`rvs-ports-hint`,children:e.error})]}))(u),f!==void 0&&(0,o.jsx)(`div`,{className:`rvs-ports-hint`,children:f})]})]})]})]})}function FH(){return{cpu:[],mem:[],netRx:[],netTx:[],temp:[]}}function IH(e,t,n,r=Date.now()){return{alias:e,state:t,reason:n,sampledAt:r,kernel:null,cpuCores:null,cpuModel:null,ip:null,uptimeSeconds:null,load1:null,load5:null,load15:null,cpuPercent:null,memUsedBytes:null,memTotalBytes:null,memPercent:null,diskUsedBytes:null,diskTotalBytes:null,diskPercent:null,temperatureC:null,netRxBps:null,netTxBps:null}}function LH(e,t){if(t===null||!Number.isFinite(t))return e;let n=[...e,t];return n.length>60&&n.splice(0,n.length-60),n}function RH(e,t){let n=LH(e.cpu,t.cpuPercent),r=LH(e.mem,t.memPercent),i=LH(e.netRx,t.netRxBps),a=LH(e.netTx,t.netTxBps),o=LH(e.temp,t.temperatureC);return n===e.cpu&&r===e.mem&&i===e.netRx&&a===e.netTx&&o===e.temp?e:{cpu:n,mem:r,netRx:i,netTx:a,temp:o}}function zH(e){return Math.round(e*100)/100}function BH(e,t=[]){let n=[...e,...t].filter(e=>Number.isFinite(e));if(n.length===0)return;let r=Math.min(...n),i=Math.max(...n);return r===i&&(--r,i+=1),{min:r,max:i}}function VH(e,t,n,r){let i=e.filter(e=>Number.isFinite(e));if(i.length===0||t<=0||n<=0)return``;let a=r===void 0?Math.min(...i):r.min,o=r===void 0?Math.max(...i):r.max;o===a&&(--a,o+=1);let s=i.length===1?0:t/(i.length-1);return`M${i.map((e,r)=>{let c=i.length===1?t:r*s,l=1-(e-a)/(o-a),u=Math.max(0,Math.min(n,l*n));return`${zH(c)},${zH(u)}`}).join(`L`)}`}let HH=[`B`,`KB`,`MB`,`GB`,`TB`];function UH(e){if(!Number.isFinite(e)||e<=0)return`0 B`;let t=e,n=0;for(;t>=1024&&n<HH.length-1;)t/=1024,n+=1;return n===0?`${Math.round(t)} ${HH[n]}`:`${t>=100?Math.round(t):Math.round(t*10)/10} ${HH[n]}`}function WH(e){let t=e,n=0;for(;t>=1024&&n<HH.length-1;)t/=1024,n+=1;return{value:t,unit:HH[n]}}function GH(e,t){if(!Number.isFinite(e)||!Number.isFinite(t)||t<=0)return``;let n=WH(t),r=e/1024**HH.indexOf(n.unit),i=e=>String(e>=100?Math.round(e):Math.round(e*10)/10);return`${i(r)} / ${i(n.value)} ${n.unit}`}function KH(e){return`${Math.round(e)}%`}function qH(e){return`${UH(e)}/s`}function JH(e){let t=Math.floor(e);if(!Number.isFinite(t)||t<=0)return`—`;let n=Math.floor(t/86400),r=Math.floor(t%86400/3600),i=Math.floor(t%3600/60);return n>0?`${n}d ${r}h`:r>0?`${r}h ${i}m`:`${i}m`}function YH(e){return`${Math.round(e*10)/10} °C`}function XH(e){let t=Math.max(0,Math.floor(e/1e3));return t<60?`${t}s`:t<3600?`${Math.floor(t/60)}m`:`${Math.floor(t/3600)}h`}function ZH(e){return e===null||!Number.isFinite(e)||e<75?`ok`:e<90?`warn`:`hot`}function QH(e,t){if(e===null||!Number.isFinite(e)||e<0)return t(`proc.unknown`);let n=Math.floor(e/86400),r=Math.floor(e%86400/3600),i=Math.floor(e%3600/60);return n>0?`${n}d ${r}h`:r>0?`${r}h ${i}m`:i>0?`${i}m`:`${Math.max(1,Math.floor(e))}s`}function $H(e){return`${e.toFixed(1)}%`}function eU(e,t){let n=[...e];if(t===`pid`)n.sort((e,t)=>e.pid-t.pid);else{let e=t===`cpu`?`cpuPercent`:`memPercent`;n.sort((t,n)=>n[e]-t[e]||t.pid-n.pid)}return n}function tU(e){let t=e.t,[n,r]=(0,i.useState)(e.aliases[0]??``),[a,s]=(0,i.useState)(!1),[c,l]=(0,i.useState)(void 0),[u,d]=(0,i.useState)(!1),[f,p]=(0,i.useState)(void 0),[m,h]=(0,i.useState)(``),[g,_]=(0,i.useState)(`cpu`),[v,y]=(0,i.useState)(void 0),[b,x]=(0,i.useState)(void 0),S=(0,i.useRef)(new Set),C=(0,i.useRef)(n);C.current=n;let w=(0,i.useRef)(!0);(0,i.useEffect)(()=>(w.current=!0,()=>{w.current=!1}),[]),(0,i.useEffect)(()=>{e.aliases.includes(n)||(r(e.aliases[0]??``),l(void 0),p(void 0))},[e.aliases,n]);let T=(0,i.useCallback)(async(e=!1,r=!1)=>{let i=n;if(!(i===``||S.current.has(i))){S.current.add(i),r&&d(!0);try{let t=await V.processes(i,e);if(!w.current||i!==C.current)return;l(t),p(t.error)}catch(e){if(!w.current)return;p(e instanceof pn&&e.status===404?t(`proc.hostTooOld`):e instanceof pn?e.message:String(e))}finally{S.current.delete(i),r&&w.current&&i===C.current&&d(!1)}}},[n]);(0,i.useEffect)(()=>{if(!a||!e.visible||e.paused||n===``)return;let t=()=>{document.hidden||T(!1,!1)};t();let r=window.setInterval(t,Math.max(2e3,e.intervalMs||5e3));return()=>window.clearInterval(r)},[a,e.visible,e.paused,n,T,e.intervalMs]),(0,i.useEffect)(()=>{if(!a||!e.visible||e.paused)return;let t=()=>{document.hidden||T(!1,!1)};return document.addEventListener(`visibilitychange`,t),()=>document.removeEventListener(`visibilitychange`,t)},[a,e.visible,e.paused,T]);let E=(0,i.useMemo)(()=>{let e=m.trim().toLowerCase(),t=c?.processes??[];return eU(e===``?t:t.filter(t=>t.command.toLowerCase().includes(e)||t.user.toLowerCase().includes(e)||String(t.pid).includes(e)),g)},[c,m,g]),D=async e=>{if(await hc({title:t(`proc.killTitle`),text:t(`proc.killText`).replace(`{host}`,n).replace(`{pid}`,String(e.pid)).replace(`{command}`,e.command.slice(0,120)),danger:!0,okText:t(`proc.kill`),cancelText:t(`common.cancel`)})){y(e.pid);try{await V.killProcess(n,e.pid,`TERM`),H(t(`proc.killSent`).replace(`{pid}`,String(e.pid))),await T(!0,!1)}catch(t){H(t instanceof pn?t.message:String(t),!0),x(e.pid)}finally{w.current&&y(void 0)}}},O=async e=>{if(await hc({title:t(`proc.killForceTitle`),text:t(`proc.killForceText`).replace(`{host}`,n).replace(`{pid}`,String(e.pid)).replace(`{command}`,e.command.slice(0,120)),danger:!0,okText:t(`proc.killForce`),cancelText:t(`common.cancel`)})){y(e.pid);try{await V.killProcess(n,e.pid,`KILL`),H(t(`proc.killForceSent`).replace(`{pid}`,String(e.pid))),x(void 0),await T(!0,!1)}catch(e){H(e instanceof pn?e.message:String(e),!0)}finally{w.current&&y(void 0)}}},k=e.hosts.find(e=>e.alias===n),A=c!==void 0&&c.tool===`unknown`;return(0,o.jsxs)(`section`,{className:a?`rvs-proc expanded`:`rvs-proc`,"aria-label":t(`proc.title`),children:[(0,o.jsxs)(`div`,{className:`rvs-proc-head`,children:[(0,o.jsx)(`button`,{type:`button`,className:`rvs-proc-toggle`,"aria-expanded":a,onClick:()=>{s(e=>!e)},title:t(a?`proc.collapse`:`proc.expand`),children:(0,o.jsx)(`span`,{"aria-hidden":`true`,children:a?`▾`:`▸`})}),(0,o.jsx)(`span`,{className:`rvs-proc-title`,children:t(`proc.title`)}),e.aliases.length>1&&(0,o.jsx)(`select`,{className:`rvs-select rvs-proc-host`,value:n,onChange:e=>{r(e.target.value),l(void 0),p(void 0)},"aria-label":t(`proc.host`),children:e.aliases.map(e=>(0,o.jsx)(`option`,{value:e,children:e},e))}),e.aliases.length===1&&k!==void 0&&(0,o.jsx)(`span`,{className:`rvs-proc-host-label`,children:k.alias}),a&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(`input`,{className:`rvs-input rvs-proc-filter`,value:m,onChange:e=>{h(e.target.value)},placeholder:t(`proc.filter`),"aria-label":t(`proc.filter`)}),(0,o.jsxs)(`select`,{className:`rvs-select rvs-proc-sort`,value:g,onChange:e=>{_(e.target.value)},"aria-label":t(`proc.sort`),children:[(0,o.jsx)(`option`,{value:`cpu`,children:t(`proc.sortCpu`)}),(0,o.jsx)(`option`,{value:`mem`,children:t(`proc.sortMem`)}),(0,o.jsx)(`option`,{value:`pid`,children:t(`proc.sortPid`)})]}),(0,o.jsx)(U,{title:t(`proc.refresh`),onClick:()=>{T(!0,!0)},disabled:u||n===``,children:u?(0,o.jsx)(Tc,{}):(0,o.jsx)(hs,{size:13})})]})]}),!a&&(0,o.jsx)(`div`,{className:`rvs-proc-collapsed`,children:t(`proc.collapsedHint`)}),a&&f!==void 0&&(0,o.jsx)(`div`,{className:`rvs-banner warn rvs-proc-banner`,children:A?t(`proc.cannotEnumerate`):f}),a&&c?.tool===`none`&&(0,o.jsx)(`div`,{className:`rvs-banner warn rvs-proc-banner`,children:t(`proc.noPs`)}),a&&c?.truncated===!0&&(0,o.jsx)(`div`,{className:`rvs-banner info rvs-proc-banner`,children:t(`proc.truncated`).replace(`{count}`,String(c.processes.length))}),a&&n===``&&(0,o.jsx)(`div`,{className:`rvs-empty`,children:t(`proc.noHost`)}),a&&n!==``&&E.length===0&&!u&&f===void 0&&c!==void 0&&c.tool!==`none`&&c.tool!==`unknown`&&(0,o.jsx)(`div`,{className:`rvs-empty`,children:t(`proc.empty`)}),a&&E.length>0&&(0,o.jsxs)(`div`,{className:`rvs-proc-table rvs-scroll`,role:`table`,"aria-label":t(`proc.title`),"aria-live":`polite`,children:[(0,o.jsxs)(`div`,{className:`rvs-proc-row rvs-proc-row-head`,role:`row`,children:[(0,o.jsx)(`span`,{role:`columnheader`,children:`PID`}),(0,o.jsx)(`span`,{role:`columnheader`,children:`PPID`}),(0,o.jsx)(`span`,{role:`columnheader`,children:`USER`}),(0,o.jsx)(`span`,{role:`columnheader`,title:t(`proc.cpuHint`),children:`CPU`}),(0,o.jsx)(`span`,{role:`columnheader`,children:`MEM`}),(0,o.jsx)(`span`,{role:`columnheader`,children:t(`proc.elapsed`)}),(0,o.jsx)(`span`,{role:`columnheader`,children:t(`proc.command`)}),(0,o.jsx)(`span`,{"aria-hidden":`true`})]}),E.map(e=>(0,o.jsxs)(`div`,{className:`rvs-proc-row`,role:`row`,children:[(0,o.jsx)(`span`,{role:`cell`,className:`rvs-proc-pid`,children:e.pid}),(0,o.jsx)(`span`,{role:`cell`,className:`rvs-proc-pid`,children:e.ppid===0?`—`:e.ppid}),(0,o.jsx)(`span`,{role:`cell`,className:`rvs-proc-user`,title:e.user,children:e.user}),(0,o.jsx)(`span`,{role:`cell`,className:`rvs-proc-num`,children:$H(e.cpuPercent)}),(0,o.jsx)(`span`,{role:`cell`,className:`rvs-proc-num`,children:$H(e.memPercent)}),(0,o.jsx)(`span`,{role:`cell`,className:`rvs-proc-elapsed`,children:QH(e.elapsedSeconds,t)}),(0,o.jsx)(`span`,{role:`cell`,className:`rvs-proc-command`,title:e.command,children:e.command}),(0,o.jsx)(`span`,{role:`cell`,children:(0,o.jsx)(`button`,{type:`button`,className:b===e.pid?`rvs-proc-kill danger`:`rvs-proc-kill`,title:b===e.pid?t(`proc.killForceTitle`):t(`proc.killTitle`),"aria-label":`${b===e.pid?t(`proc.killForceTitle`):t(`proc.killTitle`)} PID ${e.pid}`,disabled:v===e.pid,onClick:()=>{b===e.pid?O(e):D(e)},children:v===e.pid?(0,o.jsx)(Tc,{}):b===e.pid?t(`proc.killForce`):t(`proc.kill`)})})]},e.pid))]})]})}function nU(e){return e.slots.queued+(e.sftpSlots?.queued??0)+(e.netSlots?.queued??0)+(e.gitSlots?.queued??0)}function rU(e){let t=e.connections;return t.shared.channels+t.pty.channels+t.forward.channels+t.sftp.channels+(t.helper?.channels??0)}function iU(e,t=``){return[...e].sort((e,n)=>{let r=Number(n.alias===t)-Number(e.alias===t);if(r!==0)return r;let i=Number(nU(n)>0)-Number(nU(e)>0);return i===0?e.alias<n.alias?-1:+(e.alias>n.alias):i})}function aU(e){let t=e.t;return(0,o.jsxs)(`div`,{className:`rvs-pool-lane`,children:[(0,o.jsx)(`span`,{className:`rvs-pool-lane-name`,children:e.label}),(0,o.jsxs)(`span`,{className:e.lane.open?`rvs-pool-lane-state open`:`rvs-pool-lane-state`,children:[e.lane.open?t(`pool.laneOpen`):t(`pool.laneClosed`),` · `,t(`pool.channels`).replace(`{channels}`,String(e.lane.channels)),e.inFlight!==void 0&&(0,o.jsxs)(o.Fragment,{children:[` · `,e.inFlight]})]}),e.egress!==void 0&&(0,o.jsx)(`span`,{className:`rvs-pool-egress`,title:e.egress,children:e.egress}),e.fallback!==void 0&&(0,o.jsx)(`span`,{className:`rvs-pool-fallback`,title:e.fallback,children:e.fallback})]})}function oU(e){let t=e.t,n=e.host,r=nU(n),i=n.egress===void 0?void 0:O({egress:n.egress},t),a=n.sftpFallback===!0?t(`pool.sftpFallback`):void 0,s=n.connections.helper,c=s===void 0||s.held<=0?void 0:t(`pool.helperInFlight`).replace(`{count}`,String(s.held));return(0,o.jsxs)(`div`,{className:`rvs-pool-host`,role:`group`,"aria-label":n.alias,children:[(0,o.jsxs)(`div`,{className:`rvs-pool-host-head`,children:[(0,o.jsx)(`span`,{className:`rvs-pool-host-alias`,title:n.alias,children:n.alias}),r>0&&(0,o.jsx)(`span`,{className:`rvs-pool-queue`,children:t(`pool.queued`).replace(`{queued}`,String(r))})]}),(0,o.jsx)(aU,{t,label:t(`pool.shared`),lane:n.connections.shared,egress:i}),(0,o.jsx)(aU,{t,label:t(`pool.pty`),lane:n.connections.pty}),(0,o.jsx)(aU,{t,label:t(`pool.forward`),lane:n.connections.forward}),(0,o.jsx)(aU,{t,label:t(`pool.sftp`),lane:n.connections.sftp,fallback:a}),s!==void 0&&(0,o.jsx)(aU,{t,label:t(`pool.helper`),lane:s,inFlight:c}),(0,o.jsx)(`div`,{className:`rvs-pool-slots`,children:t(`pool.slots`).replace(`{active}`,String(n.slots.active)).replace(`{limit}`,String(n.slots.limit)).replace(`{queued}`,String(n.slots.queued))}),n.sftpSlots!==void 0&&(0,o.jsx)(`div`,{className:`rvs-pool-slots`,children:t(`pool.sftpSlots`).replace(`{active}`,String(n.sftpSlots.active)).replace(`{limit}`,String(n.sftpSlots.limit)).replace(`{queued}`,String(n.sftpSlots.queued))}),n.netSlots!==void 0&&(0,o.jsx)(`div`,{className:`rvs-pool-slots`,children:t(`pool.netSlots`).replace(`{active}`,String(n.netSlots.active)).replace(`{limit}`,String(n.netSlots.limit)).replace(`{queued}`,String(n.netSlots.queued))}),n.gitSlots!==void 0&&(0,o.jsx)(`div`,{className:`rvs-pool-slots`,children:t(`pool.gitSlots`).replace(`{active}`,String(n.gitSlots.active)).replace(`{limit}`,String(n.gitSlots.limit)).replace(`{queued}`,String(n.gitSlots.queued))})]})}function sU(e){let t=e.t,[n,r]=(0,i.useState)(!1),[a,s]=(0,i.useState)(void 0),[c,l]=(0,i.useState)(!1),[u,d]=(0,i.useState)(void 0),f=(0,i.useRef)(!1),p=(0,i.useRef)(!0);(0,i.useEffect)(()=>(p.current=!0,()=>{p.current=!1}),[]);let m=(0,i.useCallback)(async()=>{if(!f.current){f.current=!0;try{let e=await V.getPoolStats();if(!p.current)return;if(e===void 0){l(!0);return}s(e),d(void 0)}catch(e){if(!p.current)return;d(e instanceof pn?e.message:String(e))}finally{f.current=!1}}},[]);(0,i.useEffect)(()=>{if(!n||!e.visible||e.paused||c)return;let t=()=>{document.hidden||m()};t();let r=window.setInterval(t,Math.max(2e3,e.intervalMs||5e3));return()=>window.clearInterval(r)},[n,e.visible,e.paused,c,m,e.intervalMs]),(0,i.useEffect)(()=>{if(!n||!e.visible||e.paused||c)return;let t=()=>{document.hidden||m()};return document.addEventListener(`visibilitychange`,t),()=>document.removeEventListener(`visibilitychange`,t)},[n,e.visible,e.paused,c,m]);let h=e.currentAlias??``,g=(0,i.useMemo)(()=>iU(a?.hosts??[],h),[a,h]),_=(0,i.useMemo)(()=>{if(a!==void 0)return{hosts:g.length,connections:g.reduce((e,t)=>e+rU(t),0),queued:g.reduce((e,t)=>e+nU(t),0)}},[a,g]);if(e.hosts.length===0)return null;let v=n&&!c&&u===void 0&&a===void 0;return(0,o.jsxs)(`section`,{className:n?`rvs-pool expanded`:`rvs-pool`,"aria-label":t(`pool.title`),children:[(0,o.jsxs)(`div`,{className:`rvs-pool-head`,children:[(0,o.jsx)(`button`,{type:`button`,className:`rvs-pool-toggle`,"aria-expanded":n,onClick:()=>{r(e=>!e)},title:t(n?`pool.collapse`:`pool.expand`),children:(0,o.jsx)(`span`,{"aria-hidden":`true`,children:n?`▾`:`▸`})}),(0,o.jsx)(`span`,{className:`rvs-pool-title`,children:t(`pool.title`)}),_!==void 0&&(0,o.jsx)(`span`,{className:`rvs-pool-summary`,"aria-live":`polite`,children:t(`pool.summary`).replace(`{hosts}`,String(_.hosts)).replace(`{connections}`,String(_.connections)).replace(`{queued}`,String(_.queued))})]}),!n&&(0,o.jsx)(`div`,{className:`rvs-pool-collapsed`,children:t(`pool.collapsedHint`)}),n&&c&&(0,o.jsx)(`div`,{className:`rvs-pool-note`,children:t(`pool.unsupported`)}),n&&!c&&u!==void 0&&(0,o.jsx)(`div`,{className:`rvs-pool-note error`,children:u}),v&&(0,o.jsxs)(`div`,{className:`rvs-pool-note`,children:[(0,o.jsx)(Tc,{}),` `,t(`pool.loading`)]}),n&&!c&&a!==void 0&&g.length===0&&(0,o.jsx)(`div`,{className:`rvs-pool-note`,children:t(`pool.empty`)}),n&&g.length>0&&(0,o.jsx)(`div`,{className:`rvs-pool-list rvs-scroll`,children:g.map(e=>(0,o.jsx)(oU,{t,host:e},e.alias))})]})}let cU=`dsh-remote-vs.monitor.scope`,lU=`dsh-remote-vs.monitor.interval`,uU=[5e3,1e4,3e4];function dU(){try{let e=Number(localStorage.getItem(lU));if(uU.includes(e))return e}catch{}return 5e3}function fU(e){try{localStorage.setItem(lU,String(e))}catch{}}function pU(){try{let e=localStorage.getItem(cU);if(e===`current`||e===`all`||e!==null&&e.startsWith(`host:`)&&e.length>5)return e}catch{}return`current`}function mU(e){try{localStorage.setItem(cU,e)}catch{}}function hU(e,t){return t!==``&&e.some(e=>e.alias===t)?t:e[0]?.alias??``}function gU(e,t,n){if(e===`all`)return t.map(e=>e.alias);if(e.startsWith(`host:`)){let n=e.slice(5);if(t.some(e=>e.alias===n))return[n]}let r=hU(t,n);return r===``?[]:[r]}function _U(e){let t=e.size??16;return(0,o.jsxs)(`svg`,{width:t,height:t,viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.4`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,o.jsx)(`rect`,{x:`1.6`,y:`2.6`,width:`12.8`,height:`9`,rx:`1.4`}),(0,o.jsx)(`path`,{d:`M5.2 7.6h1.6l1.1-2.2 1.4 4 1-1.8h1.5`}),(0,o.jsx)(`path`,{d:`M5.6 14.2h4.8`})]})}function vU(e){let t=e.size??14;return(0,o.jsxs)(`svg`,{width:t,height:t,viewBox:`0 0 16 16`,fill:`currentColor`,"aria-hidden":`true`,children:[(0,o.jsx)(`rect`,{x:`4.2`,y:`3`,width:`2.4`,height:`10`,rx:`0.8`}),(0,o.jsx)(`rect`,{x:`9.4`,y:`3`,width:`2.4`,height:`10`,rx:`0.8`})]})}function yU(e){let t=e.size??14;return(0,o.jsx)(`svg`,{width:t,height:t,viewBox:`0 0 16 16`,fill:`currentColor`,"aria-hidden":`true`,children:(0,o.jsx)(`path`,{d:`M5 3.2v9.6c0 .5.6.8 1 .5l7-4.6a.6.6 0 0 0 0-1l-7-4.6c-.4-.3-1 0-1 .5Z`})})}function bU(e){let t=e.size??14;return(0,o.jsxs)(`svg`,{width:t,height:t,viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.4`,strokeLinecap:`round`,"aria-hidden":`true`,children:[(0,o.jsx)(`path`,{d:`M2.4 4.6h4.2M9.4 4.6h4.2`}),(0,o.jsx)(`path`,{d:`M2.4 8h2.2M7.4 8h6.2`}),(0,o.jsx)(`path`,{d:`M2.4 11.4h4.2M9.4 11.4h4.2`}),(0,o.jsx)(`circle`,{cx:`8`,cy:`4.6`,r:`1.3`}),(0,o.jsx)(`circle`,{cx:`6`,cy:`8`,r:`1.3`}),(0,o.jsx)(`circle`,{cx:`8`,cy:`11.4`,r:`1.3`})]})}function xU(e){return(0,o.jsxs)(`div`,{className:`rvs-monitor-tile`,children:[(0,o.jsx)(`div`,{className:`rvs-monitor-tile-label`,children:e.label}),(0,o.jsx)(`div`,{className:`rvs-monitor-tile-value`,children:e.value}),e.percent!==null&&(0,o.jsx)(`div`,{className:`rvs-monitor-bar`,"aria-hidden":`true`,children:(0,o.jsx)(`span`,{className:`rvs-monitor-bar-fill ${ZH(e.percent)}`,style:{width:`${Math.max(0,Math.min(100,e.percent))}%`}})}),e.sub!==void 0&&(0,o.jsx)(`div`,{className:`rvs-monitor-tile-sub`,children:e.sub})]})}function SU(e){return(0,o.jsxs)(`div`,{className:`rvs-monitor-fact`,title:e.title,children:[(0,o.jsx)(`div`,{className:`rvs-monitor-fact-label`,children:e.label}),(0,o.jsx)(`div`,{className:`rvs-monitor-fact-value`,children:e.value})]})}function CU(e){let t=`rvs-grad-${(0,i.useId)().replace(/[^A-Za-z0-9_-]/g,``)}`,n=e.valuesAlt??[],r=n.length===0?void 0:BH(e.values,n),a=VH(e.values,100,28,r),s=n.length===0?``:VH(n,100,28,r),c=e.values.length<2;return(0,o.jsxs)(`div`,{className:`rvs-monitor-spark ${e.tone}`,children:[(0,o.jsxs)(`div`,{className:`rvs-monitor-spark-head`,children:[(0,o.jsx)(`span`,{className:`rvs-monitor-spark-label`,children:e.label}),n.length>0&&(0,o.jsxs)(`span`,{className:`rvs-monitor-spark-legend`,"aria-hidden":`true`,children:[(0,o.jsxs)(`span`,{className:`rvs-monitor-spark-key`,children:[(0,o.jsx)(`i`,{className:`rvs-monitor-spark-line rx`}),`↓`]}),(0,o.jsxs)(`span`,{className:`rvs-monitor-spark-key`,children:[(0,o.jsx)(`i`,{className:`rvs-monitor-spark-line tx`}),`↑`]})]})]}),a===``?(0,o.jsx)(`div`,{className:`rvs-monitor-spark-empty`,children:e.empty}):(0,o.jsx)(`svg`,{viewBox:`0 0 100 28`,preserveAspectRatio:`none`,"aria-hidden":`true`,children:c?(0,o.jsx)(`circle`,{cx:`98`,cy:`14`,r:`2`,fill:`currentColor`}):(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(`defs`,{children:(0,o.jsxs)(`linearGradient`,{id:t,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,o.jsx)(`stop`,{offset:`0%`,stopColor:`currentColor`,stopOpacity:`0.22`}),(0,o.jsx)(`stop`,{offset:`100%`,stopColor:`currentColor`,stopOpacity:`0`})]})}),(0,o.jsx)(`path`,{d:`${a}L100,28L0,28Z`,fill:`url(#${t})`}),s!==``&&(0,o.jsx)(`path`,{d:s,fill:`none`,stroke:`currentColor`,strokeWidth:`1.3`,strokeDasharray:`3 3`,opacity:`0.6`,vectorEffect:`non-scaling-stroke`}),(0,o.jsx)(`path`,{d:a,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,vectorEffect:`non-scaling-stroke`})]})})]})}function wU(e,t){return t(e===`ok`?`monitor.stateOk`:e===`error`?`monitor.stateError`:`monitor.stateUnknown`)}function TU(e,t){let n=t.find(t=>t.alias===e);return n===void 0?e:`${n.user}@${n.host}:${n.port}`}function EU(e){let t=e.t,n=pl().workspace?.alias??``,[r,a]=(0,i.useState)(pU),[s,c]=(0,i.useState)(dU),[l,u]=(0,i.useState)(!1),[d,f]=(0,i.useState)({}),[p,m]=(0,i.useState)({}),[h,g]=(0,i.useState)(!1),[_,v]=(0,i.useState)(!1),y=(0,i.useRef)(new Set),b=(0,i.useRef)(!0);(0,i.useEffect)(()=>(b.current=!0,()=>{b.current=!1}),[]);let x=(0,i.useMemo)(()=>gU(r,e.hosts,n),[r,e.hosts,n]),S=x.join(`|`),C=(0,i.useRef)(x);C.current=x;let w=hU(e.hosts,n),T=(0,i.useMemo)(()=>{if(r===`all`)return`all`;if(r.startsWith(`host:`)){let t=r.slice(5);if(e.hosts.some(e=>e.alias===t))return r}return`current`},[r,e.hosts]),E=(0,i.useCallback)(async(e,t)=>{await Promise.all(e.map(async e=>{if(!y.current.has(e)){y.current.add(e);try{let n=await V.hostMetrics(e,t);if(!b.current)return;f(t=>({...t,[e]:n})),m(t=>({...t,[e]:RH(t[e]??FH(),n)}))}catch(t){if(!b.current)return;let n=t instanceof pn?t.message:String(t);f(t=>({...t,[e]:IH(e,`error`,n)}))}finally{y.current.delete(e)}}}))},[]);(0,i.useEffect)(()=>{if(!e.visible||h||C.current.length===0)return;let t=()=>{document.hidden||E(C.current,!1)};t();let n=window.setInterval(t,s),r=()=>{document.hidden||t()};return document.addEventListener(`visibilitychange`,r),()=>{document.removeEventListener(`visibilitychange`,r),window.clearInterval(n)}},[e.visible,h,S,s,E]);let D=(0,i.useCallback)(()=>{let e=C.current;e.length!==0&&(v(!0),E(e,!0).finally(()=>{b.current&&v(!1)}))},[E]),O=(0,i.useCallback)(e=>{let t=e;a(t),mU(t)},[]),k=(0,i.useCallback)(e=>{let t=Number(e);uU.includes(t)&&(c(t),fU(t))},[]),A=t(`monitor.unknown`),j=e=>wU(e,t),M=e=>{let n=Date.now()-e.sampledAt;return n<1500?t(`monitor.justNow`):t(`monitor.updatedAgo`).replace(`{age}`,XH(n))},N=n=>{let r=d[n];if(r===void 0)return(0,o.jsx)(`div`,{className:`rvs-empty`,children:e.visible?(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(Tc,{}),` `,t(`monitor.loading`)]}):t(`monitor.noData`)});let i=r.state,a=j(i),s=p[n]??FH(),c=r.memPercent,l=r.diskPercent,u=r.load1===null||r.load5===null||r.load15===null?A:[r.load1,r.load5,r.load15].map(e=>e.toFixed(2)).join(` / `),f=r.netRxBps===null&&r.netTxBps===null?A:`${r.netRxBps===null?A:qH(r.netRxBps)} ↓ / ${r.netTxBps===null?A:qH(r.netTxBps)} ↑`;return(0,o.jsxs)(`div`,{className:`rvs-monitor-card ${i}`,children:[(0,o.jsxs)(`div`,{className:`rvs-monitor-head`,children:[(0,o.jsx)(`span`,{className:`rvs-monitor-dot ${i}`,"aria-hidden":`true`}),(0,o.jsx)(`span`,{className:`rvs-monitor-title`,title:n,children:n}),(0,o.jsx)(`span`,{className:`rvs-monitor-conn`,title:TU(n,e.hosts),children:TU(n,e.hosts)})]}),(0,o.jsxs)(`div`,{className:`rvs-monitor-sub`,children:[(0,o.jsx)(`span`,{className:`rvs-monitor-state ${i}`,children:a}),(0,o.jsx)(`span`,{className:`rvs-monitor-age`,children:M(r)}),r.reason!==void 0&&(0,o.jsx)(`span`,{className:`rvs-monitor-reason`,title:r.reason,children:t(`monitor.reason`).replace(`{reason}`,r.reason)})]}),i===`ok`?(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(`div`,{className:`rvs-monitor-grid`,children:[(0,o.jsx)(xU,{label:t(`monitor.cpu`),value:r.cpuPercent===null?A:KH(r.cpuPercent),percent:r.cpuPercent,sub:r.cpuCores===null?r.cpuPercent===null?t(`monitor.warming`):void 0:t(`monitor.cores`).replace(`{count}`,String(r.cpuCores))}),(0,o.jsx)(xU,{label:t(`monitor.ram`),value:c===null?A:KH(c),percent:c,sub:r.memUsedBytes===null||r.memTotalBytes===null?void 0:GH(r.memUsedBytes,r.memTotalBytes)}),(0,o.jsx)(xU,{label:t(`monitor.disk`),value:l===null?A:KH(l),percent:l,sub:r.diskUsedBytes===null||r.diskTotalBytes===null?void 0:GH(r.diskUsedBytes,r.diskTotalBytes)})]}),(0,o.jsxs)(`div`,{className:`rvs-monitor-facts`,children:[(0,o.jsx)(SU,{label:t(`monitor.temp`),value:r.temperatureC===null?A:YH(r.temperatureC)}),(0,o.jsx)(SU,{label:t(`monitor.uptime`),value:r.uptimeSeconds===null?A:JH(r.uptimeSeconds)}),(0,o.jsx)(SU,{label:t(`monitor.load`),value:u}),(0,o.jsx)(SU,{label:t(`monitor.net`),value:f,title:r.netRxBps===null&&r.netTxBps===null?t(`monitor.warming`):void 0})]}),(0,o.jsxs)(`div`,{className:`rvs-monitor-sparks`,children:[(0,o.jsx)(CU,{label:t(`monitor.cpuHistory`),values:s.cpu,tone:`cpu`,empty:t(`monitor.warming`)}),(0,o.jsx)(CU,{label:t(`monitor.memHistory`),values:s.mem,tone:`mem`,empty:t(`monitor.warming`)}),(0,o.jsx)(CU,{label:t(`monitor.netHistory`),values:s.netRx,valuesAlt:s.netTx,tone:`net`,empty:t(`monitor.warming`)}),(0,o.jsx)(CU,{label:t(`monitor.tempHistory`),values:s.temp,tone:`temp`,empty:t(`monitor.unknown`)})]}),(0,o.jsx)(`div`,{className:`rvs-monitor-hint`,children:r.kernel===null?t(`monitor.linuxOnly`):`${r.kernel}${r.cpuModel===null?``:` · ${r.cpuModel}`}${r.ip===null?``:` · ${r.ip}`}`})]}):(0,o.jsx)(`div`,{className:`rvs-monitor-hint`,children:r.reason??t(`monitor.noData`)})]})},ee=n=>{let r=n.filter(e=>d[e]?.state===`ok`).length;return(0,o.jsxs)(`div`,{className:`rvs-monitor-list`,children:[(0,o.jsx)(`div`,{className:`rvs-monitor-summary`,children:t(`monitor.allSummary`).replace(`{ok}`,String(r)).replace(`{total}`,String(n.length))}),n.map(n=>{let r=d[n],i=r?.state??`unknown`,a=j(i),s=r?.cpuPercent??null,c=r?.memPercent??null;return(0,o.jsxs)(`button`,{type:`button`,className:`rvs-monitor-row ${i}`,onClick:()=>O(`host:${n}`),title:t(`monitor.inspect`),children:[(0,o.jsxs)(`span`,{className:`rvs-monitor-row-top`,children:[(0,o.jsx)(`span`,{className:`rvs-monitor-dot ${i}`,role:`img`,"aria-label":a}),(0,o.jsx)(`span`,{className:`rvs-monitor-row-name`,children:n}),(0,o.jsx)(`span`,{className:`rvs-monitor-row-host`,children:TU(n,e.hosts)}),r===void 0?(0,o.jsx)(Tc,{}):(0,o.jsx)(`span`,{className:`rvs-monitor-row-cpu`,children:s===null?A:KH(s)})]}),(0,o.jsxs)(`span`,{className:`rvs-monitor-row-bars`,children:[(0,o.jsx)(`span`,{className:`rvs-monitor-row-bar`,title:`${t(`monitor.cpu`)} ${s===null?A:KH(s)}`,children:(0,o.jsx)(`span`,{className:`rvs-monitor-bar-fill ${ZH(s)}`,style:{width:`${s===null?0:Math.max(0,Math.min(100,s))}%`}})}),(0,o.jsx)(`span`,{className:`rvs-monitor-row-bar`,title:`${t(`monitor.ram`)} ${c===null?A:KH(c)}`,children:(0,o.jsx)(`span`,{className:`rvs-monitor-bar-fill ${ZH(c)}`,style:{width:`${c===null?0:Math.max(0,Math.min(100,c))}%`}})})]}),(0,o.jsxs)(`span`,{className:`rvs-monitor-row-facts`,children:[(0,o.jsxs)(`span`,{children:[t(`monitor.ram`),` `,c===null?A:KH(c)]}),(0,o.jsxs)(`span`,{children:[t(`monitor.temp`),` `,r?.temperatureC===null||r?.temperatureC===void 0?A:YH(r.temperatureC)]}),(0,o.jsxs)(`span`,{children:[t(`monitor.uptime`),` `,r?.uptimeSeconds===null||r?.uptimeSeconds===void 0?A:JH(r.uptimeSeconds)]})]})]},n)}),(0,o.jsx)(`div`,{className:`rvs-monitor-hint`,children:t(`monitor.linuxOnly`)})]})},P=x.length===1?x[0]:void 0;return(0,o.jsxs)(`div`,{className:`rvs-pane grow`,children:[(0,o.jsxs)(`div`,{className:`rvs-header rvs-monitor-header`,children:[(0,o.jsx)(`span`,{className:`rvs-title`,children:t(`tab.monitor`)}),(0,o.jsxs)(`select`,{className:`rvs-select`,value:T,onChange:e=>O(e.target.value),disabled:e.hosts.length===0,title:`${t(`monitor.selectScope`)}${w===``?``:` · ${w}`}`,style:{flex:1,minWidth:90},children:[(0,o.jsx)(`option`,{value:`current`,style:iz,children:t(`monitor.scopeCurrent`)}),e.hosts.map(e=>(0,o.jsx)(`option`,{value:`host:${e.alias}`,style:iz,children:e.alias},e.alias)),(0,o.jsx)(`option`,{value:`all`,style:iz,children:t(`monitor.scopeAll`)})]}),(0,o.jsx)(U,{title:t(`monitor.settings`),onClick:()=>u(e=>!e),className:l?`active`:void 0,children:(0,o.jsx)(bU,{})}),(0,o.jsx)(U,{title:t(h?`monitor.resume`:`monitor.pause`),onClick:()=>g(e=>!e),children:h?(0,o.jsx)(yU,{}):(0,o.jsx)(vU,{})}),(0,o.jsx)(U,{title:t(`monitor.refresh`),onClick:D,disabled:x.length===0||_,children:_?(0,o.jsx)(Tc,{}):(0,o.jsx)(hs,{size:14})})]}),l&&(0,o.jsxs)(`div`,{className:`rvs-monitor-settings`,children:[(0,o.jsxs)(`div`,{className:`rvs-monitor-settings-head`,children:[(0,o.jsx)(`span`,{className:`rvs-monitor-settings-label`,children:t(`monitor.interval`)}),(0,o.jsx)(`span`,{className:`rvs-monitor-settings-hint`,children:t(`monitor.intervalHint`)})]}),(0,o.jsx)(wc,{value:String(s),onChange:k,options:[{id:`5000`,label:t(`monitor.interval5`)},{id:`10000`,label:t(`monitor.interval10`)},{id:`30000`,label:t(`monitor.interval30`)}]})]}),(0,o.jsxs)(`div`,{className:`rvs-monitor-body`,children:[(0,o.jsxs)(`div`,{className:`rvs-monitor-content rvs-scroll`,children:[e.hosts.length===0&&(0,o.jsx)(`div`,{className:`rvs-banner warn`,children:t(`monitor.noHosts`)}),e.hosts.length>0&&x.length===0&&(0,o.jsx)(`div`,{className:`rvs-empty`,children:t(`monitor.noHost`)}),h&&(0,o.jsx)(`div`,{className:`rvs-banner info`,children:t(`monitor.paused`)}),P!==void 0&&N(P),P===void 0&&x.length>1&&ee(x)]}),(0,o.jsx)(tU,{t,hosts:e.hosts,aliases:x,visible:e.visible,paused:h,intervalMs:s}),(0,o.jsx)(sU,{t,hosts:e.hosts,visible:e.visible,paused:h,intervalMs:s,currentAlias:w})]})]})}function DU(e){let{dir:t,name:n}=Cz(e.path),r=(0,i.useMemo)(()=>new Set(Sz(e.query,n)),[e.query,n]);return(0,o.jsxs)(`div`,{className:e.active?`rvs-qo-row active`:`rvs-qo-row`,role:`option`,"aria-selected":e.active,id:`rvs-qo-option-${e.index}`,"data-qo-index":e.index,onMouseDown:t=>{t.preventDefault(),e.onPick()},onMouseEnter:e.onHover,children:[t!==``&&(0,o.jsx)(`span`,{className:`rvs-qo-dir`,title:t,children:t}),(0,o.jsx)(`span`,{className:`rvs-qo-name`,children:n.split(``).map((e,t)=>r.has(t)?(0,o.jsx)(`mark`,{className:`rvs-qo-hit`,children:e},t):(0,o.jsx)(`span`,{children:e},t))})]})}function OU(e){let t=pl(),n=t.t,r=t.alias,s=t.root,c=(0,i.useSyncExternalStore)(Vz,Bz),[l,u]=(0,i.useState)(``),[d,f]=(0,i.useState)(0),p=(0,i.useRef)(null),m=(0,i.useRef)(null),h=(0,i.useRef)(null),g=(0,i.useRef)(e.onClose);g.current=e.onClose;let _=(0,i.useRef)(typeof document>`u`?null:document.activeElement);(0,i.useEffect)(()=>(p.current?.focus(),()=>{let e=_.current;e!==null&&document.body.contains(e)&&e.focus()}),[]);let v=e=>{if(e.key!==`Tab`)return;let t=h.current;if(t===null)return;let n=Array.from(t.querySelectorAll(`input:not([disabled]), button:not([disabled]), [tabindex]:not([tabindex="-1"])`));if(n.length===0)return;let r=n[0],i=n[n.length-1],a=document.activeElement;if(!(a!==null&&t.contains(a))){e.preventDefault(),r.focus();return}if(e.shiftKey&&a===r){e.preventDefault(),i.focus();return}!e.shiftKey&&a===i&&(e.preventDefault(),r.focus())};(0,i.useEffect)(()=>{let e=e=>{e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),g.current())};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[]),(0,i.useEffect)(()=>{if(r===``||s===``){Hz(Lz(n(`quickopen.noWorkspace`)));return}let e=kn();if(!Nz(Bz(),r,s,e))return;Hz(Pz(Bz(),r,s));let t={alias:r,root:s};Jz({exec:V.exec,writeSequence:kn},t).then(e=>Hz(Fz(Bz(),e)),e=>Hz(Iz(Bz(),Ez(e),t)))},[r,s,n]);let y=(0,i.useMemo)(()=>{if(r===``||s===``)return[];let e=[];for(let t of Oz(r)){let n=Tz(s,t);n!==void 0&&n!==``&&e.push(n)}return e},[r,s]),b=l.trim()===``,x=b?y:c.index?.paths??[],S=(0,i.useMemo)(()=>bz(l,x,50),[l,x]),C=S.hits.length,w=C===0?-1:Math.min(d,C-1);(0,i.useEffect)(()=>{f(0)},[l,c.phase,c.index]),(0,i.useEffect)(()=>{w<0||(m.current?.querySelector(`[data-qo-index="${w}"]`))?.scrollIntoView?.({block:`nearest`})},[w]);let T=n=>{if(r===``||s===``)return;let i=wz(s,n);kz(r,i),t.openFile(i),e.onClose()};return typeof document>`u`?null:(0,a.createPortal)((0,o.jsx)(`div`,{className:`rvs-portal`,children:(0,o.jsx)(`div`,{className:`rvs-qo-mask`,onMouseDown:t=>{t.target===t.currentTarget&&e.onClose()},children:(0,o.jsxs)(`div`,{className:`rvs-qo`,role:`dialog`,"aria-modal":`true`,"aria-label":n(`quickopen.title`),ref:h,onKeyDown:v,children:[(0,o.jsxs)(`div`,{className:`rvs-qo-bar`,children:[(0,o.jsx)(`input`,{ref:p,className:`rvs-qo-input`,type:`text`,value:l,placeholder:n(`quickopen.placeholder`),spellCheck:!1,autoComplete:`off`,role:`combobox`,"aria-expanded":!0,"aria-controls":`rvs-qo-list`,"aria-activedescendant":w>=0?`rvs-qo-option-${w}`:void 0,onChange:e=>u(e.target.value),onKeyDown:e=>{if(!(e.nativeEvent.isComposing===!0||e.keyCode===229)){if(e.key===`ArrowDown`||e.key===`ArrowUp`){if(e.preventDefault(),C===0)return;f(t=>{let n=Math.min(t,C-1);return e.key===`ArrowDown`?(n+1)%C:n<=0?C-1:n-1});return}if(e.key===`Enter`){e.preventDefault();let t=w>=0?S.hits[w]:void 0;t!==void 0&&T(t)}}}}),(0,o.jsx)(`span`,{className:`rvs-qo-hint`,children:n(`quickopen.hint`)})]}),(0,o.jsx)(`div`,{className:`rvs-qo-list`,id:`rvs-qo-list`,role:`listbox`,ref:m,children:S.hits.map((e,t)=>(0,o.jsx)(DU,{path:e,query:l,active:t===w,index:t,onPick:()=>T(e),onHover:()=>f(t)},e))}),(0,o.jsxs)(`div`,{className:`rvs-qo-foot`,children:[c.phase===`error`?(0,o.jsx)(`span`,{className:`rvs-qo-note error`,role:`status`,children:n(`quickopen.indexError`).replace(`{reason}`,c.error??``)}):c.phase===`loading`?(0,o.jsxs)(`span`,{className:`rvs-qo-note`,role:`status`,children:[(0,o.jsx)(Tc,{}),` `,n(`quickopen.indexing`)]}):b?C===0?(0,o.jsx)(`span`,{className:`rvs-qo-note`,children:n(`quickopen.emptyRecent`)}):(0,o.jsx)(`span`,{className:`rvs-qo-note`,children:n(`quickopen.recent`)}):C===0?(0,o.jsx)(`span`,{className:`rvs-qo-note`,children:n(`quickopen.noResults`)}):S.truncated?(0,o.jsx)(`span`,{className:`rvs-qo-note`,children:n(`quickopen.more`)}):null,c.index?.truncated===!0&&(0,o.jsx)(`span`,{className:`rvs-qo-note warn`,role:`status`,children:n(`quickopen.truncated`).replace(`{count}`,String(c.index.paths.length))}),c.index?.depthCapped!==void 0&&(0,o.jsx)(`span`,{className:`rvs-qo-note warn`,role:`status`,children:n(`quickopen.depthCapped`).replace(`{depth}`,String(c.index.depthCapped)).replace(`{count}`,String(c.index.paths.length))}),c.index?.warning!==void 0&&(0,o.jsx)(`span`,{className:`rvs-qo-note warn`,role:`status`,children:n(`quickopen.warning`).replace(`{detail}`,c.index.warning)})]})]})})}),document.body)}function kU(e){if(typeof e!=`string`||e===``||e.length>4096)throw Error(`invalid path: ${String(e)}`);let t=e.replace(/\\/g,`/`).replace(/\/+$/,``)||`/`;if(/[\0\n\r]/.test(t))throw Error(`path contains control characters`);if(!t.startsWith(`/`))throw Error(`path must be absolute`);if(t.split(`/`).some(e=>e===`..`))throw Error(`path must not contain ..`);return t}function AU(e,t){let n=t.replace(/\\/g,`/`).trim().replace(/^\/+/,``);if(n===``||n.split(`/`).some(e=>e===``||e===`.`||e===`..`))throw Error(`invalid name: ${t}`);return`${kU(e)}/${n}`}function jU(e,t,n){return`cp -r -- ${B(kU(e))} ${n===void 0?`${B(kU(t))}/`:B(AU(t,n))}`}function MU(e,t,n){return`mv -- ${B(kU(e))} ${n===void 0?`${B(kU(t))}/`:B(AU(t,n))}`}function NU(e){if(typeof e!=`string`||e===``)throw Error(`invalid path: empty`);if(e.length>4096)throw Error(`invalid path: too long`);if(!e.startsWith(`/`))throw Error(`invalid path: must be absolute`);if(/[\u0000-\u001f\u007f-\u009f]/.test(e))throw Error(`invalid path: control characters`);let t=e.replace(/\/{2,}/g,`/`).replace(/\/+$/,``)||`/`;if(t===`/`)throw Error(`invalid path: refusing to remove /`);if(t.split(`/`).some(e=>e===`..`||e===`.`))throw Error(`invalid path: must not contain . or ..`);return t}function PU(e){let t=[];for(let n=0;n<e.length;n+=1){let r=B(NU(e[n]));t.push(`echo 'RV_DEL_ITEM ${n}'`),t.push(`if rm -rf -- ${r}; then echo 'RV_DEL_OK ${n}'; else echo 'RV_DEL_FAIL ${n}'; fi`)}return t.push(`exit 0`),t.join(`
7059
7111
  `)}function FU(e){let t=[],n=new Set;for(let r of e){let e=NU(r);n.has(e)||(n.add(e),t.push(e))}let r=[],i=[];for(let e of t){if(i.length>0){let t=[...i,e],n=new TextEncoder().encode(PU(t)).length;if(t.length>200||n>49152){r.push(i),i=[e];continue}i=t;continue}i=[e]}return i.length>0&&r.push(i),r}function IU(e){let t=/^RV_DEL_(ITEM|OK|FAIL) (\d+)$/.exec(e.trim());if(t===null)return;let n=Number(t[2]);if(Number.isSafeInteger(n))return{kind:t[1]===`ITEM`?`item`:t[1]===`OK`?`ok`:`fail`,index:n}}function LU(e,t,n=650){let r,i,a=()=>{i!==void 0&&(t.clear(i),i=void 0)};return{hover(o){r===o&&i!==void 0||(a(),r=o,i=t.set(()=>{r===o&&(r=void 0,i=void 0,e(o))},n))},leave(e){r===e&&(a(),r=void 0)},reset(){a(),r=void 0},pending(){return r}}}var RU=class{keyOf;load;store;inFlight=new Map;newest=new Map;sequence=0;constructor(e,t,n){this.keyOf=e,this.load=t,this.store=n}request(e,t,n=!1){let r=this.keyOf(e),i=this.inFlight.get(r);if(!n&&i!==void 0&&i.revision===t)return i.promise;let a=this.sequence+=1,o=this.load(e),s={promise:o,revision:t};this.inFlight.set(r,s),this.newest.set(r,a);let c=()=>{this.inFlight.get(r)===s&&this.inFlight.delete(r)};return o.then(e=>{this.newest.get(r)===a&&(this.newest.delete(r),this.store(r,e)),c()},()=>{this.newest.get(r)===a&&this.newest.delete(r),c()}),o}busy(e){return this.inFlight.has(this.keyOf(e))}};function zU(e){let t=e.replace(/\\/g,`/`);if(t.trim()===``)return{ok:!1,reason:`empty`};if(t.startsWith(`/`)||/^[A-Za-z]:/.test(t))return{ok:!1,reason:`absolute`};let n=[];for(let e of t.split(`/`))if(!(e===``||e===`.`)){if(e===`..`||e.includes(`\0`))return{ok:!1,reason:`escape`};n.push(e)}return n.length===0?{ok:!1,reason:`empty`}:{ok:!0,path:n.join(`/`)}}function BU(e){let t=e.split(`/`);t.pop();let n=[],r=``;for(let e of t)r=r===``?e:`${r}/${e}`,n.push(r);return n}function VU(e,t=2147483648){let n=[],r=[],i=new Set,a=new Set;for(let o of e){let e=zU(o.rel);if(!e.ok){r.push({rel:o.rel,reason:e.reason});continue}let s=e.path;if(!i.has(s)){if(o.size>t){r.push({rel:s,reason:`too-large`});continue}i.add(s),n.push({rel:s,size:o.size});for(let e of BU(s))a.add(e)}}return{dirs:[...a].sort((e,t)=>{let n=e.split(`/`).length-t.split(`/`).length;return n===0?e.localeCompare(t):n}),files:n,skipped:r}}function HU(e,t){let n=new Set(e.dirs);for(let e of t){let t=zU(e);if(t.ok)for(let e of[...BU(t.path),t.path])n.add(e)}return{...e,dirs:[...n].sort((e,t)=>{let n=e.split(`/`).length-t.split(`/`).length;return n===0?e.localeCompare(t):n})}}function UU(e){return new Promise((t,n)=>{let r=e.file?.bind(e);if(r===void 0){n(Error(`no file reader for ${e.name}`));return}let i=!1,a=setTimeout(()=>{i||(i=!0,n(Error(`the browser never delivered "${e.name}" (entry API timed out)`)))},1500);a.unref?.(),r(e=>{i||(i=!0,clearTimeout(a),t(e))},e=>{i||(i=!0,clearTimeout(a),n(e instanceof Error?e:Error(String(e))))})})}function WU(e){return new Promise((t,n)=>{let r=[],i=()=>{e.readEntries(e=>{if(e.length===0){t(r);return}r.push(...e),i()},e=>n(e instanceof Error?e:Error(String(e))))};i()})}async function GU(e){let t=[],n=[],r=0,i=async(e,a)=>{let o=a===``?e.name:`${a}/${e.name}`;if(e.isFile){let n=await UU(e);t.push({rel:o,size:typeof n.size==`number`?n.size:0,blob:n});return}if(!e.isDirectory)return;if(r+=1,r>5e3)throw Error(`too many directories in the drop`);n.push(o);let s=e.createReader;if(s===void 0)return;let c=await WU(s.call(e));for(let e of c)await i(e,o)};for(let t of e)await i(t,``);return{files:t,dirs:n}}function KU(e,t,n){return new Promise(r=>{let i=setTimeout(()=>{aW(`deadline`,{label:n,ms:t}),r(void 0)},t);i.unref?.(),e.then(e=>{clearTimeout(i),r(e)},()=>{clearTimeout(i),r(void 0)})})}function qU(e){return typeof e==`object`&&!!e&&e.name===`AbortError`}function JU(e,t){return`${e}:${t}`}function YU(e,t){return e!==t}function XU(e){return!e}function ZU(e){return!XU(e)}function QU(e,t){return e===t||e.startsWith(`${t}/`)}function $U(e,t){let n=t.replace(/\/+$/,``),r=n.slice(n.lastIndexOf(`/`)+1);return`${e.replace(/\/+$/,``)}/${r}`}function eW(e,t){if(t.length===0)return e;let n=new Set,r=!1;for(let i of e){if(t.some(e=>QU(i,e))){r=!0;continue}n.add(i)}return r?n:e}function tW(e,t,n){let r=new Set,i=!1;for(let a of e)QU(a,t)?(r.add(`${n}${a.slice(t.length)}`),i=!0):r.add(a);return i?r:e}function nW(e,t,n){if(n.length===0)return e;let r=JU(t,``),i={},a=!1;for(let[t,o]of Object.entries(e)){let e=t.startsWith(r)?t.slice(r.length):t;if(n.some(t=>QU(e,t))){a=!0;continue}i[t]=o}return a?i:e}function rW(e,t,n,r){let i=JU(t,``),a={},o=!1;for(let[s,c]of Object.entries(e)){if(!s.startsWith(i)){a[s]=c;continue}let e=s.slice(i.length);QU(e,n)?(a[JU(t,`${r}${e.slice(n.length)}`)]=c,o=!0):a[s]=c}return o?a:e}function iW(e){if(!(`clientX`in e))return;let{clientX:t,clientY:n}=e;if(!(typeof t!=`number`||typeof n!=`number`)&&!(t===0&&n===0))return{x:t,y:n}}function aW(e,t){console.info(`[dsh-remote-vs] drop`,e,t)}function oW(e){return e>=1024*1024*1024?`${(e/(1024*1024*1024)).toFixed(1)} GB`:e>=1024*1024?`${(e/(1024*1024)).toFixed(1)} MB`:e>=1024?`${Math.round(e/1024)} KB`:`${e} B`}function sW(e,t){if(t.phase===`preparing`)return e(`files.uploadPreparing`);if(t.phase===`waiting`)return`${e(`files.uploadWaiting`)} ${t.name}`;let n=`${t.done+1}/${t.total}`;if(t.size<=0)return`${e(`files.uploading`)} ${n} · ${t.name}`;let r=Math.min(100,Math.floor(t.loaded/t.size*100));return`${e(`files.uploading`)} ${n} · ${r}% · ${oW(t.loaded)}/${oW(t.size)} · ${t.name}`}function cW(e,t){return e(`files.deleting`).replace(`{done}`,String(t.done)).replace(`{total}`,String(t.total)).replace(`{name}`,t.name)}function lW(e,t,n){let r=e+t;for(;;){let e=r.indexOf(`
7060
7112
  `);if(e<0)break;let t=r.slice(0,e);r=r.slice(e+1);let i=IU(t);i!==void 0&&n(i)}return r}let uW={height:28,boxSizing:`border-box`,paddingTop:2,paddingBottom:2},dW=new Intl.Collator(void 0,{numeric:!1,sensitivity:`variant`});function fW(e,t,n,r,i=8){let a=Number.isFinite(e)?Math.max(0,Math.trunc(e)):0;if(a===0)return{from:0,to:0,before:0,after:0};let o=Math.max(0,Number.isFinite(r)?r:0),s=(Number.isFinite(n)?n:0)-o;if(s<=0){let e=a<=100?a:Math.min(40,a);return{from:0,to:e,before:0,after:(a-e)*28}}let c=Math.max(0,Math.trunc(Number.isFinite(i)?i:8)),l=Math.max(0,Math.min((Number.isFinite(t)?t:0)-o,a*28-s)),u=Math.min(Math.floor(l/28),a-1),d=Math.max(1,Math.ceil(s/28)),f=Math.max(0,u-c),p=Math.min(a,Math.max(f+1,u+d+c));return{from:f,to:p,before:f*28,after:(a-p)*28}}function pW(e,t,n){let r={};for(let[n,i]of Object.entries(e))n!==t&&(r[n]=i);return r[t]=n,r}function mW(e,t){let n=Object.keys(e),r=n.length-50;if(r<=0)return e;let i;for(let a=0;a<r;a++){let r=n[a];t.has(r)||(i===void 0&&(i={...e}),delete i[r])}return i??e}function hW(e){let t=new Set;if(e.root===``)return t;let n=r=>{let i=JU(e.alias,r);t.add(i);for(let t of e.listings[i]??[])e.visible!==void 0&&!e.visible(t)||t.isDir&&e.expanded.has(t.path)&&n(t.path)};return n(e.root),t}function gW(e){return e.isDir?void 0:e.path}function _W(e){if(e.root===``)return[];let t=[],n=(r,i)=>{let a=e.creating;a?.dir===r&&t.push({kind:`create`,dir:r,createKind:a.kind,depth:i});for(let a of e.rowsOf(r)??[])if(t.push({kind:`entry`,entry:a,depth:i}),!(!a.isDir||!e.isExpanded(a.path))){if(e.rowsOf(a.path)===void 0){let n=e.placeholderOf?.(a.path);n!==void 0&&t.push({kind:`pending`,dir:a.path,depth:i+1,reason:n});continue}n(a.path,i+1)}};return n(e.root,0),t}function vW(e,t,n){let r=e.filter(e=>e.kind===`entry`),i=r.findIndex(e=>e.entry.path===t);if(i<0)return;if(n===`up`)return r[i-1]?.entry.path;if(n===`down`)return r[i+1]?.entry.path;let a=r[i];if(n===`child`){let e=r[i+1];return e!==void 0&&e.depth>a.depth?e.entry.path:void 0}for(let e=i-1;e>=0;--e){let t=r[e];if(t.depth<a.depth)return t.entry.path}}function yW(e,t){let n=e.filter(e=>e.kind===`entry`);return t!==void 0&&n.some(e=>e.entry.path===t)?t:n[0]?.entry.path}function bW(e){return e.replace(/[\\"\u0000-\u001f\u007f]/g,e=>e===`\\`||e===`"`?`\\${e}`:`\\${e.charCodeAt(0).toString(16)} `)}function xW(e){let t=document.querySelector(`[data-rvs-path="${bW(e)}"]`);return t!==null&&t.dataset.rvsPath===e?t:null}let SW=(0,i.memo)(function(e){let{entry:t,depth:n,posinset:r,setsize:i,status:a,ignored:s,isSelected:c,isOpen:l,isCut:u,isDropTarget:d,isRenaming:f,isFocused:p,chatEnabled:m,actions:h}=e,{openMenu:g}=h.current;return(0,o.jsxs)(`div`,{role:`treeitem`,"aria-level":n+1,"aria-posinset":r,"aria-setsize":i,"aria-selected":c,...t.isDir?{"aria-expanded":l}:{},tabIndex:p?0:-1,onFocus:()=>h.current.focusPath(t.path),onKeyDown:e=>h.current.keyDown(t,e),className:[`rvs-node`,c?`selected`:``,u?`cut`:``,d?`drop-target`:``,p?`focused`:``].filter(Boolean).join(` `),style:{...uW,paddingLeft:8+n*14},title:t.path,"data-rvs-path":t.path,"data-rvs-dir":t.isDir?`1`:`0`,draggable:!0,onClick:e=>h.current.select(t,e),onDoubleClick:()=>h.current.openFile(t),onMouseEnter:()=>{t.isDir&&h.current.hoverDir(t.path)},onMouseLeave:()=>h.current.hoverDir(void 0),onPointerDown:e=>{e.button===2&&g(e,t)},onContextMenu:e=>{h.current.contextMenu(e,t)},onDragStart:e=>{h.current.startDrag(t),e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,t.path)},onDragOver:e=>{h.current.dragOver(t,e)},onDragLeave:()=>{h.current.dragLeave(t)},onDrop:e=>{h.current.dropOn(t,e)},children:[(0,o.jsx)(`span`,{className:`rvs-node-icon`,children:t.isDir?(0,o.jsx)(Ys,{path:t.path,open:l,size:16}):(0,o.jsx)(Js,{path:t.path,size:16})}),f?(0,o.jsx)(TW,{initial:t.name,onCommit:e=>{h.current.commitRename(t,e)},onCancel:()=>h.current.cancelRename()}):(0,o.jsx)(`span`,{className:`rvs-node-name ${a===void 0?``:`rvs-git-${nc(a)}`}`,style:s&&a===void 0?{opacity:.5}:void 0,children:t.name}),a!==void 0&&(0,o.jsx)(`span`,{className:`rvs-git-letter rvs-letter-${nc(a)}`,children:rc(a)}),t.isSymlink&&(0,o.jsx)(`span`,{className:`rvs-hit-dir`,title:e.symlinkTitle,children:`↩`}),(0,o.jsx)(`span`,{className:`rvs-node-actions`,children:(0,o.jsx)(`button`,{type:`button`,className:`rvs-hbtn`,title:e.referenceTitle,disabled:!m,onClick:e=>{e.stopPropagation(),h.current.reference(t)},children:`@`})})]})});function CW(e){let t=pl(),{t:n,alias:r,root:a,repoRoot:s,marks:c}=t,l=ce()?.state===`error`;(0,i.useEffect)(()=>{t.ready&&ie(t.hosts.map(e=>e.alias))},[t.ready,t.hosts]);let u=t.ctx,[d,f]=(0,i.useState)({}),p=(0,i.useRef)({}),m=(0,i.useRef)(!0),h=(0,i.useRef)(void 0),[g,_]=(0,i.useState)(new Set),[v,y]=(0,i.useState)(new Set),[b,x]=(0,i.useState)(new Set),[S,C]=(0,i.useState)(void 0),[w,T]=(0,i.useState)(void 0),[E,D]=(0,i.useState)(void 0),[O,k]=(0,i.useState)(void 0),[j,M]=(0,i.useState)(void 0),[N,ee]=(0,i.useState)(void 0),[P,F]=(0,i.useState)(!1),[I,te]=(0,i.useState)(void 0),[L,R]=(0,i.useState)(void 0),ne=(0,i.useRef)([]),z=(0,i.useRef)(``),re=(0,i.useRef)(null),ae=(0,i.useRef)(null),oe=(0,i.useRef)(null),se=(0,i.useRef)(null),le=(0,i.useRef)([]),ue=(0,i.useCallback)(e=>{let t=le.current;for(let n=0;n<t.length;n+=1){let r=t[n];if(r!==void 0&&r.kind===`entry`&&r.entry.path===e)return n}return-1},[]),de=(0,i.useCallback)(()=>{let e=oe.current,t=se.current;if(e===null)return{header:0,viewport:0,scrollTop:0};let n=e.scrollTop,r=e.clientHeight;if(t===null)return{header:0,viewport:r,scrollTop:n};let i=t.getBoundingClientRect().top-e.getBoundingClientRect().top+n;return{header:Math.max(0,i),viewport:r,scrollTop:n}},[]),fe=(0,i.useCallback)(e=>{let t=oe.current;if(t===null||e<0)return;let{header:n,viewport:r}=de(),i=Math.max(0,r-n),a=Math.max(0,n+e*28-Math.floor(i/3));Math.abs(a-t.scrollTop)<1||(t.scrollTop=a)},[de]),pe=(0,i.useCallback)(e=>{let t=oe.current;if(t===null||e<0)return;let{header:n,viewport:r}=de(),i=r-n;if(i<=0)return;let a=Math.max(0,le.current.length*28-i),o=Math.max(0,Math.min(t.scrollTop-n,a)),s=e*28,c=s+28,l=t.scrollTop;s<o?l=n+Math.max(0,s-28):c>o+i&&(l=n+Math.min(a,c-i+28)),!(Math.abs(l-t.scrollTop)<1)&&(t.scrollTop=Math.max(0,l))},[de]),me=(0,i.useRef)(void 0),he=(0,i.useRef)(void 0),ge=(0,i.useRef)(!1),_e=(0,i.useRef)(v);_e.current=v;let ve=(0,i.useRef)(()=>void 0),B=(0,i.useRef)(void 0);B.current===void 0&&(B.current=LU(e=>ve.current(e),{set:(e,t)=>window.setTimeout(e,t),clear:e=>window.clearTimeout(e)}));let ye=(0,i.useRef)(0),be=Sc(),xe=sR(t.ctx),Se=t.workspace===void 0?void 0:t.aliasPaths[t.workspace.id],Ce=xe.sessionId!==void 0&&xe.sessionWorkspacePath!==void 0&&Se!==void 0&&hI(xe.sessionWorkspacePath,Se),we=(0,i.useRef)(t.revision);we.current=t.revision;let Te=(0,i.useRef)(r),Ee=(0,i.useMemo)(()=>new RU(e=>JU(r,e),e=>V.fileOp.list(r,e),(e,t)=>{m.current&&Te.current===r&&f(n=>pW(n,e,t))}),[r]),De=(0,i.useCallback)(async(e,t=!1,n=!1)=>{if(r===``||l)return!1;let i=JU(r,e);_(e=>{let t=new Set(e);return t.add(i),t});let a=!1;try{await Ee.request(e,we.current,t),a=!0}catch(e){!n&&!A(e)&&H(e instanceof Error?e.message:String(e),!0)}finally{_(e=>{let t=new Set(e);return t.delete(i),t})}return a},[r,Ee,l]),Oe=(0,i.useCallback)(e=>{if(r===``||l)return;let t=JU(r,e);p.current[t]===void 0&&(Ee.busy(e)||Ee.request(e,we.current).catch(()=>void 0))},[r,Ee,l]),ke=e=>{h.current!==void 0&&(window.clearTimeout(h.current),h.current=void 0),e!==void 0&&(h.current=window.setTimeout(()=>{h.current=void 0,Oe(e)},150))};(0,i.useEffect)(()=>{let e=t.revealRequest;if(e===void 0||!YU(ye.current,e.id))return;ye.current=e.id;let n=a.replace(/\/+$/,``),r=e.path.replace(/\/+$/,``);if(r!==n&&!r.startsWith(`${n}/`))return;let i=[],o=n;for(let e of r.slice(n.length).split(`/`))e!==``&&(o=`${o}/${e}`,i.push(o));for(let e of i)De(e);i.length>0&&y(e=>{let t=new Set(e);for(let e of i)t.add(e);return t});let s=0,c=window.setInterval(()=>{s+=1;let e=xW(r);if(e!==null){window.clearInterval(c),e.scrollIntoView({block:`center`});return}let t=ue(r);t>=0&&fe(t),s>20&&window.clearInterval(c)},150);return()=>window.clearInterval(c)},[t.revealRequest,a,De,ue,fe]);let Ae=t.revision;(0,i.useEffect)(()=>{Te.current=r},[r]);let je=(0,i.useRef)(``),Me=(0,i.useRef)(Ae);(0,i.useEffect)(()=>{if(a===``||e.visible===!1)return;let t=je.current!==JU(r,a);if(!(!t&&Ae===Me.current)){je.current=JU(r,a),Me.current=Ae,t&&y(new Set([a]));for(let e of new Set(t?[a]:[a,...v]))De(e,!0)}},[Ae,a,r,e.visible,De]),(0,i.useEffect)(()=>{let e=new Set;for(let t of v)e.add(JU(r,t));f(t=>mW(t,e))},[v,r,d]),(0,i.useEffect)(()=>{if(a===``||v.size<=20)return;let t=hW({root:a,alias:r,listings:d,expanded:v,visible:t=>e.showHidden||!t.name.startsWith(`.`)}),n=[];for(let e of v)e!==a&&!t.has(JU(r,e))&&n.push(e);if(n.length<=20)return;let i=new Set(n.slice(0,n.length-20));y(e=>{let t;for(let n of i)e.has(n)&&(t===void 0&&(t=new Set(e)),t.delete(n));return t??e})},[a,r,d,v,e.showHidden]),(0,i.useEffect)(()=>{p.current=d},[d]),(0,i.useEffect)(()=>(m.current=!0,()=>{m.current=!1,B.current?.reset(),h.current!==void 0&&window.clearTimeout(h.current)}),[]),(0,i.useEffect)(()=>{B.current?.reset()},[r,a]);let Ne=(0,i.useMemo)(()=>{let t=new Map;return n=>{if(t.has(n))return t.get(n);let i=d[JU(r,n)],a;return i!==void 0&&(a=[...e.showHidden?i:i.filter(e=>!e.name.startsWith(`.`))].sort((e,t)=>e.isDir===t.isDir?dW.compare(e.name,t.name):e.isDir?-1:1)),t.set(n,a),a}},[d,r,e.showHidden]),Pe=(0,i.useCallback)((e,t=[])=>{for(let n of Ne(e)??[])t.push(n.path),n.isDir&&v.has(n.path)&&Pe(n.path,t);return t},[Ne,v]),Fe=e=>{if(!e.isDir)return;let t=v.has(e.path);y(n=>{let r=new Set(n);return t?r.delete(e.path):r.add(e.path),r}),t||De(e.path)};ve.current=(0,i.useCallback)(e=>{e===``||l||(y(t=>{if(t.has(e))return t;let n=new Set(t);return n.add(e),n}),De(e,!0,!0).then(t=>{t||p.current[JU(r,e)]===void 0&&y(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n})}))},[r,l,De]);let Ie=(0,i.useCallback)(e=>{if(e.isDir){Fe(e);return}if(tc(e.path)){t.openFile(e.path);return}let n=_l(s,e.path);if(n===``){t.openFile(e.path);return}let r=c.files.get(n),i=r===`?`,a=t.buckets.staged.find(e=>e.path===n)?.status;if(r!==void 0||a!==void 0){t.openDiff(n,a!==void 0&&(r===void 0||r===a),i);return}t.openFile(e.path)},[c,s,t]),Le=(e,t)=>{let n=t.ctrlKey||t.metaKey;if(t.shiftKey&&S!==void 0){let t=Pe(a),n=t.indexOf(S),r=t.indexOf(e.path);if(n>=0&&r>=0){let i=t.slice(Math.min(n,r),Math.max(n,r)+1);x(new Set(i)),e.isDir&&Fe(e);return}}if(n){x(t=>{let n=new Set(t);return n.has(e.path)?n.delete(e.path):n.add(e.path),n}),C(e.path),e.isDir&&Fe(e);return}x(new Set([e.path])),C(e.path),e.isDir?Fe(e):Ie(e)},Re=(0,i.useMemo)(()=>{let e=[],t=n=>{for(let r of Ne(n)??[])b.has(r.path)&&e.push(r),r.isDir&&v.has(r.path)&&t(r.path)};return t(a),e},[Ne,b,v,a]),ze=()=>{let e=Re[0];return e===void 0?a:e.isDir?e.path:e.path.split(`/`).slice(0,-1).join(`/`)||`/`},Be=(0,i.useCallback)(async e=>{for(let t of e)await De(t,!0)},[De]),Ve=(0,i.useCallback)(e=>{if(e.length===0)return;let t=t=>e.some(e=>QU(t,e));y(t=>eW(t,e)),x(t=>eW(t,e)),C(e=>e!==void 0&&t(e)?void 0:e),f(t=>nW(t,r,e)),T(e=>e!==void 0&&t(e)?void 0:e),D(e=>e!==void 0&&t(e.dir)?void 0:e),M(e=>e!==void 0&&t(e)?void 0:e),st(e=>e!==void 0&&t(e)?void 0:e),k(e=>{if(e===void 0)return e;let n=e.paths.filter(e=>!t(e));return n.length===e.paths.length?e:n.length===0?void 0:{...e,paths:n}})},[r]),He=(0,i.useCallback)((e,t)=>{let n=n=>QU(n,e)?`${t}${n.slice(e.length)}`:n;y(n=>tW(n,e,t)),x(n=>tW(n,e,t)),C(e=>e===void 0?void 0:n(e)),f(n=>rW(n,r,e,t)),T(e=>e===void 0?void 0:n(e)),D(e=>e===void 0?void 0:{...e,dir:n(e.dir)}),st(e=>e===void 0?void 0:n(e))},[r]),Ue=async e=>{if(!XU(ge.current)){H(n(`files.transferBusy`),!0);return}let i=E;if(D(void 0),i===void 0||e.trim()===``)return;let a;try{a=AU(i.dir,e)}catch(e){H(e instanceof Error?e.message:String(e),!0);return}F(!0);try{i.kind===`file`?await V.fileOp.write(r,a,``):await V.fileOp.mkdir(r,a),y(e=>new Set(e).add(i.dir)),await Be([i.dir]),await t.afterWrite(),H(`${n(`files.created`)} ${a}`)}catch(e){H(e instanceof Error?e.message:String(e),!0)}finally{F(!1)}},We=async(e,i)=>{if(T(void 0),!XU(ge.current)){H(n(`files.transferBusy`),!0);return}if(i.trim()===``||i===e.name)return;let a;try{a=AU(e.path.split(`/`).slice(0,-1).join(`/`)||`/`,i)}catch(e){H(e instanceof Error?e.message:String(e),!0);return}F(!0);try{await V.fileOp.rename(r,e.path,a),He(e.path,a),await Be([ze()]),await t.afterWrite(),H(`${n(`files.renamed`)} ${a}`)}catch(e){H(e instanceof Error?e.message:String(e),!0)}finally{F(!1)}},Ge=async e=>{if(e.length===0)return;if(!XU(ge.current)){H(n(`files.transferBusy`),!0);return}let t=e[0],i=e.length===1?t.path:`${e.length} ${n(`files.items`)}`;if(!await hc({title:n(`files.deleteTitle`),text:n(`files.deleteConfirm`).replace(`{target}`,i),danger:!0,okText:n(`files.delete`)}))return;let a=[],o=[];for(let t of e)try{FU([t.path]),a.push(t)}catch{o.push(t)}if(a.length===0&&o.length===0)return;let s=a.length===0?[]:FU(a.map(e=>e.path));if(s.length===0&&o.length===0)return;let c=s.flat(),l=c.length+o.length,u=new Map;for(let e of a)u.set(NU(e.path),e);let d=e=>u.get(NU(e)),f=[],p=new Set,m=0,h=new Set,g=[],_=[],v=!1,y=e=>{let t=NU(e);for(;;){if(p.has(t))return!0;let e=t.lastIndexOf(`/`);if(e<=0)return!1;t=t.slice(0,e)}},b=e=>f.some(t=>e===t||e.startsWith(`${t}/`)),x=e=>{R({done:m,total:l,name:e})},S=(e,t)=>{h.has(e)||(h.add(e),m+=1,x(t))},C=e=>{let t=NU(e.path);S(t,e.name),!y(t)&&(f.push(e.path),p.add(t))},w=e=>{S(e.path,e.name),!f.includes(e.path)&&f.push(e.path)},T=(e,t)=>{S(e.path,e.name),g.push(`${e.name}: ${t}`),_.push(e.path)},E=(e,t)=>{if(t===`item`){let t=d(e);x(t?.name??ic(e));return}if(t!==`ok`)return;let n=d(e);n!==void 0&&C(n)},D=async e=>{let t=new Map;e.forEach((e,n)=>t.set(n,e));let n=``,i=e=>{n=lW(n,e,e=>{let n=t.get(e.index);n!==void 0&&E(n,e.kind)})};try{await V.execStream(r,PU(e),3e5,{signal:O.signal,onData:(e,t)=>{e===`out`&&i(t)}})}catch(e){if(O.signal.aborted||qU(e)){v=!0;return}}n!==``&&i(`
7061
7113
  `);let a=[];for(let t of e){if(y(t)){S(t,d(t)?.name??ic(t));continue}let e=d(t);e!==void 0&&a.push(e)}for(let e of a){if(O.signal.aborted){v=!0;return}if(y(e.path)){S(e.path,e.name);continue}try{await V.fileOp.rm(r,e.path,e.isDir),C(e)}catch(t){T(e,t instanceof Error?t.message:String(t))}}};F(!0),ge.current=!0;let O=new AbortController;he.current=O,x(ic(c[0]??``));try{for(let e of s){if(O.signal.aborted){v=!0;break}if(await D(e),v)break}for(let e of o){if(O.signal.aborted){v=!0;break}if(b(e.path)){S(e.path,e.name);continue}x(e.name);try{await V.fileOp.rm(r,e.path,e.isDir),w(e)}catch(t){T(e,t instanceof Error?t.message:String(t))}}}catch(e){g.push(e instanceof Error?e.message:String(e))}finally{he.current=void 0,R(void 0),F(!1),ge.current=!1}Ve(f);let k=[...new Set([...f,..._].map(e=>e.split(`/`).slice(0,-1).join(`/`)||`/`))];if(await Promise.all(k.map(e=>De(e,!0))),f.length>0&&On(),f.every(e=>it(e))||Su().catch(()=>void 0),v){let e=n(`files.deleteCancelled`).replace(`{removed}`,String(f.length)).replace(`{left}`,String(Math.max(0,l-m)));H(g.length===0?e:`${e}\n${g.join(`
@@ -7066,7 +7118,7 @@ Integer Float Double Long Int32 Int64 Uint8 uint32_t int32_t uint64_t int64_t si
7066
7118
  `)+(u.length>8?`\n… (${u.length})`:``),okText:n(`files.overwrite`)}),new Promise(e=>{if(l.signal.aborted){e(!1);return}l.signal.addEventListener(`abort`,()=>e(!1),{once:!0})})])){me.current=void 0,ge.current=!1,te(void 0);return}f=!0}F(!0);let p=[],m=new Set([e]),h=0,g=!1;try{for(let e of s.dirs){if(l.signal.aborted)break;try{await V.fileOp.mkdir(r,c(e)),m.add(c(e).split(`/`).slice(0,-1).join(`/`)||`/`)}catch(t){p.push(`${e}: ${t instanceof Error?t.message:String(t)}`)}}let e=s.files.filter(e=>a.has(e.rel)).length;for(let t of s.files){if(l.signal.aborted)break;let n=a.get(t.rel);if(n===void 0){aW(`missing-blob`,{rel:t.rel,keys:[...a.keys()].slice(0,5)});continue}aW(`upload-file`,{rel:t.rel,blobSize:n.size,overwrite:f});let i=n.size>0?n.size:t.size>0?t.size:0;te({phase:`uploading`,done:h,total:e,name:t.rel,loaded:0,size:i});try{await En({alias:r,path:c(t.rel),blob:n,overwrite:f,signal:l.signal,onProgress:n=>{te({phase:`uploading`,done:h,total:e,name:t.rel,loaded:n.loaded,size:n.total>0?n.total:i})}});let a=c(t.rel).split(`/`).slice(0,-1).join(`/`)||`/`;m.add(a)}catch(e){if(l.signal.aborted){g=!0;break}p.push(`${t.rel}: ${e instanceof Error?e.message:String(e)}`)}h+=1}}finally{g||=l.signal.aborted,me.current=void 0,ge.current=!1,te(void 0),F(!1)}if(await Be([...m]),t.afterWrite(),g){H(`${n(`files.uploadAbort`)}: ${h}/${s.files.length}`,!1);return}p.length>0?H(p.join(`
7067
7119
  `),!0):H(`${n(`files.uploaded`)} ${s.files.length}`)},Ye=(0,i.useCallback)(async(e,t)=>{te({phase:`preparing`,done:0,total:0,name:``,loaded:0,size:0});let r=[...t.files],i=async()=>{if(r.length===0){te(void 0),H(`${n(`files.uploadSkipped`)} (${[...t.types].join(`,`)})`,!0);return}let i=new Map(r.map(e=>[e.name,e]));await Je(e,r.map(e=>({rel:e.name,size:e.size})),i,[])},a=[...t.items],o=[];for(let e of a){let t=e.webkitGetAsEntry?.();t!=null&&o.push(t)}if(aW(`transfer`,{entries:o.length,files:r.length}),o.length>0)try{let t=await GU(o);if(aW(`collected`,{files:t.files.length,dirs:t.dirs.length}),t.files.length>0||r.length===0){let n=new Map(t.files.map(e=>[e.rel,e.blob]));await Je(e,t.files.map(e=>({rel:e.rel,size:e.size})),n,t.dirs);return}aW(`walk-empty`,{entries:o.length})}catch(e){aW(`walk-failed`,String(e))}await i()},[r,a,Be,t,n]),Xe=e=>e!==null&&[...e.types].includes(`Files`),Ze=(e,t)=>{if(!Xe(t.dataTransfer))return;if(!XU(ge.current)){H(n(`files.transferBusy`),!0);return}t.preventDefault(),t.stopPropagation(),M(void 0),ee(void 0);let r=t.dataTransfer;Ye(e,r).catch(e=>{H(e instanceof Error?e.message:String(e),!0)})},Qe=e=>{let t=iW(e);if(t!==void 0)for(let e of document.elementsFromPoint(t.x,t.y)){let t=e.closest(`[data-rvs-path]`);if(t===null)continue;let n=t.getAttribute(`data-rvs-path`)??``;if(n!==``)return t.getAttribute(`data-rvs-dir`)===`1`?n:n.split(`/`).slice(0,-1).join(`/`)||`/`}let n=e.target,r=n instanceof Element?n.closest(`[data-rvs-path]`):null,i=r?.getAttribute(`data-rvs-path`)??``;return i===``?a:r?.getAttribute(`data-rvs-dir`)===`1`?i:i.split(`/`).slice(0,-1).join(`/`)||`/`};(0,i.useEffect)(()=>{let e=oe.current;if(e===null)return;let t=t=>{let n=iW(t);if(n===void 0)return!1;let r=e.getBoundingClientRect();return n.x>=r.left&&n.x<=r.right&&n.y>=r.top&&n.y<=r.bottom},n=e=>{e.preventDefault(),e.stopPropagation(),e.dataTransfer!==null&&(e.dataTransfer.dropEffect=`copy`)},r=e=>{let t=iW(e);if(t!==void 0)for(let e of document.elementsFromPoint(t.x,t.y)){let t=e.closest(`[data-rvs-path]`);if(t===null)continue;let n=t.getAttribute(`data-rvs-path`)??``;if(n!==``)return t.getAttribute(`data-rvs-dir`)===`1`?n:void 0}},i=e=>{let t=r(e);t!==void 0&&!_e.current.has(t)?B.current?.hover(t):B.current?.reset()},o=e=>{!Xe(e.dataTransfer)||!t(e)||(n(e),M(a),ee(a),i(e))},s=e=>{!Xe(e.dataTransfer)||!t(e)||(n(e),M(a),ee(a),i(e))},c=e=>{if(B.current?.reset(),aW(`drop`,{types:e.dataTransfer===null?null:[...e.dataTransfer.types],overPane:t(e),target:e.target?.className?.toString().slice(0,40)??null,items:e.dataTransfer===null?0:e.dataTransfer.items.length,files:e.dataTransfer===null?0:e.dataTransfer.files.length}),!Xe(e.dataTransfer)||!t(e))return;let r=e.dataTransfer;if(r===null)return;n(e);let i=Qe(e);M(void 0),ee(void 0),Ye(i,r).catch(e=>{H(e instanceof Error?e.message:String(e),!0)})},l=e=>{t(e)&&e.relatedTarget!==null||(B.current?.reset(),M(void 0),ee(void 0))},u=()=>{B.current?.reset(),ne.current=[],M(void 0),ee(void 0)};return window.addEventListener(`dragenter`,o,!0),window.addEventListener(`dragover`,s,!0),window.addEventListener(`drop`,c,!0),window.addEventListener(`dragleave`,l,!0),window.addEventListener(`dragend`,u,!0),()=>{B.current?.reset(),window.removeEventListener(`dragenter`,o,!0),window.removeEventListener(`dragover`,s,!0),window.removeEventListener(`drop`,c,!0),window.removeEventListener(`dragleave`,l,!0),window.removeEventListener(`dragend`,u,!0)}},[a,r,Ye]);let $e=e=>{uH(r,e.path,{name:e.name,directory:e.isDir})},et=(0,i.useCallback)((e,t)=>{e!==``&&e!==a&&!v.has(e)&&(y(t=>new Set(t).add(e)),De(e)),D({dir:e,kind:t})},[a,v,De]),tt=(i,o)=>{i.preventDefault(),i.stopPropagation();let c=ZU(I!==void 0);o!==void 0&&!b.has(o.path)&&(x(new Set([o.path])),C(o.path));let l=o!==void 0&&b.has(o.path)&&b.size>1,d=o===void 0?[]:l?Re:[o],f=a;o!==void 0&&(f=o.isDir?o.path:o.path.split(`/`).slice(0,-1).join(`/`)||`/`);let p=[{label:n(`files.newFile`),onSelect:()=>et(f,`file`),disabled:c},{label:n(`files.newFolder`),onSelect:()=>et(f,`folder`),disabled:c},{label:n(`files.uploadFile`),onSelect:()=>{z.current=f,re.current?.click()},disabled:c},{label:n(`files.uploadFolder`),onSelect:()=>{z.current=f,ae.current?.click()},disabled:c},{label:n(`files.pasteHere`),onSelect:()=>{Ke(f)},disabled:O===void 0||c,hint:O===void 0?void 0:`${O.paths.length}`}];o!==void 0&&(p.push({label:n(`files.open`),onSelect:()=>Ie(o),separated:!0}),o.isDir||p.push({label:n(`files.openInFloat`),onSelect:()=>{t.openInFloatEditor(o.path)},disabled:!t.floatAvailable}),!o.isDir&&tc(o.path)&&p.push({label:n(`files.openAsText`),onSelect:()=>t.openFile(o.path)}),p.push({label:n(`files.findInFolder`),onSelect:()=>t.requestSearch({mode:`content`,scope:f})}),o.isDir&&p.push({label:n(`files.openInTerminal`),onSelect:()=>{t.openTerminalAt(f)}}),o.isDir||p.push({label:n(`files.searchNameHere`),onSelect:()=>t.requestSearch({mode:`name`,scope:f})}),d.length===1&&p.push({label:n(`files.rename`),onSelect:()=>T(o.path)}),p.push({label:n(`files.copy`),onSelect:()=>{k({paths:d.map(e=>e.path),mode:`copy`}),H(n(`files.copiedClipboard`))}}),p.push({label:n(`files.cut`),onSelect:()=>{k({paths:d.map(e=>e.path),mode:`cut`}),H(n(`files.cutClipboard`))}}),p.push({label:n(`files.delete`)+(d.length>1?` (${d.length})`:``),onSelect:()=>{Ge(d)},danger:!0,disabled:c}),p.push({label:n(`files.copyRel`),onSelect:()=>{Cc(d.map(e=>_l(s,e.path)||e.path).join(`
7068
7120
  `)),H(n(`files.copiedClipboard`))},separated:!0}),p.push({label:n(`files.copyAbs`),onSelect:()=>{Cc(d.map(e=>e.path).join(`
7069
- `)),H(n(`files.copiedClipboard`))}}),p.push({label:n(`files.download`)+(d.length>1?` (${d.length})`:``),onSelect:()=>{if(d.length===1){$e(o);return}if(d.length>100){H(n(`downloads.tooMany`),!0);return}dH(r,d.map(e=>e.path))}}),p.push({label:n(`files.referenceFile`),onSelect:()=>{if(xe.sessionId!==void 0)for(let e of d)gI(u,xe.sessionId,s??a,e.path,e.isDir)},disabled:!Ce,separated:!0})),p.push({label:e.showHidden?n(`files.hideHidden`):n(`files.showHidden`),onSelect:e.onToggleHidden,separated:!0}),p.push({label:n(`files.collapseAll`),onSelect:()=>y(new Set([a]))}),p.push({label:n(`files.refresh`),onSelect:()=>{De(a,!0)}}),be.open(i.clientX,i.clientY,p)},nt=(0,i.useCallback)(e=>{let t=_l(s,e.path);if(t!==``)return e.isDir?c.dirs.get(t):c.files.get(t)},[s,c]),rt=(0,i.useCallback)(e=>{let t=_l(s,e.path);return t===``?!1:e.isDir?c.ignoredDirs.has(t):c.ignored.has(t)},[s,c]),it=(0,i.useCallback)(e=>{let t=_l(s,e);if(t===``)return!1;if(c.ignored.has(t)||c.ignoredDirs.has(t))return!0;let n=t.split(`/`),r=``;for(let e=0;e<n.length-1;e+=1)if(r=r===``?n[e]:`${r}/${n[e]}`,c.ignoredDirs.has(r))return!0;return!1},[s,c]),at=(e,t)=>{e.preventDefault(),be.menu===void 0&&tt(e,t)},[ot,st]=(0,i.useState)(void 0),ct=e=>{if(e===void 0)return;st(e);let t=0,n=()=>{let r=xW(e);if(r!==null){r.focus();return}let i=ue(e);i>=0&&pe(i),t+=1,t<16&&requestAnimationFrame(n)};requestAnimationFrame(n)},lt=(e,t)=>{let n=le.current,r=t.key;if(r===`ArrowDown`||r===`ArrowUp`){t.preventDefault(),ct(vW(n,e.path,r===`ArrowDown`?`down`:`up`));return}if(r===`ArrowRight`&&e.isDir){if(t.preventDefault(),!v.has(e.path)){Fe(e),ct(e.path);return}ct(vW(n,e.path,`child`)??e.path);return}if(r===`ArrowLeft`){if(t.preventDefault(),e.isDir&&v.has(e.path)){Fe(e),ct(e.path);return}ct(vW(n,e.path,`parent`)??e.path);return}if(r===`Enter`){t.preventDefault(),Ie(e);return}if(r===` `||r===`Spacebar`){t.preventDefault(),x(new Set([e.path])),C(e.path);return}if(r===`Home`||r===`End`){t.preventDefault();let e=n.filter(e=>e.kind===`entry`),i=r===`Home`?e[0]:e[e.length-1];i!==void 0&&ct(i.entry.path);return}if(r===`F10`&&t.shiftKey||r===`ContextMenu`){t.preventDefault();let n=xW(e.path)?.getBoundingClientRect();tt({preventDefault:()=>void 0,stopPropagation:()=>void 0,clientX:n===void 0?0:n.left,clientY:n===void 0?0:n.bottom},e)}},ut=(0,i.useRef)({select:()=>void 0,openFile:()=>void 0,hoverDir:()=>void 0,openMenu:()=>void 0,contextMenu:()=>void 0,startDrag:()=>void 0,dragOver:()=>void 0,dragLeave:()=>void 0,dropOn:()=>void 0,commitRename:()=>void 0,cancelRename:()=>void 0,reference:()=>void 0,keyDown:()=>void 0,focusPath:()=>void 0});ut.current={select:Le,openFile:e=>{let n=gW(e);n!==void 0&&t.openFile(n)},hoverDir:ke,openMenu:tt,contextMenu:at,startDrag:e=>{ne.current=b.has(e.path)?[...b]:[e.path]},dragOver:(e,t)=>{if(Xe(t.dataTransfer)){t.preventDefault(),t.stopPropagation(),M(e.path),ee(e.isDir?e.path:e.path.split(`/`).slice(0,-1).join(`/`)||`/`);return}let n=ne.current[0];if(e.isDir&&n!==void 0&&t.dataTransfer!==null&&[...t.dataTransfer.types].includes(`text/plain`)&&e.path!==n&&!e.path.startsWith(`${n}/`)){t.preventDefault(),M(e.path),v.has(e.path)?B.current?.reset():B.current?.hover(e.path);return}B.current?.reset()},dragLeave:e=>{B.current?.leave(e.path),M(t=>t===e.path?void 0:t)},dropOn:(e,t)=>{if(B.current?.reset(),Xe(t.dataTransfer)){let n=e.isDir?e.path:e.path.split(`/`).slice(0,-1).join(`/`)||`/`;Ze(n,t);return}e.isDir&&qe(e.path,t)},commitRename:(e,t)=>{We(e,t)},cancelRename:()=>T(void 0),reference:e=>{xe.sessionId!==void 0&&gI(u,xe.sessionId,s??a,e.path,e.isDir)},keyDown:lt,focusPath:e=>{st(e)}};let dt=(0,i.useMemo)(()=>_W({root:a,rowsOf:Ne,isExpanded:e=>v.has(e),...E===void 0?{}:{creating:E},placeholderOf:e=>l?`offline`:g.has(JU(r,e))?`loading`:void 0}),[a,Ne,v,E,l,g,r]);le.current=dt;let[ft,pt]=(0,i.useState)({from:0,to:40,before:0,after:0}),mt=(0,i.useMemo)(()=>dt.slice(ft.from,ft.to),[dt,ft.from,ft.to]),ht=(0,i.useCallback)(()=>{let{header:e,viewport:t,scrollTop:n}=de(),r=fW(le.current.length,n,t,e);pt(e=>e.from===r.from&&e.to===r.to&&e.before===r.before&&e.after===r.after?e:r)},[de]);(0,i.useLayoutEffect)(()=>{ht()}),(0,i.useEffect)(()=>{let e=oe.current;if(e===null||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(()=>ht());return t.observe(e),()=>t.disconnect()},[ht]);let gt=``;w===void 0?E===void 0?ot!==void 0&&(gt=`focus:${ot}`):gt=`create:${E.dir}`:gt=`rename:${w}`;let _t=(0,i.useRef)(``);(0,i.useEffect)(()=>{if(gt===``){_t.current=``;return}if(_t.current===gt)return;_t.current=gt;let e=le.current,t=-1;w===void 0?E===void 0?ot!==void 0&&(t=e.findIndex(e=>e.kind===`entry`&&e.entry.path===ot)):t=e.findIndex(e=>e.kind===`create`&&e.dir===E.dir):t=e.findIndex(e=>e.kind===`entry`&&e.entry.path===w),!(t<0||t>=ft.from&&t<ft.to)&&pe(t)},[gt,w,E,ot,dt,ft,pe]),(0,i.useEffect)(()=>{let e=yW(dt,ot);e!==ot&&st(e)},[dt,ot]);let vt=(e,t)=>{let i=Ne(e),a=JU(r,e);if(i===void 0&&l)return(0,o.jsx)(`div`,{className:`rvs-empty`,style:{paddingLeft:12+t*14},children:n(`files.offline`)});if(i===void 0&&g.has(a))return(0,o.jsx)(`div`,{className:`rvs-empty`,style:{paddingLeft:12+t*14},children:n(`common.loading`)});let s=n(Ce?`files.referenceFile`:`files.refDisabled`),c=n(`files.symlink`),u=O!==void 0&&O.mode===`cut`?new Set(O.paths):void 0,d=mt.some(e=>e.kind===`entry`&&e.entry.path===ot)?ot:mt.find(e=>e.kind===`entry`)?.entry.path;return(0,o.jsxs)(o.Fragment,{children:[ft.before>0&&(0,o.jsx)(`div`,{"aria-hidden":`true`,style:{height:ft.before}}),mt.map((e,t)=>e.kind===`create`?(0,o.jsx)(wW,{depth:e.depth,kind:e.createKind,onCommit:e=>{Ue(e)},onCancel:()=>D(void 0),fileIcon:(0,o.jsx)(Js,{path:`untitled`,size:16}),folderIcon:(0,o.jsx)(Ys,{path:`name`,open:!1,size:16}),t:n},`create:${e.dir}`):e.kind===`pending`?(0,o.jsx)(`div`,{className:`rvs-empty`,style:{...uW,paddingLeft:12+e.depth*14},children:e.reason===`offline`?n(`files.offline`):n(`common.loading`)},`pending:${e.dir}`):(0,o.jsx)(SW,{entry:e.entry,depth:e.depth,posinset:ft.from+t+1,setsize:dt.length,status:nt(e.entry),ignored:rt(e.entry),isSelected:b.has(e.entry.path),isOpen:v.has(e.entry.path),isCut:u!==void 0&&u.has(e.entry.path),isDropTarget:j===e.entry.path,isRenaming:w===e.entry.path,isFocused:d===e.entry.path,chatEnabled:Ce,referenceTitle:s,symlinkTitle:c,actions:ut},e.entry.path)),ft.after>0&&(0,o.jsx)(`div`,{"aria-hidden":`true`,style:{height:ft.after}})]})},yt=a===``?``:a;return(0,o.jsxs)(`div`,{className:`rvs-pane grow`,children:[(0,o.jsxs)(`div`,{className:`rvs-header`,children:[(0,o.jsx)(`span`,{className:`rvs-title`,children:n(`tab.files`)}),(0,o.jsx)(U,{title:n(`files.newFile`),onClick:()=>et(a,`file`),disabled:I!==void 0,children:(0,o.jsx)(gs,{size:14})}),(0,o.jsx)(U,{title:n(`files.newFolder`),onClick:()=>et(a,`folder`),disabled:I!==void 0,children:(0,o.jsx)(_s,{size:14})}),(0,o.jsx)(U,{title:n(`files.collapseAll`),onClick:()=>y(new Set([a])),children:(0,o.jsx)(os,{size:13})}),(0,o.jsx)(U,{title:n(`files.uploadFile`),onClick:()=>{z.current=a,re.current?.click()},disabled:r===``||a===``||I!==void 0,children:(0,o.jsx)(Hs,{size:14})}),(0,o.jsx)(U,{title:n(`files.refresh`),onClick:()=>{De(a,!0)},disabled:P||g.has(JU(r,a)),children:(0,o.jsx)(hs,{size:14})}),(0,o.jsx)(U,{title:e.showHidden?n(`files.hideHidden`):n(`files.showHidden`),onClick:e.onToggleHidden,children:(0,o.jsx)(ds,{size:13})})]}),I!==void 0&&(0,o.jsxs)(`div`,{className:`rvs-upload-bar`,children:[(0,o.jsx)(Tc,{}),(0,o.jsx)(`span`,{className:`rvs-upload-text`,title:`${I.done+1}/${I.total} · ${I.name}`,children:sW(n,I)}),(0,o.jsx)(`button`,{type:`button`,className:`rvs-hbtn`,title:n(`files.uploadAbort`),onClick:()=>me.current?.abort(),children:`✕`})]}),L!==void 0&&(0,o.jsxs)(`div`,{className:`rvs-upload-bar`,children:[(0,o.jsx)(Tc,{}),(0,o.jsx)(`span`,{className:`rvs-upload-text`,title:L.name,children:cW(n,L)}),(0,o.jsx)(`button`,{type:`button`,className:`rvs-hbtn`,title:n(`files.deleteCancel`),onClick:()=>he.current?.abort(),children:`✕`})]}),(0,o.jsx)(`input`,{ref:re,type:`file`,multiple:!0,style:{display:`none`},onChange:e=>{let t=[...e.target.files??[]];if(e.target.value=``,!XU(ge.current))return;let n=z.current||a,r=new Map(t.map(e=>[e.name,e]));Je(n,t.map(e=>({rel:e.name,size:e.size})),r,[]).catch(e=>{H(e instanceof Error?e.message:String(e),!0)})}}),(0,o.jsx)(`input`,{ref:e=>{ae.current=e,e!==null&&e.setAttribute(`webkitdirectory`,``)},type:`file`,multiple:!0,style:{display:`none`},onChange:e=>{let t=[...e.target.files??[]];if(e.target.value=``,!XU(ge.current))return;let n=z.current||a,r=[],i=new Map,o=new Set;for(let e of t){let t=e.webkitRelativePath,n=t!==void 0&&t!==``?t:e.name;r.push({rel:n,size:e.size}),i.set(n,e);let a=n.split(`/`);a.pop();let s=``;for(let e of a)s=s===``?e:`${s}/${e}`,o.add(s)}Je(n,r,i,[...o])}}),(0,o.jsx)(`div`,{ref:oe,className:`rvs-scroll`,onClick:e=>{e.target===e.currentTarget&&x(new Set)},onPointerDown:e=>{e.button===2&&e.target===e.currentTarget&&tt(e,void 0)},onContextMenu:e=>{e.target===e.currentTarget&&(e.preventDefault(),be.menu===void 0&&tt(e,void 0))},onDragOver:e=>{Xe(e.dataTransfer)&&(e.preventDefault(),M(a),ee(a))},onDragLeave:e=>{e.target===e.currentTarget&&(M(void 0),ee(void 0))},onDrop:e=>Ze(a,e),onScroll:()=>ht(),children:(0,o.jsxs)(`div`,{className:`rvs-tree`,role:`tree`,"aria-label":n(`tab.files`),"aria-multiselectable":`true`,onPointerDown:e=>{e.button===2&&tt(e,void 0)},onContextMenu:e=>{e.preventDefault(),be.menu===void 0&&tt(e,void 0)},children:[(0,o.jsx)(`div`,{className:`rvs-empty`,style:{textAlign:`left`,padding:`2px 8px`,direction:`rtl`,unicodeBidi:`plaintext`},title:yt,children:(0,o.jsx)(`code`,{style:{fontSize:11},children:yt})}),j!==void 0&&N!==void 0&&(0,o.jsx)(`div`,{className:`rvs-drop-hint`,title:j,children:`${n(`files.dropToUpload`)} → ${j.split(`/`).slice(-1)[0]||j}`}),(0,o.jsx)(`div`,{ref:se,"aria-hidden":`true`,style:{height:0}}),a!==``&&vt(a,0),a===``&&(0,o.jsx)(`div`,{className:`rvs-empty`,children:n(`files.selectWorkspace`)})]})}),be.menu!==void 0&&(0,o.jsx)(xc,{x:be.menu.x,y:be.menu.y,entries:be.menu.entries,onClose:be.close})]})}function wW(e){return(0,o.jsxs)(`div`,{className:`rvs-node`,style:{...uW,paddingLeft:8+e.depth*14},onClick:e=>e.stopPropagation(),children:[(0,o.jsx)(`span`,{className:`rvs-node-icon`,children:e.kind===`folder`?e.folderIcon:e.fileIcon}),(0,o.jsx)(TW,{initial:``,placeholder:e.kind===`folder`?e.t(`files.folderPlaceholder`):e.t(`files.filePlaceholder`),onCommit:e.onCommit,onCancel:e.onCancel})]})}function TW(e){let[t,n]=(0,i.useState)(e.initial),r=(0,i.useRef)(null),a=(0,i.useRef)(!1);(0,i.useEffect)(()=>{let t=r.current;if(t===null)return;t.focus();let n=e.initial.lastIndexOf(`.`);n>0?t.setSelectionRange(0,n):t.select()},[e.initial]);let s=()=>{a.current||(a.current=!0,e.onCommit(t))},c=()=>{a.current||(a.current=!0,e.onCancel())};return(0,o.jsx)(`input`,{ref:r,className:`rvs-rename-input`,value:t,placeholder:e.placeholder,spellCheck:!1,onClick:e=>e.stopPropagation(),onChange:e=>n(e.target.value),onKeyDown:e=>{e.stopPropagation(),!(e.nativeEvent.isComposing===!0||e.keyCode===229)&&(e.key===`Enter`?(e.preventDefault(),s()):e.key===`Escape`&&(e.preventDefault(),c()))},onBlur:()=>{t.trim()===``?c():s()}})}let EW=[`.git`,`node_modules`,`.venv`,`venv`,`__pycache__`,`.cache`,`dist`,`build`,`out`,`target`,`.next`,`.idea`,`.gradle`],DW={regex:!1,caseSensitive:!1,wholeWord:!1,maxResults:400,maxLineChars:500};function OW(e){if(typeof e!=`string`)throw Error(`invalid query`);if(/[\0\n\r]/.test(e))throw Error(`query contains control characters`);let t=e.trim();if(t===``)throw Error(`empty query`);if(t.length>256)throw Error(`query too long`);return t}function kW(e,t,n=DW){let r=OW(t),i=Math.min(Math.max(Math.floor(n.maxResults),1),2e3),a=Math.min(Math.max(Math.floor(n.maxLineChars),80),4e3),o=[...EW,...n.prune??[]],s=[`grep -rIn --null --binary-files=without-match`,...o.map(e=>`--exclude-dir=${B(e)}`),n.caseSensitive?``:`-i`,n.wholeWord?`-w`:``,n.regex?`-E`:`-F`,`-e ${B(r)}`,`--`,B(ye(e))].filter(e=>e!==``),c=[`rg -n --no-heading --null --color=never --with-filename --hidden`,...o.map(e=>`-g ${B(`!**/${e}/**`)}`),n.caseSensitive?``:`-i`,n.wholeWord?`-w`:``,n.regex?``:`-F`,`-e ${B(r)}`,B(ye(e))].filter(e=>e!==``),l=`${s.join(` `)} 2>/dev/null`;return`if command -v rg >/dev/null 2>&1; then ${`${c.join(` `)} 2>/dev/null`}; else ${l}; fi | cut -c1-${a} | head -n ${i+1}`}function AW(e,t=DW.maxResults,n=DW.maxLineChars){let r=[],i=Math.max(1,Math.floor(t)),a=Math.max(1,Math.floor(n)),o=!1,s=!1;for(let t of e.split(`
7121
+ `)),H(n(`files.copiedClipboard`))}}),p.push({label:n(`files.download`)+(d.length>1?` (${d.length})`:``),onSelect:()=>{if(d.length===1){$e(o);return}if(d.length>100){H(n(`downloads.tooMany`),!0);return}dH(r,d.map(e=>e.path))}}),p.push({label:n(`files.referenceFile`),onSelect:()=>{if(xe.sessionId!==void 0)for(let e of d)gI(u,xe.sessionId,a,e.path,e.isDir)},disabled:!Ce,separated:!0})),p.push({label:e.showHidden?n(`files.hideHidden`):n(`files.showHidden`),onSelect:e.onToggleHidden,separated:!0}),p.push({label:n(`files.collapseAll`),onSelect:()=>y(new Set([a]))}),p.push({label:n(`files.refresh`),onSelect:()=>{De(a,!0)}}),be.open(i.clientX,i.clientY,p)},nt=(0,i.useCallback)(e=>{let t=_l(s,e.path);if(t!==``)return e.isDir?c.dirs.get(t):c.files.get(t)},[s,c]),rt=(0,i.useCallback)(e=>{let t=_l(s,e.path);return t===``?!1:e.isDir?c.ignoredDirs.has(t):c.ignored.has(t)},[s,c]),it=(0,i.useCallback)(e=>{let t=_l(s,e);if(t===``)return!1;if(c.ignored.has(t)||c.ignoredDirs.has(t))return!0;let n=t.split(`/`),r=``;for(let e=0;e<n.length-1;e+=1)if(r=r===``?n[e]:`${r}/${n[e]}`,c.ignoredDirs.has(r))return!0;return!1},[s,c]),at=(e,t)=>{e.preventDefault(),be.menu===void 0&&tt(e,t)},[ot,st]=(0,i.useState)(void 0),ct=e=>{if(e===void 0)return;st(e);let t=0,n=()=>{let r=xW(e);if(r!==null){r.focus();return}let i=ue(e);i>=0&&pe(i),t+=1,t<16&&requestAnimationFrame(n)};requestAnimationFrame(n)},lt=(e,t)=>{let n=le.current,r=t.key;if(r===`ArrowDown`||r===`ArrowUp`){t.preventDefault(),ct(vW(n,e.path,r===`ArrowDown`?`down`:`up`));return}if(r===`ArrowRight`&&e.isDir){if(t.preventDefault(),!v.has(e.path)){Fe(e),ct(e.path);return}ct(vW(n,e.path,`child`)??e.path);return}if(r===`ArrowLeft`){if(t.preventDefault(),e.isDir&&v.has(e.path)){Fe(e),ct(e.path);return}ct(vW(n,e.path,`parent`)??e.path);return}if(r===`Enter`){t.preventDefault(),Ie(e);return}if(r===` `||r===`Spacebar`){t.preventDefault(),x(new Set([e.path])),C(e.path);return}if(r===`Home`||r===`End`){t.preventDefault();let e=n.filter(e=>e.kind===`entry`),i=r===`Home`?e[0]:e[e.length-1];i!==void 0&&ct(i.entry.path);return}if(r===`F10`&&t.shiftKey||r===`ContextMenu`){t.preventDefault();let n=xW(e.path)?.getBoundingClientRect();tt({preventDefault:()=>void 0,stopPropagation:()=>void 0,clientX:n===void 0?0:n.left,clientY:n===void 0?0:n.bottom},e)}},ut=(0,i.useRef)({select:()=>void 0,openFile:()=>void 0,hoverDir:()=>void 0,openMenu:()=>void 0,contextMenu:()=>void 0,startDrag:()=>void 0,dragOver:()=>void 0,dragLeave:()=>void 0,dropOn:()=>void 0,commitRename:()=>void 0,cancelRename:()=>void 0,reference:()=>void 0,keyDown:()=>void 0,focusPath:()=>void 0});ut.current={select:Le,openFile:e=>{let n=gW(e);n!==void 0&&t.openFile(n)},hoverDir:ke,openMenu:tt,contextMenu:at,startDrag:e=>{ne.current=b.has(e.path)?[...b]:[e.path]},dragOver:(e,t)=>{if(Xe(t.dataTransfer)){t.preventDefault(),t.stopPropagation(),M(e.path),ee(e.isDir?e.path:e.path.split(`/`).slice(0,-1).join(`/`)||`/`);return}let n=ne.current[0];if(e.isDir&&n!==void 0&&t.dataTransfer!==null&&[...t.dataTransfer.types].includes(`text/plain`)&&e.path!==n&&!e.path.startsWith(`${n}/`)){t.preventDefault(),M(e.path),v.has(e.path)?B.current?.reset():B.current?.hover(e.path);return}B.current?.reset()},dragLeave:e=>{B.current?.leave(e.path),M(t=>t===e.path?void 0:t)},dropOn:(e,t)=>{if(B.current?.reset(),Xe(t.dataTransfer)){let n=e.isDir?e.path:e.path.split(`/`).slice(0,-1).join(`/`)||`/`;Ze(n,t);return}e.isDir&&qe(e.path,t)},commitRename:(e,t)=>{We(e,t)},cancelRename:()=>T(void 0),reference:e=>{xe.sessionId!==void 0&&gI(u,xe.sessionId,a,e.path,e.isDir)},keyDown:lt,focusPath:e=>{st(e)}};let dt=(0,i.useMemo)(()=>_W({root:a,rowsOf:Ne,isExpanded:e=>v.has(e),...E===void 0?{}:{creating:E},placeholderOf:e=>l?`offline`:g.has(JU(r,e))?`loading`:void 0}),[a,Ne,v,E,l,g,r]);le.current=dt;let[ft,pt]=(0,i.useState)({from:0,to:40,before:0,after:0}),mt=(0,i.useMemo)(()=>dt.slice(ft.from,ft.to),[dt,ft.from,ft.to]),ht=(0,i.useCallback)(()=>{let{header:e,viewport:t,scrollTop:n}=de(),r=fW(le.current.length,n,t,e);pt(e=>e.from===r.from&&e.to===r.to&&e.before===r.before&&e.after===r.after?e:r)},[de]);(0,i.useLayoutEffect)(()=>{ht()}),(0,i.useEffect)(()=>{let e=oe.current;if(e===null||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(()=>ht());return t.observe(e),()=>t.disconnect()},[ht]);let gt=``;w===void 0?E===void 0?ot!==void 0&&(gt=`focus:${ot}`):gt=`create:${E.dir}`:gt=`rename:${w}`;let _t=(0,i.useRef)(``);(0,i.useEffect)(()=>{if(gt===``){_t.current=``;return}if(_t.current===gt)return;_t.current=gt;let e=le.current,t=-1;w===void 0?E===void 0?ot!==void 0&&(t=e.findIndex(e=>e.kind===`entry`&&e.entry.path===ot)):t=e.findIndex(e=>e.kind===`create`&&e.dir===E.dir):t=e.findIndex(e=>e.kind===`entry`&&e.entry.path===w),!(t<0||t>=ft.from&&t<ft.to)&&pe(t)},[gt,w,E,ot,dt,ft,pe]),(0,i.useEffect)(()=>{let e=yW(dt,ot);e!==ot&&st(e)},[dt,ot]);let vt=(e,t)=>{let i=Ne(e),a=JU(r,e);if(i===void 0&&l)return(0,o.jsx)(`div`,{className:`rvs-empty`,style:{paddingLeft:12+t*14},children:n(`files.offline`)});if(i===void 0&&g.has(a))return(0,o.jsx)(`div`,{className:`rvs-empty`,style:{paddingLeft:12+t*14},children:n(`common.loading`)});let s=n(Ce?`files.referenceFile`:`files.refDisabled`),c=n(`files.symlink`),u=O!==void 0&&O.mode===`cut`?new Set(O.paths):void 0,d=mt.some(e=>e.kind===`entry`&&e.entry.path===ot)?ot:mt.find(e=>e.kind===`entry`)?.entry.path;return(0,o.jsxs)(o.Fragment,{children:[ft.before>0&&(0,o.jsx)(`div`,{"aria-hidden":`true`,style:{height:ft.before}}),mt.map((e,t)=>e.kind===`create`?(0,o.jsx)(wW,{depth:e.depth,kind:e.createKind,onCommit:e=>{Ue(e)},onCancel:()=>D(void 0),fileIcon:(0,o.jsx)(Js,{path:`untitled`,size:16}),folderIcon:(0,o.jsx)(Ys,{path:`name`,open:!1,size:16}),t:n},`create:${e.dir}`):e.kind===`pending`?(0,o.jsx)(`div`,{className:`rvs-empty`,style:{...uW,paddingLeft:12+e.depth*14},children:e.reason===`offline`?n(`files.offline`):n(`common.loading`)},`pending:${e.dir}`):(0,o.jsx)(SW,{entry:e.entry,depth:e.depth,posinset:ft.from+t+1,setsize:dt.length,status:nt(e.entry),ignored:rt(e.entry),isSelected:b.has(e.entry.path),isOpen:v.has(e.entry.path),isCut:u!==void 0&&u.has(e.entry.path),isDropTarget:j===e.entry.path,isRenaming:w===e.entry.path,isFocused:d===e.entry.path,chatEnabled:Ce,referenceTitle:s,symlinkTitle:c,actions:ut},e.entry.path)),ft.after>0&&(0,o.jsx)(`div`,{"aria-hidden":`true`,style:{height:ft.after}})]})},yt=a===``?``:a;return(0,o.jsxs)(`div`,{className:`rvs-pane grow`,children:[(0,o.jsxs)(`div`,{className:`rvs-header`,children:[(0,o.jsx)(`span`,{className:`rvs-title`,children:n(`tab.files`)}),(0,o.jsx)(U,{title:n(`files.newFile`),onClick:()=>et(a,`file`),disabled:I!==void 0,children:(0,o.jsx)(gs,{size:14})}),(0,o.jsx)(U,{title:n(`files.newFolder`),onClick:()=>et(a,`folder`),disabled:I!==void 0,children:(0,o.jsx)(_s,{size:14})}),(0,o.jsx)(U,{title:n(`files.collapseAll`),onClick:()=>y(new Set([a])),children:(0,o.jsx)(os,{size:13})}),(0,o.jsx)(U,{title:n(`files.uploadFile`),onClick:()=>{z.current=a,re.current?.click()},disabled:r===``||a===``||I!==void 0,children:(0,o.jsx)(Hs,{size:14})}),(0,o.jsx)(U,{title:n(`files.refresh`),onClick:()=>{De(a,!0)},disabled:P||g.has(JU(r,a)),children:(0,o.jsx)(hs,{size:14})}),(0,o.jsx)(U,{title:e.showHidden?n(`files.hideHidden`):n(`files.showHidden`),onClick:e.onToggleHidden,children:(0,o.jsx)(ds,{size:13})})]}),I!==void 0&&(0,o.jsxs)(`div`,{className:`rvs-upload-bar`,children:[(0,o.jsx)(Tc,{}),(0,o.jsx)(`span`,{className:`rvs-upload-text`,title:`${I.done+1}/${I.total} · ${I.name}`,children:sW(n,I)}),(0,o.jsx)(`button`,{type:`button`,className:`rvs-hbtn`,title:n(`files.uploadAbort`),onClick:()=>me.current?.abort(),children:`✕`})]}),L!==void 0&&(0,o.jsxs)(`div`,{className:`rvs-upload-bar`,children:[(0,o.jsx)(Tc,{}),(0,o.jsx)(`span`,{className:`rvs-upload-text`,title:L.name,children:cW(n,L)}),(0,o.jsx)(`button`,{type:`button`,className:`rvs-hbtn`,title:n(`files.deleteCancel`),onClick:()=>he.current?.abort(),children:`✕`})]}),(0,o.jsx)(`input`,{ref:re,type:`file`,multiple:!0,style:{display:`none`},onChange:e=>{let t=[...e.target.files??[]];if(e.target.value=``,!XU(ge.current))return;let n=z.current||a,r=new Map(t.map(e=>[e.name,e]));Je(n,t.map(e=>({rel:e.name,size:e.size})),r,[]).catch(e=>{H(e instanceof Error?e.message:String(e),!0)})}}),(0,o.jsx)(`input`,{ref:e=>{ae.current=e,e!==null&&e.setAttribute(`webkitdirectory`,``)},type:`file`,multiple:!0,style:{display:`none`},onChange:e=>{let t=[...e.target.files??[]];if(e.target.value=``,!XU(ge.current))return;let n=z.current||a,r=[],i=new Map,o=new Set;for(let e of t){let t=e.webkitRelativePath,n=t!==void 0&&t!==``?t:e.name;r.push({rel:n,size:e.size}),i.set(n,e);let a=n.split(`/`);a.pop();let s=``;for(let e of a)s=s===``?e:`${s}/${e}`,o.add(s)}Je(n,r,i,[...o])}}),(0,o.jsx)(`div`,{ref:oe,className:`rvs-scroll`,onClick:e=>{e.target===e.currentTarget&&x(new Set)},onPointerDown:e=>{e.button===2&&e.target===e.currentTarget&&tt(e,void 0)},onContextMenu:e=>{e.target===e.currentTarget&&(e.preventDefault(),be.menu===void 0&&tt(e,void 0))},onDragOver:e=>{Xe(e.dataTransfer)&&(e.preventDefault(),M(a),ee(a))},onDragLeave:e=>{e.target===e.currentTarget&&(M(void 0),ee(void 0))},onDrop:e=>Ze(a,e),onScroll:()=>ht(),children:(0,o.jsxs)(`div`,{className:`rvs-tree`,role:`tree`,"aria-label":n(`tab.files`),"aria-multiselectable":`true`,onPointerDown:e=>{e.button===2&&tt(e,void 0)},onContextMenu:e=>{e.preventDefault(),be.menu===void 0&&tt(e,void 0)},children:[(0,o.jsx)(`div`,{className:`rvs-empty`,style:{textAlign:`left`,padding:`2px 8px`,direction:`rtl`,unicodeBidi:`plaintext`},title:yt,children:(0,o.jsx)(`code`,{style:{fontSize:11},children:yt})}),j!==void 0&&N!==void 0&&(0,o.jsx)(`div`,{className:`rvs-drop-hint`,title:j,children:`${n(`files.dropToUpload`)} → ${j.split(`/`).slice(-1)[0]||j}`}),(0,o.jsx)(`div`,{ref:se,"aria-hidden":`true`,style:{height:0}}),a!==``&&vt(a,0),a===``&&(0,o.jsx)(`div`,{className:`rvs-empty`,children:n(`files.selectWorkspace`)})]})}),be.menu!==void 0&&(0,o.jsx)(xc,{x:be.menu.x,y:be.menu.y,entries:be.menu.entries,onClose:be.close})]})}function wW(e){return(0,o.jsxs)(`div`,{className:`rvs-node`,style:{...uW,paddingLeft:8+e.depth*14},onClick:e=>e.stopPropagation(),children:[(0,o.jsx)(`span`,{className:`rvs-node-icon`,children:e.kind===`folder`?e.folderIcon:e.fileIcon}),(0,o.jsx)(TW,{initial:``,placeholder:e.kind===`folder`?e.t(`files.folderPlaceholder`):e.t(`files.filePlaceholder`),onCommit:e.onCommit,onCancel:e.onCancel})]})}function TW(e){let[t,n]=(0,i.useState)(e.initial),r=(0,i.useRef)(null),a=(0,i.useRef)(!1);(0,i.useEffect)(()=>{let t=r.current;if(t===null)return;t.focus();let n=e.initial.lastIndexOf(`.`);n>0?t.setSelectionRange(0,n):t.select()},[e.initial]);let s=()=>{a.current||(a.current=!0,e.onCommit(t))},c=()=>{a.current||(a.current=!0,e.onCancel())};return(0,o.jsx)(`input`,{ref:r,className:`rvs-rename-input`,value:t,placeholder:e.placeholder,spellCheck:!1,onClick:e=>e.stopPropagation(),onChange:e=>n(e.target.value),onKeyDown:e=>{e.stopPropagation(),!(e.nativeEvent.isComposing===!0||e.keyCode===229)&&(e.key===`Enter`?(e.preventDefault(),s()):e.key===`Escape`&&(e.preventDefault(),c()))},onBlur:()=>{t.trim()===``?c():s()}})}let EW=[`.git`,`node_modules`,`.venv`,`venv`,`__pycache__`,`.cache`,`dist`,`build`,`out`,`target`,`.next`,`.idea`,`.gradle`],DW={regex:!1,caseSensitive:!1,wholeWord:!1,maxResults:400,maxLineChars:500};function OW(e){if(typeof e!=`string`)throw Error(`invalid query`);if(/[\0\n\r]/.test(e))throw Error(`query contains control characters`);let t=e.trim();if(t===``)throw Error(`empty query`);if(t.length>256)throw Error(`query too long`);return t}function kW(e,t,n=DW){let r=OW(t),i=Math.min(Math.max(Math.floor(n.maxResults),1),2e3),a=Math.min(Math.max(Math.floor(n.maxLineChars),80),4e3),o=[...EW,...n.prune??[]],s=[`grep -rIn --null --binary-files=without-match`,...o.map(e=>`--exclude-dir=${B(e)}`),n.caseSensitive?``:`-i`,n.wholeWord?`-w`:``,n.regex?`-E`:`-F`,`-e ${B(r)}`,`--`,B(ye(e))].filter(e=>e!==``),c=[`rg -n --no-heading --null --color=never --with-filename --hidden`,...o.map(e=>`-g ${B(`!**/${e}/**`)}`),n.caseSensitive?``:`-i`,n.wholeWord?`-w`:``,n.regex?``:`-F`,`-e ${B(r)}`,B(ye(e))].filter(e=>e!==``),l=`${s.join(` `)} 2>/dev/null`;return`if command -v rg >/dev/null 2>&1; then ${`${c.join(` `)} 2>/dev/null`}; else ${l}; fi | cut -c1-${a} | head -n ${i+1}`}function AW(e,t=DW.maxResults,n=DW.maxLineChars){let r=[],i=Math.max(1,Math.floor(t)),a=Math.max(1,Math.floor(n)),o=!1,s=!1;for(let t of e.split(`
7070
7122
  `)){if(t===``)continue;if(t.length>4e3)break;let e=``,n=``,c=t.indexOf(`\0`);if(c>=0)e=t.slice(0,c),n=t.slice(c+1);else{let r=/^(.*?):(\d+):(.*)$/.exec(t);if(r===null)continue;e=r[1],n=`${r[2]}:${r[3]}`}let l=n.indexOf(`:`);if(l<=0)continue;let u=Number(n.slice(0,l));if(!Number.isFinite(u)||u<=0)continue;let d=n.slice(l+1);if(d.length>=a-1&&(s=!0),r.length>=i){o=!0;break}r.push({path:e,line:u,text:d})}return{hits:r,truncated:o,linesClipped:s}}function jW(e){let t=[],n=new Map;for(let r of e){let e=n.get(r.path);e===void 0?(n.set(r.path,t.length),t.push({path:r.path,hits:[r]})):t[e].hits.push(r)}return t}function MW(e,t,n,r,i){let a=t;if(a===``)return[{text:e,hit:!1}];let o;try{o=i??(n?new RegExp(a,r?`g`:`gi`):new RegExp(a.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),r?`g`:`gi`))}catch{o=new RegExp(a.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),r?`g`:`gi`)}o.lastIndex=0;let s=[],c=0,l=0;for(let t=o.exec(e);t!==null;t=o.exec(e)){if(t[0]===``){o.lastIndex+=1;continue}if(l++>200)break;t.index>c&&s.push({text:e.slice(c,t.index),hit:!1}),s.push({text:t[0],hit:!0}),c=t.index+t[0].length}return c<e.length&&s.push({text:e.slice(c),hit:!1}),s.length===0?[{text:e,hit:!1}]:s}let NW=`dsh-remote-vs.search.mode`,PW=`dsh-remote-vs.search.options`;function FW(){try{return localStorage.getItem(NW)===`content`?`content`:`name`}catch{return`name`}}function IW(){try{let e=localStorage.getItem(PW);if(e===null)return{caseSensitive:!1,wholeWord:!1,regex:!1};let t=JSON.parse(e);if(typeof t!=`object`||!t)return{caseSensitive:!1,wholeWord:!1,regex:!1};let{caseSensitive:n,wholeWord:r,regex:i}=t;return{caseSensitive:n===!0,wholeWord:r===!0,regex:i===!0}}catch{return{caseSensitive:!1,wholeWord:!1,regex:!1}}}function LW(e,t){let n=e.replace(/\/+$/,``);return t===n?``:t.startsWith(`${n}/`)?t.slice(n.length+1):t}function RW(e,t){if(e===``)return!0;let n=t.replace(/\/+$/,``);return n===``?!1:e===n||e.startsWith(`${n}/`)}function zW(e){let t=e.mode===`content`&&e.ran;return{nameTruncated:e.mode===`name`&&e.ran&&e.nameTruncated,contentTruncated:t&&e.contentTruncated,linesClipped:t&&e.linesClipped}}function BW(e,t=200){for(let n of e.split(`
7071
7123
  `)){let e=n.trim();if(e!==``)return e.length>t?`${e.slice(0,t)}…`:e}}function VW(e){return e.isDir?`reveal`:`open`}function HW(e,t){return t?.aborted===!0||e instanceof Error&&e.name===`AbortError`}let UW=!1;async function WW(e,t,n){if(UW)return V.exec(e,t,12e4);let r=``,i=``,a=(e,t)=>{r.length+i.length>=8388608||(e===`out`?r+=t:i+=t)};try{return{...await V.execStream(e,t,12e4,{signal:n,onData:(e,t)=>a(e===`out`?`out`:`err`,t)}),stdout:r,stderr:i}}catch(r){if(HW(r,n))throw r;if(r instanceof pn&&(r.status===404||r.status===405))return UW=!0,V.exec(e,t,12e4);throw r}}function GW(){let e=pl(),{t,alias:n,root:r,repoRoot:a}=e,[s,c]=(0,i.useState)(FW),[l,u]=(0,i.useState)(``),[d,f]=(0,i.useState)(``),[p,m]=(0,i.useState)(IW),[h,g]=(0,i.useState)([]),[_,v]=(0,i.useState)(!1),[y,b]=(0,i.useState)([]),[x,S]=(0,i.useState)(!1),[C,w]=(0,i.useState)(!1),[T,E]=(0,i.useState)(!1),[D,O]=(0,i.useState)(!1),[k,A]=(0,i.useState)(void 0),[j,M]=(0,i.useState)(void 0),N=(0,i.useRef)(0),ee=(0,i.useRef)(void 0),P=Sc();(0,i.useEffect)(()=>()=>{ee.current?.abort()},[]);let F=d===``?r:d,I=(0,i.useMemo)(()=>F===``||r===``?``:F===r?r:LW(r,F),[F,r]),te=(0,i.useCallback)(e=>{c(e);try{localStorage.setItem(NW,e)}catch{}},[]),L=(0,i.useCallback)(e=>{m(t=>{let n={...t,...e};try{localStorage.setItem(PW,JSON.stringify(n))}catch{}return n})},[]),R=(0,i.useCallback)(async(e,t,r,i)=>{let a=e.trim();if(a===``||n===``||r===``){N.current+=1,ee.current?.abort(),ee.current=void 0,E(!1),g([]),b([]),O(!1),A(void 0),M(void 0),v(!1),S(!1),w(!1);return}let o=++N.current;E(!0),A(void 0),M(void 0),t===`name`?v(!1):(S(!1),w(!1));try{if(t===`name`){let e=await ia(n,r,a);if(N.current!==o)return;g(e.hits),v(e.truncated),b([])}else{let e=kW(r,a,{...DW,caseSensitive:i.caseSensitive,wholeWord:i.wholeWord,regex:i.regex});ee.current?.abort();let t=new AbortController;ee.current=t;let s=await WW(n,e,t.signal);if(N.current!==o)return;if(!s.success&&s.stdout.trim()===``&&s.stderr.trim()!==``)b([]),S(!1),w(!1),A(s.stderr.trim());else{let e=AW(s.stdout,DW.maxResults,DW.maxLineChars);b(e.hits),S(e.truncated),w(e.linesClipped),g([]),M(BW(s.stderr))}ee.current===t&&(ee.current=void 0)}O(!0)}catch(e){if(N.current!==o)return;if(HW(e,t===`content`?ee.current?.signal:void 0)){E(!1);return}A(e instanceof Error?e.message:String(e)),b([]),g([]),O(!0)}finally{N.current===o&&E(!1)}},[n]);(0,i.useEffect)(()=>{let e=setTimeout(()=>{R(l,s,F,p)},350);return e.unref?.(),()=>clearTimeout(e)},[l,s,F,p,R]);let ne=e.searchRequest;(0,i.useEffect)(()=>{ne!==void 0&&(te(ne.mode),f(ne.scope===r?``:ne.scope),u(ne.query))},[ne?.id]),(0,i.useEffect)(()=>{d!==``&&!RW(d,r)&&f(``)},[d,r,n]);let z=(t,n)=>{e.openFile(t,n===void 0?void 0:{line:n})},re=e=>{let t=`${F.replace(/\/+$/,``)}/${e.path}`;return{abs:t,dir:e.isDir?t:t.slice(0,t.lastIndexOf(`/`))||`/`}},ie=e=>{let{abs:t}=re(e);uH(n,t,{name:ic(t),directory:e.isDir})},ae=(n,r)=>{n.preventDefault(),n.stopPropagation();let{abs:i,dir:o}=re(r),s=_l(a,i)||i;P.open(n.clientX,n.clientY,[{label:t(`files.copyAbs`),onSelect:()=>{Cc(i),H(t(`files.copiedClipboard`))}},{label:t(`files.copyRel`),onSelect:()=>{Cc(s),H(t(`files.copiedClipboard`))}},{label:t(`files.download`),onSelect:()=>{ie(r)}},{label:t(`files.openInFloat`),onSelect:()=>{e.openInFloatEditor(i)},disabled:!e.floatAvailable||r.isDir,separated:!0},{label:t(`search.revealInExplorer`),onSelect:()=>{e.revealInExplorer(o)}},{label:t(`search.openInTerminal`),onSelect:()=>{e.openTerminalAt(o)}}])},oe=(0,i.useMemo)(()=>jW(y),[y]),se=(0,i.useMemo)(()=>{let e=l.trim();if(e===``||!p.regex)return null;try{return new RegExp(e,p.caseSensitive?`g`:`gi`)}catch{return null}},[l,p.regex,p.caseSensitive]),ce=(e,t,n,r)=>(0,o.jsx)(`button`,{type:`button`,className:`rvs-toggle${t?` active`:``}`,title:e,"aria-pressed":t,onClick:n,children:r}),le=s===`name`?h.length:y.length,ue=zW({mode:s,ran:D,nameTruncated:_,contentTruncated:x,linesClipped:C});return(0,o.jsxs)(`div`,{className:`rvs-pane grow`,children:[(0,o.jsxs)(`div`,{className:`rvs-header`,children:[(0,o.jsx)(`span`,{className:`rvs-title`,children:t(`tab.search`)}),T&&(0,o.jsx)(Tc,{}),(0,o.jsx)(`span`,{className:`rvs-count`,children:le>0?le:``})]}),(0,o.jsxs)(`div`,{className:`rvs-search-row`,children:[(0,o.jsx)(`span`,{className:`rvs-node-icon`,title:t(s===`name`?`search.modeNameHint`:`search.modeContentHint`),children:s===`name`?(0,o.jsx)(Ts,{size:15}):(0,o.jsx)(Es,{size:15})}),(0,o.jsx)(wc,{value:s,onChange:te,options:[{id:`name`,label:t(`search.modeName`),title:t(`search.modeNameHint`)},{id:`content`,label:t(`search.modeContent`),title:t(`search.modeContentHint`)}]})]}),(0,o.jsxs)(`div`,{className:`rvs-search-row`,style:{borderBottom:s===`content`?`none`:void 0},children:[(0,o.jsx)(`input`,{className:`rvs-input`,placeholder:t(s===`name`?`search.placeholder`:`search.placeholderContent`),value:l,spellCheck:!1,onChange:e=>u(e.target.value),onKeyDown:e=>{e.nativeEvent.isComposing===!0||e.keyCode===229||(e.key===`Enter`?(e.preventDefault(),R(l,s,F,p)):e.key===`Escape`&&u(``))}}),s===`content`&&(0,o.jsxs)(`span`,{className:`rvs-toggles`,children:[ce(t(`search.matchCase`),p.caseSensitive,()=>L({caseSensitive:!p.caseSensitive}),(0,o.jsx)(Os,{size:14})),ce(t(`search.wholeWord`),p.wholeWord,()=>L({wholeWord:!p.wholeWord}),(0,o.jsx)(ks,{size:14})),ce(t(`search.useRegex`),p.regex,()=>L({regex:!p.regex}),(0,o.jsx)(As,{size:14}))]})]}),s===`content`&&(0,o.jsxs)(`div`,{className:`rvs-search-row`,style:{paddingTop:2},children:[(0,o.jsx)(`span`,{className:`rvs-scope-label`,title:t(`search.inFolder`),children:t(`search.inFolder`)}),(0,o.jsx)(`input`,{className:`rvs-input`,placeholder:t(`search.inFolderPlaceholder`),value:I,spellCheck:!1,onChange:e=>{let t=e.target.value.trim();if(t===``||t===r){f(``);return}f(t.startsWith(`/`)?t:`${r.replace(/\/+$/,``)}/${t.replace(/^\.?\//,``)}`)},onKeyDown:e=>{e.key===`Escape`&&f(``)}}),(0,o.jsx)(`button`,{type:`button`,className:`rvs-hbtn`,title:t(`search.resetScope`),onClick:()=>f(``),children:(0,o.jsx)(Ds,{size:14})})]}),k!==void 0&&(0,o.jsx)(`div`,{className:`rvs-banner error`,children:k}),j!==void 0&&(0,o.jsx)(`div`,{className:`rvs-banner warn`,children:t(`search.stderrWarn`).replace(`{detail}`,j)}),ue.contentTruncated&&(0,o.jsx)(`div`,{className:`rvs-banner warn`,children:t(`search.truncated`)}),ue.linesClipped&&(0,o.jsx)(`div`,{className:`rvs-banner warn`,children:t(`search.linesClipped`)}),(0,o.jsxs)(`div`,{className:`rvs-scroll`,children:[!D&&l.trim()===``&&(0,o.jsx)(`div`,{className:`rvs-empty`,children:t(s===`name`?`search.hint`:`search.hintContent`)}),s===`name`&&(0,o.jsxs)(o.Fragment,{children:[D&&h.length===0&&l.trim()!==``&&(0,o.jsx)(`div`,{className:`rvs-empty`,children:t(`search.empty`)}),h.map(t=>(0,o.jsxs)(`button`,{type:`button`,className:`rvs-hit`,title:t.path,onClick:()=>{let{abs:n}=re(t);VW(t)===`reveal`?e.revealInExplorer(n):z(n)},onContextMenu:e=>{ae(e,t)},children:[(0,o.jsx)(`span`,{className:`rvs-node-icon`,children:t.isDir?(0,o.jsx)(`span`,{style:{color:`var(--rvs-fg3)`},children:`▸`}):(0,o.jsx)(Ks,{path:t.path,size:14})}),(0,o.jsx)(`span`,{className:`rvs-hit-name`,children:t.name}),t.dir!==``&&(0,o.jsx)(`span`,{className:`rvs-hit-dir`,children:t.dir})]},t.path)),ue.nameTruncated&&(0,o.jsx)(`div`,{className:`rvs-empty`,children:t(`search.truncated`)})]}),s===`content`&&(0,o.jsxs)(o.Fragment,{children:[D&&y.length===0&&l.trim()!==``&&k===void 0&&(0,o.jsx)(`div`,{className:`rvs-empty`,children:t(`search.emptyContent`).replace(`{scope}`,I||r)}),oe.map(e=>(0,o.jsxs)(`div`,{children:[(0,o.jsxs)(`button`,{type:`button`,className:`rvs-hit rvs-hit-file`,title:e.path,onClick:()=>z(e.path,e.hits[0]?.line),children:[(0,o.jsx)(`span`,{className:`rvs-node-icon`,children:(0,o.jsx)(Ks,{path:e.path,size:14})}),(0,o.jsx)(`span`,{className:`rvs-hit-name`,children:ic(e.path)}),(0,o.jsx)(`span`,{className:`rvs-hit-dir`,children:LW(r,e.path)}),(0,o.jsx)(`span`,{className:`rvs-hit-count`,children:e.hits.length})]}),e.hits.map(t=>(0,o.jsxs)(`button`,{type:`button`,className:`rvs-hit rvs-hit-line`,title:`${e.path}:${t.line}`,onClick:()=>z(e.path,t.line),children:[(0,o.jsx)(`span`,{className:`rvs-hit-lineno`,children:t.line}),(0,o.jsx)(`span`,{className:`rvs-hit-text`,children:MW(t.text,l.trim(),p.regex,p.caseSensitive,se).map((e,t)=>e.hit?(0,o.jsx)(`mark`,{className:`rvs-mark`,children:e.text},t):(0,o.jsx)(`span`,{children:e.text},t))})]},t.line))]},e.path))]})]}),P.menu!==void 0&&(0,o.jsx)(xc,{x:P.menu.x,y:P.menu.y,entries:P.menu.entries,onClose:P.close})]})}let KW=[`details`,`content`,`diff`];function qW(e){return typeof e==`string`&&KW.includes(e)}function JW(e,t){let n=KW.indexOf(e);if(t===`Home`)return KW[0];if(t===`End`)return KW[KW.length-1];if(t===`ArrowLeft`)return KW[(n-1+KW.length)%KW.length];if(t===`ArrowRight`)return KW[(n+1)%KW.length]}function YW(e,t,n){return n!==`diff`||t===``?!1:e.key!==t||e.text===void 0&&e.error===void 0}function XW(e,t=6e3){let n=[],r=0,i=0,a=0,o=!1;for(let s of qt(e)){let e=[],c=0,l=0,u=!1,d=1,f=1;for(let[n,r]of s.hunks.entries()){let i=r.newStart-f,o=r.oldStart-d;(n===0?r.oldStart>1||r.newStart>1:i>0||o>0)&&(a<t?(e.push({kind:`skip`,oldLine:null,newLine:null,text:``}),a+=1):u=!0);let s=r.oldStart,p=r.newStart;for(let n of r.lines){if(n.startsWith(`\\`))continue;let r=n[0];if(r===`+`){c+=1,a<t?(e.push({kind:`add`,oldLine:null,newLine:p,text:n.slice(1)}),a+=1):u=!0,p+=1;continue}if(r===`-`){l+=1,a<t?(e.push({kind:`del`,oldLine:s,newLine:null,text:n.slice(1)}),a+=1):u=!0,s+=1;continue}a<t?(e.push({kind:`context`,oldLine:s,newLine:p,text:n.slice(1)}),a+=1):u=!0,s+=1,p+=1}d=s,f=p}r+=c,i+=l,u&&(o=!0),n.push({path:s.path,oldPath:s.oldPath,status:s.status,binary:s.binary,added:c,deleted:l,rows:e,truncated:u})}return{files:n,added:r,deleted:i,truncated:o}}function ZW(e,t){if(t!==``){for(let n of e.files)if(n.path===t||n.oldPath===t)return n.path}}function QW(e){let t=[],n=[];for(let r of e.split(`
7072
7124
  `)){if(r.startsWith(`diff --git `)){n.length>0&&t.push($W(n)),n=[r];continue}n.length>0&&n.push(r)}return n.length>0&&t.push($W(n)),t}function $W(e){let t=e.join(`
@@ -7382,7 +7434,7 @@ Integer Float Double Long Int32 Int64 Uint8 uint32_t int32_t uint64_t int64_t si
7382
7434
  [dsh-remote] clipboard read denied by the browser\r
7383
7435
  `);return}i.paste(e)})},A=vK({read:MK,paste:e=>{i.paste(e)},onDenied:()=>{i.write(`\r
7384
7436
  [dsh-remote] clipboard read denied by the browser\r
7385
- `)}}),j=0,M=e=>{if(e.preventDefault(),e.stopPropagation(),Date.now()<j){j=0;return}let t=e.clipboardData?.getData(`text/plain`)??``;A.observed(),t!==``&&i.paste(t)};e.addEventListener(`paste`,M,!0),i.attachCustomKeyEventHandler(e=>{let t=_K({type:e.type,key:e.key,ctrl:e.ctrlKey,shift:e.shiftKey,alt:e.altKey,meta:e.metaKey});if(t===void 0){if(e.type===`keydown`&&(e.ctrlKey||e.metaKey)&&!e.shiftKey&&!e.altKey&&(e.key===`b`||e.key===`B`)&&n.current.onQuickAddSnippet!==void 0){e.preventDefault();let t=i.getSelection();return n.current.onQuickAddSnippet({...t===``?{}:{selection:t},...S===``?{}:{line:S}}),!1}return!0}return t===`copy-interrupt`?i.hasSelection()?(e.preventDefault(),O(!1),!1):!0:t===`paste`?(e.preventDefault(),j=Date.now()+600,k(),!1):t===`paste-native`?(A.arm(),!0):i.hasSelection()?(e.preventDefault(),O(!1),!1):!0});let N=e=>{e.preventDefault();let t=i.hasSelection(),n=[{label:c.current(`term.copy`),disabled:yK({hasSelection:t}).copyDisabled,onSelect:()=>{O(!1),i.focus()}},{label:c.current(`term.paste`),onSelect:()=>{k(),i.focus()}},{label:c.current(`term.selectAll`),separated:!0,onSelect:()=>{i.selectAll(),i.focus()}}];s.current(e.clientX,e.clientY,n)};return e.addEventListener(`contextmenu`,N),i.focus(),()=>{r.current=void 0,a(),f(),d.dispose(),u.dispose(),window.clearTimeout(D),window.removeEventListener(`resize`,E),e.removeEventListener(`paste`,M,!0),e.removeEventListener(`contextmenu`,N),T.disconnect();try{p.close()}catch{}i.dispose()}},[]),(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(`div`,{ref:t,style:{height:`100%`,minHeight:200}}),a.menu!==void 0&&(0,o.jsx)(xc,{x:a.menu.x,y:a.menu.y,entries:a.menu.entries,onClose:a.close})]})}let PK=`dsh-remote-vs.term.snippets`;function FK(){return`s${Date.now().toString(36)}${Math.random().toString(36).slice(2,6)}`}function IK(e){let t=(e.name??``).trim().slice(0,80),n=(e.command??``).trim().slice(0,4e3);if(!(t===``||n===``))return{name:t,command:n}}function LK(e){if(typeof e!=`string`||e===``)return[];let t;try{t=JSON.parse(e)}catch{return[]}if(!Array.isArray(t))return[];let n=[],r=new Set;for(let e of t){if(typeof e!=`object`||!e)continue;let t=e,i=IK({name:typeof t.name==`string`?t.name:``,command:typeof t.command==`string`?t.command:``});if(i===void 0)continue;let a=typeof t.id==`string`&&t.id!==``?t.id:FK();if(r.has(a)&&(a=FK()),r.add(a),n.push({id:a,...i}),n.length>=200)break}return n}function RK(e){return JSON.stringify(e.map(e=>({id:e.id,name:e.name,command:e.command})))}function zK(e,t,n=FK()){let r=IK(t);if(r===void 0)return e;e.some(e=>e.id===n)&&(n=FK());let i=[...e,{id:n,...r}];return i.length>200?i.slice(i.length-200):i}function BK(e,t,n){let r=e.findIndex(e=>e.id===t);if(r<0)return e;let i=IK(n);if(i===void 0)return e;let a=e[r];if(a.name===i.name&&a.command===i.command)return e;let o=[...e];return o[r]={id:t,...i},o}function VK(e,t){let n=e.filter(e=>e.id!==t);return n.length===e.length?e:n}function HK(e,t,n){if(e.length<2)return e;let r=Math.max(0,Math.min(e.length-1,t)),i=Math.max(0,Math.min(e.length-1,n));if(r===i)return e;let a=[...e],[o]=a.splice(r,1);return o===void 0?e:(a.splice(i,0,o),a)}let UK=new Set,WK;function GK(){try{return LK(localStorage.getItem(PK))}catch{return[]}}function KK(e){try{localStorage.setItem(PK,RK(e))}catch{}}function qK(){for(let e of[...UK])try{e()}catch{}}function JK(){return WK===void 0&&(WK=GK()),WK}function YK(e){return UK.add(e),()=>{UK.delete(e)}}function XK(e){let t=JK(),n=e(t);n!==t&&(WK=n,KK(n),qK())}function ZK(e){let t=e.t,n=(0,i.useSyncExternalStore)(YK,JK,JK),[r,s]=(0,i.useState)(void 0),[c,l]=(0,i.useState)(void 0),[u,d]=(0,i.useState)(void 0),[f,p]=(0,i.useState)(void 0),m=(0,i.useRef)(null),h=(0,i.useRef)(null),g=(0,i.useRef)(e.addRequest),_=(0,i.useCallback)(()=>{let e=m.current?.getBoundingClientRect();e!=null&&s({left:Math.max(4,e.left),top:e.bottom+4,width:300})},[]),v=(0,i.useCallback)(()=>{s(void 0),d(void 0),p(void 0)},[]);(0,i.useEffect)(()=>{if(r===void 0)return;let e=h.current;if(e!==null)return(e.querySelector(`.rvs-snips-insert`)??yc(e)[0])?.focus(),()=>{let e=document.activeElement;(e===null||e===document.body||h.current?.contains(e)===!0)&&m.current?.focus()}},[r]);let y=e=>{if(e.nativeEvent.isComposing)return;if(e.key===`Escape`){e.preventDefault(),e.stopPropagation(),v();return}if(e.altKey||e.key!==`ArrowDown`&&e.key!==`ArrowUp`)return;let t=h.current;if(t===null)return;let n=Array.from(t.querySelectorAll(`.rvs-snips-insert`));if(n.length===0)return;e.preventDefault();let r=n.indexOf(document.activeElement);n[e.key===`ArrowDown`?(r+1)%n.length:r<=0?n.length-1:r-1]?.focus()};(0,i.useEffect)(()=>{e.addRequest!==g.current&&(g.current=e.addRequest,_(),l({mode:`add`,content:e.addContent}))},[e.addRequest,e.addContent,_]),(0,i.useEffect)(()=>{if(r===void 0)return;let e=e=>{let t=e.target;t instanceof Node&&h.current?.contains(t)!==!0&&m.current?.contains(t)!==!0&&v()},t=()=>v(),n=e=>{if(e.key!==`Escape`)return;let t=document.activeElement;t instanceof Node&&h.current?.contains(t)===!0||t instanceof Element&&t.closest(`.xterm`)!==null||v()};return document.addEventListener(`mousedown`,e,!0),document.addEventListener(`keydown`,n,!0),window.addEventListener(`resize`,t),()=>{document.removeEventListener(`mousedown`,e,!0),document.removeEventListener(`keydown`,n,!0),window.removeEventListener(`resize`,t)}},[r,v]);let b=t=>{if(!e.onInsert(t.command)){window.setTimeout(()=>{l(void 0)},0);return}v()},x=e=>{hc({title:t(`term.snippetDeleteTitle`),text:e.name,danger:!0,okText:t(`term.snippetDelete`)}).then(t=>{t&&XK(t=>VK(t,e.id))})},S=(e,t)=>{XK(n=>HK(n,e,e+t))},C=r===void 0?void 0:(0,a.createPortal)((0,o.jsxs)(`div`,{ref:h,className:`rvs-portal rvs-snips-panel`,role:`dialog`,"aria-label":t(`term.snippets`),onKeyDown:y,style:{left:`${r.left}px`,top:`${r.top}px`,width:`${r.width}px`},children:[(0,o.jsxs)(`div`,{className:`rvs-snips-head`,children:[(0,o.jsxs)(`span`,{className:`rvs-snips-title`,children:[`⚡ `,t(`term.snippets`)]}),(0,o.jsx)(`span`,{className:`rvs-snips-spacer`}),(0,o.jsx)(`button`,{type:`button`,className:`rvs-snips-add`,title:t(`term.snippetAdd`),"aria-label":t(`term.snippetAdd`),onClick:()=>l({mode:`add`,content:``}),children:`+`})]}),(0,o.jsxs)(`div`,{className:`rvs-snips-list`,children:[n.length===0&&(0,o.jsx)(`div`,{className:`rvs-snips-empty`,children:t(`term.snippetEmpty`)}),n.map((e,n)=>(0,o.jsxs)(`div`,{className:`rvs-snips-row${f===n&&u!==void 0?` drop`:``}`,draggable:!0,onDragStart:e=>{d({from:n}),e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,String(n))},onDragOver:e=>{u!==void 0&&(e.preventDefault(),e.dataTransfer.dropEffect=`move`,p(n))},onDrop:e=>{e.preventDefault();let t=Number(e.dataTransfer.getData(`text/plain`));d(void 0),p(void 0),Number.isFinite(t)&&XK(e=>HK(e,t,n))},onDragEnd:()=>{d(void 0),p(void 0)},children:[(0,o.jsx)(`span`,{className:`rvs-snips-grip`,title:t(`term.snippetDragHint`),role:`button`,"aria-label":t(`term.snippetDragHint`),tabIndex:0,onKeyDown:e=>{e.altKey&&e.key===`ArrowUp`&&(e.preventDefault(),S(n,-1)),e.altKey&&e.key===`ArrowDown`&&(e.preventDefault(),S(n,1))},children:`⠿`}),(0,o.jsxs)(`button`,{type:`button`,className:`rvs-snips-insert`,title:`${t(`term.snippetInsertHint`)}\n${e.command}`,onClick:()=>b(e),children:[(0,o.jsx)(`span`,{className:`rvs-snips-name`,children:e.name}),(0,o.jsx)(`span`,{className:`rvs-snips-arrow`,"aria-hidden":`true`,children:`-->`}),(0,o.jsx)(`span`,{className:`rvs-snips-text`,children:e.command})]}),(0,o.jsx)(`button`,{type:`button`,className:`rvs-snips-icon`,title:t(`term.snippetEdit`),"aria-label":t(`term.snippetEdit`),onClick:()=>l({mode:`edit`,snippet:e}),children:`✎`}),(0,o.jsx)(`button`,{type:`button`,className:`rvs-snips-icon danger`,title:t(`term.snippetDelete`),"aria-label":t(`term.snippetDelete`),onClick:()=>x(e),children:`×`})]},e.id))]}),(0,o.jsx)(`div`,{className:`rvs-snips-foot`,children:t(`term.snippetFootHint`)})]}),document.body);return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(`button`,{ref:m,type:`button`,className:`rvs-hbtn rvs-snips-btn`,title:t(`term.snippets`),"aria-label":t(`term.snippets`),onClick:()=>{r===void 0?_():v()},children:[(0,o.jsx)(`span`,{"aria-hidden":`true`,children:`⚡`}),` `,t(`term.snippets`)]}),C,c!==void 0&&(0,o.jsx)(QK,{t,mode:c.mode,...c.mode===`edit`?{snippet:c.snippet}:{initialCommand:c.content},onCancel:()=>l(void 0),onSubmit:e=>{c.mode===`add`?XK(t=>zK(t,e)):XK(t=>BK(t,c.snippet.id,e)),l(void 0),v()}})]})}function QK(e){let t=e.t,[n,r]=(0,i.useState)(e.snippet?.name??``),[s,c]=(0,i.useState)(e.snippet?.command??e.initialCommand??``),[l,u]=(0,i.useState)(void 0),d=(0,i.useRef)(null),f=(0,i.useRef)(document.activeElement);(0,i.useEffect)(()=>(d.current?.focus(),d.current?.select(),()=>{let e=f.current;e!==null&&document.body.contains(e)&&e.focus()}),[]),(0,i.useEffect)(()=>{let t=t=>{t.isComposing||t.key===`Escape`&&(t.preventDefault(),e.onCancel())};return document.addEventListener(`keydown`,t,!0),()=>document.removeEventListener(`keydown`,t,!0)},[e]);let p=()=>{if(n.trim()===``){u(t(`term.snippetNameRequired`));return}if(s.trim()===``){u(t(`term.snippetCommandRequired`));return}e.onSubmit({name:n,command:s})};return(0,a.createPortal)((0,o.jsx)(`div`,{className:`rvs-portal rvs-modal-mask`,onMouseDown:t=>{t.target===t.currentTarget&&e.onCancel()},children:(0,o.jsxs)(`div`,{className:`rvs-modal-box`,role:`dialog`,"aria-modal":`true`,"aria-label":e.mode===`add`?t(`term.snippetAdd`):t(`term.snippetEdit`),children:[(0,o.jsx)(`div`,{className:`rvs-modal-title`,children:e.mode===`add`?t(`term.snippetAdd`):t(`term.snippetEdit`)}),(0,o.jsxs)(`label`,{className:`rvs-snips-field`,children:[(0,o.jsx)(`span`,{children:t(`term.snippetName`)}),(0,o.jsx)(`input`,{ref:d,value:n,placeholder:t(`term.snippetNamePlaceholder`),onChange:e=>{r(e.target.value),u(void 0)},onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&(e.preventDefault(),p())}})]}),(0,o.jsxs)(`label`,{className:`rvs-snips-field`,children:[(0,o.jsx)(`span`,{children:t(`term.snippetCommand`)}),(0,o.jsx)(`textarea`,{className:`rvs-snips-command`,value:s,placeholder:t(`term.snippetCommandPlaceholder`),rows:4,onChange:e=>{c(e.target.value),u(void 0)}})]}),l!==void 0&&(0,o.jsx)(`div`,{className:`rvs-snips-error`,role:`alert`,children:l}),(0,o.jsxs)(`div`,{className:`rvs-modal-row`,children:[(0,o.jsx)(`button`,{type:`button`,className:`rvs-modal-btn`,onClick:e.onCancel,children:t(`common.cancel`)}),(0,o.jsx)(`button`,{type:`button`,className:`rvs-modal-btn primary`,onClick:p,children:t(`common.save`)})]})]})}),document.body)}let $K=`dsh-remote-vs.term.alias`,eq=`dsh-remote-vs.term.tabs`;function tq(){try{return localStorage.getItem($K)??``}catch{return``}}function nq(){try{let e=localStorage.getItem(eq);if(e===null)return[];let t=JSON.parse(e);if(!Array.isArray(t))return[];let n=[];for(let e of t){if(typeof e!=`object`||!e)continue;let{id:t,alias:r,session:i}=e;typeof t!=`string`||typeof r!=`string`||n.push(i===void 0||typeof i!=`string`?{id:t,alias:r}:{id:t,alias:r,session:i})}return n}catch{return[]}}function rq(e){try{let t=e.map(e=>e.session===void 0?{id:e.id,alias:e.alias}:{id:e.id,alias:e.alias,session:e.session});localStorage.setItem(eq,JSON.stringify(t))}catch{}}function iq(){return`t${Date.now().toString(36)}${Math.random().toString(36).slice(2,6)}`}let aq=0,oq,sq=new Set;function cq(e){if(oq!==e){oq=e;for(let e of[...sq])e()}}function lq(e){return sq.add(e),()=>{sq.delete(e)}}function uq(e){oq===void 0&&cq(e)}function dq(e,t){return e===t}let fq=new Set([`websocket refused`,`websocket error`]);function pq(e,t){return t===`terminal session expired`?`expired`:e===null&&(t===void 0||fq.has(t))?`reattach`:`exited`}function mq(e,t,n){let r=pq(t,n);return r===`expired`?{connected:!1,session:void 0,kind:r}:r===`reattach`?{connected:!1,session:e.session,kind:r,noteKey:`term.disconnected`}:{connected:!1,session:void 0,kind:r,...t===null?n===void 0?{noteKey:`term.closed`}:{noteText:n}:{noteText:`exit ${t}`}}}function hq(e){let t=e.t,n=(0,i.useRef)(Symbol(`terminal-surface`));uq(n.current);let r=(0,i.useSyncExternalStore)(lq,()=>dq(oq,n.current)),[a,s]=(0,i.useState)(tq),[c,l]=(0,i.useState)(()=>nq().map(e=>({id:e.id,alias:e.alias,...e.session===void 0?{}:{session:e.session},nonce:0,connected:!0}))),[u,d]=(0,i.useState)(()=>c[0]?.id),[f,p]=(0,i.useState)(void 0),m=a!==``&&e.hosts.some(e=>e.alias===a)?a:e.hosts[0]?.alias??``,h=(0,i.useRef)(!1);(0,i.useEffect)(()=>{if(!r){h.current=!1;return}let e=!h.current;h.current=!0,e&&l(e=>e.map(e=>!e.connected&&e.session!==void 0?{...e,connected:!0,nonce:e.nonce+1,note:void 0}:e))},[r]),(0,i.useEffect)(()=>{e.visible&&cq(n.current)},[e.visible]),(0,i.useEffect)(()=>{if(r)try{localStorage.setItem($K,m)}catch{}},[m,r]),(0,i.useEffect)(()=>{r&&rq(c)},[c,r]),(0,i.useEffect)(()=>{e.hosts.length!==0&&l(t=>t.filter(t=>e.hosts.some(e=>e.alias===t.alias)))},[e.hosts]);let g=(0,i.useCallback)((e,t)=>{l(n=>n.map(n=>n.id===e?{...n,...t}:n))},[]),_=(0,i.useCallback)((e,t)=>{if(e===``)return;let n={id:iq(),alias:e,nonce:0,connected:!0,...t===void 0?{}:{initialCommand:t}};l(e=>[...e,n]),d(n.id)},[]);(0,i.useEffect)(()=>{let t=e.request;if(t===void 0||t.id===aq||!r||e.visible!==!0)return;aq=t.id;let n=t.alias!==``&&e.hosts.some(e=>e.alias===t.alias)?t.alias:m;n!==a&&s(n),_(n,fo(t.dir))},[e.request,e.hosts,m,a,_,r,e.visible]);let v=(0,i.useCallback)(async e=>{if(!await hc({title:t(`term.closeTitle`),text:`${e.alias}${e.session===void 0?``:` · ${e.session.slice(0,8)}`}`,danger:!0,okText:t(`term.close`)}))return;e.session!==void 0&&V.terminalClose(e.session).catch(()=>void 0),l(t=>t.filter(t=>t.id!==e.id));let n=c.filter(t=>t.id!==e.id);d(t=>t===e.id?n[n.length-1]?.id:t)},[t,c]),y=(0,i.useCallback)((e,t)=>{if(t){let t=c.find(t=>t.id===e);t?.session!==void 0&&V.terminalClose(t.session).catch(()=>void 0)}l(n=>n.map(n=>n.id===e?{...n,nonce:n.nonce+1,connected:!0,note:void 0,...t?{session:void 0}:{}}:n))},[c]),b=c.find(e=>e.id===u)??c[0],x=t=>{let n=e.hosts.find(e=>e.alias===t);if(n!==void 0)return n.user===`root`?`/root`:`/home/${n.user}`},S=e=>{let t=c.filter(t=>t.alias===e.alias),n=t.findIndex(t=>t.id===e.id)+1,r=e.alias;return t.length>1?`${r} #${n}`:r};return r?(0,o.jsxs)(`div`,{className:`rvs-pane grow`,children:[(0,o.jsxs)(`div`,{className:`rvs-header`,children:[(0,o.jsx)(`span`,{className:`rvs-title`,children:t(`tab.terminal`)}),(0,o.jsx)(ZK,{t,addRequest:f?.id??0,addContent:f?.content??``,onInsert:e=>EK(b?.id,e)?!0:(H(t(`term.snippetNoTerminal`),!0),!1)}),(0,o.jsx)(`select`,{className:`rvs-select`,value:m,onChange:e=>s(e.target.value),disabled:e.hosts.length===0,title:t(`term.selectHost`),style:{flex:1,minWidth:90},children:e.hosts.map(e=>(0,o.jsxs)(`option`,{value:e.alias,style:iz,children:[e.alias,` (`,e.user,`@`,e.host,`)`]},e.alias))}),(0,o.jsx)(U,{title:t(`term.new`),onClick:()=>_(m),disabled:m===``,children:(0,o.jsx)(gs,{size:15})})]}),e.hosts.length===0&&(0,o.jsx)(`div`,{className:`rvs-banner warn`,children:t(`term.noHosts`)}),(0,o.jsxs)(`div`,{className:`rvs-term-tabs`,role:`tablist`,children:[c.map(e=>(0,o.jsxs)(`span`,{className:`rvs-term-tabwrap`,children:[(0,o.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":e.id===b?.id,className:`rvs-term-tab${e.id===b?.id?` active`:``}${e.note===void 0?``:` dead`}`,title:`${e.alias}${e.session===void 0?``:`\n${e.session}`}`,onClick:()=>d(e.id),onMouseDown:t=>{t.button===1&&(t.preventDefault(),v(e))},children:[(0,o.jsx)(Ns,{size:13}),(0,o.jsx)(`span`,{className:`rvs-term-name`,children:S(e)})]}),(0,o.jsx)(`button`,{type:`button`,className:`rvs-etab-close`,"aria-label":t(`term.close`),title:t(`term.close`),onMouseDown:e=>e.preventDefault(),onClick:()=>{v(e)},children:(0,o.jsx)(ys,{size:11})})]},e.id)),(0,o.jsx)(`button`,{type:`button`,className:`rvs-term-tab`,title:t(`term.new`),onClick:()=>_(m),disabled:m===``,style:{padding:`0 8px`},children:(0,o.jsx)(gs,{size:13})})]}),(0,o.jsxs)(`div`,{className:`rvs-term-body`,children:[c.length===0&&(0,o.jsx)(`div`,{className:`rvs-empty`,children:t(`term.empty`)}),c.map(n=>(0,o.jsx)(`div`,{className:`rvs-term-slot`,style:{display:n.id===b?.id?`block`:`none`},children:n.connected?(0,o.jsx)(NK,{wsUrl:V.terminalUrl({...n.session===void 0?{alias:n.alias}:{session:n.session},cols:80,rows:24}),visible:e.visible&&n.id===b?.id,t,tabId:n.id,onQuickAddSnippet:e=>{let t=(e.selection??e.line??``).trim();p(e=>({id:(e?.id??0)+1,content:t}))},...x(n.alias)===void 0?{}:{home:x(n.alias)},onPathClick:(e,t)=>{Vl(n.alias,e,t)},...n.initialCommand===void 0?{}:{initialInput:n.initialCommand},onReady:e=>g(n.id,{session:e,connected:!0,note:void 0}),onExit:(e,r)=>{let i=mq(n,e,r);if(i.kind===`expired`){g(n.id,{session:void 0,nonce:n.nonce+1,connected:!0,note:void 0});return}g(n.id,{connected:i.connected,session:i.session,note:i.noteText??(i.noteKey===void 0?void 0:t(i.noteKey))})}},`${n.id}:${n.nonce}`):(0,o.jsxs)(`div`,{className:`rvs-term-dead`,children:[n.note!==void 0&&(0,o.jsx)(`div`,{className:`rvs-empty`,children:n.note}),(0,o.jsx)(`div`,{className:`rvs-commit-row`,style:{justifyContent:`center`},children:(0,o.jsx)(`button`,{type:`button`,className:`rvs-chip primary`,onClick:()=>y(n.id,n.session===void 0),children:t(`term.reconnect`)})})]})},n.id))]})]}):null}function gq(e){let t=e.t,[n,r]=(0,i.useState)(e.initialPath),[a,s]=(0,i.useState)(e.initialPath),[c,l]=(0,i.useState)([]),[u,d]=(0,i.useState)(``),[f,p]=(0,i.useState)(!1),[m,h]=(0,i.useState)(void 0),g=(0,i.useRef)(0),_=(0,i.useRef)(null),v=(0,i.useRef)(null),y=(0,i.useRef)(null),b=(0,i.useRef)(e.onCancel);b.current=e.onCancel;let x=(0,i.useRef)(e.open);x.current=e.open;let S=async t=>{let n=++g.current;p(!0),h(void 0);try{let i=await V.fileOp.list(e.alias,t);if(n!==g.current)return;r(t),s(t),l(i.filter(e=>e.isDir||e.isSymlink))}catch(e){n===g.current&&h(e instanceof pn?e.message:String(e))}finally{n===g.current&&p(!1)}};if((0,i.useEffect)(()=>{if(!e.open)return;g.current+=1,l([]),h(void 0);let t=e.initialPath.trim()===``?void 0:e.initialPath.trim();return V.exec(e.alias,`printf %s "$HOME"`,15e3).then(e=>{let t=e.success?e.stdout.trim():``;t.startsWith(`/`)&&d(t)},()=>void 0),S(t??`/`),()=>{g.current+=1}},[e.open,e.alias]),(0,i.useEffect)(()=>{if(!e.open)return;y.current=typeof document>`u`?null:document.activeElement;let t=window.setTimeout(()=>v.current?.focus(),0),n=e=>{if(e.key===`Escape`){e.preventDefault(),b.current();return}if(e.key!==`Tab`)return;let t=_.current;if(t===null)return;let n=Array.from(t.querySelectorAll(`button:not([disabled]), input:not([disabled]), [tabindex]:not([tabindex="-1"])`));if(n.length===0)return;let r=n[0],i=n[n.length-1],a=document.activeElement;e.shiftKey&&(a===r||a===null||!t.contains(a))?(e.preventDefault(),i.focus()):!e.shiftKey&&a===i&&(e.preventDefault(),r.focus())};return window.addEventListener(`keydown`,n),()=>{window.clearTimeout(t),window.removeEventListener(`keydown`,n);let e=y.current;e!==null&&document.body.contains(e)&&e.focus()}},[e.open]),!e.open)return null;let C=n===`/`?void 0:n.replace(/\/+$/,``).split(`/`).slice(0,-1).join(`/`)||`/`,w=()=>{let e=a.trim();e!==``&&S(e)};return(0,o.jsx)(`div`,{style:{position:`fixed`,inset:0,zIndex:1e3,display:`grid`,placeItems:`center`,background:`rgba(0,0,0,.45)`},role:`dialog`,"aria-modal":`true`,"aria-label":e.title,onClick:e.onCancel,children:(0,o.jsxs)(`div`,{ref:_,style:{width:`min(560px, calc(100vw - 32px))`,maxHeight:`min(640px, calc(100vh - 32px))`,display:`flex`,flexDirection:`column`,background:`Canvas`,color:`CanvasText`,border:`1px solid rgba(127,127,127,.4)`,borderRadius:8,padding:14,fontSize:13},onClick:e=>e.stopPropagation(),children:[(0,o.jsx)(`div`,{style:{fontWeight:600,marginBottom:8},children:e.title}),(0,o.jsxs)(`div`,{style:{display:`flex`,gap:8,marginBottom:8},children:[(0,o.jsx)(`input`,{ref:v,value:a,onChange:e=>s(e.target.value),onKeyDown:e=>{e.nativeEvent.isComposing===!0||e.keyCode===229||e.key===`Enter`&&w()},placeholder:`/home/user/project`,spellCheck:!1,style:{flex:1,background:`rgba(127,127,127,.12)`,color:`inherit`,border:`1px solid rgba(127,127,127,.35)`,borderRadius:6,padding:`4px 8px`,fontSize:13,fontFamily:`inherit`,outline:`none`}}),(0,o.jsx)(cz,{onClick:w,disabled:f||a.trim()===``,children:t(`dirPicker.go`)})]}),(0,o.jsxs)(`div`,{style:{display:`flex`,gap:8,alignItems:`center`,marginBottom:8},children:[(0,o.jsx)(cz,{onClick:()=>u!==``&&void S(u),disabled:f||u===``,children:t(`dirPicker.home`)}),(0,o.jsx)(cz,{onClick:()=>C!==void 0&&void S(C),disabled:f||C===void 0,children:t(`dirPicker.up`)}),(0,o.jsx)(`code`,{style:{fontSize:12,opacity:.75,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:n})]}),(0,o.jsxs)(`div`,{style:{flex:1,minHeight:140,maxHeight:320,overflowY:`auto`,border:`1px solid rgba(127,127,127,.3)`,borderRadius:6,padding:4},children:[c.map(e=>(0,o.jsxs)(`div`,{role:`button`,tabIndex:0,onClick:()=>void S(e.path),onKeyDown:t=>{t.key!==`Enter`&&t.key!==` `||(t.preventDefault(),S(e.path))},title:e.path,style:{display:`flex`,gap:6,alignItems:`center`,padding:`3px 8px`,borderRadius:4,cursor:`pointer`,fontSize:13},onMouseEnter:e=>{e.currentTarget.style.background=`rgba(77,107,254,.18)`},onMouseLeave:e=>{e.currentTarget.style.background=`transparent`},children:[(0,o.jsx)(`span`,{children:e.isSymlink?`🔗`:`📁`}),(0,o.jsx)(`span`,{style:{overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:e.name})]},e.path)),!f&&c.length===0&&m===void 0&&(0,o.jsx)(`div`,{style:{padding:8,opacity:.6,fontSize:12},children:t(`dirPicker.empty`)}),f&&(0,o.jsx)(`div`,{style:{padding:8,opacity:.6,fontSize:12},children:t(`common.loading`)})]}),m!==void 0&&(0,o.jsx)(`div`,{style:{marginTop:8,padding:`6px 10px`,borderRadius:6,fontSize:12,background:`rgba(200,60,60,.15)`,whiteSpace:`pre-wrap`,wordBreak:`break-word`},children:m}),(0,o.jsxs)(`div`,{style:{display:`flex`,gap:8,justifyContent:`flex-end`,marginTop:12},children:[(0,o.jsx)(cz,{onClick:e.onCancel,children:t(`hosts.cancel`)}),(0,o.jsx)(cz,{kind:`primary`,onClick:()=>e.onPick(n),disabled:f,children:t(`dirPicker.select`)})]})]})})}function _q(e){return e instanceof pn?e.message:String(e)}function vq(e,t,n,r){return e!==t||n!==r}function yq(e,t,n){return e&&t!==void 0&&t!==``&&t===n}function bq(e){let t=e.t,[n,r]=(0,i.useState)(e.hosts[0]?.alias??``),[a,s]=(0,i.useState)(!1),[c,l]=(0,i.useState)(!1),[u,d]=(0,i.useState)(!1),[f,p]=(0,i.useState)(void 0),[m,h]=(0,i.useState)(``),[g,_]=(0,i.useState)(``),[v,y]=(0,i.useState)(void 0),[b,x]=(0,i.useState)(void 0),[S,C]=(0,i.useState)(void 0),[w,T]=(0,i.useState)(!1),E=(0,i.useRef)(0),D=(0,i.useRef)(n);D.current=n;let O=(0,i.useRef)(!0);(0,i.useEffect)(()=>(O.current=!0,()=>{O.current=!1}),[]);let k=()=>({sequence:E.current+=1,requestAlias:n}),A=e=>!O.current||vq(e.sequence,E.current,e.requestAlias,D.current),j=e=>{r(e),s(!1),l(!1),d(!1),p(void 0),x(void 0),C(void 0)},M=()=>{if(n===``)return;let e=k();y(`test`),V.testHost(e.requestAlias).then(n=>{A(e)||(y(void 0),n.ok?(s(!0),x(`${e.requestAlias}: OK (${n.durationMs} ms)`),C(void 0)):(s(!1),C(n.error??t(`hosts.unknownError`)),x(void 0)))},t=>{A(e)||(y(void 0),s(!1),C(_q(t)),x(void 0))})},N=()=>{if(n===``)return;let e=k();y(`push`),V.deployPush(e.requestAlias).then(t=>{A(e)||(y(void 0),t.action===`failed`?(l(!1),C(t.detail),x(void 0)):(l(!0),x(t.detail),C(void 0)))},t=>{A(e)||(y(void 0),l(!1),C(_q(t)),x(void 0))})},ee=e=>{let r=(e??m).trim();if(n===``||r===``)return;e!==void 0&&h(e);let i=k();y(`verify`),V.fileOp.stat(i.requestAlias,r).then(e=>{A(i)||(y(void 0),e.isDir?(d(!0),p(i.requestAlias),x(t(`ws.directoryOk`).replace(`{path}`,r)),C(void 0)):(d(!1),p(void 0),C(t(`ws.notDirectory`).replace(`{path}`,r)),x(void 0)))},e=>{A(i)||(y(void 0),d(!1),p(void 0),C(_q(e)),x(void 0))})},P=()=>{if(n===``||g.trim()===``||m.trim()===``||!yq(u,f,n))return;let t=k();y(`save`),V.createWorkspace({name:g.trim(),alias:t.requestAlias,remotePath:m.trim()}).then(t=>{O.current&&(y(void 0),e.onSaved?.(t.workspace,t.aliasPath),e.onDone())},e=>{O.current&&(y(void 0),C(_q(e)),x(void 0))})},F=v!==void 0;return(0,o.jsxs)(`div`,{style:{...tz,marginTop:10,paddingTop:10},children:[(0,o.jsx)(`strong`,{children:t(`ws.new`)}),b!==void 0&&(0,o.jsx)(uz,{kind:`info`,children:b}),S!==void 0&&(0,o.jsx)(uz,{kind:`error`,children:S}),(0,o.jsx)(`div`,{style:{marginTop:8,fontWeight:600},children:t(`ws.step1`)}),(0,o.jsxs)(fz,{children:[(0,o.jsx)(`select`,{value:n,disabled:F||e.hosts.length===0,onChange:e=>j(e.target.value),style:{...rz,padding:`4px 8px`,fontSize:13,width:`auto`,flex:1},children:e.hosts.map(e=>(0,o.jsxs)(`option`,{value:e.alias,style:iz,children:[e.alias,` (`,e.user,`@`,e.host,`)`]},e.alias))}),(0,o.jsxs)(cz,{onClick:M,disabled:F||n===``,children:[t(v===`test`?`hosts.testing`:`hosts.test`),` `,a?`✓`:``]})]}),(0,o.jsx)(`div`,{style:{marginTop:8,fontWeight:600},children:t(`ws.step2`)}),(0,o.jsxs)(fz,{children:[(0,o.jsxs)(cz,{onClick:N,disabled:F||!a,children:[t(v===`push`?`hosts.pushing`:`hosts.push`),` `,c?`✓`:``]}),!a&&(0,o.jsx)(`span`,{style:{fontSize:12,opacity:.6},children:t(`ws.testFirst`)})]}),(0,o.jsx)(`div`,{style:{marginTop:8,fontWeight:600},children:t(`ws.step3`)}),(0,o.jsx)(dz,{label:t(`ws.remotePath`),children:(0,o.jsxs)(`div`,{style:{display:`flex`,gap:8},children:[(0,o.jsx)(`input`,{value:m,disabled:F||!c,onChange:e=>{h(e.target.value),d(!1),p(void 0)},placeholder:`/home/user/project`,style:nz}),(0,o.jsx)(cz,{onClick:()=>T(!0),disabled:F||!c,children:t(`ws.browse`)}),(0,o.jsxs)(cz,{onClick:()=>ee(),disabled:F||!c||m.trim()===``,children:[t(`ws.verifyPath`),` `,u&&f===n?`✓`:``]})]})}),(0,o.jsx)(dz,{label:t(`ws.name`),children:(0,o.jsx)(`input`,{value:g,disabled:F||!c,onChange:e=>_(e.target.value),placeholder:n===``?``:`${n} workspace`,style:nz})}),!c&&(0,o.jsx)(`div`,{style:{fontSize:12,opacity:.6,marginBottom:8},children:t(`ws.pushFirst`)}),(0,o.jsxs)(fz,{children:[(0,o.jsx)(cz,{kind:`primary`,onClick:P,disabled:F||!c||!yq(u,f,n)||g.trim()===``,children:t(v===`save`?`common.loading`:`ws.save`)}),(0,o.jsx)(cz,{onClick:e.onCancel,disabled:F,children:t(`hosts.cancel`)})]}),(0,o.jsx)(gq,{t,open:w,title:t(`dirPicker.title`),alias:n,initialPath:m,onPick:e=>{T(!1),d(!1),p(void 0),ee(e)},onCancel:()=>T(!1)})]})}function xq(e){return e instanceof pn?e.message:String(e)}function Sq(e){let t=e.t,[n,r]=(0,i.useState)(!1),[a,s]=(0,i.useState)(void 0),[c,l]=(0,i.useState)(void 0),[u,d]=(0,i.useState)(void 0),f=async n=>{await hc({title:t(`ws.unbindTitle`),text:t(`ws.unbindConfirm`).replace(`{name}`,n.name),danger:!0,okText:t(`ws.delete`),cancelText:t(`common.cancel`)})&&(d(n.id),V.deleteWorkspace(n.id).then(()=>{d(void 0),s(t(`ws.removed`)),l(void 0),e.onChanged()},e=>{d(void 0),l(xq(e)),s(void 0)}))};return(0,o.jsxs)(`div`,{style:{flex:1,minHeight:0,overflow:`auto`},children:[(0,o.jsxs)(fz,{children:[(0,o.jsx)(`strong`,{style:{fontSize:14},children:t(`ws.title`)}),(0,o.jsx)(`span`,{style:{flex:1}}),(0,o.jsx)(cz,{kind:`primary`,onClick:()=>{r(!n),s(void 0),l(void 0)},disabled:e.hosts.length===0,title:e.hosts.length===0?t(`ws.empty`):void 0,children:t(`ws.new`)})]}),(0,o.jsxs)(`div`,{style:{fontSize:12,opacity:.75,marginTop:6},children:[t(`route.mode`),`: `,(0,o.jsx)(`code`,{children:e.routing.mode}),e.routing.tombstones.length>0&&(0,o.jsxs)(`span`,{children:[` · `,t(`route.tombstones`),`: `,e.routing.tombstones.length]})]}),a!==void 0&&(0,o.jsx)(uz,{kind:`info`,children:a}),c!==void 0&&(0,o.jsx)(uz,{kind:`error`,children:c}),e.workspaces.length===0&&!n&&(0,o.jsx)(`div`,{style:{opacity:.7,marginTop:10},children:t(`ws.empty`)}),e.workspaces.map(n=>(0,o.jsxs)(`div`,{style:{...tz,marginTop:10,paddingTop:8},children:[(0,o.jsxs)(fz,{children:[(0,o.jsx)(`strong`,{children:n.name}),(0,o.jsxs)(`code`,{style:{fontSize:12,opacity:.8},children:[n.alias,`:`,n.remotePath]})]}),e.routing.aliasPaths[n.id]!==void 0&&(0,o.jsxs)(`div`,{style:{fontSize:12,opacity:.6,marginTop:2},title:t(`route.aliasPath`),children:[`→ `,e.routing.aliasPaths[n.id]]}),(0,o.jsx)(`div`,{style:{marginTop:6},children:(0,o.jsxs)(fz,{children:[e.onOpenFiles!==void 0&&(0,o.jsx)(cz,{kind:`primary`,onClick:()=>e.onOpenFiles?.(n.id),children:t(`ws.open`)}),(0,o.jsx)(cz,{kind:`danger`,onClick:()=>{f(n)},disabled:u!==void 0,children:t(`ws.delete`)})]})})]},n.id)),n&&(0,o.jsx)(bq,{t,hosts:e.hosts,onDone:()=>{r(!1),s(t(`ws.saved`)),l(void 0),e.onChanged()},onCancel:()=>r(!1)})]})}let Cq=`dsh-remote-vs.showHidden`;function wq(e){return{dirty:e.filter(e=>e.dirty).length,reload:e.filter(e=>!e.loading&&!e.dirty&&(e.kind===`file`||e.kind===`diff`)).map(e=>e.id)}}let Tq=e=>({t:e.t,ready:e.ready,view:e.view,hosts:e.hosts,workspaces:e.workspaces,routing:e.routing,workspace:e.workspace,aliasPaths:e.aliasPaths,error:e.error,repoRoot:e.repoRoot,head:e.head,gitBusy:e.gitBusy,editorSurface:e.editorSurface,floatOpen:e.floatOpen,terminalRequest:e.terminalRequest,tabs:e.tabs,activeTab:e.activeTab,buckets:e.buckets,selectWorkspace:e.selectWorkspace,refreshAll:e.refreshAll,reloadTab:e.reloadTab,info:e.info}),Eq=(0,i.memo)(GW),Dq=(0,i.memo)(cK),Oq=(0,i.memo)(GG),kq=(0,i.memo)(hq),Aq=(0,i.memo)(PH),jq=(0,i.memo)(EU),Mq=(0,i.memo)(Sq),Nq=(0,i.memo)(qV),Pq=(0,i.memo)(JV);function Fq(e){return kd(e.ctx),(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(vc,{}),(0,o.jsx)(Iq,{ctx:e.ctx,visible:e.visible!==!1})]})}function Iq(e){let t=gl(Tq,hl),n=t.t,r=t.view,a=(0,i.useRef)(t.tabs);a.current=t.tabs;let[s,c]=(0,i.useState)(()=>{try{return localStorage.getItem(Cq)===`1`}catch{return!1}}),[l,u]=(0,i.useState)(!0),d=(0,i.useRef)(null),f=(0,i.useCallback)(e=>{if(d.current?.disconnect(),d.current=null,e===null||typeof IntersectionObserver>`u`)return;let t=new IntersectionObserver(e=>{let t=e[e.length-1];t!==void 0&&u(t.isIntersecting)});t.observe(e),d.current=t},[]),p=e.visible&&l,m=e=>p&&r===e,[h,g]=(0,i.useState)(!1),_=t.ready;(0,i.useEffect)(()=>{let e=e=>{if(!(!p||!_)&&(e.ctrlKey||e.metaKey)&&!(e.altKey||e.shiftKey)&&!(e.key!==`p`&&e.key!==`P`)&&(e.preventDefault(),!e.repeat)){if(!h){if(qD())return;let e=document.activeElement;if(e instanceof HTMLElement&&e.closest(`.xterm`)!==null||e instanceof HTMLElement&&e.closest(`.xterm, textarea, input, [contenteditable="true"]`)!==null&&e.closest(`.cm-content`)===null)return}g(e=>!e)}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[p,_,h]),(0,i.useEffect)(()=>{p||g(!1)},[p]);let v=(0,i.useCallback)(e=>{Ll(e)},[]),y=(0,i.useCallback)(()=>{Ll(`history`)},[]),b=(0,i.useCallback)(e=>{Kl(e),Ll(`explorer`)},[]),x=(0,i.useCallback)(()=>{c(e=>!e)},[]),S=t.workspace?.alias??``,C=ce();(0,i.useEffect)(()=>{L(S)},[S]),(0,i.useEffect)(()=>{if(S===``)return;let e=!1,t=async()=>{if(!document.hidden)try{let t=await V.connectionStatus();e||ne(t)}catch{}};t();let n=window.setInterval(()=>{t()},5e3);return()=>{e=!0,window.clearInterval(n)}},[S]);let w=(0,i.useRef)(void 0),T=(0,i.useRef)(C);T.current=C;let E=(0,i.useRef)(S);E.current=S,(0,i.useEffect)(()=>{w.current={alias:S,state:C?.state}},[S]),(0,i.useEffect)(()=>{let e=w.current;if(w.current={alias:S,state:C?.state},!ae(e,S,C?.state))return;let r=window.setTimeout(()=>{if(T.current?.state!==`ok`||E.current!==S)return;let e=wq(a.current);Eu();for(let n of e.reload)t.reloadTab(n);e.dirty>0?t.info(n(`connection.recoveredDirty`)):t.info(n(`connection.recovered`))},1e4);return()=>window.clearTimeout(r)},[C?.state]);let[D,O]=(0,i.useState)(()=>new Set([t.view]));(0,i.useEffect)(()=>{O(e=>e.has(r)?e:new Set(e).add(r))},[r]),(0,i.useEffect)(()=>{t.workspaces.length===0&&r!==`workspaces`&&r!==`monitor`&&v(`workspaces`)},[t.workspaces.length,r,v]);let k=sR(e.ctx);if((0,i.useEffect)(()=>{k.sessionId!==void 0&&(ou(k.sessionId),gu({sessionId:k.sessionId,workspacePath:k.sessionWorkspacePath}))},[k.sessionId,k.sessionWorkspacePath,t.ready,t.workspaces,t.aliasPaths]),(0,i.useEffect)(()=>{try{localStorage.setItem(Cq,s?`1`:`0`)}catch{}},[s]),!t.ready)return(0,o.jsx)(`div`,{className:`rvs-root`,children:(0,o.jsxs)(`div`,{className:`rvs-empty`,style:{margin:`auto`},children:[(0,o.jsx)(Tc,{}),` `,n(`common.loading`)]})});let A=t.editorSurface===`sidebar`,j=e=>{switch(e){case`search`:return(0,o.jsx)(Eq,{});case`scm`:return(0,o.jsx)(Dq,{onOpenHistory:y,visible:m(`scm`)});case`history`:return(0,o.jsx)(Oq,{});case`terminal`:return(0,o.jsx)(kq,{t:n,hosts:t.hosts,visible:m(`terminal`),request:t.terminalRequest});case`ports`:return(0,o.jsx)(Aq,{t:n,hosts:t.hosts,visible:m(`ports`)});case`monitor`:return(0,o.jsx)(jq,{t:n,hosts:t.hosts,visible:m(`monitor`)});case`workspaces`:return(0,o.jsx)(`div`,{className:`rvs-viewpad`,style:{height:`100%`},children:(0,o.jsx)(Mq,{t:n,hosts:t.hosts,workspaces:t.workspaces,routing:t.routing,onChanged:t.refreshAll,onOpenFiles:b})});case`editor`:return A?(0,o.jsx)(Nq,{visible:m(`editor`)}):(0,o.jsx)(Pq,{mode:t.floatOpen?`float`:`center`});default:return(0,o.jsx)(CW,{showHidden:s,onToggleHidden:x,visible:m(`explorer`)})}},M=(0,o.jsx)(`div`,{className:`rvs-pane grow`,children:[...D].map(e=>(0,o.jsx)(`div`,{className:`rvs-viewslot`,style:{display:r===e?`flex`:`none`},children:j(e)},e))}),N=(e,t,n,i=0)=>(0,o.jsxs)(`button`,{type:`button`,className:`rvs-rail-btn${r===e?` active`:``}`,title:t,"aria-label":t,onClick:()=>v(e),children:[n,i>0&&(0,o.jsx)(`span`,{className:`rvs-rail-badge`,children:i>99?`99+`:i})]},e);return(0,o.jsxs)(`div`,{className:`rvs-root`,ref:f,children:[(0,o.jsx)(gH,{t:n}),h&&p&&(0,o.jsx)(OU,{onClose:()=>g(!1)}),(0,o.jsxs)(`div`,{className:`rvs-rail`,children:[N(`explorer`,n(`tab.files`),(0,o.jsx)(Fs,{size:17})),N(`search`,n(`tab.search`),(0,o.jsx)(ws,{size:17})),N(`scm`,n(`tab.git`),(0,o.jsx)(js,{size:17}),t.buckets.total),N(`history`,n(`tab.history`),(0,o.jsx)(Ms,{size:17})),(0,o.jsx)(`div`,{className:`rvs-rail-sep`}),N(`editor`,t.activeTab?.rel.split(`/`).pop()??n(`tab.editor`),(0,o.jsx)(Rs,{size:17}),t.tabs.length),N(`terminal`,n(`tab.terminal`),(0,o.jsx)(Ns,{size:17})),N(`ports`,n(`tab.ports`),(0,o.jsx)(MH,{size:17})),N(`monitor`,n(`tab.monitor`),(0,o.jsx)(_U,{size:17})),N(`workspaces`,n(`tab.workspaces`),(0,o.jsx)(Ps,{size:17}),t.workspaces.length)]}),(0,o.jsxs)(`div`,{className:`rvs-column`,children:[(0,o.jsxs)(`div`,{className:`rvs-globalbar`,children:[(0,o.jsx)(`select`,{className:`rvs-select`,value:t.workspace?.id??``,onChange:e=>t.selectWorkspace(e.target.value),title:n(`files.selectWorkspace`),children:t.workspaces.map(e=>(0,o.jsxs)(`option`,{value:e.id,children:[e.name,` (`,e.alias,`)`]},e.id))}),(0,o.jsx)(jd,{}),t.repoRoot!==void 0&&t.head!==void 0&&(0,o.jsxs)(`span`,{className:`rvs-pill`,title:t.repoRoot,children:[`⑂ `,t.head.detached?n(`scm.detached`):t.head.branch,t.head.ahead>0&&` ↑${t.head.ahead}`,t.head.behind>0&&` ↓${t.head.behind}`]}),t.gitBusy&&(0,o.jsx)(Tc,{})]}),t.error!==void 0&&(0,o.jsx)(`div`,{className:`rvs-banner error`,role:`status`,children:t.error}),(0,o.jsx)(`div`,{className:`rvs-pane`,style:{flex:1,minHeight:0},children:M})]})]})}let Lq=`dsh-remote-vs`,Rq=`remote-vs-explorer`;function zq(e,t){let n;try{let t=e.get(`sidebarRightTabs`);if(n=typeof t==`object`&&t?t:void 0,typeof n?.register!=`function`)return}catch{return}let r={id:Lq,kind:Rq,keepMounted:!0,title:()=>t(`native.tab`),guide:[{id:`remote`,order:30,title:()=>t(`native.guide.title`),description:()=>t(`native.guide.desc`)}]},i;try{i=n.register(r)}catch(e){console.warn(`[dsh-remote-vs] native explorer registration failed:`,e);return}let a=t=>{let{tab:n}=t.useTabInfo();return(0,o.jsx)(Fq,{ctx:e,visible:n.visible})},s;try{s=e.slots.inject(`sidebar.right.pane.tab`,()=>e.slots.register({name:`sidebar.right.pane.tab`,key:Lq},a))}catch(e){console.warn(`[dsh-remote-vs] native explorer seat registration failed:`,e);try{i?.()}catch{}return}return()=>{try{s?.()}catch{}try{i?.()}catch{}}}let Bq,Vq,Hq=new Set;function Uq(){return Bq}function Wq(e){return Hq.add(e),()=>{Hq.delete(e)}}function Gq(e){return{autoOpenRemoteWorkspace:typeof e?.autoOpenRemoteWorkspace==`boolean`?e.autoOpenRemoteWorkspace:f.autoOpenRemoteWorkspace,remoteWorkspaceWidthRatio:typeof e?.remoteWorkspaceWidthRatio==`number`&&Number.isFinite(e.remoteWorkspaceWidthRatio)?h(e.remoteWorkspaceWidthRatio):f.remoteWorkspaceWidthRatio}}function Kq(e,t){Bq=e;for(let n of[...Hq])try{n(e,t)}catch{}return e}function qq(e=!1){if(!e&&Bq!==void 0)return Promise.resolve(Bq);if(!e&&Vq!==void 0)return Vq;let t=V.getViewSettings().then(e=>Kq(Gq(e),`load`),()=>void 0).finally(()=>{Vq===t&&(Vq=void 0)});return Vq=t,t}async function Jq(e){return Kq(Gq(await V.setViewSettings(e)),`save`)}let Yq=`[data-rightbar-col]`;function Xq(e){try{let t=e.get(`sidebarRight`);return typeof t==`object`&&t?t:void 0}catch{return}}function Zq(e){try{return Xq(e)?.active?.()?.kind===Rq}catch{return!1}}function Qq(e){let t=new Set,n=new Set,r=new Map,i,a=0,o=0,s=0,c=!1,l=Uq()?.remoteWorkspaceWidthRatio,u,d=async()=>{if(i!==void 0&&i.bindings.length>0&&Date.now()-a<3e4)return i;try{let e=await V.getWorkspaces();return i={bindings:e.workspaces,aliasPaths:e.aliasPaths},a=Date.now(),i}catch{i=void 0;return}},f=async t=>{let n=await d();if(n===void 0)return`unknown`;if(n.bindings.length===0)return`local`;let r=iR(e,t);if(r!==void 0)return Po(n,r)===void 0?`local`:`remote`;let i;try{i=(await V.sessionCwd(t)).cwd}catch{return`unknown`}return i===void 0||i===``?`unknown`:Po(n,i)===void 0?`local`:`remote`},p=t=>{let n=s+=1,r=600,i=()=>{if(c||n!==s)return;let a=document.querySelector(`[data-side="rightbar"]`);a!==null&&Zq(e)&&$q(a,t)||(--r,r>0&&requestAnimationFrame(i))};requestAnimationFrame(i)},m=t=>{let n=Xq(e);if(typeof n?.openTab!=`function`)return!1;try{n.openTab(Rq)}catch{return!1}return p(t),!0},h=e=>{let n=(r.get(e)??0)+1;if(n<10){r.set(e,n);return}r.delete(e),t.add(e)},g=async e=>{n.add(e);try{let n=await f(e);if(c)return;if(n===`unknown`){h(e);return}if(r.delete(e),t.add(e),n!==`remote`)return;let i=Uq();if(i?.autoOpenRemoteWorkspace!==!0||m(i.remoteWorkspaceWidthRatio))return;t.delete(e),h(e)}finally{n.delete(e)}},_=()=>{if(c)return;let r=rR(e);if(!(r===void 0||t.has(r)||n.has(r))){if(Uq()===void 0){let e=Date.now();e>=o&&(o=e+1e4,qq(!0));return}g(r)}},v=Wq((t,n)=>{let r=l;if(l=t.remoteWorkspaceWidthRatio,n!==`save`||r===t.remoteWorkspaceWidthRatio)return;let i=Xq(e);typeof i?.isExpanded==`function`&&i.isExpanded()&&Zq(e)&&p(t.remoteWorkspaceWidthRatio)});return qq(),u=setInterval(_,1500),u.unref?.(),()=>{c=!0,s+=1,v(),u!==void 0&&(clearInterval(u),u=void 0)}}function $q(e,t){let n=document.documentElement.clientWidth;if(n<=0)return!1;let r=Math.min(Math.max(Math.round(n*h(t)),300),Math.max(300,Math.round(n*.7))),i=eJ(e,n);if(i===void 0)return!1;let a=Math.round(i)-r;if(Math.abs(a)<1)return!0;let o=Math.round(e.getBoundingClientRect().left);return rJ(e,()=>{iJ(e,()=>{tJ(e,`pointerdown`,o),tJ(e,`pointerup`,o+a)})}),!0}function eJ(e,t){let n=Number.parseFloat(e.style.left);if(Number.isFinite(n)&&n>=0&&n<=t){let e=t-n;if(e>=300/2)return e}let r=document.querySelector(Yq);if(r!==null){let e=r.getBoundingClientRect().width;if(e>0)return e}let i=e.parentElement;if(i!==null){let e=getComputedStyle(i).gridTemplateColumns.trim().split(/\s+/),t=e[e.length-1],n=t===void 0?NaN:Number.parseFloat(t);if(Number.isFinite(n)&&n>0)return n}let a=t-e.getBoundingClientRect().left-4;return a>0?a:void 0}function tJ(e,t,n){let r=e.getBoundingClientRect();e.dispatchEvent(new PointerEvent(t,{bubbles:!0,cancelable:!0,composed:!0,pointerId:1,pointerType:`mouse`,isPrimary:!0,button:0,buttons:+(t===`pointerdown`),clientX:n,clientY:Math.round(r.top+r.height/2)}))}let nJ=[`setPointerCapture`,`hasPointerCapture`,`releasePointerCapture`];function rJ(e,t){let n=nJ.map(t=>Object.getOwnPropertyDescriptor(e,t));for(let t of nJ)Object.defineProperty(e,t,{configurable:!0,writable:!0,value:t===`hasPointerCapture`?()=>!1:()=>void 0});try{t()}finally{nJ.forEach((t,r)=>{let i=n[r];i===void 0?Reflect.deleteProperty(e,t):Object.defineProperty(e,t,i)})}}function iJ(e,t){let n=e.parentElement,r=document.querySelector(Yq),i=[];for(let e of[n,r])e instanceof HTMLElement&&i.push(e);if(i.length===0){t();return}let a=i.map(e=>e.style.transition);for(let e of i)e.style.transition=`none`;t(),requestAnimationFrame(()=>{i.forEach((e,t)=>{e.style.transition=a[t]??``})})}function aJ(...e){try{if(typeof localStorage>`u`||localStorage.getItem(`dsh-remote-vs.debug`)!==`1`)return}catch{return}console.info(`[rvs-flow]`,...e)}function oJ(e){if(typeof e==`object`&&e&&`rpcError`in e){let t=e.rpcError;if(typeof t==`object`&&t&&`message`in t&&typeof t.message==`string`)return t.message}return e instanceof Error?e.message:String(e)}function sJ(e){if(typeof e==`object`&&e&&`rpcError`in e){let t=e.rpcError;if(typeof t==`object`&&t&&`code`in t)return t.code===`directory-picker/unavailable`}return oJ(e).includes(`directory-picker/unavailable`)}function cJ(e){let{t,busy:n,injected:r}=e,[a,s]=(0,i.useState)(`probing`),[c,l]=(0,i.useState)(void 0),[u,d]=(0,i.useState)(``),[f,p]=(0,i.useState)(!1),[m,h]=(0,i.useState)(void 0),[g,_]=(0,i.useState)(void 0),[v,y]=(0,i.useState)(!1),[b,x]=(0,i.useState)(``),S=(0,i.useRef)(0),C=async e=>{let t=++S.current;p(!0),h(void 0);try{let n=await r.listDirectory(e);if(t!==S.current)return;l(n),d(n.path),s(`browse`)}catch(e){if(t!==S.current)return;sJ(e)?(aJ(`browse unavailable -> native`),s(`native`)):(aJ(`browse failed`,oJ(e)),s(a===`browse`?`browse`:`failed`),h(oJ(e)))}finally{t===S.current&&p(!1)}},w=()=>{let e=u.trim();e!==``&&C(e)},T=()=>{let e=b.trim(),t=c?.path;if(e===``||t===void 0)return;let n=++S.current;p(!0),h(void 0),r.createDirectory(t,e).then(e=>{n===S.current&&(y(!1),x(``),p(!1),C(e))},e=>{n===S.current&&(p(!1),h(oJ(e)))})},E=()=>{let n=++S.current,i=e.flowEpoch.current;p(!0),h(void 0),_(void 0),aJ(`native chooser requested`),r.pickDirectory().then(r=>{if(e.flowEpoch.current!==i){aJ(`native chooser result dropped (another open request)`,r);return}n!==S.current&&aJ(`native chooser result adopted after remount`,r),aJ(`native chooser returned`,r===null?`cancelled`:r),p(!1),r===null?_(t(`flow.nativeCancelled`)):e.onPicked(r)},t=>{e.flowEpoch.current===i&&(aJ(`native chooser failed`,oJ(t)),p(!1),h(oJ(t)))})};(0,i.useEffect)(()=>(S.current+=1,l(void 0),h(void 0),_(void 0),s(`probing`),C(void 0),()=>{S.current+=1}),[]);let D=n||f,O=n||f||a===`probing`;if(a===`probing`&&c===void 0&&m===void 0)return(0,o.jsx)(`div`,{style:{padding:12,opacity:.6,fontSize:12},children:t(`common.loading`)});if(a===`native`)return(0,o.jsxs)(`div`,{style:{padding:`4px 0`},children:[(0,o.jsx)(`div`,{style:{fontSize:12,opacity:.75,marginBottom:10},children:t(`flow.nativeHint`)}),g!==void 0&&(0,o.jsx)(uz,{kind:`info`,children:g}),m!==void 0&&(0,o.jsx)(uz,{kind:`error`,children:m}),(0,o.jsx)(cz,{kind:`primary`,onClick:E,disabled:D,children:t(`flow.nativePick`)})]});if(a===`failed`&&c===void 0)return(0,o.jsxs)(`div`,{style:{padding:`4px 0`},children:[m!==void 0&&(0,o.jsx)(uz,{kind:`error`,children:m}),(0,o.jsx)(cz,{onClick:()=>{s(`probing`),C(void 0)},disabled:D,children:t(`flow.retry`)})]});let k=c?.path??``,A=c!==void 0&&c.crumbs.length>=2?c.crumbs[c.crumbs.length-2]?.path:void 0,j=c?.home;return(0,o.jsxs)(`div`,{children:[(0,o.jsxs)(`div`,{style:{display:`flex`,gap:8,marginBottom:8},children:[(0,o.jsx)(`input`,{value:u,onChange:e=>d(e.target.value),onKeyDown:e=>{e.nativeEvent.isComposing===!0||e.keyCode===229||e.key===`Enter`&&w()},disabled:O,spellCheck:!1,style:{flex:1,background:`rgba(127,127,127,.12)`,color:`inherit`,border:`1px solid rgba(127,127,127,.35)`,borderRadius:6,padding:`4px 8px`,fontSize:13,fontFamily:`inherit`,outline:`none`}}),(0,o.jsx)(cz,{onClick:w,disabled:O||u.trim()===``,children:t(`dirPicker.go`)})]}),(0,o.jsxs)(`div`,{style:{display:`flex`,gap:8,alignItems:`center`,marginBottom:8},children:[(0,o.jsx)(cz,{onClick:()=>j!==void 0&&void C(j),disabled:O||j===void 0,children:t(`dirPicker.home`)}),(0,o.jsx)(cz,{onClick:()=>A!==void 0&&void C(A),disabled:O||A===void 0,children:t(`dirPicker.up`)}),(0,o.jsx)(`code`,{style:{fontSize:12,opacity:.75,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:k})]}),(0,o.jsxs)(`div`,{style:{minHeight:120,maxHeight:240,overflowY:`auto`,border:`1px solid rgba(127,127,127,.3)`,borderRadius:6,padding:4},children:[(c?.entries??[]).filter(e=>!e.hidden).map(e=>(0,o.jsxs)(`div`,{role:`button`,tabIndex:O?-1:0,"aria-disabled":O===!0||void 0,onClick:()=>{O||C(e.path)},onKeyDown:t=>{O||t.key!==`Enter`&&t.key!==` `||(t.preventDefault(),C(e.path))},title:e.path,style:{display:`flex`,gap:6,alignItems:`center`,padding:`3px 8px`,borderRadius:4,cursor:O?`default`:`pointer`,fontSize:13},onMouseEnter:e=>{O||(e.currentTarget.style.background=`rgba(77,107,254,.18)`)},onMouseLeave:e=>{e.currentTarget.style.background=`transparent`},children:[(0,o.jsx)(`span`,{children:`📁`}),(0,o.jsx)(`span`,{style:{overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:e.name})]},e.path)),!f&&(c?.entries??[]).length===0&&m===void 0&&(0,o.jsx)(`div`,{style:{padding:8,opacity:.6,fontSize:12},children:t(`dirPicker.empty`)}),f&&(0,o.jsx)(`div`,{style:{padding:8,opacity:.6,fontSize:12},children:t(`common.loading`)})]}),c?.truncated===!0&&(0,o.jsx)(`div`,{style:{fontSize:12,opacity:.6,marginTop:4},children:t(`flow.truncated`)}),m!==void 0&&(0,o.jsx)(uz,{kind:`error`,children:m}),v?(0,o.jsxs)(`div`,{style:{display:`flex`,gap:8,marginTop:8},children:[(0,o.jsx)(`input`,{value:b,onChange:e=>x(e.target.value),onKeyDown:e=>{e.nativeEvent.isComposing===!0||e.keyCode===229||e.key===`Enter`&&T()},placeholder:t(`flow.mkdirName`),disabled:D,spellCheck:!1,style:{flex:1,background:`rgba(127,127,127,.12)`,color:`inherit`,border:`1px solid rgba(127,127,127,.35)`,borderRadius:6,padding:`4px 8px`,fontSize:13,fontFamily:`inherit`,outline:`none`}}),(0,o.jsx)(cz,{kind:`primary`,onClick:T,disabled:D||b.trim()===``,children:t(`flow.create`)}),(0,o.jsx)(cz,{onClick:()=>{y(!1),x(``)},disabled:D,children:t(`hosts.cancel`)})]}):(0,o.jsxs)(`div`,{style:{display:`flex`,gap:8,marginTop:8},children:[(0,o.jsx)(cz,{onClick:()=>y(!0),disabled:O||k===``,children:t(`flow.mkdir`)}),(0,o.jsx)(`span`,{style:{flex:1}}),(0,o.jsx)(cz,{kind:`primary`,onClick:()=>e.onPicked(k),disabled:O||k===``,children:t(`flow.open`)})]})]})}function lJ(e){let{t}=e,[n,r]=(0,i.useState)(void 0),[a,s]=(0,i.useState)(void 0),[c,l]=(0,i.useState)(!1);return(0,i.useEffect)(()=>{let e=!0;return V.getHosts().then(t=>{e&&r(t)},t=>{e&&s(t instanceof pn?t.message:String(t))}),()=>{e=!1}},[]),a===void 0?n===void 0?(0,o.jsx)(`div`,{style:{padding:12,opacity:.6,fontSize:12},children:t(`common.loading`)}):n.length===0?(0,o.jsx)(`div`,{style:{padding:`4px 0`},children:(0,o.jsx)(uz,{kind:`info`,children:t(`flow.noHosts`)})}):c||e.busy?(0,o.jsx)(`div`,{style:{padding:12,opacity:.6,fontSize:12},children:t(`common.loading`)}):(0,o.jsx)(`div`,{style:{maxHeight:420,overflowY:`auto`,paddingRight:2},children:(0,o.jsx)(bq,{t,hosts:n,onDone:()=>void 0,onCancel:e.onCancel,onSaved:(t,n)=>{l(!0),aJ(`remote wizard saved`,n),e.onPicked(n)}})}):(0,o.jsx)(`div`,{style:{padding:`4px 0`},children:(0,o.jsx)(uz,{kind:`error`,children:a})})}function uJ(e){let[t]=(0,i.useState)(()=>fe(de())),[n,r]=(0,i.useState)(`local`),[a,s]=(0,i.useState)(0),c=(0,i.useRef)(0),l=t=>{aJ(`finish`,t),e.onCancel(),e.onPicked(t)},u=(0,i.useRef)(!1);(0,i.useEffect)(()=>{e.open&&!u.current&&(r(`local`),c.current+=1,s(c.current)),aJ(`open`,e.open),u.current=e.open},[e.open]);let d=(0,i.useRef)(null),f=(0,i.useRef)(null),p=(0,i.useRef)(e.onCancel);p.current=e.onCancel;let m=(0,i.useRef)(e.busy);if(m.current=e.busy,(0,i.useEffect)(()=>{if(!e.open)return;f.current=typeof document>`u`?null:document.activeElement;let t=window.setTimeout(()=>{d.current?.querySelector(`button:not([disabled])`)?.focus()},0),n=e=>{e.key!==`Escape`||m.current||(e.preventDefault(),p.current())};return window.addEventListener(`keydown`,n),()=>{window.clearTimeout(t),window.removeEventListener(`keydown`,n);let e=f.current;e!==null&&document.body.contains(e)&&e.focus()}},[e.open]),!e.open)return null;let h={listDirectory:e.listDirectory,createDirectory:e.createDirectory,pickDirectory:e.pickDirectory};return(0,o.jsx)(`div`,{style:{position:`fixed`,inset:0,zIndex:1e3,display:`grid`,placeItems:`center`,background:`rgba(0,0,0,.45)`},role:`dialog`,"aria-modal":`true`,"aria-label":t(`flow.title`),onClick:()=>{e.busy||e.onCancel()},children:(0,o.jsxs)(`div`,{ref:d,style:{width:`min(600px, calc(100vw - 32px))`,maxHeight:`min(680px, calc(100vh - 32px))`,display:`flex`,flexDirection:`column`,background:`Canvas`,color:`CanvasText`,border:`1px solid rgba(127,127,127,.4)`,borderRadius:8,padding:14,fontSize:13},onClick:e=>e.stopPropagation(),children:[(0,o.jsxs)(`div`,{style:{display:`flex`,gap:8,alignItems:`center`,marginBottom:10},children:[(0,o.jsx)(`strong`,{children:t(`flow.title`)}),(0,o.jsx)(`span`,{style:{flex:1}}),(0,o.jsx)(`button`,{type:`button`,onClick:()=>r(`local`),disabled:e.busy,style:{background:n===`local`?`rgba(77,107,254,.25)`:`rgba(127,127,127,.12)`,color:`inherit`,border:`1px solid ${n===`local`?`rgba(77,107,254,.6)`:`rgba(127,127,127,.3)`}`,borderRadius:6,padding:`4px 12px`,fontSize:13,cursor:`pointer`},children:t(`flow.local`)}),(0,o.jsx)(`button`,{type:`button`,onClick:()=>r(`remote`),disabled:e.busy,style:{background:n===`remote`?`rgba(77,107,254,.25)`:`rgba(127,127,127,.12)`,color:`inherit`,border:`1px solid ${n===`remote`?`rgba(77,107,254,.6)`:`rgba(127,127,127,.3)`}`,borderRadius:6,padding:`4px 12px`,fontSize:13,cursor:`pointer`},children:t(`flow.remote`)})]}),(0,o.jsx)(`div`,{style:{flex:1,minHeight:0,overflowY:`auto`},children:n===`local`?(0,o.jsx)(cJ,{t,busy:e.busy,injected:h,flowEpoch:c,onPicked:l},`local-${a}`):(0,o.jsx)(lJ,{t,busy:e.busy,onPicked:l,onCancel:e.onCancel},`remote-${a}`)}),(0,o.jsx)(`div`,{style:{display:`flex`,gap:8,justifyContent:`flex-end`,marginTop:12},children:(0,o.jsx)(cz,{onClick:e.onCancel,disabled:e.busy,children:t(`hosts.cancel`)})})]})})}let dJ=`dsh-remote-vs.float.rect`,fJ=`dsh-remote-vs.float.font`,pJ=`dsh-remote-vs.float.ball`,mJ=[`n`,`s`,`e`,`w`,`ne`,`nw`,`se`,`sw`];function hJ(){return{width:window.innerWidth,height:window.innerHeight}}function gJ(){let e=hJ();try{let t=Ba(localStorage.getItem(dJ),e);if(t!==void 0)return t}catch{}return Fa(e)}function _J(){try{return Ua(localStorage.getItem(fJ))}catch{return 13}}function vJ(){let e=hJ();try{return qa(localStorage.getItem(pJ),e)}catch{return}}function yJ(e){kd(e.ctx);let t=pl(),n=t.t,r=t.floatOpen,a=t.activeTab,[s,c]=(0,i.useState)(void 0),[l,u]=(0,i.useState)(()=>typeof window>`u`?{width:0,height:0}:hJ()),[d,f]=(0,i.useState)(13),[p,m]=(0,i.useState)(!1),[h,g]=(0,i.useState)(!1),[_,v]=(0,i.useState)(!1),[y,b]=(0,i.useState)(void 0),x=(0,i.useRef)(l);x.current=l;let S=(0,i.useRef)(void 0),C=(0,i.useRef)(void 0),w=(0,i.useRef)(null),T=(0,i.useRef)(d);T.current=d;let E=s!==void 0,D=(0,i.useRef)(r),O=(e,t,n)=>{let r=t-e.pointerX,i=n-e.pointerY;return e.kind===`ball`?Wa({x:e.start.x+r,y:e.start.y+i},x.current):e.kind===`move`?La(e.rect,r,i,x.current):Ra(e.rect,e.handle,r,i,x.current)};(0,i.useEffect)(()=>(dd(!0),()=>dd(!1)),[]),(0,i.useEffect)(()=>{if(!r||s!==void 0)return;let e=hJ();u(e),c(gJ()),f(_J()),b(vJ())},[r,s]),(0,i.useEffect)(()=>{r&&!D.current&&g(!1),D.current=r},[r]),(0,i.useEffect)(()=>{let e=()=>{let e=hJ();u(e),b(t=>t===void 0?t:Wa(t,e)),c(t=>t===void 0?t:p?za(e):Ia(t,e))};return window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[p]);let k=(0,i.useCallback)(e=>{try{localStorage.setItem(dJ,Va(e))}catch{}},[]),A=(0,i.useCallback)(e=>{try{localStorage.setItem(pJ,Ja(e))}catch{}},[]);(0,i.useEffect)(()=>{if(!_)return;let e=e=>{let t=S.current;if(t===void 0)return;if(!(e.buttons&1)){S.current=void 0,v(!1);return}let n=O(t,e.clientX,e.clientY);t.kind===`ball`?b(n):c(n)},t=e=>{let t=S.current;if(S.current=void 0,v(!1),t===void 0)return;let n=O(t,e.clientX,e.clientY);if(t.kind===`ball`){let r=n;b(r),A(r),Ka(e.clientX-t.pointerX,e.clientY-t.pointerY)&&g(!1);return}if(p)return;let r=n;c(r),k(r)},n=()=>{S.current=void 0,v(!1)};return window.addEventListener(`pointermove`,e),window.addEventListener(`pointerup`,t),window.addEventListener(`pointercancel`,n),()=>{window.removeEventListener(`pointermove`,e),window.removeEventListener(`pointerup`,t),window.removeEventListener(`pointercancel`,n)}},[_,p,k,A]),(0,i.useEffect)(()=>{let e=w.current;if(e===null)return;let t=e=>{if(!(e.ctrlKey||e.metaKey))return;e.preventDefault();let t=Ha(T.current,e.deltaY);if(t!==T.current){T.current=t,f(t);try{localStorage.setItem(fJ,String(t))}catch{}window.requestAnimationFrame(()=>window.dispatchEvent(new Event(`resize`)))}};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[r,h,E]);let j=(e,t)=>{if(e.button===0){e.preventDefault();try{e.currentTarget.setPointerCapture(e.pointerId)}catch{}S.current=t,v(!0)}},M=()=>{if(s===void 0)return;let e=hJ();if(u(e),p){m(!1),g(!1),c(Ia(C.current??Fa(e),e));return}C.current=s,m(!0),g(!1),c(za(e))},N=()=>{!h&&s!==void 0&&b(y===void 0?Ga(s,x.current):Wa(y,x.current)),g(!h)},ee=(0,i.useMemo)(()=>(0,o.jsx)(`div`,{className:`rvs-float-body`,ref:w,style:{display:h?`none`:`flex`},children:(0,o.jsx)(qV,{visible:!h})}),[h]);if(!r||s===void 0)return null;let P=Wa(y??Ga(s,l),l),F=h?{left:P.x,top:P.y,width:44,height:44}:{left:s.x,top:s.y,width:s.width,height:s.height,"--rvs-editor-font-size":`${d}px`};return(0,o.jsxs)(`div`,{className:`rvs-root rvs-float-window${h?` rvs-float-mini`:``}${_?` dragging`:``}`,style:F,"data-rvs-float":h?`collapsed`:`open`,"data-rvs-float-maximized":p?`true`:void 0,title:h?n(`float.ballHint`):void 0,onPointerDown:h?e=>{e.button===0&&j(e,{kind:`ball`,pointerX:e.clientX,pointerY:e.clientY,start:P})}:void 0,children:[h?(0,o.jsxs)(`div`,{className:`rvs-float-ball`,role:`button`,tabIndex:0,"aria-label":n(`float.ballHint`),title:n(`float.ballHint`),onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),g(!1))},children:[(0,o.jsx)(`span`,{className:`rvs-float-ball-glyph`,"aria-hidden":`true`,children:`▣`}),a!==void 0&&a.dirty&&(0,o.jsx)(`span`,{className:`rvs-float-ball-dot`,title:n(`editor.unsaved`),"aria-hidden":`true`})]}):(0,o.jsxs)(`div`,{className:`rvs-float-titlebar`,onPointerDown:e=>{s===void 0||p||e.target.closest(`button`)===null&&j(e,{kind:`move`,pointerX:e.clientX,pointerY:e.clientY,rect:s})},onDoubleClick:e=>{e.target.closest(`button`)===null&&M()},title:n(`float.dragHint`),children:[(0,o.jsx)(`span`,{className:`rvs-float-glyph`,"aria-hidden":`true`,children:`▣`}),(0,o.jsx)(`span`,{className:`rvs-float-title`,children:n(`float.title`)}),a!==void 0&&(0,o.jsx)(`span`,{className:`rvs-float-file`,title:a.fullPath,children:a.rel}),(0,o.jsx)(`span`,{className:`rvs-float-spacer`}),(0,o.jsx)(`button`,{type:`button`,className:`rvs-float-btn`,title:n(`float.minimize`),"aria-label":n(`float.minimize`),onClick:N,children:`—`}),(0,o.jsx)(`button`,{type:`button`,className:`rvs-float-btn`,title:n(p?`float.restore`:`float.maximize`),"aria-label":n(p?`float.restore`:`float.maximize`),onClick:M,children:p?`❐`:`□`}),(0,o.jsx)(`button`,{type:`button`,className:`rvs-float-btn rvs-float-close`,title:n(`float.dock`),"aria-label":n(`float.dock`),onClick:()=>{t.dockFloatingEditor()},children:(0,o.jsx)(ys,{size:12})})]}),ee,(0,o.jsx)(vc,{}),!h&&!p&&mJ.map(e=>(0,o.jsx)(`div`,{className:`rvs-float-resize rvs-float-resize-${e}`,"data-rvs-float-resize":e,onPointerDown:t=>{s!==void 0&&j(t,{kind:`resize`,handle:e,pointerX:t.clientX,pointerY:t.clientY,rect:s})}},e))]})}function bJ(e,t){if(typeof document>`u`||e===``)return()=>{};let n=n=>{if(n.button!==0)return;let r=n.target;if(!(r instanceof Element)||r.closest(`.rvs-root`)!==null)return;let i=r.closest(`button, [role="tab"], [role="button"]`);if(i!==null&&(i.textContent??``).trim()===e)try{t()}catch{}};return document.addEventListener(`dblclick`,n,!0),()=>document.removeEventListener(`dblclick`,n,!0)}async function xJ(e,t,n,r){if(n.connection(e)===`error`)return{kind:`unknown`};for(let i of t){let t;try{t=await n.deadline(n.stat(e,i),r)}catch(e){if(n.isLinkFailure(e))return{kind:`unknown`};continue}return t===void 0?{kind:`unknown`}:{kind:`exists`,path:i}}return{kind:`missing`}}let SJ=new WeakMap;function CJ(e,t){return new Promise((n,r)=>{let i=setTimeout(()=>n(void 0),t);i.unref?.(),e.then(e=>{clearTimeout(i),n(e)},e=>{clearTimeout(i),r(e)})})}function wJ(e){if(typeof e!=`object`||!e)return;let t=e,n=t.line??t.params?.line;return typeof n==`number`&&Number.isInteger(n)&&n>0?n:void 0}async function TJ(e,t){let n=Fo(e.remotePath,t);if(n===void 0)return;let r=await CJ(V.exec(e.alias,n,6e3),7e3).catch(()=>void 0);if(r!==void 0)return Io(e.remotePath,t,r.stdout)}function EJ(e,t,n,r){let i=Wu();if(i.bindings.length===0)return!1;let a=wJ(r);if(t.scope===`absolute`){let e=Lo({address:n,table:i});return e!==void 0&&Gu(e.binding.id,e.candidates[0],a===void 0?{}:{line:a})}let o=iR(e,t.sessionId);if(o===void 0)return!1;let s=Lo({address:n,table:i,sessionWorkspacePath:o});if(s===void 0)return!1;let c=t.path.replace(/\\/g,`/`),l=c.startsWith(`/`)||/^[A-Za-z]:\//.test(c)||c.startsWith(`//`)?void 0:c.replace(/^(?:\.\/)+/,``);return(async()=>{let e=s;try{let r=(await CJ(V.sessionCwd(t.sessionId),1500))?.cwd;typeof r==`string`&&r!==``&&(e=Lo({address:n,table:i,sessionWorkspacePath:o,sessionCwd:r})??s)}catch{}let r=t=>{Gu(e.binding.id,t,a===void 0?{}:{line:a})},c=await xJ(e.binding.alias,e.candidates,{stat:V.fileOp.stat,deadline:CJ,connection:se,isLinkFailure:A},4e3);if(c.kind===`exists`){r(c.path);return}if(c.kind===`missing`&&l!==void 0){let t=await TJ(e.binding,l);if(t!==void 0){r(t);return}}r(e.candidates[0])})().catch(e=>{console.warn(`[dsh-remote-vs] remote file click could not open the remote editor:`,e)}),!0}function DJ(e){let t=!1,n,r=()=>{n!==void 0&&(clearInterval(n),n=void 0)},i=()=>{if(t)return!0;let n;try{n=e.get(`sidebarRight`)}catch{return!1}if(n===void 0)return!1;let i=n;if(typeof i.openResource!=`function`)return!1;if(SJ.has(n))return r(),!0;let a=i.openResource.bind(i),o=(t,n)=>{try{if(!Ku())return a(t,n);let r=ho(t);return r===void 0?a(t,n):EJ(e,r,t,n)===!0?void 0:a(t,n)}catch{return a(t,n)}};try{i.openResource=o,SJ.set(n,a)}catch{return!1}return r(),!0};return i()||(n=setInterval(()=>{i()&&r()},500),n.unref?.()),()=>{t=!0,r();let n;try{n=e.get(`sidebarRight`)}catch{n=void 0}if(n===void 0)return;let i=SJ.get(n);if(i!==void 0){try{n.openResource=i}catch{}SJ.delete(n)}}}function OJ(e){kd(e.ctx);let t=pl();return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(vc,{}),(0,o.jsx)(`div`,{className:`rvs-root rvs-center`,children:(0,o.jsxs)(`div`,{className:`rvs-column`,children:[(0,o.jsxs)(`div`,{className:`rvs-globalbar`,title:t.floatAvailable?t.t(`float.dockViewHint`):t.t(`float.unavailable`),children:[(0,o.jsx)(`select`,{className:`rvs-select`,value:t.workspace?.id??``,onChange:e=>t.selectWorkspace(e.target.value),title:t.t(`files.selectWorkspace`),children:t.workspaces.map(e=>(0,o.jsxs)(`option`,{value:e.id,children:[e.name,` (`,e.alias,`)`]},e.id))}),t.repoRoot!==void 0&&t.head!==void 0&&(0,o.jsxs)(`span`,{className:`rvs-pill`,title:t.repoRoot,children:[`⑂ `,t.head.detached?t.t(`scm.detached`):t.head.branch,t.head.ahead>0&&` ↑${t.head.ahead}`,t.head.behind>0&&` ↓${t.head.behind}`]})]}),t.editorSurface===`center`?(0,o.jsx)(qV,{visible:!0}):(0,o.jsx)(JV,{mode:t.floatOpen?`float`:`sidebar`})]})})]})}let kJ=`rvs.changes.scope`;function AJ(e){return e===`turn`?`turn`:`session`}function jJ(e){return e}function MJ(e){return e!==void 0&&e.turn>0}let NJ={statsOnly:`changes.turnStatsOnly`,unavailable:`changes.turnUnavailable`,stale:`changes.turnStaleFallback`,missing:`changes.diffMissing`,truncated:`changes.diffTruncated`,empty:`changes.diffEmpty`};function PJ(e,t){if(t===void 0||t.cached!==!0){let n=t?.reason??(e!==null&&e.kind===`unavailable`?e.reason:void 0);return{action:`closed`,noteKey:NJ.statsOnly,...n===void 0?{}:{detail:n}}}return e===null?{action:`closed`,noteKey:NJ.unavailable}:e.kind===`stale`?{action:`fallback`,noteKey:NJ.stale}:e.kind===`unavailable`?{action:`closed`,noteKey:NJ.unavailable,...e.reason===void 0?{}:{detail:e.reason}}:e.kind===`binary`?{action:`binary`}:e.kind===`missing`?{action:`closed`,noteKey:NJ.missing}:e.truncated===!0?{action:`closed`,noteKey:NJ.truncated}:e.hunks.length===0?{action:`closed`,noteKey:NJ.empty}:{action:`use`,diff:e}}function FJ(e,t){return e.action===`fallback`?{scope:`session`,keepNote:!0}:{scope:t,keepNote:!1}}function IJ(e,t){let n=[],r=0,i=0;for(let a of e)t.has(a.path)||(n.push(a),r+=a.added,i+=a.deleted);return{visible:n,hidden:e.length-n.length,added:r,deleted:i}}function LJ(e){return e.hidden<=0||e.visible>0?!1:e.truncated!==!0&&e.pending!==!0}function RJ(e,t){return t===void 0||!Number.isFinite(e)||!Number.isFinite(t)?!1:e-t<6e4}function zJ(e){return!e.visible||e.inFlight===!0||!Number.isFinite(e.now)?!1:e.lastForceAt===void 0||!Number.isFinite(e.lastForceAt)||e.now-e.lastForceAt>=5e3}function BJ(e){return`${e.path}\u0000${e.added}\u0000${e.deleted}\u0000${e.status??``}`}function VJ(e,t){return t[BJ(e)]===1}function HJ(e,t){let n=0;for(let r of e)VJ(r,t)&&(n+=1);return n}function UJ(e,t,n){if(e.length===0)return;let r=(n===void 0||n===``?-1:e.findIndex(e=>BJ(e)===n))+1;for(let n=0;n<e.length;n+=1){let i=e[(r+n)%e.length];if(!VJ(i,t))return i}}function WJ(e,t,n){let r=BJ(n),i={};for(let[e,n]of Object.entries(t))i[e]=n;return i[r]===1?delete i[r]:i[r]=1,KJ(e,i)}function GJ(e,t){if(!t)return{};let n={};for(let t of e)if(n[BJ(t)]!==1&&(n[BJ(t)]=1,Object.keys(n).length>=1e3))break;return n}function KJ(e,t){let n=new Set(e.map(e=>BJ(e))),r={},i=0;for(let[e,a]of Object.entries(t))if(!(a!==1||!n.has(e))&&(r[e]=1,i+=1,i>=1e3))break;return r}function qJ(e){if(typeof e!=`string`||e===``)return{};let t;try{t=JSON.parse(e)}catch{return{}}if(typeof t!=`object`||!t||Array.isArray(t))return{};let n={},r=0;for(let[e,i]of Object.entries(t))if(!(i!==1||e===``)&&(n[e]=1,r+=1,r>=1e3))break;return n}function JJ(e){return JSON.stringify(e)}let YJ=`src/client/changes/changes.css`,XJ=typeof document>`u`?void 0:Array.prototype.find.call(document.querySelectorAll(`style[data-rvs-css]`),e=>e.dataset.rvsCss===YJ);if(typeof document<`u`&&XJ===void 0){let e=document.createElement(`style`);e.dataset.rvsCss=YJ,e.textContent=`/**
7437
+ `)}}),j=0,M=e=>{if(e.preventDefault(),e.stopPropagation(),Date.now()<j){j=0;return}let t=e.clipboardData?.getData(`text/plain`)??``;A.observed(),t!==``&&i.paste(t)};e.addEventListener(`paste`,M,!0),i.attachCustomKeyEventHandler(e=>{let t=_K({type:e.type,key:e.key,ctrl:e.ctrlKey,shift:e.shiftKey,alt:e.altKey,meta:e.metaKey});if(t===void 0){if(e.type===`keydown`&&(e.ctrlKey||e.metaKey)&&!e.shiftKey&&!e.altKey&&(e.key===`b`||e.key===`B`)&&n.current.onQuickAddSnippet!==void 0){e.preventDefault();let t=i.getSelection();return n.current.onQuickAddSnippet({...t===``?{}:{selection:t},...S===``?{}:{line:S}}),!1}return!0}return t===`copy-interrupt`?i.hasSelection()?(e.preventDefault(),O(!1),!1):!0:t===`paste`?(e.preventDefault(),j=Date.now()+600,k(),!1):t===`paste-native`?(A.arm(),!0):i.hasSelection()?(e.preventDefault(),O(!1),!1):!0});let N=e=>{e.preventDefault();let t=i.hasSelection(),n=[{label:c.current(`term.copy`),disabled:yK({hasSelection:t}).copyDisabled,onSelect:()=>{O(!1),i.focus()}},{label:c.current(`term.paste`),onSelect:()=>{k(),i.focus()}},{label:c.current(`term.selectAll`),separated:!0,onSelect:()=>{i.selectAll(),i.focus()}}];s.current(e.clientX,e.clientY,n)};return e.addEventListener(`contextmenu`,N),i.focus(),()=>{r.current=void 0,a(),f(),d.dispose(),u.dispose(),window.clearTimeout(D),window.removeEventListener(`resize`,E),e.removeEventListener(`paste`,M,!0),e.removeEventListener(`contextmenu`,N),T.disconnect();try{p.close()}catch{}i.dispose()}},[]),(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(`div`,{ref:t,style:{height:`100%`,minHeight:200}}),a.menu!==void 0&&(0,o.jsx)(xc,{x:a.menu.x,y:a.menu.y,entries:a.menu.entries,onClose:a.close})]})}let PK=`dsh-remote-vs.term.snippets`;function FK(){return`s${Date.now().toString(36)}${Math.random().toString(36).slice(2,6)}`}function IK(e){let t=(e.name??``).trim().slice(0,80),n=(e.command??``).trim().slice(0,4e3);if(!(t===``||n===``))return{name:t,command:n}}function LK(e){if(typeof e!=`string`||e===``)return[];let t;try{t=JSON.parse(e)}catch{return[]}if(!Array.isArray(t))return[];let n=[],r=new Set;for(let e of t){if(typeof e!=`object`||!e)continue;let t=e,i=IK({name:typeof t.name==`string`?t.name:``,command:typeof t.command==`string`?t.command:``});if(i===void 0)continue;let a=typeof t.id==`string`&&t.id!==``?t.id:FK();if(r.has(a)&&(a=FK()),r.add(a),n.push({id:a,...i}),n.length>=200)break}return n}function RK(e){return JSON.stringify(e.map(e=>({id:e.id,name:e.name,command:e.command})))}function zK(e,t,n=FK()){let r=IK(t);if(r===void 0)return e;e.some(e=>e.id===n)&&(n=FK());let i=[...e,{id:n,...r}];return i.length>200?i.slice(i.length-200):i}function BK(e,t,n){let r=e.findIndex(e=>e.id===t);if(r<0)return e;let i=IK(n);if(i===void 0)return e;let a=e[r];if(a.name===i.name&&a.command===i.command)return e;let o=[...e];return o[r]={id:t,...i},o}function VK(e,t){let n=e.filter(e=>e.id!==t);return n.length===e.length?e:n}function HK(e,t,n){if(e.length<2)return e;let r=Math.max(0,Math.min(e.length-1,t)),i=Math.max(0,Math.min(e.length-1,n));if(r===i)return e;let a=[...e],[o]=a.splice(r,1);return o===void 0?e:(a.splice(i,0,o),a)}let UK=new Set,WK;function GK(){try{return LK(localStorage.getItem(PK))}catch{return[]}}function KK(e){try{localStorage.setItem(PK,RK(e))}catch{}}function qK(){for(let e of[...UK])try{e()}catch{}}function JK(){return WK===void 0&&(WK=GK()),WK}function YK(e){return UK.add(e),()=>{UK.delete(e)}}function XK(e){let t=JK(),n=e(t);n!==t&&(WK=n,KK(n),qK())}function ZK(e){let t=e.t,n=(0,i.useSyncExternalStore)(YK,JK,JK),[r,s]=(0,i.useState)(void 0),[c,l]=(0,i.useState)(void 0),[u,d]=(0,i.useState)(void 0),[f,p]=(0,i.useState)(void 0),m=(0,i.useRef)(null),h=(0,i.useRef)(null),g=(0,i.useRef)(e.addRequest),_=(0,i.useCallback)(()=>{let e=m.current?.getBoundingClientRect();e!=null&&s({left:Math.max(4,e.left),top:e.bottom+4,width:300})},[]),v=(0,i.useCallback)(()=>{s(void 0),d(void 0),p(void 0)},[]);(0,i.useEffect)(()=>{if(r===void 0)return;let e=h.current;if(e!==null)return(e.querySelector(`.rvs-snips-insert`)??yc(e)[0])?.focus(),()=>{let e=document.activeElement;(e===null||e===document.body||h.current?.contains(e)===!0)&&m.current?.focus()}},[r]);let y=e=>{if(e.nativeEvent.isComposing)return;if(e.key===`Escape`){e.preventDefault(),e.stopPropagation(),v();return}if(e.altKey||e.key!==`ArrowDown`&&e.key!==`ArrowUp`)return;let t=h.current;if(t===null)return;let n=Array.from(t.querySelectorAll(`.rvs-snips-insert`));if(n.length===0)return;e.preventDefault();let r=n.indexOf(document.activeElement);n[e.key===`ArrowDown`?(r+1)%n.length:r<=0?n.length-1:r-1]?.focus()};(0,i.useEffect)(()=>{e.addRequest!==g.current&&(g.current=e.addRequest,_(),l({mode:`add`,content:e.addContent}))},[e.addRequest,e.addContent,_]),(0,i.useEffect)(()=>{if(r===void 0)return;let e=e=>{let t=e.target;t instanceof Node&&h.current?.contains(t)!==!0&&m.current?.contains(t)!==!0&&v()},t=()=>v(),n=e=>{if(e.key!==`Escape`)return;let t=document.activeElement;t instanceof Node&&h.current?.contains(t)===!0||t instanceof Element&&t.closest(`.xterm`)!==null||v()};return document.addEventListener(`mousedown`,e,!0),document.addEventListener(`keydown`,n,!0),window.addEventListener(`resize`,t),()=>{document.removeEventListener(`mousedown`,e,!0),document.removeEventListener(`keydown`,n,!0),window.removeEventListener(`resize`,t)}},[r,v]);let b=t=>{if(!e.onInsert(t.command)){window.setTimeout(()=>{l(void 0)},0);return}v()},x=e=>{hc({title:t(`term.snippetDeleteTitle`),text:e.name,danger:!0,okText:t(`term.snippetDelete`)}).then(t=>{t&&XK(t=>VK(t,e.id))})},S=(e,t)=>{XK(n=>HK(n,e,e+t))},C=r===void 0?void 0:(0,a.createPortal)((0,o.jsxs)(`div`,{ref:h,className:`rvs-portal rvs-snips-panel`,role:`dialog`,"aria-label":t(`term.snippets`),onKeyDown:y,style:{left:`${r.left}px`,top:`${r.top}px`,width:`${r.width}px`},children:[(0,o.jsxs)(`div`,{className:`rvs-snips-head`,children:[(0,o.jsxs)(`span`,{className:`rvs-snips-title`,children:[`⚡ `,t(`term.snippets`)]}),(0,o.jsx)(`span`,{className:`rvs-snips-spacer`}),(0,o.jsx)(`button`,{type:`button`,className:`rvs-snips-add`,title:t(`term.snippetAdd`),"aria-label":t(`term.snippetAdd`),onClick:()=>l({mode:`add`,content:``}),children:`+`})]}),(0,o.jsxs)(`div`,{className:`rvs-snips-list`,children:[n.length===0&&(0,o.jsx)(`div`,{className:`rvs-snips-empty`,children:t(`term.snippetEmpty`)}),n.map((e,n)=>(0,o.jsxs)(`div`,{className:`rvs-snips-row${f===n&&u!==void 0?` drop`:``}`,draggable:!0,onDragStart:e=>{d({from:n}),e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,String(n))},onDragOver:e=>{u!==void 0&&(e.preventDefault(),e.dataTransfer.dropEffect=`move`,p(n))},onDrop:e=>{e.preventDefault();let t=Number(e.dataTransfer.getData(`text/plain`));d(void 0),p(void 0),Number.isFinite(t)&&XK(e=>HK(e,t,n))},onDragEnd:()=>{d(void 0),p(void 0)},children:[(0,o.jsx)(`span`,{className:`rvs-snips-grip`,title:t(`term.snippetDragHint`),role:`button`,"aria-label":t(`term.snippetDragHint`),tabIndex:0,onKeyDown:e=>{e.altKey&&e.key===`ArrowUp`&&(e.preventDefault(),S(n,-1)),e.altKey&&e.key===`ArrowDown`&&(e.preventDefault(),S(n,1))},children:`⠿`}),(0,o.jsxs)(`button`,{type:`button`,className:`rvs-snips-insert`,title:`${t(`term.snippetInsertHint`)}\n${e.command}`,onClick:()=>b(e),children:[(0,o.jsx)(`span`,{className:`rvs-snips-name`,children:e.name}),(0,o.jsx)(`span`,{className:`rvs-snips-arrow`,"aria-hidden":`true`,children:`-->`}),(0,o.jsx)(`span`,{className:`rvs-snips-text`,children:e.command})]}),(0,o.jsx)(`button`,{type:`button`,className:`rvs-snips-icon`,title:t(`term.snippetEdit`),"aria-label":t(`term.snippetEdit`),onClick:()=>l({mode:`edit`,snippet:e}),children:`✎`}),(0,o.jsx)(`button`,{type:`button`,className:`rvs-snips-icon danger`,title:t(`term.snippetDelete`),"aria-label":t(`term.snippetDelete`),onClick:()=>x(e),children:`×`})]},e.id))]}),(0,o.jsx)(`div`,{className:`rvs-snips-foot`,children:t(`term.snippetFootHint`)})]}),document.body);return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(`button`,{ref:m,type:`button`,className:`rvs-hbtn rvs-snips-btn`,title:t(`term.snippets`),"aria-label":t(`term.snippets`),onClick:()=>{r===void 0?_():v()},children:[(0,o.jsx)(`span`,{"aria-hidden":`true`,children:`⚡`}),` `,t(`term.snippets`)]}),C,c!==void 0&&(0,o.jsx)(QK,{t,mode:c.mode,...c.mode===`edit`?{snippet:c.snippet}:{initialCommand:c.content},onCancel:()=>l(void 0),onSubmit:e=>{c.mode===`add`?XK(t=>zK(t,e)):XK(t=>BK(t,c.snippet.id,e)),l(void 0),v()}})]})}function QK(e){let t=e.t,[n,r]=(0,i.useState)(e.snippet?.name??``),[s,c]=(0,i.useState)(e.snippet?.command??e.initialCommand??``),[l,u]=(0,i.useState)(void 0),d=(0,i.useRef)(null),f=(0,i.useRef)(document.activeElement);(0,i.useEffect)(()=>(d.current?.focus(),d.current?.select(),()=>{let e=f.current;e!==null&&document.body.contains(e)&&e.focus()}),[]),(0,i.useEffect)(()=>{let t=t=>{t.isComposing||t.key===`Escape`&&(t.preventDefault(),e.onCancel())};return document.addEventListener(`keydown`,t,!0),()=>document.removeEventListener(`keydown`,t,!0)},[e]);let p=()=>{if(n.trim()===``){u(t(`term.snippetNameRequired`));return}if(s.trim()===``){u(t(`term.snippetCommandRequired`));return}e.onSubmit({name:n,command:s})};return(0,a.createPortal)((0,o.jsx)(`div`,{className:`rvs-portal rvs-modal-mask`,onMouseDown:t=>{t.target===t.currentTarget&&e.onCancel()},children:(0,o.jsxs)(`div`,{className:`rvs-modal-box`,role:`dialog`,"aria-modal":`true`,"aria-label":e.mode===`add`?t(`term.snippetAdd`):t(`term.snippetEdit`),children:[(0,o.jsx)(`div`,{className:`rvs-modal-title`,children:e.mode===`add`?t(`term.snippetAdd`):t(`term.snippetEdit`)}),(0,o.jsxs)(`label`,{className:`rvs-snips-field`,children:[(0,o.jsx)(`span`,{children:t(`term.snippetName`)}),(0,o.jsx)(`input`,{ref:d,value:n,placeholder:t(`term.snippetNamePlaceholder`),onChange:e=>{r(e.target.value),u(void 0)},onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&(e.preventDefault(),p())}})]}),(0,o.jsxs)(`label`,{className:`rvs-snips-field`,children:[(0,o.jsx)(`span`,{children:t(`term.snippetCommand`)}),(0,o.jsx)(`textarea`,{className:`rvs-snips-command`,value:s,placeholder:t(`term.snippetCommandPlaceholder`),rows:4,onChange:e=>{c(e.target.value),u(void 0)}})]}),l!==void 0&&(0,o.jsx)(`div`,{className:`rvs-snips-error`,role:`alert`,children:l}),(0,o.jsxs)(`div`,{className:`rvs-modal-row`,children:[(0,o.jsx)(`button`,{type:`button`,className:`rvs-modal-btn`,onClick:e.onCancel,children:t(`common.cancel`)}),(0,o.jsx)(`button`,{type:`button`,className:`rvs-modal-btn primary`,onClick:p,children:t(`common.save`)})]})]})}),document.body)}let $K=`dsh-remote-vs.term.alias`,eq=`dsh-remote-vs.term.tabs`;function tq(){try{return localStorage.getItem($K)??``}catch{return``}}function nq(){try{let e=localStorage.getItem(eq);if(e===null)return[];let t=JSON.parse(e);if(!Array.isArray(t))return[];let n=[];for(let e of t){if(typeof e!=`object`||!e)continue;let{id:t,alias:r,session:i}=e;typeof t!=`string`||typeof r!=`string`||n.push(i===void 0||typeof i!=`string`?{id:t,alias:r}:{id:t,alias:r,session:i})}return n}catch{return[]}}function rq(e){try{let t=e.map(e=>e.session===void 0?{id:e.id,alias:e.alias}:{id:e.id,alias:e.alias,session:e.session});localStorage.setItem(eq,JSON.stringify(t))}catch{}}function iq(){return`t${Date.now().toString(36)}${Math.random().toString(36).slice(2,6)}`}let aq=0,oq,sq=new Set;function cq(e){if(oq!==e){oq=e;for(let e of[...sq])e()}}function lq(e){return sq.add(e),()=>{sq.delete(e)}}function uq(e){oq===void 0&&cq(e)}function dq(e,t){return e===t}let fq=new Set([`websocket refused`,`websocket error`]);function pq(e,t){return t===`terminal session expired`?`expired`:e===null&&(t===void 0||fq.has(t))?`reattach`:`exited`}function mq(e,t,n){let r=pq(t,n);return r===`expired`?{connected:!1,session:void 0,kind:r}:r===`reattach`?{connected:!1,session:e.session,kind:r,noteKey:`term.disconnected`}:{connected:!1,session:void 0,kind:r,...t===null?n===void 0?{noteKey:`term.closed`}:{noteText:n}:{noteText:`exit ${t}`}}}function hq(e){let t=e.t,n=(0,i.useRef)(Symbol(`terminal-surface`));uq(n.current);let r=(0,i.useSyncExternalStore)(lq,()=>dq(oq,n.current)),[a,s]=(0,i.useState)(tq),[c,l]=(0,i.useState)(()=>nq().map(e=>({id:e.id,alias:e.alias,...e.session===void 0?{}:{session:e.session},nonce:0,connected:!0}))),[u,d]=(0,i.useState)(()=>c[0]?.id),[f,p]=(0,i.useState)(void 0),m=a!==``&&e.hosts.some(e=>e.alias===a)?a:e.hosts[0]?.alias??``,h=(0,i.useRef)(!1);(0,i.useEffect)(()=>{if(!r){h.current=!1;return}let e=!h.current;h.current=!0,e&&l(e=>e.map(e=>!e.connected&&e.session!==void 0?{...e,connected:!0,nonce:e.nonce+1,note:void 0}:e))},[r]),(0,i.useEffect)(()=>{e.visible&&cq(n.current)},[e.visible]),(0,i.useEffect)(()=>{if(r)try{localStorage.setItem($K,m)}catch{}},[m,r]),(0,i.useEffect)(()=>{r&&rq(c)},[c,r]),(0,i.useEffect)(()=>{e.hosts.length!==0&&l(t=>t.filter(t=>e.hosts.some(e=>e.alias===t.alias)))},[e.hosts]);let g=(0,i.useCallback)((e,t)=>{l(n=>n.map(n=>n.id===e?{...n,...t}:n))},[]),_=(0,i.useCallback)((e,t)=>{if(e===``)return;let n={id:iq(),alias:e,nonce:0,connected:!0,...t===void 0?{}:{initialCommand:t}};l(e=>[...e,n]),d(n.id)},[]);(0,i.useEffect)(()=>{let t=e.request;if(t===void 0||t.id===aq||!r||e.visible!==!0)return;aq=t.id;let n=t.alias!==``&&e.hosts.some(e=>e.alias===t.alias)?t.alias:m;n!==a&&s(n),_(n,fo(t.dir))},[e.request,e.hosts,m,a,_,r,e.visible]);let v=(0,i.useCallback)(async e=>{if(!await hc({title:t(`term.closeTitle`),text:`${e.alias}${e.session===void 0?``:` · ${e.session.slice(0,8)}`}`,danger:!0,okText:t(`term.close`)}))return;e.session!==void 0&&V.terminalClose(e.session).catch(()=>void 0),l(t=>t.filter(t=>t.id!==e.id));let n=c.filter(t=>t.id!==e.id);d(t=>t===e.id?n[n.length-1]?.id:t)},[t,c]),y=(0,i.useCallback)((e,t)=>{if(t){let t=c.find(t=>t.id===e);t?.session!==void 0&&V.terminalClose(t.session).catch(()=>void 0)}l(n=>n.map(n=>n.id===e?{...n,nonce:n.nonce+1,connected:!0,note:void 0,...t?{session:void 0}:{}}:n))},[c]),b=c.find(e=>e.id===u)??c[0],x=t=>{let n=e.hosts.find(e=>e.alias===t);if(n!==void 0)return n.user===`root`?`/root`:`/home/${n.user}`},S=e=>{let t=c.filter(t=>t.alias===e.alias),n=t.findIndex(t=>t.id===e.id)+1,r=e.alias;return t.length>1?`${r} #${n}`:r};return r?(0,o.jsxs)(`div`,{className:`rvs-pane grow`,children:[(0,o.jsxs)(`div`,{className:`rvs-header`,children:[(0,o.jsx)(`span`,{className:`rvs-title`,children:t(`tab.terminal`)}),(0,o.jsx)(ZK,{t,addRequest:f?.id??0,addContent:f?.content??``,onInsert:e=>EK(b?.id,e)?!0:(H(t(`term.snippetNoTerminal`),!0),!1)}),(0,o.jsx)(`select`,{className:`rvs-select`,value:m,onChange:e=>s(e.target.value),disabled:e.hosts.length===0,title:t(`term.selectHost`),style:{flex:1,minWidth:90},children:e.hosts.map(e=>(0,o.jsxs)(`option`,{value:e.alias,style:iz,children:[e.alias,` (`,e.user,`@`,e.host,`)`]},e.alias))}),(0,o.jsx)(U,{title:t(`term.new`),onClick:()=>_(m),disabled:m===``,children:(0,o.jsx)(gs,{size:15})})]}),e.hosts.length===0&&(0,o.jsx)(`div`,{className:`rvs-banner warn`,children:t(`term.noHosts`)}),(0,o.jsxs)(`div`,{className:`rvs-term-tabs`,role:`tablist`,children:[c.map(e=>(0,o.jsxs)(`span`,{className:`rvs-term-tabwrap`,children:[(0,o.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":e.id===b?.id,className:`rvs-term-tab${e.id===b?.id?` active`:``}${e.note===void 0?``:` dead`}`,title:`${e.alias}${e.session===void 0?``:`\n${e.session}`}`,onClick:()=>d(e.id),onMouseDown:t=>{t.button===1&&(t.preventDefault(),v(e))},children:[(0,o.jsx)(Ns,{size:13}),(0,o.jsx)(`span`,{className:`rvs-term-name`,children:S(e)})]}),(0,o.jsx)(`button`,{type:`button`,className:`rvs-etab-close`,"aria-label":t(`term.close`),title:t(`term.close`),onMouseDown:e=>e.preventDefault(),onClick:()=>{v(e)},children:(0,o.jsx)(ys,{size:11})})]},e.id)),(0,o.jsx)(`button`,{type:`button`,className:`rvs-term-tab`,title:t(`term.new`),onClick:()=>_(m),disabled:m===``,style:{padding:`0 8px`},children:(0,o.jsx)(gs,{size:13})})]}),(0,o.jsxs)(`div`,{className:`rvs-term-body`,children:[c.length===0&&(0,o.jsx)(`div`,{className:`rvs-empty`,children:t(`term.empty`)}),c.map(n=>(0,o.jsx)(`div`,{className:`rvs-term-slot`,style:{display:n.id===b?.id?`block`:`none`},children:n.connected?(0,o.jsx)(NK,{wsUrl:V.terminalUrl({...n.session===void 0?{alias:n.alias}:{session:n.session},cols:80,rows:24}),visible:e.visible&&n.id===b?.id,t,tabId:n.id,onQuickAddSnippet:e=>{let t=(e.selection??e.line??``).trim();p(e=>({id:(e?.id??0)+1,content:t}))},...x(n.alias)===void 0?{}:{home:x(n.alias)},onPathClick:(e,t)=>{Vl(n.alias,e,t)},...n.initialCommand===void 0?{}:{initialInput:n.initialCommand},onReady:e=>g(n.id,{session:e,connected:!0,note:void 0}),onExit:(e,r)=>{let i=mq(n,e,r);if(i.kind===`expired`){g(n.id,{session:void 0,nonce:n.nonce+1,connected:!0,note:void 0});return}g(n.id,{connected:i.connected,session:i.session,note:i.noteText??(i.noteKey===void 0?void 0:t(i.noteKey))})}},`${n.id}:${n.nonce}`):(0,o.jsxs)(`div`,{className:`rvs-term-dead`,children:[n.note!==void 0&&(0,o.jsx)(`div`,{className:`rvs-empty`,children:n.note}),(0,o.jsx)(`div`,{className:`rvs-commit-row`,style:{justifyContent:`center`},children:(0,o.jsx)(`button`,{type:`button`,className:`rvs-chip primary`,onClick:()=>y(n.id,n.session===void 0),children:t(`term.reconnect`)})})]})},n.id))]})]}):null}function gq(e){let t=e.t,[n,r]=(0,i.useState)(e.initialPath),[a,s]=(0,i.useState)(e.initialPath),[c,l]=(0,i.useState)([]),[u,d]=(0,i.useState)(``),[f,p]=(0,i.useState)(!1),[m,h]=(0,i.useState)(void 0),g=(0,i.useRef)(0),_=(0,i.useRef)(null),v=(0,i.useRef)(null),y=(0,i.useRef)(null),b=(0,i.useRef)(e.onCancel);b.current=e.onCancel;let x=(0,i.useRef)(e.open);x.current=e.open;let S=async t=>{let n=++g.current;p(!0),h(void 0);try{let i=await V.fileOp.list(e.alias,t);if(n!==g.current)return;r(t),s(t),l(i.filter(e=>e.isDir||e.isSymlink))}catch(e){n===g.current&&h(e instanceof pn?e.message:String(e))}finally{n===g.current&&p(!1)}};if((0,i.useEffect)(()=>{if(!e.open)return;g.current+=1,l([]),h(void 0);let t=e.initialPath.trim()===``?void 0:e.initialPath.trim();return V.exec(e.alias,`printf %s "$HOME"`,15e3).then(e=>{let t=e.success?e.stdout.trim():``;t.startsWith(`/`)&&d(t)},()=>void 0),S(t??`/`),()=>{g.current+=1}},[e.open,e.alias]),(0,i.useEffect)(()=>{if(!e.open)return;y.current=typeof document>`u`?null:document.activeElement;let t=window.setTimeout(()=>v.current?.focus(),0),n=e=>{if(e.key===`Escape`){e.preventDefault(),b.current();return}if(e.key!==`Tab`)return;let t=_.current;if(t===null)return;let n=Array.from(t.querySelectorAll(`button:not([disabled]), input:not([disabled]), [tabindex]:not([tabindex="-1"])`));if(n.length===0)return;let r=n[0],i=n[n.length-1],a=document.activeElement;e.shiftKey&&(a===r||a===null||!t.contains(a))?(e.preventDefault(),i.focus()):!e.shiftKey&&a===i&&(e.preventDefault(),r.focus())};return window.addEventListener(`keydown`,n),()=>{window.clearTimeout(t),window.removeEventListener(`keydown`,n);let e=y.current;e!==null&&document.body.contains(e)&&e.focus()}},[e.open]),!e.open)return null;let C=n===`/`?void 0:n.replace(/\/+$/,``).split(`/`).slice(0,-1).join(`/`)||`/`,w=()=>{let e=a.trim();e!==``&&S(e)};return(0,o.jsx)(`div`,{style:{position:`fixed`,inset:0,zIndex:1e3,display:`grid`,placeItems:`center`,background:`rgba(0,0,0,.45)`},role:`dialog`,"aria-modal":`true`,"aria-label":e.title,onClick:e.onCancel,children:(0,o.jsxs)(`div`,{ref:_,style:{width:`min(560px, calc(100vw - 32px))`,maxHeight:`min(640px, calc(100vh - 32px))`,display:`flex`,flexDirection:`column`,background:`Canvas`,color:`CanvasText`,border:`1px solid rgba(127,127,127,.4)`,borderRadius:8,padding:14,fontSize:13},onClick:e=>e.stopPropagation(),children:[(0,o.jsx)(`div`,{style:{fontWeight:600,marginBottom:8},children:e.title}),(0,o.jsxs)(`div`,{style:{display:`flex`,gap:8,marginBottom:8},children:[(0,o.jsx)(`input`,{ref:v,value:a,onChange:e=>s(e.target.value),onKeyDown:e=>{e.nativeEvent.isComposing===!0||e.keyCode===229||e.key===`Enter`&&w()},placeholder:`/home/user/project`,spellCheck:!1,style:{flex:1,background:`rgba(127,127,127,.12)`,color:`inherit`,border:`1px solid rgba(127,127,127,.35)`,borderRadius:6,padding:`4px 8px`,fontSize:13,fontFamily:`inherit`,outline:`none`}}),(0,o.jsx)(cz,{onClick:w,disabled:f||a.trim()===``,children:t(`dirPicker.go`)})]}),(0,o.jsxs)(`div`,{style:{display:`flex`,gap:8,alignItems:`center`,marginBottom:8},children:[(0,o.jsx)(cz,{onClick:()=>u!==``&&void S(u),disabled:f||u===``,children:t(`dirPicker.home`)}),(0,o.jsx)(cz,{onClick:()=>C!==void 0&&void S(C),disabled:f||C===void 0,children:t(`dirPicker.up`)}),(0,o.jsx)(`code`,{style:{fontSize:12,opacity:.75,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:n})]}),(0,o.jsxs)(`div`,{style:{flex:1,minHeight:140,maxHeight:320,overflowY:`auto`,border:`1px solid rgba(127,127,127,.3)`,borderRadius:6,padding:4},children:[c.map(e=>(0,o.jsxs)(`div`,{role:`button`,tabIndex:0,onClick:()=>void S(e.path),onKeyDown:t=>{t.key!==`Enter`&&t.key!==` `||(t.preventDefault(),S(e.path))},title:e.path,style:{display:`flex`,gap:6,alignItems:`center`,padding:`3px 8px`,borderRadius:4,cursor:`pointer`,fontSize:13},onMouseEnter:e=>{e.currentTarget.style.background=`rgba(77,107,254,.18)`},onMouseLeave:e=>{e.currentTarget.style.background=`transparent`},children:[(0,o.jsx)(`span`,{children:e.isSymlink?`🔗`:`📁`}),(0,o.jsx)(`span`,{style:{overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:e.name})]},e.path)),!f&&c.length===0&&m===void 0&&(0,o.jsx)(`div`,{style:{padding:8,opacity:.6,fontSize:12},children:t(`dirPicker.empty`)}),f&&(0,o.jsx)(`div`,{style:{padding:8,opacity:.6,fontSize:12},children:t(`common.loading`)})]}),m!==void 0&&(0,o.jsx)(`div`,{style:{marginTop:8,padding:`6px 10px`,borderRadius:6,fontSize:12,background:`rgba(200,60,60,.15)`,whiteSpace:`pre-wrap`,wordBreak:`break-word`},children:m}),(0,o.jsxs)(`div`,{style:{display:`flex`,gap:8,justifyContent:`flex-end`,marginTop:12},children:[(0,o.jsx)(cz,{onClick:e.onCancel,children:t(`hosts.cancel`)}),(0,o.jsx)(cz,{kind:`primary`,onClick:()=>e.onPick(n),disabled:f,children:t(`dirPicker.select`)})]})]})})}function _q(e){return e instanceof pn?e.message:String(e)}function vq(e,t,n,r){return e!==t||n!==r}function yq(e,t,n){return e&&t!==void 0&&t!==``&&t===n}function bq(e){let t=e.t,[n,r]=(0,i.useState)(e.hosts[0]?.alias??``),[a,s]=(0,i.useState)(!1),[c,l]=(0,i.useState)(!1),[u,d]=(0,i.useState)(!1),[f,p]=(0,i.useState)(void 0),[m,h]=(0,i.useState)(``),[g,_]=(0,i.useState)(``),[v,y]=(0,i.useState)(void 0),[b,x]=(0,i.useState)(void 0),[S,C]=(0,i.useState)(void 0),[w,T]=(0,i.useState)(!1),E=(0,i.useRef)(0),D=(0,i.useRef)(n);D.current=n;let O=(0,i.useRef)(!0);(0,i.useEffect)(()=>(O.current=!0,()=>{O.current=!1}),[]);let k=()=>({sequence:E.current+=1,requestAlias:n}),A=e=>!O.current||vq(e.sequence,E.current,e.requestAlias,D.current),j=e=>{r(e),s(!1),l(!1),d(!1),p(void 0),x(void 0),C(void 0)},M=()=>{if(n===``)return;let e=k();y(`test`),V.testHost(e.requestAlias).then(n=>{A(e)||(y(void 0),n.ok?(s(!0),x(`${e.requestAlias}: OK (${n.durationMs} ms)`),C(void 0)):(s(!1),C(n.error??t(`hosts.unknownError`)),x(void 0)))},t=>{A(e)||(y(void 0),s(!1),C(_q(t)),x(void 0))})},N=()=>{if(n===``)return;let e=k();y(`push`),V.deployPush(e.requestAlias).then(t=>{A(e)||(y(void 0),t.action===`failed`?(l(!1),C(t.detail),x(void 0)):(l(!0),x(t.detail),C(void 0)))},t=>{A(e)||(y(void 0),l(!1),C(_q(t)),x(void 0))})},ee=e=>{let r=(e??m).trim();if(n===``||r===``)return;e!==void 0&&h(e);let i=k();y(`verify`),V.fileOp.stat(i.requestAlias,r).then(e=>{A(i)||(y(void 0),e.isDir?(d(!0),p(i.requestAlias),x(t(`ws.directoryOk`).replace(`{path}`,r)),C(void 0)):(d(!1),p(void 0),C(t(`ws.notDirectory`).replace(`{path}`,r)),x(void 0)))},e=>{A(i)||(y(void 0),d(!1),p(void 0),C(_q(e)),x(void 0))})},P=()=>{if(n===``||g.trim()===``||m.trim()===``||!yq(u,f,n))return;let t=k();y(`save`),V.createWorkspace({name:g.trim(),alias:t.requestAlias,remotePath:m.trim()}).then(t=>{O.current&&(y(void 0),e.onSaved?.(t.workspace,t.aliasPath),e.onDone())},e=>{O.current&&(y(void 0),C(_q(e)),x(void 0))})},F=v!==void 0;return(0,o.jsxs)(`div`,{style:{...tz,marginTop:10,paddingTop:10},children:[(0,o.jsx)(`strong`,{children:t(`ws.new`)}),b!==void 0&&(0,o.jsx)(uz,{kind:`info`,children:b}),S!==void 0&&(0,o.jsx)(uz,{kind:`error`,children:S}),(0,o.jsx)(`div`,{style:{marginTop:8,fontWeight:600},children:t(`ws.step1`)}),(0,o.jsxs)(fz,{children:[(0,o.jsx)(`select`,{className:`rvs-dropdown`,value:n,disabled:F||e.hosts.length===0,onChange:e=>j(e.target.value),style:{...rz,padding:`4px 8px`,fontSize:13,width:`auto`,flex:1},children:e.hosts.map(e=>(0,o.jsxs)(`option`,{value:e.alias,style:iz,children:[e.alias,` (`,e.user,`@`,e.host,`)`]},e.alias))}),(0,o.jsxs)(cz,{onClick:M,disabled:F||n===``,children:[t(v===`test`?`hosts.testing`:`hosts.test`),` `,a?`✓`:``]})]}),(0,o.jsx)(`div`,{style:{marginTop:8,fontWeight:600},children:t(`ws.step2`)}),(0,o.jsxs)(fz,{children:[(0,o.jsxs)(cz,{onClick:N,disabled:F||!a,children:[t(v===`push`?`hosts.pushing`:`hosts.push`),` `,c?`✓`:``]}),!a&&(0,o.jsx)(`span`,{style:{fontSize:12,opacity:.6},children:t(`ws.testFirst`)})]}),(0,o.jsx)(`div`,{style:{marginTop:8,fontWeight:600},children:t(`ws.step3`)}),(0,o.jsx)(dz,{label:t(`ws.remotePath`),children:(0,o.jsxs)(`div`,{style:{display:`flex`,gap:8},children:[(0,o.jsx)(`input`,{value:m,disabled:F||!c,onChange:e=>{h(e.target.value),d(!1),p(void 0)},placeholder:`/home/user/project`,style:nz}),(0,o.jsx)(cz,{onClick:()=>T(!0),disabled:F||!c,children:t(`ws.browse`)}),(0,o.jsxs)(cz,{onClick:()=>ee(),disabled:F||!c||m.trim()===``,children:[t(`ws.verifyPath`),` `,u&&f===n?`✓`:``]})]})}),(0,o.jsx)(dz,{label:t(`ws.name`),children:(0,o.jsx)(`input`,{value:g,disabled:F||!c,onChange:e=>_(e.target.value),placeholder:n===``?``:`${n} workspace`,style:nz})}),!c&&(0,o.jsx)(`div`,{style:{fontSize:12,opacity:.6,marginBottom:8},children:t(`ws.pushFirst`)}),(0,o.jsxs)(fz,{children:[(0,o.jsx)(cz,{kind:`primary`,onClick:P,disabled:F||!c||!yq(u,f,n)||g.trim()===``,children:t(v===`save`?`common.loading`:`ws.save`)}),(0,o.jsx)(cz,{onClick:e.onCancel,disabled:F,children:t(`hosts.cancel`)})]}),(0,o.jsx)(gq,{t,open:w,title:t(`dirPicker.title`),alias:n,initialPath:m,onPick:e=>{T(!1),d(!1),p(void 0),ee(e)},onCancel:()=>T(!1)})]})}function xq(e){return e instanceof pn?e.message:String(e)}function Sq(e){let t=e.t,[n,r]=(0,i.useState)(!1),[a,s]=(0,i.useState)(void 0),[c,l]=(0,i.useState)(void 0),[u,d]=(0,i.useState)(void 0),f=(0,i.useRef)(e.onChanged);f.current=e.onChanged;let p=e.visible!==!1;(0,i.useEffect)(()=>{if(!p)return;f.current();let e=window.setInterval(()=>{f.current()},2500);return()=>{window.clearInterval(e)}},[p]);let m=async n=>{await hc({title:t(`ws.unbindTitle`),text:t(`ws.unbindConfirm`).replace(`{name}`,n.name),danger:!0,okText:t(`ws.delete`),cancelText:t(`common.cancel`)})&&(d(n.id),V.deleteWorkspace(n.id).then(()=>{d(void 0),s(t(`ws.removed`)),l(void 0),e.onChanged()},e=>{d(void 0),l(xq(e)),s(void 0)}))};return(0,o.jsxs)(`div`,{style:{flex:1,minHeight:0,overflow:`auto`},children:[(0,o.jsxs)(fz,{children:[(0,o.jsx)(`strong`,{style:{fontSize:14},children:t(`ws.title`)}),(0,o.jsx)(`span`,{style:{flex:1}}),(0,o.jsx)(cz,{kind:`primary`,onClick:()=>{r(!n),s(void 0),l(void 0)},disabled:e.hosts.length===0,title:e.hosts.length===0?t(`ws.empty`):void 0,children:t(`ws.new`)})]}),(0,o.jsxs)(`div`,{style:{fontSize:12,opacity:.75,marginTop:6},children:[t(`route.mode`),`: `,(0,o.jsx)(`code`,{children:e.routing.mode}),e.routing.tombstones.length>0&&(0,o.jsxs)(`span`,{children:[` · `,t(`route.tombstones`),`: `,e.routing.tombstones.length]})]}),a!==void 0&&(0,o.jsx)(uz,{kind:`info`,children:a}),c!==void 0&&(0,o.jsx)(uz,{kind:`error`,children:c}),e.workspaces.length===0&&!n&&(0,o.jsx)(`div`,{style:{opacity:.7,marginTop:10},children:t(`ws.empty`)}),e.workspaces.map(n=>(0,o.jsxs)(`div`,{style:{...tz,marginTop:10,paddingTop:8},children:[(0,o.jsxs)(fz,{children:[(0,o.jsx)(`strong`,{children:n.name}),(0,o.jsxs)(`code`,{style:{fontSize:12,opacity:.8},children:[n.alias,`:`,n.remotePath]})]}),e.routing.aliasPaths[n.id]!==void 0&&(0,o.jsxs)(`div`,{style:{fontSize:12,opacity:.6,marginTop:2},title:t(`route.aliasPath`),children:[`→ `,e.routing.aliasPaths[n.id]]}),(0,o.jsx)(`div`,{style:{marginTop:6},children:(0,o.jsxs)(fz,{children:[e.onOpenFiles!==void 0&&(0,o.jsx)(cz,{kind:`primary`,onClick:()=>e.onOpenFiles?.(n.id),children:t(`ws.open`)}),(0,o.jsx)(cz,{kind:`danger`,onClick:()=>{m(n)},disabled:u!==void 0,children:t(`ws.delete`)})]})})]},n.id)),n&&(0,o.jsx)(bq,{t,hosts:e.hosts,onDone:()=>{r(!1),s(t(`ws.saved`)),l(void 0),e.onChanged()},onCancel:()=>r(!1)})]})}let Cq=`dsh-remote-vs.showHidden`;function wq(e){return{dirty:e.filter(e=>e.dirty).length,reload:e.filter(e=>!e.loading&&!e.dirty&&(e.kind===`file`||e.kind===`diff`)).map(e=>e.id)}}let Tq=e=>({t:e.t,ready:e.ready,view:e.view,hosts:e.hosts,workspaces:e.workspaces,routing:e.routing,workspace:e.workspace,aliasPaths:e.aliasPaths,error:e.error,repoRoot:e.repoRoot,head:e.head,gitBusy:e.gitBusy,editorSurface:e.editorSurface,floatOpen:e.floatOpen,terminalRequest:e.terminalRequest,tabs:e.tabs,activeTab:e.activeTab,buckets:e.buckets,selectWorkspace:e.selectWorkspace,refreshAll:e.refreshAll,reloadTab:e.reloadTab,info:e.info}),Eq=(0,i.memo)(GW),Dq=(0,i.memo)(cK),Oq=(0,i.memo)(GG),kq=(0,i.memo)(hq),Aq=(0,i.memo)(PH),jq=(0,i.memo)(EU),Mq=(0,i.memo)(Sq),Nq=(0,i.memo)(qV),Pq=(0,i.memo)(JV);function Fq(e){return kd(e.ctx),(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(vc,{}),(0,o.jsx)(Iq,{ctx:e.ctx,visible:e.visible!==!1})]})}function Iq(e){let t=gl(Tq,hl),n=t.t,r=t.view,a=(0,i.useRef)(t.tabs);a.current=t.tabs;let[s,c]=(0,i.useState)(()=>{try{return localStorage.getItem(Cq)===`1`}catch{return!1}}),[l,u]=(0,i.useState)(!0),d=(0,i.useRef)(null),f=(0,i.useCallback)(e=>{if(d.current?.disconnect(),d.current=null,e===null||typeof IntersectionObserver>`u`)return;let t=new IntersectionObserver(e=>{let t=e[e.length-1];t!==void 0&&u(t.isIntersecting)});t.observe(e),d.current=t},[]),p=e.visible&&l,m=e=>p&&r===e,[h,g]=(0,i.useState)(!1),_=t.ready;(0,i.useEffect)(()=>{let e=e=>{if(!(!p||!_)&&(e.ctrlKey||e.metaKey)&&!(e.altKey||e.shiftKey)&&!(e.key!==`p`&&e.key!==`P`)&&(e.preventDefault(),!e.repeat)){if(!h){if(qD())return;let e=document.activeElement;if(e instanceof HTMLElement&&e.closest(`.xterm`)!==null||e instanceof HTMLElement&&e.closest(`.xterm, textarea, input, [contenteditable="true"]`)!==null&&e.closest(`.cm-content`)===null)return}g(e=>!e)}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[p,_,h]),(0,i.useEffect)(()=>{p||g(!1)},[p]);let v=(0,i.useCallback)(e=>{Ll(e)},[]),y=(0,i.useCallback)(()=>{Ll(`history`)},[]),b=(0,i.useCallback)(e=>{Kl(e),Ll(`explorer`)},[]),x=(0,i.useCallback)(()=>{c(e=>!e)},[]),S=t.workspace?.alias??``,C=ce();(0,i.useEffect)(()=>{L(S)},[S]),(0,i.useEffect)(()=>{if(S===``)return;let e=!1,t=async()=>{if(!document.hidden)try{let t=await V.connectionStatus();e||ne(t)}catch{}};t();let n=window.setInterval(()=>{t()},5e3);return()=>{e=!0,window.clearInterval(n)}},[S]);let w=(0,i.useRef)(void 0),T=(0,i.useRef)(C);T.current=C;let E=(0,i.useRef)(S);E.current=S,(0,i.useEffect)(()=>{w.current={alias:S,state:C?.state}},[S]),(0,i.useEffect)(()=>{let e=w.current;if(w.current={alias:S,state:C?.state},!ae(e,S,C?.state))return;let r=window.setTimeout(()=>{if(T.current?.state!==`ok`||E.current!==S)return;let e=wq(a.current);Eu();for(let n of e.reload)t.reloadTab(n);e.dirty>0?t.info(n(`connection.recoveredDirty`)):t.info(n(`connection.recovered`))},1e4);return()=>window.clearTimeout(r)},[C?.state]);let[D,O]=(0,i.useState)(()=>new Set([t.view]));(0,i.useEffect)(()=>{O(e=>e.has(r)?e:new Set(e).add(r))},[r]),(0,i.useEffect)(()=>{t.workspaces.length===0&&r!==`workspaces`&&r!==`monitor`&&v(`workspaces`)},[t.workspaces.length,r,v]);let k=sR(e.ctx);if((0,i.useEffect)(()=>{k.sessionId!==void 0&&(ou(k.sessionId),gu({sessionId:k.sessionId,workspacePath:k.sessionWorkspacePath}))},[k.sessionId,k.sessionWorkspacePath,t.ready,t.workspaces,t.aliasPaths]),(0,i.useEffect)(()=>{try{localStorage.setItem(Cq,s?`1`:`0`)}catch{}},[s]),!t.ready)return(0,o.jsx)(`div`,{className:`rvs-root`,children:(0,o.jsxs)(`div`,{className:`rvs-empty`,style:{margin:`auto`},children:[(0,o.jsx)(Tc,{}),` `,n(`common.loading`)]})});let A=t.editorSurface===`sidebar`,j=e=>{switch(e){case`search`:return(0,o.jsx)(Eq,{});case`scm`:return(0,o.jsx)(Dq,{onOpenHistory:y,visible:m(`scm`)});case`history`:return(0,o.jsx)(Oq,{});case`terminal`:return(0,o.jsx)(kq,{t:n,hosts:t.hosts,visible:m(`terminal`),request:t.terminalRequest});case`ports`:return(0,o.jsx)(Aq,{t:n,hosts:t.hosts,visible:m(`ports`)});case`monitor`:return(0,o.jsx)(jq,{t:n,hosts:t.hosts,visible:m(`monitor`)});case`workspaces`:return(0,o.jsx)(`div`,{className:`rvs-viewpad`,style:{height:`100%`},children:(0,o.jsx)(Mq,{t:n,hosts:t.hosts,workspaces:t.workspaces,routing:t.routing,onChanged:t.refreshAll,visible:m(`workspaces`),onOpenFiles:b})});case`editor`:return A?(0,o.jsx)(Nq,{visible:m(`editor`)}):(0,o.jsx)(Pq,{mode:t.floatOpen?`float`:`center`});default:return(0,o.jsx)(CW,{showHidden:s,onToggleHidden:x,visible:m(`explorer`)})}},M=(0,o.jsx)(`div`,{className:`rvs-pane grow`,children:[...D].map(e=>(0,o.jsx)(`div`,{className:`rvs-viewslot`,style:{display:r===e?`flex`:`none`},children:j(e)},e))}),N=(e,t,n,i=0)=>(0,o.jsxs)(`button`,{type:`button`,className:`rvs-rail-btn${r===e?` active`:``}`,title:t,"aria-label":t,onClick:()=>v(e),children:[n,i>0&&(0,o.jsx)(`span`,{className:`rvs-rail-badge`,children:i>99?`99+`:i})]},e);return(0,o.jsxs)(`div`,{className:`rvs-root`,ref:f,children:[(0,o.jsx)(gH,{t:n}),h&&p&&(0,o.jsx)(OU,{onClose:()=>g(!1)}),(0,o.jsxs)(`div`,{className:`rvs-rail`,children:[N(`explorer`,n(`tab.files`),(0,o.jsx)(Fs,{size:17})),N(`search`,n(`tab.search`),(0,o.jsx)(ws,{size:17})),N(`scm`,n(`tab.git`),(0,o.jsx)(js,{size:17}),t.buckets.total),N(`history`,n(`tab.history`),(0,o.jsx)(Ms,{size:17})),(0,o.jsx)(`div`,{className:`rvs-rail-sep`}),N(`editor`,t.activeTab?.rel.split(`/`).pop()??n(`tab.editor`),(0,o.jsx)(Rs,{size:17}),t.tabs.length),N(`terminal`,n(`tab.terminal`),(0,o.jsx)(Ns,{size:17})),N(`ports`,n(`tab.ports`),(0,o.jsx)(MH,{size:17})),N(`monitor`,n(`tab.monitor`),(0,o.jsx)(_U,{size:17})),N(`workspaces`,n(`tab.workspaces`),(0,o.jsx)(Ps,{size:17}),t.workspaces.length)]}),(0,o.jsxs)(`div`,{className:`rvs-column`,children:[(0,o.jsxs)(`div`,{className:`rvs-globalbar`,children:[(0,o.jsx)(`select`,{className:`rvs-select`,value:t.workspace?.id??``,onChange:e=>t.selectWorkspace(e.target.value),title:n(`files.selectWorkspace`),children:t.workspaces.map(e=>(0,o.jsxs)(`option`,{value:e.id,children:[e.name,` (`,e.alias,`)`]},e.id))}),(0,o.jsx)(jd,{}),t.repoRoot!==void 0&&t.head!==void 0&&(0,o.jsxs)(`span`,{className:`rvs-pill`,title:t.repoRoot,children:[`⑂ `,t.head.detached?n(`scm.detached`):t.head.branch,t.head.ahead>0&&` ↑${t.head.ahead}`,t.head.behind>0&&` ↓${t.head.behind}`]}),t.gitBusy&&(0,o.jsx)(Tc,{})]}),t.error!==void 0&&(0,o.jsx)(`div`,{className:`rvs-banner error`,role:`status`,children:t.error}),(0,o.jsx)(`div`,{className:`rvs-pane`,style:{flex:1,minHeight:0},children:M})]})]})}let Lq=`dsh-remote-vs`,Rq=`remote-vs-explorer`;function zq(e,t){let n;try{let t=e.get(`sidebarRightTabs`);if(n=typeof t==`object`&&t?t:void 0,typeof n?.register!=`function`)return}catch{return}let r={id:Lq,kind:Rq,keepMounted:!0,title:()=>t(`native.tab`),guide:[{id:`remote`,order:30,title:()=>t(`native.guide.title`),description:()=>t(`native.guide.desc`)}]},i;try{i=n.register(r)}catch(e){console.warn(`[dsh-remote-vs] native explorer registration failed:`,e);return}let a=t=>{let{tab:n}=t.useTabInfo();return(0,o.jsx)(Fq,{ctx:e,visible:n.visible})},s;try{s=e.slots.inject(`sidebar.right.pane.tab`,()=>e.slots.register({name:`sidebar.right.pane.tab`,key:Lq},a))}catch(e){console.warn(`[dsh-remote-vs] native explorer seat registration failed:`,e);try{i?.()}catch{}return}return()=>{try{s?.()}catch{}try{i?.()}catch{}}}let Bq,Vq,Hq=new Set;function Uq(){return Bq}function Wq(e){return Hq.add(e),()=>{Hq.delete(e)}}function Gq(e){return{autoOpenRemoteWorkspace:typeof e?.autoOpenRemoteWorkspace==`boolean`?e.autoOpenRemoteWorkspace:f.autoOpenRemoteWorkspace,remoteWorkspaceWidthRatio:typeof e?.remoteWorkspaceWidthRatio==`number`&&Number.isFinite(e.remoteWorkspaceWidthRatio)?h(e.remoteWorkspaceWidthRatio):f.remoteWorkspaceWidthRatio}}function Kq(e,t){Bq=e;for(let n of[...Hq])try{n(e,t)}catch{}return e}function qq(e=!1){if(!e&&Bq!==void 0)return Promise.resolve(Bq);if(!e&&Vq!==void 0)return Vq;let t=V.getViewSettings().then(e=>Kq(Gq(e),`load`),()=>void 0).finally(()=>{Vq===t&&(Vq=void 0)});return Vq=t,t}async function Jq(e){return Kq(Gq(await V.setViewSettings(e)),`save`)}let Yq=`[data-rightbar-col]`;function Xq(e){try{let t=e.get(`sidebarRight`);return typeof t==`object`&&t?t:void 0}catch{return}}function Zq(e){try{return Xq(e)?.active?.()?.kind===Rq}catch{return!1}}function Qq(e){let t=new Set,n=new Set,r=new Map,i,a=0,o=0,s=0,c=!1,l=Uq()?.remoteWorkspaceWidthRatio,u,d=async()=>{if(i!==void 0&&i.bindings.length>0&&Date.now()-a<3e4)return i;try{let e=await V.getWorkspaces();return i={bindings:e.workspaces,aliasPaths:e.aliasPaths},a=Date.now(),i}catch{i=void 0;return}},f=async t=>{let n=await d();if(n===void 0)return`unknown`;if(n.bindings.length===0)return`local`;let r=iR(e,t);if(r!==void 0)return Po(n,r)===void 0?`local`:`remote`;let i;try{i=(await V.sessionCwd(t)).cwd}catch{return`unknown`}return i===void 0||i===``?`unknown`:Po(n,i)===void 0?`local`:`remote`},p=t=>{let n=s+=1,r=600,i=()=>{if(c||n!==s)return;let a=document.querySelector(`[data-side="rightbar"]`);a!==null&&Zq(e)&&$q(a,t)||(--r,r>0&&requestAnimationFrame(i))};requestAnimationFrame(i)},m=t=>{let n=Xq(e);if(typeof n?.openTab!=`function`)return!1;try{n.openTab(Rq)}catch{return!1}return p(t),!0},h=e=>{let n=(r.get(e)??0)+1;if(n<10){r.set(e,n);return}r.delete(e),t.add(e)},g=async e=>{n.add(e);try{let n=await f(e);if(c)return;if(n===`unknown`){h(e);return}if(r.delete(e),t.add(e),n!==`remote`)return;let i=Uq();if(i?.autoOpenRemoteWorkspace!==!0||m(i.remoteWorkspaceWidthRatio))return;t.delete(e),h(e)}finally{n.delete(e)}},_=()=>{if(c)return;let r=rR(e);if(!(r===void 0||t.has(r)||n.has(r))){if(Uq()===void 0){let e=Date.now();e>=o&&(o=e+1e4,qq(!0));return}g(r)}},v=Wq((t,n)=>{let r=l;if(l=t.remoteWorkspaceWidthRatio,n!==`save`||r===t.remoteWorkspaceWidthRatio)return;let i=Xq(e);typeof i?.isExpanded==`function`&&i.isExpanded()&&Zq(e)&&p(t.remoteWorkspaceWidthRatio)});return qq(),u=setInterval(_,1500),u.unref?.(),()=>{c=!0,s+=1,v(),u!==void 0&&(clearInterval(u),u=void 0)}}function $q(e,t){let n=document.documentElement.clientWidth;if(n<=0)return!1;let r=Math.min(Math.max(Math.round(n*h(t)),300),Math.max(300,Math.round(n*.7))),i=eJ(e,n);if(i===void 0)return!1;let a=Math.round(i)-r;if(Math.abs(a)<1)return!0;let o=Math.round(e.getBoundingClientRect().left);return rJ(e,()=>{iJ(e,()=>{tJ(e,`pointerdown`,o),tJ(e,`pointerup`,o+a)})}),!0}function eJ(e,t){let n=Number.parseFloat(e.style.left);if(Number.isFinite(n)&&n>=0&&n<=t){let e=t-n;if(e>=300/2)return e}let r=document.querySelector(Yq);if(r!==null){let e=r.getBoundingClientRect().width;if(e>0)return e}let i=e.parentElement;if(i!==null){let e=getComputedStyle(i).gridTemplateColumns.trim().split(/\s+/),t=e[e.length-1],n=t===void 0?NaN:Number.parseFloat(t);if(Number.isFinite(n)&&n>0)return n}let a=t-e.getBoundingClientRect().left-4;return a>0?a:void 0}function tJ(e,t,n){let r=e.getBoundingClientRect();e.dispatchEvent(new PointerEvent(t,{bubbles:!0,cancelable:!0,composed:!0,pointerId:1,pointerType:`mouse`,isPrimary:!0,button:0,buttons:+(t===`pointerdown`),clientX:n,clientY:Math.round(r.top+r.height/2)}))}let nJ=[`setPointerCapture`,`hasPointerCapture`,`releasePointerCapture`];function rJ(e,t){let n=nJ.map(t=>Object.getOwnPropertyDescriptor(e,t));for(let t of nJ)Object.defineProperty(e,t,{configurable:!0,writable:!0,value:t===`hasPointerCapture`?()=>!1:()=>void 0});try{t()}finally{nJ.forEach((t,r)=>{let i=n[r];i===void 0?Reflect.deleteProperty(e,t):Object.defineProperty(e,t,i)})}}function iJ(e,t){let n=e.parentElement,r=document.querySelector(Yq),i=[];for(let e of[n,r])e instanceof HTMLElement&&i.push(e);if(i.length===0){t();return}let a=i.map(e=>e.style.transition);for(let e of i)e.style.transition=`none`;t(),requestAnimationFrame(()=>{i.forEach((e,t)=>{e.style.transition=a[t]??``})})}function aJ(...e){try{if(typeof localStorage>`u`||localStorage.getItem(`dsh-remote-vs.debug`)!==`1`)return}catch{return}console.info(`[rvs-flow]`,...e)}function oJ(e){if(typeof e==`object`&&e&&`rpcError`in e){let t=e.rpcError;if(typeof t==`object`&&t&&`message`in t&&typeof t.message==`string`)return t.message}return e instanceof Error?e.message:String(e)}function sJ(e){if(typeof e==`object`&&e&&`rpcError`in e){let t=e.rpcError;if(typeof t==`object`&&t&&`code`in t)return t.code===`directory-picker/unavailable`}return oJ(e).includes(`directory-picker/unavailable`)}function cJ(e){let{t,busy:n,injected:r}=e,[a,s]=(0,i.useState)(`probing`),[c,l]=(0,i.useState)(void 0),[u,d]=(0,i.useState)(``),[f,p]=(0,i.useState)(!1),[m,h]=(0,i.useState)(void 0),[g,_]=(0,i.useState)(void 0),[v,y]=(0,i.useState)(!1),[b,x]=(0,i.useState)(``),S=(0,i.useRef)(0),C=async e=>{let t=++S.current;p(!0),h(void 0);try{let n=await r.listDirectory(e);if(t!==S.current)return;l(n),d(n.path),s(`browse`)}catch(e){if(t!==S.current)return;sJ(e)?(aJ(`browse unavailable -> native`),s(`native`)):(aJ(`browse failed`,oJ(e)),s(a===`browse`?`browse`:`failed`),h(oJ(e)))}finally{t===S.current&&p(!1)}},w=()=>{let e=u.trim();e!==``&&C(e)},T=()=>{let e=b.trim(),t=c?.path;if(e===``||t===void 0)return;let n=++S.current;p(!0),h(void 0),r.createDirectory(t,e).then(e=>{n===S.current&&(y(!1),x(``),p(!1),C(e))},e=>{n===S.current&&(p(!1),h(oJ(e)))})},E=()=>{let n=++S.current,i=e.flowEpoch.current;p(!0),h(void 0),_(void 0),aJ(`native chooser requested`),r.pickDirectory().then(r=>{if(e.flowEpoch.current!==i){aJ(`native chooser result dropped (another open request)`,r);return}n!==S.current&&aJ(`native chooser result adopted after remount`,r),aJ(`native chooser returned`,r===null?`cancelled`:r),p(!1),r===null?_(t(`flow.nativeCancelled`)):e.onPicked(r)},t=>{e.flowEpoch.current===i&&(aJ(`native chooser failed`,oJ(t)),p(!1),h(oJ(t)))})};(0,i.useEffect)(()=>(S.current+=1,l(void 0),h(void 0),_(void 0),s(`probing`),C(void 0),()=>{S.current+=1}),[]);let D=n||f,O=n||f||a===`probing`;if(a===`probing`&&c===void 0&&m===void 0)return(0,o.jsx)(`div`,{style:{padding:12,opacity:.6,fontSize:12},children:t(`common.loading`)});if(a===`native`)return(0,o.jsxs)(`div`,{style:{padding:`4px 0`},children:[(0,o.jsx)(`div`,{style:{fontSize:12,opacity:.75,marginBottom:10},children:t(`flow.nativeHint`)}),g!==void 0&&(0,o.jsx)(uz,{kind:`info`,children:g}),m!==void 0&&(0,o.jsx)(uz,{kind:`error`,children:m}),(0,o.jsx)(cz,{kind:`primary`,onClick:E,disabled:D,children:t(`flow.nativePick`)})]});if(a===`failed`&&c===void 0)return(0,o.jsxs)(`div`,{style:{padding:`4px 0`},children:[m!==void 0&&(0,o.jsx)(uz,{kind:`error`,children:m}),(0,o.jsx)(cz,{onClick:()=>{s(`probing`),C(void 0)},disabled:D,children:t(`flow.retry`)})]});let k=c?.path??``,A=c!==void 0&&c.crumbs.length>=2?c.crumbs[c.crumbs.length-2]?.path:void 0,j=c?.home;return(0,o.jsxs)(`div`,{children:[(0,o.jsxs)(`div`,{style:{display:`flex`,gap:8,marginBottom:8},children:[(0,o.jsx)(`input`,{value:u,onChange:e=>d(e.target.value),onKeyDown:e=>{e.nativeEvent.isComposing===!0||e.keyCode===229||e.key===`Enter`&&w()},disabled:O,spellCheck:!1,style:{flex:1,background:`rgba(127,127,127,.12)`,color:`inherit`,border:`1px solid rgba(127,127,127,.35)`,borderRadius:6,padding:`4px 8px`,fontSize:13,fontFamily:`inherit`,outline:`none`}}),(0,o.jsx)(cz,{onClick:w,disabled:O||u.trim()===``,children:t(`dirPicker.go`)})]}),(0,o.jsxs)(`div`,{style:{display:`flex`,gap:8,alignItems:`center`,marginBottom:8},children:[(0,o.jsx)(cz,{onClick:()=>j!==void 0&&void C(j),disabled:O||j===void 0,children:t(`dirPicker.home`)}),(0,o.jsx)(cz,{onClick:()=>A!==void 0&&void C(A),disabled:O||A===void 0,children:t(`dirPicker.up`)}),(0,o.jsx)(`code`,{style:{fontSize:12,opacity:.75,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:k})]}),(0,o.jsxs)(`div`,{style:{minHeight:120,maxHeight:240,overflowY:`auto`,border:`1px solid rgba(127,127,127,.3)`,borderRadius:6,padding:4},children:[(c?.entries??[]).filter(e=>!e.hidden).map(e=>(0,o.jsxs)(`div`,{role:`button`,tabIndex:O?-1:0,"aria-disabled":O===!0||void 0,onClick:()=>{O||C(e.path)},onKeyDown:t=>{O||t.key!==`Enter`&&t.key!==` `||(t.preventDefault(),C(e.path))},title:e.path,style:{display:`flex`,gap:6,alignItems:`center`,padding:`3px 8px`,borderRadius:4,cursor:O?`default`:`pointer`,fontSize:13},onMouseEnter:e=>{O||(e.currentTarget.style.background=`rgba(77,107,254,.18)`)},onMouseLeave:e=>{e.currentTarget.style.background=`transparent`},children:[(0,o.jsx)(`span`,{children:`📁`}),(0,o.jsx)(`span`,{style:{overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:e.name})]},e.path)),!f&&(c?.entries??[]).length===0&&m===void 0&&(0,o.jsx)(`div`,{style:{padding:8,opacity:.6,fontSize:12},children:t(`dirPicker.empty`)}),f&&(0,o.jsx)(`div`,{style:{padding:8,opacity:.6,fontSize:12},children:t(`common.loading`)})]}),c?.truncated===!0&&(0,o.jsx)(`div`,{style:{fontSize:12,opacity:.6,marginTop:4},children:t(`flow.truncated`)}),m!==void 0&&(0,o.jsx)(uz,{kind:`error`,children:m}),v?(0,o.jsxs)(`div`,{style:{display:`flex`,gap:8,marginTop:8},children:[(0,o.jsx)(`input`,{value:b,onChange:e=>x(e.target.value),onKeyDown:e=>{e.nativeEvent.isComposing===!0||e.keyCode===229||e.key===`Enter`&&T()},placeholder:t(`flow.mkdirName`),disabled:D,spellCheck:!1,style:{flex:1,background:`rgba(127,127,127,.12)`,color:`inherit`,border:`1px solid rgba(127,127,127,.35)`,borderRadius:6,padding:`4px 8px`,fontSize:13,fontFamily:`inherit`,outline:`none`}}),(0,o.jsx)(cz,{kind:`primary`,onClick:T,disabled:D||b.trim()===``,children:t(`flow.create`)}),(0,o.jsx)(cz,{onClick:()=>{y(!1),x(``)},disabled:D,children:t(`hosts.cancel`)})]}):(0,o.jsxs)(`div`,{style:{display:`flex`,gap:8,marginTop:8},children:[(0,o.jsx)(cz,{onClick:()=>y(!0),disabled:O||k===``,children:t(`flow.mkdir`)}),(0,o.jsx)(`span`,{style:{flex:1}}),(0,o.jsx)(cz,{kind:`primary`,onClick:()=>e.onPicked(k),disabled:O||k===``,children:t(`flow.open`)})]})]})}function lJ(e){let{t}=e,[n,r]=(0,i.useState)(void 0),[a,s]=(0,i.useState)(void 0),[c,l]=(0,i.useState)(!1);return(0,i.useEffect)(()=>{let e=!0;return V.getHosts().then(t=>{e&&r(t)},t=>{e&&s(t instanceof pn?t.message:String(t))}),()=>{e=!1}},[]),a===void 0?n===void 0?(0,o.jsx)(`div`,{style:{padding:12,opacity:.6,fontSize:12},children:t(`common.loading`)}):n.length===0?(0,o.jsx)(`div`,{style:{padding:`4px 0`},children:(0,o.jsx)(uz,{kind:`info`,children:t(`flow.noHosts`)})}):c||e.busy?(0,o.jsx)(`div`,{style:{padding:12,opacity:.6,fontSize:12},children:t(`common.loading`)}):(0,o.jsx)(`div`,{style:{maxHeight:420,overflowY:`auto`,paddingRight:2},children:(0,o.jsx)(bq,{t,hosts:n,onDone:()=>void 0,onCancel:e.onCancel,onSaved:(t,n)=>{l(!0),aJ(`remote wizard saved`,n),Ml(),e.onPicked(n)}})}):(0,o.jsx)(`div`,{style:{padding:`4px 0`},children:(0,o.jsx)(uz,{kind:`error`,children:a})})}function uJ(e){let[t]=(0,i.useState)(()=>fe(de())),[n,r]=(0,i.useState)(`local`),[a,s]=(0,i.useState)(0),c=(0,i.useRef)(0),l=t=>{aJ(`finish`,t),e.onCancel(),e.onPicked(t)},u=(0,i.useRef)(!1);(0,i.useEffect)(()=>{e.open&&!u.current&&(r(`local`),c.current+=1,s(c.current)),aJ(`open`,e.open),u.current=e.open},[e.open]);let d=(0,i.useRef)(null),f=(0,i.useRef)(null),p=(0,i.useRef)(e.onCancel);p.current=e.onCancel;let m=(0,i.useRef)(e.busy);if(m.current=e.busy,(0,i.useEffect)(()=>{if(!e.open)return;f.current=typeof document>`u`?null:document.activeElement;let t=window.setTimeout(()=>{d.current?.querySelector(`button:not([disabled])`)?.focus()},0),n=e=>{e.key!==`Escape`||m.current||(e.preventDefault(),p.current())};return window.addEventListener(`keydown`,n),()=>{window.clearTimeout(t),window.removeEventListener(`keydown`,n);let e=f.current;e!==null&&document.body.contains(e)&&e.focus()}},[e.open]),!e.open)return null;let h={listDirectory:e.listDirectory,createDirectory:e.createDirectory,pickDirectory:e.pickDirectory};return(0,o.jsx)(`div`,{style:{position:`fixed`,inset:0,zIndex:1e3,display:`grid`,placeItems:`center`,background:`rgba(0,0,0,.45)`},role:`dialog`,"aria-modal":`true`,"aria-label":t(`flow.title`),onClick:()=>{e.busy||e.onCancel()},children:(0,o.jsxs)(`div`,{ref:d,style:{width:`min(600px, calc(100vw - 32px))`,maxHeight:`min(680px, calc(100vh - 32px))`,display:`flex`,flexDirection:`column`,background:`Canvas`,color:`CanvasText`,border:`1px solid rgba(127,127,127,.4)`,borderRadius:8,padding:14,fontSize:13},onClick:e=>e.stopPropagation(),children:[(0,o.jsxs)(`div`,{style:{display:`flex`,gap:8,alignItems:`center`,marginBottom:10},children:[(0,o.jsx)(`strong`,{children:t(`flow.title`)}),(0,o.jsx)(`span`,{style:{flex:1}}),(0,o.jsx)(`button`,{type:`button`,onClick:()=>r(`local`),disabled:e.busy,style:{background:n===`local`?`rgba(77,107,254,.25)`:`rgba(127,127,127,.12)`,color:`inherit`,border:`1px solid ${n===`local`?`rgba(77,107,254,.6)`:`rgba(127,127,127,.3)`}`,borderRadius:6,padding:`4px 12px`,fontSize:13,cursor:`pointer`},children:t(`flow.local`)}),(0,o.jsx)(`button`,{type:`button`,onClick:()=>r(`remote`),disabled:e.busy,style:{background:n===`remote`?`rgba(77,107,254,.25)`:`rgba(127,127,127,.12)`,color:`inherit`,border:`1px solid ${n===`remote`?`rgba(77,107,254,.6)`:`rgba(127,127,127,.3)`}`,borderRadius:6,padding:`4px 12px`,fontSize:13,cursor:`pointer`},children:t(`flow.remote`)})]}),(0,o.jsx)(`div`,{style:{flex:1,minHeight:0,overflowY:`auto`},children:n===`local`?(0,o.jsx)(cJ,{t,busy:e.busy,injected:h,flowEpoch:c,onPicked:l},`local-${a}`):(0,o.jsx)(lJ,{t,busy:e.busy,onPicked:l,onCancel:e.onCancel},`remote-${a}`)}),(0,o.jsx)(`div`,{style:{display:`flex`,gap:8,justifyContent:`flex-end`,marginTop:12},children:(0,o.jsx)(cz,{onClick:e.onCancel,disabled:e.busy,children:t(`hosts.cancel`)})})]})})}let dJ=`dsh-remote-vs.float.rect`,fJ=`dsh-remote-vs.float.font`,pJ=`dsh-remote-vs.float.ball`,mJ=[`n`,`s`,`e`,`w`,`ne`,`nw`,`se`,`sw`];function hJ(){return{width:window.innerWidth,height:window.innerHeight}}function gJ(){let e=hJ();try{let t=Ba(localStorage.getItem(dJ),e);if(t!==void 0)return t}catch{}return Fa(e)}function _J(){try{return Ua(localStorage.getItem(fJ))}catch{return 13}}function vJ(){let e=hJ();try{return qa(localStorage.getItem(pJ),e)}catch{return}}function yJ(e){kd(e.ctx);let t=pl(),n=t.t,r=t.floatOpen,a=t.activeTab,[s,c]=(0,i.useState)(void 0),[l,u]=(0,i.useState)(()=>typeof window>`u`?{width:0,height:0}:hJ()),[d,f]=(0,i.useState)(13),[p,m]=(0,i.useState)(!1),[h,g]=(0,i.useState)(!1),[_,v]=(0,i.useState)(!1),[y,b]=(0,i.useState)(void 0),x=(0,i.useRef)(l);x.current=l;let S=(0,i.useRef)(void 0),C=(0,i.useRef)(void 0),w=(0,i.useRef)(null),T=(0,i.useRef)(d);T.current=d;let E=s!==void 0,D=(0,i.useRef)(r),O=(e,t,n)=>{let r=t-e.pointerX,i=n-e.pointerY;return e.kind===`ball`?Wa({x:e.start.x+r,y:e.start.y+i},x.current):e.kind===`move`?La(e.rect,r,i,x.current):Ra(e.rect,e.handle,r,i,x.current)};(0,i.useEffect)(()=>(dd(!0),()=>dd(!1)),[]),(0,i.useEffect)(()=>{if(!r||s!==void 0)return;let e=hJ();u(e),c(gJ()),f(_J()),b(vJ())},[r,s]),(0,i.useEffect)(()=>{r&&!D.current&&g(!1),D.current=r},[r]),(0,i.useEffect)(()=>{let e=()=>{let e=hJ();u(e),b(t=>t===void 0?t:Wa(t,e)),c(t=>t===void 0?t:p?za(e):Ia(t,e))};return window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[p]);let k=(0,i.useCallback)(e=>{try{localStorage.setItem(dJ,Va(e))}catch{}},[]),A=(0,i.useCallback)(e=>{try{localStorage.setItem(pJ,Ja(e))}catch{}},[]);(0,i.useEffect)(()=>{if(!_)return;let e=e=>{let t=S.current;if(t===void 0)return;if(!(e.buttons&1)){S.current=void 0,v(!1);return}let n=O(t,e.clientX,e.clientY);t.kind===`ball`?b(n):c(n)},t=e=>{let t=S.current;if(S.current=void 0,v(!1),t===void 0)return;let n=O(t,e.clientX,e.clientY);if(t.kind===`ball`){let r=n;b(r),A(r),Ka(e.clientX-t.pointerX,e.clientY-t.pointerY)&&g(!1);return}if(p)return;let r=n;c(r),k(r)},n=()=>{S.current=void 0,v(!1)};return window.addEventListener(`pointermove`,e),window.addEventListener(`pointerup`,t),window.addEventListener(`pointercancel`,n),()=>{window.removeEventListener(`pointermove`,e),window.removeEventListener(`pointerup`,t),window.removeEventListener(`pointercancel`,n)}},[_,p,k,A]),(0,i.useEffect)(()=>{let e=w.current;if(e===null)return;let t=e=>{if(!(e.ctrlKey||e.metaKey))return;e.preventDefault();let t=Ha(T.current,e.deltaY);if(t!==T.current){T.current=t,f(t);try{localStorage.setItem(fJ,String(t))}catch{}window.requestAnimationFrame(()=>window.dispatchEvent(new Event(`resize`)))}};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[r,h,E]);let j=(e,t)=>{if(e.button===0){e.preventDefault();try{e.currentTarget.setPointerCapture(e.pointerId)}catch{}S.current=t,v(!0)}},M=()=>{if(s===void 0)return;let e=hJ();if(u(e),p){m(!1),g(!1),c(Ia(C.current??Fa(e),e));return}C.current=s,m(!0),g(!1),c(za(e))},N=()=>{!h&&s!==void 0&&b(y===void 0?Ga(s,x.current):Wa(y,x.current)),g(!h)},ee=(0,i.useMemo)(()=>(0,o.jsx)(`div`,{className:`rvs-float-body`,ref:w,style:{display:h?`none`:`flex`},children:(0,o.jsx)(qV,{visible:!h})}),[h]);if(!r||s===void 0)return null;let P=Wa(y??Ga(s,l),l),F=h?{left:P.x,top:P.y,width:44,height:44}:{left:s.x,top:s.y,width:s.width,height:s.height,"--rvs-editor-font-size":`${d}px`};return(0,o.jsxs)(`div`,{className:`rvs-root rvs-float-window${h?` rvs-float-mini`:``}${_?` dragging`:``}`,style:F,"data-rvs-float":h?`collapsed`:`open`,"data-rvs-float-maximized":p?`true`:void 0,title:h?n(`float.ballHint`):void 0,onPointerDown:h?e=>{e.button===0&&j(e,{kind:`ball`,pointerX:e.clientX,pointerY:e.clientY,start:P})}:void 0,children:[h?(0,o.jsxs)(`div`,{className:`rvs-float-ball`,role:`button`,tabIndex:0,"aria-label":n(`float.ballHint`),title:n(`float.ballHint`),onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),g(!1))},children:[(0,o.jsx)(`span`,{className:`rvs-float-ball-glyph`,"aria-hidden":`true`,children:`▣`}),a!==void 0&&a.dirty&&(0,o.jsx)(`span`,{className:`rvs-float-ball-dot`,title:n(`editor.unsaved`),"aria-hidden":`true`})]}):(0,o.jsxs)(`div`,{className:`rvs-float-titlebar`,onPointerDown:e=>{s===void 0||p||e.target.closest(`button`)===null&&j(e,{kind:`move`,pointerX:e.clientX,pointerY:e.clientY,rect:s})},onDoubleClick:e=>{e.target.closest(`button`)===null&&M()},title:n(`float.dragHint`),children:[(0,o.jsx)(`span`,{className:`rvs-float-glyph`,"aria-hidden":`true`,children:`▣`}),(0,o.jsx)(`span`,{className:`rvs-float-title`,children:n(`float.title`)}),a!==void 0&&(0,o.jsx)(`span`,{className:`rvs-float-file`,title:a.fullPath,children:a.rel}),(0,o.jsx)(`span`,{className:`rvs-float-spacer`}),(0,o.jsx)(`button`,{type:`button`,className:`rvs-float-btn`,title:n(`float.minimize`),"aria-label":n(`float.minimize`),onClick:N,children:`—`}),(0,o.jsx)(`button`,{type:`button`,className:`rvs-float-btn`,title:n(p?`float.restore`:`float.maximize`),"aria-label":n(p?`float.restore`:`float.maximize`),onClick:M,children:p?`❐`:`□`}),(0,o.jsx)(`button`,{type:`button`,className:`rvs-float-btn rvs-float-close`,title:n(`float.dock`),"aria-label":n(`float.dock`),onClick:()=>{t.dockFloatingEditor()},children:(0,o.jsx)(ys,{size:12})})]}),ee,(0,o.jsx)(vc,{}),!h&&!p&&mJ.map(e=>(0,o.jsx)(`div`,{className:`rvs-float-resize rvs-float-resize-${e}`,"data-rvs-float-resize":e,onPointerDown:t=>{s!==void 0&&j(t,{kind:`resize`,handle:e,pointerX:t.clientX,pointerY:t.clientY,rect:s})}},e))]})}function bJ(e,t){if(typeof document>`u`||e===``)return()=>{};let n=n=>{if(n.button!==0)return;let r=n.target;if(!(r instanceof Element)||r.closest(`.rvs-root`)!==null)return;let i=r.closest(`button, [role="tab"], [role="button"]`);if(i!==null&&(i.textContent??``).trim()===e)try{t()}catch{}};return document.addEventListener(`dblclick`,n,!0),()=>document.removeEventListener(`dblclick`,n,!0)}async function xJ(e,t,n,r){if(n.connection(e)===`error`)return{kind:`unknown`};for(let i of t){let t;try{t=await n.deadline(n.stat(e,i),r)}catch(e){if(n.isLinkFailure(e))return{kind:`unknown`};continue}return t===void 0?{kind:`unknown`}:{kind:`exists`,path:i}}return{kind:`missing`}}let SJ=new WeakMap;function CJ(e,t){return new Promise((n,r)=>{let i=setTimeout(()=>n(void 0),t);i.unref?.(),e.then(e=>{clearTimeout(i),n(e)},e=>{clearTimeout(i),r(e)})})}function wJ(e){if(typeof e!=`object`||!e)return;let t=e,n=t.line??t.params?.line;return typeof n==`number`&&Number.isInteger(n)&&n>0?n:void 0}async function TJ(e,t){let n=Fo(e.remotePath,t);if(n===void 0)return;let r=await CJ(V.exec(e.alias,n,6e3),7e3).catch(()=>void 0);if(r!==void 0)return Io(e.remotePath,t,r.stdout)}function EJ(e,t,n,r){let i=Wu();if(i.bindings.length===0)return!1;let a=wJ(r);if(t.scope===`absolute`){let e=Lo({address:n,table:i});return e!==void 0&&Gu(e.binding.id,e.candidates[0],a===void 0?{}:{line:a})}let o=iR(e,t.sessionId);if(o===void 0)return!1;let s=Lo({address:n,table:i,sessionWorkspacePath:o});if(s===void 0)return!1;let c=t.path.replace(/\\/g,`/`),l=c.startsWith(`/`)||/^[A-Za-z]:\//.test(c)||c.startsWith(`//`)?void 0:c.replace(/^(?:\.\/)+/,``);return(async()=>{let e=s;try{let r=(await CJ(V.sessionCwd(t.sessionId),1500))?.cwd;typeof r==`string`&&r!==``&&(e=Lo({address:n,table:i,sessionWorkspacePath:o,sessionCwd:r})??s)}catch{}let r=t=>{Gu(e.binding.id,t,a===void 0?{}:{line:a})},c=await xJ(e.binding.alias,e.candidates,{stat:V.fileOp.stat,deadline:CJ,connection:se,isLinkFailure:A},4e3);if(c.kind===`exists`){r(c.path);return}if(c.kind===`missing`&&l!==void 0){let t=await TJ(e.binding,l);if(t!==void 0){r(t);return}}r(e.candidates[0])})().catch(e=>{console.warn(`[dsh-remote-vs] remote file click could not open the remote editor:`,e)}),!0}function DJ(e){let t=!1,n,r=()=>{n!==void 0&&(clearInterval(n),n=void 0)},i=()=>{if(t)return!0;let n;try{n=e.get(`sidebarRight`)}catch{return!1}if(n===void 0)return!1;let i=n;if(typeof i.openResource!=`function`)return!1;if(SJ.has(n))return r(),!0;let a=i.openResource.bind(i),o=(t,n)=>{try{if(!Ku())return a(t,n);let r=ho(t);return r===void 0?a(t,n):EJ(e,r,t,n)===!0?void 0:a(t,n)}catch{return a(t,n)}};try{i.openResource=o,SJ.set(n,a)}catch{return!1}return r(),!0};return i()||(n=setInterval(()=>{i()&&r()},500),n.unref?.()),()=>{t=!0,r();let n;try{n=e.get(`sidebarRight`)}catch{n=void 0}if(n===void 0)return;let i=SJ.get(n);if(i!==void 0){try{n.openResource=i}catch{}SJ.delete(n)}}}function OJ(e){kd(e.ctx);let t=pl();return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(vc,{}),(0,o.jsx)(`div`,{className:`rvs-root rvs-center`,children:(0,o.jsxs)(`div`,{className:`rvs-column`,children:[(0,o.jsxs)(`div`,{className:`rvs-globalbar`,title:t.floatAvailable?t.t(`float.dockViewHint`):t.t(`float.unavailable`),children:[(0,o.jsx)(`select`,{className:`rvs-select`,value:t.workspace?.id??``,onChange:e=>t.selectWorkspace(e.target.value),title:t.t(`files.selectWorkspace`),children:t.workspaces.map(e=>(0,o.jsxs)(`option`,{value:e.id,children:[e.name,` (`,e.alias,`)`]},e.id))}),t.repoRoot!==void 0&&t.head!==void 0&&(0,o.jsxs)(`span`,{className:`rvs-pill`,title:t.repoRoot,children:[`⑂ `,t.head.detached?t.t(`scm.detached`):t.head.branch,t.head.ahead>0&&` ↑${t.head.ahead}`,t.head.behind>0&&` ↓${t.head.behind}`]})]}),t.editorSurface===`center`?(0,o.jsx)(qV,{visible:!0}):(0,o.jsx)(JV,{mode:t.floatOpen?`float`:`sidebar`})]})})]})}let kJ=`rvs.changes.scope`;function AJ(e){return e===`turn`?`turn`:`session`}function jJ(e){return e}function MJ(e){return e!==void 0&&e.turn>0}let NJ={statsOnly:`changes.turnStatsOnly`,unavailable:`changes.turnUnavailable`,stale:`changes.turnStaleFallback`,missing:`changes.diffMissing`,truncated:`changes.diffTruncated`,empty:`changes.diffEmpty`};function PJ(e,t){if(t===void 0||t.cached!==!0){let n=t?.reason??(e!==null&&e.kind===`unavailable`?e.reason:void 0);return{action:`closed`,noteKey:NJ.statsOnly,...n===void 0?{}:{detail:n}}}return e===null?{action:`closed`,noteKey:NJ.unavailable}:e.kind===`stale`?{action:`fallback`,noteKey:NJ.stale}:e.kind===`unavailable`?{action:`closed`,noteKey:NJ.unavailable,...e.reason===void 0?{}:{detail:e.reason}}:e.kind===`binary`?{action:`binary`}:e.kind===`missing`?{action:`closed`,noteKey:NJ.missing}:e.truncated===!0?{action:`closed`,noteKey:NJ.truncated}:e.hunks.length===0?{action:`closed`,noteKey:NJ.empty}:{action:`use`,diff:e}}function FJ(e,t){return e.action===`fallback`?{scope:`session`,keepNote:!0}:{scope:t,keepNote:!1}}function IJ(e,t){let n=[],r=0,i=0;for(let a of e)t.has(a.path)||(n.push(a),r+=a.added,i+=a.deleted);return{visible:n,hidden:e.length-n.length,added:r,deleted:i}}function LJ(e){return e.hidden<=0||e.visible>0?!1:e.truncated!==!0&&e.pending!==!0}function RJ(e,t){return t===void 0||!Number.isFinite(e)||!Number.isFinite(t)?!1:e-t<6e4}function zJ(e){return!e.visible||e.inFlight===!0||!Number.isFinite(e.now)?!1:e.lastForceAt===void 0||!Number.isFinite(e.lastForceAt)||e.now-e.lastForceAt>=5e3}function BJ(e){return`${e.path}\u0000${e.added}\u0000${e.deleted}\u0000${e.status??``}`}function VJ(e,t){return t[BJ(e)]===1}function HJ(e,t){let n=0;for(let r of e)VJ(r,t)&&(n+=1);return n}function UJ(e,t,n){if(e.length===0)return;let r=(n===void 0||n===``?-1:e.findIndex(e=>BJ(e)===n))+1;for(let n=0;n<e.length;n+=1){let i=e[(r+n)%e.length];if(!VJ(i,t))return i}}function WJ(e,t,n){let r=BJ(n),i={};for(let[e,n]of Object.entries(t))i[e]=n;return i[r]===1?delete i[r]:i[r]=1,KJ(e,i)}function GJ(e,t){if(!t)return{};let n={};for(let t of e)if(n[BJ(t)]!==1&&(n[BJ(t)]=1,Object.keys(n).length>=1e3))break;return n}function KJ(e,t){let n=new Set(e.map(e=>BJ(e))),r={},i=0;for(let[e,a]of Object.entries(t))if(!(a!==1||!n.has(e))&&(r[e]=1,i+=1,i>=1e3))break;return r}function qJ(e){if(typeof e!=`string`||e===``)return{};let t;try{t=JSON.parse(e)}catch{return{}}if(typeof t!=`object`||!t||Array.isArray(t))return{};let n={},r=0;for(let[e,i]of Object.entries(t))if(!(i!==1||e===``)&&(n[e]=1,r+=1,r>=1e3))break;return n}function JJ(e){return JSON.stringify(e)}let YJ=`src/client/changes/changes.css`,XJ=typeof document>`u`?void 0:Array.prototype.find.call(document.querySelectorAll(`style[data-rvs-css]`),e=>e.dataset.rvsCss===YJ);if(typeof document<`u`&&XJ===void 0){let e=document.createElement(`style`);e.dataset.rvsCss=YJ,e.textContent=`/**
7386
7438
  * Session change panel (above the composer).
7387
7439
  *
7388
7440
  * Scoped under \`.rvs-changes\` — this surface renders OUTSIDE \`.rvs-root\` (it is
@@ -7925,5 +7977,5 @@ fi
7925
7977
  exit 0
7926
7978
  `}let uY=new Map(sY.map(e=>[e.key,e])),dY=/^@@RVS-DOC ([a-z0-9-]+) (ok|missing|unknown)(?: (.*))?$/;function fY(e,t=240){let n=e.replace(/\s+/g,` `).trim();return n.length<=t?n:`${n.slice(0,t-1)}…`}function pY(e){return/^\d+$/.test(e)}function mY(e){let t=e.split(/\s+/).filter(e=>e!==``);return t.length<6||!/^\d+(?:[.,]\d+)?[KMGTPE]?i?$/.test(t[3])||!/^(?:\d+%|-)$/.test(t[4])?{state:`unknown`,detail:`unexpected df row: ${e}`}:{state:`ok`,detail:`avail ${t[3]} · use ${t[4]} · ${t[0]} on ${t.slice(5).join(` `)}`}}function hY(e){let t=e.split(/\s+/).filter(e=>e!==``);return t.length<4||t[0]!==`Mem:`||!pY(t[1])||!pY(t[2])||!pY(t[3])?{state:`unknown`,detail:`unexpected free row: ${e}`}:{state:`ok`,detail:`total ${t[1]}M · used ${t[2]}M · free ${t[3]}M`}}function gY(e,t){if(e===`disk`)return mY(t);if(e===`memory`)return hY(t)}function _Y(e,t,n){let r=fY(n,600);if(t===`ok`){if(r===``)return{key:e.key,label:e.label,state:`unknown`,detail:`the probe reported success but carried no output`};let t=gY(e.key,r);return t===void 0?{key:e.key,label:e.label,state:`ok`,detail:r}:{key:e.key,label:e.label,state:t.state,detail:t.detail}}return t===`missing`?{key:e.key,label:e.label,state:`missing`,detail:r===``?`reported not installed by the remote probe`:r}:{key:e.key,label:e.label,state:`unknown`,detail:r===``?`the probe could not decide`:r}}function vY(e){let t=fY(e,300);return sY.map(e=>({key:e.key,label:e.label,state:`unknown`,detail:t}))}function yY(e){let t=fY(e,200);return t===``?`the remote command did not report an exit status (the link dropped or the time budget ran out)`:`the remote command did not report an exit status; stderr: ${t}`}function bY(e,t,n){if(n===null)return vY(yY(t));let r=new Map;for(let t of e.split(`
7927
7979
  `)){let e=t.endsWith(`\r`)?t.slice(0,-1):t,n=dY.exec(e);if(n===null)continue;let i=n[1];if(!uY.has(i)||r.has(i))continue;let a=(n[3]??``).trim();r.set(i,{state:n[2],detail:a===`-`?``:a})}return sY.map(e=>{let t=r.get(e.key);return t===void 0?{key:e.key,label:e.label,state:`unknown`,detail:`no marker line in the captured output (the probe did not answer, or the output was truncated)`}:_Y(e,t.state,t.detail)})}function xY(e){return vY(e)}function SY(e,t,n,r=Date.now()){let i=[n(`doctor.reportTitle`).replace(`{alias}`,e),n(`doctor.reportAt`).replace(`{at}`,new Date(r).toISOString()),``];for(let e of t)i.push(`${n(cY[e.state])} ${n(e.label)}: ${e.detail}`);return i.join(`
7928
- `)}function CY(e){return(0,o.jsx)(`span`,{className:`rvs-doctor-badge ${e.item.state}`,children:e.t(cY[e.item.state])})}let wY=new Map;function TY(e){let t=wY.get(e);if(t!==void 0)return t;let n=V.exec(e,lY(),2e4).then(e=>bY(e.stdout,e.stderr,e.exitCode),e=>xY(e instanceof Error?e.message:String(e))).finally(()=>{wY.get(e)===n&&wY.delete(e)});return wY.set(e,n),n}async function EY(e){try{return await navigator.clipboard.writeText(e),!0}catch{}try{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t),t.select();let n=document.execCommand(`copy`);return t.remove(),n}catch{return!1}}function DY(e){return e===null?[]:Array.from(e.querySelectorAll(`button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])`))}function OY(e){let t=e.t,[n,r]=(0,i.useState)(void 0),[a,s]=(0,i.useState)(`idle`),c=(0,i.useRef)(null),l=(0,i.useRef)(null),u=(0,i.useRef)(!0);(0,i.useEffect)(()=>(u.current=!0,()=>{u.current=!1}),[]);let d=(0,i.useCallback)(()=>{TY(e.alias).then(e=>{u.current&&r(e)})},[e.alias]);(0,i.useEffect)(()=>{d()},[d]),(0,i.useEffect)(()=>{l.current=typeof document>`u`?null:document.activeElement;let e=window.setTimeout(()=>{DY(c.current)[0]?.focus()},0);return()=>{window.clearTimeout(e);let t=l.current;t!==null&&document.body.contains(t)&&t.focus()}},[]),(0,i.useEffect)(()=>{let t=t=>{if(t.key===`Escape`){t.stopPropagation(),e.onClose();return}if(t.key!==`Tab`)return;let n=DY(c.current);if(n.length===0)return;let r=n[0],i=n[n.length-1],a=document.activeElement;c.current?.contains(a)===!0?t.shiftKey&&a===r?(t.preventDefault(),i.focus()):!t.shiftKey&&a===i&&(t.preventDefault(),r.focus()):(t.preventDefault(),t.shiftKey?i.focus():r.focus())};return document.addEventListener(`keydown`,t,!0),()=>document.removeEventListener(`keydown`,t,!0)},[e.onClose]);let f=()=>{n!==void 0&&EY(SY(e.alias,n,t)).then(e=>{u.current&&s(e?`copied`:`failed`)})},p=t(a===`copied`?`doctor.copied`:a===`failed`?`doctor.copyFailed`:`doctor.copy`),m=t(`doctor.title`).replace(`{alias}`,e.alias),h=n!==void 0&&n.some(e=>e.state===`unknown`);return(0,o.jsx)(`div`,{className:`rvs-doctor`,role:`dialog`,"aria-modal":`true`,"aria-label":m,onClick:e.onClose,children:(0,o.jsxs)(`div`,{ref:c,className:`rvs-doctor-card`,onClick:e=>e.stopPropagation(),children:[(0,o.jsxs)(`div`,{className:`rvs-doctor-head`,children:[(0,o.jsx)(`span`,{className:`rvs-doctor-title`,children:m}),(0,o.jsx)(`span`,{style:{flex:1}}),(0,o.jsx)(cz,{onClick:f,disabled:n===void 0,children:p}),(0,o.jsx)(cz,{onClick:e.onClose,children:t(`doctor.close`)})]}),n===void 0?(0,o.jsx)(`div`,{className:`rvs-doctor-body`,children:(0,o.jsxs)(`div`,{className:`rvs-doctor-loading`,children:[(0,o.jsx)(lz,{}),` `,t(`doctor.loading`)]})}):(0,o.jsx)(`div`,{className:`rvs-doctor-body`,children:(0,o.jsxs)(`table`,{className:`rvs-doctor-table`,children:[(0,o.jsx)(`thead`,{children:(0,o.jsxs)(`tr`,{children:[(0,o.jsx)(`th`,{children:t(`doctor.colItem`)}),(0,o.jsx)(`th`,{children:t(`doctor.colState`)}),(0,o.jsx)(`th`,{children:t(`doctor.colDetail`)})]})}),(0,o.jsx)(`tbody`,{children:n.map(e=>(0,o.jsxs)(`tr`,{children:[(0,o.jsx)(`td`,{className:`rvs-doctor-item`,children:t(e.label)}),(0,o.jsx)(`td`,{children:(0,o.jsx)(CY,{item:e,t})}),(0,o.jsx)(`td`,{className:`rvs-doctor-detail`,title:e.detail,children:e.detail})]},e.key))})]})}),h&&(0,o.jsx)(`div`,{className:`rvs-doctor-hint`,children:t(`doctor.unknownHint`)})]})})}function kY(e){return e instanceof pn?e.message:String(e)}function AY(e,t){return e(t===`http`?`proxy.shortHttp`:`proxy.shortSocks5`)}function jY(){return{mode:`inherit`,kind:`http`,host:``,port:``,username:``,password:``,viaAlias:``}}function MY(e){let t=jY();return e===void 0?t:(t.mode=e.mode,t.viaAlias=e.jumpVia??``,e.target!==void 0&&(t.kind=e.target.kind,t.host=e.target.host,t.port=String(e.target.port),t.username=e.target.username??``),t)}function NY(e){let t=jY();return t.mode=e===void 0?`direct`:e.defaultMode,e?.target!==void 0&&(t.kind=e.target.kind,t.host=e.target.host,t.port=String(e.target.port),t.username=e.target.username??``),t}function PY(e){let t=Number.parseInt(e.port,10),n=e.username.trim();return{kind:e.kind,host:e.host.trim(),port:Number.isInteger(t)?t:0,...n===``?{}:{username:n},...e.password===``?{}:{password:e.password}}}function FY(e){if(e.mode!==`inherit`)return e.mode===`direct`?{mode:`direct`}:e.mode===`jump`?{mode:`jump`,jump:{viaAlias:e.viaAlias.trim()}}:{mode:`proxy`,proxy:PY(e)}}function IY(e,t){if(e.mode===`proxy`){let t=Number.parseInt(e.port,10);if(e.host.trim()===``||!Number.isInteger(t)||t<1||t>65535)return`target`}if(e.mode===`jump`){let n=e.viaAlias.trim();if(n===``)return`jump`;if(t!==void 0&&!t.includes(n))return`jumpGone`}}function LY(e,t,n){if(t.mode===`direct`)return e(`proxy.summaryDirect`);if(t.mode===`proxy`){let n=t.host.trim(),r=t.port.trim();return n===``||r===``?e(`proxy.chipProxy`):e(`proxy.summaryProxy`).replace(`{kind}`,AY(e,t.kind)).replace(`{host}`,n).replace(`{port}`,r)}if(t.mode===`jump`){let n=t.viaAlias.trim();return n===``?e(`proxy.mode.jump`):e(`proxy.summaryJump`).replace(`{alias}`,n)}let r=n?.target;return n===void 0||n.defaultMode===`proxy`&&r===void 0?e(`proxy.chipInherit`):n.defaultMode===`direct`?e(`proxy.summaryInheritDirect`):e(`proxy.summaryInheritProxy`).replace(`{kind}`,AY(e,r?.kind??`http`)).replace(`{host}`,r?.host??``).replace(`{port}`,String(r?.port??``))}function RY(e,t,n){let r=LY(e,MY(t),n),i=t.mode===`jump`?t.jumpVia===void 0?e(`proxy.mode.jump`):e(`proxy.chipJump`).replace(`{alias}`,t.jumpVia):r;return{mode:t.mode,label:i,title:t.problem??e(`proxy.chipTitle`).replace(`{summary}`,r),problem:t.problem!==void 0}}function zY(e){let t=e.chip;return(0,o.jsx)(`span`,{className:t.problem?`rvs-proxy-chip is-error`:`rvs-proxy-chip`,"data-proxy-mode":t.mode,...t.problem?{"data-proxy-problem":`1`}:{},title:t.title,children:t.label})}function BY(e){return(0,o.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,marginBottom:e.open?8:4},children:[(0,o.jsxs)(`button`,{type:`button`,className:`rvs-proxy-toggle`,"aria-expanded":e.open,"aria-controls":e.controls,title:e.open?e.collapseLabel:e.expandLabel,onClick:e.onToggle,children:[(0,o.jsx)(`span`,{className:`rvs-proxy-caret`,"aria-hidden":`true`,children:`▸`}),(0,o.jsx)(`span`,{style:{fontSize:12,opacity:.75},children:e.label})]}),(0,o.jsx)(`span`,{style:{flex:1}}),(0,o.jsx)(zY,{chip:e.chip})]})}function VY(e){let t=e.t,n=e.state,r=t=>e.onChange({...n,...t}),i=e.disabled===!0;return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(`div`,{style:{display:`flex`,gap:8},children:[(0,o.jsx)(`div`,{style:{flex:1.1},children:(0,o.jsx)(dz,{label:t(`proxy.kind`),children:(0,o.jsxs)(`select`,{value:n.kind,disabled:i,onChange:e=>r({kind:e.target.value===`socks5`?`socks5`:`http`}),style:rz,children:[(0,o.jsx)(`option`,{value:`http`,style:iz,children:t(`proxy.typeHttp`)}),(0,o.jsx)(`option`,{value:`socks5`,style:iz,children:t(`proxy.typeSocks5`)})]})})}),(0,o.jsx)(`div`,{style:{flex:1.9},children:(0,o.jsx)(dz,{label:t(`proxy.host`),children:(0,o.jsx)(`input`,{value:n.host,disabled:i,onChange:e=>r({host:e.target.value}),placeholder:`192.0.2.10`,style:nz})})}),(0,o.jsx)(`div`,{style:{flex:.8},children:(0,o.jsx)(dz,{label:t(`proxy.port`),children:(0,o.jsx)(`input`,{value:n.port,disabled:i,inputMode:`numeric`,onChange:e=>r({port:e.target.value}),placeholder:`3128`,style:nz})})})]}),(0,o.jsxs)(`div`,{style:{display:`flex`,gap:8},children:[(0,o.jsx)(`div`,{style:{flex:1},children:(0,o.jsx)(dz,{label:t(`proxy.username`),children:(0,o.jsx)(`input`,{value:n.username,disabled:i,autoComplete:`off`,onChange:e=>r({username:e.target.value}),style:nz})})}),(0,o.jsx)(`div`,{style:{flex:1},children:(0,o.jsx)(dz,{label:t(`proxy.password`),children:(0,o.jsx)(`input`,{type:`password`,value:n.password,disabled:i,autoComplete:`new-password`,onChange:e=>r({password:e.target.value}),placeholder:e.storedPassword?t(`proxy.passwordKeep`):``,style:nz})})})]})]})}function HY(e){let t=e.t,n=e.state,r=t=>e.onChange({...n,...t}),a=(0,i.useId)(),s=(0,i.useId)(),c=LY(t,n,e.proxyDefault),l={mode:n.mode,label:c,title:t(`proxy.chipTitle`).replace(`{summary}`,c),problem:!1},u=e.hosts.filter(t=>t.alias!==e.self),d=n.viaAlias!==``&&!u.some(e=>e.alias===n.viaAlias);return(0,o.jsxs)(`div`,{style:{...tz,marginTop:2,paddingTop:8,marginBottom:8},children:[(0,o.jsx)(BY,{open:e.open,label:t(`proxy.title`),expandLabel:t(`proxy.expand`),collapseLabel:t(`proxy.collapse`),chip:l,controls:a,onToggle:e.onToggle}),(0,o.jsxs)(`div`,{id:a,hidden:!e.open,className:`rvs-proxy-panel`,children:[(0,o.jsxs)(fz,{children:[(0,o.jsx)(`span`,{style:{opacity:.75,marginRight:4},children:t(`proxy.mode`)}),(0,o.jsxs)(`label`,{style:{marginRight:10},children:[(0,o.jsx)(`input`,{type:`radio`,name:s,checked:n.mode===`inherit`,disabled:e.busy,onChange:()=>r({mode:`inherit`})}),` `,t(`proxy.mode.inherit`)]}),(0,o.jsxs)(`label`,{style:{marginRight:10},children:[(0,o.jsx)(`input`,{type:`radio`,name:s,checked:n.mode===`direct`,disabled:e.busy,onChange:()=>r({mode:`direct`})}),` `,t(`proxy.mode.direct`)]}),(0,o.jsxs)(`label`,{style:{marginRight:10},children:[(0,o.jsx)(`input`,{type:`radio`,name:s,checked:n.mode===`proxy`,disabled:e.busy,onChange:()=>r({mode:`proxy`})}),` `,t(`proxy.mode.proxy`)]}),(0,o.jsxs)(`label`,{children:[(0,o.jsx)(`input`,{type:`radio`,name:s,checked:n.mode===`jump`,disabled:e.busy,onChange:()=>r({mode:`jump`})}),` `,t(`proxy.mode.jump`)]})]}),n.mode===`proxy`&&(0,o.jsx)(VY,{t,state:n,onChange:e.onChange,storedPassword:e.storedPassword,disabled:e.busy}),n.mode===`jump`&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(dz,{label:t(`proxy.jumpVia`),children:(0,o.jsxs)(`select`,{value:n.viaAlias,disabled:e.busy,onChange:e=>r({viaAlias:e.target.value}),style:rz,children:[u.length===0&&(0,o.jsx)(`option`,{value:``,style:iz,children:t(`proxy.jumpNone`)}),d&&(0,o.jsx)(`option`,{value:n.viaAlias,style:iz,children:t(`proxy.jumpMissing`).replace(`{alias}`,n.viaAlias)}),u.map(e=>(0,o.jsx)(`option`,{value:e.alias,style:iz,children:e.alias===e.host?e.alias:`${e.alias} (${e.host})`},e.alias))]})}),(0,o.jsx)(`div`,{style:{fontSize:11,opacity:.6,marginBottom:8},children:t(`proxy.jumpHint`)})]}),e.error!==void 0&&(0,o.jsx)(uz,{kind:`error`,children:e.error})]})]})}function UY(e){let t=e.deploy;if(t===void 0||t.status===`not-deployed`)return(0,o.jsx)(`span`,{style:{opacity:.6},children:e.t(`deploy.notDeployed`)});let n=t.status===`failed`?`#e06060`:t.status===`ok`?`#7ee2a8`:`#e8b84b`,r=t.status===`ok`?e.t(`deploy.ok`):t.status===`skipped-same`?e.t(`deploy.skipped`):e.t(`deploy.failed`);return(0,o.jsxs)(`span`,{title:t.detail??t.artifact,style:{color:n},children:[r,` · `,t.artifact,t.manifestHash===void 0?``:` ${t.manifestHash.slice(0,8)}`]})}function WY(e){let t=e.t,[n,r]=(0,i.useState)(e.initial?.alias??``),[a,s]=(0,i.useState)(e.initial?.host??``),[c,l]=(0,i.useState)(String(e.initial?.port??22)),[u,d]=(0,i.useState)(e.initial?.user??``),[f,p]=(0,i.useState)(e.initial?.auth??`key`),[m,h]=(0,i.useState)(``),[g,_]=(0,i.useState)(``),[v,y]=(0,i.useState)(``),[b,x]=(0,i.useState)(e.initial?.description??``),[S,C]=(0,i.useState)(()=>MY(e.initial?.proxy)),[w,T]=(0,i.useState)(!1),[E,D]=(0,i.useState)(void 0),O=e.initial?.proxy?.target,k=O?.hasPassword===!0&&S.mode===`proxy`&&S.kind===O.kind&&S.host.trim()===O.host&&S.port.trim()===String(O.port)&&S.username.trim()===(O.username??``),A=e.hosts.filter(t=>t.alias!==e.initial?.alias).map(e=>e.alias),j=()=>{let r=IY(S,A);if(r!==void 0){D(r===`target`?t(`proxy.invalidTarget`):r===`jump`?t(`proxy.invalidJump`):t(`proxy.jumpGone`).replace(`{alias}`,S.viaAlias.trim())),T(!0);return}D(void 0);let i=Number.parseInt(c,10),o=FY(S),s={alias:n.trim(),host:a.trim(),port:Number.isFinite(i)?i:22,user:u.trim(),auth:f===`key`?{kind:`key`,keyPath:m.trim(),...g===``?{}:{passphrase:g}}:{kind:`password`,password:v},...b.trim()===``?{}:{description:b.trim()},...o===void 0?{}:{proxy:o}};e.onSave(s)};return(0,o.jsxs)(`div`,{style:{...tz,marginTop:10,paddingTop:10},children:[(0,o.jsx)(dz,{label:t(`form.alias`),children:(0,o.jsx)(`input`,{value:n,disabled:e.initial!==void 0||e.busy,onChange:e=>r(e.target.value),placeholder:`prod-web-1`,style:nz})}),(0,o.jsxs)(`div`,{style:{display:`flex`,gap:8},children:[(0,o.jsx)(`div`,{style:{flex:2},children:(0,o.jsx)(dz,{label:t(`form.host`),children:(0,o.jsx)(`input`,{value:a,disabled:e.busy,onChange:e=>s(e.target.value),placeholder:`192.0.2.10`,style:nz})})}),(0,o.jsx)(`div`,{style:{flex:1},children:(0,o.jsx)(dz,{label:t(`form.port`),children:(0,o.jsx)(`input`,{value:c,disabled:e.busy,onChange:e=>l(e.target.value),style:nz})})}),(0,o.jsx)(`div`,{style:{flex:1},children:(0,o.jsx)(dz,{label:t(`form.user`),children:(0,o.jsx)(`input`,{value:u,disabled:e.busy,onChange:e=>d(e.target.value),placeholder:`root`,style:nz})})})]}),(0,o.jsxs)(`div`,{style:{marginBottom:8,fontSize:12},children:[(0,o.jsx)(`span`,{style:{opacity:.75,marginRight:8},children:t(`form.auth`)}),(0,o.jsxs)(`label`,{style:{marginRight:10},children:[(0,o.jsx)(`input`,{type:`radio`,checked:f===`key`,disabled:e.busy,onChange:()=>p(`key`)}),` `,t(`form.authKey`)]}),(0,o.jsxs)(`label`,{children:[(0,o.jsx)(`input`,{type:`radio`,checked:f===`password`,disabled:e.busy,onChange:()=>p(`password`)}),` `,t(`form.authPassword`)]})]}),f===`key`?(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(dz,{label:t(`form.keyPath`),children:(0,o.jsx)(`input`,{value:m,disabled:e.busy,onChange:e=>h(e.target.value),placeholder:e.initial?.auth===`key`?t(`form.unchanged`):`C:\\Users\\me\\.ssh\\id_ed25519`,style:nz})}),(0,o.jsx)(dz,{label:t(`form.passphrase`),children:(0,o.jsx)(`input`,{type:`password`,value:g,disabled:e.busy,onChange:e=>_(e.target.value),placeholder:e.initial===void 0?``:t(`form.unchangedWhenEmpty`),style:nz})})]}):(0,o.jsx)(dz,{label:t(`form.password`),children:(0,o.jsx)(`input`,{type:`password`,value:v,disabled:e.busy,onChange:e=>y(e.target.value),placeholder:e.initial?.auth===`password`?t(`form.unchangedWhenEmpty`):``,style:nz})}),(0,o.jsx)(HY,{t,state:S,onChange:e=>{C(e),D(void 0)},open:w,onToggle:()=>T(!w),proxyDefault:e.proxyDefault,hosts:e.hosts,self:e.initial?.alias,storedPassword:k,busy:e.busy,error:E}),(0,o.jsx)(dz,{label:t(`form.description`),children:(0,o.jsx)(`input`,{value:b,disabled:e.busy,onChange:e=>x(e.target.value),style:nz})}),(0,o.jsxs)(fz,{children:[(0,o.jsx)(cz,{kind:`primary`,onClick:j,disabled:e.busy,children:t(`hosts.save`)}),(0,o.jsx)(cz,{onClick:e.onCancel,disabled:e.busy,children:t(`hosts.cancel`)})]})]})}function GY(e){let t=e.t,[n,r]=(0,i.useState)(void 0),[a,s]=(0,i.useState)(void 0),[c,l]=(0,i.useState)(void 0),[u,d]=(0,i.useState)(null),[f,p]=(0,i.useState)(null),m=e=>{r(e),s(void 0)},h=e=>{s(kY(e)),r(void 0)},g=e=>{l(`test:${e}`),V.testHost(e).then(n=>{l(void 0),n.ok?m(t(`hosts.testOk`).replace(`{alias}`,e).replace(`{ms}`,String(n.durationMs))):h(`${e}: ${n.error??t(`hosts.unknownError`)}`)},e=>{l(void 0),h(e)})},_=t=>{l(`key:${t}`),V.bootstrap(t).then(n=>{l(void 0),m(`${t}: ${n.detail} → ${n.keyPath}`),e.onChanged()},e=>{l(void 0),h(e)})},v=t=>{l(`push:${t}`),V.deployPush(t).then(n=>{l(void 0),m(`${t}: ${n.detail}`),e.onChanged()},e=>{l(void 0),h(e)})},y=async n=>{await hc({title:t(`hosts.confirmDelete`),danger:!0,okText:t(`hosts.delete`)})&&(l(`del:${n}`),V.deleteHost(n).then(()=>{l(void 0),m(t(`hosts.deleted`).replace(`{alias}`,n)),e.onChanged()},e=>{l(void 0),h(e)}))},b=n=>{l(`import:${n}`),(n===`ssh-config`?V.importSshConfig():V.importDshSsh()).then(n=>{l(void 0);let r=n.skipped.map(e=>`${e.alias}(${e.reason})`).join(`; `);m(`${t(`hosts.imported`).replace(`{count}`,String(n.imported.length))}${n.imported.length>0?`: ${n.imported.join(`, `)}`:``}${r===``?``:t(`hosts.importedSkipped`).replace(`{list}`,r)}`),e.onChanged()},e=>{l(void 0),h(e)})},x=n=>{l(`save`);let r=u===`new`?void 0:u,i=r===void 0?void 0:e.hosts.find(e=>e.alias===r)?.proxy,a=n.proxy??(i===void 0||i.mode===`inherit`?void 0:{mode:`inherit`});(r===void 0?V.createHost(n):V.updateHost(r,{host:n.host,port:n.port,user:n.user,auth:n.auth,description:n.description,...a===void 0?{}:{proxy:a}})).then(n=>{l(void 0),d(null),m(t(`hosts.saved`).replace(`{alias}`,n.alias)),e.onChanged()},e=>{l(void 0),h(e)})},S=c!==void 0;return(0,o.jsxs)(`div`,{style:{flex:1,minHeight:0,overflow:`auto`},children:[(0,o.jsxs)(fz,{children:[(0,o.jsx)(`strong`,{style:{fontSize:14},children:t(`hosts.title`)}),(0,o.jsx)(`span`,{style:{flex:1}}),(0,o.jsx)(cz,{kind:`primary`,onClick:()=>{d(`new`),r(void 0),s(void 0)},disabled:S||u!==null,children:t(`hosts.add`)})]}),(0,o.jsx)(`div`,{style:{marginTop:8},children:(0,o.jsxs)(fz,{children:[(0,o.jsx)(cz,{onClick:()=>b(`ssh-config`),disabled:S,children:t(`hosts.importSshConfig`)}),(0,o.jsx)(cz,{onClick:()=>b(`dsh-ssh`),disabled:S,children:t(`hosts.importDshSsh`)})]})}),n!==void 0&&(0,o.jsx)(uz,{kind:`info`,children:n}),a!==void 0&&(0,o.jsx)(uz,{kind:`error`,children:a}),e.hosts.length===0&&u===null&&(0,o.jsx)(`div`,{style:{opacity:.7,marginTop:10},children:t(`hosts.empty`)}),e.hosts.map(n=>(0,o.jsxs)(`div`,{style:{...tz,marginTop:10,paddingTop:8},children:[(0,o.jsxs)(fz,{children:[(0,o.jsx)(`code`,{style:{fontWeight:700},children:n.alias}),(0,o.jsxs)(`code`,{style:{opacity:.75},children:[n.user,`@`,n.host,`:`,n.port]}),(0,o.jsx)(zY,{chip:RY(t,n.proxy,e.proxyDefault)}),(0,o.jsxs)(`span`,{style:{fontSize:12,opacity:.75},children:[n.auth===`key`?n.keyReady?`🔑✓`:`🔑?`:`🔒`,n.managedKey?` (managed)`:``]})]}),(0,o.jsxs)(`div`,{style:{fontSize:12,margin:`4px 0`},children:[(0,o.jsx)(UY,{deploy:n.deploy,t}),n.description!==void 0&&n.description!==``&&(0,o.jsxs)(`span`,{style:{opacity:.7},children:[` · `,n.description]})]}),(0,o.jsxs)(fz,{children:[(0,o.jsx)(cz,{onClick:()=>g(n.alias),disabled:S,children:c===`test:${n.alias}`?t(`hosts.testing`):t(`hosts.test`)}),n.auth===`password`&&(0,o.jsx)(cz,{onClick:()=>_(n.alias),disabled:S,children:c===`key:${n.alias}`?t(`hosts.bootstrapping`):t(`hosts.bootstrap`)}),(0,o.jsx)(cz,{onClick:()=>v(n.alias),disabled:S,children:c===`push:${n.alias}`?t(`hosts.pushing`):t(`hosts.push`)}),(0,o.jsx)(cz,{onClick:()=>{p(n.alias),r(void 0),s(void 0)},disabled:S,children:t(`doctor.open`)}),(0,o.jsx)(cz,{onClick:()=>{d(u===n.alias?null:n.alias),r(void 0),s(void 0)},disabled:S,children:t(`hosts.edit`)}),(0,o.jsx)(cz,{kind:`danger`,onClick:()=>{y(n.alias)},disabled:S,children:t(`hosts.delete`)})]}),u===n.alias&&(0,o.jsx)(WY,{t,initial:n,busy:S,hosts:e.hosts,proxyDefault:e.proxyDefault,onSave:x,onCancel:()=>d(null)})]},n.alias)),f!==null&&(0,o.jsx)(OY,{t,alias:f,onClose:()=>p(null)},f),u===`new`&&(0,o.jsx)(WY,{t,busy:S,hosts:e.hosts,proxyDefault:e.proxyDefault,onSave:x,onCancel:()=>d(null)})]})}function KY(e){let[t]=(0,i.useState)(()=>fe(de())),[n,r]=(0,i.useState)([]),[a,s]=(0,i.useState)(`enforce`),[c,l]=(0,i.useState)(``),[u,d]=(0,i.useState)(!1),[h,g]=(0,i.useState)(void 0),[_,v]=(0,i.useState)(()=>({...f})),[y,b]=(0,i.useState)(f.remoteWorkspaceWidthRatio),[x,S]=(0,i.useState)(!1),[C,w]=(0,i.useState)(void 0),[T,E]=(0,i.useState)(()=>NY(void 0)),[D,O]=(0,i.useState)(!1),[k,A]=(0,i.useState)(!1),[j,M]=(0,i.useState)(void 0),N=(0,i.useId)(),ee=(0,i.useId)(),P=(0,i.useCallback)(()=>{g(void 0);let e=V.getProxySettings().then(e=>e,()=>void 0);Promise.all([V.getHosts(),V.getWorkspaces(),qq(),e]).then(([e,t,n,i])=>{r(e),s(t.mode),l(t.version),n!==void 0&&(v(n),b(n.remoteWorkspaceWidthRatio)),i!==void 0&&(w(i),E(NY(i)))},e=>g(e instanceof pn?e.message:String(e)))},[]);(0,i.useEffect)(()=>{P()},[P]);let F=(0,i.useCallback)(()=>{P(),Ml()},[P]),I=e=>{e===a||u||(d(!0),g(void 0),V.setRoutingMode(e).then(e=>{s(e),Ml()},e=>g(e instanceof pn?e.message:String(e))).finally(()=>d(!1)))},te=(0,i.useCallback)(e=>{S(!0),g(void 0),Jq(e).then(e=>{v(e),b(e.remoteWorkspaceWidthRatio)},e=>g(e instanceof pn?e.message:String(e))).finally(()=>S(!1))},[]),L=()=>{x||y===_.remoteWorkspaceWidthRatio||te({remoteWorkspaceWidthRatio:y})},R=()=>{let e=IY(T);if(e!==void 0){M(t(e===`target`?`proxy.invalidTarget`:`proxy.invalidJump`));return}A(!0),M(void 0);let n=T.mode===`proxy`?{defaultMode:`proxy`,target:PY(T)}:{defaultMode:`direct`};V.patchProxySettings(n).then(e=>{w(e),E(NY(e))},e=>M(t(`proxy.saveFailed`).replace(`{message}`,e instanceof pn?e.message:String(e)))).finally(()=>A(!1))},ne=LY(t,NY(C),void 0),z={mode:T.mode,label:ne,title:t(`proxy.chipTitle`).replace(`{summary}`,ne),problem:!1};return(0,o.jsxs)(`div`,{style:{padding:`4px 2px`,fontSize:13,lineHeight:1.5},children:[(0,o.jsxs)(`div`,{style:{...tz,borderTop:`none`,borderBottom:`1px solid rgba(127,127,127,.25)`,marginBottom:10,paddingBottom:8},children:[(0,o.jsxs)(fz,{children:[(0,o.jsx)(`span`,{style:{fontSize:12,opacity:.75},children:t(`route.mode`)}),(0,o.jsxs)(`select`,{value:a,disabled:u,onChange:e=>I(e.target.value),style:{...rz,opacity:u?.5:1},children:[(0,o.jsx)(`option`,{value:`off`,style:iz,children:t(`route.off`)}),(0,o.jsx)(`option`,{value:`shadow`,style:iz,children:t(`route.shadow`)}),(0,o.jsx)(`option`,{value:`enforce`,style:iz,children:t(`route.enforce`)})]}),u&&(0,o.jsx)(`span`,{style:{fontSize:12,opacity:.6},children:t(`route.saving`)}),c!==``&&(0,o.jsxs)(`span`,{style:{marginLeft:`auto`,fontSize:11,opacity:.6},children:[t(`plugin.version`),`: `,(0,o.jsxs)(`code`,{children:[`v`,c]})]})]}),(0,o.jsx)(`div`,{style:{fontSize:11,opacity:.6,marginTop:4},children:t(`route.hint`)})]}),h!==void 0&&(0,o.jsx)(uz,{kind:`error`,children:h}),(0,o.jsx)(GY,{t,hosts:n,proxyDefault:C,onChanged:F}),(0,o.jsxs)(`div`,{style:{...tz,marginTop:12,paddingTop:10},children:[(0,o.jsx)(BY,{open:D,label:t(`proxy.default.title`),expandLabel:t(`proxy.expand`),collapseLabel:t(`proxy.collapse`),chip:z,controls:N,onToggle:()=>O(!D)}),(0,o.jsxs)(`div`,{id:N,hidden:!D,className:`rvs-proxy-panel`,children:[(0,o.jsxs)(fz,{children:[(0,o.jsxs)(`label`,{style:{marginRight:10,opacity:k?.5:1},children:[(0,o.jsx)(`input`,{type:`radio`,name:ee,checked:T.mode===`direct`,disabled:k,onChange:()=>{E({...T,mode:`direct`}),M(void 0)}}),` `,t(`proxy.mode.direct`)]}),(0,o.jsxs)(`label`,{style:{opacity:k?.5:1},children:[(0,o.jsx)(`input`,{type:`radio`,name:ee,checked:T.mode===`proxy`,disabled:k,onChange:()=>{E({...T,mode:`proxy`}),M(void 0)}}),` `,t(`proxy.mode.proxy`)]})]}),T.mode===`proxy`&&(0,o.jsx)(VY,{t,state:T,onChange:e=>{E(e),M(void 0)},storedPassword:C?.target?.hasPassword===!0&&T.kind===C.target.kind&&T.host.trim()===C.target.host&&T.port.trim()===String(C.target.port)&&T.username.trim()===(C.target.username??``),disabled:k}),(0,o.jsx)(`div`,{style:{fontSize:11,opacity:.6,marginBottom:8},children:t(`proxy.default.hint`)}),(0,o.jsx)(fz,{children:(0,o.jsx)(cz,{kind:`primary`,onClick:R,disabled:k,children:t(k?`proxy.saving`:`proxy.save`)})}),j!==void 0&&(0,o.jsx)(uz,{kind:`error`,children:j})]})]}),(0,o.jsxs)(`div`,{style:{...tz,marginTop:12,paddingTop:10},children:[(0,o.jsx)(`div`,{style:{fontSize:12,opacity:.75,marginBottom:6},children:t(`viewSettings.title`)}),(0,o.jsxs)(fz,{children:[(0,o.jsxs)(`label`,{style:{display:`flex`,alignItems:`center`,gap:6,fontSize:12,opacity:x?.5:1},children:[(0,o.jsx)(`input`,{type:`checkbox`,checked:_.autoOpenRemoteWorkspace,disabled:x,onChange:e=>te({autoOpenRemoteWorkspace:e.target.checked})}),t(`viewSettings.autoOpen`)]}),x&&(0,o.jsx)(`span`,{style:{fontSize:12,opacity:.6},children:t(`route.saving`)})]}),(0,o.jsx)(`div`,{style:{fontSize:11,opacity:.6,marginTop:4},children:t(`viewSettings.autoOpenHint`)}),(0,o.jsxs)(fz,{children:[(0,o.jsx)(`span`,{style:{fontSize:12,opacity:.75},children:t(`viewSettings.width`)}),(0,o.jsx)(`input`,{type:`range`,min:p,max:m,step:.05,value:y,disabled:x,onChange:e=>b(Number(e.target.value)),onPointerUp:L,onKeyUp:L,onBlur:L,style:{width:180,accentColor:`inherit`,opacity:x?.5:1}}),(0,o.jsxs)(`span`,{style:{fontSize:12,opacity:.75},children:[Math.round(y*100),`%`]})]}),(0,o.jsx)(`div`,{style:{fontSize:11,opacity:.6,marginTop:4},children:t(`viewSettings.widthHint`)})]})]})}function qY(e){let[t]=(0,i.useState)(()=>fe(de())),[n,r]=(0,i.useState)([]),[a,s]=(0,i.useState)([]),[c,l]=(0,i.useState)({mode:`off`,aliasPaths:{},tombstones:[]}),[u,d]=(0,i.useState)(void 0),f=(0,i.useCallback)(()=>{d(void 0),Promise.all([V.getHosts(),V.getWorkspaces()]).then(([e,t])=>{r(e),s(t.workspaces),l({mode:t.mode,aliasPaths:t.aliasPaths,tombstones:t.tombstones})},e=>d(e instanceof pn?e.message:String(e)))},[]);(0,i.useEffect)(()=>{f()},[f]);let p=(0,i.useCallback)(()=>{f(),Ml()},[f]);return(0,o.jsxs)(`div`,{style:{padding:`4px 2px`,fontSize:13,lineHeight:1.5},children:[u!==void 0&&(0,o.jsx)(uz,{kind:`error`,children:u}),(0,o.jsx)(Sq,{t,hosts:n,workspaces:a,routing:c,onChanged:p})]})}let JY=[`slots`,`uiWorkspace`];function YY({size:e}){let t=e??16;return(0,o.jsxs)(`svg`,{width:t,height:t,viewBox:`0 0 16 16`,"aria-hidden":`true`,style:{display:`block`},children:[(0,o.jsx)(`rect`,{x:`1`,y:`1`,width:`14`,height:`14`,rx:`3`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.4`}),(0,o.jsx)(`text`,{x:`3.2`,y:`11.6`,fontFamily:`monospace`,fontSize:`7.5`,fontWeight:`bold`,fill:`currentColor`,children:`>_`})]})}function XY(e){e.effect(()=>YB(e),`dsh-remote-vs: preview host services`);let t=fe(de());e.effect(()=>{let n,r,i,a=0,s=!1,c=()=>{i!==void 0&&(clearInterval(i),i=void 0)},l=()=>{if(s)return!0;let r;try{r=e.get(`betterSidebar`)??void 0}catch{return!1}if(r===void 0)return!1;try{let e=r;typeof e.fileIcon==`function`&&typeof e.folderIcon==`function`&&Ws(e)}catch{}try{n=r.registerTab({id:`remote-vs:explorer`,title:()=>t(`tab.remote`),description:()=>t(`tab.remoteDesc`),icon:e=>(0,o.jsx)(YY,{size:e}),order:30,single:!0,component:()=>(0,o.jsx)(Fq,{ctx:e})})}catch{return!1}return so(),s=!0,c(),!0},u=()=>{s||(s=!0,c(),r=zq(e,t)??void 0,r!==void 0&&so())};if(!l()){try{let t=e.get(`loader`);typeof t?.await==`function`&&t.await().then(()=>{l()||u()},()=>{})}catch{}i=setInterval(()=>{a+=1,!l()&&a>=60&&u()},500),i.unref?.()}return()=>{c();try{n?.()}catch{}try{r?.()}catch{}(n!==void 0||r!==void 0)&&co()}},`dsh-remote-vs: explorer surface (better tab preferred, native fallback)`),e.effect(()=>e.slots.inject(`conversation.hero.workspace.directoryFlow`,()=>e.slots.inject(`sidebar.workspaces.directoryFlow`,function*(){let t={listDirectory:(t,n)=>e.uiWorkspace.listDirectory(t,n),createDirectory:(t,n)=>e.uiWorkspace.createDirectory(t,n),pickDirectory:()=>e.uiWorkspace.pickDirectory()};yield e.slots.register({name:`conversation.hero.workspace.directoryFlow`,priority:-1,inject:()=>t},uJ),yield e.slots.register({name:`sidebar.workspaces.directoryFlow`,priority:-1,inject:()=>t},uJ)})),`dsh-remote-vs: directory flow`),e.effect(()=>{let t;try{let n=e.slots;t=n.inject(`conversation.input.dock`,()=>n.register({name:`conversation.input.dock`,id:`remote-changes`,order:30},oY))}catch(e){return console.warn(`[dsh-remote-vs] conversation.input.dock registration failed:`,e),()=>{}}return()=>{try{t?.()}catch{}}},`dsh-remote-vs: session changes dock`),e.effect(()=>DJ(e),`dsh-remote-vs: remote file click routing`);let n=fe(de());e.effect(()=>e.slots.inject(`settings.section`,()=>e.slots.register({name:`settings.section`,id:`remote-hosts`,order:20,label:()=>n(`settings.hosts`)},KY)),`dsh-remote-vs: settings hosts`),e.effect(()=>e.slots.inject(`settings.section`,()=>e.slots.register({name:`settings.section`,id:`remote-workspaces`,order:21,label:()=>n(`settings.workspaces`)},qY)),`dsh-remote-vs: settings workspaces`),e.effect(()=>Qq(e),`dsh-remote-vs: auto-open remote workspace`);let r=fe(de());e.effect(()=>{let t;try{let n=e.slots;t=n.inject(`conversation.view`,()=>n.register({name:`conversation.view`,id:`remote-editor`,order:30,label:()=>r(`view.editor`)},()=>(0,o.jsx)(OJ,{ctx:e}))),so()}catch(e){return console.warn(`[dsh-remote-vs] conversation.view registration failed:`,e),()=>{}}return()=>{co(),cd(`sidebar`);try{t?.()}catch{}}},`dsh-remote-vs: conversation view (editor + diff)`),e.effect(()=>bJ(r(`view.editor`),()=>{fd()}),`dsh-remote-vs: float on tab double-click`),e.effect(()=>{let t,n;try{let r=e.slots;t=r.inject(`shell.overlay`,()=>r.register({name:`shell.overlay`,id:`remote-vs:floating-editor`,order:40},()=>(0,o.jsx)(yJ,{ctx:e}))),n=r.inject(`shell.overlay`,()=>r.register({name:`shell.overlay`,id:`remote-vs:toast-host`,order:41},()=>(0,o.jsx)(vc,{})))}catch(e){return console.warn(`[dsh-remote-vs] shell.overlay registration failed (floating editor unavailable):`,e),()=>{}}return()=>{for(let e of[t,n])try{e?.()}catch{}}},`dsh-remote-vs: floating editor window`),e.effect(()=>(he(H),()=>he(void 0)),`dsh-remote-vs: host notice toasts`)}return n.apply=XY,n.inject=JY,t.exports}});
7980
+ `)}function CY(e){return(0,o.jsx)(`span`,{className:`rvs-doctor-badge ${e.item.state}`,children:e.t(cY[e.item.state])})}let wY=new Map;function TY(e){let t=wY.get(e);if(t!==void 0)return t;let n=V.exec(e,lY(),2e4).then(e=>bY(e.stdout,e.stderr,e.exitCode),e=>xY(e instanceof Error?e.message:String(e))).finally(()=>{wY.get(e)===n&&wY.delete(e)});return wY.set(e,n),n}async function EY(e){try{return await navigator.clipboard.writeText(e),!0}catch{}try{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t),t.select();let n=document.execCommand(`copy`);return t.remove(),n}catch{return!1}}function DY(e){return e===null?[]:Array.from(e.querySelectorAll(`button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])`))}function OY(e){let t=e.t,[n,r]=(0,i.useState)(void 0),[a,s]=(0,i.useState)(`idle`),c=(0,i.useRef)(null),l=(0,i.useRef)(null),u=(0,i.useRef)(!0);(0,i.useEffect)(()=>(u.current=!0,()=>{u.current=!1}),[]);let d=(0,i.useCallback)(()=>{TY(e.alias).then(e=>{u.current&&r(e)})},[e.alias]);(0,i.useEffect)(()=>{d()},[d]),(0,i.useEffect)(()=>{l.current=typeof document>`u`?null:document.activeElement;let e=window.setTimeout(()=>{DY(c.current)[0]?.focus()},0);return()=>{window.clearTimeout(e);let t=l.current;t!==null&&document.body.contains(t)&&t.focus()}},[]),(0,i.useEffect)(()=>{let t=t=>{if(t.key===`Escape`){t.stopPropagation(),e.onClose();return}if(t.key!==`Tab`)return;let n=DY(c.current);if(n.length===0)return;let r=n[0],i=n[n.length-1],a=document.activeElement;c.current?.contains(a)===!0?t.shiftKey&&a===r?(t.preventDefault(),i.focus()):!t.shiftKey&&a===i&&(t.preventDefault(),r.focus()):(t.preventDefault(),t.shiftKey?i.focus():r.focus())};return document.addEventListener(`keydown`,t,!0),()=>document.removeEventListener(`keydown`,t,!0)},[e.onClose]);let f=()=>{n!==void 0&&EY(SY(e.alias,n,t)).then(e=>{u.current&&s(e?`copied`:`failed`)})},p=t(a===`copied`?`doctor.copied`:a===`failed`?`doctor.copyFailed`:`doctor.copy`),m=t(`doctor.title`).replace(`{alias}`,e.alias),h=n!==void 0&&n.some(e=>e.state===`unknown`);return(0,o.jsx)(`div`,{className:`rvs-doctor`,role:`dialog`,"aria-modal":`true`,"aria-label":m,onClick:e.onClose,children:(0,o.jsxs)(`div`,{ref:c,className:`rvs-doctor-card`,onClick:e=>e.stopPropagation(),children:[(0,o.jsxs)(`div`,{className:`rvs-doctor-head`,children:[(0,o.jsx)(`span`,{className:`rvs-doctor-title`,children:m}),(0,o.jsx)(`span`,{style:{flex:1}}),(0,o.jsx)(cz,{onClick:f,disabled:n===void 0,children:p}),(0,o.jsx)(cz,{onClick:e.onClose,children:t(`doctor.close`)})]}),n===void 0?(0,o.jsx)(`div`,{className:`rvs-doctor-body`,children:(0,o.jsxs)(`div`,{className:`rvs-doctor-loading`,children:[(0,o.jsx)(lz,{}),` `,t(`doctor.loading`)]})}):(0,o.jsx)(`div`,{className:`rvs-doctor-body`,children:(0,o.jsxs)(`table`,{className:`rvs-doctor-table`,children:[(0,o.jsx)(`thead`,{children:(0,o.jsxs)(`tr`,{children:[(0,o.jsx)(`th`,{children:t(`doctor.colItem`)}),(0,o.jsx)(`th`,{children:t(`doctor.colState`)}),(0,o.jsx)(`th`,{children:t(`doctor.colDetail`)})]})}),(0,o.jsx)(`tbody`,{children:n.map(e=>(0,o.jsxs)(`tr`,{children:[(0,o.jsx)(`td`,{className:`rvs-doctor-item`,children:t(e.label)}),(0,o.jsx)(`td`,{children:(0,o.jsx)(CY,{item:e,t})}),(0,o.jsx)(`td`,{className:`rvs-doctor-detail`,title:e.detail,children:e.detail})]},e.key))})]})}),h&&(0,o.jsx)(`div`,{className:`rvs-doctor-hint`,children:t(`doctor.unknownHint`)})]})})}function kY(e){return e instanceof pn?e.message:String(e)}function AY(e,t){return e(t===`http`?`proxy.shortHttp`:`proxy.shortSocks5`)}function jY(){return{mode:`inherit`,kind:`http`,host:``,port:``,username:``,password:``,viaAlias:``}}function MY(e){let t=jY();return e===void 0?t:(t.mode=e.mode,t.viaAlias=e.jumpVia??``,e.target!==void 0&&(t.kind=e.target.kind,t.host=e.target.host,t.port=String(e.target.port),t.username=e.target.username??``),t)}function NY(e){let t=jY();return t.mode=e===void 0?`direct`:e.defaultMode,e?.target!==void 0&&(t.kind=e.target.kind,t.host=e.target.host,t.port=String(e.target.port),t.username=e.target.username??``),t}function PY(e){let t=Number.parseInt(e.port,10),n=e.username.trim();return{kind:e.kind,host:e.host.trim(),port:Number.isInteger(t)?t:0,...n===``?{}:{username:n},...e.password===``?{}:{password:e.password}}}function FY(e){if(e.mode!==`inherit`)return e.mode===`direct`?{mode:`direct`}:e.mode===`jump`?{mode:`jump`,jump:{viaAlias:e.viaAlias.trim()}}:{mode:`proxy`,proxy:PY(e)}}function IY(e,t){if(e.mode===`proxy`){let t=Number.parseInt(e.port,10);if(e.host.trim()===``||!Number.isInteger(t)||t<1||t>65535)return`target`}if(e.mode===`jump`){let n=e.viaAlias.trim();if(n===``)return`jump`;if(t!==void 0&&!t.includes(n))return`jumpGone`}}function LY(e,t,n){if(t.mode===`direct`)return e(`proxy.summaryDirect`);if(t.mode===`proxy`){let n=t.host.trim(),r=t.port.trim();return n===``||r===``?e(`proxy.chipProxy`):e(`proxy.summaryProxy`).replace(`{kind}`,AY(e,t.kind)).replace(`{host}`,n).replace(`{port}`,r)}if(t.mode===`jump`){let n=t.viaAlias.trim();return n===``?e(`proxy.mode.jump`):e(`proxy.summaryJump`).replace(`{alias}`,n)}let r=n?.target;return n===void 0||n.defaultMode===`proxy`&&r===void 0?e(`proxy.chipInherit`):n.defaultMode===`direct`?e(`proxy.summaryInheritDirect`):e(`proxy.summaryInheritProxy`).replace(`{kind}`,AY(e,r?.kind??`http`)).replace(`{host}`,r?.host??``).replace(`{port}`,String(r?.port??``))}function RY(e,t,n){let r=LY(e,MY(t),n),i=t.mode===`jump`?t.jumpVia===void 0?e(`proxy.mode.jump`):e(`proxy.chipJump`).replace(`{alias}`,t.jumpVia):r;return{mode:t.mode,label:i,title:t.problem??e(`proxy.chipTitle`).replace(`{summary}`,r),problem:t.problem!==void 0}}function zY(e){let t=e.chip;return(0,o.jsx)(`span`,{className:t.problem?`rvs-proxy-chip is-error`:`rvs-proxy-chip`,"data-proxy-mode":t.mode,...t.problem?{"data-proxy-problem":`1`}:{},title:t.title,children:t.label})}function BY(e){return(0,o.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:8,marginBottom:e.open?8:4},children:[(0,o.jsxs)(`button`,{type:`button`,className:`rvs-proxy-toggle`,"aria-expanded":e.open,"aria-controls":e.controls,title:e.open?e.collapseLabel:e.expandLabel,onClick:e.onToggle,children:[(0,o.jsx)(`span`,{className:`rvs-proxy-caret`,"aria-hidden":`true`,children:`▸`}),(0,o.jsx)(`span`,{style:{fontSize:12,opacity:.75},children:e.label})]}),(0,o.jsx)(`span`,{style:{flex:1}}),(0,o.jsx)(zY,{chip:e.chip})]})}function VY(e){let t=e.t,n=e.state,r=t=>e.onChange({...n,...t}),i=e.disabled===!0;return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(`div`,{style:{display:`flex`,gap:8},children:[(0,o.jsx)(`div`,{style:{flex:1.1},children:(0,o.jsx)(dz,{label:t(`proxy.kind`),children:(0,o.jsxs)(`select`,{className:`rvs-dropdown`,value:n.kind,disabled:i,onChange:e=>r({kind:e.target.value===`socks5`?`socks5`:`http`}),style:rz,children:[(0,o.jsx)(`option`,{value:`http`,style:iz,children:t(`proxy.typeHttp`)}),(0,o.jsx)(`option`,{value:`socks5`,style:iz,children:t(`proxy.typeSocks5`)})]})})}),(0,o.jsx)(`div`,{style:{flex:1.9},children:(0,o.jsx)(dz,{label:t(`proxy.host`),children:(0,o.jsx)(`input`,{value:n.host,disabled:i,onChange:e=>r({host:e.target.value}),placeholder:`192.0.2.10`,style:nz})})}),(0,o.jsx)(`div`,{style:{flex:.8},children:(0,o.jsx)(dz,{label:t(`proxy.port`),children:(0,o.jsx)(`input`,{value:n.port,disabled:i,inputMode:`numeric`,onChange:e=>r({port:e.target.value}),placeholder:`3128`,style:nz})})})]}),(0,o.jsxs)(`div`,{style:{display:`flex`,gap:8},children:[(0,o.jsx)(`div`,{style:{flex:1},children:(0,o.jsx)(dz,{label:t(`proxy.username`),children:(0,o.jsx)(`input`,{value:n.username,disabled:i,autoComplete:`off`,onChange:e=>r({username:e.target.value}),style:nz})})}),(0,o.jsx)(`div`,{style:{flex:1},children:(0,o.jsx)(dz,{label:t(`proxy.password`),children:(0,o.jsx)(`input`,{type:`password`,value:n.password,disabled:i,autoComplete:`new-password`,onChange:e=>r({password:e.target.value}),placeholder:e.storedPassword?t(`proxy.passwordKeep`):``,style:nz})})})]})]})}function HY(e){let t=e.t,n=e.state,r=t=>e.onChange({...n,...t}),a=(0,i.useId)(),s=(0,i.useId)(),c=LY(t,n,e.proxyDefault),l={mode:n.mode,label:c,title:t(`proxy.chipTitle`).replace(`{summary}`,c),problem:!1},u=e.hosts.filter(t=>t.alias!==e.self),d=n.viaAlias!==``&&!u.some(e=>e.alias===n.viaAlias);return(0,o.jsxs)(`div`,{style:{...tz,marginTop:2,paddingTop:8,marginBottom:8},children:[(0,o.jsx)(BY,{open:e.open,label:t(`proxy.title`),expandLabel:t(`proxy.expand`),collapseLabel:t(`proxy.collapse`),chip:l,controls:a,onToggle:e.onToggle}),(0,o.jsxs)(`div`,{id:a,hidden:!e.open,className:`rvs-proxy-panel`,children:[(0,o.jsxs)(fz,{children:[(0,o.jsx)(`span`,{style:{opacity:.75,marginRight:4},children:t(`proxy.mode`)}),(0,o.jsxs)(`label`,{style:{marginRight:10},children:[(0,o.jsx)(`input`,{type:`radio`,name:s,checked:n.mode===`inherit`,disabled:e.busy,onChange:()=>r({mode:`inherit`})}),` `,t(`proxy.mode.inherit`)]}),(0,o.jsxs)(`label`,{style:{marginRight:10},children:[(0,o.jsx)(`input`,{type:`radio`,name:s,checked:n.mode===`direct`,disabled:e.busy,onChange:()=>r({mode:`direct`})}),` `,t(`proxy.mode.direct`)]}),(0,o.jsxs)(`label`,{style:{marginRight:10},children:[(0,o.jsx)(`input`,{type:`radio`,name:s,checked:n.mode===`proxy`,disabled:e.busy,onChange:()=>r({mode:`proxy`})}),` `,t(`proxy.mode.proxy`)]}),(0,o.jsxs)(`label`,{children:[(0,o.jsx)(`input`,{type:`radio`,name:s,checked:n.mode===`jump`,disabled:e.busy,onChange:()=>r({mode:`jump`})}),` `,t(`proxy.mode.jump`)]})]}),n.mode===`proxy`&&(0,o.jsx)(VY,{t,state:n,onChange:e.onChange,storedPassword:e.storedPassword,disabled:e.busy}),n.mode===`jump`&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(dz,{label:t(`proxy.jumpVia`),children:(0,o.jsxs)(`select`,{className:`rvs-dropdown`,value:n.viaAlias,disabled:e.busy,onChange:e=>r({viaAlias:e.target.value}),style:rz,children:[u.length===0&&(0,o.jsx)(`option`,{value:``,style:iz,children:t(`proxy.jumpNone`)}),d&&(0,o.jsx)(`option`,{value:n.viaAlias,style:iz,children:t(`proxy.jumpMissing`).replace(`{alias}`,n.viaAlias)}),u.map(e=>(0,o.jsx)(`option`,{value:e.alias,style:iz,children:e.alias===e.host?e.alias:`${e.alias} (${e.host})`},e.alias))]})}),(0,o.jsx)(`div`,{style:{fontSize:11,opacity:.6,marginBottom:8},children:t(`proxy.jumpHint`)})]}),e.error!==void 0&&(0,o.jsx)(uz,{kind:`error`,children:e.error})]})]})}function UY(e){let t=e.deploy;if(t===void 0||t.status===`not-deployed`)return(0,o.jsx)(`span`,{style:{opacity:.6},children:e.t(`deploy.notDeployed`)});let n=t.status===`failed`?`#e06060`:t.status===`ok`?`#7ee2a8`:`#e8b84b`,r=t.status===`ok`?e.t(`deploy.ok`):t.status===`skipped-same`?e.t(`deploy.skipped`):e.t(`deploy.failed`);return(0,o.jsxs)(`span`,{title:t.detail??t.artifact,style:{color:n},children:[r,` · `,t.artifact,t.manifestHash===void 0?``:` ${t.manifestHash.slice(0,8)}`]})}function WY(e){let t=e.t,[n,r]=(0,i.useState)(e.initial?.alias??``),[a,s]=(0,i.useState)(e.initial?.host??``),[c,l]=(0,i.useState)(String(e.initial?.port??22)),[u,d]=(0,i.useState)(e.initial?.user??``),[f,p]=(0,i.useState)(e.initial?.auth??`key`),[m,h]=(0,i.useState)(``),[g,_]=(0,i.useState)(``),[v,y]=(0,i.useState)(``),[b,x]=(0,i.useState)(e.initial?.description??``),[S,C]=(0,i.useState)(()=>MY(e.initial?.proxy)),[w,T]=(0,i.useState)(!1),[E,D]=(0,i.useState)(void 0),O=e.initial?.proxy?.target,k=O?.hasPassword===!0&&S.mode===`proxy`&&S.kind===O.kind&&S.host.trim()===O.host&&S.port.trim()===String(O.port)&&S.username.trim()===(O.username??``),A=e.hosts.filter(t=>t.alias!==e.initial?.alias).map(e=>e.alias),j=()=>{let r=IY(S,A);if(r!==void 0){D(r===`target`?t(`proxy.invalidTarget`):r===`jump`?t(`proxy.invalidJump`):t(`proxy.jumpGone`).replace(`{alias}`,S.viaAlias.trim())),T(!0);return}D(void 0);let i=Number.parseInt(c,10),o=FY(S),s={alias:n.trim(),host:a.trim(),port:Number.isFinite(i)?i:22,user:u.trim(),auth:f===`key`?{kind:`key`,keyPath:m.trim(),...g===``?{}:{passphrase:g}}:{kind:`password`,password:v},...b.trim()===``?{}:{description:b.trim()},...o===void 0?{}:{proxy:o}};e.onSave(s)};return(0,o.jsxs)(`div`,{style:{...tz,marginTop:10,paddingTop:10},children:[(0,o.jsx)(dz,{label:t(`form.alias`),children:(0,o.jsx)(`input`,{value:n,disabled:e.initial!==void 0||e.busy,onChange:e=>r(e.target.value),placeholder:`prod-web-1`,style:nz})}),(0,o.jsxs)(`div`,{style:{display:`flex`,gap:8},children:[(0,o.jsx)(`div`,{style:{flex:2},children:(0,o.jsx)(dz,{label:t(`form.host`),children:(0,o.jsx)(`input`,{value:a,disabled:e.busy,onChange:e=>s(e.target.value),placeholder:`192.0.2.10`,style:nz})})}),(0,o.jsx)(`div`,{style:{flex:1},children:(0,o.jsx)(dz,{label:t(`form.port`),children:(0,o.jsx)(`input`,{value:c,disabled:e.busy,onChange:e=>l(e.target.value),style:nz})})}),(0,o.jsx)(`div`,{style:{flex:1},children:(0,o.jsx)(dz,{label:t(`form.user`),children:(0,o.jsx)(`input`,{value:u,disabled:e.busy,onChange:e=>d(e.target.value),placeholder:`root`,style:nz})})})]}),(0,o.jsxs)(`div`,{style:{marginBottom:8,fontSize:12},children:[(0,o.jsx)(`span`,{style:{opacity:.75,marginRight:8},children:t(`form.auth`)}),(0,o.jsxs)(`label`,{style:{marginRight:10},children:[(0,o.jsx)(`input`,{type:`radio`,checked:f===`key`,disabled:e.busy,onChange:()=>p(`key`)}),` `,t(`form.authKey`)]}),(0,o.jsxs)(`label`,{children:[(0,o.jsx)(`input`,{type:`radio`,checked:f===`password`,disabled:e.busy,onChange:()=>p(`password`)}),` `,t(`form.authPassword`)]})]}),f===`key`?(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(dz,{label:t(`form.keyPath`),children:(0,o.jsx)(`input`,{value:m,disabled:e.busy,onChange:e=>h(e.target.value),placeholder:e.initial?.auth===`key`?t(`form.unchanged`):`C:\\Users\\me\\.ssh\\id_ed25519`,style:nz})}),(0,o.jsx)(dz,{label:t(`form.passphrase`),children:(0,o.jsx)(`input`,{type:`password`,value:g,disabled:e.busy,onChange:e=>_(e.target.value),placeholder:e.initial===void 0?``:t(`form.unchangedWhenEmpty`),style:nz})})]}):(0,o.jsx)(dz,{label:t(`form.password`),children:(0,o.jsx)(`input`,{type:`password`,value:v,disabled:e.busy,onChange:e=>y(e.target.value),placeholder:e.initial?.auth===`password`?t(`form.unchangedWhenEmpty`):``,style:nz})}),(0,o.jsx)(HY,{t,state:S,onChange:e=>{C(e),D(void 0)},open:w,onToggle:()=>T(!w),proxyDefault:e.proxyDefault,hosts:e.hosts,self:e.initial?.alias,storedPassword:k,busy:e.busy,error:E}),(0,o.jsx)(dz,{label:t(`form.description`),children:(0,o.jsx)(`input`,{value:b,disabled:e.busy,onChange:e=>x(e.target.value),style:nz})}),(0,o.jsxs)(fz,{children:[(0,o.jsx)(cz,{kind:`primary`,onClick:j,disabled:e.busy,children:t(`hosts.save`)}),(0,o.jsx)(cz,{onClick:e.onCancel,disabled:e.busy,children:t(`hosts.cancel`)})]})]})}function GY(e){let t=e.t,[n,r]=(0,i.useState)(void 0),[a,s]=(0,i.useState)(void 0),[c,l]=(0,i.useState)(void 0),[u,d]=(0,i.useState)(null),[f,p]=(0,i.useState)(null),m=e=>{r(e),s(void 0)},h=e=>{s(kY(e)),r(void 0)},g=e=>{l(`test:${e}`),V.testHost(e).then(n=>{l(void 0),n.ok?m(t(`hosts.testOk`).replace(`{alias}`,e).replace(`{ms}`,String(n.durationMs))):h(`${e}: ${n.error??t(`hosts.unknownError`)}`)},e=>{l(void 0),h(e)})},_=t=>{l(`key:${t}`),V.bootstrap(t).then(n=>{l(void 0),m(`${t}: ${n.detail} → ${n.keyPath}`),e.onChanged()},e=>{l(void 0),h(e)})},v=t=>{l(`push:${t}`),V.deployPush(t).then(n=>{l(void 0),m(`${t}: ${n.detail}`),e.onChanged()},e=>{l(void 0),h(e)})},y=async n=>{await hc({title:t(`hosts.confirmDelete`),danger:!0,okText:t(`hosts.delete`)})&&(l(`del:${n}`),V.deleteHost(n).then(()=>{l(void 0),m(t(`hosts.deleted`).replace(`{alias}`,n)),e.onChanged()},e=>{l(void 0),h(e)}))},b=n=>{l(`import:${n}`),(n===`ssh-config`?V.importSshConfig():V.importDshSsh()).then(n=>{l(void 0);let r=n.skipped.map(e=>`${e.alias}(${e.reason})`).join(`; `);m(`${t(`hosts.imported`).replace(`{count}`,String(n.imported.length))}${n.imported.length>0?`: ${n.imported.join(`, `)}`:``}${r===``?``:t(`hosts.importedSkipped`).replace(`{list}`,r)}`),e.onChanged()},e=>{l(void 0),h(e)})},x=n=>{l(`save`);let r=u===`new`?void 0:u,i=r===void 0?void 0:e.hosts.find(e=>e.alias===r)?.proxy,a=n.proxy??(i===void 0||i.mode===`inherit`?void 0:{mode:`inherit`});(r===void 0?V.createHost(n):V.updateHost(r,{host:n.host,port:n.port,user:n.user,auth:n.auth,description:n.description,...a===void 0?{}:{proxy:a}})).then(n=>{l(void 0),d(null),m(t(`hosts.saved`).replace(`{alias}`,n.alias)),e.onChanged()},e=>{l(void 0),h(e)})},S=c!==void 0;return(0,o.jsxs)(`div`,{style:{flex:1,minHeight:0,overflow:`auto`},children:[(0,o.jsxs)(fz,{children:[(0,o.jsx)(`strong`,{style:{fontSize:14},children:t(`hosts.title`)}),(0,o.jsx)(`span`,{style:{flex:1}}),(0,o.jsx)(cz,{kind:`primary`,onClick:()=>{d(`new`),r(void 0),s(void 0)},disabled:S||u!==null,children:t(`hosts.add`)})]}),(0,o.jsx)(`div`,{style:{marginTop:8},children:(0,o.jsxs)(fz,{children:[(0,o.jsx)(cz,{onClick:()=>b(`ssh-config`),disabled:S,children:t(`hosts.importSshConfig`)}),(0,o.jsx)(cz,{onClick:()=>b(`dsh-ssh`),disabled:S,children:t(`hosts.importDshSsh`)})]})}),n!==void 0&&(0,o.jsx)(uz,{kind:`info`,children:n}),a!==void 0&&(0,o.jsx)(uz,{kind:`error`,children:a}),e.hosts.length===0&&u===null&&(0,o.jsx)(`div`,{style:{opacity:.7,marginTop:10},children:t(`hosts.empty`)}),e.hosts.map(n=>(0,o.jsxs)(`div`,{style:{...tz,marginTop:10,paddingTop:8},children:[(0,o.jsxs)(fz,{children:[(0,o.jsx)(`code`,{style:{fontWeight:700},children:n.alias}),(0,o.jsxs)(`code`,{style:{opacity:.75},children:[n.user,`@`,n.host,`:`,n.port]}),(0,o.jsx)(zY,{chip:RY(t,n.proxy,e.proxyDefault)}),(0,o.jsxs)(`span`,{style:{fontSize:12,opacity:.75},children:[n.auth===`key`?n.keyReady?`🔑✓`:`🔑?`:`🔒`,n.managedKey?` (managed)`:``]})]}),(0,o.jsxs)(`div`,{style:{fontSize:12,margin:`4px 0`},children:[(0,o.jsx)(UY,{deploy:n.deploy,t}),n.description!==void 0&&n.description!==``&&(0,o.jsxs)(`span`,{style:{opacity:.7},children:[` · `,n.description]})]}),(0,o.jsxs)(fz,{children:[(0,o.jsx)(cz,{onClick:()=>g(n.alias),disabled:S,children:c===`test:${n.alias}`?t(`hosts.testing`):t(`hosts.test`)}),n.auth===`password`&&(0,o.jsx)(cz,{onClick:()=>_(n.alias),disabled:S,children:c===`key:${n.alias}`?t(`hosts.bootstrapping`):t(`hosts.bootstrap`)}),(0,o.jsx)(cz,{onClick:()=>v(n.alias),disabled:S,children:c===`push:${n.alias}`?t(`hosts.pushing`):t(`hosts.push`)}),(0,o.jsx)(cz,{onClick:()=>{p(n.alias),r(void 0),s(void 0)},disabled:S,children:t(`doctor.open`)}),(0,o.jsx)(cz,{onClick:()=>{d(u===n.alias?null:n.alias),r(void 0),s(void 0)},disabled:S,children:t(`hosts.edit`)}),(0,o.jsx)(cz,{kind:`danger`,onClick:()=>{y(n.alias)},disabled:S,children:t(`hosts.delete`)})]}),u===n.alias&&(0,o.jsx)(WY,{t,initial:n,busy:S,hosts:e.hosts,proxyDefault:e.proxyDefault,onSave:x,onCancel:()=>d(null)})]},n.alias)),f!==null&&(0,o.jsx)(OY,{t,alias:f,onClose:()=>p(null)},f),u===`new`&&(0,o.jsx)(WY,{t,busy:S,hosts:e.hosts,proxyDefault:e.proxyDefault,onSave:x,onCancel:()=>d(null)})]})}function KY(e){let[t]=(0,i.useState)(()=>fe(de())),[n,r]=(0,i.useState)([]),[a,s]=(0,i.useState)(`enforce`),[c,l]=(0,i.useState)(``),[u,d]=(0,i.useState)(!1),[h,g]=(0,i.useState)(void 0),[_,v]=(0,i.useState)(()=>({...f})),[y,b]=(0,i.useState)(f.remoteWorkspaceWidthRatio),[x,S]=(0,i.useState)(!1),[C,w]=(0,i.useState)(void 0),[T,E]=(0,i.useState)(()=>NY(void 0)),[D,O]=(0,i.useState)(!1),[k,A]=(0,i.useState)(!1),[j,M]=(0,i.useState)(void 0),N=(0,i.useId)(),ee=(0,i.useId)(),P=(0,i.useCallback)(()=>{g(void 0);let e=V.getProxySettings().then(e=>e,()=>void 0);Promise.all([V.getHosts(),V.getWorkspaces(),qq(),e]).then(([e,t,n,i])=>{r(e),s(t.mode),l(t.version),n!==void 0&&(v(n),b(n.remoteWorkspaceWidthRatio)),i!==void 0&&(w(i),E(NY(i)))},e=>g(e instanceof pn?e.message:String(e)))},[]);(0,i.useEffect)(()=>{P()},[P]);let F=(0,i.useCallback)(()=>{P(),Ml()},[P]),I=e=>{e===a||u||(d(!0),g(void 0),V.setRoutingMode(e).then(e=>{s(e),Ml()},e=>g(e instanceof pn?e.message:String(e))).finally(()=>d(!1)))},te=(0,i.useCallback)(e=>{S(!0),g(void 0),Jq(e).then(e=>{v(e),b(e.remoteWorkspaceWidthRatio)},e=>g(e instanceof pn?e.message:String(e))).finally(()=>S(!1))},[]),L=()=>{x||y===_.remoteWorkspaceWidthRatio||te({remoteWorkspaceWidthRatio:y})},R=()=>{let e=IY(T);if(e!==void 0){M(t(e===`target`?`proxy.invalidTarget`:`proxy.invalidJump`));return}A(!0),M(void 0);let n=T.mode===`proxy`?{defaultMode:`proxy`,target:PY(T)}:{defaultMode:`direct`};V.patchProxySettings(n).then(e=>{w(e),E(NY(e))},e=>M(t(`proxy.saveFailed`).replace(`{message}`,e instanceof pn?e.message:String(e)))).finally(()=>A(!1))},ne=LY(t,NY(C),void 0),z={mode:T.mode,label:ne,title:t(`proxy.chipTitle`).replace(`{summary}`,ne),problem:!1};return(0,o.jsxs)(`div`,{style:{padding:`4px 2px`,fontSize:13,lineHeight:1.5},children:[(0,o.jsxs)(`div`,{style:{...tz,borderTop:`none`,borderBottom:`1px solid rgba(127,127,127,.25)`,marginBottom:10,paddingBottom:8},children:[(0,o.jsxs)(fz,{children:[(0,o.jsx)(`span`,{style:{fontSize:12,opacity:.75},children:t(`route.mode`)}),(0,o.jsxs)(`select`,{className:`rvs-dropdown`,value:a,disabled:u,onChange:e=>I(e.target.value),style:{...rz,opacity:u?.5:1},children:[(0,o.jsx)(`option`,{value:`off`,style:iz,children:t(`route.off`)}),(0,o.jsx)(`option`,{value:`shadow`,style:iz,children:t(`route.shadow`)}),(0,o.jsx)(`option`,{value:`enforce`,style:iz,children:t(`route.enforce`)})]}),u&&(0,o.jsx)(`span`,{style:{fontSize:12,opacity:.6},children:t(`route.saving`)}),c!==``&&(0,o.jsxs)(`span`,{style:{marginLeft:`auto`,fontSize:11,opacity:.6},children:[t(`plugin.version`),`: `,(0,o.jsxs)(`code`,{children:[`v`,c]})]})]}),(0,o.jsx)(`div`,{style:{fontSize:11,opacity:.6,marginTop:4},children:t(`route.hint`)})]}),h!==void 0&&(0,o.jsx)(uz,{kind:`error`,children:h}),(0,o.jsx)(GY,{t,hosts:n,proxyDefault:C,onChanged:F}),(0,o.jsxs)(`div`,{style:{...tz,marginTop:12,paddingTop:10},children:[(0,o.jsx)(BY,{open:D,label:t(`proxy.default.title`),expandLabel:t(`proxy.expand`),collapseLabel:t(`proxy.collapse`),chip:z,controls:N,onToggle:()=>O(!D)}),(0,o.jsxs)(`div`,{id:N,hidden:!D,className:`rvs-proxy-panel`,children:[(0,o.jsxs)(fz,{children:[(0,o.jsxs)(`label`,{style:{marginRight:10,opacity:k?.5:1},children:[(0,o.jsx)(`input`,{type:`radio`,name:ee,checked:T.mode===`direct`,disabled:k,onChange:()=>{E({...T,mode:`direct`}),M(void 0)}}),` `,t(`proxy.mode.direct`)]}),(0,o.jsxs)(`label`,{style:{opacity:k?.5:1},children:[(0,o.jsx)(`input`,{type:`radio`,name:ee,checked:T.mode===`proxy`,disabled:k,onChange:()=>{E({...T,mode:`proxy`}),M(void 0)}}),` `,t(`proxy.mode.proxy`)]})]}),T.mode===`proxy`&&(0,o.jsx)(VY,{t,state:T,onChange:e=>{E(e),M(void 0)},storedPassword:C?.target?.hasPassword===!0&&T.kind===C.target.kind&&T.host.trim()===C.target.host&&T.port.trim()===String(C.target.port)&&T.username.trim()===(C.target.username??``),disabled:k}),(0,o.jsx)(`div`,{style:{fontSize:11,opacity:.6,marginBottom:8},children:t(`proxy.default.hint`)}),(0,o.jsx)(fz,{children:(0,o.jsx)(cz,{kind:`primary`,onClick:R,disabled:k,children:t(k?`proxy.saving`:`proxy.save`)})}),j!==void 0&&(0,o.jsx)(uz,{kind:`error`,children:j})]})]}),(0,o.jsxs)(`div`,{style:{...tz,marginTop:12,paddingTop:10},children:[(0,o.jsx)(`div`,{style:{fontSize:12,opacity:.75,marginBottom:6},children:t(`viewSettings.title`)}),(0,o.jsxs)(fz,{children:[(0,o.jsxs)(`label`,{style:{display:`flex`,alignItems:`center`,gap:6,fontSize:12,opacity:x?.5:1},children:[(0,o.jsx)(`input`,{type:`checkbox`,checked:_.autoOpenRemoteWorkspace,disabled:x,onChange:e=>te({autoOpenRemoteWorkspace:e.target.checked})}),t(`viewSettings.autoOpen`)]}),x&&(0,o.jsx)(`span`,{style:{fontSize:12,opacity:.6},children:t(`route.saving`)})]}),(0,o.jsx)(`div`,{style:{fontSize:11,opacity:.6,marginTop:4},children:t(`viewSettings.autoOpenHint`)}),(0,o.jsxs)(fz,{children:[(0,o.jsx)(`span`,{style:{fontSize:12,opacity:.75},children:t(`viewSettings.width`)}),(0,o.jsx)(`input`,{type:`range`,min:p,max:m,step:.05,value:y,disabled:x,onChange:e=>b(Number(e.target.value)),onPointerUp:L,onKeyUp:L,onBlur:L,style:{width:180,accentColor:`inherit`,opacity:x?.5:1}}),(0,o.jsxs)(`span`,{style:{fontSize:12,opacity:.75},children:[Math.round(y*100),`%`]})]}),(0,o.jsx)(`div`,{style:{fontSize:11,opacity:.6,marginTop:4},children:t(`viewSettings.widthHint`)})]})]})}function qY(e){let[t]=(0,i.useState)(()=>fe(de())),[n,r]=(0,i.useState)([]),[a,s]=(0,i.useState)([]),[c,l]=(0,i.useState)({mode:`off`,aliasPaths:{},tombstones:[]}),[u,d]=(0,i.useState)(void 0),f=(0,i.useCallback)(()=>{d(void 0),Promise.all([V.getHosts(),V.getWorkspaces()]).then(([e,t])=>{r(e),s(t.workspaces),l({mode:t.mode,aliasPaths:t.aliasPaths,tombstones:t.tombstones})},e=>d(e instanceof pn?e.message:String(e)))},[]);(0,i.useEffect)(()=>{f()},[f]);let p=(0,i.useCallback)(()=>{f(),Ml()},[f]);return(0,o.jsxs)(`div`,{style:{padding:`4px 2px`,fontSize:13,lineHeight:1.5},children:[u!==void 0&&(0,o.jsx)(uz,{kind:`error`,children:u}),(0,o.jsx)(Sq,{t,hosts:n,workspaces:a,routing:c,onChanged:p})]})}let JY=[`slots`,`uiWorkspace`];function YY({size:e}){let t=e??16;return(0,o.jsxs)(`svg`,{width:t,height:t,viewBox:`0 0 16 16`,"aria-hidden":`true`,style:{display:`block`},children:[(0,o.jsx)(`rect`,{x:`1`,y:`1`,width:`14`,height:`14`,rx:`3`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.4`}),(0,o.jsx)(`text`,{x:`3.2`,y:`11.6`,fontFamily:`monospace`,fontSize:`7.5`,fontWeight:`bold`,fill:`currentColor`,children:`>_`})]})}function XY(e){e.effect(()=>YB(e),`dsh-remote-vs: preview host services`);let t=fe(de());e.effect(()=>{let n,r,i,a=0,s=!1,c=()=>{i!==void 0&&(clearInterval(i),i=void 0)},l=()=>{if(s)return!0;let r;try{r=e.get(`betterSidebar`)??void 0}catch{return!1}if(r===void 0)return!1;try{let e=r;typeof e.fileIcon==`function`&&typeof e.folderIcon==`function`&&Ws(e)}catch{}try{n=r.registerTab({id:`remote-vs:explorer`,title:()=>t(`tab.remote`),description:()=>t(`tab.remoteDesc`),icon:e=>(0,o.jsx)(YY,{size:e}),order:30,single:!0,component:()=>(0,o.jsx)(Fq,{ctx:e})})}catch{return!1}return so(),s=!0,c(),!0},u=()=>{s||(s=!0,c(),r=zq(e,t)??void 0,r!==void 0&&so())};if(!l()){try{let t=e.get(`loader`);typeof t?.await==`function`&&t.await().then(()=>{l()||u()},()=>{})}catch{}i=setInterval(()=>{a+=1,!l()&&a>=60&&u()},500),i.unref?.()}return()=>{c();try{n?.()}catch{}try{r?.()}catch{}(n!==void 0||r!==void 0)&&co()}},`dsh-remote-vs: explorer surface (better tab preferred, native fallback)`),e.effect(()=>e.slots.inject(`conversation.hero.workspace.directoryFlow`,()=>e.slots.inject(`sidebar.workspaces.directoryFlow`,function*(){let t={listDirectory:(t,n)=>e.uiWorkspace.listDirectory(t,n),createDirectory:(t,n)=>e.uiWorkspace.createDirectory(t,n),pickDirectory:()=>e.uiWorkspace.pickDirectory()};yield e.slots.register({name:`conversation.hero.workspace.directoryFlow`,priority:-1,inject:()=>t},uJ),yield e.slots.register({name:`sidebar.workspaces.directoryFlow`,priority:-1,inject:()=>t},uJ)})),`dsh-remote-vs: directory flow`),e.effect(()=>{let t;try{let n=e.slots;t=n.inject(`conversation.input.dock`,()=>n.register({name:`conversation.input.dock`,id:`remote-changes`,order:30},oY))}catch(e){return console.warn(`[dsh-remote-vs] conversation.input.dock registration failed:`,e),()=>{}}return()=>{try{t?.()}catch{}}},`dsh-remote-vs: session changes dock`),e.effect(()=>DJ(e),`dsh-remote-vs: remote file click routing`);let n=fe(de());e.effect(()=>e.slots.inject(`settings.section`,()=>e.slots.register({name:`settings.section`,id:`remote-hosts`,order:20,label:()=>n(`settings.hosts`)},KY)),`dsh-remote-vs: settings hosts`),e.effect(()=>e.slots.inject(`settings.section`,()=>e.slots.register({name:`settings.section`,id:`remote-workspaces`,order:21,label:()=>n(`settings.workspaces`)},qY)),`dsh-remote-vs: settings workspaces`),e.effect(()=>Qq(e),`dsh-remote-vs: auto-open remote workspace`);let r=fe(de());e.effect(()=>{let t;try{let n=e.slots;t=n.inject(`conversation.view`,()=>n.register({name:`conversation.view`,id:`remote-editor`,order:30,label:()=>r(`view.editor`)},()=>(0,o.jsx)(OJ,{ctx:e}))),so()}catch(e){return console.warn(`[dsh-remote-vs] conversation.view registration failed:`,e),()=>{}}return()=>{co(),cd(`sidebar`);try{t?.()}catch{}}},`dsh-remote-vs: conversation view (editor + diff)`),e.effect(()=>bJ(r(`view.editor`),()=>{fd()}),`dsh-remote-vs: float on tab double-click`),e.effect(()=>{let t,n;try{let r=e.slots;t=r.inject(`shell.overlay`,()=>r.register({name:`shell.overlay`,id:`remote-vs:floating-editor`,order:40},()=>(0,o.jsx)(yJ,{ctx:e}))),n=r.inject(`shell.overlay`,()=>r.register({name:`shell.overlay`,id:`remote-vs:toast-host`,order:41},()=>(0,o.jsx)(vc,{})))}catch(e){return console.warn(`[dsh-remote-vs] shell.overlay registration failed (floating editor unavailable):`,e),()=>{}}return()=>{for(let e of[t,n])try{e?.()}catch{}}},`dsh-remote-vs: floating editor window`),e.effect(()=>(he(H),()=>he(void 0)),`dsh-remote-vs: host notice toasts`)}return n.apply=XY,n.inject=JY,t.exports}});
7929
7981
  //# sourceMappingURL=client.js.map