@marimo-team/frontend 0.18.5-dev198 → 0.18.5-dev200

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.
@@ -1,23 +1,23 @@
1
1
  const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./loro_wasm_bg-BTbzDT9t.js","./loro_wasm_bg-CghhyG7y.js","./chunk-LvLJmgfZ.js"])))=>i.map(i=>d[i]);
2
- var sd=Object.defineProperty;var Oa=re=>{throw TypeError(re)};var ld=(re,q,ge)=>q in re?sd(re,q,{enumerable:!0,configurable:!0,writable:!0,value:ge}):re[q]=ge;var p=(re,q,ge)=>ld(re,typeof q!="symbol"?q+"":q,ge),cd=(re,q,ge)=>q.has(re)||Oa("Cannot "+ge);var Da=(re,q,ge)=>(cd(re,q,"read from private field"),ge?ge.call(re):q.get(re)),_a=(re,q,ge)=>q.has(re)?Oa("Cannot add the same private member more than once"):q instanceof WeakSet?q.add(re):q.set(re,ge);import{s as Ua}from"./chunk-LvLJmgfZ.js";import{d as Ba,f as wr,i as Q,l as En,n as ue,p as jt,s as Nn,u as oe}from"./useEvent-DlWF5OMa.js";import{t as ud}from"./react-BGmjiNul.js";import{$t as dd,B as ja,Bn as fd,C as kn,Dt as vr,Er as Pa,Ft as md,Gr as pd,H as Ma,Kt as hd,L as Ra,M as gd,Mt as bd,Or as yd,Ot as Ga,Pt as Qe,Q as wd,Qt as vd,R as Ed,Rt as Cn,Tr as Nd,Tt as Er,Ur as Ja,Vt as kd,Yt as Cd,Z as Nr,Zt as Sd,_n as xd,_t as Ad,a as Wa,at as Td,bn as Id,br as Fd,ct as Ld,ei as Sn,fr as Od,gn as Dd,hn as _d,jt as Ud,kt as Va,l as $a,ln as Bd,lt as jd,ot as kr,p as Cr,st as xn,tn as Sr,u as Ha,ut as Pt,v as nt,vr as xr,vt as qa,wt as Pd,xr as Md,z as za,__tla as Rd}from"./cells-Dk_j8HX9.js";import{P as Ka,R as Gd,k as Jd,w as Wd}from"./zod-Cg4WLWh2.js";import{t as Re}from"./compiler-runtime-DeeZ7FnK.js";import{n as Vd,r as $d,s as Hd,t as qd,u as zd}from"./client-D08Rbi3p.js";import{d as $e,f as Kd,l as Ar,n as Ya}from"./hotkeys-uKX61F1_.js";import{t as yt}from"./invariant-C6yE60hi.js";import{f as Xa,i as Yd,m as Qa,o as Xd,p as Qd,s as Za,x as Tr}from"./utils-CJJIceVn.js";import{M as Zd,b as ef,j as wt,k as ei,o as tf,r as ti,s as nf,w as lt}from"./config-babG4OBR.js";import{a as rf,n as ni,t as of}from"./switch-Cd5iA-KH.js";import{n as af}from"./globals-BBskDqJi.js";import{t as sf}from"./ErrorBoundary-Drf1manw.js";import{t as lf}from"./useEventListener-COkmyg1v.js";import{t as cf}from"./jsx-runtime-DN_bIXfG.js";import{r as Ir,t as He}from"./button-DuYGqRtX.js";import{t as ct}from"./cn-C1rgT0yh.js";import{$t as An,Bt as Fr,Ct as ri,Dt as uf,E as df,Gt as ff,H as mf,I as pf,It as Tn,J as l,Jt as qe,P as hf,Pt as In,Rt as gf,St as Je,Ut as ut,V as oi,Vt as Mt,Xt as Rt,_ as bf,a as yf,at as B,bt as wf,ct as ze,ft as vf,it as Ef,jt as Nf,lt as Fn,m as kf,pt as Cf,qt as pe,rt as H,st as Sf,vt as xf,w as Af,wt as Tf,yt as If,zt as vt}from"./dist-CAcX026F.js";import{C as Ff,D as Lf,_ as Of,a as Df,c as _f,n as Lr,r as Uf,v as Bf,x as jf,y as Pf}from"./dist-CI6_zMIl.js";import{E as Mf,__tla as Rf}from"./JsonOutput-BCHaEg3R.js";import{c as ai,n as Gf}from"./once-CTiSlR1m.js";import{t as Or}from"./createReducer-DDa-hVe3.js";import{a as Jf,c as Wf,f as Ln,h as Vf,i as $f,l as Gt,n as ii,o as Hf,t as qf}from"./dist-DKNOF5xd.js";import{r as Jt,t as zf}from"./requests-C0HaHO6a.js";import{t as Kf}from"./createLucideIcon-CW2xpJ57.js";import{f as Yf,r as si,t as Xf,__tla as Qf}from"./layout-DenYhPfS.js";import{O as Zf,S as li,T as em,_ as tm,a as ci,k as nm,n as rm,o as om,r as ui,s as am,x as im}from"./add-cell-with-ai-CLrEdPGH.js";import{t as sm}from"./ai-model-dropdown-ea-cOLAL.js";import{h as lm}from"./select-D0g5GnIs.js";import{t as cm}from"./download-Dsuja3On.js";import{t as um}from"./circle-check-Cr0N4h9T.js";import{r as dm,t as fm}from"./types-CiMSegk1.js";import{n as di}from"./spinner-C1czjtp7.js";import{t as fi}from"./save-BOTLFf-P.js";import{I as mi,P as mm}from"./input-CaEtLL8p.js";import{a as pm,i as hm,n as pi}from"./state-HUtu_wpA.js";import{t as gm}from"./preload-helper-BW0IMuFq.js";import{t as Et}from"./use-toast-Bzf3rpev.js";import{r as bm}from"./useTheme-DfP1CWaW.js";import{t as Nt}from"./tooltip-CvjcEpZC.js";import{r as ym,t as wm}from"./mode-BOijHAOc.js";import{c as hi,i as gi,n as bi,r as vm}from"./dialog-DUEuLcT2.js";import{O as Em}from"./usePress-C2LPFxyv.js";import{a as Nm,r as km,t as Cm}from"./popover-DtnzNVk-.js";import{n as yi}from"./ImperativeModal-q6QlC2aZ.js";import{a as Sm}from"./error-banner-DU5Qb8a8.js";import{t as xm}from"./copy-DRhpWiOq.js";import{a as Am}from"./useRunCells-DLQFWY1L.js";import{t as Y}from"./extends-B9D0JO9U.js";import{t as Wt}from"./objectWithoutPropertiesLoose-CboCOq4o.js";import{t as Tm}from"./kbd-Czc5z_04.js";import{a as Dr}from"./useInstallPackage-RldLPyJs.js";import{a as Im,o as Fm}from"./cell-link-DNVmmRzI.js";import{n as Lm}from"./useAsyncData-BJJJOr9W.js";import{a as Om,o as wi,r as Dm,s as vi,t as _m}from"./command-gUA-HncX.js";import{r as Um}from"./es-DjCjT1hB.js";import{a as Bm}from"./focus-U1ePwk4d.js";import{a as Ei}from"./renderShortcut-D0Pei-OA.js";import{t as _r}from"./label-qwandMoh.js";import{n as Ur,t as Ni}from"./useDeleteCell-CFtiNna2.js";import{n as kt}from"./esm-B3JckBtM.js";import{n as jm,t as Pm}from"./icons-D4lB4En9.js";import{t as ki}from"./dist-Ciq1Lh9M.js";import{t as Mm}from"./useSplitCell-DDFoE9WM.js";import{t as Ci}from"./Inputs-DmoeP8nh.js";import{co as Rm,do as Br,fo as Gm,ft as Jm,go as Ct,ho as Si,lo as jr,mo as xi,oo as Ai,po as Wm,so as Ti,uo as Ii,__tla as Vm}from"./loro_wasm_bg-CghhyG7y.js";import{t as $m}from"./ws-itdlXHqs.js";import{t as Pr}from"./useInterval-DpipYmgs.js";let be,Fi,Li,Mr,Oi,On,Di,_i,Ui,Bi,dt,ji,Pi,Rr,Gr,Vt,Mi,Dn,Jr,_n,Un,Hm=Promise.all([(()=>{try{return Rd}catch{}})(),(()=>{try{return Rf}catch{}})(),(()=>{try{return Qf}catch{}})(),(()=>{try{return Vm}catch{}})()]).then(async()=>{var vn,La,we,ve,Ee,Ne,ke,Ce,Se,xe,Ae,Te,Ie,Fe,Le,Oe,De,_e,Ue,Be,je;var re=Kf("file-pen",[["path",{d:"M12.659 22H18a2 2 0 0 0 2-2V8a2.4 2.4 0 0 0-.706-1.706l-3.588-3.588A2.4 2.4 0 0 0 14 2H6a2 2 0 0 0-2 2v9.34",key:"o6klzx"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M10.378 12.622a1 1 0 0 1 3 3.003L8.36 20.637a2 2 0 0 1-.854.506l-2.867.837a.5.5 0 0 1-.62-.62l.836-2.869a2 2 0 0 1 .506-.853z",key:"zhnas1"}]]);const q={showInput:"Mod-l",acceptEdit:"Mod-y",rejectEdit:"Mod-u"};var ge=300;const xt=Mt.define({combine:e=>An(e,{onError:console.error,inputDebounceTime:ge,keymaps:q},{onError:(t,n)=>t&&n,inputDebounceTime:(t,n)=>t&&n,keymaps:(t,n)=>t&&n})}),rt=pe.define(),ot=qe.define({create(){return{show:!1,lineFrom:0,lineTo:0}},update(e,t){for(let n of t.effects)if(n.is(rt))return n.value;return e}}),At=pe.define(),Tt=pe.define(),Vr=qe.define({create(){return{shouldFocus:!1,inputValue:""}},update(e,t){let n=e;for(let r of t.effects)r.is(At)&&(n={...n,inputValue:r.value}),r.is(Tt)&&(n={...n,shouldFocus:r.value});return n}}),$t=pe.define(),It=qe.define({create(){return null},update(e,t){for(let n of t.effects)if(n.is($t))return n.value;return e}}),ft=pe.define(),$r=qe.define({create(){return!1},update(e,t){for(let n of t.effects)if(n.is(ft))return n.value;return e}});var Ri=1;const Hr=e=>{let{state:t}=e,n=t.selection.main;if(n.empty)return!1;let r=t.doc,o=r.lineAt(n.from),a=r.lineAt(n.to);if(t.sliceDoc(o.from,a.to).trim().length<Ri)return!1;let i=Math.max(1,Math.min(o.number,r.lines)),s=Math.max(1,Math.min(a.number,r.lines));return e.dispatch({effects:[rt.of({show:!0,lineFrom:i,lineTo:s}),Tt.of(!0),At.of("")],selection:vt.cursor(o.from)}),!0},qr=e=>e.state.field(It)?(e.dispatch({effects:[$t.of(null),rt.of({show:!1,lineFrom:0,lineTo:0}),Tt.of(!1),At.of(""),ft.of(!1)]}),!0):!1,zr=e=>{let t=e.state.field(It);return t?(e.dispatch({changes:{from:t.from,to:t.to,insert:t.oldCode},effects:[$t.of(null),rt.of({show:!1,lineFrom:0,lineTo:0}),Tt.of(!1),At.of(""),ft.of(!1)]}),!0):!1};var Bn={mac:"\u2318",windows:"\u229E Win",default:"Ctrl"};function Gi(){return navigator.platform.startsWith("Mac")?Bn.mac:navigator.platform.startsWith("Win")?Bn.windows:Bn.default}function jn(e){return e.replace("Mod",Gi()).replace("-"," ").toUpperCase()}function de(e,t){let n=document.createElement(e);return n.className=t,n}function Ji(e,t,n=void 0){let r=()=>{};return(...o)=>(r(),new Promise((a,i)=>{let s=setTimeout(()=>a(e(...o)),t);r=()=>{clearTimeout(s),n!==void 0&&i(n)}}))}var Ht=qe.define({create(){return{suggestion:null}},update(e,t){let n=t.effects.find(r=>r.is(qt));return!t.docChanged&&!n&&!t.selection?e:n&&t.state.doc===n.value.doc?{suggestion:n.value.text}:{suggestion:null}}}),qt=pe.define();function Wi(e,t){let n=e.state.selection.main.head,r=[],o=H.widget({widget:new Vi(t),side:1});return r.push(o.range(n)),H.set(r)}var Vi=class extends Fn{constructor(t){super();p(this,"suggestion");this.suggestion=t}toDOM(){let t=document.createElement("span");return t.style.opacity="0.4",t.className="cm-inline-suggestion",t.textContent=this.suggestion,t.setAttribute("role","suggestion"),t.setAttribute("aria-label",`Suggestion: ${this.suggestion}`),t}get lineBreaks(){return this.suggestion.split(`
3
- `).length-1}},$i=class{constructor(e){p(this,"cache",new Map);p(this,"timeout");this.timeout=e}get(e){let t=this.cache.get(e);return t?Date.now()-t.timestamp>this.timeout?(this.cache.delete(e),null):t.result:null}set(e,t){this.cache.set(e,{result:t,timestamp:Date.now()})}},Hi=(e,t)=>ze.fromClass(class{constructor(){p(this,"abortController",null);p(this,"cache");this.cache=new $i(t.cacheTimeout??1e3)}async update(n){var i,s,c,u,d;if(!n.docChanged||((s=(i=t.events)==null?void 0:i.beforeSuggestionFetch)==null?void 0:s.call(i,n.view))===!1)return;(c=this.abortController)==null||c.abort(),this.abortController=new AbortController;let r=n.state.doc,o=r.toString(),a=this.cache.get(o);if(a){n.view.dispatch({effects:qt.of({text:a,doc:r})});return}try{let f=await e(n.state,this.abortController.signal,n.view);if(this.abortController.signal.aborted||((d=(u=t.events)==null?void 0:u.shouldShowSuggestion)==null?void 0:d.call(u,n.view,f))===!1)return;this.cache.set(o,f),n.view.dispatch({effects:qt.of({text:f,doc:r})})}catch(f){f instanceof Error&&f.name!=="AbortError"&&console.error("Suggestion fetch error:",f)}}destroy(){var n;(n=this.abortController)==null||n.abort()}}),qi=ze.fromClass(class{constructor(){p(this,"decorations");this.decorations=H.none}update(e){var n;let t=(n=e.state.field(Ht))==null?void 0:n.suggestion;if(!t){this.decorations=H.none;return}this.decorations=Wi(e.view,t)}},{decorations:e=>e.decorations});function zi(e,t,n,r){return{...e.changeByRange(o=>{if(o===e.selection.main)return{changes:{from:n,to:r,insert:t},range:vt.cursor(n+t.length)};let a=r-n;return!o.empty||a&&e.sliceDoc(o.from-a,o.from)!==e.sliceDoc(n,r)?{range:o}:{changes:{from:o.from-a,to:o.from,insert:t},range:vt.cursor(o.from-a+t.length)}}),userEvent:"input.complete"}}var Ki=e=>{var r,o,a;let t=(r=e.state.field(Ht))==null?void 0:r.suggestion;if(!t)return!1;let n=e.state.facet(Pn);return e.dispatch({...zi(e.state,t,e.state.selection.main.head,e.state.selection.main.head)}),(a=(o=n.events)==null?void 0:o.onSuggestionAccepted)==null||a.call(o,e,t),!0},Kr=e=>{var r,o,a;let t=(r=e.state.field(Ht))==null?void 0:r.suggestion;if(!t)return!1;let n=e.state.facet(Pn);return e.dispatch({effects:qt.of({text:null,doc:e.state.doc})}),(a=(o=n.events)==null?void 0:o.onSuggestionRejected)==null||a.call(o,e,t),!0},Yi=Je.of([{key:"Tab",run:Ki},{key:"Escape",run:Kr}]),Pn=Mt.define({combine:e=>e.at(-1)});function Yr(e){let{delay:t=500,includeKeymap:n=!0}=e,r=Ji(e.fetchFn,t);return[Ht,Pn.of(e),Hi(r,e),qi,n?Yi:[]]}const Xi=B.baseTheme({".cm-ai-input-container":{display:"flex",flexDirection:"column",gap:"4px",width:"min(calc(100% + 7px), 500px)",padding:"5px 5px",margin:"0 -6px",backgroundColor:"light-dark(rgb(241, 243, 245), rgb(40, 40, 40))"},".cm-ai-input":{display:"block",width:"100%",padding:"3px 8px",border:"2px solid rgb(51, 154, 240)",borderRadius:"5px",fontSize:"12px"},".cm-ai-help-info-button":{fontSize:"10px",paddingLeft:"10px",height:"18px",color:"light-dark(rgb(109, 117, 125), rgb(170, 170, 170))",display:"block",marginRight:"auto"},".cm-ai-help-info-button:hover":{color:"light-dark(rgb(89, 97, 105), rgb(190, 190, 190))"},".cm-ai-generate-button":{background:"#0E639C",border:"none",padding:"2px 6px",color:"#ffffff",cursor:"pointer",font:"inherit",borderRadius:"4px","&:hover":{backgroundColor:"#1177bb"}},".cm-line.cm-ai-selection, .cm-line.cm-ai-selection.cm-active-line":{backgroundColor:"light-dark(color-mix(in srgb, rgb(223, 227, 232) 50%, transparent), color-mix(in srgb, rgb(50, 50, 50) 50%, transparent)) !important"},".cm-line:has(.cm-new-code-line)":{backgroundColor:"light-dark(color-mix(in srgb, rgb(183, 235, 143) 50%, transparent), color-mix(in srgb, rgb(40, 100, 40) 50%, transparent)) !important"},".cm-old-code-container":{backgroundColor:"light-dark(rgb(255, 205, 205), rgb(100, 40, 40))",position:"relative",display:"flex",paddingTop:"0",width:"100%",alignItems:"center"},".cm-code-button":{position:"absolute",right:"5px",top:"50%",transform:"translateY(-50%)",background:"none",border:"none",cursor:"pointer",fontSize:"16px"},".cm-floating-buttons":{fontFamily:"sans-serif",position:"absolute",top:"-20px",left:"5px",display:"flex"},".cm-floating-button":{fontFamily:"sans-serif",padding:"2px 5px",fontSize:"10px",cursor:"pointer",fontWeight:"700"},".cm-floating-accept":{backgroundColor:"light-dark(rgb(55, 125, 34), rgb(40, 80, 25))",borderTopLeftRadius:"5px",borderBottomLeftRadius:"5px",color:"white",filter:"brightness(90%)","&:hover":{filter:"brightness(100%)"}},".cm-floating-reject":{backgroundColor:"light-dark(rgb(220, 53, 69), rgb(180, 40, 50))",color:"white",borderTopRightRadius:"5px",borderBottomRightRadius:"5px",filter:"brightness(90%)","&:hover":{filter:"brightness(100%)"}},".hotkey":{display:"inline-block",padding:"0 4px",borderRadius:"3px",backgroundColor:"rgba(255, 255, 255, 0.1)",fontSize:"90%"},".cm-ai-loading-indicator":{fontStyle:"italic",fontSize:"10px",paddingLeft:"12px",color:"light-dark(rgb(109, 117, 125), rgb(170, 170, 170))",opacity:"0",transition:"opacity 0.3s ease-in-out","&::after":{content:'""',display:"inline-block",animation:"ellipsis-pulse 1.5s steps(4, end) infinite"},"&:not(:empty)":{opacity:"1"}},".cm-ai-input:disabled":{opacity:"0.5"},"@keyframes ellipsis-pulse":{"0%":{content:"'.'"},"25%":{content:"'..'"},"50%":{content:"'...'"},"75%":{content:"''"}},".cm-ai-loading-container":{display:"flex",alignItems:"center",padding:"0 8px"},".cm-ai-cancel-button":{padding:"2px 8px",fontSize:"10px",borderRadius:"4px",color:"light-dark(rgb(109, 117, 125), rgb(170, 170, 170))",cursor:"pointer","&:hover":{background:"light-dark(rgb(223, 227, 232), rgb(50, 50, 50))"}},".hidden":{display:"none"}});function Qi(e){var o,a;let t=e.state.facet(xt),n={...q,...t.keymaps},r=de("div","cm-ai-tooltip").appendChild(de("div","cm-ai-tooltip-button"));return r.innerHTML=`<span>Edit <span class="hotkey">${jn(n.showInput)}</span></span>`,(o=r.querySelector("span"))==null||o.addEventListener("mousedown",i=>{i.stopPropagation(),i.button===0&&i.preventDefault()}),(a=r.querySelector("span"))==null||a.addEventListener("click",i=>{i.preventDefault(),Hr(e)}),r}const Mn=Mt.define({combine(e){return An(e,{render:Qi,hideOnBlur:!1})}}),Zi=ze.fromClass((La=class{constructor(e){p(this,"view");p(this,"suppress");p(this,"dom");p(this,"mousedown",()=>{this.suppress=!0});p(this,"mouseup",()=>{this.suppress=!1,this.display(this.view)});p(this,"scroll",()=>{this.display(this.view)});p(this,"windowScroll",()=>{this.display(this.view)});_a(this,vn,e=>{var n;let t=e.state.selection.ranges.find(r=>!r.empty);if(t&&!this.suppress){let r=e.coordsAtPos(t.from);if(!r)return;let o=e.dom.getBoundingClientRect(),a=(n=e.dom.parentElement)==null?void 0:n.getBoundingClientRect(),i=r.top>=o.top&&r.top<=o.bottom&&r.left>=o.left&&r.left<=o.right,s=!a||r.top>=a.top&&r.top<=a.bottom&&r.left>=a.left&&r.left<=a.right;if(!i||!s){this.dom.style.display="none",this.dom.setAttribute("aria-hidden","true");return}this.dom.style.display="flex",this.dom.setAttribute("aria-hidden","false");let c=this.dom.getBoundingClientRect(),u=o.width-c.width,d=Math.min(r.left,u),f=r.top-c.height;f=a?Math.max(a.y,f):f,this.dom.style.left=`${d}px`,this.dom.style.top=`${f}px`,requestAnimationFrame(()=>{this.dom&&this.dom.setAttribute("aria-hidden","false")})}else this.dom.style.display="none",this.dom.setAttribute("aria-hidden","true")});this.view=e;let t=e.state.facet(Mn);this.suppress=!1,document.addEventListener("mousedown",this.mousedown),document.addEventListener("mouseup",this.mouseup),e.scrollDOM.addEventListener("scroll",this.scroll),window.addEventListener("scroll",this.windowScroll,!0);let n=t.render(e);e.dom.appendChild(n),this.dom=n}update(e){this.display(e.view)}docViewUpdate(e){this.display(e)}display(e){if(e.state.field(ot).show){this.dom.style.display="none";return}if(e.state.facet(Mn).hideOnBlur&&!e.hasFocus){this.dom.style.display="none",this.dom.setAttribute("aria-hidden","true");return}e.requestMeasure({read:Da(this,vn)})}destroy(){document.removeEventListener("mousedown",this.mousedown),document.removeEventListener("mouseup",this.mouseup),this.view.scrollDOM.removeEventListener("scroll",this.scroll),window.removeEventListener("scroll",this.windowScroll,!0),this.dom.remove()}},vn=new WeakMap,La));var es=B.baseTheme({".cm-ai-tooltip-button":{userSelect:"none",fontFamily:"system-ui, -apple-system, sans-serif",position:"fixed",display:"flex",boxSizing:"border-box",padding:"2px 6px",borderRadius:"4px",fontSize:"12px",backgroundColor:"#0E639C",color:"#ffffff",border:"1px solid transparent",boxShadow:"0 2px 4px rgba(0,0,0,0.1)",zIndex:"999",transition:"opacity 0.5s","&[aria-hidden='true']":{opacity:"0"},"&[aria-hidden='false']":{opacity:"1"},"& > span":{pointerEvents:"auto",cursor:"pointer",display:"inline-block",padding:"2px"},"&:hover":{backgroundColor:"#1177bb"}}});function ts(){return[Zi,es]}var ns=class extends Fn{constructor(t){super();p(this,"oldCode");this.oldCode=t}toDOM(t){let n=de("div","cm-old-code-container");n.setAttribute("role","region"),n.setAttribute("aria-label","Previous code version");let r=de("div","cm-old-code cm-line");r.textContent=this.oldCode;let o=de("div","cm-floating-buttons"),a=t.state.facet(xt),i={...q,...a.keymaps},s=de("button","cm-floating-button cm-floating-accept");s.innerHTML=`<span class="hotkey">${jn(i.acceptEdit)}</span> Accept`,s.setAttribute("aria-label","Accept changes"),s.addEventListener("click",u=>{u.preventDefault(),u.stopPropagation(),t.focus(),qr(t)});let c=de("button","cm-floating-button cm-floating-reject");return c.innerHTML=`<span class="hotkey">${jn(i.rejectEdit)}</span> Reject`,c.setAttribute("aria-label","Reject changes"),c.addEventListener("click",u=>{u.preventDefault(),u.stopPropagation(),t.focus(),zr(t)}),o.append(s,c),n.append(r,o),n}updateDOM(t,n){return!0}},rs=class extends Fn{constructor(t){super();p(this,"complete");p(this,"abortController",null);p(this,"dom",null);p(this,"input",null);p(this,"loadingContainer",null);p(this,"helpInfo",null);p(this,"inputContainer",null);p(this,"form",null);p(this,"view",null);p(this,"onKeyDown",async t=>{t.key==="Enter"&&!t.shiftKey?(t.preventDefault(),await this.handleSubmit()):t.key==="Escape"&&this.onCancel()});p(this,"onCancel",()=>{this.cleanup();let t=this.view;t&&(t.dispatch({effects:[rt.of({show:!1,lineFrom:0,lineTo:0}),ft.of(!1)]}),t.focus())});p(this,"handleSubmit",async t=>{var g;let n=this.view;if(!n)return;let r=n.state.facet(xt);t==null||t.stopPropagation();let o=n.state.field(ot),{input:a}=this;if(!a)return;let i=a.value.trim();if(!o.show||!i)return;let s=n.state.doc.line(o.lineFrom),c=n.state.doc.line(o.lineTo),u=s.from,d=c.to,f=n.state.sliceDoc(u,d),h=n.state.sliceDoc(0,u),m=n.state.sliceDoc(d);this.abortController=new AbortController,n.dispatch({effects:ft.of(!0)}),this.toggleLoading(!0);try{let y=await this.complete({prompt:i,selection:f,codeBefore:h,codeAfter:m,editorView:n,signal:this.abortController.signal});if(!n.state.field(ot).show)return;if(!y||typeof y!="string")throw Error("Invalid completion result");n.dispatch({changes:{from:u,to:d,insert:y},effects:[rt.of({show:!1,lineFrom:0,lineTo:0}),$t.of({from:u,to:u+y.length,oldCode:f,newCode:y}),ft.of(!1)]})}catch(y){if(y instanceof DOMException&&y.name==="AbortError")return;(g=r.onError)==null||g.call(r,y)}finally{this.cleanup(),this.toggleLoading(!1),n.focus()}});this.complete=t}toDOM(t){if(this.dom)return this.dom;this.view=t;let n=t.state.field(Vr),r=t.state.field($r),o=de("div","cm-ai-input-container");this.inputContainer=o,this.dom=o;let a=de("form","cm-ai-input-form");this.form=a,a.setAttribute("role","search"),a.setAttribute("aria-label","AI editing instructions"),a.addEventListener("submit",w=>w.preventDefault());let i=de("input","cm-ai-input");this.input=i,a.append(i),i.placeholder="Editing instructions...",i.setAttribute("aria-label","AI editing instructions"),i.setAttribute("autocomplete","off"),i.setAttribute("spellcheck","true"),i.value=n.inputValue;let s=de("div","cm-ai-loading-container");this.loadingContainer=s;let c=de("div","cm-ai-loading-indicator");c.setAttribute("role","status"),c.setAttribute("aria-live","polite"),c.textContent="Generating";let u=de("button","cm-ai-cancel-button");u.textContent="Cancel",u.setAttribute("aria-label","Cancel code generation"),u.addEventListener("click",this.onCancel),s.append(u,c);let d=de("div","cm-ai-help-info");this.helpInfo=d;let f=d.appendChild(document.createElement("button"));f.className="cm-ai-help-info-button",f.textContent="Esc to close",f.addEventListener("click",this.onCancel);let h=de("button","cm-ai-generate-button");h.textContent="\u23CE Generate",h.setAttribute("aria-label","Generate code"),h.addEventListener("click",this.handleSubmit),this.toggleLoading(r),n.shouldFocus&&requestAnimationFrame(()=>{i.value=n.inputValue,i.focus(),t.dispatch({effects:Tt.of(!1)})}),m(i.value),i.addEventListener("input",y),i.addEventListener("keydown",this.onKeyDown);function m(w){d.replaceChildren(w?h:f)}let g="";function y(){t.dispatch({effects:At.of(i.value)});let w=i.value.trim();w!==g&&(g=w,m(w))}return o}toggleLoading(t){var n;this.inputContainer&&this.form&&this.loadingContainer&&this.helpInfo&&((n=this.inputContainer)==null||n.replaceChildren(this.form,t?this.loadingContainer:this.helpInfo))}updateDOM(t,n){return this.dom=t,this.input=t.querySelector(".cm-ai-input"),!0}cleanup(){var t,n,r;(t=this.abortController)==null||t.abort(),this.abortController=null,(n=this.dom)==null||n.remove(),(r=this.input)==null||r.remove(),this.dom=null,this.input=null}destroy(){this.cleanup()}};function os(e){if(!e.prompt)throw Error("prompt function is required");let t={...q,...e.keymaps};return[xt.of(e),ot,Vr,It,$r,ts(),Xi,Je.of([{key:t.showInput,run:Hr}]),ut.highest([Je.of([{key:t.acceptEdit,run:qr},{key:t.rejectEdit,run:zr}])]),as,is,ss,ls]}const as=B.updateListener.of(e=>{let t=e.state.field(ot);if(!t.show||!e.docChanged)return;let{lineFrom:n,lineTo:r}=t,o=!1;e.changes.iterChanges((a,i,s,c)=>{let u=e.state.doc.lineAt(a).number;if(u<n){let d=e.state.doc.lineAt(c).number-e.state.doc.lineAt(s).number;n+=d,r+=d,o=!0}else if(u<=r){let d=e.state.doc.lineAt(c).number-e.state.doc.lineAt(s).number;r+=d,o=!0}}),o&&e.view.dispatch({effects:[rt.of({show:!0,lineFrom:n,lineTo:r})]})}),is=B.decorations.of(e=>{let t=e.state.field(It);return t?H.set([H.mark({class:"cm-new-code-line"}).range(t.from,t.to)]):H.none}),ss=B.decorations.compute([ot],e=>{let t=e.field(ot),n=e.facet(xt),r=[];if(t.show){let o=t.lineFrom,a=t.lineTo;for(let i=o;i<=a;i++){let s=e.doc.line(i).from;r.push(H.line({class:"cm-ai-selection"}).range(s)),i===o&&r.push(H.widget({widget:new rs(n.prompt),side:-1}).range(s))}}return H.set(r)}),ls=qe.define({create(e){return H.none},update(e,t){let n=t.state.field(It);return n?H.set([H.widget({widget:new ns(n.oldCode),block:!0}).range(n.from)]):H.none},provide:e=>B.decorations.from(e)});var cs=Re(),I=Ua(ud(),1),Rn=()=>({entries:new Map}),{valueAtom:Xr,useActions:Qr}=Or(Rn,{submit:(e,t)=>{let{cellIds:n,deleteCell:r,deleteManyCells:o,store:a}=t,i=a.get(nt),s=a.get(_d),c=new Set(i.cellIds.inOrderIds.filter(f=>i.cellData[f].code.trim()==="")),u=new Map;for(let f of n){if(c.has(f)){u.set(f,{cellId:f,type:"simple"});continue}let h=i.cellRuntime[f],m=new Map;for(let y of Object.values(s)){let w=y.declaredBy.includes(f),k=y.usedBy.some(C=>!c.has(C));w&&k&&m.set(y.name,y.usedBy)}let g;h!=null&&h.runElapsedTimeMs&&h.runElapsedTimeMs>2e3&&(g=h.runElapsedTimeMs),m.size===0&&g===void 0?u.set(f,{cellId:f,type:"simple"}):u.set(f,{cellId:f,type:"expensive",executionDurationMs:g,defs:m})}let d=[...u.values()].every(f=>f.type==="simple");return u.size>0&&d?(u.size===1?r({cellId:[...u.values()][0].cellId}):o({cellIds:[...u.values()].map(f=>f.cellId)}),Rn()):{...e,entries:u}},clear:()=>Rn()});_n=function(){let e=wr(),{submit:t,clear:n}=Qr(),{entries:r}=oe(Xr),o=Ni(),a=Ur();return(0,I.useMemo)(()=>({submit:i=>{t({cellIds:i,deleteCell:o,deleteManyCells:a,store:e})},clear:n,get idle(){return r.size===0},get shouldConfirmDelete(){return r.size>1}}),[e,t,n,r,o,a])},Li=function(e){let t=(0,cs.c)(16),n=oe(Xr),r=Qr(),o=Ur(),a;t[0]!==e||t[1]!==n.entries?(a=n.entries.get(e),t[0]=e,t[1]=n.entries,t[2]=a):a=t[2];let i=a;if(!i){let d;return t[3]===Symbol.for("react.memo_cache_sentinel")?(d={isPending:!1},t[3]=d):d=t[3],d}if(n.entries.size!==1){let d;return t[4]===i?d=t[5]:(d={isPending:!0,shouldConfirmDelete:!1,...i},t[4]=i,t[5]=d),d}let s;t[6]!==r||t[7]!==o||t[8]!==n.entries?(s=()=>{o({cellIds:[...n.entries.values()].map(us)}),r.clear()},t[6]=r,t[7]=o,t[8]=n.entries,t[9]=s):s=t[9];let c;t[10]===r?c=t[11]:(c=()=>r.clear(),t[10]=r,t[11]=c);let u;return t[12]!==i||t[13]!==s||t[14]!==c?(u={isPending:!0,...i,shouldConfirmDelete:!0,confirm:s,cancel:c},t[12]=i,t[13]=s,t[14]=c,t[15]=u):u=t[15],u};function us(e){return e.cellId}async function ds(e){var s,c;let t=`
2
+ var rd=Object.defineProperty;var Fa=re=>{throw TypeError(re)};var od=(re,q,ge)=>q in re?rd(re,q,{enumerable:!0,configurable:!0,writable:!0,value:ge}):re[q]=ge;var p=(re,q,ge)=>od(re,typeof q!="symbol"?q+"":q,ge),ad=(re,q,ge)=>q.has(re)||Fa("Cannot "+ge);var La=(re,q,ge)=>(ad(re,q,"read from private field"),ge?ge.call(re):q.get(re)),Oa=(re,q,ge)=>q.has(re)?Fa("Cannot add the same private member more than once"):q instanceof WeakSet?q.add(re):q.set(re,ge);import{s as Da}from"./chunk-LvLJmgfZ.js";import{d as _a,f as wr,i as Q,l as En,n as ue,p as Bt,s as Nn,u as oe}from"./useEvent-DlWF5OMa.js";import{t as id}from"./react-BGmjiNul.js";import{$t as sd,B as Ua,Bn as ld,C as kn,Dt as vr,Er as Ba,Ft as cd,Gr as ud,H as ja,Kt as dd,L as Pa,M as fd,Mt as md,Or as pd,Ot as Ma,Pt as Qe,Q as hd,Qt as gd,R as bd,Rt as Cn,Tr as yd,Tt as Er,Ur as Ra,Vt as wd,Yt as vd,Z as Nr,Zt as Ed,_n as Nd,_t as kd,a as Ga,at as Cd,bn as Sd,br as xd,ct as Ad,ei as Sn,fr as Td,gn as Id,hn as Fd,jt as Ld,kt as Ja,l as Wa,ln as Od,lt as Dd,ot as kr,p as Cr,st as xn,tn as Sr,u as Va,ut as jt,v as nt,vr as xr,vt as $a,wt as _d,xr as Ud,z as Ha,__tla as Bd}from"./cells-Dk_j8HX9.js";import{P as qa,R as jd,k as Pd,w as Md}from"./zod-Cg4WLWh2.js";import{t as Re}from"./compiler-runtime-DeeZ7FnK.js";import{n as Rd,r as Gd,s as Jd,t as Wd,u as Vd}from"./client-D08Rbi3p.js";import{d as $e,f as $d,l as Ar,n as za}from"./hotkeys-uKX61F1_.js";import{t as Pt}from"./invariant-C6yE60hi.js";import{f as Ka,i as Hd,m as Ya,o as qd,p as zd,s as Xa,x as Tr}from"./utils-CJJIceVn.js";import{M as Kd,b as Yd,j as yt,k as Qa,o as Xd,r as Za,s as Qd,w as lt}from"./config-babG4OBR.js";import{a as Zd,n as ei,t as ef}from"./switch-Cd5iA-KH.js";import{n as tf}from"./globals-BBskDqJi.js";import{t as nf}from"./ErrorBoundary-Drf1manw.js";import{t as rf}from"./useEventListener-COkmyg1v.js";import{t as of}from"./jsx-runtime-DN_bIXfG.js";import{r as Ir,t as He}from"./button-DuYGqRtX.js";import{t as ct}from"./cn-C1rgT0yh.js";import{$t as An,Bt as Fr,Ct as ti,Dt as af,E as sf,Gt as lf,H as cf,I as uf,It as Tn,J as l,Jt as qe,P as df,Pt as In,Rt as ff,St as Je,Ut as ut,V as ni,Vt as Mt,Xt as Rt,_ as mf,a as pf,at as B,bt as hf,ct as ze,ft as gf,it as bf,jt as yf,lt as Fn,m as wf,pt as vf,qt as pe,rt as H,st as Ef,vt as Nf,w as kf,wt as Cf,yt as Sf,zt as wt}from"./dist-CAcX026F.js";import{C as xf,D as Af,_ as Tf,a as If,c as Ff,n as Lr,r as Lf,v as Of,x as Df,y as _f}from"./dist-CI6_zMIl.js";import{E as Uf,__tla as Bf}from"./JsonOutput-BCHaEg3R.js";import{c as ri,n as jf}from"./once-CTiSlR1m.js";import{t as Or}from"./createReducer-DDa-hVe3.js";import{a as Pf,c as Mf,f as Ln,h as Rf,i as Gf,l as Gt,n as oi,o as Jf,t as Wf}from"./dist-DKNOF5xd.js";import{r as Jt,t as Vf}from"./requests-C0HaHO6a.js";import{t as $f}from"./createLucideIcon-CW2xpJ57.js";import{f as Hf,r as ai,t as qf,__tla as zf}from"./layout-DenYhPfS.js";import{O as Kf,S as ii,T as Yf,_ as Xf,a as si,k as Qf,n as Zf,o as em,r as li,s as tm,x as nm}from"./add-cell-with-ai-CLrEdPGH.js";import{t as rm}from"./ai-model-dropdown-ea-cOLAL.js";import{h as om}from"./select-D0g5GnIs.js";import{t as am}from"./download-Dsuja3On.js";import{t as im}from"./circle-check-Cr0N4h9T.js";import{r as sm,t as lm}from"./types-CiMSegk1.js";import{n as ci}from"./spinner-C1czjtp7.js";import{t as ui}from"./save-BOTLFf-P.js";import{I as di,P as cm}from"./input-CaEtLL8p.js";import{a as um,i as dm,n as fi}from"./state-HUtu_wpA.js";import{t as fm}from"./preload-helper-BW0IMuFq.js";import{t as vt}from"./use-toast-Bzf3rpev.js";import{r as mm}from"./useTheme-DfP1CWaW.js";import{t as Et}from"./tooltip-CvjcEpZC.js";import{r as pm,t as hm}from"./mode-BOijHAOc.js";import{c as mi,i as pi,n as hi,r as gm}from"./dialog-DUEuLcT2.js";import{O as bm}from"./usePress-C2LPFxyv.js";import{a as ym,r as wm,t as vm}from"./popover-DtnzNVk-.js";import{n as gi}from"./ImperativeModal-q6QlC2aZ.js";import{a as Em}from"./error-banner-DU5Qb8a8.js";import{t as Nm}from"./copy-DRhpWiOq.js";import{a as km}from"./useRunCells-DLQFWY1L.js";import{t as Y}from"./extends-B9D0JO9U.js";import{t as Wt}from"./objectWithoutPropertiesLoose-CboCOq4o.js";import{t as Cm}from"./kbd-Czc5z_04.js";import{a as Dr}from"./useInstallPackage-RldLPyJs.js";import{a as Sm,o as xm}from"./cell-link-DNVmmRzI.js";import{n as Am}from"./useAsyncData-BJJJOr9W.js";import{a as Tm,o as bi,r as Im,s as yi,t as Fm}from"./command-gUA-HncX.js";import{r as Lm}from"./es-DjCjT1hB.js";import{a as Om}from"./focus-U1ePwk4d.js";import{a as wi}from"./renderShortcut-D0Pei-OA.js";import{t as _r}from"./label-qwandMoh.js";import{n as Ur,t as vi}from"./useDeleteCell-CFtiNna2.js";import{n as Nt}from"./esm-B3JckBtM.js";import{n as Dm,t as _m}from"./icons-D4lB4En9.js";import{t as Ei}from"./dist-Ciq1Lh9M.js";import{t as Um}from"./useSplitCell-DDFoE9WM.js";import{t as Ni}from"./Inputs-DmoeP8nh.js";import{co as Bm,do as Br,fo as jm,ft as Pm,go as kt,ho as ki,lo as jr,mo as Ci,oo as Si,po as Mm,so as xi,uo as Ai,__tla as Rm}from"./loro_wasm_bg-CghhyG7y.js";import{t as Gm}from"./ws-itdlXHqs.js";import{t as Pr}from"./useInterval-DpipYmgs.js";let Ti,Mr,Ii,dt,Fi,On,Rr,Vt,Dn,be,Li,Oi,Di,_i,_n,Ui,Gr,Un,Jm=Promise.all([(()=>{try{return Bd}catch{}})(),(()=>{try{return Bf}catch{}})(),(()=>{try{return zf}catch{}})(),(()=>{try{return Rm}catch{}})()]).then(async()=>{var vn,Ia,we,ve,Ee,Ne,ke,Ce,Se,xe,Ae,Te,Ie,Fe,Le,Oe,De,_e,Ue,Be,je;var re=$f("file-pen",[["path",{d:"M12.659 22H18a2 2 0 0 0 2-2V8a2.4 2.4 0 0 0-.706-1.706l-3.588-3.588A2.4 2.4 0 0 0 14 2H6a2 2 0 0 0-2 2v9.34",key:"o6klzx"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M10.378 12.622a1 1 0 0 1 3 3.003L8.36 20.637a2 2 0 0 1-.854.506l-2.867.837a.5.5 0 0 1-.62-.62l.836-2.869a2 2 0 0 1 .506-.853z",key:"zhnas1"}]]);const q={showInput:"Mod-l",acceptEdit:"Mod-y",rejectEdit:"Mod-u"};var ge=300;const St=Mt.define({combine:e=>An(e,{onError:console.error,inputDebounceTime:ge,keymaps:q},{onError:(t,n)=>t&&n,inputDebounceTime:(t,n)=>t&&n,keymaps:(t,n)=>t&&n})}),rt=pe.define(),ot=qe.define({create(){return{show:!1,lineFrom:0,lineTo:0}},update(e,t){for(let n of t.effects)if(n.is(rt))return n.value;return e}}),xt=pe.define(),At=pe.define(),Wr=qe.define({create(){return{shouldFocus:!1,inputValue:""}},update(e,t){let n=e;for(let r of t.effects)r.is(xt)&&(n={...n,inputValue:r.value}),r.is(At)&&(n={...n,shouldFocus:r.value});return n}}),$t=pe.define(),Tt=qe.define({create(){return null},update(e,t){for(let n of t.effects)if(n.is($t))return n.value;return e}}),ft=pe.define(),Vr=qe.define({create(){return!1},update(e,t){for(let n of t.effects)if(n.is(ft))return n.value;return e}});var Bi=1;const $r=e=>{let{state:t}=e,n=t.selection.main;if(n.empty)return!1;let r=t.doc,o=r.lineAt(n.from),a=r.lineAt(n.to);if(t.sliceDoc(o.from,a.to).trim().length<Bi)return!1;let i=Math.max(1,Math.min(o.number,r.lines)),s=Math.max(1,Math.min(a.number,r.lines));return e.dispatch({effects:[rt.of({show:!0,lineFrom:i,lineTo:s}),At.of(!0),xt.of("")],selection:wt.cursor(o.from)}),!0},Hr=e=>e.state.field(Tt)?(e.dispatch({effects:[$t.of(null),rt.of({show:!1,lineFrom:0,lineTo:0}),At.of(!1),xt.of(""),ft.of(!1)]}),!0):!1,qr=e=>{let t=e.state.field(Tt);return t?(e.dispatch({changes:{from:t.from,to:t.to,insert:t.oldCode},effects:[$t.of(null),rt.of({show:!1,lineFrom:0,lineTo:0}),At.of(!1),xt.of(""),ft.of(!1)]}),!0):!1};var Bn={mac:"\u2318",windows:"\u229E Win",default:"Ctrl"};function ji(){return navigator.platform.startsWith("Mac")?Bn.mac:navigator.platform.startsWith("Win")?Bn.windows:Bn.default}function jn(e){return e.replace("Mod",ji()).replace("-"," ").toUpperCase()}function de(e,t){let n=document.createElement(e);return n.className=t,n}function Pi(e,t,n=void 0){let r=()=>{};return(...o)=>(r(),new Promise((a,i)=>{let s=setTimeout(()=>a(e(...o)),t);r=()=>{clearTimeout(s),n!==void 0&&i(n)}}))}var Ht=qe.define({create(){return{suggestion:null}},update(e,t){let n=t.effects.find(r=>r.is(qt));return!t.docChanged&&!n&&!t.selection?e:n&&t.state.doc===n.value.doc?{suggestion:n.value.text}:{suggestion:null}}}),qt=pe.define();function Mi(e,t){let n=e.state.selection.main.head,r=[],o=H.widget({widget:new Ri(t),side:1});return r.push(o.range(n)),H.set(r)}var Ri=class extends Fn{constructor(t){super();p(this,"suggestion");this.suggestion=t}toDOM(){let t=document.createElement("span");return t.style.opacity="0.4",t.className="cm-inline-suggestion",t.textContent=this.suggestion,t.setAttribute("role","suggestion"),t.setAttribute("aria-label",`Suggestion: ${this.suggestion}`),t}get lineBreaks(){return this.suggestion.split(`
3
+ `).length-1}},Gi=class{constructor(e){p(this,"cache",new Map);p(this,"timeout");this.timeout=e}get(e){let t=this.cache.get(e);return t?Date.now()-t.timestamp>this.timeout?(this.cache.delete(e),null):t.result:null}set(e,t){this.cache.set(e,{result:t,timestamp:Date.now()})}},Ji=(e,t)=>ze.fromClass(class{constructor(){p(this,"abortController",null);p(this,"cache");this.cache=new Gi(t.cacheTimeout??1e3)}async update(n){var i,s,c,u,d;if(!n.docChanged||((s=(i=t.events)==null?void 0:i.beforeSuggestionFetch)==null?void 0:s.call(i,n.view))===!1)return;(c=this.abortController)==null||c.abort(),this.abortController=new AbortController;let r=n.state.doc,o=r.toString(),a=this.cache.get(o);if(a){n.view.dispatch({effects:qt.of({text:a,doc:r})});return}try{let f=await e(n.state,this.abortController.signal,n.view);if(this.abortController.signal.aborted||((d=(u=t.events)==null?void 0:u.shouldShowSuggestion)==null?void 0:d.call(u,n.view,f))===!1)return;this.cache.set(o,f),n.view.dispatch({effects:qt.of({text:f,doc:r})})}catch(f){f instanceof Error&&f.name!=="AbortError"&&console.error("Suggestion fetch error:",f)}}destroy(){var n;(n=this.abortController)==null||n.abort()}}),Wi=ze.fromClass(class{constructor(){p(this,"decorations");this.decorations=H.none}update(e){var n;let t=(n=e.state.field(Ht))==null?void 0:n.suggestion;if(!t){this.decorations=H.none;return}this.decorations=Mi(e.view,t)}},{decorations:e=>e.decorations});function Vi(e,t,n,r){return{...e.changeByRange(o=>{if(o===e.selection.main)return{changes:{from:n,to:r,insert:t},range:wt.cursor(n+t.length)};let a=r-n;return!o.empty||a&&e.sliceDoc(o.from-a,o.from)!==e.sliceDoc(n,r)?{range:o}:{changes:{from:o.from-a,to:o.from,insert:t},range:wt.cursor(o.from-a+t.length)}}),userEvent:"input.complete"}}var $i=e=>{var r,o,a;let t=(r=e.state.field(Ht))==null?void 0:r.suggestion;if(!t)return!1;let n=e.state.facet(Pn);return e.dispatch({...Vi(e.state,t,e.state.selection.main.head,e.state.selection.main.head)}),(a=(o=n.events)==null?void 0:o.onSuggestionAccepted)==null||a.call(o,e,t),!0},zr=e=>{var r,o,a;let t=(r=e.state.field(Ht))==null?void 0:r.suggestion;if(!t)return!1;let n=e.state.facet(Pn);return e.dispatch({effects:qt.of({text:null,doc:e.state.doc})}),(a=(o=n.events)==null?void 0:o.onSuggestionRejected)==null||a.call(o,e,t),!0},Hi=Je.of([{key:"Tab",run:$i},{key:"Escape",run:zr}]),Pn=Mt.define({combine:e=>e.at(-1)});function Kr(e){let{delay:t=500,includeKeymap:n=!0}=e,r=Pi(e.fetchFn,t);return[Ht,Pn.of(e),Ji(r,e),Wi,n?Hi:[]]}const qi=B.baseTheme({".cm-ai-input-container":{display:"flex",flexDirection:"column",gap:"4px",width:"min(calc(100% + 7px), 500px)",padding:"5px 5px",margin:"0 -6px",backgroundColor:"light-dark(rgb(241, 243, 245), rgb(40, 40, 40))"},".cm-ai-input":{display:"block",width:"100%",padding:"3px 8px",border:"2px solid rgb(51, 154, 240)",borderRadius:"5px",fontSize:"12px"},".cm-ai-help-info-button":{fontSize:"10px",paddingLeft:"10px",height:"18px",color:"light-dark(rgb(109, 117, 125), rgb(170, 170, 170))",display:"block",marginRight:"auto"},".cm-ai-help-info-button:hover":{color:"light-dark(rgb(89, 97, 105), rgb(190, 190, 190))"},".cm-ai-generate-button":{background:"#0E639C",border:"none",padding:"2px 6px",color:"#ffffff",cursor:"pointer",font:"inherit",borderRadius:"4px","&:hover":{backgroundColor:"#1177bb"}},".cm-line.cm-ai-selection, .cm-line.cm-ai-selection.cm-active-line":{backgroundColor:"light-dark(color-mix(in srgb, rgb(223, 227, 232) 50%, transparent), color-mix(in srgb, rgb(50, 50, 50) 50%, transparent)) !important"},".cm-line:has(.cm-new-code-line)":{backgroundColor:"light-dark(color-mix(in srgb, rgb(183, 235, 143) 50%, transparent), color-mix(in srgb, rgb(40, 100, 40) 50%, transparent)) !important"},".cm-old-code-container":{backgroundColor:"light-dark(rgb(255, 205, 205), rgb(100, 40, 40))",position:"relative",display:"flex",paddingTop:"0",width:"100%",alignItems:"center"},".cm-code-button":{position:"absolute",right:"5px",top:"50%",transform:"translateY(-50%)",background:"none",border:"none",cursor:"pointer",fontSize:"16px"},".cm-floating-buttons":{fontFamily:"sans-serif",position:"absolute",top:"-20px",left:"5px",display:"flex"},".cm-floating-button":{fontFamily:"sans-serif",padding:"2px 5px",fontSize:"10px",cursor:"pointer",fontWeight:"700"},".cm-floating-accept":{backgroundColor:"light-dark(rgb(55, 125, 34), rgb(40, 80, 25))",borderTopLeftRadius:"5px",borderBottomLeftRadius:"5px",color:"white",filter:"brightness(90%)","&:hover":{filter:"brightness(100%)"}},".cm-floating-reject":{backgroundColor:"light-dark(rgb(220, 53, 69), rgb(180, 40, 50))",color:"white",borderTopRightRadius:"5px",borderBottomRightRadius:"5px",filter:"brightness(90%)","&:hover":{filter:"brightness(100%)"}},".hotkey":{display:"inline-block",padding:"0 4px",borderRadius:"3px",backgroundColor:"rgba(255, 255, 255, 0.1)",fontSize:"90%"},".cm-ai-loading-indicator":{fontStyle:"italic",fontSize:"10px",paddingLeft:"12px",color:"light-dark(rgb(109, 117, 125), rgb(170, 170, 170))",opacity:"0",transition:"opacity 0.3s ease-in-out","&::after":{content:'""',display:"inline-block",animation:"ellipsis-pulse 1.5s steps(4, end) infinite"},"&:not(:empty)":{opacity:"1"}},".cm-ai-input:disabled":{opacity:"0.5"},"@keyframes ellipsis-pulse":{"0%":{content:"'.'"},"25%":{content:"'..'"},"50%":{content:"'...'"},"75%":{content:"''"}},".cm-ai-loading-container":{display:"flex",alignItems:"center",padding:"0 8px"},".cm-ai-cancel-button":{padding:"2px 8px",fontSize:"10px",borderRadius:"4px",color:"light-dark(rgb(109, 117, 125), rgb(170, 170, 170))",cursor:"pointer","&:hover":{background:"light-dark(rgb(223, 227, 232), rgb(50, 50, 50))"}},".hidden":{display:"none"}});function zi(e){var o,a;let t=e.state.facet(St),n={...q,...t.keymaps},r=de("div","cm-ai-tooltip").appendChild(de("div","cm-ai-tooltip-button"));return r.innerHTML=`<span>Edit <span class="hotkey">${jn(n.showInput)}</span></span>`,(o=r.querySelector("span"))==null||o.addEventListener("mousedown",i=>{i.stopPropagation(),i.button===0&&i.preventDefault()}),(a=r.querySelector("span"))==null||a.addEventListener("click",i=>{i.preventDefault(),$r(e)}),r}const Mn=Mt.define({combine(e){return An(e,{render:zi,hideOnBlur:!1})}}),Ki=ze.fromClass((Ia=class{constructor(e){p(this,"view");p(this,"suppress");p(this,"dom");p(this,"mousedown",()=>{this.suppress=!0});p(this,"mouseup",()=>{this.suppress=!1,this.display(this.view)});p(this,"scroll",()=>{this.display(this.view)});p(this,"windowScroll",()=>{this.display(this.view)});Oa(this,vn,e=>{var n;let t=e.state.selection.ranges.find(r=>!r.empty);if(t&&!this.suppress){let r=e.coordsAtPos(t.from);if(!r)return;let o=e.dom.getBoundingClientRect(),a=(n=e.dom.parentElement)==null?void 0:n.getBoundingClientRect(),i=r.top>=o.top&&r.top<=o.bottom&&r.left>=o.left&&r.left<=o.right,s=!a||r.top>=a.top&&r.top<=a.bottom&&r.left>=a.left&&r.left<=a.right;if(!i||!s){this.dom.style.display="none",this.dom.setAttribute("aria-hidden","true");return}this.dom.style.display="flex",this.dom.setAttribute("aria-hidden","false");let c=this.dom.getBoundingClientRect(),u=o.width-c.width,d=Math.min(r.left,u),f=r.top-c.height;f=a?Math.max(a.y,f):f,this.dom.style.left=`${d}px`,this.dom.style.top=`${f}px`,requestAnimationFrame(()=>{this.dom&&this.dom.setAttribute("aria-hidden","false")})}else this.dom.style.display="none",this.dom.setAttribute("aria-hidden","true")});this.view=e;let t=e.state.facet(Mn);this.suppress=!1,document.addEventListener("mousedown",this.mousedown),document.addEventListener("mouseup",this.mouseup),e.scrollDOM.addEventListener("scroll",this.scroll),window.addEventListener("scroll",this.windowScroll,!0);let n=t.render(e);e.dom.appendChild(n),this.dom=n}update(e){this.display(e.view)}docViewUpdate(e){this.display(e)}display(e){if(e.state.field(ot).show){this.dom.style.display="none";return}if(e.state.facet(Mn).hideOnBlur&&!e.hasFocus){this.dom.style.display="none",this.dom.setAttribute("aria-hidden","true");return}e.requestMeasure({read:La(this,vn)})}destroy(){document.removeEventListener("mousedown",this.mousedown),document.removeEventListener("mouseup",this.mouseup),this.view.scrollDOM.removeEventListener("scroll",this.scroll),window.removeEventListener("scroll",this.windowScroll,!0),this.dom.remove()}},vn=new WeakMap,Ia));var Yi=B.baseTheme({".cm-ai-tooltip-button":{userSelect:"none",fontFamily:"system-ui, -apple-system, sans-serif",position:"fixed",display:"flex",boxSizing:"border-box",padding:"2px 6px",borderRadius:"4px",fontSize:"12px",backgroundColor:"#0E639C",color:"#ffffff",border:"1px solid transparent",boxShadow:"0 2px 4px rgba(0,0,0,0.1)",zIndex:"999",transition:"opacity 0.5s","&[aria-hidden='true']":{opacity:"0"},"&[aria-hidden='false']":{opacity:"1"},"& > span":{pointerEvents:"auto",cursor:"pointer",display:"inline-block",padding:"2px"},"&:hover":{backgroundColor:"#1177bb"}}});function Xi(){return[Ki,Yi]}var Qi=class extends Fn{constructor(t){super();p(this,"oldCode");this.oldCode=t}toDOM(t){let n=de("div","cm-old-code-container");n.setAttribute("role","region"),n.setAttribute("aria-label","Previous code version");let r=de("div","cm-old-code cm-line");r.textContent=this.oldCode;let o=de("div","cm-floating-buttons"),a=t.state.facet(St),i={...q,...a.keymaps},s=de("button","cm-floating-button cm-floating-accept");s.innerHTML=`<span class="hotkey">${jn(i.acceptEdit)}</span> Accept`,s.setAttribute("aria-label","Accept changes"),s.addEventListener("click",u=>{u.preventDefault(),u.stopPropagation(),t.focus(),Hr(t)});let c=de("button","cm-floating-button cm-floating-reject");return c.innerHTML=`<span class="hotkey">${jn(i.rejectEdit)}</span> Reject`,c.setAttribute("aria-label","Reject changes"),c.addEventListener("click",u=>{u.preventDefault(),u.stopPropagation(),t.focus(),qr(t)}),o.append(s,c),n.append(r,o),n}updateDOM(t,n){return!0}},Zi=class extends Fn{constructor(t){super();p(this,"complete");p(this,"abortController",null);p(this,"dom",null);p(this,"input",null);p(this,"loadingContainer",null);p(this,"helpInfo",null);p(this,"inputContainer",null);p(this,"form",null);p(this,"view",null);p(this,"onKeyDown",async t=>{t.key==="Enter"&&!t.shiftKey?(t.preventDefault(),await this.handleSubmit()):t.key==="Escape"&&this.onCancel()});p(this,"onCancel",()=>{this.cleanup();let t=this.view;t&&(t.dispatch({effects:[rt.of({show:!1,lineFrom:0,lineTo:0}),ft.of(!1)]}),t.focus())});p(this,"handleSubmit",async t=>{var g;let n=this.view;if(!n)return;let r=n.state.facet(St);t==null||t.stopPropagation();let o=n.state.field(ot),{input:a}=this;if(!a)return;let i=a.value.trim();if(!o.show||!i)return;let s=n.state.doc.line(o.lineFrom),c=n.state.doc.line(o.lineTo),u=s.from,d=c.to,f=n.state.sliceDoc(u,d),h=n.state.sliceDoc(0,u),m=n.state.sliceDoc(d);this.abortController=new AbortController,n.dispatch({effects:ft.of(!0)}),this.toggleLoading(!0);try{let y=await this.complete({prompt:i,selection:f,codeBefore:h,codeAfter:m,editorView:n,signal:this.abortController.signal});if(!n.state.field(ot).show)return;if(!y||typeof y!="string")throw Error("Invalid completion result");n.dispatch({changes:{from:u,to:d,insert:y},effects:[rt.of({show:!1,lineFrom:0,lineTo:0}),$t.of({from:u,to:u+y.length,oldCode:f,newCode:y}),ft.of(!1)]})}catch(y){if(y instanceof DOMException&&y.name==="AbortError")return;(g=r.onError)==null||g.call(r,y)}finally{this.cleanup(),this.toggleLoading(!1),n.focus()}});this.complete=t}toDOM(t){if(this.dom)return this.dom;this.view=t;let n=t.state.field(Wr),r=t.state.field(Vr),o=de("div","cm-ai-input-container");this.inputContainer=o,this.dom=o;let a=de("form","cm-ai-input-form");this.form=a,a.setAttribute("role","search"),a.setAttribute("aria-label","AI editing instructions"),a.addEventListener("submit",w=>w.preventDefault());let i=de("input","cm-ai-input");this.input=i,a.append(i),i.placeholder="Editing instructions...",i.setAttribute("aria-label","AI editing instructions"),i.setAttribute("autocomplete","off"),i.setAttribute("spellcheck","true"),i.value=n.inputValue;let s=de("div","cm-ai-loading-container");this.loadingContainer=s;let c=de("div","cm-ai-loading-indicator");c.setAttribute("role","status"),c.setAttribute("aria-live","polite"),c.textContent="Generating";let u=de("button","cm-ai-cancel-button");u.textContent="Cancel",u.setAttribute("aria-label","Cancel code generation"),u.addEventListener("click",this.onCancel),s.append(u,c);let d=de("div","cm-ai-help-info");this.helpInfo=d;let f=d.appendChild(document.createElement("button"));f.className="cm-ai-help-info-button",f.textContent="Esc to close",f.addEventListener("click",this.onCancel);let h=de("button","cm-ai-generate-button");h.textContent="\u23CE Generate",h.setAttribute("aria-label","Generate code"),h.addEventListener("click",this.handleSubmit),this.toggleLoading(r),n.shouldFocus&&requestAnimationFrame(()=>{i.value=n.inputValue,i.focus(),t.dispatch({effects:At.of(!1)})}),m(i.value),i.addEventListener("input",y),i.addEventListener("keydown",this.onKeyDown);function m(w){d.replaceChildren(w?h:f)}let g="";function y(){t.dispatch({effects:xt.of(i.value)});let w=i.value.trim();w!==g&&(g=w,m(w))}return o}toggleLoading(t){var n;this.inputContainer&&this.form&&this.loadingContainer&&this.helpInfo&&((n=this.inputContainer)==null||n.replaceChildren(this.form,t?this.loadingContainer:this.helpInfo))}updateDOM(t,n){return this.dom=t,this.input=t.querySelector(".cm-ai-input"),!0}cleanup(){var t,n,r;(t=this.abortController)==null||t.abort(),this.abortController=null,(n=this.dom)==null||n.remove(),(r=this.input)==null||r.remove(),this.dom=null,this.input=null}destroy(){this.cleanup()}};function es(e){if(!e.prompt)throw Error("prompt function is required");let t={...q,...e.keymaps};return[St.of(e),ot,Wr,Tt,Vr,Xi(),qi,Je.of([{key:t.showInput,run:$r}]),ut.highest([Je.of([{key:t.acceptEdit,run:Hr},{key:t.rejectEdit,run:qr}])]),ts,ns,rs,os]}const ts=B.updateListener.of(e=>{let t=e.state.field(ot);if(!t.show||!e.docChanged)return;let{lineFrom:n,lineTo:r}=t,o=!1;e.changes.iterChanges((a,i,s,c)=>{let u=e.state.doc.lineAt(a).number;if(u<n){let d=e.state.doc.lineAt(c).number-e.state.doc.lineAt(s).number;n+=d,r+=d,o=!0}else if(u<=r){let d=e.state.doc.lineAt(c).number-e.state.doc.lineAt(s).number;r+=d,o=!0}}),o&&e.view.dispatch({effects:[rt.of({show:!0,lineFrom:n,lineTo:r})]})}),ns=B.decorations.of(e=>{let t=e.state.field(Tt);return t?H.set([H.mark({class:"cm-new-code-line"}).range(t.from,t.to)]):H.none}),rs=B.decorations.compute([ot],e=>{let t=e.field(ot),n=e.facet(St),r=[];if(t.show){let o=t.lineFrom,a=t.lineTo;for(let i=o;i<=a;i++){let s=e.doc.line(i).from;r.push(H.line({class:"cm-ai-selection"}).range(s)),i===o&&r.push(H.widget({widget:new Zi(n.prompt),side:-1}).range(s))}}return H.set(r)}),os=qe.define({create(e){return H.none},update(e,t){let n=t.state.field(Tt);return n?H.set([H.widget({widget:new Qi(n.oldCode),block:!0}).range(n.from)]):H.none},provide:e=>B.decorations.from(e)});var as=Re(),I=Da(id(),1),Rn=()=>({entries:new Map}),{valueAtom:Yr,useActions:Xr}=Or(Rn,{submit:(e,t)=>{let{cellIds:n,deleteCell:r,deleteManyCells:o,store:a}=t,i=a.get(nt),s=a.get(Fd),c=new Set(i.cellIds.inOrderIds.filter(f=>i.cellData[f].code.trim()==="")),u=new Map;for(let f of n){if(c.has(f)){u.set(f,{cellId:f,type:"simple"});continue}let h=i.cellRuntime[f],m=new Map;for(let y of Object.values(s)){let w=y.declaredBy.includes(f),k=y.usedBy.some(C=>!c.has(C));w&&k&&m.set(y.name,y.usedBy)}let g;h!=null&&h.runElapsedTimeMs&&h.runElapsedTimeMs>2e3&&(g=h.runElapsedTimeMs),m.size===0&&g===void 0?u.set(f,{cellId:f,type:"simple"}):u.set(f,{cellId:f,type:"expensive",executionDurationMs:g,defs:m})}let d=[...u.values()].every(f=>f.type==="simple");return u.size>0&&d?(u.size===1?r({cellId:[...u.values()][0].cellId}):o({cellIds:[...u.values()].map(f=>f.cellId)}),Rn()):{...e,entries:u}},clear:()=>Rn()});Un=function(){let e=wr(),{submit:t,clear:n}=Xr(),{entries:r}=oe(Yr),o=vi(),a=Ur();return(0,I.useMemo)(()=>({submit:i=>{t({cellIds:i,deleteCell:o,deleteManyCells:a,store:e})},clear:n,get idle(){return r.size===0},get shouldConfirmDelete(){return r.size>1}}),[e,t,n,r,o,a])},Ti=function(e){let t=(0,as.c)(16),n=oe(Yr),r=Xr(),o=Ur(),a;t[0]!==e||t[1]!==n.entries?(a=n.entries.get(e),t[0]=e,t[1]=n.entries,t[2]=a):a=t[2];let i=a;if(!i){let d;return t[3]===Symbol.for("react.memo_cache_sentinel")?(d={isPending:!1},t[3]=d):d=t[3],d}if(n.entries.size!==1){let d;return t[4]===i?d=t[5]:(d={isPending:!0,shouldConfirmDelete:!1,...i},t[4]=i,t[5]=d),d}let s;t[6]!==r||t[7]!==o||t[8]!==n.entries?(s=()=>{o({cellIds:[...n.entries.values()].map(is)}),r.clear()},t[6]=r,t[7]=o,t[8]=n.entries,t[9]=s):s=t[9];let c;t[10]===r?c=t[11]:(c=()=>r.clear(),t[10]=r,t[11]=c);let u;return t[12]!==i||t[13]!==s||t[14]!==c?(u={isPending:!0,...i,shouldConfirmDelete:!0,confirm:s,cancel:c},t[12]=i,t[13]=s,t[14]=c,t[15]=u):u=t[15],u};function is(e){return e.cellId}async function ss(e){var s,c;let t=`
4
4
  ${e.codeBefore}
5
5
  <rewrite_this>
6
6
  ${e.selection}
7
7
  </rewrite_this>
8
8
  ${e.codeAfter}
9
- `.trim(),n=ti();await ei();let r=await fetch(n.getAiURL("completion").toString(),{method:"POST",headers:n.headers(),body:JSON.stringify({prompt:e.prompt,code:t,selectedText:e.selection,includeOtherCode:"",language:e.language})}),o=((s=e.selection.match(/^\s*/))==null?void 0:s[0])||"",a=(c=r.body)==null?void 0:c.getReader();if(!a)throw Error("Failed to get response reader");let i="";for(;;){let{done:u,value:d}=await a.read();if(u)break;i+=new TextDecoder().decode(d)}return i.startsWith(o)||(i=o+i),i}var b=Ua(cf(),1),fs=["%alias","%cd","%clear","%debug","%env","%load","%load_ext","%lsmagic","%matplotlib","%pwd","%who_ls","%system","%%time","%%timeit","%%writefile","%%capture","%%html","%%latex"],Gn;function ms(){let e=async r=>{let o=Q.get(Tr),{saveUserConfig:a}=zf();await a({config:{runtime:{auto_reload:r}}}).then(()=>Q.set(Tr,{...o,runtime:{...o.runtime,auto_reload:r}}))},t=[{match:"!pip install",onMatch:()=>{Q.set(Sr,r=>({...r,isSidebarOpen:!0,selectedPanel:"packages"})),Dr()},title:"Package Installation",description:(0,b.jsxs)(b.Fragment,{children:["The package manager sidebar has been opened.",(0,b.jsx)("br",{}),"Install packages directly from there instead."]})},{match:"!uv pip install",onMatch:()=>{Q.set(Sr,r=>({...r,isSidebarOpen:!0,selectedPanel:"packages"})),Dr()},title:"Package Installation",description:(0,b.jsxs)(b.Fragment,{children:["The package manager sidebar has been opened.",(0,b.jsx)("br",{}),"Install packages directly from there instead."]})},{match:"!uv add",onMatch:()=>{Q.set(Sr,r=>({...r,isSidebarOpen:!0,selectedPanel:"packages"})),Dr()},title:"Package Installation",description:(0,b.jsxs)(b.Fragment,{children:["The package manager sidebar has been opened.",(0,b.jsx)("br",{}),"Install packages directly from there instead."]})},{match:"%autoreload 2",onMatch:async()=>{await e("autorun")},title:"Module reload",description:(0,b.jsxs)(b.Fragment,{children:["Module reload mode set to ",(0,b.jsx)("b",{children:"autorun"})," - module changes will re-run the cells that import them."]})},{match:"%autoreload 1",onMatch:async()=>{await e("lazy")},title:"Module reload",description:(0,b.jsxs)(b.Fragment,{children:["Module reload mode set to ",(0,b.jsx)("b",{children:"lazy"})," - module changes will mark the cells that import them as stale."]})},{match:"%autoreload 0",onMatch:async()=>{await e("off")},title:"Module reload",description:(0,b.jsx)(b.Fragment,{children:"Module reload disabled - module changes will not be detected."})},{match:"!ls",onMatch:()=>{},title:"Listing files",description:(0,b.jsxs)(b.Fragment,{children:["Shell commands are not directly supported.",(0,b.jsx)("br",{}),"Use ",(0,b.jsx)("code",{children:"import subprocess; subprocess.run(['ls'])"})," instead."]})},...fs.map(r=>({match:r,onMatch:()=>{},title:(0,b.jsx)(Tm,{className:"inline",children:r}),description:(0,b.jsxs)(b.Fragment,{children:["Magic commands are not supported in marimo. Read more about replacements in the"," ",(0,b.jsx)("a",{href:"https://docs.marimo.io/guides/coming_from/jupyter/#adapting-to-the-absence-of-magic-commands",target:"_blank",className:"text-link underline cursor-pointer",rel:"noopener noreferrer",children:"documentation"}),"."]})}))],n=new Map(t.map(r=>[r.match,r]));return B.updateListener.of(r=>{if(r.docChanged){let o=r.state.selection.main,a=r.state.doc,i=a.lineAt(o.head),s=a.sliceString(i.from,o.anchor).trim(),c=n.get(s);c&&(c.onMatch(),Gn?Gn.upsert({title:c.title,description:c.description}):Gn=Et({title:c.title,description:c.description}))}})}var ps=new Set(["Escape","Alt-`"]);function hs(){let e=Wf.filter(t=>!ps.has(t.key));return ut.highest(Je.of([...e,{key:"Ctrl-y",run:t=>Cn(t)?ii(t):!1},{key:"Ctrl-n",run:t=>Cn(t)?Ln(!0)(t):!1},{key:"Ctrl-p",run:t=>Cn(t)?Ln(!1)(t):!1}]))}const Jn=pe.define(),Wn=pe.define(),Vn=pe.define();function z(e,t){if(!e)throw Error(t)}var gs=3402823466385289e23,bs=-3402823466385289e23,ys=4294967295,ws=2147483647,vs=-2147483648;function zt(e){if(typeof e!="number")throw Error("invalid int 32: "+typeof e);if(!Number.isInteger(e)||e>ws||e<vs)throw Error("invalid int 32: "+e)}function $n(e){if(typeof e!="number")throw Error("invalid uint 32: "+typeof e);if(!Number.isInteger(e)||e>ys||e<0)throw Error("invalid uint 32: "+e)}function Zr(e){if(typeof e!="number")throw Error("invalid float 32: "+typeof e);if(Number.isFinite(e)&&(e>gs||e<bs))throw Error("invalid float 32: "+e)}var eo=Symbol("@bufbuild/protobuf/enum-type");function Es(e){let t=e[eo];return z(t,"missing enum type on enum object"),t}function to(e,t,n,r){e[eo]=no(t,n.map(o=>({no:o.no,name:o.name,localName:e[o.no]})),r)}function no(e,t,n){let r=Object.create(null),o=Object.create(null),a=[];for(let i of t){let s=ro(i);a.push(s),r[i.name]=s,o[i.no]=s}return{typeName:e,values:a,findName(i){return r[i]},findNumber(i){return o[i]}}}function Ns(e,t,n){let r={};for(let o of t){let a=ro(o);r[a.localName]=a.no,r[a.no]=a.localName}return to(r,e,t,n),r}function ro(e){return"localName"in e?e:Object.assign(Object.assign({},e),{localName:e.name})}var X=class{equals(e){return this.getType().runtime.util.equals(this.getType(),this,e)}clone(){return this.getType().runtime.util.clone(this)}fromBinary(e,t){let n=this.getType().runtime.bin,r=n.makeReadOptions(t);return n.readMessage(this,r.readerFactory(e),e.byteLength,r),this}fromJson(e,t){let n=this.getType(),r=n.runtime.json,o=r.makeReadOptions(t);return r.readMessage(n,e,o,this),this}fromJsonString(e,t){let n;try{n=JSON.parse(e)}catch(r){throw Error(`cannot decode ${this.getType().typeName} from JSON: ${r instanceof Error?r.message:String(r)}`)}return this.fromJson(n,t)}toBinary(e){let t=this.getType().runtime.bin,n=t.makeWriteOptions(e),r=n.writerFactory();return t.writeMessage(this,r,n),r.finish()}toJson(e){let t=this.getType().runtime.json,n=t.makeWriteOptions(e);return t.writeMessage(this,n)}toJsonString(e){let t=this.toJson(e);return JSON.stringify(t,null,(e==null?void 0:e.prettySpaces)??0)}toJSON(){return this.toJson({emitDefaultValues:!0})}getType(){return Object.getPrototypeOf(this).constructor}};function ks(e,t,n,r){let o=(r==null?void 0:r.localName)??t.substring(t.lastIndexOf(".")+1),a={[o]:function(i){e.util.initFields(this),e.util.initPartial(i,this)}}[o];return Object.setPrototypeOf(a.prototype,new X),Object.assign(a,{runtime:e,typeName:t,fields:e.util.newFieldList(n),fromBinary(i,s){return new a().fromBinary(i,s)},fromJson(i,s){return new a().fromJson(i,s)},fromJsonString(i,s){return new a().fromJsonString(i,s)},equals(i,s){return e.util.equals(a,i,s)}}),a}function Cs(){let e=0,t=0;for(let r=0;r<28;r+=7){let o=this.buf[this.pos++];if(e|=(o&127)<<r,!(o&128))return this.assertBounds(),[e,t]}let n=this.buf[this.pos++];if(e|=(n&15)<<28,t=(n&112)>>4,!(n&128))return this.assertBounds(),[e,t];for(let r=3;r<=31;r+=7){let o=this.buf[this.pos++];if(t|=(o&127)<<r,!(o&128))return this.assertBounds(),[e,t]}throw Error("invalid varint")}function Hn(e,t,n){for(let a=0;a<28;a+=7){let i=e>>>a,s=!(!(i>>>7)&&t==0),c=(s?i|128:i)&255;if(n.push(c),!s)return}let r=e>>>28&15|(t&7)<<4,o=!!(t>>3);if(n.push((o?r|128:r)&255),o){for(let a=3;a<31;a+=7){let i=t>>>a,s=!!(i>>>7),c=(s?i|128:i)&255;if(n.push(c),!s)return}n.push(t>>>31&1)}}var Kt=4294967296;function oo(e){let t=e[0]==="-";t&&(e=e.slice(1));let n=1e6,r=0,o=0;function a(i,s){let c=Number(e.slice(i,s));o*=n,r=r*n+c,r>=Kt&&(o+=r/Kt|0,r%=Kt)}return a(-24,-18),a(-18,-12),a(-12,-6),a(-6),t?io(r,o):qn(r,o)}function Ss(e,t){let n=qn(e,t),r=n.hi&2147483648;r&&(n=io(n.lo,n.hi));let o=ao(n.lo,n.hi);return r?"-"+o:o}function ao(e,t){if({lo:e,hi:t}=xs(e,t),t<=2097151)return String(Kt*t+e);let n=e&16777215,r=(e>>>24|t<<8)&16777215,o=t>>16&65535,a=n+r*6777216+o*6710656,i=r+o*8147497,s=o*2,c=1e7;return a>=c&&(i+=Math.floor(a/c),a%=c),i>=c&&(s+=Math.floor(i/c),i%=c),s.toString()+so(i)+so(a)}function xs(e,t){return{lo:e>>>0,hi:t>>>0}}function qn(e,t){return{lo:e|0,hi:t|0}}function io(e,t){return t=~t,e?e=~e+1:t+=1,qn(e,t)}var so=e=>{let t=String(e);return"0000000".slice(t.length)+t};function lo(e,t){if(e>=0){for(;e>127;)t.push(e&127|128),e>>>=7;t.push(e)}else{for(let n=0;n<9;n++)t.push(e&127|128),e>>=7;t.push(1)}}function As(){let e=this.buf[this.pos++],t=e&127;if(!(e&128)||(e=this.buf[this.pos++],t|=(e&127)<<7,!(e&128))||(e=this.buf[this.pos++],t|=(e&127)<<14,!(e&128))||(e=this.buf[this.pos++],t|=(e&127)<<21,!(e&128)))return this.assertBounds(),t;e=this.buf[this.pos++],t|=(e&15)<<28;for(let n=5;e&128&&n<10;n++)e=this.buf[this.pos++];if(e&128)throw Error("invalid varint");return this.assertBounds(),t>>>0}function Ts(){let e=new DataView(new ArrayBuffer(8));if(typeof BigInt=="function"&&typeof e.getBigInt64=="function"&&typeof e.getBigUint64=="function"&&typeof e.setBigInt64=="function"&&typeof e.setBigUint64=="function"&&(typeof process!="object"||{}.BUF_BIGINT_DISABLE!=="1")){let r=BigInt("-9223372036854775808"),o=BigInt("9223372036854775807"),a=BigInt("0"),i=BigInt("18446744073709551615");return{zero:BigInt(0),supported:!0,parse(s){let c=typeof s=="bigint"?s:BigInt(s);if(c>o||c<r)throw Error(`int64 invalid: ${s}`);return c},uParse(s){let c=typeof s=="bigint"?s:BigInt(s);if(c>i||c<a)throw Error(`uint64 invalid: ${s}`);return c},enc(s){return e.setBigInt64(0,this.parse(s),!0),{lo:e.getInt32(0,!0),hi:e.getInt32(4,!0)}},uEnc(s){return e.setBigInt64(0,this.uParse(s),!0),{lo:e.getInt32(0,!0),hi:e.getInt32(4,!0)}},dec(s,c){return e.setInt32(0,s,!0),e.setInt32(4,c,!0),e.getBigInt64(0,!0)},uDec(s,c){return e.setInt32(0,s,!0),e.setInt32(4,c,!0),e.getBigUint64(0,!0)}}}let t=r=>z(/^-?[0-9]+$/.test(r),`int64 invalid: ${r}`),n=r=>z(/^[0-9]+$/.test(r),`uint64 invalid: ${r}`);return{zero:"0",supported:!1,parse(r){return typeof r!="string"&&(r=r.toString()),t(r),r},uParse(r){return typeof r!="string"&&(r=r.toString()),n(r),r},enc(r){return typeof r!="string"&&(r=r.toString()),t(r),oo(r)},uEnc(r){return typeof r!="string"&&(r=r.toString()),n(r),oo(r)},dec(r,o){return Ss(r,o)},uDec(r,o){return ao(r,o)}}}const J=Ts();var v;(function(e){e[e.DOUBLE=1]="DOUBLE",e[e.FLOAT=2]="FLOAT",e[e.INT64=3]="INT64",e[e.UINT64=4]="UINT64",e[e.INT32=5]="INT32",e[e.FIXED64=6]="FIXED64",e[e.FIXED32=7]="FIXED32",e[e.BOOL=8]="BOOL",e[e.STRING=9]="STRING",e[e.BYTES=12]="BYTES",e[e.UINT32=13]="UINT32",e[e.SFIXED32=15]="SFIXED32",e[e.SFIXED64=16]="SFIXED64",e[e.SINT32=17]="SINT32",e[e.SINT64=18]="SINT64"})(v||(v={}));var at;(function(e){e[e.BIGINT=0]="BIGINT",e[e.STRING=1]="STRING"})(at||(at={}));function Ze(e,t,n){if(t===n)return!0;if(e==v.BYTES){if(!(t instanceof Uint8Array)||!(n instanceof Uint8Array)||t.length!==n.length)return!1;for(let r=0;r<t.length;r++)if(t[r]!==n[r])return!1;return!0}switch(e){case v.UINT64:case v.FIXED64:case v.INT64:case v.SFIXED64:case v.SINT64:return t==n}return!1}function mt(e,t){switch(e){case v.BOOL:return!1;case v.UINT64:case v.FIXED64:case v.INT64:case v.SFIXED64:case v.SINT64:return t==0?J.zero:"0";case v.DOUBLE:case v.FLOAT:return 0;case v.BYTES:return new Uint8Array;case v.STRING:return"";default:return 0}}function co(e,t){switch(e){case v.BOOL:return t===!1;case v.STRING:return t==="";case v.BYTES:return t instanceof Uint8Array&&!t.byteLength;default:return t==0}}var Z;(function(e){e[e.Varint=0]="Varint",e[e.Bit64=1]="Bit64",e[e.LengthDelimited=2]="LengthDelimited",e[e.StartGroup=3]="StartGroup",e[e.EndGroup=4]="EndGroup",e[e.Bit32=5]="Bit32"})(Z||(Z={}));var Is=class{constructor(e){this.stack=[],this.textEncoder=e??new TextEncoder,this.chunks=[],this.buf=[]}finish(){this.chunks.push(new Uint8Array(this.buf));let e=0;for(let r=0;r<this.chunks.length;r++)e+=this.chunks[r].length;let t=new Uint8Array(e),n=0;for(let r=0;r<this.chunks.length;r++)t.set(this.chunks[r],n),n+=this.chunks[r].length;return this.chunks=[],t}fork(){return this.stack.push({chunks:this.chunks,buf:this.buf}),this.chunks=[],this.buf=[],this}join(){let e=this.finish(),t=this.stack.pop();if(!t)throw Error("invalid state, fork stack empty");return this.chunks=t.chunks,this.buf=t.buf,this.uint32(e.byteLength),this.raw(e)}tag(e,t){return this.uint32((e<<3|t)>>>0)}raw(e){return this.buf.length&&(this.chunks.push(new Uint8Array(this.buf)),this.buf=[]),this.chunks.push(e),this}uint32(e){for($n(e);e>127;)this.buf.push(e&127|128),e>>>=7;return this.buf.push(e),this}int32(e){return zt(e),lo(e,this.buf),this}bool(e){return this.buf.push(e?1:0),this}bytes(e){return this.uint32(e.byteLength),this.raw(e)}string(e){let t=this.textEncoder.encode(e);return this.uint32(t.byteLength),this.raw(t)}float(e){Zr(e);let t=new Uint8Array(4);return new DataView(t.buffer).setFloat32(0,e,!0),this.raw(t)}double(e){let t=new Uint8Array(8);return new DataView(t.buffer).setFloat64(0,e,!0),this.raw(t)}fixed32(e){$n(e);let t=new Uint8Array(4);return new DataView(t.buffer).setUint32(0,e,!0),this.raw(t)}sfixed32(e){zt(e);let t=new Uint8Array(4);return new DataView(t.buffer).setInt32(0,e,!0),this.raw(t)}sint32(e){return zt(e),e=(e<<1^e>>31)>>>0,lo(e,this.buf),this}sfixed64(e){let t=new Uint8Array(8),n=new DataView(t.buffer),r=J.enc(e);return n.setInt32(0,r.lo,!0),n.setInt32(4,r.hi,!0),this.raw(t)}fixed64(e){let t=new Uint8Array(8),n=new DataView(t.buffer),r=J.uEnc(e);return n.setInt32(0,r.lo,!0),n.setInt32(4,r.hi,!0),this.raw(t)}int64(e){let t=J.enc(e);return Hn(t.lo,t.hi,this.buf),this}sint64(e){let t=J.enc(e),n=t.hi>>31;return Hn(t.lo<<1^n,(t.hi<<1|t.lo>>>31)^n,this.buf),this}uint64(e){let t=J.uEnc(e);return Hn(t.lo,t.hi,this.buf),this}},Fs=class{constructor(e,t){this.varint64=Cs,this.uint32=As,this.buf=e,this.len=e.length,this.pos=0,this.view=new DataView(e.buffer,e.byteOffset,e.byteLength),this.textDecoder=t??new TextDecoder}tag(){let e=this.uint32(),t=e>>>3,n=e&7;if(t<=0||n<0||n>5)throw Error("illegal tag: field no "+t+" wire type "+n);return[t,n]}skip(e,t){let n=this.pos;switch(e){case Z.Varint:for(;this.buf[this.pos++]&128;);break;case Z.Bit64:this.pos+=4;case Z.Bit32:this.pos+=4;break;case Z.LengthDelimited:let r=this.uint32();this.pos+=r;break;case Z.StartGroup:for(;;){let[o,a]=this.tag();if(a===Z.EndGroup){if(t!==void 0&&o!==t)throw Error("invalid end group tag");break}this.skip(a,o)}break;default:throw Error("cant skip wire type "+e)}return this.assertBounds(),this.buf.subarray(n,this.pos)}assertBounds(){if(this.pos>this.len)throw RangeError("premature EOF")}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)}int64(){return J.dec(...this.varint64())}uint64(){return J.uDec(...this.varint64())}sint64(){let[e,t]=this.varint64(),n=-(e&1);return e=(e>>>1|(t&1)<<31)^n,t=t>>>1^n,J.dec(e,t)}bool(){let[e,t]=this.varint64();return e!==0||t!==0}fixed32(){return this.view.getUint32((this.pos+=4)-4,!0)}sfixed32(){return this.view.getInt32((this.pos+=4)-4,!0)}fixed64(){return J.uDec(this.sfixed32(),this.sfixed32())}sfixed64(){return J.dec(this.sfixed32(),this.sfixed32())}float(){return this.view.getFloat32((this.pos+=4)-4,!0)}double(){return this.view.getFloat64((this.pos+=8)-8,!0)}bytes(){let e=this.uint32(),t=this.pos;return this.pos+=e,this.assertBounds(),this.buf.subarray(t,t+e)}string(){return this.textDecoder.decode(this.bytes())}};function Ls(e,t,n,r){let o;return{typeName:t,extendee:n,get field(){if(!o){let a=typeof r=="function"?r():r;a.name=t.split(".").pop(),a.jsonName=`[${t}]`,o=e.util.newFieldList([a]).list()[0]}return o},runtime:e}}function uo(e){let t=e.field.localName,n=Object.create(null);return n[t]=Os(e),[n,()=>n[t]]}function Os(e){let t=e.field;if(t.repeated)return[];if(t.default!==void 0)return t.default;switch(t.kind){case"enum":return t.T.values[0].no;case"scalar":return mt(t.T,t.L);case"message":let n=t.T,r=new n;return n.fieldWrapper?n.fieldWrapper.unwrapField(r):r;case"map":throw"map fields are not allowed to be extensions"}}function Ds(e,t){if(!t.repeated&&(t.kind=="enum"||t.kind=="scalar")){for(let n=e.length-1;n>=0;--n)if(e[n].no==t.no)return[e[n]];return[]}return e.filter(n=>n.no===t.no)}var Ke="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split(""),Yt=[];for(let e=0;e<Ke.length;e++)Yt[Ke[e].charCodeAt(0)]=e;Yt[45]=Ke.indexOf("+"),Yt[95]=Ke.indexOf("/");const Xt={dec(e){let t=e.length*3/4;e[e.length-2]=="="?t-=2:e[e.length-1]=="="&&--t;let n=new Uint8Array(t),r=0,o=0,a,i=0;for(let s=0;s<e.length;s++){if(a=Yt[e.charCodeAt(s)],a===void 0)switch(e[s]){case"=":o=0;case`
10
- `:case"\r":case" ":case" ":continue;default:throw Error("invalid base64 string.")}switch(o){case 0:i=a,o=1;break;case 1:n[r++]=i<<2|(a&48)>>4,i=a,o=2;break;case 2:n[r++]=(i&15)<<4|(a&60)>>2,i=a,o=3;break;case 3:n[r++]=(i&3)<<6|a,o=0;break}}if(o==1)throw Error("invalid base64 string.");return n.subarray(0,r)},enc(e){let t="",n=0,r,o=0;for(let a=0;a<e.length;a++)switch(r=e[a],n){case 0:t+=Ke[r>>2],o=(r&3)<<4,n=1;break;case 1:t+=Ke[o|r>>4],o=(r&15)<<2,n=2;break;case 2:t+=Ke[o|r>>6],t+=Ke[r&63],n=0;break}return n&&(t+=Ke[o],t+="=",n==1&&(t+="=")),t}};function _s(e,t,n){mo(t,e);let r=t.runtime.bin.makeReadOptions(n),o=Ds(e.getType().runtime.bin.listUnknownFields(e),t.field),[a,i]=uo(t);for(let s of o)t.runtime.bin.readField(a,r.readerFactory(s.data),t.field,s.wireType,r);return i()}function Us(e,t,n,r){mo(t,e);let o=t.runtime.bin.makeReadOptions(r),a=t.runtime.bin.makeWriteOptions(r);if(fo(e,t)){let u=e.getType().runtime.bin.listUnknownFields(e).filter(d=>d.no!=t.field.no);e.getType().runtime.bin.discardUnknownFields(e);for(let d of u)e.getType().runtime.bin.onUnknownField(e,d.no,d.wireType,d.data)}let i=a.writerFactory(),s=t.field;!s.opt&&!s.repeated&&(s.kind=="enum"||s.kind=="scalar")&&(s=Object.assign(Object.assign({},t.field),{opt:!0})),t.runtime.bin.writeField(s,n,i,a);let c=o.readerFactory(i.finish());for(;c.pos<c.len;){let[u,d]=c.tag(),f=c.skip(d,u);e.getType().runtime.bin.onUnknownField(e,u,d,f)}}function fo(e,t){let n=e.getType();return t.extendee.typeName===n.typeName&&!!n.runtime.bin.listUnknownFields(e).find(r=>r.no==t.field.no)}function mo(e,t){z(e.extendee.typeName==t.getType().typeName,`extension ${e.typeName} can only be applied to message ${e.extendee.typeName}`)}function po(e,t){let n=e.localName;if(e.repeated)return t[n].length>0;if(e.oneof)return t[e.oneof.localName].case===n;switch(e.kind){case"enum":case"scalar":return e.opt||e.req?t[n]!==void 0:e.kind=="enum"?t[n]!==e.T.values[0].no:!co(e.T,t[n]);case"message":return t[n]!==void 0;case"map":return Object.keys(t[n]).length>0}}function ho(e,t){let n=e.localName,r=!e.opt&&!e.req;if(e.repeated)t[n]=[];else if(e.oneof)t[e.oneof.localName]={case:void 0};else switch(e.kind){case"map":t[n]={};break;case"enum":t[n]=r?e.T.values[0].no:void 0;break;case"scalar":t[n]=r?mt(e.T,e.L):void 0;break;case"message":t[n]=void 0;break}}function Ye(e,t){if(typeof e!="object"||!e||!Object.getOwnPropertyNames(X.prototype).every(r=>r in e&&typeof e[r]=="function"))return!1;let n=e.getType();return n===null||typeof n!="function"||!("typeName"in n)||typeof n.typeName!="string"?!1:t===void 0?!0:n.typeName==t.typeName}function go(e,t){return Ye(t)||!e.fieldWrapper?t:e.fieldWrapper.wrapField(t)}v.DOUBLE,v.FLOAT,v.INT64,v.UINT64,v.INT32,v.UINT32,v.BOOL,v.STRING,v.BYTES;var bo={ignoreUnknownFields:!1},yo={emitDefaultValues:!1,enumAsInteger:!1,useProtoFieldName:!1,prettySpaces:0};function Bs(e){return e?Object.assign(Object.assign({},bo),e):bo}function js(e){return e?Object.assign(Object.assign({},yo),e):yo}var Qt=Symbol(),Zt=Symbol();function Ps(){return{makeReadOptions:Bs,makeWriteOptions:js,readMessage(e,t,n,r){if(t==null||Array.isArray(t)||typeof t!="object")throw Error(`cannot decode message ${e.typeName} from JSON: ${We(t)}`);r??(r=new e);let o=new Map,a=n.typeRegistry;for(let[i,s]of Object.entries(t)){let c=e.fields.findJsonName(i);if(c){if(c.oneof){if(s===null&&c.kind=="scalar")continue;let u=o.get(c.oneof);if(u!==void 0)throw Error(`cannot decode message ${e.typeName} from JSON: multiple keys for oneof "${c.oneof.name}" present: "${u}", "${i}"`);o.set(c.oneof,i)}wo(r,s,c,n,e)}else{let u=!1;if(a!=null&&a.findExtension&&i.startsWith("[")&&i.endsWith("]")){let d=a.findExtension(i.substring(1,i.length-1));if(d&&d.extendee.typeName==e.typeName){u=!0;let[f,h]=uo(d);wo(f,s,d.field,n,d),Us(r,d,h(),n)}}if(!u&&!n.ignoreUnknownFields)throw Error(`cannot decode message ${e.typeName} from JSON: key "${i}" is unknown`)}}return r},writeMessage(e,t){let n=e.getType(),r={},o;try{for(o of n.fields.byNumber()){if(!po(o,e)){if(o.req)throw"required field not set";if(!t.emitDefaultValues||!Rs(o))continue}let i=o.oneof?e[o.oneof.localName].value:e[o.localName],s=vo(o,i,t);s!==void 0&&(r[t.useProtoFieldName?o.name:o.jsonName]=s)}let a=t.typeRegistry;if(a!=null&&a.findExtensionFor)for(let i of n.runtime.bin.listUnknownFields(e)){let s=a.findExtensionFor(n.typeName,i.no);if(s&&fo(e,s)){let c=_s(e,s,t),u=vo(s.field,c,t);u!==void 0&&(r[s.field.jsonName]=u)}}}catch(a){let i=o?`cannot encode field ${n.typeName}.${o.name} to JSON`:`cannot encode message ${n.typeName} to JSON`,s=a instanceof Error?a.message:String(a);throw Error(i+(s.length>0?`: ${s}`:""))}return r},readScalar(e,t,n){return Ft(e,t,n??at.BIGINT,!0)},writeScalar(e,t,n){if(t!==void 0&&(n||co(e,t)))return en(e,t)},debug:We}}function We(e){if(e===null)return"null";switch(typeof e){case"object":return Array.isArray(e)?"array":"object";case"string":return e.length>100?"string":`"${e.split('"').join('\\"')}"`;default:return String(e)}}function wo(e,t,n,r,o){let a=n.localName;if(n.repeated){if(z(n.kind!="map"),t===null)return;if(!Array.isArray(t))throw Error(`cannot decode field ${o.typeName}.${n.name} from JSON: ${We(t)}`);let i=e[a];for(let s of t){if(s===null)throw Error(`cannot decode field ${o.typeName}.${n.name} from JSON: ${We(s)}`);switch(n.kind){case"message":i.push(n.T.fromJson(s,r));break;case"enum":let c=zn(n.T,s,r.ignoreUnknownFields,!0);c!==Zt&&i.push(c);break;case"scalar":try{i.push(Ft(n.T,s,n.L,!0))}catch(u){let d=`cannot decode field ${o.typeName}.${n.name} from JSON: ${We(s)}`;throw u instanceof Error&&u.message.length>0&&(d+=`: ${u.message}`),Error(d)}break}}}else if(n.kind=="map"){if(t===null)return;if(typeof t!="object"||Array.isArray(t))throw Error(`cannot decode field ${o.typeName}.${n.name} from JSON: ${We(t)}`);let i=e[a];for(let[s,c]of Object.entries(t)){if(c===null)throw Error(`cannot decode field ${o.typeName}.${n.name} from JSON: map value null`);let u;try{u=Ms(n.K,s)}catch(d){let f=`cannot decode map key for field ${o.typeName}.${n.name} from JSON: ${We(t)}`;throw d instanceof Error&&d.message.length>0&&(f+=`: ${d.message}`),Error(f)}switch(n.V.kind){case"message":i[u]=n.V.T.fromJson(c,r);break;case"enum":let d=zn(n.V.T,c,r.ignoreUnknownFields,!0);d!==Zt&&(i[u]=d);break;case"scalar":try{i[u]=Ft(n.V.T,c,at.BIGINT,!0)}catch(f){let h=`cannot decode map value for field ${o.typeName}.${n.name} from JSON: ${We(t)}`;throw f instanceof Error&&f.message.length>0&&(h+=`: ${f.message}`),Error(h)}break}}}else switch(n.oneof&&(e=e[n.oneof.localName]={case:a},a="value"),n.kind){case"message":let i=n.T;if(t===null&&i.typeName!="google.protobuf.Value")return;let s=e[a];Ye(s)?s.fromJson(t,r):(e[a]=s=i.fromJson(t,r),i.fieldWrapper&&!n.oneof&&(e[a]=i.fieldWrapper.unwrapField(s)));break;case"enum":let c=zn(n.T,t,r.ignoreUnknownFields,!1);switch(c){case Qt:ho(n,e);break;case Zt:break;default:e[a]=c;break}break;case"scalar":try{let u=Ft(n.T,t,n.L,!1);u===Qt?ho(n,e):e[a]=u}catch(u){let d=`cannot decode field ${o.typeName}.${n.name} from JSON: ${We(t)}`;throw u instanceof Error&&u.message.length>0&&(d+=`: ${u.message}`),Error(d)}break}}function Ms(e,t){if(e===v.BOOL)switch(t){case"true":t=!0;break;case"false":t=!1;break}return Ft(e,t,at.BIGINT,!0).toString()}function Ft(e,t,n,r){if(t===null)return r?mt(e,n):Qt;switch(e){case v.DOUBLE:case v.FLOAT:if(t==="NaN")return NaN;if(t==="Infinity")return 1/0;if(t==="-Infinity")return-1/0;if(t===""||typeof t=="string"&&t.trim().length!==t.length||typeof t!="string"&&typeof t!="number")break;let o=Number(t);if(Number.isNaN(o)||!Number.isFinite(o))break;return e==v.FLOAT&&Zr(o),o;case v.INT32:case v.FIXED32:case v.SFIXED32:case v.SINT32:case v.UINT32:let a;if(typeof t=="number"?a=t:typeof t=="string"&&t.length>0&&t.trim().length===t.length&&(a=Number(t)),a===void 0)break;return e==v.UINT32||e==v.FIXED32?$n(a):zt(a),a;case v.INT64:case v.SFIXED64:case v.SINT64:if(typeof t!="number"&&typeof t!="string")break;let i=J.parse(t);return n?i.toString():i;case v.FIXED64:case v.UINT64:if(typeof t!="number"&&typeof t!="string")break;let s=J.uParse(t);return n?s.toString():s;case v.BOOL:if(typeof t!="boolean")break;return t;case v.STRING:if(typeof t!="string")break;return t;case v.BYTES:if(t==="")return new Uint8Array;if(typeof t!="string")break;return Xt.dec(t)}throw Error()}function zn(e,t,n,r){if(t===null)return e.typeName=="google.protobuf.NullValue"?0:r?e.values[0].no:Qt;switch(typeof t){case"number":if(Number.isInteger(t))return t;break;case"string":let o=e.findName(t);if(o!==void 0)return o.no;if(n)return Zt;break}throw Error(`cannot decode enum ${e.typeName} from JSON: ${We(t)}`)}function Rs(e){return e.repeated||e.kind=="map"?!0:!(e.oneof||e.kind=="message"||e.opt||e.req)}function vo(e,t,n){if(e.kind=="map"){z(typeof t=="object"&&!!t);let r={},o=Object.entries(t);switch(e.V.kind){case"scalar":for(let[i,s]of o)r[i.toString()]=en(e.V.T,s);break;case"message":for(let[i,s]of o)r[i.toString()]=s.toJson(n);break;case"enum":let a=e.V.T;for(let[i,s]of o)r[i.toString()]=Kn(a,s,n.enumAsInteger);break}return n.emitDefaultValues||o.length>0?r:void 0}if(e.repeated){z(Array.isArray(t));let r=[];switch(e.kind){case"scalar":for(let o=0;o<t.length;o++)r.push(en(e.T,t[o]));break;case"enum":for(let o=0;o<t.length;o++)r.push(Kn(e.T,t[o],n.enumAsInteger));break;case"message":for(let o=0;o<t.length;o++)r.push(t[o].toJson(n));break}return n.emitDefaultValues||r.length>0?r:void 0}switch(e.kind){case"scalar":return en(e.T,t);case"enum":return Kn(e.T,t,n.enumAsInteger);case"message":return go(e.T,t).toJson(n)}}function Kn(e,t,n){var r;return z(typeof t=="number"),e.typeName=="google.protobuf.NullValue"?null:n?t:((r=e.findNumber(t))==null?void 0:r.name)??t}function en(e,t){switch(e){case v.INT32:case v.SFIXED32:case v.SINT32:case v.FIXED32:case v.UINT32:return z(typeof t=="number"),t;case v.FLOAT:case v.DOUBLE:return z(typeof t=="number"),Number.isNaN(t)?"NaN":t===1/0?"Infinity":t===-1/0?"-Infinity":t;case v.STRING:return z(typeof t=="string"),t;case v.BOOL:return z(typeof t=="boolean"),t;case v.UINT64:case v.FIXED64:case v.INT64:case v.SFIXED64:case v.SINT64:return z(typeof t=="bigint"||typeof t=="string"||typeof t=="number"),t.toString();case v.BYTES:return z(t instanceof Uint8Array),Xt.enc(t)}}var pt=Symbol("@bufbuild/protobuf/unknown-fields"),Eo={readUnknownFields:!0,readerFactory:e=>new Fs(e)},No={writeUnknownFields:!0,writerFactory:()=>new Is};function Gs(e){return e?Object.assign(Object.assign({},Eo),e):Eo}function Js(e){return e?Object.assign(Object.assign({},No),e):No}function Ws(){return{makeReadOptions:Gs,makeWriteOptions:Js,listUnknownFields(e){return e[pt]??[]},discardUnknownFields(e){delete e[pt]},writeUnknownFields(e,t){let n=e[pt];if(n)for(let r of n)t.tag(r.no,r.wireType).raw(r.data)},onUnknownField(e,t,n,r){let o=e;Array.isArray(o[pt])||(o[pt]=[]),o[pt].push({no:t,wireType:n,data:r})},readMessage(e,t,n,r,o){let a=e.getType(),i=o?t.len:t.pos+n,s,c;for(;t.pos<i&&([s,c]=t.tag(),!(o===!0&&c==Z.EndGroup));){let u=a.fields.find(s);if(!u){let d=t.skip(c,s);r.readUnknownFields&&this.onUnknownField(e,s,c,d);continue}ko(e,t,u,c,r)}if(o&&(c!=Z.EndGroup||s!==n))throw Error("invalid end group tag")},readField:ko,writeMessage(e,t,n){let r=e.getType();for(let o of r.fields.byNumber()){if(!po(o,e)){if(o.req)throw Error(`cannot encode field ${r.typeName}.${o.name} to binary: required field not set`);continue}Co(o,o.oneof?e[o.oneof.localName].value:e[o.localName],t,n)}return n.writeUnknownFields&&this.writeUnknownFields(e,t),t},writeField(e,t,n,r){t!==void 0&&Co(e,t,n,r)}}}function ko(e,t,n,r,o){let{repeated:a,localName:i}=n;switch(n.oneof&&(e=e[n.oneof.localName],e.case!=i&&delete e.value,e.case=i,i="value"),n.kind){case"scalar":case"enum":let s=n.kind=="enum"?v.INT32:n.T,c=nn;if(n.kind=="scalar"&&n.L>0&&(c=$s),a){let h=e[i];if(r==Z.LengthDelimited&&s!=v.STRING&&s!=v.BYTES){let m=t.uint32()+t.pos;for(;t.pos<m;)h.push(c(t,s))}else h.push(c(t,s))}else e[i]=c(t,s);break;case"message":let u=n.T;a?e[i].push(tn(t,new u,o,n)):Ye(e[i])?tn(t,e[i],o,n):(e[i]=tn(t,new u,o,n),u.fieldWrapper&&!n.oneof&&!n.repeated&&(e[i]=u.fieldWrapper.unwrapField(e[i])));break;case"map":let[d,f]=Vs(n,t,o);e[i][d]=f;break}}function tn(e,t,n,r){let o=t.getType().runtime.bin,a=r==null?void 0:r.delimited;return o.readMessage(t,e,a?r.no:e.uint32(),n,a),t}function Vs(e,t,n){let r=t.uint32(),o=t.pos+r,a,i;for(;t.pos<o;){let[s]=t.tag();switch(s){case 1:a=nn(t,e.K);break;case 2:switch(e.V.kind){case"scalar":i=nn(t,e.V.T);break;case"enum":i=t.int32();break;case"message":i=tn(t,new e.V.T,n,void 0);break}break}}if(a===void 0&&(a=mt(e.K,at.BIGINT)),typeof a!="string"&&typeof a!="number"&&(a=a.toString()),i===void 0)switch(e.V.kind){case"scalar":i=mt(e.V.T,at.BIGINT);break;case"enum":i=e.V.T.values[0].no;break;case"message":i=new e.V.T;break}return[a,i]}function $s(e,t){let n=nn(e,t);return typeof n=="bigint"?n.toString():n}function nn(e,t){switch(t){case v.STRING:return e.string();case v.BOOL:return e.bool();case v.DOUBLE:return e.double();case v.FLOAT:return e.float();case v.INT32:return e.int32();case v.INT64:return e.int64();case v.UINT64:return e.uint64();case v.FIXED64:return e.fixed64();case v.BYTES:return e.bytes();case v.FIXED32:return e.fixed32();case v.SFIXED32:return e.sfixed32();case v.SFIXED64:return e.sfixed64();case v.SINT64:return e.sint64();case v.UINT32:return e.uint32();case v.SINT32:return e.sint32()}}function Co(e,t,n,r){z(t!==void 0);let o=e.repeated;switch(e.kind){case"scalar":case"enum":let a=e.kind=="enum"?v.INT32:e.T;if(o)if(z(Array.isArray(t)),e.packed)qs(n,a,e.no,t);else for(let i of t)Lt(n,a,e.no,i);else Lt(n,a,e.no,t);break;case"message":if(o){z(Array.isArray(t));for(let i of t)So(n,r,e,i)}else So(n,r,e,t);break;case"map":z(typeof t=="object"&&!!t);for(let[i,s]of Object.entries(t))Hs(n,r,e,i,s);break}}function Hs(e,t,n,r,o){e.tag(n.no,Z.LengthDelimited),e.fork();let a=r;switch(n.K){case v.INT32:case v.FIXED32:case v.UINT32:case v.SFIXED32:case v.SINT32:a=Number.parseInt(r);break;case v.BOOL:z(r=="true"||r=="false"),a=r=="true";break}switch(Lt(e,n.K,1,a),n.V.kind){case"scalar":Lt(e,n.V.T,2,o);break;case"enum":Lt(e,v.INT32,2,o);break;case"message":z(o!==void 0),e.tag(2,Z.LengthDelimited).bytes(o.toBinary(t));break}e.join()}function So(e,t,n,r){let o=go(n.T,r);n.delimited?e.tag(n.no,Z.StartGroup).raw(o.toBinary(t)).tag(n.no,Z.EndGroup):e.tag(n.no,Z.LengthDelimited).bytes(o.toBinary(t))}function Lt(e,t,n,r){z(r!==void 0);let[o,a]=xo(t);e.tag(n,o)[a](r)}function qs(e,t,n,r){if(!r.length)return;e.tag(n,Z.LengthDelimited).fork();let[,o]=xo(t);for(let a=0;a<r.length;a++)e[o](r[a]);e.join()}function xo(e){let t=Z.Varint;switch(e){case v.BYTES:case v.STRING:t=Z.LengthDelimited;break;case v.DOUBLE:case v.FIXED64:case v.SFIXED64:t=Z.Bit64;break;case v.FIXED32:case v.SFIXED32:case v.FLOAT:t=Z.Bit32;break}let n=v[e].toLowerCase();return[t,n]}function zs(){return{setEnumType:to,initPartial(e,t){if(e===void 0)return;let n=t.getType();for(let r of n.fields.byMember()){let o=r.localName,a=t,i=e;if(i[o]!=null)switch(r.kind){case"oneof":let s=i[o].case;if(s===void 0)continue;let c=r.findField(s),u=i[o].value;c&&c.kind=="message"&&!Ye(u,c.T)?u=new c.T(u):c&&c.kind==="scalar"&&c.T===v.BYTES&&(u=Ot(u)),a[o]={case:s,value:u};break;case"scalar":case"enum":let d=i[o];r.T===v.BYTES&&(d=r.repeated?d.map(Ot):Ot(d)),a[o]=d;break;case"map":switch(r.V.kind){case"scalar":case"enum":if(r.V.T===v.BYTES)for(let[m,g]of Object.entries(i[o]))a[o][m]=Ot(g);else Object.assign(a[o],i[o]);break;case"message":let h=r.V.T;for(let m of Object.keys(i[o])){let g=i[o][m];h.fieldWrapper||(g=new h(g)),a[o][m]=g}break}break;case"message":let f=r.T;if(r.repeated)a[o]=i[o].map(h=>Ye(h,f)?h:new f(h));else{let h=i[o];f.fieldWrapper?f.typeName==="google.protobuf.BytesValue"?a[o]=Ot(h):a[o]=h:a[o]=Ye(h,f)?h:new f(h)}break}}},equals(e,t,n){return t===n?!0:!t||!n?!1:e.fields.byMember().every(r=>{let o=t[r.localName],a=n[r.localName];if(r.repeated){if(o.length!==a.length)return!1;switch(r.kind){case"message":return o.every((i,s)=>r.T.equals(i,a[s]));case"scalar":return o.every((i,s)=>Ze(r.T,i,a[s]));case"enum":return o.every((i,s)=>Ze(v.INT32,i,a[s]))}throw Error(`repeated cannot contain ${r.kind}`)}switch(r.kind){case"message":let i=o,s=a;return r.T.fieldWrapper&&(i!==void 0&&!Ye(i)&&(i=r.T.fieldWrapper.wrapField(i)),s!==void 0&&!Ye(s)&&(s=r.T.fieldWrapper.wrapField(s))),r.T.equals(i,s);case"enum":return Ze(v.INT32,o,a);case"scalar":return Ze(r.T,o,a);case"oneof":if(o.case!==a.case)return!1;let c=r.findField(o.case);if(c===void 0)return!0;switch(c.kind){case"message":return c.T.equals(o.value,a.value);case"enum":return Ze(v.INT32,o.value,a.value);case"scalar":return Ze(c.T,o.value,a.value)}throw Error(`oneof cannot contain ${c.kind}`);case"map":let u=Object.keys(o).concat(Object.keys(a));switch(r.V.kind){case"message":let d=r.V.T;return u.every(h=>d.equals(o[h],a[h]));case"enum":return u.every(h=>Ze(v.INT32,o[h],a[h]));case"scalar":let f=r.V.T;return u.every(h=>Ze(f,o[h],a[h]))}break}})},clone(e){let t=e.getType(),n=new t,r=n;for(let o of t.fields.byMember()){let a=e[o.localName],i;if(o.repeated)i=a.map(rn);else if(o.kind=="map"){i=r[o.localName];for(let[s,c]of Object.entries(a))i[s]=rn(c)}else i=o.kind=="oneof"?o.findField(a.case)?{case:a.case,value:rn(a.value)}:{case:void 0}:rn(a);r[o.localName]=i}for(let o of t.runtime.bin.listUnknownFields(e))t.runtime.bin.onUnknownField(r,o.no,o.wireType,o.data);return n}}}function rn(e){if(e===void 0)return e;if(Ye(e))return e.clone();if(e instanceof Uint8Array){let t=new Uint8Array(e.byteLength);return t.set(e),t}return e}function Ot(e){return e instanceof Uint8Array?e:new Uint8Array(e)}function Ks(e,t,n){return{syntax:e,json:Ps(),bin:Ws(),util:Object.assign(Object.assign({},zs()),{newFieldList:t,initFields:n}),makeMessageType(r,o,a){return ks(this,r,o,a)},makeEnum:Ns,makeEnumType:no,getEnumType:Es,makeExtension(r,o,a){return Ls(this,r,o,a)}}}var Ys=class{constructor(e,t){this._fields=e,this._normalizer=t}findJsonName(e){if(!this.jsonNames){let t={};for(let n of this.list())t[n.jsonName]=t[n.name]=n;this.jsonNames=t}return this.jsonNames[e]}find(e){if(!this.numbers){let t={};for(let n of this.list())t[n.no]=n;this.numbers=t}return this.numbers[e]}list(){return this.all||(this.all=this._normalizer(this._fields)),this.all}byNumber(){return this.numbersAsc||(this.numbersAsc=this.list().concat().sort((e,t)=>e.no-t.no)),this.numbersAsc}byMember(){if(!this.members){this.members=[];let e=this.members,t;for(let n of this.list())n.oneof?n.oneof!==t&&(t=n.oneof,e.push(t)):e.push(n)}return this.members}};function Ao(e,t){let n=To(e);return t?n:nl(tl(n))}function Xs(e){return Ao(e,!1)}const Qs=To;function To(e){let t=!1,n=[];for(let r=0;r<e.length;r++){let o=e.charAt(r);switch(o){case"_":t=!0;break;case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":n.push(o),t=!1;break;default:t&&(t=!1,o=o.toUpperCase()),n.push(o);break}}return n.join("")}var Zs=new Set(["constructor","toString","toJSON","valueOf"]),el=new Set(["getType","clone","equals","fromBinary","fromJson","fromJsonString","toBinary","toJson","toJsonString","toObject"]),Io=e=>`${e}$`,tl=e=>el.has(e)?Io(e):e;const nl=e=>Zs.has(e)?Io(e):e;var rl=class{constructor(e){this.kind="oneof",this.repeated=!1,this.packed=!1,this.opt=!1,this.req=!1,this.default=void 0,this.fields=[],this.name=e,this.localName=Xs(e)}addField(e){z(e.oneof===this,`field ${e.name} not one of ${this.name}`),this.fields.push(e)}findField(e){if(!this._lookup){this._lookup=Object.create(null);for(let t=0;t<this.fields.length;t++)this._lookup[this.fields[t].localName]=this.fields[t]}return this._lookup[e]}};function ol(e,t){let n=[],r;for(let o of typeof e=="function"?e():e){let a=o;if(a.localName=Ao(o.name,o.oneof!==void 0),a.jsonName=o.jsonName??Qs(o.name),a.repeated=o.repeated??!1,o.kind=="scalar"&&(a.L=o.L??at.BIGINT),a.delimited=o.delimited??!1,a.req=o.req??!1,a.opt=o.opt??!1,o.packed===void 0&&(t?a.packed=o.kind=="enum"||o.kind=="scalar"&&o.T!=v.BYTES&&o.T!=v.STRING:a.packed=!1),o.oneof!==void 0){let i=typeof o.oneof=="string"?o.oneof:o.oneof.name;(!r||r.name!=i)&&(r=new rl(i)),a.oneof=r,r.addField(a)}n.push(a)}return n}const N=Ks("proto3",e=>new Ys(e,t=>ol(t,!0)),e=>{for(let t of e.getType().fields.byMember()){if(t.opt)continue;let n=t.localName,r=e;if(t.repeated){r[n]=[];continue}switch(t.kind){case"oneof":r[n]={case:void 0};break;case"enum":r[n]=0;break;case"map":r[n]={};break;case"scalar":r[n]=mt(t.T,t.L);break;case"message":break}}});var ye;(function(e){e[e.Unary=0]="Unary",e[e.ServerStreaming=1]="ServerStreaming",e[e.ClientStreaming=2]="ClientStreaming",e[e.BiDiStreaming=3]="BiDiStreaming"})(ye||(ye={}));var Fo;(function(e){e[e.NoSideEffects=1]="NoSideEffects",e[e.Idempotent=2]="Idempotent"})(Fo||(Fo={}));var Yn;(function(e){e[e.UNSPECIFIED=0]="UNSPECIFIED",e[e.JUPYTER_FORMAT=77]="JUPYTER_FORMAT"})(Yn||(Yn={})),N.util.setEnumType(Yn,"exa.codeium_common_pb.ExperimentKey",[{no:0,name:"UNSPECIFIED"},{no:77,name:"JUPYTER_FORMAT"}]);var on;(function(e){e[e.CODEIUM=0]="CODEIUM"})(on||(on={})),N.util.setEnumType(on,"exa.codeium_common_pb.AuthSource",[{no:0,name:"AUTH_SOURCE_CODEIUM"}]);var an;(function(e){e[e.UNSPECIFIED=0]="UNSPECIFIED",e[e.ENABLE_CODEIUM=1]="ENABLE_CODEIUM",e[e.DISABLE_CODEIUM=2]="DISABLE_CODEIUM",e[e.SHOW_PREVIOUS_COMPLETION=3]="SHOW_PREVIOUS_COMPLETION",e[e.SHOW_NEXT_COMPLETION=4]="SHOW_NEXT_COMPLETION"})(an||(an={})),N.util.setEnumType(an,"exa.codeium_common_pb.EventType",[{no:0,name:"EVENT_TYPE_UNSPECIFIED"},{no:1,name:"EVENT_TYPE_ENABLE_CODEIUM"},{no:2,name:"EVENT_TYPE_DISABLE_CODEIUM"},{no:3,name:"EVENT_TYPE_SHOW_PREVIOUS_COMPLETION"},{no:4,name:"EVENT_TYPE_SHOW_NEXT_COMPLETION"}]);var sn;(function(e){e[e.UNSPECIFIED=0]="UNSPECIFIED",e[e.TYPING_AS_SUGGESTED=1]="TYPING_AS_SUGGESTED",e[e.CACHE=2]="CACHE",e[e.NETWORK=3]="NETWORK"})(sn||(sn={})),N.util.setEnumType(sn,"exa.codeium_common_pb.CompletionSource",[{no:0,name:"COMPLETION_SOURCE_UNSPECIFIED"},{no:1,name:"COMPLETION_SOURCE_TYPING_AS_SUGGESTED"},{no:2,name:"COMPLETION_SOURCE_CACHE"},{no:3,name:"COMPLETION_SOURCE_NETWORK"}]);var it;(function(e){e[e.UNSPECIFIED=0]="UNSPECIFIED",e[e.C=1]="C",e[e.CLOJURE=2]="CLOJURE",e[e.COFFEESCRIPT=3]="COFFEESCRIPT",e[e.CPP=4]="CPP",e[e.CSHARP=5]="CSHARP",e[e.CSS=6]="CSS",e[e.CUDACPP=7]="CUDACPP",e[e.DOCKERFILE=8]="DOCKERFILE",e[e.GO=9]="GO",e[e.GROOVY=10]="GROOVY",e[e.HANDLEBARS=11]="HANDLEBARS",e[e.HASKELL=12]="HASKELL",e[e.HCL=13]="HCL",e[e.HTML=14]="HTML",e[e.INI=15]="INI",e[e.JAVA=16]="JAVA",e[e.JAVASCRIPT=17]="JAVASCRIPT",e[e.JSON=18]="JSON",e[e.JULIA=19]="JULIA",e[e.KOTLIN=20]="KOTLIN",e[e.LATEX=21]="LATEX",e[e.LESS=22]="LESS",e[e.LUA=23]="LUA",e[e.MAKEFILE=24]="MAKEFILE",e[e.MARKDOWN=25]="MARKDOWN",e[e.OBJECTIVEC=26]="OBJECTIVEC",e[e.OBJECTIVECPP=27]="OBJECTIVECPP",e[e.PERL=28]="PERL",e[e.PHP=29]="PHP",e[e.PLAINTEXT=30]="PLAINTEXT",e[e.PROTOBUF=31]="PROTOBUF",e[e.PBTXT=32]="PBTXT",e[e.PYTHON=33]="PYTHON",e[e.R=34]="R",e[e.RUBY=35]="RUBY",e[e.RUST=36]="RUST",e[e.SASS=37]="SASS",e[e.SCALA=38]="SCALA",e[e.SCSS=39]="SCSS",e[e.SHELL=40]="SHELL",e[e.SQL=41]="SQL",e[e.STARLARK=42]="STARLARK",e[e.SWIFT=43]="SWIFT",e[e.TSX=44]="TSX",e[e.TYPESCRIPT=45]="TYPESCRIPT",e[e.VISUALBASIC=46]="VISUALBASIC",e[e.VUE=47]="VUE",e[e.XML=48]="XML",e[e.XSL=49]="XSL",e[e.YAML=50]="YAML",e[e.SVELTE=51]="SVELTE",e[e.TOML=52]="TOML",e[e.DART=53]="DART",e[e.RST=54]="RST",e[e.OCAML=55]="OCAML",e[e.CMAKE=56]="CMAKE",e[e.PASCAL=57]="PASCAL",e[e.ELIXIR=58]="ELIXIR",e[e.FSHARP=59]="FSHARP",e[e.LISP=60]="LISP",e[e.MATLAB=61]="MATLAB",e[e.POWERSHELL=62]="POWERSHELL",e[e.SOLIDITY=63]="SOLIDITY",e[e.ADA=64]="ADA",e[e.OCAML_INTERFACE=65]="OCAML_INTERFACE"})(it||(it={})),N.util.setEnumType(it,"exa.codeium_common_pb.Language",[{no:0,name:"LANGUAGE_UNSPECIFIED"},{no:1,name:"LANGUAGE_C"},{no:2,name:"LANGUAGE_CLOJURE"},{no:3,name:"LANGUAGE_COFFEESCRIPT"},{no:4,name:"LANGUAGE_CPP"},{no:5,name:"LANGUAGE_CSHARP"},{no:6,name:"LANGUAGE_CSS"},{no:7,name:"LANGUAGE_CUDACPP"},{no:8,name:"LANGUAGE_DOCKERFILE"},{no:9,name:"LANGUAGE_GO"},{no:10,name:"LANGUAGE_GROOVY"},{no:11,name:"LANGUAGE_HANDLEBARS"},{no:12,name:"LANGUAGE_HASKELL"},{no:13,name:"LANGUAGE_HCL"},{no:14,name:"LANGUAGE_HTML"},{no:15,name:"LANGUAGE_INI"},{no:16,name:"LANGUAGE_JAVA"},{no:17,name:"LANGUAGE_JAVASCRIPT"},{no:18,name:"LANGUAGE_JSON"},{no:19,name:"LANGUAGE_JULIA"},{no:20,name:"LANGUAGE_KOTLIN"},{no:21,name:"LANGUAGE_LATEX"},{no:22,name:"LANGUAGE_LESS"},{no:23,name:"LANGUAGE_LUA"},{no:24,name:"LANGUAGE_MAKEFILE"},{no:25,name:"LANGUAGE_MARKDOWN"},{no:26,name:"LANGUAGE_OBJECTIVEC"},{no:27,name:"LANGUAGE_OBJECTIVECPP"},{no:28,name:"LANGUAGE_PERL"},{no:29,name:"LANGUAGE_PHP"},{no:30,name:"LANGUAGE_PLAINTEXT"},{no:31,name:"LANGUAGE_PROTOBUF"},{no:32,name:"LANGUAGE_PBTXT"},{no:33,name:"LANGUAGE_PYTHON"},{no:34,name:"LANGUAGE_R"},{no:35,name:"LANGUAGE_RUBY"},{no:36,name:"LANGUAGE_RUST"},{no:37,name:"LANGUAGE_SASS"},{no:38,name:"LANGUAGE_SCALA"},{no:39,name:"LANGUAGE_SCSS"},{no:40,name:"LANGUAGE_SHELL"},{no:41,name:"LANGUAGE_SQL"},{no:42,name:"LANGUAGE_STARLARK"},{no:43,name:"LANGUAGE_SWIFT"},{no:44,name:"LANGUAGE_TSX"},{no:45,name:"LANGUAGE_TYPESCRIPT"},{no:46,name:"LANGUAGE_VISUALBASIC"},{no:47,name:"LANGUAGE_VUE"},{no:48,name:"LANGUAGE_XML"},{no:49,name:"LANGUAGE_XSL"},{no:50,name:"LANGUAGE_YAML"},{no:51,name:"LANGUAGE_SVELTE"},{no:52,name:"LANGUAGE_TOML"},{no:53,name:"LANGUAGE_DART"},{no:54,name:"LANGUAGE_RST"},{no:55,name:"LANGUAGE_OCAML"},{no:56,name:"LANGUAGE_CMAKE"},{no:57,name:"LANGUAGE_PASCAL"},{no:58,name:"LANGUAGE_ELIXIR"},{no:59,name:"LANGUAGE_FSHARP"},{no:60,name:"LANGUAGE_LISP"},{no:61,name:"LANGUAGE_MATLAB"},{no:62,name:"LANGUAGE_POWERSHELL"},{no:63,name:"LANGUAGE_SOLIDITY"},{no:64,name:"LANGUAGE_ADA"},{no:65,name:"LANGUAGE_OCAML_INTERFACE"}]);var al=(we=class extends X{constructor(n){super();p(this,"completionId","");p(this,"text","");p(this,"prefix","");p(this,"stop","");p(this,"score",0);p(this,"tokens",[]);p(this,"decodedTokens",[]);p(this,"probabilities",[]);p(this,"adjustedProbabilities",[]);p(this,"generatedLength",J.zero);N.util.initPartial(n,this)}static fromBinary(n,r){return new we().fromBinary(n,r)}static fromJson(n,r){return new we().fromJson(n,r)}static fromJsonString(n,r){return new we().fromJsonString(n,r)}static equals(n,r){return N.util.equals(we,n,r)}},p(we,"runtime",N),p(we,"typeName","exa.codeium_common_pb.Completion"),p(we,"fields",N.util.newFieldList(()=>[{no:1,name:"completion_id",kind:"scalar",T:9},{no:2,name:"text",kind:"scalar",T:9},{no:3,name:"prefix",kind:"scalar",T:9},{no:4,name:"stop",kind:"scalar",T:9},{no:5,name:"score",kind:"scalar",T:1},{no:6,name:"tokens",kind:"scalar",T:4,repeated:!0},{no:7,name:"decoded_tokens",kind:"scalar",T:9,repeated:!0},{no:8,name:"probabilities",kind:"scalar",T:1,repeated:!0},{no:9,name:"adjusted_probabilities",kind:"scalar",T:1,repeated:!0},{no:10,name:"generated_length",kind:"scalar",T:4}])),we),Lo=(ve=class extends X{constructor(n){super();p(this,"ideName","");p(this,"ideVersion","");p(this,"extensionName","");p(this,"extensionVersion","");p(this,"apiKey","");p(this,"locale","");p(this,"sessionId","");p(this,"requestId",J.zero);p(this,"userAgent","");p(this,"url","");p(this,"authSource",on.CODEIUM);N.util.initPartial(n,this)}static fromBinary(n,r){return new ve().fromBinary(n,r)}static fromJson(n,r){return new ve().fromJson(n,r)}static fromJsonString(n,r){return new ve().fromJsonString(n,r)}static equals(n,r){return N.util.equals(ve,n,r)}},p(ve,"runtime",N),p(ve,"typeName","exa.codeium_common_pb.Metadata"),p(ve,"fields",N.util.newFieldList(()=>[{no:1,name:"ide_name",kind:"scalar",T:9},{no:7,name:"ide_version",kind:"scalar",T:9},{no:12,name:"extension_name",kind:"scalar",T:9},{no:2,name:"extension_version",kind:"scalar",T:9},{no:3,name:"api_key",kind:"scalar",T:9},{no:4,name:"locale",kind:"scalar",T:9},{no:10,name:"session_id",kind:"scalar",T:9},{no:9,name:"request_id",kind:"scalar",T:4},{no:13,name:"user_agent",kind:"scalar",T:9},{no:14,name:"url",kind:"scalar",T:9},{no:15,name:"auth_source",kind:"enum",T:N.getEnumType(on)}])),ve),il=(Ee=class extends X{constructor(n){super();p(this,"tabSize",J.zero);p(this,"insertSpaces",!1);N.util.initPartial(n,this)}static fromBinary(n,r){return new Ee().fromBinary(n,r)}static fromJson(n,r){return new Ee().fromJson(n,r)}static fromJsonString(n,r){return new Ee().fromJsonString(n,r)}static equals(n,r){return N.util.equals(Ee,n,r)}},p(Ee,"runtime",N),p(Ee,"typeName","exa.codeium_common_pb.EditorOptions"),p(Ee,"fields",N.util.newFieldList(()=>[{no:1,name:"tab_size",kind:"scalar",T:4},{no:2,name:"insert_spaces",kind:"scalar",T:8}])),Ee);Ne=class extends X{constructor(n){super();p(this,"eventType",an.UNSPECIFIED);p(this,"eventJson","");p(this,"timestampUnixMs",J.zero);N.util.initPartial(n,this)}static fromBinary(n,r){return new Ne().fromBinary(n,r)}static fromJson(n,r){return new Ne().fromJson(n,r)}static fromJsonString(n,r){return new Ne().fromJsonString(n,r)}static equals(n,r){return N.util.equals(Ne,n,r)}},p(Ne,"runtime",N),p(Ne,"typeName","exa.codeium_common_pb.Event"),p(Ne,"fields",N.util.newFieldList(()=>[{no:1,name:"event_type",kind:"enum",T:N.getEnumType(an)},{no:2,name:"event_json",kind:"scalar",T:9},{no:3,name:"timestamp_unix_ms",kind:"scalar",T:3}]));var sl=class extends Fn{constructor(t,n){super();p(this,"index");p(this,"total");this.index=t,this.total=n}toDOM(){let t=document.createElement("span");t.setAttribute("aria-hidden","true"),t.className="cm-codeium-cycle";let n=t.appendChild(document.createElement("span"));n.className="cm-codeium-cycle-explanation",n.innerText=`${this.index+1}/${this.total}`;let r=t.appendChild(document.createElement("button"));return r.className="cm-codeium-cycle-key",r.innerText="\u2192 (Ctrl ])",r.dataset.action="codeium-cycle",t}ignoreEvent(){return!1}};const ln=Mt.define({combine(e){return An(e,{language:it.TYPESCRIPT,timeout:150,widgetClass:sl,alwaysOn:!0},{})}}),Oo=Mt.define({combine(e){return An(e,{override:()=>[]},{})}});var ll=H.mark({class:"cm-ghostText"});const st=qe.define({create(e){return null},update(e,t){var r;let n=t.state.facet(ln);for(let o of t.effects){if(o.is(Jn)){let{changeSpecs:a,index:i}=o.value,s=a[i].map(u=>ll.range(u.absoluteStartPos,u.absoluteEndPos)),c=(r=s.at(-1))==null?void 0:r.to;return{index:i,decorations:H.set([...s,...c!==void 0&&a.length>1&&n.widgetClass?[H.widget({widget:new n.widgetClass(i,a.length),side:1}).range(c)]:[]]),changeSpecs:a,reverseChangeSet:o.value.reverseChangeSet}}if(o.is(Wn)||o.is(Vn))return null}return e&&{...e,decorations:e.decorations.map(t.changes),reverseChangeSet:e.reverseChangeSet.map(t.changes)}},provide:e=>B.decorations.from(e,t=>(t==null?void 0:t.decorations)||H.none)}),ht=In.define(),cn=In.define();var M;(function(e){e[e.Canceled=1]="Canceled",e[e.Unknown=2]="Unknown",e[e.InvalidArgument=3]="InvalidArgument",e[e.DeadlineExceeded=4]="DeadlineExceeded",e[e.NotFound=5]="NotFound",e[e.AlreadyExists=6]="AlreadyExists",e[e.PermissionDenied=7]="PermissionDenied",e[e.ResourceExhausted=8]="ResourceExhausted",e[e.FailedPrecondition=9]="FailedPrecondition",e[e.Aborted=10]="Aborted",e[e.OutOfRange=11]="OutOfRange",e[e.Unimplemented=12]="Unimplemented",e[e.Internal=13]="Internal",e[e.Unavailable=14]="Unavailable",e[e.DataLoss=15]="DataLoss",e[e.Unauthenticated=16]="Unauthenticated"})(M||(M={}));function Xn(e){let t=M[e];return typeof t=="string"?t[0].toLowerCase()+t.substring(1).replace(/[A-Z]/g,n=>"_"+n.toLowerCase()):e.toString()}var un;function cl(e){if(!un){un={};for(let t of Object.values(M))typeof t!="string"&&(un[Xn(t)]=t)}return un[e]}var he=class St extends Error{constructor(t,n=M.Unknown,r,o,a){super(ul(t,n)),this.name="ConnectError",Object.setPrototypeOf(this,new.target.prototype),this.rawMessage=t,this.code=n,this.metadata=new Headers(r??{}),this.details=o??[],this.cause=a}static from(t,n=M.Unknown){return t instanceof St?t:t instanceof Error?t.name=="AbortError"?new St(t.message,M.Canceled):new St(t.message,n,void 0,void 0,t):new St(String(t),n,void 0,void 0,t)}static[Symbol.hasInstance](t){return t instanceof Error?Object.getPrototypeOf(t)===St.prototype?!0:t.name==="ConnectError"&&"code"in t&&typeof t.code=="number"&&"metadata"in t&&"details"in t&&Array.isArray(t.details)&&"rawMessage"in t&&typeof t.rawMessage=="string"&&"cause"in t:!1}findDetails(t){let n="typeName"in t?{findMessage:o=>o===t.typeName?t:void 0}:t,r=[];for(let o of this.details){if("getType"in o){n.findMessage(o.getType().typeName)&&r.push(o);continue}let a=n.findMessage(o.type);if(a)try{r.push(a.fromBinary(o.value))}catch{}}return r}};function ul(e,t){return e.length?`[${Xn(t)}] ${e}`:`[${Xn(t)}]`}function dl(...e){let t=new Headers;for(let n of e)n.forEach((r,o)=>{t.append(o,r)});return t}function fl(e,t){let n={};for(let[r,o]of Object.entries(e.methods)){let a=t(Object.assign(Object.assign({},o),{localName:r,service:e}));a!=null&&(n[r]=a)}return n}function ml(e){let t,n=new Uint8Array;function r(o){let a=new Uint8Array(n.length+o.length);a.set(n),a.set(o,n.length),n=a}return new ReadableStream({start(){t=e.getReader()},async pull(o){let a;for(;;){if(a===void 0&&n.byteLength>=5){let c=0;for(let u=1;u<5;u++)c=(c<<8)+n[u];a={flags:n[0],length:c}}if(a!==void 0&&n.byteLength>=a.length+5)break;let s=await t.read();if(s.done)break;r(s.value)}if(a===void 0){if(n.byteLength==0){o.close();return}o.error(new he("premature end of stream",M.DataLoss));return}let i=n.subarray(5,5+a.length);n=n.subarray(5+a.length),o.enqueue({flags:a.flags,data:i})}})}function pl(e,t){let n=new Uint8Array(t.length+5);n.set(t,5);let r=new DataView(n.buffer,n.byteOffset,n.byteLength);return r.setUint8(0,e),r.setUint32(1,t.length),n}var hl=function(e){if(!Symbol.asyncIterator)throw TypeError("Symbol.asyncIterator is not defined.");var t=e[Symbol.asyncIterator],n;return t?t.call(e):(e=typeof __values=="function"?__values(e):e[Symbol.iterator](),n={},r("next"),r("throw"),r("return"),n[Symbol.asyncIterator]=function(){return this},n);function r(a){n[a]=e[a]&&function(i){return new Promise(function(s,c){i=e[a](i),o(s,c,i.done,i.value)})}}function o(a,i,s,c){Promise.resolve(c).then(function(u){a({value:u,done:s})},i)}},Dt=function(e){return this instanceof Dt?(this.v=e,this):new Dt(e)},gl=function(e,t,n){if(!Symbol.asyncIterator)throw TypeError("Symbol.asyncIterator is not defined.");var r=n.apply(e,t||[]),o,a=[];return o={},s("next"),s("throw"),s("return",i),o[Symbol.asyncIterator]=function(){return this},o;function i(m){return function(g){return Promise.resolve(g).then(m,f)}}function s(m,g){r[m]&&(o[m]=function(y){return new Promise(function(w,k){a.push([m,y,w,k])>1||c(m,y)})},g&&(o[m]=g(o[m])))}function c(m,g){try{u(r[m](g))}catch(y){h(a[0][3],y)}}function u(m){m.value instanceof Dt?Promise.resolve(m.value.v).then(d,f):h(a[0][2],m)}function d(m){c("next",m)}function f(m){c("throw",m)}function h(m,g){m(g),a.shift(),a.length&&c(a[0][0],a[0][1])}},bl=function(e){var t,n;return t={},r("next"),r("throw",function(o){throw o}),r("return"),t[Symbol.iterator]=function(){return this},t;function r(o,a){t[o]=e[o]?function(i){return(n=!n)?{value:Dt(e[o](i)),done:!1}:a?a(i):i}:a}};function yl(e){return gl(this,arguments,function*(){yield Dt(yield*bl(hl(e)))})}var Do=function(e){if(!Symbol.asyncIterator)throw TypeError("Symbol.asyncIterator is not defined.");var t=e[Symbol.asyncIterator],n;return t?t.call(e):(e=typeof __values=="function"?__values(e):e[Symbol.iterator](),n={},r("next"),r("throw"),r("return"),n[Symbol.asyncIterator]=function(){return this},n);function r(a){n[a]=e[a]&&function(i){return new Promise(function(s,c){i=e[a](i),o(s,c,i.done,i.value)})}}function o(a,i,s,c){Promise.resolve(c).then(function(u){a({value:u,done:s})},i)}},gt=function(e){return this instanceof gt?(this.v=e,this):new gt(e)},wl=function(e){var t,n;return t={},r("next"),r("throw",function(o){throw o}),r("return"),t[Symbol.iterator]=function(){return this},t;function r(o,a){t[o]=e[o]?function(i){return(n=!n)?{value:gt(e[o](i)),done:!1}:a?a(i):i}:a}},vl=function(e,t,n){if(!Symbol.asyncIterator)throw TypeError("Symbol.asyncIterator is not defined.");var r=n.apply(e,t||[]),o,a=[];return o={},s("next"),s("throw"),s("return",i),o[Symbol.asyncIterator]=function(){return this},o;function i(m){return function(g){return Promise.resolve(g).then(m,f)}}function s(m,g){r[m]&&(o[m]=function(y){return new Promise(function(w,k){a.push([m,y,w,k])>1||c(m,y)})},g&&(o[m]=g(o[m])))}function c(m,g){try{u(r[m](g))}catch(y){h(a[0][3],y)}}function u(m){m.value instanceof gt?Promise.resolve(m.value.v).then(d,f):h(a[0][2],m)}function d(m){c("next",m)}function f(m){c("throw",m)}function h(m,g){m(g),a.shift(),a.length&&c(a[0][0],a[0][1])}};function El(e,t){return fl(e,n=>{switch(n.kind){case ye.Unary:return kl(t,e,n);case ye.ServerStreaming:return Cl(t,e,n);case ye.ClientStreaming:return Sl(t,e,n);case ye.BiDiStreaming:return xl(t,e,n);default:return null}})}function Nl(e,t){return El(e,t)}function kl(e,t,n){return async function(r,o){var a,i;let s=await e.unary(t,n,o==null?void 0:o.signal,o==null?void 0:o.timeoutMs,o==null?void 0:o.headers,r,o==null?void 0:o.contextValues);return(a=o==null?void 0:o.onHeader)==null||a.call(o,s.header),(i=o==null?void 0:o.onTrailer)==null||i.call(o,s.trailer),s.message}}function Cl(e,t,n){return function(r,o){return _o(e.stream(t,n,o==null?void 0:o.signal,o==null?void 0:o.timeoutMs,o==null?void 0:o.headers,yl([r]),o==null?void 0:o.contextValues),o)}}function Sl(e,t,n){return async function(r,o){var a,i,s,c,u,d;let f=await e.stream(t,n,o==null?void 0:o.signal,o==null?void 0:o.timeoutMs,o==null?void 0:o.headers,r,o==null?void 0:o.contextValues);(u=o==null?void 0:o.onHeader)==null||u.call(o,f.header);let h,m=0;try{for(var g=!0,y=Do(f.message),w;w=await y.next(),a=w.done,!a;g=!0)c=w.value,g=!1,h=c,m++}catch(k){i={error:k}}finally{try{!g&&!a&&(s=y.return)&&await s.call(y)}finally{if(i)throw i.error}}if(!h)throw new he("protocol error: missing response message",M.Unimplemented);if(m>1)throw new he("protocol error: received extra messages for client streaming method",M.Unimplemented);return(d=o==null?void 0:o.onTrailer)==null||d.call(o,f.trailer),h}}function xl(e,t,n){return function(r,o){return _o(e.stream(t,n,o==null?void 0:o.signal,o==null?void 0:o.timeoutMs,o==null?void 0:o.headers,r,o==null?void 0:o.contextValues),o)}}function _o(e,t){let n=(function(){return vl(this,arguments,function*(){var r,o;let a=yield gt(e);(r=t==null?void 0:t.onHeader)==null||r.call(t,a.header),yield gt(yield*wl(Do(a.message))),(o=t==null?void 0:t.onTrailer)==null||o.call(t,a.trailer)})})()[Symbol.asyncIterator]();return{[Symbol.asyncIterator]:()=>({next:()=>n.next()})}}function Al(...e){let t=new AbortController,n=e.filter(o=>o!==void 0).concat(t.signal);for(let o of n){if(o.aborted){r.apply(o);break}o.addEventListener("abort",r)}function r(){t.signal.aborted||t.abort(Uo(this));for(let o of n)o.removeEventListener("abort",r)}return t}function Tl(e){let t=new AbortController,n=()=>{t.abort(new he("the operation timed out",M.DeadlineExceeded))},r;return e!==void 0&&(e<=0?n():r=setTimeout(n,e)),{signal:t.signal,cleanup:()=>clearTimeout(r)}}function Uo(e){if(!e.aborted)return;if(e.reason!==void 0)return e.reason;let t=Error("This operation was aborted");return t.name="AbortError",t}function Bo(){return{get(e){return e.id in this?this[e.id]:e.defaultValue},set(e,t){return this[e.id]=t,this},delete(e){return delete this[e.id],this}}}function jo(e,t,n){let r=typeof t=="string"?t:t.typeName,o=typeof n=="string"?n:n.name;return e.toString().replace(/\/?$/,`/${r}/${o}`)}function Po(e,t){return t instanceof e?t:new e(t)}function Il(e,t){function n(r){return r.done===!0?r:{done:r.done,value:Po(e,r.value)}}return{[Symbol.asyncIterator](){let r=t[Symbol.asyncIterator](),o={next:()=>r.next().then(n)};return r.throw!==void 0&&(o.throw=a=>r.throw(a).then(n)),r.return!==void 0&&(o.return=a=>r.return(a).then(n)),o}}}function Mo(e,t){return(t==null?void 0:t.concat().reverse().reduce((n,r)=>r(n),e))??e}function Ro(e){let t=Object.assign({},e);return t.ignoreUnknownFields??(t.ignoreUnknownFields=!0),t}function Go(e,t,n,r){let o=t?Jo(e.I,r):Wo(e.I,n);return{parse:(t?Jo(e.O,r):Wo(e.O,n)).parse,serialize:o.serialize}}function Jo(e,t){return{parse(n){try{return e.fromBinary(n,t)}catch(r){throw new he(`parse binary: ${r instanceof Error?r.message:String(r)}`,M.Internal)}},serialize(n){try{return n.toBinary(t)}catch(r){throw new he(`serialize binary: ${r instanceof Error?r.message:String(r)}`,M.Internal)}}}}function Wo(e,t){let n=(t==null?void 0:t.textEncoder)??new TextEncoder,r=(t==null?void 0:t.textDecoder)??new TextDecoder,o=Ro(t);return{parse(a){try{let i=r.decode(a);return e.fromJsonString(i,o)}catch(i){throw he.from(i,M.InvalidArgument)}},serialize(a){try{let i=a.toJsonString(o);return n.encode(i)}catch(i){throw he.from(i,M.Internal)}}}}const Fl=/^application\/(connect\+)?(?:(json)(?:; ?charset=utf-?8)?|(proto))$/i;function Ll(e){let t=e==null?void 0:e.match(Fl);if(t)return{stream:!!t[1],binary:!!t[3]}}function Vo(e,t,n){if(t&&new Headers(t).forEach((i,s)=>n.metadata.append(s,i)),typeof e!="object"||!e||Array.isArray(e))throw n;let r=n.code;"code"in e&&typeof e.code=="string"&&(r=cl(e.code)??r);let o=e.message;if(o!=null&&typeof o!="string")throw n;let a=new he(o??"",r,t);if("details"in e&&Array.isArray(e.details))for(let i of e.details){if(typeof i!="object"||!i||Array.isArray(i)||typeof i.type!="string"||typeof i.value!="string")throw n;try{a.details.push({type:i.type,value:Xt.dec(i.value),debug:i.debug})}catch{throw n}}return a}function Ol(e){let t=new he("invalid end stream",M.Unknown),n;try{n=JSON.parse(typeof e=="string"?e:new TextDecoder().decode(e))}catch{throw t}if(typeof n!="object"||!n||Array.isArray(n))throw t;let r=new Headers;if("metadata"in n){if(typeof n.metadata!="object"||n.metadata==null||Array.isArray(n.metadata))throw t;for(let[o,a]of Object.entries(n.metadata)){if(!Array.isArray(a)||a.some(i=>typeof i!="string"))throw t;for(let i of a)r.append(o,i)}}return{metadata:r,error:"error"in n&&n.error!=null?Vo(n.error,r,t):void 0}}const dn="Content-Type",$o="Content-Encoding",Ho="Connect-Protocol-Version";function Dl(e){switch(e){case 400:return M.Internal;case 401:return M.Unauthenticated;case 403:return M.PermissionDenied;case 404:return M.Unimplemented;case 429:return M.Unavailable;case 502:return M.Unavailable;case 503:return M.Unavailable;case 504:return M.Unavailable;default:return M.Unknown}}function qo(e){let t=new Headers,n=new Headers;return e.forEach((r,o)=>{o.toLowerCase().startsWith("trailer-")?n.append(o.substring(8),r):t.append(o,r)}),[t,n]}function zo(e,t,n,r,o){let a=new Headers(r??{});return n!==void 0&&a.set("Connect-Timeout-Ms",`${n}`),a.set(dn,e==ye.Unary?t?"application/proto":"application/json":t?"application/connect+proto":"application/connect+json"),a.set(Ho,"1"),o&&a.set("User-Agent","connect-es/1.6.1"),a}function Ko(e,t,n,r){let o=r.get(dn),a=Ll(o);if(n!==200){let s=new he(`HTTP ${n}`,Dl(n),r);if(e==ye.Unary&&a&&!a.binary)return{isUnaryError:!0,unaryError:s};throw s}let i={binary:t,stream:e!==ye.Unary};if((a==null?void 0:a.binary)!==i.binary||a.stream!==i.stream)throw new he(`unsupported content type ${o}`,a===void 0?M.Unknown:M.Internal,r);return{isUnaryError:!1}}var _l="application/";function Ul(e,t){return t?Xt.enc(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,""):encodeURIComponent(new TextDecoder().decode(e))}function Bl(e,t,n){let r="?connect=v1",o=e.header.get(dn);(o==null?void 0:o.indexOf(_l))===0&&(r+="&encoding="+encodeURIComponent(o.slice(12)));let a=e.header.get($o);a!==null&&a!=="identity"&&(r+="&compression="+encodeURIComponent(a),n=!0),n&&(r+="&base64=1"),r+="&message="+Ul(t,n);let i=e.url+r,s=new Headers(e.header);return[Ho,dn,"Content-Length",$o,"Accept-Encoding"].forEach(c=>s.delete(c)),Object.assign(Object.assign({},e),{init:Object.assign(Object.assign({},e.init),{method:"GET"}),url:i,header:s})}function jl(e){let t=Mo(e.next,e.interceptors),[n,r,o]=Yo(e);return t(Object.assign(Object.assign({},e.req),{message:Po(e.req.method.I,e.req.message),signal:n})).then(a=>(o(),a),r)}function Pl(e){let t=Mo(e.next,e.interceptors),[n,r,o]=Yo(e),a=Object.assign(Object.assign({},e.req),{message:Il(e.req.method.I,e.req.message),signal:n}),i=!1;return n.addEventListener("abort",function(){var s,c;let u=e.req.message[Symbol.asyncIterator]();i||(s=u.throw)==null||s.call(u,this.reason).catch(()=>{}),(c=u.return)==null||c.call(u).catch(()=>{})}),t(a).then(s=>Object.assign(Object.assign({},s),{message:{[Symbol.asyncIterator](){let c=s.message[Symbol.asyncIterator]();return{next(){return c.next().then(u=>(u.done==1&&(i=!0,o()),u),r)}}}}}),r)}function Yo(e){let{signal:t,cleanup:n}=Tl(e.timeoutMs),r=Al(e.signal,t);return[r.signal,function(o){let a=he.from(t.aborted?Uo(t):o);return r.abort(a),n(),Promise.reject(a)},function(){n(),r.abort()}]}var fn;(function(e){e[e.UNSPECIFIED=0]="UNSPECIFIED",e[e.INACTIVE=1]="INACTIVE",e[e.PROCESSING=2]="PROCESSING",e[e.SUCCESS=3]="SUCCESS",e[e.WARNING=4]="WARNING",e[e.ERROR=5]="ERROR"})(fn||(fn={})),N.util.setEnumType(fn,"exa.language_server_pb.CodeiumState",[{no:0,name:"CODEIUM_STATE_UNSPECIFIED"},{no:1,name:"CODEIUM_STATE_INACTIVE"},{no:2,name:"CODEIUM_STATE_PROCESSING"},{no:3,name:"CODEIUM_STATE_SUCCESS"},{no:4,name:"CODEIUM_STATE_WARNING"},{no:5,name:"CODEIUM_STATE_ERROR"}]);var Xo;(function(e){e[e.UNSPECIFIED=0]="UNSPECIFIED",e[e.SINGLE=1]="SINGLE",e[e.MULTI=2]="MULTI"})(Xo||(Xo={})),N.util.setEnumType(Xo,"exa.language_server_pb.LineType",[{no:0,name:"LINE_TYPE_UNSPECIFIED"},{no:1,name:"LINE_TYPE_SINGLE"},{no:2,name:"LINE_TYPE_MULTI"}]);var mn;(function(e){e[e.UNSPECIFIED=0]="UNSPECIFIED",e[e.INLINE=1]="INLINE",e[e.BLOCK=2]="BLOCK",e[e.INLINE_MASK=3]="INLINE_MASK"})(mn||(mn={})),N.util.setEnumType(mn,"exa.language_server_pb.CompletionPartType",[{no:0,name:"COMPLETION_PART_TYPE_UNSPECIFIED"},{no:1,name:"COMPLETION_PART_TYPE_INLINE"},{no:2,name:"COMPLETION_PART_TYPE_BLOCK"},{no:3,name:"COMPLETION_PART_TYPE_INLINE_MASK"}]);var Ml=(ke=class extends X{constructor(n){super();p(this,"threshold",0);N.util.initPartial(n,this)}static fromBinary(n,r){return new ke().fromBinary(n,r)}static fromJson(n,r){return new ke().fromJson(n,r)}static fromJsonString(n,r){return new ke().fromJsonString(n,r)}static equals(n,r){return N.util.equals(ke,n,r)}},p(ke,"runtime",N),p(ke,"typeName","exa.language_server_pb.MultilineConfig"),p(ke,"fields",N.util.newFieldList(()=>[{no:1,name:"threshold",kind:"scalar",T:2}])),ke),Rl=(Ce=class extends X{constructor(n){super();p(this,"metadata");p(this,"document");p(this,"editorOptions");p(this,"otherDocuments",[]);p(this,"experimentConfig");p(this,"modelName","");p(this,"multilineConfig");N.util.initPartial(n,this)}static fromBinary(n,r){return new Ce().fromBinary(n,r)}static fromJson(n,r){return new Ce().fromJson(n,r)}static fromJsonString(n,r){return new Ce().fromJsonString(n,r)}static equals(n,r){return N.util.equals(Ce,n,r)}},p(Ce,"runtime",N),p(Ce,"typeName","exa.language_server_pb.GetCompletionsRequest"),p(Ce,"fields",N.util.newFieldList(()=>[{no:1,name:"metadata",kind:"message",T:Lo},{no:2,name:"document",kind:"message",T:Qo},{no:3,name:"editor_options",kind:"message",T:il},{no:5,name:"other_documents",kind:"message",T:Qo,repeated:!0},{no:7,name:"experiment_config",kind:"message",T:Hl},{no:10,name:"model_name",kind:"scalar",T:9},{no:13,name:"multiline_config",kind:"message",T:Ml}])),Ce),Gl=(Se=class extends X{constructor(n){super();p(this,"state");p(this,"completionItems",[]);N.util.initPartial(n,this)}static fromBinary(n,r){return new Se().fromBinary(n,r)}static fromJson(n,r){return new Se().fromJson(n,r)}static fromJsonString(n,r){return new Se().fromJsonString(n,r)}static equals(n,r){return N.util.equals(Se,n,r)}},p(Se,"runtime",N),p(Se,"typeName","exa.language_server_pb.GetCompletionsResponse"),p(Se,"fields",N.util.newFieldList(()=>[{no:1,name:"state",kind:"message",T:ql},{no:2,name:"completion_items",kind:"message",T:Xl,repeated:!0}])),Se),Jl=(xe=class extends X{constructor(n){super();p(this,"metadata");p(this,"completionId","");N.util.initPartial(n,this)}static fromBinary(n,r){return new xe().fromBinary(n,r)}static fromJson(n,r){return new xe().fromJson(n,r)}static fromJsonString(n,r){return new xe().fromJsonString(n,r)}static equals(n,r){return N.util.equals(xe,n,r)}},p(xe,"runtime",N),p(xe,"typeName","exa.language_server_pb.AcceptCompletionRequest"),p(xe,"fields",N.util.newFieldList(()=>[{no:1,name:"metadata",kind:"message",T:Lo},{no:2,name:"completion_id",kind:"scalar",T:9}])),xe),Wl=(Ae=class extends X{constructor(t){super(),N.util.initPartial(t,this)}static fromBinary(t,n){return new Ae().fromBinary(t,n)}static fromJson(t,n){return new Ae().fromJson(t,n)}static fromJsonString(t,n){return new Ae().fromJsonString(t,n)}static equals(t,n){return N.util.equals(Ae,t,n)}},p(Ae,"runtime",N),p(Ae,"typeName","exa.language_server_pb.AcceptCompletionResponse"),p(Ae,"fields",N.util.newFieldList(()=>[])),Ae),Vl=(Te=class extends X{constructor(t){super(),N.util.initPartial(t,this)}static fromBinary(t,n){return new Te().fromBinary(t,n)}static fromJson(t,n){return new Te().fromJson(t,n)}static fromJsonString(t,n){return new Te().fromJsonString(t,n)}static equals(t,n){return N.util.equals(Te,t,n)}},p(Te,"runtime",N),p(Te,"typeName","exa.language_server_pb.GetAuthTokenRequest"),p(Te,"fields",N.util.newFieldList(()=>[])),Te),$l=(Ie=class extends X{constructor(n){super();p(this,"authToken","");p(this,"uuid","");N.util.initPartial(n,this)}static fromBinary(n,r){return new Ie().fromBinary(n,r)}static fromJson(n,r){return new Ie().fromJson(n,r)}static fromJsonString(n,r){return new Ie().fromJsonString(n,r)}static equals(n,r){return N.util.equals(Ie,n,r)}},p(Ie,"runtime",N),p(Ie,"typeName","exa.language_server_pb.GetAuthTokenResponse"),p(Ie,"fields",N.util.newFieldList(()=>[{no:1,name:"auth_token",kind:"scalar",T:9},{no:2,name:"uuid",kind:"scalar",T:9}])),Ie),Qn=(Fe=class extends X{constructor(n){super();p(this,"row",J.zero);p(this,"col",J.zero);N.util.initPartial(n,this)}static fromBinary(n,r){return new Fe().fromBinary(n,r)}static fromJson(n,r){return new Fe().fromJson(n,r)}static fromJsonString(n,r){return new Fe().fromJsonString(n,r)}static equals(n,r){return N.util.equals(Fe,n,r)}},p(Fe,"runtime",N),p(Fe,"typeName","exa.language_server_pb.DocumentPosition"),p(Fe,"fields",N.util.newFieldList(()=>[{no:1,name:"row",kind:"scalar",T:4},{no:2,name:"col",kind:"scalar",T:4}])),Fe),Qo=(Le=class extends X{constructor(n){super();p(this,"absolutePath","");p(this,"relativePath","");p(this,"text","");p(this,"editorLanguage","");p(this,"language",it.UNSPECIFIED);p(this,"cursorOffset",J.zero);p(this,"cursorPosition");p(this,"lineEnding","");N.util.initPartial(n,this)}static fromBinary(n,r){return new Le().fromBinary(n,r)}static fromJson(n,r){return new Le().fromJson(n,r)}static fromJsonString(n,r){return new Le().fromJsonString(n,r)}static equals(n,r){return N.util.equals(Le,n,r)}},p(Le,"runtime",N),p(Le,"typeName","exa.language_server_pb.Document"),p(Le,"fields",N.util.newFieldList(()=>[{no:1,name:"absolute_path",kind:"scalar",T:9},{no:2,name:"relative_path",kind:"scalar",T:9},{no:3,name:"text",kind:"scalar",T:9},{no:4,name:"editor_language",kind:"scalar",T:9},{no:5,name:"language",kind:"enum",T:N.getEnumType(it)},{no:6,name:"cursor_offset",kind:"scalar",T:4},{no:8,name:"cursor_position",kind:"message",T:Qn},{no:7,name:"line_ending",kind:"scalar",T:9}])),Le),Hl=(Oe=class extends X{constructor(n){super();p(this,"forceEnableExperiments",[]);N.util.initPartial(n,this)}static fromBinary(n,r){return new Oe().fromBinary(n,r)}static fromJson(n,r){return new Oe().fromJson(n,r)}static fromJsonString(n,r){return new Oe().fromJsonString(n,r)}static equals(n,r){return N.util.equals(Oe,n,r)}},p(Oe,"runtime",N),p(Oe,"typeName","exa.language_server_pb.ExperimentConfig"),p(Oe,"fields",N.util.newFieldList(()=>[{no:1,name:"force_enable_experiments",kind:"enum",T:N.getEnumType(Yn),repeated:!0}])),Oe),ql=(De=class extends X{constructor(n){super();p(this,"state",fn.UNSPECIFIED);p(this,"message","");N.util.initPartial(n,this)}static fromBinary(n,r){return new De().fromBinary(n,r)}static fromJson(n,r){return new De().fromJson(n,r)}static fromJsonString(n,r){return new De().fromJsonString(n,r)}static equals(n,r){return N.util.equals(De,n,r)}},p(De,"runtime",N),p(De,"typeName","exa.language_server_pb.State"),p(De,"fields",N.util.newFieldList(()=>[{no:1,name:"state",kind:"enum",T:N.getEnumType(fn)},{no:2,name:"message",kind:"scalar",T:9}])),De),zl=(_e=class extends X{constructor(n){super();p(this,"startOffset",J.zero);p(this,"endOffset",J.zero);p(this,"startPosition");p(this,"endPosition");N.util.initPartial(n,this)}static fromBinary(n,r){return new _e().fromBinary(n,r)}static fromJson(n,r){return new _e().fromJson(n,r)}static fromJsonString(n,r){return new _e().fromJsonString(n,r)}static equals(n,r){return N.util.equals(_e,n,r)}},p(_e,"runtime",N),p(_e,"typeName","exa.language_server_pb.Range"),p(_e,"fields",N.util.newFieldList(()=>[{no:1,name:"start_offset",kind:"scalar",T:4},{no:2,name:"end_offset",kind:"scalar",T:4},{no:3,name:"start_position",kind:"message",T:Qn},{no:4,name:"end_position",kind:"message",T:Qn}])),_e),Kl=(Ue=class extends X{constructor(n){super();p(this,"text","");p(this,"deltaCursorOffset",J.zero);N.util.initPartial(n,this)}static fromBinary(n,r){return new Ue().fromBinary(n,r)}static fromJson(n,r){return new Ue().fromJson(n,r)}static fromJsonString(n,r){return new Ue().fromJsonString(n,r)}static equals(n,r){return N.util.equals(Ue,n,r)}},p(Ue,"runtime",N),p(Ue,"typeName","exa.language_server_pb.Suffix"),p(Ue,"fields",N.util.newFieldList(()=>[{no:1,name:"text",kind:"scalar",T:9},{no:2,name:"delta_cursor_offset",kind:"scalar",T:3}])),Ue),Yl=(Be=class extends X{constructor(n){super();p(this,"text","");p(this,"offset",J.zero);p(this,"type",mn.UNSPECIFIED);p(this,"prefix","");p(this,"line",J.zero);N.util.initPartial(n,this)}static fromBinary(n,r){return new Be().fromBinary(n,r)}static fromJson(n,r){return new Be().fromJson(n,r)}static fromJsonString(n,r){return new Be().fromJsonString(n,r)}static equals(n,r){return N.util.equals(Be,n,r)}},p(Be,"runtime",N),p(Be,"typeName","exa.language_server_pb.CompletionPart"),p(Be,"fields",N.util.newFieldList(()=>[{no:1,name:"text",kind:"scalar",T:9},{no:2,name:"offset",kind:"scalar",T:4},{no:3,name:"type",kind:"enum",T:N.getEnumType(mn)},{no:4,name:"prefix",kind:"scalar",T:9},{no:5,name:"line",kind:"scalar",T:4}])),Be),Xl=(je=class extends X{constructor(n){super();p(this,"completion");p(this,"suffix");p(this,"range");p(this,"source",sn.UNSPECIFIED);p(this,"completionParts",[]);N.util.initPartial(n,this)}static fromBinary(n,r){return new je().fromBinary(n,r)}static fromJson(n,r){return new je().fromJson(n,r)}static fromJsonString(n,r){return new je().fromJsonString(n,r)}static equals(n,r){return N.util.equals(je,n,r)}},p(je,"runtime",N),p(je,"typeName","exa.language_server_pb.CompletionItem"),p(je,"fields",N.util.newFieldList(()=>[{no:1,name:"completion",kind:"message",T:al},{no:5,name:"suffix",kind:"message",T:Kl},{no:2,name:"range",kind:"message",T:zl},{no:3,name:"source",kind:"enum",T:N.getEnumType(sn)},{no:8,name:"completion_parts",kind:"message",T:Yl,repeated:!0}])),je);const Ql={typeName:"exa.language_server_pb.LanguageServerService",methods:{getCompletions:{name:"GetCompletions",I:Rl,O:Gl,kind:ye.Unary},acceptCompletion:{name:"AcceptCompletion",I:Jl,O:Wl,kind:ye.Unary},getAuthToken:{name:"GetAuthToken",I:Vl,O:$l,kind:ye.Unary}}};function Zl(){try{new Headers}catch{throw Error("connect-web requires the fetch API. Are you running on an old version of Node.js? Node.js is not supported in Connect for Web - please stay tuned for Connect for Node.")}}var _t=function(e){return this instanceof _t?(this.v=e,this):new _t(e)},ec=function(e,t,n){if(!Symbol.asyncIterator)throw TypeError("Symbol.asyncIterator is not defined.");var r=n.apply(e,t||[]),o,a=[];return o={},s("next"),s("throw"),s("return",i),o[Symbol.asyncIterator]=function(){return this},o;function i(m){return function(g){return Promise.resolve(g).then(m,f)}}function s(m,g){r[m]&&(o[m]=function(y){return new Promise(function(w,k){a.push([m,y,w,k])>1||c(m,y)})},g&&(o[m]=g(o[m])))}function c(m,g){try{u(r[m](g))}catch(y){h(a[0][3],y)}}function u(m){m.value instanceof _t?Promise.resolve(m.value.v).then(d,f):h(a[0][2],m)}function d(m){c("next",m)}function f(m){c("throw",m)}function h(m,g){m(g),a.shift(),a.length&&c(a[0][0],a[0][1])}};function tc(e){Zl();let t=e.useBinaryFormat??!1;return{async unary(n,r,o,a,i,s,c){let{serialize:u,parse:d}=Go(r,t,e.jsonOptions,e.binaryOptions);return a=a===void 0?e.defaultTimeoutMs:a<=0?void 0:a,await jl({interceptors:e.interceptors,signal:o,timeoutMs:a,req:{stream:!1,service:n,method:r,url:jo(e.baseUrl,n,r),init:{method:"POST",credentials:e.credentials??"same-origin",redirect:"error",mode:"cors"},header:zo(r.kind,t,a,i,!1),contextValues:c??Bo(),message:s},next:async f=>{let h=e.useHttpGet===!0&&r.idempotency===Fo.NoSideEffects,m=null;h?f=Bl(f,u(f.message),t):m=u(f.message);let g=await(e.fetch??globalThis.fetch)(f.url,Object.assign(Object.assign({},f.init),{headers:f.header,signal:f.signal,body:m})),{isUnaryError:y,unaryError:w}=Ko(r.kind,t,g.status,g.headers);if(y)throw Vo(await g.json(),dl(...qo(g.headers)),w);let[k,C]=qo(g.headers);return{stream:!1,service:n,method:r,header:k,message:t?d(new Uint8Array(await g.arrayBuffer())):r.O.fromJson(await g.json(),Ro(e.jsonOptions)),trailer:C}}})},async stream(n,r,o,a,i,s,c){let{serialize:u,parse:d}=Go(r,t,e.jsonOptions,e.binaryOptions);function f(m,g,y,w){return ec(this,arguments,function*(){let k=ml(m).getReader(),C=!1;for(;;){let T=yield _t(k.read());if(T.done)break;let{flags:L,data:U}=T.value;if((L&1)==1)throw new he("protocol error: received unsupported compressed output",M.Internal);if((L&2)==2){C=!0;let A=Ol(U);if(A.error){let x=A.error;throw y.forEach((G,ee)=>{x.metadata.append(ee,G)}),x}A.metadata.forEach((x,G)=>g.set(G,x));continue}yield yield _t(d(U))}if("throwIfAborted"in w&&w.throwIfAborted(),!C)throw"missing EndStreamResponse"})}async function h(m){if(r.kind!=ye.ServerStreaming)throw"The fetch API does not support streaming request bodies";let g=await m[Symbol.asyncIterator]().next();if(g.done==1)throw"missing request message";return pl(0,u(g.value))}return a=a===void 0?e.defaultTimeoutMs:a<=0?void 0:a,await Pl({interceptors:e.interceptors,timeoutMs:a,signal:o,req:{stream:!0,service:n,method:r,url:jo(e.baseUrl,n,r),init:{method:"POST",credentials:e.credentials??"same-origin",redirect:"error",mode:"cors"},header:zo(r.kind,t,a,i,!1),contextValues:c??Bo(),message:s},next:async m=>{let g=await(e.fetch??globalThis.fetch)(m.url,Object.assign(Object.assign({},m.init),{headers:m.header,signal:m.signal,body:await h(m.message)}));if(Ko(r.kind,t,g.status,g.headers),g.body===null)throw"missing response body";let y=new Headers;return Object.assign(Object.assign({},m),{header:g.headers,trailer:y,message:f(g.body,y,g.headers,m.signal)})}})}}}var nc=Nl(Ql,tc({baseUrl:"https://web-backend.codeium.com",useBinaryFormat:!0})),pn;try{pn=crypto.randomUUID()}catch{pn=function(){return"10000000-1000-4000-8000-100000000000".replace(/[018]/g,t=>(t^(crypto.getRandomValues(new Uint8Array(1))[0]??0)&15>>t/4).toString(16))}()}async function rc({text:e,cursorOffset:t,config:n,otherDocuments:r}){return await nc.getCompletions({metadata:{ideName:"web",ideVersion:"0.0.5",extensionName:"@valtown/codemirror-codeium",extensionVersion:"1.0.0",apiKey:n.apiKey,sessionId:pn,authSource:n.authSource},document:{text:e,cursorOffset:BigInt(t),language:n.language,editorLanguage:"typescript",lineEnding:`
11
- `},editorOptions:{tabSize:2n,insertSpaces:!0},otherDocuments:r,multilineConfig:void 0},{headers:{Authorization:`Basic ${n.apiKey}-${pn}`}})}function oc(e){return e.completionItems.map(t=>{let n=0;return t.completionParts.filter(r=>r.type!==3).map(r=>{let o=Number(r.offset),a=r.type===2?`
12
- ${r.text}`:r.text,i={absoluteStartPos:n+o,absoluteEndPos:n+o+a.length,from:o,to:o,insert:a};return n+=a.length,i})})}async function ac(e,t){let n=e.state.facet(ln),{override:r}=e.state.facet(Oo),o=await r(),a=e.state,i=a.selection.main.head,s=a.doc.toString();try{let c=await rc({text:s,cursorOffset:i,config:n,otherDocuments:o});if(!c||c.completionItems.length===0||!((t===void 0||i===t)&&Gt(e.state)!=="active"&&e.hasFocus))return;let u=oc(c),d=u.at(0);if(!d)return;let f=Tn.of(d,a.doc.length),h=f.invert(a.doc);e.dispatch({changes:f,effects:Jn.of({index:0,reverseChangeSet:h,changeSpecs:u}),annotations:[cn.of(null),ht.of(null),Rt.addToHistory.of(!1)]})}catch(c){console.warn("copilot completion failed",c),await new Promise(u=>setTimeout(u,300))}}function ic(e){return e.docChanged&&!e.transactions.some(t=>t.effects.some(n=>n.is(Wn)||n.is(Vn)))}function sc(e){if(!e.view.hasFocus||e.state.field(st)||Gt(e.state)==="active")return!0;for(let t of e.transactions)if(t.annotation(ht)!==void 0)return!0}function lc(){let e=null,t=0;return B.updateListener.of(n=>{let r=n.view.state.facet(ln);if(!r.alwaysOn||!ic(n)||(e&&clearTimeout(e),sc(n)))return;let o=n.state.selection.main.head;r.shouldComplete&&!r.shouldComplete(new qf(n.view.state,o,!1))||(e=setTimeout(async()=>{o===t&&await ac(n.view,t)},r.timeout),t=o)})}function Zo(e){var o;let t=e.state.field(st);if(!t)return!1;let n=(o=t.reverseChangeSet)==null?void 0:o.invert(e.state.doc);e.dispatch({changes:t.reverseChangeSet,effects:Wn.of(null),annotations:[cn.of(null),ht.of(null),Rt.addToHistory.of(!1)]});let r=0;return n==null||n.iterChangedRanges((a,i,s,c)=>{r=c}),e.dispatch({changes:n,selection:vt.cursor(r),annotations:[ht.of(null),Rt.addToHistory.of(!0)]}),!0}const ea=e=>{let{state:t}=e,n=t.field(st);if(!n)return!1;let{changeSpecs:r}=n;if(r.length<2)return!1;let o=(n.index+1)%r.length,a=r.at(o);if(!a)return!1;let i=n.reverseChangeSet.apply(t.doc),s=Tn.of(n.reverseChangeSet,t.doc.length).compose(Tn.of(a,i.length)),c=Tn.of(a,i.length).invert(i);return e.dispatch({changes:s,effects:Jn.of({index:o,reverseChangeSet:c,changeSpecs:r}),annotations:[cn.of(null),ht.of(null),Rt.addToHistory.of(!1)]}),!0};function Zn(e){let t=e.state.field(st);return t&&e.dispatch({changes:t.reverseChangeSet,effects:Vn.of(null),annotations:[cn.of(null),ht.of(null),Rt.addToHistory.of(!1)]}),!1}function cc(e,t){return e.state.field(st)?t==="Tab"?Zo(e):Zn(e):!1}function uc(e){var o,a;let t=!1,n=(o=e.state.selection.asSingle().ranges.at(0))==null?void 0:o.head,r=e.state.field(st);return n!==void 0&&r?((a=r.decorations)==null||a.between(n,n,()=>{t=!0}),t):!1}function dc(){return B.domEventHandlers({keydown(e,t){return e.key==="]"&&e.ctrlKey?!1:e.key!=="Shift"&&e.key!=="Control"&&e.key!=="Alt"&&e.key!=="Meta"?cc(t,e.key):!1},mouseup(e,t){let n=e.target;return n.nodeName==="BUTTON"&&n.dataset.action==="codeium-cycle"?(ea(t),e.stopPropagation(),e.preventDefault(),!0):uc(t)?Zo(t):Zn(t)}})}function fc(){return Je.of([{key:"Ctrl-]",run:ea}])}function mc(){return B.updateListener.of(e=>{e.focusChanged&&Zn(e.view)})}function pc(e){return[ln.of(e),st,ut.highest(fc()),ut.highest(mc()),ut.high(dc()),lc()]}function hc({response:e,prefix:t,suffix:n}){if(!e)return e;let r=e;return t&&r.startsWith(t)&&(r=r.slice(t.length)),n&&r.endsWith(n)&&(r=r.slice(0,-n.length)),r}var gc=yd(),bc=new gf,er=$e.get("@github/copilot-language-server"),ta={delay:300,includeKeymap:!0,events:{shouldShowSuggestion:e=>e.hasFocus,beforeSuggestionFetch:e=>e.hasFocus}};const yc=e=>{let t=[];return e.copilot==="codeium"&&e.codeium_api_key&&t.push(pc({apiKey:e.codeium_api_key,language:it.PYTHON}),Oo.of({override:async()=>[{text:Er(""),language:it.PYTHON,editorLanguage:"python"}]})),e.copilot==="github"&&t.push(Yr({...ta,fetchFn:async(n,r,o)=>{let a=n.selection.main.head;if(!Hd()||!o.hasFocus||n.doc.length===0)return"";await new Promise(c=>setTimeout(c,20));let i=wc(n,Er(n.doc.toString())),s=await $d().getCompletion(i);return a===o.state.selection.main.head?vc(s,i.position,n):($e.debug("ignoring response because of new position"),"")}})),e.copilot==="custom"&&t.push(Yr({...ta,fetchFn:async(n,r,o)=>{let a=n.selection.main.head;if(n.doc.length===0||!o.hasFocus)return"";let i=n.doc.sliceString(0,n.selection.main.head),s=n.doc.sliceString(n.selection.main.head,n.doc.length);if(i.length===0)return"";let c=n.field(xn).type,u=await rf.post("/ai/inline_completion",{prefix:i,suffix:s,language:c});return a===o.state.selection.main.head?(u=hc({response:u,prefix:i,suffix:s}),u):($e.debug("ignoring response because of new position"),"")}})),[...t,ut.highest(Je.of([{key:"Escape",run:n=>{let r=Kr(n);return Cn(n)?!1:r}}])),bc.of(Vd())]};function wc(e,t){let n=e.doc.toString(),r=t.split(`
9
+ `.trim(),n=Za();await Qa();let r=await fetch(n.getAiURL("completion").toString(),{method:"POST",headers:n.headers(),body:JSON.stringify({prompt:e.prompt,code:t,selectedText:e.selection,includeOtherCode:"",language:e.language})}),o=((s=e.selection.match(/^\s*/))==null?void 0:s[0])||"",a=(c=r.body)==null?void 0:c.getReader();if(!a)throw Error("Failed to get response reader");let i="";for(;;){let{done:u,value:d}=await a.read();if(u)break;i+=new TextDecoder().decode(d)}return i.startsWith(o)||(i=o+i),i}var b=Da(of(),1),ls=["%alias","%cd","%clear","%debug","%env","%load","%load_ext","%lsmagic","%matplotlib","%pwd","%who_ls","%system","%%time","%%timeit","%%writefile","%%capture","%%html","%%latex"],Gn;function cs(){let e=async r=>{let o=Q.get(Tr),{saveUserConfig:a}=Vf();await a({config:{runtime:{auto_reload:r}}}).then(()=>Q.set(Tr,{...o,runtime:{...o.runtime,auto_reload:r}}))},t=[{match:"!pip install",onMatch:()=>{Q.set(Sr,r=>({...r,isSidebarOpen:!0,selectedPanel:"packages"})),Dr()},title:"Package Installation",description:(0,b.jsxs)(b.Fragment,{children:["The package manager sidebar has been opened.",(0,b.jsx)("br",{}),"Install packages directly from there instead."]})},{match:"!uv pip install",onMatch:()=>{Q.set(Sr,r=>({...r,isSidebarOpen:!0,selectedPanel:"packages"})),Dr()},title:"Package Installation",description:(0,b.jsxs)(b.Fragment,{children:["The package manager sidebar has been opened.",(0,b.jsx)("br",{}),"Install packages directly from there instead."]})},{match:"!uv add",onMatch:()=>{Q.set(Sr,r=>({...r,isSidebarOpen:!0,selectedPanel:"packages"})),Dr()},title:"Package Installation",description:(0,b.jsxs)(b.Fragment,{children:["The package manager sidebar has been opened.",(0,b.jsx)("br",{}),"Install packages directly from there instead."]})},{match:"%autoreload 2",onMatch:async()=>{await e("autorun")},title:"Module reload",description:(0,b.jsxs)(b.Fragment,{children:["Module reload mode set to ",(0,b.jsx)("b",{children:"autorun"})," - module changes will re-run the cells that import them."]})},{match:"%autoreload 1",onMatch:async()=>{await e("lazy")},title:"Module reload",description:(0,b.jsxs)(b.Fragment,{children:["Module reload mode set to ",(0,b.jsx)("b",{children:"lazy"})," - module changes will mark the cells that import them as stale."]})},{match:"%autoreload 0",onMatch:async()=>{await e("off")},title:"Module reload",description:(0,b.jsx)(b.Fragment,{children:"Module reload disabled - module changes will not be detected."})},{match:"!ls",onMatch:()=>{},title:"Listing files",description:(0,b.jsxs)(b.Fragment,{children:["Shell commands are not directly supported.",(0,b.jsx)("br",{}),"Use ",(0,b.jsx)("code",{children:"import subprocess; subprocess.run(['ls'])"})," instead."]})},...ls.map(r=>({match:r,onMatch:()=>{},title:(0,b.jsx)(Cm,{className:"inline",children:r}),description:(0,b.jsxs)(b.Fragment,{children:["Magic commands are not supported in marimo. Read more about replacements in the"," ",(0,b.jsx)("a",{href:"https://docs.marimo.io/guides/coming_from/jupyter/#adapting-to-the-absence-of-magic-commands",target:"_blank",className:"text-link underline cursor-pointer",rel:"noopener noreferrer",children:"documentation"}),"."]})}))],n=new Map(t.map(r=>[r.match,r]));return B.updateListener.of(r=>{if(r.docChanged){let o=r.state.selection.main,a=r.state.doc,i=a.lineAt(o.head),s=a.sliceString(i.from,o.anchor).trim(),c=n.get(s);c&&(c.onMatch(),Gn?Gn.upsert({title:c.title,description:c.description}):Gn=vt({title:c.title,description:c.description}))}})}var us=new Set(["Escape","Alt-`"]);function ds(){let e=Mf.filter(t=>!us.has(t.key));return ut.highest(Je.of([...e,{key:"Ctrl-y",run:t=>Cn(t)?oi(t):!1},{key:"Ctrl-n",run:t=>Cn(t)?Ln(!0)(t):!1},{key:"Ctrl-p",run:t=>Cn(t)?Ln(!1)(t):!1}]))}const Jn=pe.define(),Wn=pe.define(),Vn=pe.define();function z(e,t){if(!e)throw Error(t)}var fs=3402823466385289e23,ms=-3402823466385289e23,ps=4294967295,hs=2147483647,gs=-2147483648;function zt(e){if(typeof e!="number")throw Error("invalid int 32: "+typeof e);if(!Number.isInteger(e)||e>hs||e<gs)throw Error("invalid int 32: "+e)}function $n(e){if(typeof e!="number")throw Error("invalid uint 32: "+typeof e);if(!Number.isInteger(e)||e>ps||e<0)throw Error("invalid uint 32: "+e)}function Qr(e){if(typeof e!="number")throw Error("invalid float 32: "+typeof e);if(Number.isFinite(e)&&(e>fs||e<ms))throw Error("invalid float 32: "+e)}var Zr=Symbol("@bufbuild/protobuf/enum-type");function bs(e){let t=e[Zr];return z(t,"missing enum type on enum object"),t}function eo(e,t,n,r){e[Zr]=to(t,n.map(o=>({no:o.no,name:o.name,localName:e[o.no]})),r)}function to(e,t,n){let r=Object.create(null),o=Object.create(null),a=[];for(let i of t){let s=no(i);a.push(s),r[i.name]=s,o[i.no]=s}return{typeName:e,values:a,findName(i){return r[i]},findNumber(i){return o[i]}}}function ys(e,t,n){let r={};for(let o of t){let a=no(o);r[a.localName]=a.no,r[a.no]=a.localName}return eo(r,e,t,n),r}function no(e){return"localName"in e?e:Object.assign(Object.assign({},e),{localName:e.name})}var X=class{equals(e){return this.getType().runtime.util.equals(this.getType(),this,e)}clone(){return this.getType().runtime.util.clone(this)}fromBinary(e,t){let n=this.getType().runtime.bin,r=n.makeReadOptions(t);return n.readMessage(this,r.readerFactory(e),e.byteLength,r),this}fromJson(e,t){let n=this.getType(),r=n.runtime.json,o=r.makeReadOptions(t);return r.readMessage(n,e,o,this),this}fromJsonString(e,t){let n;try{n=JSON.parse(e)}catch(r){throw Error(`cannot decode ${this.getType().typeName} from JSON: ${r instanceof Error?r.message:String(r)}`)}return this.fromJson(n,t)}toBinary(e){let t=this.getType().runtime.bin,n=t.makeWriteOptions(e),r=n.writerFactory();return t.writeMessage(this,r,n),r.finish()}toJson(e){let t=this.getType().runtime.json,n=t.makeWriteOptions(e);return t.writeMessage(this,n)}toJsonString(e){let t=this.toJson(e);return JSON.stringify(t,null,(e==null?void 0:e.prettySpaces)??0)}toJSON(){return this.toJson({emitDefaultValues:!0})}getType(){return Object.getPrototypeOf(this).constructor}};function ws(e,t,n,r){let o=(r==null?void 0:r.localName)??t.substring(t.lastIndexOf(".")+1),a={[o]:function(i){e.util.initFields(this),e.util.initPartial(i,this)}}[o];return Object.setPrototypeOf(a.prototype,new X),Object.assign(a,{runtime:e,typeName:t,fields:e.util.newFieldList(n),fromBinary(i,s){return new a().fromBinary(i,s)},fromJson(i,s){return new a().fromJson(i,s)},fromJsonString(i,s){return new a().fromJsonString(i,s)},equals(i,s){return e.util.equals(a,i,s)}}),a}function vs(){let e=0,t=0;for(let r=0;r<28;r+=7){let o=this.buf[this.pos++];if(e|=(o&127)<<r,!(o&128))return this.assertBounds(),[e,t]}let n=this.buf[this.pos++];if(e|=(n&15)<<28,t=(n&112)>>4,!(n&128))return this.assertBounds(),[e,t];for(let r=3;r<=31;r+=7){let o=this.buf[this.pos++];if(t|=(o&127)<<r,!(o&128))return this.assertBounds(),[e,t]}throw Error("invalid varint")}function Hn(e,t,n){for(let a=0;a<28;a+=7){let i=e>>>a,s=!(!(i>>>7)&&t==0),c=(s?i|128:i)&255;if(n.push(c),!s)return}let r=e>>>28&15|(t&7)<<4,o=!!(t>>3);if(n.push((o?r|128:r)&255),o){for(let a=3;a<31;a+=7){let i=t>>>a,s=!!(i>>>7),c=(s?i|128:i)&255;if(n.push(c),!s)return}n.push(t>>>31&1)}}var Kt=4294967296;function ro(e){let t=e[0]==="-";t&&(e=e.slice(1));let n=1e6,r=0,o=0;function a(i,s){let c=Number(e.slice(i,s));o*=n,r=r*n+c,r>=Kt&&(o+=r/Kt|0,r%=Kt)}return a(-24,-18),a(-18,-12),a(-12,-6),a(-6),t?ao(r,o):qn(r,o)}function Es(e,t){let n=qn(e,t),r=n.hi&2147483648;r&&(n=ao(n.lo,n.hi));let o=oo(n.lo,n.hi);return r?"-"+o:o}function oo(e,t){if({lo:e,hi:t}=Ns(e,t),t<=2097151)return String(Kt*t+e);let n=e&16777215,r=(e>>>24|t<<8)&16777215,o=t>>16&65535,a=n+r*6777216+o*6710656,i=r+o*8147497,s=o*2,c=1e7;return a>=c&&(i+=Math.floor(a/c),a%=c),i>=c&&(s+=Math.floor(i/c),i%=c),s.toString()+io(i)+io(a)}function Ns(e,t){return{lo:e>>>0,hi:t>>>0}}function qn(e,t){return{lo:e|0,hi:t|0}}function ao(e,t){return t=~t,e?e=~e+1:t+=1,qn(e,t)}var io=e=>{let t=String(e);return"0000000".slice(t.length)+t};function so(e,t){if(e>=0){for(;e>127;)t.push(e&127|128),e>>>=7;t.push(e)}else{for(let n=0;n<9;n++)t.push(e&127|128),e>>=7;t.push(1)}}function ks(){let e=this.buf[this.pos++],t=e&127;if(!(e&128)||(e=this.buf[this.pos++],t|=(e&127)<<7,!(e&128))||(e=this.buf[this.pos++],t|=(e&127)<<14,!(e&128))||(e=this.buf[this.pos++],t|=(e&127)<<21,!(e&128)))return this.assertBounds(),t;e=this.buf[this.pos++],t|=(e&15)<<28;for(let n=5;e&128&&n<10;n++)e=this.buf[this.pos++];if(e&128)throw Error("invalid varint");return this.assertBounds(),t>>>0}function Cs(){let e=new DataView(new ArrayBuffer(8));if(typeof BigInt=="function"&&typeof e.getBigInt64=="function"&&typeof e.getBigUint64=="function"&&typeof e.setBigInt64=="function"&&typeof e.setBigUint64=="function"&&(typeof process!="object"||{}.BUF_BIGINT_DISABLE!=="1")){let r=BigInt("-9223372036854775808"),o=BigInt("9223372036854775807"),a=BigInt("0"),i=BigInt("18446744073709551615");return{zero:BigInt(0),supported:!0,parse(s){let c=typeof s=="bigint"?s:BigInt(s);if(c>o||c<r)throw Error(`int64 invalid: ${s}`);return c},uParse(s){let c=typeof s=="bigint"?s:BigInt(s);if(c>i||c<a)throw Error(`uint64 invalid: ${s}`);return c},enc(s){return e.setBigInt64(0,this.parse(s),!0),{lo:e.getInt32(0,!0),hi:e.getInt32(4,!0)}},uEnc(s){return e.setBigInt64(0,this.uParse(s),!0),{lo:e.getInt32(0,!0),hi:e.getInt32(4,!0)}},dec(s,c){return e.setInt32(0,s,!0),e.setInt32(4,c,!0),e.getBigInt64(0,!0)},uDec(s,c){return e.setInt32(0,s,!0),e.setInt32(4,c,!0),e.getBigUint64(0,!0)}}}let t=r=>z(/^-?[0-9]+$/.test(r),`int64 invalid: ${r}`),n=r=>z(/^[0-9]+$/.test(r),`uint64 invalid: ${r}`);return{zero:"0",supported:!1,parse(r){return typeof r!="string"&&(r=r.toString()),t(r),r},uParse(r){return typeof r!="string"&&(r=r.toString()),n(r),r},enc(r){return typeof r!="string"&&(r=r.toString()),t(r),ro(r)},uEnc(r){return typeof r!="string"&&(r=r.toString()),n(r),ro(r)},dec(r,o){return Es(r,o)},uDec(r,o){return oo(r,o)}}}const J=Cs();var v;(function(e){e[e.DOUBLE=1]="DOUBLE",e[e.FLOAT=2]="FLOAT",e[e.INT64=3]="INT64",e[e.UINT64=4]="UINT64",e[e.INT32=5]="INT32",e[e.FIXED64=6]="FIXED64",e[e.FIXED32=7]="FIXED32",e[e.BOOL=8]="BOOL",e[e.STRING=9]="STRING",e[e.BYTES=12]="BYTES",e[e.UINT32=13]="UINT32",e[e.SFIXED32=15]="SFIXED32",e[e.SFIXED64=16]="SFIXED64",e[e.SINT32=17]="SINT32",e[e.SINT64=18]="SINT64"})(v||(v={}));var at;(function(e){e[e.BIGINT=0]="BIGINT",e[e.STRING=1]="STRING"})(at||(at={}));function Ze(e,t,n){if(t===n)return!0;if(e==v.BYTES){if(!(t instanceof Uint8Array)||!(n instanceof Uint8Array)||t.length!==n.length)return!1;for(let r=0;r<t.length;r++)if(t[r]!==n[r])return!1;return!0}switch(e){case v.UINT64:case v.FIXED64:case v.INT64:case v.SFIXED64:case v.SINT64:return t==n}return!1}function mt(e,t){switch(e){case v.BOOL:return!1;case v.UINT64:case v.FIXED64:case v.INT64:case v.SFIXED64:case v.SINT64:return t==0?J.zero:"0";case v.DOUBLE:case v.FLOAT:return 0;case v.BYTES:return new Uint8Array;case v.STRING:return"";default:return 0}}function lo(e,t){switch(e){case v.BOOL:return t===!1;case v.STRING:return t==="";case v.BYTES:return t instanceof Uint8Array&&!t.byteLength;default:return t==0}}var Z;(function(e){e[e.Varint=0]="Varint",e[e.Bit64=1]="Bit64",e[e.LengthDelimited=2]="LengthDelimited",e[e.StartGroup=3]="StartGroup",e[e.EndGroup=4]="EndGroup",e[e.Bit32=5]="Bit32"})(Z||(Z={}));var Ss=class{constructor(e){this.stack=[],this.textEncoder=e??new TextEncoder,this.chunks=[],this.buf=[]}finish(){this.chunks.push(new Uint8Array(this.buf));let e=0;for(let r=0;r<this.chunks.length;r++)e+=this.chunks[r].length;let t=new Uint8Array(e),n=0;for(let r=0;r<this.chunks.length;r++)t.set(this.chunks[r],n),n+=this.chunks[r].length;return this.chunks=[],t}fork(){return this.stack.push({chunks:this.chunks,buf:this.buf}),this.chunks=[],this.buf=[],this}join(){let e=this.finish(),t=this.stack.pop();if(!t)throw Error("invalid state, fork stack empty");return this.chunks=t.chunks,this.buf=t.buf,this.uint32(e.byteLength),this.raw(e)}tag(e,t){return this.uint32((e<<3|t)>>>0)}raw(e){return this.buf.length&&(this.chunks.push(new Uint8Array(this.buf)),this.buf=[]),this.chunks.push(e),this}uint32(e){for($n(e);e>127;)this.buf.push(e&127|128),e>>>=7;return this.buf.push(e),this}int32(e){return zt(e),so(e,this.buf),this}bool(e){return this.buf.push(e?1:0),this}bytes(e){return this.uint32(e.byteLength),this.raw(e)}string(e){let t=this.textEncoder.encode(e);return this.uint32(t.byteLength),this.raw(t)}float(e){Qr(e);let t=new Uint8Array(4);return new DataView(t.buffer).setFloat32(0,e,!0),this.raw(t)}double(e){let t=new Uint8Array(8);return new DataView(t.buffer).setFloat64(0,e,!0),this.raw(t)}fixed32(e){$n(e);let t=new Uint8Array(4);return new DataView(t.buffer).setUint32(0,e,!0),this.raw(t)}sfixed32(e){zt(e);let t=new Uint8Array(4);return new DataView(t.buffer).setInt32(0,e,!0),this.raw(t)}sint32(e){return zt(e),e=(e<<1^e>>31)>>>0,so(e,this.buf),this}sfixed64(e){let t=new Uint8Array(8),n=new DataView(t.buffer),r=J.enc(e);return n.setInt32(0,r.lo,!0),n.setInt32(4,r.hi,!0),this.raw(t)}fixed64(e){let t=new Uint8Array(8),n=new DataView(t.buffer),r=J.uEnc(e);return n.setInt32(0,r.lo,!0),n.setInt32(4,r.hi,!0),this.raw(t)}int64(e){let t=J.enc(e);return Hn(t.lo,t.hi,this.buf),this}sint64(e){let t=J.enc(e),n=t.hi>>31;return Hn(t.lo<<1^n,(t.hi<<1|t.lo>>>31)^n,this.buf),this}uint64(e){let t=J.uEnc(e);return Hn(t.lo,t.hi,this.buf),this}},xs=class{constructor(e,t){this.varint64=vs,this.uint32=ks,this.buf=e,this.len=e.length,this.pos=0,this.view=new DataView(e.buffer,e.byteOffset,e.byteLength),this.textDecoder=t??new TextDecoder}tag(){let e=this.uint32(),t=e>>>3,n=e&7;if(t<=0||n<0||n>5)throw Error("illegal tag: field no "+t+" wire type "+n);return[t,n]}skip(e,t){let n=this.pos;switch(e){case Z.Varint:for(;this.buf[this.pos++]&128;);break;case Z.Bit64:this.pos+=4;case Z.Bit32:this.pos+=4;break;case Z.LengthDelimited:let r=this.uint32();this.pos+=r;break;case Z.StartGroup:for(;;){let[o,a]=this.tag();if(a===Z.EndGroup){if(t!==void 0&&o!==t)throw Error("invalid end group tag");break}this.skip(a,o)}break;default:throw Error("cant skip wire type "+e)}return this.assertBounds(),this.buf.subarray(n,this.pos)}assertBounds(){if(this.pos>this.len)throw RangeError("premature EOF")}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)}int64(){return J.dec(...this.varint64())}uint64(){return J.uDec(...this.varint64())}sint64(){let[e,t]=this.varint64(),n=-(e&1);return e=(e>>>1|(t&1)<<31)^n,t=t>>>1^n,J.dec(e,t)}bool(){let[e,t]=this.varint64();return e!==0||t!==0}fixed32(){return this.view.getUint32((this.pos+=4)-4,!0)}sfixed32(){return this.view.getInt32((this.pos+=4)-4,!0)}fixed64(){return J.uDec(this.sfixed32(),this.sfixed32())}sfixed64(){return J.dec(this.sfixed32(),this.sfixed32())}float(){return this.view.getFloat32((this.pos+=4)-4,!0)}double(){return this.view.getFloat64((this.pos+=8)-8,!0)}bytes(){let e=this.uint32(),t=this.pos;return this.pos+=e,this.assertBounds(),this.buf.subarray(t,t+e)}string(){return this.textDecoder.decode(this.bytes())}};function As(e,t,n,r){let o;return{typeName:t,extendee:n,get field(){if(!o){let a=typeof r=="function"?r():r;a.name=t.split(".").pop(),a.jsonName=`[${t}]`,o=e.util.newFieldList([a]).list()[0]}return o},runtime:e}}function co(e){let t=e.field.localName,n=Object.create(null);return n[t]=Ts(e),[n,()=>n[t]]}function Ts(e){let t=e.field;if(t.repeated)return[];if(t.default!==void 0)return t.default;switch(t.kind){case"enum":return t.T.values[0].no;case"scalar":return mt(t.T,t.L);case"message":let n=t.T,r=new n;return n.fieldWrapper?n.fieldWrapper.unwrapField(r):r;case"map":throw"map fields are not allowed to be extensions"}}function Is(e,t){if(!t.repeated&&(t.kind=="enum"||t.kind=="scalar")){for(let n=e.length-1;n>=0;--n)if(e[n].no==t.no)return[e[n]];return[]}return e.filter(n=>n.no===t.no)}var Ke="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split(""),Yt=[];for(let e=0;e<Ke.length;e++)Yt[Ke[e].charCodeAt(0)]=e;Yt[45]=Ke.indexOf("+"),Yt[95]=Ke.indexOf("/");const Xt={dec(e){let t=e.length*3/4;e[e.length-2]=="="?t-=2:e[e.length-1]=="="&&--t;let n=new Uint8Array(t),r=0,o=0,a,i=0;for(let s=0;s<e.length;s++){if(a=Yt[e.charCodeAt(s)],a===void 0)switch(e[s]){case"=":o=0;case`
10
+ `:case"\r":case" ":case" ":continue;default:throw Error("invalid base64 string.")}switch(o){case 0:i=a,o=1;break;case 1:n[r++]=i<<2|(a&48)>>4,i=a,o=2;break;case 2:n[r++]=(i&15)<<4|(a&60)>>2,i=a,o=3;break;case 3:n[r++]=(i&3)<<6|a,o=0;break}}if(o==1)throw Error("invalid base64 string.");return n.subarray(0,r)},enc(e){let t="",n=0,r,o=0;for(let a=0;a<e.length;a++)switch(r=e[a],n){case 0:t+=Ke[r>>2],o=(r&3)<<4,n=1;break;case 1:t+=Ke[o|r>>4],o=(r&15)<<2,n=2;break;case 2:t+=Ke[o|r>>6],t+=Ke[r&63],n=0;break}return n&&(t+=Ke[o],t+="=",n==1&&(t+="=")),t}};function Fs(e,t,n){fo(t,e);let r=t.runtime.bin.makeReadOptions(n),o=Is(e.getType().runtime.bin.listUnknownFields(e),t.field),[a,i]=co(t);for(let s of o)t.runtime.bin.readField(a,r.readerFactory(s.data),t.field,s.wireType,r);return i()}function Ls(e,t,n,r){fo(t,e);let o=t.runtime.bin.makeReadOptions(r),a=t.runtime.bin.makeWriteOptions(r);if(uo(e,t)){let u=e.getType().runtime.bin.listUnknownFields(e).filter(d=>d.no!=t.field.no);e.getType().runtime.bin.discardUnknownFields(e);for(let d of u)e.getType().runtime.bin.onUnknownField(e,d.no,d.wireType,d.data)}let i=a.writerFactory(),s=t.field;!s.opt&&!s.repeated&&(s.kind=="enum"||s.kind=="scalar")&&(s=Object.assign(Object.assign({},t.field),{opt:!0})),t.runtime.bin.writeField(s,n,i,a);let c=o.readerFactory(i.finish());for(;c.pos<c.len;){let[u,d]=c.tag(),f=c.skip(d,u);e.getType().runtime.bin.onUnknownField(e,u,d,f)}}function uo(e,t){let n=e.getType();return t.extendee.typeName===n.typeName&&!!n.runtime.bin.listUnknownFields(e).find(r=>r.no==t.field.no)}function fo(e,t){z(e.extendee.typeName==t.getType().typeName,`extension ${e.typeName} can only be applied to message ${e.extendee.typeName}`)}function mo(e,t){let n=e.localName;if(e.repeated)return t[n].length>0;if(e.oneof)return t[e.oneof.localName].case===n;switch(e.kind){case"enum":case"scalar":return e.opt||e.req?t[n]!==void 0:e.kind=="enum"?t[n]!==e.T.values[0].no:!lo(e.T,t[n]);case"message":return t[n]!==void 0;case"map":return Object.keys(t[n]).length>0}}function po(e,t){let n=e.localName,r=!e.opt&&!e.req;if(e.repeated)t[n]=[];else if(e.oneof)t[e.oneof.localName]={case:void 0};else switch(e.kind){case"map":t[n]={};break;case"enum":t[n]=r?e.T.values[0].no:void 0;break;case"scalar":t[n]=r?mt(e.T,e.L):void 0;break;case"message":t[n]=void 0;break}}function Ye(e,t){if(typeof e!="object"||!e||!Object.getOwnPropertyNames(X.prototype).every(r=>r in e&&typeof e[r]=="function"))return!1;let n=e.getType();return n===null||typeof n!="function"||!("typeName"in n)||typeof n.typeName!="string"?!1:t===void 0?!0:n.typeName==t.typeName}function ho(e,t){return Ye(t)||!e.fieldWrapper?t:e.fieldWrapper.wrapField(t)}v.DOUBLE,v.FLOAT,v.INT64,v.UINT64,v.INT32,v.UINT32,v.BOOL,v.STRING,v.BYTES;var go={ignoreUnknownFields:!1},bo={emitDefaultValues:!1,enumAsInteger:!1,useProtoFieldName:!1,prettySpaces:0};function Os(e){return e?Object.assign(Object.assign({},go),e):go}function Ds(e){return e?Object.assign(Object.assign({},bo),e):bo}var Qt=Symbol(),Zt=Symbol();function _s(){return{makeReadOptions:Os,makeWriteOptions:Ds,readMessage(e,t,n,r){if(t==null||Array.isArray(t)||typeof t!="object")throw Error(`cannot decode message ${e.typeName} from JSON: ${We(t)}`);r??(r=new e);let o=new Map,a=n.typeRegistry;for(let[i,s]of Object.entries(t)){let c=e.fields.findJsonName(i);if(c){if(c.oneof){if(s===null&&c.kind=="scalar")continue;let u=o.get(c.oneof);if(u!==void 0)throw Error(`cannot decode message ${e.typeName} from JSON: multiple keys for oneof "${c.oneof.name}" present: "${u}", "${i}"`);o.set(c.oneof,i)}yo(r,s,c,n,e)}else{let u=!1;if(a!=null&&a.findExtension&&i.startsWith("[")&&i.endsWith("]")){let d=a.findExtension(i.substring(1,i.length-1));if(d&&d.extendee.typeName==e.typeName){u=!0;let[f,h]=co(d);yo(f,s,d.field,n,d),Ls(r,d,h(),n)}}if(!u&&!n.ignoreUnknownFields)throw Error(`cannot decode message ${e.typeName} from JSON: key "${i}" is unknown`)}}return r},writeMessage(e,t){let n=e.getType(),r={},o;try{for(o of n.fields.byNumber()){if(!mo(o,e)){if(o.req)throw"required field not set";if(!t.emitDefaultValues||!Bs(o))continue}let i=o.oneof?e[o.oneof.localName].value:e[o.localName],s=wo(o,i,t);s!==void 0&&(r[t.useProtoFieldName?o.name:o.jsonName]=s)}let a=t.typeRegistry;if(a!=null&&a.findExtensionFor)for(let i of n.runtime.bin.listUnknownFields(e)){let s=a.findExtensionFor(n.typeName,i.no);if(s&&uo(e,s)){let c=Fs(e,s,t),u=wo(s.field,c,t);u!==void 0&&(r[s.field.jsonName]=u)}}}catch(a){let i=o?`cannot encode field ${n.typeName}.${o.name} to JSON`:`cannot encode message ${n.typeName} to JSON`,s=a instanceof Error?a.message:String(a);throw Error(i+(s.length>0?`: ${s}`:""))}return r},readScalar(e,t,n){return It(e,t,n??at.BIGINT,!0)},writeScalar(e,t,n){if(t!==void 0&&(n||lo(e,t)))return en(e,t)},debug:We}}function We(e){if(e===null)return"null";switch(typeof e){case"object":return Array.isArray(e)?"array":"object";case"string":return e.length>100?"string":`"${e.split('"').join('\\"')}"`;default:return String(e)}}function yo(e,t,n,r,o){let a=n.localName;if(n.repeated){if(z(n.kind!="map"),t===null)return;if(!Array.isArray(t))throw Error(`cannot decode field ${o.typeName}.${n.name} from JSON: ${We(t)}`);let i=e[a];for(let s of t){if(s===null)throw Error(`cannot decode field ${o.typeName}.${n.name} from JSON: ${We(s)}`);switch(n.kind){case"message":i.push(n.T.fromJson(s,r));break;case"enum":let c=zn(n.T,s,r.ignoreUnknownFields,!0);c!==Zt&&i.push(c);break;case"scalar":try{i.push(It(n.T,s,n.L,!0))}catch(u){let d=`cannot decode field ${o.typeName}.${n.name} from JSON: ${We(s)}`;throw u instanceof Error&&u.message.length>0&&(d+=`: ${u.message}`),Error(d)}break}}}else if(n.kind=="map"){if(t===null)return;if(typeof t!="object"||Array.isArray(t))throw Error(`cannot decode field ${o.typeName}.${n.name} from JSON: ${We(t)}`);let i=e[a];for(let[s,c]of Object.entries(t)){if(c===null)throw Error(`cannot decode field ${o.typeName}.${n.name} from JSON: map value null`);let u;try{u=Us(n.K,s)}catch(d){let f=`cannot decode map key for field ${o.typeName}.${n.name} from JSON: ${We(t)}`;throw d instanceof Error&&d.message.length>0&&(f+=`: ${d.message}`),Error(f)}switch(n.V.kind){case"message":i[u]=n.V.T.fromJson(c,r);break;case"enum":let d=zn(n.V.T,c,r.ignoreUnknownFields,!0);d!==Zt&&(i[u]=d);break;case"scalar":try{i[u]=It(n.V.T,c,at.BIGINT,!0)}catch(f){let h=`cannot decode map value for field ${o.typeName}.${n.name} from JSON: ${We(t)}`;throw f instanceof Error&&f.message.length>0&&(h+=`: ${f.message}`),Error(h)}break}}}else switch(n.oneof&&(e=e[n.oneof.localName]={case:a},a="value"),n.kind){case"message":let i=n.T;if(t===null&&i.typeName!="google.protobuf.Value")return;let s=e[a];Ye(s)?s.fromJson(t,r):(e[a]=s=i.fromJson(t,r),i.fieldWrapper&&!n.oneof&&(e[a]=i.fieldWrapper.unwrapField(s)));break;case"enum":let c=zn(n.T,t,r.ignoreUnknownFields,!1);switch(c){case Qt:po(n,e);break;case Zt:break;default:e[a]=c;break}break;case"scalar":try{let u=It(n.T,t,n.L,!1);u===Qt?po(n,e):e[a]=u}catch(u){let d=`cannot decode field ${o.typeName}.${n.name} from JSON: ${We(t)}`;throw u instanceof Error&&u.message.length>0&&(d+=`: ${u.message}`),Error(d)}break}}function Us(e,t){if(e===v.BOOL)switch(t){case"true":t=!0;break;case"false":t=!1;break}return It(e,t,at.BIGINT,!0).toString()}function It(e,t,n,r){if(t===null)return r?mt(e,n):Qt;switch(e){case v.DOUBLE:case v.FLOAT:if(t==="NaN")return NaN;if(t==="Infinity")return 1/0;if(t==="-Infinity")return-1/0;if(t===""||typeof t=="string"&&t.trim().length!==t.length||typeof t!="string"&&typeof t!="number")break;let o=Number(t);if(Number.isNaN(o)||!Number.isFinite(o))break;return e==v.FLOAT&&Qr(o),o;case v.INT32:case v.FIXED32:case v.SFIXED32:case v.SINT32:case v.UINT32:let a;if(typeof t=="number"?a=t:typeof t=="string"&&t.length>0&&t.trim().length===t.length&&(a=Number(t)),a===void 0)break;return e==v.UINT32||e==v.FIXED32?$n(a):zt(a),a;case v.INT64:case v.SFIXED64:case v.SINT64:if(typeof t!="number"&&typeof t!="string")break;let i=J.parse(t);return n?i.toString():i;case v.FIXED64:case v.UINT64:if(typeof t!="number"&&typeof t!="string")break;let s=J.uParse(t);return n?s.toString():s;case v.BOOL:if(typeof t!="boolean")break;return t;case v.STRING:if(typeof t!="string")break;return t;case v.BYTES:if(t==="")return new Uint8Array;if(typeof t!="string")break;return Xt.dec(t)}throw Error()}function zn(e,t,n,r){if(t===null)return e.typeName=="google.protobuf.NullValue"?0:r?e.values[0].no:Qt;switch(typeof t){case"number":if(Number.isInteger(t))return t;break;case"string":let o=e.findName(t);if(o!==void 0)return o.no;if(n)return Zt;break}throw Error(`cannot decode enum ${e.typeName} from JSON: ${We(t)}`)}function Bs(e){return e.repeated||e.kind=="map"?!0:!(e.oneof||e.kind=="message"||e.opt||e.req)}function wo(e,t,n){if(e.kind=="map"){z(typeof t=="object"&&!!t);let r={},o=Object.entries(t);switch(e.V.kind){case"scalar":for(let[i,s]of o)r[i.toString()]=en(e.V.T,s);break;case"message":for(let[i,s]of o)r[i.toString()]=s.toJson(n);break;case"enum":let a=e.V.T;for(let[i,s]of o)r[i.toString()]=Kn(a,s,n.enumAsInteger);break}return n.emitDefaultValues||o.length>0?r:void 0}if(e.repeated){z(Array.isArray(t));let r=[];switch(e.kind){case"scalar":for(let o=0;o<t.length;o++)r.push(en(e.T,t[o]));break;case"enum":for(let o=0;o<t.length;o++)r.push(Kn(e.T,t[o],n.enumAsInteger));break;case"message":for(let o=0;o<t.length;o++)r.push(t[o].toJson(n));break}return n.emitDefaultValues||r.length>0?r:void 0}switch(e.kind){case"scalar":return en(e.T,t);case"enum":return Kn(e.T,t,n.enumAsInteger);case"message":return ho(e.T,t).toJson(n)}}function Kn(e,t,n){var r;return z(typeof t=="number"),e.typeName=="google.protobuf.NullValue"?null:n?t:((r=e.findNumber(t))==null?void 0:r.name)??t}function en(e,t){switch(e){case v.INT32:case v.SFIXED32:case v.SINT32:case v.FIXED32:case v.UINT32:return z(typeof t=="number"),t;case v.FLOAT:case v.DOUBLE:return z(typeof t=="number"),Number.isNaN(t)?"NaN":t===1/0?"Infinity":t===-1/0?"-Infinity":t;case v.STRING:return z(typeof t=="string"),t;case v.BOOL:return z(typeof t=="boolean"),t;case v.UINT64:case v.FIXED64:case v.INT64:case v.SFIXED64:case v.SINT64:return z(typeof t=="bigint"||typeof t=="string"||typeof t=="number"),t.toString();case v.BYTES:return z(t instanceof Uint8Array),Xt.enc(t)}}var pt=Symbol("@bufbuild/protobuf/unknown-fields"),vo={readUnknownFields:!0,readerFactory:e=>new xs(e)},Eo={writeUnknownFields:!0,writerFactory:()=>new Ss};function js(e){return e?Object.assign(Object.assign({},vo),e):vo}function Ps(e){return e?Object.assign(Object.assign({},Eo),e):Eo}function Ms(){return{makeReadOptions:js,makeWriteOptions:Ps,listUnknownFields(e){return e[pt]??[]},discardUnknownFields(e){delete e[pt]},writeUnknownFields(e,t){let n=e[pt];if(n)for(let r of n)t.tag(r.no,r.wireType).raw(r.data)},onUnknownField(e,t,n,r){let o=e;Array.isArray(o[pt])||(o[pt]=[]),o[pt].push({no:t,wireType:n,data:r})},readMessage(e,t,n,r,o){let a=e.getType(),i=o?t.len:t.pos+n,s,c;for(;t.pos<i&&([s,c]=t.tag(),!(o===!0&&c==Z.EndGroup));){let u=a.fields.find(s);if(!u){let d=t.skip(c,s);r.readUnknownFields&&this.onUnknownField(e,s,c,d);continue}No(e,t,u,c,r)}if(o&&(c!=Z.EndGroup||s!==n))throw Error("invalid end group tag")},readField:No,writeMessage(e,t,n){let r=e.getType();for(let o of r.fields.byNumber()){if(!mo(o,e)){if(o.req)throw Error(`cannot encode field ${r.typeName}.${o.name} to binary: required field not set`);continue}ko(o,o.oneof?e[o.oneof.localName].value:e[o.localName],t,n)}return n.writeUnknownFields&&this.writeUnknownFields(e,t),t},writeField(e,t,n,r){t!==void 0&&ko(e,t,n,r)}}}function No(e,t,n,r,o){let{repeated:a,localName:i}=n;switch(n.oneof&&(e=e[n.oneof.localName],e.case!=i&&delete e.value,e.case=i,i="value"),n.kind){case"scalar":case"enum":let s=n.kind=="enum"?v.INT32:n.T,c=nn;if(n.kind=="scalar"&&n.L>0&&(c=Gs),a){let h=e[i];if(r==Z.LengthDelimited&&s!=v.STRING&&s!=v.BYTES){let m=t.uint32()+t.pos;for(;t.pos<m;)h.push(c(t,s))}else h.push(c(t,s))}else e[i]=c(t,s);break;case"message":let u=n.T;a?e[i].push(tn(t,new u,o,n)):Ye(e[i])?tn(t,e[i],o,n):(e[i]=tn(t,new u,o,n),u.fieldWrapper&&!n.oneof&&!n.repeated&&(e[i]=u.fieldWrapper.unwrapField(e[i])));break;case"map":let[d,f]=Rs(n,t,o);e[i][d]=f;break}}function tn(e,t,n,r){let o=t.getType().runtime.bin,a=r==null?void 0:r.delimited;return o.readMessage(t,e,a?r.no:e.uint32(),n,a),t}function Rs(e,t,n){let r=t.uint32(),o=t.pos+r,a,i;for(;t.pos<o;){let[s]=t.tag();switch(s){case 1:a=nn(t,e.K);break;case 2:switch(e.V.kind){case"scalar":i=nn(t,e.V.T);break;case"enum":i=t.int32();break;case"message":i=tn(t,new e.V.T,n,void 0);break}break}}if(a===void 0&&(a=mt(e.K,at.BIGINT)),typeof a!="string"&&typeof a!="number"&&(a=a.toString()),i===void 0)switch(e.V.kind){case"scalar":i=mt(e.V.T,at.BIGINT);break;case"enum":i=e.V.T.values[0].no;break;case"message":i=new e.V.T;break}return[a,i]}function Gs(e,t){let n=nn(e,t);return typeof n=="bigint"?n.toString():n}function nn(e,t){switch(t){case v.STRING:return e.string();case v.BOOL:return e.bool();case v.DOUBLE:return e.double();case v.FLOAT:return e.float();case v.INT32:return e.int32();case v.INT64:return e.int64();case v.UINT64:return e.uint64();case v.FIXED64:return e.fixed64();case v.BYTES:return e.bytes();case v.FIXED32:return e.fixed32();case v.SFIXED32:return e.sfixed32();case v.SFIXED64:return e.sfixed64();case v.SINT64:return e.sint64();case v.UINT32:return e.uint32();case v.SINT32:return e.sint32()}}function ko(e,t,n,r){z(t!==void 0);let o=e.repeated;switch(e.kind){case"scalar":case"enum":let a=e.kind=="enum"?v.INT32:e.T;if(o)if(z(Array.isArray(t)),e.packed)Ws(n,a,e.no,t);else for(let i of t)Ft(n,a,e.no,i);else Ft(n,a,e.no,t);break;case"message":if(o){z(Array.isArray(t));for(let i of t)Co(n,r,e,i)}else Co(n,r,e,t);break;case"map":z(typeof t=="object"&&!!t);for(let[i,s]of Object.entries(t))Js(n,r,e,i,s);break}}function Js(e,t,n,r,o){e.tag(n.no,Z.LengthDelimited),e.fork();let a=r;switch(n.K){case v.INT32:case v.FIXED32:case v.UINT32:case v.SFIXED32:case v.SINT32:a=Number.parseInt(r);break;case v.BOOL:z(r=="true"||r=="false"),a=r=="true";break}switch(Ft(e,n.K,1,a),n.V.kind){case"scalar":Ft(e,n.V.T,2,o);break;case"enum":Ft(e,v.INT32,2,o);break;case"message":z(o!==void 0),e.tag(2,Z.LengthDelimited).bytes(o.toBinary(t));break}e.join()}function Co(e,t,n,r){let o=ho(n.T,r);n.delimited?e.tag(n.no,Z.StartGroup).raw(o.toBinary(t)).tag(n.no,Z.EndGroup):e.tag(n.no,Z.LengthDelimited).bytes(o.toBinary(t))}function Ft(e,t,n,r){z(r!==void 0);let[o,a]=So(t);e.tag(n,o)[a](r)}function Ws(e,t,n,r){if(!r.length)return;e.tag(n,Z.LengthDelimited).fork();let[,o]=So(t);for(let a=0;a<r.length;a++)e[o](r[a]);e.join()}function So(e){let t=Z.Varint;switch(e){case v.BYTES:case v.STRING:t=Z.LengthDelimited;break;case v.DOUBLE:case v.FIXED64:case v.SFIXED64:t=Z.Bit64;break;case v.FIXED32:case v.SFIXED32:case v.FLOAT:t=Z.Bit32;break}let n=v[e].toLowerCase();return[t,n]}function Vs(){return{setEnumType:eo,initPartial(e,t){if(e===void 0)return;let n=t.getType();for(let r of n.fields.byMember()){let o=r.localName,a=t,i=e;if(i[o]!=null)switch(r.kind){case"oneof":let s=i[o].case;if(s===void 0)continue;let c=r.findField(s),u=i[o].value;c&&c.kind=="message"&&!Ye(u,c.T)?u=new c.T(u):c&&c.kind==="scalar"&&c.T===v.BYTES&&(u=Lt(u)),a[o]={case:s,value:u};break;case"scalar":case"enum":let d=i[o];r.T===v.BYTES&&(d=r.repeated?d.map(Lt):Lt(d)),a[o]=d;break;case"map":switch(r.V.kind){case"scalar":case"enum":if(r.V.T===v.BYTES)for(let[m,g]of Object.entries(i[o]))a[o][m]=Lt(g);else Object.assign(a[o],i[o]);break;case"message":let h=r.V.T;for(let m of Object.keys(i[o])){let g=i[o][m];h.fieldWrapper||(g=new h(g)),a[o][m]=g}break}break;case"message":let f=r.T;if(r.repeated)a[o]=i[o].map(h=>Ye(h,f)?h:new f(h));else{let h=i[o];f.fieldWrapper?f.typeName==="google.protobuf.BytesValue"?a[o]=Lt(h):a[o]=h:a[o]=Ye(h,f)?h:new f(h)}break}}},equals(e,t,n){return t===n?!0:!t||!n?!1:e.fields.byMember().every(r=>{let o=t[r.localName],a=n[r.localName];if(r.repeated){if(o.length!==a.length)return!1;switch(r.kind){case"message":return o.every((i,s)=>r.T.equals(i,a[s]));case"scalar":return o.every((i,s)=>Ze(r.T,i,a[s]));case"enum":return o.every((i,s)=>Ze(v.INT32,i,a[s]))}throw Error(`repeated cannot contain ${r.kind}`)}switch(r.kind){case"message":let i=o,s=a;return r.T.fieldWrapper&&(i!==void 0&&!Ye(i)&&(i=r.T.fieldWrapper.wrapField(i)),s!==void 0&&!Ye(s)&&(s=r.T.fieldWrapper.wrapField(s))),r.T.equals(i,s);case"enum":return Ze(v.INT32,o,a);case"scalar":return Ze(r.T,o,a);case"oneof":if(o.case!==a.case)return!1;let c=r.findField(o.case);if(c===void 0)return!0;switch(c.kind){case"message":return c.T.equals(o.value,a.value);case"enum":return Ze(v.INT32,o.value,a.value);case"scalar":return Ze(c.T,o.value,a.value)}throw Error(`oneof cannot contain ${c.kind}`);case"map":let u=Object.keys(o).concat(Object.keys(a));switch(r.V.kind){case"message":let d=r.V.T;return u.every(h=>d.equals(o[h],a[h]));case"enum":return u.every(h=>Ze(v.INT32,o[h],a[h]));case"scalar":let f=r.V.T;return u.every(h=>Ze(f,o[h],a[h]))}break}})},clone(e){let t=e.getType(),n=new t,r=n;for(let o of t.fields.byMember()){let a=e[o.localName],i;if(o.repeated)i=a.map(rn);else if(o.kind=="map"){i=r[o.localName];for(let[s,c]of Object.entries(a))i[s]=rn(c)}else i=o.kind=="oneof"?o.findField(a.case)?{case:a.case,value:rn(a.value)}:{case:void 0}:rn(a);r[o.localName]=i}for(let o of t.runtime.bin.listUnknownFields(e))t.runtime.bin.onUnknownField(r,o.no,o.wireType,o.data);return n}}}function rn(e){if(e===void 0)return e;if(Ye(e))return e.clone();if(e instanceof Uint8Array){let t=new Uint8Array(e.byteLength);return t.set(e),t}return e}function Lt(e){return e instanceof Uint8Array?e:new Uint8Array(e)}function $s(e,t,n){return{syntax:e,json:_s(),bin:Ms(),util:Object.assign(Object.assign({},Vs()),{newFieldList:t,initFields:n}),makeMessageType(r,o,a){return ws(this,r,o,a)},makeEnum:ys,makeEnumType:to,getEnumType:bs,makeExtension(r,o,a){return As(this,r,o,a)}}}var Hs=class{constructor(e,t){this._fields=e,this._normalizer=t}findJsonName(e){if(!this.jsonNames){let t={};for(let n of this.list())t[n.jsonName]=t[n.name]=n;this.jsonNames=t}return this.jsonNames[e]}find(e){if(!this.numbers){let t={};for(let n of this.list())t[n.no]=n;this.numbers=t}return this.numbers[e]}list(){return this.all||(this.all=this._normalizer(this._fields)),this.all}byNumber(){return this.numbersAsc||(this.numbersAsc=this.list().concat().sort((e,t)=>e.no-t.no)),this.numbersAsc}byMember(){if(!this.members){this.members=[];let e=this.members,t;for(let n of this.list())n.oneof?n.oneof!==t&&(t=n.oneof,e.push(t)):e.push(n)}return this.members}};function xo(e,t){let n=Ao(e);return t?n:Qs(Xs(n))}function qs(e){return xo(e,!1)}const zs=Ao;function Ao(e){let t=!1,n=[];for(let r=0;r<e.length;r++){let o=e.charAt(r);switch(o){case"_":t=!0;break;case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":n.push(o),t=!1;break;default:t&&(t=!1,o=o.toUpperCase()),n.push(o);break}}return n.join("")}var Ks=new Set(["constructor","toString","toJSON","valueOf"]),Ys=new Set(["getType","clone","equals","fromBinary","fromJson","fromJsonString","toBinary","toJson","toJsonString","toObject"]),To=e=>`${e}$`,Xs=e=>Ys.has(e)?To(e):e;const Qs=e=>Ks.has(e)?To(e):e;var Zs=class{constructor(e){this.kind="oneof",this.repeated=!1,this.packed=!1,this.opt=!1,this.req=!1,this.default=void 0,this.fields=[],this.name=e,this.localName=qs(e)}addField(e){z(e.oneof===this,`field ${e.name} not one of ${this.name}`),this.fields.push(e)}findField(e){if(!this._lookup){this._lookup=Object.create(null);for(let t=0;t<this.fields.length;t++)this._lookup[this.fields[t].localName]=this.fields[t]}return this._lookup[e]}};function el(e,t){let n=[],r;for(let o of typeof e=="function"?e():e){let a=o;if(a.localName=xo(o.name,o.oneof!==void 0),a.jsonName=o.jsonName??zs(o.name),a.repeated=o.repeated??!1,o.kind=="scalar"&&(a.L=o.L??at.BIGINT),a.delimited=o.delimited??!1,a.req=o.req??!1,a.opt=o.opt??!1,o.packed===void 0&&(t?a.packed=o.kind=="enum"||o.kind=="scalar"&&o.T!=v.BYTES&&o.T!=v.STRING:a.packed=!1),o.oneof!==void 0){let i=typeof o.oneof=="string"?o.oneof:o.oneof.name;(!r||r.name!=i)&&(r=new Zs(i)),a.oneof=r,r.addField(a)}n.push(a)}return n}const N=$s("proto3",e=>new Hs(e,t=>el(t,!0)),e=>{for(let t of e.getType().fields.byMember()){if(t.opt)continue;let n=t.localName,r=e;if(t.repeated){r[n]=[];continue}switch(t.kind){case"oneof":r[n]={case:void 0};break;case"enum":r[n]=0;break;case"map":r[n]={};break;case"scalar":r[n]=mt(t.T,t.L);break;case"message":break}}});var ye;(function(e){e[e.Unary=0]="Unary",e[e.ServerStreaming=1]="ServerStreaming",e[e.ClientStreaming=2]="ClientStreaming",e[e.BiDiStreaming=3]="BiDiStreaming"})(ye||(ye={}));var Io;(function(e){e[e.NoSideEffects=1]="NoSideEffects",e[e.Idempotent=2]="Idempotent"})(Io||(Io={}));var Yn;(function(e){e[e.UNSPECIFIED=0]="UNSPECIFIED",e[e.JUPYTER_FORMAT=77]="JUPYTER_FORMAT"})(Yn||(Yn={})),N.util.setEnumType(Yn,"exa.codeium_common_pb.ExperimentKey",[{no:0,name:"UNSPECIFIED"},{no:77,name:"JUPYTER_FORMAT"}]);var on;(function(e){e[e.CODEIUM=0]="CODEIUM"})(on||(on={})),N.util.setEnumType(on,"exa.codeium_common_pb.AuthSource",[{no:0,name:"AUTH_SOURCE_CODEIUM"}]);var an;(function(e){e[e.UNSPECIFIED=0]="UNSPECIFIED",e[e.ENABLE_CODEIUM=1]="ENABLE_CODEIUM",e[e.DISABLE_CODEIUM=2]="DISABLE_CODEIUM",e[e.SHOW_PREVIOUS_COMPLETION=3]="SHOW_PREVIOUS_COMPLETION",e[e.SHOW_NEXT_COMPLETION=4]="SHOW_NEXT_COMPLETION"})(an||(an={})),N.util.setEnumType(an,"exa.codeium_common_pb.EventType",[{no:0,name:"EVENT_TYPE_UNSPECIFIED"},{no:1,name:"EVENT_TYPE_ENABLE_CODEIUM"},{no:2,name:"EVENT_TYPE_DISABLE_CODEIUM"},{no:3,name:"EVENT_TYPE_SHOW_PREVIOUS_COMPLETION"},{no:4,name:"EVENT_TYPE_SHOW_NEXT_COMPLETION"}]);var sn;(function(e){e[e.UNSPECIFIED=0]="UNSPECIFIED",e[e.TYPING_AS_SUGGESTED=1]="TYPING_AS_SUGGESTED",e[e.CACHE=2]="CACHE",e[e.NETWORK=3]="NETWORK"})(sn||(sn={})),N.util.setEnumType(sn,"exa.codeium_common_pb.CompletionSource",[{no:0,name:"COMPLETION_SOURCE_UNSPECIFIED"},{no:1,name:"COMPLETION_SOURCE_TYPING_AS_SUGGESTED"},{no:2,name:"COMPLETION_SOURCE_CACHE"},{no:3,name:"COMPLETION_SOURCE_NETWORK"}]);var it;(function(e){e[e.UNSPECIFIED=0]="UNSPECIFIED",e[e.C=1]="C",e[e.CLOJURE=2]="CLOJURE",e[e.COFFEESCRIPT=3]="COFFEESCRIPT",e[e.CPP=4]="CPP",e[e.CSHARP=5]="CSHARP",e[e.CSS=6]="CSS",e[e.CUDACPP=7]="CUDACPP",e[e.DOCKERFILE=8]="DOCKERFILE",e[e.GO=9]="GO",e[e.GROOVY=10]="GROOVY",e[e.HANDLEBARS=11]="HANDLEBARS",e[e.HASKELL=12]="HASKELL",e[e.HCL=13]="HCL",e[e.HTML=14]="HTML",e[e.INI=15]="INI",e[e.JAVA=16]="JAVA",e[e.JAVASCRIPT=17]="JAVASCRIPT",e[e.JSON=18]="JSON",e[e.JULIA=19]="JULIA",e[e.KOTLIN=20]="KOTLIN",e[e.LATEX=21]="LATEX",e[e.LESS=22]="LESS",e[e.LUA=23]="LUA",e[e.MAKEFILE=24]="MAKEFILE",e[e.MARKDOWN=25]="MARKDOWN",e[e.OBJECTIVEC=26]="OBJECTIVEC",e[e.OBJECTIVECPP=27]="OBJECTIVECPP",e[e.PERL=28]="PERL",e[e.PHP=29]="PHP",e[e.PLAINTEXT=30]="PLAINTEXT",e[e.PROTOBUF=31]="PROTOBUF",e[e.PBTXT=32]="PBTXT",e[e.PYTHON=33]="PYTHON",e[e.R=34]="R",e[e.RUBY=35]="RUBY",e[e.RUST=36]="RUST",e[e.SASS=37]="SASS",e[e.SCALA=38]="SCALA",e[e.SCSS=39]="SCSS",e[e.SHELL=40]="SHELL",e[e.SQL=41]="SQL",e[e.STARLARK=42]="STARLARK",e[e.SWIFT=43]="SWIFT",e[e.TSX=44]="TSX",e[e.TYPESCRIPT=45]="TYPESCRIPT",e[e.VISUALBASIC=46]="VISUALBASIC",e[e.VUE=47]="VUE",e[e.XML=48]="XML",e[e.XSL=49]="XSL",e[e.YAML=50]="YAML",e[e.SVELTE=51]="SVELTE",e[e.TOML=52]="TOML",e[e.DART=53]="DART",e[e.RST=54]="RST",e[e.OCAML=55]="OCAML",e[e.CMAKE=56]="CMAKE",e[e.PASCAL=57]="PASCAL",e[e.ELIXIR=58]="ELIXIR",e[e.FSHARP=59]="FSHARP",e[e.LISP=60]="LISP",e[e.MATLAB=61]="MATLAB",e[e.POWERSHELL=62]="POWERSHELL",e[e.SOLIDITY=63]="SOLIDITY",e[e.ADA=64]="ADA",e[e.OCAML_INTERFACE=65]="OCAML_INTERFACE"})(it||(it={})),N.util.setEnumType(it,"exa.codeium_common_pb.Language",[{no:0,name:"LANGUAGE_UNSPECIFIED"},{no:1,name:"LANGUAGE_C"},{no:2,name:"LANGUAGE_CLOJURE"},{no:3,name:"LANGUAGE_COFFEESCRIPT"},{no:4,name:"LANGUAGE_CPP"},{no:5,name:"LANGUAGE_CSHARP"},{no:6,name:"LANGUAGE_CSS"},{no:7,name:"LANGUAGE_CUDACPP"},{no:8,name:"LANGUAGE_DOCKERFILE"},{no:9,name:"LANGUAGE_GO"},{no:10,name:"LANGUAGE_GROOVY"},{no:11,name:"LANGUAGE_HANDLEBARS"},{no:12,name:"LANGUAGE_HASKELL"},{no:13,name:"LANGUAGE_HCL"},{no:14,name:"LANGUAGE_HTML"},{no:15,name:"LANGUAGE_INI"},{no:16,name:"LANGUAGE_JAVA"},{no:17,name:"LANGUAGE_JAVASCRIPT"},{no:18,name:"LANGUAGE_JSON"},{no:19,name:"LANGUAGE_JULIA"},{no:20,name:"LANGUAGE_KOTLIN"},{no:21,name:"LANGUAGE_LATEX"},{no:22,name:"LANGUAGE_LESS"},{no:23,name:"LANGUAGE_LUA"},{no:24,name:"LANGUAGE_MAKEFILE"},{no:25,name:"LANGUAGE_MARKDOWN"},{no:26,name:"LANGUAGE_OBJECTIVEC"},{no:27,name:"LANGUAGE_OBJECTIVECPP"},{no:28,name:"LANGUAGE_PERL"},{no:29,name:"LANGUAGE_PHP"},{no:30,name:"LANGUAGE_PLAINTEXT"},{no:31,name:"LANGUAGE_PROTOBUF"},{no:32,name:"LANGUAGE_PBTXT"},{no:33,name:"LANGUAGE_PYTHON"},{no:34,name:"LANGUAGE_R"},{no:35,name:"LANGUAGE_RUBY"},{no:36,name:"LANGUAGE_RUST"},{no:37,name:"LANGUAGE_SASS"},{no:38,name:"LANGUAGE_SCALA"},{no:39,name:"LANGUAGE_SCSS"},{no:40,name:"LANGUAGE_SHELL"},{no:41,name:"LANGUAGE_SQL"},{no:42,name:"LANGUAGE_STARLARK"},{no:43,name:"LANGUAGE_SWIFT"},{no:44,name:"LANGUAGE_TSX"},{no:45,name:"LANGUAGE_TYPESCRIPT"},{no:46,name:"LANGUAGE_VISUALBASIC"},{no:47,name:"LANGUAGE_VUE"},{no:48,name:"LANGUAGE_XML"},{no:49,name:"LANGUAGE_XSL"},{no:50,name:"LANGUAGE_YAML"},{no:51,name:"LANGUAGE_SVELTE"},{no:52,name:"LANGUAGE_TOML"},{no:53,name:"LANGUAGE_DART"},{no:54,name:"LANGUAGE_RST"},{no:55,name:"LANGUAGE_OCAML"},{no:56,name:"LANGUAGE_CMAKE"},{no:57,name:"LANGUAGE_PASCAL"},{no:58,name:"LANGUAGE_ELIXIR"},{no:59,name:"LANGUAGE_FSHARP"},{no:60,name:"LANGUAGE_LISP"},{no:61,name:"LANGUAGE_MATLAB"},{no:62,name:"LANGUAGE_POWERSHELL"},{no:63,name:"LANGUAGE_SOLIDITY"},{no:64,name:"LANGUAGE_ADA"},{no:65,name:"LANGUAGE_OCAML_INTERFACE"}]);var tl=(we=class extends X{constructor(n){super();p(this,"completionId","");p(this,"text","");p(this,"prefix","");p(this,"stop","");p(this,"score",0);p(this,"tokens",[]);p(this,"decodedTokens",[]);p(this,"probabilities",[]);p(this,"adjustedProbabilities",[]);p(this,"generatedLength",J.zero);N.util.initPartial(n,this)}static fromBinary(n,r){return new we().fromBinary(n,r)}static fromJson(n,r){return new we().fromJson(n,r)}static fromJsonString(n,r){return new we().fromJsonString(n,r)}static equals(n,r){return N.util.equals(we,n,r)}},p(we,"runtime",N),p(we,"typeName","exa.codeium_common_pb.Completion"),p(we,"fields",N.util.newFieldList(()=>[{no:1,name:"completion_id",kind:"scalar",T:9},{no:2,name:"text",kind:"scalar",T:9},{no:3,name:"prefix",kind:"scalar",T:9},{no:4,name:"stop",kind:"scalar",T:9},{no:5,name:"score",kind:"scalar",T:1},{no:6,name:"tokens",kind:"scalar",T:4,repeated:!0},{no:7,name:"decoded_tokens",kind:"scalar",T:9,repeated:!0},{no:8,name:"probabilities",kind:"scalar",T:1,repeated:!0},{no:9,name:"adjusted_probabilities",kind:"scalar",T:1,repeated:!0},{no:10,name:"generated_length",kind:"scalar",T:4}])),we),Fo=(ve=class extends X{constructor(n){super();p(this,"ideName","");p(this,"ideVersion","");p(this,"extensionName","");p(this,"extensionVersion","");p(this,"apiKey","");p(this,"locale","");p(this,"sessionId","");p(this,"requestId",J.zero);p(this,"userAgent","");p(this,"url","");p(this,"authSource",on.CODEIUM);N.util.initPartial(n,this)}static fromBinary(n,r){return new ve().fromBinary(n,r)}static fromJson(n,r){return new ve().fromJson(n,r)}static fromJsonString(n,r){return new ve().fromJsonString(n,r)}static equals(n,r){return N.util.equals(ve,n,r)}},p(ve,"runtime",N),p(ve,"typeName","exa.codeium_common_pb.Metadata"),p(ve,"fields",N.util.newFieldList(()=>[{no:1,name:"ide_name",kind:"scalar",T:9},{no:7,name:"ide_version",kind:"scalar",T:9},{no:12,name:"extension_name",kind:"scalar",T:9},{no:2,name:"extension_version",kind:"scalar",T:9},{no:3,name:"api_key",kind:"scalar",T:9},{no:4,name:"locale",kind:"scalar",T:9},{no:10,name:"session_id",kind:"scalar",T:9},{no:9,name:"request_id",kind:"scalar",T:4},{no:13,name:"user_agent",kind:"scalar",T:9},{no:14,name:"url",kind:"scalar",T:9},{no:15,name:"auth_source",kind:"enum",T:N.getEnumType(on)}])),ve),nl=(Ee=class extends X{constructor(n){super();p(this,"tabSize",J.zero);p(this,"insertSpaces",!1);N.util.initPartial(n,this)}static fromBinary(n,r){return new Ee().fromBinary(n,r)}static fromJson(n,r){return new Ee().fromJson(n,r)}static fromJsonString(n,r){return new Ee().fromJsonString(n,r)}static equals(n,r){return N.util.equals(Ee,n,r)}},p(Ee,"runtime",N),p(Ee,"typeName","exa.codeium_common_pb.EditorOptions"),p(Ee,"fields",N.util.newFieldList(()=>[{no:1,name:"tab_size",kind:"scalar",T:4},{no:2,name:"insert_spaces",kind:"scalar",T:8}])),Ee);Ne=class extends X{constructor(n){super();p(this,"eventType",an.UNSPECIFIED);p(this,"eventJson","");p(this,"timestampUnixMs",J.zero);N.util.initPartial(n,this)}static fromBinary(n,r){return new Ne().fromBinary(n,r)}static fromJson(n,r){return new Ne().fromJson(n,r)}static fromJsonString(n,r){return new Ne().fromJsonString(n,r)}static equals(n,r){return N.util.equals(Ne,n,r)}},p(Ne,"runtime",N),p(Ne,"typeName","exa.codeium_common_pb.Event"),p(Ne,"fields",N.util.newFieldList(()=>[{no:1,name:"event_type",kind:"enum",T:N.getEnumType(an)},{no:2,name:"event_json",kind:"scalar",T:9},{no:3,name:"timestamp_unix_ms",kind:"scalar",T:3}]));var rl=class extends Fn{constructor(t,n){super();p(this,"index");p(this,"total");this.index=t,this.total=n}toDOM(){let t=document.createElement("span");t.setAttribute("aria-hidden","true"),t.className="cm-codeium-cycle";let n=t.appendChild(document.createElement("span"));n.className="cm-codeium-cycle-explanation",n.innerText=`${this.index+1}/${this.total}`;let r=t.appendChild(document.createElement("button"));return r.className="cm-codeium-cycle-key",r.innerText="\u2192 (Ctrl ])",r.dataset.action="codeium-cycle",t}ignoreEvent(){return!1}};const ln=Mt.define({combine(e){return An(e,{language:it.TYPESCRIPT,timeout:150,widgetClass:rl,alwaysOn:!0},{})}}),Lo=Mt.define({combine(e){return An(e,{override:()=>[]},{})}});var ol=H.mark({class:"cm-ghostText"});const st=qe.define({create(e){return null},update(e,t){var r;let n=t.state.facet(ln);for(let o of t.effects){if(o.is(Jn)){let{changeSpecs:a,index:i}=o.value,s=a[i].map(u=>ol.range(u.absoluteStartPos,u.absoluteEndPos)),c=(r=s.at(-1))==null?void 0:r.to;return{index:i,decorations:H.set([...s,...c!==void 0&&a.length>1&&n.widgetClass?[H.widget({widget:new n.widgetClass(i,a.length),side:1}).range(c)]:[]]),changeSpecs:a,reverseChangeSet:o.value.reverseChangeSet}}if(o.is(Wn)||o.is(Vn))return null}return e&&{...e,decorations:e.decorations.map(t.changes),reverseChangeSet:e.reverseChangeSet.map(t.changes)}},provide:e=>B.decorations.from(e,t=>(t==null?void 0:t.decorations)||H.none)}),ht=In.define(),cn=In.define();var M;(function(e){e[e.Canceled=1]="Canceled",e[e.Unknown=2]="Unknown",e[e.InvalidArgument=3]="InvalidArgument",e[e.DeadlineExceeded=4]="DeadlineExceeded",e[e.NotFound=5]="NotFound",e[e.AlreadyExists=6]="AlreadyExists",e[e.PermissionDenied=7]="PermissionDenied",e[e.ResourceExhausted=8]="ResourceExhausted",e[e.FailedPrecondition=9]="FailedPrecondition",e[e.Aborted=10]="Aborted",e[e.OutOfRange=11]="OutOfRange",e[e.Unimplemented=12]="Unimplemented",e[e.Internal=13]="Internal",e[e.Unavailable=14]="Unavailable",e[e.DataLoss=15]="DataLoss",e[e.Unauthenticated=16]="Unauthenticated"})(M||(M={}));function Xn(e){let t=M[e];return typeof t=="string"?t[0].toLowerCase()+t.substring(1).replace(/[A-Z]/g,n=>"_"+n.toLowerCase()):e.toString()}var un;function al(e){if(!un){un={};for(let t of Object.values(M))typeof t!="string"&&(un[Xn(t)]=t)}return un[e]}var he=class Ct extends Error{constructor(t,n=M.Unknown,r,o,a){super(il(t,n)),this.name="ConnectError",Object.setPrototypeOf(this,new.target.prototype),this.rawMessage=t,this.code=n,this.metadata=new Headers(r??{}),this.details=o??[],this.cause=a}static from(t,n=M.Unknown){return t instanceof Ct?t:t instanceof Error?t.name=="AbortError"?new Ct(t.message,M.Canceled):new Ct(t.message,n,void 0,void 0,t):new Ct(String(t),n,void 0,void 0,t)}static[Symbol.hasInstance](t){return t instanceof Error?Object.getPrototypeOf(t)===Ct.prototype?!0:t.name==="ConnectError"&&"code"in t&&typeof t.code=="number"&&"metadata"in t&&"details"in t&&Array.isArray(t.details)&&"rawMessage"in t&&typeof t.rawMessage=="string"&&"cause"in t:!1}findDetails(t){let n="typeName"in t?{findMessage:o=>o===t.typeName?t:void 0}:t,r=[];for(let o of this.details){if("getType"in o){n.findMessage(o.getType().typeName)&&r.push(o);continue}let a=n.findMessage(o.type);if(a)try{r.push(a.fromBinary(o.value))}catch{}}return r}};function il(e,t){return e.length?`[${Xn(t)}] ${e}`:`[${Xn(t)}]`}function sl(...e){let t=new Headers;for(let n of e)n.forEach((r,o)=>{t.append(o,r)});return t}function ll(e,t){let n={};for(let[r,o]of Object.entries(e.methods)){let a=t(Object.assign(Object.assign({},o),{localName:r,service:e}));a!=null&&(n[r]=a)}return n}function cl(e){let t,n=new Uint8Array;function r(o){let a=new Uint8Array(n.length+o.length);a.set(n),a.set(o,n.length),n=a}return new ReadableStream({start(){t=e.getReader()},async pull(o){let a;for(;;){if(a===void 0&&n.byteLength>=5){let c=0;for(let u=1;u<5;u++)c=(c<<8)+n[u];a={flags:n[0],length:c}}if(a!==void 0&&n.byteLength>=a.length+5)break;let s=await t.read();if(s.done)break;r(s.value)}if(a===void 0){if(n.byteLength==0){o.close();return}o.error(new he("premature end of stream",M.DataLoss));return}let i=n.subarray(5,5+a.length);n=n.subarray(5+a.length),o.enqueue({flags:a.flags,data:i})}})}function ul(e,t){let n=new Uint8Array(t.length+5);n.set(t,5);let r=new DataView(n.buffer,n.byteOffset,n.byteLength);return r.setUint8(0,e),r.setUint32(1,t.length),n}var dl=function(e){if(!Symbol.asyncIterator)throw TypeError("Symbol.asyncIterator is not defined.");var t=e[Symbol.asyncIterator],n;return t?t.call(e):(e=typeof __values=="function"?__values(e):e[Symbol.iterator](),n={},r("next"),r("throw"),r("return"),n[Symbol.asyncIterator]=function(){return this},n);function r(a){n[a]=e[a]&&function(i){return new Promise(function(s,c){i=e[a](i),o(s,c,i.done,i.value)})}}function o(a,i,s,c){Promise.resolve(c).then(function(u){a({value:u,done:s})},i)}},Ot=function(e){return this instanceof Ot?(this.v=e,this):new Ot(e)},fl=function(e,t,n){if(!Symbol.asyncIterator)throw TypeError("Symbol.asyncIterator is not defined.");var r=n.apply(e,t||[]),o,a=[];return o={},s("next"),s("throw"),s("return",i),o[Symbol.asyncIterator]=function(){return this},o;function i(m){return function(g){return Promise.resolve(g).then(m,f)}}function s(m,g){r[m]&&(o[m]=function(y){return new Promise(function(w,k){a.push([m,y,w,k])>1||c(m,y)})},g&&(o[m]=g(o[m])))}function c(m,g){try{u(r[m](g))}catch(y){h(a[0][3],y)}}function u(m){m.value instanceof Ot?Promise.resolve(m.value.v).then(d,f):h(a[0][2],m)}function d(m){c("next",m)}function f(m){c("throw",m)}function h(m,g){m(g),a.shift(),a.length&&c(a[0][0],a[0][1])}},ml=function(e){var t,n;return t={},r("next"),r("throw",function(o){throw o}),r("return"),t[Symbol.iterator]=function(){return this},t;function r(o,a){t[o]=e[o]?function(i){return(n=!n)?{value:Ot(e[o](i)),done:!1}:a?a(i):i}:a}};function pl(e){return fl(this,arguments,function*(){yield Ot(yield*ml(dl(e)))})}var Oo=function(e){if(!Symbol.asyncIterator)throw TypeError("Symbol.asyncIterator is not defined.");var t=e[Symbol.asyncIterator],n;return t?t.call(e):(e=typeof __values=="function"?__values(e):e[Symbol.iterator](),n={},r("next"),r("throw"),r("return"),n[Symbol.asyncIterator]=function(){return this},n);function r(a){n[a]=e[a]&&function(i){return new Promise(function(s,c){i=e[a](i),o(s,c,i.done,i.value)})}}function o(a,i,s,c){Promise.resolve(c).then(function(u){a({value:u,done:s})},i)}},gt=function(e){return this instanceof gt?(this.v=e,this):new gt(e)},hl=function(e){var t,n;return t={},r("next"),r("throw",function(o){throw o}),r("return"),t[Symbol.iterator]=function(){return this},t;function r(o,a){t[o]=e[o]?function(i){return(n=!n)?{value:gt(e[o](i)),done:!1}:a?a(i):i}:a}},gl=function(e,t,n){if(!Symbol.asyncIterator)throw TypeError("Symbol.asyncIterator is not defined.");var r=n.apply(e,t||[]),o,a=[];return o={},s("next"),s("throw"),s("return",i),o[Symbol.asyncIterator]=function(){return this},o;function i(m){return function(g){return Promise.resolve(g).then(m,f)}}function s(m,g){r[m]&&(o[m]=function(y){return new Promise(function(w,k){a.push([m,y,w,k])>1||c(m,y)})},g&&(o[m]=g(o[m])))}function c(m,g){try{u(r[m](g))}catch(y){h(a[0][3],y)}}function u(m){m.value instanceof gt?Promise.resolve(m.value.v).then(d,f):h(a[0][2],m)}function d(m){c("next",m)}function f(m){c("throw",m)}function h(m,g){m(g),a.shift(),a.length&&c(a[0][0],a[0][1])}};function bl(e,t){return ll(e,n=>{switch(n.kind){case ye.Unary:return wl(t,e,n);case ye.ServerStreaming:return vl(t,e,n);case ye.ClientStreaming:return El(t,e,n);case ye.BiDiStreaming:return Nl(t,e,n);default:return null}})}function yl(e,t){return bl(e,t)}function wl(e,t,n){return async function(r,o){var a,i;let s=await e.unary(t,n,o==null?void 0:o.signal,o==null?void 0:o.timeoutMs,o==null?void 0:o.headers,r,o==null?void 0:o.contextValues);return(a=o==null?void 0:o.onHeader)==null||a.call(o,s.header),(i=o==null?void 0:o.onTrailer)==null||i.call(o,s.trailer),s.message}}function vl(e,t,n){return function(r,o){return Do(e.stream(t,n,o==null?void 0:o.signal,o==null?void 0:o.timeoutMs,o==null?void 0:o.headers,pl([r]),o==null?void 0:o.contextValues),o)}}function El(e,t,n){return async function(r,o){var a,i,s,c,u,d;let f=await e.stream(t,n,o==null?void 0:o.signal,o==null?void 0:o.timeoutMs,o==null?void 0:o.headers,r,o==null?void 0:o.contextValues);(u=o==null?void 0:o.onHeader)==null||u.call(o,f.header);let h,m=0;try{for(var g=!0,y=Oo(f.message),w;w=await y.next(),a=w.done,!a;g=!0)c=w.value,g=!1,h=c,m++}catch(k){i={error:k}}finally{try{!g&&!a&&(s=y.return)&&await s.call(y)}finally{if(i)throw i.error}}if(!h)throw new he("protocol error: missing response message",M.Unimplemented);if(m>1)throw new he("protocol error: received extra messages for client streaming method",M.Unimplemented);return(d=o==null?void 0:o.onTrailer)==null||d.call(o,f.trailer),h}}function Nl(e,t,n){return function(r,o){return Do(e.stream(t,n,o==null?void 0:o.signal,o==null?void 0:o.timeoutMs,o==null?void 0:o.headers,r,o==null?void 0:o.contextValues),o)}}function Do(e,t){let n=(function(){return gl(this,arguments,function*(){var r,o;let a=yield gt(e);(r=t==null?void 0:t.onHeader)==null||r.call(t,a.header),yield gt(yield*hl(Oo(a.message))),(o=t==null?void 0:t.onTrailer)==null||o.call(t,a.trailer)})})()[Symbol.asyncIterator]();return{[Symbol.asyncIterator]:()=>({next:()=>n.next()})}}function kl(...e){let t=new AbortController,n=e.filter(o=>o!==void 0).concat(t.signal);for(let o of n){if(o.aborted){r.apply(o);break}o.addEventListener("abort",r)}function r(){t.signal.aborted||t.abort(_o(this));for(let o of n)o.removeEventListener("abort",r)}return t}function Cl(e){let t=new AbortController,n=()=>{t.abort(new he("the operation timed out",M.DeadlineExceeded))},r;return e!==void 0&&(e<=0?n():r=setTimeout(n,e)),{signal:t.signal,cleanup:()=>clearTimeout(r)}}function _o(e){if(!e.aborted)return;if(e.reason!==void 0)return e.reason;let t=Error("This operation was aborted");return t.name="AbortError",t}function Uo(){return{get(e){return e.id in this?this[e.id]:e.defaultValue},set(e,t){return this[e.id]=t,this},delete(e){return delete this[e.id],this}}}function Bo(e,t,n){let r=typeof t=="string"?t:t.typeName,o=typeof n=="string"?n:n.name;return e.toString().replace(/\/?$/,`/${r}/${o}`)}function jo(e,t){return t instanceof e?t:new e(t)}function Sl(e,t){function n(r){return r.done===!0?r:{done:r.done,value:jo(e,r.value)}}return{[Symbol.asyncIterator](){let r=t[Symbol.asyncIterator](),o={next:()=>r.next().then(n)};return r.throw!==void 0&&(o.throw=a=>r.throw(a).then(n)),r.return!==void 0&&(o.return=a=>r.return(a).then(n)),o}}}function Po(e,t){return(t==null?void 0:t.concat().reverse().reduce((n,r)=>r(n),e))??e}function Mo(e){let t=Object.assign({},e);return t.ignoreUnknownFields??(t.ignoreUnknownFields=!0),t}function Ro(e,t,n,r){let o=t?Go(e.I,r):Jo(e.I,n);return{parse:(t?Go(e.O,r):Jo(e.O,n)).parse,serialize:o.serialize}}function Go(e,t){return{parse(n){try{return e.fromBinary(n,t)}catch(r){throw new he(`parse binary: ${r instanceof Error?r.message:String(r)}`,M.Internal)}},serialize(n){try{return n.toBinary(t)}catch(r){throw new he(`serialize binary: ${r instanceof Error?r.message:String(r)}`,M.Internal)}}}}function Jo(e,t){let n=(t==null?void 0:t.textEncoder)??new TextEncoder,r=(t==null?void 0:t.textDecoder)??new TextDecoder,o=Mo(t);return{parse(a){try{let i=r.decode(a);return e.fromJsonString(i,o)}catch(i){throw he.from(i,M.InvalidArgument)}},serialize(a){try{let i=a.toJsonString(o);return n.encode(i)}catch(i){throw he.from(i,M.Internal)}}}}const xl=/^application\/(connect\+)?(?:(json)(?:; ?charset=utf-?8)?|(proto))$/i;function Al(e){let t=e==null?void 0:e.match(xl);if(t)return{stream:!!t[1],binary:!!t[3]}}function Wo(e,t,n){if(t&&new Headers(t).forEach((i,s)=>n.metadata.append(s,i)),typeof e!="object"||!e||Array.isArray(e))throw n;let r=n.code;"code"in e&&typeof e.code=="string"&&(r=al(e.code)??r);let o=e.message;if(o!=null&&typeof o!="string")throw n;let a=new he(o??"",r,t);if("details"in e&&Array.isArray(e.details))for(let i of e.details){if(typeof i!="object"||!i||Array.isArray(i)||typeof i.type!="string"||typeof i.value!="string")throw n;try{a.details.push({type:i.type,value:Xt.dec(i.value),debug:i.debug})}catch{throw n}}return a}function Tl(e){let t=new he("invalid end stream",M.Unknown),n;try{n=JSON.parse(typeof e=="string"?e:new TextDecoder().decode(e))}catch{throw t}if(typeof n!="object"||!n||Array.isArray(n))throw t;let r=new Headers;if("metadata"in n){if(typeof n.metadata!="object"||n.metadata==null||Array.isArray(n.metadata))throw t;for(let[o,a]of Object.entries(n.metadata)){if(!Array.isArray(a)||a.some(i=>typeof i!="string"))throw t;for(let i of a)r.append(o,i)}}return{metadata:r,error:"error"in n&&n.error!=null?Wo(n.error,r,t):void 0}}const dn="Content-Type",Vo="Content-Encoding",$o="Connect-Protocol-Version";function Il(e){switch(e){case 400:return M.Internal;case 401:return M.Unauthenticated;case 403:return M.PermissionDenied;case 404:return M.Unimplemented;case 429:return M.Unavailable;case 502:return M.Unavailable;case 503:return M.Unavailable;case 504:return M.Unavailable;default:return M.Unknown}}function Ho(e){let t=new Headers,n=new Headers;return e.forEach((r,o)=>{o.toLowerCase().startsWith("trailer-")?n.append(o.substring(8),r):t.append(o,r)}),[t,n]}function qo(e,t,n,r,o){let a=new Headers(r??{});return n!==void 0&&a.set("Connect-Timeout-Ms",`${n}`),a.set(dn,e==ye.Unary?t?"application/proto":"application/json":t?"application/connect+proto":"application/connect+json"),a.set($o,"1"),o&&a.set("User-Agent","connect-es/1.6.1"),a}function zo(e,t,n,r){let o=r.get(dn),a=Al(o);if(n!==200){let s=new he(`HTTP ${n}`,Il(n),r);if(e==ye.Unary&&a&&!a.binary)return{isUnaryError:!0,unaryError:s};throw s}let i={binary:t,stream:e!==ye.Unary};if((a==null?void 0:a.binary)!==i.binary||a.stream!==i.stream)throw new he(`unsupported content type ${o}`,a===void 0?M.Unknown:M.Internal,r);return{isUnaryError:!1}}var Fl="application/";function Ll(e,t){return t?Xt.enc(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,""):encodeURIComponent(new TextDecoder().decode(e))}function Ol(e,t,n){let r="?connect=v1",o=e.header.get(dn);(o==null?void 0:o.indexOf(Fl))===0&&(r+="&encoding="+encodeURIComponent(o.slice(12)));let a=e.header.get(Vo);a!==null&&a!=="identity"&&(r+="&compression="+encodeURIComponent(a),n=!0),n&&(r+="&base64=1"),r+="&message="+Ll(t,n);let i=e.url+r,s=new Headers(e.header);return[$o,dn,"Content-Length",Vo,"Accept-Encoding"].forEach(c=>s.delete(c)),Object.assign(Object.assign({},e),{init:Object.assign(Object.assign({},e.init),{method:"GET"}),url:i,header:s})}function Dl(e){let t=Po(e.next,e.interceptors),[n,r,o]=Ko(e);return t(Object.assign(Object.assign({},e.req),{message:jo(e.req.method.I,e.req.message),signal:n})).then(a=>(o(),a),r)}function _l(e){let t=Po(e.next,e.interceptors),[n,r,o]=Ko(e),a=Object.assign(Object.assign({},e.req),{message:Sl(e.req.method.I,e.req.message),signal:n}),i=!1;return n.addEventListener("abort",function(){var s,c;let u=e.req.message[Symbol.asyncIterator]();i||(s=u.throw)==null||s.call(u,this.reason).catch(()=>{}),(c=u.return)==null||c.call(u).catch(()=>{})}),t(a).then(s=>Object.assign(Object.assign({},s),{message:{[Symbol.asyncIterator](){let c=s.message[Symbol.asyncIterator]();return{next(){return c.next().then(u=>(u.done==1&&(i=!0,o()),u),r)}}}}}),r)}function Ko(e){let{signal:t,cleanup:n}=Cl(e.timeoutMs),r=kl(e.signal,t);return[r.signal,function(o){let a=he.from(t.aborted?_o(t):o);return r.abort(a),n(),Promise.reject(a)},function(){n(),r.abort()}]}var fn;(function(e){e[e.UNSPECIFIED=0]="UNSPECIFIED",e[e.INACTIVE=1]="INACTIVE",e[e.PROCESSING=2]="PROCESSING",e[e.SUCCESS=3]="SUCCESS",e[e.WARNING=4]="WARNING",e[e.ERROR=5]="ERROR"})(fn||(fn={})),N.util.setEnumType(fn,"exa.language_server_pb.CodeiumState",[{no:0,name:"CODEIUM_STATE_UNSPECIFIED"},{no:1,name:"CODEIUM_STATE_INACTIVE"},{no:2,name:"CODEIUM_STATE_PROCESSING"},{no:3,name:"CODEIUM_STATE_SUCCESS"},{no:4,name:"CODEIUM_STATE_WARNING"},{no:5,name:"CODEIUM_STATE_ERROR"}]);var Yo;(function(e){e[e.UNSPECIFIED=0]="UNSPECIFIED",e[e.SINGLE=1]="SINGLE",e[e.MULTI=2]="MULTI"})(Yo||(Yo={})),N.util.setEnumType(Yo,"exa.language_server_pb.LineType",[{no:0,name:"LINE_TYPE_UNSPECIFIED"},{no:1,name:"LINE_TYPE_SINGLE"},{no:2,name:"LINE_TYPE_MULTI"}]);var mn;(function(e){e[e.UNSPECIFIED=0]="UNSPECIFIED",e[e.INLINE=1]="INLINE",e[e.BLOCK=2]="BLOCK",e[e.INLINE_MASK=3]="INLINE_MASK"})(mn||(mn={})),N.util.setEnumType(mn,"exa.language_server_pb.CompletionPartType",[{no:0,name:"COMPLETION_PART_TYPE_UNSPECIFIED"},{no:1,name:"COMPLETION_PART_TYPE_INLINE"},{no:2,name:"COMPLETION_PART_TYPE_BLOCK"},{no:3,name:"COMPLETION_PART_TYPE_INLINE_MASK"}]);var Ul=(ke=class extends X{constructor(n){super();p(this,"threshold",0);N.util.initPartial(n,this)}static fromBinary(n,r){return new ke().fromBinary(n,r)}static fromJson(n,r){return new ke().fromJson(n,r)}static fromJsonString(n,r){return new ke().fromJsonString(n,r)}static equals(n,r){return N.util.equals(ke,n,r)}},p(ke,"runtime",N),p(ke,"typeName","exa.language_server_pb.MultilineConfig"),p(ke,"fields",N.util.newFieldList(()=>[{no:1,name:"threshold",kind:"scalar",T:2}])),ke),Bl=(Ce=class extends X{constructor(n){super();p(this,"metadata");p(this,"document");p(this,"editorOptions");p(this,"otherDocuments",[]);p(this,"experimentConfig");p(this,"modelName","");p(this,"multilineConfig");N.util.initPartial(n,this)}static fromBinary(n,r){return new Ce().fromBinary(n,r)}static fromJson(n,r){return new Ce().fromJson(n,r)}static fromJsonString(n,r){return new Ce().fromJsonString(n,r)}static equals(n,r){return N.util.equals(Ce,n,r)}},p(Ce,"runtime",N),p(Ce,"typeName","exa.language_server_pb.GetCompletionsRequest"),p(Ce,"fields",N.util.newFieldList(()=>[{no:1,name:"metadata",kind:"message",T:Fo},{no:2,name:"document",kind:"message",T:Xo},{no:3,name:"editor_options",kind:"message",T:nl},{no:5,name:"other_documents",kind:"message",T:Xo,repeated:!0},{no:7,name:"experiment_config",kind:"message",T:Jl},{no:10,name:"model_name",kind:"scalar",T:9},{no:13,name:"multiline_config",kind:"message",T:Ul}])),Ce),jl=(Se=class extends X{constructor(n){super();p(this,"state");p(this,"completionItems",[]);N.util.initPartial(n,this)}static fromBinary(n,r){return new Se().fromBinary(n,r)}static fromJson(n,r){return new Se().fromJson(n,r)}static fromJsonString(n,r){return new Se().fromJsonString(n,r)}static equals(n,r){return N.util.equals(Se,n,r)}},p(Se,"runtime",N),p(Se,"typeName","exa.language_server_pb.GetCompletionsResponse"),p(Se,"fields",N.util.newFieldList(()=>[{no:1,name:"state",kind:"message",T:Wl},{no:2,name:"completion_items",kind:"message",T:ql,repeated:!0}])),Se),Pl=(xe=class extends X{constructor(n){super();p(this,"metadata");p(this,"completionId","");N.util.initPartial(n,this)}static fromBinary(n,r){return new xe().fromBinary(n,r)}static fromJson(n,r){return new xe().fromJson(n,r)}static fromJsonString(n,r){return new xe().fromJsonString(n,r)}static equals(n,r){return N.util.equals(xe,n,r)}},p(xe,"runtime",N),p(xe,"typeName","exa.language_server_pb.AcceptCompletionRequest"),p(xe,"fields",N.util.newFieldList(()=>[{no:1,name:"metadata",kind:"message",T:Fo},{no:2,name:"completion_id",kind:"scalar",T:9}])),xe),Ml=(Ae=class extends X{constructor(t){super(),N.util.initPartial(t,this)}static fromBinary(t,n){return new Ae().fromBinary(t,n)}static fromJson(t,n){return new Ae().fromJson(t,n)}static fromJsonString(t,n){return new Ae().fromJsonString(t,n)}static equals(t,n){return N.util.equals(Ae,t,n)}},p(Ae,"runtime",N),p(Ae,"typeName","exa.language_server_pb.AcceptCompletionResponse"),p(Ae,"fields",N.util.newFieldList(()=>[])),Ae),Rl=(Te=class extends X{constructor(t){super(),N.util.initPartial(t,this)}static fromBinary(t,n){return new Te().fromBinary(t,n)}static fromJson(t,n){return new Te().fromJson(t,n)}static fromJsonString(t,n){return new Te().fromJsonString(t,n)}static equals(t,n){return N.util.equals(Te,t,n)}},p(Te,"runtime",N),p(Te,"typeName","exa.language_server_pb.GetAuthTokenRequest"),p(Te,"fields",N.util.newFieldList(()=>[])),Te),Gl=(Ie=class extends X{constructor(n){super();p(this,"authToken","");p(this,"uuid","");N.util.initPartial(n,this)}static fromBinary(n,r){return new Ie().fromBinary(n,r)}static fromJson(n,r){return new Ie().fromJson(n,r)}static fromJsonString(n,r){return new Ie().fromJsonString(n,r)}static equals(n,r){return N.util.equals(Ie,n,r)}},p(Ie,"runtime",N),p(Ie,"typeName","exa.language_server_pb.GetAuthTokenResponse"),p(Ie,"fields",N.util.newFieldList(()=>[{no:1,name:"auth_token",kind:"scalar",T:9},{no:2,name:"uuid",kind:"scalar",T:9}])),Ie),Qn=(Fe=class extends X{constructor(n){super();p(this,"row",J.zero);p(this,"col",J.zero);N.util.initPartial(n,this)}static fromBinary(n,r){return new Fe().fromBinary(n,r)}static fromJson(n,r){return new Fe().fromJson(n,r)}static fromJsonString(n,r){return new Fe().fromJsonString(n,r)}static equals(n,r){return N.util.equals(Fe,n,r)}},p(Fe,"runtime",N),p(Fe,"typeName","exa.language_server_pb.DocumentPosition"),p(Fe,"fields",N.util.newFieldList(()=>[{no:1,name:"row",kind:"scalar",T:4},{no:2,name:"col",kind:"scalar",T:4}])),Fe),Xo=(Le=class extends X{constructor(n){super();p(this,"absolutePath","");p(this,"relativePath","");p(this,"text","");p(this,"editorLanguage","");p(this,"language",it.UNSPECIFIED);p(this,"cursorOffset",J.zero);p(this,"cursorPosition");p(this,"lineEnding","");N.util.initPartial(n,this)}static fromBinary(n,r){return new Le().fromBinary(n,r)}static fromJson(n,r){return new Le().fromJson(n,r)}static fromJsonString(n,r){return new Le().fromJsonString(n,r)}static equals(n,r){return N.util.equals(Le,n,r)}},p(Le,"runtime",N),p(Le,"typeName","exa.language_server_pb.Document"),p(Le,"fields",N.util.newFieldList(()=>[{no:1,name:"absolute_path",kind:"scalar",T:9},{no:2,name:"relative_path",kind:"scalar",T:9},{no:3,name:"text",kind:"scalar",T:9},{no:4,name:"editor_language",kind:"scalar",T:9},{no:5,name:"language",kind:"enum",T:N.getEnumType(it)},{no:6,name:"cursor_offset",kind:"scalar",T:4},{no:8,name:"cursor_position",kind:"message",T:Qn},{no:7,name:"line_ending",kind:"scalar",T:9}])),Le),Jl=(Oe=class extends X{constructor(n){super();p(this,"forceEnableExperiments",[]);N.util.initPartial(n,this)}static fromBinary(n,r){return new Oe().fromBinary(n,r)}static fromJson(n,r){return new Oe().fromJson(n,r)}static fromJsonString(n,r){return new Oe().fromJsonString(n,r)}static equals(n,r){return N.util.equals(Oe,n,r)}},p(Oe,"runtime",N),p(Oe,"typeName","exa.language_server_pb.ExperimentConfig"),p(Oe,"fields",N.util.newFieldList(()=>[{no:1,name:"force_enable_experiments",kind:"enum",T:N.getEnumType(Yn),repeated:!0}])),Oe),Wl=(De=class extends X{constructor(n){super();p(this,"state",fn.UNSPECIFIED);p(this,"message","");N.util.initPartial(n,this)}static fromBinary(n,r){return new De().fromBinary(n,r)}static fromJson(n,r){return new De().fromJson(n,r)}static fromJsonString(n,r){return new De().fromJsonString(n,r)}static equals(n,r){return N.util.equals(De,n,r)}},p(De,"runtime",N),p(De,"typeName","exa.language_server_pb.State"),p(De,"fields",N.util.newFieldList(()=>[{no:1,name:"state",kind:"enum",T:N.getEnumType(fn)},{no:2,name:"message",kind:"scalar",T:9}])),De),Vl=(_e=class extends X{constructor(n){super();p(this,"startOffset",J.zero);p(this,"endOffset",J.zero);p(this,"startPosition");p(this,"endPosition");N.util.initPartial(n,this)}static fromBinary(n,r){return new _e().fromBinary(n,r)}static fromJson(n,r){return new _e().fromJson(n,r)}static fromJsonString(n,r){return new _e().fromJsonString(n,r)}static equals(n,r){return N.util.equals(_e,n,r)}},p(_e,"runtime",N),p(_e,"typeName","exa.language_server_pb.Range"),p(_e,"fields",N.util.newFieldList(()=>[{no:1,name:"start_offset",kind:"scalar",T:4},{no:2,name:"end_offset",kind:"scalar",T:4},{no:3,name:"start_position",kind:"message",T:Qn},{no:4,name:"end_position",kind:"message",T:Qn}])),_e),$l=(Ue=class extends X{constructor(n){super();p(this,"text","");p(this,"deltaCursorOffset",J.zero);N.util.initPartial(n,this)}static fromBinary(n,r){return new Ue().fromBinary(n,r)}static fromJson(n,r){return new Ue().fromJson(n,r)}static fromJsonString(n,r){return new Ue().fromJsonString(n,r)}static equals(n,r){return N.util.equals(Ue,n,r)}},p(Ue,"runtime",N),p(Ue,"typeName","exa.language_server_pb.Suffix"),p(Ue,"fields",N.util.newFieldList(()=>[{no:1,name:"text",kind:"scalar",T:9},{no:2,name:"delta_cursor_offset",kind:"scalar",T:3}])),Ue),Hl=(Be=class extends X{constructor(n){super();p(this,"text","");p(this,"offset",J.zero);p(this,"type",mn.UNSPECIFIED);p(this,"prefix","");p(this,"line",J.zero);N.util.initPartial(n,this)}static fromBinary(n,r){return new Be().fromBinary(n,r)}static fromJson(n,r){return new Be().fromJson(n,r)}static fromJsonString(n,r){return new Be().fromJsonString(n,r)}static equals(n,r){return N.util.equals(Be,n,r)}},p(Be,"runtime",N),p(Be,"typeName","exa.language_server_pb.CompletionPart"),p(Be,"fields",N.util.newFieldList(()=>[{no:1,name:"text",kind:"scalar",T:9},{no:2,name:"offset",kind:"scalar",T:4},{no:3,name:"type",kind:"enum",T:N.getEnumType(mn)},{no:4,name:"prefix",kind:"scalar",T:9},{no:5,name:"line",kind:"scalar",T:4}])),Be),ql=(je=class extends X{constructor(n){super();p(this,"completion");p(this,"suffix");p(this,"range");p(this,"source",sn.UNSPECIFIED);p(this,"completionParts",[]);N.util.initPartial(n,this)}static fromBinary(n,r){return new je().fromBinary(n,r)}static fromJson(n,r){return new je().fromJson(n,r)}static fromJsonString(n,r){return new je().fromJsonString(n,r)}static equals(n,r){return N.util.equals(je,n,r)}},p(je,"runtime",N),p(je,"typeName","exa.language_server_pb.CompletionItem"),p(je,"fields",N.util.newFieldList(()=>[{no:1,name:"completion",kind:"message",T:tl},{no:5,name:"suffix",kind:"message",T:$l},{no:2,name:"range",kind:"message",T:Vl},{no:3,name:"source",kind:"enum",T:N.getEnumType(sn)},{no:8,name:"completion_parts",kind:"message",T:Hl,repeated:!0}])),je);const zl={typeName:"exa.language_server_pb.LanguageServerService",methods:{getCompletions:{name:"GetCompletions",I:Bl,O:jl,kind:ye.Unary},acceptCompletion:{name:"AcceptCompletion",I:Pl,O:Ml,kind:ye.Unary},getAuthToken:{name:"GetAuthToken",I:Rl,O:Gl,kind:ye.Unary}}};function Kl(){try{new Headers}catch{throw Error("connect-web requires the fetch API. Are you running on an old version of Node.js? Node.js is not supported in Connect for Web - please stay tuned for Connect for Node.")}}var Dt=function(e){return this instanceof Dt?(this.v=e,this):new Dt(e)},Yl=function(e,t,n){if(!Symbol.asyncIterator)throw TypeError("Symbol.asyncIterator is not defined.");var r=n.apply(e,t||[]),o,a=[];return o={},s("next"),s("throw"),s("return",i),o[Symbol.asyncIterator]=function(){return this},o;function i(m){return function(g){return Promise.resolve(g).then(m,f)}}function s(m,g){r[m]&&(o[m]=function(y){return new Promise(function(w,k){a.push([m,y,w,k])>1||c(m,y)})},g&&(o[m]=g(o[m])))}function c(m,g){try{u(r[m](g))}catch(y){h(a[0][3],y)}}function u(m){m.value instanceof Dt?Promise.resolve(m.value.v).then(d,f):h(a[0][2],m)}function d(m){c("next",m)}function f(m){c("throw",m)}function h(m,g){m(g),a.shift(),a.length&&c(a[0][0],a[0][1])}};function Xl(e){Kl();let t=e.useBinaryFormat??!1;return{async unary(n,r,o,a,i,s,c){let{serialize:u,parse:d}=Ro(r,t,e.jsonOptions,e.binaryOptions);return a=a===void 0?e.defaultTimeoutMs:a<=0?void 0:a,await Dl({interceptors:e.interceptors,signal:o,timeoutMs:a,req:{stream:!1,service:n,method:r,url:Bo(e.baseUrl,n,r),init:{method:"POST",credentials:e.credentials??"same-origin",redirect:"error",mode:"cors"},header:qo(r.kind,t,a,i,!1),contextValues:c??Uo(),message:s},next:async f=>{let h=e.useHttpGet===!0&&r.idempotency===Io.NoSideEffects,m=null;h?f=Ol(f,u(f.message),t):m=u(f.message);let g=await(e.fetch??globalThis.fetch)(f.url,Object.assign(Object.assign({},f.init),{headers:f.header,signal:f.signal,body:m})),{isUnaryError:y,unaryError:w}=zo(r.kind,t,g.status,g.headers);if(y)throw Wo(await g.json(),sl(...Ho(g.headers)),w);let[k,C]=Ho(g.headers);return{stream:!1,service:n,method:r,header:k,message:t?d(new Uint8Array(await g.arrayBuffer())):r.O.fromJson(await g.json(),Mo(e.jsonOptions)),trailer:C}}})},async stream(n,r,o,a,i,s,c){let{serialize:u,parse:d}=Ro(r,t,e.jsonOptions,e.binaryOptions);function f(m,g,y,w){return Yl(this,arguments,function*(){let k=cl(m).getReader(),C=!1;for(;;){let T=yield Dt(k.read());if(T.done)break;let{flags:L,data:U}=T.value;if((L&1)==1)throw new he("protocol error: received unsupported compressed output",M.Internal);if((L&2)==2){C=!0;let A=Tl(U);if(A.error){let x=A.error;throw y.forEach((G,ee)=>{x.metadata.append(ee,G)}),x}A.metadata.forEach((x,G)=>g.set(G,x));continue}yield yield Dt(d(U))}if("throwIfAborted"in w&&w.throwIfAborted(),!C)throw"missing EndStreamResponse"})}async function h(m){if(r.kind!=ye.ServerStreaming)throw"The fetch API does not support streaming request bodies";let g=await m[Symbol.asyncIterator]().next();if(g.done==1)throw"missing request message";return ul(0,u(g.value))}return a=a===void 0?e.defaultTimeoutMs:a<=0?void 0:a,await _l({interceptors:e.interceptors,timeoutMs:a,signal:o,req:{stream:!0,service:n,method:r,url:Bo(e.baseUrl,n,r),init:{method:"POST",credentials:e.credentials??"same-origin",redirect:"error",mode:"cors"},header:qo(r.kind,t,a,i,!1),contextValues:c??Uo(),message:s},next:async m=>{let g=await(e.fetch??globalThis.fetch)(m.url,Object.assign(Object.assign({},m.init),{headers:m.header,signal:m.signal,body:await h(m.message)}));if(zo(r.kind,t,g.status,g.headers),g.body===null)throw"missing response body";let y=new Headers;return Object.assign(Object.assign({},m),{header:g.headers,trailer:y,message:f(g.body,y,g.headers,m.signal)})}})}}}var Ql=yl(zl,Xl({baseUrl:"https://web-backend.codeium.com",useBinaryFormat:!0})),pn;try{pn=crypto.randomUUID()}catch{pn=function(){return"10000000-1000-4000-8000-100000000000".replace(/[018]/g,t=>(t^(crypto.getRandomValues(new Uint8Array(1))[0]??0)&15>>t/4).toString(16))}()}async function Zl({text:e,cursorOffset:t,config:n,otherDocuments:r}){return await Ql.getCompletions({metadata:{ideName:"web",ideVersion:"0.0.5",extensionName:"@valtown/codemirror-codeium",extensionVersion:"1.0.0",apiKey:n.apiKey,sessionId:pn,authSource:n.authSource},document:{text:e,cursorOffset:BigInt(t),language:n.language,editorLanguage:"typescript",lineEnding:`
11
+ `},editorOptions:{tabSize:2n,insertSpaces:!0},otherDocuments:r,multilineConfig:void 0},{headers:{Authorization:`Basic ${n.apiKey}-${pn}`}})}function ec(e){return e.completionItems.map(t=>{let n=0;return t.completionParts.filter(r=>r.type!==3).map(r=>{let o=Number(r.offset),a=r.type===2?`
12
+ ${r.text}`:r.text,i={absoluteStartPos:n+o,absoluteEndPos:n+o+a.length,from:o,to:o,insert:a};return n+=a.length,i})})}async function tc(e,t){let n=e.state.facet(ln),{override:r}=e.state.facet(Lo),o=await r(),a=e.state,i=a.selection.main.head,s=a.doc.toString();try{let c=await Zl({text:s,cursorOffset:i,config:n,otherDocuments:o});if(!c||c.completionItems.length===0||!((t===void 0||i===t)&&Gt(e.state)!=="active"&&e.hasFocus))return;let u=ec(c),d=u.at(0);if(!d)return;let f=Tn.of(d,a.doc.length),h=f.invert(a.doc);e.dispatch({changes:f,effects:Jn.of({index:0,reverseChangeSet:h,changeSpecs:u}),annotations:[cn.of(null),ht.of(null),Rt.addToHistory.of(!1)]})}catch(c){console.warn("copilot completion failed",c),await new Promise(u=>setTimeout(u,300))}}function nc(e){return e.docChanged&&!e.transactions.some(t=>t.effects.some(n=>n.is(Wn)||n.is(Vn)))}function rc(e){if(!e.view.hasFocus||e.state.field(st)||Gt(e.state)==="active")return!0;for(let t of e.transactions)if(t.annotation(ht)!==void 0)return!0}function oc(){let e=null,t=0;return B.updateListener.of(n=>{let r=n.view.state.facet(ln);if(!r.alwaysOn||!nc(n)||(e&&clearTimeout(e),rc(n)))return;let o=n.state.selection.main.head;r.shouldComplete&&!r.shouldComplete(new Wf(n.view.state,o,!1))||(e=setTimeout(async()=>{o===t&&await tc(n.view,t)},r.timeout),t=o)})}function Qo(e){var o;let t=e.state.field(st);if(!t)return!1;let n=(o=t.reverseChangeSet)==null?void 0:o.invert(e.state.doc);e.dispatch({changes:t.reverseChangeSet,effects:Wn.of(null),annotations:[cn.of(null),ht.of(null),Rt.addToHistory.of(!1)]});let r=0;return n==null||n.iterChangedRanges((a,i,s,c)=>{r=c}),e.dispatch({changes:n,selection:wt.cursor(r),annotations:[ht.of(null),Rt.addToHistory.of(!0)]}),!0}const Zo=e=>{let{state:t}=e,n=t.field(st);if(!n)return!1;let{changeSpecs:r}=n;if(r.length<2)return!1;let o=(n.index+1)%r.length,a=r.at(o);if(!a)return!1;let i=n.reverseChangeSet.apply(t.doc),s=Tn.of(n.reverseChangeSet,t.doc.length).compose(Tn.of(a,i.length)),c=Tn.of(a,i.length).invert(i);return e.dispatch({changes:s,effects:Jn.of({index:o,reverseChangeSet:c,changeSpecs:r}),annotations:[cn.of(null),ht.of(null),Rt.addToHistory.of(!1)]}),!0};function Zn(e){let t=e.state.field(st);return t&&e.dispatch({changes:t.reverseChangeSet,effects:Vn.of(null),annotations:[cn.of(null),ht.of(null),Rt.addToHistory.of(!1)]}),!1}function ac(e,t){return e.state.field(st)?t==="Tab"?Qo(e):Zn(e):!1}function ic(e){var o,a;let t=!1,n=(o=e.state.selection.asSingle().ranges.at(0))==null?void 0:o.head,r=e.state.field(st);return n!==void 0&&r?((a=r.decorations)==null||a.between(n,n,()=>{t=!0}),t):!1}function sc(){return B.domEventHandlers({keydown(e,t){return e.key==="]"&&e.ctrlKey?!1:e.key!=="Shift"&&e.key!=="Control"&&e.key!=="Alt"&&e.key!=="Meta"?ac(t,e.key):!1},mouseup(e,t){let n=e.target;return n.nodeName==="BUTTON"&&n.dataset.action==="codeium-cycle"?(Zo(t),e.stopPropagation(),e.preventDefault(),!0):ic(t)?Qo(t):Zn(t)}})}function lc(){return Je.of([{key:"Ctrl-]",run:Zo}])}function cc(){return B.updateListener.of(e=>{e.focusChanged&&Zn(e.view)})}function uc(e){return[ln.of(e),st,ut.highest(lc()),ut.highest(cc()),ut.high(sc()),oc()]}function dc({response:e,prefix:t,suffix:n}){if(!e)return e;let r=e;return t&&r.startsWith(t)&&(r=r.slice(t.length)),n&&r.endsWith(n)&&(r=r.slice(0,-n.length)),r}var fc=pd(),mc=new ff,er=$e.get("@github/copilot-language-server"),ea={delay:300,includeKeymap:!0,events:{shouldShowSuggestion:e=>e.hasFocus,beforeSuggestionFetch:e=>e.hasFocus}};const pc=e=>{let t=[];return e.copilot==="codeium"&&e.codeium_api_key&&t.push(uc({apiKey:e.codeium_api_key,language:it.PYTHON}),Lo.of({override:async()=>[{text:Er(""),language:it.PYTHON,editorLanguage:"python"}]})),e.copilot==="github"&&t.push(Kr({...ea,fetchFn:async(n,r,o)=>{let a=n.selection.main.head;if(!Jd()||!o.hasFocus||n.doc.length===0)return"";await new Promise(c=>setTimeout(c,20));let i=hc(n,Er(n.doc.toString())),s=await Gd().getCompletion(i);return a===o.state.selection.main.head?gc(s,i.position,n):($e.debug("ignoring response because of new position"),"")}})),e.copilot==="custom"&&t.push(Kr({...ea,fetchFn:async(n,r,o)=>{let a=n.selection.main.head;if(n.doc.length===0||!o.hasFocus)return"";let i=n.doc.sliceString(0,n.selection.main.head),s=n.doc.sliceString(n.selection.main.head,n.doc.length);if(i.length===0)return"";let c=n.field(xn).type,u=await Zd.post("/ai/inline_completion",{prefix:i,suffix:s,language:c});return a===o.state.selection.main.head?(u=dc({response:u,prefix:i,suffix:s}),u):($e.debug("ignoring response because of new position"),"")}})),[...t,ut.highest(Je.of([{key:"Escape",run:n=>{let r=zr(n);return Cn(n)?!1:r}}])),mc.of(Rd())]};function hc(e,t){let n=e.doc.toString(),r=t.split(`
13
13
  `).length-n.split(`
14
- `).length,o=Ec(e.doc,e.selection.main.head);return o.line+=r,{textDocument:{uri:`file://${qd}`,version:"replace_me"},position:o,context:{triggerKind:gc.InlineCompletionTriggerKind.Automatic},formattingOptions:{tabSize:e.tabSize,insertSpaces:!0}}}function vc(e,t,n){if(!e)return er.debug("No response from copilot"),"";let r=Array.isArray(e)?e[0]:e.items[0];if(!r)return er.debug("No response from copilot"),"";let{insertText:o,range:a}=r,i=String(o);if(!a)return er.error("No range from copilot"),i;let s=a.start.character-t.character,c=s<0?i.slice(-s):i,u=n.doc.sliceString(n.selection.main.head,n.doc.length);for(let d=0;d<c.length;d++){let f=c.slice(d);if(u.startsWith(f))return c.slice(0,d)}return c}function Ec(e,t){let n=e.lineAt(t);return{line:n.number-1,character:t-n.from}}Un=function(e){return yt("create"in e,'Expected query to have a "create" method'),e},be=pd({findText:"",replaceText:"",caseSensitive:!1,wholeWord:!1,regexp:!1,isOpen:!1,currentView:void 0},(e,t)=>{if(t===void 0)return e;switch(t.type){case"setFind":return{...e,findText:t.find};case"setReplace":return{...e,replaceText:t.replace};case"setCaseSensitive":return{...e,caseSensitive:t.caseSensitive};case"setWholeWord":return{...e,wholeWord:t.wholeWord};case"setRegex":return{...e,regexp:t.regexp};case"setIsOpen":return{...e,isOpen:t.isOpen};case"setCurrentView":return{...e,currentView:{view:t.view,range:t.range}};case"clearCurrentView":return{...e,currentView:void 0}}}),Jr=function(e){if([...document.querySelectorAll('[role="dialog"][data-state="open"]')].some(t=>t instanceof HTMLElement&&t.childNodes.length>0))return!1;if(e){let t=e.state.selection.main,n=e.state.sliceDoc(t.from,t.to);n?(Q.set(be,{type:"setFind",find:n}),Q.set(be,{type:"setCurrentView",view:e,range:{from:t.from,to:t.to}})):Q.set(be,{type:"setCurrentView",view:e,range:{from:0,to:0}})}return Q.get(be).isOpen?(Q.set(be,{type:"setIsOpen",isOpen:!1}),requestAnimationFrame(()=>{Q.set(be,{type:"setIsOpen",isOpen:!0})}),!0):(Q.set(be,{type:"setIsOpen",isOpen:!0}),!0)};function Nc(){return Q.get(be).isOpen?(Q.set(be,{type:"setIsOpen",isOpen:!1}),!0):!1}var tr=pe.define();Di=function(){let e=Q.get(be),t=$a();for(let n of t)n.state.readOnly||n.dispatch({effects:tr.of(new Lr({search:e.findText,caseSensitive:e.caseSensitive,regexp:e.regexp,replace:e.replaceText,wholeWord:e.wholeWord}))})},_i=function(){let e=$a();for(let t of e)t.state.readOnly||t.dispatch({effects:tr.of(new Lr({search:""}))})};const hn=qe.define({create(){let e=Q.get(be);return Un(new Lr({search:e.findText,caseSensitive:e.caseSensitive,regexp:e.regexp,replace:e.replaceText,wholeWord:e.wholeWord})).create()},update(e,t){for(let n of t.effects)n.is(tr)&&(e=Un(n.value).create());return e}});var kc=H.mark({class:"cm-searchMatch"}),Cc=H.mark({class:"cm-searchMatch cm-searchMatch-selected"}),Sc=250;const xc=ze.fromClass(class{constructor(e){this.view=e,this.decorations=this.highlight(e.state.field(hn))}update(e){let t=e.state.field(hn);(t!==e.startState.field(hn)||e.docChanged||e.selectionSet||e.viewportChanged)&&(this.decorations=this.highlight(t))}highlight(e){if(!e.spec.valid)return H.none;let{view:t}=this,n=new ff,r=t.visibleRanges,o=r.length;for(let a=0;a<o;a++){let{to:i}=r[a],{from:s}=r[a];for(;a<o-1&&i>r[a+1].from-2*Sc;)i=r[++a].to;e.highlight(t.state,s,i,(c,u)=>{let d=t.state.selection.ranges.some(f=>f.from===c&&f.to===u);n.add(c,u,d?Cc:kc)})}return n.finish()}},{decorations:e=>e.decorations}),Ac=B.baseTheme({"&light .cm-searchMatch":{backgroundColor:"#99ff7780"},"&dark .cm-searchMatch":{backgroundColor:"#22bb0070"},"&light .cm-searchMatch-selected":{backgroundColor:"transparent"},"&dark .cm-searchMatch.cm-searchMatch-selected":{backgroundColor:"#6199ff88 !important"}});function Tc(e){return[Je.of([{key:"Escape",preventDefault:!1,run:Nc},{key:e.getHotkey("cell.selectNextOccurrence").key,preventDefault:!0,run:Df},{key:e.getHotkey("cell.findAndReplace").key,preventDefault:!0,run:Jr}]),Uf(),xc,hn,Ac]}var Ic=H.mark({class:"underline"}),na=pe.define(),ra=pe.define(),oa=pe.define();const Fc=qe.define({create(){return H.none},update(e,t){let n=e.map(t.changes);for(let r of t.effects)r.is(na)?n=e.update({add:[Ic.range(r.value.from,r.value.to)]}):r.is(ra)?n=e.update({add:[Sd.range(r.value.from,r.value.to)]}):r.is(oa)&&(n=H.none);return n},provide:e=>B.decorations.from(e)});var Lc=class{constructor(e,t){p(this,"keydown",e=>{(e.key==="Meta"||e.key==="Control")&&(this.commandClickMode=!0,this.view.dom.addEventListener("mousemove",this.mousemove),this.view.dom.addEventListener("click",this.click))});p(this,"keyup",e=>{(e.key==="Meta"||e.key==="Control")&&this.exitCommandClickMode()});p(this,"windowBlur",()=>{this.commandClickMode&&this.exitCommandClickMode()});p(this,"mousemove",e=>{var o;if(!e.metaKey&&!e.ctrlKey){this.exitCommandClickMode();return}if(!this.commandClickMode){this.clearUnderline();return}let t=this.view.posAtCoords({x:e.clientX,y:e.clientY});if(t==null){this.clearUnderline();return}let n=(o=this.view.state.field(dd,!1))==null?void 0:o.ranges.find(a=>t>=a.from&&t<=a.to);if(n){let{from:a,to:i}=n;if(this.hoveredRange&&this.hoveredRange.from===a&&this.hoveredRange.to===i)return;this.clearUnderline(),this.hoveredRange={from:a,to:i,position:t},this.view.dispatch({effects:ra.of(this.hoveredRange)});return}let r=mf(this.view.state).cursorAt(t);if(r.name==="VariableName"){let{from:a,to:i}=r;if(this.hoveredRange&&this.hoveredRange.from===a&&this.hoveredRange.to===i)return;this.clearUnderline(),this.hoveredRange={from:a,to:i,position:t},this.view.dispatch({effects:na.of(this.hoveredRange)})}else this.clearUnderline()});p(this,"click",e=>{if(this.hoveredRange){let t=this.view.state.doc.sliceString(this.hoveredRange.from,this.hoveredRange.to);e.preventDefault(),e.stopPropagation(),this.onClick(this.view,t),this.view.dispatch({selection:{head:this.hoveredRange.position,anchor:this.hoveredRange.position}})}});this.view=e,this.commandClickMode=!1,this.hoveredRange=null,this.onClick=t,window.addEventListener("keydown",this.keydown),window.addEventListener("keyup",this.keyup),window.addEventListener("blur",this.windowBlur),window.addEventListener("mouseleave",this.windowBlur)}update(e){}destroy(){window.removeEventListener("keydown",this.keydown),window.removeEventListener("keyup",this.keyup),window.removeEventListener("blur",this.windowBlur),window.removeEventListener("mouseleave",this.windowBlur),this.view.dom.removeEventListener("mousemove",this.mousemove),this.view.dom.removeEventListener("click",this.click)}exitCommandClickMode(){this.commandClickMode=!1,this.view.dom.removeEventListener("mousemove",this.mousemove),this.view.dom.removeEventListener("click",this.click),this.clearUnderline()}clearUnderline(){this.hoveredRange&&(this.hoveredRange=(this.view.dispatch({effects:oa.of(null)}),null))}};const Oc=e=>ze.define(t=>new Lc(t,e));function Dc(){return[Fc,Oc((e,t)=>{hd(e,t)}),B.baseTheme({".underline":{textDecoration:"underline",cursor:"pointer",color:"var(--link)"}})]}function _c(){return[B.domEventHandlers({drop:(e,t)=>{var o,a;let n=(o=e.dataTransfer)==null?void 0:o.files[0];if(n!=null&&n.type.startsWith("text/"))return e.preventDefault(),bd(t,n),!0;if(n!=null&&n.type.startsWith("image/"))return e.preventDefault(),Ud(t,n),!0;let r=(a=e.dataTransfer)==null?void 0:a.getData("text/plain");if(r){e.preventDefault();let i=t.posAtCoords({x:e.clientX,y:e.clientY});return i!==null&&t.dispatch({changes:{from:i,to:i,insert:r},scrollIntoView:!0}),!0}return!1},dragover:e=>{e.preventDefault()}})]}function Uc(){return[B.domEventHandlers({paste:(e,t)=>{var o;let n=(o=e.clipboardData)==null?void 0:o.getData("text/plain");if(!(n!=null&&n.includes("@app.cell")))return!1;let r=Bc(n);return r.length===0?!1:(t.state.facet(Od).createManyBelow(r),!0)}})]}function Bc(e){if(!e.includes("@app.cell"))return[];let t=[],n=e.split(`
15
- `),r=[],o=!1,a=0,i=!1,s=!1,c=0,u=/\(/g,d=/\)/g,f=new Set(["@"]);function h(g){return(g.match(u)||[]).length-(g.match(d)||[]).length}function m(){if(r.length!==0){for(;r.length>0&&r[r.length-1].trim().startsWith("return");)r.pop();r.some(g=>g.trim()!=="")&&t.push(jc(r.join(`
16
- `))),r=[]}}for(let g of n){let y=g.trim();if(!(!y&&!o)){if(y.startsWith("@app.cell")){m(),o=!0,a=1;continue}if(a>0){y.startsWith("def")&&y.includes("(")&&!y.includes("):")&&(i=!0,c=h(y)),a--;continue}if(i){c+=h(y),c===0&&(i=!1);continue}if(o){if(f.has(y[0])||y.startsWith("if __name__")){m(),o=y.startsWith("@");continue}if(y.startsWith("return")){y.includes("(")&&!y.endsWith(")")&&(s=!0,c=h(y));continue}if(s){c+=h(y),c===0&&(s=!1);continue}r.push(g)}}}return m(),t}function jc(e){let t=e.split(`
14
+ `).length,o=bc(e.doc,e.selection.main.head);return o.line+=r,{textDocument:{uri:`file://${Wd}`,version:"replace_me"},position:o,context:{triggerKind:fc.InlineCompletionTriggerKind.Automatic},formattingOptions:{tabSize:e.tabSize,insertSpaces:!0}}}function gc(e,t,n){if(!e)return er.debug("No response from copilot"),"";let r=Array.isArray(e)?e[0]:e.items[0];if(!r)return er.debug("No response from copilot"),"";let{insertText:o,range:a}=r,i=String(o);if(!a)return er.error("No range from copilot"),i;let s=a.start.character-t.character,c=s<0?i.slice(-s):i,u=n.doc.sliceString(n.selection.main.head,n.doc.length);for(let d=0;d<c.length;d++){let f=c.slice(d);if(u.startsWith(f))return c.slice(0,d)}return c}function bc(e,t){let n=e.lineAt(t);return{line:n.number-1,character:t-n.from}}On=function(e){return Pt("create"in e,'Expected query to have a "create" method'),e},be=ud({findText:"",replaceText:"",caseSensitive:!1,wholeWord:!1,regexp:!1,isOpen:!1,currentView:void 0},(e,t)=>{if(t===void 0)return e;switch(t.type){case"setFind":return{...e,findText:t.find};case"setReplace":return{...e,replaceText:t.replace};case"setCaseSensitive":return{...e,caseSensitive:t.caseSensitive};case"setWholeWord":return{...e,wholeWord:t.wholeWord};case"setRegex":return{...e,regexp:t.regexp};case"setIsOpen":return{...e,isOpen:t.isOpen};case"setCurrentView":return{...e,currentView:{view:t.view,range:t.range}};case"clearCurrentView":return{...e,currentView:void 0}}}),Rr=function(e){if([...document.querySelectorAll('[role="dialog"][data-state="open"]')].some(t=>t instanceof HTMLElement&&t.childNodes.length>0))return!1;if(e){let t=e.state.selection.main,n=e.state.sliceDoc(t.from,t.to);n?(Q.set(be,{type:"setFind",find:n}),Q.set(be,{type:"setCurrentView",view:e,range:{from:t.from,to:t.to}})):Q.set(be,{type:"setCurrentView",view:e,range:{from:0,to:0}})}return Q.get(be).isOpen?(Q.set(be,{type:"setIsOpen",isOpen:!1}),requestAnimationFrame(()=>{Q.set(be,{type:"setIsOpen",isOpen:!0})}),!0):(Q.set(be,{type:"setIsOpen",isOpen:!0}),!0)};function yc(){return Q.get(be).isOpen?(Q.set(be,{type:"setIsOpen",isOpen:!1}),!0):!1}var tr=pe.define();Di=function(){let e=Q.get(be),t=Wa();for(let n of t)n.state.readOnly||n.dispatch({effects:tr.of(new Lr({search:e.findText,caseSensitive:e.caseSensitive,regexp:e.regexp,replace:e.replaceText,wholeWord:e.wholeWord}))})},Fi=function(){let e=Wa();for(let t of e)t.state.readOnly||t.dispatch({effects:tr.of(new Lr({search:""}))})};const hn=qe.define({create(){let e=Q.get(be);return On(new Lr({search:e.findText,caseSensitive:e.caseSensitive,regexp:e.regexp,replace:e.replaceText,wholeWord:e.wholeWord})).create()},update(e,t){for(let n of t.effects)n.is(tr)&&(e=On(n.value).create());return e}});var wc=H.mark({class:"cm-searchMatch"}),vc=H.mark({class:"cm-searchMatch cm-searchMatch-selected"}),Ec=250;const Nc=ze.fromClass(class{constructor(e){this.view=e,this.decorations=this.highlight(e.state.field(hn))}update(e){let t=e.state.field(hn);(t!==e.startState.field(hn)||e.docChanged||e.selectionSet||e.viewportChanged)&&(this.decorations=this.highlight(t))}highlight(e){if(!e.spec.valid)return H.none;let{view:t}=this,n=new lf,r=t.visibleRanges,o=r.length;for(let a=0;a<o;a++){let{to:i}=r[a],{from:s}=r[a];for(;a<o-1&&i>r[a+1].from-2*Ec;)i=r[++a].to;e.highlight(t.state,s,i,(c,u)=>{let d=t.state.selection.ranges.some(f=>f.from===c&&f.to===u);n.add(c,u,d?vc:wc)})}return n.finish()}},{decorations:e=>e.decorations}),kc=B.baseTheme({"&light .cm-searchMatch":{backgroundColor:"#99ff7780"},"&dark .cm-searchMatch":{backgroundColor:"#22bb0070"},"&light .cm-searchMatch-selected":{backgroundColor:"transparent"},"&dark .cm-searchMatch.cm-searchMatch-selected":{backgroundColor:"#6199ff88 !important"}});function Cc(e){return[Je.of([{key:"Escape",preventDefault:!1,run:yc},{key:e.getHotkey("cell.selectNextOccurrence").key,preventDefault:!0,run:If},{key:e.getHotkey("cell.findAndReplace").key,preventDefault:!0,run:Rr}]),Lf(),Nc,hn,kc]}var Sc=H.mark({class:"underline"}),ta=pe.define(),na=pe.define(),ra=pe.define();const xc=qe.define({create(){return H.none},update(e,t){let n=e.map(t.changes);for(let r of t.effects)r.is(ta)?n=e.update({add:[Sc.range(r.value.from,r.value.to)]}):r.is(na)?n=e.update({add:[Ed.range(r.value.from,r.value.to)]}):r.is(ra)&&(n=H.none);return n},provide:e=>B.decorations.from(e)});var Ac=class{constructor(e,t){p(this,"keydown",e=>{(e.key==="Meta"||e.key==="Control")&&(this.commandClickMode=!0,this.view.dom.addEventListener("mousemove",this.mousemove),this.view.dom.addEventListener("click",this.click))});p(this,"keyup",e=>{(e.key==="Meta"||e.key==="Control")&&this.exitCommandClickMode()});p(this,"windowBlur",()=>{this.commandClickMode&&this.exitCommandClickMode()});p(this,"mousemove",e=>{var o;if(!e.metaKey&&!e.ctrlKey){this.exitCommandClickMode();return}if(!this.commandClickMode){this.clearUnderline();return}let t=this.view.posAtCoords({x:e.clientX,y:e.clientY});if(t==null){this.clearUnderline();return}let n=(o=this.view.state.field(sd,!1))==null?void 0:o.ranges.find(a=>t>=a.from&&t<=a.to);if(n){let{from:a,to:i}=n;if(this.hoveredRange&&this.hoveredRange.from===a&&this.hoveredRange.to===i)return;this.clearUnderline(),this.hoveredRange={from:a,to:i,position:t},this.view.dispatch({effects:na.of(this.hoveredRange)});return}let r=cf(this.view.state).cursorAt(t);if(r.name==="VariableName"){let{from:a,to:i}=r;if(this.hoveredRange&&this.hoveredRange.from===a&&this.hoveredRange.to===i)return;this.clearUnderline(),this.hoveredRange={from:a,to:i,position:t},this.view.dispatch({effects:ta.of(this.hoveredRange)})}else this.clearUnderline()});p(this,"click",e=>{if(this.hoveredRange){let t=this.view.state.doc.sliceString(this.hoveredRange.from,this.hoveredRange.to);e.preventDefault(),e.stopPropagation(),this.onClick(this.view,t),this.view.dispatch({selection:{head:this.hoveredRange.position,anchor:this.hoveredRange.position}})}});this.view=e,this.commandClickMode=!1,this.hoveredRange=null,this.onClick=t,window.addEventListener("keydown",this.keydown),window.addEventListener("keyup",this.keyup),window.addEventListener("blur",this.windowBlur),window.addEventListener("mouseleave",this.windowBlur)}update(e){}destroy(){window.removeEventListener("keydown",this.keydown),window.removeEventListener("keyup",this.keyup),window.removeEventListener("blur",this.windowBlur),window.removeEventListener("mouseleave",this.windowBlur),this.view.dom.removeEventListener("mousemove",this.mousemove),this.view.dom.removeEventListener("click",this.click)}exitCommandClickMode(){this.commandClickMode=!1,this.view.dom.removeEventListener("mousemove",this.mousemove),this.view.dom.removeEventListener("click",this.click),this.clearUnderline()}clearUnderline(){this.hoveredRange&&(this.hoveredRange=(this.view.dispatch({effects:ra.of(null)}),null))}};const Tc=e=>ze.define(t=>new Ac(t,e));function Ic(){return[xc,Tc((e,t)=>{dd(e,t)}),B.baseTheme({".underline":{textDecoration:"underline",cursor:"pointer",color:"var(--link)"}})]}function Fc(){return[B.domEventHandlers({drop:(e,t)=>{var o,a;let n=(o=e.dataTransfer)==null?void 0:o.files[0];if(n!=null&&n.type.startsWith("text/"))return e.preventDefault(),md(t,n),!0;if(n!=null&&n.type.startsWith("image/"))return e.preventDefault(),Ld(t,n),!0;let r=(a=e.dataTransfer)==null?void 0:a.getData("text/plain");if(r){e.preventDefault();let i=t.posAtCoords({x:e.clientX,y:e.clientY});return i!==null&&t.dispatch({changes:{from:i,to:i,insert:r},scrollIntoView:!0}),!0}return!1},dragover:e=>{e.preventDefault()}})]}function Lc(){return[B.domEventHandlers({paste:(e,t)=>{var o;let n=(o=e.clipboardData)==null?void 0:o.getData("text/plain");if(!(n!=null&&n.includes("@app.cell")))return!1;let r=Oc(n);return r.length===0?!1:(t.state.facet(Td).createManyBelow(r),!0)}})]}function Oc(e){if(!e.includes("@app.cell"))return[];let t=[],n=e.split(`
15
+ `),r=[],o=!1,a=0,i=!1,s=!1,c=0,u=/\(/g,d=/\)/g,f=new Set(["@"]);function h(g){return(g.match(u)||[]).length-(g.match(d)||[]).length}function m(){if(r.length!==0){for(;r.length>0&&r[r.length-1].trim().startsWith("return");)r.pop();r.some(g=>g.trim()!=="")&&t.push(Dc(r.join(`
16
+ `))),r=[]}}for(let g of n){let y=g.trim();if(!(!y&&!o)){if(y.startsWith("@app.cell")){m(),o=!0,a=1;continue}if(a>0){y.startsWith("def")&&y.includes("(")&&!y.includes("):")&&(i=!0,c=h(y)),a--;continue}if(i){c+=h(y),c===0&&(i=!1);continue}if(o){if(f.has(y[0])||y.startsWith("if __name__")){m(),o=y.startsWith("@");continue}if(y.startsWith("return")){y.includes("(")&&!y.endsWith(")")&&(s=!0,c=h(y));continue}if(s){c+=h(y),c===0&&(s=!1);continue}r.push(g)}}}return m(),t}function Dc(e){let t=e.split(`
17
17
  `);if(t.length===0)return"";let n=t.filter(a=>a.trim().length>0);if(n.length===0)return"";let r=/^\s*/,o=Math.min(...n.map(a=>{var i;return((i=a.match(r))==null?void 0:i[0].length)??1/0}));return o===0?e.trim():t.map(a=>a.slice(o)).join(`
18
- `).trim()}var ae=({variant:e,settings:t,styles:n})=>[B.theme({"&":{backgroundColor:t.background,color:t.foreground},".cm-content":{caretColor:t.caret},".cm-cursor, .cm-dropCursor":{borderLeftColor:t.caret},"&.cm-focused .cm-selectionBackgroundm .cm-selectionBackground, .cm-content ::selection":{backgroundColor:t.selection},".cm-activeLine":{backgroundColor:t.lineHighlight},".cm-gutters":{backgroundColor:t.gutterBackground,color:t.gutterForeground},".cm-activeLineGutter":{backgroundColor:t.lineHighlight}},{dark:e==="dark"}),oi(yf.define(n))];ae({variant:"dark",settings:{background:"#200020",foreground:"#D0D0FF",caret:"#7070FF",selection:"#80000080",gutterBackground:"#200020",gutterForeground:"#C080C0",lineHighlight:"#80000040"},styles:[{tag:l.comment,color:"#404080"},{tag:[l.string,l.regexp],color:"#999999"},{tag:l.number,color:"#7090B0"},{tag:[l.bool,l.null],color:"#8080A0"},{tag:[l.punctuation,l.derefOperator],color:"#805080"},{tag:l.keyword,color:"#60B0FF"},{tag:l.definitionKeyword,color:"#B0FFF0"},{tag:l.moduleKeyword,color:"#60B0FF"},{tag:l.operator,color:"#A0A0FF"},{tag:[l.variableName,l.self],color:"#008080"},{tag:l.operatorKeyword,color:"#A0A0FF"},{tag:l.controlKeyword,color:"#80A0FF"},{tag:l.className,color:"#70E080"},{tag:[l.function(l.propertyName),l.propertyName],color:"#50A0A0"},{tag:l.tagName,color:"#009090"},{tag:l.modifier,color:"#B0FFF0"},{tag:[l.squareBracket,l.attributeName],color:"#D0D0FF"}]}),ae({variant:"light",settings:{background:"#fcfcfc",foreground:"#5c6166",caret:"#ffaa33",selection:"#036dd626",gutterBackground:"#fcfcfc",gutterForeground:"#8a919966",lineHighlight:"#8a91991a"},styles:[{tag:l.comment,color:"#787b8099"},{tag:l.string,color:"#86b300"},{tag:l.regexp,color:"#4cbf99"},{tag:[l.number,l.bool,l.null],color:"#ffaa33"},{tag:l.variableName,color:"#5c6166"},{tag:[l.definitionKeyword,l.modifier],color:"#fa8d3e"},{tag:[l.keyword,l.special(l.brace)],color:"#fa8d3e"},{tag:l.operator,color:"#ed9366"},{tag:l.separator,color:"#5c6166b3"},{tag:l.punctuation,color:"#5c6166"},{tag:[l.definition(l.propertyName),l.function(l.variableName)],color:"#f2ae49"},{tag:[l.className,l.definition(l.typeName)],color:"#22a4e6"},{tag:[l.tagName,l.typeName,l.self,l.labelName],color:"#55b4d4"},{tag:l.angleBracket,color:"#55b4d480"},{tag:l.attributeName,color:"#f2ae49"}]}),ae({variant:"dark",settings:{background:"#15191EFA",foreground:"#EEF2F7",caret:"#C4C4C4",selection:"#90B2D557",gutterBackground:"#15191EFA",gutterForeground:"#aaaaaa95",lineHighlight:"#57575712"},styles:[{tag:l.comment,color:"#6E6E6E"},{tag:[l.string,l.regexp,l.special(l.brace)],color:"#5C81B3"},{tag:l.number,color:"#C1E1B8"},{tag:l.bool,color:"#53667D"},{tag:[l.definitionKeyword,l.modifier,l.function(l.propertyName)],color:"#A3D295",fontWeight:"bold"},{tag:[l.keyword,l.moduleKeyword,l.operatorKeyword,l.operator],color:"#697A8E",fontWeight:"bold"},{tag:[l.variableName,l.attributeName],color:"#708E67"},{tag:[l.function(l.variableName),l.definition(l.propertyName),l.derefOperator],color:"#fff"},{tag:l.tagName,color:"#A3D295"}]}),ae({variant:"dark",settings:{background:"#2e241d",foreground:"#BAAE9E",caret:"#A7A7A7",selection:"#DDF0FF33",gutterBackground:"#28211C",gutterForeground:"#BAAE9E90",lineHighlight:"#FFFFFF08"},styles:[{tag:l.comment,color:"#666666"},{tag:[l.string,l.special(l.brace)],color:"#54BE0D"},{tag:l.regexp,color:"#E9C062"},{tag:l.number,color:"#CF6A4C"},{tag:[l.keyword,l.operator],color:"#5EA6EA"},{tag:l.variableName,color:"#7587A6"},{tag:[l.definitionKeyword,l.modifier],color:"#F9EE98"},{tag:[l.propertyName,l.function(l.variableName)],color:"#937121"},{tag:[l.typeName,l.angleBracket,l.tagName],color:"#9B859D"}]}),ae({variant:"dark",settings:{background:"#3b2627",foreground:"#E6E1C4",caret:"#E6E1C4",selection:"#16120E",gutterBackground:"#3b2627",gutterForeground:"#E6E1C490",lineHighlight:"#1F1611"},styles:[{tag:l.comment,color:"#6B4E32"},{tag:[l.keyword,l.operator,l.derefOperator],color:"#EF5D32"},{tag:l.className,color:"#EFAC32",fontWeight:"bold"},{tag:[l.typeName,l.propertyName,l.function(l.variableName),l.definition(l.variableName)],color:"#EFAC32"},{tag:l.definition(l.typeName),color:"#EFAC32",fontWeight:"bold"},{tag:l.labelName,color:"#EFAC32",fontWeight:"bold"},{tag:[l.number,l.bool],color:"#6C99BB"},{tag:[l.variableName,l.self],color:"#7DAF9C"},{tag:[l.string,l.special(l.brace),l.regexp],color:"#D9D762"},{tag:[l.angleBracket,l.tagName,l.attributeName],color:"#EFCB43"}]}),ae({variant:"dark",settings:{background:"#000205",foreground:"#FFFFFF",caret:"#E60065",selection:"#E60C6559",gutterBackground:"#000205",gutterForeground:"#ffffff90",lineHighlight:"#4DD7FC1A"},styles:[{tag:l.comment,color:"#404040"},{tag:[l.string,l.special(l.brace),l.regexp],color:"#00D8FF"},{tag:l.number,color:"#E62286"},{tag:[l.variableName,l.attributeName,l.self],color:"#E62286",fontWeight:"bold"},{tag:l.function(l.variableName),color:"#fff",fontWeight:"bold"}]}),ae({variant:"light",settings:{background:"#fff",foreground:"#000",caret:"#000",selection:"#BDD5FC",gutterBackground:"#fff",gutterForeground:"#00000070",lineHighlight:"#FFFBD1"},styles:[{tag:l.comment,color:"#BCC8BA"},{tag:[l.string,l.special(l.brace),l.regexp],color:"#5D90CD"},{tag:[l.number,l.bool,l.null],color:"#46A609"},{tag:l.keyword,color:"#AF956F"},{tag:[l.definitionKeyword,l.modifier],color:"#C52727"},{tag:[l.angleBracket,l.tagName,l.attributeName],color:"#606060"},{tag:l.self,color:"#000"}]}),ae({variant:"dark",settings:{background:"#00254b",foreground:"#FFFFFF",caret:"#FFFFFF",selection:"#B36539BF",gutterBackground:"#00254b",gutterForeground:"#FFFFFF70",lineHighlight:"#00000059"},styles:[{tag:l.comment,color:"#0088FF"},{tag:l.string,color:"#3AD900"},{tag:l.regexp,color:"#80FFC2"},{tag:[l.number,l.bool,l.null],color:"#FF628C"},{tag:[l.definitionKeyword,l.modifier],color:"#FFEE80"},{tag:l.variableName,color:"#CCCCCC"},{tag:l.self,color:"#FF80E1"},{tag:[l.className,l.definition(l.propertyName),l.function(l.variableName),l.definition(l.typeName),l.labelName],color:"#FFDD00"},{tag:[l.keyword,l.operator],color:"#FF9D00"},{tag:[l.propertyName,l.typeName],color:"#80FFBB"},{tag:l.special(l.brace),color:"#EDEF7D"},{tag:l.attributeName,color:"#9EFFFF"},{tag:l.derefOperator,color:"#fff"}]}),ae({variant:"dark",settings:{background:"#060521",foreground:"#E0E0E0",caret:"#FFFFFFA6",selection:"#122BBB",gutterBackground:"#060521",gutterForeground:"#E0E0E090",lineHighlight:"#FFFFFF0F"},styles:[{tag:l.comment,color:"#AEAEAE"},{tag:[l.string,l.special(l.brace),l.regexp],color:"#8DFF8E"},{tag:[l.className,l.definition(l.propertyName),l.function(l.variableName),l.function(l.definition(l.variableName)),l.definition(l.typeName)],color:"#A3EBFF"},{tag:[l.number,l.bool,l.null],color:"#62E9BD"},{tag:[l.keyword,l.operator],color:"#2BF1DC"},{tag:[l.definitionKeyword,l.modifier],color:"#F8FBB1"},{tag:[l.variableName,l.self],color:"#B683CA"},{tag:[l.angleBracket,l.tagName,l.typeName,l.propertyName],color:"#60A4F1"},{tag:l.derefOperator,color:"#E0E0E0"},{tag:l.attributeName,color:"#7BACCA"}]}),ae({variant:"dark",settings:{background:"#2d2f3f",foreground:"#f8f8f2",caret:"#f8f8f0",selection:"#44475a",gutterBackground:"#282a36",gutterForeground:"rgb(144, 145, 148)",lineHighlight:"#44475a"},styles:[{tag:l.comment,color:"#6272a4"},{tag:[l.string,l.special(l.brace)],color:"#f1fa8c"},{tag:[l.number,l.self,l.bool,l.null],color:"#bd93f9"},{tag:[l.keyword,l.operator],color:"#ff79c6"},{tag:[l.definitionKeyword,l.typeName],color:"#8be9fd"},{tag:l.definition(l.typeName),color:"#f8f8f2"},{tag:[l.className,l.definition(l.propertyName),l.function(l.variableName),l.attributeName],color:"#50fa7b"}]}),ae({variant:"light",settings:{background:"#FFFFFF",foreground:"#000000",caret:"#000000",selection:"#80C7FF",gutterBackground:"#FFFFFF",gutterForeground:"#00000070",lineHighlight:"#C1E2F8"},styles:[{tag:l.comment,color:"#AAAAAA"},{tag:[l.keyword,l.operator,l.typeName,l.tagName,l.propertyName],color:"#2F6F9F",fontWeight:"bold"},{tag:[l.attributeName,l.definition(l.propertyName)],color:"#4F9FD0"},{tag:[l.className,l.string,l.special(l.brace)],color:"#CF4F5F"},{tag:l.number,color:"#CF4F5F",fontWeight:"bold"},{tag:l.variableName,fontWeight:"bold"}]}),ae({variant:"light",settings:{background:"#f2f1f8",foreground:"#0c006b",caret:"#5c49e9",selection:"#d5d1f2",gutterBackground:"#f2f1f8",gutterForeground:"#0c006b70",lineHighlight:"#e1def3"},styles:[{tag:l.comment,color:"#9995b7"},{tag:l.keyword,color:"#ff5792",fontWeight:"bold"},{tag:[l.definitionKeyword,l.modifier],color:"#ff5792"},{tag:[l.className,l.tagName,l.definition(l.typeName)],color:"#0094f0"},{tag:[l.number,l.bool,l.null,l.special(l.brace)],color:"#5842ff"},{tag:[l.definition(l.propertyName),l.function(l.variableName)],color:"#0095a8"},{tag:l.typeName,color:"#b3694d"},{tag:[l.propertyName,l.variableName],color:"#fa8900"},{tag:l.operator,color:"#ff5792"},{tag:l.self,color:"#e64100"},{tag:[l.string,l.regexp],color:"#00b368"},{tag:[l.paren,l.bracket],color:"#0431fa"},{tag:l.labelName,color:"#00bdd6"},{tag:l.attributeName,color:"#e64100"},{tag:l.angleBracket,color:"#9995b7"}]}),ae({variant:"light",settings:{background:"#faf4ed",foreground:"#575279",caret:"#575279",selection:"#6e6a8614",gutterBackground:"#faf4ed",gutterForeground:"#57527970",lineHighlight:"#6e6a860d"},styles:[{tag:l.comment,color:"#9893a5"},{tag:[l.bool,l.null],color:"#286983"},{tag:l.number,color:"#d7827e"},{tag:l.className,color:"#d7827e"},{tag:[l.angleBracket,l.tagName,l.typeName],color:"#56949f"},{tag:l.attributeName,color:"#907aa9"},{tag:l.punctuation,color:"#797593"},{tag:[l.keyword,l.modifier],color:"#286983"},{tag:[l.string,l.regexp],color:"#ea9d34"},{tag:l.variableName,color:"#d7827e"}]}),ae({variant:"light",settings:{background:"#FFFFFF",foreground:"#000000",caret:"#000000",selection:"#FFFD0054",gutterBackground:"#FFFFFF",gutterForeground:"#00000070",lineHighlight:"#00000008"},styles:[{tag:l.comment,color:"#CFCFCF"},{tag:[l.number,l.bool,l.null],color:"#E66C29"},{tag:[l.className,l.definition(l.propertyName),l.function(l.variableName),l.labelName,l.definition(l.typeName)],color:"#2EB43B"},{tag:l.keyword,color:"#D8B229"},{tag:l.operator,color:"#4EA44E",fontWeight:"bold"},{tag:[l.definitionKeyword,l.modifier],color:"#925A47"},{tag:l.string,color:"#704D3D"},{tag:l.typeName,color:"#2F8996"},{tag:[l.variableName,l.propertyName],color:"#77ACB0"},{tag:l.self,color:"#77ACB0",fontWeight:"bold"},{tag:l.regexp,color:"#E3965E"},{tag:[l.tagName,l.angleBracket],color:"#BAA827"},{tag:l.attributeName,color:"#B06520"},{tag:l.derefOperator,color:"#000"}]}),ae({variant:"light",settings:{background:"#fef7e5",foreground:"#586E75",caret:"#000000",selection:"#073642",gutterBackground:"#fef7e5",gutterForeground:"#586E7580",lineHighlight:"#EEE8D5"},styles:[{tag:l.comment,color:"#93A1A1"},{tag:l.string,color:"#2AA198"},{tag:l.regexp,color:"#D30102"},{tag:l.number,color:"#D33682"},{tag:l.variableName,color:"#268BD2"},{tag:[l.keyword,l.operator,l.punctuation],color:"#859900"},{tag:[l.definitionKeyword,l.modifier],color:"#073642",fontWeight:"bold"},{tag:[l.className,l.self,l.definition(l.propertyName)],color:"#268BD2"},{tag:l.function(l.variableName),color:"#268BD2"},{tag:[l.bool,l.null],color:"#B58900"},{tag:l.tagName,color:"#268BD2",fontWeight:"bold"},{tag:l.angleBracket,color:"#93A1A1"},{tag:l.attributeName,color:"#93A1A1"},{tag:l.typeName,color:"#859900"}]}),ae({variant:"light",settings:{background:"#FFFFFF",foreground:"#4D4D4C",caret:"#AEAFAD",selection:"#D6D6D6",gutterBackground:"#FFFFFF",gutterForeground:"#4D4D4C80",lineHighlight:"#EFEFEF"},styles:[{tag:l.comment,color:"#8E908C"},{tag:[l.variableName,l.self,l.propertyName,l.attributeName,l.regexp],color:"#C82829"},{tag:[l.number,l.bool,l.null],color:"#F5871F"},{tag:[l.className,l.typeName,l.definition(l.typeName)],color:"#C99E00"},{tag:[l.string,l.special(l.brace)],color:"#718C00"},{tag:l.operator,color:"#3E999F"},{tag:[l.definition(l.propertyName),l.function(l.variableName)],color:"#4271AE"},{tag:l.keyword,color:"#8959A8"},{tag:l.derefOperator,color:"#4D4D4C"}]});const Pc=[ae({variant:"dark",settings:{background:"var(--cm-background)",foreground:"#abb2bf",caret:"#528bff",selection:"#3E4451",lineHighlight:"#2c313c",gutterBackground:"var(--color-background)",gutterForeground:"var(--gray-10)"},styles:[{tag:l.comment,color:"var(--cm-comment)"},{tag:l.variableName,color:"#abb2bf"},{tag:[l.string,l.special(l.brace)],color:"#98c379"},{tag:l.number,color:"#d19a66"},{tag:l.bool,color:"#d19a66"},{tag:l.null,color:"#d19a66"},{tag:l.keyword,color:"#c678dd",fontWeight:500},{tag:l.className,color:"#61afef"},{tag:l.definition(l.typeName),color:"#61afef"},{tag:l.typeName,color:"#56b6c2"},{tag:l.angleBracket,color:"#abb2bf"},{tag:l.tagName,color:"#e06c75"},{tag:l.attributeName,color:"#d19a66"},{tag:l.operator,color:"#56b6c2",fontWeight:500},{tag:[l.function(l.variableName)],color:"#61afef"},{tag:[l.propertyName],color:"#e5c07b"}]}),B.theme({".mo-cm-reactive-reference":{fontWeight:"400",color:"#2a7aa5",borderBottom:"2px solid #bad3de"},".mo-cm-reactive-reference-hover":{cursor:"pointer",borderBottomWidth:"3px",borderBottomColor:"#4a90a5"}})],Mc=[ae({variant:"light",settings:{background:"#ffffff",foreground:"#000000",caret:"#000000",selection:"#d7d4f0",lineHighlight:"#cceeff44",gutterBackground:"var(--color-background)",gutterForeground:"var(--gray-10)"},styles:[{tag:l.comment,color:"var(--cm-comment)"},{tag:l.variableName,color:"#000000"},{tag:[l.string,l.special(l.brace)],color:"#a11"},{tag:l.number,color:"#164"},{tag:l.bool,color:"#219"},{tag:l.null,color:"#219"},{tag:l.keyword,color:"#708",fontWeight:500},{tag:l.className,color:"#00f"},{tag:l.definition(l.typeName),color:"#00f"},{tag:l.typeName,color:"#085"},{tag:l.angleBracket,color:"#000000"},{tag:l.tagName,color:"#170"},{tag:l.attributeName,color:"#00c"},{tag:l.operator,color:"#a2f",fontWeight:500},{tag:[l.function(l.variableName)],color:"#00c"},{tag:[l.propertyName],color:"#05a"}]}),B.theme({".mo-cm-reactive-reference":{fontWeight:"400",color:"#005f87",borderBottom:"2px solid #bad3de"},".mo-cm-reactive-reference-hover":{cursor:"pointer",borderBottomWidth:"3px"}})];function aa(e){let{showPlaceholder:t,enableAI:n}=e;return t?"marimo-import":n?"ai":"none"}const Rc=e=>{let{cellId:t,keymapConfig:n,hotkeys:r,enableAI:o,cellActions:a,completionConfig:i,lspConfig:s,diagnosticsConfig:c,displayConfig:u,inlineAiTooltip:d}=e,f=aa(e);return[zd(n,r),_c(),Uc(),ms(),Md({completionConfig:i,hotkeys:r,placeholderType:f,lspConfig:s,diagnosticsConfig:c}),md({cellId:t,hotkeys:r,cellActions:a,keymapConfig:n}),Jc(e),Dc(),c!=null&&c.enabled?_f():[],o&&d?[os({prompt:h=>ds({prompt:h.prompt,selection:h.selection,codeBefore:h.codeBefore,codeAfter:h.codeAfter,language:xd(h.editorView)})}),Mn.of({hideOnBlur:!0})]:[],vd(t,u.reference_highlighting??!0)]};var Gc=e=>{let{from:t,to:n}=e.state.selection.main;if(t!==n)return!1;let r=e.state.doc.lineAt(n);return r.text.slice(0,n-r.from).trim()===""?!1:Vf(e)};const Jc=e=>{let{theme:t,hotkeys:n,completionConfig:r,cellId:o,lspConfig:a,diagnosticsConfig:i}=e,s=aa(e);return[B.lineWrapping,vf(),Cf(),xf(),If(),wf(),Tf(),uf(),Nf({position:"fixed",parent:document.querySelector("#App")??void 0}),Dd(),t==="dark"?Pc:Mc,Cd(a),yc(r),Af(),$f(),hs(),ut.high(Je.of(Jf)),kf(),hf(),pf.of(" "),oi(bf,{fallback:!0}),Je.of(df),Td({placeholderType:s,completionConfig:r,hotkeys:n,cellId:o,lspConfig:{...a,diagnostics:i}}),Fd.of(Of()),Fr.allowMultipleSelections.of(!0),Tc(n),Je.of([{key:"Tab",run:c=>ii(c)||Gc(c)||jf(c),preventDefault:!0},{key:n.getHotkey("completion.moveDown").key,run:c=>Gt(c.state)===null?!1:(Ln(!0)(c),!0),preventDefault:!0},{key:n.getHotkey("completion.moveUp").key,run:c=>Gt(c.state)===null?!1:(Ln(!1)(c),!0),preventDefault:!0}]),Je.of([...Pf,Ff])]};var et=(e=>!e||e instanceof WebAssembly.Module?e:typeof e=="object"&&"default"in e?e.default??e:e)(Jm),nr=e=>{Wm(e),typeof xi=="function"&&xi(),Wc(Ct)};function Wc(e){typeof e.__wbindgen_start=="function"&&e.__wbindgen_start()}if(et&&et.__wbindgen_start)nr(et);else if("Bun"in globalThis){let e;if(et instanceof WebAssembly.Module)({instance:e}=await WebAssembly.instantiate(et,{"./loro_wasm_bg.js":Ct}));else{let t=Bun.pathToFileURL(et);({instance:e}=await WebAssembly.instantiateStreaming(fetch(t),{"./loro_wasm_bg.js":Ct}))}nr(e.exports)}else{let e=et instanceof WebAssembly.Module?et:await gm(()=>import("./loro_wasm_bg-BTbzDT9t.js").then(async r=>(await r.__tla,r)),__vite__mapDeps([0,1,2]),import.meta.url),t=e instanceof WebAssembly.Module?e:e&&e.default||e,n;if(t instanceof WebAssembly.Instance)n=t;else if(t instanceof WebAssembly.Module)n=await WebAssembly.instantiate(t,{"./loro_wasm_bg.js":Ct});else if(t instanceof ArrayBuffer||ArrayBuffer.isView(t)){let{instance:r}=await WebAssembly.instantiate(t,{"./loro_wasm_bg.js":Ct});n=r}else if(typeof t=="string"||t instanceof URL){let r=await fetch(t),{instance:o}=await WebAssembly.instantiateStreaming(r,{"./loro_wasm_bg.js":Ct});n=o}else throw console.error("Unsupported wasm import type:",t),Error("Unsupported wasm import type: "+typeof t);nr(n.exports??n)}var Vc=["Map","Text","List","Tree","MovableList","Counter"];function $c(e){return e.startsWith("cid:")}function ia(e){if(typeof e!="object"||!e)return!1;let t=Object.getPrototypeOf(e);return typeof t!="object"||!t||typeof t.kind!="function"?!1:Vc.includes(e.kind())}var Hc=class{constructor(e,t=3e4){this.listeners=new Set,this.inner=new Ai(e,t),this.peer=e,this.timeout=t}apply(e,t="remote"){let{updated:n,added:r}=this.inner.apply(e);this.listeners.forEach(o=>{o({updated:n,added:r,removed:[]},t)}),this.startTimerIfNotEmpty()}setLocalState(e){let t=this.inner.getState(this.peer)==null;this.inner.setLocalState(e),t?this.listeners.forEach(n=>{n({updated:[],added:[this.inner.peer()],removed:[]},"local")}):this.listeners.forEach(n=>{n({updated:[this.inner.peer()],added:[],removed:[]},"local")}),this.startTimerIfNotEmpty()}getLocalState(){return this.inner.getState(this.peer)}getAllStates(){return this.inner.getAllStates()}encode(e){return this.inner.encode(e)}encodeAll(){return this.inner.encodeAll()}addListener(e){this.listeners.add(e)}removeListener(e){this.listeners.delete(e)}peers(){return this.inner.peers()}destroy(){clearInterval(this.timer),this.listeners.clear()}startTimerIfNotEmpty(){this.inner.isEmpty()||this.timer!=null||(this.timer=setInterval(()=>{let e=this.inner.removeOutdated();e.length>0&&this.listeners.forEach(t=>{t({updated:[],added:[],removed:e},"timeout")}),this.inner.isEmpty()&&(clearInterval(this.timer),this.timer=void 0)},this.timeout/2))}};jr.prototype.toJsonWithReplacer=function(e){let t=new Set,n=this,r=(a,i)=>{if(typeof i=="string"&&$c(i)&&!t.has(i)){t.add(i);let c=n.getContainerById(i);if(c==null)throw Error(`ContainerID not found: ${i}`);let u=e(a,c);if(u===c){let d=c.getShallowValue();return typeof d=="object"?o(d):d}if(ia(u))throw Error("Using new container is not allowed in toJsonWithReplacer");return typeof u=="object"&&u?o(u):u}if(typeof i=="object"&&i)return o(i);let s=e(a,i);if(ia(s))throw Error("Using new container is not allowed in toJsonWithReplacer");return s},o=a=>{if(Array.isArray(a))return a.map((s,c)=>r(c,s)).filter(s=>s!==void 0);let i={};for(let[s,c]of Object.entries(a)){let u=r(s,c);u!==void 0&&(i[s]=u)}return i};return o(n.getShallowValue())};var sa=Symbol("loro.callPendingEventsWrapped");function rr(e,t){let n=Object.getOwnPropertyDescriptor(e,t);if(!n||typeof n.value!="function")return;let r=n.value;if(r[sa])return;let o=function(...a){let i;try{return i=r.apply(this,a),i}finally{i&&typeof i.then=="function"?i.finally(()=>{Si()}):Si()}};o[sa]=!0,Object.defineProperty(e,t,{...n,value:o})}function qc(e,t){for(let n of t)rr(e,n)}function or(e){let t=new Set,n=e;for(;n&&n!==Object.prototype&&n!==Function.prototype;){for(let r of Object.getOwnPropertyNames(n))r==="constructor"||t.has(r)||(t.add(r),rr(n,r));for(let r of Object.getOwnPropertySymbols(n))t.has(r)||(t.add(r),rr(n,r));n=Object.getPrototypeOf(n)}}or(jr.prototype),or(Rm.prototype),or(Ai.prototype),qc(Gm.prototype,["undo","redo"]);const zc=B.baseTheme({".loro-cursor":{position:"absolute",width:"2px",display:"inline-block",height:"1.2em"},".loro-cursor::before":{position:"absolute",top:"1.3em",left:"0",content:"var(--rtc-name)",padding:"2px 6px",fontSize:"12px",borderRadius:"3px",whiteSpace:"nowrap",userSelect:"none",backgroundColor:"inherit",opacity:"0.7"},".loro-selection":{opacity:"0.5"}});In.define();const Ut=pe.define(),ar=qe.define({create(){return{remoteCursors:new Map,isCheckout:!1}},update(e,t){for(let n of t.effects)if(n.is(Ut))switch(n.value.type){case"update":{let{peer:r,user:o,cursor:a}=n.value;e.remoteCursors.set(r,{uid:r,cursor:a,user:o});break}case"delete":e.remoteCursors.delete(n.value.peer);break;case"checkout":e.isCheckout=n.value.checkout}return e}});var la=e=>{let t=e.transactions.flatMap(n=>n.effects).filter(n=>n.is(Ut));return e.docChanged||e.viewportChanged||t.length>0};const Kc=()=>ri({above:!0,class:"loro-cursor-layer",update:la,markers:e=>{let{remoteCursors:t,isCheckout:n}=e.state.field(ar);return n?[]:[...t.values()].flatMap(r=>{var a,i;let o=vt.cursor(r.cursor.anchor);return Xc.createCursor(e,o,((a=r.user)==null?void 0:a.name)||"unknown",((i=r.user)==null?void 0:i.colorClassName)||"")})}}),Yc=()=>ri({above:!1,class:"loro-selection-layer",update:la,markers:e=>{let{remoteCursors:t,isCheckout:n}=e.state.field(ar);return n?[]:[...t.entries()].filter(([,r])=>r.cursor.head!==void 0&&r.cursor.anchor!==r.cursor.head).flatMap(([,r])=>{var a;let o=vt.range(r.cursor.anchor,r.cursor.head);return Sf.forRange(e,`loro-selection ${((a=r.user)==null?void 0:a.colorClassName)||""}`,o)})}});var Xc=class Wr{constructor(t,n,r,o,a){this.left=t,this.top=n,this.height=r,this.name=o,this.colorClassName=a}draw(){let t=document.createElement("div");return this.adjust(t),t}update(t){return this.adjust(t),!0}adjust(t){t.style.left=`${this.left}px`,t.style.top=`${this.top}px`,t.style.height=`${this.height}px`,t.className=`loro-cursor ${this.colorClassName}`,t.style.setProperty("--rtc-name",`"${this.name}"`)}eq(t){return this.left===t.left&&this.top===t.top&&this.height===t.height&&this.name===t.name}static createCursor(t,n,r,o){let a=Wr.calculateAbsoluteCursorPosition(n,t);if(!a)return[];let i=t.scrollDOM.getBoundingClientRect(),s=(t.textDirection===Ef.LTR?i.left:i.right-t.scrollDOM.clientWidth)-t.scrollDOM.scrollLeft,c=i.top-t.scrollDOM.scrollTop;return[new Wr(a.left-s,a.top-c,a.bottom-a.top,r,o)]}static calculateAbsoluteCursorPosition(t,n){let r=Math.max(0,Math.min(n.state.doc.length,t.anchor));return n.coordsAtPos(r,t.assoc||1)}},Qc=(e,t,n,r)=>{let o=[],{updated:a,added:i}=n;for(let s of[...a,...i]){let c=ca(e,t,s,r);c&&o.push(c)}return o},ca=(e,t,n,r)=>{var c,u;let o=t.getAllStates()[n];if(!o||n===e.peerIdStr||o.scopeId!==r)return;if(o.type==="delete")return Ut.of({type:"delete",peer:o.uid,scopeId:o.scopeId});let a=Ti.decode(o.cursor.anchor),i=((c=e.getCursorPos(a))==null?void 0:c.offset)??0,s=i;if(o.cursor.head){let d=Ti.decode(o.cursor.head);s=((u=e.getCursorPos(d))==null?void 0:u.offset)??0}return Ut.of({type:"update",peer:o.uid,scopeId:o.scopeId,cursor:{anchor:i,head:s},user:o.user})},Zc=class{constructor(e,t,n,r,o,a,i){this.view=e,this.doc=t,this.user=n,this.awareness=r,this.getTextFromDoc=o,this.scopeId=a,this.getUserId=i,this.sub=this.doc.subscribe(s=>{if(s.by==="local"){let c=[];for(let u of this.awareness.peers()){let d=ca(this.doc,this.awareness,u,this.scopeId);d&&c.push(d)}this.view.dispatch({effects:c})}else s.by==="checkout"&&this.view.dispatch({effects:[Ut.of({type:"checkout",checkout:this.doc.isDetached()})]})})}update(e){if(!e.selectionSet&&!e.focusChanged&&!e.docChanged)return;let t=e.state.selection.main;if(this.view.hasFocus&&!this.doc.isDetached()){let n=tu({doc:this.doc,getTextFromDoc:this.getTextFromDoc,anchor:t.anchor,head:t.head});this.awareness.setLocalState({type:"update",uid:this.getUserId?this.getUserId():this.doc.peerIdStr,scopeId:this.scopeId,cursor:n,user:this.user})}else this.awareness.setLocalState({type:"delete",uid:this.getUserId?this.getUserId():this.doc.peerIdStr,scopeId:this.scopeId})}destroy(){var e;(e=this.sub)==null||e.call(this),this.awareness.setLocalState({type:"delete",uid:this.getUserId?this.getUserId():this.doc.peerIdStr,scopeId:this.scopeId})}},eu=class{constructor(e,t,n,r){this.view=e,this.doc=t,this.awareness=n,this.scopeId=r;let o=async(a,i)=>{i!=="local"&&this.view.dispatch({effects:Qc(this.doc,this.awareness,a,this.scopeId)})};this._awarenessListener=o,this.awareness.addListener(o)}destroy(){this._awarenessListener&&this.awareness.removeListener(this._awarenessListener)}},tu=({doc:e,getTextFromDoc:t,anchor:n,head:r})=>{var i,s;n===r&&(r=void 0);let o=(i=t(e).getCursor(n))==null?void 0:i.encode();if(!o)throw Error("cursor head not found");let a;return r!==void 0&&(a=(s=t(e).getCursor(r))==null?void 0:s.encode()),{anchor:o,head:a}};const gn=["bg-(--amber-6)","bg-(--blue-6)","bg-(--crimson-6)","bg-(--cyan-6)","bg-(--grass-6)","bg-(--gray-6)","bg-(--green-6)","bg-(--lime-6)","bg-(--orange-6)","bg-(--purple-6)","bg-(--red-6)","bg-(--sage-6)","bg-(--sky-6)","bg-(--slate-6)"],nu=e=>{if(typeof e=="string"){let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n),t=Math.trunc(t);return gn[Math.abs(t)%gn.length]}return gn[e%gn.length]},ru=(e,t,n)=>ze.define(r=>new ou(r,e,t,n)),bt=In.define();var ou=class{constructor(e,t,n,r){p(this,"isInitDispatch",!1);p(this,"onRemoteUpdate",e=>{if(e.by!=="local"){if(e.by==="checkout"){this.view.dispatch({changes:[{from:0,to:this.view.state.doc.length,insert:this.getTextFromDoc(this.doc).toString()}],annotations:[bt.of(this)]});return}if(e.by==="import"){let t=[],n=0;for(let{diff:r,path:o}of e.events){if(o.join("/")!==this.docPath.join("/")||r.type!=="text")continue;let a=r.diff;for(let i of a)i.insert?t.push({from:n,to:n,insert:i.insert}):i.delete?(t.push({from:n,to:n+i.delete}),n+=i.delete):i.retain!=null&&(n+=i.retain);t.length>0&&this.view.dispatch({changes:t,annotations:[bt.of(this)]})}}}});this.view=e,this.doc=t,this.docPath=n,this.getTextFromDoc=r,this.sub=t.subscribe(this.onRemoteUpdate),Promise.resolve().then(()=>{this.isInitDispatch=!0;let o=this.view.state.doc.toString(),a=this.getTextFromDoc(this.doc);o!==a.toString()&&e.dispatch({changes:[{from:0,to:this.view.state.doc.length,insert:a.toString()}]})})}update(e){if(this.isInitDispatch){this.isInitDispatch=!1;return}if(!e.docChanged||e.transactions.length>0&&(e.transactions[0].annotation(bt)===this||e.transactions[0].annotation(bt)==="undo"))return;let t=0;e.changes.iterChanges((n,r,o,a,i)=>{let s=i.sliceString(0,i.length,`
19
- `);n!==r&&this.getTextFromDoc(this.doc).delete(n+t,r-n),s.length>0&&this.getTextFromDoc(this.doc).insert(n+t,s),t+=s.length-(r-n)}),this.doc.commit()}destroy(){var e;(e=this.sub)==null||e.call(this),this.sub=void 0}},fe=$e.get("rtc"),ua=fe.get("awareness").disabled(),ir="awareness:";function au(e,t){let n=new TextEncoder().encode(e);return new Uint8Array([...n,...t])}function iu(e,t){return new TextDecoder().decode(e.slice(0,t.length))===t}function su(e,t){return e.slice(t.length)}dt=jt(void 0);var ie=new jr,bn=new Hc(ie.peerIdStr),sr=Gf(()=>{fe.debug("creating websocket");let e=new $m(ti().getWsSyncURL(nf()).toString(),void 0,{maxRetries:10,debug:!1,startClosed:!0,connectionTimeout:1e4});return Promise.resolve().then(async()=>{await ei(),wm()==="edit"&&e.reconnect()}),e.addEventListener("message",async t=>{let n=await t.data.arrayBuffer(),r=new Uint8Array(n);if(iu(r,ir)){let o=su(r,ir);bn.apply(o),ua.debug("applied awareness update");return}ie.import(r),fe.debug("imported doc change. new doc:",ie.toJSON()),Q.get(dt)!==ie&&Q.set(dt,ie)}),e.addEventListener("open",()=>{fe.debug("websocket open")}),e.addEventListener("close",t=>{fe.warn("websocket close",t),Q.get(dt)===ie&&Q.set(dt,void 0)}),e});Nr()&&sr(),ie.subscribeLocalUpdates(e=>{fe.debug("local update, sending to server"),sr().send(e)}),bn.addListener((e,t)=>{let n=[...e.added,...e.removed,...e.updated];t==="local"&&(ua.debug("awareness changes",n),sr().send(au(ir,bn.encode(n))))});function lr(e,t,n=""){if(Zd())return{extension:[],code:n};let r=ie.getByPath(`codes/${e}`)!==void 0,o=ie.getMap("codes").getOrCreateContainer(e,new Br);return r||(fe.log("initializing code for new cell",n),o.insert(0,n)),{code:n.toString(),extension:[lu(e),cu(e),uu(ie,bn,{get name(){return Q.get(wd)||"Anonymous"},get colorClassName(){return nu(this.name)}},()=>o,e),ru(ie,["codes",e],()=>o)]}}function lu(e){let t=(r,o)=>{let a=r.state.field(xn).type,i=o.toString();i&&i!==a&&(fe.debug(`[incoming] setting language type: ${a} -> ${i}`),Pt(r,{language:i,keepCodeAsIs:!0}))},n=(r,o)=>{let a=r.state.field(vr),i=o.toJSON();Nn(a,i)||r.dispatch({effects:[Va.of(i)],annotations:[bt.of(!0)]})};return ze.define(r=>{let o;return Promise.resolve().then(()=>{let a=ie.getByPath(`languages/${e}`);if(!a){fe.error("no language container found for cell",e);return}yt(a instanceof Br,"language type is not a LoroText");let i=ie.getByPath(`language_metadata/${e}`);if(!i){fe.error("no language metadata container found for cell",e);return}yt(i instanceof Ii,"language metadata is not a LoroMap"),t(r,a),n(r,i),o=ie.subscribe(s=>{if(s.origin==="local")return;let c=s.events.some(d=>d.target===a.id),u=s.events.some(d=>d.target===i.id);c&&t(r,a),u&&n(r,i)})}),{destroy(){o()}}})}function cu(e){let t=ie.getMap("languages").getOrCreateContainer(e,new Br),n=ie.getMap("language_metadata").getOrCreateContainer(e,new Ii);return B.updateListener.of(r=>{let o=t.toString()!=="";if(!r.docChanged&&o)return;if(!o){let i=kr(r.state).type;Pt(r.view,{language:i}),fe.debug("no initial language, setting default to",i),t.delete(0,t.length),t.insert(0,i),fe.debug("no initial language metadata, setting default to",r.state.field(vr));let s=r.state.field(vr);for(let c of Object.keys(s))n.set(c,s[c]);ie.commit();return}let a=!1;for(let i of r.transactions)if(!i.annotation(bt)){for(let s of i.effects)if(s.is(jd)&&t.toString()!==s.value.type&&(fe.debug(`[outgoing] language change: ${t} -> ${s.value.type}`),t.delete(0,t.length),t.insert(0,s.value.type),a=!0),s.is(Va)||s.is(Ga)){let c=s.value;s.is(Ga)?(fe.debug("[outgoing] setting language metadata: ",c),n.clear()):fe.debug("[outgoing] updating language metadata: ",c);for(let u of Object.keys(c))n.set(u,c[u]);a=!0}}a&&ie.commit()})}function uu(e,t,n,r,o,a){let i=`loro:cell:${o}`;return[ar,Kc(),Yc(),ze.define(s=>new Zc(s,e,n,t,r,i,a)),ze.define(s=>new eu(s,e,t,i)),zc]}var du=Re();Rr=e=>{let t=(0,du.c)(41),{resetOnBlur:n,placeholderText:r,initialValue:o,flexibleWidth:a,onNameChange:i,className:s}=e,c=n===void 0?!1:n,u=o===void 0?null:o,d=a===void 0?!1:a,{sendListFiles:f}=Jt(),[h,m]=(0,I.useState)(u),g;t[0]===Symbol.for("react.memo_cache_sentinel")?(g=[],t[0]=g):g=t[0];let[y,w]=(0,I.useState)(g),[k,C]=(0,I.useState)(!1),T=(0,I.useRef)(null),L=(0,I.useRef)(!1),U,A;t[1]===u?(U=t[2],A=t[3]):(U=()=>{m(u)},A=[u],t[1]=u,t[2]=U,t[3]=A),(0,I.useEffect)(U,A);let x;t[4]===Symbol.for("react.memo_cache_sentinel")?(x=()=>{C(!0)},t[4]=x):x=t[4];let G=x,ee;t[5]!==u||t[6]!==c?(ee=ce=>{var ne;(ne=ce.relatedTarget)!=null&&ne.closest(".filename-input")||(C(!1),c&&m(u))},t[5]=u,t[6]=c,t[7]=ee):ee=t[7];let $=ee,F;t[8]===h?F=t[9]:(F=Qe.dirname(h||""),t[8]=h,t[9]=F);let j=F,se=Qe.basename(h||""),_=y.filter(ce=>Qe.basename(ce.path).startsWith(se)),P;t[10]!==j||t[11]!==k||t[12]!==f?(P=async()=>{if(!k){w([]);return}w((await f({path:j})).files)},t[10]=j,t[11]=k,t[12]=f,t[13]=P):P=t[13];let me;t[14]!==j||t[15]!==k?(me=[j,k],t[14]=j,t[15]=k,t[16]=me):me=t[16];let{isPending:K}=Lm(P,me),E=fu(h,y,u),S=(E||_.length>0)&&(0,b.jsxs)(vi,{className:"font-mono",children:[!K&&(0,b.jsx)(Dm,{children:"No files"}),E&&(0,b.jsxs)(wi,{variant:"success",className:"py-2 px-3",onSelect:()=>{var ce;E&&(L.current=!0,i(E),(ce=T.current)==null||ce.blur())},children:[(0,b.jsx)(re,{className:"w-4 h-4 mr-2"})," ",(0,b.jsxs)("span",{className:"text-sm",children:[u?"Rename to: ":"Save as: ",(0,b.jsx)("span",{className:"font-medium text-sm",children:Qe.basename(E)})]})]},"_rename_"),_.map(ce=>{let ne=fm[ce.isDirectory?"directory":dm(ce.path)];return(0,b.jsxs)(wi,{variant:ce.isDirectory?"default":"muted",className:"py-2 px-3",onSelect:()=>{ce.isDirectory?m(`${ce.path}/`):m(ce.path)},children:[(0,b.jsx)(ne,{className:"w-4 h-4 mr-2"})," ",Qe.basename(ce.path)]},ce.path)})]}),R=Math.max(20,(h==null?void 0:h.length)||(r==null?void 0:r.length)||0)*10,D=k?h||"":u||"",te;t[17]!==d||t[18]!==R?(te=d?{maxWidth:R}:void 0,t[17]=d,t[18]=R,t[19]=te):te=t[19];let Ge;t[20]===s?Ge=t[21]:(Ge=ct(s,"w-full px-4 py-1 my-1 h-9 font-mono text-foreground/60"),t[20]=s,t[21]=Ge);let Pe;t[22]!==r||t[23]!==D||t[24]!==te||t[25]!==Ge?(Pe=(0,b.jsx)(Nm,{children:(0,b.jsx)(Om,{"data-testid":"dir-completion-input",tabIndex:-1,rootClassName:"border-none justify-center px-1",spellCheck:"false",value:D,onKeyDown:mu,icon:null,ref:T,onValueChange:m,placeholder:r,autoComplete:"off",style:te,className:Ge})}),t[22]=r,t[23]=D,t[24]=te,t[25]=Ge,t[26]=Pe):Pe=t[26];let Ve=S&&"group-focus-within:block",Me;t[27]===Ve?Me=t[28]:(Me=ct("p-0 w-full min-w-80 max-w-80vw hidden",Ve),t[27]=Ve,t[28]=Me);let O;t[29]!==S||t[30]!==Me?(O=(0,b.jsx)(km,{side:"bottom",className:Me,portal:!1,children:S}),t[29]=S,t[30]=Me,t[31]=O):O=t[31];let W;t[32]!==Pe||t[33]!==O?(W=(0,b.jsxs)(vi,{children:[Pe,O]}),t[32]=Pe,t[33]=O,t[34]=W):W=t[34];let V;t[35]!==$||t[36]!==W?(V=(0,b.jsx)(_m,{onFocus:G,onBlur:$,shouldFilter:!1,id:"filename-input",className:"bg-transparent group filename-input",children:W}),t[35]=$,t[36]=W,t[37]=V):V=t[37];let le;return t[38]!==k||t[39]!==V?(le=(0,b.jsx)(sf,{children:(0,b.jsx)(Cm,{open:k,modal:!1,children:V})}),t[38]=k,t[39]=V,t[40]=le):le=t[40],le};function fu(e,t,n){if(e&&!e.endsWith("/")&&((Bd("markdown")?new Set(["py","md","markdown","qmd"]):new Set(["py"])).has(Qe.extension(e))||(e=e.endsWith(".")?`${e}py`:e.endsWith(".p")?`${e}y`:`${e}.py`),!t.some(r=>r.path===e||Qe.basename(r.path)===e)&&!(n&&(n===e||Qe.basename(n)===e))))return e}function mu(e){e.key==="Escape"&&e.currentTarget.blur()}var da=Re(),pu=e=>{let t=(0,da.c)(33),n=()=>{cm(new Blob([r()],{type:"text/plain"}),`${e.proposedName}.json`)},r=ue(bu),o;t[0]!==n||t[1]!==e?(o=U=>{U.preventDefault(),n(),e.closeModal()},t[0]=n,t[1]=e,t[2]=o):o=t[2];let a;t[3]===e?a=t[4]:(a=U=>{U.key==="Escape"&&e.closeModal()},t[3]=e,t[4]=a);let i;t[5]===Symbol.for("react.memo_cache_sentinel")?(i=(0,b.jsx)(hi,{className:"text-accent-foreground mb-6",children:"Download unsaved changes?"}),t[5]=i):i=t[5];let s;t[6]===Symbol.for("react.memo_cache_sentinel")?(s={wordBreak:"break-word"},t[6]=s):s=t[6];let c,u;t[7]===Symbol.for("react.memo_cache_sentinel")?(c=(0,b.jsx)("p",{children:"This app has unsaved changes. To recover:"}),u={paddingBottom:"10px"},t[7]=c,t[8]=u):(c=t[7],u=t[8]);let d;t[9]===e.proposedName?d=t[10]:(d=(0,b.jsxs)("li",{style:u,children:['Click the "Download" button. This will download a file called\xA0',(0,b.jsxs)("code",{children:[e.proposedName,".json"]}),". This file contains your code."]}),t[9]=e.proposedName,t[10]=d);let f;t[11]===Symbol.for("react.memo_cache_sentinel")?(f={paddingBottom:"10px"},t[11]=f):f=t[11];let h;t[12]===Symbol.for("react.memo_cache_sentinel")?(h={display:"block",padding:"10px"},t[12]=h):h=t[12];let m;t[13]===e.proposedName?m=t[14]:(m=(0,b.jsxs)("code",{style:h,children:["marimo recover ",e.proposedName,".json ",">"," ",e.proposedName,".py"]}),t[13]=e.proposedName,t[14]=m);let g;t[15]===e.proposedName?g=t[16]:(g=(0,b.jsxs)("code",{children:[e.proposedName,".py"]}),t[15]=e.proposedName,t[16]=g);let y;t[17]!==g||t[18]!==m?(y=(0,b.jsxs)("li",{style:f,children:["In your terminal, type",m,"to overwrite ",g," with the recovered changes."]}),t[17]=g,t[18]=m,t[19]=y):y=t[19];let w;t[20]!==y||t[21]!==d?(w=(0,b.jsx)(vm,{className:"markdown break-words",style:s,children:(0,b.jsxs)("div",{className:"prose dark:prose-invert",children:[c,(0,b.jsxs)("ol",{children:[d,y]})]})}),t[20]=y,t[21]=d,t[22]=w):w=t[22];let k;t[23]===e.closeModal?k=t[24]:(k=(0,b.jsx)(He,{"aria-label":"Cancel",variant:"secondary","data-testid":"cancel-recovery-button",onClick:e.closeModal,children:"Cancel"}),t[23]=e.closeModal,t[24]=k);let C;t[25]===Symbol.for("react.memo_cache_sentinel")?(C=(0,b.jsx)(He,{"data-testid":"download-recovery-button","aria-label":"Download",variant:"default",type:"submit",children:"Download"}),t[25]=C):C=t[25];let T;t[26]===k?T=t[27]:(T=(0,b.jsxs)(gi,{children:[k,C]}),t[26]=k,t[27]=T);let L;return t[28]!==o||t[29]!==a||t[30]!==w||t[31]!==T?(L=(0,b.jsx)(bi,{className:"w-fit",children:(0,b.jsxs)("form",{onSubmit:o,onKeyDown:a,children:[i,w,T]})}),t[28]=o,t[29]=a,t[30]=w,t[31]=T,t[32]=L):L=t[32],L};const hu=e=>{let t=(0,da.c)(12),{filename:n,needsSave:r}=e,{openModal:o,closeModal:a}=yi(),i;t[0]===n?i=t[1]:(i=n===null?"app":Qe.basename(n).split(".")[0],t[0]=n,t[1]=i);let s=i,c;t[2]!==a||t[3]!==r||t[4]!==o||t[5]!==s?(c=()=>{r&&o((0,b.jsx)(pu,{proposedName:s,closeModal:a}))},t[2]=a,t[3]=r,t[4]=o,t[5]=s,t[6]=c):c=t[6];let u=c;ni("global.save",u);let d;t[7]===Symbol.for("react.memo_cache_sentinel")?(d=Ei("global.save"),t[7]=d):d=t[7];let f=r?"yellow":"gray",h;t[8]===Symbol.for("react.memo_cache_sentinel")?(h=(0,b.jsx)(fi,{strokeWidth:1.5,size:18}),t[8]=h):h=t[8];let m;return t[9]!==u||t[10]!==f?(m=(0,b.jsx)(Nt,{content:d,children:(0,b.jsx)(Ci,{onClick:u,id:"save-button","aria-label":"Save",className:"rectangle",color:f,children:h})}),t[9]=u,t[10]=f,t[11]=m):m=t[11],m};function gu(e){return{id:e.id,name:e.name,code:e.code,code_hash:null,config:{column:0,...e.config}}}function bu(){let e=xr(Cr()),t={version:"1",metadata:{marimo_version:af()},cells:e.map(gu)};return JSON.stringify(t,null,2)}var yu=Re(),cr=5e3;function wu(){let e=(0,yu.c)(12),t=oe(Yd),{state:n}=oe(lt),r=t.auto_download.includes("markdown"),o=t.auto_download.includes("html"),a=t.auto_download.includes("ipynb"),i=n===wt.OPEN,s=!r||!i,c=!o||!i,u=!a||!i,{autoExportAsHTML:d,autoExportAsIPYNB:f,autoExportAsMarkdown:h}=Jt(),m;e[0]===h?m=e[1]:(m=async()=>{await h({download:!1})},e[0]=h,e[1]=m);let g;e[2]===s?g=e[3]:(g={delayMs:cr,whenVisible:!0,disabled:s},e[2]=s,e[3]=g),Pr(m,g);let y;e[4]===d?y=e[5]:(y=async()=>{await d({download:!1,includeCode:!0,files:Yf.INSTANCE.filenames()})},e[4]=d,e[5]=y);let w;e[6]===c?w=e[7]:(w={delayMs:cr,whenVisible:!0,disabled:c},e[6]=c,e[7]=w),Pr(y,w);let k;e[8]===f?k=e[9]:(k=async()=>{await f({download:!1})},e[8]=f,e[9]=k);let C;e[10]===u?C=e[11]:(C={delayMs:cr,whenVisible:!0,disabled:u},e[10]=u,e[11]=C),Pr(k,C)}let ur;On=jt(void 0),ur=jt(e=>{let t=e(On);return vu({state:e(nt),layout:e(si),lastSavedNotebook:t})});function vu({state:e,layout:t,lastSavedNotebook:n}){if(!n)return!1;let{cellIds:r,cellData:o}=e,a=r.inOrderIds.map(u=>o[u]),i=a.map(u=>u.code),s=a.map(u=>u.config),c=a.map(u=>u.name);return!ai(i,n.codes)||!ai(c,n.names)||!Nn(s,n.configs)||!Nn(t.selectedLayout,n.layout.selectedLayout)||!Nn(t.layoutData,n.layout.layoutData)}var Eu=Re();function Nu(e){let t=(0,Eu.c)(21),{codes:n,cellConfigs:r,config:o,connStatus:a,cellNames:i,needsSave:s,kioskMode:c,onSave:u}=e,d=(0,I.useRef)(null),f;t[0]===n?f=t[1]:(f=n.join(":"),t[0]=n,t[1]=f);let h=f,m;t[2]===r?m=t[3]:(m=r.map(ku).join(":"),t[2]=r,t[3]=m);let g=m,y;t[4]===i?y=t[5]:(y=i.join(":"),t[4]=i,t[5]=y);let w=y,k;t[6]!==o||t[7]!==a.state||t[8]!==c||t[9]!==s||t[10]!==u?(k=()=>{if(!c)return o.autosave==="after_delay"&&(d.current!==null&&clearTimeout(d.current),s&&a.state===wt.OPEN&&(d.current=setTimeout(u,o.autosave_delay))),()=>{d.current!==null&&clearTimeout(d.current)}},t[6]=o,t[7]=a.state,t[8]=c,t[9]=s,t[10]=u,t[11]=k):k=t[11];let C;t[12]!==g||t[13]!==w||t[14]!==h||t[15]!==o||t[16]!==a.state||t[17]!==c||t[18]!==s||t[19]!==u?(C=[h,g,w,o,a.state,u,c,s],t[12]=g,t[13]=w,t[14]=h,t[15]=o,t[16]=a.state,t[17]=c,t[18]=s,t[19]=u,t[20]=C):C=t[20],(0,I.useEffect)(k,C)}function ku(e){return JSON.stringify(e)}var yn=Re();Oi=e=>{let t=(0,yn.c)(15),{kioskMode:n}=e,r=Im(),o=oe(ur),a=oe(lt).state===wt.CLOSED,{saveOrNameNotebook:i,saveIfNotebookIsPersistent:s}=dr(),c;t[0]!==n||t[1]!==s?(c={onSave:s,kioskMode:n},t[0]=n,t[1]=s,t[2]=c):c=t[2],Au(c),wu();let u;t[3]===o?u=t[4]:(u=w=>{if(o)return w.preventDefault(),w.returnValue="You have unsaved changes. Are you sure you want to leave?",w.returnValue},t[3]=o,t[4]=u),lf(window,"beforeunload",u);let d;t[5]===i?d=t[6]:(d=w=>{w.preventDefault(),w.stopPropagation(),i()},t[5]=i,t[6]=d);let f=d;if(ni("global.save",i),a){let w;return t[7]!==r||t[8]!==o?(w=(0,b.jsx)(hu,{filename:r,needsSave:o}),t[7]=r,t[8]=o,t[9]=w):w=t[9],w}let h;t[10]===Symbol.for("react.memo_cache_sentinel")?(h=Ei("global.save"),t[10]=h):h=t[10];let m=o?"yellow":"hint-green",g;t[11]===Symbol.for("react.memo_cache_sentinel")?(g=(0,b.jsx)(fi,{strokeWidth:1.5,size:18}),t[11]=g):g=t[11];let y;return t[12]!==f||t[13]!==m?(y=(0,b.jsx)(Nt,{content:h,children:(0,b.jsx)(Ci,{"data-testid":"save-button",id:"save-button",shape:"rectangle",color:m,onClick:f,children:g})}),t[12]=f,t[13]=m,t[14]=y):y=t[14],y};function dr(){let e=(0,yn.c)(20),{sendSave:t}=Jt(),{openModal:n,closeModal:r,openAlert:o}=yi(),a=Ba(On),i=Fm(),s=wr(),c;e[0]!==o||e[1]!==t||e[2]!==a||e[3]!==s?(c=async(k,C)=>{let T=s.get(lt),L=s.get(Za);if(s.get(ym))return;if(T.state!==wt.OPEN){o("Failed to save notebook: not connected to a kernel.");return}$e.log("saving to ",k),C&&L.format_on_save&&($e.log("formatting notebook (onSave)"),await Id());let U=Cr(),A=xr(U),x=A.map(xu),G=A.map(Su),ee=A.map(Cu),$=Ha(U),F=s.get(si);G.length!==0&&(await t({cellIds:x,codes:G,names:ee,filename:k,configs:$,layout:Xf(),persist:!0}),a({names:ee,codes:G,configs:$,layout:F}))},e[0]=o,e[1]=t,e[2]=a,e[3]=s,e[4]=c):c=e[4];let u=ue(c),d;e[5]!==u||e[6]!==s?(d=k=>{let C=k===void 0?!1:k,T=s.get(Ja),L=s.get(lt);fa(T)&&L.state===wt.OPEN&&u(T,C)},e[5]=u,e[6]=s,e[7]=d):d=e[7];let f=ue(d),h;e[8]!==u||e[9]!==i?(h=k=>{i(k).then(C=>{C!==null&&u(C,!0)})},e[8]=u,e[9]=i,e[10]=h):h=e[10];let m=h,g;e[11]!==r||e[12]!==m||e[13]!==n||e[14]!==f||e[15]!==s?(g=()=>{let k=s.get(Ja),C=s.get(lt);f(!0),!fa(k)&&C.state!==wt.CLOSED&&n((0,b.jsx)(Fu,{onClose:r,onSave:m}))},e[11]=r,e[12]=m,e[13]=n,e[14]=f,e[15]=s,e[16]=g):g=e[16];let y=ue(g),w;return e[17]!==f||e[18]!==y?(w={saveOrNameNotebook:y,saveIfNotebookIsPersistent:f},e[17]=f,e[18]=y,e[19]=w):w=e[19],w}function Cu(e){return e.name}function Su(e){return e.code}function xu(e){return e.id}function fa(e){return e!==null&&!e.startsWith("/tmp/")&&!e.startsWith("/var/folders")&&!e.includes("AppData\\Local\\Temp")}function Au(e){let t=(0,yn.c)(14),n=oe(Za),r=gd(),[o]=En(lt),a=oe(ur),i,s;if(t[0]!==r){let h=xr(r);i=h.map(Iu),s=h.map(Tu),t[0]=r,t[1]=i,t[2]=s}else i=t[1],s=t[2];let c=s,u;t[3]===r?u=t[4]:(u=Ha(r),t[3]=r,t[4]=u);let d=u,f;t[5]!==n||t[6]!==c||t[7]!==i||t[8]!==d||t[9]!==o||t[10]!==a||t[11]!==e.kioskMode||t[12]!==e.onSave?(f={onSave:e.onSave,needsSave:a,codes:i,cellConfigs:d,cellNames:c,connStatus:o,config:n,kioskMode:e.kioskMode},t[5]=n,t[6]=c,t[7]=i,t[8]=d,t[9]=o,t[10]=a,t[11]=e.kioskMode,t[12]=e.onSave,t[13]=f):f=t[13],Nu(f)}function Tu(e){return e.name}function Iu(e){return e.code}var Fu=e=>{let t=(0,yn.c)(17),{onClose:n,onSave:r}=e,[o,a]=(0,I.useState)(),i;t[0]!==n||t[1]!==r?(i=w=>{a(w),w.trim()&&(r(w),n())},t[0]=n,t[1]=r,t[2]=i):i=t[2];let s=i,c;t[3]===Symbol.for("react.memo_cache_sentinel")?(c=(0,b.jsx)(hi,{children:"Save notebook"}),t[3]=c):c=t[3];let u;t[4]===Symbol.for("react.memo_cache_sentinel")?(u=(0,b.jsx)(_r,{className:"text-md pt-6 px-1",children:"Save as"}),t[4]=u):u=t[4];let d;t[5]===s?d=t[6]:(d=(0,b.jsxs)("div",{className:"flex flex-col",children:[u,(0,b.jsx)(Rr,{onNameChange:s,placeholderText:"filename",className:"missing-filename"})]}),t[5]=s,t[6]=d);let f;t[7]===n?f=t[8]:(f=(0,b.jsx)(He,{"data-testid":"cancel-save-dialog-button","aria-label":"Cancel",variant:"secondary",onClick:n,children:"Cancel"}),t[7]=n,t[8]=f);let h=!o,m;t[9]===h?m=t[10]:(m=(0,b.jsx)(He,{"data-testid":"submit-save-dialog-button","aria-label":"Save",variant:"default",disabled:h,type:"submit",children:"Save"}),t[9]=h,t[10]=m);let g;t[11]!==f||t[12]!==m?(g=(0,b.jsxs)(gi,{children:[f,m]}),t[11]=f,t[12]=m,t[13]=g):g=t[13];let y;return t[14]!==d||t[15]!==g?(y=(0,b.jsxs)(bi,{children:[c,d,g]}),t[14]=d,t[15]=g,t[16]=y):y=t[16],y};Dn=function(...e){return t=>{e.forEach(n=>{typeof n=="function"?n(t):n!=null&&(n.current=t)})}};var ma={modified:{doc:""},original:{doc:""}},pa=(0,I.createContext)(ma);function Lu(e,t){return Y({},e,t,{modified:Y({},e.modified,t.modified),original:Y({},e.original,t.original)})}var fr=()=>(0,I.useContext)(pa),Ou=e=>{var{children:t,theme:n}=e,[r,o]=(0,I.useReducer)(Lu,Y({},ma,{theme:n}));return(0,I.useEffect)(()=>o({theme:n}),[n]),(0,b.jsx)(pa.Provider,{value:Y({},r,{dispatch:o}),children:t})},Du=["extensions","value","selection","onChange"],ha=e=>{var{extensions:t=[],value:n,selection:r,onChange:o}=e,a=Wt(e,Du),{theme:i,dispatch:s}=fr(),c=kt(Y({},a,{theme:i}));return(0,I.useEffect)(()=>s({original:{doc:n,selection:r,extensions:[...c,...t]},originalExtension:{onChange:o,option:a,extension:[t]}}),[e]),null};ha.displayName="CodeMirrorMerge.Original";var _u=["extensions","value","selection","onChange"],ga=e=>{var{extensions:t=[],value:n,selection:r,onChange:o}=e,a=Wt(e,_u),{theme:i,dispatch:s}=fr(),c=kt(Y({},a,{theme:i}));return(0,I.useEffect)(()=>{s({modified:{doc:n,selection:r,extensions:[...c,...t]},modifiedExtension:{onChange:o,option:a,extension:[t]}})},[e]),null};ga.displayName="CodeMirrorMerge.Modified";var Uu=["className","children","orientation","revertControls","highlightChanges","gutter","collapseUnchanged","destroyRerender","renderRevertControl","diffConfig","root"],Bu=["modified","modifiedExtension","original","originalExtension","theme","dispatch"],ba=I.forwardRef((e,t)=>{var{className:n,children:r,orientation:o,revertControls:a,highlightChanges:i,gutter:s,collapseUnchanged:c,destroyRerender:u=!0,renderRevertControl:d,diffConfig:f,root:h}=e,m=Wt(e,Uu),g=fr(),{modified:y,modifiedExtension:w,original:k,originalExtension:C,theme:T,dispatch:L}=g,U=Wt(g,Bu),A=(0,I.useRef)(null),x=(0,I.useRef)(),G={orientation:o,revertControls:a,highlightChanges:i,gutter:s,collapseUnchanged:c,renderRevertControl:d,diffConfig:f,root:h};(0,I.useImperativeHandle)(t,()=>({container:A.current,view:x.current,modified:y,original:k,config:Y({a:k,b:y,parent:A.current},G)}),[A,x,y,k,G]);var ee=B.updateListener.of(F=>{if(F.docChanged&&typeof(C==null?void 0:C.onChange)=="function"){var j=F.state.doc.toString();C==null||C.onChange(j,F)}}),$=B.updateListener.of(F=>{if(F.docChanged&&typeof(w==null?void 0:w.onChange)=="function"){var j=F.state.doc.toString();w==null||w.onChange(j,F)}});return(0,I.useEffect)(()=>{!x.current&&A.current&&C&&w&&(x.current=new ki(Y({a:Y({},k,{extensions:[...(C==null?void 0:C.extension)||[],...kt(Y({},C==null?void 0:C.option,{theme:T})),ee]}),b:Y({},y,{extensions:[...(w==null?void 0:w.extension)||[],...kt(Y({},w==null?void 0:w.option,{theme:T})),$]}),parent:A.current},G)),L({view:x.current}))},[x,A,C,w]),(0,I.useEffect)(()=>{var K,E;if(k&&k.doc&&x.current){var F=(K=x.current)==null?void 0:K.a.state.doc.toString();if(F!==k.doc){var j;(j=x.current)==null||j.a.dispatch({changes:{from:0,to:F.length,insert:k.doc||""}})}}if(y&&y.doc&&x.current){var se=(E=x.current)==null?void 0:E.b.state.doc.toString();if(se!==y.doc){var _;(_=x.current)==null||_.b.dispatch({changes:{from:0,to:se.length,insert:y.doc||""}})}}if(u&&x.current){var P=x.current.a.state.selection.ranges[0].from,me=x.current.b.state.selection.ranges[0].from;x.current.destroy(),x.current=new ki(Y({a:Y({},k,{extensions:[...(C==null?void 0:C.extension)||[],...kt(Y({},C==null?void 0:C.option,{theme:T}))]}),b:Y({},y,{extensions:[...(w==null?void 0:w.extension)||[],...kt(Y({},w==null?void 0:w.option,{theme:T}))]}),parent:A.current},G)),P&&(x.current.a.focus(),x.current.a.dispatch({selection:{anchor:P,head:P}})),me&&(x.current.b.focus(),x.current.b.dispatch({selection:{anchor:me,head:me}}))}},[x,T,A.current,k,y,C,w,u]),(0,I.useEffect)(()=>()=>x.current&&x.current.destroy(),[]),(0,I.useEffect)(()=>{if(x.current){var F={};U.orientation!==o&&(F.orientation=o),U.revertControls!==a&&(F.revertControls=a),U.highlightChanges!==i&&(F.highlightChanges=i),U.gutter!==s&&(F.gutter=s),U.collapseUnchanged!==c&&(F.collapseUnchanged=c),U.renderRevertControl!==d&&(F.collapseUnchanged=c),Object.keys(F).length&&L&&x.current&&(x.current.reconfigure(Y({},F)),L(Y({},F)))}},[L,x,o,a,i,s,c,d]),(0,b.jsx)("div",Y({ref:A,className:"cm-merge-theme"+(n?" "+n:"")},m,{children:r}))});ba.displayName="CodeMirrorMerge.Internal";var ju=["theme"],wn=I.forwardRef((e,t)=>{var{theme:n}=e;return(0,b.jsx)(Ou,{theme:n,children:(0,b.jsx)(ba,Y({},Wt(e,ju),{ref:t}))})});wn.Original=ha,wn.Modified=ga,wn.displayName="CodeMirrorMerge";var mr=wn,Pu=Re(),Mu=mr.Original,Ru=mr.Modified,ya=[Pd(),B.lineWrapping];const Gu=({cellId:e,aiCompletionCell:t,className:n,onChange:r,currentLanguageAdapter:o,currentCode:a,declineChange:i,acceptChange:s,runCell:c,outputArea:u,children:d})=>{let[f,h]=(0,I.useState)(!1),[m,g]=(0,I.useState)({}),[y,w]=En(hm),k=(0,I.useId)(),C=tf(),{initialPrompt:T,triggerImmediately:L,cellId:U}=t??{},A=U===e,x=oe(tm).get(e),G;(x==null?void 0:x.type)==="update_cell"&&(G=x.previousCode);let{completion:ee,input:$,stop:F,isLoading:j,setCompletion:se,setInput:_,handleSubmit:P,complete:me}=em({api:C.getAiURL("completion").toString(),headers:C.headers(),initialInput:T,streamProtocol:"text",experimental_throttle:100,body:{...Object.keys(m).length>0?m:T?li({input:T}):{},includeOtherCode:y?Er(a):"",code:a,language:o},onError:ne=>{Et({title:"Completion failed",description:Sm(ne)})},onFinish:(ne,tt)=>{se(tt.trimEnd())}}),K=I.useRef(null),E=ee.trimEnd(),S=(0,I.useCallback)(()=>{L&&!j&&T&&me(T)},[L]);(0,I.useEffect)(()=>{var ne;A&&(Ed(()=>{let tt=K.current;return tt!=null&&tt.view?(tt.view.focus(),S(),!0):!1},{retries:3,delay:100,initialDelay:100}),kd((ne=K.current)==null?void 0:ne.view))},[A,S]),(0,I.useEffect)(()=>{A&&_(T||"")},[A,T,_]);let{theme:R}=bm(),D=()=>{s(E),se("")},te=()=>{i(),se("")},Ge=A&&L&&(E||j);u??(u="below");let Pe=A&&(!L||f),Ve=(0,b.jsx)("div",{className:ct("w-full bg-(--cm-background) flex justify-center transition-all duration-300 ease-in-out overflow-hidden",Ge?"max-h-20 opacity-100 translate-y-0":"max-h-0 opacity-0 -translate-y-2"),children:(0,b.jsx)(Ju,{status:j?"loading":"generated",onAccept:D,onReject:te,showInputPrompt:f,setShowInputPrompt:h,runCell:c,className:"mt-4 mb-3 w-128"})}),Me=(ne,tt)=>(0,b.jsxs)(mr,{className:"cm",theme:R,children:[(0,b.jsx)(Mu,{onChange:r,value:ne,extensions:ya}),(0,b.jsx)(Ru,{value:tt,editable:!1,readOnly:!0,extensions:ya})]}),O=()=>{if(E&&A)return Me(a,E);if(!E&&G)return Me(G,a)},W=(0,b.jsxs)(He,{"data-testid":"stop-completion-button",variant:"text",size:"xs",className:"mb-0",onClick:F,children:[(0,b.jsx)(di,{className:"animate-spin mr-1",size:14}),"Stop"]}),V=(0,b.jsx)(Nt,{content:"Submit",children:(0,b.jsx)(He,{variant:"text",size:"icon",onClick:P,children:(0,b.jsx)(Zf,{className:"h-3 w-3"})})}),le=(0,b.jsx)(Nt,{content:"Add context",children:(0,b.jsx)(He,{variant:"text",size:"icon",onClick:()=>im(K),children:(0,b.jsx)(nm,{className:"h-3 w-3"})})}),ce=(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(ui,{isLoading:j,onAccept:D,size:"xs",multipleCompletions:!1,acceptShortcut:"Mod-\u21B5",runCell:c,borderless:!0,buttonStyles:"hover:shadow-none",playButtonStyles:"hover:shadow-none"}),(0,b.jsx)(ci,{onDecline:te,size:"xs",multipleCompletions:!1,declineShortcut:"Shift-Mod-Delete",borderless:!0,className:"hover:shadow-none"})]});return(0,b.jsxs)("div",{"data-ai-input-open":Pe,className:ct("flex flex-col w-full rounded-[inherit]",n),children:[(0,b.jsx)("div",{className:ct("flex items-center gap-2 px-3 transition-all rounded-[inherit] rounded-b-none duration-300",Pe&&"max-h-[400px] border-b min-h-11 visible",!Pe&&"max-h-0 min-h-0 invisible"),children:A&&(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(pm,{className:"text-(--blue-10) shrink-0",size:16}),(0,b.jsx)(rm,{inputRef:K,className:"h-full my-0 py-2 flex items-center",onClose:()=>{i(),se("")},value:$,onChange:ne=>{_(ne),g(li({input:ne}))},onSubmit:()=>{var ne;j||((ne=K.current)!=null&&ne.view&&am(K.current.view),P())},onKeyDown:om({handleAcceptCompletion:D,handleDeclineCompletion:te,isLoading:j,hasCompletion:E.trim().length>0})}),(0,b.jsxs)("div",{className:"-mr-1.5 py-1.5",children:[(0,b.jsxs)("div",{className:"flex flex-row items-center justify-end gap-0.5",children:[j&&W,V,le,(0,b.jsx)(sm,{triggerClassName:"h-7 text-xs",iconSize:"small",forRole:"edit",displayIconOnly:!0})]}),E&&(0,b.jsx)("div",{className:"mt-1 flex items-center gap-1",children:ce})]}),(0,b.jsx)("div",{className:"h-full w-px bg-border mx-2"}),(0,b.jsx)(Nt,{content:"Include code from other cells",children:(0,b.jsxs)("div",{className:"flex flex-row items-start gap-1 overflow-hidden",children:[(0,b.jsx)(Ad,{"data-testid":"include-other-cells-checkbox",id:k,checked:y,onCheckedChange:ne=>w(!!ne)}),(0,b.jsx)(_r,{htmlFor:k,className:"text-muted-foreground text-xs whitespace-nowrap ellipsis",children:"All code"})]})}),(0,b.jsx)(He,{"data-testid":"decline-completion-button",variant:"text",size:"icon",disabled:j,onClick:()=>{F(),i(),se("")},children:(0,b.jsx)(lm,{className:"text-(--red-10)",size:16})})]})}),u==="above"&&Ve,O(),(!E||!A)&&!G&&d,u==="below"&&Ve]})};var Ju=e=>{let t=(0,Pu.c)(27),{status:n,onAccept:r,onReject:o,className:a,showInputPrompt:i,setShowInputPrompt:s,runCell:c}=e,u=n==="loading",d;t[0]===a?d=t[1]:(d=ct("flex flex-row items-center gap-6 rounded-md py-2 px-2.5 text-sm border border-border","shadow-[0_0_6px_1px_rgba(34,197,94,0.15)]",a),t[0]=a,t[1]=d);let f;t[2]===u?f=t[3]:(f=u?(0,b.jsx)(di,{className:"animate-spin text-blue-600 mb-px",size:15,strokeWidth:2,"aria-label":"Generating fix"}):(0,b.jsx)(um,{className:"text-green-600 mb-px",size:15,strokeWidth:2,"aria-label":"Fix generated"}),t[2]=u,t[3]=f);let h=u?"Generating fix...":"Showing fix",m;t[4]===h?m=t[5]:(m=(0,b.jsx)("p",{className:"transition-opacity duration-200 text-muted-foreground",children:h}),t[4]=h,t[5]=m);let g;t[6]!==f||t[7]!==m?(g=(0,b.jsxs)("div",{className:"flex flex-row items-center gap-2",children:[f,m]}),t[6]=f,t[7]=m,t[8]=g):g=t[8];let y;t[9]===Symbol.for("react.memo_cache_sentinel")?(y=(0,b.jsx)(_r,{htmlFor:"show-input-prompt",className:"text-muted-foreground text-xs whitespace-nowrap ellipsis",children:"Show prompt"}),t[9]=y):y=t[9];let w;t[10]!==s||t[11]!==i?(w=(0,b.jsxs)("div",{className:"flex flex-row items-center gap-1",children:[y,(0,b.jsx)(of,{checked:i,onCheckedChange:s,size:"xs"})]}),t[10]=s,t[11]=i,t[12]=w):w=t[12];let k;t[13]!==u||t[14]!==r||t[15]!==c?(k=(0,b.jsx)(ui,{isLoading:u,onAccept:r,size:"xs",borderless:!0,runCell:c}),t[13]=u,t[14]=r,t[15]=c,t[16]=k):k=t[16];let C;t[17]===o?C=t[18]:(C=(0,b.jsx)(ci,{onDecline:o,size:"xs",borderless:!0}),t[17]=o,t[18]=C);let T;t[19]!==k||t[20]!==C?(T=(0,b.jsxs)("div",{className:"flex flex-row items-center gap-2 ml-auto",children:[k,C]}),t[19]=k,t[20]=C,t[21]=T):T=t[21];let L;return t[22]!==d||t[23]!==T||t[24]!==g||t[25]!==w?(L=(0,b.jsxs)("div",{className:d,children:[g,w,T]}),t[22]=d,t[23]=T,t[24]=g,t[25]=w,t[26]=L):L=t[26],L},pr="web application/x-marimo-cell",Wu=Ka({cells:Wd(Ka({code:Gd()})),version:Jd("1.0")});function Vu(){let e=kn();return{copyCells:ue(async t=>{let n=Cr(),r=t.map(o=>n.cellData[o]).filter(Boolean);if(r.length!==0)try{let o={cells:r.map(s=>({code:s.code})),version:"1.0"},a=r.map(s=>s.code).join(`
18
+ `).trim()}var ae=({variant:e,settings:t,styles:n})=>[B.theme({"&":{backgroundColor:t.background,color:t.foreground},".cm-content":{caretColor:t.caret},".cm-cursor, .cm-dropCursor":{borderLeftColor:t.caret},"&.cm-focused .cm-selectionBackgroundm .cm-selectionBackground, .cm-content ::selection":{backgroundColor:t.selection},".cm-activeLine":{backgroundColor:t.lineHighlight},".cm-gutters":{backgroundColor:t.gutterBackground,color:t.gutterForeground},".cm-activeLineGutter":{backgroundColor:t.lineHighlight}},{dark:e==="dark"}),ni(pf.define(n))];ae({variant:"dark",settings:{background:"#200020",foreground:"#D0D0FF",caret:"#7070FF",selection:"#80000080",gutterBackground:"#200020",gutterForeground:"#C080C0",lineHighlight:"#80000040"},styles:[{tag:l.comment,color:"#404080"},{tag:[l.string,l.regexp],color:"#999999"},{tag:l.number,color:"#7090B0"},{tag:[l.bool,l.null],color:"#8080A0"},{tag:[l.punctuation,l.derefOperator],color:"#805080"},{tag:l.keyword,color:"#60B0FF"},{tag:l.definitionKeyword,color:"#B0FFF0"},{tag:l.moduleKeyword,color:"#60B0FF"},{tag:l.operator,color:"#A0A0FF"},{tag:[l.variableName,l.self],color:"#008080"},{tag:l.operatorKeyword,color:"#A0A0FF"},{tag:l.controlKeyword,color:"#80A0FF"},{tag:l.className,color:"#70E080"},{tag:[l.function(l.propertyName),l.propertyName],color:"#50A0A0"},{tag:l.tagName,color:"#009090"},{tag:l.modifier,color:"#B0FFF0"},{tag:[l.squareBracket,l.attributeName],color:"#D0D0FF"}]}),ae({variant:"light",settings:{background:"#fcfcfc",foreground:"#5c6166",caret:"#ffaa33",selection:"#036dd626",gutterBackground:"#fcfcfc",gutterForeground:"#8a919966",lineHighlight:"#8a91991a"},styles:[{tag:l.comment,color:"#787b8099"},{tag:l.string,color:"#86b300"},{tag:l.regexp,color:"#4cbf99"},{tag:[l.number,l.bool,l.null],color:"#ffaa33"},{tag:l.variableName,color:"#5c6166"},{tag:[l.definitionKeyword,l.modifier],color:"#fa8d3e"},{tag:[l.keyword,l.special(l.brace)],color:"#fa8d3e"},{tag:l.operator,color:"#ed9366"},{tag:l.separator,color:"#5c6166b3"},{tag:l.punctuation,color:"#5c6166"},{tag:[l.definition(l.propertyName),l.function(l.variableName)],color:"#f2ae49"},{tag:[l.className,l.definition(l.typeName)],color:"#22a4e6"},{tag:[l.tagName,l.typeName,l.self,l.labelName],color:"#55b4d4"},{tag:l.angleBracket,color:"#55b4d480"},{tag:l.attributeName,color:"#f2ae49"}]}),ae({variant:"dark",settings:{background:"#15191EFA",foreground:"#EEF2F7",caret:"#C4C4C4",selection:"#90B2D557",gutterBackground:"#15191EFA",gutterForeground:"#aaaaaa95",lineHighlight:"#57575712"},styles:[{tag:l.comment,color:"#6E6E6E"},{tag:[l.string,l.regexp,l.special(l.brace)],color:"#5C81B3"},{tag:l.number,color:"#C1E1B8"},{tag:l.bool,color:"#53667D"},{tag:[l.definitionKeyword,l.modifier,l.function(l.propertyName)],color:"#A3D295",fontWeight:"bold"},{tag:[l.keyword,l.moduleKeyword,l.operatorKeyword,l.operator],color:"#697A8E",fontWeight:"bold"},{tag:[l.variableName,l.attributeName],color:"#708E67"},{tag:[l.function(l.variableName),l.definition(l.propertyName),l.derefOperator],color:"#fff"},{tag:l.tagName,color:"#A3D295"}]}),ae({variant:"dark",settings:{background:"#2e241d",foreground:"#BAAE9E",caret:"#A7A7A7",selection:"#DDF0FF33",gutterBackground:"#28211C",gutterForeground:"#BAAE9E90",lineHighlight:"#FFFFFF08"},styles:[{tag:l.comment,color:"#666666"},{tag:[l.string,l.special(l.brace)],color:"#54BE0D"},{tag:l.regexp,color:"#E9C062"},{tag:l.number,color:"#CF6A4C"},{tag:[l.keyword,l.operator],color:"#5EA6EA"},{tag:l.variableName,color:"#7587A6"},{tag:[l.definitionKeyword,l.modifier],color:"#F9EE98"},{tag:[l.propertyName,l.function(l.variableName)],color:"#937121"},{tag:[l.typeName,l.angleBracket,l.tagName],color:"#9B859D"}]}),ae({variant:"dark",settings:{background:"#3b2627",foreground:"#E6E1C4",caret:"#E6E1C4",selection:"#16120E",gutterBackground:"#3b2627",gutterForeground:"#E6E1C490",lineHighlight:"#1F1611"},styles:[{tag:l.comment,color:"#6B4E32"},{tag:[l.keyword,l.operator,l.derefOperator],color:"#EF5D32"},{tag:l.className,color:"#EFAC32",fontWeight:"bold"},{tag:[l.typeName,l.propertyName,l.function(l.variableName),l.definition(l.variableName)],color:"#EFAC32"},{tag:l.definition(l.typeName),color:"#EFAC32",fontWeight:"bold"},{tag:l.labelName,color:"#EFAC32",fontWeight:"bold"},{tag:[l.number,l.bool],color:"#6C99BB"},{tag:[l.variableName,l.self],color:"#7DAF9C"},{tag:[l.string,l.special(l.brace),l.regexp],color:"#D9D762"},{tag:[l.angleBracket,l.tagName,l.attributeName],color:"#EFCB43"}]}),ae({variant:"dark",settings:{background:"#000205",foreground:"#FFFFFF",caret:"#E60065",selection:"#E60C6559",gutterBackground:"#000205",gutterForeground:"#ffffff90",lineHighlight:"#4DD7FC1A"},styles:[{tag:l.comment,color:"#404040"},{tag:[l.string,l.special(l.brace),l.regexp],color:"#00D8FF"},{tag:l.number,color:"#E62286"},{tag:[l.variableName,l.attributeName,l.self],color:"#E62286",fontWeight:"bold"},{tag:l.function(l.variableName),color:"#fff",fontWeight:"bold"}]}),ae({variant:"light",settings:{background:"#fff",foreground:"#000",caret:"#000",selection:"#BDD5FC",gutterBackground:"#fff",gutterForeground:"#00000070",lineHighlight:"#FFFBD1"},styles:[{tag:l.comment,color:"#BCC8BA"},{tag:[l.string,l.special(l.brace),l.regexp],color:"#5D90CD"},{tag:[l.number,l.bool,l.null],color:"#46A609"},{tag:l.keyword,color:"#AF956F"},{tag:[l.definitionKeyword,l.modifier],color:"#C52727"},{tag:[l.angleBracket,l.tagName,l.attributeName],color:"#606060"},{tag:l.self,color:"#000"}]}),ae({variant:"dark",settings:{background:"#00254b",foreground:"#FFFFFF",caret:"#FFFFFF",selection:"#B36539BF",gutterBackground:"#00254b",gutterForeground:"#FFFFFF70",lineHighlight:"#00000059"},styles:[{tag:l.comment,color:"#0088FF"},{tag:l.string,color:"#3AD900"},{tag:l.regexp,color:"#80FFC2"},{tag:[l.number,l.bool,l.null],color:"#FF628C"},{tag:[l.definitionKeyword,l.modifier],color:"#FFEE80"},{tag:l.variableName,color:"#CCCCCC"},{tag:l.self,color:"#FF80E1"},{tag:[l.className,l.definition(l.propertyName),l.function(l.variableName),l.definition(l.typeName),l.labelName],color:"#FFDD00"},{tag:[l.keyword,l.operator],color:"#FF9D00"},{tag:[l.propertyName,l.typeName],color:"#80FFBB"},{tag:l.special(l.brace),color:"#EDEF7D"},{tag:l.attributeName,color:"#9EFFFF"},{tag:l.derefOperator,color:"#fff"}]}),ae({variant:"dark",settings:{background:"#060521",foreground:"#E0E0E0",caret:"#FFFFFFA6",selection:"#122BBB",gutterBackground:"#060521",gutterForeground:"#E0E0E090",lineHighlight:"#FFFFFF0F"},styles:[{tag:l.comment,color:"#AEAEAE"},{tag:[l.string,l.special(l.brace),l.regexp],color:"#8DFF8E"},{tag:[l.className,l.definition(l.propertyName),l.function(l.variableName),l.function(l.definition(l.variableName)),l.definition(l.typeName)],color:"#A3EBFF"},{tag:[l.number,l.bool,l.null],color:"#62E9BD"},{tag:[l.keyword,l.operator],color:"#2BF1DC"},{tag:[l.definitionKeyword,l.modifier],color:"#F8FBB1"},{tag:[l.variableName,l.self],color:"#B683CA"},{tag:[l.angleBracket,l.tagName,l.typeName,l.propertyName],color:"#60A4F1"},{tag:l.derefOperator,color:"#E0E0E0"},{tag:l.attributeName,color:"#7BACCA"}]}),ae({variant:"dark",settings:{background:"#2d2f3f",foreground:"#f8f8f2",caret:"#f8f8f0",selection:"#44475a",gutterBackground:"#282a36",gutterForeground:"rgb(144, 145, 148)",lineHighlight:"#44475a"},styles:[{tag:l.comment,color:"#6272a4"},{tag:[l.string,l.special(l.brace)],color:"#f1fa8c"},{tag:[l.number,l.self,l.bool,l.null],color:"#bd93f9"},{tag:[l.keyword,l.operator],color:"#ff79c6"},{tag:[l.definitionKeyword,l.typeName],color:"#8be9fd"},{tag:l.definition(l.typeName),color:"#f8f8f2"},{tag:[l.className,l.definition(l.propertyName),l.function(l.variableName),l.attributeName],color:"#50fa7b"}]}),ae({variant:"light",settings:{background:"#FFFFFF",foreground:"#000000",caret:"#000000",selection:"#80C7FF",gutterBackground:"#FFFFFF",gutterForeground:"#00000070",lineHighlight:"#C1E2F8"},styles:[{tag:l.comment,color:"#AAAAAA"},{tag:[l.keyword,l.operator,l.typeName,l.tagName,l.propertyName],color:"#2F6F9F",fontWeight:"bold"},{tag:[l.attributeName,l.definition(l.propertyName)],color:"#4F9FD0"},{tag:[l.className,l.string,l.special(l.brace)],color:"#CF4F5F"},{tag:l.number,color:"#CF4F5F",fontWeight:"bold"},{tag:l.variableName,fontWeight:"bold"}]}),ae({variant:"light",settings:{background:"#f2f1f8",foreground:"#0c006b",caret:"#5c49e9",selection:"#d5d1f2",gutterBackground:"#f2f1f8",gutterForeground:"#0c006b70",lineHighlight:"#e1def3"},styles:[{tag:l.comment,color:"#9995b7"},{tag:l.keyword,color:"#ff5792",fontWeight:"bold"},{tag:[l.definitionKeyword,l.modifier],color:"#ff5792"},{tag:[l.className,l.tagName,l.definition(l.typeName)],color:"#0094f0"},{tag:[l.number,l.bool,l.null,l.special(l.brace)],color:"#5842ff"},{tag:[l.definition(l.propertyName),l.function(l.variableName)],color:"#0095a8"},{tag:l.typeName,color:"#b3694d"},{tag:[l.propertyName,l.variableName],color:"#fa8900"},{tag:l.operator,color:"#ff5792"},{tag:l.self,color:"#e64100"},{tag:[l.string,l.regexp],color:"#00b368"},{tag:[l.paren,l.bracket],color:"#0431fa"},{tag:l.labelName,color:"#00bdd6"},{tag:l.attributeName,color:"#e64100"},{tag:l.angleBracket,color:"#9995b7"}]}),ae({variant:"light",settings:{background:"#faf4ed",foreground:"#575279",caret:"#575279",selection:"#6e6a8614",gutterBackground:"#faf4ed",gutterForeground:"#57527970",lineHighlight:"#6e6a860d"},styles:[{tag:l.comment,color:"#9893a5"},{tag:[l.bool,l.null],color:"#286983"},{tag:l.number,color:"#d7827e"},{tag:l.className,color:"#d7827e"},{tag:[l.angleBracket,l.tagName,l.typeName],color:"#56949f"},{tag:l.attributeName,color:"#907aa9"},{tag:l.punctuation,color:"#797593"},{tag:[l.keyword,l.modifier],color:"#286983"},{tag:[l.string,l.regexp],color:"#ea9d34"},{tag:l.variableName,color:"#d7827e"}]}),ae({variant:"light",settings:{background:"#FFFFFF",foreground:"#000000",caret:"#000000",selection:"#FFFD0054",gutterBackground:"#FFFFFF",gutterForeground:"#00000070",lineHighlight:"#00000008"},styles:[{tag:l.comment,color:"#CFCFCF"},{tag:[l.number,l.bool,l.null],color:"#E66C29"},{tag:[l.className,l.definition(l.propertyName),l.function(l.variableName),l.labelName,l.definition(l.typeName)],color:"#2EB43B"},{tag:l.keyword,color:"#D8B229"},{tag:l.operator,color:"#4EA44E",fontWeight:"bold"},{tag:[l.definitionKeyword,l.modifier],color:"#925A47"},{tag:l.string,color:"#704D3D"},{tag:l.typeName,color:"#2F8996"},{tag:[l.variableName,l.propertyName],color:"#77ACB0"},{tag:l.self,color:"#77ACB0",fontWeight:"bold"},{tag:l.regexp,color:"#E3965E"},{tag:[l.tagName,l.angleBracket],color:"#BAA827"},{tag:l.attributeName,color:"#B06520"},{tag:l.derefOperator,color:"#000"}]}),ae({variant:"light",settings:{background:"#fef7e5",foreground:"#586E75",caret:"#000000",selection:"#073642",gutterBackground:"#fef7e5",gutterForeground:"#586E7580",lineHighlight:"#EEE8D5"},styles:[{tag:l.comment,color:"#93A1A1"},{tag:l.string,color:"#2AA198"},{tag:l.regexp,color:"#D30102"},{tag:l.number,color:"#D33682"},{tag:l.variableName,color:"#268BD2"},{tag:[l.keyword,l.operator,l.punctuation],color:"#859900"},{tag:[l.definitionKeyword,l.modifier],color:"#073642",fontWeight:"bold"},{tag:[l.className,l.self,l.definition(l.propertyName)],color:"#268BD2"},{tag:l.function(l.variableName),color:"#268BD2"},{tag:[l.bool,l.null],color:"#B58900"},{tag:l.tagName,color:"#268BD2",fontWeight:"bold"},{tag:l.angleBracket,color:"#93A1A1"},{tag:l.attributeName,color:"#93A1A1"},{tag:l.typeName,color:"#859900"}]}),ae({variant:"light",settings:{background:"#FFFFFF",foreground:"#4D4D4C",caret:"#AEAFAD",selection:"#D6D6D6",gutterBackground:"#FFFFFF",gutterForeground:"#4D4D4C80",lineHighlight:"#EFEFEF"},styles:[{tag:l.comment,color:"#8E908C"},{tag:[l.variableName,l.self,l.propertyName,l.attributeName,l.regexp],color:"#C82829"},{tag:[l.number,l.bool,l.null],color:"#F5871F"},{tag:[l.className,l.typeName,l.definition(l.typeName)],color:"#C99E00"},{tag:[l.string,l.special(l.brace)],color:"#718C00"},{tag:l.operator,color:"#3E999F"},{tag:[l.definition(l.propertyName),l.function(l.variableName)],color:"#4271AE"},{tag:l.keyword,color:"#8959A8"},{tag:l.derefOperator,color:"#4D4D4C"}]});const _c=[ae({variant:"dark",settings:{background:"var(--cm-background)",foreground:"#abb2bf",caret:"#528bff",selection:"#3E4451",lineHighlight:"#2c313c",gutterBackground:"var(--color-background)",gutterForeground:"var(--gray-10)"},styles:[{tag:l.comment,color:"var(--cm-comment)"},{tag:l.variableName,color:"#abb2bf"},{tag:[l.string,l.special(l.brace)],color:"#98c379"},{tag:l.number,color:"#d19a66"},{tag:l.bool,color:"#d19a66"},{tag:l.null,color:"#d19a66"},{tag:l.keyword,color:"#c678dd",fontWeight:500},{tag:l.className,color:"#61afef"},{tag:l.definition(l.typeName),color:"#61afef"},{tag:l.typeName,color:"#56b6c2"},{tag:l.angleBracket,color:"#abb2bf"},{tag:l.tagName,color:"#e06c75"},{tag:l.attributeName,color:"#d19a66"},{tag:l.operator,color:"#56b6c2",fontWeight:500},{tag:[l.function(l.variableName)],color:"#61afef"},{tag:[l.propertyName],color:"#e5c07b"}]}),B.theme({".mo-cm-reactive-reference":{fontWeight:"400",color:"#2a7aa5",borderBottom:"2px solid #bad3de"},".mo-cm-reactive-reference-hover":{cursor:"pointer",borderBottomWidth:"3px",borderBottomColor:"#4a90a5"}})],Uc=[ae({variant:"light",settings:{background:"#ffffff",foreground:"#000000",caret:"#000000",selection:"#d7d4f0",lineHighlight:"#cceeff44",gutterBackground:"var(--color-background)",gutterForeground:"var(--gray-10)"},styles:[{tag:l.comment,color:"var(--cm-comment)"},{tag:l.variableName,color:"#000000"},{tag:[l.string,l.special(l.brace)],color:"#a11"},{tag:l.number,color:"#164"},{tag:l.bool,color:"#219"},{tag:l.null,color:"#219"},{tag:l.keyword,color:"#708",fontWeight:500},{tag:l.className,color:"#00f"},{tag:l.definition(l.typeName),color:"#00f"},{tag:l.typeName,color:"#085"},{tag:l.angleBracket,color:"#000000"},{tag:l.tagName,color:"#170"},{tag:l.attributeName,color:"#00c"},{tag:l.operator,color:"#a2f",fontWeight:500},{tag:[l.function(l.variableName)],color:"#00c"},{tag:[l.propertyName],color:"#05a"}]}),B.theme({".mo-cm-reactive-reference":{fontWeight:"400",color:"#005f87",borderBottom:"2px solid #bad3de"},".mo-cm-reactive-reference-hover":{cursor:"pointer",borderBottomWidth:"3px"}})];function oa(e){let{showPlaceholder:t,enableAI:n}=e;return t?"marimo-import":n?"ai":"none"}const Bc=e=>{let{cellId:t,keymapConfig:n,hotkeys:r,enableAI:o,cellActions:a,completionConfig:i,lspConfig:s,diagnosticsConfig:c,displayConfig:u,inlineAiTooltip:d}=e,f=oa(e);return[Vd(n,r),Fc(),Lc(),cs(),Ud({completionConfig:i,hotkeys:r,placeholderType:f,lspConfig:s,diagnosticsConfig:c}),cd({cellId:t,hotkeys:r,cellActions:a,keymapConfig:n}),Pc(e),Ic(),c!=null&&c.enabled?Ff():[],o&&d?[es({prompt:h=>ss({prompt:h.prompt,selection:h.selection,codeBefore:h.codeBefore,codeAfter:h.codeAfter,language:Nd(h.editorView)})}),Mn.of({hideOnBlur:!0})]:[],gd(t,u.reference_highlighting??!0)]};var jc=e=>{let{from:t,to:n}=e.state.selection.main;if(t!==n)return!1;let r=e.state.doc.lineAt(n);return r.text.slice(0,n-r.from).trim()===""?!1:Rf(e)};const Pc=e=>{let{theme:t,hotkeys:n,completionConfig:r,cellId:o,lspConfig:a,diagnosticsConfig:i}=e,s=oa(e);return[B.lineWrapping,gf(),vf(),Nf(),Sf(),hf(),Cf(),af(),yf({position:"fixed",parent:document.querySelector("#App")??void 0}),Id(),t==="dark"?_c:Uc,vd(a),pc(r),kf(),Gf(),ds(),ut.high(Je.of(Pf)),wf(),df(),uf.of(" "),ni(mf,{fallback:!0}),Je.of(sf),Cd({placeholderType:s,completionConfig:r,hotkeys:n,cellId:o,lspConfig:{...a,diagnostics:i}}),xd.of(Tf()),Fr.allowMultipleSelections.of(!0),Cc(n),Je.of([{key:"Tab",run:c=>oi(c)||jc(c)||Df(c),preventDefault:!0},{key:n.getHotkey("completion.moveDown").key,run:c=>Gt(c.state)===null?!1:(Ln(!0)(c),!0),preventDefault:!0},{key:n.getHotkey("completion.moveUp").key,run:c=>Gt(c.state)===null?!1:(Ln(!1)(c),!0),preventDefault:!0}]),Je.of([..._f,xf])]};var et=(e=>!e||e instanceof WebAssembly.Module?e:typeof e=="object"&&"default"in e?e.default??e:e)(Pm),nr=e=>{Mm(e),typeof Ci=="function"&&Ci(),Mc(kt)};function Mc(e){typeof e.__wbindgen_start=="function"&&e.__wbindgen_start()}if(et&&et.__wbindgen_start)nr(et);else if("Bun"in globalThis){let e;if(et instanceof WebAssembly.Module)({instance:e}=await WebAssembly.instantiate(et,{"./loro_wasm_bg.js":kt}));else{let t=Bun.pathToFileURL(et);({instance:e}=await WebAssembly.instantiateStreaming(fetch(t),{"./loro_wasm_bg.js":kt}))}nr(e.exports)}else{let e=et instanceof WebAssembly.Module?et:await fm(()=>import("./loro_wasm_bg-BTbzDT9t.js").then(async r=>(await r.__tla,r)),__vite__mapDeps([0,1,2]),import.meta.url),t=e instanceof WebAssembly.Module?e:e&&e.default||e,n;if(t instanceof WebAssembly.Instance)n=t;else if(t instanceof WebAssembly.Module)n=await WebAssembly.instantiate(t,{"./loro_wasm_bg.js":kt});else if(t instanceof ArrayBuffer||ArrayBuffer.isView(t)){let{instance:r}=await WebAssembly.instantiate(t,{"./loro_wasm_bg.js":kt});n=r}else if(typeof t=="string"||t instanceof URL){let r=await fetch(t),{instance:o}=await WebAssembly.instantiateStreaming(r,{"./loro_wasm_bg.js":kt});n=o}else throw console.error("Unsupported wasm import type:",t),Error("Unsupported wasm import type: "+typeof t);nr(n.exports??n)}var Rc=["Map","Text","List","Tree","MovableList","Counter"];function Gc(e){return e.startsWith("cid:")}function aa(e){if(typeof e!="object"||!e)return!1;let t=Object.getPrototypeOf(e);return typeof t!="object"||!t||typeof t.kind!="function"?!1:Rc.includes(e.kind())}var Jc=class{constructor(e,t=3e4){this.listeners=new Set,this.inner=new Si(e,t),this.peer=e,this.timeout=t}apply(e,t="remote"){let{updated:n,added:r}=this.inner.apply(e);this.listeners.forEach(o=>{o({updated:n,added:r,removed:[]},t)}),this.startTimerIfNotEmpty()}setLocalState(e){let t=this.inner.getState(this.peer)==null;this.inner.setLocalState(e),t?this.listeners.forEach(n=>{n({updated:[],added:[this.inner.peer()],removed:[]},"local")}):this.listeners.forEach(n=>{n({updated:[this.inner.peer()],added:[],removed:[]},"local")}),this.startTimerIfNotEmpty()}getLocalState(){return this.inner.getState(this.peer)}getAllStates(){return this.inner.getAllStates()}encode(e){return this.inner.encode(e)}encodeAll(){return this.inner.encodeAll()}addListener(e){this.listeners.add(e)}removeListener(e){this.listeners.delete(e)}peers(){return this.inner.peers()}destroy(){clearInterval(this.timer),this.listeners.clear()}startTimerIfNotEmpty(){this.inner.isEmpty()||this.timer!=null||(this.timer=setInterval(()=>{let e=this.inner.removeOutdated();e.length>0&&this.listeners.forEach(t=>{t({updated:[],added:[],removed:e},"timeout")}),this.inner.isEmpty()&&(clearInterval(this.timer),this.timer=void 0)},this.timeout/2))}};jr.prototype.toJsonWithReplacer=function(e){let t=new Set,n=this,r=(a,i)=>{if(typeof i=="string"&&Gc(i)&&!t.has(i)){t.add(i);let c=n.getContainerById(i);if(c==null)throw Error(`ContainerID not found: ${i}`);let u=e(a,c);if(u===c){let d=c.getShallowValue();return typeof d=="object"?o(d):d}if(aa(u))throw Error("Using new container is not allowed in toJsonWithReplacer");return typeof u=="object"&&u?o(u):u}if(typeof i=="object"&&i)return o(i);let s=e(a,i);if(aa(s))throw Error("Using new container is not allowed in toJsonWithReplacer");return s},o=a=>{if(Array.isArray(a))return a.map((s,c)=>r(c,s)).filter(s=>s!==void 0);let i={};for(let[s,c]of Object.entries(a)){let u=r(s,c);u!==void 0&&(i[s]=u)}return i};return o(n.getShallowValue())};var ia=Symbol("loro.callPendingEventsWrapped");function rr(e,t){let n=Object.getOwnPropertyDescriptor(e,t);if(!n||typeof n.value!="function")return;let r=n.value;if(r[ia])return;let o=function(...a){let i;try{return i=r.apply(this,a),i}finally{i&&typeof i.then=="function"?i.finally(()=>{ki()}):ki()}};o[ia]=!0,Object.defineProperty(e,t,{...n,value:o})}function Wc(e,t){for(let n of t)rr(e,n)}function or(e){let t=new Set,n=e;for(;n&&n!==Object.prototype&&n!==Function.prototype;){for(let r of Object.getOwnPropertyNames(n))r==="constructor"||t.has(r)||(t.add(r),rr(n,r));for(let r of Object.getOwnPropertySymbols(n))t.has(r)||(t.add(r),rr(n,r));n=Object.getPrototypeOf(n)}}or(jr.prototype),or(Bm.prototype),or(Si.prototype),Wc(jm.prototype,["undo","redo"]);const Vc=B.baseTheme({".loro-cursor":{position:"absolute",width:"2px",display:"inline-block",height:"1.2em"},".loro-cursor::before":{position:"absolute",top:"1.3em",left:"0",content:"var(--rtc-name)",padding:"2px 6px",fontSize:"12px",borderRadius:"3px",whiteSpace:"nowrap",userSelect:"none",backgroundColor:"inherit",opacity:"0.7"},".loro-selection":{opacity:"0.5"}});In.define();const _t=pe.define(),ar=qe.define({create(){return{remoteCursors:new Map,isCheckout:!1}},update(e,t){for(let n of t.effects)if(n.is(_t))switch(n.value.type){case"update":{let{peer:r,user:o,cursor:a}=n.value;e.remoteCursors.set(r,{uid:r,cursor:a,user:o});break}case"delete":e.remoteCursors.delete(n.value.peer);break;case"checkout":e.isCheckout=n.value.checkout}return e}});var sa=e=>{let t=e.transactions.flatMap(n=>n.effects).filter(n=>n.is(_t));return e.docChanged||e.viewportChanged||t.length>0};const $c=()=>ti({above:!0,class:"loro-cursor-layer",update:sa,markers:e=>{let{remoteCursors:t,isCheckout:n}=e.state.field(ar);return n?[]:[...t.values()].flatMap(r=>{var a,i;let o=wt.cursor(r.cursor.anchor);return qc.createCursor(e,o,((a=r.user)==null?void 0:a.name)||"unknown",((i=r.user)==null?void 0:i.colorClassName)||"")})}}),Hc=()=>ti({above:!1,class:"loro-selection-layer",update:sa,markers:e=>{let{remoteCursors:t,isCheckout:n}=e.state.field(ar);return n?[]:[...t.entries()].filter(([,r])=>r.cursor.head!==void 0&&r.cursor.anchor!==r.cursor.head).flatMap(([,r])=>{var a;let o=wt.range(r.cursor.anchor,r.cursor.head);return Ef.forRange(e,`loro-selection ${((a=r.user)==null?void 0:a.colorClassName)||""}`,o)})}});var qc=class Jr{constructor(t,n,r,o,a){this.left=t,this.top=n,this.height=r,this.name=o,this.colorClassName=a}draw(){let t=document.createElement("div");return this.adjust(t),t}update(t){return this.adjust(t),!0}adjust(t){t.style.left=`${this.left}px`,t.style.top=`${this.top}px`,t.style.height=`${this.height}px`,t.className=`loro-cursor ${this.colorClassName}`,t.style.setProperty("--rtc-name",`"${this.name}"`)}eq(t){return this.left===t.left&&this.top===t.top&&this.height===t.height&&this.name===t.name}static createCursor(t,n,r,o){let a=Jr.calculateAbsoluteCursorPosition(n,t);if(!a)return[];let i=t.scrollDOM.getBoundingClientRect(),s=(t.textDirection===bf.LTR?i.left:i.right-t.scrollDOM.clientWidth)-t.scrollDOM.scrollLeft,c=i.top-t.scrollDOM.scrollTop;return[new Jr(a.left-s,a.top-c,a.bottom-a.top,r,o)]}static calculateAbsoluteCursorPosition(t,n){let r=Math.max(0,Math.min(n.state.doc.length,t.anchor));return n.coordsAtPos(r,t.assoc||1)}},zc=(e,t,n,r)=>{let o=[],{updated:a,added:i}=n;for(let s of[...a,...i]){let c=la(e,t,s,r);c&&o.push(c)}return o},la=(e,t,n,r)=>{var c,u;let o=t.getAllStates()[n];if(!o||n===e.peerIdStr||o.scopeId!==r)return;if(o.type==="delete")return _t.of({type:"delete",peer:o.uid,scopeId:o.scopeId});let a=xi.decode(o.cursor.anchor),i=((c=e.getCursorPos(a))==null?void 0:c.offset)??0,s=i;if(o.cursor.head){let d=xi.decode(o.cursor.head);s=((u=e.getCursorPos(d))==null?void 0:u.offset)??0}return _t.of({type:"update",peer:o.uid,scopeId:o.scopeId,cursor:{anchor:i,head:s},user:o.user})},Kc=class{constructor(e,t,n,r,o,a,i){this.view=e,this.doc=t,this.user=n,this.awareness=r,this.getTextFromDoc=o,this.scopeId=a,this.getUserId=i,this.sub=this.doc.subscribe(s=>{if(s.by==="local"){let c=[];for(let u of this.awareness.peers()){let d=la(this.doc,this.awareness,u,this.scopeId);d&&c.push(d)}this.view.dispatch({effects:c})}else s.by==="checkout"&&this.view.dispatch({effects:[_t.of({type:"checkout",checkout:this.doc.isDetached()})]})})}update(e){if(!e.selectionSet&&!e.focusChanged&&!e.docChanged)return;let t=e.state.selection.main;if(this.view.hasFocus&&!this.doc.isDetached()){let n=Xc({doc:this.doc,getTextFromDoc:this.getTextFromDoc,anchor:t.anchor,head:t.head});this.awareness.setLocalState({type:"update",uid:this.getUserId?this.getUserId():this.doc.peerIdStr,scopeId:this.scopeId,cursor:n,user:this.user})}else this.awareness.setLocalState({type:"delete",uid:this.getUserId?this.getUserId():this.doc.peerIdStr,scopeId:this.scopeId})}destroy(){var e;(e=this.sub)==null||e.call(this),this.awareness.setLocalState({type:"delete",uid:this.getUserId?this.getUserId():this.doc.peerIdStr,scopeId:this.scopeId})}},Yc=class{constructor(e,t,n,r){this.view=e,this.doc=t,this.awareness=n,this.scopeId=r;let o=async(a,i)=>{i!=="local"&&this.view.dispatch({effects:zc(this.doc,this.awareness,a,this.scopeId)})};this._awarenessListener=o,this.awareness.addListener(o)}destroy(){this._awarenessListener&&this.awareness.removeListener(this._awarenessListener)}},Xc=({doc:e,getTextFromDoc:t,anchor:n,head:r})=>{var i,s;n===r&&(r=void 0);let o=(i=t(e).getCursor(n))==null?void 0:i.encode();if(!o)throw Error("cursor head not found");let a;return r!==void 0&&(a=(s=t(e).getCursor(r))==null?void 0:s.encode()),{anchor:o,head:a}};const gn=["bg-(--amber-6)","bg-(--blue-6)","bg-(--crimson-6)","bg-(--cyan-6)","bg-(--grass-6)","bg-(--gray-6)","bg-(--green-6)","bg-(--lime-6)","bg-(--orange-6)","bg-(--purple-6)","bg-(--red-6)","bg-(--sage-6)","bg-(--sky-6)","bg-(--slate-6)"],Qc=e=>{if(typeof e=="string"){let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n),t=Math.trunc(t);return gn[Math.abs(t)%gn.length]}return gn[e%gn.length]},Zc=(e,t,n)=>ze.define(r=>new eu(r,e,t,n)),bt=In.define();var eu=class{constructor(e,t,n,r){p(this,"isInitDispatch",!1);p(this,"onRemoteUpdate",e=>{if(e.by!=="local"){if(e.by==="checkout"){this.view.dispatch({changes:[{from:0,to:this.view.state.doc.length,insert:this.getTextFromDoc(this.doc).toString()}],annotations:[bt.of(this)]});return}if(e.by==="import"){let t=[],n=0;for(let{diff:r,path:o}of e.events){if(o.join("/")!==this.docPath.join("/")||r.type!=="text")continue;let a=r.diff;for(let i of a)i.insert?t.push({from:n,to:n,insert:i.insert}):i.delete?(t.push({from:n,to:n+i.delete}),n+=i.delete):i.retain!=null&&(n+=i.retain);t.length>0&&this.view.dispatch({changes:t,annotations:[bt.of(this)]})}}}});this.view=e,this.doc=t,this.docPath=n,this.getTextFromDoc=r,this.sub=t.subscribe(this.onRemoteUpdate),Promise.resolve().then(()=>{this.isInitDispatch=!0;let o=this.view.state.doc.toString(),a=this.getTextFromDoc(this.doc);o!==a.toString()&&e.dispatch({changes:[{from:0,to:this.view.state.doc.length,insert:a.toString()}]})})}update(e){if(this.isInitDispatch){this.isInitDispatch=!1;return}if(!e.docChanged||e.transactions.length>0&&(e.transactions[0].annotation(bt)===this||e.transactions[0].annotation(bt)==="undo"))return;let t=0;e.changes.iterChanges((n,r,o,a,i)=>{let s=i.sliceString(0,i.length,`
19
+ `);n!==r&&this.getTextFromDoc(this.doc).delete(n+t,r-n),s.length>0&&this.getTextFromDoc(this.doc).insert(n+t,s),t+=s.length-(r-n)}),this.doc.commit()}destroy(){var e;(e=this.sub)==null||e.call(this),this.sub=void 0}},fe=$e.get("rtc"),ca=fe.get("awareness").disabled(),ir="awareness:";function tu(e,t){let n=new TextEncoder().encode(e);return new Uint8Array([...n,...t])}function nu(e,t){return new TextDecoder().decode(e.slice(0,t.length))===t}function ru(e,t){return e.slice(t.length)}dt=Bt(void 0);var ie=new jr,bn=new Jc(ie.peerIdStr),sr=jf(()=>{fe.debug("creating websocket");let e=new Gm(Za().getWsSyncURL(Qd()).toString(),void 0,{maxRetries:10,debug:!1,startClosed:!0,connectionTimeout:1e4});return Promise.resolve().then(async()=>{await Qa(),hm()==="edit"&&e.reconnect()}),e.addEventListener("message",async t=>{let n=await t.data.arrayBuffer(),r=new Uint8Array(n);if(nu(r,ir)){let o=ru(r,ir);bn.apply(o),ca.debug("applied awareness update");return}ie.import(r),fe.debug("imported doc change. new doc:",ie.toJSON()),Q.get(dt)!==ie&&Q.set(dt,ie)}),e.addEventListener("open",()=>{fe.debug("websocket open")}),e.addEventListener("close",t=>{fe.warn("websocket close",t),Q.get(dt)===ie&&Q.set(dt,void 0)}),e});Nr()&&sr(),ie.subscribeLocalUpdates(e=>{fe.debug("local update, sending to server"),sr().send(e)}),bn.addListener((e,t)=>{let n=[...e.added,...e.removed,...e.updated];t==="local"&&(ca.debug("awareness changes",n),sr().send(tu(ir,bn.encode(n))))});function lr(e,t,n=""){if(Kd())return{extension:[],code:n};let r=ie.getByPath(`codes/${e}`)!==void 0,o=ie.getMap("codes").getOrCreateContainer(e,new Br);return r||(fe.log("initializing code for new cell",n),o.insert(0,n)),{code:n.toString(),extension:[ou(e),au(e),iu(ie,bn,{get name(){return Q.get(hd)||"Anonymous"},get colorClassName(){return Qc(this.name)}},()=>o,e),Zc(ie,["codes",e],()=>o)]}}function ou(e){let t=(r,o)=>{let a=r.state.field(xn).type,i=o.toString();i&&i!==a&&(fe.debug(`[incoming] setting language type: ${a} -> ${i}`),jt(r,{language:i,keepCodeAsIs:!0}))},n=(r,o)=>{let a=r.state.field(vr),i=o.toJSON();Nn(a,i)||r.dispatch({effects:[Ja.of(i)],annotations:[bt.of(!0)]})};return ze.define(r=>{let o;return Promise.resolve().then(()=>{let a=ie.getByPath(`languages/${e}`);if(!a){fe.error("no language container found for cell",e);return}Pt(a instanceof Br,"language type is not a LoroText");let i=ie.getByPath(`language_metadata/${e}`);if(!i){fe.error("no language metadata container found for cell",e);return}Pt(i instanceof Ai,"language metadata is not a LoroMap"),t(r,a),n(r,i),o=ie.subscribe(s=>{if(s.origin==="local")return;let c=s.events.some(d=>d.target===a.id),u=s.events.some(d=>d.target===i.id);c&&t(r,a),u&&n(r,i)})}),{destroy(){o()}}})}function au(e){let t=ie.getMap("languages").getOrCreateContainer(e,new Br),n=ie.getMap("language_metadata").getOrCreateContainer(e,new Ai);return B.updateListener.of(r=>{let o=t.toString()!=="";if(!r.docChanged&&o)return;if(!o){let i=kr(r.state).type;jt(r.view,{language:i}),fe.debug("no initial language, setting default to",i),t.delete(0,t.length),t.insert(0,i),fe.debug("no initial language metadata, setting default to",r.state.field(vr));let s=r.state.field(vr);for(let c of Object.keys(s))n.set(c,s[c]);ie.commit();return}let a=!1;for(let i of r.transactions)if(!i.annotation(bt)){for(let s of i.effects)if(s.is(Dd)&&t.toString()!==s.value.type&&(fe.debug(`[outgoing] language change: ${t} -> ${s.value.type}`),t.delete(0,t.length),t.insert(0,s.value.type),a=!0),s.is(Ja)||s.is(Ma)){let c=s.value;s.is(Ma)?(fe.debug("[outgoing] setting language metadata: ",c),n.clear()):fe.debug("[outgoing] updating language metadata: ",c);for(let u of Object.keys(c))n.set(u,c[u]);a=!0}}a&&ie.commit()})}function iu(e,t,n,r,o,a){let i=`loro:cell:${o}`;return[ar,$c(),Hc(),ze.define(s=>new Kc(s,e,n,t,r,i,a)),ze.define(s=>new Yc(s,e,t,i)),Vc]}var su=Re();Gr=e=>{let t=(0,su.c)(41),{resetOnBlur:n,placeholderText:r,initialValue:o,flexibleWidth:a,onNameChange:i,className:s}=e,c=n===void 0?!1:n,u=o===void 0?null:o,d=a===void 0?!1:a,{sendListFiles:f}=Jt(),[h,m]=(0,I.useState)(u),g;t[0]===Symbol.for("react.memo_cache_sentinel")?(g=[],t[0]=g):g=t[0];let[y,w]=(0,I.useState)(g),[k,C]=(0,I.useState)(!1),T=(0,I.useRef)(null),L=(0,I.useRef)(!1),U,A;t[1]===u?(U=t[2],A=t[3]):(U=()=>{m(u)},A=[u],t[1]=u,t[2]=U,t[3]=A),(0,I.useEffect)(U,A);let x;t[4]===Symbol.for("react.memo_cache_sentinel")?(x=()=>{C(!0)},t[4]=x):x=t[4];let G=x,ee;t[5]!==u||t[6]!==c?(ee=ce=>{var ne;(ne=ce.relatedTarget)!=null&&ne.closest(".filename-input")||(C(!1),c&&m(u))},t[5]=u,t[6]=c,t[7]=ee):ee=t[7];let $=ee,F;t[8]===h?F=t[9]:(F=Qe.dirname(h||""),t[8]=h,t[9]=F);let j=F,se=Qe.basename(h||""),_=y.filter(ce=>Qe.basename(ce.path).startsWith(se)),P;t[10]!==j||t[11]!==k||t[12]!==f?(P=async()=>{if(!k){w([]);return}w((await f({path:j})).files)},t[10]=j,t[11]=k,t[12]=f,t[13]=P):P=t[13];let me;t[14]!==j||t[15]!==k?(me=[j,k],t[14]=j,t[15]=k,t[16]=me):me=t[16];let{isPending:K}=Am(P,me),E=lu(h,y,u),S=(E||_.length>0)&&(0,b.jsxs)(yi,{className:"font-mono",children:[!K&&(0,b.jsx)(Im,{children:"No files"}),E&&(0,b.jsxs)(bi,{variant:"success",className:"py-2 px-3",onSelect:()=>{var ce;E&&(L.current=!0,i(E),(ce=T.current)==null||ce.blur())},children:[(0,b.jsx)(re,{className:"w-4 h-4 mr-2"})," ",(0,b.jsxs)("span",{className:"text-sm",children:[u?"Rename to: ":"Save as: ",(0,b.jsx)("span",{className:"font-medium text-sm",children:Qe.basename(E)})]})]},"_rename_"),_.map(ce=>{let ne=lm[ce.isDirectory?"directory":sm(ce.path)];return(0,b.jsxs)(bi,{variant:ce.isDirectory?"default":"muted",className:"py-2 px-3",onSelect:()=>{ce.isDirectory?m(`${ce.path}/`):m(ce.path)},children:[(0,b.jsx)(ne,{className:"w-4 h-4 mr-2"})," ",Qe.basename(ce.path)]},ce.path)})]}),R=Math.max(20,(h==null?void 0:h.length)||(r==null?void 0:r.length)||0)*10,D=k?h||"":u||"",te;t[17]!==d||t[18]!==R?(te=d?{maxWidth:R}:void 0,t[17]=d,t[18]=R,t[19]=te):te=t[19];let Ge;t[20]===s?Ge=t[21]:(Ge=ct(s,"w-full px-4 py-1 my-1 h-9 font-mono text-foreground/60"),t[20]=s,t[21]=Ge);let Pe;t[22]!==r||t[23]!==D||t[24]!==te||t[25]!==Ge?(Pe=(0,b.jsx)(ym,{children:(0,b.jsx)(Tm,{"data-testid":"dir-completion-input",tabIndex:-1,rootClassName:"border-none justify-center px-1",spellCheck:"false",value:D,onKeyDown:cu,icon:null,ref:T,onValueChange:m,placeholder:r,autoComplete:"off",style:te,className:Ge})}),t[22]=r,t[23]=D,t[24]=te,t[25]=Ge,t[26]=Pe):Pe=t[26];let Ve=S&&"group-focus-within:block",Me;t[27]===Ve?Me=t[28]:(Me=ct("p-0 w-full min-w-80 max-w-80vw hidden",Ve),t[27]=Ve,t[28]=Me);let O;t[29]!==S||t[30]!==Me?(O=(0,b.jsx)(wm,{side:"bottom",className:Me,portal:!1,children:S}),t[29]=S,t[30]=Me,t[31]=O):O=t[31];let W;t[32]!==Pe||t[33]!==O?(W=(0,b.jsxs)(yi,{children:[Pe,O]}),t[32]=Pe,t[33]=O,t[34]=W):W=t[34];let V;t[35]!==$||t[36]!==W?(V=(0,b.jsx)(Fm,{onFocus:G,onBlur:$,shouldFilter:!1,id:"filename-input",className:"bg-transparent group filename-input",children:W}),t[35]=$,t[36]=W,t[37]=V):V=t[37];let le;return t[38]!==k||t[39]!==V?(le=(0,b.jsx)(nf,{children:(0,b.jsx)(vm,{open:k,modal:!1,children:V})}),t[38]=k,t[39]=V,t[40]=le):le=t[40],le};function lu(e,t,n){if(e&&!e.endsWith("/")&&((Od("markdown")?new Set(["py","md","markdown","qmd"]):new Set(["py"])).has(Qe.extension(e))||(e=e.endsWith(".")?`${e}py`:e.endsWith(".p")?`${e}y`:`${e}.py`),!t.some(r=>r.path===e||Qe.basename(r.path)===e)&&!(n&&(n===e||Qe.basename(n)===e))))return e}function cu(e){e.key==="Escape"&&e.currentTarget.blur()}var ua=Re(),uu=e=>{let t=(0,ua.c)(33),n=()=>{am(new Blob([r()],{type:"text/plain"}),`${e.proposedName}.json`)},r=ue(mu),o;t[0]!==n||t[1]!==e?(o=U=>{U.preventDefault(),n(),e.closeModal()},t[0]=n,t[1]=e,t[2]=o):o=t[2];let a;t[3]===e?a=t[4]:(a=U=>{U.key==="Escape"&&e.closeModal()},t[3]=e,t[4]=a);let i;t[5]===Symbol.for("react.memo_cache_sentinel")?(i=(0,b.jsx)(mi,{className:"text-accent-foreground mb-6",children:"Download unsaved changes?"}),t[5]=i):i=t[5];let s;t[6]===Symbol.for("react.memo_cache_sentinel")?(s={wordBreak:"break-word"},t[6]=s):s=t[6];let c,u;t[7]===Symbol.for("react.memo_cache_sentinel")?(c=(0,b.jsx)("p",{children:"This app has unsaved changes. To recover:"}),u={paddingBottom:"10px"},t[7]=c,t[8]=u):(c=t[7],u=t[8]);let d;t[9]===e.proposedName?d=t[10]:(d=(0,b.jsxs)("li",{style:u,children:['Click the "Download" button. This will download a file called\xA0',(0,b.jsxs)("code",{children:[e.proposedName,".json"]}),". This file contains your code."]}),t[9]=e.proposedName,t[10]=d);let f;t[11]===Symbol.for("react.memo_cache_sentinel")?(f={paddingBottom:"10px"},t[11]=f):f=t[11];let h;t[12]===Symbol.for("react.memo_cache_sentinel")?(h={display:"block",padding:"10px"},t[12]=h):h=t[12];let m;t[13]===e.proposedName?m=t[14]:(m=(0,b.jsxs)("code",{style:h,children:["marimo recover ",e.proposedName,".json ",">"," ",e.proposedName,".py"]}),t[13]=e.proposedName,t[14]=m);let g;t[15]===e.proposedName?g=t[16]:(g=(0,b.jsxs)("code",{children:[e.proposedName,".py"]}),t[15]=e.proposedName,t[16]=g);let y;t[17]!==g||t[18]!==m?(y=(0,b.jsxs)("li",{style:f,children:["In your terminal, type",m,"to overwrite ",g," with the recovered changes."]}),t[17]=g,t[18]=m,t[19]=y):y=t[19];let w;t[20]!==y||t[21]!==d?(w=(0,b.jsx)(gm,{className:"markdown break-words",style:s,children:(0,b.jsxs)("div",{className:"prose dark:prose-invert",children:[c,(0,b.jsxs)("ol",{children:[d,y]})]})}),t[20]=y,t[21]=d,t[22]=w):w=t[22];let k;t[23]===e.closeModal?k=t[24]:(k=(0,b.jsx)(He,{"aria-label":"Cancel",variant:"secondary","data-testid":"cancel-recovery-button",onClick:e.closeModal,children:"Cancel"}),t[23]=e.closeModal,t[24]=k);let C;t[25]===Symbol.for("react.memo_cache_sentinel")?(C=(0,b.jsx)(He,{"data-testid":"download-recovery-button","aria-label":"Download",variant:"default",type:"submit",children:"Download"}),t[25]=C):C=t[25];let T;t[26]===k?T=t[27]:(T=(0,b.jsxs)(pi,{children:[k,C]}),t[26]=k,t[27]=T);let L;return t[28]!==o||t[29]!==a||t[30]!==w||t[31]!==T?(L=(0,b.jsx)(hi,{className:"w-fit",children:(0,b.jsxs)("form",{onSubmit:o,onKeyDown:a,children:[i,w,T]})}),t[28]=o,t[29]=a,t[30]=w,t[31]=T,t[32]=L):L=t[32],L};const du=e=>{let t=(0,ua.c)(12),{filename:n,needsSave:r}=e,{openModal:o,closeModal:a}=gi(),i;t[0]===n?i=t[1]:(i=n===null?"app":Qe.basename(n).split(".")[0],t[0]=n,t[1]=i);let s=i,c;t[2]!==a||t[3]!==r||t[4]!==o||t[5]!==s?(c=()=>{r&&o((0,b.jsx)(uu,{proposedName:s,closeModal:a}))},t[2]=a,t[3]=r,t[4]=o,t[5]=s,t[6]=c):c=t[6];let u=c;ei("global.save",u);let d;t[7]===Symbol.for("react.memo_cache_sentinel")?(d=wi("global.save"),t[7]=d):d=t[7];let f=r?"yellow":"gray",h;t[8]===Symbol.for("react.memo_cache_sentinel")?(h=(0,b.jsx)(ui,{strokeWidth:1.5,size:18}),t[8]=h):h=t[8];let m;return t[9]!==u||t[10]!==f?(m=(0,b.jsx)(Et,{content:d,children:(0,b.jsx)(Ni,{onClick:u,id:"save-button","aria-label":"Save",className:"rectangle",color:f,children:h})}),t[9]=u,t[10]=f,t[11]=m):m=t[11],m};function fu(e){return{id:e.id,name:e.name,code:e.code,code_hash:null,config:{column:0,...e.config}}}function mu(){let e=xr(Cr()),t={version:"1",metadata:{marimo_version:tf()},cells:e.map(fu)};return JSON.stringify(t,null,2)}var pu=Re(),cr=5e3;function hu(){let e=(0,pu.c)(12),t=oe(Hd),{state:n}=oe(lt),r=t.auto_download.includes("markdown"),o=t.auto_download.includes("html"),a=t.auto_download.includes("ipynb"),i=n===yt.OPEN,s=!r||!i,c=!o||!i,u=!a||!i,{autoExportAsHTML:d,autoExportAsIPYNB:f,autoExportAsMarkdown:h}=Jt(),m;e[0]===h?m=e[1]:(m=async()=>{await h({download:!1})},e[0]=h,e[1]=m);let g;e[2]===s?g=e[3]:(g={delayMs:cr,whenVisible:!0,disabled:s},e[2]=s,e[3]=g),Pr(m,g);let y;e[4]===d?y=e[5]:(y=async()=>{await d({download:!1,includeCode:!0,files:Hf.INSTANCE.filenames()})},e[4]=d,e[5]=y);let w;e[6]===c?w=e[7]:(w={delayMs:cr,whenVisible:!0,disabled:c},e[6]=c,e[7]=w),Pr(y,w);let k;e[8]===f?k=e[9]:(k=async()=>{await f({download:!1})},e[8]=f,e[9]=k);let C;e[10]===u?C=e[11]:(C={delayMs:cr,whenVisible:!0,disabled:u},e[10]=u,e[11]=C),Pr(k,C)}let ur;Dn=Bt(void 0),ur=Bt(e=>{let t=e(Dn);return gu({state:e(nt),layout:e(ai),lastSavedNotebook:t})});function gu({state:e,layout:t,lastSavedNotebook:n}){if(!n)return!1;let{cellIds:r,cellData:o}=e,a=r.inOrderIds.map(u=>o[u]),i=a.map(u=>u.code),s=a.map(u=>u.config),c=a.map(u=>u.name);return!ri(i,n.codes)||!ri(c,n.names)||!Nn(s,n.configs)||!Nn(t.selectedLayout,n.layout.selectedLayout)||!Nn(t.layoutData,n.layout.layoutData)}var bu=Re();function yu(e){let t=(0,bu.c)(21),{codes:n,cellConfigs:r,config:o,connStatus:a,cellNames:i,needsSave:s,kioskMode:c,onSave:u}=e,d=(0,I.useRef)(null),f;t[0]===n?f=t[1]:(f=n.join(":"),t[0]=n,t[1]=f);let h=f,m;t[2]===r?m=t[3]:(m=r.map(wu).join(":"),t[2]=r,t[3]=m);let g=m,y;t[4]===i?y=t[5]:(y=i.join(":"),t[4]=i,t[5]=y);let w=y,k;t[6]!==o||t[7]!==a.state||t[8]!==c||t[9]!==s||t[10]!==u?(k=()=>{if(!c)return o.autosave==="after_delay"&&(d.current!==null&&clearTimeout(d.current),s&&a.state===yt.OPEN&&(d.current=setTimeout(u,o.autosave_delay))),()=>{d.current!==null&&clearTimeout(d.current)}},t[6]=o,t[7]=a.state,t[8]=c,t[9]=s,t[10]=u,t[11]=k):k=t[11];let C;t[12]!==g||t[13]!==w||t[14]!==h||t[15]!==o||t[16]!==a.state||t[17]!==c||t[18]!==s||t[19]!==u?(C=[h,g,w,o,a.state,u,c,s],t[12]=g,t[13]=w,t[14]=h,t[15]=o,t[16]=a.state,t[17]=c,t[18]=s,t[19]=u,t[20]=C):C=t[20],(0,I.useEffect)(k,C)}function wu(e){return JSON.stringify(e)}var yn=Re();Ii=e=>{let t=(0,yn.c)(15),{kioskMode:n}=e,r=Sm(),o=oe(ur),a=oe(lt).state===yt.CLOSED,{saveOrNameNotebook:i,saveIfNotebookIsPersistent:s}=dr(),c;t[0]!==n||t[1]!==s?(c={onSave:s,kioskMode:n},t[0]=n,t[1]=s,t[2]=c):c=t[2],ku(c),hu();let u;t[3]===o?u=t[4]:(u=w=>{if(o)return w.preventDefault(),w.returnValue="You have unsaved changes. Are you sure you want to leave?",w.returnValue},t[3]=o,t[4]=u),rf(window,"beforeunload",u);let d;t[5]===i?d=t[6]:(d=w=>{w.preventDefault(),w.stopPropagation(),i()},t[5]=i,t[6]=d);let f=d;if(ei("global.save",i),a){let w;return t[7]!==r||t[8]!==o?(w=(0,b.jsx)(du,{filename:r,needsSave:o}),t[7]=r,t[8]=o,t[9]=w):w=t[9],w}let h;t[10]===Symbol.for("react.memo_cache_sentinel")?(h=wi("global.save"),t[10]=h):h=t[10];let m=o?"yellow":"hint-green",g;t[11]===Symbol.for("react.memo_cache_sentinel")?(g=(0,b.jsx)(ui,{strokeWidth:1.5,size:18}),t[11]=g):g=t[11];let y;return t[12]!==f||t[13]!==m?(y=(0,b.jsx)(Et,{content:h,children:(0,b.jsx)(Ni,{"data-testid":"save-button",id:"save-button",shape:"rectangle",color:m,onClick:f,children:g})}),t[12]=f,t[13]=m,t[14]=y):y=t[14],y};function dr(){let e=(0,yn.c)(20),{sendSave:t}=Jt(),{openModal:n,closeModal:r,openAlert:o}=gi(),a=_a(Dn),i=xm(),s=wr(),c;e[0]!==o||e[1]!==t||e[2]!==a||e[3]!==s?(c=async(k,C)=>{let T=s.get(lt),L=s.get(Xa);if(s.get(pm))return;if(T.state!==yt.OPEN){o("Failed to save notebook: not connected to a kernel.");return}$e.log("saving to ",k),C&&L.format_on_save&&($e.log("formatting notebook (onSave)"),await Sd());let U=Cr(),A=xr(U),x=A.map(Nu),G=A.map(Eu),ee=A.map(vu),$=Va(U),F=s.get(ai);G.length!==0&&(await t({cellIds:x,codes:G,names:ee,filename:k,configs:$,layout:qf(),persist:!0}),a({names:ee,codes:G,configs:$,layout:F}))},e[0]=o,e[1]=t,e[2]=a,e[3]=s,e[4]=c):c=e[4];let u=ue(c),d;e[5]!==u||e[6]!==s?(d=k=>{let C=k===void 0?!1:k,T=s.get(Ra),L=s.get(lt);da(T)&&L.state===yt.OPEN&&u(T,C)},e[5]=u,e[6]=s,e[7]=d):d=e[7];let f=ue(d),h;e[8]!==u||e[9]!==i?(h=k=>{i(k).then(C=>{C!==null&&u(C,!0)})},e[8]=u,e[9]=i,e[10]=h):h=e[10];let m=h,g;e[11]!==r||e[12]!==m||e[13]!==n||e[14]!==f||e[15]!==s?(g=()=>{let k=s.get(Ra),C=s.get(lt);f(!0),!da(k)&&C.state!==yt.CLOSED&&n((0,b.jsx)(xu,{onClose:r,onSave:m}))},e[11]=r,e[12]=m,e[13]=n,e[14]=f,e[15]=s,e[16]=g):g=e[16];let y=ue(g),w;return e[17]!==f||e[18]!==y?(w={saveOrNameNotebook:y,saveIfNotebookIsPersistent:f},e[17]=f,e[18]=y,e[19]=w):w=e[19],w}function vu(e){return e.name}function Eu(e){return e.code}function Nu(e){return e.id}function da(e){return e!==null&&!e.startsWith("/tmp/")&&!e.startsWith("/var/folders")&&!e.includes("AppData\\Local\\Temp")}function ku(e){let t=(0,yn.c)(14),n=oe(Xa),r=fd(),[o]=En(lt),a=oe(ur),i,s;if(t[0]!==r){let h=xr(r);i=h.map(Su),s=h.map(Cu),t[0]=r,t[1]=i,t[2]=s}else i=t[1],s=t[2];let c=s,u;t[3]===r?u=t[4]:(u=Va(r),t[3]=r,t[4]=u);let d=u,f;t[5]!==n||t[6]!==c||t[7]!==i||t[8]!==d||t[9]!==o||t[10]!==a||t[11]!==e.kioskMode||t[12]!==e.onSave?(f={onSave:e.onSave,needsSave:a,codes:i,cellConfigs:d,cellNames:c,connStatus:o,config:n,kioskMode:e.kioskMode},t[5]=n,t[6]=c,t[7]=i,t[8]=d,t[9]=o,t[10]=a,t[11]=e.kioskMode,t[12]=e.onSave,t[13]=f):f=t[13],yu(f)}function Cu(e){return e.name}function Su(e){return e.code}var xu=e=>{let t=(0,yn.c)(17),{onClose:n,onSave:r}=e,[o,a]=(0,I.useState)(),i;t[0]!==n||t[1]!==r?(i=w=>{a(w),w.trim()&&(r(w),n())},t[0]=n,t[1]=r,t[2]=i):i=t[2];let s=i,c;t[3]===Symbol.for("react.memo_cache_sentinel")?(c=(0,b.jsx)(mi,{children:"Save notebook"}),t[3]=c):c=t[3];let u;t[4]===Symbol.for("react.memo_cache_sentinel")?(u=(0,b.jsx)(_r,{className:"text-md pt-6 px-1",children:"Save as"}),t[4]=u):u=t[4];let d;t[5]===s?d=t[6]:(d=(0,b.jsxs)("div",{className:"flex flex-col",children:[u,(0,b.jsx)(Gr,{onNameChange:s,placeholderText:"filename",className:"missing-filename"})]}),t[5]=s,t[6]=d);let f;t[7]===n?f=t[8]:(f=(0,b.jsx)(He,{"data-testid":"cancel-save-dialog-button","aria-label":"Cancel",variant:"secondary",onClick:n,children:"Cancel"}),t[7]=n,t[8]=f);let h=!o,m;t[9]===h?m=t[10]:(m=(0,b.jsx)(He,{"data-testid":"submit-save-dialog-button","aria-label":"Save",variant:"default",disabled:h,type:"submit",children:"Save"}),t[9]=h,t[10]=m);let g;t[11]!==f||t[12]!==m?(g=(0,b.jsxs)(pi,{children:[f,m]}),t[11]=f,t[12]=m,t[13]=g):g=t[13];let y;return t[14]!==d||t[15]!==g?(y=(0,b.jsxs)(hi,{children:[c,d,g]}),t[14]=d,t[15]=g,t[16]=y):y=t[16],y};_n=function(...e){return t=>{e.forEach(n=>{typeof n=="function"?n(t):n!=null&&(n.current=t)})}};var fa={modified:{doc:""},original:{doc:""}},ma=(0,I.createContext)(fa);function Au(e,t){return Y({},e,t,{modified:Y({},e.modified,t.modified),original:Y({},e.original,t.original)})}var fr=()=>(0,I.useContext)(ma),Tu=e=>{var{children:t,theme:n}=e,[r,o]=(0,I.useReducer)(Au,Y({},fa,{theme:n}));return(0,I.useEffect)(()=>o({theme:n}),[n]),(0,b.jsx)(ma.Provider,{value:Y({},r,{dispatch:o}),children:t})},Iu=["extensions","value","selection","onChange"],pa=e=>{var{extensions:t=[],value:n,selection:r,onChange:o}=e,a=Wt(e,Iu),{theme:i,dispatch:s}=fr(),c=Nt(Y({},a,{theme:i}));return(0,I.useEffect)(()=>s({original:{doc:n,selection:r,extensions:[...c,...t]},originalExtension:{onChange:o,option:a,extension:[t]}}),[e]),null};pa.displayName="CodeMirrorMerge.Original";var Fu=["extensions","value","selection","onChange"],ha=e=>{var{extensions:t=[],value:n,selection:r,onChange:o}=e,a=Wt(e,Fu),{theme:i,dispatch:s}=fr(),c=Nt(Y({},a,{theme:i}));return(0,I.useEffect)(()=>{s({modified:{doc:n,selection:r,extensions:[...c,...t]},modifiedExtension:{onChange:o,option:a,extension:[t]}})},[e]),null};ha.displayName="CodeMirrorMerge.Modified";var Lu=["className","children","orientation","revertControls","highlightChanges","gutter","collapseUnchanged","destroyRerender","renderRevertControl","diffConfig","root"],Ou=["modified","modifiedExtension","original","originalExtension","theme","dispatch"],ga=I.forwardRef((e,t)=>{var{className:n,children:r,orientation:o,revertControls:a,highlightChanges:i,gutter:s,collapseUnchanged:c,destroyRerender:u=!0,renderRevertControl:d,diffConfig:f,root:h}=e,m=Wt(e,Lu),g=fr(),{modified:y,modifiedExtension:w,original:k,originalExtension:C,theme:T,dispatch:L}=g,U=Wt(g,Ou),A=(0,I.useRef)(null),x=(0,I.useRef)(),G={orientation:o,revertControls:a,highlightChanges:i,gutter:s,collapseUnchanged:c,renderRevertControl:d,diffConfig:f,root:h};(0,I.useImperativeHandle)(t,()=>({container:A.current,view:x.current,modified:y,original:k,config:Y({a:k,b:y,parent:A.current},G)}),[A,x,y,k,G]);var ee=B.updateListener.of(F=>{if(F.docChanged&&typeof(C==null?void 0:C.onChange)=="function"){var j=F.state.doc.toString();C==null||C.onChange(j,F)}}),$=B.updateListener.of(F=>{if(F.docChanged&&typeof(w==null?void 0:w.onChange)=="function"){var j=F.state.doc.toString();w==null||w.onChange(j,F)}});return(0,I.useEffect)(()=>{!x.current&&A.current&&C&&w&&(x.current=new Ei(Y({a:Y({},k,{extensions:[...(C==null?void 0:C.extension)||[],...Nt(Y({},C==null?void 0:C.option,{theme:T})),ee]}),b:Y({},y,{extensions:[...(w==null?void 0:w.extension)||[],...Nt(Y({},w==null?void 0:w.option,{theme:T})),$]}),parent:A.current},G)),L({view:x.current}))},[x,A,C,w]),(0,I.useEffect)(()=>{var K,E;if(k&&k.doc&&x.current){var F=(K=x.current)==null?void 0:K.a.state.doc.toString();if(F!==k.doc){var j;(j=x.current)==null||j.a.dispatch({changes:{from:0,to:F.length,insert:k.doc||""}})}}if(y&&y.doc&&x.current){var se=(E=x.current)==null?void 0:E.b.state.doc.toString();if(se!==y.doc){var _;(_=x.current)==null||_.b.dispatch({changes:{from:0,to:se.length,insert:y.doc||""}})}}if(u&&x.current){var P=x.current.a.state.selection.ranges[0].from,me=x.current.b.state.selection.ranges[0].from;x.current.destroy(),x.current=new Ei(Y({a:Y({},k,{extensions:[...(C==null?void 0:C.extension)||[],...Nt(Y({},C==null?void 0:C.option,{theme:T}))]}),b:Y({},y,{extensions:[...(w==null?void 0:w.extension)||[],...Nt(Y({},w==null?void 0:w.option,{theme:T}))]}),parent:A.current},G)),P&&(x.current.a.focus(),x.current.a.dispatch({selection:{anchor:P,head:P}})),me&&(x.current.b.focus(),x.current.b.dispatch({selection:{anchor:me,head:me}}))}},[x,T,A.current,k,y,C,w,u]),(0,I.useEffect)(()=>()=>x.current&&x.current.destroy(),[]),(0,I.useEffect)(()=>{if(x.current){var F={};U.orientation!==o&&(F.orientation=o),U.revertControls!==a&&(F.revertControls=a),U.highlightChanges!==i&&(F.highlightChanges=i),U.gutter!==s&&(F.gutter=s),U.collapseUnchanged!==c&&(F.collapseUnchanged=c),U.renderRevertControl!==d&&(F.collapseUnchanged=c),Object.keys(F).length&&L&&x.current&&(x.current.reconfigure(Y({},F)),L(Y({},F)))}},[L,x,o,a,i,s,c,d]),(0,b.jsx)("div",Y({ref:A,className:"cm-merge-theme"+(n?" "+n:"")},m,{children:r}))});ga.displayName="CodeMirrorMerge.Internal";var Du=["theme"],wn=I.forwardRef((e,t)=>{var{theme:n}=e;return(0,b.jsx)(Tu,{theme:n,children:(0,b.jsx)(ga,Y({},Wt(e,Du),{ref:t}))})});wn.Original=pa,wn.Modified=ha,wn.displayName="CodeMirrorMerge";var mr=wn,_u=Re(),Uu=mr.Original,Bu=mr.Modified,ba=[_d(),B.lineWrapping];const ju=({cellId:e,aiCompletionCell:t,className:n,onChange:r,currentLanguageAdapter:o,currentCode:a,declineChange:i,acceptChange:s,runCell:c,outputArea:u,children:d})=>{let[f,h]=(0,I.useState)(!1),[m,g]=(0,I.useState)({}),[y,w]=En(dm),k=(0,I.useId)(),C=Xd(),{initialPrompt:T,triggerImmediately:L,cellId:U}=t??{},A=U===e,x=oe(Xf).get(e),G;(x==null?void 0:x.type)==="update_cell"&&(G=x.previousCode);let{completion:ee,input:$,stop:F,isLoading:j,setCompletion:se,setInput:_,handleSubmit:P,complete:me}=Yf({api:C.getAiURL("completion").toString(),headers:C.headers(),initialInput:T,streamProtocol:"text",experimental_throttle:100,body:{...Object.keys(m).length>0?m:T?ii({input:T}):{},includeOtherCode:y?Er(a):"",code:a,language:o},onError:ne=>{vt({title:"Completion failed",description:Em(ne)})},onFinish:(ne,tt)=>{se(tt.trimEnd())}}),K=I.useRef(null),E=ee.trimEnd(),S=(0,I.useCallback)(()=>{L&&!j&&T&&me(T)},[L]);(0,I.useEffect)(()=>{var ne;A&&(bd(()=>{let tt=K.current;return tt!=null&&tt.view?(tt.view.focus(),S(),!0):!1},{retries:3,delay:100,initialDelay:100}),wd((ne=K.current)==null?void 0:ne.view))},[A,S]),(0,I.useEffect)(()=>{A&&_(T||"")},[A,T,_]);let{theme:R}=mm(),D=()=>{s(E),se("")},te=()=>{i(),se("")},Ge=A&&L&&(E||j);u??(u="below");let Pe=A&&(!L||f),Ve=(0,b.jsx)("div",{className:ct("w-full bg-(--cm-background) flex justify-center transition-all duration-300 ease-in-out overflow-hidden",Ge?"max-h-20 opacity-100 translate-y-0":"max-h-0 opacity-0 -translate-y-2"),children:(0,b.jsx)(Pu,{status:j?"loading":"generated",onAccept:D,onReject:te,showInputPrompt:f,setShowInputPrompt:h,runCell:c,className:"mt-4 mb-3 w-128"})}),Me=(ne,tt)=>(0,b.jsxs)(mr,{className:"cm",theme:R,children:[(0,b.jsx)(Uu,{onChange:r,value:ne,extensions:ba}),(0,b.jsx)(Bu,{value:tt,editable:!1,readOnly:!0,extensions:ba})]}),O=()=>{if(E&&A)return Me(a,E);if(!E&&G)return Me(G,a)},W=(0,b.jsxs)(He,{"data-testid":"stop-completion-button",variant:"text",size:"xs",className:"mb-0",onClick:F,children:[(0,b.jsx)(ci,{className:"animate-spin mr-1",size:14}),"Stop"]}),V=(0,b.jsx)(Et,{content:"Submit",children:(0,b.jsx)(He,{variant:"text",size:"icon",onClick:P,children:(0,b.jsx)(Kf,{className:"h-3 w-3"})})}),le=(0,b.jsx)(Et,{content:"Add context",children:(0,b.jsx)(He,{variant:"text",size:"icon",onClick:()=>nm(K),children:(0,b.jsx)(Qf,{className:"h-3 w-3"})})}),ce=(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(li,{isLoading:j,onAccept:D,size:"xs",multipleCompletions:!1,acceptShortcut:"Mod-\u21B5",runCell:c,borderless:!0,buttonStyles:"hover:shadow-none",playButtonStyles:"hover:shadow-none"}),(0,b.jsx)(si,{onDecline:te,size:"xs",multipleCompletions:!1,declineShortcut:"Shift-Mod-Delete",borderless:!0,className:"hover:shadow-none"})]});return(0,b.jsxs)("div",{"data-ai-input-open":Pe,className:ct("flex flex-col w-full rounded-[inherit]",n),children:[(0,b.jsx)("div",{className:ct("flex items-center gap-2 px-3 transition-all rounded-[inherit] rounded-b-none duration-300",Pe&&"max-h-[400px] border-b min-h-11 visible",!Pe&&"max-h-0 min-h-0 invisible"),children:A&&(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(um,{className:"text-(--blue-10) shrink-0",size:16}),(0,b.jsx)(Zf,{inputRef:K,className:"h-full my-0 py-2 flex items-center",onClose:()=>{i(),se("")},value:$,onChange:ne=>{_(ne),g(ii({input:ne}))},onSubmit:()=>{var ne;j||((ne=K.current)!=null&&ne.view&&tm(K.current.view),P())},onKeyDown:em({handleAcceptCompletion:D,handleDeclineCompletion:te,isLoading:j,hasCompletion:E.trim().length>0})}),(0,b.jsxs)("div",{className:"-mr-1.5 py-1.5",children:[(0,b.jsxs)("div",{className:"flex flex-row items-center justify-end gap-0.5",children:[j&&W,V,le,(0,b.jsx)(rm,{triggerClassName:"h-7 text-xs",iconSize:"small",forRole:"edit",displayIconOnly:!0})]}),E&&(0,b.jsx)("div",{className:"mt-1 flex items-center gap-1",children:ce})]}),(0,b.jsx)("div",{className:"h-full w-px bg-border mx-2"}),(0,b.jsx)(Et,{content:"Include code from other cells",children:(0,b.jsxs)("div",{className:"flex flex-row items-start gap-1 overflow-hidden",children:[(0,b.jsx)(kd,{"data-testid":"include-other-cells-checkbox",id:k,checked:y,onCheckedChange:ne=>w(!!ne)}),(0,b.jsx)(_r,{htmlFor:k,className:"text-muted-foreground text-xs whitespace-nowrap ellipsis",children:"All code"})]})}),(0,b.jsx)(He,{"data-testid":"decline-completion-button",variant:"text",size:"icon",disabled:j,onClick:()=>{F(),i(),se("")},children:(0,b.jsx)(om,{className:"text-(--red-10)",size:16})})]})}),u==="above"&&Ve,O(),(!E||!A)&&!G&&d,u==="below"&&Ve]})};var Pu=e=>{let t=(0,_u.c)(27),{status:n,onAccept:r,onReject:o,className:a,showInputPrompt:i,setShowInputPrompt:s,runCell:c}=e,u=n==="loading",d;t[0]===a?d=t[1]:(d=ct("flex flex-row items-center gap-6 rounded-md py-2 px-2.5 text-sm border border-border","shadow-[0_0_6px_1px_rgba(34,197,94,0.15)]",a),t[0]=a,t[1]=d);let f;t[2]===u?f=t[3]:(f=u?(0,b.jsx)(ci,{className:"animate-spin text-blue-600 mb-px",size:15,strokeWidth:2,"aria-label":"Generating fix"}):(0,b.jsx)(im,{className:"text-green-600 mb-px",size:15,strokeWidth:2,"aria-label":"Fix generated"}),t[2]=u,t[3]=f);let h=u?"Generating fix...":"Showing fix",m;t[4]===h?m=t[5]:(m=(0,b.jsx)("p",{className:"transition-opacity duration-200 text-muted-foreground",children:h}),t[4]=h,t[5]=m);let g;t[6]!==f||t[7]!==m?(g=(0,b.jsxs)("div",{className:"flex flex-row items-center gap-2",children:[f,m]}),t[6]=f,t[7]=m,t[8]=g):g=t[8];let y;t[9]===Symbol.for("react.memo_cache_sentinel")?(y=(0,b.jsx)(_r,{htmlFor:"show-input-prompt",className:"text-muted-foreground text-xs whitespace-nowrap ellipsis",children:"Show prompt"}),t[9]=y):y=t[9];let w;t[10]!==s||t[11]!==i?(w=(0,b.jsxs)("div",{className:"flex flex-row items-center gap-1",children:[y,(0,b.jsx)(ef,{checked:i,onCheckedChange:s,size:"xs"})]}),t[10]=s,t[11]=i,t[12]=w):w=t[12];let k;t[13]!==u||t[14]!==r||t[15]!==c?(k=(0,b.jsx)(li,{isLoading:u,onAccept:r,size:"xs",borderless:!0,runCell:c}),t[13]=u,t[14]=r,t[15]=c,t[16]=k):k=t[16];let C;t[17]===o?C=t[18]:(C=(0,b.jsx)(si,{onDecline:o,size:"xs",borderless:!0}),t[17]=o,t[18]=C);let T;t[19]!==k||t[20]!==C?(T=(0,b.jsxs)("div",{className:"flex flex-row items-center gap-2 ml-auto",children:[k,C]}),t[19]=k,t[20]=C,t[21]=T):T=t[21];let L;return t[22]!==d||t[23]!==T||t[24]!==g||t[25]!==w?(L=(0,b.jsxs)("div",{className:d,children:[g,w,T]}),t[22]=d,t[23]=T,t[24]=g,t[25]=w,t[26]=L):L=t[26],L},pr="web application/x-marimo-cell",Mu=qa({cells:Md(qa({code:jd()})),version:Pd("1.0")});function Ru(){let e=kn();return{copyCells:ue(async t=>{let n=Cr(),r=t.map(o=>n.cellData[o]).filter(Boolean);if(r.length!==0)try{let o={cells:r.map(s=>({code:s.code})),version:"1.0"},a=r.map(s=>s.code).join(`
20
20
 
21
- `),i=new zu().add(pr,o).add("text/plain",a).build();await navigator.clipboard.write([i]),wa(r.length)}catch(o){$e.error("Failed to copy cells to clipboard",o);try{await xm(r.map(a=>a.code).join(`
21
+ `),i=new Vu().add(pr,o).add("text/plain",a).build();await navigator.clipboard.write([i]),ya(r.length)}catch(o){$e.error("Failed to copy cells to clipboard",o);try{await Nm(r.map(a=>a.code).join(`
22
22
 
23
- `)),wa(r.length)}catch{$u()}}}),pasteAtCell:ue(async(t,n)=>{let{before:r=!1}=n??{};try{let o=await navigator.clipboard.read();for(let i of o)if(i.types.includes(pr)){let s=await(await i.getType(pr)).text();try{let c=Wu.parse(JSON.parse(s));if(c.cells.length===0)break;let u=t,d=c.cells.reverse();for(let f of d)e.createNewCell({cellId:u,before:r,code:f.code,autoFocus:!0});return}catch(c){$e.warn("Failed to parse clipboard cell data",c)}}let a=await navigator.clipboard.readText();a.trim()?e.createNewCell({cellId:t,before:r,code:a,autoFocus:!0}):Hu()}catch(o){$e.error("Failed to paste from clipboard",o),qu()}})}}var wa=e=>{let t=e===1?"Cell":`${e} cells`;Et({title:`${t} copied`,description:`${t} ${e===1?"has":"have"} been copied to clipboard.`})},$u=()=>{Et({title:"Copy failed",description:"Failed to copy cells to clipboard.",variant:"danger"})},Hu=()=>{Et({title:"Nothing to paste",description:"No cell or text found in clipboard.",variant:"danger"})},qu=()=>{Et({title:"Paste failed",description:"Failed to read from clipboard",variant:"danger"})},zu=class{constructor(){p(this,"items",{})}add(e,t){return ClipboardItem.supports(e)?typeof t=="string"?(this.items[e]=new Blob([t],{type:e}),this):(this.items[e]=new Blob([JSON.stringify(t)],{type:e}),this):($e.warn(`ClipboardItem does not support ${e}`),this)}build(){return new ClipboardItem(this.items)}},Ku=Re();function va(){return{selectionStart:null,selectionEnd:null,selected:new Set}}var{reducer:qm,createActions:zm,valueAtom:hr,useActions:Yu}=Or(va,{select:(e,t)=>({selectionStart:t.cellId,selectionEnd:t.cellId,selected:new Set([t.cellId])}),extend:(e,t)=>{if(!e.selectionStart)return{selectionStart:t.cellId,selectionEnd:t.cellId,selected:new Set([t.cellId])};let{cellId:n,allCellIds:r}=t;try{let o=r.findWithId(e.selectionStart),a=o.indexOfOrThrow(e.selectionStart),i=o.indexOfOrThrow(n),[s,c]=a<i?[a,i]:[i,a],u=o.slice(s,c+1);return{selectionStart:e.selectionStart,selectionEnd:n,selected:new Set(u)}}catch{return{selectionStart:n,selectionEnd:n,selected:new Set([n])}}},clear:e=>e.selected.size===0?e:va()});Bi=()=>oe(hr);function Xu(e){let t=(0,Ku.c)(2),n;return t[0]===e?n=t[1]:(n=jt(r=>r(hr).selected.has(e)),t[0]=e,t[1]=n),oe(n)}Mr=function(){return Yu()};function Qu(e){return e.get(hr).selected}let Ea,Na,ka;Ea=Re(),{valueAtom:Na,useActions:Vt}=Or(()=>new Set,{add:(e,t)=>{if(e.has(t))return e;let n=new Set(e);return n.add(t),n},remove:(e,t)=>{if(!e.has(t))return e;let n=new Set(e);return n.delete(t),Ma(()=>{let r=document.activeElement;if(!r)return;let o=Sn.findElementThroughShadowDOMs(r);o&&Ra(Sn.parse(o.id))}),n}}),ka=e=>jt(t=>t(Na).has(e)),Pi=function(e){let t=(0,Ea.c)(2),n;return t[0]===e?n=t[1]:(n=ka(e),t[0]=e,t[1]=n),oe(n)};var Bt=new WeakMap,Zu=500;function ed(e){if(e.ctrlKey||e.metaKey||e.altKey)return"";let t=e.key.toLowerCase();return e.shiftKey?`shift+${t}`:t}function td(e,t){let n=ed(e),r=e.target;if(!n||!r)return!1;let o=Bt.get(r),a=n;o!=null&&o.timeout&&clearTimeout(o.timeout),o&&(a=`${o.sequence} ${n}`);let i=t[a];if(i)return Bt.delete(r),i();if(!o){let s=t[n];if(s)return s()}if(Object.keys(t).some(s=>s.startsWith(`${a} `))){let s=window.setTimeout(()=>{Bt.delete(r)},Zu);return Bt.set(r,{sequence:a,timeout:s}),!0}return Bt.delete(r),!1}var gr=Re();function Ca(e){return{handle:t=>e(t),bulkHandle:t=>{let n=!0;try{for(let r of t)n&&(n=e(r));return n}catch{return!1}}}}function Xe(e){return{handle:t=>e([t]),bulkHandle:t=>e(t)}}function nd(e,t){let n=(0,gr.c)(12),r=Bm(),o=kn(),a=Vt(),i;n[0]!==e||n[1]!==r?(i=()=>{r.focusCell({cellId:e})},n[0]=e,n[1]=r,n[2]=i):i=n[2];let s;n[3]!==o||n[4]!==e||n[5]!==t||n[6]!==r||n[7]!==a?(s=()=>{a.remove(e),o.markTouched({cellId:e}),r.blurCell(),t.current&&br(t.current)},n[3]=o,n[4]=e,n[5]=t,n[6]=r,n[7]=a,n[8]=s):s=n[8];let c;n[9]!==i||n[10]!==s?(c={onFocusWithin:i,onBlurWithin:s},n[9]=i,n[10]=s,n[11]=c):c=n[11];let{focusWithinProps:u}=mm(c);return u}Fi=function(e,t){let n=(0,gr.c)(30),{canMoveX:r,editorView:o,cellActionDropdownRef:a}=t,{saveOrNameNotebook:i}=dr(),{saveCellConfig:s}=Jt(),c=Ba(pi),u=kn(),d=wr(),f=Vt(),h=Am(),m=oe(Qa),{copyCells:g,pasteAtCell:y}=Vu(),w=Mr(),k=Xu(e),C=_n(),T=Ur(),L=oe(Tr),U;n[0]!==C||n[1]!==w?(U={clear:()=>{C.clear(),w.clear()},extend:_=>{C.clear(),w.extend(_)},select:_=>{C.clear(),w.select(_)}},n[0]=C,n[1]=w,n[2]=U):U=n[2];let A=U,x=oe(Xa),G;n[3]===x?G=n[4]:(G=(_,P)=>Ar(x.getHotkey(_).key)(P.nativeEvent||P),n[3]=x,n[4]=G);let ee=G,$=nd(e,o),F;n[5]!==u||n[6]!==r||n[7]!==a||n[8]!==e||n[9]!==g||n[10]!==T||n[11]!==o||n[12]!==k||n[13]!==ee||n[14]!==m||n[15]!==y||n[16]!==C||n[17]!==h||n[18]!==s||n[19]!==i||n[20]!==A||n[21]!==c||n[22]!==d||n[23]!==f||n[24]!==L?(F={onKeyDown:_=>{if(Ir.fromInput(_)){_.continuePropagation();return}let P={"Mod+ArrowUp":()=>(u.focusTopCell(),A.clear(),!0),"Mod+ArrowDown":()=>(u.focusBottomCell(),A.clear(),!0),ArrowUp:()=>(u.focusCell({cellId:e,where:"before"}),A.clear(),!0),ArrowDown:()=>(u.focusCell({cellId:e,where:"after"}),A.clear(),!0),ArrowLeft:()=>{if(r){let E=d.get(nt),S=E.cellIds.findWithId(e),R=E.cellIds.indexOf(S),D=E.cellIds.at(R-1);if(D&&D.length>0){let te=Sa(e,D);return u.focusCell({cellId:te,where:"exact"}),A.clear(),!0}}return!1},ArrowRight:()=>{if(r){let E=d.get(nt),S=E.cellIds.findWithId(e),R=E.cellIds.indexOf(S),D=E.cellIds.at(R+1);if(D&&D.length>0){let te=Sa(e,D);return u.focusCell({cellId:te,where:"exact"}),A.clear(),!0}}return!1},"Shift+ArrowUp":()=>{let E=d.get(Wa);A.extend({cellId:e,allCellIds:E});let S=E.findWithId(e).before(e);return S&&A.extend({cellId:S,allCellIds:E}),u.focusCell({cellId:e,where:"before"}),!0},"Shift+ArrowDown":()=>{let E=d.get(Wa);A.extend({cellId:e,allCellIds:E});let S=E.findWithId(e).after(e);return S&&A.extend({cellId:S,allCellIds:E}),u.focusCell({cellId:e,where:"after"}),!0},Escape:()=>k?(A.clear(),!0):!1,Enter:()=>(f.add(e),ja(d,e),A.clear(),!0),s:()=>(i(),!0)};for(let[E,S]of Object.entries(P))if(Ar(E)(_)&&S()){_.preventDefault();return}let me={"cell.run":Xe(E=>(h(E),!0)),"cell.runAndNewBelow":Xe(E=>{h(E);let S=E[E.length-1];return u.moveToNextCell({cellId:S,before:!1}),!0}),"cell.runAndNewAbove":Xe(E=>{h(E);let S=E[0];return u.moveToNextCell({cellId:S,before:!0}),!0}),"cell.createAbove":E=>(u.createNewCell({cellId:E,before:!0}),!0),"cell.createBelow":E=>(u.createNewCell({cellId:E,before:!1}),!0),"cell.moveUp":Xe(E=>{let S=E[0];return d.get(nt).cellIds.findWithId(S).first()===S?!1:(E.forEach(R=>{u.moveCell({cellId:R,before:!0})}),!0)}),"cell.moveDown":Xe(E=>{let S=E[E.length-1];return d.get(nt).cellIds.findWithId(S).last()===S?!1:([...E].reverse().forEach(R=>{u.moveCell({cellId:R,before:!1})}),!0)}),"cell.moveLeft":Ca(E=>r?(u.moveCell({cellId:E,direction:"left"}),!0):!1),"cell.moveRight":Ca(E=>r?(u.moveCell({cellId:E,direction:"right"}),!0):!1),"cell.hideCode":Xe(E=>{var R;let S=!E.map(D=>{var te;return((te=d.get(nt).cellData[D])==null?void 0:te.config)||null}).every(rd);s({configs:Object.fromEntries(E.map(D=>[D,{hide_code:S}]))});for(let D of E)u.updateCellConfig({cellId:D,config:{hide_code:S}});if(E.length===1){let D=E[0];u.focusCell({cellId:D,where:"after"}),S?((R=o.current)==null||R.contentDOM.blur(),za(D)):ja(d,D)}return!0}),"cell.focusDown":E=>(u.focusCell({cellId:E,where:"after"}),!0),"cell.focusUp":E=>(u.focusCell({cellId:E,where:"before"}),!0),"cell.sendToBottom":Xe(E=>(E.forEach(S=>{u.sendToBottom({cellId:S})}),!0)),"cell.sendToTop":Xe(E=>([...E].reverse().forEach(S=>{u.sendToTop({cellId:S})}),!0)),"cell.aiCompletion":E=>{var R;let S=!1;return c(D=>(D==null?void 0:D.cellId)===E?(S=!0,null):{cellId:E}),S&&((R=o.current)==null||R.focus()),!0},"cell.cellActions":()=>{var E;return(E=a.current)==null||E.toggle(),!0},"command.copyCell":Xe(E=>(g(E),!0)),"command.pasteCell":E=>(y(E),!0),"command.createCellBefore":E=>Ir.hasModifier(_)?!1:(u.createNewCell({cellId:E,before:!0,autoFocus:!0}),!0),"command.createCellAfter":E=>Ir.hasModifier(_)?!1:(u.createNewCell({cellId:E,before:!1,autoFocus:!0}),!0),"cell.delete":()=>{if(!L.keymap.destructive_delete)return!1;let E=K.size>=2?[...K]:[e],S=d.get(nt);return E.some(R=>{let{status:D}=S.cellRuntime[R];return D==="running"||D==="queued"})?!1:C.idle?(C.submit(E),!0):(T({cellIds:E}),C.clear(),!0)}},K=Qu(d);if(m==="vim"&&td(_.nativeEvent||_,{j:P.ArrowDown,k:P.ArrowUp,h:P.ArrowLeft,l:P.ArrowRight,i:P.Enter,"shift+j":P["Shift+ArrowDown"],"shift+k":P["Shift+ArrowUp"],"g g":P["Mod+ArrowUp"],"shift+g":P["Mod+ArrowDown"],"d d":()=>me["cell.delete"](),"y y":()=>(g(K.size>=2?[...K]:[e]),!0),p:()=>(y(e,{before:!1}),!0),"shift+p":()=>(y(e,{before:!0}),!0),o:()=>(u.createNewCell({cellId:e,before:!1,autoFocus:!0}),!0),"shift+o":()=>(u.createNewCell({cellId:e,before:!0,autoFocus:!0}),!0),u:()=>(u.undoDeleteCell(),!0)})){_.preventDefault();return}for(let[E,S]of Object.entries(me))if(ee(E,_)){if(S instanceof Function){if(S(e)){_.preventDefault();return}}else if(K.size>=2?S.bulkHandle([...K]):S.handle(e)){_.preventDefault();return}return}_.continuePropagation()}},n[5]=u,n[6]=r,n[7]=a,n[8]=e,n[9]=g,n[10]=T,n[11]=o,n[12]=k,n[13]=ee,n[14]=m,n[15]=y,n[16]=C,n[17]=h,n[18]=s,n[19]=i,n[20]=A,n[21]=c,n[22]=d,n[23]=f,n[24]=L,n[25]=F):F=n[25];let{keyboardProps:j}=mi(F),se;return n[26]!==$||n[27]!==k||n[28]!==j?(se=Em($,j,{"data-selected":k,className:"data-[selected=true]:ring-1 data-[selected=true]:ring-(--blue-8) data-[selected=true]:ring-offset-1"}),n[26]=$,n[27]=k,n[28]=j,n[29]=se):se=n[29],se};function rd(e){return e==null?void 0:e.hide_code}function od(e,t){let n=(0,gr.c)(12),r=Vt(),o=oe(Qa),a=oe(Xa),i;n[0]===a?i=n[1]:(i=Ar(a.getHotkey("command.vimEnterCommandMode").key),n[0]=a,n[1]=i);let s=i,c;n[2]!==e||n[3]!==r?(c=()=>{r.remove(e),za(e),Ma(()=>{Ra(e)})},n[2]=e,n[3]=r,n[4]=c):c=n[4];let u=c,d;n[5]!==t||n[6]!==u?(d=()=>{if(!t.current){u();return}let g=t.current,y=g.state;if(Lf(g))return;let w=y.field(Pa,!1),k=Gt(y)!==null;w&&br(g),k&&Hf(g),!(w||k)&&u()},n[5]=t,n[6]=u,n[7]=d):d=n[7];let f=d,h;n[8]!==f||n[9]!==o||n[10]!==s?(h={onKeyDown:g=>{o==="vim"?s(g)&&f():g.key==="Escape"&&f(),g.continuePropagation()}},n[8]=f,n[9]=o,n[10]=s,n[11]=h):h=n[11];let{keyboardProps:m}=mi(h);return m}function Sa(e,t){let n=document.getElementById(Sn.create(e));if(!n)return t.first();let r=n.getBoundingClientRect();for(let o of t.topLevelIds){let a=document.getElementById(Sn.create(o));if(a){let i=a.getBoundingClientRect();if(r.top<=i.bottom&&r.bottom>=i.top)return o}}return t.last()}function br(e){e.state.field(Pa,!1)&&e.dispatch({effects:Nd.of(null)})}var xa=Re();const ad=e=>{let t=(0,xa.c)(24),{editorView:n,code:r,currentLanguageAdapter:o,onAfterToggle:a}=e,i;t[0]===r?i=t[1]:(i=qa.markdown.isSupported(r)||r.trim()==="",t[0]=r,t[1]=i);let s=i,c;t[2]===r?c=t[3]:(c=qa.sql.isSupported(r)||r.trim()==="",t[2]=r,t[3]=c);let u=c&&o==="python",d;t[4]===Symbol.for("react.memo_cache_sentinel")?(d=(0,b.jsx)(fd,{color:"var(--sky-11)",strokeWidth:2.5,className:"w-4 h-4"}),t[4]=d):d=t[4];let f;t[5]!==o||t[6]!==n||t[7]!==a||t[8]!==u?(f=(0,b.jsx)(yr,{editorView:n,currentLanguageAdapter:o,canSwitchToLanguage:u,icon:d,toType:"sql",displayName:"SQL",onAfterToggle:a}),t[5]=o,t[6]=n,t[7]=a,t[8]=u,t[9]=f):f=t[9];let h=s&&o==="python",m;t[10]===Symbol.for("react.memo_cache_sentinel")?(m=(0,b.jsx)(Pm,{fill:"var(--sky-11)",color:"black",className:"w-4 h-4"}),t[10]=m):m=t[10];let g;t[11]!==o||t[12]!==n||t[13]!==a||t[14]!==h?(g=(0,b.jsx)(yr,{editorView:n,currentLanguageAdapter:o,canSwitchToLanguage:h,icon:m,toType:"markdown",displayName:"Markdown",onAfterToggle:a}),t[11]=o,t[12]=n,t[13]=a,t[14]=h,t[15]=g):g=t[15];let y;t[16]===Symbol.for("react.memo_cache_sentinel")?(y=(0,b.jsx)(jm,{fill:"var(--sky-11)",color:"black",className:"w-4 h-4"}),t[16]=y):y=t[16];let w;t[17]!==o||t[18]!==n?(w=(0,b.jsx)(yr,{editorView:n,currentLanguageAdapter:o,canSwitchToLanguage:!0,icon:y,toType:"python",displayName:"Python",onAfterToggle:Kd.NOOP}),t[17]=o,t[18]=n,t[19]=w):w=t[19];let k;return t[20]!==w||t[21]!==f||t[22]!==g?(k=(0,b.jsxs)("div",{className:"absolute right-3 top-2 z-20 flex hover-action gap-1",children:[f,g,w]}),t[20]=w,t[21]=f,t[22]=g,t[23]=k):k=t[23],k},yr=e=>{let t=(0,xa.c)(10),{editorView:n,currentLanguageAdapter:r,canSwitchToLanguage:o,icon:a,toType:i,displayName:s,onAfterToggle:c}=e,u;t[0]!==n||t[1]!==c||t[2]!==i?(u=()=>{n&&(Pt(n,{language:i}),c())},t[0]=n,t[1]=c,t[2]=i,t[3]=u):u=t[3];let d=u;if(!o||r===i)return null;let f=`View as ${s}`,h;t[4]!==d||t[5]!==a?(h=(0,b.jsx)(He,{"data-testid":"language-toggle-button",variant:"text",size:"xs",className:"opacity-80 px-1",onClick:d,children:a}),t[4]=d,t[5]=a,t[6]=h):h=t[6];let m;return t[7]!==f||t[8]!==h?(m=(0,b.jsx)(Nt,{content:f,children:h}),t[7]=f,t[8]=h,t[9]=m):m=t[9],m};var Aa=Re(),Ta=({theme:e,showPlaceholder:t,id:n,config:r,code:o,status:a,serializedEditorState:i,setEditorView:s,runCell:c,userConfig:u,editorViewRef:d,editorViewParentRef:f,hidden:h,hasOutput:m,showHiddenCode:g,languageAdapter:y,setLanguageAdapter:w,showLanguageToggles:k=!0,outputArea:C})=>{var Me;let[T,L]=En(pi),U=Ni(),{saveOrNameNotebook:A}=dr(),x=_n(),{saveCellConfig:G}=Jt(),ee=a==="running"||a==="queued",$=kn(),F=Mm(),j=y==="markdown",se=ue(()=>ee?!1:x.idle&&u.keymap.destructive_delete?(x.submit([n]),!0):(U({cellId:n}),!0)),_=ue(()=>ee?!1:(c(),d.current&&br(d.current),!0)),P=ue(()=>{let O=!r.hide_code;return G({configs:{[n]:{hide_code:O}}}),$.updateCellConfig({cellId:n,config:{hide_code:O}}),O}),me=oe(Xd),K=ue(()=>{Um({autoInstantiate:me,createNewCell:$.createNewCell})}),E=Qd(u),S=(0,I.useMemo)(()=>{var W;let O=Rc({cellId:n,showPlaceholder:t,enableAI:E,cellActions:{...$,afterToggleMarkdown:K,onRun:_,deleteCell:se,saveNotebook:A,createManyBelow:V=>{for(let le of[...V].reverse())$.createNewCell({code:le,before:!1,cellId:n,skipIfCodeExists:!0})},splitCell:F,toggleHideCode:P,aiCellCompletion:()=>{let V=!1;return L(le=>(le==null?void 0:le.cellId)===n?(V=!0,null):{cellId:n}),V}},completionConfig:u.completion,keymapConfig:u.keymap,lspConfig:u.language_servers,theme:e,hotkeys:new Ya(u.keymap.overrides??{}),diagnosticsConfig:u.diagnostics,displayConfig:u.display,inlineAiTooltip:((W=u.ai)==null?void 0:W.inline_tooltip)??!1});return O.push(ze.define(V=>(w(V.state.field(xn).type),{update(le){w(le.state.field(xn).type)}})),B.updateListener.of(V=>{V.selectionSet&&V.state.selection.ranges.some(le=>le.from!==le.to)&&g({focus:!1})}),B.domEventHandlers({focus:()=>{g({focus:!1})}})),O},[n,u.keymap,u.completion,u.language_servers,u.display,u.diagnostics,E,e,t,$,F,P,se,_,L,K,w,g,A]),R=Nr(),D=ue(()=>{if(R){let W=lr(n,V=>{$.updateCellCode({cellId:n,code:V,formattingChange:!0})},o);S.push(W.extension),o=W.code}let O=new B({state:Fr.create({doc:o,extensions:S})});s(O),R||Pt(O,{language:kr(O.state).type})}),te=ue(()=>{if(yt(d.current!==null,"Editor view is not initialized"),R){let O=lr(n,W=>{$.updateCellCode({cellId:n,code:W,formattingChange:!0})});S.push(O.extension)}d.current.dispatch({effects:[pe.reconfigure.of([S]),Ld(d.current,{completionConfig:u.completion,hotkeysProvider:new Ya(u.keymap.overrides??{}),lspConfig:{...u.language_servers,diagnostics:u.diagnostics}})]})}),Ge=ue(()=>{if(yt(i,"Editor view is not initialized"),R){let W=lr(n,V=>{$.updateCellCode({cellId:n,code:V,formattingChange:!0})},o);S.push(W.extension),o=W.code}let O=new B({state:Fr.fromJSON(i,{doc:o,extensions:S},{history:Bf})});R||Pt(O,{language:kr(O.state).type}),s(O),$.clearSerializedEditorState({cellId:n})});(0,I.useEffect)(()=>{i===null?d.current===null?D():te():Ge(),d.current!==null&&f&&f.current!==null&&f.current.replaceChildren(d.current.dom)},[D,te,Ge,d,f,i,S]),(0,I.useEffect)(()=>{let O=d.current;return()=>{O==null||O.destroy()}},[d]);let Pe=od(n,d),Ve="";return j&&h&&m?Ve="h-0 overflow-hidden":h&&(Ve="opacity-20 h-8 [&>div.cm-editor]:h-full [&>div.cm-editor]:overflow-hidden [&_.cm-panels]:hidden"),(0,b.jsx)(Gu,{cellId:n,aiCompletionCell:T,currentCode:((Me=d.current)==null?void 0:Me.state.doc.toString())??o,currentLanguageAdapter:y,declineChange:ue(()=>{var O;L(null),(O=d.current)==null||O.focus()}),onChange:ue(O=>{var W;(W=d.current)==null||W.dispatch({changes:{from:0,to:d.current.state.doc.length,insert:O}})}),acceptChange:ue(O=>{var W,V;(W=d.current)==null||W.dispatch({changes:{from:0,to:d.current.state.doc.length,insert:O}}),(V=d.current)==null||V.focus(),L(null)}),runCell:_,outputArea:C,children:(0,b.jsxs)("div",{className:"relative w-full",...Pe,children:[(0,b.jsx)(Ia,{className:Ve,editorView:d.current,ref:f,hidden:h,showHiddenCode:g}),!h&&k&&(0,b.jsx)("div",{className:"absolute top-1 right-5",children:(0,b.jsx)(ad,{code:o,editorView:d.current,currentLanguageAdapter:y,onAfterToggle:K})})]})})},Ia=I.forwardRef((e,t)=>{let n=(0,Aa.c)(14),{className:r,editorView:o,hidden:a,showHiddenCode:i}=e,s=(0,I.useRef)(null),c,u;n[0]===o?(c=n[1],u=n[2]):(c=()=>{o!==null&&s.current!==null&&s.current.children.length===0&&s.current.append(o.dom)},u=[o,s],n[0]=o,n[1]=c,n[2]=u),(0,I.useEffect)(c,u);let d;n[3]===r?d=n[4]:(d=ct("cm mathjax_ignore",r),n[3]=r,n[4]=d);let f;n[5]!==a||n[6]!==i?(f=g=>{a&&i&&(g.stopPropagation(),i({focus:!0}))},n[5]=a,n[6]=i,n[7]=f):f=n[7];let h;n[8]===t?h=n[9]:(h=g=>{t?Dn(t,s)(g):Dn(s)(g)},n[8]=t,n[9]=h);let m;return n[10]!==d||n[11]!==f||n[12]!==h?(m=(0,b.jsx)("div",{className:d,onDoubleClick:f,ref:h,"data-testid":"cell-editor"}),n[10]=d,n[11]=f,n[12]=h,n[13]=m):m=n[13],m});Ia.displayName="CellCodeMirrorEditor";function id(e){let t=n=>{let r=(0,Aa.c)(5),o=oe(lt),[a,i]=En(dt);if(ef(o.state)||a===void 0){let c;r[0]===Symbol.for("react.memo_cache_sentinel")?(c=(0,b.jsx)("span",{children:"Waiting for real-time collaboration connection..."}),r[0]=c):c=r[0];let u;return r[1]===i?u=r[2]:(u=(0,b.jsx)("div",{className:"flex h-full w-full items-baseline p-4",children:(0,b.jsxs)(Mf,{milliseconds:1e3,fallback:null,children:[c,(0,b.jsx)(He,{variant:"link",onClick:()=>{i("disabled")},children:"Turn off real-time collaboration"})]})}),r[1]=i,r[2]=u),u}let s;return r[3]===n?s=r[4]:(s=(0,b.jsx)(e,{...n}),r[3]=n,r[4]=s),s};return t.displayName=`WithWaitUntilConnected(${e.displayName})`,t}Ui=Nr()?id((0,I.memo)(Ta)):(0,I.memo)(Ta);var Fa=(0,I.createContext)(null);Mi=Fa.Provider,Gr=function(){let e=(0,I.useContext)(Fa);return yt(e!==null,"usePanelSection must be used within a PanelSectionProvider"),e},ji=function(){return Gr()==="sidebar"?"vertical":"horizontal"}});export{be as _,Hm as __tla,Fi as a,Li as b,Mr as c,Oi as d,On as f,Di as g,_i as h,Ui as i,Bi as l,dt as m,ji as n,Pi as o,Rr as p,Gr as r,Vt as s,Mi as t,Dn as u,Jr as v,_n as x,Un as y};
23
+ `)),ya(r.length)}catch{Gu()}}}),pasteAtCell:ue(async(t,n)=>{let{before:r=!1}=n??{};try{let o=await navigator.clipboard.read();for(let i of o)if(i.types.includes(pr)){let s=await(await i.getType(pr)).text();try{let c=Mu.parse(JSON.parse(s));if(c.cells.length===0)break;let u=t,d=c.cells.reverse();for(let f of d)e.createNewCell({cellId:u,before:r,code:f.code,autoFocus:!0});return}catch(c){$e.warn("Failed to parse clipboard cell data",c)}}let a=await navigator.clipboard.readText();a.trim()?e.createNewCell({cellId:t,before:r,code:a,autoFocus:!0}):Ju()}catch(o){$e.error("Failed to paste from clipboard",o),Wu()}})}}var ya=e=>{let t=e===1?"Cell":`${e} cells`;vt({title:`${t} copied`,description:`${t} ${e===1?"has":"have"} been copied to clipboard.`})},Gu=()=>{vt({title:"Copy failed",description:"Failed to copy cells to clipboard.",variant:"danger"})},Ju=()=>{vt({title:"Nothing to paste",description:"No cell or text found in clipboard.",variant:"danger"})},Wu=()=>{vt({title:"Paste failed",description:"Failed to read from clipboard",variant:"danger"})},Vu=class{constructor(){p(this,"items",{})}add(e,t){return ClipboardItem.supports(e)?typeof t=="string"?(this.items[e]=new Blob([t],{type:e}),this):(this.items[e]=new Blob([JSON.stringify(t)],{type:e}),this):($e.warn(`ClipboardItem does not support ${e}`),this)}build(){return new ClipboardItem(this.items)}},$u=Re();function wa(){return{selectionStart:null,selectionEnd:null,selected:new Set}}var{reducer:Wm,createActions:Vm,valueAtom:hr,useActions:Hu}=Or(wa,{select:(e,t)=>({selectionStart:t.cellId,selectionEnd:t.cellId,selected:new Set([t.cellId])}),extend:(e,t)=>{if(!e.selectionStart)return{selectionStart:t.cellId,selectionEnd:t.cellId,selected:new Set([t.cellId])};let{cellId:n,allCellIds:r}=t;try{let o=r.findWithId(e.selectionStart),a=o.indexOfOrThrow(e.selectionStart),i=o.indexOfOrThrow(n),[s,c]=a<i?[a,i]:[i,a],u=o.slice(s,c+1);return{selectionStart:e.selectionStart,selectionEnd:n,selected:new Set(u)}}catch{return{selectionStart:n,selectionEnd:n,selected:new Set([n])}}},clear:e=>e.selected.size===0?e:wa()});Oi=()=>oe(hr);function qu(e){let t=(0,$u.c)(2),n;return t[0]===e?n=t[1]:(n=Bt(r=>r(hr).selected.has(e)),t[0]=e,t[1]=n),oe(n)}Mr=function(){return Hu()};function zu(e){return e.get(hr).selected}let va,Ea,Na;va=Re(),{valueAtom:Ea,useActions:Vt}=Or(()=>new Set,{add:(e,t)=>{if(e.has(t))return e;let n=new Set(e);return n.add(t),n},remove:(e,t)=>{if(!e.has(t))return e;let n=new Set(e);return n.delete(t),ja(()=>{let r=document.activeElement;if(!r)return;let o=Sn.findElementThroughShadowDOMs(r);o&&Pa(Sn.parse(o.id))}),n}}),Na=e=>Bt(t=>t(Ea).has(e)),_i=function(e){let t=(0,va.c)(2),n;return t[0]===e?n=t[1]:(n=Na(e),t[0]=e,t[1]=n),oe(n)};var Ut=new WeakMap,Ku=500;function Yu(e){if(e.ctrlKey||e.metaKey||e.altKey)return"";let t=e.key.toLowerCase();return e.shiftKey?`shift+${t}`:t}function Xu(e,t){let n=Yu(e),r=e.target;if(!n||!r)return!1;let o=Ut.get(r),a=n;o!=null&&o.timeout&&clearTimeout(o.timeout),o&&(a=`${o.sequence} ${n}`);let i=t[a];if(i)return Ut.delete(r),i();if(!o){let s=t[n];if(s)return s()}if(Object.keys(t).some(s=>s.startsWith(`${a} `))){let s=window.setTimeout(()=>{Ut.delete(r)},Ku);return Ut.set(r,{sequence:a,timeout:s}),!0}return Ut.delete(r),!1}var gr=Re();function ka(e){return{handle:t=>e(t),bulkHandle:t=>{let n=!0;try{for(let r of t)n&&(n=e(r));return n}catch{return!1}}}}function Xe(e){return{handle:t=>e([t]),bulkHandle:t=>e(t)}}function Qu(e,t){let n=(0,gr.c)(12),r=Om(),o=kn(),a=Vt(),i;n[0]!==e||n[1]!==r?(i=()=>{r.focusCell({cellId:e})},n[0]=e,n[1]=r,n[2]=i):i=n[2];let s;n[3]!==o||n[4]!==e||n[5]!==t||n[6]!==r||n[7]!==a?(s=()=>{a.remove(e),o.markTouched({cellId:e}),r.blurCell(),t.current&&br(t.current)},n[3]=o,n[4]=e,n[5]=t,n[6]=r,n[7]=a,n[8]=s):s=n[8];let c;n[9]!==i||n[10]!==s?(c={onFocusWithin:i,onBlurWithin:s},n[9]=i,n[10]=s,n[11]=c):c=n[11];let{focusWithinProps:u}=cm(c);return u}Li=function(e,t){let n=(0,gr.c)(30),{canMoveX:r,editorView:o,cellActionDropdownRef:a}=t,{saveOrNameNotebook:i}=dr(),{saveCellConfig:s}=Jt(),c=_a(fi),u=kn(),d=wr(),f=Vt(),h=km(),m=oe(Ya),{copyCells:g,pasteAtCell:y}=Ru(),w=Mr(),k=qu(e),C=Un(),T=Ur(),L=oe(Tr),U;n[0]!==C||n[1]!==w?(U={clear:()=>{C.clear(),w.clear()},extend:_=>{C.clear(),w.extend(_)},select:_=>{C.clear(),w.select(_)}},n[0]=C,n[1]=w,n[2]=U):U=n[2];let A=U,x=oe(Ka),G;n[3]===x?G=n[4]:(G=(_,P)=>Ar(x.getHotkey(_).key)(P.nativeEvent||P),n[3]=x,n[4]=G);let ee=G,$=Qu(e,o),F;n[5]!==u||n[6]!==r||n[7]!==a||n[8]!==e||n[9]!==g||n[10]!==T||n[11]!==o||n[12]!==k||n[13]!==ee||n[14]!==m||n[15]!==y||n[16]!==C||n[17]!==h||n[18]!==s||n[19]!==i||n[20]!==A||n[21]!==c||n[22]!==d||n[23]!==f||n[24]!==L?(F={onKeyDown:_=>{if(Ir.fromInput(_)){_.continuePropagation();return}let P={"Mod+ArrowUp":()=>(u.focusTopCell(),A.clear(),!0),"Mod+ArrowDown":()=>(u.focusBottomCell(),A.clear(),!0),ArrowUp:()=>(u.focusCell({cellId:e,where:"before"}),A.clear(),!0),ArrowDown:()=>(u.focusCell({cellId:e,where:"after"}),A.clear(),!0),ArrowLeft:()=>{if(r){let E=d.get(nt),S=E.cellIds.findWithId(e),R=E.cellIds.indexOf(S),D=E.cellIds.at(R-1);if(D&&D.length>0){let te=Ca(e,D);return u.focusCell({cellId:te,where:"exact"}),A.clear(),!0}}return!1},ArrowRight:()=>{if(r){let E=d.get(nt),S=E.cellIds.findWithId(e),R=E.cellIds.indexOf(S),D=E.cellIds.at(R+1);if(D&&D.length>0){let te=Ca(e,D);return u.focusCell({cellId:te,where:"exact"}),A.clear(),!0}}return!1},"Shift+ArrowUp":()=>{let E=d.get(Ga);A.extend({cellId:e,allCellIds:E});let S=E.findWithId(e).before(e);return S&&A.extend({cellId:S,allCellIds:E}),u.focusCell({cellId:e,where:"before"}),!0},"Shift+ArrowDown":()=>{let E=d.get(Ga);A.extend({cellId:e,allCellIds:E});let S=E.findWithId(e).after(e);return S&&A.extend({cellId:S,allCellIds:E}),u.focusCell({cellId:e,where:"after"}),!0},Escape:()=>k?(A.clear(),!0):!1,Enter:()=>(f.add(e),Ua(d,e),A.clear(),!0),s:()=>(i(),!0)};for(let[E,S]of Object.entries(P))if(Ar(E)(_)&&S()){_.preventDefault();return}let me={"cell.run":Xe(E=>(h(E),!0)),"cell.runAndNewBelow":Xe(E=>{h(E);let S=E[E.length-1];return u.moveToNextCell({cellId:S,before:!1}),!0}),"cell.runAndNewAbove":Xe(E=>{h(E);let S=E[0];return u.moveToNextCell({cellId:S,before:!0}),!0}),"cell.createAbove":E=>(u.createNewCell({cellId:E,before:!0}),!0),"cell.createBelow":E=>(u.createNewCell({cellId:E,before:!1}),!0),"cell.moveUp":Xe(E=>{let S=E[0];return d.get(nt).cellIds.findWithId(S).first()===S?!1:(E.forEach(R=>{u.moveCell({cellId:R,before:!0})}),!0)}),"cell.moveDown":Xe(E=>{let S=E[E.length-1];return d.get(nt).cellIds.findWithId(S).last()===S?!1:([...E].reverse().forEach(R=>{u.moveCell({cellId:R,before:!1})}),!0)}),"cell.moveLeft":ka(E=>r?(u.moveCell({cellId:E,direction:"left"}),!0):!1),"cell.moveRight":ka(E=>r?(u.moveCell({cellId:E,direction:"right"}),!0):!1),"cell.hideCode":Xe(E=>{var R;let S=!E.map(D=>{var te;return((te=d.get(nt).cellData[D])==null?void 0:te.config)||null}).every(Zu);s({configs:Object.fromEntries(E.map(D=>[D,{hide_code:S}]))});for(let D of E)u.updateCellConfig({cellId:D,config:{hide_code:S}});if(E.length===1){let D=E[0];u.focusCell({cellId:D,where:"after"}),S?((R=o.current)==null||R.contentDOM.blur(),Ha(D)):Ua(d,D)}return!0}),"cell.focusDown":E=>(u.focusCell({cellId:E,where:"after"}),!0),"cell.focusUp":E=>(u.focusCell({cellId:E,where:"before"}),!0),"cell.sendToBottom":Xe(E=>(E.forEach(S=>{u.sendToBottom({cellId:S})}),!0)),"cell.sendToTop":Xe(E=>([...E].reverse().forEach(S=>{u.sendToTop({cellId:S})}),!0)),"cell.aiCompletion":E=>{var R;let S=!1;return c(D=>(D==null?void 0:D.cellId)===E?(S=!0,null):{cellId:E}),S&&((R=o.current)==null||R.focus()),!0},"cell.cellActions":()=>{var E;return(E=a.current)==null||E.toggle(),!0},"command.copyCell":Xe(E=>(g(E),!0)),"command.pasteCell":E=>(y(E),!0),"command.createCellBefore":E=>Ir.hasModifier(_)?!1:(u.createNewCell({cellId:E,before:!0,autoFocus:!0}),!0),"command.createCellAfter":E=>Ir.hasModifier(_)?!1:(u.createNewCell({cellId:E,before:!1,autoFocus:!0}),!0),"cell.delete":()=>{if(!L.keymap.destructive_delete)return!1;let E=K.size>=2?[...K]:[e],S=d.get(nt);return E.some(R=>{let{status:D}=S.cellRuntime[R];return D==="running"||D==="queued"})?!1:C.idle?(C.submit(E),!0):(T({cellIds:E}),C.clear(),!0)}},K=zu(d);if(m==="vim"&&Xu(_.nativeEvent||_,{j:P.ArrowDown,k:P.ArrowUp,h:P.ArrowLeft,l:P.ArrowRight,i:P.Enter,"shift+j":P["Shift+ArrowDown"],"shift+k":P["Shift+ArrowUp"],"g g":P["Mod+ArrowUp"],"shift+g":P["Mod+ArrowDown"],"d d":()=>me["cell.delete"](),"y y":()=>(g(K.size>=2?[...K]:[e]),!0),p:()=>(y(e,{before:!1}),!0),"shift+p":()=>(y(e,{before:!0}),!0),o:()=>(u.createNewCell({cellId:e,before:!1,autoFocus:!0}),!0),"shift+o":()=>(u.createNewCell({cellId:e,before:!0,autoFocus:!0}),!0),u:()=>(u.undoDeleteCell(),!0)})){_.preventDefault();return}for(let[E,S]of Object.entries(me))if(ee(E,_)){if(S instanceof Function){if(S(e)){_.preventDefault();return}}else if(K.size>=2?S.bulkHandle([...K]):S.handle(e)){_.preventDefault();return}return}_.continuePropagation()}},n[5]=u,n[6]=r,n[7]=a,n[8]=e,n[9]=g,n[10]=T,n[11]=o,n[12]=k,n[13]=ee,n[14]=m,n[15]=y,n[16]=C,n[17]=h,n[18]=s,n[19]=i,n[20]=A,n[21]=c,n[22]=d,n[23]=f,n[24]=L,n[25]=F):F=n[25];let{keyboardProps:j}=di(F),se;return n[26]!==$||n[27]!==k||n[28]!==j?(se=bm($,j,{"data-selected":k,className:"data-[selected=true]:ring-1 data-[selected=true]:ring-(--blue-8) data-[selected=true]:ring-offset-1"}),n[26]=$,n[27]=k,n[28]=j,n[29]=se):se=n[29],se};function Zu(e){return e==null?void 0:e.hide_code}function ed(e,t){let n=(0,gr.c)(12),r=Vt(),o=oe(Ya),a=oe(Ka),i;n[0]===a?i=n[1]:(i=Ar(a.getHotkey("command.vimEnterCommandMode").key),n[0]=a,n[1]=i);let s=i,c;n[2]!==e||n[3]!==r?(c=()=>{r.remove(e),Ha(e),ja(()=>{Pa(e)})},n[2]=e,n[3]=r,n[4]=c):c=n[4];let u=c,d;n[5]!==t||n[6]!==u?(d=()=>{if(!t.current){u();return}let g=t.current,y=g.state;if(Af(g))return;let w=y.field(Ba,!1),k=Gt(y)!==null;w&&br(g),k&&Jf(g),!(w||k)&&u()},n[5]=t,n[6]=u,n[7]=d):d=n[7];let f=d,h;n[8]!==f||n[9]!==o||n[10]!==s?(h={onKeyDown:g=>{o==="vim"?s(g)&&f():g.key==="Escape"&&f(),g.continuePropagation()}},n[8]=f,n[9]=o,n[10]=s,n[11]=h):h=n[11];let{keyboardProps:m}=di(h);return m}function Ca(e,t){let n=document.getElementById(Sn.create(e));if(!n)return t.first();let r=n.getBoundingClientRect();for(let o of t.topLevelIds){let a=document.getElementById(Sn.create(o));if(a){let i=a.getBoundingClientRect();if(r.top<=i.bottom&&r.bottom>=i.top)return o}}return t.last()}function br(e){e.state.field(Ba,!1)&&e.dispatch({effects:yd.of(null)})}var Sa=Re();const td=e=>{let t=(0,Sa.c)(24),{editorView:n,code:r,currentLanguageAdapter:o,onAfterToggle:a}=e,i;t[0]===r?i=t[1]:(i=$a.markdown.isSupported(r)||r.trim()==="",t[0]=r,t[1]=i);let s=i,c;t[2]===r?c=t[3]:(c=$a.sql.isSupported(r)||r.trim()==="",t[2]=r,t[3]=c);let u=c&&o==="python",d;t[4]===Symbol.for("react.memo_cache_sentinel")?(d=(0,b.jsx)(ld,{color:"var(--sky-11)",strokeWidth:2.5,className:"w-4 h-4"}),t[4]=d):d=t[4];let f;t[5]!==o||t[6]!==n||t[7]!==a||t[8]!==u?(f=(0,b.jsx)(yr,{editorView:n,currentLanguageAdapter:o,canSwitchToLanguage:u,icon:d,toType:"sql",displayName:"SQL",onAfterToggle:a}),t[5]=o,t[6]=n,t[7]=a,t[8]=u,t[9]=f):f=t[9];let h=s&&o==="python",m;t[10]===Symbol.for("react.memo_cache_sentinel")?(m=(0,b.jsx)(_m,{fill:"var(--sky-11)",color:"black",className:"w-4 h-4"}),t[10]=m):m=t[10];let g;t[11]!==o||t[12]!==n||t[13]!==a||t[14]!==h?(g=(0,b.jsx)(yr,{editorView:n,currentLanguageAdapter:o,canSwitchToLanguage:h,icon:m,toType:"markdown",displayName:"Markdown",onAfterToggle:a}),t[11]=o,t[12]=n,t[13]=a,t[14]=h,t[15]=g):g=t[15];let y;t[16]===Symbol.for("react.memo_cache_sentinel")?(y=(0,b.jsx)(Dm,{fill:"var(--sky-11)",color:"black",className:"w-4 h-4"}),t[16]=y):y=t[16];let w;t[17]!==o||t[18]!==n?(w=(0,b.jsx)(yr,{editorView:n,currentLanguageAdapter:o,canSwitchToLanguage:!0,icon:y,toType:"python",displayName:"Python",onAfterToggle:$d.NOOP}),t[17]=o,t[18]=n,t[19]=w):w=t[19];let k;return t[20]!==w||t[21]!==f||t[22]!==g?(k=(0,b.jsxs)("div",{className:"absolute right-3 top-2 z-20 flex hover-action gap-1",children:[f,g,w]}),t[20]=w,t[21]=f,t[22]=g,t[23]=k):k=t[23],k},yr=e=>{let t=(0,Sa.c)(10),{editorView:n,currentLanguageAdapter:r,canSwitchToLanguage:o,icon:a,toType:i,displayName:s,onAfterToggle:c}=e,u;t[0]!==n||t[1]!==c||t[2]!==i?(u=()=>{n&&(jt(n,{language:i}),c())},t[0]=n,t[1]=c,t[2]=i,t[3]=u):u=t[3];let d=u;if(!o||r===i)return null;let f=`View as ${s}`,h;t[4]!==d||t[5]!==a?(h=(0,b.jsx)(He,{"data-testid":"language-toggle-button",variant:"text",size:"xs",className:"opacity-80 px-1",onClick:d,children:a}),t[4]=d,t[5]=a,t[6]=h):h=t[6];let m;return t[7]!==f||t[8]!==h?(m=(0,b.jsx)(Et,{content:f,children:h}),t[7]=f,t[8]=h,t[9]=m):m=t[9],m};var xa=Re(),Aa=({theme:e,showPlaceholder:t,id:n,config:r,code:o,status:a,serializedEditorState:i,setEditorView:s,runCell:c,userConfig:u,editorViewRef:d,editorViewParentRef:f,hidden:h,hasOutput:m,showHiddenCode:g,languageAdapter:y,setLanguageAdapter:w,showLanguageToggles:k=!0,outputArea:C})=>{var Me;let[T,L]=En(fi),U=vi(),{saveOrNameNotebook:A}=dr(),x=Un(),{saveCellConfig:G}=Jt(),ee=a==="running"||a==="queued",$=kn(),F=Um(),j=y==="markdown",se=ue(()=>ee?!1:x.idle&&u.keymap.destructive_delete?(x.submit([n]),!0):(U({cellId:n}),!0)),_=ue(()=>ee?!1:(c(),d.current&&br(d.current),!0)),P=ue(()=>{let O=!r.hide_code;return G({configs:{[n]:{hide_code:O}}}),$.updateCellConfig({cellId:n,config:{hide_code:O}}),O}),me=oe(qd),K=ue(()=>{Lm({autoInstantiate:me,createNewCell:$.createNewCell})}),E=zd(u),S=(0,I.useMemo)(()=>{var W;let O=Bc({cellId:n,showPlaceholder:t,enableAI:E,cellActions:{...$,afterToggleMarkdown:K,onRun:_,deleteCell:se,saveNotebook:A,createManyBelow:V=>{for(let le of[...V].reverse())$.createNewCell({code:le,before:!1,cellId:n,skipIfCodeExists:!0})},splitCell:F,toggleHideCode:P,aiCellCompletion:()=>{let V=!1;return L(le=>(le==null?void 0:le.cellId)===n?(V=!0,null):{cellId:n}),V}},completionConfig:u.completion,keymapConfig:u.keymap,lspConfig:u.language_servers,theme:e,hotkeys:new za(u.keymap.overrides??{}),diagnosticsConfig:u.diagnostics,displayConfig:u.display,inlineAiTooltip:((W=u.ai)==null?void 0:W.inline_tooltip)??!1});return O.push(ze.define(V=>(w(V.state.field(xn).type),{update(le){w(le.state.field(xn).type)}})),B.updateListener.of(V=>{V.selectionSet&&V.state.selection.ranges.some(le=>le.from!==le.to)&&g({focus:!1})}),B.domEventHandlers({focus:()=>{g({focus:!1})}})),O},[n,u.keymap,u.completion,u.language_servers,u.display,u.diagnostics,E,e,t,$,F,P,se,_,L,K,w,g,A]),R=Nr(),D=ue(()=>{if(R){let W=lr(n,V=>{$.updateCellCode({cellId:n,code:V,formattingChange:!0})},o);S.push(W.extension),o=W.code}let O=new B({state:Fr.create({doc:o,extensions:S})});s(O),R||jt(O,{language:kr(O.state).type})}),te=ue(()=>{if(Pt(d.current!==null,"Editor view is not initialized"),R){let O=lr(n,W=>{$.updateCellCode({cellId:n,code:W,formattingChange:!0})});S.push(O.extension)}d.current.dispatch({effects:[pe.reconfigure.of([S]),Ad(d.current,{completionConfig:u.completion,hotkeysProvider:new za(u.keymap.overrides??{}),lspConfig:{...u.language_servers,diagnostics:u.diagnostics}})]})}),Ge=ue(()=>{if(Pt(i,"Editor view is not initialized"),R){let W=lr(n,V=>{$.updateCellCode({cellId:n,code:V,formattingChange:!0})},o);S.push(W.extension),o=W.code}let O=new B({state:Fr.fromJSON(i,{doc:o,extensions:S},{history:Of})});R||jt(O,{language:kr(O.state).type}),s(O),$.clearSerializedEditorState({cellId:n})});(0,I.useEffect)(()=>{i===null?d.current===null?D():te():Ge(),d.current!==null&&f&&f.current!==null&&f.current.replaceChildren(d.current.dom)},[D,te,Ge,d,f,i,S]),(0,I.useEffect)(()=>{let O=d.current;return()=>{O==null||O.destroy()}},[d]);let Pe=ed(n,d),Ve="";return j&&h&&m?Ve="h-0 overflow-hidden":h&&(Ve="opacity-20 h-8 [&>div.cm-editor]:h-full [&>div.cm-editor]:overflow-hidden [&_.cm-panels]:hidden"),(0,b.jsx)(ju,{cellId:n,aiCompletionCell:T,currentCode:((Me=d.current)==null?void 0:Me.state.doc.toString())??o,currentLanguageAdapter:y,declineChange:ue(()=>{var O;L(null),(O=d.current)==null||O.focus()}),onChange:ue(O=>{var W;(W=d.current)==null||W.dispatch({changes:{from:0,to:d.current.state.doc.length,insert:O}})}),acceptChange:ue(O=>{var W,V;(W=d.current)==null||W.dispatch({changes:{from:0,to:d.current.state.doc.length,insert:O}}),(V=d.current)==null||V.focus(),L(null)}),runCell:_,outputArea:C,children:(0,b.jsxs)("div",{className:"relative w-full",...Pe,children:[(0,b.jsx)(Ta,{className:Ve,editorView:d.current,ref:f,hidden:h,showHiddenCode:g}),!h&&k&&(0,b.jsx)("div",{className:"absolute top-1 right-5",children:(0,b.jsx)(td,{code:o,editorView:d.current,currentLanguageAdapter:y,onAfterToggle:K})})]})})},Ta=I.forwardRef((e,t)=>{let n=(0,xa.c)(14),{className:r,editorView:o,hidden:a,showHiddenCode:i}=e,s=(0,I.useRef)(null),c,u;n[0]===o?(c=n[1],u=n[2]):(c=()=>{o!==null&&s.current!==null&&s.current.children.length===0&&s.current.append(o.dom)},u=[o,s],n[0]=o,n[1]=c,n[2]=u),(0,I.useEffect)(c,u);let d;n[3]===r?d=n[4]:(d=ct("cm mathjax_ignore",r),n[3]=r,n[4]=d);let f;n[5]!==a||n[6]!==i?(f=g=>{a&&i&&(g.stopPropagation(),i({focus:!0}))},n[5]=a,n[6]=i,n[7]=f):f=n[7];let h;n[8]===t?h=n[9]:(h=g=>{t?_n(t,s)(g):_n(s)(g)},n[8]=t,n[9]=h);let m;return n[10]!==d||n[11]!==f||n[12]!==h?(m=(0,b.jsx)("div",{className:d,onDoubleClick:f,ref:h,"data-testid":"cell-editor"}),n[10]=d,n[11]=f,n[12]=h,n[13]=m):m=n[13],m});Ta.displayName="CellCodeMirrorEditor";function nd(e){let t=n=>{let r=(0,xa.c)(5),o=oe(lt),[a,i]=En(dt);if(Yd(o.state)||a===void 0){let c;r[0]===Symbol.for("react.memo_cache_sentinel")?(c=(0,b.jsx)("span",{children:"Waiting for real-time collaboration connection..."}),r[0]=c):c=r[0];let u;return r[1]===i?u=r[2]:(u=(0,b.jsx)("div",{className:"flex h-full w-full items-baseline p-4",children:(0,b.jsxs)(Uf,{milliseconds:1e3,fallback:null,children:[c,(0,b.jsx)(He,{variant:"link",onClick:()=>{i("disabled")},children:"Turn off real-time collaboration"})]})}),r[1]=i,r[2]=u),u}let s;return r[3]===n?s=r[4]:(s=(0,b.jsx)(e,{...n}),r[3]=n,r[4]=s),s};return t.displayName=`WithWaitUntilConnected(${e.displayName})`,t}Ui=Nr()?nd((0,I.memo)(Aa)):(0,I.memo)(Aa)});export{Ti as _,Jm as __tla,Mr as a,Ii as c,dt as d,Fi as f,On as g,Rr as h,Vt as i,Dn as l,be as m,Li as n,Oi as o,Di as p,_i as r,_n as s,Ui as t,Gr as u,Un as v};