agent-canvas 0.1.7 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,43 +1,9 @@
1
- import g1,{useEffect as R0,useLayoutEffect as m$,useState as Z1,useCallback as C0,useRef as d1,createContext as W2}from"react";import{createRoot as j$}from"react-dom/client";import{SessionContext as T2,ActiveViewCtx as I$}from"#canvas/runtime";import{useState as i1,useCallback as y1,useEffect as Z5,useRef as q5}from"react";import{AnnotationCtx as y2}from"#canvas/runtime";function G1(){return`ann-${Date.now()}-${Math.random().toString(36).slice(2,6)}`}function a1(J,$){J.style.height="auto",J.style.height=($?Math.max($,J.scrollHeight):J.scrollHeight)+"px"}import{useAnnotations as q1}from"#canvas/runtime";import{jsxDEV as P2}from"react/jsx-dev-runtime";function j0(J,$){return`canvas:${J}:rev:${$}`}function o1(J,$){try{let Q=localStorage.getItem(j0(J,$));if(!Q)return null;return JSON.parse(Q)}catch{return null}}function M2(J,$,Q){try{localStorage.setItem(j0(J,$),JSON.stringify(Q))}catch{}}function B2(J,$){try{localStorage.removeItem(j0(J,$))}catch{}}function X5({sessionId:J,revision:$,isReadOnly:Q,children:Z}){let Y=q5(`${J}:${$}`),[X,q]=i1(()=>{return o1(J,$)?.annotations??[]}),[_,z]=i1(()=>{return o1(J,$)?.generalNote??""}),[K,U]=i1(null),[H,G]=i1(()=>{let w=o1(J,$);return w?.responses?new Map(w.responses):new Map}),[N,W]=i1(()=>{let w=o1(J,$);return w?.feedbackEntries?new Map(w.feedbackEntries):new Map});Z5(()=>{let w=`${J}:${$}`;if(w===Y.current)return;Y.current=w;let I=o1(J,$);q(I?.annotations??[]),z(I?.generalNote??""),G(I?.responses?new Map(I.responses):new Map),W(I?.feedbackEntries?new Map(I.feedbackEntries):new Map),U(null)},[J,$]);let M=q5(null);Z5(()=>{if(Q)return;if(M.current)clearTimeout(M.current);return M.current=setTimeout(()=>{M2(J,$,{annotations:X,generalNote:_,responses:Array.from(H.entries()),feedbackEntries:Array.from(N.entries())})},300),()=>{if(M.current)clearTimeout(M.current)}},[X,_,H,N,J,$,Q]);let F=y1((w,I,T,L,c)=>{q((o)=>[...o,{id:w,snippet:I,note:T,createdAt:new Date().toISOString(),filePath:L,context:c}])},[]),B=y1((w,I,T)=>{F(G1(),w,I,T)},[F]),y=y1((w,I)=>{q((T)=>T.map((L)=>L.id===w?{...L,note:I}:L))},[]),S=y1((w)=>{L2(w),q((I)=>I.filter((T)=>T.id!==w)),U((I)=>I===w?null:I)},[]),R=y1((w,I)=>{G((T)=>{let L=new Map(T);return L.set(w,I),L})},[]),m=y1((w,I)=>{W((T)=>{let L=T.get(w);if(L&&L.markdown===I.markdown&&L.label===I.label&&L.required===I.required)return T;let c=new Map(T);return c.set(w,I),c})},[]),k=y1((w)=>{W((I)=>{if(!I.has(w))return I;let T=new Map(I);return T.delete(w),T})},[]),V=y1(()=>{for(let w of document.querySelectorAll("[data-annotation-id]"))z5(w);q([]),z(""),U(null),G(new Map),W(new Map),B2(J,$)},[J,$]);return P2(y2.Provider,{value:{annotations:X,addAnnotation:B,addAnnotationWithId:F,updateAnnotation:y,removeAnnotation:S,generalNote:_,setGeneralNote:z,clearAll:V,activeAnnotationId:K,setActiveAnnotationId:U,responses:H,setResponse:R,feedbackEntries:N,setFeedbackEntry:m,removeFeedbackEntry:k},children:Z},void 0,!1,void 0,this)}function L2(J){let $=document.querySelectorAll(`[data-annotation-id="${J}"]`);for(let Q of $)z5(Q)}function z5(J){let $=J.parentNode;if(!$)return;let Q=document.createTextNode(J.textContent||"");$.replaceChild(Q,J),$.normalize()}import g0,{useEffect as _1,useState as X1,useRef as O5,useContext as R2,useCallback as C2,useMemo as N0}from"react";import{createPortal as m2}from"react-dom";import{SessionContext as j2}from"#canvas/runtime";function u1(J,$){let Q=[],Z=S2(J);for(let Y of Z){let X=document.createRange();if(X.selectNodeContents(Y),Y===J.startContainer)X.setStart(Y,J.startOffset);if(Y===J.endContainer)X.setEnd(Y,J.endOffset);let q=X.toString();if(!q||!q.trim())continue;let _=document.createElement("mark");_.setAttribute("data-annotation-id",$),_.style.cssText=`
2
- background: var(--color-highlight-annotation);
3
- border-bottom: 1.5px solid var(--color-highlight-bg);
4
- border-radius: 2px;
5
- cursor: pointer;
6
- transition: background 150ms ease;
7
- color: inherit;
8
- padding: 1px 0;
9
- `;try{X.surroundContents(_)}catch{let z=X.extractContents();_.appendChild(z),X.insertNode(_)}Q.push(_)}return Q}function S2(J){let $=[],Q=J.commonAncestorContainer;if(Q.nodeType===Node.TEXT_NODE)return $.push(Q),$;let Z=document.createTreeWalker(Q,NodeFilter.SHOW_TEXT),Y;while(Y=Z.nextNode()){if(Y.parentElement?.classList.contains("select-none"))continue;if(J.intersectsNode(Y))$.push(Y)}return $}function A1(J,$){let Q=document.querySelectorAll(`[data-annotation-id="${J}"]`);for(let Z of Q)Z.style.cssText=$?`
10
- background: var(--color-highlight-bg);
11
- border-bottom: 1.5px solid var(--color-highlight-border);
12
- border-radius: 2px;
13
- cursor: pointer;
14
- transition: background 150ms ease;
15
- color: inherit;
16
- padding: 1px 0;
17
- `:`
18
- background: var(--color-highlight-annotation);
19
- border-bottom: 1.5px solid var(--color-highlight-bg);
20
- border-radius: 2px;
21
- cursor: pointer;
22
- transition: background 150ms ease;
23
- color: inherit;
24
- padding: 1px 0;
25
- `}function z0(J,$){if($!=null&&$!==J)A1($,!1);if(J!=null)A1(J,!0)}function _0(J,$){let Q=document.querySelectorAll(`[data-annotation-id="${J}"]`);for(let Z of Q)Z.setAttribute("data-annotation-id",$)}function K0(J,$){let Q=$.filter((_)=>!document.querySelector(`[data-annotation-id="${_.id}"]`));if(!Q.length)return;let Z=[],Y="",X=document.createTreeWalker(J,NodeFilter.SHOW_TEXT),q;while(q=X.nextNode()){if(q.parentElement?.classList.contains("select-none"))continue;Z.push({node:q,start:Y.length}),Y+=q.textContent||""}for(let _ of Q){let z=_.snippet;if(!z)continue;let K=[],U=0;while(!0){let F=Y.indexOf(z,U);if(F===-1)break;K.push(F),U=F+1}if(K.length===0)continue;let H=K[0];if(K.length>1&&_.context){let F=-1;for(let B of K){let y=0;if(_.context.before){let S=Y.slice(Math.max(0,B-80),B);if(S.includes(_.context.before))y+=2;else if(_.context.before.length>10&&S.includes(_.context.before.slice(-10)))y+=1}if(_.context.after){let S=Y.slice(B+z.length,B+z.length+80);if(S.includes(_.context.after))y+=2;else if(_.context.after.length>10&&S.includes(_.context.after.slice(0,10)))y+=1}if(y>F)F=y,H=B}}let G=H,N=H+z.length,W=_5(Z,G),M=_5(Z,N);if(!W||!M)continue;try{let F=document.createRange();F.setStart(W.node,W.offset),F.setEnd(M.node,M.offset),u1(F,_.id)}catch{}}}function _5(J,$){for(let Q=J.length-1;Q>=0;Q--)if(J[Q].start<=$){let Z=$-J[Q].start,Y=J[Q].node.textContent?.length??0;if(Z<=Y)return{node:J[Q].node,offset:Z}}return null}function U0(J){let $=document.querySelectorAll(`[data-annotation-id="${J}"]`);for(let Q of $){let Z=Q.parentNode;if(!Z)continue;while(Q.firstChild)Z.insertBefore(Q.firstChild,Q);Z.removeChild(Q),Z.normalize()}}function U5(J,$){let Q=K5(J,"before",60),Z=K5(J,"after",60),Y=A2(J.startContainer,$);return{before:Q,after:Z,hierarchy:Y}}function K5(J,$,Q){let Z=b2($==="before"?J.startContainer:J.endContainer);if(!Z)return"";let Y="";if($==="before"){let X=document.createTreeWalker(Z,NodeFilter.SHOW_TEXT),q;while(q=X.nextNode()){if(q===J.startContainer){Y+=(q.textContent||"").slice(0,J.startOffset);break}if(q.parentElement?.hasAttribute("data-annotation-id"))continue;Y+=q.textContent||""}if(Y.length>Q){Y=Y.slice(-Q);let _=Y.indexOf(" ");if(_>0)Y=Y.slice(_+1)}}else{let X=document.createTreeWalker(Z,NodeFilter.SHOW_TEXT),q=!1,_;while(_=X.nextNode()){if(_===J.endContainer){Y+=(_.textContent||"").slice(J.endOffset),q=!0;continue}if(q){if(_.parentElement?.hasAttribute("data-annotation-id"))continue;Y+=_.textContent||""}}if(Y.length>Q){Y=Y.slice(0,Q);let z=Y.lastIndexOf(" ");if(z>0)Y=Y.slice(0,z)}}return Y.trim()}function b2(J){let $=new Set(["DIV","P","LI","PRE","BLOCKQUOTE","SECTION","ARTICLE"]),Q=J.parentElement;while(Q){if($.has(Q.tagName))return Q;Q=Q.parentElement}return null}function A2(J,$){let Q=[],Z=J instanceof Element?J:J.parentElement;while(Z&&Z!==$){let Y=Z.getAttribute?.("data-task-id");if(Y){let X=Z.querySelector(".font-semibold");if(X)Q.unshift(X.textContent?.trim()||Y)}if(Z.tagName==="DIV"&&Z.querySelector(":scope > button .font-heading, :scope > div .font-heading")){let X=Z.querySelector(".font-heading");if(X)Q.unshift(X.textContent?.trim()||"")}Z=Z.parentElement}return Q}function I0(J){let $=J.snippet.trim(),Q=J.context,Z=$.length<30;if(Q&&Z&&(Q.before||Q.after)){let Y=[];if(Q.before)Y.push(`...${Q.before} `);if(Y.push($),Q.after)Y.push(` ${Q.after}...`);return Y.join("")}return $}import{useEffect as G0,useRef as H0,useState as s1,useCallback as V0,useMemo as H5}from"react";import{createPortal as w2}from"react-dom";function G5(J,$){let Y=$||document.body,X=J.getBoundingClientRect(),q=Y.getBoundingClientRect(),_=Y===document.body?window.scrollY:Y.scrollTop,z=X.bottom-q.top+_+8,K=Math.max(0,Math.min(X.left-q.left,q.width-280-12));return Y.style.position="relative",{style:{position:"absolute",top:`${z}px`,left:`${K}px`},parent:Y}}import{jsxDEV as e}from"react/jsx-dev-runtime";function W5({anchorEl:J,scrollContainer:$,onClose:Q,ignoreSelector:Z,zIndex:Y="50",padding:X="12px",width:q="280px",children:_}){let z=H0(null),K=H0(Q);K.current=Q;let{style:U,parent:H}=G5(J,$);return G0(()=>{let G=setTimeout(()=>{let N=(W)=>{if(z.current&&!z.current.contains(W.target)){if(Z&&W.target.closest?.(Z))return;K.current(),document.removeEventListener("mousedown",N)}};return document.addEventListener("mousedown",N),()=>document.removeEventListener("mousedown",N)},0);return()=>clearTimeout(G)},[Z]),w2(e("div",{ref:z,style:{...U,zIndex:Y,width:q,background:"var(--color-bg-elevated)",border:"1px solid var(--color-border-hover)",borderRadius:"8px",boxShadow:"0 4px 12px var(--color-shadow)",padding:X,fontFamily:"'Inter', sans-serif"},children:_},void 0,!1,void 0,this),H)}var T5=[{label:"Clarity",items:["Unclear","Why?","Needs example","Missing context"]},{label:"Scope",items:["Overkill","Out of scope","Important","Risky"]},{label:"Action",items:["Simplify","Rethink","Expand on this","Skip this"]}],N5=T5.flatMap((J)=>J.items);function t1({anchorEl:J,scrollContainer:$,snippet:Q,truncateAt:Z=100,header:Y,onAdd:X,onCancel:q}){let[_,z]=s1(""),[K,U]=s1(null),[H,G]=s1(!1),N=H0(null);G0(()=>{N.current?.focus()},[]);let W=V0(()=>{if(_.trim())X(_.trim());else q()},[_,X,q]),M=_.trim().length>0?N5.filter((T)=>T.toLowerCase().startsWith(_.trim().toLowerCase())):N5,F=H?[]:M.length===1&&M[0].toLowerCase()===_.trim().toLowerCase()?[]:M,B=new Set(F),y=T5.map((T)=>({label:T.label,items:T.items.filter((L)=>B.has(L))})).filter((T)=>T.items.length>0),S=y.map((T)=>T.items),R=S.flat(),m=H5(()=>{if(K===null)return 0;let T=0;for(let L=0;L<S.length;L++){if(K<T+S[L].length)return L;T+=S[L].length}return 0},[K,S]),k=H5(()=>{if(K===null)return 0;let T=0;for(let L=0;L<m;L++)T+=S[L].length;return K-T},[K,m,S]),V=(T,L)=>{let c=0;for(let o=0;o<T;o++)c+=S[o].length;return c+L};G0(()=>{U(null),G(!1)},[_]);let w=V0((T)=>{z(T)},[]),I=Q.length>Z?Q.slice(0,Z)+"...":Q;return e(W5,{anchorEl:J,scrollContainer:$,onClose:q,width:"420px",children:[Y??e("div",{style:{fontSize:"11px",color:"var(--color-text-tertiary)",fontStyle:"italic",marginBottom:"8px",lineHeight:"1.4",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden"},children:["“",I,"”"]},void 0,!0,void 0,this),e("textarea",{ref:N,value:_,onChange:(T)=>z(T.target.value),onKeyDown:(T)=>{if(R.length>0&&(T.key==="ArrowDown"||T.key==="ArrowUp"||T.key==="ArrowLeft"||T.key==="ArrowRight")){if(T.preventDefault(),K===null){U(0);return}if(T.key==="ArrowDown"){let L=Math.min(k+1,S[m].length-1);U(V(m,L))}else if(T.key==="ArrowUp"){let L=Math.max(k-1,0);U(V(m,L))}else if(T.key==="ArrowRight"){let L=Math.min(m+1,S.length-1),c=Math.min(k,S[L].length-1);U(V(L,c))}else if(T.key==="ArrowLeft"){let L=Math.max(m-1,0),c=Math.min(k,S[L].length-1);U(V(L,c))}return}if(K!==null&&R.length>0){if(T.key==="Tab"){T.preventDefault(),w(R[K]);return}if(T.key==="Enter"&&!T.shiftKey){T.preventDefault(),X(R[K]);return}}if(T.key==="Enter"&&!T.shiftKey){T.preventDefault(),W();return}if(T.key==="Escape")if(R.length>0&&!H)G(!0);else q()},style:{width:"100%",minHeight:"60px",background:"transparent",border:"none",color:"var(--color-text-primary)",fontFamily:"'Inter', sans-serif",fontSize:"13px",lineHeight:"1.5",resize:"vertical",outline:"none"},placeholder:"Add your note..."},void 0,!1,void 0,this),e("div",{style:{display:"flex",justifyContent:"flex-end",gap:"8px",marginTop:"8px"},children:[e("button",{onClick:q,style:{fontSize:"11px",color:"var(--color-text-tertiary)",background:"none",border:"none",cursor:"pointer",padding:"4px 12px",fontFamily:"'Inter', sans-serif"},children:"Cancel"},void 0,!1,void 0,this),e("button",{onClick:W,style:{fontSize:"11px",fontWeight:500,padding:"4px 12px",borderRadius:"6px",background:"var(--color-highlight-bg)",color:"var(--color-text-primary)",border:"1px solid var(--color-highlight-border)",cursor:"pointer",fontFamily:"'Inter', sans-serif"},children:"Add"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),R.length>0&&e("div",{style:{marginTop:"6px",borderTop:"1px solid var(--color-border-subtle)",paddingTop:"8px",display:"flex",gap:"4px"},children:y.map((T)=>e("div",{style:{flex:1},children:[e("div",{style:{fontSize:"10px",fontWeight:600,color:"var(--color-text-disabled)",textTransform:"uppercase",letterSpacing:"0.05em",padding:"2px 6px",marginBottom:"2px",fontFamily:"'Inter', sans-serif"},children:T.label},void 0,!1,void 0,this),T.items.map((L)=>{let c=R.indexOf(L);return e("div",{onMouseDown:(o)=>{o.preventDefault(),o.stopPropagation(),w(L)},onMouseEnter:()=>U(c),style:{padding:"3px 6px",fontSize:"12px",borderRadius:"4px",fontFamily:"'Inter', sans-serif",color:c===K?"var(--color-text-primary)":"var(--color-text-secondary)",background:c===K?"var(--color-highlight-selected)":"transparent",cursor:"pointer"},children:[e("span",{style:{fontWeight:500},children:L.slice(0,_.trim().length)},void 0,!1,void 0,this),L.slice(_.trim().length)]},L,!0,void 0,this)})]},T.label,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function n1({anchorEl:J,scrollContainer:$,initialNote:Q,onUpdate:Z,onDelete:Y,onClose:X}){let[q,_]=s1(Q),z=H0(null),[K,U]=s1(!1);G0(()=>{let G=z.current;if(G)G.style.height="auto",G.style.height=G.scrollHeight+"px",G.focus(),G.setSelectionRange(G.value.length,G.value.length)},[]);let H=V0(()=>{if(!q.trim()){Y(),X();return}Z(q),X()},[q,Z,Y,X]);return e(W5,{anchorEl:J,scrollContainer:$,onClose:H,ignoreSelector:"[data-annotation-id]",zIndex:"60",padding:"10px 12px",children:[e("textarea",{ref:z,value:q,onChange:(G)=>{_(G.target.value),Z(G.target.value),G.target.style.height="auto",G.target.style.height=G.target.scrollHeight+"px"},onKeyDown:(G)=>{if(G.key==="Enter"&&!G.shiftKey)G.preventDefault(),H();if(G.key==="Escape")H()},style:{width:"100%",background:"transparent",border:"none",color:"var(--color-text-primary)",fontFamily:"'Inter', sans-serif",fontSize:"13px",lineHeight:"1.5",resize:"none",outline:"none",overflow:"hidden"}},void 0,!1,void 0,this),e("div",{style:{display:"flex",justifyContent:"flex-end",marginTop:"6px"},children:e("button",{onClick:()=>{Y(),X()},onMouseEnter:()=>U(!0),onMouseLeave:()=>U(!1),style:{fontSize:"11px",color:K?"var(--color-accent-red)":"var(--color-text-tertiary)",background:"none",border:"none",cursor:"pointer",padding:"2px 0",fontFamily:"'Inter', sans-serif"},children:"Delete"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{jsxDEV as l,Fragment as y5}from"react/jsx-dev-runtime";var f0="[data-md='item'], [data-md='section'], [data-md='table'] tbody tr, [data-md='callout'], [data-md='note'], [data-md='checklist-item'], [data-md='choice-option'], [data-md='multichoice-option'], [data-md='userinput'], [data-md='rangeinput'], [data-md='image']",D0="[data-md='item'], [data-md='section'], [data-md='table'] tbody tr, [data-md='callout'], [data-md='note'], [data-md='checklist-item'], [data-md='image']";function F5({revision:J}){let $=R2(j2),[Q,Z]=X1(null),[Y,X]=X1(null),[q,_]=X1(!0),z=O5(null),{annotations:K,addAnnotationWithId:U,removeAnnotation:H,updateAnnotation:G,activeAnnotationId:N,setActiveAnnotationId:W}=q1(),[M,F]=X1(null),[B,y]=X1(null),[S,R]=X1(null),[m,k]=X1(null),[V,w]=X1(null),[I,T]=X1(null),[L,c]=X1(!1);_1(()=>{_(!0),X(null),T(null),import(`/api/session/${$}/plan.js?rev=${J}&t=${Date.now()}`).then((b)=>{Z(()=>b.default),_(!1)}).catch((b)=>{X(b.message),_(!1)})},[$,J]),_1(()=>{if(!Q||!z.current)return;let b=setTimeout(()=>{if(z.current)K0(z.current,K)},50);return()=>clearTimeout(b)},[Q]);let o=O5(null);_1(()=>{z0(N,o.current),o.current=N},[N]),_1(()=>{let b=z.current;if(!b)return;let C=(p)=>{let u=p.target.closest("[data-annotation-id]");if(!u)return;p.stopPropagation();let r=u.getAttribute("data-annotation-id");if(r===N)y({anchorEl:u,annId:r});else W(r)},h=(p)=>{let u=p.target.closest("[data-annotation-id]");if(u){let r=u.getAttribute("data-annotation-id");W(r)}},E=(p)=>{let u=p.target.closest("[data-annotation-id]"),r=p.relatedTarget?.closest?.("[data-annotation-id]");if(u&&!r){if(!document.getElementById("ann-inline-popover"))W(null)}};return b.addEventListener("click",C),b.addEventListener("mouseover",h),b.addEventListener("mouseout",E),()=>{b.removeEventListener("click",C),b.removeEventListener("mouseover",h),b.removeEventListener("mouseout",E)}},[Q,K,N]);let Q1=N0(()=>{let b=new Map;for(let C of K)if(C.snippet.startsWith("["))b.set(C.snippet,C.id);return b},[K]);_1(()=>{let b=z.current;if(!b)return;let C=(E)=>{if(V||S||B)return;let p=E.target;if(p.closest("[data-block-comment-btn]"))return;c(!1);let u=p.closest(f0);if(u&&b.contains(u)){let A=w1(b).indexOf(u);T(A>=0?A:null)}else T(null);let r=p.closest(D0);if(r&&b.contains(r)){k(r);let d=v1(r),A=d?Q1.get(d):void 0;if(A&&A!==N)W(A)}else k(null)},h=(E)=>{if(V||S||B)return;if(E.relatedTarget?.closest("[data-block-comment-btn]"))return;k(null),W(null)};return b.addEventListener("mousemove",C),b.addEventListener("mouseleave",h),()=>{b.removeEventListener("mousemove",C),b.removeEventListener("mouseleave",h)}},[Q,V,S,B,Q1,N]),_1(()=>{let b=(C)=>{let h=C.target.tagName;if(h==="INPUT"||h==="TEXTAREA"||C.target.isContentEditable)return;if(V||S||B)return;let E=z.current;if(!E)return;if(C.key==="ArrowDown"){C.preventDefault(),c(!0);let p=w1(E);if(p.length===0)return;T((u)=>{if(u===null)return 0;return Math.min(u+1,p.length-1)})}else if(C.key==="ArrowUp"){C.preventDefault(),c(!0);let p=w1(E);if(p.length===0)return;T((u)=>{if(u===null)return p.length-1;return Math.max(u-1,0)})}else if(C.key==="a"||C.key==="A"){if(I===null||!E)return;C.preventDefault();let u=w1(E)[I];if(!u)return;let r=v1(u);if(!r)return;let d=Q1.get(r);if(d)W(d),w({anchorEl:u,snippet:r,annId:d});else w({anchorEl:u,snippet:r})}else if(C.key===" "||C.key==="Enter"){if(I===null)return;let u=w1(E)[I];if(!u)return;let r=u.getAttribute("data-md");if(r==="choice-option"||r==="multichoice-option")C.preventDefault(),u.dispatchEvent(new CustomEvent("kb-select",{bubbles:!0}));else if(r==="userinput"){C.preventDefault();let d=u.querySelector("textarea");if(d){d.focus();let A=(g)=>{if(g.key==="Escape")g.preventDefault(),d.blur(),c(!0)};d.addEventListener("keydown",A),d.addEventListener("blur",()=>d.removeEventListener("keydown",A),{once:!0})}}else if(r==="rangeinput"){C.preventDefault();let d=u.querySelector("input[type='range']");if(d){d.focus();let A=(g)=>{if(g.key==="Escape"||g.key==="ArrowUp"||g.key==="ArrowDown")g.preventDefault(),d.blur(),c(!0)};d.addEventListener("keydown",A),d.addEventListener("blur",()=>d.removeEventListener("keydown",A),{once:!0})}}}else if(C.key==="Escape")T(null),c(!1),W(null)};return document.addEventListener("keydown",b),()=>document.removeEventListener("keydown",b)},[I,V,S,B,Q1]),_1(()=>{let b=z.current;if(!b||I===null||!L)return;let h=w1(b)[I];if(!h)return;h.style.outline="2px solid var(--color-accent-blue)",h.style.outlineOffset="-2px",h.style.borderRadius="8px",h.scrollIntoView({block:"nearest",behavior:"smooth"});let E=v1(h),p=E?Q1.get(E):void 0;if(p)W(p);return()=>{h.style.outline="",h.style.outlineOffset="",h.style.borderRadius=""}},[I,L,Q1]),_1(()=>{let b=()=>P1();return document.addEventListener("mouseup",b),()=>document.removeEventListener("mouseup",b)},[]);let P1=C2(()=>{let b=window.getSelection();if(!b||b.isCollapsed||!b.toString().trim())return;if(!z.current)return;let C=b.getRangeAt(0);if(!z.current.contains(C.startContainer))return;if(C.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let h=b.toString().trim();if(h.length<2)return;let E=C.cloneRange(),p=U5(C,z.current),u=`__pending_${Date.now()}`;try{u1(E,u)}catch{}window.getSelection()?.removeAllRanges();let r=document.querySelectorAll(`[data-annotation-id="${u}"]`),d=r[r.length-1];if(!d)return;R({anchorEl:d,tempId:u,snippet:h,ctx:p})},[U]),j=N0(()=>Q?l(Q,{},void 0,!1,void 0,this):null,[Q]);if(q)return l("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-body",children:"Loading plan..."},void 0,!1,void 0,this);if(Y)return l("div",{className:"bg-accent-red-muted rounded-lg p-5",children:[l("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Compilation Error"},void 0,!1,void 0,this),l("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:Y},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(!Q)return l("div",{className:"text-text-tertiary text-center py-8 font-body text-body",children:"No plan loaded"},void 0,!1,void 0,this);let i=document.getElementById("plan-scroll-container");return l(y5,{children:[l("div",{ref:z,className:"plan-content plan-updated",children:j},void 0,!1,void 0,this),M&&l(g2,{note:M.note,onSave:(b)=>{G(M.id,b),F(null)},onCancel:()=>F(null)},void 0,!1,void 0,this),B&&(()=>{let b=K.find((C)=>C.id===B.annId);if(!b)return null;return l(n1,{anchorEl:B.anchorEl,scrollContainer:i,initialNote:b.note,onUpdate:(C)=>G(B.annId,C),onDelete:()=>{H(B.annId),W(null)},onClose:()=>y(null)},void 0,!1,void 0,this)})(),S&&l(t1,{anchorEl:S.anchorEl,scrollContainer:i,snippet:S.snippet,truncateAt:80,onAdd:(b)=>{let C=G1();_0(S.tempId,C),U(C,S.snippet,b,void 0,S.ctx),R(null)},onCancel:()=>{U0(S.tempId),R(null)}},void 0,!1,void 0,this),l(I2,{containerRef:z,hoveredBlock:m,focusedBlockIndex:I,blockPopover:V,blockAnnotationMap:Q1,activeAnnotationId:N,onOpen:(b,C,h)=>{if(h)W(h),w({anchorEl:b,snippet:C,annId:h});else w({anchorEl:b,snippet:C})}},void 0,!1,void 0,this),V&&!V.annId&&l(t1,{anchorEl:V.anchorEl,scrollContainer:i,snippet:V.snippet,truncateAt:80,onAdd:(b)=>{let C=G1();U(C,V.snippet,b),w(null)},onCancel:()=>w(null)},void 0,!1,void 0,this),V?.annId&&(()=>{let b=K.find((C)=>C.id===V.annId);if(!b)return null;return l(n1,{anchorEl:V.anchorEl,scrollContainer:i,initialNote:b.note,onUpdate:(C)=>G(V.annId,C),onDelete:()=>{H(V.annId),W(null),w(null)},onClose:()=>w(null)},void 0,!1,void 0,this)})()]},void 0,!0,void 0,this)}function w1(J){return Array.from(J.querySelectorAll(f0))}function v1(J){let $=J.getAttribute("data-md");if($==="item"){let Q=J.getAttribute("data-md-label");return Q?`[Item] ${Q}`:null}if($==="section"){let Q=J.getAttribute("data-md-title");return Q?`[Section] ${Q}`:null}if($==="callout"){let Q=J.getAttribute("data-md-type")||"info",Z=J.textContent?.trim().slice(0,60)||"Callout";return`[Callout:${Q}] ${Z}`}if($==="note")return`[Note] ${J.textContent?.trim().slice(0,60)||"Note"}`;if(J.tagName==="TR"){let Q=Array.from(J.querySelectorAll("td")).map((Z)=>Z.textContent?.trim()).filter(Boolean);return Q.length?`[Row] ${Q.join(" | ")}`:null}if($==="checklist-item"){let Q=J.getAttribute("data-md-label");return Q?`[Checklist] ${Q}`:null}if($==="choice-option"||$==="multichoice-option"){let Q=J.getAttribute("data-md-label");return Q?`[Option] ${Q}`:null}if($==="userinput"){let Q=J.getAttribute("data-md-label");return Q?`[Input] ${Q}`:null}if($==="rangeinput"){let Q=J.getAttribute("data-md-label");return Q?`[Range] ${Q}`:null}if($==="image"){let Q=J.getAttribute("data-md-src");return Q?`[Image] ${Q}`:null}return null}function I2({containerRef:J,hoveredBlock:$,focusedBlockIndex:Q,blockPopover:Z,blockAnnotationMap:Y,activeAnnotationId:X,onOpen:q}){let[_,z]=X1([]);_1(()=>{let N=J.current;if(!N||Y.size===0){z([]);return}let W=[];for(let M of N.querySelectorAll(D0)){let F=v1(M);if(F&&Y.has(F))W.push(M)}z(W)},[Y,J.current]);let[K,U]=X1(null);_1(()=>{if(!X||!J.current){U(null);return}for(let N of J.current.querySelectorAll(f0)){let W=v1(N);if(W&&Y.get(W)===X){U(N);return}}U(null)},[X,Y]),_1(()=>{if(!K)return;return K.style.boxShadow="inset 0 0 0 1.5px var(--color-highlight-bg)",K.style.borderRadius="8px",()=>{K.style.boxShadow="",K.style.borderRadius=""}},[K]);let H=N0(()=>{if(Q===null||!J.current)return null;let N=w1(J.current)[Q];if(!N)return null;return N.matches(D0)?N:null},[Q,J.current]),G=N0(()=>{let N=new Set(_);if($)N.add($);if(H)N.add(H);if(Z?.anchorEl)N.add(Z.anchorEl);return Array.from(N)},[_,$,H,Z]);return l(y5,{children:G.map((N)=>l(V2,{block:N,isHovered:N===$||N===H||N===Z?.anchorEl,blockAnnotationMap:Y,activeAnnotationId:X,onOpen:q},N.getAttribute("data-task-id")||N.getAttribute("data-md-title")||N.textContent?.slice(0,30)||"block",!1,void 0,this))},void 0,!1,void 0,this)}function V2({block:J,isHovered:$,blockAnnotationMap:Q,activeAnnotationId:Z,onOpen:Y}){let X=v1(J);if(!X)return null;let q=Q.get(X),_=!!q;return m2(l("button",{"data-block-comment-btn":!0,onClick:(K)=>{K.stopPropagation(),Y(K.currentTarget,X,q)},className:`absolute top-1 right-1 z-10 w-6 h-6 flex items-center justify-center rounded transition-all duration-150 ${_?q===Z?"text-accent-amber bg-accent-amber-muted":"text-accent-amber opacity-60 hover:opacity-100":$?"text-text-disabled hover:text-text-tertiary opacity-50 hover:opacity-100":"text-text-disabled opacity-0 group-hover/section:opacity-20 hover:!opacity-80"}`,title:_?"Edit annotation":"Add annotation",children:l("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:_?"currentColor":"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:l("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),J)}function g2({note:J,onSave:$,onCancel:Q}){let[Z,Y]=g0.useState(J),X=g0.useRef(null);return g0.useEffect(()=>{X.current?.focus(),X.current?.select()},[]),l("div",{className:"fixed inset-0 z-50 bg-black/40 flex items-center justify-center",onClick:Q,children:l("div",{className:"bg-bg-elevated border border-border-hover rounded-lg shadow-md p-4 w-80",onClick:(q)=>q.stopPropagation(),children:[l("div",{className:"text-tiny uppercase tracking-widest text-text-tertiary font-body mb-2",children:"Edit annotation"},void 0,!1,void 0,this),l("textarea",{ref:X,value:Z,onChange:(q)=>Y(q.target.value),className:"w-full bg-transparent border-none text-body font-body text-text-primary resize-vertical focus:outline-none min-h-[60px]",onKeyDown:(q)=>{if(q.key==="Enter"&&(q.ctrlKey||q.metaKey))$(Z.trim());if(q.key==="Escape")Q()}},void 0,!1,void 0,this),l("div",{className:"flex justify-end gap-2 mt-2",children:[l("button",{onClick:Q,className:"text-meta text-text-tertiary font-body px-3 py-1",children:"Cancel"},void 0,!1,void 0,this),l("button",{onClick:()=>$(Z.trim()),className:"text-meta font-medium font-body px-3 py-1 rounded-md bg-highlight-bg text-text-primary border border-highlight-border",children:"Save"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}import I3,{useRef as x5,useEffect as o0,useCallback as h5,useState as x1,useContext as i0}from"react";function e1(J,$,Q,Z){let Y=[],X=J.filter((U)=>!U.filePath),q=J.filter((U)=>U.filePath),_=Q?Array.from(Q.values()).filter((U)=>k0(U)):[],z=Z?Array.from(Z.values()).filter((U)=>U.markdown.trim()):[];if(_.length>0||z.length>0){Y.push("## Responses"),Y.push("");for(let U of _)Y.push(k2(U));for(let U of z)Y.push(U.markdown.trim()),Y.push("")}if(X.length>0){Y.push("## Plan annotations"),Y.push("");let U=u2(X);Y.push(B5(U))}if(q.length>0){let U={};for(let H of q){let G=H.filePath;if(!U[G])U[G]=[];U[G].push(H)}Y.push("## File annotations"),Y.push("");for(let[H,G]of Object.entries(U)){Y.push(`### ${H}`),Y.push("");for(let N of G)Y.push(M5(N))}}if($.trim())Y.push("## General notes"),Y.push(""),Y.push($.trim()),Y.push("");return Y.join(`
26
- `).trim()+`
27
- `}function k0(J){if(J.note?.trim())return!0;if(J.value===null||J.value===void 0)return!1;if(J.type==="text"&&!J.value.trim())return!1;if(J.type==="checkbox"&&J.value.length===0)return!1;return!0}function D2(J){let $=[];for(let Q of J.values()){if(!Q.required)continue;if(Q.value===null||Q.value===void 0){$.push(Q);continue}if(Q.type==="text"&&!Q.value.trim()){$.push(Q);continue}if(Q.type==="checkbox"&&Q.value.length===0){$.push(Q);continue}}return $}function f2(J){let $=[];for(let Q of J.values())if(Q.required&&!Q.markdown.trim())$.push(Q);return $}function W0(J,$){let Q=D2(J),Z=f2($);return[...Q.map((Y)=>Y.label),...Z.map((Y)=>Y.label||Y.id)]}function k2(J){let $=[];switch($.push(`**${J.label}**`),J.type){case"radio":case"select":$.push(`Answer: ${J.value}`);break;case"checkbox":for(let Q of J.value)$.push(`- [x] ${Q}`);break;case"text":$.push(""),$.push(J.value.trim());break;case"range":$.push(`Answer: ${J.value}`);break}if(J.note?.trim())$.push(""),$.push(`Note: ${J.note.trim()}`);return $.push(""),$.join(`
28
- `)}function M5(J){let $=[],Q=J.snippet.trim(),Z=J.context,Y=Z?.lineStart!=null;if(J.filePath&&Y){let X=Z.lineStart,q=Z.lineEnd??X,_=Q.split(`
29
- `);if(Q.length<30&&X===q&&(Z.before||Z.after)){let K=I0(J);$.push(`> L${X}: ${K}`)}else if(_.length<=6)for(let K=0;K<_.length;K++)$.push(`> ${X+K} | ${_[K]}`);else{for(let K=0;K<3;K++)$.push(`> ${X+K} | ${_[K]}`);$.push(`> ... (${_.length} lines)`);for(let K=_.length-3;K<_.length;K++)$.push(`> ${X+K} | ${_[K]}`)}}else{let X=I0(J);if(Q.split(`
30
- `).length<=3)$.push(`> ${X.split(`
31
- `).join(`
32
- > `)}`);else{let q=Q.split(`
33
- `);$.push(`> ${q[0]}`),$.push(`> ... (${q.length} lines)`),$.push(`> ${q[q.length-1]}`)}}if(J.note.trim())$.push(""),$.push(J.note.trim());return $.push(""),$.join(`
34
- `)}function u2(J){let $={label:"",annotations:[],children:new Map};for(let Q of J){let Z=Q.context?.hierarchy||[],Y=$;for(let X of Z){if(!Y.children.has(X))Y.children.set(X,{label:X,annotations:[],children:new Map});Y=Y.children.get(X)}Y.annotations.push(Q)}return $}function B5(J,$=0){let Q=[];for(let Z of J.annotations)Q.push(M5(Z));for(let[,Z]of J.children){let Y=$===0?"###":"####";Q.push(`${Y} ${Z.label}`),Q.push(""),Q.push(B5(Z,$+1))}return Q.join(`
35
- `)}import{SessionContext as V3}from"#canvas/runtime";import{useEffect as a0,useState as L0,useRef as R3,useMemo as C3}from"react";function v0(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var m1=v0();function R5(J){m1=J}var R1={exec:()=>null};function v(J,$=""){let Q=typeof J=="string"?J:J.source,Z={replace:(Y,X)=>{let q=typeof X=="string"?X:X.source;return q=q.replace(J1.caret,"$1"),Q=Q.replace(Y,q),Z},getRegex:()=>new RegExp(Q,$)};return Z}var v2=(()=>{try{return!!new RegExp("(?<=1)(?<!1)")}catch{return!1}})(),J1={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] +\S/,listReplaceTask:/^\[[ xX]\] +/,listTaskCheckbox:/\[[ xX]\]/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:(J)=>new RegExp(`^( {0,3}${J})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:(J)=>new RegExp(`^ {0,${Math.min(3,J-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:(J)=>new RegExp(`^ {0,${Math.min(3,J-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:(J)=>new RegExp(`^ {0,${Math.min(3,J-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:(J)=>new RegExp(`^ {0,${Math.min(3,J-1)}}#`),htmlBeginRegex:(J)=>new RegExp(`^ {0,${Math.min(3,J-1)}}<(?:[a-z].*>|!--)`,"i"),blockquoteBeginRegex:(J)=>new RegExp(`^ {0,${Math.min(3,J-1)}}>`)},E2=/^(?:[ \t]*(?:\n|$))+/,x2=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,h2=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,Q0=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,p2=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,E0=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,C5=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,m5=v(C5).replace(/bull/g,E0).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,"").getRegex(),c2=v(C5).replace(/bull/g,E0).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),x0=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,d2=/^[^\n]+/,h0=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,r2=v(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",h0).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),l2=v(/^(bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,E0).getRegex(),M0="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",p0=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,a2=v("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$))","i").replace("comment",p0).replace("tag",M0).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),j5=v(x0).replace("hr",Q0).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",M0).getRegex(),i2=v(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",j5).getRegex(),c0={blockquote:i2,code:x2,def:r2,fences:h2,heading:p2,hr:Q0,html:a2,lheading:m5,list:l2,newline:E2,paragraph:j5,table:R1,text:d2},L5=v("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",Q0).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3}\t)[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",M0).getRegex(),o2={...c0,lheading:c2,table:L5,paragraph:v(x0).replace("hr",Q0).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",L5).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",M0).getRegex()},s2={...c0,html:v(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",p0).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:R1,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:v(x0).replace("hr",Q0).replace("heading",` *#{1,6} *[^
36
- ]`).replace("lheading",m5).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},t2=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,n2=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,I5=/^( {2,}|\\)\n(?!\s*$)/,e2=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,B0=/[\p{P}\p{S}]/u,d0=/[\s\p{P}\p{S}]/u,V5=/[^\s\p{P}\p{S}]/u,$3=v(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,d0).getRegex(),g5=/(?!~)[\p{P}\p{S}]/u,J3=/(?!~)[\s\p{P}\p{S}]/u,Y3=/(?:[^\s\p{P}\p{S}]|~)/u,D5=/(?![*_])[\p{P}\p{S}]/u,Q3=/(?![*_])[\s\p{P}\p{S}]/u,Z3=/(?:[^\s\p{P}\p{S}]|[*_])/u,q3=v(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",v2?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),f5=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,X3=v(f5,"u").replace(/punct/g,B0).getRegex(),z3=v(f5,"u").replace(/punct/g,g5).getRegex(),k5="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",_3=v(k5,"gu").replace(/notPunctSpace/g,V5).replace(/punctSpace/g,d0).replace(/punct/g,B0).getRegex(),K3=v(k5,"gu").replace(/notPunctSpace/g,Y3).replace(/punctSpace/g,J3).replace(/punct/g,g5).getRegex(),U3=v("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,V5).replace(/punctSpace/g,d0).replace(/punct/g,B0).getRegex(),G3=v(/^~~?(?:((?!~)punct)|[^\s~])/,"u").replace(/punct/g,D5).getRegex(),H3="^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)",N3=v(H3,"gu").replace(/notPunctSpace/g,Z3).replace(/punctSpace/g,Q3).replace(/punct/g,D5).getRegex(),W3=v(/\\(punct)/,"gu").replace(/punct/g,B0).getRegex(),T3=v(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme",/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email",/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),O3=v(p0).replace("(?:-->|$)","-->").getRegex(),F3=v("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment",O3).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),O0=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+[^`]*?`+(?!`)|[^\[\]\\`])*?/,y3=v(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace("label",O0).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),u5=v(/^!?\[(label)\]\[(ref)\]/).replace("label",O0).replace("ref",h0).getRegex(),v5=v(/^!?\[(ref)\](?:\[\])?/).replace("ref",h0).getRegex(),M3=v("reflink|nolink(?!\\()","g").replace("reflink",u5).replace("nolink",v5).getRegex(),P5=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,r0={_backpedal:R1,anyPunctuation:W3,autolink:T3,blockSkip:q3,br:I5,code:n2,del:R1,delLDelim:R1,delRDelim:R1,emStrongLDelim:X3,emStrongRDelimAst:_3,emStrongRDelimUnd:U3,escape:t2,link:y3,nolink:v5,punctuation:$3,reflink:u5,reflinkSearch:M3,tag:F3,text:e2,url:R1},B3={...r0,link:v(/^!?\[(label)\]\((.*?)\)/).replace("label",O0).getRegex(),reflink:v(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",O0).getRegex()},u0={...r0,emStrongRDelimAst:K3,emStrongLDelim:z3,delLDelim:G3,delRDelim:N3,url:v(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol",P5).replace("email",/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/,text:v(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace("protocol",P5).getRegex()},L3={...u0,br:v(I5).replace("{2,}","*").getRegex(),text:v(u0.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},T0={normal:c0,gfm:o2,pedantic:s2},$0={normal:r0,gfm:u0,breaks:L3,pedantic:B3},P3={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},S5=(J)=>P3[J];function H1(J,$){if($){if(J1.escapeTest.test(J))return J.replace(J1.escapeReplace,S5)}else if(J1.escapeTestNoEncode.test(J))return J.replace(J1.escapeReplaceNoEncode,S5);return J}function b5(J){try{J=encodeURI(J).replace(J1.percentDecode,"%")}catch{return null}return J}function A5(J,$){let Q=J.replace(J1.findPipe,(X,q,_)=>{let z=!1,K=q;for(;--K>=0&&_[K]==="\\";)z=!z;return z?"|":" |"}),Z=Q.split(J1.splitPipe),Y=0;if(Z[0].trim()||Z.shift(),Z.length>0&&!Z.at(-1)?.trim()&&Z.pop(),$)if(Z.length>$)Z.splice($);else for(;Z.length<$;)Z.push("");for(;Y<Z.length;Y++)Z[Y]=Z[Y].trim().replace(J1.slashPipe,"|");return Z}function J0(J,$,Q){let Z=J.length;if(Z===0)return"";let Y=0;for(;Y<Z;){let X=J.charAt(Z-Y-1);if(X===$&&!Q)Y++;else if(X!==$&&Q)Y++;else break}return J.slice(0,Z-Y)}function S3(J,$){if(J.indexOf($[1])===-1)return-1;let Q=0;for(let Z=0;Z<J.length;Z++)if(J[Z]==="\\")Z++;else if(J[Z]===$[0])Q++;else if(J[Z]===$[1]&&(Q--,Q<0))return Z;return Q>0?-2:-1}function b3(J,$=0){let Q=$,Z="";for(let Y of J)if(Y==="\t"){let X=4-Q%4;Z+=" ".repeat(X),Q+=X}else Z+=Y,Q++;return Z}function w5(J,$,Q,Z,Y){let X=$.href,q=$.title||null,_=J[1].replace(Y.other.outputLinkReplace,"$1");Z.state.inLink=!0;let z={type:J[0].charAt(0)==="!"?"image":"link",raw:Q,href:X,title:q,text:_,tokens:Z.inlineTokens(_)};return Z.state.inLink=!1,z}function A3(J,$,Q){let Z=J.match(Q.other.indentCodeCompensation);if(Z===null)return $;let Y=Z[1];return $.split(`
1
+ import g1,{useEffect as X0,useLayoutEffect as m$,useState as Q1,useCallback as C0,useRef as d1,createContext as W2,useMemo as j$}from"react";import{createRoot as I$}from"react-dom/client";function I0(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var R1=I0();function U5(J){R1=J}var A1={exec:()=>null};function v(J,$=""){let Q=typeof J=="string"?J:J.source,Z={replace:(Y,X)=>{let q=typeof X=="string"?X:X.source;return q=q.replace(J1.caret,"$1"),Q=Q.replace(Y,q),Z},getRegex:()=>new RegExp(Q,$)};return Z}var y2=(()=>{try{return!!new RegExp("(?<=1)(?<!1)")}catch{return!1}})(),J1={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] +\S/,listReplaceTask:/^\[[ xX]\] +/,listTaskCheckbox:/\[[ xX]\]/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:(J)=>new RegExp(`^( {0,3}${J})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:(J)=>new RegExp(`^ {0,${Math.min(3,J-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:(J)=>new RegExp(`^ {0,${Math.min(3,J-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:(J)=>new RegExp(`^ {0,${Math.min(3,J-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:(J)=>new RegExp(`^ {0,${Math.min(3,J-1)}}#`),htmlBeginRegex:(J)=>new RegExp(`^ {0,${Math.min(3,J-1)}}<(?:[a-z].*>|!--)`,"i"),blockquoteBeginRegex:(J)=>new RegExp(`^ {0,${Math.min(3,J-1)}}>`)},M2=/^(?:[ \t]*(?:\n|$))+/,B2=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,L2=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,s1=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,P2=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,V0=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,G5=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,H5=v(G5).replace(/bull/g,V0).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,"").getRegex(),S2=v(G5).replace(/bull/g,V0).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),g0=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,b2=/^[^\n]+/,D0=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,A2=v(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",D0).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),w2=v(/^(bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,V0).getRegex(),H0="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",f0=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,R2=v("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$))","i").replace("comment",f0).replace("tag",H0).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),N5=v(g0).replace("hr",s1).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",H0).getRegex(),C2=v(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",N5).getRegex(),k0={blockquote:C2,code:B2,def:A2,fences:L2,heading:P2,hr:s1,html:R2,lheading:H5,list:w2,newline:M2,paragraph:N5,table:A1,text:b2},Z5=v("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",s1).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3}\t)[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",H0).getRegex(),m2={...k0,lheading:S2,table:Z5,paragraph:v(g0).replace("hr",s1).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",Z5).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",H0).getRegex()},j2={...k0,html:v(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",f0).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:A1,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:v(g0).replace("hr",s1).replace("heading",` *#{1,6} *[^
2
+ ]`).replace("lheading",H5).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},I2=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,V2=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,W5=/^( {2,}|\\)\n(?!\s*$)/,g2=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,N0=/[\p{P}\p{S}]/u,u0=/[\s\p{P}\p{S}]/u,T5=/[^\s\p{P}\p{S}]/u,D2=v(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,u0).getRegex(),O5=/(?!~)[\p{P}\p{S}]/u,f2=/(?!~)[\s\p{P}\p{S}]/u,k2=/(?:[^\s\p{P}\p{S}]|~)/u,F5=/(?![*_])[\p{P}\p{S}]/u,u2=/(?![*_])[\s\p{P}\p{S}]/u,v2=/(?:[^\s\p{P}\p{S}]|[*_])/u,E2=v(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",y2?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),y5=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,x2=v(y5,"u").replace(/punct/g,N0).getRegex(),h2=v(y5,"u").replace(/punct/g,O5).getRegex(),M5="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",p2=v(M5,"gu").replace(/notPunctSpace/g,T5).replace(/punctSpace/g,u0).replace(/punct/g,N0).getRegex(),c2=v(M5,"gu").replace(/notPunctSpace/g,k2).replace(/punctSpace/g,f2).replace(/punct/g,O5).getRegex(),d2=v("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,T5).replace(/punctSpace/g,u0).replace(/punct/g,N0).getRegex(),r2=v(/^~~?(?:((?!~)punct)|[^\s~])/,"u").replace(/punct/g,F5).getRegex(),l2="^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)",a2=v(l2,"gu").replace(/notPunctSpace/g,v2).replace(/punctSpace/g,u2).replace(/punct/g,F5).getRegex(),i2=v(/\\(punct)/,"gu").replace(/punct/g,N0).getRegex(),o2=v(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme",/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email",/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),s2=v(f0).replace("(?:-->|$)","-->").getRegex(),t2=v("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment",s2).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),K0=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+[^`]*?`+(?!`)|[^\[\]\\`])*?/,n2=v(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace("label",K0).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),B5=v(/^!?\[(label)\]\[(ref)\]/).replace("label",K0).replace("ref",D0).getRegex(),L5=v(/^!?\[(ref)\](?:\[\])?/).replace("ref",D0).getRegex(),e2=v("reflink|nolink(?!\\()","g").replace("reflink",B5).replace("nolink",L5).getRegex(),q5=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,v0={_backpedal:A1,anyPunctuation:i2,autolink:o2,blockSkip:E2,br:W5,code:V2,del:A1,delLDelim:A1,delRDelim:A1,emStrongLDelim:x2,emStrongRDelimAst:p2,emStrongRDelimUnd:d2,escape:I2,link:n2,nolink:L5,punctuation:D2,reflink:B5,reflinkSearch:e2,tag:t2,text:g2,url:A1},$3={...v0,link:v(/^!?\[(label)\]\((.*?)\)/).replace("label",K0).getRegex(),reflink:v(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",K0).getRegex()},j0={...v0,emStrongRDelimAst:c2,emStrongLDelim:h2,delLDelim:r2,delRDelim:a2,url:v(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol",q5).replace("email",/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/,text:v(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace("protocol",q5).getRegex()},J3={...j0,br:v(W5).replace("{2,}","*").getRegex(),text:v(j0.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},_0={normal:k0,gfm:m2,pedantic:j2},a1={normal:v0,gfm:j0,breaks:J3,pedantic:$3},Y3={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},X5=(J)=>Y3[J];function G1(J,$){if($){if(J1.escapeTest.test(J))return J.replace(J1.escapeReplace,X5)}else if(J1.escapeTestNoEncode.test(J))return J.replace(J1.escapeReplaceNoEncode,X5);return J}function z5(J){try{J=encodeURI(J).replace(J1.percentDecode,"%")}catch{return null}return J}function _5(J,$){let Q=J.replace(J1.findPipe,(X,q,_)=>{let z=!1,K=q;for(;--K>=0&&_[K]==="\\";)z=!z;return z?"|":" |"}),Z=Q.split(J1.splitPipe),Y=0;if(Z[0].trim()||Z.shift(),Z.length>0&&!Z.at(-1)?.trim()&&Z.pop(),$)if(Z.length>$)Z.splice($);else for(;Z.length<$;)Z.push("");for(;Y<Z.length;Y++)Z[Y]=Z[Y].trim().replace(J1.slashPipe,"|");return Z}function i1(J,$,Q){let Z=J.length;if(Z===0)return"";let Y=0;for(;Y<Z;){let X=J.charAt(Z-Y-1);if(X===$&&!Q)Y++;else if(X!==$&&Q)Y++;else break}return J.slice(0,Z-Y)}function Q3(J,$){if(J.indexOf($[1])===-1)return-1;let Q=0;for(let Z=0;Z<J.length;Z++)if(J[Z]==="\\")Z++;else if(J[Z]===$[0])Q++;else if(J[Z]===$[1]&&(Q--,Q<0))return Z;return Q>0?-2:-1}function Z3(J,$=0){let Q=$,Z="";for(let Y of J)if(Y==="\t"){let X=4-Q%4;Z+=" ".repeat(X),Q+=X}else Z+=Y,Q++;return Z}function K5(J,$,Q,Z,Y){let X=$.href,q=$.title||null,_=J[1].replace(Y.other.outputLinkReplace,"$1");Z.state.inLink=!0;let z={type:J[0].charAt(0)==="!"?"image":"link",raw:Q,href:X,title:q,text:_,tokens:Z.inlineTokens(_)};return Z.state.inLink=!1,z}function q3(J,$,Q){let Z=J.match(Q.other.indentCodeCompensation);if(Z===null)return $;let Y=Z[1];return $.split(`
37
3
  `).map((X)=>{let q=X.match(Q.other.beginningSpace);if(q===null)return X;let[_]=q;return _.length>=Y.length?X.slice(Y.length):X}).join(`
38
- `)}var F0=class{options;rules;lexer;constructor(J){this.options=J||m1}space(J){let $=this.rules.block.newline.exec(J);if($&&$[0].length>0)return{type:"space",raw:$[0]}}code(J){let $=this.rules.block.code.exec(J);if($){let Q=$[0].replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:$[0],codeBlockStyle:"indented",text:this.options.pedantic?Q:J0(Q,`
39
- `)}}}fences(J){let $=this.rules.block.fences.exec(J);if($){let Q=$[0],Z=A3(Q,$[3]||"",this.rules);return{type:"code",raw:Q,lang:$[2]?$[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):$[2],text:Z}}}heading(J){let $=this.rules.block.heading.exec(J);if($){let Q=$[2].trim();if(this.rules.other.endingHash.test(Q)){let Z=J0(Q,"#");(this.options.pedantic||!Z||this.rules.other.endingSpaceChar.test(Z))&&(Q=Z.trim())}return{type:"heading",raw:$[0],depth:$[1].length,text:Q,tokens:this.lexer.inline(Q)}}}hr(J){let $=this.rules.block.hr.exec(J);if($)return{type:"hr",raw:J0($[0],`
40
- `)}}blockquote(J){let $=this.rules.block.blockquote.exec(J);if($){let Q=J0($[0],`
4
+ `)}var U0=class{options;rules;lexer;constructor(J){this.options=J||R1}space(J){let $=this.rules.block.newline.exec(J);if($&&$[0].length>0)return{type:"space",raw:$[0]}}code(J){let $=this.rules.block.code.exec(J);if($){let Q=$[0].replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:$[0],codeBlockStyle:"indented",text:this.options.pedantic?Q:i1(Q,`
5
+ `)}}}fences(J){let $=this.rules.block.fences.exec(J);if($){let Q=$[0],Z=q3(Q,$[3]||"",this.rules);return{type:"code",raw:Q,lang:$[2]?$[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):$[2],text:Z}}}heading(J){let $=this.rules.block.heading.exec(J);if($){let Q=$[2].trim();if(this.rules.other.endingHash.test(Q)){let Z=i1(Q,"#");(this.options.pedantic||!Z||this.rules.other.endingSpaceChar.test(Z))&&(Q=Z.trim())}return{type:"heading",raw:$[0],depth:$[1].length,text:Q,tokens:this.lexer.inline(Q)}}}hr(J){let $=this.rules.block.hr.exec(J);if($)return{type:"hr",raw:i1($[0],`
6
+ `)}}blockquote(J){let $=this.rules.block.blockquote.exec(J);if($){let Q=i1($[0],`
41
7
  `).split(`
42
8
  `),Z="",Y="",X=[];for(;Q.length>0;){let q=!1,_=[],z;for(z=0;z<Q.length;z++)if(this.rules.other.blockquoteStart.test(Q[z]))_.push(Q[z]),q=!0;else if(!q)_.push(Q[z]);else break;Q=Q.slice(z);let K=_.join(`
43
9
  `),U=K.replace(this.rules.other.blockquoteSetextReplace,`
@@ -48,16 +14,16 @@ ${U}`:U;let H=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTo
48
14
  `),M=this.blockquote(W);X[X.length-1]=M,Z=Z.substring(0,Z.length-N.raw.length)+M.raw,Y=Y.substring(0,Y.length-N.text.length)+M.text;break}else if(G?.type==="list"){let N=G,W=N.raw+`
49
15
  `+Q.join(`
50
16
  `),M=this.list(W);X[X.length-1]=M,Z=Z.substring(0,Z.length-G.raw.length)+M.raw,Y=Y.substring(0,Y.length-N.raw.length)+M.raw,Q=W.substring(X.at(-1).raw.length).split(`
51
- `);continue}}return{type:"blockquote",raw:Z,tokens:X,text:Y}}}list(J){let $=this.rules.block.list.exec(J);if($){let Q=$[1].trim(),Z=Q.length>1,Y={type:"list",raw:"",ordered:Z,start:Z?+Q.slice(0,-1):"",loose:!1,items:[]};Q=Z?`\\d{1,9}\\${Q.slice(-1)}`:`\\${Q}`,this.options.pedantic&&(Q=Z?Q:"[*+-]");let X=this.rules.other.listItemRegex(Q),q=!1;for(;J;){let z=!1,K="",U="";if(!($=X.exec(J))||this.rules.block.hr.test(J))break;K=$[0],J=J.substring(K.length);let H=b3($[2].split(`
17
+ `);continue}}return{type:"blockquote",raw:Z,tokens:X,text:Y}}}list(J){let $=this.rules.block.list.exec(J);if($){let Q=$[1].trim(),Z=Q.length>1,Y={type:"list",raw:"",ordered:Z,start:Z?+Q.slice(0,-1):"",loose:!1,items:[]};Q=Z?`\\d{1,9}\\${Q.slice(-1)}`:`\\${Q}`,this.options.pedantic&&(Q=Z?Q:"[*+-]");let X=this.rules.other.listItemRegex(Q),q=!1;for(;J;){let z=!1,K="",U="";if(!($=X.exec(J))||this.rules.block.hr.test(J))break;K=$[0],J=J.substring(K.length);let H=Z3($[2].split(`
52
18
  `,1)[0],$[1].length),G=J.split(`
53
19
  `,1)[0],N=!H.trim(),W=0;if(this.options.pedantic?(W=2,U=H.trimStart()):N?W=$[1].length+1:(W=H.search(this.rules.other.nonSpaceChar),W=W>4?1:W,U=H.slice(W),W+=$[1].length),N&&this.rules.other.blankLine.test(G)&&(K+=G+`
54
- `,J=J.substring(G.length+1),z=!0),!z){let M=this.rules.other.nextBulletRegex(W),F=this.rules.other.hrRegex(W),B=this.rules.other.fencesBeginRegex(W),y=this.rules.other.headingBeginRegex(W),S=this.rules.other.htmlBeginRegex(W),R=this.rules.other.blockquoteBeginRegex(W);for(;J;){let m=J.split(`
55
- `,1)[0],k;if(G=m,this.options.pedantic?(G=G.replace(this.rules.other.listReplaceNesting," "),k=G):k=G.replace(this.rules.other.tabCharGlobal," "),B.test(G)||y.test(G)||S.test(G)||R.test(G)||M.test(G)||F.test(G))break;if(k.search(this.rules.other.nonSpaceChar)>=W||!G.trim())U+=`
56
- `+k.slice(W);else{if(N||H.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||B.test(H)||y.test(H)||F.test(H))break;U+=`
20
+ `,J=J.substring(G.length+1),z=!0),!z){let M=this.rules.other.nextBulletRegex(W),F=this.rules.other.hrRegex(W),L=this.rules.other.fencesBeginRegex(W),y=this.rules.other.headingBeginRegex(W),S=this.rules.other.htmlBeginRegex(W),R=this.rules.other.blockquoteBeginRegex(W);for(;J;){let m=J.split(`
21
+ `,1)[0],k;if(G=m,this.options.pedantic?(G=G.replace(this.rules.other.listReplaceNesting," "),k=G):k=G.replace(this.rules.other.tabCharGlobal," "),L.test(G)||y.test(G)||S.test(G)||R.test(G)||M.test(G)||F.test(G))break;if(k.search(this.rules.other.nonSpaceChar)>=W||!G.trim())U+=`
22
+ `+k.slice(W);else{if(N||H.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||L.test(H)||y.test(H)||F.test(H))break;U+=`
57
23
  `+G}N=!G.trim(),K+=m+`
58
- `,J=J.substring(m.length+1),H=k.slice(W)}}Y.loose||(q?Y.loose=!0:this.rules.other.doubleBlankLine.test(K)&&(q=!0)),Y.items.push({type:"list_item",raw:K,task:!!this.options.gfm&&this.rules.other.listIsTask.test(U),loose:!1,text:U,tokens:[]}),Y.raw+=K}let _=Y.items.at(-1);if(_)_.raw=_.raw.trimEnd(),_.text=_.text.trimEnd();else return;Y.raw=Y.raw.trimEnd();for(let z of Y.items){if(this.lexer.state.top=!1,z.tokens=this.lexer.blockTokens(z.text,[]),z.task){if(z.text=z.text.replace(this.rules.other.listReplaceTask,""),z.tokens[0]?.type==="text"||z.tokens[0]?.type==="paragraph"){z.tokens[0].raw=z.tokens[0].raw.replace(this.rules.other.listReplaceTask,""),z.tokens[0].text=z.tokens[0].text.replace(this.rules.other.listReplaceTask,"");for(let U=this.lexer.inlineQueue.length-1;U>=0;U--)if(this.rules.other.listIsTask.test(this.lexer.inlineQueue[U].src)){this.lexer.inlineQueue[U].src=this.lexer.inlineQueue[U].src.replace(this.rules.other.listReplaceTask,"");break}}let K=this.rules.other.listTaskCheckbox.exec(z.raw);if(K){let U={type:"checkbox",raw:K[0]+" ",checked:K[0]!=="[ ]"};z.checked=U.checked,Y.loose?z.tokens[0]&&["paragraph","text"].includes(z.tokens[0].type)&&"tokens"in z.tokens[0]&&z.tokens[0].tokens?(z.tokens[0].raw=U.raw+z.tokens[0].raw,z.tokens[0].text=U.raw+z.tokens[0].text,z.tokens[0].tokens.unshift(U)):z.tokens.unshift({type:"paragraph",raw:U.raw,text:U.raw,tokens:[U]}):z.tokens.unshift(U)}}if(!Y.loose){let K=z.tokens.filter((H)=>H.type==="space"),U=K.length>0&&K.some((H)=>this.rules.other.anyLine.test(H.raw));Y.loose=U}}if(Y.loose)for(let z of Y.items){z.loose=!0;for(let K of z.tokens)K.type==="text"&&(K.type="paragraph")}return Y}}html(J){let $=this.rules.block.html.exec(J);if($)return{type:"html",block:!0,raw:$[0],pre:$[1]==="pre"||$[1]==="script"||$[1]==="style",text:$[0]}}def(J){let $=this.rules.block.def.exec(J);if($){let Q=$[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal," "),Z=$[2]?$[2].replace(this.rules.other.hrefBrackets,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",Y=$[3]?$[3].substring(1,$[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):$[3];return{type:"def",tag:Q,raw:$[0],href:Z,title:Y}}}table(J){let $=this.rules.block.table.exec(J);if(!$||!this.rules.other.tableDelimiter.test($[2]))return;let Q=A5($[1]),Z=$[2].replace(this.rules.other.tableAlignChars,"").split("|"),Y=$[3]?.trim()?$[3].replace(this.rules.other.tableRowBlankLine,"").split(`
59
- `):[],X={type:"table",raw:$[0],header:[],align:[],rows:[]};if(Q.length===Z.length){for(let q of Z)this.rules.other.tableAlignRight.test(q)?X.align.push("right"):this.rules.other.tableAlignCenter.test(q)?X.align.push("center"):this.rules.other.tableAlignLeft.test(q)?X.align.push("left"):X.align.push(null);for(let q=0;q<Q.length;q++)X.header.push({text:Q[q],tokens:this.lexer.inline(Q[q]),header:!0,align:X.align[q]});for(let q of Y)X.rows.push(A5(q,X.header.length).map((_,z)=>({text:_,tokens:this.lexer.inline(_),header:!1,align:X.align[z]})));return X}}lheading(J){let $=this.rules.block.lheading.exec(J);if($)return{type:"heading",raw:$[0],depth:$[2].charAt(0)==="="?1:2,text:$[1],tokens:this.lexer.inline($[1])}}paragraph(J){let $=this.rules.block.paragraph.exec(J);if($){let Q=$[1].charAt($[1].length-1)===`
60
- `?$[1].slice(0,-1):$[1];return{type:"paragraph",raw:$[0],text:Q,tokens:this.lexer.inline(Q)}}}text(J){let $=this.rules.block.text.exec(J);if($)return{type:"text",raw:$[0],text:$[0],tokens:this.lexer.inline($[0])}}escape(J){let $=this.rules.inline.escape.exec(J);if($)return{type:"escape",raw:$[0],text:$[1]}}tag(J){let $=this.rules.inline.tag.exec(J);if($)return!this.lexer.state.inLink&&this.rules.other.startATag.test($[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test($[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test($[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test($[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:$[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:$[0]}}link(J){let $=this.rules.inline.link.exec(J);if($){let Q=$[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(Q)){if(!this.rules.other.endAngleBracket.test(Q))return;let X=J0(Q.slice(0,-1),"\\");if((Q.length-X.length)%2===0)return}else{let X=S3($[2],"()");if(X===-2)return;if(X>-1){let q=($[0].indexOf("!")===0?5:4)+$[1].length+X;$[2]=$[2].substring(0,X),$[0]=$[0].substring(0,q).trim(),$[3]=""}}let Z=$[2],Y="";if(this.options.pedantic){let X=this.rules.other.pedanticHrefTitle.exec(Z);X&&(Z=X[1],Y=X[3])}else Y=$[3]?$[3].slice(1,-1):"";return Z=Z.trim(),this.rules.other.startAngleBracket.test(Z)&&(this.options.pedantic&&!this.rules.other.endAngleBracket.test(Q)?Z=Z.slice(1):Z=Z.slice(1,-1)),w5($,{href:Z&&Z.replace(this.rules.inline.anyPunctuation,"$1"),title:Y&&Y.replace(this.rules.inline.anyPunctuation,"$1")},$[0],this.lexer,this.rules)}}reflink(J,$){let Q;if((Q=this.rules.inline.reflink.exec(J))||(Q=this.rules.inline.nolink.exec(J))){let Z=(Q[2]||Q[1]).replace(this.rules.other.multipleSpaceGlobal," "),Y=$[Z.toLowerCase()];if(!Y){let X=Q[0].charAt(0);return{type:"text",raw:X,text:X}}return w5(Q,Y,Q[0],this.lexer,this.rules)}}emStrong(J,$,Q=""){let Z=this.rules.inline.emStrongLDelim.exec(J);if(!Z||Z[3]&&Q.match(this.rules.other.unicodeAlphaNumeric))return;if(!(Z[1]||Z[2])||!Q||this.rules.inline.punctuation.exec(Q)){let Y=[...Z[0]].length-1,X,q,_=Y,z=0,K=Z[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(K.lastIndex=0,$=$.slice(-1*J.length+Y);(Z=K.exec($))!=null;){if(X=Z[1]||Z[2]||Z[3]||Z[4]||Z[5]||Z[6],!X)continue;if(q=[...X].length,Z[3]||Z[4]){_+=q;continue}else if((Z[5]||Z[6])&&Y%3&&!((Y+q)%3)){z+=q;continue}if(_-=q,_>0)continue;q=Math.min(q,q+_+z);let U=[...Z[0]][0].length,H=J.slice(0,Y+Z.index+U+q);if(Math.min(Y,q)%2){let N=H.slice(1,-1);return{type:"em",raw:H,text:N,tokens:this.lexer.inlineTokens(N)}}let G=H.slice(2,-2);return{type:"strong",raw:H,text:G,tokens:this.lexer.inlineTokens(G)}}}}codespan(J){let $=this.rules.inline.code.exec(J);if($){let Q=$[2].replace(this.rules.other.newLineCharGlobal," "),Z=this.rules.other.nonSpaceChar.test(Q),Y=this.rules.other.startingSpaceChar.test(Q)&&this.rules.other.endingSpaceChar.test(Q);return Z&&Y&&(Q=Q.substring(1,Q.length-1)),{type:"codespan",raw:$[0],text:Q}}}br(J){let $=this.rules.inline.br.exec(J);if($)return{type:"br",raw:$[0]}}del(J,$,Q=""){let Z=this.rules.inline.delLDelim.exec(J);if(!Z)return;if(!Z[1]||!Q||this.rules.inline.punctuation.exec(Q)){let Y=[...Z[0]].length-1,X,q,_=Y,z=this.rules.inline.delRDelim;for(z.lastIndex=0,$=$.slice(-1*J.length+Y);(Z=z.exec($))!=null;){if(X=Z[1]||Z[2]||Z[3]||Z[4]||Z[5]||Z[6],!X||(q=[...X].length,q!==Y))continue;if(Z[3]||Z[4]){_+=q;continue}if(_-=q,_>0)continue;q=Math.min(q,q+_);let K=[...Z[0]][0].length,U=J.slice(0,Y+Z.index+K+q),H=U.slice(Y,-Y);return{type:"del",raw:U,text:H,tokens:this.lexer.inlineTokens(H)}}}}autolink(J){let $=this.rules.inline.autolink.exec(J);if($){let Q,Z;return $[2]==="@"?(Q=$[1],Z="mailto:"+Q):(Q=$[1],Z=Q),{type:"link",raw:$[0],text:Q,href:Z,tokens:[{type:"text",raw:Q,text:Q}]}}}url(J){let $;if($=this.rules.inline.url.exec(J)){let Q,Z;if($[2]==="@")Q=$[0],Z="mailto:"+Q;else{let Y;do Y=$[0],$[0]=this.rules.inline._backpedal.exec($[0])?.[0]??"";while(Y!==$[0]);Q=$[0],$[1]==="www."?Z="http://"+$[0]:Z=$[0]}return{type:"link",raw:$[0],text:Q,href:Z,tokens:[{type:"text",raw:Q,text:Q}]}}}inlineText(J){let $=this.rules.inline.text.exec(J);if($){let Q=this.lexer.state.inRawBlock;return{type:"text",raw:$[0],text:$[0],escaped:Q}}}},K1=class J{tokens;options;state;inlineQueue;tokenizer;constructor($){this.tokens=[],this.tokens.links=Object.create(null),this.options=$||m1,this.options.tokenizer=this.options.tokenizer||new F0,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};let Q={other:J1,block:T0.normal,inline:$0.normal};this.options.pedantic?(Q.block=T0.pedantic,Q.inline=$0.pedantic):this.options.gfm&&(Q.block=T0.gfm,this.options.breaks?Q.inline=$0.breaks:Q.inline=$0.gfm),this.tokenizer.rules=Q}static get rules(){return{block:T0,inline:$0}}static lex($,Q){return new J(Q).lex($)}static lexInline($,Q){return new J(Q).inlineTokens($)}lex($){$=$.replace(J1.carriageReturn,`
24
+ `,J=J.substring(m.length+1),H=k.slice(W)}}Y.loose||(q?Y.loose=!0:this.rules.other.doubleBlankLine.test(K)&&(q=!0)),Y.items.push({type:"list_item",raw:K,task:!!this.options.gfm&&this.rules.other.listIsTask.test(U),loose:!1,text:U,tokens:[]}),Y.raw+=K}let _=Y.items.at(-1);if(_)_.raw=_.raw.trimEnd(),_.text=_.text.trimEnd();else return;Y.raw=Y.raw.trimEnd();for(let z of Y.items){if(this.lexer.state.top=!1,z.tokens=this.lexer.blockTokens(z.text,[]),z.task){if(z.text=z.text.replace(this.rules.other.listReplaceTask,""),z.tokens[0]?.type==="text"||z.tokens[0]?.type==="paragraph"){z.tokens[0].raw=z.tokens[0].raw.replace(this.rules.other.listReplaceTask,""),z.tokens[0].text=z.tokens[0].text.replace(this.rules.other.listReplaceTask,"");for(let U=this.lexer.inlineQueue.length-1;U>=0;U--)if(this.rules.other.listIsTask.test(this.lexer.inlineQueue[U].src)){this.lexer.inlineQueue[U].src=this.lexer.inlineQueue[U].src.replace(this.rules.other.listReplaceTask,"");break}}let K=this.rules.other.listTaskCheckbox.exec(z.raw);if(K){let U={type:"checkbox",raw:K[0]+" ",checked:K[0]!=="[ ]"};z.checked=U.checked,Y.loose?z.tokens[0]&&["paragraph","text"].includes(z.tokens[0].type)&&"tokens"in z.tokens[0]&&z.tokens[0].tokens?(z.tokens[0].raw=U.raw+z.tokens[0].raw,z.tokens[0].text=U.raw+z.tokens[0].text,z.tokens[0].tokens.unshift(U)):z.tokens.unshift({type:"paragraph",raw:U.raw,text:U.raw,tokens:[U]}):z.tokens.unshift(U)}}if(!Y.loose){let K=z.tokens.filter((H)=>H.type==="space"),U=K.length>0&&K.some((H)=>this.rules.other.anyLine.test(H.raw));Y.loose=U}}if(Y.loose)for(let z of Y.items){z.loose=!0;for(let K of z.tokens)K.type==="text"&&(K.type="paragraph")}return Y}}html(J){let $=this.rules.block.html.exec(J);if($)return{type:"html",block:!0,raw:$[0],pre:$[1]==="pre"||$[1]==="script"||$[1]==="style",text:$[0]}}def(J){let $=this.rules.block.def.exec(J);if($){let Q=$[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal," "),Z=$[2]?$[2].replace(this.rules.other.hrefBrackets,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",Y=$[3]?$[3].substring(1,$[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):$[3];return{type:"def",tag:Q,raw:$[0],href:Z,title:Y}}}table(J){let $=this.rules.block.table.exec(J);if(!$||!this.rules.other.tableDelimiter.test($[2]))return;let Q=_5($[1]),Z=$[2].replace(this.rules.other.tableAlignChars,"").split("|"),Y=$[3]?.trim()?$[3].replace(this.rules.other.tableRowBlankLine,"").split(`
25
+ `):[],X={type:"table",raw:$[0],header:[],align:[],rows:[]};if(Q.length===Z.length){for(let q of Z)this.rules.other.tableAlignRight.test(q)?X.align.push("right"):this.rules.other.tableAlignCenter.test(q)?X.align.push("center"):this.rules.other.tableAlignLeft.test(q)?X.align.push("left"):X.align.push(null);for(let q=0;q<Q.length;q++)X.header.push({text:Q[q],tokens:this.lexer.inline(Q[q]),header:!0,align:X.align[q]});for(let q of Y)X.rows.push(_5(q,X.header.length).map((_,z)=>({text:_,tokens:this.lexer.inline(_),header:!1,align:X.align[z]})));return X}}lheading(J){let $=this.rules.block.lheading.exec(J);if($)return{type:"heading",raw:$[0],depth:$[2].charAt(0)==="="?1:2,text:$[1],tokens:this.lexer.inline($[1])}}paragraph(J){let $=this.rules.block.paragraph.exec(J);if($){let Q=$[1].charAt($[1].length-1)===`
26
+ `?$[1].slice(0,-1):$[1];return{type:"paragraph",raw:$[0],text:Q,tokens:this.lexer.inline(Q)}}}text(J){let $=this.rules.block.text.exec(J);if($)return{type:"text",raw:$[0],text:$[0],tokens:this.lexer.inline($[0])}}escape(J){let $=this.rules.inline.escape.exec(J);if($)return{type:"escape",raw:$[0],text:$[1]}}tag(J){let $=this.rules.inline.tag.exec(J);if($)return!this.lexer.state.inLink&&this.rules.other.startATag.test($[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test($[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test($[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test($[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:$[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:$[0]}}link(J){let $=this.rules.inline.link.exec(J);if($){let Q=$[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(Q)){if(!this.rules.other.endAngleBracket.test(Q))return;let X=i1(Q.slice(0,-1),"\\");if((Q.length-X.length)%2===0)return}else{let X=Q3($[2],"()");if(X===-2)return;if(X>-1){let q=($[0].indexOf("!")===0?5:4)+$[1].length+X;$[2]=$[2].substring(0,X),$[0]=$[0].substring(0,q).trim(),$[3]=""}}let Z=$[2],Y="";if(this.options.pedantic){let X=this.rules.other.pedanticHrefTitle.exec(Z);X&&(Z=X[1],Y=X[3])}else Y=$[3]?$[3].slice(1,-1):"";return Z=Z.trim(),this.rules.other.startAngleBracket.test(Z)&&(this.options.pedantic&&!this.rules.other.endAngleBracket.test(Q)?Z=Z.slice(1):Z=Z.slice(1,-1)),K5($,{href:Z&&Z.replace(this.rules.inline.anyPunctuation,"$1"),title:Y&&Y.replace(this.rules.inline.anyPunctuation,"$1")},$[0],this.lexer,this.rules)}}reflink(J,$){let Q;if((Q=this.rules.inline.reflink.exec(J))||(Q=this.rules.inline.nolink.exec(J))){let Z=(Q[2]||Q[1]).replace(this.rules.other.multipleSpaceGlobal," "),Y=$[Z.toLowerCase()];if(!Y){let X=Q[0].charAt(0);return{type:"text",raw:X,text:X}}return K5(Q,Y,Q[0],this.lexer,this.rules)}}emStrong(J,$,Q=""){let Z=this.rules.inline.emStrongLDelim.exec(J);if(!Z||Z[3]&&Q.match(this.rules.other.unicodeAlphaNumeric))return;if(!(Z[1]||Z[2])||!Q||this.rules.inline.punctuation.exec(Q)){let Y=[...Z[0]].length-1,X,q,_=Y,z=0,K=Z[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(K.lastIndex=0,$=$.slice(-1*J.length+Y);(Z=K.exec($))!=null;){if(X=Z[1]||Z[2]||Z[3]||Z[4]||Z[5]||Z[6],!X)continue;if(q=[...X].length,Z[3]||Z[4]){_+=q;continue}else if((Z[5]||Z[6])&&Y%3&&!((Y+q)%3)){z+=q;continue}if(_-=q,_>0)continue;q=Math.min(q,q+_+z);let U=[...Z[0]][0].length,H=J.slice(0,Y+Z.index+U+q);if(Math.min(Y,q)%2){let N=H.slice(1,-1);return{type:"em",raw:H,text:N,tokens:this.lexer.inlineTokens(N)}}let G=H.slice(2,-2);return{type:"strong",raw:H,text:G,tokens:this.lexer.inlineTokens(G)}}}}codespan(J){let $=this.rules.inline.code.exec(J);if($){let Q=$[2].replace(this.rules.other.newLineCharGlobal," "),Z=this.rules.other.nonSpaceChar.test(Q),Y=this.rules.other.startingSpaceChar.test(Q)&&this.rules.other.endingSpaceChar.test(Q);return Z&&Y&&(Q=Q.substring(1,Q.length-1)),{type:"codespan",raw:$[0],text:Q}}}br(J){let $=this.rules.inline.br.exec(J);if($)return{type:"br",raw:$[0]}}del(J,$,Q=""){let Z=this.rules.inline.delLDelim.exec(J);if(!Z)return;if(!Z[1]||!Q||this.rules.inline.punctuation.exec(Q)){let Y=[...Z[0]].length-1,X,q,_=Y,z=this.rules.inline.delRDelim;for(z.lastIndex=0,$=$.slice(-1*J.length+Y);(Z=z.exec($))!=null;){if(X=Z[1]||Z[2]||Z[3]||Z[4]||Z[5]||Z[6],!X||(q=[...X].length,q!==Y))continue;if(Z[3]||Z[4]){_+=q;continue}if(_-=q,_>0)continue;q=Math.min(q,q+_);let K=[...Z[0]][0].length,U=J.slice(0,Y+Z.index+K+q),H=U.slice(Y,-Y);return{type:"del",raw:U,text:H,tokens:this.lexer.inlineTokens(H)}}}}autolink(J){let $=this.rules.inline.autolink.exec(J);if($){let Q,Z;return $[2]==="@"?(Q=$[1],Z="mailto:"+Q):(Q=$[1],Z=Q),{type:"link",raw:$[0],text:Q,href:Z,tokens:[{type:"text",raw:Q,text:Q}]}}}url(J){let $;if($=this.rules.inline.url.exec(J)){let Q,Z;if($[2]==="@")Q=$[0],Z="mailto:"+Q;else{let Y;do Y=$[0],$[0]=this.rules.inline._backpedal.exec($[0])?.[0]??"";while(Y!==$[0]);Q=$[0],$[1]==="www."?Z="http://"+$[0]:Z=$[0]}return{type:"link",raw:$[0],text:Q,href:Z,tokens:[{type:"text",raw:Q,text:Q}]}}}inlineText(J){let $=this.rules.inline.text.exec(J);if($){let Q=this.lexer.state.inRawBlock;return{type:"text",raw:$[0],text:$[0],escaped:Q}}}},_1=class J{tokens;options;state;inlineQueue;tokenizer;constructor($){this.tokens=[],this.tokens.links=Object.create(null),this.options=$||R1,this.options.tokenizer=this.options.tokenizer||new U0,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};let Q={other:J1,block:_0.normal,inline:a1.normal};this.options.pedantic?(Q.block=_0.pedantic,Q.inline=a1.pedantic):this.options.gfm&&(Q.block=_0.gfm,this.options.breaks?Q.inline=a1.breaks:Q.inline=a1.gfm),this.tokenizer.rules=Q}static get rules(){return{block:_0,inline:a1}}static lex($,Q){return new J(Q).lex($)}static lexInline($,Q){return new J(Q).inlineTokens($)}lex($){$=$.replace(J1.carriageReturn,`
61
27
  `),this.blockTokens($,this.tokens);for(let Q=0;Q<this.inlineQueue.length;Q++){let Z=this.inlineQueue[Q];this.inlineTokens(Z.src,Z.tokens)}return this.inlineQueue=[],this.tokens}blockTokens($,Q=[],Z=!1){for(this.options.pedantic&&($=$.replace(J1.tabCharGlobal," ").replace(J1.spaceLine,""));$;){let Y;if(this.options.extensions?.block?.some((q)=>(Y=q.call({lexer:this},$,Q))?($=$.substring(Y.raw.length),Q.push(Y),!0):!1))continue;if(Y=this.tokenizer.space($)){$=$.substring(Y.raw.length);let q=Q.at(-1);Y.raw.length===1&&q!==void 0?q.raw+=`
62
28
  `:Q.push(Y);continue}if(Y=this.tokenizer.code($)){$=$.substring(Y.raw.length);let q=Q.at(-1);q?.type==="paragraph"||q?.type==="text"?(q.raw+=(q.raw.endsWith(`
63
29
  `)?"":`
@@ -71,9 +37,9 @@ ${U}`:U;let H=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTo
71
37
  `+Y.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=q.text):Q.push(Y),Z=X.length!==$.length,$=$.substring(Y.raw.length);continue}if(Y=this.tokenizer.text($)){$=$.substring(Y.raw.length);let q=Q.at(-1);q?.type==="text"?(q.raw+=(q.raw.endsWith(`
72
38
  `)?"":`
73
39
  `)+Y.raw,q.text+=`
74
- `+Y.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=q.text):Q.push(Y);continue}if($){let q="Infinite loop on byte: "+$.charCodeAt(0);if(this.options.silent){console.error(q);break}else throw Error(q)}}return this.state.top=!0,Q}inline($,Q=[]){return this.inlineQueue.push({src:$,tokens:Q}),Q}inlineTokens($,Q=[]){let Z=$,Y=null;if(this.tokens.links){let z=Object.keys(this.tokens.links);if(z.length>0)for(;(Y=this.tokenizer.rules.inline.reflinkSearch.exec(Z))!=null;)z.includes(Y[0].slice(Y[0].lastIndexOf("[")+1,-1))&&(Z=Z.slice(0,Y.index)+"["+"a".repeat(Y[0].length-2)+"]"+Z.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(Y=this.tokenizer.rules.inline.anyPunctuation.exec(Z))!=null;)Z=Z.slice(0,Y.index)+"++"+Z.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);let X;for(;(Y=this.tokenizer.rules.inline.blockSkip.exec(Z))!=null;)X=Y[2]?Y[2].length:0,Z=Z.slice(0,Y.index+X)+"["+"a".repeat(Y[0].length-X-2)+"]"+Z.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);Z=this.options.hooks?.emStrongMask?.call({lexer:this},Z)??Z;let q=!1,_="";for(;$;){q||(_=""),q=!1;let z;if(this.options.extensions?.inline?.some((U)=>(z=U.call({lexer:this},$,Q))?($=$.substring(z.raw.length),Q.push(z),!0):!1))continue;if(z=this.tokenizer.escape($)){$=$.substring(z.raw.length),Q.push(z);continue}if(z=this.tokenizer.tag($)){$=$.substring(z.raw.length),Q.push(z);continue}if(z=this.tokenizer.link($)){$=$.substring(z.raw.length),Q.push(z);continue}if(z=this.tokenizer.reflink($,this.tokens.links)){$=$.substring(z.raw.length);let U=Q.at(-1);z.type==="text"&&U?.type==="text"?(U.raw+=z.raw,U.text+=z.text):Q.push(z);continue}if(z=this.tokenizer.emStrong($,Z,_)){$=$.substring(z.raw.length),Q.push(z);continue}if(z=this.tokenizer.codespan($)){$=$.substring(z.raw.length),Q.push(z);continue}if(z=this.tokenizer.br($)){$=$.substring(z.raw.length),Q.push(z);continue}if(z=this.tokenizer.del($,Z,_)){$=$.substring(z.raw.length),Q.push(z);continue}if(z=this.tokenizer.autolink($)){$=$.substring(z.raw.length),Q.push(z);continue}if(!this.state.inLink&&(z=this.tokenizer.url($))){$=$.substring(z.raw.length),Q.push(z);continue}let K=$;if(this.options.extensions?.startInline){let U=1/0,H=$.slice(1),G;this.options.extensions.startInline.forEach((N)=>{G=N.call({lexer:this},H),typeof G=="number"&&G>=0&&(U=Math.min(U,G))}),U<1/0&&U>=0&&(K=$.substring(0,U+1))}if(z=this.tokenizer.inlineText(K)){$=$.substring(z.raw.length),z.raw.slice(-1)!=="_"&&(_=z.raw.slice(-1)),q=!0;let U=Q.at(-1);U?.type==="text"?(U.raw+=z.raw,U.text+=z.text):Q.push(z);continue}if($){let U="Infinite loop on byte: "+$.charCodeAt(0);if(this.options.silent){console.error(U);break}else throw Error(U)}}return Q}},y0=class{options;parser;constructor(J){this.options=J||m1}space(J){return""}code({text:J,lang:$,escaped:Q}){let Z=($||"").match(J1.notSpaceStart)?.[0],Y=J.replace(J1.endingNewline,"")+`
75
- `;return Z?'<pre><code class="language-'+H1(Z)+'">'+(Q?Y:H1(Y,!0))+`</code></pre>
76
- `:"<pre><code>"+(Q?Y:H1(Y,!0))+`</code></pre>
40
+ `+Y.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=q.text):Q.push(Y);continue}if($){let q="Infinite loop on byte: "+$.charCodeAt(0);if(this.options.silent){console.error(q);break}else throw Error(q)}}return this.state.top=!0,Q}inline($,Q=[]){return this.inlineQueue.push({src:$,tokens:Q}),Q}inlineTokens($,Q=[]){let Z=$,Y=null;if(this.tokens.links){let z=Object.keys(this.tokens.links);if(z.length>0)for(;(Y=this.tokenizer.rules.inline.reflinkSearch.exec(Z))!=null;)z.includes(Y[0].slice(Y[0].lastIndexOf("[")+1,-1))&&(Z=Z.slice(0,Y.index)+"["+"a".repeat(Y[0].length-2)+"]"+Z.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(Y=this.tokenizer.rules.inline.anyPunctuation.exec(Z))!=null;)Z=Z.slice(0,Y.index)+"++"+Z.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);let X;for(;(Y=this.tokenizer.rules.inline.blockSkip.exec(Z))!=null;)X=Y[2]?Y[2].length:0,Z=Z.slice(0,Y.index+X)+"["+"a".repeat(Y[0].length-X-2)+"]"+Z.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);Z=this.options.hooks?.emStrongMask?.call({lexer:this},Z)??Z;let q=!1,_="";for(;$;){q||(_=""),q=!1;let z;if(this.options.extensions?.inline?.some((U)=>(z=U.call({lexer:this},$,Q))?($=$.substring(z.raw.length),Q.push(z),!0):!1))continue;if(z=this.tokenizer.escape($)){$=$.substring(z.raw.length),Q.push(z);continue}if(z=this.tokenizer.tag($)){$=$.substring(z.raw.length),Q.push(z);continue}if(z=this.tokenizer.link($)){$=$.substring(z.raw.length),Q.push(z);continue}if(z=this.tokenizer.reflink($,this.tokens.links)){$=$.substring(z.raw.length);let U=Q.at(-1);z.type==="text"&&U?.type==="text"?(U.raw+=z.raw,U.text+=z.text):Q.push(z);continue}if(z=this.tokenizer.emStrong($,Z,_)){$=$.substring(z.raw.length),Q.push(z);continue}if(z=this.tokenizer.codespan($)){$=$.substring(z.raw.length),Q.push(z);continue}if(z=this.tokenizer.br($)){$=$.substring(z.raw.length),Q.push(z);continue}if(z=this.tokenizer.del($,Z,_)){$=$.substring(z.raw.length),Q.push(z);continue}if(z=this.tokenizer.autolink($)){$=$.substring(z.raw.length),Q.push(z);continue}if(!this.state.inLink&&(z=this.tokenizer.url($))){$=$.substring(z.raw.length),Q.push(z);continue}let K=$;if(this.options.extensions?.startInline){let U=1/0,H=$.slice(1),G;this.options.extensions.startInline.forEach((N)=>{G=N.call({lexer:this},H),typeof G=="number"&&G>=0&&(U=Math.min(U,G))}),U<1/0&&U>=0&&(K=$.substring(0,U+1))}if(z=this.tokenizer.inlineText(K)){$=$.substring(z.raw.length),z.raw.slice(-1)!=="_"&&(_=z.raw.slice(-1)),q=!0;let U=Q.at(-1);U?.type==="text"?(U.raw+=z.raw,U.text+=z.text):Q.push(z);continue}if($){let U="Infinite loop on byte: "+$.charCodeAt(0);if(this.options.silent){console.error(U);break}else throw Error(U)}}return Q}},G0=class{options;parser;constructor(J){this.options=J||R1}space(J){return""}code({text:J,lang:$,escaped:Q}){let Z=($||"").match(J1.notSpaceStart)?.[0],Y=J.replace(J1.endingNewline,"")+`
41
+ `;return Z?'<pre><code class="language-'+G1(Z)+'">'+(Q?Y:G1(Y,!0))+`</code></pre>
42
+ `:"<pre><code>"+(Q?Y:G1(Y,!0))+`</code></pre>
77
43
  `}blockquote({tokens:J}){return`<blockquote>
78
44
  ${this.parser.parse(J)}</blockquote>
79
45
  `}html({text:J}){return J}def(J){return""}heading({tokens:J,depth:$}){return`<h${$}>${this.parser.parseInline(J)}</h${$}>
@@ -89,27 +55,61 @@ ${this.parser.parse(J)}</blockquote>
89
55
  `}tablerow({text:J}){return`<tr>
90
56
  ${J}</tr>
91
57
  `}tablecell(J){let $=this.parser.parseInline(J.tokens),Q=J.header?"th":"td";return(J.align?`<${Q} align="${J.align}">`:`<${Q}>`)+$+`</${Q}>
92
- `}strong({tokens:J}){return`<strong>${this.parser.parseInline(J)}</strong>`}em({tokens:J}){return`<em>${this.parser.parseInline(J)}</em>`}codespan({text:J}){return`<code>${H1(J,!0)}</code>`}br(J){return"<br>"}del({tokens:J}){return`<del>${this.parser.parseInline(J)}</del>`}link({href:J,title:$,tokens:Q}){let Z=this.parser.parseInline(Q),Y=b5(J);if(Y===null)return Z;J=Y;let X='<a href="'+J+'"';return $&&(X+=' title="'+H1($)+'"'),X+=">"+Z+"</a>",X}image({href:J,title:$,text:Q,tokens:Z}){Z&&(Q=this.parser.parseInline(Z,this.parser.textRenderer));let Y=b5(J);if(Y===null)return H1(Q);J=Y;let X=`<img src="${J}" alt="${H1(Q)}"`;return $&&(X+=` title="${H1($)}"`),X+=">",X}text(J){return"tokens"in J&&J.tokens?this.parser.parseInline(J.tokens):("escaped"in J)&&J.escaped?J.text:H1(J.text)}},l0=class{strong({text:J}){return J}em({text:J}){return J}codespan({text:J}){return J}del({text:J}){return J}html({text:J}){return J}text({text:J}){return J}link({text:J}){return""+J}image({text:J}){return""+J}br(){return""}checkbox({raw:J}){return J}},U1=class J{options;renderer;textRenderer;constructor($){this.options=$||m1,this.options.renderer=this.options.renderer||new y0,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new l0}static parse($,Q){return new J(Q).parse($)}static parseInline($,Q){return new J(Q).parseInline($)}parse($){let Q="";for(let Z=0;Z<$.length;Z++){let Y=$[Z];if(this.options.extensions?.renderers?.[Y.type]){let q=Y,_=this.options.extensions.renderers[q.type].call({parser:this},q);if(_!==!1||!["space","hr","heading","code","table","blockquote","list","html","def","paragraph","text"].includes(q.type)){Q+=_||"";continue}}let X=Y;switch(X.type){case"space":{Q+=this.renderer.space(X);break}case"hr":{Q+=this.renderer.hr(X);break}case"heading":{Q+=this.renderer.heading(X);break}case"code":{Q+=this.renderer.code(X);break}case"table":{Q+=this.renderer.table(X);break}case"blockquote":{Q+=this.renderer.blockquote(X);break}case"list":{Q+=this.renderer.list(X);break}case"checkbox":{Q+=this.renderer.checkbox(X);break}case"html":{Q+=this.renderer.html(X);break}case"def":{Q+=this.renderer.def(X);break}case"paragraph":{Q+=this.renderer.paragraph(X);break}case"text":{Q+=this.renderer.text(X);break}default:{let q='Token with "'+X.type+'" type was not found.';if(this.options.silent)return console.error(q),"";throw Error(q)}}}return Q}parseInline($,Q=this.renderer){let Z="";for(let Y=0;Y<$.length;Y++){let X=$[Y];if(this.options.extensions?.renderers?.[X.type]){let _=this.options.extensions.renderers[X.type].call({parser:this},X);if(_!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(X.type)){Z+=_||"";continue}}let q=X;switch(q.type){case"escape":{Z+=Q.text(q);break}case"html":{Z+=Q.html(q);break}case"link":{Z+=Q.link(q);break}case"image":{Z+=Q.image(q);break}case"checkbox":{Z+=Q.checkbox(q);break}case"strong":{Z+=Q.strong(q);break}case"em":{Z+=Q.em(q);break}case"codespan":{Z+=Q.codespan(q);break}case"br":{Z+=Q.br(q);break}case"del":{Z+=Q.del(q);break}case"text":{Z+=Q.text(q);break}default:{let _='Token with "'+q.type+'" type was not found.';if(this.options.silent)return console.error(_),"";throw Error(_)}}}return Z}},Y0=class{options;block;constructor(J){this.options=J||m1}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens","emStrongMask"]);static passThroughHooksRespectAsync=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(J){return J}postprocess(J){return J}processAllTokens(J){return J}emStrongMask(J){return J}provideLexer(){return this.block?K1.lex:K1.lexInline}provideParser(){return this.block?U1.parse:U1.parseInline}},w3=class{defaults=v0();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=U1;Renderer=y0;TextRenderer=l0;Lexer=K1;Tokenizer=F0;Hooks=Y0;constructor(...J){this.use(...J)}walkTokens(J,$){let Q=[];for(let Z of J)switch(Q=Q.concat($.call(this,Z)),Z.type){case"table":{let Y=Z;for(let X of Y.header)Q=Q.concat(this.walkTokens(X.tokens,$));for(let X of Y.rows)for(let q of X)Q=Q.concat(this.walkTokens(q.tokens,$));break}case"list":{let Y=Z;Q=Q.concat(this.walkTokens(Y.items,$));break}default:{let Y=Z;this.defaults.extensions?.childTokens?.[Y.type]?this.defaults.extensions.childTokens[Y.type].forEach((X)=>{let q=Y[X].flat(1/0);Q=Q.concat(this.walkTokens(q,$))}):Y.tokens&&(Q=Q.concat(this.walkTokens(Y.tokens,$)))}}return Q}use(...J){let $=this.defaults.extensions||{renderers:{},childTokens:{}};return J.forEach((Q)=>{let Z={...Q};if(Z.async=this.defaults.async||Z.async||!1,Q.extensions&&(Q.extensions.forEach((Y)=>{if(!Y.name)throw Error("extension name required");if("renderer"in Y){let X=$.renderers[Y.name];X?$.renderers[Y.name]=function(...q){let _=Y.renderer.apply(this,q);return _===!1&&(_=X.apply(this,q)),_}:$.renderers[Y.name]=Y.renderer}if("tokenizer"in Y){if(!Y.level||Y.level!=="block"&&Y.level!=="inline")throw Error("extension level must be 'block' or 'inline'");let X=$[Y.level];X?X.unshift(Y.tokenizer):$[Y.level]=[Y.tokenizer],Y.start&&(Y.level==="block"?$.startBlock?$.startBlock.push(Y.start):$.startBlock=[Y.start]:Y.level==="inline"&&($.startInline?$.startInline.push(Y.start):$.startInline=[Y.start]))}"childTokens"in Y&&Y.childTokens&&($.childTokens[Y.name]=Y.childTokens)}),Z.extensions=$),Q.renderer){let Y=this.defaults.renderer||new y0(this.defaults);for(let X in Q.renderer){if(!(X in Y))throw Error(`renderer '${X}' does not exist`);if(["options","parser"].includes(X))continue;let q=X,_=Q.renderer[q],z=Y[q];Y[q]=(...K)=>{let U=_.apply(Y,K);return U===!1&&(U=z.apply(Y,K)),U||""}}Z.renderer=Y}if(Q.tokenizer){let Y=this.defaults.tokenizer||new F0(this.defaults);for(let X in Q.tokenizer){if(!(X in Y))throw Error(`tokenizer '${X}' does not exist`);if(["options","rules","lexer"].includes(X))continue;let q=X,_=Q.tokenizer[q],z=Y[q];Y[q]=(...K)=>{let U=_.apply(Y,K);return U===!1&&(U=z.apply(Y,K)),U}}Z.tokenizer=Y}if(Q.hooks){let Y=this.defaults.hooks||new Y0;for(let X in Q.hooks){if(!(X in Y))throw Error(`hook '${X}' does not exist`);if(["options","block"].includes(X))continue;let q=X,_=Q.hooks[q],z=Y[q];Y0.passThroughHooks.has(X)?Y[q]=(K)=>{if(this.defaults.async&&Y0.passThroughHooksRespectAsync.has(X))return(async()=>{let H=await _.call(Y,K);return z.call(Y,H)})();let U=_.call(Y,K);return z.call(Y,U)}:Y[q]=(...K)=>{if(this.defaults.async)return(async()=>{let H=await _.apply(Y,K);return H===!1&&(H=await z.apply(Y,K)),H})();let U=_.apply(Y,K);return U===!1&&(U=z.apply(Y,K)),U}}Z.hooks=Y}if(Q.walkTokens){let Y=this.defaults.walkTokens,X=Q.walkTokens;Z.walkTokens=function(q){let _=[];return _.push(X.call(this,q)),Y&&(_=_.concat(Y.call(this,q))),_}}this.defaults={...this.defaults,...Z}}),this}setOptions(J){return this.defaults={...this.defaults,...J},this}lexer(J,$){return K1.lex(J,$??this.defaults)}parser(J,$){return U1.parse(J,$??this.defaults)}parseMarkdown(J){return($,Q)=>{let Z={...Q},Y={...this.defaults,...Z},X=this.onError(!!Y.silent,!!Y.async);if(this.defaults.async===!0&&Z.async===!1)return X(Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(typeof $>"u"||$===null)return X(Error("marked(): input parameter is undefined or null"));if(typeof $!="string")return X(Error("marked(): input parameter is of type "+Object.prototype.toString.call($)+", string expected"));if(Y.hooks&&(Y.hooks.options=Y,Y.hooks.block=J),Y.async)return(async()=>{let q=Y.hooks?await Y.hooks.preprocess($):$,_=await(Y.hooks?await Y.hooks.provideLexer():J?K1.lex:K1.lexInline)(q,Y),z=Y.hooks?await Y.hooks.processAllTokens(_):_;Y.walkTokens&&await Promise.all(this.walkTokens(z,Y.walkTokens));let K=await(Y.hooks?await Y.hooks.provideParser():J?U1.parse:U1.parseInline)(z,Y);return Y.hooks?await Y.hooks.postprocess(K):K})().catch(X);try{Y.hooks&&($=Y.hooks.preprocess($));let q=(Y.hooks?Y.hooks.provideLexer():J?K1.lex:K1.lexInline)($,Y);Y.hooks&&(q=Y.hooks.processAllTokens(q)),Y.walkTokens&&this.walkTokens(q,Y.walkTokens);let _=(Y.hooks?Y.hooks.provideParser():J?U1.parse:U1.parseInline)(q,Y);return Y.hooks&&(_=Y.hooks.postprocess(_)),_}catch(q){return X(q)}}}onError(J,$){return(Q)=>{if(Q.message+=`
93
- Please report this to https://github.com/markedjs/marked.`,J){let Z="<p>An error occurred:</p><pre>"+H1(Q.message+"",!0)+"</pre>";return $?Promise.resolve(Z):Z}if($)return Promise.reject(Q);throw Q}}},C1=new w3;function x(J,$){return C1.parse(J,$)}x.options=x.setOptions=function(J){return C1.setOptions(J),x.defaults=C1.defaults,R5(x.defaults),x};x.getDefaults=v0;x.defaults=m1;x.use=function(...J){return C1.use(...J),x.defaults=C1.defaults,R5(x.defaults),x};x.walkTokens=function(J,$){return C1.walkTokens(J,$)};x.parseInline=C1.parseInline;x.Parser=U1;x.parser=U1.parse;x.Renderer=y0;x.TextRenderer=l0;x.Lexer=K1;x.lexer=K1.lex;x.Tokenizer=F0;x.Hooks=Y0;x.parse=x;var{options:G4,setOptions:H4,use:N4,walkTokens:W4,parseInline:T4}=x;var O4=U1.parse,F4=K1.lex;import{jsxDEV as s}from"react/jsx-dev-runtime";function E5({open:J,onClose:$,onSubmit:Q}){let{annotations:Z,generalNote:Y,responses:X,feedbackEntries:q}=q1(),[_,z]=L0(""),[K,U]=L0(!1),[H,G]=L0(!1),[N,W]=L0(null),M=R3(null);if(a0(()=>{if(!J){U(!1),G(!1),W(null);return}if(K)return;z(e1(Z,Y,X,q))},[Z,Y,X,q,K,J]),a0(()=>{if(J&&H&&M.current)M.current.focus()},[J,H]),a0(()=>{if(!J)return;let B=(y)=>{if(y.key==="Escape")$()};return window.addEventListener("keydown",B),()=>window.removeEventListener("keydown",B)},[J,$]),!J)return null;let F=_.trim().length>0;return s("div",{className:"fixed inset-0 z-50 bg-black/50 backdrop-blur-sm flex items-center justify-center p-8",onClick:$,children:s("div",{className:"bg-bg-surface border border-border-medium rounded-xl shadow-lg w-full max-w-2xl flex flex-col",style:{height:"80vh"},onClick:(B)=>B.stopPropagation(),children:[s("div",{className:"flex items-center justify-between px-5 py-3 border-b border-border-subtle flex-shrink-0",children:[s("div",{className:"flex items-center gap-3",children:[s("span",{className:"text-[13px] font-medium text-text-primary font-body",children:"Response preview"},void 0,!1,void 0,this),K&&s("button",{onClick:()=>{U(!1),G(!1)},className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body",children:"Reset"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),s("div",{className:"flex items-center gap-2",children:[s("div",{className:"flex items-center bg-bg-base rounded-md p-0.5",children:[s("button",{onClick:()=>G(!1),className:`px-2.5 py-1 rounded text-[11px] font-body font-medium transition-colors ${!H?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Preview"},void 0,!1,void 0,this),s("button",{onClick:()=>G(!0),className:`px-2.5 py-1 rounded text-[11px] font-body font-medium transition-colors ${H?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Edit"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),s("button",{onClick:$,className:"text-text-tertiary hover:text-text-secondary w-7 h-7 flex items-center justify-center rounded-md hover:bg-border-subtle transition-colors",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),H?s("textarea",{ref:M,value:_,onChange:(B)=>{z(B.target.value),U(!0)},className:"flex-1 w-full bg-bg-base p-5 text-[13px] font-mono text-text-code resize-none focus:outline-none leading-relaxed placeholder:text-text-disabled",placeholder:"Your feedback will appear here..."},void 0,!1,void 0,this):s("div",{className:"flex-1 overflow-y-auto p-5",children:s(P0,{text:_},void 0,!1,void 0,this)},void 0,!1,void 0,this),N&&s("div",{className:"px-5 py-2 text-[12px] text-accent-red font-body border-t border-border-subtle flex-shrink-0 flex items-center justify-between gap-2",children:[s("span",{children:N},void 0,!1,void 0,this),s("button",{onClick:()=>{W(null),Q(_)},className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body whitespace-nowrap underline",children:"Submit anyway"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),s("div",{className:"flex justify-end gap-2 px-5 py-3 border-t border-border-subtle flex-shrink-0",children:[s("button",{onClick:$,className:"px-4 py-2 rounded-lg text-[13px] font-body text-text-tertiary hover:text-text-secondary transition-colors",children:"Cancel"},void 0,!1,void 0,this),s("button",{onClick:()=>{let B=W0(X,q);if(B.length>0){W(`Please answer: ${B.join(", ")}`);return}W(null),Q(_)},disabled:!F,className:`px-6 py-2 rounded-lg font-body text-[13px] font-medium transition-all ${F?"bg-btn-primary text-btn-primary-text hover:opacity-90":"bg-bg-input text-text-disabled cursor-default"}`,children:"Submit feedback"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function P0({text:J}){let $=C3(()=>x.parse(J,{async:!1}),[J]);return s("div",{className:"prose-canvas font-body text-body text-text-primary leading-relaxed",dangerouslySetInnerHTML:{__html:$}},void 0,!1,void 0,this)}import{jsxDEV as j1}from"react/jsx-dev-runtime";var m3={ts:"#3178c6",tsx:"#3178c6",js:"#e8a32e",jsx:"#4ba0c8",html:"#e34c26",css:"#264de4",scss:"#c69",json:"#7a7568",yaml:"#cb171e",yml:"#cb171e",toml:"#9c4221",rs:"#dea584",go:"#00add8",c:"#6a6a6a",cpp:"#f34b7d",h:"#6a6a6a",py:"#3572a5",rb:"#cc342d",sh:"#5a8c3c",bash:"#5a8c3c",md:"#3573b5",txt:"#6b6560",lock:"#6b6560",gitignore:"#6b6560",svg:"#d9952e",png:"#6a9c2e",jpg:"#6a9c2e",gif:"#6a9c2e"},j3={ts:"TS",tsx:"TX",js:"JS",jsx:"JX",py:"PY",rs:"RS",go:"GO",rb:"RB",json:"{}",yaml:"YM",yml:"YM",toml:"TM",html:"<>",css:"#",scss:"#",md:"M↓",sh:"$",bash:"$",c:"C",cpp:"C+",h:"H",svg:"◇",png:"▣",jpg:"▣"};function E1({name:J,type:$,expanded:Q,className:Z=""}){if($==="dir")return j1("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",className:`flex-shrink-0 ${Z}`,children:Q?j1("path",{d:"M1.5 3.5h5l1.5 1.5h6.5v8h-13z",style:{fill:"var(--color-folder-fill-active)",stroke:"var(--color-folder-stroke-active)"},strokeWidth:"1"},void 0,!1,void 0,this):j1("path",{d:"M1.5 3.5h5l1.5 1.5h6.5v8h-13z",style:{fill:"var(--color-folder-fill)",stroke:"var(--color-folder-stroke)"},strokeWidth:"1"},void 0,!1,void 0,this)},void 0,!1,void 0,this);let Y=J.includes(".")?J.split(".").pop().toLowerCase():"",X=m3[Y]||"#6b6560",q=j3[Y];return j1("svg",{width:"14",height:"14",viewBox:"0 0 16 16",className:`flex-shrink-0 ${Z}`,children:[j1("path",{d:"M2 1.5h8l3.5 3.5v9.5a1 1 0 01-1 1H3a1 1 0 01-1-1v-12a1 1 0 011-1z",fill:X,opacity:"0.85"},void 0,!1,void 0,this),j1("path",{d:"M10 1.5v2.5a1 1 0 001 1h2.5",fill:"none",stroke:"white",strokeWidth:"0.5",opacity:"0.5"},void 0,!1,void 0,this),q&&j1("text",{x:"8",y:"11.5",textAnchor:"middle",fill:"white",fontSize:"5.5",fontFamily:"monospace",fontWeight:"600",children:q},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{jsxDEV as P,Fragment as v3}from"react/jsx-dev-runtime";function s0({onPreview:J,onSubmit:$,collapseButton:Q}){let{isReadOnly:Z,selectedRevision:Y,currentRevision:X,revisions:q}=i0(h1),_=i0(V3),z=Z&&Y===X,U=q.find((H)=>H.revision===Y)?.label||`Round ${Y}`;if(Z)return P(D3,{sessionId:_,revision:Y,label:U,waitingForUpdate:z,collapseButton:Q},void 0,!1,void 0,this);return P(u3,{onPreview:J,onSubmit:$,collapseButton:Q},void 0,!1,void 0,this)}function g3({sessionId:J,revision:$,label:Q,waitingForUpdate:Z,collapseButton:Y}){let[X,q]=x1(null),[_,z]=x1(!0);return o0(()=>{z(!0),fetch(`/api/session/${J}/revision/${$}/feedback`).then((K)=>K.json()).then((K)=>{q(K.feedback||null),z(!1)}).catch(()=>{q(null),z(!1)})},[J,$]),P("div",{className:"flex flex-col h-full",children:[P("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[P("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:Z?"Feedback sent":`Feedback — ${Q}`},void 0,!1,void 0,this),Y]},void 0,!0,void 0,this),Z&&P("div",{className:"mx-4 mb-3 px-3 py-2.5 rounded-lg bg-accent-green-muted flex items-center gap-2 flex-shrink-0",children:[P("span",{className:"w-2 h-2 rounded-full bg-accent-green animate-pulse"},void 0,!1,void 0,this),P("span",{className:"text-[12px] font-body text-accent-green",children:"Waiting for next revision..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),P("div",{className:"flex-1 overflow-y-auto px-4",children:_?P("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"Loading..."},void 0,!1,void 0,this):X?P(P0,{text:X},void 0,!1,void 0,this):P("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"No feedback was submitted for this revision."},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function D3({sessionId:J,revision:$,label:Q,waitingForUpdate:Z,collapseButton:Y}){let{annotations:X,generalNote:q,activeAnnotationId:_,setActiveAnnotationId:z}=q1(),{setActiveView:K}=i0(I1),U=X.length>0||q.trim().length>0,[H,G]=x1("feedback");if(!U)return P(g3,{sessionId:J,revision:$,label:Q,waitingForUpdate:Z,collapseButton:Y},void 0,!1,void 0,this);return P("div",{className:"flex flex-col h-full",children:[P("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[P("div",{className:"flex items-center gap-1 bg-bg-input rounded-md p-0.5",children:[P("button",{onClick:()=>G("feedback"),className:`px-2.5 py-1 rounded text-[11px] font-medium font-body transition-colors ${H==="feedback"?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Feedback"},void 0,!1,void 0,this),P("button",{onClick:()=>G("annotations"),className:`px-2.5 py-1 rounded text-[11px] font-medium font-body transition-colors flex items-center gap-1.5 ${H==="annotations"?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:["Annotations",P("span",{className:"inline-flex items-center justify-center min-w-[16px] h-[16px] px-1 rounded-full bg-border-subtle text-[10px] font-medium",children:X.length},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Y]},void 0,!0,void 0,this),Z&&P("div",{className:"mx-4 mb-3 px-3 py-2.5 rounded-lg bg-accent-green-muted flex items-center gap-2 flex-shrink-0",children:[P("span",{className:"w-2 h-2 rounded-full bg-accent-green animate-pulse"},void 0,!1,void 0,this),P("span",{className:"text-[12px] font-body text-accent-green",children:"Waiting for next revision..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),H==="feedback"?P(f3,{sessionId:J,revision:$},void 0,!1,void 0,this):P(k3,{annotations:X,generalNote:q,activeAnnotationId:_,setActiveAnnotationId:z,setActiveView:K},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function f3({sessionId:J,revision:$}){let[Q,Z]=x1(null),[Y,X]=x1(!0);return o0(()=>{X(!0),fetch(`/api/session/${J}/revision/${$}/feedback`).then((q)=>q.json()).then((q)=>{Z(q.feedback||null),X(!1)}).catch(()=>{Z(null),X(!1)})},[J,$]),P("div",{className:"flex-1 overflow-y-auto px-4",children:Y?P("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"Loading..."},void 0,!1,void 0,this):Q?P(P0,{text:Q},void 0,!1,void 0,this):P("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"No feedback was submitted for this revision."},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function k3({annotations:J,generalNote:$,activeAnnotationId:Q,setActiveAnnotationId:Z,setActiveView:Y}){let X=J.filter((G)=>!G.filePath),q=J.filter((G)=>G.filePath),_={};for(let G of q){let N=G.filePath;if(!_[N])_[N]=[];_[N].push(G)}let z=(G)=>{Z(G),A1(G,!0);let N=document.querySelector(`[data-annotation-id="${G}"]`);if(N)N.scrollIntoView({behavior:"smooth",block:"nearest"})},K=(G)=>{Z(null),A1(G,!1)},U=(G)=>{if(G.id===Q)Z(null);else if(Z(G.id),G.filePath)Y({type:"file",path:G.filePath}),setTimeout(()=>{let N=document.querySelector(`[data-annotation-id="${G.id}"]`);if(N)N.scrollIntoView({behavior:"smooth",block:"center"})},150)},H=(G)=>P("div",{className:`relative px-3 py-2.5 transition-colors duration-150 cursor-pointer ${Q===G.id?"bg-highlight-selected":"odd:bg-bg-elevated-half hover:bg-bg-input"}`,onMouseEnter:()=>z(G.id),onMouseLeave:()=>K(G.id),onClick:()=>U(G),children:[P("div",{className:"text-[11px] text-text-tertiary italic line-clamp-2 mb-1.5 leading-snug font-body border-l-2 border-border-medium pl-2",children:G.snippet.length>80?G.snippet.slice(0,80)+"...":G.snippet},void 0,!1,void 0,this),G.note.trim()&&P("div",{className:"text-[13px] font-body text-text-primary leading-relaxed",children:G.note},void 0,!1,void 0,this)]},G.id,!0,void 0,this);return P(v3,{children:[P("div",{className:"flex-1 overflow-y-auto",children:[X.length>0&&q.length>0&&P("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body px-3 mb-1 mt-1",children:"Plan"},void 0,!1,void 0,this),X.map(H),Object.entries(_).map(([G,N])=>P("div",{children:[P("button",{onClick:()=>Y({type:"file",path:G}),className:"flex items-center gap-1.5 text-[10px] uppercase tracking-widest text-text-tertiary hover:text-text-secondary font-body px-3 pt-3 pb-1 truncate transition-colors w-full text-left",title:G,children:[P(E1,{name:G.split("/").pop()||G,type:"file"},void 0,!1,void 0,this),P("span",{className:"truncate",children:G},void 0,!1,void 0,this)]},void 0,!0,void 0,this),N.map(H)]},G,!0,void 0,this))]},void 0,!0,void 0,this),$.trim()&&P("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:P("div",{className:"text-[13px] font-body text-text-primary leading-relaxed",children:$},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function u3({onPreview:J,onSubmit:$,collapseButton:Q}){let{annotations:Z,updateAnnotation:Y,removeAnnotation:X,generalNote:q,setGeneralNote:_,activeAnnotationId:z,setActiveAnnotationId:K,responses:U,feedbackEntries:H}=q1(),{setActiveView:G}=I3.useContext(I1),N=x5(null),W=x5(new Map),M=Z.filter((T)=>!T.filePath),F=Z.filter((T)=>T.filePath),B={};for(let T of F){let L=T.filePath;if(!B[L])B[L]=[];B[L].push(T)}o0(()=>{if(!z)return;let T=W.current.get(z);if(T)T.scrollIntoView({behavior:"smooth",block:"nearest"})},[z]);let y=h5((T)=>{K(T),A1(T,!0);let L=document.querySelector(`[data-annotation-id="${T}"]`);if(L)L.scrollIntoView({behavior:"smooth",block:"nearest"})},[K]),S=h5((T)=>{K(null),A1(T,!1)},[z]),R=Array.from(U.values()).some(k0),m=H.size>0,k=Z.length>0||q.trim().length>0||R||m,[V,w]=x1(null),I=(T)=>P("div",{ref:(L)=>{if(L)W.current.set(T.id,L);else W.current.delete(T.id)},className:`group/ann relative px-3 py-2.5 transition-colors duration-150 ${z===T.id?"bg-highlight-selected":"odd:bg-bg-elevated-half hover:bg-bg-input"}`,onMouseEnter:()=>y(T.id),onMouseLeave:()=>S(T.id),onClick:()=>{if(T.id===z)K(null);else if(K(T.id),T.filePath)G({type:"file",path:T.filePath}),setTimeout(()=>{let L=document.querySelector(`[data-annotation-id="${T.id}"]`);if(L)L.scrollIntoView({behavior:"smooth",block:"center"})},150)},children:[P("div",{className:"text-[11px] text-text-tertiary italic line-clamp-2 mb-1.5 leading-snug font-body border-l-2 border-border-medium pl-2",children:T.snippet.length>80?T.snippet.slice(0,80)+"...":T.snippet},void 0,!1,void 0,this),P("textarea",{value:T.note,onChange:(L)=>Y(T.id,L.target.value),onClick:(L)=>L.stopPropagation(),className:"w-full bg-transparent text-[13px] font-body text-text-primary resize-none focus:outline-none leading-relaxed p-0 border-none min-h-[20px]",rows:1,style:{height:"auto",overflow:"hidden"},onInput:(L)=>a1(L.target),ref:(L)=>{if(L)a1(L)}},void 0,!1,void 0,this),P("div",{className:"absolute top-1.5 right-1.5 opacity-0 group-hover/ann:opacity-100 transition-opacity duration-100",children:P("button",{onClick:(L)=>{L.stopPropagation(),X(T.id)},className:"w-5 h-5 flex items-center justify-center rounded text-text-tertiary hover:text-accent-red hover:bg-accent-red-muted transition-colors",title:"Delete annotation",children:P("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[P("polyline",{points:"3 6 5 6 21 6"},void 0,!1,void 0,this),P("path",{d:"M19 6v14a2 2 0 01-2 2H7a2 2 0 01-2-2V6m3 0V4a2 2 0 012-2h4a2 2 0 012 2v2"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},T.id,!0,void 0,this);return P("div",{className:"flex flex-col h-full",children:[P("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[P("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body flex items-center gap-2",children:["Annotations",Z.length>0&&P("span",{className:"inline-flex items-center justify-center min-w-[18px] h-[18px] px-1 rounded-full bg-border-subtle text-[10px] font-medium text-text-secondary",children:Z.length},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Q]},void 0,!0,void 0,this),P("div",{ref:N,className:"flex-1 overflow-y-auto",children:[Z.length===0&&P("p",{className:"text-[12px] text-text-tertiary px-3 py-4 leading-relaxed font-body",children:"Select text in the plan or in files to add annotations."},void 0,!1,void 0,this),M.length>0&&F.length>0&&P("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body px-3 mb-1 mt-1",children:"Plan"},void 0,!1,void 0,this),M.map(I),Object.entries(B).map(([T,L])=>P("div",{children:[P("button",{onClick:()=>G({type:"file",path:T}),className:"flex items-center gap-1.5 text-[10px] uppercase tracking-widest text-text-tertiary hover:text-text-secondary font-body px-3 pt-3 pb-1 truncate transition-colors w-full text-left",title:T,children:[P(E1,{name:T.split("/").pop()||T,type:"file"},void 0,!1,void 0,this),P("span",{className:"truncate",children:T},void 0,!1,void 0,this)]},void 0,!0,void 0,this),L.map(I)]},T,!0,void 0,this))]},void 0,!0,void 0,this),P("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:P("textarea",{value:q,onChange:(T)=>_(T.target.value),className:"w-full bg-transparent text-[13px] font-body text-text-primary resize-none leading-relaxed p-0 border-none ring-0 shadow-none outline-none focus:outline-none focus:ring-0 focus:border-none placeholder:text-text-disabled min-h-[40px]",placeholder:"General notes...",onInput:(T)=>a1(T.target,40),ref:(T)=>{if(T)a1(T,40)}},void 0,!1,void 0,this)},void 0,!1,void 0,this),V&&P("div",{className:"px-4 py-2 text-[12px] text-accent-red font-body border-t border-border-subtle flex-shrink-0 flex items-center justify-between gap-2",children:[P("span",{children:V},void 0,!1,void 0,this),P("button",{onClick:()=>{w(null);let T=e1(Z,q,U,H);$(T)},className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body whitespace-nowrap underline",children:"Submit anyway"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),P("div",{className:"px-4 py-3 border-t border-border-subtle flex-shrink-0",children:k?P("div",{className:"flex gap-2",children:[P("button",{onClick:J,className:"flex-1 py-2 rounded-lg font-body text-[13px] font-medium transition-all bg-border-subtle text-text-secondary hover:bg-border-medium hover:text-text-primary",children:"Preview"},void 0,!1,void 0,this),P("button",{onClick:()=>{let T=W0(U,H);if(T.length>0){w(`Please answer: ${T.join(", ")}`);return}w(null);let L=e1(Z,q,U,H);$(L)},className:"flex-1 py-2 rounded-lg font-body text-[13px] font-medium transition-all bg-btn-primary text-btn-primary-text hover:opacity-90 hover:-translate-y-px shadow-sm",children:"Submit"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):P("button",{onClick:()=>$("No feedback — looks good."),className:"w-full py-2 rounded-lg font-body text-[13px] font-medium border border-border-medium text-text-secondary hover:text-text-primary hover:border-border-hover hover:bg-bg-input transition-all",children:"Submit without feedback"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{useEffect as E3,useState as p5,useContext as c5,useMemo as x3}from"react";import{SessionContext as h3}from"#canvas/runtime";import{jsxDEV as f,Fragment as t0}from"react/jsx-dev-runtime";function d5({embedded:J}={}){let $=c5(h3),{annotations:Q,addAnnotation:Z}=q1(),{setActiveView:Y}=c5(I1),[X,q]=p5(!1),[_,z]=p5({}),{annCountMap:K,annotatedFiles:U}=x3(()=>{let y=new Map;for(let S of Q)if(S.filePath)y.set(S.filePath,(y.get(S.filePath)||0)+1);return{annCountMap:y,annotatedFiles:[...y.keys()]}},[Q]),H=async(y)=>{let R=await(await fetch(`/api/tree?session=${$}&path=${encodeURIComponent(y)}`)).json();if(R.entries)z((m)=>({...m,[y]:{entries:R.entries,expanded:!0,loaded:!0}}))};E3(()=>{if(!X&&!_[""])H("")},[X]);let G=(y)=>{if(_[y]?.loaded)z((S)=>({...S,[y]:{...S[y],expanded:!S[y].expanded}}));else H(y)},N=(y)=>{Y({type:"file",path:y})},W=async(y)=>{let R=await(await fetch(`/api/file?session=${$}&path=${encodeURIComponent(y)}`)).json();if(!R.error){let m=R.content.split(`
58
+ `}strong({tokens:J}){return`<strong>${this.parser.parseInline(J)}</strong>`}em({tokens:J}){return`<em>${this.parser.parseInline(J)}</em>`}codespan({text:J}){return`<code>${G1(J,!0)}</code>`}br(J){return"<br>"}del({tokens:J}){return`<del>${this.parser.parseInline(J)}</del>`}link({href:J,title:$,tokens:Q}){let Z=this.parser.parseInline(Q),Y=z5(J);if(Y===null)return Z;J=Y;let X='<a href="'+J+'"';return $&&(X+=' title="'+G1($)+'"'),X+=">"+Z+"</a>",X}image({href:J,title:$,text:Q,tokens:Z}){Z&&(Q=this.parser.parseInline(Z,this.parser.textRenderer));let Y=z5(J);if(Y===null)return G1(Q);J=Y;let X=`<img src="${J}" alt="${G1(Q)}"`;return $&&(X+=` title="${G1($)}"`),X+=">",X}text(J){return"tokens"in J&&J.tokens?this.parser.parseInline(J.tokens):("escaped"in J)&&J.escaped?J.text:G1(J.text)}},E0=class{strong({text:J}){return J}em({text:J}){return J}codespan({text:J}){return J}del({text:J}){return J}html({text:J}){return J}text({text:J}){return J}link({text:J}){return""+J}image({text:J}){return""+J}br(){return""}checkbox({raw:J}){return J}},K1=class J{options;renderer;textRenderer;constructor($){this.options=$||R1,this.options.renderer=this.options.renderer||new G0,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new E0}static parse($,Q){return new J(Q).parse($)}static parseInline($,Q){return new J(Q).parseInline($)}parse($){let Q="";for(let Z=0;Z<$.length;Z++){let Y=$[Z];if(this.options.extensions?.renderers?.[Y.type]){let q=Y,_=this.options.extensions.renderers[q.type].call({parser:this},q);if(_!==!1||!["space","hr","heading","code","table","blockquote","list","html","def","paragraph","text"].includes(q.type)){Q+=_||"";continue}}let X=Y;switch(X.type){case"space":{Q+=this.renderer.space(X);break}case"hr":{Q+=this.renderer.hr(X);break}case"heading":{Q+=this.renderer.heading(X);break}case"code":{Q+=this.renderer.code(X);break}case"table":{Q+=this.renderer.table(X);break}case"blockquote":{Q+=this.renderer.blockquote(X);break}case"list":{Q+=this.renderer.list(X);break}case"checkbox":{Q+=this.renderer.checkbox(X);break}case"html":{Q+=this.renderer.html(X);break}case"def":{Q+=this.renderer.def(X);break}case"paragraph":{Q+=this.renderer.paragraph(X);break}case"text":{Q+=this.renderer.text(X);break}default:{let q='Token with "'+X.type+'" type was not found.';if(this.options.silent)return console.error(q),"";throw Error(q)}}}return Q}parseInline($,Q=this.renderer){let Z="";for(let Y=0;Y<$.length;Y++){let X=$[Y];if(this.options.extensions?.renderers?.[X.type]){let _=this.options.extensions.renderers[X.type].call({parser:this},X);if(_!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(X.type)){Z+=_||"";continue}}let q=X;switch(q.type){case"escape":{Z+=Q.text(q);break}case"html":{Z+=Q.html(q);break}case"link":{Z+=Q.link(q);break}case"image":{Z+=Q.image(q);break}case"checkbox":{Z+=Q.checkbox(q);break}case"strong":{Z+=Q.strong(q);break}case"em":{Z+=Q.em(q);break}case"codespan":{Z+=Q.codespan(q);break}case"br":{Z+=Q.br(q);break}case"del":{Z+=Q.del(q);break}case"text":{Z+=Q.text(q);break}default:{let _='Token with "'+q.type+'" type was not found.';if(this.options.silent)return console.error(_),"";throw Error(_)}}}return Z}},o1=class{options;block;constructor(J){this.options=J||R1}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens","emStrongMask"]);static passThroughHooksRespectAsync=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(J){return J}postprocess(J){return J}processAllTokens(J){return J}emStrongMask(J){return J}provideLexer(){return this.block?_1.lex:_1.lexInline}provideParser(){return this.block?K1.parse:K1.parseInline}},X3=class{defaults=I0();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=K1;Renderer=G0;TextRenderer=E0;Lexer=_1;Tokenizer=U0;Hooks=o1;constructor(...J){this.use(...J)}walkTokens(J,$){let Q=[];for(let Z of J)switch(Q=Q.concat($.call(this,Z)),Z.type){case"table":{let Y=Z;for(let X of Y.header)Q=Q.concat(this.walkTokens(X.tokens,$));for(let X of Y.rows)for(let q of X)Q=Q.concat(this.walkTokens(q.tokens,$));break}case"list":{let Y=Z;Q=Q.concat(this.walkTokens(Y.items,$));break}default:{let Y=Z;this.defaults.extensions?.childTokens?.[Y.type]?this.defaults.extensions.childTokens[Y.type].forEach((X)=>{let q=Y[X].flat(1/0);Q=Q.concat(this.walkTokens(q,$))}):Y.tokens&&(Q=Q.concat(this.walkTokens(Y.tokens,$)))}}return Q}use(...J){let $=this.defaults.extensions||{renderers:{},childTokens:{}};return J.forEach((Q)=>{let Z={...Q};if(Z.async=this.defaults.async||Z.async||!1,Q.extensions&&(Q.extensions.forEach((Y)=>{if(!Y.name)throw Error("extension name required");if("renderer"in Y){let X=$.renderers[Y.name];X?$.renderers[Y.name]=function(...q){let _=Y.renderer.apply(this,q);return _===!1&&(_=X.apply(this,q)),_}:$.renderers[Y.name]=Y.renderer}if("tokenizer"in Y){if(!Y.level||Y.level!=="block"&&Y.level!=="inline")throw Error("extension level must be 'block' or 'inline'");let X=$[Y.level];X?X.unshift(Y.tokenizer):$[Y.level]=[Y.tokenizer],Y.start&&(Y.level==="block"?$.startBlock?$.startBlock.push(Y.start):$.startBlock=[Y.start]:Y.level==="inline"&&($.startInline?$.startInline.push(Y.start):$.startInline=[Y.start]))}"childTokens"in Y&&Y.childTokens&&($.childTokens[Y.name]=Y.childTokens)}),Z.extensions=$),Q.renderer){let Y=this.defaults.renderer||new G0(this.defaults);for(let X in Q.renderer){if(!(X in Y))throw Error(`renderer '${X}' does not exist`);if(["options","parser"].includes(X))continue;let q=X,_=Q.renderer[q],z=Y[q];Y[q]=(...K)=>{let U=_.apply(Y,K);return U===!1&&(U=z.apply(Y,K)),U||""}}Z.renderer=Y}if(Q.tokenizer){let Y=this.defaults.tokenizer||new U0(this.defaults);for(let X in Q.tokenizer){if(!(X in Y))throw Error(`tokenizer '${X}' does not exist`);if(["options","rules","lexer"].includes(X))continue;let q=X,_=Q.tokenizer[q],z=Y[q];Y[q]=(...K)=>{let U=_.apply(Y,K);return U===!1&&(U=z.apply(Y,K)),U}}Z.tokenizer=Y}if(Q.hooks){let Y=this.defaults.hooks||new o1;for(let X in Q.hooks){if(!(X in Y))throw Error(`hook '${X}' does not exist`);if(["options","block"].includes(X))continue;let q=X,_=Q.hooks[q],z=Y[q];o1.passThroughHooks.has(X)?Y[q]=(K)=>{if(this.defaults.async&&o1.passThroughHooksRespectAsync.has(X))return(async()=>{let H=await _.call(Y,K);return z.call(Y,H)})();let U=_.call(Y,K);return z.call(Y,U)}:Y[q]=(...K)=>{if(this.defaults.async)return(async()=>{let H=await _.apply(Y,K);return H===!1&&(H=await z.apply(Y,K)),H})();let U=_.apply(Y,K);return U===!1&&(U=z.apply(Y,K)),U}}Z.hooks=Y}if(Q.walkTokens){let Y=this.defaults.walkTokens,X=Q.walkTokens;Z.walkTokens=function(q){let _=[];return _.push(X.call(this,q)),Y&&(_=_.concat(Y.call(this,q))),_}}this.defaults={...this.defaults,...Z}}),this}setOptions(J){return this.defaults={...this.defaults,...J},this}lexer(J,$){return _1.lex(J,$??this.defaults)}parser(J,$){return K1.parse(J,$??this.defaults)}parseMarkdown(J){return($,Q)=>{let Z={...Q},Y={...this.defaults,...Z},X=this.onError(!!Y.silent,!!Y.async);if(this.defaults.async===!0&&Z.async===!1)return X(Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(typeof $>"u"||$===null)return X(Error("marked(): input parameter is undefined or null"));if(typeof $!="string")return X(Error("marked(): input parameter is of type "+Object.prototype.toString.call($)+", string expected"));if(Y.hooks&&(Y.hooks.options=Y,Y.hooks.block=J),Y.async)return(async()=>{let q=Y.hooks?await Y.hooks.preprocess($):$,_=await(Y.hooks?await Y.hooks.provideLexer():J?_1.lex:_1.lexInline)(q,Y),z=Y.hooks?await Y.hooks.processAllTokens(_):_;Y.walkTokens&&await Promise.all(this.walkTokens(z,Y.walkTokens));let K=await(Y.hooks?await Y.hooks.provideParser():J?K1.parse:K1.parseInline)(z,Y);return Y.hooks?await Y.hooks.postprocess(K):K})().catch(X);try{Y.hooks&&($=Y.hooks.preprocess($));let q=(Y.hooks?Y.hooks.provideLexer():J?_1.lex:_1.lexInline)($,Y);Y.hooks&&(q=Y.hooks.processAllTokens(q)),Y.walkTokens&&this.walkTokens(q,Y.walkTokens);let _=(Y.hooks?Y.hooks.provideParser():J?K1.parse:K1.parseInline)(q,Y);return Y.hooks&&(_=Y.hooks.postprocess(_)),_}catch(q){return X(q)}}}onError(J,$){return(Q)=>{if(Q.message+=`
59
+ Please report this to https://github.com/markedjs/marked.`,J){let Z="<p>An error occurred:</p><pre>"+G1(Q.message+"",!0)+"</pre>";return $?Promise.resolve(Z):Z}if($)return Promise.reject(Q);throw Q}}},w1=new X3;function E(J,$){return w1.parse(J,$)}E.options=E.setOptions=function(J){return w1.setOptions(J),E.defaults=w1.defaults,U5(E.defaults),E};E.getDefaults=I0;E.defaults=R1;E.use=function(...J){return w1.use(...J),E.defaults=w1.defaults,U5(E.defaults),E};E.walkTokens=function(J,$){return w1.walkTokens(J,$)};E.parseInline=w1.parseInline;E.Parser=K1;E.parser=K1.parse;E.Renderer=G0;E.TextRenderer=E0;E.Lexer=_1;E.lexer=_1.lex;E.Tokenizer=U0;E.Hooks=o1;E.parse=E;var{options:v$,setOptions:E$,use:x$,walkTokens:h$,parseInline:p$}=E;var c$=K1.parse,d$=_1.lex;import{SessionContext as T2,ActiveViewCtx as V$}from"#canvas/runtime";import{useState as n1,useCallback as y1,useEffect as P5,useRef as S5}from"react";import{AnnotationCtx as z3}from"#canvas/runtime";function H1(){return`ann-${Date.now()}-${Math.random().toString(36).slice(2,6)}`}function t1(J,$){J.style.height="auto",J.style.height=($?Math.max($,J.scrollHeight):J.scrollHeight)+"px"}import{useAnnotations as q1}from"#canvas/runtime";import{jsxDEV as G3}from"react/jsx-dev-runtime";function x0(J,$){return`canvas:${J}:rev:${$}`}function e1(J,$){try{let Q=localStorage.getItem(x0(J,$));if(!Q)return null;return JSON.parse(Q)}catch{return null}}function _3(J,$,Q){try{localStorage.setItem(x0(J,$),JSON.stringify(Q))}catch{}}function K3(J,$){try{localStorage.removeItem(x0(J,$))}catch{}}function b5({sessionId:J,revision:$,isReadOnly:Q,children:Z}){let Y=S5(`${J}:${$}`),[X,q]=n1(()=>{return e1(J,$)?.annotations??[]}),[_,z]=n1(()=>{return e1(J,$)?.generalNote??""}),[K,U]=n1(null),[H,G]=n1(()=>{let w=e1(J,$);return w?.responses?new Map(w.responses):new Map}),[N,W]=n1(()=>{let w=e1(J,$);return w?.feedbackEntries?new Map(w.feedbackEntries):new Map});P5(()=>{let w=`${J}:${$}`;if(w===Y.current)return;Y.current=w;let I=e1(J,$);q(I?.annotations??[]),z(I?.generalNote??""),G(I?.responses?new Map(I.responses):new Map),W(I?.feedbackEntries?new Map(I.feedbackEntries):new Map),U(null)},[J,$]);let M=S5(null);P5(()=>{if(Q)return;if(M.current)clearTimeout(M.current);return M.current=setTimeout(()=>{_3(J,$,{annotations:X,generalNote:_,responses:Array.from(H.entries()),feedbackEntries:Array.from(N.entries())})},300),()=>{if(M.current)clearTimeout(M.current)}},[X,_,H,N,J,$,Q]);let F=y1((w,I,T,B,c)=>{q((o)=>[...o,{id:w,snippet:I,note:T,createdAt:new Date().toISOString(),filePath:B,context:c}])},[]),L=y1((w,I,T)=>{F(H1(),w,I,T)},[F]),y=y1((w,I)=>{q((T)=>T.map((B)=>B.id===w?{...B,note:I}:B))},[]),S=y1((w)=>{U3(w),q((I)=>I.filter((T)=>T.id!==w)),U((I)=>I===w?null:I)},[]),R=y1((w,I)=>{G((T)=>{let B=new Map(T);return B.set(w,I),B})},[]),m=y1((w,I)=>{W((T)=>{let B=T.get(w);if(B&&B.markdown===I.markdown&&B.label===I.label&&B.required===I.required)return T;let c=new Map(T);return c.set(w,I),c})},[]),k=y1((w)=>{W((I)=>{if(!I.has(w))return I;let T=new Map(I);return T.delete(w),T})},[]),V=y1(()=>{for(let w of document.querySelectorAll("[data-annotation-id]"))A5(w);q([]),z(""),U(null),G(new Map),W(new Map),K3(J,$)},[J,$]);return G3(z3.Provider,{value:{annotations:X,addAnnotation:L,addAnnotationWithId:F,updateAnnotation:y,removeAnnotation:S,generalNote:_,setGeneralNote:z,clearAll:V,activeAnnotationId:K,setActiveAnnotationId:U,responses:H,setResponse:R,feedbackEntries:N,setFeedbackEntry:m,removeFeedbackEntry:k},children:Z},void 0,!1,void 0,this)}function U3(J){let $=document.querySelectorAll(`[data-annotation-id="${J}"]`);for(let Q of $)A5(Q)}function A5(J){let $=J.parentNode;if(!$)return;let Q=document.createTextNode(J.textContent||"");$.replaceChild(Q,J),$.normalize()}import c0,{useEffect as U1,useState as X1,useRef as D5,useContext as O3,useCallback as F3,useMemo as B0}from"react";import{createPortal as y3}from"react-dom";import{SessionContext as M3}from"#canvas/runtime";function u1(J,$){let Q=[],Z=H3(J);for(let Y of Z){let X=document.createRange();if(X.selectNodeContents(Y),Y===J.startContainer)X.setStart(Y,J.startOffset);if(Y===J.endContainer)X.setEnd(Y,J.endOffset);let q=X.toString();if(!q||!q.trim())continue;let _=document.createElement("mark");_.setAttribute("data-annotation-id",$),_.style.cssText=`
60
+ background: var(--color-highlight-annotation);
61
+ border-bottom: 1.5px solid var(--color-highlight-bg);
62
+ border-radius: 2px;
63
+ cursor: pointer;
64
+ transition: background 150ms ease;
65
+ color: inherit;
66
+ padding: 1px 0;
67
+ `;try{X.surroundContents(_)}catch{let z=X.extractContents();_.appendChild(z),X.insertNode(_)}Q.push(_)}return Q}function H3(J){let $=[],Q=J.commonAncestorContainer;if(Q.nodeType===Node.TEXT_NODE)return $.push(Q),$;let Z=document.createTreeWalker(Q,NodeFilter.SHOW_TEXT),Y;while(Y=Z.nextNode()){if(Y.parentElement?.classList.contains("select-none"))continue;if(J.intersectsNode(Y))$.push(Y)}return $}function C1(J,$){let Q=document.querySelectorAll(`[data-annotation-id="${J}"]`);for(let Z of Q)Z.style.cssText=$?`
68
+ background: var(--color-highlight-bg);
69
+ border-bottom: 1.5px solid var(--color-highlight-border);
70
+ border-radius: 2px;
71
+ cursor: pointer;
72
+ transition: background 150ms ease;
73
+ color: inherit;
74
+ padding: 1px 0;
75
+ `:`
76
+ background: var(--color-highlight-annotation);
77
+ border-bottom: 1.5px solid var(--color-highlight-bg);
78
+ border-radius: 2px;
79
+ cursor: pointer;
80
+ transition: background 150ms ease;
81
+ color: inherit;
82
+ padding: 1px 0;
83
+ `}function W0(J,$){if($!=null&&$!==J)C1($,!1);if(J!=null)C1(J,!0)}function T0(J,$){let Q=document.querySelectorAll(`[data-annotation-id="${J}"]`);for(let Z of Q)Z.setAttribute("data-annotation-id",$)}function O0(J,$){let Q=$.filter((_)=>!document.querySelector(`[data-annotation-id="${_.id}"]`));if(!Q.length)return;let Z=[],Y="",X=document.createTreeWalker(J,NodeFilter.SHOW_TEXT),q;while(q=X.nextNode()){if(q.parentElement?.classList.contains("select-none"))continue;Z.push({node:q,start:Y.length}),Y+=q.textContent||""}for(let _ of Q){let z=_.snippet;if(!z)continue;let K=[],U=0;while(!0){let F=Y.indexOf(z,U);if(F===-1)break;K.push(F),U=F+1}if(K.length===0)continue;let H=K[0];if(K.length>1&&_.context){let F=-1;for(let L of K){let y=0;if(_.context.before){let S=Y.slice(Math.max(0,L-80),L);if(S.includes(_.context.before))y+=2;else if(_.context.before.length>10&&S.includes(_.context.before.slice(-10)))y+=1}if(_.context.after){let S=Y.slice(L+z.length,L+z.length+80);if(S.includes(_.context.after))y+=2;else if(_.context.after.length>10&&S.includes(_.context.after.slice(0,10)))y+=1}if(y>F)F=y,H=L}}let G=H,N=H+z.length,W=w5(Z,G),M=w5(Z,N);if(!W||!M)continue;try{let F=document.createRange();F.setStart(W.node,W.offset),F.setEnd(M.node,M.offset),u1(F,_.id)}catch{}}}function w5(J,$){for(let Q=J.length-1;Q>=0;Q--)if(J[Q].start<=$){let Z=$-J[Q].start,Y=J[Q].node.textContent?.length??0;if(Z<=Y)return{node:J[Q].node,offset:Z}}return null}function F0(J){let $=document.querySelectorAll(`[data-annotation-id="${J}"]`);for(let Q of $){let Z=Q.parentNode;if(!Z)continue;while(Q.firstChild)Z.insertBefore(Q.firstChild,Q);Z.removeChild(Q),Z.normalize()}}function C5(J,$){let Q=R5(J,"before",60),Z=R5(J,"after",60),Y=W3(J.startContainer,$);return{before:Q,after:Z,hierarchy:Y}}function R5(J,$,Q){let Z=N3($==="before"?J.startContainer:J.endContainer);if(!Z)return"";let Y="";if($==="before"){let X=document.createTreeWalker(Z,NodeFilter.SHOW_TEXT),q;while(q=X.nextNode()){if(q===J.startContainer){Y+=(q.textContent||"").slice(0,J.startOffset);break}if(q.parentElement?.hasAttribute("data-annotation-id"))continue;Y+=q.textContent||""}if(Y.length>Q){Y=Y.slice(-Q);let _=Y.indexOf(" ");if(_>0)Y=Y.slice(_+1)}}else{let X=document.createTreeWalker(Z,NodeFilter.SHOW_TEXT),q=!1,_;while(_=X.nextNode()){if(_===J.endContainer){Y+=(_.textContent||"").slice(J.endOffset),q=!0;continue}if(q){if(_.parentElement?.hasAttribute("data-annotation-id"))continue;Y+=_.textContent||""}}if(Y.length>Q){Y=Y.slice(0,Q);let z=Y.lastIndexOf(" ");if(z>0)Y=Y.slice(0,z)}}return Y.trim()}function N3(J){let $=new Set(["DIV","P","LI","PRE","BLOCKQUOTE","SECTION","ARTICLE"]),Q=J.parentElement;while(Q){if($.has(Q.tagName))return Q;Q=Q.parentElement}return null}function W3(J,$){let Q=[],Z=J instanceof Element?J:J.parentElement;while(Z&&Z!==$){let Y=Z.getAttribute?.("data-task-id");if(Y){let X=Z.querySelector(".font-semibold");if(X)Q.unshift(X.textContent?.trim()||Y)}if(Z.tagName==="DIV"&&Z.querySelector(":scope > button .font-heading, :scope > div .font-heading")){let X=Z.querySelector(".font-heading");if(X)Q.unshift(X.textContent?.trim()||"")}Z=Z.parentElement}return Q}function h0(J){let $=J.snippet.trim(),Q=J.context,Z=$.length<30;if(Q&&Z&&(Q.before||Q.after)){let Y=[];if(Q.before)Y.push(`...${Q.before} `);if(Y.push($),Q.after)Y.push(` ${Q.after}...`);return Y.join("")}return $}import{useEffect as y0,useRef as M0,useState as $0,useCallback as p0,useMemo as j5}from"react";import{createPortal as T3}from"react-dom";function m5(J,$){let Y=$||document.body,X=J.getBoundingClientRect(),q=Y.getBoundingClientRect(),_=Y===document.body?window.scrollY:Y.scrollTop,z=X.bottom-q.top+_+8,K=Math.max(0,Math.min(X.left-q.left,q.width-280-12));return Y.style.position="relative",{style:{position:"absolute",top:`${z}px`,left:`${K}px`},parent:Y}}import{jsxDEV as e}from"react/jsx-dev-runtime";function V5({anchorEl:J,scrollContainer:$,onClose:Q,ignoreSelector:Z,zIndex:Y="50",padding:X="12px",width:q="280px",children:_}){let z=M0(null),K=M0(Q);K.current=Q;let{style:U,parent:H}=m5(J,$);return y0(()=>{let G=setTimeout(()=>{let N=(W)=>{if(z.current&&!z.current.contains(W.target)){if(Z&&W.target.closest?.(Z))return;K.current(),document.removeEventListener("mousedown",N)}};return document.addEventListener("mousedown",N),()=>document.removeEventListener("mousedown",N)},0);return()=>clearTimeout(G)},[Z]),T3(e("div",{ref:z,style:{...U,zIndex:Y,width:q,background:"var(--color-bg-elevated)",border:"1px solid var(--color-border-hover)",borderRadius:"8px",boxShadow:"0 4px 12px var(--color-shadow)",padding:X,fontFamily:"'Inter', sans-serif"},children:_},void 0,!1,void 0,this),H)}var g5=[{label:"Clarity",items:["Unclear","Why?","Needs example","Missing context"]},{label:"Scope",items:["Overkill","Out of scope","Important","Risky"]},{label:"Action",items:["Simplify","Rethink","Expand on this","Skip this"]}],I5=g5.flatMap((J)=>J.items);function J0({anchorEl:J,scrollContainer:$,snippet:Q,truncateAt:Z=100,header:Y,onAdd:X,onCancel:q}){let[_,z]=$0(""),[K,U]=$0(null),[H,G]=$0(!1),N=M0(null);y0(()=>{N.current?.focus()},[]);let W=p0(()=>{if(_.trim())X(_.trim());else q()},[_,X,q]),M=_.trim().length>0?I5.filter((T)=>T.toLowerCase().startsWith(_.trim().toLowerCase())):I5,F=H?[]:M.length===1&&M[0].toLowerCase()===_.trim().toLowerCase()?[]:M,L=new Set(F),y=g5.map((T)=>({label:T.label,items:T.items.filter((B)=>L.has(B))})).filter((T)=>T.items.length>0),S=y.map((T)=>T.items),R=S.flat(),m=j5(()=>{if(K===null)return 0;let T=0;for(let B=0;B<S.length;B++){if(K<T+S[B].length)return B;T+=S[B].length}return 0},[K,S]),k=j5(()=>{if(K===null)return 0;let T=0;for(let B=0;B<m;B++)T+=S[B].length;return K-T},[K,m,S]),V=(T,B)=>{let c=0;for(let o=0;o<T;o++)c+=S[o].length;return c+B};y0(()=>{U(null),G(!1)},[_]);let w=p0((T)=>{z(T)},[]),I=Q.length>Z?Q.slice(0,Z)+"...":Q;return e(V5,{anchorEl:J,scrollContainer:$,onClose:q,width:"420px",children:[Y??e("div",{style:{fontSize:"11px",color:"var(--color-text-tertiary)",fontStyle:"italic",marginBottom:"8px",lineHeight:"1.4",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden"},children:["“",I,"”"]},void 0,!0,void 0,this),e("textarea",{ref:N,value:_,onChange:(T)=>z(T.target.value),onKeyDown:(T)=>{if(R.length>0&&(T.key==="ArrowDown"||T.key==="ArrowUp"||T.key==="ArrowLeft"||T.key==="ArrowRight")){if(T.preventDefault(),K===null){U(0);return}if(T.key==="ArrowDown"){let B=Math.min(k+1,S[m].length-1);U(V(m,B))}else if(T.key==="ArrowUp"){let B=Math.max(k-1,0);U(V(m,B))}else if(T.key==="ArrowRight"){let B=Math.min(m+1,S.length-1),c=Math.min(k,S[B].length-1);U(V(B,c))}else if(T.key==="ArrowLeft"){let B=Math.max(m-1,0),c=Math.min(k,S[B].length-1);U(V(B,c))}return}if(K!==null&&R.length>0){if(T.key==="Tab"){T.preventDefault(),w(R[K]);return}if(T.key==="Enter"&&!T.shiftKey){T.preventDefault(),X(R[K]);return}}if(T.key==="Enter"&&!T.shiftKey){T.preventDefault(),W();return}if(T.key==="Escape")if(R.length>0&&!H)G(!0);else q()},style:{width:"100%",minHeight:"60px",background:"transparent",border:"none",color:"var(--color-text-primary)",fontFamily:"'Inter', sans-serif",fontSize:"13px",lineHeight:"1.5",resize:"vertical",outline:"none"},placeholder:"Add your note..."},void 0,!1,void 0,this),e("div",{style:{display:"flex",justifyContent:"flex-end",gap:"8px",marginTop:"8px"},children:[e("button",{onClick:q,style:{fontSize:"11px",color:"var(--color-text-tertiary)",background:"none",border:"none",cursor:"pointer",padding:"4px 12px",fontFamily:"'Inter', sans-serif"},children:"Cancel"},void 0,!1,void 0,this),e("button",{onClick:W,style:{fontSize:"11px",fontWeight:500,padding:"4px 12px",borderRadius:"6px",background:"var(--color-highlight-bg)",color:"var(--color-text-primary)",border:"1px solid var(--color-highlight-border)",cursor:"pointer",fontFamily:"'Inter', sans-serif"},children:"Add"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),R.length>0&&e("div",{style:{marginTop:"6px",borderTop:"1px solid var(--color-border-subtle)",paddingTop:"8px",display:"flex",gap:"4px"},children:y.map((T)=>e("div",{style:{flex:1},children:[e("div",{style:{fontSize:"10px",fontWeight:600,color:"var(--color-text-disabled)",textTransform:"uppercase",letterSpacing:"0.05em",padding:"2px 6px",marginBottom:"2px",fontFamily:"'Inter', sans-serif"},children:T.label},void 0,!1,void 0,this),T.items.map((B)=>{let c=R.indexOf(B);return e("div",{onMouseDown:(o)=>{o.preventDefault(),o.stopPropagation(),w(B)},onMouseEnter:()=>U(c),style:{padding:"3px 6px",fontSize:"12px",borderRadius:"4px",fontFamily:"'Inter', sans-serif",color:c===K?"var(--color-text-primary)":"var(--color-text-secondary)",background:c===K?"var(--color-highlight-selected)":"transparent",cursor:"pointer"},children:[e("span",{style:{fontWeight:500},children:B.slice(0,_.trim().length)},void 0,!1,void 0,this),B.slice(_.trim().length)]},B,!0,void 0,this)})]},T.label,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Y0({anchorEl:J,scrollContainer:$,initialNote:Q,onUpdate:Z,onDelete:Y,onClose:X}){let[q,_]=$0(Q),z=M0(null),[K,U]=$0(!1);y0(()=>{let G=z.current;if(G)G.style.height="auto",G.style.height=G.scrollHeight+"px",G.focus(),G.setSelectionRange(G.value.length,G.value.length)},[]);let H=p0(()=>{if(!q.trim()){Y(),X();return}Z(q),X()},[q,Z,Y,X]);return e(V5,{anchorEl:J,scrollContainer:$,onClose:H,ignoreSelector:"[data-annotation-id]",zIndex:"60",padding:"10px 12px",children:[e("textarea",{ref:z,value:q,onChange:(G)=>{_(G.target.value),Z(G.target.value),G.target.style.height="auto",G.target.style.height=G.target.scrollHeight+"px"},onKeyDown:(G)=>{if(G.key==="Enter"&&!G.shiftKey)G.preventDefault(),H();if(G.key==="Escape")H()},style:{width:"100%",background:"transparent",border:"none",color:"var(--color-text-primary)",fontFamily:"'Inter', sans-serif",fontSize:"13px",lineHeight:"1.5",resize:"none",outline:"none",overflow:"hidden"}},void 0,!1,void 0,this),e("div",{style:{display:"flex",justifyContent:"flex-end",marginTop:"6px"},children:e("button",{onClick:()=>{Y(),X()},onMouseEnter:()=>U(!0),onMouseLeave:()=>U(!1),style:{fontSize:"11px",color:K?"var(--color-accent-red)":"var(--color-text-tertiary)",background:"none",border:"none",cursor:"pointer",padding:"2px 0",fontFamily:"'Inter', sans-serif"},children:"Delete"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{jsxDEV as l,Fragment as k5}from"react/jsx-dev-runtime";var r0="[data-md='item'], [data-md='section'], [data-md='table'] tbody tr, [data-md='callout'], [data-md='note'], [data-md='checklist-item'], [data-md='choice-option'], [data-md='multichoice-option'], [data-md='userinput'], [data-md='rangeinput'], [data-md='image']",d0="[data-md='item'], [data-md='section'], [data-md='table'] tbody tr, [data-md='callout'], [data-md='note'], [data-md='checklist-item'], [data-md='image']";function f5({revision:J}){let $=O3(M3),[Q,Z]=X1(null),[Y,X]=X1(null),[q,_]=X1(!0),z=D5(null),{annotations:K,addAnnotationWithId:U,removeAnnotation:H,updateAnnotation:G,activeAnnotationId:N,setActiveAnnotationId:W}=q1(),[M,F]=X1(null),[L,y]=X1(null),[S,R]=X1(null),[m,k]=X1(null),[V,w]=X1(null),[I,T]=X1(null),[B,c]=X1(!1);U1(()=>{_(!0),X(null),T(null),import(`/api/session/${$}/plan.js?rev=${J}&t=${Date.now()}`).then((b)=>{Z(()=>b.default),_(!1)}).catch((b)=>{X(b.message),_(!1)})},[$,J]),U1(()=>{if(!Q||!z.current)return;let b=setTimeout(()=>{if(z.current)O0(z.current,K)},50);return()=>clearTimeout(b)},[Q]);let o=D5(null);U1(()=>{W0(N,o.current),o.current=N},[N]),U1(()=>{let b=z.current;if(!b)return;let C=(p)=>{let u=p.target.closest("[data-annotation-id]");if(!u)return;p.stopPropagation();let r=u.getAttribute("data-annotation-id");if(r===N)y({anchorEl:u,annId:r});else W(r)},h=(p)=>{let u=p.target.closest("[data-annotation-id]");if(u){let r=u.getAttribute("data-annotation-id");W(r)}},x=(p)=>{let u=p.target.closest("[data-annotation-id]"),r=p.relatedTarget?.closest?.("[data-annotation-id]");if(u&&!r){if(!document.getElementById("ann-inline-popover"))W(null)}};return b.addEventListener("click",C),b.addEventListener("mouseover",h),b.addEventListener("mouseout",x),()=>{b.removeEventListener("click",C),b.removeEventListener("mouseover",h),b.removeEventListener("mouseout",x)}},[Q,K,N]);let Z1=B0(()=>{let b=new Map;for(let C of K)if(C.snippet.startsWith("["))b.set(C.snippet,C.id);return b},[K]);U1(()=>{let b=z.current;if(!b)return;let C=(x)=>{if(V||S||L)return;let p=x.target;if(p.closest("[data-block-comment-btn]"))return;c(!1);let u=p.closest(r0);if(u&&b.contains(u)){let A=m1(b).indexOf(u);T(A>=0?A:null)}else T(null);let r=p.closest(d0);if(r&&b.contains(r)){k(r);let d=v1(r),A=d?Z1.get(d):void 0;if(A&&A!==N)W(A)}else k(null)},h=(x)=>{if(V||S||L)return;if(x.relatedTarget?.closest("[data-block-comment-btn]"))return;k(null),W(null)};return b.addEventListener("mousemove",C),b.addEventListener("mouseleave",h),()=>{b.removeEventListener("mousemove",C),b.removeEventListener("mouseleave",h)}},[Q,V,S,L,Z1,N]),U1(()=>{let b=(C)=>{let h=C.target.tagName;if(h==="INPUT"||h==="TEXTAREA"||C.target.isContentEditable)return;if(V||S||L)return;let x=z.current;if(!x)return;if(C.key==="ArrowDown"){C.preventDefault(),c(!0);let p=m1(x);if(p.length===0)return;T((u)=>{if(u===null)return 0;return Math.min(u+1,p.length-1)})}else if(C.key==="ArrowUp"){C.preventDefault(),c(!0);let p=m1(x);if(p.length===0)return;T((u)=>{if(u===null)return p.length-1;return Math.max(u-1,0)})}else if(C.key==="a"||C.key==="A"){if(I===null||!x)return;C.preventDefault();let u=m1(x)[I];if(!u)return;let r=v1(u);if(!r)return;let d=Z1.get(r);if(d)W(d),w({anchorEl:u,snippet:r,annId:d});else w({anchorEl:u,snippet:r})}else if(C.key===" "||C.key==="Enter"){if(I===null)return;let u=m1(x)[I];if(!u)return;let r=u.getAttribute("data-md");if(r==="choice-option"||r==="multichoice-option")C.preventDefault(),u.dispatchEvent(new CustomEvent("kb-select",{bubbles:!0}));else if(r==="userinput"){C.preventDefault();let d=u.querySelector("textarea");if(d){d.focus();let A=(g)=>{if(g.key==="Escape")g.preventDefault(),d.blur(),c(!0)};d.addEventListener("keydown",A),d.addEventListener("blur",()=>d.removeEventListener("keydown",A),{once:!0})}}else if(r==="rangeinput"){C.preventDefault();let d=u.querySelector("input[type='range']");if(d){d.focus();let A=(g)=>{if(g.key==="Escape"||g.key==="ArrowUp"||g.key==="ArrowDown")g.preventDefault(),d.blur(),c(!0)};d.addEventListener("keydown",A),d.addEventListener("blur",()=>d.removeEventListener("keydown",A),{once:!0})}}}else if(C.key==="Escape")T(null),c(!1),W(null)};return document.addEventListener("keydown",b),()=>document.removeEventListener("keydown",b)},[I,V,S,L,Z1]),U1(()=>{let b=z.current;if(!b||I===null||!B)return;let h=m1(b)[I];if(!h)return;h.style.outline="2px solid var(--color-accent-blue)",h.style.outlineOffset="-2px",h.style.borderRadius="8px",h.scrollIntoView({block:"nearest",behavior:"smooth"});let x=v1(h),p=x?Z1.get(x):void 0;if(p)W(p);return()=>{h.style.outline="",h.style.outlineOffset="",h.style.borderRadius=""}},[I,B,Z1]),U1(()=>{let b=()=>P1();return document.addEventListener("mouseup",b),()=>document.removeEventListener("mouseup",b)},[]);let P1=F3(()=>{let b=window.getSelection();if(!b||b.isCollapsed||!b.toString().trim())return;if(!z.current)return;let C=b.getRangeAt(0);if(!z.current.contains(C.startContainer))return;if(C.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let h=b.toString().trim();if(h.length<2)return;let x=C.cloneRange(),p=C5(C,z.current),u=`__pending_${Date.now()}`;try{u1(x,u)}catch{}window.getSelection()?.removeAllRanges();let r=document.querySelectorAll(`[data-annotation-id="${u}"]`),d=r[r.length-1];if(!d)return;R({anchorEl:d,tempId:u,snippet:h,ctx:p})},[U]),j=B0(()=>Q?l(Q,{},void 0,!1,void 0,this):null,[Q]);if(q)return l("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-body",children:"Loading plan..."},void 0,!1,void 0,this);if(Y)return l("div",{className:"bg-accent-red-muted rounded-lg p-5",children:[l("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Compilation Error"},void 0,!1,void 0,this),l("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:Y},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(!Q)return l("div",{className:"text-text-tertiary text-center py-8 font-body text-body",children:"No plan loaded"},void 0,!1,void 0,this);let i=document.getElementById("plan-scroll-container");return l(k5,{children:[l("div",{ref:z,className:"plan-content plan-updated",children:j},void 0,!1,void 0,this),M&&l(P3,{note:M.note,onSave:(b)=>{G(M.id,b),F(null)},onCancel:()=>F(null)},void 0,!1,void 0,this),L&&(()=>{let b=K.find((C)=>C.id===L.annId);if(!b)return null;return l(Y0,{anchorEl:L.anchorEl,scrollContainer:i,initialNote:b.note,onUpdate:(C)=>G(L.annId,C),onDelete:()=>{H(L.annId),W(null)},onClose:()=>y(null)},void 0,!1,void 0,this)})(),S&&l(J0,{anchorEl:S.anchorEl,scrollContainer:i,snippet:S.snippet,truncateAt:80,onAdd:(b)=>{let C=H1();T0(S.tempId,C),U(C,S.snippet,b,void 0,S.ctx),R(null)},onCancel:()=>{F0(S.tempId),R(null)}},void 0,!1,void 0,this),l(B3,{containerRef:z,hoveredBlock:m,focusedBlockIndex:I,blockPopover:V,blockAnnotationMap:Z1,activeAnnotationId:N,onOpen:(b,C,h)=>{if(h)W(h),w({anchorEl:b,snippet:C,annId:h});else w({anchorEl:b,snippet:C})}},void 0,!1,void 0,this),V&&!V.annId&&l(J0,{anchorEl:V.anchorEl,scrollContainer:i,snippet:V.snippet,truncateAt:80,onAdd:(b)=>{let C=H1();U(C,V.snippet,b),w(null)},onCancel:()=>w(null)},void 0,!1,void 0,this),V?.annId&&(()=>{let b=K.find((C)=>C.id===V.annId);if(!b)return null;return l(Y0,{anchorEl:V.anchorEl,scrollContainer:i,initialNote:b.note,onUpdate:(C)=>G(V.annId,C),onDelete:()=>{H(V.annId),W(null),w(null)},onClose:()=>w(null)},void 0,!1,void 0,this)})()]},void 0,!0,void 0,this)}function m1(J){return Array.from(J.querySelectorAll(r0))}function v1(J){let $=J.getAttribute("data-md");if($==="item"){let Q=J.getAttribute("data-md-label");return Q?`[Item] ${Q}`:null}if($==="section"){let Q=J.getAttribute("data-md-title");return Q?`[Section] ${Q}`:null}if($==="callout"){let Q=J.getAttribute("data-md-type")||"info",Z=J.textContent?.trim().slice(0,60)||"Callout";return`[Callout:${Q}] ${Z}`}if($==="note")return`[Note] ${J.textContent?.trim().slice(0,60)||"Note"}`;if(J.tagName==="TR"){let Q=Array.from(J.querySelectorAll("td")).map((Z)=>Z.textContent?.trim()).filter(Boolean);return Q.length?`[Row] ${Q.join(" | ")}`:null}if($==="checklist-item"){let Q=J.getAttribute("data-md-label");return Q?`[Checklist] ${Q}`:null}if($==="choice-option"||$==="multichoice-option"){let Q=J.getAttribute("data-md-label");return Q?`[Option] ${Q}`:null}if($==="userinput"){let Q=J.getAttribute("data-md-label");return Q?`[Input] ${Q}`:null}if($==="rangeinput"){let Q=J.getAttribute("data-md-label");return Q?`[Range] ${Q}`:null}if($==="image"){let Q=J.getAttribute("data-md-src");return Q?`[Image] ${Q}`:null}return null}function B3({containerRef:J,hoveredBlock:$,focusedBlockIndex:Q,blockPopover:Z,blockAnnotationMap:Y,activeAnnotationId:X,onOpen:q}){let[_,z]=X1([]);U1(()=>{let N=J.current;if(!N||Y.size===0){z([]);return}let W=[];for(let M of N.querySelectorAll(d0)){let F=v1(M);if(F&&Y.has(F))W.push(M)}z(W)},[Y,J.current]);let[K,U]=X1(null);U1(()=>{if(!X||!J.current){U(null);return}for(let N of J.current.querySelectorAll(r0)){let W=v1(N);if(W&&Y.get(W)===X){U(N);return}}U(null)},[X,Y]),U1(()=>{if(!K)return;return K.style.boxShadow="inset 0 0 0 1.5px var(--color-highlight-bg)",K.style.borderRadius="8px",()=>{K.style.boxShadow="",K.style.borderRadius=""}},[K]);let H=B0(()=>{if(Q===null||!J.current)return null;let N=m1(J.current)[Q];if(!N)return null;return N.matches(d0)?N:null},[Q,J.current]),G=B0(()=>{let N=new Set(_);if($)N.add($);if(H)N.add(H);if(Z?.anchorEl)N.add(Z.anchorEl);return Array.from(N)},[_,$,H,Z]);return l(k5,{children:G.map((N)=>l(L3,{block:N,isHovered:N===$||N===H||N===Z?.anchorEl,blockAnnotationMap:Y,activeAnnotationId:X,onOpen:q},N.getAttribute("data-task-id")||N.getAttribute("data-md-title")||N.textContent?.slice(0,30)||"block",!1,void 0,this))},void 0,!1,void 0,this)}function L3({block:J,isHovered:$,blockAnnotationMap:Q,activeAnnotationId:Z,onOpen:Y}){let X=v1(J);if(!X)return null;let q=Q.get(X),_=!!q;return y3(l("button",{"data-block-comment-btn":!0,onClick:(K)=>{K.stopPropagation(),Y(K.currentTarget,X,q)},className:`absolute top-1 right-1 z-10 w-6 h-6 flex items-center justify-center rounded transition-all duration-150 ${_?q===Z?"text-accent-amber bg-accent-amber-muted":"text-accent-amber opacity-60 hover:opacity-100":$?"text-text-disabled hover:text-text-tertiary opacity-50 hover:opacity-100":"text-text-disabled opacity-0 group-hover/section:opacity-20 hover:!opacity-80"}`,title:_?"Edit annotation":"Add annotation",children:l("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:_?"currentColor":"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:l("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),J)}function P3({note:J,onSave:$,onCancel:Q}){let[Z,Y]=c0.useState(J),X=c0.useRef(null);return c0.useEffect(()=>{X.current?.focus(),X.current?.select()},[]),l("div",{className:"fixed inset-0 z-50 bg-black/40 flex items-center justify-center",onClick:Q,children:l("div",{className:"bg-bg-elevated border border-border-hover rounded-lg shadow-md p-4 w-80",onClick:(q)=>q.stopPropagation(),children:[l("div",{className:"text-tiny uppercase tracking-widest text-text-tertiary font-body mb-2",children:"Edit annotation"},void 0,!1,void 0,this),l("textarea",{ref:X,value:Z,onChange:(q)=>Y(q.target.value),className:"w-full bg-transparent border-none text-body font-body text-text-primary resize-vertical focus:outline-none min-h-[60px]",onKeyDown:(q)=>{if(q.key==="Enter"&&(q.ctrlKey||q.metaKey))$(Z.trim());if(q.key==="Escape")Q()}},void 0,!1,void 0,this),l("div",{className:"flex justify-end gap-2 mt-2",children:[l("button",{onClick:Q,className:"text-meta text-text-tertiary font-body px-3 py-1",children:"Cancel"},void 0,!1,void 0,this),l("button",{onClick:()=>$(Z.trim()),className:"text-meta font-medium font-body px-3 py-1 rounded-md bg-highlight-bg text-text-primary border border-highlight-border",children:"Save"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}import I3,{useRef as x5,useEffect as o0,useCallback as h5,useState as x1,useContext as i0}from"react";function Q0(J,$,Q,Z){let Y=[],X=J.filter((U)=>!U.filePath),q=J.filter((U)=>U.filePath),_=Q?Array.from(Q.values()).filter((U)=>l0(U)):[],z=Z?Array.from(Z.values()).filter((U)=>U.markdown.trim()):[];if(_.length>0||z.length>0){Y.push("## Responses"),Y.push("");for(let U of _)Y.push(A3(U));for(let U of z)Y.push(U.markdown.trim()),Y.push("")}if(X.length>0){Y.push("## Plan annotations"),Y.push("");let U=w3(X);Y.push(v5(U))}if(q.length>0){let U={};for(let H of q){let G=H.filePath;if(!U[G])U[G]=[];U[G].push(H)}Y.push("## File annotations"),Y.push("");for(let[H,G]of Object.entries(U)){Y.push(`### ${H}`),Y.push("");for(let N of G)Y.push(u5(N))}}if($.trim())Y.push("## General notes"),Y.push(""),Y.push($.trim()),Y.push("");return Y.join(`
84
+ `).trim()+`
85
+ `}function l0(J){if(J.note?.trim())return!0;if(J.value===null||J.value===void 0)return!1;if(J.type==="text"&&!J.value.trim())return!1;if(J.type==="checkbox"&&J.value.length===0)return!1;return!0}function S3(J){let $=[];for(let Q of J.values()){if(!Q.required)continue;if(Q.value===null||Q.value===void 0){$.push(Q);continue}if(Q.type==="text"&&!Q.value.trim()){$.push(Q);continue}if(Q.type==="checkbox"&&Q.value.length===0){$.push(Q);continue}}return $}function b3(J){let $=[];for(let Q of J.values())if(Q.required&&!Q.markdown.trim())$.push(Q);return $}function L0(J,$){let Q=S3(J),Z=b3($);return[...Q.map((Y)=>Y.label),...Z.map((Y)=>Y.label||Y.id)]}function A3(J){let $=[];switch($.push(`**${J.label}**`),J.type){case"radio":case"select":$.push(`Answer: ${J.value}`);break;case"checkbox":for(let Q of J.value)$.push(`- [x] ${Q}`);break;case"text":$.push(""),$.push(J.value.trim());break;case"range":$.push(`Answer: ${J.value}`);break}if(J.note?.trim())$.push(""),$.push(`Note: ${J.note.trim()}`);return $.push(""),$.join(`
86
+ `)}function u5(J){let $=[],Q=J.snippet.trim(),Z=J.context,Y=Z?.lineStart!=null;if(J.filePath&&Y){let X=Z.lineStart,q=Z.lineEnd??X,_=Q.split(`
87
+ `);if(Q.length<30&&X===q&&(Z.before||Z.after)){let K=h0(J);$.push(`> L${X}: ${K}`)}else if(_.length<=6)for(let K=0;K<_.length;K++)$.push(`> ${X+K} | ${_[K]}`);else{for(let K=0;K<3;K++)$.push(`> ${X+K} | ${_[K]}`);$.push(`> ... (${_.length} lines)`);for(let K=_.length-3;K<_.length;K++)$.push(`> ${X+K} | ${_[K]}`)}}else{let X=h0(J);if(Q.split(`
88
+ `).length<=3)$.push(`> ${X.split(`
89
+ `).join(`
90
+ > `)}`);else{let q=Q.split(`
91
+ `);$.push(`> ${q[0]}`),$.push(`> ... (${q.length} lines)`),$.push(`> ${q[q.length-1]}`)}}if(J.note.trim())$.push(""),$.push(J.note.trim());return $.push(""),$.join(`
92
+ `)}function w3(J){let $={label:"",annotations:[],children:new Map};for(let Q of J){let Z=Q.context?.hierarchy||[],Y=$;for(let X of Z){if(!Y.children.has(X))Y.children.set(X,{label:X,annotations:[],children:new Map});Y=Y.children.get(X)}Y.annotations.push(Q)}return $}function v5(J,$=0){let Q=[];for(let Z of J.annotations)Q.push(u5(Z));for(let[,Z]of J.children){let Y=$===0?"###":"####";Q.push(`${Y} ${Z.label}`),Q.push(""),Q.push(v5(Z,$+1))}return Q.join(`
93
+ `)}import{SessionContext as V3}from"#canvas/runtime";import{useEffect as a0,useState as P0,useRef as R3,useMemo as C3}from"react";import{jsxDEV as s}from"react/jsx-dev-runtime";function E5({open:J,onClose:$,onSubmit:Q}){let{annotations:Z,generalNote:Y,responses:X,feedbackEntries:q}=q1(),[_,z]=P0(""),[K,U]=P0(!1),[H,G]=P0(!1),[N,W]=P0(null),M=R3(null);if(a0(()=>{if(!J){U(!1),G(!1),W(null);return}if(K)return;z(Q0(Z,Y,X,q))},[Z,Y,X,q,K,J]),a0(()=>{if(J&&H&&M.current)M.current.focus()},[J,H]),a0(()=>{if(!J)return;let L=(y)=>{if(y.key==="Escape")$()};return window.addEventListener("keydown",L),()=>window.removeEventListener("keydown",L)},[J,$]),!J)return null;let F=_.trim().length>0;return s("div",{className:"fixed inset-0 z-50 bg-black/50 backdrop-blur-sm flex items-center justify-center p-8",onClick:$,children:s("div",{className:"bg-bg-surface border border-border-medium rounded-xl shadow-lg w-full max-w-2xl flex flex-col",style:{height:"80vh"},onClick:(L)=>L.stopPropagation(),children:[s("div",{className:"flex items-center justify-between px-5 py-3 border-b border-border-subtle flex-shrink-0",children:[s("div",{className:"flex items-center gap-3",children:[s("span",{className:"text-[13px] font-medium text-text-primary font-body",children:"Response preview"},void 0,!1,void 0,this),K&&s("button",{onClick:()=>{U(!1),G(!1)},className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body",children:"Reset"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),s("div",{className:"flex items-center gap-2",children:[s("div",{className:"flex items-center bg-bg-base rounded-md p-0.5",children:[s("button",{onClick:()=>G(!1),className:`px-2.5 py-1 rounded text-[11px] font-body font-medium transition-colors ${!H?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Preview"},void 0,!1,void 0,this),s("button",{onClick:()=>G(!0),className:`px-2.5 py-1 rounded text-[11px] font-body font-medium transition-colors ${H?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Edit"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),s("button",{onClick:$,className:"text-text-tertiary hover:text-text-secondary w-7 h-7 flex items-center justify-center rounded-md hover:bg-border-subtle transition-colors",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),H?s("textarea",{ref:M,value:_,onChange:(L)=>{z(L.target.value),U(!0)},className:"flex-1 w-full bg-bg-base p-5 text-[13px] font-mono text-text-code resize-none focus:outline-none leading-relaxed placeholder:text-text-disabled",placeholder:"Your feedback will appear here..."},void 0,!1,void 0,this):s("div",{className:"flex-1 overflow-y-auto p-5",children:s(S0,{text:_},void 0,!1,void 0,this)},void 0,!1,void 0,this),N&&s("div",{className:"px-5 py-2 text-[12px] text-accent-red font-body border-t border-border-subtle flex-shrink-0 flex items-center justify-between gap-2",children:[s("span",{children:N},void 0,!1,void 0,this),s("button",{onClick:()=>{W(null),Q(_)},className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body whitespace-nowrap underline",children:"Submit anyway"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),s("div",{className:"flex justify-end gap-2 px-5 py-3 border-t border-border-subtle flex-shrink-0",children:[s("button",{onClick:$,className:"px-4 py-2 rounded-lg text-[13px] font-body text-text-tertiary hover:text-text-secondary transition-colors",children:"Cancel"},void 0,!1,void 0,this),s("button",{onClick:()=>{let L=L0(X,q);if(L.length>0){W(`Please answer: ${L.join(", ")}`);return}W(null),Q(_)},disabled:!F,className:`px-6 py-2 rounded-lg font-body text-[13px] font-medium transition-all ${F?"bg-btn-primary text-btn-primary-text hover:opacity-90":"bg-bg-input text-text-disabled cursor-default"}`,children:"Submit feedback"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function S0({text:J}){let $=C3(()=>E.parse(J,{async:!1}),[J]);return s("div",{className:"prose-canvas font-body text-body text-text-primary leading-relaxed",dangerouslySetInnerHTML:{__html:$}},void 0,!1,void 0,this)}import{jsxDEV as j1}from"react/jsx-dev-runtime";var m3={ts:"#3178c6",tsx:"#3178c6",js:"#e8a32e",jsx:"#4ba0c8",html:"#e34c26",css:"#264de4",scss:"#c69",json:"#7a7568",yaml:"#cb171e",yml:"#cb171e",toml:"#9c4221",rs:"#dea584",go:"#00add8",c:"#6a6a6a",cpp:"#f34b7d",h:"#6a6a6a",py:"#3572a5",rb:"#cc342d",sh:"#5a8c3c",bash:"#5a8c3c",md:"#3573b5",txt:"#6b6560",lock:"#6b6560",gitignore:"#6b6560",svg:"#d9952e",png:"#6a9c2e",jpg:"#6a9c2e",gif:"#6a9c2e"},j3={ts:"TS",tsx:"TX",js:"JS",jsx:"JX",py:"PY",rs:"RS",go:"GO",rb:"RB",json:"{}",yaml:"YM",yml:"YM",toml:"TM",html:"<>",css:"#",scss:"#",md:"M↓",sh:"$",bash:"$",c:"C",cpp:"C+",h:"H",svg:"◇",png:"▣",jpg:"▣"};function E1({name:J,type:$,expanded:Q,className:Z=""}){if($==="dir")return j1("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",className:`flex-shrink-0 ${Z}`,children:Q?j1("path",{d:"M1.5 3.5h5l1.5 1.5h6.5v8h-13z",style:{fill:"var(--color-folder-fill-active)",stroke:"var(--color-folder-stroke-active)"},strokeWidth:"1"},void 0,!1,void 0,this):j1("path",{d:"M1.5 3.5h5l1.5 1.5h6.5v8h-13z",style:{fill:"var(--color-folder-fill)",stroke:"var(--color-folder-stroke)"},strokeWidth:"1"},void 0,!1,void 0,this)},void 0,!1,void 0,this);let Y=J.includes(".")?J.split(".").pop().toLowerCase():"",X=m3[Y]||"#6b6560",q=j3[Y];return j1("svg",{width:"14",height:"14",viewBox:"0 0 16 16",className:`flex-shrink-0 ${Z}`,children:[j1("path",{d:"M2 1.5h8l3.5 3.5v9.5a1 1 0 01-1 1H3a1 1 0 01-1-1v-12a1 1 0 011-1z",fill:X,opacity:"0.85"},void 0,!1,void 0,this),j1("path",{d:"M10 1.5v2.5a1 1 0 001 1h2.5",fill:"none",stroke:"white",strokeWidth:"0.5",opacity:"0.5"},void 0,!1,void 0,this),q&&j1("text",{x:"8",y:"11.5",textAnchor:"middle",fill:"white",fontSize:"5.5",fontFamily:"monospace",fontWeight:"600",children:q},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{jsxDEV as P,Fragment as v3}from"react/jsx-dev-runtime";function s0({onPreview:J,onSubmit:$,collapseButton:Q}){let{isReadOnly:Z,selectedRevision:Y,currentRevision:X,revisions:q}=i0(h1),_=i0(V3),z=Z&&Y===X,U=q.find((H)=>H.revision===Y)?.label||`Round ${Y}`;if(Z)return P(D3,{sessionId:_,revision:Y,label:U,waitingForUpdate:z,collapseButton:Q},void 0,!1,void 0,this);return P(u3,{onPreview:J,onSubmit:$,collapseButton:Q},void 0,!1,void 0,this)}function g3({sessionId:J,revision:$,label:Q,waitingForUpdate:Z,collapseButton:Y}){let[X,q]=x1(null),[_,z]=x1(!0);return o0(()=>{z(!0),fetch(`/api/session/${J}/revision/${$}/feedback`).then((K)=>K.json()).then((K)=>{q(K.feedback||null),z(!1)}).catch(()=>{q(null),z(!1)})},[J,$]),P("div",{className:"flex flex-col h-full",children:[P("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[P("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:Z?"Feedback sent":`Feedback — ${Q}`},void 0,!1,void 0,this),Y]},void 0,!0,void 0,this),Z&&P("div",{className:"mx-4 mb-3 px-3 py-2.5 rounded-lg bg-accent-green-muted flex items-center gap-2 flex-shrink-0",children:[P("span",{className:"w-2 h-2 rounded-full bg-accent-green animate-pulse"},void 0,!1,void 0,this),P("span",{className:"text-[12px] font-body text-accent-green",children:"Waiting for next revision..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),P("div",{className:"flex-1 overflow-y-auto px-4",children:_?P("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"Loading..."},void 0,!1,void 0,this):X?P(S0,{text:X},void 0,!1,void 0,this):P("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"No feedback was submitted for this revision."},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function D3({sessionId:J,revision:$,label:Q,waitingForUpdate:Z,collapseButton:Y}){let{annotations:X,generalNote:q,activeAnnotationId:_,setActiveAnnotationId:z}=q1(),{setActiveView:K}=i0(I1),U=X.length>0||q.trim().length>0,[H,G]=x1("feedback");if(!U)return P(g3,{sessionId:J,revision:$,label:Q,waitingForUpdate:Z,collapseButton:Y},void 0,!1,void 0,this);return P("div",{className:"flex flex-col h-full",children:[P("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[P("div",{className:"flex items-center gap-1 bg-bg-input rounded-md p-0.5",children:[P("button",{onClick:()=>G("feedback"),className:`px-2.5 py-1 rounded text-[11px] font-medium font-body transition-colors ${H==="feedback"?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Feedback"},void 0,!1,void 0,this),P("button",{onClick:()=>G("annotations"),className:`px-2.5 py-1 rounded text-[11px] font-medium font-body transition-colors flex items-center gap-1.5 ${H==="annotations"?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:["Annotations",P("span",{className:"inline-flex items-center justify-center min-w-[16px] h-[16px] px-1 rounded-full bg-border-subtle text-[10px] font-medium",children:X.length},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Y]},void 0,!0,void 0,this),Z&&P("div",{className:"mx-4 mb-3 px-3 py-2.5 rounded-lg bg-accent-green-muted flex items-center gap-2 flex-shrink-0",children:[P("span",{className:"w-2 h-2 rounded-full bg-accent-green animate-pulse"},void 0,!1,void 0,this),P("span",{className:"text-[12px] font-body text-accent-green",children:"Waiting for next revision..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),H==="feedback"?P(f3,{sessionId:J,revision:$},void 0,!1,void 0,this):P(k3,{annotations:X,generalNote:q,activeAnnotationId:_,setActiveAnnotationId:z,setActiveView:K},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function f3({sessionId:J,revision:$}){let[Q,Z]=x1(null),[Y,X]=x1(!0);return o0(()=>{X(!0),fetch(`/api/session/${J}/revision/${$}/feedback`).then((q)=>q.json()).then((q)=>{Z(q.feedback||null),X(!1)}).catch(()=>{Z(null),X(!1)})},[J,$]),P("div",{className:"flex-1 overflow-y-auto px-4",children:Y?P("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"Loading..."},void 0,!1,void 0,this):Q?P(S0,{text:Q},void 0,!1,void 0,this):P("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"No feedback was submitted for this revision."},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function k3({annotations:J,generalNote:$,activeAnnotationId:Q,setActiveAnnotationId:Z,setActiveView:Y}){let X=J.filter((G)=>!G.filePath),q=J.filter((G)=>G.filePath),_={};for(let G of q){let N=G.filePath;if(!_[N])_[N]=[];_[N].push(G)}let z=(G)=>{Z(G),C1(G,!0);let N=document.querySelector(`[data-annotation-id="${G}"]`);if(N)N.scrollIntoView({behavior:"smooth",block:"nearest"})},K=(G)=>{Z(null),C1(G,!1)},U=(G)=>{if(G.id===Q)Z(null);else if(Z(G.id),G.filePath)Y({type:"file",path:G.filePath}),setTimeout(()=>{let N=document.querySelector(`[data-annotation-id="${G.id}"]`);if(N)N.scrollIntoView({behavior:"smooth",block:"center"})},150)},H=(G)=>P("div",{className:`relative px-3 py-2.5 transition-colors duration-150 cursor-pointer ${Q===G.id?"bg-highlight-selected":"odd:bg-bg-elevated-half hover:bg-bg-input"}`,onMouseEnter:()=>z(G.id),onMouseLeave:()=>K(G.id),onClick:()=>U(G),children:[P("div",{className:"text-[11px] text-text-tertiary italic line-clamp-2 mb-1.5 leading-snug font-body border-l-2 border-border-medium pl-2",children:G.snippet.length>80?G.snippet.slice(0,80)+"...":G.snippet},void 0,!1,void 0,this),G.note.trim()&&P("div",{className:"text-[13px] font-body text-text-primary leading-relaxed",children:G.note},void 0,!1,void 0,this)]},G.id,!0,void 0,this);return P(v3,{children:[P("div",{className:"flex-1 overflow-y-auto",children:[X.length>0&&q.length>0&&P("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body px-3 mb-1 mt-1",children:"Plan"},void 0,!1,void 0,this),X.map(H),Object.entries(_).map(([G,N])=>P("div",{children:[P("button",{onClick:()=>Y({type:"file",path:G}),className:"flex items-center gap-1.5 text-[10px] uppercase tracking-widest text-text-tertiary hover:text-text-secondary font-body px-3 pt-3 pb-1 truncate transition-colors w-full text-left",title:G,children:[P(E1,{name:G.split("/").pop()||G,type:"file"},void 0,!1,void 0,this),P("span",{className:"truncate",children:G},void 0,!1,void 0,this)]},void 0,!0,void 0,this),N.map(H)]},G,!0,void 0,this))]},void 0,!0,void 0,this),$.trim()&&P("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:P("div",{className:"text-[13px] font-body text-text-primary leading-relaxed",children:$},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function u3({onPreview:J,onSubmit:$,collapseButton:Q}){let{annotations:Z,updateAnnotation:Y,removeAnnotation:X,generalNote:q,setGeneralNote:_,activeAnnotationId:z,setActiveAnnotationId:K,responses:U,feedbackEntries:H}=q1(),{setActiveView:G}=I3.useContext(I1),N=x5(null),W=x5(new Map),M=Z.filter((T)=>!T.filePath),F=Z.filter((T)=>T.filePath),L={};for(let T of F){let B=T.filePath;if(!L[B])L[B]=[];L[B].push(T)}o0(()=>{if(!z)return;let T=W.current.get(z);if(T)T.scrollIntoView({behavior:"smooth",block:"nearest"})},[z]);let y=h5((T)=>{K(T),C1(T,!0);let B=document.querySelector(`[data-annotation-id="${T}"]`);if(B)B.scrollIntoView({behavior:"smooth",block:"nearest"})},[K]),S=h5((T)=>{K(null),C1(T,!1)},[z]),R=Array.from(U.values()).some(l0),m=H.size>0,k=Z.length>0||q.trim().length>0||R||m,[V,w]=x1(null),I=(T)=>P("div",{ref:(B)=>{if(B)W.current.set(T.id,B);else W.current.delete(T.id)},className:`group/ann relative px-3 py-2.5 transition-colors duration-150 ${z===T.id?"bg-highlight-selected":"odd:bg-bg-elevated-half hover:bg-bg-input"}`,onMouseEnter:()=>y(T.id),onMouseLeave:()=>S(T.id),onClick:()=>{if(T.id===z)K(null);else if(K(T.id),T.filePath)G({type:"file",path:T.filePath}),setTimeout(()=>{let B=document.querySelector(`[data-annotation-id="${T.id}"]`);if(B)B.scrollIntoView({behavior:"smooth",block:"center"})},150)},children:[P("div",{className:"text-[11px] text-text-tertiary italic line-clamp-2 mb-1.5 leading-snug font-body border-l-2 border-border-medium pl-2",children:T.snippet.length>80?T.snippet.slice(0,80)+"...":T.snippet},void 0,!1,void 0,this),P("textarea",{value:T.note,onChange:(B)=>Y(T.id,B.target.value),onClick:(B)=>B.stopPropagation(),className:"w-full bg-transparent text-[13px] font-body text-text-primary resize-none focus:outline-none leading-relaxed p-0 border-none min-h-[20px]",rows:1,style:{height:"auto",overflow:"hidden"},onInput:(B)=>t1(B.target),ref:(B)=>{if(B)t1(B)}},void 0,!1,void 0,this),P("div",{className:"absolute top-1.5 right-1.5 opacity-0 group-hover/ann:opacity-100 transition-opacity duration-100",children:P("button",{onClick:(B)=>{B.stopPropagation(),X(T.id)},className:"w-5 h-5 flex items-center justify-center rounded text-text-tertiary hover:text-accent-red hover:bg-accent-red-muted transition-colors",title:"Delete annotation",children:P("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[P("polyline",{points:"3 6 5 6 21 6"},void 0,!1,void 0,this),P("path",{d:"M19 6v14a2 2 0 01-2 2H7a2 2 0 01-2-2V6m3 0V4a2 2 0 012-2h4a2 2 0 012 2v2"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},T.id,!0,void 0,this);return P("div",{className:"flex flex-col h-full",children:[P("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[P("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body flex items-center gap-2",children:["Annotations",Z.length>0&&P("span",{className:"inline-flex items-center justify-center min-w-[18px] h-[18px] px-1 rounded-full bg-border-subtle text-[10px] font-medium text-text-secondary",children:Z.length},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Q]},void 0,!0,void 0,this),P("div",{ref:N,className:"flex-1 overflow-y-auto",children:[Z.length===0&&P("p",{className:"text-[12px] text-text-tertiary px-3 py-4 leading-relaxed font-body",children:"Select text in the plan or in files to add annotations."},void 0,!1,void 0,this),M.length>0&&F.length>0&&P("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body px-3 mb-1 mt-1",children:"Plan"},void 0,!1,void 0,this),M.map(I),Object.entries(L).map(([T,B])=>P("div",{children:[P("button",{onClick:()=>G({type:"file",path:T}),className:"flex items-center gap-1.5 text-[10px] uppercase tracking-widest text-text-tertiary hover:text-text-secondary font-body px-3 pt-3 pb-1 truncate transition-colors w-full text-left",title:T,children:[P(E1,{name:T.split("/").pop()||T,type:"file"},void 0,!1,void 0,this),P("span",{className:"truncate",children:T},void 0,!1,void 0,this)]},void 0,!0,void 0,this),B.map(I)]},T,!0,void 0,this))]},void 0,!0,void 0,this),P("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:P("textarea",{value:q,onChange:(T)=>_(T.target.value),className:"w-full bg-transparent text-[13px] font-body text-text-primary resize-none leading-relaxed p-0 border-none ring-0 shadow-none outline-none focus:outline-none focus:ring-0 focus:border-none placeholder:text-text-disabled min-h-[40px]",placeholder:"General notes...",onInput:(T)=>t1(T.target,40),ref:(T)=>{if(T)t1(T,40)}},void 0,!1,void 0,this)},void 0,!1,void 0,this),V&&P("div",{className:"px-4 py-2 text-[12px] text-accent-red font-body border-t border-border-subtle flex-shrink-0 flex items-center justify-between gap-2",children:[P("span",{children:V},void 0,!1,void 0,this),P("button",{onClick:()=>{w(null);let T=Q0(Z,q,U,H);$(T)},className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body whitespace-nowrap underline",children:"Submit anyway"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),P("div",{className:"px-4 py-3 border-t border-border-subtle flex-shrink-0",children:k?P("div",{className:"flex gap-2",children:[P("button",{onClick:J,className:"flex-1 py-2 rounded-lg font-body text-[13px] font-medium transition-all bg-border-subtle text-text-secondary hover:bg-border-medium hover:text-text-primary",children:"Preview"},void 0,!1,void 0,this),P("button",{onClick:()=>{let T=L0(U,H);if(T.length>0){w(`Please answer: ${T.join(", ")}`);return}w(null);let B=Q0(Z,q,U,H);$(B)},className:"flex-1 py-2 rounded-lg font-body text-[13px] font-medium transition-all bg-btn-primary text-btn-primary-text hover:opacity-90 hover:-translate-y-px shadow-sm",children:"Submit"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):P("button",{onClick:()=>$("No feedback — looks good."),className:"w-full py-2 rounded-lg font-body text-[13px] font-medium border border-border-medium text-text-secondary hover:text-text-primary hover:border-border-hover hover:bg-bg-input transition-all",children:"Submit without feedback"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{useEffect as E3,useState as p5,useContext as c5,useMemo as x3}from"react";import{SessionContext as h3}from"#canvas/runtime";import{jsxDEV as f,Fragment as t0}from"react/jsx-dev-runtime";function d5({embedded:J}={}){let $=c5(h3),{annotations:Q,addAnnotation:Z}=q1(),{setActiveView:Y}=c5(I1),[X,q]=p5(!1),[_,z]=p5({}),{annCountMap:K,annotatedFiles:U}=x3(()=>{let y=new Map;for(let S of Q)if(S.filePath)y.set(S.filePath,(y.get(S.filePath)||0)+1);return{annCountMap:y,annotatedFiles:[...y.keys()]}},[Q]),H=async(y)=>{let R=await(await fetch(`/api/tree?session=${$}&path=${encodeURIComponent(y)}`)).json();if(R.entries)z((m)=>({...m,[y]:{entries:R.entries,expanded:!0,loaded:!0}}))};E3(()=>{if(!X&&!_[""])H("")},[X]);let G=(y)=>{if(_[y]?.loaded)z((S)=>({...S,[y]:{...S[y],expanded:!S[y].expanded}}));else H(y)},N=(y)=>{Y({type:"file",path:y})},W=async(y)=>{let R=await(await fetch(`/api/file?session=${$}&path=${encodeURIComponent(y)}`)).json();if(!R.error){let m=R.content.split(`
94
94
  `).slice(0,3).join(`
95
95
  `)+(R.content.split(`
96
96
  `).length>3?`
97
- ...`:"");Z(m,"Include this file for context",y)}},M=async(y)=>{let S=[];if(_[y]?.loaded)S=_[y].entries;else{let m=await(await fetch(`/api/tree?session=${$}&path=${encodeURIComponent(y)}`)).json();if(m.entries)S=m.entries}await Promise.all(S.filter((R)=>R.type==="file").map((R)=>W(y?`${y}/${R.name}`:R.name)))},F=(y)=>K.get(y)||0,B=(y,S=0)=>{let R=_[y];if(!R?.expanded)return null;return R.entries.map((m)=>{let k=y?`${y}/${m.name}`:m.name,V=F(k);return f("div",{children:[f("div",{className:"group/item flex items-center py-[3px] hover:bg-bg-elevated text-[13px] font-body cursor-default transition-colors duration-100",style:{paddingLeft:`${16+S*16}px`,paddingRight:"8px"},children:m.type==="dir"?f(t0,{children:[f("span",{onClick:()=>G(k),className:"flex items-center gap-1.5 flex-1 text-text-secondary hover:text-text-primary cursor-pointer truncate",children:[f(E1,{name:m.name,type:"dir",expanded:_[k]?.expanded},void 0,!1,void 0,this),f("span",{className:"truncate",children:m.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this),f("button",{onClick:(w)=>{w.stopPropagation(),M(k)},className:"text-[11px] text-text-tertiary hover:text-text-secondary opacity-0 group-hover/item:opacity-100 transition-opacity px-1 flex-shrink-0",title:"Add all files in folder",children:"+"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):f(t0,{children:[f("span",{onClick:()=>N(k),className:`flex-1 truncate cursor-pointer flex items-center gap-1.5 ${V>0?"text-text-primary":"text-text-secondary hover:text-text-primary"}`,children:[f(E1,{name:m.name,type:"file"},void 0,!1,void 0,this),f("span",{className:"truncate",children:m.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this),f("div",{className:"flex items-center gap-1 flex-shrink-0 ml-1",children:[V>0&&f("span",{className:"text-[10px] font-medium bg-badge-bg text-accent-amber px-1.5 py-px rounded-full min-w-[18px] text-center",children:V},void 0,!1,void 0,this),f("button",{onClick:(w)=>{w.stopPropagation(),W(k)},className:"text-[11px] text-text-tertiary hover:text-text-secondary opacity-0 group-hover/item:opacity-100 transition-opacity px-1",title:"Add file to context",children:"+"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),m.type==="dir"&&B(k,S+1)]},k,!0,void 0,this)})};if(J)return f(t0,{children:[f("div",{className:"flex items-center justify-between px-4 pt-3 pb-2 flex-shrink-0",children:f("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:"Files"},void 0,!1,void 0,this)},void 0,!1,void 0,this),f("div",{className:"flex-1 overflow-y-auto",children:B("")},void 0,!1,void 0,this),U.length>0&&f("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:[f("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body mb-1.5",children:"Referenced"},void 0,!1,void 0,this),U.map((y)=>f("div",{onClick:()=>N(y),className:"flex items-center justify-between text-[12px] font-body text-text-secondary hover:text-text-primary cursor-pointer py-0.5",children:[f("span",{className:"truncate",children:y.split("/").pop()},void 0,!1,void 0,this),f("span",{className:"text-[10px] font-medium bg-badge-bg text-accent-amber px-1.5 py-px rounded-full min-w-[18px] text-center flex-shrink-0 ml-1",children:F(y)},void 0,!1,void 0,this)]},y,!0,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);if(X)return f("div",{className:"hidden lg:flex w-8 border-r border-border-subtle bg-bg-surface flex-col items-center flex-shrink-0",children:f("button",{onClick:()=>q(!1),className:"mt-3 p-1 text-text-tertiary hover:text-text-secondary transition-colors",children:f("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:f("path",{d:"M5 3l4 4-4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this);return f("div",{className:"hidden lg:flex w-60 border-r border-border-subtle bg-bg-surface flex-col flex-shrink-0 overflow-hidden",children:[f("div",{className:"flex items-center justify-between px-4 pt-4 pb-3 flex-shrink-0",children:[f("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:"Files"},void 0,!1,void 0,this),f("button",{onClick:()=>q(!0),className:"text-text-tertiary hover:text-text-secondary transition-colors p-0.5",children:f("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:f("path",{d:"M9 3l-4 4 4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),f("div",{className:"flex-1 overflow-y-auto",children:B("")},void 0,!1,void 0,this),U.length>0&&f("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:[f("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body mb-1.5",children:"Referenced"},void 0,!1,void 0,this),U.map((y)=>f("div",{onClick:()=>N(y),className:"flex items-center justify-between text-[12px] font-body text-text-secondary hover:text-text-primary cursor-pointer py-0.5",children:[f("span",{className:"truncate",children:y.split("/").pop()},void 0,!1,void 0,this),f("span",{className:"text-[10px] font-medium bg-badge-bg text-accent-amber px-1.5 py-px rounded-full min-w-[18px] text-center flex-shrink-0 ml-1",children:F(y)},void 0,!1,void 0,this)]},y,!0,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}import{useEffect as p1,useState as T1,useContext as p3,useCallback as r5,useRef as M1,useMemo as l5}from"react";import{SessionContext as c3}from"#canvas/runtime";var S0={ts:"typescript",tsx:"typescript",js:"javascript",jsx:"javascript",py:"python",rs:"rust",go:"go",rb:"ruby",java:"java",json:"json",yaml:"yaml",yml:"yaml",md:"markdown",css:"css",html:"html",sh:"bash",bash:"bash",toml:"toml",sql:"sql",xml:"xml",c:"c",cpp:"cpp",h:"c"};import{jsxDEV as N1}from"react/jsx-dev-runtime";function a5(J){let $=J instanceof HTMLElement?J:J.parentElement;while($){if($.hasAttribute("data-line-num"))return $;$=$.parentElement}return null}function i5({path:J}){let $=p3(c3),{annotations:Q,addAnnotationWithId:Z,removeAnnotation:Y,updateAnnotation:X,activeAnnotationId:q,setActiveAnnotationId:_}=q1(),[z,K]=T1(null),[U,H]=T1("text"),[G,N]=T1(!0),[W,M]=T1(null),F=M1(null),[B,y]=T1(null),S=M1(""),[R,m]=T1(null),[k,V]=T1(null),w=M1(null),I=M1(null),T=M1([]),[L,c]=T1(null),[o,Q1]=T1(null),P1=Q.filter((A)=>A.filePath===J);p1(()=>{N(!0),M(null),fetch(`/api/file?session=${$}&path=${encodeURIComponent(J)}`).then((A)=>A.json()).then((A)=>{if(A.error)M(A.error),N(!1);else K(A.content),H(A.language||"text"),N(!1)}).catch(()=>{M("Failed to fetch file"),N(!1)})},[$,J]),p1(()=>{if(!z||!F.current)return;let A=setTimeout(()=>{if(F.current)K0(F.current,P1)},50);return()=>clearTimeout(A)},[z,J]);let j=M1(null);p1(()=>{z0(q,j.current),j.current=q},[q]),p1(()=>{let A=F.current;if(!A)return;let g=(t)=>{let $1=t.target.closest("[data-annotation-id]");if(!$1)return;t.stopPropagation();let O1=$1.getAttribute("data-annotation-id");if(O1===q)c({anchorEl:$1,annId:O1});else _(O1)},a=(t)=>{let $1=t.target.closest("[data-annotation-id]");if($1)_($1.getAttribute("data-annotation-id"))},n=(t)=>{let $1=t.target.closest("[data-annotation-id]"),O1=t.relatedTarget?.closest?.("[data-annotation-id]");if($1&&!O1&&!document.getElementById("ann-inline-popover"))_(null)};return A.addEventListener("click",g),A.addEventListener("mouseover",a),A.addEventListener("mouseout",n),()=>{A.removeEventListener("click",g),A.removeEventListener("mouseover",a),A.removeEventListener("mouseout",n)}},[z,Q,q]),p1(()=>{let A=()=>C();return document.addEventListener("mouseup",A),()=>document.removeEventListener("mouseup",A)},[]);let i=M1(J);i.current=J;let b=M1(Z);b.current=Z;let C=r5(()=>{let A=window.getSelection();if(!A||A.isCollapsed||!A.toString().trim())return;if(!F.current)return;let g=A.getRangeAt(0);if(!F.current.contains(g.startContainer))return;if(g.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let a=A.toString().trim();if(a.length<2)return;let n=a5(g.startContainer),t=a5(g.endContainer),$1=n?parseInt(n.getAttribute("data-line-num"),10):void 0,O1=t?parseInt(t.getAttribute("data-line-num"),10):void 0,D1="",f1="";if(a.length<30&&n&&n===t){let k1=n.querySelector("code");if(k1){let S1=k1.textContent||"",b1=S1.indexOf(a);if(b1>=0)D1=S1.slice(0,b1).trimStart(),f1=S1.slice(b1+a.length).trimEnd()}}let m0={before:D1,after:f1,hierarchy:[],lineStart:$1,lineEnd:O1},F1=`__pending_${Date.now()}`,X0=g.cloneRange();try{u1(X0,F1)}catch{}A.removeAllRanges();let r1=document.querySelectorAll(`[data-annotation-id="${F1}"]`),l1=r1[r1.length-1];if(!l1)return;S.current=a,y(F1),Q1({anchorEl:l1,tempId:F1,snippet:a,ctx:m0})},[]),h=r5((A,g)=>{A.preventDefault(),w.current=g,I.current=g,m(g),V(g)},[]);p1(()=>{let A=(a)=>{if(w.current===null)return;let n=a.target.closest("[data-line-num]");if(n){let t=parseInt(n.getAttribute("data-line-num"),10);I.current=t,V(t)}},g=()=>{let a=w.current;if(a===null)return;w.current=null;let n=I.current??a,t=Math.min(a,n),$1=Math.max(a,n),D1=T.current.slice(t-1,$1).join(`
98
- `);if(!D1.trim()){m(null),V(null);return}let f1=`__pending_${Date.now()}`,m0={before:"",after:"",hierarchy:[],lineStart:t,lineEnd:$1};if(F.current){let F1=F.current.querySelectorAll("[data-line-num]"),X0=F1[t-1],r1=F1[$1-1];if(X0&&r1){let k1=X0.querySelector("code"),S1=r1.querySelector("code");if(k1&&S1)try{let b1=document.createRange();b1.setStartBefore(k1.firstChild||k1),b1.setEndAfter(S1.lastChild||S1),u1(b1,f1)}catch{}}let l1=F1[$1-1];if(l1)S.current=D1,y(f1),Q1({anchorEl:l1,tempId:f1,snippet:D1,ctx:m0})}m(null),V(null)};return document.addEventListener("mousemove",A),document.addEventListener("mouseup",g),()=>{document.removeEventListener("mousemove",A),document.removeEventListener("mouseup",g)}},[]);let E=l5(()=>{if(!z)return null;let A=window.hljs;if(!A)return null;let g=J.split(".").pop()||"",a=S0[g];try{return(a?A.highlight(z,{language:a}):A.highlightAuto(z)).value.split(`
97
+ ...`:"");Z(m,"Include this file for context",y)}},M=async(y)=>{let S=[];if(_[y]?.loaded)S=_[y].entries;else{let m=await(await fetch(`/api/tree?session=${$}&path=${encodeURIComponent(y)}`)).json();if(m.entries)S=m.entries}await Promise.all(S.filter((R)=>R.type==="file").map((R)=>W(y?`${y}/${R.name}`:R.name)))},F=(y)=>K.get(y)||0,L=(y,S=0)=>{let R=_[y];if(!R?.expanded)return null;return R.entries.map((m)=>{let k=y?`${y}/${m.name}`:m.name,V=F(k);return f("div",{children:[f("div",{className:"group/item flex items-center py-[3px] hover:bg-bg-elevated text-[13px] font-body cursor-default transition-colors duration-100",style:{paddingLeft:`${16+S*16}px`,paddingRight:"8px"},children:m.type==="dir"?f(t0,{children:[f("span",{onClick:()=>G(k),className:"flex items-center gap-1.5 flex-1 text-text-secondary hover:text-text-primary cursor-pointer truncate",children:[f(E1,{name:m.name,type:"dir",expanded:_[k]?.expanded},void 0,!1,void 0,this),f("span",{className:"truncate",children:m.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this),f("button",{onClick:(w)=>{w.stopPropagation(),M(k)},className:"text-[11px] text-text-tertiary hover:text-text-secondary opacity-0 group-hover/item:opacity-100 transition-opacity px-1 flex-shrink-0",title:"Add all files in folder",children:"+"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):f(t0,{children:[f("span",{onClick:()=>N(k),className:`flex-1 truncate cursor-pointer flex items-center gap-1.5 ${V>0?"text-text-primary":"text-text-secondary hover:text-text-primary"}`,children:[f(E1,{name:m.name,type:"file"},void 0,!1,void 0,this),f("span",{className:"truncate",children:m.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this),f("div",{className:"flex items-center gap-1 flex-shrink-0 ml-1",children:[V>0&&f("span",{className:"text-[10px] font-medium bg-badge-bg text-accent-amber px-1.5 py-px rounded-full min-w-[18px] text-center",children:V},void 0,!1,void 0,this),f("button",{onClick:(w)=>{w.stopPropagation(),W(k)},className:"text-[11px] text-text-tertiary hover:text-text-secondary opacity-0 group-hover/item:opacity-100 transition-opacity px-1",title:"Add file to context",children:"+"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),m.type==="dir"&&L(k,S+1)]},k,!0,void 0,this)})};if(J)return f(t0,{children:[f("div",{className:"flex items-center justify-between px-4 pt-3 pb-2 flex-shrink-0",children:f("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:"Files"},void 0,!1,void 0,this)},void 0,!1,void 0,this),f("div",{className:"flex-1 overflow-y-auto",children:L("")},void 0,!1,void 0,this),U.length>0&&f("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:[f("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body mb-1.5",children:"Referenced"},void 0,!1,void 0,this),U.map((y)=>f("div",{onClick:()=>N(y),className:"flex items-center justify-between text-[12px] font-body text-text-secondary hover:text-text-primary cursor-pointer py-0.5",children:[f("span",{className:"truncate",children:y.split("/").pop()},void 0,!1,void 0,this),f("span",{className:"text-[10px] font-medium bg-badge-bg text-accent-amber px-1.5 py-px rounded-full min-w-[18px] text-center flex-shrink-0 ml-1",children:F(y)},void 0,!1,void 0,this)]},y,!0,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);if(X)return f("div",{className:"hidden lg:flex w-8 border-r border-border-subtle bg-bg-surface flex-col items-center flex-shrink-0",children:f("button",{onClick:()=>q(!1),className:"mt-3 p-1 text-text-tertiary hover:text-text-secondary transition-colors",children:f("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:f("path",{d:"M5 3l4 4-4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this);return f("div",{className:"hidden lg:flex w-60 border-r border-border-subtle bg-bg-surface flex-col flex-shrink-0 overflow-hidden",children:[f("div",{className:"flex items-center justify-between px-4 pt-4 pb-3 flex-shrink-0",children:[f("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:"Files"},void 0,!1,void 0,this),f("button",{onClick:()=>q(!0),className:"text-text-tertiary hover:text-text-secondary transition-colors p-0.5",children:f("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:f("path",{d:"M9 3l-4 4 4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),f("div",{className:"flex-1 overflow-y-auto",children:L("")},void 0,!1,void 0,this),U.length>0&&f("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:[f("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body mb-1.5",children:"Referenced"},void 0,!1,void 0,this),U.map((y)=>f("div",{onClick:()=>N(y),className:"flex items-center justify-between text-[12px] font-body text-text-secondary hover:text-text-primary cursor-pointer py-0.5",children:[f("span",{className:"truncate",children:y.split("/").pop()},void 0,!1,void 0,this),f("span",{className:"text-[10px] font-medium bg-badge-bg text-accent-amber px-1.5 py-px rounded-full min-w-[18px] text-center flex-shrink-0 ml-1",children:F(y)},void 0,!1,void 0,this)]},y,!0,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}import{useEffect as p1,useState as T1,useContext as p3,useCallback as r5,useRef as M1,useMemo as l5}from"react";import{SessionContext as c3}from"#canvas/runtime";var b0={ts:"typescript",tsx:"typescript",js:"javascript",jsx:"javascript",py:"python",rs:"rust",go:"go",rb:"ruby",java:"java",json:"json",yaml:"yaml",yml:"yaml",md:"markdown",css:"css",html:"html",sh:"bash",bash:"bash",toml:"toml",sql:"sql",xml:"xml",c:"c",cpp:"cpp",h:"c"};import{jsxDEV as N1}from"react/jsx-dev-runtime";function a5(J){let $=J instanceof HTMLElement?J:J.parentElement;while($){if($.hasAttribute("data-line-num"))return $;$=$.parentElement}return null}function i5({path:J}){let $=p3(c3),{annotations:Q,addAnnotationWithId:Z,removeAnnotation:Y,updateAnnotation:X,activeAnnotationId:q,setActiveAnnotationId:_}=q1(),[z,K]=T1(null),[U,H]=T1("text"),[G,N]=T1(!0),[W,M]=T1(null),F=M1(null),[L,y]=T1(null),S=M1(""),[R,m]=T1(null),[k,V]=T1(null),w=M1(null),I=M1(null),T=M1([]),[B,c]=T1(null),[o,Z1]=T1(null),P1=Q.filter((A)=>A.filePath===J);p1(()=>{N(!0),M(null),fetch(`/api/file?session=${$}&path=${encodeURIComponent(J)}`).then((A)=>A.json()).then((A)=>{if(A.error)M(A.error),N(!1);else K(A.content),H(A.language||"text"),N(!1)}).catch(()=>{M("Failed to fetch file"),N(!1)})},[$,J]),p1(()=>{if(!z||!F.current)return;let A=setTimeout(()=>{if(F.current)O0(F.current,P1)},50);return()=>clearTimeout(A)},[z,J]);let j=M1(null);p1(()=>{W0(q,j.current),j.current=q},[q]),p1(()=>{let A=F.current;if(!A)return;let g=(t)=>{let $1=t.target.closest("[data-annotation-id]");if(!$1)return;t.stopPropagation();let O1=$1.getAttribute("data-annotation-id");if(O1===q)c({anchorEl:$1,annId:O1});else _(O1)},a=(t)=>{let $1=t.target.closest("[data-annotation-id]");if($1)_($1.getAttribute("data-annotation-id"))},n=(t)=>{let $1=t.target.closest("[data-annotation-id]"),O1=t.relatedTarget?.closest?.("[data-annotation-id]");if($1&&!O1&&!document.getElementById("ann-inline-popover"))_(null)};return A.addEventListener("click",g),A.addEventListener("mouseover",a),A.addEventListener("mouseout",n),()=>{A.removeEventListener("click",g),A.removeEventListener("mouseover",a),A.removeEventListener("mouseout",n)}},[z,Q,q]),p1(()=>{let A=()=>C();return document.addEventListener("mouseup",A),()=>document.removeEventListener("mouseup",A)},[]);let i=M1(J);i.current=J;let b=M1(Z);b.current=Z;let C=r5(()=>{let A=window.getSelection();if(!A||A.isCollapsed||!A.toString().trim())return;if(!F.current)return;let g=A.getRangeAt(0);if(!F.current.contains(g.startContainer))return;if(g.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let a=A.toString().trim();if(a.length<2)return;let n=a5(g.startContainer),t=a5(g.endContainer),$1=n?parseInt(n.getAttribute("data-line-num"),10):void 0,O1=t?parseInt(t.getAttribute("data-line-num"),10):void 0,D1="",f1="";if(a.length<30&&n&&n===t){let k1=n.querySelector("code");if(k1){let S1=k1.textContent||"",b1=S1.indexOf(a);if(b1>=0)D1=S1.slice(0,b1).trimStart(),f1=S1.slice(b1+a.length).trimEnd()}}let m0={before:D1,after:f1,hierarchy:[],lineStart:$1,lineEnd:O1},F1=`__pending_${Date.now()}`,z0=g.cloneRange();try{u1(z0,F1)}catch{}A.removeAllRanges();let r1=document.querySelectorAll(`[data-annotation-id="${F1}"]`),l1=r1[r1.length-1];if(!l1)return;S.current=a,y(F1),Z1({anchorEl:l1,tempId:F1,snippet:a,ctx:m0})},[]),h=r5((A,g)=>{A.preventDefault(),w.current=g,I.current=g,m(g),V(g)},[]);p1(()=>{let A=(a)=>{if(w.current===null)return;let n=a.target.closest("[data-line-num]");if(n){let t=parseInt(n.getAttribute("data-line-num"),10);I.current=t,V(t)}},g=()=>{let a=w.current;if(a===null)return;w.current=null;let n=I.current??a,t=Math.min(a,n),$1=Math.max(a,n),D1=T.current.slice(t-1,$1).join(`
98
+ `);if(!D1.trim()){m(null),V(null);return}let f1=`__pending_${Date.now()}`,m0={before:"",after:"",hierarchy:[],lineStart:t,lineEnd:$1};if(F.current){let F1=F.current.querySelectorAll("[data-line-num]"),z0=F1[t-1],r1=F1[$1-1];if(z0&&r1){let k1=z0.querySelector("code"),S1=r1.querySelector("code");if(k1&&S1)try{let b1=document.createRange();b1.setStartBefore(k1.firstChild||k1),b1.setEndAfter(S1.lastChild||S1),u1(b1,f1)}catch{}}let l1=F1[$1-1];if(l1)S.current=D1,y(f1),Z1({anchorEl:l1,tempId:f1,snippet:D1,ctx:m0})}m(null),V(null)};return document.addEventListener("mousemove",A),document.addEventListener("mouseup",g),()=>{document.removeEventListener("mousemove",A),document.removeEventListener("mouseup",g)}},[]);let x=l5(()=>{if(!z)return null;let A=window.hljs;if(!A)return null;let g=J.split(".").pop()||"",a=b0[g];try{return(a?A.highlight(z,{language:a}):A.highlightAuto(z)).value.split(`
99
99
  `)}catch{return null}},[z,J]);if(G)return N1("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-[13px]",children:["Loading ",J,"..."]},void 0,!0,void 0,this);if(W)return N1("div",{className:"p-8 text-accent-red font-body text-[13px]",children:W},void 0,!1,void 0,this);if(!z)return null;let p=z.split(`
100
100
  `);T.current=p;let u=l5(()=>{if(R===null)return null;let A=k??R;return{start:Math.min(R,A),end:Math.max(R,A)}},[R,k]),r=()=>{let A=z.split(`
101
101
  `).slice(0,3).join(`
102
102
  `)+(p.length>3?`
103
- ...`:""),g=G1();Z(g,A,"",J),_(g)},d=F.current?.closest("#plan-scroll-container");return N1("div",{children:[N1("pre",{ref:F,className:"text-code font-mono text-text-code bg-bg-base select-text cursor-text py-3 hljs",children:p.map((A,g)=>{let a=g+1,n=u&&a>=u.start&&a<=u.end;return N1("div",{"data-line-num":a,className:`flex px-5 ${n?"bg-accent-blue/10":"hover:bg-bg-elevated-half"}`,children:[N1("span",{className:"text-text-tertiary select-none w-10 text-right pr-4 shrink-0 py-px text-[12px] cursor-pointer opacity-40 hover:opacity-100 hover:text-accent-blue",onMouseDown:(t)=>h(t,a),children:a},void 0,!1,void 0,this),E?N1("code",{className:"py-px",dangerouslySetInnerHTML:{__html:E[g]||" "}},void 0,!1,void 0,this):N1("code",{className:"py-px",children:A||" "},void 0,!1,void 0,this)]},g,!0,void 0,this)})},void 0,!1,void 0,this),L&&(()=>{let A=Q.find((g)=>g.id===L.annId);if(!A)return null;return N1(n1,{anchorEl:L.anchorEl,scrollContainer:d,initialNote:A.note,onUpdate:(g)=>X(L.annId,g),onDelete:()=>{Y(L.annId),_(null)},onClose:()=>c(null)},void 0,!1,void 0,this)})(),o&&N1(t1,{anchorEl:o.anchorEl,scrollContainer:d,snippet:o.snippet,onAdd:(A)=>{let g=G1();_0(o.tempId,g),Z(g,o.snippet,A,J,o.ctx),y(null),Q1(null)},onCancel:()=>{U0(o.tempId),y(null),Q1(null)}},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{useEffect as o5,useState as s5,useRef as d3}from"react";import{jsxDEV as W1}from"react/jsx-dev-runtime";function t5(J,$){if($){let Q=$.replace(/\/+$/,"").split("/");return Q[Q.length-1]||J}return J.length>30?J.slice(0,30)+"...":J}function n0({currentSessionId:J,projectRoot:$}){let[Q,Z]=s5([]),[Y,X]=s5(!1),q=d3(null);o5(()=>{let K=async()=>{try{let G=await(await fetch("/api/sessions")).json();Z((N)=>{let W=JSON.stringify(G);return JSON.stringify(N)===W?N:G})}catch{}};K();let U=setInterval(K,5000);return()=>clearInterval(U)},[]),o5(()=>{if(!Y)return;let K=(U)=>{if(q.current&&!q.current.contains(U.target))X(!1)};return document.addEventListener("mousedown",K),()=>document.removeEventListener("mousedown",K)},[Y]);let _=Q.filter((K)=>K.id!==J),z=t5(J,$);return W1("div",{className:"relative",ref:q,children:[W1("div",{className:"flex items-center gap-1.5 font-body text-body font-medium",children:[W1("a",{href:`/s/${J}`,className:"text-text-primary hover:text-text-secondary transition-colors",children:z},void 0,!1,void 0,this),_.length>0&&W1("button",{onClick:()=>X(!Y),className:"flex items-center justify-center text-text-tertiary hover:text-text-secondary transition-colors",children:W1("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:`transition-transform duration-200 ${Y?"rotate-180":""}`,children:W1("path",{d:"M3 5l3 3 3-3",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Y&&_.length>0&&W1("div",{className:"absolute top-full left-0 mt-2 w-64 bg-bg-elevated border border-border-hover rounded-lg shadow-lg z-50 py-1 overflow-hidden",children:_.map((K)=>W1("a",{href:`/s/${K.id}`,className:"flex items-center gap-2.5 px-4 py-2.5 text-body font-body text-text-secondary hover:bg-bg-surface hover:text-text-primary transition-colors",children:[W1("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${K.currentRevision>0?"bg-accent-green":"bg-border-hover"}`},void 0,!1,void 0,this),W1("span",{className:"truncate",children:t5(K.id,K.projectRoot)},void 0,!1,void 0,this)]},K.id,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function n5(J){let $=[];return b0(J,$,0),$.join(`
103
+ ...`:""),g=H1();Z(g,A,"",J),_(g)},d=F.current?.closest("#plan-scroll-container");return N1("div",{children:[N1("pre",{ref:F,className:"text-code font-mono text-text-code bg-bg-base select-text cursor-text py-3 hljs",children:p.map((A,g)=>{let a=g+1,n=u&&a>=u.start&&a<=u.end;return N1("div",{"data-line-num":a,className:`flex px-5 ${n?"bg-accent-blue/10":"hover:bg-bg-elevated-half"}`,children:[N1("span",{className:"text-text-tertiary select-none w-10 text-right pr-4 shrink-0 py-px text-[12px] cursor-pointer opacity-40 hover:opacity-100 hover:text-accent-blue",onMouseDown:(t)=>h(t,a),children:a},void 0,!1,void 0,this),x?N1("code",{className:"py-px",dangerouslySetInnerHTML:{__html:x[g]||" "}},void 0,!1,void 0,this):N1("code",{className:"py-px",children:A||" "},void 0,!1,void 0,this)]},g,!0,void 0,this)})},void 0,!1,void 0,this),B&&(()=>{let A=Q.find((g)=>g.id===B.annId);if(!A)return null;return N1(Y0,{anchorEl:B.anchorEl,scrollContainer:d,initialNote:A.note,onUpdate:(g)=>X(B.annId,g),onDelete:()=>{Y(B.annId),_(null)},onClose:()=>c(null)},void 0,!1,void 0,this)})(),o&&N1(J0,{anchorEl:o.anchorEl,scrollContainer:d,snippet:o.snippet,onAdd:(A)=>{let g=H1();T0(o.tempId,g),Z(g,o.snippet,A,J,o.ctx),y(null),Z1(null)},onCancel:()=>{F0(o.tempId),y(null),Z1(null)}},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{useEffect as o5,useState as s5,useRef as d3}from"react";import{jsxDEV as W1}from"react/jsx-dev-runtime";function t5(J,$){if($){let Q=$.replace(/\/+$/,"").split("/");return Q[Q.length-1]||J}return J.length>30?J.slice(0,30)+"...":J}function n0({currentSessionId:J,projectRoot:$}){let[Q,Z]=s5([]),[Y,X]=s5(!1),q=d3(null);o5(()=>{let K=async()=>{try{let G=await(await fetch("/api/sessions")).json();Z((N)=>{let W=JSON.stringify(G);return JSON.stringify(N)===W?N:G})}catch{}};K();let U=setInterval(K,5000);return()=>clearInterval(U)},[]),o5(()=>{if(!Y)return;let K=(U)=>{if(q.current&&!q.current.contains(U.target))X(!1)};return document.addEventListener("mousedown",K),()=>document.removeEventListener("mousedown",K)},[Y]);let _=Q.filter((K)=>K.id!==J),z=t5(J,$);return W1("div",{className:"relative",ref:q,children:[W1("div",{className:"flex items-center gap-1.5 font-body text-body font-medium",children:[W1("a",{href:`/s/${J}`,className:"text-text-primary hover:text-text-secondary transition-colors",children:z},void 0,!1,void 0,this),_.length>0&&W1("button",{onClick:()=>X(!Y),className:"flex items-center justify-center text-text-tertiary hover:text-text-secondary transition-colors",children:W1("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:`transition-transform duration-200 ${Y?"rotate-180":""}`,children:W1("path",{d:"M3 5l3 3 3-3",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Y&&_.length>0&&W1("div",{className:"absolute top-full left-0 mt-2 w-64 bg-bg-elevated border border-border-hover rounded-lg shadow-lg z-50 py-1 overflow-hidden",children:_.map((K)=>W1("a",{href:`/s/${K.id}`,className:"flex items-center gap-2.5 px-4 py-2.5 text-body font-body text-text-secondary hover:bg-bg-surface hover:text-text-primary transition-colors",children:[W1("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${K.currentRevision>0?"bg-accent-green":"bg-border-hover"}`},void 0,!1,void 0,this),W1("span",{className:"truncate",children:t5(K.id,K.projectRoot)},void 0,!1,void 0,this)]},K.id,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function n5(J){let $=[];return A0(J,$,0),$.join(`
104
104
  `).replace(/\n{3,}/g,`
105
105
 
106
106
  `).trim()+`
107
- `}var r3=new Set(["CODE","SPAN","STRONG","EM","A","B","I","U","SMALL","SUB","SUP","MARK","ABBR"]);function b0(J,$,Q){if(l3(J)){let Z=a3(J);if(Z)$.push(Z,"");return}for(let Z of J.childNodes)if(Z.nodeType===Node.ELEMENT_NODE)i3(Z,$,Q);else if(Z.nodeType===Node.TEXT_NODE){let Y=Z.textContent?.trim();if(Y)$.push(Y,"")}}function l3(J){for(let $ of J.childNodes){if($.nodeType===Node.TEXT_NODE)continue;if($.nodeType===Node.ELEMENT_NODE){let Q=$;if(!r3.has(Q.tagName)||Q.hasAttribute("data-md"))return!1}}return J.childNodes.length>0}function a3(J){let $="";for(let Q of J.childNodes)if(Q.nodeType===Node.TEXT_NODE)$+=Q.textContent||"";else if(Q.nodeType===Node.ELEMENT_NODE){let Z=Q;if(Z.tagName==="CODE")$+="`"+(Z.textContent||"")+"`";else $+=Z.textContent||""}return $.trim()}function i3(J,$,Q){let Z=J.getAttribute("data-md");if(Z)switch(Z){case"section":return o3(J,$,Q);case"item":return s3(J,$);case"codeblock":return t3(J,$);case"callout":return n3(J,$);case"note":return e3(J,$);case"table":return $$(J,$);case"checklist":return J$(J,$);case"diff":return Y$(J,$);case"mermaid":return Q$(J,$);case"choice":return Z$(J,$);case"multichoice":return q$(J,$);case"choice-option":case"multichoice-option":return;case"userinput":return X$(J,$);case"rangeinput":return z$(J,$);case"checklist-item":return;case"filepreview":return _$(J,$);case"priority":return K$(J,$)}if(J.querySelector("button, input, select, textarea"))return;if(J.children.length>0)b0(J,$,Q);else{let Y=J.textContent?.trim();if(Y)$.push(Y,"")}}function o3(J,$,Q){let Z=J.getAttribute("data-md-title")||"Untitled",Y=Q===0?"##":"###";$.push(`${Y} ${Z}`,"");let X=J.querySelector(":scope > div:last-of-type");if(X)b0(X,$,Q+1)}function s3(J,$){let Q=J.getAttribute("data-md-label")||"",Z=J.getAttribute("data-md-status"),Y=J.getAttribute("data-md-badge"),X="-";if(Z==="done")X="- [x]";else if(Z)X="- [ ]";let q=`${X} **${Q}**`;if(Y)q+=` \`${Y}\``;$.push(q);let _=J.querySelector(".text-text-secondary");if(_){let z=[];b0(_,z,0);for(let K of z)$.push(K?` ${K}`:"")}$.push("")}function t3(J,$){let Q=J.getAttribute("data-md-language")||"",Y=J.querySelector("code")?.textContent||"";$.push(`\`\`\`${Q}`,Y,"```","")}function n3(J,$){let Q=J.getAttribute("data-md-type")||"info",Z={info:"Info",warning:"Warning",danger:"Danger",tip:"Tip"},Y=U$(J.querySelector(".text-text-secondary")||J);$.push(`> **${Z[Q]||Q}:** ${Y}`,"")}function e3(J,$){let Q=J.textContent?.trim()||"";$.push(`> *${Q}*`,"")}function $$(J,$){let Q=J.querySelector("table");if(!Q)return;let Z=[];for(let Y of Q.querySelectorAll("thead th"))Z.push(Y.textContent?.trim()||"");if(Z.length===0)return;$.push(`| ${Z.join(" | ")} |`),$.push(`| ${Z.map(()=>"---").join(" | ")} |`);for(let Y of Q.querySelectorAll("tbody tr")){let X=[];for(let q of Y.querySelectorAll("td"))X.push(q.textContent?.trim()||"");$.push(`| ${X.join(" | ")} |`)}$.push("")}function J$(J,$){for(let Q of J.querySelectorAll("li")){let Z=Q.querySelector(".bg-accent-green")!==null,Y=Q.textContent?.trim()||"";$.push(`- [${Z?"x":" "}] ${Y}`)}$.push("")}function Y$(J,$){let Q=J.getAttribute("data-md-language")||"";$.push(`\`\`\`diff${Q?` (${Q})`:""}`);for(let Z of J.querySelectorAll("[class*='flex']")){let Y=Z.querySelector(".text-accent-red")?"-":Z.querySelector(".text-accent-green")?"+":" ",X=Z.querySelector("code");if(X)$.push(`${Y} ${X.textContent}`)}$.push("```","")}function Q$(J,$){let Q=J.getAttribute("data-md-source")||"";if(Q)$.push("```mermaid",Q,"```","")}function Z$(J,$){let Q=J.getAttribute("data-md-label")||"";$.push(`**${Q}:**`);for(let Z of J.querySelectorAll("[data-md='choice-option']")){let Y=Z.getAttribute("data-md-label")||Z.textContent?.trim()||"",X=Z.querySelector(".bg-accent-amber")!==null;$.push(`- ${X?"(x)":"( )"} ${Y}`)}$.push("")}function q$(J,$){let Q=J.getAttribute("data-md-label")||"";$.push(`**${Q}:**`);for(let Z of J.querySelectorAll("[data-md='multichoice-option']")){let Y=Z.getAttribute("data-md-label")||Z.textContent?.trim()||"",X=Z.querySelector(".bg-accent-amber")!==null;$.push(`- [${X?"x":" "}] ${Y}`)}$.push("")}function X$(J,$){let Q=J.getAttribute("data-md-label")||"",Y=J.querySelector("textarea")?.value?.trim()||"";$.push(`**${Q}:** ${Y||"_empty_"}`,"")}function z$(J,$){let Q=J.getAttribute("data-md-label")||"",Z=J.querySelector("input[type='range']"),X=J.querySelector(".font-mono")?.textContent?.trim()||Z?.value||"—";$.push(`**${Q}:** ${X}`,"")}function _$(J,$){let Q=J.getAttribute("data-md-path")||"",Z=J.getAttribute("data-md-lines")||"",X=J.querySelector("code")?.textContent||"",q=Q.split(".").pop()||"",_=S0[q]||"",z=Z?`${Q} (L${Z})`:Q;$.push(z,"",`\`\`\`${_}`,X,"```","")}function K$(J,$){}function U$(J){return J?.textContent?.trim()||""}import A$,{useEffect as c1,useState as Y1,useRef as L1}from"react";import{useEffect as G$,useState as H$,useRef as N$,useContext as W$}from"react";import{jsxDEV as z1,Fragment as e5}from"react/jsx-dev-runtime";function T$(J){return J.label||`Round ${J.revision}`}function O$(J){let $=Date.now()-new Date(J).getTime(),Q=Math.floor($/1000);if(Q<60)return"just now";let Z=Math.floor(Q/60);if(Z<60)return`${Z}m ago`;let Y=Math.floor(Z/60);if(Y<24)return`${Y}h ago`;return`${Math.floor(Y/24)}d ago`}function Z0({value:J,onChange:$,accent:Q="default",className:Z}){let{currentRevision:Y,revisions:X}=W$(h1),[q,_]=H$(!1),z=N$(null);G$(()=>{if(!q)return;let H=(G)=>{if(z.current&&!z.current.contains(G.target))_(!1)};return document.addEventListener("mousedown",H),()=>document.removeEventListener("mousedown",H)},[q]);let K=X.find((H)=>H.revision===J);return z1("div",{className:"relative",ref:z,children:[z1("button",{onClick:()=>_(!q),className:`flex items-center gap-1.5 text-[12px] font-body font-medium px-2 py-1 rounded-md transition-colors hover:bg-bg-elevated ${{default:"text-text-secondary hover:text-text-primary",red:"text-accent-red",green:"text-accent-green",amber:"text-accent-amber bg-highlight-selected"}[Q]} ${Z||""}`,children:[K?T$(K):`Round ${J}`,z1("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",className:`text-text-tertiary transition-transform duration-200 ${q?"rotate-180":""}`,children:z1("path",{d:"M2.5 4l2.5 2.5L7.5 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),q&&z1("div",{className:"absolute top-full left-0 mt-1 w-64 bg-bg-elevated border border-border-hover rounded-lg shadow-lg z-50 py-1 max-h-80 overflow-y-auto",children:[...X].reverse().map((H)=>z1("button",{onClick:()=>{$(H.revision),_(!1)},className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] font-body transition-colors ${H.revision===J?"bg-bg-surface text-text-primary":"text-text-secondary hover:bg-bg-surface hover:text-text-primary"}`,children:[z1("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${H.revision===Y?"bg-accent-green":H.hasFeedback?"bg-accent-amber":"bg-border-hover"}`},void 0,!1,void 0,this),z1("span",{className:"flex-1 text-left truncate",children:H.label?z1(e5,{children:[H.label," ",z1("span",{className:"text-text-tertiary",children:["#",H.revision]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):z1(e5,{children:["Round ",H.revision]},void 0,!0,void 0,this)},void 0,!1,void 0,this),z1("span",{className:"text-[10px] text-text-tertiary flex-shrink-0",children:H.revision===Y?"current":H.hasFeedback?"sent":O$(H.createdAt)},void 0,!1,void 0,this)]},H.revision,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function B1(J,$){let Q=J.length,Z=$.length;if(Q===0||Z===0)return[];let Y=Array.from({length:Q+1},()=>Array(Z+1).fill(0));for(let z=1;z<=Q;z++)for(let K=1;K<=Z;K++)Y[z][K]=J[z-1]===$[K-1]?Y[z-1][K-1]+1:Math.max(Y[z-1][K],Y[z][K-1]);let X=[],q=Q,_=Z;while(q>0&&_>0)if(J[q-1]===$[_-1])X.unshift(J[q-1]),q--,_--;else if(Y[q-1][_]>Y[q][_-1])q--;else _--;return X}function $2(J){let $=[],Q=[],Z=document.createTreeWalker(J,NodeFilter.SHOW_TEXT,{acceptNode(X){let q=X.parentElement;if(!q)return NodeFilter.FILTER_REJECT;if(q.closest("svg, .select-none, [data-no-diff]"))return NodeFilter.FILTER_REJECT;return NodeFilter.FILTER_ACCEPT}}),Y;while(Y=Z.nextNode()){let q=(Y.nodeValue||"").match(/\S+|\s+/g);if(!q)continue;let _=0;for(let z of q)$.push(z),Q.push({text:z,node:Y,offset:_}),_+=z.length}return{words:$,map:Q}}function e0(J,$){if(J.length>5000||$.length>5000)return F$(J,$);return Q2(J,$)}function Q2(J,$){let Q=A0(J,$),Z=[],Y=[],X=0,q=0,_=0;while(X<J.length||q<$.length)if(_<Q.length&&X<J.length&&q<$.length&&J[X]===Q[_]&&$[q]===Q[_])Z.push({type:"same",index:X}),Y.push({type:"same",index:q}),X++,q++,_++;else if(X<J.length&&(_>=Q.length||J[X]!==Q[_]))Z.push({type:"removed",index:X}),X++;else if(q<$.length)Y.push({type:"added",index:q}),q++;return{oldOps:Z,newOps:Y}}function A0(J,$){let Q=J.length,Z=$.length;if(Q===0||Z===0)return[];if(Q===1)return $.includes(J[0])?[J[0]]:[];if(Z===1)return J.includes($[0])?[$[0]]:[];if(Q*Z<=1e6)return B1(J,$);let Y=Math.floor(Q/2),X=J.slice(0,Y),q=J.slice(Y),_=J2(X,$),z=J2([...q].reverse(),[...$].reverse()),K=0,U=0;for(let N=0;N<=Z;N++){let W=_[N]+z[Z-N];if(W>K)K=W,U=N}let H=$.slice(0,U),G=$.slice(U);return[...A0(X,H),...A0(q,G)]}function J2(J,$){let Q=$.length,Z=Array(Q+1).fill(0),Y=Array(Q+1).fill(0);for(let X=0;X<J.length;X++){for(let q=1;q<=Q;q++)Y[q]=J[X]===$[q-1]?Z[q-1]+1:Math.max(Z[q],Y[q-1]);[Z,Y]=[Y,Z],Y.fill(0)}return Z}function F$(J,$){let Z=(W)=>{let M=[];for(let F=0;F<W.length;F+=200){let B=Math.min(F+200,W.length);M.push({start:F,end:B,text:W.slice(F,B).join("")})}return M},Y=Z(J),X=Z($),q=Y.map((W)=>W.text),_=X.map((W)=>W.text),z=A0(q,_),K=[],U=[],H=0,G=0,N=0;while(H<Y.length||G<X.length)if(N<z.length&&H<Y.length&&G<X.length&&q[H]===z[N]&&_[G]===z[N]){for(let W=Y[H].start;W<Y[H].end;W++)K.push({type:"same",index:W});for(let W=X[G].start;W<X[G].end;W++)U.push({type:"same",index:W});H++,G++,N++}else if(H<Y.length&&(N>=z.length||q[H]!==z[N]))if(G<X.length&&(N>=z.length||_[G]!==z[N])){let W=Q2(J.slice(Y[H].start,Y[H].end),$.slice(X[G].start,X[G].end));for(let M of W.oldOps)K.push({type:M.type,index:M.index+Y[H].start});for(let M of W.newOps)U.push({type:M.type,index:M.index+X[G].start});H++,G++}else{for(let W=Y[H].start;W<Y[H].end;W++)K.push({type:"removed",index:W});H++}else if(G<X.length){for(let W=X[G].start;W<X[G].end;W++)U.push({type:"added",index:W});G++}return{oldOps:K,newOps:U}}function Y2(J,$,Q){let Z=new Map;for(let Y of J){if(Y.type==="same")continue;let X=$[Y.index];if(!X||!X.node.parentNode)continue;let q=Z.get(X.node);if(!q)q=[],Z.set(X.node,q);q.push({offset:X.offset,length:X.text.length})}for(let[Y,X]of Z){if(!Y.parentNode)continue;let q=Y.nodeValue||"";X.sort((H,G)=>H.offset-G.offset);let _=[];for(let H of X){let G=_[_.length-1];if(G&&H.offset<=G.offset+G.length)G.length=Math.max(G.length,H.offset+H.length-G.offset);else _.push({...H})}let z=Y.parentNode,K=document.createDocumentFragment(),U=0;for(let H of _){if(H.offset>U)K.appendChild(document.createTextNode(q.slice(U,H.offset)));let G=document.createElement("span");G.className=Q,G.textContent=q.slice(H.offset,H.offset+H.length),K.appendChild(G),U=H.offset+H.length}if(U<q.length)K.appendChild(document.createTextNode(q.slice(U)));z.replaceChild(K,Y)}}function Z2(J,$){let Q=y$(J,$),Z=$2(J),Y=$2($),{oldOps:X,newOps:q}=e0(Z.words,Y.words),_=X.some((z)=>z.type==="removed")||q.some((z)=>z.type==="added");return Y2(X,Z.map,"diff-removed"),Y2(q,Y.map,"diff-added"),_||Q}function y$(J,$){let Q=Array.from(J.querySelectorAll('[data-md="mermaid"]')),Z=Array.from($.querySelectorAll('[data-md="mermaid"]')),Y=!1,X=Math.max(Q.length,Z.length);for(let q=0;q<X;q++){let _=Q[q],z=Z[q];if(!_&&z){z.classList.add("diff-block-added"),z.style.position="relative",Y=!0;continue}if(_&&!z){_.classList.add("diff-block-removed"),_.style.position="relative",Y=!0;continue}if(!_||!z)continue;let K=(_.getAttribute("data-md-source")||"").trim(),U=(z.getAttribute("data-md-source")||"").trim();if(K===U)continue;Y=!0,_.style.borderLeft="3px solid var(--color-accent-red)",_.style.paddingLeft="8px",z.style.borderLeft="3px solid var(--color-accent-green)",z.style.paddingLeft="8px";let H=K.split(`
107
+ `}var r3=new Set(["CODE","SPAN","STRONG","EM","A","B","I","U","SMALL","SUB","SUP","MARK","ABBR"]);function A0(J,$,Q){if(l3(J)){let Z=a3(J);if(Z)$.push(Z,"");return}for(let Z of J.childNodes)if(Z.nodeType===Node.ELEMENT_NODE)i3(Z,$,Q);else if(Z.nodeType===Node.TEXT_NODE){let Y=Z.textContent?.trim();if(Y)$.push(Y,"")}}function l3(J){for(let $ of J.childNodes){if($.nodeType===Node.TEXT_NODE)continue;if($.nodeType===Node.ELEMENT_NODE){let Q=$;if(!r3.has(Q.tagName)||Q.hasAttribute("data-md"))return!1}}return J.childNodes.length>0}function a3(J){let $="";for(let Q of J.childNodes)if(Q.nodeType===Node.TEXT_NODE)$+=Q.textContent||"";else if(Q.nodeType===Node.ELEMENT_NODE){let Z=Q;if(Z.tagName==="CODE")$+="`"+(Z.textContent||"")+"`";else $+=Z.textContent||""}return $.trim()}function i3(J,$,Q){let Z=J.getAttribute("data-md");if(Z)switch(Z){case"section":return o3(J,$,Q);case"item":return s3(J,$);case"codeblock":return t3(J,$);case"callout":return n3(J,$);case"note":return e3(J,$);case"table":return $$(J,$);case"checklist":return J$(J,$);case"diff":return Y$(J,$);case"mermaid":return Q$(J,$);case"choice":return Z$(J,$);case"multichoice":return q$(J,$);case"choice-option":case"multichoice-option":return;case"userinput":return X$(J,$);case"rangeinput":return z$(J,$);case"checklist-item":return;case"filepreview":return _$(J,$);case"priority":return K$(J,$)}if(J.querySelector("button, input, select, textarea"))return;if(J.children.length>0)A0(J,$,Q);else{let Y=J.textContent?.trim();if(Y)$.push(Y,"")}}function o3(J,$,Q){let Z=J.getAttribute("data-md-title")||"Untitled",Y=Q===0?"##":"###";$.push(`${Y} ${Z}`,"");let X=J.querySelector(":scope > div:last-of-type");if(X)A0(X,$,Q+1)}function s3(J,$){let Q=J.getAttribute("data-md-label")||"",Z=J.getAttribute("data-md-status"),Y=J.getAttribute("data-md-badge"),X="-";if(Z==="done")X="- [x]";else if(Z)X="- [ ]";let q=`${X} **${Q}**`;if(Y)q+=` \`${Y}\``;$.push(q);let _=J.querySelector(".text-text-secondary");if(_){let z=[];A0(_,z,0);for(let K of z)$.push(K?` ${K}`:"")}$.push("")}function t3(J,$){let Q=J.getAttribute("data-md-language")||"",Y=J.querySelector("code")?.textContent||"";$.push(`\`\`\`${Q}`,Y,"```","")}function n3(J,$){let Q=J.getAttribute("data-md-type")||"info",Z={info:"Info",warning:"Warning",danger:"Danger",tip:"Tip"},Y=U$(J.querySelector(".text-text-secondary")||J);$.push(`> **${Z[Q]||Q}:** ${Y}`,"")}function e3(J,$){let Q=J.textContent?.trim()||"";$.push(`> *${Q}*`,"")}function $$(J,$){let Q=J.querySelector("table");if(!Q)return;let Z=[];for(let Y of Q.querySelectorAll("thead th"))Z.push(Y.textContent?.trim()||"");if(Z.length===0)return;$.push(`| ${Z.join(" | ")} |`),$.push(`| ${Z.map(()=>"---").join(" | ")} |`);for(let Y of Q.querySelectorAll("tbody tr")){let X=[];for(let q of Y.querySelectorAll("td"))X.push(q.textContent?.trim()||"");$.push(`| ${X.join(" | ")} |`)}$.push("")}function J$(J,$){for(let Q of J.querySelectorAll("li")){let Z=Q.querySelector(".bg-accent-green")!==null,Y=Q.textContent?.trim()||"";$.push(`- [${Z?"x":" "}] ${Y}`)}$.push("")}function Y$(J,$){let Q=J.getAttribute("data-md-language")||"";$.push(`\`\`\`diff${Q?` (${Q})`:""}`);for(let Z of J.querySelectorAll("[class*='flex']")){let Y=Z.querySelector(".text-accent-red")?"-":Z.querySelector(".text-accent-green")?"+":" ",X=Z.querySelector("code");if(X)$.push(`${Y} ${X.textContent}`)}$.push("```","")}function Q$(J,$){let Q=J.getAttribute("data-md-source")||"";if(Q)$.push("```mermaid",Q,"```","")}function Z$(J,$){let Q=J.getAttribute("data-md-label")||"";$.push(`**${Q}:**`);for(let Z of J.querySelectorAll("[data-md='choice-option']")){let Y=Z.getAttribute("data-md-label")||Z.textContent?.trim()||"",X=Z.querySelector(".bg-accent-amber")!==null;$.push(`- ${X?"(x)":"( )"} ${Y}`)}$.push("")}function q$(J,$){let Q=J.getAttribute("data-md-label")||"";$.push(`**${Q}:**`);for(let Z of J.querySelectorAll("[data-md='multichoice-option']")){let Y=Z.getAttribute("data-md-label")||Z.textContent?.trim()||"",X=Z.querySelector(".bg-accent-amber")!==null;$.push(`- [${X?"x":" "}] ${Y}`)}$.push("")}function X$(J,$){let Q=J.getAttribute("data-md-label")||"",Y=J.querySelector("textarea")?.value?.trim()||"";$.push(`**${Q}:** ${Y||"_empty_"}`,"")}function z$(J,$){let Q=J.getAttribute("data-md-label")||"",Z=J.querySelector("input[type='range']"),X=J.querySelector(".font-mono")?.textContent?.trim()||Z?.value||"—";$.push(`**${Q}:** ${X}`,"")}function _$(J,$){let Q=J.getAttribute("data-md-path")||"",Z=J.getAttribute("data-md-lines")||"",X=J.querySelector("code")?.textContent||"",q=Q.split(".").pop()||"",_=b0[q]||"",z=Z?`${Q} (L${Z})`:Q;$.push(z,"",`\`\`\`${_}`,X,"```","")}function K$(J,$){}function U$(J){return J?.textContent?.trim()||""}import A$,{useEffect as c1,useState as Y1,useRef as L1}from"react";import{useEffect as G$,useState as H$,useRef as N$,useContext as W$}from"react";import{jsxDEV as z1,Fragment as e5}from"react/jsx-dev-runtime";function T$(J){return J.label||`Round ${J.revision}`}function O$(J){let $=Date.now()-new Date(J).getTime(),Q=Math.floor($/1000);if(Q<60)return"just now";let Z=Math.floor(Q/60);if(Z<60)return`${Z}m ago`;let Y=Math.floor(Z/60);if(Y<24)return`${Y}h ago`;return`${Math.floor(Y/24)}d ago`}function Z0({value:J,onChange:$,accent:Q="default",className:Z}){let{currentRevision:Y,revisions:X}=W$(h1),[q,_]=H$(!1),z=N$(null);G$(()=>{if(!q)return;let H=(G)=>{if(z.current&&!z.current.contains(G.target))_(!1)};return document.addEventListener("mousedown",H),()=>document.removeEventListener("mousedown",H)},[q]);let K=X.find((H)=>H.revision===J);return z1("div",{className:"relative",ref:z,children:[z1("button",{onClick:()=>_(!q),className:`flex items-center gap-1.5 text-[12px] font-body font-medium px-2 py-1 rounded-md transition-colors hover:bg-bg-elevated ${{default:"text-text-secondary hover:text-text-primary",red:"text-accent-red",green:"text-accent-green",amber:"text-accent-amber bg-highlight-selected"}[Q]} ${Z||""}`,children:[K?T$(K):`Round ${J}`,z1("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",className:`text-text-tertiary transition-transform duration-200 ${q?"rotate-180":""}`,children:z1("path",{d:"M2.5 4l2.5 2.5L7.5 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),q&&z1("div",{className:"absolute top-full left-0 mt-1 w-64 bg-bg-elevated border border-border-hover rounded-lg shadow-lg z-50 py-1 max-h-80 overflow-y-auto",children:[...X].reverse().map((H)=>z1("button",{onClick:()=>{$(H.revision),_(!1)},className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] font-body transition-colors ${H.revision===J?"bg-bg-surface text-text-primary":"text-text-secondary hover:bg-bg-surface hover:text-text-primary"}`,children:[z1("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${H.revision===Y?"bg-accent-green":H.hasFeedback?"bg-accent-amber":"bg-border-hover"}`},void 0,!1,void 0,this),z1("span",{className:"flex-1 text-left truncate",children:H.label?z1(e5,{children:[H.label," ",z1("span",{className:"text-text-tertiary",children:["#",H.revision]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):z1(e5,{children:["Round ",H.revision]},void 0,!0,void 0,this)},void 0,!1,void 0,this),z1("span",{className:"text-[10px] text-text-tertiary flex-shrink-0",children:H.revision===Y?"current":H.hasFeedback?"sent":O$(H.createdAt)},void 0,!1,void 0,this)]},H.revision,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function B1(J,$){let Q=J.length,Z=$.length;if(Q===0||Z===0)return[];let Y=Array.from({length:Q+1},()=>Array(Z+1).fill(0));for(let z=1;z<=Q;z++)for(let K=1;K<=Z;K++)Y[z][K]=J[z-1]===$[K-1]?Y[z-1][K-1]+1:Math.max(Y[z-1][K],Y[z][K-1]);let X=[],q=Q,_=Z;while(q>0&&_>0)if(J[q-1]===$[_-1])X.unshift(J[q-1]),q--,_--;else if(Y[q-1][_]>Y[q][_-1])q--;else _--;return X}function $2(J){let $=[],Q=[],Z=document.createTreeWalker(J,NodeFilter.SHOW_TEXT,{acceptNode(X){let q=X.parentElement;if(!q)return NodeFilter.FILTER_REJECT;if(q.closest("svg, .select-none, [data-no-diff]"))return NodeFilter.FILTER_REJECT;return NodeFilter.FILTER_ACCEPT}}),Y;while(Y=Z.nextNode()){let q=(Y.nodeValue||"").match(/\S+|\s+/g);if(!q)continue;let _=0;for(let z of q)$.push(z),Q.push({text:z,node:Y,offset:_}),_+=z.length}return{words:$,map:Q}}function e0(J,$){if(J.length>5000||$.length>5000)return F$(J,$);return Q2(J,$)}function Q2(J,$){let Q=w0(J,$),Z=[],Y=[],X=0,q=0,_=0;while(X<J.length||q<$.length)if(_<Q.length&&X<J.length&&q<$.length&&J[X]===Q[_]&&$[q]===Q[_])Z.push({type:"same",index:X}),Y.push({type:"same",index:q}),X++,q++,_++;else if(X<J.length&&(_>=Q.length||J[X]!==Q[_]))Z.push({type:"removed",index:X}),X++;else if(q<$.length)Y.push({type:"added",index:q}),q++;return{oldOps:Z,newOps:Y}}function w0(J,$){let Q=J.length,Z=$.length;if(Q===0||Z===0)return[];if(Q===1)return $.includes(J[0])?[J[0]]:[];if(Z===1)return J.includes($[0])?[$[0]]:[];if(Q*Z<=1e6)return B1(J,$);let Y=Math.floor(Q/2),X=J.slice(0,Y),q=J.slice(Y),_=J2(X,$),z=J2([...q].reverse(),[...$].reverse()),K=0,U=0;for(let N=0;N<=Z;N++){let W=_[N]+z[Z-N];if(W>K)K=W,U=N}let H=$.slice(0,U),G=$.slice(U);return[...w0(X,H),...w0(q,G)]}function J2(J,$){let Q=$.length,Z=Array(Q+1).fill(0),Y=Array(Q+1).fill(0);for(let X=0;X<J.length;X++){for(let q=1;q<=Q;q++)Y[q]=J[X]===$[q-1]?Z[q-1]+1:Math.max(Z[q],Y[q-1]);[Z,Y]=[Y,Z],Y.fill(0)}return Z}function F$(J,$){let Z=(W)=>{let M=[];for(let F=0;F<W.length;F+=200){let L=Math.min(F+200,W.length);M.push({start:F,end:L,text:W.slice(F,L).join("")})}return M},Y=Z(J),X=Z($),q=Y.map((W)=>W.text),_=X.map((W)=>W.text),z=w0(q,_),K=[],U=[],H=0,G=0,N=0;while(H<Y.length||G<X.length)if(N<z.length&&H<Y.length&&G<X.length&&q[H]===z[N]&&_[G]===z[N]){for(let W=Y[H].start;W<Y[H].end;W++)K.push({type:"same",index:W});for(let W=X[G].start;W<X[G].end;W++)U.push({type:"same",index:W});H++,G++,N++}else if(H<Y.length&&(N>=z.length||q[H]!==z[N]))if(G<X.length&&(N>=z.length||_[G]!==z[N])){let W=Q2(J.slice(Y[H].start,Y[H].end),$.slice(X[G].start,X[G].end));for(let M of W.oldOps)K.push({type:M.type,index:M.index+Y[H].start});for(let M of W.newOps)U.push({type:M.type,index:M.index+X[G].start});H++,G++}else{for(let W=Y[H].start;W<Y[H].end;W++)K.push({type:"removed",index:W});H++}else if(G<X.length){for(let W=X[G].start;W<X[G].end;W++)U.push({type:"added",index:W});G++}return{oldOps:K,newOps:U}}function Y2(J,$,Q){let Z=new Map;for(let Y of J){if(Y.type==="same")continue;let X=$[Y.index];if(!X||!X.node.parentNode)continue;let q=Z.get(X.node);if(!q)q=[],Z.set(X.node,q);q.push({offset:X.offset,length:X.text.length})}for(let[Y,X]of Z){if(!Y.parentNode)continue;let q=Y.nodeValue||"";X.sort((H,G)=>H.offset-G.offset);let _=[];for(let H of X){let G=_[_.length-1];if(G&&H.offset<=G.offset+G.length)G.length=Math.max(G.length,H.offset+H.length-G.offset);else _.push({...H})}let z=Y.parentNode,K=document.createDocumentFragment(),U=0;for(let H of _){if(H.offset>U)K.appendChild(document.createTextNode(q.slice(U,H.offset)));let G=document.createElement("span");G.className=Q,G.textContent=q.slice(H.offset,H.offset+H.length),K.appendChild(G),U=H.offset+H.length}if(U<q.length)K.appendChild(document.createTextNode(q.slice(U)));z.replaceChild(K,Y)}}function Z2(J,$){let Q=y$(J,$),Z=$2(J),Y=$2($),{oldOps:X,newOps:q}=e0(Z.words,Y.words),_=X.some((z)=>z.type==="removed")||q.some((z)=>z.type==="added");return Y2(X,Z.map,"diff-removed"),Y2(q,Y.map,"diff-added"),_||Q}function y$(J,$){let Q=Array.from(J.querySelectorAll('[data-md="mermaid"]')),Z=Array.from($.querySelectorAll('[data-md="mermaid"]')),Y=!1,X=Math.max(Q.length,Z.length);for(let q=0;q<X;q++){let _=Q[q],z=Z[q];if(!_&&z){z.classList.add("diff-block-added"),z.style.position="relative",Y=!0;continue}if(_&&!z){_.classList.add("diff-block-removed"),_.style.position="relative",Y=!0;continue}if(!_||!z)continue;let K=(_.getAttribute("data-md-source")||"").trim(),U=(z.getAttribute("data-md-source")||"").trim();if(K===U)continue;Y=!0,_.style.borderLeft="3px solid var(--color-accent-red)",_.style.paddingLeft="8px",z.style.borderLeft="3px solid var(--color-accent-green)",z.style.paddingLeft="8px";let H=K.split(`
108
108
  `),G=U.split(`
109
- `),N=B1(H,G),W=(M,F,B)=>{let y=document.createElement("div");y.className="mt-2 bg-bg-code rounded-md overflow-hidden text-tiny font-mono",y.setAttribute("data-no-diff","true");let S=0,R=0;while(R<M.length){let m=document.createElement("div");if(m.className="px-3 py-0.5 whitespace-pre-wrap",S<F.length&&M[R]===F[S])m.textContent=" "+M[R],R++,S++;else m.classList.add(B==="old"?"diff-removed":"diff-added"),m.textContent=(B==="old"?"- ":"+ ")+M[R],R++;y.appendChild(m)}return y};_.appendChild(W(H,N,"old")),z.appendChild(W(G,N,"new"))}return Y}function $5(J){let $=[],Q=J.querySelectorAll(":scope > [data-md]");for(let Z of Q)$.push(q0(Z));if($.length===0){let Z=J.querySelectorAll("[data-md]"),Y=new Set;for(let X of Z){let q=X.parentElement?.closest("[data-md]");if(q&&J.contains(q))continue;if(Y.has(X))continue;Y.add(X),$.push(q0(X))}}return $}function q0(J){let $=J.getAttribute("data-md")||"unknown",Q=M$(J,$),Z=[];if($==="section"){let Y=J.querySelector(":scope > div.mt-6, :scope > div:last-child");if(Y)for(let X of Y.querySelectorAll(":scope > [data-md]"))Z.push(q0(X))}else if($==="table")for(let Y of J.querySelectorAll(":scope table > tbody > tr"))Z.push({key:"tr:"+(Y.textContent||"").slice(0,80),type:"tr",element:Y,children:[]});else if($==="checklist")for(let Y of J.querySelectorAll(":scope > [data-md='checklist-item']"))Z.push(q0(Y));else for(let Y of J.querySelectorAll("[data-md]"))if(Y.parentElement?.closest("[data-md]")===J)Z.push(q0(Y));return{key:Q,type:$,element:J,children:Z}}function M$(J,$){switch($){case"section":return"section:"+(J.getAttribute("data-md-title")||"");case"item":return"item:"+(J.getAttribute("data-task-id")||J.getAttribute("data-md-label")||"");case"codeblock":case"diff":return $+":"+(J.textContent||"").slice(0,80);case"checklist-item":return"checklist-item:"+(J.getAttribute("data-md-label")||J.textContent?.slice(0,60)||"");case"checklist":return"checklist:"+J.querySelectorAll("[data-md='checklist-item']").length;case"markdown":return"markdown:"+(J.getAttribute("data-md-file")||"inline");case"mermaid":return"mermaid:"+(J.getAttribute("data-md-source")||"").slice(0,80);case"callout":return"callout:"+(J.getAttribute("data-md-type")||"")+":"+(J.textContent||"").slice(0,60);default:return $+":"+(J.getAttribute("data-md-label")||J.textContent?.slice(0,60)||"")}}function J5(J,$){let Q=J.map((K)=>K.key),Z=$.map((K)=>K.key),Y=B1(Q,Z),X=[],q=0,_=0,z=0;while(q<J.length||_<$.length)if(z<Y.length&&q<J.length&&_<$.length&&Q[q]===Y[z]&&Z[_]===Y[z]){let K=J[q],U=$[_],H=K.children.length>0||U.children.length>0?J5(K.children,U.children):void 0;X.push({kind:"matched",oldBlock:K,newBlock:U,childMatches:H}),q++,_++,z++}else if(q<J.length&&(z>=Y.length||Q[q]!==Y[z]))X.push({kind:"removed",oldBlock:J[q]}),q++;else if(_<$.length)X.push({kind:"added",newBlock:$[_]}),_++;return X}function X2(J){let $=document.createDocumentFragment(),Q=!1;for(let Z of J)if(Z.kind==="removed")Q=!0,$.appendChild(z2(Z.oldBlock.element));else if(Z.kind==="added")Q=!0,$.appendChild(B$(Z.newBlock.element));else{let Y=Z.newBlock.element.cloneNode(!0),X=Z.newBlock.type;if(X==="mermaid"){if(G2(Z.oldBlock.element,Y))Q=!0}else if(Z.childMatches&&Z.childMatches.length>0&&(X==="table"||X==="checklist")){if(K2(Y,Z.childMatches,X))Q=!0}else if(Z.childMatches&&Z.childMatches.length>0){if(_2(Z.oldBlock,Y,Z.childMatches,X))Q=!0}else if(X==="markdown"){if(U2(Z.oldBlock.element,Y))Q=!0}else if(V1(Z.oldBlock.element,Y,!1))Q=!0;$.appendChild(Y)}return{fragment:$,hasChanges:Q}}function z2(J){let $=J.cloneNode(!0);return $.classList.add("diff-block-removed"),$.style.position="relative",Y5($,"Removed","var(--color-accent-red)"),$}function B$(J){let $=J.cloneNode(!0);return $.classList.add("diff-block-added"),$.style.position="relative",Y5($,"Added","var(--color-accent-green)"),$}function _2(J,$,Q,Z){let Y=!1,X=L$(J,$),q,_;if(Z==="section"){let z=J.element.querySelector(":scope > div:first-child"),K=$.querySelector(":scope > div:first-child");if(z&&K){if(V1(z,K,!1))Y=!0}q=J.element.querySelector(":scope > div.mt-6, :scope > div:last-child"),_=$.querySelector(":scope > div.mt-6, :scope > div:last-child")}else q=J.element,_=$;if(!q||!_)return Y;for(let z of Q)if(z.kind==="matched"){let K=X.newMap.get(z.newBlock.element);if(K){if(z.newBlock.type==="mermaid"){if(G2(z.oldBlock.element,K))Y=!0}else if(z.childMatches&&z.childMatches.length>0&&(z.newBlock.type==="table"||z.newBlock.type==="checklist")){if(K2(K,z.childMatches,z.newBlock.type))Y=!0}else if(z.childMatches&&z.childMatches.length>0){if(_2(z.oldBlock,K,z.childMatches,z.newBlock.type))Y=!0}else if(z.newBlock.type==="markdown"){if(U2(z.oldBlock.element,K))Y=!0}else if(V1(z.oldBlock.element,K,!1))Y=!0}}else if(z.kind==="removed"){Y=!0;let K=z2(z.oldBlock.element),U=S$(Q,z,X.newMap);_.insertBefore(K,U)}else if(z.kind==="added"){Y=!0;let K=X.newMap.get(z.newBlock.element);if(K)K.classList.add("diff-block-added"),K.style.position="relative",Y5(K,"Added","var(--color-accent-green)")}if(V1(q,_,!0))Y=!0;return Y}function K2(J,$,Q){let Z=Q==="table"?J.querySelector(":scope table > tbody"):J;if(!Z)return!1;let Y=!1;Z.innerHTML="";for(let X of $)if(X.kind==="removed"){Y=!0;let q=X.oldBlock.element.cloneNode(!0);q.classList.add(Q==="table"?"diff-row-removed":"diff-item-removed"),Z.appendChild(q)}else if(X.kind==="added"){Y=!0;let q=X.newBlock.element.cloneNode(!0);q.classList.add(Q==="table"?"diff-row-added":"diff-item-added"),Z.appendChild(q)}else{let q=X.newBlock.element.cloneNode(!0);if(V1(X.oldBlock.element,q,!1))Y=!0;Z.appendChild(q)}return Y}function L$(J,$){let Q=new Map,Z=J.element.querySelectorAll("[data-md]"),Y=$.querySelectorAll("[data-md]");return{newMap:{get(X){return P$($,X)}}}}function P$(J,$){let Q=$.getAttribute("data-md");if(!Q)return null;let Z=$.getAttribute("data-md-label"),Y=$.getAttribute("data-md-title"),X=`[data-md="${Q}"]`;if(Y)X+=`[data-md-title="${CSS.escape(Y)}"]`;else if(Z)X+=`[data-md-label="${CSS.escape(Z)}"]`;let q=J.querySelectorAll(X);if(q.length===1)return q[0];let _=($.textContent||"").slice(0,100),z=null,K=-1;for(let U of q){let H=(U.textContent||"").slice(0,100),G=0;for(let N=0;N<Math.min(_.length,H.length);N++)if(_[N]===H[N])G++;if(G>K)K=G,z=U}return z}function S$(J,$,Q){let Z=J.indexOf($);for(let Y=Z+1;Y<J.length;Y++){let X=J[Y];if((X.kind==="matched"||X.kind==="added")&&X.newBlock)return Q.get(X.newBlock.element)||null}return null}function U2(J,$){let Q=Array.from(J.children),Z=Array.from($.children);if(Q.length===0&&Z.length===0)return V1(J,$,!1);let Y=Q.map((G)=>G.tagName.toLowerCase()),X=Z.map((G)=>G.tagName.toLowerCase()),q=B1(Y,X),_=[],z=0,K=0,U=0;while(z<Q.length||K<Z.length)if(U<q.length&&z<Q.length&&K<Z.length&&Y[z]===q[U]&&X[K]===q[U])_.push({kind:"matched",oldChild:Q[z],newChild:Z[K]}),z++,K++,U++;else if(z<Q.length&&(U>=q.length||Y[z]!==q[U]))_.push({kind:"removed",oldChild:Q[z]}),z++;else if(K<Z.length)_.push({kind:"added",newChild:Z[K]}),K++;let H=!1;while($.firstChild)$.removeChild($.firstChild);for(let G of _)if(G.kind==="matched"){let N=(G.oldChild.textContent||"").match(/\S+/g)||[],W=(G.newChild.textContent||"").match(/\S+/g)||[],M=B1(N,W),F=Math.max(N.length,W.length);if((F>0?1-M.length/F:0)>0.5){H=!0;let y=G.oldChild.cloneNode(!0);y.classList.add("diff-block-removed"),$.appendChild(y),G.newChild.classList.add("diff-block-added"),$.appendChild(G.newChild)}else{if(V1(G.oldChild,G.newChild,!1))H=!0;$.appendChild(G.newChild)}}else if(G.kind==="removed"){H=!0;let N=G.oldChild.cloneNode(!0);N.classList.add("diff-block-removed"),$.appendChild(N)}else H=!0,G.newChild.classList.add("diff-block-added"),$.appendChild(G.newChild);return H}function q2(J,$){let Q=$?new Set(Array.from(J.querySelectorAll("[data-md]"))):new Set,Z=[],Y=[],X=document.createTreeWalker(J,NodeFilter.SHOW_TEXT,{acceptNode(_){let z=_.parentElement;if(!z)return NodeFilter.FILTER_REJECT;if(z.closest("svg, .select-none, [data-no-diff]"))return NodeFilter.FILTER_REJECT;if($){for(let K of Q)if(K.contains(_))return NodeFilter.FILTER_REJECT}return NodeFilter.FILTER_ACCEPT}}),q;while(q=X.nextNode()){let z=(q.nodeValue||"").match(/\S+|\s+/g);if(!z)continue;let K=0;for(let U of z)Z.push(U),Y.push({text:U,node:q,offset:K}),K+=U.length}return{words:Z,map:Y}}function V1(J,$,Q){let Z=q2(J,Q),Y=q2($,Q);if(Z.words.length===0&&Y.words.length===0)return!1;let{oldOps:X,newOps:q}=e0(Z.words,Y.words),_=X.some((F)=>F.type==="removed"),z=q.some((F)=>F.type==="added");if(!_&&!z)return!1;let K=[],U=[];for(let F of X)if(F.type==="same")K.push(F.index);for(let F of q)if(F.type==="same")U.push(F.index);let H=new Map;for(let F=0;F<K.length&&F<U.length;F++)H.set(K[F],U[F]);let G=[];{let F=[],B=-1;for(let y of X)if(y.type==="same"){if(F.length>0)G.push({text:F.join(""),anchorNewIdx:B>=0?H.get(B)??null:null}),F=[];B=y.index}else if(y.type==="removed")F.push(Z.words[y.index]);if(F.length>0)G.push({text:F.join(""),anchorNewIdx:B>=0?H.get(B)??null:null})}let N=new Map,W=new Map;for(let F of q){if(F.type!=="added")continue;let B=Y.map[F.index];if(!B?.node.parentNode)continue;let y=N.get(B.node);if(!y)y=[],N.set(B.node,y);y.push({start:B.offset,end:B.offset+B.text.length})}for(let F of G)if(F.anchorNewIdx===null){if(Y.map.length>0){let B=Y.map[0].node,y=W.get(B);if(!y)y=[],W.set(B,y);y.push({offset:0,text:F.text})}}else{let B=Y.map[F.anchorNewIdx];if(!B)continue;let y=W.get(B.node);if(!y)y=[],W.set(B.node,y);y.push({offset:B.offset+B.text.length,text:F.text})}let M=new Set([...N.keys(),...W.keys()]);for(let F of M)b$(F,N.get(F)||[],W.get(F)||[]);return!0}function b$(J,$,Q){if(!J.parentNode)return;let Z=J.nodeValue||"";$.sort((U,H)=>U.start-H.start);let Y=[];for(let U of $){let H=Y[Y.length-1];if(H&&U.start<=H.end)H.end=Math.max(H.end,U.end);else Y.push({...U})}Q.sort((U,H)=>U.offset-H.offset);let X=J.parentNode,q=document.createDocumentFragment(),_=0,z=0,K=0;while(_<=Z.length){let U=z<Y.length?Y[z].start:1/0,H=K<Q.length?Q[K].offset:1/0,G=Math.min(U,H);if(G===1/0){if(_<Z.length)q.appendChild(document.createTextNode(Z.slice(_)));break}let N=Math.max(G,_);if(N>_)q.appendChild(document.createTextNode(Z.slice(_,N))),_=N;while(K<Q.length&&Q[K].offset<=_){let W=document.createElement("span");W.className="diff-removed",W.textContent=Q[K].text,q.appendChild(W),K++}if(z<Y.length&&Y[z].start<=_){let W=Y[z],M=document.createElement("span");M.className="diff-added",M.textContent=Z.slice(_,W.end),q.appendChild(M),_=W.end,z++;while(K<Q.length&&Q[K].offset<=_){let F=document.createElement("span");F.className="diff-removed",F.textContent=Q[K].text,q.appendChild(F),K++}}}while(K<Q.length){let U=document.createElement("span");U.className="diff-removed",U.textContent=Q[K].text,q.appendChild(U),K++}X.replaceChild(q,J)}function G2(J,$){let Q=(J.getAttribute("data-md-source")||"").trim(),Z=($.getAttribute("data-md-source")||"").trim();if(Q===Z)return!1;let Y=Q.split(`
109
+ `),N=B1(H,G),W=(M,F,L)=>{let y=document.createElement("div");y.className="mt-2 bg-bg-code rounded-md overflow-hidden text-tiny font-mono",y.setAttribute("data-no-diff","true");let S=0,R=0;while(R<M.length){let m=document.createElement("div");if(m.className="px-3 py-0.5 whitespace-pre-wrap",S<F.length&&M[R]===F[S])m.textContent=" "+M[R],R++,S++;else m.classList.add(L==="old"?"diff-removed":"diff-added"),m.textContent=(L==="old"?"- ":"+ ")+M[R],R++;y.appendChild(m)}return y};_.appendChild(W(H,N,"old")),z.appendChild(W(G,N,"new"))}return Y}function $5(J){let $=[],Q=J.querySelectorAll(":scope > [data-md]");for(let Z of Q)$.push(q0(Z));if($.length===0){let Z=J.querySelectorAll("[data-md]"),Y=new Set;for(let X of Z){let q=X.parentElement?.closest("[data-md]");if(q&&J.contains(q))continue;if(Y.has(X))continue;Y.add(X),$.push(q0(X))}}return $}function q0(J){let $=J.getAttribute("data-md")||"unknown",Q=M$(J,$),Z=[];if($==="section"){let Y=J.querySelector(":scope > div.mt-6, :scope > div:last-child");if(Y)for(let X of Y.querySelectorAll(":scope > [data-md]"))Z.push(q0(X))}else if($==="table")for(let Y of J.querySelectorAll(":scope table > tbody > tr"))Z.push({key:"tr:"+(Y.textContent||"").slice(0,80),type:"tr",element:Y,children:[]});else if($==="checklist")for(let Y of J.querySelectorAll(":scope > [data-md='checklist-item']"))Z.push(q0(Y));else for(let Y of J.querySelectorAll("[data-md]"))if(Y.parentElement?.closest("[data-md]")===J)Z.push(q0(Y));return{key:Q,type:$,element:J,children:Z}}function M$(J,$){switch($){case"section":return"section:"+(J.getAttribute("data-md-title")||"");case"item":return"item:"+(J.getAttribute("data-task-id")||J.getAttribute("data-md-label")||"");case"codeblock":case"diff":return $+":"+(J.textContent||"").slice(0,80);case"checklist-item":return"checklist-item:"+(J.getAttribute("data-md-label")||J.textContent?.slice(0,60)||"");case"checklist":return"checklist:"+J.querySelectorAll("[data-md='checklist-item']").length;case"markdown":return"markdown:"+(J.getAttribute("data-md-file")||"inline");case"mermaid":return"mermaid:"+(J.getAttribute("data-md-source")||"").slice(0,80);case"callout":return"callout:"+(J.getAttribute("data-md-type")||"")+":"+(J.textContent||"").slice(0,60);default:return $+":"+(J.getAttribute("data-md-label")||J.textContent?.slice(0,60)||"")}}function J5(J,$){let Q=J.map((K)=>K.key),Z=$.map((K)=>K.key),Y=B1(Q,Z),X=[],q=0,_=0,z=0;while(q<J.length||_<$.length)if(z<Y.length&&q<J.length&&_<$.length&&Q[q]===Y[z]&&Z[_]===Y[z]){let K=J[q],U=$[_],H=K.children.length>0||U.children.length>0?J5(K.children,U.children):void 0;X.push({kind:"matched",oldBlock:K,newBlock:U,childMatches:H}),q++,_++,z++}else if(q<J.length&&(z>=Y.length||Q[q]!==Y[z]))X.push({kind:"removed",oldBlock:J[q]}),q++;else if(_<$.length)X.push({kind:"added",newBlock:$[_]}),_++;return X}function X2(J){let $=document.createDocumentFragment(),Q=!1;for(let Z of J)if(Z.kind==="removed")Q=!0,$.appendChild(z2(Z.oldBlock.element));else if(Z.kind==="added")Q=!0,$.appendChild(B$(Z.newBlock.element));else{let Y=Z.newBlock.element.cloneNode(!0),X=Z.newBlock.type;if(X==="mermaid"){if(G2(Z.oldBlock.element,Y))Q=!0}else if(Z.childMatches&&Z.childMatches.length>0&&(X==="table"||X==="checklist")){if(K2(Y,Z.childMatches,X))Q=!0}else if(Z.childMatches&&Z.childMatches.length>0){if(_2(Z.oldBlock,Y,Z.childMatches,X))Q=!0}else if(X==="markdown"){if(U2(Z.oldBlock.element,Y))Q=!0}else if(V1(Z.oldBlock.element,Y,!1))Q=!0;$.appendChild(Y)}return{fragment:$,hasChanges:Q}}function z2(J){let $=J.cloneNode(!0);return $.classList.add("diff-block-removed"),$.style.position="relative",Y5($,"Removed","var(--color-accent-red)"),$}function B$(J){let $=J.cloneNode(!0);return $.classList.add("diff-block-added"),$.style.position="relative",Y5($,"Added","var(--color-accent-green)"),$}function _2(J,$,Q,Z){let Y=!1,X=L$(J,$),q,_;if(Z==="section"){let z=J.element.querySelector(":scope > div:first-child"),K=$.querySelector(":scope > div:first-child");if(z&&K){if(V1(z,K,!1))Y=!0}q=J.element.querySelector(":scope > div.mt-6, :scope > div:last-child"),_=$.querySelector(":scope > div.mt-6, :scope > div:last-child")}else q=J.element,_=$;if(!q||!_)return Y;for(let z of Q)if(z.kind==="matched"){let K=X.newMap.get(z.newBlock.element);if(K){if(z.newBlock.type==="mermaid"){if(G2(z.oldBlock.element,K))Y=!0}else if(z.childMatches&&z.childMatches.length>0&&(z.newBlock.type==="table"||z.newBlock.type==="checklist")){if(K2(K,z.childMatches,z.newBlock.type))Y=!0}else if(z.childMatches&&z.childMatches.length>0){if(_2(z.oldBlock,K,z.childMatches,z.newBlock.type))Y=!0}else if(z.newBlock.type==="markdown"){if(U2(z.oldBlock.element,K))Y=!0}else if(V1(z.oldBlock.element,K,!1))Y=!0}}else if(z.kind==="removed"){Y=!0;let K=z2(z.oldBlock.element),U=S$(Q,z,X.newMap);_.insertBefore(K,U)}else if(z.kind==="added"){Y=!0;let K=X.newMap.get(z.newBlock.element);if(K)K.classList.add("diff-block-added"),K.style.position="relative",Y5(K,"Added","var(--color-accent-green)")}if(V1(q,_,!0))Y=!0;return Y}function K2(J,$,Q){let Z=Q==="table"?J.querySelector(":scope table > tbody"):J;if(!Z)return!1;let Y=!1;Z.innerHTML="";for(let X of $)if(X.kind==="removed"){Y=!0;let q=X.oldBlock.element.cloneNode(!0);q.classList.add(Q==="table"?"diff-row-removed":"diff-item-removed"),Z.appendChild(q)}else if(X.kind==="added"){Y=!0;let q=X.newBlock.element.cloneNode(!0);q.classList.add(Q==="table"?"diff-row-added":"diff-item-added"),Z.appendChild(q)}else{let q=X.newBlock.element.cloneNode(!0);if(V1(X.oldBlock.element,q,!1))Y=!0;Z.appendChild(q)}return Y}function L$(J,$){let Q=new Map,Z=J.element.querySelectorAll("[data-md]"),Y=$.querySelectorAll("[data-md]");return{newMap:{get(X){return P$($,X)}}}}function P$(J,$){let Q=$.getAttribute("data-md");if(!Q)return null;let Z=$.getAttribute("data-md-label"),Y=$.getAttribute("data-md-title"),X=`[data-md="${Q}"]`;if(Y)X+=`[data-md-title="${CSS.escape(Y)}"]`;else if(Z)X+=`[data-md-label="${CSS.escape(Z)}"]`;let q=J.querySelectorAll(X);if(q.length===1)return q[0];let _=($.textContent||"").slice(0,100),z=null,K=-1;for(let U of q){let H=(U.textContent||"").slice(0,100),G=0;for(let N=0;N<Math.min(_.length,H.length);N++)if(_[N]===H[N])G++;if(G>K)K=G,z=U}return z}function S$(J,$,Q){let Z=J.indexOf($);for(let Y=Z+1;Y<J.length;Y++){let X=J[Y];if((X.kind==="matched"||X.kind==="added")&&X.newBlock)return Q.get(X.newBlock.element)||null}return null}function U2(J,$){let Q=Array.from(J.children),Z=Array.from($.children);if(Q.length===0&&Z.length===0)return V1(J,$,!1);let Y=Q.map((G)=>G.tagName.toLowerCase()),X=Z.map((G)=>G.tagName.toLowerCase()),q=B1(Y,X),_=[],z=0,K=0,U=0;while(z<Q.length||K<Z.length)if(U<q.length&&z<Q.length&&K<Z.length&&Y[z]===q[U]&&X[K]===q[U])_.push({kind:"matched",oldChild:Q[z],newChild:Z[K]}),z++,K++,U++;else if(z<Q.length&&(U>=q.length||Y[z]!==q[U]))_.push({kind:"removed",oldChild:Q[z]}),z++;else if(K<Z.length)_.push({kind:"added",newChild:Z[K]}),K++;let H=!1;while($.firstChild)$.removeChild($.firstChild);for(let G of _)if(G.kind==="matched"){let N=(G.oldChild.textContent||"").match(/\S+/g)||[],W=(G.newChild.textContent||"").match(/\S+/g)||[],M=B1(N,W),F=Math.max(N.length,W.length);if((F>0?1-M.length/F:0)>0.5){H=!0;let y=G.oldChild.cloneNode(!0);y.classList.add("diff-block-removed"),$.appendChild(y),G.newChild.classList.add("diff-block-added"),$.appendChild(G.newChild)}else{if(V1(G.oldChild,G.newChild,!1))H=!0;$.appendChild(G.newChild)}}else if(G.kind==="removed"){H=!0;let N=G.oldChild.cloneNode(!0);N.classList.add("diff-block-removed"),$.appendChild(N)}else H=!0,G.newChild.classList.add("diff-block-added"),$.appendChild(G.newChild);return H}function q2(J,$){let Q=$?new Set(Array.from(J.querySelectorAll("[data-md]"))):new Set,Z=[],Y=[],X=document.createTreeWalker(J,NodeFilter.SHOW_TEXT,{acceptNode(_){let z=_.parentElement;if(!z)return NodeFilter.FILTER_REJECT;if(z.closest("svg, .select-none, [data-no-diff]"))return NodeFilter.FILTER_REJECT;if($){for(let K of Q)if(K.contains(_))return NodeFilter.FILTER_REJECT}return NodeFilter.FILTER_ACCEPT}}),q;while(q=X.nextNode()){let z=(q.nodeValue||"").match(/\S+|\s+/g);if(!z)continue;let K=0;for(let U of z)Z.push(U),Y.push({text:U,node:q,offset:K}),K+=U.length}return{words:Z,map:Y}}function V1(J,$,Q){let Z=q2(J,Q),Y=q2($,Q);if(Z.words.length===0&&Y.words.length===0)return!1;let{oldOps:X,newOps:q}=e0(Z.words,Y.words),_=X.some((F)=>F.type==="removed"),z=q.some((F)=>F.type==="added");if(!_&&!z)return!1;let K=[],U=[];for(let F of X)if(F.type==="same")K.push(F.index);for(let F of q)if(F.type==="same")U.push(F.index);let H=new Map;for(let F=0;F<K.length&&F<U.length;F++)H.set(K[F],U[F]);let G=[];{let F=[],L=-1;for(let y of X)if(y.type==="same"){if(F.length>0)G.push({text:F.join(""),anchorNewIdx:L>=0?H.get(L)??null:null}),F=[];L=y.index}else if(y.type==="removed")F.push(Z.words[y.index]);if(F.length>0)G.push({text:F.join(""),anchorNewIdx:L>=0?H.get(L)??null:null})}let N=new Map,W=new Map;for(let F of q){if(F.type!=="added")continue;let L=Y.map[F.index];if(!L?.node.parentNode)continue;let y=N.get(L.node);if(!y)y=[],N.set(L.node,y);y.push({start:L.offset,end:L.offset+L.text.length})}for(let F of G)if(F.anchorNewIdx===null){if(Y.map.length>0){let L=Y.map[0].node,y=W.get(L);if(!y)y=[],W.set(L,y);y.push({offset:0,text:F.text})}}else{let L=Y.map[F.anchorNewIdx];if(!L)continue;let y=W.get(L.node);if(!y)y=[],W.set(L.node,y);y.push({offset:L.offset+L.text.length,text:F.text})}let M=new Set([...N.keys(),...W.keys()]);for(let F of M)b$(F,N.get(F)||[],W.get(F)||[]);return!0}function b$(J,$,Q){if(!J.parentNode)return;let Z=J.nodeValue||"";$.sort((U,H)=>U.start-H.start);let Y=[];for(let U of $){let H=Y[Y.length-1];if(H&&U.start<=H.end)H.end=Math.max(H.end,U.end);else Y.push({...U})}Q.sort((U,H)=>U.offset-H.offset);let X=J.parentNode,q=document.createDocumentFragment(),_=0,z=0,K=0;while(_<=Z.length){let U=z<Y.length?Y[z].start:1/0,H=K<Q.length?Q[K].offset:1/0,G=Math.min(U,H);if(G===1/0){if(_<Z.length)q.appendChild(document.createTextNode(Z.slice(_)));break}let N=Math.max(G,_);if(N>_)q.appendChild(document.createTextNode(Z.slice(_,N))),_=N;while(K<Q.length&&Q[K].offset<=_){let W=document.createElement("span");W.className="diff-removed",W.textContent=Q[K].text,q.appendChild(W),K++}if(z<Y.length&&Y[z].start<=_){let W=Y[z],M=document.createElement("span");M.className="diff-added",M.textContent=Z.slice(_,W.end),q.appendChild(M),_=W.end,z++;while(K<Q.length&&Q[K].offset<=_){let F=document.createElement("span");F.className="diff-removed",F.textContent=Q[K].text,q.appendChild(F),K++}}}while(K<Q.length){let U=document.createElement("span");U.className="diff-removed",U.textContent=Q[K].text,q.appendChild(U),K++}X.replaceChild(q,J)}function G2(J,$){let Q=(J.getAttribute("data-md-source")||"").trim(),Z=($.getAttribute("data-md-source")||"").trim();if(Q===Z)return!1;let Y=Q.split(`
110
110
  `),X=Z.split(`
111
- `),q=B1(Y,X),_=[],z=0,K=0,U=0;while(z<Y.length||K<X.length)if(U<q.length&&z<Y.length&&K<X.length&&Y[z]===q[U]&&X[K]===q[U])_.push({type:"same",line:Y[z]}),z++,K++,U++;else if(z<Y.length&&(U>=q.length||Y[z]!==q[U]))_.push({type:"removed",line:Y[z]}),z++;else if(K<X.length)_.push({type:"added",line:X[K]}),K++;let H=document.createElement("div");H.className="mt-2 bg-bg-code rounded-md overflow-hidden text-tiny font-mono",H.setAttribute("data-no-diff","true");for(let G of _){let N=document.createElement("div");if(N.className="px-3 py-0.5 whitespace-pre-wrap",G.type==="removed")N.classList.add("diff-removed"),N.textContent="- "+G.line;else if(G.type==="added")N.classList.add("diff-added"),N.textContent="+ "+G.line;else N.textContent=" "+G.line;H.appendChild(N)}return $.appendChild(H),!0}function Y5(J,$,Q){let Z=document.createElement("span");Z.className="diff-block-label",Z.textContent=$,Z.style.color=Q,Z.style.backgroundColor=`color-mix(in srgb, ${Q} 12%, transparent)`,J.appendChild(Z)}import{jsxDEV as D}from"react/jsx-dev-runtime";function H2({initialLeft:J,initialRight:$,sessionId:Q,onExit:Z}){let[Y,X]=Y1(J),[q,_]=Y1($),[z,K]=Y1("unified"),[U,H]=Y1(!0),[G,N]=Y1(!1);return D("div",{className:"flex flex-col h-screen",children:[D("div",{className:"flex items-center justify-between px-6 py-3 border-b border-border-subtle bg-bg-surface flex-shrink-0",children:[D("div",{className:"flex items-center gap-3",children:[D("span",{className:"text-[13px] font-body font-medium text-text-primary",children:"Compare"},void 0,!1,void 0,this),D(Z0,{value:Y,onChange:X,accent:"red"},void 0,!1,void 0,this),D("span",{className:"text-text-tertiary text-[13px]",children:"→"},void 0,!1,void 0,this),D(Z0,{value:q,onChange:_,accent:"green"},void 0,!1,void 0,this),G&&!U&&D("span",{className:"text-[11px] font-body text-text-tertiary bg-bg-elevated px-2 py-0.5 rounded",children:"No changes"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),D("div",{className:"flex items-center gap-4",children:[D("div",{className:"flex items-center bg-bg-elevated rounded-md p-0.5",children:[D("button",{onClick:()=>K("unified"),className:`text-[11px] font-body px-2.5 py-1 rounded transition-colors ${z==="unified"?"bg-bg-surface text-text-primary font-medium shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Unified"},void 0,!1,void 0,this),D("button",{onClick:()=>K("side-by-side"),className:`text-[11px] font-body px-2.5 py-1 rounded transition-colors ${z==="side-by-side"?"bg-bg-surface text-text-primary font-medium shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Side-by-side"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z==="side-by-side"&&D(w$,{},void 0,!1,void 0,this),D("button",{onClick:Z,className:"text-[12px] font-body font-medium text-text-secondary hover:text-text-primary px-3 py-1.5 rounded-md hover:bg-bg-elevated transition-colors",children:"Exit Compare"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),z==="unified"?D(R$,{sessionId:Q,leftRev:Y,rightRev:q,onDiffResult:(W,M)=>{N(W),H(M)}},`unified-${Y}-${q}`,!1,void 0,this):D(C$,{sessionId:Q,leftRev:Y,rightRev:q,onDiffResult:(W,M)=>{N(W),H(M)}},`sbs-${Y}-${q}`,!1,void 0,this)]},void 0,!0,void 0,this)}function w$(){let[J,$]=Y1(!0);return c1(()=>{return document.documentElement.dataset.syncScroll=J?"1":"0",()=>{delete document.documentElement.dataset.syncScroll}},[J]),D("label",{className:"flex items-center gap-1.5 cursor-pointer select-none",children:[D("input",{type:"checkbox",checked:J,onChange:(Q)=>$(Q.target.checked),className:"accent-accent-amber w-3.5 h-3.5"},void 0,!1,void 0,this),D("span",{className:"text-[11px] font-body text-text-secondary",children:"Sync scroll"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function R$({sessionId:J,leftRev:$,rightRev:Q,onDiffResult:Z}){let Y=L1(null),X=L1(null),q=L1(null),[_,z]=Y1(!1),[K,U]=Y1(!1),[H,G]=Y1(!1);return c1(()=>{if(!_||!K||H)return;if(!Y.current||!X.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!Y.current||!X.current||!q.current)return;let N=$5(Y.current),W=$5(X.current),M=J5(N,W),{fragment:F,hasChanges:B}=X2(M);q.current.innerHTML="",q.current.appendChild(F),G(!0),Z(!0,B)})})},[_,K,H]),D("div",{className:"flex-1 min-h-0 overflow-y-auto",children:[D("div",{style:{position:"absolute",left:-9999,visibility:"hidden",pointerEvents:"none",width:720},children:[D(w0,{ref:Y,sessionId:J,revision:$,onReady:()=>z(!0)},void 0,!1,void 0,this),D(w0,{ref:X,sessionId:J,revision:Q,onReady:()=>U(!0)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),D("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:[!H&&D("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-body",children:"Loading..."},void 0,!1,void 0,this),D("div",{ref:q},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function C$({sessionId:J,leftRev:$,rightRev:Q,onDiffResult:Z}){let Y=L1(null),X=L1(null),[q,_]=Y1(!1),[z,K]=Y1(!1),[U,H]=Y1(!1),G=L1(null),N=L1(null),W=L1(!1);return c1(()=>{if(!q||!z||U)return;if(!Y.current||!X.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!Y.current||!X.current)return;let M=Z2(Y.current,X.current);H(!0),Z(!0,M)})})},[q,z,U]),c1(()=>{let M=G.current,F=N.current;if(!M||!F)return;let B=(R,m)=>{if(document.documentElement.dataset.syncScroll==="0")return;if(W.current)return;W.current=!0;let k=R.scrollHeight-R.clientHeight,V=m.scrollHeight-m.clientHeight;if(k>0&&V>0)m.scrollTop=R.scrollTop/k*V;requestAnimationFrame(()=>{W.current=!1})},y=()=>B(M,F),S=()=>B(F,M);return M.addEventListener("scroll",y),F.addEventListener("scroll",S),()=>{M.removeEventListener("scroll",y),F.removeEventListener("scroll",S)}},[]),D("div",{className:"flex flex-1 min-h-0",children:[D("div",{ref:G,className:"w-1/2 overflow-y-auto border-r border-border-subtle",children:D("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:D(w0,{ref:Y,sessionId:J,revision:$,onReady:()=>_(!0)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),D("div",{ref:N,className:"w-1/2 overflow-y-auto",children:D("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:D(w0,{ref:X,sessionId:J,revision:Q,onReady:()=>K(!0)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var w0=A$.forwardRef(({sessionId:J,revision:$,onReady:Q},Z)=>{let[Y,X]=Y1(null),[q,_]=Y1(null),[z,K]=Y1(!0);if(c1(()=>{K(!0),_(null),import(`/api/session/${J}/plan.js?rev=${$}&t=${Date.now()}`).then((U)=>{X(()=>U.default),K(!1)}).catch((U)=>{_(U.message),K(!1)})},[J,$]),c1(()=>{if(!Y)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{Q()})})},[Y]),z)return D("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-body",children:"Loading..."},void 0,!1,void 0,this);if(q)return D("div",{className:"bg-accent-red-muted rounded-lg p-5",children:[D("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Error"},void 0,!1,void 0,this),D("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:q},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(!Y)return D("div",{className:"text-text-tertiary text-center py-8 font-body text-body",children:"No plan loaded"},void 0,!1,void 0,this);return D("div",{ref:Z,children:D(Y,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)});import{jsxDEV as O,Fragment as Q5}from"react/jsx-dev-runtime";var I1=W2({activeView:{type:"plan"},setActiveView:()=>{},openFiles:[],closeFile:()=>{}}),h1=W2({currentRevision:1,selectedRevision:1,revisions:[],setSelectedRevision:()=>{},isReadOnly:!1,compareRevision:null,setCompareRevision:()=>{}});function O2(){let[J,$]=Z1(()=>localStorage.getItem("canvas-theme")||document.documentElement.dataset.theme||"dark");return O("button",{onClick:()=>{let Z=J==="dark"?"light":"dark";document.documentElement.dataset.theme=Z,localStorage.setItem("canvas-theme",Z),$(Z)},className:"w-7 h-7 flex items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:J==="dark"?"Switch to light theme":"Switch to dark theme",children:J==="dark"?O("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[O("circle",{cx:"12",cy:"12",r:"5"},void 0,!1,void 0,this),O("line",{x1:"12",y1:"1",x2:"12",y2:"3"},void 0,!1,void 0,this),O("line",{x1:"12",y1:"21",x2:"12",y2:"23"},void 0,!1,void 0,this),O("line",{x1:"4.22",y1:"4.22",x2:"5.64",y2:"5.64"},void 0,!1,void 0,this),O("line",{x1:"18.36",y1:"18.36",x2:"19.78",y2:"19.78"},void 0,!1,void 0,this),O("line",{x1:"1",y1:"12",x2:"3",y2:"12"},void 0,!1,void 0,this),O("line",{x1:"21",y1:"12",x2:"23",y2:"12"},void 0,!1,void 0,this),O("line",{x1:"4.22",y1:"19.78",x2:"5.64",y2:"18.36"},void 0,!1,void 0,this),O("line",{x1:"18.36",y1:"5.64",x2:"19.78",y2:"4.22"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):O("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:O("path",{d:"M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function F2(){let{currentRevision:J,selectedRevision:$,revisions:Q,setSelectedRevision:Z,setCompareRevision:Y}=g1.useContext(h1);if(Q.length<=1){let _=Q[0]?.label||`Round ${J}`;return O("span",{className:"text-[11px] text-text-tertiary font-body",children:_},void 0,!1,void 0,this)}return O("div",{className:"flex flex-col gap-1",children:[O(Z0,{value:$,onChange:Z,accent:$===J?"default":"amber"},void 0,!1,void 0,this),O("button",{onClick:()=>{let _=Q.find((K)=>K.revision===$)?.sourceFile,z;if($===J)z=[...Q].reverse().find((U)=>U.revision<J&&(!_||U.sourceFile===_))?.revision??Math.max(1,J-1);else z=$;Y({left:z,right:J})},className:"text-[11px] font-body font-medium px-2 py-0.5 rounded-md text-accent-blue hover:bg-accent-blue-muted transition-colors self-start",children:"Compare"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function V$(){let J=window.location.pathname.replace("/s/","")||"",[$,Q]=Z1(1),[Z,Y]=Z1(1),[X,q]=Z1([]),[_,z]=Z1(null),[K,U]=Z1(!1),[H,G]=Z1(!1),[N,W]=Z1({type:"plan"}),[M,F]=Z1([]),B=d1(null),[y,S]=Z1(),[R,m]=Z1(!1),[k,V]=Z1(!1),[w,I]=Z1(!1);R0(()=>{let j=["Agent Canvas"];if(y){let i=y.replace(/\/+$/,"").split("/");j.push(i[i.length-1]||J)}else if(J)j.push(J);if(N.type==="file")j.push(N.path.split("/").pop()||N.path);else if(_)j.push("Compare");document.title=j.join(" — ")},[J,y,N,_]);let T=d1(new Map),L=X.find((j)=>j.revision===Z),c=Z!==$||!!L?.hasFeedback,o=C0((j)=>{if(T.current.set(N.type==="plan"?"plan":`file:${N.path}`,window.scrollY),W(j),j.type==="file")F((i)=>i.includes(j.path)?i:[...i,j.path])},[N]),Q1=C0((j)=>{T.current.delete(`file:${j}`),F((i)=>i.filter((b)=>b!==j)),W((i)=>{if(i.type==="file"&&i.path===j)return T.current.set(`file:${j}`,window.scrollY),{type:"plan"};return i})},[]);m$(()=>{let j=N.type==="plan"?"plan":`file:${N.path}`;window.scrollTo(0,T.current.get(j)||0)},[N]),R0(()=>{if(!J)return;fetch(`/api/session/${J}/meta`).then((j)=>j.json()).then((j)=>{if(j.currentRevision)Q(j.currentRevision),Y(j.currentRevision),q(j.revisions||[]);if(j.projectRoot)S(j.projectRoot)}).catch(()=>{})},[J]),R0(()=>{if(!J)return;let j=null,i=()=>{let b=window.location.protocol==="https:"?"wss:":"ws:",C=new WebSocket(`${b}//${window.location.host}/ws/session/${J}`);B.current=C,C.onopen=()=>U(!0),C.onclose=()=>{U(!1),j=setTimeout(i,2000)},C.onmessage=(h)=>{try{let E=JSON.parse(h.data);if(E.type==="plan-updated"){if(Q(E.currentRevision),Y(E.currentRevision),z(null),E.revisions)q(E.revisions)}if(E.type==="revision-updated"){if(E.revisions)q(E.revisions)}}catch{}}};return i(),()=>{if(j)clearTimeout(j);B.current?.close()}},[J]);let P1=C0((j)=>{if(B.current?.readyState===WebSocket.OPEN)B.current.send(JSON.stringify({type:"submit",feedback:j})),G(!1)},[]);if(!J)return O("div",{className:"flex items-center justify-center h-screen text-text-tertiary font-body",children:"No session selected."},void 0,!1,void 0,this);return O(T2.Provider,{value:J,children:O(h1.Provider,{value:{currentRevision:$,selectedRevision:Z,revisions:X,setSelectedRevision:Y,isReadOnly:c,compareRevision:_,setCompareRevision:z},children:O(X5,{sessionId:J,revision:Z,isReadOnly:c,children:O(I1.Provider,{value:{activeView:N,setActiveView:o,openFiles:M,closeFile:Q1},children:O(I$.Provider,{value:{setActiveView:o},children:O("div",{className:"min-h-screen bg-bg-base",children:[O(g$,{sessionId:J,projectRoot:y,connected:K,onMobileSidebar:()=>m(!R),collapsed:k,onToggle:()=>V((j)=>!j)},void 0,!1,void 0,this),_===null&&O(D$,{collapsed:w,onToggle:()=>I((j)=>!j),children:O(s0,{onPreview:()=>G(!0),onSubmit:P1},void 0,!1,void 0,this)},void 0,!1,void 0,this),_!==null?O("div",{className:`${k?"lg:ml-0":"lg:ml-60"} transition-[margin] duration-200`,children:O(H2,{initialLeft:_.left,initialRight:_.right,sessionId:J,onExit:()=>z(null)},void 0,!1,void 0,this)},void 0,!1,void 0,this):O("div",{className:`relative ${k?"lg:ml-0":"lg:ml-60"} ${w?"lg:mr-0":"lg:mr-[var(--sidebar-width,320px)]"} transition-[margin] duration-200`,id:"plan-scroll-container",children:[O("div",{className:"lg:hidden sticky top-0 z-20 flex items-center justify-between px-4 py-2 border-b border-border-subtle bg-bg-surface",children:[O("div",{className:"flex items-center gap-2",children:[O(n0,{currentSessionId:J,projectRoot:y},void 0,!1,void 0,this),O("span",{className:`w-1.5 h-1.5 rounded-full ${K?"bg-accent-green":"bg-accent-red"}`},void 0,!1,void 0,this)]},void 0,!0,void 0,this),O("div",{className:"flex items-center gap-1",children:[O(F2,{},void 0,!1,void 0,this),O("button",{onClick:()=>m(!R),className:"w-7 h-7 flex items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Annotations",children:O("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:O("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),O(O2,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),O(f$,{},void 0,!1,void 0,this),O("div",{style:{display:N.type==="plan"?void 0:"none"},children:O("div",{className:"relative max-w-[720px] mx-auto px-6 pt-12 pb-32",children:[O("button",{onClick:()=>{let j=document.querySelector(".plan-content");if(!j)return;let i=n5(j);navigator.clipboard.writeText(i).then(()=>{let b=document.getElementById("export-md-btn");if(b)b.setAttribute("data-copied","true"),setTimeout(()=>{b.removeAttribute("data-copied")},1500)})},id:"export-md-btn",className:"group absolute top-3 right-6 p-1.5 text-text-tertiary hover:text-text-secondary transition-colors z-10",title:"Copy as Markdown",children:[O("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"group-[[data-copied=true]]:hidden",children:[O("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"},void 0,!1,void 0,this),O("path",{d:"M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),O("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"hidden group-[[data-copied=true]]:block text-green-500",children:O("polyline",{points:"20 6 9 17 4 12"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),O(F5,{revision:Z},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),M.map((j)=>O("div",{style:{display:N.type==="file"&&N.path===j?void 0:"none"},children:O(i5,{path:j},void 0,!1,void 0,this)},j,!1,void 0,this))]},void 0,!0,void 0,this),R&&O("div",{className:"lg:hidden fixed inset-0 z-40 flex",children:[O("div",{className:"flex-1",onClick:()=>m(!1)},void 0,!1,void 0,this),O("div",{className:"w-80 max-w-[85vw] bg-bg-surface border-l border-border-subtle flex flex-col shadow-lg",children:[O("div",{className:"flex items-center justify-between px-4 py-2 border-b border-border-subtle flex-shrink-0",children:[O("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:"Sidebar"},void 0,!1,void 0,this),O("button",{onClick:()=>m(!1),className:"text-text-tertiary hover:text-text-secondary w-7 h-7 flex items-center justify-center",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),O("div",{className:"flex-1 overflow-hidden",children:O(s0,{onPreview:()=>G(!0),onSubmit:P1},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),O(E5,{open:H,onClose:()=>G(!1),onSubmit:P1},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},`${J}:${Z}`,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function g$({sessionId:J,projectRoot:$,connected:Q,onMobileSidebar:Z,collapsed:Y,onToggle:X}){return O(Q5,{children:[Y&&O("button",{onClick:X,className:"hidden lg:flex fixed top-3 left-3 z-20 w-7 h-7 items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors bg-bg-surface border border-border-subtle",title:"Show sidebar",children:O("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[O("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"},void 0,!1,void 0,this),O("line",{x1:"9",y1:"3",x2:"9",y2:"21"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),O("div",{className:`hidden lg:flex w-60 flex-col fixed top-0 left-0 bottom-0 bg-bg-surface border-r border-border-subtle z-10 transition-transform duration-200 ${Y?"-translate-x-full":""}`,children:[O("div",{className:"px-4 pt-4 pb-3 flex-shrink-0 border-b border-border-subtle",children:[O("div",{className:"flex items-center gap-2 mb-2",children:[O("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",className:"text-text-tertiary flex-shrink-0",children:O("path",{d:"M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this),O(n0,{currentSessionId:J,projectRoot:$},void 0,!1,void 0,this),O("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${Q?"bg-accent-green":"bg-accent-red"}`},void 0,!1,void 0,this),O("button",{onClick:X,className:"ml-auto w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Hide sidebar",children:O("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[O("polyline",{points:"11 17 6 12 11 7"},void 0,!1,void 0,this),O("polyline",{points:"18 17 13 12 18 7"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),O(F2,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this),O("div",{className:"flex-1 flex flex-col overflow-hidden",children:O(d5,{embedded:!0},void 0,!1,void 0,this)},void 0,!1,void 0,this),O("div",{className:"px-4 py-3 border-t border-border-subtle flex items-center justify-between flex-shrink-0",children:[O("span",{className:"text-[10px] text-text-tertiary font-body uppercase tracking-widest",children:"Theme"},void 0,!1,void 0,this),O(O2,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function D$({children:J,collapsed:$,onToggle:Q}){let[Z,Y]=Z1(()=>{let U=localStorage.getItem("canvas-sidebar-width");return U?parseInt(U,10):320}),X=d1(!1),q=d1(0),_=d1(0),z=d1(Z);z.current=Z;let K=C0((U)=>{U.preventDefault(),X.current=!0,q.current=U.clientX,_.current=z.current;let H=(N)=>{if(!X.current)return;let W=q.current-N.clientX,M=Math.max(240,Math.min(600,_.current+W));Y(M),z.current=M},G=()=>{X.current=!1,localStorage.setItem("canvas-sidebar-width",String(z.current)),document.removeEventListener("mousemove",H),document.removeEventListener("mouseup",G),document.body.style.cursor="",document.body.style.userSelect=""};document.addEventListener("mousemove",H),document.addEventListener("mouseup",G),document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[]);return R0(()=>{return document.documentElement.style.setProperty("--sidebar-width",`${Z}px`),()=>{document.documentElement.style.removeProperty("--sidebar-width")}},[Z]),O(Q5,{children:[$&&O("button",{onClick:Q,className:"hidden lg:flex fixed top-3 right-3 z-20 w-7 h-7 items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors bg-bg-surface border border-border-subtle",title:"Show annotations",children:O("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:O("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),O("div",{className:`hidden lg:flex flex-col fixed top-0 right-0 bottom-0 bg-bg-surface border-l border-border-subtle z-10 transition-transform duration-200 ${$?"translate-x-full":""}`,style:{width:Z},children:[O("div",{onMouseDown:K,className:"absolute left-0 top-0 bottom-0 w-1 cursor-col-resize hover:bg-accent-blue/30 transition-colors z-20",style:{marginLeft:"-2px"}},void 0,!1,void 0,this),g1.Children.map(J,(U)=>g1.isValidElement(U)?g1.cloneElement(U,{collapseButton:O("button",{onClick:Q,className:"w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Hide annotations",children:O("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[O("polyline",{points:"13 17 18 12 13 7"},void 0,!1,void 0,this),O("polyline",{points:"6 17 11 12 6 7"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}):U)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function f$(){let{activeView:J,setActiveView:$,openFiles:Q,closeFile:Z}=g1.useContext(I1),Y=g1.useContext(T2),{addAnnotationWithId:X,setActiveAnnotationId:q}=q1(),_=Q.length>0;if(!_)return null;return O("div",{className:"flex items-center border-b border-border-medium bg-bg-surface overflow-x-auto sticky top-0 z-10",children:[_&&O("button",{onClick:()=>$({type:"plan"}),className:`flex items-center gap-1.5 px-4 py-2.5 text-[13px] font-body whitespace-nowrap transition-colors relative ${J.type==="plan"?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[O("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",className:"opacity-60",children:O("path",{d:"M12 2L2 7l10 5 10-5-10-5z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this),"Plan",J.type==="plan"&&O("span",{className:"absolute bottom-0 left-3 right-3 h-[2px] bg-text-primary rounded-full"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),_&&O(Q5,{children:[O("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this),Q.map((z,K)=>{let U=z.split("/").pop()||z,H=J.type==="file"&&J.path===z;return O(g1.Fragment,{children:[O("div",{className:"flex items-center",children:[O("button",{onClick:()=>$({type:"file",path:z}),className:`flex items-center gap-1.5 pl-3 pr-1 py-2.5 text-[13px] font-mono whitespace-nowrap transition-colors relative ${H?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[U,H&&O("span",{className:"absolute bottom-0 left-3 right-1 h-[2px] bg-text-primary rounded-full"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),O("button",{onClick:(G)=>{G.stopPropagation(),Z(z)},className:"text-text-tertiary hover:text-text-secondary px-1.5 py-1 text-[10px] transition-colors rounded hover:bg-bg-input",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),K<Q.length-1&&O("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this)]},z,!0,void 0,this)})]},void 0,!0,void 0,this),O("div",{className:"ml-auto flex items-center gap-1 flex-shrink-0",children:J.type==="file"&&O("button",{onClick:async()=>{let z=J.path;try{let U=await(await fetch(`/api/file?session=${Y}&path=${encodeURIComponent(z)}`)).json();if(!U.error){let H=U.content.split(`
111
+ `),q=B1(Y,X),_=[],z=0,K=0,U=0;while(z<Y.length||K<X.length)if(U<q.length&&z<Y.length&&K<X.length&&Y[z]===q[U]&&X[K]===q[U])_.push({type:"same",line:Y[z]}),z++,K++,U++;else if(z<Y.length&&(U>=q.length||Y[z]!==q[U]))_.push({type:"removed",line:Y[z]}),z++;else if(K<X.length)_.push({type:"added",line:X[K]}),K++;let H=document.createElement("div");H.className="mt-2 bg-bg-code rounded-md overflow-hidden text-tiny font-mono",H.setAttribute("data-no-diff","true");for(let G of _){let N=document.createElement("div");if(N.className="px-3 py-0.5 whitespace-pre-wrap",G.type==="removed")N.classList.add("diff-removed"),N.textContent="- "+G.line;else if(G.type==="added")N.classList.add("diff-added"),N.textContent="+ "+G.line;else N.textContent=" "+G.line;H.appendChild(N)}return $.appendChild(H),!0}function Y5(J,$,Q){let Z=document.createElement("span");Z.className="diff-block-label",Z.textContent=$,Z.style.color=Q,Z.style.backgroundColor=`color-mix(in srgb, ${Q} 12%, transparent)`,J.appendChild(Z)}import{jsxDEV as D}from"react/jsx-dev-runtime";function H2({initialLeft:J,initialRight:$,sessionId:Q,onExit:Z}){let[Y,X]=Y1(J),[q,_]=Y1($),[z,K]=Y1("unified"),[U,H]=Y1(!0),[G,N]=Y1(!1);return D("div",{className:"flex flex-col h-screen",children:[D("div",{className:"flex items-center justify-between px-6 py-3 border-b border-border-subtle bg-bg-surface flex-shrink-0",children:[D("div",{className:"flex items-center gap-3",children:[D("span",{className:"text-[13px] font-body font-medium text-text-primary",children:"Compare"},void 0,!1,void 0,this),D(Z0,{value:Y,onChange:X,accent:"red"},void 0,!1,void 0,this),D("span",{className:"text-text-tertiary text-[13px]",children:"→"},void 0,!1,void 0,this),D(Z0,{value:q,onChange:_,accent:"green"},void 0,!1,void 0,this),G&&!U&&D("span",{className:"text-[11px] font-body text-text-tertiary bg-bg-elevated px-2 py-0.5 rounded",children:"No changes"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),D("div",{className:"flex items-center gap-4",children:[D("div",{className:"flex items-center bg-bg-elevated rounded-md p-0.5",children:[D("button",{onClick:()=>K("unified"),className:`text-[11px] font-body px-2.5 py-1 rounded transition-colors ${z==="unified"?"bg-bg-surface text-text-primary font-medium shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Unified"},void 0,!1,void 0,this),D("button",{onClick:()=>K("side-by-side"),className:`text-[11px] font-body px-2.5 py-1 rounded transition-colors ${z==="side-by-side"?"bg-bg-surface text-text-primary font-medium shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Side-by-side"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z==="side-by-side"&&D(w$,{},void 0,!1,void 0,this),D("button",{onClick:Z,className:"text-[12px] font-body font-medium text-text-secondary hover:text-text-primary px-3 py-1.5 rounded-md hover:bg-bg-elevated transition-colors",children:"Exit Compare"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),z==="unified"?D(R$,{sessionId:Q,leftRev:Y,rightRev:q,onDiffResult:(W,M)=>{N(W),H(M)}},`unified-${Y}-${q}`,!1,void 0,this):D(C$,{sessionId:Q,leftRev:Y,rightRev:q,onDiffResult:(W,M)=>{N(W),H(M)}},`sbs-${Y}-${q}`,!1,void 0,this)]},void 0,!0,void 0,this)}function w$(){let[J,$]=Y1(!0);return c1(()=>{return document.documentElement.dataset.syncScroll=J?"1":"0",()=>{delete document.documentElement.dataset.syncScroll}},[J]),D("label",{className:"flex items-center gap-1.5 cursor-pointer select-none",children:[D("input",{type:"checkbox",checked:J,onChange:(Q)=>$(Q.target.checked),className:"accent-accent-amber w-3.5 h-3.5"},void 0,!1,void 0,this),D("span",{className:"text-[11px] font-body text-text-secondary",children:"Sync scroll"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function R$({sessionId:J,leftRev:$,rightRev:Q,onDiffResult:Z}){let Y=L1(null),X=L1(null),q=L1(null),[_,z]=Y1(!1),[K,U]=Y1(!1),[H,G]=Y1(!1);return c1(()=>{if(!_||!K||H)return;if(!Y.current||!X.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!Y.current||!X.current||!q.current)return;let N=$5(Y.current),W=$5(X.current),M=J5(N,W),{fragment:F,hasChanges:L}=X2(M);q.current.innerHTML="",q.current.appendChild(F),G(!0),Z(!0,L)})})},[_,K,H]),D("div",{className:"flex-1 min-h-0 overflow-y-auto",children:[D("div",{style:{position:"absolute",left:-9999,visibility:"hidden",pointerEvents:"none",width:720},children:[D(R0,{ref:Y,sessionId:J,revision:$,onReady:()=>z(!0)},void 0,!1,void 0,this),D(R0,{ref:X,sessionId:J,revision:Q,onReady:()=>U(!0)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),D("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:[!H&&D("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-body",children:"Loading..."},void 0,!1,void 0,this),D("div",{ref:q},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function C$({sessionId:J,leftRev:$,rightRev:Q,onDiffResult:Z}){let Y=L1(null),X=L1(null),[q,_]=Y1(!1),[z,K]=Y1(!1),[U,H]=Y1(!1),G=L1(null),N=L1(null),W=L1(!1);return c1(()=>{if(!q||!z||U)return;if(!Y.current||!X.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!Y.current||!X.current)return;let M=Z2(Y.current,X.current);H(!0),Z(!0,M)})})},[q,z,U]),c1(()=>{let M=G.current,F=N.current;if(!M||!F)return;let L=(R,m)=>{if(document.documentElement.dataset.syncScroll==="0")return;if(W.current)return;W.current=!0;let k=R.scrollHeight-R.clientHeight,V=m.scrollHeight-m.clientHeight;if(k>0&&V>0)m.scrollTop=R.scrollTop/k*V;requestAnimationFrame(()=>{W.current=!1})},y=()=>L(M,F),S=()=>L(F,M);return M.addEventListener("scroll",y),F.addEventListener("scroll",S),()=>{M.removeEventListener("scroll",y),F.removeEventListener("scroll",S)}},[]),D("div",{className:"flex flex-1 min-h-0",children:[D("div",{ref:G,className:"w-1/2 overflow-y-auto border-r border-border-subtle",children:D("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:D(R0,{ref:Y,sessionId:J,revision:$,onReady:()=>_(!0)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),D("div",{ref:N,className:"w-1/2 overflow-y-auto",children:D("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:D(R0,{ref:X,sessionId:J,revision:Q,onReady:()=>K(!0)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var R0=A$.forwardRef(({sessionId:J,revision:$,onReady:Q},Z)=>{let[Y,X]=Y1(null),[q,_]=Y1(null),[z,K]=Y1(!0);if(c1(()=>{K(!0),_(null),import(`/api/session/${J}/plan.js?rev=${$}&t=${Date.now()}`).then((U)=>{X(()=>U.default),K(!1)}).catch((U)=>{_(U.message),K(!1)})},[J,$]),c1(()=>{if(!Y)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{Q()})})},[Y]),z)return D("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-body",children:"Loading..."},void 0,!1,void 0,this);if(q)return D("div",{className:"bg-accent-red-muted rounded-lg p-5",children:[D("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Error"},void 0,!1,void 0,this),D("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:q},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(!Y)return D("div",{className:"text-text-tertiary text-center py-8 font-body text-body",children:"No plan loaded"},void 0,!1,void 0,this);return D("div",{ref:Z,children:D(Y,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)});import{jsxDEV as O,Fragment as Q5}from"react/jsx-dev-runtime";var I1=W2({activeView:{type:"plan"},setActiveView:()=>{},openFiles:[],closeFile:()=>{}}),h1=W2({currentRevision:1,selectedRevision:1,revisions:[],setSelectedRevision:()=>{},isReadOnly:!1,compareRevision:null,setCompareRevision:()=>{}});function O2(){let[J,$]=Q1(()=>localStorage.getItem("canvas-theme")||document.documentElement.dataset.theme||"dark");return O("button",{onClick:()=>{let Z=J==="dark"?"light":"dark";document.documentElement.dataset.theme=Z,localStorage.setItem("canvas-theme",Z),$(Z)},className:"w-7 h-7 flex items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:J==="dark"?"Switch to light theme":"Switch to dark theme",children:J==="dark"?O("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[O("circle",{cx:"12",cy:"12",r:"5"},void 0,!1,void 0,this),O("line",{x1:"12",y1:"1",x2:"12",y2:"3"},void 0,!1,void 0,this),O("line",{x1:"12",y1:"21",x2:"12",y2:"23"},void 0,!1,void 0,this),O("line",{x1:"4.22",y1:"4.22",x2:"5.64",y2:"5.64"},void 0,!1,void 0,this),O("line",{x1:"18.36",y1:"18.36",x2:"19.78",y2:"19.78"},void 0,!1,void 0,this),O("line",{x1:"1",y1:"12",x2:"3",y2:"12"},void 0,!1,void 0,this),O("line",{x1:"21",y1:"12",x2:"23",y2:"12"},void 0,!1,void 0,this),O("line",{x1:"4.22",y1:"19.78",x2:"5.64",y2:"18.36"},void 0,!1,void 0,this),O("line",{x1:"18.36",y1:"5.64",x2:"19.78",y2:"4.22"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):O("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:O("path",{d:"M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function F2(){let{currentRevision:J,selectedRevision:$,revisions:Q,setSelectedRevision:Z,setCompareRevision:Y}=g1.useContext(h1);if(Q.length<=1){let _=Q[0]?.label||`Round ${J}`;return O("span",{className:"text-[11px] text-text-tertiary font-body",children:_},void 0,!1,void 0,this)}return O("div",{className:"flex flex-col gap-1",children:[O(Z0,{value:$,onChange:Z,accent:$===J?"default":"amber"},void 0,!1,void 0,this),O("button",{onClick:()=>{let _=Q.find((K)=>K.revision===$)?.sourceFile,z;if($===J)z=[...Q].reverse().find((U)=>U.revision<J&&(!_||U.sourceFile===_))?.revision??Math.max(1,J-1);else z=$;Y({left:z,right:J})},className:"text-[11px] font-body font-medium px-2 py-0.5 rounded-md text-accent-blue hover:bg-accent-blue-muted transition-colors self-start",children:"Compare"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function g$(){let J=window.location.pathname.replace("/s/","")||"",[$,Q]=Q1(1),[Z,Y]=Q1(1),[X,q]=Q1([]),[_,z]=Q1(null),[K,U]=Q1(!1),[H,G]=Q1(!1),[N,W]=Q1({type:"plan"}),[M,F]=Q1([]),L=d1(null),[y,S]=Q1(),[R,m]=Q1(!1),[k,V]=Q1(!1),[w,I]=Q1(!1);X0(()=>{let j=["Agent Canvas"];if(y){let i=y.replace(/\/+$/,"").split("/");j.push(i[i.length-1]||J)}else if(J)j.push(J);if(N.type==="file")j.push(N.path.split("/").pop()||N.path);else if(_)j.push("Compare");document.title=j.join(" — ")},[J,y,N,_]);let T=d1(new Map),B=X.find((j)=>j.revision===Z),c=Z!==$||!!B?.hasFeedback,o=C0((j)=>{if(T.current.set(N.type==="plan"?"plan":`file:${N.path}`,window.scrollY),W(j),j.type==="file")F((i)=>i.includes(j.path)?i:[...i,j.path])},[N]),Z1=C0((j)=>{T.current.delete(`file:${j}`),F((i)=>i.filter((b)=>b!==j)),W((i)=>{if(i.type==="file"&&i.path===j)return T.current.set(`file:${j}`,window.scrollY),{type:"plan"};return i})},[]);m$(()=>{let j=N.type==="plan"?"plan":`file:${N.path}`;window.scrollTo(0,T.current.get(j)||0)},[N]),X0(()=>{if(!J)return;fetch(`/api/session/${J}/meta`).then((j)=>j.json()).then((j)=>{if(j.currentRevision)Q(j.currentRevision),Y(j.currentRevision),q(j.revisions||[]);if(j.projectRoot)S(j.projectRoot)}).catch(()=>{})},[J]),X0(()=>{if(!J)return;let j=null,i=()=>{let b=window.location.protocol==="https:"?"wss:":"ws:",C=new WebSocket(`${b}//${window.location.host}/ws/session/${J}`);L.current=C,C.onopen=()=>U(!0),C.onclose=()=>{U(!1),j=setTimeout(i,2000)},C.onmessage=(h)=>{try{let x=JSON.parse(h.data);if(x.type==="plan-updated"){if(Q(x.currentRevision),Y(x.currentRevision),z(null),x.revisions)q(x.revisions)}if(x.type==="revision-updated"){if(x.revisions)q(x.revisions)}}catch{}}};return i(),()=>{if(j)clearTimeout(j);L.current?.close()}},[J]);let P1=C0((j)=>{if(L.current?.readyState===WebSocket.OPEN)L.current.send(JSON.stringify({type:"submit",feedback:j})),G(!1)},[]);if(!J)return O("div",{className:"flex items-center justify-center h-screen text-text-tertiary font-body",children:"No session selected."},void 0,!1,void 0,this);return O(T2.Provider,{value:J,children:O(h1.Provider,{value:{currentRevision:$,selectedRevision:Z,revisions:X,setSelectedRevision:Y,isReadOnly:c,compareRevision:_,setCompareRevision:z},children:O(b5,{sessionId:J,revision:Z,isReadOnly:c,children:O(I1.Provider,{value:{activeView:N,setActiveView:o,openFiles:M,closeFile:Z1},children:O(V$.Provider,{value:{setActiveView:o},children:O("div",{className:"min-h-screen bg-bg-base",children:[O(D$,{sessionId:J,projectRoot:y,connected:K,onMobileSidebar:()=>m(!R),collapsed:k,onToggle:()=>V((j)=>!j)},void 0,!1,void 0,this),_===null&&O(f$,{collapsed:w,onToggle:()=>I((j)=>!j),children:O(s0,{onPreview:()=>G(!0),onSubmit:P1},void 0,!1,void 0,this)},void 0,!1,void 0,this),_!==null?O("div",{className:`${k?"lg:ml-0":"lg:ml-60"} transition-[margin] duration-200`,children:O(H2,{initialLeft:_.left,initialRight:_.right,sessionId:J,onExit:()=>z(null)},void 0,!1,void 0,this)},void 0,!1,void 0,this):O("div",{className:`relative ${k?"lg:ml-0":"lg:ml-60"} ${w?"lg:mr-0":"lg:mr-[var(--sidebar-width,320px)]"} transition-[margin] duration-200`,id:"plan-scroll-container",children:[O("div",{className:"lg:hidden sticky top-0 z-20 flex items-center justify-between px-4 py-2 border-b border-border-subtle bg-bg-surface",children:[O("div",{className:"flex items-center gap-2",children:[O(n0,{currentSessionId:J,projectRoot:y},void 0,!1,void 0,this),O("span",{className:`w-1.5 h-1.5 rounded-full ${K?"bg-accent-green":"bg-accent-red"}`},void 0,!1,void 0,this)]},void 0,!0,void 0,this),O("div",{className:"flex items-center gap-1",children:[O(F2,{},void 0,!1,void 0,this),O("button",{onClick:()=>m(!R),className:"w-7 h-7 flex items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Annotations",children:O("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:O("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),O(O2,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),O(u$,{},void 0,!1,void 0,this),O("div",{style:{display:N.type==="plan"?void 0:"none"},children:O("div",{className:"relative max-w-[720px] mx-auto px-6 pt-12 pb-32",children:[O("button",{onClick:()=>{let j=document.querySelector(".plan-content");if(!j)return;let i=n5(j);navigator.clipboard.writeText(i).then(()=>{let b=document.getElementById("export-md-btn");if(b)b.setAttribute("data-copied","true"),setTimeout(()=>{b.removeAttribute("data-copied")},1500)})},id:"export-md-btn",className:"group absolute top-3 right-6 p-1.5 text-text-tertiary hover:text-text-secondary transition-colors z-10",title:"Copy as Markdown",children:[O("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"group-[[data-copied=true]]:hidden",children:[O("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"},void 0,!1,void 0,this),O("path",{d:"M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),O("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"hidden group-[[data-copied=true]]:block text-green-500",children:O("polyline",{points:"20 6 9 17 4 12"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),B?.response&&O(k$,{markdown:B.response},void 0,!1,void 0,this),O(f5,{revision:Z},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),M.map((j)=>O("div",{style:{display:N.type==="file"&&N.path===j?void 0:"none"},children:O(i5,{path:j},void 0,!1,void 0,this)},j,!1,void 0,this))]},void 0,!0,void 0,this),R&&O("div",{className:"lg:hidden fixed inset-0 z-40 flex",children:[O("div",{className:"flex-1",onClick:()=>m(!1)},void 0,!1,void 0,this),O("div",{className:"w-80 max-w-[85vw] bg-bg-surface border-l border-border-subtle flex flex-col shadow-lg",children:[O("div",{className:"flex items-center justify-between px-4 py-2 border-b border-border-subtle flex-shrink-0",children:[O("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:"Sidebar"},void 0,!1,void 0,this),O("button",{onClick:()=>m(!1),className:"text-text-tertiary hover:text-text-secondary w-7 h-7 flex items-center justify-center",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),O("div",{className:"flex-1 overflow-hidden",children:O(s0,{onPreview:()=>G(!0),onSubmit:P1},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),O(E5,{open:H,onClose:()=>G(!1),onSubmit:P1},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},`${J}:${Z}`,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function D$({sessionId:J,projectRoot:$,connected:Q,onMobileSidebar:Z,collapsed:Y,onToggle:X}){return O(Q5,{children:[Y&&O("button",{onClick:X,className:"hidden lg:flex fixed top-3 left-3 z-20 w-7 h-7 items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors bg-bg-surface border border-border-subtle",title:"Show sidebar",children:O("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[O("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"},void 0,!1,void 0,this),O("line",{x1:"9",y1:"3",x2:"9",y2:"21"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),O("div",{className:`hidden lg:flex w-60 flex-col fixed top-0 left-0 bottom-0 bg-bg-surface border-r border-border-subtle z-10 transition-transform duration-200 ${Y?"-translate-x-full":""}`,children:[O("div",{className:"px-4 pt-4 pb-3 flex-shrink-0 border-b border-border-subtle",children:[O("div",{className:"flex items-center gap-2 mb-2",children:[O("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",className:"text-text-tertiary flex-shrink-0",children:O("path",{d:"M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this),O(n0,{currentSessionId:J,projectRoot:$},void 0,!1,void 0,this),O("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${Q?"bg-accent-green":"bg-accent-red"}`},void 0,!1,void 0,this),O("button",{onClick:X,className:"ml-auto w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Hide sidebar",children:O("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[O("polyline",{points:"11 17 6 12 11 7"},void 0,!1,void 0,this),O("polyline",{points:"18 17 13 12 18 7"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),O(F2,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this),O("div",{className:"flex-1 flex flex-col overflow-hidden",children:O(d5,{embedded:!0},void 0,!1,void 0,this)},void 0,!1,void 0,this),O("div",{className:"px-4 py-3 border-t border-border-subtle flex items-center justify-between flex-shrink-0",children:[O("span",{className:"text-[10px] text-text-tertiary font-body uppercase tracking-widest",children:"Theme"},void 0,!1,void 0,this),O(O2,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function f$({children:J,collapsed:$,onToggle:Q}){let[Z,Y]=Q1(()=>{let U=localStorage.getItem("canvas-sidebar-width");return U?parseInt(U,10):320}),X=d1(!1),q=d1(0),_=d1(0),z=d1(Z);z.current=Z;let K=C0((U)=>{U.preventDefault(),X.current=!0,q.current=U.clientX,_.current=z.current;let H=(N)=>{if(!X.current)return;let W=q.current-N.clientX,M=Math.max(240,Math.min(600,_.current+W));Y(M),z.current=M},G=()=>{X.current=!1,localStorage.setItem("canvas-sidebar-width",String(z.current)),document.removeEventListener("mousemove",H),document.removeEventListener("mouseup",G),document.body.style.cursor="",document.body.style.userSelect=""};document.addEventListener("mousemove",H),document.addEventListener("mouseup",G),document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[]);return X0(()=>{return document.documentElement.style.setProperty("--sidebar-width",`${Z}px`),()=>{document.documentElement.style.removeProperty("--sidebar-width")}},[Z]),O(Q5,{children:[$&&O("button",{onClick:Q,className:"hidden lg:flex fixed top-3 right-3 z-20 w-7 h-7 items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors bg-bg-surface border border-border-subtle",title:"Show annotations",children:O("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:O("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),O("div",{className:`hidden lg:flex flex-col fixed top-0 right-0 bottom-0 bg-bg-surface border-l border-border-subtle z-10 transition-transform duration-200 ${$?"translate-x-full":""}`,style:{width:Z},children:[O("div",{onMouseDown:K,className:"absolute left-0 top-0 bottom-0 w-1 cursor-col-resize hover:bg-accent-blue/30 transition-colors z-20",style:{marginLeft:"-2px"}},void 0,!1,void 0,this),g1.Children.map(J,(U)=>g1.isValidElement(U)?g1.cloneElement(U,{collapseButton:O("button",{onClick:Q,className:"w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Hide annotations",children:O("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[O("polyline",{points:"13 17 18 12 13 7"},void 0,!1,void 0,this),O("polyline",{points:"6 17 11 12 6 7"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}):U)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function k$({markdown:J}){let[$,Q]=Q1(!1),Z=j$(()=>E.parse(J,{async:!1}),[J]);if(X0(()=>{Q(!1)},[J]),$)return null;return O("div",{className:"mb-6 rounded-lg border border-accent-blue/20 bg-accent-blue/5 relative",children:[O("button",{onClick:()=>Q(!0),className:"absolute top-2 right-2 w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",children:O("span",{className:"text-xs",children:"✕"},void 0,!1,void 0,this)},void 0,!1,void 0,this),O("div",{className:"px-4 py-3 pr-10",children:[O("div",{className:"flex items-center gap-2 mb-1.5",children:[O("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-accent-blue flex-shrink-0",children:O("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this),O("span",{className:"text-[11px] font-medium uppercase tracking-widest text-accent-blue font-body",children:"Agent Response"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),O("div",{className:"prose-canvas text-sm",dangerouslySetInnerHTML:{__html:Z}},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function u$(){let{activeView:J,setActiveView:$,openFiles:Q,closeFile:Z}=g1.useContext(I1),Y=g1.useContext(T2),{addAnnotationWithId:X,setActiveAnnotationId:q}=q1(),_=Q.length>0;if(!_)return null;return O("div",{className:"flex items-center border-b border-border-medium bg-bg-surface overflow-x-auto sticky top-0 z-10",children:[_&&O("button",{onClick:()=>$({type:"plan"}),className:`flex items-center gap-1.5 px-4 py-2.5 text-[13px] font-body whitespace-nowrap transition-colors relative ${J.type==="plan"?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[O("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",className:"opacity-60",children:O("path",{d:"M12 2L2 7l10 5 10-5-10-5z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this),"Plan",J.type==="plan"&&O("span",{className:"absolute bottom-0 left-3 right-3 h-[2px] bg-text-primary rounded-full"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),_&&O(Q5,{children:[O("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this),Q.map((z,K)=>{let U=z.split("/").pop()||z,H=J.type==="file"&&J.path===z;return O(g1.Fragment,{children:[O("div",{className:"flex items-center",children:[O("button",{onClick:()=>$({type:"file",path:z}),className:`flex items-center gap-1.5 pl-3 pr-1 py-2.5 text-[13px] font-mono whitespace-nowrap transition-colors relative ${H?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[U,H&&O("span",{className:"absolute bottom-0 left-3 right-1 h-[2px] bg-text-primary rounded-full"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),O("button",{onClick:(G)=>{G.stopPropagation(),Z(z)},className:"text-text-tertiary hover:text-text-secondary px-1.5 py-1 text-[10px] transition-colors rounded hover:bg-bg-input",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),K<Q.length-1&&O("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this)]},z,!0,void 0,this)})]},void 0,!0,void 0,this),O("div",{className:"ml-auto flex items-center gap-1 flex-shrink-0",children:J.type==="file"&&O("button",{onClick:async()=>{let z=J.path;try{let U=await(await fetch(`/api/file?session=${Y}&path=${encodeURIComponent(z)}`)).json();if(!U.error){let H=U.content.split(`
112
112
  `).slice(0,3).join(`
113
113
  `)+(U.content.split(`
114
114
  `).length>3?`
115
- ...`:""),G=G1();X(G,H,"",z),q(G)}}catch{}},className:"flex items-center gap-1 px-3 py-1.5 text-[11px] font-medium font-body text-text-tertiary hover:text-text-secondary whitespace-nowrap transition-colors",children:[O("span",{className:"text-[13px] leading-none",children:"+"},void 0,!1,void 0,this),"Add to context"]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var N2=document.getElementById("root");if(N2)j$(N2).render(O(V$,{},void 0,!1,void 0,this));export{h1 as RevisionContext,I1 as ActiveViewContext};
115
+ ...`:""),G=H1();X(G,H,"",z),q(G)}}catch{}},className:"flex items-center gap-1 px-3 py-1.5 text-[11px] font-medium font-body text-text-tertiary hover:text-text-secondary whitespace-nowrap transition-colors",children:[O("span",{className:"text-[13px] leading-none",children:"+"},void 0,!1,void 0,this),"Add to context"]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var N2=document.getElementById("root");if(N2)I$(N2).render(O(g$,{},void 0,!1,void 0,this));export{h1 as RevisionContext,I1 as ActiveViewContext};