@puddle-code/cli 0.4.13 → 0.4.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -13
- package/dist/index.js +4 -3
- package/dist/public/assets/App-HMdAT-QZ.js +15 -0
- package/dist/public/assets/{Dashboard-DyNOxwSR.js → Dashboard--rx_rrB_.js} +1 -1
- package/dist/public/assets/{LazyTerminal-BjT3haSN.js → LazyTerminal-CIclyIWs.js} +2 -2
- package/dist/public/assets/{NotebookWidget-CPhHup1W.js → NotebookWidget-C25iz3Cj.js} +1 -1
- package/dist/public/assets/{PaneEditorBody-DCGP8CyB.js → PaneEditorBody-AMEuxrqB.js} +4 -4
- package/dist/public/assets/{ReleaseNotesDialog-BD0uYU6B.js → ReleaseNotesDialog-Pa1yagZd.js} +1 -1
- package/dist/public/assets/Ripple-PKD1N1WS.js +12 -0
- package/dist/public/assets/Ripple-vJvVFdfw.css +1 -0
- package/dist/public/assets/{SettingsDialog-DwWcTOGl.js → SettingsDialog-B15ygzWY.js} +1 -1
- package/dist/public/assets/Terminal-D4qZBQDk.js +65 -0
- package/dist/public/assets/{Workspace-CjOdyZwS.js → Workspace-Baj8JhOO.js} +6 -6
- package/dist/public/assets/{_virtual_notebook-widget-runtime-BDEYw1H-.js → _virtual_notebook-widget-runtime-CVsZLTbL.js} +1 -1
- package/dist/public/assets/{expanding-content-xApnlOBO.js → expanding-content-CXpxNvmA.js} +1 -1
- package/dist/public/assets/{index-MjsHIzAR.js → index-B5q_SMZR.js} +2 -2
- package/dist/public/assets/{index-BfQvnKtf.css → index-D_XpA70m.css} +1 -1
- package/dist/public/assets/{markdown-BaCjN652.js → markdown-BlvTv1jG.js} +1 -1
- package/dist/public/assets/{notification-delivery-14yN_sWJ.js → notification-delivery-CGw2AFKW.js} +1 -1
- package/dist/public/assets/preferences-4IYvJCFc.js +1 -0
- package/dist/public/assets/render-rich-content-DXt6ncgk.js +4 -0
- package/dist/public/assets/selection-actions-BWAzKbbb.js +1 -0
- package/dist/public/assets/{use-ui-state-CyfRHVgg.js → use-ui-state-BZrKAgQ4.js} +1 -1
- package/dist/public/assets/ws-DV_MCpbg.js +1 -0
- package/dist/public/index.html +2 -2
- package/package.json +1 -1
- package/dist/public/assets/App-BOGDHWlW.js +0 -23
- package/dist/public/assets/Ripple-B-wG6_Xj.js +0 -7
- package/dist/public/assets/Ripple-V2kU3kad.css +0 -1
- package/dist/public/assets/Terminal-DzImIFH4.js +0 -65
- package/dist/public/assets/link-buffer-DcFk9vqt.js +0 -1
- package/dist/public/assets/preferences-DC7PJ3Go.js +0 -1
- package/dist/public/assets/render-rich-content-Dvum-lQy.js +0 -4
- package/dist/public/assets/ws-CS9chtfK.js +0 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/NotebookWidget-
|
|
2
|
-
import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{t}from"./react-CZI7_Jkm.js";import{Et as n,H as r,_ as i,g as a,h as o,kt as s,m as c,p as l,wt as u,x as d}from"./protocol-support-BwRR1kRO.js";import{at as f,ct as p,it as m,k as h,lt as g,nt as _,o as v,ot as y,rt as b,st as x,tt as S}from"./auth-C3ruG3fE.js";import{n as C,t as w}from"./context-D1MuDP6X.js";import{i as T,r as E,t as D}from"./client-settings-BdKglwtW.js";import{r as O,s as k}from"./theme-swfNLod9.js";import{t as A}from"./jsx-runtime-By8HlURe.js";import{t as j}from"./preload-helper-Czpn1I53.js";import{t as M}from"./purify.es-D8QhFVkO.js";import"./katex.min-ZqdHjttS.js";import{a as ee,c as N,h as P,i as F,p as I,r as te}from"./editor.api2-DTL_SiN1.js";import{n as ne,r as re,t as ie}from"./api-CULxlzTe.js";import{B as ae,C as oe,E as se,J as ce,K as le,O as ue,P as de,R as fe,T as pe,U as me,W as he,X as ge,Y as _e,Z as ve,_ as ye,a as be,at as xe,d as Se,i as Ce,it as we,j as Te,k as Ee,m as De,n as Oe,nt as ke,ot as Ae,r as je,rt as Me,st as Ne,u as Pe,v as Fe,w as Ie}from"./media-refresh-store-CYiYB60R.js";import{n as Le}from"./motion-Bd_MB9cH.js";import{t as Re}from"./createLucideIcon-C9A1vLE-.js";import{n as L}from"./dist-BOS6OKSE.js";import{i as ze,r as Be}from"./dist-Dac0re_p.js";import{n as Ve,r as He}from"./dist-BeQvHdsz.js";import{t as Ue}from"./arrow-down-CtYa-Aya.js";import{a as We,i as Ge,n as Ke,o as qe,r as Je,t as Ye}from"./select-CGxTz4dh.js";import{t as Xe}from"./chevron-down-HQLVE6o5.js";import{a as Ze,n as Qe,o as $e,r as et,t as tt}from"./FindWidget-Bh_7yWNg.js";import{t as nt}from"./copy-D0Theg4Q.js";import{t as rt}from"./rotate-ccw-BI2k_h3A.js";import{a as it,i as at,n as ot,o as st,r as ct,t as lt}from"./preview-kind-CPkO-rSz.js";import{t as ut}from"./x-DV6-RYI2.js";import{h as dt,l as ft,t as pt,v as mt}from"./ws-CS9chtfK.js";import{t as ht}from"./control-tray-c9uXOo-i.js";import{a as gt,o as _t,r as vt,s as yt,t as bt}from"./command--8Svn0Z-.js";import{n as xt,r as St,t as Ct}from"./popover-D5HmbdQ7.js";import{i as wt,n as Tt,r as Et}from"./markdown-it-CWoG9_Dn.js";import{t as Dt}from"./debounce-B9DrqirV.js";import{a as Ot,c as kt,d as At,f as jt,i as Mt,l as Nt,o as Pt,p as Ft,r as It,s as Lt,t as Rt,u as zt}from"./buffer-store-Bh2IilxW.js";import{r as Bt,t as Vt}from"./view-state-store-DVvLMbeY.js";import{a as Ht,c as Ut,i as Wt,l as Gt,o as Kt,r as qt,s as Jt,t as Yt}from"./markdown-BaCjN652.js";import{i as Xt,n as Zt,r as Qt,t as $t}from"./drafts-B_tChlzR.js";import{r as en}from"./buffer-logic-BAkSBQT7.js";import{a as tn,i as nn,n as rn,o as an,r as on}from"./editor-sync-W1bamxAP.js";import{r as sn,t as cn}from"./math-CSw6sgCC.js";import{n as ln}from"./math-delimiters-BCnTi7Ii.js";import{n as un}from"./markdown-mermaid-TizVRNLQ.js";var dn=Re(`arrow-down-to-line`,[[`path`,{d:`M12 17V3`,key:`1cwfxf`}],[`path`,{d:`m6 11 6 6 6-6`,key:`12ii2o`}],[`path`,{d:`M19 21H5`,key:`150jfl`}]]),fn=Re(`arrow-up-to-line`,[[`path`,{d:`M5 3h14`,key:`7usisc`}],[`path`,{d:`m18 13-6-6-6 6`,key:`1kf1n9`}],[`path`,{d:`M12 7v14`,key:`1akyts`}]]),pn=Re(`combine`,[[`path`,{d:`M14 3a1 1 0 0 1 1 1v5a1 1 0 0 1-1 1`,key:`1l7d7l`}],[`path`,{d:`M19 3a1 1 0 0 1 1 1v5a1 1 0 0 1-1 1`,key:`9955pe`}],[`path`,{d:`m7 15 3 3`,key:`4hkfgk`}],[`path`,{d:`m7 21 3-3H5a2 2 0 0 1-2-2v-2`,key:`1xljwe`}],[`rect`,{x:`14`,y:`14`,width:`7`,height:`7`,rx:`1`,key:`1cdgtw`}],[`rect`,{x:`3`,y:`3`,width:`7`,height:`7`,rx:`1`,key:`zi3rio`}]]),mn=Re(`cpu`,[[`path`,{d:`M12 20v2`,key:`1lh1kg`}],[`path`,{d:`M12 2v2`,key:`tus03m`}],[`path`,{d:`M17 20v2`,key:`1rnc9c`}],[`path`,{d:`M17 2v2`,key:`11trls`}],[`path`,{d:`M2 12h2`,key:`1t8f8n`}],[`path`,{d:`M2 17h2`,key:`7oei6x`}],[`path`,{d:`M2 7h2`,key:`asdhe0`}],[`path`,{d:`M20 12h2`,key:`1q8mjw`}],[`path`,{d:`M20 17h2`,key:`1fpfkl`}],[`path`,{d:`M20 7h2`,key:`1o8tra`}],[`path`,{d:`M7 20v2`,key:`4gnj0m`}],[`path`,{d:`M7 2v2`,key:`1i4yhu`}],[`rect`,{x:`4`,y:`4`,width:`16`,height:`16`,rx:`2`,key:`1vbyd7`}],[`rect`,{x:`8`,y:`8`,width:`8`,height:`8`,rx:`1`,key:`z9xiuo`}]]),hn=Re(`list-tree`,[[`path`,{d:`M8 5h13`,key:`1pao27`}],[`path`,{d:`M13 12h8`,key:`h98zly`}],[`path`,{d:`M13 19h8`,key:`c3s6r1`}],[`path`,{d:`M3 10a2 2 0 0 0 2 2h3`,key:`1npucw`}],[`path`,{d:`M3 5v12a2 2 0 0 0 2 2h3`,key:`x1gjn2`}]]),R=e(t(),1),z=A();String.prototype.codePointAt;function gn(e,t){return function(n){let r,i=0,a=``;for(;r=e.exec(n);)i!==r.index&&(a+=n.substring(i,r.index)),a+=t.get(r[0].charCodeAt(0)),i=r.index+1;return a+n.substring(i)}}var _n=gn(/["&\u00A0]/g,new Map([[34,`"`],[38,`&`],[160,` `]])),vn=gn(/[&<>\u00A0]/g,new Map([[38,`&`],[60,`<`],[62,`>`],[160,` `]])),yn=new Map,bn=new Map,xn=1;function Sn(e){for(let t of bn.get(e)??[])t()}function Cn(e,t){yn.set(e,t),Sn(e)}function wn(e){let t={phase:`unresolved`,revision:xn++};return Cn(e,t),t}function Tn(e){let t=yn.get(e);return!t||t.phase!==`unresolved`&&t.phase!==`load-error`?null:(Cn(e,{phase:`loading`,revision:t.revision}),t.revision)}function En(e,t,n,r){let i=yn.get(e);return!i||i.phase!==`loading`||i.revision!==t?!1:(Cn(e,{phase:`opening`,revision:t,content:n,mtimeMs:r}),!0)}function Dn(e,t){let n=yn.get(e);return!n||n.phase!==`opening`||n.revision!==t?!1:(Cn(e,{...n,phase:`comparing`}),!0)}function On(e,t,n){let r=yn.get(e);return!r||r.phase!==`loading`||r.revision!==t?!1:(Cn(e,{phase:`load-error`,revision:t,message:n}),!0)}function kn(e,t){return t&&e?.phase===`unresolved`}function An(e){return e?.phase===`comparing`?e.mtimeMs:void 0}function jn(e){return e?.phase===`loading`||e?.phase===`load-error`||e?.phase===`opening`}function Mn(e){return e.phase===`opening`||e.phase===`comparing`}function Nn(e){yn.delete(e)&&Sn(e)}function Pn(e){return yn.get(e)??null}function Fn(e,t){let n=bn.get(e);return n||(n=new Set,bn.set(e,n)),n.add(t),()=>n.delete(t)}function In(e){return{tabSize:e,insertSpaces:!0,detectIndentation:!1}}var Ln=new Vt,Rn=new Vt;function zn(e){let t={...e.contributionsState};return delete t[`editor.contrib.wordHighlighter`],{...e,contributionsState:t}}function Bn(e,t){let n=(0,R.useRef)(null),r=(0,R.useRef)(null);return(0,R.useLayoutEffect)(()=>(n.current&&(r.current=t(n.current,e)),()=>{r.current?.(),r.current=null}),[e,t]),(0,R.useCallback)(i=>{r.current?.(),n.current=i,i.onDidDispose(()=>{n.current===i&&(n.current=null)}),r.current=t(i,e)},[e,t])}function Vn(e,t){let n=Ln.get(t);n&&e.restoreViewState(n);let r=()=>{if(!e.getModel())return;let n=e.saveViewState();n&&Ln.set(t,zn(n))},i=[e.onDidScrollChange(r),e.onDidChangeCursorSelection(r)];return()=>{r(),i.forEach(e=>e.dispose())}}function Hn(e,t){let n=Rn.get(t),r=n!==void 0,i=()=>{if(r||!e.getModel())return;let n=e.saveViewState();n&&Rn.set(t,{...n,original:n.original&&zn(n.original),modified:n.modified&&zn(n.modified)})};n&&e.restoreViewState(n);let a=[e.onDidUpdateDiff(()=>{r&&(r=!1,n&&e.restoreViewState(n))}),...[e.getOriginalEditor(),e.getModifiedEditor()].flatMap(e=>[e.onDidScrollChange(i),e.onDidChangeCursorSelection(i)])];return()=>{i(),a.forEach(e=>e.dispose())}}function Un(e){return Bn(Bt(`code`,e),Vn)}function Wn(e){return Bn(Bt(`diff`,e),Hn)}function Gn({session:e,path:t,conflict:n,model:r,onTakeDisk:i,onKeepMine:a,onSave:o,onReady:s}){let c=T(),l=Wn([`conflict`,r.uri.toString()]),u=(0,R.useId)(),d=(0,R.useMemo)(()=>getComputedStyle(document.documentElement).getPropertyValue(`--font-mono`).trim()||void 0,[]),f=(0,R.useRef)(o);f.current=o;let p=(0,R.useRef)(null),m=()=>{let e=p.current;if(!e)return;let t=e.getModel();e.setModel(null),t?.original.dispose(),p.current=null},h=(0,R.useRef)(m);return h.current=m,(0,R.useEffect)(()=>()=>h.current(),[]),(0,z.jsxs)(`div`,{className:`flex h-full flex-col bg-ground`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-3 bg-elevated px-3 py-1.5 text-xs text-fg-secondary`,children:[(0,z.jsx)(`span`,{children:`This file changed on disk. Yours is on the right — merge what you want, then save.`}),(0,z.jsx)(`button`,{type:`button`,onClick:i,className:`ml-auto shrink-0 text-fg-muted transition-colors hover:text-fg`,children:`Take the disk version`}),(0,z.jsx)(`button`,{type:`button`,onClick:a,disabled:n.phase!==`comparing`,className:`shrink-0 text-fg-muted transition-colors hover:text-fg`,children:`Keep mine`})]}),(0,z.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,z.jsx)(Ft,{modifiedModelPath:r.uri.toString(),originalModelPath:`puddle-disk://${encodeURIComponent(e)}/${n.mtimeMs}/${encodeURIComponent(u)}/${t.split(`/`).map(encodeURIComponent).join(`/`)}`,original:n.content,language:r.getLanguageId(),theme:At,keepCurrentModifiedModel:!0,loading:(0,z.jsx)(`div`,{className:`p-3 text-xs text-fg-muted`,children:`…`}),onMount:e=>{l(e),p.current=e,e.onDidDispose(()=>{p.current=null}),e.getModifiedEditor().addCommand(F.CtrlCmd|te.KeyS,()=>f.current()),s?.(n.revision)},options:{readOnly:n.phase!==`comparing`,originalEditable:!1,renderSideBySide:!0,automaticLayout:!0,fontFamily:d,fontSize:c.editorFontSize,...In(c.editorTabSize),wordWrap:c.editorWordWrap?`on`:`off`,minimap:{enabled:!1},fixedOverflowWidgets:!0,scrollBeyondLastLine:!1}})})]})}function Kn({session:e,path:t,buffer:n,focused:r}){let i=n.conflict;return!i||i.phase===`unresolved`?null:Mn(i)&&n.model?(0,z.jsx)(Gn,{session:e,path:t,conflict:i,model:n.model,onTakeDisk:n.takeDisk,onKeepMine:n.keepMine,onSave:n.save,onReady:r?n.comparisonReady:void 0}):i.phase===`load-error`?(0,z.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-3 bg-ground px-4 text-center text-sm text-fg-muted`,children:[(0,z.jsx)(`span`,{children:`The disk version could not be loaded.`}),(0,z.jsx)(`span`,{className:`max-w-lg text-xs text-fg-secondary`,children:i.message}),(0,z.jsx)(`button`,{type:`button`,onClick:n.compare,className:`rounded-md bg-elevated px-3 py-1.5 text-xs text-fg-secondary transition-colors hover:bg-border hover:text-fg`,children:`Retry compare`})]}):(0,z.jsx)(`div`,{className:`flex h-full items-center justify-center bg-ground text-sm text-fg-muted`,children:`Loading the disk version…`})}function qn(e){return Number.isFinite(e)?Math.min(1,Math.max(0,e)):0}function Jn(e,t,n){return qn(e/Math.max(1,t-n))}function Yn(e,t,n){return qn(e)*Math.max(0,t-n)}function Xn(e,t){return JSON.stringify([e,t.session,t.root??null,t.path])}var Zn=new class{positions=new Map;listeners=new Map;revision=0;publish(e,t,n,r=null){let i={ratio:qn(n),sourceLine:r!==null&&Number.isFinite(r)?Math.max(1,r):null,revision:++this.revision},a=Xn(e,t);this.positions.set(a,i);for(let e of this.listeners.get(a)??[])e(i);return i}get(e,t){return this.positions.get(Xn(e,t))}subscribe(e,t,n){let r=Xn(e,t),i=this.listeners.get(r);i||(i=new Set,this.listeners.set(r,i)),i.add(n);let a=this.positions.get(r);return a&&n(a),()=>{i?.delete(n),i?.size===0&&this.listeners.delete(r)}}},Qn=new Vt;function $n(e){let t=null;return{schedule:()=>{t===null&&(t=requestAnimationFrame(()=>{t=null,e()}))},dispose:()=>{t!==null&&cancelAnimationFrame(t),t=null}}}function er(e,t,n,r){let i=Math.max(0,t-n);if(e.ratio<=0)return 0;if(e.ratio>=1)return i;if(e.sourceLine!==null&&r){let t=Ut(r,e.sourceLine);if(t!==null)return Math.min(i,Math.max(0,t))}return Yn(e.ratio,t,n)}function tr(e,t){if(t.driver&&t.receiver)throw Error(`a preview scroll surface cannot be both driver and receiver`);let n=t.store??Zn,r=t.viewKey?Qn.get(t.viewKey):void 0,i=t.sourceAnchors?.(),a=()=>void 0,o,s=n=>{r=n,t.viewKey&&Qn.set(t.viewKey,n),e.scrollTop=er(n,e.scrollHeight,e.clientHeight,i)};r&&s(r);let c=()=>{if(e.clientHeight<=0)return;let a=Jn(e.scrollTop,e.scrollHeight,e.clientHeight),o=i?Gt(i,e.scrollTop):null;r={ratio:a,sourceLine:o,revision:0},t.viewKey&&Qn.set(t.viewKey,r),t.driver&&n.publish(t.channel,t.target,a,o)};t.receiver?a=n.subscribe(t.channel,t.target,s):(t.driver||t.viewKey)&&(o=$n(c),e.addEventListener(`scroll`,o.schedule,{passive:!0}),o.schedule());let l=new ResizeObserver(()=>{i=t.sourceAnchors?.(),r?s(r):o?.schedule()});for(let e of t.resizeElements??[])l.observe(e);return()=>{o&&(c(),e.removeEventListener(`scroll`,o.schedule)),a(),l.disconnect(),o?.dispose()}}function nr(e,t){let n=e.getModel()?.getLineCount()??0;if(n===0)return null;let r=1,i=n;for(;r<i;){let n=Math.ceil((r+i)/2);e.getTopForLineNumber(n)<=t?r=n:i=n-1}let a=e.getTopForLineNumber(r),o=r<n?e.getTopForLineNumber(r+1):e.getScrollHeight();return o<=a?r:r+Math.min(1,Math.max(0,(t-a)/(o-a)))}function rr(e,t){let n=e.getModel()?.getLineCount()??0;if(n===0||!Number.isFinite(t))return null;let r=Math.min(n+1,Math.max(1,t)),i=Math.floor(r);if(i>n)return e.getScrollHeight();let a=i+1,o=e.getTopForLineNumber(i),s=a<=n?e.getTopForLineNumber(a):e.getScrollHeight();return o+(r-i)*(s-o)}function ir(e,t,n){if(t.driver&&t.receiver)throw Error(`a Monaco scroll surface cannot be both driver and receiver`);let r=t.store??Zn,i=[],a,o=()=>void 0,s,c=()=>e.getLayoutInfo().height,l=t=>{a=t;let r=t.ratio>0&&t.ratio<1&&t.sourceLine!==null?rr(e,t.sourceLine):null;e.setScrollTop(r??er(t,e.getScrollHeight(),c()),n)};return t.receiver?(o=r.subscribe(t.channel,t.target,l),i.push(e.onDidChangeModel(()=>a&&l(a))),i.push(e.onDidLayoutChange(()=>a&&l(a))),i.push(e.onDidContentSizeChange(()=>a&&l(a)))):t.driver&&(s=$n(()=>{let n=Jn(e.getScrollTop(),e.getScrollHeight(),c());r.publish(t.channel,t.target,n,nr(e,e.getScrollTop()))}),i.push(e.onDidScrollChange(s.schedule)),i.push(e.onDidChangeModel(s.schedule)),i.push(e.onDidChangeModelContent(s.schedule)),i.push(e.onDidLayoutChange(s.schedule)),i.push(e.onDidContentSizeChange(s.schedule)),s.schedule()),()=>{o();for(let e of i)e.dispose();s?.dispose()}}function ar(e){return!e}function or(e){let t=e.split(`+`),n=t.pop()??``,r=0;for(let e of t)e===`meta`?r|=F.CtrlCmd:e===`ctrl`?r|=F.WinCtrl:e===`alt`?r|=F.Alt:e===`shift`&&(r|=F.Shift);let i=te[/^Key[A-Z]$/.test(n)?`Key${n.slice(3)}`:/^Digit[0-9]$/.test(n)?`Digit${n.slice(5)}`:n];return typeof i==`number`?r|i:null}function sr(e,t){let n=or(ft(`editor.save`));n!==null&&e.addCommand(n,()=>t.onSave());let r=or(ft(`editor.wordWrap`));e.addAction({id:`puddle.toggleWordWrap`,label:`Toggle Word Wrap`,keybindings:r===null?[]:[r],run:()=>E({editorWordWrap:ar(D().editorWordWrap)})})}var cr=new WeakSet;function lr(e){return cr.has(e)?!1:(cr.add(e),!0)}function ur(e){return`file-conflict:${e}`}function dr(e,t,n,r,i){let a=i?.passive===!0,o=i?.focused??!0,s=Rt(e,t,r),c=ve(e,t,{root:r,live:i?.live}),l=_e(e,r),[u,d]=(0,R.useState)(null),[f,p]=(0,R.useState)(!1),m=(0,R.useRef)(!1),h=(0,R.useRef)(null),g=(0,R.useRef)(null),_=(0,R.useRef)(n);_.current=n;let v=(0,R.useRef)(!1),y=(0,R.useCallback)((e,t)=>{g.current?.cancel(),v.current=!0;try{Lt(s,e,t)}finally{v.current=!1}},[s]),b=(0,R.useSyncExternalStore)((0,R.useCallback)(e=>zt(s,e),[s]),()=>Mt(s)),x=(0,R.useSyncExternalStore)((0,R.useCallback)(e=>an(s,e),[s]),()=>tn(s)),S=(0,R.useSyncExternalStore)((0,R.useCallback)(e=>Fn(s,e),[s]),()=>Pn(s));(0,R.useEffect)(()=>{let n=c.data;if(!n||n.binary||n.content===null||m.current)return;m.current=!0;let i=Nt(s)!==void 0,a=It(e,t,n.content,n.mtime_ms,r),o=a.getValue();d(a),!i&&Xt(e,t,r).then(i=>{if(!i)return;let s=Zt(i,o,n.mtime_ms);s===`discard`?$t(e,t,r):s===`restore`?en(a,i.content)&&p(!0):L(`This file has an unsaved draft from an earlier version.`,{description:`The file changed on disk since the draft was saved.`,duration:12e3,action:{label:`Restore draft`,onClick:()=>{en(a,i.content)&&p(!0)}}})})},[c.data,s,e,t,r]),(0,R.useEffect)(()=>{if(!u||a)return;let n=Qt(e,t,r);g.current=n;let i=u.onDidChangeContent(()=>{v.current||(n(u.getValue(),Nt(s)??0),rn(e,t,r))});return()=>{n.flush(),i.dispose(),g.current=null}},[u,s,e,t,r,a]),(0,R.useEffect)(()=>{!u||!x.savedElsewhere||Mt(s)||c.refetch().then(e=>{Mt(s)||(e.data&&e.data.content!==null&&y(e.data.content,e.data.mtime_ms),nn(s))})},[x.savedElsewhere,u,s]),(0,R.useEffect)(()=>{let e=c.data;!u||!e||e.content===null||!Mt(s)&&e.mtime_ms!==Nt(s)&&y(e.content,e.mtime_ms)},[c.data,u,s]);let C=(0,R.useCallback)((n,i)=>{Ot(s,n,i),g.current?.cancel(),$t(e,t,r),on(e,t,i,r),p(!1),Nn(s)},[s,e,t,r]),w=(0,R.useCallback)(()=>{let e=Tn(s);e!==null&&(L.dismiss(ur(s)),c.refetch({throwOnError:!0}).then(t=>{let n=t.data;if(!n)throw Error(`The disk version did not load.`);if(n.content===null)throw Error(`The file on disk is binary and cannot be compared as text.`);En(s,e,n.content,n.mtime_ms)}).catch(t=>{On(s,e,t instanceof Error?t.message:`The disk version did not load.`)}))},[c,s]),T=(0,R.useRef)(w);T.current=w,(0,R.useEffect)(()=>{if(!kn(S,o))return;let e=ur(s);return L(`File changed on disk`,{id:e,description:`Nothing was written — your unsaved version is intact.`,duration:1/0,closeButton:!0,action:{label:`Compare`,onClick:()=>T.current()}}),()=>{L.dismiss(e)}},[S,o,s]);let E=(0,R.useCallback)(()=>{c.refetch().then(n=>{n.data&&n.data.content!==null&&y(n.data.content,n.data.mtime_ms),$t(e,t,r),p(!1),Nn(s)})},[s,e,t,y]),D=(0,R.useCallback)((e,n)=>{l.mutate({path:t,content:e},{onSuccess:e=>C(n,e.mtime_ms),onError:e=>L.error(e instanceof Error?e.message:`Overwrite failed`)})},[l,t,C]),O=(0,R.useCallback)(async()=>{if(!u||!Mt(s))return!0;let e=u.getValue(),n=u.getAlternativeVersionId();if(jn(Pn(s)))return!1;let r=An(Pn(s))??Nt(s);try{let i=await l.mutateAsync({path:t,content:e,expected_mtime_ms:r});return C(n,i.mtime_ms),!0}catch(e){return e instanceof ie&&e.status===409&&e.code===`stale_file`?wn(s):L.error(e instanceof Error?e.message:`Save failed`),!1}},[u,s,l,t,C]),k=(0,R.useRef)(O);k.current=O,(0,R.useEffect)(()=>ue(Te(e,t,r),()=>k.current(),{session:e,path:t,...r===void 0?{}:{root:r}}),[e,t,r]);let A=(0,R.useCallback)(()=>{let n=h.current,i=_.current;!n||!i||!o||i.session!==e||i.path!==t||(i.root??void 0)!==(r??void 0)||lr(i)&&(n.revealLineInCenter(i.line),n.setPosition({lineNumber:i.line,column:i.column??1}),n.focus())},[e,t,r,o]),j=(0,R.useCallback)(e=>{h.current=e,sr(e,{onSave:()=>k.current()}),A()},[A]);(0,R.useEffect)(()=>{A()},[n,u,A]);let M=(0,R.useCallback)(()=>{E()},[E]),ee=(0,R.useCallback)(()=>{!u||Pn(s)?.phase!==`comparing`||D(u.getValue(),u.getAlternativeVersionId())},[u,s,D]),N=(0,R.useCallback)(e=>{Dn(s,e)},[s]),P,F=null;c.data?.binary?P=`binary`:c.error?c.error instanceof ie&&c.error.status===413?P=`too-large`:(P=`error`,F=c.error instanceof Error?c.error.message:`Failed to load file`):P=u?`ready`:`loading`;let I=b&&x.savedElsewhere?`saved-elsewhere`:b&&x.dirtyElsewhere?`dirty-elsewhere`:null;return{status:P,errorMessage:F,model:u,dirty:b,restoredNotice:f,discardRestore:M,peerBadge:I,conflict:S,takeDisk:E,keepMine:ee,compare:w,comparisonReady:N,save:O,onMount:j}}function fr(e,t,n,r){for(let i of e)if(_r([i],n).some(e=>(r===void 0||e.kind===r)&&t>=e.startLineNumber&&t<=e.endLineNumber))return i;return null}function pr(e,t){return hr(e.modifiedStartLineNumber,e.modifiedEndLineNumber)>0?Math.min(t,e.modifiedEndLineNumber):Math.max(0,Math.min(t,e.modifiedStartLineNumber-1))}function mr(e){let t=hr(e.originalStartLineNumber,e.originalEndLineNumber),n=hr(e.modifiedStartLineNumber,e.modifiedEndLineNumber);return Math.max(5,Math.min(14,t+n+4))}function hr(e,t){return t===0?0:Math.max(0,t-e+1)}function gr(e,t){if(e>t)return{startLineNumber:Math.max(1,t),endLineNumber:Math.max(1,t),kind:`deleted-after`};let n=Math.max(1,e);return{startLineNumber:n,endLineNumber:n,kind:`deleted-before`}}function _r(e,t){let n=[];for(let r of e){let e=hr(r.originalStartLineNumber,r.originalEndLineNumber),i=hr(r.modifiedStartLineNumber,r.modifiedEndLineNumber);if(e===0&&i>0){n.push({startLineNumber:r.modifiedStartLineNumber,endLineNumber:r.modifiedEndLineNumber,kind:`added`});continue}if(i===0&&e>0){n.push(gr(r.modifiedStartLineNumber,t));continue}let a=Math.min(e,i);a>0&&n.push({startLineNumber:r.modifiedStartLineNumber,endLineNumber:r.modifiedStartLineNumber+a-1,kind:`modified`}),i>a&&n.push({startLineNumber:r.modifiedStartLineNumber+a,endLineNumber:r.modifiedEndLineNumber,kind:`added`}),e>a&&n.push(gr(r.modifiedStartLineNumber+i,t))}return n}var vr=28,yr=[[`puddle-dirty-added`,`added`],[`puddle-dirty-modified`,`modified`],[`puddle-dirty-deleted-before`,`deleted-before`],[`puddle-dirty-deleted-after`,`deleted-after`]];function br(e){if(e){for(let[t,n]of yr)if(e.classList.contains(t)||e.closest(`.${t}`))return n}}function xr({editor:e,original:t,modified:n,path:r}){let i=[],a=null,o=!1,s=t=>{try{e.changeViewZones(e=>e.removeZone(t))}catch{}},c=()=>{let e=a;e&&(a=null,e.frame!==null&&cancelAnimationFrame(e.frame),e.diffEditor&&(e.diffEditor.setModel(null),e.diffEditor.dispose()),s(e.zoneId))},l=e=>{let t=e.diffEditor;if(!t)return;let r=Math.max(1,Math.min(n.getLineCount(),e.change.modifiedStartLineNumber));t.getModifiedEditor().revealLineInCenter(r,I.ScrollType.Immediate)},u=(i,s)=>{if(a?.anchorLine===i){c();return}c();let u=e.getOption(I.EditorOption.lineHeight),d=document.createElement(`div`);d.className=`puddle-dirty-peek`;let f=document.createElement(`div`);f.className=`puddle-dirty-peek-header`;let p=document.createElement(`span`);p.className=`puddle-dirty-peek-title`,p.textContent=`${r.split(`/`).pop()??r} · Local changes against HEAD`;let m=document.createElement(`button`);m.type=`button`,m.className=`puddle-dirty-peek-close`,m.setAttribute(`aria-label`,`Close inline change`),m.title=`Close inline change`,m.textContent=`×`,m.addEventListener(`pointerdown`,e=>{e.preventDefault(),e.stopPropagation(),c()}),m.addEventListener(`click`,e=>{e.preventDefault(),e.stopPropagation(),c()});let h=document.createElement(`div`);h.className=`puddle-dirty-peek-editor`,f.append(p,m),d.append(f,h);let g=document.createElement(`div`);g.className=`puddle-dirty-peek-margin`;let _={afterLineNumber:pr(s,n.getLineCount()),heightInPx:vr+mr(s)*u,domNode:d,marginDomNode:g,suppressMouseDown:!1},v=``;e.changeViewZones(e=>{v=e.addZone(_)});let y={anchorLine:i,change:s,zone:_,zoneId:v,frame:null,diffEditor:null};a=y,y.frame=requestAnimationFrame(()=>{if(y.frame=null,o||a!==y)return;let r=I.createDiffEditor(h,{readOnly:!0,domReadOnly:!0,originalEditable:!1,renderSideBySide:!1,renderMarginRevertIcon:!1,renderOverviewRuler:!1,enableSplitViewResizing:!1,isInEmbeddedEditor:!0,automaticLayout:!0,fontFamily:e.getOption(I.EditorOption.fontFamily),fontSize:e.getOption(I.EditorOption.fontSize),lineHeight:u,minimap:{enabled:!1},glyphMargin:!1,folding:!1,scrollBeyondLastLine:!1,fixedOverflowWidgets:!0,hideUnchangedRegions:{enabled:!0,minimumLineCount:0,contextLineCount:2,revealLineCount:3}});y.diffEditor=r,r.setModel({original:t,modified:n}),r.onDidUpdateDiff(()=>l(y)),l(y)}),e.revealLineInCenter(Math.max(1,Math.min(n.getLineCount(),s.modifiedStartLineNumber)))},d=e.onMouseDown(e=>{if(!e.event.leftButton||e.target.type!==I.MouseTargetType.GUTTER_LINE_DECORATIONS||e.target.position===null)return;let t=e.target.position.lineNumber,r=fr(i,t,n.getLineCount(),br(e.target.element));r&&(e.event.preventDefault(),e.event.stopPropagation(),u(t,r))});return{update(t){if(i=t,!a)return;let r=a,o=fr(t,r.anchorLine,n.getLineCount());if(!o){c();return}r.change=o,r.zone.afterLineNumber=pr(o,n.getLineCount()),r.zone.heightInPx=vr+mr(o)*e.getOption(I.EditorOption.lineHeight);try{e.changeViewZones(e=>e.layoutZone(r.zoneId))}catch{c();return}l(r)},dispose(){o=!0,d.dispose(),c()}}}var Sr={added:`puddle-dirty-added`,modified:`puddle-dirty-modified`,"deleted-before":`puddle-dirty-deleted-before`,"deleted-after":`puddle-dirty-deleted-after`};function Cr(e,t,n,i){let a=r(),o=le(e,t,{root:n,enabled:a.data!==void 0&&d(a.data.protocol)&&i!==null}),[s,c]=(0,R.useState)(null),l=(0,R.useCallback)(e=>{c(e)},[]);return(0,R.useLayoutEffect)(()=>{let e=o.data;if(!s||!i||!e||e.repository===null||e.ignored||e.binary)return;let n=document.createElement(`div`);n.className=`puddle-hidden-diff-controller`,document.body.appendChild(n);let r=I.createModel(e.exists?e.content??``:``,i.getLanguageId()),a=I.createDiffEditor(n,{readOnly:!0,automaticLayout:!1,renderSideBySide:!1,minimap:{enabled:!1}}),c=s.createDecorationsCollection();a.setModel({original:r,modified:i});let l=xr({editor:s,original:r,modified:i,path:t}),u=()=>{let e=a.getLineChanges();e&&(l.update(e),c.set(_r(e,i.getLineCount()).map(e=>({range:new N(e.startLineNumber,1,e.endLineNumber,1),options:{isWholeLine:!0,linesDecorationsClassName:Sr[e.kind]}}))))},d=a.onDidUpdateDiff(u);return u(),()=>{d.dispose(),l.dispose(),c.clear(),a.setModel(null),a.dispose(),r.dispose(),n.remove()}},[s,i,o.data]),l}function wr({message:e,session:t,path:n,root:r,download:i}){return(0,z.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-3 bg-ground text-sm text-fg-muted`,children:[(0,z.jsx)(`span`,{children:e}),i&&(0,z.jsxs)(`button`,{type:`button`,onClick:()=>void fe(t,n,r).catch(e=>L.error(e instanceof Error?e.message:`Download failed`)),className:`flex items-center gap-1.5 text-fg-secondary transition-colors hover:text-fg`,children:[(0,z.jsx)(Ae,{className:`size-4`}),`Download`]})]})}function Tr({session:e,path:t,reveal:n,root:r,focused:i=!0,scrollDriver:a=!1,scrollReceiver:o=!1,scrollChannel:s=`profile`}){let c=T(),l=Le(),u=Un([e,r,t]),d=dr(e,t,n,r,{focused:i}),f=de(e,t,r),p=Cr(e,t,r,d.model),m=(0,R.useMemo)(()=>getComputedStyle(document.documentElement).getPropertyValue(`--font-mono`).trim()||void 0,[]),[h,g]=(0,R.useState)(null),_=(0,R.useMemo)(()=>({session:e,path:t,root:r}),[e,t,r]),v=d.conflict!==null&&d.conflict.phase!==`unresolved`;if((0,R.useEffect)(()=>{if(!(!h||!d.model||v))return ir(h,{channel:s,target:_,driver:a,receiver:o},I.ScrollType.Immediate)},[h,d.model,v,s,_,a,o]),(0,R.useEffect)(()=>{let e=d.model;e&&I.setModelMarkers(e,`puddle-compilation`,f.map(t=>{let n=Math.min(t.line,e.getLineCount()),r=e.getLineMaxColumn(n),i=Math.min(t.column??1,r),a=t.end_line??n,o=Math.max(n,Math.min(a,e.getLineCount())),s=e.getLineMaxColumn(o),c=Math.min(t.end_column??(t.column?i+1:s),s);return{severity:t.severity===`error`?ee.Error:t.severity===`warning`?ee.Warning:ee.Info,message:t.message,source:`Puddle compilation`,startLineNumber:n,startColumn:i,endLineNumber:o,endColumn:Math.max(i,c)}}))},[d.model,f]),d.conflict&&d.conflict.phase!==`unresolved`)return(0,z.jsx)(Kn,{session:e,path:t,buffer:d,focused:i});if(d.status===`binary`)return(0,z.jsx)(wr,{message:`Binary file — use Download`,session:e,path:t,root:r,download:!0});if(d.status===`too-large`)return(0,z.jsx)(wr,{message:`File too large to edit — use Download`,session:e,path:t,root:r,download:!0});if(d.status===`error`)return(0,z.jsx)(wr,{message:d.errorMessage??`Failed to load file`,session:e,path:t,root:r});let y=d.peerBadge===`saved-elsewhere`?`Saved in another window`:d.peerBadge===`dirty-elsewhere`?`Also being edited in another window`:null;return(0,z.jsxs)(`div`,{className:`flex h-full flex-col bg-ground`,children:[d.restoredNotice&&(0,z.jsxs)(`div`,{className:`flex items-center gap-3 bg-elevated px-3 py-1.5 text-xs text-fg-secondary`,children:[(0,z.jsx)(`span`,{children:`Restored unsaved changes`}),(0,z.jsx)(`button`,{type:`button`,onClick:d.discardRestore,className:`text-fg-muted transition-colors hover:text-fg`,children:`Discard`})]}),y&&(0,z.jsx)(`div`,{className:`bg-surface px-3 py-1 text-xs text-fg-muted`,children:y}),(0,z.jsx)(`div`,{className:`min-h-0 flex-1 pl-1`,children:d.model&&(0,z.jsx)(jt,{path:d.model.uri.toString(),defaultValue:d.model.getValue(),theme:`puddle`,keepCurrentModel:!0,saveViewState:!1,onMount:e=>{u(e),d.onMount(e),p(e),g(e)},loading:(0,z.jsx)(`div`,{className:`p-3 text-xs text-fg-muted`,children:`…`}),options:{cursorBlinking:l?`solid`:`blink`,cursorSmoothCaretAnimation:`off`,smoothScrolling:!1,automaticLayout:!0,fontFamily:m,fontSize:c.editorFontSize,...In(c.editorTabSize),wordWrap:c.editorWordWrap?`on`:`off`,minimap:{enabled:!1},glyphMargin:!1,lineNumbersMinChars:1,lineDecorationsWidth:5,fixedOverflowWidgets:!0,scrollBeyondLastLine:!1}})})]})}function B({children:e}){return(0,z.jsx)(`div`,{className:`flex h-full items-center justify-center px-4 text-xs text-fg-muted`,children:e})}function Er(e,t){let n=(0,R.useRef)(t);n.current=t,(0,R.useEffect)(()=>(kt(e),()=>{n.current?.(),Pt(e)}),[e])}function Dr(e,t,n,r){let i=r.split(`/`).map(encodeURIComponent).join(`/`);return`${e}://${encodeURIComponent(t)}/${encodeURIComponent(n)}/${i}`}function Or({session:e,refName:t,path:n,content:r}){let i=T(),a=Un([e,t,n]),o=(0,R.useMemo)(()=>getComputedStyle(document.documentElement).getPropertyValue(`--font-mono`).trim()||void 0,[]);return(0,z.jsx)(jt,{path:Dr(`puddle-view`,e,t,n),defaultValue:r,theme:At,saveViewState:!1,onMount:a,loading:(0,z.jsx)(B,{children:`…`}),options:{readOnly:!0,automaticLayout:!0,fontFamily:o,fontSize:i.editorFontSize,...In(i.editorTabSize),minimap:{enabled:!1},fixedOverflowWidgets:!0,scrollBeyondLastLine:!1}})}function kr({session:e,against:t,path:n,root:r,indexBase:i=!1}){let a=he(e,t,n,{root:r,enabled:!i}),o=ce(e,n,{root:r,enabled:i}),s=i?o:a;return s.isPending?(0,z.jsx)(B,{children:`…`}):s.error?(0,z.jsx)(B,{children:s.error instanceof Error?s.error.message:`Failed to load`}):s.data.binary?(0,z.jsx)(B,{children:`Binary file — deleted`}):(0,z.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,z.jsx)(`div`,{className:`bg-surface px-4 py-1 text-xs text-fg-muted`,children:`Deleted`}),(0,z.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,z.jsx)(Or,{session:e,refName:`${t}:${r??``}`,path:n,content:s.data.content??``})})]})}function Ar({session:e,against:t,path:n,basePath:r,root:i,indexBase:a=!1,focused:o=!0}){let s=T(),c=Wn([e,i,t,a,n]),l=dr(e,n,null,i,{focused:o}),u=he(e,t,r,{root:i,enabled:!a}),d=ce(e,r,{root:i,enabled:a}),f=a?d:u,p=(0,R.useRef)(null);Er(Rt(e,n,i),()=>{let e=p.current;if(!e)return;let t=e.getModel();e.setModel(null),t?.original.dispose(),p.current=null});let m=(0,R.useRef)(l.save);m.current=l.save;let h=(0,R.useMemo)(()=>getComputedStyle(document.documentElement).getPropertyValue(`--font-mono`).trim()||void 0,[]),g=f.error instanceof ie&&f.error.status===404;return l.conflict&&l.conflict.phase!==`unresolved`?(0,z.jsx)(Kn,{session:e,path:n,buffer:l,focused:o}):l.status===`binary`||f.data?.binary?(0,z.jsx)(B,{children:`Binary file`}):l.status===`too-large`?(0,z.jsx)(B,{children:`File too large to show`}):l.status===`error`?(0,z.jsx)(B,{children:l.errorMessage??`Failed to load file`}):g||a&&d.data&&!d.data.exists?(0,z.jsx)(Tr,{session:e,path:n,reveal:null,root:i,focused:o}):f.isPending||!l.model?(0,z.jsx)(B,{children:`…`}):f.error?(0,z.jsx)(B,{children:f.error instanceof Error?f.error.message:`Failed to load base`}):(0,z.jsx)(Ft,{modifiedModelPath:l.model.uri.toString(),originalModelPath:Dr(`puddle-base`,e,`${t}:${i??``}`,r),original:f.data.content??``,language:l.model.getLanguageId(),theme:At,keepCurrentModifiedModel:!0,loading:(0,z.jsx)(B,{children:`…`}),onMount:e=>{c(e),p.current=e,e.onDidDispose(()=>{p.current=null}),e.getModifiedEditor().addCommand(F.CtrlCmd|te.KeyS,()=>m.current())},options:{readOnly:!1,originalEditable:!1,renderSideBySide:!0,automaticLayout:!0,fontFamily:h,fontSize:s.editorFontSize,...In(s.editorTabSize),wordWrap:s.editorWordWrap?`on`:`off`,minimap:{enabled:!1},fixedOverflowWidgets:!0,scrollBeyondLastLine:!1}})}function jr({session:e,against:t,entry:n,root:r}){let i=T(),a=Wn([e,r,t,`staged`,n.path]),o=n.old_path??n.path,s=he(e,t,o,{root:r,enabled:n.status!==`added`}),c=ce(e,n.path,{root:r,enabled:n.status!==`deleted`}),l=(0,R.useMemo)(()=>getComputedStyle(document.documentElement).getPropertyValue(`--font-mono`).trim()||void 0,[]);if(n.status===`deleted`)return(0,z.jsx)(kr,{session:e,against:t,path:o,root:r});if(c.isPending||n.status!==`added`&&s.isPending)return(0,z.jsx)(B,{children:`…`});if(c.error||s.error){let e=c.error??s.error;return(0,z.jsx)(B,{children:e instanceof Error?e.message:`Failed to load staged content`})}return c.data.binary||s.data?.binary?(0,z.jsx)(B,{children:`Binary file`}):n.status===`added`?(0,z.jsx)(Or,{session:e,refName:`index:${r??``}`,path:n.path,content:c.data.content??``}):s.data?(0,z.jsx)(Ft,{originalModelPath:Dr(`puddle-head`,e,`${t}:${r??``}`,o),modifiedModelPath:Dr(`puddle-index`,e,`${t}:${r??``}`,n.path),original:s.data.content??``,modified:c.data.content??``,onMount:a,theme:At,loading:(0,z.jsx)(B,{children:`…`}),options:{readOnly:!0,originalEditable:!1,renderSideBySide:!0,automaticLayout:!0,fontFamily:l,fontSize:i.editorFontSize,...In(i.editorTabSize),wordWrap:i.editorWordWrap?`on`:`off`,minimap:{enabled:!1},fixedOverflowWidgets:!0,scrollBeyondLastLine:!1}}):(0,z.jsx)(B,{children:`Failed to load HEAD content`})}function Mr({session:e,path:t,root:n,focused:r}){return Er(Rt(e,t,n)),(0,z.jsx)(Tr,{session:e,path:t,reveal:null,root:n,focused:r})}function Nr({session:e,against:t,entry:n,root:r,area:i,focused:a=!0}){if(i===`staged`)return(0,z.jsx)(jr,{session:e,against:t,entry:n,root:r});switch(n.status){case`added`:return(0,z.jsx)(Mr,{session:e,path:n.path,root:r,focused:a});case`deleted`:return(0,z.jsx)(kr,{session:e,against:t,path:n.path,root:r,indexBase:i===`unstaged`});case`modified`:case`renamed`:return(0,z.jsx)(Ar,{session:e,against:t,path:n.path,basePath:n.old_path??n.path,root:r,indexBase:i===`unstaged`,focused:a});default:return null}}function Pr({session:e,sha:t,path:n,root:r}){let i=he(e,t,n,{root:r});return i.isPending?(0,z.jsx)(B,{children:`…`}):i.error?(0,z.jsx)(B,{children:i.error instanceof Error?i.error.message:`Failed to load file`}):i.data.binary?(0,z.jsx)(B,{children:`Binary file`}):(0,z.jsx)(Or,{session:e,refName:`${t}:${r??``}`,path:n,content:i.data.content??``})}function Fr({session:e,originalRef:t,originalPath:n,originalContent:r,modifiedRef:i,modifiedPath:a,modifiedContent:o,root:s}){let c=T(),l=Wn([e,s,t,n,i,a]),u=(0,R.useRef)(null),d=(0,R.useMemo)(()=>getComputedStyle(document.documentElement).getPropertyValue(`--font-mono`).trim()||void 0,[]);return(0,R.useEffect)(()=>()=>{let e=u.current;if(!e)return;let t=e.getModel();e.setModel(null),t?.original.dispose(),t?.modified.dispose(),u.current=null},[]),(0,z.jsx)(Ft,{originalModelPath:Dr(`puddle-hist-orig`,e,`${t}:${s??``}`,n),modifiedModelPath:Dr(`puddle-hist-mod`,e,`${i}:${s??``}`,a),original:r,modified:o,theme:At,keepCurrentOriginalModel:!0,keepCurrentModifiedModel:!0,loading:(0,z.jsx)(B,{children:`…`}),onMount:e=>{l(e),u.current=e,e.onDidDispose(()=>{u.current=null})},options:{readOnly:!0,originalEditable:!1,renderSideBySide:!0,automaticLayout:!0,fontFamily:d,fontSize:c.editorFontSize,...In(c.editorTabSize),minimap:{enabled:!1},fixedOverflowWidgets:!0,scrollBeyondLastLine:!1}})}function Ir({session:e,sha:t,path:n,basePath:r,root:i}){let a=he(e,`${t}^`,r,{root:i}),o=he(e,t,n,{root:i});return a.error instanceof ie&&a.error.status===404?(0,z.jsx)(Pr,{session:e,sha:t,path:n,root:i}):a.isPending||o.isPending?(0,z.jsx)(B,{children:`…`}):a.error?(0,z.jsx)(B,{children:a.error instanceof Error?a.error.message:`Failed to load original`}):o.error?(0,z.jsx)(B,{children:o.error instanceof Error?o.error.message:`Failed to load file`}):a.data.binary||o.data.binary?(0,z.jsx)(B,{children:`Binary file`}):(0,z.jsx)(Fr,{session:e,originalRef:`${t}^`,originalPath:r,originalContent:a.data.content??``,modifiedRef:t,modifiedPath:n,modifiedContent:o.data.content??``,root:i})}function Lr({session:e,sha:t,entry:n,isRootCommit:r,root:i}){switch(se(n.status,r)){case`added`:return(0,z.jsx)(Pr,{session:e,sha:t,path:n.path,root:i});case`deleted`:return(0,z.jsx)(kr,{session:e,against:`${t}^`,path:n.path,root:i});case`modified`:case`renamed`:return(0,z.jsx)(Ir,{session:e,sha:t,path:n.path,basePath:n.old_path??n.path,root:i});default:return null}}function Rr({session:e,sha:t,path:n,root:r}){let i=me(e,t,r);if(i.isPending)return(0,z.jsx)(`div`,{className:`px-4 py-3 text-xs text-fg-muted`,children:`Loading commit…`});if(i.error)return(0,z.jsx)(`div`,{className:`px-4 py-3 text-xs text-fg-muted`,children:i.error instanceof Error?i.error.message:`Failed to load commit`});let a=i.data.files.find(e=>e.path===n);return a?(0,z.jsx)(`div`,{className:`h-full`,children:(0,z.jsx)(Lr,{session:e,sha:t,entry:a,isRootCommit:i.data.parents.length===0,root:r})}):(0,z.jsxs)(`div`,{className:`flex h-full items-center justify-center px-4 text-center text-xs text-fg-muted`,children:[(0,z.jsx)(`span`,{className:`text-fg-secondary`,children:n}),` is not part of`,` `,(0,z.jsx)(`span`,{className:`font-mono`,children:t.slice(0,7)}),`.`]})}function zr({session:e,path:t,root:n,area:r,focused:i=!0}){let a=ge(e,{root:n,against:r===void 0?`base`:`head`,area:r});if(a.isPending)return(0,z.jsx)(`div`,{className:`px-4 py-3 text-xs text-fg-muted`,children:`Loading diff…`});if(a.error)return(0,z.jsx)(`div`,{className:`px-4 py-3 text-xs text-fg-muted`,children:a.error instanceof Error?a.error.message:`Failed to load diff`});let o=a.data.entries.find(e=>e.path===t);return o?(0,z.jsx)(`div`,{className:`h-full`,children:(0,z.jsx)(Nr,{session:e,against:a.data.against,entry:o,root:n,area:r,focused:i})}):(0,z.jsxs)(`div`,{className:`flex h-full items-center justify-center px-4 text-center text-xs text-fg-muted`,children:[`No changes to `,(0,z.jsx)(`span`,{className:`mx-1 text-fg-secondary`,children:t}),` against the base.`]})}var Br=800;function Vr({name:e}){let t=T(),n=mt(),r=Un([n,e]),i=pe(n,e),a=s(),o=dt(`editor.save`),c=(0,R.useRef)(null),l=(0,R.useRef)(null),u=(0,R.useMemo)(()=>getComputedStyle(document.documentElement).getPropertyValue(`--font-mono`).trim()||void 0,[]);if((0,R.useEffect)(()=>{if(n===null)return;let t=Dt(t=>{oe(n,e,t).catch(e=>L.error(e instanceof Error?e.message:`Draft not saved`))},Br);return l.current=t,()=>{t.flush(),l.current=null}},[n,e]),n===null)return null;if(i.error)return(0,z.jsx)(`div`,{className:`flex h-full items-center justify-center bg-ground text-sm text-fg-muted`,children:i.error instanceof Error?i.error.message:`Failed to load the draft`});if(i.data===void 0)return(0,z.jsx)(`div`,{className:`p-3 text-xs text-fg-muted`,children:`…`});let d=()=>{let t=c.current;t&&(l.current?.flush(),Fe({name:e,content:t.getValue()}))};return(0,z.jsxs)(`div`,{className:`flex h-full flex-col bg-ground`,children:[(0,z.jsxs)(`div`,{className:`bg-surface px-3 py-1 text-xs text-fg-muted`,children:[`Draft — not in any worktree; `,o,` saves it into one`]}),(0,z.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,z.jsx)(jt,{path:`puddle-untitled://${n}/${e}`,defaultValue:i.data.content,theme:At,keepCurrentModel:!1,saveViewState:!1,loading:(0,z.jsx)(`div`,{className:`p-3 text-xs text-fg-muted`,children:`…`}),onMount:t=>{r(t),c.current=t,ye(e,t.getValue()),sr(t,{onSave:d})},onChange:t=>{let r=t??``;ye(e,r),Ie(a,n,e,r),l.current?.(r)},options:{automaticLayout:!0,fontFamily:u,fontSize:t.editorFontSize,...In(t.editorTabSize),minimap:{enabled:!1},fixedOverflowWidgets:!0,scrollBeyondLastLine:!1,wordWrap:t.editorWordWrap?`on`:`off`}})})]})}var Hr=p([x(),_(x())]),Ur=y(x(),g()),Wr=m({output_type:x(),text:Hr.optional(),data:y(x(),g()).optional(),traceback:_(x()).optional(),ename:x().optional(),evalue:x().optional()}),Gr=m({id:x().optional(),cell_type:S([`code`,`markdown`,`raw`]),metadata:Ur,source:Hr,outputs:_(Wr).optional(),execution_count:f().int().nullable().optional()}),Kr=m({nbformat:b(4),nbformat_minor:f().int().nonnegative(),metadata:Ur,cells:_(Gr).max(2e3)});function qr(e){if(e.length>5*1024*1024)throw Error(`This notebook exceeds the 5 MiB editor limit.`);let t;try{t=JSON.parse(e)}catch{throw Error(`This notebook is not valid JSON. Switch to source to repair it.`)}let n=Kr.safeParse(t);if(!n.success)throw Error(`Expected a version 4 notebook with at most 2,000 valid cells. Switch to source to inspect it.`);return n.data}function V(e){return typeof e==`string`?e:Array.isArray(e)&&e.every(e=>typeof e==`string`)?e.join(``):``}function Jr(e,t,n){return{...e,cells:e.cells.map((e,r)=>r===t?{...e,source:n.match(/[^\n]*\n|[^\n]+$/g)??[],...e.cell_type===`code`&&e.outputs?.length&&!e.metadata.puddle_execution?{metadata:{...e.metadata,puddle_execution:{id:`saved`,revision:0,source:V(e.source),state:`saved`}}}:{}}:e)}}function Yr(e){let t=new Set;return{...e,cells:e.cells.map((n,r)=>{let i=n.id;if(!i||t.has(i))for(i=`puddle-${r}`;t.has(i)||e.cells.some(e=>e.id===i);)i+=`-`;return t.add(i),n.id===i?n:{...n,id:i}})}}function Xr(e,t){if(e.cell_type!==`code`)return e.cell_type===`raw`?`plaintext`:`markdown`;let n=e.metadata.vscode,r=t.metadata.language_info,i=t.metadata.kernelspec,a=n?.languageId??r?.name??i?.language??`python`;return typeof a==`string`?a:`python`}function Zr(e,t){let n=t===`markdown`||t===`raw`?t:`code`,r={...e,cell_type:n};return n===`code`?(r.metadata={...e.metadata,vscode:{...e.metadata.vscode??{},languageId:t}},r.outputs??=[],r.execution_count??=null):(delete r.outputs,delete r.execution_count),r}function Qr(e){return{id:crypto.randomUUID(),cell_type:e,metadata:{},source:[],...e===`code`?{outputs:[],execution_count:null}:{}}}function $r(e){return(e.output_type===`error`?e.traceback?.join(`
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/NotebookWidget-C25iz3Cj.js","assets/rolldown-runtime-QTnfLwEv.js","assets/react-CZI7_Jkm.js","assets/auth-C3ruG3fE.js","assets/context-D1MuDP6X.js","assets/protocol-support-BwRR1kRO.js","assets/jsx-runtime-By8HlURe.js","assets/api-CULxlzTe.js","assets/theme-swfNLod9.js","assets/preload-helper-Czpn1I53.js","assets/PdfViewer-BH-FXEVV.js","assets/createLucideIcon-C9A1vLE-.js","assets/dist-BOS6OKSE.js","assets/react-dom-cJyBB_A4.js","assets/control-tray-c9uXOo-i.js","assets/control-tray-CG26TqqQ.css","assets/view-state-store-DVvLMbeY.js","assets/scroll-restoration-wdDB8mmu.js","assets/PdfViewer-Re37jQgv.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{t}from"./react-CZI7_Jkm.js";import{Et as n,H as r,_ as i,g as a,h as o,kt as s,m as c,p as l,wt as u,x as d}from"./protocol-support-BwRR1kRO.js";import{at as f,ct as p,it as m,k as h,lt as g,nt as _,o as v,ot as y,rt as b,st as x,tt as S}from"./auth-C3ruG3fE.js";import{n as C,t as w}from"./context-D1MuDP6X.js";import{i as T,r as E,t as D}from"./client-settings-BdKglwtW.js";import{r as O,s as k}from"./theme-swfNLod9.js";import{t as A}from"./jsx-runtime-By8HlURe.js";import{t as j}from"./preload-helper-Czpn1I53.js";import{t as M}from"./purify.es-D8QhFVkO.js";import"./katex.min-ZqdHjttS.js";import{a as ee,c as N,h as P,i as F,p as I,r as te}from"./editor.api2-DTL_SiN1.js";import{n as ne,r as re,t as ie}from"./api-CULxlzTe.js";import{B as ae,C as oe,E as se,J as ce,K as le,O as ue,P as de,R as fe,T as pe,U as me,W as he,X as ge,Y as _e,Z as ve,_ as ye,a as be,at as xe,d as Se,i as Ce,it as we,j as Te,k as Ee,m as De,n as Oe,nt as ke,ot as Ae,r as je,rt as Me,st as Ne,u as Pe,v as Fe,w as Ie}from"./media-refresh-store-CYiYB60R.js";import{n as Le}from"./motion-Bd_MB9cH.js";import{t as Re}from"./createLucideIcon-C9A1vLE-.js";import{n as L}from"./dist-BOS6OKSE.js";import{i as ze,r as Be}from"./dist-Dac0re_p.js";import{n as Ve,r as He}from"./dist-BeQvHdsz.js";import{t as Ue}from"./arrow-down-CtYa-Aya.js";import{a as We,i as Ge,n as Ke,o as qe,r as Je,t as Ye}from"./select-CGxTz4dh.js";import{t as Xe}from"./chevron-down-HQLVE6o5.js";import{a as Ze,n as Qe,o as $e,r as et,t as tt}from"./FindWidget-Bh_7yWNg.js";import{t as nt}from"./copy-D0Theg4Q.js";import{t as rt}from"./rotate-ccw-BI2k_h3A.js";import{a as it,i as at,n as ot,o as st,r as ct,t as lt}from"./preview-kind-CPkO-rSz.js";import{t as ut}from"./x-DV6-RYI2.js";import{g as dt,t as ft,u as pt,y as mt}from"./ws-DV_MCpbg.js";import{t as ht}from"./control-tray-c9uXOo-i.js";import{a as gt,o as _t,r as vt,s as yt,t as bt}from"./command--8Svn0Z-.js";import{n as xt,r as St,t as Ct}from"./popover-D5HmbdQ7.js";import{i as wt,n as Tt,r as Et}from"./markdown-it-CWoG9_Dn.js";import{t as Dt}from"./debounce-B9DrqirV.js";import{a as Ot,c as kt,d as At,f as jt,i as Mt,l as Nt,o as Pt,p as Ft,r as It,s as Lt,t as Rt,u as zt}from"./buffer-store-Bh2IilxW.js";import{r as Bt,t as Vt}from"./view-state-store-DVvLMbeY.js";import{a as Ht,c as Ut,i as Wt,l as Gt,o as Kt,r as qt,s as Jt,t as Yt}from"./markdown-BlvTv1jG.js";import{i as Xt,n as Zt,r as Qt,t as $t}from"./drafts-B_tChlzR.js";import{r as en}from"./buffer-logic-BAkSBQT7.js";import{a as tn,i as nn,n as rn,o as an,r as on}from"./editor-sync-W1bamxAP.js";import{r as sn,t as cn}from"./math-CSw6sgCC.js";import{n as ln}from"./math-delimiters-BCnTi7Ii.js";import{n as un}from"./markdown-mermaid-TizVRNLQ.js";var dn=Re(`arrow-down-to-line`,[[`path`,{d:`M12 17V3`,key:`1cwfxf`}],[`path`,{d:`m6 11 6 6 6-6`,key:`12ii2o`}],[`path`,{d:`M19 21H5`,key:`150jfl`}]]),fn=Re(`arrow-up-to-line`,[[`path`,{d:`M5 3h14`,key:`7usisc`}],[`path`,{d:`m18 13-6-6-6 6`,key:`1kf1n9`}],[`path`,{d:`M12 7v14`,key:`1akyts`}]]),pn=Re(`combine`,[[`path`,{d:`M14 3a1 1 0 0 1 1 1v5a1 1 0 0 1-1 1`,key:`1l7d7l`}],[`path`,{d:`M19 3a1 1 0 0 1 1 1v5a1 1 0 0 1-1 1`,key:`9955pe`}],[`path`,{d:`m7 15 3 3`,key:`4hkfgk`}],[`path`,{d:`m7 21 3-3H5a2 2 0 0 1-2-2v-2`,key:`1xljwe`}],[`rect`,{x:`14`,y:`14`,width:`7`,height:`7`,rx:`1`,key:`1cdgtw`}],[`rect`,{x:`3`,y:`3`,width:`7`,height:`7`,rx:`1`,key:`zi3rio`}]]),mn=Re(`cpu`,[[`path`,{d:`M12 20v2`,key:`1lh1kg`}],[`path`,{d:`M12 2v2`,key:`tus03m`}],[`path`,{d:`M17 20v2`,key:`1rnc9c`}],[`path`,{d:`M17 2v2`,key:`11trls`}],[`path`,{d:`M2 12h2`,key:`1t8f8n`}],[`path`,{d:`M2 17h2`,key:`7oei6x`}],[`path`,{d:`M2 7h2`,key:`asdhe0`}],[`path`,{d:`M20 12h2`,key:`1q8mjw`}],[`path`,{d:`M20 17h2`,key:`1fpfkl`}],[`path`,{d:`M20 7h2`,key:`1o8tra`}],[`path`,{d:`M7 20v2`,key:`4gnj0m`}],[`path`,{d:`M7 2v2`,key:`1i4yhu`}],[`rect`,{x:`4`,y:`4`,width:`16`,height:`16`,rx:`2`,key:`1vbyd7`}],[`rect`,{x:`8`,y:`8`,width:`8`,height:`8`,rx:`1`,key:`z9xiuo`}]]),hn=Re(`list-tree`,[[`path`,{d:`M8 5h13`,key:`1pao27`}],[`path`,{d:`M13 12h8`,key:`h98zly`}],[`path`,{d:`M13 19h8`,key:`c3s6r1`}],[`path`,{d:`M3 10a2 2 0 0 0 2 2h3`,key:`1npucw`}],[`path`,{d:`M3 5v12a2 2 0 0 0 2 2h3`,key:`x1gjn2`}]]),R=e(t(),1),z=A();String.prototype.codePointAt;function gn(e,t){return function(n){let r,i=0,a=``;for(;r=e.exec(n);)i!==r.index&&(a+=n.substring(i,r.index)),a+=t.get(r[0].charCodeAt(0)),i=r.index+1;return a+n.substring(i)}}var _n=gn(/["&\u00A0]/g,new Map([[34,`"`],[38,`&`],[160,` `]])),vn=gn(/[&<>\u00A0]/g,new Map([[38,`&`],[60,`<`],[62,`>`],[160,` `]])),yn=new Map,bn=new Map,xn=1;function Sn(e){for(let t of bn.get(e)??[])t()}function Cn(e,t){yn.set(e,t),Sn(e)}function wn(e){let t={phase:`unresolved`,revision:xn++};return Cn(e,t),t}function Tn(e){let t=yn.get(e);return!t||t.phase!==`unresolved`&&t.phase!==`load-error`?null:(Cn(e,{phase:`loading`,revision:t.revision}),t.revision)}function En(e,t,n,r){let i=yn.get(e);return!i||i.phase!==`loading`||i.revision!==t?!1:(Cn(e,{phase:`opening`,revision:t,content:n,mtimeMs:r}),!0)}function Dn(e,t){let n=yn.get(e);return!n||n.phase!==`opening`||n.revision!==t?!1:(Cn(e,{...n,phase:`comparing`}),!0)}function On(e,t,n){let r=yn.get(e);return!r||r.phase!==`loading`||r.revision!==t?!1:(Cn(e,{phase:`load-error`,revision:t,message:n}),!0)}function kn(e,t){return t&&e?.phase===`unresolved`}function An(e){return e?.phase===`comparing`?e.mtimeMs:void 0}function jn(e){return e?.phase===`loading`||e?.phase===`load-error`||e?.phase===`opening`}function Mn(e){return e.phase===`opening`||e.phase===`comparing`}function Nn(e){yn.delete(e)&&Sn(e)}function Pn(e){return yn.get(e)??null}function Fn(e,t){let n=bn.get(e);return n||(n=new Set,bn.set(e,n)),n.add(t),()=>n.delete(t)}function In(e){return{tabSize:e,insertSpaces:!0,detectIndentation:!1}}var Ln=new Vt,Rn=new Vt;function zn(e){let t={...e.contributionsState};return delete t[`editor.contrib.wordHighlighter`],{...e,contributionsState:t}}function Bn(e,t){let n=(0,R.useRef)(null),r=(0,R.useRef)(null);return(0,R.useLayoutEffect)(()=>(n.current&&(r.current=t(n.current,e)),()=>{r.current?.(),r.current=null}),[e,t]),(0,R.useCallback)(i=>{r.current?.(),n.current=i,i.onDidDispose(()=>{n.current===i&&(n.current=null)}),r.current=t(i,e)},[e,t])}function Vn(e,t){let n=Ln.get(t);n&&e.restoreViewState(n);let r=()=>{if(!e.getModel())return;let n=e.saveViewState();n&&Ln.set(t,zn(n))},i=[e.onDidScrollChange(r),e.onDidChangeCursorSelection(r)];return()=>{r(),i.forEach(e=>e.dispose())}}function Hn(e,t){let n=Rn.get(t),r=n!==void 0,i=()=>{if(r||!e.getModel())return;let n=e.saveViewState();n&&Rn.set(t,{...n,original:n.original&&zn(n.original),modified:n.modified&&zn(n.modified)})};n&&e.restoreViewState(n);let a=[e.onDidUpdateDiff(()=>{r&&(r=!1,n&&e.restoreViewState(n))}),...[e.getOriginalEditor(),e.getModifiedEditor()].flatMap(e=>[e.onDidScrollChange(i),e.onDidChangeCursorSelection(i)])];return()=>{i(),a.forEach(e=>e.dispose())}}function Un(e){return Bn(Bt(`code`,e),Vn)}function Wn(e){return Bn(Bt(`diff`,e),Hn)}function Gn({session:e,path:t,conflict:n,model:r,onTakeDisk:i,onKeepMine:a,onSave:o,onReady:s}){let c=T(),l=Wn([`conflict`,r.uri.toString()]),u=(0,R.useId)(),d=(0,R.useMemo)(()=>getComputedStyle(document.documentElement).getPropertyValue(`--font-mono`).trim()||void 0,[]),f=(0,R.useRef)(o);f.current=o;let p=(0,R.useRef)(null),m=()=>{let e=p.current;if(!e)return;let t=e.getModel();e.setModel(null),t?.original.dispose(),p.current=null},h=(0,R.useRef)(m);return h.current=m,(0,R.useEffect)(()=>()=>h.current(),[]),(0,z.jsxs)(`div`,{className:`flex h-full flex-col bg-ground`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-3 bg-elevated px-3 py-1.5 text-xs text-fg-secondary`,children:[(0,z.jsx)(`span`,{children:`This file changed on disk. Yours is on the right — merge what you want, then save.`}),(0,z.jsx)(`button`,{type:`button`,onClick:i,className:`ml-auto shrink-0 text-fg-muted transition-colors hover:text-fg`,children:`Take the disk version`}),(0,z.jsx)(`button`,{type:`button`,onClick:a,disabled:n.phase!==`comparing`,className:`shrink-0 text-fg-muted transition-colors hover:text-fg`,children:`Keep mine`})]}),(0,z.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,z.jsx)(Ft,{modifiedModelPath:r.uri.toString(),originalModelPath:`puddle-disk://${encodeURIComponent(e)}/${n.mtimeMs}/${encodeURIComponent(u)}/${t.split(`/`).map(encodeURIComponent).join(`/`)}`,original:n.content,language:r.getLanguageId(),theme:At,keepCurrentModifiedModel:!0,loading:(0,z.jsx)(`div`,{className:`p-3 text-xs text-fg-muted`,children:`…`}),onMount:e=>{l(e),p.current=e,e.onDidDispose(()=>{p.current=null}),e.getModifiedEditor().addCommand(F.CtrlCmd|te.KeyS,()=>f.current()),s?.(n.revision)},options:{readOnly:n.phase!==`comparing`,originalEditable:!1,renderSideBySide:!0,automaticLayout:!0,fontFamily:d,fontSize:c.editorFontSize,...In(c.editorTabSize),wordWrap:c.editorWordWrap?`on`:`off`,minimap:{enabled:!1},fixedOverflowWidgets:!0,scrollBeyondLastLine:!1}})})]})}function Kn({session:e,path:t,buffer:n,focused:r}){let i=n.conflict;return!i||i.phase===`unresolved`?null:Mn(i)&&n.model?(0,z.jsx)(Gn,{session:e,path:t,conflict:i,model:n.model,onTakeDisk:n.takeDisk,onKeepMine:n.keepMine,onSave:n.save,onReady:r?n.comparisonReady:void 0}):i.phase===`load-error`?(0,z.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-3 bg-ground px-4 text-center text-sm text-fg-muted`,children:[(0,z.jsx)(`span`,{children:`The disk version could not be loaded.`}),(0,z.jsx)(`span`,{className:`max-w-lg text-xs text-fg-secondary`,children:i.message}),(0,z.jsx)(`button`,{type:`button`,onClick:n.compare,className:`rounded-md bg-elevated px-3 py-1.5 text-xs text-fg-secondary transition-colors hover:bg-border hover:text-fg`,children:`Retry compare`})]}):(0,z.jsx)(`div`,{className:`flex h-full items-center justify-center bg-ground text-sm text-fg-muted`,children:`Loading the disk version…`})}function qn(e){return Number.isFinite(e)?Math.min(1,Math.max(0,e)):0}function Jn(e,t,n){return qn(e/Math.max(1,t-n))}function Yn(e,t,n){return qn(e)*Math.max(0,t-n)}function Xn(e,t){return JSON.stringify([e,t.session,t.root??null,t.path])}var Zn=new class{positions=new Map;listeners=new Map;revision=0;publish(e,t,n,r=null){let i={ratio:qn(n),sourceLine:r!==null&&Number.isFinite(r)?Math.max(1,r):null,revision:++this.revision},a=Xn(e,t);this.positions.set(a,i);for(let e of this.listeners.get(a)??[])e(i);return i}get(e,t){return this.positions.get(Xn(e,t))}subscribe(e,t,n){let r=Xn(e,t),i=this.listeners.get(r);i||(i=new Set,this.listeners.set(r,i)),i.add(n);let a=this.positions.get(r);return a&&n(a),()=>{i?.delete(n),i?.size===0&&this.listeners.delete(r)}}},Qn=new Vt;function $n(e){let t=null;return{schedule:()=>{t===null&&(t=requestAnimationFrame(()=>{t=null,e()}))},dispose:()=>{t!==null&&cancelAnimationFrame(t),t=null}}}function er(e,t,n,r){let i=Math.max(0,t-n);if(e.ratio<=0)return 0;if(e.ratio>=1)return i;if(e.sourceLine!==null&&r){let t=Ut(r,e.sourceLine);if(t!==null)return Math.min(i,Math.max(0,t))}return Yn(e.ratio,t,n)}function tr(e,t){if(t.driver&&t.receiver)throw Error(`a preview scroll surface cannot be both driver and receiver`);let n=t.store??Zn,r=t.viewKey?Qn.get(t.viewKey):void 0,i=t.sourceAnchors?.(),a=()=>void 0,o,s=n=>{r=n,t.viewKey&&Qn.set(t.viewKey,n),e.scrollTop=er(n,e.scrollHeight,e.clientHeight,i)};r&&s(r);let c=()=>{if(e.clientHeight<=0)return;let a=Jn(e.scrollTop,e.scrollHeight,e.clientHeight),o=i?Gt(i,e.scrollTop):null;r={ratio:a,sourceLine:o,revision:0},t.viewKey&&Qn.set(t.viewKey,r),t.driver&&n.publish(t.channel,t.target,a,o)};t.receiver?a=n.subscribe(t.channel,t.target,s):(t.driver||t.viewKey)&&(o=$n(c),e.addEventListener(`scroll`,o.schedule,{passive:!0}),o.schedule());let l=new ResizeObserver(()=>{i=t.sourceAnchors?.(),r?s(r):o?.schedule()});for(let e of t.resizeElements??[])l.observe(e);return()=>{o&&(c(),e.removeEventListener(`scroll`,o.schedule)),a(),l.disconnect(),o?.dispose()}}function nr(e,t){let n=e.getModel()?.getLineCount()??0;if(n===0)return null;let r=1,i=n;for(;r<i;){let n=Math.ceil((r+i)/2);e.getTopForLineNumber(n)<=t?r=n:i=n-1}let a=e.getTopForLineNumber(r),o=r<n?e.getTopForLineNumber(r+1):e.getScrollHeight();return o<=a?r:r+Math.min(1,Math.max(0,(t-a)/(o-a)))}function rr(e,t){let n=e.getModel()?.getLineCount()??0;if(n===0||!Number.isFinite(t))return null;let r=Math.min(n+1,Math.max(1,t)),i=Math.floor(r);if(i>n)return e.getScrollHeight();let a=i+1,o=e.getTopForLineNumber(i),s=a<=n?e.getTopForLineNumber(a):e.getScrollHeight();return o+(r-i)*(s-o)}function ir(e,t,n){if(t.driver&&t.receiver)throw Error(`a Monaco scroll surface cannot be both driver and receiver`);let r=t.store??Zn,i=[],a,o=()=>void 0,s,c=()=>e.getLayoutInfo().height,l=t=>{a=t;let r=t.ratio>0&&t.ratio<1&&t.sourceLine!==null?rr(e,t.sourceLine):null;e.setScrollTop(r??er(t,e.getScrollHeight(),c()),n)};return t.receiver?(o=r.subscribe(t.channel,t.target,l),i.push(e.onDidChangeModel(()=>a&&l(a))),i.push(e.onDidLayoutChange(()=>a&&l(a))),i.push(e.onDidContentSizeChange(()=>a&&l(a)))):t.driver&&(s=$n(()=>{let n=Jn(e.getScrollTop(),e.getScrollHeight(),c());r.publish(t.channel,t.target,n,nr(e,e.getScrollTop()))}),i.push(e.onDidScrollChange(s.schedule)),i.push(e.onDidChangeModel(s.schedule)),i.push(e.onDidChangeModelContent(s.schedule)),i.push(e.onDidLayoutChange(s.schedule)),i.push(e.onDidContentSizeChange(s.schedule)),s.schedule()),()=>{o();for(let e of i)e.dispose();s?.dispose()}}function ar(e){return!e}function or(e){let t=e.split(`+`),n=t.pop()??``,r=0;for(let e of t)e===`meta`?r|=F.CtrlCmd:e===`ctrl`?r|=F.WinCtrl:e===`alt`?r|=F.Alt:e===`shift`&&(r|=F.Shift);let i=te[/^Key[A-Z]$/.test(n)?`Key${n.slice(3)}`:/^Digit[0-9]$/.test(n)?`Digit${n.slice(5)}`:n];return typeof i==`number`?r|i:null}function sr(e,t){let n=or(pt(`editor.save`));n!==null&&e.addCommand(n,()=>t.onSave());let r=or(pt(`editor.wordWrap`));e.addAction({id:`puddle.toggleWordWrap`,label:`Toggle Word Wrap`,keybindings:r===null?[]:[r],run:()=>E({editorWordWrap:ar(D().editorWordWrap)})})}var cr=new WeakSet;function lr(e){return cr.has(e)?!1:(cr.add(e),!0)}function ur(e){return`file-conflict:${e}`}function dr(e,t,n,r,i){let a=i?.passive===!0,o=i?.focused??!0,s=Rt(e,t,r),c=ve(e,t,{root:r,live:i?.live}),l=_e(e,r),[u,d]=(0,R.useState)(null),[f,p]=(0,R.useState)(!1),m=(0,R.useRef)(!1),h=(0,R.useRef)(null),g=(0,R.useRef)(null),_=(0,R.useRef)(n);_.current=n;let v=(0,R.useRef)(!1),y=(0,R.useCallback)((e,t)=>{g.current?.cancel(),v.current=!0;try{Lt(s,e,t)}finally{v.current=!1}},[s]),b=(0,R.useSyncExternalStore)((0,R.useCallback)(e=>zt(s,e),[s]),()=>Mt(s)),x=(0,R.useSyncExternalStore)((0,R.useCallback)(e=>an(s,e),[s]),()=>tn(s)),S=(0,R.useSyncExternalStore)((0,R.useCallback)(e=>Fn(s,e),[s]),()=>Pn(s));(0,R.useEffect)(()=>{let n=c.data;if(!n||n.binary||n.content===null||m.current)return;m.current=!0;let i=Nt(s)!==void 0,a=It(e,t,n.content,n.mtime_ms,r),o=a.getValue();d(a),!i&&Xt(e,t,r).then(i=>{if(!i)return;let s=Zt(i,o,n.mtime_ms);s===`discard`?$t(e,t,r):s===`restore`?en(a,i.content)&&p(!0):L(`This file has an unsaved draft from an earlier version.`,{description:`The file changed on disk since the draft was saved.`,duration:12e3,action:{label:`Restore draft`,onClick:()=>{en(a,i.content)&&p(!0)}}})})},[c.data,s,e,t,r]),(0,R.useEffect)(()=>{if(!u||a)return;let n=Qt(e,t,r);g.current=n;let i=u.onDidChangeContent(()=>{v.current||(n(u.getValue(),Nt(s)??0),rn(e,t,r))});return()=>{n.flush(),i.dispose(),g.current=null}},[u,s,e,t,r,a]),(0,R.useEffect)(()=>{!u||!x.savedElsewhere||Mt(s)||c.refetch().then(e=>{Mt(s)||(e.data&&e.data.content!==null&&y(e.data.content,e.data.mtime_ms),nn(s))})},[x.savedElsewhere,u,s]),(0,R.useEffect)(()=>{let e=c.data;!u||!e||e.content===null||!Mt(s)&&e.mtime_ms!==Nt(s)&&y(e.content,e.mtime_ms)},[c.data,u,s]);let C=(0,R.useCallback)((n,i)=>{Ot(s,n,i),g.current?.cancel(),$t(e,t,r),on(e,t,i,r),p(!1),Nn(s)},[s,e,t,r]),w=(0,R.useCallback)(()=>{let e=Tn(s);e!==null&&(L.dismiss(ur(s)),c.refetch({throwOnError:!0}).then(t=>{let n=t.data;if(!n)throw Error(`The disk version did not load.`);if(n.content===null)throw Error(`The file on disk is binary and cannot be compared as text.`);En(s,e,n.content,n.mtime_ms)}).catch(t=>{On(s,e,t instanceof Error?t.message:`The disk version did not load.`)}))},[c,s]),T=(0,R.useRef)(w);T.current=w,(0,R.useEffect)(()=>{if(!kn(S,o))return;let e=ur(s);return L(`File changed on disk`,{id:e,description:`Nothing was written — your unsaved version is intact.`,duration:1/0,closeButton:!0,action:{label:`Compare`,onClick:()=>T.current()}}),()=>{L.dismiss(e)}},[S,o,s]);let E=(0,R.useCallback)(()=>{c.refetch().then(n=>{n.data&&n.data.content!==null&&y(n.data.content,n.data.mtime_ms),$t(e,t,r),p(!1),Nn(s)})},[s,e,t,y]),D=(0,R.useCallback)((e,n)=>{l.mutate({path:t,content:e},{onSuccess:e=>C(n,e.mtime_ms),onError:e=>L.error(e instanceof Error?e.message:`Overwrite failed`)})},[l,t,C]),O=(0,R.useCallback)(async()=>{if(!u||!Mt(s))return!0;let e=u.getValue(),n=u.getAlternativeVersionId();if(jn(Pn(s)))return!1;let r=An(Pn(s))??Nt(s);try{let i=await l.mutateAsync({path:t,content:e,expected_mtime_ms:r});return C(n,i.mtime_ms),!0}catch(e){return e instanceof ie&&e.status===409&&e.code===`stale_file`?wn(s):L.error(e instanceof Error?e.message:`Save failed`),!1}},[u,s,l,t,C]),k=(0,R.useRef)(O);k.current=O,(0,R.useEffect)(()=>ue(Te(e,t,r),()=>k.current(),{session:e,path:t,...r===void 0?{}:{root:r}}),[e,t,r]);let A=(0,R.useCallback)(()=>{let n=h.current,i=_.current;!n||!i||!o||i.session!==e||i.path!==t||(i.root??void 0)!==(r??void 0)||lr(i)&&(n.revealLineInCenter(i.line),n.setPosition({lineNumber:i.line,column:i.column??1}),n.focus())},[e,t,r,o]),j=(0,R.useCallback)(e=>{h.current=e,sr(e,{onSave:()=>k.current()}),A()},[A]);(0,R.useEffect)(()=>{A()},[n,u,A]);let M=(0,R.useCallback)(()=>{E()},[E]),ee=(0,R.useCallback)(()=>{!u||Pn(s)?.phase!==`comparing`||D(u.getValue(),u.getAlternativeVersionId())},[u,s,D]),N=(0,R.useCallback)(e=>{Dn(s,e)},[s]),P,F=null;c.data?.binary?P=`binary`:c.error?c.error instanceof ie&&c.error.status===413?P=`too-large`:(P=`error`,F=c.error instanceof Error?c.error.message:`Failed to load file`):P=u?`ready`:`loading`;let I=b&&x.savedElsewhere?`saved-elsewhere`:b&&x.dirtyElsewhere?`dirty-elsewhere`:null;return{status:P,errorMessage:F,model:u,dirty:b,restoredNotice:f,discardRestore:M,peerBadge:I,conflict:S,takeDisk:E,keepMine:ee,compare:w,comparisonReady:N,save:O,onMount:j}}function fr(e,t,n,r){for(let i of e)if(_r([i],n).some(e=>(r===void 0||e.kind===r)&&t>=e.startLineNumber&&t<=e.endLineNumber))return i;return null}function pr(e,t){return hr(e.modifiedStartLineNumber,e.modifiedEndLineNumber)>0?Math.min(t,e.modifiedEndLineNumber):Math.max(0,Math.min(t,e.modifiedStartLineNumber-1))}function mr(e){let t=hr(e.originalStartLineNumber,e.originalEndLineNumber),n=hr(e.modifiedStartLineNumber,e.modifiedEndLineNumber);return Math.max(5,Math.min(14,t+n+4))}function hr(e,t){return t===0?0:Math.max(0,t-e+1)}function gr(e,t){if(e>t)return{startLineNumber:Math.max(1,t),endLineNumber:Math.max(1,t),kind:`deleted-after`};let n=Math.max(1,e);return{startLineNumber:n,endLineNumber:n,kind:`deleted-before`}}function _r(e,t){let n=[];for(let r of e){let e=hr(r.originalStartLineNumber,r.originalEndLineNumber),i=hr(r.modifiedStartLineNumber,r.modifiedEndLineNumber);if(e===0&&i>0){n.push({startLineNumber:r.modifiedStartLineNumber,endLineNumber:r.modifiedEndLineNumber,kind:`added`});continue}if(i===0&&e>0){n.push(gr(r.modifiedStartLineNumber,t));continue}let a=Math.min(e,i);a>0&&n.push({startLineNumber:r.modifiedStartLineNumber,endLineNumber:r.modifiedStartLineNumber+a-1,kind:`modified`}),i>a&&n.push({startLineNumber:r.modifiedStartLineNumber+a,endLineNumber:r.modifiedEndLineNumber,kind:`added`}),e>a&&n.push(gr(r.modifiedStartLineNumber+i,t))}return n}var vr=28,yr=[[`puddle-dirty-added`,`added`],[`puddle-dirty-modified`,`modified`],[`puddle-dirty-deleted-before`,`deleted-before`],[`puddle-dirty-deleted-after`,`deleted-after`]];function br(e){if(e){for(let[t,n]of yr)if(e.classList.contains(t)||e.closest(`.${t}`))return n}}function xr({editor:e,original:t,modified:n,path:r}){let i=[],a=null,o=!1,s=t=>{try{e.changeViewZones(e=>e.removeZone(t))}catch{}},c=()=>{let e=a;e&&(a=null,e.frame!==null&&cancelAnimationFrame(e.frame),e.diffEditor&&(e.diffEditor.setModel(null),e.diffEditor.dispose()),s(e.zoneId))},l=e=>{let t=e.diffEditor;if(!t)return;let r=Math.max(1,Math.min(n.getLineCount(),e.change.modifiedStartLineNumber));t.getModifiedEditor().revealLineInCenter(r,I.ScrollType.Immediate)},u=(i,s)=>{if(a?.anchorLine===i){c();return}c();let u=e.getOption(I.EditorOption.lineHeight),d=document.createElement(`div`);d.className=`puddle-dirty-peek`;let f=document.createElement(`div`);f.className=`puddle-dirty-peek-header`;let p=document.createElement(`span`);p.className=`puddle-dirty-peek-title`,p.textContent=`${r.split(`/`).pop()??r} · Local changes against HEAD`;let m=document.createElement(`button`);m.type=`button`,m.className=`puddle-dirty-peek-close`,m.setAttribute(`aria-label`,`Close inline change`),m.title=`Close inline change`,m.textContent=`×`,m.addEventListener(`pointerdown`,e=>{e.preventDefault(),e.stopPropagation(),c()}),m.addEventListener(`click`,e=>{e.preventDefault(),e.stopPropagation(),c()});let h=document.createElement(`div`);h.className=`puddle-dirty-peek-editor`,f.append(p,m),d.append(f,h);let g=document.createElement(`div`);g.className=`puddle-dirty-peek-margin`;let _={afterLineNumber:pr(s,n.getLineCount()),heightInPx:vr+mr(s)*u,domNode:d,marginDomNode:g,suppressMouseDown:!1},v=``;e.changeViewZones(e=>{v=e.addZone(_)});let y={anchorLine:i,change:s,zone:_,zoneId:v,frame:null,diffEditor:null};a=y,y.frame=requestAnimationFrame(()=>{if(y.frame=null,o||a!==y)return;let r=I.createDiffEditor(h,{readOnly:!0,domReadOnly:!0,originalEditable:!1,renderSideBySide:!1,renderMarginRevertIcon:!1,renderOverviewRuler:!1,enableSplitViewResizing:!1,isInEmbeddedEditor:!0,automaticLayout:!0,fontFamily:e.getOption(I.EditorOption.fontFamily),fontSize:e.getOption(I.EditorOption.fontSize),lineHeight:u,minimap:{enabled:!1},glyphMargin:!1,folding:!1,scrollBeyondLastLine:!1,fixedOverflowWidgets:!0,hideUnchangedRegions:{enabled:!0,minimumLineCount:0,contextLineCount:2,revealLineCount:3}});y.diffEditor=r,r.setModel({original:t,modified:n}),r.onDidUpdateDiff(()=>l(y)),l(y)}),e.revealLineInCenter(Math.max(1,Math.min(n.getLineCount(),s.modifiedStartLineNumber)))},d=e.onMouseDown(e=>{if(!e.event.leftButton||e.target.type!==I.MouseTargetType.GUTTER_LINE_DECORATIONS||e.target.position===null)return;let t=e.target.position.lineNumber,r=fr(i,t,n.getLineCount(),br(e.target.element));r&&(e.event.preventDefault(),e.event.stopPropagation(),u(t,r))});return{update(t){if(i=t,!a)return;let r=a,o=fr(t,r.anchorLine,n.getLineCount());if(!o){c();return}r.change=o,r.zone.afterLineNumber=pr(o,n.getLineCount()),r.zone.heightInPx=vr+mr(o)*e.getOption(I.EditorOption.lineHeight);try{e.changeViewZones(e=>e.layoutZone(r.zoneId))}catch{c();return}l(r)},dispose(){o=!0,d.dispose(),c()}}}var Sr={added:`puddle-dirty-added`,modified:`puddle-dirty-modified`,"deleted-before":`puddle-dirty-deleted-before`,"deleted-after":`puddle-dirty-deleted-after`};function Cr(e,t,n,i){let a=r(),o=le(e,t,{root:n,enabled:a.data!==void 0&&d(a.data.protocol)&&i!==null}),[s,c]=(0,R.useState)(null),l=(0,R.useCallback)(e=>{c(e)},[]);return(0,R.useLayoutEffect)(()=>{let e=o.data;if(!s||!i||!e||e.repository===null||e.ignored||e.binary)return;let n=document.createElement(`div`);n.className=`puddle-hidden-diff-controller`,document.body.appendChild(n);let r=I.createModel(e.exists?e.content??``:``,i.getLanguageId()),a=I.createDiffEditor(n,{readOnly:!0,automaticLayout:!1,renderSideBySide:!1,minimap:{enabled:!1}}),c=s.createDecorationsCollection();a.setModel({original:r,modified:i});let l=xr({editor:s,original:r,modified:i,path:t}),u=()=>{let e=a.getLineChanges();e&&(l.update(e),c.set(_r(e,i.getLineCount()).map(e=>({range:new N(e.startLineNumber,1,e.endLineNumber,1),options:{isWholeLine:!0,linesDecorationsClassName:Sr[e.kind]}}))))},d=a.onDidUpdateDiff(u);return u(),()=>{d.dispose(),l.dispose(),c.clear(),a.setModel(null),a.dispose(),r.dispose(),n.remove()}},[s,i,o.data]),l}function wr({message:e,session:t,path:n,root:r,download:i}){return(0,z.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-3 bg-ground text-sm text-fg-muted`,children:[(0,z.jsx)(`span`,{children:e}),i&&(0,z.jsxs)(`button`,{type:`button`,onClick:()=>void fe(t,n,r).catch(e=>L.error(e instanceof Error?e.message:`Download failed`)),className:`flex items-center gap-1.5 text-fg-secondary transition-colors hover:text-fg`,children:[(0,z.jsx)(Ae,{className:`size-4`}),`Download`]})]})}function Tr({session:e,path:t,reveal:n,root:r,focused:i=!0,scrollDriver:a=!1,scrollReceiver:o=!1,scrollChannel:s=`profile`}){let c=T(),l=Le(),u=Un([e,r,t]),d=dr(e,t,n,r,{focused:i}),f=de(e,t,r),p=Cr(e,t,r,d.model),m=(0,R.useMemo)(()=>getComputedStyle(document.documentElement).getPropertyValue(`--font-mono`).trim()||void 0,[]),[h,g]=(0,R.useState)(null),_=(0,R.useMemo)(()=>({session:e,path:t,root:r}),[e,t,r]),v=d.conflict!==null&&d.conflict.phase!==`unresolved`;if((0,R.useEffect)(()=>{if(!(!h||!d.model||v))return ir(h,{channel:s,target:_,driver:a,receiver:o},I.ScrollType.Immediate)},[h,d.model,v,s,_,a,o]),(0,R.useEffect)(()=>{let e=d.model;e&&I.setModelMarkers(e,`puddle-compilation`,f.map(t=>{let n=Math.min(t.line,e.getLineCount()),r=e.getLineMaxColumn(n),i=Math.min(t.column??1,r),a=t.end_line??n,o=Math.max(n,Math.min(a,e.getLineCount())),s=e.getLineMaxColumn(o),c=Math.min(t.end_column??(t.column?i+1:s),s);return{severity:t.severity===`error`?ee.Error:t.severity===`warning`?ee.Warning:ee.Info,message:t.message,source:`Puddle compilation`,startLineNumber:n,startColumn:i,endLineNumber:o,endColumn:Math.max(i,c)}}))},[d.model,f]),d.conflict&&d.conflict.phase!==`unresolved`)return(0,z.jsx)(Kn,{session:e,path:t,buffer:d,focused:i});if(d.status===`binary`)return(0,z.jsx)(wr,{message:`Binary file — use Download`,session:e,path:t,root:r,download:!0});if(d.status===`too-large`)return(0,z.jsx)(wr,{message:`File too large to edit — use Download`,session:e,path:t,root:r,download:!0});if(d.status===`error`)return(0,z.jsx)(wr,{message:d.errorMessage??`Failed to load file`,session:e,path:t,root:r});let y=d.peerBadge===`saved-elsewhere`?`Saved in another window`:d.peerBadge===`dirty-elsewhere`?`Also being edited in another window`:null;return(0,z.jsxs)(`div`,{className:`flex h-full flex-col bg-ground`,children:[d.restoredNotice&&(0,z.jsxs)(`div`,{className:`flex items-center gap-3 bg-elevated px-3 py-1.5 text-xs text-fg-secondary`,children:[(0,z.jsx)(`span`,{children:`Restored unsaved changes`}),(0,z.jsx)(`button`,{type:`button`,onClick:d.discardRestore,className:`text-fg-muted transition-colors hover:text-fg`,children:`Discard`})]}),y&&(0,z.jsx)(`div`,{className:`bg-surface px-3 py-1 text-xs text-fg-muted`,children:y}),(0,z.jsx)(`div`,{className:`min-h-0 flex-1 pl-1`,children:d.model&&(0,z.jsx)(jt,{path:d.model.uri.toString(),defaultValue:d.model.getValue(),theme:`puddle`,keepCurrentModel:!0,saveViewState:!1,onMount:e=>{u(e),d.onMount(e),p(e),g(e)},loading:(0,z.jsx)(`div`,{className:`p-3 text-xs text-fg-muted`,children:`…`}),options:{cursorBlinking:l?`solid`:`blink`,cursorSmoothCaretAnimation:`off`,smoothScrolling:!1,automaticLayout:!0,fontFamily:m,fontSize:c.editorFontSize,...In(c.editorTabSize),wordWrap:c.editorWordWrap?`on`:`off`,minimap:{enabled:!1},glyphMargin:!1,lineNumbersMinChars:1,lineDecorationsWidth:5,fixedOverflowWidgets:!0,scrollBeyondLastLine:!1}})})]})}function B({children:e}){return(0,z.jsx)(`div`,{className:`flex h-full items-center justify-center px-4 text-xs text-fg-muted`,children:e})}function Er(e,t){let n=(0,R.useRef)(t);n.current=t,(0,R.useEffect)(()=>(kt(e),()=>{n.current?.(),Pt(e)}),[e])}function Dr(e,t,n,r){let i=r.split(`/`).map(encodeURIComponent).join(`/`);return`${e}://${encodeURIComponent(t)}/${encodeURIComponent(n)}/${i}`}function Or({session:e,refName:t,path:n,content:r}){let i=T(),a=Un([e,t,n]),o=(0,R.useMemo)(()=>getComputedStyle(document.documentElement).getPropertyValue(`--font-mono`).trim()||void 0,[]);return(0,z.jsx)(jt,{path:Dr(`puddle-view`,e,t,n),defaultValue:r,theme:At,saveViewState:!1,onMount:a,loading:(0,z.jsx)(B,{children:`…`}),options:{readOnly:!0,automaticLayout:!0,fontFamily:o,fontSize:i.editorFontSize,...In(i.editorTabSize),minimap:{enabled:!1},fixedOverflowWidgets:!0,scrollBeyondLastLine:!1}})}function kr({session:e,against:t,path:n,root:r,indexBase:i=!1}){let a=he(e,t,n,{root:r,enabled:!i}),o=ce(e,n,{root:r,enabled:i}),s=i?o:a;return s.isPending?(0,z.jsx)(B,{children:`…`}):s.error?(0,z.jsx)(B,{children:s.error instanceof Error?s.error.message:`Failed to load`}):s.data.binary?(0,z.jsx)(B,{children:`Binary file — deleted`}):(0,z.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,z.jsx)(`div`,{className:`bg-surface px-4 py-1 text-xs text-fg-muted`,children:`Deleted`}),(0,z.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,z.jsx)(Or,{session:e,refName:`${t}:${r??``}`,path:n,content:s.data.content??``})})]})}function Ar({session:e,against:t,path:n,basePath:r,root:i,indexBase:a=!1,focused:o=!0}){let s=T(),c=Wn([e,i,t,a,n]),l=dr(e,n,null,i,{focused:o}),u=he(e,t,r,{root:i,enabled:!a}),d=ce(e,r,{root:i,enabled:a}),f=a?d:u,p=(0,R.useRef)(null);Er(Rt(e,n,i),()=>{let e=p.current;if(!e)return;let t=e.getModel();e.setModel(null),t?.original.dispose(),p.current=null});let m=(0,R.useRef)(l.save);m.current=l.save;let h=(0,R.useMemo)(()=>getComputedStyle(document.documentElement).getPropertyValue(`--font-mono`).trim()||void 0,[]),g=f.error instanceof ie&&f.error.status===404;return l.conflict&&l.conflict.phase!==`unresolved`?(0,z.jsx)(Kn,{session:e,path:n,buffer:l,focused:o}):l.status===`binary`||f.data?.binary?(0,z.jsx)(B,{children:`Binary file`}):l.status===`too-large`?(0,z.jsx)(B,{children:`File too large to show`}):l.status===`error`?(0,z.jsx)(B,{children:l.errorMessage??`Failed to load file`}):g||a&&d.data&&!d.data.exists?(0,z.jsx)(Tr,{session:e,path:n,reveal:null,root:i,focused:o}):f.isPending||!l.model?(0,z.jsx)(B,{children:`…`}):f.error?(0,z.jsx)(B,{children:f.error instanceof Error?f.error.message:`Failed to load base`}):(0,z.jsx)(Ft,{modifiedModelPath:l.model.uri.toString(),originalModelPath:Dr(`puddle-base`,e,`${t}:${i??``}`,r),original:f.data.content??``,language:l.model.getLanguageId(),theme:At,keepCurrentModifiedModel:!0,loading:(0,z.jsx)(B,{children:`…`}),onMount:e=>{c(e),p.current=e,e.onDidDispose(()=>{p.current=null}),e.getModifiedEditor().addCommand(F.CtrlCmd|te.KeyS,()=>m.current())},options:{readOnly:!1,originalEditable:!1,renderSideBySide:!0,automaticLayout:!0,fontFamily:h,fontSize:s.editorFontSize,...In(s.editorTabSize),wordWrap:s.editorWordWrap?`on`:`off`,minimap:{enabled:!1},fixedOverflowWidgets:!0,scrollBeyondLastLine:!1}})}function jr({session:e,against:t,entry:n,root:r}){let i=T(),a=Wn([e,r,t,`staged`,n.path]),o=n.old_path??n.path,s=he(e,t,o,{root:r,enabled:n.status!==`added`}),c=ce(e,n.path,{root:r,enabled:n.status!==`deleted`}),l=(0,R.useMemo)(()=>getComputedStyle(document.documentElement).getPropertyValue(`--font-mono`).trim()||void 0,[]);if(n.status===`deleted`)return(0,z.jsx)(kr,{session:e,against:t,path:o,root:r});if(c.isPending||n.status!==`added`&&s.isPending)return(0,z.jsx)(B,{children:`…`});if(c.error||s.error){let e=c.error??s.error;return(0,z.jsx)(B,{children:e instanceof Error?e.message:`Failed to load staged content`})}return c.data.binary||s.data?.binary?(0,z.jsx)(B,{children:`Binary file`}):n.status===`added`?(0,z.jsx)(Or,{session:e,refName:`index:${r??``}`,path:n.path,content:c.data.content??``}):s.data?(0,z.jsx)(Ft,{originalModelPath:Dr(`puddle-head`,e,`${t}:${r??``}`,o),modifiedModelPath:Dr(`puddle-index`,e,`${t}:${r??``}`,n.path),original:s.data.content??``,modified:c.data.content??``,onMount:a,theme:At,loading:(0,z.jsx)(B,{children:`…`}),options:{readOnly:!0,originalEditable:!1,renderSideBySide:!0,automaticLayout:!0,fontFamily:l,fontSize:i.editorFontSize,...In(i.editorTabSize),wordWrap:i.editorWordWrap?`on`:`off`,minimap:{enabled:!1},fixedOverflowWidgets:!0,scrollBeyondLastLine:!1}}):(0,z.jsx)(B,{children:`Failed to load HEAD content`})}function Mr({session:e,path:t,root:n,focused:r}){return Er(Rt(e,t,n)),(0,z.jsx)(Tr,{session:e,path:t,reveal:null,root:n,focused:r})}function Nr({session:e,against:t,entry:n,root:r,area:i,focused:a=!0}){if(i===`staged`)return(0,z.jsx)(jr,{session:e,against:t,entry:n,root:r});switch(n.status){case`added`:return(0,z.jsx)(Mr,{session:e,path:n.path,root:r,focused:a});case`deleted`:return(0,z.jsx)(kr,{session:e,against:t,path:n.path,root:r,indexBase:i===`unstaged`});case`modified`:case`renamed`:return(0,z.jsx)(Ar,{session:e,against:t,path:n.path,basePath:n.old_path??n.path,root:r,indexBase:i===`unstaged`,focused:a});default:return null}}function Pr({session:e,sha:t,path:n,root:r}){let i=he(e,t,n,{root:r});return i.isPending?(0,z.jsx)(B,{children:`…`}):i.error?(0,z.jsx)(B,{children:i.error instanceof Error?i.error.message:`Failed to load file`}):i.data.binary?(0,z.jsx)(B,{children:`Binary file`}):(0,z.jsx)(Or,{session:e,refName:`${t}:${r??``}`,path:n,content:i.data.content??``})}function Fr({session:e,originalRef:t,originalPath:n,originalContent:r,modifiedRef:i,modifiedPath:a,modifiedContent:o,root:s}){let c=T(),l=Wn([e,s,t,n,i,a]),u=(0,R.useRef)(null),d=(0,R.useMemo)(()=>getComputedStyle(document.documentElement).getPropertyValue(`--font-mono`).trim()||void 0,[]);return(0,R.useEffect)(()=>()=>{let e=u.current;if(!e)return;let t=e.getModel();e.setModel(null),t?.original.dispose(),t?.modified.dispose(),u.current=null},[]),(0,z.jsx)(Ft,{originalModelPath:Dr(`puddle-hist-orig`,e,`${t}:${s??``}`,n),modifiedModelPath:Dr(`puddle-hist-mod`,e,`${i}:${s??``}`,a),original:r,modified:o,theme:At,keepCurrentOriginalModel:!0,keepCurrentModifiedModel:!0,loading:(0,z.jsx)(B,{children:`…`}),onMount:e=>{l(e),u.current=e,e.onDidDispose(()=>{u.current=null})},options:{readOnly:!0,originalEditable:!1,renderSideBySide:!0,automaticLayout:!0,fontFamily:d,fontSize:c.editorFontSize,...In(c.editorTabSize),minimap:{enabled:!1},fixedOverflowWidgets:!0,scrollBeyondLastLine:!1}})}function Ir({session:e,sha:t,path:n,basePath:r,root:i}){let a=he(e,`${t}^`,r,{root:i}),o=he(e,t,n,{root:i});return a.error instanceof ie&&a.error.status===404?(0,z.jsx)(Pr,{session:e,sha:t,path:n,root:i}):a.isPending||o.isPending?(0,z.jsx)(B,{children:`…`}):a.error?(0,z.jsx)(B,{children:a.error instanceof Error?a.error.message:`Failed to load original`}):o.error?(0,z.jsx)(B,{children:o.error instanceof Error?o.error.message:`Failed to load file`}):a.data.binary||o.data.binary?(0,z.jsx)(B,{children:`Binary file`}):(0,z.jsx)(Fr,{session:e,originalRef:`${t}^`,originalPath:r,originalContent:a.data.content??``,modifiedRef:t,modifiedPath:n,modifiedContent:o.data.content??``,root:i})}function Lr({session:e,sha:t,entry:n,isRootCommit:r,root:i}){switch(se(n.status,r)){case`added`:return(0,z.jsx)(Pr,{session:e,sha:t,path:n.path,root:i});case`deleted`:return(0,z.jsx)(kr,{session:e,against:`${t}^`,path:n.path,root:i});case`modified`:case`renamed`:return(0,z.jsx)(Ir,{session:e,sha:t,path:n.path,basePath:n.old_path??n.path,root:i});default:return null}}function Rr({session:e,sha:t,path:n,root:r}){let i=me(e,t,r);if(i.isPending)return(0,z.jsx)(`div`,{className:`px-4 py-3 text-xs text-fg-muted`,children:`Loading commit…`});if(i.error)return(0,z.jsx)(`div`,{className:`px-4 py-3 text-xs text-fg-muted`,children:i.error instanceof Error?i.error.message:`Failed to load commit`});let a=i.data.files.find(e=>e.path===n);return a?(0,z.jsx)(`div`,{className:`h-full`,children:(0,z.jsx)(Lr,{session:e,sha:t,entry:a,isRootCommit:i.data.parents.length===0,root:r})}):(0,z.jsxs)(`div`,{className:`flex h-full items-center justify-center px-4 text-center text-xs text-fg-muted`,children:[(0,z.jsx)(`span`,{className:`text-fg-secondary`,children:n}),` is not part of`,` `,(0,z.jsx)(`span`,{className:`font-mono`,children:t.slice(0,7)}),`.`]})}function zr({session:e,path:t,root:n,area:r,focused:i=!0}){let a=ge(e,{root:n,against:r===void 0?`base`:`head`,area:r});if(a.isPending)return(0,z.jsx)(`div`,{className:`px-4 py-3 text-xs text-fg-muted`,children:`Loading diff…`});if(a.error)return(0,z.jsx)(`div`,{className:`px-4 py-3 text-xs text-fg-muted`,children:a.error instanceof Error?a.error.message:`Failed to load diff`});let o=a.data.entries.find(e=>e.path===t);return o?(0,z.jsx)(`div`,{className:`h-full`,children:(0,z.jsx)(Nr,{session:e,against:a.data.against,entry:o,root:n,area:r,focused:i})}):(0,z.jsxs)(`div`,{className:`flex h-full items-center justify-center px-4 text-center text-xs text-fg-muted`,children:[`No changes to `,(0,z.jsx)(`span`,{className:`mx-1 text-fg-secondary`,children:t}),` against the base.`]})}var Br=800;function Vr({name:e}){let t=T(),n=mt(),r=Un([n,e]),i=pe(n,e),a=s(),o=dt(`editor.save`),c=(0,R.useRef)(null),l=(0,R.useRef)(null),u=(0,R.useMemo)(()=>getComputedStyle(document.documentElement).getPropertyValue(`--font-mono`).trim()||void 0,[]);if((0,R.useEffect)(()=>{if(n===null)return;let t=Dt(t=>{oe(n,e,t).catch(e=>L.error(e instanceof Error?e.message:`Draft not saved`))},Br);return l.current=t,()=>{t.flush(),l.current=null}},[n,e]),n===null)return null;if(i.error)return(0,z.jsx)(`div`,{className:`flex h-full items-center justify-center bg-ground text-sm text-fg-muted`,children:i.error instanceof Error?i.error.message:`Failed to load the draft`});if(i.data===void 0)return(0,z.jsx)(`div`,{className:`p-3 text-xs text-fg-muted`,children:`…`});let d=()=>{let t=c.current;t&&(l.current?.flush(),Fe({name:e,content:t.getValue()}))};return(0,z.jsxs)(`div`,{className:`flex h-full flex-col bg-ground`,children:[(0,z.jsxs)(`div`,{className:`bg-surface px-3 py-1 text-xs text-fg-muted`,children:[`Draft — not in any worktree; `,o,` saves it into one`]}),(0,z.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,z.jsx)(jt,{path:`puddle-untitled://${n}/${e}`,defaultValue:i.data.content,theme:At,keepCurrentModel:!1,saveViewState:!1,loading:(0,z.jsx)(`div`,{className:`p-3 text-xs text-fg-muted`,children:`…`}),onMount:t=>{r(t),c.current=t,ye(e,t.getValue()),sr(t,{onSave:d})},onChange:t=>{let r=t??``;ye(e,r),Ie(a,n,e,r),l.current?.(r)},options:{automaticLayout:!0,fontFamily:u,fontSize:t.editorFontSize,...In(t.editorTabSize),minimap:{enabled:!1},fixedOverflowWidgets:!0,scrollBeyondLastLine:!1,wordWrap:t.editorWordWrap?`on`:`off`}})})]})}var Hr=p([x(),_(x())]),Ur=y(x(),g()),Wr=m({output_type:x(),text:Hr.optional(),data:y(x(),g()).optional(),traceback:_(x()).optional(),ename:x().optional(),evalue:x().optional()}),Gr=m({id:x().optional(),cell_type:S([`code`,`markdown`,`raw`]),metadata:Ur,source:Hr,outputs:_(Wr).optional(),execution_count:f().int().nullable().optional()}),Kr=m({nbformat:b(4),nbformat_minor:f().int().nonnegative(),metadata:Ur,cells:_(Gr).max(2e3)});function qr(e){if(e.length>5*1024*1024)throw Error(`This notebook exceeds the 5 MiB editor limit.`);let t;try{t=JSON.parse(e)}catch{throw Error(`This notebook is not valid JSON. Switch to source to repair it.`)}let n=Kr.safeParse(t);if(!n.success)throw Error(`Expected a version 4 notebook with at most 2,000 valid cells. Switch to source to inspect it.`);return n.data}function V(e){return typeof e==`string`?e:Array.isArray(e)&&e.every(e=>typeof e==`string`)?e.join(``):``}function Jr(e,t,n){return{...e,cells:e.cells.map((e,r)=>r===t?{...e,source:n.match(/[^\n]*\n|[^\n]+$/g)??[],...e.cell_type===`code`&&e.outputs?.length&&!e.metadata.puddle_execution?{metadata:{...e.metadata,puddle_execution:{id:`saved`,revision:0,source:V(e.source),state:`saved`}}}:{}}:e)}}function Yr(e){let t=new Set;return{...e,cells:e.cells.map((n,r)=>{let i=n.id;if(!i||t.has(i))for(i=`puddle-${r}`;t.has(i)||e.cells.some(e=>e.id===i);)i+=`-`;return t.add(i),n.id===i?n:{...n,id:i}})}}function Xr(e,t){if(e.cell_type!==`code`)return e.cell_type===`raw`?`plaintext`:`markdown`;let n=e.metadata.vscode,r=t.metadata.language_info,i=t.metadata.kernelspec,a=n?.languageId??r?.name??i?.language??`python`;return typeof a==`string`?a:`python`}function Zr(e,t){let n=t===`markdown`||t===`raw`?t:`code`,r={...e,cell_type:n};return n===`code`?(r.metadata={...e.metadata,vscode:{...e.metadata.vscode??{},languageId:t}},r.outputs??=[],r.execution_count??=null):(delete r.outputs,delete r.execution_count),r}function Qr(e){return{id:crypto.randomUUID(),cell_type:e,metadata:{},source:[],...e===`code`?{outputs:[],execution_count:null}:{}}}function $r(e){return(e.output_type===`error`?e.traceback?.join(`
|
|
3
3
|
`)??`${e.ename??`Error`}: ${e.evalue??``}`:V(e.text??e.data?.[`text/plain`])).replace(/\u001b\[[0-?]*[ -/]*[@-~]/g,``)}function ei(e,t){let n=0;for(;n<e.length&&n<t.length&&e[n]===t[n];)n++;let r=e.length,i=t.length;for(;r>n&&i>n&&e[r-1]===t[i-1];)r--,i--;return{start:n,end:r,text:t.slice(n,i)}}function ti(e){return{...e,cells:e.cells.map(e=>e.cell_type===`code`?{...e,outputs:[],execution_count:null}:e)}}function ni(e){return e.cells.map((e,t)=>{let n=V(e.source).split(`
|
|
4
4
|
`).find(e=>e.trim())?.trim()??``;return{index:t,level:e.cell_type===`markdown`?/^(#{1,6})\s/.exec(n)?.[1]?.length??0:0,label:(e.cell_type===`markdown`?n.replace(/^#{1,6}\s+/,``):n).slice(0,100)||`${e.cell_type===`code`?`Code`:e.cell_type===`markdown`?`Markdown`:`Raw`} cell`}})}function ri(e,t){let n=ni(e),r=n[t]?.level;if(!r)return[t];let i=n.find(e=>e.index>t&&e.level>0&&e.level<=r);return Array.from({length:(i?.index??e.cells.length)-t},(e,n)=>t+n)}function ii(e,t){let n=!1,r=new Map(t.cells.map(e=>[e.id,e])),i=e.cells.map(e=>{let i=r.get(e.id);if(e.cell_type!==`code`||!i||i.state===`queued`)return e;let a=e.metadata.puddle_execution;return a?.id===t.id&&typeof a.revision==`number`&&a.revision>=i.revision||i.state===`cancelled`&&i.elapsed_ms===void 0?e:(n=!0,{...e,outputs:i.outputs,execution_count:i.execution_count,metadata:{...e.metadata,puddle_execution:{id:t.id,revision:i.revision,source:i.source,state:i.state,elapsed_ms:i.elapsed_ms}}})});return n?{...e,cells:i}:e}function ai(e){let t=e.metadata.puddle_execution;if(!(!t||typeof t!=`object`||!(`source`in t)||typeof t.source!=`string`||!(`state`in t)||typeof t.state!=`string`))return{source:t.source,state:t.state===`running`||t.state===`queued`?`saved`:t.state,...`elapsed_ms`in t&&typeof t.elapsed_ms==`number`?{elapsed_ms:t.elapsed_ms}:{}}}function oi({notebook:e,active:t,selected:n,update:r,choose:i,setEditing:a,run:o,onUndo:s,onRedo:c}){let l=(n,a=e.cells.findIndex(e=>e.id===t)+1)=>{if(e.cells.length>=2e3)return;let o=Qr(n),s=[...e.cells];s.splice(t===null?s.length:a,0,o),r({...e,cells:s}),i(o.id,!0)},u=(t,n)=>r({...e,cells:e.cells.map((e,r)=>r===t?n:e)}),d=(t,n)=>{e.cells[t]?.cell_type===`code`&&o([t]),a(null),n===`insert`||n===`next`&&t===e.cells.length-1?l(e.cells[t].cell_type,t+1):n===`next`&&i(e.cells[t+1].id)};return{add:l,replace:u,execute:d,operation:(t,n)=>{let a=[...e.cells],o=a[t];if(n===`insert`){l(`code`,t+1);return}if(n===`clear`){u(t,{...o,outputs:[],execution_count:null});return}if(n===`delete`&&(a.splice(t,1),a.length&&i(a[Math.min(t,a.length-1)].id)),n===`up`||n===`down`){let e=t+(n===`up`?-1:1);if(e<0||e>=a.length)return;[a[t],a[e]]=[a[e],o],i(o.id)}if(n===`duplicate`){if(a.length>=2e3)return;let e={...structuredClone(o),id:crypto.randomUUID()};a.splice(t+1,0,e),i(e.id,!0)}if(n===`merge`){let e=a[t+1];if(!e||e.cell_type!==o.cell_type)return;a[t]={...o,source:`${V(o.source)}\n${V(e.source)}`},a.splice(t+1,1),i(o.id,!0)}r({...e,cells:a})},keyDown:f=>{if(f.target.closest(`.monaco-editor,input,textarea,button,[role=dialog],[role=menu],[cmdk-root]`))return;let p=e.cells.findIndex(e=>e.id===t);if((f.metaKey||f.ctrlKey)&&f.key.toLowerCase()===`z`){f.preventDefault(),f.shiftKey?c?.():s?.();return}if(f.key===`Enter`&&(f.metaKey||f.ctrlKey)&&n.length>1){f.preventDefault(),o(e.cells.flatMap((e,t)=>n.includes(e.id)?[t]:[]));return}if(f.key===`Enter`&&p>=0)f.preventDefault(),f.metaKey||f.ctrlKey||f.shiftKey||f.altKey?d(p,f.shiftKey?`next`:f.altKey?`insert`:`stay`):a(t);else if(f.key===`ArrowDown`||f.key===`ArrowUp`){f.preventDefault();let t=Math.max(0,Math.min(e.cells.length-1,p+(f.key===`ArrowDown`?1:-1)));e.cells[t]&&i(e.cells[t].id,!1,f.shiftKey)}else!f.metaKey&&!f.ctrlKey&&!f.altKey&&((f.key===`a`||f.key===`b`)&&(f.preventDefault(),l(`code`,Math.max(0,p+ +(f.key===`b`)))),(f.key===`m`||f.key===`y`)&&p>=0&&(f.preventDefault(),u(p,Zr(e.cells[p],f.key===`m`?`markdown`:`python`))),(f.key===`Delete`||f.key===`Backspace`)&&(f.preventDefault(),r({...e,cells:e.cells.filter(e=>!n.includes(e.id))})))}}}function si(e,t,n,r,i){if(!(e.target.closest(`.monaco-editor,input,textarea`)||!r.length)&&!(t!==`paste`&&window.getSelection()?.toString()))if(t===`paste`){let t=e.clipboardData.getData(`text/plain`);if(t.length>5*1024*1024)return;try{let a=JSON.parse(t);if(!a||typeof a!=`object`||!(`puddle_notebook_cells`in a))return;let o=qr(JSON.stringify({nbformat:4,nbformat_minor:5,metadata:{},cells:a.puddle_notebook_cells})).cells;if(e.preventDefault(),n.cells.length+o.length>2e3){L.error(`A notebook can contain at most 2,000 cells`);return}let s=[...n.cells],c=Math.max(...s.flatMap((e,t)=>r.includes(e.id)?[t]:[]));s.splice(c+1,0,...o.map(e=>({...e,id:crypto.randomUUID()}))),i({...n,cells:s})}catch{}}else{let a=n.cells.filter(e=>r.includes(e.id));e.clipboardData.setData(`text/plain`,JSON.stringify({puddle_notebook_cells:a})),e.preventDefault(),t===`cut`&&i({...n,cells:n.cells.filter(e=>!r.includes(e.id))})}}function ci({controls:e}){return e.open?(0,z.jsx)(tt,{query:e.query,focusKey:e.focusKey,options:e.options,result:e.result,onQueryChange:e.setQuery,onOptionsChange:e.setOptions,onNext:e.next,onPrevious:e.previous,onClose:e.close}):null}function li(e,t){return Math.min(t,Math.max(1,Math.floor(e)))}function ui({notebook:e,focused:t,onReveal:n,onChange:r}){let[i,a]=(0,R.useState)(!1),[o,s]=(0,R.useState)(``),c=(0,R.useRef)(null),l=(0,R.useRef)([]),u=(0,R.useRef)(-1),d=(0,R.useRef)(!1),f=Ze({shortcutEnabled:t,onFind:(t,r,a)=>{let o=c.current;if(a===`reset`){l.current=[],u.current=-1;for(let n of e.cells){let e=[{text:V(n.source),output:!1},...i?[{text:(n.outputs??[]).map($r).join(`
|
|
5
|
-
`),output:!0}]:[]];for(let i of e){let e=et(i.text,t,r,Math.max(0,1e3-l.current.length));if(e.invalid)return{index:-1,count:0,invalid:!0};if(l.current.push(...e.matches.map(e=>({...e,id:n.id,output:i.output}))),l.current.length>=1e3)break}if(l.current.length>=1e3)break}if(d.current&&o){let e=l.current.findIndex(e=>e.id===o.id&&e.output===o.output&&e.start>=o.start);u.current=e>=0?e-1:-1}}let s=l.current.length;return u.current=s?(u.current+(a===`previous`?-1:1)+s)%s:-1,c.current=l.current[u.current]??null,d.current||n(c.current),{index:u.current,count:s,limited:s>=1e3}},onClear:()=>{c.current=null,n(null)}});(0,R.useEffect)(()=>{f.refresh()},[i,f.refresh]);let p=t=>{let n=Qe(f.query,f.options);if(!n||!r)return;let i=e;e.cells.forEach((e,r)=>{let a=V(e.source),s=c.current;t?i=Jr(i,r,a.replace(n,o)):s&&!s.output&&s.id===e.id&&(i=Jr(i,r,a.slice(0,s.start)+a.slice(s.start,s.end).replace(n,o)+a.slice(s.end)))}),r(i),l.current=[],c.current=null};return(0,R.useEffect)(()=>{d.current=c.current!==null,f.open&&f.refresh(),d.current=!1},[e,f.open,f.refresh]),(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(ci,{controls:f}),f.open&&(0,z.jsxs)(`div`,{className:`absolute right-2 top-10 z-30 flex max-w-full flex-wrap items-center gap-2 rounded-b-md bg-surface px-2 py-1.5 text-xs text-fg-secondary`,children:[(0,z.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-1`,children:[(0,z.jsx)(`input`,{type:`checkbox`,checked:i,onChange:e=>a(e.target.checked)}),`Include output`]}),r&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`input`,{"aria-label":`Replace in notebook`,value:o,onChange:e=>s(e.target.value),placeholder:`Replace`,className:`min-w-0 bg-ground px-2 py-1 outline-none`}),(0,z.jsx)(`button`,{type:`button`,className:`cursor-pointer hover:text-fg`,disabled:!f.query||!!c.current?.output,onClick:()=>p(!1),children:`Replace`}),(0,z.jsx)(`button`,{type:`button`,className:`cursor-pointer hover:text-fg`,disabled:!f.query,onClick:()=>p(!0),children:`Replace all`})]})]})]})}function di(e){return n({queryKey:[`notebook-kernels`],queryFn:()=>ne(`GET`,`/api/notebooks/kernels`),enabled:e,staleTime:3e4})}function fi(e,t){return n({queryKey:[`notebook-kernel`,e],queryFn:()=>ne(`POST`,`/api/notebooks/status`,{source:e}),enabled:t,refetchInterval:1500,retry:!1})}function pi(e){return ne(`POST`,`/api/notebooks/kernel`,e)}function mi(e,t){return n({queryKey:[`notebook-environments`,e],queryFn:()=>ne(`POST`,`/api/notebooks/environments`,{source:e}),enabled:t,staleTime:3e4,retry:!1})}var hi=u(250),gi=u(5e3),_i=e=>e?.execution?.state===`running`?hi():gi();function vi(e,t,n){let r=[`notebook-execution`,t],i=!0;return{queryKey:r,reset:()=>{i=!0},queryFn:async({signal:a})=>{let o=e.getQueryState(r),s=!i&&!o?.isInvalidated&&o?.status!==`error`?o?.data:void 0,c=s?.execution?{id:s.execution.id,revision:s.execution.revision}:null;try{let o=await ne(`POST`,`/api/notebooks/execution`,{source:t,...n&&s?{known:c}:{}},a);if(a.throwIfAborted(),`unchanged`in o){if(!s)throw Error(`Notebook observation has no matching snapshot`);return i=!1,e.getQueryData(r)??s}return i=!1,o}catch(e){throw i=!0,e}}}}function yi(e,t,a,l){let u=r(),d=l&&!v()&&c(u.data?.protocol),f=(0,R.useRef)({notebook:t,onChange:a});f.current={notebook:t,onChange:a};let p=s(),[m,h]=(0,R.useState)(!1),g=(0,R.useRef)(!1),[_,y]=(0,R.useState)(null),b=(0,R.useRef)(!0);(0,R.useEffect)(()=>(b.current=!0,()=>{b.current=!1}),[]);let x=i(u.data?.protocol),S=(0,R.useMemo)(()=>vi(p,e,x),[p,e.session,e.path,e.root,x]),C=S.queryKey;(0,R.useEffect)(()=>{if(d)return pt.onConnectionChange(e=>{S.reset(),e?p.invalidateQueries({queryKey:S.queryKey}):p.cancelQueries({queryKey:S.queryKey})})},[d,S,p]);let w=n({queryKey:C,queryFn:S.queryFn,refetchOnReconnect:()=>(S.reset(),`always`),enabled:d,retry:!1,refetchInterval:e=>_i(e.state.data)}),T=w.data?.execution;(0,R.useEffect)(()=>{if(!T||!f.current.notebook||!f.current.onChange)return;let e=ii(f.current.notebook,T);e!==f.current.notebook&&f.current.onChange(e)},[T]);let E=async t=>{let n=f.current.notebook;if(!d||!n||g.current||T?.state===`running`)return;let r=n.cells.flatMap((e,n)=>e.cell_type===`code`&&V(e.source).trim()&&(!t||t.includes(n))?[{id:e.id,source:V(e.source)}]:[]);if(r.length){g.current=!0,h(!0),y(null),f.current.onChange?.(n);try{let t=n.metadata.kernelspec,i=await ne(`POST`,`/api/notebooks/execute`,{source:e,cells:r,...t?.name?{kernel:t.name}:{}});await p.cancelQueries({queryKey:C}),b.current&&p.setQueryData(C,i)}catch(e){b.current&&y(e instanceof Error?e.message:`Notebook execution failed`)}finally{g.current=!1,b.current&&(h(!1),p.invalidateQueries({queryKey:C}))}}},D=(0,R.useRef)(E);return D.current=E,(0,R.useEffect)(()=>d?Se(e,()=>{D.current()}):void 0,[d,e.session,e.path,e.root]),{supported:d,intelligenceSupported:d&&o(u.data?.protocol),run:E,interrupt:async()=>{try{await pi({source:e,action:`interrupt`})}catch(e){b.current&&y(e instanceof Error?e.message:`Interrupt failed`)}finally{p.invalidateQueries({queryKey:C})}},execution:T,busy:m||T?.state===`running`,error:_??(w.error instanceof Error?w.error.message:T?.error)}}var bi=(0,R.createContext)(null);function xi({source:e,environment:t,current:n,kernels:r,pending:i,onAction:a}){let[o,s]=(0,R.useState)(!1),[c,l]=(0,R.useState)(``),u=(0,R.useId)(),d=mi(e,o),f=[...d.data?.environments??[]];t&&!f.some(e=>e.python===t.python)&&f.unshift(t);let p=e=>{s(!1),a(e)};return(0,z.jsxs)(Ct,{open:o,onOpenChange:s,children:[(0,z.jsx)(St,{asChild:!0,children:(0,z.jsxs)(`button`,{type:`button`,disabled:i,"aria-label":`Select Python environment`,title:t?.python??`Changing environments starts a fresh kernel`,className:`flex max-w-64 cursor-pointer items-center gap-1.5 rounded-sm px-2 py-1.5 text-xs text-fg-secondary hover:bg-surface hover:text-fg disabled:cursor-default disabled:opacity-40`,children:[(0,z.jsx)(mn,{className:`size-3.5 shrink-0`}),(0,z.jsx)(`span`,{className:`truncate`,children:t?.label??n?.display_name??`Select environment`})]})}),(0,z.jsxs)(xt,{align:`end`,className:`w-96 max-w-[calc(100vw-2rem)] p-3`,children:[(0,z.jsx)(`p`,{className:`mb-2 text-xs text-fg-muted`,children:`Python environments on this host`}),(0,z.jsxs)(`div`,{className:`max-h-64 overflow-y-auto`,"aria-label":`Python environments`,children:[d.isLoading&&(0,z.jsx)(`p`,{role:`status`,className:`py-2 text-xs text-fg-muted`,children:`Looking for environments…`}),d.isError&&(0,z.jsx)(`p`,{role:`alert`,className:`py-2 text-xs text-danger`,children:`Couldn’t discover environments. You can enter a path below.`}),d.data&&!f.length&&(0,z.jsx)(`p`,{className:`py-2 text-xs text-fg-muted`,children:`No Python environments found. Enter a path below.`}),f.map(n=>(0,z.jsxs)(`button`,{type:`button`,disabled:i,onClick:()=>p({source:e,action:`select-python`,python:n.python}),className:`flex w-full cursor-pointer items-center gap-2 rounded-sm px-2 py-2 text-left hover:bg-surface disabled:cursor-default disabled:opacity-40`,children:[(0,z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,z.jsx)(`p`,{className:`text-xs text-fg`,children:n.label}),(0,z.jsx)(`p`,{className:`break-all text-xs text-fg-muted`,children:n.python}),(n.error||!n.ipykernel||!n.nbconvert)&&(0,z.jsx)(`p`,{className:`text-xs text-fg-secondary`,children:n.error?`Couldn’t inspect this Python`:n.ipykernel?`nbconvert not installed`:`ipykernel not installed`})]}),t?.python===n.python&&(0,z.jsx)(qe,{className:`size-3.5 shrink-0 text-accent`})]},n.python)),r.length>0&&(0,z.jsx)(`p`,{className:`mb-1 mt-3 text-xs text-fg-muted`,children:`Registered Jupyter kernels`}),r.map(r=>(0,z.jsxs)(`button`,{type:`button`,disabled:i,className:`flex w-full cursor-pointer items-center justify-between rounded-sm px-2 py-2 text-left text-xs text-fg-secondary hover:bg-surface hover:text-fg`,onClick:()=>p({source:e,action:`select`,kernel:r.name}),children:[r.display_name,!t&&n?.name===r.name&&(0,z.jsx)(qe,{className:`size-3.5`})]},r.name))]}),(0,z.jsxs)(`form`,{className:`mt-3 flex flex-col gap-2`,onSubmit:t=>{t.preventDefault(),c.trim()&&p({source:e,action:`select-python`,python:c.trim()})},children:[(0,z.jsx)(`label`,{htmlFor:u,className:`text-xs text-fg-secondary`,children:`Environment folder or Python executable`}),(0,z.jsx)(ze,{id:u,value:c,onChange:e=>l(e.target.value),placeholder:`.venv, ~/miniforge3/envs/analysis, /path/to/python`,disabled:i}),(0,z.jsx)(`p`,{className:`text-xs text-fg-muted`,children:`Relative paths start beside this notebook. Switching starts fresh.`}),(0,z.jsx)(`button`,{type:`submit`,disabled:i||!c.trim(),className:`cursor-pointer self-end rounded-sm px-2 py-1.5 text-xs text-fg-secondary hover:bg-surface hover:text-fg disabled:cursor-default disabled:opacity-40`,children:`Use path`})]})]})]})}var Si=`flex cursor-pointer items-center gap-1.5 whitespace-nowrap rounded-sm px-2 py-1.5 text-xs text-fg-secondary transition-colors hover:bg-surface hover:text-fg disabled:cursor-default disabled:opacity-40`;function Ci({source:e,notebook:t,onSelect:n}){let i=(0,R.useRef)(n);i.current=n;let o=(0,R.useRef)(!0);(0,R.useEffect)(()=>(o.current=!0,()=>{o.current=!1}),[]);let c=r(),u=a(c.data?.protocol),d=l(c.data?.protocol),f=di(u),p=fi(e,u),m=s(),[h,g]=(0,R.useState)(null),_=h!==null,[v,y]=(0,R.useState)(null);if(!u)return null;let b=t.metadata.kernelspec,x=p.data?.kernel??(typeof b?.name==`string`?b.name:``),S=f.data?.kernels??[],C=S.find(e=>e.name===x),w=p.data?.environment,T=w&&!w.error?[!w.ipykernel&&`ipykernel`,!w.nbconvert&&`nbconvert`].filter(Boolean).join(` and `):``,E=p.data&&p.data.state!==`stopped`&&p.data.state!==`dead`,D=p.data?.state===`busy`||p.data?.state===`starting`,O=async t=>{g(t.action),y(null);try{let n=await pi(t);if(m.setQueryData([`notebook-kernel`,e],n),(t.action===`select-python`||t.action===`install-python`)&&(m.invalidateQueries({queryKey:[`notebook-environments`]}),o.current&&i.current({name:`python3`,display_name:`Python 3`,language:`python`})),t.action===`select`){let e=S.find(e=>e.name===t.kernel);e&&o.current&&i.current(e)}}catch(e){y(e instanceof Error?e.message:`Kernel operation failed`)}finally{g(null)}};return(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[D&&(0,z.jsxs)(`button`,{type:`button`,className:Si,disabled:_,onClick:()=>void O({source:e,action:`interrupt`}),children:[(0,z.jsx)(Me,{className:`size-3.5`}),`Interrupt`]}),(0,z.jsx)(`span`,{className:`text-xs text-fg-muted`,role:`status`,children:_?h===`install-python`?`Installing…`:`Updating…`:p.data?.state===`dead`?`Kernel exited`:D?`Busy`:E?`Idle`:``}),d?(0,z.jsx)(xi,{source:e,environment:w,current:C,kernels:S,pending:_,onAction:O}):(0,z.jsxs)(Ye,{value:C?.name??``,disabled:_||!f.data?.available||S.length===0,onValueChange:t=>void O({source:e,action:`select`,kernel:t}),children:[(0,z.jsxs)(Ge,{className:`h-7 max-w-52 gap-1.5 bg-transparent text-xs hover:bg-surface`,"aria-label":`Select kernel`,title:`Kernels stay alive until shut down. Changing kernels starts fresh.`,children:[(0,z.jsx)(mn,{className:`size-3.5 shrink-0`}),(0,z.jsx)(We,{placeholder:x?`${x} (not installed)`:`Select Kernel`})]}),(0,z.jsx)(Ke,{children:S.map(e=>(0,z.jsx)(Je,{value:e.name,detail:e.language,children:(0,z.jsx)(`span`,{children:e.display_name})},e.name))})]}),(0,z.jsxs)(je,{children:[(0,z.jsx)(Pe,{asChild:!0,children:(0,z.jsx)(`button`,{type:`button`,className:Si,disabled:_,"aria-label":`Kernel actions`,children:(0,z.jsx)(xe,{className:`size-3.5`})})}),(0,z.jsxs)(Ce,{align:`end`,children:[(0,z.jsxs)(be,{disabled:!C&&!w,onSelect:()=>void O({source:e,action:`restart`}),children:[(0,z.jsx)(rt,{}),`Restart kernel`]}),(0,z.jsxs)(be,{disabled:!E,onSelect:()=>void O({source:e,action:`shutdown`}),children:[(0,z.jsx)(ut,{}),`Shut down kernel`]})]})]})]}),T&&(0,z.jsxs)(`div`,{className:`flex w-full flex-wrap items-center gap-2 px-2 text-xs text-fg-muted`,children:[(0,z.jsxs)(`span`,{className:`break-all`,children:[T,` missing from `,w?.python,`.`]}),(0,z.jsxs)(`button`,{type:`button`,className:Si,disabled:_,onClick:()=>{w&&O({source:e,action:`install-python`,python:w.python})},children:[`Install `,T]})]}),(v||p.data?.error||!d&&(f.data?.error||f.isError)||p.isError)&&(0,z.jsx)(`p`,{role:`alert`,className:`w-full px-2 text-xs text-danger`,children:v??p.data?.error??f.data?.error??`Couldn’t load notebook kernels`}),!d&&f.data&&!f.data.available&&!f.data.error&&(0,z.jsx)(`p`,{className:`w-full px-2 text-xs text-fg-muted`,children:`Install Jupyter and a language kernel on this host to run notebooks.`})]})}var wi=`flex cursor-pointer items-center gap-1.5 whitespace-nowrap rounded-sm px-2 py-1.5 text-xs text-fg-secondary transition-colors hover:bg-surface hover:text-fg disabled:cursor-default disabled:opacity-40`;function Ti({notebook:e,source:t,onChange:n,onAdd:i,onRevealCell:o,onRun:s,onRunCopy:c,onRunSection:l,running:u=!1}){let[d,f]=(0,R.useState)(!1),p=r(),m=fi(t,!!s&&a(p.data?.protocol)),h=u||m.data?.state===`busy`||m.data?.state===`starting`,g=m.data?.environment,_=g&&(!g.ipykernel||!g.nbconvert),v=ni(e),y=e.cells.some(e=>e.cell_type===`code`&&((e.outputs?.length??0)>0||e.execution_count!=null));return(0,z.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-1 bg-ground px-3 py-2`,role:`toolbar`,"aria-label":`Notebook`,children:[n&&(0,z.jsxs)(ht,{label:`Add notebook cells`,children:[(0,z.jsxs)(`button`,{type:`button`,className:wi,disabled:e.cells.length>=2e3,onClick:()=>i(`code`),"aria-label":`Add code cell`,children:[(0,z.jsx)(He,{className:`size-3.5`}),`Code`]}),(0,z.jsxs)(`button`,{type:`button`,className:wi,disabled:e.cells.length>=2e3,onClick:()=>i(`markdown`),"aria-label":`Add Markdown cell`,children:[(0,z.jsx)(He,{className:`size-3.5`}),`Markdown`]})]}),(0,z.jsxs)(ht,{label:`Notebook actions`,className:`flex-wrap !rounded-[var(--ui-radius)]`,children:[s&&(0,z.jsxs)(`button`,{type:`button`,className:wi,disabled:h||_,onClick:s,children:[(0,z.jsx)(we,{className:`size-3.5`}),h?`Running…`:`Run All`]}),n&&(0,z.jsxs)(`button`,{type:`button`,className:wi,disabled:!y,onClick:()=>n(ti(e)),children:[(0,z.jsx)(Ve,{className:`size-3.5`}),`Clear All Outputs`]}),(0,z.jsxs)(Ct,{open:d,onOpenChange:f,children:[(0,z.jsx)(St,{asChild:!0,children:(0,z.jsxs)(`button`,{type:`button`,className:wi,disabled:v.length===0,children:[(0,z.jsx)(hn,{className:`size-3.5`}),`Outline`]})}),(0,z.jsx)(xt,{align:`start`,className:`max-h-72 w-72 overflow-y-auto p-1`,children:(0,z.jsx)(`nav`,{"aria-label":`Notebook outline`,className:`flex flex-col`,children:v.map(e=>(0,z.jsxs)(`div`,{className:`group/outline flex items-center`,style:{paddingLeft:`calc(var(--spacing) * ${Math.max(0,e.level-1)*3})`},children:[(0,z.jsxs)(`button`,{type:`button`,className:`${wi} min-w-0 flex-1 text-left`,onClick:()=>{o(e.index),f(!1)},children:[(0,z.jsx)(`span`,{className:`w-5 shrink-0 text-fg-muted`,children:e.index+1}),(0,z.jsx)(`span`,{className:`truncate`,children:e.label})]}),!!e.level&&l&&(0,z.jsx)(`button`,{type:`button`,disabled:h,title:`Run Section`,"aria-label":`Run section ${e.label}`,className:`${wi} opacity-0 group-hover/outline:opacity-100 focus:opacity-100 pointer-coarse:opacity-100`,onClick:()=>{l(e.index),f(!1)},children:(0,z.jsx)(we,{className:`size-3.5`})})]},e.index))})})]}),n&&(0,z.jsxs)(je,{children:[(0,z.jsx)(Pe,{asChild:!0,children:(0,z.jsx)(`button`,{type:`button`,className:wi,"aria-label":`More notebook actions`,children:(0,z.jsx)(xe,{className:`size-3.5`})})}),(0,z.jsxs)(Ce,{align:`start`,children:[c&&(0,z.jsx)(be,{disabled:h,onSelect:c,children:`Run to Executed Copy`}),(0,z.jsxs)(be,{disabled:e.cells.length>=2e3,onSelect:()=>i(`raw`),children:[(0,z.jsx)(He,{}),`Add raw cell`]})]})]})]}),n&&s&&(0,z.jsx)(Ci,{source:t,notebook:e,onSelect:t=>n({...e,metadata:{...e.metadata,kernelspec:t}})},JSON.stringify(t))]})}function Ei({code:e,onRun:t,busy:n,index:r,count:i,canMerge:a,onOperation:o}){let s=(e,t,n,r=!1)=>(0,z.jsx)(`button`,{type:`button`,className:`cursor-pointer rounded-sm p-1 text-fg-muted hover:bg-elevated hover:text-fg disabled:cursor-default disabled:opacity-40`,title:e,"aria-label":e,onClick:n,disabled:r,children:t});return(0,z.jsxs)(`div`,{className:`ml-auto flex flex-wrap items-center opacity-0 focus-within:opacity-100 group-hover/cell:opacity-100 pointer-coarse:opacity-100`,children:[e&&t&&(0,z.jsxs)(z.Fragment,{children:[s(`Run Cell`,(0,z.jsx)(we,{className:`size-3.5`}),()=>t(`cell`),n),s(`Run Above`,(0,z.jsx)(fn,{className:`size-3.5`}),()=>t(`above`),n||r===0),s(`Run Cell and Below`,(0,z.jsx)(dn,{className:`size-3.5`}),()=>t(`below`),n)]}),s(`Insert cell below`,(0,z.jsx)(He,{className:`size-3.5`}),()=>o(`insert`),i>=2e3),s(`Duplicate cell`,(0,z.jsx)(nt,{className:`size-3.5`}),()=>o(`duplicate`),i>=2e3),s(`Merge with next cell`,(0,z.jsx)(pn,{className:`size-3.5`}),()=>o(`merge`),!a),s(`Move cell up`,(0,z.jsx)(Ne,{className:`size-3.5`}),()=>o(`up`),r===0),s(`Move cell down`,(0,z.jsx)(Ue,{className:`size-3.5`}),()=>o(`down`),r===i-1),s(`Delete cell`,(0,z.jsx)(Ve,{className:`size-3.5`}),()=>o(`delete`))]})}function Di(e,t){let n=async(n,r,i)=>{let a=e.getValue();if(a.length>65536||i.isCancellationRequested)return null;let o=e.getVersionId();try{let s=await ne(`POST`,`/api/notebooks/intelligence`,{source:t,kind:n,code:a,cursor:[...a.slice(0,e.getOffsetAt(r))].length});return i.isCancellationRequested||e.isDisposed()||o!==e.getVersionId()?null:{response:s,code:a}}catch{return null}},r=()=>{let t=e.getLanguageId();return t===`markdown`||t===`plaintext`?[]:[P.registerCompletionItemProvider(t,{triggerCharacters:[`.`],async provideCompletionItems(t,r,i,a){if(t!==e)return{suggestions:[]};let o=await n(`complete`,r,a);if(!o)return{suggestions:[]};let{response:s,code:c}=o,l=e.getPositionAt([...c].slice(0,s.start).join(``).length),u=e.getPositionAt([...c].slice(0,s.end).join(``).length),d=new N(l.lineNumber,l.column,u.lineNumber,u.column);return{suggestions:s.matches.map(e=>({label:e,insertText:e,kind:P.CompletionItemKind.Text,range:d}))}}}),P.registerHoverProvider(t,{async provideHover(t,r,i){if(t!==e)return null;let a=await n(`inspect`,r,i);return a?.response.documentation?{contents:[{value:a.response.documentation.replace(/\u001b\[[0-?]*[ -/]*[@-~]/g,``).replace(/[\\`*_{}[\]()#+.!<>-]/g,`\\$&`),isTrusted:!1,supportHtml:!1}]}:null}})]},i=r(),a=e.onDidChangeLanguage(()=>{i.forEach(e=>e.dispose()),i=r()});return{dispose(){a.dispose(),i.forEach(e=>e.dispose())}}}function Oi({value:e,language:t,label:n,focus:r,onChange:i,onExecute:a,onEscape:o,onSplit:s,onSave:c,match:l}){let u=T(),d=Math.round(u.editorFontSize*1.5),f=(0,R.useContext)(bi),[p,m]=(0,R.useState)(null);(0,R.useEffect)(()=>{if(!p||!f?.intelligence)return;let e=Di(p,{session:f.session,path:f.path,...f.root?{root:f.root}:{}});return()=>e.dispose()},[p,f?.intelligence,f?.session,f?.path,f?.root]);let h=(0,R.useRef)(null),g=(0,R.useRef)(null),_=(0,R.useRef)(null),v=(0,R.useRef)(!1),y=(0,R.useRef)(null),b=(0,R.useRef)({onChange:i,onExecute:a,onEscape:o,onSplit:s,onSave:c});b.current={onChange:i,onExecute:a,onEscape:o,onSplit:s,onSave:c};let x=(0,R.useRef)(r);x.current=r;let S=(0,R.useRef)(l);S.current=l;let C=e=>{let t=e.getModel(),n=S.current;if(!t||!n)return;let r=t.getPositionAt(n.start),i=t.getPositionAt(n.end);e.setSelection(new N(r.lineNumber,r.column,i.lineNumber,i.column)),e.revealPositionInCenter(r)};(0,R.useEffect)(()=>{g.current&&C(g.current)},[l]);let[w,E]=(0,R.useState)(!1),[D,O]=(0,R.useState)(!1),[k,A]=(0,R.useState)(Math.max(64,e.split(`
|
|
6
|
-
`).length*d+24));return(0,R.useEffect)(()=>{let e=new IntersectionObserver(([e])=>E(!!e?.isIntersecting),{rootMargin:`600px`});return h.current&&e.observe(h.current),()=>e.disconnect()},[]),(0,R.useEffect)(()=>()=>{_.current?.dispose()},[]),(0,R.useEffect)(()=>{let n=_.current;n&&n.getValue()!==e&&(v.current=!0,n.pushEditOperations([],[{range:n.getFullModelRange(),text:e}],()=>null),v.current=!1),n&&I.setModelLanguage(n,t)},[e,t]),(0,R.useEffect)(()=>{r&&g.current?.focus()},[r]),(0,z.jsxs)(`div`,{ref:h,style:{height:k},className:`relative min-w-0 rounded-md`,onWheelCapture:e=>{!e.shiftKey&&Math.abs(e.deltaY)>=Math.abs(e.deltaX)&&!e.target.closest(`.overflowingContentWidgets,.overflowingOverlayWidgets,.contentWidgets,.overlayWidgets`)&&e.stopPropagation()},children:[!p&&(0,z.jsx)(`pre`,{"aria-hidden":`true`,className:`absolute inset-0 overflow-hidden px-2 py-3 font-mono text-fg`,style:{fontSize:u.editorFontSize,lineHeight:`${d}px`,whiteSpace:u.editorWordWrap?`pre-wrap`:`pre`},children:e}),(w||r||D)&&(0,z.jsx)(jt,{loading:null,theme:`puddle`,defaultValue:e,defaultLanguage:t,keepCurrentModel:!0,saveViewState:!1,onMount:e=>{if(_.current){let t=e.getModel();e.setModel(_.current),t!==_.current&&t?.dispose()}else _.current=e.getModel();g.current=e,m(e.getModel()),sr(e,{onSave:()=>b.current.onSave()}),y.current&&e.restoreViewState(y.current),e.setScrollTop(0);let t=!1,n=()=>{if(t||!h.current||!h.current.clientWidth)return;t=!0,e.layout({width:h.current.clientWidth,height:h.current.clientHeight});let n=Math.max(64,e.getContentHeight());h.current.style.height=`${n}px`,e.layout({width:h.current.clientWidth,height:n}),A(n),t=!1},r=e.onDidContentSizeChange(n),i=new ResizeObserver(n);i.observe(h.current);let a=e.onDidFocusEditorWidget(()=>O(!0)),o=e.onDidBlurEditorWidget(()=>O(!1)),s=e.onDidChangeModelContent(()=>{v.current||b.current.onChange(e.getValue())}),c=e.onDidScrollChange(()=>{y.current=e.saveViewState()}),l=e.onDidChangeCursorSelection(()=>{y.current=e.saveViewState()});e.addCommand(F.CtrlCmd|te.Enter,()=>b.current.onExecute(`stay`)),e.addCommand(F.Shift|te.Enter,()=>b.current.onExecute(`next`)),e.addCommand(F.Alt|te.Enter,()=>b.current.onExecute(`insert`)),e.addCommand(te.Escape,()=>b.current.onEscape(),`!suggestWidgetVisible && !findWidgetVisible`),e.addCommand(F.CtrlCmd|F.Shift|te.Minus,()=>{let t=e.getPosition();t&&b.current.onSplit(e.getModel().getOffsetAt(t))}),e.onDidDispose(()=>{r.dispose(),i.disconnect(),a.dispose(),o.dispose(),c.dispose(),l.dispose(),s.dispose(),g.current=null,m(null)}),n(),C(e),x.current&&e.focus()},beforeMount:()=>{_.current&&I.setModelLanguage(_.current,t)},options:{ariaLabel:n,automaticLayout:!1,fontFamily:getComputedStyle(document.documentElement).getPropertyValue(`--font-mono`).trim(),fontSize:u.editorFontSize,lineHeight:d,...In(u.editorTabSize),wordWrap:u.editorWordWrap?`on`:`off`,minimap:{enabled:!1},glyphMargin:!1,folding:!0,lineNumbers:`off`,lineDecorationsWidth:8,lineNumbersMinChars:3,scrollBeyondLastLine:!1,fixedOverflowWidgets:!0,padding:{top:12,bottom:12},renderLineHighlight:`none`,occurrencesHighlight:`off`,scrollbar:{alwaysConsumeMouseWheel:!1,vertical:`hidden`}},onChange:()=>{g.current&&(y.current=g.current.saveViewState())}})]})}function ki({language:e,onChange:t}){let[n,r]=(0,R.useState)(!1),i=[`markdown`,`raw`,...P.getLanguages().map(e=>e.id).filter(e=>e!==`markdown`).sort()];return(0,z.jsxs)(Ct,{open:n,onOpenChange:r,children:[(0,z.jsx)(St,{asChild:!0,children:(0,z.jsxs)(`button`,{type:`button`,"aria-label":`Cell language: ${e}`,className:`flex cursor-pointer items-center gap-1 font-mono text-xs text-fg-muted hover:text-fg`,children:[e,(0,z.jsx)(Xe,{className:`size-3`})]})}),(0,z.jsxs)(xt,{align:`start`,className:`w-56 p-0`,children:[(0,z.jsxs)(bt,{children:[(0,z.jsx)(gt,{placeholder:`Find a language…`}),(0,z.jsxs)(yt,{children:[(0,z.jsx)(vt,{children:`No matching languages`}),i.map(e=>(0,z.jsx)(_t,{onSelect:()=>{t(e),r(!1)},children:e},e))]})]}),(0,z.jsx)(`p`,{className:`px-3 py-2 text-xs text-fg-muted`,children:`Code languages set highlighting. Execution uses the notebook kernel.`})]})]})}async function Ai(e,t,n){let r=`path=${encodeURIComponent(t)}${ae(n)}`,i=v();return i?Mi(i,async()=>{if(v()!==i)throw Error(`Preview host changed`);let t=h.parse(await ne(`GET`,`/api/worktrees/${e}/preview-asset?${r}`));return new Blob([Uint8Array.from(atob(t.data),e=>e.charCodeAt(0))],{type:t.mime})}):(await re(`GET`,`/api/worktrees/${e}/media?${r}`)).blob()}var ji=new WeakMap;async function Mi(e,t){let n=ji.get(e);if(n||(n={active:0,waiting:[]},ji.set(e,n)),n.waiting.length>=128)throw Error(`Too many preview assets`);n.active>=2?await new Promise(e=>n.waiting.push(e)):n.active+=1;try{return await t()}finally{let e=n.waiting.shift();e?e():--n.active}}function Ni(e,t,n,r,i){(0,R.useEffect)(()=>{let t=e.current;if(!t)return;let a=!1,o=[],s=async e=>{try{let t=await Ai(n,e,i);if(a)return null;let r=URL.createObjectURL(t);return o.push(r),r}catch{return null}};for(let e of t.querySelectorAll(`img[src], source[src]`)){let t=ct(r,e.getAttribute(`src`)??``);t&&(e.removeAttribute(`src`),s(t).then(t=>{!a&&t&&e.setAttribute(`src`,t)}))}for(let e of t.querySelectorAll(`img[srcset], source[srcset]`)){let t=lt(e.getAttribute(`srcset`)??``),n=t.map(({ref:e})=>ct(r,e));n.some(e=>e!==null)&&(e.removeAttribute(`srcset`),Promise.all(t.map(async(e,t)=>{let r=n[t];if(!r)return e;let i=await s(r);return i?{...e,ref:i}:null})).then(t=>{if(a)return;let n=t.filter(e=>e!==null);n.length>0&&e.setAttribute(`srcset`,at(n))}))}return()=>{a=!0;for(let e of o)URL.revokeObjectURL(e)}},[t,e,n,r,i])}var Pi=(0,R.lazy)(()=>j(()=>import(`./NotebookWidget-CPhHup1W.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9])));function Fi(e,t){return!t||typeof t!=`object`?e:e.replace(/attachment:([^\s"')>]+)/g,(e,n)=>{try{let r=t[decodeURIComponent(n)];if(!r||typeof r!=`object`)return e;for(let e of[`image/png`,`image/jpeg`,`image/gif`,`image/webp`]){let t=V(r[e]).replace(/\s/g,``);if(t&&/^[A-Za-z0-9+/]*={0,2}$/.test(t))return`data:${e};base64,${t}`}}catch{}return e})}function Ii({text:e,markdown:t=!1,attachments:n}){let r=(0,R.useContext)(bi),i=(0,R.useRef)(null),a=(0,R.useId)().replace(/[^a-zA-Z0-9_-]/g,``),o=(0,R.useSyncExternalStore)(k,O,O),s=(0,R.useMemo)(()=>M.sanitize(t?Yt(Fi(e,n),a):e,{FORBID_TAGS:[`style`,`iframe`,`form`,`input`,`button`],...t?{}:{FORBID_ATTR:[`style`]}}),[e,t,n,a]),c=(0,R.useMemo)(()=>({__html:s}),[s,o]);return Ni(i,s,r?.session??``,r?.path??``,r?.root),(0,R.useEffect)(()=>{let e=new AbortController;return i.current&&t&&un(i.current,o,e.signal),()=>e.abort()},[s,o,t]),(0,z.jsx)(`div`,{ref:i,className:`md-preview overflow-x-auto text-sm`,dangerouslySetInnerHTML:c,onClick:e=>{let t=e.target.closest(`a`);if(!t)return;let n=t.getAttribute(`href`)??``;if(/^https?:/i.test(n)){e.preventDefault(),window.open(n,`_blank`,`noopener,noreferrer`);return}if(n.startsWith(`#`)){e.preventDefault();try{i.current?.querySelector(`#${CSS.escape(decodeURIComponent(n.slice(1)))}`)?.scrollIntoView({block:`nearest`})}catch{}return}let a=r?ct(r.path,n):null;a&&(e.preventDefault(),(e.metaKey||e.ctrlKey)&&r?.onOpenFile?.(a))}})}var Li=`cursor-pointer rounded-sm p-1 text-fg-muted hover:bg-surface hover:text-fg`;function Ri({output:e}){let t=null;for(let n of[`image/png`,`image/jpeg`,`image/gif`,`image/webp`]){let r=V(e.data?.[n]).replace(/\s/g,``);if(r&&/^[A-Za-z0-9+/]*={0,2}$/.test(r)){try{t={src:`data:${n};base64,${r}`,blob:new Blob([Uint8Array.from(atob(r),e=>e.charCodeAt(0))],{type:n}),extension:n.split(`/`)[1]}}catch{}if(t)break}}let n=V(e.data?.[`image/svg+xml`]),r=n?M.sanitize(n,{USE_PROFILES:{svg:!0,svgFilters:!0},FORBID_TAGS:[`style`,`foreignObject`,`image`,`use`],FORBID_ATTR:[`style`,`href`,`xlink:href`]}):``,i=V(e.data?.[`text/html`]),a=V(e.data?.[`text/markdown`]),o=e.data?.[`application/json`],s=e.data?.[`application/vnd.jupyter.widget-view+json`],c=s&&typeof s==`object`&&`model_id`in s&&typeof s.model_id==`string`?s.model_id:null,l=$r(e)||(o===void 0?``:JSON.stringify(o,null,2))||`This output format cannot be displayed.`;return(0,z.jsxs)(`div`,{className:`group/output relative`,children:[(0,z.jsxs)(`div`,{className:`absolute right-1 top-0 z-10 flex gap-1 bg-ground opacity-0 group-hover/output:opacity-100 focus-within:opacity-100 pointer-coarse:opacity-100`,children:[(0,z.jsx)(`button`,{type:`button`,title:`Copy output`,"aria-label":`Copy output`,className:Li,onClick:()=>{navigator.clipboard.writeText(l).catch(()=>L.error(`Could not copy output`))},children:(0,z.jsx)(nt,{className:`size-3.5`})}),(t||r)&&(0,z.jsx)(`button`,{type:`button`,title:`Save image`,"aria-label":`Save image`,className:Li,onClick:()=>ke(t?.blob??new Blob([r],{type:`image/svg+xml`}),`notebook-output.${t?.extension??`svg`}`),children:(0,z.jsx)(Ae,{className:`size-3.5`})})]}),c?(0,z.jsx)(R.Suspense,{fallback:(0,z.jsx)(`p`,{className:`text-xs text-fg-muted`,children:`Loading widget…`}),children:(0,z.jsx)(Pi,{modelId:c,fallback:$r(e)})}):t?(0,z.jsx)(`img`,{src:t.src,alt:`Notebook output`,className:`max-w-full`}):r?(0,z.jsx)(`div`,{dangerouslySetInnerHTML:{__html:r}}):i?(0,z.jsx)(Ii,{text:i}):a?(0,z.jsx)(Ii,{text:a,markdown:!0}):(0,z.jsx)(`pre`,{className:`overflow-x-auto whitespace-pre-wrap font-mono text-sm ${e.output_type===`error`?`text-danger`:`text-fg-secondary`}`,children:l})]})}function zi({source:e,execution:t,onInterrupt:n}){let r=(0,R.useRef)(null),i=(0,R.useRef)(!1),[a,o]=(0,R.useState)(``),[s,c]=(0,R.useState)(!1),[l,u]=(0,R.useState)(null),d=t.input;return(0,R.useEffect)(()=>{r.current?.focus({preventScroll:!0}),r.current?.scrollIntoView({block:`nearest`})},[]),d?(0,z.jsxs)(`form`,{className:`mt-2 font-mono text-sm text-fg-secondary`,"aria-busy":s,onSubmit:n=>{n.preventDefault(),!i.current&&(i.current=!0,c(!0),u(null),ne(`POST`,`/api/notebooks/input`,{source:e,run_id:t.id,input_id:d.id,value:a}).then(()=>{d.password&&o(``)}).catch(e=>{u(e instanceof Error?e.message:`Input failed`),i.current=!1,c(!1)}))},children:[(0,z.jsxs)(`label`,{className:`flex min-w-0 flex-wrap items-baseline`,children:[(0,z.jsx)(`span`,{className:`whitespace-pre-wrap break-words`,children:d.prompt}),(0,z.jsx)(`input`,{ref:r,"aria-label":d.prompt||`Kernel input`,type:d.password?`password`:`text`,value:a,readOnly:s,maxLength:65536,autoComplete:`off`,autoCapitalize:`off`,spellCheck:!1,onChange:e=>o(e.target.value),onKeyDown:e=>{n&&e.ctrlKey&&!e.metaKey&&!e.altKey&&!e.shiftKey&&e.key.toLowerCase()===`c`&&e.currentTarget.selectionStart===e.currentTarget.selectionEnd&&(e.preventDefault(),e.stopPropagation(),n())},className:`min-w-16 flex-1 cursor-text bg-transparent p-0 text-fg outline-none read-only:opacity-60`})]}),l&&(0,z.jsx)(`p`,{role:`alert`,className:`mt-1 text-xs text-danger`,children:l})]}):null}var Bi=`cursor-pointer rounded-sm p-1 text-fg-muted transition-colors hover:bg-elevated hover:text-fg disabled:cursor-default disabled:opacity-40`;function Vi({cell:e,notebook:t,index:n,active:r,editing:i,selected:a,editable:o,onSelect:s,onEdit:c,onSource:l,onLanguage:u,onExecute:d,onRun:f,onInterrupt:p,onOperation:m,onSplit:h,onSave:g,execution:_,inputExecution:v,inputSource:y,match:b,onToggleSection:x,sectionCollapsed:S}){let C=(0,R.useRef)(null),[w,T]=(0,R.useState)(!1),E=y?v?.input:void 0;(0,R.useEffect)(()=>{(b?.output||E)&&T(!1)},[b,E]);let D=w&&!E,O=e.cell_type===`code`,k=V(e.source),A=_?.state===`running`||_?.state===`queued`,j=Xr(e,t),M=(e,t,n,r=!1)=>(0,z.jsx)(`button`,{type:`button`,className:Bi,title:e,"aria-label":e,onClick:n,disabled:r,children:t});return(0,z.jsxs)(`section`,{ref:C,"data-notebook-cell":n,"data-cell-id":e.id,tabIndex:r?0:-1,"aria-label":`Cell ${n+1}`,"aria-current":r||void 0,className:`group/cell relative min-w-0 outline-none`,onMouseDown:e=>{e.shiftKey&&!e.target.closest(`.monaco-editor,input,button`)&&e.preventDefault()},onFocus:()=>{r||s(!1)},onClick:e=>{if((e.metaKey||e.ctrlKey)&&O&&!e.target.closest(`.monaco-editor,a,button,input`)){e.preventDefault(),f?.(`cell`);return}e.target.closest(`button,input,[role=option]`)||s(e.shiftKey&&!e.target.closest(`.monaco-editor`))},children:[(0,z.jsx)(`div`,{className:`absolute -left-10 top-9 w-9 text-center font-mono text-xs text-fg-muted`,children:(0,z.jsxs)(`button`,{type:`button`,className:`${Bi} group/run relative w-full`,disabled:!o||O&&(!f||!A&&!k.trim()),title:O?A?`Interrupt execution`:`Run Cell (⌘/Ctrl+Enter)`:i?`Show rendered cell`:`Edit cell source`,"aria-label":O?A?`Interrupt execution`:`Run Cell`:i?`Show rendered cell`:`Edit cell source`,onClick:()=>{O?A?p?.():f?.(`cell`):c(!i)},children:[(0,z.jsx)(`span`,{className:O&&f?`group-hover/run:invisible group-focus-visible/run:invisible`:``,children:O?`[${A?`*`:e.execution_count??` `}]`:i?`[›]`:`[ ]`}),O&&f&&(A?(0,z.jsx)(Me,{className:`absolute inset-0 m-auto hidden size-3.5 group-hover/run:block group-focus-visible/run:block`}):(0,z.jsx)(we,{className:`absolute inset-0 m-auto hidden size-3.5 group-hover/run:block group-focus-visible/run:block`}))]})}),(0,z.jsxs)(`div`,{className:`mb-2 flex min-h-7 items-center gap-2 text-xs text-fg-muted`,children:[x&&M(S?`Expand section`:`Fold section`,S?(0,z.jsx)(Be,{className:`size-3`}):(0,z.jsx)(Xe,{className:`size-3`}),x),o?(0,z.jsx)(ki,{language:e.cell_type===`raw`?`raw`:j,onChange:u}):(0,z.jsx)(`span`,{className:`font-mono`,children:e.cell_type===`raw`?`raw`:j}),_&&(0,z.jsxs)(`span`,{role:`status`,children:[_.state,_.elapsed_ms===void 0?``:` · ${(_.elapsed_ms/1e3).toFixed(1)}s`]}),_&&_.source!==k&&(0,z.jsx)(`span`,{title:`The source changed after this execution`,children:`Source changed`}),o&&(0,z.jsx)(Ei,{code:O,onRun:f,busy:A,index:n,count:t.cells.length,canMerge:e.cell_type===t.cells[n+1]?.cell_type,onOperation:m})]}),(0,z.jsx)(`div`,{className:O||i||e.cell_type===`raw`?`rounded-[var(--ui-radius)] p-3 ${a?`bg-elevated`:`bg-surface`}`:void 0,children:o&&(O||i)?(0,z.jsx)(Oi,{value:k,match:b&&!b.output?b:void 0,language:j,label:`Cell ${n+1} source`,focus:r&&i&&!b,onChange:e=>{e!==k&&l(e)},onExecute:d,onEscape:()=>{c(!1),C.current?.focus()},onSave:g,onSplit:h}):e.cell_type===`markdown`?(0,z.jsx)(`div`,{onDoubleClick:()=>{o&&c(!0)},className:o?`cursor-text`:``,children:(0,z.jsx)(Ii,{text:k,markdown:!0,attachments:e.attachments})}):(0,z.jsx)(`pre`,{className:`overflow-x-auto whitespace-pre-wrap font-mono text-sm`,onDoubleClick:()=>{o&&c(!0)},children:k})}),(!!e.outputs?.length||E)&&(0,z.jsxs)(`div`,{className:`mt-2`,role:`group`,"aria-label":`Cell ${n+1} output`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-fg-muted`,children:[M(D?`Expand output`:`Collapse output`,D?(0,z.jsx)(Be,{className:`size-3`}):(0,z.jsx)(Xe,{className:`size-3`}),()=>T(!w),!!E),(0,z.jsx)(`span`,{children:`Output`}),o&&M(`Clear cell output`,(0,z.jsx)(Ve,{className:`size-3`}),()=>m(`clear`))]}),!D&&(0,z.jsxs)(`div`,{className:`mt-2 max-h-96 overflow-auto rounded-[var(--ui-radius)] bg-surface p-3`,children:[e.outputs?.map((e,t)=>(0,z.jsx)(`div`,{className:`mt-2 first:mt-0`,children:(0,z.jsx)(Ri,{output:e})},t)),E&&v&&y&&(0,z.jsx)(zi,{source:y,execution:v,onInterrupt:p},`${v.id}:${E.id}`)]})]})]})}var Hi=new Vt;function Ui(e,t,n){let r=Hi.get(n),i=!!r,a=e.scrollTop,o=()=>e.clientHeight>0&&e.clientWidth>0,s=()=>{if(!o())return;let r=e.getBoundingClientRect().top,i=[...t.querySelectorAll(`[data-cell-id]`)].find(e=>e.getBoundingClientRect().bottom>r);Hi.set(n,{cell:i?.dataset.cellId,offset:i?i.getBoundingClientRect().top-r:0,top:e.scrollTop,left:e.scrollLeft})},c=()=>{if(!i||!r||!o())return;let n=r.cell?t.querySelector(`[data-cell-id="${CSS.escape(r.cell)}"]`):null;e.scrollTop=n?e.scrollTop+n.getBoundingClientRect().top-e.getBoundingClientRect().top-r.offset:r.top,e.scrollLeft=r.left,a=e.scrollTop},l=()=>{i=!1},u=()=>{e.scrollTop!==a&&(i=!1),i||s()};c();let d=new ResizeObserver(c);d.observe(e),d.observe(t),e.addEventListener(`scroll`,u,{passive:!0});let f=[`wheel`,`touchstart`,`pointerdown`,`keydown`];for(let t of f)e.addEventListener(t,l,{passive:!0});return()=>{i||s(),d.disconnect(),e.removeEventListener(`scroll`,u);for(let t of f)e.removeEventListener(t,l)}}function Wi({text:e,session:t,path:n,root:r,onChange:i,onRun:a,running:o,onUndo:s,onRedo:c,onOpenFile:l,focused:u=!0}){let d=(0,R.useMemo)(()=>{try{return{notebook:Yr(qr(e)),error:null}}catch(e){return{notebook:null,error:e instanceof Error?e.message:`Invalid notebook`}}},[e]),[f,p]=(0,R.useState)([]),[m,h]=(0,R.useState)(null),g=(0,R.useRef)(!0),[_,v]=(0,R.useState)(null),[y,b]=(0,R.useState)(null),x=(0,R.useRef)(null),[S,T]=(0,R.useState)([]),E=(0,R.useRef)(null),D=(0,R.useRef)(null),O=(0,R.useRef)(null),k=Bt(`notebook`,[t,r,n]),A=d.notebook!==null;(0,R.useLayoutEffect)(()=>{if(!(!E.current||!D.current||!A))return Ui(E.current,D.current,k)},[k,A]),(0,R.useLayoutEffect)(()=>{if(!O.current)return;let e=D.current?.querySelector(`[data-cell-id="${CSS.escape(O.current)}"]`);e&&(e.scrollIntoView({block:`nearest`}),g.current&&e.focus({preventScroll:!0}),g.current=!0,O.current=null)});let j=e=>i?.(`${JSON.stringify(e,null,1)}\n`),M=d.notebook,ee=(0,R.useMemo)(()=>({session:t,path:n,...r===void 0?{}:{root:r}}),[t,n,r]),N=yi(ee,M,i?j:void 0,!!a),P=C(ee,M,i?j:void 0,!!a),F=N.execution?.input?N.execution.cells.find(e=>e.state===`running`)?.id:void 0;if((0,R.useLayoutEffect)(()=>{if(!M||!F||!f.length)return;let e=M.cells.findIndex(e=>e.id===F),t=f.filter(t=>{let n=M.cells.findIndex(e=>e.id===t);return n<0||!ri(M,n).includes(e)});t.length!==f.length&&p(t)},[M,F,f]),!M)return(0,z.jsx)(`p`,{className:`p-6 text-sm text-danger`,role:`alert`,children:d.error});let I=(e,t=!1)=>{let n=x.current??_??e,r=M.cells.findIndex(e=>e.id===n),i=M.cells.findIndex(t=>t.id===e);T(t?M.cells.slice(Math.min(r,i),Math.max(r,i)+1).map(e=>e.id):[e]),t||(x.current=e),v(e)},te=(e,t=!1,n=!1)=>{I(e,n),b(t?e:null),O.current=e},ne=ni(M),re=new Set(M.cells.flatMap((e,t)=>f.includes(e.id)?ri(M,t).slice(1):[])),{add:ie,replace:ae,execute:oe,operation:se,keyDown:ce}=oi({notebook:M,active:_,selected:S,update:j,choose:te,setEditing:b,run:N.run,onUndo:s,onRedo:c});return(0,z.jsx)(w.Provider,{value:P,children:(0,z.jsx)(bi.Provider,{value:{...ee,onOpenFile:l,intelligence:N.intelligenceSupported},children:(0,z.jsxs)(`div`,{className:`relative flex h-full min-h-0 flex-col bg-ground`,onKeyDown:i?ce:void 0,onCopy:e=>{i&&si(e,`copy`,M,S,j)},onCut:e=>{i&&si(e,`cut`,M,S,j)},onPaste:e=>{i&&si(e,`paste`,M,S,j)},children:[(0,z.jsx)(ui,{notebook:M,focused:u,onChange:i?j:void 0,onReveal:e=>{h(e),e&&(p([]),v(e.id),e.output||b(e.id),O.current=e.id,g.current=!1)}}),(0,z.jsx)(Ti,{notebook:M,source:{session:t,path:n,...r===void 0?{}:{root:r}},onChange:i?j:void 0,onAdd:ie,onRun:N.supported?()=>{N.run()}:a,onRunCopy:N.supported?a:void 0,running:o||N.busy,onRevealCell:e=>{p([]),te(M.cells[e].id)},onRunSection:N.supported?e=>{N.run(ri(M,e))}:void 0}),(0,z.jsx)(`div`,{ref:E,className:`min-h-0 flex-1 overflow-auto bg-ground text-fg`,children:(0,z.jsxs)(`div`,{ref:D,className:`mx-auto flex max-w-4xl flex-col gap-7 py-6 pr-6 pl-14`,children:[(0,z.jsxs)(`p`,{className:`text-xs text-fg-muted`,children:[M.cells.length,` cells`]}),P.saveWarning&&(0,z.jsx)(`p`,{role:`status`,className:`text-xs text-fg-muted`,children:P.saveWarning}),N.error&&(0,z.jsx)(`p`,{role:`alert`,className:`text-xs text-danger`,children:N.error}),M.cells.map((e,a)=>re.has(a)?null:(0,z.jsx)(Vi,{cell:e,match:m&&m.id===e.id?m:void 0,sectionCollapsed:f.includes(e.id),onToggleSection:ne[a]?.level?()=>p(t=>t.includes(e.id)?t.filter(t=>t!==e.id):[...t,e.id]):void 0,notebook:M,index:a,active:_===e.id,editing:y===e.id,selected:S.length>1&&S.includes(e.id),editable:!!i,onSelect:t=>I(e.id,t),onEdit:t=>{v(e.id),b(t?e.id:null)},onSource:e=>j(Jr(M,a,e)),onLanguage:t=>ae(a,Zr(e,t)),onInterrupt:()=>{N.interrupt()},execution:N.execution?.cells.find(t=>t.id===e.id)??ai(e),inputExecution:F===e.id?N.execution??void 0:void 0,inputSource:ee,onRun:N.supported?e=>{N.run(M.cells.flatMap((t,n)=>(e===`cell`?n===a:e===`above`?n<a:n>=a)?[n]:[]))}:void 0,onExecute:e=>oe(a,e),onOperation:e=>se(a,e),onSave:()=>{Ee(Te(t,n,r))},onSplit:t=>{if(M.cells.length>=2e3)return;let n=V(e.source),r={...Qr(e.cell_type),source:n.slice(t)},i=[...M.cells];i.splice(a,1,{...e,source:n.slice(0,t)},r),j({...M,cells:i}),te(r.id,!0)}},e.id)),i&&(0,z.jsx)(`div`,{className:`flex gap-3`,children:[`code`,`markdown`,`raw`].map(e=>(0,z.jsxs)(`button`,{disabled:M.cells.length>=2e3,className:`cursor-pointer rounded-sm p-1 text-fg-muted transition-colors hover:bg-elevated hover:text-fg disabled:cursor-default disabled:opacity-40 flex items-center gap-1.5 text-xs`,onClick:()=>ie(e,M.cells.length),children:[(0,z.jsx)(He,{className:`size-3.5`}),e===`code`?`Code`:e===`markdown`?`Markdown`:`Raw`,` cell`]},e))})]})})]})})})}var Gi=0;function Ki(e){let t=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,{acceptNode(e){let t=e.parentElement;return!e.textContent||t?.closest(`script, style, noscript, [hidden], [aria-hidden="true"]`)?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}}),n=[],r=``,i;for(;i=t.nextNode();){let e=i.textContent??``,t=r.length;r+=e,n.push({node:i,start:t,end:r.length})}return{text:r,nodes:n}}function qi(e,t){let n=t.find(t=>t.end>e.start),r=t.findLast(t=>t.start<e.end);if(!n||!r)return null;let i=document.createRange();return i.setStart(n.node,e.start-n.start),i.setEnd(r.node,e.end-r.start),i}var Ji=class{root;matchName=`puddle-find-${++Gi}-match`;activeName=`puddle-find-${Gi}-active`;style;signature=``;ranges=[];index=-1;limited=!1;constructor(e){this.root=e,this.style=document.createElement(`style`),this.style.textContent=`
|
|
5
|
+
`),output:!0}]:[]];for(let i of e){let e=et(i.text,t,r,Math.max(0,1e3-l.current.length));if(e.invalid)return{index:-1,count:0,invalid:!0};if(l.current.push(...e.matches.map(e=>({...e,id:n.id,output:i.output}))),l.current.length>=1e3)break}if(l.current.length>=1e3)break}if(d.current&&o){let e=l.current.findIndex(e=>e.id===o.id&&e.output===o.output&&e.start>=o.start);u.current=e>=0?e-1:-1}}let s=l.current.length;return u.current=s?(u.current+(a===`previous`?-1:1)+s)%s:-1,c.current=l.current[u.current]??null,d.current||n(c.current),{index:u.current,count:s,limited:s>=1e3}},onClear:()=>{c.current=null,n(null)}});(0,R.useEffect)(()=>{f.refresh()},[i,f.refresh]);let p=t=>{let n=Qe(f.query,f.options);if(!n||!r)return;let i=e;e.cells.forEach((e,r)=>{let a=V(e.source),s=c.current;t?i=Jr(i,r,a.replace(n,o)):s&&!s.output&&s.id===e.id&&(i=Jr(i,r,a.slice(0,s.start)+a.slice(s.start,s.end).replace(n,o)+a.slice(s.end)))}),r(i),l.current=[],c.current=null};return(0,R.useEffect)(()=>{d.current=c.current!==null,f.open&&f.refresh(),d.current=!1},[e,f.open,f.refresh]),(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(ci,{controls:f}),f.open&&(0,z.jsxs)(`div`,{className:`absolute right-2 top-10 z-30 flex max-w-full flex-wrap items-center gap-2 rounded-b-md bg-surface px-2 py-1.5 text-xs text-fg-secondary`,children:[(0,z.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-1`,children:[(0,z.jsx)(`input`,{type:`checkbox`,checked:i,onChange:e=>a(e.target.checked)}),`Include output`]}),r&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`input`,{"aria-label":`Replace in notebook`,value:o,onChange:e=>s(e.target.value),placeholder:`Replace`,className:`min-w-0 bg-ground px-2 py-1 outline-none`}),(0,z.jsx)(`button`,{type:`button`,className:`cursor-pointer hover:text-fg`,disabled:!f.query||!!c.current?.output,onClick:()=>p(!1),children:`Replace`}),(0,z.jsx)(`button`,{type:`button`,className:`cursor-pointer hover:text-fg`,disabled:!f.query,onClick:()=>p(!0),children:`Replace all`})]})]})]})}function di(e){return n({queryKey:[`notebook-kernels`],queryFn:()=>ne(`GET`,`/api/notebooks/kernels`),enabled:e,staleTime:3e4})}function fi(e,t){return n({queryKey:[`notebook-kernel`,e],queryFn:()=>ne(`POST`,`/api/notebooks/status`,{source:e}),enabled:t,refetchInterval:1500,retry:!1})}function pi(e){return ne(`POST`,`/api/notebooks/kernel`,e)}function mi(e,t){return n({queryKey:[`notebook-environments`,e],queryFn:()=>ne(`POST`,`/api/notebooks/environments`,{source:e}),enabled:t,staleTime:3e4,retry:!1})}var hi=u(250),gi=u(5e3),_i=e=>e?.execution?.state===`running`?hi():gi();function vi(e,t,n){let r=[`notebook-execution`,t],i=!0;return{queryKey:r,reset:()=>{i=!0},queryFn:async({signal:a})=>{let o=e.getQueryState(r),s=!i&&!o?.isInvalidated&&o?.status!==`error`?o?.data:void 0,c=s?.execution?{id:s.execution.id,revision:s.execution.revision}:null;try{let o=await ne(`POST`,`/api/notebooks/execution`,{source:t,...n&&s?{known:c}:{}},a);if(a.throwIfAborted(),`unchanged`in o){if(!s)throw Error(`Notebook observation has no matching snapshot`);return i=!1,e.getQueryData(r)??s}return i=!1,o}catch(e){throw i=!0,e}}}}function yi(e,t,a,l){let u=r(),d=l&&!v()&&c(u.data?.protocol),f=(0,R.useRef)({notebook:t,onChange:a});f.current={notebook:t,onChange:a};let p=s(),[m,h]=(0,R.useState)(!1),g=(0,R.useRef)(!1),[_,y]=(0,R.useState)(null),b=(0,R.useRef)(!0);(0,R.useEffect)(()=>(b.current=!0,()=>{b.current=!1}),[]);let x=i(u.data?.protocol),S=(0,R.useMemo)(()=>vi(p,e,x),[p,e.session,e.path,e.root,x]),C=S.queryKey;(0,R.useEffect)(()=>{if(d)return ft.onConnectionChange(e=>{S.reset(),e?p.invalidateQueries({queryKey:S.queryKey}):p.cancelQueries({queryKey:S.queryKey})})},[d,S,p]);let w=n({queryKey:C,queryFn:S.queryFn,refetchOnReconnect:()=>(S.reset(),`always`),enabled:d,retry:!1,refetchInterval:e=>_i(e.state.data)}),T=w.data?.execution;(0,R.useEffect)(()=>{if(!T||!f.current.notebook||!f.current.onChange)return;let e=ii(f.current.notebook,T);e!==f.current.notebook&&f.current.onChange(e)},[T]);let E=async t=>{let n=f.current.notebook;if(!d||!n||g.current||T?.state===`running`)return;let r=n.cells.flatMap((e,n)=>e.cell_type===`code`&&V(e.source).trim()&&(!t||t.includes(n))?[{id:e.id,source:V(e.source)}]:[]);if(r.length){g.current=!0,h(!0),y(null),f.current.onChange?.(n);try{let t=n.metadata.kernelspec,i=await ne(`POST`,`/api/notebooks/execute`,{source:e,cells:r,...t?.name?{kernel:t.name}:{}});await p.cancelQueries({queryKey:C}),b.current&&p.setQueryData(C,i)}catch(e){b.current&&y(e instanceof Error?e.message:`Notebook execution failed`)}finally{g.current=!1,b.current&&(h(!1),p.invalidateQueries({queryKey:C}))}}},D=(0,R.useRef)(E);return D.current=E,(0,R.useEffect)(()=>d?Se(e,()=>{D.current()}):void 0,[d,e.session,e.path,e.root]),{supported:d,intelligenceSupported:d&&o(u.data?.protocol),run:E,interrupt:async()=>{try{await pi({source:e,action:`interrupt`})}catch(e){b.current&&y(e instanceof Error?e.message:`Interrupt failed`)}finally{p.invalidateQueries({queryKey:C})}},execution:T,busy:m||T?.state===`running`,error:_??(w.error instanceof Error?w.error.message:T?.error)}}var bi=(0,R.createContext)(null);function xi({source:e,environment:t,current:n,kernels:r,pending:i,onAction:a}){let[o,s]=(0,R.useState)(!1),[c,l]=(0,R.useState)(``),u=(0,R.useId)(),d=mi(e,o),f=[...d.data?.environments??[]];t&&!f.some(e=>e.python===t.python)&&f.unshift(t);let p=e=>{s(!1),a(e)};return(0,z.jsxs)(Ct,{open:o,onOpenChange:s,children:[(0,z.jsx)(St,{asChild:!0,children:(0,z.jsxs)(`button`,{type:`button`,disabled:i,"aria-label":`Select Python environment`,title:t?.python??`Changing environments starts a fresh kernel`,className:`flex max-w-64 cursor-pointer items-center gap-1.5 rounded-sm px-2 py-1.5 text-xs text-fg-secondary hover:bg-surface hover:text-fg disabled:cursor-default disabled:opacity-40`,children:[(0,z.jsx)(mn,{className:`size-3.5 shrink-0`}),(0,z.jsx)(`span`,{className:`truncate`,children:t?.label??n?.display_name??`Select environment`})]})}),(0,z.jsxs)(xt,{align:`end`,className:`w-96 max-w-[calc(100vw-2rem)] p-3`,children:[(0,z.jsx)(`p`,{className:`mb-2 text-xs text-fg-muted`,children:`Python environments on this host`}),(0,z.jsxs)(`div`,{className:`max-h-64 overflow-y-auto`,"aria-label":`Python environments`,children:[d.isLoading&&(0,z.jsx)(`p`,{role:`status`,className:`py-2 text-xs text-fg-muted`,children:`Looking for environments…`}),d.isError&&(0,z.jsx)(`p`,{role:`alert`,className:`py-2 text-xs text-danger`,children:`Couldn’t discover environments. You can enter a path below.`}),d.data&&!f.length&&(0,z.jsx)(`p`,{className:`py-2 text-xs text-fg-muted`,children:`No Python environments found. Enter a path below.`}),f.map(n=>(0,z.jsxs)(`button`,{type:`button`,disabled:i,onClick:()=>p({source:e,action:`select-python`,python:n.python}),className:`flex w-full cursor-pointer items-center gap-2 rounded-sm px-2 py-2 text-left hover:bg-surface disabled:cursor-default disabled:opacity-40`,children:[(0,z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,z.jsx)(`p`,{className:`text-xs text-fg`,children:n.label}),(0,z.jsx)(`p`,{className:`break-all text-xs text-fg-muted`,children:n.python}),(n.error||!n.ipykernel||!n.nbconvert)&&(0,z.jsx)(`p`,{className:`text-xs text-fg-secondary`,children:n.error?`Couldn’t inspect this Python`:n.ipykernel?`nbconvert not installed`:`ipykernel not installed`})]}),t?.python===n.python&&(0,z.jsx)(qe,{className:`size-3.5 shrink-0 text-accent`})]},n.python)),r.length>0&&(0,z.jsx)(`p`,{className:`mb-1 mt-3 text-xs text-fg-muted`,children:`Registered Jupyter kernels`}),r.map(r=>(0,z.jsxs)(`button`,{type:`button`,disabled:i,className:`flex w-full cursor-pointer items-center justify-between rounded-sm px-2 py-2 text-left text-xs text-fg-secondary hover:bg-surface hover:text-fg`,onClick:()=>p({source:e,action:`select`,kernel:r.name}),children:[r.display_name,!t&&n?.name===r.name&&(0,z.jsx)(qe,{className:`size-3.5`})]},r.name))]}),(0,z.jsxs)(`form`,{className:`mt-3 flex flex-col gap-2`,onSubmit:t=>{t.preventDefault(),c.trim()&&p({source:e,action:`select-python`,python:c.trim()})},children:[(0,z.jsx)(`label`,{htmlFor:u,className:`text-xs text-fg-secondary`,children:`Environment folder or Python executable`}),(0,z.jsx)(ze,{id:u,value:c,onChange:e=>l(e.target.value),placeholder:`.venv, ~/miniforge3/envs/analysis, /path/to/python`,disabled:i}),(0,z.jsx)(`p`,{className:`text-xs text-fg-muted`,children:`Relative paths start beside this notebook. Switching starts fresh.`}),(0,z.jsx)(`button`,{type:`submit`,disabled:i||!c.trim(),className:`cursor-pointer self-end rounded-sm px-2 py-1.5 text-xs text-fg-secondary hover:bg-surface hover:text-fg disabled:cursor-default disabled:opacity-40`,children:`Use path`})]})]})]})}var Si=`flex cursor-pointer items-center gap-1.5 whitespace-nowrap rounded-sm px-2 py-1.5 text-xs text-fg-secondary transition-colors hover:bg-surface hover:text-fg disabled:cursor-default disabled:opacity-40`;function Ci({source:e,notebook:t,onSelect:n}){let i=(0,R.useRef)(n);i.current=n;let o=(0,R.useRef)(!0);(0,R.useEffect)(()=>(o.current=!0,()=>{o.current=!1}),[]);let c=r(),u=a(c.data?.protocol),d=l(c.data?.protocol),f=di(u),p=fi(e,u),m=s(),[h,g]=(0,R.useState)(null),_=h!==null,[v,y]=(0,R.useState)(null);if(!u)return null;let b=t.metadata.kernelspec,x=p.data?.kernel??(typeof b?.name==`string`?b.name:``),S=f.data?.kernels??[],C=S.find(e=>e.name===x),w=p.data?.environment,T=w&&!w.error?[!w.ipykernel&&`ipykernel`,!w.nbconvert&&`nbconvert`].filter(Boolean).join(` and `):``,E=p.data&&p.data.state!==`stopped`&&p.data.state!==`dead`,D=p.data?.state===`busy`||p.data?.state===`starting`,O=async t=>{g(t.action),y(null);try{let n=await pi(t);if(m.setQueryData([`notebook-kernel`,e],n),(t.action===`select-python`||t.action===`install-python`)&&(m.invalidateQueries({queryKey:[`notebook-environments`]}),o.current&&i.current({name:`python3`,display_name:`Python 3`,language:`python`})),t.action===`select`){let e=S.find(e=>e.name===t.kernel);e&&o.current&&i.current(e)}}catch(e){y(e instanceof Error?e.message:`Kernel operation failed`)}finally{g(null)}};return(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[D&&(0,z.jsxs)(`button`,{type:`button`,className:Si,disabled:_,onClick:()=>void O({source:e,action:`interrupt`}),children:[(0,z.jsx)(Me,{className:`size-3.5`}),`Interrupt`]}),(0,z.jsx)(`span`,{className:`text-xs text-fg-muted`,role:`status`,children:_?h===`install-python`?`Installing…`:`Updating…`:p.data?.state===`dead`?`Kernel exited`:D?`Busy`:E?`Idle`:``}),d?(0,z.jsx)(xi,{source:e,environment:w,current:C,kernels:S,pending:_,onAction:O}):(0,z.jsxs)(Ye,{value:C?.name??``,disabled:_||!f.data?.available||S.length===0,onValueChange:t=>void O({source:e,action:`select`,kernel:t}),children:[(0,z.jsxs)(Ge,{className:`h-7 max-w-52 gap-1.5 bg-transparent text-xs hover:bg-surface`,"aria-label":`Select kernel`,title:`Kernels stay alive until shut down. Changing kernels starts fresh.`,children:[(0,z.jsx)(mn,{className:`size-3.5 shrink-0`}),(0,z.jsx)(We,{placeholder:x?`${x} (not installed)`:`Select Kernel`})]}),(0,z.jsx)(Ke,{children:S.map(e=>(0,z.jsx)(Je,{value:e.name,detail:e.language,children:(0,z.jsx)(`span`,{children:e.display_name})},e.name))})]}),(0,z.jsxs)(je,{children:[(0,z.jsx)(Pe,{asChild:!0,children:(0,z.jsx)(`button`,{type:`button`,className:Si,disabled:_,"aria-label":`Kernel actions`,children:(0,z.jsx)(xe,{className:`size-3.5`})})}),(0,z.jsxs)(Ce,{align:`end`,children:[(0,z.jsxs)(be,{disabled:!C&&!w,onSelect:()=>void O({source:e,action:`restart`}),children:[(0,z.jsx)(rt,{}),`Restart kernel`]}),(0,z.jsxs)(be,{disabled:!E,onSelect:()=>void O({source:e,action:`shutdown`}),children:[(0,z.jsx)(ut,{}),`Shut down kernel`]})]})]})]}),T&&(0,z.jsxs)(`div`,{className:`flex w-full flex-wrap items-center gap-2 px-2 text-xs text-fg-muted`,children:[(0,z.jsxs)(`span`,{className:`break-all`,children:[T,` missing from `,w?.python,`.`]}),(0,z.jsxs)(`button`,{type:`button`,className:Si,disabled:_,onClick:()=>{w&&O({source:e,action:`install-python`,python:w.python})},children:[`Install `,T]})]}),(v||p.data?.error||!d&&(f.data?.error||f.isError)||p.isError)&&(0,z.jsx)(`p`,{role:`alert`,className:`w-full px-2 text-xs text-danger`,children:v??p.data?.error??f.data?.error??`Couldn’t load notebook kernels`}),!d&&f.data&&!f.data.available&&!f.data.error&&(0,z.jsx)(`p`,{className:`w-full px-2 text-xs text-fg-muted`,children:`Install Jupyter and a language kernel on this host to run notebooks.`})]})}var wi=`flex cursor-pointer items-center gap-1.5 whitespace-nowrap rounded-sm px-2 py-1.5 text-xs text-fg-secondary transition-colors hover:bg-surface hover:text-fg disabled:cursor-default disabled:opacity-40`;function Ti({notebook:e,source:t,onChange:n,onAdd:i,onRevealCell:o,onRun:s,onRunCopy:c,onRunSection:l,running:u=!1}){let[d,f]=(0,R.useState)(!1),p=r(),m=fi(t,!!s&&a(p.data?.protocol)),h=u||m.data?.state===`busy`||m.data?.state===`starting`,g=m.data?.environment,_=g&&(!g.ipykernel||!g.nbconvert),v=ni(e),y=e.cells.some(e=>e.cell_type===`code`&&((e.outputs?.length??0)>0||e.execution_count!=null));return(0,z.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-1 bg-ground px-3 py-2`,role:`toolbar`,"aria-label":`Notebook`,children:[n&&(0,z.jsxs)(ht,{label:`Add notebook cells`,children:[(0,z.jsxs)(`button`,{type:`button`,className:wi,disabled:e.cells.length>=2e3,onClick:()=>i(`code`),"aria-label":`Add code cell`,children:[(0,z.jsx)(He,{className:`size-3.5`}),`Code`]}),(0,z.jsxs)(`button`,{type:`button`,className:wi,disabled:e.cells.length>=2e3,onClick:()=>i(`markdown`),"aria-label":`Add Markdown cell`,children:[(0,z.jsx)(He,{className:`size-3.5`}),`Markdown`]})]}),(0,z.jsxs)(ht,{label:`Notebook actions`,className:`flex-wrap !rounded-[var(--ui-radius)]`,children:[s&&(0,z.jsxs)(`button`,{type:`button`,className:wi,disabled:h||_,onClick:s,children:[(0,z.jsx)(we,{className:`size-3.5`}),h?`Running…`:`Run All`]}),n&&(0,z.jsxs)(`button`,{type:`button`,className:wi,disabled:!y,onClick:()=>n(ti(e)),children:[(0,z.jsx)(Ve,{className:`size-3.5`}),`Clear All Outputs`]}),(0,z.jsxs)(Ct,{open:d,onOpenChange:f,children:[(0,z.jsx)(St,{asChild:!0,children:(0,z.jsxs)(`button`,{type:`button`,className:wi,disabled:v.length===0,children:[(0,z.jsx)(hn,{className:`size-3.5`}),`Outline`]})}),(0,z.jsx)(xt,{align:`start`,className:`max-h-72 w-72 overflow-y-auto p-1`,children:(0,z.jsx)(`nav`,{"aria-label":`Notebook outline`,className:`flex flex-col`,children:v.map(e=>(0,z.jsxs)(`div`,{className:`group/outline flex items-center`,style:{paddingLeft:`calc(var(--spacing) * ${Math.max(0,e.level-1)*3})`},children:[(0,z.jsxs)(`button`,{type:`button`,className:`${wi} min-w-0 flex-1 text-left`,onClick:()=>{o(e.index),f(!1)},children:[(0,z.jsx)(`span`,{className:`w-5 shrink-0 text-fg-muted`,children:e.index+1}),(0,z.jsx)(`span`,{className:`truncate`,children:e.label})]}),!!e.level&&l&&(0,z.jsx)(`button`,{type:`button`,disabled:h,title:`Run Section`,"aria-label":`Run section ${e.label}`,className:`${wi} opacity-0 group-hover/outline:opacity-100 focus:opacity-100 pointer-coarse:opacity-100`,onClick:()=>{l(e.index),f(!1)},children:(0,z.jsx)(we,{className:`size-3.5`})})]},e.index))})})]}),n&&(0,z.jsxs)(je,{children:[(0,z.jsx)(Pe,{asChild:!0,children:(0,z.jsx)(`button`,{type:`button`,className:wi,"aria-label":`More notebook actions`,children:(0,z.jsx)(xe,{className:`size-3.5`})})}),(0,z.jsxs)(Ce,{align:`start`,children:[c&&(0,z.jsx)(be,{disabled:h,onSelect:c,children:`Run to Executed Copy`}),(0,z.jsxs)(be,{disabled:e.cells.length>=2e3,onSelect:()=>i(`raw`),children:[(0,z.jsx)(He,{}),`Add raw cell`]})]})]})]}),n&&s&&(0,z.jsx)(Ci,{source:t,notebook:e,onSelect:t=>n({...e,metadata:{...e.metadata,kernelspec:t}})},JSON.stringify(t))]})}function Ei({code:e,onRun:t,busy:n,index:r,count:i,canMerge:a,onOperation:o}){let s=(e,t,n,r=!1)=>(0,z.jsx)(`button`,{type:`button`,className:`cursor-pointer rounded-sm p-1 text-fg-muted hover:bg-elevated hover:text-fg disabled:cursor-default disabled:opacity-40`,title:e,"aria-label":e,onClick:n,disabled:r,children:t});return(0,z.jsxs)(`div`,{className:`ml-auto flex flex-wrap items-center opacity-0 focus-within:opacity-100 group-hover/cell:opacity-100 pointer-coarse:opacity-100`,children:[e&&t&&(0,z.jsxs)(z.Fragment,{children:[s(`Run Cell`,(0,z.jsx)(we,{className:`size-3.5`}),()=>t(`cell`),n),s(`Run Above`,(0,z.jsx)(fn,{className:`size-3.5`}),()=>t(`above`),n||r===0),s(`Run Cell and Below`,(0,z.jsx)(dn,{className:`size-3.5`}),()=>t(`below`),n)]}),s(`Insert cell below`,(0,z.jsx)(He,{className:`size-3.5`}),()=>o(`insert`),i>=2e3),s(`Duplicate cell`,(0,z.jsx)(nt,{className:`size-3.5`}),()=>o(`duplicate`),i>=2e3),s(`Merge with next cell`,(0,z.jsx)(pn,{className:`size-3.5`}),()=>o(`merge`),!a),s(`Move cell up`,(0,z.jsx)(Ne,{className:`size-3.5`}),()=>o(`up`),r===0),s(`Move cell down`,(0,z.jsx)(Ue,{className:`size-3.5`}),()=>o(`down`),r===i-1),s(`Delete cell`,(0,z.jsx)(Ve,{className:`size-3.5`}),()=>o(`delete`))]})}function Di(e,t){let n=async(n,r,i)=>{let a=e.getValue();if(a.length>65536||i.isCancellationRequested)return null;let o=e.getVersionId();try{let s=await ne(`POST`,`/api/notebooks/intelligence`,{source:t,kind:n,code:a,cursor:[...a.slice(0,e.getOffsetAt(r))].length});return i.isCancellationRequested||e.isDisposed()||o!==e.getVersionId()?null:{response:s,code:a}}catch{return null}},r=()=>{let t=e.getLanguageId();return t===`markdown`||t===`plaintext`?[]:[P.registerCompletionItemProvider(t,{triggerCharacters:[`.`],async provideCompletionItems(t,r,i,a){if(t!==e)return{suggestions:[]};let o=await n(`complete`,r,a);if(!o)return{suggestions:[]};let{response:s,code:c}=o,l=e.getPositionAt([...c].slice(0,s.start).join(``).length),u=e.getPositionAt([...c].slice(0,s.end).join(``).length),d=new N(l.lineNumber,l.column,u.lineNumber,u.column);return{suggestions:s.matches.map(e=>({label:e,insertText:e,kind:P.CompletionItemKind.Text,range:d}))}}}),P.registerHoverProvider(t,{async provideHover(t,r,i){if(t!==e)return null;let a=await n(`inspect`,r,i);return a?.response.documentation?{contents:[{value:a.response.documentation.replace(/\u001b\[[0-?]*[ -/]*[@-~]/g,``).replace(/[\\`*_{}[\]()#+.!<>-]/g,`\\$&`),isTrusted:!1,supportHtml:!1}]}:null}})]},i=r(),a=e.onDidChangeLanguage(()=>{i.forEach(e=>e.dispose()),i=r()});return{dispose(){a.dispose(),i.forEach(e=>e.dispose())}}}function Oi({value:e,language:t,label:n,focus:r,onChange:i,onExecute:a,onEscape:o,onSplit:s,onSave:c,match:l}){let u=T(),d=Math.round(u.editorFontSize*1.5),f=(0,R.useContext)(bi),[p,m]=(0,R.useState)(null);(0,R.useEffect)(()=>{if(!p||!f?.intelligence)return;let e=Di(p,{session:f.session,path:f.path,...f.root?{root:f.root}:{}});return()=>e.dispose()},[p,f?.intelligence,f?.session,f?.path,f?.root]);let h=(0,R.useRef)(null),g=(0,R.useRef)(null),_=(0,R.useRef)(null),v=(0,R.useRef)(!1),y=(0,R.useRef)(null),b=(0,R.useRef)({onChange:i,onExecute:a,onEscape:o,onSplit:s,onSave:c});b.current={onChange:i,onExecute:a,onEscape:o,onSplit:s,onSave:c};let x=(0,R.useRef)(r);x.current=r;let S=(0,R.useRef)(l);S.current=l;let C=e=>{let t=e.getModel(),n=S.current;if(!t||!n)return;let r=t.getPositionAt(n.start),i=t.getPositionAt(n.end);e.setSelection(new N(r.lineNumber,r.column,i.lineNumber,i.column)),e.revealPositionInCenter(r)};(0,R.useEffect)(()=>{g.current&&C(g.current)},[l]);let[w,E]=(0,R.useState)(!1),[D,O]=(0,R.useState)(!1),[k,A]=(0,R.useState)(Math.max(64,e.split(`
|
|
6
|
+
`).length*d+24));return(0,R.useEffect)(()=>{let e=new IntersectionObserver(([e])=>E(!!e?.isIntersecting),{rootMargin:`600px`});return h.current&&e.observe(h.current),()=>e.disconnect()},[]),(0,R.useEffect)(()=>()=>{_.current?.dispose()},[]),(0,R.useEffect)(()=>{let n=_.current;n&&n.getValue()!==e&&(v.current=!0,n.pushEditOperations([],[{range:n.getFullModelRange(),text:e}],()=>null),v.current=!1),n&&I.setModelLanguage(n,t)},[e,t]),(0,R.useEffect)(()=>{r&&g.current?.focus()},[r]),(0,z.jsxs)(`div`,{ref:h,style:{height:k},className:`relative min-w-0 rounded-md`,onWheelCapture:e=>{!e.shiftKey&&Math.abs(e.deltaY)>=Math.abs(e.deltaX)&&!e.target.closest(`.overflowingContentWidgets,.overflowingOverlayWidgets,.contentWidgets,.overlayWidgets`)&&e.stopPropagation()},children:[!p&&(0,z.jsx)(`pre`,{"aria-hidden":`true`,className:`absolute inset-0 overflow-hidden px-2 py-3 font-mono text-fg`,style:{fontSize:u.editorFontSize,lineHeight:`${d}px`,whiteSpace:u.editorWordWrap?`pre-wrap`:`pre`},children:e}),(w||r||D)&&(0,z.jsx)(jt,{loading:null,theme:`puddle`,defaultValue:e,defaultLanguage:t,keepCurrentModel:!0,saveViewState:!1,onMount:e=>{if(_.current){let t=e.getModel();e.setModel(_.current),t!==_.current&&t?.dispose()}else _.current=e.getModel();g.current=e,m(e.getModel()),sr(e,{onSave:()=>b.current.onSave()}),y.current&&e.restoreViewState(y.current),e.setScrollTop(0);let t=!1,n=()=>{if(t||!h.current||!h.current.clientWidth)return;t=!0,e.layout({width:h.current.clientWidth,height:h.current.clientHeight});let n=Math.max(64,e.getContentHeight());h.current.style.height=`${n}px`,e.layout({width:h.current.clientWidth,height:n}),A(n),t=!1},r=e.onDidContentSizeChange(n),i=new ResizeObserver(n);i.observe(h.current);let a=e.onDidFocusEditorWidget(()=>O(!0)),o=e.onDidBlurEditorWidget(()=>O(!1)),s=e.onDidChangeModelContent(()=>{v.current||b.current.onChange(e.getValue())}),c=e.onDidScrollChange(()=>{y.current=e.saveViewState()}),l=e.onDidChangeCursorSelection(()=>{y.current=e.saveViewState()});e.addCommand(F.CtrlCmd|te.Enter,()=>b.current.onExecute(`stay`)),e.addCommand(F.Shift|te.Enter,()=>b.current.onExecute(`next`)),e.addCommand(F.Alt|te.Enter,()=>b.current.onExecute(`insert`)),e.addCommand(te.Escape,()=>b.current.onEscape(),`!suggestWidgetVisible && !findWidgetVisible`),e.addCommand(F.CtrlCmd|F.Shift|te.Minus,()=>{let t=e.getPosition();t&&b.current.onSplit(e.getModel().getOffsetAt(t))}),e.onDidDispose(()=>{r.dispose(),i.disconnect(),a.dispose(),o.dispose(),c.dispose(),l.dispose(),s.dispose(),g.current=null,m(null)}),n(),C(e),x.current&&e.focus()},beforeMount:()=>{_.current&&I.setModelLanguage(_.current,t)},options:{ariaLabel:n,automaticLayout:!1,fontFamily:getComputedStyle(document.documentElement).getPropertyValue(`--font-mono`).trim(),fontSize:u.editorFontSize,lineHeight:d,...In(u.editorTabSize),wordWrap:u.editorWordWrap?`on`:`off`,minimap:{enabled:!1},glyphMargin:!1,folding:!0,lineNumbers:`off`,lineDecorationsWidth:8,lineNumbersMinChars:3,scrollBeyondLastLine:!1,fixedOverflowWidgets:!0,padding:{top:12,bottom:12},renderLineHighlight:`none`,occurrencesHighlight:`off`,scrollbar:{alwaysConsumeMouseWheel:!1,vertical:`hidden`}},onChange:()=>{g.current&&(y.current=g.current.saveViewState())}})]})}function ki({language:e,onChange:t}){let[n,r]=(0,R.useState)(!1),i=[`markdown`,`raw`,...P.getLanguages().map(e=>e.id).filter(e=>e!==`markdown`).sort()];return(0,z.jsxs)(Ct,{open:n,onOpenChange:r,children:[(0,z.jsx)(St,{asChild:!0,children:(0,z.jsxs)(`button`,{type:`button`,"aria-label":`Cell language: ${e}`,className:`flex cursor-pointer items-center gap-1 font-mono text-xs text-fg-muted hover:text-fg`,children:[e,(0,z.jsx)(Xe,{className:`size-3`})]})}),(0,z.jsxs)(xt,{align:`start`,className:`w-56 p-0`,children:[(0,z.jsxs)(bt,{children:[(0,z.jsx)(gt,{placeholder:`Find a language…`}),(0,z.jsxs)(yt,{children:[(0,z.jsx)(vt,{children:`No matching languages`}),i.map(e=>(0,z.jsx)(_t,{onSelect:()=>{t(e),r(!1)},children:e},e))]})]}),(0,z.jsx)(`p`,{className:`px-3 py-2 text-xs text-fg-muted`,children:`Code languages set highlighting. Execution uses the notebook kernel.`})]})]})}async function Ai(e,t,n){let r=`path=${encodeURIComponent(t)}${ae(n)}`,i=v();return i?Mi(i,async()=>{if(v()!==i)throw Error(`Preview host changed`);let t=h.parse(await ne(`GET`,`/api/worktrees/${e}/preview-asset?${r}`));return new Blob([Uint8Array.from(atob(t.data),e=>e.charCodeAt(0))],{type:t.mime})}):(await re(`GET`,`/api/worktrees/${e}/media?${r}`)).blob()}var ji=new WeakMap;async function Mi(e,t){let n=ji.get(e);if(n||(n={active:0,waiting:[]},ji.set(e,n)),n.waiting.length>=128)throw Error(`Too many preview assets`);n.active>=2?await new Promise(e=>n.waiting.push(e)):n.active+=1;try{return await t()}finally{let e=n.waiting.shift();e?e():--n.active}}function Ni(e,t,n,r,i){(0,R.useEffect)(()=>{let t=e.current;if(!t)return;let a=!1,o=[],s=async e=>{try{let t=await Ai(n,e,i);if(a)return null;let r=URL.createObjectURL(t);return o.push(r),r}catch{return null}};for(let e of t.querySelectorAll(`img[src], source[src]`)){let t=ct(r,e.getAttribute(`src`)??``);t&&(e.removeAttribute(`src`),s(t).then(t=>{!a&&t&&e.setAttribute(`src`,t)}))}for(let e of t.querySelectorAll(`img[srcset], source[srcset]`)){let t=lt(e.getAttribute(`srcset`)??``),n=t.map(({ref:e})=>ct(r,e));n.some(e=>e!==null)&&(e.removeAttribute(`srcset`),Promise.all(t.map(async(e,t)=>{let r=n[t];if(!r)return e;let i=await s(r);return i?{...e,ref:i}:null})).then(t=>{if(a)return;let n=t.filter(e=>e!==null);n.length>0&&e.setAttribute(`srcset`,at(n))}))}return()=>{a=!0;for(let e of o)URL.revokeObjectURL(e)}},[t,e,n,r,i])}var Pi=(0,R.lazy)(()=>j(()=>import(`./NotebookWidget-C25iz3Cj.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9])));function Fi(e,t){return!t||typeof t!=`object`?e:e.replace(/attachment:([^\s"')>]+)/g,(e,n)=>{try{let r=t[decodeURIComponent(n)];if(!r||typeof r!=`object`)return e;for(let e of[`image/png`,`image/jpeg`,`image/gif`,`image/webp`]){let t=V(r[e]).replace(/\s/g,``);if(t&&/^[A-Za-z0-9+/]*={0,2}$/.test(t))return`data:${e};base64,${t}`}}catch{}return e})}function Ii({text:e,markdown:t=!1,attachments:n}){let r=(0,R.useContext)(bi),i=(0,R.useRef)(null),a=(0,R.useId)().replace(/[^a-zA-Z0-9_-]/g,``),o=(0,R.useSyncExternalStore)(k,O,O),s=(0,R.useMemo)(()=>M.sanitize(t?Yt(Fi(e,n),a):e,{FORBID_TAGS:[`style`,`iframe`,`form`,`input`,`button`],...t?{}:{FORBID_ATTR:[`style`]}}),[e,t,n,a]),c=(0,R.useMemo)(()=>({__html:s}),[s,o]);return Ni(i,s,r?.session??``,r?.path??``,r?.root),(0,R.useEffect)(()=>{let e=new AbortController;return i.current&&t&&un(i.current,o,e.signal),()=>e.abort()},[s,o,t]),(0,z.jsx)(`div`,{ref:i,className:`md-preview overflow-x-auto text-sm`,dangerouslySetInnerHTML:c,onClick:e=>{let t=e.target.closest(`a`);if(!t)return;let n=t.getAttribute(`href`)??``;if(/^https?:/i.test(n)){e.preventDefault(),window.open(n,`_blank`,`noopener,noreferrer`);return}if(n.startsWith(`#`)){e.preventDefault();try{i.current?.querySelector(`#${CSS.escape(decodeURIComponent(n.slice(1)))}`)?.scrollIntoView({block:`nearest`})}catch{}return}let a=r?ct(r.path,n):null;a&&(e.preventDefault(),(e.metaKey||e.ctrlKey)&&r?.onOpenFile?.(a))}})}var Li=`cursor-pointer rounded-sm p-1 text-fg-muted hover:bg-surface hover:text-fg`;function Ri({output:e}){let t=null;for(let n of[`image/png`,`image/jpeg`,`image/gif`,`image/webp`]){let r=V(e.data?.[n]).replace(/\s/g,``);if(r&&/^[A-Za-z0-9+/]*={0,2}$/.test(r)){try{t={src:`data:${n};base64,${r}`,blob:new Blob([Uint8Array.from(atob(r),e=>e.charCodeAt(0))],{type:n}),extension:n.split(`/`)[1]}}catch{}if(t)break}}let n=V(e.data?.[`image/svg+xml`]),r=n?M.sanitize(n,{USE_PROFILES:{svg:!0,svgFilters:!0},FORBID_TAGS:[`style`,`foreignObject`,`image`,`use`],FORBID_ATTR:[`style`,`href`,`xlink:href`]}):``,i=V(e.data?.[`text/html`]),a=V(e.data?.[`text/markdown`]),o=e.data?.[`application/json`],s=e.data?.[`application/vnd.jupyter.widget-view+json`],c=s&&typeof s==`object`&&`model_id`in s&&typeof s.model_id==`string`?s.model_id:null,l=$r(e)||(o===void 0?``:JSON.stringify(o,null,2))||`This output format cannot be displayed.`;return(0,z.jsxs)(`div`,{className:`group/output relative`,children:[(0,z.jsxs)(`div`,{className:`absolute right-1 top-0 z-10 flex gap-1 bg-ground opacity-0 group-hover/output:opacity-100 focus-within:opacity-100 pointer-coarse:opacity-100`,children:[(0,z.jsx)(`button`,{type:`button`,title:`Copy output`,"aria-label":`Copy output`,className:Li,onClick:()=>{navigator.clipboard.writeText(l).catch(()=>L.error(`Could not copy output`))},children:(0,z.jsx)(nt,{className:`size-3.5`})}),(t||r)&&(0,z.jsx)(`button`,{type:`button`,title:`Save image`,"aria-label":`Save image`,className:Li,onClick:()=>ke(t?.blob??new Blob([r],{type:`image/svg+xml`}),`notebook-output.${t?.extension??`svg`}`),children:(0,z.jsx)(Ae,{className:`size-3.5`})})]}),c?(0,z.jsx)(R.Suspense,{fallback:(0,z.jsx)(`p`,{className:`text-xs text-fg-muted`,children:`Loading widget…`}),children:(0,z.jsx)(Pi,{modelId:c,fallback:$r(e)})}):t?(0,z.jsx)(`img`,{src:t.src,alt:`Notebook output`,className:`max-w-full`}):r?(0,z.jsx)(`div`,{dangerouslySetInnerHTML:{__html:r}}):i?(0,z.jsx)(Ii,{text:i}):a?(0,z.jsx)(Ii,{text:a,markdown:!0}):(0,z.jsx)(`pre`,{className:`overflow-x-auto whitespace-pre-wrap font-mono text-sm ${e.output_type===`error`?`text-danger`:`text-fg-secondary`}`,children:l})]})}function zi({source:e,execution:t,onInterrupt:n}){let r=(0,R.useRef)(null),i=(0,R.useRef)(!1),[a,o]=(0,R.useState)(``),[s,c]=(0,R.useState)(!1),[l,u]=(0,R.useState)(null),d=t.input;return(0,R.useEffect)(()=>{r.current?.focus({preventScroll:!0}),r.current?.scrollIntoView({block:`nearest`})},[]),d?(0,z.jsxs)(`form`,{className:`mt-2 font-mono text-sm text-fg-secondary`,"aria-busy":s,onSubmit:n=>{n.preventDefault(),!i.current&&(i.current=!0,c(!0),u(null),ne(`POST`,`/api/notebooks/input`,{source:e,run_id:t.id,input_id:d.id,value:a}).then(()=>{d.password&&o(``)}).catch(e=>{u(e instanceof Error?e.message:`Input failed`),i.current=!1,c(!1)}))},children:[(0,z.jsxs)(`label`,{className:`flex min-w-0 flex-wrap items-baseline`,children:[(0,z.jsx)(`span`,{className:`whitespace-pre-wrap break-words`,children:d.prompt}),(0,z.jsx)(`input`,{ref:r,"aria-label":d.prompt||`Kernel input`,type:d.password?`password`:`text`,value:a,readOnly:s,maxLength:65536,autoComplete:`off`,autoCapitalize:`off`,spellCheck:!1,onChange:e=>o(e.target.value),onKeyDown:e=>{n&&e.ctrlKey&&!e.metaKey&&!e.altKey&&!e.shiftKey&&e.key.toLowerCase()===`c`&&e.currentTarget.selectionStart===e.currentTarget.selectionEnd&&(e.preventDefault(),e.stopPropagation(),n())},className:`min-w-16 flex-1 cursor-text bg-transparent p-0 text-fg outline-none read-only:opacity-60`})]}),l&&(0,z.jsx)(`p`,{role:`alert`,className:`mt-1 text-xs text-danger`,children:l})]}):null}var Bi=`cursor-pointer rounded-sm p-1 text-fg-muted transition-colors hover:bg-elevated hover:text-fg disabled:cursor-default disabled:opacity-40`;function Vi({cell:e,notebook:t,index:n,active:r,editing:i,selected:a,editable:o,onSelect:s,onEdit:c,onSource:l,onLanguage:u,onExecute:d,onRun:f,onInterrupt:p,onOperation:m,onSplit:h,onSave:g,execution:_,inputExecution:v,inputSource:y,match:b,onToggleSection:x,sectionCollapsed:S}){let C=(0,R.useRef)(null),[w,T]=(0,R.useState)(!1),E=y?v?.input:void 0;(0,R.useEffect)(()=>{(b?.output||E)&&T(!1)},[b,E]);let D=w&&!E,O=e.cell_type===`code`,k=V(e.source),A=_?.state===`running`||_?.state===`queued`,j=Xr(e,t),M=(e,t,n,r=!1)=>(0,z.jsx)(`button`,{type:`button`,className:Bi,title:e,"aria-label":e,onClick:n,disabled:r,children:t});return(0,z.jsxs)(`section`,{ref:C,"data-notebook-cell":n,"data-cell-id":e.id,tabIndex:r?0:-1,"aria-label":`Cell ${n+1}`,"aria-current":r||void 0,className:`group/cell relative min-w-0 outline-none`,onMouseDown:e=>{e.shiftKey&&!e.target.closest(`.monaco-editor,input,button`)&&e.preventDefault()},onFocus:()=>{r||s(!1)},onClick:e=>{if((e.metaKey||e.ctrlKey)&&O&&!e.target.closest(`.monaco-editor,a,button,input`)){e.preventDefault(),f?.(`cell`);return}e.target.closest(`button,input,[role=option]`)||s(e.shiftKey&&!e.target.closest(`.monaco-editor`))},children:[(0,z.jsx)(`div`,{className:`absolute -left-10 top-9 w-9 text-center font-mono text-xs text-fg-muted`,children:(0,z.jsxs)(`button`,{type:`button`,className:`${Bi} group/run relative w-full`,disabled:!o||O&&(!f||!A&&!k.trim()),title:O?A?`Interrupt execution`:`Run Cell (⌘/Ctrl+Enter)`:i?`Show rendered cell`:`Edit cell source`,"aria-label":O?A?`Interrupt execution`:`Run Cell`:i?`Show rendered cell`:`Edit cell source`,onClick:()=>{O?A?p?.():f?.(`cell`):c(!i)},children:[(0,z.jsx)(`span`,{className:O&&f?`group-hover/run:invisible group-focus-visible/run:invisible`:``,children:O?`[${A?`*`:e.execution_count??` `}]`:i?`[›]`:`[ ]`}),O&&f&&(A?(0,z.jsx)(Me,{className:`absolute inset-0 m-auto hidden size-3.5 group-hover/run:block group-focus-visible/run:block`}):(0,z.jsx)(we,{className:`absolute inset-0 m-auto hidden size-3.5 group-hover/run:block group-focus-visible/run:block`}))]})}),(0,z.jsxs)(`div`,{className:`mb-2 flex min-h-7 items-center gap-2 text-xs text-fg-muted`,children:[x&&M(S?`Expand section`:`Fold section`,S?(0,z.jsx)(Be,{className:`size-3`}):(0,z.jsx)(Xe,{className:`size-3`}),x),o?(0,z.jsx)(ki,{language:e.cell_type===`raw`?`raw`:j,onChange:u}):(0,z.jsx)(`span`,{className:`font-mono`,children:e.cell_type===`raw`?`raw`:j}),_&&(0,z.jsxs)(`span`,{role:`status`,children:[_.state,_.elapsed_ms===void 0?``:` · ${(_.elapsed_ms/1e3).toFixed(1)}s`]}),_&&_.source!==k&&(0,z.jsx)(`span`,{title:`The source changed after this execution`,children:`Source changed`}),o&&(0,z.jsx)(Ei,{code:O,onRun:f,busy:A,index:n,count:t.cells.length,canMerge:e.cell_type===t.cells[n+1]?.cell_type,onOperation:m})]}),(0,z.jsx)(`div`,{className:O||i||e.cell_type===`raw`?`rounded-[var(--ui-radius)] p-3 ${a?`bg-elevated`:`bg-surface`}`:void 0,children:o&&(O||i)?(0,z.jsx)(Oi,{value:k,match:b&&!b.output?b:void 0,language:j,label:`Cell ${n+1} source`,focus:r&&i&&!b,onChange:e=>{e!==k&&l(e)},onExecute:d,onEscape:()=>{c(!1),C.current?.focus()},onSave:g,onSplit:h}):e.cell_type===`markdown`?(0,z.jsx)(`div`,{onDoubleClick:()=>{o&&c(!0)},className:o?`cursor-text`:``,children:(0,z.jsx)(Ii,{text:k,markdown:!0,attachments:e.attachments})}):(0,z.jsx)(`pre`,{className:`overflow-x-auto whitespace-pre-wrap font-mono text-sm`,onDoubleClick:()=>{o&&c(!0)},children:k})}),(!!e.outputs?.length||E)&&(0,z.jsxs)(`div`,{className:`mt-2`,role:`group`,"aria-label":`Cell ${n+1} output`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-fg-muted`,children:[M(D?`Expand output`:`Collapse output`,D?(0,z.jsx)(Be,{className:`size-3`}):(0,z.jsx)(Xe,{className:`size-3`}),()=>T(!w),!!E),(0,z.jsx)(`span`,{children:`Output`}),o&&M(`Clear cell output`,(0,z.jsx)(Ve,{className:`size-3`}),()=>m(`clear`))]}),!D&&(0,z.jsxs)(`div`,{className:`mt-2 max-h-96 overflow-auto rounded-[var(--ui-radius)] bg-surface p-3`,children:[e.outputs?.map((e,t)=>(0,z.jsx)(`div`,{className:`mt-2 first:mt-0`,children:(0,z.jsx)(Ri,{output:e})},t)),E&&v&&y&&(0,z.jsx)(zi,{source:y,execution:v,onInterrupt:p},`${v.id}:${E.id}`)]})]})]})}var Hi=new Vt;function Ui(e,t,n){let r=Hi.get(n),i=!!r,a=e.scrollTop,o=()=>e.clientHeight>0&&e.clientWidth>0,s=()=>{if(!o())return;let r=e.getBoundingClientRect().top,i=[...t.querySelectorAll(`[data-cell-id]`)].find(e=>e.getBoundingClientRect().bottom>r);Hi.set(n,{cell:i?.dataset.cellId,offset:i?i.getBoundingClientRect().top-r:0,top:e.scrollTop,left:e.scrollLeft})},c=()=>{if(!i||!r||!o())return;let n=r.cell?t.querySelector(`[data-cell-id="${CSS.escape(r.cell)}"]`):null;e.scrollTop=n?e.scrollTop+n.getBoundingClientRect().top-e.getBoundingClientRect().top-r.offset:r.top,e.scrollLeft=r.left,a=e.scrollTop},l=()=>{i=!1},u=()=>{e.scrollTop!==a&&(i=!1),i||s()};c();let d=new ResizeObserver(c);d.observe(e),d.observe(t),e.addEventListener(`scroll`,u,{passive:!0});let f=[`wheel`,`touchstart`,`pointerdown`,`keydown`];for(let t of f)e.addEventListener(t,l,{passive:!0});return()=>{i||s(),d.disconnect(),e.removeEventListener(`scroll`,u);for(let t of f)e.removeEventListener(t,l)}}function Wi({text:e,session:t,path:n,root:r,onChange:i,onRun:a,running:o,onUndo:s,onRedo:c,onOpenFile:l,focused:u=!0}){let d=(0,R.useMemo)(()=>{try{return{notebook:Yr(qr(e)),error:null}}catch(e){return{notebook:null,error:e instanceof Error?e.message:`Invalid notebook`}}},[e]),[f,p]=(0,R.useState)([]),[m,h]=(0,R.useState)(null),g=(0,R.useRef)(!0),[_,v]=(0,R.useState)(null),[y,b]=(0,R.useState)(null),x=(0,R.useRef)(null),[S,T]=(0,R.useState)([]),E=(0,R.useRef)(null),D=(0,R.useRef)(null),O=(0,R.useRef)(null),k=Bt(`notebook`,[t,r,n]),A=d.notebook!==null;(0,R.useLayoutEffect)(()=>{if(!(!E.current||!D.current||!A))return Ui(E.current,D.current,k)},[k,A]),(0,R.useLayoutEffect)(()=>{if(!O.current)return;let e=D.current?.querySelector(`[data-cell-id="${CSS.escape(O.current)}"]`);e&&(e.scrollIntoView({block:`nearest`}),g.current&&e.focus({preventScroll:!0}),g.current=!0,O.current=null)});let j=e=>i?.(`${JSON.stringify(e,null,1)}\n`),M=d.notebook,ee=(0,R.useMemo)(()=>({session:t,path:n,...r===void 0?{}:{root:r}}),[t,n,r]),N=yi(ee,M,i?j:void 0,!!a),P=C(ee,M,i?j:void 0,!!a),F=N.execution?.input?N.execution.cells.find(e=>e.state===`running`)?.id:void 0;if((0,R.useLayoutEffect)(()=>{if(!M||!F||!f.length)return;let e=M.cells.findIndex(e=>e.id===F),t=f.filter(t=>{let n=M.cells.findIndex(e=>e.id===t);return n<0||!ri(M,n).includes(e)});t.length!==f.length&&p(t)},[M,F,f]),!M)return(0,z.jsx)(`p`,{className:`p-6 text-sm text-danger`,role:`alert`,children:d.error});let I=(e,t=!1)=>{let n=x.current??_??e,r=M.cells.findIndex(e=>e.id===n),i=M.cells.findIndex(t=>t.id===e);T(t?M.cells.slice(Math.min(r,i),Math.max(r,i)+1).map(e=>e.id):[e]),t||(x.current=e),v(e)},te=(e,t=!1,n=!1)=>{I(e,n),b(t?e:null),O.current=e},ne=ni(M),re=new Set(M.cells.flatMap((e,t)=>f.includes(e.id)?ri(M,t).slice(1):[])),{add:ie,replace:ae,execute:oe,operation:se,keyDown:ce}=oi({notebook:M,active:_,selected:S,update:j,choose:te,setEditing:b,run:N.run,onUndo:s,onRedo:c});return(0,z.jsx)(w.Provider,{value:P,children:(0,z.jsx)(bi.Provider,{value:{...ee,onOpenFile:l,intelligence:N.intelligenceSupported},children:(0,z.jsxs)(`div`,{className:`relative flex h-full min-h-0 flex-col bg-ground`,onKeyDown:i?ce:void 0,onCopy:e=>{i&&si(e,`copy`,M,S,j)},onCut:e=>{i&&si(e,`cut`,M,S,j)},onPaste:e=>{i&&si(e,`paste`,M,S,j)},children:[(0,z.jsx)(ui,{notebook:M,focused:u,onChange:i?j:void 0,onReveal:e=>{h(e),e&&(p([]),v(e.id),e.output||b(e.id),O.current=e.id,g.current=!1)}}),(0,z.jsx)(Ti,{notebook:M,source:{session:t,path:n,...r===void 0?{}:{root:r}},onChange:i?j:void 0,onAdd:ie,onRun:N.supported?()=>{N.run()}:a,onRunCopy:N.supported?a:void 0,running:o||N.busy,onRevealCell:e=>{p([]),te(M.cells[e].id)},onRunSection:N.supported?e=>{N.run(ri(M,e))}:void 0}),(0,z.jsx)(`div`,{ref:E,className:`min-h-0 flex-1 overflow-auto bg-ground text-fg`,children:(0,z.jsxs)(`div`,{ref:D,className:`mx-auto flex max-w-4xl flex-col gap-7 py-6 pr-6 pl-14`,children:[(0,z.jsxs)(`p`,{className:`text-xs text-fg-muted`,children:[M.cells.length,` cells`]}),P.saveWarning&&(0,z.jsx)(`p`,{role:`status`,className:`text-xs text-fg-muted`,children:P.saveWarning}),N.error&&(0,z.jsx)(`p`,{role:`alert`,className:`text-xs text-danger`,children:N.error}),M.cells.map((e,a)=>re.has(a)?null:(0,z.jsx)(Vi,{cell:e,match:m&&m.id===e.id?m:void 0,sectionCollapsed:f.includes(e.id),onToggleSection:ne[a]?.level?()=>p(t=>t.includes(e.id)?t.filter(t=>t!==e.id):[...t,e.id]):void 0,notebook:M,index:a,active:_===e.id,editing:y===e.id,selected:S.length>1&&S.includes(e.id),editable:!!i,onSelect:t=>I(e.id,t),onEdit:t=>{v(e.id),b(t?e.id:null)},onSource:e=>j(Jr(M,a,e)),onLanguage:t=>ae(a,Zr(e,t)),onInterrupt:()=>{N.interrupt()},execution:N.execution?.cells.find(t=>t.id===e.id)??ai(e),inputExecution:F===e.id?N.execution??void 0:void 0,inputSource:ee,onRun:N.supported?e=>{N.run(M.cells.flatMap((t,n)=>(e===`cell`?n===a:e===`above`?n<a:n>=a)?[n]:[]))}:void 0,onExecute:e=>oe(a,e),onOperation:e=>se(a,e),onSave:()=>{Ee(Te(t,n,r))},onSplit:t=>{if(M.cells.length>=2e3)return;let n=V(e.source),r={...Qr(e.cell_type),source:n.slice(t)},i=[...M.cells];i.splice(a,1,{...e,source:n.slice(0,t)},r),j({...M,cells:i}),te(r.id,!0)}},e.id)),i&&(0,z.jsx)(`div`,{className:`flex gap-3`,children:[`code`,`markdown`,`raw`].map(e=>(0,z.jsxs)(`button`,{disabled:M.cells.length>=2e3,className:`cursor-pointer rounded-sm p-1 text-fg-muted transition-colors hover:bg-elevated hover:text-fg disabled:cursor-default disabled:opacity-40 flex items-center gap-1.5 text-xs`,onClick:()=>ie(e,M.cells.length),children:[(0,z.jsx)(He,{className:`size-3.5`}),e===`code`?`Code`:e===`markdown`?`Markdown`:`Raw`,` cell`]},e))})]})})]})})})}var Gi=0;function Ki(e){let t=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,{acceptNode(e){let t=e.parentElement;return!e.textContent||t?.closest(`script, style, noscript, [hidden], [aria-hidden="true"]`)?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}}),n=[],r=``,i;for(;i=t.nextNode();){let e=i.textContent??``,t=r.length;r+=e,n.push({node:i,start:t,end:r.length})}return{text:r,nodes:n}}function qi(e,t){let n=t.find(t=>t.end>e.start),r=t.findLast(t=>t.start<e.end);if(!n||!r)return null;let i=document.createRange();return i.setStart(n.node,e.start-n.start),i.setEnd(r.node,e.end-r.start),i}var Ji=class{root;matchName=`puddle-find-${++Gi}-match`;activeName=`puddle-find-${Gi}-active`;style;signature=``;ranges=[];index=-1;limited=!1;constructor(e){this.root=e,this.style=document.createElement(`style`),this.style.textContent=`
|
|
7
7
|
::highlight(${this.matchName}) { background: var(--selection); }
|
|
8
8
|
::highlight(${this.activeName}) { background: var(--accent); color: var(--action-ink); }
|
|
9
9
|
`,document.head.appendChild(this.style)}find(e,t,n){let r=JSON.stringify([e,t]);if(r!==this.signature||n===`reset`){this.signature=r;let n=Ki(this.root),i=et(n.text,e,t);if(this.ranges=i.matches.map(e=>qi(e,n.nodes)).filter(e=>e!==null),this.limited=i.limited,this.index=this.ranges.length>0?0:-1,i.invalid)return this.clearHighlights(),{index:-1,count:0,invalid:!0}}else this.ranges.length>0&&(this.index=n===`previous`?(this.index-1+this.ranges.length)%this.ranges.length:(this.index+1)%this.ranges.length);return this.paint(),{index:this.index,count:this.ranges.length,limited:this.limited}}clear(){this.signature=``,this.ranges=[],this.index=-1,this.limited=!1,this.clearHighlights()}dispose(){this.clear(),this.style.remove()}clearHighlights(){CSS.highlights.delete(this.matchName),CSS.highlights.delete(this.activeName)}paint(){if(this.clearHighlights(),this.ranges.length===0)return;CSS.highlights.set(this.matchName,new Highlight(...this.ranges));let e=this.ranges[this.index];e&&(CSS.highlights.set(this.activeName,new Highlight(e)),e.startContainer.parentElement?.scrollIntoView({block:`center`,inline:`nearest`}))}};M.addHook(`afterSanitizeAttributes`,e=>{e.tagName===`A`&&/^https?:/i.test(e.getAttribute(`href`)??``)&&(e.setAttribute(`target`,`_blank`),e.setAttribute(`rel`,`noopener noreferrer`))});function Yi({session:e,path:t,text:n,root:r,scrollDriver:i=!1,scrollReceiver:a=!1,scrollChannel:o=`profile`,focused:s=!0,onRevealSource:c,onOpenFile:l,mobile:u=!1}){let d=Bt(`markdown`,[e,r,t]),f=(0,R.useId)().replace(/[^A-Za-z0-9_-]/g,``),p=(0,R.useSyncExternalStore)(e=>k(e),O,O),m=(0,R.useMemo)(()=>M.sanitize(Yt(n,f)),[n,f]),h=(0,R.useMemo)(()=>Kt(n),[n]),g=(0,R.useMemo)(()=>({__html:m}),[m,p]),_=(0,R.useRef)(null),v=(0,R.useRef)(null),y=(0,R.useRef)(null);(0,R.useEffect)(()=>{let e=v.current;if(!e)return;let t=new Ji(e);return y.current=t,()=>{t.dispose(),y.current=null}},[]);let b=Ze({shortcutEnabled:s,onFind:(e,t,n)=>y.current?.find(e,t,n)??$e,onClear:()=>y.current?.clear(),onCloseFocus:()=>_.current?.focus({preventScroll:!0})});(0,R.useEffect)(()=>b.refresh(),[m,p,b.refresh]),(0,R.useEffect)(()=>{let e=v.current;if(!e)return;let t=new AbortController;return un(e,p,t.signal).then(()=>{t.signal.aborted||b.refresh()}),()=>t.abort()},[m,p,b.refresh]),(0,R.useLayoutEffect)(()=>{let n=_.current,s=v.current;if(!(!n||!s))return tr(n,{viewKey:d,channel:o,target:{session:e,path:t,root:r},driver:i,receiver:a,resizeElements:[n,s],sourceAnchors:()=>Jt(n,s,h)})},[m,h,e,t,r,o,i,a,d]),Ni(v,m,e,t,r);let x=e=>{let n=e.target.closest(`a`);if(n){let r=n.getAttribute(`href`)??``;if(/^https?:/i.test(r))return;if(e.preventDefault(),r.startsWith(`#`)){let e=Xi(r);(e?v.current?.querySelector(`#${CSS.escape(e)}`):null)?.scrollIntoView({block:`nearest`});return}if(!u&&!e.metaKey&&!e.ctrlKey)return;let i=ct(t,r);if(!i)return;l?.(i);return}if(!e.metaKey&&!e.ctrlKey||!c)return;let r=_.current,i=v.current;if(!r||!i)return;let a=e.clientY-r.getBoundingClientRect().top+r.scrollTop,o=Gt(Jt(r,i,h),a);o!==null&&(e.preventDefault(),c({line:li(o,h)}))},S=T().editorFontSize;return(0,z.jsxs)(`div`,{className:`relative size-full bg-ground`,children:[(0,z.jsx)(`div`,{ref:_,tabIndex:-1,className:`h-full overflow-auto overscroll-contain outline-none`,children:(0,z.jsx)(`div`,{ref:v,onClick:x,style:{fontSize:S},className:`md-preview mx-auto max-w-3xl px-6 py-5 text-fg-secondary`,dangerouslySetInnerHTML:g})}),(0,z.jsx)(ci,{controls:b})]})}function Xi(e){try{return decodeURIComponent(e.slice(1))}catch{return null}}var Zi=`puddle-preview-scroll-report`,Qi=`puddle-preview-scroll-apply`,$i=`puddle-preview-source-reveal`;function ea(){return crypto.randomUUID()}function ta(e,t,n){if(e.source!==t||t===null||typeof e.data!=`object`||e.data===null)return null;let r=e.data;return r.channel===n?r:null}function na(e,t,n){let r=ta(e,t,n);return!r||r.kind!==`puddle-preview-scroll-report`||typeof r.ratio!=`number`||!Number.isFinite(r.ratio)||r.sourceLine!==null&&(typeof r.sourceLine!=`number`||!Number.isFinite(r.sourceLine))||typeof r.layout!=`boolean`||typeof r.scrolled!=`boolean`?null:{kind:Zi,channel:n,ratio:qn(r.ratio),sourceLine:r.sourceLine===null?null:Math.max(1,r.sourceLine),layout:r.layout,scrolled:r.scrolled}}function ra(e,t,n){let r=ta(e,t,n);return!r||r.kind!==`puddle-preview-source-reveal`||typeof r.line!=`number`||!Number.isFinite(r.line)?null:{kind:$i,channel:n,line:Math.max(1,r.line)}}function ia(e,t,n){e?.postMessage({kind:Qi,channel:t,ratio:qn(n.ratio),sourceLine:n.sourceLine!==null&&Number.isFinite(n.sourceLine)?Math.max(1,n.sourceLine):null},`*`)}function aa(e){return`(() => {
|
package/dist/public/assets/{ReleaseNotesDialog-BD0uYU6B.js → ReleaseNotesDialog-Pa1yagZd.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{t}from"./react-CZI7_Jkm.js";import{t as n}from"./jsx-runtime-By8HlURe.js";import{t as r}from"./purify.es-D8QhFVkO.js";import{i,o as a,r as o,s,t as c}from"./dialog-DtvE8ATK.js";import{a as l,i as u,n as d}from"./queue-BlrQxHDl.js";import{t as f}from"./markdown-
|
|
1
|
+
import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{t}from"./react-CZI7_Jkm.js";import{t as n}from"./jsx-runtime-By8HlURe.js";import{t as r}from"./purify.es-D8QhFVkO.js";import{i,o as a,r as o,s,t as c}from"./dialog-DtvE8ATK.js";import{a as l,i as u,n as d}from"./queue-BlrQxHDl.js";import{t as f}from"./markdown-BlvTv1jG.js";var p=e(t(),1),m=n();function h({markdown:e}){let t=(0,p.useId)().replace(/[^A-Za-z0-9_-]/g,``),n=(0,p.useMemo)(()=>{let n=r.sanitize(f(e,t),{RETURN_DOM_FRAGMENT:!0,USE_PROFILES:{html:!0},FORBID_TAGS:[`img`,`video`,`audio`,`source`,`iframe`,`object`,`embed`,`style`,`form`],FORBID_ATTR:[`style`,`src`,`srcset`,`poster`,`action`]});for(let e of n.querySelectorAll(`a`)){let t=e.getAttribute(`href`)??``;/^https?:\/\//i.test(t)?(e.setAttribute(`target`,`_blank`),e.setAttribute(`rel`,`noopener noreferrer`)):t.startsWith(`#`)||e.removeAttribute(`href`)}let i=document.createElement(`div`);return i.append(n),{__html:i.innerHTML}},[e,t]);return(0,m.jsx)(`div`,{className:`md-preview text-sm text-fg-secondary`,onClick:e=>{let t=e.target.closest(`a`)?.getAttribute(`href`);if(t?.startsWith(`#`)){e.preventDefault();try{e.currentTarget.closest(`[role="dialog"]`)?.querySelector(`#${CSS.escape(decodeURIComponent(t.slice(1)))}`)?.scrollIntoView({block:`nearest`})}catch{}}},dangerouslySetInnerHTML:n})}function g(){let[e,t]=(0,p.useState)(!1);return(0,p.useLayoutEffect)(()=>{let e=()=>{let e=Array.from(document.querySelectorAll(`[role="dialog"], [role="alertdialog"], dialog[open]`)).some(e=>!e.hasAttribute(`data-release-notes`)&&!e.hidden&&e.getAttribute(`data-state`)!==`closed`);t(!e)},n=new MutationObserver(e);return n.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[`data-state`,`hidden`,`open`,`role`]}),e(),()=>n.disconnect()},[]),e}function _({group:e}){return(0,p.useEffect)(()=>d.presented(e),[e]),null}function v({current:e}){let t=g(),n=l.flatMap(t=>{let n=e.entries.find(e=>e.component===t);return n?[n]:[]});return t?(0,m.jsx)(c,{open:!0,onOpenChange:t=>{t||d.dismiss(e)},children:(0,m.jsxs)(o,{wide:!0,className:`gap-6`,"data-release-notes":``,children:[(0,m.jsx)(_,{group:e}),(0,m.jsxs)(a,{children:[(0,m.jsxs)(s,{children:[`What’s new in `,e.version]}),(0,m.jsxs)(i,{children:[n.map(e=>u[e.component]).join(` · `),` release notes`]})]}),(0,m.jsx)(`nav`,{"aria-label":`Release note sections`,className:`flex flex-wrap gap-x-5 gap-y-2 text-sm`,children:n.map(e=>(0,m.jsx)(`a`,{className:`text-fg-muted hover:text-fg`,href:`#${e.component}`,onClick:t=>{t.preventDefault(),t.currentTarget.closest(`[role="dialog"]`)?.querySelector(`#${e.component}`)?.scrollIntoView({block:`nearest`})},children:u[e.component]},e.component))}),n.map(e=>(0,m.jsx)(`section`,{id:e.component,"aria-label":u[e.component],children:(0,m.jsx)(h,{markdown:e.markdown})},e.component))]})}):null}export{v as ReleaseNotesDialog};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{t}from"./react-CZI7_Jkm.js";import{r as n,s as r}from"./theme-swfNLod9.js";import{t as i}from"./jsx-runtime-By8HlURe.js";import{t as a}from"./purify.es-D8QhFVkO.js";import"./katex.min-ZqdHjttS.js";import{n as o}from"./forward-link-CAXhnLYS.js";import{t as s}from"./createLucideIcon-C9A1vLE-.js";import{t as c}from"./button-DtByPSFL.js";import{t as l}from"./arrow-down-CtYa-Aya.js";import{t as u}from"./square-terminal-CIkfNq3I.js";import{t as d}from"./waves-horizontal-CLDJf7Dd.js";import{t as f}from"./control-tray-c9uXOo-i.js";import{n as p}from"./errors-efDAjyqa.js";import{n as m}from"./markdown-BlvTv1jG.js";import{o as h,r as g,s as _,t as v}from"./preferences-4IYvJCFc.js";import{n as y,r as b,t as x}from"./render-rich-content-DXt6ncgk.js";var S=s(`grip-horizontal`,[[`circle`,{cx:`12`,cy:`9`,r:`1`,key:`124mty`}],[`circle`,{cx:`19`,cy:`9`,r:`1`,key:`1ruzo2`}],[`circle`,{cx:`5`,cy:`9`,r:`1`,key:`1a8b28`}],[`circle`,{cx:`12`,cy:`15`,r:`1`,key:`1e56xg`}],[`circle`,{cx:`19`,cy:`15`,r:`1`,key:`1a92ep`}],[`circle`,{cx:`5`,cy:`15`,r:`1`,key:`5r1jwy`}]]),C=e(t(),1),w=[`black`,`red`,`green`,`yellow`,`blue`,`magenta`,`cyan`,`white`,`brightBlack`,`brightRed`,`brightGreen`,`brightYellow`,`brightBlue`,`brightMagenta`,`brightCyan`,`brightWhite`];function T(e,t,n,r){if(t){if(r?.[e])return r[e];if(e<16){let t=n[w[e]];return t&&/^#[\da-f]{6}$/i.test(t)?t:void 0}if(e<232){let t=[0,95,135,175,215,255],n=e-16;e=t[Math.floor(n/36)]<<16|t[Math.floor(n/6)%6]<<8|t[n%6]}else{let t=8+(e-232)*10;e=t<<16|t<<8|t}}return`#${(e&16777215).toString(16).padStart(6,`0`)}`}function E(e,t,n){if(!e||e.isInvisible?.())return``;let r=[];e.isBold?.()&&r.push(`font-weight:700`),e.isItalic?.()&&r.push(`font-style:italic`);let i=[e.isUnderline?.()?`underline`:``,e.isStrikethrough?.()?`line-through`:``,e.isOverline?.()?`overline`:``].filter(Boolean);i.length&&r.push(`text-decoration:${i.join(` `)}`);let a=e;if(e.isUnderline?.()){let i=[`solid`,`solid`,`double`,`wavy`,`dotted`,`dashed`][a.getUnderlineStyle?.()??1];if(i&&r.push(`text-decoration-style:${i}`),a.isUnderlineColorPalette?.()||a.isUnderlineColorRGB?.()){let i=a.getUnderlineColor();n?.boldBright&&e.isBold?.()&&a.isUnderlineColorPalette?.()&&i<8&&(i+=8);let o=T(i,!!a.isUnderlineColorPalette?.(),t,n?.ansi);o&&r.push(`text-decoration-color:${o}`)}}e.isDim?.()&&r.push(`opacity:0.5`);let o=e.getFgColor?.();n?.boldBright&&e.isBold?.()&&e.isFgPalette?.()&&o<8&&(o+=8);let s=e.isFgDefault?.()===!1||e.isFgPalette?.()||e.isFgRGB?.()?T(o,!!e.isFgPalette(),t,n?.ansi):void 0,c=e.isBgDefault?.()===!1||e.isBgPalette?.()||e.isBgRGB?.()?T(e.getBgColor(),!!e.isBgPalette(),t,n?.ansi):void 0;return e.isInverse?.()&&([s,c]=[c??t.background,s??t.foreground]),c?.toLowerCase()===t.background?.toLowerCase()&&(c=void 0),s&&/^#[\da-f]{6}$/i.test(s)&&r.push(`color:${s}`),c&&/^#[\da-f]{6}$/i.test(c)&&r.push(`background-color:${c}`),(c||i.length)&&r.push(`white-space:break-spaces`),r.join(`;`)}function D(e,t,n=[]){let r=`ripple`;for(;e.includes(r);)r+=`_`;let i=new Map,a=0;return{text:e.split(`
|
|
2
|
+
`).map((e,o)=>{let s=n[o]??0,c=s>0,l=a;if(a+=e.length+1,/^\s*(`{3,}|~{3,})/.test(e))return e;let u=e.trim()?/^(\s*(?:(?:[•●⏺✦›❯*-]|\d+[.)])\s+)?(?:#{1,6}\s+|>\s+)?)/.exec(e)[0].length:0;for(let n of t.toReversed()){let t=Math.max(u,s,n.start-l),a=Math.min(e.length,n.end-l);if(a<=t)continue;let o=e.slice(t,a);if((c||!n.css.includes(`white-space:`))&&(t+=o.length-o.trimStart().length,a-=o.length-o.trimEnd().length),a<=t)continue;let d=`${r}${i.size}\uE001`,f=c&&n.css.includes(`background-color:`)?n.css.split(`;`).filter(e=>!/^(?:background-color|white-space):/.test(e)).join(`;`):n.css,p=n.href&&/^https?:\/\//i.test(n.href)?n.href.replace(/&/g,`&`).replace(/"/g,`"`).replace(/</g,`<`).replace(/>/g,`>`):void 0;i.set(d,p?`<a href="${p}" style="${f}">`:`<span style="${f}">`);let m=`${r}${i.size}\uE001`;i.set(m,p?`</a>`:`</span>`),e=e.slice(0,t)+d+e.slice(t,a)+m+e.slice(a)}return c?e.trimEnd():e}).join(`
|
|
3
|
+
`),restore:e=>{for(let[t,n]of i)e=e.replaceAll(t,n);return e}}}var O=32768;function k(e,t,n,r={},i){let a=Math.min(e.length,n?.last??e.length),o=Math.min(600,Math.floor(O/(t+1))),s=Math.max(0,n?.first??0,a-o);for(;s<a&&e.getLine(s)?.isWrapped;)s++;let c=[],l=new Map,u=0,d=0,f=[];for(let o=s;o<a;o++){let a=h(e,o,t,n);if(!a)break;let s=!1,p=a.text.split(``).map((t,n)=>{let r=a.cells[n];return e.getLine(o)?.getCell(r.col)?.isInvisible?.()?(s=!0,` `):t}).join(``),m=e.getLine(o+1)?.isWrapped?p.length:p.trimEnd().length;for(let t=p.length-1;t>=m;t--){let n=e.getLine(o)?.getCell(a.cells[t].col);if(n&&!n.isInvisible?.()&&E(n,r,i).includes(`white-space:`)){m=t+1;break}}let g=p.slice(0,m);if(u+g.length+1>32768)break;u+=g.length+1,!a.isWrapped&&c.length&&d++;for(let t=0;t<g.length;t++){let n=e.getLine(o)?.getCell(a.cells[t].col),s=E(n,r,i),c=n&&i?.link?.(n);if(!s&&!c)continue;let l=f.at(-1),u=d+t;l&&l.end===u&&l.css===s&&l.href===c?l.end++:f.push({start:u,end:u+1,css:s,...c&&{href:c}})}l.set(o,{offset:d,cells:a.cells,length:g.length,concealed:s}),d+=g.length,a.isWrapped&&c.length?c[c.length-1]+=g:c.push(g)}let p=c.join(`
|
|
4
|
+
`),m=p.slice(0,Math.max(p.trimEnd().length,f.at(-1)?.end??0)),g=[],_=(e,t)=>{let n=f.filter(n=>n.end>e&&n.start<t).map(n=>({...n,start:Math.max(e,n.start)-e,end:Math.min(t,n.end)-e}));g.push({kind:`text`,source:m.slice(e,t),...n.length?{styles:n}:{}})},v=0;for(let r of y(e,t,s,a-s,n)){let e=l.get(r.start.row),t=l.get(r.end.row);if(!e||!t||[...l.entries()].some(([e,t])=>e>=r.start.row&&e<=r.end.row&&t.concealed))continue;let n=e.cells.findIndex(e=>e.col>=r.start.col),i=t.cells.findLastIndex(e=>e.col<=r.end.col)+1;if(n<0||i===0)continue;let a=e.offset+Math.min(e.length,n),o=Math.min(m.length,t.offset+Math.min(t.length,i));a<v||o<=a||(a>v&&_(v,a),g.push({kind:r.kind,source:r.source,display:r.display}),v=o)}return v<m.length&&_(v,m.length),{text:m,truncated:s>0,alternate:e.type===`alternate`,parts:g,...i&&{foreground:r.foreground,background:r.background}}}function A(e,t,n=[],r=0,i){let a=t===`codex`?/^[ \t]*[›❯] /:t===`claude-code`?/^[ \t]*[❯>] /:t===`gemini-cli`?/^[ \t]*> /:void 0;if(a)return a.exec(e)?.[0].length??0;if(t!==`opencode`)return 0;let o=/^([ \t]*┃ {1,2})/.exec(e);if(!o)return 0;let s=e.indexOf(`┃`)+r,c=n.find(e=>e.start<=s&&e.end>s),l=/(?:^|;)color:(#[\da-f]{6})(?:;|$)/i.exec(c?.css??``)?.[1],u=n.some(t=>t.start<r+e.length&&t.end>s+1&&t.css.includes(`background-color:`));return!l||!i||l.toLowerCase()===i.toLowerCase()||!u?0:o[0].length}function j(e,t){switch(t){case`codex`:return/^\s*[›❯>]\s/.test(e);case`claude-code`:return/^\s*[❯>]\s/.test(e);case`gemini-cli`:return/^\s*(?:[>!*]|\(r:\))\s/.test(e);case`opencode`:return/^\s*┃/.test(e);default:return!1}}function M(e,t){return(t===`claude-code`||t===`gemini-cli`)&&/^\s*[─━]{3,}\s*$/.test(e)||t===`gemini-cli`&&/^\s*[▄▀]{3,}\s*$/.test(e)}function N(e,t,n){return t?e===`codex`&&/Back to bottom|Earlier messages available/.test(n)?{key:`Escape`,code:`Escape`,keyCode:27}:e===`gemini-cli`?{key:`End`,code:`End`,keyCode:35,ctrlKey:!0}:e===`opencode`?{key:`g`,code:`KeyG`,keyCode:71,ctrlKey:!0,altKey:!0,input:`\x1B\x07`}:null:null}function P(e,t=!1,n=!1,r={}){let i=e.split(`
|
|
5
|
+
`),a=0,o=[],s=i.map(e=>{o.push(a);let t=A(e,r.agentType,r.styles,a,r.background);return a+=e.length+1,t}),c=D(e,r.styles??[],s);e=c.text;let l=e.split(`
|
|
6
|
+
`),u=l.some(e=>/^ {2}\S/.test(e))&&l.every(e=>!e.trim()||/^ {2}|^[•●⏺✦›❯]/.test(e)),d=l.map(e=>(u?e.replace(/^ {2}/,``):e).replace(/^[•●⏺✦] (?=#)/,``).replace(/^(\s*)[•●⏺✦] /,`$1- `)),f=[],p=new Set;for(let e=0;e<s.length;e++)if(s[e]){M(i[e-1]??``,r.agentType)&&p.add(e-1);for(let t=e+1;t<i.length;t++){if(M(i[t],r.agentType)){p.add(t);break}if(!i[t].trim()||s[t]||/^[•●⏺✦]/.test(i[t]))break}}let h=[],g=()=>{h.length&&f.push(m(h.join(`
|
|
7
|
+
`))),h=[]};for(let e=0;e<d.length;e++){let t=d[e];if(p.has(e)){g();continue}if(s[e]){g();let t=o[e]+s[e],n=(r.styles?.find(n=>n.end>t&&n.start<o[e]+i[e].length&&n.css.includes(`background-color:`)))?.css.split(`;`).filter(e=>/^(?:background-color|color):#[\da-f]{6}$/i.test(e)).join(`;`),a=[l[e].slice(s[e])];if(r.agentType===`opencode`)for(;e+1<d.length&&s[e+1];)e++,a.push(l[e].slice(s[e]));else for(;e+1<d.length&&d[e+1].trim()&&!p.has(e+1)&&!/[\u2500-\u257f]/.test(i[e+1])&&!s[e+1]&&!/^\s*(?:[•●⏺✦›❯*-] |#{1,6} )/.test(i[e+1]);)a.push(d[++e]);f.push(`<div class="ripple-user-turn"${n?` style="${n}"`:``}>${m(a.join(`
|
|
8
|
+
`))}</div>`);continue}let n=/^\s*(`{3,}|~{3,})(.*)$/.exec(t);if(n){g();let r=[t],i=!1;for(;++e<d.length;){let t=d[e];r.push(t);let a=/^\s*(`{3,}|~{3,})\s*$/.exec(t);if(a&&a[1][0]===n[1][0]&&a[1].length>=n[1].length){i=!0;break}}f.push(i?m(r.join(`
|
|
9
|
+
`)):F(r.join(`
|
|
10
|
+
`)))}else if(/^(?: {4}|\t)|[\u2500-\u259f]|\S {2,}\S/.test(u?i[e].replace(/^ {2}/,``):i[e])||/^(?:const|let|var)\s+\w+\s*[:=]|^console\.\w+\(/.test(i[e].trimStart())){g();let n=[t];for(;e+1<d.length&&!s[e+1]&&!p.has(e+1)&&(/^(?: {4}|\t)|[\u2500-\u259f]|\S {2,}\S/.test(u?i[e+1].replace(/^ {2}/,``):i[e+1])||/^(?:const|let|var)\s+\w+\s*[:=]|^console\.\w+\(/.test(i[e+1].trimStart()));)n.push(d[++e]);f.push(F(n.join(`
|
|
11
|
+
`)))}else h.push(t)}g();let _=f.join(``);return t&&(_=_.replace(/^<p>([\s\S]*?)<\/p>\n?/,`$1`)),n&&(_=_.replace(/<p>((?:(?!<p>)[\s\S])*)<\/p>\n?$/,`$1`)),t&&/^\s/.test(e)&&(_=` ${_}`),n&&/\s$/.test(e)&&(_+=` `),c.restore(_)}function F(e){return`<pre${/[\u2500-\u259f]/.test(e)?` class="ripple-terminal-art"`:``}><code>${e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`)}</code></pre>`}function I(e,t,n=null){let r=e.buffer.active,i=r.viewportY,a=e.rows;if(r.type===`normal`&&i===r.baseY&&t){let t=e.rows;for(;t>0&&!r.getLine(i+t-1)?.translateToString(!0).trim();)t--;t=Math.max(r.cursorY+1,Math.min(e.rows,t+1)),t>=6&&(a=t)}let o=0,s=e.cols;if(t===`opencode`)for(let t=i+e.rows-1;t>=i+Math.floor(e.rows/2);t--){let e=/^(\s*)╹(▀{8,})/.exec(r.getLine(t)?.translateToString(!0)??``);if(e){o=e[1].length,s=e[0].length;break}}let c=Math.max(0,a-5),l=!1;if(t&&r.baseY+r.cursorY>=i&&r.baseY+r.cursorY<i+e.rows){let n=Math.min(i+e.rows-1,r.baseY+r.cursorY),a=r.type===`alternate`?i+Math.floor(e.rows/2):Math.max(i,n-Math.max(12,Math.floor(e.rows/2)));for(let e=n;e>=a;e--){let n=r.getLine(e);if(!j(n?.translateToString(!0)??``,t))continue;if(l=!0,c=e-i,t===`opencode`)for(;c>0&&j(r.getLine(i+c-1)?.translateToString(!0)??``,t);)c--;let a=r.getLine(i+c-1);(M(a?.translateToString(!0)??``,t)||a&&!a.translateToString(!0).trim()&&a.getCell(0)?.getBgColorMode()===n?.getCell(0)?.getBgColorMode()&&a.getCell(0)?.getBgColor()===n?.getCell(0)?.getBgColor())&&c--;break}}l||(a=e.rows,c=Math.max(0,e.rows-5)),n!==null&&(c=Math.max(3,a-n)),c=Math.max(0,Math.min(a-1,c));let u=i+c;if(t===`codex`||t===`gemini-cli`)for(;u>i;){let e=r.getLine(u-1)?.translateToString(!0).trim()??``,n=t===`codex`?/^(?:New activity\s*·\s*)?↓\s*Back to bottom\b/.test(e):/^(?:Shift\+Tab to |\? for shortcuts$)/i.test(e)||M(e,t);if(e&&!n)break;u--}if(t===`gemini-cli`&&r.type===`alternate`){let t=Array.from({length:u-i},(t,n)=>r.getLine(i+n)?.getCell(e.cols-1)?.getChars()??``);t.some(e=>/[▄█▀]/.test(e))&&t.every(e=>/^[ ▄█▀]*$/.test(e))&&s--}let d=((e.element?.querySelector(`.xterm-screen`))?.getBoundingClientRect().height||e.rows*16)/e.rows;return{first:i,last:u,firstCol:o,lastCol:s,nativeRows:a-c,cellHeight:d,bottom:Math.max(0,a-c)*d,nativeOffset:(e.rows-a)*d}}function L(e,t){let n=e.element?.querySelector(`.xterm-screen`);if(!n)return;let r=n.getBoundingClientRect();n.dispatchEvent(new WheelEvent(`wheel`,{bubbles:!0,cancelable:!0,deltaX:t.deltaX,deltaY:t.deltaY,deltaMode:t.deltaMode,ctrlKey:t.ctrlKey,altKey:t.altKey,metaKey:t.metaKey,clientX:Math.max(r.left,Math.min(r.right-1,t.clientX)),clientY:Math.max(r.top,Math.min(r.bottom-1,t.clientY))}))}var R=i();function z({part:e,theme:t,active:n}){let r=(0,C.useRef)(null),{kind:i,source:a,display:o}=e;return(0,C.useEffect)(()=>{let e=r.current;if(!e||!n)return;let s=new AbortController;return e.textContent=a,x(e,{kind:i,source:a,display:o},t,s.signal).catch(()=>{s.signal.aborted||(e.textContent=a)}),()=>s.abort()},[a,i,o,t,n]),(0,R.jsx)(`span`,{ref:r,"data-ripple-rich":i,className:o?`ripple-rich-display`:void 0})}function B({terminal:e,stream:t,rows:n}){let r=(0,C.useRef)(null),i=n=>v(t,Math.max(1,Math.min(e.rows-3,n)));return(0,R.jsx)(`div`,{role:`separator`,"aria-label":`Native CLI boundary`,"aria-orientation":`horizontal`,"aria-valuemin":1,"aria-valuemax":Math.max(1,e.rows-3),"aria-valuenow":n,"aria-valuetext":`${n} native CLI rows`,tabIndex:0,className:`ripple-boundary`,title:`Drag to expose native CLI rows. Double-click to restore automatic placement.`,onPointerDown:t=>{t.button===0&&(t.preventDefault(),t.currentTarget.setPointerCapture(t.pointerId),r.current={y:t.clientY,rows:n,cellHeight:I(e).cellHeight})},onPointerMove:e=>{r.current&&i(r.current.rows+Math.round((r.current.y-e.clientY)/r.current.cellHeight))},onPointerUp:e=>{r.current=null,e.currentTarget.releasePointerCapture(e.pointerId)},onLostPointerCapture:()=>{r.current=null},onDoubleClick:()=>v(t,null),onKeyDown:e=>{e.key===`ArrowUp`||e.key===`ArrowDown`?(e.preventDefault(),i(n+(e.key===`ArrowUp`?1:-1))):e.key===`Home`&&(e.preventDefault(),v(t,null))},children:(0,R.jsx)(S,{className:`size-4`})})}function V(e,t){let n=e._core,r=n?._themeService?.colors,i=e=>`#${(e.rgba>>>8).toString(16).padStart(6,`0`)}`,a={...e.options.theme,...r&&{foreground:i(r.foreground),background:i(r.background)}};if(t===`opencode`&&e.buffer.active.type===`alternate`){let t=e.buffer.active.getLine(e.buffer.active.viewportY)?.getCell(0);t?.isBgRGB()?a.background=`#${t.getBgColor().toString(16).padStart(6,`0`)}`:t?.isBgPalette()&&r&&(a.background=i(r.ansi[t.getBgColor()])),t?.isFgRGB()?a.foreground=`#${t.getFgColor().toString(16).padStart(6,`0`)}`:t?.isFgPalette()&&r&&(a.foreground=i(r.ansi[t.getFgColor()]))}return{theme:a,ansi:r?.ansi.map(i),boldBright:e.options.drawBoldTextInBrightColors,link:e=>{if(e.isInvisible())return;let t=e.extended?.urlId,r=t?n?._oscLinkService?.getLinkData(t)?.uri:void 0;return r&&/^https?:\/\//i.test(r)?r:void 0}}}function H({terminal:e,stream:t,active:i,agentType:s,onDisable:m}){let[h,v]=(0,C.useState)(()=>k(e.buffer.active,e.cols)),y=(0,C.useRef)(null),[x,S]=(0,C.useState)(80),[w,T]=(0,C.useState)(0),[E,D]=(0,C.useState)(5),O=g(t),[A,j]=(0,C.useState)(!1),M=(0,C.useRef)(!1),F=(0,C.useRef)(null),H=(0,C.useCallback)(()=>{let t=I(e,s,O);return S(t.bottom),T(t.nativeOffset),D(t.nativeRows),t},[e,s,O]),U=(0,C.useCallback)((t=H())=>{let n=V(e,s);return k(e.buffer.active,e.cols,t,n.theme,n)},[e,s,H]),W=(0,C.useRef)(!0),G=(0,C.useRef)(0),[K,q]=(0,C.useState)(!0),J=(0,C.useSyncExternalStore)(r,n,n);(0,C.useLayoutEffect)(()=>{let t=e.element?.closest(`.ripple-native`);if(!t)return;let n=t.style.transform;return t.style.transform=A||!w?``:`translateY(${w}px)`,()=>{t.style.transform=n}},[e,w,A]),(0,C.useEffect)(()=>{if(!i||A)return;let t,n=e.buffer.active.viewportY===e.buffer.active.baseY,a=(e=!1)=>{clearTimeout(t),t=void 0;let n=H(),r=window.getSelection(),i=r&&!r.isCollapsed&&y.current?.contains(r.anchorNode);if(!e&&(i||!W.current&&!M.current))return;let a=U(n);v(e=>e.text===a.text&&e.truncated===a.truncated&&e.alternate===a.alternate&&e.foreground===a.foreground&&e.background===a.background&&JSON.stringify(e.parts)===JSON.stringify(a.parts)?e:a)},o=()=>{t??=setTimeout(a,32)},s=[e.onWriteParsed(o),e.onResize(o),{dispose:r(o)},e.onScroll(()=>{let t=e.buffer.active.viewportY===e.buffer.active.baseY;(!t||!n)&&(M.current=!0),n=t,o()}),e.buffer.onBufferChange(()=>{W.current=!0,q(!0),a(!0)})],c=e=>{M.current=!0,F.current=e.deltaY<0?`start`:`end`,o()};return e.element?.addEventListener(`wheel`,c,{capture:!0,passive:!0}),document.addEventListener(`selectionchange`,o),a(!0),()=>{clearTimeout(t),document.removeEventListener(`selectionchange`,o),e.element?.removeEventListener(`wheel`,c,!0),s.forEach(e=>e.dispose())}},[e,i,U,H,A]),(0,C.useEffect)(()=>{let t=y.current;if(!t||!i||A)return;let n=n=>{n.ctrlKey||n.metaKey||n.deltaY===0||(M.current=!1,(n.deltaY<0?t.scrollTop<=1:t.scrollTop+t.clientHeight>=t.scrollHeight-1)&&(n.preventDefault(),L(e,n)))};return t.addEventListener(`wheel`,n,{passive:!1}),()=>t.removeEventListener(`wheel`,n)},[e,i,A]);let Y=(0,C.useMemo)(()=>h.parts.map((e,t)=>{let n=h.parts[t-1],r=h.parts[t+1];return e.kind===`text`?{__html:a.sanitize(P(e.source,n?.kind===`math`&&!n.display,r?.kind===`math`&&!r.display,{styles:e.styles,agentType:s,background:h.background}))}:null}),[h.parts,h.background,s]);return(0,C.useLayoutEffect)(()=>{let e=y.current,t=e?.firstElementChild;if(!e||!t||!i||A)return;let n=()=>{F.current?(e.scrollTop=F.current===`start`?0:e.scrollHeight,F.current=null):W.current&&(e.scrollTop=e.scrollHeight)},r=new ResizeObserver(n);return r.observe(t),n(),()=>r.disconnect()},[h,i,A]),(0,R.jsxs)(`section`,{className:`ripple`,"data-native":A,style:{bottom:A?`auto`:x},"data-alternate":h.alternate,"aria-label":`Ripple reading view`,children:[(0,R.jsxs)(`div`,{className:`ripple-toolbar`,children:[(0,R.jsxs)(`span`,{className:`flex items-center gap-2 text-sm`,children:[(0,R.jsx)(d,{className:`size-4`}),` Ripple`,` `,(0,R.jsx)(`span`,{className:`text-xs text-fg-muted`,children:`Experimental`})]}),(0,R.jsxs)(f,{label:`Ripple controls`,children:[(0,R.jsx)(c,{variant:`ghost`,size:`sm`,onClick:()=>{j(!A),e.focus()},children:A?`Reading view`:`Show CLI`}),(0,R.jsx)(c,{variant:`ghost`,size:`sm`,onClick:()=>e.focus(),children:`Type in CLI`}),(0,R.jsxs)(c,{variant:`ghost`,size:`sm`,onClick:m,children:[(0,R.jsx)(u,{}),` CLI only`]})]})]}),(0,R.jsx)(`div`,{ref:y,className:`ripple-scroll`,style:{color:h.foreground,backgroundColor:h.background},tabIndex:0,"aria-label":`Readable terminal output`,onWheel:()=>{G.current=Date.now()+1e3},onPointerDown:()=>{M.current=!1,G.current=Date.now()+1e3},onPointerMove:e=>{e.buttons&&(G.current=Date.now()+1e3)},onKeyDown:t=>{if(t.target.closest(`a`))return;let n=window.getSelection();n&&!n.isCollapsed||(t.key.length===1&&!t.ctrlKey&&!t.metaKey&&!t.altKey?(t.preventDefault(),e.focus(),e.input(t.key,!0)):[`Enter`,`Escape`,`Backspace`,`Delete`,`ArrowLeft`,`ArrowRight`].includes(t.key)&&(t.preventDefault(),e.focus(),e.textarea?.dispatchEvent(new KeyboardEvent(`keydown`,{key:t.key,code:t.code,keyCode:t.keyCode,shiftKey:t.shiftKey,ctrlKey:t.ctrlKey,altKey:t.altKey,metaKey:t.metaKey,bubbles:!0,cancelable:!0}))),[`ArrowUp`,`ArrowDown`,`PageUp`,`PageDown`,`Home`,`End`,` `].includes(t.key)&&(G.current=Date.now()+1e3))},onScroll:e=>{let t=e.currentTarget,n=W.current,r=t.scrollHeight-t.scrollTop-t.clientHeight<32;(r||Date.now()<G.current)&&(W.current=r),q(W.current),!n&&W.current&&v(U())},onClick:e=>{let n=e.target.closest(`a`);if(!n)return;e.preventDefault();let r=n.getAttribute(`href`);r&&/^https?:\/\//i.test(r)&&o(b(r,t,_()!==null)).catch(p)},children:(0,R.jsxs)(`div`,{className:`ripple-content`,children:[h.truncated&&!h.alternate&&(0,R.jsx)(`p`,{className:`ripple-note`,children:`Recent output · Full history is available in the CLI.`}),h.text?(0,R.jsx)(`div`,{className:`ripple-prose`,children:h.parts.map((e,t)=>e.kind===`text`?(0,R.jsx)(`div`,{className:`ripple-text`,dangerouslySetInnerHTML:Y[t]},t):(0,R.jsx)(z,{part:e,theme:J,active:i},t))}):(0,R.jsx)(`p`,{className:`ripple-note`,children:`Agent output will appear here. Type in the native input below; use Show CLI for menus and approvals.`})]})}),!K&&(0,R.jsxs)(c,{className:`ripple-latest`,variant:`secondary`,size:`sm`,onClick:()=>{if(W.current=!0,q(!0),h.alternate){let t=e.buffer.active,n=N(s,!0,Array.from({length:E+1},(n,r)=>t.getLine(t.viewportY+e.rows-r-1)?.translateToString(!0)??``).join(`
|
|
12
|
+
`));n?.input?e.input(n.input,!0):n&&e.textarea?.dispatchEvent(new KeyboardEvent(`keydown`,{...n,bubbles:!0,cancelable:!0}))}e.scrollToBottom(),v(U()),y.current&&(y.current.scrollTop=y.current.scrollHeight)},children:[(0,R.jsx)(l,{}),` `,h.alternate&&![`codex`,`gemini-cli`,`opencode`].includes(s??``)?`Bottom of view`:`Latest output`]}),(0,R.jsx)(B,{terminal:e,stream:t,rows:E})]})}export{H as Ripple};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.puddle-terminal-ripple{isolation:isolate;overflow:hidden}.puddle-terminal-ripple>.ripple-native{z-index:0;min-height:0;position:relative}.ripple{z-index:2;background:var(--bg-base);min-height:0;color:var(--text-primary);font-family:var(--font-sans);flex-direction:column;flex:1;display:flex;position:absolute;inset:0 0 auto}.ripple[data-native=true]>:not(.ripple-toolbar){display:none}.ripple-toolbar{flex-wrap:wrap;justify-content:space-between;align-items:center;gap:.25rem;padding:.25rem .75rem;display:flex}.ripple-scroll{overscroll-behavior:contain;scrollbar-gutter:stable;overflow-anchor:none;flex:1;min-height:0;overflow:auto}.ripple-content{overflow-wrap:anywhere;width:100%;padding:.5rem .75rem;line-height:1.55}.ripple-note{color:var(--text-muted);margin-block:0 1.25rem;font-size:.75rem}.ripple-text{display:contents}.ripple-user-turn{border-radius:var(--ui-surface-radius);background:var(--explorer-hover);white-space:normal;width:fit-content;max-width:85%;margin:0 0 1rem auto;padding:.6rem .9rem}.ripple-user-turn>:last-child,.ripple-prose>:last-child,.ripple-prose .ripple-text>:last-child{margin-bottom:0}.ripple-rich-display{margin-block:1rem;display:block;overflow-x:auto}.ripple-rich-display svg{max-width:100%;height:auto;margin-inline:auto;display:block}.ripple-prose .katex{font-size:1.1em}.ripple-prose .katex-error,.ripple-prose .mermaid-error{color:var(--danger)}.ripple-prose :is(p,ul,ol,pre,blockquote,table){margin-block:0 1rem}.ripple-prose :is(h1,h2,h3,h4,h5,h6){margin-block:1.5rem .75rem;font-weight:600;line-height:1.4}.ripple-prose h1{font-size:1.5em}.ripple-prose h2{font-size:1.25em}.ripple-prose ul{padding-left:1.5rem;list-style:outside}.ripple-prose ol{padding-left:1.5rem;list-style:decimal}.ripple-prose blockquote{color:var(--text-secondary);padding-left:1rem}.ripple-prose a{color:var(--text-gold);cursor:pointer;text-decoration:underline}.ripple-prose code{font-family:var(--font-mono);font-size:.85em}.ripple-prose pre{white-space:pre;line-height:1.5;overflow:auto}.ripple-prose pre.ripple-terminal-art{line-height:1}.ripple-prose th,.ripple-prose td{text-align:left;padding:.25rem .75rem}.ripple-prose hr{border:0;margin-block:1.5rem}.ripple-latest{position:absolute;bottom:.5rem;left:50%;transform:translate(-50%)}.ripple-boundary{border-radius:var(--ui-radius);background:var(--bg-base);width:1.75rem;height:1rem;color:var(--text-muted);cursor:row-resize;touch-action:none;-webkit-user-select:none;user-select:none;place-items:center;display:grid;position:absolute;bottom:-.5rem;right:.25rem}.ripple-boundary:hover,.ripple-boundary:focus-visible{color:var(--text-primary);background:var(--bg-elevated)}
|