agent-canvas 0.1.10 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,91 +1,91 @@
1
- import V1,{useEffect as F1,useLayoutEffect as s$,useState as e,useCallback as S0,useRef as O1,createContext as w2,useMemo as S2}from"react";import{createRoot as o$}from"react-dom/client";function j0(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var B1=j0();function W5(J){B1=J}var L1={exec:()=>null};function d(J,$=""){let Y=typeof J=="string"?J:J.source,Z={replace:(Q,X)=>{let q=typeof X=="string"?X:X.source;return q=q.replace($1.caret,"$1"),Y=Y.replace(Q,q),Z},getRegex:()=>new RegExp(Y,$)};return Z}var C2=(()=>{try{return!!new RegExp("(?<=1)(?<!1)")}catch{return!1}})(),$1={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] +\S/,listReplaceTask:/^\[[ xX]\] +/,listTaskCheckbox:/\[[ xX]\]/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:(J)=>new RegExp(`^( {0,3}${J})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:(J)=>new RegExp(`^ {0,${Math.min(3,J-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:(J)=>new RegExp(`^ {0,${Math.min(3,J-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:(J)=>new RegExp(`^ {0,${Math.min(3,J-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:(J)=>new RegExp(`^ {0,${Math.min(3,J-1)}}#`),htmlBeginRegex:(J)=>new RegExp(`^ {0,${Math.min(3,J-1)}}<(?:[a-z].*>|!--)`,"i"),blockquoteBeginRegex:(J)=>new RegExp(`^ {0,${Math.min(3,J-1)}}>`)},I2=/^(?:[ \t]*(?:\n|$))+/,V2=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,D2=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,c1=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,m2=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,C0=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,F5=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,N5=d(F5).replace(/bull/g,C0).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(),k2=d(F5).replace(/bull/g,C0).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(),I0=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,f2=/^[^\n]+/,V0=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,g2=d(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",V0).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),v2=d(/^(bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,C0).getRegex(),Y0="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",D0=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,u2=d("^ {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",D0).replace("tag",Y0).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),T5=d(I0).replace("hr",c1).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",Y0).getRegex(),E2=d(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",T5).getRegex(),m0={blockquote:E2,code:V2,def:g2,fences:D2,heading:m2,hr:c1,html:u2,lheading:N5,list:v2,newline:I2,paragraph:T5,table:L1,text:f2},z5=d("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",c1).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",Y0).getRegex(),x2={...m0,lheading:k2,table:z5,paragraph:d(I0).replace("hr",c1).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",z5).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Y0).getRegex()},h2={...m0,html:d(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",D0).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:L1,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:d(I0).replace("hr",c1).replace("heading",` *#{1,6} *[^
2
- ]`).replace("lheading",N5).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},p2=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,c2=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,y5=/^( {2,}|\\)\n(?!\s*$)/,d2=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,Q0=/[\p{P}\p{S}]/u,k0=/[\s\p{P}\p{S}]/u,O5=/[^\s\p{P}\p{S}]/u,r2=d(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,k0).getRegex(),L5=/(?!~)[\p{P}\p{S}]/u,l2=/(?!~)[\s\p{P}\p{S}]/u,a2=/(?:[^\s\p{P}\p{S}]|~)/u,M5=/(?![*_])[\p{P}\p{S}]/u,i2=/(?![*_])[\s\p{P}\p{S}]/u,s2=/(?:[^\s\p{P}\p{S}]|[*_])/u,o2=d(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",C2?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),B5=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,t2=d(B5,"u").replace(/punct/g,Q0).getRegex(),n2=d(B5,"u").replace(/punct/g,L5).getRegex(),P5="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",e2=d(P5,"gu").replace(/notPunctSpace/g,O5).replace(/punctSpace/g,k0).replace(/punct/g,Q0).getRegex(),$3=d(P5,"gu").replace(/notPunctSpace/g,a2).replace(/punctSpace/g,l2).replace(/punct/g,L5).getRegex(),J3=d("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,O5).replace(/punctSpace/g,k0).replace(/punct/g,Q0).getRegex(),Y3=d(/^~~?(?:((?!~)punct)|[^\s~])/,"u").replace(/punct/g,M5).getRegex(),Q3="^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)",Z3=d(Q3,"gu").replace(/notPunctSpace/g,s2).replace(/punctSpace/g,i2).replace(/punct/g,M5).getRegex(),q3=d(/\\(punct)/,"gu").replace(/punct/g,Q0).getRegex(),X3=d(/^<(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(),z3=d(D0).replace("(?:-->|$)","-->").getRegex(),_3=d("^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",z3).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),e1=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+[^`]*?`+(?!`)|[^\[\]\\`])*?/,K3=d(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace("label",e1).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),S5=d(/^!?\[(label)\]\[(ref)\]/).replace("label",e1).replace("ref",V0).getRegex(),b5=d(/^!?\[(ref)\](?:\[\])?/).replace("ref",V0).getRegex(),U3=d("reflink|nolink(?!\\()","g").replace("reflink",S5).replace("nolink",b5).getRegex(),_5=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,f0={_backpedal:L1,anyPunctuation:q3,autolink:X3,blockSkip:o2,br:y5,code:c2,del:L1,delLDelim:L1,delRDelim:L1,emStrongLDelim:t2,emStrongRDelimAst:e2,emStrongRDelimUnd:J3,escape:p2,link:K3,nolink:b5,punctuation:r2,reflink:S5,reflinkSearch:U3,tag:_3,text:d2,url:L1},G3={...f0,link:d(/^!?\[(label)\]\((.*?)\)/).replace("label",e1).getRegex(),reflink:d(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",e1).getRegex()},R0={...f0,emStrongRDelimAst:$3,emStrongLDelim:n2,delLDelim:Y3,delRDelim:Z3,url:d(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol",_5).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:d(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace("protocol",_5).getRegex()},H3={...R0,br:d(y5).replace("{2,}","*").getRegex(),text:d(R0.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},n1={normal:m0,gfm:x2,pedantic:h2},x1={normal:f0,gfm:R0,breaks:H3,pedantic:G3},W3={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},K5=(J)=>W3[J];function _1(J,$){if($){if($1.escapeTest.test(J))return J.replace($1.escapeReplace,K5)}else if($1.escapeTestNoEncode.test(J))return J.replace($1.escapeReplaceNoEncode,K5);return J}function U5(J){try{J=encodeURI(J).replace($1.percentDecode,"%")}catch{return null}return J}function G5(J,$){let Y=J.replace($1.findPipe,(X,q,_)=>{let z=!1,K=q;for(;--K>=0&&_[K]==="\\";)z=!z;return z?"|":" |"}),Z=Y.split($1.splitPipe),Q=0;if(Z[0].trim()||Z.shift(),Z.length>0&&!Z.at(-1)?.trim()&&Z.pop(),$)if(Z.length>$)Z.splice($);else for(;Z.length<$;)Z.push("");for(;Q<Z.length;Q++)Z[Q]=Z[Q].trim().replace($1.slashPipe,"|");return Z}function h1(J,$,Y){let Z=J.length;if(Z===0)return"";let Q=0;for(;Q<Z;){let X=J.charAt(Z-Q-1);if(X===$&&!Y)Q++;else if(X!==$&&Y)Q++;else break}return J.slice(0,Z-Q)}function F3(J,$){if(J.indexOf($[1])===-1)return-1;let Y=0;for(let Z=0;Z<J.length;Z++)if(J[Z]==="\\")Z++;else if(J[Z]===$[0])Y++;else if(J[Z]===$[1]&&(Y--,Y<0))return Z;return Y>0?-2:-1}function N3(J,$=0){let Y=$,Z="";for(let Q of J)if(Q==="\t"){let X=4-Y%4;Z+=" ".repeat(X),Y+=X}else Z+=Q,Y++;return Z}function H5(J,$,Y,Z,Q){let X=$.href,q=$.title||null,_=J[1].replace(Q.other.outputLinkReplace,"$1");Z.state.inLink=!0;let z={type:J[0].charAt(0)==="!"?"image":"link",raw:Y,href:X,title:q,text:_,tokens:Z.inlineTokens(_)};return Z.state.inLink=!1,z}function T3(J,$,Y){let Z=J.match(Y.other.indentCodeCompensation);if(Z===null)return $;let Q=Z[1];return $.split(`
3
- `).map((X)=>{let q=X.match(Y.other.beginningSpace);if(q===null)return X;let[_]=q;return _.length>=Q.length?X.slice(Q.length):X}).join(`
1
+ import V1,{useEffect as H1,useLayoutEffect as o$,useState as e,useCallback as S0,useRef as O1,createContext as A2,useMemo as S2}from"react";import{createRoot as t$}from"react-dom/client";function j0(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var B1=j0();function W5(J){B1=J}var L1={exec:()=>null};function d(J,$=""){let Y=typeof J=="string"?J:J.source,Z={replace:(Q,q)=>{let X=typeof q=="string"?q:q.source;return X=X.replace($1.caret,"$1"),Y=Y.replace(Q,X),Z},getRegex:()=>new RegExp(Y,$)};return Z}var I2=(()=>{try{return!!new RegExp("(?<=1)(?<!1)")}catch{return!1}})(),$1={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] +\S/,listReplaceTask:/^\[[ xX]\] +/,listTaskCheckbox:/\[[ xX]\]/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:(J)=>new RegExp(`^( {0,3}${J})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:(J)=>new RegExp(`^ {0,${Math.min(3,J-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:(J)=>new RegExp(`^ {0,${Math.min(3,J-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:(J)=>new RegExp(`^ {0,${Math.min(3,J-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:(J)=>new RegExp(`^ {0,${Math.min(3,J-1)}}#`),htmlBeginRegex:(J)=>new RegExp(`^ {0,${Math.min(3,J-1)}}<(?:[a-z].*>|!--)`,"i"),blockquoteBeginRegex:(J)=>new RegExp(`^ {0,${Math.min(3,J-1)}}>`)},V2=/^(?:[ \t]*(?:\n|$))+/,D2=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,m2=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,c1=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,k2=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,C0=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,F5=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,N5=d(F5).replace(/bull/g,C0).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(),f2=d(F5).replace(/bull/g,C0).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(),I0=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,g2=/^[^\n]+/,V0=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,v2=d(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",V0).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),u2=d(/^(bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,C0).getRegex(),Y0="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",D0=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,E2=d("^ {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",D0).replace("tag",Y0).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),T5=d(I0).replace("hr",c1).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",Y0).getRegex(),x2=d(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",T5).getRegex(),m0={blockquote:x2,code:D2,def:v2,fences:m2,heading:k2,hr:c1,html:E2,lheading:N5,list:u2,newline:V2,paragraph:T5,table:L1,text:g2},z5=d("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",c1).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",Y0).getRegex(),h2={...m0,lheading:f2,table:z5,paragraph:d(I0).replace("hr",c1).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",z5).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Y0).getRegex()},p2={...m0,html:d(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",D0).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:L1,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:d(I0).replace("hr",c1).replace("heading",` *#{1,6} *[^
2
+ ]`).replace("lheading",N5).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},c2=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,d2=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,y5=/^( {2,}|\\)\n(?!\s*$)/,r2=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,Q0=/[\p{P}\p{S}]/u,k0=/[\s\p{P}\p{S}]/u,O5=/[^\s\p{P}\p{S}]/u,l2=d(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,k0).getRegex(),L5=/(?!~)[\p{P}\p{S}]/u,a2=/(?!~)[\s\p{P}\p{S}]/u,i2=/(?:[^\s\p{P}\p{S}]|~)/u,M5=/(?![*_])[\p{P}\p{S}]/u,s2=/(?![*_])[\s\p{P}\p{S}]/u,o2=/(?:[^\s\p{P}\p{S}]|[*_])/u,t2=d(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",I2?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),B5=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,n2=d(B5,"u").replace(/punct/g,Q0).getRegex(),e2=d(B5,"u").replace(/punct/g,L5).getRegex(),P5="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",$3=d(P5,"gu").replace(/notPunctSpace/g,O5).replace(/punctSpace/g,k0).replace(/punct/g,Q0).getRegex(),J3=d(P5,"gu").replace(/notPunctSpace/g,i2).replace(/punctSpace/g,a2).replace(/punct/g,L5).getRegex(),Y3=d("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,O5).replace(/punctSpace/g,k0).replace(/punct/g,Q0).getRegex(),Q3=d(/^~~?(?:((?!~)punct)|[^\s~])/,"u").replace(/punct/g,M5).getRegex(),Z3="^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)",X3=d(Z3,"gu").replace(/notPunctSpace/g,o2).replace(/punctSpace/g,s2).replace(/punct/g,M5).getRegex(),q3=d(/\\(punct)/,"gu").replace(/punct/g,Q0).getRegex(),z3=d(/^<(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(),_3=d(D0).replace("(?:-->|$)","-->").getRegex(),K3=d("^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",_3).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),e1=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+[^`]*?`+(?!`)|[^\[\]\\`])*?/,U3=d(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace("label",e1).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),S5=d(/^!?\[(label)\]\[(ref)\]/).replace("label",e1).replace("ref",V0).getRegex(),b5=d(/^!?\[(ref)\](?:\[\])?/).replace("ref",V0).getRegex(),G3=d("reflink|nolink(?!\\()","g").replace("reflink",S5).replace("nolink",b5).getRegex(),_5=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,f0={_backpedal:L1,anyPunctuation:q3,autolink:z3,blockSkip:t2,br:y5,code:d2,del:L1,delLDelim:L1,delRDelim:L1,emStrongLDelim:n2,emStrongRDelimAst:$3,emStrongRDelimUnd:Y3,escape:c2,link:U3,nolink:b5,punctuation:l2,reflink:S5,reflinkSearch:G3,tag:K3,text:r2,url:L1},H3={...f0,link:d(/^!?\[(label)\]\((.*?)\)/).replace("label",e1).getRegex(),reflink:d(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",e1).getRegex()},R0={...f0,emStrongRDelimAst:J3,emStrongLDelim:e2,delLDelim:Q3,delRDelim:X3,url:d(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol",_5).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:d(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace("protocol",_5).getRegex()},W3={...R0,br:d(y5).replace("{2,}","*").getRegex(),text:d(R0.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},n1={normal:m0,gfm:h2,pedantic:p2},x1={normal:f0,gfm:R0,breaks:W3,pedantic:H3},F3={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},K5=(J)=>F3[J];function _1(J,$){if($){if($1.escapeTest.test(J))return J.replace($1.escapeReplace,K5)}else if($1.escapeTestNoEncode.test(J))return J.replace($1.escapeReplaceNoEncode,K5);return J}function U5(J){try{J=encodeURI(J).replace($1.percentDecode,"%")}catch{return null}return J}function G5(J,$){let Y=J.replace($1.findPipe,(q,X,_)=>{let z=!1,K=X;for(;--K>=0&&_[K]==="\\";)z=!z;return z?"|":" |"}),Z=Y.split($1.splitPipe),Q=0;if(Z[0].trim()||Z.shift(),Z.length>0&&!Z.at(-1)?.trim()&&Z.pop(),$)if(Z.length>$)Z.splice($);else for(;Z.length<$;)Z.push("");for(;Q<Z.length;Q++)Z[Q]=Z[Q].trim().replace($1.slashPipe,"|");return Z}function h1(J,$,Y){let Z=J.length;if(Z===0)return"";let Q=0;for(;Q<Z;){let q=J.charAt(Z-Q-1);if(q===$&&!Y)Q++;else if(q!==$&&Y)Q++;else break}return J.slice(0,Z-Q)}function N3(J,$){if(J.indexOf($[1])===-1)return-1;let Y=0;for(let Z=0;Z<J.length;Z++)if(J[Z]==="\\")Z++;else if(J[Z]===$[0])Y++;else if(J[Z]===$[1]&&(Y--,Y<0))return Z;return Y>0?-2:-1}function T3(J,$=0){let Y=$,Z="";for(let Q of J)if(Q==="\t"){let q=4-Y%4;Z+=" ".repeat(q),Y+=q}else Z+=Q,Y++;return Z}function H5(J,$,Y,Z,Q){let q=$.href,X=$.title||null,_=J[1].replace(Q.other.outputLinkReplace,"$1");Z.state.inLink=!0;let z={type:J[0].charAt(0)==="!"?"image":"link",raw:Y,href:q,title:X,text:_,tokens:Z.inlineTokens(_)};return Z.state.inLink=!1,z}function y3(J,$,Y){let Z=J.match(Y.other.indentCodeCompensation);if(Z===null)return $;let Q=Z[1];return $.split(`
3
+ `).map((q)=>{let X=q.match(Y.other.beginningSpace);if(X===null)return q;let[_]=X;return _.length>=Q.length?q.slice(Q.length):q}).join(`
4
4
  `)}var $0=class{options;rules;lexer;constructor(J){this.options=J||B1}space(J){let $=this.rules.block.newline.exec(J);if($&&$[0].length>0)return{type:"space",raw:$[0]}}code(J){let $=this.rules.block.code.exec(J);if($){let Y=$[0].replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:$[0],codeBlockStyle:"indented",text:this.options.pedantic?Y:h1(Y,`
5
- `)}}}fences(J){let $=this.rules.block.fences.exec(J);if($){let Y=$[0],Z=T3(Y,$[3]||"",this.rules);return{type:"code",raw:Y,lang:$[2]?$[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):$[2],text:Z}}}heading(J){let $=this.rules.block.heading.exec(J);if($){let Y=$[2].trim();if(this.rules.other.endingHash.test(Y)){let Z=h1(Y,"#");(this.options.pedantic||!Z||this.rules.other.endingSpaceChar.test(Z))&&(Y=Z.trim())}return{type:"heading",raw:$[0],depth:$[1].length,text:Y,tokens:this.lexer.inline(Y)}}}hr(J){let $=this.rules.block.hr.exec(J);if($)return{type:"hr",raw:h1($[0],`
5
+ `)}}}fences(J){let $=this.rules.block.fences.exec(J);if($){let Y=$[0],Z=y3(Y,$[3]||"",this.rules);return{type:"code",raw:Y,lang:$[2]?$[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):$[2],text:Z}}}heading(J){let $=this.rules.block.heading.exec(J);if($){let Y=$[2].trim();if(this.rules.other.endingHash.test(Y)){let Z=h1(Y,"#");(this.options.pedantic||!Z||this.rules.other.endingSpaceChar.test(Z))&&(Y=Z.trim())}return{type:"heading",raw:$[0],depth:$[1].length,text:Y,tokens:this.lexer.inline(Y)}}}hr(J){let $=this.rules.block.hr.exec(J);if($)return{type:"hr",raw:h1($[0],`
6
6
  `)}}blockquote(J){let $=this.rules.block.blockquote.exec(J);if($){let Y=h1($[0],`
7
7
  `).split(`
8
- `),Z="",Q="",X=[];for(;Y.length>0;){let q=!1,_=[],z;for(z=0;z<Y.length;z++)if(this.rules.other.blockquoteStart.test(Y[z]))_.push(Y[z]),q=!0;else if(!q)_.push(Y[z]);else break;Y=Y.slice(z);let K=_.join(`
8
+ `),Z="",Q="",q=[];for(;Y.length>0;){let X=!1,_=[],z;for(z=0;z<Y.length;z++)if(this.rules.other.blockquoteStart.test(Y[z]))_.push(Y[z]),X=!0;else if(!X)_.push(Y[z]);else break;Y=Y.slice(z);let K=_.join(`
9
9
  `),G=K.replace(this.rules.other.blockquoteSetextReplace,`
10
10
  $1`).replace(this.rules.other.blockquoteSetextReplace2,"");Z=Z?`${Z}
11
11
  ${K}`:K,Q=Q?`${Q}
12
- ${G}`:G;let U=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(G,X,!0),this.lexer.state.top=U,Y.length===0)break;let H=X.at(-1);if(H?.type==="code")break;if(H?.type==="blockquote"){let F=H,W=F.raw+`
12
+ ${G}`:G;let U=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(G,q,!0),this.lexer.state.top=U,Y.length===0)break;let H=q.at(-1);if(H?.type==="code")break;if(H?.type==="blockquote"){let F=H,W=F.raw+`
13
13
  `+Y.join(`
14
- `),L=this.blockquote(W);X[X.length-1]=L,Z=Z.substring(0,Z.length-F.raw.length)+L.raw,Q=Q.substring(0,Q.length-F.text.length)+L.text;break}else if(H?.type==="list"){let F=H,W=F.raw+`
14
+ `),L=this.blockquote(W);q[q.length-1]=L,Z=Z.substring(0,Z.length-F.raw.length)+L.raw,Q=Q.substring(0,Q.length-F.text.length)+L.text;break}else if(H?.type==="list"){let F=H,W=F.raw+`
15
15
  `+Y.join(`
16
- `),L=this.list(W);X[X.length-1]=L,Z=Z.substring(0,Z.length-H.raw.length)+L.raw,Q=Q.substring(0,Q.length-F.raw.length)+L.raw,Y=W.substring(X.at(-1).raw.length).split(`
17
- `);continue}}return{type:"blockquote",raw:Z,tokens:X,text:Q}}}list(J){let $=this.rules.block.list.exec(J);if($){let Y=$[1].trim(),Z=Y.length>1,Q={type:"list",raw:"",ordered:Z,start:Z?+Y.slice(0,-1):"",loose:!1,items:[]};Y=Z?`\\d{1,9}\\${Y.slice(-1)}`:`\\${Y}`,this.options.pedantic&&(Y=Z?Y:"[*+-]");let X=this.rules.other.listItemRegex(Y),q=!1;for(;J;){let z=!1,K="",G="";if(!($=X.exec(J))||this.rules.block.hr.test(J))break;K=$[0],J=J.substring(K.length);let U=N3($[2].split(`
16
+ `),L=this.list(W);q[q.length-1]=L,Z=Z.substring(0,Z.length-H.raw.length)+L.raw,Q=Q.substring(0,Q.length-F.raw.length)+L.raw,Y=W.substring(q.at(-1).raw.length).split(`
17
+ `);continue}}return{type:"blockquote",raw:Z,tokens:q,text:Q}}}list(J){let $=this.rules.block.list.exec(J);if($){let Y=$[1].trim(),Z=Y.length>1,Q={type:"list",raw:"",ordered:Z,start:Z?+Y.slice(0,-1):"",loose:!1,items:[]};Y=Z?`\\d{1,9}\\${Y.slice(-1)}`:`\\${Y}`,this.options.pedantic&&(Y=Z?Y:"[*+-]");let q=this.rules.other.listItemRegex(Y),X=!1;for(;J;){let z=!1,K="",G="";if(!($=q.exec(J))||this.rules.block.hr.test(J))break;K=$[0],J=J.substring(K.length);let U=T3($[2].split(`
18
18
  `,1)[0],$[1].length),H=J.split(`
19
19
  `,1)[0],F=!U.trim(),W=0;if(this.options.pedantic?(W=2,G=U.trimStart()):F?W=$[1].length+1:(W=U.search(this.rules.other.nonSpaceChar),W=W>4?1:W,G=U.slice(W),W+=$[1].length),F&&this.rules.other.blankLine.test(H)&&(K+=H+`
20
- `,J=J.substring(H.length+1),z=!0),!z){let L=this.rules.other.nextBulletRegex(W),T=this.rules.other.hrRegex(W),B=this.rules.other.fencesBeginRegex(W),O=this.rules.other.headingBeginRegex(W),D=this.rules.other.htmlBeginRegex(W),R=this.rules.other.blockquoteBeginRegex(W);for(;J;){let P=J.split(`
21
- `,1)[0],k;if(H=P,this.options.pedantic?(H=H.replace(this.rules.other.listReplaceNesting," "),k=H):k=H.replace(this.rules.other.tabCharGlobal," "),B.test(H)||O.test(H)||D.test(H)||R.test(H)||L.test(H)||T.test(H))break;if(k.search(this.rules.other.nonSpaceChar)>=W||!H.trim())G+=`
22
- `+k.slice(W);else{if(F||U.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||B.test(U)||O.test(U)||T.test(U))break;G+=`
20
+ `,J=J.substring(H.length+1),z=!0),!z){let L=this.rules.other.nextBulletRegex(W),y=this.rules.other.hrRegex(W),B=this.rules.other.fencesBeginRegex(W),O=this.rules.other.headingBeginRegex(W),D=this.rules.other.htmlBeginRegex(W),R=this.rules.other.blockquoteBeginRegex(W);for(;J;){let P=J.split(`
21
+ `,1)[0],k;if(H=P,this.options.pedantic?(H=H.replace(this.rules.other.listReplaceNesting," "),k=H):k=H.replace(this.rules.other.tabCharGlobal," "),B.test(H)||O.test(H)||D.test(H)||R.test(H)||L.test(H)||y.test(H))break;if(k.search(this.rules.other.nonSpaceChar)>=W||!H.trim())G+=`
22
+ `+k.slice(W);else{if(F||U.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||B.test(U)||O.test(U)||y.test(U))break;G+=`
23
23
  `+H}F=!H.trim(),K+=P+`
24
- `,J=J.substring(P.length+1),U=k.slice(W)}}Q.loose||(q?Q.loose=!0:this.rules.other.doubleBlankLine.test(K)&&(q=!0)),Q.items.push({type:"list_item",raw:K,task:!!this.options.gfm&&this.rules.other.listIsTask.test(G),loose:!1,text:G,tokens:[]}),Q.raw+=K}let _=Q.items.at(-1);if(_)_.raw=_.raw.trimEnd(),_.text=_.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 G=this.lexer.inlineQueue.length-1;G>=0;G--)if(this.rules.other.listIsTask.test(this.lexer.inlineQueue[G].src)){this.lexer.inlineQueue[G].src=this.lexer.inlineQueue[G].src.replace(this.rules.other.listReplaceTask,"");break}}let K=this.rules.other.listTaskCheckbox.exec(z.raw);if(K){let G={type:"checkbox",raw:K[0]+" ",checked:K[0]!=="[ ]"};z.checked=G.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=G.raw+z.tokens[0].raw,z.tokens[0].text=G.raw+z.tokens[0].text,z.tokens[0].tokens.unshift(G)):z.tokens.unshift({type:"paragraph",raw:G.raw,text:G.raw,tokens:[G]}):z.tokens.unshift(G)}}if(!Q.loose){let K=z.tokens.filter((U)=>U.type==="space"),G=K.length>0&&K.some((U)=>this.rules.other.anyLine.test(U.raw));Q.loose=G}}if(Q.loose)for(let z of Q.items){z.loose=!0;for(let K of z.tokens)K.type==="text"&&(K.type="paragraph")}return Q}}html(J){let $=this.rules.block.html.exec(J);if($)return{type:"html",block:!0,raw:$[0],pre:$[1]==="pre"||$[1]==="script"||$[1]==="style",text:$[0]}}def(J){let $=this.rules.block.def.exec(J);if($){let Y=$[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal," "),Z=$[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:Y,raw:$[0],href:Z,title:Q}}}table(J){let $=this.rules.block.table.exec(J);if(!$||!this.rules.other.tableDelimiter.test($[2]))return;let Y=G5($[1]),Z=$[2].replace(this.rules.other.tableAlignChars,"").split("|"),Q=$[3]?.trim()?$[3].replace(this.rules.other.tableRowBlankLine,"").split(`
25
- `):[],X={type:"table",raw:$[0],header:[],align:[],rows:[]};if(Y.length===Z.length){for(let q of Z)this.rules.other.tableAlignRight.test(q)?X.align.push("right"):this.rules.other.tableAlignCenter.test(q)?X.align.push("center"):this.rules.other.tableAlignLeft.test(q)?X.align.push("left"):X.align.push(null);for(let q=0;q<Y.length;q++)X.header.push({text:Y[q],tokens:this.lexer.inline(Y[q]),header:!0,align:X.align[q]});for(let q of Q)X.rows.push(G5(q,X.header.length).map((_,z)=>({text:_,tokens:this.lexer.inline(_),header:!1,align:X.align[z]})));return X}}lheading(J){let $=this.rules.block.lheading.exec(J);if($)return{type:"heading",raw:$[0],depth:$[2].charAt(0)==="="?1:2,text:$[1],tokens:this.lexer.inline($[1])}}paragraph(J){let $=this.rules.block.paragraph.exec(J);if($){let Y=$[1].charAt($[1].length-1)===`
26
- `?$[1].slice(0,-1):$[1];return{type:"paragraph",raw:$[0],text:Y,tokens:this.lexer.inline(Y)}}}text(J){let $=this.rules.block.text.exec(J);if($)return{type:"text",raw:$[0],text:$[0],tokens:this.lexer.inline($[0])}}escape(J){let $=this.rules.inline.escape.exec(J);if($)return{type:"escape",raw:$[0],text:$[1]}}tag(J){let $=this.rules.inline.tag.exec(J);if($)return!this.lexer.state.inLink&&this.rules.other.startATag.test($[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test($[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test($[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test($[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:$[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:$[0]}}link(J){let $=this.rules.inline.link.exec(J);if($){let Y=$[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(Y)){if(!this.rules.other.endAngleBracket.test(Y))return;let X=h1(Y.slice(0,-1),"\\");if((Y.length-X.length)%2===0)return}else{let X=F3($[2],"()");if(X===-2)return;if(X>-1){let q=($[0].indexOf("!")===0?5:4)+$[1].length+X;$[2]=$[2].substring(0,X),$[0]=$[0].substring(0,q).trim(),$[3]=""}}let Z=$[2],Q="";if(this.options.pedantic){let X=this.rules.other.pedanticHrefTitle.exec(Z);X&&(Z=X[1],Q=X[3])}else Q=$[3]?$[3].slice(1,-1):"";return Z=Z.trim(),this.rules.other.startAngleBracket.test(Z)&&(this.options.pedantic&&!this.rules.other.endAngleBracket.test(Y)?Z=Z.slice(1):Z=Z.slice(1,-1)),H5($,{href:Z&&Z.replace(this.rules.inline.anyPunctuation,"$1"),title:Q&&Q.replace(this.rules.inline.anyPunctuation,"$1")},$[0],this.lexer,this.rules)}}reflink(J,$){let Y;if((Y=this.rules.inline.reflink.exec(J))||(Y=this.rules.inline.nolink.exec(J))){let Z=(Y[2]||Y[1]).replace(this.rules.other.multipleSpaceGlobal," "),Q=$[Z.toLowerCase()];if(!Q){let X=Y[0].charAt(0);return{type:"text",raw:X,text:X}}return H5(Y,Q,Y[0],this.lexer,this.rules)}}emStrong(J,$,Y=""){let Z=this.rules.inline.emStrongLDelim.exec(J);if(!Z||Z[3]&&Y.match(this.rules.other.unicodeAlphaNumeric))return;if(!(Z[1]||Z[2])||!Y||this.rules.inline.punctuation.exec(Y)){let Q=[...Z[0]].length-1,X,q,_=Q,z=0,K=Z[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(K.lastIndex=0,$=$.slice(-1*J.length+Q);(Z=K.exec($))!=null;){if(X=Z[1]||Z[2]||Z[3]||Z[4]||Z[5]||Z[6],!X)continue;if(q=[...X].length,Z[3]||Z[4]){_+=q;continue}else if((Z[5]||Z[6])&&Q%3&&!((Q+q)%3)){z+=q;continue}if(_-=q,_>0)continue;q=Math.min(q,q+_+z);let G=[...Z[0]][0].length,U=J.slice(0,Q+Z.index+G+q);if(Math.min(Q,q)%2){let F=U.slice(1,-1);return{type:"em",raw:U,text:F,tokens:this.lexer.inlineTokens(F)}}let H=U.slice(2,-2);return{type:"strong",raw:U,text:H,tokens:this.lexer.inlineTokens(H)}}}}codespan(J){let $=this.rules.inline.code.exec(J);if($){let Y=$[2].replace(this.rules.other.newLineCharGlobal," "),Z=this.rules.other.nonSpaceChar.test(Y),Q=this.rules.other.startingSpaceChar.test(Y)&&this.rules.other.endingSpaceChar.test(Y);return Z&&Q&&(Y=Y.substring(1,Y.length-1)),{type:"codespan",raw:$[0],text:Y}}}br(J){let $=this.rules.inline.br.exec(J);if($)return{type:"br",raw:$[0]}}del(J,$,Y=""){let Z=this.rules.inline.delLDelim.exec(J);if(!Z)return;if(!Z[1]||!Y||this.rules.inline.punctuation.exec(Y)){let Q=[...Z[0]].length-1,X,q,_=Q,z=this.rules.inline.delRDelim;for(z.lastIndex=0,$=$.slice(-1*J.length+Q);(Z=z.exec($))!=null;){if(X=Z[1]||Z[2]||Z[3]||Z[4]||Z[5]||Z[6],!X||(q=[...X].length,q!==Q))continue;if(Z[3]||Z[4]){_+=q;continue}if(_-=q,_>0)continue;q=Math.min(q,q+_);let K=[...Z[0]][0].length,G=J.slice(0,Q+Z.index+K+q),U=G.slice(Q,-Q);return{type:"del",raw:G,text:U,tokens:this.lexer.inlineTokens(U)}}}}autolink(J){let $=this.rules.inline.autolink.exec(J);if($){let Y,Z;return $[2]==="@"?(Y=$[1],Z="mailto:"+Y):(Y=$[1],Z=Y),{type:"link",raw:$[0],text:Y,href:Z,tokens:[{type:"text",raw:Y,text:Y}]}}}url(J){let $;if($=this.rules.inline.url.exec(J)){let Y,Z;if($[2]==="@")Y=$[0],Z="mailto:"+Y;else{let Q;do Q=$[0],$[0]=this.rules.inline._backpedal.exec($[0])?.[0]??"";while(Q!==$[0]);Y=$[0],$[1]==="www."?Z="http://"+$[0]:Z=$[0]}return{type:"link",raw:$[0],text:Y,href:Z,tokens:[{type:"text",raw:Y,text:Y}]}}}inlineText(J){let $=this.rules.inline.text.exec(J);if($){let Y=this.lexer.state.inRawBlock;return{type:"text",raw:$[0],text:$[0],escaped:Y}}}},q1=class J{tokens;options;state;inlineQueue;tokenizer;constructor($){this.tokens=[],this.tokens.links=Object.create(null),this.options=$||B1,this.options.tokenizer=this.options.tokenizer||new $0,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 Y={other:$1,block:n1.normal,inline:x1.normal};this.options.pedantic?(Y.block=n1.pedantic,Y.inline=x1.pedantic):this.options.gfm&&(Y.block=n1.gfm,this.options.breaks?Y.inline=x1.breaks:Y.inline=x1.gfm),this.tokenizer.rules=Y}static get rules(){return{block:n1,inline:x1}}static lex($,Y){return new J(Y).lex($)}static lexInline($,Y){return new J(Y).inlineTokens($)}lex($){$=$.replace($1.carriageReturn,`
27
- `),this.blockTokens($,this.tokens);for(let Y=0;Y<this.inlineQueue.length;Y++){let Z=this.inlineQueue[Y];this.inlineTokens(Z.src,Z.tokens)}return this.inlineQueue=[],this.tokens}blockTokens($,Y=[],Z=!1){for(this.options.pedantic&&($=$.replace($1.tabCharGlobal," ").replace($1.spaceLine,""));$;){let Q;if(this.options.extensions?.block?.some((q)=>(Q=q.call({lexer:this},$,Y))?($=$.substring(Q.raw.length),Y.push(Q),!0):!1))continue;if(Q=this.tokenizer.space($)){$=$.substring(Q.raw.length);let q=Y.at(-1);Q.raw.length===1&&q!==void 0?q.raw+=`
28
- `:Y.push(Q);continue}if(Q=this.tokenizer.code($)){$=$.substring(Q.raw.length);let q=Y.at(-1);q?.type==="paragraph"||q?.type==="text"?(q.raw+=(q.raw.endsWith(`
24
+ `,J=J.substring(P.length+1),U=k.slice(W)}}Q.loose||(X?Q.loose=!0:this.rules.other.doubleBlankLine.test(K)&&(X=!0)),Q.items.push({type:"list_item",raw:K,task:!!this.options.gfm&&this.rules.other.listIsTask.test(G),loose:!1,text:G,tokens:[]}),Q.raw+=K}let _=Q.items.at(-1);if(_)_.raw=_.raw.trimEnd(),_.text=_.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 G=this.lexer.inlineQueue.length-1;G>=0;G--)if(this.rules.other.listIsTask.test(this.lexer.inlineQueue[G].src)){this.lexer.inlineQueue[G].src=this.lexer.inlineQueue[G].src.replace(this.rules.other.listReplaceTask,"");break}}let K=this.rules.other.listTaskCheckbox.exec(z.raw);if(K){let G={type:"checkbox",raw:K[0]+" ",checked:K[0]!=="[ ]"};z.checked=G.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=G.raw+z.tokens[0].raw,z.tokens[0].text=G.raw+z.tokens[0].text,z.tokens[0].tokens.unshift(G)):z.tokens.unshift({type:"paragraph",raw:G.raw,text:G.raw,tokens:[G]}):z.tokens.unshift(G)}}if(!Q.loose){let K=z.tokens.filter((U)=>U.type==="space"),G=K.length>0&&K.some((U)=>this.rules.other.anyLine.test(U.raw));Q.loose=G}}if(Q.loose)for(let z of Q.items){z.loose=!0;for(let K of z.tokens)K.type==="text"&&(K.type="paragraph")}return Q}}html(J){let $=this.rules.block.html.exec(J);if($)return{type:"html",block:!0,raw:$[0],pre:$[1]==="pre"||$[1]==="script"||$[1]==="style",text:$[0]}}def(J){let $=this.rules.block.def.exec(J);if($){let Y=$[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal," "),Z=$[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:Y,raw:$[0],href:Z,title:Q}}}table(J){let $=this.rules.block.table.exec(J);if(!$||!this.rules.other.tableDelimiter.test($[2]))return;let Y=G5($[1]),Z=$[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(Y.length===Z.length){for(let X of Z)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<Y.length;X++)q.header.push({text:Y[X],tokens:this.lexer.inline(Y[X]),header:!0,align:q.align[X]});for(let X of Q)q.rows.push(G5(X,q.header.length).map((_,z)=>({text:_,tokens:this.lexer.inline(_),header:!1,align:q.align[z]})));return q}}lheading(J){let $=this.rules.block.lheading.exec(J);if($)return{type:"heading",raw:$[0],depth:$[2].charAt(0)==="="?1:2,text:$[1],tokens:this.lexer.inline($[1])}}paragraph(J){let $=this.rules.block.paragraph.exec(J);if($){let Y=$[1].charAt($[1].length-1)===`
26
+ `?$[1].slice(0,-1):$[1];return{type:"paragraph",raw:$[0],text:Y,tokens:this.lexer.inline(Y)}}}text(J){let $=this.rules.block.text.exec(J);if($)return{type:"text",raw:$[0],text:$[0],tokens:this.lexer.inline($[0])}}escape(J){let $=this.rules.inline.escape.exec(J);if($)return{type:"escape",raw:$[0],text:$[1]}}tag(J){let $=this.rules.inline.tag.exec(J);if($)return!this.lexer.state.inLink&&this.rules.other.startATag.test($[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test($[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test($[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test($[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:$[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:$[0]}}link(J){let $=this.rules.inline.link.exec(J);if($){let Y=$[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(Y)){if(!this.rules.other.endAngleBracket.test(Y))return;let q=h1(Y.slice(0,-1),"\\");if((Y.length-q.length)%2===0)return}else{let q=N3($[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 Z=$[2],Q="";if(this.options.pedantic){let q=this.rules.other.pedanticHrefTitle.exec(Z);q&&(Z=q[1],Q=q[3])}else Q=$[3]?$[3].slice(1,-1):"";return Z=Z.trim(),this.rules.other.startAngleBracket.test(Z)&&(this.options.pedantic&&!this.rules.other.endAngleBracket.test(Y)?Z=Z.slice(1):Z=Z.slice(1,-1)),H5($,{href:Z&&Z.replace(this.rules.inline.anyPunctuation,"$1"),title:Q&&Q.replace(this.rules.inline.anyPunctuation,"$1")},$[0],this.lexer,this.rules)}}reflink(J,$){let Y;if((Y=this.rules.inline.reflink.exec(J))||(Y=this.rules.inline.nolink.exec(J))){let Z=(Y[2]||Y[1]).replace(this.rules.other.multipleSpaceGlobal," "),Q=$[Z.toLowerCase()];if(!Q){let q=Y[0].charAt(0);return{type:"text",raw:q,text:q}}return H5(Y,Q,Y[0],this.lexer,this.rules)}}emStrong(J,$,Y=""){let Z=this.rules.inline.emStrongLDelim.exec(J);if(!Z||Z[3]&&Y.match(this.rules.other.unicodeAlphaNumeric))return;if(!(Z[1]||Z[2])||!Y||this.rules.inline.punctuation.exec(Y)){let Q=[...Z[0]].length-1,q,X,_=Q,z=0,K=Z[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(K.lastIndex=0,$=$.slice(-1*J.length+Q);(Z=K.exec($))!=null;){if(q=Z[1]||Z[2]||Z[3]||Z[4]||Z[5]||Z[6],!q)continue;if(X=[...q].length,Z[3]||Z[4]){_+=X;continue}else if((Z[5]||Z[6])&&Q%3&&!((Q+X)%3)){z+=X;continue}if(_-=X,_>0)continue;X=Math.min(X,X+_+z);let G=[...Z[0]][0].length,U=J.slice(0,Q+Z.index+G+X);if(Math.min(Q,X)%2){let F=U.slice(1,-1);return{type:"em",raw:U,text:F,tokens:this.lexer.inlineTokens(F)}}let H=U.slice(2,-2);return{type:"strong",raw:U,text:H,tokens:this.lexer.inlineTokens(H)}}}}codespan(J){let $=this.rules.inline.code.exec(J);if($){let Y=$[2].replace(this.rules.other.newLineCharGlobal," "),Z=this.rules.other.nonSpaceChar.test(Y),Q=this.rules.other.startingSpaceChar.test(Y)&&this.rules.other.endingSpaceChar.test(Y);return Z&&Q&&(Y=Y.substring(1,Y.length-1)),{type:"codespan",raw:$[0],text:Y}}}br(J){let $=this.rules.inline.br.exec(J);if($)return{type:"br",raw:$[0]}}del(J,$,Y=""){let Z=this.rules.inline.delLDelim.exec(J);if(!Z)return;if(!Z[1]||!Y||this.rules.inline.punctuation.exec(Y)){let Q=[...Z[0]].length-1,q,X,_=Q,z=this.rules.inline.delRDelim;for(z.lastIndex=0,$=$.slice(-1*J.length+Q);(Z=z.exec($))!=null;){if(q=Z[1]||Z[2]||Z[3]||Z[4]||Z[5]||Z[6],!q||(X=[...q].length,X!==Q))continue;if(Z[3]||Z[4]){_+=X;continue}if(_-=X,_>0)continue;X=Math.min(X,X+_);let K=[...Z[0]][0].length,G=J.slice(0,Q+Z.index+K+X),U=G.slice(Q,-Q);return{type:"del",raw:G,text:U,tokens:this.lexer.inlineTokens(U)}}}}autolink(J){let $=this.rules.inline.autolink.exec(J);if($){let Y,Z;return $[2]==="@"?(Y=$[1],Z="mailto:"+Y):(Y=$[1],Z=Y),{type:"link",raw:$[0],text:Y,href:Z,tokens:[{type:"text",raw:Y,text:Y}]}}}url(J){let $;if($=this.rules.inline.url.exec(J)){let Y,Z;if($[2]==="@")Y=$[0],Z="mailto:"+Y;else{let Q;do Q=$[0],$[0]=this.rules.inline._backpedal.exec($[0])?.[0]??"";while(Q!==$[0]);Y=$[0],$[1]==="www."?Z="http://"+$[0]:Z=$[0]}return{type:"link",raw:$[0],text:Y,href:Z,tokens:[{type:"text",raw:Y,text:Y}]}}}inlineText(J){let $=this.rules.inline.text.exec(J);if($){let Y=this.lexer.state.inRawBlock;return{type:"text",raw:$[0],text:$[0],escaped:Y}}}},X1=class J{tokens;options;state;inlineQueue;tokenizer;constructor($){this.tokens=[],this.tokens.links=Object.create(null),this.options=$||B1,this.options.tokenizer=this.options.tokenizer||new $0,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 Y={other:$1,block:n1.normal,inline:x1.normal};this.options.pedantic?(Y.block=n1.pedantic,Y.inline=x1.pedantic):this.options.gfm&&(Y.block=n1.gfm,this.options.breaks?Y.inline=x1.breaks:Y.inline=x1.gfm),this.tokenizer.rules=Y}static get rules(){return{block:n1,inline:x1}}static lex($,Y){return new J(Y).lex($)}static lexInline($,Y){return new J(Y).inlineTokens($)}lex($){$=$.replace($1.carriageReturn,`
27
+ `),this.blockTokens($,this.tokens);for(let Y=0;Y<this.inlineQueue.length;Y++){let Z=this.inlineQueue[Y];this.inlineTokens(Z.src,Z.tokens)}return this.inlineQueue=[],this.tokens}blockTokens($,Y=[],Z=!1){for(this.options.pedantic&&($=$.replace($1.tabCharGlobal," ").replace($1.spaceLine,""));$;){let Q;if(this.options.extensions?.block?.some((X)=>(Q=X.call({lexer:this},$,Y))?($=$.substring(Q.raw.length),Y.push(Q),!0):!1))continue;if(Q=this.tokenizer.space($)){$=$.substring(Q.raw.length);let X=Y.at(-1);Q.raw.length===1&&X!==void 0?X.raw+=`
28
+ `:Y.push(Q);continue}if(Q=this.tokenizer.code($)){$=$.substring(Q.raw.length);let X=Y.at(-1);X?.type==="paragraph"||X?.type==="text"?(X.raw+=(X.raw.endsWith(`
29
29
  `)?"":`
30
- `)+Q.raw,q.text+=`
31
- `+Q.text,this.inlineQueue.at(-1).src=q.text):Y.push(Q);continue}if(Q=this.tokenizer.fences($)){$=$.substring(Q.raw.length),Y.push(Q);continue}if(Q=this.tokenizer.heading($)){$=$.substring(Q.raw.length),Y.push(Q);continue}if(Q=this.tokenizer.hr($)){$=$.substring(Q.raw.length),Y.push(Q);continue}if(Q=this.tokenizer.blockquote($)){$=$.substring(Q.raw.length),Y.push(Q);continue}if(Q=this.tokenizer.list($)){$=$.substring(Q.raw.length),Y.push(Q);continue}if(Q=this.tokenizer.html($)){$=$.substring(Q.raw.length),Y.push(Q);continue}if(Q=this.tokenizer.def($)){$=$.substring(Q.raw.length);let q=Y.at(-1);q?.type==="paragraph"||q?.type==="text"?(q.raw+=(q.raw.endsWith(`
30
+ `)+Q.raw,X.text+=`
31
+ `+Q.text,this.inlineQueue.at(-1).src=X.text):Y.push(Q);continue}if(Q=this.tokenizer.fences($)){$=$.substring(Q.raw.length),Y.push(Q);continue}if(Q=this.tokenizer.heading($)){$=$.substring(Q.raw.length),Y.push(Q);continue}if(Q=this.tokenizer.hr($)){$=$.substring(Q.raw.length),Y.push(Q);continue}if(Q=this.tokenizer.blockquote($)){$=$.substring(Q.raw.length),Y.push(Q);continue}if(Q=this.tokenizer.list($)){$=$.substring(Q.raw.length),Y.push(Q);continue}if(Q=this.tokenizer.html($)){$=$.substring(Q.raw.length),Y.push(Q);continue}if(Q=this.tokenizer.def($)){$=$.substring(Q.raw.length);let X=Y.at(-1);X?.type==="paragraph"||X?.type==="text"?(X.raw+=(X.raw.endsWith(`
32
32
  `)?"":`
33
- `)+Q.raw,q.text+=`
34
- `+Q.raw,this.inlineQueue.at(-1).src=q.text):this.tokens.links[Q.tag]||(this.tokens.links[Q.tag]={href:Q.href,title:Q.title},Y.push(Q));continue}if(Q=this.tokenizer.table($)){$=$.substring(Q.raw.length),Y.push(Q);continue}if(Q=this.tokenizer.lheading($)){$=$.substring(Q.raw.length),Y.push(Q);continue}let X=$;if(this.options.extensions?.startBlock){let q=1/0,_=$.slice(1),z;this.options.extensions.startBlock.forEach((K)=>{z=K.call({lexer:this},_),typeof z=="number"&&z>=0&&(q=Math.min(q,z))}),q<1/0&&q>=0&&(X=$.substring(0,q+1))}if(this.state.top&&(Q=this.tokenizer.paragraph(X))){let q=Y.at(-1);Z&&q?.type==="paragraph"?(q.raw+=(q.raw.endsWith(`
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},Y.push(Q));continue}if(Q=this.tokenizer.table($)){$=$.substring(Q.raw.length),Y.push(Q);continue}if(Q=this.tokenizer.lheading($)){$=$.substring(Q.raw.length),Y.push(Q);continue}let q=$;if(this.options.extensions?.startBlock){let X=1/0,_=$.slice(1),z;this.options.extensions.startBlock.forEach((K)=>{z=K.call({lexer:this},_),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=Y.at(-1);Z&&X?.type==="paragraph"?(X.raw+=(X.raw.endsWith(`
35
35
  `)?"":`
36
- `)+Q.raw,q.text+=`
37
- `+Q.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=q.text):Y.push(Q),Z=X.length!==$.length,$=$.substring(Q.raw.length);continue}if(Q=this.tokenizer.text($)){$=$.substring(Q.raw.length);let q=Y.at(-1);q?.type==="text"?(q.raw+=(q.raw.endsWith(`
36
+ `)+Q.raw,X.text+=`
37
+ `+Q.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=X.text):Y.push(Q),Z=q.length!==$.length,$=$.substring(Q.raw.length);continue}if(Q=this.tokenizer.text($)){$=$.substring(Q.raw.length);let X=Y.at(-1);X?.type==="text"?(X.raw+=(X.raw.endsWith(`
38
38
  `)?"":`
39
- `)+Q.raw,q.text+=`
40
- `+Q.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=q.text):Y.push(Q);continue}if($){let q="Infinite loop on byte: "+$.charCodeAt(0);if(this.options.silent){console.error(q);break}else throw Error(q)}}return this.state.top=!0,Y}inline($,Y=[]){return this.inlineQueue.push({src:$,tokens:Y}),Y}inlineTokens($,Y=[]){let Z=$,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(Z))!=null;)z.includes(Q[0].slice(Q[0].lastIndexOf("[")+1,-1))&&(Z=Z.slice(0,Q.index)+"["+"a".repeat(Q[0].length-2)+"]"+Z.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(Q=this.tokenizer.rules.inline.anyPunctuation.exec(Z))!=null;)Z=Z.slice(0,Q.index)+"++"+Z.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);let X;for(;(Q=this.tokenizer.rules.inline.blockSkip.exec(Z))!=null;)X=Q[2]?Q[2].length:0,Z=Z.slice(0,Q.index+X)+"["+"a".repeat(Q[0].length-X-2)+"]"+Z.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);Z=this.options.hooks?.emStrongMask?.call({lexer:this},Z)??Z;let q=!1,_="";for(;$;){q||(_=""),q=!1;let z;if(this.options.extensions?.inline?.some((G)=>(z=G.call({lexer:this},$,Y))?($=$.substring(z.raw.length),Y.push(z),!0):!1))continue;if(z=this.tokenizer.escape($)){$=$.substring(z.raw.length),Y.push(z);continue}if(z=this.tokenizer.tag($)){$=$.substring(z.raw.length),Y.push(z);continue}if(z=this.tokenizer.link($)){$=$.substring(z.raw.length),Y.push(z);continue}if(z=this.tokenizer.reflink($,this.tokens.links)){$=$.substring(z.raw.length);let G=Y.at(-1);z.type==="text"&&G?.type==="text"?(G.raw+=z.raw,G.text+=z.text):Y.push(z);continue}if(z=this.tokenizer.emStrong($,Z,_)){$=$.substring(z.raw.length),Y.push(z);continue}if(z=this.tokenizer.codespan($)){$=$.substring(z.raw.length),Y.push(z);continue}if(z=this.tokenizer.br($)){$=$.substring(z.raw.length),Y.push(z);continue}if(z=this.tokenizer.del($,Z,_)){$=$.substring(z.raw.length),Y.push(z);continue}if(z=this.tokenizer.autolink($)){$=$.substring(z.raw.length),Y.push(z);continue}if(!this.state.inLink&&(z=this.tokenizer.url($))){$=$.substring(z.raw.length),Y.push(z);continue}let K=$;if(this.options.extensions?.startInline){let G=1/0,U=$.slice(1),H;this.options.extensions.startInline.forEach((F)=>{H=F.call({lexer:this},U),typeof H=="number"&&H>=0&&(G=Math.min(G,H))}),G<1/0&&G>=0&&(K=$.substring(0,G+1))}if(z=this.tokenizer.inlineText(K)){$=$.substring(z.raw.length),z.raw.slice(-1)!=="_"&&(_=z.raw.slice(-1)),q=!0;let G=Y.at(-1);G?.type==="text"?(G.raw+=z.raw,G.text+=z.text):Y.push(z);continue}if($){let G="Infinite loop on byte: "+$.charCodeAt(0);if(this.options.silent){console.error(G);break}else throw Error(G)}}return Y}},J0=class{options;parser;constructor(J){this.options=J||B1}space(J){return""}code({text:J,lang:$,escaped:Y}){let Z=($||"").match($1.notSpaceStart)?.[0],Q=J.replace($1.endingNewline,"")+`
39
+ `)+Q.raw,X.text+=`
40
+ `+Q.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=X.text):Y.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,Y}inline($,Y=[]){return this.inlineQueue.push({src:$,tokens:Y}),Y}inlineTokens($,Y=[]){let Z=$,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(Z))!=null;)z.includes(Q[0].slice(Q[0].lastIndexOf("[")+1,-1))&&(Z=Z.slice(0,Q.index)+"["+"a".repeat(Q[0].length-2)+"]"+Z.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(Q=this.tokenizer.rules.inline.anyPunctuation.exec(Z))!=null;)Z=Z.slice(0,Q.index)+"++"+Z.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);let q;for(;(Q=this.tokenizer.rules.inline.blockSkip.exec(Z))!=null;)q=Q[2]?Q[2].length:0,Z=Z.slice(0,Q.index+q)+"["+"a".repeat(Q[0].length-q-2)+"]"+Z.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);Z=this.options.hooks?.emStrongMask?.call({lexer:this},Z)??Z;let X=!1,_="";for(;$;){X||(_=""),X=!1;let z;if(this.options.extensions?.inline?.some((G)=>(z=G.call({lexer:this},$,Y))?($=$.substring(z.raw.length),Y.push(z),!0):!1))continue;if(z=this.tokenizer.escape($)){$=$.substring(z.raw.length),Y.push(z);continue}if(z=this.tokenizer.tag($)){$=$.substring(z.raw.length),Y.push(z);continue}if(z=this.tokenizer.link($)){$=$.substring(z.raw.length),Y.push(z);continue}if(z=this.tokenizer.reflink($,this.tokens.links)){$=$.substring(z.raw.length);let G=Y.at(-1);z.type==="text"&&G?.type==="text"?(G.raw+=z.raw,G.text+=z.text):Y.push(z);continue}if(z=this.tokenizer.emStrong($,Z,_)){$=$.substring(z.raw.length),Y.push(z);continue}if(z=this.tokenizer.codespan($)){$=$.substring(z.raw.length),Y.push(z);continue}if(z=this.tokenizer.br($)){$=$.substring(z.raw.length),Y.push(z);continue}if(z=this.tokenizer.del($,Z,_)){$=$.substring(z.raw.length),Y.push(z);continue}if(z=this.tokenizer.autolink($)){$=$.substring(z.raw.length),Y.push(z);continue}if(!this.state.inLink&&(z=this.tokenizer.url($))){$=$.substring(z.raw.length),Y.push(z);continue}let K=$;if(this.options.extensions?.startInline){let G=1/0,U=$.slice(1),H;this.options.extensions.startInline.forEach((F)=>{H=F.call({lexer:this},U),typeof H=="number"&&H>=0&&(G=Math.min(G,H))}),G<1/0&&G>=0&&(K=$.substring(0,G+1))}if(z=this.tokenizer.inlineText(K)){$=$.substring(z.raw.length),z.raw.slice(-1)!=="_"&&(_=z.raw.slice(-1)),X=!0;let G=Y.at(-1);G?.type==="text"?(G.raw+=z.raw,G.text+=z.text):Y.push(z);continue}if($){let G="Infinite loop on byte: "+$.charCodeAt(0);if(this.options.silent){console.error(G);break}else throw Error(G)}}return Y}},J0=class{options;parser;constructor(J){this.options=J||B1}space(J){return""}code({text:J,lang:$,escaped:Y}){let Z=($||"").match($1.notSpaceStart)?.[0],Q=J.replace($1.endingNewline,"")+`
41
41
  `;return Z?'<pre><code class="language-'+_1(Z)+'">'+(Y?Q:_1(Q,!0))+`</code></pre>
42
42
  `:"<pre><code>"+(Y?Q:_1(Q,!0))+`</code></pre>
43
43
  `}blockquote({tokens:J}){return`<blockquote>
44
44
  ${this.parser.parse(J)}</blockquote>
45
45
  `}html({text:J}){return J}def(J){return""}heading({tokens:J,depth:$}){return`<h${$}>${this.parser.parseInline(J)}</h${$}>
46
46
  `}hr(J){return`<hr>
47
- `}list(J){let{ordered:$,start:Y}=J,Z="";for(let q=0;q<J.items.length;q++){let _=J.items[q];Z+=this.listitem(_)}let Q=$?"ol":"ul",X=$&&Y!==1?' start="'+Y+'"':"";return"<"+Q+X+`>
47
+ `}list(J){let{ordered:$,start:Y}=J,Z="";for(let X=0;X<J.items.length;X++){let _=J.items[X];Z+=this.listitem(_)}let Q=$?"ol":"ul",q=$&&Y!==1?' start="'+Y+'"':"";return"<"+Q+q+`>
48
48
  `+Z+"</"+Q+`>
49
49
  `}listitem(J){return`<li>${this.parser.parse(J.tokens)}</li>
50
50
  `}checkbox({checked:J}){return"<input "+(J?'checked="" ':"")+'disabled="" type="checkbox"> '}paragraph({tokens:J}){return`<p>${this.parser.parseInline(J)}</p>
51
- `}table(J){let $="",Y="";for(let Q=0;Q<J.header.length;Q++)Y+=this.tablecell(J.header[Q]);$+=this.tablerow({text:Y});let Z="";for(let Q=0;Q<J.rows.length;Q++){let X=J.rows[Q];Y="";for(let q=0;q<X.length;q++)Y+=this.tablecell(X[q]);Z+=this.tablerow({text:Y})}return Z&&(Z=`<tbody>${Z}</tbody>`),`<table>
51
+ `}table(J){let $="",Y="";for(let Q=0;Q<J.header.length;Q++)Y+=this.tablecell(J.header[Q]);$+=this.tablerow({text:Y});let Z="";for(let Q=0;Q<J.rows.length;Q++){let q=J.rows[Q];Y="";for(let X=0;X<q.length;X++)Y+=this.tablecell(q[X]);Z+=this.tablerow({text:Y})}return Z&&(Z=`<tbody>${Z}</tbody>`),`<table>
52
52
  <thead>
53
53
  `+$+`</thead>
54
54
  `+Z+`</table>
55
55
  `}tablerow({text:J}){return`<tr>
56
56
  ${J}</tr>
57
57
  `}tablecell(J){let $=this.parser.parseInline(J.tokens),Y=J.header?"th":"td";return(J.align?`<${Y} align="${J.align}">`:`<${Y}>`)+$+`</${Y}>
58
- `}strong({tokens:J}){return`<strong>${this.parser.parseInline(J)}</strong>`}em({tokens:J}){return`<em>${this.parser.parseInline(J)}</em>`}codespan({text:J}){return`<code>${_1(J,!0)}</code>`}br(J){return"<br>"}del({tokens:J}){return`<del>${this.parser.parseInline(J)}</del>`}link({href:J,title:$,tokens:Y}){let Z=this.parser.parseInline(Y),Q=U5(J);if(Q===null)return Z;J=Q;let X='<a href="'+J+'"';return $&&(X+=' title="'+_1($)+'"'),X+=">"+Z+"</a>",X}image({href:J,title:$,text:Y,tokens:Z}){Z&&(Y=this.parser.parseInline(Z,this.parser.textRenderer));let Q=U5(J);if(Q===null)return _1(Y);J=Q;let X=`<img src="${J}" alt="${_1(Y)}"`;return $&&(X+=` title="${_1($)}"`),X+=">",X}text(J){return"tokens"in J&&J.tokens?this.parser.parseInline(J.tokens):("escaped"in J)&&J.escaped?J.text:_1(J.text)}},g0=class{strong({text:J}){return J}em({text:J}){return J}codespan({text:J}){return J}del({text:J}){return J}html({text:J}){return J}text({text:J}){return J}link({text:J}){return""+J}image({text:J}){return""+J}br(){return""}checkbox({raw:J}){return J}},X1=class J{options;renderer;textRenderer;constructor($){this.options=$||B1,this.options.renderer=this.options.renderer||new J0,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new g0}static parse($,Y){return new J(Y).parse($)}static parseInline($,Y){return new J(Y).parseInline($)}parse($){let Y="";for(let Z=0;Z<$.length;Z++){let Q=$[Z];if(this.options.extensions?.renderers?.[Q.type]){let q=Q,_=this.options.extensions.renderers[q.type].call({parser:this},q);if(_!==!1||!["space","hr","heading","code","table","blockquote","list","html","def","paragraph","text"].includes(q.type)){Y+=_||"";continue}}let X=Q;switch(X.type){case"space":{Y+=this.renderer.space(X);break}case"hr":{Y+=this.renderer.hr(X);break}case"heading":{Y+=this.renderer.heading(X);break}case"code":{Y+=this.renderer.code(X);break}case"table":{Y+=this.renderer.table(X);break}case"blockquote":{Y+=this.renderer.blockquote(X);break}case"list":{Y+=this.renderer.list(X);break}case"checkbox":{Y+=this.renderer.checkbox(X);break}case"html":{Y+=this.renderer.html(X);break}case"def":{Y+=this.renderer.def(X);break}case"paragraph":{Y+=this.renderer.paragraph(X);break}case"text":{Y+=this.renderer.text(X);break}default:{let q='Token with "'+X.type+'" type was not found.';if(this.options.silent)return console.error(q),"";throw Error(q)}}}return Y}parseInline($,Y=this.renderer){let Z="";for(let Q=0;Q<$.length;Q++){let X=$[Q];if(this.options.extensions?.renderers?.[X.type]){let _=this.options.extensions.renderers[X.type].call({parser:this},X);if(_!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(X.type)){Z+=_||"";continue}}let q=X;switch(q.type){case"escape":{Z+=Y.text(q);break}case"html":{Z+=Y.html(q);break}case"link":{Z+=Y.link(q);break}case"image":{Z+=Y.image(q);break}case"checkbox":{Z+=Y.checkbox(q);break}case"strong":{Z+=Y.strong(q);break}case"em":{Z+=Y.em(q);break}case"codespan":{Z+=Y.codespan(q);break}case"br":{Z+=Y.br(q);break}case"del":{Z+=Y.del(q);break}case"text":{Z+=Y.text(q);break}default:{let _='Token with "'+q.type+'" type was not found.';if(this.options.silent)return console.error(_),"";throw Error(_)}}}return Z}},p1=class{options;block;constructor(J){this.options=J||B1}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens","emStrongMask"]);static passThroughHooksRespectAsync=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(J){return J}postprocess(J){return J}processAllTokens(J){return J}emStrongMask(J){return J}provideLexer(){return this.block?q1.lex:q1.lexInline}provideParser(){return this.block?X1.parse:X1.parseInline}},y3=class{defaults=j0();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=X1;Renderer=J0;TextRenderer=g0;Lexer=q1;Tokenizer=$0;Hooks=p1;constructor(...J){this.use(...J)}walkTokens(J,$){let Y=[];for(let Z of J)switch(Y=Y.concat($.call(this,Z)),Z.type){case"table":{let Q=Z;for(let X of Q.header)Y=Y.concat(this.walkTokens(X.tokens,$));for(let X of Q.rows)for(let q of X)Y=Y.concat(this.walkTokens(q.tokens,$));break}case"list":{let Q=Z;Y=Y.concat(this.walkTokens(Q.items,$));break}default:{let Q=Z;this.defaults.extensions?.childTokens?.[Q.type]?this.defaults.extensions.childTokens[Q.type].forEach((X)=>{let q=Q[X].flat(1/0);Y=Y.concat(this.walkTokens(q,$))}):Q.tokens&&(Y=Y.concat(this.walkTokens(Q.tokens,$)))}}return Y}use(...J){let $=this.defaults.extensions||{renderers:{},childTokens:{}};return J.forEach((Y)=>{let Z={...Y};if(Z.async=this.defaults.async||Z.async||!1,Y.extensions&&(Y.extensions.forEach((Q)=>{if(!Q.name)throw Error("extension name required");if("renderer"in Q){let X=$.renderers[Q.name];X?$.renderers[Q.name]=function(...q){let _=Q.renderer.apply(this,q);return _===!1&&(_=X.apply(this,q)),_}:$.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 X=$[Q.level];X?X.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)}),Z.extensions=$),Y.renderer){let Q=this.defaults.renderer||new J0(this.defaults);for(let X in Y.renderer){if(!(X in Q))throw Error(`renderer '${X}' does not exist`);if(["options","parser"].includes(X))continue;let q=X,_=Y.renderer[q],z=Q[q];Q[q]=(...K)=>{let G=_.apply(Q,K);return G===!1&&(G=z.apply(Q,K)),G||""}}Z.renderer=Q}if(Y.tokenizer){let Q=this.defaults.tokenizer||new $0(this.defaults);for(let X in Y.tokenizer){if(!(X in Q))throw Error(`tokenizer '${X}' does not exist`);if(["options","rules","lexer"].includes(X))continue;let q=X,_=Y.tokenizer[q],z=Q[q];Q[q]=(...K)=>{let G=_.apply(Q,K);return G===!1&&(G=z.apply(Q,K)),G}}Z.tokenizer=Q}if(Y.hooks){let Q=this.defaults.hooks||new p1;for(let X in Y.hooks){if(!(X in Q))throw Error(`hook '${X}' does not exist`);if(["options","block"].includes(X))continue;let q=X,_=Y.hooks[q],z=Q[q];p1.passThroughHooks.has(X)?Q[q]=(K)=>{if(this.defaults.async&&p1.passThroughHooksRespectAsync.has(X))return(async()=>{let U=await _.call(Q,K);return z.call(Q,U)})();let G=_.call(Q,K);return z.call(Q,G)}:Q[q]=(...K)=>{if(this.defaults.async)return(async()=>{let U=await _.apply(Q,K);return U===!1&&(U=await z.apply(Q,K)),U})();let G=_.apply(Q,K);return G===!1&&(G=z.apply(Q,K)),G}}Z.hooks=Q}if(Y.walkTokens){let Q=this.defaults.walkTokens,X=Y.walkTokens;Z.walkTokens=function(q){let _=[];return _.push(X.call(this,q)),Q&&(_=_.concat(Q.call(this,q))),_}}this.defaults={...this.defaults,...Z}}),this}setOptions(J){return this.defaults={...this.defaults,...J},this}lexer(J,$){return q1.lex(J,$??this.defaults)}parser(J,$){return X1.parse(J,$??this.defaults)}parseMarkdown(J){return($,Y)=>{let Z={...Y},Q={...this.defaults,...Z},X=this.onError(!!Q.silent,!!Q.async);if(this.defaults.async===!0&&Z.async===!1)return X(Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(typeof $>"u"||$===null)return X(Error("marked(): input parameter is undefined or null"));if(typeof $!="string")return X(Error("marked(): input parameter is of type "+Object.prototype.toString.call($)+", string expected"));if(Q.hooks&&(Q.hooks.options=Q,Q.hooks.block=J),Q.async)return(async()=>{let q=Q.hooks?await Q.hooks.preprocess($):$,_=await(Q.hooks?await Q.hooks.provideLexer():J?q1.lex:q1.lexInline)(q,Q),z=Q.hooks?await Q.hooks.processAllTokens(_):_;Q.walkTokens&&await Promise.all(this.walkTokens(z,Q.walkTokens));let K=await(Q.hooks?await Q.hooks.provideParser():J?X1.parse:X1.parseInline)(z,Q);return Q.hooks?await Q.hooks.postprocess(K):K})().catch(X);try{Q.hooks&&($=Q.hooks.preprocess($));let q=(Q.hooks?Q.hooks.provideLexer():J?q1.lex:q1.lexInline)($,Q);Q.hooks&&(q=Q.hooks.processAllTokens(q)),Q.walkTokens&&this.walkTokens(q,Q.walkTokens);let _=(Q.hooks?Q.hooks.provideParser():J?X1.parse:X1.parseInline)(q,Q);return Q.hooks&&(_=Q.hooks.postprocess(_)),_}catch(q){return X(q)}}}onError(J,$){return(Y)=>{if(Y.message+=`
59
- Please report this to https://github.com/markedjs/marked.`,J){let Z="<p>An error occurred:</p><pre>"+_1(Y.message+"",!0)+"</pre>";return $?Promise.resolve(Z):Z}if($)return Promise.reject(Y);throw Y}}},M1=new y3;function r(J,$){return M1.parse(J,$)}r.options=r.setOptions=function(J){return M1.setOptions(J),r.defaults=M1.defaults,W5(r.defaults),r};r.getDefaults=j0;r.defaults=B1;r.use=function(...J){return M1.use(...J),r.defaults=M1.defaults,W5(r.defaults),r};r.walkTokens=function(J,$){return M1.walkTokens(J,$)};r.parseInline=M1.parseInline;r.Parser=X1;r.parser=X1.parse;r.Renderer=J0;r.TextRenderer=g0;r.Lexer=q1;r.lexer=q1.lex;r.Tokenizer=$0;r.Hooks=p1;r.parse=r;var{options:Q4,setOptions:Z4,use:q4,walkTokens:X4,parseInline:z4}=r;var _4=X1.parse,K4=q1.lex;import{SessionContext as A2,ActiveViewCtx as t$}from"#canvas/runtime";import{useState as r1,useCallback as K1,useEffect as w5,useRef as A5}from"react";import{AnnotationCtx as O3}from"#canvas/runtime";var Q1="__agent-response__";function z1(){return`ann-${Date.now()}-${Math.random().toString(36).slice(2,6)}`}function d1(J,$){J.style.height="auto",J.style.height=($?Math.max($,J.scrollHeight):J.scrollHeight)+"px"}import{useAnnotations as o}from"#canvas/runtime";import{jsxDEV as P3}from"react/jsx-dev-runtime";function v0(J,$){return`canvas:${J}:rev:${$}`}function l1(J,$){try{let Y=localStorage.getItem(v0(J,$));if(!Y)return null;return JSON.parse(Y)}catch{return null}}function L3(J,$,Y){try{localStorage.setItem(v0(J,$),JSON.stringify(Y))}catch{}}function M3(J,$){try{localStorage.removeItem(v0(J,$))}catch{}}function R5({sessionId:J,revision:$,isReadOnly:Y,children:Z}){let Q=A5(`${J}:${$}`),[X,q]=r1(()=>{return l1(J,$)?.annotations??[]}),[_,z]=r1(()=>{return l1(J,$)?.generalNote??""}),[K,G]=r1(null),[U,H]=r1(()=>{let j=l1(J,$);return j?.responses?new Map(j.responses):new Map}),[F,W]=r1(()=>{let j=l1(J,$);return j?.feedbackEntries?new Map(j.feedbackEntries):new Map});w5(()=>{let j=`${J}:${$}`;if(j===Q.current)return;Q.current=j;let V=l1(J,$);q(V?.annotations??[]),z(V?.generalNote??""),H(V?.responses?new Map(V.responses):new Map),W(V?.feedbackEntries?new Map(V.feedbackEntries):new Map),G(null)},[J,$]);let L=A5(null);w5(()=>{if(Y)return;if(L.current)clearTimeout(L.current);return L.current=setTimeout(()=>{L3(J,$,{annotations:X,generalNote:_,responses:Array.from(U.entries()),feedbackEntries:Array.from(F.entries())})},300),()=>{if(L.current)clearTimeout(L.current)}},[X,_,U,F,J,$,Y]);let T=K1((j,V,C,I,S,w)=>{q((N)=>[...N,{id:j,snippet:V,note:C,createdAt:new Date().toISOString(),filePath:I,context:S,...w?.length?{images:w}:{}}])},[]),B=K1((j,V,C)=>{T(z1(),j,V,C)},[T]),O=K1((j,V)=>{q((C)=>C.map((I)=>I.id===j?{...I,note:V}:I))},[]),D=K1((j)=>{B3(j),q((V)=>V.filter((C)=>C.id!==j)),G((V)=>V===j?null:V)},[]),R=K1((j,V)=>{q((C)=>C.map((I)=>I.id===j?{...I,images:[...I.images||[],V]}:I))},[]),P=K1((j,V)=>{q((C)=>C.map((I)=>I.id===j?{...I,images:(I.images||[]).filter((S)=>S!==V)}:I))},[]),k=K1((j,V)=>{H((C)=>{let I=new Map(C);return I.set(j,V),I})},[]),v=K1((j,V)=>{W((C)=>{let I=C.get(j);if(I&&I.markdown===V.markdown&&I.label===V.label&&I.required===V.required)return C;let S=new Map(C);return S.set(j,V),S})},[]),g=K1((j)=>{W((V)=>{if(!V.has(j))return V;let C=new Map(V);return C.delete(j),C})},[]),h=K1(()=>{for(let j of document.querySelectorAll("[data-annotation-id]"))j5(j);q([]),z(""),G(null),H(new Map),W(new Map),M3(J,$)},[J,$]);return P3(O3.Provider,{value:{annotations:X,addAnnotation:B,addAnnotationWithId:T,updateAnnotation:O,removeAnnotation:D,addAnnotationImage:R,removeAnnotationImage:P,generalNote:_,setGeneralNote:z,clearAll:h,activeAnnotationId:K,setActiveAnnotationId:G,responses:U,setResponse:k,feedbackEntries:F,setFeedbackEntry:v,removeFeedbackEntry:g},children:Z},void 0,!1,void 0,this)}function B3(J){let $=document.querySelectorAll(`[data-annotation-id="${J}"]`);for(let Y of $)j5(Y)}function j5(J){let $=J.parentNode;if(!$)return;let Y=document.createTextNode(J.textContent||"");$.replaceChild(Y,J),$.normalize()}import c0,{useEffect as R1,useState as U1,useRef as m3,useContext as k3,useMemo as H0}from"react";import{createPortal as f3}from"react-dom";import{SessionContext as g3}from"#canvas/runtime";function P1(J,$){let Y=C5(J,"before",60),Z=C5(J,"after",60),Q=b3(J.startContainer,$);return{before:Y,after:Z,hierarchy:Q}}function C5(J,$,Y){let Z=S3($==="before"?J.startContainer:J.endContainer);if(!Z)return"";let Q="";if($==="before"){let X=document.createTreeWalker(Z,NodeFilter.SHOW_TEXT),q;while(q=X.nextNode()){if(q===J.startContainer){Q+=(q.textContent||"").slice(0,J.startOffset);break}if(q.parentElement?.hasAttribute("data-annotation-id"))continue;Q+=q.textContent||""}if(Q.length>Y){Q=Q.slice(-Y);let _=Q.indexOf(" ");if(_>0)Q=Q.slice(_+1)}}else{let X=document.createTreeWalker(Z,NodeFilter.SHOW_TEXT),q=!1,_;while(_=X.nextNode()){if(_===J.endContainer){Q+=(_.textContent||"").slice(J.endOffset),q=!0;continue}if(q){if(_.parentElement?.hasAttribute("data-annotation-id"))continue;Q+=_.textContent||""}}if(Q.length>Y){Q=Q.slice(0,Y);let z=Q.lastIndexOf(" ");if(z>0)Q=Q.slice(0,z)}}return Q.trim()}function S3(J){let $=new Set(["DIV","P","LI","PRE","BLOCKQUOTE","SECTION","ARTICLE"]),Y=J.parentElement;while(Y){if($.has(Y.tagName))return Y;Y=Y.parentElement}return null}function b3(J,$){let Y=[],Z=J instanceof Element?J:J.parentElement;while(Z&&Z!==$){let Q=Z.getAttribute?.("data-task-id");if(Q){let X=Z.querySelector(".font-semibold");if(X)Y.unshift(X.textContent?.trim()||Q)}if(Z.tagName==="DIV"&&Z.querySelector(":scope > button .font-heading, :scope > div .font-heading")){let X=Z.querySelector(".font-heading");if(X)Y.unshift(X.textContent?.trim()||"")}Z=Z.parentElement}return Y}function u0(J){let $=J.snippet.trim(),Y=J.context,Z=$.length<30;if(Y&&Z&&(Y.before||Y.after)){let Q=[];if(Y.before)Q.push(`...${Y.before} `);if(Q.push(`**${$}**`),Y.after)Q.push(` ${Y.after}...`);return Q.join("")}return $}import{useEffect as g5,useRef as X0,useState as a1,useCallback as q0,useMemo as k5,useContext as A3}from"react";import{createPortal as R3}from"react-dom";function I5(J,$){let Q=$||document.body,X=J.getBoundingClientRect(),q=Q.getBoundingClientRect(),_=Q===document.body?window.scrollY:Q.scrollTop,z=X.bottom-q.top+_+8,K=Math.max(0,Math.min(X.left-q.left,q.width-280-12));return Q.style.position="relative",{style:{position:"absolute",top:`${z}px`,left:`${K}px`},parent:Q}}import{useState as E0,useRef as x0,useCallback as H1,useEffect as V5}from"react";import{jsxDEV as t}from"react/jsx-dev-runtime";function D5(J){return`/api/uploads/${J.split("/").pop()}`}async function w3(J,$){let Y=new FormData;Y.append("image",$);try{return(await(await fetch(`/api/session/${J}/upload`,{method:"POST",body:Y})).json()).path||null}catch{return null}}function Z0({note:J,onNoteChange:$,images:Y,onAddImage:Z,onRemoveImage:Q,sessionId:X,placeholder:q="Add your note...",autoFocus:_=!1,autoResize:z=!1,readOnly:K=!1,onKeyDown:G,onTextareaClick:U,textareaRef:H,textareaClassName:F,textareaStyle:W,minHeight:L,attachButton:T="always",openFilePickerRef:B}){let[O,D]=E0(!1),[R,P]=E0(!1),[k,v]=E0(!1),g=x0(0),h=x0(null),j=x0(null),V=H1(()=>j.current?.click(),[]);V5(()=>{if(B)B.current=V},[B,V]);let C=H1((M)=>{if(h.current=M,H)H.current=M;if(M&&z)d1(M,L)},[H,z,L]);V5(()=>{if(_&&h.current){let M=h.current;if(M.focus(),M.value)M.setSelectionRange(M.value.length,M.value.length)}},[_]);let I=H1(async(M)=>{if(!M.type.startsWith("image/"))return;P(!0);try{let m=await w3(X,M);if(m)Z(m)}finally{P(!1)}},[X,Z]),S=H1((M)=>{let m=M.clipboardData.items;for(let l of m)if(l.type.startsWith("image/")){M.preventDefault();let Z1=l.getAsFile();if(Z1)I(Z1);return}},[I]),w=H1((M)=>{if(M.preventDefault(),g.current++,g.current===1)D(!0)},[]),N=H1((M)=>{M.preventDefault()},[]),b=H1((M)=>{if(M.preventDefault(),g.current--,g.current===0)D(!1)},[]),f=H1((M)=>{M.preventDefault(),g.current=0,D(!1);for(let m of M.dataTransfer.files)if(m.type.startsWith("image/"))I(m)},[I]),u=H1((M)=>{if($(M.target.value),z)M.target.style.height="auto",M.target.style.height=(L?Math.max(L,M.target.scrollHeight):M.target.scrollHeight)+"px"},[$,z,L]),p="w-full bg-transparent text-[13px] font-body text-text-primary resize-none focus:outline-none leading-relaxed p-0 border-none",c={width:"100%",background:"transparent",border:"none",color:"var(--color-text-primary)",fontFamily:"'Inter', sans-serif",fontSize:"13px",lineHeight:"1.5",outline:"none",...z?{resize:"none",overflow:"hidden"}:{resize:"vertical"}},i=!K&&(T==="always"||T==="on-focus"&&k);return t("div",{style:{position:"relative"},onDragEnter:K?void 0:w,onDragOver:K?void 0:N,onDragLeave:K?void 0:b,onDrop:K?void 0:f,children:[t("textarea",{ref:C,value:J,onChange:K?void 0:u,onPaste:K?void 0:S,onKeyDown:G,onClick:U,onFocus:()=>v(!0),onBlur:()=>{setTimeout(()=>v(!1),150)},readOnly:K,placeholder:q,className:F??p,style:W??c,rows:z?1:void 0},void 0,!1,void 0,this),!K&&t("input",{ref:j,type:"file",accept:"image/*",multiple:!0,style:{display:"none"},onChange:(M)=>{let m=M.target.files;if(m)for(let l of m)I(l);M.target.value=""}},void 0,!1,void 0,this),(Y.length>0||i)&&t("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"6px",alignItems:"center"},children:[Y.map((M)=>t("div",{style:{position:"relative",width:"56px",height:"56px",borderRadius:"6px",overflow:"hidden",border:"1px solid var(--color-border-subtle)",flexShrink:0},children:[t("img",{src:D5(M),alt:"",style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}},void 0,!1,void 0,this),!K&&t("button",{onClick:(m)=>{m.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)),i&&t(h0,{onClick:V},void 0,!1,void 0,this)]},void 0,!0,void 0,this),R&&t("div",{style:{fontSize:"11px",color:"var(--color-text-tertiary)",fontFamily:"'Inter', sans-serif",marginTop:"4px"},children:"Uploading..."},void 0,!1,void 0,this),O&&t("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 h0({onClick:J,size:$=16}){return t("button",{onClick:(Y)=>{Y.stopPropagation(),J()},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:(Y)=>{Y.currentTarget.style.color="var(--color-text-secondary)"},onMouseLeave:(Y)=>{Y.currentTarget.style.color="var(--color-text-tertiary)"},children:t("svg",{width:$,height:$,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[t("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"},void 0,!1,void 0,this),t("circle",{cx:"8.5",cy:"8.5",r:"1.5"},void 0,!1,void 0,this),t("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 m5({images:J}){if(!J.length)return null;return t("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"6px"},children:J.map(($)=>t("div",{style:{width:"56px",height:"56px",borderRadius:"6px",overflow:"hidden",border:"1px solid var(--color-border-subtle)",flexShrink:0},children:t("img",{src:D5($),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 j3}from"#canvas/runtime";import{jsxDEV as n,Fragment as I3}from"react/jsx-dev-runtime";function C3({anchorEl:J,scrollContainer:$,onClose:Y,ignoreSelector:Z,zIndex:Q="50",padding:X="12px",width:q="280px",children:_}){let z=X0(null),K=X0(Y);K.current=Y;let{style:G,parent:U}=I5(J,$);return g5(()=>{let H=setTimeout(()=>{let F=(W)=>{if(z.current&&!z.current.contains(W.target)){if(Z&&W.target.closest?.(Z))return;K.current(),document.removeEventListener("mousedown",F)}};return document.addEventListener("mousedown",F),()=>document.removeEventListener("mousedown",F)},0);return()=>clearTimeout(H)},[Z]),R3(n("div",{ref:z,style:{...G,zIndex:Q,width:q,background:"var(--color-bg-elevated)",border:"1px solid var(--color-border-hover)",borderRadius:"8px",boxShadow:"0 4px 12px var(--color-shadow)",padding:X,fontFamily:"'Inter', sans-serif"},children:_},void 0,!1,void 0,this),U)}var v5=[{label:"Clarity",items:["Unclear","Why?","Needs example","Missing context"]},{label:"Scope",items:["Overkill","Out of scope","Important","Risky"]},{label:"Action",items:["Simplify","Rethink","Expand on this","Skip this"]}],f5=v5.flatMap((J)=>J.items);function u5({anchorEl:J,scrollContainer:$,snippet:Y,truncateAt:Z=100,header:Q,initialNote:X="",initialImages:q,onConfirm:_,onCancel:z,onDelete:K}){let G=A3(j3),U=X!==""||!!K,[H,F]=a1(X),[W,L]=a1(q||[]),[T,B]=a1(null),[O,D]=a1(U),[R,P]=a1(!1),k=X0(null),v=X0(null),g=q0(()=>{if(H.trim()||W.length>0)_(H.trim(),W);else if(U&&K)K();else z()},[H,W,_,z,U,K]),h=q0(()=>{if(U){if(!H.trim()&&W.length===0&&K){K(),z();return}_(H,W);return}z()},[H,W,U,_,z,K]),j=!U,V=H.trim().length>0?f5.filter((M)=>M.toLowerCase().startsWith(H.trim().toLowerCase())):f5,C=!j||O?[]:V.length===1&&V[0].toLowerCase()===H.trim().toLowerCase()?[]:V,I=new Set(C),S=v5.map((M)=>({label:M.label,items:M.items.filter((m)=>I.has(m))})).filter((M)=>M.items.length>0),w=S.map((M)=>M.items),N=w.flat(),b=k5(()=>{if(T===null)return 0;let M=0;for(let m=0;m<w.length;m++){if(T<M+w[m].length)return m;M+=w[m].length}return 0},[T,w]),f=k5(()=>{if(T===null)return 0;let M=0;for(let m=0;m<b;m++)M+=w[m].length;return T-M},[T,b,w]),u=(M,m)=>{let l=0;for(let Z1=0;Z1<M;Z1++)l+=w[Z1].length;return l+m};g5(()=>{B(null),D(U)},[H]);let p=q0((M)=>{F(M)},[]),c=Y.length>Z?Y.slice(0,Z)+"...":Y,i=q0((M)=>{if(N.length>0&&(M.key==="ArrowDown"||M.key==="ArrowUp"||M.key==="ArrowLeft"||M.key==="ArrowRight")){if(M.preventDefault(),T===null){B(0);return}if(M.key==="ArrowDown"){let m=Math.min(f+1,w[b].length-1);B(u(b,m))}else if(M.key==="ArrowUp"){let m=Math.max(f-1,0);B(u(b,m))}else if(M.key==="ArrowRight"){let m=Math.min(b+1,w.length-1),l=Math.min(f,w[m].length-1);B(u(m,l))}else if(M.key==="ArrowLeft"){let m=Math.max(b-1,0),l=Math.min(f,w[m].length-1);B(u(m,l))}return}if(T!==null&&N.length>0){if(M.key==="Tab"){M.preventDefault(),p(N[T]);return}if(M.key==="Enter"&&!M.shiftKey){M.preventDefault(),_(N[T],W);return}}if(M.key==="Enter"&&!M.shiftKey){M.preventDefault(),g();return}if(M.key==="Escape")if(N.length>0&&!O)D(!0);else if(U)h();else z()},[N,T,f,b,w,u,p,_,W,g,O,U,h,z]);return n(C3,{anchorEl:J,scrollContainer:$,onClose:U?h:z,ignoreSelector:U?"[data-annotation-id]":void 0,zIndex:U?"60":"50",padding:U?"10px 12px":"12px",width:"420px",children:[!U&&(Q??n("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:["“",c,"”"]},void 0,!0,void 0,this)),n(Z0,{note:H,onNoteChange:F,images:W,onAddImage:(M)=>L((m)=>[...m,M]),onRemoveImage:(M)=>L((m)=>m.filter((l)=>l!==M)),sessionId:G,autoFocus:!0,autoResize:U,textareaRef:k,onKeyDown:i,attachButton:"none",openFilePickerRef:v,textareaStyle:U?{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),n("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginTop:U?"6px":"8px"},children:[n(h0,{onClick:()=>v.current?.(),size:14},void 0,!1,void 0,this),n("div",{style:{flex:1}},void 0,!1,void 0,this),U?n("button",{onClick:()=>{if(K)K();z()},onMouseEnter:()=>P(!0),onMouseLeave:()=>P(!1),style:{fontSize:"11px",color:R?"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):n(I3,{children:[n("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),n("button",{onClick:g,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),N.length>0&&n("div",{style:{marginTop:"6px",borderTop:"1px solid var(--color-border-subtle)",paddingTop:"8px",display:"flex",gap:"4px"},children:S.map((M)=>n("div",{style:{flex:1},children:[n("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:M.label},void 0,!1,void 0,this),M.items.map((m)=>{let l=N.indexOf(m);return n("div",{onMouseDown:(Z1)=>{Z1.preventDefault(),Z1.stopPropagation(),p(m)},onMouseEnter:()=>B(l),style:{padding:"3px 6px",fontSize:"12px",borderRadius:"4px",fontFamily:"'Inter', sans-serif",color:l===T?"var(--color-text-primary)":"var(--color-text-secondary)",background:l===T?"var(--color-highlight-selected)":"transparent",cursor:"pointer"},children:[n("span",{style:{fontWeight:500},children:m.slice(0,H.trim().length)},void 0,!1,void 0,this),m.slice(H.trim().length)]},m,!0,void 0,this)})]},M.label,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function D1({anchorEl:J,scrollContainer:$,snippet:Y,truncateAt:Z,header:Q,onAdd:X,onCancel:q}){return n(u5,{anchorEl:J,scrollContainer:$,snippet:Y,truncateAt:Z,header:Q,onConfirm:(_,z)=>X(_,z),onCancel:q},void 0,!1,void 0,this)}function m1({anchorEl:J,scrollContainer:$,initialNote:Y,initialImages:Z,onUpdate:Q,onDelete:X,onClose:q}){return n(u5,{anchorEl:J,scrollContainer:$,snippet:"",initialNote:Y,initialImages:Z,onConfirm:(_,z)=>{Q(_,z),q()},onDelete:X,onCancel:q},void 0,!1,void 0,this)}import{useEffect as G0,useState as x5,useRef as k1,useCallback as h5}from"react";function b1(J,$){let Y=[],Z=V3(J);for(let Q of Z){let X=document.createRange();if(X.selectNodeContents(Q),Q===J.startContainer)X.setStart(Q,J.startOffset);if(Q===J.endContainer)X.setEnd(Q,J.endOffset);let q=X.toString();if(!q||!q.trim())continue;let _=document.createElement("mark");_.setAttribute("data-annotation-id",$);try{X.surroundContents(_)}catch{let z=X.extractContents();_.appendChild(z),X.insertNode(_)}Y.push(_)}return Y}function V3(J){let $=[],Y=J.commonAncestorContainer;if(Y.nodeType===Node.TEXT_NODE)return $.push(Y),$;let Z=document.createTreeWalker(Y,NodeFilter.SHOW_TEXT),Q;while(Q=Z.nextNode()){if(Q.parentElement?.classList.contains("select-none"))continue;if(J.intersectsNode(Q))$.push(Q)}return $}function S1(J,$){let Y=document.querySelectorAll(`[data-annotation-id="${J}"]`);for(let Z of Y)Z.classList.toggle("mark-active",$)}function z0(J,$){if($!=null&&$!==J)S1($,!1);if(J!=null)S1(J,!0)}function _0(J,$){let Y=document.querySelectorAll(`[data-annotation-id="${J}"]`);for(let Z of Y)Z.setAttribute("data-annotation-id",$)}function K0(J,$){let Y=$.filter((_)=>!document.querySelector(`[data-annotation-id="${_.id}"]`));if(!Y.length)return;let Z=[],Q="",X=document.createTreeWalker(J,NodeFilter.SHOW_TEXT),q;while(q=X.nextNode()){if(q.parentElement?.classList.contains("select-none"))continue;Z.push({node:q,start:Q.length}),Q+=q.textContent||""}for(let _ of Y){let z=_.snippet;if(!z)continue;let K=[],G=0;while(!0){let T=Q.indexOf(z,G);if(T===-1)break;K.push(T),G=T+1}if(K.length===0)continue;let U=K[0];if(K.length>1&&_.context){let T=-1;for(let B of K){let O=0;if(_.context.before){let D=Q.slice(Math.max(0,B-80),B);if(D.includes(_.context.before))O+=2;else if(_.context.before.length>10&&D.includes(_.context.before.slice(-10)))O+=1}if(_.context.after){let D=Q.slice(B+z.length,B+z.length+80);if(D.includes(_.context.after))O+=2;else if(_.context.after.length>10&&D.includes(_.context.after.slice(0,10)))O+=1}if(O>T)T=O,U=B}}let H=U,F=U+z.length,W=E5(Z,H),L=E5(Z,F);if(!W||!L)continue;try{let T=document.createRange();T.setStart(W.node,W.offset),T.setEnd(L.node,L.offset),b1(T,_.id)}catch{}}}function E5(J,$){for(let Y=J.length-1;Y>=0;Y--)if(J[Y].start<=$){let Z=$-J[Y].start,Q=J[Y].node.textContent?.length??0;if(Z<=Q)return{node:J[Y].node,offset:Z}}return null}function U0(J){let $=document.querySelectorAll(`[data-annotation-id="${J}"]`);for(let Y of $){let Z=Y.parentNode;if(!Z)continue;while(Y.firstChild)Z.insertBefore(Y.firstChild,Y);Z.removeChild(Y),Z.normalize()}}import{jsxDEV as p0,Fragment as D3}from"react/jsx-dev-runtime";function w1(J){let{containerRef:$,restoreKey:Y,restoreAnnotations:Z,extractContext:Q,filePath:X,scrollContainer:q}=J,{annotations:_,addAnnotationWithId:z,removeAnnotation:K,updateAnnotation:G,addAnnotationImage:U,removeAnnotationImage:H,activeAnnotationId:F,setActiveAnnotationId:W}=o(),[L,T]=x5(null),[B,O]=x5(null),D=k1(Q);D.current=Q;let R=k1(X);R.current=X;let P=k1(z);P.current=z;let k=k1(F);k.current=F;let v=k1(W);v.current=W,G0(()=>{if(!$.current)return;let C=setTimeout(()=>{if($.current)K0($.current,Z)},50);return()=>clearTimeout(C)},[Y]);let g=k1(null);G0(()=>{z0(F,g.current),g.current=F},[F]),G0(()=>{let C=$.current;if(!C)return;let I=(N)=>{let b=N.target.closest("[data-annotation-id]");if(!b)return;N.stopPropagation();let f=b.getAttribute("data-annotation-id");if(f===k.current)T({anchorEl:b,annId:f});else v.current(f)},S=(N)=>{let b=N.target.closest("[data-annotation-id]");if(b)v.current(b.getAttribute("data-annotation-id"))},w=(N)=>{let b=N.target.closest("[data-annotation-id]"),f=N.relatedTarget?.closest?.("[data-annotation-id]");if(b&&!f&&!document.getElementById("ann-inline-popover"))v.current(null)};return C.addEventListener("click",I),C.addEventListener("mouseover",S),C.addEventListener("mouseout",w),()=>{C.removeEventListener("click",I),C.removeEventListener("mouseover",S),C.removeEventListener("mouseout",w)}},[Y]),G0(()=>{let C=()=>h();return document.addEventListener("mouseup",C),()=>document.removeEventListener("mouseup",C)},[]);let h=h5(()=>{let C=window.getSelection();if(!C||C.isCollapsed||!C.toString().trim())return;if(!$.current)return;let I=C.getRangeAt(0);if(!$.current.contains(I.startContainer))return;if(I.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let S=C.toString().trim();if(S.length<2)return;let w=D.current(I),N=I.cloneRange(),b=`__pending_${Date.now()}`;try{b1(N,b)}catch{}window.getSelection()?.removeAllRanges();let f=document.querySelectorAll(`[data-annotation-id="${b}"]`),u=f[f.length-1];if(!u)return;O({anchorEl:u,tempId:b,snippet:S,ctx:w})},[]),j=h5((C,I,S,w)=>{O({anchorEl:C,tempId:I,snippet:S,ctx:w})},[]);return{popovers:p0(D3,{children:[L&&(()=>{let C=_.find((I)=>I.id===L.annId);if(!C)return null;return p0(m1,{anchorEl:L.anchorEl,scrollContainer:q,initialNote:C.note,initialImages:C.images,onUpdate:(I,S)=>{G(L.annId,I);let w=C.images||[];for(let N of S)if(!w.includes(N))U(L.annId,N);for(let N of w)if(!S.includes(N))H(L.annId,N)},onDelete:()=>{K(L.annId),W(null)},onClose:()=>T(null)},void 0,!1,void 0,this)})(),B&&p0(D1,{anchorEl:B.anchorEl,scrollContainer:q,snippet:B.snippet,truncateAt:80,onAdd:(C,I)=>{let S=z1();_0(B.tempId,S),P.current(S,B.snippet,C,R.current,B.ctx,I),O(null)},onCancel:()=>{U0(B.tempId),O(null)}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),openCreatePopover:j,isPopoverOpen:!!(L||B)}}import{jsxDEV as a,Fragment as c5}from"react/jsx-dev-runtime";var r0="[data-md='item'], [data-md='section'], [data-md='table'] tbody tr, [data-md='callout'], [data-md='note'], [data-md='checklist-item'], [data-md='choice-option'], [data-md='multichoice-option'], [data-md='userinput'], [data-md='rangeinput'], [data-md='image']",d0="[data-md='item'], [data-md='section'], [data-md='table'] tbody tr, [data-md='callout'], [data-md='note'], [data-md='checklist-item'], [data-md='image']";function p5({revision:J}){let $=k3(g3),[Y,Z]=U1(null),[Q,X]=U1(null),[q,_]=U1(!0),z=m3(null),{annotations:K,addAnnotationWithId:G,removeAnnotation:U,updateAnnotation:H,addAnnotationImage:F,removeAnnotationImage:W,activeAnnotationId:L,setActiveAnnotationId:T}=o(),[B,O]=U1(null),[D,R]=U1(null),[P,k]=U1(null),[v,g]=U1(null),[h,j]=U1(!1);R1(()=>{_(!0),X(null),g(null),import(`/api/session/${$}/plan.js?rev=${J}&t=${Date.now()}`).then((N)=>{Z(()=>N.default),_(!1)}).catch((N)=>{X(N.message),_(!1)})},[$,J]);let V=document.getElementById("plan-scroll-container"),{popovers:C,isPopoverOpen:I}=w1({containerRef:z,restoreKey:Y,restoreAnnotations:K,extractContext:(N)=>P1(N,z.current),scrollContainer:V}),S=H0(()=>{let N=new Map;for(let b of K)if(b.snippet.startsWith("["))N.set(b.snippet,b.id);return N},[K]);R1(()=>{let N=z.current;if(!N)return;let b=(u)=>{if(P||I)return;let p=u.target;if(p.closest("[data-block-comment-btn]"))return;j(!1);let c=p.closest(r0);if(c&&N.contains(c)){let m=A1(N).indexOf(c);g(m>=0?m:null)}else g(null);let i=p.closest(d0);if(i&&N.contains(i)){R(i);let M=f1(i),m=M?S.get(M):void 0;if(m&&m!==L)T(m)}else R(null)},f=(u)=>{if(P||I)return;if(u.relatedTarget?.closest("[data-block-comment-btn]"))return;R(null),T(null)};return N.addEventListener("mousemove",b),N.addEventListener("mouseleave",f),()=>{N.removeEventListener("mousemove",b),N.removeEventListener("mouseleave",f)}},[Y,P,I,S,L]),R1(()=>{let N=(b)=>{let f=b.target.tagName;if(f==="INPUT"||f==="TEXTAREA"||b.target.isContentEditable)return;if(P||I)return;let u=z.current;if(!u)return;if(b.key==="ArrowDown"){b.preventDefault(),j(!0);let p=A1(u);if(p.length===0)return;g((c)=>{if(c===null)return 0;return Math.min(c+1,p.length-1)})}else if(b.key==="ArrowUp"){b.preventDefault(),j(!0);let p=A1(u);if(p.length===0)return;g((c)=>{if(c===null)return p.length-1;return Math.max(c-1,0)})}else if(b.key==="a"||b.key==="A"){if(v===null||!u)return;b.preventDefault();let c=A1(u)[v];if(!c)return;let i=f1(c);if(!i)return;let M=S.get(i);if(M)T(M),k({anchorEl:c,snippet:i,annId:M});else k({anchorEl:c,snippet:i})}else if(b.key===" "||b.key==="Enter"){if(v===null)return;let c=A1(u)[v];if(!c)return;let i=c.getAttribute("data-md");if(i==="choice-option"||i==="multichoice-option")b.preventDefault(),c.dispatchEvent(new CustomEvent("kb-select",{bubbles:!0}));else if(i==="userinput"){b.preventDefault();let M=c.querySelector("textarea");if(M){M.focus();let m=(l)=>{if(l.key==="Escape")l.preventDefault(),M.blur(),j(!0)};M.addEventListener("keydown",m),M.addEventListener("blur",()=>M.removeEventListener("keydown",m),{once:!0})}}else if(i==="rangeinput"){b.preventDefault();let M=c.querySelector("input[type='range']");if(M){M.focus();let m=(l)=>{if(l.key==="Escape"||l.key==="ArrowUp"||l.key==="ArrowDown")l.preventDefault(),M.blur(),j(!0)};M.addEventListener("keydown",m),M.addEventListener("blur",()=>M.removeEventListener("keydown",m),{once:!0})}}}else if(b.key==="Escape")g(null),j(!1),T(null)};return document.addEventListener("keydown",N),()=>document.removeEventListener("keydown",N)},[v,P,I,S]),R1(()=>{let N=z.current;if(!N||v===null||!h)return;let f=A1(N)[v];if(!f)return;f.style.outline="2px solid var(--color-accent-blue)",f.style.outlineOffset="-2px",f.style.borderRadius="8px",f.scrollIntoView({block:"nearest",behavior:"smooth"});let u=f1(f),p=u?S.get(u):void 0;if(p)T(p);return()=>{f.style.outline="",f.style.outlineOffset="",f.style.borderRadius=""}},[v,h,S]);let w=H0(()=>Y?a(Y,{},void 0,!1,void 0,this):null,[Y]);if(q)return a("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 a("div",{className:"bg-accent-red-muted rounded-lg p-5",children:[a("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Compilation Error"},void 0,!1,void 0,this),a("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:Q},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(!Y)return a("div",{className:"text-text-tertiary text-center py-8 font-body text-body",children:"No canvas loaded"},void 0,!1,void 0,this);return a(c5,{children:[a("div",{ref:z,className:"plan-content plan-updated",children:w},void 0,!1,void 0,this),B&&a(E3,{note:B.note,onSave:(N)=>{H(B.id,N),O(null)},onCancel:()=>O(null)},void 0,!1,void 0,this),C,a(v3,{containerRef:z,hoveredBlock:D,focusedBlockIndex:v,blockPopover:P,blockAnnotationMap:S,activeAnnotationId:L,onOpen:(N,b,f)=>{if(f)T(f),k({anchorEl:N,snippet:b,annId:f});else k({anchorEl:N,snippet:b})}},void 0,!1,void 0,this),P&&!P.annId&&a(D1,{anchorEl:P.anchorEl,scrollContainer:V,snippet:P.snippet,truncateAt:80,onAdd:(N,b)=>{let f=z1();G(f,P.snippet,N,void 0,void 0,b),k(null)},onCancel:()=>k(null)},void 0,!1,void 0,this),P?.annId&&(()=>{let N=K.find((b)=>b.id===P.annId);if(!N)return null;return a(m1,{anchorEl:P.anchorEl,scrollContainer:V,initialNote:N.note,initialImages:N.images,onUpdate:(b,f)=>{H(P.annId,b);let u=N.images||[];for(let p of f)if(!u.includes(p))F(P.annId,p);for(let p of u)if(!f.includes(p))W(P.annId,p)},onDelete:()=>{U(P.annId),T(null),k(null)},onClose:()=>k(null)},void 0,!1,void 0,this)})()]},void 0,!0,void 0,this)}function A1(J){return Array.from(J.querySelectorAll(r0))}function f1(J){let $=J.getAttribute("data-md");if($==="item"){let Y=J.getAttribute("data-md-label");return Y?`[Item] ${Y}`:null}if($==="section"){let Y=J.getAttribute("data-md-title");return Y?`[Section] ${Y}`:null}if($==="callout"){let Y=J.getAttribute("data-md-type")||"info",Z=J.textContent?.trim().slice(0,60)||"Callout";return`[Callout:${Y}] ${Z}`}if($==="note")return`[Note] ${J.textContent?.trim().slice(0,60)||"Note"}`;if(J.tagName==="TR"){let Y=Array.from(J.querySelectorAll("td")).map((Z)=>Z.textContent?.trim()).filter(Boolean);return Y.length?`[Row] ${Y.join(" | ")}`:null}if($==="checklist-item"){let Y=J.getAttribute("data-md-label");return Y?`[Checklist] ${Y}`:null}if($==="choice-option"||$==="multichoice-option"){let Y=J.getAttribute("data-md-label");return Y?`[Option] ${Y}`:null}if($==="userinput"){let Y=J.getAttribute("data-md-label");return Y?`[Input] ${Y}`:null}if($==="rangeinput"){let Y=J.getAttribute("data-md-label");return Y?`[Range] ${Y}`:null}if($==="image"){let Y=J.getAttribute("data-md-src");return Y?`[Image] ${Y}`:null}return null}function v3({containerRef:J,hoveredBlock:$,focusedBlockIndex:Y,blockPopover:Z,blockAnnotationMap:Q,activeAnnotationId:X,onOpen:q}){let[_,z]=U1([]);R1(()=>{let F=J.current;if(!F||Q.size===0){z([]);return}let W=[];for(let L of F.querySelectorAll(d0)){let T=f1(L);if(T&&Q.has(T))W.push(L)}z(W)},[Q,J.current]);let[K,G]=U1(null);R1(()=>{if(!X||!J.current){G(null);return}for(let F of J.current.querySelectorAll(r0)){let W=f1(F);if(W&&Q.get(W)===X){G(F);return}}G(null)},[X,Q]),R1(()=>{if(!K)return;return K.style.boxShadow="inset 0 0 0 1.5px var(--color-highlight-bg)",K.style.borderRadius="8px",()=>{K.style.boxShadow="",K.style.borderRadius=""}},[K]);let U=H0(()=>{if(Y===null||!J.current)return null;let F=A1(J.current)[Y];if(!F)return null;return F.matches(d0)?F:null},[Y,J.current]),H=H0(()=>{let F=new Set(_);if($)F.add($);if(U)F.add(U);if(Z?.anchorEl)F.add(Z.anchorEl);return Array.from(F)},[_,$,U,Z]);return a(c5,{children:H.map((F)=>a(u3,{block:F,isHovered:F===$||F===U||F===Z?.anchorEl,blockAnnotationMap:Q,activeAnnotationId:X,onOpen:q},F.getAttribute("data-task-id")||F.getAttribute("data-md-title")||F.textContent?.slice(0,30)||"block",!1,void 0,this))},void 0,!1,void 0,this)}function u3({block:J,isHovered:$,blockAnnotationMap:Y,activeAnnotationId:Z,onOpen:Q}){let X=f1(J);if(!X)return null;let q=Y.get(X),_=!!q;return f3(a("button",{"data-block-comment-btn":!0,onClick:(K)=>{K.stopPropagation(),Q(K.currentTarget,X,q)},className:`absolute top-1 right-1 z-10 w-6 h-6 flex items-center justify-center rounded transition-all duration-150 ${_?q===Z?"text-accent-amber bg-accent-amber-muted":"text-accent-amber opacity-60 hover:opacity-100":$?"text-text-disabled hover:text-text-tertiary opacity-50 hover:opacity-100":"text-text-disabled opacity-0 group-hover/section:opacity-20 hover:!opacity-80"}`,title:_?"Edit annotation":"Add annotation",children:a("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:_?"currentColor":"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:a("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),J)}function E3({note:J,onSave:$,onCancel:Y}){let[Z,Q]=c0.useState(J),X=c0.useRef(null);return c0.useEffect(()=>{X.current?.focus(),X.current?.select()},[]),a("div",{className:"fixed inset-0 z-50 bg-black/40 flex items-center justify-center",onClick:Y,children:a("div",{className:"bg-bg-elevated border border-border-hover rounded-lg shadow-md p-4 w-80",onClick:(q)=>q.stopPropagation(),children:[a("div",{className:"text-tiny uppercase tracking-widest text-text-tertiary font-body mb-2",children:"Edit annotation"},void 0,!1,void 0,this),a("textarea",{ref:X,value:Z,onChange:(q)=>Q(q.target.value),className:"w-full bg-transparent border-none text-body font-body text-text-primary resize-vertical focus:outline-none min-h-[60px]",onKeyDown:(q)=>{if(q.key==="Enter"&&(q.ctrlKey||q.metaKey))$(Z.trim());if(q.key==="Escape")Y()}},void 0,!1,void 0,this),a("div",{className:"flex justify-end gap-2 mt-2",children:[a("button",{onClick:Y,className:"text-meta text-text-tertiary font-body px-3 py-1",children:"Cancel"},void 0,!1,void 0,this),a("button",{onClick:()=>$(Z.trim()),className:"text-meta font-medium font-body px-3 py-1 rounded-md bg-highlight-bg text-text-primary border border-highlight-border",children:"Save"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}import t3,{useRef as a5,useEffect as o0,useCallback as i5,useState as g1,useContext as y0}from"react";function i1(J,$,Y,Z){let Q=[],X=J.filter((U)=>U.filePath===Q1),q=J.filter((U)=>!U.filePath),_=J.filter((U)=>U.filePath&&U.filePath!==Q1),z=Y?Array.from(Y.values()).filter((U)=>a0(U)):[],K=Z?Array.from(Z.values()).filter((U)=>U.markdown.trim()):[];if(z.length>0||K.length>0){Q.push("## Responses"),Q.push("");for(let U of z)Q.push(p3(U));for(let U of K)Q.push(U.markdown.trim()),Q.push("")}if(X.length>0){Q.push("## Annotations on agent response"),Q.push("");for(let U of X)Q.push(l0(U))}if(q.length>0){Q.push("## Canvas annotations"),Q.push("");let U=c3(q);Q.push(d5(U))}if(_.length>0){let U={};for(let H of _){let F=H.filePath;if(!U[F])U[F]=[];U[F].push(H)}Q.push("## File annotations"),Q.push("");for(let[H,F]of Object.entries(U)){Q.push(`### ${H}`),Q.push("");for(let W of F)Q.push(l0(W))}}if($.trim())Q.push("## General notes"),Q.push(""),Q.push($.trim()),Q.push("");return Q.join(`
58
+ `}strong({tokens:J}){return`<strong>${this.parser.parseInline(J)}</strong>`}em({tokens:J}){return`<em>${this.parser.parseInline(J)}</em>`}codespan({text:J}){return`<code>${_1(J,!0)}</code>`}br(J){return"<br>"}del({tokens:J}){return`<del>${this.parser.parseInline(J)}</del>`}link({href:J,title:$,tokens:Y}){let Z=this.parser.parseInline(Y),Q=U5(J);if(Q===null)return Z;J=Q;let q='<a href="'+J+'"';return $&&(q+=' title="'+_1($)+'"'),q+=">"+Z+"</a>",q}image({href:J,title:$,text:Y,tokens:Z}){Z&&(Y=this.parser.parseInline(Z,this.parser.textRenderer));let Q=U5(J);if(Q===null)return _1(Y);J=Q;let q=`<img src="${J}" alt="${_1(Y)}"`;return $&&(q+=` title="${_1($)}"`),q+=">",q}text(J){return"tokens"in J&&J.tokens?this.parser.parseInline(J.tokens):("escaped"in J)&&J.escaped?J.text:_1(J.text)}},g0=class{strong({text:J}){return J}em({text:J}){return J}codespan({text:J}){return J}del({text:J}){return J}html({text:J}){return J}text({text:J}){return J}link({text:J}){return""+J}image({text:J}){return""+J}br(){return""}checkbox({raw:J}){return J}},q1=class J{options;renderer;textRenderer;constructor($){this.options=$||B1,this.options.renderer=this.options.renderer||new J0,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new g0}static parse($,Y){return new J(Y).parse($)}static parseInline($,Y){return new J(Y).parseInline($)}parse($){let Y="";for(let Z=0;Z<$.length;Z++){let Q=$[Z];if(this.options.extensions?.renderers?.[Q.type]){let X=Q,_=this.options.extensions.renderers[X.type].call({parser:this},X);if(_!==!1||!["space","hr","heading","code","table","blockquote","list","html","def","paragraph","text"].includes(X.type)){Y+=_||"";continue}}let q=Q;switch(q.type){case"space":{Y+=this.renderer.space(q);break}case"hr":{Y+=this.renderer.hr(q);break}case"heading":{Y+=this.renderer.heading(q);break}case"code":{Y+=this.renderer.code(q);break}case"table":{Y+=this.renderer.table(q);break}case"blockquote":{Y+=this.renderer.blockquote(q);break}case"list":{Y+=this.renderer.list(q);break}case"checkbox":{Y+=this.renderer.checkbox(q);break}case"html":{Y+=this.renderer.html(q);break}case"def":{Y+=this.renderer.def(q);break}case"paragraph":{Y+=this.renderer.paragraph(q);break}case"text":{Y+=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 Y}parseInline($,Y=this.renderer){let Z="";for(let Q=0;Q<$.length;Q++){let q=$[Q];if(this.options.extensions?.renderers?.[q.type]){let _=this.options.extensions.renderers[q.type].call({parser:this},q);if(_!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(q.type)){Z+=_||"";continue}}let X=q;switch(X.type){case"escape":{Z+=Y.text(X);break}case"html":{Z+=Y.html(X);break}case"link":{Z+=Y.link(X);break}case"image":{Z+=Y.image(X);break}case"checkbox":{Z+=Y.checkbox(X);break}case"strong":{Z+=Y.strong(X);break}case"em":{Z+=Y.em(X);break}case"codespan":{Z+=Y.codespan(X);break}case"br":{Z+=Y.br(X);break}case"del":{Z+=Y.del(X);break}case"text":{Z+=Y.text(X);break}default:{let _='Token with "'+X.type+'" type was not found.';if(this.options.silent)return console.error(_),"";throw Error(_)}}}return Z}},p1=class{options;block;constructor(J){this.options=J||B1}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens","emStrongMask"]);static passThroughHooksRespectAsync=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(J){return J}postprocess(J){return J}processAllTokens(J){return J}emStrongMask(J){return J}provideLexer(){return this.block?X1.lex:X1.lexInline}provideParser(){return this.block?q1.parse:q1.parseInline}},O3=class{defaults=j0();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=q1;Renderer=J0;TextRenderer=g0;Lexer=X1;Tokenizer=$0;Hooks=p1;constructor(...J){this.use(...J)}walkTokens(J,$){let Y=[];for(let Z of J)switch(Y=Y.concat($.call(this,Z)),Z.type){case"table":{let Q=Z;for(let q of Q.header)Y=Y.concat(this.walkTokens(q.tokens,$));for(let q of Q.rows)for(let X of q)Y=Y.concat(this.walkTokens(X.tokens,$));break}case"list":{let Q=Z;Y=Y.concat(this.walkTokens(Q.items,$));break}default:{let Q=Z;this.defaults.extensions?.childTokens?.[Q.type]?this.defaults.extensions.childTokens[Q.type].forEach((q)=>{let X=Q[q].flat(1/0);Y=Y.concat(this.walkTokens(X,$))}):Q.tokens&&(Y=Y.concat(this.walkTokens(Q.tokens,$)))}}return Y}use(...J){let $=this.defaults.extensions||{renderers:{},childTokens:{}};return J.forEach((Y)=>{let Z={...Y};if(Z.async=this.defaults.async||Z.async||!1,Y.extensions&&(Y.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 _=Q.renderer.apply(this,X);return _===!1&&(_=q.apply(this,X)),_}:$.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)}),Z.extensions=$),Y.renderer){let Q=this.defaults.renderer||new J0(this.defaults);for(let q in Y.renderer){if(!(q in Q))throw Error(`renderer '${q}' does not exist`);if(["options","parser"].includes(q))continue;let X=q,_=Y.renderer[X],z=Q[X];Q[X]=(...K)=>{let G=_.apply(Q,K);return G===!1&&(G=z.apply(Q,K)),G||""}}Z.renderer=Q}if(Y.tokenizer){let Q=this.defaults.tokenizer||new $0(this.defaults);for(let q in Y.tokenizer){if(!(q in Q))throw Error(`tokenizer '${q}' does not exist`);if(["options","rules","lexer"].includes(q))continue;let X=q,_=Y.tokenizer[X],z=Q[X];Q[X]=(...K)=>{let G=_.apply(Q,K);return G===!1&&(G=z.apply(Q,K)),G}}Z.tokenizer=Q}if(Y.hooks){let Q=this.defaults.hooks||new p1;for(let q in Y.hooks){if(!(q in Q))throw Error(`hook '${q}' does not exist`);if(["options","block"].includes(q))continue;let X=q,_=Y.hooks[X],z=Q[X];p1.passThroughHooks.has(q)?Q[X]=(K)=>{if(this.defaults.async&&p1.passThroughHooksRespectAsync.has(q))return(async()=>{let U=await _.call(Q,K);return z.call(Q,U)})();let G=_.call(Q,K);return z.call(Q,G)}:Q[X]=(...K)=>{if(this.defaults.async)return(async()=>{let U=await _.apply(Q,K);return U===!1&&(U=await z.apply(Q,K)),U})();let G=_.apply(Q,K);return G===!1&&(G=z.apply(Q,K)),G}}Z.hooks=Q}if(Y.walkTokens){let Q=this.defaults.walkTokens,q=Y.walkTokens;Z.walkTokens=function(X){let _=[];return _.push(q.call(this,X)),Q&&(_=_.concat(Q.call(this,X))),_}}this.defaults={...this.defaults,...Z}}),this}setOptions(J){return this.defaults={...this.defaults,...J},this}lexer(J,$){return X1.lex(J,$??this.defaults)}parser(J,$){return q1.parse(J,$??this.defaults)}parseMarkdown(J){return($,Y)=>{let Z={...Y},Q={...this.defaults,...Z},q=this.onError(!!Q.silent,!!Q.async);if(this.defaults.async===!0&&Z.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=J),Q.async)return(async()=>{let X=Q.hooks?await Q.hooks.preprocess($):$,_=await(Q.hooks?await Q.hooks.provideLexer():J?X1.lex:X1.lexInline)(X,Q),z=Q.hooks?await Q.hooks.processAllTokens(_):_;Q.walkTokens&&await Promise.all(this.walkTokens(z,Q.walkTokens));let K=await(Q.hooks?await Q.hooks.provideParser():J?q1.parse:q1.parseInline)(z,Q);return Q.hooks?await Q.hooks.postprocess(K):K})().catch(q);try{Q.hooks&&($=Q.hooks.preprocess($));let X=(Q.hooks?Q.hooks.provideLexer():J?X1.lex:X1.lexInline)($,Q);Q.hooks&&(X=Q.hooks.processAllTokens(X)),Q.walkTokens&&this.walkTokens(X,Q.walkTokens);let _=(Q.hooks?Q.hooks.provideParser():J?q1.parse:q1.parseInline)(X,Q);return Q.hooks&&(_=Q.hooks.postprocess(_)),_}catch(X){return q(X)}}}onError(J,$){return(Y)=>{if(Y.message+=`
59
+ Please report this to https://github.com/markedjs/marked.`,J){let Z="<p>An error occurred:</p><pre>"+_1(Y.message+"",!0)+"</pre>";return $?Promise.resolve(Z):Z}if($)return Promise.reject(Y);throw Y}}},M1=new O3;function r(J,$){return M1.parse(J,$)}r.options=r.setOptions=function(J){return M1.setOptions(J),r.defaults=M1.defaults,W5(r.defaults),r};r.getDefaults=j0;r.defaults=B1;r.use=function(...J){return M1.use(...J),r.defaults=M1.defaults,W5(r.defaults),r};r.walkTokens=function(J,$){return M1.walkTokens(J,$)};r.parseInline=M1.parseInline;r.Parser=q1;r.parser=q1.parse;r.Renderer=J0;r.TextRenderer=g0;r.Lexer=X1;r.lexer=X1.lex;r.Tokenizer=$0;r.Hooks=p1;r.parse=r;var{options:X4,setOptions:q4,use:z4,walkTokens:_4,parseInline:K4}=r;var U4=q1.parse,G4=X1.lex;import{SessionContext as R2,ActiveViewCtx as n$}from"#canvas/runtime";import{useState as r1,useCallback as K1,useEffect as w5,useRef as A5}from"react";import{AnnotationCtx as L3}from"#canvas/runtime";var Q1="__agent-response__";function z1(){return`ann-${Date.now()}-${Math.random().toString(36).slice(2,6)}`}function d1(J,$){J.style.height="auto",J.style.height=($?Math.max($,J.scrollHeight):J.scrollHeight)+"px"}import{useAnnotations as o}from"#canvas/runtime";import{jsxDEV as S3}from"react/jsx-dev-runtime";function v0(J,$){return`canvas:${J}:rev:${$}`}function l1(J,$){try{let Y=localStorage.getItem(v0(J,$));if(!Y)return null;return JSON.parse(Y)}catch{return null}}function M3(J,$,Y){try{localStorage.setItem(v0(J,$),JSON.stringify(Y))}catch{}}function B3(J,$){try{localStorage.removeItem(v0(J,$))}catch{}}function R5({sessionId:J,revision:$,isReadOnly:Y,children:Z}){let Q=A5(`${J}:${$}`),[q,X]=r1(()=>{return l1(J,$)?.annotations??[]}),[_,z]=r1(()=>{return l1(J,$)?.generalNote??""}),[K,G]=r1(null),[U,H]=r1(()=>{let j=l1(J,$);return j?.responses?new Map(j.responses):new Map}),[F,W]=r1(()=>{let j=l1(J,$);return j?.feedbackEntries?new Map(j.feedbackEntries):new Map});w5(()=>{let j=`${J}:${$}`;if(j===Q.current)return;Q.current=j;let V=l1(J,$);X(V?.annotations??[]),z(V?.generalNote??""),H(V?.responses?new Map(V.responses):new Map),W(V?.feedbackEntries?new Map(V.feedbackEntries):new Map),G(null)},[J,$]);let L=A5(null);w5(()=>{if(Y)return;if(L.current)clearTimeout(L.current);return L.current=setTimeout(()=>{M3(J,$,{annotations:q,generalNote:_,responses:Array.from(U.entries()),feedbackEntries:Array.from(F.entries())})},300),()=>{if(L.current)clearTimeout(L.current)}},[q,_,U,F,J,$,Y]);let y=K1((j,V,C,I,S,w)=>{X((N)=>[...N,{id:j,snippet:V,note:C,createdAt:new Date().toISOString(),filePath:I,context:S,...w?.length?{images:w}:{}}])},[]),B=K1((j,V,C)=>{y(z1(),j,V,C)},[y]),O=K1((j,V)=>{X((C)=>C.map((I)=>I.id===j?{...I,note:V}:I))},[]),D=K1((j)=>{P3(j),X((V)=>V.filter((C)=>C.id!==j)),G((V)=>V===j?null:V)},[]),R=K1((j,V)=>{X((C)=>C.map((I)=>I.id===j?{...I,images:[...I.images||[],V]}:I))},[]),P=K1((j,V)=>{X((C)=>C.map((I)=>I.id===j?{...I,images:(I.images||[]).filter((S)=>S!==V)}:I))},[]),k=K1((j,V)=>{H((C)=>{let I=new Map(C);return I.set(j,V),I})},[]),v=K1((j,V)=>{W((C)=>{let I=C.get(j);if(I&&I.markdown===V.markdown&&I.label===V.label&&I.required===V.required)return C;let S=new Map(C);return S.set(j,V),S})},[]),g=K1((j)=>{W((V)=>{if(!V.has(j))return V;let C=new Map(V);return C.delete(j),C})},[]),h=K1(()=>{for(let j of document.querySelectorAll("[data-annotation-id]"))j5(j);X([]),z(""),G(null),H(new Map),W(new Map),B3(J,$)},[J,$]);return S3(L3.Provider,{value:{annotations:q,addAnnotation:B,addAnnotationWithId:y,updateAnnotation:O,removeAnnotation:D,addAnnotationImage:R,removeAnnotationImage:P,generalNote:_,setGeneralNote:z,clearAll:h,activeAnnotationId:K,setActiveAnnotationId:G,responses:U,setResponse:k,feedbackEntries:F,setFeedbackEntry:v,removeFeedbackEntry:g},children:Z},void 0,!1,void 0,this)}function P3(J){let $=document.querySelectorAll(`[data-annotation-id="${J}"]`);for(let Y of $)j5(Y)}function j5(J){let $=J.parentNode;if(!$)return;let Y=document.createTextNode(J.textContent||"");$.replaceChild(Y,J),$.normalize()}import c0,{useEffect as R1,useState as U1,useRef as k3,useContext as f3,useMemo as H0}from"react";import{createPortal as g3}from"react-dom";import{SessionContext as v3}from"#canvas/runtime";function P1(J,$){let Y=C5(J,"before",60),Z=C5(J,"after",60),Q=w3(J.startContainer,$);return{before:Y,after:Z,hierarchy:Q}}function C5(J,$,Y){let Z=b3($==="before"?J.startContainer:J.endContainer);if(!Z)return"";let Q="";if($==="before"){let q=document.createTreeWalker(Z,NodeFilter.SHOW_TEXT),X;while(X=q.nextNode()){if(X===J.startContainer){Q+=(X.textContent||"").slice(0,J.startOffset);break}if(X.parentElement?.hasAttribute("data-annotation-id"))continue;Q+=X.textContent||""}if(Q.length>Y){Q=Q.slice(-Y);let _=Q.indexOf(" ");if(_>0)Q=Q.slice(_+1)}}else{let q=document.createTreeWalker(Z,NodeFilter.SHOW_TEXT),X=!1,_;while(_=q.nextNode()){if(_===J.endContainer){Q+=(_.textContent||"").slice(J.endOffset),X=!0;continue}if(X){if(_.parentElement?.hasAttribute("data-annotation-id"))continue;Q+=_.textContent||""}}if(Q.length>Y){Q=Q.slice(0,Y);let z=Q.lastIndexOf(" ");if(z>0)Q=Q.slice(0,z)}}return Q.trim()}function b3(J){let $=new Set(["DIV","P","LI","PRE","BLOCKQUOTE","SECTION","ARTICLE"]),Y=J.parentElement;while(Y){if($.has(Y.tagName))return Y;Y=Y.parentElement}return null}function w3(J,$){let Y=[],Z=J instanceof Element?J:J.parentElement;while(Z&&Z!==$){let Q=Z.getAttribute?.("data-task-id");if(Q){let q=Z.querySelector(".font-semibold");if(q)Y.unshift(q.textContent?.trim()||Q)}if(Z.tagName==="DIV"&&Z.querySelector(":scope > button .font-heading, :scope > div .font-heading")){let q=Z.querySelector(".font-heading");if(q)Y.unshift(q.textContent?.trim()||"")}Z=Z.parentElement}return Y}function u0(J){let $=J.snippet.trim(),Y=J.context,Z=$.length<30;if(Y&&Z&&(Y.before||Y.after)){let Q=[];if(Y.before)Q.push(`...${Y.before} `);if(Q.push(`**${$}**`),Y.after)Q.push(` ${Y.after}...`);return Q.join("")}return $}import{useEffect as g5,useRef as q0,useState as a1,useCallback as X0,useMemo as k5,useContext as R3}from"react";import{createPortal as j3}from"react-dom";function I5(J,$){let Q=$||document.body,q=J.getBoundingClientRect(),X=Q.getBoundingClientRect(),_=Q===document.body?window.scrollY:Q.scrollTop,z=q.bottom-X.top+_+8,K=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:`${K}px`},parent:Q}}import{useState as E0,useRef as x0,useCallback as W1,useEffect as V5}from"react";import{jsxDEV as t}from"react/jsx-dev-runtime";function D5(J){return`/api/uploads/${J.split("/").pop()}`}async function A3(J,$){let Y=new FormData;Y.append("image",$);try{return(await(await fetch(`/api/session/${J}/upload`,{method:"POST",body:Y})).json()).path||null}catch{return null}}function Z0({note:J,onNoteChange:$,images:Y,onAddImage:Z,onRemoveImage:Q,sessionId:q,placeholder:X="Add your note...",autoFocus:_=!1,autoResize:z=!1,readOnly:K=!1,onKeyDown:G,onTextareaClick:U,textareaRef:H,textareaClassName:F,textareaStyle:W,minHeight:L,attachButton:y="always",openFilePickerRef:B}){let[O,D]=E0(!1),[R,P]=E0(!1),[k,v]=E0(!1),g=x0(0),h=x0(null),j=x0(null),V=W1(()=>j.current?.click(),[]);V5(()=>{if(B)B.current=V},[B,V]);let C=W1((M)=>{if(h.current=M,H)H.current=M;if(M&&z)d1(M,L)},[H,z,L]);V5(()=>{if(_&&h.current){let M=h.current;if(M.focus(),M.value)M.setSelectionRange(M.value.length,M.value.length)}},[_]);let I=W1(async(M)=>{if(!M.type.startsWith("image/"))return;P(!0);try{let m=await A3(q,M);if(m)Z(m)}finally{P(!1)}},[q,Z]),S=W1((M)=>{let m=M.clipboardData.items;for(let l of m)if(l.type.startsWith("image/")){M.preventDefault();let Z1=l.getAsFile();if(Z1)I(Z1);return}},[I]),w=W1((M)=>{if(M.preventDefault(),g.current++,g.current===1)D(!0)},[]),N=W1((M)=>{M.preventDefault()},[]),b=W1((M)=>{if(M.preventDefault(),g.current--,g.current===0)D(!1)},[]),f=W1((M)=>{M.preventDefault(),g.current=0,D(!1);for(let m of M.dataTransfer.files)if(m.type.startsWith("image/"))I(m)},[I]),u=W1((M)=>{if($(M.target.value),z)M.target.style.height="auto",M.target.style.height=(L?Math.max(L,M.target.scrollHeight):M.target.scrollHeight)+"px"},[$,z,L]),p="w-full bg-transparent text-[13px] font-body text-text-primary resize-none focus:outline-none leading-relaxed p-0 border-none",c={width:"100%",background:"transparent",border:"none",color:"var(--color-text-primary)",fontFamily:"'Inter', sans-serif",fontSize:"13px",lineHeight:"1.5",outline:"none",...z?{resize:"none",overflow:"hidden"}:{resize:"vertical"}},i=!K&&(y==="always"||y==="on-focus"&&k);return t("div",{style:{position:"relative"},onDragEnter:K?void 0:w,onDragOver:K?void 0:N,onDragLeave:K?void 0:b,onDrop:K?void 0:f,children:[t("textarea",{ref:C,value:J,onChange:K?void 0:u,onPaste:K?void 0:S,onKeyDown:G,onClick:U,onFocus:()=>v(!0),onBlur:()=>{setTimeout(()=>v(!1),150)},readOnly:K,placeholder:X,className:F??p,style:W??c,rows:z?1:void 0},void 0,!1,void 0,this),!K&&t("input",{ref:j,type:"file",accept:"image/*",multiple:!0,style:{display:"none"},onChange:(M)=>{let m=M.target.files;if(m)for(let l of m)I(l);M.target.value=""}},void 0,!1,void 0,this),(Y.length>0||i)&&t("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"6px",alignItems:"center"},children:[Y.map((M)=>t("div",{style:{position:"relative",width:"56px",height:"56px",borderRadius:"6px",overflow:"hidden",border:"1px solid var(--color-border-subtle)",flexShrink:0},children:[t("img",{src:D5(M),alt:"",style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}},void 0,!1,void 0,this),!K&&t("button",{onClick:(m)=>{m.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)),i&&t(h0,{onClick:V},void 0,!1,void 0,this)]},void 0,!0,void 0,this),R&&t("div",{style:{fontSize:"11px",color:"var(--color-text-tertiary)",fontFamily:"'Inter', sans-serif",marginTop:"4px"},children:"Uploading..."},void 0,!1,void 0,this),O&&t("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 h0({onClick:J,size:$=16}){return t("button",{onClick:(Y)=>{Y.stopPropagation(),J()},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:(Y)=>{Y.currentTarget.style.color="var(--color-text-secondary)"},onMouseLeave:(Y)=>{Y.currentTarget.style.color="var(--color-text-tertiary)"},children:t("svg",{width:$,height:$,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[t("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"},void 0,!1,void 0,this),t("circle",{cx:"8.5",cy:"8.5",r:"1.5"},void 0,!1,void 0,this),t("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 m5({images:J}){if(!J.length)return null;return t("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"6px"},children:J.map(($)=>t("div",{style:{width:"56px",height:"56px",borderRadius:"6px",overflow:"hidden",border:"1px solid var(--color-border-subtle)",flexShrink:0},children:t("img",{src:D5($),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 C3}from"#canvas/runtime";import{jsxDEV as n,Fragment as V3}from"react/jsx-dev-runtime";function I3({anchorEl:J,scrollContainer:$,onClose:Y,ignoreSelector:Z,zIndex:Q="50",padding:q="12px",width:X="280px",children:_}){let z=q0(null),K=q0(Y);K.current=Y;let{style:G,parent:U}=I5(J,$);return g5(()=>{let H=setTimeout(()=>{let F=(W)=>{if(z.current&&!z.current.contains(W.target)){if(Z&&W.target.closest?.(Z))return;K.current(),document.removeEventListener("mousedown",F)}};return document.addEventListener("mousedown",F),()=>document.removeEventListener("mousedown",F)},0);return()=>clearTimeout(H)},[Z]),j3(n("div",{ref:z,style:{...G,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:_},void 0,!1,void 0,this),U)}var v5=[{label:"Clarity",items:["Unclear","Why?","Needs example","Missing context"]},{label:"Scope",items:["Overkill","Out of scope","Important","Risky"]},{label:"Action",items:["Simplify","Rethink","Expand on this","Skip this"]}],f5=v5.flatMap((J)=>J.items);function u5({anchorEl:J,scrollContainer:$,snippet:Y,truncateAt:Z=100,header:Q,initialNote:q="",initialImages:X,onConfirm:_,onCancel:z,onDelete:K}){let G=R3(C3),U=q!==""||!!K,[H,F]=a1(q),[W,L]=a1(X||[]),[y,B]=a1(null),[O,D]=a1(U),[R,P]=a1(!1),k=q0(null),v=q0(null),g=X0(()=>{if(H.trim()||W.length>0)_(H.trim(),W);else if(U&&K)K();else z()},[H,W,_,z,U,K]),h=X0(()=>{if(U){if(!H.trim()&&W.length===0&&K){K(),z();return}_(H,W);return}z()},[H,W,U,_,z,K]),j=!U,V=H.trim().length>0?f5.filter((M)=>M.toLowerCase().startsWith(H.trim().toLowerCase())):f5,C=!j||O?[]:V.length===1&&V[0].toLowerCase()===H.trim().toLowerCase()?[]:V,I=new Set(C),S=v5.map((M)=>({label:M.label,items:M.items.filter((m)=>I.has(m))})).filter((M)=>M.items.length>0),w=S.map((M)=>M.items),N=w.flat(),b=k5(()=>{if(y===null)return 0;let M=0;for(let m=0;m<w.length;m++){if(y<M+w[m].length)return m;M+=w[m].length}return 0},[y,w]),f=k5(()=>{if(y===null)return 0;let M=0;for(let m=0;m<b;m++)M+=w[m].length;return y-M},[y,b,w]),u=(M,m)=>{let l=0;for(let Z1=0;Z1<M;Z1++)l+=w[Z1].length;return l+m};g5(()=>{B(null),D(U)},[H]);let p=X0((M)=>{F(M)},[]),c=Y.length>Z?Y.slice(0,Z)+"...":Y,i=X0((M)=>{if(N.length>0&&(M.key==="ArrowDown"||M.key==="ArrowUp"||M.key==="ArrowLeft"||M.key==="ArrowRight")){if(M.preventDefault(),y===null){B(0);return}if(M.key==="ArrowDown"){let m=Math.min(f+1,w[b].length-1);B(u(b,m))}else if(M.key==="ArrowUp"){let m=Math.max(f-1,0);B(u(b,m))}else if(M.key==="ArrowRight"){let m=Math.min(b+1,w.length-1),l=Math.min(f,w[m].length-1);B(u(m,l))}else if(M.key==="ArrowLeft"){let m=Math.max(b-1,0),l=Math.min(f,w[m].length-1);B(u(m,l))}return}if(y!==null&&N.length>0){if(M.key==="Tab"){M.preventDefault(),p(N[y]);return}if(M.key==="Enter"&&!M.shiftKey){M.preventDefault(),_(N[y],W);return}}if(M.key==="Enter"&&!M.shiftKey){M.preventDefault(),g();return}if(M.key==="Escape")if(N.length>0&&!O)D(!0);else if(U)h();else z()},[N,y,f,b,w,u,p,_,W,g,O,U,h,z]);return n(I3,{anchorEl:J,scrollContainer:$,onClose:U?h:z,ignoreSelector:U?"[data-annotation-id]":void 0,zIndex:U?"60":"50",padding:U?"10px 12px":"12px",width:"420px",children:[!U&&(Q??n("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:["“",c,"”"]},void 0,!0,void 0,this)),n(Z0,{note:H,onNoteChange:F,images:W,onAddImage:(M)=>L((m)=>[...m,M]),onRemoveImage:(M)=>L((m)=>m.filter((l)=>l!==M)),sessionId:G,autoFocus:!0,autoResize:U,textareaRef:k,onKeyDown:i,attachButton:"none",openFilePickerRef:v,textareaStyle:U?{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),n("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginTop:U?"6px":"8px"},children:[n(h0,{onClick:()=>v.current?.(),size:14},void 0,!1,void 0,this),n("div",{style:{flex:1}},void 0,!1,void 0,this),U?n("button",{onClick:()=>{if(K)K();z()},onMouseEnter:()=>P(!0),onMouseLeave:()=>P(!1),style:{fontSize:"11px",color:R?"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):n(V3,{children:[n("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),n("button",{onClick:g,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),N.length>0&&n("div",{style:{marginTop:"6px",borderTop:"1px solid var(--color-border-subtle)",paddingTop:"8px",display:"flex",gap:"4px"},children:S.map((M)=>n("div",{style:{flex:1},children:[n("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:M.label},void 0,!1,void 0,this),M.items.map((m)=>{let l=N.indexOf(m);return n("div",{onMouseDown:(Z1)=>{Z1.preventDefault(),Z1.stopPropagation(),p(m)},onMouseEnter:()=>B(l),style:{padding:"3px 6px",fontSize:"12px",borderRadius:"4px",fontFamily:"'Inter', sans-serif",color:l===y?"var(--color-text-primary)":"var(--color-text-secondary)",background:l===y?"var(--color-highlight-selected)":"transparent",cursor:"pointer"},children:[n("span",{style:{fontWeight:500},children:m.slice(0,H.trim().length)},void 0,!1,void 0,this),m.slice(H.trim().length)]},m,!0,void 0,this)})]},M.label,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function D1({anchorEl:J,scrollContainer:$,snippet:Y,truncateAt:Z,header:Q,onAdd:q,onCancel:X}){return n(u5,{anchorEl:J,scrollContainer:$,snippet:Y,truncateAt:Z,header:Q,onConfirm:(_,z)=>q(_,z),onCancel:X},void 0,!1,void 0,this)}function m1({anchorEl:J,scrollContainer:$,initialNote:Y,initialImages:Z,onUpdate:Q,onDelete:q,onClose:X}){return n(u5,{anchorEl:J,scrollContainer:$,snippet:"",initialNote:Y,initialImages:Z,onConfirm:(_,z)=>{Q(_,z),X()},onDelete:q,onCancel:X},void 0,!1,void 0,this)}import{useEffect as G0,useState as x5,useRef as k1,useCallback as h5}from"react";function b1(J,$){let Y=[],Z=D3(J);for(let Q of Z){let q=document.createRange();if(q.selectNodeContents(Q),Q===J.startContainer)q.setStart(Q,J.startOffset);if(Q===J.endContainer)q.setEnd(Q,J.endOffset);let X=q.toString();if(!X||!X.trim())continue;let _=document.createElement("mark");_.setAttribute("data-annotation-id",$);try{q.surroundContents(_)}catch{let z=q.extractContents();_.appendChild(z),q.insertNode(_)}Y.push(_)}return Y}function D3(J){let $=[],Y=J.commonAncestorContainer;if(Y.nodeType===Node.TEXT_NODE)return $.push(Y),$;let Z=document.createTreeWalker(Y,NodeFilter.SHOW_TEXT),Q;while(Q=Z.nextNode()){if(Q.parentElement?.classList.contains("select-none"))continue;if(J.intersectsNode(Q))$.push(Q)}return $}function S1(J,$){let Y=document.querySelectorAll(`[data-annotation-id="${J}"]`);for(let Z of Y)Z.classList.toggle("mark-active",$)}function z0(J,$){if($!=null&&$!==J)S1($,!1);if(J!=null)S1(J,!0)}function _0(J,$){let Y=document.querySelectorAll(`[data-annotation-id="${J}"]`);for(let Z of Y)Z.setAttribute("data-annotation-id",$)}function K0(J,$){let Y=$.filter((_)=>!document.querySelector(`[data-annotation-id="${_.id}"]`));if(!Y.length)return;let Z=[],Q="",q=document.createTreeWalker(J,NodeFilter.SHOW_TEXT),X;while(X=q.nextNode()){if(X.parentElement?.classList.contains("select-none"))continue;Z.push({node:X,start:Q.length}),Q+=X.textContent||""}for(let _ of Y){let z=_.snippet;if(!z)continue;let K=[],G=0;while(!0){let y=Q.indexOf(z,G);if(y===-1)break;K.push(y),G=y+1}if(K.length===0)continue;let U=K[0];if(K.length>1&&_.context){let y=-1;for(let B of K){let O=0;if(_.context.before){let D=Q.slice(Math.max(0,B-80),B);if(D.includes(_.context.before))O+=2;else if(_.context.before.length>10&&D.includes(_.context.before.slice(-10)))O+=1}if(_.context.after){let D=Q.slice(B+z.length,B+z.length+80);if(D.includes(_.context.after))O+=2;else if(_.context.after.length>10&&D.includes(_.context.after.slice(0,10)))O+=1}if(O>y)y=O,U=B}}let H=U,F=U+z.length,W=E5(Z,H),L=E5(Z,F);if(!W||!L)continue;try{let y=document.createRange();y.setStart(W.node,W.offset),y.setEnd(L.node,L.offset),b1(y,_.id)}catch{}}}function E5(J,$){for(let Y=J.length-1;Y>=0;Y--)if(J[Y].start<=$){let Z=$-J[Y].start,Q=J[Y].node.textContent?.length??0;if(Z<=Q)return{node:J[Y].node,offset:Z}}return null}function U0(J){let $=document.querySelectorAll(`[data-annotation-id="${J}"]`);for(let Y of $){let Z=Y.parentNode;if(!Z)continue;while(Y.firstChild)Z.insertBefore(Y.firstChild,Y);Z.removeChild(Y),Z.normalize()}}import{jsxDEV as p0,Fragment as m3}from"react/jsx-dev-runtime";function w1(J){let{containerRef:$,restoreKey:Y,restoreAnnotations:Z,extractContext:Q,filePath:q,scrollContainer:X}=J,{annotations:_,addAnnotationWithId:z,removeAnnotation:K,updateAnnotation:G,addAnnotationImage:U,removeAnnotationImage:H,activeAnnotationId:F,setActiveAnnotationId:W}=o(),[L,y]=x5(null),[B,O]=x5(null),D=k1(Q);D.current=Q;let R=k1(q);R.current=q;let P=k1(z);P.current=z;let k=k1(F);k.current=F;let v=k1(W);v.current=W,G0(()=>{if(!$.current)return;let C=setTimeout(()=>{if($.current)K0($.current,Z)},50);return()=>clearTimeout(C)},[Y]);let g=k1(null);G0(()=>{z0(F,g.current),g.current=F},[F]),G0(()=>{let C=$.current;if(!C)return;let I=(N)=>{let b=N.target.closest("[data-annotation-id]");if(!b)return;N.stopPropagation();let f=b.getAttribute("data-annotation-id");if(f===k.current)y({anchorEl:b,annId:f});else v.current(f)},S=(N)=>{let b=N.target.closest("[data-annotation-id]");if(b)v.current(b.getAttribute("data-annotation-id"))},w=(N)=>{let b=N.target.closest("[data-annotation-id]"),f=N.relatedTarget?.closest?.("[data-annotation-id]");if(b&&!f&&!document.getElementById("ann-inline-popover"))v.current(null)};return C.addEventListener("click",I),C.addEventListener("mouseover",S),C.addEventListener("mouseout",w),()=>{C.removeEventListener("click",I),C.removeEventListener("mouseover",S),C.removeEventListener("mouseout",w)}},[Y]),G0(()=>{let C=()=>h();return document.addEventListener("mouseup",C),()=>document.removeEventListener("mouseup",C)},[]);let h=h5(()=>{let C=window.getSelection();if(!C||C.isCollapsed||!C.toString().trim())return;if(!$.current)return;let I=C.getRangeAt(0);if(!$.current.contains(I.startContainer))return;if(I.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let S=C.toString().trim();if(S.length<2)return;let w=D.current(I),N=I.cloneRange(),b=`__pending_${Date.now()}`;try{b1(N,b)}catch{}window.getSelection()?.removeAllRanges();let f=document.querySelectorAll(`[data-annotation-id="${b}"]`),u=f[f.length-1];if(!u)return;O({anchorEl:u,tempId:b,snippet:S,ctx:w})},[]),j=h5((C,I,S,w)=>{O({anchorEl:C,tempId:I,snippet:S,ctx:w})},[]);return{popovers:p0(m3,{children:[L&&(()=>{let C=_.find((I)=>I.id===L.annId);if(!C)return null;return p0(m1,{anchorEl:L.anchorEl,scrollContainer:X,initialNote:C.note,initialImages:C.images,onUpdate:(I,S)=>{G(L.annId,I);let w=C.images||[];for(let N of S)if(!w.includes(N))U(L.annId,N);for(let N of w)if(!S.includes(N))H(L.annId,N)},onDelete:()=>{K(L.annId),W(null)},onClose:()=>y(null)},void 0,!1,void 0,this)})(),B&&p0(D1,{anchorEl:B.anchorEl,scrollContainer:X,snippet:B.snippet,truncateAt:80,onAdd:(C,I)=>{let S=z1();_0(B.tempId,S),P.current(S,B.snippet,C,R.current,B.ctx,I),O(null)},onCancel:()=>{U0(B.tempId),O(null)}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),openCreatePopover:j,isPopoverOpen:!!(L||B)}}import{jsxDEV as a,Fragment as c5}from"react/jsx-dev-runtime";var r0="[data-md='item'], [data-md='section'], [data-md='table'] tbody tr, [data-md='callout'], [data-md='note'], [data-md='checklist-item'], [data-md='choice-option'], [data-md='multichoice-option'], [data-md='userinput'], [data-md='rangeinput'], [data-md='image']",d0="[data-md='item'], [data-md='section'], [data-md='table'] tbody tr, [data-md='callout'], [data-md='note'], [data-md='checklist-item'], [data-md='image']";function p5({revision:J}){let $=f3(v3),[Y,Z]=U1(null),[Q,q]=U1(null),[X,_]=U1(!0),z=k3(null),{annotations:K,addAnnotationWithId:G,removeAnnotation:U,updateAnnotation:H,addAnnotationImage:F,removeAnnotationImage:W,activeAnnotationId:L,setActiveAnnotationId:y}=o(),[B,O]=U1(null),[D,R]=U1(null),[P,k]=U1(null),[v,g]=U1(null),[h,j]=U1(!1);R1(()=>{_(!0),q(null),g(null),import(`/api/session/${$}/plan.js?rev=${J}&t=${Date.now()}`).then((N)=>{Z(()=>N.default),_(!1)}).catch((N)=>{q(N.message),_(!1)})},[$,J]);let V=document.getElementById("plan-scroll-container"),{popovers:C,isPopoverOpen:I}=w1({containerRef:z,restoreKey:Y,restoreAnnotations:K,extractContext:(N)=>P1(N,z.current),scrollContainer:V}),S=H0(()=>{let N=new Map;for(let b of K)if(b.snippet.startsWith("["))N.set(b.snippet,b.id);return N},[K]);R1(()=>{let N=z.current;if(!N)return;let b=(u)=>{if(P||I)return;let p=u.target;if(p.closest("[data-block-comment-btn]"))return;j(!1);let c=p.closest(r0);if(c&&N.contains(c)){let m=A1(N).indexOf(c);g(m>=0?m:null)}else g(null);let i=p.closest(d0);if(i&&N.contains(i)){R(i);let M=f1(i),m=M?S.get(M):void 0;if(m&&m!==L)y(m)}else R(null)},f=(u)=>{if(P||I)return;if(u.relatedTarget?.closest("[data-block-comment-btn]"))return;R(null),y(null)};return N.addEventListener("mousemove",b),N.addEventListener("mouseleave",f),()=>{N.removeEventListener("mousemove",b),N.removeEventListener("mouseleave",f)}},[Y,P,I,S,L]),R1(()=>{let N=(b)=>{let f=b.target.tagName;if(f==="INPUT"||f==="TEXTAREA"||b.target.isContentEditable)return;if(P||I)return;let u=z.current;if(!u)return;if(b.key==="ArrowDown"){b.preventDefault(),j(!0);let p=A1(u);if(p.length===0)return;g((c)=>{if(c===null)return 0;return Math.min(c+1,p.length-1)})}else if(b.key==="ArrowUp"){b.preventDefault(),j(!0);let p=A1(u);if(p.length===0)return;g((c)=>{if(c===null)return p.length-1;return Math.max(c-1,0)})}else if(b.key==="a"||b.key==="A"){if(v===null||!u)return;b.preventDefault();let c=A1(u)[v];if(!c)return;let i=f1(c);if(!i)return;let M=S.get(i);if(M)y(M),k({anchorEl:c,snippet:i,annId:M});else k({anchorEl:c,snippet:i})}else if(b.key===" "||b.key==="Enter"){if(v===null)return;let c=A1(u)[v];if(!c)return;let i=c.getAttribute("data-md");if(i==="choice-option"||i==="multichoice-option")b.preventDefault(),c.dispatchEvent(new CustomEvent("kb-select",{bubbles:!0}));else if(i==="userinput"){b.preventDefault();let M=c.querySelector("textarea");if(M){M.focus();let m=(l)=>{if(l.key==="Escape")l.preventDefault(),M.blur(),j(!0)};M.addEventListener("keydown",m),M.addEventListener("blur",()=>M.removeEventListener("keydown",m),{once:!0})}}else if(i==="rangeinput"){b.preventDefault();let M=c.querySelector("input[type='range']");if(M){M.focus();let m=(l)=>{if(l.key==="Escape"||l.key==="ArrowUp"||l.key==="ArrowDown")l.preventDefault(),M.blur(),j(!0)};M.addEventListener("keydown",m),M.addEventListener("blur",()=>M.removeEventListener("keydown",m),{once:!0})}}}else if(b.key==="Escape")g(null),j(!1),y(null)};return document.addEventListener("keydown",N),()=>document.removeEventListener("keydown",N)},[v,P,I,S]),R1(()=>{let N=z.current;if(!N||v===null||!h)return;let f=A1(N)[v];if(!f)return;f.style.outline="2px solid var(--color-accent-blue)",f.style.outlineOffset="-2px",f.style.borderRadius="8px",f.scrollIntoView({block:"nearest",behavior:"smooth"});let u=f1(f),p=u?S.get(u):void 0;if(p)y(p);return()=>{f.style.outline="",f.style.outlineOffset="",f.style.borderRadius=""}},[v,h,S]);let w=H0(()=>Y?a(Y,{},void 0,!1,void 0,this):null,[Y]);if(X)return a("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 a("div",{className:"bg-accent-red-muted rounded-lg p-5",children:[a("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Compilation Error"},void 0,!1,void 0,this),a("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:Q},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(!Y)return a("div",{className:"text-text-tertiary text-center py-8 font-body text-body",children:"No canvas loaded"},void 0,!1,void 0,this);return a(c5,{children:[a("div",{ref:z,className:"plan-content plan-updated",children:w},void 0,!1,void 0,this),B&&a(x3,{note:B.note,onSave:(N)=>{H(B.id,N),O(null)},onCancel:()=>O(null)},void 0,!1,void 0,this),C,a(u3,{containerRef:z,hoveredBlock:D,focusedBlockIndex:v,blockPopover:P,blockAnnotationMap:S,activeAnnotationId:L,onOpen:(N,b,f)=>{if(f)y(f),k({anchorEl:N,snippet:b,annId:f});else k({anchorEl:N,snippet:b})}},void 0,!1,void 0,this),P&&!P.annId&&a(D1,{anchorEl:P.anchorEl,scrollContainer:V,snippet:P.snippet,truncateAt:80,onAdd:(N,b)=>{let f=z1();G(f,P.snippet,N,void 0,void 0,b),k(null)},onCancel:()=>k(null)},void 0,!1,void 0,this),P?.annId&&(()=>{let N=K.find((b)=>b.id===P.annId);if(!N)return null;return a(m1,{anchorEl:P.anchorEl,scrollContainer:V,initialNote:N.note,initialImages:N.images,onUpdate:(b,f)=>{H(P.annId,b);let u=N.images||[];for(let p of f)if(!u.includes(p))F(P.annId,p);for(let p of u)if(!f.includes(p))W(P.annId,p)},onDelete:()=>{U(P.annId),y(null),k(null)},onClose:()=>k(null)},void 0,!1,void 0,this)})()]},void 0,!0,void 0,this)}function A1(J){return Array.from(J.querySelectorAll(r0))}function f1(J){let $=J.getAttribute("data-md");if($==="item"){let Y=J.getAttribute("data-md-label");return Y?`[Item] ${Y}`:null}if($==="section"){let Y=J.getAttribute("data-md-title");return Y?`[Section] ${Y}`:null}if($==="callout"){let Y=J.getAttribute("data-md-type")||"info",Z=J.textContent?.trim().slice(0,60)||"Callout";return`[Callout:${Y}] ${Z}`}if($==="note")return`[Note] ${J.textContent?.trim().slice(0,60)||"Note"}`;if(J.tagName==="TR"){let Y=Array.from(J.querySelectorAll("td")).map((Z)=>Z.textContent?.trim()).filter(Boolean);return Y.length?`[Row] ${Y.join(" | ")}`:null}if($==="checklist-item"){let Y=J.getAttribute("data-md-label");return Y?`[Checklist] ${Y}`:null}if($==="choice-option"||$==="multichoice-option"){let Y=J.getAttribute("data-md-label");return Y?`[Option] ${Y}`:null}if($==="userinput"){let Y=J.getAttribute("data-md-label");return Y?`[Input] ${Y}`:null}if($==="rangeinput"){let Y=J.getAttribute("data-md-label");return Y?`[Range] ${Y}`:null}if($==="image"){let Y=J.getAttribute("data-md-src");return Y?`[Image] ${Y}`:null}return null}function u3({containerRef:J,hoveredBlock:$,focusedBlockIndex:Y,blockPopover:Z,blockAnnotationMap:Q,activeAnnotationId:q,onOpen:X}){let[_,z]=U1([]);R1(()=>{let F=J.current;if(!F||Q.size===0){z([]);return}let W=[];for(let L of F.querySelectorAll(d0)){let y=f1(L);if(y&&Q.has(y))W.push(L)}z(W)},[Q,J.current]);let[K,G]=U1(null);R1(()=>{if(!q||!J.current){G(null);return}for(let F of J.current.querySelectorAll(r0)){let W=f1(F);if(W&&Q.get(W)===q){G(F);return}}G(null)},[q,Q]),R1(()=>{if(!K)return;return K.style.boxShadow="inset 0 0 0 1.5px var(--color-highlight-bg)",K.style.borderRadius="8px",()=>{K.style.boxShadow="",K.style.borderRadius=""}},[K]);let U=H0(()=>{if(Y===null||!J.current)return null;let F=A1(J.current)[Y];if(!F)return null;return F.matches(d0)?F:null},[Y,J.current]),H=H0(()=>{let F=new Set(_);if($)F.add($);if(U)F.add(U);if(Z?.anchorEl)F.add(Z.anchorEl);return Array.from(F)},[_,$,U,Z]);return a(c5,{children:H.map((F)=>a(E3,{block:F,isHovered:F===$||F===U||F===Z?.anchorEl,blockAnnotationMap:Q,activeAnnotationId:q,onOpen:X},F.getAttribute("data-task-id")||F.getAttribute("data-md-title")||F.textContent?.slice(0,30)||"block",!1,void 0,this))},void 0,!1,void 0,this)}function E3({block:J,isHovered:$,blockAnnotationMap:Y,activeAnnotationId:Z,onOpen:Q}){let q=f1(J);if(!q)return null;let X=Y.get(q),_=!!X;return g3(a("button",{"data-block-comment-btn":!0,onClick:(K)=>{K.stopPropagation(),Q(K.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 ${_?X===Z?"text-accent-amber bg-accent-amber-muted":"text-accent-amber opacity-60 hover:opacity-100":$?"text-text-disabled hover:text-text-tertiary opacity-50 hover:opacity-100":"text-text-disabled opacity-0 group-hover/section:opacity-20 hover:!opacity-80"}`,title:_?"Edit annotation":"Add annotation",children:a("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:_?"currentColor":"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:a("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),J)}function x3({note:J,onSave:$,onCancel:Y}){let[Z,Q]=c0.useState(J),q=c0.useRef(null);return c0.useEffect(()=>{q.current?.focus(),q.current?.select()},[]),a("div",{className:"fixed inset-0 z-50 bg-black/40 flex items-center justify-center",onClick:Y,children:a("div",{className:"bg-bg-elevated border border-border-hover rounded-lg shadow-md p-4 w-80",onClick:(X)=>X.stopPropagation(),children:[a("div",{className:"text-tiny uppercase tracking-widest text-text-tertiary font-body mb-2",children:"Edit annotation"},void 0,!1,void 0,this),a("textarea",{ref:q,value:Z,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))$(Z.trim());if(X.key==="Escape")Y()}},void 0,!1,void 0,this),a("div",{className:"flex justify-end gap-2 mt-2",children:[a("button",{onClick:Y,className:"text-meta text-text-tertiary font-body px-3 py-1",children:"Cancel"},void 0,!1,void 0,this),a("button",{onClick:()=>$(Z.trim()),className:"text-meta font-medium font-body px-3 py-1 rounded-md bg-highlight-bg text-text-primary border border-highlight-border",children:"Save"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}import n3,{useRef as a5,useEffect as o0,useCallback as i5,useState as g1,useContext as y0}from"react";function i1(J,$,Y,Z){let Q=[],q=J.filter((U)=>U.filePath===Q1),X=J.filter((U)=>!U.filePath),_=J.filter((U)=>U.filePath&&U.filePath!==Q1),z=Y?Array.from(Y.values()).filter((U)=>a0(U)):[],K=Z?Array.from(Z.values()).filter((U)=>U.markdown.trim()):[];if(z.length>0||K.length>0){Q.push("## Responses"),Q.push("");for(let U of z)Q.push(c3(U));for(let U of K)Q.push(U.markdown.trim()),Q.push("")}if(q.length>0){Q.push("## Annotations on agent response"),Q.push("");for(let U of q)Q.push(l0(U))}if(X.length>0){Q.push("## Canvas annotations"),Q.push("");let U=d3(X);Q.push(d5(U))}if(_.length>0){let U={};for(let H of _){let F=H.filePath;if(!U[F])U[F]=[];U[F].push(H)}Q.push("## File annotations"),Q.push("");for(let[H,F]of Object.entries(U)){Q.push(`### ${H}`),Q.push("");for(let W of F)Q.push(l0(W))}}if($.trim())Q.push("## General notes"),Q.push(""),Q.push($.trim()),Q.push("");return Q.join(`
60
60
  `).trim()+`
61
- `}function a0(J){if(J.note?.trim())return!0;if(J.value===null||J.value===void 0)return!1;if(J.type==="text"&&!J.value.trim())return!1;if(J.type==="checkbox"&&J.value.length===0)return!1;return!0}function x3(J){let $=[];for(let Y of J.values()){if(!Y.required)continue;if(Y.value===null||Y.value===void 0){$.push(Y);continue}if(Y.type==="text"&&!Y.value.trim()){$.push(Y);continue}if(Y.type==="checkbox"&&Y.value.length===0){$.push(Y);continue}}return $}function h3(J){let $=[];for(let Y of J.values())if(Y.required&&!Y.markdown.trim())$.push(Y);return $}function W0(J,$){let Y=x3(J),Z=h3($);return[...Y.map((Q)=>Q.label),...Z.map((Q)=>Q.label||Q.id)]}function p3(J){let $=[];switch($.push(`**${J.label}**`),J.type){case"radio":case"select":$.push(`Answer: ${J.value}`);break;case"checkbox":for(let Y of J.value)$.push(`- [x] ${Y}`);break;case"text":$.push(""),$.push(J.value.trim());break;case"range":$.push(`Answer: ${J.value}`);break}if(J.note?.trim())$.push(""),$.push(`Note: ${J.note.trim()}`);return $.push(""),$.join(`
62
- `)}function l0(J){let $=[],Y=J.snippet.trim(),Z=J.context,Q=Z?.lineStart!=null;if(J.filePath&&Q){let X=Z.lineStart,q=Z.lineEnd??X,_=Y.split(`
63
- `);if(Y.length<30&&X===q&&(Z.before||Z.after)){let K=u0(J);$.push(`> L${X}: ${K}`)}else if(_.length<=6)for(let K=0;K<_.length;K++)$.push(`> ${X+K} | ${_[K]}`);else{for(let K=0;K<3;K++)$.push(`> ${X+K} | ${_[K]}`);$.push(`> ... (${_.length} lines)`);for(let K=_.length-3;K<_.length;K++)$.push(`> ${X+K} | ${_[K]}`)}}else{let X=u0(J);if(Y.split(`
64
- `).length<=3)$.push(`> ${X.split(`
61
+ `}function a0(J){if(J.note?.trim())return!0;if(J.value===null||J.value===void 0)return!1;if(J.type==="text"&&!J.value.trim())return!1;if(J.type==="checkbox"&&J.value.length===0)return!1;return!0}function h3(J){let $=[];for(let Y of J.values()){if(!Y.required)continue;if(Y.value===null||Y.value===void 0){$.push(Y);continue}if(Y.type==="text"&&!Y.value.trim()){$.push(Y);continue}if(Y.type==="checkbox"&&Y.value.length===0){$.push(Y);continue}}return $}function p3(J){let $=[];for(let Y of J.values())if(Y.required&&!Y.markdown.trim())$.push(Y);return $}function W0(J,$){let Y=h3(J),Z=p3($);return[...Y.map((Q)=>Q.label),...Z.map((Q)=>Q.label||Q.id)]}function c3(J){let $=[];switch($.push(`**${J.label}**`),J.type){case"radio":case"select":$.push(`Answer: ${J.value}`);break;case"checkbox":for(let Y of J.value)$.push(`- [x] ${Y}`);break;case"text":$.push(""),$.push(J.value.trim());break;case"range":$.push(`Answer: ${J.value}`);break}if(J.note?.trim())$.push(""),$.push(`Note: ${J.note.trim()}`);return $.push(""),$.join(`
62
+ `)}function l0(J){let $=[],Y=J.snippet.trim(),Z=J.context,Q=Z?.lineStart!=null;if(J.filePath&&Q){let q=Z.lineStart,X=Z.lineEnd??q,_=Y.split(`
63
+ `);if(Y.length<30&&q===X&&(Z.before||Z.after)){let K=u0(J);$.push(`> L${q}: ${K}`)}else if(_.length<=6)for(let K=0;K<_.length;K++)$.push(`> ${q+K} | ${_[K]}`);else{for(let K=0;K<3;K++)$.push(`> ${q+K} | ${_[K]}`);$.push(`> ... (${_.length} lines)`);for(let K=_.length-3;K<_.length;K++)$.push(`> ${q+K} | ${_[K]}`)}}else{let q=u0(J);if(Y.split(`
64
+ `).length<=3)$.push(`> ${q.split(`
65
65
  `).join(`
66
- > `)}`);else{let q=Y.split(`
67
- `);$.push(`> ${q[0]}`),$.push(`> ... (${q.length} lines)`),$.push(`> ${q[q.length-1]}`)}}if(J.note.trim())$.push(""),$.push(J.note.trim());if(J.images?.length){$.push("");for(let X of J.images)$.push(`![screenshot](${X})`)}return $.push(""),$.join(`
68
- `)}function c3(J){let $={label:"",annotations:[],children:new Map};for(let Y of J){let Z=Y.context?.hierarchy||[],Q=$;for(let X of Z){if(!Q.children.has(X))Q.children.set(X,{label:X,annotations:[],children:new Map});Q=Q.children.get(X)}Q.annotations.push(Y)}return $}function d5(J,$=0){let Y=[];for(let Z of J.annotations)Y.push(l0(Z));for(let[,Z]of J.children){let Q=$===0?"###":"####";Y.push(`${Q} ${Z.label}`),Y.push(""),Y.push(d5(Z,$+1))}return Y.join(`
69
- `)}import{SessionContext as s5}from"#canvas/runtime";import{useEffect as i0,useState as F0,useRef as d3,useMemo as r3}from"react";import{jsxDEV as s}from"react/jsx-dev-runtime";function r5({open:J,onClose:$,onSubmit:Y}){let{annotations:Z,generalNote:Q,responses:X,feedbackEntries:q}=o(),[_,z]=F0(""),[K,G]=F0(!1),[U,H]=F0(!1),[F,W]=F0(null),L=d3(null);if(i0(()=>{if(!J){G(!1),H(!1),W(null);return}if(K)return;z(i1(Z,Q,X,q))},[Z,Q,X,q,K,J]),i0(()=>{if(J&&U&&L.current)L.current.focus()},[J,U]),i0(()=>{if(!J)return;let B=(O)=>{if(O.key==="Escape")$()};return window.addEventListener("keydown",B),()=>window.removeEventListener("keydown",B)},[J,$]),!J)return null;let T=_.trim().length>0;return s("div",{className:"fixed inset-0 z-50 bg-black/50 backdrop-blur-sm flex items-center justify-center p-8",onClick:$,children:s("div",{className:"bg-bg-surface border border-border-medium rounded-xl shadow-lg w-full max-w-2xl flex flex-col",style:{height:"80vh"},onClick:(B)=>B.stopPropagation(),children:[s("div",{className:"flex items-center justify-between px-5 py-3 border-b border-border-subtle flex-shrink-0",children:[s("div",{className:"flex items-center gap-3",children:[s("span",{className:"text-[13px] font-medium text-text-primary font-body",children:"Response preview"},void 0,!1,void 0,this),K&&s("button",{onClick:()=>{G(!1),H(!1)},className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body",children:"Reset"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),s("div",{className:"flex items-center gap-2",children:[s("div",{className:"flex items-center bg-bg-base rounded-md p-0.5",children:[s("button",{onClick:()=>H(!1),className:`px-2.5 py-1 rounded text-[11px] font-body font-medium transition-colors ${!U?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Preview"},void 0,!1,void 0,this),s("button",{onClick:()=>H(!0),className:`px-2.5 py-1 rounded text-[11px] font-body font-medium transition-colors ${U?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Edit"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),s("button",{onClick:$,className:"text-text-tertiary hover:text-text-secondary w-7 h-7 flex items-center justify-center rounded-md hover:bg-border-subtle transition-colors",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),U?s("textarea",{ref:L,value:_,onChange:(B)=>{z(B.target.value),G(!0)},className:"flex-1 w-full bg-bg-base p-5 text-[13px] font-mono text-text-code resize-none focus:outline-none leading-relaxed placeholder:text-text-disabled",placeholder:"Your feedback will appear here..."},void 0,!1,void 0,this):s("div",{className:"flex-1 overflow-y-auto p-5",children:s(N0,{text:_},void 0,!1,void 0,this)},void 0,!1,void 0,this),F&&s("div",{className:"px-5 py-2 text-[12px] text-accent-red font-body border-t border-border-subtle flex-shrink-0 flex items-center justify-between gap-2",children:[s("span",{children:F},void 0,!1,void 0,this),s("button",{onClick:()=>{W(null),Y(_)},className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body whitespace-nowrap underline",children:"Submit anyway"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),s("div",{className:"flex justify-end gap-2 px-5 py-3 border-t border-border-subtle flex-shrink-0",children:[s("button",{onClick:$,className:"px-4 py-2 rounded-lg text-[13px] font-body text-text-tertiary hover:text-text-secondary transition-colors",children:"Cancel"},void 0,!1,void 0,this),s("button",{onClick:()=>{let B=W0(X,q);if(B.length>0){W(`Please answer: ${B.join(", ")}`);return}W(null),Y(_)},disabled:!T,className:`px-6 py-2 rounded-lg font-body text-[13px] font-medium transition-all ${T?"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 l3=/!\[([^\]]*)\]\((\/tmp\/agent-canvas\/uploads\/([^)]+))\)/g;function a3(J){return J.replace(l3,($,Y,Z,Q)=>`![${Y}](/api/uploads/${Q})`)}function N0({text:J}){let $=r3(()=>r.parse(a3(J),{async:!1}),[J]);return s("div",{className:"prose-canvas font-body text-body text-text-primary leading-relaxed",dangerouslySetInnerHTML:{__html:$}},void 0,!1,void 0,this)}import{jsxDEV as j1}from"react/jsx-dev-runtime";var i3={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"},s3={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 N1({name:J,type:$,expanded:Y,className:Z=""}){if($==="dir")return j1("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",className:`flex-shrink-0 ${Z}`,children:Y?j1("path",{d:"M1.5 3.5h5l1.5 1.5h6.5v8h-13z",style:{fill:"var(--color-folder-fill-active)",stroke:"var(--color-folder-stroke-active)"},strokeWidth:"1"},void 0,!1,void 0,this):j1("path",{d:"M1.5 3.5h5l1.5 1.5h6.5v8h-13z",style:{fill:"var(--color-folder-fill)",stroke:"var(--color-folder-stroke)"},strokeWidth:"1"},void 0,!1,void 0,this)},void 0,!1,void 0,this);let Q=J.includes(".")?J.split(".").pop().toLowerCase():"",X=i3[Q]||"#6b6560",q=s3[Q];return j1("svg",{width:"14",height:"14",viewBox:"0 0 16 16",className:`flex-shrink-0 ${Z}`,children:[j1("path",{d:"M2 1.5h8l3.5 3.5v9.5a1 1 0 01-1 1H3a1 1 0 01-1-1v-12a1 1 0 011-1z",fill:X,opacity:"0.85"},void 0,!1,void 0,this),j1("path",{d:"M10 1.5v2.5a1 1 0 001 1h2.5",fill:"none",stroke:"white",strokeWidth:"0.5",opacity:"0.5"},void 0,!1,void 0,this),q&&j1("text",{x:"8",y:"11.5",textAnchor:"middle",fill:"white",fontSize:"5.5",fontFamily:"monospace",fontWeight:"600",children:q},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function o3(J){let $=J.getAttribute("data-md");if($==="item"){let Y=J.getAttribute("data-md-label");return Y?`[Item] ${Y}`:null}if($==="section"){let Y=J.getAttribute("data-md-title");return Y?`[Section] ${Y}`:null}if($==="callout"){let Y=J.getAttribute("data-md-type")||"info",Z=J.textContent?.trim().slice(0,60)||"Callout";return`[Callout:${Y}] ${Z}`}if($==="note")return`[Note] ${J.textContent?.trim().slice(0,60)||"Note"}`;if(J.tagName==="TR"){let Y=Array.from(J.querySelectorAll("td")).map((Z)=>Z.textContent?.trim()).filter(Boolean);return Y.length?`[Row] ${Y.join(" | ")}`:null}if($==="checklist-item"){let Y=J.getAttribute("data-md-label");return Y?`[Checklist] ${Y}`:null}if($==="choice-option"||$==="multichoice-option"){let Y=J.getAttribute("data-md-label");return Y?`[Option] ${Y}`:null}if($==="userinput"){let Y=J.getAttribute("data-md-label");return Y?`[Input] ${Y}`:null}if($==="rangeinput"){let Y=J.getAttribute("data-md-label");return Y?`[Range] ${Y}`:null}if($==="image"){let Y=J.getAttribute("data-md-src");return Y?`[Image] ${Y}`:null}return null}function s1(J){let $=document.querySelector(`[data-annotation-id="${J.id}"]`);if($)return $;if(J.snippet.startsWith("[")){for(let Y 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(o3(Y)===J.snippet)return Y}return null}function l5(J){J.classList.remove("ann-flash"),J.offsetWidth,J.classList.add("ann-flash"),J.addEventListener("animationend",()=>{J.classList.remove("ann-flash")},{once:!0})}function s0(J,$){if(J.filePath)$({type:"file",path:J.filePath}),setTimeout(()=>{let Y=s1(J);if(Y)Y.scrollIntoView({behavior:"smooth",block:"center"}),l5(Y)},150);else{let Y=s1(J);if(Y)Y.scrollIntoView({behavior:"smooth",block:"center"}),l5(Y)}}import{jsxDEV as A,Fragment as T0}from"react/jsx-dev-runtime";function t0({onPreview:J,onSubmit:$,collapseButton:Y}){let{isReadOnly:Z,selectedRevision:Q,currentRevision:X,revisions:q}=y0(v1),_=y0(s5),z=Z&&Q===X,G=q.find((U)=>U.revision===Q)?.label||`Round ${Q}`;if(Z)return A(e3,{sessionId:_,revision:Q,label:G,waitingForUpdate:z,collapseButton:Y},void 0,!1,void 0,this);return A(Y$,{onPreview:J,onSubmit:$,collapseButton:Y},void 0,!1,void 0,this)}function n3({sessionId:J,revision:$,label:Y,waitingForUpdate:Z,collapseButton:Q}){let[X,q]=g1(null),[_,z]=g1(!0);return o0(()=>{z(!0),fetch(`/api/session/${J}/revision/${$}/feedback`).then((K)=>K.json()).then((K)=>{q(K.feedback||null),z(!1)}).catch(()=>{q(null),z(!1)})},[J,$]),A("div",{className:"flex flex-col h-full",children:[A("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[A("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:Z?"Feedback sent":`Feedback — ${Y}`},void 0,!1,void 0,this),Q]},void 0,!0,void 0,this),Z&&A("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:[A("span",{className:"w-2 h-2 rounded-full bg-accent-green animate-pulse"},void 0,!1,void 0,this),A("span",{className:"text-[12px] font-body text-accent-green",children:"Waiting for next revision..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),A("div",{className:"flex-1 overflow-y-auto px-4",children:_?A("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"Loading..."},void 0,!1,void 0,this):X?A(N0,{text:X},void 0,!1,void 0,this):A("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 e3({sessionId:J,revision:$,label:Y,waitingForUpdate:Z,collapseButton:Q}){let{annotations:X,generalNote:q,activeAnnotationId:_,setActiveAnnotationId:z}=o(),{setActiveView:K}=y0(C1),G=X.length>0||q.trim().length>0,[U,H]=g1("feedback");if(!G)return A(n3,{sessionId:J,revision:$,label:Y,waitingForUpdate:Z,collapseButton:Q},void 0,!1,void 0,this);return A("div",{className:"flex flex-col h-full",children:[A("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[A("div",{className:"flex items-center gap-1 bg-bg-input rounded-md p-0.5",children:[A("button",{onClick:()=>H("feedback"),className:`px-2.5 py-1 rounded text-[11px] font-medium font-body transition-colors ${U==="feedback"?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Feedback"},void 0,!1,void 0,this),A("button",{onClick:()=>H("annotations"),className:`px-2.5 py-1 rounded text-[11px] font-medium font-body transition-colors flex items-center gap-1.5 ${U==="annotations"?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:["Annotations",A("span",{className:"inline-flex items-center justify-center min-w-[16px] h-[16px] px-1 rounded-full bg-border-subtle text-[10px] font-medium",children:X.length},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Q]},void 0,!0,void 0,this),Z&&A("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:[A("span",{className:"w-2 h-2 rounded-full bg-accent-green animate-pulse"},void 0,!1,void 0,this),A("span",{className:"text-[12px] font-body text-accent-green",children:"Waiting for next revision..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),U==="feedback"?A($$,{sessionId:J,revision:$},void 0,!1,void 0,this):A(J$,{annotations:X,generalNote:q,activeAnnotationId:_,setActiveAnnotationId:z,setActiveView:K},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function $$({sessionId:J,revision:$}){let[Y,Z]=g1(null),[Q,X]=g1(!0);return o0(()=>{X(!0),fetch(`/api/session/${J}/revision/${$}/feedback`).then((q)=>q.json()).then((q)=>{Z(q.feedback||null),X(!1)}).catch(()=>{Z(null),X(!1)})},[J,$]),A("div",{className:"flex-1 overflow-y-auto px-4",children:Q?A("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"Loading..."},void 0,!1,void 0,this):Y?A(N0,{text:Y},void 0,!1,void 0,this):A("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 J$({annotations:J,generalNote:$,activeAnnotationId:Y,setActiveAnnotationId:Z,setActiveView:Q}){let X=J.filter((W)=>W.filePath===Q1),q=J.filter((W)=>!W.filePath),_=J.filter((W)=>W.filePath&&W.filePath!==Q1),z={};for(let W of _){let L=W.filePath;if(!z[L])z[L]=[];z[L].push(W)}let K=(W)=>{Z(W),S1(W,!0)},G=(W)=>{Z(null),S1(W,!1)},U=(W)=>{if(W.id===Y)Z(null);else if(Z(W.id),W.filePath)Q({type:"file",path:W.filePath}),setTimeout(()=>{let L=s1(W);if(L)L.scrollIntoView({behavior:"smooth",block:"center"})},150)},H=(W)=>A("div",{className:`group/ann relative px-3 py-2.5 transition-colors duration-150 cursor-pointer ${Y===W.id?"bg-highlight-selected":"odd:bg-bg-elevated-half hover:bg-bg-input"}`,onMouseEnter:()=>K(W.id),onMouseLeave:()=>G(W.id),onClick:()=>U(W),children:[A("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:W.snippet.length>80?W.snippet.slice(0,80)+"...":W.snippet},void 0,!1,void 0,this),W.note.trim()&&A("div",{className:"text-[13px] font-body text-text-primary leading-relaxed",children:W.note},void 0,!1,void 0,this),A(m5,{images:W.images||[]},void 0,!1,void 0,this),A("div",{className:"absolute top-1.5 right-1.5 opacity-0 group-hover/ann:opacity-100 transition-opacity duration-100",children:A("button",{onClick:(L)=>{L.stopPropagation(),s0(W,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:A("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[A("circle",{cx:"12",cy:"12",r:"3"},void 0,!1,void 0,this),A("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)]},W.id,!0,void 0,this),F=[X,q,_].filter((W)=>W.length>0).length>1;return A(T0,{children:[A("div",{className:"flex-1 overflow-y-auto",children:[X.length>0&&A(T0,{children:[F&&A("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body px-3 mb-1 mt-1",children:"Agent Response"},void 0,!1,void 0,this),X.map(H)]},void 0,!0,void 0,this),q.length>0&&A(T0,{children:[F&&A("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),q.map(H)]},void 0,!0,void 0,this),Object.entries(z).map(([W,L])=>A("div",{children:[A("button",{onClick:()=>Q({type:"file",path:W}),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:W,children:[A(N1,{name:W.split("/").pop()||W,type:"file"},void 0,!1,void 0,this),A("span",{className:"truncate",children:W},void 0,!1,void 0,this)]},void 0,!0,void 0,this),L.map(H)]},W,!0,void 0,this))]},void 0,!0,void 0,this),$.trim()&&A("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:A("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 Y$({onPreview:J,onSubmit:$,collapseButton:Y}){let{annotations:Z,updateAnnotation:Q,removeAnnotation:X,addAnnotationImage:q,removeAnnotationImage:_,generalNote:z,setGeneralNote:K,activeAnnotationId:G,setActiveAnnotationId:U,responses:H,feedbackEntries:F}=o(),W=y0(s5),{setActiveView:L}=t3.useContext(C1),T=a5(null),B=a5(new Map),O=Z.filter((S)=>S.filePath===Q1),D=Z.filter((S)=>!S.filePath),R=Z.filter((S)=>S.filePath&&S.filePath!==Q1),P={};for(let S of R){let w=S.filePath;if(!P[w])P[w]=[];P[w].push(S)}o0(()=>{if(!G)return;let S=B.current.get(G);if(S)S.scrollIntoView({behavior:"smooth",block:"nearest"})},[G]);let k=i5((S)=>{U(S),S1(S,!0)},[U]),v=i5((S)=>{U(null),S1(S,!1)},[G]),g=Array.from(H.values()).some(a0),h=F.size>0,j=Z.length>0||z.trim().length>0||g||h,[V,C]=g1(null),I=(S)=>A("div",{ref:(w)=>{if(w)B.current.set(S.id,w);else B.current.delete(S.id)},className:`group/ann relative px-3 py-2.5 transition-colors duration-150 ${G===S.id?"bg-highlight-selected":"odd:bg-bg-elevated-half hover:bg-bg-input"}`,onMouseEnter:()=>k(S.id),onMouseLeave:()=>v(S.id),onClick:()=>{if(S.id===G)U(null);else if(U(S.id),S.filePath)L({type:"file",path:S.filePath}),setTimeout(()=>{let w=s1(S);if(w)w.scrollIntoView({behavior:"smooth",block:"center"})},150)},children:[A("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:S.snippet.length>80?S.snippet.slice(0,80)+"...":S.snippet},void 0,!1,void 0,this),A("div",{onClick:(w)=>w.stopPropagation(),children:A(Z0,{note:S.note,onNoteChange:(w)=>Q(S.id,w),images:S.images||[],onAddImage:(w)=>q(S.id,w),onRemoveImage:(w)=>_(S.id,w),sessionId:W,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),A("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:[A("button",{onClick:(w)=>{w.stopPropagation(),s0(S,L)},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:A("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[A("circle",{cx:"12",cy:"12",r:"3"},void 0,!1,void 0,this),A("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),A("button",{onClick:(w)=>{w.stopPropagation(),X(S.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:A("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[A("polyline",{points:"3 6 5 6 21 6"},void 0,!1,void 0,this),A("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)]},S.id,!0,void 0,this);return A("div",{className:"flex flex-col h-full",children:[A("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[A("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body flex items-center gap-2",children:["Annotations",Z.length>0&&A("span",{className:"inline-flex items-center justify-center min-w-[18px] h-[18px] px-1 rounded-full bg-border-subtle text-[10px] font-medium text-text-secondary",children:Z.length},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Y]},void 0,!0,void 0,this),A("div",{ref:T,className:"flex-1 overflow-y-auto",children:[Z.length===0&&A("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),O.length>0&&A(T0,{children:[(D.length>0||R.length>0)&&A("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),O.map(I)]},void 0,!0,void 0,this),D.length>0&&(O.length>0||R.length>0)&&A("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),D.map(I),Object.entries(P).map(([S,w])=>A("div",{children:[A("button",{onClick:()=>L({type:"file",path:S}),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:S,children:[A(N1,{name:S.split("/").pop()||S,type:"file"},void 0,!1,void 0,this),A("span",{className:"truncate",children:S},void 0,!1,void 0,this)]},void 0,!0,void 0,this),w.map(I)]},S,!0,void 0,this))]},void 0,!0,void 0,this),A("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:A("textarea",{value:z,onChange:(S)=>K(S.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:(S)=>d1(S.target,40),ref:(S)=>{if(S)d1(S,40)}},void 0,!1,void 0,this)},void 0,!1,void 0,this),V&&A("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:[A("span",{children:V},void 0,!1,void 0,this),A("button",{onClick:()=>{C(null);let S=i1(Z,z,H,F);$(S)},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),A("div",{className:"px-4 py-3 border-t border-border-subtle flex-shrink-0",children:j?A("div",{className:"flex gap-2",children:[A("button",{onClick:J,className:"flex-1 py-2 rounded-lg font-body text-[13px] font-medium transition-all bg-border-subtle text-text-secondary hover:bg-border-medium hover:text-text-primary",children:"Preview"},void 0,!1,void 0,this),A("button",{onClick:()=>{let S=W0(H,F);if(S.length>0){C(`Please answer: ${S.join(", ")}`);return}C(null);let w=i1(Z,z,H,F);$(w)},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):A("button",{onClick:()=>$("No feedback — looks good."),className:"w-full py-2 rounded-lg font-body text-[13px] font-medium border border-border-medium text-text-secondary hover:text-text-primary hover:border-border-hover hover:bg-bg-input transition-all",children:"Submit without feedback"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{useEffect as Q$,useState as o5,useContext as t5,useMemo as Z$}from"react";import{SessionContext as q$}from"#canvas/runtime";import{jsxDEV as x,Fragment as n0}from"react/jsx-dev-runtime";function n5({embedded:J}={}){let $=t5(q$),{annotations:Y,addAnnotation:Z}=o(),{setActiveView:Q}=t5(C1),[X,q]=o5(!1),[_,z]=o5({}),{annCountMap:K,annotatedFiles:G}=Z$(()=>{let O=new Map;for(let D of Y)if(D.filePath&&D.filePath!==Q1)O.set(D.filePath,(O.get(D.filePath)||0)+1);return{annCountMap:O,annotatedFiles:[...O.keys()]}},[Y]),U=async(O)=>{let R=await(await fetch(`/api/tree?session=${$}&path=${encodeURIComponent(O)}`)).json();if(R.entries)z((P)=>({...P,[O]:{entries:R.entries,expanded:!0,loaded:!0}}))};Q$(()=>{if(!X&&!_[""])U("")},[X]);let H=(O)=>{if(_[O]?.loaded)z((D)=>({...D,[O]:{...D[O],expanded:!D[O].expanded}}));else U(O)},F=(O)=>{Q({type:"file",path:O})},W=async(O)=>{let R=await(await fetch(`/api/file?session=${$}&path=${encodeURIComponent(O)}`)).json();if(!R.error){let P=R.content.split(`
66
+ > `)}`);else{let X=Y.split(`
67
+ `);$.push(`> ${X[0]}`),$.push(`> ... (${X.length} lines)`),$.push(`> ${X[X.length-1]}`)}}if(J.note.trim())$.push(""),$.push(J.note.trim());if(J.images?.length){$.push("");for(let q of J.images)$.push(`![screenshot](${q})`)}return $.push(""),$.join(`
68
+ `)}function d3(J){let $={label:"",annotations:[],children:new Map};for(let Y of J){let Z=Y.context?.hierarchy||[],Q=$;for(let q of Z){if(!Q.children.has(q))Q.children.set(q,{label:q,annotations:[],children:new Map});Q=Q.children.get(q)}Q.annotations.push(Y)}return $}function d5(J,$=0){let Y=[];for(let Z of J.annotations)Y.push(l0(Z));for(let[,Z]of J.children){let Q=$===0?"###":"####";Y.push(`${Q} ${Z.label}`),Y.push(""),Y.push(d5(Z,$+1))}return Y.join(`
69
+ `)}import{SessionContext as s5}from"#canvas/runtime";import{useEffect as i0,useState as F0,useRef as r3,useMemo as l3}from"react";import{jsxDEV as s}from"react/jsx-dev-runtime";function r5({open:J,onClose:$,onSubmit:Y}){let{annotations:Z,generalNote:Q,responses:q,feedbackEntries:X}=o(),[_,z]=F0(""),[K,G]=F0(!1),[U,H]=F0(!1),[F,W]=F0(null),L=r3(null);if(i0(()=>{if(!J){G(!1),H(!1),W(null);return}if(K)return;z(i1(Z,Q,q,X))},[Z,Q,q,X,K,J]),i0(()=>{if(J&&U&&L.current)L.current.focus()},[J,U]),i0(()=>{if(!J)return;let B=(O)=>{if(O.key==="Escape")$()};return window.addEventListener("keydown",B),()=>window.removeEventListener("keydown",B)},[J,$]),!J)return null;let y=_.trim().length>0;return s("div",{className:"fixed inset-0 z-50 bg-black/50 backdrop-blur-sm flex items-center justify-center p-8",onClick:$,children:s("div",{className:"bg-bg-surface border border-border-medium rounded-xl shadow-lg w-full max-w-2xl flex flex-col",style:{height:"80vh"},onClick:(B)=>B.stopPropagation(),children:[s("div",{className:"flex items-center justify-between px-5 py-3 border-b border-border-subtle flex-shrink-0",children:[s("div",{className:"flex items-center gap-3",children:[s("span",{className:"text-[13px] font-medium text-text-primary font-body",children:"Response preview"},void 0,!1,void 0,this),K&&s("button",{onClick:()=>{G(!1),H(!1)},className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body",children:"Reset"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),s("div",{className:"flex items-center gap-2",children:[s("div",{className:"flex items-center bg-bg-base rounded-md p-0.5",children:[s("button",{onClick:()=>H(!1),className:`px-2.5 py-1 rounded text-[11px] font-body font-medium transition-colors ${!U?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Preview"},void 0,!1,void 0,this),s("button",{onClick:()=>H(!0),className:`px-2.5 py-1 rounded text-[11px] font-body font-medium transition-colors ${U?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Edit"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),s("button",{onClick:$,className:"text-text-tertiary hover:text-text-secondary w-7 h-7 flex items-center justify-center rounded-md hover:bg-border-subtle transition-colors",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),U?s("textarea",{ref:L,value:_,onChange:(B)=>{z(B.target.value),G(!0)},className:"flex-1 w-full bg-bg-base p-5 text-[13px] font-mono text-text-code resize-none focus:outline-none leading-relaxed placeholder:text-text-disabled",placeholder:"Your feedback will appear here..."},void 0,!1,void 0,this):s("div",{className:"flex-1 overflow-y-auto p-5",children:s(N0,{text:_},void 0,!1,void 0,this)},void 0,!1,void 0,this),F&&s("div",{className:"px-5 py-2 text-[12px] text-accent-red font-body border-t border-border-subtle flex-shrink-0 flex items-center justify-between gap-2",children:[s("span",{children:F},void 0,!1,void 0,this),s("button",{onClick:()=>{W(null),Y(_)},className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body whitespace-nowrap underline",children:"Submit anyway"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),s("div",{className:"flex justify-end gap-2 px-5 py-3 border-t border-border-subtle flex-shrink-0",children:[s("button",{onClick:$,className:"px-4 py-2 rounded-lg text-[13px] font-body text-text-tertiary hover:text-text-secondary transition-colors",children:"Cancel"},void 0,!1,void 0,this),s("button",{onClick:()=>{let B=W0(q,X);if(B.length>0){W(`Please answer: ${B.join(", ")}`);return}W(null),Y(_)},disabled:!y,className:`px-6 py-2 rounded-lg font-body text-[13px] font-medium transition-all ${y?"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 a3=/!\[([^\]]*)\]\((\/tmp\/agent-canvas\/uploads\/([^)]+))\)/g;function i3(J){return J.replace(a3,($,Y,Z,Q)=>`![${Y}](/api/uploads/${Q})`)}function N0({text:J}){let $=l3(()=>r.parse(i3(J),{async:!1}),[J]);return s("div",{className:"prose-canvas font-body text-body text-text-primary leading-relaxed",dangerouslySetInnerHTML:{__html:$}},void 0,!1,void 0,this)}import{jsxDEV as j1}from"react/jsx-dev-runtime";var s3={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"},o3={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 N1({name:J,type:$,expanded:Y,className:Z=""}){if($==="dir")return j1("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",className:`flex-shrink-0 ${Z}`,children:Y?j1("path",{d:"M1.5 3.5h5l1.5 1.5h6.5v8h-13z",style:{fill:"var(--color-folder-fill-active)",stroke:"var(--color-folder-stroke-active)"},strokeWidth:"1"},void 0,!1,void 0,this):j1("path",{d:"M1.5 3.5h5l1.5 1.5h6.5v8h-13z",style:{fill:"var(--color-folder-fill)",stroke:"var(--color-folder-stroke)"},strokeWidth:"1"},void 0,!1,void 0,this)},void 0,!1,void 0,this);let Q=J.includes(".")?J.split(".").pop().toLowerCase():"",q=s3[Q]||"#6b6560",X=o3[Q];return j1("svg",{width:"14",height:"14",viewBox:"0 0 16 16",className:`flex-shrink-0 ${Z}`,children:[j1("path",{d:"M2 1.5h8l3.5 3.5v9.5a1 1 0 01-1 1H3a1 1 0 01-1-1v-12a1 1 0 011-1z",fill:q,opacity:"0.85"},void 0,!1,void 0,this),j1("path",{d:"M10 1.5v2.5a1 1 0 001 1h2.5",fill:"none",stroke:"white",strokeWidth:"0.5",opacity:"0.5"},void 0,!1,void 0,this),X&&j1("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 t3(J){let $=J.getAttribute("data-md");if($==="item"){let Y=J.getAttribute("data-md-label");return Y?`[Item] ${Y}`:null}if($==="section"){let Y=J.getAttribute("data-md-title");return Y?`[Section] ${Y}`:null}if($==="callout"){let Y=J.getAttribute("data-md-type")||"info",Z=J.textContent?.trim().slice(0,60)||"Callout";return`[Callout:${Y}] ${Z}`}if($==="note")return`[Note] ${J.textContent?.trim().slice(0,60)||"Note"}`;if(J.tagName==="TR"){let Y=Array.from(J.querySelectorAll("td")).map((Z)=>Z.textContent?.trim()).filter(Boolean);return Y.length?`[Row] ${Y.join(" | ")}`:null}if($==="checklist-item"){let Y=J.getAttribute("data-md-label");return Y?`[Checklist] ${Y}`:null}if($==="choice-option"||$==="multichoice-option"){let Y=J.getAttribute("data-md-label");return Y?`[Option] ${Y}`:null}if($==="userinput"){let Y=J.getAttribute("data-md-label");return Y?`[Input] ${Y}`:null}if($==="rangeinput"){let Y=J.getAttribute("data-md-label");return Y?`[Range] ${Y}`:null}if($==="image"){let Y=J.getAttribute("data-md-src");return Y?`[Image] ${Y}`:null}return null}function s1(J){let $=document.querySelector(`[data-annotation-id="${J.id}"]`);if($)return $;if(J.snippet.startsWith("[")){for(let Y 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(t3(Y)===J.snippet)return Y}return null}function l5(J){J.classList.remove("ann-flash"),J.offsetWidth,J.classList.add("ann-flash"),J.addEventListener("animationend",()=>{J.classList.remove("ann-flash")},{once:!0})}function s0(J,$){if(J.filePath)$({type:"file",path:J.filePath}),setTimeout(()=>{let Y=s1(J);if(Y)Y.scrollIntoView({behavior:"smooth",block:"center"}),l5(Y)},150);else{let Y=s1(J);if(Y)Y.scrollIntoView({behavior:"smooth",block:"center"}),l5(Y)}}import{jsxDEV as A,Fragment as T0}from"react/jsx-dev-runtime";function t0({onPreview:J,onSubmit:$,collapseButton:Y}){let{isReadOnly:Z,selectedRevision:Q,currentRevision:q,revisions:X}=y0(v1),_=y0(s5),z=Z&&Q===q,G=X.find((U)=>U.revision===Q)?.label||`Round ${Q}`;if(Z)return A($$,{sessionId:_,revision:Q,label:G,waitingForUpdate:z,collapseButton:Y},void 0,!1,void 0,this);return A(Q$,{onPreview:J,onSubmit:$,collapseButton:Y},void 0,!1,void 0,this)}function e3({sessionId:J,revision:$,label:Y,waitingForUpdate:Z,collapseButton:Q}){let[q,X]=g1(null),[_,z]=g1(!0);return o0(()=>{z(!0),fetch(`/api/session/${J}/revision/${$}/feedback`).then((K)=>K.json()).then((K)=>{X(K.feedback||null),z(!1)}).catch(()=>{X(null),z(!1)})},[J,$]),A("div",{className:"flex flex-col h-full",children:[A("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[A("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:Z?"Feedback sent":`Feedback — ${Y}`},void 0,!1,void 0,this),Q]},void 0,!0,void 0,this),Z&&A("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:[A("span",{className:"w-2 h-2 rounded-full bg-accent-green animate-pulse"},void 0,!1,void 0,this),A("span",{className:"text-[12px] font-body text-accent-green",children:"Waiting for next revision..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),A("div",{className:"flex-1 overflow-y-auto px-4",children:_?A("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"Loading..."},void 0,!1,void 0,this):q?A(N0,{text:q},void 0,!1,void 0,this):A("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 $$({sessionId:J,revision:$,label:Y,waitingForUpdate:Z,collapseButton:Q}){let{annotations:q,generalNote:X,activeAnnotationId:_,setActiveAnnotationId:z}=o(),{setActiveView:K}=y0(C1),G=q.length>0||X.trim().length>0,[U,H]=g1("feedback");if(!G)return A(e3,{sessionId:J,revision:$,label:Y,waitingForUpdate:Z,collapseButton:Q},void 0,!1,void 0,this);return A("div",{className:"flex flex-col h-full",children:[A("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[A("div",{className:"flex items-center gap-1 bg-bg-input rounded-md p-0.5",children:[A("button",{onClick:()=>H("feedback"),className:`px-2.5 py-1 rounded text-[11px] font-medium font-body transition-colors ${U==="feedback"?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Feedback"},void 0,!1,void 0,this),A("button",{onClick:()=>H("annotations"),className:`px-2.5 py-1 rounded text-[11px] font-medium font-body transition-colors flex items-center gap-1.5 ${U==="annotations"?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:["Annotations",A("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:q.length},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Q]},void 0,!0,void 0,this),Z&&A("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:[A("span",{className:"w-2 h-2 rounded-full bg-accent-green animate-pulse"},void 0,!1,void 0,this),A("span",{className:"text-[12px] font-body text-accent-green",children:"Waiting for next revision..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),U==="feedback"?A(J$,{sessionId:J,revision:$},void 0,!1,void 0,this):A(Y$,{annotations:q,generalNote:X,activeAnnotationId:_,setActiveAnnotationId:z,setActiveView:K},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function J$({sessionId:J,revision:$}){let[Y,Z]=g1(null),[Q,q]=g1(!0);return o0(()=>{q(!0),fetch(`/api/session/${J}/revision/${$}/feedback`).then((X)=>X.json()).then((X)=>{Z(X.feedback||null),q(!1)}).catch(()=>{Z(null),q(!1)})},[J,$]),A("div",{className:"flex-1 overflow-y-auto px-4",children:Q?A("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"Loading..."},void 0,!1,void 0,this):Y?A(N0,{text:Y},void 0,!1,void 0,this):A("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 Y$({annotations:J,generalNote:$,activeAnnotationId:Y,setActiveAnnotationId:Z,setActiveView:Q}){let q=J.filter((W)=>W.filePath===Q1),X=J.filter((W)=>!W.filePath),_=J.filter((W)=>W.filePath&&W.filePath!==Q1),z={};for(let W of _){let L=W.filePath;if(!z[L])z[L]=[];z[L].push(W)}let K=(W)=>{Z(W),S1(W,!0)},G=(W)=>{Z(null),S1(W,!1)},U=(W)=>{if(W.id===Y)Z(null);else if(Z(W.id),W.filePath)Q({type:"file",path:W.filePath}),setTimeout(()=>{let L=s1(W);if(L)L.scrollIntoView({behavior:"smooth",block:"center"})},150)},H=(W)=>A("div",{className:`group/ann relative px-3 py-2.5 transition-colors duration-150 cursor-pointer ${Y===W.id?"bg-highlight-selected":"odd:bg-bg-elevated-half hover:bg-bg-input"}`,onMouseEnter:()=>K(W.id),onMouseLeave:()=>G(W.id),onClick:()=>U(W),children:[A("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:W.snippet.length>80?W.snippet.slice(0,80)+"...":W.snippet},void 0,!1,void 0,this),W.note.trim()&&A("div",{className:"text-[13px] font-body text-text-primary leading-relaxed",children:W.note},void 0,!1,void 0,this),A(m5,{images:W.images||[]},void 0,!1,void 0,this),A("div",{className:"absolute top-1.5 right-1.5 opacity-0 group-hover/ann:opacity-100 transition-opacity duration-100",children:A("button",{onClick:(L)=>{L.stopPropagation(),s0(W,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:A("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[A("circle",{cx:"12",cy:"12",r:"3"},void 0,!1,void 0,this),A("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)]},W.id,!0,void 0,this),F=[q,X,_].filter((W)=>W.length>0).length>1;return A(T0,{children:[A("div",{className:"flex-1 overflow-y-auto",children:[q.length>0&&A(T0,{children:[F&&A("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(H)]},void 0,!0,void 0,this),X.length>0&&A(T0,{children:[F&&A("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(H)]},void 0,!0,void 0,this),Object.entries(z).map(([W,L])=>A("div",{children:[A("button",{onClick:()=>Q({type:"file",path:W}),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:W,children:[A(N1,{name:W.split("/").pop()||W,type:"file"},void 0,!1,void 0,this),A("span",{className:"truncate",children:W},void 0,!1,void 0,this)]},void 0,!0,void 0,this),L.map(H)]},W,!0,void 0,this))]},void 0,!0,void 0,this),$.trim()&&A("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:A("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 Q$({onPreview:J,onSubmit:$,collapseButton:Y}){let{annotations:Z,updateAnnotation:Q,removeAnnotation:q,addAnnotationImage:X,removeAnnotationImage:_,generalNote:z,setGeneralNote:K,activeAnnotationId:G,setActiveAnnotationId:U,responses:H,feedbackEntries:F}=o(),W=y0(s5),{setActiveView:L}=n3.useContext(C1),y=a5(null),B=a5(new Map),O=Z.filter((S)=>S.filePath===Q1),D=Z.filter((S)=>!S.filePath),R=Z.filter((S)=>S.filePath&&S.filePath!==Q1),P={};for(let S of R){let w=S.filePath;if(!P[w])P[w]=[];P[w].push(S)}o0(()=>{if(!G)return;let S=B.current.get(G);if(S)S.scrollIntoView({behavior:"smooth",block:"nearest"})},[G]);let k=i5((S)=>{U(S),S1(S,!0)},[U]),v=i5((S)=>{U(null),S1(S,!1)},[G]),g=Array.from(H.values()).some(a0),h=F.size>0,j=Z.length>0||z.trim().length>0||g||h,[V,C]=g1(null),I=(S)=>A("div",{ref:(w)=>{if(w)B.current.set(S.id,w);else B.current.delete(S.id)},className:`group/ann relative px-3 py-2.5 transition-colors duration-150 ${G===S.id?"bg-highlight-selected":"odd:bg-bg-elevated-half hover:bg-bg-input"}`,onMouseEnter:()=>k(S.id),onMouseLeave:()=>v(S.id),onClick:()=>{if(S.id===G)U(null);else if(U(S.id),S.filePath)L({type:"file",path:S.filePath}),setTimeout(()=>{let w=s1(S);if(w)w.scrollIntoView({behavior:"smooth",block:"center"})},150)},children:[A("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:S.snippet.length>80?S.snippet.slice(0,80)+"...":S.snippet},void 0,!1,void 0,this),A("div",{onClick:(w)=>w.stopPropagation(),children:A(Z0,{note:S.note,onNoteChange:(w)=>Q(S.id,w),images:S.images||[],onAddImage:(w)=>X(S.id,w),onRemoveImage:(w)=>_(S.id,w),sessionId:W,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),A("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:[A("button",{onClick:(w)=>{w.stopPropagation(),s0(S,L)},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:A("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[A("circle",{cx:"12",cy:"12",r:"3"},void 0,!1,void 0,this),A("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),A("button",{onClick:(w)=>{w.stopPropagation(),q(S.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:A("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[A("polyline",{points:"3 6 5 6 21 6"},void 0,!1,void 0,this),A("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)]},S.id,!0,void 0,this);return A("div",{className:"flex flex-col h-full",children:[A("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[A("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body flex items-center gap-2",children:["Annotations",Z.length>0&&A("span",{className:"inline-flex items-center justify-center min-w-[18px] h-[18px] px-1 rounded-full bg-border-subtle text-[10px] font-medium text-text-secondary",children:Z.length},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Y]},void 0,!0,void 0,this),A("div",{ref:y,className:"flex-1 overflow-y-auto",children:[Z.length===0&&A("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),O.length>0&&A(T0,{children:[(D.length>0||R.length>0)&&A("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),O.map(I)]},void 0,!0,void 0,this),D.length>0&&(O.length>0||R.length>0)&&A("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),D.map(I),Object.entries(P).map(([S,w])=>A("div",{children:[A("button",{onClick:()=>L({type:"file",path:S}),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:S,children:[A(N1,{name:S.split("/").pop()||S,type:"file"},void 0,!1,void 0,this),A("span",{className:"truncate",children:S},void 0,!1,void 0,this)]},void 0,!0,void 0,this),w.map(I)]},S,!0,void 0,this))]},void 0,!0,void 0,this),A("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:A("textarea",{value:z,onChange:(S)=>K(S.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:(S)=>d1(S.target,40),ref:(S)=>{if(S)d1(S,40)}},void 0,!1,void 0,this)},void 0,!1,void 0,this),V&&A("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:[A("span",{children:V},void 0,!1,void 0,this),A("button",{onClick:()=>{C(null);let S=i1(Z,z,H,F);$(S)},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),A("div",{className:"px-4 py-3 border-t border-border-subtle flex-shrink-0",children:j?A("div",{className:"flex gap-2",children:[A("button",{onClick:J,className:"flex-1 py-2 rounded-lg font-body text-[13px] font-medium transition-all bg-border-subtle text-text-secondary hover:bg-border-medium hover:text-text-primary",children:"Preview"},void 0,!1,void 0,this),A("button",{onClick:()=>{let S=W0(H,F);if(S.length>0){C(`Please answer: ${S.join(", ")}`);return}C(null);let w=i1(Z,z,H,F);$(w)},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):A("button",{onClick:()=>$("No feedback — looks good."),className:"w-full py-2 rounded-lg font-body text-[13px] font-medium border border-border-medium text-text-secondary hover:text-text-primary hover:border-border-hover hover:bg-bg-input transition-all",children:"Submit without feedback"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{useEffect as Z$,useState as o5,useContext as t5,useMemo as X$}from"react";import{SessionContext as q$}from"#canvas/runtime";import{jsxDEV as x,Fragment as n0}from"react/jsx-dev-runtime";function n5({embedded:J}={}){let $=t5(q$),{annotations:Y,addAnnotation:Z}=o(),{setActiveView:Q}=t5(C1),[q,X]=o5(!1),[_,z]=o5({}),{annCountMap:K,annotatedFiles:G}=X$(()=>{let O=new Map;for(let D of Y)if(D.filePath&&D.filePath!==Q1)O.set(D.filePath,(O.get(D.filePath)||0)+1);return{annCountMap:O,annotatedFiles:[...O.keys()]}},[Y]),U=async(O)=>{let R=await(await fetch(`/api/tree?session=${$}&path=${encodeURIComponent(O)}`)).json();if(R.entries)z((P)=>({...P,[O]:{entries:R.entries,expanded:!0,loaded:!0}}))};Z$(()=>{if(!q&&!_[""])U("")},[q]);let H=(O)=>{if(_[O]?.loaded)z((D)=>({...D,[O]:{...D[O],expanded:!D[O].expanded}}));else U(O)},F=(O)=>{Q({type:"file",path:O})},W=async(O)=>{let R=await(await fetch(`/api/file?session=${$}&path=${encodeURIComponent(O)}`)).json();if(!R.error){let P=R.content.split(`
70
70
  `).slice(0,3).join(`
71
71
  `)+(R.content.split(`
72
72
  `).length>3?`
73
- ...`:"");Z(P,"Include this file for context",O)}},L=async(O)=>{let D=[];if(_[O]?.loaded)D=_[O].entries;else{let P=await(await fetch(`/api/tree?session=${$}&path=${encodeURIComponent(O)}`)).json();if(P.entries)D=P.entries}await Promise.all(D.filter((R)=>R.type==="file").map((R)=>W(O?`${O}/${R.name}`:R.name)))},T=(O)=>K.get(O)||0,B=(O,D=0)=>{let R=_[O];if(!R?.expanded)return null;return R.entries.map((P)=>{let k=O?`${O}/${P.name}`:P.name,v=T(k);return x("div",{children:[x("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+D*16}px`,paddingRight:"8px"},children:P.type==="dir"?x(n0,{children:[x("span",{onClick:()=>H(k),className:"flex items-center gap-1.5 flex-1 text-text-secondary hover:text-text-primary cursor-pointer truncate",children:[x(N1,{name:P.name,type:"dir",expanded:_[k]?.expanded},void 0,!1,void 0,this),x("span",{className:"truncate",children:P.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this),x("button",{onClick:(g)=>{g.stopPropagation(),L(k)},className:"text-[11px] text-text-tertiary hover:text-text-secondary opacity-0 group-hover/item:opacity-100 transition-opacity px-1 flex-shrink-0",title:"Add all files in folder",children:"+"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):x(n0,{children:[x("span",{onClick:()=>F(k),className:`flex-1 truncate cursor-pointer flex items-center gap-1.5 ${v>0?"text-text-primary":"text-text-secondary hover:text-text-primary"}`,children:[x(N1,{name:P.name,type:"file"},void 0,!1,void 0,this),x("span",{className:"truncate",children:P.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this),x("div",{className:"flex items-center gap-1 flex-shrink-0 ml-1",children:[v>0&&x("span",{className:"text-[10px] font-medium bg-badge-bg text-accent-amber px-1.5 py-px rounded-full min-w-[18px] text-center",children:v},void 0,!1,void 0,this),x("button",{onClick:(g)=>{g.stopPropagation(),W(k)},className:"text-[11px] text-text-tertiary hover:text-text-secondary opacity-0 group-hover/item:opacity-100 transition-opacity px-1",title:"Add file to context",children:"+"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),P.type==="dir"&&B(k,D+1)]},k,!0,void 0,this)})};if(J)return x(n0,{children:[x("div",{className:"flex items-center justify-between px-4 pt-3 pb-2 flex-shrink-0",children:x("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),x("div",{className:"flex-1 overflow-y-auto",children:B("")},void 0,!1,void 0,this),G.length>0&&x("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:[x("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body mb-1.5",children:"Referenced"},void 0,!1,void 0,this),G.map((O)=>x("div",{onClick:()=>F(O),className:"flex items-center justify-between text-[12px] font-body text-text-secondary hover:text-text-primary cursor-pointer py-0.5",children:[x("span",{className:"truncate",children:O.split("/").pop()},void 0,!1,void 0,this),x("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:T(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(X)return x("div",{className:"hidden lg:flex w-8 border-r border-border-subtle bg-bg-surface flex-col items-center flex-shrink-0",children:x("button",{onClick:()=>q(!1),className:"mt-3 p-1 text-text-tertiary hover:text-text-secondary transition-colors",children:x("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:x("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 x("div",{className:"hidden lg:flex w-60 border-r border-border-subtle bg-bg-surface flex-col flex-shrink-0 overflow-hidden",children:[x("div",{className:"flex items-center justify-between px-4 pt-4 pb-3 flex-shrink-0",children:[x("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:"Files"},void 0,!1,void 0,this),x("button",{onClick:()=>q(!0),className:"text-text-tertiary hover:text-text-secondary transition-colors p-0.5",children:x("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:x("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),x("div",{className:"flex-1 overflow-y-auto",children:B("")},void 0,!1,void 0,this),G.length>0&&x("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:[x("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body mb-1.5",children:"Referenced"},void 0,!1,void 0,this),G.map((O)=>x("div",{onClick:()=>F(O),className:"flex items-center justify-between text-[12px] font-body text-text-secondary hover:text-text-primary cursor-pointer py-0.5",children:[x("span",{className:"truncate",children:O.split("/").pop()},void 0,!1,void 0,this),x("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:T(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 u1,useContext as X$,useCallback as z$,useRef as L0,useMemo as $2}from"react";import{SessionContext as _$}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 T1}from"react/jsx-dev-runtime";function J2(J){let $=J instanceof HTMLElement?J:J.parentElement;while($){if($.hasAttribute("data-line-num"))return $;$=$.parentElement}return null}function K$(J){let $=J.toString().trim(),Y=J2(J.startContainer),Z=J2(J.endContainer),Q=Y?parseInt(Y.getAttribute("data-line-num"),10):void 0,X=Z?parseInt(Z.getAttribute("data-line-num"),10):void 0,q="",_="";if($.length<30&&Y&&Y===Z){let z=Y.querySelector("code");if(z){let K=z.textContent||"",G=K.indexOf($);if(G>=0)q=K.slice(0,G).trimStart(),_=K.slice(G+$.length).trimEnd()}}return{before:q,after:_,hierarchy:[],lineStart:Q,lineEnd:X}}function Y2({path:J}){let $=X$(_$),{annotations:Y,addAnnotationWithId:Z,activeAnnotationId:Q,setActiveAnnotationId:X}=o(),[q,_]=u1(null),[z,K]=u1("text"),[G,U]=u1(!0),[H,F]=u1(null),W=L0(null),[L,T]=u1(null),[B,O]=u1(null),D=L0(null),R=L0(null),P=L0([]),k=Y.filter((w)=>w.filePath===J),v=W.current?.closest("#plan-scroll-container"),{popovers:g,openCreatePopover:h}=w1({containerRef:W,restoreKey:`${q}:${J}`,restoreAnnotations:k,extractContext:K$,filePath:J,scrollContainer:v});e5(()=>{U(!0),F(null),fetch(`/api/file?session=${$}&path=${encodeURIComponent(J)}`).then((w)=>w.json()).then((w)=>{if(w.error)F(w.error),U(!1);else _(w.content),K(w.language||"text"),U(!1)}).catch(()=>{F("Failed to fetch file"),U(!1)})},[$,J]);let j=z$((w,N)=>{w.preventDefault(),D.current=N,R.current=N,T(N),O(N)},[]);e5(()=>{let w=(b)=>{if(D.current===null)return;let f=b.target.closest("[data-line-num]");if(f){let u=parseInt(f.getAttribute("data-line-num"),10);R.current=u,O(u)}},N=()=>{let b=D.current;if(b===null)return;D.current=null;let f=R.current??b,u=Math.min(b,f),p=Math.max(b,f),i=P.current.slice(u-1,p).join(`
74
- `);if(!i.trim()){T(null),O(null);return}let M=`__pending_${Date.now()}`,m={before:"",after:"",hierarchy:[],lineStart:u,lineEnd:p};if(W.current){let l=W.current.querySelectorAll("[data-line-num]"),Z1=l[u-1],q5=l[p-1];if(Z1&&q5){let b0=Z1.querySelector("code"),w0=q5.querySelector("code");if(b0&&w0)try{let A0=document.createRange();A0.setStartBefore(b0.firstChild||b0),A0.setEndAfter(w0.lastChild||w0),b1(A0,M)}catch{}}let X5=l[p-1];if(X5)h(X5,M,i,m)}T(null),O(null)};return document.addEventListener("mousemove",w),document.addEventListener("mouseup",N),()=>{document.removeEventListener("mousemove",w),document.removeEventListener("mouseup",N)}},[]);let V=$2(()=>{if(!q)return null;let w=window.hljs;if(!w)return null;let N=J.split(".").pop()||"",b=O0[N];try{return(b?w.highlight(q,{language:b}):w.highlightAuto(q)).value.split(`
75
- `)}catch{return null}},[q,J]);if(G)return T1("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-[13px]",children:["Loading ",J,"..."]},void 0,!0,void 0,this);if(H)return T1("div",{className:"p-8 text-accent-red font-body text-[13px]",children:H},void 0,!1,void 0,this);if(!q)return null;let C=q.split(`
76
- `);P.current=C;let I=$2(()=>{if(L===null)return null;let w=B??L;return{start:Math.min(L,w),end:Math.max(L,w)}},[L,B]),S=()=>{let w=q.split(`
73
+ ...`:"");Z(P,"Include this file for context",O)}},L=async(O)=>{let D=[];if(_[O]?.loaded)D=_[O].entries;else{let P=await(await fetch(`/api/tree?session=${$}&path=${encodeURIComponent(O)}`)).json();if(P.entries)D=P.entries}await Promise.all(D.filter((R)=>R.type==="file").map((R)=>W(O?`${O}/${R.name}`:R.name)))},y=(O)=>K.get(O)||0,B=(O,D=0)=>{let R=_[O];if(!R?.expanded)return null;return R.entries.map((P)=>{let k=O?`${O}/${P.name}`:P.name,v=y(k);return x("div",{children:[x("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+D*16}px`,paddingRight:"8px"},children:P.type==="dir"?x(n0,{children:[x("span",{onClick:()=>H(k),className:"flex items-center gap-1.5 flex-1 text-text-secondary hover:text-text-primary cursor-pointer truncate",children:[x(N1,{name:P.name,type:"dir",expanded:_[k]?.expanded},void 0,!1,void 0,this),x("span",{className:"truncate",children:P.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this),x("button",{onClick:(g)=>{g.stopPropagation(),L(k)},className:"text-[11px] text-text-tertiary hover:text-text-secondary opacity-0 group-hover/item:opacity-100 transition-opacity px-1 flex-shrink-0",title:"Add all files in folder",children:"+"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):x(n0,{children:[x("span",{onClick:()=>F(k),className:`flex-1 truncate cursor-pointer flex items-center gap-1.5 ${v>0?"text-text-primary":"text-text-secondary hover:text-text-primary"}`,children:[x(N1,{name:P.name,type:"file"},void 0,!1,void 0,this),x("span",{className:"truncate",children:P.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this),x("div",{className:"flex items-center gap-1 flex-shrink-0 ml-1",children:[v>0&&x("span",{className:"text-[10px] font-medium bg-badge-bg text-accent-amber px-1.5 py-px rounded-full min-w-[18px] text-center",children:v},void 0,!1,void 0,this),x("button",{onClick:(g)=>{g.stopPropagation(),W(k)},className:"text-[11px] text-text-tertiary hover:text-text-secondary opacity-0 group-hover/item:opacity-100 transition-opacity px-1",title:"Add file to context",children:"+"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),P.type==="dir"&&B(k,D+1)]},k,!0,void 0,this)})};if(J)return x(n0,{children:[x("div",{className:"flex items-center justify-between px-4 pt-3 pb-2 flex-shrink-0",children:x("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),x("div",{className:"flex-1 overflow-y-auto",children:B("")},void 0,!1,void 0,this),G.length>0&&x("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:[x("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body mb-1.5",children:"Referenced"},void 0,!1,void 0,this),G.map((O)=>x("div",{onClick:()=>F(O),className:"flex items-center justify-between text-[12px] font-body text-text-secondary hover:text-text-primary cursor-pointer py-0.5",children:[x("span",{className:"truncate",children:O.split("/").pop()},void 0,!1,void 0,this),x("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:y(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 x("div",{className:"hidden lg:flex w-8 border-r border-border-subtle bg-bg-surface flex-col items-center flex-shrink-0",children:x("button",{onClick:()=>X(!1),className:"mt-3 p-1 text-text-tertiary hover:text-text-secondary transition-colors",children:x("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:x("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 x("div",{className:"hidden lg:flex w-60 border-r border-border-subtle bg-bg-surface flex-col flex-shrink-0 overflow-hidden",children:[x("div",{className:"flex items-center justify-between px-4 pt-4 pb-3 flex-shrink-0",children:[x("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:"Files"},void 0,!1,void 0,this),x("button",{onClick:()=>X(!0),className:"text-text-tertiary hover:text-text-secondary transition-colors p-0.5",children:x("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:x("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),x("div",{className:"flex-1 overflow-y-auto",children:B("")},void 0,!1,void 0,this),G.length>0&&x("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:[x("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body mb-1.5",children:"Referenced"},void 0,!1,void 0,this),G.map((O)=>x("div",{onClick:()=>F(O),className:"flex items-center justify-between text-[12px] font-body text-text-secondary hover:text-text-primary cursor-pointer py-0.5",children:[x("span",{className:"truncate",children:O.split("/").pop()},void 0,!1,void 0,this),x("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:y(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 u1,useContext as z$,useCallback as _$,useRef as L0,useMemo as $2}from"react";import{SessionContext as K$}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 T1}from"react/jsx-dev-runtime";function J2(J){let $=J instanceof HTMLElement?J:J.parentElement;while($){if($.hasAttribute("data-line-num"))return $;$=$.parentElement}return null}function U$(J){let $=J.toString().trim(),Y=J2(J.startContainer),Z=J2(J.endContainer),Q=Y?parseInt(Y.getAttribute("data-line-num"),10):void 0,q=Z?parseInt(Z.getAttribute("data-line-num"),10):void 0,X="",_="";if($.length<30&&Y&&Y===Z){let z=Y.querySelector("code");if(z){let K=z.textContent||"",G=K.indexOf($);if(G>=0)X=K.slice(0,G).trimStart(),_=K.slice(G+$.length).trimEnd()}}return{before:X,after:_,hierarchy:[],lineStart:Q,lineEnd:q}}function Y2({path:J}){let $=z$(K$),{annotations:Y,addAnnotationWithId:Z,activeAnnotationId:Q,setActiveAnnotationId:q}=o(),[X,_]=u1(null),[z,K]=u1("text"),[G,U]=u1(!0),[H,F]=u1(null),W=L0(null),[L,y]=u1(null),[B,O]=u1(null),D=L0(null),R=L0(null),P=L0([]),k=Y.filter((w)=>w.filePath===J),v=W.current?.closest("#plan-scroll-container"),{popovers:g,openCreatePopover:h}=w1({containerRef:W,restoreKey:`${X}:${J}`,restoreAnnotations:k,extractContext:U$,filePath:J,scrollContainer:v});e5(()=>{U(!0),F(null),fetch(`/api/file?session=${$}&path=${encodeURIComponent(J)}`).then((w)=>w.json()).then((w)=>{if(w.error)F(w.error),U(!1);else _(w.content),K(w.language||"text"),U(!1)}).catch(()=>{F("Failed to fetch file"),U(!1)})},[$,J]);let j=_$((w,N)=>{w.preventDefault(),D.current=N,R.current=N,y(N),O(N)},[]);e5(()=>{let w=(b)=>{if(D.current===null)return;let f=b.target.closest("[data-line-num]");if(f){let u=parseInt(f.getAttribute("data-line-num"),10);R.current=u,O(u)}},N=()=>{let b=D.current;if(b===null)return;D.current=null;let f=R.current??b,u=Math.min(b,f),p=Math.max(b,f),i=P.current.slice(u-1,p).join(`
74
+ `);if(!i.trim()){y(null),O(null);return}let M=`__pending_${Date.now()}`,m={before:"",after:"",hierarchy:[],lineStart:u,lineEnd:p};if(W.current){let l=W.current.querySelectorAll("[data-line-num]"),Z1=l[u-1],X5=l[p-1];if(Z1&&X5){let b0=Z1.querySelector("code"),w0=X5.querySelector("code");if(b0&&w0)try{let A0=document.createRange();A0.setStartBefore(b0.firstChild||b0),A0.setEndAfter(w0.lastChild||w0),b1(A0,M)}catch{}}let q5=l[p-1];if(q5)h(q5,M,i,m)}y(null),O(null)};return document.addEventListener("mousemove",w),document.addEventListener("mouseup",N),()=>{document.removeEventListener("mousemove",w),document.removeEventListener("mouseup",N)}},[]);let V=$2(()=>{if(!X)return null;let w=window.hljs;if(!w)return null;let N=J.split(".").pop()||"",b=O0[N];try{return(b?w.highlight(X,{language:b}):w.highlightAuto(X)).value.split(`
75
+ `)}catch{return null}},[X,J]);if(G)return T1("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-[13px]",children:["Loading ",J,"..."]},void 0,!0,void 0,this);if(H)return T1("div",{className:"p-8 text-accent-red font-body text-[13px]",children:H},void 0,!1,void 0,this);if(!X)return null;let C=X.split(`
76
+ `);P.current=C;let I=$2(()=>{if(L===null)return null;let w=B??L;return{start:Math.min(L,w),end:Math.max(L,w)}},[L,B]),S=()=>{let w=X.split(`
77
77
  `).slice(0,3).join(`
78
78
  `)+(C.length>3?`
79
- ...`:""),N=z1();Z(N,w,"",J),X(N)};return T1("div",{children:[T1("pre",{ref:W,className:"text-code font-mono text-text-code bg-bg-base select-text cursor-text py-3 hljs",children:C.map((w,N)=>{let b=N+1,f=I&&b>=I.start&&b<=I.end;return T1("div",{"data-line-num":b,className:`flex px-5 ${f?"bg-accent-blue/10":"hover:bg-bg-elevated-half"}`,children:[T1("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:(u)=>j(u,b),children:b},void 0,!1,void 0,this),V?T1("code",{className:"py-px",dangerouslySetInnerHTML:{__html:V[N]||" "}},void 0,!1,void 0,this):T1("code",{className:"py-px",children:w||" "},void 0,!1,void 0,this)]},N,!0,void 0,this)})},void 0,!1,void 0,this),g]},void 0,!0,void 0,this)}import{useEffect as Q2,useState as Z2,useRef as U$}from"react";import{jsxDEV as G1}from"react/jsx-dev-runtime";function q2(J,$){if($){let Y=$.replace(/\/+$/,"").split("/");return Y[Y.length-1]||J}return J.length>30?J.slice(0,30)+"...":J}function e0({currentSessionId:J,projectRoot:$}){let[Y,Z]=Z2([]),[Q,X]=Z2(!1),q=U$(null);Q2(()=>{let K=async()=>{try{let H=await(await fetch("/api/sessions")).json();Z((F)=>{let W=JSON.stringify(H);return JSON.stringify(F)===W?F:H})}catch{}};K();let G=setInterval(K,5000);return()=>clearInterval(G)},[]),Q2(()=>{if(!Q)return;let K=(G)=>{if(q.current&&!q.current.contains(G.target))X(!1)};return document.addEventListener("mousedown",K),()=>document.removeEventListener("mousedown",K)},[Q]);let _=Y.filter((K)=>K.id!==J),z=q2(J,$);return G1("div",{className:"relative",ref:q,children:[G1("div",{className:"flex items-center gap-1.5 font-body text-body font-medium",children:[G1("a",{href:`/s/${J}`,className:"text-text-primary hover:text-text-secondary transition-colors",children:z},void 0,!1,void 0,this),_.length>0&&G1("button",{onClick:()=>X(!Q),className:"flex items-center justify-center text-text-tertiary hover:text-text-secondary transition-colors",children:G1("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:`transition-transform duration-200 ${Q?"rotate-180":""}`,children:G1("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&&_.length>0&&G1("div",{className:"absolute top-full left-0 mt-2 w-64 bg-bg-elevated border border-border-hover rounded-lg shadow-lg z-50 py-1 overflow-hidden",children:_.map((K)=>G1("a",{href:`/s/${K.id}`,className:"flex items-center gap-2.5 px-4 py-2.5 text-body font-body text-text-secondary hover:bg-bg-surface hover:text-text-primary transition-colors",children:[G1("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${K.currentRevision>0?"bg-accent-green":"bg-border-hover"}`},void 0,!1,void 0,this),G1("span",{className:"truncate",children:q2(K.id,K.projectRoot)},void 0,!1,void 0,this)]},K.id,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function X2(J){let $=[];return M0(J,$,0),$.join(`
79
+ ...`:""),N=z1();Z(N,w,"",J),q(N)};return T1("div",{children:[T1("pre",{ref:W,className:"text-code font-mono text-text-code bg-bg-base select-text cursor-text py-3 hljs",children:C.map((w,N)=>{let b=N+1,f=I&&b>=I.start&&b<=I.end;return T1("div",{"data-line-num":b,className:`flex px-5 ${f?"bg-accent-blue/10":"hover:bg-bg-elevated-half"}`,children:[T1("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:(u)=>j(u,b),children:b},void 0,!1,void 0,this),V?T1("code",{className:"py-px",dangerouslySetInnerHTML:{__html:V[N]||" "}},void 0,!1,void 0,this):T1("code",{className:"py-px",children:w||" "},void 0,!1,void 0,this)]},N,!0,void 0,this)})},void 0,!1,void 0,this),g]},void 0,!0,void 0,this)}import{useEffect as Q2,useState as Z2,useRef as G$}from"react";import{jsxDEV as G1}from"react/jsx-dev-runtime";function X2(J,$){if($){let Y=$.replace(/\/+$/,"").split("/");return Y[Y.length-1]||J}return J.length>30?J.slice(0,30)+"...":J}function e0({currentSessionId:J,projectRoot:$}){let[Y,Z]=Z2([]),[Q,q]=Z2(!1),X=G$(null);Q2(()=>{let K=async()=>{try{let H=await(await fetch("/api/sessions")).json();Z((F)=>{let W=JSON.stringify(H);return JSON.stringify(F)===W?F:H})}catch{}};K();let G=setInterval(K,5000);return()=>clearInterval(G)},[]),Q2(()=>{if(!Q)return;let K=(G)=>{if(X.current&&!X.current.contains(G.target))q(!1)};return document.addEventListener("mousedown",K),()=>document.removeEventListener("mousedown",K)},[Q]);let _=Y.filter((K)=>K.id!==J),z=X2(J,$);return G1("div",{className:"relative",ref:X,children:[G1("div",{className:"flex items-center gap-1.5 font-body text-body font-medium",children:[G1("a",{href:`/s/${J}`,className:"text-text-primary hover:text-text-secondary transition-colors",children:z},void 0,!1,void 0,this),_.length>0&&G1("button",{onClick:()=>q(!Q),className:"flex items-center justify-center text-text-tertiary hover:text-text-secondary transition-colors",children:G1("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:`transition-transform duration-200 ${Q?"rotate-180":""}`,children:G1("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&&_.length>0&&G1("div",{className:"absolute top-full left-0 mt-2 w-64 bg-bg-elevated border border-border-hover rounded-lg shadow-lg z-50 py-1 overflow-hidden",children:_.map((K)=>G1("a",{href:`/s/${K.id}`,className:"flex items-center gap-2.5 px-4 py-2.5 text-body font-body text-text-secondary hover:bg-bg-surface hover:text-text-primary transition-colors",children:[G1("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${K.currentRevision>0?"bg-accent-green":"bg-border-hover"}`},void 0,!1,void 0,this),G1("span",{className:"truncate",children:X2(K.id,K.projectRoot)},void 0,!1,void 0,this)]},K.id,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function q2(J){let $=[];return M0(J,$,0),$.join(`
80
80
  `).replace(/\n{3,}/g,`
81
81
 
82
82
  `).trim()+`
83
- `}var G$=new Set(["CODE","SPAN","STRONG","EM","A","B","I","U","SMALL","SUB","SUP","MARK","ABBR"]);function M0(J,$,Y){if(H$(J)){let Z=W$(J);if(Z)$.push(Z,"");return}for(let Z of J.childNodes)if(Z.nodeType===Node.ELEMENT_NODE)F$(Z,$,Y);else if(Z.nodeType===Node.TEXT_NODE){let Q=Z.textContent?.trim();if(Q)$.push(Q,"")}}function H$(J){for(let $ of J.childNodes){if($.nodeType===Node.TEXT_NODE)continue;if($.nodeType===Node.ELEMENT_NODE){let Y=$;if(!G$.has(Y.tagName)||Y.hasAttribute("data-md"))return!1}}return J.childNodes.length>0}function W$(J){let $="";for(let Y of J.childNodes)if(Y.nodeType===Node.TEXT_NODE)$+=Y.textContent||"";else if(Y.nodeType===Node.ELEMENT_NODE){let Z=Y;if(Z.tagName==="CODE")$+="`"+(Z.textContent||"")+"`";else $+=Z.textContent||""}return $.trim()}function F$(J,$,Y){let Z=J.getAttribute("data-md");if(Z)switch(Z){case"section":return N$(J,$,Y);case"item":return T$(J,$);case"codeblock":return y$(J,$);case"callout":return O$(J,$);case"note":return L$(J,$);case"table":return M$(J,$);case"checklist":return B$(J,$);case"diff":return P$(J,$);case"mermaid":return S$(J,$);case"choice":return b$(J,$);case"multichoice":return w$(J,$);case"choice-option":case"multichoice-option":return;case"userinput":return A$(J,$);case"rangeinput":return R$(J,$);case"checklist-item":return;case"filepreview":return j$(J,$);case"priority":return C$(J,$)}if(J.querySelector("button, input, select, textarea"))return;if(J.children.length>0)M0(J,$,Y);else{let Q=J.textContent?.trim();if(Q)$.push(Q,"")}}function N$(J,$,Y){let Z=J.getAttribute("data-md-title")||"Untitled",Q=Y===0?"##":"###";$.push(`${Q} ${Z}`,"");let X=J.querySelector(":scope > div:last-of-type");if(X)M0(X,$,Y+1)}function T$(J,$){let Y=J.getAttribute("data-md-label")||"",Z=J.getAttribute("data-md-status"),Q=J.getAttribute("data-md-badge"),X="-";if(Z==="done")X="- [x]";else if(Z)X="- [ ]";let q=`${X} **${Y}**`;if(Q)q+=` \`${Q}\``;$.push(q);let _=J.querySelector(".text-text-secondary");if(_){let z=[];M0(_,z,0);for(let K of z)$.push(K?` ${K}`:"")}$.push("")}function y$(J,$){let Y=J.getAttribute("data-md-language")||"",Q=J.querySelector("code")?.textContent||"";$.push(`\`\`\`${Y}`,Q,"```","")}function O$(J,$){let Y=J.getAttribute("data-md-type")||"info",Z={info:"Info",warning:"Warning",danger:"Danger",tip:"Tip"},Q=I$(J.querySelector(".text-text-secondary")||J);$.push(`> **${Z[Y]||Y}:** ${Q}`,"")}function L$(J,$){let Y=J.textContent?.trim()||"";$.push(`> *${Y}*`,"")}function M$(J,$){let Y=J.querySelector("table");if(!Y)return;let Z=[];for(let Q of Y.querySelectorAll("thead th"))Z.push(Q.textContent?.trim()||"");if(Z.length===0)return;$.push(`| ${Z.join(" | ")} |`),$.push(`| ${Z.map(()=>"---").join(" | ")} |`);for(let Q of Y.querySelectorAll("tbody tr")){let X=[];for(let q of Q.querySelectorAll("td"))X.push(q.textContent?.trim()||"");$.push(`| ${X.join(" | ")} |`)}$.push("")}function B$(J,$){for(let Y of J.querySelectorAll("li")){let Z=Y.querySelector(".bg-accent-green")!==null,Q=Y.textContent?.trim()||"";$.push(`- [${Z?"x":" "}] ${Q}`)}$.push("")}function P$(J,$){let Y=J.getAttribute("data-md-language")||"";$.push(`\`\`\`diff${Y?` (${Y})`:""}`);for(let Z of J.querySelectorAll("[class*='flex']")){let Q=Z.querySelector(".text-accent-red")?"-":Z.querySelector(".text-accent-green")?"+":" ",X=Z.querySelector("code");if(X)$.push(`${Q} ${X.textContent}`)}$.push("```","")}function S$(J,$){let Y=J.getAttribute("data-md-source")||"";if(Y)$.push("```mermaid",Y,"```","")}function b$(J,$){let Y=J.getAttribute("data-md-label")||"";$.push(`**${Y}:**`);for(let Z of J.querySelectorAll("[data-md='choice-option']")){let Q=Z.getAttribute("data-md-label")||Z.textContent?.trim()||"",X=Z.querySelector(".bg-accent-amber")!==null;$.push(`- ${X?"(x)":"( )"} ${Q}`)}$.push("")}function w$(J,$){let Y=J.getAttribute("data-md-label")||"";$.push(`**${Y}:**`);for(let Z of J.querySelectorAll("[data-md='multichoice-option']")){let Q=Z.getAttribute("data-md-label")||Z.textContent?.trim()||"",X=Z.querySelector(".bg-accent-amber")!==null;$.push(`- [${X?"x":" "}] ${Q}`)}$.push("")}function A$(J,$){let Y=J.getAttribute("data-md-label")||"",Q=J.querySelector("textarea")?.value?.trim()||"";$.push(`**${Y}:** ${Q||"_empty_"}`,"")}function R$(J,$){let Y=J.getAttribute("data-md-label")||"",Z=J.querySelector("input[type='range']"),X=J.querySelector(".font-mono")?.textContent?.trim()||Z?.value||"—";$.push(`**${Y}:** ${X}`,"")}function j$(J,$){let Y=J.getAttribute("data-md-path")||"",Z=J.getAttribute("data-md-lines")||"",X=J.querySelector("code")?.textContent||"",q=Y.split(".").pop()||"",_=O0[q]||"",z=Z?`${Y} (L${Z})`:Y;$.push(z,"",`\`\`\`${_}`,X,"```","")}function C$(J,$){}function I$(J){return J?.textContent?.trim()||""}import M2,{useEffect as E1,useState as Y1,useRef as W1,useCallback as B2,useMemo as r$}from"react";import{useEffect as V$,useState as D$,useRef as m$,useContext as k$}from"react";import{jsxDEV as J1,Fragment as z2}from"react/jsx-dev-runtime";function f$(J){return J.label||`Round ${J.revision}`}function g$(J){let $=Date.now()-new Date(J).getTime(),Y=Math.floor($/1000);if(Y<60)return"just now";let Z=Math.floor(Y/60);if(Z<60)return`${Z}m ago`;let Q=Math.floor(Z/60);if(Q<24)return`${Q}h ago`;return`${Math.floor(Q/24)}d ago`}function o1({value:J,onChange:$,accent:Y="default",className:Z}){let{currentRevision:Q,revisions:X}=k$(v1),[q,_]=D$(!1),z=m$(null);V$(()=>{if(!q)return;let U=(H)=>{if(z.current&&!z.current.contains(H.target))_(!1)};return document.addEventListener("mousedown",U),()=>document.removeEventListener("mousedown",U)},[q]);let K=X.find((U)=>U.revision===J);return J1("div",{className:"relative",ref:z,children:[J1("button",{onClick:()=>_(!q),className:`flex items-center gap-1.5 text-[12px] font-body font-medium px-2 py-1 rounded-md transition-colors hover:bg-bg-elevated ${{default:"text-text-secondary hover:text-text-primary",red:"text-accent-red",green:"text-accent-green",amber:"text-accent-amber bg-highlight-selected"}[Y]} ${Z||""}`,children:[K?f$(K):`Round ${J}`,J1("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",className:`text-text-tertiary transition-transform duration-200 ${q?"rotate-180":""}`,children:J1("path",{d:"M2.5 4l2.5 2.5L7.5 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),q&&J1("div",{className:"absolute top-full left-0 mt-1 w-64 bg-bg-elevated border border-border-hover rounded-lg shadow-lg z-50 py-1 max-h-80 overflow-y-auto",children:[...X].reverse().map((U)=>J1("button",{onClick:()=>{$(U.revision),_(!1)},className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] font-body transition-colors ${U.revision===J?"bg-bg-surface text-text-primary":"text-text-secondary hover:bg-bg-surface hover:text-text-primary"}`,children:[J1("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${U.revision===Q?"bg-accent-green":U.hasFeedback?"bg-accent-amber":"bg-border-hover"}`},void 0,!1,void 0,this),J1("span",{className:"flex-1 text-left truncate",children:U.label?J1(z2,{children:[U.label," ",J1("span",{className:"text-text-tertiary",children:["#",U.revision]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):J1(z2,{children:["Round ",U.revision]},void 0,!0,void 0,this)},void 0,!1,void 0,this),J1("span",{className:"text-[10px] text-text-tertiary flex-shrink-0 flex items-center gap-1.5",children:[U.diffStats&&J1("span",{className:"font-mono",children:[J1("span",{className:"text-accent-green",children:["+",U.diffStats.added]},void 0,!0,void 0,this)," ",J1("span",{className:"text-accent-red",children:["-",U.diffStats.removed]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),U.revision===Q?"current":U.hasFeedback?"sent":g$(U.createdAt)]},void 0,!0,void 0,this)]},U.revision,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function y1(J,$){let Y=J.length,Z=$.length;if(Y===0||Z===0)return[];let Q=Array.from({length:Y+1},()=>Array(Z+1).fill(0));for(let z=1;z<=Y;z++)for(let K=1;K<=Z;K++)Q[z][K]=J[z-1]===$[K-1]?Q[z-1][K-1]+1:Math.max(Q[z-1][K],Q[z][K-1]);let X=[],q=Y,_=Z;while(q>0&&_>0)if(J[q-1]===$[_-1])X.unshift(J[q-1]),q--,_--;else if(Q[q-1][_]>Q[q][_-1])q--;else _--;return X}function _2(J){let $=[],Y=[],Z=document.createTreeWalker(J,NodeFilter.SHOW_TEXT,{acceptNode(X){let q=X.parentElement;if(!q)return NodeFilter.FILTER_REJECT;if(q.closest("svg, .select-none, [data-no-diff]"))return NodeFilter.FILTER_REJECT;return NodeFilter.FILTER_ACCEPT}}),Q;while(Q=Z.nextNode()){let q=(Q.nodeValue||"").match(/\S+|\s+/g);if(!q)continue;let _=0;for(let z of q)$.push(z),Y.push({text:z,node:Q,offset:_}),_+=z.length}return{words:$,map:Y}}function $5(J,$){if(J.length>5000||$.length>5000)return v$(J,$);return G2(J,$)}function G2(J,$){let Y=B0(J,$),Z=[],Q=[],X=0,q=0,_=0;while(X<J.length||q<$.length)if(_<Y.length&&X<J.length&&q<$.length&&J[X]===Y[_]&&$[q]===Y[_])Z.push({type:"same",index:X}),Q.push({type:"same",index:q}),X++,q++,_++;else if(X<J.length&&(_>=Y.length||J[X]!==Y[_]))Z.push({type:"removed",index:X}),X++;else if(q<$.length)Q.push({type:"added",index:q}),q++;return{oldOps:Z,newOps:Q}}function B0(J,$){let Y=J.length,Z=$.length;if(Y===0||Z===0)return[];if(Y===1)return $.includes(J[0])?[J[0]]:[];if(Z===1)return J.includes($[0])?[$[0]]:[];if(Y*Z<=1e6)return y1(J,$);let Q=Math.floor(Y/2),X=J.slice(0,Q),q=J.slice(Q),_=K2(X,$),z=K2([...q].reverse(),[...$].reverse()),K=0,G=0;for(let F=0;F<=Z;F++){let W=_[F]+z[Z-F];if(W>K)K=W,G=F}let U=$.slice(0,G),H=$.slice(G);return[...B0(X,U),...B0(q,H)]}function K2(J,$){let Y=$.length,Z=Array(Y+1).fill(0),Q=Array(Y+1).fill(0);for(let X=0;X<J.length;X++){for(let q=1;q<=Y;q++)Q[q]=J[X]===$[q-1]?Z[q-1]+1:Math.max(Z[q],Q[q-1]);[Z,Q]=[Q,Z],Q.fill(0)}return Z}function v$(J,$){let Z=(W)=>{let L=[];for(let T=0;T<W.length;T+=200){let B=Math.min(T+200,W.length);L.push({start:T,end:B,text:W.slice(T,B).join("")})}return L},Q=Z(J),X=Z($),q=Q.map((W)=>W.text),_=X.map((W)=>W.text),z=B0(q,_),K=[],G=[],U=0,H=0,F=0;while(U<Q.length||H<X.length)if(F<z.length&&U<Q.length&&H<X.length&&q[U]===z[F]&&_[H]===z[F]){for(let W=Q[U].start;W<Q[U].end;W++)K.push({type:"same",index:W});for(let W=X[H].start;W<X[H].end;W++)G.push({type:"same",index:W});U++,H++,F++}else if(U<Q.length&&(F>=z.length||q[U]!==z[F]))if(H<X.length&&(F>=z.length||_[H]!==z[F])){let W=G2(J.slice(Q[U].start,Q[U].end),$.slice(X[H].start,X[H].end));for(let L of W.oldOps)K.push({type:L.type,index:L.index+Q[U].start});for(let L of W.newOps)G.push({type:L.type,index:L.index+X[H].start});U++,H++}else{for(let W=Q[U].start;W<Q[U].end;W++)K.push({type:"removed",index:W});U++}else if(H<X.length){for(let W=X[H].start;W<X[H].end;W++)G.push({type:"added",index:W});H++}return{oldOps:K,newOps:G}}function U2(J,$,Y){let Z=new Map;for(let Q of J){if(Q.type==="same")continue;let X=$[Q.index];if(!X||!X.node.parentNode)continue;let q=Z.get(X.node);if(!q)q=[],Z.set(X.node,q);q.push({offset:X.offset,length:X.text.length})}for(let[Q,X]of Z){if(!Q.parentNode)continue;let q=Q.nodeValue||"";X.sort((U,H)=>U.offset-H.offset);let _=[];for(let U of X){let H=_[_.length-1];if(H&&U.offset<=H.offset+H.length)H.length=Math.max(H.length,U.offset+U.length-H.offset);else _.push({...U})}let z=Q.parentNode,K=document.createDocumentFragment(),G=0;for(let U of _){if(U.offset>G)K.appendChild(document.createTextNode(q.slice(G,U.offset)));let H=document.createElement("span");H.className=Y,H.textContent=q.slice(U.offset,U.offset+U.length),K.appendChild(H),G=U.offset+U.length}if(G<q.length)K.appendChild(document.createTextNode(q.slice(G)));z.replaceChild(K,Q)}}function H2(J,$){let Y=u$(J,$),Z=_2(J),Q=_2($),{oldOps:X,newOps:q}=$5(Z.words,Q.words),_=X.some((z)=>z.type==="removed")||q.some((z)=>z.type==="added");return U2(X,Z.map,"diff-removed"),U2(q,Q.map,"diff-added"),_||Y}function u$(J,$){let Y=Array.from(J.querySelectorAll('[data-md="mermaid"]')),Z=Array.from($.querySelectorAll('[data-md="mermaid"]')),Q=!1,X=Math.max(Y.length,Z.length);for(let q=0;q<X;q++){let _=Y[q],z=Z[q];if(!_&&z){z.classList.add("diff-block-added"),z.style.position="relative",Q=!0;continue}if(_&&!z){_.classList.add("diff-block-removed"),_.style.position="relative",Q=!0;continue}if(!_||!z)continue;let K=(_.getAttribute("data-md-source")||"").trim(),G=(z.getAttribute("data-md-source")||"").trim();if(K===G)continue;Q=!0,_.style.borderLeft="3px solid var(--color-accent-red)",_.style.paddingLeft="8px",z.style.borderLeft="3px solid var(--color-accent-green)",z.style.paddingLeft="8px";let U=K.split(`
83
+ `}var H$=new Set(["CODE","SPAN","STRONG","EM","A","B","I","U","SMALL","SUB","SUP","MARK","ABBR"]);function M0(J,$,Y){if(W$(J)){let Z=F$(J);if(Z)$.push(Z,"");return}for(let Z of J.childNodes)if(Z.nodeType===Node.ELEMENT_NODE)N$(Z,$,Y);else if(Z.nodeType===Node.TEXT_NODE){let Q=Z.textContent?.trim();if(Q)$.push(Q,"")}}function W$(J){for(let $ of J.childNodes){if($.nodeType===Node.TEXT_NODE)continue;if($.nodeType===Node.ELEMENT_NODE){let Y=$;if(!H$.has(Y.tagName)||Y.hasAttribute("data-md"))return!1}}return J.childNodes.length>0}function F$(J){let $="";for(let Y of J.childNodes)if(Y.nodeType===Node.TEXT_NODE)$+=Y.textContent||"";else if(Y.nodeType===Node.ELEMENT_NODE){let Z=Y;if(Z.tagName==="CODE")$+="`"+(Z.textContent||"")+"`";else $+=Z.textContent||""}return $.trim()}function N$(J,$,Y){let Z=J.getAttribute("data-md");if(Z)switch(Z){case"section":return T$(J,$,Y);case"item":return y$(J,$);case"codeblock":return O$(J,$);case"callout":return L$(J,$);case"note":return M$(J,$);case"table":return B$(J,$);case"checklist":return P$(J,$);case"diff":return S$(J,$);case"mermaid":return b$(J,$);case"choice":return w$(J,$);case"multichoice":return A$(J,$);case"choice-option":case"multichoice-option":return;case"userinput":return R$(J,$);case"rangeinput":return j$(J,$);case"checklist-item":return;case"filepreview":return C$(J,$);case"priority":return I$(J,$)}if(J.querySelector("button, input, select, textarea"))return;if(J.children.length>0)M0(J,$,Y);else{let Q=J.textContent?.trim();if(Q)$.push(Q,"")}}function T$(J,$,Y){let Z=J.getAttribute("data-md-title")||"Untitled",Q=Y===0?"##":"###";$.push(`${Q} ${Z}`,"");let q=J.querySelector(":scope > div:last-of-type");if(q)M0(q,$,Y+1)}function y$(J,$){let Y=J.getAttribute("data-md-label")||"",Z=J.getAttribute("data-md-status"),Q=J.getAttribute("data-md-badge"),q="-";if(Z==="done")q="- [x]";else if(Z)q="- [ ]";let X=`${q} **${Y}**`;if(Q)X+=` \`${Q}\``;$.push(X);let _=J.querySelector(".text-text-secondary");if(_){let z=[];M0(_,z,0);for(let K of z)$.push(K?` ${K}`:"")}$.push("")}function O$(J,$){let Y=J.getAttribute("data-md-language")||"",Q=J.querySelector("code")?.textContent||"";$.push(`\`\`\`${Y}`,Q,"```","")}function L$(J,$){let Y=J.getAttribute("data-md-type")||"info",Z={info:"Info",warning:"Warning",danger:"Danger",tip:"Tip"},Q=V$(J.querySelector(".text-text-secondary")||J);$.push(`> **${Z[Y]||Y}:** ${Q}`,"")}function M$(J,$){let Y=J.textContent?.trim()||"";$.push(`> *${Y}*`,"")}function B$(J,$){let Y=J.querySelector("table");if(!Y)return;let Z=[];for(let Q of Y.querySelectorAll("thead th"))Z.push(Q.textContent?.trim()||"");if(Z.length===0)return;$.push(`| ${Z.join(" | ")} |`),$.push(`| ${Z.map(()=>"---").join(" | ")} |`);for(let Q of Y.querySelectorAll("tbody tr")){let q=[];for(let X of Q.querySelectorAll("td"))q.push(X.textContent?.trim()||"");$.push(`| ${q.join(" | ")} |`)}$.push("")}function P$(J,$){for(let Y of J.querySelectorAll("li")){let Z=Y.querySelector(".bg-accent-green")!==null,Q=Y.textContent?.trim()||"";$.push(`- [${Z?"x":" "}] ${Q}`)}$.push("")}function S$(J,$){let Y=J.getAttribute("data-md-language")||"";$.push(`\`\`\`diff${Y?` (${Y})`:""}`);for(let Z of J.querySelectorAll("[class*='flex']")){let Q=Z.querySelector(".text-accent-red")?"-":Z.querySelector(".text-accent-green")?"+":" ",q=Z.querySelector("code");if(q)$.push(`${Q} ${q.textContent}`)}$.push("```","")}function b$(J,$){let Y=J.getAttribute("data-md-source")||"";if(Y)$.push("```mermaid",Y,"```","")}function w$(J,$){let Y=J.getAttribute("data-md-label")||"";$.push(`**${Y}:**`);for(let Z of J.querySelectorAll("[data-md='choice-option']")){let Q=Z.getAttribute("data-md-label")||Z.textContent?.trim()||"",q=Z.querySelector(".bg-accent-amber")!==null;$.push(`- ${q?"(x)":"( )"} ${Q}`)}$.push("")}function A$(J,$){let Y=J.getAttribute("data-md-label")||"";$.push(`**${Y}:**`);for(let Z of J.querySelectorAll("[data-md='multichoice-option']")){let Q=Z.getAttribute("data-md-label")||Z.textContent?.trim()||"",q=Z.querySelector(".bg-accent-amber")!==null;$.push(`- [${q?"x":" "}] ${Q}`)}$.push("")}function R$(J,$){let Y=J.getAttribute("data-md-label")||"",Q=J.querySelector("textarea")?.value?.trim()||"";$.push(`**${Y}:** ${Q||"_empty_"}`,"")}function j$(J,$){let Y=J.getAttribute("data-md-label")||"",Z=J.querySelector("input[type='range']"),q=J.querySelector(".font-mono")?.textContent?.trim()||Z?.value||"—";$.push(`**${Y}:** ${q}`,"")}function C$(J,$){let Y=J.getAttribute("data-md-path")||"",Z=J.getAttribute("data-md-lines")||"",q=J.querySelector("code")?.textContent||"",X=Y.split(".").pop()||"",_=O0[X]||"",z=Z?`${Y} (L${Z})`:Y;$.push(z,"",`\`\`\`${_}`,q,"```","")}function I$(J,$){}function V$(J){return J?.textContent?.trim()||""}import M2,{useEffect as E1,useState as Y1,useRef as F1,useCallback as B2,useMemo as l$}from"react";import{useEffect as D$,useState as m$,useRef as k$,useContext as f$}from"react";import{jsxDEV as J1,Fragment as z2}from"react/jsx-dev-runtime";function g$(J){return J.label||`Round ${J.revision}`}function v$(J){let $=Date.now()-new Date(J).getTime(),Y=Math.floor($/1000);if(Y<60)return"just now";let Z=Math.floor(Y/60);if(Z<60)return`${Z}m ago`;let Q=Math.floor(Z/60);if(Q<24)return`${Q}h ago`;return`${Math.floor(Q/24)}d ago`}function o1({value:J,onChange:$,accent:Y="default",className:Z}){let{currentRevision:Q,revisions:q}=f$(v1),[X,_]=m$(!1),z=k$(null);D$(()=>{if(!X)return;let U=(H)=>{if(z.current&&!z.current.contains(H.target))_(!1)};return document.addEventListener("mousedown",U),()=>document.removeEventListener("mousedown",U)},[X]);let K=q.find((U)=>U.revision===J);return J1("div",{className:"relative",ref:z,children:[J1("button",{onClick:()=>_(!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"}[Y]} ${Z||""}`,children:[K?g$(K):`Round ${J}`,J1("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",className:`text-text-tertiary transition-transform duration-200 ${X?"rotate-180":""}`,children:J1("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&&J1("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((U)=>J1("button",{onClick:()=>{$(U.revision),_(!1)},className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] font-body transition-colors ${U.revision===J?"bg-bg-surface text-text-primary":"text-text-secondary hover:bg-bg-surface hover:text-text-primary"}`,children:[J1("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${U.revision===Q?"bg-accent-green":U.hasFeedback?"bg-accent-amber":"bg-border-hover"}`},void 0,!1,void 0,this),J1("span",{className:"flex-1 text-left truncate",children:U.label?J1(z2,{children:[U.label," ",J1("span",{className:"text-text-tertiary",children:["#",U.revision]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):J1(z2,{children:["Round ",U.revision]},void 0,!0,void 0,this)},void 0,!1,void 0,this),J1("span",{className:"text-[10px] text-text-tertiary flex-shrink-0 flex items-center gap-1.5",children:[U.diffStats&&J1("span",{className:"font-mono",children:[J1("span",{className:"text-accent-green",children:["+",U.diffStats.added]},void 0,!0,void 0,this)," ",J1("span",{className:"text-accent-red",children:["-",U.diffStats.removed]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),U.revision===Q?"current":U.hasFeedback?"sent":v$(U.createdAt)]},void 0,!0,void 0,this)]},U.revision,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function y1(J,$){let Y=J.length,Z=$.length;if(Y===0||Z===0)return[];let Q=Array.from({length:Y+1},()=>Array(Z+1).fill(0));for(let z=1;z<=Y;z++)for(let K=1;K<=Z;K++)Q[z][K]=J[z-1]===$[K-1]?Q[z-1][K-1]+1:Math.max(Q[z-1][K],Q[z][K-1]);let q=[],X=Y,_=Z;while(X>0&&_>0)if(J[X-1]===$[_-1])q.unshift(J[X-1]),X--,_--;else if(Q[X-1][_]>Q[X][_-1])X--;else _--;return q}function _2(J){let $=[],Y=[],Z=document.createTreeWalker(J,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=Z.nextNode()){let X=(Q.nodeValue||"").match(/\S+|\s+/g);if(!X)continue;let _=0;for(let z of X)$.push(z),Y.push({text:z,node:Q,offset:_}),_+=z.length}return{words:$,map:Y}}function $5(J,$){if(J.length>5000||$.length>5000)return u$(J,$);return G2(J,$)}function G2(J,$){let Y=B0(J,$),Z=[],Q=[],q=0,X=0,_=0;while(q<J.length||X<$.length)if(_<Y.length&&q<J.length&&X<$.length&&J[q]===Y[_]&&$[X]===Y[_])Z.push({type:"same",index:q}),Q.push({type:"same",index:X}),q++,X++,_++;else if(q<J.length&&(_>=Y.length||J[q]!==Y[_]))Z.push({type:"removed",index:q}),q++;else if(X<$.length)Q.push({type:"added",index:X}),X++;return{oldOps:Z,newOps:Q}}function B0(J,$){let Y=J.length,Z=$.length;if(Y===0||Z===0)return[];if(Y===1)return $.includes(J[0])?[J[0]]:[];if(Z===1)return J.includes($[0])?[$[0]]:[];if(Y*Z<=1e6)return y1(J,$);let Q=Math.floor(Y/2),q=J.slice(0,Q),X=J.slice(Q),_=K2(q,$),z=K2([...X].reverse(),[...$].reverse()),K=0,G=0;for(let F=0;F<=Z;F++){let W=_[F]+z[Z-F];if(W>K)K=W,G=F}let U=$.slice(0,G),H=$.slice(G);return[...B0(q,U),...B0(X,H)]}function K2(J,$){let Y=$.length,Z=Array(Y+1).fill(0),Q=Array(Y+1).fill(0);for(let q=0;q<J.length;q++){for(let X=1;X<=Y;X++)Q[X]=J[q]===$[X-1]?Z[X-1]+1:Math.max(Z[X],Q[X-1]);[Z,Q]=[Q,Z],Q.fill(0)}return Z}function u$(J,$){let Z=(W)=>{let L=[];for(let y=0;y<W.length;y+=200){let B=Math.min(y+200,W.length);L.push({start:y,end:B,text:W.slice(y,B).join("")})}return L},Q=Z(J),q=Z($),X=Q.map((W)=>W.text),_=q.map((W)=>W.text),z=B0(X,_),K=[],G=[],U=0,H=0,F=0;while(U<Q.length||H<q.length)if(F<z.length&&U<Q.length&&H<q.length&&X[U]===z[F]&&_[H]===z[F]){for(let W=Q[U].start;W<Q[U].end;W++)K.push({type:"same",index:W});for(let W=q[H].start;W<q[H].end;W++)G.push({type:"same",index:W});U++,H++,F++}else if(U<Q.length&&(F>=z.length||X[U]!==z[F]))if(H<q.length&&(F>=z.length||_[H]!==z[F])){let W=G2(J.slice(Q[U].start,Q[U].end),$.slice(q[H].start,q[H].end));for(let L of W.oldOps)K.push({type:L.type,index:L.index+Q[U].start});for(let L of W.newOps)G.push({type:L.type,index:L.index+q[H].start});U++,H++}else{for(let W=Q[U].start;W<Q[U].end;W++)K.push({type:"removed",index:W});U++}else if(H<q.length){for(let W=q[H].start;W<q[H].end;W++)G.push({type:"added",index:W});H++}return{oldOps:K,newOps:G}}function U2(J,$,Y){let Z=new Map;for(let Q of J){if(Q.type==="same")continue;let q=$[Q.index];if(!q||!q.node.parentNode)continue;let X=Z.get(q.node);if(!X)X=[],Z.set(q.node,X);X.push({offset:q.offset,length:q.text.length})}for(let[Q,q]of Z){if(!Q.parentNode)continue;let X=Q.nodeValue||"";q.sort((U,H)=>U.offset-H.offset);let _=[];for(let U of q){let H=_[_.length-1];if(H&&U.offset<=H.offset+H.length)H.length=Math.max(H.length,U.offset+U.length-H.offset);else _.push({...U})}let z=Q.parentNode,K=document.createDocumentFragment(),G=0;for(let U of _){if(U.offset>G)K.appendChild(document.createTextNode(X.slice(G,U.offset)));let H=document.createElement("span");H.className=Y,H.textContent=X.slice(U.offset,U.offset+U.length),K.appendChild(H),G=U.offset+U.length}if(G<X.length)K.appendChild(document.createTextNode(X.slice(G)));z.replaceChild(K,Q)}}function H2(J,$){let Y=E$(J,$),Z=_2(J),Q=_2($),{oldOps:q,newOps:X}=$5(Z.words,Q.words),_=q.some((z)=>z.type==="removed")||X.some((z)=>z.type==="added");return U2(q,Z.map,"diff-removed"),U2(X,Q.map,"diff-added"),_||Y}function E$(J,$){let Y=Array.from(J.querySelectorAll('[data-md="mermaid"]')),Z=Array.from($.querySelectorAll('[data-md="mermaid"]')),Q=!1,q=Math.max(Y.length,Z.length);for(let X=0;X<q;X++){let _=Y[X],z=Z[X];if(!_&&z){z.classList.add("diff-block-added"),z.style.position="relative",Q=!0;continue}if(_&&!z){_.classList.add("diff-block-removed"),_.style.position="relative",Q=!0;continue}if(!_||!z)continue;let K=(_.getAttribute("data-md-source")||"").trim(),G=(z.getAttribute("data-md-source")||"").trim();if(K===G)continue;Q=!0,_.style.borderLeft="3px solid var(--color-accent-red)",_.style.paddingLeft="8px",z.style.borderLeft="3px solid var(--color-accent-green)",z.style.paddingLeft="8px";let U=K.split(`
84
84
  `),H=G.split(`
85
- `),F=y1(U,H),W=(L,T,B)=>{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 D=0,R=0;while(R<L.length){let P=document.createElement("div");if(P.className="px-3 py-0.5 whitespace-pre-wrap",D<T.length&&L[R]===T[D])P.textContent=" "+L[R],R++,D++;else P.classList.add(B==="old"?"diff-removed":"diff-added"),P.textContent=(B==="old"?"- ":"+ ")+L[R],R++;O.appendChild(P)}return O};_.appendChild(W(U,F,"old")),z.appendChild(W(H,F,"new"))}return Q}function J5(J){let $=[],Y=J.querySelectorAll(":scope > [data-md]");for(let Z of Y)$.push(t1(Z));if($.length===0){let Z=J.querySelectorAll("[data-md]"),Q=new Set;for(let X of Z){let q=X.parentElement?.closest("[data-md]");if(q&&J.contains(q))continue;if(Q.has(X))continue;Q.add(X),$.push(t1(X))}}return $}function t1(J){let $=J.getAttribute("data-md")||"unknown",Y=E$(J,$),Z=[];if($==="section"){let Q=J.querySelector(":scope > div.mt-6, :scope > div:last-child");if(Q)for(let X of Q.querySelectorAll(":scope > [data-md]"))Z.push(t1(X))}else if($==="table")for(let Q of J.querySelectorAll(":scope table > tbody > tr"))Z.push({key:"tr:"+(Q.textContent||"").slice(0,80),type:"tr",element:Q,children:[]});else if($==="checklist")for(let Q of J.querySelectorAll(":scope > [data-md='checklist-item']"))Z.push(t1(Q));else for(let Q of J.querySelectorAll("[data-md]"))if(Q.parentElement?.closest("[data-md]")===J)Z.push(t1(Q));return{key:Y,type:$,element:J,children:Z}}function E$(J,$){switch($){case"section":return"section:"+(J.getAttribute("data-md-title")||"");case"item":return"item:"+(J.getAttribute("data-task-id")||J.getAttribute("data-md-label")||"");case"codeblock":case"diff":return $+":"+(J.textContent||"").slice(0,80);case"checklist-item":return"checklist-item:"+(J.getAttribute("data-md-label")||J.textContent?.slice(0,60)||"");case"checklist":return"checklist:"+J.querySelectorAll("[data-md='checklist-item']").length;case"markdown":return"markdown:"+(J.getAttribute("data-md-file")||"inline");case"mermaid":return"mermaid:"+(J.getAttribute("data-md-source")||"").slice(0,80);case"callout":return"callout:"+(J.getAttribute("data-md-type")||"")+":"+(J.textContent||"").slice(0,60);default:return $+":"+(J.getAttribute("data-md-label")||J.textContent?.slice(0,60)||"")}}function Y5(J,$){let Y=J.map((K)=>K.key),Z=$.map((K)=>K.key),Q=y1(Y,Z),X=[],q=0,_=0,z=0;while(q<J.length||_<$.length)if(z<Q.length&&q<J.length&&_<$.length&&Y[q]===Q[z]&&Z[_]===Q[z]){let K=J[q],G=$[_],U=K.children.length>0||G.children.length>0?Y5(K.children,G.children):void 0;X.push({kind:"matched",oldBlock:K,newBlock:G,childMatches:U}),q++,_++,z++}else if(q<J.length&&(z>=Q.length||Y[q]!==Q[z]))X.push({kind:"removed",oldBlock:J[q]}),q++;else if(_<$.length)X.push({kind:"added",newBlock:$[_]}),_++;return X}function F2(J){let $=document.createDocumentFragment(),Y=!1;for(let Z of J)if(Z.kind==="removed")Y=!0,$.appendChild(N2(Z.oldBlock.element));else if(Z.kind==="added")Y=!0,$.appendChild(x$(Z.newBlock.element));else{let Q=Z.newBlock.element.cloneNode(!0),X=Z.newBlock.type;if(X==="mermaid"){if(L2(Z.oldBlock.element,Q))Y=!0}else if(Z.childMatches&&Z.childMatches.length>0&&(X==="table"||X==="checklist")){if(y2(Q,Z.childMatches,X))Y=!0}else if(Z.childMatches&&Z.childMatches.length>0){if(T2(Z.oldBlock,Q,Z.childMatches,X))Y=!0}else if(X==="markdown"){if(O2(Z.oldBlock.element,Q))Y=!0}else if(I1(Z.oldBlock.element,Q,!1))Y=!0;$.appendChild(Q)}return{fragment:$,hasChanges:Y}}function N2(J){let $=J.cloneNode(!0);return $.classList.add("diff-block-removed"),$.style.position="relative",Q5($,"Removed","var(--color-accent-red)"),$}function x$(J){let $=J.cloneNode(!0);return $.classList.add("diff-block-added"),$.style.position="relative",Q5($,"Added","var(--color-accent-green)"),$}function T2(J,$,Y,Z){let Q=!1,X=h$(J,$),q,_;if(Z==="section"){let z=J.element.querySelector(":scope > div:first-child"),K=$.querySelector(":scope > div:first-child");if(z&&K){if(I1(z,K,!1))Q=!0}q=J.element.querySelector(":scope > div.mt-6, :scope > div:last-child"),_=$.querySelector(":scope > div.mt-6, :scope > div:last-child")}else q=J.element,_=$;if(!q||!_)return Q;for(let z of Y)if(z.kind==="matched"){let K=X.newMap.get(z.newBlock.element);if(K){if(z.newBlock.type==="mermaid"){if(L2(z.oldBlock.element,K))Q=!0}else if(z.childMatches&&z.childMatches.length>0&&(z.newBlock.type==="table"||z.newBlock.type==="checklist")){if(y2(K,z.childMatches,z.newBlock.type))Q=!0}else if(z.childMatches&&z.childMatches.length>0){if(T2(z.oldBlock,K,z.childMatches,z.newBlock.type))Q=!0}else if(z.newBlock.type==="markdown"){if(O2(z.oldBlock.element,K))Q=!0}else if(I1(z.oldBlock.element,K,!1))Q=!0}}else if(z.kind==="removed"){Q=!0;let K=N2(z.oldBlock.element),G=c$(Y,z,X.newMap);_.insertBefore(K,G)}else if(z.kind==="added"){Q=!0;let K=X.newMap.get(z.newBlock.element);if(K)K.classList.add("diff-block-added"),K.style.position="relative",Q5(K,"Added","var(--color-accent-green)")}if(I1(q,_,!0))Q=!0;return Q}function y2(J,$,Y){let Z=Y==="table"?J.querySelector(":scope table > tbody"):J;if(!Z)return!1;let Q=!1;Z.innerHTML="";for(let X of $)if(X.kind==="removed"){Q=!0;let q=X.oldBlock.element.cloneNode(!0);q.classList.add(Y==="table"?"diff-row-removed":"diff-item-removed"),Z.appendChild(q)}else if(X.kind==="added"){Q=!0;let q=X.newBlock.element.cloneNode(!0);q.classList.add(Y==="table"?"diff-row-added":"diff-item-added"),Z.appendChild(q)}else{let q=X.newBlock.element.cloneNode(!0);if(I1(X.oldBlock.element,q,!1))Q=!0;Z.appendChild(q)}return Q}function h$(J,$){let Y=new Map,Z=J.element.querySelectorAll("[data-md]"),Q=$.querySelectorAll("[data-md]");return{newMap:{get(X){return p$($,X)}}}}function p$(J,$){let Y=$.getAttribute("data-md");if(!Y)return null;let Z=$.getAttribute("data-md-label"),Q=$.getAttribute("data-md-title"),X=`[data-md="${Y}"]`;if(Q)X+=`[data-md-title="${CSS.escape(Q)}"]`;else if(Z)X+=`[data-md-label="${CSS.escape(Z)}"]`;let q=J.querySelectorAll(X);if(q.length===1)return q[0];let _=($.textContent||"").slice(0,100),z=null,K=-1;for(let G of q){let U=(G.textContent||"").slice(0,100),H=0;for(let F=0;F<Math.min(_.length,U.length);F++)if(_[F]===U[F])H++;if(H>K)K=H,z=G}return z}function c$(J,$,Y){let Z=J.indexOf($);for(let Q=Z+1;Q<J.length;Q++){let X=J[Q];if((X.kind==="matched"||X.kind==="added")&&X.newBlock)return Y.get(X.newBlock.element)||null}return null}function O2(J,$){let Y=Array.from(J.children),Z=Array.from($.children);if(Y.length===0&&Z.length===0)return I1(J,$,!1);let Q=Y.map((H)=>H.tagName.toLowerCase()),X=Z.map((H)=>H.tagName.toLowerCase()),q=y1(Q,X),_=[],z=0,K=0,G=0;while(z<Y.length||K<Z.length)if(G<q.length&&z<Y.length&&K<Z.length&&Q[z]===q[G]&&X[K]===q[G])_.push({kind:"matched",oldChild:Y[z],newChild:Z[K]}),z++,K++,G++;else if(z<Y.length&&(G>=q.length||Q[z]!==q[G]))_.push({kind:"removed",oldChild:Y[z]}),z++;else if(K<Z.length)_.push({kind:"added",newChild:Z[K]}),K++;let U=!1;while($.firstChild)$.removeChild($.firstChild);for(let H of _)if(H.kind==="matched"){let F=(H.oldChild.textContent||"").match(/\S+/g)||[],W=(H.newChild.textContent||"").match(/\S+/g)||[],L=y1(F,W),T=Math.max(F.length,W.length);if((T>0?1-L.length/T:0)>0.5){U=!0;let O=H.oldChild.cloneNode(!0);O.classList.add("diff-block-removed"),$.appendChild(O),H.newChild.classList.add("diff-block-added"),$.appendChild(H.newChild)}else{if(I1(H.oldChild,H.newChild,!1))U=!0;$.appendChild(H.newChild)}}else if(H.kind==="removed"){U=!0;let F=H.oldChild.cloneNode(!0);F.classList.add("diff-block-removed"),$.appendChild(F)}else U=!0,H.newChild.classList.add("diff-block-added"),$.appendChild(H.newChild);return U}function W2(J,$){let Y=$?new Set(Array.from(J.querySelectorAll("[data-md]"))):new Set,Z=[],Q=[],X=document.createTreeWalker(J,NodeFilter.SHOW_TEXT,{acceptNode(_){let z=_.parentElement;if(!z)return NodeFilter.FILTER_REJECT;if(z.closest("svg, .select-none, [data-no-diff]"))return NodeFilter.FILTER_REJECT;if($){for(let K of Y)if(K.contains(_))return NodeFilter.FILTER_REJECT}return NodeFilter.FILTER_ACCEPT}}),q;while(q=X.nextNode()){let z=(q.nodeValue||"").match(/\S+|\s+/g);if(!z)continue;let K=0;for(let G of z)Z.push(G),Q.push({text:G,node:q,offset:K}),K+=G.length}return{words:Z,map:Q}}function I1(J,$,Y){let Z=W2(J,Y),Q=W2($,Y);if(Z.words.length===0&&Q.words.length===0)return!1;let{oldOps:X,newOps:q}=$5(Z.words,Q.words),_=X.some((T)=>T.type==="removed"),z=q.some((T)=>T.type==="added");if(!_&&!z)return!1;let K=[],G=[];for(let T of X)if(T.type==="same")K.push(T.index);for(let T of q)if(T.type==="same")G.push(T.index);let U=new Map;for(let T=0;T<K.length&&T<G.length;T++)U.set(K[T],G[T]);let H=[];{let T=[],B=-1;for(let O of X)if(O.type==="same"){if(T.length>0)H.push({text:T.join(""),anchorNewIdx:B>=0?U.get(B)??null:null}),T=[];B=O.index}else if(O.type==="removed")T.push(Z.words[O.index]);if(T.length>0)H.push({text:T.join(""),anchorNewIdx:B>=0?U.get(B)??null:null})}let F=new Map,W=new Map;for(let T of q){if(T.type!=="added")continue;let B=Q.map[T.index];if(!B?.node.parentNode)continue;let O=F.get(B.node);if(!O)O=[],F.set(B.node,O);O.push({start:B.offset,end:B.offset+B.text.length})}for(let T of H)if(T.anchorNewIdx===null){if(Q.map.length>0){let B=Q.map[0].node,O=W.get(B);if(!O)O=[],W.set(B,O);O.push({offset:0,text:T.text})}}else{let B=Q.map[T.anchorNewIdx];if(!B)continue;let O=W.get(B.node);if(!O)O=[],W.set(B.node,O);O.push({offset:B.offset+B.text.length,text:T.text})}let L=new Set([...F.keys(),...W.keys()]);for(let T of L)d$(T,F.get(T)||[],W.get(T)||[]);return!0}function d$(J,$,Y){if(!J.parentNode)return;let Z=J.nodeValue||"";$.sort((G,U)=>G.start-U.start);let Q=[];for(let G of $){let U=Q[Q.length-1];if(U&&G.start<=U.end)U.end=Math.max(U.end,G.end);else Q.push({...G})}Y.sort((G,U)=>G.offset-U.offset);let X=J.parentNode,q=document.createDocumentFragment(),_=0,z=0,K=0;while(_<=Z.length){let G=z<Q.length?Q[z].start:1/0,U=K<Y.length?Y[K].offset:1/0,H=Math.min(G,U);if(H===1/0){if(_<Z.length)q.appendChild(document.createTextNode(Z.slice(_)));break}let F=Math.max(H,_);if(F>_)q.appendChild(document.createTextNode(Z.slice(_,F))),_=F;while(K<Y.length&&Y[K].offset<=_){let W=document.createElement("span");W.className="diff-removed",W.textContent=Y[K].text,q.appendChild(W),K++}if(z<Q.length&&Q[z].start<=_){let W=Q[z],L=document.createElement("span");L.className="diff-added",L.textContent=Z.slice(_,W.end),q.appendChild(L),_=W.end,z++;while(K<Y.length&&Y[K].offset<=_){let T=document.createElement("span");T.className="diff-removed",T.textContent=Y[K].text,q.appendChild(T),K++}}}while(K<Y.length){let G=document.createElement("span");G.className="diff-removed",G.textContent=Y[K].text,q.appendChild(G),K++}X.replaceChild(q,J)}function L2(J,$){let Y=(J.getAttribute("data-md-source")||"").trim(),Z=($.getAttribute("data-md-source")||"").trim();if(Y===Z)return!1;let Q=Y.split(`
86
- `),X=Z.split(`
87
- `),q=y1(Q,X),_=[],z=0,K=0,G=0;while(z<Q.length||K<X.length)if(G<q.length&&z<Q.length&&K<X.length&&Q[z]===q[G]&&X[K]===q[G])_.push({type:"same",line:Q[z]}),z++,K++,G++;else if(z<Q.length&&(G>=q.length||Q[z]!==q[G]))_.push({type:"removed",line:Q[z]}),z++;else if(K<X.length)_.push({type:"added",line:X[K]}),K++;let U=document.createElement("div");U.className="mt-2 bg-bg-code rounded-md overflow-hidden text-tiny font-mono",U.setAttribute("data-no-diff","true");for(let H of _){let F=document.createElement("div");if(F.className="px-3 py-0.5 whitespace-pre-wrap",H.type==="removed")F.classList.add("diff-removed"),F.textContent="- "+H.line;else if(H.type==="added")F.classList.add("diff-added"),F.textContent="+ "+H.line;else F.textContent=" "+H.line;U.appendChild(F)}return $.appendChild(U),!0}function Q5(J,$,Y){let Z=document.createElement("span");Z.className="diff-block-label",Z.textContent=$,Z.style.color=Y,Z.style.backgroundColor=`color-mix(in srgb, ${Y} 12%, transparent)`,J.appendChild(Z)}import{jsxDEV as E}from"react/jsx-dev-runtime";function P2({initialLeft:J,initialRight:$,sessionId:Y,onExit:Z}){let[Q,X]=Y1(J),[q,_]=Y1($),[z,K]=Y1("unified"),[G,U]=Y1(!0),[H,F]=Y1(!1);return E("div",{className:"flex flex-col h-screen",children:[E("div",{className:"flex items-center justify-between px-6 py-3 border-b border-border-subtle bg-bg-surface flex-shrink-0",children:[E("div",{className:"flex items-center gap-3",children:[E("span",{className:"text-[13px] font-body font-medium text-text-primary",children:"Compare"},void 0,!1,void 0,this),E(o1,{value:Q,onChange:X,accent:"red"},void 0,!1,void 0,this),E("span",{className:"text-text-tertiary text-[13px]",children:"→"},void 0,!1,void 0,this),E(o1,{value:q,onChange:_,accent:"green"},void 0,!1,void 0,this),H&&!G&&E("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),E("div",{className:"flex items-center gap-4",children:[E("div",{className:"flex items-center bg-bg-elevated rounded-md p-0.5",children:[E("button",{onClick:()=>K("unified"),className:`text-[11px] font-body px-2.5 py-1 rounded transition-colors ${z==="unified"?"bg-bg-surface text-text-primary font-medium shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Unified"},void 0,!1,void 0,this),E("button",{onClick:()=>K("side-by-side"),className:`text-[11px] font-body px-2.5 py-1 rounded transition-colors ${z==="side-by-side"?"bg-bg-surface text-text-primary font-medium shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Side-by-side"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z==="side-by-side"&&E(l$,{},void 0,!1,void 0,this),E("button",{onClick:Z,className:"text-[12px] font-body font-medium text-text-secondary hover:text-text-primary px-3 py-1.5 rounded-md hover:bg-bg-elevated transition-colors",children:"Exit Compare"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),z==="unified"?E(a$,{sessionId:Y,leftRev:Q,rightRev:q,onDiffResult:(W,L)=>{F(W),U(L)}},`unified-${Q}-${q}`,!1,void 0,this):E(i$,{sessionId:Y,leftRev:Q,rightRev:q,onDiffResult:(W,L)=>{F(W),U(L)}},`sbs-${Q}-${q}`,!1,void 0,this)]},void 0,!0,void 0,this)}function l$(){let[J,$]=Y1(!0);return E1(()=>{return document.documentElement.dataset.syncScroll=J?"1":"0",()=>{delete document.documentElement.dataset.syncScroll}},[J]),E("label",{className:"flex items-center gap-1.5 cursor-pointer select-none",children:[E("input",{type:"checkbox",checked:J,onChange:(Y)=>$(Y.target.checked),className:"accent-accent-amber w-3.5 h-3.5"},void 0,!1,void 0,this),E("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 a$({sessionId:J,leftRev:$,rightRev:Y,onDiffResult:Z}){let Q=W1(null),X=W1(null),q=W1(null),[_,z]=Y1(!1),[K,G]=Y1(!1),[U,H]=Y1(!1),{annotations:F}=o(),W=F.filter((T)=>!T.filePath),{popovers:L}=w1({containerRef:q,restoreKey:U,restoreAnnotations:W,extractContext:(T)=>P1(T,q.current)});return E1(()=>{if(!_||!K||U)return;if(!Q.current||!X.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!Q.current||!X.current||!q.current)return;let T=J5(Q.current),B=J5(X.current),O=Y5(T,B),{fragment:D,hasChanges:R}=F2(O);q.current.innerHTML="",q.current.appendChild(D),H(!0),Z(!0,R)})})},[_,K,U]),E("div",{className:"flex-1 min-h-0 overflow-y-auto",children:[!U&&E("div",{style:{position:"absolute",left:-9999,visibility:"hidden",pointerEvents:"none",width:720},children:[E(P0,{ref:Q,sessionId:J,revision:$,onReady:()=>z(!0)},void 0,!1,void 0,this),E(P0,{ref:X,sessionId:J,revision:Y,onReady:()=>G(!0)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),E("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:[!U&&E("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-body",children:"Loading..."},void 0,!1,void 0,this),E("div",{ref:q},void 0,!1,void 0,this)]},void 0,!0,void 0,this),L]},void 0,!0,void 0,this)}function i$({sessionId:J,leftRev:$,rightRev:Y,onDiffResult:Z}){let Q=W1(null),X=W1(null),[q,_]=Y1(!1),[z,K]=Y1(!1),[G,U]=Y1(!1),H=W1(null),F=W1(null),W=W1(null),L=W1(!1),T=B2(()=>_(!0),[]),B=B2(()=>K(!0),[]),{annotations:O}=o(),D=O.filter((P)=>!P.filePath),{popovers:R}=w1({containerRef:H,restoreKey:G,restoreAnnotations:D,extractContext:(P)=>P1(P,H.current)});return E1(()=>{if(!q||!z||G)return;if(!Q.current||!X.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!Q.current||!X.current)return;let P=H2(Q.current,X.current);U(!0),Z(!0,P)})})},[q,z,G]),E1(()=>{let P=F.current,k=W.current;if(!P||!k)return;let v=(j,V)=>{if(document.documentElement.dataset.syncScroll==="0")return;if(L.current)return;L.current=!0;let C=j.scrollHeight-j.clientHeight,I=V.scrollHeight-V.clientHeight;if(C>0&&I>0)V.scrollTop=j.scrollTop/C*I;requestAnimationFrame(()=>{L.current=!1})},g=()=>v(P,k),h=()=>v(k,P);return P.addEventListener("scroll",g),k.addEventListener("scroll",h),()=>{P.removeEventListener("scroll",g),k.removeEventListener("scroll",h)}},[]),E("div",{ref:H,className:"flex flex-1 min-h-0",children:[E("div",{ref:F,className:"w-1/2 overflow-y-auto border-r border-border-subtle",children:E("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:E(P0,{ref:Q,sessionId:J,revision:$,onReady:T},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),E("div",{ref:W,className:"w-1/2 overflow-y-auto",children:E("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:E(P0,{ref:X,sessionId:J,revision:Y,onReady:B},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),R]},void 0,!0,void 0,this)}var P0=M2.memo(M2.forwardRef(({sessionId:J,revision:$,onReady:Y},Z)=>{let[Q,X]=Y1(null),[q,_]=Y1(null),[z,K]=Y1(!0);E1(()=>{K(!0),_(null),import(`/api/session/${J}/plan.js?rev=${$}&t=${Date.now()}`).then((U)=>{X(()=>U.default),K(!1)}).catch((U)=>{_(U.message),K(!1)})},[J,$]),E1(()=>{if(!Q)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{Y()})})},[Q]);let G=r$(()=>Q?E(Q,{},void 0,!1,void 0,this):null,[Q]);if(z)return E("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-body",children:"Loading..."},void 0,!1,void 0,this);if(q)return E("div",{className:"bg-accent-red-muted rounded-lg p-5",children:[E("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Error"},void 0,!1,void 0,this),E("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(!Q)return E("div",{className:"text-text-tertiary text-center py-8 font-body text-body",children:"No canvas loaded"},void 0,!1,void 0,this);return E("div",{ref:Z,children:G},void 0,!1,void 0,this)}));import{jsxDEV as y,Fragment as Z5}from"react/jsx-dev-runtime";var C1=w2({activeView:{type:"plan"},setActiveView:()=>{},openFiles:[],closeFile:()=>{}}),v1=w2({currentRevision:1,selectedRevision:1,revisions:[],setSelectedRevision:()=>{},isReadOnly:!1,compareRevision:null,setCompareRevision:()=>{}});function R2(){let[J,$]=e(()=>localStorage.getItem("canvas-theme")||document.documentElement.dataset.theme||"dark");return y("button",{onClick:()=>{let Z=J==="dark"?"light":"dark";document.documentElement.dataset.theme=Z,localStorage.setItem("canvas-theme",Z),$(Z)},className:"w-7 h-7 flex items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:J==="dark"?"Switch to light theme":"Switch to dark theme",children:J==="dark"?y("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[y("circle",{cx:"12",cy:"12",r:"5"},void 0,!1,void 0,this),y("line",{x1:"12",y1:"1",x2:"12",y2:"3"},void 0,!1,void 0,this),y("line",{x1:"12",y1:"21",x2:"12",y2:"23"},void 0,!1,void 0,this),y("line",{x1:"4.22",y1:"4.22",x2:"5.64",y2:"5.64"},void 0,!1,void 0,this),y("line",{x1:"18.36",y1:"18.36",x2:"19.78",y2:"19.78"},void 0,!1,void 0,this),y("line",{x1:"1",y1:"12",x2:"3",y2:"12"},void 0,!1,void 0,this),y("line",{x1:"21",y1:"12",x2:"23",y2:"12"},void 0,!1,void 0,this),y("line",{x1:"4.22",y1:"19.78",x2:"5.64",y2:"18.36"},void 0,!1,void 0,this),y("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):y("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:y("path",{d:"M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function j2(){let{currentRevision:J,selectedRevision:$,revisions:Y,setSelectedRevision:Z,setCompareRevision:Q}=V1.useContext(v1);if(Y.length<=1){let _=Y[0]?.label||`Round ${J}`;return y("span",{className:"text-[11px] text-text-tertiary font-body",children:_},void 0,!1,void 0,this)}return y("div",{className:"flex flex-col gap-1",children:[y(o1,{value:$,onChange:Z,accent:$===J?"default":"amber"},void 0,!1,void 0,this),y("button",{onClick:()=>{let _=Y.find((K)=>K.revision===$)?.sourceFile,z;if($===J)z=[...Y].reverse().find((G)=>G.revision<J&&(!_||G.sourceFile===_))?.revision??Math.max(1,J-1);else z=$;Q({left:z,right:J})},className:"text-[11px] font-body font-medium px-2 py-0.5 rounded-md text-accent-blue hover:bg-accent-blue-muted transition-colors self-start",children:"Compare"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function n$(){let J=window.location.pathname.replace("/s/","")||"",[$,Y]=e(1),[Z,Q]=e(1),[X,q]=e([]),[_,z]=e(null),[K,G]=e(!1),[U,H]=e(!1),[F,W]=e({type:"plan"}),[L,T]=e([]),B=O1(null),[O,D]=e(),[R,P]=e(!1),[k,v]=e(!1),[g,h]=e(!1);F1(()=>{let N=["Agent Canvas"];if(O){let b=O.replace(/\/+$/,"").split("/");N.push(b[b.length-1]||J)}else if(J)N.push(J);if(F.type==="file")N.push(F.path.split("/").pop()||F.path);else if(_)N.push("Compare");document.title=N.join(" — ")},[J,O,F,_]);let j=O1(new Map),V=X.find((N)=>N.revision===Z),C=Z!==$||!!V?.hasFeedback,I=S0((N)=>{if(j.current.set(F.type==="plan"?"plan":`file:${F.path}`,window.scrollY),W(N),N.type==="file")T((b)=>b.includes(N.path)?b:[...b,N.path])},[F]),S=S0((N)=>{j.current.delete(`file:${N}`),T((b)=>b.filter((f)=>f!==N)),W((b)=>{if(b.type==="file"&&b.path===N)return j.current.set(`file:${N}`,window.scrollY),{type:"plan"};return b})},[]);s$(()=>{let N=F.type==="plan"?"plan":`file:${F.path}`;window.scrollTo(0,j.current.get(N)||0)},[F]),F1(()=>{if(!J)return;fetch(`/api/session/${J}/meta`).then((N)=>N.json()).then((N)=>{if(N.currentRevision)Y(N.currentRevision),Q(N.currentRevision),q(N.revisions||[]);if(N.projectRoot)D(N.projectRoot)}).catch(()=>{})},[J]),F1(()=>{if(!J)return;let N=null,b=()=>{let f=window.location.protocol==="https:"?"wss:":"ws:",u=new WebSocket(`${f}//${window.location.host}/ws/session/${J}`);B.current=u,u.onopen=()=>G(!0),u.onclose=()=>{G(!1),N=setTimeout(b,2000)},u.onmessage=(p)=>{try{let c=JSON.parse(p.data);if(c.type==="plan-updated"){if(Y(c.currentRevision),Q(c.currentRevision),z(null),c.revisions)q(c.revisions)}if(c.type==="revision-updated"){if(c.revisions)q(c.revisions)}}catch{}}};return b(),()=>{if(N)clearTimeout(N);B.current?.close()}},[J]);let w=S0((N)=>{if(B.current?.readyState===WebSocket.OPEN)B.current.send(JSON.stringify({type:"submit",feedback:N})),H(!1)},[]);if(!J)return y("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 y(A2.Provider,{value:J,children:y(v1.Provider,{value:{currentRevision:$,selectedRevision:Z,revisions:X,setSelectedRevision:Q,isReadOnly:C,compareRevision:_,setCompareRevision:z},children:y(R5,{sessionId:J,revision:Z,isReadOnly:C,children:y(C1.Provider,{value:{activeView:F,setActiveView:I,openFiles:L,closeFile:S},children:y(t$.Provider,{value:{setActiveView:I},children:y("div",{className:"min-h-screen bg-bg-base",children:[y(e$,{sessionId:J,projectRoot:O,connected:K,onMobileSidebar:()=>P(!R),collapsed:k,onToggle:()=>v((N)=>!N)},void 0,!1,void 0,this),y($4,{collapsed:g,onToggle:()=>h((N)=>!N),children:y(t0,{onPreview:()=>H(!0),onSubmit:w},void 0,!1,void 0,this)},void 0,!1,void 0,this),_!==null?y("div",{className:`${k?"lg:ml-0":"lg:ml-60"} ${g?"lg:mr-0":"lg:mr-[var(--sidebar-width,320px)]"} transition-[margin] duration-200`,children:y(P2,{initialLeft:_.left,initialRight:_.right,sessionId:J,onExit:()=>z(null)},void 0,!1,void 0,this)},void 0,!1,void 0,this):y("div",{className:`relative ${k?"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:[y("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:[y("div",{className:"flex items-center gap-2",children:[y(e0,{currentSessionId:J,projectRoot:O},void 0,!1,void 0,this),y("span",{className:`w-1.5 h-1.5 rounded-full ${K?"bg-accent-green":"bg-accent-red"}`},void 0,!1,void 0,this)]},void 0,!0,void 0,this),y("div",{className:"flex items-center gap-1",children:[y(j2,{},void 0,!1,void 0,this),y("button",{onClick:()=>P(!R),className:"w-7 h-7 flex items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Annotations",children:y("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:y("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(R2,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),y(Y4,{},void 0,!1,void 0,this),y("div",{style:{display:F.type==="plan"?void 0:"none"},children:y("div",{className:"relative max-w-[720px] mx-auto px-6 pt-12 pb-32",children:[y("button",{onClick:()=>{let N=document.querySelector(".plan-content");if(!N)return;let b=X2(N);navigator.clipboard.writeText(b).then(()=>{let f=document.getElementById("export-md-btn");if(f)f.setAttribute("data-copied","true"),setTimeout(()=>{f.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:[y("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:[y("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"},void 0,!1,void 0,this),y("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),y("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:y("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),V?.response&&y(J4,{markdown:V.response},void 0,!1,void 0,this),y(p5,{revision:Z},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),L.map((N)=>y("div",{style:{display:F.type==="file"&&F.path===N?void 0:"none"},children:y(Y2,{path:N},void 0,!1,void 0,this)},N,!1,void 0,this))]},void 0,!0,void 0,this),R&&y("div",{className:"lg:hidden fixed inset-0 z-40 flex",children:[y("div",{className:"flex-1",onClick:()=>P(!1)},void 0,!1,void 0,this),y("div",{className:"w-80 max-w-[85vw] bg-bg-surface border-l border-border-subtle flex flex-col shadow-lg",children:[y("div",{className:"flex items-center justify-between px-4 py-2 border-b border-border-subtle flex-shrink-0",children:[y("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:"Sidebar"},void 0,!1,void 0,this),y("button",{onClick:()=>P(!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),y("div",{className:"flex-1 overflow-hidden",children:y(t0,{onPreview:()=>H(!0),onSubmit:w},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),y(r5,{open:U,onClose:()=>H(!1),onSubmit:w},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},`${J}:${Z}`,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function e$({sessionId:J,projectRoot:$,connected:Y,onMobileSidebar:Z,collapsed:Q,onToggle:X}){return y(Z5,{children:[Q&&y("button",{onClick:X,className:"hidden lg:flex fixed top-3 left-3 z-20 w-7 h-7 items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors bg-bg-surface border border-border-subtle",title:"Show sidebar",children:y("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[y("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"},void 0,!1,void 0,this),y("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),y("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:[y("div",{className:"px-4 pt-4 pb-3 flex-shrink-0 border-b border-border-subtle",children:[y("div",{className:"flex items-center gap-2 mb-2",children:[y("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",className:"text-text-tertiary flex-shrink-0",children:y("path",{d:"M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this),y(e0,{currentSessionId:J,projectRoot:$},void 0,!1,void 0,this),y("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${Y?"bg-accent-green":"bg-accent-red"}`},void 0,!1,void 0,this),y("button",{onClick:X,className:"ml-auto w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Hide sidebar",children:y("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[y("polyline",{points:"11 17 6 12 11 7"},void 0,!1,void 0,this),y("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),y(j2,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this),y("div",{className:"flex-1 flex flex-col overflow-hidden",children:y(n5,{embedded:!0},void 0,!1,void 0,this)},void 0,!1,void 0,this),y("div",{className:"px-4 py-3 border-t border-border-subtle flex items-center justify-between flex-shrink-0",children:[y("span",{className:"text-[10px] text-text-tertiary font-body uppercase tracking-widest",children:"Theme"},void 0,!1,void 0,this),y(R2,{},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 $4({children:J,collapsed:$,onToggle:Y}){let[Z,Q]=e(()=>{let G=localStorage.getItem("canvas-sidebar-width");return G?parseInt(G,10):320}),X=O1(!1),q=O1(0),_=O1(0),z=O1(Z);z.current=Z;let K=S0((G)=>{G.preventDefault(),X.current=!0,q.current=G.clientX,_.current=z.current;let U=(F)=>{if(!X.current)return;let W=q.current-F.clientX,L=Math.max(240,Math.min(600,_.current+W));Q(L),z.current=L},H=()=>{X.current=!1,localStorage.setItem("canvas-sidebar-width",String(z.current)),document.removeEventListener("mousemove",U),document.removeEventListener("mouseup",H),document.body.style.cursor="",document.body.style.userSelect=""};document.addEventListener("mousemove",U),document.addEventListener("mouseup",H),document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[]);return F1(()=>{return document.documentElement.style.setProperty("--sidebar-width",`${Z}px`),()=>{document.documentElement.style.removeProperty("--sidebar-width")}},[Z]),y(Z5,{children:[$&&y("button",{onClick:Y,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:y("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:y("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("div",{className:`hidden lg:flex flex-col fixed top-0 right-0 bottom-0 bg-bg-surface border-l border-border-subtle z-10 transition-transform duration-200 ${$?"translate-x-full":""}`,style:{width:Z},children:[y("div",{onMouseDown:K,className:"absolute left-0 top-0 bottom-0 w-1 cursor-col-resize hover:bg-accent-blue/30 transition-colors z-20",style:{marginLeft:"-2px"}},void 0,!1,void 0,this),V1.Children.map(J,(G)=>V1.isValidElement(G)?V1.cloneElement(G,{collapseButton:y("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",title:"Hide annotations",children:y("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[y("polyline",{points:"13 17 18 12 13 7"},void 0,!1,void 0,this),y("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)}):G)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function J4({markdown:J}){let[$,Y]=e(!1),Z=S2(()=>r.parse(J,{async:!1}),[J]),Q=O1(null),{annotations:X,addAnnotationWithId:q,removeAnnotation:_,updateAnnotation:z,addAnnotationImage:K,removeAnnotationImage:G,activeAnnotationId:U,setActiveAnnotationId:H}=o(),[F,W]=e(null),[L,T]=e(null),B=S2(()=>X.filter((R)=>R.filePath===Q1),[X]);F1(()=>{Y(!1)},[J]),F1(()=>{if(!Q.current||B.length===0)return;let R=setTimeout(()=>{if(Q.current)K0(Q.current,B)},50);return()=>clearTimeout(R)},[Z,B.length]);let O=O1(null);if(F1(()=>{z0(U,O.current),O.current=U},[U]),F1(()=>{let R=Q.current;if(!R)return;let P=(g)=>{let h=g.target.closest("[data-annotation-id]");if(!h)return;g.stopPropagation();let j=h.getAttribute("data-annotation-id");if(j===U)T({anchorEl:h,annId:j});else H(j)},k=(g)=>{let h=g.target.closest("[data-annotation-id]");if(h)H(h.getAttribute("data-annotation-id"))},v=(g)=>{let h=g.target.closest("[data-annotation-id]"),j=g.relatedTarget?.closest?.("[data-annotation-id]");if(h&&!j)H(null)};return R.addEventListener("click",P),R.addEventListener("mouseover",k),R.addEventListener("mouseout",v),()=>{R.removeEventListener("click",P),R.removeEventListener("mouseover",k),R.removeEventListener("mouseout",v)}},[Z,U]),F1(()=>{let R=()=>{let P=window.getSelection();if(!P||P.isCollapsed||!P.toString().trim())return;if(!Q.current)return;let k=P.getRangeAt(0);if(!Q.current.contains(k.startContainer))return;if(k.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let v=P.toString().trim();if(v.length<2)return;let g=k.cloneRange(),h=P1(k,Q.current),j=`__pending_${Date.now()}`;try{b1(g,j)}catch{}window.getSelection()?.removeAllRanges();let V=document.querySelectorAll(`[data-annotation-id="${j}"]`),C=V[V.length-1];if(!C)return;W({anchorEl:C,tempId:j,snippet:v,ctx:h})};return document.addEventListener("mouseup",R),()=>document.removeEventListener("mouseup",R)},[]),$)return null;let D=document.getElementById("plan-scroll-container");return y("div",{className:"mb-6 rounded-lg border border-accent-blue/20 bg-accent-blue/5 relative",children:[y("button",{onClick:()=>Y(!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:y("span",{className:"text-xs",children:"✕"},void 0,!1,void 0,this)},void 0,!1,void 0,this),y("div",{className:"px-4 py-3 pr-10",children:[y("div",{className:"flex items-center gap-2 mb-1.5",children:[y("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:y("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),y("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),y("div",{ref:Q,className:"prose-canvas text-sm",dangerouslySetInnerHTML:{__html:Z}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F&&y(D1,{anchorEl:F.anchorEl,scrollContainer:D,snippet:F.snippet,truncateAt:80,onAdd:(R,P)=>{let k=z1();_0(F.tempId,k),q(k,F.snippet,R,Q1,F.ctx,P),W(null)},onCancel:()=>{U0(F.tempId),W(null)}},void 0,!1,void 0,this),L&&(()=>{let R=X.find((P)=>P.id===L.annId);if(!R)return null;return y(m1,{anchorEl:L.anchorEl,scrollContainer:D,initialNote:R.note,initialImages:R.images,onUpdate:(P,k)=>{z(L.annId,P);let v=R.images||[];for(let g of k)if(!v.includes(g))K(L.annId,g);for(let g of v)if(!k.includes(g))G(L.annId,g)},onDelete:()=>{_(L.annId),H(null)},onClose:()=>T(null)},void 0,!1,void 0,this)})()]},void 0,!0,void 0,this)}function Y4(){let{activeView:J,setActiveView:$,openFiles:Y,closeFile:Z}=V1.useContext(C1),Q=V1.useContext(A2),{addAnnotationWithId:X,setActiveAnnotationId:q}=o(),_=Y.length>0;if(!_)return null;return y("div",{className:"flex items-center border-b border-border-medium bg-bg-surface overflow-x-auto sticky top-0 z-10",children:[_&&y("button",{onClick:()=>$({type:"plan"}),className:`flex items-center gap-1.5 px-4 py-2.5 text-[13px] font-body whitespace-nowrap transition-colors relative ${J.type==="plan"?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[y("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",className:"opacity-60",children:y("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),"Canvas",J.type==="plan"&&y("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),_&&y(Z5,{children:[y("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this),Y.map((z,K)=>{let G=z.split("/").pop()||z,U=J.type==="file"&&J.path===z;return y(V1.Fragment,{children:[y("div",{className:"flex items-center",children:[y("button",{onClick:()=>$({type:"file",path:z}),className:`flex items-center gap-1.5 pl-3 pr-1 py-2.5 text-[13px] font-body whitespace-nowrap transition-colors relative ${U?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[y(N1,{name:G,type:"file"},void 0,!1,void 0,this),G,U&&y("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),y("button",{onClick:(H)=>{H.stopPropagation(),Z(z)},className:"text-text-tertiary hover:text-text-secondary px-1.5 py-1 text-[10px] transition-colors rounded hover:bg-bg-input",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),K<Y.length-1&&y("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this)]},z,!0,void 0,this)})]},void 0,!0,void 0,this),y("div",{className:"ml-auto flex items-center gap-1 flex-shrink-0",children:J.type==="file"&&y("button",{onClick:async()=>{let z=J.path;try{let G=await(await fetch(`/api/file?session=${Q}&path=${encodeURIComponent(z)}`)).json();if(!G.error){let U=G.content.split(`
85
+ `),F=y1(U,H),W=(L,y,B)=>{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 D=0,R=0;while(R<L.length){let P=document.createElement("div");if(P.className="px-3 py-0.5 whitespace-pre-wrap",D<y.length&&L[R]===y[D])P.textContent=" "+L[R],R++,D++;else P.classList.add(B==="old"?"diff-removed":"diff-added"),P.textContent=(B==="old"?"- ":"+ ")+L[R],R++;O.appendChild(P)}return O};_.appendChild(W(U,F,"old")),z.appendChild(W(H,F,"new"))}return Q}function J5(J){let $=[],Y=J.querySelectorAll(":scope > [data-md]");for(let Z of Y)$.push(t1(Z));if($.length===0){let Z=J.querySelectorAll("[data-md]"),Q=new Set;for(let q of Z){let X=q.parentElement?.closest("[data-md]");if(X&&J.contains(X))continue;if(Q.has(q))continue;Q.add(q),$.push(t1(q))}}return $}function t1(J){let $=J.getAttribute("data-md")||"unknown",Y=x$(J,$),Z=[];if($==="section"){let Q=J.querySelector(":scope > div.mt-6, :scope > div:last-child");if(Q)for(let q of Q.querySelectorAll(":scope > [data-md]"))Z.push(t1(q))}else if($==="table")for(let Q of J.querySelectorAll(":scope table > tbody > tr"))Z.push({key:"tr:"+(Q.textContent||"").slice(0,80),type:"tr",element:Q,children:[]});else if($==="checklist")for(let Q of J.querySelectorAll(":scope > [data-md='checklist-item']"))Z.push(t1(Q));else for(let Q of J.querySelectorAll("[data-md]"))if(Q.parentElement?.closest("[data-md]")===J)Z.push(t1(Q));return{key:Y,type:$,element:J,children:Z}}function x$(J,$){switch($){case"section":return"section:"+(J.getAttribute("data-md-title")||"");case"item":return"item:"+(J.getAttribute("data-task-id")||J.getAttribute("data-md-label")||"");case"codeblock":case"diff":return $+":"+(J.textContent||"").slice(0,80);case"checklist-item":return"checklist-item:"+(J.getAttribute("data-md-label")||J.textContent?.slice(0,60)||"");case"checklist":return"checklist:"+J.querySelectorAll("[data-md='checklist-item']").length;case"markdown":return"markdown:"+(J.getAttribute("data-md-file")||"inline");case"mermaid":return"mermaid:"+(J.getAttribute("data-md-source")||"").slice(0,80);case"callout":return"callout:"+(J.getAttribute("data-md-type")||"")+":"+(J.textContent||"").slice(0,60);default:return $+":"+(J.getAttribute("data-md-label")||J.textContent?.slice(0,60)||"")}}function Y5(J,$){let Y=J.map((K)=>K.key),Z=$.map((K)=>K.key),Q=y1(Y,Z),q=[],X=0,_=0,z=0;while(X<J.length||_<$.length)if(z<Q.length&&X<J.length&&_<$.length&&Y[X]===Q[z]&&Z[_]===Q[z]){let K=J[X],G=$[_],U=K.children.length>0||G.children.length>0?Y5(K.children,G.children):void 0;q.push({kind:"matched",oldBlock:K,newBlock:G,childMatches:U}),X++,_++,z++}else if(X<J.length&&(z>=Q.length||Y[X]!==Q[z]))q.push({kind:"removed",oldBlock:J[X]}),X++;else if(_<$.length)q.push({kind:"added",newBlock:$[_]}),_++;return q}function F2(J){let $=document.createDocumentFragment(),Y=!1;for(let Z of J)if(Z.kind==="removed")Y=!0,$.appendChild(N2(Z.oldBlock.element));else if(Z.kind==="added")Y=!0,$.appendChild(h$(Z.newBlock.element));else{let Q=Z.newBlock.element.cloneNode(!0),q=Z.newBlock.type;if(q==="mermaid"){if(L2(Z.oldBlock.element,Q))Y=!0}else if(Z.childMatches&&Z.childMatches.length>0&&(q==="table"||q==="checklist")){if(y2(Q,Z.childMatches,q))Y=!0}else if(Z.childMatches&&Z.childMatches.length>0){if(T2(Z.oldBlock,Q,Z.childMatches,q))Y=!0}else if(q==="markdown"){if(O2(Z.oldBlock.element,Q))Y=!0}else if(I1(Z.oldBlock.element,Q,!1))Y=!0;$.appendChild(Q)}return{fragment:$,hasChanges:Y}}function N2(J){let $=J.cloneNode(!0);return $.classList.add("diff-block-removed"),$.style.position="relative",Q5($,"Removed","var(--color-accent-red)"),$}function h$(J){let $=J.cloneNode(!0);return $.classList.add("diff-block-added"),$.style.position="relative",Q5($,"Added","var(--color-accent-green)"),$}function T2(J,$,Y,Z){let Q=!1,q=p$(J,$),X,_;if(Z==="section"){let z=J.element.querySelector(":scope > div:first-child"),K=$.querySelector(":scope > div:first-child");if(z&&K){if(I1(z,K,!1))Q=!0}X=J.element.querySelector(":scope > div.mt-6, :scope > div:last-child"),_=$.querySelector(":scope > div.mt-6, :scope > div:last-child")}else X=J.element,_=$;if(!X||!_)return Q;for(let z of Y)if(z.kind==="matched"){let K=q.newMap.get(z.newBlock.element);if(K){if(z.newBlock.type==="mermaid"){if(L2(z.oldBlock.element,K))Q=!0}else if(z.childMatches&&z.childMatches.length>0&&(z.newBlock.type==="table"||z.newBlock.type==="checklist")){if(y2(K,z.childMatches,z.newBlock.type))Q=!0}else if(z.childMatches&&z.childMatches.length>0){if(T2(z.oldBlock,K,z.childMatches,z.newBlock.type))Q=!0}else if(z.newBlock.type==="markdown"){if(O2(z.oldBlock.element,K))Q=!0}else if(I1(z.oldBlock.element,K,!1))Q=!0}}else if(z.kind==="removed"){Q=!0;let K=N2(z.oldBlock.element),G=d$(Y,z,q.newMap);_.insertBefore(K,G)}else if(z.kind==="added"){Q=!0;let K=q.newMap.get(z.newBlock.element);if(K)K.classList.add("diff-block-added"),K.style.position="relative",Q5(K,"Added","var(--color-accent-green)")}if(I1(X,_,!0))Q=!0;return Q}function y2(J,$,Y){let Z=Y==="table"?J.querySelector(":scope table > tbody"):J;if(!Z)return!1;let Q=!1;Z.innerHTML="";for(let q of $)if(q.kind==="removed"){Q=!0;let X=q.oldBlock.element.cloneNode(!0);X.classList.add(Y==="table"?"diff-row-removed":"diff-item-removed"),Z.appendChild(X)}else if(q.kind==="added"){Q=!0;let X=q.newBlock.element.cloneNode(!0);X.classList.add(Y==="table"?"diff-row-added":"diff-item-added"),Z.appendChild(X)}else{let X=q.newBlock.element.cloneNode(!0);if(I1(q.oldBlock.element,X,!1))Q=!0;Z.appendChild(X)}return Q}function p$(J,$){let Y=new Map,Z=J.element.querySelectorAll("[data-md]"),Q=$.querySelectorAll("[data-md]");return{newMap:{get(q){return c$($,q)}}}}function c$(J,$){let Y=$.getAttribute("data-md");if(!Y)return null;let Z=$.getAttribute("data-md-label"),Q=$.getAttribute("data-md-title"),q=`[data-md="${Y}"]`;if(Q)q+=`[data-md-title="${CSS.escape(Q)}"]`;else if(Z)q+=`[data-md-label="${CSS.escape(Z)}"]`;let X=J.querySelectorAll(q);if(X.length===1)return X[0];let _=($.textContent||"").slice(0,100),z=null,K=-1;for(let G of X){let U=(G.textContent||"").slice(0,100),H=0;for(let F=0;F<Math.min(_.length,U.length);F++)if(_[F]===U[F])H++;if(H>K)K=H,z=G}return z}function d$(J,$,Y){let Z=J.indexOf($);for(let Q=Z+1;Q<J.length;Q++){let q=J[Q];if((q.kind==="matched"||q.kind==="added")&&q.newBlock)return Y.get(q.newBlock.element)||null}return null}function O2(J,$){let Y=Array.from(J.children),Z=Array.from($.children);if(Y.length===0&&Z.length===0)return I1(J,$,!1);let Q=Y.map((H)=>H.tagName.toLowerCase()),q=Z.map((H)=>H.tagName.toLowerCase()),X=y1(Q,q),_=[],z=0,K=0,G=0;while(z<Y.length||K<Z.length)if(G<X.length&&z<Y.length&&K<Z.length&&Q[z]===X[G]&&q[K]===X[G])_.push({kind:"matched",oldChild:Y[z],newChild:Z[K]}),z++,K++,G++;else if(z<Y.length&&(G>=X.length||Q[z]!==X[G]))_.push({kind:"removed",oldChild:Y[z]}),z++;else if(K<Z.length)_.push({kind:"added",newChild:Z[K]}),K++;let U=!1;while($.firstChild)$.removeChild($.firstChild);for(let H of _)if(H.kind==="matched"){let F=(H.oldChild.textContent||"").match(/\S+/g)||[],W=(H.newChild.textContent||"").match(/\S+/g)||[],L=y1(F,W),y=Math.max(F.length,W.length);if((y>0?1-L.length/y:0)>0.5){U=!0;let O=H.oldChild.cloneNode(!0);O.classList.add("diff-block-removed"),$.appendChild(O),H.newChild.classList.add("diff-block-added"),$.appendChild(H.newChild)}else{if(I1(H.oldChild,H.newChild,!1))U=!0;$.appendChild(H.newChild)}}else if(H.kind==="removed"){U=!0;let F=H.oldChild.cloneNode(!0);F.classList.add("diff-block-removed"),$.appendChild(F)}else U=!0,H.newChild.classList.add("diff-block-added"),$.appendChild(H.newChild);return U}function W2(J,$){let Y=$?new Set(Array.from(J.querySelectorAll("[data-md]"))):new Set,Z=[],Q=[],q=document.createTreeWalker(J,NodeFilter.SHOW_TEXT,{acceptNode(_){let z=_.parentElement;if(!z)return NodeFilter.FILTER_REJECT;if(z.closest("svg, .select-none, [data-no-diff]"))return NodeFilter.FILTER_REJECT;if($){for(let K of Y)if(K.contains(_))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 K=0;for(let G of z)Z.push(G),Q.push({text:G,node:X,offset:K}),K+=G.length}return{words:Z,map:Q}}function I1(J,$,Y){let Z=W2(J,Y),Q=W2($,Y);if(Z.words.length===0&&Q.words.length===0)return!1;let{oldOps:q,newOps:X}=$5(Z.words,Q.words),_=q.some((y)=>y.type==="removed"),z=X.some((y)=>y.type==="added");if(!_&&!z)return!1;let K=[],G=[];for(let y of q)if(y.type==="same")K.push(y.index);for(let y of X)if(y.type==="same")G.push(y.index);let U=new Map;for(let y=0;y<K.length&&y<G.length;y++)U.set(K[y],G[y]);let H=[];{let y=[],B=-1;for(let O of q)if(O.type==="same"){if(y.length>0)H.push({text:y.join(""),anchorNewIdx:B>=0?U.get(B)??null:null}),y=[];B=O.index}else if(O.type==="removed")y.push(Z.words[O.index]);if(y.length>0)H.push({text:y.join(""),anchorNewIdx:B>=0?U.get(B)??null:null})}let F=new Map,W=new Map;for(let y of X){if(y.type!=="added")continue;let B=Q.map[y.index];if(!B?.node.parentNode)continue;let O=F.get(B.node);if(!O)O=[],F.set(B.node,O);O.push({start:B.offset,end:B.offset+B.text.length})}for(let y of H)if(y.anchorNewIdx===null){if(Q.map.length>0){let B=Q.map[0].node,O=W.get(B);if(!O)O=[],W.set(B,O);O.push({offset:0,text:y.text})}}else{let B=Q.map[y.anchorNewIdx];if(!B)continue;let O=W.get(B.node);if(!O)O=[],W.set(B.node,O);O.push({offset:B.offset+B.text.length,text:y.text})}let L=new Set([...F.keys(),...W.keys()]);for(let y of L)r$(y,F.get(y)||[],W.get(y)||[]);return!0}function r$(J,$,Y){if(!J.parentNode)return;let Z=J.nodeValue||"";$.sort((G,U)=>G.start-U.start);let Q=[];for(let G of $){let U=Q[Q.length-1];if(U&&G.start<=U.end)U.end=Math.max(U.end,G.end);else Q.push({...G})}Y.sort((G,U)=>G.offset-U.offset);let q=J.parentNode,X=document.createDocumentFragment(),_=0,z=0,K=0;while(_<=Z.length){let G=z<Q.length?Q[z].start:1/0,U=K<Y.length?Y[K].offset:1/0,H=Math.min(G,U);if(H===1/0){if(_<Z.length)X.appendChild(document.createTextNode(Z.slice(_)));break}let F=Math.max(H,_);if(F>_)X.appendChild(document.createTextNode(Z.slice(_,F))),_=F;while(K<Y.length&&Y[K].offset<=_){let W=document.createElement("span");W.className="diff-removed",W.textContent=Y[K].text,X.appendChild(W),K++}if(z<Q.length&&Q[z].start<=_){let W=Q[z],L=document.createElement("span");L.className="diff-added",L.textContent=Z.slice(_,W.end),X.appendChild(L),_=W.end,z++;while(K<Y.length&&Y[K].offset<=_){let y=document.createElement("span");y.className="diff-removed",y.textContent=Y[K].text,X.appendChild(y),K++}}}while(K<Y.length){let G=document.createElement("span");G.className="diff-removed",G.textContent=Y[K].text,X.appendChild(G),K++}q.replaceChild(X,J)}function L2(J,$){let Y=(J.getAttribute("data-md-source")||"").trim(),Z=($.getAttribute("data-md-source")||"").trim();if(Y===Z)return!1;let Q=Y.split(`
86
+ `),q=Z.split(`
87
+ `),X=y1(Q,q),_=[],z=0,K=0,G=0;while(z<Q.length||K<q.length)if(G<X.length&&z<Q.length&&K<q.length&&Q[z]===X[G]&&q[K]===X[G])_.push({type:"same",line:Q[z]}),z++,K++,G++;else if(z<Q.length&&(G>=X.length||Q[z]!==X[G]))_.push({type:"removed",line:Q[z]}),z++;else if(K<q.length)_.push({type:"added",line:q[K]}),K++;let U=document.createElement("div");U.className="mt-2 bg-bg-code rounded-md overflow-hidden text-tiny font-mono",U.setAttribute("data-no-diff","true");for(let H of _){let F=document.createElement("div");if(F.className="px-3 py-0.5 whitespace-pre-wrap",H.type==="removed")F.classList.add("diff-removed"),F.textContent="- "+H.line;else if(H.type==="added")F.classList.add("diff-added"),F.textContent="+ "+H.line;else F.textContent=" "+H.line;U.appendChild(F)}return $.appendChild(U),!0}function Q5(J,$,Y){let Z=document.createElement("span");Z.className="diff-block-label",Z.textContent=$,Z.style.color=Y,Z.style.backgroundColor=`color-mix(in srgb, ${Y} 12%, transparent)`,J.appendChild(Z)}import{jsxDEV as E}from"react/jsx-dev-runtime";function P2({initialLeft:J,initialRight:$,sessionId:Y,onExit:Z}){let[Q,q]=Y1(J),[X,_]=Y1($),[z,K]=Y1("unified"),[G,U]=Y1(!0),[H,F]=Y1(!1);return E("div",{className:"flex flex-col h-screen",children:[E("div",{className:"flex items-center justify-between px-6 py-3 border-b border-border-subtle bg-bg-surface flex-shrink-0",children:[E("div",{className:"flex items-center gap-3",children:[E("span",{className:"text-[13px] font-body font-medium text-text-primary",children:"Compare"},void 0,!1,void 0,this),E(o1,{value:Q,onChange:q,accent:"red"},void 0,!1,void 0,this),E("span",{className:"text-text-tertiary text-[13px]",children:"→"},void 0,!1,void 0,this),E(o1,{value:X,onChange:_,accent:"green"},void 0,!1,void 0,this),H&&!G&&E("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),E("div",{className:"flex items-center gap-4",children:[E("div",{className:"flex items-center bg-bg-elevated rounded-md p-0.5",children:[E("button",{onClick:()=>K("unified"),className:`text-[11px] font-body px-2.5 py-1 rounded transition-colors ${z==="unified"?"bg-bg-surface text-text-primary font-medium shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Unified"},void 0,!1,void 0,this),E("button",{onClick:()=>K("side-by-side"),className:`text-[11px] font-body px-2.5 py-1 rounded transition-colors ${z==="side-by-side"?"bg-bg-surface text-text-primary font-medium shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Side-by-side"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z==="side-by-side"&&E(a$,{},void 0,!1,void 0,this),E("button",{onClick:Z,className:"text-[12px] font-body font-medium text-text-secondary hover:text-text-primary px-3 py-1.5 rounded-md hover:bg-bg-elevated transition-colors",children:"Exit Compare"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),z==="unified"?E(i$,{sessionId:Y,leftRev:Q,rightRev:X,onDiffResult:(W,L)=>{F(W),U(L)}},`unified-${Q}-${X}`,!1,void 0,this):E(s$,{sessionId:Y,leftRev:Q,rightRev:X,onDiffResult:(W,L)=>{F(W),U(L)}},`sbs-${Q}-${X}`,!1,void 0,this)]},void 0,!0,void 0,this)}function a$(){let[J,$]=Y1(!0);return E1(()=>{return document.documentElement.dataset.syncScroll=J?"1":"0",()=>{delete document.documentElement.dataset.syncScroll}},[J]),E("label",{className:"flex items-center gap-1.5 cursor-pointer select-none",children:[E("input",{type:"checkbox",checked:J,onChange:(Y)=>$(Y.target.checked),className:"accent-accent-amber w-3.5 h-3.5"},void 0,!1,void 0,this),E("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 i$({sessionId:J,leftRev:$,rightRev:Y,onDiffResult:Z}){let Q=F1(null),q=F1(null),X=F1(null),[_,z]=Y1(!1),[K,G]=Y1(!1),[U,H]=Y1(!1),{annotations:F}=o(),W=F.filter((y)=>!y.filePath),{popovers:L}=w1({containerRef:X,restoreKey:U,restoreAnnotations:W,extractContext:(y)=>P1(y,X.current)});return E1(()=>{if(!_||!K||U)return;if(!Q.current||!q.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!Q.current||!q.current||!X.current)return;let y=J5(Q.current),B=J5(q.current),O=Y5(y,B),{fragment:D,hasChanges:R}=F2(O);X.current.innerHTML="",X.current.appendChild(D),H(!0),Z(!0,R)})})},[_,K,U]),E("div",{className:"flex-1 min-h-0 overflow-y-auto",children:[!U&&E("div",{style:{position:"absolute",left:-9999,visibility:"hidden",pointerEvents:"none",width:720},children:[E(P0,{ref:Q,sessionId:J,revision:$,onReady:()=>z(!0)},void 0,!1,void 0,this),E(P0,{ref:q,sessionId:J,revision:Y,onReady:()=>G(!0)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),E("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:[!U&&E("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-body",children:"Loading..."},void 0,!1,void 0,this),E("div",{ref:X},void 0,!1,void 0,this)]},void 0,!0,void 0,this),L]},void 0,!0,void 0,this)}function s$({sessionId:J,leftRev:$,rightRev:Y,onDiffResult:Z}){let Q=F1(null),q=F1(null),[X,_]=Y1(!1),[z,K]=Y1(!1),[G,U]=Y1(!1),H=F1(null),F=F1(null),W=F1(null),L=F1(!1),y=B2(()=>_(!0),[]),B=B2(()=>K(!0),[]),{annotations:O}=o(),D=O.filter((P)=>!P.filePath),{popovers:R}=w1({containerRef:H,restoreKey:G,restoreAnnotations:D,extractContext:(P)=>P1(P,H.current)});return E1(()=>{if(!X||!z||G)return;if(!Q.current||!q.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!Q.current||!q.current)return;let P=H2(Q.current,q.current);U(!0),Z(!0,P)})})},[X,z,G]),E1(()=>{let P=F.current,k=W.current;if(!P||!k)return;let v=(j,V)=>{if(document.documentElement.dataset.syncScroll==="0")return;if(L.current)return;L.current=!0;let C=j.scrollHeight-j.clientHeight,I=V.scrollHeight-V.clientHeight;if(C>0&&I>0)V.scrollTop=j.scrollTop/C*I;requestAnimationFrame(()=>{L.current=!1})},g=()=>v(P,k),h=()=>v(k,P);return P.addEventListener("scroll",g),k.addEventListener("scroll",h),()=>{P.removeEventListener("scroll",g),k.removeEventListener("scroll",h)}},[]),E("div",{ref:H,className:"flex flex-1 min-h-0",children:[E("div",{ref:F,className:"w-1/2 overflow-y-auto border-r border-border-subtle",children:E("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:E(P0,{ref:Q,sessionId:J,revision:$,onReady:y},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),E("div",{ref:W,className:"w-1/2 overflow-y-auto",children:E("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:E(P0,{ref:q,sessionId:J,revision:Y,onReady:B},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),R]},void 0,!0,void 0,this)}var P0=M2.memo(M2.forwardRef(({sessionId:J,revision:$,onReady:Y},Z)=>{let[Q,q]=Y1(null),[X,_]=Y1(null),[z,K]=Y1(!0);E1(()=>{K(!0),_(null),import(`/api/session/${J}/plan.js?rev=${$}&t=${Date.now()}`).then((U)=>{q(()=>U.default),K(!1)}).catch((U)=>{_(U.message),K(!1)})},[J,$]),E1(()=>{if(!Q)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{Y()})})},[Q]);let G=l$(()=>Q?E(Q,{},void 0,!1,void 0,this):null,[Q]);if(z)return E("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(X)return E("div",{className:"bg-accent-red-muted rounded-lg p-5",children:[E("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Error"},void 0,!1,void 0,this),E("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:X},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(!Q)return E("div",{className:"text-text-tertiary text-center py-8 font-body text-body",children:"No canvas loaded"},void 0,!1,void 0,this);return E("div",{ref:Z,children:G},void 0,!1,void 0,this)}));import{jsxDEV as T,Fragment as Z5}from"react/jsx-dev-runtime";var C1=A2({activeView:{type:"plan"},setActiveView:()=>{},openFiles:[],closeFile:()=>{}}),v1=A2({currentRevision:1,selectedRevision:1,revisions:[],setSelectedRevision:()=>{},isReadOnly:!1,compareRevision:null,setCompareRevision:()=>{}});function e$(J){if(J==="auto")return window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light";return J}function b2(J){document.documentElement.dataset.theme=e$(J)}function j2(){let[J,$]=e(()=>{let Q=localStorage.getItem("canvas-theme");if(Q==="light"||Q==="dark"||Q==="auto")return Q;return"auto"});return H1(()=>{if(b2(J),J!=="auto")return;let Q=window.matchMedia("(prefers-color-scheme: dark)"),q=()=>b2("auto");return Q.addEventListener("change",q),()=>Q.removeEventListener("change",q)},[J]),T("button",{onClick:()=>{let Q=J==="auto"?"light":J==="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)"}[J],children:J==="auto"?T("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[T("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2",ry:"2"},void 0,!1,void 0,this),T("line",{x1:"8",y1:"21",x2:"16",y2:"21"},void 0,!1,void 0,this),T("line",{x1:"12",y1:"17",x2:"12",y2:"21"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):J==="dark"?T("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:T("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):T("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[T("circle",{cx:"12",cy:"12",r:"5"},void 0,!1,void 0,this),T("line",{x1:"12",y1:"1",x2:"12",y2:"3"},void 0,!1,void 0,this),T("line",{x1:"12",y1:"21",x2:"12",y2:"23"},void 0,!1,void 0,this),T("line",{x1:"4.22",y1:"4.22",x2:"5.64",y2:"5.64"},void 0,!1,void 0,this),T("line",{x1:"18.36",y1:"18.36",x2:"19.78",y2:"19.78"},void 0,!1,void 0,this),T("line",{x1:"1",y1:"12",x2:"3",y2:"12"},void 0,!1,void 0,this),T("line",{x1:"21",y1:"12",x2:"23",y2:"12"},void 0,!1,void 0,this),T("line",{x1:"4.22",y1:"19.78",x2:"5.64",y2:"18.36"},void 0,!1,void 0,this),T("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 C2(){let{currentRevision:J,selectedRevision:$,revisions:Y,setSelectedRevision:Z,setCompareRevision:Q}=V1.useContext(v1);if(Y.length<=1){let _=Y[0]?.label||`Round ${J}`;return T("span",{className:"text-[11px] text-text-tertiary font-body",children:_},void 0,!1,void 0,this)}return T("div",{className:"flex flex-col gap-1",children:[T(o1,{value:$,onChange:Z,accent:$===J?"default":"amber"},void 0,!1,void 0,this),T("button",{onClick:()=>{let _=Y.find((K)=>K.revision===$)?.sourceFile,z;if($===J)z=[...Y].reverse().find((G)=>G.revision<J&&(!_||G.sourceFile===_))?.revision??Math.max(1,J-1);else z=$;Q({left:z,right:J})},className:"text-[11px] font-body font-medium px-2 py-0.5 rounded-md text-accent-blue hover:bg-accent-blue-muted transition-colors self-start",children:"Compare"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function $4(){let J=window.location.pathname.replace("/s/","")||"",[$,Y]=e(1),[Z,Q]=e(1),[q,X]=e([]),[_,z]=e(null),[K,G]=e(!1),[U,H]=e(!1),[F,W]=e({type:"plan"}),[L,y]=e([]),B=O1(null),[O,D]=e(),[R,P]=e(!1),[k,v]=e(!1),[g,h]=e(!1);H1(()=>{let N=["Agent Canvas"];if(O){let b=O.replace(/\/+$/,"").split("/");N.push(b[b.length-1]||J)}else if(J)N.push(J);if(F.type==="file")N.push(F.path.split("/").pop()||F.path);else if(_)N.push("Compare");document.title=N.join(" — ")},[J,O,F,_]);let j=O1(new Map),V=q.find((N)=>N.revision===Z),C=Z!==$||!!V?.hasFeedback,I=S0((N)=>{if(j.current.set(F.type==="plan"?"plan":`file:${F.path}`,window.scrollY),W(N),N.type==="file")y((b)=>b.includes(N.path)?b:[...b,N.path])},[F]),S=S0((N)=>{j.current.delete(`file:${N}`),y((b)=>b.filter((f)=>f!==N)),W((b)=>{if(b.type==="file"&&b.path===N)return j.current.set(`file:${N}`,window.scrollY),{type:"plan"};return b})},[]);o$(()=>{let N=F.type==="plan"?"plan":`file:${F.path}`;window.scrollTo(0,j.current.get(N)||0)},[F]),H1(()=>{if(!J)return;fetch(`/api/session/${J}/meta`).then((N)=>N.json()).then((N)=>{if(N.currentRevision)Y(N.currentRevision),Q(N.currentRevision),X(N.revisions||[]);if(N.projectRoot)D(N.projectRoot)}).catch(()=>{})},[J]),H1(()=>{if(!J)return;let N=null,b=()=>{let f=window.location.protocol==="https:"?"wss:":"ws:",u=new WebSocket(`${f}//${window.location.host}/ws/session/${J}`);B.current=u,u.onopen=()=>G(!0),u.onclose=()=>{G(!1),N=setTimeout(b,2000)},u.onmessage=(p)=>{try{let c=JSON.parse(p.data);if(c.type==="plan-updated"){if(Y(c.currentRevision),Q(c.currentRevision),z(null),c.revisions)X(c.revisions)}if(c.type==="revision-updated"){if(c.revisions)X(c.revisions)}}catch{}}};return b(),()=>{if(N)clearTimeout(N);B.current?.close()}},[J]);let w=S0((N)=>{if(B.current?.readyState===WebSocket.OPEN)B.current.send(JSON.stringify({type:"submit",feedback:N})),H(!1)},[]);if(!J)return T("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 T(R2.Provider,{value:J,children:T(v1.Provider,{value:{currentRevision:$,selectedRevision:Z,revisions:q,setSelectedRevision:Q,isReadOnly:C,compareRevision:_,setCompareRevision:z},children:T(R5,{sessionId:J,revision:Z,isReadOnly:C,children:T(C1.Provider,{value:{activeView:F,setActiveView:I,openFiles:L,closeFile:S},children:T(n$.Provider,{value:{setActiveView:I},children:T("div",{className:"min-h-screen bg-bg-base",children:[T(J4,{sessionId:J,projectRoot:O,connected:K,onMobileSidebar:()=>P(!R),collapsed:k,onToggle:()=>v((N)=>!N)},void 0,!1,void 0,this),T(Y4,{collapsed:g,onToggle:()=>h((N)=>!N),children:T(t0,{onPreview:()=>H(!0),onSubmit:w},void 0,!1,void 0,this)},void 0,!1,void 0,this),_!==null?T("div",{className:`${k?"lg:ml-0":"lg:ml-60"} ${g?"lg:mr-0":"lg:mr-[var(--sidebar-width,320px)]"} transition-[margin] duration-200`,children:T(P2,{initialLeft:_.left,initialRight:_.right,sessionId:J,onExit:()=>z(null)},void 0,!1,void 0,this)},void 0,!1,void 0,this):T("div",{className:`relative ${k?"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:[T("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:[T("div",{className:"flex items-center gap-2",children:[T(e0,{currentSessionId:J,projectRoot:O},void 0,!1,void 0,this),T("span",{className:`w-1.5 h-1.5 rounded-full ${K?"bg-accent-green":"bg-accent-red"}`},void 0,!1,void 0,this)]},void 0,!0,void 0,this),T("div",{className:"flex items-center gap-1",children:[T(C2,{},void 0,!1,void 0,this),T("button",{onClick:()=>P(!R),className:"w-7 h-7 flex items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Annotations",children:T("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:T("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),T(j2,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),T(Z4,{},void 0,!1,void 0,this),T("div",{style:{display:F.type==="plan"?void 0:"none"},children:T("div",{className:"relative max-w-[720px] mx-auto px-6 pt-12 pb-32",children:[T("button",{onClick:()=>{let N=document.querySelector(".plan-content");if(!N)return;let b=q2(N);navigator.clipboard.writeText(b).then(()=>{let f=document.getElementById("export-md-btn");if(f)f.setAttribute("data-copied","true"),setTimeout(()=>{f.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:[T("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:[T("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"},void 0,!1,void 0,this),T("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),T("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:T("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),V?.response&&T(Q4,{markdown:V.response},void 0,!1,void 0,this),T(p5,{revision:Z},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),L.map((N)=>T("div",{style:{display:F.type==="file"&&F.path===N?void 0:"none"},children:T(Y2,{path:N},void 0,!1,void 0,this)},N,!1,void 0,this))]},void 0,!0,void 0,this),R&&T("div",{className:"lg:hidden fixed inset-0 z-40 flex",children:[T("div",{className:"flex-1",onClick:()=>P(!1)},void 0,!1,void 0,this),T("div",{className:"w-80 max-w-[85vw] bg-bg-surface border-l border-border-subtle flex flex-col shadow-lg",children:[T("div",{className:"flex items-center justify-between px-4 py-2 border-b border-border-subtle flex-shrink-0",children:[T("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:"Sidebar"},void 0,!1,void 0,this),T("button",{onClick:()=>P(!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),T("div",{className:"flex-1 overflow-hidden",children:T(t0,{onPreview:()=>H(!0),onSubmit:w},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),T(r5,{open:U,onClose:()=>H(!1),onSubmit:w},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},`${J}:${Z}`,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function J4({sessionId:J,projectRoot:$,connected:Y,onMobileSidebar:Z,collapsed:Q,onToggle:q}){return T(Z5,{children:[Q&&T("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:T("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[T("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"},void 0,!1,void 0,this),T("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),T("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:[T("div",{className:"px-4 pt-4 pb-3 flex-shrink-0 border-b border-border-subtle",children:[T("div",{className:"flex items-center gap-2 mb-2",children:[T("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",className:"text-text-tertiary flex-shrink-0",children:T("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),T(e0,{currentSessionId:J,projectRoot:$},void 0,!1,void 0,this),T("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${Y?"bg-accent-green":"bg-accent-red"}`},void 0,!1,void 0,this),T("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:T("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[T("polyline",{points:"11 17 6 12 11 7"},void 0,!1,void 0,this),T("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),T(C2,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this),T("div",{className:"flex-1 flex flex-col overflow-hidden",children:T(n5,{embedded:!0},void 0,!1,void 0,this)},void 0,!1,void 0,this),T("div",{className:"px-4 py-3 border-t border-border-subtle flex items-center justify-between flex-shrink-0",children:[T("span",{className:"text-[10px] text-text-tertiary font-body uppercase tracking-widest",children:"Theme"},void 0,!1,void 0,this),T(j2,{},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 Y4({children:J,collapsed:$,onToggle:Y}){let[Z,Q]=e(()=>{let G=localStorage.getItem("canvas-sidebar-width");return G?parseInt(G,10):320}),q=O1(!1),X=O1(0),_=O1(0),z=O1(Z);z.current=Z;let K=S0((G)=>{G.preventDefault(),q.current=!0,X.current=G.clientX,_.current=z.current;let U=(F)=>{if(!q.current)return;let W=X.current-F.clientX,L=Math.max(240,Math.min(600,_.current+W));Q(L),z.current=L},H=()=>{q.current=!1,localStorage.setItem("canvas-sidebar-width",String(z.current)),document.removeEventListener("mousemove",U),document.removeEventListener("mouseup",H),document.body.style.cursor="",document.body.style.userSelect=""};document.addEventListener("mousemove",U),document.addEventListener("mouseup",H),document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[]);return H1(()=>{return document.documentElement.style.setProperty("--sidebar-width",`${Z}px`),()=>{document.documentElement.style.removeProperty("--sidebar-width")}},[Z]),T(Z5,{children:[$&&T("button",{onClick:Y,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:T("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:T("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),T("div",{className:`hidden lg:flex flex-col fixed top-0 right-0 bottom-0 bg-bg-surface border-l border-border-subtle z-10 transition-transform duration-200 ${$?"translate-x-full":""}`,style:{width:Z},children:[T("div",{onMouseDown:K,className:"absolute left-0 top-0 bottom-0 w-1 cursor-col-resize hover:bg-accent-blue/30 transition-colors z-20",style:{marginLeft:"-2px"}},void 0,!1,void 0,this),V1.Children.map(J,(G)=>V1.isValidElement(G)?V1.cloneElement(G,{collapseButton:T("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",title:"Hide annotations",children:T("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[T("polyline",{points:"13 17 18 12 13 7"},void 0,!1,void 0,this),T("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)}):G)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function Q4({markdown:J}){let[$,Y]=e(!1),Z=S2(()=>r.parse(J,{async:!1}),[J]),Q=O1(null),{annotations:q,addAnnotationWithId:X,removeAnnotation:_,updateAnnotation:z,addAnnotationImage:K,removeAnnotationImage:G,activeAnnotationId:U,setActiveAnnotationId:H}=o(),[F,W]=e(null),[L,y]=e(null),B=S2(()=>q.filter((R)=>R.filePath===Q1),[q]);H1(()=>{Y(!1)},[J]),H1(()=>{if(!Q.current||B.length===0)return;let R=setTimeout(()=>{if(Q.current)K0(Q.current,B)},50);return()=>clearTimeout(R)},[Z,B.length]);let O=O1(null);if(H1(()=>{z0(U,O.current),O.current=U},[U]),H1(()=>{let R=Q.current;if(!R)return;let P=(g)=>{let h=g.target.closest("[data-annotation-id]");if(!h)return;g.stopPropagation();let j=h.getAttribute("data-annotation-id");if(j===U)y({anchorEl:h,annId:j});else H(j)},k=(g)=>{let h=g.target.closest("[data-annotation-id]");if(h)H(h.getAttribute("data-annotation-id"))},v=(g)=>{let h=g.target.closest("[data-annotation-id]"),j=g.relatedTarget?.closest?.("[data-annotation-id]");if(h&&!j)H(null)};return R.addEventListener("click",P),R.addEventListener("mouseover",k),R.addEventListener("mouseout",v),()=>{R.removeEventListener("click",P),R.removeEventListener("mouseover",k),R.removeEventListener("mouseout",v)}},[Z,U]),H1(()=>{let R=()=>{let P=window.getSelection();if(!P||P.isCollapsed||!P.toString().trim())return;if(!Q.current)return;let k=P.getRangeAt(0);if(!Q.current.contains(k.startContainer))return;if(k.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let v=P.toString().trim();if(v.length<2)return;let g=k.cloneRange(),h=P1(k,Q.current),j=`__pending_${Date.now()}`;try{b1(g,j)}catch{}window.getSelection()?.removeAllRanges();let V=document.querySelectorAll(`[data-annotation-id="${j}"]`),C=V[V.length-1];if(!C)return;W({anchorEl:C,tempId:j,snippet:v,ctx:h})};return document.addEventListener("mouseup",R),()=>document.removeEventListener("mouseup",R)},[]),$)return null;let D=document.getElementById("plan-scroll-container");return T("div",{className:"mb-6 rounded-lg border border-accent-blue/20 bg-accent-blue/5 relative",children:[T("button",{onClick:()=>Y(!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:T("span",{className:"text-xs",children:"✕"},void 0,!1,void 0,this)},void 0,!1,void 0,this),T("div",{className:"px-4 py-3 pr-10",children:[T("div",{className:"flex items-center gap-2 mb-1.5",children:[T("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:T("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),T("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),T("div",{ref:Q,className:"prose-canvas text-sm",dangerouslySetInnerHTML:{__html:Z}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F&&T(D1,{anchorEl:F.anchorEl,scrollContainer:D,snippet:F.snippet,truncateAt:80,onAdd:(R,P)=>{let k=z1();_0(F.tempId,k),X(k,F.snippet,R,Q1,F.ctx,P),W(null)},onCancel:()=>{U0(F.tempId),W(null)}},void 0,!1,void 0,this),L&&(()=>{let R=q.find((P)=>P.id===L.annId);if(!R)return null;return T(m1,{anchorEl:L.anchorEl,scrollContainer:D,initialNote:R.note,initialImages:R.images,onUpdate:(P,k)=>{z(L.annId,P);let v=R.images||[];for(let g of k)if(!v.includes(g))K(L.annId,g);for(let g of v)if(!k.includes(g))G(L.annId,g)},onDelete:()=>{_(L.annId),H(null)},onClose:()=>y(null)},void 0,!1,void 0,this)})()]},void 0,!0,void 0,this)}function Z4(){let{activeView:J,setActiveView:$,openFiles:Y,closeFile:Z}=V1.useContext(C1),Q=V1.useContext(R2),{addAnnotationWithId:q,setActiveAnnotationId:X}=o(),_=Y.length>0;if(!_)return null;return T("div",{className:"flex items-center border-b border-border-medium bg-bg-surface overflow-x-auto sticky top-0 z-10",children:[_&&T("button",{onClick:()=>$({type:"plan"}),className:`flex items-center gap-1.5 px-4 py-2.5 text-[13px] font-body whitespace-nowrap transition-colors relative ${J.type==="plan"?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[T("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",className:"opacity-60",children:T("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),"Canvas",J.type==="plan"&&T("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),_&&T(Z5,{children:[T("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this),Y.map((z,K)=>{let G=z.split("/").pop()||z,U=J.type==="file"&&J.path===z;return T(V1.Fragment,{children:[T("div",{className:"flex items-center",children:[T("button",{onClick:()=>$({type:"file",path:z}),className:`flex items-center gap-1.5 pl-3 pr-1 py-2.5 text-[13px] font-body whitespace-nowrap transition-colors relative ${U?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[T(N1,{name:G,type:"file"},void 0,!1,void 0,this),G,U&&T("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),T("button",{onClick:(H)=>{H.stopPropagation(),Z(z)},className:"text-text-tertiary hover:text-text-secondary px-1.5 py-1 text-[10px] transition-colors rounded hover:bg-bg-input",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),K<Y.length-1&&T("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this)]},z,!0,void 0,this)})]},void 0,!0,void 0,this),T("div",{className:"ml-auto flex items-center gap-1 flex-shrink-0",children:J.type==="file"&&T("button",{onClick:async()=>{let z=J.path;try{let G=await(await fetch(`/api/file?session=${Q}&path=${encodeURIComponent(z)}`)).json();if(!G.error){let U=G.content.split(`
88
88
  `).slice(0,3).join(`
89
89
  `)+(G.content.split(`
90
90
  `).length>3?`
91
- ...`:""),H=z1();X(H,U,"",z),q(H)}}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:[y("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 b2=document.getElementById("root");if(b2)o$(b2).render(y(n$,{},void 0,!1,void 0,this));export{v1 as RevisionContext,C1 as ActiveViewContext};
91
+ ...`:""),H=z1();q(H,U,"",z),X(H)}}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:[T("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 w2=document.getElementById("root");if(w2)t$(w2).render(T($4,{},void 0,!1,void 0,this));export{v1 as RevisionContext,C1 as ActiveViewContext};