@spexcode/spec-dashboard 0.7.0-next.1 → 0.7.0-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{App-BBoP1IyU.js → App-DYT3vIqP.js} +2 -2
- package/{dist-public/assets/EmptyView-BdrTMUAy.js → dist/assets/EmptyView-DXv-3Vi6.js} +1 -1
- package/{dist-public/assets/EvalsPage-DIfyOQXb.js → dist/assets/EvalsPage-DnqAjyfu.js} +1 -1
- package/dist/assets/{FileView-BqSwsBx0.js → FileView-Ky36PD82.js} +2 -2
- package/dist/assets/{GraphView-DmtM56Gf.js → GraphView-BvMh1fxd.js} +3 -3
- package/dist/assets/{IssuesPage-BZ36PpJ-.js → IssuesPage-o2vddaI6.js} +1 -1
- package/dist/assets/{MobileApp-DuXKCmKv.js → MobileApp-BpxEZ2v5.js} +2 -2
- package/dist/assets/{Modal-oF4JAL6H.js → Modal-B5_IjGMa.js} +1 -1
- package/dist/assets/{NodeView-CZYwYCCu.js → NodeView-CmbCDI2Y.js} +1 -1
- package/{dist-public/assets/ProjectsPage-Ctzz8z3E.js → dist/assets/ProjectsPage-CgdGHve4.js} +1 -1
- package/dist/assets/{ProseActions-CSG_3k1b.js → ProseActions-Dkx3P_qH.js} +1 -1
- package/dist/assets/{Settings-qIX2_HmP.js → Settings-DMBJWtL1.js} +1 -1
- package/dist/assets/{SpecView-CM3BOtTy.js → SpecView-p-_SoBZr.js} +1 -1
- package/{dist-public/assets/Thread-UIOe-Brh.js → dist/assets/Thread-C1g83eTx.js} +1 -1
- package/dist/assets/{WorkspaceSurface-BysfRmg3.js → WorkspaceSurface-BDOIUi8k.js} +1 -1
- package/dist/assets/{index-Co8kmYQY.js → index-46VMgJJ4.js} +1 -1
- package/dist/assets/{index-cI0gAOhx.js → index-CgZDxhet.js} +1 -1
- package/dist/assets/{tabs-C4phsoFs.js → tabs-Bvj-BhvS.js} +5 -5
- package/dist/index.html +1 -1
- package/dist-public/assets/{App-DI39ygL3.js → App-CDdmrKFq.js} +2 -2
- package/{dist/assets/EmptyView-DvUslJmJ.js → dist-public/assets/EmptyView-DRdZkhRg.js} +1 -1
- package/{dist/assets/EvalsPage-DBVkF_F0.js → dist-public/assets/EvalsPage-CBY68cBl.js} +1 -1
- package/dist-public/assets/{FileView-BmDYhU9C.js → FileView-DqnTViYx.js} +2 -2
- package/dist-public/assets/{GraphView-nuH0yFnk.js → GraphView-BJZFYfsi.js} +3 -3
- package/dist-public/assets/{IssuesPage-0kQamj5x.js → IssuesPage-DKmph_qG.js} +1 -1
- package/dist-public/assets/{MobileApp-DxiBJpdL.js → MobileApp-BFjt38EF.js} +2 -2
- package/dist-public/assets/{Modal-DvHG_lvi.js → Modal-BBcXFZSm.js} +1 -1
- package/dist-public/assets/{NodeView-BQwIXw15.js → NodeView-B1bLcqBp.js} +1 -1
- package/{dist/assets/ProjectsPage-DUpxEHcM.js → dist-public/assets/ProjectsPage-CFdwq3E1.js} +1 -1
- package/dist-public/assets/{ProseActions-3FcAR01Y.js → ProseActions-DjJjWzCZ.js} +1 -1
- package/dist-public/assets/{Settings-GX7a1idU.js → Settings-gD1FYaqA.js} +1 -1
- package/dist-public/assets/{SpecView-OcNkvuaj.js → SpecView-DMl6Tici.js} +1 -1
- package/{dist/assets/Thread-4tohzgUo.js → dist-public/assets/Thread-BNw463gn.js} +1 -1
- package/dist-public/assets/{WorkspaceSurface-r01RoZft.js → WorkspaceSurface-D698lLJt.js} +1 -1
- package/dist-public/assets/{index-Ix7HFN0I.js → index-BtwC9HM0.js} +1 -1
- package/dist-public/assets/{index-DkZ_7FOT.js → index-CTgHFYup.js} +1 -1
- package/dist-public/assets/{tabs-Dv9P0FBJ.js → tabs-Di_VWVhW.js} +5 -5
- package/dist-public/index.html +1 -1
- package/package.json +5 -5
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-
|
|
2
|
-
import{v as N5,u as He,r as k,m as Di,j as p,I as je,w as L5,x as O5,a as Zt,y as h4,z as P5,A as F5,B as I5,D as z5,E as j5,C as d4,F as H5,G as f4,H as $5,J as p4,k as Hi,K as Yo,_ as Gs,L as q5,M as W5,O as K5,N as V5,Q as U5,e as G5,n as Y5,R as X5,T as e0,i as J5,o as Q1,U as Z5,W as Q5,X as e_}from"./index-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-CgZDxhet.js","assets/index-46VMgJJ4.js","assets/index-B948v2sT.css","assets/App-DYT3vIqP.js","assets/Modal-B5_IjGMa.js","assets/GraphView-BvMh1fxd.js","assets/NodeView-CmbCDI2Y.js","assets/Thread-C1g83eTx.js","assets/ProseActions-Dkx3P_qH.js","assets/GraphStats-CxHsXNy-.js","assets/GraphView-BnuhLJ6X.css","assets/SpecView-p-_SoBZr.js","assets/FileView-Ky36PD82.js","assets/EvalsPage-DnqAjyfu.js","assets/IssuesPage-o2vddaI6.js","assets/Settings-DMBJWtL1.js","assets/EmptyView-DXv-3Vi6.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{v as N5,u as He,r as k,m as Di,j as p,I as je,w as L5,x as O5,a as Zt,y as h4,z as P5,A as F5,B as I5,D as z5,E as j5,C as d4,F as H5,G as f4,H as $5,J as p4,k as Hi,K as Yo,_ as Gs,L as q5,M as W5,O as K5,N as V5,Q as U5,e as G5,n as Y5,R as X5,T as e0,i as J5,o as Q1,U as Z5,W as Q5,X as e_}from"./index-46VMgJJ4.js";import{b as ni,r as Vt,i as t_,n as wn,p as bf,s as ep,f as i_,d as _f,j as r_,k as s_,u as yf,a as m4,l as g4,m as n_,e as wf,c as v4,h as o_}from"./App-DYT3vIqP.js";import{i as wa,P as ru,M as ua}from"./Modal-B5_IjGMa.js";const Hr=t=>{var e;return(t==null?void 0:t.title)||(t==null?void 0:t.headline)||(t==null?void 0:t.name)||(t==null?void 0:t.activity)||(t==null?void 0:t.note)||(t==null?void 0:t.promptPreview)||(t==null?void 0:t.node)||((e=t==null?void 0:t.raw)==null?void 0:e.title)||(t==null?void 0:t.branch)||(t==null?void 0:t.id)},b4=t=>(t==null?void 0:t.label)||(t==null?void 0:t.name)||(t==null?void 0:t.node)||(t==null?void 0:t.title)||(t==null?void 0:t.branch)||(t==null?void 0:t.id);/**
|
|
3
3
|
* Copyright (c) 2014-2024 The xterm.js authors. All rights reserved.
|
|
4
4
|
* @license MIT
|
|
5
5
|
*
|
|
@@ -313,7 +313,7 @@ l0,-`+(i+144)+`c-2,-159.3,-10,-310.7,-24,-454c-53.3,-528,-210,-949.7,
|
|
|
313
313
|
`).trim();if(c<0||!h)return!1;if(s)return!0;const d=e.push("prose_math_block","math",0);return d.block=!0,d.content=h,d.map=[i,c+1],d.markup=a,e.line=c+1,!0},{alt:["paragraph","reference","blockquote","list"]})},tC=t=>{t.inline.ruler.before("link","prose_evidence",(e,i)=>{const r=e.src.slice(e.pos),s=/^!\[([^\]]*)\]\((\/api\/(?:evidence|yatsu\/blob)\/[0-9a-f]{64})(?:\s+["']([^"']*)["'])?\)/i.exec(r);if(!s)return!1;if(!i){const n=e.push("prose_evidence","a",0);n.content=s[1],n.meta={hash:Qk(s[2]),src:s[2],alt:s[1],title:s[3]||null}}return e.pos+=s[0].length,!0}),t.inline.ruler.before("text","prose_spec_ref",(e,i)=>{if(!e.src.startsWith("[[",e.pos))return!1;const r=e.src.indexOf("]]",e.pos+2);if(r<0||r===e.pos+2||e.src.slice(e.pos+2,r).includes(`
|
|
314
314
|
`))return!1;if(!i){const s=e.src.slice(e.pos+2,r),n=e.push("prose_spec_ref","a",0);n.content=s,n.meta={id:s}}return e.pos=r+2,!0}),t.block.ruler.before("paragraph","prose_time_anchor",(e,i,r,s)=>{var c;const n=e.bMarks[i]+e.tShift[i],o=e.eMarks[i],a=e.src.slice(n,o).trim(),l=/^▶\s*(\d+):([0-5]?\d)(?:\s*·\s*([^\n]*))?$/.exec(a);if(!l)return!1;if(s)return!0;const u=e.push("prose_time_anchor","span",0);return u.block=!0,u.content=a,u.map=[i,i+1],u.meta={tMs:(Number(l[1])*60+Number(l[2]))*1e3,step:((c=l[3])==null?void 0:c.trim())||null,label:a},e.line=i+1,!0})},iC=new sr({linkify:!0,html:!1}).use(eC).use(tC),rC=t=>{for(const e of t)if(!(e.type!=="inline"||!e.children||!e.map))for(const i of e.children)i.map||(i.map=[...e.map]);return t};function sC(t){const e=t==null?"":String(t);return rC(iC.parse(e,{}))}function yR(t){const e=t==null?"":String(t),i=/^#\s+[^\n]*(?:\n+|$)/.exec(e);if(!i)return{source:e,removedLines:0};const r=i[0].endsWith(`
|
|
315
315
|
`)?i[0].split(`
|
|
316
|
-
`).length-1:1;return{source:e.slice(i[0].length),removedLines:r}}const I3=t=>/^(?:https?:|mailto:|#|\/)/i.test(String(t||""))?String(t):null,Ei=(t,e)=>{const i=t==null?void 0:t.map;return!i||!Number.isInteger(e)||e<=0?{}:{"data-l0":e+i[0],"data-l1":e+i[1]-1}},Sn=(t,e)=>{var i;return((i=t==null?void 0:t.attrGet)==null?void 0:i.call(t,e))??null},ag=t=>{if(!t)return;const e={};for(const i of String(t).split(";")){const r=i.indexOf(":");if(r<0)continue;const s=i.slice(0,r).trim(),n=i.slice(r+1).trim();if(!s||!n)continue;const o=s.startsWith("--")?s:s.replace(/-([a-z])/g,(a,l)=>l.toUpperCase());e[o]=n}return Object.keys(e).length?e:void 0},qo=new Map,nC=512,oC=(t,e)=>{const i=`${e?"d":"i"}\0${t}`;if(qo.has(i))return qo.get(i);let r=null;try{r=Xk.renderToString(t,{...Jk,displayMode:e})}catch{r=null}return qo.size>=nC&&qo.clear(),qo.set(i,r),r},z3=(t,e,i,r={})=>{const s=oC(e.content,i);return s===null?t(i?"pre":"span",{...r,className:"doc-math-error"},e.content):t(i?"div":"span",{...r,className:i?"doc-math-block":"doc-math","data-math-source":e.content,dangerouslySetInnerHTML:{__html:s}})},lg=(t,e,i,r)=>{const s=Ei(e,r.lineBase);if(e.type==="link_open"){const n=I3(Sn(e,"href"));return n?t("a",{...s,className:"doc-link doc-external",href:n,target:"_blank",rel:"noreferrer"},i):i}return e.type==="strong_open"?t("strong",s,i):e.type==="em_open"?t("em",s,i):e.type==="s_open"?t("del",s,i):i},aC=(t,e=[],i)=>{var o,a;const r=[],s=[{token:null,children:r}],n=()=>s[s.length-1].children;for(const l of e)if(l.type==="text")n().push(l.content);else if(l.type==="hardbreak")n().push(t("br"));else if(l.type==="softbreak")n().push(i.softBreak==="break"?t("br"):" ");else if(l.type==="code_inline")n().push(t("code",Ei(l,i.lineBase),l.content));else if(l.type==="prose_math_inline")n().push(z3(t,l,!1,Ei(l,i.lineBase)));else if(l.type==="prose_spec_ref"){const u=(o=i.renderSpecRef)==null?void 0:o.call(i,l.meta.id,l,Ei(l,i.lineBase));n().push(u??t("span",{...Ei(l,i.lineBase),className:"doc-ref","data-spec-id":l.meta.id},l.meta.id))}else if(l.type==="prose_evidence"){const u=(a=i.renderEvidence)==null?void 0:a.call(i,l.meta,l,Ei(l,i.lineBase));n().push(u??t("a",{...Ei(l,i.lineBase),className:"doc-evidence",href:l.meta.src,"data-evidence-hash":l.meta.hash},l.meta.alt))}else if(l.type==="image"){const u=I3(Sn(l,"src"));n().push(u?t("img",{...Ei(l,i.lineBase),className:"doc-image",src:u,alt:l.content||Sn(l,"alt")||"",title:Sn(l,"title")||void 0}):l.content)}else if(l.type==="link_open"||l.type==="strong_open"||l.type==="em_open"||l.type==="s_open")s.push({token:l,children:[]});else if(l.type==="link_close"||l.type==="strong_close"||l.type==="em_close"||l.type==="s_close"){if(s.length===1)continue;const u=s.pop();n().push(lg(t,u.token,u.children,i))}for(;s.length>1;){const l=s.pop();n().push(lg(t,l.token,l.children,i))}return r},ug=(t,e,i,r)=>{const s=Ei(e,r.lineBase);switch(e.type){case"paragraph_open":return t("p",s,i);case"heading_open":return t(e.tag,{...s,className:`doc-h doc-h-level doc-h${e.tag.slice(1)}`},i);case"blockquote_open":return t("blockquote",{...s,className:"doc-quote"},i);case"bullet_list_open":return t("ul",s,i);case"ordered_list_open":return t("ol",{...s,start:Sn(e,"start")||void 0},i);case"list_item_open":return t("li",s,i);case"table_open":return t("table",{...s,className:"doc-table"},i);case"thead_open":return t("thead",s,i);case"tbody_open":return t("tbody",s,i);case"tr_open":return t("tr",s,i);case"th_open":return t("th",{...s,style:ag(Sn(e,"style"))},i);case"td_open":return t("td",{...s,style:ag(Sn(e,"style"))},i);default:return i}};function lC(t,e={}){var o,a;const i=e.h;if(typeof i!="function")throw new TypeError("renderProseTokens requires a React-compatible h function");const r=[],s=[{token:null,children:r}],n=()=>s[s.length-1].children;for(const l of t||[])if(l.type==="inline")n().push(...aC(i,l.children,e));else if(l.type==="fence"||l.type==="code_block"){const u=(o=l.info)==null?void 0:o.trim().split(/\s+/,1)[0];n().push(i("pre",{...Ei(l,e.lineBase),className:"doc-pre"},i("code",{className:u?`language-${u}`:void 0},l.content)))}else if(l.type==="prose_math_block")n().push(z3(i,l,!0,Ei(l,e.lineBase)));else if(l.type==="prose_time_anchor"){const u=(a=e.renderTimeAnchor)==null?void 0:a.call(e,l.meta,l,Ei(l,e.lineBase));n().push(u??i("span",{...Ei(l,e.lineBase),className:"fv-anchor static","data-time-ms":l.meta.tMs},l.meta.label))}else if(l.type==="hr")n().push(i("hr",Ei(l,e.lineBase)));else if(l.type==="html_block"||l.type==="html_inline")n().push(l.content);else if(l.nesting===1)s.push({token:l,children:[]});else if(l.nesting===-1){if(s.length===1)continue;const u=s.pop();n().push(ug(i,u.token,u.children,e))}for(;s.length>1;){const l=s.pop();n().push(ug(i,l.token,l.children,e))}return r}function uC({children:t,className:e="",lineBase:i=0,softBreak:r,renderSpecRef:s,renderEvidence:n,renderTimeAnchor:o}){const a=k.useMemo(()=>{try{return sC(t)}catch{return null}},[t]),l=a?lC(a,{h:(()=>{let u=0;return(c,h,...d)=>{const f=h!==null&&typeof h=="object"&&!Array.isArray(h),m=f?{...h,key:h.key??`prose-${u++}`}:{key:`prose-${u++}`};return f?k.createElement(c,m,...d):k.createElement(c,m,h,...d)}})(),lineBase:i,softBreak:r,renderSpecRef:s,renderEvidence:n,renderTimeAnchor:o}):k.createElement("p",null,t==null?"":String(t));return k.createElement("div",{className:e},l)}function j3({children:t,className:e="",softBreak:i,renderSpecRef:r,renderEvidence:s,renderTimeAnchor:n}){const o=r||((l,u,c)=>k.createElement("span",{className:"doc-ref","data-spec-id":l,...c},l)),a=s||((l,u,c)=>k.createElement("a",{className:"doc-evidence",href:l.src,"data-evidence-hash":l.hash,...c},l.alt||l.hash));return k.createElement(uC,{className:`rich-text${e?` ${e}`:""}`,softBreak:i,renderSpecRef:o,renderEvidence:a,renderTimeAnchor:n},t)}const cg=t=>{const e=document.createRange();return e.selectNode(t),e};function cC(t,e){if(!t||t.collapsed||!e)return"";const i=[...e.querySelectorAll("[data-math-source]")].filter(a=>t.intersectsNode(a));if(!i.length)return t.toString();const r=[];let s=t.startContainer,n=t.startOffset;for(const[a,l]of i.entries()){const u=cg(l),c=t.compareBoundaryPoints(Range.START_TO_START,u)<=0;if(a>0||c){const d=document.createRange();d.setStart(s,n),d.setEndBefore(l),r.push(d.toString())}r.push(l.getAttribute("data-math-source")||"");const h=document.createRange();h.setStartAfter(l),h.collapse(!0),s=h.startContainer,n=h.startOffset}const o=cg(i[i.length-1]);if(t.compareBoundaryPoints(Range.END_TO_END,o)>=0){const a=document.createRange();a.setStart(s,n),a.setEnd(t.endContainer,t.endOffset),r.push(a.toString())}return r.join("")}function hC(t,e,i=0,r){if(!t)return;const s=r||getComputedStyle(t),n=s.boxSizing==="border-box"?(parseFloat(s.borderTopWidth)||0)+(parseFloat(s.borderBottomWidth)||0):0,o=t.placeholder;!t.value&&o&&(t.placeholder=""),t.style.height="auto";const a=t.scrollHeight+n;t.style.overflowY=a>e?"auto":"hidden",t.style.height=`${Math.min(Math.max(a,i),e)}px`,t.placeholder!==o&&(t.placeholder=o)}function da(t){var e,i;return t.isComposing||((e=t.nativeEvent)==null?void 0:e.isComposing)||t.keyCode===229||((i=t.nativeEvent)==null?void 0:i.keyCode)===229}const fd=k.forwardRef(function({value:e,className:i="",...r},s){const n=k.useRef(null);return k.useImperativeHandle(s,()=>n.current),k.useLayoutEffect(()=>{const o=n.current;if(!o)return;const a=getComputedStyle(o);hC(o,parseFloat(a.maxHeight)||1/0,parseFloat(a.minHeight)||0,a)},[e]),p.jsx("textarea",{ref:n,value:e,className:`composer-textarea ${i}`.trim(),...r})}),H3=k.forwardRef(function({as:e="div",className:i="",preview:r=null,editor:s,footer:n,...o},a){return p.jsxs(e,{ref:a,className:`composer-surface ${i}`.trim(),...o,children:[r,p.jsx("div",{className:"composer-editor",children:s}),p.jsx("div",{className:"composer-footer",children:n})]})}),bo=t=>Di(`/api/evidence/${t}`);function dC({src:t,alt:e,onClose:i}){return ni(!0,i),p.jsx("div",{className:"lightbox",onClick:i,children:p.jsx("img",{src:t,alt:e})})}function fC({hash:t}){const e=He(),[i,r]=k.useState(null);return k.useEffect(()=>{let s=!0;return fetch(bo(t)).then(n=>n.ok?n.text():Promise.reject(new Error("miss"))).then(n=>{s&&r(n)}).catch(()=>{s&&r("")}),()=>{s=!1}},[t]),i===null?p.jsx("pre",{className:"eval-transcript loading",children:e("nodeView.eval.loadingTranscript")}):p.jsx("pre",{className:"eval-transcript",children:i})}function pC({hash:t,collapsed:e=!1}){const i=He(),[r,s]=k.useState(null);if(k.useEffect(()=>{let o=!0;return fetch(bo(t)).then(a=>a.ok?a.text():Promise.reject(new Error("miss"))).then(a=>{let l=a,u=!0;try{l=JSON.stringify(JSON.parse(a),null,2)}catch{u=!1}o&&s({text:l,valid:u})}).catch(()=>{o&&s({text:"",valid:!1})}),()=>{o=!1}},[t]),r===null)return p.jsx("pre",{className:"eval-data loading",children:i("nodeView.eval.loadingData")});const n=r.valid?i("nodeView.eval.data"):i("nodeView.eval.dataInvalid");return e?p.jsxs("details",{className:"eval-datawrap eval-datafold",children:[p.jsx("summary",{className:"eval-datahead",children:n}),p.jsx("pre",{className:"eval-data",children:r.text})]}):p.jsxs("div",{className:"eval-datawrap",children:[p.jsx("div",{className:"eval-datahead",children:n}),p.jsx("pre",{className:"eval-data",children:r.text})]})}function mC({hash:t,alt:e}){const[i,r]=k.useState(!1);return p.jsxs(p.Fragment,{children:[p.jsx("img",{className:"an-image",src:bo(t),alt:e,loading:"lazy",onClick:()=>r(!0)}),i&&p.jsx(dC,{src:bo(t),alt:e,onClose:()=>r(!1)})]})}function gC({exit:t}){return p.jsx(je,{name:t?"minimize":"maximize",size:15})}function wR({target:t,className:e=""}){const i=He(),[r,s]=k.useState(!1);k.useEffect(()=>{const o=()=>{const a=document.fullscreenElement,l=t==null?void 0:t.current;s(!!a&&!!l&&(a===l||l.contains(a)))};return document.addEventListener("fullscreenchange",o),()=>document.removeEventListener("fullscreenchange",o)},[t]);const n=()=>{var a,l;const o=t==null?void 0:t.current;o&&(document.fullscreenElement?(a=document.exitFullscreen||document.webkitExitFullscreen)==null||a.call(document):(l=o.requestFullscreen||o.webkitRequestFullscreen)==null||l.call(o))};return p.jsx("button",{type:"button",className:`an-fs ${e}`,onClick:n,"data-tip":i(r?"annotator.exitFullscreen":"annotator.fullscreen"),"aria-label":i(r?"annotator.exitFullscreen":"annotator.fullscreen"),children:p.jsx(gC,{exit:r})})}function vC({e:t,alt:e="",collapsed:i=!1}){const r=He();return t.state==="miss"?p.jsx("div",{className:"eval-noimg",children:r("nodeView.eval.miss")}):t.kind==="transcript"?p.jsx(fC,{hash:t.hash}):t.kind==="data"?p.jsx(pC,{hash:t.hash,collapsed:i}):t.kind==="video"?p.jsx("video",{className:"eval-video",src:bo(t.hash),controls:!0,preload:"metadata",playsInline:!0}):p.jsx(mC,{hash:t.hash,alt:e})}const Dl=new Map;function bC(t){const[e,i]=k.useState(()=>Dl.get(t)??null);return k.useEffect(()=>{if(Dl.has(t)){i(Dl.get(t));return}let r=!0;return fetch(bo(t),{headers:{Range:"bytes=0-0"}}).then(s=>{const n=s.headers.get("content-type")||"",o=s.ok?{kind:n.startsWith("video/")?"video":n.startsWith("image/")?"image":n.startsWith("application/json")?"data":"transcript",state:"present"}:{kind:"image",state:"miss"};Dl.set(t,o),r&&i(o)}).catch(()=>{r&&i({kind:"image",state:"miss"})}),()=>{r=!1}},[t]),e}function _C({hash:t,alt:e=""}){const i=bC(t);return i?p.jsx(vC,{e:{hash:t,...i},alt:e}):null}function pd({children:t,className:e=""}){return p.jsx(j3,{className:e,softBreak:"break",renderSpecRef:(i,r,s)=>{const n=Vt("spec",i);return p.jsx("a",{className:"doc-link",href:n,...s,onClick:o=>f5(o,n),children:i})},renderEvidence:(i,r,s)=>p.jsx("span",{className:"rich-evidence",...s,children:p.jsx(_C,{hash:i.hash,alt:i.alt||"evidence"})}),children:t})}const yC=t=>p.jsx(pd,{children:t});function hg({loadToolOutput:t,children:e}){const i=He(),r=k.useMemo(()=>({...fv,loading:i("common.loading"),running:i("session.executionRunning"),more:i("mobile.more")}),[i]);return p.jsx(K7,{renderText:yC,labels:r,loadToolOutput:t,children:e})}const dg=t=>typeof t=="number"?t:Date.parse(t),wC=/\n*— from session (?:"(.*?)" \(([^\s)]+)\)|(\S+))(?: on machine \S+)?\. To reply: spex session send (?:--ssh \S+ )?\S+ "<your reply>"\s*$/;function xC(t){const e=wC.exec(t||"");return e?{text:t.slice(0,e.index),envelope:{label:e[1]||null,id:e[2]||e[3]}}:{text:t,envelope:null}}function SC(t,e){const i=[];let r=null,s=!1;const n=a=>{r??(r={kind:"seam",ts:a,from:dg(a)})},o=(a,l=!1)=>{r&&i.push({...r,to:a,open:l}),r=null};for(const a of t){const l=a.display||a.status;if(a.kind==="status"&&(s=l==="working"),a.kind==="status"&&s&&!a.note){n(a.ts);continue}o(dg(a.ts)),a.kind==="sent"?i.push({kind:"quote",ts:a.ts,from:a.from,...xC(a.text)}):l==="error"||l==="corrupt"?i.push({kind:"event",ts:a.ts,status:l,text:a.note}):i.push({kind:"say",ts:a.ts,status:l,text:a.note}),s&&n(a.ts)}return r&&o(Math.max(r.from+1,e),!0),i}const Ru={merged:{color:"#859900"},active:{color:"#cb4b16"},drift:{color:"#b58900"},pending:{color:"#93a1a1"}},kC={added:"+",edited:"~",deleted:"✕",moved:"→"},xR=["merged","active","drift","pending"];function SR(t){var o,a;const e={merged:[],active:[],drift:[],pending:[]},i=[],r=new Set,s={pass:0,fail:0,stalePass:0,staleFail:0,empty:0},n={pass:[],fail:[],stalePass:[],staleFail:[],empty:[]};for(const l of t){e[l.status]&&e[l.status].push(l.id);const u=(o=l.reviewSummary)==null?void 0:o.issues;if(u!=null&&u.open){i.push(l.id);for(const h of u.openIds||[])r.add(h)}const c=(a=l.reviewSummary)==null?void 0:a.evals;if(c)for(const h of Object.keys(s)){const d=c[h]||0;s[h]+=d,d>0&&n[h].push(l.id)}}return{total:t.length,status:e,issueIds:i,issueCount:r.size,scoreCount:s,scoreNodes:n}}function kR(t,e=14){const i=String(t??"");if(i.length<=e)return i;if(e<=1)return"…".slice(0,e);const r=e-1,s=Math.max(1,Math.floor(r/2)-1),n=r-s;return`${i.slice(0,s)}…${i.slice(i.length-n)}`}const fg=["◆","▲","●","■","★","✦","⬟","⬢","❖","◈","✸","⟡","✚","❂","◐","◑","⬣","▰","✶","⬤","✹","◇","⊛","✺"],pg=["circle","rounded","square","hex"];function CC(t){const e=L5(t);return{seed:t,glyph:fg[(e>>>9)%fg.length],shape:pg[(e>>>17)%pg.length],...O5(t)}}function n1({seed:t,status:e,title:i,size:r=16}){const s=CC(t),n={width:r,height:r};return p.jsx("span",{className:`avatar av-st-${e||"none"}`,"data-tip":i,"aria-label":i,style:n,children:p.jsx("span",{className:`av-face av-gen av-${s.shape}`,style:{...n,background:s.bg,color:s.fg,fontSize:r*.62},children:s.glyph})})}function $3(t){var e;return Hr(t)||((e=t==null?void 0:t.id)==null?void 0:e.slice(0,8))||""}function md({session:t,active:e=!1,selected:i=!1,onPick:r,onHover:s,onOpen:n,compact:o=!1,newSession:a=!1,name:l=null,className:u=""}){const c=He(),h=a?null:o0(t),d=a?c("sessionPicker.newSession"):$3(t),f=a?d:`${d} · ${c(`status.${h.status}`)}`;return p.jsxs("button",{type:"button",role:"option","aria-selected":i,className:`session-picker-row${e?" active":""}${i?" selected":""}${o?" compact":""}${a?" new":""}${u?` ${u}`:""}`,"data-session-picker-id":a?"new":t.id,title:f,onMouseDown:m=>m.preventDefault(),onMouseEnter:s,onDoubleClick:()=>n==null?void 0:n(a?"new":t.id),onClick:()=>r==null?void 0:r(a?"new":t.id),children:[a?p.jsx("span",{className:"session-picker-new-icon","aria-hidden":"true",children:p.jsx(je,{name:"plus",size:13})}):p.jsx(n1,{seed:t.id,status:h.status,size:o?15:17,title:f}),p.jsx("span",{className:"session-picker-name",children:l||d}),!a&&p.jsx("span",{className:"session-picker-status",style:{color:h.color},"aria-label":c(`status.${h.status}`),children:h.glyph})]})}function AC({sessions:t=[],value:e="",onChange:i,onOpen:r,includeNew:s=!1,filter:n=!0,placeholder:o,ariaLabel:a,className:l="",compact:u=!1,autoFocus:c=!1}){const h=He(),d=k.useRef(null),[f,m]=k.useState(""),[v,_]=k.useState(0),w=k.useMemo(()=>{const D=f.trim().toLocaleLowerCase(),R=t.filter(E=>!D||[$3(E),b4(E),E.id].some(L=>L==null?void 0:L.toLocaleLowerCase().includes(D)));return s?[...R,{id:"new",__new:!0}]:R},[s,f,t]);k.useEffect(()=>{_(D=>Math.min(D,Math.max(w.length-1,0)))},[w.length]),k.useEffect(()=>{var D;c&&((D=d.current)==null||D.focus())},[c]);const x=D=>{i==null||i(D),D!=="new"&&m("")},A=D=>{if(D.key==="ArrowDown")D.preventDefault(),_(R=>w.length?(R+1)%w.length:0);else if(D.key==="ArrowUp")D.preventDefault(),_(R=>w.length?(R-1+w.length)%w.length:0);else if(D.key==="Enter"){D.preventDefault();const R=w[v];R&&x(R.id)}};return p.jsxs("div",{className:`session-picker${u?" compact":""}${l?` ${l}`:""}`,children:[n&&p.jsx("input",{ref:d,className:"session-picker-filter",value:f,placeholder:o||h("sessionPicker.filter"),"aria-label":a||h("sessionPicker.filter"),onChange:D=>{m(D.target.value),_(0)},onKeyDown:A}),p.jsx("div",{className:"session-picker-list",role:"listbox","aria-label":a||h("sessionPicker.label"),children:w.length?w.map((D,R)=>D.__new?p.jsx(md,{newSession:!0,active:R===v,selected:e==="new",onPick:x,onOpen:r,onHover:()=>_(R),compact:u},"new"):p.jsx(md,{session:D,active:R===v,selected:e===D.id,onPick:x,onOpen:r,onHover:()=>_(R),compact:u},D.id)):p.jsx("div",{className:"session-picker-empty",children:h("sessionPicker.empty")})})]})}const EC=/\[\[(\.?[\p{L}\p{N}_-]+)\]\]/gu,q3=(t,e=[])=>t.replace(EC,(i,r)=>{const s=e.find(n=>n.id===r);return s?`[[${s.id}]] (${s.path})`:i}),W3=(t,e=[])=>e.find(i=>i.ui&&t.trim()===`/${i.name}`)||null,K3=t=>(t||"").replace(/^\.spec\//,"").replace(/\/spec\.md$/,"");function DC(t,e,i){const r=e.toLowerCase(),s=[];for(const n of t){const o=n.id.toLowerCase(),a=K3(n.path).toLowerCase();let l;if(!r)l=3;else if(o.startsWith(r))l=0;else if(o.includes(r))l=1;else if(a.includes(r))l=2;else continue;n.id===i&&(l=-1),s.push({s:n,score:l})}return s.sort((n,o)=>n.score-o.score||n.s.id.length-o.s.id.length||n.s.id.localeCompare(o.s.id)),s.slice(0,8).map(n=>n.s)}function MC(t,e){const i=e.toLowerCase(),r=u=>Hr(u)||(u.id||"").slice(0,8),s=u=>{var c,h;return[u==null?void 0:u.title,u==null?void 0:u.label,(c=u==null?void 0:u.raw)==null?void 0:c.name,(h=u==null?void 0:u.raw)==null?void 0:h.title,u==null?void 0:u.activity,u==null?void 0:u.promptPreview,u==null?void 0:u.note].filter(d=>typeof d=="string"&&d.trim()).map(d=>d.toLowerCase())},n=[];for(const u of t||[]){const c=(u.id||"").toLowerCase(),h=s(u);let d;if(!i)d=3;else if(c===i||h.some(f=>f===i))d=0;else if(c.startsWith(i)||h.some(f=>f.startsWith(i)))d=1;else if(c.includes(i)||h.some(f=>f.includes(i)))d=2;else continue;n.push({s:u,score:d})}n.sort((u,c)=>u.score-c.score||(c.s.created||0)-(u.s.created||0));const o=n.map(u=>({id:u.s.id,label:r(u.s),sub:u.s.node||u.s.status,session:u.s})),a=n.filter(u=>u.score===0).length,l=o.slice(0,Math.min(a,7));return[...l,{id:"new",label:"new",sub:"choose a launcher"},...o.slice(l.length)].slice(0,8)}function TC(t,e){const i=e.toLowerCase();return(t||[]).map(r=>{const s=(r.name||"").toLowerCase(),n=i?s.startsWith(i)?0:s.includes(i)?1:-1:1;return{launcher:r,score:n}}).filter(r=>r.score>=0).sort((r,s)=>r.score-s.score||r.launcher.name.localeCompare(s.launcher.name)).slice(0,8).map(({launcher:r})=>({id:r.name,label:r.name,sub:r.cmd||r.harness||""}))}function ia(t,e){if(!e)return t;const i=t.toLowerCase().indexOf(e.toLowerCase());return i<0?t:p.jsxs(p.Fragment,{children:[t.slice(0,i),p.jsx("b",{className:"mention-hit",children:t.slice(i,i+e.length)}),t.slice(i+e.length)]})}function V3(t,e){const i=e.toLowerCase(),r=[];for(const s of t){const n=s.name.toLowerCase();let o;if(!i)o=1;else if(n.startsWith(i))o=0;else if(n.includes(i))o=1;else continue;r.push({c:s,score:o})}return r.sort((s,n)=>s.score-n.score),r.slice(0,10).map(s=>s.c)}function BC(t,e,i){let r=e;for(;r>0&&!/\s/.test(t[r-1]);)r--;if(t[r]!=="/")return null;const s=t.slice(r+1,e),n=V3(i,s);return n.length?{items:n,index:0,start:r,end:e,query:s}:null}function RC(t,e){const i=/^\/(\S*)$/.exec(t);if(!i)return null;const r=V3(e,i[1]);return r.length?{items:r,index:0,start:0,end:t.length,query:i[1]}:null}const NC=t=>t&&t[0].toUpperCase()+t.slice(1),LC={user:"(user)",project:"(project)",skill:"[skill]","built-in":"built-in",ui:"[ui]",preset:"[preset]",review:"[review]"};function OC({menu:t,up:e,head:i,onPick:r,onHover:s}){const n=He();return p.jsxs("ul",{className:e?"mention-menu up":"mention-menu",role:"listbox",children:[p.jsxs("li",{className:"mention-head",children:["// ",i," — ",n("session.menuHint")]}),t.items.map((o,a)=>{const l=o.ui?"ui":o.source??o.kind,u=o.ui?` sc-${o.color}`:"";return p.jsxs("li",{role:"option","aria-selected":a===t.index,className:`${a===t.index?"mention-item on":"mention-item"}${u}`,onMouseDown:c=>{c.preventDefault(),r(o)},onMouseEnter:()=>s(a),children:[p.jsxs("span",{className:o.ui?"slash-name ui":"slash-name",children:["/",ia(o.name,t.query)]}),p.jsx("span",{className:"slash-desc",children:NC(o.description??o.desc)}),p.jsx("span",{className:`slash-src src-${l}`,children:LC[l]||l})]},`${l}:${o.name}`)})]})}function PC(t,e,i,r){let s=e-1;for(;s>=0&&/[\p{L}\p{N}_.\-]/u.test(t[s]);)s--;if(s>=1&&t[s-1]==="["&&t[s]==="["){const n=t.slice(s+1,e),o=DC(i,n,r);return o.length?{kind:"mention",items:o,index:0,start:s-1,end:e,query:n}:null}return null}function mg(t,e,i,r=[]){let s=e-1;for(;s>=0&&/[\p{L}\p{N}_.:\-]/u.test(t[s]);)s--;if(s>=0&&t[s]==="@"&&(s===0||/\s/.test(t[s-1]))){const n=t.slice(s+1,e);if(n.startsWith("new:")){const a=TC(r,n.slice(4));return a.length?{kind:"launcher",items:a,index:0,start:s,end:e,query:n.slice(4)}:null}const o=MC(i,n);return o.length?{kind:"session",items:o,index:0,start:s,end:e,query:n}:null}return null}function FC({menu:t,up:e,fixedStyle:i,onPick:r,onHover:s}){const n=He(),o=t.kind==="launcher",a=t.kind==="session"||o,l=o?`@new:${t.query}`:t.query?a?`@${t.query}`:`[[${t.query}]]`:n(a?"session.menuSessions":"session.menuSpecNodes");return p.jsxs("ul",{className:`${e?"mention-menu up":"mention-menu"}${i?" fixed":""}`,style:i||void 0,role:"listbox",children:[p.jsxs("li",{className:"mention-head",children:["// ",l," — ",n("session.menuHint")]}),t.items.map((u,c)=>{var h;return a&&u.session?p.jsx(md,{session:u.session,compact:!0,active:c===t.index,onPick:()=>r(u),onHover:()=>s(c),className:"mention-item",name:p.jsxs(p.Fragment,{children:["@",ia(u.label,t.query)]})},u.id):p.jsxs("li",{role:"option","aria-selected":c===t.index,className:`${c===t.index?"mention-item on":"mention-item"}${o||t.kind==="session"&&u.id==="new"?" new":""}`,onMouseDown:d=>{d.preventDefault(),r(u)},onMouseEnter:()=>s(c),children:[!a&&p.jsx("span",{className:"mention-dot",style:{background:((h=Ru[u.status])==null?void 0:h.color)||Ru.pending.color}}),p.jsx("span",{className:"mention-id",children:o?p.jsxs(p.Fragment,{children:["@new:",ia(u.label,t.query)]}):a?p.jsxs(p.Fragment,{children:["@",ia(u.label,t.query)]}):ia(u.id,t.query)}),p.jsx("span",{className:"mention-path",children:a?u.sub:K3(u.path)})]},u.id)})]})}function gd({inputRef:t,value:e,setValue:i,specs:r=[],sessions:s=[],launchers:n=[],focusId:o=null,up:a=!1,fixedAbove:l=null,slash:u=null}){const[c,h]=k.useState(null),[d,f]=k.useState(null),m=k.useRef(null),v=F=>`${F.value}\0${F.selectionStart}`,_=(F,$)=>{var z;if(!((z=u==null?void 0:u.commands)!=null&&z.length))return null;const W=u.mode==="token"?BC(F,$,u.commands):RC(F,u.commands);return W?{kind:"slash",...W}:null},w=F=>{var T;if(!F){h(null),f(null);return}const $=v(F);if(m.current===$){h(null),f(null);return}m.current=null;const W=F.selectionStart,z=PC(F.value,W,r,o)||mg(F.value,W,s,n)||_(F.value,W);if(h(z),!z||!l){f(null);return}const j=F.getBoundingClientRect(),C=(T=F.closest(l))==null?void 0:T.getBoundingClientRect(),O=(C==null?void 0:C.top)??j.top;f({left:`${j.left}px`,width:`${j.width}px`,right:"auto",bottom:`${Math.max(8,window.innerHeight-O+8)}px`})};k.useEffect(()=>{const F=t.current;n.length&&F&&document.activeElement===F&&w(F)},[n]);const x=F=>h($=>$&&{...$,index:($.index+F+$.items.length)%$.items.length}),A=F=>h($=>$&&{...$,index:F}),D=F=>{var j;if(!F||!c)return;m.current=null;const $=e.slice(0,c.start);if(c.kind==="slash"){if((j=u==null?void 0:u.onPick)!=null&&j.call(u,F,c)){h(null),f(null);return}const C=`/${F.name} `;i($+C+e.slice(c.end)),h(null),f(null);const O=$.length+C.length;requestAnimationFrame(()=>{const T=t.current;T&&(T.focus(),T.setSelectionRange(O,O))});return}if(c.kind==="session"&&F.id==="new"){const C="@new:",O=$+C+e.slice(c.end),T=$.length+C.length;i(O),h(mg(O,T,s,n)),requestAnimationFrame(()=>{const U=t.current;U&&(U.focus(),U.setSelectionRange(T,T))});return}const W=c.kind==="session"?`@${F.id} `:c.kind==="launcher"?`@new:${F.id} `:`[[${F.id}]] `;i($+W+e.slice(c.end)),h(null),f(null);const z=$.length+W.length;requestAnimationFrame(()=>{const C=t.current;C&&(C.focus(),C.setSelectionRange(z,z))})},R=F=>c?F.key==="ArrowDown"?(F.preventDefault(),F.stopPropagation(),x(1),!0):F.key==="ArrowUp"?(F.preventDefault(),F.stopPropagation(),x(-1),!0):F.key==="Enter"||F.key==="Tab"?(F.preventDefault(),F.stopPropagation(),D(c.items[c.index]),!0):F.key==="Escape"?(F.preventDefault(),F.stopPropagation(),E(),!0):!1:!1,E=()=>{t.current&&(m.current=v(t.current)),h(null),f(null)},L=()=>{m.current=null,h(null),f(null)};ni(!!c,E);const q=c?c.kind==="slash"?p.jsx(OC,{menu:c,up:a,head:c.query?`/${c.query}`:u==null?void 0:u.head,onPick:D,onHover:A}):p.jsx(FC,{menu:c,up:a,fixedStyle:d,onPick:D,onHover:A}):null;return{menu:c,sync:w,onKeyDown:R,close:L,dismiss:E,accept:D,nav:x,menuEl:q}}function CR(t,e,i,r){return e?t.key==="ArrowDown"?(t.preventDefault(),t.stopPropagation(),i(s=>s&&{...s,index:(s.index+1)%s.items.length}),!0):t.key==="ArrowUp"?(t.preventDefault(),t.stopPropagation(),i(s=>s&&{...s,index:(s.index-1+s.items.length)%s.items.length}),!0):t.key==="Enter"||t.key==="Tab"?(t.preventDefault(),t.stopPropagation(),r(e.items[e.index]),!0):t.key==="Escape"?(t.preventDefault(),t.stopPropagation(),i(null),!0):!1:!1}function U3(t,e,i,r=null){if(!t)return;const s=t.selectionStart??t.value.length,n=t.selectionEnd??s;i(t.value.slice(0,s)+e+t.value.slice(n));const o=s+e.length;requestAnimationFrame(()=>{t.isConnected&&(t.focus(),t.setSelectionRange(o,o),r==null||r(t))})}function AR({label:t,onClick:e,disabled:i=!1,children:r}){return p.jsx("button",{type:"button",className:"fv-trigger-btn","data-tip":t,"aria-label":t,disabled:i,onMouseDown:s=>s.preventDefault(),onClick:e,children:r})}const Ml=1,vd=1024,IC=1024,zC=1024,bd=vd*IC,gg=bd*zC;let jC=0;const HC=()=>{var t,e;return((e=(t=globalThis.crypto)==null?void 0:t.randomUUID)==null?void 0:e.call(t))||`attachment-${Date.now()}-${++jC}`},vg=t=>t<vd?`${t} B`:t<bd?`${Math.round(t/vd)} KB`:t<gg?`${(t/bd).toFixed(1)} MB`:`${(t/gg).toFixed(2)} GB`,Tl=async t=>{const e=await t.json().catch(()=>null);return(e==null?void 0:e.error)||`upload failed (HTTP ${t.status})`},$C=(t,e)=>(t==null?void 0:t.size)===e&&Number.isSafeInteger(t.chunkBytes)&&t.chunkBytes>0&&Number.isSafeInteger(t.concurrency)&&t.concurrency>0&&Number.isSafeInteger(t.requestTimeoutMs)&&t.requestTimeoutMs>0&&Number.isSafeInteger(t.retryLimit)&&t.retryLimit>=0&&Number.isSafeInteger(t.retryDelayMs)&&t.retryDelayMs>=0&&Number.isSafeInteger(t.offset)&&t.offset>=0&&t.offset<=e,qC=(t,e)=>new Promise((i,r)=>{if(e.signal.aborted){r(new Error("upload cancelled"));return}const s=window.setTimeout(()=>{e.signal.removeEventListener("abort",n),i()},t),n=()=>{window.clearTimeout(s),r(new Error("upload cancelled"))};e.signal.addEventListener("abort",n,{once:!0})}),bg=async(t,e,i,r)=>{const s=new AbortController,n=()=>s.abort();i.signal.addEventListener("abort",n,{once:!0});const o=window.setTimeout(()=>s.abort(),r);try{return await fetch(t,{...e,signal:s.signal})}catch(a){throw!i.signal.aborted&&s.signal.aborted?new Error("upload request timed out"):a}finally{window.clearTimeout(o),i.signal.removeEventListener("abort",n)}},WC=async(t,e,i)=>{let r=0;for(;;)try{return await t()}catch(s){if(i.signal.aborted||r>=e.retryLimit)throw s;r+=1,await qC(e.retryDelayMs,i)}},KC=(t,e,i)=>{const r=t.current;if(!r){e(u=>{const c=u||"";return c+(c&&!/\s$/.test(c)?" ":"")+i+" "});return}const s=r.value,n=r.selectionStart,o=r.selectionEnd,a=s.slice(0,n),l=(a&&!/\s$/.test(a)?" ":"")+i+" ";e(a+l+s.slice(o)),requestAnimationFrame(()=>{if(!r.isConnected)return;r.focus();const u=a.length+l.length;r.setSelectionRange(u,u)})};function _d({inputRef:t,setValue:e,variant:i="command",disabled:r=!1}){const s=He(),[n,o]=k.useState([]),[a,l]=k.useState(!1),u=k.useRef([]),c=k.useRef(new Map),h=k.useRef(!1),d=k.useRef(null),f=k.useRef(null);f.current=C=>KC(t,e,C);const m=C=>{u.current=C,o(C)},v=(C,O)=>m(u.current.map(T=>T.id===C?{...T,...O}:T)),_=async(C,O=null)=>{const T=u.current.find(H=>H.id===C);if(!T||T.phase==="cancelled")return null;v(C,{phase:"uploading",error:null});const U=new AbortController;c.current.set(C,U);try{let H=T.transferId,re=null;if(H){const Y=await fetch(Di(`/api/uploads/${H}`),{signal:U.signal});if(Y.ok)re=await Y.json();else if(Y.status!==404)throw new Error(await Tl(Y))}if(!re){const Y=await fetch(Di("/api/uploads"),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({name:T.file.name||"pasted",size:T.file.size}),signal:U.signal});if(!Y.ok)throw new Error(await Tl(Y));if(re=await Y.json(),H=re==null?void 0:re.id,!H)throw new Error("upload did not return a transfer id");v(C,{transferId:H})}if(!$C(re,T.file.size))throw new Error("upload transfer metadata is invalid");O==null||O(re.concurrency);let G=re.offset;for(v(C,{offset:G});G<T.file.size;){const Y=T.file.slice(G,Math.min(T.file.size,G+re.chunkBytes)),le=await WC(async()=>{const de=await bg(Di(`/api/uploads/${H}`),{method:"PATCH",headers:{"content-type":"application/offset+octet-stream","upload-offset":String(G)},body:Y},U,re.requestTimeoutMs);if(de.status>=500)throw new Error(await Tl(de));return de},re,U),te=await le.json().catch(()=>null);if(le.status===409&&Number.isSafeInteger(te==null?void 0:te.offset)&&te.offset>=0&&te.offset<=T.file.size){G=te.offset,v(C,{offset:G});continue}if(!le.ok)throw new Error((te==null?void 0:te.error)||`upload failed (HTTP ${le.status})`);if(!Number.isSafeInteger(te==null?void 0:te.offset)||te.offset<=G||te.offset>T.file.size)throw new Error("upload did not advance its committed offset");G=te.offset,v(C,{offset:G})}const X=await bg(Di(`/api/uploads/${H}/complete`),{method:"POST"},U,re.requestTimeoutMs);if(!X.ok)throw new Error(await Tl(X));const oe=await X.json().catch(()=>null);if(!(oe!=null&&oe.path))throw new Error("upload did not return a path");const I=u.current.find(Y=>Y.id===C);return(I==null?void 0:I.phase)==="cancelled"?null:(T.splice(oe.path),v(C,{phase:"complete",offset:T.file.size,path:oe.path}),re.concurrency)}catch(H){O==null||O(null),U.signal.aborted?v(C,{phase:"cancelled",offset:0,transferId:null,error:null}):v(C,{phase:"failed",error:H instanceof Error?H.message:String(H)})}finally{c.current.delete(C)}return null},w=async C=>{if(!h.current){h.current=!0;try{const[O,...T]=C;let U;const H=new Promise(Y=>{U=Y}),re=O?_(O,U):Promise.resolve(Ml),G=O?await H:Ml,X=Math.min(Math.max(0,(G||Ml)-Ml),T.length);if(X===0){await re;for(const Y of T)await _(Y);return}let oe=0;const I=Array.from({length:X},async()=>{for(;oe<T.length;){const Y=T[oe];oe+=1,await _(Y)}});await Promise.all([re,...I])}finally{h.current=!1}}},x=C=>{h.current||w([C])},A=async C=>{var T;const O=u.current.find(U=>U.id===C);O&&((T=c.current.get(C))==null||T.abort(),O.transferId&&await fetch(Di(`/api/uploads/${O.transferId}`),{method:"DELETE"}).catch(()=>{}),v(C,{phase:"cancelled",offset:0,transferId:null,error:null}))},D=C=>{const O=u.current.find(T=>T.id===C);O&&(O.phase!=="complete"&&O.phase!=="cancelled"&&A(C),m(u.current.filter(T=>T.id!==C)))},R=async C=>{const O=[...C||[]];if(!O.length||r||h.current)return;const T=f.current,U=O.map(H=>({id:HC(),file:H,splice:T,phase:"queued",offset:0,transferId:null,error:null}));m([...u.current,...U]),await w(U.map(H=>H.id))},E=()=>{var C;r||(C=d.current)==null||C.click()},L=C=>{var T;const O=(T=C.clipboardData)==null?void 0:T.files;r||!O||!O.length||(C.preventDefault(),R(O))},q=C=>{var O;r||[...((O=C.dataTransfer)==null?void 0:O.types)||[]].includes("Files")&&(C.preventDefault(),l(!0))},F=()=>l(!1),$=C=>{var O;C.preventDefault(),l(!1),R((O=C.dataTransfer)==null?void 0:O.files)},W=n.some(C=>C.phase==="queued"||C.phase==="uploading"),z=p.jsx("input",{ref:d,type:"file",multiple:!0,style:{display:"none"},onChange:C=>{R(C.target.files),C.target.value=""}}),j=n.length?p.jsx("div",{className:`si-attach-queue ${i}`,"aria-live":"polite",children:n.map(C=>{const O=C.phase==="queued"||C.phase==="uploading",T=C.phase==="queued"?s("session.attachQueued"):C.phase==="uploading"?`${vg(C.offset)} / ${vg(C.file.size)}`:C.phase==="complete"?s("session.attachDone"):C.phase==="cancelled"?s("session.attachCancelled"):C.error;return p.jsxs("div",{className:`si-attach-row ${C.phase}`,onAnimationEnd:U=>{U.target===U.currentTarget&&U.animationName==="si-attach-complete-out"&&D(C.id)},children:[p.jsxs("span",{className:"si-attach-name",title:C.file.name,children:[p.jsx(je,{name:"paperclip",size:12}),C.file.name]}),p.jsx("progress",{className:"si-attach-progress",value:C.offset,max:C.file.size,"aria-label":`${C.file.name}: ${T}`}),p.jsx("span",{className:"si-attach-status",role:C.phase==="failed"?"alert":"status",children:T}),C.phase==="failed"&&p.jsx(Zt,{icon:"rotate-ccw",size:13,className:"si-attach-action",label:s("session.attachRetry"),disabled:h.current,onClick:()=>x(C.id)}),(O||C.phase==="failed")&&p.jsx(Zt,{icon:"x",size:13,className:"si-attach-action",label:s("session.attachCancel"),onClick:()=>{A(C.id)}}),(C.phase==="complete"||C.phase==="cancelled")&&p.jsx(Zt,{icon:"x",size:13,className:"si-attach-action",label:s("session.attachDismiss"),onClick:()=>D(C.id)})]},C.id)})}):null;return{pick:E,busy:W,dragging:a,onPaste:L,fileInput:z,queue:j,dropProps:{onDragOver:q,onDragLeave:F,onDrop:$}}}const G3=new Map,o1=t=>G3.get(t)||null;async function VC(t,e){var i,r;try{const s=((r=(i=globalThis.crypto)==null?void 0:i.randomUUID)==null?void 0:r.call(i))||`session-create-${Date.now()}-${Math.random().toString(16).slice(2)}`,n=await fetch(Di("/api/sessions"),{method:"POST",headers:{"Content-Type":"application/json","Idempotency-Key":s},body:JSON.stringify({prompt:t,...e?{launcher:e}:{}})}),o=await n.json().catch(()=>null),a={ok:n.ok,error:o==null?void 0:o.error};return o!=null&&o.id&&(G3.set(o.id,o),a.id=o.id,a.session=o),a}catch{return{ok:!1}}}let bn=null,Bl=null;const UC=()=>bn?Promise.resolve(bn):(Bl||(Bl=h4().then(t=>(bn=t,t)).catch(t=>{throw Bl=null,t})),Bl),_g=t=>Array.isArray(t==null?void 0:t.launchers)?t.launchers:[],GC=()=>{try{return localStorage.getItem("si.launcher")||""}catch{return""}},yg=(t,e,i=GC())=>{var r;return t.some(s=>s.name===i)?i:e&&t.some(s=>s.name===e)?e:((r=t[0])==null?void 0:r.name)||i};function Y3(){const t=_g(bn),[e,i]=k.useState(t),[r,s]=k.useState(()=>yg(t,bn==null?void 0:bn.default)),n=o=>{s(o);try{localStorage.setItem("si.launcher",o)}catch{}};return k.useEffect(()=>{UC().then(o=>{const a=_g(o);a.length&&(i(a),s(l=>yg(a,o.default,l)))}).catch(()=>{})},[]),{launchers:e,launcher:r,pickLauncher:n}}function X3(){const[t,e]=k.useState([]);return k.useEffect(()=>{P5().then(i=>{Array.isArray(i)&&e(i)}).catch(()=>{})},[]),t}function J3(t){const[e,i]=k.useState([]);return k.useEffect(()=>{let r=!0;return fetch(Di(`/api/slash-commands?harness=${encodeURIComponent(t||"claude")}`)).then(s=>s.json()).then(s=>{r&&Array.isArray(s)&&i(s)}).catch(()=>{}),()=>{r=!1}},[t]),e}const YC=[{name:"command",color:"blue",icon:"command",button:!0,typed:!1,pressed:!0,anchor:"right",when:t=>!!(t!=null&&t.status)&&t.status!=="offline"&&t.status!=="queued"&&t.liveness!=="offline",labelKey:"session.commandBtn",titleKey:"session.commandTitle",shortcut:"shell.commandBox"},{name:"eval",color:"cyan",button:!1,when:t=>!!(t!=null&&t.status),labelKey:"sessionEval.btn",titleKey:"sessionEval.btnTitle",descKey:"session.cmd.evalDesc"},{name:"relaunch",color:"blue",icon:"rotate-ccw",button:!0,typed:!1,when:t=>!!(t!=null&&t.status)&&t.status!=="queued"&&t.status!=="retired"&&t.liveness==="offline",labelKey:"session.relaunch",titleKey:"session.relaunchTitle"},{name:"stop",color:"muted",button:!1,when:t=>!!(t!=null&&t.status)&&t.status!=="offline"&&t.status!=="queued"&&t.liveness!=="offline",titleKey:"session.cmd.stopTitle",descKey:"session.cmd.stopDesc"},{name:"close",color:"red",button:!1,when:t=>!!(t!=null&&t.status)&&t.status!=="offline",titleKey:"session.cmd.closeTitle",descKey:"session.cmd.closeDesc"}];function wg(t,e={}){return t!=null&&t.archived?[]:YC.filter(i=>i.when(t)).map(i=>{var r;return{...i,...((r=i.availability)==null?void 0:r.call(i,t))||{enabled:!0},run:e[i.name]}})}function Z3(t=[],e=[],i=[]){const r=new Set;return[...t,...e.map(s=>({...s,source:"preset"})),...i].filter(s=>!(s!=null&&s.name)||r.has(s.name)?!1:(r.add(s.name),!0))}const XC=t=>new Date(t).toLocaleDateString([],{month:"short",day:"numeric"}),xg=t=>new Date(t).toDateString(),Ac=new Map;function Sg(t,e,i){return`${t}:${e}:${i}`}function Ec(t,e){return`${t}:${e}`}const JC=(t,e)=>t!=null&&t.length===e.length&&(t.length===0||JSON.stringify(t[t.length-1])===JSON.stringify(e[e.length-1])),ZC='button, summary, a, input, textarea, select, option, label, [role], [contenteditable]:not([contenteditable="false"])',QC=new Set(["Backspace","Delete","Enter","ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End","PageUp","PageDown"]),Ar=Object.freeze({NORMAL:0,WORD:1,LINE:2}),x0=()=>typeof Highlight<"u"&&typeof CSS<"u"&&!!CSS.highlights,eA=()=>{x0()&&CSS.highlights.delete("timeline-sel")},tA=()=>x0()&&typeof document.caretRangeFromPoint=="function",iA=t=>{const e=document.getSelection();if(!t||!e||e.rangeCount===0)return;const i=r=>!!r&&t.contains(r);(i(e.anchorNode)||i(e.focusNode))&&e.removeAllRanges()},kg=t=>!x0()||!t||t.collapsed?!1:(CSS.highlights.set("timeline-sel",new Highlight(t)),!0),rA=t=>{let e=!1;const i=s=>{if(s.clipboardData)try{s.clipboardData.setData("text/plain",t),s.preventDefault(),e=!0}catch{}};document.addEventListener("copy",i,!0);let r=!1;try{r=document.execCommand("copy")===!0}catch{}return document.removeEventListener("copy",i,!0),e&&r},sA=async t=>{var e;try{if(typeof((e=navigator.clipboard)==null?void 0:e.writeText)=="function")return await navigator.clipboard.writeText(t),!0}catch{}return rA(t)},Nu=(t,e,i)=>{var s;const r=(s=document.caretRangeFromPoint)==null?void 0:s.call(document,e,i);return r&&t.contains(r.startContainer)?r:null},Cg=(t,e,i)=>{const r=Nu(t,e,i),s=r==null?void 0:r.startContainer;if(!s||s.nodeType!==Node.TEXT_NODE||!s.data)return null;const n=Math.min(r.startOffset,s.data.length);let o=null;if(typeof Intl.Segmenter=="function"){const l=[...new Intl.Segmenter(void 0,{granularity:"word"}).segment(s.data)];o=l.find(({index:u,segment:c,isWordLike:h})=>h&&u<=n&&n<u+c.length)||l.findLast(({index:u,segment:c,isWordLike:h})=>h&&u<n&&n<=u+c.length),o&&(o=[o.index,o.index+o.segment.length])}if(!o){const l=h=>/[\p{L}\p{M}\p{N}_]/u.test(h);let u=Math.min(n,s.data.length-1);if(!l(s.data[u])&&u>0&&l(s.data[u-1])&&(u-=1),!l(s.data[u]))return null;let c=u+1;for(;u>0&&l(s.data[u-1]);)u-=1;for(;c<s.data.length&&l(s.data[c]);)c+=1;o=[u,c]}const a=document.createRange();return a.setStart(s,o[0]),a.setEnd(s,o[1]),a},Ag=(t,e,i)=>{const r=Nu(t,e,i),s=r==null?void 0:r.startContainer,n=(s==null?void 0:s.nodeType)===Node.ELEMENT_NODE?s:s==null?void 0:s.parentElement,o=n==null?void 0:n.closest(".m-ev-note, .tx-quote-text");if(!o||!t.contains(o))return null;const a=document.createRange();return a.selectNodeContents(o),a},nA=(t,e,i)=>{const r=t.compareBoundaryPoints(Range.START_TO_START,e)<=0,s=r?t:e,n=r?e:t,o=document.createRange();return o.setStart(s.startContainer,s.startOffset),i===Ar.NORMAL?o.setEnd(n.startContainer,n.startOffset):o.setEnd(n.endContainer,n.endOffset),o};function oA({session:t,state:e,active:i,inputRef:r,draft:s,setDraft:n,sending:o,send:a,sendErr:l,sendNote:u,onRestore:c,actionOutcome:h,onComposerPress:d,working:f=!1,stopping:m=!1,stop:v,specs:_=[],sessions:w=[],boardCommands:x=[]}){const A=He(),D=e!=="live",R=!D&&f,{launchers:E}=Y3(),L=X3(),q=J3(t==null?void 0:t.harness),F=k.useMemo(()=>Z3(x,L,q),[x,L,q]),$=gd({inputRef:r,value:s,setValue:n,specs:_,sessions:w,launchers:E,up:!0,slash:{commands:F,mode:"line",head:A("session.menuCommands"),onPick:C=>{var O;return C.ui?(n(""),(O=C.run)==null||O.call(C),!0):!1}}}),W=_d({inputRef:r,setValue:n,variant:"command",disabled:D}),z=C=>U3(r.current,C,n,$.sync),j=()=>{var T;if(D)return;const C=s.trim();if(!C)return;const O=W3(C,F);if(O){n(""),$.close(),(T=O.run)==null||T.call(O);return}a(q3(C,_))};return p.jsx(H3,{as:"footer",className:`m-composer is-${e}${W.dragging?" dragover":""}`,"data-footer-state":e,...W.dropProps,preview:(l||u)&&p.jsx("div",{className:l?"m-senderr":"m-sendnote",children:l||u}),editor:!D&&p.jsxs(p.Fragment,{children:[p.jsxs("div",{className:"m-composer-line fv-tawrap",children:[p.jsx(fd,{ref:r,className:"m-input","data-focus-sink":i&&!D?"":void 0,rows:1,placeholder:A("mobile.inputPlaceholder"),value:s,onMouseDownCapture:d,onChange:C=>{n(C.target.value),$.sync(C.target)},onSelect:C=>$.sync(C.target),onBlur:$.close,onPaste:W.onPaste,onKeyDown:C=>{da(C)||$.onKeyDown(C)||!D&&C.key==="Enter"&&!C.shiftKey&&!da(C)&&(C.preventDefault(),C.stopPropagation(),j())}}),$.menuEl]}),W.queue]}),footer:p.jsxs(p.Fragment,{children:[!D&&p.jsxs(p.Fragment,{children:[W.fileInput,p.jsxs("div",{className:"si-command-tools m-composer-tools",children:[p.jsxs("span",{className:"si-command-title",children:[p.jsx(je,{name:"command",size:12}),A("session.commandBox")]}),p.jsx("button",{type:"button",className:"fv-trigger-btn","data-tip":A("thread.mentionActor"),"aria-label":A("thread.mentionActor"),onMouseDown:C=>C.preventDefault(),onClick:()=>z("@"),children:"@"}),p.jsx("button",{type:"button",className:"fv-trigger-btn","data-tip":A("thread.mentionNode"),"aria-label":A("thread.mentionNode"),onMouseDown:C=>C.preventDefault(),onClick:()=>z("[["),children:"[["}),p.jsx("button",{type:"button",className:"fv-trigger-btn","data-tip":A("session.menuCommands"),"aria-label":A("session.menuCommands"),onMouseDown:C=>C.preventDefault(),onClick:()=>z("/"),children:"/"}),p.jsx(Zt,{icon:W.busy?"loader":"paperclip",size:14,iconClassName:W.busy?"si-attach-busy":void 0,className:"si-command-tool",label:A("session.attachTitle"),disabled:W.busy,onClick:W.pick}),R&&p.jsx(Zt,{icon:"stop",size:12,className:"m-stop",label:A("mobile.stop"),disabled:m,onMouseDown:C=>C.preventDefault(),onClick:v}),p.jsx(Zt,{icon:"send",size:14,className:"m-send",label:A("mobile.send"),disabled:!s.trim()||o,onMouseDown:C=>C.preventDefault(),onClick:j})]})]}),D&&p.jsxs("div",{className:"m-coldline",children:[p.jsx("span",{children:A(e==="archived"?"session.archivedReadOnly":"session.offlineReadOnly")}),c&&p.jsx("button",{type:"button",className:"m-coldline-action",disabled:(h==null?void 0:h.phase)==="pending",onClick:c,children:A(e==="archived"?"session.shelfRestore":"session.relaunch")})]}),D&&h&&p.jsx("div",{className:`si-action-outcome ${h.phase}`,role:h.phase==="failed"?"alert":"status",children:h.message})]})})}function aA({s:t,sessions:e=[],active:i=!0,footerState:r="live",onRestore:s,actionOutcome:n,specs:o=[],boardCommands:a=[]}){var Hn,ye;const l=He(),u=t_(),[c,h]=k.useState(null),[d,f]=k.useState(null),[m,v]=k.useState(""),[_,w]=k.useState(!1),[x,A]=k.useState(!1),[D,R]=k.useState(null),[E,L]=k.useState(null),[q,F]=k.useState(null),[$,W]=k.useState(()=>new Set),[z,j]=k.useState(()=>new Map),[C,O]=k.useState(null),[T,U]=k.useState(()=>Date.now()),H=k.useRef(null),re=k.useRef(null),G=k.useRef(null),X=k.useRef(null),oe=k.useRef(null),I=k.useRef(null),Y=k.useRef(new Map),le=k.useRef(new Map),te=J=>{let Q=le.current.get(J);return Q||(Q=Ee=>{const Me=`${J}:${Ee}`;let We=Y.current.get(Me);return We||(We=H5(t.id,J,Ee),Y.current.set(Me,We)),We.then(Xe=>{var Oe;return Xe.ok?{ok:!0,output:((Oe=Xe.data)==null?void 0:Oe.output)??null}:{ok:!1,error:Xe.error}})},le.current.set(J,Q)),Q},[de,ke]=k.useState(()=>Date.now()),Ye=k.useRef(0),Ct=k.useRef(new Set),At=k.useRef(new Map),nt=k.useRef(new Map),Be=k.useRef(!0),vt=k.useCallback(()=>F5(t.id).then(J=>{Number.isFinite(J==null?void 0:J.serverNow)&&(Ye.current=J.serverNow-Date.now());const Q=Date.now()+Ye.current;U(Q),ke(Q),J&&h(Ee=>JC(Ee,J.events)?Ee:J.events)}),[t.id]),vr=i&&r==="live"&&t.status==="working";k.useEffect(()=>{if(!vr)return;const J=()=>{document.visibilityState!=="hidden"&&U(Date.now()+Ye.current)};J();const Q=setInterval(J,1e3);return()=>clearInterval(Q)},[vr]),k.useEffect(()=>{h(null),f(null),F(null),L(null),W(new Set),j(new Map),Ct.current.clear(),At.current.clear(),nt.current.clear(),Y.current.clear(),le.current.clear(),O(null),br.current=null,qt.current=!1,Si(!1),U(Date.now()),ke(Date.now()),Be.current=!0},[t.id]),k.useEffect(()=>{i&&(vt(),I5(t.id).then(J=>{J&&f(J)}))},[t.id,vt,i]),k.useEffect(()=>{if(!i||u||document.visibilityState==="hidden")return;const J=requestAnimationFrame(()=>{const Q=G.current;i&&!u&&document.visibilityState!=="hidden"&&(Q==null?void 0:Q.offsetParent)!==null&&getComputedStyle(Q).visibility!=="hidden"&&document.activeElement!==Q&&Q.focus()});return()=>cancelAnimationFrame(J)},[t.id,i,u]),k.useEffect(()=>{if(!i||r==="archived")return;const J=setInterval(vt,8e3);return()=>clearInterval(J)},[vt,i,r]),k.useEffect(()=>{i&&r!=="archived"&&vt()},[t.status,t.note,vt,i,r]);const ht=k.useMemo(()=>SC(c||[],de),[c,de]),Yr=ht.length&&ht[ht.length-1].kind==="seam"&&ht[ht.length-1].open?ht[ht.length-1]:null,Pt=i&&r==="live"&&Yr?Yr.from:null,br=k.useRef(null);k.useEffect(()=>{if(Pt!==null)return br.current!==Pt&&(br.current=Pt,O(null)),z5(t.id,Pt,O)},[t.id,Pt]);const qt=k.useRef(!1),[Ni,Si]=k.useState(!1),Wt=!qt.current&&c!==null&&Pt!==null&&C===null&&!Ni;k.useEffect(()=>{if(!Wt)return;const J=setTimeout(()=>Si(!0),600);return()=>clearTimeout(J)},[Wt]),c!==null&&!Wt&&(qt.current=!0);const Gi=k.useMemo(()=>{for(let J=ht.length-1;J>=0;J--)if(ht[J].kind==="say"&&ht[J].text)return ht[J].text;return null},[ht]),Yi=k.useCallback(async(J,Q)=>{const Ee=Sg(t.id,J.from,J.to);At.current.set(Q,Ee);const Me=Ac.get(Ee);if(Me){j(Pe=>new Map(Pe).set(Q,{...Me,transcriptKey:Ee}));return}if(Ct.current.has(Ee))return;Ct.current.add(Ee),j(Pe=>{var Oi;return((Oi=Pe.get(Q))==null?void 0:Oi.state)==="ready"?Pe:new Map(Pe).set(Q,{state:"loading",transcriptKey:Ee})});const We=await j5(t.id,J.from,J.to);Ct.current.delete(Ee);const Xe=We.ok?{state:"ready",data:We.data,transcriptKey:Ee}:{state:"error",error:We.error,transcriptKey:Ee},Oe=nt.current.get(Q);Oe&&Oe!==Ee&&Ac.delete(Oe),Ac.set(Ee,Xe),nt.current.set(Q,Ee),j(Pe=>{if(At.current.get(Q)!==Ee)return Pe;const Oi=Pe.get(Q);return!We.ok&&(Oi==null?void 0:Oi.state)==="ready"?new Map(Pe).set(Q,{...Oi,transcriptKey:Ee}):new Map(Pe).set(Q,Xe)})},[t.id]);k.useEffect(()=>{if(!(!i||!c))for(const J of ht){if(J.kind!=="seam"||J.open&&J.from===Pt)continue;const Q=Ec(t.id,J.from);if(!$.has(Q))continue;const Ee=Sg(t.id,J.from,J.to),Me=z.get(Q);(Me==null?void 0:Me.transcriptKey)===Ee||Ct.current.has(Ee)||Yi(J,Q)}},[i,c,ht,$,Yi,t.id,z,Pt]);const ce=k.useCallback(()=>{const J=H.current;J&&Be.current&&(J.scrollTop=J.scrollHeight)},[]),Ae=()=>{const J=H.current;J&&(Be.current=J.scrollHeight-J.scrollTop-J.clientHeight<48)};k.useLayoutEffect(ce,[c,ce]),k.useLayoutEffect(()=>{if(!i||typeof ResizeObserver!="function")return;const J=re.current;if(!J)return;const Q=new ResizeObserver(ce);return Q.observe(J),()=>Q.disconnect()},[i,ce]);const Re=()=>{oe.current=null,eA(),iA(H.current),F(null)},$e=k.useCallback(async J=>{clearTimeout(I.current),F(null);const Q=await sA(J);return F(Q?"copied":"failed"),Q&&(I.current=setTimeout(()=>F(null),1200)),Q},[]);k.useEffect(()=>()=>clearTimeout(I.current),[]);const zn=J=>{const Q=H.current,Ee=J.target;if(J.button!==0||!Q||!(Ee instanceof Element)||!tA())return;const Me=Ee.closest(ZC);if(Me&&Q.contains(Me))return;if(Ee===Q){const Oe=Q.getBoundingClientRect();if(J.clientX-Oe.left-Q.clientLeft>=Q.clientWidth||J.clientY-Oe.top-Q.clientTop>=Q.clientHeight)return}Re(),J.preventDefault();const We=J.detail===2?Ar.WORD:J.detail>=3?Ar.LINE:Ar.NORMAL,Xe=We===Ar.WORD?Cg(Q,J.clientX,J.clientY):We===Ar.LINE?Ag(Q,J.clientX,J.clientY):Nu(Q,J.clientX,J.clientY);Xe&&(X.current={mode:We,anchor:Xe.cloneRange(),x:J.clientX,y:J.clientY},We!==Ar.NORMAL&&(oe.current=Xe,kg(Xe)))};k.useEffect(()=>{if(!i)return;const J=Me=>{const We=X.current,Xe=H.current;if(!We||!Xe||(Me.preventDefault(),We.mode===Ar.NORMAL&&Math.hypot(Me.clientX-We.x,Me.clientY-We.y)<3))return;const Oe=We.mode===Ar.WORD?Cg(Xe,Me.clientX,Me.clientY):We.mode===Ar.LINE?Ag(Xe,Me.clientX,Me.clientY):Nu(Xe,Me.clientX,Me.clientY);if(!Oe||!We.anchor.startContainer.isConnected)return;const Pe=nA(We.anchor,Oe,We.mode);oe.current=Pe,kg(Pe)},Q=()=>{X.current=null},Ee=Me=>{const We=oe.current,Xe=G.current;if(!We||We.collapsed||!Xe)return;const Oe=Me.ctrlKey||Me.metaKey,Pe=Me.key.toLowerCase();if(Me.key==="Escape"){Re();return}if(Oe&&Pe==="c"){if(document.activeElement!==Xe||Xe.selectionStart!==Xe.selectionEnd)return;Me.preventDefault(),Me.stopPropagation(),$e(cC(We,H.current));return}if(document.activeElement!==Xe)return;const Oi=Me.key.length===1&&!Oe&&!Me.altKey,tn=Oe&&!Me.altKey&&["a","v","x","y","z"].includes(Pe),$n=Me.isComposing||Me.key==="Process"||Me.key==="Dead";(Oi||tn||$n||QC.has(Me.key))&&Re()};return document.addEventListener("mousemove",J,!0),document.addEventListener("mouseup",Q,!0),document.addEventListener("keydown",Ee,!0),()=>{X.current=null,Re(),document.removeEventListener("mousemove",J,!0),document.removeEventListener("mouseup",Q,!0),document.removeEventListener("keydown",Ee,!0)}},[i,$e]);const _r=()=>Re(),il=async J=>{var Ee,Me;if(!J||_)return;w(!0),R(null);const Q=await f4(t.id,J,{replyVia:"note"});w(!1),Q.ok?(v(""),L(((Ee=Q.outcome)==null?void 0:Ee.mentionSummary)||null),vt()):R(((Me=Q.outcome)==null?void 0:Me.error)||l("mobile.sendFailed"))},Zs=async()=>{if(x)return;A(!0),R(null);const J=await $5(t.id);A(!1),J.ok?vt():R(J.error||l("mobile.stopFailed"))},rl=J=>{if(!J)return l("mobile.you");const Q=e.find(Ee=>Ee.id===J);return Q?Hr(Q):J.slice(0,8)},Qs=J=>{const Q=Ec(t.id,J.from),Ee=new Set($);if(Ee.has(Q)){Ee.delete(Q),W(Ee);return}Ee.add(Q),W(Ee),J.open&&J.from===Pt||Yi(J,Q)},Xi=[];let Li=null;const jn=(J,Q)=>{xg(J)!==Li&&(Li=xg(J),Xi.push(p.jsxs("div",{className:"m-day",children:[p.jsx("div",{className:"m-gut",children:XC(J)}),p.jsx("div",{className:"m-day-rule"})]},`d${Q}`)))},Ft=J=>p.jsx("div",{className:"m-gut",children:p.jsx("time",{children:cu(J)})}),en=t.created||(d==null?void 0:d.created)||((Hn=c==null?void 0:c[0])==null?void 0:Hn.ts);d!=null&&d.prompt&&(en&&jn(en,"p"),Xi.push(p.jsxs("div",{className:"m-ev m-ev-prompt",children:[p.jsx(Wh,{ts:en,text:d.prompt}),en?Ft(en):p.jsx("div",{className:"m-gut"})]},"prompt")));for(const[J,Q]of ht.entries())if(jn(Q.ts,J),Q.kind==="quote")Xi.push(p.jsxs("div",{className:"m-ev m-ev-sent",children:[p.jsx(Wh,{who:Q.from?((ye=Q.envelope)==null?void 0:ye.label)||rl(Q.from):null,ts:Q.ts,text:Q.text}),Ft(Q.ts)]},J));else if(Q.kind==="say")Xi.push(p.jsxs("div",{className:"m-ev m-ev-say",children:[p.jsx("div",{className:"m-gut"}),p.jsxs("article",{className:"m-say",children:[p.jsxs("div",{className:"m-say-head",children:[p.jsx("time",{className:"m-line-time",children:cu(Q.ts)}),p.jsxs("span",{className:"m-say-chip",style:{color:lr[Q.status]},children:[p.jsx("span",{className:"m-ev-glyph",children:Au[Q.status]||"·"}),p.jsx("span",{className:"m-ev-word",children:l(`status.${Q.status}`)})]}),Q.text&&!x0()&&p.jsx("button",{type:"button",className:"m-copy-note",onClick:()=>$e(Q.text),children:l("mobile.copy")})]}),Q.text&&p.jsx("div",{className:"m-ev-note",children:p.jsx(pd,{children:Q.text})})]})]},J));else if(Q.kind==="event")Xi.push(p.jsxs("div",{className:"m-ev m-ev-line",children:[p.jsx("div",{className:"m-gut"}),p.jsxs("div",{className:"m-line",children:[p.jsx("time",{className:"m-line-time",children:cu(Q.ts)}),p.jsx("span",{className:"m-ev-glyph",style:{color:lr[Q.status]},children:Au[Q.status]||"·"}),p.jsx("span",{className:"m-ev-word",style:{color:lr[Q.status]},children:l(`status.${Q.status}`)}),Q.text&&p.jsx("div",{className:"m-line-text m-ev-note",children:p.jsx(pd,{children:Q.text})})]})]},J));else{const Ee=Ec(t.id,Q.from),Me=$.has(Ee),We=Q.open&&r==="live",Xe=Q.open&&Q.from===Pt,Oe=Xe?C===null?{state:"loading"}:C.error?{state:"error",error:C.error}:{state:"ready",data:C}:z.get(Ee),Pe=We?`${l("status.working")} · ${Qp(Math.max(0,T-Q.from))}`:Q.open?l("status.working"):`${l("mobile.worked")} ${Qp(Q.to-Q.from)}`,Oi=(Oe==null?void 0:Oe.state)==="ready"?Oe.data.turns.reduce((tn,$n)=>{var Lo;return tn+(((Lo=$n.tools)==null?void 0:Lo.length)||0)},0):0;Xi.push(p.jsxs("div",{className:"m-ev m-ev-seam",children:[p.jsx("div",{className:"m-gut"}),p.jsxs("div",{className:"m-seam",children:[p.jsxs("button",{type:"button",className:`m-seam-row${We?" is-live":""}`,"aria-expanded":Me,onClick:()=>Qs(Q),children:[p.jsx("span",{className:"m-seam-lead",children:Pe}),(Oe==null?void 0:Oe.state)==="ready"&&p.jsxs("span",{className:"m-seam-detail",children:[Oe.data.turns.length," turns · ",Oi," tool uses"]}),p.jsx(d4,{open:Me,className:"m-seam-caret"})]}),p.jsxs(hg,{loadToolOutput:te(Q.from),children:[Me&&p.jsxs("div",{className:"m-seam-inset",children:[(Oe==null?void 0:Oe.state)==="loading"&&p.jsx("div",{className:"m-transcript-state",children:"transcript 加载中…"}),(Oe==null?void 0:Oe.state)==="error"&&p.jsxs("div",{className:"m-transcript-state is-error",children:["transcript 已不可用:",Oe.error]}),(Oe==null?void 0:Oe.state)==="ready"&&p.jsx(Q7,{data:Oe.data,live:Xe})]}),Xe&&!Me&&p.jsx(ew,{turns:C==null?void 0:C.turns,revision:C==null?void 0:C.revision,lastSaid:Gi},Ee)]})]})]},J))}return p.jsx(hg,{children:p.jsxs("div",{className:"tl-chat",children:[p.jsx("div",{className:"m-timeline","data-selectable":!0,ref:H,onScroll:Ae,onMouseDown:zn,children:p.jsx("div",{className:"m-col",ref:re,children:c===null||Wt?p.jsx("div",{className:"m-empty",children:l("common.loading")}):Xi.length===0?p.jsx("div",{className:"m-empty",children:l("mobile.noEvents")}):Xi})}),q&&p.jsx("div",{className:`m-copy-status ${q}`,role:"status","aria-live":"polite","aria-atomic":"true",children:l(`mobile.${q==="copied"?"copied":"copyFailed"}`)}),p.jsx(oA,{session:t,state:r,active:i,inputRef:G,draft:m,setDraft:v,sending:_,send:il,sendErr:D,sendNote:E,onRestore:s,actionOutcome:n,onComposerPress:_r,working:t.status==="working",stopping:x,stop:Zs,specs:o,sessions:e,boardCommands:a})]})})}let yd=[],Q3=[];(()=>{let t="lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,1n,9,16,o,,x,1i,3,,i,,7,a,2,t,3,1k,,,7,2,2,2,3,9,,a,2,q,,2,3,1k,,,5,4,2,2,3,3,,u,2,3,,b,3,1k,,,8,,3,,3,k,2,m,6,,3,1k,,,7,2,2,2,3,7,3,a,2,u,,1n,5,3,3,,4,9,,14,5,1j,,,7,,3,,4,7,2,b,2,t,3,1k,,,7,,3,,4,7,2,b,2,f,,c,4,1j,2,,7,,3,,4,9,,a,2,t,3,1y,,4,6,,,,8,i,2,1p,,,8,c,8,2q,,,a,b,7,21,2,r,,,,,,4,2,1d,k,,2,5,b,,10,9,,2u,b,,6,n,4,4,3,g,4,d,,,3,6,,f,,jj,3,qa,4,s,3,t,2,u,2,1s,w,9,,19,3,,,39,2,y,,3a,c,4,c,63,5,1l,a,,,,,2,o,2,,1c,1a,2,c,k,5,1b,h,12,9,c,3,u,d,1k,e,1c,k,48,3,,l,4,,6,,2,3,5i,1s,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,n,5,4,,2b,2,1e,i,q,i,d,,12,8,p,d,18,4,1b,e,10,,1v,e,c,,8,2,1a,,1f,,,3,2,2,5,2,,,15,5,5,2,6k,8,,2,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,1t,5,8t,2,25,6,1y,b,1d,4,3e,3,1h,f,15,,2,2,a,4,19,b,7,,1p,3,10,e,g,2,18,,c,3,1c,e,8,4,,2,2k,c,6,,2,,4d,c,l,4,1j,2,,7,2,2,2,3,9,,a,2,2,7,3,5,1v,9,,,2,,,4,,5,,,e,2,2a,i,n,,29,k,6j,7,2,9,r,2,2a,h,2y,d,2t,3,2,a,74,f,6t,6,,2,2,4,,,,2,3x,7,2,7,3,,s,a,14,7,,4,8,,9,b,1a,g,5i,8,5j,8,,8,2a,m,,e,3e,6,3,,,2,,7,,,1u,5,,2,,5,9n,4,9,2,,,1c,7,3,5,n,,44l,,6,f,8ug,i,1xc,5,1n,7,t4,,,1j,7,4,29,,b,2,f57,2,3mp,1a,2,n,f2,5,3,6,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,2s,,4g,7,af,,1p,4,e4,4,72,2,6r,,2,,7,2,5,,d6,7,31,7,240,5".split(",").map(e=>e?parseInt(e,36):1);for(let e=0,i=0;e<t.length;e++)(e%2?Q3:yd).push(i=i+t[e])})();function lA(t){if(t<768)return!1;for(let e=0,i=yd.length;;){let r=e+i>>1;if(t<yd[r])i=r;else if(t>=Q3[r])e=r+1;else return!0;if(e==i)return!1}}function Eg(t){return t>=127462&&t<=127487}const Dg=8205;function uA(t,e,i=!0,r=!0){return(i?eb:cA)(t,e,r)}function eb(t,e,i){if(e==t.length)return e;e&&tb(t.charCodeAt(e))&&ib(t.charCodeAt(e-1))&&e--;let r=Dc(t,e);for(e+=Mg(r);e<t.length;){let s=Dc(t,e);if(r==Dg||s==Dg||i&&lA(s))e+=Mg(s),r=s;else if(Eg(s)){let n=0,o=e-2;for(;o>=0&&Eg(Dc(t,o));)n++,o-=2;if(n%2==0)break;e+=2}else break}return e}function cA(t,e,i){for(;e>1;){let r=eb(t,e-2,i);if(r<e)return r;e--}return 0}function Dc(t,e){let i=t.charCodeAt(e);if(!ib(i)||e+1==t.length)return i;let r=t.charCodeAt(e+1);return tb(r)?(i-55296<<10)+(r-56320)+65536:i}function tb(t){return t>=56320&&t<57344}function ib(t){return t>=55296&&t<56320}function Mg(t){return t<65536?1:2}let Ve=class rb{lineAt(e){if(e<0||e>this.length)throw new RangeError(`Invalid position ${e} in document of length ${this.length}`);return this.lineInner(e,!1,1,0)}line(e){if(e<1||e>this.lines)throw new RangeError(`Invalid line number ${e} in ${this.lines}-line document`);return this.lineInner(e,!0,1,0)}replace(e,i,r){[e,i]=_o(this,e,i);let s=[];return this.decompose(0,e,s,2),r.length&&r.decompose(0,r.length,s,3),this.decompose(i,this.length,s,1),Tr.from(s,this.length-(i-e)+r.length)}append(e){return this.replace(this.length,this.length,e)}slice(e,i=this.length){[e,i]=_o(this,e,i);let r=[];return this.decompose(e,i,r,0),Tr.from(r,i-e)}eq(e){if(e==this)return!0;if(e.length!=this.length||e.lines!=this.lines)return!1;let i=this.scanIdentical(e,1),r=this.length-this.scanIdentical(e,-1),s=new fa(this),n=new fa(e);for(let o=i,a=i;;){if(s.next(o),n.next(o),o=0,s.lineBreak!=n.lineBreak||s.done!=n.done||s.value!=n.value)return!1;if(a+=s.value.length,s.done||a>=r)return!0}}iter(e=1){return new fa(this,e)}iterRange(e,i=this.length){return new sb(this,e,i)}iterLines(e,i){let r;if(e==null)r=this.iter();else{i==null&&(i=this.lines+1);let s=this.line(e).from;r=this.iterRange(s,Math.max(s,i==this.lines+1?this.length:i<=1?0:this.line(i-1).to))}return new nb(r)}toString(){return this.sliceString(0)}toJSON(){let e=[];return this.flatten(e),e}constructor(){}static of(e){if(e.length==0)throw new RangeError("A document must have at least one line");return e.length==1&&!e[0]?rb.empty:e.length<=32?new St(e):Tr.from(St.split(e,[]))}};class St extends Ve{constructor(e,i=hA(e)){super(),this.text=e,this.length=i}get lines(){return this.text.length}get children(){return null}lineInner(e,i,r,s){for(let n=0;;n++){let o=this.text[n],a=s+o.length;if((i?r:a)>=e)return new dA(s,a,r,o);s=a+1,r++}}decompose(e,i,r,s){let n=e<=0&&i>=this.length?this:new St(Tg(this.text,e,i),Math.min(i,this.length)-Math.max(0,e));if(s&1){let o=r.pop(),a=pu(n.text,o.text.slice(),0,n.length);if(a.length<=32)r.push(new St(a,o.length+n.length));else{let l=a.length>>1;r.push(new St(a.slice(0,l)),new St(a.slice(l)))}}else r.push(n)}replace(e,i,r){if(!(r instanceof St))return super.replace(e,i,r);[e,i]=_o(this,e,i);let s=pu(this.text,pu(r.text,Tg(this.text,0,e)),i),n=this.length+r.length-(i-e);return s.length<=32?new St(s,n):Tr.from(St.split(s,[]),n)}sliceString(e,i=this.length,r=`
|
|
316
|
+
`).length-1:1;return{source:e.slice(i[0].length),removedLines:r}}const I3=t=>/^(?:https?:|mailto:|#|\/)/i.test(String(t||""))?String(t):null,Ei=(t,e)=>{const i=t==null?void 0:t.map;return!i||!Number.isInteger(e)||e<=0?{}:{"data-l0":e+i[0],"data-l1":e+i[1]-1}},Sn=(t,e)=>{var i;return((i=t==null?void 0:t.attrGet)==null?void 0:i.call(t,e))??null},ag=t=>{if(!t)return;const e={};for(const i of String(t).split(";")){const r=i.indexOf(":");if(r<0)continue;const s=i.slice(0,r).trim(),n=i.slice(r+1).trim();if(!s||!n)continue;const o=s.startsWith("--")?s:s.replace(/-([a-z])/g,(a,l)=>l.toUpperCase());e[o]=n}return Object.keys(e).length?e:void 0},qo=new Map,nC=512,oC=(t,e)=>{const i=`${e?"d":"i"}\0${t}`;if(qo.has(i))return qo.get(i);let r=null;try{r=Xk.renderToString(t,{...Jk,displayMode:e})}catch{r=null}return qo.size>=nC&&qo.clear(),qo.set(i,r),r},z3=(t,e,i,r={})=>{const s=oC(e.content,i);return s===null?t(i?"pre":"span",{...r,className:"doc-math-error"},e.content):t(i?"div":"span",{...r,className:i?"doc-math-block":"doc-math","data-math-source":e.content,dangerouslySetInnerHTML:{__html:s}})},lg=(t,e,i,r)=>{const s=Ei(e,r.lineBase);if(e.type==="link_open"){const n=I3(Sn(e,"href"));return n?t("a",{...s,className:"doc-link doc-external",href:n,target:"_blank",rel:"noreferrer"},i):i}return e.type==="strong_open"?t("strong",s,i):e.type==="em_open"?t("em",s,i):e.type==="s_open"?t("del",s,i):i},aC=(t,e=[],i)=>{var o,a;const r=[],s=[{token:null,children:r}],n=()=>s[s.length-1].children;for(const l of e)if(l.type==="text")n().push(l.content);else if(l.type==="hardbreak")n().push(t("br"));else if(l.type==="softbreak")n().push(i.softBreak==="break"?t("br"):" ");else if(l.type==="code_inline")n().push(t("code",Ei(l,i.lineBase),l.content));else if(l.type==="prose_math_inline")n().push(z3(t,l,!1,Ei(l,i.lineBase)));else if(l.type==="prose_spec_ref"){const u=(o=i.renderSpecRef)==null?void 0:o.call(i,l.meta.id,l,Ei(l,i.lineBase));n().push(u??t("span",{...Ei(l,i.lineBase),className:"doc-ref","data-spec-id":l.meta.id},l.meta.id))}else if(l.type==="prose_evidence"){const u=(a=i.renderEvidence)==null?void 0:a.call(i,l.meta,l,Ei(l,i.lineBase));n().push(u??t("a",{...Ei(l,i.lineBase),className:"doc-evidence",href:l.meta.src,"data-evidence-hash":l.meta.hash},l.meta.alt))}else if(l.type==="image"){const u=I3(Sn(l,"src"));n().push(u?t("img",{...Ei(l,i.lineBase),className:"doc-image",src:u,alt:l.content||Sn(l,"alt")||"",title:Sn(l,"title")||void 0}):l.content)}else if(l.type==="link_open"||l.type==="strong_open"||l.type==="em_open"||l.type==="s_open")s.push({token:l,children:[]});else if(l.type==="link_close"||l.type==="strong_close"||l.type==="em_close"||l.type==="s_close"){if(s.length===1)continue;const u=s.pop();n().push(lg(t,u.token,u.children,i))}for(;s.length>1;){const l=s.pop();n().push(lg(t,l.token,l.children,i))}return r},ug=(t,e,i,r)=>{const s=Ei(e,r.lineBase);switch(e.type){case"paragraph_open":return t("p",s,i);case"heading_open":return t(e.tag,{...s,className:`doc-h doc-h-level doc-h${e.tag.slice(1)}`},i);case"blockquote_open":return t("blockquote",{...s,className:"doc-quote"},i);case"bullet_list_open":return t("ul",s,i);case"ordered_list_open":return t("ol",{...s,start:Sn(e,"start")||void 0},i);case"list_item_open":return t("li",s,i);case"table_open":return t("table",{...s,className:"doc-table"},i);case"thead_open":return t("thead",s,i);case"tbody_open":return t("tbody",s,i);case"tr_open":return t("tr",s,i);case"th_open":return t("th",{...s,style:ag(Sn(e,"style"))},i);case"td_open":return t("td",{...s,style:ag(Sn(e,"style"))},i);default:return i}};function lC(t,e={}){var o,a;const i=e.h;if(typeof i!="function")throw new TypeError("renderProseTokens requires a React-compatible h function");const r=[],s=[{token:null,children:r}],n=()=>s[s.length-1].children;for(const l of t||[])if(l.type==="inline")n().push(...aC(i,l.children,e));else if(l.type==="fence"||l.type==="code_block"){const u=(o=l.info)==null?void 0:o.trim().split(/\s+/,1)[0];n().push(i("pre",{...Ei(l,e.lineBase),className:"doc-pre"},i("code",{className:u?`language-${u}`:void 0},l.content)))}else if(l.type==="prose_math_block")n().push(z3(i,l,!0,Ei(l,e.lineBase)));else if(l.type==="prose_time_anchor"){const u=(a=e.renderTimeAnchor)==null?void 0:a.call(e,l.meta,l,Ei(l,e.lineBase));n().push(u??i("span",{...Ei(l,e.lineBase),className:"fv-anchor static","data-time-ms":l.meta.tMs},l.meta.label))}else if(l.type==="hr")n().push(i("hr",Ei(l,e.lineBase)));else if(l.type==="html_block"||l.type==="html_inline")n().push(l.content);else if(l.nesting===1)s.push({token:l,children:[]});else if(l.nesting===-1){if(s.length===1)continue;const u=s.pop();n().push(ug(i,u.token,u.children,e))}for(;s.length>1;){const l=s.pop();n().push(ug(i,l.token,l.children,e))}return r}function uC({children:t,className:e="",lineBase:i=0,softBreak:r,renderSpecRef:s,renderEvidence:n,renderTimeAnchor:o}){const a=k.useMemo(()=>{try{return sC(t)}catch{return null}},[t]),l=a?lC(a,{h:(()=>{let u=0;return(c,h,...d)=>{const f=h!==null&&typeof h=="object"&&!Array.isArray(h),m=f?{...h,key:h.key??`prose-${u++}`}:{key:`prose-${u++}`};return f?k.createElement(c,m,...d):k.createElement(c,m,h,...d)}})(),lineBase:i,softBreak:r,renderSpecRef:s,renderEvidence:n,renderTimeAnchor:o}):k.createElement("p",null,t==null?"":String(t));return k.createElement("div",{className:e},l)}function j3({children:t,className:e="",softBreak:i,renderSpecRef:r,renderEvidence:s,renderTimeAnchor:n}){const o=r||((l,u,c)=>k.createElement("span",{className:"doc-ref","data-spec-id":l,...c},l)),a=s||((l,u,c)=>k.createElement("a",{className:"doc-evidence",href:l.src,"data-evidence-hash":l.hash,...c},l.alt||l.hash));return k.createElement(uC,{className:`rich-text${e?` ${e}`:""}`,softBreak:i,renderSpecRef:o,renderEvidence:a,renderTimeAnchor:n},t)}const cg=t=>{const e=document.createRange();return e.selectNode(t),e};function cC(t,e){if(!t||t.collapsed||!e)return"";const i=[...e.querySelectorAll("[data-math-source]")].filter(a=>t.intersectsNode(a));if(!i.length)return t.toString();const r=[];let s=t.startContainer,n=t.startOffset;for(const[a,l]of i.entries()){const u=cg(l),c=t.compareBoundaryPoints(Range.START_TO_START,u)<=0;if(a>0||c){const d=document.createRange();d.setStart(s,n),d.setEndBefore(l),r.push(d.toString())}r.push(l.getAttribute("data-math-source")||"");const h=document.createRange();h.setStartAfter(l),h.collapse(!0),s=h.startContainer,n=h.startOffset}const o=cg(i[i.length-1]);if(t.compareBoundaryPoints(Range.END_TO_END,o)>=0){const a=document.createRange();a.setStart(s,n),a.setEnd(t.endContainer,t.endOffset),r.push(a.toString())}return r.join("")}function hC(t,e,i=0,r){if(!t)return;const s=r||getComputedStyle(t),n=s.boxSizing==="border-box"?(parseFloat(s.borderTopWidth)||0)+(parseFloat(s.borderBottomWidth)||0):0,o=t.placeholder;!t.value&&o&&(t.placeholder=""),t.style.height="auto";const a=t.scrollHeight+n;t.style.overflowY=a>e?"auto":"hidden",t.style.height=`${Math.min(Math.max(a,i),e)}px`,t.placeholder!==o&&(t.placeholder=o)}function da(t){var e,i;return t.isComposing||((e=t.nativeEvent)==null?void 0:e.isComposing)||t.keyCode===229||((i=t.nativeEvent)==null?void 0:i.keyCode)===229}const fd=k.forwardRef(function({value:e,className:i="",...r},s){const n=k.useRef(null);return k.useImperativeHandle(s,()=>n.current),k.useLayoutEffect(()=>{const o=n.current;if(!o)return;const a=getComputedStyle(o);hC(o,parseFloat(a.maxHeight)||1/0,parseFloat(a.minHeight)||0,a)},[e]),p.jsx("textarea",{ref:n,value:e,className:`composer-textarea ${i}`.trim(),...r})}),H3=k.forwardRef(function({as:e="div",className:i="",preview:r=null,editor:s,footer:n,...o},a){return p.jsxs(e,{ref:a,className:`composer-surface ${i}`.trim(),...o,children:[r,p.jsx("div",{className:"composer-editor",children:s}),p.jsx("div",{className:"composer-footer",children:n})]})}),bo=t=>Di(`/api/evidence/${t}`);function dC({src:t,alt:e,onClose:i}){return ni(!0,i),p.jsx("div",{className:"lightbox",onClick:i,children:p.jsx("img",{src:t,alt:e})})}function fC({hash:t}){const e=He(),[i,r]=k.useState(null);return k.useEffect(()=>{let s=!0;return fetch(bo(t)).then(n=>n.ok?n.text():Promise.reject(new Error("miss"))).then(n=>{s&&r(n)}).catch(()=>{s&&r("")}),()=>{s=!1}},[t]),i===null?p.jsx("pre",{className:"eval-transcript loading",children:e("nodeView.eval.loadingTranscript")}):p.jsx("pre",{className:"eval-transcript",children:i})}function pC({hash:t,collapsed:e=!1}){const i=He(),[r,s]=k.useState(null);if(k.useEffect(()=>{let o=!0;return fetch(bo(t)).then(a=>a.ok?a.text():Promise.reject(new Error("miss"))).then(a=>{let l=a,u=!0;try{l=JSON.stringify(JSON.parse(a),null,2)}catch{u=!1}o&&s({text:l,valid:u})}).catch(()=>{o&&s({text:"",valid:!1})}),()=>{o=!1}},[t]),r===null)return p.jsx("pre",{className:"eval-data loading",children:i("nodeView.eval.loadingData")});const n=r.valid?i("nodeView.eval.data"):i("nodeView.eval.dataInvalid");return e?p.jsxs("details",{className:"eval-datawrap eval-datafold",children:[p.jsx("summary",{className:"eval-datahead",children:n}),p.jsx("pre",{className:"eval-data",children:r.text})]}):p.jsxs("div",{className:"eval-datawrap",children:[p.jsx("div",{className:"eval-datahead",children:n}),p.jsx("pre",{className:"eval-data",children:r.text})]})}function mC({hash:t,alt:e}){const[i,r]=k.useState(!1);return p.jsxs(p.Fragment,{children:[p.jsx("img",{className:"an-image",src:bo(t),alt:e,loading:"lazy",onClick:()=>r(!0)}),i&&p.jsx(dC,{src:bo(t),alt:e,onClose:()=>r(!1)})]})}function gC({exit:t}){return p.jsx(je,{name:t?"minimize":"maximize",size:15})}function wR({target:t,className:e=""}){const i=He(),[r,s]=k.useState(!1);k.useEffect(()=>{const o=()=>{const a=document.fullscreenElement,l=t==null?void 0:t.current;s(!!a&&!!l&&(a===l||l.contains(a)))};return document.addEventListener("fullscreenchange",o),()=>document.removeEventListener("fullscreenchange",o)},[t]);const n=()=>{var a,l;const o=t==null?void 0:t.current;o&&(document.fullscreenElement?(a=document.exitFullscreen||document.webkitExitFullscreen)==null||a.call(document):(l=o.requestFullscreen||o.webkitRequestFullscreen)==null||l.call(o))};return p.jsx("button",{type:"button",className:`an-fs ${e}`,onClick:n,"data-tip":i(r?"annotator.exitFullscreen":"annotator.fullscreen"),"aria-label":i(r?"annotator.exitFullscreen":"annotator.fullscreen"),children:p.jsx(gC,{exit:r})})}function vC({e:t,alt:e="",collapsed:i=!1}){const r=He();return t.state==="miss"?p.jsx("div",{className:"eval-noimg",children:r("nodeView.eval.miss")}):t.kind==="transcript"?p.jsx(fC,{hash:t.hash}):t.kind==="data"?p.jsx(pC,{hash:t.hash,collapsed:i}):t.kind==="video"?p.jsx("video",{className:"eval-video",src:bo(t.hash),controls:!0,preload:"metadata",playsInline:!0}):p.jsx(mC,{hash:t.hash,alt:e})}const Dl=new Map;function bC(t){const[e,i]=k.useState(()=>Dl.get(t)??null);return k.useEffect(()=>{if(Dl.has(t)){i(Dl.get(t));return}let r=!0;return fetch(bo(t),{headers:{Range:"bytes=0-0"}}).then(s=>{const n=s.headers.get("content-type")||"",o=s.ok?{kind:n.startsWith("video/")?"video":n.startsWith("image/")?"image":n.startsWith("application/json")?"data":"transcript",state:"present"}:{kind:"image",state:"miss"};Dl.set(t,o),r&&i(o)}).catch(()=>{r&&i({kind:"image",state:"miss"})}),()=>{r=!1}},[t]),e}function _C({hash:t,alt:e=""}){const i=bC(t);return i?p.jsx(vC,{e:{hash:t,...i},alt:e}):null}function pd({children:t,className:e=""}){return p.jsx(j3,{className:e,softBreak:"break",renderSpecRef:(i,r,s)=>{const n=Vt("spec",i);return p.jsx("a",{className:"doc-link",href:n,...s,onClick:o=>f5(o,n),children:i})},renderEvidence:(i,r,s)=>p.jsx("span",{className:"rich-evidence",...s,children:p.jsx(_C,{hash:i.hash,alt:i.alt||"evidence"})}),children:t})}const yC=t=>p.jsx(pd,{children:t});function hg({loadToolOutput:t,children:e}){const i=He(),r=k.useMemo(()=>({...fv,loading:i("common.loading"),running:i("session.executionRunning"),more:i("mobile.more")}),[i]);return p.jsx(K7,{renderText:yC,labels:r,loadToolOutput:t,children:e})}const dg=t=>typeof t=="number"?t:Date.parse(t),wC=/\n*— from session (?:"(.*?)" \(([^\s)]+)\)|(\S+))(?: on machine \S+)?\. To reply: spex session send (?:--ssh \S+ )?\S+ "<your reply>"\s*$/;function xC(t){const e=wC.exec(t||"");return e?{text:t.slice(0,e.index),envelope:{label:e[1]||null,id:e[2]||e[3]}}:{text:t,envelope:null}}function SC(t,e){const i=[];let r=null,s=!1;const n=a=>{r??(r={kind:"seam",ts:a,from:dg(a)})},o=(a,l=!1)=>{r&&i.push({...r,to:a,open:l}),r=null};for(const a of t){const l=a.display||a.status;if(a.kind==="status"&&(s=l==="working"),a.kind==="status"&&s&&!a.note){n(a.ts);continue}o(dg(a.ts)),a.kind==="sent"?i.push({kind:"quote",ts:a.ts,from:a.from,...xC(a.text)}):l==="error"||l==="corrupt"?i.push({kind:"event",ts:a.ts,status:l,text:a.note}):i.push({kind:"say",ts:a.ts,status:l,text:a.note}),s&&n(a.ts)}return r&&o(Math.max(r.from+1,e),!0),i}const Ru={merged:{color:"#859900"},active:{color:"#cb4b16"},drift:{color:"#b58900"},pending:{color:"#93a1a1"}},kC={added:"+",edited:"~",deleted:"✕",moved:"→"},xR=["merged","active","drift","pending"];function SR(t){var o,a;const e={merged:[],active:[],drift:[],pending:[]},i=[],r=new Set,s={pass:0,fail:0,stalePass:0,staleFail:0,empty:0},n={pass:[],fail:[],stalePass:[],staleFail:[],empty:[]};for(const l of t){e[l.status]&&e[l.status].push(l.id);const u=(o=l.reviewSummary)==null?void 0:o.issues;if(u!=null&&u.open){i.push(l.id);for(const h of u.openIds||[])r.add(h)}const c=(a=l.reviewSummary)==null?void 0:a.evals;if(c)for(const h of Object.keys(s)){const d=c[h]||0;s[h]+=d,d>0&&n[h].push(l.id)}}return{total:t.length,status:e,issueIds:i,issueCount:r.size,scoreCount:s,scoreNodes:n}}function kR(t,e=14){const i=String(t??"");if(i.length<=e)return i;if(e<=1)return"…".slice(0,e);const r=e-1,s=Math.max(1,Math.floor(r/2)-1),n=r-s;return`${i.slice(0,s)}…${i.slice(i.length-n)}`}const fg=["◆","▲","●","■","★","✦","⬟","⬢","❖","◈","✸","⟡","✚","❂","◐","◑","⬣","▰","✶","⬤","✹","◇","⊛","✺"],pg=["circle","rounded","square","hex"];function CC(t){const e=L5(t);return{seed:t,glyph:fg[(e>>>9)%fg.length],shape:pg[(e>>>17)%pg.length],...O5(t)}}function n1({seed:t,status:e,title:i,size:r=16}){const s=CC(t),n={width:r,height:r};return p.jsx("span",{className:`avatar av-st-${e||"none"}`,"data-tip":i,"aria-label":i,style:n,children:p.jsx("span",{className:`av-face av-gen av-${s.shape}`,style:{...n,background:s.bg,color:s.fg,fontSize:r*.62},children:s.glyph})})}function $3(t){var e;return Hr(t)||((e=t==null?void 0:t.id)==null?void 0:e.slice(0,8))||""}function md({session:t,active:e=!1,selected:i=!1,onPick:r,onHover:s,onOpen:n,compact:o=!1,newSession:a=!1,name:l=null,className:u=""}){const c=He(),h=a?null:o0(t),d=a?c("sessionPicker.newSession"):$3(t),f=a?d:`${d} · ${c(`status.${h.status}`)}`;return p.jsxs("button",{type:"button",role:"option","aria-selected":i,className:`session-picker-row${e?" active":""}${i?" selected":""}${o?" compact":""}${a?" new":""}${u?` ${u}`:""}`,"data-session-picker-id":a?"new":t.id,title:f,onMouseDown:m=>m.preventDefault(),onMouseEnter:s,onDoubleClick:()=>n==null?void 0:n(a?"new":t.id),onClick:()=>r==null?void 0:r(a?"new":t.id),children:[a?p.jsx("span",{className:"session-picker-new-icon","aria-hidden":"true",children:p.jsx(je,{name:"plus",size:13})}):p.jsx(n1,{seed:t.id,status:h.status,size:o?15:17,title:f}),p.jsx("span",{className:"session-picker-name",children:l||d}),!a&&p.jsx("span",{className:"session-picker-status",style:{color:h.color},"aria-label":c(`status.${h.status}`),children:h.glyph})]})}function AC({sessions:t=[],value:e="",onChange:i,onOpen:r,includeNew:s=!1,filter:n=!0,placeholder:o,ariaLabel:a,className:l="",compact:u=!1,autoFocus:c=!1}){const h=He(),d=k.useRef(null),[f,m]=k.useState(""),[v,_]=k.useState(0),w=k.useMemo(()=>{const D=f.trim().toLocaleLowerCase(),R=t.filter(E=>!D||[$3(E),b4(E),E.id].some(L=>L==null?void 0:L.toLocaleLowerCase().includes(D)));return s?[...R,{id:"new",__new:!0}]:R},[s,f,t]);k.useEffect(()=>{_(D=>Math.min(D,Math.max(w.length-1,0)))},[w.length]),k.useEffect(()=>{var D;c&&((D=d.current)==null||D.focus())},[c]);const x=D=>{i==null||i(D),D!=="new"&&m("")},A=D=>{if(D.key==="ArrowDown")D.preventDefault(),_(R=>w.length?(R+1)%w.length:0);else if(D.key==="ArrowUp")D.preventDefault(),_(R=>w.length?(R-1+w.length)%w.length:0);else if(D.key==="Enter"){D.preventDefault();const R=w[v];R&&x(R.id)}};return p.jsxs("div",{className:`session-picker${u?" compact":""}${l?` ${l}`:""}`,children:[n&&p.jsx("input",{ref:d,className:"session-picker-filter",value:f,placeholder:o||h("sessionPicker.filter"),"aria-label":a||h("sessionPicker.filter"),onChange:D=>{m(D.target.value),_(0)},onKeyDown:A}),p.jsx("div",{className:"session-picker-list",role:"listbox","aria-label":a||h("sessionPicker.label"),children:w.length?w.map((D,R)=>D.__new?p.jsx(md,{newSession:!0,active:R===v,selected:e==="new",onPick:x,onOpen:r,onHover:()=>_(R),compact:u},"new"):p.jsx(md,{session:D,active:R===v,selected:e===D.id,onPick:x,onOpen:r,onHover:()=>_(R),compact:u},D.id)):p.jsx("div",{className:"session-picker-empty",children:h("sessionPicker.empty")})})]})}const EC=/\[\[(\.?[\p{L}\p{N}_-]+)\]\]/gu,q3=(t,e=[])=>t.replace(EC,(i,r)=>{const s=e.find(n=>n.id===r);return s?`[[${s.id}]] (${s.path})`:i}),W3=(t,e=[])=>e.find(i=>i.ui&&t.trim()===`/${i.name}`)||null,K3=t=>(t||"").replace(/^\.spec\//,"").replace(/\/spec\.md$/,"");function DC(t,e,i){const r=e.toLowerCase(),s=[];for(const n of t){const o=n.id.toLowerCase(),a=K3(n.path).toLowerCase();let l;if(!r)l=3;else if(o.startsWith(r))l=0;else if(o.includes(r))l=1;else if(a.includes(r))l=2;else continue;n.id===i&&(l=-1),s.push({s:n,score:l})}return s.sort((n,o)=>n.score-o.score||n.s.id.length-o.s.id.length||n.s.id.localeCompare(o.s.id)),s.slice(0,8).map(n=>n.s)}function MC(t,e){const i=e.toLowerCase(),r=u=>Hr(u)||(u.id||"").slice(0,8),s=u=>{var c,h;return[u==null?void 0:u.title,u==null?void 0:u.label,(c=u==null?void 0:u.raw)==null?void 0:c.name,(h=u==null?void 0:u.raw)==null?void 0:h.title,u==null?void 0:u.activity,u==null?void 0:u.promptPreview,u==null?void 0:u.note].filter(d=>typeof d=="string"&&d.trim()).map(d=>d.toLowerCase())},n=[];for(const u of t||[]){const c=(u.id||"").toLowerCase(),h=s(u);let d;if(!i)d=3;else if(c===i||h.some(f=>f===i))d=0;else if(c.startsWith(i)||h.some(f=>f.startsWith(i)))d=1;else if(c.includes(i)||h.some(f=>f.includes(i)))d=2;else continue;n.push({s:u,score:d})}n.sort((u,c)=>u.score-c.score||(c.s.created||0)-(u.s.created||0));const o=n.map(u=>({id:u.s.id,label:r(u.s),sub:u.s.node||u.s.status,session:u.s})),a=n.filter(u=>u.score===0).length,l=o.slice(0,Math.min(a,7));return[...l,{id:"new",label:"new",sub:"choose a launcher"},...o.slice(l.length)].slice(0,8)}function TC(t,e){const i=e.toLowerCase();return(t||[]).map(r=>{const s=(r.name||"").toLowerCase(),n=i?s.startsWith(i)?0:s.includes(i)?1:-1:1;return{launcher:r,score:n}}).filter(r=>r.score>=0).sort((r,s)=>r.score-s.score||r.launcher.name.localeCompare(s.launcher.name)).slice(0,8).map(({launcher:r})=>({id:r.name,label:r.name,sub:r.cmd||r.harness||""}))}function ia(t,e){if(!e)return t;const i=t.toLowerCase().indexOf(e.toLowerCase());return i<0?t:p.jsxs(p.Fragment,{children:[t.slice(0,i),p.jsx("b",{className:"mention-hit",children:t.slice(i,i+e.length)}),t.slice(i+e.length)]})}function V3(t,e){const i=e.toLowerCase(),r=[];for(const s of t){const n=s.name.toLowerCase();let o;if(!i)o=1;else if(n.startsWith(i))o=0;else if(n.includes(i))o=1;else continue;r.push({c:s,score:o})}return r.sort((s,n)=>s.score-n.score),r.slice(0,10).map(s=>s.c)}function BC(t,e,i){let r=e;for(;r>0&&!/\s/.test(t[r-1]);)r--;if(t[r]!=="/")return null;const s=t.slice(r+1,e),n=V3(i,s);return n.length?{items:n,index:0,start:r,end:e,query:s}:null}function RC(t,e){const i=/^\/(\S*)$/.exec(t);if(!i)return null;const r=V3(e,i[1]);return r.length?{items:r,index:0,start:0,end:t.length,query:i[1]}:null}const NC=t=>t&&t[0].toUpperCase()+t.slice(1),LC={user:"(user)",project:"(project)",skill:"[skill]","built-in":"built-in",ui:"[ui]",preset:"[preset]",review:"[review]"};function OC({menu:t,up:e,head:i,onPick:r,onHover:s}){const n=He();return p.jsxs("ul",{className:e?"mention-menu up":"mention-menu",role:"listbox",children:[p.jsxs("li",{className:"mention-head",children:["// ",i," — ",n("session.menuHint")]}),t.items.map((o,a)=>{const l=o.ui?"ui":o.source??o.kind,u=o.ui?` sc-${o.color}`:"";return p.jsxs("li",{role:"option","aria-selected":a===t.index,className:`${a===t.index?"mention-item on":"mention-item"}${u}`,onMouseDown:c=>{c.preventDefault(),r(o)},onMouseEnter:()=>s(a),children:[p.jsxs("span",{className:o.ui?"slash-name ui":"slash-name",children:["/",ia(o.name,t.query)]}),p.jsx("span",{className:"slash-desc",children:NC(o.description??o.desc)}),p.jsx("span",{className:`slash-src src-${l}`,children:LC[l]||l})]},`${l}:${o.name}`)})]})}function PC(t,e,i,r){let s=e-1;for(;s>=0&&/[\p{L}\p{N}_.\-]/u.test(t[s]);)s--;if(s>=1&&t[s-1]==="["&&t[s]==="["){const n=t.slice(s+1,e),o=DC(i,n,r);return o.length?{kind:"mention",items:o,index:0,start:s-1,end:e,query:n}:null}return null}function mg(t,e,i,r=[]){let s=e-1;for(;s>=0&&/[\p{L}\p{N}_.:\-]/u.test(t[s]);)s--;if(s>=0&&t[s]==="@"&&(s===0||/\s/.test(t[s-1]))){const n=t.slice(s+1,e);if(n.startsWith("new:")){const a=TC(r,n.slice(4));return a.length?{kind:"launcher",items:a,index:0,start:s,end:e,query:n.slice(4)}:null}const o=MC(i,n);return o.length?{kind:"session",items:o,index:0,start:s,end:e,query:n}:null}return null}function FC({menu:t,up:e,fixedStyle:i,onPick:r,onHover:s}){const n=He(),o=t.kind==="launcher",a=t.kind==="session"||o,l=o?`@new:${t.query}`:t.query?a?`@${t.query}`:`[[${t.query}]]`:n(a?"session.menuSessions":"session.menuSpecNodes");return p.jsxs("ul",{className:`${e?"mention-menu up":"mention-menu"}${i?" fixed":""}`,style:i||void 0,role:"listbox",children:[p.jsxs("li",{className:"mention-head",children:["// ",l," — ",n("session.menuHint")]}),t.items.map((u,c)=>{var h;return a&&u.session?p.jsx(md,{session:u.session,compact:!0,active:c===t.index,onPick:()=>r(u),onHover:()=>s(c),className:"mention-item",name:p.jsxs(p.Fragment,{children:["@",ia(u.label,t.query)]})},u.id):p.jsxs("li",{role:"option","aria-selected":c===t.index,className:`${c===t.index?"mention-item on":"mention-item"}${o||t.kind==="session"&&u.id==="new"?" new":""}`,onMouseDown:d=>{d.preventDefault(),r(u)},onMouseEnter:()=>s(c),children:[!a&&p.jsx("span",{className:"mention-dot",style:{background:((h=Ru[u.status])==null?void 0:h.color)||Ru.pending.color}}),p.jsx("span",{className:"mention-id",children:o?p.jsxs(p.Fragment,{children:["@new:",ia(u.label,t.query)]}):a?p.jsxs(p.Fragment,{children:["@",ia(u.label,t.query)]}):ia(u.id,t.query)}),p.jsx("span",{className:"mention-path",children:a?u.sub:K3(u.path)})]},u.id)})]})}function gd({inputRef:t,value:e,setValue:i,specs:r=[],sessions:s=[],launchers:n=[],focusId:o=null,up:a=!1,fixedAbove:l=null,slash:u=null}){const[c,h]=k.useState(null),[d,f]=k.useState(null),m=k.useRef(null),v=F=>`${F.value}\0${F.selectionStart}`,_=(F,$)=>{var z;if(!((z=u==null?void 0:u.commands)!=null&&z.length))return null;const W=u.mode==="token"?BC(F,$,u.commands):RC(F,u.commands);return W?{kind:"slash",...W}:null},w=F=>{var T;if(!F){h(null),f(null);return}const $=v(F);if(m.current===$){h(null),f(null);return}m.current=null;const W=F.selectionStart,z=PC(F.value,W,r,o)||mg(F.value,W,s,n)||_(F.value,W);if(h(z),!z||!l){f(null);return}const j=F.getBoundingClientRect(),C=(T=F.closest(l))==null?void 0:T.getBoundingClientRect(),O=(C==null?void 0:C.top)??j.top;f({left:`${j.left}px`,width:`${j.width}px`,right:"auto",bottom:`${Math.max(8,window.innerHeight-O+8)}px`})};k.useEffect(()=>{const F=t.current;n.length&&F&&document.activeElement===F&&w(F)},[n]);const x=F=>h($=>$&&{...$,index:($.index+F+$.items.length)%$.items.length}),A=F=>h($=>$&&{...$,index:F}),D=F=>{var j;if(!F||!c)return;m.current=null;const $=e.slice(0,c.start);if(c.kind==="slash"){if((j=u==null?void 0:u.onPick)!=null&&j.call(u,F,c)){h(null),f(null);return}const C=`/${F.name} `;i($+C+e.slice(c.end)),h(null),f(null);const O=$.length+C.length;requestAnimationFrame(()=>{const T=t.current;T&&(T.focus(),T.setSelectionRange(O,O))});return}if(c.kind==="session"&&F.id==="new"){const C="@new:",O=$+C+e.slice(c.end),T=$.length+C.length;i(O),h(mg(O,T,s,n)),requestAnimationFrame(()=>{const U=t.current;U&&(U.focus(),U.setSelectionRange(T,T))});return}const W=c.kind==="session"?`@${F.id} `:c.kind==="launcher"?`@new:${F.id} `:`[[${F.id}]] `;i($+W+e.slice(c.end)),h(null),f(null);const z=$.length+W.length;requestAnimationFrame(()=>{const C=t.current;C&&(C.focus(),C.setSelectionRange(z,z))})},R=F=>c?F.key==="ArrowDown"?(F.preventDefault(),F.stopPropagation(),x(1),!0):F.key==="ArrowUp"?(F.preventDefault(),F.stopPropagation(),x(-1),!0):F.key==="Enter"||F.key==="Tab"?(F.preventDefault(),F.stopPropagation(),D(c.items[c.index]),!0):F.key==="Escape"?(F.preventDefault(),F.stopPropagation(),E(),!0):!1:!1,E=()=>{t.current&&(m.current=v(t.current)),h(null),f(null)},L=()=>{m.current=null,h(null),f(null)};ni(!!c,E);const q=c?c.kind==="slash"?p.jsx(OC,{menu:c,up:a,head:c.query?`/${c.query}`:u==null?void 0:u.head,onPick:D,onHover:A}):p.jsx(FC,{menu:c,up:a,fixedStyle:d,onPick:D,onHover:A}):null;return{menu:c,sync:w,onKeyDown:R,close:L,dismiss:E,accept:D,nav:x,menuEl:q}}function CR(t,e,i,r){return e?t.key==="ArrowDown"?(t.preventDefault(),t.stopPropagation(),i(s=>s&&{...s,index:(s.index+1)%s.items.length}),!0):t.key==="ArrowUp"?(t.preventDefault(),t.stopPropagation(),i(s=>s&&{...s,index:(s.index-1+s.items.length)%s.items.length}),!0):t.key==="Enter"||t.key==="Tab"?(t.preventDefault(),t.stopPropagation(),r(e.items[e.index]),!0):t.key==="Escape"?(t.preventDefault(),t.stopPropagation(),i(null),!0):!1:!1}function U3(t,e,i,r=null){if(!t)return;const s=t.selectionStart??t.value.length,n=t.selectionEnd??s;i(t.value.slice(0,s)+e+t.value.slice(n));const o=s+e.length;requestAnimationFrame(()=>{t.isConnected&&(t.focus(),t.setSelectionRange(o,o),r==null||r(t))})}function AR({label:t,onClick:e,disabled:i=!1,children:r}){return p.jsx("button",{type:"button",className:"fv-trigger-btn","data-tip":t,"aria-label":t,disabled:i,onMouseDown:s=>s.preventDefault(),onClick:e,children:r})}const Ml=1,vd=1024,IC=1024,zC=1024,bd=vd*IC,gg=bd*zC;let jC=0;const HC=()=>{var t,e;return((e=(t=globalThis.crypto)==null?void 0:t.randomUUID)==null?void 0:e.call(t))||`attachment-${Date.now()}-${++jC}`},vg=t=>t<vd?`${t} B`:t<bd?`${Math.round(t/vd)} KB`:t<gg?`${(t/bd).toFixed(1)} MB`:`${(t/gg).toFixed(2)} GB`,Tl=async t=>{const e=await t.json().catch(()=>null);return(e==null?void 0:e.error)||`upload failed (HTTP ${t.status})`},$C=(t,e)=>(t==null?void 0:t.size)===e&&Number.isSafeInteger(t.chunkBytes)&&t.chunkBytes>0&&Number.isSafeInteger(t.concurrency)&&t.concurrency>0&&Number.isSafeInteger(t.requestTimeoutMs)&&t.requestTimeoutMs>0&&Number.isSafeInteger(t.retryLimit)&&t.retryLimit>=0&&Number.isSafeInteger(t.retryDelayMs)&&t.retryDelayMs>=0&&Number.isSafeInteger(t.offset)&&t.offset>=0&&t.offset<=e,qC=(t,e)=>new Promise((i,r)=>{if(e.signal.aborted){r(new Error("upload cancelled"));return}const s=window.setTimeout(()=>{e.signal.removeEventListener("abort",n),i()},t),n=()=>{window.clearTimeout(s),r(new Error("upload cancelled"))};e.signal.addEventListener("abort",n,{once:!0})}),bg=async(t,e,i,r)=>{const s=new AbortController,n=()=>s.abort();i.signal.addEventListener("abort",n,{once:!0});const o=window.setTimeout(()=>s.abort(),r);try{return await fetch(t,{...e,signal:s.signal})}catch(a){throw!i.signal.aborted&&s.signal.aborted?new Error("upload request timed out"):a}finally{window.clearTimeout(o),i.signal.removeEventListener("abort",n)}},WC=async(t,e,i)=>{let r=0;for(;;)try{return await t()}catch(s){if(i.signal.aborted||r>=e.retryLimit)throw s;r+=1,await qC(e.retryDelayMs,i)}},KC=(t,e,i)=>{const r=t.current;if(!r){e(u=>{const c=u||"";return c+(c&&!/\s$/.test(c)?" ":"")+i+" "});return}const s=r.value,n=r.selectionStart,o=r.selectionEnd,a=s.slice(0,n),l=(a&&!/\s$/.test(a)?" ":"")+i+" ";e(a+l+s.slice(o)),requestAnimationFrame(()=>{if(!r.isConnected)return;r.focus();const u=a.length+l.length;r.setSelectionRange(u,u)})};function _d({inputRef:t,setValue:e,variant:i="command",disabled:r=!1}){const s=He(),[n,o]=k.useState([]),[a,l]=k.useState(!1),u=k.useRef([]),c=k.useRef(new Map),h=k.useRef(!1),d=k.useRef(null),f=k.useRef(null);f.current=C=>KC(t,e,C);const m=C=>{u.current=C,o(C)},v=(C,O)=>m(u.current.map(T=>T.id===C?{...T,...O}:T)),_=async(C,O=null)=>{const T=u.current.find(H=>H.id===C);if(!T||T.phase==="cancelled")return null;v(C,{phase:"uploading",error:null});const U=new AbortController;c.current.set(C,U);try{let H=T.transferId,re=null;if(H){const Y=await fetch(Di(`/api/uploads/${H}`),{signal:U.signal});if(Y.ok)re=await Y.json();else if(Y.status!==404)throw new Error(await Tl(Y))}if(!re){const Y=await fetch(Di("/api/uploads"),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({name:T.file.name||"pasted",size:T.file.size}),signal:U.signal});if(!Y.ok)throw new Error(await Tl(Y));if(re=await Y.json(),H=re==null?void 0:re.id,!H)throw new Error("upload did not return a transfer id");v(C,{transferId:H})}if(!$C(re,T.file.size))throw new Error("upload transfer metadata is invalid");O==null||O(re.concurrency);let G=re.offset;for(v(C,{offset:G});G<T.file.size;){const Y=T.file.slice(G,Math.min(T.file.size,G+re.chunkBytes)),le=await WC(async()=>{const de=await bg(Di(`/api/uploads/${H}`),{method:"PATCH",headers:{"content-type":"application/offset+octet-stream","upload-offset":String(G)},body:Y},U,re.requestTimeoutMs);if(de.status>=500)throw new Error(await Tl(de));return de},re,U),te=await le.json().catch(()=>null);if(le.status===409&&Number.isSafeInteger(te==null?void 0:te.offset)&&te.offset>=0&&te.offset<=T.file.size){G=te.offset,v(C,{offset:G});continue}if(!le.ok)throw new Error((te==null?void 0:te.error)||`upload failed (HTTP ${le.status})`);if(!Number.isSafeInteger(te==null?void 0:te.offset)||te.offset<=G||te.offset>T.file.size)throw new Error("upload did not advance its committed offset");G=te.offset,v(C,{offset:G})}const X=await bg(Di(`/api/uploads/${H}/complete`),{method:"POST"},U,re.requestTimeoutMs);if(!X.ok)throw new Error(await Tl(X));const oe=await X.json().catch(()=>null);if(!(oe!=null&&oe.path))throw new Error("upload did not return a path");const I=u.current.find(Y=>Y.id===C);return(I==null?void 0:I.phase)==="cancelled"?null:(T.splice(oe.path),v(C,{phase:"complete",offset:T.file.size,path:oe.path}),re.concurrency)}catch(H){O==null||O(null),U.signal.aborted?v(C,{phase:"cancelled",offset:0,transferId:null,error:null}):v(C,{phase:"failed",error:H instanceof Error?H.message:String(H)})}finally{c.current.delete(C)}return null},w=async C=>{if(!h.current){h.current=!0;try{const[O,...T]=C;let U;const H=new Promise(Y=>{U=Y}),re=O?_(O,U):Promise.resolve(Ml),G=O?await H:Ml,X=Math.min(Math.max(0,(G||Ml)-Ml),T.length);if(X===0){await re;for(const Y of T)await _(Y);return}let oe=0;const I=Array.from({length:X},async()=>{for(;oe<T.length;){const Y=T[oe];oe+=1,await _(Y)}});await Promise.all([re,...I])}finally{h.current=!1}}},x=C=>{h.current||w([C])},A=async C=>{var T;const O=u.current.find(U=>U.id===C);O&&((T=c.current.get(C))==null||T.abort(),O.transferId&&await fetch(Di(`/api/uploads/${O.transferId}`),{method:"DELETE"}).catch(()=>{}),v(C,{phase:"cancelled",offset:0,transferId:null,error:null}))},D=C=>{const O=u.current.find(T=>T.id===C);O&&(O.phase!=="complete"&&O.phase!=="cancelled"&&A(C),m(u.current.filter(T=>T.id!==C)))},R=async C=>{const O=[...C||[]];if(!O.length||r||h.current)return;const T=f.current,U=O.map(H=>({id:HC(),file:H,splice:T,phase:"queued",offset:0,transferId:null,error:null}));m([...u.current,...U]),await w(U.map(H=>H.id))},E=()=>{var C;r||(C=d.current)==null||C.click()},L=C=>{var T;const O=(T=C.clipboardData)==null?void 0:T.files;r||!O||!O.length||(C.preventDefault(),R(O))},q=C=>{var O;r||[...((O=C.dataTransfer)==null?void 0:O.types)||[]].includes("Files")&&(C.preventDefault(),l(!0))},F=()=>l(!1),$=C=>{var O;C.preventDefault(),l(!1),R((O=C.dataTransfer)==null?void 0:O.files)},W=n.some(C=>C.phase==="queued"||C.phase==="uploading"),z=p.jsx("input",{ref:d,type:"file",multiple:!0,style:{display:"none"},onChange:C=>{R(C.target.files),C.target.value=""}}),j=n.length?p.jsx("div",{className:`si-attach-queue ${i}`,"aria-live":"polite",children:n.map(C=>{const O=C.phase==="queued"||C.phase==="uploading",T=C.phase==="queued"?s("session.attachQueued"):C.phase==="uploading"?`${vg(C.offset)} / ${vg(C.file.size)}`:C.phase==="complete"?s("session.attachDone"):C.phase==="cancelled"?s("session.attachCancelled"):C.error;return p.jsxs("div",{className:`si-attach-row ${C.phase}`,onAnimationEnd:U=>{U.target===U.currentTarget&&U.animationName==="si-attach-complete-out"&&D(C.id)},children:[p.jsxs("span",{className:"si-attach-name",title:C.file.name,children:[p.jsx(je,{name:"paperclip",size:12}),C.file.name]}),p.jsx("progress",{className:"si-attach-progress",value:C.offset,max:C.file.size,"aria-label":`${C.file.name}: ${T}`}),p.jsx("span",{className:"si-attach-status",role:C.phase==="failed"?"alert":"status",children:T}),C.phase==="failed"&&p.jsx(Zt,{icon:"rotate-ccw",size:13,className:"si-attach-action",label:s("session.attachRetry"),disabled:h.current,onClick:()=>x(C.id)}),(O||C.phase==="failed")&&p.jsx(Zt,{icon:"x",size:13,className:"si-attach-action",label:s("session.attachCancel"),onClick:()=>{A(C.id)}}),(C.phase==="complete"||C.phase==="cancelled")&&p.jsx(Zt,{icon:"x",size:13,className:"si-attach-action",label:s("session.attachDismiss"),onClick:()=>D(C.id)})]},C.id)})}):null;return{pick:E,busy:W,dragging:a,onPaste:L,fileInput:z,queue:j,dropProps:{onDragOver:q,onDragLeave:F,onDrop:$}}}const G3=new Map,o1=t=>G3.get(t)||null;async function VC(t,e){var i,r;try{const s=((r=(i=globalThis.crypto)==null?void 0:i.randomUUID)==null?void 0:r.call(i))||`session-create-${Date.now()}-${Math.random().toString(16).slice(2)}`,n=await fetch(Di("/api/sessions"),{method:"POST",headers:{"Content-Type":"application/json","Idempotency-Key":s},body:JSON.stringify({prompt:t,...e?{launcher:e}:{}})}),o=await n.json().catch(()=>null),a={ok:n.ok,error:o==null?void 0:o.error};return o!=null&&o.id&&(G3.set(o.id,o),a.id=o.id,a.session=o),a}catch{return{ok:!1}}}let bn=null,Bl=null;const UC=()=>bn?Promise.resolve(bn):(Bl||(Bl=h4().then(t=>(bn=t,t)).catch(t=>{throw Bl=null,t})),Bl),_g=t=>Array.isArray(t==null?void 0:t.launchers)?t.launchers:[],GC=()=>{try{return localStorage.getItem("si.launcher")||""}catch{return""}},yg=(t,e,i=GC())=>{var r;return t.some(s=>s.name===i)?i:e&&t.some(s=>s.name===e)?e:((r=t[0])==null?void 0:r.name)||i};function Y3(){const t=_g(bn),[e,i]=k.useState(t),[r,s]=k.useState(()=>yg(t,bn==null?void 0:bn.default)),n=o=>{s(o);try{localStorage.setItem("si.launcher",o)}catch{}};return k.useEffect(()=>{UC().then(o=>{const a=_g(o);a.length&&(i(a),s(l=>yg(a,o.default,l)))}).catch(()=>{})},[]),{launchers:e,launcher:r,pickLauncher:n}}function X3(){const[t,e]=k.useState([]);return k.useEffect(()=>{P5().then(i=>{Array.isArray(i)&&e(i)}).catch(()=>{})},[]),t}function J3(t){const[e,i]=k.useState([]);return k.useEffect(()=>{let r=!0;return fetch(Di(`/api/slash-commands?harness=${encodeURIComponent(t||"claude")}`)).then(s=>s.json()).then(s=>{r&&Array.isArray(s)&&i(s)}).catch(()=>{}),()=>{r=!1}},[t]),e}const YC=[{name:"command",color:"blue",icon:"command",button:!0,typed:!1,pressed:!0,anchor:"right",when:t=>!!(t!=null&&t.status)&&t.status!=="offline"&&t.status!=="queued"&&t.liveness!=="offline",labelKey:"session.commandBtn",titleKey:"session.commandTitle",shortcut:"shell.commandBox"},{name:"eval",color:"cyan",button:!1,when:t=>!!(t!=null&&t.status),labelKey:"sessionEval.btn",titleKey:"sessionEval.btnTitle",descKey:"session.cmd.evalDesc"},{name:"relaunch",color:"blue",icon:"rotate-ccw",button:!0,typed:!1,when:t=>!!(t!=null&&t.status)&&t.status!=="queued"&&t.status!=="retired"&&t.liveness==="offline",labelKey:"session.relaunch",titleKey:"session.relaunchTitle"},{name:"stop",color:"muted",button:!1,when:t=>!!(t!=null&&t.status)&&t.status!=="offline"&&t.status!=="queued"&&t.liveness!=="offline",titleKey:"session.cmd.stopTitle",descKey:"session.cmd.stopDesc"},{name:"close",color:"red",button:!1,when:t=>!!(t!=null&&t.status)&&t.status!=="offline",titleKey:"session.cmd.closeTitle",descKey:"session.cmd.closeDesc"}];function wg(t,e={}){return t!=null&&t.archived?[]:YC.filter(i=>i.when(t)).map(i=>{var r;return{...i,...((r=i.availability)==null?void 0:r.call(i,t))||{enabled:!0},run:e[i.name]}})}function Z3(t=[],e=[],i=[]){const r=new Set;return[...t,...e.map(s=>({...s,source:"preset"})),...i].filter(s=>!(s!=null&&s.name)||r.has(s.name)?!1:(r.add(s.name),!0))}const XC=t=>new Date(t).toLocaleDateString([],{month:"short",day:"numeric"}),xg=t=>new Date(t).toDateString(),Ac=new Map;function Sg(t,e,i){return`${t}:${e}:${i}`}function Ec(t,e){return`${t}:${e}`}const JC=(t,e)=>t!=null&&t.length===e.length&&(t.length===0||JSON.stringify(t[t.length-1])===JSON.stringify(e[e.length-1])),ZC='button, summary, a, input, textarea, select, option, label, [role], [contenteditable]:not([contenteditable="false"])',QC=new Set(["Backspace","Delete","Enter","ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End","PageUp","PageDown"]),Ar=Object.freeze({NORMAL:0,WORD:1,LINE:2}),x0=()=>typeof Highlight<"u"&&typeof CSS<"u"&&!!CSS.highlights,eA=()=>{x0()&&CSS.highlights.delete("timeline-sel")},tA=()=>x0()&&typeof document.caretRangeFromPoint=="function",iA=t=>{const e=document.getSelection();if(!t||!e||e.rangeCount===0)return;const i=r=>!!r&&t.contains(r);(i(e.anchorNode)||i(e.focusNode))&&e.removeAllRanges()},kg=t=>!x0()||!t||t.collapsed?!1:(CSS.highlights.set("timeline-sel",new Highlight(t)),!0),rA=t=>{let e=!1;const i=s=>{if(s.clipboardData)try{s.clipboardData.setData("text/plain",t),s.preventDefault(),e=!0}catch{}};document.addEventListener("copy",i,!0);let r=!1;try{r=document.execCommand("copy")===!0}catch{}return document.removeEventListener("copy",i,!0),e&&r},sA=async t=>{var e;try{if(typeof((e=navigator.clipboard)==null?void 0:e.writeText)=="function")return await navigator.clipboard.writeText(t),!0}catch{}return rA(t)},Nu=(t,e,i)=>{var s;const r=(s=document.caretRangeFromPoint)==null?void 0:s.call(document,e,i);return r&&t.contains(r.startContainer)?r:null},Cg=(t,e,i)=>{const r=Nu(t,e,i),s=r==null?void 0:r.startContainer;if(!s||s.nodeType!==Node.TEXT_NODE||!s.data)return null;const n=Math.min(r.startOffset,s.data.length);let o=null;if(typeof Intl.Segmenter=="function"){const l=[...new Intl.Segmenter(void 0,{granularity:"word"}).segment(s.data)];o=l.find(({index:u,segment:c,isWordLike:h})=>h&&u<=n&&n<u+c.length)||l.findLast(({index:u,segment:c,isWordLike:h})=>h&&u<n&&n<=u+c.length),o&&(o=[o.index,o.index+o.segment.length])}if(!o){const l=h=>/[\p{L}\p{M}\p{N}_]/u.test(h);let u=Math.min(n,s.data.length-1);if(!l(s.data[u])&&u>0&&l(s.data[u-1])&&(u-=1),!l(s.data[u]))return null;let c=u+1;for(;u>0&&l(s.data[u-1]);)u-=1;for(;c<s.data.length&&l(s.data[c]);)c+=1;o=[u,c]}const a=document.createRange();return a.setStart(s,o[0]),a.setEnd(s,o[1]),a},Ag=(t,e,i)=>{const r=Nu(t,e,i),s=r==null?void 0:r.startContainer,n=(s==null?void 0:s.nodeType)===Node.ELEMENT_NODE?s:s==null?void 0:s.parentElement,o=n==null?void 0:n.closest(".m-ev-note, .tx-quote-text");if(!o||!t.contains(o))return null;const a=document.createRange();return a.selectNodeContents(o),a},nA=(t,e,i)=>{const r=t.compareBoundaryPoints(Range.START_TO_START,e)<=0,s=r?t:e,n=r?e:t,o=document.createRange();return o.setStart(s.startContainer,s.startOffset),i===Ar.NORMAL?o.setEnd(n.startContainer,n.startOffset):o.setEnd(n.endContainer,n.endOffset),o};function oA({session:t,state:e,active:i,inputRef:r,draft:s,setDraft:n,sending:o,send:a,sendErr:l,sendNote:u,onRestore:c,actionOutcome:h,onComposerPress:d,working:f=!1,stopping:m=!1,stop:v,specs:_=[],sessions:w=[],boardCommands:x=[]}){const A=He(),D=e!=="live",R=!D&&f,{launchers:E}=Y3(),L=X3(),q=J3(t==null?void 0:t.harness),F=k.useMemo(()=>Z3(x,L,q),[x,L,q]),$=gd({inputRef:r,value:s,setValue:n,specs:_,sessions:w,launchers:E,up:!0,slash:{commands:F,mode:"line",head:A("session.menuCommands"),onPick:C=>{var O;return C.ui?(n(""),(O=C.run)==null||O.call(C),!0):!1}}}),W=_d({inputRef:r,setValue:n,variant:"command",disabled:D}),z=C=>U3(r.current,C,n,$.sync),j=()=>{var T;if(D)return;const C=s.trim();if(!C)return;const O=W3(C,F);if(O){n(""),$.close(),(T=O.run)==null||T.call(O);return}a(q3(C,_))};return p.jsx(H3,{as:"footer",className:`m-composer is-${e}${W.dragging?" dragover":""}`,"data-footer-state":e,...W.dropProps,preview:(l||u)&&p.jsx("div",{className:l?"m-senderr":"m-sendnote",children:l||u}),editor:!D&&p.jsxs(p.Fragment,{children:[p.jsxs("div",{className:"m-composer-line fv-tawrap",children:[p.jsx(fd,{ref:r,className:"m-input","data-focus-sink":i&&!D?"":void 0,rows:1,placeholder:A("mobile.inputPlaceholder"),value:s,onMouseDownCapture:d,onChange:C=>{n(C.target.value),$.sync(C.target)},onSelect:C=>$.sync(C.target),onBlur:$.close,onPaste:W.onPaste,onKeyDown:C=>{da(C)||$.onKeyDown(C)||!D&&C.key==="Enter"&&!C.shiftKey&&!da(C)&&(C.preventDefault(),C.stopPropagation(),j())}}),$.menuEl]}),W.queue]}),footer:p.jsxs(p.Fragment,{children:[!D&&p.jsxs(p.Fragment,{children:[W.fileInput,p.jsxs("div",{className:"si-command-tools m-composer-tools",children:[p.jsxs("span",{className:"si-command-title",children:[p.jsx(je,{name:"command",size:12}),A("session.commandBox")]}),p.jsx("button",{type:"button",className:"fv-trigger-btn","data-tip":A("thread.mentionActor"),"aria-label":A("thread.mentionActor"),onMouseDown:C=>C.preventDefault(),onClick:()=>z("@"),children:"@"}),p.jsx("button",{type:"button",className:"fv-trigger-btn","data-tip":A("thread.mentionNode"),"aria-label":A("thread.mentionNode"),onMouseDown:C=>C.preventDefault(),onClick:()=>z("[["),children:"[["}),p.jsx("button",{type:"button",className:"fv-trigger-btn","data-tip":A("session.menuCommands"),"aria-label":A("session.menuCommands"),onMouseDown:C=>C.preventDefault(),onClick:()=>z("/"),children:"/"}),p.jsx(Zt,{icon:W.busy?"loader":"paperclip",size:14,iconClassName:W.busy?"si-attach-busy":void 0,className:"si-command-tool",label:A("session.attachTitle"),disabled:W.busy,onClick:W.pick}),R&&p.jsx(Zt,{icon:"stop",size:12,className:"m-stop",label:A("mobile.stop"),disabled:m,onMouseDown:C=>C.preventDefault(),onClick:v}),p.jsx(Zt,{icon:"send",size:14,className:"m-send",label:A("mobile.send"),disabled:!s.trim()||o,onMouseDown:C=>C.preventDefault(),onClick:j})]})]}),D&&p.jsxs("div",{className:"m-coldline",children:[p.jsx("span",{children:A(e==="archived"?"session.archivedReadOnly":"session.offlineReadOnly")}),c&&p.jsx("button",{type:"button",className:"m-coldline-action",disabled:(h==null?void 0:h.phase)==="pending",onClick:c,children:A(e==="archived"?"session.shelfRestore":"session.relaunch")})]}),D&&h&&p.jsx("div",{className:`si-action-outcome ${h.phase}`,role:h.phase==="failed"?"alert":"status",children:h.message})]})})}function aA({s:t,sessions:e=[],active:i=!0,footerState:r="live",onRestore:s,actionOutcome:n,specs:o=[],boardCommands:a=[]}){var Hn,ye;const l=He(),u=t_(),[c,h]=k.useState(null),[d,f]=k.useState(null),[m,v]=k.useState(""),[_,w]=k.useState(!1),[x,A]=k.useState(!1),[D,R]=k.useState(null),[E,L]=k.useState(null),[q,F]=k.useState(null),[$,W]=k.useState(()=>new Set),[z,j]=k.useState(()=>new Map),[C,O]=k.useState(null),[T,U]=k.useState(()=>Date.now()),H=k.useRef(null),re=k.useRef(null),G=k.useRef(null),X=k.useRef(null),oe=k.useRef(null),I=k.useRef(null),Y=k.useRef(new Map),le=k.useRef(new Map),te=J=>{let Q=le.current.get(J);return Q||(Q=Ee=>{const Me=`${J}:${Ee}`;let We=Y.current.get(Me);return We||(We=H5(t.id,J,Ee),Y.current.set(Me,We)),We.then(Xe=>{var Oe;return Xe.ok?{ok:!0,output:((Oe=Xe.data)==null?void 0:Oe.output)??null}:{ok:!1,error:Xe.error}})},le.current.set(J,Q)),Q},[de,ke]=k.useState(()=>Date.now()),Ye=k.useRef(0),Ct=k.useRef(new Set),At=k.useRef(new Map),nt=k.useRef(new Map),Be=k.useRef(!0),vt=k.useCallback(()=>F5(t.id).then(J=>{Number.isFinite(J==null?void 0:J.serverNow)&&(Ye.current=J.serverNow-Date.now());const Q=Date.now()+Ye.current;U(Q),ke(Q),J&&h(Ee=>JC(Ee,J.events)?Ee:J.events)}),[t.id]),vr=i&&r==="live"&&t.status==="working";k.useEffect(()=>{if(!vr)return;const J=()=>{document.visibilityState!=="hidden"&&U(Date.now()+Ye.current)};J();const Q=setInterval(J,1e3);return()=>clearInterval(Q)},[vr]),k.useEffect(()=>{h(null),f(null),F(null),L(null),W(new Set),j(new Map),Ct.current.clear(),At.current.clear(),nt.current.clear(),Y.current.clear(),le.current.clear(),O(null),br.current=null,qt.current=!1,Si(!1),U(Date.now()),ke(Date.now()),Be.current=!0},[t.id]),k.useEffect(()=>{i&&(vt(),I5(t.id).then(J=>{J&&f(J)}))},[t.id,vt,i]),k.useEffect(()=>{if(!i||u||document.visibilityState==="hidden")return;const J=requestAnimationFrame(()=>{const Q=G.current;i&&!u&&document.visibilityState!=="hidden"&&Q&&Q.offsetParent!==null&&getComputedStyle(Q).visibility!=="hidden"&&document.activeElement!==Q&&Q.focus()});return()=>cancelAnimationFrame(J)},[t.id,i,u]),k.useEffect(()=>{if(!i||r==="archived")return;const J=setInterval(vt,8e3);return()=>clearInterval(J)},[vt,i,r]),k.useEffect(()=>{i&&r!=="archived"&&vt()},[t.status,t.note,vt,i,r]);const ht=k.useMemo(()=>SC(c||[],de),[c,de]),Yr=ht.length&&ht[ht.length-1].kind==="seam"&&ht[ht.length-1].open?ht[ht.length-1]:null,Pt=i&&r==="live"&&Yr?Yr.from:null,br=k.useRef(null);k.useEffect(()=>{if(Pt!==null)return br.current!==Pt&&(br.current=Pt,O(null)),z5(t.id,Pt,O)},[t.id,Pt]);const qt=k.useRef(!1),[Ni,Si]=k.useState(!1),Wt=!qt.current&&c!==null&&Pt!==null&&C===null&&!Ni;k.useEffect(()=>{if(!Wt)return;const J=setTimeout(()=>Si(!0),600);return()=>clearTimeout(J)},[Wt]),c!==null&&!Wt&&(qt.current=!0);const Gi=k.useMemo(()=>{for(let J=ht.length-1;J>=0;J--)if(ht[J].kind==="say"&&ht[J].text)return ht[J].text;return null},[ht]),Yi=k.useCallback(async(J,Q)=>{const Ee=Sg(t.id,J.from,J.to);At.current.set(Q,Ee);const Me=Ac.get(Ee);if(Me){j(Pe=>new Map(Pe).set(Q,{...Me,transcriptKey:Ee}));return}if(Ct.current.has(Ee))return;Ct.current.add(Ee),j(Pe=>{var Oi;return((Oi=Pe.get(Q))==null?void 0:Oi.state)==="ready"?Pe:new Map(Pe).set(Q,{state:"loading",transcriptKey:Ee})});const We=await j5(t.id,J.from,J.to);Ct.current.delete(Ee);const Xe=We.ok?{state:"ready",data:We.data,transcriptKey:Ee}:{state:"error",error:We.error,transcriptKey:Ee},Oe=nt.current.get(Q);Oe&&Oe!==Ee&&Ac.delete(Oe),Ac.set(Ee,Xe),nt.current.set(Q,Ee),j(Pe=>{if(At.current.get(Q)!==Ee)return Pe;const Oi=Pe.get(Q);return!We.ok&&(Oi==null?void 0:Oi.state)==="ready"?new Map(Pe).set(Q,{...Oi,transcriptKey:Ee}):new Map(Pe).set(Q,Xe)})},[t.id]);k.useEffect(()=>{if(!(!i||!c))for(const J of ht){if(J.kind!=="seam"||J.open&&J.from===Pt)continue;const Q=Ec(t.id,J.from);if(!$.has(Q))continue;const Ee=Sg(t.id,J.from,J.to),Me=z.get(Q);(Me==null?void 0:Me.transcriptKey)===Ee||Ct.current.has(Ee)||Yi(J,Q)}},[i,c,ht,$,Yi,t.id,z,Pt]);const ce=k.useCallback(()=>{const J=H.current;J&&Be.current&&(J.scrollTop=J.scrollHeight)},[]),Ae=()=>{const J=H.current;J&&(Be.current=J.scrollHeight-J.scrollTop-J.clientHeight<48)};k.useLayoutEffect(ce,[c,ce]),k.useLayoutEffect(()=>{if(!i||typeof ResizeObserver!="function")return;const J=re.current;if(!J)return;const Q=new ResizeObserver(ce);return Q.observe(J),()=>Q.disconnect()},[i,ce]);const Re=()=>{oe.current=null,eA(),iA(H.current),F(null)},$e=k.useCallback(async J=>{clearTimeout(I.current),F(null);const Q=await sA(J);return F(Q?"copied":"failed"),Q&&(I.current=setTimeout(()=>F(null),1200)),Q},[]);k.useEffect(()=>()=>clearTimeout(I.current),[]);const zn=J=>{const Q=H.current,Ee=J.target;if(J.button!==0||!Q||!(Ee instanceof Element)||!tA())return;const Me=Ee.closest(ZC);if(Me&&Q.contains(Me))return;if(Ee===Q){const Oe=Q.getBoundingClientRect();if(J.clientX-Oe.left-Q.clientLeft>=Q.clientWidth||J.clientY-Oe.top-Q.clientTop>=Q.clientHeight)return}Re(),J.preventDefault();const We=J.detail===2?Ar.WORD:J.detail>=3?Ar.LINE:Ar.NORMAL,Xe=We===Ar.WORD?Cg(Q,J.clientX,J.clientY):We===Ar.LINE?Ag(Q,J.clientX,J.clientY):Nu(Q,J.clientX,J.clientY);Xe&&(X.current={mode:We,anchor:Xe.cloneRange(),x:J.clientX,y:J.clientY},We!==Ar.NORMAL&&(oe.current=Xe,kg(Xe)))};k.useEffect(()=>{if(!i)return;const J=Me=>{const We=X.current,Xe=H.current;if(!We||!Xe||(Me.preventDefault(),We.mode===Ar.NORMAL&&Math.hypot(Me.clientX-We.x,Me.clientY-We.y)<3))return;const Oe=We.mode===Ar.WORD?Cg(Xe,Me.clientX,Me.clientY):We.mode===Ar.LINE?Ag(Xe,Me.clientX,Me.clientY):Nu(Xe,Me.clientX,Me.clientY);if(!Oe||!We.anchor.startContainer.isConnected)return;const Pe=nA(We.anchor,Oe,We.mode);oe.current=Pe,kg(Pe)},Q=()=>{X.current=null},Ee=Me=>{const We=oe.current,Xe=G.current;if(!We||We.collapsed||!Xe)return;const Oe=Me.ctrlKey||Me.metaKey,Pe=Me.key.toLowerCase();if(Me.key==="Escape"){Re();return}if(Oe&&Pe==="c"){if(document.activeElement!==Xe||Xe.selectionStart!==Xe.selectionEnd)return;Me.preventDefault(),Me.stopPropagation(),$e(cC(We,H.current));return}if(document.activeElement!==Xe)return;const Oi=Me.key.length===1&&!Oe&&!Me.altKey,tn=Oe&&!Me.altKey&&["a","v","x","y","z"].includes(Pe),$n=Me.isComposing||Me.key==="Process"||Me.key==="Dead";(Oi||tn||$n||QC.has(Me.key))&&Re()};return document.addEventListener("mousemove",J,!0),document.addEventListener("mouseup",Q,!0),document.addEventListener("keydown",Ee,!0),()=>{X.current=null,Re(),document.removeEventListener("mousemove",J,!0),document.removeEventListener("mouseup",Q,!0),document.removeEventListener("keydown",Ee,!0)}},[i,$e]);const _r=()=>Re(),il=async J=>{var Ee,Me;if(!J||_)return;w(!0),R(null);const Q=await f4(t.id,J,{replyVia:"note"});w(!1),Q.ok?(v(""),L(((Ee=Q.outcome)==null?void 0:Ee.mentionSummary)||null),vt()):R(((Me=Q.outcome)==null?void 0:Me.error)||l("mobile.sendFailed"))},Zs=async()=>{if(x)return;A(!0),R(null);const J=await $5(t.id);A(!1),J.ok?vt():R(J.error||l("mobile.stopFailed"))},rl=J=>{if(!J)return l("mobile.you");const Q=e.find(Ee=>Ee.id===J);return Q?Hr(Q):J.slice(0,8)},Qs=J=>{const Q=Ec(t.id,J.from),Ee=new Set($);if(Ee.has(Q)){Ee.delete(Q),W(Ee);return}Ee.add(Q),W(Ee),J.open&&J.from===Pt||Yi(J,Q)},Xi=[];let Li=null;const jn=(J,Q)=>{xg(J)!==Li&&(Li=xg(J),Xi.push(p.jsxs("div",{className:"m-day",children:[p.jsx("div",{className:"m-gut",children:XC(J)}),p.jsx("div",{className:"m-day-rule"})]},`d${Q}`)))},Ft=J=>p.jsx("div",{className:"m-gut",children:p.jsx("time",{children:cu(J)})}),en=t.created||(d==null?void 0:d.created)||((Hn=c==null?void 0:c[0])==null?void 0:Hn.ts);d!=null&&d.prompt&&(en&&jn(en,"p"),Xi.push(p.jsxs("div",{className:"m-ev m-ev-prompt",children:[p.jsx(Wh,{ts:en,text:d.prompt}),en?Ft(en):p.jsx("div",{className:"m-gut"})]},"prompt")));for(const[J,Q]of ht.entries())if(jn(Q.ts,J),Q.kind==="quote")Xi.push(p.jsxs("div",{className:"m-ev m-ev-sent",children:[p.jsx(Wh,{who:Q.from?((ye=Q.envelope)==null?void 0:ye.label)||rl(Q.from):null,ts:Q.ts,text:Q.text}),Ft(Q.ts)]},J));else if(Q.kind==="say")Xi.push(p.jsxs("div",{className:"m-ev m-ev-say",children:[p.jsx("div",{className:"m-gut"}),p.jsxs("article",{className:"m-say",children:[p.jsxs("div",{className:"m-say-head",children:[p.jsx("time",{className:"m-line-time",children:cu(Q.ts)}),p.jsxs("span",{className:"m-say-chip",style:{color:lr[Q.status]},children:[p.jsx("span",{className:"m-ev-glyph",children:Au[Q.status]||"·"}),p.jsx("span",{className:"m-ev-word",children:l(`status.${Q.status}`)})]}),Q.text&&!x0()&&p.jsx("button",{type:"button",className:"m-copy-note",onClick:()=>$e(Q.text),children:l("mobile.copy")})]}),Q.text&&p.jsx("div",{className:"m-ev-note",children:p.jsx(pd,{children:Q.text})})]})]},J));else if(Q.kind==="event")Xi.push(p.jsxs("div",{className:"m-ev m-ev-line",children:[p.jsx("div",{className:"m-gut"}),p.jsxs("div",{className:"m-line",children:[p.jsx("time",{className:"m-line-time",children:cu(Q.ts)}),p.jsx("span",{className:"m-ev-glyph",style:{color:lr[Q.status]},children:Au[Q.status]||"·"}),p.jsx("span",{className:"m-ev-word",style:{color:lr[Q.status]},children:l(`status.${Q.status}`)}),Q.text&&p.jsx("div",{className:"m-line-text m-ev-note",children:p.jsx(pd,{children:Q.text})})]})]},J));else{const Ee=Ec(t.id,Q.from),Me=$.has(Ee),We=Q.open&&r==="live",Xe=Q.open&&Q.from===Pt,Oe=Xe?C===null?{state:"loading"}:C.error?{state:"error",error:C.error}:{state:"ready",data:C}:z.get(Ee),Pe=We?`${l("status.working")} · ${Qp(Math.max(0,T-Q.from))}`:Q.open?l("status.working"):`${l("mobile.worked")} ${Qp(Q.to-Q.from)}`,Oi=(Oe==null?void 0:Oe.state)==="ready"?Oe.data.turns.reduce((tn,$n)=>{var Lo;return tn+(((Lo=$n.tools)==null?void 0:Lo.length)||0)},0):0;Xi.push(p.jsxs("div",{className:"m-ev m-ev-seam",children:[p.jsx("div",{className:"m-gut"}),p.jsxs("div",{className:"m-seam",children:[p.jsxs("button",{type:"button",className:`m-seam-row${We?" is-live":""}`,"aria-expanded":Me,onClick:()=>Qs(Q),children:[p.jsx("span",{className:"m-seam-lead",children:Pe}),(Oe==null?void 0:Oe.state)==="ready"&&p.jsxs("span",{className:"m-seam-detail",children:[Oe.data.turns.length," turns · ",Oi," tool uses"]}),p.jsx(d4,{open:Me,className:"m-seam-caret"})]}),p.jsxs(hg,{loadToolOutput:te(Q.from),children:[Me&&p.jsxs("div",{className:"m-seam-inset",children:[(Oe==null?void 0:Oe.state)==="loading"&&p.jsx("div",{className:"m-transcript-state",children:"transcript 加载中…"}),(Oe==null?void 0:Oe.state)==="error"&&p.jsxs("div",{className:"m-transcript-state is-error",children:["transcript 已不可用:",Oe.error]}),(Oe==null?void 0:Oe.state)==="ready"&&p.jsx(Q7,{data:Oe.data,live:Xe})]}),Xe&&!Me&&p.jsx(ew,{turns:C==null?void 0:C.turns,revision:C==null?void 0:C.revision,lastSaid:Gi},Ee)]})]})]},J))}return p.jsx(hg,{children:p.jsxs("div",{className:"tl-chat",children:[p.jsx("div",{className:"m-timeline","data-selectable":!0,ref:H,onScroll:Ae,onMouseDown:zn,children:p.jsx("div",{className:"m-col",ref:re,children:c===null||Wt?p.jsx("div",{className:"m-empty",children:l("common.loading")}):Xi.length===0?p.jsx("div",{className:"m-empty",children:l("mobile.noEvents")}):Xi})}),q&&p.jsx("div",{className:`m-copy-status ${q}`,role:"status","aria-live":"polite","aria-atomic":"true",children:l(`mobile.${q==="copied"?"copied":"copyFailed"}`)}),p.jsx(oA,{session:t,state:r,active:i,inputRef:G,draft:m,setDraft:v,sending:_,send:il,sendErr:D,sendNote:E,onRestore:s,actionOutcome:n,onComposerPress:_r,working:t.status==="working",stopping:x,stop:Zs,specs:o,sessions:e,boardCommands:a})]})})}let yd=[],Q3=[];(()=>{let t="lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,1n,9,16,o,,x,1i,3,,i,,7,a,2,t,3,1k,,,7,2,2,2,3,9,,a,2,q,,2,3,1k,,,5,4,2,2,3,3,,u,2,3,,b,3,1k,,,8,,3,,3,k,2,m,6,,3,1k,,,7,2,2,2,3,7,3,a,2,u,,1n,5,3,3,,4,9,,14,5,1j,,,7,,3,,4,7,2,b,2,t,3,1k,,,7,,3,,4,7,2,b,2,f,,c,4,1j,2,,7,,3,,4,9,,a,2,t,3,1y,,4,6,,,,8,i,2,1p,,,8,c,8,2q,,,a,b,7,21,2,r,,,,,,4,2,1d,k,,2,5,b,,10,9,,2u,b,,6,n,4,4,3,g,4,d,,,3,6,,f,,jj,3,qa,4,s,3,t,2,u,2,1s,w,9,,19,3,,,39,2,y,,3a,c,4,c,63,5,1l,a,,,,,2,o,2,,1c,1a,2,c,k,5,1b,h,12,9,c,3,u,d,1k,e,1c,k,48,3,,l,4,,6,,2,3,5i,1s,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,n,5,4,,2b,2,1e,i,q,i,d,,12,8,p,d,18,4,1b,e,10,,1v,e,c,,8,2,1a,,1f,,,3,2,2,5,2,,,15,5,5,2,6k,8,,2,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,1t,5,8t,2,25,6,1y,b,1d,4,3e,3,1h,f,15,,2,2,a,4,19,b,7,,1p,3,10,e,g,2,18,,c,3,1c,e,8,4,,2,2k,c,6,,2,,4d,c,l,4,1j,2,,7,2,2,2,3,9,,a,2,2,7,3,5,1v,9,,,2,,,4,,5,,,e,2,2a,i,n,,29,k,6j,7,2,9,r,2,2a,h,2y,d,2t,3,2,a,74,f,6t,6,,2,2,4,,,,2,3x,7,2,7,3,,s,a,14,7,,4,8,,9,b,1a,g,5i,8,5j,8,,8,2a,m,,e,3e,6,3,,,2,,7,,,1u,5,,2,,5,9n,4,9,2,,,1c,7,3,5,n,,44l,,6,f,8ug,i,1xc,5,1n,7,t4,,,1j,7,4,29,,b,2,f57,2,3mp,1a,2,n,f2,5,3,6,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,2s,,4g,7,af,,1p,4,e4,4,72,2,6r,,2,,7,2,5,,d6,7,31,7,240,5".split(",").map(e=>e?parseInt(e,36):1);for(let e=0,i=0;e<t.length;e++)(e%2?Q3:yd).push(i=i+t[e])})();function lA(t){if(t<768)return!1;for(let e=0,i=yd.length;;){let r=e+i>>1;if(t<yd[r])i=r;else if(t>=Q3[r])e=r+1;else return!0;if(e==i)return!1}}function Eg(t){return t>=127462&&t<=127487}const Dg=8205;function uA(t,e,i=!0,r=!0){return(i?eb:cA)(t,e,r)}function eb(t,e,i){if(e==t.length)return e;e&&tb(t.charCodeAt(e))&&ib(t.charCodeAt(e-1))&&e--;let r=Dc(t,e);for(e+=Mg(r);e<t.length;){let s=Dc(t,e);if(r==Dg||s==Dg||i&&lA(s))e+=Mg(s),r=s;else if(Eg(s)){let n=0,o=e-2;for(;o>=0&&Eg(Dc(t,o));)n++,o-=2;if(n%2==0)break;e+=2}else break}return e}function cA(t,e,i){for(;e>1;){let r=eb(t,e-2,i);if(r<e)return r;e--}return 0}function Dc(t,e){let i=t.charCodeAt(e);if(!ib(i)||e+1==t.length)return i;let r=t.charCodeAt(e+1);return tb(r)?(i-55296<<10)+(r-56320)+65536:i}function tb(t){return t>=56320&&t<57344}function ib(t){return t>=55296&&t<56320}function Mg(t){return t<65536?1:2}let Ve=class rb{lineAt(e){if(e<0||e>this.length)throw new RangeError(`Invalid position ${e} in document of length ${this.length}`);return this.lineInner(e,!1,1,0)}line(e){if(e<1||e>this.lines)throw new RangeError(`Invalid line number ${e} in ${this.lines}-line document`);return this.lineInner(e,!0,1,0)}replace(e,i,r){[e,i]=_o(this,e,i);let s=[];return this.decompose(0,e,s,2),r.length&&r.decompose(0,r.length,s,3),this.decompose(i,this.length,s,1),Tr.from(s,this.length-(i-e)+r.length)}append(e){return this.replace(this.length,this.length,e)}slice(e,i=this.length){[e,i]=_o(this,e,i);let r=[];return this.decompose(e,i,r,0),Tr.from(r,i-e)}eq(e){if(e==this)return!0;if(e.length!=this.length||e.lines!=this.lines)return!1;let i=this.scanIdentical(e,1),r=this.length-this.scanIdentical(e,-1),s=new fa(this),n=new fa(e);for(let o=i,a=i;;){if(s.next(o),n.next(o),o=0,s.lineBreak!=n.lineBreak||s.done!=n.done||s.value!=n.value)return!1;if(a+=s.value.length,s.done||a>=r)return!0}}iter(e=1){return new fa(this,e)}iterRange(e,i=this.length){return new sb(this,e,i)}iterLines(e,i){let r;if(e==null)r=this.iter();else{i==null&&(i=this.lines+1);let s=this.line(e).from;r=this.iterRange(s,Math.max(s,i==this.lines+1?this.length:i<=1?0:this.line(i-1).to))}return new nb(r)}toString(){return this.sliceString(0)}toJSON(){let e=[];return this.flatten(e),e}constructor(){}static of(e){if(e.length==0)throw new RangeError("A document must have at least one line");return e.length==1&&!e[0]?rb.empty:e.length<=32?new St(e):Tr.from(St.split(e,[]))}};class St extends Ve{constructor(e,i=hA(e)){super(),this.text=e,this.length=i}get lines(){return this.text.length}get children(){return null}lineInner(e,i,r,s){for(let n=0;;n++){let o=this.text[n],a=s+o.length;if((i?r:a)>=e)return new dA(s,a,r,o);s=a+1,r++}}decompose(e,i,r,s){let n=e<=0&&i>=this.length?this:new St(Tg(this.text,e,i),Math.min(i,this.length)-Math.max(0,e));if(s&1){let o=r.pop(),a=pu(n.text,o.text.slice(),0,n.length);if(a.length<=32)r.push(new St(a,o.length+n.length));else{let l=a.length>>1;r.push(new St(a.slice(0,l)),new St(a.slice(l)))}}else r.push(n)}replace(e,i,r){if(!(r instanceof St))return super.replace(e,i,r);[e,i]=_o(this,e,i);let s=pu(this.text,pu(r.text,Tg(this.text,0,e)),i),n=this.length+r.length-(i-e);return s.length<=32?new St(s,n):Tr.from(St.split(s,[]),n)}sliceString(e,i=this.length,r=`
|
|
317
317
|
`){[e,i]=_o(this,e,i);let s="";for(let n=0,o=0;n<=i&&o<this.text.length;o++){let a=this.text[o],l=n+a.length;n>e&&o&&(s+=r),e<l&&i>n&&(s+=a.slice(Math.max(0,e-n),i-n)),n=l+1}return s}flatten(e){for(let i of this.text)e.push(i)}scanIdentical(){return 0}static split(e,i){let r=[],s=-1;for(let n of e)r.push(n),s+=n.length+1,r.length==32&&(i.push(new St(r,s)),r=[],s=-1);return s>-1&&i.push(new St(r,s)),i}}class Tr extends Ve{constructor(e,i){super(),this.children=e,this.length=i,this.lines=0;for(let r of e)this.lines+=r.lines}lineInner(e,i,r,s){for(let n=0;;n++){let o=this.children[n],a=s+o.length,l=r+o.lines-1;if((i?l:a)>=e)return o.lineInner(e,i,r,s);s=a+1,r=l+1}}decompose(e,i,r,s){for(let n=0,o=0;o<=i&&n<this.children.length;n++){let a=this.children[n],l=o+a.length;if(e<=l&&i>=o){let u=s&((o<=e?1:0)|(l>=i?2:0));o>=e&&l<=i&&!u?r.push(a):a.decompose(e-o,i-o,r,u)}o=l+1}}replace(e,i,r){if([e,i]=_o(this,e,i),r.lines<this.lines)for(let s=0,n=0;s<this.children.length;s++){let o=this.children[s],a=n+o.length;if(e>=n&&i<=a){let l=o.replace(e-n,i-n,r),u=this.lines-o.lines+l.lines;if(l.lines<u>>4&&l.lines>u>>6){let c=this.children.slice();return c[s]=l,new Tr(c,this.length-(i-e)+r.length)}return super.replace(n,a,l)}n=a+1}return super.replace(e,i,r)}sliceString(e,i=this.length,r=`
|
|
318
318
|
`){[e,i]=_o(this,e,i);let s="";for(let n=0,o=0;n<this.children.length&&o<=i;n++){let a=this.children[n],l=o+a.length;o>e&&n&&(s+=r),e<l&&i>o&&(s+=a.sliceString(e-o,i-o,r)),o=l+1}return s}flatten(e){for(let i of this.children)i.flatten(e)}scanIdentical(e,i){if(!(e instanceof Tr))return 0;let r=0,[s,n,o,a]=i>0?[0,0,this.children.length,e.children.length]:[this.children.length-1,e.children.length-1,-1,-1];for(;;s+=i,n+=i){if(s==o||n==a)return r;let l=this.children[s],u=e.children[n];if(l!=u)return r+l.scanIdentical(u,i);r+=l.length+1}}static from(e,i=e.reduce((r,s)=>r+s.length+1,-1)){let r=0;for(let f of e)r+=f.lines;if(r<32){let f=[];for(let m of e)m.flatten(f);return new St(f,i)}let s=Math.max(32,r>>5),n=s<<1,o=s>>1,a=[],l=0,u=-1,c=[];function h(f){let m;if(f.lines>n&&f instanceof Tr)for(let v of f.children)h(v);else f.lines>o&&(l>o||!l)?(d(),a.push(f)):f instanceof St&&l&&(m=c[c.length-1])instanceof St&&f.lines+m.lines<=32?(l+=f.lines,u+=f.length+1,c[c.length-1]=new St(m.text.concat(f.text),m.length+1+f.length)):(l+f.lines>s&&d(),l+=f.lines,u+=f.length+1,c.push(f))}function d(){l!=0&&(a.push(c.length==1?c[0]:Tr.from(c,u)),u=-1,l=c.length=0)}for(let f of e)h(f);return d(),a.length==1?a[0]:new Tr(a,i)}}Ve.empty=new St([""],0);function hA(t){let e=-1;for(let i of t)e+=i.length+1;return e}function pu(t,e,i=0,r=1e9){for(let s=0,n=0,o=!0;n<t.length&&s<=r;n++){let a=t[n],l=s+a.length;l>=i&&(l>r&&(a=a.slice(0,r-s)),s<i&&(a=a.slice(i-s)),o?(e[e.length-1]+=a,o=!1):e.push(a)),s=l+1}return e}function Tg(t,e,i){return pu(t,[""],e,i)}class fa{constructor(e,i=1){this.dir=i,this.done=!1,this.lineBreak=!1,this.value="",this.nodes=[e],this.offsets=[i>0?1:(e instanceof St?e.text.length:e.children.length)<<1]}nextInner(e,i){for(this.done=this.lineBreak=!1;;){let r=this.nodes.length-1,s=this.nodes[r],n=this.offsets[r],o=n>>1,a=s instanceof St?s.text.length:s.children.length;if(o==(i>0?a:0)){if(r==0)return this.done=!0,this.value="",this;i>0&&this.offsets[r-1]++,this.nodes.pop(),this.offsets.pop()}else if((n&1)==(i>0?0:1)){if(this.offsets[r]+=i,e==0)return this.lineBreak=!0,this.value=`
|
|
319
319
|
`,this;e--}else if(s instanceof St){let l=s.text[o+(i<0?-1:0)];if(this.offsets[r]+=i,l.length>Math.max(0,e))return this.value=e==0?l:i>0?l.slice(e):l.slice(0,l.length-e),this;e-=l.length}else{let l=s.children[o+(i<0?-1:0)];e>l.length?(e-=l.length,this.offsets[r]+=i):(i<0&&this.offsets[r]--,this.nodes.push(l),this.offsets.push(i>0?1:(l instanceof St?l.text.length:l.children.length)<<1))}}}next(e=0){return e<0&&(this.nextInner(-e,-this.dir),e=this.value.length),this.nextInner(e,this.dir)}}class sb{constructor(e,i,r){this.value="",this.done=!1,this.cursor=new fa(e,i>r?-1:1),this.pos=i>r?e.length:0,this.from=Math.min(i,r),this.to=Math.max(i,r)}nextInner(e,i){if(i<0?this.pos<=this.from:this.pos>=this.to)return this.value="",this.done=!0,this;e+=Math.max(0,i<0?this.pos-this.to:this.from-this.pos);let r=i<0?this.pos-this.from:this.to-this.pos;e>r&&(e=r),r-=e;let{value:s}=this.cursor.next(e);return this.pos+=(s.length+e)*i,this.value=s.length<=r?s:i<0?s.slice(s.length-r):s.slice(0,r),this.done=!this.value,this}next(e=0){return e<0?e=Math.max(e,this.from-this.pos):e>0&&(e=Math.min(e,this.to-this.pos)),this.nextInner(e,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&this.value!=""}}class nb{constructor(e){this.inner=e,this.afterBreak=!0,this.value="",this.done=!1}next(e=0){let{done:i,lineBreak:r,value:s}=this.inner.next(e);return i&&this.afterBreak?(this.value="",this.afterBreak=!1):i?(this.done=!0,this.value=""):r?this.afterBreak?this.value="":(this.afterBreak=!0,this.next()):(this.value=s,this.afterBreak=!1),this}get lineBreak(){return!1}}typeof Symbol<"u"&&(Ve.prototype[Symbol.iterator]=function(){return this.iter()},fa.prototype[Symbol.iterator]=sb.prototype[Symbol.iterator]=nb.prototype[Symbol.iterator]=function(){return this});class dA{constructor(e,i,r,s){this.from=e,this.to=i,this.number=r,this.text=s}get length(){return this.to-this.from}}function _o(t,e,i){return e=Math.max(0,Math.min(t.length,e)),[e,Math.max(e,Math.min(t.length,i))]}function Pr(t,e,i=!0,r=!0){return uA(t,e,i,r)}function fA(t){return t>=56320&&t<57344}function pA(t){return t>=55296&&t<56320}function mA(t,e){let i=t.charCodeAt(e);if(!pA(i)||e+1==t.length)return i;let r=t.charCodeAt(e+1);return fA(r)?(i-55296<<10)+(r-56320)+65536:i}function gA(t){return t<65536?1:2}const wd=/\r\n?|\n/;var ji=function(t){return t[t.Simple=0]="Simple",t[t.TrackDel=1]="TrackDel",t[t.TrackBefore=2]="TrackBefore",t[t.TrackAfter=3]="TrackAfter",t}(ji||(ji={}));class ns{constructor(e){this.sections=e}get length(){let e=0;for(let i=0;i<this.sections.length;i+=2)e+=this.sections[i];return e}get newLength(){let e=0;for(let i=0;i<this.sections.length;i+=2){let r=this.sections[i+1];e+=r<0?this.sections[i]:r}return e}get empty(){return this.sections.length==0||this.sections.length==2&&this.sections[1]<0}iterGaps(e){for(let i=0,r=0,s=0;i<this.sections.length;){let n=this.sections[i++],o=this.sections[i++];o<0?(e(r,s,n),s+=n):s+=o,r+=n}}iterChangedRanges(e,i=!1){xd(this,e,i)}get invertedDesc(){let e=[];for(let i=0;i<this.sections.length;){let r=this.sections[i++],s=this.sections[i++];s<0?e.push(r,s):e.push(s,r)}return new ns(e)}composeDesc(e){return this.empty?e:e.empty?this:ob(this,e)}mapDesc(e,i=!1){return e.empty?this:Sd(this,e,i)}mapPos(e,i=-1,r=ji.Simple){let s=0,n=0;for(let o=0;o<this.sections.length;){let a=this.sections[o++],l=this.sections[o++],u=s+a;if(l<0){if(u>e)return n+(e-s);n+=a}else{if(r!=ji.Simple&&u>=e&&(r==ji.TrackDel&&s<e&&u>e||r==ji.TrackBefore&&s<e||r==ji.TrackAfter&&u>e))return null;if(u>e||u==e&&i<0&&!a)return e==s||i<0?n:n+l;n+=l}s=u}if(e>s)throw new RangeError(`Position ${e} is out of range for changeset of length ${s}`);return n}touchesRange(e,i=e){for(let r=0,s=0;r<this.sections.length&&s<=i;){let n=this.sections[r++],o=this.sections[r++],a=s+n;if(o>=0&&s<=i&&a>=e)return s<e&&a>i?"cover":!0;s=a}return!1}toString(){let e="";for(let i=0;i<this.sections.length;){let r=this.sections[i++],s=this.sections[i++];e+=(e?" ":"")+r+(s>=0?":"+s:"")}return e}toJSON(){return this.sections}static fromJSON(e){if(!Array.isArray(e)||e.length%2||e.some(i=>typeof i!="number"))throw new RangeError("Invalid JSON representation of ChangeDesc");return new ns(e)}static create(e){return new ns(e)}}class Mt extends ns{constructor(e,i){super(e),this.inserted=i}apply(e){if(this.length!=e.length)throw new RangeError("Applying change set to a document with the wrong length");return xd(this,(i,r,s,n,o)=>e=e.replace(s,s+(r-i),o),!1),e}mapDesc(e,i=!1){return Sd(this,e,i,!0)}invert(e){let i=this.sections.slice(),r=[];for(let s=0,n=0;s<i.length;s+=2){let o=i[s],a=i[s+1];if(a>=0){i[s]=a,i[s+1]=o;let l=s>>1;for(;r.length<l;)r.push(Ve.empty);r.push(o?e.slice(n,n+o):Ve.empty)}n+=o}return new Mt(i,r)}compose(e){return this.empty?e:e.empty?this:ob(this,e,!0)}map(e,i=!1){return e.empty?this:Sd(this,e,i,!0)}iterChanges(e,i=!1){xd(this,e,i)}get desc(){return ns.create(this.sections)}filter(e){let i=[],r=[],s=[],n=new La(this);e:for(let o=0,a=0;;){let l=o==e.length?1e9:e[o++];for(;a<l||a==l&&n.len==0;){if(n.done)break e;let c=Math.min(n.len,l-a);li(s,c,-1);let h=n.ins==-1?-1:n.off==0?n.ins:0;li(i,c,h),h>0&&Is(r,i,n.text),n.forward(c),a+=c}let u=e[o++];for(;a<u;){if(n.done)break e;let c=Math.min(n.len,u-a);li(i,c,-1),li(s,c,n.ins==-1?-1:n.off==0?n.ins:0),n.forward(c),a+=c}}return{changes:new Mt(i,r),filtered:ns.create(s)}}toJSON(){let e=[];for(let i=0;i<this.sections.length;i+=2){let r=this.sections[i],s=this.sections[i+1];s<0?e.push(r):s==0?e.push([r]):e.push([r].concat(this.inserted[i>>1].toJSON()))}return e}static of(e,i,r){let s=[],n=[],o=0,a=null;function l(c=!1){if(!c&&!s.length)return;o<i&&li(s,i-o,-1);let h=new Mt(s,n);a=a?a.compose(h.map(a)):h,s=[],n=[],o=0}function u(c){if(Array.isArray(c))for(let h of c)u(h);else if(c instanceof Mt){if(c.length!=i)throw new RangeError(`Mismatched change set length (got ${c.length}, expected ${i})`);l(),a=a?a.compose(c.map(a)):c}else{let{from:h,to:d=h,insert:f}=c;if(h>d||h<0||d>i)throw new RangeError(`Invalid change range ${h} to ${d} (in doc of length ${i})`);let m=f?typeof f=="string"?Ve.of(f.split(r||wd)):f:Ve.empty,v=m.length;if(h==d&&v==0)return;h<o&&l(),h>o&&li(s,h-o,-1),li(s,d-h,v),Is(n,s,m),o=d}}return u(e),l(!a),a}static empty(e){return new Mt(e?[e,-1]:[],[])}static fromJSON(e){if(!Array.isArray(e))throw new RangeError("Invalid JSON representation of ChangeSet");let i=[],r=[];for(let s=0;s<e.length;s++){let n=e[s];if(typeof n=="number")i.push(n,-1);else{if(!Array.isArray(n)||typeof n[0]!="number"||n.some((o,a)=>a&&typeof o!="string"))throw new RangeError("Invalid JSON representation of ChangeSet");if(n.length==1)i.push(n[0],0);else{for(;r.length<s;)r.push(Ve.empty);r[s]=Ve.of(n.slice(1)),i.push(n[0],r[s].length)}}}return new Mt(i,r)}static createSet(e,i){return new Mt(e,i)}}function li(t,e,i,r=!1){if(e==0&&i<=0)return;let s=t.length-2;s>=0&&i<=0&&i==t[s+1]?t[s]+=e:s>=0&&e==0&&t[s]==0?t[s+1]+=i:r?(t[s]+=e,t[s+1]+=i):t.push(e,i)}function Is(t,e,i){if(i.length==0)return;let r=e.length-2>>1;if(r<t.length)t[t.length-1]=t[t.length-1].append(i);else{for(;t.length<r;)t.push(Ve.empty);t.push(i)}}function xd(t,e,i){let r=t.inserted;for(let s=0,n=0,o=0;o<t.sections.length;){let a=t.sections[o++],l=t.sections[o++];if(l<0)s+=a,n+=a;else{let u=s,c=n,h=Ve.empty;for(;u+=a,c+=l,l&&r&&(h=h.append(r[o-2>>1])),!(i||o==t.sections.length||t.sections[o+1]<0);)a=t.sections[o++],l=t.sections[o++];e(s,u,n,c,h),s=u,n=c}}}function Sd(t,e,i,r=!1){let s=[],n=r?[]:null,o=new La(t),a=new La(e);for(let l=-1;;){if(o.done&&a.len||a.done&&o.len)throw new Error("Mismatched change set lengths");if(o.ins==-1&&a.ins==-1){let u=Math.min(o.len,a.len);li(s,u,-1),o.forward(u),a.forward(u)}else if(a.ins>=0&&(o.ins<0||l==o.i||o.off==0&&(a.len<o.len||a.len==o.len&&!i))){let u=a.len;for(li(s,a.ins,-1);u;){let c=Math.min(o.len,u);o.ins>=0&&l<o.i&&o.len<=c&&(li(s,0,o.ins),n&&Is(n,s,o.text),l=o.i),o.forward(c),u-=c}a.next()}else if(o.ins>=0){let u=0,c=o.len;for(;c;)if(a.ins==-1){let h=Math.min(c,a.len);u+=h,c-=h,a.forward(h)}else if(a.ins==0&&a.len<c)c-=a.len,a.next();else break;li(s,u,l<o.i?o.ins:0),n&&l<o.i&&Is(n,s,o.text),l=o.i,o.forward(o.len-c)}else{if(o.done&&a.done)return n?Mt.createSet(s,n):ns.create(s);throw new Error("Mismatched change set lengths")}}}function ob(t,e,i=!1){let r=[],s=i?[]:null,n=new La(t),o=new La(e);for(let a=!1;;){if(n.done&&o.done)return s?Mt.createSet(r,s):ns.create(r);if(n.ins==0)li(r,n.len,0,a),n.next();else if(o.len==0&&!o.done)li(r,0,o.ins,a),s&&Is(s,r,o.text),o.next();else{if(n.done||o.done)throw new Error("Mismatched change set lengths");{let l=Math.min(n.len2,o.len),u=r.length;if(n.ins==-1){let c=o.ins==-1?-1:o.off?0:o.ins;li(r,l,c,a),s&&c&&Is(s,r,o.text)}else o.ins==-1?(li(r,n.off?0:n.len,l,a),s&&Is(s,r,n.textBit(l))):(li(r,n.off?0:n.len,o.off?0:o.ins,a),s&&!o.off&&Is(s,r,o.text));a=(n.ins>l||o.ins>=0&&o.len>l)&&(a||r.length>u),n.forward2(l),o.forward(l)}}}}class La{constructor(e){this.set=e,this.i=0,this.next()}next(){let{sections:e}=this.set;this.i<e.length?(this.len=e[this.i++],this.ins=e[this.i++]):(this.len=0,this.ins=-2),this.off=0}get done(){return this.ins==-2}get len2(){return this.ins<0?this.len:this.ins}get text(){let{inserted:e}=this.set,i=this.i-2>>1;return i>=e.length?Ve.empty:e[i]}textBit(e){let{inserted:i}=this.set,r=this.i-2>>1;return r>=i.length&&!e?Ve.empty:i[r].slice(this.off,e==null?void 0:this.off+e)}forward(e){e==this.len?this.next():(this.len-=e,this.off+=e)}forward2(e){this.ins==-1?this.forward(e):e==this.ins?this.next():(this.ins-=e,this.off+=e)}}class Rs{constructor(e,i,r,s){this.from=e,this.to=i,this.flags=r,this.goalColumn=s}get anchor(){return this.flags&32?this.to:this.from}get head(){return this.flags&32?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return this.flags&8?-1:this.flags&16?1:0}get undirectional(){return(this.flags&64)>0}get bidiLevel(){let e=this.flags&7;return e==7?null:e}map(e,i=-1){let r,s;return this.empty?r=s=e.mapPos(this.from,i):(r=e.mapPos(this.from,1),s=e.mapPos(this.to,-1)),r==this.from&&s==this.to?this:new Rs(r,s,this.flags,this.goalColumn)}extend(e,i=e,r=0){if(e<=this.anchor&&i>=this.anchor)return ve.range(e,i,void 0,void 0,r);let s=Math.abs(e-this.anchor)>Math.abs(i-this.anchor)?e:i;return ve.range(this.anchor,s,void 0,void 0,r)}eq(e,i=!1){return this.anchor==e.anchor&&this.head==e.head&&this.goalColumn==e.goalColumn&&(!i||!this.empty||this.assoc==e.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(e){if(!e||typeof e.anchor!="number"||typeof e.head!="number")throw new RangeError("Invalid JSON representation for SelectionRange");return ve.range(e.anchor,e.head)}static create(e,i,r,s){return new Rs(e,i,r,s)}}class ve{constructor(e,i){this.ranges=e,this.mainIndex=i}map(e,i=-1){return e.empty?this:ve.create(this.ranges.map(r=>r.map(e,i)),this.mainIndex)}eq(e,i=!1){if(this.ranges.length!=e.ranges.length||this.mainIndex!=e.mainIndex)return!1;for(let r=0;r<this.ranges.length;r++)if(!this.ranges[r].eq(e.ranges[r],i))return!1;return!0}get main(){return this.ranges[this.mainIndex]}asSingle(){return this.ranges.length==1?this:new ve([this.main],0)}addRange(e,i=!0){return ve.create([e].concat(this.ranges),i?0:this.mainIndex+1)}replaceRange(e,i=this.mainIndex){let r=this.ranges.slice();return r[i]=e,ve.create(r,this.mainIndex)}toJSON(){return{ranges:this.ranges.map(e=>e.toJSON()),main:this.mainIndex}}static fromJSON(e){if(!e||!Array.isArray(e.ranges)||typeof e.main!="number"||e.main>=e.ranges.length)throw new RangeError("Invalid JSON representation for EditorSelection");return new ve(e.ranges.map(i=>Rs.fromJSON(i)),e.main)}static single(e,i=e){return new ve([ve.range(e,i)],0)}static create(e,i=0){if(e.length==0)throw new RangeError("A selection needs at least one range");for(let r=0,s=0;s<e.length;s++){let n=e[s];if(n.empty?n.from<=r:n.from<r)return ve.normalized(e.slice(),i);r=n.to}return new ve(e,i)}static cursor(e,i=0,r,s){return Rs.create(e,e,(i==0?0:i<0?8:16)|(r==null?7:Math.min(6,r)),s)}static range(e,i,r,s,n){let o=s==null?7:Math.min(6,s);return!n&&e!=i&&(n=i<e?1:-1),n&&(o|=n<0?8:16),i<e?Rs.create(i,e,o|32,r):Rs.create(e,i,o,r)}static undirectionalRange(e,i){return Rs.create(e,i,64,void 0)}static normalized(e,i=0){let r=e[i];e.sort((s,n)=>s.from-n.from),i=e.indexOf(r);for(let s=1;s<e.length;s++){let n=e[s],o=e[s-1];if(n.empty?n.from<=o.to:n.from<o.to){let a=o.from,l=Math.max(n.to,o.to);s<=i&&i--,e.splice(--s,2,n.anchor>n.head?ve.range(l,a):ve.range(a,l))}}return new ve(e,i)}}function ab(t,e){for(let i of t.ranges)if(i.to>e)throw new RangeError("Selection points outside of document")}let a1=0;class we{constructor(e,i,r,s,n){this.combine=e,this.compareInput=i,this.compare=r,this.isStatic=s,this.id=a1++,this.default=e([]),this.extensions=typeof n=="function"?n(this):n}get reader(){return this}static define(e={}){return new we(e.combine||(i=>i),e.compareInput||((i,r)=>i===r),e.compare||(e.combine?(i,r)=>i===r:l1),!!e.static,e.enables)}of(e){return new mu([],this,0,e)}compute(e,i){if(this.isStatic)throw new Error("Can't compute a static facet");return new mu(e,this,1,i)}computeN(e,i){if(this.isStatic)throw new Error("Can't compute a static facet");return new mu(e,this,2,i)}from(e,i){return i||(i=r=>r),this.compute([e],r=>i(r.field(e)))}}function l1(t,e){return t==e||t.length==e.length&&t.every((i,r)=>i===e[r])}class mu{constructor(e,i,r,s){this.dependencies=e,this.facet=i,this.type=r,this.value=s,this.id=a1++}dynamicSlot(e){var i;let r=this.value,s=this.facet.compareInput,n=this.id,o=e[n]>>1,a=this.type==2,l=!1,u=!1,c=[];for(let h of this.dependencies)h=="doc"?l=!0:h=="selection"?u=!0:((i=e[h.id])!==null&&i!==void 0?i:1)&1||c.push(e[h.id]);return{create(h){return h.values[o]=r(h),1},update(h,d){if(l&&d.docChanged||u&&(d.docChanged||d.selection)||kd(h,c)){let f=r(h);if(a?!Bg(f,h.values[o],s):!s(f,h.values[o]))return h.values[o]=f,1}return 0},reconfigure:(h,d)=>{let f,m=d.config.address[n];if(m!=null){let v=Ou(d,m);if(this.dependencies.every(_=>_ instanceof we?d.facet(_)===h.facet(_):_ instanceof or?d.field(_,!1)==h.field(_,!1):!0)||(a?Bg(f=r(h),v,s):s(f=r(h),v)))return h.values[o]=v,0}else f=r(h);return h.values[o]=f,1}}}get extension(){return this}}function Bg(t,e,i){if(t.length!=e.length)return!1;for(let r=0;r<t.length;r++)if(!i(t[r],e[r]))return!1;return!0}function kd(t,e){let i=!1;for(let r of e)pa(t,r)&1&&(i=!0);return i}function vA(t,e,i){let r=i.map(l=>t[l.id]),s=i.map(l=>l.type),n=r.filter(l=>!(l&1)),o=t[e.id]>>1;function a(l){let u=[];for(let c=0;c<r.length;c++){let h=Ou(l,r[c]);if(s[c]==2)for(let d of h)u.push(d);else u.push(h)}return e.combine(u)}return{create(l){for(let u of r)pa(l,u);return l.values[o]=a(l),1},update(l,u){if(!kd(l,n))return 0;let c=a(l);return e.compare(c,l.values[o])?0:(l.values[o]=c,1)},reconfigure(l,u){let c=kd(l,r),h=u.config.facets[e.id],d=u.facet(e);if(h&&!c&&l1(i,h))return l.values[o]=d,0;let f=a(l);return e.compare(f,d)?(l.values[o]=d,0):(l.values[o]=f,1)}}}const Rl=we.define({static:!0});class or{constructor(e,i,r,s,n){this.id=e,this.createF=i,this.updateF=r,this.compareF=s,this.spec=n,this.provides=void 0}static define(e){let i=new or(a1++,e.create,e.update,e.compare||((r,s)=>r===s),e);return e.provide&&(i.provides=e.provide(i)),i}create(e){let i=e.facet(Rl).find(r=>r.field==this);return((i==null?void 0:i.create)||this.createF)(e)}slot(e){let i=e[this.id]>>1;return{create:r=>(r.values[i]=this.create(r),1),update:(r,s)=>{let n=r.values[i],o=this.updateF(n,s);return this.compareF(n,o)?0:(r.values[i]=o,1)},reconfigure:(r,s)=>{let n=r.facet(Rl),o=s.facet(Rl),a;return(a=n.find(l=>l.field==this))&&a!=o.find(l=>l.field==this)?(r.values[i]=a.create(r),1):s.config.address[this.id]!=null?(r.values[i]=s.field(this),0):(r.values[i]=this.create(r),1)}}}init(e){return[this,Rl.of({field:this,create:e})]}get extension(){return this}}const gn={lowest:4,low:3,default:2,high:1,highest:0};function Wo(t){return e=>new lb(e,t)}const Fn={highest:Wo(gn.highest),high:Wo(gn.high),default:Wo(gn.default),low:Wo(gn.low),lowest:Wo(gn.lowest)};class lb{constructor(e,i){this.inner=e,this.prec=i}get extension(){return this}}class Ro{of(e){return new Cd(this,e)}reconfigure(e){return Ro.reconfigure.of({compartment:this,extension:e})}get(e){return e.config.compartments.get(this)}}class Cd{constructor(e,i){this.compartment=e,this.inner=i}get extension(){return this}}class Lu{constructor(e,i,r,s,n,o){for(this.base=e,this.compartments=i,this.dynamicSlots=r,this.address=s,this.staticValues=n,this.facets=o,this.statusTemplate=[];this.statusTemplate.length<r.length;)this.statusTemplate.push(0)}staticFacet(e){let i=this.address[e.id];return i==null?e.default:this.staticValues[i>>1]}static resolve(e,i,r){let s=[],n=Object.create(null),o=new Map;for(let d of bA(e,i,o))d instanceof or?s.push(d):(n[d.facet.id]||(n[d.facet.id]=[])).push(d);let a=Object.create(null),l=[],u=[];for(let d of s)a[d.id]=u.length<<1,u.push(f=>d.slot(f));let c=r==null?void 0:r.config.facets;for(let d in n){let f=n[d],m=f[0].facet,v=c&&c[d]||[];if(f.every(_=>_.type==0))if(a[m.id]=l.length<<1|1,l1(v,f))l.push(r.facet(m));else{let _=m.combine(f.map(w=>w.value));l.push(r&&m.compare(_,r.facet(m))?r.facet(m):_)}else{for(let _ of f)_.type==0?(a[_.id]=l.length<<1|1,l.push(_.value)):(a[_.id]=u.length<<1,u.push(w=>_.dynamicSlot(w)));a[m.id]=u.length<<1,u.push(_=>vA(_,m,f))}}let h=u.map(d=>d(a));return new Lu(e,o,h,a,l,n)}}function bA(t,e,i){let r=[[],[],[],[],[]],s=new Map;function n(o,a){let l=s.get(o);if(l!=null){if(l<=a)return;let u=r[l].indexOf(o);u>-1&&r[l].splice(u,1),o instanceof Cd&&i.delete(o.compartment)}if(s.set(o,a),Array.isArray(o))for(let u of o)n(u,a);else if(o instanceof Cd){if(i.has(o.compartment))throw new RangeError("Duplicate use of compartment in extensions");let u=e.get(o.compartment)||o.inner;i.set(o.compartment,u),n(u,a)}else if(o instanceof lb)n(o.inner,o.prec);else if(o instanceof or)r[a].push(o),o.provides&&n(o.provides,a);else if(o instanceof mu)r[a].push(o),o.facet.extensions&&n(o.facet.extensions,gn.default);else{let u=o.extension;if(!u)throw new Error(`Unrecognized extension value in extension set (${o}).`);if(u==o)throw new Error(`Unrecognized extension value in extension set (${o}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);n(u,a)}}return n(t,gn.default),r.reduce((o,a)=>o.concat(a))}function pa(t,e){if(e&1)return 2;let i=e>>1,r=t.status[i];if(r==4)throw new Error("Cyclic dependency between fields and/or facets");if(r&2)return r;t.status[i]=4;let s=t.computeSlot(t,t.config.dynamicSlots[i]);return t.status[i]=2|s}function Ou(t,e){return e&1?t.config.staticValues[e>>1]:t.values[e>>1]}const ub=we.define(),Ad=we.define({combine:t=>t.some(e=>e),static:!0}),cb=we.define({combine:t=>t.length?t[0]:void 0,static:!0}),hb=we.define(),db=we.define(),fb=we.define(),pb=we.define({combine:t=>t.length?t[0]:!1});class No{constructor(e,i){this.type=e,this.value=i}static define(){return new _A}}class _A{of(e){return new No(this,e)}}class yA{constructor(e){this.map=e}of(e){return new at(this,e)}}class at{constructor(e,i){this.type=e,this.value=i}map(e){let i=this.type.map(this.value,e);return i===void 0?void 0:i==this.value?this:new at(this.type,i)}is(e){return this.type==e}static define(e={}){return new yA(e.map||(i=>i))}static mapEffects(e,i){if(!e.length)return e;let r=[];for(let s of e){let n=s.map(i);n&&r.push(n)}return r}}at.reconfigure=at.define();at.appendConfig=at.define();class ui{constructor(e,i,r,s,n,o){this.startState=e,this.changes=i,this.selection=r,this.effects=s,this.annotations=n,this.scrollIntoView=o,this._doc=null,this._state=null,r&&ab(r,i.newLength),n.some(a=>a.type==ui.time)||(this.annotations=n.concat(ui.time.of(Date.now())))}static create(e,i,r,s,n,o){return new ui(e,i,r,s,n,o)}get newDoc(){return this._doc||(this._doc=this.changes.apply(this.startState.doc))}get newSelection(){return this.selection||this.startState.selection.map(this.changes)}get state(){return this._state||this.startState.applyTransaction(this),this._state}annotation(e){for(let i of this.annotations)if(i.type==e)return i.value}get docChanged(){return!this.changes.empty}get reconfigured(){return this.startState.config!=this.state.config}isUserEvent(e){let i=this.annotation(ui.userEvent);return!!(i&&(i==e||i.length>e.length&&i.slice(0,e.length)==e&&i[e.length]=="."))}}ui.time=No.define();ui.userEvent=No.define();ui.addToHistory=No.define();ui.remote=No.define();function wA(t,e){let i=[];for(let r=0,s=0;;){let n,o;if(r<t.length&&(s==e.length||e[s]>=t[r]))n=t[r++],o=t[r++];else if(s<e.length)n=e[s++],o=e[s++];else return i;!i.length||i[i.length-1]<n?i.push(n,o):i[i.length-1]<o&&(i[i.length-1]=o)}}function mb(t,e,i){var r;let s,n,o;return i?(s=e.changes,n=Mt.empty(e.changes.length),o=t.changes.compose(e.changes)):(s=e.changes.map(t.changes),n=t.changes.mapDesc(e.changes,!0),o=t.changes.compose(s)),{changes:o,selection:e.selection?e.selection.map(n):(r=t.selection)===null||r===void 0?void 0:r.map(s),effects:at.mapEffects(t.effects,s).concat(at.mapEffects(e.effects,n)),annotations:t.annotations.length?t.annotations.concat(e.annotations):e.annotations,scrollIntoView:t.scrollIntoView||e.scrollIntoView}}function Ed(t,e,i){let r=e.selection,s=no(e.annotations);return e.userEvent&&(s=s.concat(ui.userEvent.of(e.userEvent))),{changes:e.changes instanceof Mt?e.changes:Mt.of(e.changes||[],i,t.facet(cb)),selection:r&&(r instanceof ve?r:ve.single(r.anchor,r.head)),effects:no(e.effects),annotations:s,scrollIntoView:!!e.scrollIntoView}}function gb(t,e,i){let r=Ed(t,e.length?e[0]:{},t.doc.length);e.length&&e[0].filter===!1&&(i=!1);for(let n=1;n<e.length;n++){e[n].filter===!1&&(i=!1);let o=!!e[n].sequential;r=mb(r,Ed(t,e[n],o?r.changes.newLength:t.doc.length),o)}let s=ui.create(t,r.changes,r.selection,r.effects,r.annotations,r.scrollIntoView);return SA(i?xA(s):s)}function xA(t){let e=t.startState,i=!0;for(let s of e.facet(hb)){let n=s(t);if(n===!1){i=!1;break}Array.isArray(n)&&(i=i===!0?n:wA(i,n))}if(i!==!0){let s,n;if(i===!1)n=t.changes.invertedDesc,s=Mt.empty(e.doc.length);else{let o=t.changes.filter(i);s=o.changes,n=o.filtered.mapDesc(o.changes).invertedDesc}t=ui.create(e,s,t.selection&&t.selection.map(n),at.mapEffects(t.effects,n),t.annotations,t.scrollIntoView)}let r=e.facet(db);for(let s=r.length-1;s>=0;s--){let n=r[s](t);n instanceof ui?t=n:Array.isArray(n)&&n.length==1&&n[0]instanceof ui?t=n[0]:t=gb(e,no(n),!1)}return t}function SA(t){let e=t.startState,i=e.facet(fb),r=t;for(let s=i.length-1;s>=0;s--){let n=i[s](t);n&&Object.keys(n).length&&(r=mb(r,Ed(e,n,t.changes.newLength),!0))}return r==t?t:ui.create(e,t.changes,t.selection,r.effects,r.annotations,r.scrollIntoView)}const kA=[];function no(t){return t==null?kA:Array.isArray(t)?t:[t]}var rs=function(t){return t[t.Word=0]="Word",t[t.Space=1]="Space",t[t.Other=2]="Other",t}(rs||(rs={}));const CA=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;let Dd;try{Dd=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch{}function AA(t){if(Dd)return Dd.test(t);for(let e=0;e<t.length;e++){let i=t[e];if(/\w/.test(i)||i>""&&(i.toUpperCase()!=i.toLowerCase()||CA.test(i)))return!0}return!1}function EA(t){return e=>{if(!/\S/.test(e))return rs.Space;if(AA(e))return rs.Word;for(let i=0;i<t.length;i++)if(e.indexOf(t[i])>-1)return rs.Word;return rs.Other}}class Ke{constructor(e,i,r,s,n,o){this.config=e,this.doc=i,this.selection=r,this.values=s,this.status=e.statusTemplate.slice(),this.computeSlot=n,o&&(o._state=this);for(let a=0;a<this.config.dynamicSlots.length;a++)pa(this,a<<1);this.computeSlot=null}field(e,i=!0){let r=this.config.address[e.id];if(r==null){if(i)throw new RangeError("Field is not present in this state");return}return pa(this,r),Ou(this,r)}update(...e){return gb(this,e,!0)}applyTransaction(e){let i=this.config,{base:r,compartments:s}=i;for(let a of e.effects)a.is(Ro.reconfigure)?(i&&(s=new Map,i.compartments.forEach((l,u)=>s.set(u,l)),i=null),s.set(a.value.compartment,a.value.extension)):a.is(at.reconfigure)?(i=null,r=a.value):a.is(at.appendConfig)&&(i=null,r=no(r).concat(a.value));let n;i?n=e.startState.values.slice():(i=Lu.resolve(r,s,this),n=new Ke(i,this.doc,this.selection,i.dynamicSlots.map(()=>null),(l,u)=>u.reconfigure(l,this),null).values);let o=e.startState.facet(Ad)?e.newSelection:e.newSelection.asSingle();new Ke(i,e.newDoc,o,n,(a,l)=>l.update(a,e),e)}replaceSelection(e){return typeof e=="string"&&(e=this.toText(e)),this.changeByRange(i=>({changes:{from:i.from,to:i.to,insert:e},range:ve.cursor(i.from+e.length)}))}changeByRange(e){let i=this.selection,r=e(i.ranges[0]),s=this.changes(r.changes),n=[r.range],o=no(r.effects);for(let a=1;a<i.ranges.length;a++){let l=e(i.ranges[a]),u=this.changes(l.changes),c=u.map(s);for(let d=0;d<a;d++)n[d]=n[d].map(c);let h=s.mapDesc(u,!0);n.push(l.range.map(h)),s=s.compose(c),o=at.mapEffects(o,c).concat(at.mapEffects(no(l.effects),h))}return{changes:s,selection:ve.create(n,i.mainIndex),effects:o}}changes(e=[]){return e instanceof Mt?e:Mt.of(e,this.doc.length,this.facet(Ke.lineSeparator))}toText(e){return Ve.of(e.split(this.facet(Ke.lineSeparator)||wd))}sliceDoc(e=0,i=this.doc.length){return this.doc.sliceString(e,i,this.lineBreak)}facet(e){let i=this.config.address[e.id];return i==null?e.default:(pa(this,i),Ou(this,i))}toJSON(e){let i={doc:this.sliceDoc(),selection:this.selection.toJSON()};if(e)for(let r in e){let s=e[r];s instanceof or&&this.config.address[s.id]!=null&&(i[r]=s.spec.toJSON(this.field(e[r]),this))}return i}static fromJSON(e,i={},r){if(!e||typeof e.doc!="string")throw new RangeError("Invalid JSON representation for EditorState");let s=[];if(r){for(let n in r)if(Object.prototype.hasOwnProperty.call(e,n)){let o=r[n],a=e[n];s.push(o.init(l=>o.spec.fromJSON(a,l)))}}return Ke.create({doc:e.doc,selection:ve.fromJSON(e.selection),extensions:i.extensions?s.concat([i.extensions]):s})}static create(e={}){let i=Lu.resolve(e.extensions||[],new Map),r=e.doc instanceof Ve?e.doc:Ve.of((e.doc||"").split(i.staticFacet(Ke.lineSeparator)||wd)),s=e.selection?e.selection instanceof ve?e.selection:ve.single(e.selection.anchor,e.selection.head):ve.single(0);return ab(s,r.length),i.staticFacet(Ad)||(s=s.asSingle()),new Ke(i,r,s,i.dynamicSlots.map(()=>null),(n,o)=>o.create(n),null)}get tabSize(){return this.facet(Ke.tabSize)}get lineBreak(){return this.facet(Ke.lineSeparator)||`
|
|
@@ -324,7 +324,7 @@ l0,-`+(i+144)+`c-2,-159.3,-10,-310.7,-24,-454c-53.3,-528,-210,-949.7,
|
|
|
324
324
|
`&&t.lineWrapping&&(r&&(r=ve.single(r.main.anchor-1,r.main.head-1)),i={from:n.from,to:n.to,insert:Ve.of([" "])}),i)return v1(t,i,r,o);if(r&&!$u(r,n)){let a=!1,l="select";return t.inputState.lastSelectionTime>Date.now()-50&&(t.inputState.lastSelectionOrigin=="select"&&(a=!0),l=t.inputState.lastSelectionOrigin,l=="select.pointer"&&(r=Jb(s.facet(el).map(u=>u(t)),r))),t.dispatch({selection:r,scrollIntoView:a,userEvent:l}),!0}else return!1}function v1(t,e,i,r=-1){if(me.ios&&t.inputState.flushIOSKey(e))return!0;let s=t.state.selection.main;if(me.android&&(e.to==s.to&&(e.from==s.from||e.from==s.from-1&&t.state.sliceDoc(e.from,s.from)==" ")&&e.insert.length==1&&e.insert.lines==2&&ao(t.contentDOM,"Enter",13)||(e.from==s.from-1&&e.to==s.to&&e.insert.length==0||r==8&&e.insert.length<e.to-e.from&&e.to>s.head)&&ao(t.contentDOM,"Backspace",8)||e.from==s.from&&e.to==s.to+1&&e.insert.length==0&&ao(t.contentDOM,"Delete",46)))return!0;let n=e.insert.toString();t.inputState.composing>=0&&t.inputState.composing++;let o,a=()=>o||(o=NE(t,e,i));return t.state.facet(zb).some(l=>l(t,e.from,e.to,n,a))||t.dispatch(a()),!0}function NE(t,e,i){let r,s=t.state,n=s.selection.main,o=-1;if(e.from==e.to&&e.from<n.from||e.from>n.to){let l=e.from<n.from?-1:1,u=l<0?n.from:n.to,c=va(s.facet(el).map(h=>h(t)),u,l);e.from==c&&(o=c)}if(o>-1)r={changes:e,selection:ve.cursor(e.from+e.insert.length,-1)};else if(e.from>=n.from&&e.to<=n.to&&e.to-e.from>=(n.to-n.from)/3&&(!i||i.main.empty&&i.main.from==e.from+e.insert.length)&&t.inputState.composing<0){let l=n.from<e.from?s.sliceDoc(n.from,e.from):"",u=n.to>e.to?s.sliceDoc(e.to,n.to):"";r=s.replaceSelection(t.state.toText(l+e.insert.sliceString(0,void 0,t.state.lineBreak)+u))}else{let l=s.changes(e),u=i&&i.main.to<=l.newLength?i.main:void 0;if(s.selection.ranges.length>1&&(t.inputState.composing>=0||t.inputState.compositionPendingChange)&&e.to<=n.to+10&&e.to>=n.to-10){let c=t.state.sliceDoc(e.from,e.to),h,d=i&&Xb(t,i.main.head);if(d){let m=e.insert.length-(e.to-e.from);h={from:d.from,to:d.to-m}}else h=t.state.doc.lineAt(n.head);let f=n.to-e.to;r=s.changeByRange(m=>{if(m.from==n.from&&m.to==n.to)return{changes:l,range:u||m.map(l)};let v=m.to-f,_=v-c.length;if(t.state.sliceDoc(_,v)!=c||v>=h.from&&_<=h.to)return{range:m};let w=s.changes({from:_,to:v,insert:e.insert}),x=m.to-n.to;return{changes:w,range:u?ve.range(Math.max(0,u.anchor+x),Math.max(0,u.head+x)):m.map(w)}})}else r={changes:l,selection:u&&s.selection.replaceRange(u)}}let a="input.type";return(t.composing||t.inputState.compositionPendingChange&&t.inputState.compositionEndedAt>Date.now()-50)&&(t.inputState.compositionPendingChange=!1,a+=".compose",t.inputState.compositionFirstChange&&(a+=".start",t.inputState.compositionFirstChange=!1)),s.update(r,{userEvent:a,scrollIntoView:!0})}function e6(t,e,i,r){let s=Math.min(t.length,e.length),n=0;for(;n<s&&t.charCodeAt(n)==e.charCodeAt(n);)n++;if(n==s&&t.length==e.length)return null;let o=t.length,a=e.length;for(;o>0&&a>0&&t.charCodeAt(o-1)==e.charCodeAt(a-1);)o--,a--;if(r=="end"){let l=Math.max(0,n-Math.min(o,a));i-=o+l-n}if(o<n&&t.length<e.length){let l=i<=n&&i>=o?n-i:0;n-=l,a=n+(a-o),o=n}else if(a<n){let l=i<=n&&i>=a?n-i:0;n-=l,o=n+(o-a),a=n}return{from:n,toA:o,toB:a}}function LE(t){let e=[];if(t.root.activeElement!=t.contentDOM)return e;let{anchorNode:i,anchorOffset:r,focusNode:s,focusOffset:n}=t.observer.selectionRange;return i&&(e.push(new Yg(i,r)),(s!=i||n!=r)&&e.push(new Yg(s,n))),e}function OE(t,e){if(t.length==0)return null;let i=t[0].pos,r=t.length==2?t[1].pos:i;return i>-1&&r>-1?ve.single(i+e,r+e):null}function $u(t,e){return e.head==t.main.head&&e.anchor==t.main.anchor}class PE{setSelectionOrigin(e){this.lastSelectionOrigin=e,this.lastSelectionTime=Date.now()}constructor(e){this.view=e,this.lastKeyCode=0,this.lastKeyTime=0,this.touchActive=!1,this.lastTouchTime=0,this.lastTouchX=0,this.lastTouchY=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.lastWheelEvent=0,this.pendingIOSKey=void 0,this.lastIOSMomentumScroll=0,this.tabFocusMode=-1,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastContextMenu=0,this.scrollHandlers=[],this.handlers=Object.create(null),this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.compositionPendingKey=!1,this.compositionPendingChange=!1,this.insertingText="",this.insertingTextAt=0,this.mouseSelection=null,this.draggedContent=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=e.hasFocus,me.safari&&e.contentDOM.addEventListener("input",()=>null),me.gecko&&ZE(e.contentDOM.ownerDocument)}handleEvent(e){!KE(this.view,e)||this.ignoreDuringComposition(e)||e.type=="keydown"&&this.keydown(e)||(this.view.updateState!=0?Promise.resolve().then(()=>this.runHandlers(e.type,e)):this.runHandlers(e.type,e))}runHandlers(e,i){let r=this.handlers[e];if(r){for(let s of r.observers)s(this.view,i);for(let s of r.handlers){if(i.defaultPrevented)break;if(s(this.view,i)){i.preventDefault();break}}}}ensureHandlers(e){let i=IE(e),r=this.handlers,s=this.view.contentDOM;for(let n in i)if(n!="scroll"){let o=!i[n].handlers.length,a=r[n];a&&o!=!a.handlers.length&&(s.removeEventListener(n,this.handleEvent),a=null),a||s.addEventListener(n,this.handleEvent,{passive:o})}for(let n in r)n!="scroll"&&!i[n]&&s.removeEventListener(n,this.handleEvent);this.handlers=i}keydown(e){if(this.lastKeyCode=e.keyCode,this.lastKeyTime=Date.now(),e.keyCode==9&&this.tabFocusMode>-1&&(!this.tabFocusMode||Date.now()<=this.tabFocusMode))return!0;if(this.tabFocusMode>0&&e.keyCode!=27&&i6.indexOf(e.keyCode)<0&&(this.tabFocusMode=-1),me.android&&me.chrome&&!e.synthetic&&(e.keyCode==13||e.keyCode==8))return this.view.observer.delayAndroidKey(e.key,e.keyCode),!0;if(me.ios&&!e.synthetic&&!e.altKey&&!e.metaKey&&(t6.some(i=>i.keyCode==e.keyCode)&&!e.ctrlKey||zE.indexOf(e.key)>-1&&e.ctrlKey)){let i={ctrlKey:e.ctrlKey,altKey:e.altKey,metaKey:e.metaKey,shiftKey:e.shiftKey};return i.shiftKey&&me.ios&&!/^(off|none)$/.test(this.view.contentDOM.autocapitalize)&&FE(this.view.win)&&(i.shiftKey=!1),this.pendingIOSKey={key:e.key,keyCode:e.keyCode,mods:i},setTimeout(()=>this.flushIOSKey(),250),!0}return e.keyCode!=229&&this.view.observer.forceFlush(),!1}flushIOSKey(e){let i=this.pendingIOSKey;return!i||i.key=="Enter"&&e&&e.from<e.to&&/^\S+$/.test(e.insert.toString())?!1:(this.pendingIOSKey=void 0,ao(this.view.contentDOM,i.key,i.keyCode,i.mods))}ignoreDuringComposition(e){return!/^key/.test(e.type)||e.synthetic?!1:this.composing>0?!0:me.safari&&!me.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100?(this.compositionPendingKey=!1,!0):!1}startMouseSelection(e){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=e}update(e){this.view.observer.update(e),this.mouseSelection&&this.mouseSelection.update(e),this.draggedContent&&e.docChanged&&(this.draggedContent=this.draggedContent.map(e.changes)),e.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}}function FE(t){return t.visualViewport?t.visualViewport.height*t.visualViewport.scale/t.document.documentElement.clientHeight<.85:!1}function Xg(t,e){return(i,r)=>{try{return e.call(t,r,i)}catch(s){Ir(i.state,s)}}}function IE(t){let e=Object.create(null);function i(r){return e[r]||(e[r]={observers:[],handlers:[]})}for(let r of t){let s=r.spec,n=s&&s.plugin.domEventHandlers,o=s&&s.plugin.domEventObservers;if(n)for(let a in n){let l=n[a];l&&i(a).handlers.push(Xg(r.value,l))}if(o)for(let a in o){let l=o[a];l&&i(a).observers.push(Xg(r.value,l))}}for(let r in pr)i(r).handlers.push(pr[r]);for(let r in _i)i(r).observers.push(_i[r]);return e}const t6=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],zE="dthko",i6=[16,17,18,20,91,92,224,225],Pl=6;function Fl(t){return Math.max(0,t)*.7+8}function jE(t,e){return Math.max(Math.abs(t.clientX-e.clientX),Math.abs(t.clientY-e.clientY))}class HE{constructor(e,i,r,s){this.view=e,this.startEvent=i,this.style=r,this.mustSelect=s,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=i,this.scrollParents=Sb(e.contentDOM),this.atoms=e.state.facet(el).map(o=>o(e));let n=e.contentDOM.ownerDocument;n.addEventListener("mousemove",this.move=this.move.bind(this)),n.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=i.shiftKey,this.multiple=e.state.facet(Ke.allowMultipleSelections)&&$E(e,i),this.dragging=WE(e,i)&&n6(i)==1?null:!1}start(e){this.dragging===!1&&this.select(e)}move(e){if(e.buttons==0)return this.destroy();if(this.dragging||this.dragging==null&&jE(this.startEvent,e)<10)return;this.select(this.lastEvent=e);let i=0,r=0,s=0,n=0,o=this.view.win.innerWidth,a=this.view.win.innerHeight;this.scrollParents.x&&({left:s,right:o}=this.scrollParents.x.getBoundingClientRect()),this.scrollParents.y&&({top:n,bottom:a}=this.scrollParents.y.getBoundingClientRect());let l=Gb(this.view);e.clientX-l.left<=s+Pl?i=-Fl(s-e.clientX):e.clientX+l.right>=o-Pl&&(i=Fl(e.clientX-o)),e.clientY-l.top<=n+Pl?r=-Fl(n-e.clientY):e.clientY+l.bottom>=a-Pl&&(r=Fl(e.clientY-a)),this.setScrollSpeed(i,r)}up(e){this.dragging==null&&this.select(this.lastEvent),this.dragging||e.preventDefault(),this.destroy()}destroy(){this.setScrollSpeed(0,0);let e=this.view.contentDOM.ownerDocument;e.removeEventListener("mousemove",this.move),e.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=this.view.inputState.draggedContent=null}setScrollSpeed(e,i){this.scrollSpeed={x:e,y:i},e||i?this.scrolling<0&&(this.scrolling=setInterval(()=>this.scroll(),50)):this.scrolling>-1&&(clearInterval(this.scrolling),this.scrolling=-1)}scroll(){let{x:e,y:i}=this.scrollSpeed;e&&this.scrollParents.x&&(this.scrollParents.x.scrollLeft+=e,e=0),i&&this.scrollParents.y&&(this.scrollParents.y.scrollTop+=i,i=0),(e||i)&&this.view.win.scrollBy(e,i),this.dragging===!1&&this.select(this.lastEvent)}select(e){let{view:i}=this,r=Jb(this.atoms,this.style.get(e,this.extend,this.multiple));(this.mustSelect||!r.eq(i.state.selection,this.dragging===!1))&&this.view.dispatch({selection:r,userEvent:"select.pointer"}),this.mustSelect=!1}update(e){e.transactions.some(i=>i.isUserEvent("input.type"))?this.destroy():this.style.update(e)&&setTimeout(()=>this.select(this.lastEvent),20)}}function $E(t,e){let i=t.state.facet(Ob);return i.length?i[0](e):me.mac?e.metaKey:e.ctrlKey}function qE(t,e){let i=t.state.facet(Pb);return i.length?i[0](e):me.mac?!e.altKey:!e.ctrlKey}function WE(t,e){let{main:i}=t.state.selection;if(i.empty)return!1;let r=Ia(t.root);if(!r||r.rangeCount==0)return!0;let s=r.getRangeAt(0).getClientRects();for(let n=0;n<s.length;n++){let o=s[n];if(o.left<=e.clientX&&o.right>=e.clientX&&o.top<=e.clientY&&o.bottom>=e.clientY)return!0}return!1}function KE(t,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let i=e.target,r;i!=t.contentDOM;i=i.parentNode)if(!i||i.nodeType==11||(r=yt.get(i))&&r.isWidget()&&!r.isHidden&&r.widget.ignoreEvent(e))return!1;return!0}const pr=Object.create(null),_i=Object.create(null),r6=me.ie&&me.ie_version<15||me.ios&&me.webkit_version<604;function VE(t){let e=t.dom.parentNode;if(!e)return;let i=e.appendChild(document.createElement("textarea"));i.style.cssText="position: fixed; left: -10000px; top: 10px",i.focus(),setTimeout(()=>{t.focus(),i.remove(),s6(t,i.value)},50)}function E0(t,e,i){for(let r of t.facet(e))i=r(i,t);return i}function s6(t,e){e=E0(t.state,f1,e);let{state:i}=t,r,s=1,n=i.toText(e),o=n.lines==i.selection.ranges.length;if(Kd!=null&&i.selection.ranges.every(l=>l.empty)&&Kd==n.toString()){let l=-1;r=i.changeByRange(u=>{let c=i.doc.lineAt(u.from);if(c.from==l)return{range:u};l=c.from;let h=i.toText((o?n.line(s++).text:e)+i.lineBreak);return{changes:{from:c.from,insert:h},range:ve.cursor(u.from+h.length)}})}else o?r=i.changeByRange(l=>{let u=n.line(s++);return{changes:{from:l.from,to:l.to,insert:u.text},range:ve.cursor(l.from+u.length)}}):r=i.replaceSelection(n);t.dispatch(r,{userEvent:"input.paste",scrollIntoView:!0})}_i.scroll=t=>{let e=t.inputState;e.lastScrollTop=t.scrollDOM.scrollTop,e.lastScrollLeft=t.scrollDOM.scrollLeft,me.ios&&!e.touchActive&&(e.lastIOSMomentumScroll=Date.now())};_i.wheel=_i.mousewheel=t=>{t.inputState.lastWheelEvent=Date.now()};pr.keydown=(t,e)=>(t.inputState.setSelectionOrigin("select"),e.keyCode==27&&t.inputState.tabFocusMode!=0&&(t.inputState.tabFocusMode=Date.now()+2e3),!1);_i.touchstart=(t,e)=>{let i=t.inputState,r=e.targetTouches[0];i.touchActive=!0,i.lastTouchTime=Date.now(),r&&(i.lastTouchX=r.clientX,i.lastTouchY=r.clientY),i.setSelectionOrigin("select.pointer")};_i.touchmove=t=>{t.inputState.setSelectionOrigin("select.pointer")};_i.touchend=(t,e)=>{t.inputState.touchActive=!1};pr.mousedown=(t,e)=>{if(t.observer.flush(),t.inputState.lastTouchTime>Date.now()-2e3)return!1;let i=null;for(let r of t.state.facet(Fb))if(i=r(t,e),i)break;if(!i&&e.button==0&&(i=GE(t,e)),i){let r=!t.hasFocus;t.inputState.startMouseSelection(new HE(t,e,i,r)),r&&t.observer.ignore(()=>{Ab(t.contentDOM);let n=t.root.activeElement;n&&!n.contains(t.contentDOM)&&n.blur()});let s=t.inputState.mouseSelection;if(s)return s.start(e),s.dragging===!1}else t.inputState.setSelectionOrigin("select.pointer");return!1};function Jg(t,e,i,r){if(r==1)return ve.cursor(e,i);if(r==2)return xE(t.state,e,i);{let s=t.docView.lineAt(e,i),n=t.state.doc.lineAt(s?s.posAtEnd:e),o=s?s.posAtStart:n.from,a=s?s.posAtEnd:n.to;return a<t.state.doc.length&&a==n.to&&a++,ve.undirectionalRange(o,a)}}const UE=me.ie&&me.ie_version<=11;let Zg=null,Qg=0,e2=0;function n6(t){if(!UE)return t.detail;let e=Zg,i=e2;return Zg=t,e2=Date.now(),Qg=!e||i>Date.now()-400&&Math.abs(e.clientX-t.clientX)<2&&Math.abs(e.clientY-t.clientY)<2?(Qg+1)%3:1}function GE(t,e){let i=t.posAndSideAtCoords({x:e.clientX,y:e.clientY},!1),r=n6(e),s=t.state.selection;return{update(n){n.docChanged&&(i.pos=n.changes.mapPos(i.pos),s=s.map(n.changes))},get(n,o,a){let l=t.posAndSideAtCoords({x:n.clientX,y:n.clientY},!1),u,c=Jg(t,l.pos,l.assoc,r);if(i.pos!=l.pos&&!o){let h=Jg(t,i.pos,i.assoc,r),d=Math.min(h.from,c.from),f=Math.max(h.to,c.to);c=d<c.from?ve.range(d,f,c.assoc):ve.range(f,d,c.assoc)}return o?s.replaceRange(s.main.extend(c.from,c.to,c.assoc)):a&&r==1&&s.ranges.length>1&&(u=YE(s,l.pos))?u:a?s.addRange(c):ve.create([c])}}}function YE(t,e){for(let i=0;i<t.ranges.length;i++){let{from:r,to:s}=t.ranges[i];if(r<=e&&s>=e)return ve.create(t.ranges.slice(0,i).concat(t.ranges.slice(i+1)),t.mainIndex==i?0:t.mainIndex-(t.mainIndex>i?1:0))}return null}pr.dragstart=(t,e)=>{let{selection:{main:i}}=t.state;if(e.target.draggable){let s=t.docView.tile.nearest(e.target);if(s&&s.isWidget()){let n=s.posAtStart,o=n+s.length;(n>=i.to||o<=i.from)&&(i=ve.undirectionalRange(n,o))}}let{inputState:r}=t;return r.mouseSelection&&(r.mouseSelection.dragging=!0),r.draggedContent=i,e.dataTransfer&&(e.dataTransfer.setData("Text",E0(t.state,p1,t.state.sliceDoc(i.from,i.to))),e.dataTransfer.effectAllowed="copyMove"),!1};pr.dragend=t=>(t.inputState.draggedContent=null,!1);function t2(t,e,i,r){if(i=E0(t.state,f1,i),!i)return;let s=t.posAtCoords({x:e.clientX,y:e.clientY},!1),{draggedContent:n}=t.inputState,o=r&&n&&qE(t,e)?{from:n.from,to:n.to}:null,a={from:s,insert:i},l=t.state.changes(o?[o,a]:a);t.focus(),t.dispatch({changes:l,selection:{anchor:l.mapPos(s,-1),head:l.mapPos(s,1)},userEvent:o?"move.drop":"input.drop"}),t.inputState.draggedContent=null}pr.drop=(t,e)=>{if(!e.dataTransfer)return!1;if(t.state.readOnly)return!0;let i=e.dataTransfer.files;if(i&&i.length){let r=Array(i.length),s=0,n=()=>{++s==i.length&&t2(t,e,r.filter(o=>o!=null).join(t.state.lineBreak),!1)};for(let o=0;o<i.length;o++){let a=new FileReader;a.onerror=n,a.onload=()=>{/[\x00-\x08\x0e-\x1f]{2}/.test(a.result)||(r[o]=a.result),n()},a.readAsText(i[o])}return!0}else{let r=e.dataTransfer.getData("Text");if(r)return t2(t,e,r,!0),!0}return!1};pr.paste=(t,e)=>{if(t.state.readOnly)return!0;t.observer.flush();let i=r6?null:e.clipboardData;return i?(s6(t,i.getData("text/plain")||i.getData("text/uri-list")),!0):(VE(t),!1)};function XE(t,e){let i=t.dom.parentNode;if(!i)return;let r=i.appendChild(document.createElement("textarea"));r.style.cssText="position: fixed; left: -10000px; top: 10px",r.value=e,r.focus(),r.selectionEnd=e.length,r.selectionStart=0,setTimeout(()=>{r.remove(),t.focus()},50)}function JE(t){let e=[],i=[],r=!1;for(let s of t.selection.ranges)s.empty||(e.push(t.sliceDoc(s.from,s.to)),i.push(s));if(!e.length){let s=-1;for(let{from:n}of t.selection.ranges){let o=t.doc.lineAt(n);o.number>s&&(e.push(o.text),i.push({from:o.from,to:Math.min(t.doc.length,o.to+1)})),s=o.number}r=!0}return{text:E0(t,p1,e.join(t.lineBreak)),ranges:i,linewise:r}}let Kd=null;pr.copy=pr.cut=(t,e)=>{if(!ma(t.contentDOM,t.observer.selectionRange))return!1;let{text:i,ranges:r,linewise:s}=JE(t.state);if(!i&&!s)return!1;Kd=s?i:null,e.type=="cut"&&!t.state.readOnly&&t.dispatch({changes:r,scrollIntoView:!0,userEvent:"delete.cut"});let n=r6?null:e.clipboardData;return n?(n.clearData(),n.setData("text/plain",i),!0):(XE(t,i),!1)};const o6=No.define();function a6(t,e){let i=[];for(let r of t.facet(jb)){let s=r(t,e);s&&i.push(s)}return i.length?t.update({effects:i,annotations:o6.of(!0)}):null}function l6(t){setTimeout(()=>{let e=t.hasFocus;if(e!=t.inputState.notifiedFocused){let i=a6(t.state,e);i?t.dispatch(i):t.update([])}},10)}_i.focus=t=>{t.inputState.lastFocusTime=Date.now(),!t.scrollDOM.scrollTop&&(t.inputState.lastScrollTop||t.inputState.lastScrollLeft)&&(t.scrollDOM.scrollTop=t.inputState.lastScrollTop,t.scrollDOM.scrollLeft=t.inputState.lastScrollLeft),l6(t)};_i.blur=t=>{t.observer.clearSelectionRange(),l6(t)};_i.compositionstart=_i.compositionupdate=t=>{t.observer.editContext||(t.inputState.compositionFirstChange==null&&(t.inputState.compositionFirstChange=!0),t.inputState.composing<0&&(t.inputState.composing=0))};_i.compositionend=t=>{t.observer.editContext||(t.inputState.composing=-1,t.inputState.compositionEndedAt=Date.now(),t.inputState.compositionPendingKey=!0,t.inputState.compositionPendingChange=t.observer.pendingRecords().length>0,t.inputState.compositionFirstChange=null,me.chrome&&me.android?t.observer.flushSoon():t.inputState.compositionPendingChange?Promise.resolve().then(()=>t.observer.flush()):setTimeout(()=>{t.inputState.composing<0&&t.docView.hasComposition&&t.update([])},50))};_i.contextmenu=t=>{t.inputState.lastContextMenu=Date.now()};pr.beforeinput=(t,e)=>{var i,r;if((e.inputType=="insertText"||e.inputType=="insertCompositionText")&&(t.inputState.insertingText=e.data,t.inputState.insertingTextAt=Date.now()),e.inputType=="insertReplacementText"&&t.observer.editContext){let n=(i=e.dataTransfer)===null||i===void 0?void 0:i.getData("text/plain"),o=e.getTargetRanges();if(n&&o.length){let a=o[0],l=t.posAtDOM(a.startContainer,a.startOffset),u=t.posAtDOM(a.endContainer,a.endOffset);return v1(t,{from:l,to:u,insert:t.state.toText(n)},null),!0}}let s;if(me.chrome&&me.android&&(s=t6.find(n=>n.inputType==e.inputType))&&(t.observer.delayAndroidKey(s.key,s.keyCode),s.key=="Backspace"||s.key=="Delete")){let n=((r=window.visualViewport)===null||r===void 0?void 0:r.height)||0;setTimeout(()=>{var o;(((o=window.visualViewport)===null||o===void 0?void 0:o.height)||0)>n+10&&t.hasFocus&&(t.contentDOM.blur(),t.focus())},100)}return me.ios&&e.inputType=="deleteContentForward"&&t.observer.flushSoon(),me.safari&&e.inputType=="insertText"&&t.inputState.composing>=0&&setTimeout(()=>_i.compositionend(t,e),20),!1};const i2=new Set;function ZE(t){i2.has(t)||(i2.add(t),t.addEventListener("copy",()=>{}),t.addEventListener("cut",()=>{}))}const r2=["pre-wrap","normal","pre-line","break-spaces"];let xo=!1;function s2(){xo=!1}class QE{constructor(e){this.lineWrapping=e,this.doc=Ve.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30}heightForGap(e,i){let r=this.doc.lineAt(i).number-this.doc.lineAt(e).number+1;return this.lineWrapping&&(r+=Math.max(0,Math.ceil((i-e-r*this.lineLength*.5)/this.lineLength))),this.lineHeight*r}heightForLine(e){return this.lineWrapping?(1+Math.max(0,Math.ceil((e-this.lineLength)/Math.max(1,this.lineLength-5))))*this.lineHeight:this.lineHeight}setDoc(e){return this.doc=e,this}mustRefreshForWrapping(e){return r2.indexOf(e)>-1!=this.lineWrapping}mustRefreshForHeights(e){let i=!1;for(let r=0;r<e.length;r++){let s=e[r];s<0?r++:this.heightSamples[Math.floor(s*10)]||(i=!0,this.heightSamples[Math.floor(s*10)]=!0)}return i}refresh(e,i,r,s,n,o){let a=r2.indexOf(e)>-1,l=Math.abs(i-this.lineHeight)>.3||this.lineWrapping!=a;if(this.lineWrapping=a,this.lineHeight=i,this.charWidth=r,this.textHeight=s,this.lineLength=n,l){this.heightSamples={};for(let u=0;u<o.length;u++){let c=o[u];c<0?u++:this.heightSamples[Math.floor(c*10)]=!0}}return l}}class eD{constructor(e,i){this.from=e,this.heights=i,this.index=0}get more(){return this.index<this.heights.length}}class ur{constructor(e,i,r,s,n){this.from=e,this.length=i,this.top=r,this.height=s,this._content=n}get type(){return typeof this._content=="number"?Ti.Text:Array.isArray(this._content)?this._content:this._content.type}get to(){return this.from+this.length}get bottom(){return this.top+this.height}get widget(){return this._content instanceof Mn?this._content.widget:null}get widgetLineBreaks(){return typeof this._content=="number"?this._content:0}join(e){let i=(Array.isArray(this._content)?this._content:[this]).concat(Array.isArray(e._content)?e._content:[e]);return new ur(this.from,this.length+e.length,this.top,this.height+e.height,i)}}var rt=function(t){return t[t.ByPos=0]="ByPos",t[t.ByHeight=1]="ByHeight",t[t.ByPosNoHeight=2]="ByPosNoHeight",t}(rt||(rt={}));const vu=.001;class bi{constructor(e,i,r=2){this.length=e,this.height=i,this.flags=r}get outdated(){return(this.flags&2)>0}set outdated(e){this.flags=(e?2:0)|this.flags&-3}setHeight(e){this.height!=e&&(Math.abs(this.height-e)>vu&&(xo=!0),this.height=e)}replace(e,i,r){return bi.of(r)}decomposeLeft(e,i){i.push(this)}decomposeRight(e,i){i.push(this)}applyChanges(e,i,r,s){let n=this,o=r.doc;for(let a=s.length-1;a>=0;a--){let{fromA:l,toA:u,fromB:c,toB:h}=s[a],d=n.lineAt(l,rt.ByPosNoHeight,r.setDoc(i),0,0),f=d.to>=u?d:n.lineAt(u,rt.ByPosNoHeight,r,0,0);for(h+=f.to-u,u=f.to;a>0&&d.from<=s[a-1].toA;)l=s[a-1].fromA,c=s[a-1].fromB,a--,l<d.from&&(d=n.lineAt(l,rt.ByPosNoHeight,r,0,0));c+=d.from-l,l=d.from;let m=b1.build(r.setDoc(o),e,c,h);n=qu(n,n.replace(l,u,m))}return n.updateHeight(r,0)}static empty(){return new zi(0,0,0)}static of(e){if(e.length==1)return e[0];let i=0,r=e.length,s=0,n=0;for(;;)if(i==r)if(s>n*2){let a=e[i-1];a.break?e.splice(--i,1,a.left,null,a.right):e.splice(--i,1,a.left,a.right),r+=1+a.break,s-=a.size}else if(n>s*2){let a=e[r];a.break?e.splice(r,1,a.left,null,a.right):e.splice(r,1,a.left,a.right),r+=2+a.break,n-=a.size}else break;else if(s<n){let a=e[i++];a&&(s+=a.size)}else{let a=e[--r];a&&(n+=a.size)}let o=0;return e[i-1]==null?(o=1,i--):e[i]==null&&(o=1,r++),new iD(bi.of(e.slice(0,i)),o,bi.of(e.slice(r)))}}function qu(t,e){return t==e?t:(t.constructor!=e.constructor&&(xo=!0),e)}bi.prototype.size=1;const tD=qe.replace({});class u6 extends bi{constructor(e,i,r){super(e,i),this.deco=r,this.spaceAbove=0}mainBlock(e,i){return new ur(i,this.length,e+this.spaceAbove,this.height-this.spaceAbove,this.deco||0)}blockAt(e,i,r,s){return this.spaceAbove&&e<r+this.spaceAbove?new ur(s,0,r,this.spaceAbove,tD):this.mainBlock(r,s)}lineAt(e,i,r,s,n){let o=this.mainBlock(s,n);return this.spaceAbove?this.blockAt(0,r,s,n).join(o):o}forEachLine(e,i,r,s,n,o){e<=n+this.length&&i>=n&&o(this.lineAt(0,rt.ByPos,r,s,n))}setMeasuredHeight(e){let i=e.heights[e.index++];i<0?(this.spaceAbove=-i,i=e.heights[e.index++]):this.spaceAbove=0,this.setHeight(i)}updateHeight(e,i=0,r=!1,s){return s&&s.from<=i&&s.more&&this.setMeasuredHeight(s),this.outdated=!1,this}toString(){return`block(${this.length})`}}class zi extends u6{constructor(e,i,r){super(e,i,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0,this.spaceAbove=r}mainBlock(e,i){return new ur(i,this.length,e+this.spaceAbove,this.height-this.spaceAbove,this.breaks)}replace(e,i,r){let s=r[0];return r.length==1&&(s instanceof zi||s instanceof ti&&s.flags&4)&&Math.abs(this.length-s.length)<10?(s instanceof ti?s=new zi(s.length,this.height,this.spaceAbove):s.height=this.height,this.outdated||(s.outdated=!1),s):bi.of(r)}updateHeight(e,i=0,r=!1,s){return s&&s.from<=i&&s.more?this.setMeasuredHeight(s):(r||this.outdated)&&(this.spaceAbove=0,this.setHeight(Math.max(this.widgetHeight,e.heightForLine(this.length-this.collapsed))+this.breaks*e.lineHeight)),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}}class ti extends bi{constructor(e){super(e,0)}heightMetrics(e,i){let r=e.doc.lineAt(i).number,s=e.doc.lineAt(i+this.length).number,n=s-r+1,o,a=0;if(e.lineWrapping){let l=Math.min(this.height,e.lineHeight*n);o=l/n,this.length>n+1&&(a=(this.height-l)/(this.length-n-1))}else o=this.height/n;return{firstLine:r,lastLine:s,perLine:o,perChar:a}}blockAt(e,i,r,s){let{firstLine:n,lastLine:o,perLine:a,perChar:l}=this.heightMetrics(i,s);if(i.lineWrapping){let u=s+(e<i.lineHeight?0:Math.round(Math.max(0,Math.min(1,(e-r)/this.height))*this.length)),c=i.doc.lineAt(u),h=a+c.length*l,d=Math.max(r,e-h/2);return new ur(c.from,c.length,d,h,0)}else{let u=Math.max(0,Math.min(o-n,Math.floor((e-r)/a))),{from:c,length:h}=i.doc.line(n+u);return new ur(c,h,r+a*u,a,0)}}lineAt(e,i,r,s,n){if(i==rt.ByHeight)return this.blockAt(e,r,s,n);if(i==rt.ByPosNoHeight){let{from:f,to:m}=r.doc.lineAt(e);return new ur(f,m-f,0,0,0)}let{firstLine:o,perLine:a,perChar:l}=this.heightMetrics(r,n),u=r.doc.lineAt(e),c=a+u.length*l,h=u.number-o,d=s+a*h+l*(u.from-n-h);return new ur(u.from,u.length,Math.max(s,Math.min(d,s+this.height-c)),c,0)}forEachLine(e,i,r,s,n,o){e=Math.max(e,n),i=Math.min(i,n+this.length);let{firstLine:a,perLine:l,perChar:u}=this.heightMetrics(r,n);for(let c=e,h=s;c<=i;){let d=r.doc.lineAt(c);if(c==e){let m=d.number-a;h+=l*m+u*(e-n-m)}let f=l+u*d.length;o(new ur(d.from,d.length,h,f,0)),h+=f,c=d.to+1}}replace(e,i,r){let s=this.length-i;if(s>0){let n=r[r.length-1];n instanceof ti?r[r.length-1]=new ti(n.length+s):r.push(null,new ti(s-1))}if(e>0){let n=r[0];n instanceof ti?r[0]=new ti(e+n.length):r.unshift(new ti(e-1),null)}return bi.of(r)}decomposeLeft(e,i){i.push(new ti(e-1),null)}decomposeRight(e,i){i.push(null,new ti(this.length-e-1))}updateHeight(e,i=0,r=!1,s){let n=i+this.length;if(s&&s.from<=i+this.length&&s.more){let o=[],a=Math.max(i,s.from),l=-1;for(s.from>i&&o.push(new ti(s.from-i-1).updateHeight(e,i));a<=n&&s.more;){let c=e.doc.lineAt(a).length;o.length&&o.push(null);let h=s.heights[s.index++],d=0;h<0&&(d=-h,h=s.heights[s.index++]),l==-1?l=h:Math.abs(h-l)>=vu&&(l=-2);let f=new zi(c,h,d);f.outdated=!1,o.push(f),a+=c+1}a<=n&&o.push(null,new ti(n-a).updateHeight(e,a));let u=bi.of(o);return(l<0||Math.abs(u.height-this.height)>=vu||Math.abs(l-this.heightMetrics(e,i).perLine)>=vu)&&(xo=!0),qu(this,u)}else(r||this.outdated)&&(this.setHeight(e.heightForGap(i,i+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}}class iD extends bi{constructor(e,i,r){super(e.length+i+r.length,e.height+r.height,i|(e.outdated||r.outdated?2:0)),this.left=e,this.right=r,this.size=e.size+r.size}get break(){return this.flags&1}blockAt(e,i,r,s){let n=r+this.left.height;return e<n?this.left.blockAt(e,i,r,s):this.right.blockAt(e,i,n,s+this.left.length+this.break)}lineAt(e,i,r,s,n){let o=s+this.left.height,a=n+this.left.length+this.break,l=i==rt.ByHeight?e<o:e<a,u=l?this.left.lineAt(e,i,r,s,n):this.right.lineAt(e,i,r,o,a);if(this.break||(l?u.to<a:u.from>a))return u;let c=i==rt.ByPosNoHeight?rt.ByPosNoHeight:rt.ByPos;return l?u.join(this.right.lineAt(a,c,r,o,a)):this.left.lineAt(a,c,r,s,n).join(u)}forEachLine(e,i,r,s,n,o){let a=s+this.left.height,l=n+this.left.length+this.break;if(this.break)e<l&&this.left.forEachLine(e,i,r,s,n,o),i>=l&&this.right.forEachLine(e,i,r,a,l,o);else{let u=this.lineAt(l,rt.ByPos,r,s,n);e<u.from&&this.left.forEachLine(e,u.from-1,r,s,n,o),u.to>=e&&u.from<=i&&o(u),i>u.to&&this.right.forEachLine(u.to+1,i,r,a,l,o)}}replace(e,i,r){let s=this.left.length+this.break;if(i<s)return this.balanced(this.left.replace(e,i,r),this.right);if(e>this.left.length)return this.balanced(this.left,this.right.replace(e-s,i-s,r));let n=[];e>0&&this.decomposeLeft(e,n);let o=n.length;for(let a of r)n.push(a);if(e>0&&n2(n,o-1),i<this.length){let a=n.length;this.decomposeRight(i,n),n2(n,a)}return bi.of(n)}decomposeLeft(e,i){let r=this.left.length;if(e<=r)return this.left.decomposeLeft(e,i);i.push(this.left),this.break&&(r++,e>=r&&i.push(null)),e>r&&this.right.decomposeLeft(e-r,i)}decomposeRight(e,i){let r=this.left.length,s=r+this.break;if(e>=s)return this.right.decomposeRight(e-s,i);e<r&&this.left.decomposeRight(e,i),this.break&&e<s&&i.push(null),i.push(this.right)}balanced(e,i){return e.size>2*i.size||i.size>2*e.size?bi.of(this.break?[e,null,i]:[e,i]):(this.left=qu(this.left,e),this.right=qu(this.right,i),this.setHeight(e.height+i.height),this.outdated=e.outdated||i.outdated,this.size=e.size+i.size,this.length=e.length+this.break+i.length,this)}updateHeight(e,i=0,r=!1,s){let{left:n,right:o}=this,a=i+n.length+this.break,l=null;return s&&s.from<=i+n.length&&s.more?l=n=n.updateHeight(e,i,r,s):n.updateHeight(e,i,r),s&&s.from<=a+o.length&&s.more?l=o=o.updateHeight(e,a,r,s):o.updateHeight(e,a,r),l?this.balanced(n,o):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}}function n2(t,e){let i,r;t[e]==null&&(i=t[e-1])instanceof ti&&(r=t[e+1])instanceof ti&&t.splice(e-1,3,new ti(i.length+1+r.length))}const rD=5;class b1{constructor(e,i){this.pos=e,this.oracle=i,this.nodes=[],this.lineStart=-1,this.lineEnd=-1,this.covering=null,this.writtenTo=e}get isCovered(){return this.covering&&this.nodes[this.nodes.length-1]==this.covering}span(e,i){if(this.lineStart>-1){let r=Math.min(i,this.lineEnd),s=this.nodes[this.nodes.length-1];s instanceof zi?s.length+=r-this.pos:(r>this.pos||!this.isCovered)&&this.nodes.push(new zi(r-this.pos,-1,0)),this.writtenTo=r,i>r&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=i}point(e,i,r){if(e<i||r.heightRelevant){let s=r.widget?r.widget.estimatedHeight:0,n=r.widget?r.widget.lineBreaks:0;s<0&&(s=this.oracle.lineHeight);let o=i-e;r.block?this.addBlock(new u6(o,s,r)):(o||n||s>=rD)&&this.addLineDeco(s,n,o)}else i>e&&this.span(e,i);this.lineEnd>-1&&this.lineEnd<this.pos&&(this.lineEnd=this.oracle.doc.lineAt(this.pos).to)}enterLine(){if(this.lineStart>-1)return;let{from:e,to:i}=this.oracle.doc.lineAt(this.pos);this.lineStart=e,this.lineEnd=i,this.writtenTo<e&&((this.writtenTo<e-1||this.nodes[this.nodes.length-1]==null)&&this.nodes.push(this.blankContent(this.writtenTo,e-1)),this.nodes.push(null)),this.pos>e&&this.nodes.push(new zi(this.pos-e,-1,0)),this.writtenTo=this.pos}blankContent(e,i){let r=new ti(i-e);return this.oracle.doc.lineAt(e).to==i&&(r.flags|=4),r}ensureLine(){this.enterLine();let e=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(e instanceof zi)return e;let i=new zi(0,-1,0);return this.nodes.push(i),i}addBlock(e){this.enterLine();let i=e.deco;i&&i.startSide>0&&!this.isCovered&&this.ensureLine(),this.nodes.push(e),this.writtenTo=this.pos=this.pos+e.length,i&&i.endSide>0&&(this.covering=e)}addLineDeco(e,i,r){let s=this.ensureLine();s.length+=r,s.collapsed+=r,s.widgetHeight=Math.max(s.widgetHeight,e),s.breaks+=i,this.writtenTo=this.pos=this.pos+r}finish(e){let i=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(i instanceof zi)&&!this.isCovered?this.nodes.push(new zi(0,-1,0)):(this.writtenTo<this.pos||i==null)&&this.nodes.push(this.blankContent(this.writtenTo,this.pos));let r=e;for(let s of this.nodes)s instanceof zi&&s.updateHeight(this.oracle,r),r+=s?s.length:1;return this.nodes}static build(e,i,r,s){let n=new b1(r,e);return ze.spans(i,r,s,n,0),n.finish(r)}}function sD(t,e,i){let r=new nD;return ze.compare(t,e,i,r,0),r.changes}class nD{constructor(){this.changes=[]}compareRange(){}comparePoint(e,i,r,s){(e<i||r&&r.heightRelevant||s&&s.heightRelevant)&&oo(e,i,this.changes,5)}}function oD(t,e){let i=t.getBoundingClientRect(),r=t.ownerDocument,s=r.defaultView||window,n=Math.max(0,i.left),o=Math.min(s.innerWidth,i.right),a=Math.max(0,i.top),l=Math.min(s.innerHeight,i.bottom);for(let u=t.parentNode;u&&u!=r.body;)if(u.nodeType==1){let c=u,h=window.getComputedStyle(c);if((c.scrollHeight>c.clientHeight||c.scrollWidth>c.clientWidth)&&h.overflow!="visible"){let d=c.getBoundingClientRect();n=Math.max(n,d.left),o=Math.min(o,d.right),a=Math.max(a,d.top),l=Math.min(u==t.parentNode?s.innerHeight:l,d.bottom)}u=h.position=="absolute"||h.position=="fixed"?c.offsetParent:c.parentNode}else if(u.nodeType==11)u=u.host;else break;return{left:n-i.left,right:Math.max(n,o)-i.left,top:a-(i.top+e),bottom:Math.max(a,l)-(i.top+e)}}function aD(t){let e=t.getBoundingClientRect(),i=t.ownerDocument.defaultView||window;return e.left<i.innerWidth&&e.right>0&&e.top<i.innerHeight&&e.bottom>0}function lD(t,e){let i=t.getBoundingClientRect();return{left:0,right:i.right-i.left,top:e,bottom:i.bottom-(i.top+e)}}class Fc{constructor(e,i,r,s){this.from=e,this.to=i,this.size=r,this.displaySize=s}static same(e,i){if(e.length!=i.length)return!1;for(let r=0;r<e.length;r++){let s=e[r],n=i[r];if(s.from!=n.from||s.to!=n.to||s.size!=n.size)return!1}return!0}draw(e,i){return qe.replace({widget:new uD(this.displaySize*(i?e.scaleY:e.scaleX),i)}).range(this.from,this.to)}}class uD extends Js{constructor(e,i){super(),this.size=e,this.vertical=i}eq(e){return e.size==this.size&&e.vertical==this.vertical}toDOM(){let e=document.createElement("div");return this.vertical?e.style.height=this.size+"px":(e.style.width=this.size+"px",e.style.height="2px",e.style.display="inline-block"),e}get estimatedHeight(){return this.vertical?this.size:-1}}class o2{constructor(e,i){this.view=e,this.state=i,this.pixelViewport={left:0,right:window.innerWidth,top:0,bottom:0},this.inView=!0,this.paddingTop=0,this.paddingBottom=0,this.contentDOMWidth=0,this.contentDOMHeight=0,this.editorHeight=0,this.editorWidth=0,this.scaleX=1,this.scaleY=1,this.scrollOffset=0,this.scrolledToBottom=!1,this.scrollAnchorPos=0,this.scrollAnchorHeight=-1,this.scaler=a2,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=Lt.LTR,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1;let r=i.facet(m1).some(s=>typeof s!="function"&&s.class=="cm-lineWrapping");this.heightOracle=new QE(r),this.stateDeco=l2(i),this.heightMap=bi.empty().applyChanges(this.stateDeco,Ve.empty,this.heightOracle.setDoc(i.doc),[new ir(0,0,0,i.doc.length)]);for(let s=0;s<2&&(this.viewport=this.getViewport(0,null),!!this.updateForViewport());s++);this.updateViewportLines(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=qe.set(this.lineGaps.map(s=>s.draw(this,!1))),this.scrollParent=e.scrollDOM,this.computeVisibleRanges()}updateForViewport(){let e=[this.viewport],{main:i}=this.state.selection;for(let r=0;r<=1;r++){let s=r?i.head:i.anchor;if(!e.some(({from:n,to:o})=>s>=n&&s<=o)){let{from:n,to:o}=this.lineBlockAt(s);e.push(new Il(n,o))}}return this.viewports=e.sort((r,s)=>r.from-s.from),this.updateScaler()}updateScaler(){let e=this.scaler;return this.scaler=this.heightMap.height<=7e6?a2:new _1(this.heightOracle,this.heightMap,this.viewports),e.eq(this.scaler)?0:2}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.heightOracle.setDoc(this.state.doc),0,0,e=>{this.viewportLines.push(sa(e,this.scaler))})}update(e,i=null){this.state=e.state;let r=this.stateDeco;this.stateDeco=l2(this.state);let s=e.changedRanges,n=ir.extendWithRanges(s,sD(r,this.stateDeco,e?e.changes:Mt.empty(this.state.doc.length))),o=this.heightMap.height,a=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollOffset);s2(),this.heightMap=this.heightMap.applyChanges(this.stateDeco,e.startState.doc,this.heightOracle.setDoc(this.state.doc),n),(this.heightMap.height!=o||xo)&&(e.flags|=2),a?(this.scrollAnchorPos=e.changes.mapPos(a.from,-1),this.scrollAnchorHeight=a.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=o);let l=n.length?this.mapViewport(this.viewport,e.changes):this.viewport;(i&&(i.range.head<l.from||i.range.head>l.to)||!this.viewportIsAppropriate(l))&&(l=this.getViewport(0,i));let u=l.from!=this.viewport.from||l.to!=this.viewport.to;this.viewport=l,e.flags|=this.updateForViewport(),(u||!e.changes.empty||e.flags&2)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,e.changes))),e.flags|=this.computeVisibleRanges(e.changes),i&&(this.scrollTarget=i),!this.mustEnforceCursorAssoc&&(e.selectionSet||e.focusChanged)&&e.view.lineWrapping&&e.state.selection.main.empty&&e.state.selection.main.assoc&&!e.state.facet(QA)&&(this.mustEnforceCursorAssoc=!0)}measure(){let{view:e}=this,i=e.contentDOM,r=window.getComputedStyle(i),s=this.heightOracle,n=r.whiteSpace;this.defaultTextDirection=r.direction=="rtl"?Lt.RTL:Lt.LTR;let o=this.heightOracle.mustRefreshForWrapping(n)||this.mustMeasureContent==="refresh",a=i.getBoundingClientRect(),l=o||this.mustMeasureContent||this.contentDOMHeight!=a.height;this.contentDOMHeight=a.height,this.mustMeasureContent=!1;let u=0,c=0;if(a.width&&a.height){let{scaleX:R,scaleY:E}=xb(i,a);(R>.005&&Math.abs(this.scaleX-R)>.005||E>.005&&Math.abs(this.scaleY-E)>.005)&&(this.scaleX=R,this.scaleY=E,u|=16,o=l=!0)}let h=(parseInt(r.paddingTop)||0)*this.scaleY,d=(parseInt(r.paddingBottom)||0)*this.scaleY;(this.paddingTop!=h||this.paddingBottom!=d)&&(this.paddingTop=h,this.paddingBottom=d,u|=18),this.editorWidth!=e.scrollDOM.clientWidth&&(s.lineWrapping&&(l=!0),this.editorWidth=e.scrollDOM.clientWidth,u|=16);let f=Sb(this.view.contentDOM,!1).y;f!=this.scrollParent&&(this.scrollParent=f,this.scrollAnchorHeight=-1,this.scrollOffset=0);let m=this.getScrollOffset();this.scrollOffset!=m&&(this.scrollAnchorHeight=-1,this.scrollOffset=m),this.scrolledToBottom=Eb(this.scrollParent||e.win);let v=(this.printing?lD:oD)(i,this.paddingTop),_=v.top-this.pixelViewport.top,w=v.bottom-this.pixelViewport.bottom;this.pixelViewport=v;let x=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(x!=this.inView&&(this.inView=x,x&&(l=!0)),!this.inView&&!this.scrollTarget&&!aD(e.dom))return 0;let A=a.width;if((this.contentDOMWidth!=A||this.editorHeight!=e.scrollDOM.clientHeight)&&(this.contentDOMWidth=a.width,this.editorHeight=e.scrollDOM.clientHeight,u|=16),l){let R=e.docView.measureVisibleLineHeights(this.viewport);if(s.mustRefreshForHeights(R)&&(o=!0),o||s.lineWrapping&&Math.abs(A-this.contentDOMWidth)>s.charWidth){let{lineHeight:E,charWidth:L,textHeight:q}=e.docView.measureTextSize();o=E>0&&s.refresh(n,E,L,q,Math.max(5,A/L),R),o&&(e.docView.minWidth=0,u|=16)}_>0&&w>0?c=Math.max(_,w):_<0&&w<0&&(c=Math.min(_,w)),s2();for(let E of this.viewports){let L=E.from==this.viewport.from?R:e.docView.measureVisibleLineHeights(E);this.heightMap=(o?bi.empty().applyChanges(this.stateDeco,Ve.empty,this.heightOracle,[new ir(0,0,0,e.state.doc.length)]):this.heightMap).updateHeight(s,0,o,new eD(E.from,L))}xo&&(u|=2)}let D=!this.viewportIsAppropriate(this.viewport,c)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return D&&(u&2&&(u|=this.updateScaler()),this.viewport=this.getViewport(c,this.scrollTarget),u|=this.updateForViewport()),(u&2||D)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(o?[]:this.lineGaps,e)),u|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,e.docView.enforceCursorAssoc()),u}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(e,i){let r=.5-Math.max(-.5,Math.min(.5,e/1e3/2)),s=this.heightMap,n=this.heightOracle,{visibleTop:o,visibleBottom:a}=this,l=new Il(s.lineAt(o-r*1e3,rt.ByHeight,n,0,0).from,s.lineAt(a+(1-r)*1e3,rt.ByHeight,n,0,0).to);if(i){let{head:u}=i.range;if(u<l.from||u>l.to){let c=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),h=s.lineAt(u,rt.ByPos,n,0,0),d;i.y=="center"?d=(h.top+h.bottom)/2-c/2:i.y=="start"||i.y=="nearest"&&u<l.from?d=h.top:d=h.bottom-c,l=new Il(s.lineAt(d-1e3/2,rt.ByHeight,n,0,0).from,s.lineAt(d+c+1e3/2,rt.ByHeight,n,0,0).to)}}return l}mapViewport(e,i){let r=i.mapPos(e.from,-1),s=i.mapPos(e.to,1);return new Il(this.heightMap.lineAt(r,rt.ByPos,this.heightOracle,0,0).from,this.heightMap.lineAt(s,rt.ByPos,this.heightOracle,0,0).to)}viewportIsAppropriate({from:e,to:i},r=0){if(!this.inView)return!0;let{top:s}=this.heightMap.lineAt(e,rt.ByPos,this.heightOracle,0,0),{bottom:n}=this.heightMap.lineAt(i,rt.ByPos,this.heightOracle,0,0),{visibleTop:o,visibleBottom:a}=this;return(e==0||s<=o-Math.max(10,Math.min(-r,250)))&&(i==this.state.doc.length||n>=a+Math.max(10,Math.min(r,250)))&&s>o-2*1e3&&n<a+2*1e3}mapLineGaps(e,i){if(!e.length||i.empty)return e;let r=[];for(let s of e)i.touchesRange(s.from,s.to)||r.push(new Fc(i.mapPos(s.from),i.mapPos(s.to),s.size,s.displaySize));return r}ensureLineGaps(e,i){let r=this.heightOracle.lineWrapping,s=r?1e4:2e3,n=s>>1,o=s<<1;if(this.defaultTextDirection!=Lt.LTR&&!r)return[];let a=[],l=(c,h,d,f)=>{if(h-c<n)return;let m=this.state.selection.main,v=[m.from];m.empty||v.push(m.to);for(let w of v)if(w>c&&w<h){l(c,w-10,d,f),l(w+10,h,d,f);return}let _=hD(e,w=>w.from>=d.from&&w.to<=d.to&&Math.abs(w.from-c)<n&&Math.abs(w.to-h)<n&&!v.some(x=>w.from<x&&w.to>x));if(!_){if(h<d.to&&i&&r&&i.visibleRanges.some(A=>A.from<=h&&A.to>=h)){let A=i.moveToLineBoundary(ve.cursor(h),!1,!0).head;A>c&&(h=A)}let w=this.gapSize(d,c,h,f),x=r||w<2e6?w:2e6;_=new Fc(c,h,w,x)}a.push(_)},u=c=>{if(c.length<o||c.type!=Ti.Text)return;let h=cD(c.from,c.to,this.stateDeco);if(h.total<o)return;let d=this.scrollTarget?this.scrollTarget.range.head:null,f,m;if(r){let v=s/this.heightOracle.lineLength*this.heightOracle.lineHeight,_,w;if(d!=null){let x=jl(h,d),A=((this.visibleBottom-this.visibleTop)/2+v)/c.height;_=x-A,w=x+A}else _=(this.visibleTop-c.top-v)/c.height,w=(this.visibleBottom-c.top+v)/c.height;f=zl(h,_),m=zl(h,w)}else{let v=h.total*this.heightOracle.charWidth,_=s*this.heightOracle.charWidth,w=0;if(v>2e6)for(let E of e)E.from>=c.from&&E.from<c.to&&E.size!=E.displaySize&&E.from*this.heightOracle.charWidth+w<this.pixelViewport.left&&(w=E.size-E.displaySize);let x=this.pixelViewport.left+w,A=this.pixelViewport.right+w,D,R;if(d!=null){let E=jl(h,d),L=((A-x)/2+_)/v;D=E-L,R=E+L}else D=(x-_)/v,R=(A+_)/v;f=zl(h,D),m=zl(h,R)}f>c.from&&l(c.from,f,c,h),m<c.to&&l(m,c.to,c,h)};for(let c of this.viewportLines)Array.isArray(c.type)?c.type.forEach(u):u(c);return a}gapSize(e,i,r,s){let n=jl(s,r)-jl(s,i);return this.heightOracle.lineWrapping?e.height*n:s.total*this.heightOracle.charWidth*n}updateLineGaps(e){Fc.same(e,this.lineGaps)||(this.lineGaps=e,this.lineGapDeco=qe.set(e.map(i=>i.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(e){let i=this.stateDeco;this.lineGaps.length&&(i=i.concat(this.lineGapDeco));let r=[];ze.spans(i,this.viewport.from,this.viewport.to,{span(n,o){r.push({from:n,to:o})},point(){}},20);let s=0;if(r.length!=this.visibleRanges.length)s=12;else for(let n=0;n<r.length&&!(s&8);n++){let o=this.visibleRanges[n],a=r[n];(o.from!=a.from||o.to!=a.to)&&(s|=4,e&&e.mapPos(o.from,-1)==a.from&&e.mapPos(o.to,1)==a.to||(s|=8))}return this.visibleRanges=r,s}lineBlockAt(e){return e>=this.viewport.from&&e<=this.viewport.to&&this.viewportLines.find(i=>i.from<=e&&i.to>=e)||sa(this.heightMap.lineAt(e,rt.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(e){return e>=this.viewportLines[0].top&&e<=this.viewportLines[this.viewportLines.length-1].bottom&&this.viewportLines.find(i=>i.top<=e&&i.bottom>=e)||sa(this.heightMap.lineAt(this.scaler.fromDOM(e),rt.ByHeight,this.heightOracle,0,0),this.scaler)}getScrollOffset(){return(this.scrollParent==this.view.scrollDOM?this.scrollParent.scrollTop:(this.scrollParent?this.scrollParent.getBoundingClientRect().top:0)-this.view.contentDOM.getBoundingClientRect().top)*this.scaleY}scrollAnchorAt(e){let i=this.lineBlockAtHeight(e+8);return i.from>=this.viewport.from||this.viewportLines[0].top-e>200?i:this.viewportLines[0]}elementAtHeight(e){return sa(this.heightMap.blockAt(this.scaler.fromDOM(e),this.heightOracle,0,0),this.scaler)}get docHeight(){return this.scaler.toDOM(this.heightMap.height)}get contentHeight(){return this.docHeight+this.paddingTop+this.paddingBottom}}class Il{constructor(e,i){this.from=e,this.to=i}}function cD(t,e,i){let r=[],s=t,n=0;return ze.spans(i,t,e,{span(){},point(o,a){o>s&&(r.push({from:s,to:o}),n+=o-s),s=a}},20),s<e&&(r.push({from:s,to:e}),n+=e-s),{total:n,ranges:r}}function zl({total:t,ranges:e},i){if(i<=0)return e[0].from;if(i>=1)return e[e.length-1].to;let r=Math.floor(t*i);for(let s=0;;s++){let{from:n,to:o}=e[s],a=o-n;if(r<=a)return n+r;r-=a}}function jl(t,e){let i=0;for(let{from:r,to:s}of t.ranges){if(e<=s){i+=e-r;break}i+=s-r}return i/t.total}function hD(t,e){for(let i of t)if(e(i))return i}const a2={toDOM(t){return t},fromDOM(t){return t},scale:1,eq(t){return t==this}};function l2(t){let e=t.facet(k0).filter(r=>typeof r!="function"),i=t.facet(g1).filter(r=>typeof r!="function");return i.length&&e.push(ze.join(i)),e}class _1{constructor(e,i,r){let s=0,n=0,o=0;this.viewports=r.map(({from:a,to:l})=>{let u=i.lineAt(a,rt.ByPos,e,0,0).top,c=i.lineAt(l,rt.ByPos,e,0,0).bottom;return s+=c-u,{from:a,to:l,top:u,bottom:c,domTop:0,domBottom:0}}),this.scale=(7e6-s)/(i.height-s);for(let a of this.viewports)a.domTop=o+(a.top-n)*this.scale,o=a.domBottom=a.domTop+(a.bottom-a.top),n=a.bottom}toDOM(e){for(let i=0,r=0,s=0;;i++){let n=i<this.viewports.length?this.viewports[i]:null;if(!n||e<n.top)return s+(e-r)*this.scale;if(e<=n.bottom)return n.domTop+(e-n.top);r=n.bottom,s=n.domBottom}}fromDOM(e){for(let i=0,r=0,s=0;;i++){let n=i<this.viewports.length?this.viewports[i]:null;if(!n||e<n.domTop)return r+(e-s)/this.scale;if(e<=n.domBottom)return n.top+(e-n.domTop);r=n.bottom,s=n.domBottom}}eq(e){return e instanceof _1?this.scale==e.scale&&this.viewports.length==e.viewports.length&&this.viewports.every((i,r)=>i.from==e.viewports[r].from&&i.to==e.viewports[r].to):!1}}function sa(t,e){if(e.scale==1)return t;let i=e.toDOM(t.top),r=e.toDOM(t.bottom);return new ur(t.from,t.length,i,r-i,Array.isArray(t._content)?t._content.map(s=>sa(s,e)):t._content)}const Hl=we.define({combine:t=>t.join(" ")}),Vd=we.define({combine:t=>t.indexOf(!0)>-1}),Ud=us.newName(),c6=us.newName(),h6=us.newName(),d6={"&light":"."+c6,"&dark":"."+h6};function Gd(t,e,i){return new us(e,{finish(r){return/&/.test(r)?r.replace(/&\w*/,s=>{if(s=="&")return t;if(!i||!i[s])throw new RangeError(`Unsupported selector: ${s}`);return i[s]}):t+" "+r}})}const dD=Gd("."+Ud,{"&":{position:"relative !important",boxSizing:"border-box","&.cm-focused":{outline:"1px dotted #212121"},display:"flex !important",flexDirection:"column"},".cm-scroller":{display:"flex !important",alignItems:"flex-start !important",fontFamily:"monospace",lineHeight:1.4,height:"100%",overflowX:"auto",position:"relative",zIndex:0,overflowAnchor:"none"},".cm-content":{margin:0,flexGrow:2,flexShrink:0,display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",minHeight:"100%",padding:"4px 0",outline:"none","&[contenteditable=true]":{WebkitUserModify:"read-write-plaintext-only"}},".cm-lineWrapping":{whiteSpace_fallback:"pre-wrap",whiteSpace:"break-spaces",wordBreak:"break-word",overflowWrap:"anywhere",flexShrink:1},"&light .cm-content":{caretColor:"black"},"&dark .cm-content":{caretColor:"white"},".cm-line":{display:"block",padding:"0 2px 0 6px"},".cm-layer":{userSelect:"none",position:"absolute",left:0,top:0,contain:"size style","& > *":{position:"absolute"}},"&light .cm-selectionBackground":{background:"#d9d9d9"},"&dark .cm-selectionBackground":{background:"#222"},"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#d7d4f0"},"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#233"},".cm-cursorLayer":{pointerEvents:"none"},"&.cm-focused > .cm-scroller > .cm-cursorLayer":{animation:"steps(1) cm-blink 1.2s infinite"},"@keyframes cm-blink":{"0%":{},"50%":{opacity:0},"100%":{}},"@keyframes cm-blink2":{"0%":{},"50%":{opacity:0},"100%":{}},".cm-cursor, .cm-dropCursor":{borderLeft:"1.2px solid black",marginLeft:"-0.6px",pointerEvents:"none"},".cm-cursor":{display:"none"},"&dark .cm-cursor":{borderLeftColor:"#ddd"},".cm-selectionHandle":{backgroundColor:"currentColor",width:"1.5px"},".cm-selectionHandle-start::before, .cm-selectionHandle-end::before":{content:'""',backgroundColor:"inherit",borderRadius:"50%",width:"8px",height:"8px",position:"absolute",left:"-3.25px"},".cm-selectionHandle-start::before":{top:"-8px"},".cm-selectionHandle-end::before":{bottom:"-8px"},".cm-dropCursor":{position:"absolute"},"&.cm-focused > .cm-scroller > .cm-cursorLayer .cm-cursor":{display:"block"},".cm-iso":{unicodeBidi:"isolate"},".cm-announced":{position:"fixed",top:"-10000px"},"@media print":{".cm-announced":{display:"none"}},"&light .cm-activeLine":{backgroundColor:"#cceeff44"},"&dark .cm-activeLine":{backgroundColor:"#99eeff33"},"&light .cm-specialChar":{color:"red"},"&dark .cm-specialChar":{color:"#f78"},".cm-gutters":{flexShrink:0,display:"flex",height:"100%",boxSizing:"border-box",zIndex:200},".cm-gutters-before":{insetInlineStart:0},".cm-gutters-after":{insetInlineEnd:0},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",border:"0px solid #ddd","&.cm-gutters-before":{borderRightWidth:"1px"},"&.cm-gutters-after":{borderLeftWidth:"1px"}},"&dark .cm-gutters":{backgroundColor:"#333338",color:"#ccc"},".cm-gutter":{display:"flex !important",flexDirection:"column",flexShrink:0,boxSizing:"border-box",minHeight:"100%",overflow:"hidden"},".cm-gutterElement":{boxSizing:"border-box"},".cm-lineNumbers .cm-gutterElement":{padding:"0 3px 0 5px",minWidth:"20px",textAlign:"right",whiteSpace:"nowrap"},"&light .cm-activeLineGutter":{backgroundColor:"#e2f2ff"},"&dark .cm-activeLineGutter":{backgroundColor:"#222227"},".cm-panels":{boxSizing:"border-box",position:"sticky",left:0,right:0,zIndex:300},"&light .cm-panels":{backgroundColor:"#f5f5f5",color:"black"},".cm-panels-top":{top:"0"},".cm-panels-bottom":{bottom:"0"},"&light .cm-panels-top":{borderBottom:"1px solid #ddd"},"&light .cm-panels-bottom":{borderTop:"1px solid #ddd"},"&dark .cm-panels":{backgroundColor:"#333338",color:"white"},".cm-dialog":{padding:"2px 19px 4px 6px",position:"relative","& label":{fontSize:"80%"}},".cm-dialog-close":{position:"absolute",top:"3px",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",fontSize:"14px",padding:"0"},".cm-tab":{display:"inline-block",overflow:"hidden",verticalAlign:"bottom"},".cm-widgetBuffer":{verticalAlign:"text-top",height:"1em",width:0,display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top",userSelect:"none"},".cm-highlightSpace":{backgroundImage:"radial-gradient(circle at 50% 55%, #aaa 20%, transparent 5%)",backgroundPosition:"center"},".cm-highlightTab":{backgroundImage:`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="200" height="20"><path stroke="%23888" stroke-width="1" fill="none" d="M1 10H196L190 5M190 15L196 10M197 4L197 16"/></svg>')`,backgroundSize:"auto 100%",backgroundPosition:"right 90%",backgroundRepeat:"no-repeat"},".cm-trailingSpace":{backgroundColor:"#ff332255"},".cm-button":{verticalAlign:"middle",color:"inherit",fontSize:"70%",padding:".2em 1em",borderRadius:"1px"},"&light .cm-button":{backgroundImage:"linear-gradient(#eff1f5, #d9d9df)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#b4b4b4, #d0d3d6)"}},"&dark .cm-button":{backgroundImage:"linear-gradient(#393939, #111)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#111, #333)"}},".cm-textfield":{verticalAlign:"middle",color:"inherit",fontSize:"70%",border:"1px solid silver",padding:".2em .5em"},"&light .cm-textfield":{backgroundColor:"white"},"&dark .cm-textfield":{border:"1px solid #555",backgroundColor:"inherit"}},d6),fD={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},Ic=me.ie&&me.ie_version<=11;class pD{constructor(e){this.view=e,this.active=!1,this.editContext=null,this.selectionRange=new HA,this.selectionChanged=!1,this.delayedFlush=-1,this.resizeTimeout=-1,this.queue=[],this.delayedAndroidKey=null,this.flushingAndroidKey=-1,this.lastChange=0,this.scrollTargets=[],this.intersection=null,this.resizeScroll=null,this.intersecting=!1,this.gapIntersection=null,this.gaps=[],this.printQuery=null,this.parentCheck=-1,this.dom=e.contentDOM,this.observer=new MutationObserver(i=>{for(let r of i)this.queue.push(r);(me.ie&&me.ie_version<=11||me.ios&&e.composing)&&i.some(r=>r.type=="childList"&&r.removedNodes.length||r.type=="characterData"&&r.oldValue.length>r.target.nodeValue.length)?this.flushSoon():this.flush()}),window.EditContext&&me.android&&e.constructor.EDIT_CONTEXT!==!1&&!(me.chrome&&me.chrome_version<126)&&(this.editContext=new gD(e),e.state.facet(ts)&&(e.contentDOM.editContext=this.editContext.editContext)),Ic&&(this.onCharData=i=>{this.queue.push({target:i.target,type:"characterData",oldValue:i.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this),this.onResize=this.onResize.bind(this),this.onPrint=this.onPrint.bind(this),this.onScroll=this.onScroll.bind(this),window.matchMedia&&(this.printQuery=window.matchMedia("print")),typeof ResizeObserver=="function"&&(this.resizeScroll=new ResizeObserver(()=>{var i;((i=this.view.docView)===null||i===void 0?void 0:i.lastUpdate)<Date.now()-75&&this.onResize()}),this.resizeScroll.observe(e.scrollDOM)),this.addWindowListeners(this.win=e.win),this.start(),typeof IntersectionObserver=="function"&&(this.intersection=new IntersectionObserver(i=>{this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),i.length>0&&i[i.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent("Event")))},{threshold:[0,.001]}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver(i=>{i.length>0&&i[i.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))},{})),this.listenForScroll(),this.readSelectionRange()}onScrollChanged(e){this.view.inputState.runHandlers("scroll",e),this.intersecting&&this.view.measure()}onScroll(e){this.intersecting&&this.flush(!1),this.editContext&&this.view.requestMeasure(this.editContext.measureReq),this.onScrollChanged(e)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(e){(e.type=="change"||!e.type)&&!e.matches||(this.view.viewState.printing=!0,this.view.measure(),setTimeout(()=>{this.view.viewState.printing=!1,this.view.requestMeasure()},500))}updateGaps(e){if(this.gapIntersection&&(e.length!=this.gaps.length||this.gaps.some((i,r)=>i!=e[r]))){this.gapIntersection.disconnect();for(let i of e)this.gapIntersection.observe(i);this.gaps=e}}onSelectionChange(e){let i=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:r}=this,s=this.selectionRange;if(r.state.facet(ts)?r.root.activeElement!=this.dom:!ma(this.dom,s))return;let n=s.anchorNode&&r.docView.tile.nearest(s.anchorNode);if(n&&n.isWidget()&&n.widget.ignoreEvent(e)){i||(this.selectionChanged=!1);return}(me.ie&&me.ie_version<=11||me.android&&me.chrome)&&!r.state.selection.main.empty&&s.focusNode&&ga(s.focusNode,s.focusOffset,s.anchorNode,s.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:e}=this,i=Ia(e.root);if(!i)return!1;let r=me.safari&&e.root.nodeType==11&&e.root.activeElement==this.dom&&mD(this.view,i)||i;if(!r||this.selectionRange.eq(r))return!1;let s=ma(this.dom,r);return s&&!this.selectionChanged&&e.inputState.lastFocusTime>Date.now()-200&&e.inputState.lastTouchTime<Date.now()-300&&qA(this.dom,r)?(this.view.inputState.lastFocusTime=0,e.docView.updateSelection(),!1):(this.selectionRange.setRange(r),s&&(this.selectionChanged=!0),!0)}setSelectionRange(e,i){this.selectionRange.set(e.node,e.offset,i.node,i.offset),this.selectionChanged=!1}clearSelectionRange(){this.selectionRange.set(null,0,null,0)}listenForScroll(){this.parentCheck=-1;let e=0,i=null;for(let r=this.dom;r;)if(r.nodeType==1)!i&&e<this.scrollTargets.length&&this.scrollTargets[e]==r?e++:i||(i=this.scrollTargets.slice(0,e)),i&&i.push(r),r=r.assignedSlot||r.parentNode;else if(r.nodeType==11)r=r.host;else break;if(e<this.scrollTargets.length&&!i&&(i=this.scrollTargets.slice(0,e)),i){for(let r of this.scrollTargets)r.removeEventListener("scroll",this.onScroll);for(let r of this.scrollTargets=i)r.addEventListener("scroll",this.onScroll)}}ignore(e){if(!this.active)return e();try{return this.stop(),e()}finally{this.start(),this.clear()}}start(){this.active||(this.observer.observe(this.dom,fD),Ic&&this.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.active=!0)}stop(){this.active&&(this.active=!1,this.observer.disconnect(),Ic&&this.dom.removeEventListener("DOMCharacterDataModified",this.onCharData))}clear(){this.processRecords(),this.queue.length=0,this.selectionChanged=!1}delayAndroidKey(e,i){var r;if(!this.delayedAndroidKey){let s=()=>{let n=this.delayedAndroidKey;n&&(this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=n.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&n.force&&ao(this.dom,n.key,n.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(s)}(!this.delayedAndroidKey||e=="Enter")&&(this.delayedAndroidKey={key:e,keyCode:i,force:this.lastChange<Date.now()-50||!!(!((r=this.delayedAndroidKey)===null||r===void 0)&&r.force)})}clearDelayedAndroidKey(){this.win.cancelAnimationFrame(this.flushingAndroidKey),this.delayedAndroidKey=null,this.flushingAndroidKey=-1}flushSoon(){this.delayedFlush<0&&(this.delayedFlush=this.view.win.requestAnimationFrame(()=>{this.delayedFlush=-1,this.flush()}))}forceFlush(){this.delayedFlush>=0&&(this.view.win.cancelAnimationFrame(this.delayedFlush),this.delayedFlush=-1),this.flush()}pendingRecords(){for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}processRecords(){let e=this.pendingRecords();e.length&&(this.queue=[]);let i=-1,r=-1,s=!1;for(let n of e){let o=this.readMutation(n);o&&(o.typeOver&&(s=!0),i==-1?{from:i,to:r}=o:(i=Math.min(o.from,i),r=Math.max(o.to,r)))}return{from:i,to:r,typeOver:s}}readChange(){let{from:e,to:i,typeOver:r}=this.processRecords(),s=this.selectionChanged&&ma(this.dom,this.selectionRange);if(e<0&&!s)return null;e>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let n=new RE(this.view,e,i,r);return this.view.docView.domChanged={newSel:n.newSel?n.newSel.main:null},n}flush(e=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;e&&this.readSelectionRange();let i=this.readChange();if(!i)return this.view.requestMeasure(),!1;let r=this.view.state,s=Qb(this.view,i);return this.view.state==r&&(i.domChanged||i.newSel&&!$u(this.view.state.selection,i.newSel.main))&&this.view.update([]),s}readMutation(e){let i=this.view.docView.tile.nearest(e.target);if(!i||i.isWidget())return null;if(i.markDirty(e.type=="attributes"),e.type=="childList"){let r=u2(i,e.previousSibling||e.target.previousSibling,-1),s=u2(i,e.nextSibling||e.target.nextSibling,1);return{from:r?i.posAfter(r):i.posAtStart,to:s?i.posBefore(s):i.posAtEnd,typeOver:!1}}else return e.type=="characterData"?{from:i.posAtStart,to:i.posAtEnd,typeOver:e.target.nodeValue==e.oldValue}:null}setWindow(e){e!=this.win&&(this.removeWindowListeners(this.win),this.win=e,this.addWindowListeners(this.win))}addWindowListeners(e){e.addEventListener("resize",this.onResize),this.printQuery?this.printQuery.addEventListener?this.printQuery.addEventListener("change",this.onPrint):this.printQuery.addListener(this.onPrint):e.addEventListener("beforeprint",this.onPrint),e.addEventListener("scroll",this.onScroll),e.document.addEventListener("selectionchange",this.onSelectionChange)}removeWindowListeners(e){e.removeEventListener("scroll",this.onScroll),e.removeEventListener("resize",this.onResize),this.printQuery?this.printQuery.removeEventListener?this.printQuery.removeEventListener("change",this.onPrint):this.printQuery.removeListener(this.onPrint):e.removeEventListener("beforeprint",this.onPrint),e.document.removeEventListener("selectionchange",this.onSelectionChange)}update(e){this.editContext&&(this.editContext.update(e),e.startState.facet(ts)!=e.state.facet(ts)&&(e.view.contentDOM.editContext=e.state.facet(ts)?this.editContext.editContext:null))}destroy(){var e,i,r;this.stop(),(e=this.intersection)===null||e===void 0||e.disconnect(),(i=this.gapIntersection)===null||i===void 0||i.disconnect(),(r=this.resizeScroll)===null||r===void 0||r.disconnect();for(let s of this.scrollTargets)s.removeEventListener("scroll",this.onScroll);this.removeWindowListeners(this.win),clearTimeout(this.parentCheck),clearTimeout(this.resizeTimeout),this.win.cancelAnimationFrame(this.delayedFlush),this.win.cancelAnimationFrame(this.flushingAndroidKey),this.editContext&&(this.view.contentDOM.editContext=null,this.editContext.destroy())}}function u2(t,e,i){for(;e;){let r=yt.get(e);if(r&&r.parent==t)return r;let s=e.parentNode;e=s!=t.dom?s:i>0?e.nextSibling:e.previousSibling}return null}function c2(t,e){let i=e.startContainer,r=e.startOffset,s=e.endContainer,n=e.endOffset,o=t.docView.domAtPos(t.state.selection.main.anchor,1);return ga(o.node,o.offset,s,n)&&([i,r,s,n]=[s,n,i,r]),{anchorNode:i,anchorOffset:r,focusNode:s,focusOffset:n}}function mD(t,e){if(e.getComposedRanges){let s=e.getComposedRanges(t.root)[0];if(s)return c2(t,s)}let i=null;function r(s){s.preventDefault(),s.stopImmediatePropagation(),i=s.getTargetRanges()[0]}return t.contentDOM.addEventListener("beforeinput",r,!0),t.dom.ownerDocument.execCommand("indent"),t.contentDOM.removeEventListener("beforeinput",r,!0),i?c2(t,i):null}class gD{constructor(e){this.from=0,this.to=0,this.pendingContextChange=null,this.handlers=Object.create(null),this.composing=null,this.resetRange(e.state);let i=this.editContext=new window.EditContext({text:e.state.doc.sliceString(this.from,this.to),selectionStart:this.toContextPos(Math.max(this.from,Math.min(this.to,e.state.selection.main.anchor))),selectionEnd:this.toContextPos(e.state.selection.main.head)});this.handlers.textupdate=r=>{let s=e.state.selection.main,{anchor:n,head:o}=s,a=this.toEditorPos(r.updateRangeStart),l=this.toEditorPos(r.updateRangeEnd);e.inputState.composing>=0&&!this.composing&&(this.composing={contextBase:r.updateRangeStart,editorBase:a,drifted:!1});let u=l-a>r.text.length;a==this.from&&n<this.from?a=n:l==this.to&&n>this.to&&(l=n);let c=e6(e.state.sliceDoc(a,l),r.text,(u?s.from:s.to)-a,u?"end":null);if(!c){let d=ve.single(this.toEditorPos(r.selectionStart),this.toEditorPos(r.selectionEnd));$u(d,s)||e.dispatch({selection:d,userEvent:"select"});return}let h={from:c.from+a,to:c.toA+a,insert:Ve.of(r.text.slice(c.from,c.toB).split(`
|
|
325
325
|
`))};if((me.mac||me.android)&&h.from==o-1&&/^\. ?$/.test(r.text)&&e.contentDOM.getAttribute("autocorrect")=="off"&&(h={from:a,to:l,insert:Ve.of([r.text.replace("."," ")])}),this.pendingContextChange=h,!e.state.readOnly){let d=this.to-this.from+(h.to-h.from+h.insert.length);v1(e,h,ve.single(this.toEditorPos(r.selectionStart,d),this.toEditorPos(r.selectionEnd,d)))}this.pendingContextChange&&(this.revertPending(e.state),this.setSelection(e.state)),h.from<h.to&&!h.insert.length&&e.inputState.composing>=0&&!/[\\p{Alphabetic}\\p{Number}_]/.test(i.text.slice(Math.max(0,r.updateRangeStart-1),Math.min(i.text.length,r.updateRangeStart+1)))&&this.handlers.compositionend(r)},this.handlers.characterboundsupdate=r=>{let s=[],n=null;for(let o=this.toEditorPos(r.rangeStart),a=this.toEditorPos(r.rangeEnd);o<a;o++){let l=e.coordsForChar(o);n=l&&new DOMRect(l.left,l.top,l.right-l.left,l.bottom-l.top)||n||new DOMRect,s.push(n)}i.updateCharacterBounds(r.rangeStart,s)},this.handlers.textformatupdate=r=>{let s=[];for(let n of r.getTextFormats()){let o=n.underlineStyle,a=n.underlineThickness;if(!/none/i.test(o)&&!/none/i.test(a)){let l=this.toEditorPos(n.rangeStart),u=this.toEditorPos(n.rangeEnd);if(l<u){let c=`text-decoration: underline ${/^[a-z]/.test(o)?o+" ":o=="Dashed"?"dashed ":o=="Squiggle"?"wavy ":""}${/thin/i.test(a)?1:2}px`;s.push(qe.mark({attributes:{style:c}}).range(l,u))}}}e.dispatch({effects:qb.of(qe.set(s))})},this.handlers.compositionstart=()=>{e.inputState.composing<0&&(e.inputState.composing=0,e.inputState.compositionFirstChange=!0)},this.handlers.compositionend=()=>{if(e.inputState.composing=-1,e.inputState.compositionFirstChange=null,this.composing){let{drifted:r}=this.composing;this.composing=null,r&&this.reset(e.state)}};for(let r in this.handlers)i.addEventListener(r,this.handlers[r]);this.measureReq={read:r=>{let s=Ia(r.root);s&&s.rangeCount&&this.editContext.updateSelectionBounds(s.getRangeAt(0).getBoundingClientRect())}}}applyEdits(e){let i=0,r=!1,s=this.pendingContextChange;return e.changes.iterChanges((n,o,a,l,u)=>{if(r)return;let c=u.length-(o-n);if(s&&o>=s.to)if(s.from==n&&s.to==o&&s.insert.eq(u)){s=this.pendingContextChange=null,i+=c,this.to+=c;return}else s=null,this.revertPending(e.state);if(n+=i,o+=i,o<=this.from)this.from+=c,this.to+=c;else if(n<this.to){if(n<this.from||o>this.to||this.to-this.from+u.length>3e4){r=!0;return}this.editContext.updateText(this.toContextPos(n),this.toContextPos(o),u.toString()),this.to+=c}i+=c}),s&&!r&&this.revertPending(e.state),!r}update(e){let i=this.pendingContextChange,r=e.startState.selection.main;this.composing&&(this.composing.drifted||!e.changes.touchesRange(r.from,r.to)&&e.transactions.some(s=>!s.isUserEvent("input.type")&&s.changes.touchesRange(this.from,this.to)))?(this.composing.drifted=!0,this.composing.editorBase=e.changes.mapPos(this.composing.editorBase)):!this.applyEdits(e)||!this.rangeIsValid(e.state)?(this.pendingContextChange=null,this.reset(e.state)):(e.docChanged||e.selectionSet||i)&&this.setSelection(e.state),(e.geometryChanged||e.docChanged||e.selectionSet)&&e.view.requestMeasure(this.measureReq)}resetRange(e){let{head:i}=e.selection.main;this.from=Math.max(0,i-1e4),this.to=Math.min(e.doc.length,i+1e4)}reset(e){this.resetRange(e),this.editContext.updateText(0,this.editContext.text.length,e.doc.sliceString(this.from,this.to)),this.setSelection(e)}revertPending(e){let i=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(i.from),this.toContextPos(i.from+i.insert.length),e.doc.sliceString(i.from,i.to))}setSelection(e){let{main:i}=e.selection,r=this.toContextPos(Math.max(this.from,Math.min(this.to,i.anchor))),s=this.toContextPos(i.head);(this.editContext.selectionStart!=r||this.editContext.selectionEnd!=s)&&this.editContext.updateSelection(r,s)}rangeIsValid(e){let{head:i}=e.selection.main;return!(this.from>0&&i-this.from<500||this.to<e.doc.length&&this.to-i<500||this.to-this.from>1e4*3)}toEditorPos(e,i=this.to-this.from){e=Math.min(e,i);let r=this.composing;return r&&r.drifted?r.editorBase+(e-r.contextBase):e+this.from}toContextPos(e){let i=this.composing;return i&&i.drifted?i.contextBase+(e-i.editorBase):e-this.from}destroy(){for(let e in this.handlers)this.editContext.removeEventListener(e,this.handlers[e])}}class xe{get state(){return this.viewState.state}get viewport(){return this.viewState.viewport}get visibleRanges(){return this.viewState.visibleRanges}get inView(){return this.viewState.inView}get composing(){return!!this.inputState&&this.inputState.composing>0}get compositionStarted(){return!!this.inputState&&this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}constructor(e={}){var i;this.plugins=[],this.pluginMap=new Map,this.editorAttrs={},this.contentAttrs={},this.bidiCache=[],this.destroyed=!1,this.updateState=2,this.measureScheduled=-1,this.measureRequests=[],this.contentDOM=document.createElement("div"),this.scrollDOM=document.createElement("div"),this.scrollDOM.tabIndex=-1,this.scrollDOM.className="cm-scroller",this.scrollDOM.appendChild(this.contentDOM),this.announceDOM=document.createElement("div"),this.announceDOM.className="cm-announced",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM),e.parent&&e.parent.appendChild(this.dom);let{dispatch:r}=e;this.dispatchTransactions=e.dispatchTransactions||r&&(s=>s.forEach(n=>r(n,this)))||(s=>this.update(s)),this.dispatch=this.dispatch.bind(this),this._root=e.root||$A(e.parent)||document,this.viewState=new o2(this,e.state||Ke.create(e)),e.scrollTo&&e.scrollTo.is(Ol)&&(this.viewState.scrollTarget=e.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(Qn).map(s=>new Rc(s));for(let s of this.plugins)s.update(this);this.observer=new pD(this),this.inputState=new PE(this),this.inputState.ensureHandlers(this.plugins),this.docView=new Ug(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),!((i=document.fonts)===null||i===void 0)&&i.ready&&document.fonts.ready.then(()=>{this.viewState.mustMeasureContent="refresh",this.requestMeasure()})}dispatch(...e){let i=e.length==1&&e[0]instanceof ui?e:e.length==1&&Array.isArray(e[0])?e[0]:[this.state.update(...e)];this.dispatchTransactions(i,this)}update(e){if(this.updateState!=0)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let i=!1,r=!1,s,n=this.state;for(let d of e){if(d.startState!=n)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");n=d.state}if(this.destroyed){this.viewState.state=n;return}let o=this.hasFocus,a=0,l=null;e.some(d=>d.annotation(o6))?(this.inputState.notifiedFocused=o,a=1):o!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=o,l=a6(n,o),l||(a=1));let u=this.observer.delayedAndroidKey,c=null;if(u?(this.observer.clearDelayedAndroidKey(),c=this.observer.readChange(),(c&&!this.state.doc.eq(n.doc)||!this.state.selection.eq(n.selection))&&(c=null)):this.observer.clear(),n.facet(Ke.phrases)!=this.state.facet(Ke.phrases))return this.setState(n);s=zu.create(this,n,e),s.flags|=a;let h=this.viewState.scrollTarget;try{this.updateState=2;for(let d of e){if(h&&(h=h.map(d.changes)),d.scrollIntoView){let{main:f}=d.state.selection,{x:m,y:v}=this.state.facet(xe.cursorScrollMargin);h=new lo(f.empty?f:ve.cursor(f.head,f.head>f.anchor?-1:1),"nearest","nearest",v,m)}for(let f of d.effects)f.is(Ol)&&(h=f.value.clip(this.state))}this.viewState.update(s,h),this.bidiCache=Wu.update(this.bidiCache,s.changes),s.empty||(this.updatePlugins(s),this.inputState.update(s)),i=this.docView.update(s),this.state.facet(ra)!=this.styleModules&&this.mountStyles(),r=this.updateAttrs(),this.showAnnouncements(e),this.docView.updateSelection(i,e.some(d=>d.isUserEvent("select.pointer")))}finally{this.updateState=0}if(s.startState.facet(Hl)!=s.state.facet(Hl)&&(this.viewState.mustMeasureContent=!0),(i||r||h||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),i&&this.docViewUpdate(),!s.empty)for(let d of this.state.facet($d))try{d(s)}catch(f){Ir(this.state,f,"update listener")}(l||c)&&Promise.resolve().then(()=>{l&&this.state==l.startState&&this.dispatch(l),c&&!Qb(this,c)&&u.force&&ao(this.contentDOM,u.key,u.keyCode)})}setState(e){if(this.updateState!=0)throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");if(this.destroyed){this.viewState.state=e;return}this.updateState=2;let i=this.hasFocus;try{for(let r of this.plugins)r.destroy(this);this.viewState=new o2(this,e),this.plugins=e.facet(Qn).map(r=>new Rc(r)),this.pluginMap.clear();for(let r of this.plugins)r.update(this);this.docView.destroy(),this.docView=new Ug(this),this.inputState.ensureHandlers(this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}i&&this.focus(),this.requestMeasure()}updatePlugins(e){let i=e.startState.facet(Qn),r=e.state.facet(Qn);if(i!=r){let s=[];for(let n of r){let o=i.indexOf(n);if(o<0)s.push(new Rc(n));else{let a=this.plugins[o];a.mustUpdate=e,s.push(a)}}for(let n of this.plugins)n.mustUpdate!=e&&n.destroy(this);this.plugins=s,this.pluginMap.clear()}else for(let s of this.plugins)s.mustUpdate=e;for(let s=0;s<this.plugins.length;s++)this.plugins[s].update(this);i!=r&&this.inputState.ensureHandlers(this.plugins)}docViewUpdate(){for(let e of this.plugins){let i=e.value;if(i&&i.docViewUpdate)try{i.docViewUpdate(this)}catch(r){Ir(this.state,r,"doc view update listener")}}}measure(e=!0){if(this.destroyed)return;if(this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.observer.delayedAndroidKey){this.measureScheduled=-1,this.requestMeasure();return}this.measureScheduled=0,e&&this.observer.forceFlush();let i=null,r=this.viewState.scrollParent,s=this.viewState.getScrollOffset(),{scrollAnchorPos:n,scrollAnchorHeight:o}=this.viewState;Math.abs(s-this.viewState.scrollOffset)>1&&(o=-1),this.viewState.scrollAnchorHeight=-1;try{for(let a=0;;a++){if(o<0)if(Eb(r||this.win))n=-1,o=this.viewState.heightMap.height;else{let f=this.viewState.scrollAnchorAt(s);n=f.from,o=f.top}this.updateState=1;let l=this.viewState.measure();if(!l&&!this.measureRequests.length&&this.viewState.scrollTarget==null)break;if(a>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let u=[];l&4||([this.measureRequests,u]=[u,this.measureRequests]);let c=u.map(f=>{try{return f.read(this)}catch(m){return Ir(this.state,m),h2}}),h=zu.create(this,this.state,[]),d=!1;h.flags|=l,i?i.flags|=l:i=h,this.updateState=2,h.empty||(this.updatePlugins(h),this.inputState.update(h),this.updateAttrs(),d=this.docView.update(h),d&&this.docViewUpdate());for(let f=0;f<u.length;f++)if(c[f]!=h2)try{let m=u[f];m.write&&m.write(c[f],this)}catch(m){Ir(this.state,m)}if(d&&this.docView.updateSelection(!0),!h.viewportChanged&&this.measureRequests.length==0){if(this.viewState.editorHeight)if(this.viewState.scrollTarget){this.docView.scrollIntoView(this.viewState.scrollTarget),this.viewState.scrollTarget=null,o=-1;continue}else{let m=((n<0?this.viewState.heightMap.height:this.viewState.lineBlockAt(n).top)-o)/this.scaleY;if((m>1||m<-1)&&!(me.ios&&this.inputState.lastIOSMomentumScroll>Date.now()-100)&&(r==this.scrollDOM||this.hasFocus||Math.max(this.inputState.lastWheelEvent,this.inputState.lastTouchTime)>Date.now()-100)){s=s+m,r?n<0?r.scrollTop=r.scrollHeight:r.scrollTop+=m:this.win.scrollBy(0,m),o=-1;continue}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(i&&!i.empty)for(let a of this.state.facet($d))a(i)}get themeClasses(){return Ud+" "+(this.state.facet(Vd)?h6:c6)+" "+this.state.facet(Hl)}updateAttrs(){let e=d2(this,Wb,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),i={spellcheck:"false",autocorrect:"off",autocapitalize:"off",writingsuggestions:"false",translate:"no",contenteditable:this.state.facet(ts)?"true":"false",class:"cm-content",style:`${me.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(i["aria-readonly"]="true"),d2(this,m1,i);let r=this.observer.ignore(()=>{let s=Hg(this.contentDOM,this.contentAttrs,i),n=Hg(this.dom,this.editorAttrs,e);return s||n});return this.editorAttrs=e,this.contentAttrs=i,r}showAnnouncements(e){let i=!0;for(let r of e)for(let s of r.effects)if(s.is(xe.announce)){i&&(this.announceDOM.textContent=""),i=!1;let n=this.announceDOM.appendChild(document.createElement("div"));n.textContent=s.value}}mountStyles(){this.styleModules=this.state.facet(ra);let e=this.state.facet(xe.cspNonce);us.mount(this.root,this.styleModules.concat(dD).reverse(),e?{nonce:e}:void 0)}readMeasured(){if(this.updateState==2)throw new Error("Reading the editor layout isn't allowed during an update");this.updateState==0&&this.measureScheduled>-1&&this.measure(!1)}requestMeasure(e){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame(()=>this.measure())),e){if(this.measureRequests.indexOf(e)>-1)return;if(e.key!=null){for(let i=0;i<this.measureRequests.length;i++)if(this.measureRequests[i].key===e.key){this.measureRequests[i]=e;return}}this.measureRequests.push(e)}}plugin(e){let i=this.pluginMap.get(e);return(i===void 0||i&&i.plugin!=e)&&this.pluginMap.set(e,i=this.plugins.find(r=>r.plugin==e)||null),i&&i.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}get scaleX(){return this.viewState.scaleX}get scaleY(){return this.viewState.scaleY}elementAtHeight(e){return this.readMeasured(),this.viewState.elementAtHeight(e)}lineBlockAtHeight(e){return this.readMeasured(),this.viewState.lineBlockAtHeight(e)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(e){return this.viewState.lineBlockAt(e)}get contentHeight(){return this.viewState.contentHeight}moveByChar(e,i,r){return Pc(this,e,Gg(this,e,i,r))}moveByGroup(e,i){return Pc(this,e,Gg(this,e,i,r=>AE(this,e.head,r)))}visualLineSide(e,i){let r=this.bidiSpans(e),s=this.textDirectionAt(e.from),n=r[i?r.length-1:0];return ve.cursor(n.side(i,s)+e.from,n.forward(!i,s)?1:-1)}moveToLineBoundary(e,i,r=!0){return CE(this,e,i,r)}moveVertically(e,i,r){return Pc(this,e,EE(this,e,i,r))}domAtPos(e,i=1){return this.docView.domAtPos(e,i)}posAtDOM(e,i=0){return this.docView.posFromDOM(e,i)}posAtCoords(e,i=!0){this.readMeasured();let r=Wd(this,e,i);return r&&r.pos}posAndSideAtCoords(e,i=!0){return this.readMeasured(),Wd(this,e,i)}coordsAtPos(e,i=1){this.readMeasured();let r=this.state.doc.lineAt(e),s=this.bidiSpans(r),n=s[Fr.find(s,e-r.from,-1,i)];return this.docView.coordsAt(e,i,n.dir==Lt.RTL)}coordsForChar(e){return this.readMeasured(),this.docView.coordsForChar(e)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.defaultTextDirection}textDirectionAt(e){return!this.state.facet(Hb)||e<this.viewport.from||e>this.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(e))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(e){if(e.length>vD)return Nb(e.length);let i=this.textDirectionAt(e.from),r;for(let n of this.bidiCache)if(n.from==e.from&&n.dir==i&&(n.fresh||Rb(n.isolates,r=Wg(this,e))))return n.order;r||(r=Wg(this,e));let s=XA(e.text,i,r);return this.bidiCache.push(new Wu(e.from,e.to,i,r,!0,s)),s}get hasFocus(){var e;return(this.dom.ownerDocument.hasFocus()||me.safari&&((e=this.inputState)===null||e===void 0?void 0:e.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{Ab(this.contentDOM),this.docView.updateSelection()})}setRoot(e){this._root!=e&&(this._root=e,this.observer.setWindow((e.nodeType==9?e:e.ownerDocument).defaultView||window),this.mountStyles())}destroy(){this.root.activeElement==this.contentDOM&&this.contentDOM.blur();for(let e of this.plugins)e.destroy(this);this.plugins=[],this.inputState.destroy(),this.docView.destroy(),this.dom.remove(),this.observer.destroy(),this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(e,i={}){var r,s,n,o;return Ol.of(new lo(typeof e=="number"?ve.cursor(e):e,(r=i.y)!==null&&r!==void 0?r:"nearest",(s=i.x)!==null&&s!==void 0?s:"nearest",(n=i.yMargin)!==null&&n!==void 0?n:5,(o=i.xMargin)!==null&&o!==void 0?o:5))}scrollSnapshot(){let{scrollTop:e,scrollLeft:i}=this.scrollDOM,r=this.viewState.scrollAnchorAt(e);return Ol.of(new lo(ve.cursor(r.from),"start","start",r.top-e,i,!0))}setTabFocusMode(e){e==null?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:typeof e=="boolean"?this.inputState.tabFocusMode=e?0:-1:this.inputState.tabFocusMode!=0&&(this.inputState.tabFocusMode=Date.now()+e)}static domEventHandlers(e){return qr.define(()=>({}),{eventHandlers:e})}static domEventObservers(e){return qr.define(()=>({}),{eventObservers:e})}static theme(e,i){let r=us.newName(),s=[Hl.of(r),ra.of(Gd(`.${r}`,e))];return i&&i.dark&&s.push(Vd.of(!0)),s}static baseTheme(e){return Fn.lowest(ra.of(Gd("."+Ud,e,d6)))}static findFromDOM(e){var i;let r=e.querySelector(".cm-content"),s=r&&yt.get(r)||yt.get(e);return((i=s==null?void 0:s.root)===null||i===void 0?void 0:i.view)||null}}xe.styleModule=ra;xe.inputHandler=zb;xe.clipboardInputFilter=f1;xe.clipboardOutputFilter=p1;xe.scrollHandler=$b;xe.focusChangeEffect=jb;xe.perLineTextDirection=Hb;xe.exceptionSink=Ib;xe.updateListener=$d;xe.editable=ts;xe.mouseSelectionStyle=Fb;xe.dragMovesSelection=Pb;xe.clickAddsSelectionRange=Ob;xe.decorations=k0;xe.blockWrappers=Kb;xe.outerDecorations=g1;xe.atomicRanges=el;xe.bidiIsolatedRanges=Vb;xe.cursorScrollMargin=we.define({combine:t=>{let e=5,i=5;for(let r of t)typeof r=="number"?e=i=r:{x:e,y:i}=r;return{x:e,y:i}}});xe.scrollMargins=Ub;xe.darkTheme=Vd;xe.cspNonce=we.define({combine:t=>t.length?t[0]:""});xe.contentAttributes=m1;xe.editorAttributes=Wb;xe.lineWrapping=xe.contentAttributes.of({class:"cm-lineWrapping"});xe.announce=at.define();const vD=4096,h2={};class Wu{constructor(e,i,r,s,n,o){this.from=e,this.to=i,this.dir=r,this.isolates=s,this.fresh=n,this.order=o}static update(e,i){if(i.empty&&!e.some(n=>n.fresh))return e;let r=[],s=e.length?e[e.length-1].dir:Lt.LTR;for(let n=Math.max(0,e.length-10);n<e.length;n++){let o=e[n];o.dir==s&&!i.touchesRange(o.from,o.to)&&r.push(new Wu(i.mapPos(o.from,1),i.mapPos(o.to,-1),o.dir,o.isolates,!1,o.order))}return r}}function d2(t,e,i){for(let r=t.state.facet(e),s=r.length-1;s>=0;s--){let n=r[s],o=typeof n=="function"?n(t):n;o&&c1(o,i)}return i}const bD=me.mac?"mac":me.windows?"win":me.linux?"linux":"key";function _D(t,e){const i=t.split(/-(?!$)/);let r=i[i.length-1];r=="Space"&&(r=" ");let s,n,o,a;for(let l=0;l<i.length-1;++l){const u=i[l];if(/^(cmd|meta|m)$/i.test(u))a=!0;else if(/^a(lt)?$/i.test(u))s=!0;else if(/^(c|ctrl|control)$/i.test(u))n=!0;else if(/^s(hift)?$/i.test(u))o=!0;else if(/^mod$/i.test(u))e=="mac"?a=!0:n=!0;else throw new Error("Unrecognized modifier name: "+u)}return s&&(r="Alt-"+r),n&&(r="Ctrl-"+r),a&&(r="Meta-"+r),o&&(r="Shift-"+r),r}function $l(t,e,i){return e.altKey&&(t="Alt-"+t),e.ctrlKey&&(t="Ctrl-"+t),e.metaKey&&(t="Meta-"+t),i!==!1&&e.shiftKey&&(t="Shift-"+t),t}const yD=Fn.default(xe.domEventHandlers({keydown(t,e){return CD(xD(e.state),t,e,"editor")}})),wD=we.define({enables:yD}),f2=new WeakMap;function xD(t){let e=t.facet(wD),i=f2.get(e);return i||f2.set(e,i=kD(e.reduce((r,s)=>r.concat(s),[]))),i}let Ns=null;const SD=4e3;function kD(t,e=bD){let i=Object.create(null),r=Object.create(null),s=(o,a)=>{let l=r[o];if(l==null)r[o]=a;else if(l!=a)throw new Error("Key binding "+o+" is used both as a regular binding and as a multi-stroke prefix")},n=(o,a,l,u,c)=>{var h,d;let f=i[o]||(i[o]=Object.create(null)),m=a.split(/ (?!$)/).map(w=>_D(w,e));for(let w=1;w<m.length;w++){let x=m.slice(0,w).join(" ");s(x,!0),f[x]||(f[x]={preventDefault:!0,stopPropagation:!1,run:[A=>{let D=Ns={view:A,prefix:x,scope:o};return setTimeout(()=>{Ns==D&&(Ns=null)},SD),!0}]})}let v=m.join(" ");s(v,!1);let _=f[v]||(f[v]={preventDefault:!1,stopPropagation:!1,run:((d=(h=f._any)===null||h===void 0?void 0:h.run)===null||d===void 0?void 0:d.slice())||[]});l&&_.run.push(l),u&&(_.preventDefault=!0),c&&(_.stopPropagation=!0)};for(let o of t){let a=o.scope?o.scope.split(" "):["editor"];if(o.any)for(let u of a){let c=i[u]||(i[u]=Object.create(null));c._any||(c._any={preventDefault:!1,stopPropagation:!1,run:[]});let{any:h}=o;for(let d in c)c[d].run.push(f=>h(f,Yd))}let l=o[e]||o.key;if(l)for(let u of a)n(u,l,o.run,o.preventDefault,o.stopPropagation),o.shift&&n(u,"Shift-"+l,o.shift,o.preventDefault,o.stopPropagation)}return i}let Yd=null;function CD(t,e,i,r){Yd=e;let s=OA(e),n=mA(s,0),o=gA(n)==s.length&&s!=" ",a="",l=!1,u=!1,c=!1;Ns&&Ns.view==i&&Ns.scope==r&&(a=Ns.prefix+" ",i6.indexOf(e.keyCode)<0&&(u=!0,Ns=null));let h=new Set,d=_=>{if(_){for(let w of _.run)if(!h.has(w)&&(h.add(w),w(i)))return _.stopPropagation&&(c=!0),!0;_.preventDefault&&(_.stopPropagation&&(c=!0),u=!0)}return!1},f=t[r],m,v;return f&&(d(f[a+$l(s,e,!o)])?l=!0:o&&(e.altKey||e.metaKey||e.ctrlKey)&&!(me.windows&&e.ctrlKey&&e.altKey)&&!(me.mac&&e.altKey&&!(e.ctrlKey||e.metaKey))&&(m=Ks[e.keyCode])&&m!=s?(d(f[a+$l(m,e,!0)])||e.shiftKey&&(v=Pa[e.keyCode])!=s&&v!=m&&d(f[a+$l(v,e,!1)]))&&(l=!0):o&&e.shiftKey&&d(f[a+$l(s,e,!0)])&&(l=!0),!l&&d(f._any)&&(l=!0)),u&&(l=!0),l&&c&&e.stopPropagation(),Yd=null,l}function DR(){return ED}const AD=qe.line({class:"cm-activeLine"}),ED=qr.fromClass(class{constructor(t){this.decorations=this.getDeco(t)}update(t){(t.docChanged||t.selectionSet)&&(this.decorations=this.getDeco(t.view))}getDeco(t){let e=-1,i=[];for(let r of t.state.selection.ranges){let s=t.lineBlockAt(r.head);s.from>e&&(i.push(AD.range(s.from)),e=s.from)}return qe.set(i)}},{decorations:t=>t.decorations});class mr extends Dn{compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}eq(e){return!1}destroy(e){}}mr.prototype.elementClass="";mr.prototype.toDOM=void 0;mr.prototype.mapMode=ji.TrackBefore;mr.prototype.startSide=mr.prototype.endSide=-1;mr.prototype.point=!0;const bu=we.define(),DD=we.define(),MD={class:"",renderEmptyElements:!1,elementStyle:"",markers:()=>ze.empty,lineMarker:()=>null,widgetMarker:()=>null,lineMarkerChange:null,initialSpacer:null,updateSpacer:null,domEventHandlers:{},side:"before"},ba=we.define();function f6(t){return[p6(),ba.of({...MD,...t})]}const p2=we.define({combine:t=>t.some(e=>e)});function p6(t){return[TD]}const TD=qr.fromClass(class{constructor(t){this.view=t,this.domAfter=null,this.prevViewport=t.viewport,this.dom=document.createElement("div"),this.dom.className="cm-gutters cm-gutters-before",this.dom.setAttribute("aria-hidden","true"),this.dom.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.gutters=t.state.facet(ba).map(e=>new g2(t,e)),this.fixed=!t.state.facet(p2);for(let e of this.gutters)e.config.side=="after"?this.getDOMAfter().appendChild(e.dom):this.dom.appendChild(e.dom);this.fixed&&(this.dom.style.position="sticky"),this.syncGutters(!1),t.scrollDOM.insertBefore(this.dom,t.contentDOM)}getDOMAfter(){return this.domAfter||(this.domAfter=document.createElement("div"),this.domAfter.className="cm-gutters cm-gutters-after",this.domAfter.setAttribute("aria-hidden","true"),this.domAfter.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.domAfter.style.position=this.fixed?"sticky":"",this.view.scrollDOM.appendChild(this.domAfter)),this.domAfter}update(t){if(this.updateGutters(t)){let e=this.prevViewport,i=t.view.viewport,r=Math.min(e.to,i.to)-Math.max(e.from,i.from);this.syncGutters(r<(i.to-i.from)*.8)}if(t.geometryChanged){let e=this.view.contentHeight/this.view.scaleY+"px";this.dom.style.minHeight=e,this.domAfter&&(this.domAfter.style.minHeight=e)}this.view.state.facet(p2)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?"sticky":"",this.domAfter&&(this.domAfter.style.position=this.fixed?"sticky":"")),this.prevViewport=t.view.viewport}syncGutters(t){let e=this.dom.nextSibling;t&&(this.dom.remove(),this.domAfter&&this.domAfter.remove());let i=ze.iter(this.view.state.facet(bu),this.view.viewport.from),r=[],s=this.gutters.map(n=>new BD(n,this.view.viewport,-this.view.documentPadding.top));for(let n of this.view.viewportLineBlocks)if(r.length&&(r=[]),Array.isArray(n.type)){let o=!0;for(let a of n.type)if(a.type==Ti.Text&&o){Xd(i,r,a.from);for(let l of s)l.line(this.view,a,r);o=!1}else if(a.widget)for(let l of s)l.widget(this.view,a)}else if(n.type==Ti.Text){Xd(i,r,n.from);for(let o of s)o.line(this.view,n,r)}else if(n.widget)for(let o of s)o.widget(this.view,n);for(let n of s)n.finish();t&&(this.view.scrollDOM.insertBefore(this.dom,e),this.domAfter&&this.view.scrollDOM.appendChild(this.domAfter))}updateGutters(t){let e=t.startState.facet(ba),i=t.state.facet(ba),r=t.docChanged||t.heightChanged||t.viewportChanged||!ze.eq(t.startState.facet(bu),t.state.facet(bu),t.view.viewport.from,t.view.viewport.to);if(e==i)for(let s of this.gutters)s.update(t)&&(r=!0);else{r=!0;let s=[];for(let n of i){let o=e.indexOf(n);o<0?s.push(new g2(this.view,n)):(this.gutters[o].update(t),s.push(this.gutters[o]))}for(let n of this.gutters)n.dom.remove(),s.indexOf(n)<0&&n.destroy();for(let n of s)n.config.side=="after"?this.getDOMAfter().appendChild(n.dom):this.dom.appendChild(n.dom);this.gutters=s}return r}destroy(){for(let t of this.gutters)t.destroy();this.dom.remove(),this.domAfter&&this.domAfter.remove()}},{provide:t=>xe.scrollMargins.of(e=>{let i=e.plugin(t);if(!i||i.gutters.length==0||!i.fixed)return null;let r=i.dom.offsetWidth*e.scaleX,s=i.domAfter?i.domAfter.offsetWidth*e.scaleX:0;return e.textDirection==Lt.LTR?{left:r,right:s}:{right:r,left:s}})});function m2(t){return Array.isArray(t)?t:[t]}function Xd(t,e,i){for(;t.value&&t.from<=i;)t.from==i&&e.push(t.value),t.next()}class BD{constructor(e,i,r){this.gutter=e,this.height=r,this.i=0,this.cursor=ze.iter(e.markers,i.from)}addElement(e,i,r){let{gutter:s}=this,n=(i.top-this.height)/e.scaleY,o=i.height/e.scaleY;if(this.i==s.elements.length){let a=new m6(e,o,n,r);s.elements.push(a),s.dom.appendChild(a.dom)}else s.elements[this.i].update(e,o,n,r);this.height=i.bottom,this.i++}line(e,i,r){let s=[];Xd(this.cursor,s,i.from),r.length&&(s=s.concat(r));let n=this.gutter.config.lineMarker(e,i,s);n&&s.unshift(n);let o=this.gutter;s.length==0&&!o.config.renderEmptyElements||this.addElement(e,i,s)}widget(e,i){let r=this.gutter.config.widgetMarker(e,i.widget,i),s=r?[r]:null;for(let n of e.state.facet(DD)){let o=n(e,i.widget,i);o&&(s||(s=[])).push(o)}s&&this.addElement(e,i,s)}finish(){let e=this.gutter;for(;e.elements.length>this.i;){let i=e.elements.pop();e.dom.removeChild(i.dom),i.destroy()}}}class g2{constructor(e,i){this.view=e,this.config=i,this.elements=[],this.spacer=null,this.dom=document.createElement("div"),this.dom.className="cm-gutter"+(this.config.class?" "+this.config.class:"");for(let r in i.domEventHandlers)this.dom.addEventListener(r,s=>{let n=s.target,o;if(n!=this.dom&&this.dom.contains(n)){for(;n.parentNode!=this.dom;)n=n.parentNode;let l=n.getBoundingClientRect();o=(l.top+l.bottom)/2}else o=s.clientY;let a=e.lineBlockAtHeight(o-e.documentTop);i.domEventHandlers[r](e,a,s)&&s.preventDefault()});this.markers=m2(i.markers(e)),i.initialSpacer&&(this.spacer=new m6(e,0,0,[i.initialSpacer(e)]),this.dom.appendChild(this.spacer.dom),this.spacer.dom.style.cssText+="visibility: hidden; pointer-events: none")}update(e){let i=this.markers;if(this.markers=m2(this.config.markers(e.view)),this.spacer&&this.config.updateSpacer){let s=this.config.updateSpacer(this.spacer.markers[0],e);s!=this.spacer.markers[0]&&this.spacer.update(e.view,0,0,[s])}let r=e.view.viewport;return!ze.eq(this.markers,i,r.from,r.to)||(this.config.lineMarkerChange?this.config.lineMarkerChange(e):!1)}destroy(){for(let e of this.elements)e.destroy()}}class m6{constructor(e,i,r,s){this.height=-1,this.above=0,this.markers=[],this.dom=document.createElement("div"),this.dom.className="cm-gutterElement",this.update(e,i,r,s)}update(e,i,r,s){this.height!=i&&(this.height=i,this.dom.style.height=i+"px"),this.above!=r&&(this.dom.style.marginTop=(this.above=r)?r+"px":""),RD(this.markers,s)||this.setMarkers(e,s)}setMarkers(e,i){let r="cm-gutterElement",s=this.dom.firstChild;for(let n=0,o=0;;){let a=o,l=n<i.length?i[n++]:null,u=!1;if(l){let c=l.elementClass;c&&(r+=" "+c);for(let h=o;h<this.markers.length;h++)if(this.markers[h].compare(l)){a=h,u=!0;break}}else a=this.markers.length;for(;o<a;){let c=this.markers[o++];if(c.toDOM){c.destroy(s);let h=s.nextSibling;s.remove(),s=h}}if(!l)break;l.toDOM&&(u?s=s.nextSibling:this.dom.insertBefore(l.toDOM(e),s)),u&&o++}this.dom.className=r,this.markers=i}destroy(){this.setMarkers(null,[])}}function RD(t,e){if(t.length!=e.length)return!1;for(let i=0;i<t.length;i++)if(!t[i].compare(e[i]))return!1;return!0}const ND=we.define(),LD=we.define(),eo=we.define({combine(t){return DA(t,{formatNumber:String,domEventHandlers:{}},{domEventHandlers(e,i){let r=Object.assign({},e);for(let s in i){let n=r[s],o=i[s];r[s]=n?(a,l,u)=>n(a,l,u)||o(a,l,u):o}return r}})}});class zc extends mr{constructor(e){super(),this.number=e}eq(e){return this.number==e.number}toDOM(){return document.createTextNode(this.number)}}function jc(t,e){return t.state.facet(eo).formatNumber(e,t.state)}const OD=ba.compute([eo],t=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers(e){return e.state.facet(ND)},lineMarker(e,i,r){return r.some(s=>s.toDOM)?null:new zc(jc(e,e.state.doc.lineAt(i.from).number))},widgetMarker:(e,i,r)=>{for(let s of e.state.facet(LD)){let n=s(e,i,r);if(n)return n}return null},lineMarkerChange:e=>e.startState.facet(eo)!=e.state.facet(eo),initialSpacer(e){return new zc(jc(e,v2(e.state.doc.lines)))},updateSpacer(e,i){let r=jc(i.view,v2(i.view.state.doc.lines));return r==e.number?e:new zc(r)},domEventHandlers:t.facet(eo).domEventHandlers,side:"before"}));function PD(t={}){return[eo.of(t),p6(),OD]}function v2(t){let e=9;for(;e<t;)e=e*10+9;return e}const FD=new class extends mr{constructor(){super(...arguments),this.elementClass="cm-activeLineGutter"}},ID=bu.compute(["selection"],t=>{let e=[],i=-1;for(let r of t.selection.ranges){let s=t.doc.lineAt(r.head).from;s>i&&(i=s,e.push(FD.range(s)))}return ze.of(e)});function MR(){return ID}const zD=1024;let jD=0,Hc=class{constructor(e,i){this.from=e,this.to=i}};class Qe{constructor(e={}){this.id=jD++,this.perNode=!!e.perNode,this.deserialize=e.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")}),this.combine=e.combine||null}add(e){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return typeof e!="function"&&(e=Ki.match(e)),i=>{let r=e(i);return r===void 0?null:[this,r]}}}Qe.closedBy=new Qe({deserialize:t=>t.split(" ")});Qe.openedBy=new Qe({deserialize:t=>t.split(" ")});Qe.group=new Qe({deserialize:t=>t.split(" ")});Qe.isolate=new Qe({deserialize:t=>{if(t&&t!="rtl"&&t!="ltr"&&t!="auto")throw new RangeError("Invalid value for isolate: "+t);return t||"auto"}});Qe.contextHash=new Qe({perNode:!0});Qe.lookAhead=new Qe({perNode:!0});Qe.mounted=new Qe({perNode:!0});class _a{constructor(e,i,r,s=!1){this.tree=e,this.overlay=i,this.parser=r,this.bracketed=s}static get(e){return e&&e.props&&e.props[Qe.mounted.id]}}const HD=Object.create(null);class Ki{constructor(e,i,r,s=0){this.name=e,this.props=i,this.id=r,this.flags=s}static define(e){let i=e.props&&e.props.length?Object.create(null):HD,r=(e.top?1:0)|(e.skipped?2:0)|(e.error?4:0)|(e.name==null?8:0),s=new Ki(e.name||"",i,e.id,r);if(e.props){for(let n of e.props)if(Array.isArray(n)||(n=n(s)),n){if(n[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");i[n[0].id]=n[1]}}return s}prop(e){return this.props[e.id]}get isTop(){return(this.flags&1)>0}get isSkipped(){return(this.flags&2)>0}get isError(){return(this.flags&4)>0}get isAnonymous(){return(this.flags&8)>0}is(e){if(typeof e=="string"){if(this.name==e)return!0;let i=this.prop(Qe.group);return i?i.indexOf(e)>-1:!1}return this.id==e}static match(e){let i=Object.create(null);for(let r in e)for(let s of r.split(" "))i[s]=e[r];return r=>{for(let s=r.prop(Qe.group),n=-1;n<(s?s.length:0);n++){let o=i[n<0?r.name:s[n]];if(o)return o}}}}Ki.none=new Ki("",Object.create(null),0,8);class g6{constructor(e){this.types=e;for(let i=0;i<e.length;i++)if(e[i].id!=i)throw new RangeError("Node type ids should correspond to array positions when creating a node set")}extend(...e){let i=[];for(let r of this.types){let s=null;for(let n of e){let o=n(r);if(o){s||(s=Object.assign({},r.props));let a=o[1],l=o[0];l.combine&&l.id in s&&(a=l.combine(s[l.id],a)),s[l.id]=a}}i.push(s?new Ki(r.name,s,r.id,r.flags):r)}return new g6(i)}}const ql=new WeakMap,b2=new WeakMap;var kt;(function(t){t[t.ExcludeBuffers=1]="ExcludeBuffers",t[t.IncludeAnonymous=2]="IncludeAnonymous",t[t.IgnoreMounts=4]="IgnoreMounts",t[t.IgnoreOverlays=8]="IgnoreOverlays",t[t.EnterBracketed=16]="EnterBracketed"})(kt||(kt={}));class oi{constructor(e,i,r,s,n){if(this.type=e,this.children=i,this.positions=r,this.length=s,this.props=null,n&&n.length){this.props=Object.create(null);for(let[o,a]of n)this.props[typeof o=="number"?o:o.id]=a}}toString(){let e=_a.get(this);if(e&&!e.overlay)return e.tree.toString();let i="";for(let r of this.children){let s=r.toString();s&&(i&&(i+=","),i+=s)}return this.type.name?(/\W/.test(this.type.name)&&!this.type.isError?JSON.stringify(this.type.name):this.type.name)+(i.length?"("+i+")":""):i}cursor(e=0){return new Zd(this.topNode,e)}cursorAt(e,i=0,r=0){let s=ql.get(this)||this.topNode,n=new Zd(s);return n.moveTo(e,i),ql.set(this,n._tree),n}get topNode(){return new Bi(this,0,0,null)}resolve(e,i=0){let r=ja(ql.get(this)||this.topNode,e,i,!1);return ql.set(this,r),r}resolveInner(e,i=0){let r=ja(b2.get(this)||this.topNode,e,i,!0);return b2.set(this,r),r}resolveStack(e,i=0){return WD(this,e,i)}iterate(e){let{enter:i,leave:r,from:s=0,to:n=this.length}=e,o=e.mode||0,a=(o&kt.IncludeAnonymous)>0;for(let l=this.cursor(o|kt.IncludeAnonymous);;){let u=!1;if(l.from<=n&&l.to>=s&&(!a&&l.type.isAnonymous||i(l)!==!1)){if(l.firstChild())continue;u=!0}for(;u&&r&&(a||!l.type.isAnonymous)&&r(l),!l.nextSibling();){if(!l.parent())return;u=!0}}}prop(e){return e.perNode?this.props?this.props[e.id]:void 0:this.type.prop(e)}get propValues(){let e=[];if(this.props)for(let i in this.props)e.push([+i,this.props[i]]);return e}balance(e={}){return this.children.length<=8?this:x1(Ki.none,this.children,this.positions,0,this.children.length,0,this.length,(i,r,s)=>new oi(this.type,i,r,s,this.propValues),e.makeTree||((i,r,s)=>new oi(Ki.none,i,r,s)))}static build(e){return KD(e)}}oi.empty=new oi(Ki.none,[],[],0);class y1{constructor(e,i){this.buffer=e,this.index=i}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}get pos(){return this.index}next(){this.index-=4}fork(){return new y1(this.buffer,this.index)}}class Us{constructor(e,i,r){this.buffer=e,this.length=i,this.set=r}get type(){return Ki.none}toString(){let e=[];for(let i=0;i<this.buffer.length;)e.push(this.childString(i)),i=this.buffer[i+3];return e.join(",")}childString(e){let i=this.buffer[e],r=this.buffer[e+3],s=this.set.types[i],n=s.name;if(/\W/.test(n)&&!s.isError&&(n=JSON.stringify(n)),e+=4,r==e)return n;let o=[];for(;e<r;)o.push(this.childString(e)),e=this.buffer[e+3];return n+"("+o.join(",")+")"}findChild(e,i,r,s,n){let{buffer:o}=this,a=-1;for(let l=e;l!=i&&!(v6(n,s,o[l+1],o[l+2])&&(a=l,r>0));l=o[l+3]);return a}slice(e,i,r){let s=this.buffer,n=new Uint16Array(i-e),o=0;for(let a=e,l=0;a<i;){n[l++]=s[a++],n[l++]=s[a++]-r;let u=n[l++]=s[a++]-r;n[l++]=s[a++]-e,o=Math.max(o,u)}return new Us(n,o,this.set)}}function v6(t,e,i,r){switch(t){case-2:return i<e;case-1:return r>=e&&i<e;case 0:return i<e&&r>e;case 1:return i<=e&&r>e;case 2:return r>e;case 4:return!0}}function ja(t,e,i,r){for(var s;t.from==t.to||(i<1?t.from>=e:t.from>e)||(i>-1?t.to<=e:t.to<e);){let o=!r&&t instanceof Bi&&t.index<0?null:t.parent;if(!o)return t;t=o}let n=r?0:kt.IgnoreOverlays;if(r)for(let o=t,a=o.parent;a;o=a,a=o.parent)o instanceof Bi&&o.index<0&&((s=a.enter(e,i,n))===null||s===void 0?void 0:s.from)!=o.from&&(t=a);for(;;){let o=t.enter(e,i,n);if(!o)return t;t=o}}class b6{cursor(e=0){return new Zd(this,e)}getChild(e,i=null,r=null){let s=_2(this,e,i,r);return s.length?s[0]:null}getChildren(e,i=null,r=null){return _2(this,e,i,r)}resolve(e,i=0){return ja(this,e,i,!1)}resolveInner(e,i=0){return ja(this,e,i,!0)}matchContext(e){return Jd(this.parent,e)}enterUnfinishedNodesBefore(e){let i=this.childBefore(e),r=this;for(;i;){let s=i.lastChild;if(!s||s.to!=i.to)break;s.type.isError&&s.from==s.to?(r=i,i=s.prevSibling):i=s}return r}get node(){return this}get next(){return this.parent}}class Bi extends b6{constructor(e,i,r,s){super(),this._tree=e,this.from=i,this.index=r,this._parent=s}get type(){return this._tree.type}get name(){return this._tree.type.name}get to(){return this.from+this._tree.length}nextChild(e,i,r,s,n=0){for(let o=this;;){for(let{children:a,positions:l}=o._tree,u=i>0?a.length:-1;e!=u;e+=i){let c=a[e],h=l[e]+o.from,d;if(!(!(n&kt.EnterBracketed&&c instanceof oi&&(d=_a.get(c))&&!d.overlay&&d.bracketed&&r>=h&&r<=h+c.length)&&!v6(s,r,h,h+c.length))){if(c instanceof Us){if(n&kt.ExcludeBuffers)continue;let f=c.findChild(0,c.buffer.length,i,r-h,s);if(f>-1)return new zr(new $D(o,c,e,h),null,f)}else if(n&kt.IncludeAnonymous||!c.type.isAnonymous||w1(c)){let f;if(!(n&kt.IgnoreMounts)&&(f=_a.get(c))&&!f.overlay)return new Bi(f.tree,h,e,o);let m=new Bi(c,h,e,o);return n&kt.IncludeAnonymous||!m.type.isAnonymous?m:m.nextChild(i<0?c.children.length-1:0,i,r,s,n)}}}if(n&kt.IncludeAnonymous||!o.type.isAnonymous||(o.index>=0?e=o.index+i:e=i<0?-1:o._parent._tree.children.length,o=o._parent,!o))return null}}get firstChild(){return this.nextChild(0,1,0,4)}get lastChild(){return this.nextChild(this._tree.children.length-1,-1,0,4)}childAfter(e){return this.nextChild(0,1,e,2)}childBefore(e){return this.nextChild(this._tree.children.length-1,-1,e,-2)}prop(e){return this._tree.prop(e)}enter(e,i,r=0){let s;if(!(r&kt.IgnoreOverlays)&&(s=_a.get(this._tree))&&s.overlay){let n=e-this.from,o=r&kt.EnterBracketed&&s.bracketed;for(let{from:a,to:l}of s.overlay)if((i>0||o?a<=n:a<n)&&(i<0||o?l>=n:l>n))return new Bi(s.tree,s.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,e,i,r)}nextSignificantParent(){let e=this;for(;e.type.isAnonymous&&e._parent;)e=e._parent;return e}get parent(){return this._parent?this._parent.nextSignificantParent():null}get nextSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index+1,1,0,4):null}get prevSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index-1,-1,0,4):null}get tree(){return this._tree}toTree(){return this._tree}toString(){return this._tree.toString()}}function _2(t,e,i,r){let s=t.cursor(),n=[];if(!s.firstChild())return n;if(i!=null){for(let o=!1;!o;)if(o=s.type.is(i),!s.nextSibling())return n}for(;;){if(r!=null&&s.type.is(r))return n;if(s.type.is(e)&&n.push(s.node),!s.nextSibling())return r==null?n:[]}}function Jd(t,e,i=e.length-1){for(let r=t;i>=0;r=r.parent){if(!r)return!1;if(!r.type.isAnonymous){if(e[i]&&e[i]!=r.name)return!1;i--}}return!0}class $D{constructor(e,i,r,s){this.parent=e,this.buffer=i,this.index=r,this.start=s}}class zr extends b6{get name(){return this.type.name}get from(){return this.context.start+this.context.buffer.buffer[this.index+1]}get to(){return this.context.start+this.context.buffer.buffer[this.index+2]}constructor(e,i,r){super(),this.context=e,this._parent=i,this.index=r,this.type=e.buffer.set.types[e.buffer.buffer[r]]}child(e,i,r){let{buffer:s}=this.context,n=s.findChild(this.index+4,s.buffer[this.index+3],e,i-this.context.start,r);return n<0?null:new zr(this.context,this,n)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(e){return this.child(1,e,2)}childBefore(e){return this.child(-1,e,-2)}prop(e){return this.type.prop(e)}enter(e,i,r=0){if(r&kt.ExcludeBuffers)return null;let{buffer:s}=this.context,n=s.findChild(this.index+4,s.buffer[this.index+3],i>0?1:-1,e-this.context.start,i);return n<0?null:new zr(this.context,this,n)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(e){return this._parent?null:this.context.parent.nextChild(this.context.index+e,e,0,4)}get nextSibling(){let{buffer:e}=this.context,i=e.buffer[this.index+3];return i<(this._parent?e.buffer[this._parent.index+3]:e.buffer.length)?new zr(this.context,this._parent,i):this.externalSibling(1)}get prevSibling(){let{buffer:e}=this.context,i=this._parent?this._parent.index+4:0;return this.index==i?this.externalSibling(-1):new zr(this.context,this._parent,e.findChild(i,this.index,-1,0,4))}get tree(){return null}toTree(){let e=[],i=[],{buffer:r}=this.context,s=this.index+4,n=r.buffer[this.index+3];if(n>s){let o=r.buffer[this.index+1];e.push(r.slice(s,n,o)),i.push(0)}return new oi(this.type,e,i,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}}function _6(t){if(!t.length)return null;let e=0,i=t[0];for(let n=1;n<t.length;n++){let o=t[n];(o.from>i.from||o.to<i.to)&&(i=o,e=n)}let r=i instanceof Bi&&i.index<0?null:i.parent,s=t.slice();return r?s[e]=r:s.splice(e,1),new qD(s,i)}class qD{constructor(e,i){this.heads=e,this.node=i}get next(){return _6(this.heads)}}function WD(t,e,i){let r=t.resolveInner(e,i),s=null;for(let n=r instanceof Bi?r:r.context.parent;n;n=n.parent)if(n.index<0){let o=n.parent;(s||(s=[r])).push(o.resolve(e,i)),n=o}else{let o=_a.get(n.tree);if(o&&o.overlay&&o.overlay[0].from<=e&&o.overlay[o.overlay.length-1].to>=e){let a=new Bi(o.tree,o.overlay[0].from+n.from,-1,n);(s||(s=[r])).push(ja(a,e,i,!1))}}return s?_6(s):r}class Zd{get name(){return this.type.name}constructor(e,i=0){if(this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,this.mode=i&~kt.EnterBracketed,e instanceof Bi)this.yieldNode(e);else{this._tree=e.context.parent,this.buffer=e.context;for(let r=e._parent;r;r=r._parent)this.stack.unshift(r.index);this.bufferNode=e,this.yieldBuf(e.index)}}yieldNode(e){return e?(this._tree=e,this.type=e.type,this.from=e.from,this.to=e.to,!0):!1}yieldBuf(e,i){this.index=e;let{start:r,buffer:s}=this.buffer;return this.type=i||s.set.types[s.buffer[e]],this.from=r+s.buffer[e+1],this.to=r+s.buffer[e+2],!0}yield(e){return e?e instanceof Bi?(this.buffer=null,this.yieldNode(e)):(this.buffer=e.context,this.yieldBuf(e.index,e.type)):!1}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(e,i,r){if(!this.buffer)return this.yield(this._tree.nextChild(e<0?this._tree._tree.children.length-1:0,e,i,r,this.mode));let{buffer:s}=this.buffer,n=s.findChild(this.index+4,s.buffer[this.index+3],e,i-this.buffer.start,r);return n<0?!1:(this.stack.push(this.index),this.yieldBuf(n))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(e){return this.enterChild(1,e,2)}childBefore(e){return this.enterChild(-1,e,-2)}enter(e,i,r=this.mode){return this.buffer?r&kt.ExcludeBuffers?!1:this.enterChild(1,e,i):this.yield(this._tree.enter(e,i,r))}parent(){if(!this.buffer)return this.yieldNode(this.mode&kt.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let e=this.mode&kt.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(e)}sibling(e){if(!this.buffer)return this._tree._parent?this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+e,e,0,4,this.mode)):!1;let{buffer:i}=this.buffer,r=this.stack.length-1;if(e<0){let s=r<0?0:this.stack[r]+4;if(this.index!=s)return this.yieldBuf(i.findChild(s,this.index,-1,0,4))}else{let s=i.buffer[this.index+3];if(s<(r<0?i.buffer.length:i.buffer[this.stack[r]+3]))return this.yieldBuf(s)}return r<0?this.yield(this.buffer.parent.nextChild(this.buffer.index+e,e,0,4,this.mode)):!1}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(e){let i,r,{buffer:s}=this;if(s){if(e>0){if(this.index<s.buffer.buffer.length)return!1}else for(let n=0;n<this.index;n++)if(s.buffer.buffer[n+3]<this.index)return!1;({index:i,parent:r}=s)}else({index:i,_parent:r}=this._tree);for(;r;{index:i,_parent:r}=r)if(i>-1)for(let n=i+e,o=e<0?-1:r._tree.children.length;n!=o;n+=e){let a=r._tree.children[n];if(this.mode&kt.IncludeAnonymous||a instanceof Us||!a.type.isAnonymous||w1(a))return!1}return!0}move(e,i){if(i&&this.enterChild(e,0,4))return!0;for(;;){if(this.sibling(e))return!0;if(this.atLastNode(e)||!this.parent())return!1}}next(e=!0){return this.move(1,e)}prev(e=!0){return this.move(-1,e)}moveTo(e,i=0){for(;(this.from==this.to||(i<1?this.from>=e:this.from>e)||(i>-1?this.to<=e:this.to<e))&&this.parent(););for(;this.enterChild(1,e,i););return this}get node(){if(!this.buffer)return this._tree;let e=this.bufferNode,i=null,r=0;if(e&&e.context==this.buffer)e:for(let s=this.index,n=this.stack.length;n>=0;){for(let o=e;o;o=o._parent)if(o.index==s){if(s==this.index)return o;i=o,r=n+1;break e}s=this.stack[--n]}for(let s=r;s<this.stack.length;s++)i=new zr(this.buffer,i,this.stack[s]);return this.bufferNode=new zr(this.buffer,i,this.index)}get tree(){return this.buffer?null:this._tree._tree}iterate(e,i){for(let r=0;;){let s=!1;if(this.type.isAnonymous||e(this)!==!1){if(this.firstChild()){r++;continue}this.type.isAnonymous||(s=!0)}for(;;){if(s&&i&&i(this),s=this.type.isAnonymous,!r)return;if(this.nextSibling())break;this.parent(),r--,s=!0}}}matchContext(e){if(!this.buffer)return Jd(this.node.parent,e);let{buffer:i}=this.buffer,{types:r}=i.set;for(let s=e.length-1,n=this.stack.length-1;s>=0;n--){if(n<0)return Jd(this._tree,e,s);let o=r[i.buffer[this.stack[n]]];if(!o.isAnonymous){if(e[s]&&e[s]!=o.name)return!1;s--}}return!0}}function w1(t){return t.children.some(e=>e instanceof Us||!e.type.isAnonymous||w1(e))}function KD(t){var e;let{buffer:i,nodeSet:r,maxBufferLength:s=zD,reused:n=[],minRepeatType:o=r.types.length}=t,a=Array.isArray(i)?new y1(i,i.length):i,l=r.types,u=0,c=0;function h(R,E,L,q,F,$){let{id:W,start:z,end:j,size:C}=a,O=c,T=u;if(C<0)if(a.next(),C==-1){let X=n[W];L.push(X),q.push(z-R);return}else if(C==-3){u=W;return}else if(C==-4){c=W;return}else throw new RangeError(`Unrecognized record size: ${C}`);let U=l[W],H,re,G=z-R;if(j-z<=s&&(re=_(a.pos-E,F))){let X=new Uint16Array(re.size-re.skip),oe=a.pos-re.size,I=X.length;for(;a.pos>oe;)I=w(re.start,X,I);H=new Us(X,j-re.start,r),G=re.start-R}else{let X=a.pos-C;a.next();let oe=[],I=[],Y=W>=o?W:-1,le=0,te=j;for(;a.pos>X;)Y>=0&&a.id==Y&&a.size>=0?(a.end<=te-s&&(m(oe,I,z,le,a.end,te,Y,O,T),le=oe.length,te=a.end),a.next()):$>2500?d(z,X,oe,I):h(z,X,oe,I,Y,$+1);if(Y>=0&&le>0&&le<oe.length&&m(oe,I,z,le,z,te,Y,O,T),oe.reverse(),I.reverse(),Y>-1&&le>0){let de=f(U,T);H=x1(U,oe,I,0,oe.length,0,j-z,de,de)}else H=v(U,oe,I,j-z,O-j,T)}L.push(H),q.push(G)}function d(R,E,L,q){let F=[],$=0,W=-1;for(;a.pos>E;){let{id:z,start:j,end:C,size:O}=a;if(O>4)a.next();else{if(W>-1&&j<W)break;W<0&&(W=C-s),F.push(z,j,C),$++,a.next()}}if($){let z=new Uint16Array($*4),j=F[F.length-2];for(let C=F.length-3,O=0;C>=0;C-=3)z[O++]=F[C],z[O++]=F[C+1]-j,z[O++]=F[C+2]-j,z[O++]=O;L.push(new Us(z,F[2]-j,r)),q.push(j-R)}}function f(R,E){return(L,q,F)=>{let $=0,W=L.length-1,z,j;if(W>=0&&(z=L[W])instanceof oi){if(!W&&z.type==R&&z.length==F)return z;(j=z.prop(Qe.lookAhead))&&($=q[W]+z.length+j)}return v(R,L,q,F,$,E)}}function m(R,E,L,q,F,$,W,z,j){let C=[],O=[];for(;R.length>q;)C.push(R.pop()),O.push(E.pop()+L-F);R.push(v(r.types[W],C,O,$-F,z-$,j)),E.push(F-L)}function v(R,E,L,q,F,$,W){if($){let z=[Qe.contextHash,$];W=W?[z].concat(W):[z]}if(F>25){let z=[Qe.lookAhead,F];W=W?[z].concat(W):[z]}return new oi(R,E,L,q,W)}function _(R,E){let L=a.fork(),q=0,F=0,$=0,W=L.end-s,z={size:0,start:0,skip:0};e:for(let j=L.pos-R;L.pos>j;){let C=L.size;if(L.id==E&&C>=0){z.size=q,z.start=F,z.skip=$,$+=4,q+=4,L.next();continue}let O=L.pos-C;if(C<0||O<j||L.start<W)break;let T=L.id>=o?4:0,U=L.start;for(L.next();L.pos>O;){if(L.size<0)if(L.size==-3||L.size==-4)T+=4;else break e;else L.id>=o&&(T+=4);L.next()}F=U,q+=C,$+=T}return(E<0||q==R)&&(z.size=q,z.start=F,z.skip=$),z.size>4?z:void 0}function w(R,E,L){let{id:q,start:F,end:$,size:W}=a;if(a.next(),W>=0&&q<o){let z=L;if(W>4){let j=a.pos-(W-4);for(;a.pos>j;)L=w(R,E,L)}E[--L]=z,E[--L]=$-R,E[--L]=F-R,E[--L]=q}else W==-3?u=q:W==-4&&(c=q);return L}let x=[],A=[];for(;a.pos>0;)h(t.start||0,t.bufferStart||0,x,A,-1,0);let D=(e=t.length)!==null&&e!==void 0?e:x.length?A[0]+x[0].length:0;return new oi(l[t.topID],x.reverse(),A.reverse(),D)}const y2=new WeakMap;function _u(t,e){if(!t.isAnonymous||e instanceof Us||e.type!=t)return 1;let i=y2.get(e);if(i==null){i=1;for(let r of e.children){if(r.type!=t||!(r instanceof oi)){i=1;break}i+=_u(t,r)}y2.set(e,i)}return i}function x1(t,e,i,r,s,n,o,a,l){let u=0;for(let m=r;m<s;m++)u+=_u(t,e[m]);let c=Math.ceil(u*1.5/8),h=[],d=[];function f(m,v,_,w,x){for(let A=_;A<w;){let D=A,R=v[A],E=_u(t,m[A]);for(A++;A<w;A++){let L=_u(t,m[A]);if(E+L>=c)break;E+=L}if(A==D+1){if(E>c){let L=m[D];f(L.children,L.positions,0,L.children.length,v[D]+x);continue}h.push(m[D])}else{let L=v[A-1]+m[A-1].length-R;h.push(x1(t,m,v,D,A,R,L,null,l))}d.push(R+x-n)}}return f(e,i,r,s,0),(a||l)(h,d,o)}class BR{constructor(){this.map=new WeakMap}setBuffer(e,i,r){let s=this.map.get(e);s||this.map.set(e,s=new Map),s.set(i,r)}getBuffer(e,i){let r=this.map.get(e);return r&&r.get(i)}set(e,i){e instanceof zr?this.setBuffer(e.context.buffer,e.index,i):e instanceof Bi&&this.map.set(e.tree,i)}get(e){return e instanceof zr?this.getBuffer(e.context.buffer,e.index):e instanceof Bi?this.map.get(e.tree):void 0}cursorSet(e,i){e.buffer?this.setBuffer(e.buffer.buffer,e.index,i):this.map.set(e.tree,i)}cursorGet(e){return e.buffer?this.getBuffer(e.buffer.buffer,e.index):this.map.get(e.tree)}}class kn{constructor(e,i,r,s,n=!1,o=!1){this.from=e,this.to=i,this.tree=r,this.offset=s,this.open=(n?1:0)|(o?2:0)}get openStart(){return(this.open&1)>0}get openEnd(){return(this.open&2)>0}static addTree(e,i=[],r=!1){let s=[new kn(0,e.length,e,0,!1,r)];for(let n of i)n.to>e.length&&s.push(n);return s}static applyChanges(e,i,r=128){if(!i.length)return e;let s=[],n=1,o=e.length?e[0]:null;for(let a=0,l=0,u=0;;a++){let c=a<i.length?i[a]:null,h=c?c.fromA:1e9;if(h-l>=r)for(;o&&o.from<h;){let d=o;if(l>=d.from||h<=d.to||u){let f=Math.max(d.from,l)-u,m=Math.min(d.to,h)-u;d=f>=m?null:new kn(f,m,d.tree,d.offset+u,a>0,!!c)}if(d&&s.push(d),o.to>h)break;o=n<e.length?e[n++]:null}if(!c)break;l=c.toA,u=c.toA-c.toB}return s}}class VD{startParse(e,i,r){return typeof e=="string"&&(e=new UD(e)),r=r?r.length?r.map(s=>new Hc(s.from,s.to)):[new Hc(0,0)]:[new Hc(0,e.length)],this.createParse(e,i||[],r)}parse(e,i,r){let s=this.startParse(e,i,r);for(;;){let n=s.advance();if(n)return n}}}class UD{constructor(e){this.string=e}get length(){return this.string.length}chunk(e){return this.string.slice(e)}get lineChunks(){return!1}read(e,i){return this.string.slice(e,i)}}new Qe({perNode:!0});let GD=0;class er{constructor(e,i,r,s){this.name=e,this.set=i,this.base=r,this.modified=s,this.id=GD++}toString(){let{name:e}=this;for(let i of this.modified)i.name&&(e=`${i.name}(${e})`);return e}static define(e,i){let r=typeof e=="string"?e:"?";if(e instanceof er&&(i=e),i!=null&&i.base)throw new Error("Can not derive from a modified tag");let s=new er(r,[],null,[]);if(s.set.push(s),i)for(let n of i.set)s.set.push(n);return s}static defineModifier(e){let i=new Ku(e);return r=>r.modified.indexOf(i)>-1?r:Ku.get(r.base||r,r.modified.concat(i).sort((s,n)=>s.id-n.id))}}let YD=0;class Ku{constructor(e){this.name=e,this.instances=[],this.id=YD++}static get(e,i){if(!i.length)return e;let r=i[0].instances.find(a=>a.base==e&&XD(i,a.modified));if(r)return r;let s=[],n=new er(e.name,s,e,i);for(let a of i)a.instances.push(n);let o=JD(i);for(let a of e.set)if(!a.modified.length)for(let l of o)s.push(Ku.get(a,l));return n}}function XD(t,e){return t.length==e.length&&t.every((i,r)=>i==e[r])}function JD(t){let e=[[]];for(let i=0;i<t.length;i++)for(let r=0,s=e.length;r<s;r++)e.push(e[r].concat(t[i]));return e.sort((i,r)=>r.length-i.length)}function ZD(t){let e=Object.create(null);for(let i in t){let r=t[i];Array.isArray(r)||(r=[r]);for(let s of i.split(" "))if(s){let n=[],o=2,a=s;for(let h=0;;){if(a=="..."&&h>0&&h+3==s.length){o=1;break}let d=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(a);if(!d)throw new RangeError("Invalid path: "+s);if(n.push(d[0]=="*"?"":d[0][0]=='"'?JSON.parse(d[0]):d[0]),h+=d[0].length,h==s.length)break;let f=s[h++];if(h==s.length&&f=="!"){o=0;break}if(f!="/")throw new RangeError("Invalid path: "+s);a=s.slice(h)}let l=n.length-1,u=n[l];if(!u)throw new RangeError("Invalid path: "+s);let c=new Ha(r,o,l>0?n.slice(0,l):null);e[u]=c.sort(e[u])}}return y6.add(e)}const y6=new Qe({combine(t,e){let i,r,s;for(;t||e;){if(!t||e&&t.depth>=e.depth?(s=e,e=e.next):(s=t,t=t.next),i&&i.mode==s.mode&&!s.context&&!i.context)continue;let n=new Ha(s.tags,s.mode,s.context);i?i.next=n:r=n,i=n}return r}});class Ha{constructor(e,i,r,s){this.tags=e,this.mode=i,this.context=r,this.next=s}get opaque(){return this.mode==0}get inherit(){return this.mode==1}sort(e){return!e||e.depth<this.depth?(this.next=e,this):(e.next=this.sort(e.next),e)}get depth(){return this.context?this.context.length:0}}Ha.empty=new Ha([],2,null);function w6(t,e){let i=Object.create(null);for(let n of t)if(!Array.isArray(n.tag))i[n.tag.id]=n.class;else for(let o of n.tag)i[o.id]=n.class;let{scope:r,all:s=null}=e||{};return{style:n=>{let o=s;for(let a of n)for(let l of a.set){let u=i[l.id];if(u){o=o?o+" "+u:u;break}}return o},scope:r}}function QD(t,e){let i=null;for(let r of t){let s=r.style(e);s&&(i=i?i+" "+s:s)}return i}function x6(t,e,i,r=0,s=t.length){let n=new eM(r,Array.isArray(e)?e:[e],i);n.highlightRange(t.cursor(),r,s,"",n.highlighters),n.flush(s)}class eM{constructor(e,i,r){this.at=e,this.highlighters=i,this.span=r,this.class=""}startSpan(e,i){i!=this.class&&(this.flush(e),e>this.at&&(this.at=e),this.class=i)}flush(e){e>this.at&&this.class&&this.span(this.at,e,this.class)}highlightRange(e,i,r,s,n){let{type:o,from:a,to:l}=e;if(a>=r||l<=i)return;o.isTop&&(n=this.highlighters.filter(f=>!f.scope||f.scope(o)));let u=s,c=tM(e)||Ha.empty,h=QD(n,c.tags);if(h&&(u&&(u+=" "),u+=h,c.mode==1&&(s+=(s?" ":"")+h)),this.startSpan(Math.max(i,a),u),c.opaque)return;let d=e.tree&&e.tree.prop(Qe.mounted);if(d&&d.overlay){let f=e.node.enter(d.overlay[0].from+a,1),m=this.highlighters.filter(_=>!_.scope||_.scope(d.tree.type)),v=e.firstChild();for(let _=0,w=a;;_++){let x=_<d.overlay.length?d.overlay[_]:null,A=x?x.from+a:l,D=Math.max(i,w),R=Math.min(r,A);if(D<R&&v)for(;e.from<R&&(this.highlightRange(e,D,R,s,n),this.startSpan(Math.min(R,e.to),u),!(e.to>=A||!e.nextSibling())););if(!x||A>r)break;w=x.to+a,w>i&&(this.highlightRange(f.cursor(),Math.max(i,x.from+a),Math.min(r,w),"",m),this.startSpan(Math.min(r,w),u))}v&&e.parent()}else if(e.firstChild()){d&&(s="");do if(!(e.to<=i)){if(e.from>=r)break;this.highlightRange(e,i,r,s,n),this.startSpan(Math.min(r,e.to),u)}while(e.nextSibling());e.parent()}}}function tM(t){let e=t.type.prop(y6);for(;e&&e.context&&!t.matchContext(e.context);)e=e.next;return e||null}const he=er.define,Wl=he(),Ms=he(),w2=he(Ms),x2=he(Ms),Ts=he(),Kl=he(Ts),$c=he(Ts),Er=he(),cn=he(Er),Sr=he(),kr=he(),Qd=he(),Vo=he(Qd),Vl=he(),be={comment:Wl,lineComment:he(Wl),blockComment:he(Wl),docComment:he(Wl),name:Ms,variableName:he(Ms),typeName:w2,tagName:he(w2),propertyName:x2,attributeName:he(x2),className:he(Ms),labelName:he(Ms),namespace:he(Ms),macroName:he(Ms),literal:Ts,string:Kl,docString:he(Kl),character:he(Kl),attributeValue:he(Kl),number:$c,integer:he($c),float:he($c),bool:he(Ts),regexp:he(Ts),escape:he(Ts),color:he(Ts),url:he(Ts),keyword:Sr,self:he(Sr),null:he(Sr),atom:he(Sr),unit:he(Sr),modifier:he(Sr),operatorKeyword:he(Sr),controlKeyword:he(Sr),definitionKeyword:he(Sr),moduleKeyword:he(Sr),operator:kr,derefOperator:he(kr),arithmeticOperator:he(kr),logicOperator:he(kr),bitwiseOperator:he(kr),compareOperator:he(kr),updateOperator:he(kr),definitionOperator:he(kr),typeOperator:he(kr),controlOperator:he(kr),punctuation:Qd,separator:he(Qd),bracket:Vo,angleBracket:he(Vo),squareBracket:he(Vo),paren:he(Vo),brace:he(Vo),content:Er,heading:cn,heading1:he(cn),heading2:he(cn),heading3:he(cn),heading4:he(cn),heading5:he(cn),heading6:he(cn),contentSeparator:he(Er),list:he(Er),quote:he(Er),emphasis:he(Er),strong:he(Er),link:he(Er),monospace:he(Er),strikethrough:he(Er),inserted:he(),deleted:he(),changed:he(),invalid:he(),meta:Vl,documentMeta:he(Vl),annotation:he(Vl),processingInstruction:he(Vl),definition:er.defineModifier("definition"),constant:er.defineModifier("constant"),function:er.defineModifier("function"),standard:er.defineModifier("standard"),local:er.defineModifier("local"),special:er.defineModifier("special")};for(let t in be){let e=be[t];e instanceof er&&(e.name=t)}w6([{tag:be.link,class:"tok-link"},{tag:be.heading,class:"tok-heading"},{tag:be.emphasis,class:"tok-emphasis"},{tag:be.strong,class:"tok-strong"},{tag:be.keyword,class:"tok-keyword"},{tag:be.atom,class:"tok-atom"},{tag:be.bool,class:"tok-bool"},{tag:be.url,class:"tok-url"},{tag:be.labelName,class:"tok-labelName"},{tag:be.inserted,class:"tok-inserted"},{tag:be.deleted,class:"tok-deleted"},{tag:be.literal,class:"tok-literal"},{tag:be.string,class:"tok-string"},{tag:be.number,class:"tok-number"},{tag:[be.regexp,be.escape,be.special(be.string)],class:"tok-string2"},{tag:be.variableName,class:"tok-variableName"},{tag:be.local(be.variableName),class:"tok-variableName tok-local"},{tag:be.definition(be.variableName),class:"tok-variableName tok-definition"},{tag:be.special(be.variableName),class:"tok-variableName2"},{tag:be.definition(be.propertyName),class:"tok-propertyName tok-definition"},{tag:be.typeName,class:"tok-typeName"},{tag:be.namespace,class:"tok-namespace"},{tag:be.className,class:"tok-className"},{tag:be.macroName,class:"tok-macroName"},{tag:be.propertyName,class:"tok-propertyName"},{tag:be.operator,class:"tok-operator"},{tag:be.comment,class:"tok-comment"},{tag:be.meta,class:"tok-meta"},{tag:be.invalid,class:"tok-invalid"},{tag:be.punctuation,class:"tok-punctuation"}]);var qc;const to=new Qe;function iM(t){return we.define({combine:t?e=>e.concat(t):void 0})}const rM=new Qe;class hr{constructor(e,i,r=[],s=""){this.data=e,this.name=s,Ke.prototype.hasOwnProperty("tree")||Object.defineProperty(Ke.prototype,"tree",{get(){return $a(this)}}),this.parser=i,this.extension=[Rn.of(this),Ke.languageData.of((n,o,a)=>{let l=S2(n,o,a),u=l.type.prop(to);if(!u)return[];let c=n.facet(u),h=l.type.prop(rM);if(h){let d=l.resolve(o-l.from,a);for(let f of h)if(f.test(d,n)){let m=n.facet(f.facet);return f.type=="replace"?m:m.concat(c)}}return c})].concat(r)}isActiveAt(e,i,r=-1){return S2(e,i,r).type.prop(to)==this.data}findRegions(e){let i=e.facet(Rn);if((i==null?void 0:i.data)==this.data)return[{from:0,to:e.doc.length}];if(!i||!i.allowsNesting)return[];let r=[],s=(n,o)=>{if(n.prop(to)==this.data){r.push({from:o,to:o+n.length});return}let a=n.prop(Qe.mounted);if(a){if(a.tree.prop(to)==this.data){if(a.overlay)for(let l of a.overlay)r.push({from:l.from+o,to:l.to+o});else r.push({from:o,to:o+n.length});return}else if(a.overlay){let l=r.length;if(s(a.tree,a.overlay[0].from+o),r.length>l)return}}for(let l=0;l<n.children.length;l++){let u=n.children[l];u instanceof oi&&s(u,n.positions[l]+o)}};return s($a(e),0),r}get allowsNesting(){return!0}}hr.setState=at.define();function S2(t,e,i){let r=t.facet(Rn),s=$a(t).topNode;if(!r||r.allowsNesting)for(let n=s;n;n=n.enter(e,i,kt.ExcludeBuffers|kt.EnterBracketed))n.type.isTop&&(s=n);return s}class ef extends hr{constructor(e,i,r){super(e,i,[],r),this.parser=i}static define(e){let i=iM(e.languageData);return new ef(i,e.parser.configure({props:[to.add(r=>r.isTop?i:void 0)]}),e.name)}configure(e,i){return new ef(this.data,this.parser.configure(e),i||this.name)}get allowsNesting(){return this.parser.hasWrappers()}}function $a(t){let e=t.field(hr.state,!1);return e?e.tree:oi.empty}class sM{constructor(e){this.doc=e,this.cursorPos=0,this.string="",this.cursor=e.iter()}get length(){return this.doc.length}syncTo(e){return this.string=this.cursor.next(e-this.cursorPos).value,this.cursorPos=e+this.string.length,this.cursorPos-this.string.length}chunk(e){return this.syncTo(e),this.string}get lineChunks(){return!0}read(e,i){let r=this.cursorPos-this.string.length;return e<r||i>=this.cursorPos?this.doc.sliceString(e,i):this.string.slice(e-r,i-r)}}let Uo=null;class Vu{constructor(e,i,r=[],s,n,o,a,l){this.parser=e,this.state=i,this.fragments=r,this.tree=s,this.treeLen=n,this.viewport=o,this.skipped=a,this.scheduleOn=l,this.parse=null,this.tempSkipped=[]}static create(e,i,r){return new Vu(e,i,[],oi.empty,0,r,[],null)}startParse(){return this.parser.startParse(new sM(this.state.doc),this.fragments)}work(e,i){return i!=null&&i>=this.state.doc.length&&(i=void 0),this.tree!=oi.empty&&this.isDone(i??this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var r;if(typeof e=="number"){let s=Date.now()+e;e=()=>Date.now()>s}for(this.parse||(this.parse=this.startParse()),i!=null&&(this.parse.stoppedAt==null||this.parse.stoppedAt>i)&&i<this.state.doc.length&&this.parse.stopAt(i);;){let s=this.parse.advance();if(s)if(this.fragments=this.withoutTempSkipped(kn.addTree(s,this.fragments,this.parse.stoppedAt!=null)),this.treeLen=(r=this.parse.stoppedAt)!==null&&r!==void 0?r:this.state.doc.length,this.tree=s,this.parse=null,this.treeLen<(i??this.state.doc.length))this.parse=this.startParse();else return!0;if(e())return!1}})}takeTree(){let e,i;this.parse&&(e=this.parse.parsedPos)>=this.treeLen&&((this.parse.stoppedAt==null||this.parse.stoppedAt>e)&&this.parse.stopAt(e),this.withContext(()=>{for(;!(i=this.parse.advance()););}),this.treeLen=e,this.tree=i,this.fragments=this.withoutTempSkipped(kn.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(e){let i=Uo;Uo=this;try{return e()}finally{Uo=i}}withoutTempSkipped(e){for(let i;i=this.tempSkipped.pop();)e=k2(e,i.from,i.to);return e}changes(e,i){let{fragments:r,tree:s,treeLen:n,viewport:o,skipped:a}=this;if(this.takeTree(),!e.empty){let l=[];if(e.iterChangedRanges((u,c,h,d)=>l.push({fromA:u,toA:c,fromB:h,toB:d})),r=kn.applyChanges(r,l),s=oi.empty,n=0,o={from:e.mapPos(o.from,-1),to:e.mapPos(o.to,1)},this.skipped.length){a=[];for(let u of this.skipped){let c=e.mapPos(u.from,1),h=e.mapPos(u.to,-1);c<h&&a.push({from:c,to:h})}}}return new Vu(this.parser,i,r,s,n,o,a,this.scheduleOn)}updateViewport(e){if(this.viewport.from==e.from&&this.viewport.to==e.to)return!1;this.viewport=e;let i=this.skipped.length;for(let r=0;r<this.skipped.length;r++){let{from:s,to:n}=this.skipped[r];s<e.to&&n>e.from&&(this.fragments=k2(this.fragments,s,n),this.skipped.splice(r--,1))}return this.skipped.length>=i?!1:(this.reset(),!0)}reset(){this.parse&&(this.takeTree(),this.parse=null)}skipUntilInView(e,i){this.skipped.push({from:e,to:i})}static getSkippingParser(e){return new class extends VD{createParse(i,r,s){let n=s[0].from,o=s[s.length-1].to;return{parsedPos:n,advance(){let l=Uo;if(l){for(let u of s)l.tempSkipped.push(u);e&&(l.scheduleOn=l.scheduleOn?Promise.all([l.scheduleOn,e]):e)}return this.parsedPos=o,new oi(Ki.none,[],[],o-n)},stoppedAt:null,stopAt(){}}}}}isDone(e){e=Math.min(e,this.state.doc.length);let i=this.fragments;return this.treeLen>=e&&i.length&&i[0].from==0&&i[0].to>=e}static get(){return Uo}}function k2(t,e,i){return kn.applyChanges(t,[{fromA:e,toA:i,fromB:e,toB:i}])}class So{constructor(e){this.context=e,this.tree=e.tree}apply(e){if(!e.docChanged&&this.tree==this.context.tree)return this;let i=this.context.changes(e.changes,e.state),r=this.context.treeLen==e.startState.doc.length?void 0:Math.max(e.changes.mapPos(this.context.treeLen),i.viewport.to);return i.work(20,r)||i.takeTree(),new So(i)}static init(e){let i=Math.min(3e3,e.doc.length),r=Vu.create(e.facet(Rn).parser,e,{from:0,to:i});return r.work(20,i)||r.takeTree(),new So(r)}}hr.state=or.define({create:So.init,update(t,e){for(let i of e.effects)if(i.is(hr.setState))return i.value;return e.startState.facet(Rn)!=e.state.facet(Rn)?So.init(e.state):t.apply(e)}});let S6=t=>{let e=setTimeout(()=>t(),500);return()=>clearTimeout(e)};typeof requestIdleCallback<"u"&&(S6=t=>{let e=-1,i=setTimeout(()=>{e=requestIdleCallback(t,{timeout:400})},100);return()=>e<0?clearTimeout(i):cancelIdleCallback(e)});const Wc=typeof navigator<"u"&&(!((qc=navigator.scheduling)===null||qc===void 0)&&qc.isInputPending)?()=>navigator.scheduling.isInputPending():null,nM=qr.fromClass(class{constructor(e){this.view=e,this.working=null,this.workScheduled=0,this.chunkEnd=-1,this.chunkBudget=-1,this.work=this.work.bind(this),this.scheduleWork()}update(e){let i=this.view.state.field(hr.state).context;(i.updateViewport(e.view.viewport)||this.view.viewport.to>i.treeLen)&&this.scheduleWork(),(e.docChanged||e.selectionSet)&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(i)}scheduleWork(){if(this.working)return;let{state:e}=this.view,i=e.field(hr.state);(i.tree!=i.context.tree||!i.context.isDone(e.doc.length))&&(this.working=S6(this.work))}work(e){this.working=null;let i=Date.now();if(this.chunkEnd<i&&(this.chunkEnd<0||this.view.hasFocus)&&(this.chunkEnd=i+3e4,this.chunkBudget=3e3),this.chunkBudget<=0)return;let{state:r,viewport:{to:s}}=this.view,n=r.field(hr.state);if(n.tree==n.context.tree&&n.context.isDone(s+1e5))return;let o=Date.now()+Math.min(this.chunkBudget,100,e&&!Wc?Math.max(25,e.timeRemaining()-5):1e9),a=n.context.treeLen<s&&r.doc.length>s+1e3,l=n.context.work(()=>Wc&&Wc()||Date.now()>o,s+(a?0:1e5));this.chunkBudget-=Date.now()-i,(l||this.chunkBudget<=0)&&(n.context.takeTree(),this.view.dispatch({effects:hr.setState.of(new So(n.context))})),this.chunkBudget>0&&!(l&&!a)&&this.scheduleWork(),this.checkAsyncSchedule(n.context)}checkAsyncSchedule(e){e.scheduleOn&&(this.workScheduled++,e.scheduleOn.then(()=>this.scheduleWork()).catch(i=>Ir(this.view.state,i)).then(()=>this.workScheduled--),e.scheduleOn=null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),Rn=we.define({combine(t){return t.length?t[0]:null},enables:t=>[hr.state,nM,xe.contentAttributes.compute([t],e=>{let i=e.facet(t);return i&&i.name?{"data-language":i.name}:{}})]});class NR{constructor(e,i=[]){this.language=e,this.support=i,this.extension=[e,i]}}const LR=we.define({combine:t=>{if(!t.length)return" ";let e=t[0];if(!e||/\S/.test(e)||Array.from(e).some(i=>i!=e[0]))throw new Error("Invalid indent unit: "+JSON.stringify(t[0]));return e}}),OR=new Qe;function oM(t){let e=t.node,i=e.childAfter(e.from),r=e.lastChild;if(!i)return null;let s=t.options.simulateBreak,n=t.state.doc.lineAt(i.from),o=s==null||s<=n.from?n.to:Math.min(n.to,s);for(let a=i.to;;){let l=e.childAfter(a);if(!l||l==r)return null;if(!l.type.isSkipped){if(l.from>=o)return null;let u=/^ */.exec(n.text.slice(i.to-n.from))[0].length;return{from:i.from,to:i.to+u}}a=l.to}}function PR({closing:t,align:e=!0,units:i=1}){return r=>aM(r,e,i,t)}function aM(t,e,i,r,s){let n=t.textAfter,o=n.match(/^\s*/)[0].length,a=r&&n.slice(o,o+r.length)==r||s==t.pos+o,l=e?oM(t):null;return l?a?t.column(l.from):t.column(l.to):t.baseIndent+(a?0:t.unit*i)}const FR=t=>t.baseIndent;function IR({except:t,units:e=1}={}){return i=>{let r=t&&t.test(i.textAfter);return i.baseIndent+(r?0:e*i.unit)}}const zR=new Qe;function jR(t){let e=t.firstChild,i=t.lastChild;return e&&e.to<i.from?{from:e.to,to:i.type.isError?t.to:i.from}:null}class D0{constructor(e,i){this.specs=e;let r;function s(a){let l=us.newName();return(r||(r=Object.create(null)))["."+l]=a,l}const n=typeof i.all=="string"?i.all:i.all?s(i.all):void 0,o=i.scope;this.scope=o instanceof hr?a=>a.prop(to)==o.data:o?a=>a==o:void 0,this.style=w6(e.map(a=>({tag:a.tag,class:a.class||s(Object.assign({},a,{tag:null}))})),{all:n}).style,this.module=r?new us(r):null,this.themeType=i.themeType}static define(e,i){return new D0(e,i||{})}}const tf=we.define(),lM=we.define({combine(t){return t.length?[t[0]]:null}});function yu(t){let e=t.facet(tf);return e.length?e:t.facet(lM)}function uM(t,e){let i=[dM],r;return t instanceof D0&&(t.module&&i.push(xe.styleModule.of(t.module)),r=t.themeType),r?i.push(tf.computeN([xe.darkTheme],s=>s.facet(xe.darkTheme)==(r=="dark")?[t]:[])):i.push(tf.of(t)),i}function cM(t,e,i){let r=yu(t),s=null;if(r){for(let n of r)if(!n.scope||i){let o=n.style(e);o&&(s=s?s+" "+o:o)}}return s}class hM{constructor(e){this.markCache=Object.create(null),this.tree=$a(e.state),this.decorations=this.buildDeco(e,yu(e.state)),this.decoratedTo=e.viewport.to}update(e){let i=$a(e.state),r=yu(e.state),s=r!=yu(e.startState),{viewport:n}=e.view,o=e.changes.mapPos(this.decoratedTo,1);i.length<n.to&&!s&&i.type==this.tree.type&&o>=n.to?(this.decorations=this.decorations.map(e.changes),this.decoratedTo=o):(i!=this.tree||e.viewportChanged||s)&&(this.tree=i,this.decorations=this.buildDeco(e.view,r),this.decoratedTo=n.to)}buildDeco(e,i){if(!i||!this.tree.length)return qe.none;let r=new fr;for(let{from:s,to:n}of e.visibleRanges)x6(this.tree,i,(o,a,l)=>{r.add(o,a,this.markCache[l]||(this.markCache[l]=qe.mark({class:l})))},s,n);return r.finish()}}const dM=Fn.high(qr.fromClass(hM,{decorations:t=>t.decorations})),fM=Object.create(null),C2=[Ki.none],A2=[],E2=Object.create(null),pM=Object.create(null);for(let[t,e]of[["variable","variableName"],["variable-2","variableName.special"],["string-2","string.special"],["def","variableName.definition"],["tag","tagName"],["attribute","attributeName"],["type","typeName"],["builtin","variableName.standard"],["qualifier","modifier"],["error","invalid"],["header","heading"],["property","propertyName"]])pM[t]=mM(fM,e);function Kc(t,e){A2.indexOf(t)>-1||(A2.push(t),console.warn(e))}function mM(t,e){let i=[];for(let a of e.split(" ")){let l=[];for(let u of a.split(".")){let c=t[u]||be[u];c?typeof c=="function"?l.length?l=l.map(c):Kc(u,`Modifier ${u} used at start of tag`):l.length?Kc(u,`Tag ${u} used as modifier`):l=Array.isArray(c)?c:[c]:Kc(u,`Unknown highlighting tag ${u}`)}for(let u of l)i.push(u)}if(!i.length)return 0;let r=e.replace(/ /g,"_"),s=r+" "+i.map(a=>a.id),n=E2[s];if(n)return n.id;let o=E2[s]=Ki.define({id:C2.length,name:r,props:[ZD({[r]:i})]});return C2.push(o),o.id}Lt.RTL,Lt.LTR;class Bt{constructor(e,i,r,s){this.fromA=e,this.toA=i,this.fromB=r,this.toB=s}offset(e,i=e){return new Bt(this.fromA+e,this.toA+e,this.fromB+i,this.toB+i)}}function Nn(t,e,i,r,s,n){if(t==r)return[];let o=k1(t,e,i,r,s,n),a=C1(t,e+o,i,r,s+o,n);e+=o,i-=a,s+=o,n-=a;let l=i-e,u=n-s;if(!l||!u)return[new Bt(e,i,s,n)];if(l>u){let h=t.slice(e,i).indexOf(r.slice(s,n));if(h>-1)return[new Bt(e,e+h,s,s),new Bt(e+h+u,i,n,n)]}else if(u>l){let h=r.slice(s,n).indexOf(t.slice(e,i));if(h>-1)return[new Bt(e,e,s,s+h),new Bt(i,i,s+h+l,n)]}if(l==1||u==1)return[new Bt(e,i,s,n)];let c=A6(t,e,i,r,s,n);if(c){let[h,d,f]=c;return Nn(t,e,h,r,s,d).concat(Nn(t,h+f,i,r,d+f,n))}return gM(t,e,i,r,s,n)}let na=1e9,oa=0,S1=!1;function gM(t,e,i,r,s,n){let o=i-e,a=n-s;if(na<1e9&&Math.min(o,a)>na*16||oa>0&&Date.now()>oa)return Math.min(o,a)>na*64?[new Bt(e,i,s,n)]:D2(t,e,i,r,s,n);let l=Math.ceil((o+a)/2);Vc.reset(l),Uc.reset(l);let u=(f,m)=>t.charCodeAt(e+f)==r.charCodeAt(s+m),c=(f,m)=>t.charCodeAt(i-f-1)==r.charCodeAt(n-m-1),h=(o-a)%2!=0?Uc:null,d=h?null:Vc;for(let f=0;f<l;f++){if(f>na||oa>0&&!(f&63)&&Date.now()>oa)return D2(t,e,i,r,s,n);let m=Vc.advance(f,o,a,l,h,!1,u)||Uc.advance(f,o,a,l,d,!0,c);if(m)return vM(t,e,i,e+m[0],r,s,n,s+m[1])}return[new Bt(e,i,s,n)]}class k6{constructor(){this.vec=[]}reset(e){this.len=e<<1;for(let i=0;i<this.len;i++)this.vec[i]=-1;this.vec[e+1]=0,this.start=this.end=0}advance(e,i,r,s,n,o,a){for(let l=-e+this.start;l<=e-this.end;l+=2){let u=s+l,c=l==-e||l!=e&&this.vec[u-1]<this.vec[u+1]?this.vec[u+1]:this.vec[u-1]+1,h=c-l;for(;c<i&&h<r&&a(c,h);)c++,h++;if(this.vec[u]=c,c>i)this.end+=2;else if(h>r)this.start+=2;else if(n){let d=s+(i-r)-l;if(d>=0&&d<this.len&&n.vec[d]!=-1)if(o){let f=n.vec[d];if(f>=i-c)return[f,s+f-d]}else{let f=i-n.vec[d];if(c>=f)return[c,h]}}}return null}}const Vc=new k6,Uc=new k6;function vM(t,e,i,r,s,n,o,a){let l=!1;return!ko(t,r)&&++r==i&&(l=!0),!ko(s,a)&&++a==o&&(l=!0),l?[new Bt(e,i,n,o)]:Nn(t,e,r,s,n,a).concat(Nn(t,r,i,s,a,o))}function C6(t,e){let i=1,r=Math.min(t,e);for(;i<r;)i=i<<1;return i}function k1(t,e,i,r,s,n){if(e==i||e==n||t.charCodeAt(e)!=r.charCodeAt(s))return 0;let o=C6(i-e,n-s);for(let a=e,l=s;;){let u=a+o,c=l+o;if(u>i||c>n||t.slice(a,u)!=r.slice(l,c)){if(o==1)return a-e-(ko(t,a)?0:1);o=o>>1}else{if(u==i||c==n)return u-e;a=u,l=c}}}function C1(t,e,i,r,s,n){if(e==i||s==n||t.charCodeAt(i-1)!=r.charCodeAt(n-1))return 0;let o=C6(i-e,n-s);for(let a=i,l=n;;){let u=a-o,c=l-o;if(u<e||c<s||t.slice(u,a)!=r.slice(c,l)){if(o==1)return i-a-(ko(t,a)?0:1);o=o>>1}else{if(u==e||c==s)return i-u;a=u,l=c}}}function rf(t,e,i,r,s,n,o,a){let l=r.slice(s,n),u=null;for(;;){if(u||o<a)return u;for(let c=e+o;;){ko(t,c)||c++;let h=c+o;if(ko(t,h)||(h+=h==c+1?1:-1),h>=i)break;let d=t.slice(c,h),f=-1;for(;(f=l.indexOf(d,f+1))!=-1;){let m=k1(t,h,i,r,s+f+d.length,n),v=C1(t,e,c,r,s,s+f),_=d.length+m+v;(!u||u[2]<_)&&(u=[c-v,s+f-v,_])}c=h}if(a<0)return u;o=o>>1}}function A6(t,e,i,r,s,n){let o=i-e,a=n-s;if(o<a){let l=A6(r,s,n,t,e,i);return l&&[l[1],l[0],l[2]]}return o<4||a*2<o?null:rf(t,e,i,r,s,n,Math.floor(o/4),-1)}function D2(t,e,i,r,s,n){S1=!0;let o=i-e,a=n-s,l;if(o<a){let d=rf(r,s,n,t,e,i,Math.floor(o/6),50);l=d&&[d[1],d[0],d[2]]}else l=rf(t,e,i,r,s,n,Math.floor(a/6),50);if(!l)return[new Bt(e,i,s,n)];let[u,c,h]=l;return Nn(t,e,u,r,s,c).concat(Nn(t,u+h,i,r,c+h,n))}function E6(t,e){for(let i=1;i<t.length;i++){let r=t[i-1],s=t[i];r.toA>s.fromA-e&&r.toB>s.fromB-e&&(t[i-1]=new Bt(r.fromA,s.toA,r.fromB,s.toB),t.splice(i--,1))}}function bM(t,e,i){for(;;){E6(i,1);let r=!1;for(let s=0;s<i.length;s++){let n=i[s],o,a;(o=k1(t,n.fromA,n.toA,e,n.fromB,n.toB))&&(n=i[s]=new Bt(n.fromA+o,n.toA,n.fromB+o,n.toB)),(a=C1(t,n.fromA,n.toA,e,n.fromB,n.toB))&&(n=i[s]=new Bt(n.fromA,n.toA-a,n.fromB,n.toB-a));let l=n.toA-n.fromA,u=n.toB-n.fromB;if(l&&u)continue;let c=n.fromA-(s?i[s-1].toA:0),h=(s<i.length-1?i[s+1].fromA:t.length)-n.toA;if(!c||!h)continue;let d=l?t.slice(n.fromA,n.toA):e.slice(n.fromB,n.toB);c<=d.length&&t.slice(n.fromA-c,n.fromA)==d.slice(d.length-c)?(i[s]=new Bt(n.fromA-c,n.toA-c,n.fromB-c,n.toB-c),r=!0):h<=d.length&&t.slice(n.toA,n.toA+h)==d.slice(0,h)&&(i[s]=new Bt(n.fromA+h,n.toA+h,n.fromB+h,n.toB+h),r=!0)}if(!r)break}return i}function _M(t,e,i){for(let r=0,s=0;s<t.length;s++){let n=t[s],o=n.toA-n.fromA,a=n.toB-n.fromB;if(o&&a||o>3||a>3){let l=s==t.length-1?e.length:t[s+1].fromA,u=n.fromA-r,c=l-n.toA,h=T2(e,n.fromA,u),d=M2(e,n.toA,c),f=n.fromA-h,m=d-n.toA;if((!o||!a)&&f&&m){let v=Math.max(o,a),[_,w,x]=o?[e,n.fromA,n.toA]:[i,n.fromB,n.toB];v>f&&e.slice(h,n.fromA)==_.slice(x-f,x)?(n=t[s]=new Bt(h,h+o,n.fromB-f,n.toB-f),h=n.fromA,d=M2(e,n.toA,l-n.toA)):v>m&&e.slice(n.toA,d)==_.slice(w,w+m)&&(n=t[s]=new Bt(d-o,d,n.fromB+m,n.toB+m),d=n.toA,h=T2(e,n.fromA,n.fromA-r)),f=n.fromA-h,m=d-n.toA}if(f||m)n=t[s]=new Bt(n.fromA-f,n.toA+m,n.fromB-f,n.toB+m);else if(o){if(!a){let v=R2(e,n.fromA,n.toA),_,w=v<0?-1:B2(e,n.toA,n.fromA);v>-1&&(_=v-n.fromA)<=c&&e.slice(n.fromA,v)==e.slice(n.toA,n.toA+_)?n=t[s]=n.offset(_):w>-1&&(_=n.toA-w)<=u&&e.slice(n.fromA-_,n.fromA)==e.slice(w,n.toA)&&(n=t[s]=n.offset(-_))}}else{let v=R2(i,n.fromB,n.toB),_,w=v<0?-1:B2(i,n.toB,n.fromB);v>-1&&(_=v-n.fromB)<=c&&i.slice(n.fromB,v)==i.slice(n.toB,n.toB+_)?n=t[s]=n.offset(_):w>-1&&(_=n.toB-w)<=u&&i.slice(n.fromB-_,n.fromB)==i.slice(w,n.toB)&&(n=t[s]=n.offset(-_))}}r=n.toA}return E6(t,3),t}let Cn;try{Cn=new RegExp("[\\p{Alphabetic}\\p{Number}]","u")}catch{}function D6(t){return t>48&&t<58||t>64&&t<91||t>96&&t<123}function M6(t,e){if(e==t.length)return 0;let i=t.charCodeAt(e);return i<192?D6(i)?1:0:Cn?!R6(i)||e==t.length-1?Cn.test(String.fromCharCode(i))?1:0:Cn.test(t.slice(e,e+2))?2:0:0}function T6(t,e){if(!e)return 0;let i=t.charCodeAt(e-1);return i<192?D6(i)?1:0:Cn?!N6(i)||e==1?Cn.test(String.fromCharCode(i))?1:0:Cn.test(t.slice(e-2,e))?2:0:0}const B6=8;function M2(t,e,i){if(e==t.length||!T6(t,e))return e;for(let r=e,s=e+i,n=0;n<B6;n++){let o=M6(t,r);if(!o||r+o>s)return r;r+=o}return e}function T2(t,e,i){if(!e||!M6(t,e))return e;for(let r=e,s=e-i,n=0;n<B6;n++){let o=T6(t,r);if(!o||r-o<s)return r;r-=o}return e}function B2(t,e,i){for(;e!=i;e--)if(t.charCodeAt(e-1)==10)return e;return-1}function R2(t,e,i){for(;e!=i;e++)if(t.charCodeAt(e)==10)return e;return-1}const R6=t=>t>=55296&&t<=56319,N6=t=>t>=56320&&t<=57343;function ko(t,e){return!e||e==t.length||!R6(t.charCodeAt(e-1))||!N6(t.charCodeAt(e))}function yM(t,e,i){var r;let s=i==null?void 0:i.override;return s?s(t,e):(na=((r=i==null?void 0:i.scanLimit)!==null&&r!==void 0?r:1e9)>>1,oa=i!=null&&i.timeout?Date.now()+i.timeout:0,S1=!1,bM(t,e,Nn(t,0,t.length,e,0,e.length)))}function L6(){return!S1}function O6(t,e,i){return _M(yM(t,e,i),t,e)}const gi=we.define({combine:t=>t[0]}),sf=at.define(),P6=we.define(),hi=or.define({create(t){return null},update(t,e){for(let i of e.effects)i.is(sf)&&(t=i.value);for(let i of e.state.facet(P6))t=i(t,e);return t}});let F6=t=>({state:e,dispatch:i})=>{let r=e.field(hi,!1),s=e.facet(gi);if(!r||!r.length||!s)return!1;let{head:n}=e.selection.main,o=0;for(let c=r.length-1;c>=0;c--){let h=r[c],[d,f]=s.side=="b"?[h.fromB,h.toB]:[h.fromA,h.toA];if(f<n){o=c+1;break}if(d<=n){if(r.length==1)return!1;o=c+(t<0?0:1);break}}let a=r[(o+(t<0?r.length-1:0))%r.length],[l,u]=s.side=="b"?[a.fromB,a.toB]:[a.fromA,a.toA];return i(e.update({selection:{anchor:l},userEvent:"select.byChunk",effects:xe.scrollIntoView(ve.range(u,l))})),!0};const wM=F6(1),xM=F6(-1);class as{constructor(e,i,r,s,n,o=!0){this.changes=e,this.fromA=i,this.toA=r,this.fromB=s,this.toB=n,this.precise=o}offset(e,i){return e||i?new as(this.changes,this.fromA+e,this.toA+e,this.fromB+i,this.toB+i,this.precise):this}get endA(){return Math.max(this.fromA,this.toA-1)}get endB(){return Math.max(this.fromB,this.toB-1)}static build(e,i,r){let s=O6(e.toString(),i.toString(),r);return I6(s,e,i,0,0,L6())}static updateA(e,i,r,s,n){return F2(P2(e,s,!0,r.length),e,i,r,n)}static updateB(e,i,r,s,n){return F2(P2(e,s,!1,i.length),e,i,r,n)}}function N2(t,e,i,r){let s=i.lineAt(t),n=r.lineAt(e);return s.to==t&&n.to==e&&t<i.length&&e<r.length?[t+1,e+1]:[s.from,n.from]}function L2(t,e,i,r){let s=i.lineAt(t),n=r.lineAt(e);return s.from==t&&n.from==e?[t,e]:[s.to+1,n.to+1]}function I6(t,e,i,r,s,n){let o=[];for(let a=0;a<t.length;a++){let l=t[a],[u,c]=N2(l.fromA+r,l.fromB+s,e,i),[h,d]=L2(l.toA+r,l.toB+s,e,i),f=[l.offset(-u+r,-c+s)];for(;a<t.length-1;){let m=t[a+1],[v,_]=N2(m.fromA+r,m.fromB+s,e,i);if(v>h+1&&_>d+1)break;f.push(m.offset(-u+r,-c+s)),[h,d]=L2(m.toA+r,m.toB+s,e,i),a++}o.push(new as(f,u,Math.max(u,h),c,Math.max(c,d),n))}return o}const Ul=1e3;function O2(t,e,i,r){let s=0,n=t.length;for(;;){if(s==n){let c=0,h=0;s&&({toA:c,toB:h}=t[s-1]);let d=e-(i?c:h);return[c+d,h+d]}let o=s+n>>1,a=t[o],[l,u]=i?[a.fromA,a.toA]:[a.fromB,a.toB];if(l>e)n=o;else if(u<=e)s=o+1;else return r?[a.fromA,a.fromB]:[a.toA,a.toB]}}function P2(t,e,i,r){let s=[];return e.iterChangedRanges((n,o,a,l)=>{let u=0,c=i?e.length:r,h=0,d=i?r:e.length;n>Ul&&([u,h]=O2(t,n-Ul,i,!0)),o<e.length-Ul&&([c,d]=O2(t,o+Ul,i,!1));let f=l-a-(o-n),m,[v,_]=i?[f,0]:[0,f];s.length&&(m=s[s.length-1]).toA>=u?s[s.length-1]={fromA:m.fromA,fromB:m.fromB,toA:c,toB:d,diffA:m.diffA+v,diffB:m.diffB+_}:s.push({fromA:u,toA:c,fromB:h,toB:d,diffA:v,diffB:_})}),s}function F2(t,e,i,r,s){if(!t.length)return e;let n=[];for(let o=0,a=0,l=0,u=0;;o++){let c=o==t.length?null:t[o],h=c?c.fromA+a:i.length,d=c?c.fromB+l:r.length;for(;u<e.length;){let _=e[u];if(c&&(_.toA+a>h||_.toB+l>d))break;n.push(_.offset(a,l)),u++}if(!c)break;let f=c.toA+a+c.diffA,m=c.toB+l+c.diffB,v=O6(i.sliceString(h,f),r.sliceString(d,m),s);for(let _ of I6(v,i,r,h,d,L6()))n.push(_);for(a+=c.diffA,l+=c.diffB;u<e.length;){let _=e[u];if(_.fromA+a>f&&_.fromB+l>m)break;u++}}return n}const z6={scanLimit:500},M0=qr.fromClass(class{constructor(t){({deco:this.deco,gutter:this.gutter}=j2(t))}update(t){(t.docChanged||t.viewportChanged||SM(t.startState,t.state)||kM(t.startState,t.state))&&({deco:this.deco,gutter:this.gutter}=j2(t.view))}},{decorations:t=>t.deco}),Gl=Fn.low(f6({class:"cm-changeGutter",markers:t=>{var e;return((e=t.plugin(M0))===null||e===void 0?void 0:e.gutter)||ze.empty}}));function SM(t,e){return t.field(hi,!1)!=e.field(hi,!1)}function kM(t,e){return t.facet(gi)!=e.facet(gi)}const I2=qe.line({class:"cm-changedLine"}),j6=qe.mark({class:"cm-changedText"}),CM=qe.mark({tagName:"ins",class:"cm-insertedLine"}),AM=qe.mark({tagName:"del",class:"cm-deletedLine"}),z2=new class extends mr{constructor(){super(...arguments),this.elementClass="cm-changedLineGutter"}};function EM(t,e,i,r,s,n){let o=i?t.fromA:t.fromB,a=i?t.toA:t.toB,l=0;if(o!=a){s.add(o,o,I2),s.add(o,a,i?AM:CM),n&&n.add(o,o,z2);for(let u=e.iterRange(o,a-1),c=o;!u.next().done;){if(u.lineBreak){c++,s.add(c,c,I2),n&&n.add(c,c,z2);continue}let h=c+u.value.length;if(r)for(;l<t.changes.length;){let d=t.changes[l],f=o+(i?d.fromA:d.fromB),m=o+(i?d.toA:d.toB),v=Math.max(c,f),_=Math.min(h,m);if(v<_&&s.add(v,_,j6),m<h)l++;else break}c=h}}}function j2(t){let e=t.state.field(hi),{side:i,highlightChanges:r,markGutter:s,overrideChunk:n}=t.state.facet(gi),o=i=="a",a=new fr,l=s?new fr:null,{from:u,to:c}=t.viewport;for(let h of e){if((o?h.fromA:h.fromB)>=c)break;(o?h.toA:h.toB)>u&&(!n||!n(t.state,h,a,l))&&EM(h,t.state.doc,o,r,a,l)}return{deco:a.finish(),gutter:l&&l.finish()}}class Yl extends Js{constructor(e){super(),this.height=e}eq(e){return this.height==e.height}toDOM(){let e=document.createElement("div");return e.className="cm-mergeSpacer",e.style.height=this.height+"px",e}updateDOM(e){return e.style.height=this.height+"px",!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}}const Uu=at.define({map:(t,e)=>t.map(e)}),aa=or.define({create:()=>qe.none,update:(t,e)=>{for(let i of e.effects)if(i.is(Uu))return i.value;return t.map(e.changes)},provide:t=>xe.decorations.from(t)}),Xl=.01;function H2(t,e){if(t.size!=e.size)return!1;let i=t.iter(),r=e.iter();for(;i.value;){if(i.from!=r.from||Math.abs(i.value.spec.widget.height-r.value.spec.widget.height)>1)return!1;i.next(),r.next()}return!0}function DM(t,e,i){let r=new fr,s=new fr,n=t.state.field(aa).iter(),o=e.state.field(aa).iter(),a=0,l=0,u=0,c=0,h=t.viewport,d=e.viewport;for(let _=0;;_++){let w=_<i.length?i[_]:null,x=w?w.fromA:t.state.doc.length,A=w?w.fromB:e.state.doc.length;if(a<x){let D=t.lineBlockAt(a).top+u,R=e.lineBlockAt(l).top+c,E=D-R;E<-Xl?(u-=E,r.add(a,a,qe.widget({widget:new Yl(-E),block:!0,side:-1}))):E>Xl&&(c+=E,s.add(l,l,qe.widget({widget:new Yl(E),block:!0,side:-1})))}if(x>a+1e3&&a<h.from&&x>h.from&&l<d.from&&A>d.from){let D=Math.min(h.from-a,d.from-l);a+=D,l+=D,_--}else if(w)a=w.toA,l=w.toB;else break;for(;n.value&&n.from<a;)u-=n.value.spec.widget.height,n.next();for(;o.value&&o.from<l;)c-=o.value.spec.widget.height,o.next()}for(;n.value;)u-=n.value.spec.widget.height,n.next();for(;o.value;)c-=o.value.spec.widget.height,o.next();let f=t.contentHeight+u-(e.contentHeight+c);f<Xl?r.add(t.state.doc.length,t.state.doc.length,qe.widget({widget:new Yl(-f),block:!0,side:1})):f>Xl&&s.add(e.state.doc.length,e.state.doc.length,qe.widget({widget:new Yl(f),block:!0,side:1}));let m=r.finish(),v=s.finish();H2(m,t.state.field(aa))||t.dispatch({effects:Uu.of(m)}),H2(v,e.state.field(aa))||e.dispatch({effects:Uu.of(v)})}const nf=at.define({map:(t,e)=>e.mapPos(t)});class MM extends Js{constructor(e){super(),this.lines=e}eq(e){return this.lines==e.lines}toDOM(e){let i=document.createElement("div");return i.className="cm-collapsedLines",i.textContent=e.state.phrase("$ unchanged lines",this.lines),i.addEventListener("click",r=>{let s=e.posAtDOM(r.target);e.dispatch({effects:nf.of(s)});let{side:n,sibling:o}=e.state.facet(gi);o&&o().dispatch({effects:nf.of(TM(s,e.state.field(hi),n=="a"))})}),i}ignoreEvent(e){return e instanceof MouseEvent}get estimatedHeight(){return 27}get type(){return"collapsed-unchanged-code"}}function TM(t,e,i){let r=0,s=0;for(let n=0;;n++){let o=n<e.length?e[n]:null;if(!o||(i?o.fromA:o.fromB)>=t)return s+(t-r);[r,s]=i?[o.toA,o.toB]:[o.toB,o.toA]}}const BM=or.define({create(t){return qe.none},update(t,e){t=t.map(e.changes);for(let i of e.effects)i.is(nf)&&(t=t.update({filter:r=>r!=i.value}));if(t.size&&e.state.field(hi)!=e.startState.field(hi,!1)){let i=e.state.facet(gi).side=="a",r=[];for(let s of e.state.field(hi))t.between(i?s.fromA:s.fromB,i?s.toA:s.toB,n=>{r.push(n)});r.length&&(t=t.update({filter:s=>r.indexOf(s)<0}))}return t},provide:t=>xe.decorations.from(t)});function of({margin:t=3,minSize:e=4}){return BM.init(i=>RM(i,t,e))}function RM(t,e,i){let r=new fr,s=t.facet(gi).side=="a",n=t.field(hi),o=1;for(let a=0;;a++){let l=a<n.length?n[a]:null,u=a?o+e:1,c=l?t.doc.lineAt(s?l.fromA:l.fromB).number-1-e:t.doc.lines,h=c-u+1;if(h>=i&&r.add(t.doc.line(u).from,t.doc.line(c).to,qe.replace({widget:new MM(h),block:!0})),!l)break;o=t.doc.lineAt(Math.min(t.doc.length,s?l.toA:l.toB)).number}return r.finish()}const NM=xe.styleModule.of(new us({".cm-mergeView":{overflowY:"auto"},".cm-mergeViewEditors":{display:"flex",alignItems:"stretch"},".cm-mergeViewEditor":{flexGrow:1,flexBasis:0,overflow:"hidden"},".cm-merge-revert":{width:"1.6em",flexGrow:0,flexShrink:0,position:"relative"},".cm-merge-revert button":{position:"absolute",display:"block",width:"100%",boxSizing:"border-box",textAlign:"center",background:"none",border:"none",font:"inherit",cursor:"pointer"}})),H6=xe.baseTheme({".cm-mergeView & .cm-scroller, .cm-mergeView &":{height:"auto !important",overflowY:"visible !important"},"&.cm-merge-a .cm-changedLine, .cm-deletedChunk":{backgroundColor:"rgba(160, 128, 100, .08)"},"&.cm-merge-b .cm-changedLine, .cm-inlineChangedLine":{backgroundColor:"rgba(100, 160, 128, .08)"},"&light.cm-merge-a .cm-changedText, &light .cm-deletedChunk .cm-deletedText":{background:"linear-gradient(#ee443366, #ee443366) bottom/100% 2px no-repeat"},"&dark.cm-merge-a .cm-changedText, &dark .cm-deletedChunk .cm-deletedText":{background:"linear-gradient(#ffaa9966, #ffaa9966) bottom/100% 2px no-repeat"},"&light.cm-merge-b .cm-changedText":{background:"linear-gradient(#22bb22aa, #22bb22aa) bottom/100% 2px no-repeat"},"&dark.cm-merge-b .cm-changedText":{background:"linear-gradient(#88ff88aa, #88ff88aa) bottom/100% 2px no-repeat"},"&.cm-merge-b .cm-deletedText":{background:"#ff000033"},".cm-insertedLine, .cm-deletedLine, .cm-deletedLine del":{textDecoration:"none"},".cm-deletedChunk":{paddingLeft:"6px","& .cm-chunkButtons":{position:"absolute",insetInlineEnd:"5px"},"& button":{border:"none",cursor:"pointer",color:"white",margin:"0 2px",borderRadius:"3px","&[name=accept]":{background:"#2a2"},"&[name=reject]":{background:"#d43"}}},".cm-collapsedLines":{padding:"5px 5px 5px 10px",cursor:"pointer","&:before":{content:'"⦚"',marginInlineEnd:"7px"},"&:after":{content:'"⦚"',marginInlineStart:"7px"}},"&light .cm-collapsedLines":{color:"#444",background:"linear-gradient(to bottom, transparent 0, #f3f3f3 30%, #f3f3f3 70%, transparent 100%)"},"&dark .cm-collapsedLines":{color:"#ddd",background:"linear-gradient(to bottom, transparent 0, #222 30%, #222 70%, transparent 100%)"},".cm-changeGutter":{width:"3px",paddingLeft:"1px"},"&light.cm-merge-a .cm-changedLineGutter, &light .cm-deletedLineGutter":{background:"#e43"},"&dark.cm-merge-a .cm-changedLineGutter, &dark .cm-deletedLineGutter":{background:"#fa9"},"&light.cm-merge-b .cm-changedLineGutter":{background:"#2b2"},"&dark.cm-merge-b .cm-changedLineGutter":{background:"#8f8"},".cm-inlineChangedLineGutter":{background:"#75d"}}),$2=new Ro,Jl=new Ro;class LM{constructor(e){this.revertDOM=null,this.revertToA=!1,this.revertToLeft=!1,this.measuring=-1,this.diffConf=e.diffConfig||z6;let i=[Fn.low(M0),H6,NM,aa,xe.updateListener.of(h=>{this.measuring<0&&(h.heightChanged||h.viewportChanged)&&!h.transactions.some(d=>d.effects.some(f=>f.is(Uu)))&&this.measure()})],r=[gi.of({side:"a",sibling:()=>this.b,highlightChanges:e.highlightChanges!==!1,markGutter:e.gutter!==!1})];e.gutter!==!1&&r.push(Gl);let s=Ke.create({doc:e.a.doc,selection:e.a.selection,extensions:[e.a.extensions||[],xe.editorAttributes.of({class:"cm-merge-a"}),Jl.of(r),i]}),n=[gi.of({side:"b",sibling:()=>this.a,highlightChanges:e.highlightChanges!==!1,markGutter:e.gutter!==!1})];e.gutter!==!1&&n.push(Gl);let o=Ke.create({doc:e.b.doc,selection:e.b.selection,extensions:[e.b.extensions||[],xe.editorAttributes.of({class:"cm-merge-b"}),Jl.of(n),i]});this.chunks=as.build(s.doc,o.doc,this.diffConf);let a=[hi.init(()=>this.chunks),$2.of(e.collapseUnchanged?of(e.collapseUnchanged):[])];s=s.update({effects:at.appendConfig.of(a)}).state,o=o.update({effects:at.appendConfig.of(a)}).state,this.dom=document.createElement("div"),this.dom.className="cm-mergeView",this.editorDOM=this.dom.appendChild(document.createElement("div")),this.editorDOM.className="cm-mergeViewEditors";let l=e.orientation||"a-b",u=document.createElement("div");u.className="cm-mergeViewEditor";let c=document.createElement("div");c.className="cm-mergeViewEditor",this.editorDOM.appendChild(l=="a-b"?u:c),this.editorDOM.appendChild(l=="a-b"?c:u),this.a=new xe({state:s,parent:u,root:e.root,dispatchTransactions:h=>this.dispatch(h,this.a)}),this.b=new xe({state:o,parent:c,root:e.root,dispatchTransactions:h=>this.dispatch(h,this.b)}),this.setupRevertControls(!!e.revertControls,e.revertControls=="b-to-a",e.renderRevertControl),e.parent&&e.parent.appendChild(this.dom),this.scheduleMeasure()}dispatch(e,i){if(e.some(r=>r.docChanged)){let r=e[e.length-1],s=e.reduce((o,a)=>o.compose(a.changes),Mt.empty(e[0].startState.doc.length));this.chunks=i==this.a?as.updateA(this.chunks,r.newDoc,this.b.state.doc,s,this.diffConf):as.updateB(this.chunks,this.a.state.doc,r.newDoc,s,this.diffConf),i.update([...e,r.state.update({effects:sf.of(this.chunks)})]);let n=i==this.a?this.b:this.a;n.update([n.state.update({effects:sf.of(this.chunks)})]),this.scheduleMeasure()}else i.update(e)}reconfigure(e){if("diffConfig"in e&&(this.diffConf=e.diffConfig),"orientation"in e){let n=e.orientation!="b-a";if(n!=(this.editorDOM.firstChild==this.a.dom.parentNode)){let o=this.a.dom.parentNode,a=this.b.dom.parentNode;o.remove(),a.remove(),this.editorDOM.insertBefore(n?o:a,this.editorDOM.firstChild),this.editorDOM.appendChild(n?a:o),this.revertToLeft=!this.revertToLeft,this.revertDOM&&(this.revertDOM.textContent="")}}if("revertControls"in e||"renderRevertControl"in e){let n=!!this.revertDOM,o=this.revertToA,a=this.renderRevert;"revertControls"in e&&(n=!!e.revertControls,o=e.revertControls=="b-to-a"),"renderRevertControl"in e&&(a=e.renderRevertControl),this.setupRevertControls(n,o,a)}let i="highlightChanges"in e,r="gutter"in e,s="collapseUnchanged"in e;if(i||r||s){let n=[],o=[];if(i||r){let a=this.a.state.facet(gi),l=r?e.gutter!==!1:a.markGutter,u=i?e.highlightChanges!==!1:a.highlightChanges;n.push(Jl.reconfigure([gi.of({side:"a",sibling:()=>this.b,highlightChanges:u,markGutter:l}),l?Gl:[]])),o.push(Jl.reconfigure([gi.of({side:"b",sibling:()=>this.a,highlightChanges:u,markGutter:l}),l?Gl:[]]))}if(s){let a=$2.reconfigure(e.collapseUnchanged?of(e.collapseUnchanged):[]);n.push(a),o.push(a)}this.a.dispatch({effects:n}),this.b.dispatch({effects:o})}this.scheduleMeasure()}setupRevertControls(e,i,r){this.revertToA=i,this.revertToLeft=this.revertToA==(this.editorDOM.firstChild==this.a.dom.parentNode),this.renderRevert=r,!e&&this.revertDOM?(this.revertDOM.remove(),this.revertDOM=null):e&&!this.revertDOM?(this.revertDOM=this.editorDOM.insertBefore(document.createElement("div"),this.editorDOM.firstChild.nextSibling),this.revertDOM.addEventListener("mousedown",s=>this.revertClicked(s)),this.revertDOM.className="cm-merge-revert"):this.revertDOM&&(this.revertDOM.textContent="")}scheduleMeasure(){if(this.measuring<0){let e=this.dom.ownerDocument.defaultView||window;this.measuring=e.requestAnimationFrame(()=>{this.measuring=-1,this.measure()})}}measure(){DM(this.a,this.b,this.chunks),this.revertDOM&&this.updateRevertButtons()}updateRevertButtons(){let e=this.revertDOM,i=e.firstChild,r=this.a.viewport,s=this.b.viewport;for(let n=0;n<this.chunks.length;n++){let o=this.chunks[n];if(o.fromA>r.to||o.fromB>s.to)break;if(o.fromA<r.from||o.fromB<s.from)continue;let a=this.a.lineBlockAt(o.fromA).top+"px";for(;i&&+i.dataset.chunk<n;)i=q2(i);i&&i.dataset.chunk==String(n)?(i.style.top!=a&&(i.style.top=a),i=i.nextSibling):e.insertBefore(this.renderRevertButton(a,n),i)}for(;i;)i=q2(i)}renderRevertButton(e,i){let r;if(this.renderRevert)r=this.renderRevert();else{r=document.createElement("button");let s=this.a.state.phrase("Revert this chunk");r.setAttribute("aria-label",s),r.setAttribute("title",s),r.textContent=this.revertToLeft?"⇜":"⇝"}return r.style.top=e,r.setAttribute("data-chunk",String(i)),r}revertClicked(e){let i=e.target,r;for(;i&&i.parentNode!=this.revertDOM;)i=i.parentNode;if(i&&(r=this.chunks[i.dataset.chunk])){let[s,n,o,a,l,u]=this.revertToA?[this.b,this.a,r.fromB,r.toB,r.fromA,r.toA]:[this.a,this.b,r.fromA,r.toA,r.fromB,r.toB],c=s.state.sliceDoc(o,Math.max(o,a-1));o!=a&&u<=n.state.doc.length&&(c+=s.state.lineBreak),n.dispatch({changes:{from:l,to:Math.min(n.state.doc.length,u),insert:c},userEvent:"revert"}),e.preventDefault()}}destroy(){this.a.destroy(),this.b.destroy(),this.measuring>-1&&(this.dom.ownerDocument.defaultView||window).cancelAnimationFrame(this.measuring),this.dom.remove()}}function q2(t){let e=t.nextSibling;return t.remove(),e}const OM=new class extends mr{constructor(){super(...arguments),this.elementClass="cm-deletedLineGutter"}},PM=Fn.low(f6({class:"cm-changeGutter",markers:t=>{var e;return((e=t.plugin(M0))===null||e===void 0?void 0:e.gutter)||ze.empty},widgetMarker:(t,e)=>e instanceof $6?OM:null}));function FM(t){var e;let i=typeof t.original=="string"?Ve.of(t.original.split(/\r?\n/)):t.original,r=t.diffConfig||z6;return[Fn.low(M0),HM,H6,xe.editorAttributes.of({class:"cm-merge-b"}),P6.of((s,n)=>{let o=n.effects.find(a=>a.is(A1));return o&&(s=as.updateA(s,o.value.doc,n.startState.doc,o.value.changes,r)),n.docChanged&&(s=as.updateB(s,n.state.field(Co),n.newDoc,n.changes,r)),s}),gi.of({highlightChanges:t.highlightChanges!==!1,markGutter:t.gutter!==!1,syntaxHighlightDeletions:t.syntaxHighlightDeletions!==!1,syntaxHighlightDeletionsMaxLength:3e3,mergeControls:(e=t.mergeControls)!==null&&e!==void 0?e:!0,overrideChunk:t.allowInlineDiffs?KM:void 0,side:"b"}),Co.init(()=>i),t.gutter!==!1?PM:[],t.collapseUnchanged?of(t.collapseUnchanged):[],hi.init(s=>as.build(i,s.doc,r))]}const A1=at.define(),Co=or.define({create:()=>Ve.empty,update(t,e){for(let i of e.effects)i.is(A1)&&(t=i.value.doc);return t}}),W2=new WeakMap;class $6 extends Js{constructor(e){super(),this.buildDOM=e,this.dom=null}eq(e){return this.dom==e.dom}toDOM(e){return this.dom||(this.dom=this.buildDOM(e))}}function IM(t,e,i){let r=W2.get(e.changes);if(r)return r;let s=o=>{let{highlightChanges:a,syntaxHighlightDeletions:l,syntaxHighlightDeletionsMaxLength:u,mergeControls:c}=t.facet(gi),h=document.createElement("div");if(h.className="cm-deletedChunk",c){let D=h.appendChild(document.createElement("div"));D.className="cm-chunkButtons";let R=L=>{L.preventDefault(),zM(o,o.posAtDOM(h))},E=L=>{L.preventDefault(),jM(o,o.posAtDOM(h))};if(typeof c=="function")D.appendChild(c("accept",R)),D.appendChild(c("reject",E));else{let L=D.appendChild(document.createElement("button"));L.name="accept",L.textContent=t.phrase("Accept"),L.onmousedown=R;let q=D.appendChild(document.createElement("button"));q.name="reject",q.textContent=t.phrase("Reject"),q.onmousedown=E}}if(i||e.fromA>=e.toA)return h;let d=o.state.field(Co).sliceString(e.fromA,e.endA),f=l&&t.facet(Rn),m=x(),v=e.changes,_=0,w=!1;function x(){let D=h.appendChild(document.createElement("div"));return D.className="cm-deletedLine",D.appendChild(document.createElement("del"))}function A(D,R,E){for(let L=D;L<R;){if(d.charAt(L)==`
|
|
326
326
|
`){m.firstChild||m.appendChild(document.createElement("br")),m=x(),L++;continue}let q=R,F=E+(w?" cm-deletedText":""),$=!1,W=d.indexOf(`
|
|
327
|
-
`,L);if(W>-1&&W<R&&(q=W),a&&_<v.length){let z=Math.max(0,w?v[_].toA:v[_].fromA);z<=q&&(q=z,w&&_++,$=!0)}if(q>L){let z=document.createTextNode(d.slice(L,q));if(F){let j=m.appendChild(document.createElement("span"));j.className=F,j.appendChild(z)}else m.appendChild(z);L=q}$&&(w=!w)}}if(f&&e.toA-e.fromA<=u){let D=f.parser.parse(d),R=0;x6(D,{style:E=>cM(t,E)},(E,L,q)=>{E>R&&A(R,E,""),A(E,L,q),R=L}),A(R,d.length,"")}else A(0,d.length,"");return m.firstChild||m.appendChild(document.createElement("br")),h},n=qe.widget({block:!0,side:-1,widget:new $6(s)});return W2.set(e.changes,n),n}function zM(t,e){let{state:i}=t,r=e??i.selection.main.head,s=t.state.field(hi).find(l=>l.fromB<=r&&l.endB>=r);if(!s)return!1;let n=t.state.sliceDoc(s.fromB,Math.max(s.fromB,s.toB-1)),o=t.state.field(Co);s.fromB!=s.toB&&s.toA<=o.length&&(n+=t.state.lineBreak);let a=Mt.of({from:s.fromA,to:Math.min(o.length,s.toA),insert:n},o.length);return t.dispatch({effects:A1.of({doc:a.apply(o),changes:a}),userEvent:"accept"}),!0}function jM(t,e){let{state:i}=t,r=e??i.selection.main.head,s=i.field(hi).find(a=>a.fromB<=r&&a.endB>=r);if(!s)return!1;let o=i.field(Co).sliceString(s.fromA,Math.max(s.fromA,s.toA-1));return s.fromA!=s.toA&&s.toB<=i.doc.length&&(o+=i.lineBreak),t.dispatch({changes:{from:s.fromB,to:Math.min(i.doc.length,s.toB),insert:o},userEvent:"revert"}),!0}function K2(t){let e=new fr;for(let i of t.field(hi)){let r=t.facet(gi).overrideChunk&&q6(t,i);e.add(i.fromB,i.fromB,IM(t,i,!!r))}return e.finish()}const HM=or.define({create:t=>K2(t),update(t,e){return e.state.field(hi,!1)!=e.startState.field(hi,!1)?K2(e.state):t},provide:t=>xe.decorations.from(t)}),V2=new WeakMap;function q6(t,e){let i=V2.get(e);if(i!==void 0)return i;i=null;let r=t.field(Co),s=t.doc,n=r.lineAt(e.endA).number-r.lineAt(e.fromA).number+1,o=s.lineAt(e.endB).number-s.lineAt(e.fromB).number+1;e:if(n==o&&n<10){let a=[],l=0,u=e.fromA,c=e.fromB;for(let h of e.changes){if(h.fromA<h.toA){l+=h.toA-h.fromA;let d=r.sliceString(u+h.fromA,u+h.toA);if(/\n/.test(d))break e;a.push(qe.widget({widget:new $M(d),side:-1}).range(c+h.fromB))}h.fromB<h.toB&&a.push(j6.range(c+h.fromB,c+h.toB))}l<e.endA-e.fromA-n*2&&(i=a)}return V2.set(e,i),i}class $M extends Js{constructor(e){super(),this.text=e}eq(e){return this.text==e.text}toDOM(e){let i=document.createElement("del");return i.className="cm-deletedText",i.textContent=this.text,i}}const qM=new class extends mr{constructor(){super(...arguments),this.elementClass="cm-inlineChangedLineGutter"}},WM=qe.line({class:"cm-inlineChangedLine"});function KM(t,e,i,r){let s=q6(t,e),n=0;if(!s)return!1;for(let o=t.doc.lineAt(e.fromB);;){for(r&&r.add(o.from,o.from,qM),i.add(o.from,o.from,WM);n<s.length&&s[n].to<=o.to;){let a=s[n++];i.add(a.from,a.to,a.value)}if(o.to>=e.endB)break;o=t.doc.lineAt(o.to+1)}return!0}function Gc(t){const e={name:"",dirs:new Map,files:[]};for(const i of t){const r=String(i.path||"").split("/").filter(Boolean);if(!r.pop())continue;let n=e;for(const o of r)n.dirs.has(o)||n.dirs.set(o,{name:o,dirs:new Map,files:[]}),n=n.dirs.get(o);n.files.push(i)}return W6(e).children}function W6(t){const e=[];for(const r of t.dirs.values()){let s=W6(r);for(;!s.files.length&&s.children.length===1&&s.children[0].kind==="dir";){const n=s.children[0];s={...n,name:`${s.name}/${n.name}`}}e.push(s)}e.sort((r,s)=>r.name.localeCompare(s.name));const i=[...t.files].sort((r,s)=>r.path.localeCompare(s.path)).map(r=>({kind:"file",name:r.path.split("/").pop(),file:r}));return{kind:"dir",name:t.name,files:t.files,children:[...e,...i]}}function af(t,e=""){const i=[];for(const r of t){if(r.kind!=="dir")continue;const s=e?`${e}/${r.name}`:r.name;i.push(s,...af(r.children,s))}return i}function VM(t){const e=String(t||"").split("/"),i=e.pop()||"";return{dir:e.join("/"),name:i,dirSegments:e}}const UM=D0.define([{tag:[be.keyword,be.modifier,be.controlKeyword],color:"var(--magenta)"},{tag:[be.function(be.variableName),be.function(be.propertyName)],color:"var(--blue)"},{tag:[be.string,be.special(be.string)],color:"var(--green)"},{tag:[be.comment,be.lineComment,be.blockComment],color:"var(--muted)",fontStyle:"italic"},{tag:[be.number,be.bool,be.null],color:"var(--orange)"},{tag:[be.typeName,be.className,be.tagName],color:"var(--yellow)"},{tag:[be.propertyName,be.attributeName],color:"var(--cyan)"},{tag:[be.operator,be.punctuation],color:"var(--ink)"},{tag:[be.invalid],color:"var(--red)"}]),GM=xe.theme({"&":{backgroundColor:"var(--paper)",color:"var(--ink)",fontSize:"var(--type-meta)",minHeight:"100%"},".cm-content":{fontFamily:"var(--mono)",padding:"8px 0"},".cm-scroller":{fontFamily:"var(--mono)",lineHeight:"1.55",overflow:"auto"},".cm-gutters":{backgroundColor:"var(--paper)",color:"var(--muted)",border:"none",opacity:".7"},".cm-lineNumbers .cm-gutterElement":{padding:"0 10px"},".cm-line":{whiteSpace:"pre"},".cm-mergeView":{minWidth:"0"}},{dark:!0}),YM=new Set(["js","jsx","mjs","cjs","ts","tsx","mts","cts"]);async function XM(t){const e=(t.split(".").pop()||"").toLowerCase();if(!YM.has(e))return[];try{const{javascript:i}=await Gs(async()=>{const{javascript:r}=await import("./index-
|
|
327
|
+
`,L);if(W>-1&&W<R&&(q=W),a&&_<v.length){let z=Math.max(0,w?v[_].toA:v[_].fromA);z<=q&&(q=z,w&&_++,$=!0)}if(q>L){let z=document.createTextNode(d.slice(L,q));if(F){let j=m.appendChild(document.createElement("span"));j.className=F,j.appendChild(z)}else m.appendChild(z);L=q}$&&(w=!w)}}if(f&&e.toA-e.fromA<=u){let D=f.parser.parse(d),R=0;x6(D,{style:E=>cM(t,E)},(E,L,q)=>{E>R&&A(R,E,""),A(E,L,q),R=L}),A(R,d.length,"")}else A(0,d.length,"");return m.firstChild||m.appendChild(document.createElement("br")),h},n=qe.widget({block:!0,side:-1,widget:new $6(s)});return W2.set(e.changes,n),n}function zM(t,e){let{state:i}=t,r=e??i.selection.main.head,s=t.state.field(hi).find(l=>l.fromB<=r&&l.endB>=r);if(!s)return!1;let n=t.state.sliceDoc(s.fromB,Math.max(s.fromB,s.toB-1)),o=t.state.field(Co);s.fromB!=s.toB&&s.toA<=o.length&&(n+=t.state.lineBreak);let a=Mt.of({from:s.fromA,to:Math.min(o.length,s.toA),insert:n},o.length);return t.dispatch({effects:A1.of({doc:a.apply(o),changes:a}),userEvent:"accept"}),!0}function jM(t,e){let{state:i}=t,r=e??i.selection.main.head,s=i.field(hi).find(a=>a.fromB<=r&&a.endB>=r);if(!s)return!1;let o=i.field(Co).sliceString(s.fromA,Math.max(s.fromA,s.toA-1));return s.fromA!=s.toA&&s.toB<=i.doc.length&&(o+=i.lineBreak),t.dispatch({changes:{from:s.fromB,to:Math.min(i.doc.length,s.toB),insert:o},userEvent:"revert"}),!0}function K2(t){let e=new fr;for(let i of t.field(hi)){let r=t.facet(gi).overrideChunk&&q6(t,i);e.add(i.fromB,i.fromB,IM(t,i,!!r))}return e.finish()}const HM=or.define({create:t=>K2(t),update(t,e){return e.state.field(hi,!1)!=e.startState.field(hi,!1)?K2(e.state):t},provide:t=>xe.decorations.from(t)}),V2=new WeakMap;function q6(t,e){let i=V2.get(e);if(i!==void 0)return i;i=null;let r=t.field(Co),s=t.doc,n=r.lineAt(e.endA).number-r.lineAt(e.fromA).number+1,o=s.lineAt(e.endB).number-s.lineAt(e.fromB).number+1;e:if(n==o&&n<10){let a=[],l=0,u=e.fromA,c=e.fromB;for(let h of e.changes){if(h.fromA<h.toA){l+=h.toA-h.fromA;let d=r.sliceString(u+h.fromA,u+h.toA);if(/\n/.test(d))break e;a.push(qe.widget({widget:new $M(d),side:-1}).range(c+h.fromB))}h.fromB<h.toB&&a.push(j6.range(c+h.fromB,c+h.toB))}l<e.endA-e.fromA-n*2&&(i=a)}return V2.set(e,i),i}class $M extends Js{constructor(e){super(),this.text=e}eq(e){return this.text==e.text}toDOM(e){let i=document.createElement("del");return i.className="cm-deletedText",i.textContent=this.text,i}}const qM=new class extends mr{constructor(){super(...arguments),this.elementClass="cm-inlineChangedLineGutter"}},WM=qe.line({class:"cm-inlineChangedLine"});function KM(t,e,i,r){let s=q6(t,e),n=0;if(!s)return!1;for(let o=t.doc.lineAt(e.fromB);;){for(r&&r.add(o.from,o.from,qM),i.add(o.from,o.from,WM);n<s.length&&s[n].to<=o.to;){let a=s[n++];i.add(a.from,a.to,a.value)}if(o.to>=e.endB)break;o=t.doc.lineAt(o.to+1)}return!0}function Gc(t){const e={name:"",dirs:new Map,files:[]};for(const i of t){const r=String(i.path||"").split("/").filter(Boolean);if(!r.pop())continue;let n=e;for(const o of r)n.dirs.has(o)||n.dirs.set(o,{name:o,dirs:new Map,files:[]}),n=n.dirs.get(o);n.files.push(i)}return W6(e).children}function W6(t){const e=[];for(const r of t.dirs.values()){let s=W6(r);for(;!s.files.length&&s.children.length===1&&s.children[0].kind==="dir";){const n=s.children[0];s={...n,name:`${s.name}/${n.name}`}}e.push(s)}e.sort((r,s)=>r.name.localeCompare(s.name));const i=[...t.files].sort((r,s)=>r.path.localeCompare(s.path)).map(r=>({kind:"file",name:r.path.split("/").pop(),file:r}));return{kind:"dir",name:t.name,files:t.files,children:[...e,...i]}}function af(t,e=""){const i=[];for(const r of t){if(r.kind!=="dir")continue;const s=e?`${e}/${r.name}`:r.name;i.push(s,...af(r.children,s))}return i}function VM(t){const e=String(t||"").split("/"),i=e.pop()||"";return{dir:e.join("/"),name:i,dirSegments:e}}const UM=D0.define([{tag:[be.keyword,be.modifier,be.controlKeyword],color:"var(--magenta)"},{tag:[be.function(be.variableName),be.function(be.propertyName)],color:"var(--blue)"},{tag:[be.string,be.special(be.string)],color:"var(--green)"},{tag:[be.comment,be.lineComment,be.blockComment],color:"var(--muted)",fontStyle:"italic"},{tag:[be.number,be.bool,be.null],color:"var(--orange)"},{tag:[be.typeName,be.className,be.tagName],color:"var(--yellow)"},{tag:[be.propertyName,be.attributeName],color:"var(--cyan)"},{tag:[be.operator,be.punctuation],color:"var(--ink)"},{tag:[be.invalid],color:"var(--red)"}]),GM=xe.theme({"&":{backgroundColor:"var(--paper)",color:"var(--ink)",fontSize:"var(--type-meta)",minHeight:"100%"},".cm-content":{fontFamily:"var(--mono)",padding:"8px 0"},".cm-scroller":{fontFamily:"var(--mono)",lineHeight:"1.55",overflow:"auto"},".cm-gutters":{backgroundColor:"var(--paper)",color:"var(--muted)",border:"none",opacity:".7"},".cm-lineNumbers .cm-gutterElement":{padding:"0 10px"},".cm-line":{whiteSpace:"pre"},".cm-mergeView":{minWidth:"0"}},{dark:!0}),YM=new Set(["js","jsx","mjs","cjs","ts","tsx","mts","cts"]);async function XM(t){const e=(t.split(".").pop()||"").toLowerCase();if(!YM.has(e))return[];try{const{javascript:i}=await Gs(async()=>{const{javascript:r}=await import("./index-CgZDxhet.js");return{javascript:r}},__vite__mapDeps([0,1,2,3,4]));return i({jsx:e.endsWith("sx"),typescript:e.startsWith("t")||e.startsWith("mt")||e.startsWith("ct")})}catch{return[]}}function JM(t){const e=[],i=[],r=[],s=[];let n=0,o=0,a=!1;for(const l of String(t||"").split(`
|
|
328
328
|
`)){const u=l.match(/^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/);if(u){n=Number(u[1]),o=Number(u[2]),a=!0;continue}if(!(!a||l.startsWith("--- ")||l.startsWith("+++ ")||l.startsWith("diff ")||l.startsWith("index ")||l.startsWith("\\"))){if(l.startsWith("-")){e.push(l.slice(1)),r.push(n++);continue}if(l.startsWith("+")){i.push(l.slice(1)),s.push(o++);continue}if(l.startsWith(" ")){const c=l.slice(1);e.push(c),i.push(c),r.push(n++),s.push(o++)}}}return{oldText:e.join(`
|
|
329
329
|
`),newText:i.join(`
|
|
330
330
|
`),oldNumbers:r,newNumbers:s}}function ZM(t){return PD({formatNumber:e=>t[e-1]?String(t[e-1]):""})}function Yc(t,e,i){return[Ke.readOnly.of(!0),xe.editable.of(!1),ZM(t),uM(UM),e,i?xe.lineWrapping:[],GM]}const Gn=t=>t?`${t.scope}:${t.file.path}`:"",QM=(t,e)=>{var i;return!!e&&[...((t==null?void 0:t.files)||[]).map(r=>`branch:${r.path}`),...(((i=t==null?void 0:t.working)==null?void 0:i.files)||[]).map(r=>`working:${r.path}`)].includes(e)},eT=t=>{var e;return((t==null?void 0:t.files)||[]).length?{scope:"branch",file:t.files[0]}:(((e=t==null?void 0:t.working)==null?void 0:e.files)||[]).length?{scope:"working",file:t.working.files[0]}:null};function tT({sessionId:t,file:e,scope:i,comments:r,open:s,mode:n,wrap:o,onComment:a,onEdit:l,onRetract:u,onView:c,onNext:h,onPrevious:d}){const f=He(),m=k.useRef(null),v=k.useRef(null),[_,w]=k.useState(e.patch||""),x=k.useMemo(()=>JM(_),[_]);k.useEffect(()=>{if(!s||_||!e.path)return;let E=!0;return Hi(`${Yo(t,"diff")}?scope=${i}&path=${encodeURIComponent(e.path)}`,{cache:"no-store"}).then(L=>L.json()).then(L=>{var F,$,W,z,j;const q=i==="working"?(W=($=(F=L==null?void 0:L.working)==null?void 0:F.files)==null?void 0:$[0])==null?void 0:W.patch:(j=(z=L==null?void 0:L.files)==null?void 0:z[0])==null?void 0:j.patch;E&&typeof q=="string"&&w(q)}).catch(()=>{}),()=>{E=!1}},[t,e.path,s,_,i]),k.useEffect(()=>{if(!s||!m.current||!_)return;let E=!0;return(async()=>{const q=await XM(e.path);if(!(!E||!m.current))if(n==="split"){const F=new LM({a:{doc:x.oldText,extensions:Yc(x.oldNumbers,q,o)},b:{doc:x.newText,extensions:Yc(x.newNumbers,q,o)},parent:m.current,orientation:"a-b",highlightChanges:!0,gutter:!0,collapseUnchanged:{margin:10,minSize:12},diffConfig:{scanLimit:5e3,timeout:100}});v.current=F,c(e.path,F)}else{const F=new xe({parent:m.current,state:Ke.create({doc:x.newText,extensions:[...Yc(x.newNumbers,q,o),FM({original:x.oldText,highlightChanges:!0,syntaxHighlightDeletions:!0,mergeControls:!1,collapseUnchanged:{margin:10,minSize:12},diffConfig:{scanLimit:5e3,timeout:100}})]})});v.current=F,c(e.path,F)}})(),()=>{var q;E=!1,(q=v.current)==null||q.destroy(),v.current=null,c(e.path,null)}},[e.path,n,s,x,c,_,o]);const A=E=>{var j,C,O,T,U,H;if(E.button!==0)return;const L=(C=(j=E.target).closest)==null?void 0:C.call(j,".cm-line");if(!L||!((O=m.current)!=null&&O.contains(L)))return;const q=L.closest(".cm-editor"),F=n==="split"?q===((U=(T=v.current)==null?void 0:T.a)==null?void 0:U.dom)?v.current.a:(H=v.current)==null?void 0:H.b:v.current;if(!F)return;const $=F.state.doc.lineAt(F.posAtDOM(L,0)).number,z=(n==="split"&&F===v.current.a?x.oldNumbers:x.newNumbers)[$-1];z&&a(z,z)},{dirSegments:D,name:R}=VM(e.path);return p.jsxs("section",{className:"diff-file is-open","data-diff-file":e.path,"data-diff-scope":i,children:[p.jsxs("header",{className:"diff-file-head","data-tip":e.path,children:[p.jsxs("span",{className:"diff-file-name",children:[p.jsx(K6,{segments:D}),p.jsx("strong",{children:R})]}),p.jsx("span",{className:`diff-file-status is-${e.status}`,children:e.status}),p.jsxs("span",{className:"diff-file-stat",children:[p.jsxs("span",{className:"diff-add",children:["+",e.additions]})," ",p.jsxs("span",{className:"diff-del",children:["−",e.deletions]})]}),i==="working"&&p.jsx("span",{className:"diff-file-scope",children:f("session.diffUncommitted")}),p.jsx("span",{className:"diff-toolbar-spacer"}),p.jsxs("span",{className:"diff-hunk-tools",children:[p.jsx("button",{type:"button",onClick:d,"aria-label":f("session.diffPrevious"),children:"↑"}),p.jsx("button",{type:"button",onClick:h,"aria-label":f("session.diffNext"),children:"↓"})]})]}),p.jsx("div",{className:`diff-editor diff-editor-${n}${o?" is-wrap":""}`,ref:m,onMouseDown:A}),r.length>0&&p.jsx("div",{className:"diff-comments",children:r.map(E=>p.jsxs("div",{className:`diff-comment${E.sentAt?" sent":""}`,children:[p.jsxs("span",{className:"diff-comment-line",children:["L",E.lineStart,E.lineEnd!==E.lineStart?`-L${E.lineEnd}`:""]}),p.jsx("span",{className:"diff-comment-body",children:E.body}),E.sentAt&&p.jsx(je,{name:"check",size:12}),p.jsx(Zt,{icon:"pencil",size:12,label:f("session.diffEdit"),onClick:()=>l(E)}),p.jsx(Zt,{icon:"trash",size:12,label:f("session.diffRetract"),onClick:()=>u(E)})]},E.id))})]})}function K6({segments:t}){const e=k.useRef(null),[i,r]=k.useState(!1);return k.useEffect(()=>{const s=e.current;if(!s||typeof ResizeObserver>"u")return;const n=()=>r(s.scrollWidth>s.clientWidth+1);n();const o=new ResizeObserver(n);return o.observe(s),()=>o.disconnect()},[t]),t.length?p.jsx("span",{className:`path-head${i?" is-clipped":""}`,ref:e,children:[...t].reverse().map((s,n)=>p.jsxs("span",{children:[s,"/"]},`${t.length-n}:${s}`))}):null}function V6({nodes:t,depth:e,prefix:i,scope:r,selected:s,openDirs:n,onToggleDir:o,onSelect:a}){return t.map(l=>{if(l.kind==="dir"){const c=i?`${i}/${l.name}`:l.name,h=n.has(c);return p.jsxs(k.Fragment,{children:[p.jsxs("button",{type:"button",className:"ft-row ft-dir",style:{paddingLeft:6+e*11,"--depth":e},"aria-expanded":h,"data-tip":c,onClick:()=>o(c),children:[p.jsx("span",{className:"ft-caret",children:p.jsx(d4,{open:h})}),p.jsx("span",{className:"ft-label",children:l.name.includes("/")?p.jsxs(p.Fragment,{children:[p.jsx(K6,{segments:l.name.split("/").slice(0,-1)}),p.jsx("span",{className:"path-leaf",children:l.name.split("/").pop()})]}):p.jsx("span",{className:"path-leaf",children:l.name})})]}),h&&p.jsx(V6,{nodes:l.children,depth:e+1,prefix:c,scope:r,selected:s,openDirs:n,onToggleDir:o,onSelect:a})]},`d:${c}`)}const u=`${r}:${l.file.path}`;return p.jsxs("button",{type:"button",className:`ft-row ft-code diff-tree-file${u===s?" on":""}`,style:{paddingLeft:6+e*11,"--depth":e},"aria-current":u===s?"true":void 0,"data-tip":l.file.path,onClick:()=>a(u),children:[p.jsx("span",{className:"ft-caret"}),p.jsx("span",{className:"ft-label",children:p.jsx("span",{className:"path-leaf",children:l.name})}),p.jsxs("span",{className:"diff-tree-stat",children:[p.jsxs("span",{className:"diff-add",children:["+",l.file.additions]})," ",p.jsxs("span",{className:"diff-del",children:["−",l.file.deletions]})]})]},`f:${u}`)})}function iT({sessionId:t}){var H,re,G,X,oe;const e=He(),{lang:i}=p4(),r=k.useRef(new Map),[s,n]=k.useState({phase:"loading",data:null,error:null}),[o,a]=k.useState(null),[l,u]=k.useState(""),[c,h]=k.useState("split"),[d,f]=k.useState(!1),[m,v]=k.useState(""),[_,w]=k.useState(()=>new Set),x=k.useCallback((I,Y)=>{Y?r.current.set(I,Y):r.current.delete(I)},[]),A=()=>{n(I=>({...I,phase:"loading"})),Hi(Yo(t,"diff"),{cache:"no-store"}).then(async I=>{var le;const Y=await I.json().catch(()=>({}));if(I.status===409){n({phase:"unavailable",data:null,error:null,detail:(Y==null?void 0:Y.error)||""});return}if(!I.ok)throw new Error((Y==null?void 0:Y.error)||`HTTP ${I.status}`);n({phase:"ready",data:Y,error:null}),v(te=>QM(Y,te)?te:Gn(eT(Y))),w(new Set([...af(Gc(Y.files||[])),...af(Gc(((le=Y.working)==null?void 0:le.files)||[]))]))}).catch(I=>n({phase:"error",data:null,error:I}))};k.useEffect(()=>(A(),()=>{r.current.clear()}),[t]);const D=((H=s.data)==null?void 0:H.files)||[],R=((G=(re=s.data)==null?void 0:re.working)==null?void 0:G.files)||[],E=[...D.map(I=>({scope:"branch",file:I})),...R.map(I=>({scope:"working",file:I}))],L=((X=s.data)==null?void 0:X.comments)||[],q=L.filter(I=>!I.sentAt).length,F=E.find(I=>Gn(I)===m)||E[0]||null,$=Math.max(0,E.findIndex(I=>Gn(I)===m)),W=k.useCallback(I=>w(Y=>{const le=new Set(Y);return le.delete(I)||le.add(I),le}),[]),z=I=>{const Y=I>0?wM:xM,le=r.current.get(m);le&&Y(c==="split"?le.b:le)||E.length<2||v(Gn(E[($+I+E.length)%E.length]))},j=async()=>{if(!o||!l.trim())return;const I=E.find(le=>le.file.path===o.filePath)||F;if(!I)return;(await Hi(Yo(t,"diff-comments"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...o,filePath:o.filePath||I.file.path,body:l,diffIdentity:I.file.diffIdentity})})).ok&&(a(null),u(""),A())},C=async I=>{(await Hi(`${Yo(t,"diff-comments")}/${encodeURIComponent(I.id)}`,{method:"DELETE"})).ok&&(a(le=>(le==null?void 0:le.id)===I.id?null:le),A())},O=async()=>{(await Hi(Yo(t,"diff-comments","send"),{method:"POST",headers:{"Content-Type":"application/json"},body:"{}"})).ok&&A()};if(s.phase==="loading")return p.jsx("div",{className:"diff-state",children:e("session.diffLoading")});if(s.phase==="unavailable")return p.jsxs("div",{className:"diff-state diff-unavailable",children:[e("session.diffUnavailable"),s.detail?p.jsx("code",{className:"diff-oids",children:s.detail}):null]});if(s.phase==="error")return p.jsx("div",{className:"diff-state error",children:e("session.diffFailed",{message:((oe=s.error)==null?void 0:oe.message)||String(s.error)})});const T=s.data.branchState==="no-commits"?p.jsx("div",{className:"diff-state diff-no-commits",children:e("session.diffNoCommits")}):s.data.branchState==="merged"?p.jsxs("div",{className:"diff-state diff-merged",children:[p.jsx("strong",{children:e("session.diffMerged",{base:s.data.baseRef})}),s.data.commitUrl?p.jsx("a",{href:s.data.commitUrl,target:"_blank",rel:"noreferrer",children:e("session.diffCommit",{commit:s.data.head})}):p.jsx("code",{children:s.data.head})]}):p.jsx("div",{className:"diff-state",children:e("session.diffEmpty")}),U=(I,Y)=>Y.length>0&&p.jsxs(k.Fragment,{children:[p.jsx("div",{className:"diff-file-group",children:e(I==="branch"?"session.diffGroupCommitted":"session.diffGroupUncommitted",{n:Y.length})}),p.jsx(V6,{nodes:Gc(Y),depth:0,prefix:"",scope:I,selected:m,openDirs:_,onToggleDir:W,onSelect:v})]},I);return p.jsxs("div",{className:"diff-document","data-diff-document":!0,"data-branch-state":s.data.branchState,lang:i,children:[p.jsxs("header",{className:"diff-toolbar",children:[p.jsxs("span",{className:"diff-refs",children:[p.jsx(je,{name:"git-merge",size:14}),p.jsx("strong",{children:s.data.branch}),p.jsx("span",{children:"→"}),p.jsx("strong",{children:s.data.baseRef})]}),p.jsx("span",{className:"diff-toolbar-spacer"}),p.jsxs("div",{className:"diff-mode",role:"group","aria-label":e("session.diffMode"),children:[p.jsx("button",{type:"button","aria-pressed":c==="split",onClick:()=>h("split"),children:e("session.diffSplit")}),p.jsx("button",{type:"button","aria-pressed":c==="unified",onClick:()=>h("unified"),children:e("session.diffUnified")})]}),p.jsx("button",{type:"button","aria-pressed":d,onClick:()=>f(I=>!I),children:e("session.diffWrap")}),q>0&&p.jsx("span",{className:"diff-unsent",children:e("session.diffUnsent",{n:q})}),p.jsx(Zt,{icon:"send",size:14,label:e("session.diffSend"),disabled:!q,onClick:O})]}),p.jsxs("code",{className:"diff-oids",children:[s.data.head," → ",s.data.base]}),!E.length&&T,E.length>0&&p.jsxs("div",{className:"diff-review-body",children:[p.jsxs("nav",{className:"diff-file-panel","aria-label":e("session.diffFiles"),children:[p.jsx("div",{className:"diff-file-panel-head",children:p.jsx("span",{children:e("session.diffFiles")})}),[U("branch",D),U("working",R)]]}),p.jsxs("div",{className:"diff-files",children:[!D.length&&p.jsx("div",{className:"diff-scope-note",children:T}),F&&p.jsx(tT,{sessionId:t,file:F.file,scope:F.scope,open:!0,mode:c,wrap:d,comments:L.filter(I=>I.filePath===F.file.path),onView:(I,Y)=>x(Gn(F),Y),onNext:()=>z(1),onPrevious:()=>z(-1),onComment:(I,Y)=>{I!=null&&(a({filePath:F.file.path,lineStart:I,lineEnd:Y}),u(""))},onEdit:I=>{a(I),u(I.body)},onRetract:C},`${Gn(F)}:${F.file.diffIdentity}`)]})]}),o&&p.jsxs("div",{className:"diff-comment-compose",role:"dialog",children:[p.jsx("strong",{children:e("session.diffComment")}),p.jsxs("span",{children:[o.filePath||(F==null?void 0:F.file.path),":L",o.lineStart]}),p.jsx("textarea",{autoFocus:!0,value:l,onChange:I=>u(I.target.value),placeholder:e("session.diffCommentPlaceholder")}),p.jsxs("div",{children:[p.jsx("button",{type:"button",onClick:()=>a(null),children:e("common.cancel")}),p.jsx("button",{type:"button",disabled:!l.trim(),onClick:j,children:e("session.diffCommentSave")})]})]})]})}const rT=[{id:"claude",label:"Claude Code",Glyph:q5},{id:"codex",label:"Codex",Glyph:W5},{id:"opencode",label:"opencode",Glyph:K5},{id:"pi",label:"pi",Glyph:V5}],U2=Object.fromEntries(rT.map(t=>[t.id,t])),G2=t=>{const e=typeof t=="string"?t.replace(/-headless$/,""):"";return U2[e]||U2.claude},Zl=new Map;async function sT(t){if(Zl.has(t))return Zl.get(t);const e=Hi(t).then(async i=>{const r=await i.json().catch(()=>null);if(!i.ok)throw new Error((r==null?void 0:r.error)||`HTTP ${i.status}`);return r}).finally(()=>Zl.delete(t));return Zl.set(t,e),e}const HR=t=>{const e=typeof t=="string"&&/^\d+$/.test(t)?Number(t):Number.NaN;return Number.isSafeInteger(e)&&e>0?e:1};function nT(t,e){return e<=0?[]:e<=10?Array.from({length:e},(i,r)=>r+1):t<=7?[...Array.from({length:8},(i,r)=>r+1),"gap",e-1,e]:t>=e-6||t>e?[1,2,"gap",...Array.from({length:8},(i,r)=>e-7+r)]:[1,2,"gap",t-2,t-1,t,t+1,t+2,"gap",e-1,e]}function $R(t,e,i,{enabled:r=!0,refreshKey:s=null,pollMs:n=15e3,view:o=null}={}){const[a,l]=k.useState(null),[u,c]=k.useState(null),[h,d]=k.useState(r),f=k.useRef(0),m=k.useCallback(async({quiet:_=!1}={})=>{if(!r)return null;const w=++f.current;_||d(!0),c(null);const x=new URLSearchParams({q:String(e||""),page:String(i)});o&&x.set("view",o);try{const A=await sT(`/api/${t}?${x}`);return w===f.current&&l(D=>D&&A&&D.revision===A.revision?D:A),A}catch(A){return w===f.current&&c(A instanceof Error?A.message:String(A)),null}finally{w===f.current&&d(!1)}},[t,r,i,e,o]),v=k.useRef(null);return k.useEffect(()=>{if(!r){d(!1);return}const _=`${t}\0${e}\0${i}\0${o||""}`,w=_!==v.current;v.current=_,w&&l(null),m({quiet:!w});const x=n>0?setInterval(()=>m({quiet:!0}),n):null;return()=>{x&&clearInterval(x)}},[t,e,i,o,r,m,n,s]),{data:a,error:u,loading:h,reload:m}}const Ql=8,Y2=t=>[...(t==null?void 0:t.querySelectorAll('[role="menuitem"]:not(:disabled)'))||[]];function E1({x:t,y:e,anchorKey:i,label:r,keyboard:s=!1,children:n}){const o=k.useRef(null),[a,l]=k.useState({left:t,top:e,visibility:"hidden"});k.useLayoutEffect(()=>{var h;const c=(h=o.current)==null?void 0:h.getBoundingClientRect();c&&l({left:Math.max(Ql,Math.min(t,window.innerWidth-c.width-Ql)),top:Math.max(Ql,Math.min(e,window.innerHeight-c.height-Ql)),visibility:"visible"})},[t,e,i]),k.useEffect(()=>{var c;s&&a.visibility==="visible"&&((c=Y2(o.current)[0])==null||c.focus())},[s,a.visibility,i]);const u=k.useCallback(c=>{const h=Y2(o.current);if(!h.length)return;const d=c.key==="ArrowDown"?1:c.key==="ArrowUp"?-1:0,f=c.key==="Home"?0:c.key==="End"?h.length-1:null;if(!d&&f===null)return;if(c.preventDefault(),c.stopPropagation(),f!==null){h[f].focus();return}const m=h.indexOf(document.activeElement);h[m===-1?d>0?0:h.length-1:(m+d+h.length)%h.length].focus()},[]);return p.jsx("div",{ref:o,className:"sess-menu",role:"menu","aria-label":r,style:a,onClick:c=>c.stopPropagation(),onKeyDown:u,onMouseDownCapture:wa,children:n})}function Gu({children:t}){return p.jsx("div",{className:"sess-menu-group",role:"group",children:t})}function U6(){return p.jsx("div",{className:"sess-menu-sep",role:"separator"})}function Ci({icon:t,leading:e,danger:i=!1,hint:r=null,className:s="",children:n,...o}){if(!t&&!e)throw new Error("context menu item requires an icon or leading glyph");const a=["sess-menu-item",i&&"danger",s].filter(Boolean).join(" ");return p.jsxs("button",{type:"button",role:"menuitem",className:a,...o,children:[p.jsx("span",{className:"sess-menu-icon",children:e??p.jsx(je,{name:t,size:14,className:"sess-menu-svg"})}),p.jsx("span",{className:"sess-menu-label",children:n}),r?p.jsx("span",{className:"sess-menu-hint","aria-hidden":"true",children:r}):null]})}const qR=t=>({kind:"graph-node",nodeId:t}),WR=t=>({kind:"spec",nodeId:t}),KR=t=>({kind:"session",sessionId:t}),VR=t=>({kind:"issue",issueId:t}),UR=(t,e)=>({kind:"review-list",page:t,query:e}),GR=(t,e=null)=>({kind:"eval",nodeId:t,scenario:e}),lf=(t,e,i)=>({kind:"session-eval",sessionId:t,nodeId:e,scenario:i}),oT=t=>({kind:"hash",hash:t});function tl(t){if(!t)return Vt("graph");if(t.kind==="hash")return t.hash;if(t.kind==="graph-node")return Vt("graph",t.nodeId);if(t.kind==="spec")return Vt("spec",t.nodeId);if(t.kind==="session")return Vt("sessions",t.sessionId);if(t.kind==="session-surface")return t.surface==="evals"?Vt("evals",null,{q:ep(t.sessionId)}):Vt("sessions",t.sessionId,{surface:t.surface});if(t.kind==="session-eval"){const e=t.nodeId&&t.scenario?`${t.nodeId}/${t.scenario}`:null;return Vt("evals",e,{q:e?`scope:${t.sessionId}`:ep(t.sessionId)})}return t.kind==="issue"?Vt("issues",t.issueId):t.kind==="review-list"?Vt(t.page,null,t.query?{q:t.query}:null):t.kind==="eval"?t.scenario?Vt("evals",`${t.nodeId}/${t.scenario}`):Vt("evals",null,{q:i_(t.nodeId)}):Vt("graph")}function aT(t){const{page:e,param:i,query:r}=bf(tl(t));return{page:e,param:i,query:r}}const lT=(t,e=window.location.href)=>new URL(tl(t),e).href;function uT(t){var s;const e=document.activeElement,i=document.createElement("textarea");i.value=t,i.style.cssText="position:fixed;left:-9999px;top:0",document.body.append(i),i.select();let r=!1;try{r=document.execCommand("copy")}catch{}return i.remove(),(s=e==null?void 0:e.focus)==null||s.call(e),r}async function cT(t){var e;try{if((e=navigator.clipboard)!=null&&e.writeText)return await navigator.clipboard.writeText(t),!0}catch{}return uT(t)}const hT=t=>cT(lT(t));function YR(t,e=null){return t==="issues"?Vt("issues"):e?tl(lf(e)):Vt("evals")}function XR(t,{onOpenSession:e}={}){if(t)if(t.kind==="session")e?e(t.sessionId):wn("sessions",t.sessionId);else{const{page:i,param:r,query:s}=bf(tl(t));wn(i,r,{query:s})}}const X2={issue:{open:{icon:"issue-opened",tone:"open",label:"reviewState.issueOpen"},closed:{icon:"issue-closed",tone:"closed",label:"reviewState.issueClosed"}},eval:{pass:{icon:"circle-check",tone:"pass",label:"score.pass"},fail:{icon:"circle-x",tone:"fail",label:"score.fail"},stalePass:{icon:"circle-check-dashed",tone:"stale",label:"score.stalePass"},staleFail:{icon:"circle-x-dashed",tone:"stale",label:"score.staleFail"},review:{icon:"clock",tone:"review",label:"reviewList.needsReview"},empty:{icon:"circle-minus",tone:"empty",label:"score.empty"},missing:{icon:"circle-dashed",tone:"empty",label:"score.missing"},legacy:{icon:"circle-minus",tone:"empty",label:"score.empty"}}},dT=(t,e)=>{var r;const i=t==="issue"?e==="open"?"open":"closed":e||"empty";return((r=X2[t])==null?void 0:r[i])||X2.eval.empty};function io({kind:t,state:e,showLabel:i=!1,size:r=16,className:s="",title:n}){const o=He(),a=dT(t,e),l=n||o(a.label);return p.jsxs("span",{className:`review-state ${t} ${a.tone} ${s}`,"data-tip":l,"aria-label":l,children:[p.jsx("span",{className:"review-state-icon",style:{width:r,height:r},children:p.jsx(je,{name:a.icon,size:r})}),i&&p.jsx("span",{className:"review-state-label",children:l})]})}function JR(t,e){const i={...t,...e};for(const[r,s]of Object.entries(i))(s==null||s==="")&&delete i[r];return i}const fT=t=>t&&typeof t=="object"?t.hasData?t.filtered:t.dataset:t,G6=(t,e,i)=>{const r=Array.isArray(t)?t:[];return!(e!=null&&String(e)!=="")||i==null||r.some(n=>String(n.value)==="")?r:[{value:"",label:i},...r]},pT=(t=[])=>t.reduce((e,i)=>((i.active??(i.value!=null&&String(i.value)!==""))&&(e.mobile+=1,i.mobileOnly||(e.desktop+=1)),e),{desktop:0,mobile:0}),D1=(t,e,i)=>e?i==="Home"?0:i==="End"?e-1:i==="ArrowDown"||i==="ArrowRight"?t<0?0:(t+1)%e:i==="ArrowUp"||i==="ArrowLeft"?t<0?e-1:(t-1+e)%e:t:-1,mT=(t,e)=>{var r;const i=t==null?void 0:t.tagName;return i==="INPUT"||i==="TEXTAREA"||i==="SELECT"||i==="BUTTON"&&(e==="Enter"||e===" ")||e==="Enter"&&((r=t==null?void 0:t.closest)!=null&&r.call(t,"a[href]"))?!1:e==="j"||e==="k"||e==="Enter"},Xc=t=>[...(t==null?void 0:t.querySelectorAll('[role="menuitemradio"]'))||[]].filter(e=>e.getClientRects().length>0),Jc=(t,e)=>{const i=t[e];if(i){for(const r of t)r.tabIndex=r===i?0:-1;i.focus()}};function Y6(){const[t,e]=k.useState(!1),i=k.useRef(null),r=k.useRef(null),s=k.useRef(null),n=k.useRef("checked"),o=(d=!1)=>{var f;d&&((f=s.current)==null||f.focus()),e(!1)},a=(d,f="checked")=>{s.current=d,n.current=f,e(!0)},l=d=>{t?o(!1):a(d)};return ni(t,()=>o(!0)),k.useEffect(()=>{if(!t)return;const d=f=>{var m;(m=i.current)!=null&&m.contains(f.target)||o(!1)};return window.addEventListener("pointerdown",d,!0),()=>window.removeEventListener("pointerdown",d,!0)},[t]),k.useEffect(()=>{if(!t)return;const d=requestAnimationFrame(()=>{const f=Xc(r.current),m=f.findIndex(_=>_.getAttribute("aria-checked")==="true"),v=n.current==="last"?f.length-1:n.current==="first"?0:m>=0?m:0;Jc(f,v)});return()=>cancelAnimationFrame(d)},[t]),{open:t,ref:i,menuRef:r,close:o,toggle:l,onTriggerKeyDown:d=>{d.key!=="ArrowDown"&&d.key!=="ArrowUp"||(d.preventDefault(),d.stopPropagation(),a(d.currentTarget,d.key==="ArrowUp"?"last":"first"))},onMenuKeyDown:d=>{if(!["ArrowDown","ArrowUp","Home","End"].includes(d.key))return;const f=Xc(r.current),m=f.indexOf(document.activeElement);d.preventDefault(),d.stopPropagation(),Jc(f,D1(m,f.length,d.key))},onItemFocus:d=>{const f=Xc(r.current);Jc(f,f.indexOf(d.currentTarget))}}}function ZR({label:t,value:e="",options:i=[],onChange:r,mobile:s=!1,clearLabel:n}){const o=Y6(),a=G6(i,e,n);if(!a.length)return null;const l=a.find(h=>String(h.value)===String(e)),u=e?(l==null?void 0:l.label)||String(e):"",c=u?`${t}: ${u}`:t;return p.jsxs("div",{className:`rl-facet-wrap ${s?"mobile-stay":""}`,ref:o.ref,children:[p.jsxs("button",{type:"button",className:`rl-facet ${e?"active":""}`,"aria-label":c,"aria-haspopup":"menu","aria-expanded":o.open,onClick:h=>o.toggle(h.currentTarget),onKeyDown:o.onTriggerKeyDown,children:[p.jsx("span",{className:"rl-facet-label",children:c}),s&&p.jsx("span",{className:"rl-facet-label-mobile","aria-hidden":"true",children:u||t}),p.jsx(je,{name:"chevron-down",size:12})]}),o.open&&p.jsx("div",{className:"rl-menu",role:"menu","aria-label":t,ref:o.menuRef,onKeyDown:o.onMenuKeyDown,children:a.map(h=>p.jsxs("button",{type:"button",role:"menuitemradio","aria-checked":String(h.value)===String(e),tabIndex:-1,className:"rl-menu-item",onFocus:o.onItemFocus,onClick:()=>{o.close(!0),r(h.value)},children:[p.jsx(je,{name:String(h.value)===String(e)?"check":"blank",size:13}),p.jsx("span",{children:h.label}),h.count!=null&&p.jsx("span",{className:"rl-menu-count",children:h.count})]},String(h.value)))})]})}function gT({label:t,groups:e=[],clearLabel:i,compact:r=!1,className:s=""}){const n=He(),o=k.useId(),a=e.map(d=>({...d,options:G6(d.options,d.value,d.clearLabel===null?null:d.clearLabel||i)})).filter(d=>d.options.length),l=a.some(d=>!d.mobileOnly),u=pT(a),c=Y6();if(!a.length)return null;const h=(d,f)=>d>0&&p.jsxs("span",{className:`rl-secondary-filter-count ${f}`,children:[p.jsx("span",{"aria-hidden":"true",children:d}),p.jsx("span",{className:"sr-only",children:n("reviewList.activeFilters",{n:d})})]});return p.jsxs("div",{className:`rl-secondary-filters ${l?"":"mobile-only"} ${u.desktop?"active-desktop":""} ${u.mobile?"active-mobile":""} ${s}`,ref:c.ref,children:[r?p.jsx(Zt,{icon:"filter",size:16,className:"rl-secondary-filters-trigger compact",label:t,"aria-haspopup":"menu","aria-expanded":c.open,onClick:d=>c.toggle(d.currentTarget),onKeyDown:c.onTriggerKeyDown}):p.jsxs("button",{type:"button",className:"rl-secondary-filters-trigger","aria-haspopup":"menu","aria-expanded":c.open,onClick:d=>c.toggle(d.currentTarget),onKeyDown:c.onTriggerKeyDown,children:[p.jsx(je,{name:"filter",size:14}),p.jsx("span",{children:t}),h(u.desktop,"for-desktop"),h(u.mobile,"for-mobile"),p.jsx(je,{name:"chevron-down",size:12})]}),c.open&&p.jsx("div",{className:"rl-menu rl-secondary-filters-menu",role:"menu","aria-label":t,ref:c.menuRef,onKeyDown:c.onMenuKeyDown,children:a.map((d,f)=>p.jsxs("div",{role:"group","aria-labelledby":`${o}-group-${f}`,className:`rl-menu-group ${d.mobileOnly?"mobile-only":""}`,children:[p.jsx("div",{className:"rl-menu-label",id:`${o}-group-${f}`,children:d.label}),d.options.map(m=>p.jsxs("button",{type:"button",role:"menuitemradio","aria-checked":String(m.value)===String(d.value||""),tabIndex:-1,className:"rl-menu-item",onFocus:c.onItemFocus,onClick:()=>{c.close(!0),d.onChange(m.value)},children:[p.jsx(je,{name:String(m.value)===String(d.value||"")?"check":"blank",size:13}),p.jsx("span",{children:m.label}),m.count!=null&&p.jsx("span",{className:"rl-menu-count",children:m.count})]},String(m.value)))]},`${d.label}-${d.mobileOnly?"mobile":"all"}`))})]})}function QR({state:t,title:e,meta:i,aside:r}){return p.jsxs("div",{className:"rl-row-grid",children:[p.jsx("div",{className:"rl-row-state",children:t}),p.jsxs("div",{className:"rl-row-body",children:[p.jsx("div",{className:"rl-row-title",children:e}),i&&p.jsx("div",{className:"rl-row-meta",children:i})]}),r&&p.jsx("div",{className:"rl-row-aside",children:r})]})}const eu=t=>{const e=String(t??"").trim();return e?`${e} `:""};function vT({value:t="",onSubmit:e,placeholder:i,label:r,keys:s=[],suggest:n={}}){const[o,a]=k.useState(()=>eu(t)),[l,u]=k.useState(-1),[c,h]=k.useState(-1),d=k.useRef(null),f=k.useRef(null),m=k.useId(),v=k.useRef(null),_=E=>requestAnimationFrame(()=>{const L=d.current;L&&(E&&L.focus(),L.setSelectionRange(L.value.length,L.value.length))});k.useEffect(()=>{a(eu(t)),u(-1),h(-1),_(v.current!==null&&v.current!==t),v.current=t},[t]);const w=l>=0?r_(o,l,s,n):{start:0,end:0,items:[]},x=w.items.length>0;ni(x,()=>u(-1));const A=()=>{f.current&&d.current&&(f.current.scrollLeft=d.current.scrollLeft)};k.useEffect(A);const D=E=>{u(-1),h(-1);const L=E.trim();a(eu(L)||eu(t)),_(!0),e(L)},R=E=>{const L=`${o.slice(0,w.start)}${E.insert}${o.slice(w.end)}`;if(a(L),E.type==="value"){D(L);return}const q=w.start+E.insert.length;u(q),h(-1),requestAnimationFrame(()=>{var F,$;(F=d.current)==null||F.focus(),($=d.current)==null||$.setSelectionRange(q,q)})};return p.jsxs("form",{className:"rl-query rq",role:"search",onSubmit:E=>{E.preventDefault(),D(o)},children:[p.jsxs("div",{className:"rq-wrap",children:[p.jsx("div",{className:"rq-hl","aria-hidden":"true",ref:f,children:s_(o).map((E,L)=>E.ws||E.key==null||!s.includes(E.key)?p.jsx("span",{children:E.raw},L):p.jsxs("span",{className:"rq-tok",children:[p.jsx("span",{className:"rq-tok-key",children:E.raw.slice(0,E.key.length+1)}),p.jsx("span",{className:"rq-tok-val",children:E.raw.slice(E.key.length+1)})]},L))}),p.jsx("input",{ref:d,role:"combobox","aria-expanded":x,"aria-controls":m,"aria-autocomplete":"list","aria-activedescendant":x&&c>=0?`${m}-o${c}`:void 0,value:o,spellCheck:!1,autoComplete:"off",placeholder:i,"aria-label":r,onChange:E=>{a(E.target.value),u(E.target.selectionStart??E.target.value.length),h(-1)},onScroll:A,onKeyDown:E=>{x&&(E.key==="ArrowDown"||E.key==="ArrowUp"?(E.preventDefault(),h(D1(c,w.items.length,E.key))):E.key==="Enter"&&c>=0&&(E.preventDefault(),R(w.items[c])))},onBlur:()=>u(-1)})]}),x&&p.jsx("div",{className:"rl-menu rq-list",role:"listbox",id:m,"aria-label":r,children:w.items.map((E,L)=>p.jsxs("div",{id:`${m}-o${L}`,role:"option","aria-selected":L===c,className:`rq-opt ${L===c?"active":""}`,onPointerDown:q=>{q.preventDefault(),R(E)},children:[p.jsx("span",{className:"rq-opt-token",children:E.insert.trim()}),E.label&&E.label!==E.value&&p.jsx("span",{className:"rq-opt-label",children:E.label})]},E.insert))}),p.jsx("button",{type:"submit",className:"rl-query-submit","data-tip":r,"aria-label":r,children:p.jsx(je,{name:"search",size:16})})]})}function eN({value:t="",onChange:e,placeholder:i,searchLabel:r,filterLabel:s,groups:n,clearLabel:o,clearSearchLabel:a,summary:l,trailing:u=null}){const c=He(),h=p.jsxs("div",{className:"rf-compact",role:"search",children:[p.jsx("span",{className:"rf-search-icon",children:p.jsx(je,{name:"search",size:13})}),p.jsx("input",{value:t,onChange:f=>e(f.target.value),placeholder:i,"aria-label":r}),t&&p.jsx(Zt,{icon:"x",size:12,className:"rf-clear",label:a,onClick:()=>e("")}),p.jsx(gT,{label:s,clearLabel:o,groups:n,compact:!0,className:"rf-secondary-filters"})]});if(!l)return h;const d=c("reviewList.showing",{shown:l.shown,total:l.total});return p.jsxs("div",{className:"rf-row",children:[p.jsxs("span",{className:"rf-summary","data-tip":d,children:[p.jsx("span",{className:"sr-only",children:d}),p.jsx("span",{className:"rf-summary-full","aria-hidden":"true",children:d}),p.jsxs("span",{className:"rf-summary-compact","aria-hidden":"true",children:[l.shown,"/",l.total]})]}),h,u]})}function bT({page:t,pageCount:e,prev:i,next:r,hrefFor:s}){const n=He();if(e<=1&&t<=1)return null;const o=(a,l,u,c="")=>a==null?p.jsx("span",{className:`rl-page-link disabled ${c}`,"aria-disabled":"true",children:l}):p.jsx("a",{className:`rl-page-link ${c}`,href:s(a),rel:u,"aria-label":u?n(`reviewList.${u}Page`):n("reviewList.page",{n:a}),children:l});return p.jsxs("nav",{className:"rl-pagination","aria-label":n("reviewList.pagination"),children:[o(i,n("reviewList.previous"),"prev","direction"),nT(t,e).map((a,l)=>a==="gap"?p.jsx("span",{className:"rl-page-gap","aria-hidden":"true",children:"…"},`gap-${l}`):p.jsx("a",{className:"rl-page-link number",href:s(a),"aria-label":n("reviewList.page",{n:a}),"aria-current":a===t?"page":void 0,children:a},a)),o(r,n("reviewList.next"),"next","direction")]})}function _T({menu:t,onClose:e}){const i=He();if(k.useEffect(()=>{if(t)return window.addEventListener("click",e),window.addEventListener("contextmenu",e,!0),()=>{window.removeEventListener("click",e),window.removeEventListener("contextmenu",e,!0)}},[t,e]),ni(!!t,e),!t)return null;const r=s=>n=>{n.stopPropagation(),e(),s()};return p.jsxs(E1,{x:t.x,y:t.y,anchorKey:t.href,label:i("reviewList.rowMenu"),children:[p.jsx(Ci,{icon:"plus",onClick:r(()=>{const s=d5(t.href);L1(s.page,s.param,s.query)}),children:i("tabs.openInNewTab")}),p.jsx(Ci,{icon:"copy",onClick:r(()=>hT(oT(t.href))),children:i("reviewList.copyAddress")})]})}function tN({leading:t,error:e,loading:i=!1,title:r,action:s,search:n,sections:o=[],sectionMode:a="tabs",facets:l,secondaryFilters:u,rows:c,empty:h,pagination:d,children:f}){const m=He(),[v,_]=k.useState(null),[w,x]=k.useState(null),A=k.useId(),D=k.useRef({});D.current={rows:c,cur:v},_f($=>{if($.metaKey||$.ctrlKey||$.altKey||!mT($.target,$.key))return!1;const W=D.current.rows.filter(C=>C.href);if(!W.length)return!1;if($.key==="Enter"){const C=W.find(O=>O.key===D.current.cur);return C?($.preventDefault(),window.location.hash=C.href,!0):!1}$.preventDefault();const z=W.findIndex(C=>C.key===D.current.cur),j=z<0?$.key==="j"?0:W.length-1:Math.max(0,Math.min(W.length-1,z+($.key==="j"?1:-1)));return _(W[j].key),!0}),k.useEffect(()=>{var $;($=document.querySelector(".lp-row.cur"))==null||$.scrollIntoView({block:"nearest"})},[v]);const R=fT(h),E=Math.max(0,o.findIndex($=>$.active)),L=a==="tabs",q=`${A}-panel`,F=$=>`${A}-tab-${$}`;return p.jsxs(ru,{className:"lp-page",children:[t,p.jsxs("div",{className:"rl-content",children:[p.jsxs("div",{className:"rl-titlebar",children:[p.jsx("h1",{children:r}),s]}),n&&p.jsx(vT,{...n}),e&&p.jsx("div",{className:"fv-error lp-error",role:"alert",children:e}),p.jsxs("section",{className:"rl-list",children:[p.jsxs("header",{className:"lp-head",children:[p.jsx("div",{className:"rl-sections",role:L?"tablist":"group","aria-label":r,...L?{"aria-orientation":"horizontal"}:{},children:o.map(($,W)=>p.jsxs("button",{type:"button",role:L?"tab":void 0,"aria-selected":L?$.active:void 0,"aria-pressed":L?void 0:$.active,"aria-controls":L?q:void 0,id:L?F(W):void 0,tabIndex:L?W===E?0:-1:void 0,className:`rl-section ${$.active?"active":""}`,onClick:$.onSelect,onKeyDown:z=>{var O,T;if(!L||!["ArrowLeft","ArrowRight","Home","End"].includes(z.key))return;const j=[...z.currentTarget.closest('[role="tablist"]').querySelectorAll('[role="tab"]')],C=D1(j.indexOf(z.currentTarget),j.length,z.key);z.preventDefault(),z.stopPropagation(),(O=j[C])==null||O.focus(),(T=j[C])==null||T.click()},children:[p.jsx("span",{children:$.label}),p.jsx("span",{className:"rl-section-count",children:$.count}),$.countSuffix&&p.jsxs("span",{className:"rl-section-suffix","data-tip":$.countSuffix.text,children:[p.jsx("span",{className:"sr-only",children:$.countSuffix.text}),p.jsx("span",{className:"rl-section-suffix-full","aria-hidden":"true",children:$.countSuffix.text}),p.jsx("span",{className:"rl-section-suffix-compact","aria-hidden":"true",children:$.countSuffix.compact})]})]},$.key))}),p.jsxs("div",{className:"rl-facets",children:[l,u]})]}),p.jsxs("div",{className:"lp-rows",role:L?"tabpanel":"region",id:q,"aria-busy":i||void 0,"aria-labelledby":L?F(E):void 0,"aria-label":L?void 0:r,children:[c.length===0&&p.jsx("div",{className:"lp-empty",children:i?m("common.loading"):R}),c.map($=>p.jsxs("div",{className:`lp-row ${$.href?"":"inert"} ${$.cls||""} ${v===$.key?"cur":""}`,children:[$.href&&p.jsx("a",{className:"lp-row-link",href:$.href,onClick:W=>f5(W,$.href),onContextMenu:W=>{W.preventDefault(),x({x:W.clientX,y:W.clientY,href:$.href})},children:p.jsx("span",{className:"sr-only",children:$.label||$.key})}),$.content]},$.key))]})]}),d&&p.jsx(bT,{...d})]}),f,p.jsx(_T,{menu:w,onClose:()=>x(null)})]})}function iN({title:t,titleMeta:e,status:i,side:r,composer:s,missing:n,failure:o,listHref:a,listLabel:l,backHref:u,backLabel:c,children:h}){return o?p.jsxs(ru,{className:"ds-page ds-missing ds-failed",role:"alert",children:[p.jsx("div",{className:"ds-missing-note",children:o}),a&&p.jsx("a",{className:"ds-backlink",href:a,children:l})]}):n?p.jsxs(ru,{className:"ds-page ds-missing",children:[p.jsx("div",{className:"ds-missing-note",children:n}),a&&p.jsx("a",{className:"ds-backlink",href:a,children:l})]}):p.jsxs(ru,{className:"ds-page",children:[p.jsxs("header",{className:"ds-head",children:[u&&p.jsx("a",{className:"ds-back",href:u,"data-tip":c,"aria-label":c,children:p.jsx(je,{name:"arrow-left",size:16})}),p.jsxs("h1",{className:"ds-title",children:[t,e&&p.jsx("span",{className:"ds-title-meta",children:e})]})]}),i&&p.jsx("div",{className:"ds-status",children:i}),p.jsxs("div",{className:"ds-cols",children:[p.jsxs("div",{className:"ds-main",children:[h,s&&p.jsx("div",{className:"ds-compose",children:s})]}),p.jsx("aside",{className:"ds-side",children:r})]})]})}function rN({label:t,children:e}){return p.jsxs("div",{className:"ds-side-sec",children:[p.jsx("span",{className:"ds-side-label",children:t}),p.jsx("div",{className:"ds-side-body",children:e})]})}function sN({text:t,tip:e,dim:i=!1,mono:r=!1,href:s=null,external:n=!1,onClick:o=null,className:a="",lead:l=null,trail:u=null,label:c=null}){const h=`ds-val${i?" dim":""}${r?" mono":""}${s||o?" link":""}${a?` ${a}`:""}`,d=e??(typeof t=="string"?t:void 0),f=c?{"aria-label":c}:{},m=p.jsxs(p.Fragment,{children:[l,p.jsx("span",{className:"ds-val-text",children:t}),u]});return s?p.jsx("a",{className:h,href:s,"data-tip":d,...f,...n?{target:"_blank",rel:"noreferrer"}:{},children:m}):o?p.jsx("button",{type:"button",className:h,onClick:o,"data-tip":d,...f,children:m}):p.jsx("span",{className:h,"data-tip":d,children:m})}function yT(t){var e,i;return((e=t==null?void 0:t.verdict)==null?void 0:e.status)==="pass"?"check":((i=t==null?void 0:t.verdict)==null?void 0:i.status)==="fail"?"cross":null}function wT(t){const e=yT(t);return e?t.fresh?e==="cross"?"fail":"pass":e==="cross"?"staleFail":"stalePass":"empty"}function xT(t,e){if(!t)return[];const i=new Map;for(const r of e||[])i.has(r.scenario)||i.set(r.scenario,r);return t.map(r=>{const s=i.get(r.name)||null;return{...r,reading:s,state:s?wT(s):"missing"}})}function ST(t){return t.length?t.some(e=>e.state==="fail")?"fail":t.some(e=>e.state==="staleFail")?"staleFail":t.some(e=>e.state==="stalePass")?"stalePass":t.some(e=>e.state==="empty"||e.state==="missing")?"empty":"pass":null}const kT=t=>t.fail>0?"fail":t.staleFail>0?"staleFail":t.stalePass>0?"stalePass":t.empty>0?"empty":"pass";function nN({scenarios:t,evals:e,summary:i=null,href:r}){const s=He(),n=i?null:xT(t,e),o=(i==null?void 0:i.total)??n.length;if(!o)return null;const a=i?kT(i):ST(n),l=(i==null?void 0:i.pass)??n.filter(d=>d.state==="pass").length,u=s("score.count",{satisfied:l,total:o,outstanding:o-l}),c=p.jsxs(p.Fragment,{children:[p.jsx(je,{name:"check",size:11}),l,"/",o]});if(!r)return p.jsx("span",{className:`scenario-count ${a}`,"data-tip":u,"aria-label":u,children:c});const h=`${u} — ${s("score.openList")}`;return p.jsx("a",{className:`scenario-count ${a}`,href:r,"data-tip":h,"aria-label":h,children:c})}function Go({kind:t,state:e,cls:i,n:r,label:s}){return p.jsxs("span",{className:`ovc ${i}`,"data-tip":s,children:[p.jsx(io,{kind:t,state:e,title:s,size:11}),r]})}function oN({tags:t}){return t!=null&&t.length?p.jsx("span",{className:"tag-chips",children:t.map(e=>p.jsx("span",{className:"tag-chip",children:e},e))}):null}function aN({state:t,title:e}){return t?p.jsx(io,{kind:"eval",state:t,title:e,className:`score-badge ${t}`,size:14}):null}function J2({label:t,cmd:e}){const i=He(),[r,s]=k.useState(!1),n=()=>{var o;(o=navigator.clipboard)==null||o.writeText(e).then(()=>s(!0),()=>{})};return p.jsxs("div",{className:"sess-attach-row",children:[p.jsx("span",{className:"sess-attach-label",children:t}),p.jsx("input",{className:"sess-attach-cmd",readOnly:!0,value:e,spellCheck:!1,onFocus:o=>o.target.select()}),p.jsx("button",{type:"button",className:"sess-rename-btn sess-attach-copy",onClick:n,children:i(r?"sessionWindow.attachCopied":"sessionWindow.attachCopy")})]})}function CT({session:t,socket:e,onClose:i}){const r=He();if(ni(!!t,i),!t)return null;const s=`spex session attach ${t.id}`,n=`tmux -L ${e} attach -t ${t.id}`;return p.jsx(ua,{title:r("sessionWindow.attachTitle",{name:Hr(t)}),closeLabel:r("common.close"),className:"sess-rename-modal sess-attach-modal",onClose:i,children:p.jsxs("div",{className:"sess-attach",children:[p.jsx(J2,{label:r("sessionWindow.attachSpex"),cmd:s}),p.jsx(J2,{label:r("sessionWindow.attachTmux"),cmd:n})]})})}function AT({menu:t,closeRequest:e=null,onCloseRequestDone:i,onClose:r,onChanged:s,onLock:n,onError:o,onMultiSelect:a,onDetach:l}){const u=He(),[c,h]=k.useState(null),[d,f]=k.useState(null),[m,v]=k.useState(null),[_,w]=k.useState(null),[x,A]=k.useState("spexcode"),[D,R]=k.useState(""),[E,L]=k.useState({adapter:"claude",thread:"",tmux:"",worktree:"",branch:""}),[q,F]=k.useState(!1),$=k.useRef(null);k.useEffect(()=>{h4().then(te=>{te!=null&&te.tmuxSocket&&A(te.tmuxSocket)}).catch(()=>{})},[]),k.useEffect(()=>{if(!t)return;const te=de=>{var ke,Ye;(Ye=(ke=de.target)==null?void 0:ke.closest)!=null&&Ye.call(ke,'.sess-menu, [aria-haspopup="menu"]')||r()};return window.addEventListener("mousedown",te,!0),()=>window.removeEventListener("mousedown",te,!0)},[t,r]),ni(!!t,r),ni(!!c,()=>h(null)),ni(!!d,()=>f(null)),ni(!!m,()=>v(null)),k.useEffect(()=>{c&&requestAnimationFrame(()=>{var te;return(te=$.current)==null?void 0:te.select()})},[c]);const W=te=>{te.stopPropagation();const{id:de}=t.session;r(),L1("sessions",de)},z=te=>{te.stopPropagation(),n==null||n(t.session),r()},j=te=>{var de;te.stopPropagation(),R((((de=t.session.raw)==null?void 0:de.name)??t.session.name)||""),h(t.session),r()},C=te=>{te.stopPropagation(),a==null||a(t.session),r()},O=te=>{te.stopPropagation(),l==null||l(t.session),r()},T=te=>{te.stopPropagation(),w(t.session),r()},U=te=>{te.stopPropagation();const{id:de}=t.session;r(),Hi(`/api/sessions/${de}/resume`,{method:"POST"}).then(async ke=>{if(ke.ok)return;const Ye=await ke.json().catch(()=>null);o==null||o((Ye==null?void 0:Ye.error)||`session resume refused (HTTP ${ke.status})`)}).catch(ke=>o==null?void 0:o(ke instanceof Error?ke.message:String(ke))).finally(()=>s==null?void 0:s())},H=te=>{te.stopPropagation(),f(t.session),r()},re=te=>{te.stopPropagation();const{id:de}=t.session;L({adapter:"claude",thread:"",tmux:de,worktree:"",branch:""}),v(t.session),r()},G=te=>de=>L(ke=>({...ke,[te]:de.target.value})),X=async te=>{if(te.preventDefault(),!(q||!m)){F(!0);try{const de=await Hi(`/api/sessions/${m.id}/quarantine`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...E,thread:E.thread.trim()||null})}),ke=await de.json().catch(()=>null);if(!de.ok||(ke==null?void 0:ke.ok)===!1){o==null||o((ke==null?void 0:ke.error)||`session quarantine refused (HTTP ${de.status})`);return}v(null)}catch(de){o==null||o(de instanceof Error?de.message:String(de))}finally{F(!1),s==null||s()}}},oe=d||e,I=()=>{f(null),i==null||i()},Y=()=>{const{id:te}=oe;I(),Hi(`/api/sessions/${te}/close`,{method:"POST"}).then(async de=>{const ke=await de.json().catch(()=>null);(!de.ok||(ke==null?void 0:ke.ok)===!1)&&(o==null||o((ke==null?void 0:ke.error)||`session close refused (HTTP ${de.status})`))}).catch(de=>o==null?void 0:o(de instanceof Error?de.message:String(de))).finally(()=>s==null?void 0:s())},le=async te=>{if(te.preventDefault(),!q){F(!0);try{const de=await Hi(`/api/sessions/${c.id}/rename`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:D})}),ke=await de.json().catch(()=>null);(!de.ok||(ke==null?void 0:ke.ok)===!1)&&(s==null||s())}catch{}finally{F(!1),h(null)}}};return p.jsxs(p.Fragment,{children:[t&&p.jsxs(E1,{x:t.x,y:t.y,anchorKey:t.session.id,label:u("sessionWindow.menuLabel"),children:[p.jsxs(Gu,{children:[p.jsx(Ci,{icon:"plus",onClick:W,children:u("tabs.openInNewTab")}),p.jsx(Ci,{icon:"lock",onClick:z,children:u("sessionWindow.lock")}),p.jsx(Ci,{icon:"pencil",onClick:j,children:u("sessionWindow.rename")}),p.jsx(Ci,{icon:"list-checks",onClick:C,children:u("sessionWindow.select")}),t.session.parent&&p.jsx(Ci,{icon:"corner-up-left",onClick:O,children:u("sessionWindow.detach")}),t.session.liveness!=="offline"&&t.session.status!=="queued"&&p.jsx(Ci,{icon:"terminal",onClick:T,children:u("sessionWindow.attach")}),t.session.archived&&p.jsx(Ci,{icon:"star-filled",onClick:U,children:u("sessionWindow.resume")}),t.session.status==="corrupt"&&p.jsx(Ci,{icon:"archive",onClick:re,children:u("sessionWindow.quarantine")})]}),p.jsx(U6,{}),p.jsx(Gu,{children:p.jsx(Ci,{icon:"trash",danger:!0,onClick:H,children:u("sessionWindow.close")})})]}),p.jsx(CT,{session:_,socket:x,onClose:()=>w(null)}),c&&p.jsx(ua,{title:u("sessionWindow.renameTitle",{name:Hr(c)}),closeLabel:u("common.close"),className:"sess-rename-modal",onClose:()=>h(null),children:p.jsxs("form",{className:"sess-rename",onSubmit:le,children:[p.jsx("input",{ref:$,className:"sess-rename-input",value:D,autoFocus:!0,placeholder:u("sessionWindow.renamePlaceholder"),onChange:te=>R(te.target.value)}),p.jsxs("div",{className:"sess-rename-actions",children:[p.jsx("button",{type:"button",className:"sess-rename-btn",onClick:()=>h(null),children:u("common.cancel")}),p.jsx("button",{type:"submit",className:"sess-rename-btn sess-rename-save",disabled:q,children:u("common.save")})]})]})}),oe&&p.jsx(ua,{title:u("sessionWindow.closeTitle",{name:Hr(oe)}),closeLabel:u("common.close"),className:"sess-rename-modal",onClose:I,children:p.jsxs("div",{className:"sess-confirm",children:[p.jsx("p",{className:"sess-confirm-msg",children:u("sessionWindow.closeConfirm")}),p.jsxs("div",{className:"sess-rename-actions",children:[p.jsx("button",{type:"button",className:"sess-rename-btn",onClick:I,children:u("common.cancel")}),p.jsx("button",{type:"button",className:"sess-rename-btn danger",onClick:Y,autoFocus:!0,children:u("sessionWindow.close")})]})]})}),m&&p.jsx(ua,{title:u("sessionWindow.quarantineTitle"),closeLabel:u("common.close"),className:"sess-rename-modal",onClose:()=>v(null),children:p.jsxs("form",{className:"sess-rename",onSubmit:X,children:[p.jsxs("label",{children:[p.jsx("span",{children:u("sessionWindow.quarantineAdapter")}),p.jsx("input",{className:"sess-rename-input",value:E.adapter,onChange:G("adapter"),autoFocus:!0})]}),p.jsxs("label",{children:[p.jsx("span",{children:u("sessionWindow.quarantineThread")}),p.jsx("input",{className:"sess-rename-input",value:E.thread,onChange:G("thread")})]}),p.jsxs("label",{children:[p.jsx("span",{children:u("sessionWindow.quarantineTmux")}),p.jsx("input",{className:"sess-rename-input",value:E.tmux,onChange:G("tmux")})]}),p.jsxs("label",{children:[p.jsx("span",{children:u("sessionWindow.quarantineWorktree")}),p.jsx("input",{className:"sess-rename-input",value:E.worktree,onChange:G("worktree")})]}),p.jsxs("label",{children:[p.jsx("span",{children:u("sessionWindow.quarantineBranch")}),p.jsx("input",{className:"sess-rename-input",value:E.branch,onChange:G("branch")})]}),p.jsxs("div",{className:"sess-rename-actions",children:[p.jsx("button",{type:"button",className:"sess-rename-btn",onClick:()=>v(null),children:u("common.cancel")}),p.jsx("button",{type:"submit",className:"sess-rename-btn",disabled:q,children:u("sessionWindow.quarantineConfirm")})]})]})})]})}const ET=({size:t=12})=>p.jsx(je,{name:"lock",size:t});function DT(t){if(!(t!=null&&t.length))return null;const e={};return t.forEach(i=>{e[i.op]=(e[i.op]||0)+1}),Object.entries(e).map(([i,r])=>`${kC[i]}${r}`).join(" ")}function MT({guides:t=[],expandable:e,kin:i=0}){const r=e||t.length>0;return p.jsxs("span",{className:"sess-lead",children:[r&&p.jsx("span",{className:"sess-fold pod sess-fold-slot","aria-hidden":"true",children:i}),t.map((s,n)=>{const o=n===t.length-1?s?"tee":"elbow":s?"rail":"gap";return p.jsx("span",{className:`sess-rail ${o}`,"aria-hidden":"true"},n)})]})}function TT({expanded:t,rollup:e,kin:i,onToggle:r,inert:s=!1}){const n=`${t?"Hide":"Show"} ${i} nested session${i===1?"":"s"}`,o=t?{color:e,borderColor:e}:{background:e,borderColor:e};return s?p.jsx("span",{"aria-hidden":"true",className:`sess-fold pod sess-fold-control${t?" open":""}`,style:o,children:i}):p.jsx("button",{type:"button",tabIndex:-1,className:`sess-fold pod sess-fold-control${t?" open":""}`,style:o,"aria-expanded":t,"aria-label":n,"data-tip":n,onMouseDown:a=>a.preventDefault(),onClick:a=>{a.stopPropagation(),r()},children:i})}function Z2({item:t,activeId:e,selecting:i=!1,picked:r=new Set,dragging:s=!1,dropTarget:n=!1,onToggleFold:o,rowProps:a={},inert:l=!1,style:u}){const{s:c}=t,h=e===c.id,d=i&&r.has(c.id),f=t.expandable||t.depth?p.jsx(MT,{guides:t.guides,expandable:t.expandable,kin:t.kin}):null,m=t.expandable?{expanded:t.expanded,rollup:t.rollup,kin:t.kin}:null,v=`sess-tree-row si-tree-row${s?" dragging":""}${n?" drop-target":""}${l?" si-session-drag-ghost":""}`,_=`si-item${h&&!i?" on":""}${d?" picked":""}`,w=p.jsx(p.Fragment,{children:p.jsx(BT,{s:c,locked:!1,showAvatar:!1,lead:f})}),x={"--ov":U5(c.id),"--sess-fold-indent":`${t.depth*14}px`,...u};return p.jsxs("div",{className:v,"data-session-depth":t.depth,style:x,...l?{"aria-hidden":"true"}:{"data-session-drop-id":c.id},children:[p.jsxs("button",{type:"button",className:_,tabIndex:l?-1:void 0,...a,children:[i&&!l&&p.jsx("span",{className:`si-check${d?" on":""}`,"aria-hidden":"true"}),w]}),m&&p.jsx(TT,{...m,inert:l,onToggle:o})]})}function lN(){const[t,e]=k.useState(()=>new Set),i=s=>e(n=>{const o=new Set(n);return o.has(s)?o.delete(s):o.add(s),o}),r=k.useCallback(s=>e(n=>{const o=s.filter(l=>l&&!n.has(l));if(!o.length)return n;const a=new Set(n);return o.forEach(l=>a.add(l)),a}),[]);return{expanded:t,toggle:i,expand:r}}function BT({s:t,locked:e,showAvatar:i=!0,lead:r=null}){const s=He(),n=DT(t.ops),o=o0(t),a=Hr(t),l=s(`status.${o.status}`);return p.jsxs(p.Fragment,{children:[r,i&&p.jsx(n1,{seed:t.id,status:o.status,title:`${b4(t)} · ${l} — ${t.id.slice(0,8)}`}),p.jsxs("span",{className:"sess-meta",children:[p.jsx("span",{className:"sess-glyph",style:{color:o.color},"data-tip":t.note?`${l} · ${t.note}`:l,"aria-label":t.note?`${l} · ${t.note}`:l,children:o.glyph}),n&&p.jsx("span",{className:"sess-ops",children:n})]}),p.jsx("span",{className:"sess-id","data-tip":a,children:a}),t.archiveHazard&&p.jsx("span",{className:"sess-hazard","data-tip":t.archiveHazard,"aria-label":t.archiveHazard,children:p.jsx(je,{name:"issue-opened",size:13})}),e&&p.jsx("span",{className:"sess-lock","data-tip":s("sessionWindow.lockedTitle"),children:p.jsx(ET,{})})]})}function RT({item:t,baseClass:e,onToggle:i}){const r=He(),s=t.zone==="offline"||t.zone==="archive",n=`${e} ${e}-${t.zone}${s?` si-zone-fold${t.folded?"":" open"}`:""}${t.dropTarget?" drop-target":""}`;if(!s)return p.jsxs("div",{className:n,children:[t.count>0&&p.jsx("span",{className:"si-zone-count","aria-hidden":"true",children:t.count}),p.jsx("span",{className:"si-zone-label",children:r(`sessionZone.${t.zone}`)})]});const o=t.zone==="archive"?r(t.folded?"sessionZone.showArchive":"sessionZone.hideArchive",{n:t.count}):r(t.folded?"sessionZone.showHistory":"sessionZone.hideHistory",{n:t.count});return p.jsxs("button",{type:"button",className:n,"aria-expanded":!t.folded,"aria-label":o,"data-tip":o,"data-archive-count":t.zone==="archive"?t.count:void 0,"data-session-archive-drop":t.zone==="archive"?"":void 0,"data-session-archive-zone":t.zone==="archive"?"":void 0,onClick:i,children:[(t.count>0||t.zone==="archive")&&p.jsx("span",{className:"si-zone-count","aria-hidden":"true",children:t.count}),p.jsx("span",{className:"si-zone-label",children:r(`sessionZone.${t.zone}`)})]})}function uN({sessions:t=[],activeId:e=null,onPick:i,onOpenSession:r,onNew:s}){const n=He(),[o,a]=k.useState(!1);ni(o,()=>a(!1));const l=t.find(d=>d.source===e),u=(l?[l]:t).slice(0,3),c=d=>{if(d==="new"){a(!1),s==null||s();return}const f=t.find(m=>m.id===d);f&&(i==null||i(f))},h=d=>{a(!1),d!=="new"&&(r==null||r(d))};return p.jsxs("div",{className:"sess-badge",children:[p.jsxs("button",{type:"button",className:"sess-badge-trigger","aria-expanded":o,"aria-controls":"graph-session-picker","aria-label":n("sessionWindow.badgeLabel"),"data-tip":n("sessionWindow.badgeLabel"),onClick:()=>a(d=>!d),children:[p.jsx("span",{className:"sess-badge-face","aria-hidden":"true",children:u.map(d=>p.jsx(n1,{seed:d.id,status:d.status,size:15},d.id))}),p.jsx("span",{className:"sess-badge-count",children:t.length})]}),o&&p.jsx("div",{id:"graph-session-picker",className:"sess-badge-panel",role:"dialog","aria-label":n("sessionWindow.badgeLabel"),children:p.jsx(AC,{sessions:t,value:(l==null?void 0:l.id)||"",onChange:c,onOpen:h,includeNew:!0,filter:t.length>5,compact:!0,ariaLabel:n("sessionWindow.badgeLabel")})})]})}let dr={expanded:new Set,offlineOpen:!1};const uf=new Set,M1=t=>{dr=t,uf.forEach(e=>e())},NT=t=>(uf.add(t),()=>uf.delete(t)),X6=()=>k.useSyncExternalStore(NT,()=>dr,()=>dr),Zc=t=>{if(!t)return;const e=new Set(dr.expanded);e.has(t)?e.delete(t):e.add(t),M1({...dr,expanded:e})},LT=(t=[])=>{const e=new Set(dr.expanded);t.filter(Boolean).forEach(i=>e.add(i)),!(e.size===dr.expanded.size&&[...e].every(i=>dr.expanded.has(i)))&&M1({...dr,expanded:e})},OT=t=>{const e=!!t;e!==dr.offlineOpen&&M1({...dr,offlineOpen:e})};function PT({ids:t,onCancel:e,onClosed:i,onError:r}){const s=He(),[n,o]=k.useState(!1);ni(n,()=>o(!1));const a=()=>{o(!1),Promise.all(t.map(l=>Hi(`/api/sessions/${l}/close`,{method:"POST"}).then(async u=>{if(u.ok)return;const c=await u.json().catch(()=>null);throw new Error((c==null?void 0:c.error)||`session close refused (HTTP ${u.status})`)}))).then(()=>i==null?void 0:i()).catch(l=>{r==null||r(l instanceof Error?l.message:String(l)),i==null||i()})};return p.jsxs(p.Fragment,{children:[p.jsxs("div",{className:"si-selbar",children:[p.jsx("span",{className:"si-selcount",children:s("sessionSelect.selected",{n:t.length})}),p.jsx(Zt,{icon:"trash",size:14,className:"si-selaction danger",label:s("sessionSelect.close"),disabled:!t.length,onClick:()=>o(!0)}),p.jsx(Zt,{icon:"x",size:14,className:"si-selaction",label:s("common.cancel"),onClick:e})]}),n&&p.jsx(ua,{title:s("sessionSelect.closeTitle",{n:t.length}),closeLabel:s("common.close"),className:"sess-rename-modal",onClose:()=>o(!1),children:p.jsxs("div",{className:"sess-confirm",children:[p.jsx("p",{className:"sess-confirm-msg",children:s("sessionSelect.closeConfirm")}),p.jsxs("div",{className:"sess-rename-actions",children:[p.jsx("button",{type:"button",className:"sess-rename-btn",onClick:()=>o(!1),children:s("common.cancel")}),p.jsx("button",{type:"button",className:"sess-rename-btn danger",onClick:a,children:s("sessionSelect.close")})]})]})})]})}const FT=6,Q2="is-dragging";function e4(){const t=e=>{e.stopPropagation(),e.preventDefault()};window.addEventListener("click",t,!0),window.setTimeout(()=>window.removeEventListener("click",t,!0),0)}function cf(t,e,i){var r,s;return((s=(r=document.elementFromPoint(t,e))==null?void 0:r.closest)==null?void 0:s.call(r,i))||null}function J6(t,{threshold:e=FT,onStart:i,onMove:r,onDrop:s,onCancel:n}={}){if(t.button!==0)return()=>{};const o={x:t.clientX,y:t.clientY};let a=!1;const l=()=>{window.removeEventListener("mousemove",c,!0),window.removeEventListener("mouseup",h,!0),window.removeEventListener("keydown",d,!0),a&&document.body.classList.remove(Q2)},u=()=>{const f=a;l(),a=!1,f&&(e4(),n==null||n())};function c(f){const m={x:f.clientX,y:f.clientY};if(!a){if(Math.hypot(m.x-o.x,m.y-o.y)<e)return;a=!0,document.body.classList.add(Q2),i==null||i(m)}r==null||r(m)}function h(f){const m=a;l(),a=!1,m&&(e4(),s==null||s({x:f.clientX,y:f.clientY}))}function d(f){f.key==="Escape"&&u()}return window.addEventListener("mousemove",c,!0),window.addEventListener("mouseup",h,!0),window.addEventListener("keydown",d,!0),u}function IT(t,e,{min:i,max:r,dir:s=1}={}){const[n,o]=k.useState(()=>{try{const c=parseInt(localStorage.getItem(t),10);if(Number.isFinite(c))return Math.max(i,Math.min(r,c))}catch{}return e}),a=k.useRef(null),l=k.useCallback(c=>{c.preventDefault(),a.current={x:c.clientX,w:n};const h=f=>{const m=a.current;if(!m)return;const v=Math.max(i,Math.min(r,m.w+(f.clientX-m.x)*s));o(v)},d=()=>{a.current=null,window.removeEventListener("mousemove",h),window.removeEventListener("mouseup",d),document.body.classList.remove("is-resizing"),o(f=>{try{localStorage.setItem(t,String(Math.round(f)))}catch{}return f})};window.addEventListener("mousemove",h),window.addEventListener("mouseup",d),document.body.classList.add("is-resizing")},[t,n,i,r,s]),u=k.useCallback(()=>{o(e);try{localStorage.removeItem(t)}catch{}},[e,t]);return[n,l,u]}const ya={key:"spex.dockWidth",initial:204,min:180,max:460},t4=["spex.ftWidth","spex.siListWidth"];try{if(localStorage.getItem(ya.key)==null)for(const t of t4){const e=parseInt(localStorage.getItem(t),10);if(Number.isFinite(e)){localStorage.setItem(ya.key,String(e));break}}t4.forEach(t=>localStorage.removeItem(t))}catch{}function zT(t,e,i){if(!(i!=null&&i.altKey)||i.ctrlKey||i.metaKey)return null;const r=i.code||i.key;if(r!=="ArrowUp"&&r!=="ArrowDown")return null;const s=t.find(l=>l.type==="row"&&l.s.id===e);if(!s)return null;if(i.shiftKey)return{type:s.expandable?r==="ArrowDown"?"expand":"collapse":"noop",id:s.s.id};const n=t.filter(l=>l.type==="row"),o=n.findIndex(l=>l.s.id===e),a=n[o+(r==="ArrowDown"?1:-1)];return a?{type:"move",id:a.s.id}:{type:"noop"}}const Qc=.75;function jT({sessions:t=[],activeId:e,archiveActive:i=!1,closing:r=!1,opening:s=!1,onSelect:n,onArchive:o,onSearch:a,reload:l,onContextMenu:u,onError:c,selectRequest:h=null,onSelectRequestConsumed:d}){const f=He(),{expanded:m,offlineOpen:v}=X6(),[_,w]=k.useState(!1),[x,A]=k.useState(()=>new Set),[D,R]=k.useState(null),E=k.useRef(null),L=k.useRef(null),[q,F,$]=IT(ya.key,ya.initial,ya),W=k.useMemo(()=>Of(t,G=>m.has(G),{zoneFolded:G=>G==="offline"&&!v,keepVisible:G=>G.id===e}),[t,m,v,e]);_f(G=>{const X=zT(W,e,G);if(!X)return!1;if(G.preventDefault(),G.stopPropagation(),X.type==="move")n==null||n(X.id);else if(X.type==="expand"){const oe=W.find(I=>I.type==="row"&&I.s.id===X.id);oe&&!oe.expanded&&Zc(X.id)}else if(X.type==="collapse"){const oe=W.find(I=>I.type==="row"&&I.s.id===X.id);oe!=null&&oe.expanded&&Zc(X.id)}return!0},30);const z=k.useCallback(async(G,X)=>{const oe=t.find(I=>I.id===G);if(!(!oe||(oe.parent||null)===X))try{const I=await Hi("/api/sessions/reparent",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({children:[G],parent:X})}),Y=await I.json().catch(()=>null);if(!I.ok||(Y==null?void 0:Y.ok)===!1)throw new Error((Y==null?void 0:Y.error)||`session parent update refused (HTTP ${I.status})`);X&<([X]),l==null||l()}catch(I){c==null||c(I instanceof Error?I.message:String(I))}},[t,l,c]),j=k.useCallback((G,X)=>{const oe=cf(G.x,G.y,"[data-session-drop-id]");if(oe){const I=oe.dataset.sessionDropId;return I===X.id||I===X.parent||iw(t,I).includes(X.id)?void 0:I}return X.parent&&cf(G.x,G.y,"[data-session-root-drop]")?null:void 0},[t]),C=k.useCallback((G,X)=>{if(G.button!==0||_)return;const I=G.currentTarget.getBoundingClientRect(),Y={id:X.id,parent:X.parent||null,width:I.width,height:I.height,offsetX:G.clientX-I.left,offsetY:G.clientY-I.top,x:G.clientX,y:G.clientY,target:void 0,started:!1},le=de=>{Y.x=de.x,Y.y=de.y,Y.target=j(de,Y),R({...Y})},te=()=>{document.body.classList.remove("is-session-dragging"),R(null),E.current=null};E.current=J6(G,{onStart:de=>{Y.started=!0,document.body.classList.add("is-session-dragging"),le(de)},onMove:le,onDrop:de=>{const ke=j(de,Y);te(),ke!==void 0&&z(Y.id,ke)},onCancel:te})},[z,j,_]);k.useEffect(()=>()=>{var G;return(G=E.current)==null?void 0:G.call(E)},[]),k.useEffect(()=>{h&&(w(!0),A(new Set([h.id])),d==null||d())},[h,d]);const O=()=>{w(!1),A(new Set)},T=G=>A(X=>{const oe=new Set(X);return oe.has(G)?oe.delete(G):oe.add(G),oe}),U=()=>{O(),l==null||l()},H=D?W.find(G=>G.type==="row"&&G.s.id===D.id):null,re=!!(D!=null&&D.parent);return p.jsxs(p.Fragment,{children:[p.jsxs("aside",{className:r?"si-list dock-closing":"si-list","data-fold":s?"in":void 0,ref:L,style:{width:q},onMouseDownCapture:wa,"aria-hidden":r?"true":void 0,children:[_?p.jsx(PT,{ids:[...x],onCancel:O,onClosed:U,onError:c}):p.jsxs("div",{className:"si-toprow",children:[p.jsxs("button",{type:"button",className:`si-pill new${e==="new"?" on":""}`,"aria-label":f("session.newSessionTitle"),onClick:()=>n==null?void 0:n("new"),children:[p.jsx("span",{className:"si-pill-glyph",children:p.jsx(je,{name:"plus",size:14})}),p.jsx("span",{className:"si-pill-label",children:f("session.newSessionTitle")})]}),p.jsx("button",{type:"button",className:`si-pill archive${i?" on":""}`,"aria-label":f("session.archiveTitle"),"data-tip":f("session.archiveTitle"),onClick:o,children:p.jsx("span",{className:"si-pill-glyph",children:p.jsx(je,{name:"archive",size:14})})}),p.jsx("button",{type:"button",className:"si-pill search","aria-label":f("session.searchTitle"),"data-tip":f("session.searchTitle"),onClick:a,children:p.jsx("span",{className:"si-pill-glyph",children:p.jsx(je,{name:"search",size:14})})})]}),p.jsxs("div",{className:"si-session-scroll","data-session-scroll":!0,children:[re&&p.jsxs("div",{className:`si-root-drop${D.target===null?" on":""}`,"data-session-root-drop":!0,"data-tip":f("session.rootDrop"),"aria-label":f("session.rootDrop"),children:[p.jsx(je,{name:"corner-up-left",size:14}),p.jsx("span",{children:f("session.rootDrop")})]}),W.map(G=>{var oe;if(G.type==="zone")return p.jsx(RT,{item:G,baseClass:"si-zone",onToggle:()=>G.zone==="offline"?OT(!v):void 0},`zone-${G.zone}`);const X=G.s;return _&&x.has(X.id),p.jsx(Z2,{item:G,activeId:e,selecting:_,picked:x,dragging:(D==null?void 0:D.id)===X.id,dropTarget:(D==null?void 0:D.target)===X.id,onToggleFold:()=>Zc(X.id),rowProps:{"data-sid":X.id,"aria-grabbed":(D==null?void 0:D.id)===X.id||void 0,onMouseDown:I=>C(I,X),onClick:I=>_?T(X.id):n==null?void 0:n(X.id,{newTab:h5(I)}),onContextMenu:I=>{I.preventDefault(),I.stopPropagation(),_||u==null||u({x:I.clientX,y:I.clientY,session:X})},"data-tip":(oe=X.ops)!=null&&oe.length?f("session.opsTitle"):f("session.lockTitle")}},X.id)})]}),H&&p.jsx(Z2,{item:H,activeId:e,selecting:_,picked:x,inert:!0,style:{width:D.width,"--si-session-drag-ghost-scale":Qc,left:D.x-D.offsetX*Qc,top:D.y-D.offsetY*Qc}})]}),p.jsx("div",{className:"si-resizer",onMouseDownCapture:wa,onMouseDown:F,onDoubleClick:$,role:"separator","aria-orientation":"vertical","aria-label":f("session.resizeList")})]})}const Xn="terminal",Dr="conversation",la="diff",Yu="resource:",HT="spexcode.session-surface.v1",$T=new Set([Xn,Dr]),hf=new Set;let Z6=null;const Q6=(t=G5)=>`${HT}.${t||"root"}`,df=()=>({defaultSurface:Dr,sessions:{}}),Xu=t=>$T.has(t),qa=t=>typeof t=="string"&&t.startsWith(Yu)&&t.length>Yu.length,qT=t=>Xu(t)||t===la||qa(t),ff=t=>qa(t)?t.slice(Yu.length):null,i4=t=>`${Yu}${t}`,Bs=(t,e,i)=>`${t}:${e}:${i}`;function WT(t){const e=df();return!t||typeof t!="object"||(Xu(t.defaultSurface)&&(e.defaultSurface=t.defaultSurface),t.sessions&&typeof t.sessions=="object"&&!Array.isArray(t.sessions)&&(e.sessions=Object.fromEntries(Object.entries(t.sessions).filter(([,i])=>Xu(i))))),e}function T0(){try{const t=localStorage.getItem(Q6());return t?WT(JSON.parse(t)):df()}catch{return Z6||df()}}function e5(t){Z6=t;try{localStorage.setItem(Q6(),JSON.stringify(t))}catch{}for(const e of hf)e(t);return t}function t5(t){if(!Xu(t))throw new Error(`Invalid session base surface: ${t}`);return t}function cN(){return T0().defaultSurface}function tu(t){const e=T0();return e.sessions[t]||e.defaultSurface}function hN(t){const e=T0();return e5({...e,defaultSurface:t5(t)}).defaultSurface}function KT(t,e){if(!t)throw new Error("A session id is required to set its base surface");const i=T0();return e5({...i,sessions:{...i.sessions,[t]:t5(e)}}).sessions[t]}function VT(t){return hf.add(t),()=>hf.delete(t)}const i5=[{id:"nav.up",keys:["ArrowUp","k","K"],rebind:!1,desc:"legend.graph.move"},{id:"nav.down",keys:["ArrowDown","j","J"],rebind:!1,desc:"legend.graph.move"},{id:"nav.parent",keys:["ArrowLeft","h","H"],rebind:!1,desc:"legend.graph.parent"},{id:"nav.child",keys:["ArrowRight","l","L"],rebind:!1,desc:"legend.graph.child"},{id:"graph.zoomIn",keys:["+","="],rebind:!0,desc:"legend.graph.zoom"},{id:"graph.zoomOut",keys:["-","_"],rebind:!0,desc:"legend.graph.zoom"},{id:"graph.zoomReset",keys:["0"],rebind:!0,desc:"legend.graph.zoom"},{id:"graph.info",keys:["i","I","Enter"],rebind:!0,desc:"legend.graph.info"},{id:"graph.search",keys:["/"],rebind:!0,desc:"legend.graph.search"},{id:"graph.cycle",keys:["o"],rebind:!0,desc:"legend.graph.overlayCycle"},{id:"graph.cycleRev",keys:["O"],rebind:!0,desc:"legend.graph.overlayCycle"},{id:"graph.fresh",keys:["["],rebind:!0,desc:"legend.graph.fresh"},{id:"graph.evals",keys:["f"],rebind:!0,desc:"legend.graph.evals"},{id:"graph.newChild",keys:["n"],sequence:["n","n"],rebind:!1,desc:"legend.graph.newChild"},{id:"graph.del",keys:["d"],sequence:["d","d"],rebind:!1,desc:"legend.graph.del"},{id:"graph.settings",keys:[","],rebind:!0,desc:"legend.graph.settings"},{id:"graph.help",keys:["?"],rebind:!0,desc:"legend.graph.help"},{id:"shell.newSession",keys:["Alt+KeyN"],rebind:!1,desc:"legend.shell.newSession"},{id:"shell.evals",keys:["Alt+KeyF"],rebind:!1,desc:"legend.shell.evals"},{id:"shell.search",keys:["Alt+Slash"],rebind:!1,desc:"legend.shell.search"},{id:"shell.sessionPrevious",keys:["Alt+ArrowUp"],rebind:!1,desc:"legend.shell.sessionPrevious"},{id:"shell.sessionNext",keys:["Alt+ArrowDown"],rebind:!1,desc:"legend.shell.sessionNext"},{id:"shell.sessionExpand",keys:["Alt+Shift+ArrowDown"],rebind:!1,desc:"legend.shell.sessionExpand"},{id:"shell.sessionCollapse",keys:["Alt+Shift+ArrowUp"],rebind:!1,desc:"legend.shell.sessionCollapse"},{id:"shell.dockToggle",keys:["Alt+Shift+KeyE"],rebind:!1,desc:"legend.shell.dockToggle"},{id:"shell.dockMode",keys:["Alt+Shift+KeyM"],rebind:!1,desc:"legend.shell.dockMode"},{id:"shell.contextToggle",keys:["Alt+Shift+KeyC"],rebind:!1,desc:"legend.shell.contextToggle"},{id:"shell.tabClose",keys:["Alt+Shift+KeyX"],rebind:!1,desc:"legend.shell.tabClose"},{id:"shell.tabNext",keys:["Alt+Shift+ArrowRight"],rebind:!1,desc:"legend.shell.tabNext"},{id:"shell.tabPrevious",keys:["Alt+Shift+ArrowLeft"],rebind:!1,desc:"legend.shell.tabPrevious"},{id:"shell.tabSplit",keys:["Alt+Shift+Enter"],rebind:!1,desc:"legend.shell.tabSplit"},{id:"shell.commandBox",keys:["Alt+KeyI"],rebind:!1,desc:"legend.shell.commandBox"},{id:"explorer.menu",keys:["Shift+F10","ContextMenu"],rebind:!1,desc:"legend.explorer.menu"},{id:"explorer.openInNewTab",keys:["Alt+Enter"],rebind:!1,desc:"legend.explorer.openInNewTab"}],UT={ArrowUp:"↑",ArrowDown:"↓",ArrowLeft:"←",ArrowRight:"→",Enter:"⏎",Escape:"esc"," ":"␣","-":"−"},GT={Alt:"⌥",Ctrl:"⌃",Meta:"⌘",Shift:"⇧"},YT={Slash:"/",Backslash:"\\",Comma:",",Period:".",Semicolon:";",Quote:"'",Backquote:"`",Minus:"−",Equal:"=",BracketLeft:"[",BracketRight:"]",Space:"␣"},r4=t=>UT[t]||YT[t]||t.replace(/^Key([A-Z])$/,"$1").replace(/^Digit(\d)$/,"$1"),XT=t=>{if(typeof t!="string"||!t)return"";if(!t.includes("+"))return r4(t);const e=t.split("+"),i=e.pop();return e.map(r=>GT[r]||`${r}+`).join("")+r4(i)},JT=Object.fromEntries(i5.map(t=>[t.id,t])),dN=t=>{var e;return((e=JT[t])==null?void 0:e.sequence)||[]},ZT=(t,e=null)=>t!=null&&t.rebind?e||t.keys||[]:t!=null&&t.sequence?[t.sequence.join("")]:(t==null?void 0:t.keys)||[],T1="spex.keybindings.v1",r5=Object.fromEntries(i5.map(t=>[t.id,t]));function QT(){try{return JSON.parse(localStorage.getItem(T1))||{}}catch{return{}}}let yn=QT();function B1(t){var i;const e=yn[t];return e&&e.keys||((i=r5[t])==null?void 0:i.keys)||[]}function fN(t){return!!yn[t]}function eB(t,e){return B1(t).includes(e)}function tB(t){const e=[];return t.altKey&&e.push("Alt"),t.ctrlKey&&e.push("Ctrl"),t.metaKey&&e.push("Meta"),t.shiftKey&&e.push("Shift"),`${e.length?`${e.join("+")}+`:""}${t.code||t.key}`}function iB(t,e){return B1(t).includes(tB(e))||!e.altKey&&!e.ctrlKey&&!e.metaKey&&eB(t,e.key)}function rB(...t){const e=[];for(const i of t){const r=XT(ZT(r5[i],B1(i))[0]);r&&!e.includes(r)&&e.push(r)}return e.join(" · ")}function sB(t,...e){const i=rB(...e);return i?`${t} (${i})`:t}function pN(t,e){yn={...yn,[t]:{...yn[t],...e}},localStorage.setItem(T1,JSON.stringify(yn))}function mN(){yn={},localStorage.removeItem(T1)}const nB=/<!-- spexcode-selection (\{.*?\}) -->/g,R1=t=>t&&typeof t.path=="string"&&t.path&&Number.isInteger(t.startLine)&&t.startLine>0&&Number.isInteger(t.endLine)&&t.endLine>=t.startLine&&typeof t.text=="string"&&(t.node===void 0||typeof t.node=="string"&&!!t.node);function oB(t){if(!R1(t))throw new TypeError("invalid code selection");return`<!-- spexcode-selection ${JSON.stringify({...t.node?{node:t.node}:{},path:t.path,startLine:t.startLine,endLine:t.endLine,text:t.text})} -->`}function aB(t){const e=typeof t=="string"?t:"",i=[];return{text:e.replace(nB,(s,n)=>{try{const o=JSON.parse(n);if(R1(o))i.push(o);else return s}catch{return s}return""}).replace(/\n{3,}/g,`
|
|
@@ -332,4 +332,4 @@ l0,-`+(i+144)+`c-2,-159.3,-10,-310.7,-24,-454c-53.3,-528,-210,-949.7,
|
|
|
332
332
|
`).trim(),selections:i}}function lB(t,e=[]){const i=typeof t=="string"?t.trim():"",r=e.filter(R1).map(oB);return[i,...r].filter(Boolean).join(`
|
|
333
333
|
|
|
334
334
|
`)}function uB({selection:t,onRemove:e=null,className:i=""}){const r=He();if(!t)return null;const s=t.node||t.path,n=r("proseActions.lines",{a:t.startLine,b:t.endLine}),o=`${s}:${n}`;return p.jsxs("div",{role:"group",className:`selection-attachment${i?` ${i}`:""}`,"data-selection-attachment":!0,title:t.text||o,"aria-label":o,children:[p.jsx(je,{name:"file-diff",size:12,className:"selection-attachment-icon"}),p.jsx("span",{className:"selection-attachment-address",title:s,children:s}),p.jsx("span",{className:"selection-attachment-range",children:n}),e&&p.jsx(Zt,{icon:"x",size:12,className:"icon-btn selection-attachment-remove",label:r("session.removeCodeSelection"),onClick:e})]})}const cB=t=>{try{const e=new URL(t);return`${e.hostname.replace(/^\[|\]$/g,"")}:${e.port}${e.pathname==="/"?"":e.pathname}`}catch{return t}},hB=128,dB=t=>{const e=String(t||"").indexOf("/");return e>0?{node:t.slice(0,e),scenario:t.slice(e+1)}:{node:t||"",scenario:""}};function pf(t,{specs:e,sessions:i,names:r,t:s}){var n,o,a;if(t.page==="graph")return s("tabs.graph");if(t.page==="spec")return t.param?((n=e==null?void 0:e.find(l=>l.id===t.param))==null?void 0:n.title)||t.param:s("tabs.spec");if(t.page==="file")return((o=t.param)==null?void 0:o.split("/").pop())||s("tabs.graph");if(t.page==="evals")return s("tabs.evals");if(t.page==="issues")return s("tabs.issues");if(t.page==="sessions"){if(!t.param||t.param==="new")return s("tabs.sessions");const l=(i==null?void 0:i.find(h=>{var d;return h.id===t.param||((d=h.id)==null?void 0:d.startsWith(t.param))}))||o1(t.param),u=l?Hr(l):t.param.slice(0,8),c=(a=t.query)==null?void 0:a.surface;if(qa(c)){const h=ff(c),d=[...((l==null?void 0:l.files)||[]).map(f=>({id:Bs(l.id,"file",f),label:f.split("/").filter(Boolean).pop()||f})),...((l==null?void 0:l.web)||[]).map(f=>({id:Bs(l.id,"web",f.key),label:cB(f.url)}))].find(f=>f.id===h);return(d==null?void 0:d.label)||h}return u}return s(`tabs.${t.page}`)}function fB({tab:t,specs:e,sessions:i}){const r=t.page==="spec"?t.param:t.page==="evals"&&t.param?dB(t.param).node:null;if(r){const s=e==null?void 0:e.find(n=>n.id===r);return!s||!Ru[s.status]?null:p.jsx("i",{className:"tab-dot",style:{background:Ru[s.status].color}})}if(t.page==="sessions"&&t.param&&t.param!=="new"){const s=(i==null?void 0:i.find(o=>{var a;return o.id===t.param||((a=o.id)==null?void 0:a.startsWith(t.param))}))||o1(t.param);if((s==null?void 0:s.status)==="starting"||(s==null?void 0:s.status)==="queued")return p.jsx("i",{className:"tab-spinner","aria-hidden":"true",children:"⟳"});const n=s&&lr[s.status];return n?p.jsx("i",{className:"tab-dot",style:{background:n}}):null}return null}function pB({tab:t}){const e=QB(t.page)?ZB(t.page):null;return e?p.jsx(je,{name:e,size:13,className:"tab-kind-icon"}):null}function mB(t,e){const{page:i,param:r}=t||{};return i==="spec"||i==="file"||i==="sessions"&&r||(i==="evals"||i==="issues")&&r?pf(t,e):e.t(`place.${i}`)}function gB({specs:t,sessions:e,route:i,trailing:r=null,onSessionContextMenu:s=null}){const n=He(),[o,a]=k.useState([]),[l,u]=k.useState(!1),c=k.useRef(null),h=k.useCallback(T=>{var re;const U=Je(T);a(G=>{if(G.some(oe=>oe.key===U))return G;const X=d.current.findIndex(oe=>Je(oe)===U);return[...G,{key:U,tab:T,index:X}]});const H=(re=window.matchMedia)!=null&&re.call(window,"(prefers-reduced-motion: reduce)").matches?0:150;window.setTimeout(()=>a(G=>G.filter(X=>X.key!==U)),H)},[]),d=k.useRef([]),{tabs:f,activeKey:m,open:v,close:_,closeOthers:w,move:x}=p5({onCloseStart:h});d.current=f,k.useEffect(()=>{const T=c.current;if(!T||typeof ResizeObserver>"u")return;const U=()=>{const re=f.length*hB>T.clientWidth;u(G=>G===re?G:re)};U();const H=new ResizeObserver(U);return H.observe(T),()=>H.disconnect()},[f.length]);const A=Y5(),{splitTo:D}=yf(),R=X5(),[E,L]=k.useState(null),[q,F]=k.useState(null),$=k.useRef(null);k.useEffect(()=>()=>{var T;return(T=$.current)==null?void 0:T.call($)},[]),k.useEffect(()=>{if(!q)return;const T=U=>{var H,re;(re=(H=U.target)==null?void 0:H.closest)!=null&&re.call(H,".sess-menu")||F(null)};return window.addEventListener("click",T),window.addEventListener("contextmenu",T,!0),()=>{window.removeEventListener("click",T),window.removeEventListener("contextmenu",T,!0)}},[q]),ni(!!q,()=>F(null));const W=(T,U)=>{const H=d.current,re=cf(T.x,T.y,".tab");if(re){const I=H.findIndex(de=>Je(de)===re.dataset.tabKey);if(I<0)return;const Y=re.getBoundingClientRect(),te=T.x>Y.left+Y.width/2?H[I+1]?Je(H[I+1]):null:re.dataset.tabKey;return mf(H,U,te)===H?void 0:te}const G=c.current;if(!G||!H.length)return;const X=G.getBoundingClientRect();if(T.x<X.left||T.x>X.right||T.y<X.top||T.y>X.bottom)return;const oe=Math.max(...[...G.querySelectorAll(".tab")].map(I=>I.getBoundingClientRect().right));if(!(T.x<oe))return mf(H,U,null)===H?void 0:null},z=(T,U)=>{const H=Je(U),re=G=>{const X=W(G,H);X!==void 0&&x(H,X),L(oe=>oe&&oe.key===H&&oe.before===X?oe:{key:H,before:X})};$.current=J6(T,{onStart:re,onMove:re,onDrop:G=>{const X=W(G,H);L(null),$.current=null,X!==void 0&&x(H,X)},onCancel:()=>{L(null),$.current=null}})},j=Vt(i.page,i.param,i.query),C=[...R.values()].filter(T=>T.document===j).sort((T,U)=>(U.priority??0)-(T.priority??0)||T.id.localeCompare(U.id)),O=[...f];return o.filter(T=>!f.some(U=>Je(U)===T.key)).sort((T,U)=>T.index-U.index).forEach(T=>O.splice(Math.max(0,Math.min(T.index,O.length)),0,T.tab)),p.jsxs("div",{className:"tabstrip",children:[p.jsxs("div",{ref:c,className:`tabstrip-tabs${l?" wrapped":""}`,role:"tablist","aria-label":n("tabs.aria"),children:[!f.length&&p.jsx("span",{className:"tab-place",children:mB(i,{specs:t,sessions:e,names:A,t:n})}),O.map((T,U)=>{const H=Je(T),re=o.some(I=>I.key===H)&&!f.some(I=>Je(I)===H),G=H===m,X=pf(T,{specs:t,sessions:e,names:A,t:n}),oe=`${(E==null?void 0:E.key)===H?" tab-moving":""}${(E==null?void 0:E.before)===H?" tab-drop-before":""}${E&&E.before===null&&U===f.length-1?" tab-drop-after":""}`;return p.jsxs("div",{"data-tab-key":H,className:`tab${G?" on":""}${re?" tab-closing":""}${oe}`,role:"tab","aria-selected":G,"aria-grabbed":(E==null?void 0:E.key)===H||void 0,"aria-hidden":re?"true":void 0,onMouseDown:I=>{re||z(I,T)},onContextMenu:I=>{if(re)return;I.preventDefault();const Y=T.page==="sessions"&&T.param&&T.param!=="new"?(e==null?void 0:e.find(le=>{var te;return le.id===T.param||((te=le.id)==null?void 0:te.startsWith(T.param))}))||o1(T.param):null;Y&&s?(F(null),s({x:I.clientX,y:I.clientY,session:Y})):F({x:I.clientX,y:I.clientY,tab:T,key:H})},onAuxClick:I=>{!re&&I.button===1&&(I.preventDefault(),_(T))},children:[p.jsxs("button",{type:"button",className:"tab-face","data-tip":X,"aria-label":X,onClick:I=>{re||(I.altKey?D(T):v(T))},children:[p.jsx(pB,{tab:T}),p.jsx(fB,{tab:T,specs:t,sessions:e}),p.jsx("span",{className:"tab-label",children:X})]}),p.jsx("button",{type:"button",className:"tab-x",onClick:()=>{re||_(T)},"aria-label":n("tabs.close"),children:p.jsx(je,{name:"x",size:11})})]},H)})]}),(C.length>0||r)&&p.jsxs("div",{className:"tabstrip-actions",role:"toolbar","aria-label":n("documentActions.aria"),children:[C.map(T=>{const U=T.disabled&&T.disabledReason||T.label;return p.jsxs("div",{className:"document-action",children:[T.node||p.jsx(Zt,{icon:T.icon,size:14,label:U,className:`document-action-button${T.pressed?" on":""}${T.disabled?" disabled":""}`,"data-action":T.id,"aria-pressed":T.pressed,"aria-haspopup":T.haspopup?"menu":void 0,disabled:T.disabled,onClick:T.onClick}),T.menu]},T.key||`${T.document}:${T.id}`)}),r]}),q&&p.jsxs(E1,{x:q.x,y:q.y,anchorKey:q.key,label:n("tabs.menuLabel"),children:[p.jsxs(Gu,{children:[p.jsx(Ci,{icon:"x",danger:!0,onClick:T=>{T.stopPropagation(),F(null),_(q.tab)},children:n("tabs.menuClose")}),p.jsx(Ci,{icon:"circle-minus",danger:!0,onClick:T=>{T.stopPropagation(),F(null),w(q.tab)},children:n("tabs.menuCloseOthers")})]}),p.jsx(U6,{}),p.jsx(Gu,{children:p.jsx(Ci,{icon:"panel-right",onClick:T=>{T.stopPropagation(),F(null),D(q.tab)},children:n("tabs.menuSplit")})})]})]})}const vB=170;function bB(t,e=vB){const[i,r]=k.useState(!1),[s,n]=k.useState(!1),o=k.useRef(t);return k.useEffect(()=>{if(o.current===t)return;if(o.current=t,t){r(!1),n(!0);const l=setTimeout(()=>n(!1),e);return()=>clearTimeout(l)}n(!1),r(!0);const a=setTimeout(()=>r(!1),e);return()=>clearTimeout(a)},[t,e]),[t||i,i,s]}const hn=t=>{var e;return((e=t==null?void 0:t.capabilities)==null?void 0:e.headless)===!0},eh=t=>!(t!=null&&t.archived)&&(t==null?void 0:t.liveness)==="online",Ju=t=>{if(typeof(t==null?void 0:t.closedAt)!="string")return null;const e=Date.parse(t.closedAt);return Number.isFinite(e)?e:null},s4=t=>[...t].sort((e,i)=>{const r=Ju(e),s=Ju(i);return r==null&&s==null?e.id.localeCompare(i.id):r==null?1:s==null?-1:s-r||e.id.localeCompare(i.id)}),th=t=>{if(t==null)return"unknown";const e=new Date(t);return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`};function _B({sessions:t,onOpenSession:e,onClose:i}){const{lang:r,t:s}=p4(),[n,o]=k.useState(""),a=k.useRef(null),l=k.useRef([]);ni(!0,i);const u=k.useMemo(()=>{const x=n.trim().toLocaleLowerCase(r);return x?t.filter(A=>[Hr(A),A.label,A.id,A.node].filter(Boolean).some(D=>String(D).toLocaleLowerCase(r).includes(x))):t},[t,n,r]),c=k.useMemo(()=>{const x=[];for(const A of u){const D=th(Ju(A)),R=x[x.length-1];(R==null?void 0:R.key)===D?R.rows.push(A):x.push({key:D,rows:[A]})}return x},[u]),h=th(Date.now()),d=new Date;d.setDate(d.getDate()-1);const f=th(d),m=x=>x==="unknown"?s("session.archiveUnknownDate"):x===h?s("session.archiveToday"):x===f?s("session.archiveYesterday"):new Intl.DateTimeFormat(r,{year:"numeric",month:"long",day:"numeric"}).format(new Date(`${x}T12:00:00`)),v=x=>{const A=Ju(x);return A==null?"":new Intl.DateTimeFormat(r,{hour:"2-digit",minute:"2-digit"}).format(A)},_=c.flatMap(x=>x.rows);k.useEffect(()=>{var x;(x=a.current)==null||x.focus()},[]);const w=x=>{var R;if(x.key!=="ArrowDown"&&x.key!=="ArrowUp")return;x.preventDefault();const A=l.current.findIndex(E=>E===document.activeElement),D=Math.max(0,Math.min(_.length-1,A+(x.key==="ArrowDown"?1:-1)));(R=l.current[D])==null||R.focus()};return p.jsx("div",{className:"si-archive-backdrop","data-archive-backdrop":!0,onKeyDown:w,onMouseDown:x=>{x.target===x.currentTarget&&i()},children:p.jsxs("div",{className:"si-archive-page","data-archive-page":!0,role:"dialog","aria-modal":"true","aria-label":s("session.archiveTitle"),children:[p.jsxs("header",{className:"si-archive-head",children:[p.jsxs("div",{children:[p.jsx("h1",{children:s("session.archiveTitle")}),p.jsx("span",{children:s("session.archiveCount",{n:t.length})})]}),p.jsxs("label",{className:"si-archive-search",children:[p.jsx(je,{name:"search",size:15}),p.jsx("input",{ref:a,value:n,onChange:x=>o(x.target.value),placeholder:s("session.archiveSearch"),"aria-label":s("session.archiveSearch")})]})]}),p.jsxs("div",{className:"si-archive-index","data-archive-index":!0,children:[!c.length&&p.jsx("div",{className:"si-archive-empty",children:s("session.archiveEmpty")}),c.map(x=>p.jsxs("section",{className:"si-archive-group","data-archive-day":x.key,children:[p.jsx("h2",{className:"si-archive-date",children:m(x.key)}),x.rows.map(A=>p.jsxs("button",{ref:D=>{l.current[_.indexOf(A)]=D},type:"button",className:"si-archive-page-row","data-sid":A.id,onClick:()=>e(A.id),children:[p.jsx("span",{className:"si-archive-row-title",children:Hr(A)}),p.jsx("span",{className:"si-archive-row-node",children:A.node||A.label}),p.jsx("time",{dateTime:A.closedAt||void 0,children:v(A)}),p.jsx(je,{name:"chevron-right",size:14})]},A.id))]},x.key))]})]})})}const yB=()=>p.jsx(je,{name:"paperclip",size:15}),wB=()=>p.jsx(je,{name:"loader",size:15,className:"si-attach-busy"}),xB=["███████╗██████╗ ███████╗██╗ ██╗ ██████╗ ██████╗ ██████╗ ███████╗","██╔════╝██╔══██╗██╔════╝╚██╗██╔╝██╔════╝██╔═══██╗██╔══██╗██╔════╝","███████╗██████╔╝█████╗ ╚███╔╝ ██║ ██║ ██║██║ ██║█████╗ ","╚════██║██╔═══╝ ██╔══╝ ██╔██╗ ██║ ██║ ██║██║ ██║██╔══╝ ","███████║██║ ███████╗██╔╝ ██╗╚██████╗╚██████╔╝██████╔╝███████╗","╚══════╝╚═╝ ╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝"].join(`
|
|
335
|
-
`);function s5(){return p.jsx("pre",{className:"si-hero","aria-label":"SpexCode",children:xB})}function n4({outcome:t}){if(!t)return null;const e=t.phase==="failed"?"alert":"status";return p.jsx("div",{className:`si-action-outcome ${t.phase}`,role:e,children:t.message})}const Zu=t=>t.split("/").filter(Boolean).pop()||t,SB=t=>/\.(?:md|markdown)$/i.test(t);function kB({path:t,text:e}){return SB(t)?p.jsx(j3,{className:"si-file-markdown",children:e}):p.jsx("pre",{className:"si-file-text",children:e})}function CB({path:t,html:e}){return p.jsx("iframe",{className:"si-file-html",srcDoc:e,title:Zu(t)})}const ih=t=>{try{const e=new URL(t);return`${e.hostname.replace(/^\[|\]$/g,"")}:${e.port}${e.pathname==="/"?"":e.pathname}`}catch{return t}},AB=(t,e)=>`${e_}/web/${encodeURIComponent(t)}/${encodeURIComponent(e)}/`;function EB({options:t,onOpen:e}){const i=He();return p.jsx("div",{className:"document-action-menu",role:"menu","aria-label":i("session.resourceMenuLabel"),onMouseDown:r=>r.stopPropagation(),children:t.length?t.map(r=>p.jsxs("button",{type:"button",className:"si-resource-menu-row",role:"menuitem",onClick:()=>e(r),children:[p.jsx(je,{name:r.kind==="file"?"folder-open":"globe",size:13}),p.jsx("span",{children:r.label})]},r.id)):p.jsx("span",{className:"si-resource-menu-empty",children:i("session.resourceMenuEmpty")})})}function DB({document:t,action:e}){return Q5(t,e),null}function MB({document:t,actions:e}){return e.map(i=>p.jsx(DB,{document:t,action:i},i.id))}function TB({tab:t,active:e=!1,focusRequest:i=0,onEscape:r}){const s=He(),[n,o]=k.useState({phase:"loading"}),a=k.useRef(null),l=k.useRef(e),u=k.useRef(r);return l.current=e,u.current=r,k.useEffect(()=>{if(t.kind!=="file")return;let c=!1,h=null;const d=Di(`/api/sessions/${encodeURIComponent(t.sessionId)}/files/download?path=${encodeURIComponent(t.value)}&preview=1`);return o({phase:"loading"}),fetch(d).then(async f=>{if(!f.ok){const v=await f.json().catch(()=>null);throw new Error((v==null?void 0:v.error)||s("session.filePreviewFailed",{status:f.status}))}const m=f.headers.get("X-Spexcode-Preview-Kind");if(m==="image")h=URL.createObjectURL(await f.blob()),c||o({phase:"image",url:h});else{const v=await f.text();c||o({phase:m==="html"?"html":"text",text:v})}}).catch(f=>{c||o({phase:"error",message:f instanceof Error?f.message:String(f)})}),()=>{c=!0,h&&URL.revokeObjectURL(h)}},[t.kind,t.sessionId,t.value,t.revision,s]),k.useEffect(()=>{if(t.kind!=="web")return;const c=a.current;if(!c)return;let h=null;const d=v=>{var A;if(!(v.key==="Escape"||v.altKey&&!v.metaKey&&!v.ctrlKey))return;const w=new KeyboardEvent("keydown",{key:v.key,code:v.code,altKey:v.altKey,ctrlKey:v.ctrlKey,metaKey:v.metaKey,shiftKey:v.shiftKey,bubbles:!0,cancelable:!0}),x=!window.dispatchEvent(w);v.key==="Escape"?(v.preventDefault(),x||(A=u.current)==null||A.call(u)):x&&v.preventDefault()},f=()=>{h==null||h.removeEventListener("keydown",d,!0),h=c.contentWindow,h==null||h.addEventListener("keydown",d,!0)},m=()=>{f(),l.current&&document.visibilityState!=="hidden"&&requestAnimationFrame(()=>{var v;return(v=c.contentWindow)==null?void 0:v.focus()})};return c.addEventListener("load",m),f(),()=>{c.removeEventListener("load",m),h==null||h.removeEventListener("keydown",d,!0)}},[t.kind,t.revision]),k.useEffect(()=>{if(t.kind!=="web"||!e||document.visibilityState==="hidden")return;const c=requestAnimationFrame(()=>{var h,d;return(d=(h=a.current)==null?void 0:h.contentWindow)==null?void 0:d.focus()});return()=>cancelAnimationFrame(c)},[t.kind,t.revision,e,i]),t.kind==="web"?p.jsx("iframe",{ref:a,className:"si-resource-web",src:AB(t.sessionId,t.key),title:t.label},t.revision):p.jsxs("div",{className:`si-resource-file ${n.phase}`,"data-selectable":!0,children:[n.phase==="loading"&&p.jsx(je,{name:"loader",size:18,className:"si-attach-busy"}),n.phase==="error"&&p.jsx("p",{className:"si-file-preview-error",role:"alert",children:n.message}),n.phase==="text"&&p.jsx(kB,{path:t.value,text:n.text}),n.phase==="html"&&p.jsx(CB,{path:t.value,html:n.text}),n.phase==="image"&&p.jsx("img",{src:n.url,alt:Zu(t.value)})]})}function n5(t,e=!0,i=!1){var s;if(!t)return{phase:i?"dormant":"loading"};const r=t.phase==="ready"&&t.value?t.value:(s=t.lastKnown)==null?void 0:s.value;return e?t.phase==="ready"&&t.value?{phase:"ready",...t.value}:t.phase==="dormant"?r?{phase:"dormant",...r}:{phase:"dormant"}:t.phase==="updating"?r?{phase:"updating",...r}:{phase:"loading"}:t.phase==="error"?r?{phase:"error",...r}:{phase:"error"}:{phase:"loading"}:r?{phase:"disconnected",...r}:{phase:"disconnected"}}function BB({summary:t}){const e=He(),i=Number.isInteger(t.total);return!i&&t.phase==="loading"?p.jsx("span",{className:"si-eval-wait","data-tip":e("session.evalLoading"),children:p.jsx(je,{name:"loader",size:12,className:"si-eval-spinner"})}):!i&&t.phase==="dormant"?p.jsx("span",{className:"si-eval-wait",children:p.jsx(io,{kind:"eval",state:"missing",title:e("session.evalDormant"),size:12})}):i?p.jsxs("span",{className:`si-eval-stats ${t.phase}`,"aria-hidden":"true",children:[t.pass>0&&p.jsx(Go,{kind:"eval",state:"pass",cls:"st-pass secondary",n:t.pass,label:e("session.evalPass",{n:t.pass})}),t.fail>0&&p.jsx(Go,{kind:"eval",state:"fail",cls:"st-fail secondary",n:t.fail,label:e("session.evalFail",{n:t.fail})}),t.review>0&&p.jsx(Go,{kind:"eval",state:"review",cls:"st-review secondary",n:t.review,label:e("session.evalReview",{n:t.review})}),t.blind>0&&p.jsx(Go,{kind:"eval",state:"missing",cls:"st-empty blind",n:t.blind,label:e("session.evalBlind",{n:t.blind})}),t.unknown>0&&p.jsx(Go,{kind:"eval",state:"missing",cls:"st-empty blind",n:t.unknown,label:e("session.evalUnknown",{n:t.unknown})}),t.phase==="updating"&&p.jsx(je,{name:"loader",size:11,className:"si-eval-spinner si-eval-phase"}),t.phase==="dormant"&&p.jsx(io,{kind:"eval",state:"missing",title:e("session.evalDormantLast"),className:"si-eval-phase",size:11}),(t.phase==="disconnected"||t.phase==="error")&&p.jsx(io,{kind:"eval",state:"missing",title:e("session.evalUnavailable"),className:"si-eval-phase",size:11})]}):p.jsx("span",{className:"si-eval-wait",children:p.jsx(io,{kind:"eval",state:"missing",title:e("session.evalUnavailable"),size:12})})}function RB({launchers:t,launcher:e,pickLauncher:i}){const r=He(),[s,n]=k.useState(!1);ni(s,()=>n(!1));const o=t.find(u=>u.name===e),l=G2(o==null?void 0:o.harness).Glyph;return p.jsxs("div",{className:"si-launcher-picker",children:[p.jsxs("button",{type:"button",className:s?"si-launcher-btn on":"si-launcher-btn",onClick:()=>n(u=>!u),"aria-haspopup":"dialog","aria-expanded":s,"aria-label":r("session.launcherLabel"),"data-tip":r("session.launcherTip"),children:[p.jsx("span",{className:"si-launcher-harness","aria-hidden":"true",children:p.jsx(l,{})}),p.jsx("span",{className:"si-launcher-name",children:e})]}),s&&p.jsxs(p.Fragment,{children:[p.jsx("div",{className:"si-launcher-backdrop",onMouseDown:()=>n(!1)}),p.jsx("div",{className:"si-launcher-pop",role:"dialog","aria-modal":"true","aria-label":r("session.launcherLabel"),children:t.map(u=>{const c=G2(u.harness),h=c.Glyph;return p.jsxs("button",{type:"button",role:"menuitemradio","aria-checked":u.name===e,className:`si-launcher-row${u.name===e?" on":""}`,onClick:()=>{i(u.name),n(!1)},children:[p.jsxs("span",{className:"si-launcher-row-main",children:[p.jsx("span",{className:"si-launcher-harness","data-tip":c.label,"aria-hidden":"true",children:p.jsx(h,{})}),p.jsx("span",{className:"si-launcher-name",children:u.name}),u.name===e&&p.jsx(je,{name:"check",size:13,className:"si-launcher-check"})]}),u.cmd?p.jsx("span",{className:"si-launcher-cmd",children:u.cmd}):null]},u.name)})})]})]})}function o5({sessions:t,specs:e=[],focusNode:i,open:r,searchOpen:s=!1,sel:n,setSel:o,seed:a,onSeedConsumed:l,onClose:u,onPickSession:c,onOpenArchive:h,onOpenSearch:d,reload:f,boardLive:m=!1,archiveRequested:v=!1,surface:_=null,route:w=null}){const x=He(),A=e0(),{notify:D}=J5(),{lockGraphTo:R}=yf(),{dock:E}=m4(),[L,q,F]=bB(E),[$,W]=k.useState(""),[z,j]=k.useState([]),[C,O]=k.useState(null),[T,U]=k.useState(null),[H,re]=k.useState({}),{launchers:G,launcher:X,pickLauncher:oe}=Y3(),[I,Y]=k.useState(null),[le,te]=k.useState(!1),[de,ke]=k.useState(0),[Ye,Ct]=k.useState(0),[At,nt]=k.useState([]),{tabs:Be}=p5(),[vt,vr]=k.useState(()=>new Set),[ht,Yr]=k.useState(()=>new Set),[Pt,br]=k.useState(0),[qt,Ni]=k.useState(!1),Si=k.useRef(null),Wt=k.useRef(null),Gi=k.useRef({}),Yi=k.useRef(null),ce=k.useRef(null);k.useEffect(()=>VT(()=>br(M=>M+1)),[]);const Ae=k.useRef(null);k.useEffect(()=>{!I||I.phase==="pending"||I.phase==="sending"||(D(I.message,{kind:I.phase==="delivered"?"success":"error"}),Y(null))},[I,D]);const Re=()=>{Ae.current&&window.clearTimeout(Ae.current),Ae.current=null,te(!1),Y(M=>(M==null?void 0:M.owner)==="command"?null:M)},[$e,zn]=k.useState(null),[_r,il]=k.useState(null),Zs=k.useCallback(()=>{if(ce.current)return ce.current;const M=fetch(Di("/api/sessions/archive-index")).then(async K=>{if(!K.ok)throw new Error(`archive index refused (HTTP ${K.status})`);const V=await K.json(),_e=s4(Array.isArray(V)?V.map(Ce=>({...Ce,archived:!0})):[]);return zn(_e),_e}).catch(K=>(Y({owner:"panel",phase:"failed",message:K instanceof Error?K.message:String(K)}),[])).finally(()=>{ce.current=null});return ce.current=M,M},[]);k.useEffect(()=>{r&&$e===null&&Zs()},[r,$e,Zs]);const rl=k.useRef(null);k.useEffect(()=>{const M=new Set(t.map(V=>V.id)),K=rl.current;rl.current=M,r&&$e!==null&&K&&[...K].some(V=>!M.has(V))&&Zs()},[r,t,$e,Zs]);const Qs=k.useMemo(()=>{const M=new Map(t.map(K=>[K.id,K]));for(const K of $e||[])M.has(K.id)||M.set(K.id,K);return _r&&!M.has(_r.id)&&M.set(_r.id,_r),[...M.values()]},[t,$e,_r]),Xi=k.useRef(new Set);for(const M of Qs)Xi.current.add(M.id);const[Li,jn]=k.useState(null);k.useEffect(()=>{Li&&t.some(M=>M.id===Li.id)&&jn(null)},[t,Li]),k.useEffect(()=>{Li&&($e!=null&&$e.some(M=>M.id===Li.id))&&jn(null)},[$e,Li]);const Ft=k.useMemo(()=>!Li||Qs.some(M=>M.id===Li.id)?Qs:[...Qs,Li],[Qs,Li]);k.useEffect(()=>{_r&&t.some(M=>M.id===_r.id)&&il(null)},[t,_r]);const en=k.useMemo(()=>s4(Ft.filter(M=>M.archived)),[Ft]),Hn=k.useMemo(()=>new Set(["new",...Ft.map(M=>M.id)]),[Ft]),ye=Hn.has(n)||n!=="new"&&Xi.current.has(n)?n:"new",J=ye!=="new",{expanded:Q,offlineOpen:Ee}=X6(),Me=k.useMemo(()=>Of(t||[],M=>Q.has(M),{zoneFolded:M=>M==="offline"&&!Ee,keepVisible:M=>M.id===ye}),[t,Q,Ee,ye]),We=k.useMemo(()=>["new",...Me.filter(M=>M.type==="row").map(M=>M.s.id)],[Me]),Xe=k.useRef(new Set);k.useEffect(()=>{!r||n==="new"||Hn.has(n)||!Xi.current.has(n)||Xe.current.has(n)||(Xe.current.add(n),fetch(Di(`/api/sessions/${encodeURIComponent(n)}`)).then(async M=>{if(!M.ok){o("new");return}const K=await M.json();jn({...K,archived:K.archived===!0,liveness:K.archived===!0?"offline":K.liveness})}).catch(M=>{Y({owner:"panel",phase:"failed",message:M instanceof Error?M.message:String(M)}),o("new")}))},[r,n,Hn,o]);const Oe=(i==null?void 0:i.id)||null,Pe=Ft.find(M=>M.id===ye),[Oi,tn]=k.useState(!1);k.useEffect(()=>{v&&tn(!0)},[v]);const $n=hn(Pe),Lo=(Pe==null?void 0:Pe.liveness)==="offline",m5=!!(Pe!=null&&Pe.archived),O1=Lo||m5,Oo=qT(_)?_:null,g5=qa(Oo)?ff(Oo):null,gs=$n||O1?Dr:Oo||tu(ye),rn=gs===Dr,vs=gs===la,v5=M=>{const K=Ft.find(V=>V.id===M);return hn(K)?Dr:tu(M)},R0=!rn&&wg(Pe,{}).some(M=>M.name==="command"),bs=n5(J?Pe==null?void 0:Pe.evalSummary:null,m,!!Pe),b5=tm(Pe),P1=Pe?[...(Pe.files||[]).map(M=>({id:Bs(ye,"file",M),sessionId:ye,kind:"file",value:M,label:Zu(M),revision:0})),...(Pe.web||[]).map(M=>({id:Bs(ye,"web",M.key),sessionId:ye,kind:"web",key:M.key,value:M.url,label:ih(M.url),revision:0}))]:[],_s=J?g5:null,dt=At.find(M=>M.id===_s)||P1.find(M=>M.id===_s)||null,F1=P1.filter(M=>!Be.some(K=>{var V;return K.page==="sessions"&&K.param===ye&&((V=K.query)==null?void 0:V.surface)===i4(M.id)})),_5=M=>{Ct(K=>K+1),Re()},I1=M=>{nt(K=>K.some(V=>V.id===M.id)?K:[...K,M]),vr(K=>{if(!K.has(M.id))return K;const V=new Set(K);return V.delete(M.id),V}),_5(),Ni(!1),A.open({page:"sessions",param:M.sessionId,query:{surface:i4(M.id)}})},y5=M=>nt(K=>K.map(V=>V.id===M.id?{...V,revision:V.revision+1}:V)),z1=M=>Y({owner:"panel",phase:"failed",message:M instanceof Error?M.message:String(M)}),w5=async(M,K)=>{const V=Di(`/api/sessions/${encodeURIComponent(M)}/files/download?path=${encodeURIComponent(K)}`);try{const _e=await fetch(V,{method:"HEAD"});if(!_e.ok){const et=await _e.json().catch(()=>null);throw new Error((et==null?void 0:et.error)||x("session.fileDownloadFailed",{status:_e.status}))}const Ce=document.createElement("a");Ce.href=V,Ce.download=Zu(K),Ce.style.display="none",document.body.appendChild(Ce),Ce.click(),Ce.remove()}catch(_e){z1(_e)}},x5=async M=>{var K;try{if(!((K=navigator.clipboard)!=null&&K.writeText))throw new Error(x("session.fileCopyUnavailable"));await navigator.clipboard.writeText(M)}catch(V){z1(V)}};k.useEffect(()=>{const M=new Map;for(const _e of t)for(const Ce of _e.web||[]){const et={id:Bs(_e.id,"web",Ce.key),sessionId:_e.id,kind:"web",key:Ce.key,value:Ce.url,label:ih(Ce.url),revision:0};M.set(et.id,et)}const K=Yi.current;if(Yi.current=M,!K)return;const V=[...M].filter(([_e])=>!K.has(_e)).map(([,_e])=>_e);V.length&&vr(_e=>new Set([..._e,...V.map(Ce=>Ce.id)]))},[t]),k.useEffect(()=>{const M=new Set;for(const K of t){for(const V of K.files||[])M.add(Bs(K.id,"file",V));for(const V of K.web||[])M.add(Bs(K.id,"web",V.key))}nt(K=>K.filter(V=>M.has(V.id)))},[t]),k.useEffect(()=>{const M=new Set(Be.filter(K=>{var V;return K.page==="sessions"&&qa((V=K.query)==null?void 0:V.surface)}).map(K=>ff(K.query.surface)));_s&&M.add(_s),nt(K=>K.filter(V=>M.has(V.id)))},[Be,_s]),k.useEffect(()=>{!_s||!dt||nt(M=>M.some(K=>K.id===_s)?M:[...M,dt])},[_s,dt]);const sl=k.useMemo(()=>{const M=[];for(const K of t)for(const V of K.web||[]){const _e={id:Bs(K.id,"web",V.key),sessionId:K.id,kind:"web",key:V.key,value:V.url,label:ih(V.url),revision:0};vt.has(_e.id)&&M.push(_e)}return M},[t,vt]);Q1(sl.length?{id:"session-resource-unread",side:"right",priority:20,kind:"standard",text:x("session.unreadResources",{n:sl.length}),tooltip:x("session.unreadResources",{n:sl.length}),onClick:()=>I1(sl[0])}:null),ni(qt,()=>Ni(!1)),k.useEffect(()=>{if(!qt)return;const M=K=>{var V,_e;(_e=(V=K.target)==null?void 0:V.closest)!=null&&_e.call(V,'.document-action-menu, [data-action="resource-picker"]')||Ni(!1)};return window.addEventListener("mousedown",M,!0),()=>window.removeEventListener("mousedown",M,!0)},[qt]),ni(vs,()=>A.open({page:"sessions",param:ye,query:null},{replace:!0}));const nl=H[ye]||"",sn=M=>re(K=>({...K,[ye]:typeof M=="function"?M(K[ye]||""):M})),N0=M=>{M!=="new"&&(Re(),I0(),$1(K=>K.has(M)?K:new Set(K).add(M)),o(M))},L0=(M,K,V=!1)=>{M!=="new"&&(N0(M),K===Dr?Yr(_e=>_e.has(M)?_e:new Set(_e).add(M)):ke(_e=>_e+1),(V||M===ye)&&A.open({page:"sessions",param:M,query:{surface:K}},{replace:!0}))},S5=J3(Pe==null?void 0:Pe.harness),j1=X3();k.useEffect(()=>{Ae.current&&window.clearTimeout(Ae.current),Ae.current=null,te(!1),Y(null),I0()},[ye]),k.useEffect(()=>{R0||Re()},[R0]),k.useEffect(()=>()=>{Ae.current&&window.clearTimeout(Ae.current)},[]);const[H1,$1]=k.useState(()=>new Set);k.useEffect(()=>{$1(M=>{const K=new Set([...M].filter(V=>{const _e=Ft.find(Ce=>Ce.id===V);return _e&&!hn(_e)&&eh(_e)}));for(const V of Ft)!hn(V)&&eh(V)&&K.add(V.id);if(ye!=="new"){const V=t.find(_e=>_e.id===ye);V&&hn(V)&&K.add(ye)}return K.size===M.size&&[...K].every(V=>M.has(V))?M:K})},[Ft,ye]),k.useEffect(()=>{Yr(M=>{const K=new Set(Ft.map(Ce=>Ce.id)),V=new Set([...M].filter(Ce=>K.has(Ce))),_e=ye==="new"?null:Ft.find(Ce=>Ce.id===ye);return _e&&(!eh(_e)||hn(_e)||rn)&&V.add(_e.id),V.size===M.size&&[...V].every(Ce=>M.has(Ce))?M:V})},[Ft,ye,rn,Pt]),k.useEffect(()=>{if(a==null)return;o("new");const M=aB(a);W(M.text),j(M.selections),I0(),l==null||l(),requestAnimationFrame(()=>{const K=Si.current;K&&(K.focus(),K.setSelectionRange(a.length,a.length))})},[a]),k.useEffect(()=>{if(!r)return;const M=setTimeout(()=>{var K,V;ye==="new"?(K=Si.current)==null||K.focus():le&&((V=Wt.current)==null||V.focus())},0);return()=>clearTimeout(M)},[r,ye,le]);const O0=()=>{const M=lB($,z);M&&(W(""),j([]),VC(M,X).then(K=>{var V,_e,Ce,et,Et,Wn;K.ok&&K.id?(il({id:K.id,...K.session||{},label:((V=K.session)==null?void 0:V.label)||M.split(/\s+/).slice(0,8).join(" ")||K.id,title:((_e=K.session)==null?void 0:_e.title)||((Ce=K.session)==null?void 0:Ce.label)||M.split(/\s+/).slice(0,8).join(" ")||K.id,status:((et=K.session)==null?void 0:et.status)||"queued",liveness:((Et=K.session)==null?void 0:Et.liveness)||"offline",archived:!1,capabilities:((Wn=K.session)==null?void 0:Wn.capabilities)||{headless:!0}}),N1("sessions",K.id,null),A.open({page:"sessions",param:K.id,query:null}),f==null||f()):K.ok||D(K.error||x("session.launchFailed"),{kind:"error"})}))},q1=async()=>{const M=nl;if(!M.trim()||ye==="new")return;const K=W3(M,A5);if(K){sn(""),ys.close(),K.run();return}const V=q3(M,e);if((I==null?void 0:I.owner)==="command"&&I.phase==="sending")return;const _e=Gi.current[ye]||crypto.randomUUID();Gi.current[ye]=_e,Y({owner:"command",phase:"sending",message:x("session.outcomeSending")});const Ce=new AbortController,et=window.setTimeout(()=>Ce.abort(),Z5);try{const{ok:Et,status:Wn,outcome:ei}=await f4(ye,V,{deliveryId:_e,signal:Ce.signal});if(!Et){if(ei!=null&&ei.deliveryPending){Y({owner:"command",phase:"queued",message:x("session.outcomeQueued")});return}Y({owner:"command",phase:"failed",message:(ei==null?void 0:ei.error)||x("session.deliveryFailed",{status:Wn})});return}if((ei==null?void 0:ei.delivery)==="queued"){Y({owner:"command",phase:"queued",message:x("session.outcomeQueued")});return}sn(ll=>ll===M?"":ll),delete Gi.current[ye];const H0=(ei==null?void 0:ei.mentionSummary)||((ei==null?void 0:ei.delivery)==="deferred"?x("session.outcomeAccepted"):x("session.outcomeDelivered"));Y({owner:"command",phase:"delivered",message:H0}),Ae.current=window.setTimeout(()=>Re(),650)}catch(Et){if(Ce.signal.aborted){Y({owner:"command",phase:"failed",message:x("session.outcomeUnconfirmed")});return}Y({owner:"command",phase:"failed",message:Et instanceof Error?Et.message:String(Et)})}finally{window.clearTimeout(et)}},k5=()=>z.length?p.jsx("div",{className:"si-code-selection-queue","aria-label":x("session.codeSelectionAttachments"),children:z.map((M,K)=>p.jsx(uB,{selection:M,onRemove:()=>j(V=>V.filter((_e,Ce)=>Ce!==K))},`${M.path}:${M.startLine}:${M.endLine}:${K}`))}):null,P0=async(M,K,V="panel",_e={})=>{Y({owner:V,phase:"pending",message:x("session.outcomeWorking")});let Ce=!0;try{const et=await fetch(Di(`/api/sessions/${ye}/${M}`),K?{method:"POST",headers:{"content-type":"application/json",..._e},body:JSON.stringify(K)}:{method:"POST",headers:_e}),Et=await et.json().catch(()=>null);(!et.ok||(Et==null?void 0:Et.ok)===!1)&&(Ce=!1,Y({owner:V,phase:"failed",message:(Et==null?void 0:Et.error)||`session ${M} refused (HTTP ${et.status})`}))}catch(et){Ce=!1,Y({owner:V,phase:"failed",message:et instanceof Error?et.message:String(et)})}return Ce&&Y(null),await(f==null?void 0:f()),Ce&&V==="command"&&Re(),Ce},W1=async()=>{const M=await P0("resume");return M&&await Zs(),M},F0=wg(Pe,{command:()=>{le?Re():te(!0)},eval:()=>{J&&A.open(aT(lf(ye)))},relaunch:W1,stop:M=>P0("stop",void 0,M),close:M=>P0("close",void 0,M)}),K1=F0.filter(M=>M.typed!==!1&&M.enabled),V1=(M,K)=>({name:M.name,description:x(M.descKey),ui:!0,color:M.color,run:()=>{var V;return(V=M.run)==null?void 0:V.call(M,K)}}),U1=K1.map(M=>V1(M,"command")),C5=K1.map(M=>V1(M,"panel")),qn=gd({inputRef:Si,value:$,setValue:W,specs:e,sessions:Ft,launchers:G,focusId:Oe,slash:{commands:j1,mode:"token",head:x("session.menuPresets"),onPick:(M,K)=>{const V=[$.slice(0,K.start).trim(),$.slice(K.end).trim()].filter(Boolean).join(" "),_e=`/${M.name}${V?` ${V}`:""} `;return W(_e),requestAnimationFrame(()=>{const Ce=Si.current;Ce&&(Ce.focus(),Ce.setSelectionRange(_e.length,_e.length))}),!0}}}),ys=gd({inputRef:Wt,value:nl,setValue:sn,specs:e,sessions:Ft,launchers:G,focusId:Oe,up:!0,slash:{commands:Z3(U1,j1,S5),mode:"line",head:x("session.menuCommands"),onPick:M=>M.ui?(sn(""),M.run(),!0):!1}}),A5=U1,I0=()=>{qn.close(),ys.close()},z0=M=>U3(Wt.current,M,sn,ys.sync),ws=_d({inputRef:Si,setValue:W,variant:"new"}),Xr=_d({inputRef:Wt,setValue:sn,variant:"command"}),nn=Number.isInteger(bs.total)?x("session.evalDoorSummary",bs):"",j0=bs.phase==="ready"?nn:bs.phase==="updating"?x("session.evalUpdating",{summary:nn}):bs.phase==="disconnected"?x("session.evalDisconnected",{summary:nn}):bs.phase==="dormant"?nn?x("session.evalDormantKnown",{summary:nn}):x("session.evalDormant"):bs.phase==="loading"?x("session.evalLoading"):nn?x("session.evalFailedKnown",{summary:nn}):x("session.evalUnavailable"),E5=g4()&&J&&F0.some(M=>M.name==="eval");Q1(E5?{id:"session-eval",side:"right",priority:25,tooltip:j0,node:p.jsxs("a",{className:"si-eval-door","data-action":"eval",href:tl(lf(ye)),"data-tip":j0,"aria-label":j0,children:[p.jsx(je,{name:"evals",size:14}),p.jsx(BB,{summary:bs})]})}:null);const D5=J?Vt("sessions",ye,Oo?{surface:Oo}:null):null,M5=$n||O1?[Dr]:[Dr,Xn,la],ol=gs===la?tu(ye):gs,T5=J?[{id:"resource-picker",icon:"folder-open",label:x("session.addResourceTab"),priority:100,pressed:qt,haspopup:!0,onClick:()=>Ni(M=>(M||O(null),!M)),menuKey:qt?F1.map(M=>M.id).join(","):"",menu:qt?p.jsx(EB,{options:F1,onOpen:I1}):null},...!dt&&M5.length>1?[{id:"surface-switcher",icon:ol===Xn?"message-square":"terminal",label:x(ol===Xn?"session.switchToConversation":"session.switchToTerminal"),priority:80,menuKey:`${ol}:${vs?"diff":"base"}`,onClick:()=>{Ni(!1);const M=ol===Xn?Dr:Xn;KT(ye,M),L0(ye,M,!0)}},{id:"diff-switcher",icon:"git-compare",label:x(vs?"session.diffClose":"session.diffScope"),priority:79,pressed:vs,menuKey:vs?"diff":"base",onClick:()=>{Ni(!1),L0(ye,vs?tu(ye):la,!0)}}]:[],...F0.filter(M=>M.button&&!dt&&(gs==="terminal"||M.name!=="merge")).map(M=>{const K=M.enabled&&!(M.name==="command"&&rn);return{id:M.name,icon:M.icon,label:K?sB(x(M.titleKey),...M.shortcut?[M.shortcut]:[]):x(M.disabledTitleKey||M.titleKey),disabled:!K,disabledReason:M.enabled?void 0:x(M.disabledTitleKey),pressed:M.pressed?le:void 0,onClick:()=>{var V;return(V=M.run)==null?void 0:V.call(M)},priority:M.anchor==="right"?-10:50}}),...dt?[{id:"refresh-resource",icon:"rotate-ccw",label:x("session.refreshResourceTab",{name:dt.label}),priority:40,onClick:()=>y5(dt)},...dt.kind==="file"?[{id:"download-resource",icon:"download",label:x("session.downloadFile"),priority:39,onClick:()=>{w5(dt.sessionId,dt.value)}},{id:"copy-resource",icon:"copy",label:dt.value,priority:38,onClick:()=>{x5(dt.value)}}]:[]]:[]]:[],G1=k.useRef({}),al=ye==="new"?qn:ys;return G1.current={active:ye,submit:O0,menu:al.menu,navMenu:al.nav,accept:al.accept,closeMenu:al.dismiss,open:r,searchOpen:s,commandOpen:le,commandAvailable:R0,setCommandOpen:te,closeCommandBox:Re,sessionOrder:We},_f(M=>((V=>{var ul,J1,cl,Z1;const{active:_e,submit:Ce,menu:et,navMenu:Et,accept:Wn,closeMenu:ei,open:H0,searchOpen:ll,commandOpen:Y1,commandAvailable:B5,setCommandOpen:R5,closeCommandBox:X1,sessionOrder:Po}=G1.current;if(!(!H0||ll)&&!((J1=(ul=V.target)==null?void 0:ul.closest)!=null&&J1.call(ul,"[data-focus-overlay]"))&&!((V.key==="Enter"||V.key===" ")&&((Z1=(cl=V.target)==null?void 0:cl.closest)!=null&&Z1.call(cl,"button, a[href]")))){if(iB("shell.commandBox",V)&&!V.metaKey&&!V.ctrlKey&&_e!=="new"){V.preventDefault(),V.stopPropagation(),B5&&(Y1?X1():R5(!0));return}if(!(V.altKey&&!V.metaKey&&!V.ctrlKey&&["KeyN","KeyF"].includes(V.code))){if(et){if(V.key==="ArrowDown"){V.preventDefault(),V.stopPropagation(),Et(1);return}if(V.key==="ArrowUp"){V.preventDefault(),V.stopPropagation(),Et(-1);return}if((V.key==="Enter"||V.key==="Tab")&&!da(V)){V.preventDefault(),V.stopPropagation(),Wn(et.items[et.index]);return}if(V.key==="Escape"){V.preventDefault(),V.stopPropagation(),ei();return}}if(Y1&&V.key==="Escape"){V.preventDefault(),V.stopPropagation(),X1();return}if(V.key==="ArrowUp"||V.key==="ArrowDown"){if(n_(V.target))return;V.preventDefault(),V.stopPropagation();let $0=Po.indexOf(_e);$0<0&&($0=0);const q0=Math.max(0,Math.min(Po.length-1,$0+(V.key==="ArrowDown"?1:-1)));Po[q0]!==_e&&(c?c(Po[q0]):o(Po[q0]));return}}}})(M),M.cancelBubble),10,{allowTyping:!0}),p.jsxs(p.Fragment,{children:[p.jsxs("div",{className:"si-page",children:[L&&p.jsx(jT,{closing:q,opening:F,sessions:t,activeId:ye,onSelect:(M,K)=>c?c(M,K):M==="new"?o("new"):N0(M),archiveActive:v,onArchive:h,onSearch:d,reload:f,onContextMenu:O,selectRequest:T,onSelectRequestConsumed:()=>U(null),onError:M=>Y({owner:"panel",phase:"failed",message:M})}),p.jsxs("div",{className:"si-document",children:[w&&p.jsx(gB,{specs:e,sessions:t,route:w,onSessionContextMenu:M=>{Ni(!1),O(M)}}),p.jsxs("div",{className:"si-panel",onMouseDownCapture:wa,children:[ws.fileInput,Xr.fileInput,p.jsxs("section",{className:`si-content${ye==="new"?" is-new":" is-session"}`,children:[ye==="new"&&p.jsxs("div",{className:"si-new-center",children:[p.jsx(s5,{}),p.jsxs("div",{className:ws.dragging?"si-inputwrap dragover":"si-inputwrap",...ws.dropProps,children:[p.jsx(fd,{ref:Si,className:"si-input","data-focus-sink":!0,rows:1,value:$,onKeyDown:M=>{M.key!=="Enter"||M.shiftKey||da(M)||(M.preventDefault(),M.stopPropagation(),O0())},onChange:M=>{W(M.target.value),qn.sync(M.target)},onSelect:M=>qn.sync(M.target),onPaste:ws.onPaste,onBlur:qn.close,placeholder:x("session.inputPlaceholder"),spellCheck:!1}),p.jsx("button",{type:"button",className:"si-attach","data-tip":x("session.attachTitle"),onClick:ws.pick,disabled:ws.busy,children:ws.busy?p.jsx(wB,{}):p.jsx(yB,{})}),p.jsx(Zt,{icon:"send",size:14,className:"si-launch",label:x("session.launchSend"),disabled:!$.trim(),onMouseDown:wa,onClick:O0}),qn.menuEl]}),k5(),ws.queue,G.length?p.jsx(RB,{launchers:G,launcher:X,pickLauncher:oe}):null,p.jsxs("div",{className:"si-hint",children:[x("session.hint.before"),p.jsx("code",{children:"[["}),x("session.hint.mid"),p.jsx("code",{children:"/"}),x("session.hint.after")]})]}),p.jsxs("div",{className:"si-session-wrap","aria-hidden":!J,style:{display:"flex",flexDirection:"column",flex:1,minWidth:0,minHeight:0,position:J?"relative":"absolute",inset:J?void 0:0,visibility:J?"visible":"hidden",pointerEvents:J?"auto":"none"},children:[p.jsx(MB,{document:D5,actions:T5}),p.jsxs("div",{className:`si-term-body${rn?" is-conversation":""}${vs?" is-diff":""}${dt?" is-resource":""}`,id:dt?`si-resource-panel-${dt.id}`:`si-${gs}-panel-${ye}`,"aria-label":(dt==null?void 0:dt.label)||x(rn?"session.tabConversation":"session.tabTerminal"),style:{position:"relative"},children:[[...new Set([...H1,...ht])].map(M=>{const K=Ft.find(Et=>Et.id===M);if(!K)return null;const V=hn(K),_e=M===ye&&!dt,Ce=_e&&gs==="terminal",et=_e&&(V||gs===Dr);return p.jsxs("div",{children:[!V&&H1.has(M)&&p.jsx("div",{className:"si-term-layer",style:{position:"absolute",inset:0,visibility:Ce?"visible":"hidden",pointerEvents:Ce?"auto":"none"},children:p.jsx(P7,{sessionId:M,active:r&&Ce,focused:r&&Ce&&!le,writable:r&&Ce,focusRequest:M===ye?de:0})}),(V||ht.has(M))&&p.jsx("div",{className:"si-term-layer",style:{position:"absolute",inset:0,visibility:et?"visible":"hidden",pointerEvents:et?"auto":"none"},children:p.jsx(aA,{s:K,sessions:Ft,active:r&&et,specs:e,boardCommands:M===ye?C5:[],footerState:tm(K),onRestore:M===ye&&K.status!=="retired"?W1:void 0,actionOutcome:M===ye&&(I==null?void 0:I.owner)==="panel"?I:null})})]},M)}),vs&&p.jsx(iT,{sessionId:ye}),At.map(M=>{const K=(dt==null?void 0:dt.id)===M.id;return p.jsx("div",{className:"si-resource-layer",style:{position:"absolute",inset:0,visibility:K?"visible":"hidden",pointerEvents:K?"auto":"none"},children:p.jsx(TB,{tab:M,active:r&&K,focusRequest:K?Ye:0,onEscape:()=>L0(M.sessionId,v5(M.sessionId),!0)})},M.id)}),(I==null?void 0:I.owner)==="panel"&&b5==="live"&&p.jsx("div",{className:"si-action-outcome-float",children:p.jsx(n4,{outcome:I})}),le&&!Lo&&!rn&&p.jsxs("div",{className:"si-command-layer",role:"dialog","aria-label":x("session.commandBox"),children:[p.jsx("button",{type:"button",className:"si-command-dismiss",tabIndex:-1,"aria-label":x("session.commandClose"),onMouseDown:Re}),p.jsx(H3,{className:`si-command-box${Xr.dragging?" dragover":""}`,...Xr.dropProps,editor:p.jsxs(p.Fragment,{children:[p.jsxs("div",{className:"fv-tawrap",children:[p.jsx(fd,{ref:Wt,className:"si-command-input",rows:1,value:nl,"data-focus-sink":!0,onChange:M=>{delete Gi.current[ye],sn(M.target.value),ys.sync(M.target)},onSelect:M=>ys.sync(M.target),onPaste:Xr.onPaste,onBlur:ys.close,onKeyDown:M=>{M.key==="Enter"&&!M.shiftKey&&!da(M)&&(M.preventDefault(),M.stopPropagation(),q1())},placeholder:x("session.commandPlaceholder"),spellCheck:!1}),ys.menuEl]}),Xr.queue]}),footer:p.jsxs("div",{className:"si-command-tools",children:[p.jsxs("span",{className:"si-command-title",children:[p.jsx(je,{name:"command",size:12}),x("session.commandBox")]}),p.jsx("button",{type:"button",className:"fv-trigger-btn","data-tip":x("thread.mentionActor"),"aria-label":x("thread.mentionActor"),onClick:()=>z0("@"),children:"@"}),p.jsx("button",{type:"button",className:"fv-trigger-btn","data-tip":x("thread.mentionNode"),"aria-label":x("thread.mentionNode"),onClick:()=>z0("[["),children:"[["}),p.jsx("button",{type:"button",className:"fv-trigger-btn","data-tip":x("session.menuCommands"),"aria-label":x("session.menuCommands"),onClick:()=>z0("/"),children:"/"}),p.jsx(Zt,{icon:Xr.busy?"loader":"paperclip",size:14,iconClassName:Xr.busy?"si-attach-busy":void 0,className:"si-command-tool",label:x("session.attachTitle"),disabled:Xr.busy,onClick:Xr.pick}),(I==null?void 0:I.owner)==="command"&&p.jsx(n4,{outcome:I}),p.jsx(Zt,{icon:"send",size:14,className:"si-command-send",label:x("session.commandSend"),disabled:!nl.trim()||(I==null?void 0:I.owner)==="command"&&I.phase==="sending",onClick:q1})]})})]})]})]})]})]})]})]}),Oi&&p.jsx(_B,{sessions:en,onOpenSession:M=>{tn(!1),c==null||c(M),N0(M)},onClose:()=>{tn(!1),v&&A.open({page:"sessions",param:ye==="new"?null:ye,query:null})}}),p.jsx(AT,{menu:C,onClose:()=>O(null),onChanged:f,onError:M=>{var V;const K=(V=C==null?void 0:C.session)==null?void 0:V.id;if(K&&K!==ye){o(K),requestAnimationFrame(()=>Y({owner:"panel",phase:"failed",message:M}));return}Y({owner:"panel",phase:"failed",message:M})},onLock:M=>{R(M.source,{toggle:!1}),u()},onMultiSelect:M=>U(M),onDetach:M=>{Hi("/api/sessions/reparent",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({children:[M.id],parent:null})}).then(()=>f==null?void 0:f())}})]})}const gN=Object.freeze(Object.defineProperty({__proto__:null,LaunchHero:s5,default:o5,sessionEvalDisplay:n5},Symbol.toStringTag,{value:"Module"}));function NB({param:t,query:e}){const{specs:i,sessions:r,boardLive:s}=wf(),{reload:n}=v4(),{palette:o}=m4(),{openPalette:a,takeCompose:l,watchCompose:u}=yf(),c=e0(),h=k.useCallback((_,{newTab:w=!1}={})=>{const x={page:"sessions",param:_,query:null};return w&&_!=="new"&&N1(x.page,x.param,x.query),c.open(x)},[c]),d=t&&t!=="new"?t:"new",[f,m]=k.useState(null),v=g4();return k.useEffect(()=>{typeof(e==null?void 0:e.seed)=="string"&&e.seed.length&&m(e.seed)},[e==null?void 0:e.seed]),k.useEffect(()=>{if(!v)return;const _=()=>{const w=l();w!=null&&m(w)};return _(),u(_)},[v,l,u]),p.jsx(o5,{sessions:r,specs:i,focusNode:null,open:v,searchOpen:!!o,sel:d,surface:e==null?void 0:e.surface,setSel:h,seed:f,onSeedConsumed:()=>m(null),onClose:()=>c.open({page:"graph",param:null,query:null}),onPickSession:h,onOpenArchive:()=>c.open({page:"sessions",param:t&&t!=="new"?t:null,query:{archive:"1"}}),onOpenSearch:()=>a("sessions"),boardLive:s,reload:n,archiveRequested:(e==null?void 0:e.archive)==="1",route:{page:"sessions",param:t,query:e}})}const LB=/^[a-z][a-z0-9-]*$/,OB=t=>t&&typeof t=="object"&&!Array.isArray(t);function rh(t){if(typeof t!="string"||!LB.test(t))throw new TypeError(`view name must be lowercase kebab-case: ${String(t)}`)}const PB=new Set([Symbol.for("react.lazy"),Symbol.for("react.memo"),Symbol.for("react.forward_ref")]),FB=t=>typeof t=="function"||t&&typeof t=="object"&&PB.has(t.$$typeof);function o4(t){if(!t||typeof t!="object"||!FB(t.component))throw new TypeError("view definition requires a component function or React component");return Object.freeze({...t})}function IB(t={}){const e=new Map,i=new Map,r=new Map;for(const[l,u]of Object.entries(t))rh(l),e.set(l,o4(u)),i.set(l,"core");const s=(l,u,c="runtime")=>{if(rh(l),typeof c!="string"||c.length===0)throw new TypeError("view owner is required");if(e.has(l))throw new Error(`view already registered: ${l}`);return e.set(l,o4(u)),i.set(l,c),e.get(l)},n=l=>{if(!l||typeof l!="object"||typeof l.id!="string"||l.id.length===0)throw new TypeError("plugin requires a non-empty id");if(r.has(l.id))throw new Error(`plugin already registered: ${l.id}`);if(!l.views||typeof l.views!="object"||Array.isArray(l.views))throw new TypeError(`plugin ${l.id} requires a views object`);const u=Object.keys(l.views);for(const h of u)if(rh(h),e.has(h))throw new Error(`view already registered: ${h}`);const c=[];try{for(const h of u)s(h,l.views[h],l.id),c.push(h);r.set(l.id,Object.freeze({id:l.id,views:Object.freeze([...u])}))}catch(h){for(const d of c)e.delete(d),i.delete(d);throw h}return r.get(l.id)},o=l=>{const u=r.get(l);if(!u)return!1;for(const c of u.views)e.delete(c),i.delete(c);return r.delete(l),!0},a=Object.freeze({assertAddress:(l,u="address")=>{if(!OB(l)||typeof l.page!="string"||!e.has(l.page))throw new TypeError(`${u}.page is not a registered view: ${String(l==null?void 0:l.page)}`);const c=l.param??null;if(c!=null&&typeof c!="string")throw new TypeError(`${u}.param must be a string or null`);return typeof e.get(l.page).document=="function"&&c==="new"&&l.page==="sessions",l},isDocument:(l,u=null)=>{const c=e.get(l);return typeof(c==null?void 0:c.document)=="function"?c.document(l,u):!!(c!=null&&c.document)},isResident:(l,u=null)=>{var c;return!!((c=e.get(l))!=null&&c.resident)&&u==null}});return Object.freeze({get:l=>e.get(l),has:l=>e.has(l),ownerOf:l=>i.get(l),entries:()=>[...e.entries()],registerView:s,registerPlugin:n,unregisterPlugin:o,routeContract:a})}function zB(t){return{id:"dashboard-settings",views:{settings:{component:t,surface:"workspace",document:!0,resident:!0,icon:"settings",className:"view-settings"}}}}const sh="spexcode.chunk-reload";function In(t){return k.lazy(async()=>{for(let e=0;;e++)try{const i=await t();try{sessionStorage.removeItem(sh)}catch{}return i}catch(i){if(e<2){await new Promise(s=>setTimeout(s,250));continue}let r=!0;try{r=sessionStorage.getItem(sh)==="1"}catch{}if(r)throw i;try{sessionStorage.setItem(sh,"1")}catch{}location.reload(),await new Promise(()=>{})}})}const a5=In(()=>Gs(()=>import("./GraphView-DmtM56Gf.js"),__vite__mapDeps([5,1,2,3,6,7,8,9,4,10]))),jB=In(()=>Gs(()=>import("./SpecView-CM3BOtTy.js"),__vite__mapDeps([11,1,2,6,7,3,8,4]))),HB=In(()=>Gs(()=>import("./FileView-BqSwsBx0.js"),__vite__mapDeps([12,1,2,8,3,4]))),$B=In(()=>Gs(()=>import("./EvalsPage-DBVkF_F0.js"),__vite__mapDeps([13,1,2,7,3,4]))),qB=In(()=>Gs(()=>import("./IssuesPage-BZ36PpJ-.js"),__vite__mapDeps([14,1,2,6,7,3,8,4]))),WB=In(()=>Gs(()=>import("./Settings-qIX2_HmP.js"),__vite__mapDeps([15,1,2,3,4]))),KB=In(()=>Gs(()=>import("./EmptyView-DvUslJmJ.js"),__vite__mapDeps([16,1,2,3])));function VB({param:t,query:e}){return t==null?p.jsx(a5,{page:"spec",param:t,query:e}):p.jsx(jB,{param:t,query:e})}function UB({param:t,query:e}){const{specs:i,sessions:r,issuesStamp:s}=wf(),{reload:n}=v4(),o=e0(),a=l=>o.open({page:"sessions",param:l,query:null});return p.jsx($B,{param:t,query:e,specs:i,sessions:r,issuesStamp:s,reloadBoard:n,onOpenSession:a})}function GB({param:t,query:e}){const{specs:i,sessions:r,issuesStamp:s}=wf(),n=e0(),o=a=>n.open({page:"sessions",param:a,query:null});return p.jsx(qB,{param:t,query:e,specs:i,sessions:r,issuesStamp:s,onOpenSession:o})}function YB(){return p.jsx(WB,{})}const XB=Object.freeze({graph:{component:a5,surface:"workspace",document:!1,icon:"graph",className:"view-graph"},spec:{component:VB,surface:"workspace",document:!0,resident:!0,icon:"graph",className:"view-spec"},file:{component:HB,surface:"workspace",document:(t,e)=>e!=null,icon:"files",className:"view-file"},sessions:{component:NB,surface:"workspace",document:(t,e)=>e!=null&&e!=="new",icon:"sessions",className:"view-sessions"},evals:{component:UB,surface:"workspace",document:!0,resident:!0,icon:"evals",className:"view-evals"},issues:{component:GB,surface:"workspace",document:!0,resident:!0,icon:"issues",className:"view-issues"},empty:{component:KB,surface:"workspace",document:!1,className:"view-empty"}}),Ln=IB(XB),vN=Ln.routeContract,JB=t=>Ln.registerPlugin(t);JB(zB(YB));const bN=t=>Ln.get(t)||Ln.get("sessions"),ZB=t=>{var e;return((e=Ln.get(t))==null?void 0:e.icon)||null},l5=(t,e=null)=>{const i=Ln.get(t);return typeof(i==null?void 0:i.document)=="function"?i.document(t,e):!!(i!=null&&i.document)},QB=(t,e=null)=>{var i;return!!((i=Ln.get(t))!=null&&i.resident)&&e==null},uo=t=>{var e;return(t==null?void 0:t.page)==="sessions"&&typeof((e=t==null?void 0:t.query)==null?void 0:e.surface)=="string"&&t.query.surface.startsWith("resource:")},Qu=t=>uo(t)?"file":t==null?void 0:t.page,u5=new Set(["spec","evals","issues","settings"]),B0=t=>(t==null?void 0:t.page)==="sessions"&&(t!=null&&t.param)&&!uo(t)?{...t,query:null}:u5.has(t==null?void 0:t.page)?{...t,param:null,query:null}:t,Je=t=>{const e=B0(t);return Vt(e.page,e.param,e.query)};function eR(t,e=()=>!0){const i=[],r=new Set;for(const s of t){if(!e(s.page,s.param??null))continue;const n={page:s.page,param:s.param??null,query:s.query??null},o=Je(n);r.has(o)||(r.add(o),i.push(n))}return i}function tR(t,e,i="slot",r=null){const s={page:e.page,param:e.param??null,query:e.query??null},n=B0(s),o=Je(n),a=t.find(c=>Je(c)===o);if(a){const c=n.page==="sessions"&&!uo(n)&&JSON.stringify(a.query||null)!==JSON.stringify(n.query||null),h=u5.has(n.page)&&(a.param!==s.param||JSON.stringify(a.query||null)!==JSON.stringify(s.query||null));return!c&&!h?t:t.map(d=>Je(d)===o?{...d,param:s.param,query:s.query}:d)}const l={page:s.page,param:s.param,query:s.query},u=i==="append"||r==null?-1:t.findIndex(c=>Je(c)===r&&Qu(c)===Qu(n));return u<0?[...t,l]:t.map((c,h)=>h===u?l:c)}function mf(t,e,i=null){const r=t.findIndex(o=>Je(o)===e);if(r<0)return t;const s=t.filter((o,a)=>a!==r),n=i==null?s.length:s.findIndex(o=>Je(o)===i);return n<0||n===r?t:[...s.slice(0,n),t[r],...s.slice(n)]}function iR(t,e,i,r=[]){const s=Qu(B0(t));if(uo(t)){const c=e.find(h=>h.page==="sessions"&&h.param===t.param&&!uo(h));if(c)return c}const n=c=>{for(const h of r){const d=e.find(f=>Je(f)===h);if(d&&c(d))return d}return null},o=c=>{for(let h=0;h<e.length;h+=1){const d=e[i+h];if(d&&c(d))return d;const f=e[i-1-h];if(f&&c(f))return f}return null},a=()=>!0,l=c=>Qu(c)===s,u=n(a)||o(l)||o(a);return u||(uo(t)?{page:"sessions",param:"new",query:null}:(t==null?void 0:t.page)==="spec"||(t==null?void 0:t.page)==="file"?{page:"graph",param:null,query:null}:{page:"empty",param:null,query:null})}const gf="spexcode.tabs",rR=()=>{try{const t=JSON.parse(localStorage.getItem(gf)||"[]");if(!Array.isArray(t))return[];const e=t.filter(r=>r&&typeof r.page=="string"),i=eR(e,l5);return JSON.stringify(i)!==JSON.stringify(e)&&localStorage.setItem(gf,JSON.stringify(i)),i}catch{return[]}},sR=t=>{try{localStorage.setItem(gf,JSON.stringify(t))}catch{}};let c5=null;const vf=new Set,Ii=()=>c5??(c5=rR()),iu=t=>{const e=t;if(e===Ii())return e;c5=e,sR(e);for(const i of[...vf])i(e);return e};let co=[],a4=null;const nR=t=>{if(co[0]===t)return;const e=new Set(Ii().map(Je));co=[t,...co.filter(i=>i!==t&&e.has(i))]};let Jn=null,Ls=null;function oR(t){return Ls=t,()=>{Ls===t&&(Ls=null)}}function _N(t,...e){var i;return(i=Ls==null?void 0:Ls[t])==null?void 0:i.call(Ls,...e)}const h5=t=>t.button===0&&!t.shiftKey&&!t.altKey&&(t.ctrlKey||t.metaKey);function N1(t,e=null,i=null){const r=Je(B0({page:t,param:e,query:i}));Jn=Ii().some(s=>Je(s)===r)?null:r}function L1(t,e=null,i=null){N1(t,e,i),wn(t,e,{query:i})}const d5=t=>{const{page:e,param:i,query:r}=bf(t);return{page:e,param:i,query:Object.keys(r||{}).length?r:null}};function f5(t,e){if(!h5(t))return!1;t.preventDefault();const i=d5(e);return L1(i.page,i.param,i.query),!0}function yN(t){const e=Ii().filter(t),i=e[e.length-1];return i?(wn(i.page,i.param,{query:i.query}),!0):!1}function p5({onCloseStart:t}={}){const e=o_(),[i,r]=k.useState(Ii),s=k.useRef(t);k.useEffect(()=>{s.current=t},[t]),k.useEffect(()=>(vf.add(r),r(Ii()),()=>{vf.delete(r)}),[]),k.useEffect(()=>{const c=Je(e),h=a4;if(a4=c,Jn&&Jn!==c&&(Jn=null),!l5(e.page,e.param))return;const d=Jn===c?"append":"slot";Jn=null,iu(tR(Ii(),e,d,h)),nR(c)},[e.page,e.param,e.query]);const n=Je(e),o=k.useCallback(c=>wn(c.page,c.param,{query:c.query}),[]),a=k.useCallback(c=>{var v;const h=Je(c),d=Ii(),f=d.findIndex(_=>Je(_)===h);if(f<0)return;(v=s.current)==null||v.call(s,c);const m=d.filter((_,w)=>w!==f);if(iu(m),co=co.filter(_=>_!==h),h===n){const _=iR(c,m,f,co);wn(_.page,_.param,{query:_.query})}},[n]),l=k.useCallback(c=>{const h=Je(c),d=Ii();d.filter(f=>Je(f)!==h).forEach(f=>{var m;return(m=s.current)==null?void 0:m.call(s,f)}),iu(d.filter(f=>Je(f)===h)),h!==n&&wn(c.page,c.param,{query:c.query})},[n]),u=k.useCallback((c,h)=>{iu(mf(Ii(),c,h))},[]);return k.useEffect(()=>oR({closeActive:()=>{const c=Ii().find(h=>Je(h)===n);c&&a(c)},move:c=>{const h=Ii(),d=h.findIndex(f=>Je(f)===n);d<0||h.length<2||o(h[(d+c+h.length)%h.length])},active:()=>Ii().find(c=>Je(c)===n)||null}),[n,o,a]),k.useMemo(()=>({tabs:i,activeKey:n,open:o,close:a,closeOthers:l,move:u}),[i,n,o,a,l,u])}export{_N as $,Z2 as A,AT as B,E1 as C,ya as D,J6 as E,cf as F,K3 as G,vR as H,Hr as I,b4 as J,lr as K,KR as L,bB as M,$R as N,xT as O,tl as P,GR as Q,io as R,Ru as S,VR as T,kC as U,i5 as V,ZT as W,B1 as X,XT as Y,mB as Z,eB as _,Gu as a,CR as a$,gB as a0,aT as a1,Y3 as a2,SR as a3,xR as a4,aN as a5,bN as a6,G2 as a7,vN as a8,n1 as a9,tN as aA,gT as aB,ZR as aC,wT as aD,rN as aE,sN as aF,iN as aG,wR as aH,vC as aI,Y6 as aJ,HR as aK,YR as aL,gd as aM,EC as aN,H3 as aO,AR as aP,U3 as aQ,eN as aR,UR as aS,yR as aT,uC as aU,_C as aV,oN as aW,Go as aX,tm as aY,lB as aZ,N1 as a_,lN as aa,RT as ab,MT as ac,BT as ad,TT as ae,JR as af,fd as ag,da as ah,lf as ai,aA as aj,VC as ak,kR as al,nN as am,AC as an,uN as ao,ET as ap,dN as aq,xe as ar,Ke as as,PD as at,DR as au,MR as av,uM as aw,D0 as ax,be as ay,QR as az,Ci as b,OC as b0,uB as b1,o0 as b2,BC as b3,gR as b4,V3 as b5,C7 as b6,cN as b7,Xn as b8,Dr as b9,wD as bA,ji as bB,Js as bC,we as bD,Dn as bE,NR as bF,ef as bG,OR as bH,FR as bI,IR as bJ,PR as bK,zR as bL,jR as bM,rM as bN,iM as bO,BR as bP,gN as bQ,Xp as ba,S7 as bb,x7 as bc,mR as bd,hN as be,pN as bf,fN as bg,mN as bh,VD as bi,g6 as bj,Ki as bk,zD as bl,Qe as bm,oi as bn,kt as bo,ZD as bp,$a as bq,ui as br,Ve as bs,at as bt,LR as bu,No as bv,ve as bw,qe as bx,or as by,Fn as bz,U6 as c,hT as d,WR as e,yN as f,qR as g,cT as h,ZB as i,oT as j,f5 as k,iB as l,h5 as m,XR as n,L1 as o,X6 as p,LT as q,iw as r,rB as s,Kh as t,IT as u,OT as v,sB as w,Of as x,zT as y,Zc as z};
|
|
335
|
+
`);function s5(){return p.jsx("pre",{className:"si-hero","aria-label":"SpexCode",children:xB})}function n4({outcome:t}){if(!t)return null;const e=t.phase==="failed"?"alert":"status";return p.jsx("div",{className:`si-action-outcome ${t.phase}`,role:e,children:t.message})}const Zu=t=>t.split("/").filter(Boolean).pop()||t,SB=t=>/\.(?:md|markdown)$/i.test(t);function kB({path:t,text:e}){return SB(t)?p.jsx(j3,{className:"si-file-markdown",children:e}):p.jsx("pre",{className:"si-file-text",children:e})}function CB({path:t,html:e}){return p.jsx("iframe",{className:"si-file-html",srcDoc:e,title:Zu(t)})}const ih=t=>{try{const e=new URL(t);return`${e.hostname.replace(/^\[|\]$/g,"")}:${e.port}${e.pathname==="/"?"":e.pathname}`}catch{return t}},AB=(t,e)=>`${e_}/web/${encodeURIComponent(t)}/${encodeURIComponent(e)}/`;function EB({options:t,onOpen:e}){const i=He();return p.jsx("div",{className:"document-action-menu",role:"menu","aria-label":i("session.resourceMenuLabel"),onMouseDown:r=>r.stopPropagation(),children:t.length?t.map(r=>p.jsxs("button",{type:"button",className:"si-resource-menu-row",role:"menuitem",onClick:()=>e(r),children:[p.jsx(je,{name:r.kind==="file"?"folder-open":"globe",size:13}),p.jsx("span",{children:r.label})]},r.id)):p.jsx("span",{className:"si-resource-menu-empty",children:i("session.resourceMenuEmpty")})})}function DB({document:t,action:e}){return Q5(t,e),null}function MB({document:t,actions:e}){return e.map(i=>p.jsx(DB,{document:t,action:i},i.id))}function TB({tab:t,active:e=!1,focusRequest:i=0,onEscape:r}){const s=He(),[n,o]=k.useState({phase:"loading"}),a=k.useRef(null),l=k.useRef(e),u=k.useRef(r);return l.current=e,u.current=r,k.useEffect(()=>{if(t.kind!=="file")return;let c=!1,h=null;const d=Di(`/api/sessions/${encodeURIComponent(t.sessionId)}/files/download?path=${encodeURIComponent(t.value)}&preview=1`);return o({phase:"loading"}),fetch(d).then(async f=>{if(!f.ok){const v=await f.json().catch(()=>null);throw new Error((v==null?void 0:v.error)||s("session.filePreviewFailed",{status:f.status}))}const m=f.headers.get("X-Spexcode-Preview-Kind");if(m==="image")h=URL.createObjectURL(await f.blob()),c||o({phase:"image",url:h});else{const v=await f.text();c||o({phase:m==="html"?"html":"text",text:v})}}).catch(f=>{c||o({phase:"error",message:f instanceof Error?f.message:String(f)})}),()=>{c=!0,h&&URL.revokeObjectURL(h)}},[t.kind,t.sessionId,t.value,t.revision,s]),k.useEffect(()=>{if(t.kind!=="web")return;const c=a.current;if(!c)return;let h=null;const d=v=>{var A;if(!(v.key==="Escape"||v.altKey&&!v.metaKey&&!v.ctrlKey))return;const w=new KeyboardEvent("keydown",{key:v.key,code:v.code,altKey:v.altKey,ctrlKey:v.ctrlKey,metaKey:v.metaKey,shiftKey:v.shiftKey,bubbles:!0,cancelable:!0}),x=!window.dispatchEvent(w);v.key==="Escape"?(v.preventDefault(),x||(A=u.current)==null||A.call(u)):x&&v.preventDefault()},f=()=>{h==null||h.removeEventListener("keydown",d,!0),h=c.contentWindow,h==null||h.addEventListener("keydown",d,!0)},m=()=>{f(),l.current&&document.visibilityState!=="hidden"&&requestAnimationFrame(()=>{var v;return(v=c.contentWindow)==null?void 0:v.focus()})};return c.addEventListener("load",m),f(),()=>{c.removeEventListener("load",m),h==null||h.removeEventListener("keydown",d,!0)}},[t.kind,t.revision]),k.useEffect(()=>{if(t.kind!=="web"||!e||document.visibilityState==="hidden")return;const c=requestAnimationFrame(()=>{var h,d;return(d=(h=a.current)==null?void 0:h.contentWindow)==null?void 0:d.focus()});return()=>cancelAnimationFrame(c)},[t.kind,t.revision,e,i]),t.kind==="web"?p.jsx("iframe",{ref:a,className:"si-resource-web",src:AB(t.sessionId,t.key),title:t.label},t.revision):p.jsxs("div",{className:`si-resource-file ${n.phase}`,"data-selectable":!0,children:[n.phase==="loading"&&p.jsx(je,{name:"loader",size:18,className:"si-attach-busy"}),n.phase==="error"&&p.jsx("p",{className:"si-file-preview-error",role:"alert",children:n.message}),n.phase==="text"&&p.jsx(kB,{path:t.value,text:n.text}),n.phase==="html"&&p.jsx(CB,{path:t.value,html:n.text}),n.phase==="image"&&p.jsx("img",{src:n.url,alt:Zu(t.value)})]})}function n5(t,e=!0,i=!1){var s;if(!t)return{phase:i?"dormant":"loading"};const r=t.phase==="ready"&&t.value?t.value:(s=t.lastKnown)==null?void 0:s.value;return e?t.phase==="ready"&&t.value?{phase:"ready",...t.value}:t.phase==="dormant"?r?{phase:"dormant",...r}:{phase:"dormant"}:t.phase==="updating"?r?{phase:"updating",...r}:{phase:"loading"}:t.phase==="error"?r?{phase:"error",...r}:{phase:"error"}:{phase:"loading"}:r?{phase:"disconnected",...r}:{phase:"disconnected"}}function BB({summary:t}){const e=He(),i=Number.isInteger(t.total);return!i&&t.phase==="loading"?p.jsx("span",{className:"si-eval-wait","data-tip":e("session.evalLoading"),children:p.jsx(je,{name:"loader",size:12,className:"si-eval-spinner"})}):!i&&t.phase==="dormant"?p.jsx("span",{className:"si-eval-wait",children:p.jsx(io,{kind:"eval",state:"missing",title:e("session.evalDormant"),size:12})}):i?p.jsxs("span",{className:`si-eval-stats ${t.phase}`,"aria-hidden":"true",children:[t.pass>0&&p.jsx(Go,{kind:"eval",state:"pass",cls:"st-pass secondary",n:t.pass,label:e("session.evalPass",{n:t.pass})}),t.fail>0&&p.jsx(Go,{kind:"eval",state:"fail",cls:"st-fail secondary",n:t.fail,label:e("session.evalFail",{n:t.fail})}),t.review>0&&p.jsx(Go,{kind:"eval",state:"review",cls:"st-review secondary",n:t.review,label:e("session.evalReview",{n:t.review})}),t.blind>0&&p.jsx(Go,{kind:"eval",state:"missing",cls:"st-empty blind",n:t.blind,label:e("session.evalBlind",{n:t.blind})}),t.unknown>0&&p.jsx(Go,{kind:"eval",state:"missing",cls:"st-empty blind",n:t.unknown,label:e("session.evalUnknown",{n:t.unknown})}),t.phase==="updating"&&p.jsx(je,{name:"loader",size:11,className:"si-eval-spinner si-eval-phase"}),t.phase==="dormant"&&p.jsx(io,{kind:"eval",state:"missing",title:e("session.evalDormantLast"),className:"si-eval-phase",size:11}),(t.phase==="disconnected"||t.phase==="error")&&p.jsx(io,{kind:"eval",state:"missing",title:e("session.evalUnavailable"),className:"si-eval-phase",size:11})]}):p.jsx("span",{className:"si-eval-wait",children:p.jsx(io,{kind:"eval",state:"missing",title:e("session.evalUnavailable"),size:12})})}function RB({launchers:t,launcher:e,pickLauncher:i}){const r=He(),[s,n]=k.useState(!1);ni(s,()=>n(!1));const o=t.find(u=>u.name===e),l=G2(o==null?void 0:o.harness).Glyph;return p.jsxs("div",{className:"si-launcher-picker",children:[p.jsxs("button",{type:"button",className:s?"si-launcher-btn on":"si-launcher-btn",onClick:()=>n(u=>!u),"aria-haspopup":"dialog","aria-expanded":s,"aria-label":r("session.launcherLabel"),"data-tip":r("session.launcherTip"),children:[p.jsx("span",{className:"si-launcher-harness","aria-hidden":"true",children:p.jsx(l,{})}),p.jsx("span",{className:"si-launcher-name",children:e})]}),s&&p.jsxs(p.Fragment,{children:[p.jsx("div",{className:"si-launcher-backdrop",onMouseDown:()=>n(!1)}),p.jsx("div",{className:"si-launcher-pop",role:"dialog","aria-modal":"true","aria-label":r("session.launcherLabel"),children:t.map(u=>{const c=G2(u.harness),h=c.Glyph;return p.jsxs("button",{type:"button",role:"menuitemradio","aria-checked":u.name===e,className:`si-launcher-row${u.name===e?" on":""}`,onClick:()=>{i(u.name),n(!1)},children:[p.jsxs("span",{className:"si-launcher-row-main",children:[p.jsx("span",{className:"si-launcher-harness","data-tip":c.label,"aria-hidden":"true",children:p.jsx(h,{})}),p.jsx("span",{className:"si-launcher-name",children:u.name}),u.name===e&&p.jsx(je,{name:"check",size:13,className:"si-launcher-check"})]}),u.cmd?p.jsx("span",{className:"si-launcher-cmd",children:u.cmd}):null]},u.name)})})]})]})}function o5({sessions:t,specs:e=[],focusNode:i,open:r,searchOpen:s=!1,sel:n,setSel:o,seed:a,onSeedConsumed:l,onClose:u,onPickSession:c,onOpenArchive:h,onOpenSearch:d,reload:f,boardLive:m=!1,archiveRequested:v=!1,surface:_=null,route:w=null}){const x=He(),A=e0(),{notify:D}=J5(),{lockGraphTo:R}=yf(),{dock:E}=m4(),[L,q,F]=bB(E),[$,W]=k.useState(""),[z,j]=k.useState([]),[C,O]=k.useState(null),[T,U]=k.useState(null),[H,re]=k.useState({}),{launchers:G,launcher:X,pickLauncher:oe}=Y3(),[I,Y]=k.useState(null),[le,te]=k.useState(!1),[de,ke]=k.useState(0),[Ye,Ct]=k.useState(0),[At,nt]=k.useState([]),{tabs:Be}=p5(),[vt,vr]=k.useState(()=>new Set),[ht,Yr]=k.useState(()=>new Set),[Pt,br]=k.useState(0),[qt,Ni]=k.useState(!1),Si=k.useRef(null),Wt=k.useRef(null),Gi=k.useRef({}),Yi=k.useRef(null),ce=k.useRef(null);k.useEffect(()=>VT(()=>br(M=>M+1)),[]);const Ae=k.useRef(null);k.useEffect(()=>{!I||I.phase==="pending"||I.phase==="sending"||(D(I.message,{kind:I.phase==="delivered"?"success":"error"}),Y(null))},[I,D]);const Re=()=>{Ae.current&&window.clearTimeout(Ae.current),Ae.current=null,te(!1),Y(M=>(M==null?void 0:M.owner)==="command"?null:M)},[$e,zn]=k.useState(null),[_r,il]=k.useState(null),Zs=k.useCallback(()=>{if(ce.current)return ce.current;const M=fetch(Di("/api/sessions/archive-index")).then(async K=>{if(!K.ok)throw new Error(`archive index refused (HTTP ${K.status})`);const V=await K.json(),_e=s4(Array.isArray(V)?V.map(Ce=>({...Ce,archived:!0})):[]);return zn(_e),_e}).catch(K=>(Y({owner:"panel",phase:"failed",message:K instanceof Error?K.message:String(K)}),[])).finally(()=>{ce.current=null});return ce.current=M,M},[]);k.useEffect(()=>{r&&$e===null&&Zs()},[r,$e,Zs]);const rl=k.useRef(null);k.useEffect(()=>{const M=new Set(t.map(V=>V.id)),K=rl.current;rl.current=M,r&&$e!==null&&K&&[...K].some(V=>!M.has(V))&&Zs()},[r,t,$e,Zs]);const Qs=k.useMemo(()=>{const M=new Map(t.map(K=>[K.id,K]));for(const K of $e||[])M.has(K.id)||M.set(K.id,K);return _r&&!M.has(_r.id)&&M.set(_r.id,_r),[...M.values()]},[t,$e,_r]),Xi=k.useRef(new Set);for(const M of Qs)Xi.current.add(M.id);const[Li,jn]=k.useState(null);k.useEffect(()=>{Li&&t.some(M=>M.id===Li.id)&&jn(null)},[t,Li]),k.useEffect(()=>{Li&&($e!=null&&$e.some(M=>M.id===Li.id))&&jn(null)},[$e,Li]);const Ft=k.useMemo(()=>!Li||Qs.some(M=>M.id===Li.id)?Qs:[...Qs,Li],[Qs,Li]);k.useEffect(()=>{_r&&t.some(M=>M.id===_r.id)&&il(null)},[t,_r]);const en=k.useMemo(()=>s4(Ft.filter(M=>M.archived)),[Ft]),Hn=k.useMemo(()=>new Set(["new",...Ft.map(M=>M.id)]),[Ft]),ye=Hn.has(n)||n!=="new"&&Xi.current.has(n)?n:"new",J=ye!=="new",{expanded:Q,offlineOpen:Ee}=X6(),Me=k.useMemo(()=>Of(t||[],M=>Q.has(M),{zoneFolded:M=>M==="offline"&&!Ee,keepVisible:M=>M.id===ye}),[t,Q,Ee,ye]),We=k.useMemo(()=>["new",...Me.filter(M=>M.type==="row").map(M=>M.s.id)],[Me]),Xe=k.useRef(new Set);k.useEffect(()=>{!r||n==="new"||Hn.has(n)||!Xi.current.has(n)||Xe.current.has(n)||(Xe.current.add(n),fetch(Di(`/api/sessions/${encodeURIComponent(n)}`)).then(async M=>{if(!M.ok){o("new");return}const K=await M.json();jn({...K,archived:K.archived===!0,liveness:K.archived===!0?"offline":K.liveness})}).catch(M=>{Y({owner:"panel",phase:"failed",message:M instanceof Error?M.message:String(M)}),o("new")}))},[r,n,Hn,o]);const Oe=(i==null?void 0:i.id)||null,Pe=Ft.find(M=>M.id===ye),[Oi,tn]=k.useState(!1);k.useEffect(()=>{v&&tn(!0)},[v]);const $n=hn(Pe),Lo=(Pe==null?void 0:Pe.liveness)==="offline",m5=!!(Pe!=null&&Pe.archived),O1=Lo||m5,Oo=qT(_)?_:null,g5=qa(Oo)?ff(Oo):null,gs=$n||O1?Dr:Oo||tu(ye),rn=gs===Dr,vs=gs===la,v5=M=>{const K=Ft.find(V=>V.id===M);return hn(K)?Dr:tu(M)},R0=!rn&&wg(Pe,{}).some(M=>M.name==="command"),bs=n5(J?Pe==null?void 0:Pe.evalSummary:null,m,!!Pe),b5=tm(Pe),P1=Pe?[...(Pe.files||[]).map(M=>({id:Bs(ye,"file",M),sessionId:ye,kind:"file",value:M,label:Zu(M),revision:0})),...(Pe.web||[]).map(M=>({id:Bs(ye,"web",M.key),sessionId:ye,kind:"web",key:M.key,value:M.url,label:ih(M.url),revision:0}))]:[],_s=J?g5:null,dt=At.find(M=>M.id===_s)||P1.find(M=>M.id===_s)||null,F1=P1.filter(M=>!Be.some(K=>{var V;return K.page==="sessions"&&K.param===ye&&((V=K.query)==null?void 0:V.surface)===i4(M.id)})),_5=M=>{Ct(K=>K+1),Re()},I1=M=>{nt(K=>K.some(V=>V.id===M.id)?K:[...K,M]),vr(K=>{if(!K.has(M.id))return K;const V=new Set(K);return V.delete(M.id),V}),_5(),Ni(!1),A.open({page:"sessions",param:M.sessionId,query:{surface:i4(M.id)}})},y5=M=>nt(K=>K.map(V=>V.id===M.id?{...V,revision:V.revision+1}:V)),z1=M=>Y({owner:"panel",phase:"failed",message:M instanceof Error?M.message:String(M)}),w5=async(M,K)=>{const V=Di(`/api/sessions/${encodeURIComponent(M)}/files/download?path=${encodeURIComponent(K)}`);try{const _e=await fetch(V,{method:"HEAD"});if(!_e.ok){const et=await _e.json().catch(()=>null);throw new Error((et==null?void 0:et.error)||x("session.fileDownloadFailed",{status:_e.status}))}const Ce=document.createElement("a");Ce.href=V,Ce.download=Zu(K),Ce.style.display="none",document.body.appendChild(Ce),Ce.click(),Ce.remove()}catch(_e){z1(_e)}},x5=async M=>{var K;try{if(!((K=navigator.clipboard)!=null&&K.writeText))throw new Error(x("session.fileCopyUnavailable"));await navigator.clipboard.writeText(M)}catch(V){z1(V)}};k.useEffect(()=>{const M=new Map;for(const _e of t)for(const Ce of _e.web||[]){const et={id:Bs(_e.id,"web",Ce.key),sessionId:_e.id,kind:"web",key:Ce.key,value:Ce.url,label:ih(Ce.url),revision:0};M.set(et.id,et)}const K=Yi.current;if(Yi.current=M,!K)return;const V=[...M].filter(([_e])=>!K.has(_e)).map(([,_e])=>_e);V.length&&vr(_e=>new Set([..._e,...V.map(Ce=>Ce.id)]))},[t]),k.useEffect(()=>{const M=new Set;for(const K of t){for(const V of K.files||[])M.add(Bs(K.id,"file",V));for(const V of K.web||[])M.add(Bs(K.id,"web",V.key))}nt(K=>K.filter(V=>M.has(V.id)))},[t]),k.useEffect(()=>{const M=new Set(Be.filter(K=>{var V;return K.page==="sessions"&&qa((V=K.query)==null?void 0:V.surface)}).map(K=>ff(K.query.surface)));_s&&M.add(_s),nt(K=>K.filter(V=>M.has(V.id)))},[Be,_s]),k.useEffect(()=>{!_s||!dt||nt(M=>M.some(K=>K.id===_s)?M:[...M,dt])},[_s,dt]);const sl=k.useMemo(()=>{const M=[];for(const K of t)for(const V of K.web||[]){const _e={id:Bs(K.id,"web",V.key),sessionId:K.id,kind:"web",key:V.key,value:V.url,label:ih(V.url),revision:0};vt.has(_e.id)&&M.push(_e)}return M},[t,vt]);Q1(sl.length?{id:"session-resource-unread",side:"right",priority:20,kind:"standard",text:x("session.unreadResources",{n:sl.length}),tooltip:x("session.unreadResources",{n:sl.length}),onClick:()=>I1(sl[0])}:null),ni(qt,()=>Ni(!1)),k.useEffect(()=>{if(!qt)return;const M=K=>{var V,_e;(_e=(V=K.target)==null?void 0:V.closest)!=null&&_e.call(V,'.document-action-menu, [data-action="resource-picker"]')||Ni(!1)};return window.addEventListener("mousedown",M,!0),()=>window.removeEventListener("mousedown",M,!0)},[qt]),ni(vs,()=>A.open({page:"sessions",param:ye,query:null},{replace:!0}));const nl=H[ye]||"",sn=M=>re(K=>({...K,[ye]:typeof M=="function"?M(K[ye]||""):M})),N0=M=>{M!=="new"&&(Re(),I0(),$1(K=>K.has(M)?K:new Set(K).add(M)),o(M))},L0=(M,K,V=!1)=>{M!=="new"&&(N0(M),K===Dr?Yr(_e=>_e.has(M)?_e:new Set(_e).add(M)):ke(_e=>_e+1),(V||M===ye)&&A.open({page:"sessions",param:M,query:{surface:K}},{replace:!0}))},S5=J3(Pe==null?void 0:Pe.harness),j1=X3();k.useEffect(()=>{Ae.current&&window.clearTimeout(Ae.current),Ae.current=null,te(!1),Y(null),I0()},[ye]),k.useEffect(()=>{R0||Re()},[R0]),k.useEffect(()=>()=>{Ae.current&&window.clearTimeout(Ae.current)},[]);const[H1,$1]=k.useState(()=>new Set);k.useEffect(()=>{$1(M=>{const K=new Set([...M].filter(V=>{const _e=Ft.find(Ce=>Ce.id===V);return _e&&!hn(_e)&&eh(_e)}));for(const V of Ft)!hn(V)&&eh(V)&&K.add(V.id);if(ye!=="new"){const V=t.find(_e=>_e.id===ye);V&&hn(V)&&K.add(ye)}return K.size===M.size&&[...K].every(V=>M.has(V))?M:K})},[Ft,ye]),k.useEffect(()=>{Yr(M=>{const K=new Set(Ft.map(Ce=>Ce.id)),V=new Set([...M].filter(Ce=>K.has(Ce))),_e=ye==="new"?null:Ft.find(Ce=>Ce.id===ye);return _e&&(!eh(_e)||hn(_e)||rn)&&V.add(_e.id),V.size===M.size&&[...V].every(Ce=>M.has(Ce))?M:V})},[Ft,ye,rn,Pt]),k.useEffect(()=>{if(a==null)return;o("new");const M=aB(a);W(M.text),j(M.selections),I0(),l==null||l(),requestAnimationFrame(()=>{const K=Si.current;K&&(K.focus(),K.setSelectionRange(a.length,a.length))})},[a]),k.useEffect(()=>{if(!r)return;const M=setTimeout(()=>{var K,V;ye==="new"?(K=Si.current)==null||K.focus():le&&((V=Wt.current)==null||V.focus())},0);return()=>clearTimeout(M)},[r,ye,le]);const O0=()=>{const M=lB($,z);M&&(W(""),j([]),VC(M,X).then(K=>{var V,_e,Ce,et,Et,Wn;K.ok&&K.id?(il({id:K.id,...K.session||{},label:((V=K.session)==null?void 0:V.label)||M.split(/\s+/).slice(0,8).join(" ")||K.id,title:((_e=K.session)==null?void 0:_e.title)||((Ce=K.session)==null?void 0:Ce.label)||M.split(/\s+/).slice(0,8).join(" ")||K.id,status:((et=K.session)==null?void 0:et.status)||"queued",liveness:((Et=K.session)==null?void 0:Et.liveness)||"offline",archived:!1,capabilities:((Wn=K.session)==null?void 0:Wn.capabilities)||{headless:!0}}),N1("sessions",K.id,null),A.open({page:"sessions",param:K.id,query:null}),f==null||f()):K.ok||D(K.error||x("session.launchFailed"),{kind:"error"})}))},q1=async()=>{const M=nl;if(!M.trim()||ye==="new")return;const K=W3(M,A5);if(K){sn(""),ys.close(),K.run();return}const V=q3(M,e);if((I==null?void 0:I.owner)==="command"&&I.phase==="sending")return;const _e=Gi.current[ye]||crypto.randomUUID();Gi.current[ye]=_e,Y({owner:"command",phase:"sending",message:x("session.outcomeSending")});const Ce=new AbortController,et=window.setTimeout(()=>Ce.abort(),Z5);try{const{ok:Et,status:Wn,outcome:ei}=await f4(ye,V,{deliveryId:_e,signal:Ce.signal});if(!Et){if(ei!=null&&ei.deliveryPending){Y({owner:"command",phase:"queued",message:x("session.outcomeQueued")});return}Y({owner:"command",phase:"failed",message:(ei==null?void 0:ei.error)||x("session.deliveryFailed",{status:Wn})});return}if((ei==null?void 0:ei.delivery)==="queued"){Y({owner:"command",phase:"queued",message:x("session.outcomeQueued")});return}sn(ll=>ll===M?"":ll),delete Gi.current[ye];const H0=(ei==null?void 0:ei.mentionSummary)||((ei==null?void 0:ei.delivery)==="deferred"?x("session.outcomeAccepted"):x("session.outcomeDelivered"));Y({owner:"command",phase:"delivered",message:H0}),Ae.current=window.setTimeout(()=>Re(),650)}catch(Et){if(Ce.signal.aborted){Y({owner:"command",phase:"failed",message:x("session.outcomeUnconfirmed")});return}Y({owner:"command",phase:"failed",message:Et instanceof Error?Et.message:String(Et)})}finally{window.clearTimeout(et)}},k5=()=>z.length?p.jsx("div",{className:"si-code-selection-queue","aria-label":x("session.codeSelectionAttachments"),children:z.map((M,K)=>p.jsx(uB,{selection:M,onRemove:()=>j(V=>V.filter((_e,Ce)=>Ce!==K))},`${M.path}:${M.startLine}:${M.endLine}:${K}`))}):null,P0=async(M,K,V="panel",_e={})=>{Y({owner:V,phase:"pending",message:x("session.outcomeWorking")});let Ce=!0;try{const et=await fetch(Di(`/api/sessions/${ye}/${M}`),K?{method:"POST",headers:{"content-type":"application/json",..._e},body:JSON.stringify(K)}:{method:"POST",headers:_e}),Et=await et.json().catch(()=>null);(!et.ok||(Et==null?void 0:Et.ok)===!1)&&(Ce=!1,Y({owner:V,phase:"failed",message:(Et==null?void 0:Et.error)||`session ${M} refused (HTTP ${et.status})`}))}catch(et){Ce=!1,Y({owner:V,phase:"failed",message:et instanceof Error?et.message:String(et)})}return Ce&&Y(null),await(f==null?void 0:f()),Ce&&V==="command"&&Re(),Ce},W1=async()=>{const M=await P0("resume");return M&&await Zs(),M},F0=wg(Pe,{command:()=>{le?Re():te(!0)},eval:()=>{J&&A.open(aT(lf(ye)))},relaunch:W1,stop:M=>P0("stop",void 0,M),close:M=>P0("close",void 0,M)}),K1=F0.filter(M=>M.typed!==!1&&M.enabled),V1=(M,K)=>({name:M.name,description:x(M.descKey),ui:!0,color:M.color,run:()=>{var V;return(V=M.run)==null?void 0:V.call(M,K)}}),U1=K1.map(M=>V1(M,"command")),C5=K1.map(M=>V1(M,"panel")),qn=gd({inputRef:Si,value:$,setValue:W,specs:e,sessions:Ft,launchers:G,focusId:Oe,slash:{commands:j1,mode:"token",head:x("session.menuPresets"),onPick:(M,K)=>{const V=[$.slice(0,K.start).trim(),$.slice(K.end).trim()].filter(Boolean).join(" "),_e=`/${M.name}${V?` ${V}`:""} `;return W(_e),requestAnimationFrame(()=>{const Ce=Si.current;Ce&&(Ce.focus(),Ce.setSelectionRange(_e.length,_e.length))}),!0}}}),ys=gd({inputRef:Wt,value:nl,setValue:sn,specs:e,sessions:Ft,launchers:G,focusId:Oe,up:!0,slash:{commands:Z3(U1,j1,S5),mode:"line",head:x("session.menuCommands"),onPick:M=>M.ui?(sn(""),M.run(),!0):!1}}),A5=U1,I0=()=>{qn.close(),ys.close()},z0=M=>U3(Wt.current,M,sn,ys.sync),ws=_d({inputRef:Si,setValue:W,variant:"new"}),Xr=_d({inputRef:Wt,setValue:sn,variant:"command"}),nn=Number.isInteger(bs.total)?x("session.evalDoorSummary",bs):"",j0=bs.phase==="ready"?nn:bs.phase==="updating"?x("session.evalUpdating",{summary:nn}):bs.phase==="disconnected"?x("session.evalDisconnected",{summary:nn}):bs.phase==="dormant"?nn?x("session.evalDormantKnown",{summary:nn}):x("session.evalDormant"):bs.phase==="loading"?x("session.evalLoading"):nn?x("session.evalFailedKnown",{summary:nn}):x("session.evalUnavailable"),E5=g4()&&J&&F0.some(M=>M.name==="eval");Q1(E5?{id:"session-eval",side:"right",priority:25,tooltip:j0,node:p.jsxs("a",{className:"si-eval-door","data-action":"eval",href:tl(lf(ye)),"data-tip":j0,"aria-label":j0,children:[p.jsx(je,{name:"evals",size:14}),p.jsx(BB,{summary:bs})]})}:null);const D5=J?Vt("sessions",ye,Oo?{surface:Oo}:null):null,M5=$n||O1?[Dr]:[Dr,Xn,la],ol=gs===la?tu(ye):gs,T5=J?[{id:"resource-picker",icon:"folder-open",label:x("session.addResourceTab"),priority:100,pressed:qt,haspopup:!0,onClick:()=>Ni(M=>(M||O(null),!M)),menuKey:qt?F1.map(M=>M.id).join(","):"",menu:qt?p.jsx(EB,{options:F1,onOpen:I1}):null},...!dt&&M5.length>1?[{id:"surface-switcher",icon:ol===Xn?"message-square":"terminal",label:x(ol===Xn?"session.switchToConversation":"session.switchToTerminal"),priority:80,menuKey:`${ol}:${vs?"diff":"base"}`,onClick:()=>{Ni(!1);const M=ol===Xn?Dr:Xn;KT(ye,M),L0(ye,M,!0)}},{id:"diff-switcher",icon:"git-compare",label:x(vs?"session.diffClose":"session.diffScope"),priority:79,pressed:vs,menuKey:vs?"diff":"base",onClick:()=>{Ni(!1),L0(ye,vs?tu(ye):la,!0)}}]:[],...F0.filter(M=>M.button&&!dt&&(gs==="terminal"||M.name!=="merge")).map(M=>{const K=M.enabled&&!(M.name==="command"&&rn);return{id:M.name,icon:M.icon,label:K?sB(x(M.titleKey),...M.shortcut?[M.shortcut]:[]):x(M.disabledTitleKey||M.titleKey),disabled:!K,disabledReason:M.enabled?void 0:x(M.disabledTitleKey),pressed:M.pressed?le:void 0,onClick:()=>{var V;return(V=M.run)==null?void 0:V.call(M)},priority:M.anchor==="right"?-10:50}}),...dt?[{id:"refresh-resource",icon:"rotate-ccw",label:x("session.refreshResourceTab",{name:dt.label}),priority:40,onClick:()=>y5(dt)},...dt.kind==="file"?[{id:"download-resource",icon:"download",label:x("session.downloadFile"),priority:39,onClick:()=>{w5(dt.sessionId,dt.value)}},{id:"copy-resource",icon:"copy",label:dt.value,priority:38,onClick:()=>{x5(dt.value)}}]:[]]:[]]:[],G1=k.useRef({}),al=ye==="new"?qn:ys;return G1.current={active:ye,submit:O0,menu:al.menu,navMenu:al.nav,accept:al.accept,closeMenu:al.dismiss,open:r,searchOpen:s,commandOpen:le,commandAvailable:R0,setCommandOpen:te,closeCommandBox:Re,sessionOrder:We},_f(M=>((V=>{var ul,J1,cl,Z1;const{active:_e,submit:Ce,menu:et,navMenu:Et,accept:Wn,closeMenu:ei,open:H0,searchOpen:ll,commandOpen:Y1,commandAvailable:B5,setCommandOpen:R5,closeCommandBox:X1,sessionOrder:Po}=G1.current;if(!(!H0||ll)&&!((J1=(ul=V.target)==null?void 0:ul.closest)!=null&&J1.call(ul,"[data-focus-overlay]"))&&!((V.key==="Enter"||V.key===" ")&&((Z1=(cl=V.target)==null?void 0:cl.closest)!=null&&Z1.call(cl,"button, a[href]")))){if(iB("shell.commandBox",V)&&!V.metaKey&&!V.ctrlKey&&_e!=="new"){V.preventDefault(),V.stopPropagation(),B5&&(Y1?X1():R5(!0));return}if(!(V.altKey&&!V.metaKey&&!V.ctrlKey&&["KeyN","KeyF"].includes(V.code))){if(et){if(V.key==="ArrowDown"){V.preventDefault(),V.stopPropagation(),Et(1);return}if(V.key==="ArrowUp"){V.preventDefault(),V.stopPropagation(),Et(-1);return}if((V.key==="Enter"||V.key==="Tab")&&!da(V)){V.preventDefault(),V.stopPropagation(),Wn(et.items[et.index]);return}if(V.key==="Escape"){V.preventDefault(),V.stopPropagation(),ei();return}}if(Y1&&V.key==="Escape"){V.preventDefault(),V.stopPropagation(),X1();return}if(V.key==="ArrowUp"||V.key==="ArrowDown"){if(n_(V.target))return;V.preventDefault(),V.stopPropagation();let $0=Po.indexOf(_e);$0<0&&($0=0);const q0=Math.max(0,Math.min(Po.length-1,$0+(V.key==="ArrowDown"?1:-1)));Po[q0]!==_e&&(c?c(Po[q0]):o(Po[q0]));return}}}})(M),M.cancelBubble),10,{allowTyping:!0}),p.jsxs(p.Fragment,{children:[p.jsxs("div",{className:"si-page",children:[L&&p.jsx(jT,{closing:q,opening:F,sessions:t,activeId:ye,onSelect:(M,K)=>c?c(M,K):M==="new"?o("new"):N0(M),archiveActive:v,onArchive:h,onSearch:d,reload:f,onContextMenu:O,selectRequest:T,onSelectRequestConsumed:()=>U(null),onError:M=>Y({owner:"panel",phase:"failed",message:M})}),p.jsxs("div",{className:"si-document",children:[w&&p.jsx(gB,{specs:e,sessions:t,route:w,onSessionContextMenu:M=>{Ni(!1),O(M)}}),p.jsxs("div",{className:"si-panel",onMouseDownCapture:wa,children:[ws.fileInput,Xr.fileInput,p.jsxs("section",{className:`si-content${ye==="new"?" is-new":" is-session"}`,children:[ye==="new"&&p.jsxs("div",{className:"si-new-center",children:[p.jsx(s5,{}),p.jsxs("div",{className:ws.dragging?"si-inputwrap dragover":"si-inputwrap",...ws.dropProps,children:[p.jsx(fd,{ref:Si,className:"si-input","data-focus-sink":!0,rows:1,value:$,onKeyDown:M=>{M.key!=="Enter"||M.shiftKey||da(M)||(M.preventDefault(),M.stopPropagation(),O0())},onChange:M=>{W(M.target.value),qn.sync(M.target)},onSelect:M=>qn.sync(M.target),onPaste:ws.onPaste,onBlur:qn.close,placeholder:x("session.inputPlaceholder"),spellCheck:!1}),p.jsx("button",{type:"button",className:"si-attach","data-tip":x("session.attachTitle"),onClick:ws.pick,disabled:ws.busy,children:ws.busy?p.jsx(wB,{}):p.jsx(yB,{})}),p.jsx(Zt,{icon:"send",size:14,className:"si-launch",label:x("session.launchSend"),disabled:!$.trim(),onMouseDown:wa,onClick:O0}),qn.menuEl]}),k5(),ws.queue,G.length?p.jsx(RB,{launchers:G,launcher:X,pickLauncher:oe}):null,p.jsxs("div",{className:"si-hint",children:[x("session.hint.before"),p.jsx("code",{children:"[["}),x("session.hint.mid"),p.jsx("code",{children:"/"}),x("session.hint.after")]})]}),p.jsxs("div",{className:"si-session-wrap","aria-hidden":!J,style:{display:"flex",flexDirection:"column",flex:1,minWidth:0,minHeight:0,position:J?"relative":"absolute",inset:J?void 0:0,visibility:J?"visible":"hidden",pointerEvents:J?"auto":"none"},children:[p.jsx(MB,{document:D5,actions:T5}),p.jsxs("div",{className:`si-term-body${rn?" is-conversation":""}${vs?" is-diff":""}${dt?" is-resource":""}`,id:dt?`si-resource-panel-${dt.id}`:`si-${gs}-panel-${ye}`,"aria-label":(dt==null?void 0:dt.label)||x(rn?"session.tabConversation":"session.tabTerminal"),style:{position:"relative"},children:[[...new Set([...H1,...ht])].map(M=>{const K=Ft.find(Et=>Et.id===M);if(!K)return null;const V=hn(K),_e=M===ye&&!dt,Ce=_e&&gs==="terminal",et=_e&&(V||gs===Dr);return p.jsxs("div",{children:[!V&&H1.has(M)&&p.jsx("div",{className:"si-term-layer",style:{position:"absolute",inset:0,visibility:Ce?"visible":"hidden",pointerEvents:Ce?"auto":"none"},children:p.jsx(P7,{sessionId:M,active:r&&Ce,focused:r&&Ce&&!le,writable:r&&Ce,focusRequest:M===ye?de:0})}),(V||ht.has(M))&&p.jsx("div",{className:"si-term-layer",style:{position:"absolute",inset:0,visibility:et?"visible":"hidden",pointerEvents:et?"auto":"none"},children:p.jsx(aA,{s:K,sessions:Ft,active:r&&et,specs:e,boardCommands:M===ye?C5:[],footerState:tm(K),onRestore:M===ye&&K.status!=="retired"?W1:void 0,actionOutcome:M===ye&&(I==null?void 0:I.owner)==="panel"?I:null})})]},M)}),vs&&p.jsx(iT,{sessionId:ye}),At.map(M=>{const K=(dt==null?void 0:dt.id)===M.id;return p.jsx("div",{className:"si-resource-layer",style:{position:"absolute",inset:0,visibility:K?"visible":"hidden",pointerEvents:K?"auto":"none"},children:p.jsx(TB,{tab:M,active:r&&K,focusRequest:K?Ye:0,onEscape:()=>L0(M.sessionId,v5(M.sessionId),!0)})},M.id)}),(I==null?void 0:I.owner)==="panel"&&b5==="live"&&p.jsx("div",{className:"si-action-outcome-float",children:p.jsx(n4,{outcome:I})}),le&&!Lo&&!rn&&p.jsxs("div",{className:"si-command-layer",role:"dialog","aria-label":x("session.commandBox"),children:[p.jsx("button",{type:"button",className:"si-command-dismiss",tabIndex:-1,"aria-label":x("session.commandClose"),onMouseDown:Re}),p.jsx(H3,{className:`si-command-box${Xr.dragging?" dragover":""}`,...Xr.dropProps,editor:p.jsxs(p.Fragment,{children:[p.jsxs("div",{className:"fv-tawrap",children:[p.jsx(fd,{ref:Wt,className:"si-command-input",rows:1,value:nl,"data-focus-sink":!0,onChange:M=>{delete Gi.current[ye],sn(M.target.value),ys.sync(M.target)},onSelect:M=>ys.sync(M.target),onPaste:Xr.onPaste,onBlur:ys.close,onKeyDown:M=>{M.key==="Enter"&&!M.shiftKey&&!da(M)&&(M.preventDefault(),M.stopPropagation(),q1())},placeholder:x("session.commandPlaceholder"),spellCheck:!1}),ys.menuEl]}),Xr.queue]}),footer:p.jsxs("div",{className:"si-command-tools",children:[p.jsxs("span",{className:"si-command-title",children:[p.jsx(je,{name:"command",size:12}),x("session.commandBox")]}),p.jsx("button",{type:"button",className:"fv-trigger-btn","data-tip":x("thread.mentionActor"),"aria-label":x("thread.mentionActor"),onClick:()=>z0("@"),children:"@"}),p.jsx("button",{type:"button",className:"fv-trigger-btn","data-tip":x("thread.mentionNode"),"aria-label":x("thread.mentionNode"),onClick:()=>z0("[["),children:"[["}),p.jsx("button",{type:"button",className:"fv-trigger-btn","data-tip":x("session.menuCommands"),"aria-label":x("session.menuCommands"),onClick:()=>z0("/"),children:"/"}),p.jsx(Zt,{icon:Xr.busy?"loader":"paperclip",size:14,iconClassName:Xr.busy?"si-attach-busy":void 0,className:"si-command-tool",label:x("session.attachTitle"),disabled:Xr.busy,onClick:Xr.pick}),(I==null?void 0:I.owner)==="command"&&p.jsx(n4,{outcome:I}),p.jsx(Zt,{icon:"send",size:14,className:"si-command-send",label:x("session.commandSend"),disabled:!nl.trim()||(I==null?void 0:I.owner)==="command"&&I.phase==="sending",onClick:q1})]})})]})]})]})]})]})]})]}),Oi&&p.jsx(_B,{sessions:en,onOpenSession:M=>{tn(!1),c==null||c(M),N0(M)},onClose:()=>{tn(!1),v&&A.open({page:"sessions",param:ye==="new"?null:ye,query:null})}}),p.jsx(AT,{menu:C,onClose:()=>O(null),onChanged:f,onError:M=>{var V;const K=(V=C==null?void 0:C.session)==null?void 0:V.id;if(K&&K!==ye){o(K),requestAnimationFrame(()=>Y({owner:"panel",phase:"failed",message:M}));return}Y({owner:"panel",phase:"failed",message:M})},onLock:M=>{R(M.source,{toggle:!1}),u()},onMultiSelect:M=>U(M),onDetach:M=>{Hi("/api/sessions/reparent",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({children:[M.id],parent:null})}).then(()=>f==null?void 0:f())}})]})}const gN=Object.freeze(Object.defineProperty({__proto__:null,LaunchHero:s5,default:o5,sessionEvalDisplay:n5},Symbol.toStringTag,{value:"Module"}));function NB({param:t,query:e}){const{specs:i,sessions:r,boardLive:s}=wf(),{reload:n}=v4(),{palette:o}=m4(),{openPalette:a,takeCompose:l,watchCompose:u}=yf(),c=e0(),h=k.useCallback((_,{newTab:w=!1}={})=>{const x={page:"sessions",param:_,query:null};return w&&_!=="new"&&N1(x.page,x.param,x.query),c.open(x)},[c]),d=t&&t!=="new"?t:"new",[f,m]=k.useState(null),v=g4();return k.useEffect(()=>{typeof(e==null?void 0:e.seed)=="string"&&e.seed.length&&m(e.seed)},[e==null?void 0:e.seed]),k.useEffect(()=>{if(!v)return;const _=()=>{const w=l();w!=null&&m(w)};return _(),u(_)},[v,l,u]),p.jsx(o5,{sessions:r,specs:i,focusNode:null,open:v,searchOpen:!!o,sel:d,surface:e==null?void 0:e.surface,setSel:h,seed:f,onSeedConsumed:()=>m(null),onClose:()=>c.open({page:"graph",param:null,query:null}),onPickSession:h,onOpenArchive:()=>c.open({page:"sessions",param:t&&t!=="new"?t:null,query:{archive:"1"}}),onOpenSearch:()=>a("sessions"),boardLive:s,reload:n,archiveRequested:(e==null?void 0:e.archive)==="1",route:{page:"sessions",param:t,query:e}})}const LB=/^[a-z][a-z0-9-]*$/,OB=t=>t&&typeof t=="object"&&!Array.isArray(t);function rh(t){if(typeof t!="string"||!LB.test(t))throw new TypeError(`view name must be lowercase kebab-case: ${String(t)}`)}const PB=new Set([Symbol.for("react.lazy"),Symbol.for("react.memo"),Symbol.for("react.forward_ref")]),FB=t=>typeof t=="function"||t&&typeof t=="object"&&PB.has(t.$$typeof);function o4(t){if(!t||typeof t!="object"||!FB(t.component))throw new TypeError("view definition requires a component function or React component");return Object.freeze({...t})}function IB(t={}){const e=new Map,i=new Map,r=new Map;for(const[l,u]of Object.entries(t))rh(l),e.set(l,o4(u)),i.set(l,"core");const s=(l,u,c="runtime")=>{if(rh(l),typeof c!="string"||c.length===0)throw new TypeError("view owner is required");if(e.has(l))throw new Error(`view already registered: ${l}`);return e.set(l,o4(u)),i.set(l,c),e.get(l)},n=l=>{if(!l||typeof l!="object"||typeof l.id!="string"||l.id.length===0)throw new TypeError("plugin requires a non-empty id");if(r.has(l.id))throw new Error(`plugin already registered: ${l.id}`);if(!l.views||typeof l.views!="object"||Array.isArray(l.views))throw new TypeError(`plugin ${l.id} requires a views object`);const u=Object.keys(l.views);for(const h of u)if(rh(h),e.has(h))throw new Error(`view already registered: ${h}`);const c=[];try{for(const h of u)s(h,l.views[h],l.id),c.push(h);r.set(l.id,Object.freeze({id:l.id,views:Object.freeze([...u])}))}catch(h){for(const d of c)e.delete(d),i.delete(d);throw h}return r.get(l.id)},o=l=>{const u=r.get(l);if(!u)return!1;for(const c of u.views)e.delete(c),i.delete(c);return r.delete(l),!0},a=Object.freeze({assertAddress:(l,u="address")=>{if(!OB(l)||typeof l.page!="string"||!e.has(l.page))throw new TypeError(`${u}.page is not a registered view: ${String(l==null?void 0:l.page)}`);const c=l.param??null;if(c!=null&&typeof c!="string")throw new TypeError(`${u}.param must be a string or null`);return typeof e.get(l.page).document=="function"&&c==="new"&&l.page==="sessions",l},isDocument:(l,u=null)=>{const c=e.get(l);return typeof(c==null?void 0:c.document)=="function"?c.document(l,u):!!(c!=null&&c.document)},isResident:(l,u=null)=>{var c;return!!((c=e.get(l))!=null&&c.resident)&&u==null}});return Object.freeze({get:l=>e.get(l),has:l=>e.has(l),ownerOf:l=>i.get(l),entries:()=>[...e.entries()],registerView:s,registerPlugin:n,unregisterPlugin:o,routeContract:a})}function zB(t){return{id:"dashboard-settings",views:{settings:{component:t,surface:"workspace",document:!0,resident:!0,icon:"settings",className:"view-settings"}}}}const sh="spexcode.chunk-reload";function In(t){return k.lazy(async()=>{for(let e=0;;e++)try{const i=await t();try{sessionStorage.removeItem(sh)}catch{}return i}catch(i){if(e<2){await new Promise(s=>setTimeout(s,250));continue}let r=!0;try{r=sessionStorage.getItem(sh)==="1"}catch{}if(r)throw i;try{sessionStorage.setItem(sh,"1")}catch{}location.reload(),await new Promise(()=>{})}})}const a5=In(()=>Gs(()=>import("./GraphView-BvMh1fxd.js"),__vite__mapDeps([5,1,2,3,6,7,8,9,4,10]))),jB=In(()=>Gs(()=>import("./SpecView-p-_SoBZr.js"),__vite__mapDeps([11,1,2,6,7,3,8,4]))),HB=In(()=>Gs(()=>import("./FileView-Ky36PD82.js"),__vite__mapDeps([12,1,2,8,3,4]))),$B=In(()=>Gs(()=>import("./EvalsPage-DnqAjyfu.js"),__vite__mapDeps([13,1,2,7,3,4]))),qB=In(()=>Gs(()=>import("./IssuesPage-o2vddaI6.js"),__vite__mapDeps([14,1,2,6,7,3,8,4]))),WB=In(()=>Gs(()=>import("./Settings-DMBJWtL1.js"),__vite__mapDeps([15,1,2,3,4]))),KB=In(()=>Gs(()=>import("./EmptyView-DXv-3Vi6.js"),__vite__mapDeps([16,1,2,3])));function VB({param:t,query:e}){return t==null?p.jsx(a5,{page:"spec",param:t,query:e}):p.jsx(jB,{param:t,query:e})}function UB({param:t,query:e}){const{specs:i,sessions:r,issuesStamp:s}=wf(),{reload:n}=v4(),o=e0(),a=l=>o.open({page:"sessions",param:l,query:null});return p.jsx($B,{param:t,query:e,specs:i,sessions:r,issuesStamp:s,reloadBoard:n,onOpenSession:a})}function GB({param:t,query:e}){const{specs:i,sessions:r,issuesStamp:s}=wf(),n=e0(),o=a=>n.open({page:"sessions",param:a,query:null});return p.jsx(qB,{param:t,query:e,specs:i,sessions:r,issuesStamp:s,onOpenSession:o})}function YB(){return p.jsx(WB,{})}const XB=Object.freeze({graph:{component:a5,surface:"workspace",document:!1,icon:"graph",className:"view-graph"},spec:{component:VB,surface:"workspace",document:!0,resident:!0,icon:"graph",className:"view-spec"},file:{component:HB,surface:"workspace",document:(t,e)=>e!=null,icon:"files",className:"view-file"},sessions:{component:NB,surface:"workspace",document:(t,e)=>e!=null&&e!=="new",icon:"sessions",className:"view-sessions"},evals:{component:UB,surface:"workspace",document:!0,resident:!0,icon:"evals",className:"view-evals"},issues:{component:GB,surface:"workspace",document:!0,resident:!0,icon:"issues",className:"view-issues"},empty:{component:KB,surface:"workspace",document:!1,className:"view-empty"}}),Ln=IB(XB),vN=Ln.routeContract,JB=t=>Ln.registerPlugin(t);JB(zB(YB));const bN=t=>Ln.get(t)||Ln.get("sessions"),ZB=t=>{var e;return((e=Ln.get(t))==null?void 0:e.icon)||null},l5=(t,e=null)=>{const i=Ln.get(t);return typeof(i==null?void 0:i.document)=="function"?i.document(t,e):!!(i!=null&&i.document)},QB=(t,e=null)=>{var i;return!!((i=Ln.get(t))!=null&&i.resident)&&e==null},uo=t=>{var e;return(t==null?void 0:t.page)==="sessions"&&typeof((e=t==null?void 0:t.query)==null?void 0:e.surface)=="string"&&t.query.surface.startsWith("resource:")},Qu=t=>uo(t)?"file":t==null?void 0:t.page,u5=new Set(["spec","evals","issues","settings"]),B0=t=>(t==null?void 0:t.page)==="sessions"&&(t!=null&&t.param)&&!uo(t)?{...t,query:null}:u5.has(t==null?void 0:t.page)?{...t,param:null,query:null}:t,Je=t=>{const e=B0(t);return Vt(e.page,e.param,e.query)};function eR(t,e=()=>!0){const i=[],r=new Set;for(const s of t){if(!e(s.page,s.param??null))continue;const n={page:s.page,param:s.param??null,query:s.query??null},o=Je(n);r.has(o)||(r.add(o),i.push(n))}return i}function tR(t,e,i="slot",r=null){const s={page:e.page,param:e.param??null,query:e.query??null},n=B0(s),o=Je(n),a=t.find(c=>Je(c)===o);if(a){const c=n.page==="sessions"&&!uo(n)&&JSON.stringify(a.query||null)!==JSON.stringify(n.query||null),h=u5.has(n.page)&&(a.param!==s.param||JSON.stringify(a.query||null)!==JSON.stringify(s.query||null));return!c&&!h?t:t.map(d=>Je(d)===o?{...d,param:s.param,query:s.query}:d)}const l={page:s.page,param:s.param,query:s.query},u=i==="append"||r==null?-1:t.findIndex(c=>Je(c)===r&&Qu(c)===Qu(n));return u<0?[...t,l]:t.map((c,h)=>h===u?l:c)}function mf(t,e,i=null){const r=t.findIndex(o=>Je(o)===e);if(r<0)return t;const s=t.filter((o,a)=>a!==r),n=i==null?s.length:s.findIndex(o=>Je(o)===i);return n<0||n===r?t:[...s.slice(0,n),t[r],...s.slice(n)]}function iR(t,e,i,r=[]){const s=Qu(B0(t));if(uo(t)){const c=e.find(h=>h.page==="sessions"&&h.param===t.param&&!uo(h));if(c)return c}const n=c=>{for(const h of r){const d=e.find(f=>Je(f)===h);if(d&&c(d))return d}return null},o=c=>{for(let h=0;h<e.length;h+=1){const d=e[i+h];if(d&&c(d))return d;const f=e[i-1-h];if(f&&c(f))return f}return null},a=()=>!0,l=c=>Qu(c)===s,u=n(a)||o(l)||o(a);return u||(uo(t)?{page:"sessions",param:"new",query:null}:(t==null?void 0:t.page)==="spec"||(t==null?void 0:t.page)==="file"?{page:"graph",param:null,query:null}:{page:"empty",param:null,query:null})}const gf="spexcode.tabs",rR=()=>{try{const t=JSON.parse(localStorage.getItem(gf)||"[]");if(!Array.isArray(t))return[];const e=t.filter(r=>r&&typeof r.page=="string"),i=eR(e,l5);return JSON.stringify(i)!==JSON.stringify(e)&&localStorage.setItem(gf,JSON.stringify(i)),i}catch{return[]}},sR=t=>{try{localStorage.setItem(gf,JSON.stringify(t))}catch{}};let c5=null;const vf=new Set,Ii=()=>c5??(c5=rR()),iu=t=>{const e=t;if(e===Ii())return e;c5=e,sR(e);for(const i of[...vf])i(e);return e};let co=[],a4=null;const nR=t=>{if(co[0]===t)return;const e=new Set(Ii().map(Je));co=[t,...co.filter(i=>i!==t&&e.has(i))]};let Jn=null,Ls=null;function oR(t){return Ls=t,()=>{Ls===t&&(Ls=null)}}function _N(t,...e){var i;return(i=Ls==null?void 0:Ls[t])==null?void 0:i.call(Ls,...e)}const h5=t=>t.button===0&&!t.shiftKey&&!t.altKey&&(t.ctrlKey||t.metaKey);function N1(t,e=null,i=null){const r=Je(B0({page:t,param:e,query:i}));Jn=Ii().some(s=>Je(s)===r)?null:r}function L1(t,e=null,i=null){N1(t,e,i),wn(t,e,{query:i})}const d5=t=>{const{page:e,param:i,query:r}=bf(t);return{page:e,param:i,query:Object.keys(r||{}).length?r:null}};function f5(t,e){if(!h5(t))return!1;t.preventDefault();const i=d5(e);return L1(i.page,i.param,i.query),!0}function yN(t){const e=Ii().filter(t),i=e[e.length-1];return i?(wn(i.page,i.param,{query:i.query}),!0):!1}function p5({onCloseStart:t}={}){const e=o_(),[i,r]=k.useState(Ii),s=k.useRef(t);k.useEffect(()=>{s.current=t},[t]),k.useEffect(()=>(vf.add(r),r(Ii()),()=>{vf.delete(r)}),[]),k.useEffect(()=>{const c=Je(e),h=a4;if(a4=c,Jn&&Jn!==c&&(Jn=null),!l5(e.page,e.param))return;const d=Jn===c?"append":"slot";Jn=null,iu(tR(Ii(),e,d,h)),nR(c)},[e.page,e.param,e.query]);const n=Je(e),o=k.useCallback(c=>wn(c.page,c.param,{query:c.query}),[]),a=k.useCallback(c=>{var v;const h=Je(c),d=Ii(),f=d.findIndex(_=>Je(_)===h);if(f<0)return;(v=s.current)==null||v.call(s,c);const m=d.filter((_,w)=>w!==f);if(iu(m),co=co.filter(_=>_!==h),h===n){const _=iR(c,m,f,co);wn(_.page,_.param,{query:_.query})}},[n]),l=k.useCallback(c=>{const h=Je(c),d=Ii();d.filter(f=>Je(f)!==h).forEach(f=>{var m;return(m=s.current)==null?void 0:m.call(s,f)}),iu(d.filter(f=>Je(f)===h)),h!==n&&wn(c.page,c.param,{query:c.query})},[n]),u=k.useCallback((c,h)=>{iu(mf(Ii(),c,h))},[]);return k.useEffect(()=>oR({closeActive:()=>{const c=Ii().find(h=>Je(h)===n);c&&a(c)},move:c=>{const h=Ii(),d=h.findIndex(f=>Je(f)===n);d<0||h.length<2||o(h[(d+c+h.length)%h.length])},active:()=>Ii().find(c=>Je(c)===n)||null}),[n,o,a]),k.useMemo(()=>({tabs:i,activeKey:n,open:o,close:a,closeOthers:l,move:u}),[i,n,o,a,l,u])}export{_N as $,Z2 as A,AT as B,E1 as C,ya as D,J6 as E,cf as F,K3 as G,vR as H,Hr as I,b4 as J,lr as K,KR as L,bB as M,$R as N,xT as O,tl as P,GR as Q,io as R,Ru as S,VR as T,kC as U,i5 as V,ZT as W,B1 as X,XT as Y,mB as Z,eB as _,Gu as a,CR as a$,gB as a0,aT as a1,Y3 as a2,SR as a3,xR as a4,aN as a5,bN as a6,G2 as a7,vN as a8,n1 as a9,tN as aA,gT as aB,ZR as aC,wT as aD,rN as aE,sN as aF,iN as aG,wR as aH,vC as aI,Y6 as aJ,HR as aK,YR as aL,gd as aM,EC as aN,H3 as aO,AR as aP,U3 as aQ,eN as aR,UR as aS,yR as aT,uC as aU,_C as aV,oN as aW,Go as aX,tm as aY,lB as aZ,N1 as a_,lN as aa,RT as ab,MT as ac,BT as ad,TT as ae,JR as af,fd as ag,da as ah,lf as ai,aA as aj,VC as ak,kR as al,nN as am,AC as an,uN as ao,ET as ap,dN as aq,xe as ar,Ke as as,PD as at,DR as au,MR as av,uM as aw,D0 as ax,be as ay,QR as az,Ci as b,OC as b0,uB as b1,o0 as b2,BC as b3,gR as b4,V3 as b5,C7 as b6,cN as b7,Xn as b8,Dr as b9,wD as bA,ji as bB,Js as bC,we as bD,Dn as bE,NR as bF,ef as bG,OR as bH,FR as bI,IR as bJ,PR as bK,zR as bL,jR as bM,rM as bN,iM as bO,BR as bP,gN as bQ,Xp as ba,S7 as bb,x7 as bc,mR as bd,hN as be,pN as bf,fN as bg,mN as bh,VD as bi,g6 as bj,Ki as bk,zD as bl,Qe as bm,oi as bn,kt as bo,ZD as bp,$a as bq,ui as br,Ve as bs,at as bt,LR as bu,No as bv,ve as bw,qe as bx,or as by,Fn as bz,U6 as c,hT as d,WR as e,yN as f,qR as g,cT as h,ZB as i,oT as j,f5 as k,iB as l,h5 as m,XR as n,L1 as o,X6 as p,LT as q,iw as r,rB as s,Kh as t,IT as u,OT as v,sB as w,Of as x,zT as y,Zc as z};
|