agent-canvas 0.1.30 → 0.1.32
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/bun.lock +46 -322
- package/daemon/client/useTextAnnotation.tsx +3 -2
- package/daemon/dist/client.css +1 -1
- package/daemon/dist/client.js +52 -52
- package/daemon/dist/components.js +28 -28
- package/daemon/dist/preact-compat.js +1 -1
- package/daemon/src/compiler.ts +4 -10
- package/daemon/src/remote-feedback.test.ts +0 -14
- package/daemon/src/share.test.ts +0 -7
- package/package.json +2 -2
- package/workers/canvas-share/public/assets/client.css +1 -1
- package/workers/canvas-share/public/assets/client.js +52 -52
- package/workers/canvas-share/public/assets/components.js +28 -28
- package/workers/canvas-share/public/assets/preact-compat.js +1 -1
package/daemon/dist/client.js
CHANGED
|
@@ -1,91 +1,91 @@
|
|
|
1
|
-
import u1,{useEffect as M1,useLayoutEffect as
|
|
2
|
-
]`).replace("lheading",
|
|
3
|
-
`).map((
|
|
4
|
-
`)}var
|
|
5
|
-
`)}}}fences(
|
|
6
|
-
`)}}blockquote(
|
|
1
|
+
import u1,{useEffect as M1,useLayoutEffect as X4,useState as Y1,useCallback as A0,useRef as g1,createContext as T3,useMemo as G3}from"react";import{createRoot as z4}from"react-dom/client";function z2(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var c1=z2();function a2(Y){c1=Y}var h1={exec:()=>null};function s(Y,$=""){let Z=typeof Y=="string"?Y:Y.source,J={replace:(q,Q)=>{let X=typeof Q=="string"?Q:Q.source;return X=X.replace(U1.caret,"$1"),Z=Z.replace(q,X),J},getRegex:()=>new RegExp(Z,$)};return J}var M3=(()=>{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:(Y)=>new RegExp(`^( {0,3}${Y})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:(Y)=>new RegExp(`^ {0,${Math.min(3,Y-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:(Y)=>new RegExp(`^ {0,${Math.min(3,Y-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:(Y)=>new RegExp(`^ {0,${Math.min(3,Y-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:(Y)=>new RegExp(`^ {0,${Math.min(3,Y-1)}}#`),htmlBeginRegex:(Y)=>new RegExp(`^ {0,${Math.min(3,Y-1)}}<(?:[a-z].*>|!--)`,"i"),blockquoteBeginRegex:(Y)=>new RegExp(`^ {0,${Math.min(3,Y-1)}}>`)},y3=/^(?:[ \t]*(?:\n|$))+/,P3=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,S3=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,N0=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,b3=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,_2=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,o2=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,s2=s(o2).replace(/bull/g,_2).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(),w3=s(o2).replace(/bull/g,_2).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(),G2=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,j3=/^[^\n]+/,K2=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,A3=s(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",K2).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),C3=s(/^(bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,_2).getRegex(),k0="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",U2=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,I3=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",U2).replace("tag",k0).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),t2=s(G2).replace("hr",N0).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",k0).getRegex(),V3=s(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",t2).getRegex(),H2={blockquote:V3,code:P3,def:A3,fences:S3,heading:b3,hr:N0,html:I3,lheading:s2,list:C3,newline:y3,paragraph:t2,table:h1,text:j3},p2=s("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",N0).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",k0).getRegex(),R3={...H2,lheading:w3,table:p2,paragraph:s(G2).replace("hr",N0).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",p2).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",k0).getRegex()},D3={...H2,html:s(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",U2).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(G2).replace("hr",N0).replace("heading",` *#{1,6} *[^
|
|
2
|
+
]`).replace("lheading",s2).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},k3=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,E3=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,n2=/^( {2,}|\\)\n(?!\s*$)/,x3=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,Z0=/[\p{P}\p{S}]/u,E0=/[\s\p{P}\p{S}]/u,W2=/[^\s\p{P}\p{S}]/u,m3=s(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,E0).getRegex(),e2=/(?!~)[\p{P}\p{S}]/u,u3=/(?!~)[\s\p{P}\p{S}]/u,g3=/(?:[^\s\p{P}\p{S}]|~)/u,v3=s(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",M3?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),$5=/^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/,f3=s($5,"u").replace(/punct/g,Z0).getRegex(),h3=s($5,"u").replace(/punct/g,e2).getRegex(),Y5="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",p3=s(Y5,"gu").replace(/notPunctSpace/g,W2).replace(/punctSpace/g,E0).replace(/punct/g,Z0).getRegex(),c3=s(Y5,"gu").replace(/notPunctSpace/g,g3).replace(/punctSpace/g,u3).replace(/punct/g,e2).getRegex(),d3=s("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,W2).replace(/punctSpace/g,E0).replace(/punct/g,Z0).getRegex(),r3=s(/^~~?(?:((?!~)punct)|[^\s~])/,"u").replace(/punct/g,Z0).getRegex(),l3="^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)",i3=s(l3,"gu").replace(/notPunctSpace/g,W2).replace(/punctSpace/g,E0).replace(/punct/g,Z0).getRegex(),a3=s(/\\(punct)/,"gu").replace(/punct/g,Z0).getRegex(),o3=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(),s3=s(U2).replace("(?:-->|$)","-->").getRegex(),t3=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",s3).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),V0=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/,n3=s(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace("label",V0).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),Z5=s(/^!?\[(label)\]\[(ref)\]/).replace("label",V0).replace("ref",K2).getRegex(),q5=s(/^!?\[(ref)\](?:\[\])?/).replace("ref",K2).getRegex(),e3=s("reflink|nolink(?!\\()","g").replace("reflink",Z5).replace("nolink",q5).getRegex(),c2=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,T2={_backpedal:h1,anyPunctuation:a3,autolink:o3,blockSkip:v3,br:n2,code:E3,del:h1,delLDelim:h1,delRDelim:h1,emStrongLDelim:f3,emStrongRDelimAst:p3,emStrongRDelimUnd:d3,escape:k3,link:n3,nolink:q5,punctuation:m3,reflink:Z5,reflinkSearch:e3,tag:t3,text:x3,url:h1},$7={...T2,link:s(/^!?\[(label)\]\((.*?)\)/).replace("label",V0).getRegex(),reflink:s(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",V0).getRegex()},X2={...T2,emStrongRDelimAst:c3,emStrongLDelim:h3,delLDelim:r3,delRDelim:i3,url:s(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol",c2).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",c2).getRegex()},Y7={...X2,br:s(n2).replace("{2,}","*").getRegex(),text:s(X2.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},I0={normal:H2,gfm:R3,pedantic:D3},H0={normal:T2,gfm:X2,breaks:Y7,pedantic:$7},Z7={"&":"&","<":"<",">":">",'"':""","'":"'"},d2=(Y)=>Z7[Y];function P1(Y,$){if($){if(U1.escapeTest.test(Y))return Y.replace(U1.escapeReplace,d2)}else if(U1.escapeTestNoEncode.test(Y))return Y.replace(U1.escapeReplaceNoEncode,d2);return Y}function r2(Y){try{Y=encodeURI(Y).replace(U1.percentDecode,"%")}catch{return null}return Y}function l2(Y,$){let Z=Y.replace(U1.findPipe,(Q,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 W0(Y,$,Z){let J=Y.length;if(J===0)return"";let q=0;for(;q<J;){let Q=Y.charAt(J-q-1);if(Q===$&&!Z)q++;else if(Q!==$&&Z)q++;else break}return Y.slice(0,J-q)}function q7(Y,$){if(Y.indexOf($[1])===-1)return-1;let Z=0;for(let J=0;J<Y.length;J++)if(Y[J]==="\\")J++;else if(Y[J]===$[0])Z++;else if(Y[J]===$[1]&&(Z--,Z<0))return J;return Z>0?-2:-1}function J7(Y,$=0){let Z=$,J="";for(let q of Y)if(q==="\t"){let Q=4-Z%4;J+=" ".repeat(Q),Z+=Q}else J+=q,Z++;return J}function i2(Y,$,Z,J,q){let Q=$.href,X=$.title||null,G=Y[1].replace(q.other.outputLinkReplace,"$1");J.state.inLink=!0;let z={type:Y[0].charAt(0)==="!"?"image":"link",raw:Z,href:Q,title:X,text:G,tokens:J.inlineTokens(G)};return J.state.inLink=!1,z}function Q7(Y,$,Z){let J=Y.match(Z.other.indentCodeCompensation);if(J===null)return $;let q=J[1];return $.split(`
|
|
3
|
+
`).map((Q)=>{let X=Q.match(Z.other.beginningSpace);if(X===null)return Q;let[G]=X;return G.length>=q.length?Q.slice(q.length):Q}).join(`
|
|
4
|
+
`)}var R0=class{options;rules;lexer;constructor(Y){this.options=Y||c1}space(Y){let $=this.rules.block.newline.exec(Y);if($&&$[0].length>0)return{type:"space",raw:$[0]}}code(Y){let $=this.rules.block.code.exec(Y);if($){let Z=$[0].replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:$[0],codeBlockStyle:"indented",text:this.options.pedantic?Z:W0(Z,`
|
|
5
|
+
`)}}}fences(Y){let $=this.rules.block.fences.exec(Y);if($){let Z=$[0],J=Q7(Z,$[3]||"",this.rules);return{type:"code",raw:Z,lang:$[2]?$[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):$[2],text:J}}}heading(Y){let $=this.rules.block.heading.exec(Y);if($){let Z=$[2].trim();if(this.rules.other.endingHash.test(Z)){let J=W0(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(Y){let $=this.rules.block.hr.exec(Y);if($)return{type:"hr",raw:W0($[0],`
|
|
6
|
+
`)}}blockquote(Y){let $=this.rules.block.blockquote.exec(Y);if($){let Z=W0($[0],`
|
|
7
7
|
`).split(`
|
|
8
|
-
`),J="",q="",
|
|
8
|
+
`),J="",q="",Q=[];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
9
|
`),H=_.replace(this.rules.other.blockquoteSetextReplace,`
|
|
10
10
|
$1`).replace(this.rules.other.blockquoteSetextReplace2,"");J=J?`${J}
|
|
11
11
|
${_}`:_,q=q?`${q}
|
|
12
|
-
${H}`:H;let K=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(H,
|
|
12
|
+
${H}`:H;let K=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(H,Q,!0),this.lexer.state.top=K,Z.length===0)break;let W=Q.at(-1);if(W?.type==="code")break;if(W?.type==="blockquote"){let T=W,U=T.raw+`
|
|
13
13
|
`+Z.join(`
|
|
14
|
-
`),B=this.blockquote(U);
|
|
14
|
+
`),B=this.blockquote(U);Q[Q.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
|
-
`),B=this.list(U);
|
|
17
|
-
`);continue}}return{type:"blockquote",raw:J,tokens:
|
|
18
|
-
`,1)[0],$[1].length),W=
|
|
16
|
+
`),B=this.list(U);Q[Q.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(Q.at(-1).raw.length).split(`
|
|
17
|
+
`);continue}}return{type:"blockquote",raw:J,tokens:Q,text:q}}}list(Y){let $=this.rules.block.list.exec(Y);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 Q=this.rules.other.listItemRegex(Z),X=!1;for(;Y;){let z=!1,_="",H="";if(!($=Q.exec(Y))||this.rules.block.hr.test(Y))break;_=$[0],Y=Y.substring(_.length);let K=J7($[2].split(`
|
|
18
|
+
`,1)[0],$[1].length),W=Y.split(`
|
|
19
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
|
-
`,
|
|
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)||
|
|
20
|
+
`,Y=Y.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),C=this.rules.other.htmlBeginRegex(U),S=this.rules.other.blockquoteBeginRegex(U);for(;Y;){let y=Y.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)||C.test(W)||S.test(W)||B.test(W)||N.test(W))break;if(b.search(this.rules.other.nonSpaceChar)>=U||!W.trim())H+=`
|
|
22
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
23
|
`+W}T=!W.trim(),_+=y+`
|
|
24
|
-
`,
|
|
25
|
-
`):[],
|
|
26
|
-
`?$[1].slice(0,-1):$[1];return{type:"paragraph",raw:$[0],text:Z,tokens:this.lexer.inline(Z)}}}text(
|
|
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+=`
|
|
24
|
+
`,Y=Y.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(Y){let $=this.rules.block.html.exec(Y);if($)return{type:"html",block:!0,raw:$[0],pre:$[1]==="pre"||$[1]==="script"||$[1]==="style",text:$[0]}}def(Y){let $=this.rules.block.def.exec(Y);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(Y){let $=this.rules.block.table.exec(Y);if(!$||!this.rules.other.tableDelimiter.test($[2]))return;let Z=l2($[1]),J=$[2].replace(this.rules.other.tableAlignChars,"").split("|"),q=$[3]?.trim()?$[3].replace(this.rules.other.tableRowBlankLine,"").split(`
|
|
25
|
+
`):[],Q={type:"table",raw:$[0],header:[],align:[],rows:[]};if(Z.length===J.length){for(let X of J)this.rules.other.tableAlignRight.test(X)?Q.align.push("right"):this.rules.other.tableAlignCenter.test(X)?Q.align.push("center"):this.rules.other.tableAlignLeft.test(X)?Q.align.push("left"):Q.align.push(null);for(let X=0;X<Z.length;X++)Q.header.push({text:Z[X],tokens:this.lexer.inline(Z[X]),header:!0,align:Q.align[X]});for(let X of q)Q.rows.push(l2(X,Q.header.length).map((G,z)=>({text:G,tokens:this.lexer.inline(G),header:!1,align:Q.align[z]})));return Q}}lheading(Y){let $=this.rules.block.lheading.exec(Y);if($){let Z=$[1].trim();return{type:"heading",raw:$[0],depth:$[2].charAt(0)==="="?1:2,text:Z,tokens:this.lexer.inline(Z)}}}paragraph(Y){let $=this.rules.block.paragraph.exec(Y);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(Y){let $=this.rules.block.text.exec(Y);if($)return{type:"text",raw:$[0],text:$[0],tokens:this.lexer.inline($[0])}}escape(Y){let $=this.rules.inline.escape.exec(Y);if($)return{type:"escape",raw:$[0],text:$[1]}}tag(Y){let $=this.rules.inline.tag.exec(Y);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(Y){let $=this.rules.inline.link.exec(Y);if($){let Z=$[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(Z)){if(!this.rules.other.endAngleBracket.test(Z))return;let Q=W0(Z.slice(0,-1),"\\");if((Z.length-Q.length)%2===0)return}else{let Q=q7($[2],"()");if(Q===-2)return;if(Q>-1){let X=($[0].indexOf("!")===0?5:4)+$[1].length+Q;$[2]=$[2].substring(0,Q),$[0]=$[0].substring(0,X).trim(),$[3]=""}}let J=$[2],q="";if(this.options.pedantic){let Q=this.rules.other.pedanticHrefTitle.exec(J);Q&&(J=Q[1],q=Q[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)),i2($,{href:J&&J.replace(this.rules.inline.anyPunctuation,"$1"),title:q&&q.replace(this.rules.inline.anyPunctuation,"$1")},$[0],this.lexer,this.rules)}}reflink(Y,$){let Z;if((Z=this.rules.inline.reflink.exec(Y))||(Z=this.rules.inline.nolink.exec(Y))){let J=(Z[2]||Z[1]).replace(this.rules.other.multipleSpaceGlobal," "),q=$[J.toLowerCase()];if(!q){let Q=Z[0].charAt(0);return{type:"text",raw:Q,text:Q}}return i2(Z,q,Z[0],this.lexer,this.rules)}}emStrong(Y,$,Z=""){let J=this.rules.inline.emStrongLDelim.exec(Y);if(!J||!J[1]&&!J[2]&&!J[3]&&!J[4]||J[4]&&Z.match(this.rules.other.unicodeAlphaNumeric))return;if(!(J[1]||J[3])||!Z||this.rules.inline.punctuation.exec(Z)){let q=[...J[0]].length-1,Q,X,G=q,z=0,_=J[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(_.lastIndex=0,$=$.slice(-1*Y.length+q);(J=_.exec($))!==null;){if(Q=J[1]||J[2]||J[3]||J[4]||J[5]||J[6],!Q)continue;if(X=[...Q].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=Y.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(Y){let $=this.rules.inline.code.exec(Y);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(Y){let $=this.rules.inline.br.exec(Y);if($)return{type:"br",raw:$[0]}}del(Y,$,Z=""){let J=this.rules.inline.delLDelim.exec(Y);if(!J)return;if(!J[1]||!Z||this.rules.inline.punctuation.exec(Z)){let q=[...J[0]].length-1,Q,X,G=q,z=this.rules.inline.delRDelim;for(z.lastIndex=0,$=$.slice(-1*Y.length+q);(J=z.exec($))!==null;){if(Q=J[1]||J[2]||J[3]||J[4]||J[5]||J[6],!Q||(X=[...Q].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=Y.slice(0,q+J.index+_+X),K=H.slice(q,-q);return{type:"del",raw:H,text:K,tokens:this.lexer.inlineTokens(K)}}}}autolink(Y){let $=this.rules.inline.autolink.exec(Y);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(Y){let $;if($=this.rules.inline.url.exec(Y)){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(Y){let $=this.rules.inline.text.exec(Y);if($){let Z=this.lexer.state.inRawBlock;return{type:"text",raw:$[0],text:$[0],escaped:Z}}}},N1=class Y{tokens;options;state;inlineQueue;tokenizer;constructor($){this.tokens=[],this.tokens.links=Object.create(null),this.options=$||c1,this.options.tokenizer=this.options.tokenizer||new R0,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:I0.normal,inline:H0.normal};this.options.pedantic?(Z.block=I0.pedantic,Z.inline=H0.pedantic):this.options.gfm&&(Z.block=I0.gfm,this.options.breaks?Z.inline=H0.breaks:Z.inline=H0.gfm),this.tokenizer.rules=Z}static get rules(){return{block:I0,inline:H0}}static lex($,Z){return new Y(Z).lex($)}static lexInline($,Z){return new Y(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.tokenizer.lexer=this,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
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
30
|
`)+q.raw,X.text+=`
|
|
31
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
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
|
|
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 Q=$;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&&(Q=$.substring(0,X+1))}if(this.state.top&&(q=this.tokenizer.paragraph(Q))){let X=Z.at(-1);J&&X?.type==="paragraph"?(X.raw+=(X.raw.endsWith(`
|
|
35
35
|
`)?"":`
|
|
36
36
|
`)+q.raw,X.text+=`
|
|
37
|
-
`+q.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=X.text):Z.push(q),J=
|
|
37
|
+
`+q.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=X.text):Z.push(q),J=Q.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
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))
|
|
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=[]){this.tokenizer.lexer=this;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 Q;for(;(q=this.tokenizer.rules.inline.blockSkip.exec(J))!==null;)Q=q[2]?q[2].length:0,J=J.slice(0,q.index+Q)+"["+"a".repeat(q[0].length-Q-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}},D0=class{options;parser;constructor(Y){this.options=Y||c1}space(Y){return""}code({text:Y,lang:$,escaped:Z}){let J=($||"").match(U1.notSpaceStart)?.[0],q=Y.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
|
-
`}blockquote({tokens:
|
|
44
|
-
${this.parser.parse(
|
|
45
|
-
`}html({text:
|
|
46
|
-
`}hr(
|
|
47
|
-
`}list(
|
|
43
|
+
`}blockquote({tokens:Y}){return`<blockquote>
|
|
44
|
+
${this.parser.parse(Y)}</blockquote>
|
|
45
|
+
`}html({text:Y}){return Y}def(Y){return""}heading({tokens:Y,depth:$}){return`<h${$}>${this.parser.parseInline(Y)}</h${$}>
|
|
46
|
+
`}hr(Y){return`<hr>
|
|
47
|
+
`}list(Y){let{ordered:$,start:Z}=Y,J="";for(let X=0;X<Y.items.length;X++){let G=Y.items[X];J+=this.listitem(G)}let q=$?"ol":"ul",Q=$&&Z!==1?' start="'+Z+'"':"";return"<"+q+Q+`>
|
|
48
48
|
`+J+"</"+q+`>
|
|
49
|
-
`}listitem(
|
|
50
|
-
`}checkbox({checked:
|
|
51
|
-
`}table(
|
|
49
|
+
`}listitem(Y){return`<li>${this.parser.parse(Y.tokens)}</li>
|
|
50
|
+
`}checkbox({checked:Y}){return"<input "+(Y?'checked="" ':"")+'disabled="" type="checkbox"> '}paragraph({tokens:Y}){return`<p>${this.parser.parseInline(Y)}</p>
|
|
51
|
+
`}table(Y){let $="",Z="";for(let q=0;q<Y.header.length;q++)Z+=this.tablecell(Y.header[q]);$+=this.tablerow({text:Z});let J="";for(let q=0;q<Y.rows.length;q++){let Q=Y.rows[q];Z="";for(let X=0;X<Q.length;X++)Z+=this.tablecell(Q[X]);J+=this.tablerow({text:Z})}return J&&(J=`<tbody>${J}</tbody>`),`<table>
|
|
52
52
|
<thead>
|
|
53
53
|
`+$+`</thead>
|
|
54
54
|
`+J+`</table>
|
|
55
|
-
`}tablerow({text:
|
|
56
|
-
${
|
|
57
|
-
`}tablecell(
|
|
58
|
-
`}strong({tokens:
|
|
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(`
|
|
55
|
+
`}tablerow({text:Y}){return`<tr>
|
|
56
|
+
${Y}</tr>
|
|
57
|
+
`}tablecell(Y){let $=this.parser.parseInline(Y.tokens),Z=Y.header?"th":"td";return(Y.align?`<${Z} align="${Y.align}">`:`<${Z}>`)+$+`</${Z}>
|
|
58
|
+
`}strong({tokens:Y}){return`<strong>${this.parser.parseInline(Y)}</strong>`}em({tokens:Y}){return`<em>${this.parser.parseInline(Y)}</em>`}codespan({text:Y}){return`<code>${P1(Y,!0)}</code>`}br(Y){return"<br>"}del({tokens:Y}){return`<del>${this.parser.parseInline(Y)}</del>`}link({href:Y,title:$,tokens:Z}){let J=this.parser.parseInline(Z),q=r2(Y);if(q===null)return J;Y=q;let Q='<a href="'+Y+'"';return $&&(Q+=' title="'+P1($)+'"'),Q+=">"+J+"</a>",Q}image({href:Y,title:$,text:Z,tokens:J}){J&&(Z=this.parser.parseInline(J,this.parser.textRenderer));let q=r2(Y);if(q===null)return P1(Z);Y=q;let Q=`<img src="${Y}" alt="${P1(Z)}"`;return $&&(Q+=` title="${P1($)}"`),Q+=">",Q}text(Y){return"tokens"in Y&&Y.tokens?this.parser.parseInline(Y.tokens):("escaped"in Y)&&Y.escaped?Y.text:P1(Y.text)}},N2=class{strong({text:Y}){return Y}em({text:Y}){return Y}codespan({text:Y}){return Y}del({text:Y}){return Y}html({text:Y}){return Y}text({text:Y}){return Y}link({text:Y}){return""+Y}image({text:Y}){return""+Y}br(){return""}checkbox({raw:Y}){return Y}},O1=class Y{options;renderer;textRenderer;constructor($){this.options=$||c1,this.options.renderer=this.options.renderer||new D0,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new N2}static parse($,Z){return new Y(Z).parse($)}static parseInline($,Z){return new Y(Z).parseInline($)}parse($){this.renderer.parser=this;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 Q=q;switch(Q.type){case"space":{Z+=this.renderer.space(Q);break}case"hr":{Z+=this.renderer.hr(Q);break}case"heading":{Z+=this.renderer.heading(Q);break}case"code":{Z+=this.renderer.code(Q);break}case"table":{Z+=this.renderer.table(Q);break}case"blockquote":{Z+=this.renderer.blockquote(Q);break}case"list":{Z+=this.renderer.list(Q);break}case"checkbox":{Z+=this.renderer.checkbox(Q);break}case"html":{Z+=this.renderer.html(Q);break}case"def":{Z+=this.renderer.def(Q);break}case"paragraph":{Z+=this.renderer.paragraph(Q);break}case"text":{Z+=this.renderer.text(Q);break}default:{let X='Token with "'+Q.type+'" type was not found.';if(this.options.silent)return console.error(X),"";throw Error(X)}}}return Z}parseInline($,Z=this.renderer){this.renderer.parser=this;let J="";for(let q=0;q<$.length;q++){let Q=$[q];if(this.options.extensions?.renderers?.[Q.type]){let G=this.options.extensions.renderers[Q.type].call({parser:this},Q);if(G!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(Q.type)){J+=G||"";continue}}let X=Q;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}},T0=class{options;block;constructor(Y){this.options=Y||c1}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens","emStrongMask"]);static passThroughHooksRespectAsync=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(Y){return Y}postprocess(Y){return Y}processAllTokens(Y){return Y}emStrongMask(Y){return Y}provideLexer(Y=this.block){return Y?N1.lex:N1.lexInline}provideParser(Y=this.block){return Y?O1.parse:O1.parseInline}},X7=class{defaults=z2();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=O1;Renderer=D0;TextRenderer=N2;Lexer=N1;Tokenizer=R0;Hooks=T0;constructor(...Y){this.use(...Y)}walkTokens(Y,$){let Z=[];for(let J of Y)switch(Z=Z.concat($.call(this,J)),J.type){case"table":{let q=J;for(let Q of q.header)Z=Z.concat(this.walkTokens(Q.tokens,$));for(let Q of q.rows)for(let X of Q)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((Q)=>{let X=q[Q].flat(1/0);Z=Z.concat(this.walkTokens(X,$))}):q.tokens&&(Z=Z.concat(this.walkTokens(q.tokens,$)))}}return Z}use(...Y){let $=this.defaults.extensions||{renderers:{},childTokens:{}};return Y.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 Q=$.renderers[q.name];Q?$.renderers[q.name]=function(...X){let G=q.renderer.apply(this,X);return G===!1&&(G=Q.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 Q=$[q.level];Q?Q.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 D0(this.defaults);for(let Q in Z.renderer){if(!(Q in q))throw Error(`renderer '${Q}' does not exist`);if(["options","parser"].includes(Q))continue;let X=Q,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 R0(this.defaults);for(let Q in Z.tokenizer){if(!(Q in q))throw Error(`tokenizer '${Q}' does not exist`);if(["options","rules","lexer"].includes(Q))continue;let X=Q,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 T0;for(let Q in Z.hooks){if(!(Q in q))throw Error(`hook '${Q}' does not exist`);if(["options","block"].includes(Q))continue;let X=Q,G=Z.hooks[X],z=q[X];T0.passThroughHooks.has(Q)?q[X]=(_)=>{if(this.defaults.async&&T0.passThroughHooksRespectAsync.has(Q))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,Q=Z.walkTokens;J.walkTokens=function(X){let G=[];return G.push(Q.call(this,X)),q&&(G=G.concat(q.call(this,X))),G}}this.defaults={...this.defaults,...J}}),this}setOptions(Y){return this.defaults={...this.defaults,...Y},this}lexer(Y,$){return N1.lex(Y,$??this.defaults)}parser(Y,$){return O1.parse(Y,$??this.defaults)}parseMarkdown(Y){return($,Z)=>{let J={...Z},q={...this.defaults,...J},Q=this.onError(!!q.silent,!!q.async);if(this.defaults.async===!0&&J.async===!1)return Q(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 Q(Error("marked(): input parameter is undefined or null"));if(typeof $!="string")return Q(Error("marked(): input parameter is of type "+Object.prototype.toString.call($)+", string expected"));if(q.hooks&&(q.hooks.options=q,q.hooks.block=Y),q.async)return(async()=>{let X=q.hooks?await q.hooks.preprocess($):$,G=await(q.hooks?await q.hooks.provideLexer(Y):Y?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(Y):Y?O1.parse:O1.parseInline)(z,q);return q.hooks?await q.hooks.postprocess(_):_})().catch(Q);try{q.hooks&&($=q.hooks.preprocess($));let X=(q.hooks?q.hooks.provideLexer(Y):Y?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(Y):Y?O1.parse:O1.parseInline)(X,q);return q.hooks&&(G=q.hooks.postprocess(G)),G}catch(X){return Q(X)}}}onError(Y,$){return(Z)=>{if(Z.message+=`
|
|
59
|
+
Please report this to https://github.com/markedjs/marked.`,Y){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 X7;function t(Y,$){return p1.parse(Y,$)}t.options=t.setOptions=function(Y){return p1.setOptions(Y),t.defaults=p1.defaults,a2(t.defaults),t};t.getDefaults=z2;t.defaults=c1;t.use=function(...Y){return p1.use(...Y),t.defaults=p1.defaults,a2(t.defaults),t};t.walkTokens=function(Y,$){return p1.walkTokens(Y,$)};t.parseInline=p1.parseInline;t.Parser=O1;t.parser=O1.parse;t.Renderer=D0;t.TextRenderer=N2;t.Lexer=N1;t.lexer=N1.lex;t.Tokenizer=R0;t.Hooks=T0;t.parse=t;var{options:T4,setOptions:N4,use:O4,walkTokens:F4,parseInline:B4}=t;var L4=O1.parse,M4=N1.lex;import{SessionContext as N3,ActiveViewCtx as _4}from"#canvas/runtime";import{useState as F0,useCallback as S1,useEffect as z7,useRef as _7,useMemo as G7}from"react";import{AnnotationCtx as K7}from"#canvas/runtime";var T1="__agent-response__";function F1(){return`ann-${Date.now()}-${Math.random().toString(36).slice(2,6)}`}function O0(Y,$){Y.style.height="auto",Y.style.height=($?Math.max($,Y.scrollHeight):Y.scrollHeight)+"px"}import{useAnnotations as Q1}from"#canvas/runtime";import{jsxDEV as T7}from"react/jsx-dev-runtime";function O2(Y,$){return`canvas:${Y}:rev:${$}`}function x0(Y,$){try{let Z=localStorage.getItem(O2(Y,$));if(!Z)return null;return JSON.parse(Z)}catch{return null}}function U7(Y,$,Z){try{localStorage.setItem(O2(Y,$),JSON.stringify(Z))}catch{}}function H7(Y,$){try{localStorage.removeItem(O2(Y,$))}catch{}}function J5({sessionId:Y,revision:$,isReadOnly:Z,remoteAnnotations:J,children:q}){let[Q,X]=F0(()=>{return(x0(Y,$)?.annotations??[]).map((E)=>({...E,source:E.source??"local"}))}),G=G7(()=>{if(!J||J.length===0)return Q;let V=new Set(Q.map((g)=>g.id)),E=J.filter((g)=>!V.has(g.id));return[...Q,...E.map((g)=>({...g,source:"remote"}))]},[Q,J]),[z,_]=F0(()=>{return x0(Y,$)?.generalNote??""}),[H,K]=F0(null),[W,T]=F0(()=>{let V=x0(Y,$);return V?.responses?new Map(V.responses):new Map}),[U,B]=F0(()=>{let V=x0(Y,$);return V?.feedbackEntries?new Map(V.feedbackEntries):new Map}),N=_7(null);z7(()=>{if(Z)return;if(N.current)clearTimeout(N.current);return N.current=setTimeout(()=>{U7(Y,$,{annotations:Q,generalNote:z,responses:Array.from(W.entries()),feedbackEntries:Array.from(U.entries())})},300),()=>{if(N.current)clearTimeout(N.current)}},[Q,z,W,U,Y,$,Z]);let M=S1((V,E,g,l,w,u,h)=>{X((A)=>[...A,{id:V,snippet:E,note:g,createdAt:new Date().toISOString(),filePath:l,context:w,...u?.length?{images:u}:{},...h?{canvasFile:h}:{}}])},[]),O=S1((V,E,g)=>{M(F1(),V,E,g)},[M]),C=S1((V,E)=>{X((g)=>g.map((l)=>l.id===V?{...l,note:E}:l))},[]),S=S1((V)=>{W7(V),X((E)=>E.filter((g)=>g.id!==V)),K((E)=>E===V?null:E)},[]),y=S1((V,E)=>{X((g)=>g.map((l)=>l.id===V?{...l,images:[...l.images||[],E]}:l))},[]),b=S1((V,E)=>{X((g)=>g.map((l)=>l.id===V?{...l,images:(l.images||[]).filter((w)=>w!==E)}:l))},[]),I=S1((V,E)=>{T((g)=>{let l=new Map(g);return l.set(V,E),l})},[]),k=S1((V,E)=>{B((g)=>{let l=g.get(V);if(l&&l.markdown===E.markdown&&l.label===E.label&&l.required===E.required)return g;let w=new Map(g);return w.set(V,E),w})},[]),c=S1((V)=>{B((E)=>{if(!E.has(V))return E;let g=new Map(E);return g.delete(V),g})},[]),f=S1(()=>{for(let V of document.querySelectorAll("[data-annotation-id]"))Q5(V);X([]),_(""),K(null),T(new Map),B(new Map),H7(Y,$)},[Y,$]);return T7(K7.Provider,{value:{annotations:G,addAnnotation:O,addAnnotationWithId:M,updateAnnotation:C,removeAnnotation:S,addAnnotationImage:y,removeAnnotationImage:b,generalNote:z,setGeneralNote:_,clearAll:f,activeAnnotationId:H,setActiveAnnotationId:K,responses:W,setResponse:I,feedbackEntries:U,setFeedbackEntry:k,removeFeedbackEntry:c},children:q},void 0,!1,void 0,this)}function W7(Y){let $=document.querySelectorAll(`[data-annotation-id="${Y}"]`);for(let Z of $)Q5(Z)}function Q5(Y){let $=Y.parentNode;if(!$)return;let Z=document.createTextNode(Y.textContent||"");$.replaceChild(Z,Y),$.normalize()}import S2,{useEffect as s1,useState as b1,useRef as C7,useContext as I7,useMemo as B0}from"react";import{createPortal as V7}from"react-dom";import{SessionContext as R7,CanvasFileCtx as D7}from"#canvas/runtime";function d1(Y,$){let Z=X5(Y,"before",60),J=X5(Y,"after",60),q=O7(Y.startContainer,$);return{before:Z,after:J,hierarchy:q}}function X5(Y,$,Z){let J=N7($==="before"?Y.startContainer:Y.endContainer);if(!J)return"";let q="";if($==="before"){let Q=document.createTreeWalker(J,NodeFilter.SHOW_TEXT),X;while(X=Q.nextNode()){if(X===Y.startContainer){q+=(X.textContent||"").slice(0,Y.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 Q=document.createTreeWalker(J,NodeFilter.SHOW_TEXT),X=!1,G;while(G=Q.nextNode()){if(G===Y.endContainer){q+=(G.textContent||"").slice(Y.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 N7(Y){let $=new Set(["DIV","P","LI","PRE","BLOCKQUOTE","SECTION","ARTICLE"]),Z=Y.parentElement;while(Z){if($.has(Z.tagName))return Z;Z=Z.parentElement}return null}function O7(Y,$){let Z=[],J=Y instanceof Element?Y:Y.parentElement;while(J&&J!==$){let q=J.getAttribute?.("data-task-id");if(q){let Q=J.querySelector(".font-semibold");if(Q)Z.unshift(Q.textContent?.trim()||q)}if(J.tagName==="DIV"&&J.querySelector(":scope > button .font-heading, :scope > div .font-heading")){let Q=J.querySelector(".font-heading");if(Q)Z.unshift(Q.textContent?.trim()||"")}J=J.parentElement}return Z}function F2(Y){let $=Y.snippet.trim(),Z=Y.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 M7,useRef as g0,useState as q0,useCallback as u0,useMemo as F5,useContext as y7}from"react";import{createPortal as P7}from"react-dom";function z5(Y,$){let q=$||document.body,Q=Y.getBoundingClientRect(),X=q.getBoundingClientRect(),G=q===document.body?window.scrollY:q.scrollTop,z=Q.bottom-X.top+G+8,_=Math.max(0,Math.min(Q.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 L2,useRef as M2,useCallback as C1,useEffect as B7}from"react";function F7(){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=F7();function _5(){if(Z1.isShared)return`/s/${Z1.shareId}/meta`;return`/api/session/${Z1.sessionId}/meta`}function G5(Y,$){let Z=Y.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 K5(){if(Z1.isShared)return`/s/${Z1.shareId}/upload`;return`/api/session/${Z1.sessionId}/upload`}var U5="canvas-reviewer-identity";function B2(){try{let Y=localStorage.getItem(U5);if(!Y)return null;return JSON.parse(Y)}catch{return null}}function H5(Y){let $=B2();if(!$)$={id:crypto.randomUUID?.()||String(Date.now()),name:Y};else $.name=Y;return localStorage.setItem(U5,JSON.stringify($)),$}async function W5(Y){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(Y)});if(!$.ok){let Z=await $.text().catch(()=>"");throw Error(`Feedback submission failed: ${$.status} ${Z}`)}}var B1=!Z1.isShared,T5=!Z1.isShared;import{jsxDEV as X1}from"react/jsx-dev-runtime";function N5(Y){if(Y.startsWith("/s/")||Y.startsWith("http://")||Y.startsWith("https://"))return Y;return`/api/uploads/${Y.split("/").pop()}`}async function L7(Y,$){let Z=new FormData;Z.append("image",$);try{let q=await(await fetch(K5(),{method:"POST",body:Z})).json();if(Z1.isShared)return q.url||null;return q.path||null}catch{return null}}function m0({note:Y,onNoteChange:$,images:Z,onAddImage:J,onRemoveImage:q,sessionId:Q,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,C]=L2(!1),[S,y]=L2(!1),[b,I]=L2(!1),k=M2(0),c=M2(null),f=M2(null),V=C1(()=>f.current?.click(),[]);if(M)M.current=V;let E=C1((m)=>{if(c.current=m,W)W.current=m;if(m&&z)O0(m,B)},[W,z,B]);B7(()=>{if(G&&c.current){let m=c.current;if(m.focus(),m.value)m.setSelectionRange(m.value.length,m.value.length)}},[G]);let g=C1(async(m)=>{if(!m.type.startsWith("image/"))return;y(!0);try{let a=await L7(Q,m);if(a)J(a)}finally{y(!1)}},[Q,J]),l=C1((m)=>{let a=m.clipboardData.items;for(let j of a)if(j.type.startsWith("image/")){m.preventDefault();let v=j.getAsFile();if(v)g(v);return}},[g]),w=C1((m)=>{if(m.preventDefault(),k.current++,k.current===1)C(!0)},[]),u=C1((m)=>{m.preventDefault()},[]),h=C1((m)=>{if(m.preventDefault(),k.current--,k.current===0)C(!1)},[]),A=C1((m)=>{m.preventDefault(),k.current=0,C(!1);for(let a of m.dataTransfer.files)if(a.type.startsWith("image/"))g(a)},[g]),D=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",d={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"}},x=!_&&(N==="always"||N==="on-focus"&&b);return X1("div",{style:{position:"relative"},onDragEnter:_?void 0:w,onDragOver:_?void 0:u,onDragLeave:_?void 0:h,onDrop:_?void 0:A,children:[X1("textarea",{ref:E,value:Y,onChange:_?void 0:D,onPaste:_?void 0:l,onKeyDown:H,onClick:K,onFocus:()=>I(!0),onBlur:()=>{setTimeout(()=>I(!1),150)},readOnly:_,placeholder:X,className:T??L,style:U??d,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:(m)=>{let a=m.target.files;if(a)for(let j of a)g(j);m.target.value=""}},void 0,!1,void 0,this),(Z.length>0||x)&&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:N5(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)),x&&X1(y2,{onClick:V},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 y2({onClick:Y,size:$=16}){return X1("button",{onClick:(Z)=>{Z.stopPropagation(),Y()},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 O5({images:Y}){if(!Y.length)return null;return X1("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"6px"},children:Y.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:N5($),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 S7}from"#canvas/runtime";import{jsxDEV as z1,Fragment as w7}from"react/jsx-dev-runtime";function b7({anchorEl:Y,scrollContainer:$,onClose:Z,ignoreSelector:J,zIndex:q="50",padding:Q="12px",width:X="280px",children:G}){let z=g0(null),_=g0(Z);_.current=Z;let{style:H,parent:K}=z5(Y,$);return M7(()=>{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]),P7(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:Q,fontFamily:"'Inter', sans-serif"},children:G},void 0,!1,void 0,this),K)}var L5=[{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"]}],B5=L5.flatMap((Y)=>Y.items);function M5({anchorEl:Y,scrollContainer:$,snippet:Z,truncateAt:J=100,header:q,initialNote:Q="",initialImages:X,onConfirm:G,onCancel:z,onDelete:_}){let H=y7(S7),K=Q!==""||!!_,[W,T]=q0(Q),[U,B]=q0(X||[]),[N,M]=q0(null),[O,C]=q0(K),[S,y]=q0(!1),b=g0(null),I=g0(null),k=u0(()=>{if(W.trim()||U.length>0)G(W.trim(),U);else if(K&&_)_();else z()},[W,U,G,z,K,_]),c=u0(()=>{if(K){if(!W.trim()&&U.length===0&&_){_(),z();return}G(W,U);return}z()},[W,U,K,G,z,_]),f=!K,V=W.trim().length>0?B5.filter((j)=>j.toLowerCase().startsWith(W.trim().toLowerCase())):B5,E=!f||O?[]:V.length===1&&V[0].toLowerCase()===W.trim().toLowerCase()?[]:V,g=new Set(E),l=L5.map((j)=>({label:j.label,items:j.items.filter((v)=>g.has(v))})).filter((j)=>j.items.length>0),w=l.map((j)=>j.items),u=w.flat(),h=F5(()=>{if(N===null)return 0;let j=0;for(let v=0;v<w.length;v++){if(N<j+w[v].length)return v;j+=w[v].length}return 0},[N,w]),A=F5(()=>{if(N===null)return 0;let j=0;for(let v=0;v<h;v++)j+=w[v].length;return N-j},[N,h,w]),D=(j,v)=>{let $1=0;for(let K1=0;K1<j;K1++)$1+=w[K1].length;return $1+v},[L,d]=q0(W);if(W!==L)d(W),M(null),C(K);let x=u0((j)=>{T(j)},[]),m=Z.length>J?Z.slice(0,J)+"...":Z,a=u0((j)=>{if(u.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 v=Math.min(A+1,w[h].length-1);M(D(h,v))}else if(j.key==="ArrowUp"){let v=Math.max(A-1,0);M(D(h,v))}else if(j.key==="ArrowRight"){let v=Math.min(h+1,w.length-1),$1=Math.min(A,w[v].length-1);M(D(v,$1))}else if(j.key==="ArrowLeft"){let v=Math.max(h-1,0),$1=Math.min(A,w[v].length-1);M(D(v,$1))}return}if(N!==null&&u.length>0){if(j.key==="Tab"){j.preventDefault(),x(u[N]);return}if(j.key==="Enter"&&!j.shiftKey){j.preventDefault(),G(u[N],U);return}}if(j.key==="Enter"&&!j.shiftKey){j.preventDefault(),k();return}if(j.key==="Escape")if(u.length>0&&!O)C(!0);else if(K)c();else z()},[u,N,A,h,w,D,x,G,U,k,O,K,c,z]);return z1(b7,{anchorEl:Y,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(m0,{note:W,onNoteChange:T,images:U,onAddImage:(j)=>B((v)=>[...v,j]),onRemoveImage:(j)=>B((v)=>v.filter(($1)=>$1!==j)),sessionId:H,autoFocus:!0,autoResize:K,textareaRef:b,onKeyDown:a,attachButton:"none",openFilePickerRef:I,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(y2,{onClick:()=>I.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(w7,{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:k,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),u.length>0&&z1("div",{style:{marginTop:"6px",borderTop:"1px solid var(--color-border-subtle)",paddingTop:"8px",display:"flex",gap:"4px"},children:l.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((v)=>{let $1=u.indexOf(v);return z1("div",{onMouseDown:(K1)=>{K1.preventDefault(),K1.stopPropagation(),x(v)},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:v.slice(0,W.trim().length)},void 0,!1,void 0,this),v.slice(W.trim().length)]},v,!0,void 0,this)})]},j.label,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function J0({anchorEl:Y,scrollContainer:$,snippet:Z,truncateAt:J,header:q,onAdd:Q,onCancel:X}){return z1(M5,{anchorEl:Y,scrollContainer:$,snippet:Z,truncateAt:J,header:q,onConfirm:(G,z)=>Q(G,z),onCancel:X},void 0,!1,void 0,this)}function Q0({anchorEl:Y,scrollContainer:$,initialNote:Z,initialImages:J,onUpdate:q,onDelete:Q,onClose:X}){return z1(M5,{anchorEl:Y,scrollContainer:$,snippet:"",initialNote:Z,initialImages:J,onConfirm:(G,z)=>{q(G,z),X()},onDelete:Q,onCancel:X},void 0,!1,void 0,this)}import{useEffect as c0,useState as P5,useRef as i1,useCallback as S5}from"react";function l1(Y,$){let Z=[],J=j7(Y);for(let q of J){let Q=document.createRange();if(Q.selectNodeContents(q),q===Y.startContainer)Q.setStart(q,Y.startOffset);if(q===Y.endContainer)Q.setEnd(q,Y.endOffset);let X=Q.toString();if(!X||!X.trim())continue;let G=document.createElement("mark");G.setAttribute("data-annotation-id",$);try{Q.surroundContents(G)}catch{let z=Q.extractContents();G.appendChild(z),Q.insertNode(G)}Z.push(G)}return Z}function j7(Y){let $=[],Z=Y.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(Y.intersectsNode(q))$.push(q)}return $}function r1(Y,$){let Z=document.querySelectorAll(`[data-annotation-id="${Y}"]`);for(let J of Z)J.classList.toggle("mark-active",$)}function v0(Y,$){if($!=null&&$!==Y)r1($,!1);if(Y!=null)r1(Y,!0)}function f0(Y,$){let Z=document.querySelectorAll(`[data-annotation-id="${Y}"]`);for(let J of Z)J.setAttribute("data-annotation-id",$)}function h0(Y,$){let Z=$.filter((G)=>!document.querySelector(`[data-annotation-id="${G.id}"]`));if(!Z.length)return;let J=[],q="",Q=document.createTreeWalker(Y,NodeFilter.SHOW_TEXT),X;while(X=Q.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 C=q.slice(Math.max(0,M-80),M);if(C.includes(G.context.before))O+=2;else if(G.context.before.length>10&&C.includes(G.context.before.slice(-10)))O+=1}if(G.context.after){let C=q.slice(M+z.length,M+z.length+80);if(C.includes(G.context.after))O+=2;else if(G.context.after.length>10&&C.includes(G.context.after.slice(0,10)))O+=1}if(O>N)N=O,K=M}}let W=K,T=K+z.length,U=y5(J,W),B=y5(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 y5(Y,$){for(let Z=Y.length-1;Z>=0;Z--)if(Y[Z].start<=$){let J=$-Y[Z].start,q=Y[Z].node.textContent?.length??0;if(J<=q)return{node:Y[Z].node,offset:J}}return null}function p0(Y){let $=document.querySelectorAll(`[data-annotation-id="${Y}"]`);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 P2,Fragment as A7}from"react/jsx-dev-runtime";function a1(Y){let{containerRef:$,restoreKey:Z,restoreAnnotations:J,extractContext:q,filePath:Q,canvasFile:X,scrollContainer:G}=Y,{annotations:z,addAnnotationWithId:_,removeAnnotation:H,updateAnnotation:K,addAnnotationImage:W,removeAnnotationImage:T,activeAnnotationId:U,setActiveAnnotationId:B}=Q1(),[N,M]=P5(null),[O,C]=P5(null),S=i1(q);S.current=q;let y=i1(Q);y.current=Q;let b=i1(X);b.current=X;let I=i1(_);I.current=_;let k=i1(U);k.current=U;let c=i1(B);c.current=B;let f=J.length;c0(()=>{if(!$.current)return;let w=setTimeout(()=>{if($.current)h0($.current,J)},50);return()=>clearTimeout(w)},[Z,f]);let V=i1(null);c0(()=>{v0(U,V.current),V.current=U},[U]),c0(()=>{let w=$.current;if(!w)return;let u=(D)=>{let L=D.target.closest("[data-annotation-id]");if(!L)return;D.stopPropagation();let d=L.getAttribute("data-annotation-id");if(d===k.current)M({anchorEl:L,annId:d});else c.current(d)},h=(D)=>{let L=D.target.closest("[data-annotation-id]");if(L)c.current(L.getAttribute("data-annotation-id"))},A=(D)=>{let L=D.target.closest("[data-annotation-id]"),d=D.relatedTarget?.closest?.("[data-annotation-id]");if(L&&!d&&!document.getElementById("ann-inline-popover"))c.current(null)};return w.addEventListener("click",u),w.addEventListener("mouseover",h),w.addEventListener("mouseout",A),()=>{w.removeEventListener("click",u),w.removeEventListener("mouseover",h),w.removeEventListener("mouseout",A)}},[Z]),c0(()=>{let w=()=>E();return document.addEventListener("mouseup",w),()=>document.removeEventListener("mouseup",w)},[]);let E=S5(()=>{let w=window.getSelection();if(!w||w.isCollapsed||!w.toString().trim())return;if(!$.current)return;let u=w.getRangeAt(0);if(!$.current.contains(u.startContainer))return;if(u.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let h=w.toString().trim();if(h.length<2)return;let A=S.current(u),D=u.cloneRange(),L=`__pending_${Date.now()}`;try{l1(D,L)}catch{}window.getSelection()?.removeAllRanges();let d=document.querySelectorAll(`[data-annotation-id="${L}"]`),x=d[d.length-1];if(!x)return;C({anchorEl:x,tempId:L,snippet:h,ctx:A})},[]),g=S5((w,u,h,A)=>{C({anchorEl:w,tempId:u,snippet:h,ctx:A})},[]);return{popovers:P2(A7,{children:[N&&(()=>{let w=z.find((u)=>u.id===N.annId);if(!w)return null;return P2(Q0,{anchorEl:N.anchorEl,scrollContainer:G,initialNote:w.note,initialImages:w.images,onUpdate:(u,h)=>{K(N.annId,u);let A=w.images||[];for(let D of h)if(!A.includes(D))W(N.annId,D);for(let D of A)if(!h.includes(D))T(N.annId,D)},onDelete:()=>{H(N.annId),B(null)},onClose:()=>M(null)},void 0,!1,void 0,this)})(),O&&P2(J0,{anchorEl:O.anchorEl,scrollContainer:G,snippet:O.snippet,truncateAt:80,onAdd:(w,u)=>{let h=F1();f0(O.tempId,h),I.current(h,O.snippet,w,y.current,O.ctx,u,b.current),C(null)},onCancel:()=>{p0(O.tempId),C(null)}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),openCreatePopover:g,isPopoverOpen:!!(N||O)}}import{jsxDEV as q1,Fragment as m7}from"react/jsx-dev-runtime";var w2="[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']",b2="[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 L0({revision:Y,filename:$}){let Z=I7(R7),[J,q]=b1(null),[Q,X]=b1(null),[G,z]=b1(!0),_=C7(null),{annotations:H,addAnnotationWithId:K,removeAnnotation:W,updateAnnotation:T,addAnnotationImage:U,removeAnnotationImage:B,activeAnnotationId:N,setActiveAnnotationId:M}=Q1(),O=B0(()=>H.filter((A)=>!A.filePath&&(!A.canvasFile||A.canvasFile===$)),[H,$]),[C,S]=b1(null),[y,b]=b1(null),[I,k]=b1(null),[c,f]=b1(null),[V,E]=b1(!1);s1(()=>{z(!0),X(null),f(null),import(G5($,Y)).then((A)=>{q(()=>A.default),z(!1)}).catch((A)=>{X(A.message),z(!1)})},[Z,Y,$]);let g=document.getElementById("plan-scroll-container"),{popovers:l,isPopoverOpen:w}=a1({containerRef:_,restoreKey:J,restoreAnnotations:O,extractContext:(A)=>d1(A,_.current),canvasFile:$,scrollContainer:g}),u=B0(()=>{let A=new Map;for(let D of O)if(D.snippet.startsWith("["))A.set(D.snippet,D.id);return A},[O]);s1(()=>{let A=_.current;if(!A)return;let D=(d)=>{if(I||w)return;let x=d.target;if(x.closest("[data-block-comment-btn]"))return;E(!1);let m=x.closest(w2);if(m&&A.contains(m)){let v=o1(A).indexOf(m);f(v>=0?v:null)}else f(null);let a=x.closest(b2);if(a&&A.contains(a)){b(a);let j=X0(a),v=j?u.get(j):void 0;if(v&&v!==N)M(v)}else b(null)},L=(d)=>{if(I||w)return;if(d.relatedTarget?.closest("[data-block-comment-btn]"))return;b(null),M(null)};return A.addEventListener("mousemove",D),A.addEventListener("mouseleave",L),()=>{A.removeEventListener("mousemove",D),A.removeEventListener("mouseleave",L)}},[J,I,w,u,N]),s1(()=>{let A=(D)=>{let L=D.target.tagName;if(L==="INPUT"||L==="TEXTAREA"||D.target.isContentEditable)return;if(I||w)return;let d=_.current;if(!d)return;if(D.key==="ArrowDown"){D.preventDefault(),E(!0);let x=o1(d);if(x.length===0)return;f((m)=>{if(m===null)return 0;return Math.min(m+1,x.length-1)})}else if(D.key==="ArrowUp"){D.preventDefault(),E(!0);let x=o1(d);if(x.length===0)return;f((m)=>{if(m===null)return x.length-1;return Math.max(m-1,0)})}else if(D.key==="a"||D.key==="A"){if(c===null||!d)return;D.preventDefault();let m=o1(d)[c];if(!m)return;let a=X0(m);if(!a)return;let j=u.get(a);if(j)M(j),k({anchorEl:m,snippet:a,annId:j});else k({anchorEl:m,snippet:a})}else if(D.key===" "||D.key==="Enter"){if(c===null)return;let m=o1(d)[c];if(!m)return;let a=m.getAttribute("data-md");if(a==="choice-option"||a==="multichoice-option")D.preventDefault(),m.dispatchEvent(new CustomEvent("kb-select",{bubbles:!0}));else if(a==="userinput"){D.preventDefault();let j=m.querySelector("textarea");if(j){j.focus();let v=($1)=>{if($1.key==="Escape")$1.preventDefault(),j.blur(),E(!0)};j.addEventListener("keydown",v),j.addEventListener("blur",()=>j.removeEventListener("keydown",v),{once:!0})}}else if(a==="rangeinput"){D.preventDefault();let j=m.querySelector("input[type='range']");if(j){j.focus();let v=($1)=>{if($1.key==="Escape"||$1.key==="ArrowUp"||$1.key==="ArrowDown")$1.preventDefault(),j.blur(),E(!0)};j.addEventListener("keydown",v),j.addEventListener("blur",()=>j.removeEventListener("keydown",v),{once:!0})}}}else if(D.key==="Escape")f(null),E(!1),M(null)};return document.addEventListener("keydown",A),()=>document.removeEventListener("keydown",A)},[c,I,w,u]),s1(()=>{let A=_.current;if(!A||c===null||!V)return;let L=o1(A)[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 d=X0(L),x=d?u.get(d):void 0;if(x)M(x);return()=>{L.style.outline="",L.style.outlineOffset="",L.style.borderRadius=""}},[c,V,u]);let h=B0(()=>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(Q)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:Q},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(D7.Provider,{value:$,children:[q1("div",{ref:_,className:"plan-content plan-updated",children:h},void 0,!1,void 0,this),C&&q1(x7,{note:C.note,onSave:(A)=>{T(C.id,A),S(null)},onCancel:()=>S(null)},void 0,!1,void 0,this),l,q1(k7,{containerRef:_,hoveredBlock:y,focusedBlockIndex:c,blockPopover:I,blockAnnotationMap:u,activeAnnotationId:N,onOpen:(A,D,L)=>{if(L)M(L),k({anchorEl:A,snippet:D,annId:L});else k({anchorEl:A,snippet:D})}},void 0,!1,void 0,this),I&&!I.annId&&q1(J0,{anchorEl:I.anchorEl,scrollContainer:g,snippet:I.snippet,truncateAt:80,onAdd:(A,D)=>{let L=F1();K(L,I.snippet,A,void 0,void 0,D,$),k(null)},onCancel:()=>k(null)},void 0,!1,void 0,this),I?.annId&&(()=>{let A=O.find((D)=>D.id===I.annId);if(!A)return null;return q1(Q0,{anchorEl:I.anchorEl,scrollContainer:g,initialNote:A.note,initialImages:A.images,onUpdate:(D,L)=>{T(I.annId,D);let d=A.images||[];for(let x of L)if(!d.includes(x))U(I.annId,x);for(let x of d)if(!L.includes(x))B(I.annId,x)},onDelete:()=>{W(I.annId),M(null),k(null)},onClose:()=>k(null)},void 0,!1,void 0,this)})()]},void 0,!0,void 0,this)}function o1(Y){return Array.from(Y.querySelectorAll(w2))}function X0(Y){let $=Y.getAttribute("data-md");if($==="item"){let Z=Y.getAttribute("data-md-label");return Z?`[Item] ${Z}`:null}if($==="section"){let Z=Y.getAttribute("data-md-title");return Z?`[Section] ${Z}`:null}if($==="callout"){let Z=Y.getAttribute("data-md-type")||"info",J=Y.textContent?.trim().slice(0,60)||"Callout";return`[Callout:${Z}] ${J}`}if($==="note")return`[Note] ${Y.textContent?.trim().slice(0,60)||"Note"}`;if(Y.tagName==="TR"){let Z=Array.from(Y.querySelectorAll("td")).map((J)=>J.textContent?.trim()).filter(Boolean);return Z.length?`[Row] ${Z.join(" | ")}`:null}if($==="checklist-item"){let Z=Y.getAttribute("data-md-label");return Z?`[Checklist] ${Z}`:null}if($==="choice-option"||$==="multichoice-option"){let Z=Y.getAttribute("data-md-label");return Z?`[Option] ${Z}`:null}if($==="userinput"){let Z=Y.getAttribute("data-md-label");return Z?`[Input] ${Z}`:null}if($==="rangeinput"){let Z=Y.getAttribute("data-md-label");return Z?`[Range] ${Z}`:null}if($==="image"){let Z=Y.getAttribute("data-md-src");return Z?`[Image] ${Z}`:null}return null}function k7({containerRef:Y,hoveredBlock:$,focusedBlockIndex:Z,blockPopover:J,blockAnnotationMap:q,activeAnnotationId:Q,onOpen:X}){let[G,z]=b1([]);s1(()=>{let T=Y.current;if(!T||q.size===0){z([]);return}let U=[];for(let B of T.querySelectorAll(b2)){let N=X0(B);if(N&&q.has(N))U.push(B)}z(U)},[q,Y.current]);let[_,H]=b1(null);s1(()=>{if(!Q||!Y.current){H(null);return}for(let T of Y.current.querySelectorAll(w2)){let U=X0(T);if(U&&q.get(U)===Q){H(T);return}}H(null)},[Q,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=B0(()=>{if(Z===null||!Y.current)return null;let T=o1(Y.current)[Z];if(!T)return null;return T.matches(b2)?T:null},[Z,Y.current]),W=B0(()=>{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(m7,{children:W.map((T)=>q1(E7,{block:T,isHovered:T===$||T===K||T===J?.anchorEl,blockAnnotationMap:q,activeAnnotationId:Q,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 E7({block:Y,isHovered:$,blockAnnotationMap:Z,activeAnnotationId:J,onOpen:q}){let Q=X0(Y);if(!Q)return null;let X=Z.get(Q),G=!!X;return V7(q1("button",{"data-block-comment-btn":!0,onClick:(_)=>{_.stopPropagation(),q(_.currentTarget,Q,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),Y)}function x7({note:Y,onSave:$,onCancel:Z}){let[J,q]=S2.useState(Y),Q=S2.useRef(null);return S2.useEffect(()=>{Q.current?.focus(),Q.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:Q,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 i7,{useRef as C5,useEffect as i0,useCallback as V2,useState as E1,useContext as a0,useMemo as a7}from"react";function M0(Y,$,Z,J,q){let Q=[],X=Y.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)=>A2(T)):[],K=J?Array.from(J.values()).filter((T)=>T.markdown.trim()):[];if(H.length>0||K.length>0){Q.push("## Responses"),Q.push("");for(let T of H)Q.push(v7(T));for(let T of K)Q.push(T.markdown.trim()),Q.push("")}if(G.length>0){Q.push("## Annotations on agent response"),Q.push("");for(let T of G)Q.push(j2(T))}if(z.length>0){Q.push("## Canvas annotations"),Q.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)Q.push(`### ${N.replace(/\.jsx$/,"")}`),Q.push("");let O=f7(M);Q.push(b5(O))}}if(_.length>0){let T={};for(let U of _){let B=U.filePath;if(!T[B])T[B]=[];T[B].push(U)}Q.push("## File annotations"),Q.push("");for(let[U,B]of Object.entries(T)){Q.push(`### ${U}`),Q.push("");for(let N of B)Q.push(j2(N))}}if($.trim())Q.push("## General notes"),Q.push(""),Q.push($.trim()),Q.push("");return Q.join(`
|
|
60
60
|
`).trim()+`
|
|
61
|
-
`}function
|
|
62
|
-
`)}function
|
|
63
|
-
`);if(Z.length<30&&
|
|
64
|
-
`).length<=3)$.push(`> ${
|
|
61
|
+
`}function A2(Y){if(Y.note?.trim())return!0;if(Y.value===null||Y.value===void 0)return!1;if(Y.type==="text"&&!Y.value.trim())return!1;if(Y.type==="checkbox"&&Y.value.length===0)return!1;return!0}function u7(Y){let $=[];for(let Z of Y.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 g7(Y){let $=[];for(let Z of Y.values())if(Z.required&&!Z.markdown.trim())$.push(Z);return $}function d0(Y,$){let Z=u7(Y),J=g7($);return[...Z.map((q)=>q.label),...J.map((q)=>q.label||q.id)]}function v7(Y){let $=[];switch($.push(`**${Y.label}**`),Y.type){case"radio":case"select":$.push(`Answer: ${Y.value}`);break;case"checkbox":for(let Z of Y.value)$.push(`- [x] ${Z}`);break;case"text":$.push(""),$.push(Y.value.trim());break;case"range":$.push(`Answer: ${Y.value}`);break}if(Y.note?.trim())$.push(""),$.push(`Note: ${Y.note.trim()}`);return $.push(""),$.join(`
|
|
62
|
+
`)}function j2(Y){let $=[],Z=Y.snippet.trim(),J=Y.context,q=J?.lineStart!=null;if(Y.filePath&&q){let Q=J.lineStart,X=J.lineEnd??Q,G=Z.split(`
|
|
63
|
+
`);if(Z.length<30&&Q===X&&(J.before||J.after)){let _=F2(Y);$.push(`> L${Q}: ${_}`)}else if(G.length<=6)for(let _=0;_<G.length;_++)$.push(`> ${Q+_} | ${G[_]}`);else{for(let _=0;_<3;_++)$.push(`> ${Q+_} | ${G[_]}`);$.push(`> ... (${G.length} lines)`);for(let _=G.length-3;_<G.length;_++)$.push(`> ${Q+_} | ${G[_]}`)}}else{let Q=F2(Y);if(Z.split(`
|
|
64
|
+
`).length<=3)$.push(`> ${Q.split(`
|
|
65
65
|
`).join(`
|
|
66
66
|
> `)}`);else{let X=Z.split(`
|
|
67
|
-
`);$.push(`> ${X[0]}`),$.push(`> ... (${X.length} lines)`),$.push(`> ${X[X.length-1]}`)}}if(
|
|
68
|
-
`)}function
|
|
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(`
|
|
67
|
+
`);$.push(`> ${X[0]}`),$.push(`> ... (${X.length} lines)`),$.push(`> ${X[X.length-1]}`)}}if(Y.note.trim())$.push(""),$.push(Y.note.trim());if(Y.images?.length){$.push("");for(let Q of Y.images)$.push(``)}return $.push(""),$.join(`
|
|
68
|
+
`)}function f7(Y){let $={label:"",annotations:[],children:new Map};for(let Z of Y){let J=Z.context?.hierarchy||[],q=$;for(let Q of J){if(!q.children.has(Q))q.children.set(Q,{label:Q,annotations:[],children:new Map});q=q.children.get(Q)}q.annotations.push(Z)}return $}function b5(Y,$=0){let Z=[];for(let J of Y.annotations)Z.push(j2(J));for(let[,J]of Y.children){let q=$===0?"###":"####";Z.push(`${q} ${J.label}`),Z.push(""),Z.push(b5(J,$+1))}return Z.join(`
|
|
69
|
+
`)}import{SessionContext as I5}from"#canvas/runtime";import{useEffect as w5,useState as y0,useRef as h7,useMemo as C2}from"react";import{jsxDEV as J1}from"react/jsx-dev-runtime";function j5({open:Y,onClose:$,onSubmit:Z,includedRemoteIds:J,onToggleRemoteId:q}){let{annotations:Q,generalNote:X,responses:G,feedbackEntries:z}=Q1(),[_,H]=y0(""),[K,W]=y0(!1),[T,U]=y0(!1),[B,N]=y0(null),M=h7(null),[O,C]=y0(!1),S=C2(()=>Q.filter((k)=>k.source==="remote"),[Q]);if(Y&&!O)W(!1),U(!1),N(null);if(!Y&&O)W(!1),U(!1),N(null);if(Y!==O)C(Y);let y=C2(()=>M0(Q,X,G,z,J),[Q,X,G,z,J]),b=K?_:y;if(w5(()=>{if(Y&&T&&M.current)M.current.focus()},[Y,T]),w5(()=>{if(!Y)return;let k=(c)=>{if(c.key==="Escape")$()};return window.addEventListener("keydown",k),()=>window.removeEventListener("keydown",k)},[Y,$]),!Y)return null;let I=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:(k)=>k.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:(k)=>{H(k.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(r0,{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 k=d0(G,z);if(k.length>0){N(`Please answer: ${k.join(", ")}`);return}N(null),Z(b)},disabled:!I,className:`px-6 py-2 rounded-lg font-body text-[13px] font-medium transition-all ${I?"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 p7=/!\[([^\]]*)\]\((\/tmp\/agent-canvas\/uploads\/([^)]+))\)/g;function c7(Y){return Y.replace(p7,($,Z,J,q)=>``)}function r0({text:Y}){let $=C2(()=>t.parse(c7(Y),{async:!1}),[Y]);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 d7={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"},r7={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:Y,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=Y.includes(".")?Y.split(".").pop().toLowerCase():"",Q=d7[q]||"#6b6560",X=r7[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:Q,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 l7(Y){let $=Y.getAttribute("data-md");if($==="item"){let Z=Y.getAttribute("data-md-label");return Z?`[Item] ${Z}`:null}if($==="section"){let Z=Y.getAttribute("data-md-title");return Z?`[Section] ${Z}`:null}if($==="callout"){let Z=Y.getAttribute("data-md-type")||"info",J=Y.textContent?.trim().slice(0,60)||"Callout";return`[Callout:${Z}] ${J}`}if($==="note")return`[Note] ${Y.textContent?.trim().slice(0,60)||"Note"}`;if(Y.tagName==="TR"){let Z=Array.from(Y.querySelectorAll("td")).map((J)=>J.textContent?.trim()).filter(Boolean);return Z.length?`[Row] ${Z.join(" | ")}`:null}if($==="checklist-item"){let Z=Y.getAttribute("data-md-label");return Z?`[Checklist] ${Z}`:null}if($==="choice-option"||$==="multichoice-option"){let Z=Y.getAttribute("data-md-label");return Z?`[Option] ${Z}`:null}if($==="userinput"){let Z=Y.getAttribute("data-md-label");return Z?`[Input] ${Z}`:null}if($==="rangeinput"){let Z=Y.getAttribute("data-md-label");return Z?`[Range] ${Z}`:null}if($==="image"){let Z=Y.getAttribute("data-md-src");return Z?`[Image] ${Z}`:null}return null}function P0(Y){let $=document.querySelector(`[data-annotation-id="${Y.id}"]`);if($)return $;if(Y.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(l7(Z)===Y.snippet)return Z}return null}function A5(Y){Y.classList.remove("ann-flash"),Y.offsetWidth,Y.classList.add("ann-flash"),Y.addEventListener("animationend",()=>{Y.classList.remove("ann-flash")},{once:!0})}function I2(Y,$){if(Y.filePath)$({type:"file",path:Y.filePath}),setTimeout(()=>{let Z=P0(Y);if(Z)Z.scrollIntoView({behavior:"smooth",block:"center"}),A5(Z)},150);else{let Z=P0(Y);if(Z)Z.scrollIntoView({behavior:"smooth",block:"center"}),A5(Z)}}import{jsxDEV as P,Fragment as l0}from"react/jsx-dev-runtime";function R2({onSubmit:Y,collapseButton:$}){let{isReadOnly:Z,selectedRevision:J,currentRevision:q,revisions:Q,agentWatching:X}=a0(w1),G=a0(I5),z=Q.find((W)=>W.revision===J),_=Z&&J===q,H=!!z?.feedbackConsumed,K=z?.label||`Round ${J}`;if(Z)return P(s7,{sessionId:G,revision:J,label:K,waitingForUpdate:_,feedbackConsumed:H,agentWatching:X,collapseButton:$},void 0,!1,void 0,this);return P(e7,{onSubmit:Y,agentWatching:X,collapseButton:$},void 0,!1,void 0,this)}function o7({sessionId:Y,revision:$,label:Z,waitingForUpdate:J,feedbackConsumed:q,agentWatching:Q,collapseButton:X}){let G=Z1.isShared,[z,_]=E1(null),[H,K]=E1(!0);return i0(()=>{if(K(!0),!B1){_(null),K(!1);return}fetch(`/api/session/${Y}/revision/${$}/feedback`).then((W)=>W.json()).then((W)=>{_(W.feedback||null),K(!1)}).catch(()=>{_(null),K(!1)})},[Y,$]),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(V5,{feedbackConsumed:q,agentWatching:Q},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(r0,{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 V5({feedbackConsumed:Y,agentWatching:$}){if(Y)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 s7({sessionId:Y,revision:$,label:Z,waitingForUpdate:J,feedbackConsumed:q,agentWatching:Q,collapseButton:X}){let{annotations:G,generalNote:z,activeAnnotationId:_,setActiveAnnotationId:H}=Q1(),{setActiveView:K}=a0(I1),W=G.length>0||z.trim().length>0,[T,U]=E1("feedback");if(!W)return P(o7,{sessionId:Y,revision:$,label:Z,waitingForUpdate:J,feedbackConsumed:q,agentWatching:Q,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(V5,{feedbackConsumed:q,agentWatching:Q},void 0,!1,void 0,this),T==="feedback"?P(t7,{sessionId:Y,revision:$},void 0,!1,void 0,this):P(n7,{annotations:G,generalNote:z,activeAnnotationId:_,setActiveAnnotationId:H,setActiveView:K},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function t7({sessionId:Y,revision:$}){let[Z,J]=E1(null),[q,Q]=E1(!0);return i0(()=>{if(Q(!0),!B1){J(null),Q(!1);return}fetch(`/api/session/${Y}/revision/${$}/feedback`).then((X)=>X.json()).then((X)=>{J(X.feedback||null),Q(!1)}).catch(()=>{J(null),Q(!1)})},[Y,$]),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(r0,{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 n7({annotations:Y,generalNote:$,activeAnnotationId:Z,setActiveAnnotationId:J,setActiveView:q}){let Q=Y.filter((U)=>U.filePath===T1),X=Y.filter((U)=>!U.filePath),G=Y.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=P0(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(O5,{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(),I2(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=[Q,X,G].filter((U)=>U.length>0).length>1;return P(l0,{children:[P("div",{className:"flex-1 overflow-y-auto",children:[Q.length>0&&P(l0,{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),Q.map(W)]},void 0,!0,void 0,this),X.length>0&&P(l0,{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 e7({onSubmit:Y,agentWatching:$,collapseButton:Z}){let[J,q]=E1(!1),{annotations:Q,updateAnnotation:X,removeAnnotation:G,addAnnotationImage:z,removeAnnotationImage:_,generalNote:H,setGeneralNote:K,activeAnnotationId:W,setActiveAnnotationId:T,responses:U,feedbackEntries:B}=Q1(),N=a0(I5),{setActiveView:M}=i7.useContext(I1),O=C5(null),C=C5(new Map),S=Q.filter((L)=>L.filePath===T1),y=Q.filter((L)=>!L.filePath),b=Q.filter((L)=>L.filePath&&L.filePath!==T1),I={};for(let L of b){let d=L.filePath;if(!I[d])I[d]=[];I[d].push(L)}i0(()=>{if(!W)return;let L=C.current.get(W);if(L)L.scrollIntoView({behavior:"smooth",block:"nearest"})},[W]);let k=V2((L)=>{T(L),r1(L,!0)},[T]),c=V2((L)=>{T(null),r1(L,!1)},[W]),f=a7(()=>Q.filter((L)=>L.source==="remote"),[Q]),[V,E]=E1(()=>new Set);i0(()=>{if(f.length===0)return;E((L)=>{let d=new Set(L);for(let x of f)d.add(x.id);return d.size===L.size?L:d})},[f]);let g=V2((L)=>{E((d)=>{let x=new Set(d);if(x.has(L))x.delete(L);else x.add(L);return x})},[]),l=Array.from(U.values()).some(A2),w=B.size>0,u=Q.length>0||H.trim().length>0||l||w,[h,A]=E1(null),D=(L)=>{let d=L.source==="remote";return P("div",{ref:(x)=>{if(x)C.current.set(L.id,x);else C.current.delete(L.id)},className:`group/ann relative px-3 py-2.5 transition-colors duration-150 ${W===L.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:()=>k(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 x=P0(L);if(x)x.scrollIntoView({behavior:"smooth",block:"center"})},150)},children:[d&&L.author&&P("div",{className:"flex items-center gap-1.5 mb-1.5",children:[P("input",{type:"checkbox",checked:V.has(L.id),onChange:(x)=>{x.stopPropagation(),g(L.id)},onClick:(x)=>x.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),d?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:(x)=>x.stopPropagation(),children:P(m0,{note:L.note,onNoteChange:(x)=>X(L.id,x),images:L.images||[],onAddImage:(x)=>z(L.id,x),onRemoveImage:(x)=>_(L.id,x),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:(x)=>{x.stopPropagation(),I2(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),!d&&P("button",{onClick:(x)=>{x.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",Q.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:Q.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:[Q.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(l0,{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(D)]},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(D),Object.entries(I).map(([L,d])=>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),d.map(D)]},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)=>O0(L.target,40),ref:(L)=>{if(L)O0(L,40)}},void 0,!1,void 0,this)},void 0,!1,void 0,this),h&&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:h},void 0,!1,void 0,this),P("button",{onClick:()=>{A(null);let L=M0(Q,H,U,B,V);Y(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:u?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=d0(U,B);if(L.length>0){A(`Please answer: ${L.join(", ")}`);return}A(null);let d=M0(Q,H,U,B,V);Y(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):P("button",{onClick:()=>Y("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(j5,{open:J,onClose:()=>q(!1),onSubmit:Y,includedRemoteIds:V,onToggleRemoteId:g},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{useEffect as $8,useState as R5,useContext as D5,useMemo as Y8}from"react";import{SessionContext as Z8}from"#canvas/runtime";import{jsxDEV as i,Fragment as D2}from"react/jsx-dev-runtime";function k5({embedded:Y}={}){let $=D5(Z8),{annotations:Z,addAnnotation:J}=Q1(),{setActiveView:q}=D5(I1),[Q,X]=R5(!1),[G,z]=R5({});if(!B1)return i("div",{className:Y?"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}=Y8(()=>{let O=new Map;for(let C of Z)if(C.filePath&&C.filePath!==T1)O.set(C.filePath,(O.get(C.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}}))};$8(()=>{if(!Q&&!G[""])K("")},[Q]);let W=(O)=>{if(G[O]?.loaded)z((C)=>({...C,[O]:{...C[O],expanded:!C[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(y,"Include this file for context",O)}},B=async(O)=>{let
|
|
74
|
-
`);if(!
|
|
75
|
-
`)}catch{return null}},[X,
|
|
76
|
-
`);y.current=
|
|
73
|
+
...`:"");J(y,"Include this file for context",O)}},B=async(O)=>{let C=[];if(G[O]?.loaded)C=G[O].entries;else{let y=await(await fetch(`/api/tree?session=${$}&path=${encodeURIComponent(O)}`)).json();if(y.entries)C=y.entries}await Promise.all(C.filter((S)=>S.type==="file").map((S)=>U(O?`${O}/${S.name}`:S.name)))},N=(O)=>_.get(O)||0,M=(O,C=0)=>{let S=G[O];if(!S?.expanded)return null;return S.entries.map((y)=>{let b=O?`${O}/${y.name}`:y.name,I=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+C*16}px`,paddingRight:"8px"},children:y.type==="dir"?i(D2,{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:(k)=>{k.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(D2,{children:[i("span",{onClick:()=>T(b),className:`flex-1 truncate cursor-pointer flex items-center gap-1.5 ${I>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:[I>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:I},void 0,!1,void 0,this),i("button",{onClick:(k)=>{k.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,C+1)]},b,!0,void 0,this)})};if(Y)return i(D2,{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(Q)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 E5,useState as z0,useContext as q8,useCallback as J8,useRef as s0,useMemo as x5}from"react";import{SessionContext as Q8}from"#canvas/runtime";var o0={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 m5(Y){let $=Y instanceof HTMLElement?Y:Y.parentElement;while($){if($.hasAttribute("data-line-num"))return $;$=$.parentElement}return null}function X8(Y){let $=Y.toString().trim(),Z=m5(Y.startContainer),J=m5(Y.endContainer),q=Z?parseInt(Z.getAttribute("data-line-num"),10):void 0,Q=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:Q}}function u5({path:Y}){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:Y},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 $=q8(Q8),{annotations:Z,addAnnotationWithId:J,activeAnnotationId:q,setActiveAnnotationId:Q}=Q1(),[X,G]=z0(null),[z,_]=z0("text"),[H,K]=z0(!0),[W,T]=z0(null),U=s0(null),[B,N]=z0(null),[M,O]=z0(null),C=s0(null),S=s0(null),y=s0([]),b=Z.filter((w)=>w.filePath===Y),I=U.current?.closest("#plan-scroll-container"),{popovers:k,openCreatePopover:c}=a1({containerRef:U,restoreKey:`${X}:${Y}`,restoreAnnotations:b,extractContext:X8,filePath:Y,scrollContainer:I});E5(()=>{K(!0),T(null),fetch(`/api/file?session=${$}&path=${encodeURIComponent(Y)}`).then((w)=>w.json()).then((w)=>{if(w.error)T(w.error),K(!1);else G(w.content),_(w.language||"text"),K(!1)}).catch(()=>{T("Failed to fetch file"),K(!1)})},[$,Y]);let f=J8((w,u)=>{w.preventDefault(),C.current=u,S.current=u,N(u),O(u)},[]);E5(()=>{let w=(h)=>{if(C.current===null)return;let A=h.target.closest("[data-line-num]");if(A){let D=parseInt(A.getAttribute("data-line-num"),10);S.current=D,O(D)}},u=()=>{let h=C.current;if(h===null)return;C.current=null;let A=S.current??h,D=Math.min(h,A),L=Math.max(h,A),x=y.current.slice(D-1,L).join(`
|
|
74
|
+
`);if(!x.trim()){N(null),O(null);return}let m=`__pending_${Date.now()}`,a={before:"",after:"",hierarchy:[],lineStart:D,lineEnd:L};if(U.current){let j=U.current.querySelectorAll("[data-line-num]"),v=j[D-1],$1=j[L-1];if(v&&$1){let v1=v.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,x,a)}N(null),O(null)};return document.addEventListener("mousemove",w),document.addEventListener("mouseup",u),()=>{document.removeEventListener("mousemove",w),document.removeEventListener("mouseup",u)}},[]);let V=x5(()=>{if(!X)return null;let w=window.hljs;if(!w)return null;let u=Y.split(".").pop()||"",h=o0[u];try{return(h?w.highlight(X,{language:h}):w.highlightAuto(X)).value.split(`
|
|
75
|
+
`)}catch{return null}},[X,Y]);if(H)return W1("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-[13px]",children:["Loading ",Y,"..."]},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 E=X.split(`
|
|
76
|
+
`);y.current=E;let g=x5(()=>{if(B===null)return null;let w=M??B;return{start:Math.min(B,w),end:Math.max(B,w)}},[B,M]),l=()=>{let w=X.split(`
|
|
77
77
|
`).slice(0,3).join(`
|
|
78
|
-
`)+(
|
|
79
|
-
...`:""),
|
|
78
|
+
`)+(E.length>3?`
|
|
79
|
+
...`:""),u=F1();J(u,w,"",Y),Q(u)};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:E.map((w,u)=>{let h=u+1,A=g&&h>=g.start&&h<=g.end;return W1("div",{"data-line-num":h,className:`flex px-5 ${A?"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:(D)=>f(D,h),children:h},void 0,!1,void 0,this),V?W1("code",{className:"py-px",dangerouslySetInnerHTML:{__html:V[u]||" "}},void 0,!1,void 0,this):W1("code",{className:"py-px",children:w||" "},void 0,!1,void 0,this)]},u,!0,void 0,this)})},void 0,!1,void 0,this),k]},void 0,!0,void 0,this)}import{useEffect as g5,useState as v5,useRef as z8}from"react";import{jsxDEV as j1}from"react/jsx-dev-runtime";function f5(Y,$){if($){let Z=$.replace(/\/+$/,"").split("/");return Z[Z.length-1]||Y}return Y.length>30?Y.slice(0,30)+"...":Y}function k2({currentSessionId:Y,projectRoot:$}){let[Z,J]=v5([]),[q,Q]=v5(!1),X=z8(null);g5(()=>{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)},[]),g5(()=>{if(!q)return;let _=(H)=>{if(X.current&&!X.current.contains(H.target))Q(!1)};return document.addEventListener("mousedown",_),()=>document.removeEventListener("mousedown",_)},[q]);let G=Z.filter((_)=>_.id!==Y),z=f5(Y,$);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/${Y}`,className:"text-text-primary hover:text-text-secondary transition-colors",children:z},void 0,!1,void 0,this),G.length>0&&j1("button",{onClick:()=>Q(!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:f5(_.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 h5(Y){let $=[];return t0(Y,$,0),$.join(`
|
|
80
80
|
`).replace(/\n{3,}/g,`
|
|
81
81
|
|
|
82
82
|
`).trim()+`
|
|
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(`
|
|
83
|
+
`}var _8=new Set(["CODE","SPAN","STRONG","EM","A","B","I","U","SMALL","SUB","SUP","MARK","ABBR"]);function t0(Y,$,Z){if(G8(Y)){let J=K8(Y);if(J)$.push(J,"");return}for(let J of Y.childNodes)if(J.nodeType===Node.ELEMENT_NODE)U8(J,$,Z);else if(J.nodeType===Node.TEXT_NODE){let q=J.textContent?.trim();if(q)$.push(q,"")}}function G8(Y){for(let $ of Y.childNodes){if($.nodeType===Node.TEXT_NODE)continue;if($.nodeType===Node.ELEMENT_NODE){let Z=$;if(!_8.has(Z.tagName)||Z.hasAttribute("data-md"))return!1}}return Y.childNodes.length>0}function K8(Y){let $="";for(let Z of Y.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 U8(Y,$,Z){let J=Y.getAttribute("data-md");if(J)switch(J){case"section":return H8(Y,$,Z);case"item":return W8(Y,$);case"codeblock":return T8(Y,$);case"callout":return N8(Y,$);case"note":return O8(Y,$);case"table":return F8(Y,$);case"checklist":return B8(Y,$);case"diff":return L8(Y,$);case"mermaid":return M8(Y,$);case"choice":return y8(Y,$);case"multichoice":return P8(Y,$);case"choice-option":case"multichoice-option":return;case"userinput":return S8(Y,$);case"rangeinput":return b8(Y,$);case"checklist-item":return;case"filepreview":return w8(Y,$);case"priority":return j8(Y,$)}if(Y.querySelector("button, input, select, textarea"))return;if(Y.children.length>0)t0(Y,$,Z);else{let q=Y.textContent?.trim();if(q)$.push(q,"")}}function H8(Y,$,Z){let J=Y.getAttribute("data-md-title")||"Untitled",q=Z===0?"##":"###";$.push(`${q} ${J}`,"");let Q=Y.querySelector(":scope > div:last-of-type");if(Q)t0(Q,$,Z+1)}function W8(Y,$){let Z=Y.getAttribute("data-md-label")||"",J=Y.getAttribute("data-md-status"),q=Y.getAttribute("data-md-badge"),Q="-";if(J==="done")Q="- [x]";else if(J)Q="- [ ]";let X=`${Q} **${Z}**`;if(q)X+=` \`${q}\``;$.push(X);let G=Y.querySelector(".text-text-secondary");if(G){let z=[];t0(G,z,0);for(let _ of z)$.push(_?` ${_}`:"")}$.push("")}function T8(Y,$){let Z=Y.getAttribute("data-md-language")||"",q=Y.querySelector("code")?.textContent||"";$.push(`\`\`\`${Z}`,q,"```","")}function N8(Y,$){let Z=Y.getAttribute("data-md-type")||"info",J={info:"Info",warning:"Warning",danger:"Danger",tip:"Tip"},q=A8(Y.querySelector(".text-text-secondary")||Y);$.push(`> **${J[Z]||Z}:** ${q}`,"")}function O8(Y,$){let Z=Y.textContent?.trim()||"";$.push(`> *${Z}*`,"")}function F8(Y,$){let Z=Y.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 Q=[];for(let X of q.querySelectorAll("td"))Q.push(X.textContent?.trim()||"");$.push(`| ${Q.join(" | ")} |`)}$.push("")}function B8(Y,$){for(let Z of Y.querySelectorAll("li")){let J=Z.querySelector(".bg-accent-green")!==null,q=Z.textContent?.trim()||"";$.push(`- [${J?"x":" "}] ${q}`)}$.push("")}function L8(Y,$){let Z=Y.getAttribute("data-md-language")||"";$.push(`\`\`\`diff${Z?` (${Z})`:""}`);for(let J of Y.querySelectorAll("[class*='flex']")){let q=J.querySelector(".text-accent-red")?"-":J.querySelector(".text-accent-green")?"+":" ",Q=J.querySelector("code");if(Q)$.push(`${q} ${Q.textContent}`)}$.push("```","")}function M8(Y,$){let Z=Y.getAttribute("data-md-source")||"";if(Z)$.push("```mermaid",Z,"```","")}function y8(Y,$){let Z=Y.getAttribute("data-md-label")||"";$.push(`**${Z}:**`);for(let J of Y.querySelectorAll("[data-md='choice-option']")){let q=J.getAttribute("data-md-label")||J.textContent?.trim()||"",Q=J.querySelector(".bg-accent-amber")!==null;$.push(`- ${Q?"(x)":"( )"} ${q}`)}$.push("")}function P8(Y,$){let Z=Y.getAttribute("data-md-label")||"";$.push(`**${Z}:**`);for(let J of Y.querySelectorAll("[data-md='multichoice-option']")){let q=J.getAttribute("data-md-label")||J.textContent?.trim()||"",Q=J.querySelector(".bg-accent-amber")!==null;$.push(`- [${Q?"x":" "}] ${q}`)}$.push("")}function S8(Y,$){let Z=Y.getAttribute("data-md-label")||"",q=Y.querySelector("textarea")?.value?.trim()||"";$.push(`**${Z}:** ${q||"_empty_"}`,"")}function b8(Y,$){let Z=Y.getAttribute("data-md-label")||"",J=Y.querySelector("input[type='range']"),Q=Y.querySelector(".font-mono")?.textContent?.trim()||J?.value||"—";$.push(`**${Z}:** ${Q}`,"")}function w8(Y,$){let Z=Y.getAttribute("data-md-path")||"",J=Y.getAttribute("data-md-lines")||"",Q=Y.querySelector("code")?.textContent||"",X=Z.split(".").pop()||"",G=o0[X]||"",z=J?`${Z} (L${J})`:Z;$.push(z,"",`\`\`\`${G}`,Q,"```","")}function j8(Y,$){}function A8(Y){return Y?.textContent?.trim()||""}import e5,{useEffect as m1,useState as _1,useRef as V1,useCallback as $3,useMemo as Y2,useContext as c8}from"react";import{useEffect as C8,useState as I8,useRef as V8,useContext as R8}from"react";import{jsxDEV as H1,Fragment as p5}from"react/jsx-dev-runtime";function D8(Y){return Y.label||`Round ${Y.revision}`}function k8(Y){let $=Date.now()-new Date(Y).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 S0({value:Y,onChange:$,accent:Z="default",className:J}){let{currentRevision:q,revisions:Q}=R8(w1),[X,G]=I8(!1),z=V8(null);C8(()=>{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 _=Q.find((K)=>K.revision===Y);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:[_?D8(_):`Round ${Y}`,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:[...Q].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===Y?"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(p5,{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(p5,{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":k8(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(Y,$){let Z=Y.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][_]=Y[z-1]===$[_-1]?q[z-1][_-1]+1:Math.max(q[z-1][_],q[z][_-1]);let Q=[],X=Z,G=J;while(X>0&&G>0)if(Y[X-1]===$[G-1])Q.unshift(Y[X-1]),X--,G--;else if(q[X-1][G]>q[X][G-1])X--;else G--;return Q}function c5(Y){let $=[],Z=[],J=document.createTreeWalker(Y,NodeFilter.SHOW_TEXT,{acceptNode(Q){let X=Q.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 E2(Y,$){if(Y.length>5000||$.length>5000)return E8(Y,$);return l5(Y,$)}function l5(Y,$){let Z=n0(Y,$),J=[],q=[],Q=0,X=0,G=0;while(Q<Y.length||X<$.length)if(G<Z.length&&Q<Y.length&&X<$.length&&Y[Q]===Z[G]&&$[X]===Z[G])J.push({type:"same",index:Q}),q.push({type:"same",index:X}),Q++,X++,G++;else if(Q<Y.length&&(G>=Z.length||Y[Q]!==Z[G]))J.push({type:"removed",index:Q}),Q++;else if(X<$.length)q.push({type:"added",index:X}),X++;return{oldOps:J,newOps:q}}function n0(Y,$){let Z=Y.length,J=$.length;if(Z===0||J===0)return[];if(Z===1)return $.includes(Y[0])?[Y[0]]:[];if(J===1)return Y.includes($[0])?[$[0]]:[];if(Z*J<=1e6)return x1(Y,$);let q=Math.floor(Z/2),Q=Y.slice(0,q),X=Y.slice(q),G=d5(Q,$),z=d5([...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[...n0(Q,K),...n0(X,W)]}function d5(Y,$){let Z=$.length,J=Array(Z+1).fill(0),q=Array(Z+1).fill(0);for(let Q=0;Q<Y.length;Q++){for(let X=1;X<=Z;X++)q[X]=Y[Q]===$[X-1]?J[X-1]+1:Math.max(J[X],q[X-1]);[J,q]=[q,J],q.fill(0)}return J}function E8(Y,$){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(Y),Q=J($),X=q.map((U)=>U.text),G=Q.map((U)=>U.text),z=n0(X,G),_=[],H=[],K=0,W=0,T=0;while(K<q.length||W<Q.length)if(T<z.length&&K<q.length&&W<Q.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=Q[W].start;U<Q[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<Q.length&&(T>=z.length||G[W]!==z[T])){let U=l5(Y.slice(q[K].start,q[K].end),$.slice(Q[W].start,Q[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+Q[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<Q.length){for(let U=Q[W].start;U<Q[W].end;U++)H.push({type:"added",index:U});W++}return{oldOps:_,newOps:H}}function r5(Y,$,Z){let J=new Map;for(let q of Y){if(q.type==="same")continue;let Q=$[q.index];if(!Q||!Q.node.parentNode)continue;let X=J.get(Q.node);if(!X)X=[],J.set(Q.node,X);X.push({offset:Q.offset,length:Q.text.length})}for(let[q,Q]of J){if(!q.parentNode)continue;let X=q.nodeValue||"";Q.sort((K,W)=>K.offset-W.offset);let G=[];for(let K of Q){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 e0(Y,$){let Z=x8(Y,$),J=c5(Y),q=c5($),{oldOps:Q,newOps:X}=E2(J.words,q.words),G=Q.some((z)=>z.type==="removed")||X.some((z)=>z.type==="added");return r5(Q,J.map,"diff-removed"),r5(X,q.map,"diff-added"),G||Z}function x8(Y,$){let Z=Array.from(Y.querySelectorAll('[data-md="mermaid"]')),J=Array.from($.querySelectorAll('[data-md="mermaid"]')),q=!1,Q=Math.max(Z.length,J.length);for(let X=0;X<Q;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
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
|
-
`),
|
|
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(`
|
|
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 C=0,S=0;while(S<B.length){let y=document.createElement("div");if(y.className="px-3 py-0.5 whitespace-pre-wrap",C<N.length&&B[S]===N[C])y.textContent=" "+B[S],S++,C++;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 _0(Y){let $=[],Z=Y.querySelectorAll(":scope > [data-md]");for(let J of Z)$.push(b0(J));if($.length===0){let J=Y.querySelectorAll("[data-md]"),q=new Set;for(let Q of J){let X=Q.parentElement?.closest("[data-md]");if(X&&Y.contains(X))continue;if(q.has(Q))continue;q.add(Q),$.push(b0(Q))}}return $}function b0(Y){let $=Y.getAttribute("data-md")||"unknown",Z=m8(Y,$),J=[];if($==="section"){let q=Y.querySelector(":scope > div.mt-6, :scope > div:last-child");if(q)for(let Q of q.querySelectorAll(":scope > [data-md]"))J.push(b0(Q))}else if($==="table")for(let q of Y.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 Y.querySelectorAll(":scope > [data-md='checklist-item']"))J.push(b0(q));else for(let q of Y.querySelectorAll("[data-md]"))if(q.parentElement?.closest("[data-md]")===Y)J.push(b0(q));return{key:Z,type:$,element:Y,children:J}}function m8(Y,$){switch($){case"section":return"section:"+(Y.getAttribute("data-md-title")||"");case"item":return"item:"+(Y.getAttribute("data-task-id")||Y.getAttribute("data-md-label")||"");case"codeblock":case"diff":return $+":"+(Y.textContent||"").slice(0,80);case"checklist-item":return"checklist-item:"+(Y.getAttribute("data-md-label")||Y.textContent?.slice(0,60)||"");case"checklist":return"checklist:"+Y.querySelectorAll("[data-md='checklist-item']").length;case"markdown":return"markdown:"+(Y.getAttribute("data-md-file")||"inline");case"mermaid":return"mermaid:"+(Y.getAttribute("data-md-source")||"").slice(0,80);case"callout":return"callout:"+(Y.getAttribute("data-md-type")||"")+":"+(Y.textContent||"").slice(0,60);default:return $+":"+(Y.getAttribute("data-md-label")||Y.textContent?.slice(0,60)||"")}}function w0(Y,$){let Z=Y.map((_)=>_.key),J=$.map((_)=>_.key),q=x1(Z,J),Q=[],X=0,G=0,z=0;while(X<Y.length||G<$.length)if(z<q.length&&X<Y.length&&G<$.length&&Z[X]===q[z]&&J[G]===q[z]){let _=Y[X],H=$[G],K=_.children.length>0||H.children.length>0?w0(_.children,H.children):void 0;Q.push({kind:"matched",oldBlock:_,newBlock:H,childMatches:K}),X++,G++,z++}else if(X<Y.length&&(z>=q.length||Z[X]!==q[z]))Q.push({kind:"removed",oldBlock:Y[X]}),X++;else if(G<$.length)Q.push({kind:"added",newBlock:$[G]}),G++;return Q}function $2(Y){let $=document.createDocumentFragment(),Z=!1;for(let J of Y)if(J.kind==="removed")Z=!0,$.appendChild(a5(J.oldBlock.element));else if(J.kind==="added")Z=!0,$.appendChild(u8(J.newBlock.element));else{let q=J.newBlock.element.cloneNode(!0),Q=J.newBlock.type;if(Q==="mermaid"){if(n5(J.oldBlock.element,q))Z=!0}else if(J.childMatches&&J.childMatches.length>0&&(Q==="table"||Q==="checklist")){if(s5(q,J.childMatches,Q))Z=!0}else if(J.childMatches&&J.childMatches.length>0){if(o5(J.oldBlock,q,J.childMatches,Q))Z=!0}else if(Q==="markdown"){if(t5(J.oldBlock.element,q))Z=!0}else if(n1(J.oldBlock.element,q,!1))Z=!0;$.appendChild(q)}return{fragment:$,hasChanges:Z}}function a5(Y){let $=Y.cloneNode(!0);return $.classList.add("diff-block-removed"),$.style.position="relative",x2($,"Removed","var(--color-accent-red)"),$}function u8(Y){let $=Y.cloneNode(!0);return $.classList.add("diff-block-added"),$.style.position="relative",x2($,"Added","var(--color-accent-green)"),$}function o5(Y,$,Z,J){let q=!1,Q=g8(Y,$),X,G;if(J==="section"){let z=Y.element.querySelector(":scope > div:first-child"),_=$.querySelector(":scope > div:first-child");if(z&&_){if(n1(z,_,!1))q=!0}X=Y.element.querySelector(":scope > div.mt-6, :scope > div:last-child"),G=$.querySelector(":scope > div.mt-6, :scope > div:last-child")}else X=Y.element,G=$;if(!X||!G)return q;for(let z of Z)if(z.kind==="matched"){let _=Q.newMap.get(z.newBlock.element);if(_){if(z.newBlock.type==="mermaid"){if(n5(z.oldBlock.element,_))q=!0}else if(z.childMatches&&z.childMatches.length>0&&(z.newBlock.type==="table"||z.newBlock.type==="checklist")){if(s5(_,z.childMatches,z.newBlock.type))q=!0}else if(z.childMatches&&z.childMatches.length>0){if(o5(z.oldBlock,_,z.childMatches,z.newBlock.type))q=!0}else if(z.newBlock.type==="markdown"){if(t5(z.oldBlock.element,_))q=!0}else if(n1(z.oldBlock.element,_,!1))q=!0}}else if(z.kind==="removed"){q=!0;let _=a5(z.oldBlock.element),H=f8(Z,z,Q.newMap),K=H?h8(G,H):null;G.insertBefore(_,K)}else if(z.kind==="added"){q=!0;let _=Q.newMap.get(z.newBlock.element);if(_)_.classList.add("diff-block-added"),_.style.position="relative",x2(_,"Added","var(--color-accent-green)")}if(n1(X,G,!0))q=!0;return q}function s5(Y,$,Z){let J=Z==="table"?Y.querySelector(":scope table > tbody"):Y;if(!J)return!1;let q=!1;J.innerHTML="";for(let Q of $)if(Q.kind==="removed"){q=!0;let X=Q.oldBlock.element.cloneNode(!0);X.classList.add(Z==="table"?"diff-row-removed":"diff-item-removed"),J.appendChild(X)}else if(Q.kind==="added"){q=!0;let X=Q.newBlock.element.cloneNode(!0);X.classList.add(Z==="table"?"diff-row-added":"diff-item-added"),J.appendChild(X)}else{let X=Q.newBlock.element.cloneNode(!0);if(n1(Q.oldBlock.element,X,!1))q=!0;J.appendChild(X)}return q}function g8(Y,$){let Z=new Map,J=Y.element.querySelectorAll("[data-md]"),q=$.querySelectorAll("[data-md]");return{newMap:{get(Q){return v8($,Q)}}}}function v8(Y,$){let Z=$.getAttribute("data-md");if(!Z)return null;let J=$.getAttribute("data-md-label"),q=$.getAttribute("data-md-title"),Q=`[data-md="${Z}"]`;if(q)Q+=`[data-md-title="${CSS.escape(q)}"]`;else if(J)Q+=`[data-md-label="${CSS.escape(J)}"]`;let X=Y.querySelectorAll(Q);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 f8(Y,$,Z){let J=Y.indexOf($);for(let q=J+1;q<Y.length;q++){let Q=Y[q];if((Q.kind==="matched"||Q.kind==="added")&&Q.newBlock)return Z.get(Q.newBlock.element)||null}return null}function h8(Y,$){let Z=$;while(Z&&Z.parentElement!==Y)Z=Z.parentElement;return Z}function t5(Y,$){let Z=Array.from(Y.children),J=Array.from($.children);if(Z.length===0&&J.length===0)return n1(Y,$,!1);let q=Z.map((W)=>W.tagName.toLowerCase()),Q=J.map((W)=>W.tagName.toLowerCase()),X=x1(q,Q),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]&&Q[_]===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 i5(Y,$){let Z=$?new Set(Array.from(Y.querySelectorAll("[data-md]"))):new Set,J=[],q=[],Q=document.createTreeWalker(Y,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=Q.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(Y,$,Z){let J=i5(Y,Z),q=i5($,Z);if(J.words.length===0&&q.words.length===0)return!1;let{oldOps:Q,newOps:X}=E2(J.words,q.words),G=Q.some((N)=>N.type==="removed"),z=X.some((N)=>N.type==="added");if(!G&&!z)return!1;let _=[],H=[];for(let N of Q)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 Q)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)p8(N,T.get(N)||[],U.get(N)||[]);return!0}function p8(Y,$,Z){if(!Y.parentNode)return;let J=Y.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 Q=Y.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),_++}Q.replaceChild(X,Y)}function n5(Y,$){let Z=(Y.getAttribute("data-md-source")||"").trim(),J=($.getAttribute("data-md-source")||"").trim();if(Z===J)return!1;let q=Z.split(`
|
|
86
|
+
`),Q=J.split(`
|
|
87
|
+
`),X=x1(q,Q),G=[],z=0,_=0,H=0;while(z<q.length||_<Q.length)if(H<X.length&&z<q.length&&_<Q.length&&q[z]===X[H]&&Q[_]===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(_<Q.length)G.push({type:"added",line:Q[_]}),_++;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 x2(Y,$,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)`,Y.appendChild(J)}import{jsxDEV as p}from"react/jsx-dev-runtime";function d8(Y,$,Z){let J=Y.find((X)=>X.revision===$),q=Y.find((X)=>X.revision===Z),Q=new Set;for(let X of J?.canvasFiles||[])Q.add(X.filename);for(let X of q?.canvasFiles||[])Q.add(X.filename);return[...Q].sort()}function Y3({initialLeft:Y,initialRight:$,sessionId:Z,onExit:J}){let[q,Q]=_1(Y),[X,G]=_1($),[z,_]=_1("unified"),[H,K]=_1(!0),[W,T]=_1(!1),{revisions:U}=c8(w1),B=Y2(()=>d8(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=Y2(()=>{return U.find((y)=>y.revision===q)?.canvasFiles.some((y)=>y.filename===N)??!1},[U,q,N]),C=Y2(()=>{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(S0,{value:q,onChange:Q,accent:"red"},void 0,!1,void 0,this),p("span",{className:"text-text-tertiary text-[13px]",children:"→"},void 0,!1,void 0,this),p(S0,{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(r8,{},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,I=U.find((f)=>f.revision===q)?.canvasFiles.some((f)=>f.filename===S),k=U.find((f)=>f.revision===X)?.canvasFiles.some((f)=>f.filename===S),c=!I?" (added)":!k?" (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] ${!I?"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||!C?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(l8,{sessionId:Z,leftRev:q,rightRev:X,filename:N,onDiffResult:(S,y)=>{T(S),K(y)}},`unified-${q}-${X}-${N}`,!1,void 0,this):p(i8,{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 r8(){let[Y,$]=_1(!0);return m1(()=>{return document.documentElement.dataset.syncScroll=Y?"1":"0",()=>{delete document.documentElement.dataset.syncScroll}},[Y]),p("label",{className:"flex items-center gap-1.5 cursor-pointer select-none",children:[p("input",{type:"checkbox",checked:Y,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 l8({sessionId:Y,leftRev:$,rightRev:Z,filename:J,onDiffResult:q}){let Q=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}=Q1(),C=O.filter((y)=>!y.filePath&&(!y.canvasFile||y.canvasFile===J)),{popovers:S}=a1({containerRef:G,restoreKey:W,restoreAnnotations:C,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:!!Q.current,newRef:!!X.current}),M(!0)},1e4);return()=>clearTimeout(y)},[W,U,z,H]),m1(()=>{if(!z||!H||W)return;if(!Q.current||!X.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!Q.current||!X.current||!G.current){console.warn("[unified-diff] refs lost between rAF frames",{old:!!Q.current,new:!!X.current,unified:!!G.current});return}try{let y=_0(Q.current),b=_0(X.current),I=w0(y,b),{fragment:k,hasChanges:c}=$2(I);G.current.innerHTML="",G.current.appendChild(k),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:Q,sessionId:Y,revision:$,filename:J,onReady:()=>_(!0),onError:(y)=>B(`Rev ${$}: ${y}`)},void 0,!1,void 0,this),p(R1,{ref:X,sessionId:Y,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 i8({sessionId:Y,leftRev:$,rightRev:Z,filename:J,onDiffResult:q}){let Q=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=$3(()=>z(!0),[]),O=$3(()=>H(!0),[]),{annotations:C}=Q1(),S=C.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(!Q.current||!X.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!Q.current||!X.current)return;let b=e0(Q.current,X.current);W(!0),q(!0,b)})})},[G,_,K]),m1(()=>{let b=U.current,I=B.current;if(!b||!I)return;let k=(V,E)=>{if(document.documentElement.dataset.syncScroll==="0")return;if(N.current)return;N.current=!0;let g=V.scrollHeight-V.clientHeight,l=E.scrollHeight-E.clientHeight;if(g>0&&l>0)E.scrollTop=V.scrollTop/g*l;requestAnimationFrame(()=>{N.current=!1})},c=()=>k(b,I),f=()=>k(I,b);return b.addEventListener("scroll",c),I.addEventListener("scroll",f),()=>{b.removeEventListener("scroll",c),I.removeEventListener("scroll",f)}},[]),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:Q,sessionId:Y,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:Y,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=e5.memo(e5.forwardRef(({sessionId:Y,revision:$,filename:Z,onReady:J,onError:q},Q)=>{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/${Y}/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)})},[Y,$,Z]),m1(()=>{if(!X)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{J()})})},[X]);let W=Y2(()=>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:Q,children:W},void 0,!1,void 0,this)}));import{useState as D1,useContext as m2,useMemo as a8,useRef as j0,useEffect as q3,useCallback as Z3}from"react";import{SessionContext as o8}from"#canvas/runtime";import{jsxDEV as r}from"react/jsx-dev-runtime";function u2(Y,$){if(!Y)return[];return Y.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 J3(Y){return Y.filter(($)=>$.status!=="unchanged").map(($)=>$.filename)}function Q3({revision:Y,responseBanner:$}){let{setActiveView:Z}=m2(I1),{revisions:J}=m2(w1),q=J.find((_)=>_.revision===Y),Q=J.find((_)=>_.revision===Y-1),X=a8(()=>u2(q,Q),[q,Q]),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(t8,{change:_,revision:Y,previousRevision:Q?.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(Y4,{change:_,revision:Y,onOpenTab:()=>Z({type:"canvas",filename:_.filename})},_.filename,!1,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function s8({mode:Y,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 ${Y===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 t8({change:Y,revision:$,previousRevision:Z,onOpenTab:J}){let q=Y.filename.replace(/\.jsx$/,""),Q=Y.status==="new",X=Y.diffStats,G=Y.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 ${Q?"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:Q?"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(s8,{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":Y.filename,children:r(L0,{revision:$,filename:Y.filename},void 0,!1,void 0,this)},void 0,!1,void 0,this):G&&Z!=null?r(n8,{filename:Y.filename,leftRev:Z,rightRev:$,mode:z},`${z}-${$}-${Z}`,!1,void 0,this):null]},void 0,!0,void 0,this)}function n8({filename:Y,leftRev:$,rightRev:Z,mode:J}){let q=m2(o8);if(J==="unified")return r(e8,{sessionId:q,filename:Y,leftRev:$,rightRev:Z},void 0,!1,void 0,this);return r($4,{sessionId:q,filename:Y,leftRev:$,rightRev:Z},void 0,!1,void 0,this)}function e8({sessionId:Y,filename:$,leftRev:Z,rightRev:J}){let q=j0(null),Q=j0(null),X=j0(null),[G,z]=D1(!1),[_,H]=D1(!1),[K,W]=D1(!1),[T,U]=D1(null);return q3(()=>{if(!G||!_||K)return;if(!q.current||!Q.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!q.current||!Q.current||!X.current)return;try{let B=_0(q.current),N=_0(Q.current),M=w0(B,N),{fragment:O}=$2(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:Y,revision:Z,filename:$,onReady:()=>z(!0),onError:(B)=>U(B)},void 0,!1,void 0,this),r(R1,{ref:Q,sessionId:Y,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 $4({sessionId:Y,filename:$,leftRev:Z,rightRev:J}){let q=j0(null),Q=j0(null),[X,G]=D1(!1),[z,_]=D1(!1),[H,K]=D1(!1),W=Z3(()=>G(!0),[]),T=Z3(()=>_(!0),[]);return q3(()=>{if(!X||!z||H)return;if(!q.current||!Q.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!q.current||!Q.current)return;e0(q.current,Q.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:Y,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:Q,sessionId:Y,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 Y4({change:Y,revision:$,onOpenTab:Z}){let[J,q]=D1(!1),Q=Y.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:Q},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":Y.filename,children:r(L0,{revision:$,filename:Y.filename},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{useState as Z2,useEffect as Z4,useCallback as g2}from"react";import{jsxDEV as n}from"react/jsx-dev-runtime";function X3({sessionId:Y,revision:$,open:Z,shareEnabled:J,existingShares:q,onClose:Q,onShareCreated:X,onShareRevoked:G}){let[z,_]=Z2(!1),[H,K]=Z2(!1),[W,T]=Z2(null),[U,B]=Z2(!1),N=q.find((S)=>S.revision===$);Z4(()=>{if(!Z)_(!1),K(!1),T(null),B(!1)},[Z]);let M=g2(async()=>{_(!0),T(null);try{let S=await fetch(`/api/session/${Y}/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)}},[Y,$,X]),O=g2(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/${Y}/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)}},[Y,G]),C=g2((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:Q,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:Q,className:"w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",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:()=>C(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 z3({onClick:Y,title:$="Share this revision",hasShare:Z}){return n("button",{onClick:Y,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 q4,useEffect as J4,useRef as Q4}from"react";import{jsxDEV as L1}from"react/jsx-dev-runtime";function _3({open:Y,onClose:$,onSubmit:Z}){let[J,q]=q4(""),Q=Q4(null);if(J4(()=>{if(Y)q(""),setTimeout(()=>Q.current?.focus(),50)},[Y]),!Y)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:Q,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 C0}from"react/jsx-dev-runtime";function K3(Y){let $=[];for(let Z of Y)for(let J of Z.annotations)$.push({...J,source:"remote",author:Z.author});return $}var I1=T3({activeView:{type:"overview"},setActiveView:()=>{},openFiles:[],closeFile:()=>{},canvasFiles:[]}),w1=T3({currentRevision:1,selectedRevision:1,revisions:[],setSelectedRevision:()=>{},isReadOnly:!1,compareRevision:null,setCompareRevision:()=>{},agentWatching:!1});function G4(Y){if(Y==="auto")return window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light";return Y}function U3(Y){document.documentElement.dataset.theme=G4(Y)}function O3(){let[Y,$]=Y1(()=>{let q=localStorage.getItem("canvas-theme");if(q==="light"||q==="dark"||q==="auto")return q;return"auto"});return M1(()=>{if(U3(Y),Y!=="auto")return;let q=window.matchMedia("(prefers-color-scheme: dark)"),Q=()=>U3("auto");return q.addEventListener("change",Q),()=>q.removeEventListener("change",Q)},[Y]),F("button",{onClick:()=>{let q=Y==="auto"?"light":Y==="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)"}[Y],children:Y==="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):Y==="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 F3(){let{currentRevision:Y,selectedRevision:$,revisions:Z,setSelectedRevision:J,setCompareRevision:q}=u1.useContext(w1);if(Z.length<=1){let G=Z[0]?.label||`Round ${Y}`;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(S0,{value:$,onChange:J,accent:$===Y?"default":"amber"},void 0,!1,void 0,this),F("button",{onClick:()=>{let X;if($===Y)X=[...Z].reverse().find((z)=>z.revision<Y)?.revision??Math.max(1,Y-1);else X=$;q({left:X,right:Y})},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 K4(){let Y=Z1.isShared?Z1.shareId:Z1.sessionId,$=Z1.isShared,[Z,J]=Y1(1),[q,Q]=Y1(1),[X,G]=Y1([]),[z,_]=Y1(null),[H,K]=Y1(!1),[W,T]=Y1(!1),[U,B]=Y1(!1),[N,M]=Y1([]),[O,C]=Y1({type:"overview"}),[S,y]=Y1([]),b=g1(null),[I,k]=Y1(),[c,f]=Y1(!1),[V,E]=Y1(!1),[g,l]=Y1(!1),[w,u]=Y1(!1),[h,A]=Y1([]),[D,L]=Y1(!1),[d,x]=Y1(new Map),[m,a]=Y1(!1),[j,v]=Y1(null),[$1,K1]=Y1(null);M1(()=>{if(!$1)return;let R=setTimeout(()=>K1(null),4000);return()=>clearTimeout(R)},[$1]),M1(()=>{let R=["Agent Canvas"];if(I){let o=I.replace(/\/+$/,"").split("/");R.push(o[o.length-1]||Y)}else if(Y)R.push(Y);if(O.type==="file")R.push(O.path.split("/").pop()||O.path);else if(O.type==="overview")R.push("Overview");else if(O.type==="canvas"&&N.length>1&&O.filename)R.push(O.filename.replace(/\.jsx$/,""));else if(z)R.push("Compare");document.title=R.join(" — ")},[Y,I,O,z]);let v1=g1(new Map),A1=X.find((R)=>R.revision===q),e1=q!==Z||!!A1?.hasFeedback||W,v2=A0((R)=>{let o=O.type==="overview"?"overview":O.type==="canvas"?`canvas:${O.filename}`:`file:${O.path}`;if(v1.current.set(o,window.scrollY),C(R),R.type==="file")y((e)=>e.includes(R.path)?e:[...e,R.path])},[O]),B3=A0((R)=>{v1.current.delete(`file:${R}`),y((o)=>o.filter((e)=>e!==R)),C((o)=>{if(o.type==="file"&&o.path===R)return N.length>1?{type:"overview"}:{type:"canvas",filename:N[0]||""};return o})},[N]);X4(()=>{let R=O.type==="overview"?"overview":O.type==="canvas"?`canvas:${O.filename}`:`file:${O.path}`;window.scrollTo(0,v1.current.get(R)||0)},[O]),M1(()=>{if(!Y)return;fetch(_5()).then((R)=>R.json()).then((R)=>{if(R.currentRevision)J(R.currentRevision),Q(R.currentRevision),G(R.revisions||[]);if(R.canvasFiles){let o=R.canvasFiles.sort();M(o),C((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(R.projectRoot)k(R.projectRoot);if(Array.isArray(R.shares))A(R.shares);L(!!R.shareEnabled)}).catch(()=>{})},[Y]),M1(()=>{if(!Y||!q||$)return;fetch(`/api/session/${Y}/revision/${q}/remote-feedback`).then((R)=>R.json()).then((R)=>{if(!Array.isArray(R.entries))return;let o=K3(R.entries);x((e)=>{let y1=new Map(e);return y1.set(q,o),y1})}).catch(()=>{})},[Y,q,$]),M1(()=>{if(!Y)return;if(!T5){K(!0);return}let R=null,o=()=>{let e=window.location.protocol==="https:"?"wss:":"ws:",y1=new WebSocket(`${e}//${window.location.host}/ws/session/${Y}`);b.current=y1,y1.onopen=()=>K(!0),y1.onclose=()=>{K(!1),R=setTimeout(o,2000)},y1.onmessage=(h2)=>{try{let G1=JSON.parse(h2.data);if(G1.type==="plan-updated"){if(J(G1.currentRevision),Q(G1.currentRevision),_(null),G1.revisions){let $0=G1.revisions;G($0);let G0=$0.find((f1)=>f1.revision===G1.currentRevision);if(G0?.canvasFiles){let f1=G0.canvasFiles.map((U0)=>U0.filename).sort();M(f1);let J2=$0.find((U0)=>U0.revision===G1.currentRevision-1),K0=u2(G0,J2),Y0=J3(K0);if(Y0.length===1)C({type:"canvas",filename:Y0[0]});else if(Y0.length>1||f1.length>1)C({type:"overview"});else C({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,G0=G1.entries||[],f1=K3(G0);x((J2)=>{let K0=new Map(J2),Y0=K0.get($0)||[],U0=new Set(Y0.map((Q2)=>Q2.id)),L3=[...Y0,...f1.filter((Q2)=>!U0.has(Q2.id))];return K0.set($0,L3),K0})}}catch{}}};return o(),()=>{if(R)clearTimeout(R);b.current?.close()}},[Y]);let q2=A0(async(R,o)=>{try{let e=localStorage.getItem(`canvas:${Y}:rev:${q}`),y1=[];if(e)try{y1=(JSON.parse(e).annotations||[]).filter((G1)=>G1.source!=="remote")}catch{}await W5({author:o,revision:q,annotations:y1,generalNote:R}),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}`})}},[Y,q]),f2=A0(async(R)=>{if($){let o=B2();if(!o){v(R),a(!0);return}await q2(R,o);return}if(b.current?.readyState===WebSocket.OPEN)b.current.send(JSON.stringify({type:"submit",feedback:R}))},[$,q2]);if(!Y)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(N3.Provider,{value:Y,children:F(w1.Provider,{value:{currentRevision:Z,selectedRevision:q,revisions:X,setSelectedRevision:Q,isReadOnly:e1,compareRevision:z,setCompareRevision:_,agentWatching:U},children:F(J5,{sessionId:Y,revision:q,isReadOnly:e1,remoteAnnotations:d.get(q),children:F(I1.Provider,{value:{activeView:O,setActiveView:v2,openFiles:S,closeFile:B3,canvasFiles:N},children:F(_4.Provider,{value:{setActiveView:v2},children:F("div",{className:"min-h-screen bg-bg-base",children:[F(U4,{sessionId:Y,projectRoot:I,connected:H,onMobileSidebar:()=>f(!c),collapsed:V,onToggle:()=>E((R)=>!R)},void 0,!1,void 0,this),F(H4,{collapsed:g,onToggle:()=>l((R)=>!R),children:F(R2,{onSubmit:f2},void 0,!1,void 0,this)},void 0,!1,void 0,this),z!==null?F("div",{className:`${V?"lg:ml-0":"lg:ml-60"} ${g?"lg:mr-0":"lg:mr-[var(--sidebar-width,320px)]"} transition-[margin] duration-200`,children:F(Y3,{initialLeft:z.left,initialRight:z.right,sessionId:Y,onExit:()=>_(null)},void 0,!1,void 0,this)},void 0,!1,void 0,this):F("div",{className:`relative ${V?"lg:ml-0":"lg:ml-60"} ${g?"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(k2,{currentSessionId:Y,projectRoot:I},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(F3,{},void 0,!1,void 0,this),F("button",{onClick:()=>f(!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(O3,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),F(W4,{},void 0,!1,void 0,this),O.type==="overview"&&F(Q3,{revision:q,responseBanner:A1?.response?F(H3,{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:[D&&F("div",{className:"absolute top-3 right-12 z-10",children:F(z3,{onClick:()=>u(!0),hasShare:h.some((R)=>R.revision===q),title:h.some((R)=>R.revision===q)?"Manage share link":"Share this revision"},void 0,!1,void 0,this)},void 0,!1,void 0,this),F("button",{onClick:()=>{let R=document.querySelector(`[data-canvas-file="${O.filename}"] .plan-content`);if(!R)return;let o=h5(R);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(H3,{markdown:A1.response},void 0,!1,void 0,this),F("div",{"data-canvas-file":O.filename,children:F(L0,{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((R)=>F("div",{style:{display:O.type==="file"&&O.path===R?void 0:"none"},children:F(u5,{path:R},void 0,!1,void 0,this)},R,!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:()=>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(R2,{onSubmit:f2},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(X3,{sessionId:Y,revision:q,open:w,shareEnabled:D,existingShares:h,onClose:()=>u(!1),onShareCreated:(R)=>{A((o)=>[...o.filter((e)=>e.shareId!==R.shareId),R]),K1({kind:"success",message:"Share link created. Copy and send it to reviewers."})},onShareRevoked:(R)=>{A((o)=>o.filter((e)=>e.shareId!==R)),K1({kind:"success",message:"Share link revoked."})}},void 0,!1,void 0,this),F(_3,{open:m,onClose:()=>{a(!1),v(null)},onSubmit:async(R)=>{let o=H5(R);if(a(!1),j!==null)await q2(j,o),v(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)},`${Y}:${q}`,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function U4({sessionId:Y,projectRoot:$,connected:Z,onMobileSidebar:J,collapsed:q,onToggle:Q}){let X=Z1.isShared;return F(C0,{children:[q&&F("button",{onClick:Q,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(C0,{children:[F(k2,{currentSessionId:Y,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:Q,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(F3,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("div",{className:"flex-1 flex flex-col overflow-hidden",children:F(k5,{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(O3,{},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 H4({children:Y,collapsed:$,onToggle:Z}){let[J,q]=Y1(()=>{let H=localStorage.getItem("canvas-sidebar-width");return H?parseInt(H,10):320}),Q=g1(!1),X=g1(0),G=g1(0),z=g1(J);z.current=J;let _=A0((H)=>{H.preventDefault(),Q.current=!0,X.current=H.clientX,G.current=z.current;let K=(T)=>{if(!Q.current)return;let U=X.current-T.clientX,B=Math.max(240,Math.min(600,G.current+U));q(B),z.current=B},W=()=>{Q.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(C0,{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(Y,(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 H3({markdown:Y}){let[$,Z]=Y1(!1),J=G3(()=>t.parse(Y,{async:!1}),[Y]),q=g1(null),{annotations:Q,addAnnotationWithId:X,removeAnnotation:G,updateAnnotation:z,addAnnotationImage:_,removeAnnotationImage:H,activeAnnotationId:K,setActiveAnnotationId:W}=Q1(),[T,U]=Y1(null),[B,N]=Y1(null),M=G3(()=>Q.filter((b)=>b.filePath===T1),[Q]),[O,C]=Y1(Y);if(Y!==O)C(Y),Z(!1);M1(()=>{if(!q.current||M.length===0)return;let b=setTimeout(()=>{if(q.current)h0(q.current,M)},50);return()=>clearTimeout(b)},[J,M.length]);let S=g1(null);if(M1(()=>{v0(K,S.current),S.current=K},[K]),M1(()=>{let b=q.current;if(!b)return;let I=(f)=>{let V=f.target.closest("[data-annotation-id]");if(!V)return;f.stopPropagation();let E=V.getAttribute("data-annotation-id");if(E===K)N({anchorEl:V,annId:E});else W(E)},k=(f)=>{let V=f.target.closest("[data-annotation-id]");if(V)W(V.getAttribute("data-annotation-id"))},c=(f)=>{let V=f.target.closest("[data-annotation-id]"),E=f.relatedTarget?.closest?.("[data-annotation-id]");if(V&&!E)W(null)};return b.addEventListener("click",I),b.addEventListener("mouseover",k),b.addEventListener("mouseout",c),()=>{b.removeEventListener("click",I),b.removeEventListener("mouseover",k),b.removeEventListener("mouseout",c)}},[J,K]),M1(()=>{let b=()=>{let I=window.getSelection();if(!I||I.isCollapsed||!I.toString().trim())return;if(!q.current)return;let k=I.getRangeAt(0);if(!q.current.contains(k.startContainer))return;if(k.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let c=I.toString().trim();if(c.length<2)return;let f=k.cloneRange(),V=d1(k,q.current),E=`__pending_${Date.now()}`;try{l1(f,E)}catch{}window.getSelection()?.removeAllRanges();let g=document.querySelectorAll(`[data-annotation-id="${E}"]`),l=g[g.length-1];if(!l)return;U({anchorEl:l,tempId:E,snippet:c,ctx:V})};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(J0,{anchorEl:T.anchorEl,scrollContainer:y,snippet:T.snippet,truncateAt:80,onAdd:(b,I)=>{let k=F1();f0(T.tempId,k),X(k,T.snippet,b,T1,T.ctx,I),U(null)},onCancel:()=>{p0(T.tempId),U(null)}},void 0,!1,void 0,this),B&&(()=>{let b=Q.find((I)=>I.id===B.annId);if(!b)return null;return F(Q0,{anchorEl:B.anchorEl,scrollContainer:y,initialNote:b.note,initialImages:b.images,onUpdate:(I,k)=>{z(B.annId,I);let c=b.images||[];for(let f of k)if(!c.includes(f))_(B.annId,f);for(let f of c)if(!k.includes(f))H(B.annId,f)},onDelete:()=>{G(B.annId),W(null)},onClose:()=>N(null)},void 0,!1,void 0,this)})()]},void 0,!0,void 0,this)}function W4(){let{activeView:Y,setActiveView:$,openFiles:Z,closeFile:J,canvasFiles:q}=u1.useContext(I1),Q=u1.useContext(N3),{addAnnotationWithId:X,setActiveAnnotationId:G}=Q1();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(C0,{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 ${Y.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",Y.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=Y.type==="canvas"&&Y.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(C0,{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=Y.type==="file"&&Y.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:Y.type==="file"&&B1&&F("button",{onClick:async()=>{let _=Y.path;try{let K=await(await fetch(`/api/file?session=${Q}&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();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
|
|
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 W3=document.getElementById("root");if(W3)z4(W3).render(F(K4,{},void 0,!1,void 0,this));export{w1 as RevisionContext,I1 as ActiveViewContext};
|