@hienlh/ppm 0.2.1 → 0.2.4
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.
- package/CHANGELOG.md +63 -0
- package/dist/web/assets/api-client-B_eCZViO.js +1 -0
- package/dist/web/assets/chat-tab-FOn2nq1x.js +6 -0
- package/dist/web/assets/{code-editor-BgiyQO-M.js → code-editor-R0uEZQ-h.js} +1 -1
- package/dist/web/assets/{diff-viewer-8_asmBRZ.js → diff-viewer-DDQ2Z0sz.js} +1 -1
- package/dist/web/assets/{git-graph-BiyTIbCz.js → git-graph-ugBsFNaz.js} +1 -1
- package/dist/web/assets/{git-status-panel-BifyO31N.js → git-status-panel-UMKtdAxp.js} +1 -1
- package/dist/web/assets/index-CGDMk8DE.css +2 -0
- package/dist/web/assets/index-Dmu22zQo.js +12 -0
- package/dist/web/assets/project-list-D38uQSpC.js +1 -0
- package/dist/web/assets/{settings-tab-Cn5Ja0_J.js → settings-tab-BpyCSbii.js} +1 -1
- package/dist/web/index.html +3 -3
- package/dist/web/sw.js +1 -1
- package/package.json +4 -4
- package/src/cli/commands/report.ts +1 -1
- package/src/cli/commands/status.ts +31 -22
- package/src/cli/commands/stop.ts +37 -29
- package/src/index.ts +2 -1
- package/src/server/index.ts +100 -66
- package/src/server/routes/chat.ts +13 -18
- package/src/server/routes/projects.ts +12 -0
- package/src/server/routes/static.ts +2 -2
- package/src/services/claude-usage.service.ts +93 -74
- package/src/services/project.service.ts +43 -0
- package/src/types/chat.ts +0 -2
- package/src/version.ts +7 -0
- package/src/web/components/chat/chat-tab.tsx +24 -7
- package/src/web/components/chat/usage-badge.tsx +23 -23
- package/src/web/components/layout/mobile-drawer.tsx +19 -1
- package/src/web/components/layout/sidebar.tsx +15 -4
- package/src/web/components/projects/project-list.tsx +153 -4
- package/src/web/hooks/use-chat.ts +30 -41
- package/src/web/hooks/use-usage.ts +65 -0
- package/src/web/lib/api-client.ts +9 -0
- package/src/web/lib/report-bug.ts +33 -0
- package/dist/web/assets/api-client-BgVufYKf.js +0 -1
- package/dist/web/assets/chat-tab-C4ovA2w4.js +0 -6
- package/dist/web/assets/index-DILaVO6p.css +0 -2
- package/dist/web/assets/index-DasstYgw.js +0 -11
- package/dist/web/assets/project-list-C7L3hZct.js +0 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.2.3] - 2026-03-16
|
|
4
|
+
|
|
5
|
+
### Changed
|
|
6
|
+
- Replace ccburn CLI with native OAuth API fetch for usage limits (700ms vs 3-5s)
|
|
7
|
+
- Health check uses WebSocket instead of HTTP polling (avoids browser 6-conn limit)
|
|
8
|
+
- Usage tracking separated into independent `useUsage` hook with auto-refresh
|
|
9
|
+
|
|
10
|
+
### Removed
|
|
11
|
+
- `ccburn` dependency (no longer needed)
|
|
12
|
+
|
|
13
|
+
## [0.2.2] - 2026-03-15
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
- Single source of truth for version (`src/version.ts` reads from `package.json`)
|
|
17
|
+
- Version shown in daemon start output
|
|
18
|
+
|
|
19
|
+
### Fixed
|
|
20
|
+
- Version no longer hardcoded in multiple files
|
|
21
|
+
|
|
22
|
+
## [0.2.1] - 2026-03-15
|
|
23
|
+
|
|
24
|
+
### Added
|
|
25
|
+
- `ppm logs` command — view daemon logs (`-n`, `-f`, `--clear`)
|
|
26
|
+
- `ppm report` command — open GitHub issue pre-filled with env info + logs
|
|
27
|
+
- Daemon stdout/stderr written to `~/.ppm/ppm.log`
|
|
28
|
+
- Frontend health check — detects server crash, prompts bug report
|
|
29
|
+
- Sensitive data (tokens, passwords, API keys) auto-redacted from logs
|
|
30
|
+
- `/api/logs/recent` public endpoint for bug reports
|
|
31
|
+
|
|
32
|
+
## [0.2.0] - 2026-03-15
|
|
33
|
+
|
|
34
|
+
### Added
|
|
35
|
+
- `--share` / `-s` flag — public URL via Cloudflare Quick Tunnel
|
|
36
|
+
- Default daemon mode — `ppm start` runs in background
|
|
37
|
+
- `--foreground` / `-f` flag — opt-in foreground mode
|
|
38
|
+
- `ppm status` command with `--json` flag and QR code
|
|
39
|
+
- `ppm init` — interactive setup (port, auth, password, share, AI settings)
|
|
40
|
+
- Auto-init on first `ppm start`
|
|
41
|
+
- Non-interactive init via flags (`-y`, `--port`, `--auth`, `--password`)
|
|
42
|
+
- `device_name` config — shown in sidebar, login screen, page title
|
|
43
|
+
- `/api/info` public endpoint (version + device name)
|
|
44
|
+
- QR code for share URL in terminal
|
|
45
|
+
- Auth warning when sharing with auth disabled
|
|
46
|
+
- Cloudflared auto-download (macOS .tgz + Linux binary)
|
|
47
|
+
- Tunnel runs as independent process — survives server crash
|
|
48
|
+
- `ppm start --share` reuses existing tunnel if alive
|
|
49
|
+
|
|
50
|
+
### Changed
|
|
51
|
+
- `ppm start` defaults to daemon mode (was opt-in)
|
|
52
|
+
- Status file `~/.ppm/status.json` replaces `ppm.pid` (with fallback)
|
|
53
|
+
- `ppm stop` kills both server and tunnel, cleans up files
|
|
54
|
+
|
|
55
|
+
## [0.1.6] - 2026-03-15
|
|
56
|
+
|
|
57
|
+
### Added
|
|
58
|
+
- Configurable AI provider settings via `ppm.yaml`, API, and UI
|
|
59
|
+
- Chat tool UI improvements, diff viewer, git panels, editor enhancements
|
|
60
|
+
|
|
61
|
+
### Fixed
|
|
62
|
+
- Global focus-visible outline causing blue ring on all inputs
|
|
63
|
+
- Unified input styles across app
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=`ppm-auth-token`,t=new class{baseUrl;constructor(e=``){this.baseUrl=e}getToken(){return localStorage.getItem(e)}headers(){let e={"Content-Type":`application/json`},t=this.getToken();return t&&(e.Authorization=`Bearer ${t}`),e}async get(e){let t=await fetch(`${this.baseUrl}${e}`,{headers:this.headers()});return this.handleResponse(t)}async post(e,t){let n=await fetch(`${this.baseUrl}${e}`,{method:`POST`,headers:this.headers(),body:t==null?void 0:JSON.stringify(t)});return this.handleResponse(n)}async put(e,t){let n=await fetch(`${this.baseUrl}${e}`,{method:`PUT`,headers:this.headers(),body:t==null?void 0:JSON.stringify(t)});return this.handleResponse(n)}async patch(e,t){let n=await fetch(`${this.baseUrl}${e}`,{method:`PATCH`,headers:this.headers(),body:t==null?void 0:JSON.stringify(t)});return this.handleResponse(n)}async del(e,t){let n=await fetch(`${this.baseUrl}${e}`,{method:`DELETE`,headers:this.headers(),body:t==null?void 0:JSON.stringify(t)});await this.handleResponse(n)}async handleResponse(t){if(t.status===401)throw localStorage.removeItem(e),window.location.reload(),Error(`Unauthorized`);let n=await t.json();if(n.ok===!1)throw Error(n.error??`HTTP ${t.status}`);return n.data}};function n(e){return`/api/project/${encodeURIComponent(e)}`}function r(t){localStorage.setItem(e,t)}function i(){return localStorage.getItem(e)}export{r as i,i as n,n as r,t};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{a as e,n as t,r as n,t as r}from"./jsx-runtime-BFALxl05.js";import{n as i,t as a}from"./marked.esm-Cv8mjgnt.js";import{t as o}from"./external-link-Dim3NH6h.js";import{t as s}from"./refresh-cw-DJSjl6Ev.js";import{t as c}from"./trash-2-CjahwKg8.js";import{t as l}from"./x-BxhOxZ5p.js";import{n as u}from"./utils-61GRB9Cb.js";import{n as d,r as f,t as p}from"./api-client-B_eCZViO.js";import{D as m,E as h,S as g,T as _,_ as v,c as y,g as b,h as x,l as S,m as C,p as w,w as T,x as E,y as D}from"./index-Dmu22zQo.js";var O=t(`activity`,[[`path`,{d:`M22 12h-2.48a2 2 0 0 0-1.93 1.46l-2.35 8.36a.25.25 0 0 1-.48 0L9.24 2.18a.25.25 0 0 0-.48 0l-2.35 8.36A2 2 0 0 1 4.49 12H2`,key:`169zse`}]]),k=t(`bot`,[[`path`,{d:`M12 8V4H8`,key:`hb8ula`}],[`rect`,{width:`16`,height:`12`,x:`4`,y:`8`,rx:`2`,key:`enze0r`}],[`path`,{d:`M2 14h2`,key:`vft8re`}],[`path`,{d:`M20 14h2`,key:`4cs60a`}],[`path`,{d:`M15 13v2`,key:`1xurst`}],[`path`,{d:`M9 13v2`,key:`rq6x2g`}]]),A=t(`circle-x`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m15 9-6 6`,key:`1uzhvr`}],[`path`,{d:`m9 9 6 6`,key:`z0biqf`}]]),j=t(`globe`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20`,key:`13o1zl`}],[`path`,{d:`M2 12h20`,key:`9i4pu4`}]]),M=t(`image`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,ry:`2`,key:`1m3agn`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}],[`path`,{d:`m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21`,key:`1xmnt7`}]]),N=t(`list-todo`,[[`path`,{d:`M13 5h8`,key:`a7qcls`}],[`path`,{d:`M13 12h8`,key:`h98zly`}],[`path`,{d:`M13 19h8`,key:`c3s6r1`}],[`path`,{d:`m3 17 2 2 4-4`,key:`1jhpwq`}],[`rect`,{x:`3`,y:`4`,width:`6`,height:`6`,rx:`1`,key:`cif1o7`}]]),P=t(`paperclip`,[[`path`,{d:`m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551`,key:`1miecu`}]]),F=t(`send`,[[`path`,{d:`M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z`,key:`1ffxy3`}],[`path`,{d:`m21.854 2.147-10.94 10.939`,key:`12cjpa`}]]),I=t(`shield-alert`,[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`M12 8v4`,key:`1got3b`}],[`path`,{d:`M12 16h.01`,key:`1drbdi`}]]),L=t(`sparkles`,[[`path`,{d:`M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594z`,key:`1s2grr`}],[`path`,{d:`M20 2v4`,key:`1rf3ol`}],[`path`,{d:`M22 4h-4`,key:`gwowj6`}],[`circle`,{cx:`4`,cy:`20`,r:`2`,key:`6kqj1y`}]]),ee=t(`square`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]),te=t(`upload`,[[`path`,{d:`M12 3v12`,key:`1x0j5s`}],[`path`,{d:`m17 8-5-5-5 5`,key:`7q97r8`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}]]),R=t(`wrench`,[[`path`,{d:`M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.106-3.105c.32-.322.863-.22.983.218a6 6 0 0 1-8.259 7.057l-7.91 7.91a1 1 0 0 1-2.999-3l7.91-7.91a6 6 0 0 1 7.057-8.259c.438.12.54.662.219.984z`,key:`1ngwbx`}]]),z=e(n(),1),B=3e4,V=1e3,H=class{ws=null;url;handlers=[];reconnectAttempts=0;reconnectTimer=null;intentionalClose=!1;constructor(e){this.url=e}connect(){this.intentionalClose=!1,this.cleanup();let e=window.location.protocol===`https:`?`wss:`:`ws:`,t=this.url.startsWith(`ws`)?this.url:`${e}//${window.location.host}${this.url}`;this.ws=new WebSocket(t),this.ws.onopen=()=>{this.reconnectAttempts=0},this.ws.onmessage=e=>{for(let t of this.handlers)t(e)},this.ws.onclose=()=>{this.intentionalClose||this.scheduleReconnect()},this.ws.onerror=()=>{this.ws?.close()}}disconnect(){this.intentionalClose=!0,this.cleanup(),this.reconnectTimer&&=(clearTimeout(this.reconnectTimer),null)}send(e){this.ws?.readyState===WebSocket.OPEN&&this.ws.send(e)}onMessage(e){return this.handlers.push(e),()=>{this.handlers=this.handlers.filter(t=>t!==e)}}get isConnected(){return this.ws?.readyState===WebSocket.OPEN}cleanup(){this.ws&&=(this.ws.onopen=null,this.ws.onclose=null,this.ws.onmessage=null,this.ws.onerror=null,(this.ws.readyState===WebSocket.OPEN||this.ws.readyState===WebSocket.CONNECTING)&&this.ws.close(),null)}scheduleReconnect(){let e=Math.min(V*2**this.reconnectAttempts,B);this.reconnectAttempts++,this.reconnectTimer=setTimeout(()=>this.connect(),e)}};function ne({url:e,onMessage:t,autoConnect:n=!0}){let r=(0,z.useRef)(null);return(0,z.useEffect)(()=>{let i=new H(e);return r.current=i,t&&i.onMessage(t),n&&i.connect(),()=>{i.disconnect(),r.current=null}},[e,n]),{send:(0,z.useCallback)(e=>{r.current?.send(e)},[]),connect:(0,z.useCallback)(()=>{r.current?.connect()},[]),disconnect:(0,z.useCallback)(()=>{r.current?.disconnect()},[])}}function re(e,t=`claude-sdk`,n=``,r){let[i,a]=(0,z.useState)([]),[o,s]=(0,z.useState)(!1),[c,l]=(0,z.useState)(!1),[u,p]=(0,z.useState)(null),[m,h]=(0,z.useState)(!1),g=(0,z.useRef)(r?.onUsageEvent);g.current=r?.onUsageEvent;let _=(0,z.useRef)(``),v=(0,z.useRef)([]),y=(0,z.useRef)(!1),b=(0,z.useRef)(null),x=(0,z.useRef)(()=>{}),S=(0,z.useCallback)(e=>{let t;try{t=JSON.parse(e.data)}catch{return}if(t.type!==`ping`){if(t.type===`connected`){h(!0);return}switch(t.type){case`text`:{_.current+=t.content,v.current.push(t);let e=_.current,n=[...v.current];a(t=>{let r=t[t.length-1];return r?.role===`assistant`&&!r.id.startsWith(`final-`)?[...t.slice(0,-1),{...r,content:e,events:n}]:[...t,{id:`streaming-${Date.now()}`,role:`assistant`,content:e,events:n,timestamp:new Date().toISOString()}]});break}case`tool_use`:{v.current.push(t);let e=_.current,n=[...v.current];a(t=>{let r=t[t.length-1];return r?.role===`assistant`?[...t.slice(0,-1),{...r,events:n}]:[...t,{id:`streaming-${Date.now()}`,role:`assistant`,content:e,events:n,timestamp:new Date().toISOString()}]});break}case`tool_result`:{v.current.push(t);let e=[...v.current];a(t=>{let n=t[t.length-1];return n?.role===`assistant`?[...t.slice(0,-1),{...n,events:e}]:t});break}case`approval_request`:v.current.push(t),p({requestId:t.requestId,tool:t.tool,input:t.input});break;case`usage`:g.current?.(t.usage);break;case`error`:{v.current.push(t);let e=[...v.current];a(n=>{let r=n[n.length-1];return r?.role===`assistant`?[...n.slice(0,-1),{...r,events:e}]:[...n,{id:`error-${Date.now()}`,role:`system`,content:t.message,events:[t],timestamp:new Date().toISOString()}]}),y.current=!1,l(!1);break}case`done`:{let e=_.current,t=[...v.current];a(n=>{let r=n[n.length-1];return r?.role===`assistant`?[...n.slice(0,-1),{...r,id:`final-${Date.now()}`,content:e||r.content,events:t.length>0?t:r.events}]:n}),_.current=``,v.current=[];let n=b.current;n?(b.current=null,a(e=>[...e,{id:`user-${Date.now()}`,role:`user`,content:n,timestamp:new Date().toISOString()}]),_.current=``,v.current=[],y.current=!0,l(!0),x.current(JSON.stringify({type:`message`,content:n}))):(y.current=!1,l(!1));break}}}},[]),{send:C,connect:w}=ne({url:e&&n?`/ws/project/${encodeURIComponent(n)}/chat/${e}`:``,onMessage:S,autoConnect:!!e&&!!n});return x.current=C,(0,z.useEffect)(()=>{let r=!1;return l(!1),p(null),_.current=``,v.current=[],h(!1),e&&n?(s(!0),fetch(`${f(n)}/chat/sessions/${e}/messages?providerId=${t}`,{headers:{Authorization:`Bearer ${d()}`}}).then(e=>e.json()).then(e=>{r||y.current||(e.ok&&Array.isArray(e.data)&&e.data.length>0?a(e.data):a([]))}).catch(()=>{!r&&!y.current&&a([])}).finally(()=>{r||s(!1)})):a([]),()=>{r=!0}},[e,t,n]),{messages:i,messagesLoading:o,isStreaming:c,pendingApproval:u,sendMessage:(0,z.useCallback)(e=>{if(e.trim()){if(c){b.current=e;return}a(t=>[...t,{id:`user-${Date.now()}`,role:`user`,content:e,timestamp:new Date().toISOString()}]),_.current=``,v.current=[],y.current=!0,l(!0),C(JSON.stringify({type:`message`,content:e}))}},[C,c]),respondToApproval:(0,z.useCallback)((e,t,n)=>{if(C(JSON.stringify({type:`approval_response`,requestId:e,approved:t,data:n})),t&&n){let t=v.current.find(t=>t.type===`approval_request`&&t.requestId===e&&t.tool===`AskUserQuestion`);if(t){let e=t.input;e&&typeof e==`object`&&(e.answers=n)}a(e=>[...e])}p(null)},[C]),cancelStreaming:(0,z.useCallback)(()=>{if(!y.current)return;C(JSON.stringify({type:`cancel`}));let e=_.current,t=[...v.current];a(n=>{let r=n[n.length-1];return r?.role===`assistant`?[...n.slice(0,-1),{...r,id:`final-${Date.now()}`,content:e||r.content,events:t.length>0?t:r.events}]:n}),_.current=``,v.current=[],b.current=null,y.current=!1,l(!1),p(null)},[C]),reconnect:(0,z.useCallback)(()=>{h(!1),w()},[w]),refetchMessages:(0,z.useCallback)(()=>{!e||!n||y.current||(s(!0),fetch(`${f(n)}/chat/sessions/${e}/messages?providerId=${t}`,{headers:{Authorization:`Bearer ${d()}`}}).then(e=>e.json()).then(e=>{e.ok&&Array.isArray(e.data)&&e.data.length>0&&a(e.data)}).catch(()=>{}).finally(()=>s(!1)))},[e,t,n]),isConnected:m}}var U=6e4;function ie(e,t=`claude-sdk`){let[n,r]=(0,z.useState)({}),[i,a]=(0,z.useState)(!1),[o,s]=(0,z.useState)(null),c=(0,z.useRef)(null),l=(0,z.useCallback)((n=!1)=>{if(!e)return;a(!0);let i=n?`&_t=${Date.now()}`:``;fetch(`${f(e)}/chat/usage?providerId=${t}${i}`,{headers:{Authorization:`Bearer ${d()}`}}).then(e=>e.json()).then(e=>{e.ok&&e.data&&(r(t=>({...t,...e.data})),s(Date.now()))}).catch(()=>{}).finally(()=>a(!1))},[e,t]);return(0,z.useEffect)(()=>(l(),c.current=setInterval(()=>l(!0),U),()=>{c.current&&clearInterval(c.current)}),[l]),{usageInfo:n,usageLoading:i,lastUpdatedAt:o,refreshUsage:(0,z.useCallback)(()=>{l(!0)},[l]),mergeUsage:(0,z.useCallback)(e=>{r(t=>{let n={...t,...e};return e.totalCostUsd!=null&&(n.queryCostUsd=e.totalCostUsd,n.totalCostUsd=(t.totalCostUsd??0)+e.totalCostUsd),n})},[])}}var W=r();function G(e){let t=e.type===`approval_request`;return{toolName:e.type===`tool_use`?e.tool:t?e.tool??`Tool`:`Tool`,input:e.type===`tool_use`?e.input:t?e.input??{}:{}}}function K({tool:e,result:t,completed:n,projectName:r}){let[i,a]=(0,z.useState)(!1);if(e.type===`error`)return(0,W.jsxs)(`div`,{className:`flex items-center gap-2 rounded bg-red-500/10 border border-red-500/20 px-2 py-1.5 text-xs text-red-400`,children:[(0,W.jsx)(_,{className:`size-3`}),(0,W.jsx)(`span`,{children:e.message})]});let{toolName:o,input:s}=G(e),c=t?.type===`tool_result`,l=c&&!!t.isError,u=o===`AskUserQuestion`&&!!s?.answers;return(0,W.jsxs)(`div`,{className:`rounded border border-border bg-background text-xs`,children:[(0,W.jsxs)(`button`,{onClick:()=>a(!i),className:`flex items-center gap-2 px-2 py-1.5 w-full text-left hover:bg-surface transition-colors min-w-0`,children:[i?(0,W.jsx)(m,{className:`size-3 shrink-0`}):(0,W.jsx)(h,{className:`size-3 shrink-0`}),l?(0,W.jsx)(A,{className:`size-3 text-red-400 shrink-0`}):c||u||n?(0,W.jsx)(T,{className:`size-3 text-green-400 shrink-0`}):(0,W.jsx)(R,{className:`size-3 text-yellow-400 shrink-0`}),(0,W.jsx)(`span`,{className:`truncate text-text-primary`,children:(0,W.jsx)(q,{name:o,input:s})})]}),i&&(0,W.jsxs)(`div`,{className:`px-2 pb-2 space-y-1.5`,children:[(e.type===`tool_use`||e.type===`approval_request`)&&(0,W.jsx)(J,{name:o,input:s,projectName:r}),c&&(0,W.jsx)(ae,{toolName:o,output:t.output})]})]})}function q({name:e,input:t}){let n=e=>String(e??``);switch(e){case`Read`:case`Write`:case`Edit`:case`MultiEdit`:case`NotebookEdit`:return(0,W.jsxs)(W.Fragment,{children:[e,` `,(0,W.jsx)(`span`,{className:`text-text-subtle`,children:se(n(t.file_path))})]});case`Bash`:return(0,W.jsxs)(W.Fragment,{children:[e,` `,(0,W.jsx)(`span`,{className:`font-mono text-text-subtle`,children:Z(n(t.command),60)})]});case`Glob`:return(0,W.jsxs)(W.Fragment,{children:[e,` `,(0,W.jsx)(`span`,{className:`font-mono text-text-subtle`,children:n(t.pattern)})]});case`Grep`:return(0,W.jsxs)(W.Fragment,{children:[e,` `,(0,W.jsx)(`span`,{className:`font-mono text-text-subtle`,children:Z(n(t.pattern),40)})]});case`WebSearch`:return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(C,{className:`size-3 inline`}),` `,e,` `,(0,W.jsx)(`span`,{className:`text-text-subtle`,children:Z(n(t.query),50)})]});case`WebFetch`:return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(j,{className:`size-3 inline`}),` `,e,` `,(0,W.jsx)(`span`,{className:`text-text-subtle`,children:Z(n(t.url),50)})]});case`ToolSearch`:return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(C,{className:`size-3 inline`}),` `,e,` `,(0,W.jsx)(`span`,{className:`text-text-subtle`,children:Z(n(t.query),50)})]});case`Agent`:case`Task`:return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(k,{className:`size-3 inline`}),` `,e,` `,(0,W.jsx)(`span`,{className:`text-text-subtle`,children:Z(n(t.description||t.prompt),60)})]});case`TodoWrite`:{let n=t.todos??[],r=n.filter(e=>e.status===`completed`).length;return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(N,{className:`size-3 inline`}),` `,e,` `,(0,W.jsxs)(`span`,{className:`text-text-subtle`,children:[r,`/`,n.length,` done`]})]})}case`AskUserQuestion`:{let n=t.questions??[],r=!!t.answers;return(0,W.jsxs)(W.Fragment,{children:[e,` `,(0,W.jsxs)(`span`,{className:`text-text-subtle`,children:[n.length,` question`,n.length===1?``:`s`,r?` ✓`:``]})]})}default:return(0,W.jsx)(W.Fragment,{children:e})}}function J({name:e,input:t,projectName:n}){let r=e=>String(e??``),{openTab:i}=S(),a=e=>{n&&i({type:`editor`,title:e.split(`/`).pop()??e,metadata:{filePath:e,projectName:n},projectId:n,closable:!0})};switch(e){case`Bash`:return(0,W.jsxs)(`div`,{className:`space-y-1`,children:[!!t.description&&(0,W.jsx)(`p`,{className:`text-text-subtle italic`,children:r(t.description)}),(0,W.jsx)(`pre`,{className:`font-mono text-text-secondary overflow-x-auto whitespace-pre-wrap break-all`,children:r(t.command)})]});case`Read`:case`Write`:case`Edit`:case`MultiEdit`:case`NotebookEdit`:{let n=r(t.file_path);return(0,W.jsxs)(`div`,{className:`space-y-1`,children:[(0,W.jsxs)(`button`,{type:`button`,className:`font-mono text-text-secondary break-all hover:text-primary hover:underline text-left flex items-center gap-1`,onClick:()=>a(n),title:`Open file in editor`,children:[(0,W.jsx)(o,{className:`size-3 shrink-0`}),n]}),e===`Edit`&&!!t.old_string&&(0,W.jsx)(`div`,{className:`border-l-2 border-red-400/40 pl-2`,children:(0,W.jsx)(`pre`,{className:`font-mono text-red-400/70 overflow-x-auto whitespace-pre-wrap`,children:Z(r(t.old_string),200)})}),e===`Edit`&&!!t.new_string&&(0,W.jsx)(`div`,{className:`border-l-2 border-green-400/40 pl-2`,children:(0,W.jsx)(`pre`,{className:`font-mono text-green-400/70 overflow-x-auto whitespace-pre-wrap`,children:Z(r(t.new_string),200)})}),e===`Write`&&!!t.content&&(0,W.jsx)(`pre`,{className:`font-mono text-text-subtle overflow-x-auto max-h-32 whitespace-pre-wrap`,children:Z(r(t.content),300)})]})}case`Glob`:return(0,W.jsxs)(`p`,{className:`font-mono text-text-secondary`,children:[r(t.pattern),t.path?` in ${r(t.path)}`:``]});case`Grep`:return(0,W.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,W.jsxs)(`p`,{className:`font-mono text-text-secondary`,children:[`/`,r(t.pattern),`/`]}),!!t.path&&(0,W.jsxs)(`p`,{className:`text-text-subtle`,children:[`in `,r(t.path)]})]});case`TodoWrite`:return(0,W.jsx)(Y,{todos:t.todos??[]});case`Agent`:case`Task`:return(0,W.jsxs)(`div`,{className:`space-y-1`,children:[!!t.description&&(0,W.jsx)(`p`,{className:`text-text-secondary font-medium`,children:r(t.description)}),!!t.subagent_type&&(0,W.jsxs)(`p`,{className:`text-text-subtle`,children:[`Type: `,r(t.subagent_type)]}),!!t.prompt&&(0,W.jsx)(X,{content:r(t.prompt),maxHeight:`max-h-48`})]});case`ToolSearch`:return(0,W.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,W.jsx)(`p`,{className:`font-mono text-text-secondary`,children:r(t.query)}),!!t.max_results&&(0,W.jsxs)(`p`,{className:`text-text-subtle`,children:[`Max results: `,r(t.max_results)]})]});case`WebFetch`:return(0,W.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,W.jsxs)(`a`,{href:r(t.url),target:`_blank`,rel:`noopener noreferrer`,className:`font-mono text-primary hover:underline break-all flex items-center gap-1`,children:[(0,W.jsx)(j,{className:`size-3 shrink-0`}),r(t.url)]}),!!t.prompt&&(0,W.jsx)(`p`,{className:`text-text-subtle`,children:Z(r(t.prompt),100)})]});case`AskUserQuestion`:{let e=t.questions??[],n=t.answers??{};return(0,W.jsx)(`div`,{className:`space-y-2`,children:e.map((e,t)=>(0,W.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,W.jsxs)(`p`,{className:`text-text-primary font-medium`,children:[e.header?`${e.header}: `:``,e.question]}),(0,W.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:e.options.map((t,r)=>(0,W.jsx)(`span`,{className:`inline-block rounded px-1.5 py-0.5 text-xs border ${(n[e.question]??``).split(`, `).includes(t.label)?`border-accent bg-accent/20 text-text-primary`:`border-border text-text-subtle`}`,children:t.label},r))}),n[e.question]&&(0,W.jsxs)(`p`,{className:`text-accent text-xs`,children:[`Answer: `,n[e.question]]})]},t))})}default:return(0,W.jsx)(`pre`,{className:`overflow-x-auto text-text-secondary font-mono whitespace-pre-wrap break-all`,children:JSON.stringify(t,null,2)})}}function Y({todos:e}){return(0,W.jsx)(`div`,{className:`space-y-0.5`,children:e.map((e,t)=>(0,W.jsxs)(`div`,{className:`flex items-start gap-1.5`,children:[(0,W.jsx)(`span`,{className:`shrink-0 mt-0.5 ${e.status===`completed`?`text-green-400`:e.status===`in_progress`?`text-yellow-400`:`text-text-subtle`}`,children:e.status===`completed`?`✓`:e.status===`in_progress`?`▶`:`○`}),(0,W.jsx)(`span`,{className:e.status===`completed`?`line-through text-text-subtle`:`text-text-secondary`,children:e.content})]},t))})}function ae({toolName:e,output:t}){let[n,r]=(0,z.useState)(!1),a=(0,z.useMemo)(()=>{if(e!==`Agent`&&e!==`Task`)return null;try{let e=JSON.parse(t);if(Array.isArray(e)){let t=e.filter(e=>e.type===`text`&&e.text).map(e=>e.text).join(`
|
|
2
|
+
|
|
3
|
+
`);if(t)return t}if(typeof e==`string`)return e}catch{if(t&&!t.startsWith(`[{`))return t}return null},[e,t]);return a?(0,W.jsxs)(`div`,{className:`border-t border-border pt-1.5 space-y-1`,children:[(0,W.jsx)(X,{content:a,maxHeight:`max-h-60`}),(0,W.jsxs)(`button`,{type:`button`,onClick:()=>r(!n),className:`flex items-center gap-1 text-[10px] text-text-subtle hover:text-text-secondary transition-colors`,children:[(0,W.jsx)(i,{className:`size-3`}),n?`Hide`:`Show`,` raw`]}),n&&(0,W.jsx)(`pre`,{className:`overflow-x-auto text-text-subtle font-mono max-h-40 whitespace-pre-wrap break-all text-[10px]`,children:t})]}):(0,W.jsx)(oe,{output:t})}function oe({output:e}){let t=e.split(`
|
|
4
|
+
`).length,n=t>3||e.length>200,[r,i]=(0,z.useState)(n);return(0,W.jsxs)(`div`,{className:`border-t border-border pt-1.5`,children:[n&&(0,W.jsxs)(`button`,{type:`button`,onClick:()=>i(!r),className:`flex items-center gap-1 text-[10px] text-text-subtle hover:text-text-secondary transition-colors mb-1`,children:[r?(0,W.jsx)(h,{className:`size-3`}):(0,W.jsx)(m,{className:`size-3`}),`Output (`,t,` lines)`]}),(0,W.jsx)(`pre`,{className:`overflow-x-auto text-text-subtle font-mono whitespace-pre-wrap break-all ${r?`max-h-16 overflow-hidden`:`max-h-60`}`,children:e})]})}function X({content:e,maxHeight:t=`max-h-48`}){let n=(0,z.useMemo)(()=>{try{return a.parse(e,{gfm:!0,breaks:!0})}catch{return e}},[e]);return(0,W.jsx)(`div`,{className:`markdown-content prose-sm text-text-secondary overflow-auto ${t}`,dangerouslySetInnerHTML:{__html:n}})}function se(e){return e?e.split(`/`).pop()??e:``}function Z(e,t=50){return e?e.length>t?e.slice(0,t)+`…`:e:``}function ce({messages:e,messagesLoading:t,pendingApproval:n,onApprovalResponse:r,isStreaming:i,projectName:a}){let o=(0,z.useRef)(null),s=(0,z.useRef)(!0);return(0,z.useEffect)(()=>{let t=s.current?`instant`:`smooth`;o.current?.scrollIntoView({behavior:t}),s.current&&e.length>0&&(s.current=!1)},[e,n]),t?(0,W.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,W.jsx)(k,{className:`size-10 text-text-subtle animate-pulse`}),(0,W.jsx)(`p`,{className:`text-sm`,children:`Loading messages...`})]}):e.length===0&&!i?(0,W.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,W.jsx)(k,{className:`size-10 text-text-subtle`}),(0,W.jsx)(`p`,{className:`text-sm`,children:`Send a message to start the conversation`})]}):(0,W.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-4 space-y-4`,children:[e.filter(e=>{let t=e.content&&e.content.trim().length>0,n=e.events&&e.events.length>0;return t||n}).map(e=>(0,W.jsx)(le,{message:e,isStreaming:i&&e.id.startsWith(`streaming-`),projectName:a},e.id)),n&&(n.tool===`AskUserQuestion`?(0,W.jsx)(Se,{approval:n,onRespond:r}):(0,W.jsx)(xe,{approval:n,onRespond:r})),i&&(0,W.jsx)(ye,{lastMessage:e[e.length-1]}),(0,W.jsx)(`div`,{ref:o})]})}function le({message:e,isStreaming:t,projectName:n}){return e.role===`user`?(0,W.jsx)(me,{content:e.content,projectName:n}):e.role===`system`?(0,W.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg bg-red-500/10 border border-red-500/20 px-3 py-2 text-sm text-red-400`,children:[(0,W.jsx)(_,{className:`size-4 shrink-0`}),(0,W.jsx)(`p`,{children:e.content})]}):(0,W.jsx)(`div`,{className:`flex flex-col gap-2`,children:e.events&&e.events.length>0?(0,W.jsx)(_e,{events:e.events,isStreaming:t,projectName:n}):e.content&&(0,W.jsx)(`div`,{className:`text-sm text-text-primary`,children:(0,W.jsx)(be,{content:e.content,projectName:n})})})}var ue=new Set([`.png`,`.jpg`,`.jpeg`,`.gif`,`.webp`]);function de(e){let t=e.match(/^\[Attached file: (.+?)\]\n\n?/);if(t)return{files:[t[1]],text:e.slice(t[0].length)};let n=e.match(/^\[Attached files:\n([\s\S]+?)\]\n\n?/);return n?{files:n[1].split(`
|
|
5
|
+
`).map(e=>e.trim()).filter(Boolean),text:e.slice(n[0].length)}:{files:[],text:e}}function Q(e,t){let n=e.split(`/`).pop()??``;return`/api/project/${encodeURIComponent(t??`_`)}/chat/uploads/${encodeURIComponent(n)}`}function fe(e){let t=e.lastIndexOf(`.`);return t===-1?!1:ue.has(e.slice(t).toLowerCase())}function pe(e){return e.toLowerCase().endsWith(`.pdf`)}function me({content:e,projectName:t}){let{files:n,text:r}=(0,z.useMemo)(()=>de(e),[e]);return(0,W.jsx)(`div`,{className:`flex justify-end`,children:(0,W.jsxs)(`div`,{className:`rounded-lg bg-primary/10 px-3 py-2 text-sm text-text-primary max-w-[85%] space-y-2`,children:[n.length>0&&(0,W.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:n.map((e,n)=>fe(e)?(0,W.jsx)(he,{src:Q(e,t),alt:e.split(`/`).pop()??`image`},n):pe(e)?(0,W.jsx)(ge,{src:Q(e,t),filename:e.split(`/`).pop()??`document.pdf`,mimeType:`application/pdf`},n):(0,W.jsxs)(`div`,{className:`flex items-center gap-1.5 rounded-md border border-border bg-background/50 px-2 py-1 text-xs text-text-secondary`,children:[(0,W.jsx)(g,{className:`size-3.5 shrink-0`}),(0,W.jsx)(`span`,{className:`truncate max-w-40`,children:e.split(`/`).pop()})]},n))}),r&&(0,W.jsx)(`p`,{className:`whitespace-pre-wrap break-words`,children:r})]})})}function he({src:e,alt:t}){let[n,r]=(0,z.useState)(null),[i,a]=(0,z.useState)(!1);return(0,z.useEffect)(()=>{let t,n=d();return fetch(e,{headers:n?{Authorization:`Bearer ${n}`}:{}}).then(e=>{if(!e.ok)throw Error(`Failed to load`);return e.blob()}).then(e=>{let n=URL.createObjectURL(e);t=n,r(n)}).catch(()=>a(!0)),()=>{t&&URL.revokeObjectURL(t)}},[e]),i?(0,W.jsxs)(`div`,{className:`flex items-center gap-1.5 rounded-md border border-border bg-background/50 px-2 py-1 text-xs text-text-secondary`,children:[(0,W.jsx)(M,{className:`size-3.5 shrink-0`}),(0,W.jsx)(`span`,{className:`truncate max-w-40`,children:t})]}):n?(0,W.jsx)(`a`,{href:n,target:`_blank`,rel:`noopener noreferrer`,className:`block`,children:(0,W.jsx)(`img`,{src:n,alt:t,className:`rounded-md max-h-48 max-w-full object-contain border border-border`})}):(0,W.jsx)(`div`,{className:`rounded-md bg-surface border border-border h-24 w-32 animate-pulse`})}function ge({src:e,filename:t,mimeType:n}){let[r,i]=(0,z.useState)(!1);return(0,W.jsxs)(`button`,{type:`button`,onClick:(0,z.useCallback)(async()=>{i(!0);try{let t=d(),r=await fetch(e,{headers:t?{Authorization:`Bearer ${t}`}:{}});if(!r.ok)throw Error(`Failed to load`);let i=await r.blob(),a=URL.createObjectURL(new Blob([i],{type:n}));window.open(a,`_blank`),setTimeout(()=>URL.revokeObjectURL(a),6e4)}catch{window.open(e,`_blank`)}finally{i(!1)}},[e,n]),disabled:r,className:`flex items-center gap-1.5 rounded-md border border-border bg-background/50 px-2 py-1 text-xs text-text-secondary hover:bg-surface hover:text-text-primary transition-colors cursor-pointer disabled:opacity-50`,children:[(0,W.jsx)(g,{className:`size-3.5 shrink-0 text-red-400`}),(0,W.jsx)(`span`,{className:`truncate max-w-40`,children:t}),r&&(0,W.jsx)(`span`,{className:`animate-spin text-[10px]`,children:`...`})]})}function _e({events:e,isStreaming:t,projectName:n}){let r=[],i=``;for(let t=0;t<e.length;t++){let n=e[t];n.type===`text`?i+=n.content:n.type===`tool_use`?(i&&=(r.push({kind:`text`,content:i}),``),r.push({kind:`tool`,tool:n})):n.type===`tool_result`||(i&&=(r.push({kind:`text`,content:i}),``),r.push({kind:`tool`,tool:n}))}i&&r.push({kind:`text`,content:i});let a=e.filter(e=>e.type===`tool_result`);for(let e of a){let t=e.toolUseId;if(t){let n=r.find(e=>e.kind===`tool`&&e.tool.type===`tool_use`&&e.tool.toolUseId===t);if(n){n.result=e;continue}}let n=r.find(e=>e.kind===`tool`&&!e.result);n&&(n.result=e)}for(let e=0;e<r.length;e++){let n=r[e];n.kind===`tool`&&!n.result&&(n.completed=e<r.length-1||!t)}return(0,W.jsx)(W.Fragment,{children:r.map((e,i)=>{if(e.kind===`text`){let a=t&&i===r.length-1;return(0,W.jsx)(`div`,{className:`text-sm text-text-primary`,children:(0,W.jsx)(ve,{content:e.content,animate:a,projectName:n})},`text-${i}`)}return(0,W.jsx)(K,{tool:e.tool,result:e.result,completed:e.completed,projectName:n},`tool-${i}`)})})}function ve({content:e,animate:t,projectName:n}){return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(be,{content:e,projectName:n}),t&&(0,W.jsx)(`span`,{className:`text-text-subtle text-sm animate-pulse`,children:`Thinking...`})]})}function ye({lastMessage:e}){if(!e||e.role!==`assistant`)return(0,W.jsx)(`div`,{className:`flex items-center gap-2 text-text-subtle text-sm`,children:(0,W.jsx)(`span`,{className:`animate-pulse`,children:`Thinking...`})});let t=e.events;if(t&&t.length>0){let e=t[t.length-1];if(e?.type===`tool_use`||e?.type===`tool_result`)return(0,W.jsx)(`div`,{className:`flex items-center gap-2 text-text-subtle text-sm`,children:(0,W.jsx)(`span`,{className:`animate-pulse`,children:`Thinking...`})})}return null}a.setOptions({gfm:!0,breaks:!0});function be({content:e,projectName:t}){let n=(0,z.useMemo)(()=>{try{return a.parse(e)}catch{return e}},[e]),r=(0,z.useRef)(null),{openTab:i}=S();return(0,z.useEffect)(()=>{let e=r.current;if(!e)return;e.querySelectorAll(`pre`).forEach(e=>{if(e.querySelector(`.code-actions`))return;let n=e.querySelector(`code`),r=n?.textContent??e.textContent??``,a=n?.className??``,o=/language-(bash|sh|shell|zsh)/.test(a)||!a.includes(`language-`)&&r.startsWith(`$`);e.style.position=`relative`;let s=document.createElement(`div`);s.className=`code-actions absolute top-1 right-1 flex gap-1 opacity-0 group-hover:opacity-100 transition-opacity`,e.classList.add(`group`);let c=document.createElement(`button`);if(c.className=`flex items-center justify-center size-6 rounded bg-surface-elevated/80 hover:bg-surface-elevated text-text-secondary hover:text-text-primary transition-colors border border-border/50`,c.title=`Copy`,c.innerHTML=`<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="14" height="14" x="8" y="8" rx="2" ry="2"/><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"/></svg>`,c.addEventListener(`click`,()=>{navigator.clipboard.writeText(r),c.innerHTML=`<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg>`,setTimeout(()=>{c.innerHTML=`<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="14" height="14" x="8" y="8" rx="2" ry="2"/><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"/></svg>`},2e3)}),s.appendChild(c),o){let e=document.createElement(`button`);e.className=`flex items-center justify-center size-6 rounded bg-surface-elevated/80 hover:bg-surface-elevated text-text-secondary hover:text-text-primary transition-colors border border-border/50`,e.title=`Run in terminal`,e.innerHTML=`<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="4 17 10 11 4 5"/><line x1="12" y1="19" x2="20" y2="19"/></svg>`,e.addEventListener(`click`,()=>{navigator.clipboard.writeText(r.replace(/^\$\s*/gm,``)),t&&i({type:`terminal`,title:`Terminal`,metadata:{projectName:t},projectId:t,closable:!0})}),s.appendChild(e)}e.appendChild(s)});let n=n=>{let r=n.target.closest(`a`);if(!r||!e.contains(r))return;let a=r.getAttribute(`href`)??``;(/^(\/|\.\/|\.\.\/)/.test(a)||/\.(ts|tsx|js|jsx|py|json|md|yaml|yml|toml|css|html|sh|go|rs|sql)$/i.test(a))&&t&&(n.preventDefault(),i({type:`editor`,title:a.split(`/`).pop()??a,metadata:{filePath:a,projectName:t},projectId:t,closable:!0}))};return e.addEventListener(`click`,n),()=>e.removeEventListener(`click`,n)},[n,t,i]),(0,W.jsx)(`div`,{ref:r,className:`markdown-content prose-sm`,dangerouslySetInnerHTML:{__html:n}})}function xe({approval:e,onRespond:t}){return(0,W.jsxs)(`div`,{className:`rounded-lg border-2 border-yellow-500/40 bg-yellow-500/10 p-3 space-y-2`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2 text-yellow-400 text-sm font-medium`,children:[(0,W.jsx)(I,{className:`size-4`}),(0,W.jsx)(`span`,{children:`Tool Approval Required`})]}),(0,W.jsx)(`div`,{className:`text-xs text-text-primary`,children:(0,W.jsx)(`span`,{className:`font-medium`,children:e.tool})}),(0,W.jsx)(`pre`,{className:`text-xs font-mono text-text-secondary overflow-x-auto bg-background rounded p-2 border border-border`,children:JSON.stringify(e.input,null,2)}),(0,W.jsxs)(`div`,{className:`flex gap-2`,children:[(0,W.jsx)(`button`,{onClick:()=>t(e.requestId,!0),className:`px-4 py-1.5 rounded bg-green-600 text-white text-xs font-medium hover:bg-green-500 transition-colors`,children:`Allow`}),(0,W.jsx)(`button`,{onClick:()=>t(e.requestId,!1),className:`px-4 py-1.5 rounded bg-red-600 text-white text-xs font-medium hover:bg-red-500 transition-colors`,children:`Deny`})]})]})}function Se({approval:e,onRespond:t}){let n=e.input.questions??[],[r,i]=(0,z.useState)({}),[a,o]=(0,z.useState)({}),s=(e,t,n)=>{o(t=>({...t,[e]:!1})),i(r=>{if(!n)return{...r,[e]:t};let i=r[e]??``,a=i?i.split(`, `):[],o=a.indexOf(t);return o>=0?a.splice(o,1):a.push(t),{...r,[e]:a.join(`, `)}})},c=e=>{o(t=>({...t,[e]:!0})),i(t=>({...t,[e]:``}))},l=(e,t)=>{i(n=>({...n,[e]:t}))},u=n.every(e=>r[e.question]?.trim());return(0,W.jsxs)(`div`,{className:`rounded-lg border-2 border-accent/40 bg-accent/5 p-3 space-y-3`,children:[n.map((e,t)=>(0,W.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,W.jsxs)(`p`,{className:`text-sm text-text-primary font-medium`,children:[e.header?`${e.header}: `:``,e.question]}),e.multiSelect&&(0,W.jsx)(`p`,{className:`text-xs text-text-subtle`,children:`Select multiple`}),(0,W.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[e.options.map((t,n)=>(0,W.jsxs)(`button`,{onClick:()=>s(e.question,t.label,e.multiSelect),className:`text-left rounded px-2.5 py-1.5 text-xs border transition-colors ${!a[e.question]&&(r[e.question]??``).split(`, `).includes(t.label)?`border-accent bg-accent/20 text-text-primary`:`border-border bg-background text-text-secondary hover:bg-surface-elevated`}`,children:[(0,W.jsx)(`span`,{className:`font-medium`,children:t.label}),t.description&&(0,W.jsxs)(`span`,{className:`text-text-subtle ml-1.5`,children:[`— `,t.description]})]},n)),a[e.question]?(0,W.jsx)(`input`,{type:`text`,autoFocus:!0,placeholder:`Type your answer...`,value:r[e.question]??``,onChange:t=>l(e.question,t.target.value),className:`rounded px-2.5 py-1.5 text-xs border border-accent bg-accent/10 text-text-primary outline-none placeholder:text-text-subtle`}):(0,W.jsx)(`button`,{onClick:()=>c(e.question),className:`text-left rounded px-2.5 py-1.5 text-xs border border-dashed border-border text-text-subtle hover:bg-surface-elevated transition-colors`,children:`Other — type your own answer`})]})]},t)),(0,W.jsxs)(`div`,{className:`flex gap-2 pt-1`,children:[(0,W.jsx)(`button`,{onClick:()=>t(e.requestId,!0,r),disabled:!u,className:`px-4 py-1.5 rounded bg-accent text-white text-xs font-medium hover:bg-accent/80 transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,children:`Submit`}),(0,W.jsx)(`button`,{onClick:()=>t(e.requestId,!1),className:`px-4 py-1.5 rounded bg-surface-elevated text-text-secondary text-xs hover:bg-surface transition-colors`,children:`Skip`})]})]})}var Ce=new Set([`image/png`,`image/jpeg`,`image/gif`,`image/webp`]),we=new Set([`application/pdf`]),Te=[`text/`,`application/json`,`application/xml`,`application/javascript`,`application/typescript`,`application/x-yaml`,`application/toml`,`application/x-sh`],Ee=new Set(`.ts,.tsx,.js,.jsx,.mjs,.cjs,.py,.rb,.go,.rs,.java,.kt,.swift,.c,.cpp,.h,.hpp,.cs,.json,.yaml,.yml,.toml,.xml,.md,.mdx,.txt,.csv,.tsv,.html,.css,.scss,.less,.sass,.sh,.bash,.zsh,.fish,.sql,.graphql,.gql,.env,.ini,.cfg,.conf,.dockerfile,.makefile,.vue,.svelte,.astro,.ipynb`.split(`,`));function De(e){return Ce.has(e.type)}function Oe(e){if(Ce.has(e.type)||we.has(e.type)||Te.some(t=>e.type.startsWith(t)))return!0;let t=ke(e.name);return!!(t&&Ee.has(t))}function ke(e){let t=e.lastIndexOf(`.`);return t===-1?``:e.slice(t).toLowerCase()}function Ae({attachments:e,onRemove:t}){return e.length===0?null:(0,W.jsx)(`div`,{className:`flex flex-wrap gap-1.5 px-3 pt-2`,children:e.map(e=>(0,W.jsxs)(`div`,{className:`flex items-center gap-1.5 rounded-md border border-border bg-surface px-2 py-1 text-xs text-text-secondary max-w-48`,children:[e.previewUrl?(0,W.jsx)(`img`,{src:e.previewUrl,alt:e.name,className:`size-5 rounded object-cover shrink-0`}):e.isImage?(0,W.jsx)(M,{className:`size-3.5 shrink-0 text-text-subtle`}):(0,W.jsx)(g,{className:`size-3.5 shrink-0 text-text-subtle`}),(0,W.jsx)(`span`,{className:`truncate`,children:e.name}),e.status===`uploading`?(0,W.jsx)(v,{className:`size-3 shrink-0 animate-spin text-text-subtle`}):e.status===`error`?(0,W.jsx)(`span`,{className:`text-red-500 shrink-0`,title:`Upload failed`,children:`!`}):null,(0,W.jsx)(`button`,{type:`button`,onClick:()=>t(e.id),className:`shrink-0 rounded-sm p-0.5 hover:bg-border/50 transition-colors`,"aria-label":`Remove ${e.name}`,children:(0,W.jsx)(l,{className:`size-3`})})]},e.id))})}function je(e){let t=[];function n(e){for(let r of e)t.push(r),r.children&&n(r.children)}return n(e),t}function Me({items:e,filter:t,onSelect:n,onClose:r,visible:i}){let[a,o]=(0,z.useState)(0),s=(0,z.useRef)(null),c=(()=>{if(!t)return e.slice(0,50);let n=t.toLowerCase();return e.filter(e=>e.path.toLowerCase().includes(n)||e.name.toLowerCase().includes(n)).slice(0,50)})();(0,z.useEffect)(()=>{o(0)},[t]),(0,z.useEffect)(()=>{let e=s.current;e&&e.children[a]?.scrollIntoView({block:`nearest`})},[a]);let l=(0,z.useCallback)(e=>{if(!i||c.length===0)return!1;switch(e.key){case`ArrowUp`:return e.preventDefault(),o(e=>e>0?e-1:c.length-1),!0;case`ArrowDown`:return e.preventDefault(),o(e=>e<c.length-1?e+1:0),!0;case`Enter`:case`Tab`:return e.preventDefault(),c[a]&&n(c[a]),!0;case`Escape`:return e.preventDefault(),r(),!0}return!1},[i,c,a,n,r]);return(0,z.useEffect)(()=>{if(!i)return;let e=e=>{l(e)};return document.addEventListener(`keydown`,e,!0),()=>document.removeEventListener(`keydown`,e,!0)},[i,l]),!i||c.length===0?null:(0,W.jsx)(`div`,{className:`max-h-52 overflow-y-auto border-b border-border bg-surface`,children:(0,W.jsx)(`div`,{ref:s,className:`py-1`,children:c.map((e,t)=>(0,W.jsxs)(`button`,{className:`flex items-center gap-2 w-full px-3 py-1.5 text-left transition-colors ${t===a?`bg-primary/10 text-primary`:`hover:bg-surface-hover text-text-primary`}`,onMouseEnter:()=>o(t),onClick:()=>n(e),children:[(0,W.jsx)(`span`,{className:`shrink-0`,children:e.type===`directory`?(0,W.jsx)(D,{className:`size-4 text-amber-500`}):(0,W.jsx)(E,{className:`size-4 text-blue-400`})}),(0,W.jsx)(`span`,{className:`text-sm truncate`,children:e.path})]},e.path))})})}function Ne({onSend:e,isStreaming:t,onCancel:n,disabled:r,projectName:i,onSlashStateChange:a,onSlashItemsLoaded:o,slashSelected:s,onFileStateChange:c,onFileItemsLoaded:l,fileSelected:m,externalFiles:h}){let[g,_]=(0,z.useState)(``),[v,y]=(0,z.useState)([]),b=(0,z.useRef)(null),x=(0,z.useRef)(null),S=(0,z.useRef)([]),C=(0,z.useRef)([]);(0,z.useEffect)(()=>{if(!i){S.current=[],o?.([]);return}p.get(`${f(i)}/chat/slash-items`).then(e=>{S.current=e,o?.(e)}).catch(()=>{S.current=[],o?.([])})},[i]),(0,z.useEffect)(()=>{if(!i){C.current=[],l?.([]);return}p.get(`${f(i)}/files/tree?depth=5`).then(e=>{let t=je(e);C.current=t,l?.(t)}).catch(()=>{C.current=[],l?.([])})},[i]),(0,z.useEffect)(()=>{if(!s)return;let e=`/${s.name} `;_(e),a?.(!1,``),c?.(!1,``);let t=b.current;t&&(t.focus(),setTimeout(()=>{t.selectionStart=t.selectionEnd=e.length},0))},[s]),(0,z.useEffect)(()=>{if(!m)return;let e=b.current;if(!e)return;let t=e.selectionStart,n=g.slice(0,t),r=g.slice(t),i=n.match(/@(\S*)$/);if(i){let t=n.length-i[0].length;_(n.slice(0,t)+`@${m.path} `+r);let a=t+m.path.length+2;setTimeout(()=>{e.selectionStart=e.selectionEnd=a,e.focus()},0)}else{let t=g+`@${m.path} `;_(t),setTimeout(()=>{e.selectionStart=e.selectionEnd=t.length,e.focus()},0)}c?.(!1,``)},[m]),(0,z.useEffect)(()=>{!h||h.length===0||T(h)},[h]);let w=(0,z.useCallback)(async e=>{if(!i)return null;try{let t=new FormData;t.append(`files`,e);let n={},r=d();r&&(n.Authorization=`Bearer ${r}`);let a=await(await fetch(`${f(i)}/chat/upload`,{method:`POST`,headers:n,body:t})).json();return a.ok&&Array.isArray(a.data)&&a.data.length>0?a.data[0].path:null}catch{return null}},[i]),T=(0,z.useCallback)(e=>{for(let t of e){if(!Oe(t)){_(e=>e+(e.length>0&&!e.endsWith(` `)?` `:``)+t.name);continue}let e=u(),n=De(t),r=n?URL.createObjectURL(t):void 0,i={id:e,name:t.name,file:t,isImage:n,previewUrl:r,status:`uploading`};y(e=>[...e,i]),w(t).then(t=>{y(n=>n.map(n=>n.id===e?{...n,serverPath:t??void 0,status:t?`ready`:`error`}:n))})}b.current?.focus()},[w]),E=(0,z.useCallback)(e=>{y(t=>{let n=t.find(t=>t.id===e);return n?.previewUrl&&URL.revokeObjectURL(n.previewUrl),t.filter(t=>t.id!==e)})},[]),D=(0,z.useCallback)(()=>{let t=g.trim(),n=v.filter(e=>e.status===`ready`);if(!(!t&&n.length===0)&&!r){a?.(!1,``),c?.(!1,``),e(t,n),_(``);for(let e of v)e.previewUrl&&URL.revokeObjectURL(e.previewUrl);y([]),b.current&&(b.current.style.height=`auto`)}},[g,v,r,e,a,c]),O=(0,z.useCallback)(e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),D())},[D]),k=(0,z.useCallback)((e,t)=>{let n=e.match(/^\/(\S*)$/);if(n&&S.current.length>0){a?.(!0,n[1]??``),c?.(!1,``);return}let r=e.slice(0,t).match(/@(\S*)$/);if(r&&C.current.length>0){c?.(!0,r[1]??``),a?.(!1,``);return}a?.(!1,``),c?.(!1,``)},[a,c]),A=(0,z.useCallback)(e=>{_(e),setTimeout(()=>{k(e,b.current?.selectionStart??e.length)},0)},[k]),j=(0,z.useCallback)(()=>{let e=b.current;e&&(e.style.height=`auto`,e.style.height=Math.min(e.scrollHeight,160)+`px`)},[]),M=(0,z.useCallback)(e=>{let t=e.clipboardData?.items;if(!t)return;let n=[];for(let e of t)if(e.kind===`file`){let t=e.getAsFile();t&&n.push(t)}n.length>0&&(e.preventDefault(),T(n))},[T]),N=(0,z.useCallback)(e=>{e.preventDefault();let t=Array.from(e.dataTransfer.files);t.length>0&&T(t)},[T]),I=(0,z.useCallback)(e=>{e.preventDefault()},[]),L=(0,z.useCallback)(()=>{x.current?.click()},[]),te=(0,z.useCallback)(e=>{let t=Array.from(e.target.files??[]);t.length>0&&T(t),e.target.value=``},[T]),R=g.trim().length>0||v.some(e=>e.status===`ready`),B=t&&!R;return(0,W.jsxs)(`div`,{className:`border-t border-border bg-background`,children:[(0,W.jsx)(Ae,{attachments:v,onRemove:E}),(0,W.jsxs)(`div`,{className:`flex items-end gap-2 p-3`,children:[(0,W.jsx)(`button`,{type:`button`,onClick:L,disabled:r,className:`flex items-center justify-center rounded-lg p-2 text-text-subtle hover:text-text-primary hover:bg-surface transition-colors shrink-0 disabled:opacity-50`,"aria-label":`Attach file`,children:(0,W.jsx)(P,{className:`size-4`})}),(0,W.jsx)(`input`,{ref:x,type:`file`,multiple:!0,className:`hidden`,onChange:te}),(0,W.jsx)(`textarea`,{ref:b,value:g,onChange:e=>{A(e.target.value),j()},onKeyDown:O,onPaste:M,onDrop:N,onDragOver:I,placeholder:t?`Send follow-up or press Stop...`:`Type / for commands, @ for files, or drop files...`,disabled:r,rows:1,className:`flex-1 resize-none rounded-lg border border-border bg-surface px-3 py-2 text-base md:text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:border-ring disabled:opacity-50 max-h-40`}),B?(0,W.jsx)(`button`,{onClick:n,className:`flex items-center justify-center rounded-lg bg-red-600 p-2 text-white hover:bg-red-500 transition-colors shrink-0`,"aria-label":`Stop response`,children:(0,W.jsx)(ee,{className:`size-4`})}):(0,W.jsx)(`button`,{onClick:D,disabled:r||!R,className:`flex items-center justify-center rounded-lg bg-primary p-2 text-white hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors shrink-0`,"aria-label":`Send message`,children:(0,W.jsx)(F,{className:`size-4`})})]})]})}function Pe({currentSessionId:e,onSelectSession:t,onNewSession:n,projectName:r}){let[i,a]=(0,z.useState)([]),[o,s]=(0,z.useState)(!1),[l,u]=(0,z.useState)(!1),d=(0,z.useCallback)(async()=>{if(r){u(!0);try{a(await p.get(`${f(r)}/chat/sessions`))}catch{}finally{u(!1)}}},[r]);(0,z.useEffect)(()=>{d()},[d]),(0,z.useEffect)(()=>{o&&d()},[o,d]);let h=i.find(t=>t.id===e),g=async(e,t)=>{e.stopPropagation();try{if(!r)return;await p.del(`${f(r)}/chat/sessions/${t.id}?providerId=${t.providerId}`),a(e=>e.filter(e=>e.id!==t.id))}catch{}};return(0,W.jsxs)(`div`,{className:`relative`,children:[(0,W.jsxs)(`button`,{onClick:()=>s(!o),className:`flex items-center gap-1.5 text-sm text-text-secondary hover:text-text-primary transition-colors px-2 py-1 rounded hover:bg-surface-elevated`,children:[(0,W.jsx)(b,{className:`size-3.5`}),(0,W.jsx)(`span`,{className:`truncate max-w-[150px]`,children:h?.title??`Select chat`}),(0,W.jsx)(m,{className:`size-3`})]}),o&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>s(!1)}),(0,W.jsxs)(`div`,{className:`absolute bottom-full left-0 mb-1 z-50 w-64 rounded-lg border border-border bg-surface shadow-lg overflow-hidden`,children:[(0,W.jsxs)(`button`,{onClick:()=>{n(),s(!1)},className:`flex items-center gap-2 w-full px-3 py-2 text-sm text-primary hover:bg-surface-elevated transition-colors border-b border-border`,children:[(0,W.jsx)(x,{className:`size-4`}),(0,W.jsx)(`span`,{children:`New Chat`})]}),(0,W.jsxs)(`div`,{className:`max-h-60 overflow-y-auto`,children:[l&&(0,W.jsx)(`p`,{className:`px-3 py-2 text-xs text-text-subtle animate-pulse`,children:`Loading sessions...`}),!l&&i.length===0&&(0,W.jsx)(`p`,{className:`px-3 py-2 text-xs text-text-subtle`,children:`No sessions yet`}),i.map(n=>(0,W.jsxs)(`div`,{onClick:()=>{t(n),s(!1)},className:`flex items-center justify-between px-3 py-2 text-sm cursor-pointer hover:bg-surface-elevated transition-colors ${n.id===e?`bg-surface-elevated text-text-primary`:`text-text-secondary`}`,children:[(0,W.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1`,children:[(0,W.jsx)(`span`,{className:`truncate text-xs font-medium`,children:n.title}),(0,W.jsx)(`span`,{className:`text-xs text-text-subtle`,children:new Date(n.createdAt).toLocaleDateString()})]}),(0,W.jsx)(`button`,{onClick:e=>g(e,n),className:`p-1 rounded hover:bg-red-500/20 text-text-subtle hover:text-red-400 transition-colors shrink-0`,"aria-label":`Delete session`,children:(0,W.jsx)(c,{className:`size-3`})})]},n.id))]})]})]})]})}function Fe({items:e,filter:t,onSelect:n,onClose:r,visible:i}){let[a,o]=(0,z.useState)(0),s=(0,z.useRef)(null),c=e.filter(e=>{let n=t.toLowerCase();return e.name.toLowerCase().includes(n)||e.description.toLowerCase().includes(n)});(0,z.useEffect)(()=>{o(0)},[t]),(0,z.useEffect)(()=>{let e=s.current;e&&e.children[a]?.scrollIntoView({block:`nearest`})},[a]);let l=(0,z.useCallback)(e=>{if(!i||c.length===0)return!1;switch(e.key){case`ArrowUp`:return e.preventDefault(),o(e=>e>0?e-1:c.length-1),!0;case`ArrowDown`:return e.preventDefault(),o(e=>e<c.length-1?e+1:0),!0;case`Enter`:case`Tab`:return e.preventDefault(),c[a]&&n(c[a]),!0;case`Escape`:return e.preventDefault(),r(),!0}return!1},[i,c,a,n,r]);return(0,z.useEffect)(()=>{if(!i)return;let e=e=>{l(e)};return document.addEventListener(`keydown`,e,!0),()=>document.removeEventListener(`keydown`,e,!0)},[i,l]),!i||c.length===0?null:(0,W.jsx)(`div`,{className:`max-h-52 overflow-y-auto border-b border-border bg-surface`,children:(0,W.jsx)(`div`,{ref:s,className:`py-1`,children:c.map((e,t)=>(0,W.jsxs)(`button`,{className:`flex items-start gap-3 w-full px-3 py-2 text-left transition-colors ${t===a?`bg-primary/10 text-primary`:`hover:bg-surface-hover text-text-primary`}`,onMouseEnter:()=>o(t),onClick:()=>n(e),children:[(0,W.jsx)(`span`,{className:`shrink-0 mt-0.5`,children:e.type===`skill`?(0,W.jsx)(L,{className:`size-4 text-amber-500`}):(0,W.jsx)(w,{className:`size-4 text-blue-500`})}),(0,W.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,W.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,W.jsxs)(`span`,{className:`font-medium text-sm`,children:[`/`,e.name]}),e.argumentHint&&(0,W.jsx)(`span`,{className:`text-xs text-text-subtle`,children:e.argumentHint}),(0,W.jsx)(`span`,{className:`text-xs text-text-subtle capitalize ml-auto`,children:e.scope===`user`?`global`:e.type})]}),e.description&&(0,W.jsx)(`p`,{className:`text-xs text-text-subtle mt-0.5 line-clamp-2`,children:e.description})]})]},`${e.type}-${e.name}`))})})}function Ie(e){return e>=90?`text-red-500`:e>=70?`text-amber-500`:`text-green-500`}function Le(e){return e>=90?`bg-red-500`:e>=70?`bg-amber-500`:`bg-green-500`}function Re({usage:e,loading:t,onClick:n}){let r=e.fiveHour==null?null:Math.round(e.fiveHour*100),i=e.sevenDay==null?null:Math.round(e.sevenDay*100),a=r==null?`--%`:`${r}%`,o=i==null?`--%`:`${i}%`;return(0,W.jsxs)(`button`,{onClick:n,className:`flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] font-medium tabular-nums transition-colors hover:bg-surface-hover ${r!=null||i!=null?Ie(Math.max(r??0,i??0)):`text-text-subtle`}`,title:`Click for usage details`,children:[t?(0,W.jsx)(s,{className:`size-3 animate-spin`}):(0,W.jsx)(O,{className:`size-3`}),(0,W.jsxs)(`span`,{children:[`5h:`,a]}),(0,W.jsx)(`span`,{className:`text-text-subtle`,children:`·`}),(0,W.jsxs)(`span`,{children:[`Wk:`,o]})]})}function ze(e){if(!e)return null;let t=null;if(e.resetsInMinutes!=null)t=e.resetsInMinutes;else if(e.resetsInHours!=null)t=Math.round(e.resetsInHours*60);else if(e.resetsAt){let n=new Date(e.resetsAt).getTime()-Date.now();t=n>0?Math.ceil(n/6e4):0}if(t==null)return null;if(t<=0)return`now`;let n=Math.floor(t/1440),r=Math.floor(t%1440/60),i=t%60;return n>0?i>0?`${n}d ${r}h ${i}m`:r>0?`${n}d ${r}h`:`${n}d`:r>0?i>0?`${r}h ${i}m`:`${r}h`:`${i}m`}function $({label:e,bucket:t}){if(!t)return null;let n=Math.round(t.utilization*100),r=ze(t);return(0,W.jsxs)(`div`,{className:`space-y-1`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,W.jsx)(`span`,{className:`text-xs font-medium text-text-primary`,children:e}),r&&(0,W.jsxs)(`span`,{className:`text-[10px] text-text-subtle`,children:[`↻ `,r]})]}),(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(`div`,{className:`flex-1 h-2 rounded-full bg-border overflow-hidden`,children:(0,W.jsx)(`div`,{className:`h-full rounded-full transition-all ${Le(n)}`,style:{width:`${Math.min(n,100)}%`}})}),(0,W.jsxs)(`span`,{className:`text-xs font-medium tabular-nums w-10 text-right ${Ie(n)}`,children:[n,`%`]})]})]})}function Be(e){if(!e)return null;let t=Math.round((Date.now()-e)/1e3);return t<5?`just now`:t<60?`${t}s ago`:`${Math.floor(t/60)}m ago`}function Ve({usage:e,visible:t,onClose:n,onReload:r,loading:i,lastUpdatedAt:a}){if(!t)return null;let o=e.queryCostUsd!=null||e.totalCostUsd!=null,c=e.session||e.weekly||e.weeklyOpus||e.weeklySonnet;return(0,W.jsxs)(`div`,{className:`border-b border-border bg-surface px-3 py-2.5 space-y-2.5`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(`span`,{className:`text-xs font-semibold text-text-primary`,children:`Usage Limits`}),a&&(0,W.jsx)(`span`,{className:`text-[10px] text-text-subtle`,children:Be(a)})]}),(0,W.jsxs)(`div`,{className:`flex items-center gap-1`,children:[r&&(0,W.jsx)(`button`,{onClick:r,disabled:i,className:`text-xs text-text-subtle hover:text-text-primary px-1 disabled:opacity-50`,title:`Refresh usage data`,children:(0,W.jsx)(s,{className:`size-3 ${i?`animate-spin`:``}`})}),(0,W.jsx)(`button`,{onClick:n,className:`text-xs text-text-subtle hover:text-text-primary px-1`,children:`✕`})]})]}),c?(0,W.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,W.jsx)($,{label:`5-Hour Session`,bucket:e.session}),(0,W.jsx)($,{label:`Weekly`,bucket:e.weekly}),(0,W.jsx)($,{label:`Weekly (Opus)`,bucket:e.weeklyOpus}),(0,W.jsx)($,{label:`Weekly (Sonnet)`,bucket:e.weeklySonnet})]}):(0,W.jsxs)(`p`,{className:`text-xs text-text-subtle`,children:[`No data — run `,(0,W.jsx)(`code`,{className:`bg-surface-elevated px-1 rounded`,children:`bun install`})]}),o&&(0,W.jsxs)(`div`,{className:`border-t border-border pt-2 space-y-1`,children:[e.queryCostUsd!=null&&(0,W.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,W.jsx)(`span`,{className:`text-text-subtle`,children:`Last query`}),(0,W.jsxs)(`span`,{className:`text-text-primary font-medium tabular-nums`,children:[`$`,e.queryCostUsd.toFixed(4)]})]}),e.totalCostUsd!=null&&(0,W.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,W.jsx)(`span`,{className:`text-text-subtle`,children:`Session total`}),(0,W.jsxs)(`span`,{className:`text-text-primary font-medium tabular-nums`,children:[`$`,e.totalCostUsd.toFixed(4)]})]})]})]})}function He({metadata:e,tabId:t}){let[n,r]=(0,z.useState)(e?.sessionId??null),[i,a]=(0,z.useState)(e?.providerId??`claude-sdk`),[o,s]=(0,z.useState)([]),[c,l]=(0,z.useState)(!1),[u,d]=(0,z.useState)(``),[m,h]=(0,z.useState)(null),[g,_]=(0,z.useState)([]),[v,b]=(0,z.useState)(!1),[x,C]=(0,z.useState)(``),[w,T]=(0,z.useState)(null),[E,D]=(0,z.useState)(!1),[O,k]=(0,z.useState)(!1),[A,j]=(0,z.useState)(null),M=(0,z.useRef)(0),N=y(e=>e.activeProject),P=S(e=>e.updateTab),{usageInfo:F,usageLoading:I,lastUpdatedAt:L,refreshUsage:ee,mergeUsage:R}=ie(N?.name??``,i);(0,z.useEffect)(()=>{!t||!n||P(t,{metadata:{...e,sessionId:n,providerId:i}})},[n,i]);let{messages:B,messagesLoading:V,isStreaming:H,pendingApproval:ne,sendMessage:U,respondToApproval:G,cancelStreaming:K,reconnect:q,refetchMessages:J,isConnected:Y}=re(n,i,N?.name??``,{onUsageEvent:R}),ae=(0,z.useCallback)(()=>{let e=N?.name??null;S.getState().openTab({type:`chat`,title:`AI Chat`,metadata:{projectName:e},projectId:e,closable:!0})},[N?.name]),oe=(0,z.useCallback)(e=>{r(e.id),a(e.providerId)},[]),X=(0,z.useCallback)((e,t)=>{if(t.length===0)return e;let n=t.filter(e=>e.serverPath).map(e=>e.serverPath).join(`
|
|
6
|
+
`);return n?(t.length===1?`[Attached file: ${n}]\n\n`:`[Attached files:\n${n}\n]\n\n`)+e:e},[]),se=(0,z.useCallback)(async(t,o=[])=>{let s=X(t,o);if(s.trim()){if(!n)try{let n=N?.name??e?.project??``,o=await p.post(`${f(n)}/chat/sessions`,{providerId:i,title:t.slice(0,50)});r(o.id),a(o.providerId),setTimeout(()=>{U(s)},500);return}catch(e){console.error(`Failed to create session:`,e);return}U(s)}},[n,i,e?.project,U,X,N?.name]),Z=(0,z.useCallback)((e,t)=>{l(e),d(t)},[]),le=(0,z.useCallback)(e=>{h(e),l(!1),d(``),setTimeout(()=>h(null),50)},[]),ue=(0,z.useCallback)(()=>{l(!1),d(``)},[]),de=(0,z.useCallback)((e,t)=>{b(e),C(t)},[]),Q=(0,z.useCallback)(e=>{T(e),b(!1),C(``),setTimeout(()=>T(null),50)},[]),fe=(0,z.useCallback)(()=>{b(!1),C(``)},[]);return(0,W.jsxs)(`div`,{className:`flex flex-col h-full relative`,onDragEnter:(0,z.useCallback)(e=>{e.preventDefault(),M.current++,e.dataTransfer.types.includes(`Files`)&&k(!0)},[]),onDragLeave:(0,z.useCallback)(e=>{e.preventDefault(),M.current--,M.current===0&&k(!1)},[]),onDragOver:(0,z.useCallback)(e=>{e.preventDefault()},[]),onDrop:(0,z.useCallback)(e=>{e.preventDefault(),M.current=0,k(!1);let t=Array.from(e.dataTransfer.files);t.length>0&&(j(t),setTimeout(()=>j(null),100))},[]),children:[O&&(0,W.jsx)(`div`,{className:`absolute inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm border-2 border-dashed border-primary rounded-lg pointer-events-none`,children:(0,W.jsxs)(`div`,{className:`flex flex-col items-center gap-2 text-primary`,children:[(0,W.jsx)(te,{className:`size-8`}),(0,W.jsx)(`span`,{className:`text-sm font-medium`,children:`Drop files to attach`})]})}),(0,W.jsx)(ce,{messages:B,messagesLoading:V,pendingApproval:ne,onApprovalResponse:G,isStreaming:H,projectName:N?.name}),(0,W.jsxs)(`div`,{className:`border-t border-border bg-background shrink-0`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-1.5 border-b border-border/50`,children:[(0,W.jsx)(Pe,{currentSessionId:n,onSelectSession:oe,onNewSession:ae,projectName:N?.name}),(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(Re,{usage:F,loading:I,onClick:()=>D(e=>!e)}),(0,W.jsx)(`button`,{onClick:()=>{Y||q(),J()},className:`group relative size-4 flex items-center justify-center rounded-full hover:bg-surface-hover transition-colors`,title:Y?`Connected — click to refetch messages`:`Disconnected — click to reconnect`,children:(0,W.jsx)(`span`,{className:`size-2 rounded-full transition-colors ${Y?`bg-green-500`:`bg-red-500 animate-pulse`}`})})]})]}),(0,W.jsx)(Ve,{usage:F,visible:E,onClose:()=>D(!1),onReload:ee,loading:I,lastUpdatedAt:L}),(0,W.jsx)(Fe,{items:o,filter:u,onSelect:le,onClose:ue,visible:c}),(0,W.jsx)(Me,{items:g,filter:x,onSelect:Q,onClose:fe,visible:v}),(0,W.jsx)(Ne,{onSend:se,isStreaming:H,onCancel:K,projectName:N?.name,onSlashStateChange:Z,onSlashItemsLoaded:s,slashSelected:m,onFileStateChange:de,onFileItemsLoaded:_,fileSelected:w,externalFiles:A})]})]})}export{He as ChatTab};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{a as e,n as t,r as n,t as r}from"./jsx-runtime-BFALxl05.js";import{n as i,t as a}from"./marked.esm-Cv8mjgnt.js";import{t as o}from"./external-link-Dim3NH6h.js";import{n as s,r as c,t as l}from"./api-client-BgVufYKf.js";import{_ as u,l as d}from"./index-DasstYgw.js";import{$ as f,A as p,B as m,C as h,D as g,E as _,F as v,G as y,H as b,J as x,K as S,L as C,M as w,N as T,O as E,P as D,Q as O,R as k,S as A,T as j,U as ee,V as M,W as te,X as ne,Z as re,_ as ie,a as ae,b as oe,c as se,ct as ce,d as le,dt as ue,f as de,ft as fe,g as pe,gt as me,h as he,ht as N,i as ge,it as _e,j as ve,l as ye,lt as be,m as xe,mt as Se,n as Ce,nt as we,o as Te,ot as Ee,p as De,pt as Oe,q as ke,r as Ae,rt as je,s as Me,st as P,t as Ne,tt as F,u as Pe,ut as Fe,v as Ie,w as Le,x as Re,y as ze,z as Be}from"./dist-CBiGQxfr.js";var Ve=t(`eye`,[[`path`,{d:`M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0`,key:`1nclc0`}],[`circle`,{cx:`12`,cy:`12`,r:`3`,key:`1v7zrd`}]]),He=t(`file-exclamation-point`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M12 9v4`,key:`juzpu7`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),I=e(n());function Ue(){return Ue=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},Ue.apply(null,arguments)}function We(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}var Ge=e=>{let{state:t}=e,n=t.doc.lineAt(t.selection.main.from),r=Xe(e.state,n.from);return r.line?qe(e):r.block?Ye(e):!1};function Ke(e,t){return({state:n,dispatch:r})=>{if(n.readOnly)return!1;let i=e(t,n);return i?(r(n.update(i)),!0):!1}}var qe=Ke(tt,0),Je=Ke(et,0),Ye=Ke((e,t)=>et(e,t,$e(t)),0);function Xe(e,t){let n=e.languageDataAt(`commentTokens`,t,1);return n.length?n[0]:{}}var Ze=50;function Qe(e,{open:t,close:n},r,i){let a=e.sliceDoc(r-Ze,r),o=e.sliceDoc(i,i+Ze),s=/\s*$/.exec(a)[0].length,c=/^\s*/.exec(o)[0].length,l=a.length-s;if(a.slice(l-t.length,l)==t&&o.slice(c,c+n.length)==n)return{open:{pos:r-s,margin:s&&1},close:{pos:i+c,margin:c&&1}};let u,d;i-r<=2*Ze?u=d=e.sliceDoc(r,i):(u=e.sliceDoc(r,r+Ze),d=e.sliceDoc(i-Ze,i));let f=/^\s*/.exec(u)[0].length,p=/\s*$/.exec(d)[0].length,m=d.length-p-n.length;return u.slice(f,f+t.length)==t&&d.slice(m,m+n.length)==n?{open:{pos:r+f+t.length,margin:/\s/.test(u.charAt(f+t.length))?1:0},close:{pos:i-p-n.length,margin:/\s/.test(d.charAt(m-1))?1:0}}:null}function $e(e){let t=[];for(let n of e.selection.ranges){let r=e.doc.lineAt(n.from),i=n.to<=r.to?r:e.doc.lineAt(n.to);i.from>r.from&&i.from==n.to&&(i=n.to==r.to+1?r:e.doc.lineAt(n.to-1));let a=t.length-1;a>=0&&t[a].to>r.from?t[a].to=i.to:t.push({from:r.from+/^\s*/.exec(r.text)[0].length,to:i.to})}return t}function et(e,t,n=t.selection.ranges){let r=n.map(e=>Xe(t,e.from).block);if(!r.every(e=>e))return null;let i=n.map((e,n)=>Qe(t,r[n],e.from,e.to));if(e!=2&&!i.every(e=>e))return{changes:t.changes(n.map((e,t)=>i[t]?[]:[{from:e.from,insert:r[t].open+` `},{from:e.to,insert:` `+r[t].close}]))};if(e!=1&&i.some(e=>e)){let e=[];for(let t=0,n;t<i.length;t++)if(n=i[t]){let i=r[t],{open:a,close:o}=n;e.push({from:a.pos-i.open.length,to:a.pos+a.margin},{from:o.pos-o.margin,to:o.pos+i.close.length})}return{changes:e}}return null}function tt(e,t,n=t.selection.ranges){let r=[],i=-1;ranges:for(let{from:e,to:a}of n){let n=r.length,o=1e9,s;for(let n=e;n<=a;){let c=t.doc.lineAt(n);if(s==null&&(s=Xe(t,c.from).line,!s))continue ranges;if(c.from>i&&(e==a||a>c.from)){i=c.from;let e=/^\s*/.exec(c.text)[0].length,t=e==c.length,n=c.text.slice(e,e+s.length)==s?e:-1;e<c.text.length&&e<o&&(o=e),r.push({line:c,comment:n,token:s,indent:e,empty:t,single:!1})}n=c.to+1}if(o<1e9)for(let e=n;e<r.length;e++)r[e].indent<r[e].line.text.length&&(r[e].indent=o);r.length==n+1&&(r[n].single=!0)}if(e!=2&&r.some(e=>e.comment<0&&(!e.empty||e.single))){let e=[];for(let{line:t,token:n,indent:i,empty:a,single:o}of r)(o||!a)&&e.push({from:t.from+i,insert:n+` `});let n=t.changes(e);return{changes:n,selection:t.selection.map(n,1)}}else if(e!=1&&r.some(e=>e.comment>=0)){let e=[];for(let{line:t,comment:n,token:i}of r)if(n>=0){let r=t.from+n,a=r+i.length;t.text[a-t.from]==` `&&a++,e.push({from:r,to:a})}return{changes:e}}return null}var nt=ne.define(),rt=ne.define(),it=je.define(),at=je.define({combine(e){return Oe(e,{minDepth:100,newGroupDelay:500,joinToEvent:(e,t)=>t},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(e,t)=>(n,r)=>e(n,r)||t(n,r)})}}),ot=ce.define({create(){return Ct.empty},update(e,t){let n=t.state.facet(at),r=t.annotation(nt);if(r){let i=L.fromTransaction(t,r.selection),a=r.side,o=a==0?e.undone:e.done;return o=i?pt(o,o.length,n.minDepth,i):vt(o,t.startState.selection),new Ct(a==0?r.rest:o,a==0?o:r.rest)}let i=t.annotation(rt);if((i==`full`||i==`before`)&&(e=e.isolate()),t.annotation(Fe.addToHistory)===!1)return t.changes.empty?e:e.addMapping(t.changes.desc);let a=L.fromTransaction(t),o=t.annotation(Fe.time),s=t.annotation(Fe.userEvent);return a?e=e.addChanges(a,o,s,n,t):t.selection&&(e=e.addSelection(t.startState.selection,o,s,n.newGroupDelay)),(i==`full`||i==`after`)&&(e=e.isolate()),e},toJSON(e){return{done:e.done.map(e=>e.toJSON()),undone:e.undone.map(e=>e.toJSON())}},fromJSON(e){return new Ct(e.done.map(L.fromJSON),e.undone.map(L.fromJSON))}});function st(e={}){return[ot,at.of(e),E.domEventHandlers({beforeinput(e,t){let n=e.inputType==`historyUndo`?lt:e.inputType==`historyRedo`?ut:null;return n?(e.preventDefault(),n(t)):!1}})]}function ct(e,t){return function({state:n,dispatch:r}){if(!t&&n.readOnly)return!1;let i=n.field(ot,!1);if(!i)return!1;let a=i.pop(e,n,t);return a?(r(a),!0):!1}}var lt=ct(0,!1),ut=ct(1,!1),dt=ct(0,!0),ft=ct(1,!0),L=class e{constructor(e,t,n,r,i){this.changes=e,this.effects=t,this.mapped=n,this.startSelection=r,this.selectionsAfter=i}setSelAfter(t){return new e(this.changes,this.effects,this.mapped,this.startSelection,t)}toJSON(){return{changes:this.changes?.toJSON(),mapped:this.mapped?.toJSON(),startSelection:this.startSelection?.toJSON(),selectionsAfter:this.selectionsAfter.map(e=>e.toJSON())}}static fromJSON(t){return new e(t.changes&&O.fromJSON(t.changes),[],t.mapped&&re.fromJSON(t.mapped),t.startSelection&&F.fromJSON(t.startSelection),t.selectionsAfter.map(F.fromJSON))}static fromTransaction(t,n){let r=R;for(let e of t.startState.facet(it)){let n=e(t);n.length&&(r=r.concat(n))}return!r.length&&t.changes.empty?null:new e(t.changes.invert(t.startState.doc),r,void 0,n||t.startState.selection,R)}static selection(t){return new e(void 0,R,void 0,void 0,t)}};function pt(e,t,n,r){let i=t+1>n+20?t-n-1:0,a=e.slice(i,t);return a.push(r),a}function mt(e,t){let n=[],r=!1;return e.iterChangedRanges((e,t)=>n.push(e,t)),t.iterChangedRanges((e,t,i,a)=>{for(let e=0;e<n.length;){let t=n[e++],o=n[e++];a>=t&&i<=o&&(r=!0)}}),r}function ht(e,t){return e.ranges.length==t.ranges.length&&e.ranges.filter((e,n)=>e.empty!=t.ranges[n].empty).length===0}function gt(e,t){return e.length?t.length?e.concat(t):e:t}var R=[],_t=200;function vt(e,t){if(e.length){let n=e[e.length-1],r=n.selectionsAfter.slice(Math.max(0,n.selectionsAfter.length-_t));return r.length&&r[r.length-1].eq(t)?e:(r.push(t),pt(e,e.length-1,1e9,n.setSelAfter(r)))}else return[L.selection([t])]}function yt(e){let t=e[e.length-1],n=e.slice();return n[e.length-1]=t.setSelAfter(t.selectionsAfter.slice(0,t.selectionsAfter.length-1)),n}function bt(e,t){if(!e.length)return e;let n=e.length,r=R;for(;n;){let i=xt(e[n-1],t,r);if(i.changes&&!i.changes.empty||i.effects.length){let t=e.slice(0,n);return t[n-1]=i,t}else t=i.mapped,n--,r=i.selectionsAfter}return r.length?[L.selection(r)]:R}function xt(e,t,n){let r=gt(e.selectionsAfter.length?e.selectionsAfter.map(e=>e.map(t)):R,n);if(!e.changes)return L.selection(r);let i=e.changes.map(t),a=t.mapDesc(e.changes,!0),o=e.mapped?e.mapped.composeDesc(a):a;return new L(i,P.mapEffects(e.effects,t),o,e.startSelection.map(a),r)}var St=/^(input\.type|delete)($|\.)/,Ct=class e{constructor(e,t,n=0,r=void 0){this.done=e,this.undone=t,this.prevTime=n,this.prevUserEvent=r}isolate(){return this.prevTime?new e(this.done,this.undone):this}addChanges(t,n,r,i,a){let o=this.done,s=o[o.length-1];return o=s&&s.changes&&!s.changes.empty&&t.changes&&(!r||St.test(r))&&(!s.selectionsAfter.length&&n-this.prevTime<i.newGroupDelay&&i.joinToEvent(a,mt(s.changes,t.changes))||r==`input.type.compose`)?pt(o,o.length-1,i.minDepth,new L(t.changes.compose(s.changes),gt(P.mapEffects(t.effects,s.changes),s.effects),s.mapped,s.startSelection,R)):pt(o,o.length,i.minDepth,t),new e(o,R,n,r)}addSelection(t,n,r,i){let a=this.done.length?this.done[this.done.length-1].selectionsAfter:R;return a.length>0&&n-this.prevTime<i&&r==this.prevUserEvent&&r&&/^select($|\.)/.test(r)&&ht(a[a.length-1],t)?this:new e(vt(this.done,t),this.undone,n,r)}addMapping(t){return new e(bt(this.done,t),bt(this.undone,t),this.prevTime,this.prevUserEvent)}pop(e,t,n){let r=e==0?this.done:this.undone;if(r.length==0)return null;let i=r[r.length-1],a=i.selectionsAfter[0]||(i.startSelection?i.startSelection.map(i.changes.invertedDesc,1):t.selection);if(n&&i.selectionsAfter.length)return t.update({selection:i.selectionsAfter[i.selectionsAfter.length-1],annotations:nt.of({side:e,rest:yt(r),selection:a}),userEvent:e==0?`select.undo`:`select.redo`,scrollIntoView:!0});if(i.changes){let n=r.length==1?R:r.slice(0,r.length-1);return i.mapped&&(n=bt(n,i.mapped)),t.update({changes:i.changes,selection:i.startSelection,effects:i.effects,annotations:nt.of({side:e,rest:n,selection:a}),filter:!1,userEvent:e==0?`undo`:`redo`,scrollIntoView:!0})}else return null}};Ct.empty=new Ct(R,R);var wt=[{key:`Mod-z`,run:lt,preventDefault:!0},{key:`Mod-y`,mac:`Mod-Shift-z`,run:ut,preventDefault:!0},{linux:`Ctrl-Shift-z`,run:ut,preventDefault:!0},{key:`Mod-u`,run:dt,preventDefault:!0},{key:`Alt-u`,mac:`Mod-Shift-u`,run:ft,preventDefault:!0}];function z(e,t){return F.create(e.ranges.map(t),e.mainIndex)}function B(e,t){return e.update({selection:t,scrollIntoView:!0,userEvent:`select`})}function V({state:e,dispatch:t},n){let r=z(e.selection,n);return r.eq(e.selection,!0)?!1:(t(B(e,r)),!0)}function Tt(e,t){return F.cursor(t?e.to:e.from)}function Et(e,t){return V(e,n=>n.empty?e.moveByChar(n,t):Tt(n,t))}function H(e){return e.textDirectionAt(e.state.selection.main.head)==g.LTR}var Dt=e=>Et(e,!H(e)),Ot=e=>Et(e,H(e));function kt(e,t){return V(e,n=>n.empty?e.moveByGroup(n,t):Tt(n,t))}var At=e=>kt(e,!H(e)),jt=e=>kt(e,H(e));typeof Intl<`u`&&Intl.Segmenter&&new Intl.Segmenter(void 0,{granularity:`word`});function Mt(e,t,n){if(t.type.prop(n))return!0;let r=t.to-t.from;return r&&(r>2||/[^\s,.;:]/.test(e.sliceDoc(t.from,t.to)))||t.firstChild}function Nt(e,t,n){let r=Le(e).resolveInner(t.head),i=n?j.closedBy:j.openedBy;for(let a=t.head;;){let t=n?r.childAfter(a):r.childBefore(a);if(!t)break;Mt(e,t,i)?r=t:a=n?t.to:t.from}let a=r.type.prop(i),o,s;return s=a&&(o=n?A(e,r.from,1):A(e,r.to,-1))&&o.matched?n?o.end.to:o.end.from:n?r.to:r.from,F.cursor(s,n?-1:1)}var Pt=e=>V(e,t=>Nt(e.state,t,!H(e))),Ft=e=>V(e,t=>Nt(e.state,t,H(e)));function It(e,t){return V(e,n=>{if(!n.empty)return Tt(n,t);let r=e.moveVertically(n,t);return r.head==n.head?e.moveToLineBoundary(n,t):r})}var Lt=e=>It(e,!1),Rt=e=>It(e,!0);function zt(e){let t=e.scrollDOM.clientHeight<e.scrollDOM.scrollHeight-2,n=0,r=0,i;if(t){for(let t of e.state.facet(E.scrollMargins)){let i=t(e);i?.top&&(n=Math.max(i?.top,n)),i?.bottom&&(r=Math.max(i?.bottom,r))}i=e.scrollDOM.clientHeight-n-r}else i=(e.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:n,marginBottom:r,selfScroll:t,height:Math.max(e.defaultLineHeight,i-5)}}function Bt(e,t){let n=zt(e),{state:r}=e,i=z(r.selection,r=>r.empty?e.moveVertically(r,t,n.height):Tt(r,t));if(i.eq(r.selection))return!1;let a;if(n.selfScroll){let t=e.coordsAtPos(r.selection.main.head),o=e.scrollDOM.getBoundingClientRect(),s=o.top+n.marginTop,c=o.bottom-n.marginBottom;t&&t.top>s&&t.bottom<c&&(a=E.scrollIntoView(i.main.head,{y:`start`,yMargin:t.top-s}))}return e.dispatch(B(r,i),{effects:a}),!0}var Vt=e=>Bt(e,!1),Ht=e=>Bt(e,!0);function U(e,t,n){let r=e.lineBlockAt(t.head),i=e.moveToLineBoundary(t,n);if(i.head==t.head&&i.head!=(n?r.to:r.from)&&(i=e.moveToLineBoundary(t,n,!1)),!n&&i.head==r.from&&r.length){let n=/^\s*/.exec(e.state.sliceDoc(r.from,Math.min(r.from+100,r.to)))[0].length;n&&t.head!=r.from+n&&(i=F.cursor(r.from+n))}return i}var Ut=e=>V(e,t=>U(e,t,!0)),Wt=e=>V(e,t=>U(e,t,!1)),Gt=e=>V(e,t=>U(e,t,!H(e))),Kt=e=>V(e,t=>U(e,t,H(e))),qt=e=>V(e,t=>F.cursor(e.lineBlockAt(t.head).from,1)),Jt=e=>V(e,t=>F.cursor(e.lineBlockAt(t.head).to,-1));function Yt(e,t,n){let r=!1,i=z(e.selection,t=>{let i=A(e,t.head,-1)||A(e,t.head,1)||t.head>0&&A(e,t.head-1,1)||t.head<e.doc.length&&A(e,t.head+1,-1);if(!i||!i.end)return t;r=!0;let a=i.start.from==t.head?i.end.to:i.end.from;return n?F.range(t.anchor,a):F.cursor(a)});return r?(t(B(e,i)),!0):!1}var Xt=({state:e,dispatch:t})=>Yt(e,t,!1);function W(e,t){let n=z(e.state.selection,e=>{let n=t(e);return F.range(e.anchor,n.head,n.goalColumn,n.bidiLevel||void 0,n.assoc)});return n.eq(e.state.selection)?!1:(e.dispatch(B(e.state,n)),!0)}function Zt(e,t){return W(e,n=>e.moveByChar(n,t))}var Qt=e=>Zt(e,!H(e)),$t=e=>Zt(e,H(e));function en(e,t){return W(e,n=>e.moveByGroup(n,t))}var tn=e=>en(e,!H(e)),nn=e=>en(e,H(e)),rn=e=>W(e,t=>Nt(e.state,t,!H(e))),an=e=>W(e,t=>Nt(e.state,t,H(e)));function on(e,t){return W(e,n=>e.moveVertically(n,t))}var sn=e=>on(e,!1),cn=e=>on(e,!0);function ln(e,t){return W(e,n=>e.moveVertically(n,t,zt(e).height))}var un=e=>ln(e,!1),dn=e=>ln(e,!0),fn=e=>W(e,t=>U(e,t,!0)),pn=e=>W(e,t=>U(e,t,!1)),mn=e=>W(e,t=>U(e,t,!H(e))),hn=e=>W(e,t=>U(e,t,H(e))),gn=e=>W(e,t=>F.cursor(e.lineBlockAt(t.head).from)),_n=e=>W(e,t=>F.cursor(e.lineBlockAt(t.head).to)),vn=({state:e,dispatch:t})=>(t(B(e,{anchor:0})),!0),yn=({state:e,dispatch:t})=>(t(B(e,{anchor:e.doc.length})),!0),bn=({state:e,dispatch:t})=>(t(B(e,{anchor:e.selection.main.anchor,head:0})),!0),xn=({state:e,dispatch:t})=>(t(B(e,{anchor:e.selection.main.anchor,head:e.doc.length})),!0),Sn=({state:e,dispatch:t})=>(t(e.update({selection:{anchor:0,head:e.doc.length},userEvent:`select`})),!0),Cn=({state:e,dispatch:t})=>{let n=Hn(e).map(({from:t,to:n})=>F.range(t,Math.min(n+1,e.doc.length)));return t(e.update({selection:F.create(n),userEvent:`select`})),!0},wn=({state:e,dispatch:t})=>{let n=z(e.selection,t=>{let n=Le(e),r=n.resolveStack(t.from,1);if(t.empty){let e=n.resolveStack(t.from,-1);e.node.from>=r.node.from&&e.node.to<=r.node.to&&(r=e)}for(let e=r;e;e=e.next){let{node:n}=e;if((n.from<t.from&&n.to>=t.to||n.to>t.to&&n.from<=t.from)&&e.next)return F.range(n.to,n.from)}return t});return n.eq(e.selection)?!1:(t(B(e,n)),!0)};function Tn(e,t){let{state:n}=e,r=n.selection,i=n.selection.ranges.slice();for(let r of n.selection.ranges){let a=n.doc.lineAt(r.head);if(t?a.to<e.state.doc.length:a.from>0)for(let n=r;;){let r=e.moveVertically(n,t);if(r.head<a.from||r.head>a.to){i.some(e=>e.head==r.head)||i.push(r);break}else if(r.head==n.head)break;else n=r}}return i.length==r.ranges.length?!1:(e.dispatch(B(n,F.create(i,i.length-1))),!0)}var En=e=>Tn(e,!1),Dn=e=>Tn(e,!0),On=({state:e,dispatch:t})=>{let n=e.selection,r=null;return n.ranges.length>1?r=F.create([n.main]):n.main.empty||(r=F.create([F.cursor(n.main.head)])),r?(t(B(e,r)),!0):!1};function kn(e,t){if(e.state.readOnly)return!1;let n=`delete.selection`,{state:r}=e,i=r.changeByRange(r=>{let{from:i,to:a}=r;if(i==a){let o=t(r);o<i?(n=`delete.backward`,o=An(e,o,!1)):o>i&&(n=`delete.forward`,o=An(e,o,!0)),i=Math.min(i,o),a=Math.max(a,o)}else i=An(e,i,!1),a=An(e,a,!0);return i==a?{range:r}:{changes:{from:i,to:a},range:F.cursor(i,i<r.head?-1:1)}});return i.changes.empty?!1:(e.dispatch(r.update(i,{scrollIntoView:!0,userEvent:n,effects:n==`delete.selection`?E.announce.of(r.phrase(`Selection deleted`)):void 0})),!0)}function An(e,t,n){if(e instanceof E)for(let r of e.state.facet(E.atomicRanges).map(t=>t(e)))r.between(t,t,(e,r)=>{e<t&&r>t&&(t=n?r:e)});return t}var jn=(e,t,n)=>kn(e,r=>{let i=r.from,{state:a}=e,o=a.doc.lineAt(i),s,c;if(n&&!t&&i>o.from&&i<o.from+200&&!/[^ \t]/.test(s=o.text.slice(0,i-o.from))){if(s[s.length-1]==` `)return i-1;let e=Se(s,a.tabSize)%ie(a)||ie(a);for(let t=0;t<e&&s[s.length-1-t]==` `;t++)i--;c=i}else c=N(o.text,i-o.from,t,t)+o.from,c==i&&o.number!=(t?a.doc.lines:1)?c+=t?1:-1:!t&&/[\ufe00-\ufe0f]/.test(o.text.slice(c-o.from,i-o.from))&&(c=N(o.text,c-o.from,!1,!1)+o.from);return c}),Mn=e=>jn(e,!1,!0),Nn=e=>jn(e,!0,!1),Pn=(e,t)=>kn(e,n=>{let r=n.head,{state:i}=e,a=i.doc.lineAt(r),o=i.charCategorizer(r);for(let e=null;;){if(r==(t?a.to:a.from)){r==n.head&&a.number!=(t?i.doc.lines:1)&&(r+=t?1:-1);break}let s=N(a.text,r-a.from,t)+a.from,c=a.text.slice(Math.min(r,s)-a.from,Math.max(r,s)-a.from),l=o(c);if(e!=null&&l!=e)break;(c!=` `||r!=n.head)&&(e=l),r=s}return r}),Fn=e=>Pn(e,!1),In=e=>Pn(e,!0),Ln=e=>kn(e,t=>{let n=e.lineBlockAt(t.head).to;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}),Rn=e=>kn(e,t=>{let n=e.moveToLineBoundary(t,!1).head;return t.head>n?n:Math.max(0,t.head-1)}),zn=e=>kn(e,t=>{let n=e.moveToLineBoundary(t,!0).head;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}),Bn=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(e=>({changes:{from:e.from,to:e.to,insert:be.of([``,``])},range:F.cursor(e.from)}));return t(e.update(n,{scrollIntoView:!0,userEvent:`input`})),!0},Vn=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(t=>{if(!t.empty||t.from==0||t.from==e.doc.length)return{range:t};let n=t.from,r=e.doc.lineAt(n),i=n==r.from?n-1:N(r.text,n-r.from,!1)+r.from,a=n==r.to?n+1:N(r.text,n-r.from,!0)+r.from;return{changes:{from:i,to:a,insert:e.doc.slice(n,a).append(e.doc.slice(i,n))},range:F.cursor(a)}});return n.changes.empty?!1:(t(e.update(n,{scrollIntoView:!0,userEvent:`move.character`})),!0)};function Hn(e){let t=[],n=-1;for(let r of e.selection.ranges){let i=e.doc.lineAt(r.from),a=e.doc.lineAt(r.to);if(!r.empty&&r.to==a.from&&(a=e.doc.lineAt(r.to-1)),n>=i.number){let e=t[t.length-1];e.to=a.to,e.ranges.push(r)}else t.push({from:i.from,to:a.to,ranges:[r]});n=a.number+1}return t}function Un(e,t,n){if(e.readOnly)return!1;let r=[],i=[];for(let t of Hn(e)){if(n?t.to==e.doc.length:t.from==0)continue;let a=e.doc.lineAt(n?t.to+1:t.from-1),o=a.length+1;if(n){r.push({from:t.to,to:a.to},{from:t.from,insert:a.text+e.lineBreak});for(let n of t.ranges)i.push(F.range(Math.min(e.doc.length,n.anchor+o),Math.min(e.doc.length,n.head+o)))}else{r.push({from:a.from,to:t.from},{from:t.to,insert:e.lineBreak+a.text});for(let e of t.ranges)i.push(F.range(e.anchor-o,e.head-o))}}return r.length?(t(e.update({changes:r,scrollIntoView:!0,selection:F.create(i,e.selection.mainIndex),userEvent:`move.line`})),!0):!1}var Wn=({state:e,dispatch:t})=>Un(e,t,!1),Gn=({state:e,dispatch:t})=>Un(e,t,!0);function Kn(e,t,n){if(e.readOnly)return!1;let r=[];for(let t of Hn(e))n?r.push({from:t.from,insert:e.doc.slice(t.from,t.to)+e.lineBreak}):r.push({from:t.to,insert:e.lineBreak+e.doc.slice(t.from,t.to)});let i=e.changes(r);return t(e.update({changes:i,selection:e.selection.map(i,n?1:-1),scrollIntoView:!0,userEvent:`input.copyline`})),!0}var qn=({state:e,dispatch:t})=>Kn(e,t,!1),Jn=({state:e,dispatch:t})=>Kn(e,t,!0),Yn=e=>{if(e.state.readOnly)return!1;let{state:t}=e,n=t.changes(Hn(t).map(({from:e,to:n})=>(e>0?e--:n<t.doc.length&&n++,{from:e,to:n}))),r=z(t.selection,t=>{let n;if(e.lineWrapping){let r=e.lineBlockAt(t.head),i=e.coordsAtPos(t.head,t.assoc||1);i&&(n=r.bottom+e.documentTop-i.bottom+e.defaultLineHeight/2)}return e.moveVertically(t,!0,n)}).map(n);return e.dispatch({changes:n,selection:r,scrollIntoView:!0,userEvent:`delete.line`}),!0};function Xn(e,t){if(/\(\)|\[\]|\{\}/.test(e.sliceDoc(t-1,t+1)))return{from:t,to:t};let n=Le(e).resolveInner(t),r=n.childBefore(t),i=n.childAfter(t),a;return r&&i&&r.to<=t&&i.from>=t&&(a=r.type.prop(j.closedBy))&&a.indexOf(i.name)>-1&&e.doc.lineAt(r.to).from==e.doc.lineAt(i.from).from&&!/\S/.test(e.sliceDoc(r.to,i.from))?{from:r.to,to:i.from}:null}var Zn=$n(!1),Qn=$n(!0);function $n(e){return({state:t,dispatch:n})=>{if(t.readOnly)return!1;let r=t.changeByRange(n=>{let{from:r,to:i}=n,a=t.doc.lineAt(r),o=!e&&r==i&&Xn(t,r);e&&(r=i=(i<=a.to?a:t.doc.lineAt(i)).to);let s=new de(t,{simulateBreak:r,simulateDoubleBreak:!!o}),c=Ie(s,r);for(c??=Se(/^\s*/.exec(t.doc.lineAt(r).text)[0],t.tabSize);i<a.to&&/\s/.test(a.text[i-a.from]);)i++;o?{from:r,to:i}=o:r>a.from&&r<a.from+100&&!/\S/.test(a.text.slice(0,r))&&(r=a.from);let l=[``,oe(t,c)];return o&&l.push(oe(t,s.lineIndent(a.from,-1))),{changes:{from:r,to:i,insert:be.of(l)},range:F.cursor(r+1+l[1].length)}});return n(t.update(r,{scrollIntoView:!0,userEvent:`input`})),!0}}function er(e,t){let n=-1;return e.changeByRange(r=>{let i=[];for(let a=r.from;a<=r.to;){let o=e.doc.lineAt(a);o.number>n&&(r.empty||r.to>o.from)&&(t(o,i,r),n=o.number),a=o.to+1}let a=e.changes(i);return{changes:i,range:F.range(a.mapPos(r.anchor,1),a.mapPos(r.head,1))}})}var tr=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=Object.create(null),r=new de(e,{overrideIndentation:e=>n[e]??-1}),i=er(e,(t,i,a)=>{let o=Ie(r,t.from);if(o==null)return;/\S/.test(t.text)||(o=0);let s=/^\s*/.exec(t.text)[0],c=oe(e,o);(s!=c||a.from<t.from+s.length)&&(n[t.from]=o,i.push({from:t.from,to:t.from+s.length,insert:c}))});return i.changes.empty||t(e.update(i,{userEvent:`indent`})),!0},nr=({state:e,dispatch:t})=>e.readOnly?!1:(t(e.update(er(e,(t,n)=>{n.push({from:t.from,insert:e.facet(Re)})}),{userEvent:`input.indent`})),!0),rr=({state:e,dispatch:t})=>e.readOnly?!1:(t(e.update(er(e,(t,n)=>{let r=/^\s*/.exec(t.text)[0];if(!r)return;let i=Se(r,e.tabSize),a=0,o=oe(e,Math.max(0,i-ie(e)));for(;a<r.length&&a<o.length&&r.charCodeAt(a)==o.charCodeAt(a);)a++;n.push({from:t.from+a,to:t.from+r.length,insert:o.slice(a)})}),{userEvent:`delete.dedent`})),!0),ir=e=>(e.setTabFocusMode(),!0),ar=[{key:`Ctrl-b`,run:Dt,shift:Qt,preventDefault:!0},{key:`Ctrl-f`,run:Ot,shift:$t},{key:`Ctrl-p`,run:Lt,shift:sn},{key:`Ctrl-n`,run:Rt,shift:cn},{key:`Ctrl-a`,run:qt,shift:gn},{key:`Ctrl-e`,run:Jt,shift:_n},{key:`Ctrl-d`,run:Nn},{key:`Ctrl-h`,run:Mn},{key:`Ctrl-k`,run:Ln},{key:`Ctrl-Alt-h`,run:Fn},{key:`Ctrl-o`,run:Bn},{key:`Ctrl-t`,run:Vn},{key:`Ctrl-v`,run:Ht}],or=[{key:`ArrowLeft`,run:Dt,shift:Qt,preventDefault:!0},{key:`Mod-ArrowLeft`,mac:`Alt-ArrowLeft`,run:At,shift:tn,preventDefault:!0},{mac:`Cmd-ArrowLeft`,run:Gt,shift:mn,preventDefault:!0},{key:`ArrowRight`,run:Ot,shift:$t,preventDefault:!0},{key:`Mod-ArrowRight`,mac:`Alt-ArrowRight`,run:jt,shift:nn,preventDefault:!0},{mac:`Cmd-ArrowRight`,run:Kt,shift:hn,preventDefault:!0},{key:`ArrowUp`,run:Lt,shift:sn,preventDefault:!0},{mac:`Cmd-ArrowUp`,run:vn,shift:bn},{mac:`Ctrl-ArrowUp`,run:Vt,shift:un},{key:`ArrowDown`,run:Rt,shift:cn,preventDefault:!0},{mac:`Cmd-ArrowDown`,run:yn,shift:xn},{mac:`Ctrl-ArrowDown`,run:Ht,shift:dn},{key:`PageUp`,run:Vt,shift:un},{key:`PageDown`,run:Ht,shift:dn},{key:`Home`,run:Wt,shift:pn,preventDefault:!0},{key:`Mod-Home`,run:vn,shift:bn},{key:`End`,run:Ut,shift:fn,preventDefault:!0},{key:`Mod-End`,run:yn,shift:xn},{key:`Enter`,run:Zn,shift:Zn},{key:`Mod-a`,run:Sn},{key:`Backspace`,run:Mn,shift:Mn,preventDefault:!0},{key:`Delete`,run:Nn,preventDefault:!0},{key:`Mod-Backspace`,mac:`Alt-Backspace`,run:Fn,preventDefault:!0},{key:`Mod-Delete`,mac:`Alt-Delete`,run:In,preventDefault:!0},{mac:`Mod-Backspace`,run:Rn,preventDefault:!0},{mac:`Mod-Delete`,run:zn,preventDefault:!0}].concat(ar.map(e=>({mac:e.key,run:e.run,shift:e.shift}))),sr=[{key:`Alt-ArrowLeft`,mac:`Ctrl-ArrowLeft`,run:Pt,shift:rn},{key:`Alt-ArrowRight`,mac:`Ctrl-ArrowRight`,run:Ft,shift:an},{key:`Alt-ArrowUp`,run:Wn},{key:`Shift-Alt-ArrowUp`,run:qn},{key:`Alt-ArrowDown`,run:Gn},{key:`Shift-Alt-ArrowDown`,run:Jn},{key:`Mod-Alt-ArrowUp`,run:En},{key:`Mod-Alt-ArrowDown`,run:Dn},{key:`Escape`,run:On},{key:`Mod-Enter`,run:Qn},{key:`Alt-l`,mac:`Ctrl-l`,run:Cn},{key:`Mod-i`,run:wn,preventDefault:!0},{key:`Mod-[`,run:rr},{key:`Mod-]`,run:nr},{key:`Mod-Alt-\\`,run:tr},{key:`Shift-Mod-k`,run:Yn},{key:`Shift-Mod-\\`,run:Xt},{key:`Mod-/`,run:Ge},{key:`Alt-A`,run:Je},{key:`Ctrl-m`,mac:`Shift-Alt-m`,run:ir}].concat(or),cr={key:`Tab`,run:nr,shift:rr},lr=typeof String.prototype.normalize==`function`?e=>e.normalize(`NFKD`):e=>e,G=class{constructor(e,t,n=0,r=e.length,i,a){this.test=a,this.value={from:0,to:0},this.done=!1,this.matches=[],this.buffer=``,this.bufferPos=0,this.iter=e.iterRange(n,r),this.bufferStart=n,this.normalize=i?e=>i(lr(e)):lr,this.query=this.normalize(t)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return ue(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let e=this.peek();if(e<0)return this.done=!0,this;let t=me(e),n=this.bufferStart+this.bufferPos;this.bufferPos+=fe(e);let r=this.normalize(t);if(r.length)for(let e=0,i=n;;e++){let a=r.charCodeAt(e),o=this.match(a,i,this.bufferPos+this.bufferStart);if(e==r.length-1){if(o)return this.value=o,this;break}i==n&&e<t.length&&t.charCodeAt(e)==a&&i++}}}match(e,t,n){let r=null;for(let t=0;t<this.matches.length;t+=2){let i=this.matches[t],a=!1;this.query.charCodeAt(i)==e&&(i==this.query.length-1?r={from:this.matches[t+1],to:n}:(this.matches[t]++,a=!0)),a||(this.matches.splice(t,2),t-=2)}return this.query.charCodeAt(0)==e&&(this.query.length==1?r={from:t,to:n}:this.matches.push(1,t)),r&&this.test&&!this.test(r.from,r.to,this.buffer,this.bufferStart)&&(r=null),r}};typeof Symbol<`u`&&(G.prototype[Symbol.iterator]=function(){return this});var ur={from:-1,to:-1,match:/.*/.exec(``)},dr=`gm`+(/x/.unicode==null?``:`u`),fr=class{constructor(e,t,n,r=0,i=e.length){if(this.text=e,this.to=i,this.curLine=``,this.done=!1,this.value=ur,/\\[sWDnr]|\n|\r|\[\^/.test(t))return new hr(e,t,n,r,i);this.re=new RegExp(t,dr+(n?.ignoreCase?`i`:``)),this.test=n?.test,this.iter=e.iter(),this.curLineStart=e.lineAt(r).from,this.matchPos=_r(e,r),this.getLine(this.curLineStart)}getLine(e){this.iter.next(e),this.iter.lineBreak?this.curLine=``:(this.curLine=this.iter.value,this.curLineStart+this.curLine.length>this.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart)),this.iter.next())}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1,this.curLineStart>this.to?this.curLine=``:this.getLine(0)}next(){for(let e=this.matchPos-this.curLineStart;;){this.re.lastIndex=e;let t=this.matchPos<=this.to&&this.re.exec(this.curLine);if(t){let n=this.curLineStart+t.index,r=n+t[0].length;if(this.matchPos=_r(this.text,r+(n==r?1:0)),n==this.curLineStart+this.curLine.length&&this.nextLine(),(n<r||n>this.value.to)&&(!this.test||this.test(n,r,t)))return this.value={from:n,to:r,match:t},this;e=this.matchPos-this.curLineStart}else if(this.curLineStart+this.curLine.length<this.to)this.nextLine(),e=0;else return this.done=!0,this}}},pr=new WeakMap,mr=class e{constructor(e,t){this.from=e,this.text=t}get to(){return this.from+this.text.length}static get(t,n,r){let i=pr.get(t);if(!i||i.from>=r||i.to<=n){let i=new e(n,t.sliceString(n,r));return pr.set(t,i),i}if(i.from==n&&i.to==r)return i;let{text:a,from:o}=i;return o>n&&(a=t.sliceString(n,o)+a,o=n),i.to<r&&(a+=t.sliceString(i.to,r)),pr.set(t,new e(o,a)),new e(n,a.slice(n-o,r-o))}},hr=class{constructor(e,t,n,r,i){this.text=e,this.to=i,this.done=!1,this.value=ur,this.matchPos=_r(e,r),this.re=new RegExp(t,dr+(n?.ignoreCase?`i`:``)),this.test=n?.test,this.flat=mr.get(e,r,this.chunkEnd(r+5e3))}chunkEnd(e){return e>=this.to?this.to:this.text.lineAt(e).to}next(){for(;;){let e=this.re.lastIndex=this.matchPos-this.flat.from,t=this.re.exec(this.flat.text);if(t&&!t[0]&&t.index==e&&(this.re.lastIndex=e+1,t=this.re.exec(this.flat.text)),t){let e=this.flat.from+t.index,n=e+t[0].length;if((this.flat.to>=this.to||t.index+t[0].length<=this.flat.text.length-10)&&(!this.test||this.test(e,n,t)))return this.value={from:e,to:n,match:t},this.matchPos=_r(this.text,n+(e==n?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=mr.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}};typeof Symbol<`u`&&(fr.prototype[Symbol.iterator]=hr.prototype[Symbol.iterator]=function(){return this});function gr(e){try{return new RegExp(e,dr),!0}catch{return!1}}function _r(e,t){if(t>=e.length)return t;let n=e.lineAt(t),r;for(;t<n.to&&(r=n.text.charCodeAt(t-n.from))>=56320&&r<57344;)t++;return t}var vr=e=>{let{state:t}=e,n=String(t.doc.lineAt(e.state.selection.main.head).number),{close:r,result:i}=S(e,{label:t.phrase(`Go to line`),input:{type:`text`,name:`line`,value:n},focus:!0,submitLabel:t.phrase(`go`)});return i.then(n=>{let i=n&&/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(n.elements.line.value);if(!i){e.dispatch({effects:r});return}let a=t.doc.lineAt(t.selection.main.head),[,o,s,c,l]=i,u=c?+c.slice(1):0,d=s?+s:a.number;if(s&&l){let e=d/100;o&&(e=e*(o==`-`?-1:1)+a.number/t.doc.lines),d=Math.round(t.doc.lines*e)}else s&&o&&(d=d*(o==`-`?-1:1)+a.number);let f=t.doc.line(Math.max(1,Math.min(t.doc.lines,d))),p=F.cursor(f.from+Math.max(0,Math.min(u,f.length)));e.dispatch({effects:[r,E.scrollIntoView(p.from,{y:`center`})],selection:p})}),!0},yr={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},br=je.define({combine(e){return Oe(e,yr,{highlightWordAroundCursor:(e,t)=>e||t,minSelectionLength:Math.min,maxMatches:Math.min})}});function xr(e){let t=[Dr,Er];return e&&t.push(br.of(e)),t}var Sr=_.mark({class:`cm-selectionMatch`}),Cr=_.mark({class:`cm-selectionMatch cm-selectionMatch-main`});function wr(e,t,n,r){return(n==0||e(t.sliceDoc(n-1,n))!=f.Word)&&(r==t.doc.length||e(t.sliceDoc(r,r+1))!=f.Word)}function Tr(e,t,n,r){return e(t.sliceDoc(n,n+1))==f.Word&&e(t.sliceDoc(r-1,r))==f.Word}var Er=p.fromClass(class{constructor(e){this.decorations=this.getDeco(e)}update(e){(e.selectionSet||e.docChanged||e.viewportChanged)&&(this.decorations=this.getDeco(e.view))}getDeco(e){let t=e.state.facet(br),{state:n}=e,r=n.selection;if(r.ranges.length>1)return _.none;let i=r.main,a,o=null;if(i.empty){if(!t.highlightWordAroundCursor)return _.none;let e=n.wordAt(i.head);if(!e)return _.none;o=n.charCategorizer(i.head),a=n.sliceDoc(e.from,e.to)}else{let e=i.to-i.from;if(e<t.minSelectionLength||e>200)return _.none;if(t.wholeWords){if(a=n.sliceDoc(i.from,i.to),o=n.charCategorizer(i.head),!(wr(o,n,i.from,i.to)&&Tr(o,n,i.from,i.to)))return _.none}else if(a=n.sliceDoc(i.from,i.to),!a)return _.none}let s=[];for(let r of e.visibleRanges){let e=new G(n.doc,a,r.from,r.to);for(;!e.next().done;){let{from:r,to:a}=e.value;if((!o||wr(o,n,r,a))&&(i.empty&&r<=i.from&&a>=i.to?s.push(Cr.range(r,a)):(r>=i.to||a<=i.from)&&s.push(Sr.range(r,a)),s.length>t.maxMatches))return _.none}}return _.set(s)}},{decorations:e=>e.decorations}),Dr=E.baseTheme({".cm-selectionMatch":{backgroundColor:`#99ff7780`},".cm-searchMatch .cm-selectionMatch":{backgroundColor:`transparent`}}),Or=({state:e,dispatch:t})=>{let{selection:n}=e,r=F.create(n.ranges.map(t=>e.wordAt(t.head)||F.cursor(t.head)),n.mainIndex);return r.eq(n)?!1:(t(e.update({selection:r})),!0)};function kr(e,t){let{main:n,ranges:r}=e.selection,i=e.wordAt(n.head),a=i&&i.from==n.from&&i.to==n.to;for(let n=!1,i=new G(e.doc,t,r[r.length-1].to);;)if(i.next(),i.done){if(n)return null;i=new G(e.doc,t,0,Math.max(0,r[r.length-1].from-1)),n=!0}else{if(n&&r.some(e=>e.from==i.value.from))continue;if(a){let t=e.wordAt(i.value.from);if(!t||t.from!=i.value.from||t.to!=i.value.to)continue}return i.value}}var Ar=({state:e,dispatch:t})=>{let{ranges:n}=e.selection;if(n.some(e=>e.from===e.to))return Or({state:e,dispatch:t});let r=e.sliceDoc(n[0].from,n[0].to);if(e.selection.ranges.some(t=>e.sliceDoc(t.from,t.to)!=r))return!1;let i=kr(e,r);return i?(t(e.update({selection:e.selection.addRange(F.range(i.from,i.to),!1),effects:E.scrollIntoView(i.to)})),!0):!1},K=je.define({combine(e){return Oe(e,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:e=>new si(e),scrollToMatch:e=>E.scrollIntoView(e)})}}),jr=class{constructor(e){this.search=e.search,this.caseSensitive=!!e.caseSensitive,this.literal=!!e.literal,this.regexp=!!e.regexp,this.replace=e.replace||``,this.valid=!!this.search&&(!this.regexp||gr(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!e.wholeWord,this.test=e.test}unquote(e){return this.literal?e:e.replace(/\\([nrt\\])/g,(e,t)=>t==`n`?`
|
|
1
|
+
import{a as e,n as t,r as n,t as r}from"./jsx-runtime-BFALxl05.js";import{n as i,t as a}from"./marked.esm-Cv8mjgnt.js";import{t as o}from"./external-link-Dim3NH6h.js";import{n as s,r as c,t as l}from"./api-client-B_eCZViO.js";import{_ as u,l as d}from"./index-Dmu22zQo.js";import{$ as f,A as p,B as m,C as h,D as g,E as _,F as v,G as y,H as b,J as x,K as S,L as C,M as w,N as T,O as E,P as D,Q as O,R as k,S as A,T as j,U as ee,V as M,W as te,X as ne,Z as re,_ as ie,a as ae,b as oe,c as se,ct as ce,d as le,dt as ue,f as de,ft as fe,g as pe,gt as me,h as he,ht as N,i as ge,it as _e,j as ve,l as ye,lt as be,m as xe,mt as Se,n as Ce,nt as we,o as Te,ot as Ee,p as De,pt as Oe,q as ke,r as Ae,rt as je,s as Me,st as P,t as Ne,tt as F,u as Pe,ut as Fe,v as Ie,w as Le,x as Re,y as ze,z as Be}from"./dist-CBiGQxfr.js";var Ve=t(`eye`,[[`path`,{d:`M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0`,key:`1nclc0`}],[`circle`,{cx:`12`,cy:`12`,r:`3`,key:`1v7zrd`}]]),He=t(`file-exclamation-point`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M12 9v4`,key:`juzpu7`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),I=e(n());function Ue(){return Ue=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},Ue.apply(null,arguments)}function We(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}var Ge=e=>{let{state:t}=e,n=t.doc.lineAt(t.selection.main.from),r=Xe(e.state,n.from);return r.line?qe(e):r.block?Ye(e):!1};function Ke(e,t){return({state:n,dispatch:r})=>{if(n.readOnly)return!1;let i=e(t,n);return i?(r(n.update(i)),!0):!1}}var qe=Ke(tt,0),Je=Ke(et,0),Ye=Ke((e,t)=>et(e,t,$e(t)),0);function Xe(e,t){let n=e.languageDataAt(`commentTokens`,t,1);return n.length?n[0]:{}}var Ze=50;function Qe(e,{open:t,close:n},r,i){let a=e.sliceDoc(r-Ze,r),o=e.sliceDoc(i,i+Ze),s=/\s*$/.exec(a)[0].length,c=/^\s*/.exec(o)[0].length,l=a.length-s;if(a.slice(l-t.length,l)==t&&o.slice(c,c+n.length)==n)return{open:{pos:r-s,margin:s&&1},close:{pos:i+c,margin:c&&1}};let u,d;i-r<=2*Ze?u=d=e.sliceDoc(r,i):(u=e.sliceDoc(r,r+Ze),d=e.sliceDoc(i-Ze,i));let f=/^\s*/.exec(u)[0].length,p=/\s*$/.exec(d)[0].length,m=d.length-p-n.length;return u.slice(f,f+t.length)==t&&d.slice(m,m+n.length)==n?{open:{pos:r+f+t.length,margin:/\s/.test(u.charAt(f+t.length))?1:0},close:{pos:i-p-n.length,margin:/\s/.test(d.charAt(m-1))?1:0}}:null}function $e(e){let t=[];for(let n of e.selection.ranges){let r=e.doc.lineAt(n.from),i=n.to<=r.to?r:e.doc.lineAt(n.to);i.from>r.from&&i.from==n.to&&(i=n.to==r.to+1?r:e.doc.lineAt(n.to-1));let a=t.length-1;a>=0&&t[a].to>r.from?t[a].to=i.to:t.push({from:r.from+/^\s*/.exec(r.text)[0].length,to:i.to})}return t}function et(e,t,n=t.selection.ranges){let r=n.map(e=>Xe(t,e.from).block);if(!r.every(e=>e))return null;let i=n.map((e,n)=>Qe(t,r[n],e.from,e.to));if(e!=2&&!i.every(e=>e))return{changes:t.changes(n.map((e,t)=>i[t]?[]:[{from:e.from,insert:r[t].open+` `},{from:e.to,insert:` `+r[t].close}]))};if(e!=1&&i.some(e=>e)){let e=[];for(let t=0,n;t<i.length;t++)if(n=i[t]){let i=r[t],{open:a,close:o}=n;e.push({from:a.pos-i.open.length,to:a.pos+a.margin},{from:o.pos-o.margin,to:o.pos+i.close.length})}return{changes:e}}return null}function tt(e,t,n=t.selection.ranges){let r=[],i=-1;ranges:for(let{from:e,to:a}of n){let n=r.length,o=1e9,s;for(let n=e;n<=a;){let c=t.doc.lineAt(n);if(s==null&&(s=Xe(t,c.from).line,!s))continue ranges;if(c.from>i&&(e==a||a>c.from)){i=c.from;let e=/^\s*/.exec(c.text)[0].length,t=e==c.length,n=c.text.slice(e,e+s.length)==s?e:-1;e<c.text.length&&e<o&&(o=e),r.push({line:c,comment:n,token:s,indent:e,empty:t,single:!1})}n=c.to+1}if(o<1e9)for(let e=n;e<r.length;e++)r[e].indent<r[e].line.text.length&&(r[e].indent=o);r.length==n+1&&(r[n].single=!0)}if(e!=2&&r.some(e=>e.comment<0&&(!e.empty||e.single))){let e=[];for(let{line:t,token:n,indent:i,empty:a,single:o}of r)(o||!a)&&e.push({from:t.from+i,insert:n+` `});let n=t.changes(e);return{changes:n,selection:t.selection.map(n,1)}}else if(e!=1&&r.some(e=>e.comment>=0)){let e=[];for(let{line:t,comment:n,token:i}of r)if(n>=0){let r=t.from+n,a=r+i.length;t.text[a-t.from]==` `&&a++,e.push({from:r,to:a})}return{changes:e}}return null}var nt=ne.define(),rt=ne.define(),it=je.define(),at=je.define({combine(e){return Oe(e,{minDepth:100,newGroupDelay:500,joinToEvent:(e,t)=>t},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(e,t)=>(n,r)=>e(n,r)||t(n,r)})}}),ot=ce.define({create(){return Ct.empty},update(e,t){let n=t.state.facet(at),r=t.annotation(nt);if(r){let i=L.fromTransaction(t,r.selection),a=r.side,o=a==0?e.undone:e.done;return o=i?pt(o,o.length,n.minDepth,i):vt(o,t.startState.selection),new Ct(a==0?r.rest:o,a==0?o:r.rest)}let i=t.annotation(rt);if((i==`full`||i==`before`)&&(e=e.isolate()),t.annotation(Fe.addToHistory)===!1)return t.changes.empty?e:e.addMapping(t.changes.desc);let a=L.fromTransaction(t),o=t.annotation(Fe.time),s=t.annotation(Fe.userEvent);return a?e=e.addChanges(a,o,s,n,t):t.selection&&(e=e.addSelection(t.startState.selection,o,s,n.newGroupDelay)),(i==`full`||i==`after`)&&(e=e.isolate()),e},toJSON(e){return{done:e.done.map(e=>e.toJSON()),undone:e.undone.map(e=>e.toJSON())}},fromJSON(e){return new Ct(e.done.map(L.fromJSON),e.undone.map(L.fromJSON))}});function st(e={}){return[ot,at.of(e),E.domEventHandlers({beforeinput(e,t){let n=e.inputType==`historyUndo`?lt:e.inputType==`historyRedo`?ut:null;return n?(e.preventDefault(),n(t)):!1}})]}function ct(e,t){return function({state:n,dispatch:r}){if(!t&&n.readOnly)return!1;let i=n.field(ot,!1);if(!i)return!1;let a=i.pop(e,n,t);return a?(r(a),!0):!1}}var lt=ct(0,!1),ut=ct(1,!1),dt=ct(0,!0),ft=ct(1,!0),L=class e{constructor(e,t,n,r,i){this.changes=e,this.effects=t,this.mapped=n,this.startSelection=r,this.selectionsAfter=i}setSelAfter(t){return new e(this.changes,this.effects,this.mapped,this.startSelection,t)}toJSON(){return{changes:this.changes?.toJSON(),mapped:this.mapped?.toJSON(),startSelection:this.startSelection?.toJSON(),selectionsAfter:this.selectionsAfter.map(e=>e.toJSON())}}static fromJSON(t){return new e(t.changes&&O.fromJSON(t.changes),[],t.mapped&&re.fromJSON(t.mapped),t.startSelection&&F.fromJSON(t.startSelection),t.selectionsAfter.map(F.fromJSON))}static fromTransaction(t,n){let r=R;for(let e of t.startState.facet(it)){let n=e(t);n.length&&(r=r.concat(n))}return!r.length&&t.changes.empty?null:new e(t.changes.invert(t.startState.doc),r,void 0,n||t.startState.selection,R)}static selection(t){return new e(void 0,R,void 0,void 0,t)}};function pt(e,t,n,r){let i=t+1>n+20?t-n-1:0,a=e.slice(i,t);return a.push(r),a}function mt(e,t){let n=[],r=!1;return e.iterChangedRanges((e,t)=>n.push(e,t)),t.iterChangedRanges((e,t,i,a)=>{for(let e=0;e<n.length;){let t=n[e++],o=n[e++];a>=t&&i<=o&&(r=!0)}}),r}function ht(e,t){return e.ranges.length==t.ranges.length&&e.ranges.filter((e,n)=>e.empty!=t.ranges[n].empty).length===0}function gt(e,t){return e.length?t.length?e.concat(t):e:t}var R=[],_t=200;function vt(e,t){if(e.length){let n=e[e.length-1],r=n.selectionsAfter.slice(Math.max(0,n.selectionsAfter.length-_t));return r.length&&r[r.length-1].eq(t)?e:(r.push(t),pt(e,e.length-1,1e9,n.setSelAfter(r)))}else return[L.selection([t])]}function yt(e){let t=e[e.length-1],n=e.slice();return n[e.length-1]=t.setSelAfter(t.selectionsAfter.slice(0,t.selectionsAfter.length-1)),n}function bt(e,t){if(!e.length)return e;let n=e.length,r=R;for(;n;){let i=xt(e[n-1],t,r);if(i.changes&&!i.changes.empty||i.effects.length){let t=e.slice(0,n);return t[n-1]=i,t}else t=i.mapped,n--,r=i.selectionsAfter}return r.length?[L.selection(r)]:R}function xt(e,t,n){let r=gt(e.selectionsAfter.length?e.selectionsAfter.map(e=>e.map(t)):R,n);if(!e.changes)return L.selection(r);let i=e.changes.map(t),a=t.mapDesc(e.changes,!0),o=e.mapped?e.mapped.composeDesc(a):a;return new L(i,P.mapEffects(e.effects,t),o,e.startSelection.map(a),r)}var St=/^(input\.type|delete)($|\.)/,Ct=class e{constructor(e,t,n=0,r=void 0){this.done=e,this.undone=t,this.prevTime=n,this.prevUserEvent=r}isolate(){return this.prevTime?new e(this.done,this.undone):this}addChanges(t,n,r,i,a){let o=this.done,s=o[o.length-1];return o=s&&s.changes&&!s.changes.empty&&t.changes&&(!r||St.test(r))&&(!s.selectionsAfter.length&&n-this.prevTime<i.newGroupDelay&&i.joinToEvent(a,mt(s.changes,t.changes))||r==`input.type.compose`)?pt(o,o.length-1,i.minDepth,new L(t.changes.compose(s.changes),gt(P.mapEffects(t.effects,s.changes),s.effects),s.mapped,s.startSelection,R)):pt(o,o.length,i.minDepth,t),new e(o,R,n,r)}addSelection(t,n,r,i){let a=this.done.length?this.done[this.done.length-1].selectionsAfter:R;return a.length>0&&n-this.prevTime<i&&r==this.prevUserEvent&&r&&/^select($|\.)/.test(r)&&ht(a[a.length-1],t)?this:new e(vt(this.done,t),this.undone,n,r)}addMapping(t){return new e(bt(this.done,t),bt(this.undone,t),this.prevTime,this.prevUserEvent)}pop(e,t,n){let r=e==0?this.done:this.undone;if(r.length==0)return null;let i=r[r.length-1],a=i.selectionsAfter[0]||(i.startSelection?i.startSelection.map(i.changes.invertedDesc,1):t.selection);if(n&&i.selectionsAfter.length)return t.update({selection:i.selectionsAfter[i.selectionsAfter.length-1],annotations:nt.of({side:e,rest:yt(r),selection:a}),userEvent:e==0?`select.undo`:`select.redo`,scrollIntoView:!0});if(i.changes){let n=r.length==1?R:r.slice(0,r.length-1);return i.mapped&&(n=bt(n,i.mapped)),t.update({changes:i.changes,selection:i.startSelection,effects:i.effects,annotations:nt.of({side:e,rest:n,selection:a}),filter:!1,userEvent:e==0?`undo`:`redo`,scrollIntoView:!0})}else return null}};Ct.empty=new Ct(R,R);var wt=[{key:`Mod-z`,run:lt,preventDefault:!0},{key:`Mod-y`,mac:`Mod-Shift-z`,run:ut,preventDefault:!0},{linux:`Ctrl-Shift-z`,run:ut,preventDefault:!0},{key:`Mod-u`,run:dt,preventDefault:!0},{key:`Alt-u`,mac:`Mod-Shift-u`,run:ft,preventDefault:!0}];function z(e,t){return F.create(e.ranges.map(t),e.mainIndex)}function B(e,t){return e.update({selection:t,scrollIntoView:!0,userEvent:`select`})}function V({state:e,dispatch:t},n){let r=z(e.selection,n);return r.eq(e.selection,!0)?!1:(t(B(e,r)),!0)}function Tt(e,t){return F.cursor(t?e.to:e.from)}function Et(e,t){return V(e,n=>n.empty?e.moveByChar(n,t):Tt(n,t))}function H(e){return e.textDirectionAt(e.state.selection.main.head)==g.LTR}var Dt=e=>Et(e,!H(e)),Ot=e=>Et(e,H(e));function kt(e,t){return V(e,n=>n.empty?e.moveByGroup(n,t):Tt(n,t))}var At=e=>kt(e,!H(e)),jt=e=>kt(e,H(e));typeof Intl<`u`&&Intl.Segmenter&&new Intl.Segmenter(void 0,{granularity:`word`});function Mt(e,t,n){if(t.type.prop(n))return!0;let r=t.to-t.from;return r&&(r>2||/[^\s,.;:]/.test(e.sliceDoc(t.from,t.to)))||t.firstChild}function Nt(e,t,n){let r=Le(e).resolveInner(t.head),i=n?j.closedBy:j.openedBy;for(let a=t.head;;){let t=n?r.childAfter(a):r.childBefore(a);if(!t)break;Mt(e,t,i)?r=t:a=n?t.to:t.from}let a=r.type.prop(i),o,s;return s=a&&(o=n?A(e,r.from,1):A(e,r.to,-1))&&o.matched?n?o.end.to:o.end.from:n?r.to:r.from,F.cursor(s,n?-1:1)}var Pt=e=>V(e,t=>Nt(e.state,t,!H(e))),Ft=e=>V(e,t=>Nt(e.state,t,H(e)));function It(e,t){return V(e,n=>{if(!n.empty)return Tt(n,t);let r=e.moveVertically(n,t);return r.head==n.head?e.moveToLineBoundary(n,t):r})}var Lt=e=>It(e,!1),Rt=e=>It(e,!0);function zt(e){let t=e.scrollDOM.clientHeight<e.scrollDOM.scrollHeight-2,n=0,r=0,i;if(t){for(let t of e.state.facet(E.scrollMargins)){let i=t(e);i?.top&&(n=Math.max(i?.top,n)),i?.bottom&&(r=Math.max(i?.bottom,r))}i=e.scrollDOM.clientHeight-n-r}else i=(e.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:n,marginBottom:r,selfScroll:t,height:Math.max(e.defaultLineHeight,i-5)}}function Bt(e,t){let n=zt(e),{state:r}=e,i=z(r.selection,r=>r.empty?e.moveVertically(r,t,n.height):Tt(r,t));if(i.eq(r.selection))return!1;let a;if(n.selfScroll){let t=e.coordsAtPos(r.selection.main.head),o=e.scrollDOM.getBoundingClientRect(),s=o.top+n.marginTop,c=o.bottom-n.marginBottom;t&&t.top>s&&t.bottom<c&&(a=E.scrollIntoView(i.main.head,{y:`start`,yMargin:t.top-s}))}return e.dispatch(B(r,i),{effects:a}),!0}var Vt=e=>Bt(e,!1),Ht=e=>Bt(e,!0);function U(e,t,n){let r=e.lineBlockAt(t.head),i=e.moveToLineBoundary(t,n);if(i.head==t.head&&i.head!=(n?r.to:r.from)&&(i=e.moveToLineBoundary(t,n,!1)),!n&&i.head==r.from&&r.length){let n=/^\s*/.exec(e.state.sliceDoc(r.from,Math.min(r.from+100,r.to)))[0].length;n&&t.head!=r.from+n&&(i=F.cursor(r.from+n))}return i}var Ut=e=>V(e,t=>U(e,t,!0)),Wt=e=>V(e,t=>U(e,t,!1)),Gt=e=>V(e,t=>U(e,t,!H(e))),Kt=e=>V(e,t=>U(e,t,H(e))),qt=e=>V(e,t=>F.cursor(e.lineBlockAt(t.head).from,1)),Jt=e=>V(e,t=>F.cursor(e.lineBlockAt(t.head).to,-1));function Yt(e,t,n){let r=!1,i=z(e.selection,t=>{let i=A(e,t.head,-1)||A(e,t.head,1)||t.head>0&&A(e,t.head-1,1)||t.head<e.doc.length&&A(e,t.head+1,-1);if(!i||!i.end)return t;r=!0;let a=i.start.from==t.head?i.end.to:i.end.from;return n?F.range(t.anchor,a):F.cursor(a)});return r?(t(B(e,i)),!0):!1}var Xt=({state:e,dispatch:t})=>Yt(e,t,!1);function W(e,t){let n=z(e.state.selection,e=>{let n=t(e);return F.range(e.anchor,n.head,n.goalColumn,n.bidiLevel||void 0,n.assoc)});return n.eq(e.state.selection)?!1:(e.dispatch(B(e.state,n)),!0)}function Zt(e,t){return W(e,n=>e.moveByChar(n,t))}var Qt=e=>Zt(e,!H(e)),$t=e=>Zt(e,H(e));function en(e,t){return W(e,n=>e.moveByGroup(n,t))}var tn=e=>en(e,!H(e)),nn=e=>en(e,H(e)),rn=e=>W(e,t=>Nt(e.state,t,!H(e))),an=e=>W(e,t=>Nt(e.state,t,H(e)));function on(e,t){return W(e,n=>e.moveVertically(n,t))}var sn=e=>on(e,!1),cn=e=>on(e,!0);function ln(e,t){return W(e,n=>e.moveVertically(n,t,zt(e).height))}var un=e=>ln(e,!1),dn=e=>ln(e,!0),fn=e=>W(e,t=>U(e,t,!0)),pn=e=>W(e,t=>U(e,t,!1)),mn=e=>W(e,t=>U(e,t,!H(e))),hn=e=>W(e,t=>U(e,t,H(e))),gn=e=>W(e,t=>F.cursor(e.lineBlockAt(t.head).from)),_n=e=>W(e,t=>F.cursor(e.lineBlockAt(t.head).to)),vn=({state:e,dispatch:t})=>(t(B(e,{anchor:0})),!0),yn=({state:e,dispatch:t})=>(t(B(e,{anchor:e.doc.length})),!0),bn=({state:e,dispatch:t})=>(t(B(e,{anchor:e.selection.main.anchor,head:0})),!0),xn=({state:e,dispatch:t})=>(t(B(e,{anchor:e.selection.main.anchor,head:e.doc.length})),!0),Sn=({state:e,dispatch:t})=>(t(e.update({selection:{anchor:0,head:e.doc.length},userEvent:`select`})),!0),Cn=({state:e,dispatch:t})=>{let n=Hn(e).map(({from:t,to:n})=>F.range(t,Math.min(n+1,e.doc.length)));return t(e.update({selection:F.create(n),userEvent:`select`})),!0},wn=({state:e,dispatch:t})=>{let n=z(e.selection,t=>{let n=Le(e),r=n.resolveStack(t.from,1);if(t.empty){let e=n.resolveStack(t.from,-1);e.node.from>=r.node.from&&e.node.to<=r.node.to&&(r=e)}for(let e=r;e;e=e.next){let{node:n}=e;if((n.from<t.from&&n.to>=t.to||n.to>t.to&&n.from<=t.from)&&e.next)return F.range(n.to,n.from)}return t});return n.eq(e.selection)?!1:(t(B(e,n)),!0)};function Tn(e,t){let{state:n}=e,r=n.selection,i=n.selection.ranges.slice();for(let r of n.selection.ranges){let a=n.doc.lineAt(r.head);if(t?a.to<e.state.doc.length:a.from>0)for(let n=r;;){let r=e.moveVertically(n,t);if(r.head<a.from||r.head>a.to){i.some(e=>e.head==r.head)||i.push(r);break}else if(r.head==n.head)break;else n=r}}return i.length==r.ranges.length?!1:(e.dispatch(B(n,F.create(i,i.length-1))),!0)}var En=e=>Tn(e,!1),Dn=e=>Tn(e,!0),On=({state:e,dispatch:t})=>{let n=e.selection,r=null;return n.ranges.length>1?r=F.create([n.main]):n.main.empty||(r=F.create([F.cursor(n.main.head)])),r?(t(B(e,r)),!0):!1};function kn(e,t){if(e.state.readOnly)return!1;let n=`delete.selection`,{state:r}=e,i=r.changeByRange(r=>{let{from:i,to:a}=r;if(i==a){let o=t(r);o<i?(n=`delete.backward`,o=An(e,o,!1)):o>i&&(n=`delete.forward`,o=An(e,o,!0)),i=Math.min(i,o),a=Math.max(a,o)}else i=An(e,i,!1),a=An(e,a,!0);return i==a?{range:r}:{changes:{from:i,to:a},range:F.cursor(i,i<r.head?-1:1)}});return i.changes.empty?!1:(e.dispatch(r.update(i,{scrollIntoView:!0,userEvent:n,effects:n==`delete.selection`?E.announce.of(r.phrase(`Selection deleted`)):void 0})),!0)}function An(e,t,n){if(e instanceof E)for(let r of e.state.facet(E.atomicRanges).map(t=>t(e)))r.between(t,t,(e,r)=>{e<t&&r>t&&(t=n?r:e)});return t}var jn=(e,t,n)=>kn(e,r=>{let i=r.from,{state:a}=e,o=a.doc.lineAt(i),s,c;if(n&&!t&&i>o.from&&i<o.from+200&&!/[^ \t]/.test(s=o.text.slice(0,i-o.from))){if(s[s.length-1]==` `)return i-1;let e=Se(s,a.tabSize)%ie(a)||ie(a);for(let t=0;t<e&&s[s.length-1-t]==` `;t++)i--;c=i}else c=N(o.text,i-o.from,t,t)+o.from,c==i&&o.number!=(t?a.doc.lines:1)?c+=t?1:-1:!t&&/[\ufe00-\ufe0f]/.test(o.text.slice(c-o.from,i-o.from))&&(c=N(o.text,c-o.from,!1,!1)+o.from);return c}),Mn=e=>jn(e,!1,!0),Nn=e=>jn(e,!0,!1),Pn=(e,t)=>kn(e,n=>{let r=n.head,{state:i}=e,a=i.doc.lineAt(r),o=i.charCategorizer(r);for(let e=null;;){if(r==(t?a.to:a.from)){r==n.head&&a.number!=(t?i.doc.lines:1)&&(r+=t?1:-1);break}let s=N(a.text,r-a.from,t)+a.from,c=a.text.slice(Math.min(r,s)-a.from,Math.max(r,s)-a.from),l=o(c);if(e!=null&&l!=e)break;(c!=` `||r!=n.head)&&(e=l),r=s}return r}),Fn=e=>Pn(e,!1),In=e=>Pn(e,!0),Ln=e=>kn(e,t=>{let n=e.lineBlockAt(t.head).to;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}),Rn=e=>kn(e,t=>{let n=e.moveToLineBoundary(t,!1).head;return t.head>n?n:Math.max(0,t.head-1)}),zn=e=>kn(e,t=>{let n=e.moveToLineBoundary(t,!0).head;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}),Bn=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(e=>({changes:{from:e.from,to:e.to,insert:be.of([``,``])},range:F.cursor(e.from)}));return t(e.update(n,{scrollIntoView:!0,userEvent:`input`})),!0},Vn=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(t=>{if(!t.empty||t.from==0||t.from==e.doc.length)return{range:t};let n=t.from,r=e.doc.lineAt(n),i=n==r.from?n-1:N(r.text,n-r.from,!1)+r.from,a=n==r.to?n+1:N(r.text,n-r.from,!0)+r.from;return{changes:{from:i,to:a,insert:e.doc.slice(n,a).append(e.doc.slice(i,n))},range:F.cursor(a)}});return n.changes.empty?!1:(t(e.update(n,{scrollIntoView:!0,userEvent:`move.character`})),!0)};function Hn(e){let t=[],n=-1;for(let r of e.selection.ranges){let i=e.doc.lineAt(r.from),a=e.doc.lineAt(r.to);if(!r.empty&&r.to==a.from&&(a=e.doc.lineAt(r.to-1)),n>=i.number){let e=t[t.length-1];e.to=a.to,e.ranges.push(r)}else t.push({from:i.from,to:a.to,ranges:[r]});n=a.number+1}return t}function Un(e,t,n){if(e.readOnly)return!1;let r=[],i=[];for(let t of Hn(e)){if(n?t.to==e.doc.length:t.from==0)continue;let a=e.doc.lineAt(n?t.to+1:t.from-1),o=a.length+1;if(n){r.push({from:t.to,to:a.to},{from:t.from,insert:a.text+e.lineBreak});for(let n of t.ranges)i.push(F.range(Math.min(e.doc.length,n.anchor+o),Math.min(e.doc.length,n.head+o)))}else{r.push({from:a.from,to:t.from},{from:t.to,insert:e.lineBreak+a.text});for(let e of t.ranges)i.push(F.range(e.anchor-o,e.head-o))}}return r.length?(t(e.update({changes:r,scrollIntoView:!0,selection:F.create(i,e.selection.mainIndex),userEvent:`move.line`})),!0):!1}var Wn=({state:e,dispatch:t})=>Un(e,t,!1),Gn=({state:e,dispatch:t})=>Un(e,t,!0);function Kn(e,t,n){if(e.readOnly)return!1;let r=[];for(let t of Hn(e))n?r.push({from:t.from,insert:e.doc.slice(t.from,t.to)+e.lineBreak}):r.push({from:t.to,insert:e.lineBreak+e.doc.slice(t.from,t.to)});let i=e.changes(r);return t(e.update({changes:i,selection:e.selection.map(i,n?1:-1),scrollIntoView:!0,userEvent:`input.copyline`})),!0}var qn=({state:e,dispatch:t})=>Kn(e,t,!1),Jn=({state:e,dispatch:t})=>Kn(e,t,!0),Yn=e=>{if(e.state.readOnly)return!1;let{state:t}=e,n=t.changes(Hn(t).map(({from:e,to:n})=>(e>0?e--:n<t.doc.length&&n++,{from:e,to:n}))),r=z(t.selection,t=>{let n;if(e.lineWrapping){let r=e.lineBlockAt(t.head),i=e.coordsAtPos(t.head,t.assoc||1);i&&(n=r.bottom+e.documentTop-i.bottom+e.defaultLineHeight/2)}return e.moveVertically(t,!0,n)}).map(n);return e.dispatch({changes:n,selection:r,scrollIntoView:!0,userEvent:`delete.line`}),!0};function Xn(e,t){if(/\(\)|\[\]|\{\}/.test(e.sliceDoc(t-1,t+1)))return{from:t,to:t};let n=Le(e).resolveInner(t),r=n.childBefore(t),i=n.childAfter(t),a;return r&&i&&r.to<=t&&i.from>=t&&(a=r.type.prop(j.closedBy))&&a.indexOf(i.name)>-1&&e.doc.lineAt(r.to).from==e.doc.lineAt(i.from).from&&!/\S/.test(e.sliceDoc(r.to,i.from))?{from:r.to,to:i.from}:null}var Zn=$n(!1),Qn=$n(!0);function $n(e){return({state:t,dispatch:n})=>{if(t.readOnly)return!1;let r=t.changeByRange(n=>{let{from:r,to:i}=n,a=t.doc.lineAt(r),o=!e&&r==i&&Xn(t,r);e&&(r=i=(i<=a.to?a:t.doc.lineAt(i)).to);let s=new de(t,{simulateBreak:r,simulateDoubleBreak:!!o}),c=Ie(s,r);for(c??=Se(/^\s*/.exec(t.doc.lineAt(r).text)[0],t.tabSize);i<a.to&&/\s/.test(a.text[i-a.from]);)i++;o?{from:r,to:i}=o:r>a.from&&r<a.from+100&&!/\S/.test(a.text.slice(0,r))&&(r=a.from);let l=[``,oe(t,c)];return o&&l.push(oe(t,s.lineIndent(a.from,-1))),{changes:{from:r,to:i,insert:be.of(l)},range:F.cursor(r+1+l[1].length)}});return n(t.update(r,{scrollIntoView:!0,userEvent:`input`})),!0}}function er(e,t){let n=-1;return e.changeByRange(r=>{let i=[];for(let a=r.from;a<=r.to;){let o=e.doc.lineAt(a);o.number>n&&(r.empty||r.to>o.from)&&(t(o,i,r),n=o.number),a=o.to+1}let a=e.changes(i);return{changes:i,range:F.range(a.mapPos(r.anchor,1),a.mapPos(r.head,1))}})}var tr=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=Object.create(null),r=new de(e,{overrideIndentation:e=>n[e]??-1}),i=er(e,(t,i,a)=>{let o=Ie(r,t.from);if(o==null)return;/\S/.test(t.text)||(o=0);let s=/^\s*/.exec(t.text)[0],c=oe(e,o);(s!=c||a.from<t.from+s.length)&&(n[t.from]=o,i.push({from:t.from,to:t.from+s.length,insert:c}))});return i.changes.empty||t(e.update(i,{userEvent:`indent`})),!0},nr=({state:e,dispatch:t})=>e.readOnly?!1:(t(e.update(er(e,(t,n)=>{n.push({from:t.from,insert:e.facet(Re)})}),{userEvent:`input.indent`})),!0),rr=({state:e,dispatch:t})=>e.readOnly?!1:(t(e.update(er(e,(t,n)=>{let r=/^\s*/.exec(t.text)[0];if(!r)return;let i=Se(r,e.tabSize),a=0,o=oe(e,Math.max(0,i-ie(e)));for(;a<r.length&&a<o.length&&r.charCodeAt(a)==o.charCodeAt(a);)a++;n.push({from:t.from+a,to:t.from+r.length,insert:o.slice(a)})}),{userEvent:`delete.dedent`})),!0),ir=e=>(e.setTabFocusMode(),!0),ar=[{key:`Ctrl-b`,run:Dt,shift:Qt,preventDefault:!0},{key:`Ctrl-f`,run:Ot,shift:$t},{key:`Ctrl-p`,run:Lt,shift:sn},{key:`Ctrl-n`,run:Rt,shift:cn},{key:`Ctrl-a`,run:qt,shift:gn},{key:`Ctrl-e`,run:Jt,shift:_n},{key:`Ctrl-d`,run:Nn},{key:`Ctrl-h`,run:Mn},{key:`Ctrl-k`,run:Ln},{key:`Ctrl-Alt-h`,run:Fn},{key:`Ctrl-o`,run:Bn},{key:`Ctrl-t`,run:Vn},{key:`Ctrl-v`,run:Ht}],or=[{key:`ArrowLeft`,run:Dt,shift:Qt,preventDefault:!0},{key:`Mod-ArrowLeft`,mac:`Alt-ArrowLeft`,run:At,shift:tn,preventDefault:!0},{mac:`Cmd-ArrowLeft`,run:Gt,shift:mn,preventDefault:!0},{key:`ArrowRight`,run:Ot,shift:$t,preventDefault:!0},{key:`Mod-ArrowRight`,mac:`Alt-ArrowRight`,run:jt,shift:nn,preventDefault:!0},{mac:`Cmd-ArrowRight`,run:Kt,shift:hn,preventDefault:!0},{key:`ArrowUp`,run:Lt,shift:sn,preventDefault:!0},{mac:`Cmd-ArrowUp`,run:vn,shift:bn},{mac:`Ctrl-ArrowUp`,run:Vt,shift:un},{key:`ArrowDown`,run:Rt,shift:cn,preventDefault:!0},{mac:`Cmd-ArrowDown`,run:yn,shift:xn},{mac:`Ctrl-ArrowDown`,run:Ht,shift:dn},{key:`PageUp`,run:Vt,shift:un},{key:`PageDown`,run:Ht,shift:dn},{key:`Home`,run:Wt,shift:pn,preventDefault:!0},{key:`Mod-Home`,run:vn,shift:bn},{key:`End`,run:Ut,shift:fn,preventDefault:!0},{key:`Mod-End`,run:yn,shift:xn},{key:`Enter`,run:Zn,shift:Zn},{key:`Mod-a`,run:Sn},{key:`Backspace`,run:Mn,shift:Mn,preventDefault:!0},{key:`Delete`,run:Nn,preventDefault:!0},{key:`Mod-Backspace`,mac:`Alt-Backspace`,run:Fn,preventDefault:!0},{key:`Mod-Delete`,mac:`Alt-Delete`,run:In,preventDefault:!0},{mac:`Mod-Backspace`,run:Rn,preventDefault:!0},{mac:`Mod-Delete`,run:zn,preventDefault:!0}].concat(ar.map(e=>({mac:e.key,run:e.run,shift:e.shift}))),sr=[{key:`Alt-ArrowLeft`,mac:`Ctrl-ArrowLeft`,run:Pt,shift:rn},{key:`Alt-ArrowRight`,mac:`Ctrl-ArrowRight`,run:Ft,shift:an},{key:`Alt-ArrowUp`,run:Wn},{key:`Shift-Alt-ArrowUp`,run:qn},{key:`Alt-ArrowDown`,run:Gn},{key:`Shift-Alt-ArrowDown`,run:Jn},{key:`Mod-Alt-ArrowUp`,run:En},{key:`Mod-Alt-ArrowDown`,run:Dn},{key:`Escape`,run:On},{key:`Mod-Enter`,run:Qn},{key:`Alt-l`,mac:`Ctrl-l`,run:Cn},{key:`Mod-i`,run:wn,preventDefault:!0},{key:`Mod-[`,run:rr},{key:`Mod-]`,run:nr},{key:`Mod-Alt-\\`,run:tr},{key:`Shift-Mod-k`,run:Yn},{key:`Shift-Mod-\\`,run:Xt},{key:`Mod-/`,run:Ge},{key:`Alt-A`,run:Je},{key:`Ctrl-m`,mac:`Shift-Alt-m`,run:ir}].concat(or),cr={key:`Tab`,run:nr,shift:rr},lr=typeof String.prototype.normalize==`function`?e=>e.normalize(`NFKD`):e=>e,G=class{constructor(e,t,n=0,r=e.length,i,a){this.test=a,this.value={from:0,to:0},this.done=!1,this.matches=[],this.buffer=``,this.bufferPos=0,this.iter=e.iterRange(n,r),this.bufferStart=n,this.normalize=i?e=>i(lr(e)):lr,this.query=this.normalize(t)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return ue(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let e=this.peek();if(e<0)return this.done=!0,this;let t=me(e),n=this.bufferStart+this.bufferPos;this.bufferPos+=fe(e);let r=this.normalize(t);if(r.length)for(let e=0,i=n;;e++){let a=r.charCodeAt(e),o=this.match(a,i,this.bufferPos+this.bufferStart);if(e==r.length-1){if(o)return this.value=o,this;break}i==n&&e<t.length&&t.charCodeAt(e)==a&&i++}}}match(e,t,n){let r=null;for(let t=0;t<this.matches.length;t+=2){let i=this.matches[t],a=!1;this.query.charCodeAt(i)==e&&(i==this.query.length-1?r={from:this.matches[t+1],to:n}:(this.matches[t]++,a=!0)),a||(this.matches.splice(t,2),t-=2)}return this.query.charCodeAt(0)==e&&(this.query.length==1?r={from:t,to:n}:this.matches.push(1,t)),r&&this.test&&!this.test(r.from,r.to,this.buffer,this.bufferStart)&&(r=null),r}};typeof Symbol<`u`&&(G.prototype[Symbol.iterator]=function(){return this});var ur={from:-1,to:-1,match:/.*/.exec(``)},dr=`gm`+(/x/.unicode==null?``:`u`),fr=class{constructor(e,t,n,r=0,i=e.length){if(this.text=e,this.to=i,this.curLine=``,this.done=!1,this.value=ur,/\\[sWDnr]|\n|\r|\[\^/.test(t))return new hr(e,t,n,r,i);this.re=new RegExp(t,dr+(n?.ignoreCase?`i`:``)),this.test=n?.test,this.iter=e.iter(),this.curLineStart=e.lineAt(r).from,this.matchPos=_r(e,r),this.getLine(this.curLineStart)}getLine(e){this.iter.next(e),this.iter.lineBreak?this.curLine=``:(this.curLine=this.iter.value,this.curLineStart+this.curLine.length>this.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart)),this.iter.next())}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1,this.curLineStart>this.to?this.curLine=``:this.getLine(0)}next(){for(let e=this.matchPos-this.curLineStart;;){this.re.lastIndex=e;let t=this.matchPos<=this.to&&this.re.exec(this.curLine);if(t){let n=this.curLineStart+t.index,r=n+t[0].length;if(this.matchPos=_r(this.text,r+(n==r?1:0)),n==this.curLineStart+this.curLine.length&&this.nextLine(),(n<r||n>this.value.to)&&(!this.test||this.test(n,r,t)))return this.value={from:n,to:r,match:t},this;e=this.matchPos-this.curLineStart}else if(this.curLineStart+this.curLine.length<this.to)this.nextLine(),e=0;else return this.done=!0,this}}},pr=new WeakMap,mr=class e{constructor(e,t){this.from=e,this.text=t}get to(){return this.from+this.text.length}static get(t,n,r){let i=pr.get(t);if(!i||i.from>=r||i.to<=n){let i=new e(n,t.sliceString(n,r));return pr.set(t,i),i}if(i.from==n&&i.to==r)return i;let{text:a,from:o}=i;return o>n&&(a=t.sliceString(n,o)+a,o=n),i.to<r&&(a+=t.sliceString(i.to,r)),pr.set(t,new e(o,a)),new e(n,a.slice(n-o,r-o))}},hr=class{constructor(e,t,n,r,i){this.text=e,this.to=i,this.done=!1,this.value=ur,this.matchPos=_r(e,r),this.re=new RegExp(t,dr+(n?.ignoreCase?`i`:``)),this.test=n?.test,this.flat=mr.get(e,r,this.chunkEnd(r+5e3))}chunkEnd(e){return e>=this.to?this.to:this.text.lineAt(e).to}next(){for(;;){let e=this.re.lastIndex=this.matchPos-this.flat.from,t=this.re.exec(this.flat.text);if(t&&!t[0]&&t.index==e&&(this.re.lastIndex=e+1,t=this.re.exec(this.flat.text)),t){let e=this.flat.from+t.index,n=e+t[0].length;if((this.flat.to>=this.to||t.index+t[0].length<=this.flat.text.length-10)&&(!this.test||this.test(e,n,t)))return this.value={from:e,to:n,match:t},this.matchPos=_r(this.text,n+(e==n?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=mr.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}};typeof Symbol<`u`&&(fr.prototype[Symbol.iterator]=hr.prototype[Symbol.iterator]=function(){return this});function gr(e){try{return new RegExp(e,dr),!0}catch{return!1}}function _r(e,t){if(t>=e.length)return t;let n=e.lineAt(t),r;for(;t<n.to&&(r=n.text.charCodeAt(t-n.from))>=56320&&r<57344;)t++;return t}var vr=e=>{let{state:t}=e,n=String(t.doc.lineAt(e.state.selection.main.head).number),{close:r,result:i}=S(e,{label:t.phrase(`Go to line`),input:{type:`text`,name:`line`,value:n},focus:!0,submitLabel:t.phrase(`go`)});return i.then(n=>{let i=n&&/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(n.elements.line.value);if(!i){e.dispatch({effects:r});return}let a=t.doc.lineAt(t.selection.main.head),[,o,s,c,l]=i,u=c?+c.slice(1):0,d=s?+s:a.number;if(s&&l){let e=d/100;o&&(e=e*(o==`-`?-1:1)+a.number/t.doc.lines),d=Math.round(t.doc.lines*e)}else s&&o&&(d=d*(o==`-`?-1:1)+a.number);let f=t.doc.line(Math.max(1,Math.min(t.doc.lines,d))),p=F.cursor(f.from+Math.max(0,Math.min(u,f.length)));e.dispatch({effects:[r,E.scrollIntoView(p.from,{y:`center`})],selection:p})}),!0},yr={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},br=je.define({combine(e){return Oe(e,yr,{highlightWordAroundCursor:(e,t)=>e||t,minSelectionLength:Math.min,maxMatches:Math.min})}});function xr(e){let t=[Dr,Er];return e&&t.push(br.of(e)),t}var Sr=_.mark({class:`cm-selectionMatch`}),Cr=_.mark({class:`cm-selectionMatch cm-selectionMatch-main`});function wr(e,t,n,r){return(n==0||e(t.sliceDoc(n-1,n))!=f.Word)&&(r==t.doc.length||e(t.sliceDoc(r,r+1))!=f.Word)}function Tr(e,t,n,r){return e(t.sliceDoc(n,n+1))==f.Word&&e(t.sliceDoc(r-1,r))==f.Word}var Er=p.fromClass(class{constructor(e){this.decorations=this.getDeco(e)}update(e){(e.selectionSet||e.docChanged||e.viewportChanged)&&(this.decorations=this.getDeco(e.view))}getDeco(e){let t=e.state.facet(br),{state:n}=e,r=n.selection;if(r.ranges.length>1)return _.none;let i=r.main,a,o=null;if(i.empty){if(!t.highlightWordAroundCursor)return _.none;let e=n.wordAt(i.head);if(!e)return _.none;o=n.charCategorizer(i.head),a=n.sliceDoc(e.from,e.to)}else{let e=i.to-i.from;if(e<t.minSelectionLength||e>200)return _.none;if(t.wholeWords){if(a=n.sliceDoc(i.from,i.to),o=n.charCategorizer(i.head),!(wr(o,n,i.from,i.to)&&Tr(o,n,i.from,i.to)))return _.none}else if(a=n.sliceDoc(i.from,i.to),!a)return _.none}let s=[];for(let r of e.visibleRanges){let e=new G(n.doc,a,r.from,r.to);for(;!e.next().done;){let{from:r,to:a}=e.value;if((!o||wr(o,n,r,a))&&(i.empty&&r<=i.from&&a>=i.to?s.push(Cr.range(r,a)):(r>=i.to||a<=i.from)&&s.push(Sr.range(r,a)),s.length>t.maxMatches))return _.none}}return _.set(s)}},{decorations:e=>e.decorations}),Dr=E.baseTheme({".cm-selectionMatch":{backgroundColor:`#99ff7780`},".cm-searchMatch .cm-selectionMatch":{backgroundColor:`transparent`}}),Or=({state:e,dispatch:t})=>{let{selection:n}=e,r=F.create(n.ranges.map(t=>e.wordAt(t.head)||F.cursor(t.head)),n.mainIndex);return r.eq(n)?!1:(t(e.update({selection:r})),!0)};function kr(e,t){let{main:n,ranges:r}=e.selection,i=e.wordAt(n.head),a=i&&i.from==n.from&&i.to==n.to;for(let n=!1,i=new G(e.doc,t,r[r.length-1].to);;)if(i.next(),i.done){if(n)return null;i=new G(e.doc,t,0,Math.max(0,r[r.length-1].from-1)),n=!0}else{if(n&&r.some(e=>e.from==i.value.from))continue;if(a){let t=e.wordAt(i.value.from);if(!t||t.from!=i.value.from||t.to!=i.value.to)continue}return i.value}}var Ar=({state:e,dispatch:t})=>{let{ranges:n}=e.selection;if(n.some(e=>e.from===e.to))return Or({state:e,dispatch:t});let r=e.sliceDoc(n[0].from,n[0].to);if(e.selection.ranges.some(t=>e.sliceDoc(t.from,t.to)!=r))return!1;let i=kr(e,r);return i?(t(e.update({selection:e.selection.addRange(F.range(i.from,i.to),!1),effects:E.scrollIntoView(i.to)})),!0):!1},K=je.define({combine(e){return Oe(e,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:e=>new si(e),scrollToMatch:e=>E.scrollIntoView(e)})}}),jr=class{constructor(e){this.search=e.search,this.caseSensitive=!!e.caseSensitive,this.literal=!!e.literal,this.regexp=!!e.regexp,this.replace=e.replace||``,this.valid=!!this.search&&(!this.regexp||gr(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!e.wholeWord,this.test=e.test}unquote(e){return this.literal?e:e.replace(/\\([nrt\\])/g,(e,t)=>t==`n`?`
|
|
2
2
|
`:t==`r`?`\r`:t==`t`?` `:`\\`)}eq(e){return this.search==e.search&&this.replace==e.replace&&this.caseSensitive==e.caseSensitive&&this.regexp==e.regexp&&this.wholeWord==e.wholeWord&&this.test==e.test}create(){return this.regexp?new Br(this):new Fr(this)}getCursor(e,t=0,n){let r=e.doc?e:we.create({doc:e});return n??=r.doc.length,this.regexp?J(this,r,t,n):q(this,r,t,n)}},Mr=class{constructor(e){this.spec=e}};function Nr(e,t,n){return(r,i,a,o)=>n&&!n(r,i,a,o)?!1:e(r>=o&&i<=o+a.length?a.slice(r-o,i-o):t.doc.sliceString(r,i),t,r,i)}function q(e,t,n,r){let i;return e.wholeWord&&(i=Pr(t.doc,t.charCategorizer(t.selection.main.head))),e.test&&(i=Nr(e.test,t,i)),new G(t.doc,e.unquoted,n,r,e.caseSensitive?void 0:e=>e.toLowerCase(),i)}function Pr(e,t){return(n,r,i,a)=>((a>n||a+i.length<r)&&(a=Math.max(0,n-2),i=e.sliceString(a,Math.min(e.length,r+2))),(t(Lr(i,n-a))!=f.Word||t(Rr(i,n-a))!=f.Word)&&(t(Rr(i,r-a))!=f.Word||t(Lr(i,r-a))!=f.Word))}var Fr=class extends Mr{constructor(e){super(e)}nextMatch(e,t,n){let r=q(this.spec,e,n,e.doc.length).nextOverlapping();if(r.done){let n=Math.min(e.doc.length,t+this.spec.unquoted.length);r=q(this.spec,e,0,n).nextOverlapping()}return r.done||r.value.from==t&&r.value.to==n?null:r.value}prevMatchInRange(e,t,n){for(let r=n;;){let n=Math.max(t,r-1e4-this.spec.unquoted.length),i=q(this.spec,e,n,r),a=null;for(;!i.nextOverlapping().done;)a=i.value;if(a)return a;if(n==t)return null;r-=1e4}}prevMatch(e,t,n){let r=this.prevMatchInRange(e,0,t);return r||=this.prevMatchInRange(e,Math.max(0,n-this.spec.unquoted.length),e.doc.length),r&&(r.from!=t||r.to!=n)?r:null}getReplacement(e){return this.spec.unquote(this.spec.replace)}matchAll(e,t){let n=q(this.spec,e,0,e.doc.length),r=[];for(;!n.next().done;){if(r.length>=t)return null;r.push(n.value)}return r}highlight(e,t,n,r){let i=q(this.spec,e,Math.max(0,t-this.spec.unquoted.length),Math.min(n+this.spec.unquoted.length,e.doc.length));for(;!i.next().done;)r(i.value.from,i.value.to)}};function Ir(e,t,n){return(r,i,a)=>(!n||n(r,i,a))&&e(a[0],t,r,i)}function J(e,t,n,r){let i;return e.wholeWord&&(i=zr(t.charCategorizer(t.selection.main.head))),e.test&&(i=Ir(e.test,t,i)),new fr(t.doc,e.search,{ignoreCase:!e.caseSensitive,test:i},n,r)}function Lr(e,t){return e.slice(N(e,t,!1),t)}function Rr(e,t){return e.slice(t,N(e,t))}function zr(e){return(t,n,r)=>!r[0].length||(e(Lr(r.input,r.index))!=f.Word||e(Rr(r.input,r.index))!=f.Word)&&(e(Rr(r.input,r.index+r[0].length))!=f.Word||e(Lr(r.input,r.index+r[0].length))!=f.Word)}var Br=class extends Mr{nextMatch(e,t,n){let r=J(this.spec,e,n,e.doc.length).next();return r.done&&(r=J(this.spec,e,0,t).next()),r.done?null:r.value}prevMatchInRange(e,t,n){for(let r=1;;r++){let i=Math.max(t,n-r*1e4),a=J(this.spec,e,i,n),o=null;for(;!a.next().done;)o=a.value;if(o&&(i==t||o.from>i+10))return o;if(i==t)return null}}prevMatch(e,t,n){return this.prevMatchInRange(e,0,t)||this.prevMatchInRange(e,n,e.doc.length)}getReplacement(e){return this.spec.unquote(this.spec.replace).replace(/\$([$&]|\d+)/g,(t,n)=>{if(n==`&`)return e.match[0];if(n==`$`)return`$`;for(let t=n.length;t>0;t--){let r=+n.slice(0,t);if(r>0&&r<e.match.length)return e.match[r]+n.slice(t)}return t})}matchAll(e,t){let n=J(this.spec,e,0,e.doc.length),r=[];for(;!n.next().done;){if(r.length>=t)return null;r.push(n.value)}return r}highlight(e,t,n,r){let i=J(this.spec,e,Math.max(0,t-250),Math.min(n+250,e.doc.length));for(;!i.next().done;)r(i.value.from,i.value.to)}},Vr=P.define(),Hr=P.define(),Y=ce.define({create(e){return new Ur(ti(e).create(),null)},update(e,t){for(let n of t.effects)n.is(Vr)?e=new Ur(n.value.create(),e.panel):n.is(Hr)&&(e=new Ur(e.query,n.value?ei:null));return e},provide:e=>ke.from(e,e=>e.panel)}),Ur=class{constructor(e,t){this.query=e,this.panel=t}},Wr=_.mark({class:`cm-searchMatch`}),Gr=_.mark({class:`cm-searchMatch cm-searchMatch-selected`}),Kr=p.fromClass(class{constructor(e){this.view=e,this.decorations=this.highlight(e.state.field(Y))}update(e){let t=e.state.field(Y);(t!=e.startState.field(Y)||e.docChanged||e.selectionSet||e.viewportChanged)&&(this.decorations=this.highlight(t))}highlight({query:e,panel:t}){if(!t||!e.spec.valid)return _.none;let{view:n}=this,r=new Ee;for(let t=0,i=n.visibleRanges,a=i.length;t<a;t++){let{from:o,to:s}=i[t];for(;t<a-1&&s>i[t+1].from-500;)s=i[++t].to;e.highlight(n.state,o,s,(e,t)=>{let i=n.state.selection.ranges.some(n=>n.from==e&&n.to==t);r.add(e,t,i?Gr:Wr)})}return r.finish()}},{decorations:e=>e.decorations});function qr(e){return t=>{let n=t.state.field(Y,!1);return n&&n.query.spec.valid?e(t,n):ii(t)}}var Jr=qr((e,{query:t})=>{let{to:n}=e.state.selection.main,r=t.nextMatch(e.state,n,n);if(!r)return!1;let i=F.single(r.from,r.to),a=e.state.facet(K);return e.dispatch({selection:i,effects:[ui(e,r),a.scrollToMatch(i.main,e)],userEvent:`select.search`}),ri(e),!0}),Yr=qr((e,{query:t})=>{let{state:n}=e,{from:r}=n.selection.main,i=t.prevMatch(n,r,r);if(!i)return!1;let a=F.single(i.from,i.to),o=e.state.facet(K);return e.dispatch({selection:a,effects:[ui(e,i),o.scrollToMatch(a.main,e)],userEvent:`select.search`}),ri(e),!0}),Xr=qr((e,{query:t})=>{let n=t.matchAll(e.state,1e3);return!n||!n.length?!1:(e.dispatch({selection:F.create(n.map(e=>F.range(e.from,e.to))),userEvent:`select.search.matches`}),!0)}),Zr=({state:e,dispatch:t})=>{let n=e.selection;if(n.ranges.length>1||n.main.empty)return!1;let{from:r,to:i}=n.main,a=[],o=0;for(let t=new G(e.doc,e.sliceDoc(r,i));!t.next().done;){if(a.length>1e3)return!1;t.value.from==r&&(o=a.length),a.push(F.range(t.value.from,t.value.to))}return t(e.update({selection:F.create(a,o),userEvent:`select.search.matches`})),!0},Qr=qr((e,{query:t})=>{let{state:n}=e,{from:r,to:i}=n.selection.main;if(n.readOnly)return!1;let a=t.nextMatch(n,r,r);if(!a)return!1;let o=a,s=[],c,l,u=[];o.from==r&&o.to==i&&(l=n.toText(t.getReplacement(o)),s.push({from:o.from,to:o.to,insert:l}),o=t.nextMatch(n,o.from,o.to),u.push(E.announce.of(n.phrase(`replaced match on line $`,n.doc.lineAt(r).number)+`.`)));let d=e.state.changes(s);return o&&(c=F.single(o.from,o.to).map(d),u.push(ui(e,o)),u.push(n.facet(K).scrollToMatch(c.main,e))),e.dispatch({changes:d,selection:c,effects:u,userEvent:`input.replace`}),!0}),$r=qr((e,{query:t})=>{if(e.state.readOnly)return!1;let n=t.matchAll(e.state,1e9).map(e=>{let{from:n,to:r}=e;return{from:n,to:r,insert:t.getReplacement(e)}});if(!n.length)return!1;let r=e.state.phrase(`replaced $ matches`,n.length)+`.`;return e.dispatch({changes:n,effects:E.announce.of(r),userEvent:`input.replace.all`}),!0});function ei(e){return e.state.facet(K).createPanel(e)}function ti(e,t){let n=e.selection.main,r=n.empty||n.to>n.from+100?``:e.sliceDoc(n.from,n.to);if(t&&!r)return t;let i=e.facet(K);return new jr({search:t?.literal??i.literal?r:r.replace(/\n/g,`\\n`),caseSensitive:t?.caseSensitive??i.caseSensitive,literal:t?.literal??i.literal,regexp:t?.regexp??i.regexp,wholeWord:t?.wholeWord??i.wholeWord})}function ni(e){let t=v(e,ei);return t&&t.dom.querySelector(`[main-field]`)}function ri(e){let t=ni(e);t&&t==e.root.activeElement&&t.select()}var ii=e=>{let t=e.state.field(Y,!1);if(t&&t.panel){let n=ni(e);if(n&&n!=e.root.activeElement){let r=ti(e.state,t.query.spec);r.valid&&e.dispatch({effects:Vr.of(r)}),n.focus(),n.select()}}else e.dispatch({effects:[Hr.of(!0),t?Vr.of(ti(e.state,t.query.spec)):P.appendConfig.of(fi)]});return!0},ai=e=>{let t=e.state.field(Y,!1);if(!t||!t.panel)return!1;let n=v(e,ei);return n&&n.dom.contains(e.root.activeElement)&&e.focus(),e.dispatch({effects:Hr.of(!1)}),!0},oi=[{key:`Mod-f`,run:ii,scope:`editor search-panel`},{key:`F3`,run:Jr,shift:Yr,scope:`editor search-panel`,preventDefault:!0},{key:`Mod-g`,run:Jr,shift:Yr,scope:`editor search-panel`,preventDefault:!0},{key:`Escape`,run:ai,scope:`editor search-panel`},{key:`Mod-Shift-l`,run:Zr},{key:`Mod-Alt-g`,run:vr},{key:`Mod-d`,run:Ar,preventDefault:!0}],si=class{constructor(e){this.view=e;let t=this.query=e.state.field(Y).query.spec;this.commit=this.commit.bind(this),this.searchField=x(`input`,{value:t.search,placeholder:X(e,`Find`),"aria-label":X(e,`Find`),class:`cm-textfield`,name:`search`,form:``,"main-field":`true`,onchange:this.commit,onkeyup:this.commit}),this.replaceField=x(`input`,{value:t.replace,placeholder:X(e,`Replace`),"aria-label":X(e,`Replace`),class:`cm-textfield`,name:`replace`,form:``,onchange:this.commit,onkeyup:this.commit}),this.caseField=x(`input`,{type:`checkbox`,name:`case`,form:``,checked:t.caseSensitive,onchange:this.commit}),this.reField=x(`input`,{type:`checkbox`,name:`re`,form:``,checked:t.regexp,onchange:this.commit}),this.wordField=x(`input`,{type:`checkbox`,name:`word`,form:``,checked:t.wholeWord,onchange:this.commit});function n(e,t,n){return x(`button`,{class:`cm-button`,name:e,onclick:t,type:`button`},n)}this.dom=x(`div`,{onkeydown:e=>this.keydown(e),class:`cm-search`},[this.searchField,n(`next`,()=>Jr(e),[X(e,`next`)]),n(`prev`,()=>Yr(e),[X(e,`previous`)]),n(`select`,()=>Xr(e),[X(e,`all`)]),x(`label`,null,[this.caseField,X(e,`match case`)]),x(`label`,null,[this.reField,X(e,`regexp`)]),x(`label`,null,[this.wordField,X(e,`by word`)]),...e.state.readOnly?[]:[x(`br`),this.replaceField,n(`replace`,()=>Qr(e),[X(e,`replace`)]),n(`replaceAll`,()=>$r(e),[X(e,`replace all`)])],x(`button`,{name:`close`,onclick:()=>ai(e),"aria-label":X(e,`close`),type:`button`},[`×`])])}commit(){let e=new jr({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,wholeWord:this.wordField.checked,replace:this.replaceField.value});e.eq(this.query)||(this.query=e,this.view.dispatch({effects:Vr.of(e)}))}keydown(e){y(this.view,e,`search-panel`)?e.preventDefault():e.keyCode==13&&e.target==this.searchField?(e.preventDefault(),(e.shiftKey?Yr:Jr)(this.view)):e.keyCode==13&&e.target==this.replaceField&&(e.preventDefault(),Qr(this.view))}update(e){for(let t of e.transactions)for(let e of t.effects)e.is(Vr)&&!e.value.eq(this.query)&&this.setQuery(e.value)}setQuery(e){this.query=e,this.searchField.value=e.search,this.replaceField.value=e.replace,this.caseField.checked=e.caseSensitive,this.reField.checked=e.regexp,this.wordField.checked=e.wholeWord}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(K).top}};function X(e,t){return e.state.phrase(t)}var ci=30,li=/[\s\.,:;?!]/;function ui(e,{from:t,to:n}){let r=e.state.doc.lineAt(t),i=e.state.doc.lineAt(n).to,a=Math.max(r.from,t-ci),o=Math.min(i,n+ci),s=e.state.sliceDoc(a,o);if(a!=r.from){for(let e=0;e<ci;e++)if(!li.test(s[e+1])&&li.test(s[e])){s=s.slice(e);break}}if(o!=i){for(let e=s.length-1;e>s.length-ci;e--)if(!li.test(s[e-1])&&li.test(s[e])){s=s.slice(0,e);break}}return E.announce.of(`${e.state.phrase(`current match`)}. ${s} ${e.state.phrase(`on line`)} ${r.number}.`)}var di=E.baseTheme({".cm-panel.cm-search":{padding:`2px 6px 4px`,position:`relative`,"& [name=close]":{position:`absolute`,top:`0`,right:`4px`,backgroundColor:`inherit`,border:`none`,font:`inherit`,padding:0,margin:0},"& input, & button, & label":{margin:`.2em .6em .2em 0`},"& input[type=checkbox]":{marginRight:`.2em`},"& label":{fontSize:`80%`,whiteSpace:`pre`}},"&light .cm-searchMatch":{backgroundColor:`#ffff0054`},"&dark .cm-searchMatch":{backgroundColor:`#00ffff8a`},"&light .cm-searchMatch-selected":{backgroundColor:`#ff6a0054`},"&dark .cm-searchMatch-selected":{backgroundColor:`#ff00ff8a`}}),fi=[Y,_e.low(Kr),di],pi=class{constructor(e,t,n){this.from=e,this.to=t,this.diagnostic=n}},mi=class e{constructor(e,t,n){this.diagnostics=e,this.panel=t,this.selected=n}static init(t,n,r){let i=r.facet(Ei).markerFilter;i&&(t=i(t,r));let a=t.slice().sort((e,t)=>e.from-t.from||e.to-t.to),o=new Ee,s=[],c=0,l=r.doc.iter(),u=0,d=r.doc.length;for(let e=0;;){let t=e==a.length?null:a[e];if(!t&&!s.length)break;let n,r;if(s.length)n=c,r=s.reduce((e,t)=>Math.min(e,t.to),t&&t.from>n?t.from:1e8);else{if(n=t.from,n>d)break;r=t.to,s.push(t),e++}for(;e<a.length;){let t=a[e];if(t.from==n&&(t.to>t.from||t.to==n))s.push(t),e++,r=Math.min(t.to,r);else{r=Math.min(t.from,r);break}}r=Math.min(r,d);let i=!1;if(s.some(e=>e.from==n&&(e.to==r||r==d))&&(i=n==r,!i&&r-n<10)){let e=n-(u+l.value.length);e>0&&(l.next(e),u=n);for(let e=n;;){if(e>=r){i=!0;break}if(!l.lineBreak&&u+l.value.length>e)break;e=u+l.value.length,u+=l.value.length,l.next()}}let f=Li(s);if(i)o.add(n,n,_.widget({widget:new Ai(f),diagnostics:s.slice()}));else{let e=s.reduce((e,t)=>t.markClass?e+` `+t.markClass:e,``);o.add(n,r,_.mark({class:`cm-lintRange cm-lintRange-`+f+e,diagnostics:s.slice(),inclusiveEnd:s.some(e=>e.to>r)}))}if(c=r,c==d)break;for(let e=0;e<s.length;e++)s[e].to<=c&&s.splice(e--,1)}let f=o.finish();return new e(f,n,Z(f))}};function Z(e,t=null,n=0){let r=null;return e.between(n,1e9,(e,n,{spec:i})=>{if(!(t&&i.diagnostics.indexOf(t)<0))if(!r)r=new pi(e,n,t||i.diagnostics[0]);else if(i.diagnostics.indexOf(r.diagnostic)<0)return!1;else r=new pi(r.from,n,r.diagnostic)}),r}function hi(e,t){let n=t.pos,r=t.end||n,i=e.state.facet(Ei).hideOn(e,n,r);if(i!=null)return i;let a=e.startState.doc.lineAt(t.pos);return!!(e.effects.some(e=>e.is(_i))||e.changes.touchesRange(a.from,Math.max(a.to,r)))}function gi(e,t){return e.field(Q,!1)?t:t.concat(P.appendConfig.of(Ri))}var _i=P.define(),vi=P.define(),yi=P.define(),Q=ce.define({create(){return new mi(_.none,null,null)},update(e,t){if(t.docChanged&&e.diagnostics.size){let n=e.diagnostics.map(t.changes),r=null,i=e.panel;if(e.selected){let i=t.changes.mapPos(e.selected.from,1);r=Z(n,e.selected.diagnostic,i)||Z(n,null,i)}!n.size&&i&&t.state.facet(Ei).autoPanel&&(i=null),e=new mi(n,i,r)}for(let n of t.effects)if(n.is(_i)){let r=t.state.facet(Ei).autoPanel?n.value.length?Mi.open:null:e.panel;e=mi.init(n.value,r,t.state)}else n.is(vi)?e=new mi(e.diagnostics,n.value?Mi.open:null,e.selected):n.is(yi)&&(e=new mi(e.diagnostics,e.panel,n.value));return e},provide:e=>[ke.from(e,e=>e.panel),E.decorations.from(e,e=>e.diagnostics)]}),bi=_.mark({class:`cm-lintRange cm-lintRange-active`});function xi(e,t,n){let{diagnostics:r}=e.state.field(Q),i,a=-1,o=-1;r.between(t-(n<0?1:0),t+(n>0?1:0),(e,r,{spec:s})=>{if(t>=e&&t<=r&&(e==r||(t>e||n>0)&&(t<r||n<0)))return i=s.diagnostics,a=e,o=r,!1});let s=e.state.facet(Ei).tooltipFilter;return i&&s&&(i=s(i,e.state)),i?{pos:a,end:o,above:e.state.doc.lineAt(a).to<o,create(){return{dom:Si(e,i)}}}:null}function Si(e,t){return x(`ul`,{class:`cm-tooltip-lint`},t.map(t=>ki(e,t,!1)))}var Ci=e=>{let t=e.state.field(Q,!1);(!t||!t.panel)&&e.dispatch({effects:gi(e.state,[vi.of(!0)])});let n=v(e,Mi.open);return n&&n.dom.querySelector(`.cm-panel-lint ul`).focus(),!0},wi=e=>{let t=e.state.field(Q,!1);return!t||!t.panel?!1:(e.dispatch({effects:vi.of(!1)}),!0)},Ti=[{key:`Mod-Shift-m`,run:Ci,preventDefault:!0},{key:`F8`,run:e=>{let t=e.state.field(Q,!1);if(!t)return!1;let n=e.state.selection.main,r=Z(t.diagnostics,null,n.to+1);return!r&&(r=Z(t.diagnostics,null,0),!r||r.from==n.from&&r.to==n.to)?!1:(e.dispatch({selection:{anchor:r.from,head:r.to},scrollIntoView:!0}),!0)}}],Ei=je.define({combine(e){return{sources:e.map(e=>e.source).filter(e=>e!=null),...Oe(e.map(e=>e.config),{delay:750,markerFilter:null,tooltipFilter:null,needsRefresh:null,hideOn:()=>null},{delay:Math.max,markerFilter:Di,tooltipFilter:Di,needsRefresh:(e,t)=>e?t?n=>e(n)||t(n):e:t,hideOn:(e,t)=>e?t?(n,r,i)=>e(n,r,i)||t(n,r,i):e:t,autoPanel:(e,t)=>e||t})}}});function Di(e,t){return e?t?(n,r)=>t(e(n,r),r):e:t}function Oi(e){let t=[];if(e)actions:for(let{name:n}of e){for(let e=0;e<n.length;e++){let r=n[e];if(/[a-zA-Z]/.test(r)&&!t.some(e=>e.toLowerCase()==r.toLowerCase())){t.push(r);continue actions}}t.push(``)}return t}function ki(e,t,n){let r=n?Oi(t.actions):[];return x(`li`,{class:`cm-diagnostic cm-diagnostic-`+t.severity},x(`span`,{class:`cm-diagnosticText`},t.renderMessage?t.renderMessage(e):t.message),t.actions?.map((n,i)=>{let a=!1,o=r=>{if(r.preventDefault(),a)return;a=!0;let i=Z(e.state.field(Q).diagnostics,t);i&&n.apply(e,i.from,i.to)},{name:s}=n,c=r[i]?s.indexOf(r[i]):-1,l=c<0?s:[s.slice(0,c),x(`u`,s.slice(c,c+1)),s.slice(c+1)];return x(`button`,{type:`button`,class:`cm-diagnosticAction`+(n.markClass?` `+n.markClass:``),onclick:o,onmousedown:o,"aria-label":` Action: ${s}${c<0?``:` (access key "${r[i]})"`}.`},l)}),t.source&&x(`div`,{class:`cm-diagnosticSource`},t.source))}var Ai=class extends ve{constructor(e){super(),this.sev=e}eq(e){return e.sev==this.sev}toDOM(){return x(`span`,{class:`cm-lintPoint cm-lintPoint-`+this.sev})}},ji=class{constructor(e,t){this.diagnostic=t,this.id=`item_`+Math.floor(Math.random()*4294967295).toString(16),this.dom=ki(e,t,!0),this.dom.id=this.id,this.dom.setAttribute(`role`,`option`)}},Mi=class e{constructor(e){this.view=e,this.items=[];let t=t=>{if(!(t.ctrlKey||t.altKey||t.metaKey)){if(t.keyCode==27)wi(this.view),this.view.focus();else if(t.keyCode==38||t.keyCode==33)this.moveSelection((this.selectedIndex-1+this.items.length)%this.items.length);else if(t.keyCode==40||t.keyCode==34)this.moveSelection((this.selectedIndex+1)%this.items.length);else if(t.keyCode==36)this.moveSelection(0);else if(t.keyCode==35)this.moveSelection(this.items.length-1);else if(t.keyCode==13)this.view.focus();else if(t.keyCode>=65&&t.keyCode<=90&&this.selectedIndex>=0){let{diagnostic:n}=this.items[this.selectedIndex],r=Oi(n.actions);for(let i=0;i<r.length;i++)if(r[i].toUpperCase().charCodeAt(0)==t.keyCode){let t=Z(this.view.state.field(Q).diagnostics,n);t&&n.actions[i].apply(e,t.from,t.to)}}else return;t.preventDefault()}},n=e=>{for(let t=0;t<this.items.length;t++)this.items[t].dom.contains(e.target)&&this.moveSelection(t)};this.list=x(`ul`,{tabIndex:0,role:`listbox`,"aria-label":this.view.state.phrase(`Diagnostics`),onkeydown:t,onclick:n}),this.dom=x(`div`,{class:`cm-panel-lint`},this.list,x(`button`,{type:`button`,name:`close`,"aria-label":this.view.state.phrase(`close`),onclick:()=>wi(this.view)},`×`)),this.update()}get selectedIndex(){let e=this.view.state.field(Q).selected;if(!e)return-1;for(let t=0;t<this.items.length;t++)if(this.items[t].diagnostic==e.diagnostic)return t;return-1}update(){let{diagnostics:e,selected:t}=this.view.state.field(Q),n=0,r=!1,i=null,a=new Set;for(e.between(0,this.view.state.doc.length,(e,o,{spec:s})=>{for(let e of s.diagnostics){if(a.has(e))continue;a.add(e);let o=-1,s;for(let t=n;t<this.items.length;t++)if(this.items[t].diagnostic==e){o=t;break}o<0?(s=new ji(this.view,e),this.items.splice(n,0,s),r=!0):(s=this.items[o],o>n&&(this.items.splice(n,o-n),r=!0)),t&&s.diagnostic==t.diagnostic?s.dom.hasAttribute(`aria-selected`)||(s.dom.setAttribute(`aria-selected`,`true`),i=s):s.dom.hasAttribute(`aria-selected`)&&s.dom.removeAttribute(`aria-selected`),n++}});n<this.items.length&&!(this.items.length==1&&this.items[0].diagnostic.from<0);)r=!0,this.items.pop();this.items.length==0&&(this.items.push(new ji(this.view,{from:-1,to:-1,severity:`info`,message:this.view.state.phrase(`No diagnostics`)})),r=!0),i?(this.list.setAttribute(`aria-activedescendant`,i.id),this.view.requestMeasure({key:this,read:()=>({sel:i.dom.getBoundingClientRect(),panel:this.list.getBoundingClientRect()}),write:({sel:e,panel:t})=>{let n=t.height/this.list.offsetHeight;e.top<t.top?this.list.scrollTop-=(t.top-e.top)/n:e.bottom>t.bottom&&(this.list.scrollTop+=(e.bottom-t.bottom)/n)}})):this.selectedIndex<0&&this.list.removeAttribute(`aria-activedescendant`),r&&this.sync()}sync(){let e=this.list.firstChild;function t(){let t=e;e=t.nextSibling,t.remove()}for(let n of this.items)if(n.dom.parentNode==this.list){for(;e!=n.dom;)t();e=n.dom.nextSibling}else this.list.insertBefore(n.dom,e);for(;e;)t()}moveSelection(e){if(this.selectedIndex<0)return;let t=Z(this.view.state.field(Q).diagnostics,this.items[e].diagnostic);t&&this.view.dispatch({selection:{anchor:t.from,head:t.to},scrollIntoView:!0,effects:yi.of(t)})}static open(t){return new e(t)}};function Ni(e,t=`viewBox="0 0 40 40"`){return`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" ${t}>${encodeURIComponent(e)}</svg>')`}function Pi(e){return Ni(`<path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="${e}" fill="none" stroke-width=".7"/>`,`width="6" height="3"`)}var Fi=E.baseTheme({".cm-diagnostic":{padding:`3px 6px 3px 8px`,marginLeft:`-1px`,display:`block`,whiteSpace:`pre-wrap`},".cm-diagnostic-error":{borderLeft:`5px solid #d11`},".cm-diagnostic-warning":{borderLeft:`5px solid orange`},".cm-diagnostic-info":{borderLeft:`5px solid #999`},".cm-diagnostic-hint":{borderLeft:`5px solid #66d`},".cm-diagnosticAction":{font:`inherit`,border:`none`,padding:`2px 4px`,backgroundColor:`#444`,color:`white`,borderRadius:`3px`,marginLeft:`8px`,cursor:`pointer`},".cm-diagnosticSource":{fontSize:`70%`,opacity:.7},".cm-lintRange":{backgroundPosition:`left bottom`,backgroundRepeat:`repeat-x`,paddingBottom:`0.7px`},".cm-lintRange-error":{backgroundImage:Pi(`#d11`)},".cm-lintRange-warning":{backgroundImage:Pi(`orange`)},".cm-lintRange-info":{backgroundImage:Pi(`#999`)},".cm-lintRange-hint":{backgroundImage:Pi(`#66d`)},".cm-lintRange-active":{backgroundColor:`#ffdd9980`},".cm-tooltip-lint":{padding:0,margin:0},".cm-lintPoint":{position:`relative`,"&:after":{content:`""`,position:`absolute`,bottom:0,left:`-2px`,borderLeft:`3px solid transparent`,borderRight:`3px solid transparent`,borderBottom:`4px solid #d11`}},".cm-lintPoint-warning":{"&:after":{borderBottomColor:`orange`}},".cm-lintPoint-info":{"&:after":{borderBottomColor:`#999`}},".cm-lintPoint-hint":{"&:after":{borderBottomColor:`#66d`}},".cm-panel.cm-panel-lint":{position:`relative`,"& ul":{maxHeight:`100px`,overflowY:`auto`,"& [aria-selected]":{backgroundColor:`#ddd`,"& u":{textDecoration:`underline`}},"&:focus [aria-selected]":{background_fallback:`#bdf`,backgroundColor:`Highlight`,color_fallback:`white`,color:`HighlightText`},"& u":{textDecoration:`none`},padding:0,margin:0},"& [name=close]":{position:`absolute`,top:`0`,right:`2px`,background:`inherit`,border:`none`,font:`inherit`,padding:0,margin:0}},"&dark .cm-lintRange-active":{backgroundColor:`#86714a80`},"&dark .cm-panel.cm-panel-lint ul":{"& [aria-selected]":{backgroundColor:`#2e343e`}}});function Ii(e){return e==`error`?4:e==`warning`?3:e==`info`?2:1}function Li(e){let t=`hint`,n=1;for(let r of e){let e=Ii(r.severity);e>n&&(n=e,t=r.severity)}return t}var Ri=[Q,E.decorations.compute([Q],e=>{let{selected:t,panel:n}=e.field(Q);return!t||!n||t.from==t.to?_.none:_.set([bi.range(t.from,t.to)])}),m(xi,{hideOn:hi}),Fi],zi=function(e){e===void 0&&(e={});var{crosshairCursor:t=!1}=e,n=[];e.closeBracketsKeymap!==!1&&(n=n.concat(Pe)),e.defaultKeymap!==!1&&(n=n.concat(sr)),e.searchKeymap!==!1&&(n=n.concat(oi)),e.historyKeymap!==!1&&(n=n.concat(wt)),e.foldKeymap!==!1&&(n=n.concat(pe)),e.completionKeymap!==!1&&(n=n.concat(le)),e.lintKeymap!==!1&&(n=n.concat(Ti));var r=[];return e.lineNumbers!==!1&&r.push(b()),e.highlightActiveLineGutter!==!1&&r.push(k()),e.highlightSpecialChars!==!1&&r.push(Be()),e.history!==!1&&r.push(st()),e.foldGutter!==!1&&r.push(he()),e.drawSelection!==!1&&r.push(T()),e.dropCursor!==!1&&r.push(D()),e.allowMultipleSelections!==!1&&r.push(we.allowMultipleSelections.of(!0)),e.indentOnInput!==!1&&r.push(ze()),e.syntaxHighlighting!==!1&&r.push(h(xe,{fallback:!0})),e.bracketMatching!==!1&&r.push(De()),e.closeBrackets!==!1&&r.push(ye()),e.autocompletion!==!1&&r.push(se()),e.rectangularSelection!==!1&&r.push(te()),t!==!1&&r.push(w()),e.highlightActiveLine!==!1&&r.push(C()),e.highlightSelectionMatches!==!1&&r.push(xr()),e.tabSize&&typeof e.tabSize==`number`&&r.push(Re.of(` `.repeat(e.tabSize))),r.concat([M.of(n.flat())]).filter(Boolean)},Bi=E.theme({"&":{backgroundColor:`#fff`}},{dark:!1}),Vi=function(e){e===void 0&&(e={});var{indentWithTab:t=!0,editable:n=!0,readOnly:r=!1,theme:i=`light`,placeholder:a=``,basicSetup:o=!0}=e,s=[];switch(t&&s.unshift(M.of([cr])),o&&(typeof o==`boolean`?s.unshift(zi()):s.unshift(zi(o))),a&&s.unshift(ee(a)),i){case`light`:s.push(Bi);break;case`dark`:s.push(Me);break;case`none`:break;default:s.push(i);break}return n===!1&&s.push(E.editable.of(!1)),r&&s.push(we.readOnly.of(!0)),[...s]},Hi=e=>({line:e.state.doc.lineAt(e.state.selection.main.from),lineCount:e.state.doc.lines,lineBreak:e.state.lineBreak,length:e.state.doc.length,readOnly:e.state.readOnly,tabSize:e.state.tabSize,selection:e.state.selection,selectionAsSingle:e.state.selection.asSingle().main,ranges:e.state.selection.ranges,selectionCode:e.state.sliceDoc(e.state.selection.main.from,e.state.selection.main.to),selections:e.state.selection.ranges.map(t=>e.state.sliceDoc(t.from,t.to)),selectedText:e.state.selection.ranges.some(e=>!e.empty)}),Ui=class{constructor(e,t){this.timeLeftMS=void 0,this.timeoutMS=void 0,this.isCancelled=!1,this.isTimeExhausted=!1,this.callbacks=[],this.timeLeftMS=t,this.timeoutMS=t,this.callbacks.push(e)}tick(){if(!this.isCancelled&&!this.isTimeExhausted&&(this.timeLeftMS--,this.timeLeftMS<=0)){this.isTimeExhausted=!0;var e=this.callbacks.slice();this.callbacks.length=0,e.forEach(e=>{try{e()}catch(e){console.error(`TimeoutLatch callback error:`,e)}})}}cancel(){this.isCancelled=!0,this.callbacks.length=0}reset(){this.timeLeftMS=this.timeoutMS,this.isCancelled=!1,this.isTimeExhausted=!1}get isDone(){return this.isCancelled||this.isTimeExhausted}},Wi=class{constructor(){this.interval=null,this.latches=new Set}add(e){this.latches.add(e),this.start()}remove(e){this.latches.delete(e),this.latches.size===0&&this.stop()}start(){this.interval===null&&(this.interval=setInterval(()=>{this.latches.forEach(e=>{e.tick(),e.isDone&&this.remove(e)})},1))}stop(){this.interval!==null&&(clearInterval(this.interval),this.interval=null)}},Gi=null,Ki=()=>typeof window>`u`?new Wi:(Gi||=new Wi,Gi),qi=ne.define(),Ji=200,Yi=[];function Xi(e){var{value:t,selection:n,onChange:r,onStatistics:i,onCreateEditor:a,onUpdate:o,extensions:s=Yi,autoFocus:c,theme:l=`light`,height:u=null,minHeight:d=null,maxHeight:f=null,width:p=null,minWidth:m=null,maxWidth:h=null,placeholder:g=``,editable:_=!0,readOnly:v=!1,indentWithTab:y=!0,basicSetup:b=!0,root:x,initialState:S}=e,[C,w]=(0,I.useState)(),[T,D]=(0,I.useState)(),[O,k]=(0,I.useState)(),A=(0,I.useState)(()=>({current:null}))[0],j=(0,I.useState)(()=>({current:null}))[0],ee=E.theme({"&":{height:u,minHeight:d,maxHeight:f,width:p,minWidth:m,maxWidth:h},"& .cm-scroller":{height:`100% !important`}}),M=[E.updateListener.of(e=>{e.docChanged&&typeof r==`function`&&!e.transactions.some(e=>e.annotation(qi))&&(A.current?A.current.reset():(A.current=new Ui(()=>{if(j.current){var e=j.current;j.current=null,e()}A.current=null},Ji),Ki().add(A.current)),r(e.state.doc.toString(),e)),i&&i(Hi(e))}),ee,...Vi({theme:l,editable:_,readOnly:v,placeholder:g,indentWithTab:y,basicSetup:b})];return o&&typeof o==`function`&&M.push(E.updateListener.of(o)),M=M.concat(s),(0,I.useLayoutEffect)(()=>{if(C&&!O){var e={doc:t,selection:n,extensions:M},r=S?we.fromJSON(S.json,e,S.fields):we.create(e);if(k(r),!T){var i=new E({state:r,parent:C,root:x});D(i),a&&a(i,r)}}return()=>{T&&(k(void 0),D(void 0))}},[C,O]),(0,I.useEffect)(()=>{e.container&&w(e.container)},[e.container]),(0,I.useEffect)(()=>()=>{T&&(T.destroy(),D(void 0)),A.current&&=(A.current.cancel(),null)},[T]),(0,I.useEffect)(()=>{c&&T&&T.focus()},[c,T]),(0,I.useEffect)(()=>{T&&T.dispatch({effects:P.reconfigure.of(M)})},[l,s,u,d,f,p,m,h,g,_,v,y,b,r,o]),(0,I.useEffect)(()=>{if(t!==void 0){var e=T?T.state.doc.toString():``;if(T&&t!==e){var n=A.current&&!A.current.isDone,r=()=>{T&&t!==T.state.doc.toString()&&T.dispatch({changes:{from:0,to:T.state.doc.toString().length,insert:t||``},annotations:[qi.of(!0)]})};n?j.current=r:r()}}},[t,T]),{state:O,setState:k,view:T,setView:D,container:C,setContainer:w}}var $=r(),Zi=[`className`,`value`,`selection`,`extensions`,`onChange`,`onStatistics`,`onCreateEditor`,`onUpdate`,`autoFocus`,`theme`,`height`,`minHeight`,`maxHeight`,`width`,`minWidth`,`maxWidth`,`basicSetup`,`placeholder`,`indentWithTab`,`editable`,`readOnly`,`root`,`initialState`],Qi=(0,I.forwardRef)((e,t)=>{var{className:n,value:r=``,selection:i,extensions:a=[],onChange:o,onStatistics:s,onCreateEditor:c,onUpdate:l,autoFocus:u,theme:d=`light`,height:f,minHeight:p,maxHeight:m,width:h,minWidth:g,maxWidth:_,basicSetup:v,placeholder:y,indentWithTab:b,editable:x,readOnly:S,root:C,initialState:w}=e,T=We(e,Zi),E=(0,I.useRef)(null),{state:D,view:O,container:k,setContainer:A}=Xi({root:C,value:r,autoFocus:u,theme:d,height:f,minHeight:p,maxHeight:m,width:h,minWidth:g,maxWidth:_,basicSetup:v,placeholder:y,indentWithTab:b,editable:x,readOnly:S,selection:i,onChange:o,onStatistics:s,onCreateEditor:c,onUpdate:l,extensions:a,initialState:w});(0,I.useImperativeHandle)(t,()=>({editor:E.current,state:D,view:O}),[E,k,D,O]);var j=(0,I.useCallback)(e=>{E.current=e,A(e)},[A]);if(typeof r!=`string`)throw Error(`value must be typeof string but got `+typeof r);return(0,$.jsx)(`div`,Ue({ref:j,className:(typeof d==`string`?`cm-theme-`+d:`cm-theme`)+(n?` `+n:``)},T))});Qi.displayName=`CodeMirror`;var $i=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`ico`]),ea=`pdf`;function ta(e){return e.split(`.`).pop()?.toLowerCase()??``}function na(e){switch(ta(e)){case`js`:case`jsx`:return Te({jsx:!0});case`ts`:case`tsx`:return Te({jsx:!0,typescript:!0});case`py`:return ae();case`html`:return Ae();case`css`:case`scss`:return ge();case`json`:return Ce();case`md`:case`mdx`:return Ne();default:return null}}function ra({metadata:e,tabId:t}){let n=e?.filePath,r=e?.projectName,[a,o]=(0,I.useState)(null),[s,f]=(0,I.useState)(`utf-8`),[p,m]=(0,I.useState)(!0),[h,g]=(0,I.useState)(null),[_,v]=(0,I.useState)(!1),y=(0,I.useRef)(null),b=(0,I.useRef)(``),{tabs:x,updateTab:S}=d(),C=x.find(e=>e.id===t),w=n?ta(n):``,T=$i.has(w),E=w===ea,D=w===`md`||w===`mdx`,[O,k]=(0,I.useState)(`preview`);(0,I.useEffect)(()=>{if(!(!n||!r)){if(T||E){m(!1);return}return m(!0),g(null),l.get(`${c(r)}/files/read?path=${encodeURIComponent(n)}`).then(e=>{o(e.content),f(e.encoding),b.current=e.content,m(!1)}).catch(e=>{g(e instanceof Error?e.message:`Failed to load file`),m(!1)}),()=>{y.current&&clearTimeout(y.current)}}},[n,r,T,E]),(0,I.useEffect)(()=>{if(!C)return;let e=n?.split(`/`).pop()??`Untitled`,t=_?`${e} \u25CF`:e;C.title!==t&&S(C.id,{title:t})},[_]);let A=(0,I.useCallback)(async e=>{if(!(!n||!r))try{await l.put(`${c(r)}/files/write`,{path:n,content:e}),v(!1)}catch{}},[n,r]);function j(e){o(e),b.current=e,v(!0),y.current&&clearTimeout(y.current),y.current=setTimeout(()=>{A(b.current)},1e3)}if(!n||!r)return(0,$.jsx)(`div`,{className:`flex items-center justify-center h-full text-text-secondary text-sm`,children:`No file selected.`});if(p)return(0,$.jsxs)(`div`,{className:`flex items-center justify-center h-full gap-2 text-text-secondary`,children:[(0,$.jsx)(u,{className:`size-5 animate-spin`}),(0,$.jsx)(`span`,{className:`text-sm`,children:`Loading file...`})]});if(h)return(0,$.jsx)(`div`,{className:`flex items-center justify-center h-full text-error text-sm`,children:h});if(T)return(0,$.jsx)(aa,{filePath:n,projectName:r});if(E)return(0,$.jsx)(oa,{filePath:n,projectName:r});if(s===`base64`)return(0,$.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,$.jsx)(He,{className:`size-10 text-text-subtle`}),(0,$.jsx)(`p`,{className:`text-sm`,children:`This file is a binary format and cannot be displayed.`}),(0,$.jsx)(`p`,{className:`text-xs text-text-subtle`,children:n})]});let ee=[],M=na(n);M&&ee.push(M);let te=D?(0,$.jsxs)(`div`,{className:`flex items-center gap-1 px-2 py-1 border-border shrink-0 bg-background`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>k(`edit`),className:`flex items-center gap-1 px-2 py-1 rounded text-xs transition-colors ${O===`edit`?`bg-muted text-foreground`:`text-muted-foreground hover:text-foreground`}`,children:[(0,$.jsx)(i,{className:`size-3`}),`Edit`]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>k(`preview`),className:`flex items-center gap-1 px-2 py-1 rounded text-xs transition-colors ${O===`preview`?`bg-muted text-foreground`:`text-muted-foreground hover:text-foreground`}`,children:[(0,$.jsx)(Ve,{className:`size-3`}),`Preview`]})]}):null;return(0,$.jsxs)(`div`,{className:`flex flex-col h-full w-full overflow-hidden`,children:[(0,$.jsx)(`div`,{className:`hidden md:block border-b`,children:te}),D&&O===`preview`?(0,$.jsx)(ia,{content:a??``}):(0,$.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:(0,$.jsx)(Qi,{value:a??``,onChange:j,extensions:ee,theme:Me,height:`100%`,style:{height:`100%`,fontSize:`13px`,fontFamily:`var(--font-mono)`},basicSetup:{lineNumbers:!0,foldGutter:!0,autocompletion:!0,bracketMatching:!0,closeBrackets:!0,highlightActiveLine:!0,indentOnInput:!0}})}),(0,$.jsx)(`div`,{className:`md:hidden border-t`,children:te})]})}function ia({content:e}){return(0,$.jsx)(`div`,{className:`flex-1 overflow-auto p-4 markdown-content prose-sm`,dangerouslySetInnerHTML:{__html:(0,I.useMemo)(()=>{try{return a.parse(e,{gfm:!0,breaks:!0})}catch{return e}},[e])}})}function aa({filePath:e,projectName:t}){let[n,r]=(0,I.useState)(null),[i,a]=(0,I.useState)(!1);return(0,I.useEffect)(()=>{let n,i=`${c(t)}/files/raw?path=${encodeURIComponent(e)}`,o=s();return fetch(i,{headers:o?{Authorization:`Bearer ${o}`}:{}}).then(e=>{if(!e.ok)throw Error(`Failed`);return e.blob()}).then(e=>{let t=URL.createObjectURL(e);n=t,r(t)}).catch(()=>a(!0)),()=>{n&&URL.revokeObjectURL(n)}},[e,t]),i?(0,$.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,$.jsx)(He,{className:`size-10 text-text-subtle`}),(0,$.jsx)(`p`,{className:`text-sm`,children:`Failed to load image.`})]}):n?(0,$.jsx)(`div`,{className:`flex items-center justify-center h-full p-4 bg-surface overflow-auto`,children:(0,$.jsx)(`img`,{src:n,alt:e,className:`max-w-full max-h-full object-contain`})}):(0,$.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,$.jsx)(u,{className:`size-5 animate-spin text-text-subtle`})})}function oa({filePath:e,projectName:t}){let[n,r]=(0,I.useState)(null),[i,a]=(0,I.useState)(!1);(0,I.useEffect)(()=>{let n,i=`${c(t)}/files/raw?path=${encodeURIComponent(e)}`,o=s();return fetch(i,{headers:o?{Authorization:`Bearer ${o}`}:{}}).then(e=>{if(!e.ok)throw Error(`Failed`);return e.blob()}).then(e=>{let t=URL.createObjectURL(new Blob([e],{type:`application/pdf`}));n=t,r(t)}).catch(()=>a(!0)),()=>{n&&URL.revokeObjectURL(n)}},[e,t]);let l=(0,I.useCallback)(()=>{n&&window.open(n,`_blank`)},[n]);return i?(0,$.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,$.jsx)(He,{className:`size-10 text-text-subtle`}),(0,$.jsx)(`p`,{className:`text-sm`,children:`Failed to load PDF.`})]}):n?(0,$.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-1.5 border-b border-border bg-background shrink-0`,children:[(0,$.jsx)(`span`,{className:`text-xs text-text-secondary truncate`,children:e}),(0,$.jsxs)(`button`,{onClick:l,className:`flex items-center gap-1 text-xs text-text-secondary hover:text-text-primary transition-colors`,children:[(0,$.jsx)(o,{className:`size-3`}),`Open in new tab`]})]}),(0,$.jsx)(`iframe`,{src:n,title:e,className:`flex-1 w-full border-none`})]}):(0,$.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,$.jsx)(u,{className:`size-5 animate-spin text-text-subtle`})})}export{ra as CodeEditor};
|