agent-canvas 0.1.28 → 0.1.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/daemon/client/AnnotationSidebar.tsx +45 -9
- package/daemon/client/App.tsx +5 -9
- package/daemon/client/ResponsePreview.tsx +19 -3
- package/daemon/client/generateMarkdown.ts +7 -3
- package/daemon/dist/client.js +52 -52
- package/daemon/src/handlers/api.ts +1 -1
- package/package.json +1 -1
- package/workers/canvas-share/public/assets/client.js +52 -52
package/daemon/dist/client.js
CHANGED
|
@@ -1,91 +1,91 @@
|
|
|
1
|
-
import
|
|
2
|
-
]`).replace("lheading",
|
|
3
|
-
`).map((
|
|
4
|
-
`)}var V0=class{options;rules;lexer;constructor(Q){this.options=Q||
|
|
1
|
+
import u1,{useEffect as M1,useLayoutEffect as G4,useState as Q1,useCallback as j0,useRef as g1,createContext as N3,useMemo as K3}from"react";import{createRoot as K4}from"react-dom/client";function X2(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var c1=X2();function i2(Q){c1=Q}var h1={exec:()=>null};function s(Q,$=""){let Z=typeof Q=="string"?Q:Q.source,J={replace:(q,Y)=>{let X=typeof Y=="string"?Y:Y.source;return X=X.replace(U1.caret,"$1"),Z=Z.replace(q,X),J},getRegex:()=>new RegExp(Z,$)};return J}var y3=(()=>{try{return!!new RegExp("(?<=1)(?<!1)")}catch{return!1}})(),U1={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:(Q)=>new RegExp(`^( {0,3}${Q})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:(Q)=>new RegExp(`^ {0,${Math.min(3,Q-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:(Q)=>new RegExp(`^ {0,${Math.min(3,Q-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:(Q)=>new RegExp(`^ {0,${Math.min(3,Q-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:(Q)=>new RegExp(`^ {0,${Math.min(3,Q-1)}}#`),htmlBeginRegex:(Q)=>new RegExp(`^ {0,${Math.min(3,Q-1)}}<(?:[a-z].*>|!--)`,"i"),blockquoteBeginRegex:(Q)=>new RegExp(`^ {0,${Math.min(3,Q-1)}}>`)},P3=/^(?:[ \t]*(?:\n|$))+/,S3=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,b3=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,T0=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,w3=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,z2=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,a2=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,o2=s(a2).replace(/bull/g,z2).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(),j3=s(a2).replace(/bull/g,z2).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(),_2=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,A3=/^[^\n]+/,G2=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,C3=s(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",G2).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),I3=s(/^(bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,z2).getRegex(),D0="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",K2=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,V3=s("^ {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",K2).replace("tag",D0).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),s2=s(_2).replace("hr",T0).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",D0).getRegex(),R3=s(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",s2).getRegex(),U2={blockquote:R3,code:S3,def:C3,fences:b3,heading:w3,hr:T0,html:V3,lheading:o2,list:I3,newline:P3,paragraph:s2,table:h1,text:A3},h2=s("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",T0).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",D0).getRegex(),D3={...U2,lheading:j3,table:h2,paragraph:s(_2).replace("hr",T0).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",h2).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",D0).getRegex()},k3={...U2,html:s(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",K2).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:h1,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:s(_2).replace("hr",T0).replace("heading",` *#{1,6} *[^
|
|
2
|
+
]`).replace("lheading",o2).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},E3=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,x3=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,t2=/^( {2,}|\\)\n(?!\s*$)/,m3=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,k0=/[\p{P}\p{S}]/u,H2=/[\s\p{P}\p{S}]/u,n2=/[^\s\p{P}\p{S}]/u,u3=s(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,H2).getRegex(),e2=/(?!~)[\p{P}\p{S}]/u,g3=/(?!~)[\s\p{P}\p{S}]/u,v3=/(?:[^\s\p{P}\p{S}]|~)/u,$5=/(?![*_])[\p{P}\p{S}]/u,f3=/(?![*_])[\s\p{P}\p{S}]/u,h3=/(?:[^\s\p{P}\p{S}]|[*_])/u,p3=s(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",y3?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),Q5=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,c3=s(Q5,"u").replace(/punct/g,k0).getRegex(),d3=s(Q5,"u").replace(/punct/g,e2).getRegex(),Z5="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",r3=s(Z5,"gu").replace(/notPunctSpace/g,n2).replace(/punctSpace/g,H2).replace(/punct/g,k0).getRegex(),l3=s(Z5,"gu").replace(/notPunctSpace/g,v3).replace(/punctSpace/g,g3).replace(/punct/g,e2).getRegex(),i3=s("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,n2).replace(/punctSpace/g,H2).replace(/punct/g,k0).getRegex(),a3=s(/^~~?(?:((?!~)punct)|[^\s~])/,"u").replace(/punct/g,$5).getRegex(),o3="^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)",s3=s(o3,"gu").replace(/notPunctSpace/g,h3).replace(/punctSpace/g,f3).replace(/punct/g,$5).getRegex(),t3=s(/\\(punct)/,"gu").replace(/punct/g,k0).getRegex(),n3=s(/^<(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(),e3=s(K2).replace("(?:-->|$)","-->").getRegex(),$7=s("^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",e3).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),I0=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+[^`]*?`+(?!`)|[^\[\]\\`])*?/,Q7=s(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace("label",I0).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),q5=s(/^!?\[(label)\]\[(ref)\]/).replace("label",I0).replace("ref",G2).getRegex(),J5=s(/^!?\[(ref)\](?:\[\])?/).replace("ref",G2).getRegex(),Z7=s("reflink|nolink(?!\\()","g").replace("reflink",q5).replace("nolink",J5).getRegex(),p2=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,W2={_backpedal:h1,anyPunctuation:t3,autolink:n3,blockSkip:p3,br:t2,code:x3,del:h1,delLDelim:h1,delRDelim:h1,emStrongLDelim:c3,emStrongRDelimAst:r3,emStrongRDelimUnd:i3,escape:E3,link:Q7,nolink:J5,punctuation:u3,reflink:q5,reflinkSearch:Z7,tag:$7,text:m3,url:h1},q7={...W2,link:s(/^!?\[(label)\]\((.*?)\)/).replace("label",I0).getRegex(),reflink:s(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",I0).getRegex()},Y2={...W2,emStrongRDelimAst:l3,emStrongLDelim:d3,delLDelim:a3,delRDelim:s3,url:s(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol",p2).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:s(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace("protocol",p2).getRegex()},J7={...Y2,br:s(t2).replace("{2,}","*").getRegex(),text:s(Y2.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},C0={normal:U2,gfm:D3,pedantic:k3},U0={normal:W2,gfm:Y2,breaks:J7,pedantic:q7},Y7={"&":"&","<":"<",">":">",'"':""","'":"'"},c2=(Q)=>Y7[Q];function P1(Q,$){if($){if(U1.escapeTest.test(Q))return Q.replace(U1.escapeReplace,c2)}else if(U1.escapeTestNoEncode.test(Q))return Q.replace(U1.escapeReplaceNoEncode,c2);return Q}function d2(Q){try{Q=encodeURI(Q).replace(U1.percentDecode,"%")}catch{return null}return Q}function r2(Q,$){let Z=Q.replace(U1.findPipe,(Y,X,G)=>{let z=!1,_=X;for(;--_>=0&&G[_]==="\\";)z=!z;return z?"|":" |"}),J=Z.split(U1.splitPipe),q=0;if(J[0].trim()||J.shift(),J.length>0&&!J.at(-1)?.trim()&&J.pop(),$)if(J.length>$)J.splice($);else for(;J.length<$;)J.push("");for(;q<J.length;q++)J[q]=J[q].trim().replace(U1.slashPipe,"|");return J}function H0(Q,$,Z){let J=Q.length;if(J===0)return"";let q=0;for(;q<J;){let Y=Q.charAt(J-q-1);if(Y===$&&!Z)q++;else if(Y!==$&&Z)q++;else break}return Q.slice(0,J-q)}function X7(Q,$){if(Q.indexOf($[1])===-1)return-1;let Z=0;for(let J=0;J<Q.length;J++)if(Q[J]==="\\")J++;else if(Q[J]===$[0])Z++;else if(Q[J]===$[1]&&(Z--,Z<0))return J;return Z>0?-2:-1}function z7(Q,$=0){let Z=$,J="";for(let q of Q)if(q==="\t"){let Y=4-Z%4;J+=" ".repeat(Y),Z+=Y}else J+=q,Z++;return J}function l2(Q,$,Z,J,q){let Y=$.href,X=$.title||null,G=Q[1].replace(q.other.outputLinkReplace,"$1");J.state.inLink=!0;let z={type:Q[0].charAt(0)==="!"?"image":"link",raw:Z,href:Y,title:X,text:G,tokens:J.inlineTokens(G)};return J.state.inLink=!1,z}function _7(Q,$,Z){let J=Q.match(Z.other.indentCodeCompensation);if(J===null)return $;let q=J[1];return $.split(`
|
|
3
|
+
`).map((Y)=>{let X=Y.match(Z.other.beginningSpace);if(X===null)return Y;let[G]=X;return G.length>=q.length?Y.slice(q.length):Y}).join(`
|
|
4
|
+
`)}var V0=class{options;rules;lexer;constructor(Q){this.options=Q||c1}space(Q){let $=this.rules.block.newline.exec(Q);if($&&$[0].length>0)return{type:"space",raw:$[0]}}code(Q){let $=this.rules.block.code.exec(Q);if($){let Z=$[0].replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:$[0],codeBlockStyle:"indented",text:this.options.pedantic?Z:H0(Z,`
|
|
5
5
|
`)}}}fences(Q){let $=this.rules.block.fences.exec(Q);if($){let Z=$[0],J=_7(Z,$[3]||"",this.rules);return{type:"code",raw:Z,lang:$[2]?$[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):$[2],text:J}}}heading(Q){let $=this.rules.block.heading.exec(Q);if($){let Z=$[2].trim();if(this.rules.other.endingHash.test(Z)){let J=H0(Z,"#");(this.options.pedantic||!J||this.rules.other.endingSpaceChar.test(J))&&(Z=J.trim())}return{type:"heading",raw:$[0],depth:$[1].length,text:Z,tokens:this.lexer.inline(Z)}}}hr(Q){let $=this.rules.block.hr.exec(Q);if($)return{type:"hr",raw:H0($[0],`
|
|
6
6
|
`)}}blockquote(Q){let $=this.rules.block.blockquote.exec(Q);if($){let Z=H0($[0],`
|
|
7
7
|
`).split(`
|
|
8
|
-
`),J="",q="",
|
|
9
|
-
`),
|
|
8
|
+
`),J="",q="",Y=[];for(;Z.length>0;){let X=!1,G=[],z;for(z=0;z<Z.length;z++)if(this.rules.other.blockquoteStart.test(Z[z]))G.push(Z[z]),X=!0;else if(!X)G.push(Z[z]);else break;Z=Z.slice(z);let _=G.join(`
|
|
9
|
+
`),H=_.replace(this.rules.other.blockquoteSetextReplace,`
|
|
10
10
|
$1`).replace(this.rules.other.blockquoteSetextReplace2,"");J=J?`${J}
|
|
11
11
|
${_}`:_,q=q?`${q}
|
|
12
|
-
${
|
|
12
|
+
${H}`:H;let K=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(H,Y,!0),this.lexer.state.top=K,Z.length===0)break;let W=Y.at(-1);if(W?.type==="code")break;if(W?.type==="blockquote"){let T=W,U=T.raw+`
|
|
13
13
|
`+Z.join(`
|
|
14
|
-
`),
|
|
14
|
+
`),B=this.blockquote(U);Y[Y.length-1]=B,J=J.substring(0,J.length-T.raw.length)+B.raw,q=q.substring(0,q.length-T.text.length)+B.text;break}else if(W?.type==="list"){let T=W,U=T.raw+`
|
|
15
15
|
`+Z.join(`
|
|
16
|
-
`),
|
|
17
|
-
`);continue}}return{type:"blockquote",raw:J,tokens:
|
|
18
|
-
`,1)[0],$[1].length),
|
|
19
|
-
`,1)[0],T=!K.trim(),U=0;if(this.options.pedantic?(U=2,
|
|
20
|
-
`,Q=Q.substring(
|
|
21
|
-
`,1)[0],b;if(
|
|
22
|
-
`+b.slice(U);else{if(T||K.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||
|
|
23
|
-
`+
|
|
24
|
-
`,Q=Q.substring(
|
|
25
|
-
`):[],
|
|
26
|
-
`?$[1].slice(0,-1):$[1];return{type:"paragraph",raw:$[0],text:Z,tokens:this.lexer.inline(Z)}}}text(Q){let $=this.rules.block.text.exec(Q);if($)return{type:"text",raw:$[0],text:$[0],tokens:this.lexer.inline($[0])}}escape(Q){let $=this.rules.inline.escape.exec(Q);if($)return{type:"escape",raw:$[0],text:$[1]}}tag(Q){let $=this.rules.inline.tag.exec(Q);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(Q){let $=this.rules.inline.link.exec(Q);if($){let Z=$[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(Z)){if(!this.rules.other.endAngleBracket.test(Z))return;let
|
|
27
|
-
`),this.blockTokens($,this.tokens);for(let Z=0;Z<this.inlineQueue.length;Z++){let J=this.inlineQueue[Z];this.inlineTokens(J.src,J.tokens)}return this.inlineQueue=[],this.tokens}blockTokens($,Z=[],J=!1){for(this.options.pedantic&&($=$.replace(U1.tabCharGlobal," ").replace(U1.spaceLine,""));$;){let q;if(this.options.extensions?.block?.some((
|
|
28
|
-
`:Z.push(q);continue}if(q=this.tokenizer.code($)){$=$.substring(q.raw.length);let
|
|
16
|
+
`),B=this.list(U);Y[Y.length-1]=B,J=J.substring(0,J.length-W.raw.length)+B.raw,q=q.substring(0,q.length-T.raw.length)+B.raw,Z=U.substring(Y.at(-1).raw.length).split(`
|
|
17
|
+
`);continue}}return{type:"blockquote",raw:J,tokens:Y,text:q}}}list(Q){let $=this.rules.block.list.exec(Q);if($){let Z=$[1].trim(),J=Z.length>1,q={type:"list",raw:"",ordered:J,start:J?+Z.slice(0,-1):"",loose:!1,items:[]};Z=J?`\\d{1,9}\\${Z.slice(-1)}`:`\\${Z}`,this.options.pedantic&&(Z=J?Z:"[*+-]");let Y=this.rules.other.listItemRegex(Z),X=!1;for(;Q;){let z=!1,_="",H="";if(!($=Y.exec(Q))||this.rules.block.hr.test(Q))break;_=$[0],Q=Q.substring(_.length);let K=z7($[2].split(`
|
|
18
|
+
`,1)[0],$[1].length),W=Q.split(`
|
|
19
|
+
`,1)[0],T=!K.trim(),U=0;if(this.options.pedantic?(U=2,H=K.trimStart()):T?U=$[1].length+1:(U=K.search(this.rules.other.nonSpaceChar),U=U>4?1:U,H=K.slice(U),U+=$[1].length),T&&this.rules.other.blankLine.test(W)&&(_+=W+`
|
|
20
|
+
`,Q=Q.substring(W.length+1),z=!0),!z){let B=this.rules.other.nextBulletRegex(U),N=this.rules.other.hrRegex(U),M=this.rules.other.fencesBeginRegex(U),O=this.rules.other.headingBeginRegex(U),A=this.rules.other.htmlBeginRegex(U),S=this.rules.other.blockquoteBeginRegex(U);for(;Q;){let y=Q.split(`
|
|
21
|
+
`,1)[0],b;if(W=y,this.options.pedantic?(W=W.replace(this.rules.other.listReplaceNesting," "),b=W):b=W.replace(this.rules.other.tabCharGlobal," "),M.test(W)||O.test(W)||A.test(W)||S.test(W)||B.test(W)||N.test(W))break;if(b.search(this.rules.other.nonSpaceChar)>=U||!W.trim())H+=`
|
|
22
|
+
`+b.slice(U);else{if(T||K.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||M.test(K)||O.test(K)||N.test(K))break;H+=`
|
|
23
|
+
`+W}T=!W.trim(),_+=y+`
|
|
24
|
+
`,Q=Q.substring(y.length+1),K=b.slice(U)}}q.loose||(X?q.loose=!0:this.rules.other.doubleBlankLine.test(_)&&(X=!0)),q.items.push({type:"list_item",raw:_,task:!!this.options.gfm&&this.rules.other.listIsTask.test(H),loose:!1,text:H,tokens:[]}),q.raw+=_}let G=q.items.at(-1);if(G)G.raw=G.raw.trimEnd(),G.text=G.text.trimEnd();else return;q.raw=q.raw.trimEnd();for(let z of q.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 H=this.lexer.inlineQueue.length-1;H>=0;H--)if(this.rules.other.listIsTask.test(this.lexer.inlineQueue[H].src)){this.lexer.inlineQueue[H].src=this.lexer.inlineQueue[H].src.replace(this.rules.other.listReplaceTask,"");break}}let _=this.rules.other.listTaskCheckbox.exec(z.raw);if(_){let H={type:"checkbox",raw:_[0]+" ",checked:_[0]!=="[ ]"};z.checked=H.checked,q.loose?z.tokens[0]&&["paragraph","text"].includes(z.tokens[0].type)&&"tokens"in z.tokens[0]&&z.tokens[0].tokens?(z.tokens[0].raw=H.raw+z.tokens[0].raw,z.tokens[0].text=H.raw+z.tokens[0].text,z.tokens[0].tokens.unshift(H)):z.tokens.unshift({type:"paragraph",raw:H.raw,text:H.raw,tokens:[H]}):z.tokens.unshift(H)}}if(!q.loose){let _=z.tokens.filter((K)=>K.type==="space"),H=_.length>0&&_.some((K)=>this.rules.other.anyLine.test(K.raw));q.loose=H}}if(q.loose)for(let z of q.items){z.loose=!0;for(let _ of z.tokens)_.type==="text"&&(_.type="paragraph")}return q}}html(Q){let $=this.rules.block.html.exec(Q);if($)return{type:"html",block:!0,raw:$[0],pre:$[1]==="pre"||$[1]==="script"||$[1]==="style",text:$[0]}}def(Q){let $=this.rules.block.def.exec(Q);if($){let Z=$[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal," "),J=$[2]?$[2].replace(this.rules.other.hrefBrackets,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",q=$[3]?$[3].substring(1,$[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):$[3];return{type:"def",tag:Z,raw:$[0],href:J,title:q}}}table(Q){let $=this.rules.block.table.exec(Q);if(!$||!this.rules.other.tableDelimiter.test($[2]))return;let Z=r2($[1]),J=$[2].replace(this.rules.other.tableAlignChars,"").split("|"),q=$[3]?.trim()?$[3].replace(this.rules.other.tableRowBlankLine,"").split(`
|
|
25
|
+
`):[],Y={type:"table",raw:$[0],header:[],align:[],rows:[]};if(Z.length===J.length){for(let X of J)this.rules.other.tableAlignRight.test(X)?Y.align.push("right"):this.rules.other.tableAlignCenter.test(X)?Y.align.push("center"):this.rules.other.tableAlignLeft.test(X)?Y.align.push("left"):Y.align.push(null);for(let X=0;X<Z.length;X++)Y.header.push({text:Z[X],tokens:this.lexer.inline(Z[X]),header:!0,align:Y.align[X]});for(let X of q)Y.rows.push(r2(X,Y.header.length).map((G,z)=>({text:G,tokens:this.lexer.inline(G),header:!1,align:Y.align[z]})));return Y}}lheading(Q){let $=this.rules.block.lheading.exec(Q);if($)return{type:"heading",raw:$[0],depth:$[2].charAt(0)==="="?1:2,text:$[1],tokens:this.lexer.inline($[1])}}paragraph(Q){let $=this.rules.block.paragraph.exec(Q);if($){let Z=$[1].charAt($[1].length-1)===`
|
|
26
|
+
`?$[1].slice(0,-1):$[1];return{type:"paragraph",raw:$[0],text:Z,tokens:this.lexer.inline(Z)}}}text(Q){let $=this.rules.block.text.exec(Q);if($)return{type:"text",raw:$[0],text:$[0],tokens:this.lexer.inline($[0])}}escape(Q){let $=this.rules.inline.escape.exec(Q);if($)return{type:"escape",raw:$[0],text:$[1]}}tag(Q){let $=this.rules.inline.tag.exec(Q);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(Q){let $=this.rules.inline.link.exec(Q);if($){let Z=$[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(Z)){if(!this.rules.other.endAngleBracket.test(Z))return;let Y=H0(Z.slice(0,-1),"\\");if((Z.length-Y.length)%2===0)return}else{let Y=X7($[2],"()");if(Y===-2)return;if(Y>-1){let X=($[0].indexOf("!")===0?5:4)+$[1].length+Y;$[2]=$[2].substring(0,Y),$[0]=$[0].substring(0,X).trim(),$[3]=""}}let J=$[2],q="";if(this.options.pedantic){let Y=this.rules.other.pedanticHrefTitle.exec(J);Y&&(J=Y[1],q=Y[3])}else q=$[3]?$[3].slice(1,-1):"";return J=J.trim(),this.rules.other.startAngleBracket.test(J)&&(this.options.pedantic&&!this.rules.other.endAngleBracket.test(Z)?J=J.slice(1):J=J.slice(1,-1)),l2($,{href:J&&J.replace(this.rules.inline.anyPunctuation,"$1"),title:q&&q.replace(this.rules.inline.anyPunctuation,"$1")},$[0],this.lexer,this.rules)}}reflink(Q,$){let Z;if((Z=this.rules.inline.reflink.exec(Q))||(Z=this.rules.inline.nolink.exec(Q))){let J=(Z[2]||Z[1]).replace(this.rules.other.multipleSpaceGlobal," "),q=$[J.toLowerCase()];if(!q){let Y=Z[0].charAt(0);return{type:"text",raw:Y,text:Y}}return l2(Z,q,Z[0],this.lexer,this.rules)}}emStrong(Q,$,Z=""){let J=this.rules.inline.emStrongLDelim.exec(Q);if(!J||J[3]&&Z.match(this.rules.other.unicodeAlphaNumeric))return;if(!(J[1]||J[2])||!Z||this.rules.inline.punctuation.exec(Z)){let q=[...J[0]].length-1,Y,X,G=q,z=0,_=J[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(_.lastIndex=0,$=$.slice(-1*Q.length+q);(J=_.exec($))!=null;){if(Y=J[1]||J[2]||J[3]||J[4]||J[5]||J[6],!Y)continue;if(X=[...Y].length,J[3]||J[4]){G+=X;continue}else if((J[5]||J[6])&&q%3&&!((q+X)%3)){z+=X;continue}if(G-=X,G>0)continue;X=Math.min(X,X+G+z);let H=[...J[0]][0].length,K=Q.slice(0,q+J.index+H+X);if(Math.min(q,X)%2){let T=K.slice(1,-1);return{type:"em",raw:K,text:T,tokens:this.lexer.inlineTokens(T)}}let W=K.slice(2,-2);return{type:"strong",raw:K,text:W,tokens:this.lexer.inlineTokens(W)}}}}codespan(Q){let $=this.rules.inline.code.exec(Q);if($){let Z=$[2].replace(this.rules.other.newLineCharGlobal," "),J=this.rules.other.nonSpaceChar.test(Z),q=this.rules.other.startingSpaceChar.test(Z)&&this.rules.other.endingSpaceChar.test(Z);return J&&q&&(Z=Z.substring(1,Z.length-1)),{type:"codespan",raw:$[0],text:Z}}}br(Q){let $=this.rules.inline.br.exec(Q);if($)return{type:"br",raw:$[0]}}del(Q,$,Z=""){let J=this.rules.inline.delLDelim.exec(Q);if(!J)return;if(!J[1]||!Z||this.rules.inline.punctuation.exec(Z)){let q=[...J[0]].length-1,Y,X,G=q,z=this.rules.inline.delRDelim;for(z.lastIndex=0,$=$.slice(-1*Q.length+q);(J=z.exec($))!=null;){if(Y=J[1]||J[2]||J[3]||J[4]||J[5]||J[6],!Y||(X=[...Y].length,X!==q))continue;if(J[3]||J[4]){G+=X;continue}if(G-=X,G>0)continue;X=Math.min(X,X+G);let _=[...J[0]][0].length,H=Q.slice(0,q+J.index+_+X),K=H.slice(q,-q);return{type:"del",raw:H,text:K,tokens:this.lexer.inlineTokens(K)}}}}autolink(Q){let $=this.rules.inline.autolink.exec(Q);if($){let Z,J;return $[2]==="@"?(Z=$[1],J="mailto:"+Z):(Z=$[1],J=Z),{type:"link",raw:$[0],text:Z,href:J,tokens:[{type:"text",raw:Z,text:Z}]}}}url(Q){let $;if($=this.rules.inline.url.exec(Q)){let Z,J;if($[2]==="@")Z=$[0],J="mailto:"+Z;else{let q;do q=$[0],$[0]=this.rules.inline._backpedal.exec($[0])?.[0]??"";while(q!==$[0]);Z=$[0],$[1]==="www."?J="http://"+$[0]:J=$[0]}return{type:"link",raw:$[0],text:Z,href:J,tokens:[{type:"text",raw:Z,text:Z}]}}}inlineText(Q){let $=this.rules.inline.text.exec(Q);if($){let Z=this.lexer.state.inRawBlock;return{type:"text",raw:$[0],text:$[0],escaped:Z}}}},N1=class Q{tokens;options;state;inlineQueue;tokenizer;constructor($){this.tokens=[],this.tokens.links=Object.create(null),this.options=$||c1,this.options.tokenizer=this.options.tokenizer||new V0,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 Z={other:U1,block:C0.normal,inline:U0.normal};this.options.pedantic?(Z.block=C0.pedantic,Z.inline=U0.pedantic):this.options.gfm&&(Z.block=C0.gfm,this.options.breaks?Z.inline=U0.breaks:Z.inline=U0.gfm),this.tokenizer.rules=Z}static get rules(){return{block:C0,inline:U0}}static lex($,Z){return new Q(Z).lex($)}static lexInline($,Z){return new Q(Z).inlineTokens($)}lex($){$=$.replace(U1.carriageReturn,`
|
|
27
|
+
`),this.blockTokens($,this.tokens);for(let Z=0;Z<this.inlineQueue.length;Z++){let J=this.inlineQueue[Z];this.inlineTokens(J.src,J.tokens)}return this.inlineQueue=[],this.tokens}blockTokens($,Z=[],J=!1){for(this.options.pedantic&&($=$.replace(U1.tabCharGlobal," ").replace(U1.spaceLine,""));$;){let q;if(this.options.extensions?.block?.some((X)=>(q=X.call({lexer:this},$,Z))?($=$.substring(q.raw.length),Z.push(q),!0):!1))continue;if(q=this.tokenizer.space($)){$=$.substring(q.raw.length);let X=Z.at(-1);q.raw.length===1&&X!==void 0?X.raw+=`
|
|
28
|
+
`:Z.push(q);continue}if(q=this.tokenizer.code($)){$=$.substring(q.raw.length);let X=Z.at(-1);X?.type==="paragraph"||X?.type==="text"?(X.raw+=(X.raw.endsWith(`
|
|
29
29
|
`)?"":`
|
|
30
|
-
`)+q.raw,
|
|
31
|
-
`+q.text,this.inlineQueue.at(-1).src=
|
|
30
|
+
`)+q.raw,X.text+=`
|
|
31
|
+
`+q.text,this.inlineQueue.at(-1).src=X.text):Z.push(q);continue}if(q=this.tokenizer.fences($)){$=$.substring(q.raw.length),Z.push(q);continue}if(q=this.tokenizer.heading($)){$=$.substring(q.raw.length),Z.push(q);continue}if(q=this.tokenizer.hr($)){$=$.substring(q.raw.length),Z.push(q);continue}if(q=this.tokenizer.blockquote($)){$=$.substring(q.raw.length),Z.push(q);continue}if(q=this.tokenizer.list($)){$=$.substring(q.raw.length),Z.push(q);continue}if(q=this.tokenizer.html($)){$=$.substring(q.raw.length),Z.push(q);continue}if(q=this.tokenizer.def($)){$=$.substring(q.raw.length);let X=Z.at(-1);X?.type==="paragraph"||X?.type==="text"?(X.raw+=(X.raw.endsWith(`
|
|
32
32
|
`)?"":`
|
|
33
|
-
`)+q.raw,
|
|
34
|
-
`+q.raw,this.inlineQueue.at(-1).src=
|
|
33
|
+
`)+q.raw,X.text+=`
|
|
34
|
+
`+q.raw,this.inlineQueue.at(-1).src=X.text):this.tokens.links[q.tag]||(this.tokens.links[q.tag]={href:q.href,title:q.title},Z.push(q));continue}if(q=this.tokenizer.table($)){$=$.substring(q.raw.length),Z.push(q);continue}if(q=this.tokenizer.lheading($)){$=$.substring(q.raw.length),Z.push(q);continue}let Y=$;if(this.options.extensions?.startBlock){let X=1/0,G=$.slice(1),z;this.options.extensions.startBlock.forEach((_)=>{z=_.call({lexer:this},G),typeof z=="number"&&z>=0&&(X=Math.min(X,z))}),X<1/0&&X>=0&&(Y=$.substring(0,X+1))}if(this.state.top&&(q=this.tokenizer.paragraph(Y))){let X=Z.at(-1);J&&X?.type==="paragraph"?(X.raw+=(X.raw.endsWith(`
|
|
35
35
|
`)?"":`
|
|
36
|
-
`)+q.raw,
|
|
37
|
-
`+q.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=
|
|
36
|
+
`)+q.raw,X.text+=`
|
|
37
|
+
`+q.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=X.text):Z.push(q),J=Y.length!==$.length,$=$.substring(q.raw.length);continue}if(q=this.tokenizer.text($)){$=$.substring(q.raw.length);let X=Z.at(-1);X?.type==="text"?(X.raw+=(X.raw.endsWith(`
|
|
38
38
|
`)?"":`
|
|
39
|
-
`)+q.raw,
|
|
40
|
-
`+q.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=
|
|
39
|
+
`)+q.raw,X.text+=`
|
|
40
|
+
`+q.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=X.text):Z.push(q);continue}if($){let X="Infinite loop on byte: "+$.charCodeAt(0);if(this.options.silent){console.error(X);break}else throw Error(X)}}return this.state.top=!0,Z}inline($,Z=[]){return this.inlineQueue.push({src:$,tokens:Z}),Z}inlineTokens($,Z=[]){let J=$,q=null;if(this.tokens.links){let z=Object.keys(this.tokens.links);if(z.length>0)for(;(q=this.tokenizer.rules.inline.reflinkSearch.exec(J))!=null;)z.includes(q[0].slice(q[0].lastIndexOf("[")+1,-1))&&(J=J.slice(0,q.index)+"["+"a".repeat(q[0].length-2)+"]"+J.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(q=this.tokenizer.rules.inline.anyPunctuation.exec(J))!=null;)J=J.slice(0,q.index)+"++"+J.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);let Y;for(;(q=this.tokenizer.rules.inline.blockSkip.exec(J))!=null;)Y=q[2]?q[2].length:0,J=J.slice(0,q.index+Y)+"["+"a".repeat(q[0].length-Y-2)+"]"+J.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);J=this.options.hooks?.emStrongMask?.call({lexer:this},J)??J;let X=!1,G="";for(;$;){X||(G=""),X=!1;let z;if(this.options.extensions?.inline?.some((H)=>(z=H.call({lexer:this},$,Z))?($=$.substring(z.raw.length),Z.push(z),!0):!1))continue;if(z=this.tokenizer.escape($)){$=$.substring(z.raw.length),Z.push(z);continue}if(z=this.tokenizer.tag($)){$=$.substring(z.raw.length),Z.push(z);continue}if(z=this.tokenizer.link($)){$=$.substring(z.raw.length),Z.push(z);continue}if(z=this.tokenizer.reflink($,this.tokens.links)){$=$.substring(z.raw.length);let H=Z.at(-1);z.type==="text"&&H?.type==="text"?(H.raw+=z.raw,H.text+=z.text):Z.push(z);continue}if(z=this.tokenizer.emStrong($,J,G)){$=$.substring(z.raw.length),Z.push(z);continue}if(z=this.tokenizer.codespan($)){$=$.substring(z.raw.length),Z.push(z);continue}if(z=this.tokenizer.br($)){$=$.substring(z.raw.length),Z.push(z);continue}if(z=this.tokenizer.del($,J,G)){$=$.substring(z.raw.length),Z.push(z);continue}if(z=this.tokenizer.autolink($)){$=$.substring(z.raw.length),Z.push(z);continue}if(!this.state.inLink&&(z=this.tokenizer.url($))){$=$.substring(z.raw.length),Z.push(z);continue}let _=$;if(this.options.extensions?.startInline){let H=1/0,K=$.slice(1),W;this.options.extensions.startInline.forEach((T)=>{W=T.call({lexer:this},K),typeof W=="number"&&W>=0&&(H=Math.min(H,W))}),H<1/0&&H>=0&&(_=$.substring(0,H+1))}if(z=this.tokenizer.inlineText(_)){$=$.substring(z.raw.length),z.raw.slice(-1)!=="_"&&(G=z.raw.slice(-1)),X=!0;let H=Z.at(-1);H?.type==="text"?(H.raw+=z.raw,H.text+=z.text):Z.push(z);continue}if($){let H="Infinite loop on byte: "+$.charCodeAt(0);if(this.options.silent){console.error(H);break}else throw Error(H)}}return Z}},R0=class{options;parser;constructor(Q){this.options=Q||c1}space(Q){return""}code({text:Q,lang:$,escaped:Z}){let J=($||"").match(U1.notSpaceStart)?.[0],q=Q.replace(U1.endingNewline,"")+`
|
|
41
41
|
`;return J?'<pre><code class="language-'+P1(J)+'">'+(Z?q:P1(q,!0))+`</code></pre>
|
|
42
42
|
`:"<pre><code>"+(Z?q:P1(q,!0))+`</code></pre>
|
|
43
43
|
`}blockquote({tokens:Q}){return`<blockquote>
|
|
44
44
|
${this.parser.parse(Q)}</blockquote>
|
|
45
45
|
`}html({text:Q}){return Q}def(Q){return""}heading({tokens:Q,depth:$}){return`<h${$}>${this.parser.parseInline(Q)}</h${$}>
|
|
46
46
|
`}hr(Q){return`<hr>
|
|
47
|
-
`}list(Q){let{ordered:$,start:Z}=Q,J="";for(let
|
|
47
|
+
`}list(Q){let{ordered:$,start:Z}=Q,J="";for(let X=0;X<Q.items.length;X++){let G=Q.items[X];J+=this.listitem(G)}let q=$?"ol":"ul",Y=$&&Z!==1?' start="'+Z+'"':"";return"<"+q+Y+`>
|
|
48
48
|
`+J+"</"+q+`>
|
|
49
49
|
`}listitem(Q){return`<li>${this.parser.parse(Q.tokens)}</li>
|
|
50
50
|
`}checkbox({checked:Q}){return"<input "+(Q?'checked="" ':"")+'disabled="" type="checkbox"> '}paragraph({tokens:Q}){return`<p>${this.parser.parseInline(Q)}</p>
|
|
51
|
-
`}table(Q){let $="",Z="";for(let q=0;q<Q.header.length;q++)Z+=this.tablecell(Q.header[q]);$+=this.tablerow({text:Z});let J="";for(let q=0;q<Q.rows.length;q++){let
|
|
51
|
+
`}table(Q){let $="",Z="";for(let q=0;q<Q.header.length;q++)Z+=this.tablecell(Q.header[q]);$+=this.tablerow({text:Z});let J="";for(let q=0;q<Q.rows.length;q++){let Y=Q.rows[q];Z="";for(let X=0;X<Y.length;X++)Z+=this.tablecell(Y[X]);J+=this.tablerow({text:Z})}return J&&(J=`<tbody>${J}</tbody>`),`<table>
|
|
52
52
|
<thead>
|
|
53
53
|
`+$+`</thead>
|
|
54
54
|
`+J+`</table>
|
|
55
55
|
`}tablerow({text:Q}){return`<tr>
|
|
56
56
|
${Q}</tr>
|
|
57
57
|
`}tablecell(Q){let $=this.parser.parseInline(Q.tokens),Z=Q.header?"th":"td";return(Q.align?`<${Z} align="${Q.align}">`:`<${Z}>`)+$+`</${Z}>
|
|
58
|
-
`}strong({tokens:Q}){return`<strong>${this.parser.parseInline(Q)}</strong>`}em({tokens:Q}){return`<em>${this.parser.parseInline(Q)}</em>`}codespan({text:Q}){return`<code>${P1(Q,!0)}</code>`}br(Q){return"<br>"}del({tokens:Q}){return`<del>${this.parser.parseInline(Q)}</del>`}link({href:Q,title:$,tokens:Z}){let J=this.parser.parseInline(Z),q=
|
|
59
|
-
Please report this to https://github.com/markedjs/marked.`,Q){let J="<p>An error occurred:</p><pre>"+P1(Z.message+"",!0)+"</pre>";return $?Promise.resolve(J):J}if($)return Promise.reject(Z);throw Z}}},h1=new G7;function s(Q,$){return h1.parse(Q,$)}s.options=s.setOptions=function(Q){return h1.setOptions(Q),s.defaults=h1.defaults,r2(s.defaults),s};s.getDefaults=X2;s.defaults=p1;s.use=function(...Q){return h1.use(...Q),s.defaults=h1.defaults,r2(s.defaults),s};s.walkTokens=function(Q,$){return h1.walkTokens(Q,$)};s.parseInline=h1.parseInline;s.Parser=O1;s.parser=O1.parse;s.Renderer=R0;s.TextRenderer=T2;s.Lexer=N1;s.lexer=N1.lex;s.Tokenizer=V0;s.Hooks=W0;s.parse=s;var{options:O4,setOptions:F4,use:B4,walkTokens:L4,parseInline:M4}=s;var y4=O1.parse,P4=N1.lex;import{SessionContext as O3,ActiveViewCtx as K4}from"#canvas/runtime";import{useState as O0,useCallback as S1,useEffect as K7,useRef as U7,useMemo as H7}from"react";import{AnnotationCtx as W7}from"#canvas/runtime";var T1="__agent-response__";function F1(){return`ann-${Date.now()}-${Math.random().toString(36).slice(2,6)}`}function N0(Q,$){Q.style.height="auto",Q.style.height=($?Math.max($,Q.scrollHeight):Q.scrollHeight)+"px"}import{useAnnotations as Y1}from"#canvas/runtime";import{jsxDEV as F7}from"react/jsx-dev-runtime";function N2(Q,$){return`canvas:${Q}:rev:${$}`}function E0(Q,$){try{let Z=localStorage.getItem(N2(Q,$));if(!Z)return null;return JSON.parse(Z)}catch{return null}}function T7(Q,$,Z){try{localStorage.setItem(N2(Q,$),JSON.stringify(Z))}catch{}}function N7(Q,$){try{localStorage.removeItem(N2(Q,$))}catch{}}function q5({sessionId:Q,revision:$,isReadOnly:Z,remoteAnnotations:J,children:q}){let[X,Y]=O0(()=>{return(E0(Q,$)?.annotations??[]).map((k)=>({...k,source:k.source??"local"}))}),G=H7(()=>{if(!J||J.length===0)return X;let R=new Set(X.map((u)=>u.id)),k=J.filter((u)=>!R.has(u.id));return[...X,...k.map((u)=>({...u,source:"remote"}))]},[X,J]),[z,_]=O0(()=>{return E0(Q,$)?.generalNote??""}),[W,K]=O0(null),[H,T]=O0(()=>{let R=E0(Q,$);return R?.responses?new Map(R.responses):new Map}),[U,L]=O0(()=>{let R=E0(Q,$);return R?.feedbackEntries?new Map(R.feedbackEntries):new Map}),N=U7(null);K7(()=>{if(Z)return;if(N.current)clearTimeout(N.current);return N.current=setTimeout(()=>{T7(Q,$,{annotations:X,generalNote:z,responses:Array.from(H.entries()),feedbackEntries:Array.from(U.entries())})},300),()=>{if(N.current)clearTimeout(N.current)}},[X,z,H,U,Q,$,Z]);let P=S1((R,k,u,I,B,D,x)=>{Y((A)=>[...A,{id:R,snippet:k,note:u,createdAt:new Date().toISOString(),filePath:I,context:B,...D?.length?{images:D}:{},...x?{canvasFile:x}:{}}])},[]),O=S1((R,k,u)=>{P(F1(),R,k,u)},[P]),w=S1((R,k)=>{Y((u)=>u.map((I)=>I.id===R?{...I,note:k}:I))},[]),S=S1((R)=>{O7(R),Y((k)=>k.filter((u)=>u.id!==R)),K((k)=>k===R?null:k)},[]),M=S1((R,k)=>{Y((u)=>u.map((I)=>I.id===R?{...I,images:[...I.images||[],k]}:I))},[]),b=S1((R,k)=>{Y((u)=>u.map((I)=>I.id===R?{...I,images:(I.images||[]).filter((B)=>B!==k)}:I))},[]),V=S1((R,k)=>{T((u)=>{let I=new Map(u);return I.set(R,k),I})},[]),v=S1((R,k)=>{L((u)=>{let I=u.get(R);if(I&&I.markdown===k.markdown&&I.label===k.label&&I.required===k.required)return u;let B=new Map(u);return B.set(R,k),B})},[]),p=S1((R)=>{L((k)=>{if(!k.has(R))return k;let u=new Map(k);return u.delete(R),u})},[]),f=S1(()=>{for(let R of document.querySelectorAll("[data-annotation-id]"))J5(R);Y([]),_(""),K(null),T(new Map),L(new Map),N7(Q,$)},[Q,$]);return F7(W7.Provider,{value:{annotations:G,addAnnotation:O,addAnnotationWithId:P,updateAnnotation:w,removeAnnotation:S,addAnnotationImage:M,removeAnnotationImage:b,generalNote:z,setGeneralNote:_,clearAll:f,activeAnnotationId:W,setActiveAnnotationId:K,responses:H,setResponse:V,feedbackEntries:U,setFeedbackEntry:v,removeFeedbackEntry:p},children:q},void 0,!1,void 0,this)}function O7(Q){let $=document.querySelectorAll(`[data-annotation-id="${Q}"]`);for(let Z of $)J5(Z)}function J5(Q){let $=Q.parentNode;if(!$)return;let Z=document.createTextNode(Q.textContent||"");$.replaceChild(Z,Q),$.normalize()}import P2,{useEffect as o1,useState as b1,useRef as R7,useContext as D7,useMemo as F0}from"react";import{createPortal as k7}from"react-dom";import{SessionContext as E7,CanvasFileCtx as m7}from"#canvas/runtime";function c1(Q,$){let Z=Y5(Q,"before",60),J=Y5(Q,"after",60),q=L7(Q.startContainer,$);return{before:Z,after:J,hierarchy:q}}function Y5(Q,$,Z){let J=B7($==="before"?Q.startContainer:Q.endContainer);if(!J)return"";let q="";if($==="before"){let X=document.createTreeWalker(J,NodeFilter.SHOW_TEXT),Y;while(Y=X.nextNode()){if(Y===Q.startContainer){q+=(Y.textContent||"").slice(0,Q.startOffset);break}if(Y.parentElement?.hasAttribute("data-annotation-id"))continue;q+=Y.textContent||""}if(q.length>Z){q=q.slice(-Z);let G=q.indexOf(" ");if(G>0)q=q.slice(G+1)}}else{let X=document.createTreeWalker(J,NodeFilter.SHOW_TEXT),Y=!1,G;while(G=X.nextNode()){if(G===Q.endContainer){q+=(G.textContent||"").slice(Q.endOffset),Y=!0;continue}if(Y){if(G.parentElement?.hasAttribute("data-annotation-id"))continue;q+=G.textContent||""}}if(q.length>Z){q=q.slice(0,Z);let z=q.lastIndexOf(" ");if(z>0)q=q.slice(0,z)}}return q.trim()}function B7(Q){let $=new Set(["DIV","P","LI","PRE","BLOCKQUOTE","SECTION","ARTICLE"]),Z=Q.parentElement;while(Z){if($.has(Z.tagName))return Z;Z=Z.parentElement}return null}function L7(Q,$){let Z=[],J=Q instanceof Element?Q:Q.parentElement;while(J&&J!==$){let q=J.getAttribute?.("data-task-id");if(q){let X=J.querySelector(".font-semibold");if(X)Z.unshift(X.textContent?.trim()||q)}if(J.tagName==="DIV"&&J.querySelector(":scope > button .font-heading, :scope > div .font-heading")){let X=J.querySelector(".font-heading");if(X)Z.unshift(X.textContent?.trim()||"")}J=J.parentElement}return Z}function O2(Q){let $=Q.snippet.trim(),Z=Q.context,J=$.length<30;if(Z&&J&&(Z.before||Z.after)){let q=[];if(Z.before)q.push(`...${Z.before} `);if(q.push(`**${$}**`),Z.after)q.push(` ${Z.after}...`);return q.join("")}return $}import{useEffect as S7,useRef as u0,useState as Q0,useCallback as x0,useMemo as O5,useContext as b7}from"react";import{createPortal as w7}from"react-dom";function X5(Q,$){let q=$||document.body,X=Q.getBoundingClientRect(),Y=q.getBoundingClientRect(),G=q===document.body?window.scrollY:q.scrollTop,z=X.bottom-Y.top+G+8,_=Math.max(0,Math.min(X.left-Y.left,Y.width-280-12));return q.style.position="relative",{style:{position:"absolute",top:`${z}px`,left:`${_}px`},parent:q}}import{useState as B2,useRef as L2,useCallback as C1,useEffect as y7}from"react";function M7(){if(typeof window<"u"&&window.__CANVAS_SHARE__?.shareId)return{isShared:!0,shareId:window.__CANVAS_SHARE__.shareId};return{isShared:!1,sessionId:typeof window<"u"?window.location.pathname.replace("/s/",""):""}}var Z1=M7();function z5(){if(Z1.isShared)return`/s/${Z1.shareId}/meta`;return`/api/session/${Z1.sessionId}/meta`}function _5(Q,$){let Z=Q.replace(/\.jsx$/,".js");if(Z1.isShared)return`/s/${Z1.shareId}/canvas/${encodeURIComponent(Z)}`;let J=$?`?rev=${$}&t=${Date.now()}`:`?t=${Date.now()}`;return`/api/session/${Z1.sessionId}/canvas/${encodeURIComponent(Z)}${J}`}function G5(){if(Z1.isShared)return`/s/${Z1.shareId}/upload`;return`/api/session/${Z1.sessionId}/upload`}var K5="canvas-reviewer-identity";function F2(){try{let Q=localStorage.getItem(K5);if(!Q)return null;return JSON.parse(Q)}catch{return null}}function U5(Q){let $=F2();if(!$)$={id:crypto.randomUUID?.()||String(Date.now()),name:Q};else $.name=Q;return localStorage.setItem(K5,JSON.stringify($)),$}async function H5(Q){if(!Z1.isShared)throw Error("submitSharedFeedback called outside shared mode");let $=await fetch(`/s/${Z1.shareId}/feedback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Q)});if(!$.ok){let Z=await $.text().catch(()=>"");throw Error(`Feedback submission failed: ${$.status} ${Z}`)}}var B1=!Z1.isShared,W5=!Z1.isShared;import{jsxDEV as X1}from"react/jsx-dev-runtime";function T5(Q){if(Q.startsWith("/s/")||Q.startsWith("http://")||Q.startsWith("https://"))return Q;return`/api/uploads/${Q.split("/").pop()}`}async function P7(Q,$){let Z=new FormData;Z.append("image",$);try{let q=await(await fetch(G5(),{method:"POST",body:Z})).json();if(Z1.isShared)return q.url||null;return q.path||null}catch{return null}}function m0({note:Q,onNoteChange:$,images:Z,onAddImage:J,onRemoveImage:q,sessionId:X,placeholder:Y="Add your note...",autoFocus:G=!1,autoResize:z=!1,readOnly:_=!1,onKeyDown:W,onTextareaClick:K,textareaRef:H,textareaClassName:T,textareaStyle:U,minHeight:L,attachButton:N="always",openFilePickerRef:P}){let[O,w]=B2(!1),[S,M]=B2(!1),[b,V]=B2(!1),v=L2(0),p=L2(null),f=L2(null),R=C1(()=>f.current?.click(),[]);if(P)P.current=R;let k=C1((E)=>{if(p.current=E,H)H.current=E;if(E&&z)N0(E,L)},[H,z,L]);y7(()=>{if(G&&p.current){let E=p.current;if(E.focus(),E.value)E.setSelectionRange(E.value.length,E.value.length)}},[G]);let u=C1(async(E)=>{if(!E.type.startsWith("image/"))return;M(!0);try{let l=await P7(X,E);if(l)J(l)}finally{M(!1)}},[X,J]),I=C1((E)=>{let l=E.clipboardData.items;for(let j of l)if(j.type.startsWith("image/")){E.preventDefault();let g=j.getAsFile();if(g)u(g);return}},[u]),B=C1((E)=>{if(E.preventDefault(),v.current++,v.current===1)w(!0)},[]),D=C1((E)=>{E.preventDefault()},[]),x=C1((E)=>{if(E.preventDefault(),v.current--,v.current===0)w(!1)},[]),A=C1((E)=>{E.preventDefault(),v.current=0,w(!1);for(let l of E.dataTransfer.files)if(l.type.startsWith("image/"))u(l)},[u]),m=C1((E)=>{if($(E.target.value),z)E.target.style.height="auto",E.target.style.height=(L?Math.max(L,E.target.scrollHeight):E.target.scrollHeight)+"px"},[$,z,L]),d="w-full bg-transparent text-[13px] font-body text-text-primary resize-none focus:outline-none leading-relaxed p-0 border-none",Q1={width:"100%",background:"transparent",border:"none",color:"var(--color-text-primary)",fontFamily:"'Inter', sans-serif",fontSize:"13px",lineHeight:"1.5",outline:"none",...z?{resize:"none",overflow:"hidden"}:{resize:"vertical"}},i=!_&&(N==="always"||N==="on-focus"&&b);return X1("div",{style:{position:"relative"},onDragEnter:_?void 0:B,onDragOver:_?void 0:D,onDragLeave:_?void 0:x,onDrop:_?void 0:A,children:[X1("textarea",{ref:k,value:Q,onChange:_?void 0:m,onPaste:_?void 0:I,onKeyDown:W,onClick:K,onFocus:()=>V(!0),onBlur:()=>{setTimeout(()=>V(!1),150)},readOnly:_,placeholder:Y,className:T??d,style:U??Q1,rows:z?1:void 0},void 0,!1,void 0,this),!_&&X1("input",{ref:f,type:"file",accept:"image/*",multiple:!0,style:{display:"none"},onChange:(E)=>{let l=E.target.files;if(l)for(let j of l)u(j);E.target.value=""}},void 0,!1,void 0,this),(Z.length>0||i)&&X1("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"6px",alignItems:"center"},children:[Z.map((E)=>X1("div",{style:{position:"relative",width:"56px",height:"56px",borderRadius:"6px",overflow:"hidden",border:"1px solid var(--color-border-subtle)",flexShrink:0},children:[X1("img",{src:T5(E),alt:"",style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}},void 0,!1,void 0,this),!_&&X1("button",{onClick:(l)=>{l.stopPropagation(),q(E)},style:{position:"absolute",top:"2px",right:"2px",width:"16px",height:"16px",borderRadius:"50%",background:"rgba(0,0,0,0.6)",color:"white",border:"none",cursor:"pointer",fontSize:"11px",display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1,padding:0},title:"Remove image",children:"×"},void 0,!1,void 0,this)]},E,!0,void 0,this)),i&&X1(M2,{onClick:R},void 0,!1,void 0,this)]},void 0,!0,void 0,this),S&&X1("div",{style:{fontSize:"11px",color:"var(--color-text-tertiary)",fontFamily:"'Inter', sans-serif",marginTop:"4px"},children:"Uploading..."},void 0,!1,void 0,this),O&&X1("div",{style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",background:"var(--color-highlight-bg)",opacity:0.9,border:"2px dashed var(--color-highlight-border)",borderRadius:"6px",zIndex:10,pointerEvents:"none",fontSize:"12px",fontFamily:"'Inter', sans-serif",color:"var(--color-text-secondary)"},children:"Drop image"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function M2({onClick:Q,size:$=16}){return X1("button",{onClick:(Z)=>{Z.stopPropagation(),Q()},style:{width:`${$*2}px`,height:`${$*2}px`,borderRadius:"6px",border:"none",background:"transparent",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--color-text-tertiary)",flexShrink:0,transition:"color 0.15s"},title:"Attach image",onMouseEnter:(Z)=>{Z.currentTarget.style.color="var(--color-text-secondary)"},onMouseLeave:(Z)=>{Z.currentTarget.style.color="var(--color-text-tertiary)"},children:X1("svg",{width:$,height:$,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[X1("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"},void 0,!1,void 0,this),X1("circle",{cx:"8.5",cy:"8.5",r:"1.5"},void 0,!1,void 0,this),X1("polyline",{points:"21 15 16 10 5 21"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function N5({images:Q}){if(!Q.length)return null;return X1("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"6px"},children:Q.map(($)=>X1("div",{style:{width:"56px",height:"56px",borderRadius:"6px",overflow:"hidden",border:"1px solid var(--color-border-subtle)",flexShrink:0},children:X1("img",{src:T5($),alt:"",style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}},void 0,!1,void 0,this)},$,!1,void 0,this))},void 0,!1,void 0,this)}import{SessionContext as j7}from"#canvas/runtime";import{jsxDEV as z1,Fragment as C7}from"react/jsx-dev-runtime";function A7({anchorEl:Q,scrollContainer:$,onClose:Z,ignoreSelector:J,zIndex:q="50",padding:X="12px",width:Y="280px",children:G}){let z=u0(null),_=u0(Z);_.current=Z;let{style:W,parent:K}=X5(Q,$);return S7(()=>{let H=setTimeout(()=>{let T=(U)=>{if(z.current&&!z.current.contains(U.target)){if(J&&U.target.closest?.(J))return;_.current(),document.removeEventListener("mousedown",T)}};return document.addEventListener("mousedown",T),()=>document.removeEventListener("mousedown",T)},0);return()=>clearTimeout(H)},[J]),w7(z1("div",{ref:z,style:{...W,zIndex:q,width:Y,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:G},void 0,!1,void 0,this),K)}var B5=[{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"]}],F5=B5.flatMap((Q)=>Q.items);function L5({anchorEl:Q,scrollContainer:$,snippet:Z,truncateAt:J=100,header:q,initialNote:X="",initialImages:Y,onConfirm:G,onCancel:z,onDelete:_}){let W=b7(j7),K=X!==""||!!_,[H,T]=Q0(X),[U,L]=Q0(Y||[]),[N,P]=Q0(null),[O,w]=Q0(K),[S,M]=Q0(!1),b=u0(null),V=u0(null),v=x0(()=>{if(H.trim()||U.length>0)G(H.trim(),U);else if(K&&_)_();else z()},[H,U,G,z,K,_]),p=x0(()=>{if(K){if(!H.trim()&&U.length===0&&_){_(),z();return}G(H,U);return}z()},[H,U,K,G,z,_]),f=!K,R=H.trim().length>0?F5.filter((j)=>j.toLowerCase().startsWith(H.trim().toLowerCase())):F5,k=!f||O?[]:R.length===1&&R[0].toLowerCase()===H.trim().toLowerCase()?[]:R,u=new Set(k),I=B5.map((j)=>({label:j.label,items:j.items.filter((g)=>u.has(g))})).filter((j)=>j.items.length>0),B=I.map((j)=>j.items),D=B.flat(),x=O5(()=>{if(N===null)return 0;let j=0;for(let g=0;g<B.length;g++){if(N<j+B[g].length)return g;j+=B[g].length}return 0},[N,B]),A=O5(()=>{if(N===null)return 0;let j=0;for(let g=0;g<x;g++)j+=B[g].length;return N-j},[N,x,B]),m=(j,g)=>{let e=0;for(let K1=0;K1<j;K1++)e+=B[K1].length;return e+g},[d,Q1]=Q0(H);if(H!==d)Q1(H),P(null),w(K);let i=x0((j)=>{T(j)},[]),E=Z.length>J?Z.slice(0,J)+"...":Z,l=x0((j)=>{if(D.length>0&&(j.key==="ArrowDown"||j.key==="ArrowUp"||j.key==="ArrowLeft"||j.key==="ArrowRight")){if(j.preventDefault(),N===null){P(0);return}if(j.key==="ArrowDown"){let g=Math.min(A+1,B[x].length-1);P(m(x,g))}else if(j.key==="ArrowUp"){let g=Math.max(A-1,0);P(m(x,g))}else if(j.key==="ArrowRight"){let g=Math.min(x+1,B.length-1),e=Math.min(A,B[g].length-1);P(m(g,e))}else if(j.key==="ArrowLeft"){let g=Math.max(x-1,0),e=Math.min(A,B[g].length-1);P(m(g,e))}return}if(N!==null&&D.length>0){if(j.key==="Tab"){j.preventDefault(),i(D[N]);return}if(j.key==="Enter"&&!j.shiftKey){j.preventDefault(),G(D[N],U);return}}if(j.key==="Enter"&&!j.shiftKey){j.preventDefault(),v();return}if(j.key==="Escape")if(D.length>0&&!O)w(!0);else if(K)p();else z()},[D,N,A,x,B,m,i,G,U,v,O,K,p,z]);return z1(A7,{anchorEl:Q,scrollContainer:$,onClose:K?p:z,ignoreSelector:K?"[data-annotation-id]":void 0,zIndex:K?"60":"50",padding:K?"10px 12px":"12px",width:"420px",children:[!K&&(q??z1("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:["“",E,"”"]},void 0,!0,void 0,this)),z1(m0,{note:H,onNoteChange:T,images:U,onAddImage:(j)=>L((g)=>[...g,j]),onRemoveImage:(j)=>L((g)=>g.filter((e)=>e!==j)),sessionId:W,autoFocus:!0,autoResize:K,textareaRef:b,onKeyDown:l,attachButton:"none",openFilePickerRef:V,textareaStyle:K?{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"}:{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),z1("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginTop:K?"6px":"8px"},children:[z1(M2,{onClick:()=>V.current?.(),size:14},void 0,!1,void 0,this),z1("div",{style:{flex:1}},void 0,!1,void 0,this),K?z1("button",{onClick:()=>{if(_)_();z()},onMouseEnter:()=>M(!0),onMouseLeave:()=>M(!1),style:{fontSize:"11px",color:S?"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):z1(C7,{children:[z1("button",{onClick:z,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),z1("button",{onClick:v,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)]},void 0,!0,void 0,this),D.length>0&&z1("div",{style:{marginTop:"6px",borderTop:"1px solid var(--color-border-subtle)",paddingTop:"8px",display:"flex",gap:"4px"},children:I.map((j)=>z1("div",{style:{flex:1},children:[z1("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:j.label},void 0,!1,void 0,this),j.items.map((g)=>{let e=D.indexOf(g);return z1("div",{onMouseDown:(K1)=>{K1.preventDefault(),K1.stopPropagation(),i(g)},onMouseEnter:()=>P(e),style:{padding:"3px 6px",fontSize:"12px",borderRadius:"4px",fontFamily:"'Inter', sans-serif",color:e===N?"var(--color-text-primary)":"var(--color-text-secondary)",background:e===N?"var(--color-highlight-selected)":"transparent",cursor:"pointer"},children:[z1("span",{style:{fontWeight:500},children:g.slice(0,H.trim().length)},void 0,!1,void 0,this),g.slice(H.trim().length)]},g,!0,void 0,this)})]},j.label,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Z0({anchorEl:Q,scrollContainer:$,snippet:Z,truncateAt:J,header:q,onAdd:X,onCancel:Y}){return z1(L5,{anchorEl:Q,scrollContainer:$,snippet:Z,truncateAt:J,header:q,onConfirm:(G,z)=>X(G,z),onCancel:Y},void 0,!1,void 0,this)}function q0({anchorEl:Q,scrollContainer:$,initialNote:Z,initialImages:J,onUpdate:q,onDelete:X,onClose:Y}){return z1(L5,{anchorEl:Q,scrollContainer:$,snippet:"",initialNote:Z,initialImages:J,onConfirm:(G,z)=>{q(G,z),Y()},onDelete:X,onCancel:Y},void 0,!1,void 0,this)}import{useEffect as p0,useState as y5,useRef as l1,useCallback as P5}from"react";function r1(Q,$){let Z=[],J=I7(Q);for(let q of J){let X=document.createRange();if(X.selectNodeContents(q),q===Q.startContainer)X.setStart(q,Q.startOffset);if(q===Q.endContainer)X.setEnd(q,Q.endOffset);let Y=X.toString();if(!Y||!Y.trim())continue;let G=document.createElement("mark");G.setAttribute("data-annotation-id",$);try{X.surroundContents(G)}catch{let z=X.extractContents();G.appendChild(z),X.insertNode(G)}Z.push(G)}return Z}function I7(Q){let $=[],Z=Q.commonAncestorContainer;if(Z.nodeType===Node.TEXT_NODE)return $.push(Z),$;let J=document.createTreeWalker(Z,NodeFilter.SHOW_TEXT),q;while(q=J.nextNode()){if(q.parentElement?.classList.contains("select-none"))continue;if(Q.intersectsNode(q))$.push(q)}return $}function d1(Q,$){let Z=document.querySelectorAll(`[data-annotation-id="${Q}"]`);for(let J of Z)J.classList.toggle("mark-active",$)}function g0(Q,$){if($!=null&&$!==Q)d1($,!1);if(Q!=null)d1(Q,!0)}function v0(Q,$){let Z=document.querySelectorAll(`[data-annotation-id="${Q}"]`);for(let J of Z)J.setAttribute("data-annotation-id",$)}function f0(Q,$){let Z=$.filter((G)=>!document.querySelector(`[data-annotation-id="${G.id}"]`));if(!Z.length)return;let J=[],q="",X=document.createTreeWalker(Q,NodeFilter.SHOW_TEXT),Y;while(Y=X.nextNode()){if(Y.parentElement?.classList.contains("select-none"))continue;J.push({node:Y,start:q.length}),q+=Y.textContent||""}for(let G of Z){let z=G.snippet;if(!z)continue;let _=[],W=0;while(!0){let N=q.indexOf(z,W);if(N===-1)break;_.push(N),W=N+1}if(_.length===0)continue;let K=_[0];if(_.length>1&&G.context){let N=-1;for(let P of _){let O=0;if(G.context.before){let w=q.slice(Math.max(0,P-80),P);if(w.includes(G.context.before))O+=2;else if(G.context.before.length>10&&w.includes(G.context.before.slice(-10)))O+=1}if(G.context.after){let w=q.slice(P+z.length,P+z.length+80);if(w.includes(G.context.after))O+=2;else if(G.context.after.length>10&&w.includes(G.context.after.slice(0,10)))O+=1}if(O>N)N=O,K=P}}let H=K,T=K+z.length,U=M5(J,H),L=M5(J,T);if(!U||!L)continue;try{let N=document.createRange();N.setStart(U.node,U.offset),N.setEnd(L.node,L.offset),r1(N,G.id)}catch{}}}function M5(Q,$){for(let Z=Q.length-1;Z>=0;Z--)if(Q[Z].start<=$){let J=$-Q[Z].start,q=Q[Z].node.textContent?.length??0;if(J<=q)return{node:Q[Z].node,offset:J}}return null}function h0(Q){let $=document.querySelectorAll(`[data-annotation-id="${Q}"]`);for(let Z of $){let J=Z.parentNode;if(!J)continue;while(Z.firstChild)J.insertBefore(Z.firstChild,Z);J.removeChild(Z),J.normalize()}}import{jsxDEV as y2,Fragment as V7}from"react/jsx-dev-runtime";function i1(Q){let{containerRef:$,restoreKey:Z,restoreAnnotations:J,extractContext:q,filePath:X,canvasFile:Y,scrollContainer:G}=Q,{annotations:z,addAnnotationWithId:_,removeAnnotation:W,updateAnnotation:K,addAnnotationImage:H,removeAnnotationImage:T,activeAnnotationId:U,setActiveAnnotationId:L}=Y1(),[N,P]=y5(null),[O,w]=y5(null),S=l1(q);S.current=q;let M=l1(X);M.current=X;let b=l1(Y);b.current=Y;let V=l1(_);V.current=_;let v=l1(U);v.current=U;let p=l1(L);p.current=L,p0(()=>{if(!$.current)return;let I=setTimeout(()=>{if($.current)f0($.current,J)},50);return()=>clearTimeout(I)},[Z]);let f=l1(null);p0(()=>{g0(U,f.current),f.current=U},[U]),p0(()=>{let I=$.current;if(!I)return;let B=(A)=>{let m=A.target.closest("[data-annotation-id]");if(!m)return;A.stopPropagation();let d=m.getAttribute("data-annotation-id");if(d===v.current)P({anchorEl:m,annId:d});else p.current(d)},D=(A)=>{let m=A.target.closest("[data-annotation-id]");if(m)p.current(m.getAttribute("data-annotation-id"))},x=(A)=>{let m=A.target.closest("[data-annotation-id]"),d=A.relatedTarget?.closest?.("[data-annotation-id]");if(m&&!d&&!document.getElementById("ann-inline-popover"))p.current(null)};return I.addEventListener("click",B),I.addEventListener("mouseover",D),I.addEventListener("mouseout",x),()=>{I.removeEventListener("click",B),I.removeEventListener("mouseover",D),I.removeEventListener("mouseout",x)}},[Z]),p0(()=>{let I=()=>R();return document.addEventListener("mouseup",I),()=>document.removeEventListener("mouseup",I)},[]);let R=P5(()=>{let I=window.getSelection();if(!I||I.isCollapsed||!I.toString().trim())return;if(!$.current)return;let B=I.getRangeAt(0);if(!$.current.contains(B.startContainer))return;if(B.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let D=I.toString().trim();if(D.length<2)return;let x=S.current(B),A=B.cloneRange(),m=`__pending_${Date.now()}`;try{r1(A,m)}catch{}window.getSelection()?.removeAllRanges();let d=document.querySelectorAll(`[data-annotation-id="${m}"]`),Q1=d[d.length-1];if(!Q1)return;w({anchorEl:Q1,tempId:m,snippet:D,ctx:x})},[]),k=P5((I,B,D,x)=>{w({anchorEl:I,tempId:B,snippet:D,ctx:x})},[]);return{popovers:y2(V7,{children:[N&&(()=>{let I=z.find((B)=>B.id===N.annId);if(!I)return null;return y2(q0,{anchorEl:N.anchorEl,scrollContainer:G,initialNote:I.note,initialImages:I.images,onUpdate:(B,D)=>{K(N.annId,B);let x=I.images||[];for(let A of D)if(!x.includes(A))H(N.annId,A);for(let A of x)if(!D.includes(A))T(N.annId,A)},onDelete:()=>{W(N.annId),L(null)},onClose:()=>P(null)},void 0,!1,void 0,this)})(),O&&y2(Z0,{anchorEl:O.anchorEl,scrollContainer:G,snippet:O.snippet,truncateAt:80,onAdd:(I,B)=>{let D=F1();v0(O.tempId,D),V.current(D,O.snippet,I,M.current,O.ctx,B,b.current),w(null)},onCancel:()=>{h0(O.tempId),w(null)}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),openCreatePopover:k,isPopoverOpen:!!(N||O)}}import{jsxDEV as q1,Fragment as v7}from"react/jsx-dev-runtime";var b2="[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']",S2="[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 B0({revision:Q,filename:$}){let Z=D7(E7),[J,q]=b1(null),[X,Y]=b1(null),[G,z]=b1(!0),_=R7(null),{annotations:W,addAnnotationWithId:K,removeAnnotation:H,updateAnnotation:T,addAnnotationImage:U,removeAnnotationImage:L,activeAnnotationId:N,setActiveAnnotationId:P}=Y1(),O=F0(()=>W.filter((A)=>!A.filePath&&(!A.canvasFile||A.canvasFile===$)),[W,$]),[w,S]=b1(null),[M,b]=b1(null),[V,v]=b1(null),[p,f]=b1(null),[R,k]=b1(!1);o1(()=>{z(!0),Y(null),f(null),import(_5($,Q)).then((A)=>{q(()=>A.default),z(!1)}).catch((A)=>{Y(A.message),z(!1)})},[Z,Q,$]);let u=document.getElementById("plan-scroll-container"),{popovers:I,isPopoverOpen:B}=i1({containerRef:_,restoreKey:J,restoreAnnotations:O,extractContext:(A)=>c1(A,_.current),canvasFile:$,scrollContainer:u}),D=F0(()=>{let A=new Map;for(let m of O)if(m.snippet.startsWith("["))A.set(m.snippet,m.id);return A},[O]);o1(()=>{let A=_.current;if(!A)return;let m=(Q1)=>{if(V||B)return;let i=Q1.target;if(i.closest("[data-block-comment-btn]"))return;k(!1);let E=i.closest(b2);if(E&&A.contains(E)){let g=a1(A).indexOf(E);f(g>=0?g:null)}else f(null);let l=i.closest(S2);if(l&&A.contains(l)){b(l);let j=J0(l),g=j?D.get(j):void 0;if(g&&g!==N)P(g)}else b(null)},d=(Q1)=>{if(V||B)return;if(Q1.relatedTarget?.closest("[data-block-comment-btn]"))return;b(null),P(null)};return A.addEventListener("mousemove",m),A.addEventListener("mouseleave",d),()=>{A.removeEventListener("mousemove",m),A.removeEventListener("mouseleave",d)}},[J,V,B,D,N]),o1(()=>{let A=(m)=>{let d=m.target.tagName;if(d==="INPUT"||d==="TEXTAREA"||m.target.isContentEditable)return;if(V||B)return;let Q1=_.current;if(!Q1)return;if(m.key==="ArrowDown"){m.preventDefault(),k(!0);let i=a1(Q1);if(i.length===0)return;f((E)=>{if(E===null)return 0;return Math.min(E+1,i.length-1)})}else if(m.key==="ArrowUp"){m.preventDefault(),k(!0);let i=a1(Q1);if(i.length===0)return;f((E)=>{if(E===null)return i.length-1;return Math.max(E-1,0)})}else if(m.key==="a"||m.key==="A"){if(p===null||!Q1)return;m.preventDefault();let E=a1(Q1)[p];if(!E)return;let l=J0(E);if(!l)return;let j=D.get(l);if(j)P(j),v({anchorEl:E,snippet:l,annId:j});else v({anchorEl:E,snippet:l})}else if(m.key===" "||m.key==="Enter"){if(p===null)return;let E=a1(Q1)[p];if(!E)return;let l=E.getAttribute("data-md");if(l==="choice-option"||l==="multichoice-option")m.preventDefault(),E.dispatchEvent(new CustomEvent("kb-select",{bubbles:!0}));else if(l==="userinput"){m.preventDefault();let j=E.querySelector("textarea");if(j){j.focus();let g=(e)=>{if(e.key==="Escape")e.preventDefault(),j.blur(),k(!0)};j.addEventListener("keydown",g),j.addEventListener("blur",()=>j.removeEventListener("keydown",g),{once:!0})}}else if(l==="rangeinput"){m.preventDefault();let j=E.querySelector("input[type='range']");if(j){j.focus();let g=(e)=>{if(e.key==="Escape"||e.key==="ArrowUp"||e.key==="ArrowDown")e.preventDefault(),j.blur(),k(!0)};j.addEventListener("keydown",g),j.addEventListener("blur",()=>j.removeEventListener("keydown",g),{once:!0})}}}else if(m.key==="Escape")f(null),k(!1),P(null)};return document.addEventListener("keydown",A),()=>document.removeEventListener("keydown",A)},[p,V,B,D]),o1(()=>{let A=_.current;if(!A||p===null||!R)return;let d=a1(A)[p];if(!d)return;d.style.outline="2px solid var(--color-accent-blue)",d.style.outlineOffset="-2px",d.style.borderRadius="8px",d.scrollIntoView({block:"nearest",behavior:"smooth"});let Q1=J0(d),i=Q1?D.get(Q1):void 0;if(i)P(i);return()=>{d.style.outline="",d.style.outlineOffset="",d.style.borderRadius=""}},[p,R,D]);let x=F0(()=>J?q1(J,{},void 0,!1,void 0,this):null,[J]);if(G)return q1("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-body",children:"Loading canvas..."},void 0,!1,void 0,this);if(X)return q1("div",{className:"bg-accent-red-muted rounded-lg p-5",children:[q1("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Compilation Error"},void 0,!1,void 0,this),q1("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:X},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(!J)return q1("div",{className:"text-text-tertiary text-center py-8 font-body text-body",children:"No canvas loaded"},void 0,!1,void 0,this);return q1(m7.Provider,{value:$,children:[q1("div",{ref:_,className:"plan-content plan-updated",children:x},void 0,!1,void 0,this),w&&q1(g7,{note:w.note,onSave:(A)=>{T(w.id,A),S(null)},onCancel:()=>S(null)},void 0,!1,void 0,this),I,q1(x7,{containerRef:_,hoveredBlock:M,focusedBlockIndex:p,blockPopover:V,blockAnnotationMap:D,activeAnnotationId:N,onOpen:(A,m,d)=>{if(d)P(d),v({anchorEl:A,snippet:m,annId:d});else v({anchorEl:A,snippet:m})}},void 0,!1,void 0,this),V&&!V.annId&&q1(Z0,{anchorEl:V.anchorEl,scrollContainer:u,snippet:V.snippet,truncateAt:80,onAdd:(A,m)=>{let d=F1();K(d,V.snippet,A,void 0,void 0,m,$),v(null)},onCancel:()=>v(null)},void 0,!1,void 0,this),V?.annId&&(()=>{let A=O.find((m)=>m.id===V.annId);if(!A)return null;return q1(q0,{anchorEl:V.anchorEl,scrollContainer:u,initialNote:A.note,initialImages:A.images,onUpdate:(m,d)=>{T(V.annId,m);let Q1=A.images||[];for(let i of d)if(!Q1.includes(i))U(V.annId,i);for(let i of Q1)if(!d.includes(i))L(V.annId,i)},onDelete:()=>{H(V.annId),P(null),v(null)},onClose:()=>v(null)},void 0,!1,void 0,this)})()]},void 0,!0,void 0,this)}function a1(Q){return Array.from(Q.querySelectorAll(b2))}function J0(Q){let $=Q.getAttribute("data-md");if($==="item"){let Z=Q.getAttribute("data-md-label");return Z?`[Item] ${Z}`:null}if($==="section"){let Z=Q.getAttribute("data-md-title");return Z?`[Section] ${Z}`:null}if($==="callout"){let Z=Q.getAttribute("data-md-type")||"info",J=Q.textContent?.trim().slice(0,60)||"Callout";return`[Callout:${Z}] ${J}`}if($==="note")return`[Note] ${Q.textContent?.trim().slice(0,60)||"Note"}`;if(Q.tagName==="TR"){let Z=Array.from(Q.querySelectorAll("td")).map((J)=>J.textContent?.trim()).filter(Boolean);return Z.length?`[Row] ${Z.join(" | ")}`:null}if($==="checklist-item"){let Z=Q.getAttribute("data-md-label");return Z?`[Checklist] ${Z}`:null}if($==="choice-option"||$==="multichoice-option"){let Z=Q.getAttribute("data-md-label");return Z?`[Option] ${Z}`:null}if($==="userinput"){let Z=Q.getAttribute("data-md-label");return Z?`[Input] ${Z}`:null}if($==="rangeinput"){let Z=Q.getAttribute("data-md-label");return Z?`[Range] ${Z}`:null}if($==="image"){let Z=Q.getAttribute("data-md-src");return Z?`[Image] ${Z}`:null}return null}function x7({containerRef:Q,hoveredBlock:$,focusedBlockIndex:Z,blockPopover:J,blockAnnotationMap:q,activeAnnotationId:X,onOpen:Y}){let[G,z]=b1([]);o1(()=>{let T=Q.current;if(!T||q.size===0){z([]);return}let U=[];for(let L of T.querySelectorAll(S2)){let N=J0(L);if(N&&q.has(N))U.push(L)}z(U)},[q,Q.current]);let[_,W]=b1(null);o1(()=>{if(!X||!Q.current){W(null);return}for(let T of Q.current.querySelectorAll(b2)){let U=J0(T);if(U&&q.get(U)===X){W(T);return}}W(null)},[X,q]),o1(()=>{if(!_)return;return _.style.boxShadow="inset 0 0 0 1.5px var(--color-highlight-bg)",_.style.borderRadius="8px",()=>{_.style.boxShadow="",_.style.borderRadius=""}},[_]);let K=F0(()=>{if(Z===null||!Q.current)return null;let T=a1(Q.current)[Z];if(!T)return null;return T.matches(S2)?T:null},[Z,Q.current]),H=F0(()=>{let T=new Set(G);if($)T.add($);if(K)T.add(K);if(J?.anchorEl)T.add(J.anchorEl);return Array.from(T)},[G,$,K,J]);return q1(v7,{children:H.map((T)=>q1(u7,{block:T,isHovered:T===$||T===K||T===J?.anchorEl,blockAnnotationMap:q,activeAnnotationId:X,onOpen:Y},T.getAttribute("data-task-id")||T.getAttribute("data-md-title")||T.textContent?.slice(0,30)||"block",!1,void 0,this))},void 0,!1,void 0,this)}function u7({block:Q,isHovered:$,blockAnnotationMap:Z,activeAnnotationId:J,onOpen:q}){let X=J0(Q);if(!X)return null;let Y=Z.get(X),G=!!Y;return k7(q1("button",{"data-block-comment-btn":!0,onClick:(_)=>{_.stopPropagation(),q(_.currentTarget,X,Y)},className:`absolute top-1 right-1 z-10 w-6 h-6 flex items-center justify-center rounded transition-all duration-150 ${G?Y===J?"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:G?"Edit annotation":"Add annotation",children:q1("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:G?"currentColor":"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:q1("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),Q)}function g7({note:Q,onSave:$,onCancel:Z}){let[J,q]=P2.useState(Q),X=P2.useRef(null);return P2.useEffect(()=>{X.current?.focus(),X.current?.select()},[]),q1("div",{className:"fixed inset-0 z-50 bg-black/40 flex items-center justify-center",onClick:Z,children:q1("div",{className:"bg-bg-elevated border border-border-hover rounded-lg shadow-md p-4 w-80",onClick:(Y)=>Y.stopPropagation(),children:[q1("div",{className:"text-tiny uppercase tracking-widest text-text-tertiary font-body mb-2",children:"Edit annotation"},void 0,!1,void 0,this),q1("textarea",{ref:X,value:J,onChange:(Y)=>q(Y.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:(Y)=>{if(Y.key==="Enter"&&(Y.ctrlKey||Y.metaKey))$(J.trim());if(Y.key==="Escape")Z()}},void 0,!1,void 0,this),q1("div",{className:"flex justify-end gap-2 mt-2",children:[q1("button",{onClick:Z,className:"text-meta text-text-tertiary font-body px-3 py-1",children:"Cancel"},void 0,!1,void 0,this),q1("button",{onClick:()=>$(J.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 s7,{useRef as C5,useEffect as C2,useCallback as I5,useState as Y0,useContext as l0}from"react";function L0(Q,$,Z,J){let q=[],X=Q.filter((K)=>K.filePath===T1),Y=Q.filter((K)=>!K.filePath),G=Q.filter((K)=>K.filePath&&K.filePath!==T1),z=Z?Array.from(Z.values()).filter((K)=>j2(K)):[],_=J?Array.from(J.values()).filter((K)=>K.markdown.trim()):[];if(z.length>0||_.length>0){q.push("## Responses"),q.push("");for(let K of z)q.push(p7(K));for(let K of _)q.push(K.markdown.trim()),q.push("")}if(X.length>0){q.push("## Annotations on agent response"),q.push("");for(let K of X)q.push(w2(K))}if(Y.length>0){q.push("## Canvas annotations"),q.push("");let K=new Map;for(let U of Y){let L=U.canvasFile||"";if(!K.has(L))K.set(L,[]);K.get(L).push(U)}let H=[...K.keys()].sort(),T=H.length>1||H.length===1&&H[0]!=="";for(let U of H){let L=K.get(U);if(T&&U)q.push(`### ${U.replace(/\.jsx$/,"")}`),q.push("");let N=c7(L);q.push(S5(N))}}if(G.length>0){let K={};for(let H of G){let T=H.filePath;if(!K[T])K[T]=[];K[T].push(H)}q.push("## File annotations"),q.push("");for(let[H,T]of Object.entries(K)){q.push(`### ${H}`),q.push("");for(let U of T)q.push(w2(U))}}if($.trim())q.push("## General notes"),q.push(""),q.push($.trim()),q.push("");return q.join(`
|
|
58
|
+
`}strong({tokens:Q}){return`<strong>${this.parser.parseInline(Q)}</strong>`}em({tokens:Q}){return`<em>${this.parser.parseInline(Q)}</em>`}codespan({text:Q}){return`<code>${P1(Q,!0)}</code>`}br(Q){return"<br>"}del({tokens:Q}){return`<del>${this.parser.parseInline(Q)}</del>`}link({href:Q,title:$,tokens:Z}){let J=this.parser.parseInline(Z),q=d2(Q);if(q===null)return J;Q=q;let Y='<a href="'+Q+'"';return $&&(Y+=' title="'+P1($)+'"'),Y+=">"+J+"</a>",Y}image({href:Q,title:$,text:Z,tokens:J}){J&&(Z=this.parser.parseInline(J,this.parser.textRenderer));let q=d2(Q);if(q===null)return P1(Z);Q=q;let Y=`<img src="${Q}" alt="${P1(Z)}"`;return $&&(Y+=` title="${P1($)}"`),Y+=">",Y}text(Q){return"tokens"in Q&&Q.tokens?this.parser.parseInline(Q.tokens):("escaped"in Q)&&Q.escaped?Q.text:P1(Q.text)}},T2=class{strong({text:Q}){return Q}em({text:Q}){return Q}codespan({text:Q}){return Q}del({text:Q}){return Q}html({text:Q}){return Q}text({text:Q}){return Q}link({text:Q}){return""+Q}image({text:Q}){return""+Q}br(){return""}checkbox({raw:Q}){return Q}},O1=class Q{options;renderer;textRenderer;constructor($){this.options=$||c1,this.options.renderer=this.options.renderer||new R0,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new T2}static parse($,Z){return new Q(Z).parse($)}static parseInline($,Z){return new Q(Z).parseInline($)}parse($){let Z="";for(let J=0;J<$.length;J++){let q=$[J];if(this.options.extensions?.renderers?.[q.type]){let X=q,G=this.options.extensions.renderers[X.type].call({parser:this},X);if(G!==!1||!["space","hr","heading","code","table","blockquote","list","html","def","paragraph","text"].includes(X.type)){Z+=G||"";continue}}let Y=q;switch(Y.type){case"space":{Z+=this.renderer.space(Y);break}case"hr":{Z+=this.renderer.hr(Y);break}case"heading":{Z+=this.renderer.heading(Y);break}case"code":{Z+=this.renderer.code(Y);break}case"table":{Z+=this.renderer.table(Y);break}case"blockquote":{Z+=this.renderer.blockquote(Y);break}case"list":{Z+=this.renderer.list(Y);break}case"checkbox":{Z+=this.renderer.checkbox(Y);break}case"html":{Z+=this.renderer.html(Y);break}case"def":{Z+=this.renderer.def(Y);break}case"paragraph":{Z+=this.renderer.paragraph(Y);break}case"text":{Z+=this.renderer.text(Y);break}default:{let X='Token with "'+Y.type+'" type was not found.';if(this.options.silent)return console.error(X),"";throw Error(X)}}}return Z}parseInline($,Z=this.renderer){let J="";for(let q=0;q<$.length;q++){let Y=$[q];if(this.options.extensions?.renderers?.[Y.type]){let G=this.options.extensions.renderers[Y.type].call({parser:this},Y);if(G!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(Y.type)){J+=G||"";continue}}let X=Y;switch(X.type){case"escape":{J+=Z.text(X);break}case"html":{J+=Z.html(X);break}case"link":{J+=Z.link(X);break}case"image":{J+=Z.image(X);break}case"checkbox":{J+=Z.checkbox(X);break}case"strong":{J+=Z.strong(X);break}case"em":{J+=Z.em(X);break}case"codespan":{J+=Z.codespan(X);break}case"br":{J+=Z.br(X);break}case"del":{J+=Z.del(X);break}case"text":{J+=Z.text(X);break}default:{let G='Token with "'+X.type+'" type was not found.';if(this.options.silent)return console.error(G),"";throw Error(G)}}}return J}},W0=class{options;block;constructor(Q){this.options=Q||c1}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens","emStrongMask"]);static passThroughHooksRespectAsync=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(Q){return Q}postprocess(Q){return Q}processAllTokens(Q){return Q}emStrongMask(Q){return Q}provideLexer(){return this.block?N1.lex:N1.lexInline}provideParser(){return this.block?O1.parse:O1.parseInline}},G7=class{defaults=X2();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=O1;Renderer=R0;TextRenderer=T2;Lexer=N1;Tokenizer=V0;Hooks=W0;constructor(...Q){this.use(...Q)}walkTokens(Q,$){let Z=[];for(let J of Q)switch(Z=Z.concat($.call(this,J)),J.type){case"table":{let q=J;for(let Y of q.header)Z=Z.concat(this.walkTokens(Y.tokens,$));for(let Y of q.rows)for(let X of Y)Z=Z.concat(this.walkTokens(X.tokens,$));break}case"list":{let q=J;Z=Z.concat(this.walkTokens(q.items,$));break}default:{let q=J;this.defaults.extensions?.childTokens?.[q.type]?this.defaults.extensions.childTokens[q.type].forEach((Y)=>{let X=q[Y].flat(1/0);Z=Z.concat(this.walkTokens(X,$))}):q.tokens&&(Z=Z.concat(this.walkTokens(q.tokens,$)))}}return Z}use(...Q){let $=this.defaults.extensions||{renderers:{},childTokens:{}};return Q.forEach((Z)=>{let J={...Z};if(J.async=this.defaults.async||J.async||!1,Z.extensions&&(Z.extensions.forEach((q)=>{if(!q.name)throw Error("extension name required");if("renderer"in q){let Y=$.renderers[q.name];Y?$.renderers[q.name]=function(...X){let G=q.renderer.apply(this,X);return G===!1&&(G=Y.apply(this,X)),G}:$.renderers[q.name]=q.renderer}if("tokenizer"in q){if(!q.level||q.level!=="block"&&q.level!=="inline")throw Error("extension level must be 'block' or 'inline'");let Y=$[q.level];Y?Y.unshift(q.tokenizer):$[q.level]=[q.tokenizer],q.start&&(q.level==="block"?$.startBlock?$.startBlock.push(q.start):$.startBlock=[q.start]:q.level==="inline"&&($.startInline?$.startInline.push(q.start):$.startInline=[q.start]))}"childTokens"in q&&q.childTokens&&($.childTokens[q.name]=q.childTokens)}),J.extensions=$),Z.renderer){let q=this.defaults.renderer||new R0(this.defaults);for(let Y in Z.renderer){if(!(Y in q))throw Error(`renderer '${Y}' does not exist`);if(["options","parser"].includes(Y))continue;let X=Y,G=Z.renderer[X],z=q[X];q[X]=(..._)=>{let H=G.apply(q,_);return H===!1&&(H=z.apply(q,_)),H||""}}J.renderer=q}if(Z.tokenizer){let q=this.defaults.tokenizer||new V0(this.defaults);for(let Y in Z.tokenizer){if(!(Y in q))throw Error(`tokenizer '${Y}' does not exist`);if(["options","rules","lexer"].includes(Y))continue;let X=Y,G=Z.tokenizer[X],z=q[X];q[X]=(..._)=>{let H=G.apply(q,_);return H===!1&&(H=z.apply(q,_)),H}}J.tokenizer=q}if(Z.hooks){let q=this.defaults.hooks||new W0;for(let Y in Z.hooks){if(!(Y in q))throw Error(`hook '${Y}' does not exist`);if(["options","block"].includes(Y))continue;let X=Y,G=Z.hooks[X],z=q[X];W0.passThroughHooks.has(Y)?q[X]=(_)=>{if(this.defaults.async&&W0.passThroughHooksRespectAsync.has(Y))return(async()=>{let K=await G.call(q,_);return z.call(q,K)})();let H=G.call(q,_);return z.call(q,H)}:q[X]=(..._)=>{if(this.defaults.async)return(async()=>{let K=await G.apply(q,_);return K===!1&&(K=await z.apply(q,_)),K})();let H=G.apply(q,_);return H===!1&&(H=z.apply(q,_)),H}}J.hooks=q}if(Z.walkTokens){let q=this.defaults.walkTokens,Y=Z.walkTokens;J.walkTokens=function(X){let G=[];return G.push(Y.call(this,X)),q&&(G=G.concat(q.call(this,X))),G}}this.defaults={...this.defaults,...J}}),this}setOptions(Q){return this.defaults={...this.defaults,...Q},this}lexer(Q,$){return N1.lex(Q,$??this.defaults)}parser(Q,$){return O1.parse(Q,$??this.defaults)}parseMarkdown(Q){return($,Z)=>{let J={...Z},q={...this.defaults,...J},Y=this.onError(!!q.silent,!!q.async);if(this.defaults.async===!0&&J.async===!1)return Y(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 Y(Error("marked(): input parameter is undefined or null"));if(typeof $!="string")return Y(Error("marked(): input parameter is of type "+Object.prototype.toString.call($)+", string expected"));if(q.hooks&&(q.hooks.options=q,q.hooks.block=Q),q.async)return(async()=>{let X=q.hooks?await q.hooks.preprocess($):$,G=await(q.hooks?await q.hooks.provideLexer():Q?N1.lex:N1.lexInline)(X,q),z=q.hooks?await q.hooks.processAllTokens(G):G;q.walkTokens&&await Promise.all(this.walkTokens(z,q.walkTokens));let _=await(q.hooks?await q.hooks.provideParser():Q?O1.parse:O1.parseInline)(z,q);return q.hooks?await q.hooks.postprocess(_):_})().catch(Y);try{q.hooks&&($=q.hooks.preprocess($));let X=(q.hooks?q.hooks.provideLexer():Q?N1.lex:N1.lexInline)($,q);q.hooks&&(X=q.hooks.processAllTokens(X)),q.walkTokens&&this.walkTokens(X,q.walkTokens);let G=(q.hooks?q.hooks.provideParser():Q?O1.parse:O1.parseInline)(X,q);return q.hooks&&(G=q.hooks.postprocess(G)),G}catch(X){return Y(X)}}}onError(Q,$){return(Z)=>{if(Z.message+=`
|
|
59
|
+
Please report this to https://github.com/markedjs/marked.`,Q){let J="<p>An error occurred:</p><pre>"+P1(Z.message+"",!0)+"</pre>";return $?Promise.resolve(J):J}if($)return Promise.reject(Z);throw Z}}},p1=new G7;function t(Q,$){return p1.parse(Q,$)}t.options=t.setOptions=function(Q){return p1.setOptions(Q),t.defaults=p1.defaults,i2(t.defaults),t};t.getDefaults=X2;t.defaults=c1;t.use=function(...Q){return p1.use(...Q),t.defaults=p1.defaults,i2(t.defaults),t};t.walkTokens=function(Q,$){return p1.walkTokens(Q,$)};t.parseInline=p1.parseInline;t.Parser=O1;t.parser=O1.parse;t.Renderer=R0;t.TextRenderer=T2;t.Lexer=N1;t.lexer=N1.lex;t.Tokenizer=V0;t.Hooks=W0;t.parse=t;var{options:F4,setOptions:B4,use:L4,walkTokens:M4,parseInline:y4}=t;var P4=O1.parse,S4=N1.lex;import{SessionContext as O3,ActiveViewCtx as U4}from"#canvas/runtime";import{useState as O0,useCallback as S1,useEffect as K7,useRef as U7,useMemo as H7}from"react";import{AnnotationCtx as W7}from"#canvas/runtime";var T1="__agent-response__";function F1(){return`ann-${Date.now()}-${Math.random().toString(36).slice(2,6)}`}function N0(Q,$){Q.style.height="auto",Q.style.height=($?Math.max($,Q.scrollHeight):Q.scrollHeight)+"px"}import{useAnnotations as Y1}from"#canvas/runtime";import{jsxDEV as F7}from"react/jsx-dev-runtime";function N2(Q,$){return`canvas:${Q}:rev:${$}`}function E0(Q,$){try{let Z=localStorage.getItem(N2(Q,$));if(!Z)return null;return JSON.parse(Z)}catch{return null}}function T7(Q,$,Z){try{localStorage.setItem(N2(Q,$),JSON.stringify(Z))}catch{}}function N7(Q,$){try{localStorage.removeItem(N2(Q,$))}catch{}}function Y5({sessionId:Q,revision:$,isReadOnly:Z,remoteAnnotations:J,children:q}){let[Y,X]=O0(()=>{return(E0(Q,$)?.annotations??[]).map((x)=>({...x,source:x.source??"local"}))}),G=H7(()=>{if(!J||J.length===0)return Y;let R=new Set(Y.map((v)=>v.id)),x=J.filter((v)=>!R.has(v.id));return[...Y,...x.map((v)=>({...v,source:"remote"}))]},[Y,J]),[z,_]=O0(()=>{return E0(Q,$)?.generalNote??""}),[H,K]=O0(null),[W,T]=O0(()=>{let R=E0(Q,$);return R?.responses?new Map(R.responses):new Map}),[U,B]=O0(()=>{let R=E0(Q,$);return R?.feedbackEntries?new Map(R.feedbackEntries):new Map}),N=U7(null);K7(()=>{if(Z)return;if(N.current)clearTimeout(N.current);return N.current=setTimeout(()=>{T7(Q,$,{annotations:Y,generalNote:z,responses:Array.from(W.entries()),feedbackEntries:Array.from(U.entries())})},300),()=>{if(N.current)clearTimeout(N.current)}},[Y,z,W,U,Q,$,Z]);let M=S1((R,x,v,D,I,g,d)=>{X((w)=>[...w,{id:R,snippet:x,note:v,createdAt:new Date().toISOString(),filePath:D,context:I,...g?.length?{images:g}:{},...d?{canvasFile:d}:{}}])},[]),O=S1((R,x,v)=>{M(F1(),R,x,v)},[M]),A=S1((R,x)=>{X((v)=>v.map((D)=>D.id===R?{...D,note:x}:D))},[]),S=S1((R)=>{O7(R),X((x)=>x.filter((v)=>v.id!==R)),K((x)=>x===R?null:x)},[]),y=S1((R,x)=>{X((v)=>v.map((D)=>D.id===R?{...D,images:[...D.images||[],x]}:D))},[]),b=S1((R,x)=>{X((v)=>v.map((D)=>D.id===R?{...D,images:(D.images||[]).filter((I)=>I!==x)}:D))},[]),C=S1((R,x)=>{T((v)=>{let D=new Map(v);return D.set(R,x),D})},[]),E=S1((R,x)=>{B((v)=>{let D=v.get(R);if(D&&D.markdown===x.markdown&&D.label===x.label&&D.required===x.required)return v;let I=new Map(v);return I.set(R,x),I})},[]),c=S1((R)=>{B((x)=>{if(!x.has(R))return x;let v=new Map(x);return v.delete(R),v})},[]),h=S1(()=>{for(let R of document.querySelectorAll("[data-annotation-id]"))X5(R);X([]),_(""),K(null),T(new Map),B(new Map),N7(Q,$)},[Q,$]);return F7(W7.Provider,{value:{annotations:G,addAnnotation:O,addAnnotationWithId:M,updateAnnotation:A,removeAnnotation:S,addAnnotationImage:y,removeAnnotationImage:b,generalNote:z,setGeneralNote:_,clearAll:h,activeAnnotationId:H,setActiveAnnotationId:K,responses:W,setResponse:C,feedbackEntries:U,setFeedbackEntry:E,removeFeedbackEntry:c},children:q},void 0,!1,void 0,this)}function O7(Q){let $=document.querySelectorAll(`[data-annotation-id="${Q}"]`);for(let Z of $)X5(Z)}function X5(Q){let $=Q.parentNode;if(!$)return;let Z=document.createTextNode(Q.textContent||"");$.replaceChild(Z,Q),$.normalize()}import P2,{useEffect as s1,useState as b1,useRef as R7,useContext as D7,useMemo as F0}from"react";import{createPortal as k7}from"react-dom";import{SessionContext as E7,CanvasFileCtx as x7}from"#canvas/runtime";function d1(Q,$){let Z=z5(Q,"before",60),J=z5(Q,"after",60),q=L7(Q.startContainer,$);return{before:Z,after:J,hierarchy:q}}function z5(Q,$,Z){let J=B7($==="before"?Q.startContainer:Q.endContainer);if(!J)return"";let q="";if($==="before"){let Y=document.createTreeWalker(J,NodeFilter.SHOW_TEXT),X;while(X=Y.nextNode()){if(X===Q.startContainer){q+=(X.textContent||"").slice(0,Q.startOffset);break}if(X.parentElement?.hasAttribute("data-annotation-id"))continue;q+=X.textContent||""}if(q.length>Z){q=q.slice(-Z);let G=q.indexOf(" ");if(G>0)q=q.slice(G+1)}}else{let Y=document.createTreeWalker(J,NodeFilter.SHOW_TEXT),X=!1,G;while(G=Y.nextNode()){if(G===Q.endContainer){q+=(G.textContent||"").slice(Q.endOffset),X=!0;continue}if(X){if(G.parentElement?.hasAttribute("data-annotation-id"))continue;q+=G.textContent||""}}if(q.length>Z){q=q.slice(0,Z);let z=q.lastIndexOf(" ");if(z>0)q=q.slice(0,z)}}return q.trim()}function B7(Q){let $=new Set(["DIV","P","LI","PRE","BLOCKQUOTE","SECTION","ARTICLE"]),Z=Q.parentElement;while(Z){if($.has(Z.tagName))return Z;Z=Z.parentElement}return null}function L7(Q,$){let Z=[],J=Q instanceof Element?Q:Q.parentElement;while(J&&J!==$){let q=J.getAttribute?.("data-task-id");if(q){let Y=J.querySelector(".font-semibold");if(Y)Z.unshift(Y.textContent?.trim()||q)}if(J.tagName==="DIV"&&J.querySelector(":scope > button .font-heading, :scope > div .font-heading")){let Y=J.querySelector(".font-heading");if(Y)Z.unshift(Y.textContent?.trim()||"")}J=J.parentElement}return Z}function O2(Q){let $=Q.snippet.trim(),Z=Q.context,J=$.length<30;if(Z&&J&&(Z.before||Z.after)){let q=[];if(Z.before)q.push(`...${Z.before} `);if(q.push(`**${$}**`),Z.after)q.push(` ${Z.after}...`);return q.join("")}return $}import{useEffect as S7,useRef as u0,useState as Z0,useCallback as m0,useMemo as B5,useContext as b7}from"react";import{createPortal as w7}from"react-dom";function _5(Q,$){let q=$||document.body,Y=Q.getBoundingClientRect(),X=q.getBoundingClientRect(),G=q===document.body?window.scrollY:q.scrollTop,z=Y.bottom-X.top+G+8,_=Math.max(0,Math.min(Y.left-X.left,X.width-280-12));return q.style.position="relative",{style:{position:"absolute",top:`${z}px`,left:`${_}px`},parent:q}}import{useState as B2,useRef as L2,useCallback as C1,useEffect as y7}from"react";function M7(){if(typeof window<"u"&&window.__CANVAS_SHARE__?.shareId)return{isShared:!0,shareId:window.__CANVAS_SHARE__.shareId};return{isShared:!1,sessionId:typeof window<"u"?window.location.pathname.replace("/s/",""):""}}var Z1=M7();function G5(){if(Z1.isShared)return`/s/${Z1.shareId}/meta`;return`/api/session/${Z1.sessionId}/meta`}function K5(Q,$){let Z=Q.replace(/\.jsx$/,".js");if(Z1.isShared)return`/s/${Z1.shareId}/canvas/${encodeURIComponent(Z)}`;let J=$?`?rev=${$}&t=${Date.now()}`:`?t=${Date.now()}`;return`/api/session/${Z1.sessionId}/canvas/${encodeURIComponent(Z)}${J}`}function U5(){if(Z1.isShared)return`/s/${Z1.shareId}/upload`;return`/api/session/${Z1.sessionId}/upload`}var H5="canvas-reviewer-identity";function F2(){try{let Q=localStorage.getItem(H5);if(!Q)return null;return JSON.parse(Q)}catch{return null}}function W5(Q){let $=F2();if(!$)$={id:crypto.randomUUID?.()||String(Date.now()),name:Q};else $.name=Q;return localStorage.setItem(H5,JSON.stringify($)),$}async function T5(Q){if(!Z1.isShared)throw Error("submitSharedFeedback called outside shared mode");let $=await fetch(`/s/${Z1.shareId}/feedback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Q)});if(!$.ok){let Z=await $.text().catch(()=>"");throw Error(`Feedback submission failed: ${$.status} ${Z}`)}}var B1=!Z1.isShared,N5=!Z1.isShared;import{jsxDEV as X1}from"react/jsx-dev-runtime";function O5(Q){if(Q.startsWith("/s/")||Q.startsWith("http://")||Q.startsWith("https://"))return Q;return`/api/uploads/${Q.split("/").pop()}`}async function P7(Q,$){let Z=new FormData;Z.append("image",$);try{let q=await(await fetch(U5(),{method:"POST",body:Z})).json();if(Z1.isShared)return q.url||null;return q.path||null}catch{return null}}function x0({note:Q,onNoteChange:$,images:Z,onAddImage:J,onRemoveImage:q,sessionId:Y,placeholder:X="Add your note...",autoFocus:G=!1,autoResize:z=!1,readOnly:_=!1,onKeyDown:H,onTextareaClick:K,textareaRef:W,textareaClassName:T,textareaStyle:U,minHeight:B,attachButton:N="always",openFilePickerRef:M}){let[O,A]=B2(!1),[S,y]=B2(!1),[b,C]=B2(!1),E=L2(0),c=L2(null),h=L2(null),R=C1(()=>h.current?.click(),[]);if(M)M.current=R;let x=C1((m)=>{if(c.current=m,W)W.current=m;if(m&&z)N0(m,B)},[W,z,B]);y7(()=>{if(G&&c.current){let m=c.current;if(m.focus(),m.value)m.setSelectionRange(m.value.length,m.value.length)}},[G]);let v=C1(async(m)=>{if(!m.type.startsWith("image/"))return;y(!0);try{let a=await P7(Y,m);if(a)J(a)}finally{y(!1)}},[Y,J]),D=C1((m)=>{let a=m.clipboardData.items;for(let j of a)if(j.type.startsWith("image/")){m.preventDefault();let f=j.getAsFile();if(f)v(f);return}},[v]),I=C1((m)=>{if(m.preventDefault(),E.current++,E.current===1)A(!0)},[]),g=C1((m)=>{m.preventDefault()},[]),d=C1((m)=>{if(m.preventDefault(),E.current--,E.current===0)A(!1)},[]),w=C1((m)=>{m.preventDefault(),E.current=0,A(!1);for(let a of m.dataTransfer.files)if(a.type.startsWith("image/"))v(a)},[v]),k=C1((m)=>{if($(m.target.value),z)m.target.style.height="auto",m.target.style.height=(B?Math.max(B,m.target.scrollHeight):m.target.scrollHeight)+"px"},[$,z,B]),L="w-full bg-transparent text-[13px] font-body text-text-primary resize-none focus:outline-none leading-relaxed p-0 border-none",l={width:"100%",background:"transparent",border:"none",color:"var(--color-text-primary)",fontFamily:"'Inter', sans-serif",fontSize:"13px",lineHeight:"1.5",outline:"none",...z?{resize:"none",overflow:"hidden"}:{resize:"vertical"}},u=!_&&(N==="always"||N==="on-focus"&&b);return X1("div",{style:{position:"relative"},onDragEnter:_?void 0:I,onDragOver:_?void 0:g,onDragLeave:_?void 0:d,onDrop:_?void 0:w,children:[X1("textarea",{ref:x,value:Q,onChange:_?void 0:k,onPaste:_?void 0:D,onKeyDown:H,onClick:K,onFocus:()=>C(!0),onBlur:()=>{setTimeout(()=>C(!1),150)},readOnly:_,placeholder:X,className:T??L,style:U??l,rows:z?1:void 0},void 0,!1,void 0,this),!_&&X1("input",{ref:h,type:"file",accept:"image/*",multiple:!0,style:{display:"none"},onChange:(m)=>{let a=m.target.files;if(a)for(let j of a)v(j);m.target.value=""}},void 0,!1,void 0,this),(Z.length>0||u)&&X1("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"6px",alignItems:"center"},children:[Z.map((m)=>X1("div",{style:{position:"relative",width:"56px",height:"56px",borderRadius:"6px",overflow:"hidden",border:"1px solid var(--color-border-subtle)",flexShrink:0},children:[X1("img",{src:O5(m),alt:"",style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}},void 0,!1,void 0,this),!_&&X1("button",{onClick:(a)=>{a.stopPropagation(),q(m)},style:{position:"absolute",top:"2px",right:"2px",width:"16px",height:"16px",borderRadius:"50%",background:"rgba(0,0,0,0.6)",color:"white",border:"none",cursor:"pointer",fontSize:"11px",display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1,padding:0},title:"Remove image",children:"×"},void 0,!1,void 0,this)]},m,!0,void 0,this)),u&&X1(M2,{onClick:R},void 0,!1,void 0,this)]},void 0,!0,void 0,this),S&&X1("div",{style:{fontSize:"11px",color:"var(--color-text-tertiary)",fontFamily:"'Inter', sans-serif",marginTop:"4px"},children:"Uploading..."},void 0,!1,void 0,this),O&&X1("div",{style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",background:"var(--color-highlight-bg)",opacity:0.9,border:"2px dashed var(--color-highlight-border)",borderRadius:"6px",zIndex:10,pointerEvents:"none",fontSize:"12px",fontFamily:"'Inter', sans-serif",color:"var(--color-text-secondary)"},children:"Drop image"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function M2({onClick:Q,size:$=16}){return X1("button",{onClick:(Z)=>{Z.stopPropagation(),Q()},style:{width:`${$*2}px`,height:`${$*2}px`,borderRadius:"6px",border:"none",background:"transparent",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--color-text-tertiary)",flexShrink:0,transition:"color 0.15s"},title:"Attach image",onMouseEnter:(Z)=>{Z.currentTarget.style.color="var(--color-text-secondary)"},onMouseLeave:(Z)=>{Z.currentTarget.style.color="var(--color-text-tertiary)"},children:X1("svg",{width:$,height:$,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[X1("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"},void 0,!1,void 0,this),X1("circle",{cx:"8.5",cy:"8.5",r:"1.5"},void 0,!1,void 0,this),X1("polyline",{points:"21 15 16 10 5 21"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function F5({images:Q}){if(!Q.length)return null;return X1("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"6px"},children:Q.map(($)=>X1("div",{style:{width:"56px",height:"56px",borderRadius:"6px",overflow:"hidden",border:"1px solid var(--color-border-subtle)",flexShrink:0},children:X1("img",{src:O5($),alt:"",style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}},void 0,!1,void 0,this)},$,!1,void 0,this))},void 0,!1,void 0,this)}import{SessionContext as j7}from"#canvas/runtime";import{jsxDEV as z1,Fragment as C7}from"react/jsx-dev-runtime";function A7({anchorEl:Q,scrollContainer:$,onClose:Z,ignoreSelector:J,zIndex:q="50",padding:Y="12px",width:X="280px",children:G}){let z=u0(null),_=u0(Z);_.current=Z;let{style:H,parent:K}=_5(Q,$);return S7(()=>{let W=setTimeout(()=>{let T=(U)=>{if(z.current&&!z.current.contains(U.target)){if(J&&U.target.closest?.(J))return;_.current(),document.removeEventListener("mousedown",T)}};return document.addEventListener("mousedown",T),()=>document.removeEventListener("mousedown",T)},0);return()=>clearTimeout(W)},[J]),w7(z1("div",{ref:z,style:{...H,zIndex:q,width:X,background:"var(--color-bg-elevated)",border:"1px solid var(--color-border-hover)",borderRadius:"8px",boxShadow:"0 4px 12px var(--color-shadow)",padding:Y,fontFamily:"'Inter', sans-serif"},children:G},void 0,!1,void 0,this),K)}var M5=[{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"]}],L5=M5.flatMap((Q)=>Q.items);function y5({anchorEl:Q,scrollContainer:$,snippet:Z,truncateAt:J=100,header:q,initialNote:Y="",initialImages:X,onConfirm:G,onCancel:z,onDelete:_}){let H=b7(j7),K=Y!==""||!!_,[W,T]=Z0(Y),[U,B]=Z0(X||[]),[N,M]=Z0(null),[O,A]=Z0(K),[S,y]=Z0(!1),b=u0(null),C=u0(null),E=m0(()=>{if(W.trim()||U.length>0)G(W.trim(),U);else if(K&&_)_();else z()},[W,U,G,z,K,_]),c=m0(()=>{if(K){if(!W.trim()&&U.length===0&&_){_(),z();return}G(W,U);return}z()},[W,U,K,G,z,_]),h=!K,R=W.trim().length>0?L5.filter((j)=>j.toLowerCase().startsWith(W.trim().toLowerCase())):L5,x=!h||O?[]:R.length===1&&R[0].toLowerCase()===W.trim().toLowerCase()?[]:R,v=new Set(x),D=M5.map((j)=>({label:j.label,items:j.items.filter((f)=>v.has(f))})).filter((j)=>j.items.length>0),I=D.map((j)=>j.items),g=I.flat(),d=B5(()=>{if(N===null)return 0;let j=0;for(let f=0;f<I.length;f++){if(N<j+I[f].length)return f;j+=I[f].length}return 0},[N,I]),w=B5(()=>{if(N===null)return 0;let j=0;for(let f=0;f<d;f++)j+=I[f].length;return N-j},[N,d,I]),k=(j,f)=>{let $1=0;for(let K1=0;K1<j;K1++)$1+=I[K1].length;return $1+f},[L,l]=Z0(W);if(W!==L)l(W),M(null),A(K);let u=m0((j)=>{T(j)},[]),m=Z.length>J?Z.slice(0,J)+"...":Z,a=m0((j)=>{if(g.length>0&&(j.key==="ArrowDown"||j.key==="ArrowUp"||j.key==="ArrowLeft"||j.key==="ArrowRight")){if(j.preventDefault(),N===null){M(0);return}if(j.key==="ArrowDown"){let f=Math.min(w+1,I[d].length-1);M(k(d,f))}else if(j.key==="ArrowUp"){let f=Math.max(w-1,0);M(k(d,f))}else if(j.key==="ArrowRight"){let f=Math.min(d+1,I.length-1),$1=Math.min(w,I[f].length-1);M(k(f,$1))}else if(j.key==="ArrowLeft"){let f=Math.max(d-1,0),$1=Math.min(w,I[f].length-1);M(k(f,$1))}return}if(N!==null&&g.length>0){if(j.key==="Tab"){j.preventDefault(),u(g[N]);return}if(j.key==="Enter"&&!j.shiftKey){j.preventDefault(),G(g[N],U);return}}if(j.key==="Enter"&&!j.shiftKey){j.preventDefault(),E();return}if(j.key==="Escape")if(g.length>0&&!O)A(!0);else if(K)c();else z()},[g,N,w,d,I,k,u,G,U,E,O,K,c,z]);return z1(A7,{anchorEl:Q,scrollContainer:$,onClose:K?c:z,ignoreSelector:K?"[data-annotation-id]":void 0,zIndex:K?"60":"50",padding:K?"10px 12px":"12px",width:"420px",children:[!K&&(q??z1("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:["“",m,"”"]},void 0,!0,void 0,this)),z1(x0,{note:W,onNoteChange:T,images:U,onAddImage:(j)=>B((f)=>[...f,j]),onRemoveImage:(j)=>B((f)=>f.filter(($1)=>$1!==j)),sessionId:H,autoFocus:!0,autoResize:K,textareaRef:b,onKeyDown:a,attachButton:"none",openFilePickerRef:C,textareaStyle:K?{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"}:{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),z1("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginTop:K?"6px":"8px"},children:[z1(M2,{onClick:()=>C.current?.(),size:14},void 0,!1,void 0,this),z1("div",{style:{flex:1}},void 0,!1,void 0,this),K?z1("button",{onClick:()=>{if(_)_();z()},onMouseEnter:()=>y(!0),onMouseLeave:()=>y(!1),style:{fontSize:"11px",color:S?"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):z1(C7,{children:[z1("button",{onClick:z,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),z1("button",{onClick:E,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)]},void 0,!0,void 0,this),g.length>0&&z1("div",{style:{marginTop:"6px",borderTop:"1px solid var(--color-border-subtle)",paddingTop:"8px",display:"flex",gap:"4px"},children:D.map((j)=>z1("div",{style:{flex:1},children:[z1("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:j.label},void 0,!1,void 0,this),j.items.map((f)=>{let $1=g.indexOf(f);return z1("div",{onMouseDown:(K1)=>{K1.preventDefault(),K1.stopPropagation(),u(f)},onMouseEnter:()=>M($1),style:{padding:"3px 6px",fontSize:"12px",borderRadius:"4px",fontFamily:"'Inter', sans-serif",color:$1===N?"var(--color-text-primary)":"var(--color-text-secondary)",background:$1===N?"var(--color-highlight-selected)":"transparent",cursor:"pointer"},children:[z1("span",{style:{fontWeight:500},children:f.slice(0,W.trim().length)},void 0,!1,void 0,this),f.slice(W.trim().length)]},f,!0,void 0,this)})]},j.label,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function q0({anchorEl:Q,scrollContainer:$,snippet:Z,truncateAt:J,header:q,onAdd:Y,onCancel:X}){return z1(y5,{anchorEl:Q,scrollContainer:$,snippet:Z,truncateAt:J,header:q,onConfirm:(G,z)=>Y(G,z),onCancel:X},void 0,!1,void 0,this)}function J0({anchorEl:Q,scrollContainer:$,initialNote:Z,initialImages:J,onUpdate:q,onDelete:Y,onClose:X}){return z1(y5,{anchorEl:Q,scrollContainer:$,snippet:"",initialNote:Z,initialImages:J,onConfirm:(G,z)=>{q(G,z),X()},onDelete:Y,onCancel:X},void 0,!1,void 0,this)}import{useEffect as p0,useState as S5,useRef as i1,useCallback as b5}from"react";function l1(Q,$){let Z=[],J=I7(Q);for(let q of J){let Y=document.createRange();if(Y.selectNodeContents(q),q===Q.startContainer)Y.setStart(q,Q.startOffset);if(q===Q.endContainer)Y.setEnd(q,Q.endOffset);let X=Y.toString();if(!X||!X.trim())continue;let G=document.createElement("mark");G.setAttribute("data-annotation-id",$);try{Y.surroundContents(G)}catch{let z=Y.extractContents();G.appendChild(z),Y.insertNode(G)}Z.push(G)}return Z}function I7(Q){let $=[],Z=Q.commonAncestorContainer;if(Z.nodeType===Node.TEXT_NODE)return $.push(Z),$;let J=document.createTreeWalker(Z,NodeFilter.SHOW_TEXT),q;while(q=J.nextNode()){if(q.parentElement?.classList.contains("select-none"))continue;if(Q.intersectsNode(q))$.push(q)}return $}function r1(Q,$){let Z=document.querySelectorAll(`[data-annotation-id="${Q}"]`);for(let J of Z)J.classList.toggle("mark-active",$)}function g0(Q,$){if($!=null&&$!==Q)r1($,!1);if(Q!=null)r1(Q,!0)}function v0(Q,$){let Z=document.querySelectorAll(`[data-annotation-id="${Q}"]`);for(let J of Z)J.setAttribute("data-annotation-id",$)}function f0(Q,$){let Z=$.filter((G)=>!document.querySelector(`[data-annotation-id="${G.id}"]`));if(!Z.length)return;let J=[],q="",Y=document.createTreeWalker(Q,NodeFilter.SHOW_TEXT),X;while(X=Y.nextNode()){if(X.parentElement?.classList.contains("select-none"))continue;J.push({node:X,start:q.length}),q+=X.textContent||""}for(let G of Z){let z=G.snippet;if(!z)continue;let _=[],H=0;while(!0){let N=q.indexOf(z,H);if(N===-1)break;_.push(N),H=N+1}if(_.length===0)continue;let K=_[0];if(_.length>1&&G.context){let N=-1;for(let M of _){let O=0;if(G.context.before){let A=q.slice(Math.max(0,M-80),M);if(A.includes(G.context.before))O+=2;else if(G.context.before.length>10&&A.includes(G.context.before.slice(-10)))O+=1}if(G.context.after){let A=q.slice(M+z.length,M+z.length+80);if(A.includes(G.context.after))O+=2;else if(G.context.after.length>10&&A.includes(G.context.after.slice(0,10)))O+=1}if(O>N)N=O,K=M}}let W=K,T=K+z.length,U=P5(J,W),B=P5(J,T);if(!U||!B)continue;try{let N=document.createRange();N.setStart(U.node,U.offset),N.setEnd(B.node,B.offset),l1(N,G.id)}catch{}}}function P5(Q,$){for(let Z=Q.length-1;Z>=0;Z--)if(Q[Z].start<=$){let J=$-Q[Z].start,q=Q[Z].node.textContent?.length??0;if(J<=q)return{node:Q[Z].node,offset:J}}return null}function h0(Q){let $=document.querySelectorAll(`[data-annotation-id="${Q}"]`);for(let Z of $){let J=Z.parentNode;if(!J)continue;while(Z.firstChild)J.insertBefore(Z.firstChild,Z);J.removeChild(Z),J.normalize()}}import{jsxDEV as y2,Fragment as V7}from"react/jsx-dev-runtime";function a1(Q){let{containerRef:$,restoreKey:Z,restoreAnnotations:J,extractContext:q,filePath:Y,canvasFile:X,scrollContainer:G}=Q,{annotations:z,addAnnotationWithId:_,removeAnnotation:H,updateAnnotation:K,addAnnotationImage:W,removeAnnotationImage:T,activeAnnotationId:U,setActiveAnnotationId:B}=Y1(),[N,M]=S5(null),[O,A]=S5(null),S=i1(q);S.current=q;let y=i1(Y);y.current=Y;let b=i1(X);b.current=X;let C=i1(_);C.current=_;let E=i1(U);E.current=U;let c=i1(B);c.current=B,p0(()=>{if(!$.current)return;let D=setTimeout(()=>{if($.current)f0($.current,J)},50);return()=>clearTimeout(D)},[Z]);let h=i1(null);p0(()=>{g0(U,h.current),h.current=U},[U]),p0(()=>{let D=$.current;if(!D)return;let I=(w)=>{let k=w.target.closest("[data-annotation-id]");if(!k)return;w.stopPropagation();let L=k.getAttribute("data-annotation-id");if(L===E.current)M({anchorEl:k,annId:L});else c.current(L)},g=(w)=>{let k=w.target.closest("[data-annotation-id]");if(k)c.current(k.getAttribute("data-annotation-id"))},d=(w)=>{let k=w.target.closest("[data-annotation-id]"),L=w.relatedTarget?.closest?.("[data-annotation-id]");if(k&&!L&&!document.getElementById("ann-inline-popover"))c.current(null)};return D.addEventListener("click",I),D.addEventListener("mouseover",g),D.addEventListener("mouseout",d),()=>{D.removeEventListener("click",I),D.removeEventListener("mouseover",g),D.removeEventListener("mouseout",d)}},[Z]),p0(()=>{let D=()=>R();return document.addEventListener("mouseup",D),()=>document.removeEventListener("mouseup",D)},[]);let R=b5(()=>{let D=window.getSelection();if(!D||D.isCollapsed||!D.toString().trim())return;if(!$.current)return;let I=D.getRangeAt(0);if(!$.current.contains(I.startContainer))return;if(I.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let g=D.toString().trim();if(g.length<2)return;let d=S.current(I),w=I.cloneRange(),k=`__pending_${Date.now()}`;try{l1(w,k)}catch{}window.getSelection()?.removeAllRanges();let L=document.querySelectorAll(`[data-annotation-id="${k}"]`),l=L[L.length-1];if(!l)return;A({anchorEl:l,tempId:k,snippet:g,ctx:d})},[]),x=b5((D,I,g,d)=>{A({anchorEl:D,tempId:I,snippet:g,ctx:d})},[]);return{popovers:y2(V7,{children:[N&&(()=>{let D=z.find((I)=>I.id===N.annId);if(!D)return null;return y2(J0,{anchorEl:N.anchorEl,scrollContainer:G,initialNote:D.note,initialImages:D.images,onUpdate:(I,g)=>{K(N.annId,I);let d=D.images||[];for(let w of g)if(!d.includes(w))W(N.annId,w);for(let w of d)if(!g.includes(w))T(N.annId,w)},onDelete:()=>{H(N.annId),B(null)},onClose:()=>M(null)},void 0,!1,void 0,this)})(),O&&y2(q0,{anchorEl:O.anchorEl,scrollContainer:G,snippet:O.snippet,truncateAt:80,onAdd:(D,I)=>{let g=F1();v0(O.tempId,g),C.current(g,O.snippet,D,y.current,O.ctx,I,b.current),A(null)},onCancel:()=>{h0(O.tempId),A(null)}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),openCreatePopover:x,isPopoverOpen:!!(N||O)}}import{jsxDEV as q1,Fragment as v7}from"react/jsx-dev-runtime";var b2="[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']",S2="[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 B0({revision:Q,filename:$}){let Z=D7(E7),[J,q]=b1(null),[Y,X]=b1(null),[G,z]=b1(!0),_=R7(null),{annotations:H,addAnnotationWithId:K,removeAnnotation:W,updateAnnotation:T,addAnnotationImage:U,removeAnnotationImage:B,activeAnnotationId:N,setActiveAnnotationId:M}=Y1(),O=F0(()=>H.filter((w)=>!w.filePath&&(!w.canvasFile||w.canvasFile===$)),[H,$]),[A,S]=b1(null),[y,b]=b1(null),[C,E]=b1(null),[c,h]=b1(null),[R,x]=b1(!1);s1(()=>{z(!0),X(null),h(null),import(K5($,Q)).then((w)=>{q(()=>w.default),z(!1)}).catch((w)=>{X(w.message),z(!1)})},[Z,Q,$]);let v=document.getElementById("plan-scroll-container"),{popovers:D,isPopoverOpen:I}=a1({containerRef:_,restoreKey:J,restoreAnnotations:O,extractContext:(w)=>d1(w,_.current),canvasFile:$,scrollContainer:v}),g=F0(()=>{let w=new Map;for(let k of O)if(k.snippet.startsWith("["))w.set(k.snippet,k.id);return w},[O]);s1(()=>{let w=_.current;if(!w)return;let k=(l)=>{if(C||I)return;let u=l.target;if(u.closest("[data-block-comment-btn]"))return;x(!1);let m=u.closest(b2);if(m&&w.contains(m)){let f=o1(w).indexOf(m);h(f>=0?f:null)}else h(null);let a=u.closest(S2);if(a&&w.contains(a)){b(a);let j=Y0(a),f=j?g.get(j):void 0;if(f&&f!==N)M(f)}else b(null)},L=(l)=>{if(C||I)return;if(l.relatedTarget?.closest("[data-block-comment-btn]"))return;b(null),M(null)};return w.addEventListener("mousemove",k),w.addEventListener("mouseleave",L),()=>{w.removeEventListener("mousemove",k),w.removeEventListener("mouseleave",L)}},[J,C,I,g,N]),s1(()=>{let w=(k)=>{let L=k.target.tagName;if(L==="INPUT"||L==="TEXTAREA"||k.target.isContentEditable)return;if(C||I)return;let l=_.current;if(!l)return;if(k.key==="ArrowDown"){k.preventDefault(),x(!0);let u=o1(l);if(u.length===0)return;h((m)=>{if(m===null)return 0;return Math.min(m+1,u.length-1)})}else if(k.key==="ArrowUp"){k.preventDefault(),x(!0);let u=o1(l);if(u.length===0)return;h((m)=>{if(m===null)return u.length-1;return Math.max(m-1,0)})}else if(k.key==="a"||k.key==="A"){if(c===null||!l)return;k.preventDefault();let m=o1(l)[c];if(!m)return;let a=Y0(m);if(!a)return;let j=g.get(a);if(j)M(j),E({anchorEl:m,snippet:a,annId:j});else E({anchorEl:m,snippet:a})}else if(k.key===" "||k.key==="Enter"){if(c===null)return;let m=o1(l)[c];if(!m)return;let a=m.getAttribute("data-md");if(a==="choice-option"||a==="multichoice-option")k.preventDefault(),m.dispatchEvent(new CustomEvent("kb-select",{bubbles:!0}));else if(a==="userinput"){k.preventDefault();let j=m.querySelector("textarea");if(j){j.focus();let f=($1)=>{if($1.key==="Escape")$1.preventDefault(),j.blur(),x(!0)};j.addEventListener("keydown",f),j.addEventListener("blur",()=>j.removeEventListener("keydown",f),{once:!0})}}else if(a==="rangeinput"){k.preventDefault();let j=m.querySelector("input[type='range']");if(j){j.focus();let f=($1)=>{if($1.key==="Escape"||$1.key==="ArrowUp"||$1.key==="ArrowDown")$1.preventDefault(),j.blur(),x(!0)};j.addEventListener("keydown",f),j.addEventListener("blur",()=>j.removeEventListener("keydown",f),{once:!0})}}}else if(k.key==="Escape")h(null),x(!1),M(null)};return document.addEventListener("keydown",w),()=>document.removeEventListener("keydown",w)},[c,C,I,g]),s1(()=>{let w=_.current;if(!w||c===null||!R)return;let L=o1(w)[c];if(!L)return;L.style.outline="2px solid var(--color-accent-blue)",L.style.outlineOffset="-2px",L.style.borderRadius="8px",L.scrollIntoView({block:"nearest",behavior:"smooth"});let l=Y0(L),u=l?g.get(l):void 0;if(u)M(u);return()=>{L.style.outline="",L.style.outlineOffset="",L.style.borderRadius=""}},[c,R,g]);let d=F0(()=>J?q1(J,{},void 0,!1,void 0,this):null,[J]);if(G)return q1("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-body",children:"Loading canvas..."},void 0,!1,void 0,this);if(Y)return q1("div",{className:"bg-accent-red-muted rounded-lg p-5",children:[q1("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Compilation Error"},void 0,!1,void 0,this),q1("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(!J)return q1("div",{className:"text-text-tertiary text-center py-8 font-body text-body",children:"No canvas loaded"},void 0,!1,void 0,this);return q1(x7.Provider,{value:$,children:[q1("div",{ref:_,className:"plan-content plan-updated",children:d},void 0,!1,void 0,this),A&&q1(g7,{note:A.note,onSave:(w)=>{T(A.id,w),S(null)},onCancel:()=>S(null)},void 0,!1,void 0,this),D,q1(m7,{containerRef:_,hoveredBlock:y,focusedBlockIndex:c,blockPopover:C,blockAnnotationMap:g,activeAnnotationId:N,onOpen:(w,k,L)=>{if(L)M(L),E({anchorEl:w,snippet:k,annId:L});else E({anchorEl:w,snippet:k})}},void 0,!1,void 0,this),C&&!C.annId&&q1(q0,{anchorEl:C.anchorEl,scrollContainer:v,snippet:C.snippet,truncateAt:80,onAdd:(w,k)=>{let L=F1();K(L,C.snippet,w,void 0,void 0,k,$),E(null)},onCancel:()=>E(null)},void 0,!1,void 0,this),C?.annId&&(()=>{let w=O.find((k)=>k.id===C.annId);if(!w)return null;return q1(J0,{anchorEl:C.anchorEl,scrollContainer:v,initialNote:w.note,initialImages:w.images,onUpdate:(k,L)=>{T(C.annId,k);let l=w.images||[];for(let u of L)if(!l.includes(u))U(C.annId,u);for(let u of l)if(!L.includes(u))B(C.annId,u)},onDelete:()=>{W(C.annId),M(null),E(null)},onClose:()=>E(null)},void 0,!1,void 0,this)})()]},void 0,!0,void 0,this)}function o1(Q){return Array.from(Q.querySelectorAll(b2))}function Y0(Q){let $=Q.getAttribute("data-md");if($==="item"){let Z=Q.getAttribute("data-md-label");return Z?`[Item] ${Z}`:null}if($==="section"){let Z=Q.getAttribute("data-md-title");return Z?`[Section] ${Z}`:null}if($==="callout"){let Z=Q.getAttribute("data-md-type")||"info",J=Q.textContent?.trim().slice(0,60)||"Callout";return`[Callout:${Z}] ${J}`}if($==="note")return`[Note] ${Q.textContent?.trim().slice(0,60)||"Note"}`;if(Q.tagName==="TR"){let Z=Array.from(Q.querySelectorAll("td")).map((J)=>J.textContent?.trim()).filter(Boolean);return Z.length?`[Row] ${Z.join(" | ")}`:null}if($==="checklist-item"){let Z=Q.getAttribute("data-md-label");return Z?`[Checklist] ${Z}`:null}if($==="choice-option"||$==="multichoice-option"){let Z=Q.getAttribute("data-md-label");return Z?`[Option] ${Z}`:null}if($==="userinput"){let Z=Q.getAttribute("data-md-label");return Z?`[Input] ${Z}`:null}if($==="rangeinput"){let Z=Q.getAttribute("data-md-label");return Z?`[Range] ${Z}`:null}if($==="image"){let Z=Q.getAttribute("data-md-src");return Z?`[Image] ${Z}`:null}return null}function m7({containerRef:Q,hoveredBlock:$,focusedBlockIndex:Z,blockPopover:J,blockAnnotationMap:q,activeAnnotationId:Y,onOpen:X}){let[G,z]=b1([]);s1(()=>{let T=Q.current;if(!T||q.size===0){z([]);return}let U=[];for(let B of T.querySelectorAll(S2)){let N=Y0(B);if(N&&q.has(N))U.push(B)}z(U)},[q,Q.current]);let[_,H]=b1(null);s1(()=>{if(!Y||!Q.current){H(null);return}for(let T of Q.current.querySelectorAll(b2)){let U=Y0(T);if(U&&q.get(U)===Y){H(T);return}}H(null)},[Y,q]),s1(()=>{if(!_)return;return _.style.boxShadow="inset 0 0 0 1.5px var(--color-highlight-bg)",_.style.borderRadius="8px",()=>{_.style.boxShadow="",_.style.borderRadius=""}},[_]);let K=F0(()=>{if(Z===null||!Q.current)return null;let T=o1(Q.current)[Z];if(!T)return null;return T.matches(S2)?T:null},[Z,Q.current]),W=F0(()=>{let T=new Set(G);if($)T.add($);if(K)T.add(K);if(J?.anchorEl)T.add(J.anchorEl);return Array.from(T)},[G,$,K,J]);return q1(v7,{children:W.map((T)=>q1(u7,{block:T,isHovered:T===$||T===K||T===J?.anchorEl,blockAnnotationMap:q,activeAnnotationId:Y,onOpen:X},T.getAttribute("data-task-id")||T.getAttribute("data-md-title")||T.textContent?.slice(0,30)||"block",!1,void 0,this))},void 0,!1,void 0,this)}function u7({block:Q,isHovered:$,blockAnnotationMap:Z,activeAnnotationId:J,onOpen:q}){let Y=Y0(Q);if(!Y)return null;let X=Z.get(Y),G=!!X;return k7(q1("button",{"data-block-comment-btn":!0,onClick:(_)=>{_.stopPropagation(),q(_.currentTarget,Y,X)},className:`absolute top-1 right-1 z-10 w-6 h-6 flex items-center justify-center rounded transition-all duration-150 ${G?X===J?"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:G?"Edit annotation":"Add annotation",children:q1("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:G?"currentColor":"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:q1("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),Q)}function g7({note:Q,onSave:$,onCancel:Z}){let[J,q]=P2.useState(Q),Y=P2.useRef(null);return P2.useEffect(()=>{Y.current?.focus(),Y.current?.select()},[]),q1("div",{className:"fixed inset-0 z-50 bg-black/40 flex items-center justify-center",onClick:Z,children:q1("div",{className:"bg-bg-elevated border border-border-hover rounded-lg shadow-md p-4 w-80",onClick:(X)=>X.stopPropagation(),children:[q1("div",{className:"text-tiny uppercase tracking-widest text-text-tertiary font-body mb-2",children:"Edit annotation"},void 0,!1,void 0,this),q1("textarea",{ref:Y,value:J,onChange:(X)=>q(X.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:(X)=>{if(X.key==="Enter"&&(X.ctrlKey||X.metaKey))$(J.trim());if(X.key==="Escape")Z()}},void 0,!1,void 0,this),q1("div",{className:"flex justify-end gap-2 mt-2",children:[q1("button",{onClick:Z,className:"text-meta text-text-tertiary font-body px-3 py-1",children:"Cancel"},void 0,!1,void 0,this),q1("button",{onClick:()=>$(J.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 s7,{useRef as I5,useEffect as l0,useCallback as I2,useState as E1,useContext as i0,useMemo as t7}from"react";function L0(Q,$,Z,J,q){let Y=[],X=Q.filter((T)=>T.source!=="remote"||q&&q.has(T.id)),G=X.filter((T)=>T.filePath===T1),z=X.filter((T)=>!T.filePath),_=X.filter((T)=>T.filePath&&T.filePath!==T1),H=Z?Array.from(Z.values()).filter((T)=>j2(T)):[],K=J?Array.from(J.values()).filter((T)=>T.markdown.trim()):[];if(H.length>0||K.length>0){Y.push("## Responses"),Y.push("");for(let T of H)Y.push(p7(T));for(let T of K)Y.push(T.markdown.trim()),Y.push("")}if(G.length>0){Y.push("## Annotations on agent response"),Y.push("");for(let T of G)Y.push(w2(T))}if(z.length>0){Y.push("## Canvas annotations"),Y.push("");let T=new Map;for(let N of z){let M=N.canvasFile||"";if(!T.has(M))T.set(M,[]);T.get(M).push(N)}let U=[...T.keys()].sort(),B=U.length>1||U.length===1&&U[0]!=="";for(let N of U){let M=T.get(N);if(B&&N)Y.push(`### ${N.replace(/\.jsx$/,"")}`),Y.push("");let O=c7(M);Y.push(w5(O))}}if(_.length>0){let T={};for(let U of _){let B=U.filePath;if(!T[B])T[B]=[];T[B].push(U)}Y.push("## File annotations"),Y.push("");for(let[U,B]of Object.entries(T)){Y.push(`### ${U}`),Y.push("");for(let N of B)Y.push(w2(N))}}if($.trim())Y.push("## General notes"),Y.push(""),Y.push($.trim()),Y.push("");return Y.join(`
|
|
60
60
|
`).trim()+`
|
|
61
61
|
`}function j2(Q){if(Q.note?.trim())return!0;if(Q.value===null||Q.value===void 0)return!1;if(Q.type==="text"&&!Q.value.trim())return!1;if(Q.type==="checkbox"&&Q.value.length===0)return!1;return!0}function f7(Q){let $=[];for(let Z of Q.values()){if(!Z.required)continue;if(Z.value===null||Z.value===void 0){$.push(Z);continue}if(Z.type==="text"&&!Z.value.trim()){$.push(Z);continue}if(Z.type==="checkbox"&&Z.value.length===0){$.push(Z);continue}}return $}function h7(Q){let $=[];for(let Z of Q.values())if(Z.required&&!Z.markdown.trim())$.push(Z);return $}function c0(Q,$){let Z=f7(Q),J=h7($);return[...Z.map((q)=>q.label),...J.map((q)=>q.label||q.id)]}function p7(Q){let $=[];switch($.push(`**${Q.label}**`),Q.type){case"radio":case"select":$.push(`Answer: ${Q.value}`);break;case"checkbox":for(let Z of Q.value)$.push(`- [x] ${Z}`);break;case"text":$.push(""),$.push(Q.value.trim());break;case"range":$.push(`Answer: ${Q.value}`);break}if(Q.note?.trim())$.push(""),$.push(`Note: ${Q.note.trim()}`);return $.push(""),$.join(`
|
|
62
|
-
`)}function w2(Q){let $=[],Z=Q.snippet.trim(),J=Q.context,q=J?.lineStart!=null;if(Q.filePath&&q){let
|
|
63
|
-
`);if(Z.length<30&&X
|
|
64
|
-
`).length<=3)$.push(`> ${
|
|
62
|
+
`)}function w2(Q){let $=[],Z=Q.snippet.trim(),J=Q.context,q=J?.lineStart!=null;if(Q.filePath&&q){let Y=J.lineStart,X=J.lineEnd??Y,G=Z.split(`
|
|
63
|
+
`);if(Z.length<30&&Y===X&&(J.before||J.after)){let _=O2(Q);$.push(`> L${Y}: ${_}`)}else if(G.length<=6)for(let _=0;_<G.length;_++)$.push(`> ${Y+_} | ${G[_]}`);else{for(let _=0;_<3;_++)$.push(`> ${Y+_} | ${G[_]}`);$.push(`> ... (${G.length} lines)`);for(let _=G.length-3;_<G.length;_++)$.push(`> ${Y+_} | ${G[_]}`)}}else{let Y=O2(Q);if(Z.split(`
|
|
64
|
+
`).length<=3)$.push(`> ${Y.split(`
|
|
65
65
|
`).join(`
|
|
66
|
-
> `)}`);else{let
|
|
67
|
-
`);$.push(`> ${
|
|
68
|
-
`)}function c7(Q){let $={label:"",annotations:[],children:new Map};for(let Z of Q){let J=Z.context?.hierarchy||[],q=$;for(let
|
|
69
|
-
`)}import{SessionContext as V5}from"#canvas/runtime";import{useEffect as b5,useState as M0,useRef as d7,useMemo as w5}from"react";import{jsxDEV as J1}from"react/jsx-dev-runtime";function j5({open:Q,onClose:$,onSubmit:Z}){let{annotations:J,generalNote:q,responses:X,feedbackEntries:Y}=Y1(),[G,z]=M0(""),[_,W]=M0(!1),[K,H]=M0(!1),[T,U]=M0(null),L=d7(null),[N,P]=M0(!1);if(Q&&!N)W(!1),H(!1),U(null);if(!Q&&N)W(!1),H(!1),U(null);if(Q!==N)P(Q);let O=w5(()=>L0(J,q,X,Y),[J,q,X,Y]),w=_?G:O;if(b5(()=>{if(Q&&K&&L.current)L.current.focus()},[Q,K]),b5(()=>{if(!Q)return;let M=(b)=>{if(b.key==="Escape")$()};return window.addEventListener("keydown",M),()=>window.removeEventListener("keydown",M)},[Q,$]),!Q)return null;let S=w.trim().length>0;return J1("div",{className:"fixed inset-0 z-50 bg-black/50 backdrop-blur-sm flex items-center justify-center p-8",onClick:$,children:J1("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:(M)=>M.stopPropagation(),children:[J1("div",{className:"flex items-center justify-between px-5 py-3 border-b border-border-subtle flex-shrink-0",children:[J1("div",{className:"flex items-center gap-3",children:[J1("span",{className:"text-[13px] font-medium text-text-primary font-body",children:"Response preview"},void 0,!1,void 0,this),_&&J1("button",{onClick:()=>{W(!1),H(!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),J1("div",{className:"flex items-center gap-2",children:[J1("div",{className:"flex items-center bg-bg-base rounded-md p-0.5",children:[J1("button",{onClick:()=>H(!1),className:`px-2.5 py-1 rounded text-[11px] font-body font-medium transition-colors ${!K?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Preview"},void 0,!1,void 0,this),J1("button",{onClick:()=>H(!0),className:`px-2.5 py-1 rounded text-[11px] font-body font-medium transition-colors ${K?"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),J1("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),K?J1("textarea",{ref:L,value:w,onChange:(M)=>{z(M.target.value),W(!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):J1("div",{className:"flex-1 overflow-y-auto p-5",children:J1(d0,{text:w},void 0,!1,void 0,this)},void 0,!1,void 0,this),T&&J1("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:[J1("span",{children:T},void 0,!1,void 0,this),J1("button",{onClick:()=>{U(null),Z(w)},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),J1("div",{className:"flex justify-end gap-2 px-5 py-3 border-t border-border-subtle flex-shrink-0",children:[J1("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),J1("button",{onClick:()=>{let M=c0(X,Y);if(M.length>0){U(`Please answer: ${M.join(", ")}`);return}U(null),Z(w)},disabled:!S,className:`px-6 py-2 rounded-lg font-body text-[13px] font-medium transition-all ${S?"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)}var r7=/!\[([^\]]*)\]\((\/tmp\/agent-canvas\/uploads\/([^)]+))\)/g;function l7(Q){return Q.replace(r7,($,Z,J,q)=>``)}function d0({text:Q}){let $=w5(()=>s.parse(l7(Q),{async:!1}),[Q]);return J1("div",{className:"prose-canvas font-body text-body text-text-primary leading-relaxed",dangerouslySetInnerHTML:{__html:$}},void 0,!1,void 0,this)}import{jsxDEV as s1}from"react/jsx-dev-runtime";var i7={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"},a7={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 k1({name:Q,type:$,expanded:Z,className:J=""}){if($==="dir")return s1("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",className:`flex-shrink-0 ${J}`,children:Z?s1("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):s1("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 q=Q.includes(".")?Q.split(".").pop().toLowerCase():"",X=i7[q]||"#6b6560",Y=a7[q];return s1("svg",{width:"14",height:"14",viewBox:"0 0 16 16",className:`flex-shrink-0 ${J}`,children:[s1("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),s1("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),Y&&s1("text",{x:"8",y:"11.5",textAnchor:"middle",fill:"white",fontSize:"5.5",fontFamily:"monospace",fontWeight:"600",children:Y},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function o7(Q){let $=Q.getAttribute("data-md");if($==="item"){let Z=Q.getAttribute("data-md-label");return Z?`[Item] ${Z}`:null}if($==="section"){let Z=Q.getAttribute("data-md-title");return Z?`[Section] ${Z}`:null}if($==="callout"){let Z=Q.getAttribute("data-md-type")||"info",J=Q.textContent?.trim().slice(0,60)||"Callout";return`[Callout:${Z}] ${J}`}if($==="note")return`[Note] ${Q.textContent?.trim().slice(0,60)||"Note"}`;if(Q.tagName==="TR"){let Z=Array.from(Q.querySelectorAll("td")).map((J)=>J.textContent?.trim()).filter(Boolean);return Z.length?`[Row] ${Z.join(" | ")}`:null}if($==="checklist-item"){let Z=Q.getAttribute("data-md-label");return Z?`[Checklist] ${Z}`:null}if($==="choice-option"||$==="multichoice-option"){let Z=Q.getAttribute("data-md-label");return Z?`[Option] ${Z}`:null}if($==="userinput"){let Z=Q.getAttribute("data-md-label");return Z?`[Input] ${Z}`:null}if($==="rangeinput"){let Z=Q.getAttribute("data-md-label");return Z?`[Range] ${Z}`:null}if($==="image"){let Z=Q.getAttribute("data-md-src");return Z?`[Image] ${Z}`:null}return null}function y0(Q){let $=document.querySelector(`[data-annotation-id="${Q.id}"]`);if($)return $;if(Q.snippet.startsWith("[")){for(let Z of document.querySelectorAll("[data-md='item'], [data-md='section'], [data-md='table'] tbody tr, [data-md='callout'], [data-md='note'], [data-md='checklist-item'], [data-md='image']"))if(o7(Z)===Q.snippet)return Z}return null}function A5(Q){Q.classList.remove("ann-flash"),Q.offsetWidth,Q.classList.add("ann-flash"),Q.addEventListener("animationend",()=>{Q.classList.remove("ann-flash")},{once:!0})}function A2(Q,$){if(Q.filePath)$({type:"file",path:Q.filePath}),setTimeout(()=>{let Z=y0(Q);if(Z)Z.scrollIntoView({behavior:"smooth",block:"center"}),A5(Z)},150);else{let Z=y0(Q);if(Z)Z.scrollIntoView({behavior:"smooth",block:"center"}),A5(Z)}}import{jsxDEV as y,Fragment as r0}from"react/jsx-dev-runtime";function I2({onPreview:Q,onSubmit:$,collapseButton:Z}){let{isReadOnly:J,selectedRevision:q,currentRevision:X,revisions:Y,agentWatching:G}=l0(w1),z=l0(V5),_=Y.find((T)=>T.revision===q),W=J&&q===X,K=!!_?.feedbackConsumed,H=_?.label||`Round ${q}`;if(J)return y(n7,{sessionId:z,revision:q,label:H,waitingForUpdate:W,feedbackConsumed:K,agentWatching:G,collapseButton:Z},void 0,!1,void 0,this);return y(Q8,{onPreview:Q,onSubmit:$,agentWatching:G,collapseButton:Z},void 0,!1,void 0,this)}function t7({sessionId:Q,revision:$,label:Z,waitingForUpdate:J,feedbackConsumed:q,agentWatching:X,collapseButton:Y}){let G=Z1.isShared,[z,_]=Y0(null),[W,K]=Y0(!0);return C2(()=>{if(K(!0),!B1){_(null),K(!1);return}fetch(`/api/session/${Q}/revision/${$}/feedback`).then((H)=>H.json()).then((H)=>{_(H.feedback||null),K(!1)}).catch(()=>{_(null),K(!1)})},[Q,$]),y("div",{className:"flex flex-col h-full",children:[y("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[y("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:J?"Feedback sent":`Feedback — ${Z}`},void 0,!1,void 0,this),Y]},void 0,!0,void 0,this),J&&!G&&y(R5,{feedbackConsumed:q,agentWatching:X},void 0,!1,void 0,this),y("div",{className:"flex-1 overflow-y-auto px-4",children:W?y("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"Loading..."},void 0,!1,void 0,this):z?y(d0,{text:z},void 0,!1,void 0,this):y("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 R5({feedbackConsumed:Q,agentWatching:$}){if(Q)return y("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:[y("span",{className:"w-2 h-2 rounded-full bg-accent-green animate-pulse"},void 0,!1,void 0,this),y("span",{className:"text-[12px] font-body text-accent-green",children:"Feedback received — waiting for next revision..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if($)return y("div",{className:"mx-4 mb-3 px-3 py-2.5 rounded-lg bg-accent-blue-muted flex items-center gap-2 flex-shrink-0",children:[y("span",{className:"w-2 h-2 rounded-full bg-accent-blue animate-pulse"},void 0,!1,void 0,this),y("span",{className:"text-[12px] font-body text-accent-blue",children:"Waiting for agent to pick up feedback..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return y("div",{className:"mx-4 mb-3 px-3 py-2.5 rounded-lg bg-accent-amber-muted flex items-center gap-2 flex-shrink-0",children:[y("span",{className:"w-2 h-2 rounded-full bg-accent-amber"},void 0,!1,void 0,this),y("span",{className:"text-[12px] font-body text-accent-amber",children:"Agent disconnected — tell Claude to check feedback"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function n7({sessionId:Q,revision:$,label:Z,waitingForUpdate:J,feedbackConsumed:q,agentWatching:X,collapseButton:Y}){let{annotations:G,generalNote:z,activeAnnotationId:_,setActiveAnnotationId:W}=Y1(),{setActiveView:K}=l0(I1),H=G.length>0||z.trim().length>0,[T,U]=Y0("feedback");if(!H)return y(t7,{sessionId:Q,revision:$,label:Z,waitingForUpdate:J,feedbackConsumed:q,agentWatching:X,collapseButton:Y},void 0,!1,void 0,this);return y("div",{className:"flex flex-col h-full",children:[y("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[y("div",{className:"flex items-center gap-1 bg-bg-input rounded-md p-0.5",children:[y("button",{onClick:()=>U("feedback"),className:`px-2.5 py-1 rounded text-[11px] font-medium font-body transition-colors ${T==="feedback"?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Feedback"},void 0,!1,void 0,this),y("button",{onClick:()=>U("annotations"),className:`px-2.5 py-1 rounded text-[11px] font-medium font-body transition-colors flex items-center gap-1.5 ${T==="annotations"?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:["Annotations",y("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:G.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),J&&y(R5,{feedbackConsumed:q,agentWatching:X},void 0,!1,void 0,this),T==="feedback"?y(e7,{sessionId:Q,revision:$},void 0,!1,void 0,this):y($8,{annotations:G,generalNote:z,activeAnnotationId:_,setActiveAnnotationId:W,setActiveView:K},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function e7({sessionId:Q,revision:$}){let[Z,J]=Y0(null),[q,X]=Y0(!0);return C2(()=>{if(X(!0),!B1){J(null),X(!1);return}fetch(`/api/session/${Q}/revision/${$}/feedback`).then((Y)=>Y.json()).then((Y)=>{J(Y.feedback||null),X(!1)}).catch(()=>{J(null),X(!1)})},[Q,$]),y("div",{className:"flex-1 overflow-y-auto px-4",children:q?y("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"Loading..."},void 0,!1,void 0,this):Z?y(d0,{text:Z},void 0,!1,void 0,this):y("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 $8({annotations:Q,generalNote:$,activeAnnotationId:Z,setActiveAnnotationId:J,setActiveView:q}){let X=Q.filter((U)=>U.filePath===T1),Y=Q.filter((U)=>!U.filePath),G=Q.filter((U)=>U.filePath&&U.filePath!==T1),z={};for(let U of G){let L=U.filePath;if(!z[L])z[L]=[];z[L].push(U)}let _=(U)=>{J(U),d1(U,!0)},W=(U)=>{J(null),d1(U,!1)},K=(U)=>{if(U.id===Z)J(null);else if(J(U.id),U.filePath)q({type:"file",path:U.filePath}),setTimeout(()=>{let L=y0(U);if(L)L.scrollIntoView({behavior:"smooth",block:"center"})},150)},H=(U)=>y("div",{className:`group/ann relative px-3 py-2.5 transition-colors duration-150 cursor-pointer ${Z===U.id?"bg-highlight-selected":"odd:bg-bg-elevated-half hover:bg-bg-input"}`,onMouseEnter:()=>_(U.id),onMouseLeave:()=>W(U.id),onClick:()=>K(U),children:[y("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:U.snippet.length>80?U.snippet.slice(0,80)+"...":U.snippet},void 0,!1,void 0,this),U.note.trim()&&y("div",{className:"text-[13px] font-body text-text-primary leading-relaxed",children:U.note},void 0,!1,void 0,this),y(N5,{images:U.images||[]},void 0,!1,void 0,this),y("div",{className:"absolute top-1.5 right-1.5 opacity-0 group-hover/ann:opacity-100 transition-opacity duration-100",children:y("button",{onClick:(L)=>{L.stopPropagation(),A2(U,q)},className:"w-5 h-5 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-input transition-colors",title:"Scroll to annotation",children:y("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[y("circle",{cx:"12",cy:"12",r:"3"},void 0,!1,void 0,this),y("path",{d:"M12 2v4M12 18v4M2 12h4M18 12h4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},U.id,!0,void 0,this),T=[X,Y,G].filter((U)=>U.length>0).length>1;return y(r0,{children:[y("div",{className:"flex-1 overflow-y-auto",children:[X.length>0&&y(r0,{children:[T&&y("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body px-3 mb-1 mt-1",children:"Agent Response"},void 0,!1,void 0,this),X.map(H)]},void 0,!0,void 0,this),Y.length>0&&y(r0,{children:[T&&y("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body px-3 mb-1 mt-1",children:"Canvas"},void 0,!1,void 0,this),Y.map(H)]},void 0,!0,void 0,this),Object.entries(z).map(([U,L])=>y("div",{children:[y("button",{onClick:()=>q({type:"file",path:U}),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:U,children:[y(k1,{name:U.split("/").pop()||U,type:"file"},void 0,!1,void 0,this),y("span",{className:"truncate",children:U},void 0,!1,void 0,this)]},void 0,!0,void 0,this),L.map(H)]},U,!0,void 0,this))]},void 0,!0,void 0,this),$.trim()&&y("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:y("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 Q8({onPreview:Q,onSubmit:$,agentWatching:Z,collapseButton:J}){let{annotations:q,updateAnnotation:X,removeAnnotation:Y,addAnnotationImage:G,removeAnnotationImage:z,generalNote:_,setGeneralNote:W,activeAnnotationId:K,setActiveAnnotationId:H,responses:T,feedbackEntries:U}=Y1(),L=l0(V5),{setActiveView:N}=s7.useContext(I1),P=C5(null),O=C5(new Map),w=q.filter((B)=>B.filePath===T1),S=q.filter((B)=>!B.filePath),M=q.filter((B)=>B.filePath&&B.filePath!==T1),b={};for(let B of M){let D=B.filePath;if(!b[D])b[D]=[];b[D].push(B)}C2(()=>{if(!K)return;let B=O.current.get(K);if(B)B.scrollIntoView({behavior:"smooth",block:"nearest"})},[K]);let V=I5((B)=>{H(B),d1(B,!0)},[H]),v=I5((B)=>{H(null),d1(B,!1)},[K]),p=Array.from(T.values()).some(j2),f=U.size>0,R=q.length>0||_.trim().length>0||p||f,[k,u]=Y0(null),I=(B)=>{let D=B.source==="remote";return y("div",{ref:(x)=>{if(x)O.current.set(B.id,x);else O.current.delete(B.id)},className:`group/ann relative px-3 py-2.5 transition-colors duration-150 ${K===B.id?"bg-highlight-selected":D?"bg-accent-purple-muted/30 hover:bg-accent-purple-muted/50":"odd:bg-bg-elevated-half hover:bg-bg-input"}`,onMouseEnter:()=>V(B.id),onMouseLeave:()=>v(B.id),onClick:()=>{if(B.id===K)H(null);else if(H(B.id),B.filePath)N({type:"file",path:B.filePath}),setTimeout(()=>{let x=y0(B);if(x)x.scrollIntoView({behavior:"smooth",block:"center"})},150)},children:[D&&B.author&&y("div",{className:"flex items-center gap-1.5 mb-1.5",children:[y("span",{className:"inline-flex items-center justify-center w-4 h-4 rounded-full bg-accent-purple text-white text-[9px] font-medium uppercase",children:B.author.name.charAt(0)},void 0,!1,void 0,this),y("span",{className:"text-[11px] font-medium text-accent-purple font-body",children:B.author.name},void 0,!1,void 0,this),y("span",{className:"text-[10px] text-text-tertiary font-body uppercase tracking-widest",children:"Remote"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),y("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:B.snippet.length>80?B.snippet.slice(0,80)+"...":B.snippet},void 0,!1,void 0,this),D?y("div",{className:"text-[13px] font-body text-text-primary leading-relaxed whitespace-pre-wrap",children:B.note},void 0,!1,void 0,this):y("div",{onClick:(x)=>x.stopPropagation(),children:y(m0,{note:B.note,onNoteChange:(x)=>X(B.id,x),images:B.images||[],onAddImage:(x)=>G(B.id,x),onRemoveImage:(x)=>z(B.id,x),sessionId:L,autoResize:!0,minHeight:20,textareaClassName:"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]",textareaStyle:{height:"auto",overflow:"hidden"},placeholder:"Add your note...",attachButton:"on-focus"},void 0,!1,void 0,this)},void 0,!1,void 0,this),y("div",{className:"absolute top-1.5 right-1.5 opacity-0 group-hover/ann:opacity-100 transition-opacity duration-100 flex items-center gap-0.5",children:[y("button",{onClick:(x)=>{x.stopPropagation(),A2(B,N)},className:"w-5 h-5 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-input transition-colors",title:"Scroll to annotation",children:y("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[y("circle",{cx:"12",cy:"12",r:"3"},void 0,!1,void 0,this),y("path",{d:"M12 2v4M12 18v4M2 12h4M18 12h4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),!D&&y("button",{onClick:(x)=>{x.stopPropagation(),Y(B.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:y("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[y("polyline",{points:"3 6 5 6 21 6"},void 0,!1,void 0,this),y("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,!0,void 0,this)]},B.id,!0,void 0,this)};return y("div",{className:"flex flex-col h-full",children:[y("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[y("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body flex items-center gap-2",children:["Annotations",q.length>0&&y("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:q.length},void 0,!1,void 0,this),!Z1.isShared&&y("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${Z?"bg-accent-green":"bg-accent-amber"}`,title:Z?"Agent connected":"Agent disconnected"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),J]},void 0,!0,void 0,this),y("div",{ref:P,className:"flex-1 overflow-y-auto",children:[q.length===0&&y("p",{className:"text-[12px] text-text-tertiary px-3 py-4 leading-relaxed font-body",children:"Select text in the canvas or in files to add annotations."},void 0,!1,void 0,this),w.length>0&&y(r0,{children:[(S.length>0||M.length>0)&&y("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body px-3 mb-1 mt-1",children:"Agent Response"},void 0,!1,void 0,this),w.map(I)]},void 0,!0,void 0,this),S.length>0&&(w.length>0||M.length>0)&&y("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body px-3 mb-1 mt-1",children:"Canvas"},void 0,!1,void 0,this),S.map(I),Object.entries(b).map(([B,D])=>y("div",{children:[y("button",{onClick:()=>N({type:"file",path:B}),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:B,children:[y(k1,{name:B.split("/").pop()||B,type:"file"},void 0,!1,void 0,this),y("span",{className:"truncate",children:B},void 0,!1,void 0,this)]},void 0,!0,void 0,this),D.map(I)]},B,!0,void 0,this))]},void 0,!0,void 0,this),y("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:y("textarea",{value:_,onChange:(B)=>W(B.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:(B)=>N0(B.target,40),ref:(B)=>{if(B)N0(B,40)}},void 0,!1,void 0,this)},void 0,!1,void 0,this),k&&y("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:[y("span",{children:k},void 0,!1,void 0,this),y("button",{onClick:()=>{u(null);let B=L0(q,_,T,U);$(B)},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),y("div",{className:"px-4 py-3 border-t border-border-subtle flex-shrink-0",children:R?y("div",{className:"flex gap-2",children:[y("button",{onClick:Q,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),y("button",{onClick:()=>{let B=c0(T,U);if(B.length>0){u(`Please answer: ${B.join(", ")}`);return}u(null);let D=L0(q,_,T,U);$(D)},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):y("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 Z8,useState as D5,useContext as k5,useMemo as q8}from"react";import{SessionContext as J8}from"#canvas/runtime";import{jsxDEV as r,Fragment as V2}from"react/jsx-dev-runtime";function E5({embedded:Q}={}){let $=k5(J8),{annotations:Z,addAnnotation:J}=Y1(),{setActiveView:q}=k5(I1),[X,Y]=D5(!1),[G,z]=D5({});if(!B1)return r("div",{className:Q?"px-4 py-3":"p-4",children:[r("div",{className:"text-[11px] uppercase tracking-widest text-text-tertiary font-body mb-2",children:"Files"},void 0,!1,void 0,this),r("p",{className:"text-[11px] text-text-tertiary font-body leading-relaxed",children:"File browsing is not available in shared view. File previews embedded in the canvas still work."},void 0,!1,void 0,this)]},void 0,!0,void 0,this);let{annCountMap:_,annotatedFiles:W}=q8(()=>{let O=new Map;for(let w of Z)if(w.filePath&&w.filePath!==T1)O.set(w.filePath,(O.get(w.filePath)||0)+1);return{annCountMap:O,annotatedFiles:[...O.keys()]}},[Z]),K=async(O)=>{let S=await(await fetch(`/api/tree?session=${$}&path=${encodeURIComponent(O)}`)).json();if(S.entries)z((M)=>({...M,[O]:{entries:S.entries,expanded:!0,loaded:!0}}))};Z8(()=>{if(!X&&!G[""])K("")},[X]);let H=(O)=>{if(G[O]?.loaded)z((w)=>({...w,[O]:{...w[O],expanded:!w[O].expanded}}));else K(O)},T=(O)=>{q({type:"file",path:O})},U=async(O)=>{let S=await(await fetch(`/api/file?session=${$}&path=${encodeURIComponent(O)}`)).json();if(!S.error){let M=S.content.split(`
|
|
66
|
+
> `)}`);else{let X=Z.split(`
|
|
67
|
+
`);$.push(`> ${X[0]}`),$.push(`> ... (${X.length} lines)`),$.push(`> ${X[X.length-1]}`)}}if(Q.note.trim())$.push(""),$.push(Q.note.trim());if(Q.images?.length){$.push("");for(let Y of Q.images)$.push(``)}return $.push(""),$.join(`
|
|
68
|
+
`)}function c7(Q){let $={label:"",annotations:[],children:new Map};for(let Z of Q){let J=Z.context?.hierarchy||[],q=$;for(let Y of J){if(!q.children.has(Y))q.children.set(Y,{label:Y,annotations:[],children:new Map});q=q.children.get(Y)}q.annotations.push(Z)}return $}function w5(Q,$=0){let Z=[];for(let J of Q.annotations)Z.push(w2(J));for(let[,J]of Q.children){let q=$===0?"###":"####";Z.push(`${q} ${J.label}`),Z.push(""),Z.push(w5(J,$+1))}return Z.join(`
|
|
69
|
+
`)}import{SessionContext as V5}from"#canvas/runtime";import{useEffect as j5,useState as M0,useRef as d7,useMemo as A2}from"react";import{jsxDEV as J1}from"react/jsx-dev-runtime";function A5({open:Q,onClose:$,onSubmit:Z,includedRemoteIds:J,onToggleRemoteId:q}){let{annotations:Y,generalNote:X,responses:G,feedbackEntries:z}=Y1(),[_,H]=M0(""),[K,W]=M0(!1),[T,U]=M0(!1),[B,N]=M0(null),M=d7(null),[O,A]=M0(!1),S=A2(()=>Y.filter((E)=>E.source==="remote"),[Y]);if(Q&&!O)W(!1),U(!1),N(null);if(!Q&&O)W(!1),U(!1),N(null);if(Q!==O)A(Q);let y=A2(()=>L0(Y,X,G,z,J),[Y,X,G,z,J]),b=K?_:y;if(j5(()=>{if(Q&&T&&M.current)M.current.focus()},[Q,T]),j5(()=>{if(!Q)return;let E=(c)=>{if(c.key==="Escape")$()};return window.addEventListener("keydown",E),()=>window.removeEventListener("keydown",E)},[Q,$]),!Q)return null;let C=b.trim().length>0;return J1("div",{className:"fixed inset-0 z-50 bg-black/50 backdrop-blur-sm flex items-center justify-center p-8",onClick:$,children:J1("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:(E)=>E.stopPropagation(),children:[J1("div",{className:"flex items-center justify-between px-5 py-3 border-b border-border-subtle flex-shrink-0",children:[J1("div",{className:"flex items-center gap-3",children:[J1("span",{className:"text-[13px] font-medium text-text-primary font-body",children:"Response preview"},void 0,!1,void 0,this),K&&J1("button",{onClick:()=>{W(!1),U(!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),J1("div",{className:"flex items-center gap-2",children:[J1("div",{className:"flex items-center bg-bg-base rounded-md p-0.5",children:[J1("button",{onClick:()=>U(!1),className:`px-2.5 py-1 rounded text-[11px] font-body font-medium transition-colors ${!T?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Preview"},void 0,!1,void 0,this),J1("button",{onClick:()=>U(!0),className:`px-2.5 py-1 rounded text-[11px] font-body font-medium transition-colors ${T?"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),J1("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),T?J1("textarea",{ref:M,value:b,onChange:(E)=>{H(E.target.value),W(!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):J1("div",{className:"flex-1 overflow-y-auto p-5",children:J1(d0,{text:b},void 0,!1,void 0,this)},void 0,!1,void 0,this),S.length>0&&J1("div",{className:"px-5 py-2 border-t border-border-subtle flex-shrink-0",children:J1("span",{className:"text-[12px] text-text-secondary font-body",children:["Reviewer feedback: ",J.size,"/",S.length," included"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),B&&J1("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:[J1("span",{children:B},void 0,!1,void 0,this),J1("button",{onClick:()=>{N(null),Z(b)},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),J1("div",{className:"flex justify-end gap-2 px-5 py-3 border-t border-border-subtle flex-shrink-0",children:[J1("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),J1("button",{onClick:()=>{let E=c0(G,z);if(E.length>0){N(`Please answer: ${E.join(", ")}`);return}N(null),Z(b)},disabled:!C,className:`px-6 py-2 rounded-lg font-body text-[13px] font-medium transition-all ${C?"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)}var r7=/!\[([^\]]*)\]\((\/tmp\/agent-canvas\/uploads\/([^)]+))\)/g;function l7(Q){return Q.replace(r7,($,Z,J,q)=>``)}function d0({text:Q}){let $=A2(()=>t.parse(l7(Q),{async:!1}),[Q]);return J1("div",{className:"prose-canvas font-body text-body text-text-primary leading-relaxed",dangerouslySetInnerHTML:{__html:$}},void 0,!1,void 0,this)}import{jsxDEV as t1}from"react/jsx-dev-runtime";var i7={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"},a7={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 k1({name:Q,type:$,expanded:Z,className:J=""}){if($==="dir")return t1("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",className:`flex-shrink-0 ${J}`,children:Z?t1("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):t1("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 q=Q.includes(".")?Q.split(".").pop().toLowerCase():"",Y=i7[q]||"#6b6560",X=a7[q];return t1("svg",{width:"14",height:"14",viewBox:"0 0 16 16",className:`flex-shrink-0 ${J}`,children:[t1("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:Y,opacity:"0.85"},void 0,!1,void 0,this),t1("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),X&&t1("text",{x:"8",y:"11.5",textAnchor:"middle",fill:"white",fontSize:"5.5",fontFamily:"monospace",fontWeight:"600",children:X},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function o7(Q){let $=Q.getAttribute("data-md");if($==="item"){let Z=Q.getAttribute("data-md-label");return Z?`[Item] ${Z}`:null}if($==="section"){let Z=Q.getAttribute("data-md-title");return Z?`[Section] ${Z}`:null}if($==="callout"){let Z=Q.getAttribute("data-md-type")||"info",J=Q.textContent?.trim().slice(0,60)||"Callout";return`[Callout:${Z}] ${J}`}if($==="note")return`[Note] ${Q.textContent?.trim().slice(0,60)||"Note"}`;if(Q.tagName==="TR"){let Z=Array.from(Q.querySelectorAll("td")).map((J)=>J.textContent?.trim()).filter(Boolean);return Z.length?`[Row] ${Z.join(" | ")}`:null}if($==="checklist-item"){let Z=Q.getAttribute("data-md-label");return Z?`[Checklist] ${Z}`:null}if($==="choice-option"||$==="multichoice-option"){let Z=Q.getAttribute("data-md-label");return Z?`[Option] ${Z}`:null}if($==="userinput"){let Z=Q.getAttribute("data-md-label");return Z?`[Input] ${Z}`:null}if($==="rangeinput"){let Z=Q.getAttribute("data-md-label");return Z?`[Range] ${Z}`:null}if($==="image"){let Z=Q.getAttribute("data-md-src");return Z?`[Image] ${Z}`:null}return null}function y0(Q){let $=document.querySelector(`[data-annotation-id="${Q.id}"]`);if($)return $;if(Q.snippet.startsWith("[")){for(let Z of document.querySelectorAll("[data-md='item'], [data-md='section'], [data-md='table'] tbody tr, [data-md='callout'], [data-md='note'], [data-md='checklist-item'], [data-md='image']"))if(o7(Z)===Q.snippet)return Z}return null}function C5(Q){Q.classList.remove("ann-flash"),Q.offsetWidth,Q.classList.add("ann-flash"),Q.addEventListener("animationend",()=>{Q.classList.remove("ann-flash")},{once:!0})}function C2(Q,$){if(Q.filePath)$({type:"file",path:Q.filePath}),setTimeout(()=>{let Z=y0(Q);if(Z)Z.scrollIntoView({behavior:"smooth",block:"center"}),C5(Z)},150);else{let Z=y0(Q);if(Z)Z.scrollIntoView({behavior:"smooth",block:"center"}),C5(Z)}}import{jsxDEV as P,Fragment as r0}from"react/jsx-dev-runtime";function V2({onSubmit:Q,collapseButton:$}){let{isReadOnly:Z,selectedRevision:J,currentRevision:q,revisions:Y,agentWatching:X}=i0(w1),G=i0(V5),z=Y.find((W)=>W.revision===J),_=Z&&J===q,H=!!z?.feedbackConsumed,K=z?.label||`Round ${J}`;if(Z)return P(e7,{sessionId:G,revision:J,label:K,waitingForUpdate:_,feedbackConsumed:H,agentWatching:X,collapseButton:$},void 0,!1,void 0,this);return P(Z8,{onSubmit:Q,agentWatching:X,collapseButton:$},void 0,!1,void 0,this)}function n7({sessionId:Q,revision:$,label:Z,waitingForUpdate:J,feedbackConsumed:q,agentWatching:Y,collapseButton:X}){let G=Z1.isShared,[z,_]=E1(null),[H,K]=E1(!0);return l0(()=>{if(K(!0),!B1){_(null),K(!1);return}fetch(`/api/session/${Q}/revision/${$}/feedback`).then((W)=>W.json()).then((W)=>{_(W.feedback||null),K(!1)}).catch(()=>{_(null),K(!1)})},[Q,$]),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:J?"Feedback sent":`Feedback — ${Z}`},void 0,!1,void 0,this),X]},void 0,!0,void 0,this),J&&!G&&P(R5,{feedbackConsumed:q,agentWatching:Y},void 0,!1,void 0,this),P("div",{className:"flex-1 overflow-y-auto px-4",children:H?P("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"Loading..."},void 0,!1,void 0,this):z?P(d0,{text:z},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 R5({feedbackConsumed:Q,agentWatching:$}){if(Q)return 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:"Feedback received — waiting for next revision..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if($)return P("div",{className:"mx-4 mb-3 px-3 py-2.5 rounded-lg bg-accent-blue-muted flex items-center gap-2 flex-shrink-0",children:[P("span",{className:"w-2 h-2 rounded-full bg-accent-blue animate-pulse"},void 0,!1,void 0,this),P("span",{className:"text-[12px] font-body text-accent-blue",children:"Waiting for agent to pick up feedback..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return P("div",{className:"mx-4 mb-3 px-3 py-2.5 rounded-lg bg-accent-amber-muted flex items-center gap-2 flex-shrink-0",children:[P("span",{className:"w-2 h-2 rounded-full bg-accent-amber"},void 0,!1,void 0,this),P("span",{className:"text-[12px] font-body text-accent-amber",children:"Agent disconnected — tell Claude to check feedback"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function e7({sessionId:Q,revision:$,label:Z,waitingForUpdate:J,feedbackConsumed:q,agentWatching:Y,collapseButton:X}){let{annotations:G,generalNote:z,activeAnnotationId:_,setActiveAnnotationId:H}=Y1(),{setActiveView:K}=i0(I1),W=G.length>0||z.trim().length>0,[T,U]=E1("feedback");if(!W)return P(n7,{sessionId:Q,revision:$,label:Z,waitingForUpdate:J,feedbackConsumed:q,agentWatching:Y,collapseButton:X},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:()=>U("feedback"),className:`px-2.5 py-1 rounded text-[11px] font-medium font-body transition-colors ${T==="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:()=>U("annotations"),className:`px-2.5 py-1 rounded text-[11px] font-medium font-body transition-colors flex items-center gap-1.5 ${T==="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:G.length},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),X]},void 0,!0,void 0,this),J&&P(R5,{feedbackConsumed:q,agentWatching:Y},void 0,!1,void 0,this),T==="feedback"?P($8,{sessionId:Q,revision:$},void 0,!1,void 0,this):P(Q8,{annotations:G,generalNote:z,activeAnnotationId:_,setActiveAnnotationId:H,setActiveView:K},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function $8({sessionId:Q,revision:$}){let[Z,J]=E1(null),[q,Y]=E1(!0);return l0(()=>{if(Y(!0),!B1){J(null),Y(!1);return}fetch(`/api/session/${Q}/revision/${$}/feedback`).then((X)=>X.json()).then((X)=>{J(X.feedback||null),Y(!1)}).catch(()=>{J(null),Y(!1)})},[Q,$]),P("div",{className:"flex-1 overflow-y-auto px-4",children:q?P("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"Loading..."},void 0,!1,void 0,this):Z?P(d0,{text:Z},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 Q8({annotations:Q,generalNote:$,activeAnnotationId:Z,setActiveAnnotationId:J,setActiveView:q}){let Y=Q.filter((U)=>U.filePath===T1),X=Q.filter((U)=>!U.filePath),G=Q.filter((U)=>U.filePath&&U.filePath!==T1),z={};for(let U of G){let B=U.filePath;if(!z[B])z[B]=[];z[B].push(U)}let _=(U)=>{J(U),r1(U,!0)},H=(U)=>{J(null),r1(U,!1)},K=(U)=>{if(U.id===Z)J(null);else if(J(U.id),U.filePath)q({type:"file",path:U.filePath}),setTimeout(()=>{let B=y0(U);if(B)B.scrollIntoView({behavior:"smooth",block:"center"})},150)},W=(U)=>P("div",{className:`group/ann relative px-3 py-2.5 transition-colors duration-150 cursor-pointer ${Z===U.id?"bg-highlight-selected":"odd:bg-bg-elevated-half hover:bg-bg-input"}`,onMouseEnter:()=>_(U.id),onMouseLeave:()=>H(U.id),onClick:()=>K(U),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:U.snippet.length>80?U.snippet.slice(0,80)+"...":U.snippet},void 0,!1,void 0,this),U.note.trim()&&P("div",{className:"text-[13px] font-body text-text-primary leading-relaxed",children:U.note},void 0,!1,void 0,this),P(F5,{images:U.images||[]},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(),C2(U,q)},className:"w-5 h-5 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-input transition-colors",title:"Scroll to 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("circle",{cx:"12",cy:"12",r:"3"},void 0,!1,void 0,this),P("path",{d:"M12 2v4M12 18v4M2 12h4M18 12h4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},U.id,!0,void 0,this),T=[Y,X,G].filter((U)=>U.length>0).length>1;return P(r0,{children:[P("div",{className:"flex-1 overflow-y-auto",children:[Y.length>0&&P(r0,{children:[T&&P("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body px-3 mb-1 mt-1",children:"Agent Response"},void 0,!1,void 0,this),Y.map(W)]},void 0,!0,void 0,this),X.length>0&&P(r0,{children:[T&&P("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body px-3 mb-1 mt-1",children:"Canvas"},void 0,!1,void 0,this),X.map(W)]},void 0,!0,void 0,this),Object.entries(z).map(([U,B])=>P("div",{children:[P("button",{onClick:()=>q({type:"file",path:U}),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:U,children:[P(k1,{name:U.split("/").pop()||U,type:"file"},void 0,!1,void 0,this),P("span",{className:"truncate",children:U},void 0,!1,void 0,this)]},void 0,!0,void 0,this),B.map(W)]},U,!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 Z8({onSubmit:Q,agentWatching:$,collapseButton:Z}){let[J,q]=E1(!1),{annotations:Y,updateAnnotation:X,removeAnnotation:G,addAnnotationImage:z,removeAnnotationImage:_,generalNote:H,setGeneralNote:K,activeAnnotationId:W,setActiveAnnotationId:T,responses:U,feedbackEntries:B}=Y1(),N=i0(V5),{setActiveView:M}=s7.useContext(I1),O=I5(null),A=I5(new Map),S=Y.filter((L)=>L.filePath===T1),y=Y.filter((L)=>!L.filePath),b=Y.filter((L)=>L.filePath&&L.filePath!==T1),C={};for(let L of b){let l=L.filePath;if(!C[l])C[l]=[];C[l].push(L)}l0(()=>{if(!W)return;let L=A.current.get(W);if(L)L.scrollIntoView({behavior:"smooth",block:"nearest"})},[W]);let E=I2((L)=>{T(L),r1(L,!0)},[T]),c=I2((L)=>{T(null),r1(L,!1)},[W]),h=t7(()=>Y.filter((L)=>L.source==="remote"),[Y]),[R,x]=E1(()=>new Set);l0(()=>{if(h.length===0)return;x((L)=>{let l=new Set(L);for(let u of h)l.add(u.id);return l.size===L.size?L:l})},[h]);let v=I2((L)=>{x((l)=>{let u=new Set(l);if(u.has(L))u.delete(L);else u.add(L);return u})},[]),D=Array.from(U.values()).some(j2),I=B.size>0,g=Y.length>0||H.trim().length>0||D||I,[d,w]=E1(null),k=(L)=>{let l=L.source==="remote";return P("div",{ref:(u)=>{if(u)A.current.set(L.id,u);else A.current.delete(L.id)},className:`group/ann relative px-3 py-2.5 transition-colors duration-150 ${W===L.id?"bg-highlight-selected":l?"bg-accent-purple-muted/30 hover:bg-accent-purple-muted/50":"odd:bg-bg-elevated-half hover:bg-bg-input"}`,onMouseEnter:()=>E(L.id),onMouseLeave:()=>c(L.id),onClick:()=>{if(L.id===W)T(null);else if(T(L.id),L.filePath)M({type:"file",path:L.filePath}),setTimeout(()=>{let u=y0(L);if(u)u.scrollIntoView({behavior:"smooth",block:"center"})},150)},children:[l&&L.author&&P("div",{className:"flex items-center gap-1.5 mb-1.5",children:[P("input",{type:"checkbox",checked:R.has(L.id),onChange:(u)=>{u.stopPropagation(),v(L.id)},onClick:(u)=>u.stopPropagation(),className:"accent-accent-purple flex-shrink-0",title:"Include in submission"},void 0,!1,void 0,this),P("span",{className:"inline-flex items-center justify-center w-4 h-4 rounded-full bg-accent-purple text-white text-[9px] font-medium uppercase",children:L.author.name.charAt(0)},void 0,!1,void 0,this),P("span",{className:"text-[11px] font-medium text-accent-purple font-body",children:L.author.name},void 0,!1,void 0,this),P("span",{className:"text-[10px] text-text-tertiary font-body uppercase tracking-widest",children:"Remote"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),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:L.snippet.length>80?L.snippet.slice(0,80)+"...":L.snippet},void 0,!1,void 0,this),l?P("div",{className:"text-[13px] font-body text-text-primary leading-relaxed whitespace-pre-wrap",children:L.note},void 0,!1,void 0,this):P("div",{onClick:(u)=>u.stopPropagation(),children:P(x0,{note:L.note,onNoteChange:(u)=>X(L.id,u),images:L.images||[],onAddImage:(u)=>z(L.id,u),onRemoveImage:(u)=>_(L.id,u),sessionId:N,autoResize:!0,minHeight:20,textareaClassName:"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]",textareaStyle:{height:"auto",overflow:"hidden"},placeholder:"Add your note...",attachButton:"on-focus"},void 0,!1,void 0,this)},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 flex items-center gap-0.5",children:[P("button",{onClick:(u)=>{u.stopPropagation(),C2(L,M)},className:"w-5 h-5 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-input transition-colors",title:"Scroll to 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("circle",{cx:"12",cy:"12",r:"3"},void 0,!1,void 0,this),P("path",{d:"M12 2v4M12 18v4M2 12h4M18 12h4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),!l&&P("button",{onClick:(u)=>{u.stopPropagation(),G(L.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,!0,void 0,this)]},L.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",Y.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:Y.length},void 0,!1,void 0,this),!Z1.isShared&&P("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${$?"bg-accent-green":"bg-accent-amber"}`,title:$?"Agent connected":"Agent disconnected"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Z]},void 0,!0,void 0,this),P("div",{ref:O,className:"flex-1 overflow-y-auto",children:[Y.length===0&&P("p",{className:"text-[12px] text-text-tertiary px-3 py-4 leading-relaxed font-body",children:"Select text in the canvas or in files to add annotations."},void 0,!1,void 0,this),S.length>0&&P(r0,{children:[(y.length>0||b.length>0)&&P("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body px-3 mb-1 mt-1",children:"Agent Response"},void 0,!1,void 0,this),S.map(k)]},void 0,!0,void 0,this),y.length>0&&(S.length>0||b.length>0)&&P("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body px-3 mb-1 mt-1",children:"Canvas"},void 0,!1,void 0,this),y.map(k),Object.entries(C).map(([L,l])=>P("div",{children:[P("button",{onClick:()=>M({type:"file",path:L}),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:L,children:[P(k1,{name:L.split("/").pop()||L,type:"file"},void 0,!1,void 0,this),P("span",{className:"truncate",children:L},void 0,!1,void 0,this)]},void 0,!0,void 0,this),l.map(k)]},L,!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:H,onChange:(L)=>K(L.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:(L)=>N0(L.target,40),ref:(L)=>{if(L)N0(L,40)}},void 0,!1,void 0,this)},void 0,!1,void 0,this),d&&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:d},void 0,!1,void 0,this),P("button",{onClick:()=>{w(null);let L=L0(Y,H,U,B,R);Q(L)},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:g?P("div",{className:"flex gap-2",children:[P("button",{onClick:()=>q(!0),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 L=c0(U,B);if(L.length>0){w(`Please answer: ${L.join(", ")}`);return}w(null);let l=L0(Y,H,U,B,R);Q(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:()=>Q("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),P(A5,{open:J,onClose:()=>q(!1),onSubmit:Q,includedRemoteIds:R,onToggleRemoteId:v},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{useEffect as q8,useState as D5,useContext as k5,useMemo as J8}from"react";import{SessionContext as Y8}from"#canvas/runtime";import{jsxDEV as i,Fragment as R2}from"react/jsx-dev-runtime";function E5({embedded:Q}={}){let $=k5(Y8),{annotations:Z,addAnnotation:J}=Y1(),{setActiveView:q}=k5(I1),[Y,X]=D5(!1),[G,z]=D5({});if(!B1)return i("div",{className:Q?"px-4 py-3":"p-4",children:[i("div",{className:"text-[11px] uppercase tracking-widest text-text-tertiary font-body mb-2",children:"Files"},void 0,!1,void 0,this),i("p",{className:"text-[11px] text-text-tertiary font-body leading-relaxed",children:"File browsing is not available in shared view. File previews embedded in the canvas still work."},void 0,!1,void 0,this)]},void 0,!0,void 0,this);let{annCountMap:_,annotatedFiles:H}=J8(()=>{let O=new Map;for(let A of Z)if(A.filePath&&A.filePath!==T1)O.set(A.filePath,(O.get(A.filePath)||0)+1);return{annCountMap:O,annotatedFiles:[...O.keys()]}},[Z]),K=async(O)=>{let S=await(await fetch(`/api/tree?session=${$}&path=${encodeURIComponent(O)}`)).json();if(S.entries)z((y)=>({...y,[O]:{entries:S.entries,expanded:!0,loaded:!0}}))};q8(()=>{if(!Y&&!G[""])K("")},[Y]);let W=(O)=>{if(G[O]?.loaded)z((A)=>({...A,[O]:{...A[O],expanded:!A[O].expanded}}));else K(O)},T=(O)=>{q({type:"file",path:O})},U=async(O)=>{let S=await(await fetch(`/api/file?session=${$}&path=${encodeURIComponent(O)}`)).json();if(!S.error){let y=S.content.split(`
|
|
70
70
|
`).slice(0,3).join(`
|
|
71
71
|
`)+(S.content.split(`
|
|
72
72
|
`).length>3?`
|
|
73
|
-
...`:"");J(
|
|
74
|
-
`);if(!
|
|
75
|
-
`)}catch{return null}},[
|
|
76
|
-
`);
|
|
73
|
+
...`:"");J(y,"Include this file for context",O)}},B=async(O)=>{let A=[];if(G[O]?.loaded)A=G[O].entries;else{let y=await(await fetch(`/api/tree?session=${$}&path=${encodeURIComponent(O)}`)).json();if(y.entries)A=y.entries}await Promise.all(A.filter((S)=>S.type==="file").map((S)=>U(O?`${O}/${S.name}`:S.name)))},N=(O)=>_.get(O)||0,M=(O,A=0)=>{let S=G[O];if(!S?.expanded)return null;return S.entries.map((y)=>{let b=O?`${O}/${y.name}`:y.name,C=N(b);return i("div",{children:[i("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+A*16}px`,paddingRight:"8px"},children:y.type==="dir"?i(R2,{children:[i("span",{onClick:()=>W(b),className:"flex items-center gap-1.5 flex-1 text-text-secondary hover:text-text-primary cursor-pointer truncate",children:[i(k1,{name:y.name,type:"dir",expanded:G[b]?.expanded},void 0,!1,void 0,this),i("span",{className:"truncate",children:y.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("button",{onClick:(E)=>{E.stopPropagation(),B(b)},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):i(R2,{children:[i("span",{onClick:()=>T(b),className:`flex-1 truncate cursor-pointer flex items-center gap-1.5 ${C>0?"text-text-primary":"text-text-secondary hover:text-text-primary"}`,children:[i(k1,{name:y.name,type:"file"},void 0,!1,void 0,this),i("span",{className:"truncate",children:y.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{className:"flex items-center gap-1 flex-shrink-0 ml-1",children:[C>0&&i("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:C},void 0,!1,void 0,this),i("button",{onClick:(E)=>{E.stopPropagation(),U(b)},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),y.type==="dir"&&M(b,A+1)]},b,!0,void 0,this)})};if(Q)return i(R2,{children:[i("div",{className:"flex items-center justify-between px-4 pt-3 pb-2 flex-shrink-0",children:i("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),i("div",{className:"flex-1 overflow-y-auto",children:M("")},void 0,!1,void 0,this),H.length>0&&i("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:[i("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body mb-1.5",children:"Referenced"},void 0,!1,void 0,this),H.map((O)=>i("div",{onClick:()=>T(O),className:"flex items-center justify-between text-[12px] font-body text-text-secondary hover:text-text-primary cursor-pointer py-0.5",children:[i("span",{className:"truncate",children:O.split("/").pop()},void 0,!1,void 0,this),i("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:N(O)},void 0,!1,void 0,this)]},O,!0,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);if(Y)return i("div",{className:"hidden lg:flex w-8 border-r border-border-subtle bg-bg-surface flex-col items-center flex-shrink-0",children:i("button",{onClick:()=>X(!1),className:"mt-3 p-1 text-text-tertiary hover:text-text-secondary transition-colors",children:i("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:i("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 i("div",{className:"hidden lg:flex w-60 border-r border-border-subtle bg-bg-surface flex-col flex-shrink-0 overflow-hidden",children:[i("div",{className:"flex items-center justify-between px-4 pt-4 pb-3 flex-shrink-0",children:[i("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:"Files"},void 0,!1,void 0,this),i("button",{onClick:()=>X(!0),className:"text-text-tertiary hover:text-text-secondary transition-colors p-0.5",children:i("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:i("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),i("div",{className:"flex-1 overflow-y-auto",children:M("")},void 0,!1,void 0,this),H.length>0&&i("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:[i("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body mb-1.5",children:"Referenced"},void 0,!1,void 0,this),H.map((O)=>i("div",{onClick:()=>T(O),className:"flex items-center justify-between text-[12px] font-body text-text-secondary hover:text-text-primary cursor-pointer py-0.5",children:[i("span",{className:"truncate",children:O.split("/").pop()},void 0,!1,void 0,this),i("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:N(O)},void 0,!1,void 0,this)]},O,!0,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}import{useEffect as x5,useState as X0,useContext as X8,useCallback as z8,useRef as o0,useMemo as m5}from"react";import{SessionContext as _8}from"#canvas/runtime";var a0={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 W1}from"react/jsx-dev-runtime";function u5(Q){let $=Q instanceof HTMLElement?Q:Q.parentElement;while($){if($.hasAttribute("data-line-num"))return $;$=$.parentElement}return null}function G8(Q){let $=Q.toString().trim(),Z=u5(Q.startContainer),J=u5(Q.endContainer),q=Z?parseInt(Z.getAttribute("data-line-num"),10):void 0,Y=J?parseInt(J.getAttribute("data-line-num"),10):void 0,X="",G="";if($.length<30&&Z&&Z===J){let z=Z.querySelector("code");if(z){let _=z.textContent||"",H=_.indexOf($);if(H>=0)X=_.slice(0,H).trimStart(),G=_.slice(H+$.length).trimEnd()}}return{before:X,after:G,hierarchy:[],lineStart:q,lineEnd:Y}}function g5({path:Q}){if(!B1)return W1("div",{className:"max-w-[720px] mx-auto px-6 pt-12 pb-32",children:W1("div",{className:"p-4 rounded-lg border border-border-subtle bg-bg-surface",children:[W1("div",{className:"text-[11px] uppercase tracking-widest text-text-tertiary font-body mb-2",children:"File not available"},void 0,!1,void 0,this),W1("p",{className:"text-[13px] text-text-secondary font-body leading-relaxed",children:["Opening ",W1("code",{className:"px-1 py-0.5 rounded bg-bg-elevated text-text-primary text-[11px]",children:Q},void 0,!1,void 0,this)," requires filesystem access, which isn't available in shared view. If the canvas author wanted this file visible, they should embed it as a ",W1("code",{className:"px-1 py-0.5 rounded bg-bg-elevated text-text-primary text-[11px]",children:"<FilePreview>"},void 0,!1,void 0,this)," in the canvas."]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this);let $=X8(_8),{annotations:Z,addAnnotationWithId:J,activeAnnotationId:q,setActiveAnnotationId:Y}=Y1(),[X,G]=X0(null),[z,_]=X0("text"),[H,K]=X0(!0),[W,T]=X0(null),U=o0(null),[B,N]=X0(null),[M,O]=X0(null),A=o0(null),S=o0(null),y=o0([]),b=Z.filter((I)=>I.filePath===Q),C=U.current?.closest("#plan-scroll-container"),{popovers:E,openCreatePopover:c}=a1({containerRef:U,restoreKey:`${X}:${Q}`,restoreAnnotations:b,extractContext:G8,filePath:Q,scrollContainer:C});x5(()=>{K(!0),T(null),fetch(`/api/file?session=${$}&path=${encodeURIComponent(Q)}`).then((I)=>I.json()).then((I)=>{if(I.error)T(I.error),K(!1);else G(I.content),_(I.language||"text"),K(!1)}).catch(()=>{T("Failed to fetch file"),K(!1)})},[$,Q]);let h=z8((I,g)=>{I.preventDefault(),A.current=g,S.current=g,N(g),O(g)},[]);x5(()=>{let I=(d)=>{if(A.current===null)return;let w=d.target.closest("[data-line-num]");if(w){let k=parseInt(w.getAttribute("data-line-num"),10);S.current=k,O(k)}},g=()=>{let d=A.current;if(d===null)return;A.current=null;let w=S.current??d,k=Math.min(d,w),L=Math.max(d,w),u=y.current.slice(k-1,L).join(`
|
|
74
|
+
`);if(!u.trim()){N(null),O(null);return}let m=`__pending_${Date.now()}`,a={before:"",after:"",hierarchy:[],lineStart:k,lineEnd:L};if(U.current){let j=U.current.querySelectorAll("[data-line-num]"),f=j[k-1],$1=j[L-1];if(f&&$1){let v1=f.querySelector("code"),A1=$1.querySelector("code");if(v1&&A1)try{let e1=document.createRange();e1.setStartBefore(v1.firstChild||v1),e1.setEndAfter(A1.lastChild||A1),l1(e1,m)}catch{}}let K1=j[L-1];if(K1)c(K1,m,u,a)}N(null),O(null)};return document.addEventListener("mousemove",I),document.addEventListener("mouseup",g),()=>{document.removeEventListener("mousemove",I),document.removeEventListener("mouseup",g)}},[]);let R=m5(()=>{if(!X)return null;let I=window.hljs;if(!I)return null;let g=Q.split(".").pop()||"",d=a0[g];try{return(d?I.highlight(X,{language:d}):I.highlightAuto(X)).value.split(`
|
|
75
|
+
`)}catch{return null}},[X,Q]);if(H)return W1("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-[13px]",children:["Loading ",Q,"..."]},void 0,!0,void 0,this);if(W)return W1("div",{className:"p-8 text-accent-red font-body text-[13px]",children:W},void 0,!1,void 0,this);if(!X)return null;let x=X.split(`
|
|
76
|
+
`);y.current=x;let v=m5(()=>{if(B===null)return null;let I=M??B;return{start:Math.min(B,I),end:Math.max(B,I)}},[B,M]),D=()=>{let I=X.split(`
|
|
77
77
|
`).slice(0,3).join(`
|
|
78
|
-
`)+(
|
|
79
|
-
...`:""),
|
|
78
|
+
`)+(x.length>3?`
|
|
79
|
+
...`:""),g=F1();J(g,I,"",Q),Y(g)};return W1("div",{children:[W1("pre",{ref:U,className:"text-code font-mono text-text-code bg-bg-base select-text cursor-text py-3 hljs",children:x.map((I,g)=>{let d=g+1,w=v&&d>=v.start&&d<=v.end;return W1("div",{"data-line-num":d,className:`flex px-5 ${w?"bg-accent-blue/10":"hover:bg-bg-elevated-half"}`,children:[W1("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:(k)=>h(k,d),children:d},void 0,!1,void 0,this),R?W1("code",{className:"py-px",dangerouslySetInnerHTML:{__html:R[g]||" "}},void 0,!1,void 0,this):W1("code",{className:"py-px",children:I||" "},void 0,!1,void 0,this)]},g,!0,void 0,this)})},void 0,!1,void 0,this),E]},void 0,!0,void 0,this)}import{useEffect as v5,useState as f5,useRef as K8}from"react";import{jsxDEV as j1}from"react/jsx-dev-runtime";function h5(Q,$){if($){let Z=$.replace(/\/+$/,"").split("/");return Z[Z.length-1]||Q}return Q.length>30?Q.slice(0,30)+"...":Q}function D2({currentSessionId:Q,projectRoot:$}){let[Z,J]=f5([]),[q,Y]=f5(!1),X=K8(null);v5(()=>{if(!B1)return;let _=async()=>{try{let W=await(await fetch("/api/sessions")).json();J((T)=>{let U=JSON.stringify(W);return JSON.stringify(T)===U?T:W})}catch{}};_();let H=setInterval(_,5000);return()=>clearInterval(H)},[]),v5(()=>{if(!q)return;let _=(H)=>{if(X.current&&!X.current.contains(H.target))Y(!1)};return document.addEventListener("mousedown",_),()=>document.removeEventListener("mousedown",_)},[q]);let G=Z.filter((_)=>_.id!==Q),z=h5(Q,$);return j1("div",{className:"relative",ref:X,children:[j1("div",{className:"flex items-center gap-1.5 font-body text-body font-medium",children:[j1("a",{href:`/s/${Q}`,className:"text-text-primary hover:text-text-secondary transition-colors",children:z},void 0,!1,void 0,this),G.length>0&&j1("button",{onClick:()=>Y(!q),className:"flex items-center justify-center text-text-tertiary hover:text-text-secondary transition-colors",children:j1("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:`transition-transform duration-200 ${q?"rotate-180":""}`,children:j1("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),q&&G.length>0&&j1("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:G.map((_)=>j1("a",{href:`/s/${_.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:[j1("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${_.currentRevision>0?"bg-accent-green":"bg-border-hover"}`},void 0,!1,void 0,this),j1("span",{className:"truncate",children:h5(_.id,_.projectRoot)},void 0,!1,void 0,this)]},_.id,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function p5(Q){let $=[];return s0(Q,$,0),$.join(`
|
|
80
80
|
`).replace(/\n{3,}/g,`
|
|
81
81
|
|
|
82
82
|
`).trim()+`
|
|
83
|
-
`}var K8=new Set(["CODE","SPAN","STRONG","EM","A","B","I","U","SMALL","SUB","SUP","MARK","ABBR"]);function o0(Q,$,Z){if(U8(Q)){let J=H8(Q);if(J)$.push(J,"");return}for(let J of Q.childNodes)if(J.nodeType===Node.ELEMENT_NODE)W8(J,$,Z);else if(J.nodeType===Node.TEXT_NODE){let q=J.textContent?.trim();if(q)$.push(q,"")}}function U8(Q){for(let $ of Q.childNodes){if($.nodeType===Node.TEXT_NODE)continue;if($.nodeType===Node.ELEMENT_NODE){let Z=$;if(!K8.has(Z.tagName)||Z.hasAttribute("data-md"))return!1}}return Q.childNodes.length>0}function H8(Q){let $="";for(let Z of Q.childNodes)if(Z.nodeType===Node.TEXT_NODE)$+=Z.textContent||"";else if(Z.nodeType===Node.ELEMENT_NODE){let J=Z;if(J.tagName==="CODE")$+="`"+(J.textContent||"")+"`";else $+=J.textContent||""}return $.trim()}function W8(Q,$,Z){let J=Q.getAttribute("data-md");if(J)switch(J){case"section":return T8(Q,$,Z);case"item":return N8(Q,$);case"codeblock":return O8(Q,$);case"callout":return F8(Q,$);case"note":return B8(Q,$);case"table":return L8(Q,$);case"checklist":return M8(Q,$);case"diff":return y8(Q,$);case"mermaid":return P8(Q,$);case"choice":return S8(Q,$);case"multichoice":return b8(Q,$);case"choice-option":case"multichoice-option":return;case"userinput":return w8(Q,$);case"rangeinput":return j8(Q,$);case"checklist-item":return;case"filepreview":return A8(Q,$);case"priority":return C8(Q,$)}if(Q.querySelector("button, input, select, textarea"))return;if(Q.children.length>0)o0(Q,$,Z);else{let q=Q.textContent?.trim();if(q)$.push(q,"")}}function T8(Q,$,Z){let J=Q.getAttribute("data-md-title")||"Untitled",q=Z===0?"##":"###";$.push(`${q} ${J}`,"");let X=Q.querySelector(":scope > div:last-of-type");if(X)o0(X,$,Z+1)}function N8(Q,$){let Z=Q.getAttribute("data-md-label")||"",J=Q.getAttribute("data-md-status"),q=Q.getAttribute("data-md-badge"),X="-";if(J==="done")X="- [x]";else if(J)X="- [ ]";let Y=`${X} **${Z}**`;if(q)Y+=` \`${q}\``;$.push(Y);let G=Q.querySelector(".text-text-secondary");if(G){let z=[];o0(G,z,0);for(let _ of z)$.push(_?` ${_}`:"")}$.push("")}function O8(Q,$){let Z=Q.getAttribute("data-md-language")||"",q=Q.querySelector("code")?.textContent||"";$.push(`\`\`\`${Z}`,q,"```","")}function F8(Q,$){let Z=Q.getAttribute("data-md-type")||"info",J={info:"Info",warning:"Warning",danger:"Danger",tip:"Tip"},q=I8(Q.querySelector(".text-text-secondary")||Q);$.push(`> **${J[Z]||Z}:** ${q}`,"")}function B8(Q,$){let Z=Q.textContent?.trim()||"";$.push(`> *${Z}*`,"")}function L8(Q,$){let Z=Q.querySelector("table");if(!Z)return;let J=[];for(let q of Z.querySelectorAll("thead th"))J.push(q.textContent?.trim()||"");if(J.length===0)return;$.push(`| ${J.join(" | ")} |`),$.push(`| ${J.map(()=>"---").join(" | ")} |`);for(let q of Z.querySelectorAll("tbody tr")){let X=[];for(let Y of q.querySelectorAll("td"))X.push(Y.textContent?.trim()||"");$.push(`| ${X.join(" | ")} |`)}$.push("")}function M8(Q,$){for(let Z of Q.querySelectorAll("li")){let J=Z.querySelector(".bg-accent-green")!==null,q=Z.textContent?.trim()||"";$.push(`- [${J?"x":" "}] ${q}`)}$.push("")}function y8(Q,$){let Z=Q.getAttribute("data-md-language")||"";$.push(`\`\`\`diff${Z?` (${Z})`:""}`);for(let J of Q.querySelectorAll("[class*='flex']")){let q=J.querySelector(".text-accent-red")?"-":J.querySelector(".text-accent-green")?"+":" ",X=J.querySelector("code");if(X)$.push(`${q} ${X.textContent}`)}$.push("```","")}function P8(Q,$){let Z=Q.getAttribute("data-md-source")||"";if(Z)$.push("```mermaid",Z,"```","")}function S8(Q,$){let Z=Q.getAttribute("data-md-label")||"";$.push(`**${Z}:**`);for(let J of Q.querySelectorAll("[data-md='choice-option']")){let q=J.getAttribute("data-md-label")||J.textContent?.trim()||"",X=J.querySelector(".bg-accent-amber")!==null;$.push(`- ${X?"(x)":"( )"} ${q}`)}$.push("")}function b8(Q,$){let Z=Q.getAttribute("data-md-label")||"";$.push(`**${Z}:**`);for(let J of Q.querySelectorAll("[data-md='multichoice-option']")){let q=J.getAttribute("data-md-label")||J.textContent?.trim()||"",X=J.querySelector(".bg-accent-amber")!==null;$.push(`- [${X?"x":" "}] ${q}`)}$.push("")}function w8(Q,$){let Z=Q.getAttribute("data-md-label")||"",q=Q.querySelector("textarea")?.value?.trim()||"";$.push(`**${Z}:** ${q||"_empty_"}`,"")}function j8(Q,$){let Z=Q.getAttribute("data-md-label")||"",J=Q.querySelector("input[type='range']"),X=Q.querySelector(".font-mono")?.textContent?.trim()||J?.value||"—";$.push(`**${Z}:** ${X}`,"")}function A8(Q,$){let Z=Q.getAttribute("data-md-path")||"",J=Q.getAttribute("data-md-lines")||"",X=Q.querySelector("code")?.textContent||"",Y=Z.split(".").pop()||"",G=i0[Y]||"",z=J?`${Z} (L${J})`:Z;$.push(z,"",`\`\`\`${G}`,X,"```","")}function C8(Q,$){}function I8(Q){return Q?.textContent?.trim()||""}import $3,{useEffect as m1,useState as _1,useRef as V1,useCallback as Q3,useMemo as e0,useContext as r8}from"react";import{useEffect as V8,useState as R8,useRef as D8,useContext as k8}from"react";import{jsxDEV as H1,Fragment as c5}from"react/jsx-dev-runtime";function E8(Q){return Q.label||`Round ${Q.revision}`}function m8(Q){let $=Date.now()-new Date(Q).getTime(),Z=Math.floor($/1000);if(Z<60)return"just now";let J=Math.floor(Z/60);if(J<60)return`${J}m ago`;let q=Math.floor(J/60);if(q<24)return`${q}h ago`;return`${Math.floor(q/24)}d ago`}function P0({value:Q,onChange:$,accent:Z="default",className:J}){let{currentRevision:q,revisions:X}=k8(w1),[Y,G]=R8(!1),z=D8(null);V8(()=>{if(!Y)return;let K=(H)=>{if(z.current&&!z.current.contains(H.target))G(!1)};return document.addEventListener("mousedown",K),()=>document.removeEventListener("mousedown",K)},[Y]);let _=X.find((K)=>K.revision===Q);return H1("div",{className:"relative",ref:z,children:[H1("button",{onClick:()=>G(!Y),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"}[Z]} ${J||""}`,children:[_?E8(_):`Round ${Q}`,H1("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",className:`text-text-tertiary transition-transform duration-200 ${Y?"rotate-180":""}`,children:H1("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),Y&&H1("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((K)=>H1("button",{onClick:()=>{$(K.revision),G(!1)},className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] font-body transition-colors ${K.revision===Q?"bg-bg-surface text-text-primary":"text-text-secondary hover:bg-bg-surface hover:text-text-primary"}`,children:[H1("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${K.revision===q?"bg-accent-green":K.hasFeedback?"bg-accent-amber":"bg-border-hover"}`},void 0,!1,void 0,this),H1("span",{className:"flex-1 text-left truncate",children:K.label?H1(c5,{children:[K.label," ",H1("span",{className:"text-text-tertiary",children:["#",K.revision]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):H1(c5,{children:["Round ",K.revision]},void 0,!0,void 0,this)},void 0,!1,void 0,this),H1("span",{className:"text-[10px] text-text-tertiary flex-shrink-0 flex items-center gap-1.5",children:[(()=>{let H=K.canvasFiles?.reduce((T,U)=>{if(U.diffStats)T.added+=U.diffStats.added,T.removed+=U.diffStats.removed;return T},{added:0,removed:0});if(H&&(H.added>0||H.removed>0))return H1("span",{className:"font-mono",children:[H1("span",{className:"text-accent-green",children:["+",H.added]},void 0,!0,void 0,this)," ",H1("span",{className:"text-accent-red",children:["-",H.removed]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);return null})(),K.revision===q?"current":K.hasFeedback?"sent":m8(K.createdAt)]},void 0,!0,void 0,this)]},K.revision,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function E1(Q,$){let Z=Q.length,J=$.length;if(Z===0||J===0)return[];let q=Array.from({length:Z+1},()=>Array(J+1).fill(0));for(let z=1;z<=Z;z++)for(let _=1;_<=J;_++)q[z][_]=Q[z-1]===$[_-1]?q[z-1][_-1]+1:Math.max(q[z-1][_],q[z][_-1]);let X=[],Y=Z,G=J;while(Y>0&&G>0)if(Q[Y-1]===$[G-1])X.unshift(Q[Y-1]),Y--,G--;else if(q[Y-1][G]>q[Y][G-1])Y--;else G--;return X}function d5(Q){let $=[],Z=[],J=document.createTreeWalker(Q,NodeFilter.SHOW_TEXT,{acceptNode(X){let Y=X.parentElement;if(!Y)return NodeFilter.FILTER_REJECT;if(Y.closest("svg, .select-none, [data-no-diff]"))return NodeFilter.FILTER_REJECT;return NodeFilter.FILTER_ACCEPT}}),q;while(q=J.nextNode()){let Y=(q.nodeValue||"").match(/\S+|\s+/g);if(!Y)continue;let G=0;for(let z of Y)$.push(z),Z.push({text:z,node:q,offset:G}),G+=z.length}return{words:$,map:Z}}function D2(Q,$){if(Q.length>5000||$.length>5000)return x8(Q,$);return i5(Q,$)}function i5(Q,$){let Z=s0(Q,$),J=[],q=[],X=0,Y=0,G=0;while(X<Q.length||Y<$.length)if(G<Z.length&&X<Q.length&&Y<$.length&&Q[X]===Z[G]&&$[Y]===Z[G])J.push({type:"same",index:X}),q.push({type:"same",index:Y}),X++,Y++,G++;else if(X<Q.length&&(G>=Z.length||Q[X]!==Z[G]))J.push({type:"removed",index:X}),X++;else if(Y<$.length)q.push({type:"added",index:Y}),Y++;return{oldOps:J,newOps:q}}function s0(Q,$){let Z=Q.length,J=$.length;if(Z===0||J===0)return[];if(Z===1)return $.includes(Q[0])?[Q[0]]:[];if(J===1)return Q.includes($[0])?[$[0]]:[];if(Z*J<=1e6)return E1(Q,$);let q=Math.floor(Z/2),X=Q.slice(0,q),Y=Q.slice(q),G=r5(X,$),z=r5([...Y].reverse(),[...$].reverse()),_=0,W=0;for(let T=0;T<=J;T++){let U=G[T]+z[J-T];if(U>_)_=U,W=T}let K=$.slice(0,W),H=$.slice(W);return[...s0(X,K),...s0(Y,H)]}function r5(Q,$){let Z=$.length,J=Array(Z+1).fill(0),q=Array(Z+1).fill(0);for(let X=0;X<Q.length;X++){for(let Y=1;Y<=Z;Y++)q[Y]=Q[X]===$[Y-1]?J[Y-1]+1:Math.max(J[Y],q[Y-1]);[J,q]=[q,J],q.fill(0)}return J}function x8(Q,$){let J=(U)=>{let L=[];for(let N=0;N<U.length;N+=200){let P=Math.min(N+200,U.length);L.push({start:N,end:P,text:U.slice(N,P).join("")})}return L},q=J(Q),X=J($),Y=q.map((U)=>U.text),G=X.map((U)=>U.text),z=s0(Y,G),_=[],W=[],K=0,H=0,T=0;while(K<q.length||H<X.length)if(T<z.length&&K<q.length&&H<X.length&&Y[K]===z[T]&&G[H]===z[T]){for(let U=q[K].start;U<q[K].end;U++)_.push({type:"same",index:U});for(let U=X[H].start;U<X[H].end;U++)W.push({type:"same",index:U});K++,H++,T++}else if(K<q.length&&(T>=z.length||Y[K]!==z[T]))if(H<X.length&&(T>=z.length||G[H]!==z[T])){let U=i5(Q.slice(q[K].start,q[K].end),$.slice(X[H].start,X[H].end));for(let L of U.oldOps)_.push({type:L.type,index:L.index+q[K].start});for(let L of U.newOps)W.push({type:L.type,index:L.index+X[H].start});K++,H++}else{for(let U=q[K].start;U<q[K].end;U++)_.push({type:"removed",index:U});K++}else if(H<X.length){for(let U=X[H].start;U<X[H].end;U++)W.push({type:"added",index:U});H++}return{oldOps:_,newOps:W}}function l5(Q,$,Z){let J=new Map;for(let q of Q){if(q.type==="same")continue;let X=$[q.index];if(!X||!X.node.parentNode)continue;let Y=J.get(X.node);if(!Y)Y=[],J.set(X.node,Y);Y.push({offset:X.offset,length:X.text.length})}for(let[q,X]of J){if(!q.parentNode)continue;let Y=q.nodeValue||"";X.sort((K,H)=>K.offset-H.offset);let G=[];for(let K of X){let H=G[G.length-1];if(H&&K.offset<=H.offset+H.length)H.length=Math.max(H.length,K.offset+K.length-H.offset);else G.push({...K})}let z=q.parentNode,_=document.createDocumentFragment(),W=0;for(let K of G){if(K.offset>W)_.appendChild(document.createTextNode(Y.slice(W,K.offset)));let H=document.createElement("span");H.className=Z,H.textContent=Y.slice(K.offset,K.offset+K.length),_.appendChild(H),W=K.offset+K.length}if(W<Y.length)_.appendChild(document.createTextNode(Y.slice(W)));z.replaceChild(_,q)}}function t0(Q,$){let Z=u8(Q,$),J=d5(Q),q=d5($),{oldOps:X,newOps:Y}=D2(J.words,q.words),G=X.some((z)=>z.type==="removed")||Y.some((z)=>z.type==="added");return l5(X,J.map,"diff-removed"),l5(Y,q.map,"diff-added"),G||Z}function u8(Q,$){let Z=Array.from(Q.querySelectorAll('[data-md="mermaid"]')),J=Array.from($.querySelectorAll('[data-md="mermaid"]')),q=!1,X=Math.max(Z.length,J.length);for(let Y=0;Y<X;Y++){let G=Z[Y],z=J[Y];if(!G&&z){z.classList.add("diff-block-added"),z.style.position="relative",q=!0;continue}if(G&&!z){G.classList.add("diff-block-removed"),G.style.position="relative",q=!0;continue}if(!G||!z)continue;let _=(G.getAttribute("data-md-source")||"").trim(),W=(z.getAttribute("data-md-source")||"").trim();if(_===W)continue;q=!0,G.style.borderLeft="3px solid var(--color-accent-red)",G.style.paddingLeft="8px",z.style.borderLeft="3px solid var(--color-accent-green)",z.style.paddingLeft="8px";let K=_.split(`
|
|
84
|
-
`),H
|
|
85
|
-
`),T=E1(K,H),U=(L,N,P)=>{let O=document.createElement("div");O.className="mt-2 bg-bg-code rounded-md overflow-hidden text-tiny font-mono",O.setAttribute("data-no-diff","true");let w=0,S=0;while(S<L.length){let M=document.createElement("div");if(M.className="px-3 py-0.5 whitespace-pre-wrap",w<N.length&&L[S]===N[w])M.textContent=" "+L[S],S++,w++;else M.classList.add(P==="old"?"diff-removed":"diff-added"),M.textContent=(P==="old"?"- ":"+ ")+L[S],S++;O.appendChild(M)}return O};G.appendChild(U(K,T,"old")),z.appendChild(U(H,T,"new"))}return q}function z0(Q){let $=[],Z=Q.querySelectorAll(":scope > [data-md]");for(let J of Z)$.push(S0(J));if($.length===0){let J=Q.querySelectorAll("[data-md]"),q=new Set;for(let X of J){let Y=X.parentElement?.closest("[data-md]");if(Y&&Q.contains(Y))continue;if(q.has(X))continue;q.add(X),$.push(S0(X))}}return $}function S0(Q){let $=Q.getAttribute("data-md")||"unknown",Z=g8(Q,$),J=[];if($==="section"){let q=Q.querySelector(":scope > div.mt-6, :scope > div:last-child");if(q)for(let X of q.querySelectorAll(":scope > [data-md]"))J.push(S0(X))}else if($==="table")for(let q of Q.querySelectorAll(":scope table > tbody > tr"))J.push({key:"tr:"+(q.textContent||"").slice(0,80),type:"tr",element:q,children:[]});else if($==="checklist")for(let q of Q.querySelectorAll(":scope > [data-md='checklist-item']"))J.push(S0(q));else for(let q of Q.querySelectorAll("[data-md]"))if(q.parentElement?.closest("[data-md]")===Q)J.push(S0(q));return{key:Z,type:$,element:Q,children:J}}function g8(Q,$){switch($){case"section":return"section:"+(Q.getAttribute("data-md-title")||"");case"item":return"item:"+(Q.getAttribute("data-task-id")||Q.getAttribute("data-md-label")||"");case"codeblock":case"diff":return $+":"+(Q.textContent||"").slice(0,80);case"checklist-item":return"checklist-item:"+(Q.getAttribute("data-md-label")||Q.textContent?.slice(0,60)||"");case"checklist":return"checklist:"+Q.querySelectorAll("[data-md='checklist-item']").length;case"markdown":return"markdown:"+(Q.getAttribute("data-md-file")||"inline");case"mermaid":return"mermaid:"+(Q.getAttribute("data-md-source")||"").slice(0,80);case"callout":return"callout:"+(Q.getAttribute("data-md-type")||"")+":"+(Q.textContent||"").slice(0,60);default:return $+":"+(Q.getAttribute("data-md-label")||Q.textContent?.slice(0,60)||"")}}function b0(Q,$){let Z=Q.map((_)=>_.key),J=$.map((_)=>_.key),q=E1(Z,J),X=[],Y=0,G=0,z=0;while(Y<Q.length||G<$.length)if(z<q.length&&Y<Q.length&&G<$.length&&Z[Y]===q[z]&&J[G]===q[z]){let _=Q[Y],W=$[G],K=_.children.length>0||W.children.length>0?b0(_.children,W.children):void 0;X.push({kind:"matched",oldBlock:_,newBlock:W,childMatches:K}),Y++,G++,z++}else if(Y<Q.length&&(z>=q.length||Z[Y]!==q[z]))X.push({kind:"removed",oldBlock:Q[Y]}),Y++;else if(G<$.length)X.push({kind:"added",newBlock:$[G]}),G++;return X}function n0(Q){let $=document.createDocumentFragment(),Z=!1;for(let J of Q)if(J.kind==="removed")Z=!0,$.appendChild(o5(J.oldBlock.element));else if(J.kind==="added")Z=!0,$.appendChild(v8(J.newBlock.element));else{let q=J.newBlock.element.cloneNode(!0),X=J.newBlock.type;if(X==="mermaid"){if(e5(J.oldBlock.element,q))Z=!0}else if(J.childMatches&&J.childMatches.length>0&&(X==="table"||X==="checklist")){if(t5(q,J.childMatches,X))Z=!0}else if(J.childMatches&&J.childMatches.length>0){if(s5(J.oldBlock,q,J.childMatches,X))Z=!0}else if(X==="markdown"){if(n5(J.oldBlock.element,q))Z=!0}else if(t1(J.oldBlock.element,q,!1))Z=!0;$.appendChild(q)}return{fragment:$,hasChanges:Z}}function o5(Q){let $=Q.cloneNode(!0);return $.classList.add("diff-block-removed"),$.style.position="relative",k2($,"Removed","var(--color-accent-red)"),$}function v8(Q){let $=Q.cloneNode(!0);return $.classList.add("diff-block-added"),$.style.position="relative",k2($,"Added","var(--color-accent-green)"),$}function s5(Q,$,Z,J){let q=!1,X=f8(Q,$),Y,G;if(J==="section"){let z=Q.element.querySelector(":scope > div:first-child"),_=$.querySelector(":scope > div:first-child");if(z&&_){if(t1(z,_,!1))q=!0}Y=Q.element.querySelector(":scope > div.mt-6, :scope > div:last-child"),G=$.querySelector(":scope > div.mt-6, :scope > div:last-child")}else Y=Q.element,G=$;if(!Y||!G)return q;for(let z of Z)if(z.kind==="matched"){let _=X.newMap.get(z.newBlock.element);if(_){if(z.newBlock.type==="mermaid"){if(e5(z.oldBlock.element,_))q=!0}else if(z.childMatches&&z.childMatches.length>0&&(z.newBlock.type==="table"||z.newBlock.type==="checklist")){if(t5(_,z.childMatches,z.newBlock.type))q=!0}else if(z.childMatches&&z.childMatches.length>0){if(s5(z.oldBlock,_,z.childMatches,z.newBlock.type))q=!0}else if(z.newBlock.type==="markdown"){if(n5(z.oldBlock.element,_))q=!0}else if(t1(z.oldBlock.element,_,!1))q=!0}}else if(z.kind==="removed"){q=!0;let _=o5(z.oldBlock.element),W=p8(Z,z,X.newMap),K=W?c8(G,W):null;G.insertBefore(_,K)}else if(z.kind==="added"){q=!0;let _=X.newMap.get(z.newBlock.element);if(_)_.classList.add("diff-block-added"),_.style.position="relative",k2(_,"Added","var(--color-accent-green)")}if(t1(Y,G,!0))q=!0;return q}function t5(Q,$,Z){let J=Z==="table"?Q.querySelector(":scope table > tbody"):Q;if(!J)return!1;let q=!1;J.innerHTML="";for(let X of $)if(X.kind==="removed"){q=!0;let Y=X.oldBlock.element.cloneNode(!0);Y.classList.add(Z==="table"?"diff-row-removed":"diff-item-removed"),J.appendChild(Y)}else if(X.kind==="added"){q=!0;let Y=X.newBlock.element.cloneNode(!0);Y.classList.add(Z==="table"?"diff-row-added":"diff-item-added"),J.appendChild(Y)}else{let Y=X.newBlock.element.cloneNode(!0);if(t1(X.oldBlock.element,Y,!1))q=!0;J.appendChild(Y)}return q}function f8(Q,$){let Z=new Map,J=Q.element.querySelectorAll("[data-md]"),q=$.querySelectorAll("[data-md]");return{newMap:{get(X){return h8($,X)}}}}function h8(Q,$){let Z=$.getAttribute("data-md");if(!Z)return null;let J=$.getAttribute("data-md-label"),q=$.getAttribute("data-md-title"),X=`[data-md="${Z}"]`;if(q)X+=`[data-md-title="${CSS.escape(q)}"]`;else if(J)X+=`[data-md-label="${CSS.escape(J)}"]`;let Y=Q.querySelectorAll(X);if(Y.length===1)return Y[0];let G=($.textContent||"").slice(0,100),z=null,_=-1;for(let W of Y){let K=(W.textContent||"").slice(0,100),H=0;for(let T=0;T<Math.min(G.length,K.length);T++)if(G[T]===K[T])H++;if(H>_)_=H,z=W}return z}function p8(Q,$,Z){let J=Q.indexOf($);for(let q=J+1;q<Q.length;q++){let X=Q[q];if((X.kind==="matched"||X.kind==="added")&&X.newBlock)return Z.get(X.newBlock.element)||null}return null}function c8(Q,$){let Z=$;while(Z&&Z.parentElement!==Q)Z=Z.parentElement;return Z}function n5(Q,$){let Z=Array.from(Q.children),J=Array.from($.children);if(Z.length===0&&J.length===0)return t1(Q,$,!1);let q=Z.map((H)=>H.tagName.toLowerCase()),X=J.map((H)=>H.tagName.toLowerCase()),Y=E1(q,X),G=[],z=0,_=0,W=0;while(z<Z.length||_<J.length)if(W<Y.length&&z<Z.length&&_<J.length&&q[z]===Y[W]&&X[_]===Y[W])G.push({kind:"matched",oldChild:Z[z],newChild:J[_]}),z++,_++,W++;else if(z<Z.length&&(W>=Y.length||q[z]!==Y[W]))G.push({kind:"removed",oldChild:Z[z]}),z++;else if(_<J.length)G.push({kind:"added",newChild:J[_]}),_++;let K=!1;while($.firstChild)$.removeChild($.firstChild);for(let H of G)if(H.kind==="matched"){let T=(H.oldChild.textContent||"").match(/\S+/g)||[],U=(H.newChild.textContent||"").match(/\S+/g)||[],L=E1(T,U),N=Math.max(T.length,U.length);if((N>0?1-L.length/N:0)>0.5){K=!0;let O=H.oldChild.cloneNode(!0);O.classList.add("diff-block-removed"),$.appendChild(O),H.newChild.classList.add("diff-block-added"),$.appendChild(H.newChild)}else{if(t1(H.oldChild,H.newChild,!1))K=!0;$.appendChild(H.newChild)}}else if(H.kind==="removed"){K=!0;let T=H.oldChild.cloneNode(!0);T.classList.add("diff-block-removed"),$.appendChild(T)}else K=!0,H.newChild.classList.add("diff-block-added"),$.appendChild(H.newChild);return K}function a5(Q,$){let Z=$?new Set(Array.from(Q.querySelectorAll("[data-md]"))):new Set,J=[],q=[],X=document.createTreeWalker(Q,NodeFilter.SHOW_TEXT,{acceptNode(G){let z=G.parentElement;if(!z)return NodeFilter.FILTER_REJECT;if(z.closest("svg, .select-none, [data-no-diff]"))return NodeFilter.FILTER_REJECT;if($){for(let _ of Z)if(_.contains(G))return NodeFilter.FILTER_REJECT}return NodeFilter.FILTER_ACCEPT}}),Y;while(Y=X.nextNode()){let z=(Y.nodeValue||"").match(/\S+|\s+/g);if(!z)continue;let _=0;for(let W of z)J.push(W),q.push({text:W,node:Y,offset:_}),_+=W.length}return{words:J,map:q}}function t1(Q,$,Z){let J=a5(Q,Z),q=a5($,Z);if(J.words.length===0&&q.words.length===0)return!1;let{oldOps:X,newOps:Y}=D2(J.words,q.words),G=X.some((N)=>N.type==="removed"),z=Y.some((N)=>N.type==="added");if(!G&&!z)return!1;let _=[],W=[];for(let N of X)if(N.type==="same")_.push(N.index);for(let N of Y)if(N.type==="same")W.push(N.index);let K=new Map;for(let N=0;N<_.length&&N<W.length;N++)K.set(_[N],W[N]);let H=[];{let N=[],P=-1;for(let O of X)if(O.type==="same"){if(N.length>0)H.push({text:N.join(""),anchorNewIdx:P>=0?K.get(P)??null:null}),N=[];P=O.index}else if(O.type==="removed")N.push(J.words[O.index]);if(N.length>0)H.push({text:N.join(""),anchorNewIdx:P>=0?K.get(P)??null:null})}let T=new Map,U=new Map;for(let N of Y){if(N.type!=="added")continue;let P=q.map[N.index];if(!P?.node.parentNode)continue;let O=T.get(P.node);if(!O)O=[],T.set(P.node,O);O.push({start:P.offset,end:P.offset+P.text.length})}for(let N of H)if(N.anchorNewIdx===null){if(q.map.length>0){let P=q.map[0].node,O=U.get(P);if(!O)O=[],U.set(P,O);O.push({offset:0,text:N.text})}}else{let P=q.map[N.anchorNewIdx];if(!P)continue;let O=U.get(P.node);if(!O)O=[],U.set(P.node,O);O.push({offset:P.offset+P.text.length,text:N.text})}let L=new Set([...T.keys(),...U.keys()]);for(let N of L)d8(N,T.get(N)||[],U.get(N)||[]);return!0}function d8(Q,$,Z){if(!Q.parentNode)return;let J=Q.nodeValue||"";$.sort((W,K)=>W.start-K.start);let q=[];for(let W of $){let K=q[q.length-1];if(K&&W.start<=K.end)K.end=Math.max(K.end,W.end);else q.push({...W})}Z.sort((W,K)=>W.offset-K.offset);let X=Q.parentNode,Y=document.createDocumentFragment(),G=0,z=0,_=0;while(G<=J.length){let W=z<q.length?q[z].start:1/0,K=_<Z.length?Z[_].offset:1/0,H=Math.min(W,K);if(H===1/0){if(G<J.length)Y.appendChild(document.createTextNode(J.slice(G)));break}let T=Math.max(H,G);if(T>G)Y.appendChild(document.createTextNode(J.slice(G,T))),G=T;while(_<Z.length&&Z[_].offset<=G){let U=document.createElement("span");U.className="diff-removed",U.textContent=Z[_].text,Y.appendChild(U),_++}if(z<q.length&&q[z].start<=G){let U=q[z],L=document.createElement("span");L.className="diff-added",L.textContent=J.slice(G,U.end),Y.appendChild(L),G=U.end,z++;while(_<Z.length&&Z[_].offset<=G){let N=document.createElement("span");N.className="diff-removed",N.textContent=Z[_].text,Y.appendChild(N),_++}}}while(_<Z.length){let W=document.createElement("span");W.className="diff-removed",W.textContent=Z[_].text,Y.appendChild(W),_++}X.replaceChild(Y,Q)}function e5(Q,$){let Z=(Q.getAttribute("data-md-source")||"").trim(),J=($.getAttribute("data-md-source")||"").trim();if(Z===J)return!1;let q=Z.split(`
|
|
86
|
-
`),
|
|
87
|
-
`),Y=E1(q,X),G=[],z=0,_=0,W=0;while(z<q.length||_<X.length)if(W<Y.length&&z<q.length&&_<X.length&&q[z]===Y[W]&&X[_]===Y[W])G.push({type:"same",line:q[z]}),z++,_++,W++;else if(z<q.length&&(W>=Y.length||q[z]!==Y[W]))G.push({type:"removed",line:q[z]}),z++;else if(_<X.length)G.push({type:"added",line:X[_]}),_++;let K=document.createElement("div");K.className="mt-2 bg-bg-code rounded-md overflow-hidden text-tiny font-mono",K.setAttribute("data-no-diff","true");for(let H of G){let T=document.createElement("div");if(T.className="px-3 py-0.5 whitespace-pre-wrap",H.type==="removed")T.classList.add("diff-removed"),T.textContent="- "+H.line;else if(H.type==="added")T.classList.add("diff-added"),T.textContent="+ "+H.line;else T.textContent=" "+H.line;K.appendChild(T)}return $.appendChild(K),!0}function k2(Q,$,Z){let J=document.createElement("span");J.className="diff-block-label",J.textContent=$,J.style.color=Z,J.style.backgroundColor=`color-mix(in srgb, ${Z} 12%, transparent)`,Q.appendChild(J)}import{jsxDEV as h}from"react/jsx-dev-runtime";function l8(Q,$,Z){let J=Q.find((Y)=>Y.revision===$),q=Q.find((Y)=>Y.revision===Z),X=new Set;for(let Y of J?.canvasFiles||[])X.add(Y.filename);for(let Y of q?.canvasFiles||[])X.add(Y.filename);return[...X].sort()}function Z3({initialLeft:Q,initialRight:$,sessionId:Z,onExit:J}){let[q,X]=_1(Q),[Y,G]=_1($),[z,_]=_1("unified"),[W,K]=_1(!0),[H,T]=_1(!1),{revisions:U}=r8(w1),L=e0(()=>l8(U,q,Y),[U,q,Y]),[N,P]=_1(()=>L[0]||"plan.jsx");m1(()=>{if(!L.includes(N))P(L[0]||"plan.jsx")},[L,N]);let O=e0(()=>{return U.find((M)=>M.revision===q)?.canvasFiles.some((M)=>M.filename===N)??!1},[U,q,N]),w=e0(()=>{return U.find((M)=>M.revision===Y)?.canvasFiles.some((M)=>M.filename===N)??!1},[U,Y,N]);return h("div",{className:"flex flex-col h-screen",children:[h("div",{className:"flex items-center justify-between px-6 py-3 border-b border-border-subtle bg-bg-surface flex-shrink-0",children:[h("div",{className:"flex items-center gap-3",children:[h("span",{className:"text-[13px] font-body font-medium text-text-primary",children:"Compare"},void 0,!1,void 0,this),h(P0,{value:q,onChange:X,accent:"red"},void 0,!1,void 0,this),h("span",{className:"text-text-tertiary text-[13px]",children:"→"},void 0,!1,void 0,this),h(P0,{value:Y,onChange:G,accent:"green"},void 0,!1,void 0,this),H&&!W&&h("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),h("div",{className:"flex items-center gap-4",children:[h("div",{className:"flex items-center bg-bg-elevated rounded-md p-0.5",children:[h("button",{onClick:()=>_("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),h("button",{onClick:()=>_("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"&&h(i8,{},void 0,!1,void 0,this),h("button",{onClick:J,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),L.length>1&&h("div",{className:"flex items-center gap-1 px-6 py-2 border-b border-border-subtle bg-bg-surface flex-shrink-0 overflow-x-auto",children:L.map((S)=>{let M=S.replace(/\.jsx$/,""),b=S===N,V=U.find((f)=>f.revision===q)?.canvasFiles.some((f)=>f.filename===S),v=U.find((f)=>f.revision===Y)?.canvasFiles.some((f)=>f.filename===S),p=!V?" (added)":!v?" (removed)":"";return h("button",{onClick:()=>P(S),className:`text-[12px] font-body px-3 py-1 rounded-md transition-colors whitespace-nowrap ${b?"bg-bg-elevated text-text-primary font-medium":"text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated"}`,children:[M,p&&h("span",{className:`ml-1 text-[10px] ${!V?"text-accent-green":"text-accent-red"}`,children:p},void 0,!1,void 0,this)]},S,!0,void 0,this)})},void 0,!1,void 0,this),!O||!w?h("div",{className:"flex-1 flex items-center justify-center",children:h("div",{className:"text-center text-text-tertiary font-body",children:[h("div",{className:"text-lg mb-2",children:!O?"New file":"Removed file"},void 0,!1,void 0,this),h("div",{className:"text-[13px]",children:[N.replace(/\.jsx$/,"")," ",!O?"was added":"was removed"," in this revision"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this):z==="unified"?h(a8,{sessionId:Z,leftRev:q,rightRev:Y,filename:N,onDiffResult:(S,M)=>{T(S),K(M)}},`unified-${q}-${Y}-${N}`,!1,void 0,this):h(o8,{sessionId:Z,leftRev:q,rightRev:Y,filename:N,onDiffResult:(S,M)=>{T(S),K(M)}},`sbs-${q}-${Y}-${N}`,!1,void 0,this)]},void 0,!0,void 0,this)}function i8(){let[Q,$]=_1(!0);return m1(()=>{return document.documentElement.dataset.syncScroll=Q?"1":"0",()=>{delete document.documentElement.dataset.syncScroll}},[Q]),h("label",{className:"flex items-center gap-1.5 cursor-pointer select-none",children:[h("input",{type:"checkbox",checked:Q,onChange:(Z)=>$(Z.target.checked),className:"accent-accent-amber w-3.5 h-3.5"},void 0,!1,void 0,this),h("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 a8({sessionId:Q,leftRev:$,rightRev:Z,filename:J,onDiffResult:q}){let X=V1(null),Y=V1(null),G=V1(null),[z,_]=_1(!1),[W,K]=_1(!1),[H,T]=_1(!1),[U,L]=_1(null),[N,P]=_1(!1),{annotations:O}=Y1(),w=O.filter((M)=>!M.filePath&&(!M.canvasFile||M.canvasFile===J)),{popovers:S}=i1({containerRef:G,restoreKey:H,restoreAnnotations:w,extractContext:(M)=>c1(M,G.current)});return m1(()=>{if(H||U)return;let M=setTimeout(()=>{console.warn("[unified-diff] still loading after 10s",{leftReady:z,rightReady:W,oldRef:!!X.current,newRef:!!Y.current}),P(!0)},1e4);return()=>clearTimeout(M)},[H,U,z,W]),m1(()=>{if(!z||!W||H)return;if(!X.current||!Y.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!X.current||!Y.current||!G.current){console.warn("[unified-diff] refs lost between rAF frames",{old:!!X.current,new:!!Y.current,unified:!!G.current});return}try{let M=z0(X.current),b=z0(Y.current),V=b0(M,b),{fragment:v,hasChanges:p}=n0(V);G.current.innerHTML="",G.current.appendChild(v),T(!0),q(!0,p)}catch(M){console.error("[unified-diff] diff computation failed",M),L(M instanceof Error?M.message:String(M))}})})},[z,W,H]),h("div",{className:"flex-1 min-h-0 overflow-y-auto",children:[!H&&!U&&h("div",{style:{position:"absolute",left:-9999,visibility:"hidden",pointerEvents:"none",width:720},children:[h(R1,{ref:X,sessionId:Q,revision:$,filename:J,onReady:()=>_(!0),onError:(M)=>L(`Rev ${$}: ${M}`)},void 0,!1,void 0,this),h(R1,{ref:Y,sessionId:Q,revision:Z,filename:J,onReady:()=>K(!0),onError:(M)=>L(`Rev ${Z}: ${M}`)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),h("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:[!H&&!U&&h("div",{className:"flex flex-col items-center justify-center h-64 text-text-tertiary font-body text-body gap-2",children:[h("span",{children:"Loading..."},void 0,!1,void 0,this),N&&h("span",{className:"text-[11px]",children:"Taking longer than expected — check Network tab for pending requests"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),U&&h("div",{className:"bg-accent-red-muted rounded-lg p-5 mt-8",children:[h("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Failed to load revision"},void 0,!1,void 0,this),h("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:U},void 0,!1,void 0,this)]},void 0,!0,void 0,this),h("div",{ref:G},void 0,!1,void 0,this)]},void 0,!0,void 0,this),S]},void 0,!0,void 0,this)}function o8({sessionId:Q,leftRev:$,rightRev:Z,filename:J,onDiffResult:q}){let X=V1(null),Y=V1(null),[G,z]=_1(!1),[_,W]=_1(!1),[K,H]=_1(!1),T=V1(null),U=V1(null),L=V1(null),N=V1(!1),P=Q3(()=>z(!0),[]),O=Q3(()=>W(!0),[]),{annotations:w}=Y1(),S=w.filter((b)=>!b.filePath&&(!b.canvasFile||b.canvasFile===J)),{popovers:M}=i1({containerRef:T,restoreKey:K,restoreAnnotations:S,extractContext:(b)=>c1(b,T.current)});return m1(()=>{if(!G||!_||K)return;if(!X.current||!Y.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!X.current||!Y.current)return;let b=t0(X.current,Y.current);H(!0),q(!0,b)})})},[G,_,K]),m1(()=>{let b=U.current,V=L.current;if(!b||!V)return;let v=(R,k)=>{if(document.documentElement.dataset.syncScroll==="0")return;if(N.current)return;N.current=!0;let u=R.scrollHeight-R.clientHeight,I=k.scrollHeight-k.clientHeight;if(u>0&&I>0)k.scrollTop=R.scrollTop/u*I;requestAnimationFrame(()=>{N.current=!1})},p=()=>v(b,V),f=()=>v(V,b);return b.addEventListener("scroll",p),V.addEventListener("scroll",f),()=>{b.removeEventListener("scroll",p),V.removeEventListener("scroll",f)}},[]),h("div",{ref:T,className:"flex flex-1 min-h-0",children:[h("div",{ref:U,className:"w-1/2 overflow-y-auto border-r border-border-subtle",children:h("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:h(R1,{ref:X,sessionId:Q,revision:$,filename:J,onReady:P},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),h("div",{ref:L,className:"w-1/2 overflow-y-auto",children:h("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:h(R1,{ref:Y,sessionId:Q,revision:Z,filename:J,onReady:O},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),M]},void 0,!0,void 0,this)}var R1=$3.memo($3.forwardRef(({sessionId:Q,revision:$,filename:Z,onReady:J,onError:q},X)=>{let[Y,G]=_1(null),[z,_]=_1(null),[W,K]=_1(!0);m1(()=>{K(!0),_(null);let T=Z.replace(/\.jsx$/,".js");import(`/api/session/${Q}/canvas/${encodeURIComponent(T)}?rev=${$}&t=${Date.now()}`).then((U)=>{if(!U.default){_("Module has no default export"),K(!1),q?.("Module has no default export");return}G(()=>U.default),K(!1)}).catch((U)=>{_(U.message),K(!1),q?.(U.message)})},[Q,$,Z]),m1(()=>{if(!Y)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{J()})})},[Y]);let H=e0(()=>Y?h(Y,{},void 0,!1,void 0,this):null,[Y]);if(W)return h("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(z)return h("div",{className:"bg-accent-red-muted rounded-lg p-5",children:[h("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Error"},void 0,!1,void 0,this),h("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:z},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(!Y)return h("div",{className:"text-text-tertiary text-center py-8 font-body text-body",children:"No canvas loaded"},void 0,!1,void 0,this);return h("div",{ref:X,children:H},void 0,!1,void 0,this)}));import{useState as D1,useContext as E2,useMemo as s8,useRef as w0,useEffect as J3,useCallback as q3}from"react";import{SessionContext as t8}from"#canvas/runtime";import{jsxDEV as c}from"react/jsx-dev-runtime";function m2(Q,$){if(!Q)return[];return Q.canvasFiles.map((Z)=>{if(!Z.diffStats)return{filename:Z.filename,status:"new"};if(Z.diffStats.added===0&&Z.diffStats.removed===0)return{filename:Z.filename,status:"unchanged",diffStats:Z.diffStats};return{filename:Z.filename,status:"changed",diffStats:Z.diffStats}})}function Y3(Q){return Q.filter(($)=>$.status!=="unchanged").map(($)=>$.filename)}function X3({revision:Q,responseBanner:$}){let{setActiveView:Z}=E2(I1),{revisions:J}=E2(w1),q=J.find((_)=>_.revision===Q),X=J.find((_)=>_.revision===Q-1),Y=s8(()=>m2(q,X),[q,X]),G=Y.filter((_)=>_.status!=="unchanged"),z=Y.filter((_)=>_.status==="unchanged");return c("div",{className:"max-w-[720px] mx-auto px-6 pt-12 pb-32",children:[$,G.map((_)=>c(e8,{change:_,revision:Q,previousRevision:X?.revision,onOpenTab:()=>Z({type:"canvas",filename:_.filename})},_.filename,!1,void 0,this)),z.length>0&&c("div",{className:"mt-8 border-t border-border-subtle pt-4",children:[c("div",{className:"text-[11px] font-body font-medium uppercase tracking-widest text-text-tertiary mb-3",children:"Unchanged"},void 0,!1,void 0,this),z.map((_)=>c(q4,{change:_,revision:Q,onOpenTab:()=>Z({type:"canvas",filename:_.filename})},_.filename,!1,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function n8({mode:Q,onChange:$,showDiff:Z}){if(!Z)return null;return c("div",{className:"flex items-center bg-bg-elevated rounded-md p-0.5",children:["rendered","unified","side-by-side"].map((J)=>c("button",{onClick:()=>$(J),className:`text-[10px] font-body px-2 py-0.5 rounded transition-colors ${Q===J?"bg-bg-surface text-text-primary font-medium shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:J==="rendered"?"Full":J==="unified"?"Unified":"Split"},J,!1,void 0,this))},void 0,!1,void 0,this)}function e8({change:Q,revision:$,previousRevision:Z,onOpenTab:J}){let q=Q.filename.replace(/\.jsx$/,""),X=Q.status==="new",Y=Q.diffStats,G=Q.status==="changed"&&Z!=null,[z,_]=D1("rendered");return c("div",{className:"mb-8",children:[c("div",{className:"flex items-center gap-2 mb-3 pb-2 border-b border-border-subtle",children:[c("span",{className:`text-[11px] font-mono px-1.5 py-0.5 rounded ${X?"bg-accent-green/10 text-accent-green border border-accent-green/20":"bg-accent-amber/10 text-accent-amber border border-accent-amber/20"}`,children:X?"new":"modified"},void 0,!1,void 0,this),c("span",{className:"text-[14px] font-body font-medium text-text-primary",children:q},void 0,!1,void 0,this),Y&&(Y.added>0||Y.removed>0)&&c("span",{className:"text-[11px] font-mono text-text-tertiary",children:[c("span",{className:"text-accent-green",children:["+",Y.added]},void 0,!0,void 0,this)," ",c("span",{className:"text-accent-red",children:["-",Y.removed]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),c(n8,{mode:z,onChange:_,showDiff:G},void 0,!1,void 0,this),c("button",{onClick:J,className:`${G?"":"ml-auto"} text-[11px] font-body font-medium text-accent-blue hover:text-accent-blue/80 transition-colors`,children:"Open in tab"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z==="rendered"?c("div",{"data-canvas-file":Q.filename,children:c(B0,{revision:$,filename:Q.filename},void 0,!1,void 0,this)},void 0,!1,void 0,this):G&&Z!=null?c($4,{filename:Q.filename,leftRev:Z,rightRev:$,mode:z},`${z}-${$}-${Z}`,!1,void 0,this):null]},void 0,!0,void 0,this)}function $4({filename:Q,leftRev:$,rightRev:Z,mode:J}){let q=E2(t8);if(J==="unified")return c(Q4,{sessionId:q,filename:Q,leftRev:$,rightRev:Z},void 0,!1,void 0,this);return c(Z4,{sessionId:q,filename:Q,leftRev:$,rightRev:Z},void 0,!1,void 0,this)}function Q4({sessionId:Q,filename:$,leftRev:Z,rightRev:J}){let q=w0(null),X=w0(null),Y=w0(null),[G,z]=D1(!1),[_,W]=D1(!1),[K,H]=D1(!1),[T,U]=D1(null);return J3(()=>{if(!G||!_||K)return;if(!q.current||!X.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!q.current||!X.current||!Y.current)return;try{let L=z0(q.current),N=z0(X.current),P=b0(L,N),{fragment:O}=n0(P);Y.current.innerHTML="",Y.current.appendChild(O),H(!0)}catch(L){U(L instanceof Error?L.message:String(L))}})})},[G,_,K]),c("div",{children:[!K&&!T&&c("div",{style:{position:"absolute",left:-9999,visibility:"hidden",pointerEvents:"none",width:720},children:[c(R1,{ref:q,sessionId:Q,revision:Z,filename:$,onReady:()=>z(!0),onError:(L)=>U(L)},void 0,!1,void 0,this),c(R1,{ref:X,sessionId:Q,revision:J,filename:$,onReady:()=>W(!0),onError:(L)=>U(L)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!K&&!T&&c("div",{className:"flex items-center justify-center h-24 text-text-tertiary font-body text-[13px]",children:"Computing diff..."},void 0,!1,void 0,this),T&&c("div",{className:"text-accent-red text-[13px] font-body p-3 bg-accent-red-muted rounded-lg",children:T},void 0,!1,void 0,this),c("div",{ref:Y},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Z4({sessionId:Q,filename:$,leftRev:Z,rightRev:J}){let q=w0(null),X=w0(null),[Y,G]=D1(!1),[z,_]=D1(!1),[W,K]=D1(!1),H=q3(()=>G(!0),[]),T=q3(()=>_(!0),[]);return J3(()=>{if(!Y||!z||W)return;if(!q.current||!X.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!q.current||!X.current)return;t0(q.current,X.current),K(!0)})})},[Y,z,W]),c("div",{className:"flex gap-0 border-y border-border-subtle overflow-hidden w-screen relative left-1/2 -translate-x-1/2",children:[c("div",{className:"w-1/2 border-r border-border-subtle",children:[c("div",{className:"px-2 py-1 text-[10px] font-body font-medium text-text-tertiary bg-bg-elevated border-b border-border-subtle",children:["Rev ",Z]},void 0,!0,void 0,this),c("div",{className:"px-6 py-4 max-w-[600px] mx-auto",children:c(R1,{ref:q,sessionId:Q,revision:Z,filename:$,onReady:H},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),c("div",{className:"w-1/2",children:[c("div",{className:"px-2 py-1 text-[10px] font-body font-medium text-text-tertiary bg-bg-elevated border-b border-border-subtle",children:["Rev ",J]},void 0,!0,void 0,this),c("div",{className:"px-6 py-4 max-w-[600px] mx-auto",children:c(R1,{ref:X,sessionId:Q,revision:J,filename:$,onReady:T},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function q4({change:Q,revision:$,onOpenTab:Z}){let[J,q]=D1(!1),X=Q.filename.replace(/\.jsx$/,"");return c("div",{className:"mb-2",children:[c("div",{className:"flex items-center gap-2 py-1.5",children:[c("button",{onClick:()=>q(!J),className:"text-text-tertiary hover:text-text-secondary transition-colors",children:c("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",className:`transition-transform duration-150 ${J?"rotate-90":""}`,children:c("path",{d:"M3.5 2L6.5 5L3.5 8",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),c("span",{className:"text-[13px] font-body text-text-secondary",children:X},void 0,!1,void 0,this),c("button",{onClick:Z,className:"ml-auto text-[11px] font-body text-text-tertiary hover:text-accent-blue transition-colors",children:"Open in tab"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),J&&c("div",{className:"ml-5 mt-1 mb-3","data-canvas-file":Q.filename,children:c(B0,{revision:$,filename:Q.filename},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{useState as $2,useEffect as J4,useCallback as x2}from"react";import{jsxDEV as t}from"react/jsx-dev-runtime";function z3({sessionId:Q,revision:$,open:Z,shareEnabled:J,existingShares:q,onClose:X,onShareCreated:Y,onShareRevoked:G}){let[z,_]=$2(!1),[W,K]=$2(!1),[H,T]=$2(null),[U,L]=$2(!1),N=q.find((S)=>S.revision===$);J4(()=>{if(!Z)_(!1),K(!1),T(null),L(!1)},[Z]);let P=x2(async()=>{_(!0),T(null);try{let S=await fetch(`/api/session/${Q}/revision/${$}/share`,{method:"POST"}),M=await S.json();if(!S.ok||!M.ok)throw Error(M.error||`HTTP ${S.status}`);Y(M.share)}catch(S){T(S.message||String(S))}finally{_(!1)}},[Q,$,Y]),O=x2(async(S)=>{if(!window.confirm("Revoke this share link? Reviewers will no longer be able to view or comment."))return;K(!0),T(null);try{let M=await fetch(`/api/session/${Q}/shares/${S}/revoke`,{method:"POST"}),b=await M.json();if(!M.ok||!b.ok)throw Error(b.error||`HTTP ${M.status}`);G(S)}catch(M){T(M.message||String(M))}finally{K(!1)}},[Q,G]),w=x2((S)=>{navigator.clipboard.writeText(S).then(()=>{L(!0),setTimeout(()=>L(!1),1500)})},[]);if(!Z)return null;return t("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:X,children:t("div",{className:"bg-bg-surface border border-border-medium rounded-lg shadow-xl w-full max-w-md mx-4 p-5",onClick:(S)=>S.stopPropagation(),children:[t("div",{className:"flex items-center justify-between mb-3",children:[t("h2",{className:"text-sm font-medium text-text-primary font-body",children:"Share this revision"},void 0,!1,void 0,this),t("button",{onClick:X,className:"w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",children:t("span",{className:"text-xs",children:"✕"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!J?t("div",{className:"text-[13px] text-text-secondary font-body space-y-2",children:[t("p",{children:"Canvas sharing is not configured."},void 0,!1,void 0,this),t("p",{className:"text-text-tertiary",children:["Set ",t("code",{className:"px-1 py-0.5 rounded bg-bg-elevated text-text-primary text-[11px]",children:"CANVAS_SHARE_ENDPOINT"},void 0,!1,void 0,this)," to the URL of a deployed"," ",t("code",{className:"px-1 py-0.5 rounded bg-bg-elevated text-text-primary text-[11px]",children:"canvas-share"},void 0,!1,void 0,this)," worker and restart the daemon."]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):N?t("div",{className:"space-y-3",children:[t("p",{className:"text-[13px] text-text-secondary font-body",children:"This revision is shared:"},void 0,!1,void 0,this),t("div",{className:"flex gap-2",children:[t("input",{type:"text",readOnly:!0,value:N.url,className:"flex-1 px-2 py-1.5 text-[12px] font-mono bg-bg-input border border-border-medium rounded text-text-primary",onFocus:(S)=>S.currentTarget.select()},void 0,!1,void 0,this),t("button",{onClick:()=>w(N.url),className:"px-3 py-1.5 text-[12px] font-body font-medium rounded bg-accent-blue text-white hover:opacity-90 transition-opacity whitespace-nowrap",children:U?"Copied!":"Copy"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),N.expiresAt&&t("p",{className:"text-[11px] text-text-tertiary font-body",children:["Expires ",new Date(N.expiresAt).toLocaleDateString(),"."]},void 0,!0,void 0,this),t("p",{className:"text-[11px] text-text-tertiary font-body",children:"Anyone with this link can view and leave feedback. Reviewer feedback will appear in your annotation sidebar within seconds."},void 0,!1,void 0,this),t("div",{className:"flex items-center justify-between pt-1",children:[t("button",{onClick:P,disabled:z||W,className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body underline disabled:opacity-50",children:z?"Creating...":"Create a new link"},void 0,!1,void 0,this),N.ownerToken&&t("button",{onClick:()=>O(N.shareId),disabled:z||W,className:"text-[11px] text-accent-red hover:opacity-80 font-body underline disabled:opacity-50",children:W?"Revoking...":"Revoke link"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):t("div",{className:"space-y-3",children:[t("p",{className:"text-[13px] text-text-secondary font-body",children:"Create a public link to this revision. Anyone with the link can view the canvas and leave feedback. Reviewer feedback will sync back here automatically."},void 0,!1,void 0,this),t("button",{onClick:P,disabled:z,className:"w-full px-3 py-2 text-[13px] font-body font-medium rounded bg-accent-blue text-white hover:opacity-90 transition-opacity disabled:opacity-50",children:z?"Creating share link...":"Create share link"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),H&&t("div",{className:"mt-3 px-3 py-2 rounded bg-accent-red/10 border border-accent-red/20 text-[12px] text-accent-red font-body",children:H},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function _3({onClick:Q,title:$="Share this revision",hasShare:Z}){return t("button",{onClick:Q,className:`group p-1.5 transition-colors ${Z?"text-accent-blue hover:opacity-80":"text-text-tertiary hover:text-text-secondary"}`,title:$,children:t("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t("circle",{cx:"18",cy:"5",r:"3"},void 0,!1,void 0,this),t("circle",{cx:"6",cy:"12",r:"3"},void 0,!1,void 0,this),t("circle",{cx:"18",cy:"19",r:"3"},void 0,!1,void 0,this),t("line",{x1:"8.59",y1:"13.51",x2:"15.42",y2:"17.49"},void 0,!1,void 0,this),t("line",{x1:"15.41",y1:"6.51",x2:"8.59",y2:"10.49"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}import{useState as Y4,useEffect as X4,useRef as z4}from"react";import{jsxDEV as L1}from"react/jsx-dev-runtime";function G3({open:Q,onClose:$,onSubmit:Z}){let[J,q]=Y4(""),X=z4(null);if(X4(()=>{if(Q)q(""),setTimeout(()=>X.current?.focus(),50)},[Q]),!Q)return null;let Y=J.trim(),G=Y.length>=1&&Y.length<=80,z=()=>{if(!G)return;Z(Y)};return L1("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:$,children:L1("div",{className:"bg-bg-surface border border-border-medium rounded-lg shadow-xl w-full max-w-md mx-4 p-5",onClick:(_)=>_.stopPropagation(),children:[L1("div",{className:"flex items-center justify-between mb-3",children:[L1("h2",{className:"text-sm font-medium text-text-primary font-body",children:"Your name"},void 0,!1,void 0,this),L1("button",{onClick:$,className:"w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",children:L1("span",{className:"text-xs",children:"✕"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),L1("p",{className:"text-[13px] text-text-secondary font-body mb-3 leading-relaxed",children:"Before you leave feedback, please enter a name so the canvas author knows who reviewed it. This is stored locally in your browser."},void 0,!1,void 0,this),L1("input",{ref:X,type:"text",value:J,onChange:(_)=>q(_.target.value),onKeyDown:(_)=>{if(_.key==="Enter")z()},maxLength:80,placeholder:"e.g. Alice",className:"w-full px-3 py-2 text-[13px] font-body bg-bg-input border border-border-medium rounded text-text-primary placeholder:text-text-disabled focus:outline-none focus:border-accent-blue"},void 0,!1,void 0,this),L1("div",{className:"flex justify-end gap-2 mt-4",children:[L1("button",{onClick:$,className:"px-3 py-1.5 text-[12px] font-body font-medium rounded text-text-secondary hover:text-text-primary hover:bg-bg-elevated transition-colors",children:"Cancel"},void 0,!1,void 0,this),L1("button",{onClick:z,disabled:!G,className:"px-3 py-1.5 text-[12px] font-body font-medium rounded bg-accent-blue text-white hover:opacity-90 transition-opacity disabled:opacity-50",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)}import{jsxDEV as F,Fragment as A0}from"react/jsx-dev-runtime";function U3(Q){let $=[];for(let Z of Q)for(let J of Z.annotations)$.push({...J,source:"remote",author:Z.author});return $}var I1=N3({activeView:{type:"overview"},setActiveView:()=>{},openFiles:[],closeFile:()=>{},canvasFiles:[]}),w1=N3({currentRevision:1,selectedRevision:1,revisions:[],setSelectedRevision:()=>{},isReadOnly:!1,compareRevision:null,setCompareRevision:()=>{},agentWatching:!1});function U4(Q){if(Q==="auto")return window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light";return Q}function H3(Q){document.documentElement.dataset.theme=U4(Q)}function F3(){let[Q,$]=$1(()=>{let q=localStorage.getItem("canvas-theme");if(q==="light"||q==="dark"||q==="auto")return q;return"auto"});return M1(()=>{if(H3(Q),Q!=="auto")return;let q=window.matchMedia("(prefers-color-scheme: dark)"),X=()=>H3("auto");return q.addEventListener("change",X),()=>q.removeEventListener("change",X)},[Q]),F("button",{onClick:()=>{let q=Q==="auto"?"light":Q==="light"?"dark":"auto";localStorage.setItem("canvas-theme",q),$(q)},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:{auto:"Theme: system (click for light)",light:"Theme: light (click for dark)",dark:"Theme: dark (click for system)"}[Q],children:Q==="auto"?F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[F("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2",ry:"2"},void 0,!1,void 0,this),F("line",{x1:"8",y1:"21",x2:"16",y2:"21"},void 0,!1,void 0,this),F("line",{x1:"12",y1:"17",x2:"12",y2:"21"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):Q==="dark"?F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:F("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):F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[F("circle",{cx:"12",cy:"12",r:"5"},void 0,!1,void 0,this),F("line",{x1:"12",y1:"1",x2:"12",y2:"3"},void 0,!1,void 0,this),F("line",{x1:"12",y1:"21",x2:"12",y2:"23"},void 0,!1,void 0,this),F("line",{x1:"4.22",y1:"4.22",x2:"5.64",y2:"5.64"},void 0,!1,void 0,this),F("line",{x1:"18.36",y1:"18.36",x2:"19.78",y2:"19.78"},void 0,!1,void 0,this),F("line",{x1:"1",y1:"12",x2:"3",y2:"12"},void 0,!1,void 0,this),F("line",{x1:"21",y1:"12",x2:"23",y2:"12"},void 0,!1,void 0,this),F("line",{x1:"4.22",y1:"19.78",x2:"5.64",y2:"18.36"},void 0,!1,void 0,this),F("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)},void 0,!1,void 0,this)}function B3(){let{currentRevision:Q,selectedRevision:$,revisions:Z,setSelectedRevision:J,setCompareRevision:q}=x1.useContext(w1);if(Z.length<=1){let G=Z[0]?.label||`Round ${Q}`;return F("span",{className:"text-[11px] text-text-tertiary font-body",children:G},void 0,!1,void 0,this)}return F("div",{className:"flex flex-col gap-1",children:[F(P0,{value:$,onChange:J,accent:$===Q?"default":"amber"},void 0,!1,void 0,this),F("button",{onClick:()=>{let Y;if($===Q)Y=[...Z].reverse().find((z)=>z.revision<Q)?.revision??Math.max(1,Q-1);else Y=$;q({left:Y,right:Q})},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 H4(){let Q=Z1.isShared?Z1.shareId:Z1.sessionId,$=Z1.isShared,[Z,J]=$1(1),[q,X]=$1(1),[Y,G]=$1([]),[z,_]=$1(null),[W,K]=$1(!1),[H,T]=$1(!1),[U,L]=$1(!1),[N,P]=$1([]),[O,w]=$1({type:"overview"}),[S,M]=$1([]),b=u1(null),[V,v]=$1(),[p,f]=$1(!1),[R,k]=$1(!1),[u,I]=$1(!1),[B,D]=$1(!1),[x,A]=$1([]),[m,d]=$1(!1),[Q1,i]=$1(new Map),[E,l]=$1(!1),[j,g]=$1(null),[e,K1]=$1(null);M1(()=>{if(!e)return;let C=setTimeout(()=>K1(null),4000);return()=>clearTimeout(C)},[e]),M1(()=>{let C=["Agent Canvas"];if(V){let a=V.replace(/\/+$/,"").split("/");C.push(a[a.length-1]||Q)}else if(Q)C.push(Q);if(O.type==="file")C.push(O.path.split("/").pop()||O.path);else if(O.type==="overview")C.push("Overview");else if(O.type==="canvas"&&N.length>1&&O.filename)C.push(O.filename.replace(/\.jsx$/,""));else if(z)C.push("Compare");document.title=C.join(" — ")},[Q,V,O,z]);let g1=u1(new Map),A1=Y.find((C)=>C.revision===q),n1=q!==Z||!!A1?.hasFeedback,u2=j0((C)=>{let a=O.type==="overview"?"overview":O.type==="canvas"?`canvas:${O.filename}`:`file:${O.path}`;if(g1.current.set(a,window.scrollY),w(C),C.type==="file")M((n)=>n.includes(C.path)?n:[...n,C.path])},[O]),L3=j0((C)=>{g1.current.delete(`file:${C}`),M((a)=>a.filter((n)=>n!==C)),w((a)=>{if(a.type==="file"&&a.path===C)return N.length>1?{type:"overview"}:{type:"canvas",filename:N[0]||""};return a})},[N]);_4(()=>{let C=O.type==="overview"?"overview":O.type==="canvas"?`canvas:${O.filename}`:`file:${O.path}`;window.scrollTo(0,g1.current.get(C)||0)},[O]),M1(()=>{if(!Q)return;fetch(z5()).then((C)=>C.json()).then((C)=>{if(C.currentRevision)J(C.currentRevision),X(C.currentRevision),G(C.revisions||[]);if(C.canvasFiles){let a=C.canvasFiles.sort();P(a),w((n)=>{if(n.type==="overview")return a.length>1?n:{type:"canvas",filename:a[0]||""};if(n.type==="canvas"&&(!n.filename||!a.includes(n.filename)))return{type:"canvas",filename:a[0]||""};return n})}if(C.projectRoot)v(C.projectRoot);if(Array.isArray(C.shares))A(C.shares);d(!!C.shareEnabled)}).catch(()=>{})},[Q]),M1(()=>{if(!Q||!q||$)return;fetch(`/api/session/${Q}/revision/${q}/remote-feedback`).then((C)=>C.json()).then((C)=>{if(!Array.isArray(C.entries))return;let a=U3(C.entries);i((n)=>{let y1=new Map(n);return y1.set(q,a),y1})}).catch(()=>{})},[Q,q,$]),M1(()=>{if(!Q)return;if(!W5){K(!0);return}let C=null,a=()=>{let n=window.location.protocol==="https:"?"wss:":"ws:",y1=new WebSocket(`${n}//${window.location.host}/ws/session/${Q}`);b.current=y1,y1.onopen=()=>K(!0),y1.onclose=()=>{K(!1),C=setTimeout(a,2000)},y1.onmessage=(g2)=>{try{let G1=JSON.parse(g2.data);if(G1.type==="plan-updated"){if(J(G1.currentRevision),X(G1.currentRevision),_(null),G1.revisions){let e1=G1.revisions;G(e1);let _0=e1.find((v1)=>v1.revision===G1.currentRevision);if(_0?.canvasFiles){let v1=_0.canvasFiles.map((K0)=>K0.filename).sort();P(v1);let q2=e1.find((K0)=>K0.revision===G1.currentRevision-1),G0=m2(_0,q2),$0=Y3(G0);if($0.length===1)w({type:"canvas",filename:$0[0]});else if($0.length>1||v1.length>1)w({type:"overview"});else w({type:"canvas",filename:v1[0]||""})}}}if(G1.type==="revision-updated"){if(G1.revisions)G(G1.revisions)}if(G1.type==="watcher-status")T(!!G1.watching);if(G1.type==="remote-feedback"){let e1=G1.revision,_0=G1.entries||[],v1=U3(_0);i((q2)=>{let G0=new Map(q2),$0=G0.get(e1)||[],K0=new Set($0.map((J2)=>J2.id)),M3=[...$0,...v1.filter((J2)=>!K0.has(J2.id))];return G0.set(e1,M3),G0})}}catch{}}};return a(),()=>{if(C)clearTimeout(C);b.current?.close()}},[Q]);let Q2=j0(async(C,a)=>{try{let n=localStorage.getItem(`canvas:${Q}:rev:${q}`),y1=[];if(n)try{y1=(JSON.parse(n).annotations||[]).filter((G1)=>G1.source!=="remote")}catch{}await H5({author:a,revision:q,annotations:y1,generalNote:C}),L(!1),K1({kind:"success",message:"Feedback submitted. The canvas author will see it shortly."})}catch(n){K1({kind:"error",message:`Failed to submit feedback: ${n.message||n}`})}},[Q,q]),Z2=j0(async(C)=>{if($){let a=F2();if(!a){g(C),l(!0);return}await Q2(C,a);return}if(b.current?.readyState===WebSocket.OPEN)b.current.send(JSON.stringify({type:"submit",feedback:C})),L(!1)},[$,Q2]);if(!Q)return F("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 F(O3.Provider,{value:Q,children:F(w1.Provider,{value:{currentRevision:Z,selectedRevision:q,revisions:Y,setSelectedRevision:X,isReadOnly:n1,compareRevision:z,setCompareRevision:_,agentWatching:H},children:F(q5,{sessionId:Q,revision:q,isReadOnly:n1,remoteAnnotations:Q1.get(q),children:F(I1.Provider,{value:{activeView:O,setActiveView:u2,openFiles:S,closeFile:L3,canvasFiles:N},children:F(K4.Provider,{value:{setActiveView:u2},children:F("div",{className:"min-h-screen bg-bg-base",children:[F(W4,{sessionId:Q,projectRoot:V,connected:W,onMobileSidebar:()=>f(!p),collapsed:R,onToggle:()=>k((C)=>!C)},void 0,!1,void 0,this),F(T4,{collapsed:u,onToggle:()=>I((C)=>!C),children:F(I2,{onPreview:()=>L(!0),onSubmit:Z2},void 0,!1,void 0,this)},void 0,!1,void 0,this),z!==null?F("div",{className:`${R?"lg:ml-0":"lg:ml-60"} ${u?"lg:mr-0":"lg:mr-[var(--sidebar-width,320px)]"} transition-[margin] duration-200`,children:F(Z3,{initialLeft:z.left,initialRight:z.right,sessionId:Q,onExit:()=>_(null)},void 0,!1,void 0,this)},void 0,!1,void 0,this):F("div",{className:`relative ${R?"lg:ml-0":"lg:ml-60"} ${u?"lg:mr-0":"lg:mr-[var(--sidebar-width,320px)]"} transition-[margin] duration-200`,id:"plan-scroll-container",children:[F("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:[F("div",{className:"flex items-center gap-2",children:[!$&&F(R2,{currentSessionId:Q,projectRoot:V},void 0,!1,void 0,this),$&&F("span",{className:"text-[11px] text-text-tertiary font-body",children:"Shared canvas"},void 0,!1,void 0,this),!$&&F("span",{className:`w-1.5 h-1.5 rounded-full ${W?"bg-accent-green":"bg-accent-red"}`},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("div",{className:"flex items-center gap-1",children:[F(B3,{},void 0,!1,void 0,this),F("button",{onClick:()=>f(!p),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:F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:F("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),F(F3,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),F(N4,{},void 0,!1,void 0,this),O.type==="overview"&&F(X3,{revision:q,responseBanner:A1?.response?F(W3,{markdown:A1.response},void 0,!1,void 0,this):void 0},void 0,!1,void 0,this),O.type==="canvas"&&N.includes(O.filename)&&F("div",{className:"relative max-w-[720px] mx-auto px-6 pt-12 pb-32",children:[m&&F("div",{className:"absolute top-3 right-12 z-10",children:F(_3,{onClick:()=>D(!0),hasShare:x.some((C)=>C.revision===q),title:x.some((C)=>C.revision===q)?"Manage share link":"Share this revision"},void 0,!1,void 0,this)},void 0,!1,void 0,this),F("button",{onClick:()=>{let C=document.querySelector(`[data-canvas-file="${O.filename}"] .plan-content`);if(!C)return;let a=p5(C);navigator.clipboard.writeText(a).then(()=>{let n=document.getElementById("export-md-btn");if(n)n.setAttribute("data-copied","true"),setTimeout(()=>{n.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:[F("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:[F("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"},void 0,!1,void 0,this),F("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),F("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:F("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),N.length<=1&&A1?.response&&F(W3,{markdown:A1.response},void 0,!1,void 0,this),F("div",{"data-canvas-file":O.filename,children:F(B0,{revision:q,filename:O.filename},O.filename,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),S.map((C)=>F("div",{style:{display:O.type==="file"&&O.path===C?void 0:"none"},children:F(g5,{path:C},void 0,!1,void 0,this)},C,!1,void 0,this))]},void 0,!0,void 0,this),p&&F("div",{className:"lg:hidden fixed inset-0 z-40 flex",children:[F("div",{className:"flex-1",onClick:()=>f(!1)},void 0,!1,void 0,this),F("div",{className:"w-80 max-w-[85vw] bg-bg-surface border-l border-border-subtle flex flex-col shadow-lg",children:[F("div",{className:"flex items-center justify-between px-4 py-2 border-b border-border-subtle flex-shrink-0",children:[F("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:"Sidebar"},void 0,!1,void 0,this),F("button",{onClick:()=>f(!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),F("div",{className:"flex-1 overflow-hidden",children:F(I2,{onPreview:()=>L(!0),onSubmit:Z2},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),F(j5,{open:U,onClose:()=>L(!1),onSubmit:Z2},void 0,!1,void 0,this),F(z3,{sessionId:Q,revision:q,open:B,shareEnabled:m,existingShares:x,onClose:()=>D(!1),onShareCreated:(C)=>{A((a)=>[...a.filter((n)=>n.shareId!==C.shareId),C]),K1({kind:"success",message:"Share link created. Copy and send it to reviewers."})},onShareRevoked:(C)=>{A((a)=>a.filter((n)=>n.shareId!==C)),K1({kind:"success",message:"Share link revoked."})}},void 0,!1,void 0,this),F(G3,{open:E,onClose:()=>{l(!1),g(null)},onSubmit:async(C)=>{let a=U5(C);if(l(!1),j!==null)await Q2(j,a),g(null)}},void 0,!1,void 0,this),e&&F("div",{className:`fixed bottom-4 left-1/2 -translate-x-1/2 z-50 px-4 py-2.5 rounded-lg shadow-lg text-[13px] font-body font-medium flex items-center gap-2 ${e.kind==="error"?"bg-accent-red text-white":"bg-accent-green text-white"}`,children:[e.message,F("button",{onClick:()=>K1(null),className:"ml-2 opacity-70 hover:opacity-100",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)},void 0,!1,void 0,this)},`${Q}:${q}`,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function W4({sessionId:Q,projectRoot:$,connected:Z,onMobileSidebar:J,collapsed:q,onToggle:X}){let Y=Z1.isShared;return F(A0,{children:[q&&F("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:F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[F("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"},void 0,!1,void 0,this),F("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),F("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 ${q?"-translate-x-full":""}`,children:[F("div",{className:"px-4 pt-4 pb-3 flex-shrink-0 border-b border-border-subtle",children:[F("div",{className:"flex items-center gap-2 mb-2",children:[F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",className:"text-text-tertiary flex-shrink-0",children:F("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),Y?F("span",{className:"text-[12px] font-body text-text-secondary truncate flex-1",children:"Shared canvas"},void 0,!1,void 0,this):F(A0,{children:[F(R2,{currentSessionId:Q,projectRoot:$},void 0,!1,void 0,this),F("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${Z?"bg-accent-green":"bg-accent-red"}`},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("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:F("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[F("polyline",{points:"11 17 6 12 11 7"},void 0,!1,void 0,this),F("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),F(B3,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("div",{className:"flex-1 flex flex-col overflow-hidden",children:F(E5,{embedded:!0},void 0,!1,void 0,this)},void 0,!1,void 0,this),F("div",{className:"px-4 py-3 border-t border-border-subtle flex items-center justify-between flex-shrink-0",children:[F("span",{className:"text-[10px] text-text-tertiary font-body uppercase tracking-widest",children:"Theme"},void 0,!1,void 0,this),F(F3,{},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 T4({children:Q,collapsed:$,onToggle:Z}){let[J,q]=$1(()=>{let W=localStorage.getItem("canvas-sidebar-width");return W?parseInt(W,10):320}),X=u1(!1),Y=u1(0),G=u1(0),z=u1(J);z.current=J;let _=j0((W)=>{W.preventDefault(),X.current=!0,Y.current=W.clientX,G.current=z.current;let K=(T)=>{if(!X.current)return;let U=Y.current-T.clientX,L=Math.max(240,Math.min(600,G.current+U));q(L),z.current=L},H=()=>{X.current=!1,localStorage.setItem("canvas-sidebar-width",String(z.current)),document.removeEventListener("mousemove",K),document.removeEventListener("mouseup",H),document.body.style.cursor="",document.body.style.userSelect=""};document.addEventListener("mousemove",K),document.addEventListener("mouseup",H),document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[]);return M1(()=>{return document.documentElement.style.setProperty("--sidebar-width",`${J}px`),()=>{document.documentElement.style.removeProperty("--sidebar-width")}},[J]),F(A0,{children:[$&&F("button",{onClick:Z,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:F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:F("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),F("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:J},children:[F("div",{onMouseDown:_,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),x1.Children.map(Q,(W)=>x1.isValidElement(W)?x1.cloneElement(W,{collapseButton:F("button",{onClick:Z,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:F("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[F("polyline",{points:"13 17 18 12 13 7"},void 0,!1,void 0,this),F("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)}):W)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function W3({markdown:Q}){let[$,Z]=$1(!1),J=K3(()=>s.parse(Q,{async:!1}),[Q]),q=u1(null),{annotations:X,addAnnotationWithId:Y,removeAnnotation:G,updateAnnotation:z,addAnnotationImage:_,removeAnnotationImage:W,activeAnnotationId:K,setActiveAnnotationId:H}=Y1(),[T,U]=$1(null),[L,N]=$1(null),P=K3(()=>X.filter((b)=>b.filePath===T1),[X]),[O,w]=$1(Q);if(Q!==O)w(Q),Z(!1);M1(()=>{if(!q.current||P.length===0)return;let b=setTimeout(()=>{if(q.current)f0(q.current,P)},50);return()=>clearTimeout(b)},[J,P.length]);let S=u1(null);if(M1(()=>{g0(K,S.current),S.current=K},[K]),M1(()=>{let b=q.current;if(!b)return;let V=(f)=>{let R=f.target.closest("[data-annotation-id]");if(!R)return;f.stopPropagation();let k=R.getAttribute("data-annotation-id");if(k===K)N({anchorEl:R,annId:k});else H(k)},v=(f)=>{let R=f.target.closest("[data-annotation-id]");if(R)H(R.getAttribute("data-annotation-id"))},p=(f)=>{let R=f.target.closest("[data-annotation-id]"),k=f.relatedTarget?.closest?.("[data-annotation-id]");if(R&&!k)H(null)};return b.addEventListener("click",V),b.addEventListener("mouseover",v),b.addEventListener("mouseout",p),()=>{b.removeEventListener("click",V),b.removeEventListener("mouseover",v),b.removeEventListener("mouseout",p)}},[J,K]),M1(()=>{let b=()=>{let V=window.getSelection();if(!V||V.isCollapsed||!V.toString().trim())return;if(!q.current)return;let v=V.getRangeAt(0);if(!q.current.contains(v.startContainer))return;if(v.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let p=V.toString().trim();if(p.length<2)return;let f=v.cloneRange(),R=c1(v,q.current),k=`__pending_${Date.now()}`;try{r1(f,k)}catch{}window.getSelection()?.removeAllRanges();let u=document.querySelectorAll(`[data-annotation-id="${k}"]`),I=u[u.length-1];if(!I)return;U({anchorEl:I,tempId:k,snippet:p,ctx:R})};return document.addEventListener("mouseup",b),()=>document.removeEventListener("mouseup",b)},[]),$)return null;let M=document.getElementById("plan-scroll-container");return F("div",{className:"mb-6 rounded-lg border border-accent-blue/20 bg-accent-blue/5 relative",children:[F("button",{onClick:()=>Z(!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:F("span",{className:"text-xs",children:"✕"},void 0,!1,void 0,this)},void 0,!1,void 0,this),F("div",{className:"px-4 py-3 pr-10",children:[F("div",{className:"flex items-center gap-2 mb-1.5",children:[F("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:F("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),F("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),F("div",{ref:q,className:"prose-canvas text-sm",dangerouslySetInnerHTML:{__html:J}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),T&&F(Z0,{anchorEl:T.anchorEl,scrollContainer:M,snippet:T.snippet,truncateAt:80,onAdd:(b,V)=>{let v=F1();v0(T.tempId,v),Y(v,T.snippet,b,T1,T.ctx,V),U(null)},onCancel:()=>{h0(T.tempId),U(null)}},void 0,!1,void 0,this),L&&(()=>{let b=X.find((V)=>V.id===L.annId);if(!b)return null;return F(q0,{anchorEl:L.anchorEl,scrollContainer:M,initialNote:b.note,initialImages:b.images,onUpdate:(V,v)=>{z(L.annId,V);let p=b.images||[];for(let f of v)if(!p.includes(f))_(L.annId,f);for(let f of p)if(!v.includes(f))W(L.annId,f)},onDelete:()=>{G(L.annId),H(null)},onClose:()=>N(null)},void 0,!1,void 0,this)})()]},void 0,!0,void 0,this)}function N4(){let{activeView:Q,setActiveView:$,openFiles:Z,closeFile:J,canvasFiles:q}=x1.useContext(I1),X=x1.useContext(O3),{addAnnotationWithId:Y,setActiveAnnotationId:G}=Y1();if(!(q.length>1||Z.length>0))return null;return F("div",{className:"flex items-center border-b border-border-medium bg-bg-surface overflow-x-auto sticky top-0 z-10",children:[q.length>1&&F(A0,{children:[F("button",{onClick:()=>$({type:"overview"}),className:`flex items-center gap-1.5 px-4 py-2.5 text-[13px] font-body whitespace-nowrap transition-colors relative ${Q.type==="overview"?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",className:"opacity-60",children:F("path",{d:"M12 7L2 12l10 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),"Overview",Q.type==="overview"&&F("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),F("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),q.map((_,W)=>{let K=_.replace(/\.jsx$/,""),H=Q.type==="canvas"&&Q.filename===_;return F(x1.Fragment,{children:[F("button",{onClick:()=>$({type:"canvas",filename:_}),className:`flex items-center gap-1.5 px-4 py-2.5 text-[13px] font-body whitespace-nowrap transition-colors relative ${H?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[K,H&&F("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),W<q.length-1&&F("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this)]},_,!0,void 0,this)}),Z.length>0&&F(A0,{children:[F("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this),Z.map((_,W)=>{let K=_.split("/").pop()||_,H=Q.type==="file"&&Q.path===_;return F(x1.Fragment,{children:[F("div",{className:"flex items-center",children:[F("button",{onClick:()=>$({type:"file",path:_}),className:`flex items-center gap-1.5 pl-3 pr-1 py-2.5 text-[13px] font-body whitespace-nowrap transition-colors relative ${H?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[F(k1,{name:K,type:"file"},void 0,!1,void 0,this),K,H&&F("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),F("button",{onClick:(T)=>{T.stopPropagation(),J(_)},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),W<Z.length-1&&F("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this)]},_,!0,void 0,this)})]},void 0,!0,void 0,this),F("div",{className:"ml-auto flex items-center gap-1 flex-shrink-0",children:Q.type==="file"&&B1&&F("button",{onClick:async()=>{let _=Q.path;try{let K=await(await fetch(`/api/file?session=${X}&path=${encodeURIComponent(_)}`)).json();if(!K.error){let H=K.content.split(`
|
|
83
|
+
`}var U8=new Set(["CODE","SPAN","STRONG","EM","A","B","I","U","SMALL","SUB","SUP","MARK","ABBR"]);function s0(Q,$,Z){if(H8(Q)){let J=W8(Q);if(J)$.push(J,"");return}for(let J of Q.childNodes)if(J.nodeType===Node.ELEMENT_NODE)T8(J,$,Z);else if(J.nodeType===Node.TEXT_NODE){let q=J.textContent?.trim();if(q)$.push(q,"")}}function H8(Q){for(let $ of Q.childNodes){if($.nodeType===Node.TEXT_NODE)continue;if($.nodeType===Node.ELEMENT_NODE){let Z=$;if(!U8.has(Z.tagName)||Z.hasAttribute("data-md"))return!1}}return Q.childNodes.length>0}function W8(Q){let $="";for(let Z of Q.childNodes)if(Z.nodeType===Node.TEXT_NODE)$+=Z.textContent||"";else if(Z.nodeType===Node.ELEMENT_NODE){let J=Z;if(J.tagName==="CODE")$+="`"+(J.textContent||"")+"`";else $+=J.textContent||""}return $.trim()}function T8(Q,$,Z){let J=Q.getAttribute("data-md");if(J)switch(J){case"section":return N8(Q,$,Z);case"item":return O8(Q,$);case"codeblock":return F8(Q,$);case"callout":return B8(Q,$);case"note":return L8(Q,$);case"table":return M8(Q,$);case"checklist":return y8(Q,$);case"diff":return P8(Q,$);case"mermaid":return S8(Q,$);case"choice":return b8(Q,$);case"multichoice":return w8(Q,$);case"choice-option":case"multichoice-option":return;case"userinput":return j8(Q,$);case"rangeinput":return A8(Q,$);case"checklist-item":return;case"filepreview":return C8(Q,$);case"priority":return I8(Q,$)}if(Q.querySelector("button, input, select, textarea"))return;if(Q.children.length>0)s0(Q,$,Z);else{let q=Q.textContent?.trim();if(q)$.push(q,"")}}function N8(Q,$,Z){let J=Q.getAttribute("data-md-title")||"Untitled",q=Z===0?"##":"###";$.push(`${q} ${J}`,"");let Y=Q.querySelector(":scope > div:last-of-type");if(Y)s0(Y,$,Z+1)}function O8(Q,$){let Z=Q.getAttribute("data-md-label")||"",J=Q.getAttribute("data-md-status"),q=Q.getAttribute("data-md-badge"),Y="-";if(J==="done")Y="- [x]";else if(J)Y="- [ ]";let X=`${Y} **${Z}**`;if(q)X+=` \`${q}\``;$.push(X);let G=Q.querySelector(".text-text-secondary");if(G){let z=[];s0(G,z,0);for(let _ of z)$.push(_?` ${_}`:"")}$.push("")}function F8(Q,$){let Z=Q.getAttribute("data-md-language")||"",q=Q.querySelector("code")?.textContent||"";$.push(`\`\`\`${Z}`,q,"```","")}function B8(Q,$){let Z=Q.getAttribute("data-md-type")||"info",J={info:"Info",warning:"Warning",danger:"Danger",tip:"Tip"},q=V8(Q.querySelector(".text-text-secondary")||Q);$.push(`> **${J[Z]||Z}:** ${q}`,"")}function L8(Q,$){let Z=Q.textContent?.trim()||"";$.push(`> *${Z}*`,"")}function M8(Q,$){let Z=Q.querySelector("table");if(!Z)return;let J=[];for(let q of Z.querySelectorAll("thead th"))J.push(q.textContent?.trim()||"");if(J.length===0)return;$.push(`| ${J.join(" | ")} |`),$.push(`| ${J.map(()=>"---").join(" | ")} |`);for(let q of Z.querySelectorAll("tbody tr")){let Y=[];for(let X of q.querySelectorAll("td"))Y.push(X.textContent?.trim()||"");$.push(`| ${Y.join(" | ")} |`)}$.push("")}function y8(Q,$){for(let Z of Q.querySelectorAll("li")){let J=Z.querySelector(".bg-accent-green")!==null,q=Z.textContent?.trim()||"";$.push(`- [${J?"x":" "}] ${q}`)}$.push("")}function P8(Q,$){let Z=Q.getAttribute("data-md-language")||"";$.push(`\`\`\`diff${Z?` (${Z})`:""}`);for(let J of Q.querySelectorAll("[class*='flex']")){let q=J.querySelector(".text-accent-red")?"-":J.querySelector(".text-accent-green")?"+":" ",Y=J.querySelector("code");if(Y)$.push(`${q} ${Y.textContent}`)}$.push("```","")}function S8(Q,$){let Z=Q.getAttribute("data-md-source")||"";if(Z)$.push("```mermaid",Z,"```","")}function b8(Q,$){let Z=Q.getAttribute("data-md-label")||"";$.push(`**${Z}:**`);for(let J of Q.querySelectorAll("[data-md='choice-option']")){let q=J.getAttribute("data-md-label")||J.textContent?.trim()||"",Y=J.querySelector(".bg-accent-amber")!==null;$.push(`- ${Y?"(x)":"( )"} ${q}`)}$.push("")}function w8(Q,$){let Z=Q.getAttribute("data-md-label")||"";$.push(`**${Z}:**`);for(let J of Q.querySelectorAll("[data-md='multichoice-option']")){let q=J.getAttribute("data-md-label")||J.textContent?.trim()||"",Y=J.querySelector(".bg-accent-amber")!==null;$.push(`- [${Y?"x":" "}] ${q}`)}$.push("")}function j8(Q,$){let Z=Q.getAttribute("data-md-label")||"",q=Q.querySelector("textarea")?.value?.trim()||"";$.push(`**${Z}:** ${q||"_empty_"}`,"")}function A8(Q,$){let Z=Q.getAttribute("data-md-label")||"",J=Q.querySelector("input[type='range']"),Y=Q.querySelector(".font-mono")?.textContent?.trim()||J?.value||"—";$.push(`**${Z}:** ${Y}`,"")}function C8(Q,$){let Z=Q.getAttribute("data-md-path")||"",J=Q.getAttribute("data-md-lines")||"",Y=Q.querySelector("code")?.textContent||"",X=Z.split(".").pop()||"",G=a0[X]||"",z=J?`${Z} (L${J})`:Z;$.push(z,"",`\`\`\`${G}`,Y,"```","")}function I8(Q,$){}function V8(Q){return Q?.textContent?.trim()||""}import $3,{useEffect as m1,useState as _1,useRef as V1,useCallback as Q3,useMemo as $2,useContext as l8}from"react";import{useEffect as R8,useState as D8,useRef as k8,useContext as E8}from"react";import{jsxDEV as H1,Fragment as c5}from"react/jsx-dev-runtime";function x8(Q){return Q.label||`Round ${Q.revision}`}function m8(Q){let $=Date.now()-new Date(Q).getTime(),Z=Math.floor($/1000);if(Z<60)return"just now";let J=Math.floor(Z/60);if(J<60)return`${J}m ago`;let q=Math.floor(J/60);if(q<24)return`${q}h ago`;return`${Math.floor(q/24)}d ago`}function P0({value:Q,onChange:$,accent:Z="default",className:J}){let{currentRevision:q,revisions:Y}=E8(w1),[X,G]=D8(!1),z=k8(null);R8(()=>{if(!X)return;let K=(W)=>{if(z.current&&!z.current.contains(W.target))G(!1)};return document.addEventListener("mousedown",K),()=>document.removeEventListener("mousedown",K)},[X]);let _=Y.find((K)=>K.revision===Q);return H1("div",{className:"relative",ref:z,children:[H1("button",{onClick:()=>G(!X),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"}[Z]} ${J||""}`,children:[_?x8(_):`Round ${Q}`,H1("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",className:`text-text-tertiary transition-transform duration-200 ${X?"rotate-180":""}`,children:H1("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),X&&H1("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:[...Y].reverse().map((K)=>H1("button",{onClick:()=>{$(K.revision),G(!1)},className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] font-body transition-colors ${K.revision===Q?"bg-bg-surface text-text-primary":"text-text-secondary hover:bg-bg-surface hover:text-text-primary"}`,children:[H1("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${K.revision===q?"bg-accent-green":K.hasFeedback?"bg-accent-amber":"bg-border-hover"}`},void 0,!1,void 0,this),H1("span",{className:"flex-1 text-left truncate",children:K.label?H1(c5,{children:[K.label," ",H1("span",{className:"text-text-tertiary",children:["#",K.revision]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):H1(c5,{children:["Round ",K.revision]},void 0,!0,void 0,this)},void 0,!1,void 0,this),H1("span",{className:"text-[10px] text-text-tertiary flex-shrink-0 flex items-center gap-1.5",children:[(()=>{let W=K.canvasFiles?.reduce((T,U)=>{if(U.diffStats)T.added+=U.diffStats.added,T.removed+=U.diffStats.removed;return T},{added:0,removed:0});if(W&&(W.added>0||W.removed>0))return H1("span",{className:"font-mono",children:[H1("span",{className:"text-accent-green",children:["+",W.added]},void 0,!0,void 0,this)," ",H1("span",{className:"text-accent-red",children:["-",W.removed]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);return null})(),K.revision===q?"current":K.hasFeedback?"sent":m8(K.createdAt)]},void 0,!0,void 0,this)]},K.revision,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function x1(Q,$){let Z=Q.length,J=$.length;if(Z===0||J===0)return[];let q=Array.from({length:Z+1},()=>Array(J+1).fill(0));for(let z=1;z<=Z;z++)for(let _=1;_<=J;_++)q[z][_]=Q[z-1]===$[_-1]?q[z-1][_-1]+1:Math.max(q[z-1][_],q[z][_-1]);let Y=[],X=Z,G=J;while(X>0&&G>0)if(Q[X-1]===$[G-1])Y.unshift(Q[X-1]),X--,G--;else if(q[X-1][G]>q[X][G-1])X--;else G--;return Y}function d5(Q){let $=[],Z=[],J=document.createTreeWalker(Q,NodeFilter.SHOW_TEXT,{acceptNode(Y){let X=Y.parentElement;if(!X)return NodeFilter.FILTER_REJECT;if(X.closest("svg, .select-none, [data-no-diff]"))return NodeFilter.FILTER_REJECT;return NodeFilter.FILTER_ACCEPT}}),q;while(q=J.nextNode()){let X=(q.nodeValue||"").match(/\S+|\s+/g);if(!X)continue;let G=0;for(let z of X)$.push(z),Z.push({text:z,node:q,offset:G}),G+=z.length}return{words:$,map:Z}}function k2(Q,$){if(Q.length>5000||$.length>5000)return u8(Q,$);return i5(Q,$)}function i5(Q,$){let Z=t0(Q,$),J=[],q=[],Y=0,X=0,G=0;while(Y<Q.length||X<$.length)if(G<Z.length&&Y<Q.length&&X<$.length&&Q[Y]===Z[G]&&$[X]===Z[G])J.push({type:"same",index:Y}),q.push({type:"same",index:X}),Y++,X++,G++;else if(Y<Q.length&&(G>=Z.length||Q[Y]!==Z[G]))J.push({type:"removed",index:Y}),Y++;else if(X<$.length)q.push({type:"added",index:X}),X++;return{oldOps:J,newOps:q}}function t0(Q,$){let Z=Q.length,J=$.length;if(Z===0||J===0)return[];if(Z===1)return $.includes(Q[0])?[Q[0]]:[];if(J===1)return Q.includes($[0])?[$[0]]:[];if(Z*J<=1e6)return x1(Q,$);let q=Math.floor(Z/2),Y=Q.slice(0,q),X=Q.slice(q),G=r5(Y,$),z=r5([...X].reverse(),[...$].reverse()),_=0,H=0;for(let T=0;T<=J;T++){let U=G[T]+z[J-T];if(U>_)_=U,H=T}let K=$.slice(0,H),W=$.slice(H);return[...t0(Y,K),...t0(X,W)]}function r5(Q,$){let Z=$.length,J=Array(Z+1).fill(0),q=Array(Z+1).fill(0);for(let Y=0;Y<Q.length;Y++){for(let X=1;X<=Z;X++)q[X]=Q[Y]===$[X-1]?J[X-1]+1:Math.max(J[X],q[X-1]);[J,q]=[q,J],q.fill(0)}return J}function u8(Q,$){let J=(U)=>{let B=[];for(let N=0;N<U.length;N+=200){let M=Math.min(N+200,U.length);B.push({start:N,end:M,text:U.slice(N,M).join("")})}return B},q=J(Q),Y=J($),X=q.map((U)=>U.text),G=Y.map((U)=>U.text),z=t0(X,G),_=[],H=[],K=0,W=0,T=0;while(K<q.length||W<Y.length)if(T<z.length&&K<q.length&&W<Y.length&&X[K]===z[T]&&G[W]===z[T]){for(let U=q[K].start;U<q[K].end;U++)_.push({type:"same",index:U});for(let U=Y[W].start;U<Y[W].end;U++)H.push({type:"same",index:U});K++,W++,T++}else if(K<q.length&&(T>=z.length||X[K]!==z[T]))if(W<Y.length&&(T>=z.length||G[W]!==z[T])){let U=i5(Q.slice(q[K].start,q[K].end),$.slice(Y[W].start,Y[W].end));for(let B of U.oldOps)_.push({type:B.type,index:B.index+q[K].start});for(let B of U.newOps)H.push({type:B.type,index:B.index+Y[W].start});K++,W++}else{for(let U=q[K].start;U<q[K].end;U++)_.push({type:"removed",index:U});K++}else if(W<Y.length){for(let U=Y[W].start;U<Y[W].end;U++)H.push({type:"added",index:U});W++}return{oldOps:_,newOps:H}}function l5(Q,$,Z){let J=new Map;for(let q of Q){if(q.type==="same")continue;let Y=$[q.index];if(!Y||!Y.node.parentNode)continue;let X=J.get(Y.node);if(!X)X=[],J.set(Y.node,X);X.push({offset:Y.offset,length:Y.text.length})}for(let[q,Y]of J){if(!q.parentNode)continue;let X=q.nodeValue||"";Y.sort((K,W)=>K.offset-W.offset);let G=[];for(let K of Y){let W=G[G.length-1];if(W&&K.offset<=W.offset+W.length)W.length=Math.max(W.length,K.offset+K.length-W.offset);else G.push({...K})}let z=q.parentNode,_=document.createDocumentFragment(),H=0;for(let K of G){if(K.offset>H)_.appendChild(document.createTextNode(X.slice(H,K.offset)));let W=document.createElement("span");W.className=Z,W.textContent=X.slice(K.offset,K.offset+K.length),_.appendChild(W),H=K.offset+K.length}if(H<X.length)_.appendChild(document.createTextNode(X.slice(H)));z.replaceChild(_,q)}}function n0(Q,$){let Z=g8(Q,$),J=d5(Q),q=d5($),{oldOps:Y,newOps:X}=k2(J.words,q.words),G=Y.some((z)=>z.type==="removed")||X.some((z)=>z.type==="added");return l5(Y,J.map,"diff-removed"),l5(X,q.map,"diff-added"),G||Z}function g8(Q,$){let Z=Array.from(Q.querySelectorAll('[data-md="mermaid"]')),J=Array.from($.querySelectorAll('[data-md="mermaid"]')),q=!1,Y=Math.max(Z.length,J.length);for(let X=0;X<Y;X++){let G=Z[X],z=J[X];if(!G&&z){z.classList.add("diff-block-added"),z.style.position="relative",q=!0;continue}if(G&&!z){G.classList.add("diff-block-removed"),G.style.position="relative",q=!0;continue}if(!G||!z)continue;let _=(G.getAttribute("data-md-source")||"").trim(),H=(z.getAttribute("data-md-source")||"").trim();if(_===H)continue;q=!0,G.style.borderLeft="3px solid var(--color-accent-red)",G.style.paddingLeft="8px",z.style.borderLeft="3px solid var(--color-accent-green)",z.style.paddingLeft="8px";let K=_.split(`
|
|
84
|
+
`),W=H.split(`
|
|
85
|
+
`),T=x1(K,W),U=(B,N,M)=>{let O=document.createElement("div");O.className="mt-2 bg-bg-code rounded-md overflow-hidden text-tiny font-mono",O.setAttribute("data-no-diff","true");let A=0,S=0;while(S<B.length){let y=document.createElement("div");if(y.className="px-3 py-0.5 whitespace-pre-wrap",A<N.length&&B[S]===N[A])y.textContent=" "+B[S],S++,A++;else y.classList.add(M==="old"?"diff-removed":"diff-added"),y.textContent=(M==="old"?"- ":"+ ")+B[S],S++;O.appendChild(y)}return O};G.appendChild(U(K,T,"old")),z.appendChild(U(W,T,"new"))}return q}function z0(Q){let $=[],Z=Q.querySelectorAll(":scope > [data-md]");for(let J of Z)$.push(S0(J));if($.length===0){let J=Q.querySelectorAll("[data-md]"),q=new Set;for(let Y of J){let X=Y.parentElement?.closest("[data-md]");if(X&&Q.contains(X))continue;if(q.has(Y))continue;q.add(Y),$.push(S0(Y))}}return $}function S0(Q){let $=Q.getAttribute("data-md")||"unknown",Z=v8(Q,$),J=[];if($==="section"){let q=Q.querySelector(":scope > div.mt-6, :scope > div:last-child");if(q)for(let Y of q.querySelectorAll(":scope > [data-md]"))J.push(S0(Y))}else if($==="table")for(let q of Q.querySelectorAll(":scope table > tbody > tr"))J.push({key:"tr:"+(q.textContent||"").slice(0,80),type:"tr",element:q,children:[]});else if($==="checklist")for(let q of Q.querySelectorAll(":scope > [data-md='checklist-item']"))J.push(S0(q));else for(let q of Q.querySelectorAll("[data-md]"))if(q.parentElement?.closest("[data-md]")===Q)J.push(S0(q));return{key:Z,type:$,element:Q,children:J}}function v8(Q,$){switch($){case"section":return"section:"+(Q.getAttribute("data-md-title")||"");case"item":return"item:"+(Q.getAttribute("data-task-id")||Q.getAttribute("data-md-label")||"");case"codeblock":case"diff":return $+":"+(Q.textContent||"").slice(0,80);case"checklist-item":return"checklist-item:"+(Q.getAttribute("data-md-label")||Q.textContent?.slice(0,60)||"");case"checklist":return"checklist:"+Q.querySelectorAll("[data-md='checklist-item']").length;case"markdown":return"markdown:"+(Q.getAttribute("data-md-file")||"inline");case"mermaid":return"mermaid:"+(Q.getAttribute("data-md-source")||"").slice(0,80);case"callout":return"callout:"+(Q.getAttribute("data-md-type")||"")+":"+(Q.textContent||"").slice(0,60);default:return $+":"+(Q.getAttribute("data-md-label")||Q.textContent?.slice(0,60)||"")}}function b0(Q,$){let Z=Q.map((_)=>_.key),J=$.map((_)=>_.key),q=x1(Z,J),Y=[],X=0,G=0,z=0;while(X<Q.length||G<$.length)if(z<q.length&&X<Q.length&&G<$.length&&Z[X]===q[z]&&J[G]===q[z]){let _=Q[X],H=$[G],K=_.children.length>0||H.children.length>0?b0(_.children,H.children):void 0;Y.push({kind:"matched",oldBlock:_,newBlock:H,childMatches:K}),X++,G++,z++}else if(X<Q.length&&(z>=q.length||Z[X]!==q[z]))Y.push({kind:"removed",oldBlock:Q[X]}),X++;else if(G<$.length)Y.push({kind:"added",newBlock:$[G]}),G++;return Y}function e0(Q){let $=document.createDocumentFragment(),Z=!1;for(let J of Q)if(J.kind==="removed")Z=!0,$.appendChild(o5(J.oldBlock.element));else if(J.kind==="added")Z=!0,$.appendChild(f8(J.newBlock.element));else{let q=J.newBlock.element.cloneNode(!0),Y=J.newBlock.type;if(Y==="mermaid"){if(e5(J.oldBlock.element,q))Z=!0}else if(J.childMatches&&J.childMatches.length>0&&(Y==="table"||Y==="checklist")){if(t5(q,J.childMatches,Y))Z=!0}else if(J.childMatches&&J.childMatches.length>0){if(s5(J.oldBlock,q,J.childMatches,Y))Z=!0}else if(Y==="markdown"){if(n5(J.oldBlock.element,q))Z=!0}else if(n1(J.oldBlock.element,q,!1))Z=!0;$.appendChild(q)}return{fragment:$,hasChanges:Z}}function o5(Q){let $=Q.cloneNode(!0);return $.classList.add("diff-block-removed"),$.style.position="relative",E2($,"Removed","var(--color-accent-red)"),$}function f8(Q){let $=Q.cloneNode(!0);return $.classList.add("diff-block-added"),$.style.position="relative",E2($,"Added","var(--color-accent-green)"),$}function s5(Q,$,Z,J){let q=!1,Y=h8(Q,$),X,G;if(J==="section"){let z=Q.element.querySelector(":scope > div:first-child"),_=$.querySelector(":scope > div:first-child");if(z&&_){if(n1(z,_,!1))q=!0}X=Q.element.querySelector(":scope > div.mt-6, :scope > div:last-child"),G=$.querySelector(":scope > div.mt-6, :scope > div:last-child")}else X=Q.element,G=$;if(!X||!G)return q;for(let z of Z)if(z.kind==="matched"){let _=Y.newMap.get(z.newBlock.element);if(_){if(z.newBlock.type==="mermaid"){if(e5(z.oldBlock.element,_))q=!0}else if(z.childMatches&&z.childMatches.length>0&&(z.newBlock.type==="table"||z.newBlock.type==="checklist")){if(t5(_,z.childMatches,z.newBlock.type))q=!0}else if(z.childMatches&&z.childMatches.length>0){if(s5(z.oldBlock,_,z.childMatches,z.newBlock.type))q=!0}else if(z.newBlock.type==="markdown"){if(n5(z.oldBlock.element,_))q=!0}else if(n1(z.oldBlock.element,_,!1))q=!0}}else if(z.kind==="removed"){q=!0;let _=o5(z.oldBlock.element),H=c8(Z,z,Y.newMap),K=H?d8(G,H):null;G.insertBefore(_,K)}else if(z.kind==="added"){q=!0;let _=Y.newMap.get(z.newBlock.element);if(_)_.classList.add("diff-block-added"),_.style.position="relative",E2(_,"Added","var(--color-accent-green)")}if(n1(X,G,!0))q=!0;return q}function t5(Q,$,Z){let J=Z==="table"?Q.querySelector(":scope table > tbody"):Q;if(!J)return!1;let q=!1;J.innerHTML="";for(let Y of $)if(Y.kind==="removed"){q=!0;let X=Y.oldBlock.element.cloneNode(!0);X.classList.add(Z==="table"?"diff-row-removed":"diff-item-removed"),J.appendChild(X)}else if(Y.kind==="added"){q=!0;let X=Y.newBlock.element.cloneNode(!0);X.classList.add(Z==="table"?"diff-row-added":"diff-item-added"),J.appendChild(X)}else{let X=Y.newBlock.element.cloneNode(!0);if(n1(Y.oldBlock.element,X,!1))q=!0;J.appendChild(X)}return q}function h8(Q,$){let Z=new Map,J=Q.element.querySelectorAll("[data-md]"),q=$.querySelectorAll("[data-md]");return{newMap:{get(Y){return p8($,Y)}}}}function p8(Q,$){let Z=$.getAttribute("data-md");if(!Z)return null;let J=$.getAttribute("data-md-label"),q=$.getAttribute("data-md-title"),Y=`[data-md="${Z}"]`;if(q)Y+=`[data-md-title="${CSS.escape(q)}"]`;else if(J)Y+=`[data-md-label="${CSS.escape(J)}"]`;let X=Q.querySelectorAll(Y);if(X.length===1)return X[0];let G=($.textContent||"").slice(0,100),z=null,_=-1;for(let H of X){let K=(H.textContent||"").slice(0,100),W=0;for(let T=0;T<Math.min(G.length,K.length);T++)if(G[T]===K[T])W++;if(W>_)_=W,z=H}return z}function c8(Q,$,Z){let J=Q.indexOf($);for(let q=J+1;q<Q.length;q++){let Y=Q[q];if((Y.kind==="matched"||Y.kind==="added")&&Y.newBlock)return Z.get(Y.newBlock.element)||null}return null}function d8(Q,$){let Z=$;while(Z&&Z.parentElement!==Q)Z=Z.parentElement;return Z}function n5(Q,$){let Z=Array.from(Q.children),J=Array.from($.children);if(Z.length===0&&J.length===0)return n1(Q,$,!1);let q=Z.map((W)=>W.tagName.toLowerCase()),Y=J.map((W)=>W.tagName.toLowerCase()),X=x1(q,Y),G=[],z=0,_=0,H=0;while(z<Z.length||_<J.length)if(H<X.length&&z<Z.length&&_<J.length&&q[z]===X[H]&&Y[_]===X[H])G.push({kind:"matched",oldChild:Z[z],newChild:J[_]}),z++,_++,H++;else if(z<Z.length&&(H>=X.length||q[z]!==X[H]))G.push({kind:"removed",oldChild:Z[z]}),z++;else if(_<J.length)G.push({kind:"added",newChild:J[_]}),_++;let K=!1;while($.firstChild)$.removeChild($.firstChild);for(let W of G)if(W.kind==="matched"){let T=(W.oldChild.textContent||"").match(/\S+/g)||[],U=(W.newChild.textContent||"").match(/\S+/g)||[],B=x1(T,U),N=Math.max(T.length,U.length);if((N>0?1-B.length/N:0)>0.5){K=!0;let O=W.oldChild.cloneNode(!0);O.classList.add("diff-block-removed"),$.appendChild(O),W.newChild.classList.add("diff-block-added"),$.appendChild(W.newChild)}else{if(n1(W.oldChild,W.newChild,!1))K=!0;$.appendChild(W.newChild)}}else if(W.kind==="removed"){K=!0;let T=W.oldChild.cloneNode(!0);T.classList.add("diff-block-removed"),$.appendChild(T)}else K=!0,W.newChild.classList.add("diff-block-added"),$.appendChild(W.newChild);return K}function a5(Q,$){let Z=$?new Set(Array.from(Q.querySelectorAll("[data-md]"))):new Set,J=[],q=[],Y=document.createTreeWalker(Q,NodeFilter.SHOW_TEXT,{acceptNode(G){let z=G.parentElement;if(!z)return NodeFilter.FILTER_REJECT;if(z.closest("svg, .select-none, [data-no-diff]"))return NodeFilter.FILTER_REJECT;if($){for(let _ of Z)if(_.contains(G))return NodeFilter.FILTER_REJECT}return NodeFilter.FILTER_ACCEPT}}),X;while(X=Y.nextNode()){let z=(X.nodeValue||"").match(/\S+|\s+/g);if(!z)continue;let _=0;for(let H of z)J.push(H),q.push({text:H,node:X,offset:_}),_+=H.length}return{words:J,map:q}}function n1(Q,$,Z){let J=a5(Q,Z),q=a5($,Z);if(J.words.length===0&&q.words.length===0)return!1;let{oldOps:Y,newOps:X}=k2(J.words,q.words),G=Y.some((N)=>N.type==="removed"),z=X.some((N)=>N.type==="added");if(!G&&!z)return!1;let _=[],H=[];for(let N of Y)if(N.type==="same")_.push(N.index);for(let N of X)if(N.type==="same")H.push(N.index);let K=new Map;for(let N=0;N<_.length&&N<H.length;N++)K.set(_[N],H[N]);let W=[];{let N=[],M=-1;for(let O of Y)if(O.type==="same"){if(N.length>0)W.push({text:N.join(""),anchorNewIdx:M>=0?K.get(M)??null:null}),N=[];M=O.index}else if(O.type==="removed")N.push(J.words[O.index]);if(N.length>0)W.push({text:N.join(""),anchorNewIdx:M>=0?K.get(M)??null:null})}let T=new Map,U=new Map;for(let N of X){if(N.type!=="added")continue;let M=q.map[N.index];if(!M?.node.parentNode)continue;let O=T.get(M.node);if(!O)O=[],T.set(M.node,O);O.push({start:M.offset,end:M.offset+M.text.length})}for(let N of W)if(N.anchorNewIdx===null){if(q.map.length>0){let M=q.map[0].node,O=U.get(M);if(!O)O=[],U.set(M,O);O.push({offset:0,text:N.text})}}else{let M=q.map[N.anchorNewIdx];if(!M)continue;let O=U.get(M.node);if(!O)O=[],U.set(M.node,O);O.push({offset:M.offset+M.text.length,text:N.text})}let B=new Set([...T.keys(),...U.keys()]);for(let N of B)r8(N,T.get(N)||[],U.get(N)||[]);return!0}function r8(Q,$,Z){if(!Q.parentNode)return;let J=Q.nodeValue||"";$.sort((H,K)=>H.start-K.start);let q=[];for(let H of $){let K=q[q.length-1];if(K&&H.start<=K.end)K.end=Math.max(K.end,H.end);else q.push({...H})}Z.sort((H,K)=>H.offset-K.offset);let Y=Q.parentNode,X=document.createDocumentFragment(),G=0,z=0,_=0;while(G<=J.length){let H=z<q.length?q[z].start:1/0,K=_<Z.length?Z[_].offset:1/0,W=Math.min(H,K);if(W===1/0){if(G<J.length)X.appendChild(document.createTextNode(J.slice(G)));break}let T=Math.max(W,G);if(T>G)X.appendChild(document.createTextNode(J.slice(G,T))),G=T;while(_<Z.length&&Z[_].offset<=G){let U=document.createElement("span");U.className="diff-removed",U.textContent=Z[_].text,X.appendChild(U),_++}if(z<q.length&&q[z].start<=G){let U=q[z],B=document.createElement("span");B.className="diff-added",B.textContent=J.slice(G,U.end),X.appendChild(B),G=U.end,z++;while(_<Z.length&&Z[_].offset<=G){let N=document.createElement("span");N.className="diff-removed",N.textContent=Z[_].text,X.appendChild(N),_++}}}while(_<Z.length){let H=document.createElement("span");H.className="diff-removed",H.textContent=Z[_].text,X.appendChild(H),_++}Y.replaceChild(X,Q)}function e5(Q,$){let Z=(Q.getAttribute("data-md-source")||"").trim(),J=($.getAttribute("data-md-source")||"").trim();if(Z===J)return!1;let q=Z.split(`
|
|
86
|
+
`),Y=J.split(`
|
|
87
|
+
`),X=x1(q,Y),G=[],z=0,_=0,H=0;while(z<q.length||_<Y.length)if(H<X.length&&z<q.length&&_<Y.length&&q[z]===X[H]&&Y[_]===X[H])G.push({type:"same",line:q[z]}),z++,_++,H++;else if(z<q.length&&(H>=X.length||q[z]!==X[H]))G.push({type:"removed",line:q[z]}),z++;else if(_<Y.length)G.push({type:"added",line:Y[_]}),_++;let K=document.createElement("div");K.className="mt-2 bg-bg-code rounded-md overflow-hidden text-tiny font-mono",K.setAttribute("data-no-diff","true");for(let W of G){let T=document.createElement("div");if(T.className="px-3 py-0.5 whitespace-pre-wrap",W.type==="removed")T.classList.add("diff-removed"),T.textContent="- "+W.line;else if(W.type==="added")T.classList.add("diff-added"),T.textContent="+ "+W.line;else T.textContent=" "+W.line;K.appendChild(T)}return $.appendChild(K),!0}function E2(Q,$,Z){let J=document.createElement("span");J.className="diff-block-label",J.textContent=$,J.style.color=Z,J.style.backgroundColor=`color-mix(in srgb, ${Z} 12%, transparent)`,Q.appendChild(J)}import{jsxDEV as p}from"react/jsx-dev-runtime";function i8(Q,$,Z){let J=Q.find((X)=>X.revision===$),q=Q.find((X)=>X.revision===Z),Y=new Set;for(let X of J?.canvasFiles||[])Y.add(X.filename);for(let X of q?.canvasFiles||[])Y.add(X.filename);return[...Y].sort()}function Z3({initialLeft:Q,initialRight:$,sessionId:Z,onExit:J}){let[q,Y]=_1(Q),[X,G]=_1($),[z,_]=_1("unified"),[H,K]=_1(!0),[W,T]=_1(!1),{revisions:U}=l8(w1),B=$2(()=>i8(U,q,X),[U,q,X]),[N,M]=_1(()=>B[0]||"plan.jsx");m1(()=>{if(!B.includes(N))M(B[0]||"plan.jsx")},[B,N]);let O=$2(()=>{return U.find((y)=>y.revision===q)?.canvasFiles.some((y)=>y.filename===N)??!1},[U,q,N]),A=$2(()=>{return U.find((y)=>y.revision===X)?.canvasFiles.some((y)=>y.filename===N)??!1},[U,X,N]);return p("div",{className:"flex flex-col h-screen",children:[p("div",{className:"flex items-center justify-between px-6 py-3 border-b border-border-subtle bg-bg-surface flex-shrink-0",children:[p("div",{className:"flex items-center gap-3",children:[p("span",{className:"text-[13px] font-body font-medium text-text-primary",children:"Compare"},void 0,!1,void 0,this),p(P0,{value:q,onChange:Y,accent:"red"},void 0,!1,void 0,this),p("span",{className:"text-text-tertiary text-[13px]",children:"→"},void 0,!1,void 0,this),p(P0,{value:X,onChange:G,accent:"green"},void 0,!1,void 0,this),W&&!H&&p("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),p("div",{className:"flex items-center gap-4",children:[p("div",{className:"flex items-center bg-bg-elevated rounded-md p-0.5",children:[p("button",{onClick:()=>_("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),p("button",{onClick:()=>_("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"&&p(a8,{},void 0,!1,void 0,this),p("button",{onClick:J,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),B.length>1&&p("div",{className:"flex items-center gap-1 px-6 py-2 border-b border-border-subtle bg-bg-surface flex-shrink-0 overflow-x-auto",children:B.map((S)=>{let y=S.replace(/\.jsx$/,""),b=S===N,C=U.find((h)=>h.revision===q)?.canvasFiles.some((h)=>h.filename===S),E=U.find((h)=>h.revision===X)?.canvasFiles.some((h)=>h.filename===S),c=!C?" (added)":!E?" (removed)":"";return p("button",{onClick:()=>M(S),className:`text-[12px] font-body px-3 py-1 rounded-md transition-colors whitespace-nowrap ${b?"bg-bg-elevated text-text-primary font-medium":"text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated"}`,children:[y,c&&p("span",{className:`ml-1 text-[10px] ${!C?"text-accent-green":"text-accent-red"}`,children:c},void 0,!1,void 0,this)]},S,!0,void 0,this)})},void 0,!1,void 0,this),!O||!A?p("div",{className:"flex-1 flex items-center justify-center",children:p("div",{className:"text-center text-text-tertiary font-body",children:[p("div",{className:"text-lg mb-2",children:!O?"New file":"Removed file"},void 0,!1,void 0,this),p("div",{className:"text-[13px]",children:[N.replace(/\.jsx$/,"")," ",!O?"was added":"was removed"," in this revision"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this):z==="unified"?p(o8,{sessionId:Z,leftRev:q,rightRev:X,filename:N,onDiffResult:(S,y)=>{T(S),K(y)}},`unified-${q}-${X}-${N}`,!1,void 0,this):p(s8,{sessionId:Z,leftRev:q,rightRev:X,filename:N,onDiffResult:(S,y)=>{T(S),K(y)}},`sbs-${q}-${X}-${N}`,!1,void 0,this)]},void 0,!0,void 0,this)}function a8(){let[Q,$]=_1(!0);return m1(()=>{return document.documentElement.dataset.syncScroll=Q?"1":"0",()=>{delete document.documentElement.dataset.syncScroll}},[Q]),p("label",{className:"flex items-center gap-1.5 cursor-pointer select-none",children:[p("input",{type:"checkbox",checked:Q,onChange:(Z)=>$(Z.target.checked),className:"accent-accent-amber w-3.5 h-3.5"},void 0,!1,void 0,this),p("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 o8({sessionId:Q,leftRev:$,rightRev:Z,filename:J,onDiffResult:q}){let Y=V1(null),X=V1(null),G=V1(null),[z,_]=_1(!1),[H,K]=_1(!1),[W,T]=_1(!1),[U,B]=_1(null),[N,M]=_1(!1),{annotations:O}=Y1(),A=O.filter((y)=>!y.filePath&&(!y.canvasFile||y.canvasFile===J)),{popovers:S}=a1({containerRef:G,restoreKey:W,restoreAnnotations:A,extractContext:(y)=>d1(y,G.current)});return m1(()=>{if(W||U)return;let y=setTimeout(()=>{console.warn("[unified-diff] still loading after 10s",{leftReady:z,rightReady:H,oldRef:!!Y.current,newRef:!!X.current}),M(!0)},1e4);return()=>clearTimeout(y)},[W,U,z,H]),m1(()=>{if(!z||!H||W)return;if(!Y.current||!X.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!Y.current||!X.current||!G.current){console.warn("[unified-diff] refs lost between rAF frames",{old:!!Y.current,new:!!X.current,unified:!!G.current});return}try{let y=z0(Y.current),b=z0(X.current),C=b0(y,b),{fragment:E,hasChanges:c}=e0(C);G.current.innerHTML="",G.current.appendChild(E),T(!0),q(!0,c)}catch(y){console.error("[unified-diff] diff computation failed",y),B(y instanceof Error?y.message:String(y))}})})},[z,H,W]),p("div",{className:"flex-1 min-h-0 overflow-y-auto",children:[!W&&!U&&p("div",{style:{position:"absolute",left:-9999,visibility:"hidden",pointerEvents:"none",width:720},children:[p(R1,{ref:Y,sessionId:Q,revision:$,filename:J,onReady:()=>_(!0),onError:(y)=>B(`Rev ${$}: ${y}`)},void 0,!1,void 0,this),p(R1,{ref:X,sessionId:Q,revision:Z,filename:J,onReady:()=>K(!0),onError:(y)=>B(`Rev ${Z}: ${y}`)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),p("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:[!W&&!U&&p("div",{className:"flex flex-col items-center justify-center h-64 text-text-tertiary font-body text-body gap-2",children:[p("span",{children:"Loading..."},void 0,!1,void 0,this),N&&p("span",{className:"text-[11px]",children:"Taking longer than expected — check Network tab for pending requests"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),U&&p("div",{className:"bg-accent-red-muted rounded-lg p-5 mt-8",children:[p("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Failed to load revision"},void 0,!1,void 0,this),p("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:U},void 0,!1,void 0,this)]},void 0,!0,void 0,this),p("div",{ref:G},void 0,!1,void 0,this)]},void 0,!0,void 0,this),S]},void 0,!0,void 0,this)}function s8({sessionId:Q,leftRev:$,rightRev:Z,filename:J,onDiffResult:q}){let Y=V1(null),X=V1(null),[G,z]=_1(!1),[_,H]=_1(!1),[K,W]=_1(!1),T=V1(null),U=V1(null),B=V1(null),N=V1(!1),M=Q3(()=>z(!0),[]),O=Q3(()=>H(!0),[]),{annotations:A}=Y1(),S=A.filter((b)=>!b.filePath&&(!b.canvasFile||b.canvasFile===J)),{popovers:y}=a1({containerRef:T,restoreKey:K,restoreAnnotations:S,extractContext:(b)=>d1(b,T.current)});return m1(()=>{if(!G||!_||K)return;if(!Y.current||!X.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!Y.current||!X.current)return;let b=n0(Y.current,X.current);W(!0),q(!0,b)})})},[G,_,K]),m1(()=>{let b=U.current,C=B.current;if(!b||!C)return;let E=(R,x)=>{if(document.documentElement.dataset.syncScroll==="0")return;if(N.current)return;N.current=!0;let v=R.scrollHeight-R.clientHeight,D=x.scrollHeight-x.clientHeight;if(v>0&&D>0)x.scrollTop=R.scrollTop/v*D;requestAnimationFrame(()=>{N.current=!1})},c=()=>E(b,C),h=()=>E(C,b);return b.addEventListener("scroll",c),C.addEventListener("scroll",h),()=>{b.removeEventListener("scroll",c),C.removeEventListener("scroll",h)}},[]),p("div",{ref:T,className:"flex flex-1 min-h-0",children:[p("div",{ref:U,className:"w-1/2 overflow-y-auto border-r border-border-subtle",children:p("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:p(R1,{ref:Y,sessionId:Q,revision:$,filename:J,onReady:M},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),p("div",{ref:B,className:"w-1/2 overflow-y-auto",children:p("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:p(R1,{ref:X,sessionId:Q,revision:Z,filename:J,onReady:O},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),y]},void 0,!0,void 0,this)}var R1=$3.memo($3.forwardRef(({sessionId:Q,revision:$,filename:Z,onReady:J,onError:q},Y)=>{let[X,G]=_1(null),[z,_]=_1(null),[H,K]=_1(!0);m1(()=>{K(!0),_(null);let T=Z.replace(/\.jsx$/,".js");import(`/api/session/${Q}/canvas/${encodeURIComponent(T)}?rev=${$}&t=${Date.now()}`).then((U)=>{if(!U.default){_("Module has no default export"),K(!1),q?.("Module has no default export");return}G(()=>U.default),K(!1)}).catch((U)=>{_(U.message),K(!1),q?.(U.message)})},[Q,$,Z]),m1(()=>{if(!X)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{J()})})},[X]);let W=$2(()=>X?p(X,{},void 0,!1,void 0,this):null,[X]);if(H)return p("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(z)return p("div",{className:"bg-accent-red-muted rounded-lg p-5",children:[p("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Error"},void 0,!1,void 0,this),p("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:z},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(!X)return p("div",{className:"text-text-tertiary text-center py-8 font-body text-body",children:"No canvas loaded"},void 0,!1,void 0,this);return p("div",{ref:Y,children:W},void 0,!1,void 0,this)}));import{useState as D1,useContext as x2,useMemo as t8,useRef as w0,useEffect as J3,useCallback as q3}from"react";import{SessionContext as n8}from"#canvas/runtime";import{jsxDEV as r}from"react/jsx-dev-runtime";function m2(Q,$){if(!Q)return[];return Q.canvasFiles.map((Z)=>{if(!Z.diffStats)return{filename:Z.filename,status:"new"};if(Z.diffStats.added===0&&Z.diffStats.removed===0)return{filename:Z.filename,status:"unchanged",diffStats:Z.diffStats};return{filename:Z.filename,status:"changed",diffStats:Z.diffStats}})}function Y3(Q){return Q.filter(($)=>$.status!=="unchanged").map(($)=>$.filename)}function X3({revision:Q,responseBanner:$}){let{setActiveView:Z}=x2(I1),{revisions:J}=x2(w1),q=J.find((_)=>_.revision===Q),Y=J.find((_)=>_.revision===Q-1),X=t8(()=>m2(q,Y),[q,Y]),G=X.filter((_)=>_.status!=="unchanged"),z=X.filter((_)=>_.status==="unchanged");return r("div",{className:"max-w-[720px] mx-auto px-6 pt-12 pb-32",children:[$,G.map((_)=>r($4,{change:_,revision:Q,previousRevision:Y?.revision,onOpenTab:()=>Z({type:"canvas",filename:_.filename})},_.filename,!1,void 0,this)),z.length>0&&r("div",{className:"mt-8 border-t border-border-subtle pt-4",children:[r("div",{className:"text-[11px] font-body font-medium uppercase tracking-widest text-text-tertiary mb-3",children:"Unchanged"},void 0,!1,void 0,this),z.map((_)=>r(J4,{change:_,revision:Q,onOpenTab:()=>Z({type:"canvas",filename:_.filename})},_.filename,!1,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function e8({mode:Q,onChange:$,showDiff:Z}){if(!Z)return null;return r("div",{className:"flex items-center bg-bg-elevated rounded-md p-0.5",children:["rendered","unified","side-by-side"].map((J)=>r("button",{onClick:()=>$(J),className:`text-[10px] font-body px-2 py-0.5 rounded transition-colors ${Q===J?"bg-bg-surface text-text-primary font-medium shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:J==="rendered"?"Full":J==="unified"?"Unified":"Split"},J,!1,void 0,this))},void 0,!1,void 0,this)}function $4({change:Q,revision:$,previousRevision:Z,onOpenTab:J}){let q=Q.filename.replace(/\.jsx$/,""),Y=Q.status==="new",X=Q.diffStats,G=Q.status==="changed"&&Z!=null,[z,_]=D1("rendered");return r("div",{className:"mb-8",children:[r("div",{className:"flex items-center gap-2 mb-3 pb-2 border-b border-border-subtle",children:[r("span",{className:`text-[11px] font-mono px-1.5 py-0.5 rounded ${Y?"bg-accent-green/10 text-accent-green border border-accent-green/20":"bg-accent-amber/10 text-accent-amber border border-accent-amber/20"}`,children:Y?"new":"modified"},void 0,!1,void 0,this),r("span",{className:"text-[14px] font-body font-medium text-text-primary",children:q},void 0,!1,void 0,this),X&&(X.added>0||X.removed>0)&&r("span",{className:"text-[11px] font-mono text-text-tertiary",children:[r("span",{className:"text-accent-green",children:["+",X.added]},void 0,!0,void 0,this)," ",r("span",{className:"text-accent-red",children:["-",X.removed]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),r(e8,{mode:z,onChange:_,showDiff:G},void 0,!1,void 0,this),r("button",{onClick:J,className:`${G?"":"ml-auto"} text-[11px] font-body font-medium text-accent-blue hover:text-accent-blue/80 transition-colors`,children:"Open in tab"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z==="rendered"?r("div",{"data-canvas-file":Q.filename,children:r(B0,{revision:$,filename:Q.filename},void 0,!1,void 0,this)},void 0,!1,void 0,this):G&&Z!=null?r(Q4,{filename:Q.filename,leftRev:Z,rightRev:$,mode:z},`${z}-${$}-${Z}`,!1,void 0,this):null]},void 0,!0,void 0,this)}function Q4({filename:Q,leftRev:$,rightRev:Z,mode:J}){let q=x2(n8);if(J==="unified")return r(Z4,{sessionId:q,filename:Q,leftRev:$,rightRev:Z},void 0,!1,void 0,this);return r(q4,{sessionId:q,filename:Q,leftRev:$,rightRev:Z},void 0,!1,void 0,this)}function Z4({sessionId:Q,filename:$,leftRev:Z,rightRev:J}){let q=w0(null),Y=w0(null),X=w0(null),[G,z]=D1(!1),[_,H]=D1(!1),[K,W]=D1(!1),[T,U]=D1(null);return J3(()=>{if(!G||!_||K)return;if(!q.current||!Y.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!q.current||!Y.current||!X.current)return;try{let B=z0(q.current),N=z0(Y.current),M=b0(B,N),{fragment:O}=e0(M);X.current.innerHTML="",X.current.appendChild(O),W(!0)}catch(B){U(B instanceof Error?B.message:String(B))}})})},[G,_,K]),r("div",{children:[!K&&!T&&r("div",{style:{position:"absolute",left:-9999,visibility:"hidden",pointerEvents:"none",width:720},children:[r(R1,{ref:q,sessionId:Q,revision:Z,filename:$,onReady:()=>z(!0),onError:(B)=>U(B)},void 0,!1,void 0,this),r(R1,{ref:Y,sessionId:Q,revision:J,filename:$,onReady:()=>H(!0),onError:(B)=>U(B)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!K&&!T&&r("div",{className:"flex items-center justify-center h-24 text-text-tertiary font-body text-[13px]",children:"Computing diff..."},void 0,!1,void 0,this),T&&r("div",{className:"text-accent-red text-[13px] font-body p-3 bg-accent-red-muted rounded-lg",children:T},void 0,!1,void 0,this),r("div",{ref:X},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function q4({sessionId:Q,filename:$,leftRev:Z,rightRev:J}){let q=w0(null),Y=w0(null),[X,G]=D1(!1),[z,_]=D1(!1),[H,K]=D1(!1),W=q3(()=>G(!0),[]),T=q3(()=>_(!0),[]);return J3(()=>{if(!X||!z||H)return;if(!q.current||!Y.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!q.current||!Y.current)return;n0(q.current,Y.current),K(!0)})})},[X,z,H]),r("div",{className:"flex gap-0 border-y border-border-subtle overflow-hidden w-screen relative left-1/2 -translate-x-1/2",children:[r("div",{className:"w-1/2 border-r border-border-subtle",children:[r("div",{className:"px-2 py-1 text-[10px] font-body font-medium text-text-tertiary bg-bg-elevated border-b border-border-subtle",children:["Rev ",Z]},void 0,!0,void 0,this),r("div",{className:"px-6 py-4 max-w-[600px] mx-auto",children:r(R1,{ref:q,sessionId:Q,revision:Z,filename:$,onReady:W},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("div",{className:"w-1/2",children:[r("div",{className:"px-2 py-1 text-[10px] font-body font-medium text-text-tertiary bg-bg-elevated border-b border-border-subtle",children:["Rev ",J]},void 0,!0,void 0,this),r("div",{className:"px-6 py-4 max-w-[600px] mx-auto",children:r(R1,{ref:Y,sessionId:Q,revision:J,filename:$,onReady:T},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function J4({change:Q,revision:$,onOpenTab:Z}){let[J,q]=D1(!1),Y=Q.filename.replace(/\.jsx$/,"");return r("div",{className:"mb-2",children:[r("div",{className:"flex items-center gap-2 py-1.5",children:[r("button",{onClick:()=>q(!J),className:"text-text-tertiary hover:text-text-secondary transition-colors",children:r("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",className:`transition-transform duration-150 ${J?"rotate-90":""}`,children:r("path",{d:"M3.5 2L6.5 5L3.5 8",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),r("span",{className:"text-[13px] font-body text-text-secondary",children:Y},void 0,!1,void 0,this),r("button",{onClick:Z,className:"ml-auto text-[11px] font-body text-text-tertiary hover:text-accent-blue transition-colors",children:"Open in tab"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),J&&r("div",{className:"ml-5 mt-1 mb-3","data-canvas-file":Q.filename,children:r(B0,{revision:$,filename:Q.filename},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{useState as Q2,useEffect as Y4,useCallback as u2}from"react";import{jsxDEV as n}from"react/jsx-dev-runtime";function z3({sessionId:Q,revision:$,open:Z,shareEnabled:J,existingShares:q,onClose:Y,onShareCreated:X,onShareRevoked:G}){let[z,_]=Q2(!1),[H,K]=Q2(!1),[W,T]=Q2(null),[U,B]=Q2(!1),N=q.find((S)=>S.revision===$);Y4(()=>{if(!Z)_(!1),K(!1),T(null),B(!1)},[Z]);let M=u2(async()=>{_(!0),T(null);try{let S=await fetch(`/api/session/${Q}/revision/${$}/share`,{method:"POST"}),y=await S.json();if(!S.ok||!y.ok)throw Error(y.error||`HTTP ${S.status}`);X(y.share)}catch(S){T(S.message||String(S))}finally{_(!1)}},[Q,$,X]),O=u2(async(S)=>{if(!window.confirm("Revoke this share link? Reviewers will no longer be able to view or comment."))return;K(!0),T(null);try{let y=await fetch(`/api/session/${Q}/shares/${S}/revoke`,{method:"POST"}),b=await y.json();if(!y.ok||!b.ok)throw Error(b.error||`HTTP ${y.status}`);G(S)}catch(y){T(y.message||String(y))}finally{K(!1)}},[Q,G]),A=u2((S)=>{navigator.clipboard.writeText(S).then(()=>{B(!0),setTimeout(()=>B(!1),1500)})},[]);if(!Z)return null;return n("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:Y,children:n("div",{className:"bg-bg-surface border border-border-medium rounded-lg shadow-xl w-full max-w-md mx-4 p-5",onClick:(S)=>S.stopPropagation(),children:[n("div",{className:"flex items-center justify-between mb-3",children:[n("h2",{className:"text-sm font-medium text-text-primary font-body",children:"Share this revision"},void 0,!1,void 0,this),n("button",{onClick:Y,className:"w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",children:n("span",{className:"text-xs",children:"✕"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!J?n("div",{className:"text-[13px] text-text-secondary font-body space-y-2",children:[n("p",{children:"Canvas sharing is not configured."},void 0,!1,void 0,this),n("p",{className:"text-text-tertiary",children:["Set ",n("code",{className:"px-1 py-0.5 rounded bg-bg-elevated text-text-primary text-[11px]",children:"CANVAS_SHARE_ENDPOINT"},void 0,!1,void 0,this)," to the URL of a deployed"," ",n("code",{className:"px-1 py-0.5 rounded bg-bg-elevated text-text-primary text-[11px]",children:"canvas-share"},void 0,!1,void 0,this)," worker and restart the daemon."]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):N?n("div",{className:"space-y-3",children:[n("p",{className:"text-[13px] text-text-secondary font-body",children:"This revision is shared:"},void 0,!1,void 0,this),n("div",{className:"flex gap-2",children:[n("input",{type:"text",readOnly:!0,value:N.url,className:"flex-1 px-2 py-1.5 text-[12px] font-mono bg-bg-input border border-border-medium rounded text-text-primary",onFocus:(S)=>S.currentTarget.select()},void 0,!1,void 0,this),n("button",{onClick:()=>A(N.url),className:"px-3 py-1.5 text-[12px] font-body font-medium rounded bg-accent-blue text-white hover:opacity-90 transition-opacity whitespace-nowrap",children:U?"Copied!":"Copy"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),N.expiresAt&&n("p",{className:"text-[11px] text-text-tertiary font-body",children:["Expires ",new Date(N.expiresAt).toLocaleDateString(),"."]},void 0,!0,void 0,this),n("p",{className:"text-[11px] text-text-tertiary font-body",children:"Anyone with this link can view and leave feedback. Reviewer feedback will appear in your annotation sidebar within seconds."},void 0,!1,void 0,this),n("div",{className:"flex items-center justify-between pt-1",children:[n("button",{onClick:M,disabled:z||H,className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body underline disabled:opacity-50",children:z?"Creating...":"Create a new link"},void 0,!1,void 0,this),N.ownerToken&&n("button",{onClick:()=>O(N.shareId),disabled:z||H,className:"text-[11px] text-accent-red hover:opacity-80 font-body underline disabled:opacity-50",children:H?"Revoking...":"Revoke link"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):n("div",{className:"space-y-3",children:[n("p",{className:"text-[13px] text-text-secondary font-body",children:"Create a public link to this revision. Anyone with the link can view the canvas and leave feedback. Reviewer feedback will sync back here automatically."},void 0,!1,void 0,this),n("button",{onClick:M,disabled:z,className:"w-full px-3 py-2 text-[13px] font-body font-medium rounded bg-accent-blue text-white hover:opacity-90 transition-opacity disabled:opacity-50",children:z?"Creating share link...":"Create share link"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),W&&n("div",{className:"mt-3 px-3 py-2 rounded bg-accent-red/10 border border-accent-red/20 text-[12px] text-accent-red font-body",children:W},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function _3({onClick:Q,title:$="Share this revision",hasShare:Z}){return n("button",{onClick:Q,className:`group p-1.5 transition-colors ${Z?"text-accent-blue hover:opacity-80":"text-text-tertiary hover:text-text-secondary"}`,title:$,children:n("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n("circle",{cx:"18",cy:"5",r:"3"},void 0,!1,void 0,this),n("circle",{cx:"6",cy:"12",r:"3"},void 0,!1,void 0,this),n("circle",{cx:"18",cy:"19",r:"3"},void 0,!1,void 0,this),n("line",{x1:"8.59",y1:"13.51",x2:"15.42",y2:"17.49"},void 0,!1,void 0,this),n("line",{x1:"15.41",y1:"6.51",x2:"8.59",y2:"10.49"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}import{useState as X4,useEffect as z4,useRef as _4}from"react";import{jsxDEV as L1}from"react/jsx-dev-runtime";function G3({open:Q,onClose:$,onSubmit:Z}){let[J,q]=X4(""),Y=_4(null);if(z4(()=>{if(Q)q(""),setTimeout(()=>Y.current?.focus(),50)},[Q]),!Q)return null;let X=J.trim(),G=X.length>=1&&X.length<=80,z=()=>{if(!G)return;Z(X)};return L1("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:$,children:L1("div",{className:"bg-bg-surface border border-border-medium rounded-lg shadow-xl w-full max-w-md mx-4 p-5",onClick:(_)=>_.stopPropagation(),children:[L1("div",{className:"flex items-center justify-between mb-3",children:[L1("h2",{className:"text-sm font-medium text-text-primary font-body",children:"Your name"},void 0,!1,void 0,this),L1("button",{onClick:$,className:"w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",children:L1("span",{className:"text-xs",children:"✕"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),L1("p",{className:"text-[13px] text-text-secondary font-body mb-3 leading-relaxed",children:"Before you leave feedback, please enter a name so the canvas author knows who reviewed it. This is stored locally in your browser."},void 0,!1,void 0,this),L1("input",{ref:Y,type:"text",value:J,onChange:(_)=>q(_.target.value),onKeyDown:(_)=>{if(_.key==="Enter")z()},maxLength:80,placeholder:"e.g. Alice",className:"w-full px-3 py-2 text-[13px] font-body bg-bg-input border border-border-medium rounded text-text-primary placeholder:text-text-disabled focus:outline-none focus:border-accent-blue"},void 0,!1,void 0,this),L1("div",{className:"flex justify-end gap-2 mt-4",children:[L1("button",{onClick:$,className:"px-3 py-1.5 text-[12px] font-body font-medium rounded text-text-secondary hover:text-text-primary hover:bg-bg-elevated transition-colors",children:"Cancel"},void 0,!1,void 0,this),L1("button",{onClick:z,disabled:!G,className:"px-3 py-1.5 text-[12px] font-body font-medium rounded bg-accent-blue text-white hover:opacity-90 transition-opacity disabled:opacity-50",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)}import{jsxDEV as F,Fragment as A0}from"react/jsx-dev-runtime";function U3(Q){let $=[];for(let Z of Q)for(let J of Z.annotations)$.push({...J,source:"remote",author:Z.author});return $}var I1=N3({activeView:{type:"overview"},setActiveView:()=>{},openFiles:[],closeFile:()=>{},canvasFiles:[]}),w1=N3({currentRevision:1,selectedRevision:1,revisions:[],setSelectedRevision:()=>{},isReadOnly:!1,compareRevision:null,setCompareRevision:()=>{},agentWatching:!1});function H4(Q){if(Q==="auto")return window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light";return Q}function H3(Q){document.documentElement.dataset.theme=H4(Q)}function F3(){let[Q,$]=Q1(()=>{let q=localStorage.getItem("canvas-theme");if(q==="light"||q==="dark"||q==="auto")return q;return"auto"});return M1(()=>{if(H3(Q),Q!=="auto")return;let q=window.matchMedia("(prefers-color-scheme: dark)"),Y=()=>H3("auto");return q.addEventListener("change",Y),()=>q.removeEventListener("change",Y)},[Q]),F("button",{onClick:()=>{let q=Q==="auto"?"light":Q==="light"?"dark":"auto";localStorage.setItem("canvas-theme",q),$(q)},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:{auto:"Theme: system (click for light)",light:"Theme: light (click for dark)",dark:"Theme: dark (click for system)"}[Q],children:Q==="auto"?F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[F("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2",ry:"2"},void 0,!1,void 0,this),F("line",{x1:"8",y1:"21",x2:"16",y2:"21"},void 0,!1,void 0,this),F("line",{x1:"12",y1:"17",x2:"12",y2:"21"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):Q==="dark"?F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:F("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):F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[F("circle",{cx:"12",cy:"12",r:"5"},void 0,!1,void 0,this),F("line",{x1:"12",y1:"1",x2:"12",y2:"3"},void 0,!1,void 0,this),F("line",{x1:"12",y1:"21",x2:"12",y2:"23"},void 0,!1,void 0,this),F("line",{x1:"4.22",y1:"4.22",x2:"5.64",y2:"5.64"},void 0,!1,void 0,this),F("line",{x1:"18.36",y1:"18.36",x2:"19.78",y2:"19.78"},void 0,!1,void 0,this),F("line",{x1:"1",y1:"12",x2:"3",y2:"12"},void 0,!1,void 0,this),F("line",{x1:"21",y1:"12",x2:"23",y2:"12"},void 0,!1,void 0,this),F("line",{x1:"4.22",y1:"19.78",x2:"5.64",y2:"18.36"},void 0,!1,void 0,this),F("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)},void 0,!1,void 0,this)}function B3(){let{currentRevision:Q,selectedRevision:$,revisions:Z,setSelectedRevision:J,setCompareRevision:q}=u1.useContext(w1);if(Z.length<=1){let G=Z[0]?.label||`Round ${Q}`;return F("span",{className:"text-[11px] text-text-tertiary font-body",children:G},void 0,!1,void 0,this)}return F("div",{className:"flex flex-col gap-1",children:[F(P0,{value:$,onChange:J,accent:$===Q?"default":"amber"},void 0,!1,void 0,this),F("button",{onClick:()=>{let X;if($===Q)X=[...Z].reverse().find((z)=>z.revision<Q)?.revision??Math.max(1,Q-1);else X=$;q({left:X,right:Q})},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 W4(){let Q=Z1.isShared?Z1.shareId:Z1.sessionId,$=Z1.isShared,[Z,J]=Q1(1),[q,Y]=Q1(1),[X,G]=Q1([]),[z,_]=Q1(null),[H,K]=Q1(!1),[W,T]=Q1(!1),[U,B]=Q1(!1),[N,M]=Q1([]),[O,A]=Q1({type:"overview"}),[S,y]=Q1([]),b=g1(null),[C,E]=Q1(),[c,h]=Q1(!1),[R,x]=Q1(!1),[v,D]=Q1(!1),[I,g]=Q1(!1),[d,w]=Q1([]),[k,L]=Q1(!1),[l,u]=Q1(new Map),[m,a]=Q1(!1),[j,f]=Q1(null),[$1,K1]=Q1(null);M1(()=>{if(!$1)return;let V=setTimeout(()=>K1(null),4000);return()=>clearTimeout(V)},[$1]),M1(()=>{let V=["Agent Canvas"];if(C){let o=C.replace(/\/+$/,"").split("/");V.push(o[o.length-1]||Q)}else if(Q)V.push(Q);if(O.type==="file")V.push(O.path.split("/").pop()||O.path);else if(O.type==="overview")V.push("Overview");else if(O.type==="canvas"&&N.length>1&&O.filename)V.push(O.filename.replace(/\.jsx$/,""));else if(z)V.push("Compare");document.title=V.join(" — ")},[Q,C,O,z]);let v1=g1(new Map),A1=X.find((V)=>V.revision===q),e1=q!==Z||!!A1?.hasFeedback||W,g2=j0((V)=>{let o=O.type==="overview"?"overview":O.type==="canvas"?`canvas:${O.filename}`:`file:${O.path}`;if(v1.current.set(o,window.scrollY),A(V),V.type==="file")y((e)=>e.includes(V.path)?e:[...e,V.path])},[O]),L3=j0((V)=>{v1.current.delete(`file:${V}`),y((o)=>o.filter((e)=>e!==V)),A((o)=>{if(o.type==="file"&&o.path===V)return N.length>1?{type:"overview"}:{type:"canvas",filename:N[0]||""};return o})},[N]);G4(()=>{let V=O.type==="overview"?"overview":O.type==="canvas"?`canvas:${O.filename}`:`file:${O.path}`;window.scrollTo(0,v1.current.get(V)||0)},[O]),M1(()=>{if(!Q)return;fetch(G5()).then((V)=>V.json()).then((V)=>{if(V.currentRevision)J(V.currentRevision),Y(V.currentRevision),G(V.revisions||[]);if(V.canvasFiles){let o=V.canvasFiles.sort();M(o),A((e)=>{if(e.type==="overview")return o.length>1?e:{type:"canvas",filename:o[0]||""};if(e.type==="canvas"&&(!e.filename||!o.includes(e.filename)))return{type:"canvas",filename:o[0]||""};return e})}if(V.projectRoot)E(V.projectRoot);if(Array.isArray(V.shares))w(V.shares);L(!!V.shareEnabled)}).catch(()=>{})},[Q]),M1(()=>{if(!Q||!q||$)return;fetch(`/api/session/${Q}/revision/${q}/remote-feedback`).then((V)=>V.json()).then((V)=>{if(!Array.isArray(V.entries))return;let o=U3(V.entries);u((e)=>{let y1=new Map(e);return y1.set(q,o),y1})}).catch(()=>{})},[Q,q,$]),M1(()=>{if(!Q)return;if(!N5){K(!0);return}let V=null,o=()=>{let e=window.location.protocol==="https:"?"wss:":"ws:",y1=new WebSocket(`${e}//${window.location.host}/ws/session/${Q}`);b.current=y1,y1.onopen=()=>K(!0),y1.onclose=()=>{K(!1),V=setTimeout(o,2000)},y1.onmessage=(f2)=>{try{let G1=JSON.parse(f2.data);if(G1.type==="plan-updated"){if(J(G1.currentRevision),Y(G1.currentRevision),_(null),G1.revisions){let $0=G1.revisions;G($0);let _0=$0.find((f1)=>f1.revision===G1.currentRevision);if(_0?.canvasFiles){let f1=_0.canvasFiles.map((K0)=>K0.filename).sort();M(f1);let q2=$0.find((K0)=>K0.revision===G1.currentRevision-1),G0=m2(_0,q2),Q0=Y3(G0);if(Q0.length===1)A({type:"canvas",filename:Q0[0]});else if(Q0.length>1||f1.length>1)A({type:"overview"});else A({type:"canvas",filename:f1[0]||""})}}}if(G1.type==="revision-updated"){if(G1.revisions)G(G1.revisions)}if(G1.type==="watcher-status")B(!!G1.watching);if(G1.type==="remote-feedback"){let $0=G1.revision,_0=G1.entries||[],f1=U3(_0);u((q2)=>{let G0=new Map(q2),Q0=G0.get($0)||[],K0=new Set(Q0.map((J2)=>J2.id)),M3=[...Q0,...f1.filter((J2)=>!K0.has(J2.id))];return G0.set($0,M3),G0})}}catch{}}};return o(),()=>{if(V)clearTimeout(V);b.current?.close()}},[Q]);let Z2=j0(async(V,o)=>{try{let e=localStorage.getItem(`canvas:${Q}:rev:${q}`),y1=[];if(e)try{y1=(JSON.parse(e).annotations||[]).filter((G1)=>G1.source!=="remote")}catch{}await T5({author:o,revision:q,annotations:y1,generalNote:V}),T(!0),K1({kind:"success",message:"Feedback submitted. The canvas author will see it shortly."})}catch(e){K1({kind:"error",message:`Failed to submit feedback: ${e.message||e}`})}},[Q,q]),v2=j0(async(V)=>{if($){let o=F2();if(!o){f(V),a(!0);return}await Z2(V,o);return}if(b.current?.readyState===WebSocket.OPEN)b.current.send(JSON.stringify({type:"submit",feedback:V}))},[$,Z2]);if(!Q)return F("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 F(O3.Provider,{value:Q,children:F(w1.Provider,{value:{currentRevision:Z,selectedRevision:q,revisions:X,setSelectedRevision:Y,isReadOnly:e1,compareRevision:z,setCompareRevision:_,agentWatching:U},children:F(Y5,{sessionId:Q,revision:q,isReadOnly:e1,remoteAnnotations:l.get(q),children:F(I1.Provider,{value:{activeView:O,setActiveView:g2,openFiles:S,closeFile:L3,canvasFiles:N},children:F(U4.Provider,{value:{setActiveView:g2},children:F("div",{className:"min-h-screen bg-bg-base",children:[F(T4,{sessionId:Q,projectRoot:C,connected:H,onMobileSidebar:()=>h(!c),collapsed:R,onToggle:()=>x((V)=>!V)},void 0,!1,void 0,this),F(N4,{collapsed:v,onToggle:()=>D((V)=>!V),children:F(V2,{onSubmit:v2},void 0,!1,void 0,this)},void 0,!1,void 0,this),z!==null?F("div",{className:`${R?"lg:ml-0":"lg:ml-60"} ${v?"lg:mr-0":"lg:mr-[var(--sidebar-width,320px)]"} transition-[margin] duration-200`,children:F(Z3,{initialLeft:z.left,initialRight:z.right,sessionId:Q,onExit:()=>_(null)},void 0,!1,void 0,this)},void 0,!1,void 0,this):F("div",{className:`relative ${R?"lg:ml-0":"lg:ml-60"} ${v?"lg:mr-0":"lg:mr-[var(--sidebar-width,320px)]"} transition-[margin] duration-200`,id:"plan-scroll-container",children:[F("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:[F("div",{className:"flex items-center gap-2",children:[!$&&F(D2,{currentSessionId:Q,projectRoot:C},void 0,!1,void 0,this),$&&F("span",{className:"text-[11px] text-text-tertiary font-body",children:"Shared canvas"},void 0,!1,void 0,this),!$&&F("span",{className:`w-1.5 h-1.5 rounded-full ${H?"bg-accent-green":"bg-accent-red"}`},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("div",{className:"flex items-center gap-1",children:[F(B3,{},void 0,!1,void 0,this),F("button",{onClick:()=>h(!c),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:F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:F("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),F(F3,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),F(O4,{},void 0,!1,void 0,this),O.type==="overview"&&F(X3,{revision:q,responseBanner:A1?.response?F(W3,{markdown:A1.response},void 0,!1,void 0,this):void 0},void 0,!1,void 0,this),O.type==="canvas"&&N.includes(O.filename)&&F("div",{className:"relative max-w-[720px] mx-auto px-6 pt-12 pb-32",children:[k&&F("div",{className:"absolute top-3 right-12 z-10",children:F(_3,{onClick:()=>g(!0),hasShare:d.some((V)=>V.revision===q),title:d.some((V)=>V.revision===q)?"Manage share link":"Share this revision"},void 0,!1,void 0,this)},void 0,!1,void 0,this),F("button",{onClick:()=>{let V=document.querySelector(`[data-canvas-file="${O.filename}"] .plan-content`);if(!V)return;let o=p5(V);navigator.clipboard.writeText(o).then(()=>{let e=document.getElementById("export-md-btn");if(e)e.setAttribute("data-copied","true"),setTimeout(()=>{e.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:[F("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:[F("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"},void 0,!1,void 0,this),F("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),F("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:F("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),N.length<=1&&A1?.response&&F(W3,{markdown:A1.response},void 0,!1,void 0,this),F("div",{"data-canvas-file":O.filename,children:F(B0,{revision:q,filename:O.filename},O.filename,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),S.map((V)=>F("div",{style:{display:O.type==="file"&&O.path===V?void 0:"none"},children:F(g5,{path:V},void 0,!1,void 0,this)},V,!1,void 0,this))]},void 0,!0,void 0,this),c&&F("div",{className:"lg:hidden fixed inset-0 z-40 flex",children:[F("div",{className:"flex-1",onClick:()=>h(!1)},void 0,!1,void 0,this),F("div",{className:"w-80 max-w-[85vw] bg-bg-surface border-l border-border-subtle flex flex-col shadow-lg",children:[F("div",{className:"flex items-center justify-between px-4 py-2 border-b border-border-subtle flex-shrink-0",children:[F("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:"Sidebar"},void 0,!1,void 0,this),F("button",{onClick:()=>h(!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),F("div",{className:"flex-1 overflow-hidden",children:F(V2,{onSubmit:v2},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),F(z3,{sessionId:Q,revision:q,open:I,shareEnabled:k,existingShares:d,onClose:()=>g(!1),onShareCreated:(V)=>{w((o)=>[...o.filter((e)=>e.shareId!==V.shareId),V]),K1({kind:"success",message:"Share link created. Copy and send it to reviewers."})},onShareRevoked:(V)=>{w((o)=>o.filter((e)=>e.shareId!==V)),K1({kind:"success",message:"Share link revoked."})}},void 0,!1,void 0,this),F(G3,{open:m,onClose:()=>{a(!1),f(null)},onSubmit:async(V)=>{let o=W5(V);if(a(!1),j!==null)await Z2(j,o),f(null)}},void 0,!1,void 0,this),$1&&F("div",{className:`fixed bottom-4 left-1/2 -translate-x-1/2 z-50 px-4 py-2.5 rounded-lg shadow-lg text-[13px] font-body font-medium flex items-center gap-2 ${$1.kind==="error"?"bg-accent-red text-white":"bg-accent-green text-white"}`,children:[$1.message,F("button",{onClick:()=>K1(null),className:"ml-2 opacity-70 hover:opacity-100",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)},void 0,!1,void 0,this)},`${Q}:${q}`,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function T4({sessionId:Q,projectRoot:$,connected:Z,onMobileSidebar:J,collapsed:q,onToggle:Y}){let X=Z1.isShared;return F(A0,{children:[q&&F("button",{onClick:Y,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:F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[F("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"},void 0,!1,void 0,this),F("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),F("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 ${q?"-translate-x-full":""}`,children:[F("div",{className:"px-4 pt-4 pb-3 flex-shrink-0 border-b border-border-subtle",children:[F("div",{className:"flex items-center gap-2 mb-2",children:[F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",className:"text-text-tertiary flex-shrink-0",children:F("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),X?F("span",{className:"text-[12px] font-body text-text-secondary truncate flex-1",children:"Shared canvas"},void 0,!1,void 0,this):F(A0,{children:[F(D2,{currentSessionId:Q,projectRoot:$},void 0,!1,void 0,this),F("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${Z?"bg-accent-green":"bg-accent-red"}`},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("button",{onClick:Y,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:F("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[F("polyline",{points:"11 17 6 12 11 7"},void 0,!1,void 0,this),F("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),F(B3,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("div",{className:"flex-1 flex flex-col overflow-hidden",children:F(E5,{embedded:!0},void 0,!1,void 0,this)},void 0,!1,void 0,this),F("div",{className:"px-4 py-3 border-t border-border-subtle flex items-center justify-between flex-shrink-0",children:[F("span",{className:"text-[10px] text-text-tertiary font-body uppercase tracking-widest",children:"Theme"},void 0,!1,void 0,this),F(F3,{},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 N4({children:Q,collapsed:$,onToggle:Z}){let[J,q]=Q1(()=>{let H=localStorage.getItem("canvas-sidebar-width");return H?parseInt(H,10):320}),Y=g1(!1),X=g1(0),G=g1(0),z=g1(J);z.current=J;let _=j0((H)=>{H.preventDefault(),Y.current=!0,X.current=H.clientX,G.current=z.current;let K=(T)=>{if(!Y.current)return;let U=X.current-T.clientX,B=Math.max(240,Math.min(600,G.current+U));q(B),z.current=B},W=()=>{Y.current=!1,localStorage.setItem("canvas-sidebar-width",String(z.current)),document.removeEventListener("mousemove",K),document.removeEventListener("mouseup",W),document.body.style.cursor="",document.body.style.userSelect=""};document.addEventListener("mousemove",K),document.addEventListener("mouseup",W),document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[]);return M1(()=>{return document.documentElement.style.setProperty("--sidebar-width",`${J}px`),()=>{document.documentElement.style.removeProperty("--sidebar-width")}},[J]),F(A0,{children:[$&&F("button",{onClick:Z,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:F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:F("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),F("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:J},children:[F("div",{onMouseDown:_,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),u1.Children.map(Q,(H)=>u1.isValidElement(H)?u1.cloneElement(H,{collapseButton:F("button",{onClick:Z,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:F("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[F("polyline",{points:"13 17 18 12 13 7"},void 0,!1,void 0,this),F("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)}):H)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function W3({markdown:Q}){let[$,Z]=Q1(!1),J=K3(()=>t.parse(Q,{async:!1}),[Q]),q=g1(null),{annotations:Y,addAnnotationWithId:X,removeAnnotation:G,updateAnnotation:z,addAnnotationImage:_,removeAnnotationImage:H,activeAnnotationId:K,setActiveAnnotationId:W}=Y1(),[T,U]=Q1(null),[B,N]=Q1(null),M=K3(()=>Y.filter((b)=>b.filePath===T1),[Y]),[O,A]=Q1(Q);if(Q!==O)A(Q),Z(!1);M1(()=>{if(!q.current||M.length===0)return;let b=setTimeout(()=>{if(q.current)f0(q.current,M)},50);return()=>clearTimeout(b)},[J,M.length]);let S=g1(null);if(M1(()=>{g0(K,S.current),S.current=K},[K]),M1(()=>{let b=q.current;if(!b)return;let C=(h)=>{let R=h.target.closest("[data-annotation-id]");if(!R)return;h.stopPropagation();let x=R.getAttribute("data-annotation-id");if(x===K)N({anchorEl:R,annId:x});else W(x)},E=(h)=>{let R=h.target.closest("[data-annotation-id]");if(R)W(R.getAttribute("data-annotation-id"))},c=(h)=>{let R=h.target.closest("[data-annotation-id]"),x=h.relatedTarget?.closest?.("[data-annotation-id]");if(R&&!x)W(null)};return b.addEventListener("click",C),b.addEventListener("mouseover",E),b.addEventListener("mouseout",c),()=>{b.removeEventListener("click",C),b.removeEventListener("mouseover",E),b.removeEventListener("mouseout",c)}},[J,K]),M1(()=>{let b=()=>{let C=window.getSelection();if(!C||C.isCollapsed||!C.toString().trim())return;if(!q.current)return;let E=C.getRangeAt(0);if(!q.current.contains(E.startContainer))return;if(E.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let c=C.toString().trim();if(c.length<2)return;let h=E.cloneRange(),R=d1(E,q.current),x=`__pending_${Date.now()}`;try{l1(h,x)}catch{}window.getSelection()?.removeAllRanges();let v=document.querySelectorAll(`[data-annotation-id="${x}"]`),D=v[v.length-1];if(!D)return;U({anchorEl:D,tempId:x,snippet:c,ctx:R})};return document.addEventListener("mouseup",b),()=>document.removeEventListener("mouseup",b)},[]),$)return null;let y=document.getElementById("plan-scroll-container");return F("div",{className:"mb-6 rounded-lg border border-accent-blue/20 bg-accent-blue/5 relative",children:[F("button",{onClick:()=>Z(!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:F("span",{className:"text-xs",children:"✕"},void 0,!1,void 0,this)},void 0,!1,void 0,this),F("div",{className:"px-4 py-3 pr-10",children:[F("div",{className:"flex items-center gap-2 mb-1.5",children:[F("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:F("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),F("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),F("div",{ref:q,className:"prose-canvas text-sm",dangerouslySetInnerHTML:{__html:J}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),T&&F(q0,{anchorEl:T.anchorEl,scrollContainer:y,snippet:T.snippet,truncateAt:80,onAdd:(b,C)=>{let E=F1();v0(T.tempId,E),X(E,T.snippet,b,T1,T.ctx,C),U(null)},onCancel:()=>{h0(T.tempId),U(null)}},void 0,!1,void 0,this),B&&(()=>{let b=Y.find((C)=>C.id===B.annId);if(!b)return null;return F(J0,{anchorEl:B.anchorEl,scrollContainer:y,initialNote:b.note,initialImages:b.images,onUpdate:(C,E)=>{z(B.annId,C);let c=b.images||[];for(let h of E)if(!c.includes(h))_(B.annId,h);for(let h of c)if(!E.includes(h))H(B.annId,h)},onDelete:()=>{G(B.annId),W(null)},onClose:()=>N(null)},void 0,!1,void 0,this)})()]},void 0,!0,void 0,this)}function O4(){let{activeView:Q,setActiveView:$,openFiles:Z,closeFile:J,canvasFiles:q}=u1.useContext(I1),Y=u1.useContext(O3),{addAnnotationWithId:X,setActiveAnnotationId:G}=Y1();if(!(q.length>1||Z.length>0))return null;return F("div",{className:"flex items-center border-b border-border-medium bg-bg-surface overflow-x-auto sticky top-0 z-10",children:[q.length>1&&F(A0,{children:[F("button",{onClick:()=>$({type:"overview"}),className:`flex items-center gap-1.5 px-4 py-2.5 text-[13px] font-body whitespace-nowrap transition-colors relative ${Q.type==="overview"?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",className:"opacity-60",children:F("path",{d:"M12 7L2 12l10 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),"Overview",Q.type==="overview"&&F("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),F("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),q.map((_,H)=>{let K=_.replace(/\.jsx$/,""),W=Q.type==="canvas"&&Q.filename===_;return F(u1.Fragment,{children:[F("button",{onClick:()=>$({type:"canvas",filename:_}),className:`flex items-center gap-1.5 px-4 py-2.5 text-[13px] font-body whitespace-nowrap transition-colors relative ${W?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[K,W&&F("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),H<q.length-1&&F("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this)]},_,!0,void 0,this)}),Z.length>0&&F(A0,{children:[F("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this),Z.map((_,H)=>{let K=_.split("/").pop()||_,W=Q.type==="file"&&Q.path===_;return F(u1.Fragment,{children:[F("div",{className:"flex items-center",children:[F("button",{onClick:()=>$({type:"file",path:_}),className:`flex items-center gap-1.5 pl-3 pr-1 py-2.5 text-[13px] font-body whitespace-nowrap transition-colors relative ${W?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[F(k1,{name:K,type:"file"},void 0,!1,void 0,this),K,W&&F("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),F("button",{onClick:(T)=>{T.stopPropagation(),J(_)},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),H<Z.length-1&&F("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this)]},_,!0,void 0,this)})]},void 0,!0,void 0,this),F("div",{className:"ml-auto flex items-center gap-1 flex-shrink-0",children:Q.type==="file"&&B1&&F("button",{onClick:async()=>{let _=Q.path;try{let K=await(await fetch(`/api/file?session=${Y}&path=${encodeURIComponent(_)}`)).json();if(!K.error){let W=K.content.split(`
|
|
88
88
|
`).slice(0,3).join(`
|
|
89
89
|
`)+(K.content.split(`
|
|
90
90
|
`).length>3?`
|
|
91
|
-
...`:""),T=F1();
|
|
91
|
+
...`:""),T=F1();X(T,W,"",_),G(T)}}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:[F("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 T3=document.getElementById("root");if(T3)K4(T3).render(F(W4,{},void 0,!1,void 0,this));export{w1 as RevisionContext,I1 as ActiveViewContext};
|