@puddle-code/cli 0.4.3 → 0.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. package/CHANGELOG.md +2 -9
  2. package/dist/index.js +4 -2
  3. package/dist/public/assets/{App-BCbtMAtT.js → App-Cr5uXso0.js} +4 -11
  4. package/dist/public/assets/{Dashboard-nQpeuNVO.js → Dashboard-CB_H-DLw.js} +1 -1
  5. package/dist/public/assets/{EditorTabClose-BvQUApC8.js → EditorTabClose-wG0D8Zxq.js} +1 -1
  6. package/dist/public/assets/{LazyTerminal-CB6HNxTY.js → LazyTerminal-BoKGfXrR.js} +2 -2
  7. package/dist/public/assets/{ModelRefcount-DAWvhyB_.js → ModelRefcount-B7HGdIpN.js} +1 -1
  8. package/dist/public/assets/{NewProjectDialog-lh9FEfzd.js → NewProjectDialog-CdXJRYKt.js} +1 -1
  9. package/dist/public/assets/{NotebookWidget-C93HDt3h.js → NotebookWidget-kFo_mQZh.js} +1 -1
  10. package/dist/public/assets/{PaneEditorBody-DtVSqmqc.js → PaneEditorBody-DPzHCCV7.js} +4 -4
  11. package/dist/public/assets/ReleaseNotesDialog-BXqx8SP6.js +1 -0
  12. package/dist/public/assets/{SettingsDialog-D8zu__T0.js → SettingsDialog-D7eSDoiW.js} +1 -1
  13. package/dist/public/assets/{Terminal-DCG4oUTx.js → Terminal-BEHawoLK.js} +4 -4
  14. package/dist/public/assets/{Workspace-CmtwcmGk.css → Workspace-D5qlJNnU.css} +1 -1
  15. package/dist/public/assets/{Workspace-DLDOs4cG.js → Workspace-PBHY5dWY.js} +4 -4
  16. package/dist/public/assets/{buffer-store-DLpJesbU.js → buffer-store-D78ZR3kb.js} +1 -1
  17. package/dist/public/assets/{index-DdOKMIa5.js → index-BKT8bLLH.js} +2 -2
  18. package/dist/public/assets/{markdown-mermaid-CuwsuNsF.js → markdown-mermaid-A8_2kS9k.js} +1 -1
  19. package/dist/public/assets/{notification-delivery-Ygc29Xb8.js → notification-delivery-CoEqmE8J.js} +1 -1
  20. package/dist/public/assets/{selection-actions-vwVXE8h8.js → selection-actions-Ccf4ZuaR.js} +1 -1
  21. package/dist/public/assets/ws-Dgc69_w8.js +1 -0
  22. package/dist/public/index.html +1 -1
  23. package/package.json +1 -1
  24. package/dist/public/assets/ReleaseNotesDialog-Z7jtCZYz.js +0 -1
  25. package/dist/public/assets/ws-DpgAmFEj.js +0 -1
@@ -1,9 +1,9 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/NotebookWidget-C93HDt3h.js","assets/rolldown-runtime-QTnfLwEv.js","assets/react-CZI7_Jkm.js","assets/auth-olLlgxc3.js","assets/context-C3-WejyN.js","assets/protocol-support-CsLR9u7d.js","assets/jsx-runtime-By8HlURe.js","assets/api-BOuyloUi.js","assets/preload-helper-Czpn1I53.js","assets/index-DdOKMIa5.js","assets/react-dom-cJyBB_A4.js","assets/client-settings-CwqpIric.js","assets/index-C3TPFFMc.css","assets/PdfViewer-C-dXDOjG.js","assets/dist-BOS6OKSE.js","assets/createLucideIcon-C9A1vLE-.js","assets/control-tray-OJfh0_ml.js","assets/control-tray-D7OXXkAy.css","assets/view-state-store-Cy9sQJoZ.js","assets/scroll-restoration-CwXbvZvT.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{R as n,St as r,Tt as i,_ as a,d as o,f as s,p as c,u as l}from"./protocol-support-CsLR9u7d.js";import{at as u,ct as d,it as f,k as p,lt as m,nt as h,o as g,ot as _,rt as v,st as y,tt as b}from"./auth-olLlgxc3.js";import{n as x,t as S}from"./context-C3-WejyN.js";import{i as C,r as w,t as ee}from"./client-settings-CwqpIric.js";import{t as T}from"./jsx-runtime-By8HlURe.js";import{t as E}from"./preload-helper-Czpn1I53.js";import{a as D,r as O}from"./index-DdOKMIa5.js";import{t as k}from"./purify.es-D8QhFVkO.js";import"./katex.min-ZqdHjttS.js";import{a as A,c as j,h as te,i as M,p as N,r as P}from"./editor.api2-4X9Vh9Zw.js";import{n as F,r as ne,t as re}from"./api-BOuyloUi.js";import{c as ie,g as ae,p as oe}from"./hotkeys-Cu0t6sbz.js";import{B as se,C as ce,E as le,J as ue,K as de,O as fe,P as pe,R as me,T as he,U as ge,W as _e,X as ve,Y as ye,Z as be,_ as xe,a as Se,at as Ce,d as we,i as Te,it as Ee,j as De,k as Oe,m as ke,n as Ae,nt as je,ot as Me,r as Ne,rt as Pe,st as Fe,u as Ie,v as Le,w as Re}from"./media-refresh-store-CHPkX-XV.js";import{n as ze}from"./dist-BOS6OKSE.js";import{t as Be}from"./x-Dq6POV20.js";import{n as Ve,t as He}from"./chevron-right-BP2NLwlG.js";import{n as Ue,r as We}from"./dist-BHBQY7ao.js";import{t as Ge}from"./createLucideIcon-C9A1vLE-.js";import{a as Ke,i as qe,n as Je,o as Ye,r as Xe,t as Ze}from"./select-C0UTbo8D.js";import{t as Qe}from"./chevron-down-HQLVE6o5.js";import{a as $e,n as et,o as tt,r as nt,t as rt}from"./FindWidget-CaVwYvST.js";import{t as it}from"./copy-D0Theg4Q.js";import{t as at}from"./rotate-ccw-BI2k_h3A.js";import{a as ot,i as st,n as ct,o as lt,r as ut,t as dt}from"./preview-kind-CPkO-rSz.js";import{t as ft}from"./control-tray-OJfh0_ml.js";import{a as pt,o as mt,r as ht,s as gt,t as _t}from"./command-BkdEYC1b.js";import{n as vt,r as yt,t as bt}from"./popover-B5Bw2ljC.js";import{i as xt,n as St,r as Ct}from"./markdown-it-CWoG9_Dn.js";import{t as wt}from"./debounce-B9DrqirV.js";import{a as Tt,c as Et,d as Dt,f as Ot,i as kt,l as At,o as jt,p as Mt,r as Nt,s as Pt,t as Ft,u as It}from"./buffer-store-DLpJesbU.js";import{r as Lt,t as Rt}from"./view-state-store-Cy9sQJoZ.js";import{a as zt,c as Bt,i as Vt,n as Ht,o as Ut,r as Wt,s as Gt,t as Kt}from"./markdown-CMSzQtLp.js";import{i as qt,n as Jt,r as Yt,t as Xt}from"./drafts-B_tChlzR.js";import{r as Zt}from"./buffer-logic-BAkSBQT7.js";import{a as Qt,i as $t,n as en,o as tn,r as nn}from"./editor-sync-W1bamxAP.js";import{r as rn,t as an}from"./math-CSw6sgCC.js";import{n as on}from"./math-delimiters-BCnTi7Ii.js";import{n as sn}from"./markdown-mermaid-CuwsuNsF.js";var cn=Ge(`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`}]]),ln=Ge(`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`}]]),un=Ge(`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`}]]),dn=Ge(`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`}]]),fn=Ge(`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`}]]),I=e(t(),1),L=T();String.prototype.codePointAt;function pn(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 mn=pn(/["&\u00A0]/g,new Map([[34,`&quot;`],[38,`&amp;`],[160,`&nbsp;`]])),hn=pn(/[&<>\u00A0]/g,new Map([[38,`&amp;`],[60,`&lt;`],[62,`&gt;`],[160,`&nbsp;`]])),gn=new Map,_n=new Map,vn=1;function yn(e){for(let t of _n.get(e)??[])t()}function bn(e,t){gn.set(e,t),yn(e)}function xn(e){let t={phase:`unresolved`,revision:vn++};return bn(e,t),t}function Sn(e){let t=gn.get(e);return!t||t.phase!==`unresolved`&&t.phase!==`load-error`?null:(bn(e,{phase:`loading`,revision:t.revision}),t.revision)}function Cn(e,t,n,r){let i=gn.get(e);return!i||i.phase!==`loading`||i.revision!==t?!1:(bn(e,{phase:`opening`,revision:t,content:n,mtimeMs:r}),!0)}function wn(e,t){let n=gn.get(e);return!n||n.phase!==`opening`||n.revision!==t?!1:(bn(e,{...n,phase:`comparing`}),!0)}function Tn(e,t,n){let r=gn.get(e);return!r||r.phase!==`loading`||r.revision!==t?!1:(bn(e,{phase:`load-error`,revision:t,message:n}),!0)}function En(e,t){return t&&e?.phase===`unresolved`}function Dn(e){return e?.phase===`comparing`?e.mtimeMs:void 0}function On(e){return e?.phase===`loading`||e?.phase===`load-error`||e?.phase===`opening`}function kn(e){return e.phase===`opening`||e.phase===`comparing`}function An(e){gn.delete(e)&&yn(e)}function jn(e){return gn.get(e)??null}function Mn(e,t){let n=_n.get(e);return n||(n=new Set,_n.set(e,n)),n.add(t),()=>n.delete(t)}function Nn(e){return{tabSize:e,insertSpaces:!0,detectIndentation:!1}}var Pn=new Rt,Fn=new Rt;function In(e){let t={...e.contributionsState};return delete t[`editor.contrib.wordHighlighter`],{...e,contributionsState:t}}function Ln(e,t){let n=(0,I.useRef)(null),r=(0,I.useRef)(null);return(0,I.useLayoutEffect)(()=>(n.current&&(r.current=t(n.current,e)),()=>{r.current?.(),r.current=null}),[e,t]),(0,I.useCallback)(i=>{r.current?.(),n.current=i,i.onDidDispose(()=>{n.current===i&&(n.current=null)}),r.current=t(i,e)},[e,t])}function Rn(e,t){let n=Pn.get(t);n&&e.restoreViewState(n);let r=()=>{if(!e.getModel())return;let n=e.saveViewState();n&&Pn.set(t,In(n))},i=[e.onDidScrollChange(r),e.onDidChangeCursorSelection(r)];return()=>{r(),i.forEach(e=>e.dispose())}}function zn(e,t){let n=Fn.get(t),r=n!==void 0,i=()=>{if(r||!e.getModel())return;let n=e.saveViewState();n&&Fn.set(t,{...n,original:n.original&&In(n.original),modified:n.modified&&In(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 Bn(e){return Ln(Lt(`code`,e),Rn)}function Vn(e){return Ln(Lt(`diff`,e),zn)}function Hn({session:e,path:t,conflict:n,model:r,onTakeDisk:i,onKeepMine:a,onSave:o,onReady:s}){let c=C(),l=Vn([`conflict`,r.uri.toString()]),u=(0,I.useId)(),d=(0,I.useMemo)(()=>getComputedStyle(document.documentElement).getPropertyValue(`--font-mono`).trim()||void 0,[]),f=(0,I.useRef)(o);f.current=o;let p=(0,I.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,I.useRef)(m);return h.current=m,(0,I.useEffect)(()=>()=>h.current(),[]),(0,L.jsxs)(`div`,{className:`flex h-full flex-col bg-ground`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-3 bg-elevated px-3 py-1.5 text-xs text-fg-secondary`,children:[(0,L.jsx)(`span`,{children:`This file changed on disk. Yours is on the right — merge what you want, then save.`}),(0,L.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,L.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,L.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,L.jsx)(Mt,{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:Dt,keepCurrentModifiedModel:!0,loading:(0,L.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(M.CtrlCmd|P.KeyS,()=>f.current()),s?.(n.revision)},options:{readOnly:n.phase!==`comparing`,originalEditable:!1,renderSideBySide:!0,automaticLayout:!0,fontFamily:d,fontSize:c.editorFontSize,...Nn(c.editorTabSize),wordWrap:c.editorWordWrap?`on`:`off`,minimap:{enabled:!1},fixedOverflowWidgets:!0,scrollBeyondLastLine:!1}})})]})}function Un({session:e,path:t,buffer:n,focused:r}){let i=n.conflict;return!i||i.phase===`unresolved`?null:kn(i)&&n.model?(0,L.jsx)(Hn,{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,L.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,L.jsx)(`span`,{children:`The disk version could not be loaded.`}),(0,L.jsx)(`span`,{className:`max-w-lg text-xs text-fg-secondary`,children:i.message}),(0,L.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,L.jsx)(`div`,{className:`flex h-full items-center justify-center bg-ground text-sm text-fg-muted`,children:`Loading the disk version…`})}function Wn(e){return Number.isFinite(e)?Math.min(1,Math.max(0,e)):0}function Gn(e,t,n){return Wn(e/Math.max(1,t-n))}function Kn(e,t,n){return Wn(e)*Math.max(0,t-n)}function qn(e,t){return JSON.stringify([e,t.session,t.root??null,t.path])}var Jn=new class{positions=new Map;listeners=new Map;revision=0;publish(e,t,n,r=null){let i={ratio:Wn(n),sourceLine:r!==null&&Number.isFinite(r)?Math.max(1,r):null,revision:++this.revision},a=qn(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(qn(e,t))}subscribe(e,t,n){let r=qn(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)}}},Yn=new Rt;function Xn(e){let t=null;return{schedule:()=>{t===null&&(t=requestAnimationFrame(()=>{t=null,e()}))},dispose:()=>{t!==null&&cancelAnimationFrame(t),t=null}}}function Zn(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=Gt(r,e.sourceLine);if(t!==null)return Math.min(i,Math.max(0,t))}return Kn(e.ratio,t,n)}function Qn(e,t){if(t.driver&&t.receiver)throw Error(`a preview scroll surface cannot be both driver and receiver`);let n=t.store??Jn,r=t.viewKey?Yn.get(t.viewKey):void 0,i=t.sourceAnchors?.(),a=()=>void 0,o,s=n=>{r=n,t.viewKey&&Yn.set(t.viewKey,n),e.scrollTop=Zn(n,e.scrollHeight,e.clientHeight,i)};r&&s(r);let c=()=>{if(e.clientHeight<=0)return;let a=Gn(e.scrollTop,e.scrollHeight,e.clientHeight),o=i?Bt(i,e.scrollTop):null;r={ratio:a,sourceLine:o,revision:0},t.viewKey&&Yn.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=Xn(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 $n(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 er(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 tr(e,t,n){if(t.driver&&t.receiver)throw Error(`a Monaco scroll surface cannot be both driver and receiver`);let r=t.store??Jn,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?er(e,t.sourceLine):null;e.setScrollTop(r??Zn(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=Xn(()=>{let n=Gn(e.getScrollTop(),e.getScrollHeight(),c());r.publish(t.channel,t.target,n,$n(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 nr(e){return!e}function rr(e){let t=e.split(`+`),n=t.pop()??``,r=0;for(let e of t)e===`meta`?r|=M.CtrlCmd:e===`ctrl`?r|=M.WinCtrl:e===`alt`?r|=M.Alt:e===`shift`&&(r|=M.Shift);let i=P[/^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 ir(e,t){let n=rr(ie(`editor.save`));n!==null&&e.addCommand(n,()=>t.onSave());let r=rr(ie(`editor.wordWrap`));e.addAction({id:`puddle.toggleWordWrap`,label:`Toggle Word Wrap`,keybindings:r===null?[]:[r],run:()=>w({editorWordWrap:nr(ee().editorWordWrap)})})}var ar=new WeakSet;function or(e){return ar.has(e)?!1:(ar.add(e),!0)}function sr(e){return`file-conflict:${e}`}function cr(e,t,n,r,i){let a=i?.passive===!0,o=i?.focused??!0,s=Ft(e,t,r),c=be(e,t,{root:r,live:i?.live}),l=ye(e,r),[u,d]=(0,I.useState)(null),[f,p]=(0,I.useState)(!1),m=(0,I.useRef)(!1),h=(0,I.useRef)(null),g=(0,I.useRef)(null),_=(0,I.useRef)(n);_.current=n;let v=(0,I.useRef)(!1),y=(0,I.useCallback)((e,t)=>{g.current?.cancel(),v.current=!0;try{Pt(s,e,t)}finally{v.current=!1}},[s]),b=(0,I.useSyncExternalStore)((0,I.useCallback)(e=>It(s,e),[s]),()=>kt(s)),x=(0,I.useSyncExternalStore)((0,I.useCallback)(e=>tn(s,e),[s]),()=>Qt(s)),S=(0,I.useSyncExternalStore)((0,I.useCallback)(e=>Mn(s,e),[s]),()=>jn(s));(0,I.useEffect)(()=>{let n=c.data;if(!n||n.binary||n.content===null||m.current)return;m.current=!0;let i=At(s)!==void 0,a=Nt(e,t,n.content,n.mtime_ms,r),o=a.getValue();d(a),!i&&qt(e,t,r).then(i=>{if(!i)return;let s=Jt(i,o,n.mtime_ms);s===`discard`?Xt(e,t,r):s===`restore`?Zt(a,i.content)&&p(!0):ze(`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:()=>{Zt(a,i.content)&&p(!0)}}})})},[c.data,s,e,t,r]),(0,I.useEffect)(()=>{if(!u||a)return;let n=Yt(e,t,r);g.current=n;let i=u.onDidChangeContent(()=>{v.current||(n(u.getValue(),At(s)??0),en(e,t,r))});return()=>{n.flush(),i.dispose(),g.current=null}},[u,s,e,t,r,a]),(0,I.useEffect)(()=>{!u||!x.savedElsewhere||kt(s)||c.refetch().then(e=>{kt(s)||(e.data&&e.data.content!==null&&y(e.data.content,e.data.mtime_ms),$t(s))})},[x.savedElsewhere,u,s]),(0,I.useEffect)(()=>{let e=c.data;!u||!e||e.content===null||!kt(s)&&e.mtime_ms!==At(s)&&y(e.content,e.mtime_ms)},[c.data,u,s]);let C=(0,I.useCallback)((n,i)=>{Tt(s,n,i),g.current?.cancel(),Xt(e,t,r),nn(e,t,i,r),p(!1),An(s)},[s,e,t,r]),w=(0,I.useCallback)(()=>{let e=Sn(s);e!==null&&(ze.dismiss(sr(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.`);Cn(s,e,n.content,n.mtime_ms)}).catch(t=>{Tn(s,e,t instanceof Error?t.message:`The disk version did not load.`)}))},[c,s]),ee=(0,I.useRef)(w);ee.current=w,(0,I.useEffect)(()=>{if(!En(S,o))return;let e=sr(s);return ze(`File changed on disk`,{id:e,description:`Nothing was written — your unsaved version is intact.`,duration:1/0,closeButton:!0,action:{label:`Compare`,onClick:()=>ee.current()}}),()=>{ze.dismiss(e)}},[S,o,s]);let T=(0,I.useCallback)(()=>{c.refetch().then(n=>{n.data&&n.data.content!==null&&y(n.data.content,n.data.mtime_ms),Xt(e,t,r),p(!1),An(s)})},[s,e,t,y]),E=(0,I.useCallback)((e,n)=>{l.mutate({path:t,content:e},{onSuccess:e=>C(n,e.mtime_ms),onError:e=>ze.error(e instanceof Error?e.message:`Overwrite failed`)})},[l,t,C]),D=(0,I.useCallback)(async()=>{if(!u||!kt(s))return!0;let e=u.getValue(),n=u.getAlternativeVersionId();if(On(jn(s)))return!1;let r=Dn(jn(s))??At(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 re&&e.status===409&&e.code===`stale_file`?xn(s):ze.error(e instanceof Error?e.message:`Save failed`),!1}},[u,s,l,t,C]),O=(0,I.useRef)(D);O.current=D,(0,I.useEffect)(()=>fe(De(e,t,r),()=>O.current(),{session:e,path:t,...r===void 0?{}:{root:r}}),[e,t,r]);let k=(0,I.useCallback)(()=>{let n=h.current,i=_.current;!n||!i||!o||i.session!==e||i.path!==t||(i.root??void 0)!==(r??void 0)||or(i)&&(n.revealLineInCenter(i.line),n.setPosition({lineNumber:i.line,column:i.column??1}),n.focus())},[e,t,r,o]),A=(0,I.useCallback)(e=>{h.current=e,ir(e,{onSave:()=>O.current()}),k()},[k]);(0,I.useEffect)(()=>{k()},[n,u,k]);let j=(0,I.useCallback)(()=>{T()},[T]),te=(0,I.useCallback)(()=>{!u||jn(s)?.phase!==`comparing`||E(u.getValue(),u.getAlternativeVersionId())},[u,s,E]),M=(0,I.useCallback)(e=>{wn(s,e)},[s]),N,P=null;c.data?.binary?N=`binary`:c.error?c.error instanceof re&&c.error.status===413?N=`too-large`:(N=`error`,P=c.error instanceof Error?c.error.message:`Failed to load file`):N=u?`ready`:`loading`;let F=b&&x.savedElsewhere?`saved-elsewhere`:b&&x.dirtyElsewhere?`dirty-elsewhere`:null;return{status:N,errorMessage:P,model:u,dirty:b,restoredNotice:f,discardRestore:j,peerBadge:F,conflict:S,takeDisk:T,keepMine:te,compare:w,comparisonReady:M,save:D,onMount:A}}function lr(e,t,n,r){for(let i of e)if(mr([i],n).some(e=>(r===void 0||e.kind===r)&&t>=e.startLineNumber&&t<=e.endLineNumber))return i;return null}function ur(e,t){return fr(e.modifiedStartLineNumber,e.modifiedEndLineNumber)>0?Math.min(t,e.modifiedEndLineNumber):Math.max(0,Math.min(t,e.modifiedStartLineNumber-1))}function dr(e){let t=fr(e.originalStartLineNumber,e.originalEndLineNumber),n=fr(e.modifiedStartLineNumber,e.modifiedEndLineNumber);return Math.max(5,Math.min(14,t+n+4))}function fr(e,t){return t===0?0:Math.max(0,t-e+1)}function pr(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 mr(e,t){let n=[];for(let r of e){let e=fr(r.originalStartLineNumber,r.originalEndLineNumber),i=fr(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(pr(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(pr(r.modifiedStartLineNumber+i,t))}return n}var hr=28,gr=[[`puddle-dirty-added`,`added`],[`puddle-dirty-modified`,`modified`],[`puddle-dirty-deleted-before`,`deleted-before`],[`puddle-dirty-deleted-after`,`deleted-after`]];function _r(e){if(e){for(let[t,n]of gr)if(e.classList.contains(t)||e.closest(`.${t}`))return n}}function vr({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,N.ScrollType.Immediate)},u=(i,s)=>{if(a?.anchorLine===i){c();return}c();let u=e.getOption(N.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:ur(s,n.getLineCount()),heightInPx:hr+dr(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=N.createDiffEditor(h,{readOnly:!0,domReadOnly:!0,originalEditable:!1,renderSideBySide:!1,renderMarginRevertIcon:!1,renderOverviewRuler:!1,enableSplitViewResizing:!1,isInEmbeddedEditor:!0,automaticLayout:!0,fontFamily:e.getOption(N.EditorOption.fontFamily),fontSize:e.getOption(N.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!==N.MouseTargetType.GUTTER_LINE_DECORATIONS||e.target.position===null)return;let t=e.target.position.lineNumber,r=lr(i,t,n.getLineCount(),_r(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=lr(t,r.anchorLine,n.getLineCount());if(!o){c();return}r.change=o,r.zone.afterLineNumber=ur(o,n.getLineCount()),r.zone.heightInPx=hr+dr(o)*e.getOption(N.EditorOption.lineHeight);try{e.changeViewZones(e=>e.layoutZone(r.zoneId))}catch{c();return}l(r)},dispose(){o=!0,d.dispose(),c()}}}var yr={added:`puddle-dirty-added`,modified:`puddle-dirty-modified`,"deleted-before":`puddle-dirty-deleted-before`,"deleted-after":`puddle-dirty-deleted-after`};function br(e,t,r,i){let o=n(),s=de(e,t,{root:r,enabled:o.data!==void 0&&a(o.data.protocol)&&i!==null}),[c,l]=(0,I.useState)(null),u=(0,I.useCallback)(e=>{l(e)},[]);return(0,I.useLayoutEffect)(()=>{let e=s.data;if(!c||!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=N.createModel(e.exists?e.content??``:``,i.getLanguageId()),a=N.createDiffEditor(n,{readOnly:!0,automaticLayout:!1,renderSideBySide:!1,minimap:{enabled:!1}}),o=c.createDecorationsCollection();a.setModel({original:r,modified:i});let l=vr({editor:c,original:r,modified:i,path:t}),u=()=>{let e=a.getLineChanges();e&&(l.update(e),o.set(mr(e,i.getLineCount()).map(e=>({range:new j(e.startLineNumber,1,e.endLineNumber,1),options:{isWholeLine:!0,linesDecorationsClassName:yr[e.kind]}}))))},d=a.onDidUpdateDiff(u);return u(),()=>{d.dispose(),l.dispose(),o.clear(),a.setModel(null),a.dispose(),r.dispose(),n.remove()}},[c,i,s.data]),u}function xr({message:e,session:t,path:n,root:r,download:i}){return(0,L.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-3 bg-ground text-sm text-fg-muted`,children:[(0,L.jsx)(`span`,{children:e}),i&&(0,L.jsxs)(`button`,{type:`button`,onClick:()=>void me(t,n,r).catch(e=>ze.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,L.jsx)(Ce,{className:`size-4`}),`Download`]})]})}function Sr({session:e,path:t,reveal:n,root:r,focused:i=!0,scrollDriver:a=!1,scrollReceiver:o=!1,scrollChannel:s=`profile`}){let c=C(),l=Bn([e,r,t]),u=cr(e,t,n,r,{focused:i}),d=pe(e,t,r),f=br(e,t,r,u.model),p=(0,I.useMemo)(()=>getComputedStyle(document.documentElement).getPropertyValue(`--font-mono`).trim()||void 0,[]),[m,h]=(0,I.useState)(null),g=(0,I.useMemo)(()=>({session:e,path:t,root:r}),[e,t,r]),_=u.conflict!==null&&u.conflict.phase!==`unresolved`;if((0,I.useEffect)(()=>{if(!(!m||!u.model||_))return tr(m,{channel:s,target:g,driver:a,receiver:o},N.ScrollType.Immediate)},[m,u.model,_,s,g,a,o]),(0,I.useEffect)(()=>{let e=u.model;e&&N.setModelMarkers(e,`puddle-compilation`,d.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`?A.Error:t.severity===`warning`?A.Warning:A.Info,message:t.message,source:`Puddle compilation`,startLineNumber:n,startColumn:i,endLineNumber:o,endColumn:Math.max(i,c)}}))},[u.model,d]),u.conflict&&u.conflict.phase!==`unresolved`)return(0,L.jsx)(Un,{session:e,path:t,buffer:u,focused:i});if(u.status===`binary`)return(0,L.jsx)(xr,{message:`Binary file — use Download`,session:e,path:t,root:r,download:!0});if(u.status===`too-large`)return(0,L.jsx)(xr,{message:`File too large to edit — use Download`,session:e,path:t,root:r,download:!0});if(u.status===`error`)return(0,L.jsx)(xr,{message:u.errorMessage??`Failed to load file`,session:e,path:t,root:r});let v=u.peerBadge===`saved-elsewhere`?`Saved in another window`:u.peerBadge===`dirty-elsewhere`?`Also being edited in another window`:null;return(0,L.jsxs)(`div`,{className:`flex h-full flex-col bg-ground`,children:[u.restoredNotice&&(0,L.jsxs)(`div`,{className:`flex items-center gap-3 bg-elevated px-3 py-1.5 text-xs text-fg-secondary`,children:[(0,L.jsx)(`span`,{children:`Restored unsaved changes`}),(0,L.jsx)(`button`,{type:`button`,onClick:u.discardRestore,className:`text-fg-muted transition-colors hover:text-fg`,children:`Discard`})]}),v&&(0,L.jsx)(`div`,{className:`bg-surface px-3 py-1 text-xs text-fg-muted`,children:v}),(0,L.jsx)(`div`,{className:`min-h-0 flex-1 pl-1`,children:u.model&&(0,L.jsx)(Ot,{path:u.model.uri.toString(),defaultValue:u.model.getValue(),theme:`puddle`,keepCurrentModel:!0,saveViewState:!1,onMount:e=>{l(e),u.onMount(e),f(e),h(e)},loading:(0,L.jsx)(`div`,{className:`p-3 text-xs text-fg-muted`,children:`…`}),options:{automaticLayout:!0,fontFamily:p,fontSize:c.editorFontSize,...Nn(c.editorTabSize),wordWrap:c.editorWordWrap?`on`:`off`,minimap:{enabled:!1},glyphMargin:!1,lineNumbersMinChars:1,lineDecorationsWidth:5,fixedOverflowWidgets:!0,scrollBeyondLastLine:!1}})})]})}function R({children:e}){return(0,L.jsx)(`div`,{className:`flex h-full items-center justify-center px-4 text-xs text-fg-muted`,children:e})}function Cr(e,t){let n=(0,I.useRef)(t);n.current=t,(0,I.useEffect)(()=>(Et(e),()=>{n.current?.(),jt(e)}),[e])}function wr(e,t,n,r){let i=r.split(`/`).map(encodeURIComponent).join(`/`);return`${e}://${encodeURIComponent(t)}/${encodeURIComponent(n)}/${i}`}function Tr({session:e,refName:t,path:n,content:r}){let i=C(),a=Bn([e,t,n]),o=(0,I.useMemo)(()=>getComputedStyle(document.documentElement).getPropertyValue(`--font-mono`).trim()||void 0,[]);return(0,L.jsx)(Ot,{path:wr(`puddle-view`,e,t,n),defaultValue:r,theme:Dt,saveViewState:!1,onMount:a,loading:(0,L.jsx)(R,{children:`…`}),options:{readOnly:!0,automaticLayout:!0,fontFamily:o,fontSize:i.editorFontSize,...Nn(i.editorTabSize),minimap:{enabled:!1},fixedOverflowWidgets:!0,scrollBeyondLastLine:!1}})}function Er({session:e,against:t,path:n,root:r,indexBase:i=!1}){let a=_e(e,t,n,{root:r,enabled:!i}),o=ue(e,n,{root:r,enabled:i}),s=i?o:a;return s.isPending?(0,L.jsx)(R,{children:`…`}):s.error?(0,L.jsx)(R,{children:s.error instanceof Error?s.error.message:`Failed to load`}):s.data.binary?(0,L.jsx)(R,{children:`Binary file — deleted`}):(0,L.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,L.jsx)(`div`,{className:`bg-surface px-4 py-1 text-xs text-fg-muted`,children:`Deleted`}),(0,L.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,L.jsx)(Tr,{session:e,refName:`${t}:${r??``}`,path:n,content:s.data.content??``})})]})}function Dr({session:e,against:t,path:n,basePath:r,root:i,indexBase:a=!1,focused:o=!0}){let s=C(),c=Vn([e,i,t,a,n]),l=cr(e,n,null,i,{focused:o}),u=_e(e,t,r,{root:i,enabled:!a}),d=ue(e,r,{root:i,enabled:a}),f=a?d:u,p=(0,I.useRef)(null);Cr(Ft(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,I.useRef)(l.save);m.current=l.save;let h=(0,I.useMemo)(()=>getComputedStyle(document.documentElement).getPropertyValue(`--font-mono`).trim()||void 0,[]),g=f.error instanceof re&&f.error.status===404;return l.conflict&&l.conflict.phase!==`unresolved`?(0,L.jsx)(Un,{session:e,path:n,buffer:l,focused:o}):l.status===`binary`||f.data?.binary?(0,L.jsx)(R,{children:`Binary file`}):l.status===`too-large`?(0,L.jsx)(R,{children:`File too large to show`}):l.status===`error`?(0,L.jsx)(R,{children:l.errorMessage??`Failed to load file`}):g||a&&d.data&&!d.data.exists?(0,L.jsx)(Sr,{session:e,path:n,reveal:null,root:i,focused:o}):f.isPending||!l.model?(0,L.jsx)(R,{children:`…`}):f.error?(0,L.jsx)(R,{children:f.error instanceof Error?f.error.message:`Failed to load base`}):(0,L.jsx)(Mt,{modifiedModelPath:l.model.uri.toString(),originalModelPath:wr(`puddle-base`,e,`${t}:${i??``}`,r),original:f.data.content??``,language:l.model.getLanguageId(),theme:Dt,keepCurrentModifiedModel:!0,loading:(0,L.jsx)(R,{children:`…`}),onMount:e=>{c(e),p.current=e,e.onDidDispose(()=>{p.current=null}),e.getModifiedEditor().addCommand(M.CtrlCmd|P.KeyS,()=>m.current())},options:{readOnly:!1,originalEditable:!1,renderSideBySide:!0,automaticLayout:!0,fontFamily:h,fontSize:s.editorFontSize,...Nn(s.editorTabSize),wordWrap:s.editorWordWrap?`on`:`off`,minimap:{enabled:!1},fixedOverflowWidgets:!0,scrollBeyondLastLine:!1}})}function Or({session:e,against:t,entry:n,root:r}){let i=C(),a=Vn([e,r,t,`staged`,n.path]),o=n.old_path??n.path,s=_e(e,t,o,{root:r,enabled:n.status!==`added`}),c=ue(e,n.path,{root:r,enabled:n.status!==`deleted`}),l=(0,I.useMemo)(()=>getComputedStyle(document.documentElement).getPropertyValue(`--font-mono`).trim()||void 0,[]);if(n.status===`deleted`)return(0,L.jsx)(Er,{session:e,against:t,path:o,root:r});if(c.isPending||n.status!==`added`&&s.isPending)return(0,L.jsx)(R,{children:`…`});if(c.error||s.error){let e=c.error??s.error;return(0,L.jsx)(R,{children:e instanceof Error?e.message:`Failed to load staged content`})}return c.data.binary||s.data?.binary?(0,L.jsx)(R,{children:`Binary file`}):n.status===`added`?(0,L.jsx)(Tr,{session:e,refName:`index:${r??``}`,path:n.path,content:c.data.content??``}):s.data?(0,L.jsx)(Mt,{originalModelPath:wr(`puddle-head`,e,`${t}:${r??``}`,o),modifiedModelPath:wr(`puddle-index`,e,`${t}:${r??``}`,n.path),original:s.data.content??``,modified:c.data.content??``,onMount:a,theme:Dt,loading:(0,L.jsx)(R,{children:`…`}),options:{readOnly:!0,originalEditable:!1,renderSideBySide:!0,automaticLayout:!0,fontFamily:l,fontSize:i.editorFontSize,...Nn(i.editorTabSize),wordWrap:i.editorWordWrap?`on`:`off`,minimap:{enabled:!1},fixedOverflowWidgets:!0,scrollBeyondLastLine:!1}}):(0,L.jsx)(R,{children:`Failed to load HEAD content`})}function kr({session:e,path:t,root:n,focused:r}){return Cr(Ft(e,t,n)),(0,L.jsx)(Sr,{session:e,path:t,reveal:null,root:n,focused:r})}function Ar({session:e,against:t,entry:n,root:r,area:i,focused:a=!0}){if(i===`staged`)return(0,L.jsx)(Or,{session:e,against:t,entry:n,root:r});switch(n.status){case`added`:return(0,L.jsx)(kr,{session:e,path:n.path,root:r,focused:a});case`deleted`:return(0,L.jsx)(Er,{session:e,against:t,path:n.path,root:r,indexBase:i===`unstaged`});case`modified`:case`renamed`:return(0,L.jsx)(Dr,{session:e,against:t,path:n.path,basePath:n.old_path??n.path,root:r,indexBase:i===`unstaged`,focused:a});default:return null}}function jr({session:e,sha:t,path:n,root:r}){let i=_e(e,t,n,{root:r});return i.isPending?(0,L.jsx)(R,{children:`…`}):i.error?(0,L.jsx)(R,{children:i.error instanceof Error?i.error.message:`Failed to load file`}):i.data.binary?(0,L.jsx)(R,{children:`Binary file`}):(0,L.jsx)(Tr,{session:e,refName:`${t}:${r??``}`,path:n,content:i.data.content??``})}function Mr({session:e,originalRef:t,originalPath:n,originalContent:r,modifiedRef:i,modifiedPath:a,modifiedContent:o,root:s}){let c=C(),l=Vn([e,s,t,n,i,a]),u=(0,I.useRef)(null),d=(0,I.useMemo)(()=>getComputedStyle(document.documentElement).getPropertyValue(`--font-mono`).trim()||void 0,[]);return(0,I.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,L.jsx)(Mt,{originalModelPath:wr(`puddle-hist-orig`,e,`${t}:${s??``}`,n),modifiedModelPath:wr(`puddle-hist-mod`,e,`${i}:${s??``}`,a),original:r,modified:o,theme:Dt,keepCurrentOriginalModel:!0,keepCurrentModifiedModel:!0,loading:(0,L.jsx)(R,{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,...Nn(c.editorTabSize),minimap:{enabled:!1},fixedOverflowWidgets:!0,scrollBeyondLastLine:!1}})}function Nr({session:e,sha:t,path:n,basePath:r,root:i}){let a=_e(e,`${t}^`,r,{root:i}),o=_e(e,t,n,{root:i});return a.error instanceof re&&a.error.status===404?(0,L.jsx)(jr,{session:e,sha:t,path:n,root:i}):a.isPending||o.isPending?(0,L.jsx)(R,{children:`…`}):a.error?(0,L.jsx)(R,{children:a.error instanceof Error?a.error.message:`Failed to load original`}):o.error?(0,L.jsx)(R,{children:o.error instanceof Error?o.error.message:`Failed to load file`}):a.data.binary||o.data.binary?(0,L.jsx)(R,{children:`Binary file`}):(0,L.jsx)(Mr,{session:e,originalRef:`${t}^`,originalPath:r,originalContent:a.data.content??``,modifiedRef:t,modifiedPath:n,modifiedContent:o.data.content??``,root:i})}function Pr({session:e,sha:t,entry:n,isRootCommit:r,root:i}){switch(le(n.status,r)){case`added`:return(0,L.jsx)(jr,{session:e,sha:t,path:n.path,root:i});case`deleted`:return(0,L.jsx)(Er,{session:e,against:`${t}^`,path:n.path,root:i});case`modified`:case`renamed`:return(0,L.jsx)(Nr,{session:e,sha:t,path:n.path,basePath:n.old_path??n.path,root:i});default:return null}}function Fr({session:e,sha:t,path:n,root:r}){let i=ge(e,t,r);if(i.isPending)return(0,L.jsx)(`div`,{className:`px-4 py-3 text-xs text-fg-muted`,children:`Loading commit…`});if(i.error)return(0,L.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,L.jsx)(`div`,{className:`h-full`,children:(0,L.jsx)(Pr,{session:e,sha:t,entry:a,isRootCommit:i.data.parents.length===0,root:r})}):(0,L.jsxs)(`div`,{className:`flex h-full items-center justify-center px-4 text-center text-xs text-fg-muted`,children:[(0,L.jsx)(`span`,{className:`text-fg-secondary`,children:n}),` is not part of`,` `,(0,L.jsx)(`span`,{className:`font-mono`,children:t.slice(0,7)}),`.`]})}function Ir({session:e,path:t,root:n,area:r,focused:i=!0}){let a=ve(e,{root:n,against:r===void 0?`base`:`head`,area:r});if(a.isPending)return(0,L.jsx)(`div`,{className:`px-4 py-3 text-xs text-fg-muted`,children:`Loading diff…`});if(a.error)return(0,L.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,L.jsx)(`div`,{className:`h-full`,children:(0,L.jsx)(Ar,{session:e,against:a.data.against,entry:o,root:n,area:r,focused:i})}):(0,L.jsxs)(`div`,{className:`flex h-full items-center justify-center px-4 text-center text-xs text-fg-muted`,children:[`No changes to `,(0,L.jsx)(`span`,{className:`mx-1 text-fg-secondary`,children:t}),` against the base.`]})}var Lr=800;function Rr({name:e}){let t=C(),n=ae(),r=Bn([n,e]),a=he(n,e),o=i(),s=oe(`editor.save`),c=(0,I.useRef)(null),l=(0,I.useRef)(null),u=(0,I.useMemo)(()=>getComputedStyle(document.documentElement).getPropertyValue(`--font-mono`).trim()||void 0,[]);if((0,I.useEffect)(()=>{if(n===null)return;let t=wt(t=>{ce(n,e,t).catch(e=>ze.error(e instanceof Error?e.message:`Draft not saved`))},Lr);return l.current=t,()=>{t.flush(),l.current=null}},[n,e]),n===null)return null;if(a.error)return(0,L.jsx)(`div`,{className:`flex h-full items-center justify-center bg-ground text-sm text-fg-muted`,children:a.error instanceof Error?a.error.message:`Failed to load the draft`});if(a.data===void 0)return(0,L.jsx)(`div`,{className:`p-3 text-xs text-fg-muted`,children:`…`});let d=()=>{let t=c.current;t&&(l.current?.flush(),Le({name:e,content:t.getValue()}))};return(0,L.jsxs)(`div`,{className:`flex h-full flex-col bg-ground`,children:[(0,L.jsxs)(`div`,{className:`bg-surface px-3 py-1 text-xs text-fg-muted`,children:[`Draft — not in any worktree; `,s,` saves it into one`]}),(0,L.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,L.jsx)(Ot,{path:`puddle-untitled://${n}/${e}`,defaultValue:a.data.content,theme:Dt,keepCurrentModel:!1,saveViewState:!1,loading:(0,L.jsx)(`div`,{className:`p-3 text-xs text-fg-muted`,children:`…`}),onMount:t=>{r(t),c.current=t,xe(e,t.getValue()),ir(t,{onSave:d})},onChange:t=>{let r=t??``;xe(e,r),Re(o,n,e,r),l.current?.(r)},options:{automaticLayout:!0,fontFamily:u,fontSize:t.editorFontSize,...Nn(t.editorTabSize),minimap:{enabled:!1},fixedOverflowWidgets:!0,scrollBeyondLastLine:!1,wordWrap:t.editorWordWrap?`on`:`off`}})})]})}var zr=d([y(),h(y())]),Br=_(y(),m()),Vr=f({output_type:y(),text:zr.optional(),data:_(y(),m()).optional(),traceback:h(y()).optional(),ename:y().optional(),evalue:y().optional()}),Hr=f({id:y().optional(),cell_type:b([`code`,`markdown`,`raw`]),metadata:Br,source:zr,outputs:h(Vr).optional(),execution_count:u().int().nullable().optional()}),Ur=f({nbformat:v(4),nbformat_minor:u().int().nonnegative(),metadata:Br,cells:h(Hr).max(2e3)});function Wr(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=Ur.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 z(e){return typeof e==`string`?e:Array.isArray(e)&&e.every(e=>typeof e==`string`)?e.join(``):``}function Gr(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:z(e.source),state:`saved`}}}:{}}:e)}}function Kr(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 qr(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 Jr(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 Yr(e){return{id:crypto.randomUUID(),cell_type:e,metadata:{},source:[],...e===`code`?{outputs:[],execution_count:null}:{}}}function Xr(e){return(e.output_type===`error`?e.traceback?.join(`
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/NotebookWidget-kFo_mQZh.js","assets/rolldown-runtime-QTnfLwEv.js","assets/react-CZI7_Jkm.js","assets/auth-olLlgxc3.js","assets/context-C3-WejyN.js","assets/protocol-support-CsLR9u7d.js","assets/jsx-runtime-By8HlURe.js","assets/api-BOuyloUi.js","assets/preload-helper-Czpn1I53.js","assets/index-BKT8bLLH.js","assets/react-dom-cJyBB_A4.js","assets/client-settings-CwqpIric.js","assets/index-C3TPFFMc.css","assets/PdfViewer-C-dXDOjG.js","assets/dist-BOS6OKSE.js","assets/createLucideIcon-C9A1vLE-.js","assets/control-tray-OJfh0_ml.js","assets/control-tray-D7OXXkAy.css","assets/view-state-store-Cy9sQJoZ.js","assets/scroll-restoration-CwXbvZvT.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{R as n,St as r,Tt as i,_ as a,d as o,f as s,p as c,u as l}from"./protocol-support-CsLR9u7d.js";import{at as u,ct as d,it as f,k as p,lt as m,nt as h,o as g,ot as _,rt as v,st as y,tt as b}from"./auth-olLlgxc3.js";import{n as x,t as S}from"./context-C3-WejyN.js";import{i as C,r as w,t as ee}from"./client-settings-CwqpIric.js";import{t as T}from"./jsx-runtime-By8HlURe.js";import{t as E}from"./preload-helper-Czpn1I53.js";import{a as D,r as O}from"./index-BKT8bLLH.js";import{t as k}from"./purify.es-D8QhFVkO.js";import"./katex.min-ZqdHjttS.js";import{a as A,c as j,h as te,i as M,p as N,r as P}from"./editor.api2-4X9Vh9Zw.js";import{n as F,r as ne,t as re}from"./api-BOuyloUi.js";import{c as ie,g as ae,p as oe}from"./hotkeys-Cu0t6sbz.js";import{B as se,C as ce,E as le,J as ue,K as de,O as fe,P as pe,R as me,T as he,U as ge,W as _e,X as ve,Y as ye,Z as be,_ as xe,a as Se,at as Ce,d as we,i as Te,it as Ee,j as De,k as Oe,m as ke,n as Ae,nt as je,ot as Me,r as Ne,rt as Pe,st as Fe,u as Ie,v as Le,w as Re}from"./media-refresh-store-CHPkX-XV.js";import{n as ze}from"./dist-BOS6OKSE.js";import{t as Be}from"./x-Dq6POV20.js";import{n as Ve,t as He}from"./chevron-right-BP2NLwlG.js";import{n as Ue,r as We}from"./dist-BHBQY7ao.js";import{t as Ge}from"./createLucideIcon-C9A1vLE-.js";import{a as Ke,i as qe,n as Je,o as Ye,r as Xe,t as Ze}from"./select-C0UTbo8D.js";import{t as Qe}from"./chevron-down-HQLVE6o5.js";import{a as $e,n as et,o as tt,r as nt,t as rt}from"./FindWidget-CaVwYvST.js";import{t as it}from"./copy-D0Theg4Q.js";import{t as at}from"./rotate-ccw-BI2k_h3A.js";import{a as ot,i as st,n as ct,o as lt,r as ut,t as dt}from"./preview-kind-CPkO-rSz.js";import{t as ft}from"./control-tray-OJfh0_ml.js";import{a as pt,o as mt,r as ht,s as gt,t as _t}from"./command-BkdEYC1b.js";import{n as vt,r as yt,t as bt}from"./popover-B5Bw2ljC.js";import{i as xt,n as St,r as Ct}from"./markdown-it-CWoG9_Dn.js";import{t as wt}from"./debounce-B9DrqirV.js";import{a as Tt,c as Et,d as Dt,f as Ot,i as kt,l as At,o as jt,p as Mt,r as Nt,s as Pt,t as Ft,u as It}from"./buffer-store-D78ZR3kb.js";import{r as Lt,t as Rt}from"./view-state-store-Cy9sQJoZ.js";import{a as zt,c as Bt,i as Vt,n as Ht,o as Ut,r as Wt,s as Gt,t as Kt}from"./markdown-CMSzQtLp.js";import{i as qt,n as Jt,r as Yt,t as Xt}from"./drafts-B_tChlzR.js";import{r as Zt}from"./buffer-logic-BAkSBQT7.js";import{a as Qt,i as $t,n as en,o as tn,r as nn}from"./editor-sync-W1bamxAP.js";import{r as rn,t as an}from"./math-CSw6sgCC.js";import{n as on}from"./math-delimiters-BCnTi7Ii.js";import{n as sn}from"./markdown-mermaid-A8_2kS9k.js";var cn=Ge(`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`}]]),ln=Ge(`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`}]]),un=Ge(`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`}]]),dn=Ge(`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`}]]),fn=Ge(`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`}]]),I=e(t(),1),L=T();String.prototype.codePointAt;function pn(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 mn=pn(/["&\u00A0]/g,new Map([[34,`&quot;`],[38,`&amp;`],[160,`&nbsp;`]])),hn=pn(/[&<>\u00A0]/g,new Map([[38,`&amp;`],[60,`&lt;`],[62,`&gt;`],[160,`&nbsp;`]])),gn=new Map,_n=new Map,vn=1;function yn(e){for(let t of _n.get(e)??[])t()}function bn(e,t){gn.set(e,t),yn(e)}function xn(e){let t={phase:`unresolved`,revision:vn++};return bn(e,t),t}function Sn(e){let t=gn.get(e);return!t||t.phase!==`unresolved`&&t.phase!==`load-error`?null:(bn(e,{phase:`loading`,revision:t.revision}),t.revision)}function Cn(e,t,n,r){let i=gn.get(e);return!i||i.phase!==`loading`||i.revision!==t?!1:(bn(e,{phase:`opening`,revision:t,content:n,mtimeMs:r}),!0)}function wn(e,t){let n=gn.get(e);return!n||n.phase!==`opening`||n.revision!==t?!1:(bn(e,{...n,phase:`comparing`}),!0)}function Tn(e,t,n){let r=gn.get(e);return!r||r.phase!==`loading`||r.revision!==t?!1:(bn(e,{phase:`load-error`,revision:t,message:n}),!0)}function En(e,t){return t&&e?.phase===`unresolved`}function Dn(e){return e?.phase===`comparing`?e.mtimeMs:void 0}function On(e){return e?.phase===`loading`||e?.phase===`load-error`||e?.phase===`opening`}function kn(e){return e.phase===`opening`||e.phase===`comparing`}function An(e){gn.delete(e)&&yn(e)}function jn(e){return gn.get(e)??null}function Mn(e,t){let n=_n.get(e);return n||(n=new Set,_n.set(e,n)),n.add(t),()=>n.delete(t)}function Nn(e){return{tabSize:e,insertSpaces:!0,detectIndentation:!1}}var Pn=new Rt,Fn=new Rt;function In(e){let t={...e.contributionsState};return delete t[`editor.contrib.wordHighlighter`],{...e,contributionsState:t}}function Ln(e,t){let n=(0,I.useRef)(null),r=(0,I.useRef)(null);return(0,I.useLayoutEffect)(()=>(n.current&&(r.current=t(n.current,e)),()=>{r.current?.(),r.current=null}),[e,t]),(0,I.useCallback)(i=>{r.current?.(),n.current=i,i.onDidDispose(()=>{n.current===i&&(n.current=null)}),r.current=t(i,e)},[e,t])}function Rn(e,t){let n=Pn.get(t);n&&e.restoreViewState(n);let r=()=>{if(!e.getModel())return;let n=e.saveViewState();n&&Pn.set(t,In(n))},i=[e.onDidScrollChange(r),e.onDidChangeCursorSelection(r)];return()=>{r(),i.forEach(e=>e.dispose())}}function zn(e,t){let n=Fn.get(t),r=n!==void 0,i=()=>{if(r||!e.getModel())return;let n=e.saveViewState();n&&Fn.set(t,{...n,original:n.original&&In(n.original),modified:n.modified&&In(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 Bn(e){return Ln(Lt(`code`,e),Rn)}function Vn(e){return Ln(Lt(`diff`,e),zn)}function Hn({session:e,path:t,conflict:n,model:r,onTakeDisk:i,onKeepMine:a,onSave:o,onReady:s}){let c=C(),l=Vn([`conflict`,r.uri.toString()]),u=(0,I.useId)(),d=(0,I.useMemo)(()=>getComputedStyle(document.documentElement).getPropertyValue(`--font-mono`).trim()||void 0,[]),f=(0,I.useRef)(o);f.current=o;let p=(0,I.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,I.useRef)(m);return h.current=m,(0,I.useEffect)(()=>()=>h.current(),[]),(0,L.jsxs)(`div`,{className:`flex h-full flex-col bg-ground`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-3 bg-elevated px-3 py-1.5 text-xs text-fg-secondary`,children:[(0,L.jsx)(`span`,{children:`This file changed on disk. Yours is on the right — merge what you want, then save.`}),(0,L.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,L.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,L.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,L.jsx)(Mt,{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:Dt,keepCurrentModifiedModel:!0,loading:(0,L.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(M.CtrlCmd|P.KeyS,()=>f.current()),s?.(n.revision)},options:{readOnly:n.phase!==`comparing`,originalEditable:!1,renderSideBySide:!0,automaticLayout:!0,fontFamily:d,fontSize:c.editorFontSize,...Nn(c.editorTabSize),wordWrap:c.editorWordWrap?`on`:`off`,minimap:{enabled:!1},fixedOverflowWidgets:!0,scrollBeyondLastLine:!1}})})]})}function Un({session:e,path:t,buffer:n,focused:r}){let i=n.conflict;return!i||i.phase===`unresolved`?null:kn(i)&&n.model?(0,L.jsx)(Hn,{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,L.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,L.jsx)(`span`,{children:`The disk version could not be loaded.`}),(0,L.jsx)(`span`,{className:`max-w-lg text-xs text-fg-secondary`,children:i.message}),(0,L.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,L.jsx)(`div`,{className:`flex h-full items-center justify-center bg-ground text-sm text-fg-muted`,children:`Loading the disk version…`})}function Wn(e){return Number.isFinite(e)?Math.min(1,Math.max(0,e)):0}function Gn(e,t,n){return Wn(e/Math.max(1,t-n))}function Kn(e,t,n){return Wn(e)*Math.max(0,t-n)}function qn(e,t){return JSON.stringify([e,t.session,t.root??null,t.path])}var Jn=new class{positions=new Map;listeners=new Map;revision=0;publish(e,t,n,r=null){let i={ratio:Wn(n),sourceLine:r!==null&&Number.isFinite(r)?Math.max(1,r):null,revision:++this.revision},a=qn(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(qn(e,t))}subscribe(e,t,n){let r=qn(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)}}},Yn=new Rt;function Xn(e){let t=null;return{schedule:()=>{t===null&&(t=requestAnimationFrame(()=>{t=null,e()}))},dispose:()=>{t!==null&&cancelAnimationFrame(t),t=null}}}function Zn(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=Gt(r,e.sourceLine);if(t!==null)return Math.min(i,Math.max(0,t))}return Kn(e.ratio,t,n)}function Qn(e,t){if(t.driver&&t.receiver)throw Error(`a preview scroll surface cannot be both driver and receiver`);let n=t.store??Jn,r=t.viewKey?Yn.get(t.viewKey):void 0,i=t.sourceAnchors?.(),a=()=>void 0,o,s=n=>{r=n,t.viewKey&&Yn.set(t.viewKey,n),e.scrollTop=Zn(n,e.scrollHeight,e.clientHeight,i)};r&&s(r);let c=()=>{if(e.clientHeight<=0)return;let a=Gn(e.scrollTop,e.scrollHeight,e.clientHeight),o=i?Bt(i,e.scrollTop):null;r={ratio:a,sourceLine:o,revision:0},t.viewKey&&Yn.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=Xn(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 $n(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 er(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 tr(e,t,n){if(t.driver&&t.receiver)throw Error(`a Monaco scroll surface cannot be both driver and receiver`);let r=t.store??Jn,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?er(e,t.sourceLine):null;e.setScrollTop(r??Zn(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=Xn(()=>{let n=Gn(e.getScrollTop(),e.getScrollHeight(),c());r.publish(t.channel,t.target,n,$n(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 nr(e){return!e}function rr(e){let t=e.split(`+`),n=t.pop()??``,r=0;for(let e of t)e===`meta`?r|=M.CtrlCmd:e===`ctrl`?r|=M.WinCtrl:e===`alt`?r|=M.Alt:e===`shift`&&(r|=M.Shift);let i=P[/^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 ir(e,t){let n=rr(ie(`editor.save`));n!==null&&e.addCommand(n,()=>t.onSave());let r=rr(ie(`editor.wordWrap`));e.addAction({id:`puddle.toggleWordWrap`,label:`Toggle Word Wrap`,keybindings:r===null?[]:[r],run:()=>w({editorWordWrap:nr(ee().editorWordWrap)})})}var ar=new WeakSet;function or(e){return ar.has(e)?!1:(ar.add(e),!0)}function sr(e){return`file-conflict:${e}`}function cr(e,t,n,r,i){let a=i?.passive===!0,o=i?.focused??!0,s=Ft(e,t,r),c=be(e,t,{root:r,live:i?.live}),l=ye(e,r),[u,d]=(0,I.useState)(null),[f,p]=(0,I.useState)(!1),m=(0,I.useRef)(!1),h=(0,I.useRef)(null),g=(0,I.useRef)(null),_=(0,I.useRef)(n);_.current=n;let v=(0,I.useRef)(!1),y=(0,I.useCallback)((e,t)=>{g.current?.cancel(),v.current=!0;try{Pt(s,e,t)}finally{v.current=!1}},[s]),b=(0,I.useSyncExternalStore)((0,I.useCallback)(e=>It(s,e),[s]),()=>kt(s)),x=(0,I.useSyncExternalStore)((0,I.useCallback)(e=>tn(s,e),[s]),()=>Qt(s)),S=(0,I.useSyncExternalStore)((0,I.useCallback)(e=>Mn(s,e),[s]),()=>jn(s));(0,I.useEffect)(()=>{let n=c.data;if(!n||n.binary||n.content===null||m.current)return;m.current=!0;let i=At(s)!==void 0,a=Nt(e,t,n.content,n.mtime_ms,r),o=a.getValue();d(a),!i&&qt(e,t,r).then(i=>{if(!i)return;let s=Jt(i,o,n.mtime_ms);s===`discard`?Xt(e,t,r):s===`restore`?Zt(a,i.content)&&p(!0):ze(`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:()=>{Zt(a,i.content)&&p(!0)}}})})},[c.data,s,e,t,r]),(0,I.useEffect)(()=>{if(!u||a)return;let n=Yt(e,t,r);g.current=n;let i=u.onDidChangeContent(()=>{v.current||(n(u.getValue(),At(s)??0),en(e,t,r))});return()=>{n.flush(),i.dispose(),g.current=null}},[u,s,e,t,r,a]),(0,I.useEffect)(()=>{!u||!x.savedElsewhere||kt(s)||c.refetch().then(e=>{kt(s)||(e.data&&e.data.content!==null&&y(e.data.content,e.data.mtime_ms),$t(s))})},[x.savedElsewhere,u,s]),(0,I.useEffect)(()=>{let e=c.data;!u||!e||e.content===null||!kt(s)&&e.mtime_ms!==At(s)&&y(e.content,e.mtime_ms)},[c.data,u,s]);let C=(0,I.useCallback)((n,i)=>{Tt(s,n,i),g.current?.cancel(),Xt(e,t,r),nn(e,t,i,r),p(!1),An(s)},[s,e,t,r]),w=(0,I.useCallback)(()=>{let e=Sn(s);e!==null&&(ze.dismiss(sr(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.`);Cn(s,e,n.content,n.mtime_ms)}).catch(t=>{Tn(s,e,t instanceof Error?t.message:`The disk version did not load.`)}))},[c,s]),ee=(0,I.useRef)(w);ee.current=w,(0,I.useEffect)(()=>{if(!En(S,o))return;let e=sr(s);return ze(`File changed on disk`,{id:e,description:`Nothing was written — your unsaved version is intact.`,duration:1/0,closeButton:!0,action:{label:`Compare`,onClick:()=>ee.current()}}),()=>{ze.dismiss(e)}},[S,o,s]);let T=(0,I.useCallback)(()=>{c.refetch().then(n=>{n.data&&n.data.content!==null&&y(n.data.content,n.data.mtime_ms),Xt(e,t,r),p(!1),An(s)})},[s,e,t,y]),E=(0,I.useCallback)((e,n)=>{l.mutate({path:t,content:e},{onSuccess:e=>C(n,e.mtime_ms),onError:e=>ze.error(e instanceof Error?e.message:`Overwrite failed`)})},[l,t,C]),D=(0,I.useCallback)(async()=>{if(!u||!kt(s))return!0;let e=u.getValue(),n=u.getAlternativeVersionId();if(On(jn(s)))return!1;let r=Dn(jn(s))??At(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 re&&e.status===409&&e.code===`stale_file`?xn(s):ze.error(e instanceof Error?e.message:`Save failed`),!1}},[u,s,l,t,C]),O=(0,I.useRef)(D);O.current=D,(0,I.useEffect)(()=>fe(De(e,t,r),()=>O.current(),{session:e,path:t,...r===void 0?{}:{root:r}}),[e,t,r]);let k=(0,I.useCallback)(()=>{let n=h.current,i=_.current;!n||!i||!o||i.session!==e||i.path!==t||(i.root??void 0)!==(r??void 0)||or(i)&&(n.revealLineInCenter(i.line),n.setPosition({lineNumber:i.line,column:i.column??1}),n.focus())},[e,t,r,o]),A=(0,I.useCallback)(e=>{h.current=e,ir(e,{onSave:()=>O.current()}),k()},[k]);(0,I.useEffect)(()=>{k()},[n,u,k]);let j=(0,I.useCallback)(()=>{T()},[T]),te=(0,I.useCallback)(()=>{!u||jn(s)?.phase!==`comparing`||E(u.getValue(),u.getAlternativeVersionId())},[u,s,E]),M=(0,I.useCallback)(e=>{wn(s,e)},[s]),N,P=null;c.data?.binary?N=`binary`:c.error?c.error instanceof re&&c.error.status===413?N=`too-large`:(N=`error`,P=c.error instanceof Error?c.error.message:`Failed to load file`):N=u?`ready`:`loading`;let F=b&&x.savedElsewhere?`saved-elsewhere`:b&&x.dirtyElsewhere?`dirty-elsewhere`:null;return{status:N,errorMessage:P,model:u,dirty:b,restoredNotice:f,discardRestore:j,peerBadge:F,conflict:S,takeDisk:T,keepMine:te,compare:w,comparisonReady:M,save:D,onMount:A}}function lr(e,t,n,r){for(let i of e)if(mr([i],n).some(e=>(r===void 0||e.kind===r)&&t>=e.startLineNumber&&t<=e.endLineNumber))return i;return null}function ur(e,t){return fr(e.modifiedStartLineNumber,e.modifiedEndLineNumber)>0?Math.min(t,e.modifiedEndLineNumber):Math.max(0,Math.min(t,e.modifiedStartLineNumber-1))}function dr(e){let t=fr(e.originalStartLineNumber,e.originalEndLineNumber),n=fr(e.modifiedStartLineNumber,e.modifiedEndLineNumber);return Math.max(5,Math.min(14,t+n+4))}function fr(e,t){return t===0?0:Math.max(0,t-e+1)}function pr(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 mr(e,t){let n=[];for(let r of e){let e=fr(r.originalStartLineNumber,r.originalEndLineNumber),i=fr(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(pr(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(pr(r.modifiedStartLineNumber+i,t))}return n}var hr=28,gr=[[`puddle-dirty-added`,`added`],[`puddle-dirty-modified`,`modified`],[`puddle-dirty-deleted-before`,`deleted-before`],[`puddle-dirty-deleted-after`,`deleted-after`]];function _r(e){if(e){for(let[t,n]of gr)if(e.classList.contains(t)||e.closest(`.${t}`))return n}}function vr({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,N.ScrollType.Immediate)},u=(i,s)=>{if(a?.anchorLine===i){c();return}c();let u=e.getOption(N.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:ur(s,n.getLineCount()),heightInPx:hr+dr(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=N.createDiffEditor(h,{readOnly:!0,domReadOnly:!0,originalEditable:!1,renderSideBySide:!1,renderMarginRevertIcon:!1,renderOverviewRuler:!1,enableSplitViewResizing:!1,isInEmbeddedEditor:!0,automaticLayout:!0,fontFamily:e.getOption(N.EditorOption.fontFamily),fontSize:e.getOption(N.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!==N.MouseTargetType.GUTTER_LINE_DECORATIONS||e.target.position===null)return;let t=e.target.position.lineNumber,r=lr(i,t,n.getLineCount(),_r(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=lr(t,r.anchorLine,n.getLineCount());if(!o){c();return}r.change=o,r.zone.afterLineNumber=ur(o,n.getLineCount()),r.zone.heightInPx=hr+dr(o)*e.getOption(N.EditorOption.lineHeight);try{e.changeViewZones(e=>e.layoutZone(r.zoneId))}catch{c();return}l(r)},dispose(){o=!0,d.dispose(),c()}}}var yr={added:`puddle-dirty-added`,modified:`puddle-dirty-modified`,"deleted-before":`puddle-dirty-deleted-before`,"deleted-after":`puddle-dirty-deleted-after`};function br(e,t,r,i){let o=n(),s=de(e,t,{root:r,enabled:o.data!==void 0&&a(o.data.protocol)&&i!==null}),[c,l]=(0,I.useState)(null),u=(0,I.useCallback)(e=>{l(e)},[]);return(0,I.useLayoutEffect)(()=>{let e=s.data;if(!c||!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=N.createModel(e.exists?e.content??``:``,i.getLanguageId()),a=N.createDiffEditor(n,{readOnly:!0,automaticLayout:!1,renderSideBySide:!1,minimap:{enabled:!1}}),o=c.createDecorationsCollection();a.setModel({original:r,modified:i});let l=vr({editor:c,original:r,modified:i,path:t}),u=()=>{let e=a.getLineChanges();e&&(l.update(e),o.set(mr(e,i.getLineCount()).map(e=>({range:new j(e.startLineNumber,1,e.endLineNumber,1),options:{isWholeLine:!0,linesDecorationsClassName:yr[e.kind]}}))))},d=a.onDidUpdateDiff(u);return u(),()=>{d.dispose(),l.dispose(),o.clear(),a.setModel(null),a.dispose(),r.dispose(),n.remove()}},[c,i,s.data]),u}function xr({message:e,session:t,path:n,root:r,download:i}){return(0,L.jsxs)(`div`,{className:`flex h-full flex-col items-center justify-center gap-3 bg-ground text-sm text-fg-muted`,children:[(0,L.jsx)(`span`,{children:e}),i&&(0,L.jsxs)(`button`,{type:`button`,onClick:()=>void me(t,n,r).catch(e=>ze.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,L.jsx)(Ce,{className:`size-4`}),`Download`]})]})}function Sr({session:e,path:t,reveal:n,root:r,focused:i=!0,scrollDriver:a=!1,scrollReceiver:o=!1,scrollChannel:s=`profile`}){let c=C(),l=Bn([e,r,t]),u=cr(e,t,n,r,{focused:i}),d=pe(e,t,r),f=br(e,t,r,u.model),p=(0,I.useMemo)(()=>getComputedStyle(document.documentElement).getPropertyValue(`--font-mono`).trim()||void 0,[]),[m,h]=(0,I.useState)(null),g=(0,I.useMemo)(()=>({session:e,path:t,root:r}),[e,t,r]),_=u.conflict!==null&&u.conflict.phase!==`unresolved`;if((0,I.useEffect)(()=>{if(!(!m||!u.model||_))return tr(m,{channel:s,target:g,driver:a,receiver:o},N.ScrollType.Immediate)},[m,u.model,_,s,g,a,o]),(0,I.useEffect)(()=>{let e=u.model;e&&N.setModelMarkers(e,`puddle-compilation`,d.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`?A.Error:t.severity===`warning`?A.Warning:A.Info,message:t.message,source:`Puddle compilation`,startLineNumber:n,startColumn:i,endLineNumber:o,endColumn:Math.max(i,c)}}))},[u.model,d]),u.conflict&&u.conflict.phase!==`unresolved`)return(0,L.jsx)(Un,{session:e,path:t,buffer:u,focused:i});if(u.status===`binary`)return(0,L.jsx)(xr,{message:`Binary file — use Download`,session:e,path:t,root:r,download:!0});if(u.status===`too-large`)return(0,L.jsx)(xr,{message:`File too large to edit — use Download`,session:e,path:t,root:r,download:!0});if(u.status===`error`)return(0,L.jsx)(xr,{message:u.errorMessage??`Failed to load file`,session:e,path:t,root:r});let v=u.peerBadge===`saved-elsewhere`?`Saved in another window`:u.peerBadge===`dirty-elsewhere`?`Also being edited in another window`:null;return(0,L.jsxs)(`div`,{className:`flex h-full flex-col bg-ground`,children:[u.restoredNotice&&(0,L.jsxs)(`div`,{className:`flex items-center gap-3 bg-elevated px-3 py-1.5 text-xs text-fg-secondary`,children:[(0,L.jsx)(`span`,{children:`Restored unsaved changes`}),(0,L.jsx)(`button`,{type:`button`,onClick:u.discardRestore,className:`text-fg-muted transition-colors hover:text-fg`,children:`Discard`})]}),v&&(0,L.jsx)(`div`,{className:`bg-surface px-3 py-1 text-xs text-fg-muted`,children:v}),(0,L.jsx)(`div`,{className:`min-h-0 flex-1 pl-1`,children:u.model&&(0,L.jsx)(Ot,{path:u.model.uri.toString(),defaultValue:u.model.getValue(),theme:`puddle`,keepCurrentModel:!0,saveViewState:!1,onMount:e=>{l(e),u.onMount(e),f(e),h(e)},loading:(0,L.jsx)(`div`,{className:`p-3 text-xs text-fg-muted`,children:`…`}),options:{automaticLayout:!0,fontFamily:p,fontSize:c.editorFontSize,...Nn(c.editorTabSize),wordWrap:c.editorWordWrap?`on`:`off`,minimap:{enabled:!1},glyphMargin:!1,lineNumbersMinChars:1,lineDecorationsWidth:5,fixedOverflowWidgets:!0,scrollBeyondLastLine:!1}})})]})}function R({children:e}){return(0,L.jsx)(`div`,{className:`flex h-full items-center justify-center px-4 text-xs text-fg-muted`,children:e})}function Cr(e,t){let n=(0,I.useRef)(t);n.current=t,(0,I.useEffect)(()=>(Et(e),()=>{n.current?.(),jt(e)}),[e])}function wr(e,t,n,r){let i=r.split(`/`).map(encodeURIComponent).join(`/`);return`${e}://${encodeURIComponent(t)}/${encodeURIComponent(n)}/${i}`}function Tr({session:e,refName:t,path:n,content:r}){let i=C(),a=Bn([e,t,n]),o=(0,I.useMemo)(()=>getComputedStyle(document.documentElement).getPropertyValue(`--font-mono`).trim()||void 0,[]);return(0,L.jsx)(Ot,{path:wr(`puddle-view`,e,t,n),defaultValue:r,theme:Dt,saveViewState:!1,onMount:a,loading:(0,L.jsx)(R,{children:`…`}),options:{readOnly:!0,automaticLayout:!0,fontFamily:o,fontSize:i.editorFontSize,...Nn(i.editorTabSize),minimap:{enabled:!1},fixedOverflowWidgets:!0,scrollBeyondLastLine:!1}})}function Er({session:e,against:t,path:n,root:r,indexBase:i=!1}){let a=_e(e,t,n,{root:r,enabled:!i}),o=ue(e,n,{root:r,enabled:i}),s=i?o:a;return s.isPending?(0,L.jsx)(R,{children:`…`}):s.error?(0,L.jsx)(R,{children:s.error instanceof Error?s.error.message:`Failed to load`}):s.data.binary?(0,L.jsx)(R,{children:`Binary file — deleted`}):(0,L.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,L.jsx)(`div`,{className:`bg-surface px-4 py-1 text-xs text-fg-muted`,children:`Deleted`}),(0,L.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,L.jsx)(Tr,{session:e,refName:`${t}:${r??``}`,path:n,content:s.data.content??``})})]})}function Dr({session:e,against:t,path:n,basePath:r,root:i,indexBase:a=!1,focused:o=!0}){let s=C(),c=Vn([e,i,t,a,n]),l=cr(e,n,null,i,{focused:o}),u=_e(e,t,r,{root:i,enabled:!a}),d=ue(e,r,{root:i,enabled:a}),f=a?d:u,p=(0,I.useRef)(null);Cr(Ft(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,I.useRef)(l.save);m.current=l.save;let h=(0,I.useMemo)(()=>getComputedStyle(document.documentElement).getPropertyValue(`--font-mono`).trim()||void 0,[]),g=f.error instanceof re&&f.error.status===404;return l.conflict&&l.conflict.phase!==`unresolved`?(0,L.jsx)(Un,{session:e,path:n,buffer:l,focused:o}):l.status===`binary`||f.data?.binary?(0,L.jsx)(R,{children:`Binary file`}):l.status===`too-large`?(0,L.jsx)(R,{children:`File too large to show`}):l.status===`error`?(0,L.jsx)(R,{children:l.errorMessage??`Failed to load file`}):g||a&&d.data&&!d.data.exists?(0,L.jsx)(Sr,{session:e,path:n,reveal:null,root:i,focused:o}):f.isPending||!l.model?(0,L.jsx)(R,{children:`…`}):f.error?(0,L.jsx)(R,{children:f.error instanceof Error?f.error.message:`Failed to load base`}):(0,L.jsx)(Mt,{modifiedModelPath:l.model.uri.toString(),originalModelPath:wr(`puddle-base`,e,`${t}:${i??``}`,r),original:f.data.content??``,language:l.model.getLanguageId(),theme:Dt,keepCurrentModifiedModel:!0,loading:(0,L.jsx)(R,{children:`…`}),onMount:e=>{c(e),p.current=e,e.onDidDispose(()=>{p.current=null}),e.getModifiedEditor().addCommand(M.CtrlCmd|P.KeyS,()=>m.current())},options:{readOnly:!1,originalEditable:!1,renderSideBySide:!0,automaticLayout:!0,fontFamily:h,fontSize:s.editorFontSize,...Nn(s.editorTabSize),wordWrap:s.editorWordWrap?`on`:`off`,minimap:{enabled:!1},fixedOverflowWidgets:!0,scrollBeyondLastLine:!1}})}function Or({session:e,against:t,entry:n,root:r}){let i=C(),a=Vn([e,r,t,`staged`,n.path]),o=n.old_path??n.path,s=_e(e,t,o,{root:r,enabled:n.status!==`added`}),c=ue(e,n.path,{root:r,enabled:n.status!==`deleted`}),l=(0,I.useMemo)(()=>getComputedStyle(document.documentElement).getPropertyValue(`--font-mono`).trim()||void 0,[]);if(n.status===`deleted`)return(0,L.jsx)(Er,{session:e,against:t,path:o,root:r});if(c.isPending||n.status!==`added`&&s.isPending)return(0,L.jsx)(R,{children:`…`});if(c.error||s.error){let e=c.error??s.error;return(0,L.jsx)(R,{children:e instanceof Error?e.message:`Failed to load staged content`})}return c.data.binary||s.data?.binary?(0,L.jsx)(R,{children:`Binary file`}):n.status===`added`?(0,L.jsx)(Tr,{session:e,refName:`index:${r??``}`,path:n.path,content:c.data.content??``}):s.data?(0,L.jsx)(Mt,{originalModelPath:wr(`puddle-head`,e,`${t}:${r??``}`,o),modifiedModelPath:wr(`puddle-index`,e,`${t}:${r??``}`,n.path),original:s.data.content??``,modified:c.data.content??``,onMount:a,theme:Dt,loading:(0,L.jsx)(R,{children:`…`}),options:{readOnly:!0,originalEditable:!1,renderSideBySide:!0,automaticLayout:!0,fontFamily:l,fontSize:i.editorFontSize,...Nn(i.editorTabSize),wordWrap:i.editorWordWrap?`on`:`off`,minimap:{enabled:!1},fixedOverflowWidgets:!0,scrollBeyondLastLine:!1}}):(0,L.jsx)(R,{children:`Failed to load HEAD content`})}function kr({session:e,path:t,root:n,focused:r}){return Cr(Ft(e,t,n)),(0,L.jsx)(Sr,{session:e,path:t,reveal:null,root:n,focused:r})}function Ar({session:e,against:t,entry:n,root:r,area:i,focused:a=!0}){if(i===`staged`)return(0,L.jsx)(Or,{session:e,against:t,entry:n,root:r});switch(n.status){case`added`:return(0,L.jsx)(kr,{session:e,path:n.path,root:r,focused:a});case`deleted`:return(0,L.jsx)(Er,{session:e,against:t,path:n.path,root:r,indexBase:i===`unstaged`});case`modified`:case`renamed`:return(0,L.jsx)(Dr,{session:e,against:t,path:n.path,basePath:n.old_path??n.path,root:r,indexBase:i===`unstaged`,focused:a});default:return null}}function jr({session:e,sha:t,path:n,root:r}){let i=_e(e,t,n,{root:r});return i.isPending?(0,L.jsx)(R,{children:`…`}):i.error?(0,L.jsx)(R,{children:i.error instanceof Error?i.error.message:`Failed to load file`}):i.data.binary?(0,L.jsx)(R,{children:`Binary file`}):(0,L.jsx)(Tr,{session:e,refName:`${t}:${r??``}`,path:n,content:i.data.content??``})}function Mr({session:e,originalRef:t,originalPath:n,originalContent:r,modifiedRef:i,modifiedPath:a,modifiedContent:o,root:s}){let c=C(),l=Vn([e,s,t,n,i,a]),u=(0,I.useRef)(null),d=(0,I.useMemo)(()=>getComputedStyle(document.documentElement).getPropertyValue(`--font-mono`).trim()||void 0,[]);return(0,I.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,L.jsx)(Mt,{originalModelPath:wr(`puddle-hist-orig`,e,`${t}:${s??``}`,n),modifiedModelPath:wr(`puddle-hist-mod`,e,`${i}:${s??``}`,a),original:r,modified:o,theme:Dt,keepCurrentOriginalModel:!0,keepCurrentModifiedModel:!0,loading:(0,L.jsx)(R,{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,...Nn(c.editorTabSize),minimap:{enabled:!1},fixedOverflowWidgets:!0,scrollBeyondLastLine:!1}})}function Nr({session:e,sha:t,path:n,basePath:r,root:i}){let a=_e(e,`${t}^`,r,{root:i}),o=_e(e,t,n,{root:i});return a.error instanceof re&&a.error.status===404?(0,L.jsx)(jr,{session:e,sha:t,path:n,root:i}):a.isPending||o.isPending?(0,L.jsx)(R,{children:`…`}):a.error?(0,L.jsx)(R,{children:a.error instanceof Error?a.error.message:`Failed to load original`}):o.error?(0,L.jsx)(R,{children:o.error instanceof Error?o.error.message:`Failed to load file`}):a.data.binary||o.data.binary?(0,L.jsx)(R,{children:`Binary file`}):(0,L.jsx)(Mr,{session:e,originalRef:`${t}^`,originalPath:r,originalContent:a.data.content??``,modifiedRef:t,modifiedPath:n,modifiedContent:o.data.content??``,root:i})}function Pr({session:e,sha:t,entry:n,isRootCommit:r,root:i}){switch(le(n.status,r)){case`added`:return(0,L.jsx)(jr,{session:e,sha:t,path:n.path,root:i});case`deleted`:return(0,L.jsx)(Er,{session:e,against:`${t}^`,path:n.path,root:i});case`modified`:case`renamed`:return(0,L.jsx)(Nr,{session:e,sha:t,path:n.path,basePath:n.old_path??n.path,root:i});default:return null}}function Fr({session:e,sha:t,path:n,root:r}){let i=ge(e,t,r);if(i.isPending)return(0,L.jsx)(`div`,{className:`px-4 py-3 text-xs text-fg-muted`,children:`Loading commit…`});if(i.error)return(0,L.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,L.jsx)(`div`,{className:`h-full`,children:(0,L.jsx)(Pr,{session:e,sha:t,entry:a,isRootCommit:i.data.parents.length===0,root:r})}):(0,L.jsxs)(`div`,{className:`flex h-full items-center justify-center px-4 text-center text-xs text-fg-muted`,children:[(0,L.jsx)(`span`,{className:`text-fg-secondary`,children:n}),` is not part of`,` `,(0,L.jsx)(`span`,{className:`font-mono`,children:t.slice(0,7)}),`.`]})}function Ir({session:e,path:t,root:n,area:r,focused:i=!0}){let a=ve(e,{root:n,against:r===void 0?`base`:`head`,area:r});if(a.isPending)return(0,L.jsx)(`div`,{className:`px-4 py-3 text-xs text-fg-muted`,children:`Loading diff…`});if(a.error)return(0,L.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,L.jsx)(`div`,{className:`h-full`,children:(0,L.jsx)(Ar,{session:e,against:a.data.against,entry:o,root:n,area:r,focused:i})}):(0,L.jsxs)(`div`,{className:`flex h-full items-center justify-center px-4 text-center text-xs text-fg-muted`,children:[`No changes to `,(0,L.jsx)(`span`,{className:`mx-1 text-fg-secondary`,children:t}),` against the base.`]})}var Lr=800;function Rr({name:e}){let t=C(),n=ae(),r=Bn([n,e]),a=he(n,e),o=i(),s=oe(`editor.save`),c=(0,I.useRef)(null),l=(0,I.useRef)(null),u=(0,I.useMemo)(()=>getComputedStyle(document.documentElement).getPropertyValue(`--font-mono`).trim()||void 0,[]);if((0,I.useEffect)(()=>{if(n===null)return;let t=wt(t=>{ce(n,e,t).catch(e=>ze.error(e instanceof Error?e.message:`Draft not saved`))},Lr);return l.current=t,()=>{t.flush(),l.current=null}},[n,e]),n===null)return null;if(a.error)return(0,L.jsx)(`div`,{className:`flex h-full items-center justify-center bg-ground text-sm text-fg-muted`,children:a.error instanceof Error?a.error.message:`Failed to load the draft`});if(a.data===void 0)return(0,L.jsx)(`div`,{className:`p-3 text-xs text-fg-muted`,children:`…`});let d=()=>{let t=c.current;t&&(l.current?.flush(),Le({name:e,content:t.getValue()}))};return(0,L.jsxs)(`div`,{className:`flex h-full flex-col bg-ground`,children:[(0,L.jsxs)(`div`,{className:`bg-surface px-3 py-1 text-xs text-fg-muted`,children:[`Draft — not in any worktree; `,s,` saves it into one`]}),(0,L.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,L.jsx)(Ot,{path:`puddle-untitled://${n}/${e}`,defaultValue:a.data.content,theme:Dt,keepCurrentModel:!1,saveViewState:!1,loading:(0,L.jsx)(`div`,{className:`p-3 text-xs text-fg-muted`,children:`…`}),onMount:t=>{r(t),c.current=t,xe(e,t.getValue()),ir(t,{onSave:d})},onChange:t=>{let r=t??``;xe(e,r),Re(o,n,e,r),l.current?.(r)},options:{automaticLayout:!0,fontFamily:u,fontSize:t.editorFontSize,...Nn(t.editorTabSize),minimap:{enabled:!1},fixedOverflowWidgets:!0,scrollBeyondLastLine:!1,wordWrap:t.editorWordWrap?`on`:`off`}})})]})}var zr=d([y(),h(y())]),Br=_(y(),m()),Vr=f({output_type:y(),text:zr.optional(),data:_(y(),m()).optional(),traceback:h(y()).optional(),ename:y().optional(),evalue:y().optional()}),Hr=f({id:y().optional(),cell_type:b([`code`,`markdown`,`raw`]),metadata:Br,source:zr,outputs:h(Vr).optional(),execution_count:u().int().nullable().optional()}),Ur=f({nbformat:v(4),nbformat_minor:u().int().nonnegative(),metadata:Br,cells:h(Hr).max(2e3)});function Wr(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=Ur.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 z(e){return typeof e==`string`?e:Array.isArray(e)&&e.every(e=>typeof e==`string`)?e.join(``):``}function Gr(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:z(e.source),state:`saved`}}}:{}}:e)}}function Kr(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 qr(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 Jr(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 Yr(e){return{id:crypto.randomUUID(),cell_type:e,metadata:{},source:[],...e===`code`?{outputs:[],execution_count:null}:{}}}function Xr(e){return(e.output_type===`error`?e.traceback?.join(`
3
3
  `)??`${e.ename??`Error`}: ${e.evalue??``}`:z(e.text??e.data?.[`text/plain`])).replace(/\u001b\[[0-?]*[ -/]*[@-~]/g,``)}function Zr(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 Qr(e){return{...e,cells:e.cells.map(e=>e.cell_type===`code`?{...e,outputs:[],execution_count:null}:e)}}function $r(e){return e.cells.map((e,t)=>{let n=z(e.source).split(`
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 ei(e,t){let n=$r(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 ti(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 ni(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 ri({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=Yr(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:`${z(o.source)}\n${z(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,[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,Jr(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 ii(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=Wr(JSON.stringify({nbformat:4,nbformat_minor:5,metadata:{},cells:a.puddle_notebook_cells})).cells;if(e.preventDefault(),n.cells.length+o.length>2e3){ze.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 ai({controls:e}){return e.open?(0,L.jsx)(rt,{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 oi(e,t){return Math.min(t,Math.max(1,Math.floor(e)))}function si({notebook:e,focused:t,onReveal:n,onChange:r}){let[i,a]=(0,I.useState)(!1),[o,s]=(0,I.useState)(``),c=(0,I.useRef)(null),l=(0,I.useRef)([]),u=(0,I.useRef)(-1),d=(0,I.useRef)(!1),f=$e({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:z(n.source),output:!1},...i?[{text:(n.outputs??[]).map(Xr).join(`
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 ei(e,t){let n=$r(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 ti(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 ni(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 ri({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=Yr(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:`${z(o.source)}\n${z(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,Jr(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 ii(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=Wr(JSON.stringify({nbformat:4,nbformat_minor:5,metadata:{},cells:a.puddle_notebook_cells})).cells;if(e.preventDefault(),n.cells.length+o.length>2e3){ze.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 ai({controls:e}){return e.open?(0,L.jsx)(rt,{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 oi(e,t){return Math.min(t,Math.max(1,Math.floor(e)))}function si({notebook:e,focused:t,onReveal:n,onChange:r}){let[i,a]=(0,I.useState)(!1),[o,s]=(0,I.useState)(``),c=(0,I.useRef)(null),l=(0,I.useRef)([]),u=(0,I.useRef)(-1),d=(0,I.useRef)(!1),f=$e({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:z(n.source),output:!1},...i?[{text:(n.outputs??[]).map(Xr).join(`
5
5
  `),output:!0}]:[]];for(let i of e){let e=nt(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,I.useEffect)(()=>{f.refresh()},[i,f.refresh]);let p=t=>{let n=et(f.query,f.options);if(!n||!r)return;let i=e;e.cells.forEach((e,r)=>{let a=z(e.source),s=c.current;t?i=Gr(i,r,a.replace(n,o)):s&&!s.output&&s.id===e.id&&(i=Gr(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,I.useEffect)(()=>{d.current=c.current!==null,f.open&&f.refresh(),d.current=!1},[e,f.open,f.refresh]),(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(ai,{controls:f}),f.open&&(0,L.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,L.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-1`,children:[(0,L.jsx)(`input`,{type:`checkbox`,checked:i,onChange:e=>a(e.target.checked)}),`Include output`]}),r&&(0,L.jsxs)(L.Fragment,{children:[(0,L.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,L.jsx)(`button`,{type:`button`,className:`cursor-pointer hover:text-fg`,disabled:!f.query||!!c.current?.output,onClick:()=>p(!1),children:`Replace`}),(0,L.jsx)(`button`,{type:`button`,className:`cursor-pointer hover:text-fg`,disabled:!f.query,onClick:()=>p(!0),children:`Replace all`})]})]})]})}function ci(e){return r({queryKey:[`notebook-kernels`],queryFn:()=>F(`GET`,`/api/notebooks/kernels`),enabled:e,staleTime:3e4})}function li(e,t){return r({queryKey:[`notebook-kernel`,e],queryFn:()=>F(`POST`,`/api/notebooks/status`,{source:e}),enabled:t,refetchInterval:1500,retry:!1})}function ui(e){return F(`POST`,`/api/notebooks/kernel`,e)}function di(e,t){return r({queryKey:[`notebook-environments`,e],queryFn:()=>F(`POST`,`/api/notebooks/environments`,{source:e}),enabled:t,staleTime:3e4,retry:!1})}function fi(e,t,a,c){let l=n(),u=c&&!g()&&o(l.data?.protocol),d=(0,I.useRef)({notebook:t,onChange:a});d.current={notebook:t,onChange:a};let f=i(),[p,m]=(0,I.useState)(!1),h=(0,I.useRef)(!1),[_,v]=(0,I.useState)(null),y=(0,I.useRef)(!0);(0,I.useEffect)(()=>(y.current=!0,()=>{y.current=!1}),[]);let b=[`notebook-execution`,e],x=r({queryKey:b,queryFn:()=>F(`POST`,`/api/notebooks/execution`,{source:e}),enabled:u,retry:!1,refetchInterval:e=>e.state.data?.execution?.state===`running`?250:1500}),S=x.data?.execution;(0,I.useEffect)(()=>{if(!S||!d.current.notebook||!d.current.onChange)return;let e=ti(d.current.notebook,S);e!==d.current.notebook&&d.current.onChange(e)},[S]);let C=async t=>{let n=d.current.notebook;if(!u||!n||h.current||S?.state===`running`)return;let r=n.cells.flatMap((e,n)=>e.cell_type===`code`&&z(e.source).trim()&&(!t||t.includes(n))?[{id:e.id,source:z(e.source)}]:[]);if(r.length){h.current=!0,m(!0),v(null),d.current.onChange?.(n);try{let t=n.metadata.kernelspec,i=await F(`POST`,`/api/notebooks/execute`,{source:e,cells:r,...t?.name?{kernel:t.name}:{}});y.current&&f.setQueryData(b,i)}catch(e){y.current&&v(e instanceof Error?e.message:`Notebook execution failed`)}finally{h.current=!1,y.current&&(m(!1),f.invalidateQueries({queryKey:b}))}}},w=(0,I.useRef)(C);return w.current=C,(0,I.useEffect)(()=>u?we(e,()=>{w.current()}):void 0,[u,e.session,e.path,e.root]),{supported:u,intelligenceSupported:u&&s(l.data?.protocol),run:C,interrupt:async()=>{try{await ui({source:e,action:`interrupt`})}catch(e){y.current&&v(e instanceof Error?e.message:`Interrupt failed`)}finally{f.invalidateQueries({queryKey:b})}},execution:S,busy:p||S?.state===`running`,error:_??(x.error instanceof Error?x.error.message:S?.error)}}var pi=(0,I.createContext)(null);function mi({source:e,environment:t,current:n,kernels:r,pending:i,onAction:a}){let[o,s]=(0,I.useState)(!1),[c,l]=(0,I.useState)(``),u=(0,I.useId)(),d=di(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,L.jsxs)(bt,{open:o,onOpenChange:s,children:[(0,L.jsx)(yt,{asChild:!0,children:(0,L.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,L.jsx)(dn,{className:`size-3.5 shrink-0`}),(0,L.jsx)(`span`,{className:`truncate`,children:t?.label??n?.display_name??`Select environment`})]})}),(0,L.jsxs)(vt,{align:`end`,className:`w-96 max-w-[calc(100vw-2rem)] p-3`,children:[(0,L.jsx)(`p`,{className:`mb-2 text-xs text-fg-muted`,children:`Python environments on this host`}),(0,L.jsxs)(`div`,{className:`max-h-64 overflow-y-auto`,"aria-label":`Python environments`,children:[d.isLoading&&(0,L.jsx)(`p`,{role:`status`,className:`py-2 text-xs text-fg-muted`,children:`Looking for environments…`}),d.isError&&(0,L.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,L.jsx)(`p`,{className:`py-2 text-xs text-fg-muted`,children:`No Python environments found. Enter a path below.`}),f.map(n=>(0,L.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,L.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,L.jsx)(`p`,{className:`text-xs text-fg`,children:n.label}),(0,L.jsx)(`p`,{className:`break-all text-xs text-fg-muted`,children:n.python}),(n.error||!n.ipykernel||!n.nbconvert)&&(0,L.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,L.jsx)(Ye,{className:`size-3.5 shrink-0 text-accent`})]},n.python)),r.length>0&&(0,L.jsx)(`p`,{className:`mb-1 mt-3 text-xs text-fg-muted`,children:`Registered Jupyter kernels`}),r.map(r=>(0,L.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,L.jsx)(Ye,{className:`size-3.5`})]},r.name))]}),(0,L.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,L.jsx)(`label`,{htmlFor:u,className:`text-xs text-fg-secondary`,children:`Environment folder or Python executable`}),(0,L.jsx)(Ve,{id:u,value:c,onChange:e=>l(e.target.value),placeholder:`.venv, ~/miniforge3/envs/analysis, /path/to/python`,disabled:i}),(0,L.jsx)(`p`,{className:`text-xs text-fg-muted`,children:`Relative paths start beside this notebook. Switching starts fresh.`}),(0,L.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 hi=`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 gi({source:e,notebook:t,onSelect:r}){let a=(0,I.useRef)(r);a.current=r;let o=(0,I.useRef)(!0);(0,I.useEffect)(()=>(o.current=!0,()=>{o.current=!1}),[]);let s=n(),u=c(s.data?.protocol),d=l(s.data?.protocol),f=ci(u),p=li(e,u),m=i(),[h,g]=(0,I.useState)(null),_=h!==null,[v,y]=(0,I.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,ee=w&&!w.error?[!w.ipykernel&&`ipykernel`,!w.nbconvert&&`nbconvert`].filter(Boolean).join(` and `):``,T=p.data&&p.data.state!==`stopped`&&p.data.state!==`dead`,E=p.data?.state===`busy`||p.data?.state===`starting`,D=async t=>{g(t.action),y(null);try{let n=await ui(t);if(m.setQueryData([`notebook-kernel`,e],n),(t.action===`select-python`||t.action===`install-python`)&&(m.invalidateQueries({queryKey:[`notebook-environments`]}),o.current&&a.current({name:`python3`,display_name:`Python 3`,language:`python`})),t.action===`select`){let e=S.find(e=>e.name===t.kernel);e&&o.current&&a.current(e)}}catch(e){y(e instanceof Error?e.message:`Kernel operation failed`)}finally{g(null)}};return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[E&&(0,L.jsxs)(`button`,{type:`button`,className:hi,disabled:_,onClick:()=>void D({source:e,action:`interrupt`}),children:[(0,L.jsx)(je,{className:`size-3.5`}),`Interrupt`]}),(0,L.jsx)(`span`,{className:`text-xs text-fg-muted`,role:`status`,children:_?h===`install-python`?`Installing…`:`Updating…`:p.data?.state===`dead`?`Kernel exited`:E?`Busy`:T?`Idle`:``}),d?(0,L.jsx)(mi,{source:e,environment:w,current:C,kernels:S,pending:_,onAction:D}):(0,L.jsxs)(Ze,{value:C?.name??``,disabled:_||!f.data?.available||S.length===0,onValueChange:t=>void D({source:e,action:`select`,kernel:t}),children:[(0,L.jsxs)(qe,{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,L.jsx)(dn,{className:`size-3.5 shrink-0`}),(0,L.jsx)(Ke,{placeholder:x?`${x} (not installed)`:`Select Kernel`})]}),(0,L.jsx)(Je,{children:S.map(e=>(0,L.jsx)(Xe,{value:e.name,detail:e.language,children:(0,L.jsx)(`span`,{children:e.display_name})},e.name))})]}),(0,L.jsxs)(Ne,{children:[(0,L.jsx)(Ie,{asChild:!0,children:(0,L.jsx)(`button`,{type:`button`,className:hi,disabled:_,"aria-label":`Kernel actions`,children:(0,L.jsx)(Ee,{className:`size-3.5`})})}),(0,L.jsxs)(Te,{align:`end`,children:[(0,L.jsxs)(Se,{disabled:!C&&!w,onSelect:()=>void D({source:e,action:`restart`}),children:[(0,L.jsx)(at,{}),`Restart kernel`]}),(0,L.jsxs)(Se,{disabled:!T,onSelect:()=>void D({source:e,action:`shutdown`}),children:[(0,L.jsx)(Be,{}),`Shut down kernel`]})]})]})]}),ee&&(0,L.jsxs)(`div`,{className:`flex w-full flex-wrap items-center gap-2 px-2 text-xs text-fg-muted`,children:[(0,L.jsxs)(`span`,{className:`break-all`,children:[ee,` missing from `,w?.python,`.`]}),(0,L.jsxs)(`button`,{type:`button`,className:hi,disabled:_,onClick:()=>{w&&D({source:e,action:`install-python`,python:w.python})},children:[`Install `,ee]})]}),(v||p.data?.error||!d&&(f.data?.error||f.isError)||p.isError)&&(0,L.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,L.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 _i=`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 vi({notebook:e,source:t,onChange:r,onAdd:i,onRevealCell:a,onRun:o,onRunCopy:s,onRunSection:l,running:u=!1}){let[d,f]=(0,I.useState)(!1),p=n(),m=li(t,!!o&&c(p.data?.protocol)),h=u||m.data?.state===`busy`||m.data?.state===`starting`,g=m.data?.environment,_=g&&(!g.ipykernel||!g.nbconvert),v=$r(e),y=e.cells.some(e=>e.cell_type===`code`&&((e.outputs?.length??0)>0||e.execution_count!=null));return(0,L.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-1 bg-ground px-3 py-2`,role:`toolbar`,"aria-label":`Notebook`,children:[r&&(0,L.jsxs)(ft,{label:`Add notebook cells`,children:[(0,L.jsxs)(`button`,{type:`button`,className:_i,disabled:e.cells.length>=2e3,onClick:()=>i(`code`),"aria-label":`Add code cell`,children:[(0,L.jsx)(We,{className:`size-3.5`}),`Code`]}),(0,L.jsxs)(`button`,{type:`button`,className:_i,disabled:e.cells.length>=2e3,onClick:()=>i(`markdown`),"aria-label":`Add Markdown cell`,children:[(0,L.jsx)(We,{className:`size-3.5`}),`Markdown`]})]}),(0,L.jsxs)(ft,{label:`Notebook actions`,className:`flex-wrap !rounded-[var(--ui-radius)]`,children:[o&&(0,L.jsxs)(`button`,{type:`button`,className:_i,disabled:h||_,onClick:o,children:[(0,L.jsx)(Pe,{className:`size-3.5`}),h?`Running…`:`Run All`]}),r&&(0,L.jsxs)(`button`,{type:`button`,className:_i,disabled:!y,onClick:()=>r(Qr(e)),children:[(0,L.jsx)(Ue,{className:`size-3.5`}),`Clear All Outputs`]}),(0,L.jsxs)(bt,{open:d,onOpenChange:f,children:[(0,L.jsx)(yt,{asChild:!0,children:(0,L.jsxs)(`button`,{type:`button`,className:_i,disabled:v.length===0,children:[(0,L.jsx)(fn,{className:`size-3.5`}),`Outline`]})}),(0,L.jsx)(vt,{align:`start`,className:`max-h-72 w-72 overflow-y-auto p-1`,children:(0,L.jsx)(`nav`,{"aria-label":`Notebook outline`,className:`flex flex-col`,children:v.map(e=>(0,L.jsxs)(`div`,{className:`group/outline flex items-center`,style:{paddingLeft:`calc(var(--spacing) * ${Math.max(0,e.level-1)*3})`},children:[(0,L.jsxs)(`button`,{type:`button`,className:`${_i} min-w-0 flex-1 text-left`,onClick:()=>{a(e.index),f(!1)},children:[(0,L.jsx)(`span`,{className:`w-5 shrink-0 text-fg-muted`,children:e.index+1}),(0,L.jsx)(`span`,{className:`truncate`,children:e.label})]}),!!e.level&&l&&(0,L.jsx)(`button`,{type:`button`,disabled:h,title:`Run Section`,"aria-label":`Run section ${e.label}`,className:`${_i} opacity-0 group-hover/outline:opacity-100 focus:opacity-100 pointer-coarse:opacity-100`,onClick:()=>{l(e.index),f(!1)},children:(0,L.jsx)(Pe,{className:`size-3.5`})})]},e.index))})})]}),r&&(0,L.jsxs)(Ne,{children:[(0,L.jsx)(Ie,{asChild:!0,children:(0,L.jsx)(`button`,{type:`button`,className:_i,"aria-label":`More notebook actions`,children:(0,L.jsx)(Ee,{className:`size-3.5`})})}),(0,L.jsxs)(Te,{align:`start`,children:[s&&(0,L.jsx)(Se,{disabled:h,onSelect:s,children:`Run to Executed Copy`}),(0,L.jsxs)(Se,{disabled:e.cells.length>=2e3,onSelect:()=>i(`raw`),children:[(0,L.jsx)(We,{}),`Add raw cell`]})]})]})]}),r&&o&&(0,L.jsx)(gi,{source:t,notebook:e,onSelect:t=>r({...e,metadata:{...e.metadata,kernelspec:t}})},JSON.stringify(t))]})}function yi({code:e,onRun:t,busy:n,index:r,count:i,canMerge:a,onOperation:o}){let s=(e,t,n,r=!1)=>(0,L.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,L.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,L.jsxs)(L.Fragment,{children:[s(`Run Cell`,(0,L.jsx)(Pe,{className:`size-3.5`}),()=>t(`cell`),n),s(`Run Above`,(0,L.jsx)(ln,{className:`size-3.5`}),()=>t(`above`),n||r===0),s(`Run Cell and Below`,(0,L.jsx)(cn,{className:`size-3.5`}),()=>t(`below`),n)]}),s(`Insert cell below`,(0,L.jsx)(We,{className:`size-3.5`}),()=>o(`insert`),i>=2e3),s(`Duplicate cell`,(0,L.jsx)(it,{className:`size-3.5`}),()=>o(`duplicate`),i>=2e3),s(`Merge with next cell`,(0,L.jsx)(un,{className:`size-3.5`}),()=>o(`merge`),!a),s(`Move cell up`,(0,L.jsx)(Me,{className:`size-3.5`}),()=>o(`up`),r===0),s(`Move cell down`,(0,L.jsx)(Fe,{className:`size-3.5`}),()=>o(`down`),r===i-1),s(`Delete cell`,(0,L.jsx)(Ue,{className:`size-3.5`}),()=>o(`delete`))]})}function bi(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 F(`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`?[]:[te.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 j(l.lineNumber,l.column,u.lineNumber,u.column);return{suggestions:s.matches.map(e=>({label:e,insertText:e,kind:te.CompletionItemKind.Text,range:d}))}}}),te.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 xi({value:e,language:t,label:n,focus:r,onChange:i,onExecute:a,onEscape:o,onSplit:s,onSave:c,match:l}){let u=C(),d=Math.round(u.editorFontSize*1.5),f=(0,I.useContext)(pi),[p,m]=(0,I.useState)(null);(0,I.useEffect)(()=>{if(!p||!f?.intelligence)return;let e=bi(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,I.useRef)(null),g=(0,I.useRef)(null),_=(0,I.useRef)(null),v=(0,I.useRef)(!1),y=(0,I.useRef)(null),b=(0,I.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,I.useRef)(r);x.current=r;let S=(0,I.useRef)(l);S.current=l;let w=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 j(r.lineNumber,r.column,i.lineNumber,i.column)),e.revealPositionInCenter(r)};(0,I.useEffect)(()=>{g.current&&w(g.current)},[l]);let[ee,T]=(0,I.useState)(!1),[E,D]=(0,I.useState)(!1),[O,k]=(0,I.useState)(Math.max(64,e.split(`
6
- `).length*d+24));return(0,I.useEffect)(()=>{let e=new IntersectionObserver(([e])=>T(!!e?.isIntersecting),{rootMargin:`600px`});return h.current&&e.observe(h.current),()=>e.disconnect()},[]),(0,I.useEffect)(()=>()=>{_.current?.dispose()},[]),(0,I.useEffect)(()=>{let n=_.current;n&&n.getValue()!==e&&(v.current=!0,n.pushEditOperations([],[{range:n.getFullModelRange(),text:e}],()=>null),v.current=!1),n&&N.setModelLanguage(n,t)},[e,t]),(0,I.useEffect)(()=>{r&&g.current?.focus()},[r]),(0,L.jsxs)(`div`,{ref:h,style:{height:O},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,L.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}),(ee||r||E)&&(0,L.jsx)(Ot,{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()),ir(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}),k(n),t=!1},r=e.onDidContentSizeChange(n),i=new ResizeObserver(n);i.observe(h.current);let a=e.onDidFocusEditorWidget(()=>D(!0)),o=e.onDidBlurEditorWidget(()=>D(!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(M.CtrlCmd|P.Enter,()=>b.current.onExecute(`stay`)),e.addCommand(M.Shift|P.Enter,()=>b.current.onExecute(`next`)),e.addCommand(M.Alt|P.Enter,()=>b.current.onExecute(`insert`)),e.addCommand(P.Escape,()=>b.current.onEscape(),`!suggestWidgetVisible && !findWidgetVisible`),e.addCommand(M.CtrlCmd|M.Shift|P.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(),w(e),x.current&&e.focus()},beforeMount:()=>{_.current&&N.setModelLanguage(_.current,t)},options:{ariaLabel:n,automaticLayout:!1,fontFamily:getComputedStyle(document.documentElement).getPropertyValue(`--font-mono`).trim(),fontSize:u.editorFontSize,lineHeight:d,...Nn(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 Si({language:e,onChange:t}){let[n,r]=(0,I.useState)(!1),i=[`markdown`,`raw`,...te.getLanguages().map(e=>e.id).filter(e=>e!==`markdown`).sort()];return(0,L.jsxs)(bt,{open:n,onOpenChange:r,children:[(0,L.jsx)(yt,{asChild:!0,children:(0,L.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,L.jsx)(Qe,{className:`size-3`})]})}),(0,L.jsxs)(vt,{align:`start`,className:`w-56 p-0`,children:[(0,L.jsxs)(_t,{children:[(0,L.jsx)(pt,{placeholder:`Find a language…`}),(0,L.jsxs)(gt,{children:[(0,L.jsx)(ht,{children:`No matching languages`}),i.map(e=>(0,L.jsx)(mt,{onSelect:()=>{t(e),r(!1)},children:e},e))]})]}),(0,L.jsx)(`p`,{className:`px-3 py-2 text-xs text-fg-muted`,children:`Code languages set highlighting. Execution uses the notebook kernel.`})]})]})}async function Ci(e,t,n){let r=`path=${encodeURIComponent(t)}${se(n)}`,i=g();return i?Ti(i,async()=>{if(g()!==i)throw Error(`Preview host changed`);let t=p.parse(await F(`GET`,`/api/worktrees/${e}/preview-asset?${r}`));return new Blob([Uint8Array.from(atob(t.data),e=>e.charCodeAt(0))],{type:t.mime})}):(await ne(`GET`,`/api/worktrees/${e}/media?${r}`)).blob()}var wi=new WeakMap;async function Ti(e,t){let n=wi.get(e);if(n||(n={active:0,waiting:[]},wi.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 Ei(e,t,n,r,i){(0,I.useEffect)(()=>{let t=e.current;if(!t)return;let a=!1,o=[],s=async e=>{try{let t=await Ci(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=ut(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=dt(e.getAttribute(`srcset`)??``),n=t.map(({ref:e})=>ut(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`,st(n))}))}return()=>{a=!0;for(let e of o)URL.revokeObjectURL(e)}},[t,e,n,r,i])}function Di(e,t){let n=URL.createObjectURL(e),r=document.createElement(`a`);try{r.href=n,r.download=t,document.body.appendChild(r),r.click()}finally{r.remove(),setTimeout(()=>URL.revokeObjectURL(n),6e4)}}var Oi=(0,I.lazy)(()=>E(()=>import(`./NotebookWidget-C93HDt3h.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12])));function ki(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=z(r[e]).replace(/\s/g,``);if(t&&/^[A-Za-z0-9+/]*={0,2}$/.test(t))return`data:${e};base64,${t}`}}catch{}return e})}function Ai({text:e,markdown:t=!1,attachments:n}){let r=(0,I.useContext)(pi),i=(0,I.useRef)(null),a=(0,I.useId)().replace(/[^a-zA-Z0-9_-]/g,``),o=(0,I.useSyncExternalStore)(D,O,O),s=(0,I.useMemo)(()=>k.sanitize(t?Kt(ki(e,n),a):e,{FORBID_TAGS:[`style`,`iframe`,`form`,`input`,`button`],...t?{}:{FORBID_ATTR:[`style`]}}),[e,t,n,a]),c=(0,I.useMemo)(()=>({__html:s}),[s,o]);return Ei(i,s,r?.session??``,r?.path??``,r?.root),(0,I.useEffect)(()=>{let e=new AbortController;return i.current&&t&&sn(i.current,o,e.signal),()=>e.abort()},[s,o,t]),(0,L.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?ut(r.path,n):null;a&&(e.preventDefault(),(e.metaKey||e.ctrlKey)&&r?.onOpenFile?.(a))}})}var ji=`cursor-pointer rounded-sm p-1 text-fg-muted hover:bg-surface hover:text-fg`;function Mi({output:e}){let t=null;for(let n of[`image/png`,`image/jpeg`,`image/gif`,`image/webp`]){let r=z(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=z(e.data?.[`image/svg+xml`]),r=n?k.sanitize(n,{USE_PROFILES:{svg:!0,svgFilters:!0},FORBID_TAGS:[`style`,`foreignObject`,`image`,`use`],FORBID_ATTR:[`style`,`href`,`xlink:href`]}):``,i=z(e.data?.[`text/html`]),a=z(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=Xr(e)||(o===void 0?``:JSON.stringify(o,null,2))||`This output format cannot be displayed.`;return(0,L.jsxs)(`div`,{className:`group/output relative`,children:[(0,L.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,L.jsx)(`button`,{type:`button`,title:`Copy output`,"aria-label":`Copy output`,className:ji,onClick:()=>{navigator.clipboard.writeText(l).catch(()=>ze.error(`Could not copy output`))},children:(0,L.jsx)(it,{className:`size-3.5`})}),(t||r)&&(0,L.jsx)(`button`,{type:`button`,title:`Save image`,"aria-label":`Save image`,className:ji,onClick:()=>Di(t?.blob??new Blob([r],{type:`image/svg+xml`}),`notebook-output.${t?.extension??`svg`}`),children:(0,L.jsx)(Ce,{className:`size-3.5`})})]}),c?(0,L.jsx)(I.Suspense,{fallback:(0,L.jsx)(`p`,{className:`text-xs text-fg-muted`,children:`Loading widget…`}),children:(0,L.jsx)(Oi,{modelId:c,fallback:Xr(e)})}):t?(0,L.jsx)(`img`,{src:t.src,alt:`Notebook output`,className:`max-w-full`}):r?(0,L.jsx)(`div`,{dangerouslySetInnerHTML:{__html:r}}):i?(0,L.jsx)(Ai,{text:i}):a?(0,L.jsx)(Ai,{text:a,markdown:!0}):(0,L.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 Ni({source:e,execution:t,onInterrupt:n}){let r=(0,I.useRef)(null),i=(0,I.useRef)(!1),[a,o]=(0,I.useState)(``),[s,c]=(0,I.useState)(!1),[l,u]=(0,I.useState)(null),d=t.input;return(0,I.useEffect)(()=>{r.current?.focus({preventScroll:!0}),r.current?.scrollIntoView({block:`nearest`})},[]),d?(0,L.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),F(`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,L.jsxs)(`label`,{className:`flex min-w-0 flex-wrap items-baseline`,children:[(0,L.jsx)(`span`,{className:`whitespace-pre-wrap break-words`,children:d.prompt}),(0,L.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,L.jsx)(`p`,{role:`alert`,className:`mt-1 text-xs text-danger`,children:l})]}):null}var Pi=`cursor-pointer rounded-sm p-1 text-fg-muted transition-colors hover:bg-elevated hover:text-fg disabled:cursor-default disabled:opacity-40`;function Fi({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,I.useRef)(null),[w,ee]=(0,I.useState)(!1),T=y?v?.input:void 0;(0,I.useEffect)(()=>{(b?.output||T)&&ee(!1)},[b,T]);let E=w&&!T,D=e.cell_type===`code`,O=z(e.source),k=_?.state===`running`||_?.state===`queued`,A=qr(e,t),j=(e,t,n,r=!1)=>(0,L.jsx)(`button`,{type:`button`,className:Pi,title:e,"aria-label":e,onClick:n,disabled:r,children:t});return(0,L.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)&&D&&!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,L.jsx)(`div`,{className:`absolute -left-10 top-9 w-9 text-center font-mono text-xs text-fg-muted`,children:(0,L.jsxs)(`button`,{type:`button`,className:`${Pi} group/run relative w-full`,disabled:!o||D&&(!f||!k&&!O.trim()),title:D?k?`Interrupt execution`:`Run Cell (⌘/Ctrl+Enter)`:i?`Show rendered cell`:`Edit cell source`,"aria-label":D?k?`Interrupt execution`:`Run Cell`:i?`Show rendered cell`:`Edit cell source`,onClick:()=>{D?k?p?.():f?.(`cell`):c(!i)},children:[(0,L.jsx)(`span`,{className:D&&f?`group-hover/run:invisible group-focus-visible/run:invisible`:``,children:D?`[${k?`*`:e.execution_count??` `}]`:i?`[›]`:`[ ]`}),D&&f&&(k?(0,L.jsx)(je,{className:`absolute inset-0 m-auto hidden size-3.5 group-hover/run:block group-focus-visible/run:block`}):(0,L.jsx)(Pe,{className:`absolute inset-0 m-auto hidden size-3.5 group-hover/run:block group-focus-visible/run:block`}))]})}),(0,L.jsxs)(`div`,{className:`mb-2 flex min-h-7 items-center gap-2 text-xs text-fg-muted`,children:[x&&j(S?`Expand section`:`Fold section`,S?(0,L.jsx)(He,{className:`size-3`}):(0,L.jsx)(Qe,{className:`size-3`}),x),o?(0,L.jsx)(Si,{language:e.cell_type===`raw`?`raw`:A,onChange:u}):(0,L.jsx)(`span`,{className:`font-mono`,children:e.cell_type===`raw`?`raw`:A}),_&&(0,L.jsxs)(`span`,{role:`status`,children:[_.state,_.elapsed_ms===void 0?``:` · ${(_.elapsed_ms/1e3).toFixed(1)}s`]}),_&&_.source!==O&&(0,L.jsx)(`span`,{title:`The source changed after this execution`,children:`Source changed`}),o&&(0,L.jsx)(yi,{code:D,onRun:f,busy:k,index:n,count:t.cells.length,canMerge:e.cell_type===t.cells[n+1]?.cell_type,onOperation:m})]}),(0,L.jsx)(`div`,{className:D||i||e.cell_type===`raw`?`rounded-[var(--ui-radius)] p-3 ${a?`bg-elevated`:`bg-surface`}`:void 0,children:o&&(D||i)?(0,L.jsx)(xi,{value:O,match:b&&!b.output?b:void 0,language:A,label:`Cell ${n+1} source`,focus:r&&i&&!b,onChange:e=>{e!==O&&l(e)},onExecute:d,onEscape:()=>{c(!1),C.current?.focus()},onSave:g,onSplit:h}):e.cell_type===`markdown`?(0,L.jsx)(`div`,{onDoubleClick:()=>{o&&c(!0)},className:o?`cursor-text`:``,children:(0,L.jsx)(Ai,{text:O,markdown:!0,attachments:e.attachments})}):(0,L.jsx)(`pre`,{className:`overflow-x-auto whitespace-pre-wrap font-mono text-sm`,onDoubleClick:()=>{o&&c(!0)},children:O})}),(!!e.outputs?.length||T)&&(0,L.jsxs)(`div`,{className:`mt-2`,role:`group`,"aria-label":`Cell ${n+1} output`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-fg-muted`,children:[j(E?`Expand output`:`Collapse output`,E?(0,L.jsx)(He,{className:`size-3`}):(0,L.jsx)(Qe,{className:`size-3`}),()=>ee(!w),!!T),(0,L.jsx)(`span`,{children:`Output`}),o&&j(`Clear cell output`,(0,L.jsx)(Ue,{className:`size-3`}),()=>m(`clear`))]}),!E&&(0,L.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,L.jsx)(`div`,{className:`mt-2 first:mt-0`,children:(0,L.jsx)(Mi,{output:e})},t)),T&&v&&y&&(0,L.jsx)(Ni,{source:y,execution:v,onInterrupt:p},`${v.id}:${T.id}`)]})]})]})}var Ii=new Rt;function Li(e,t,n){let r=Ii.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);Ii.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 Ri({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,I.useMemo)(()=>{try{return{notebook:Kr(Wr(e)),error:null}}catch(e){return{notebook:null,error:e instanceof Error?e.message:`Invalid notebook`}}},[e]),[f,p]=(0,I.useState)([]),[m,h]=(0,I.useState)(null),g=(0,I.useRef)(!0),[_,v]=(0,I.useState)(null),[y,b]=(0,I.useState)(null),C=(0,I.useRef)(null),[w,ee]=(0,I.useState)([]),T=(0,I.useRef)(null),E=(0,I.useRef)(null),D=(0,I.useRef)(null),O=Lt(`notebook`,[t,r,n]),k=d.notebook!==null;(0,I.useLayoutEffect)(()=>{if(!(!T.current||!E.current||!k))return Li(T.current,E.current,O)},[O,k]),(0,I.useLayoutEffect)(()=>{if(!D.current)return;let e=E.current?.querySelector(`[data-cell-id="${CSS.escape(D.current)}"]`);e&&(e.scrollIntoView({block:`nearest`}),g.current&&e.focus({preventScroll:!0}),g.current=!0,D.current=null)});let A=e=>i?.(`${JSON.stringify(e,null,1)}\n`),j=d.notebook,te=(0,I.useMemo)(()=>({session:t,path:n,...r===void 0?{}:{root:r}}),[t,n,r]),M=fi(te,j,i?A:void 0,!!a),N=x(te,j,i?A:void 0,!!a),P=M.execution?.input?M.execution.cells.find(e=>e.state===`running`)?.id:void 0;if((0,I.useLayoutEffect)(()=>{if(!j||!P||!f.length)return;let e=j.cells.findIndex(e=>e.id===P),t=f.filter(t=>{let n=j.cells.findIndex(e=>e.id===t);return n<0||!ei(j,n).includes(e)});t.length!==f.length&&p(t)},[j,P,f]),!j)return(0,L.jsx)(`p`,{className:`p-6 text-sm text-danger`,role:`alert`,children:d.error});let F=(e,t=!1)=>{let n=C.current??_??e,r=j.cells.findIndex(e=>e.id===n),i=j.cells.findIndex(t=>t.id===e);ee(t?j.cells.slice(Math.min(r,i),Math.max(r,i)+1).map(e=>e.id):[e]),t||(C.current=e),v(e)},ne=(e,t=!1,n=!1)=>{F(e,n),b(t?e:null),D.current=e},re=$r(j),ie=new Set(j.cells.flatMap((e,t)=>f.includes(e.id)?ei(j,t).slice(1):[])),{add:ae,replace:oe,execute:se,operation:ce,keyDown:le}=ri({notebook:j,active:_,selected:w,update:A,choose:ne,setEditing:b,run:M.run,onUndo:s,onRedo:c});return(0,L.jsx)(S.Provider,{value:N,children:(0,L.jsx)(pi.Provider,{value:{...te,onOpenFile:l,intelligence:M.intelligenceSupported},children:(0,L.jsxs)(`div`,{className:`relative flex h-full min-h-0 flex-col bg-ground`,onKeyDown:i?le:void 0,onCopy:e=>{i&&ii(e,`copy`,j,w,A)},onCut:e=>{i&&ii(e,`cut`,j,w,A)},onPaste:e=>{i&&ii(e,`paste`,j,w,A)},children:[(0,L.jsx)(si,{notebook:j,focused:u,onChange:i?A:void 0,onReveal:e=>{h(e),e&&(p([]),v(e.id),e.output||b(e.id),D.current=e.id,g.current=!1)}}),(0,L.jsx)(vi,{notebook:j,source:{session:t,path:n,...r===void 0?{}:{root:r}},onChange:i?A:void 0,onAdd:ae,onRun:M.supported?()=>{M.run()}:a,onRunCopy:M.supported?a:void 0,running:o||M.busy,onRevealCell:e=>{p([]),ne(j.cells[e].id)},onRunSection:M.supported?e=>{M.run(ei(j,e))}:void 0}),(0,L.jsx)(`div`,{ref:T,className:`min-h-0 flex-1 overflow-auto bg-ground text-fg`,children:(0,L.jsxs)(`div`,{ref:E,className:`mx-auto flex max-w-4xl flex-col gap-7 py-6 pr-6 pl-14`,children:[(0,L.jsxs)(`p`,{className:`text-xs text-fg-muted`,children:[j.cells.length,` cells`]}),N.saveWarning&&(0,L.jsx)(`p`,{role:`status`,className:`text-xs text-fg-muted`,children:N.saveWarning}),M.error&&(0,L.jsx)(`p`,{role:`alert`,className:`text-xs text-danger`,children:M.error}),j.cells.map((e,a)=>ie.has(a)?null:(0,L.jsx)(Fi,{cell:e,match:m&&m.id===e.id?m:void 0,sectionCollapsed:f.includes(e.id),onToggleSection:re[a]?.level?()=>p(t=>t.includes(e.id)?t.filter(t=>t!==e.id):[...t,e.id]):void 0,notebook:j,index:a,active:_===e.id,editing:y===e.id,selected:w.length>1&&w.includes(e.id),editable:!!i,onSelect:t=>F(e.id,t),onEdit:t=>{v(e.id),b(t?e.id:null)},onSource:e=>A(Gr(j,a,e)),onLanguage:t=>oe(a,Jr(e,t)),onInterrupt:()=>{M.interrupt()},execution:M.execution?.cells.find(t=>t.id===e.id)??ni(e),inputExecution:P===e.id?M.execution??void 0:void 0,inputSource:te,onRun:M.supported?e=>{M.run(j.cells.flatMap((t,n)=>(e===`cell`?n===a:e===`above`?n<a:n>=a)?[n]:[]))}:void 0,onExecute:e=>se(a,e),onOperation:e=>ce(a,e),onSave:()=>{Oe(De(t,n,r))},onSplit:t=>{if(j.cells.length>=2e3)return;let n=z(e.source),r={...Yr(e.cell_type),source:n.slice(t)},i=[...j.cells];i.splice(a,1,{...e,source:n.slice(0,t)},r),A({...j,cells:i}),ne(r.id,!0)}},e.id)),i&&(0,L.jsx)(`div`,{className:`flex gap-3`,children:[`code`,`markdown`,`raw`].map(e=>(0,L.jsxs)(`button`,{disabled:j.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:()=>ae(e,j.cells.length),children:[(0,L.jsx)(We,{className:`size-3.5`}),e===`code`?`Code`:e===`markdown`?`Markdown`:`Raw`,` cell`]},e))})]})})]})})})}var zi=0;function Bi(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 Vi(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 Hi=class{root;matchName=`puddle-find-${++zi}-match`;activeName=`puddle-find-${zi}-active`;style;signature=``;ranges=[];index=-1;limited=!1;constructor(e){this.root=e,this.style=document.createElement(`style`),this.style.textContent=`
6
+ `).length*d+24));return(0,I.useEffect)(()=>{let e=new IntersectionObserver(([e])=>T(!!e?.isIntersecting),{rootMargin:`600px`});return h.current&&e.observe(h.current),()=>e.disconnect()},[]),(0,I.useEffect)(()=>()=>{_.current?.dispose()},[]),(0,I.useEffect)(()=>{let n=_.current;n&&n.getValue()!==e&&(v.current=!0,n.pushEditOperations([],[{range:n.getFullModelRange(),text:e}],()=>null),v.current=!1),n&&N.setModelLanguage(n,t)},[e,t]),(0,I.useEffect)(()=>{r&&g.current?.focus()},[r]),(0,L.jsxs)(`div`,{ref:h,style:{height:O},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,L.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}),(ee||r||E)&&(0,L.jsx)(Ot,{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()),ir(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}),k(n),t=!1},r=e.onDidContentSizeChange(n),i=new ResizeObserver(n);i.observe(h.current);let a=e.onDidFocusEditorWidget(()=>D(!0)),o=e.onDidBlurEditorWidget(()=>D(!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(M.CtrlCmd|P.Enter,()=>b.current.onExecute(`stay`)),e.addCommand(M.Shift|P.Enter,()=>b.current.onExecute(`next`)),e.addCommand(M.Alt|P.Enter,()=>b.current.onExecute(`insert`)),e.addCommand(P.Escape,()=>b.current.onEscape(),`!suggestWidgetVisible && !findWidgetVisible`),e.addCommand(M.CtrlCmd|M.Shift|P.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(),w(e),x.current&&e.focus()},beforeMount:()=>{_.current&&N.setModelLanguage(_.current,t)},options:{ariaLabel:n,automaticLayout:!1,fontFamily:getComputedStyle(document.documentElement).getPropertyValue(`--font-mono`).trim(),fontSize:u.editorFontSize,lineHeight:d,...Nn(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 Si({language:e,onChange:t}){let[n,r]=(0,I.useState)(!1),i=[`markdown`,`raw`,...te.getLanguages().map(e=>e.id).filter(e=>e!==`markdown`).sort()];return(0,L.jsxs)(bt,{open:n,onOpenChange:r,children:[(0,L.jsx)(yt,{asChild:!0,children:(0,L.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,L.jsx)(Qe,{className:`size-3`})]})}),(0,L.jsxs)(vt,{align:`start`,className:`w-56 p-0`,children:[(0,L.jsxs)(_t,{children:[(0,L.jsx)(pt,{placeholder:`Find a language…`}),(0,L.jsxs)(gt,{children:[(0,L.jsx)(ht,{children:`No matching languages`}),i.map(e=>(0,L.jsx)(mt,{onSelect:()=>{t(e),r(!1)},children:e},e))]})]}),(0,L.jsx)(`p`,{className:`px-3 py-2 text-xs text-fg-muted`,children:`Code languages set highlighting. Execution uses the notebook kernel.`})]})]})}async function Ci(e,t,n){let r=`path=${encodeURIComponent(t)}${se(n)}`,i=g();return i?Ti(i,async()=>{if(g()!==i)throw Error(`Preview host changed`);let t=p.parse(await F(`GET`,`/api/worktrees/${e}/preview-asset?${r}`));return new Blob([Uint8Array.from(atob(t.data),e=>e.charCodeAt(0))],{type:t.mime})}):(await ne(`GET`,`/api/worktrees/${e}/media?${r}`)).blob()}var wi=new WeakMap;async function Ti(e,t){let n=wi.get(e);if(n||(n={active:0,waiting:[]},wi.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 Ei(e,t,n,r,i){(0,I.useEffect)(()=>{let t=e.current;if(!t)return;let a=!1,o=[],s=async e=>{try{let t=await Ci(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=ut(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=dt(e.getAttribute(`srcset`)??``),n=t.map(({ref:e})=>ut(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`,st(n))}))}return()=>{a=!0;for(let e of o)URL.revokeObjectURL(e)}},[t,e,n,r,i])}function Di(e,t){let n=URL.createObjectURL(e),r=document.createElement(`a`);try{r.href=n,r.download=t,document.body.appendChild(r),r.click()}finally{r.remove(),setTimeout(()=>URL.revokeObjectURL(n),6e4)}}var Oi=(0,I.lazy)(()=>E(()=>import(`./NotebookWidget-kFo_mQZh.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12])));function ki(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=z(r[e]).replace(/\s/g,``);if(t&&/^[A-Za-z0-9+/]*={0,2}$/.test(t))return`data:${e};base64,${t}`}}catch{}return e})}function Ai({text:e,markdown:t=!1,attachments:n}){let r=(0,I.useContext)(pi),i=(0,I.useRef)(null),a=(0,I.useId)().replace(/[^a-zA-Z0-9_-]/g,``),o=(0,I.useSyncExternalStore)(D,O,O),s=(0,I.useMemo)(()=>k.sanitize(t?Kt(ki(e,n),a):e,{FORBID_TAGS:[`style`,`iframe`,`form`,`input`,`button`],...t?{}:{FORBID_ATTR:[`style`]}}),[e,t,n,a]),c=(0,I.useMemo)(()=>({__html:s}),[s,o]);return Ei(i,s,r?.session??``,r?.path??``,r?.root),(0,I.useEffect)(()=>{let e=new AbortController;return i.current&&t&&sn(i.current,o,e.signal),()=>e.abort()},[s,o,t]),(0,L.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?ut(r.path,n):null;a&&(e.preventDefault(),(e.metaKey||e.ctrlKey)&&r?.onOpenFile?.(a))}})}var ji=`cursor-pointer rounded-sm p-1 text-fg-muted hover:bg-surface hover:text-fg`;function Mi({output:e}){let t=null;for(let n of[`image/png`,`image/jpeg`,`image/gif`,`image/webp`]){let r=z(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=z(e.data?.[`image/svg+xml`]),r=n?k.sanitize(n,{USE_PROFILES:{svg:!0,svgFilters:!0},FORBID_TAGS:[`style`,`foreignObject`,`image`,`use`],FORBID_ATTR:[`style`,`href`,`xlink:href`]}):``,i=z(e.data?.[`text/html`]),a=z(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=Xr(e)||(o===void 0?``:JSON.stringify(o,null,2))||`This output format cannot be displayed.`;return(0,L.jsxs)(`div`,{className:`group/output relative`,children:[(0,L.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,L.jsx)(`button`,{type:`button`,title:`Copy output`,"aria-label":`Copy output`,className:ji,onClick:()=>{navigator.clipboard.writeText(l).catch(()=>ze.error(`Could not copy output`))},children:(0,L.jsx)(it,{className:`size-3.5`})}),(t||r)&&(0,L.jsx)(`button`,{type:`button`,title:`Save image`,"aria-label":`Save image`,className:ji,onClick:()=>Di(t?.blob??new Blob([r],{type:`image/svg+xml`}),`notebook-output.${t?.extension??`svg`}`),children:(0,L.jsx)(Ce,{className:`size-3.5`})})]}),c?(0,L.jsx)(I.Suspense,{fallback:(0,L.jsx)(`p`,{className:`text-xs text-fg-muted`,children:`Loading widget…`}),children:(0,L.jsx)(Oi,{modelId:c,fallback:Xr(e)})}):t?(0,L.jsx)(`img`,{src:t.src,alt:`Notebook output`,className:`max-w-full`}):r?(0,L.jsx)(`div`,{dangerouslySetInnerHTML:{__html:r}}):i?(0,L.jsx)(Ai,{text:i}):a?(0,L.jsx)(Ai,{text:a,markdown:!0}):(0,L.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 Ni({source:e,execution:t,onInterrupt:n}){let r=(0,I.useRef)(null),i=(0,I.useRef)(!1),[a,o]=(0,I.useState)(``),[s,c]=(0,I.useState)(!1),[l,u]=(0,I.useState)(null),d=t.input;return(0,I.useEffect)(()=>{r.current?.focus({preventScroll:!0}),r.current?.scrollIntoView({block:`nearest`})},[]),d?(0,L.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),F(`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,L.jsxs)(`label`,{className:`flex min-w-0 flex-wrap items-baseline`,children:[(0,L.jsx)(`span`,{className:`whitespace-pre-wrap break-words`,children:d.prompt}),(0,L.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,L.jsx)(`p`,{role:`alert`,className:`mt-1 text-xs text-danger`,children:l})]}):null}var Pi=`cursor-pointer rounded-sm p-1 text-fg-muted transition-colors hover:bg-elevated hover:text-fg disabled:cursor-default disabled:opacity-40`;function Fi({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,I.useRef)(null),[w,ee]=(0,I.useState)(!1),T=y?v?.input:void 0;(0,I.useEffect)(()=>{(b?.output||T)&&ee(!1)},[b,T]);let E=w&&!T,D=e.cell_type===`code`,O=z(e.source),k=_?.state===`running`||_?.state===`queued`,A=qr(e,t),j=(e,t,n,r=!1)=>(0,L.jsx)(`button`,{type:`button`,className:Pi,title:e,"aria-label":e,onClick:n,disabled:r,children:t});return(0,L.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)&&D&&!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,L.jsx)(`div`,{className:`absolute -left-10 top-9 w-9 text-center font-mono text-xs text-fg-muted`,children:(0,L.jsxs)(`button`,{type:`button`,className:`${Pi} group/run relative w-full`,disabled:!o||D&&(!f||!k&&!O.trim()),title:D?k?`Interrupt execution`:`Run Cell (⌘/Ctrl+Enter)`:i?`Show rendered cell`:`Edit cell source`,"aria-label":D?k?`Interrupt execution`:`Run Cell`:i?`Show rendered cell`:`Edit cell source`,onClick:()=>{D?k?p?.():f?.(`cell`):c(!i)},children:[(0,L.jsx)(`span`,{className:D&&f?`group-hover/run:invisible group-focus-visible/run:invisible`:``,children:D?`[${k?`*`:e.execution_count??` `}]`:i?`[›]`:`[ ]`}),D&&f&&(k?(0,L.jsx)(je,{className:`absolute inset-0 m-auto hidden size-3.5 group-hover/run:block group-focus-visible/run:block`}):(0,L.jsx)(Pe,{className:`absolute inset-0 m-auto hidden size-3.5 group-hover/run:block group-focus-visible/run:block`}))]})}),(0,L.jsxs)(`div`,{className:`mb-2 flex min-h-7 items-center gap-2 text-xs text-fg-muted`,children:[x&&j(S?`Expand section`:`Fold section`,S?(0,L.jsx)(He,{className:`size-3`}):(0,L.jsx)(Qe,{className:`size-3`}),x),o?(0,L.jsx)(Si,{language:e.cell_type===`raw`?`raw`:A,onChange:u}):(0,L.jsx)(`span`,{className:`font-mono`,children:e.cell_type===`raw`?`raw`:A}),_&&(0,L.jsxs)(`span`,{role:`status`,children:[_.state,_.elapsed_ms===void 0?``:` · ${(_.elapsed_ms/1e3).toFixed(1)}s`]}),_&&_.source!==O&&(0,L.jsx)(`span`,{title:`The source changed after this execution`,children:`Source changed`}),o&&(0,L.jsx)(yi,{code:D,onRun:f,busy:k,index:n,count:t.cells.length,canMerge:e.cell_type===t.cells[n+1]?.cell_type,onOperation:m})]}),(0,L.jsx)(`div`,{className:D||i||e.cell_type===`raw`?`rounded-[var(--ui-radius)] p-3 ${a?`bg-elevated`:`bg-surface`}`:void 0,children:o&&(D||i)?(0,L.jsx)(xi,{value:O,match:b&&!b.output?b:void 0,language:A,label:`Cell ${n+1} source`,focus:r&&i&&!b,onChange:e=>{e!==O&&l(e)},onExecute:d,onEscape:()=>{c(!1),C.current?.focus()},onSave:g,onSplit:h}):e.cell_type===`markdown`?(0,L.jsx)(`div`,{onDoubleClick:()=>{o&&c(!0)},className:o?`cursor-text`:``,children:(0,L.jsx)(Ai,{text:O,markdown:!0,attachments:e.attachments})}):(0,L.jsx)(`pre`,{className:`overflow-x-auto whitespace-pre-wrap font-mono text-sm`,onDoubleClick:()=>{o&&c(!0)},children:O})}),(!!e.outputs?.length||T)&&(0,L.jsxs)(`div`,{className:`mt-2`,role:`group`,"aria-label":`Cell ${n+1} output`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-fg-muted`,children:[j(E?`Expand output`:`Collapse output`,E?(0,L.jsx)(He,{className:`size-3`}):(0,L.jsx)(Qe,{className:`size-3`}),()=>ee(!w),!!T),(0,L.jsx)(`span`,{children:`Output`}),o&&j(`Clear cell output`,(0,L.jsx)(Ue,{className:`size-3`}),()=>m(`clear`))]}),!E&&(0,L.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,L.jsx)(`div`,{className:`mt-2 first:mt-0`,children:(0,L.jsx)(Mi,{output:e})},t)),T&&v&&y&&(0,L.jsx)(Ni,{source:y,execution:v,onInterrupt:p},`${v.id}:${T.id}`)]})]})]})}var Ii=new Rt;function Li(e,t,n){let r=Ii.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);Ii.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 Ri({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,I.useMemo)(()=>{try{return{notebook:Kr(Wr(e)),error:null}}catch(e){return{notebook:null,error:e instanceof Error?e.message:`Invalid notebook`}}},[e]),[f,p]=(0,I.useState)([]),[m,h]=(0,I.useState)(null),g=(0,I.useRef)(!0),[_,v]=(0,I.useState)(null),[y,b]=(0,I.useState)(null),C=(0,I.useRef)(null),[w,ee]=(0,I.useState)([]),T=(0,I.useRef)(null),E=(0,I.useRef)(null),D=(0,I.useRef)(null),O=Lt(`notebook`,[t,r,n]),k=d.notebook!==null;(0,I.useLayoutEffect)(()=>{if(!(!T.current||!E.current||!k))return Li(T.current,E.current,O)},[O,k]),(0,I.useLayoutEffect)(()=>{if(!D.current)return;let e=E.current?.querySelector(`[data-cell-id="${CSS.escape(D.current)}"]`);e&&(e.scrollIntoView({block:`nearest`}),g.current&&e.focus({preventScroll:!0}),g.current=!0,D.current=null)});let A=e=>i?.(`${JSON.stringify(e,null,1)}\n`),j=d.notebook,te=(0,I.useMemo)(()=>({session:t,path:n,...r===void 0?{}:{root:r}}),[t,n,r]),M=fi(te,j,i?A:void 0,!!a),N=x(te,j,i?A:void 0,!!a),P=M.execution?.input?M.execution.cells.find(e=>e.state===`running`)?.id:void 0;if((0,I.useLayoutEffect)(()=>{if(!j||!P||!f.length)return;let e=j.cells.findIndex(e=>e.id===P),t=f.filter(t=>{let n=j.cells.findIndex(e=>e.id===t);return n<0||!ei(j,n).includes(e)});t.length!==f.length&&p(t)},[j,P,f]),!j)return(0,L.jsx)(`p`,{className:`p-6 text-sm text-danger`,role:`alert`,children:d.error});let F=(e,t=!1)=>{let n=C.current??_??e,r=j.cells.findIndex(e=>e.id===n),i=j.cells.findIndex(t=>t.id===e);ee(t?j.cells.slice(Math.min(r,i),Math.max(r,i)+1).map(e=>e.id):[e]),t||(C.current=e),v(e)},ne=(e,t=!1,n=!1)=>{F(e,n),b(t?e:null),D.current=e},re=$r(j),ie=new Set(j.cells.flatMap((e,t)=>f.includes(e.id)?ei(j,t).slice(1):[])),{add:ae,replace:oe,execute:se,operation:ce,keyDown:le}=ri({notebook:j,active:_,selected:w,update:A,choose:ne,setEditing:b,run:M.run,onUndo:s,onRedo:c});return(0,L.jsx)(S.Provider,{value:N,children:(0,L.jsx)(pi.Provider,{value:{...te,onOpenFile:l,intelligence:M.intelligenceSupported},children:(0,L.jsxs)(`div`,{className:`relative flex h-full min-h-0 flex-col bg-ground`,onKeyDown:i?le:void 0,onCopy:e=>{i&&ii(e,`copy`,j,w,A)},onCut:e=>{i&&ii(e,`cut`,j,w,A)},onPaste:e=>{i&&ii(e,`paste`,j,w,A)},children:[(0,L.jsx)(si,{notebook:j,focused:u,onChange:i?A:void 0,onReveal:e=>{h(e),e&&(p([]),v(e.id),e.output||b(e.id),D.current=e.id,g.current=!1)}}),(0,L.jsx)(vi,{notebook:j,source:{session:t,path:n,...r===void 0?{}:{root:r}},onChange:i?A:void 0,onAdd:ae,onRun:M.supported?()=>{M.run()}:a,onRunCopy:M.supported?a:void 0,running:o||M.busy,onRevealCell:e=>{p([]),ne(j.cells[e].id)},onRunSection:M.supported?e=>{M.run(ei(j,e))}:void 0}),(0,L.jsx)(`div`,{ref:T,className:`min-h-0 flex-1 overflow-auto bg-ground text-fg`,children:(0,L.jsxs)(`div`,{ref:E,className:`mx-auto flex max-w-4xl flex-col gap-7 py-6 pr-6 pl-14`,children:[(0,L.jsxs)(`p`,{className:`text-xs text-fg-muted`,children:[j.cells.length,` cells`]}),N.saveWarning&&(0,L.jsx)(`p`,{role:`status`,className:`text-xs text-fg-muted`,children:N.saveWarning}),M.error&&(0,L.jsx)(`p`,{role:`alert`,className:`text-xs text-danger`,children:M.error}),j.cells.map((e,a)=>ie.has(a)?null:(0,L.jsx)(Fi,{cell:e,match:m&&m.id===e.id?m:void 0,sectionCollapsed:f.includes(e.id),onToggleSection:re[a]?.level?()=>p(t=>t.includes(e.id)?t.filter(t=>t!==e.id):[...t,e.id]):void 0,notebook:j,index:a,active:_===e.id,editing:y===e.id,selected:w.length>1&&w.includes(e.id),editable:!!i,onSelect:t=>F(e.id,t),onEdit:t=>{v(e.id),b(t?e.id:null)},onSource:e=>A(Gr(j,a,e)),onLanguage:t=>oe(a,Jr(e,t)),onInterrupt:()=>{M.interrupt()},execution:M.execution?.cells.find(t=>t.id===e.id)??ni(e),inputExecution:P===e.id?M.execution??void 0:void 0,inputSource:te,onRun:M.supported?e=>{M.run(j.cells.flatMap((t,n)=>(e===`cell`?n===a:e===`above`?n<a:n>=a)?[n]:[]))}:void 0,onExecute:e=>se(a,e),onOperation:e=>ce(a,e),onSave:()=>{Oe(De(t,n,r))},onSplit:t=>{if(j.cells.length>=2e3)return;let n=z(e.source),r={...Yr(e.cell_type),source:n.slice(t)},i=[...j.cells];i.splice(a,1,{...e,source:n.slice(0,t)},r),A({...j,cells:i}),ne(r.id,!0)}},e.id)),i&&(0,L.jsx)(`div`,{className:`flex gap-3`,children:[`code`,`markdown`,`raw`].map(e=>(0,L.jsxs)(`button`,{disabled:j.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:()=>ae(e,j.cells.length),children:[(0,L.jsx)(We,{className:`size-3.5`}),e===`code`?`Code`:e===`markdown`?`Markdown`:`Raw`,` cell`]},e))})]})})]})})})}var zi=0;function Bi(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 Vi(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 Hi=class{root;matchName=`puddle-find-${++zi}-match`;activeName=`puddle-find-${zi}-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=Bi(this.root),i=nt(n.text,e,t);if(this.ranges=i.matches.map(e=>Vi(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`}))}};k.addHook(`afterSanitizeAttributes`,e=>{e.tagName===`A`&&/^https?:/i.test(e.getAttribute(`href`)??``)&&(e.setAttribute(`target`,`_blank`),e.setAttribute(`rel`,`noopener noreferrer`))});function Ui({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=Lt(`markdown`,[e,r,t]),f=(0,I.useId)().replace(/[^A-Za-z0-9_-]/g,``),p=(0,I.useSyncExternalStore)(e=>D(e),O,O),m=(0,I.useMemo)(()=>k.sanitize(Kt(n,f)),[n,f]),h=(0,I.useMemo)(()=>zt(n),[n]),g=(0,I.useMemo)(()=>({__html:m}),[m,p]),_=(0,I.useRef)(null),v=(0,I.useRef)(null),y=(0,I.useRef)(null);(0,I.useEffect)(()=>{let e=v.current;if(!e)return;let t=new Hi(e);return y.current=t,()=>{t.dispose(),y.current=null}},[]);let b=$e({shortcutEnabled:s,onFind:(e,t,n)=>y.current?.find(e,t,n)??tt,onClear:()=>y.current?.clear(),onCloseFocus:()=>_.current?.focus({preventScroll:!0})});(0,I.useEffect)(()=>b.refresh(),[m,p,b.refresh]),(0,I.useEffect)(()=>{let e=v.current;if(!e)return;let t=new AbortController;return sn(e,p,t.signal).then(()=>{t.signal.aborted||b.refresh()}),()=>t.abort()},[m,p,b.refresh]),(0,I.useLayoutEffect)(()=>{let n=_.current,s=v.current;if(!(!n||!s))return Qn(n,{viewKey:d,channel:o,target:{session:e,path:t,root:r},driver:i,receiver:a,resizeElements:[n,s],sourceAnchors:()=>Ut(n,s,h)})},[m,h,e,t,r,o,i,a,d]),Ei(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=Wi(r);(e?v.current?.querySelector(`#${CSS.escape(e)}`):null)?.scrollIntoView({block:`nearest`});return}if(!u&&!e.metaKey&&!e.ctrlKey)return;let i=ut(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=Bt(Ut(r,i,h),a);o!==null&&(e.preventDefault(),c({line:oi(o,h)}))},S=C().editorFontSize;return(0,L.jsxs)(`div`,{className:`relative size-full bg-ground`,children:[(0,L.jsx)(`div`,{ref:_,tabIndex:-1,className:`h-full overflow-auto overscroll-contain outline-none`,children:(0,L.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,L.jsx)(ai,{controls:b})]})}function Wi(e){try{return decodeURIComponent(e.slice(1))}catch{return null}}var Gi=`puddle-preview-scroll-report`,Ki=`puddle-preview-scroll-apply`,qi=`puddle-preview-source-reveal`;function Ji(){return crypto.randomUUID()}function Yi(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 Xi(e,t,n){let r=Yi(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:Gi,channel:n,ratio:Wn(r.ratio),sourceLine:r.sourceLine===null?null:Math.max(1,r.sourceLine),layout:r.layout,scrolled:r.scrolled}}function Zi(e,t,n){let r=Yi(e,t,n);return!r||r.kind!==`puddle-preview-source-reveal`||typeof r.line!=`number`||!Number.isFinite(r.line)?null:{kind:qi,channel:n,line:Math.max(1,r.line)}}function Qi(e,t,n){e?.postMessage({kind:Ki,channel:t,ratio:Wn(n.ratio),sourceLine:n.sourceLine!==null&&Number.isFinite(n.sourceLine)?Math.max(1,n.sourceLine):null},`*`)}function $i(e){return`(() => {
@@ -0,0 +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{a as i,n as a,o,r as s,t as c}from"./dialog-IU2fjIs9.js";import{a as l,i as u,n as d}from"./queue-BlrQxHDl.js";import{t as f}from"./markdown-CMSzQtLp.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)(a,{wide:!0,className:`gap-6`,"data-release-notes":``,children:[(0,m.jsx)(_,{group:e}),(0,m.jsxs)(i,{children:[(0,m.jsxs)(o,{children:[`What’s new in `,e.version]}),(0,m.jsxs)(s,{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};