agent-canvas 0.1.8 → 0.1.9

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,50 +1,50 @@
1
- import g1,{useEffect as X0,useLayoutEffect as m$,useState as Q1,useCallback as C0,useRef as d1,createContext as W2,useMemo as j$}from"react";import{createRoot as I$}from"react-dom/client";function I0(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var R1=I0();function U5(J){R1=J}var A1={exec:()=>null};function v(J,$=""){let Q=typeof J=="string"?J:J.source,Z={replace:(Y,X)=>{let q=typeof X=="string"?X:X.source;return q=q.replace(J1.caret,"$1"),Q=Q.replace(Y,q),Z},getRegex:()=>new RegExp(Q,$)};return Z}var y2=(()=>{try{return!!new RegExp("(?<=1)(?<!1)")}catch{return!1}})(),J1={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] +\S/,listReplaceTask:/^\[[ xX]\] +/,listTaskCheckbox:/\[[ xX]\]/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:(J)=>new RegExp(`^( {0,3}${J})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:(J)=>new RegExp(`^ {0,${Math.min(3,J-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:(J)=>new RegExp(`^ {0,${Math.min(3,J-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:(J)=>new RegExp(`^ {0,${Math.min(3,J-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:(J)=>new RegExp(`^ {0,${Math.min(3,J-1)}}#`),htmlBeginRegex:(J)=>new RegExp(`^ {0,${Math.min(3,J-1)}}<(?:[a-z].*>|!--)`,"i"),blockquoteBeginRegex:(J)=>new RegExp(`^ {0,${Math.min(3,J-1)}}>`)},M2=/^(?:[ \t]*(?:\n|$))+/,B2=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,L2=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,s1=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,P2=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,V0=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,G5=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,H5=v(G5).replace(/bull/g,V0).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,"").getRegex(),S2=v(G5).replace(/bull/g,V0).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),g0=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,b2=/^[^\n]+/,D0=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,A2=v(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",D0).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),w2=v(/^(bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,V0).getRegex(),H0="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",f0=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,R2=v("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$))","i").replace("comment",f0).replace("tag",H0).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),N5=v(g0).replace("hr",s1).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",H0).getRegex(),C2=v(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",N5).getRegex(),k0={blockquote:C2,code:B2,def:A2,fences:L2,heading:P2,hr:s1,html:R2,lheading:H5,list:w2,newline:M2,paragraph:N5,table:A1,text:b2},Z5=v("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",s1).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3}\t)[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",H0).getRegex(),m2={...k0,lheading:S2,table:Z5,paragraph:v(g0).replace("hr",s1).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",Z5).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",H0).getRegex()},j2={...k0,html:v(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",f0).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:A1,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:v(g0).replace("hr",s1).replace("heading",` *#{1,6} *[^
2
- ]`).replace("lheading",H5).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},I2=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,V2=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,W5=/^( {2,}|\\)\n(?!\s*$)/,g2=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,N0=/[\p{P}\p{S}]/u,u0=/[\s\p{P}\p{S}]/u,T5=/[^\s\p{P}\p{S}]/u,D2=v(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,u0).getRegex(),O5=/(?!~)[\p{P}\p{S}]/u,f2=/(?!~)[\s\p{P}\p{S}]/u,k2=/(?:[^\s\p{P}\p{S}]|~)/u,F5=/(?![*_])[\p{P}\p{S}]/u,u2=/(?![*_])[\s\p{P}\p{S}]/u,v2=/(?:[^\s\p{P}\p{S}]|[*_])/u,E2=v(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",y2?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),y5=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,x2=v(y5,"u").replace(/punct/g,N0).getRegex(),h2=v(y5,"u").replace(/punct/g,O5).getRegex(),M5="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",p2=v(M5,"gu").replace(/notPunctSpace/g,T5).replace(/punctSpace/g,u0).replace(/punct/g,N0).getRegex(),c2=v(M5,"gu").replace(/notPunctSpace/g,k2).replace(/punctSpace/g,f2).replace(/punct/g,O5).getRegex(),d2=v("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,T5).replace(/punctSpace/g,u0).replace(/punct/g,N0).getRegex(),r2=v(/^~~?(?:((?!~)punct)|[^\s~])/,"u").replace(/punct/g,F5).getRegex(),l2="^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)",a2=v(l2,"gu").replace(/notPunctSpace/g,v2).replace(/punctSpace/g,u2).replace(/punct/g,F5).getRegex(),i2=v(/\\(punct)/,"gu").replace(/punct/g,N0).getRegex(),o2=v(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme",/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email",/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),s2=v(f0).replace("(?:-->|$)","-->").getRegex(),t2=v("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment",s2).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),K0=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+[^`]*?`+(?!`)|[^\[\]\\`])*?/,n2=v(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace("label",K0).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),B5=v(/^!?\[(label)\]\[(ref)\]/).replace("label",K0).replace("ref",D0).getRegex(),L5=v(/^!?\[(ref)\](?:\[\])?/).replace("ref",D0).getRegex(),e2=v("reflink|nolink(?!\\()","g").replace("reflink",B5).replace("nolink",L5).getRegex(),q5=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,v0={_backpedal:A1,anyPunctuation:i2,autolink:o2,blockSkip:E2,br:W5,code:V2,del:A1,delLDelim:A1,delRDelim:A1,emStrongLDelim:x2,emStrongRDelimAst:p2,emStrongRDelimUnd:d2,escape:I2,link:n2,nolink:L5,punctuation:D2,reflink:B5,reflinkSearch:e2,tag:t2,text:g2,url:A1},$3={...v0,link:v(/^!?\[(label)\]\((.*?)\)/).replace("label",K0).getRegex(),reflink:v(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",K0).getRegex()},j0={...v0,emStrongRDelimAst:c2,emStrongLDelim:h2,delLDelim:r2,delRDelim:a2,url:v(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol",q5).replace("email",/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/,text:v(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace("protocol",q5).getRegex()},J3={...j0,br:v(W5).replace("{2,}","*").getRegex(),text:v(j0.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},_0={normal:k0,gfm:m2,pedantic:j2},a1={normal:v0,gfm:j0,breaks:J3,pedantic:$3},Y3={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},X5=(J)=>Y3[J];function G1(J,$){if($){if(J1.escapeTest.test(J))return J.replace(J1.escapeReplace,X5)}else if(J1.escapeTestNoEncode.test(J))return J.replace(J1.escapeReplaceNoEncode,X5);return J}function z5(J){try{J=encodeURI(J).replace(J1.percentDecode,"%")}catch{return null}return J}function _5(J,$){let Q=J.replace(J1.findPipe,(X,q,_)=>{let z=!1,K=q;for(;--K>=0&&_[K]==="\\";)z=!z;return z?"|":" |"}),Z=Q.split(J1.splitPipe),Y=0;if(Z[0].trim()||Z.shift(),Z.length>0&&!Z.at(-1)?.trim()&&Z.pop(),$)if(Z.length>$)Z.splice($);else for(;Z.length<$;)Z.push("");for(;Y<Z.length;Y++)Z[Y]=Z[Y].trim().replace(J1.slashPipe,"|");return Z}function i1(J,$,Q){let Z=J.length;if(Z===0)return"";let Y=0;for(;Y<Z;){let X=J.charAt(Z-Y-1);if(X===$&&!Q)Y++;else if(X!==$&&Q)Y++;else break}return J.slice(0,Z-Y)}function Q3(J,$){if(J.indexOf($[1])===-1)return-1;let Q=0;for(let Z=0;Z<J.length;Z++)if(J[Z]==="\\")Z++;else if(J[Z]===$[0])Q++;else if(J[Z]===$[1]&&(Q--,Q<0))return Z;return Q>0?-2:-1}function Z3(J,$=0){let Q=$,Z="";for(let Y of J)if(Y==="\t"){let X=4-Q%4;Z+=" ".repeat(X),Q+=X}else Z+=Y,Q++;return Z}function K5(J,$,Q,Z,Y){let X=$.href,q=$.title||null,_=J[1].replace(Y.other.outputLinkReplace,"$1");Z.state.inLink=!0;let z={type:J[0].charAt(0)==="!"?"image":"link",raw:Q,href:X,title:q,text:_,tokens:Z.inlineTokens(_)};return Z.state.inLink=!1,z}function q3(J,$,Q){let Z=J.match(Q.other.indentCodeCompensation);if(Z===null)return $;let Y=Z[1];return $.split(`
3
- `).map((X)=>{let q=X.match(Q.other.beginningSpace);if(q===null)return X;let[_]=q;return _.length>=Y.length?X.slice(Y.length):X}).join(`
4
- `)}var U0=class{options;rules;lexer;constructor(J){this.options=J||R1}space(J){let $=this.rules.block.newline.exec(J);if($&&$[0].length>0)return{type:"space",raw:$[0]}}code(J){let $=this.rules.block.code.exec(J);if($){let Q=$[0].replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:$[0],codeBlockStyle:"indented",text:this.options.pedantic?Q:i1(Q,`
5
- `)}}}fences(J){let $=this.rules.block.fences.exec(J);if($){let Q=$[0],Z=q3(Q,$[3]||"",this.rules);return{type:"code",raw:Q,lang:$[2]?$[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):$[2],text:Z}}}heading(J){let $=this.rules.block.heading.exec(J);if($){let Q=$[2].trim();if(this.rules.other.endingHash.test(Q)){let Z=i1(Q,"#");(this.options.pedantic||!Z||this.rules.other.endingSpaceChar.test(Z))&&(Q=Z.trim())}return{type:"heading",raw:$[0],depth:$[1].length,text:Q,tokens:this.lexer.inline(Q)}}}hr(J){let $=this.rules.block.hr.exec(J);if($)return{type:"hr",raw:i1($[0],`
6
- `)}}blockquote(J){let $=this.rules.block.blockquote.exec(J);if($){let Q=i1($[0],`
1
+ import E1,{useEffect as T1,useLayoutEffect as I$,useState as e,useCallback as I0,useRef as w1,createContext as T2,useMemo as y2}from"react";import{createRoot as V$}from"react-dom/client";function D0(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var I1=D0();function F5(J){I1=J}var j1={exec:()=>null};function E(J,$=""){let Q=typeof J=="string"?J:J.source,Z={replace:(Y,X)=>{let q=typeof X=="string"?X:X.source;return q=q.replace(Y1.caret,"$1"),Q=Q.replace(Y,q),Z},getRegex:()=>new RegExp(Q,$)};return Z}var L2=(()=>{try{return!!new RegExp("(?<=1)(?<!1)")}catch{return!1}})(),Y1={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)}}>`)},P2=/^(?:[ \t]*(?:\n|$))+/,S2=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,b2=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,Z0=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,w2=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,f0=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,y5=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,N5=E(y5).replace(/bull/g,f0).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,"").getRegex(),C2=E(y5).replace(/bull/g,f0).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(),k0=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,A2=/^[^\n]+/,u0=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,R2=E(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",u0).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),j2=E(/^(bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,f0).getRegex(),T0="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",v0=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,m2=E("^ {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",v0).replace("tag",T0).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),T5=E(k0).replace("hr",Z0).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",T0).getRegex(),I2=E(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",T5).getRegex(),E0={blockquote:I2,code:S2,def:R2,fences:b2,heading:w2,hr:Z0,html:m2,lheading:N5,list:j2,newline:P2,paragraph:T5,table:j1,text:A2},K5=E("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",Z0).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",T0).getRegex(),V2={...E0,lheading:C2,table:K5,paragraph:E(k0).replace("hr",Z0).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",K5).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",T0).getRegex()},g2={...E0,html:E(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",v0).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:j1,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:E(k0).replace("hr",Z0).replace("heading",` *#{1,6} *[^
2
+ ]`).replace("lheading",N5).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},D2=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,f2=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,O5=/^( {2,}|\\)\n(?!\s*$)/,k2=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,O0=/[\p{P}\p{S}]/u,x0=/[\s\p{P}\p{S}]/u,B5=/[^\s\p{P}\p{S}]/u,u2=E(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,x0).getRegex(),M5=/(?!~)[\p{P}\p{S}]/u,v2=/(?!~)[\s\p{P}\p{S}]/u,E2=/(?:[^\s\p{P}\p{S}]|~)/u,L5=/(?![*_])[\p{P}\p{S}]/u,x2=/(?![*_])[\s\p{P}\p{S}]/u,h2=/(?:[^\s\p{P}\p{S}]|[*_])/u,p2=E(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",L2?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),P5=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,c2=E(P5,"u").replace(/punct/g,O0).getRegex(),d2=E(P5,"u").replace(/punct/g,M5).getRegex(),S5="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",r2=E(S5,"gu").replace(/notPunctSpace/g,B5).replace(/punctSpace/g,x0).replace(/punct/g,O0).getRegex(),l2=E(S5,"gu").replace(/notPunctSpace/g,E2).replace(/punctSpace/g,v2).replace(/punct/g,M5).getRegex(),a2=E("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,B5).replace(/punctSpace/g,x0).replace(/punct/g,O0).getRegex(),i2=E(/^~~?(?:((?!~)punct)|[^\s~])/,"u").replace(/punct/g,L5).getRegex(),o2="^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)",s2=E(o2,"gu").replace(/notPunctSpace/g,h2).replace(/punctSpace/g,x2).replace(/punct/g,L5).getRegex(),t2=E(/\\(punct)/,"gu").replace(/punct/g,O0).getRegex(),n2=E(/^<(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(),e2=E(v0).replace("(?:-->|$)","-->").getRegex(),$3=E("^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",e2).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),F0=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+[^`]*?`+(?!`)|[^\[\]\\`])*?/,J3=E(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace("label",F0).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),b5=E(/^!?\[(label)\]\[(ref)\]/).replace("label",F0).replace("ref",u0).getRegex(),w5=E(/^!?\[(ref)\](?:\[\])?/).replace("ref",u0).getRegex(),Y3=E("reflink|nolink(?!\\()","g").replace("reflink",b5).replace("nolink",w5).getRegex(),_5=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,h0={_backpedal:j1,anyPunctuation:t2,autolink:n2,blockSkip:p2,br:O5,code:f2,del:j1,delLDelim:j1,delRDelim:j1,emStrongLDelim:c2,emStrongRDelimAst:r2,emStrongRDelimUnd:a2,escape:D2,link:J3,nolink:w5,punctuation:u2,reflink:b5,reflinkSearch:Y3,tag:$3,text:k2,url:j1},Q3={...h0,link:E(/^!?\[(label)\]\((.*?)\)/).replace("label",F0).getRegex(),reflink:E(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",F0).getRegex()},g0={...h0,emStrongRDelimAst:l2,emStrongLDelim:d2,delLDelim:i2,delRDelim:s2,url:E(/^((?: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:E(/^([`~]+|[^`~])(?:(?= {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()},Z3={...g0,br:E(O5).replace("{2,}","*").getRegex(),text:E(g0.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},W0={normal:E0,gfm:V2,pedantic:g2},J0={normal:h0,gfm:g0,breaks:Z3,pedantic:Q3},q3={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},U5=(J)=>q3[J];function W1(J,$){if($){if(Y1.escapeTest.test(J))return J.replace(Y1.escapeReplace,U5)}else if(Y1.escapeTestNoEncode.test(J))return J.replace(Y1.escapeReplaceNoEncode,U5);return J}function G5(J){try{J=encodeURI(J).replace(Y1.percentDecode,"%")}catch{return null}return J}function H5(J,$){let Q=J.replace(Y1.findPipe,(X,q,K)=>{let z=!1,_=q;for(;--_>=0&&K[_]==="\\";)z=!z;return z?"|":" |"}),Z=Q.split(Y1.splitPipe),Y=0;if(Z[0].trim()||Z.shift(),Z.length>0&&!Z.at(-1)?.trim()&&Z.pop(),$)if(Z.length>$)Z.splice($);else for(;Z.length<$;)Z.push("");for(;Y<Z.length;Y++)Z[Y]=Z[Y].trim().replace(Y1.slashPipe,"|");return Z}function Y0(J,$,Q){let Z=J.length;if(Z===0)return"";let Y=0;for(;Y<Z;){let X=J.charAt(Z-Y-1);if(X===$&&!Q)Y++;else if(X!==$&&Q)Y++;else break}return J.slice(0,Z-Y)}function X3(J,$){if(J.indexOf($[1])===-1)return-1;let Q=0;for(let Z=0;Z<J.length;Z++)if(J[Z]==="\\")Z++;else if(J[Z]===$[0])Q++;else if(J[Z]===$[1]&&(Q--,Q<0))return Z;return Q>0?-2:-1}function z3(J,$=0){let Q=$,Z="";for(let Y of J)if(Y==="\t"){let X=4-Q%4;Z+=" ".repeat(X),Q+=X}else Z+=Y,Q++;return Z}function W5(J,$,Q,Z,Y){let X=$.href,q=$.title||null,K=J[1].replace(Y.other.outputLinkReplace,"$1");Z.state.inLink=!0;let z={type:J[0].charAt(0)==="!"?"image":"link",raw:Q,href:X,title:q,text:K,tokens:Z.inlineTokens(K)};return Z.state.inLink=!1,z}function K3(J,$,Q){let Z=J.match(Q.other.indentCodeCompensation);if(Z===null)return $;let Y=Z[1];return $.split(`
3
+ `).map((X)=>{let q=X.match(Q.other.beginningSpace);if(q===null)return X;let[K]=q;return K.length>=Y.length?X.slice(Y.length):X}).join(`
4
+ `)}var y0=class{options;rules;lexer;constructor(J){this.options=J||I1}space(J){let $=this.rules.block.newline.exec(J);if($&&$[0].length>0)return{type:"space",raw:$[0]}}code(J){let $=this.rules.block.code.exec(J);if($){let Q=$[0].replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:$[0],codeBlockStyle:"indented",text:this.options.pedantic?Q:Y0(Q,`
5
+ `)}}}fences(J){let $=this.rules.block.fences.exec(J);if($){let Q=$[0],Z=K3(Q,$[3]||"",this.rules);return{type:"code",raw:Q,lang:$[2]?$[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):$[2],text:Z}}}heading(J){let $=this.rules.block.heading.exec(J);if($){let Q=$[2].trim();if(this.rules.other.endingHash.test(Q)){let Z=Y0(Q,"#");(this.options.pedantic||!Z||this.rules.other.endingSpaceChar.test(Z))&&(Q=Z.trim())}return{type:"heading",raw:$[0],depth:$[1].length,text:Q,tokens:this.lexer.inline(Q)}}}hr(J){let $=this.rules.block.hr.exec(J);if($)return{type:"hr",raw:Y0($[0],`
6
+ `)}}blockquote(J){let $=this.rules.block.blockquote.exec(J);if($){let Q=Y0($[0],`
7
7
  `).split(`
8
- `),Z="",Y="",X=[];for(;Q.length>0;){let q=!1,_=[],z;for(z=0;z<Q.length;z++)if(this.rules.other.blockquoteStart.test(Q[z]))_.push(Q[z]),q=!0;else if(!q)_.push(Q[z]);else break;Q=Q.slice(z);let K=_.join(`
9
- `),U=K.replace(this.rules.other.blockquoteSetextReplace,`
8
+ `),Z="",Y="",X=[];for(;Q.length>0;){let q=!1,K=[],z;for(z=0;z<Q.length;z++)if(this.rules.other.blockquoteStart.test(Q[z]))K.push(Q[z]),q=!0;else if(!q)K.push(Q[z]);else break;Q=Q.slice(z);let _=K.join(`
9
+ `),U=_.replace(this.rules.other.blockquoteSetextReplace,`
10
10
  $1`).replace(this.rules.other.blockquoteSetextReplace2,"");Z=Z?`${Z}
11
- ${K}`:K,Y=Y?`${Y}
12
- ${U}`:U;let H=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(U,X,!0),this.lexer.state.top=H,Q.length===0)break;let G=X.at(-1);if(G?.type==="code")break;if(G?.type==="blockquote"){let N=G,W=N.raw+`
11
+ ${_}`:_,Y=Y?`${Y}
12
+ ${U}`:U;let G=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(U,X,!0),this.lexer.state.top=G,Q.length===0)break;let H=X.at(-1);if(H?.type==="code")break;if(H?.type==="blockquote"){let F=H,W=F.raw+`
13
13
  `+Q.join(`
14
- `),M=this.blockquote(W);X[X.length-1]=M,Z=Z.substring(0,Z.length-N.raw.length)+M.raw,Y=Y.substring(0,Y.length-N.text.length)+M.text;break}else if(G?.type==="list"){let N=G,W=N.raw+`
14
+ `),B=this.blockquote(W);X[X.length-1]=B,Z=Z.substring(0,Z.length-F.raw.length)+B.raw,Y=Y.substring(0,Y.length-F.text.length)+B.text;break}else if(H?.type==="list"){let F=H,W=F.raw+`
15
15
  `+Q.join(`
16
- `),M=this.list(W);X[X.length-1]=M,Z=Z.substring(0,Z.length-G.raw.length)+M.raw,Y=Y.substring(0,Y.length-N.raw.length)+M.raw,Q=W.substring(X.at(-1).raw.length).split(`
17
- `);continue}}return{type:"blockquote",raw:Z,tokens:X,text:Y}}}list(J){let $=this.rules.block.list.exec(J);if($){let Q=$[1].trim(),Z=Q.length>1,Y={type:"list",raw:"",ordered:Z,start:Z?+Q.slice(0,-1):"",loose:!1,items:[]};Q=Z?`\\d{1,9}\\${Q.slice(-1)}`:`\\${Q}`,this.options.pedantic&&(Q=Z?Q:"[*+-]");let X=this.rules.other.listItemRegex(Q),q=!1;for(;J;){let z=!1,K="",U="";if(!($=X.exec(J))||this.rules.block.hr.test(J))break;K=$[0],J=J.substring(K.length);let H=Z3($[2].split(`
18
- `,1)[0],$[1].length),G=J.split(`
19
- `,1)[0],N=!H.trim(),W=0;if(this.options.pedantic?(W=2,U=H.trimStart()):N?W=$[1].length+1:(W=H.search(this.rules.other.nonSpaceChar),W=W>4?1:W,U=H.slice(W),W+=$[1].length),N&&this.rules.other.blankLine.test(G)&&(K+=G+`
20
- `,J=J.substring(G.length+1),z=!0),!z){let M=this.rules.other.nextBulletRegex(W),F=this.rules.other.hrRegex(W),L=this.rules.other.fencesBeginRegex(W),y=this.rules.other.headingBeginRegex(W),S=this.rules.other.htmlBeginRegex(W),R=this.rules.other.blockquoteBeginRegex(W);for(;J;){let m=J.split(`
21
- `,1)[0],k;if(G=m,this.options.pedantic?(G=G.replace(this.rules.other.listReplaceNesting," "),k=G):k=G.replace(this.rules.other.tabCharGlobal," "),L.test(G)||y.test(G)||S.test(G)||R.test(G)||M.test(G)||F.test(G))break;if(k.search(this.rules.other.nonSpaceChar)>=W||!G.trim())U+=`
22
- `+k.slice(W);else{if(N||H.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||L.test(H)||y.test(H)||F.test(H))break;U+=`
23
- `+G}N=!G.trim(),K+=m+`
24
- `,J=J.substring(m.length+1),H=k.slice(W)}}Y.loose||(q?Y.loose=!0:this.rules.other.doubleBlankLine.test(K)&&(q=!0)),Y.items.push({type:"list_item",raw:K,task:!!this.options.gfm&&this.rules.other.listIsTask.test(U),loose:!1,text:U,tokens:[]}),Y.raw+=K}let _=Y.items.at(-1);if(_)_.raw=_.raw.trimEnd(),_.text=_.text.trimEnd();else return;Y.raw=Y.raw.trimEnd();for(let z of Y.items){if(this.lexer.state.top=!1,z.tokens=this.lexer.blockTokens(z.text,[]),z.task){if(z.text=z.text.replace(this.rules.other.listReplaceTask,""),z.tokens[0]?.type==="text"||z.tokens[0]?.type==="paragraph"){z.tokens[0].raw=z.tokens[0].raw.replace(this.rules.other.listReplaceTask,""),z.tokens[0].text=z.tokens[0].text.replace(this.rules.other.listReplaceTask,"");for(let U=this.lexer.inlineQueue.length-1;U>=0;U--)if(this.rules.other.listIsTask.test(this.lexer.inlineQueue[U].src)){this.lexer.inlineQueue[U].src=this.lexer.inlineQueue[U].src.replace(this.rules.other.listReplaceTask,"");break}}let K=this.rules.other.listTaskCheckbox.exec(z.raw);if(K){let U={type:"checkbox",raw:K[0]+" ",checked:K[0]!=="[ ]"};z.checked=U.checked,Y.loose?z.tokens[0]&&["paragraph","text"].includes(z.tokens[0].type)&&"tokens"in z.tokens[0]&&z.tokens[0].tokens?(z.tokens[0].raw=U.raw+z.tokens[0].raw,z.tokens[0].text=U.raw+z.tokens[0].text,z.tokens[0].tokens.unshift(U)):z.tokens.unshift({type:"paragraph",raw:U.raw,text:U.raw,tokens:[U]}):z.tokens.unshift(U)}}if(!Y.loose){let K=z.tokens.filter((H)=>H.type==="space"),U=K.length>0&&K.some((H)=>this.rules.other.anyLine.test(H.raw));Y.loose=U}}if(Y.loose)for(let z of Y.items){z.loose=!0;for(let K of z.tokens)K.type==="text"&&(K.type="paragraph")}return Y}}html(J){let $=this.rules.block.html.exec(J);if($)return{type:"html",block:!0,raw:$[0],pre:$[1]==="pre"||$[1]==="script"||$[1]==="style",text:$[0]}}def(J){let $=this.rules.block.def.exec(J);if($){let Q=$[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal," "),Z=$[2]?$[2].replace(this.rules.other.hrefBrackets,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",Y=$[3]?$[3].substring(1,$[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):$[3];return{type:"def",tag:Q,raw:$[0],href:Z,title:Y}}}table(J){let $=this.rules.block.table.exec(J);if(!$||!this.rules.other.tableDelimiter.test($[2]))return;let Q=_5($[1]),Z=$[2].replace(this.rules.other.tableAlignChars,"").split("|"),Y=$[3]?.trim()?$[3].replace(this.rules.other.tableRowBlankLine,"").split(`
25
- `):[],X={type:"table",raw:$[0],header:[],align:[],rows:[]};if(Q.length===Z.length){for(let q of Z)this.rules.other.tableAlignRight.test(q)?X.align.push("right"):this.rules.other.tableAlignCenter.test(q)?X.align.push("center"):this.rules.other.tableAlignLeft.test(q)?X.align.push("left"):X.align.push(null);for(let q=0;q<Q.length;q++)X.header.push({text:Q[q],tokens:this.lexer.inline(Q[q]),header:!0,align:X.align[q]});for(let q of Y)X.rows.push(_5(q,X.header.length).map((_,z)=>({text:_,tokens:this.lexer.inline(_),header:!1,align:X.align[z]})));return X}}lheading(J){let $=this.rules.block.lheading.exec(J);if($)return{type:"heading",raw:$[0],depth:$[2].charAt(0)==="="?1:2,text:$[1],tokens:this.lexer.inline($[1])}}paragraph(J){let $=this.rules.block.paragraph.exec(J);if($){let Q=$[1].charAt($[1].length-1)===`
26
- `?$[1].slice(0,-1):$[1];return{type:"paragraph",raw:$[0],text:Q,tokens:this.lexer.inline(Q)}}}text(J){let $=this.rules.block.text.exec(J);if($)return{type:"text",raw:$[0],text:$[0],tokens:this.lexer.inline($[0])}}escape(J){let $=this.rules.inline.escape.exec(J);if($)return{type:"escape",raw:$[0],text:$[1]}}tag(J){let $=this.rules.inline.tag.exec(J);if($)return!this.lexer.state.inLink&&this.rules.other.startATag.test($[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test($[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test($[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test($[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:$[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:$[0]}}link(J){let $=this.rules.inline.link.exec(J);if($){let Q=$[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(Q)){if(!this.rules.other.endAngleBracket.test(Q))return;let X=i1(Q.slice(0,-1),"\\");if((Q.length-X.length)%2===0)return}else{let X=Q3($[2],"()");if(X===-2)return;if(X>-1){let q=($[0].indexOf("!")===0?5:4)+$[1].length+X;$[2]=$[2].substring(0,X),$[0]=$[0].substring(0,q).trim(),$[3]=""}}let Z=$[2],Y="";if(this.options.pedantic){let X=this.rules.other.pedanticHrefTitle.exec(Z);X&&(Z=X[1],Y=X[3])}else Y=$[3]?$[3].slice(1,-1):"";return Z=Z.trim(),this.rules.other.startAngleBracket.test(Z)&&(this.options.pedantic&&!this.rules.other.endAngleBracket.test(Q)?Z=Z.slice(1):Z=Z.slice(1,-1)),K5($,{href:Z&&Z.replace(this.rules.inline.anyPunctuation,"$1"),title:Y&&Y.replace(this.rules.inline.anyPunctuation,"$1")},$[0],this.lexer,this.rules)}}reflink(J,$){let Q;if((Q=this.rules.inline.reflink.exec(J))||(Q=this.rules.inline.nolink.exec(J))){let Z=(Q[2]||Q[1]).replace(this.rules.other.multipleSpaceGlobal," "),Y=$[Z.toLowerCase()];if(!Y){let X=Q[0].charAt(0);return{type:"text",raw:X,text:X}}return K5(Q,Y,Q[0],this.lexer,this.rules)}}emStrong(J,$,Q=""){let Z=this.rules.inline.emStrongLDelim.exec(J);if(!Z||Z[3]&&Q.match(this.rules.other.unicodeAlphaNumeric))return;if(!(Z[1]||Z[2])||!Q||this.rules.inline.punctuation.exec(Q)){let Y=[...Z[0]].length-1,X,q,_=Y,z=0,K=Z[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(K.lastIndex=0,$=$.slice(-1*J.length+Y);(Z=K.exec($))!=null;){if(X=Z[1]||Z[2]||Z[3]||Z[4]||Z[5]||Z[6],!X)continue;if(q=[...X].length,Z[3]||Z[4]){_+=q;continue}else if((Z[5]||Z[6])&&Y%3&&!((Y+q)%3)){z+=q;continue}if(_-=q,_>0)continue;q=Math.min(q,q+_+z);let U=[...Z[0]][0].length,H=J.slice(0,Y+Z.index+U+q);if(Math.min(Y,q)%2){let N=H.slice(1,-1);return{type:"em",raw:H,text:N,tokens:this.lexer.inlineTokens(N)}}let G=H.slice(2,-2);return{type:"strong",raw:H,text:G,tokens:this.lexer.inlineTokens(G)}}}}codespan(J){let $=this.rules.inline.code.exec(J);if($){let Q=$[2].replace(this.rules.other.newLineCharGlobal," "),Z=this.rules.other.nonSpaceChar.test(Q),Y=this.rules.other.startingSpaceChar.test(Q)&&this.rules.other.endingSpaceChar.test(Q);return Z&&Y&&(Q=Q.substring(1,Q.length-1)),{type:"codespan",raw:$[0],text:Q}}}br(J){let $=this.rules.inline.br.exec(J);if($)return{type:"br",raw:$[0]}}del(J,$,Q=""){let Z=this.rules.inline.delLDelim.exec(J);if(!Z)return;if(!Z[1]||!Q||this.rules.inline.punctuation.exec(Q)){let Y=[...Z[0]].length-1,X,q,_=Y,z=this.rules.inline.delRDelim;for(z.lastIndex=0,$=$.slice(-1*J.length+Y);(Z=z.exec($))!=null;){if(X=Z[1]||Z[2]||Z[3]||Z[4]||Z[5]||Z[6],!X||(q=[...X].length,q!==Y))continue;if(Z[3]||Z[4]){_+=q;continue}if(_-=q,_>0)continue;q=Math.min(q,q+_);let K=[...Z[0]][0].length,U=J.slice(0,Y+Z.index+K+q),H=U.slice(Y,-Y);return{type:"del",raw:U,text:H,tokens:this.lexer.inlineTokens(H)}}}}autolink(J){let $=this.rules.inline.autolink.exec(J);if($){let Q,Z;return $[2]==="@"?(Q=$[1],Z="mailto:"+Q):(Q=$[1],Z=Q),{type:"link",raw:$[0],text:Q,href:Z,tokens:[{type:"text",raw:Q,text:Q}]}}}url(J){let $;if($=this.rules.inline.url.exec(J)){let Q,Z;if($[2]==="@")Q=$[0],Z="mailto:"+Q;else{let Y;do Y=$[0],$[0]=this.rules.inline._backpedal.exec($[0])?.[0]??"";while(Y!==$[0]);Q=$[0],$[1]==="www."?Z="http://"+$[0]:Z=$[0]}return{type:"link",raw:$[0],text:Q,href:Z,tokens:[{type:"text",raw:Q,text:Q}]}}}inlineText(J){let $=this.rules.inline.text.exec(J);if($){let Q=this.lexer.state.inRawBlock;return{type:"text",raw:$[0],text:$[0],escaped:Q}}}},_1=class J{tokens;options;state;inlineQueue;tokenizer;constructor($){this.tokens=[],this.tokens.links=Object.create(null),this.options=$||R1,this.options.tokenizer=this.options.tokenizer||new U0,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};let Q={other:J1,block:_0.normal,inline:a1.normal};this.options.pedantic?(Q.block=_0.pedantic,Q.inline=a1.pedantic):this.options.gfm&&(Q.block=_0.gfm,this.options.breaks?Q.inline=a1.breaks:Q.inline=a1.gfm),this.tokenizer.rules=Q}static get rules(){return{block:_0,inline:a1}}static lex($,Q){return new J(Q).lex($)}static lexInline($,Q){return new J(Q).inlineTokens($)}lex($){$=$.replace(J1.carriageReturn,`
27
- `),this.blockTokens($,this.tokens);for(let Q=0;Q<this.inlineQueue.length;Q++){let Z=this.inlineQueue[Q];this.inlineTokens(Z.src,Z.tokens)}return this.inlineQueue=[],this.tokens}blockTokens($,Q=[],Z=!1){for(this.options.pedantic&&($=$.replace(J1.tabCharGlobal," ").replace(J1.spaceLine,""));$;){let Y;if(this.options.extensions?.block?.some((q)=>(Y=q.call({lexer:this},$,Q))?($=$.substring(Y.raw.length),Q.push(Y),!0):!1))continue;if(Y=this.tokenizer.space($)){$=$.substring(Y.raw.length);let q=Q.at(-1);Y.raw.length===1&&q!==void 0?q.raw+=`
16
+ `),B=this.list(W);X[X.length-1]=B,Z=Z.substring(0,Z.length-H.raw.length)+B.raw,Y=Y.substring(0,Y.length-F.raw.length)+B.raw,Q=W.substring(X.at(-1).raw.length).split(`
17
+ `);continue}}return{type:"blockquote",raw:Z,tokens:X,text:Y}}}list(J){let $=this.rules.block.list.exec(J);if($){let Q=$[1].trim(),Z=Q.length>1,Y={type:"list",raw:"",ordered:Z,start:Z?+Q.slice(0,-1):"",loose:!1,items:[]};Q=Z?`\\d{1,9}\\${Q.slice(-1)}`:`\\${Q}`,this.options.pedantic&&(Q=Z?Q:"[*+-]");let X=this.rules.other.listItemRegex(Q),q=!1;for(;J;){let z=!1,_="",U="";if(!($=X.exec(J))||this.rules.block.hr.test(J))break;_=$[0],J=J.substring(_.length);let G=z3($[2].split(`
18
+ `,1)[0],$[1].length),H=J.split(`
19
+ `,1)[0],F=!G.trim(),W=0;if(this.options.pedantic?(W=2,U=G.trimStart()):F?W=$[1].length+1:(W=G.search(this.rules.other.nonSpaceChar),W=W>4?1:W,U=G.slice(W),W+=$[1].length),F&&this.rules.other.blankLine.test(H)&&(_+=H+`
20
+ `,J=J.substring(H.length+1),z=!0),!z){let B=this.rules.other.nextBulletRegex(W),T=this.rules.other.hrRegex(W),M=this.rules.other.fencesBeginRegex(W),y=this.rules.other.headingBeginRegex(W),L=this.rules.other.htmlBeginRegex(W),C=this.rules.other.blockquoteBeginRegex(W);for(;J;){let R=J.split(`
21
+ `,1)[0],D;if(H=R,this.options.pedantic?(H=H.replace(this.rules.other.listReplaceNesting," "),D=H):D=H.replace(this.rules.other.tabCharGlobal," "),M.test(H)||y.test(H)||L.test(H)||C.test(H)||B.test(H)||T.test(H))break;if(D.search(this.rules.other.nonSpaceChar)>=W||!H.trim())U+=`
22
+ `+D.slice(W);else{if(F||G.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||M.test(G)||y.test(G)||T.test(G))break;U+=`
23
+ `+H}F=!H.trim(),_+=R+`
24
+ `,J=J.substring(R.length+1),G=D.slice(W)}}Y.loose||(q?Y.loose=!0:this.rules.other.doubleBlankLine.test(_)&&(q=!0)),Y.items.push({type:"list_item",raw:_,task:!!this.options.gfm&&this.rules.other.listIsTask.test(U),loose:!1,text:U,tokens:[]}),Y.raw+=_}let K=Y.items.at(-1);if(K)K.raw=K.raw.trimEnd(),K.text=K.text.trimEnd();else return;Y.raw=Y.raw.trimEnd();for(let z of Y.items){if(this.lexer.state.top=!1,z.tokens=this.lexer.blockTokens(z.text,[]),z.task){if(z.text=z.text.replace(this.rules.other.listReplaceTask,""),z.tokens[0]?.type==="text"||z.tokens[0]?.type==="paragraph"){z.tokens[0].raw=z.tokens[0].raw.replace(this.rules.other.listReplaceTask,""),z.tokens[0].text=z.tokens[0].text.replace(this.rules.other.listReplaceTask,"");for(let U=this.lexer.inlineQueue.length-1;U>=0;U--)if(this.rules.other.listIsTask.test(this.lexer.inlineQueue[U].src)){this.lexer.inlineQueue[U].src=this.lexer.inlineQueue[U].src.replace(this.rules.other.listReplaceTask,"");break}}let _=this.rules.other.listTaskCheckbox.exec(z.raw);if(_){let U={type:"checkbox",raw:_[0]+" ",checked:_[0]!=="[ ]"};z.checked=U.checked,Y.loose?z.tokens[0]&&["paragraph","text"].includes(z.tokens[0].type)&&"tokens"in z.tokens[0]&&z.tokens[0].tokens?(z.tokens[0].raw=U.raw+z.tokens[0].raw,z.tokens[0].text=U.raw+z.tokens[0].text,z.tokens[0].tokens.unshift(U)):z.tokens.unshift({type:"paragraph",raw:U.raw,text:U.raw,tokens:[U]}):z.tokens.unshift(U)}}if(!Y.loose){let _=z.tokens.filter((G)=>G.type==="space"),U=_.length>0&&_.some((G)=>this.rules.other.anyLine.test(G.raw));Y.loose=U}}if(Y.loose)for(let z of Y.items){z.loose=!0;for(let _ of z.tokens)_.type==="text"&&(_.type="paragraph")}return Y}}html(J){let $=this.rules.block.html.exec(J);if($)return{type:"html",block:!0,raw:$[0],pre:$[1]==="pre"||$[1]==="script"||$[1]==="style",text:$[0]}}def(J){let $=this.rules.block.def.exec(J);if($){let Q=$[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal," "),Z=$[2]?$[2].replace(this.rules.other.hrefBrackets,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",Y=$[3]?$[3].substring(1,$[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):$[3];return{type:"def",tag:Q,raw:$[0],href:Z,title:Y}}}table(J){let $=this.rules.block.table.exec(J);if(!$||!this.rules.other.tableDelimiter.test($[2]))return;let Q=H5($[1]),Z=$[2].replace(this.rules.other.tableAlignChars,"").split("|"),Y=$[3]?.trim()?$[3].replace(this.rules.other.tableRowBlankLine,"").split(`
25
+ `):[],X={type:"table",raw:$[0],header:[],align:[],rows:[]};if(Q.length===Z.length){for(let q of Z)this.rules.other.tableAlignRight.test(q)?X.align.push("right"):this.rules.other.tableAlignCenter.test(q)?X.align.push("center"):this.rules.other.tableAlignLeft.test(q)?X.align.push("left"):X.align.push(null);for(let q=0;q<Q.length;q++)X.header.push({text:Q[q],tokens:this.lexer.inline(Q[q]),header:!0,align:X.align[q]});for(let q of Y)X.rows.push(H5(q,X.header.length).map((K,z)=>({text:K,tokens:this.lexer.inline(K),header:!1,align:X.align[z]})));return X}}lheading(J){let $=this.rules.block.lheading.exec(J);if($)return{type:"heading",raw:$[0],depth:$[2].charAt(0)==="="?1:2,text:$[1],tokens:this.lexer.inline($[1])}}paragraph(J){let $=this.rules.block.paragraph.exec(J);if($){let Q=$[1].charAt($[1].length-1)===`
26
+ `?$[1].slice(0,-1):$[1];return{type:"paragraph",raw:$[0],text:Q,tokens:this.lexer.inline(Q)}}}text(J){let $=this.rules.block.text.exec(J);if($)return{type:"text",raw:$[0],text:$[0],tokens:this.lexer.inline($[0])}}escape(J){let $=this.rules.inline.escape.exec(J);if($)return{type:"escape",raw:$[0],text:$[1]}}tag(J){let $=this.rules.inline.tag.exec(J);if($)return!this.lexer.state.inLink&&this.rules.other.startATag.test($[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test($[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test($[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test($[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:$[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:$[0]}}link(J){let $=this.rules.inline.link.exec(J);if($){let Q=$[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(Q)){if(!this.rules.other.endAngleBracket.test(Q))return;let X=Y0(Q.slice(0,-1),"\\");if((Q.length-X.length)%2===0)return}else{let X=X3($[2],"()");if(X===-2)return;if(X>-1){let q=($[0].indexOf("!")===0?5:4)+$[1].length+X;$[2]=$[2].substring(0,X),$[0]=$[0].substring(0,q).trim(),$[3]=""}}let Z=$[2],Y="";if(this.options.pedantic){let X=this.rules.other.pedanticHrefTitle.exec(Z);X&&(Z=X[1],Y=X[3])}else Y=$[3]?$[3].slice(1,-1):"";return Z=Z.trim(),this.rules.other.startAngleBracket.test(Z)&&(this.options.pedantic&&!this.rules.other.endAngleBracket.test(Q)?Z=Z.slice(1):Z=Z.slice(1,-1)),W5($,{href:Z&&Z.replace(this.rules.inline.anyPunctuation,"$1"),title:Y&&Y.replace(this.rules.inline.anyPunctuation,"$1")},$[0],this.lexer,this.rules)}}reflink(J,$){let Q;if((Q=this.rules.inline.reflink.exec(J))||(Q=this.rules.inline.nolink.exec(J))){let Z=(Q[2]||Q[1]).replace(this.rules.other.multipleSpaceGlobal," "),Y=$[Z.toLowerCase()];if(!Y){let X=Q[0].charAt(0);return{type:"text",raw:X,text:X}}return W5(Q,Y,Q[0],this.lexer,this.rules)}}emStrong(J,$,Q=""){let Z=this.rules.inline.emStrongLDelim.exec(J);if(!Z||Z[3]&&Q.match(this.rules.other.unicodeAlphaNumeric))return;if(!(Z[1]||Z[2])||!Q||this.rules.inline.punctuation.exec(Q)){let Y=[...Z[0]].length-1,X,q,K=Y,z=0,_=Z[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(_.lastIndex=0,$=$.slice(-1*J.length+Y);(Z=_.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]){K+=q;continue}else if((Z[5]||Z[6])&&Y%3&&!((Y+q)%3)){z+=q;continue}if(K-=q,K>0)continue;q=Math.min(q,q+K+z);let U=[...Z[0]][0].length,G=J.slice(0,Y+Z.index+U+q);if(Math.min(Y,q)%2){let F=G.slice(1,-1);return{type:"em",raw:G,text:F,tokens:this.lexer.inlineTokens(F)}}let H=G.slice(2,-2);return{type:"strong",raw:G,text:H,tokens:this.lexer.inlineTokens(H)}}}}codespan(J){let $=this.rules.inline.code.exec(J);if($){let Q=$[2].replace(this.rules.other.newLineCharGlobal," "),Z=this.rules.other.nonSpaceChar.test(Q),Y=this.rules.other.startingSpaceChar.test(Q)&&this.rules.other.endingSpaceChar.test(Q);return Z&&Y&&(Q=Q.substring(1,Q.length-1)),{type:"codespan",raw:$[0],text:Q}}}br(J){let $=this.rules.inline.br.exec(J);if($)return{type:"br",raw:$[0]}}del(J,$,Q=""){let Z=this.rules.inline.delLDelim.exec(J);if(!Z)return;if(!Z[1]||!Q||this.rules.inline.punctuation.exec(Q)){let Y=[...Z[0]].length-1,X,q,K=Y,z=this.rules.inline.delRDelim;for(z.lastIndex=0,$=$.slice(-1*J.length+Y);(Z=z.exec($))!=null;){if(X=Z[1]||Z[2]||Z[3]||Z[4]||Z[5]||Z[6],!X||(q=[...X].length,q!==Y))continue;if(Z[3]||Z[4]){K+=q;continue}if(K-=q,K>0)continue;q=Math.min(q,q+K);let _=[...Z[0]][0].length,U=J.slice(0,Y+Z.index+_+q),G=U.slice(Y,-Y);return{type:"del",raw:U,text:G,tokens:this.lexer.inlineTokens(G)}}}}autolink(J){let $=this.rules.inline.autolink.exec(J);if($){let Q,Z;return $[2]==="@"?(Q=$[1],Z="mailto:"+Q):(Q=$[1],Z=Q),{type:"link",raw:$[0],text:Q,href:Z,tokens:[{type:"text",raw:Q,text:Q}]}}}url(J){let $;if($=this.rules.inline.url.exec(J)){let Q,Z;if($[2]==="@")Q=$[0],Z="mailto:"+Q;else{let Y;do Y=$[0],$[0]=this.rules.inline._backpedal.exec($[0])?.[0]??"";while(Y!==$[0]);Q=$[0],$[1]==="www."?Z="http://"+$[0]:Z=$[0]}return{type:"link",raw:$[0],text:Q,href:Z,tokens:[{type:"text",raw:Q,text:Q}]}}}inlineText(J){let $=this.rules.inline.text.exec(J);if($){let Q=this.lexer.state.inRawBlock;return{type:"text",raw:$[0],text:$[0],escaped:Q}}}},K1=class J{tokens;options;state;inlineQueue;tokenizer;constructor($){this.tokens=[],this.tokens.links=Object.create(null),this.options=$||I1,this.options.tokenizer=this.options.tokenizer||new y0,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};let Q={other:Y1,block:W0.normal,inline:J0.normal};this.options.pedantic?(Q.block=W0.pedantic,Q.inline=J0.pedantic):this.options.gfm&&(Q.block=W0.gfm,this.options.breaks?Q.inline=J0.breaks:Q.inline=J0.gfm),this.tokenizer.rules=Q}static get rules(){return{block:W0,inline:J0}}static lex($,Q){return new J(Q).lex($)}static lexInline($,Q){return new J(Q).inlineTokens($)}lex($){$=$.replace(Y1.carriageReturn,`
27
+ `),this.blockTokens($,this.tokens);for(let Q=0;Q<this.inlineQueue.length;Q++){let Z=this.inlineQueue[Q];this.inlineTokens(Z.src,Z.tokens)}return this.inlineQueue=[],this.tokens}blockTokens($,Q=[],Z=!1){for(this.options.pedantic&&($=$.replace(Y1.tabCharGlobal," ").replace(Y1.spaceLine,""));$;){let Y;if(this.options.extensions?.block?.some((q)=>(Y=q.call({lexer:this},$,Q))?($=$.substring(Y.raw.length),Q.push(Y),!0):!1))continue;if(Y=this.tokenizer.space($)){$=$.substring(Y.raw.length);let q=Q.at(-1);Y.raw.length===1&&q!==void 0?q.raw+=`
28
28
  `:Q.push(Y);continue}if(Y=this.tokenizer.code($)){$=$.substring(Y.raw.length);let q=Q.at(-1);q?.type==="paragraph"||q?.type==="text"?(q.raw+=(q.raw.endsWith(`
29
29
  `)?"":`
30
30
  `)+Y.raw,q.text+=`
31
31
  `+Y.text,this.inlineQueue.at(-1).src=q.text):Q.push(Y);continue}if(Y=this.tokenizer.fences($)){$=$.substring(Y.raw.length),Q.push(Y);continue}if(Y=this.tokenizer.heading($)){$=$.substring(Y.raw.length),Q.push(Y);continue}if(Y=this.tokenizer.hr($)){$=$.substring(Y.raw.length),Q.push(Y);continue}if(Y=this.tokenizer.blockquote($)){$=$.substring(Y.raw.length),Q.push(Y);continue}if(Y=this.tokenizer.list($)){$=$.substring(Y.raw.length),Q.push(Y);continue}if(Y=this.tokenizer.html($)){$=$.substring(Y.raw.length),Q.push(Y);continue}if(Y=this.tokenizer.def($)){$=$.substring(Y.raw.length);let q=Q.at(-1);q?.type==="paragraph"||q?.type==="text"?(q.raw+=(q.raw.endsWith(`
32
32
  `)?"":`
33
33
  `)+Y.raw,q.text+=`
34
- `+Y.raw,this.inlineQueue.at(-1).src=q.text):this.tokens.links[Y.tag]||(this.tokens.links[Y.tag]={href:Y.href,title:Y.title},Q.push(Y));continue}if(Y=this.tokenizer.table($)){$=$.substring(Y.raw.length),Q.push(Y);continue}if(Y=this.tokenizer.lheading($)){$=$.substring(Y.raw.length),Q.push(Y);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&&(Y=this.tokenizer.paragraph(X))){let q=Q.at(-1);Z&&q?.type==="paragraph"?(q.raw+=(q.raw.endsWith(`
34
+ `+Y.raw,this.inlineQueue.at(-1).src=q.text):this.tokens.links[Y.tag]||(this.tokens.links[Y.tag]={href:Y.href,title:Y.title},Q.push(Y));continue}if(Y=this.tokenizer.table($)){$=$.substring(Y.raw.length),Q.push(Y);continue}if(Y=this.tokenizer.lheading($)){$=$.substring(Y.raw.length),Q.push(Y);continue}let X=$;if(this.options.extensions?.startBlock){let q=1/0,K=$.slice(1),z;this.options.extensions.startBlock.forEach((_)=>{z=_.call({lexer:this},K),typeof z=="number"&&z>=0&&(q=Math.min(q,z))}),q<1/0&&q>=0&&(X=$.substring(0,q+1))}if(this.state.top&&(Y=this.tokenizer.paragraph(X))){let q=Q.at(-1);Z&&q?.type==="paragraph"?(q.raw+=(q.raw.endsWith(`
35
35
  `)?"":`
36
36
  `)+Y.raw,q.text+=`
37
37
  `+Y.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=q.text):Q.push(Y),Z=X.length!==$.length,$=$.substring(Y.raw.length);continue}if(Y=this.tokenizer.text($)){$=$.substring(Y.raw.length);let q=Q.at(-1);q?.type==="text"?(q.raw+=(q.raw.endsWith(`
38
38
  `)?"":`
39
39
  `)+Y.raw,q.text+=`
40
- `+Y.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=q.text):Q.push(Y);continue}if($){let q="Infinite loop on byte: "+$.charCodeAt(0);if(this.options.silent){console.error(q);break}else throw Error(q)}}return this.state.top=!0,Q}inline($,Q=[]){return this.inlineQueue.push({src:$,tokens:Q}),Q}inlineTokens($,Q=[]){let Z=$,Y=null;if(this.tokens.links){let z=Object.keys(this.tokens.links);if(z.length>0)for(;(Y=this.tokenizer.rules.inline.reflinkSearch.exec(Z))!=null;)z.includes(Y[0].slice(Y[0].lastIndexOf("[")+1,-1))&&(Z=Z.slice(0,Y.index)+"["+"a".repeat(Y[0].length-2)+"]"+Z.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(Y=this.tokenizer.rules.inline.anyPunctuation.exec(Z))!=null;)Z=Z.slice(0,Y.index)+"++"+Z.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);let X;for(;(Y=this.tokenizer.rules.inline.blockSkip.exec(Z))!=null;)X=Y[2]?Y[2].length:0,Z=Z.slice(0,Y.index+X)+"["+"a".repeat(Y[0].length-X-2)+"]"+Z.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);Z=this.options.hooks?.emStrongMask?.call({lexer:this},Z)??Z;let q=!1,_="";for(;$;){q||(_=""),q=!1;let z;if(this.options.extensions?.inline?.some((U)=>(z=U.call({lexer:this},$,Q))?($=$.substring(z.raw.length),Q.push(z),!0):!1))continue;if(z=this.tokenizer.escape($)){$=$.substring(z.raw.length),Q.push(z);continue}if(z=this.tokenizer.tag($)){$=$.substring(z.raw.length),Q.push(z);continue}if(z=this.tokenizer.link($)){$=$.substring(z.raw.length),Q.push(z);continue}if(z=this.tokenizer.reflink($,this.tokens.links)){$=$.substring(z.raw.length);let U=Q.at(-1);z.type==="text"&&U?.type==="text"?(U.raw+=z.raw,U.text+=z.text):Q.push(z);continue}if(z=this.tokenizer.emStrong($,Z,_)){$=$.substring(z.raw.length),Q.push(z);continue}if(z=this.tokenizer.codespan($)){$=$.substring(z.raw.length),Q.push(z);continue}if(z=this.tokenizer.br($)){$=$.substring(z.raw.length),Q.push(z);continue}if(z=this.tokenizer.del($,Z,_)){$=$.substring(z.raw.length),Q.push(z);continue}if(z=this.tokenizer.autolink($)){$=$.substring(z.raw.length),Q.push(z);continue}if(!this.state.inLink&&(z=this.tokenizer.url($))){$=$.substring(z.raw.length),Q.push(z);continue}let K=$;if(this.options.extensions?.startInline){let U=1/0,H=$.slice(1),G;this.options.extensions.startInline.forEach((N)=>{G=N.call({lexer:this},H),typeof G=="number"&&G>=0&&(U=Math.min(U,G))}),U<1/0&&U>=0&&(K=$.substring(0,U+1))}if(z=this.tokenizer.inlineText(K)){$=$.substring(z.raw.length),z.raw.slice(-1)!=="_"&&(_=z.raw.slice(-1)),q=!0;let U=Q.at(-1);U?.type==="text"?(U.raw+=z.raw,U.text+=z.text):Q.push(z);continue}if($){let U="Infinite loop on byte: "+$.charCodeAt(0);if(this.options.silent){console.error(U);break}else throw Error(U)}}return Q}},G0=class{options;parser;constructor(J){this.options=J||R1}space(J){return""}code({text:J,lang:$,escaped:Q}){let Z=($||"").match(J1.notSpaceStart)?.[0],Y=J.replace(J1.endingNewline,"")+`
41
- `;return Z?'<pre><code class="language-'+G1(Z)+'">'+(Q?Y:G1(Y,!0))+`</code></pre>
42
- `:"<pre><code>"+(Q?Y:G1(Y,!0))+`</code></pre>
40
+ `+Y.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=q.text):Q.push(Y);continue}if($){let q="Infinite loop on byte: "+$.charCodeAt(0);if(this.options.silent){console.error(q);break}else throw Error(q)}}return this.state.top=!0,Q}inline($,Q=[]){return this.inlineQueue.push({src:$,tokens:Q}),Q}inlineTokens($,Q=[]){let Z=$,Y=null;if(this.tokens.links){let z=Object.keys(this.tokens.links);if(z.length>0)for(;(Y=this.tokenizer.rules.inline.reflinkSearch.exec(Z))!=null;)z.includes(Y[0].slice(Y[0].lastIndexOf("[")+1,-1))&&(Z=Z.slice(0,Y.index)+"["+"a".repeat(Y[0].length-2)+"]"+Z.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(Y=this.tokenizer.rules.inline.anyPunctuation.exec(Z))!=null;)Z=Z.slice(0,Y.index)+"++"+Z.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);let X;for(;(Y=this.tokenizer.rules.inline.blockSkip.exec(Z))!=null;)X=Y[2]?Y[2].length:0,Z=Z.slice(0,Y.index+X)+"["+"a".repeat(Y[0].length-X-2)+"]"+Z.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);Z=this.options.hooks?.emStrongMask?.call({lexer:this},Z)??Z;let q=!1,K="";for(;$;){q||(K=""),q=!1;let z;if(this.options.extensions?.inline?.some((U)=>(z=U.call({lexer:this},$,Q))?($=$.substring(z.raw.length),Q.push(z),!0):!1))continue;if(z=this.tokenizer.escape($)){$=$.substring(z.raw.length),Q.push(z);continue}if(z=this.tokenizer.tag($)){$=$.substring(z.raw.length),Q.push(z);continue}if(z=this.tokenizer.link($)){$=$.substring(z.raw.length),Q.push(z);continue}if(z=this.tokenizer.reflink($,this.tokens.links)){$=$.substring(z.raw.length);let U=Q.at(-1);z.type==="text"&&U?.type==="text"?(U.raw+=z.raw,U.text+=z.text):Q.push(z);continue}if(z=this.tokenizer.emStrong($,Z,K)){$=$.substring(z.raw.length),Q.push(z);continue}if(z=this.tokenizer.codespan($)){$=$.substring(z.raw.length),Q.push(z);continue}if(z=this.tokenizer.br($)){$=$.substring(z.raw.length),Q.push(z);continue}if(z=this.tokenizer.del($,Z,K)){$=$.substring(z.raw.length),Q.push(z);continue}if(z=this.tokenizer.autolink($)){$=$.substring(z.raw.length),Q.push(z);continue}if(!this.state.inLink&&(z=this.tokenizer.url($))){$=$.substring(z.raw.length),Q.push(z);continue}let _=$;if(this.options.extensions?.startInline){let U=1/0,G=$.slice(1),H;this.options.extensions.startInline.forEach((F)=>{H=F.call({lexer:this},G),typeof H=="number"&&H>=0&&(U=Math.min(U,H))}),U<1/0&&U>=0&&(_=$.substring(0,U+1))}if(z=this.tokenizer.inlineText(_)){$=$.substring(z.raw.length),z.raw.slice(-1)!=="_"&&(K=z.raw.slice(-1)),q=!0;let U=Q.at(-1);U?.type==="text"?(U.raw+=z.raw,U.text+=z.text):Q.push(z);continue}if($){let U="Infinite loop on byte: "+$.charCodeAt(0);if(this.options.silent){console.error(U);break}else throw Error(U)}}return Q}},N0=class{options;parser;constructor(J){this.options=J||I1}space(J){return""}code({text:J,lang:$,escaped:Q}){let Z=($||"").match(Y1.notSpaceStart)?.[0],Y=J.replace(Y1.endingNewline,"")+`
41
+ `;return Z?'<pre><code class="language-'+W1(Z)+'">'+(Q?Y:W1(Y,!0))+`</code></pre>
42
+ `:"<pre><code>"+(Q?Y:W1(Y,!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:Q}=J,Z="";for(let q=0;q<J.items.length;q++){let _=J.items[q];Z+=this.listitem(_)}let Y=$?"ol":"ul",X=$&&Q!==1?' start="'+Q+'"':"";return"<"+Y+X+`>
47
+ `}list(J){let{ordered:$,start:Q}=J,Z="";for(let q=0;q<J.items.length;q++){let K=J.items[q];Z+=this.listitem(K)}let Y=$?"ol":"ul",X=$&&Q!==1?' start="'+Q+'"':"";return"<"+Y+X+`>
48
48
  `+Z+"</"+Y+`>
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>
@@ -55,8 +55,8 @@ ${this.parser.parse(J)}</blockquote>
55
55
  `}tablerow({text:J}){return`<tr>
56
56
  ${J}</tr>
57
57
  `}tablecell(J){let $=this.parser.parseInline(J.tokens),Q=J.header?"th":"td";return(J.align?`<${Q} align="${J.align}">`:`<${Q}>`)+$+`</${Q}>
58
- `}strong({tokens:J}){return`<strong>${this.parser.parseInline(J)}</strong>`}em({tokens:J}){return`<em>${this.parser.parseInline(J)}</em>`}codespan({text:J}){return`<code>${G1(J,!0)}</code>`}br(J){return"<br>"}del({tokens:J}){return`<del>${this.parser.parseInline(J)}</del>`}link({href:J,title:$,tokens:Q}){let Z=this.parser.parseInline(Q),Y=z5(J);if(Y===null)return Z;J=Y;let X='<a href="'+J+'"';return $&&(X+=' title="'+G1($)+'"'),X+=">"+Z+"</a>",X}image({href:J,title:$,text:Q,tokens:Z}){Z&&(Q=this.parser.parseInline(Z,this.parser.textRenderer));let Y=z5(J);if(Y===null)return G1(Q);J=Y;let X=`<img src="${J}" alt="${G1(Q)}"`;return $&&(X+=` title="${G1($)}"`),X+=">",X}text(J){return"tokens"in J&&J.tokens?this.parser.parseInline(J.tokens):("escaped"in J)&&J.escaped?J.text:G1(J.text)}},E0=class{strong({text:J}){return J}em({text:J}){return J}codespan({text:J}){return J}del({text:J}){return J}html({text:J}){return J}text({text:J}){return J}link({text:J}){return""+J}image({text:J}){return""+J}br(){return""}checkbox({raw:J}){return J}},K1=class J{options;renderer;textRenderer;constructor($){this.options=$||R1,this.options.renderer=this.options.renderer||new G0,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new E0}static parse($,Q){return new J(Q).parse($)}static parseInline($,Q){return new J(Q).parseInline($)}parse($){let Q="";for(let Z=0;Z<$.length;Z++){let Y=$[Z];if(this.options.extensions?.renderers?.[Y.type]){let q=Y,_=this.options.extensions.renderers[q.type].call({parser:this},q);if(_!==!1||!["space","hr","heading","code","table","blockquote","list","html","def","paragraph","text"].includes(q.type)){Q+=_||"";continue}}let X=Y;switch(X.type){case"space":{Q+=this.renderer.space(X);break}case"hr":{Q+=this.renderer.hr(X);break}case"heading":{Q+=this.renderer.heading(X);break}case"code":{Q+=this.renderer.code(X);break}case"table":{Q+=this.renderer.table(X);break}case"blockquote":{Q+=this.renderer.blockquote(X);break}case"list":{Q+=this.renderer.list(X);break}case"checkbox":{Q+=this.renderer.checkbox(X);break}case"html":{Q+=this.renderer.html(X);break}case"def":{Q+=this.renderer.def(X);break}case"paragraph":{Q+=this.renderer.paragraph(X);break}case"text":{Q+=this.renderer.text(X);break}default:{let q='Token with "'+X.type+'" type was not found.';if(this.options.silent)return console.error(q),"";throw Error(q)}}}return Q}parseInline($,Q=this.renderer){let Z="";for(let Y=0;Y<$.length;Y++){let X=$[Y];if(this.options.extensions?.renderers?.[X.type]){let _=this.options.extensions.renderers[X.type].call({parser:this},X);if(_!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(X.type)){Z+=_||"";continue}}let q=X;switch(q.type){case"escape":{Z+=Q.text(q);break}case"html":{Z+=Q.html(q);break}case"link":{Z+=Q.link(q);break}case"image":{Z+=Q.image(q);break}case"checkbox":{Z+=Q.checkbox(q);break}case"strong":{Z+=Q.strong(q);break}case"em":{Z+=Q.em(q);break}case"codespan":{Z+=Q.codespan(q);break}case"br":{Z+=Q.br(q);break}case"del":{Z+=Q.del(q);break}case"text":{Z+=Q.text(q);break}default:{let _='Token with "'+q.type+'" type was not found.';if(this.options.silent)return console.error(_),"";throw Error(_)}}}return Z}},o1=class{options;block;constructor(J){this.options=J||R1}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens","emStrongMask"]);static passThroughHooksRespectAsync=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(J){return J}postprocess(J){return J}processAllTokens(J){return J}emStrongMask(J){return J}provideLexer(){return this.block?_1.lex:_1.lexInline}provideParser(){return this.block?K1.parse:K1.parseInline}},X3=class{defaults=I0();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=K1;Renderer=G0;TextRenderer=E0;Lexer=_1;Tokenizer=U0;Hooks=o1;constructor(...J){this.use(...J)}walkTokens(J,$){let Q=[];for(let Z of J)switch(Q=Q.concat($.call(this,Z)),Z.type){case"table":{let Y=Z;for(let X of Y.header)Q=Q.concat(this.walkTokens(X.tokens,$));for(let X of Y.rows)for(let q of X)Q=Q.concat(this.walkTokens(q.tokens,$));break}case"list":{let Y=Z;Q=Q.concat(this.walkTokens(Y.items,$));break}default:{let Y=Z;this.defaults.extensions?.childTokens?.[Y.type]?this.defaults.extensions.childTokens[Y.type].forEach((X)=>{let q=Y[X].flat(1/0);Q=Q.concat(this.walkTokens(q,$))}):Y.tokens&&(Q=Q.concat(this.walkTokens(Y.tokens,$)))}}return Q}use(...J){let $=this.defaults.extensions||{renderers:{},childTokens:{}};return J.forEach((Q)=>{let Z={...Q};if(Z.async=this.defaults.async||Z.async||!1,Q.extensions&&(Q.extensions.forEach((Y)=>{if(!Y.name)throw Error("extension name required");if("renderer"in Y){let X=$.renderers[Y.name];X?$.renderers[Y.name]=function(...q){let _=Y.renderer.apply(this,q);return _===!1&&(_=X.apply(this,q)),_}:$.renderers[Y.name]=Y.renderer}if("tokenizer"in Y){if(!Y.level||Y.level!=="block"&&Y.level!=="inline")throw Error("extension level must be 'block' or 'inline'");let X=$[Y.level];X?X.unshift(Y.tokenizer):$[Y.level]=[Y.tokenizer],Y.start&&(Y.level==="block"?$.startBlock?$.startBlock.push(Y.start):$.startBlock=[Y.start]:Y.level==="inline"&&($.startInline?$.startInline.push(Y.start):$.startInline=[Y.start]))}"childTokens"in Y&&Y.childTokens&&($.childTokens[Y.name]=Y.childTokens)}),Z.extensions=$),Q.renderer){let Y=this.defaults.renderer||new G0(this.defaults);for(let X in Q.renderer){if(!(X in Y))throw Error(`renderer '${X}' does not exist`);if(["options","parser"].includes(X))continue;let q=X,_=Q.renderer[q],z=Y[q];Y[q]=(...K)=>{let U=_.apply(Y,K);return U===!1&&(U=z.apply(Y,K)),U||""}}Z.renderer=Y}if(Q.tokenizer){let Y=this.defaults.tokenizer||new U0(this.defaults);for(let X in Q.tokenizer){if(!(X in Y))throw Error(`tokenizer '${X}' does not exist`);if(["options","rules","lexer"].includes(X))continue;let q=X,_=Q.tokenizer[q],z=Y[q];Y[q]=(...K)=>{let U=_.apply(Y,K);return U===!1&&(U=z.apply(Y,K)),U}}Z.tokenizer=Y}if(Q.hooks){let Y=this.defaults.hooks||new o1;for(let X in Q.hooks){if(!(X in Y))throw Error(`hook '${X}' does not exist`);if(["options","block"].includes(X))continue;let q=X,_=Q.hooks[q],z=Y[q];o1.passThroughHooks.has(X)?Y[q]=(K)=>{if(this.defaults.async&&o1.passThroughHooksRespectAsync.has(X))return(async()=>{let H=await _.call(Y,K);return z.call(Y,H)})();let U=_.call(Y,K);return z.call(Y,U)}:Y[q]=(...K)=>{if(this.defaults.async)return(async()=>{let H=await _.apply(Y,K);return H===!1&&(H=await z.apply(Y,K)),H})();let U=_.apply(Y,K);return U===!1&&(U=z.apply(Y,K)),U}}Z.hooks=Y}if(Q.walkTokens){let Y=this.defaults.walkTokens,X=Q.walkTokens;Z.walkTokens=function(q){let _=[];return _.push(X.call(this,q)),Y&&(_=_.concat(Y.call(this,q))),_}}this.defaults={...this.defaults,...Z}}),this}setOptions(J){return this.defaults={...this.defaults,...J},this}lexer(J,$){return _1.lex(J,$??this.defaults)}parser(J,$){return K1.parse(J,$??this.defaults)}parseMarkdown(J){return($,Q)=>{let Z={...Q},Y={...this.defaults,...Z},X=this.onError(!!Y.silent,!!Y.async);if(this.defaults.async===!0&&Z.async===!1)return X(Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(typeof $>"u"||$===null)return X(Error("marked(): input parameter is undefined or null"));if(typeof $!="string")return X(Error("marked(): input parameter is of type "+Object.prototype.toString.call($)+", string expected"));if(Y.hooks&&(Y.hooks.options=Y,Y.hooks.block=J),Y.async)return(async()=>{let q=Y.hooks?await Y.hooks.preprocess($):$,_=await(Y.hooks?await Y.hooks.provideLexer():J?_1.lex:_1.lexInline)(q,Y),z=Y.hooks?await Y.hooks.processAllTokens(_):_;Y.walkTokens&&await Promise.all(this.walkTokens(z,Y.walkTokens));let K=await(Y.hooks?await Y.hooks.provideParser():J?K1.parse:K1.parseInline)(z,Y);return Y.hooks?await Y.hooks.postprocess(K):K})().catch(X);try{Y.hooks&&($=Y.hooks.preprocess($));let q=(Y.hooks?Y.hooks.provideLexer():J?_1.lex:_1.lexInline)($,Y);Y.hooks&&(q=Y.hooks.processAllTokens(q)),Y.walkTokens&&this.walkTokens(q,Y.walkTokens);let _=(Y.hooks?Y.hooks.provideParser():J?K1.parse:K1.parseInline)(q,Y);return Y.hooks&&(_=Y.hooks.postprocess(_)),_}catch(q){return X(q)}}}onError(J,$){return(Q)=>{if(Q.message+=`
59
- Please report this to https://github.com/markedjs/marked.`,J){let Z="<p>An error occurred:</p><pre>"+G1(Q.message+"",!0)+"</pre>";return $?Promise.resolve(Z):Z}if($)return Promise.reject(Q);throw Q}}},w1=new X3;function E(J,$){return w1.parse(J,$)}E.options=E.setOptions=function(J){return w1.setOptions(J),E.defaults=w1.defaults,U5(E.defaults),E};E.getDefaults=I0;E.defaults=R1;E.use=function(...J){return w1.use(...J),E.defaults=w1.defaults,U5(E.defaults),E};E.walkTokens=function(J,$){return w1.walkTokens(J,$)};E.parseInline=w1.parseInline;E.Parser=K1;E.parser=K1.parse;E.Renderer=G0;E.TextRenderer=E0;E.Lexer=_1;E.lexer=_1.lex;E.Tokenizer=U0;E.Hooks=o1;E.parse=E;var{options:v$,setOptions:E$,use:x$,walkTokens:h$,parseInline:p$}=E;var c$=K1.parse,d$=_1.lex;import{SessionContext as T2,ActiveViewCtx as V$}from"#canvas/runtime";import{useState as n1,useCallback as y1,useEffect as P5,useRef as S5}from"react";import{AnnotationCtx as z3}from"#canvas/runtime";function H1(){return`ann-${Date.now()}-${Math.random().toString(36).slice(2,6)}`}function t1(J,$){J.style.height="auto",J.style.height=($?Math.max($,J.scrollHeight):J.scrollHeight)+"px"}import{useAnnotations as q1}from"#canvas/runtime";import{jsxDEV as G3}from"react/jsx-dev-runtime";function x0(J,$){return`canvas:${J}:rev:${$}`}function e1(J,$){try{let Q=localStorage.getItem(x0(J,$));if(!Q)return null;return JSON.parse(Q)}catch{return null}}function _3(J,$,Q){try{localStorage.setItem(x0(J,$),JSON.stringify(Q))}catch{}}function K3(J,$){try{localStorage.removeItem(x0(J,$))}catch{}}function b5({sessionId:J,revision:$,isReadOnly:Q,children:Z}){let Y=S5(`${J}:${$}`),[X,q]=n1(()=>{return e1(J,$)?.annotations??[]}),[_,z]=n1(()=>{return e1(J,$)?.generalNote??""}),[K,U]=n1(null),[H,G]=n1(()=>{let w=e1(J,$);return w?.responses?new Map(w.responses):new Map}),[N,W]=n1(()=>{let w=e1(J,$);return w?.feedbackEntries?new Map(w.feedbackEntries):new Map});P5(()=>{let w=`${J}:${$}`;if(w===Y.current)return;Y.current=w;let I=e1(J,$);q(I?.annotations??[]),z(I?.generalNote??""),G(I?.responses?new Map(I.responses):new Map),W(I?.feedbackEntries?new Map(I.feedbackEntries):new Map),U(null)},[J,$]);let M=S5(null);P5(()=>{if(Q)return;if(M.current)clearTimeout(M.current);return M.current=setTimeout(()=>{_3(J,$,{annotations:X,generalNote:_,responses:Array.from(H.entries()),feedbackEntries:Array.from(N.entries())})},300),()=>{if(M.current)clearTimeout(M.current)}},[X,_,H,N,J,$,Q]);let F=y1((w,I,T,B,c)=>{q((o)=>[...o,{id:w,snippet:I,note:T,createdAt:new Date().toISOString(),filePath:B,context:c}])},[]),L=y1((w,I,T)=>{F(H1(),w,I,T)},[F]),y=y1((w,I)=>{q((T)=>T.map((B)=>B.id===w?{...B,note:I}:B))},[]),S=y1((w)=>{U3(w),q((I)=>I.filter((T)=>T.id!==w)),U((I)=>I===w?null:I)},[]),R=y1((w,I)=>{G((T)=>{let B=new Map(T);return B.set(w,I),B})},[]),m=y1((w,I)=>{W((T)=>{let B=T.get(w);if(B&&B.markdown===I.markdown&&B.label===I.label&&B.required===I.required)return T;let c=new Map(T);return c.set(w,I),c})},[]),k=y1((w)=>{W((I)=>{if(!I.has(w))return I;let T=new Map(I);return T.delete(w),T})},[]),V=y1(()=>{for(let w of document.querySelectorAll("[data-annotation-id]"))A5(w);q([]),z(""),U(null),G(new Map),W(new Map),K3(J,$)},[J,$]);return G3(z3.Provider,{value:{annotations:X,addAnnotation:L,addAnnotationWithId:F,updateAnnotation:y,removeAnnotation:S,generalNote:_,setGeneralNote:z,clearAll:V,activeAnnotationId:K,setActiveAnnotationId:U,responses:H,setResponse:R,feedbackEntries:N,setFeedbackEntry:m,removeFeedbackEntry:k},children:Z},void 0,!1,void 0,this)}function U3(J){let $=document.querySelectorAll(`[data-annotation-id="${J}"]`);for(let Q of $)A5(Q)}function A5(J){let $=J.parentNode;if(!$)return;let Q=document.createTextNode(J.textContent||"");$.replaceChild(Q,J),$.normalize()}import c0,{useEffect as U1,useState as X1,useRef as D5,useContext as O3,useCallback as F3,useMemo as B0}from"react";import{createPortal as y3}from"react-dom";import{SessionContext as M3}from"#canvas/runtime";function u1(J,$){let Q=[],Z=H3(J);for(let Y of Z){let X=document.createRange();if(X.selectNodeContents(Y),Y===J.startContainer)X.setStart(Y,J.startOffset);if(Y===J.endContainer)X.setEnd(Y,J.endOffset);let q=X.toString();if(!q||!q.trim())continue;let _=document.createElement("mark");_.setAttribute("data-annotation-id",$),_.style.cssText=`
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>${W1(J,!0)}</code>`}br(J){return"<br>"}del({tokens:J}){return`<del>${this.parser.parseInline(J)}</del>`}link({href:J,title:$,tokens:Q}){let Z=this.parser.parseInline(Q),Y=G5(J);if(Y===null)return Z;J=Y;let X='<a href="'+J+'"';return $&&(X+=' title="'+W1($)+'"'),X+=">"+Z+"</a>",X}image({href:J,title:$,text:Q,tokens:Z}){Z&&(Q=this.parser.parseInline(Z,this.parser.textRenderer));let Y=G5(J);if(Y===null)return W1(Q);J=Y;let X=`<img src="${J}" alt="${W1(Q)}"`;return $&&(X+=` title="${W1($)}"`),X+=">",X}text(J){return"tokens"in J&&J.tokens?this.parser.parseInline(J.tokens):("escaped"in J)&&J.escaped?J.text:W1(J.text)}},p0=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}},_1=class J{options;renderer;textRenderer;constructor($){this.options=$||I1,this.options.renderer=this.options.renderer||new N0,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new p0}static parse($,Q){return new J(Q).parse($)}static parseInline($,Q){return new J(Q).parseInline($)}parse($){let Q="";for(let Z=0;Z<$.length;Z++){let Y=$[Z];if(this.options.extensions?.renderers?.[Y.type]){let q=Y,K=this.options.extensions.renderers[q.type].call({parser:this},q);if(K!==!1||!["space","hr","heading","code","table","blockquote","list","html","def","paragraph","text"].includes(q.type)){Q+=K||"";continue}}let X=Y;switch(X.type){case"space":{Q+=this.renderer.space(X);break}case"hr":{Q+=this.renderer.hr(X);break}case"heading":{Q+=this.renderer.heading(X);break}case"code":{Q+=this.renderer.code(X);break}case"table":{Q+=this.renderer.table(X);break}case"blockquote":{Q+=this.renderer.blockquote(X);break}case"list":{Q+=this.renderer.list(X);break}case"checkbox":{Q+=this.renderer.checkbox(X);break}case"html":{Q+=this.renderer.html(X);break}case"def":{Q+=this.renderer.def(X);break}case"paragraph":{Q+=this.renderer.paragraph(X);break}case"text":{Q+=this.renderer.text(X);break}default:{let q='Token with "'+X.type+'" type was not found.';if(this.options.silent)return console.error(q),"";throw Error(q)}}}return Q}parseInline($,Q=this.renderer){let Z="";for(let Y=0;Y<$.length;Y++){let X=$[Y];if(this.options.extensions?.renderers?.[X.type]){let K=this.options.extensions.renderers[X.type].call({parser:this},X);if(K!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(X.type)){Z+=K||"";continue}}let q=X;switch(q.type){case"escape":{Z+=Q.text(q);break}case"html":{Z+=Q.html(q);break}case"link":{Z+=Q.link(q);break}case"image":{Z+=Q.image(q);break}case"checkbox":{Z+=Q.checkbox(q);break}case"strong":{Z+=Q.strong(q);break}case"em":{Z+=Q.em(q);break}case"codespan":{Z+=Q.codespan(q);break}case"br":{Z+=Q.br(q);break}case"del":{Z+=Q.del(q);break}case"text":{Z+=Q.text(q);break}default:{let K='Token with "'+q.type+'" type was not found.';if(this.options.silent)return console.error(K),"";throw Error(K)}}}return Z}},Q0=class{options;block;constructor(J){this.options=J||I1}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens","emStrongMask"]);static passThroughHooksRespectAsync=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(J){return J}postprocess(J){return J}processAllTokens(J){return J}emStrongMask(J){return J}provideLexer(){return this.block?K1.lex:K1.lexInline}provideParser(){return this.block?_1.parse:_1.parseInline}},_3=class{defaults=D0();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=_1;Renderer=N0;TextRenderer=p0;Lexer=K1;Tokenizer=y0;Hooks=Q0;constructor(...J){this.use(...J)}walkTokens(J,$){let Q=[];for(let Z of J)switch(Q=Q.concat($.call(this,Z)),Z.type){case"table":{let Y=Z;for(let X of Y.header)Q=Q.concat(this.walkTokens(X.tokens,$));for(let X of Y.rows)for(let q of X)Q=Q.concat(this.walkTokens(q.tokens,$));break}case"list":{let Y=Z;Q=Q.concat(this.walkTokens(Y.items,$));break}default:{let Y=Z;this.defaults.extensions?.childTokens?.[Y.type]?this.defaults.extensions.childTokens[Y.type].forEach((X)=>{let q=Y[X].flat(1/0);Q=Q.concat(this.walkTokens(q,$))}):Y.tokens&&(Q=Q.concat(this.walkTokens(Y.tokens,$)))}}return Q}use(...J){let $=this.defaults.extensions||{renderers:{},childTokens:{}};return J.forEach((Q)=>{let Z={...Q};if(Z.async=this.defaults.async||Z.async||!1,Q.extensions&&(Q.extensions.forEach((Y)=>{if(!Y.name)throw Error("extension name required");if("renderer"in Y){let X=$.renderers[Y.name];X?$.renderers[Y.name]=function(...q){let K=Y.renderer.apply(this,q);return K===!1&&(K=X.apply(this,q)),K}:$.renderers[Y.name]=Y.renderer}if("tokenizer"in Y){if(!Y.level||Y.level!=="block"&&Y.level!=="inline")throw Error("extension level must be 'block' or 'inline'");let X=$[Y.level];X?X.unshift(Y.tokenizer):$[Y.level]=[Y.tokenizer],Y.start&&(Y.level==="block"?$.startBlock?$.startBlock.push(Y.start):$.startBlock=[Y.start]:Y.level==="inline"&&($.startInline?$.startInline.push(Y.start):$.startInline=[Y.start]))}"childTokens"in Y&&Y.childTokens&&($.childTokens[Y.name]=Y.childTokens)}),Z.extensions=$),Q.renderer){let Y=this.defaults.renderer||new N0(this.defaults);for(let X in Q.renderer){if(!(X in Y))throw Error(`renderer '${X}' does not exist`);if(["options","parser"].includes(X))continue;let q=X,K=Q.renderer[q],z=Y[q];Y[q]=(..._)=>{let U=K.apply(Y,_);return U===!1&&(U=z.apply(Y,_)),U||""}}Z.renderer=Y}if(Q.tokenizer){let Y=this.defaults.tokenizer||new y0(this.defaults);for(let X in Q.tokenizer){if(!(X in Y))throw Error(`tokenizer '${X}' does not exist`);if(["options","rules","lexer"].includes(X))continue;let q=X,K=Q.tokenizer[q],z=Y[q];Y[q]=(..._)=>{let U=K.apply(Y,_);return U===!1&&(U=z.apply(Y,_)),U}}Z.tokenizer=Y}if(Q.hooks){let Y=this.defaults.hooks||new Q0;for(let X in Q.hooks){if(!(X in Y))throw Error(`hook '${X}' does not exist`);if(["options","block"].includes(X))continue;let q=X,K=Q.hooks[q],z=Y[q];Q0.passThroughHooks.has(X)?Y[q]=(_)=>{if(this.defaults.async&&Q0.passThroughHooksRespectAsync.has(X))return(async()=>{let G=await K.call(Y,_);return z.call(Y,G)})();let U=K.call(Y,_);return z.call(Y,U)}:Y[q]=(..._)=>{if(this.defaults.async)return(async()=>{let G=await K.apply(Y,_);return G===!1&&(G=await z.apply(Y,_)),G})();let U=K.apply(Y,_);return U===!1&&(U=z.apply(Y,_)),U}}Z.hooks=Y}if(Q.walkTokens){let Y=this.defaults.walkTokens,X=Q.walkTokens;Z.walkTokens=function(q){let K=[];return K.push(X.call(this,q)),Y&&(K=K.concat(Y.call(this,q))),K}}this.defaults={...this.defaults,...Z}}),this}setOptions(J){return this.defaults={...this.defaults,...J},this}lexer(J,$){return K1.lex(J,$??this.defaults)}parser(J,$){return _1.parse(J,$??this.defaults)}parseMarkdown(J){return($,Q)=>{let Z={...Q},Y={...this.defaults,...Z},X=this.onError(!!Y.silent,!!Y.async);if(this.defaults.async===!0&&Z.async===!1)return X(Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(typeof $>"u"||$===null)return X(Error("marked(): input parameter is undefined or null"));if(typeof $!="string")return X(Error("marked(): input parameter is of type "+Object.prototype.toString.call($)+", string expected"));if(Y.hooks&&(Y.hooks.options=Y,Y.hooks.block=J),Y.async)return(async()=>{let q=Y.hooks?await Y.hooks.preprocess($):$,K=await(Y.hooks?await Y.hooks.provideLexer():J?K1.lex:K1.lexInline)(q,Y),z=Y.hooks?await Y.hooks.processAllTokens(K):K;Y.walkTokens&&await Promise.all(this.walkTokens(z,Y.walkTokens));let _=await(Y.hooks?await Y.hooks.provideParser():J?_1.parse:_1.parseInline)(z,Y);return Y.hooks?await Y.hooks.postprocess(_):_})().catch(X);try{Y.hooks&&($=Y.hooks.preprocess($));let q=(Y.hooks?Y.hooks.provideLexer():J?K1.lex:K1.lexInline)($,Y);Y.hooks&&(q=Y.hooks.processAllTokens(q)),Y.walkTokens&&this.walkTokens(q,Y.walkTokens);let K=(Y.hooks?Y.hooks.provideParser():J?_1.parse:_1.parseInline)(q,Y);return Y.hooks&&(K=Y.hooks.postprocess(K)),K}catch(q){return X(q)}}}onError(J,$){return(Q)=>{if(Q.message+=`
59
+ Please report this to https://github.com/markedjs/marked.`,J){let Z="<p>An error occurred:</p><pre>"+W1(Q.message+"",!0)+"</pre>";return $?Promise.resolve(Z):Z}if($)return Promise.reject(Q);throw Q}}},m1=new _3;function x(J,$){return m1.parse(J,$)}x.options=x.setOptions=function(J){return m1.setOptions(J),x.defaults=m1.defaults,F5(x.defaults),x};x.getDefaults=D0;x.defaults=I1;x.use=function(...J){return m1.use(...J),x.defaults=m1.defaults,F5(x.defaults),x};x.walkTokens=function(J,$){return m1.walkTokens(J,$)};x.parseInline=m1.parseInline;x.Parser=_1;x.parser=_1.parse;x.Renderer=N0;x.TextRenderer=p0;x.Lexer=K1;x.lexer=K1.lex;x.Tokenizer=y0;x.Hooks=Q0;x.parse=x;var{options:E$,setOptions:x$,use:h$,walkTokens:p$,parseInline:c$}=x;var d$=_1.parse,r$=K1.lex;import{SessionContext as O2,ActiveViewCtx as g$}from"#canvas/runtime";import{useState as X0,useCallback as M1,useEffect as C5,useRef as A5}from"react";import{AnnotationCtx as U3}from"#canvas/runtime";var U1="__agent-response__";function G1(){return`ann-${Date.now()}-${Math.random().toString(36).slice(2,6)}`}function q0(J,$){J.style.height="auto",J.style.height=($?Math.max($,J.scrollHeight):J.scrollHeight)+"px"}import{useAnnotations as q1}from"#canvas/runtime";import{jsxDEV as F3}from"react/jsx-dev-runtime";function c0(J,$){return`canvas:${J}:rev:${$}`}function z0(J,$){try{let Q=localStorage.getItem(c0(J,$));if(!Q)return null;return JSON.parse(Q)}catch{return null}}function G3(J,$,Q){try{localStorage.setItem(c0(J,$),JSON.stringify(Q))}catch{}}function H3(J,$){try{localStorage.removeItem(c0(J,$))}catch{}}function R5({sessionId:J,revision:$,isReadOnly:Q,children:Z}){let Y=A5(`${J}:${$}`),[X,q]=X0(()=>{return z0(J,$)?.annotations??[]}),[K,z]=X0(()=>{return z0(J,$)?.generalNote??""}),[_,U]=X0(null),[G,H]=X0(()=>{let b=z0(J,$);return b?.responses?new Map(b.responses):new Map}),[F,W]=X0(()=>{let b=z0(J,$);return b?.feedbackEntries?new Map(b.feedbackEntries):new Map});C5(()=>{let b=`${J}:${$}`;if(b===Y.current)return;Y.current=b;let I=z0(J,$);q(I?.annotations??[]),z(I?.generalNote??""),H(I?.responses?new Map(I.responses):new Map),W(I?.feedbackEntries?new Map(I.feedbackEntries):new Map),U(null)},[J,$]);let B=A5(null);C5(()=>{if(Q)return;if(B.current)clearTimeout(B.current);return B.current=setTimeout(()=>{G3(J,$,{annotations:X,generalNote:K,responses:Array.from(G.entries()),feedbackEntries:Array.from(F.entries())})},300),()=>{if(B.current)clearTimeout(B.current)}},[X,K,G,F,J,$,Q]);let T=M1((b,I,P,O,j)=>{q((o)=>[...o,{id:b,snippet:I,note:P,createdAt:new Date().toISOString(),filePath:O,context:j}])},[]),M=M1((b,I,P)=>{T(G1(),b,I,P)},[T]),y=M1((b,I)=>{q((P)=>P.map((O)=>O.id===b?{...O,note:I}:O))},[]),L=M1((b)=>{W3(b),q((I)=>I.filter((P)=>P.id!==b)),U((I)=>I===b?null:I)},[]),C=M1((b,I)=>{H((P)=>{let O=new Map(P);return O.set(b,I),O})},[]),R=M1((b,I)=>{W((P)=>{let O=P.get(b);if(O&&O.markdown===I.markdown&&O.label===I.label&&O.required===I.required)return P;let j=new Map(P);return j.set(b,I),j})},[]),D=M1((b)=>{W((I)=>{if(!I.has(b))return I;let P=new Map(I);return P.delete(b),P})},[]),V=M1(()=>{for(let b of document.querySelectorAll("[data-annotation-id]"))j5(b);q([]),z(""),U(null),H(new Map),W(new Map),H3(J,$)},[J,$]);return F3(U3.Provider,{value:{annotations:X,addAnnotation:M,addAnnotationWithId:T,updateAnnotation:y,removeAnnotation:L,generalNote:K,setGeneralNote:z,clearAll:V,activeAnnotationId:_,setActiveAnnotationId:U,responses:G,setResponse:C,feedbackEntries:F,setFeedbackEntry:R,removeFeedbackEntry:D},children:Z},void 0,!1,void 0,this)}function W3(J){let $=document.querySelectorAll(`[data-annotation-id="${J}"]`);for(let Q of $)j5(Q)}function j5(J){let $=J.parentNode;if(!$)return;let Q=document.createTextNode(J.textContent||"");$.replaceChild(Q,J),$.normalize()}import l0,{useEffect as H1,useState as X1,useRef as u5,useContext as B3,useCallback as M3,useMemo as P0}from"react";import{createPortal as L3}from"react-dom";import{SessionContext as P3}from"#canvas/runtime";function L1(J,$){let Q=[],Z=y3(J);for(let Y of Z){let X=document.createRange();if(X.selectNodeContents(Y),Y===J.startContainer)X.setStart(Y,J.startOffset);if(Y===J.endContainer)X.setEnd(Y,J.endOffset);let q=X.toString();if(!q||!q.trim())continue;let K=document.createElement("mark");K.setAttribute("data-annotation-id",$),K.style.cssText=`
60
60
  background: var(--color-highlight-annotation);
61
61
  border-bottom: 1.5px solid var(--color-highlight-bg);
62
62
  border-radius: 2px;
@@ -64,7 +64,7 @@ Please report this to https://github.com/markedjs/marked.`,J){let Z="<p>An error
64
64
  transition: background 150ms ease;
65
65
  color: inherit;
66
66
  padding: 1px 0;
67
- `;try{X.surroundContents(_)}catch{let z=X.extractContents();_.appendChild(z),X.insertNode(_)}Q.push(_)}return Q}function H3(J){let $=[],Q=J.commonAncestorContainer;if(Q.nodeType===Node.TEXT_NODE)return $.push(Q),$;let Z=document.createTreeWalker(Q,NodeFilter.SHOW_TEXT),Y;while(Y=Z.nextNode()){if(Y.parentElement?.classList.contains("select-none"))continue;if(J.intersectsNode(Y))$.push(Y)}return $}function C1(J,$){let Q=document.querySelectorAll(`[data-annotation-id="${J}"]`);for(let Z of Q)Z.style.cssText=$?`
67
+ `;try{X.surroundContents(K)}catch{let z=X.extractContents();K.appendChild(z),X.insertNode(K)}Q.push(K)}return Q}function y3(J){let $=[],Q=J.commonAncestorContainer;if(Q.nodeType===Node.TEXT_NODE)return $.push(Q),$;let Z=document.createTreeWalker(Q,NodeFilter.SHOW_TEXT),Y;while(Y=Z.nextNode()){if(Y.parentElement?.classList.contains("select-none"))continue;if(J.intersectsNode(Y))$.push(Y)}return $}function V1(J,$){let Q=document.querySelectorAll(`[data-annotation-id="${J}"]`);for(let Z of Q)Z.style.cssText=$?`
68
68
  background: var(--color-highlight-bg);
69
69
  border-bottom: 1.5px solid var(--color-highlight-border);
70
70
  border-radius: 2px;
@@ -80,36 +80,36 @@ Please report this to https://github.com/markedjs/marked.`,J){let Z="<p>An error
80
80
  transition: background 150ms ease;
81
81
  color: inherit;
82
82
  padding: 1px 0;
83
- `}function W0(J,$){if($!=null&&$!==J)C1($,!1);if(J!=null)C1(J,!0)}function T0(J,$){let Q=document.querySelectorAll(`[data-annotation-id="${J}"]`);for(let Z of Q)Z.setAttribute("data-annotation-id",$)}function O0(J,$){let Q=$.filter((_)=>!document.querySelector(`[data-annotation-id="${_.id}"]`));if(!Q.length)return;let Z=[],Y="",X=document.createTreeWalker(J,NodeFilter.SHOW_TEXT),q;while(q=X.nextNode()){if(q.parentElement?.classList.contains("select-none"))continue;Z.push({node:q,start:Y.length}),Y+=q.textContent||""}for(let _ of Q){let z=_.snippet;if(!z)continue;let K=[],U=0;while(!0){let F=Y.indexOf(z,U);if(F===-1)break;K.push(F),U=F+1}if(K.length===0)continue;let H=K[0];if(K.length>1&&_.context){let F=-1;for(let L of K){let y=0;if(_.context.before){let S=Y.slice(Math.max(0,L-80),L);if(S.includes(_.context.before))y+=2;else if(_.context.before.length>10&&S.includes(_.context.before.slice(-10)))y+=1}if(_.context.after){let S=Y.slice(L+z.length,L+z.length+80);if(S.includes(_.context.after))y+=2;else if(_.context.after.length>10&&S.includes(_.context.after.slice(0,10)))y+=1}if(y>F)F=y,H=L}}let G=H,N=H+z.length,W=w5(Z,G),M=w5(Z,N);if(!W||!M)continue;try{let F=document.createRange();F.setStart(W.node,W.offset),F.setEnd(M.node,M.offset),u1(F,_.id)}catch{}}}function w5(J,$){for(let Q=J.length-1;Q>=0;Q--)if(J[Q].start<=$){let Z=$-J[Q].start,Y=J[Q].node.textContent?.length??0;if(Z<=Y)return{node:J[Q].node,offset:Z}}return null}function F0(J){let $=document.querySelectorAll(`[data-annotation-id="${J}"]`);for(let Q of $){let Z=Q.parentNode;if(!Z)continue;while(Q.firstChild)Z.insertBefore(Q.firstChild,Q);Z.removeChild(Q),Z.normalize()}}function C5(J,$){let Q=R5(J,"before",60),Z=R5(J,"after",60),Y=W3(J.startContainer,$);return{before:Q,after:Z,hierarchy:Y}}function R5(J,$,Q){let Z=N3($==="before"?J.startContainer:J.endContainer);if(!Z)return"";let Y="";if($==="before"){let X=document.createTreeWalker(Z,NodeFilter.SHOW_TEXT),q;while(q=X.nextNode()){if(q===J.startContainer){Y+=(q.textContent||"").slice(0,J.startOffset);break}if(q.parentElement?.hasAttribute("data-annotation-id"))continue;Y+=q.textContent||""}if(Y.length>Q){Y=Y.slice(-Q);let _=Y.indexOf(" ");if(_>0)Y=Y.slice(_+1)}}else{let X=document.createTreeWalker(Z,NodeFilter.SHOW_TEXT),q=!1,_;while(_=X.nextNode()){if(_===J.endContainer){Y+=(_.textContent||"").slice(J.endOffset),q=!0;continue}if(q){if(_.parentElement?.hasAttribute("data-annotation-id"))continue;Y+=_.textContent||""}}if(Y.length>Q){Y=Y.slice(0,Q);let z=Y.lastIndexOf(" ");if(z>0)Y=Y.slice(0,z)}}return Y.trim()}function N3(J){let $=new Set(["DIV","P","LI","PRE","BLOCKQUOTE","SECTION","ARTICLE"]),Q=J.parentElement;while(Q){if($.has(Q.tagName))return Q;Q=Q.parentElement}return null}function W3(J,$){let Q=[],Z=J instanceof Element?J:J.parentElement;while(Z&&Z!==$){let Y=Z.getAttribute?.("data-task-id");if(Y){let X=Z.querySelector(".font-semibold");if(X)Q.unshift(X.textContent?.trim()||Y)}if(Z.tagName==="DIV"&&Z.querySelector(":scope > button .font-heading, :scope > div .font-heading")){let X=Z.querySelector(".font-heading");if(X)Q.unshift(X.textContent?.trim()||"")}Z=Z.parentElement}return Q}function h0(J){let $=J.snippet.trim(),Q=J.context,Z=$.length<30;if(Q&&Z&&(Q.before||Q.after)){let Y=[];if(Q.before)Y.push(`...${Q.before} `);if(Y.push($),Q.after)Y.push(` ${Q.after}...`);return Y.join("")}return $}import{useEffect as y0,useRef as M0,useState as $0,useCallback as p0,useMemo as j5}from"react";import{createPortal as T3}from"react-dom";function m5(J,$){let Y=$||document.body,X=J.getBoundingClientRect(),q=Y.getBoundingClientRect(),_=Y===document.body?window.scrollY:Y.scrollTop,z=X.bottom-q.top+_+8,K=Math.max(0,Math.min(X.left-q.left,q.width-280-12));return Y.style.position="relative",{style:{position:"absolute",top:`${z}px`,left:`${K}px`},parent:Y}}import{jsxDEV as e}from"react/jsx-dev-runtime";function V5({anchorEl:J,scrollContainer:$,onClose:Q,ignoreSelector:Z,zIndex:Y="50",padding:X="12px",width:q="280px",children:_}){let z=M0(null),K=M0(Q);K.current=Q;let{style:U,parent:H}=m5(J,$);return y0(()=>{let G=setTimeout(()=>{let N=(W)=>{if(z.current&&!z.current.contains(W.target)){if(Z&&W.target.closest?.(Z))return;K.current(),document.removeEventListener("mousedown",N)}};return document.addEventListener("mousedown",N),()=>document.removeEventListener("mousedown",N)},0);return()=>clearTimeout(G)},[Z]),T3(e("div",{ref:z,style:{...U,zIndex:Y,width:q,background:"var(--color-bg-elevated)",border:"1px solid var(--color-border-hover)",borderRadius:"8px",boxShadow:"0 4px 12px var(--color-shadow)",padding:X,fontFamily:"'Inter', sans-serif"},children:_},void 0,!1,void 0,this),H)}var g5=[{label:"Clarity",items:["Unclear","Why?","Needs example","Missing context"]},{label:"Scope",items:["Overkill","Out of scope","Important","Risky"]},{label:"Action",items:["Simplify","Rethink","Expand on this","Skip this"]}],I5=g5.flatMap((J)=>J.items);function J0({anchorEl:J,scrollContainer:$,snippet:Q,truncateAt:Z=100,header:Y,onAdd:X,onCancel:q}){let[_,z]=$0(""),[K,U]=$0(null),[H,G]=$0(!1),N=M0(null);y0(()=>{N.current?.focus()},[]);let W=p0(()=>{if(_.trim())X(_.trim());else q()},[_,X,q]),M=_.trim().length>0?I5.filter((T)=>T.toLowerCase().startsWith(_.trim().toLowerCase())):I5,F=H?[]:M.length===1&&M[0].toLowerCase()===_.trim().toLowerCase()?[]:M,L=new Set(F),y=g5.map((T)=>({label:T.label,items:T.items.filter((B)=>L.has(B))})).filter((T)=>T.items.length>0),S=y.map((T)=>T.items),R=S.flat(),m=j5(()=>{if(K===null)return 0;let T=0;for(let B=0;B<S.length;B++){if(K<T+S[B].length)return B;T+=S[B].length}return 0},[K,S]),k=j5(()=>{if(K===null)return 0;let T=0;for(let B=0;B<m;B++)T+=S[B].length;return K-T},[K,m,S]),V=(T,B)=>{let c=0;for(let o=0;o<T;o++)c+=S[o].length;return c+B};y0(()=>{U(null),G(!1)},[_]);let w=p0((T)=>{z(T)},[]),I=Q.length>Z?Q.slice(0,Z)+"...":Q;return e(V5,{anchorEl:J,scrollContainer:$,onClose:q,width:"420px",children:[Y??e("div",{style:{fontSize:"11px",color:"var(--color-text-tertiary)",fontStyle:"italic",marginBottom:"8px",lineHeight:"1.4",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden"},children:["“",I,"”"]},void 0,!0,void 0,this),e("textarea",{ref:N,value:_,onChange:(T)=>z(T.target.value),onKeyDown:(T)=>{if(R.length>0&&(T.key==="ArrowDown"||T.key==="ArrowUp"||T.key==="ArrowLeft"||T.key==="ArrowRight")){if(T.preventDefault(),K===null){U(0);return}if(T.key==="ArrowDown"){let B=Math.min(k+1,S[m].length-1);U(V(m,B))}else if(T.key==="ArrowUp"){let B=Math.max(k-1,0);U(V(m,B))}else if(T.key==="ArrowRight"){let B=Math.min(m+1,S.length-1),c=Math.min(k,S[B].length-1);U(V(B,c))}else if(T.key==="ArrowLeft"){let B=Math.max(m-1,0),c=Math.min(k,S[B].length-1);U(V(B,c))}return}if(K!==null&&R.length>0){if(T.key==="Tab"){T.preventDefault(),w(R[K]);return}if(T.key==="Enter"&&!T.shiftKey){T.preventDefault(),X(R[K]);return}}if(T.key==="Enter"&&!T.shiftKey){T.preventDefault(),W();return}if(T.key==="Escape")if(R.length>0&&!H)G(!0);else q()},style:{width:"100%",minHeight:"60px",background:"transparent",border:"none",color:"var(--color-text-primary)",fontFamily:"'Inter', sans-serif",fontSize:"13px",lineHeight:"1.5",resize:"vertical",outline:"none"},placeholder:"Add your note..."},void 0,!1,void 0,this),e("div",{style:{display:"flex",justifyContent:"flex-end",gap:"8px",marginTop:"8px"},children:[e("button",{onClick:q,style:{fontSize:"11px",color:"var(--color-text-tertiary)",background:"none",border:"none",cursor:"pointer",padding:"4px 12px",fontFamily:"'Inter', sans-serif"},children:"Cancel"},void 0,!1,void 0,this),e("button",{onClick:W,style:{fontSize:"11px",fontWeight:500,padding:"4px 12px",borderRadius:"6px",background:"var(--color-highlight-bg)",color:"var(--color-text-primary)",border:"1px solid var(--color-highlight-border)",cursor:"pointer",fontFamily:"'Inter', sans-serif"},children:"Add"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),R.length>0&&e("div",{style:{marginTop:"6px",borderTop:"1px solid var(--color-border-subtle)",paddingTop:"8px",display:"flex",gap:"4px"},children:y.map((T)=>e("div",{style:{flex:1},children:[e("div",{style:{fontSize:"10px",fontWeight:600,color:"var(--color-text-disabled)",textTransform:"uppercase",letterSpacing:"0.05em",padding:"2px 6px",marginBottom:"2px",fontFamily:"'Inter', sans-serif"},children:T.label},void 0,!1,void 0,this),T.items.map((B)=>{let c=R.indexOf(B);return e("div",{onMouseDown:(o)=>{o.preventDefault(),o.stopPropagation(),w(B)},onMouseEnter:()=>U(c),style:{padding:"3px 6px",fontSize:"12px",borderRadius:"4px",fontFamily:"'Inter', sans-serif",color:c===K?"var(--color-text-primary)":"var(--color-text-secondary)",background:c===K?"var(--color-highlight-selected)":"transparent",cursor:"pointer"},children:[e("span",{style:{fontWeight:500},children:B.slice(0,_.trim().length)},void 0,!1,void 0,this),B.slice(_.trim().length)]},B,!0,void 0,this)})]},T.label,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Y0({anchorEl:J,scrollContainer:$,initialNote:Q,onUpdate:Z,onDelete:Y,onClose:X}){let[q,_]=$0(Q),z=M0(null),[K,U]=$0(!1);y0(()=>{let G=z.current;if(G)G.style.height="auto",G.style.height=G.scrollHeight+"px",G.focus(),G.setSelectionRange(G.value.length,G.value.length)},[]);let H=p0(()=>{if(!q.trim()){Y(),X();return}Z(q),X()},[q,Z,Y,X]);return e(V5,{anchorEl:J,scrollContainer:$,onClose:H,ignoreSelector:"[data-annotation-id]",zIndex:"60",padding:"10px 12px",children:[e("textarea",{ref:z,value:q,onChange:(G)=>{_(G.target.value),Z(G.target.value),G.target.style.height="auto",G.target.style.height=G.target.scrollHeight+"px"},onKeyDown:(G)=>{if(G.key==="Enter"&&!G.shiftKey)G.preventDefault(),H();if(G.key==="Escape")H()},style:{width:"100%",background:"transparent",border:"none",color:"var(--color-text-primary)",fontFamily:"'Inter', sans-serif",fontSize:"13px",lineHeight:"1.5",resize:"none",outline:"none",overflow:"hidden"}},void 0,!1,void 0,this),e("div",{style:{display:"flex",justifyContent:"flex-end",marginTop:"6px"},children:e("button",{onClick:()=>{Y(),X()},onMouseEnter:()=>U(!0),onMouseLeave:()=>U(!1),style:{fontSize:"11px",color:K?"var(--color-accent-red)":"var(--color-text-tertiary)",background:"none",border:"none",cursor:"pointer",padding:"2px 0",fontFamily:"'Inter', sans-serif"},children:"Delete"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{jsxDEV as l,Fragment as k5}from"react/jsx-dev-runtime";var r0="[data-md='item'], [data-md='section'], [data-md='table'] tbody tr, [data-md='callout'], [data-md='note'], [data-md='checklist-item'], [data-md='choice-option'], [data-md='multichoice-option'], [data-md='userinput'], [data-md='rangeinput'], [data-md='image']",d0="[data-md='item'], [data-md='section'], [data-md='table'] tbody tr, [data-md='callout'], [data-md='note'], [data-md='checklist-item'], [data-md='image']";function f5({revision:J}){let $=O3(M3),[Q,Z]=X1(null),[Y,X]=X1(null),[q,_]=X1(!0),z=D5(null),{annotations:K,addAnnotationWithId:U,removeAnnotation:H,updateAnnotation:G,activeAnnotationId:N,setActiveAnnotationId:W}=q1(),[M,F]=X1(null),[L,y]=X1(null),[S,R]=X1(null),[m,k]=X1(null),[V,w]=X1(null),[I,T]=X1(null),[B,c]=X1(!1);U1(()=>{_(!0),X(null),T(null),import(`/api/session/${$}/plan.js?rev=${J}&t=${Date.now()}`).then((b)=>{Z(()=>b.default),_(!1)}).catch((b)=>{X(b.message),_(!1)})},[$,J]),U1(()=>{if(!Q||!z.current)return;let b=setTimeout(()=>{if(z.current)O0(z.current,K)},50);return()=>clearTimeout(b)},[Q]);let o=D5(null);U1(()=>{W0(N,o.current),o.current=N},[N]),U1(()=>{let b=z.current;if(!b)return;let C=(p)=>{let u=p.target.closest("[data-annotation-id]");if(!u)return;p.stopPropagation();let r=u.getAttribute("data-annotation-id");if(r===N)y({anchorEl:u,annId:r});else W(r)},h=(p)=>{let u=p.target.closest("[data-annotation-id]");if(u){let r=u.getAttribute("data-annotation-id");W(r)}},x=(p)=>{let u=p.target.closest("[data-annotation-id]"),r=p.relatedTarget?.closest?.("[data-annotation-id]");if(u&&!r){if(!document.getElementById("ann-inline-popover"))W(null)}};return b.addEventListener("click",C),b.addEventListener("mouseover",h),b.addEventListener("mouseout",x),()=>{b.removeEventListener("click",C),b.removeEventListener("mouseover",h),b.removeEventListener("mouseout",x)}},[Q,K,N]);let Z1=B0(()=>{let b=new Map;for(let C of K)if(C.snippet.startsWith("["))b.set(C.snippet,C.id);return b},[K]);U1(()=>{let b=z.current;if(!b)return;let C=(x)=>{if(V||S||L)return;let p=x.target;if(p.closest("[data-block-comment-btn]"))return;c(!1);let u=p.closest(r0);if(u&&b.contains(u)){let A=m1(b).indexOf(u);T(A>=0?A:null)}else T(null);let r=p.closest(d0);if(r&&b.contains(r)){k(r);let d=v1(r),A=d?Z1.get(d):void 0;if(A&&A!==N)W(A)}else k(null)},h=(x)=>{if(V||S||L)return;if(x.relatedTarget?.closest("[data-block-comment-btn]"))return;k(null),W(null)};return b.addEventListener("mousemove",C),b.addEventListener("mouseleave",h),()=>{b.removeEventListener("mousemove",C),b.removeEventListener("mouseleave",h)}},[Q,V,S,L,Z1,N]),U1(()=>{let b=(C)=>{let h=C.target.tagName;if(h==="INPUT"||h==="TEXTAREA"||C.target.isContentEditable)return;if(V||S||L)return;let x=z.current;if(!x)return;if(C.key==="ArrowDown"){C.preventDefault(),c(!0);let p=m1(x);if(p.length===0)return;T((u)=>{if(u===null)return 0;return Math.min(u+1,p.length-1)})}else if(C.key==="ArrowUp"){C.preventDefault(),c(!0);let p=m1(x);if(p.length===0)return;T((u)=>{if(u===null)return p.length-1;return Math.max(u-1,0)})}else if(C.key==="a"||C.key==="A"){if(I===null||!x)return;C.preventDefault();let u=m1(x)[I];if(!u)return;let r=v1(u);if(!r)return;let d=Z1.get(r);if(d)W(d),w({anchorEl:u,snippet:r,annId:d});else w({anchorEl:u,snippet:r})}else if(C.key===" "||C.key==="Enter"){if(I===null)return;let u=m1(x)[I];if(!u)return;let r=u.getAttribute("data-md");if(r==="choice-option"||r==="multichoice-option")C.preventDefault(),u.dispatchEvent(new CustomEvent("kb-select",{bubbles:!0}));else if(r==="userinput"){C.preventDefault();let d=u.querySelector("textarea");if(d){d.focus();let A=(g)=>{if(g.key==="Escape")g.preventDefault(),d.blur(),c(!0)};d.addEventListener("keydown",A),d.addEventListener("blur",()=>d.removeEventListener("keydown",A),{once:!0})}}else if(r==="rangeinput"){C.preventDefault();let d=u.querySelector("input[type='range']");if(d){d.focus();let A=(g)=>{if(g.key==="Escape"||g.key==="ArrowUp"||g.key==="ArrowDown")g.preventDefault(),d.blur(),c(!0)};d.addEventListener("keydown",A),d.addEventListener("blur",()=>d.removeEventListener("keydown",A),{once:!0})}}}else if(C.key==="Escape")T(null),c(!1),W(null)};return document.addEventListener("keydown",b),()=>document.removeEventListener("keydown",b)},[I,V,S,L,Z1]),U1(()=>{let b=z.current;if(!b||I===null||!B)return;let h=m1(b)[I];if(!h)return;h.style.outline="2px solid var(--color-accent-blue)",h.style.outlineOffset="-2px",h.style.borderRadius="8px",h.scrollIntoView({block:"nearest",behavior:"smooth"});let x=v1(h),p=x?Z1.get(x):void 0;if(p)W(p);return()=>{h.style.outline="",h.style.outlineOffset="",h.style.borderRadius=""}},[I,B,Z1]),U1(()=>{let b=()=>P1();return document.addEventListener("mouseup",b),()=>document.removeEventListener("mouseup",b)},[]);let P1=F3(()=>{let b=window.getSelection();if(!b||b.isCollapsed||!b.toString().trim())return;if(!z.current)return;let C=b.getRangeAt(0);if(!z.current.contains(C.startContainer))return;if(C.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let h=b.toString().trim();if(h.length<2)return;let x=C.cloneRange(),p=C5(C,z.current),u=`__pending_${Date.now()}`;try{u1(x,u)}catch{}window.getSelection()?.removeAllRanges();let r=document.querySelectorAll(`[data-annotation-id="${u}"]`),d=r[r.length-1];if(!d)return;R({anchorEl:d,tempId:u,snippet:h,ctx:p})},[U]),j=B0(()=>Q?l(Q,{},void 0,!1,void 0,this):null,[Q]);if(q)return l("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-body",children:"Loading plan..."},void 0,!1,void 0,this);if(Y)return l("div",{className:"bg-accent-red-muted rounded-lg p-5",children:[l("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Compilation Error"},void 0,!1,void 0,this),l("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:Y},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(!Q)return l("div",{className:"text-text-tertiary text-center py-8 font-body text-body",children:"No plan loaded"},void 0,!1,void 0,this);let i=document.getElementById("plan-scroll-container");return l(k5,{children:[l("div",{ref:z,className:"plan-content plan-updated",children:j},void 0,!1,void 0,this),M&&l(P3,{note:M.note,onSave:(b)=>{G(M.id,b),F(null)},onCancel:()=>F(null)},void 0,!1,void 0,this),L&&(()=>{let b=K.find((C)=>C.id===L.annId);if(!b)return null;return l(Y0,{anchorEl:L.anchorEl,scrollContainer:i,initialNote:b.note,onUpdate:(C)=>G(L.annId,C),onDelete:()=>{H(L.annId),W(null)},onClose:()=>y(null)},void 0,!1,void 0,this)})(),S&&l(J0,{anchorEl:S.anchorEl,scrollContainer:i,snippet:S.snippet,truncateAt:80,onAdd:(b)=>{let C=H1();T0(S.tempId,C),U(C,S.snippet,b,void 0,S.ctx),R(null)},onCancel:()=>{F0(S.tempId),R(null)}},void 0,!1,void 0,this),l(B3,{containerRef:z,hoveredBlock:m,focusedBlockIndex:I,blockPopover:V,blockAnnotationMap:Z1,activeAnnotationId:N,onOpen:(b,C,h)=>{if(h)W(h),w({anchorEl:b,snippet:C,annId:h});else w({anchorEl:b,snippet:C})}},void 0,!1,void 0,this),V&&!V.annId&&l(J0,{anchorEl:V.anchorEl,scrollContainer:i,snippet:V.snippet,truncateAt:80,onAdd:(b)=>{let C=H1();U(C,V.snippet,b),w(null)},onCancel:()=>w(null)},void 0,!1,void 0,this),V?.annId&&(()=>{let b=K.find((C)=>C.id===V.annId);if(!b)return null;return l(Y0,{anchorEl:V.anchorEl,scrollContainer:i,initialNote:b.note,onUpdate:(C)=>G(V.annId,C),onDelete:()=>{H(V.annId),W(null),w(null)},onClose:()=>w(null)},void 0,!1,void 0,this)})()]},void 0,!0,void 0,this)}function m1(J){return Array.from(J.querySelectorAll(r0))}function v1(J){let $=J.getAttribute("data-md");if($==="item"){let Q=J.getAttribute("data-md-label");return Q?`[Item] ${Q}`:null}if($==="section"){let Q=J.getAttribute("data-md-title");return Q?`[Section] ${Q}`:null}if($==="callout"){let Q=J.getAttribute("data-md-type")||"info",Z=J.textContent?.trim().slice(0,60)||"Callout";return`[Callout:${Q}] ${Z}`}if($==="note")return`[Note] ${J.textContent?.trim().slice(0,60)||"Note"}`;if(J.tagName==="TR"){let Q=Array.from(J.querySelectorAll("td")).map((Z)=>Z.textContent?.trim()).filter(Boolean);return Q.length?`[Row] ${Q.join(" | ")}`:null}if($==="checklist-item"){let Q=J.getAttribute("data-md-label");return Q?`[Checklist] ${Q}`:null}if($==="choice-option"||$==="multichoice-option"){let Q=J.getAttribute("data-md-label");return Q?`[Option] ${Q}`:null}if($==="userinput"){let Q=J.getAttribute("data-md-label");return Q?`[Input] ${Q}`:null}if($==="rangeinput"){let Q=J.getAttribute("data-md-label");return Q?`[Range] ${Q}`:null}if($==="image"){let Q=J.getAttribute("data-md-src");return Q?`[Image] ${Q}`:null}return null}function B3({containerRef:J,hoveredBlock:$,focusedBlockIndex:Q,blockPopover:Z,blockAnnotationMap:Y,activeAnnotationId:X,onOpen:q}){let[_,z]=X1([]);U1(()=>{let N=J.current;if(!N||Y.size===0){z([]);return}let W=[];for(let M of N.querySelectorAll(d0)){let F=v1(M);if(F&&Y.has(F))W.push(M)}z(W)},[Y,J.current]);let[K,U]=X1(null);U1(()=>{if(!X||!J.current){U(null);return}for(let N of J.current.querySelectorAll(r0)){let W=v1(N);if(W&&Y.get(W)===X){U(N);return}}U(null)},[X,Y]),U1(()=>{if(!K)return;return K.style.boxShadow="inset 0 0 0 1.5px var(--color-highlight-bg)",K.style.borderRadius="8px",()=>{K.style.boxShadow="",K.style.borderRadius=""}},[K]);let H=B0(()=>{if(Q===null||!J.current)return null;let N=m1(J.current)[Q];if(!N)return null;return N.matches(d0)?N:null},[Q,J.current]),G=B0(()=>{let N=new Set(_);if($)N.add($);if(H)N.add(H);if(Z?.anchorEl)N.add(Z.anchorEl);return Array.from(N)},[_,$,H,Z]);return l(k5,{children:G.map((N)=>l(L3,{block:N,isHovered:N===$||N===H||N===Z?.anchorEl,blockAnnotationMap:Y,activeAnnotationId:X,onOpen:q},N.getAttribute("data-task-id")||N.getAttribute("data-md-title")||N.textContent?.slice(0,30)||"block",!1,void 0,this))},void 0,!1,void 0,this)}function L3({block:J,isHovered:$,blockAnnotationMap:Q,activeAnnotationId:Z,onOpen:Y}){let X=v1(J);if(!X)return null;let q=Q.get(X),_=!!q;return y3(l("button",{"data-block-comment-btn":!0,onClick:(K)=>{K.stopPropagation(),Y(K.currentTarget,X,q)},className:`absolute top-1 right-1 z-10 w-6 h-6 flex items-center justify-center rounded transition-all duration-150 ${_?q===Z?"text-accent-amber bg-accent-amber-muted":"text-accent-amber opacity-60 hover:opacity-100":$?"text-text-disabled hover:text-text-tertiary opacity-50 hover:opacity-100":"text-text-disabled opacity-0 group-hover/section:opacity-20 hover:!opacity-80"}`,title:_?"Edit annotation":"Add annotation",children:l("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:_?"currentColor":"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:l("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),J)}function P3({note:J,onSave:$,onCancel:Q}){let[Z,Y]=c0.useState(J),X=c0.useRef(null);return c0.useEffect(()=>{X.current?.focus(),X.current?.select()},[]),l("div",{className:"fixed inset-0 z-50 bg-black/40 flex items-center justify-center",onClick:Q,children:l("div",{className:"bg-bg-elevated border border-border-hover rounded-lg shadow-md p-4 w-80",onClick:(q)=>q.stopPropagation(),children:[l("div",{className:"text-tiny uppercase tracking-widest text-text-tertiary font-body mb-2",children:"Edit annotation"},void 0,!1,void 0,this),l("textarea",{ref:X,value:Z,onChange:(q)=>Y(q.target.value),className:"w-full bg-transparent border-none text-body font-body text-text-primary resize-vertical focus:outline-none min-h-[60px]",onKeyDown:(q)=>{if(q.key==="Enter"&&(q.ctrlKey||q.metaKey))$(Z.trim());if(q.key==="Escape")Q()}},void 0,!1,void 0,this),l("div",{className:"flex justify-end gap-2 mt-2",children:[l("button",{onClick:Q,className:"text-meta text-text-tertiary font-body px-3 py-1",children:"Cancel"},void 0,!1,void 0,this),l("button",{onClick:()=>$(Z.trim()),className:"text-meta font-medium font-body px-3 py-1 rounded-md bg-highlight-bg text-text-primary border border-highlight-border",children:"Save"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}import I3,{useRef as x5,useEffect as o0,useCallback as h5,useState as x1,useContext as i0}from"react";function Q0(J,$,Q,Z){let Y=[],X=J.filter((U)=>!U.filePath),q=J.filter((U)=>U.filePath),_=Q?Array.from(Q.values()).filter((U)=>l0(U)):[],z=Z?Array.from(Z.values()).filter((U)=>U.markdown.trim()):[];if(_.length>0||z.length>0){Y.push("## Responses"),Y.push("");for(let U of _)Y.push(A3(U));for(let U of z)Y.push(U.markdown.trim()),Y.push("")}if(X.length>0){Y.push("## Plan annotations"),Y.push("");let U=w3(X);Y.push(v5(U))}if(q.length>0){let U={};for(let H of q){let G=H.filePath;if(!U[G])U[G]=[];U[G].push(H)}Y.push("## File annotations"),Y.push("");for(let[H,G]of Object.entries(U)){Y.push(`### ${H}`),Y.push("");for(let N of G)Y.push(u5(N))}}if($.trim())Y.push("## General notes"),Y.push(""),Y.push($.trim()),Y.push("");return Y.join(`
83
+ `}function c1(J,$){if($!=null&&$!==J)V1($,!1);if(J!=null)V1(J,!0)}function d1(J,$){let Q=document.querySelectorAll(`[data-annotation-id="${J}"]`);for(let Z of Q)Z.setAttribute("data-annotation-id",$)}function r1(J,$){let Q=$.filter((K)=>!document.querySelector(`[data-annotation-id="${K.id}"]`));if(!Q.length)return;let Z=[],Y="",X=document.createTreeWalker(J,NodeFilter.SHOW_TEXT),q;while(q=X.nextNode()){if(q.parentElement?.classList.contains("select-none"))continue;Z.push({node:q,start:Y.length}),Y+=q.textContent||""}for(let K of Q){let z=K.snippet;if(!z)continue;let _=[],U=0;while(!0){let T=Y.indexOf(z,U);if(T===-1)break;_.push(T),U=T+1}if(_.length===0)continue;let G=_[0];if(_.length>1&&K.context){let T=-1;for(let M of _){let y=0;if(K.context.before){let L=Y.slice(Math.max(0,M-80),M);if(L.includes(K.context.before))y+=2;else if(K.context.before.length>10&&L.includes(K.context.before.slice(-10)))y+=1}if(K.context.after){let L=Y.slice(M+z.length,M+z.length+80);if(L.includes(K.context.after))y+=2;else if(K.context.after.length>10&&L.includes(K.context.after.slice(0,10)))y+=1}if(y>T)T=y,G=M}}let H=G,F=G+z.length,W=m5(Z,H),B=m5(Z,F);if(!W||!B)continue;try{let T=document.createRange();T.setStart(W.node,W.offset),T.setEnd(B.node,B.offset),L1(T,K.id)}catch{}}}function m5(J,$){for(let Q=J.length-1;Q>=0;Q--)if(J[Q].start<=$){let Z=$-J[Q].start,Y=J[Q].node.textContent?.length??0;if(Z<=Y)return{node:J[Q].node,offset:Z}}return null}function l1(J){let $=document.querySelectorAll(`[data-annotation-id="${J}"]`);for(let Q of $){let Z=Q.parentNode;if(!Z)continue;while(Q.firstChild)Z.insertBefore(Q.firstChild,Q);Z.removeChild(Q),Z.normalize()}}function B0(J,$){let Q=I5(J,"before",60),Z=I5(J,"after",60),Y=T3(J.startContainer,$);return{before:Q,after:Z,hierarchy:Y}}function I5(J,$,Q){let Z=N3($==="before"?J.startContainer:J.endContainer);if(!Z)return"";let Y="";if($==="before"){let X=document.createTreeWalker(Z,NodeFilter.SHOW_TEXT),q;while(q=X.nextNode()){if(q===J.startContainer){Y+=(q.textContent||"").slice(0,J.startOffset);break}if(q.parentElement?.hasAttribute("data-annotation-id"))continue;Y+=q.textContent||""}if(Y.length>Q){Y=Y.slice(-Q);let K=Y.indexOf(" ");if(K>0)Y=Y.slice(K+1)}}else{let X=document.createTreeWalker(Z,NodeFilter.SHOW_TEXT),q=!1,K;while(K=X.nextNode()){if(K===J.endContainer){Y+=(K.textContent||"").slice(J.endOffset),q=!0;continue}if(q){if(K.parentElement?.hasAttribute("data-annotation-id"))continue;Y+=K.textContent||""}}if(Y.length>Q){Y=Y.slice(0,Q);let z=Y.lastIndexOf(" ");if(z>0)Y=Y.slice(0,z)}}return Y.trim()}function N3(J){let $=new Set(["DIV","P","LI","PRE","BLOCKQUOTE","SECTION","ARTICLE"]),Q=J.parentElement;while(Q){if($.has(Q.tagName))return Q;Q=Q.parentElement}return null}function T3(J,$){let Q=[],Z=J instanceof Element?J:J.parentElement;while(Z&&Z!==$){let Y=Z.getAttribute?.("data-task-id");if(Y){let X=Z.querySelector(".font-semibold");if(X)Q.unshift(X.textContent?.trim()||Y)}if(Z.tagName==="DIV"&&Z.querySelector(":scope > button .font-heading, :scope > div .font-heading")){let X=Z.querySelector(".font-heading");if(X)Q.unshift(X.textContent?.trim()||"")}Z=Z.parentElement}return Q}function d0(J){let $=J.snippet.trim(),Q=J.context,Z=$.length<30;if(Q&&Z&&(Q.before||Q.after)){let Y=[];if(Q.before)Y.push(`...${Q.before} `);if(Y.push(`**${$}**`),Q.after)Y.push(` ${Q.after}...`);return Y.join("")}return $}import{useEffect as M0,useRef as L0,useState as K0,useCallback as r0,useMemo as g5}from"react";import{createPortal as O3}from"react-dom";function V5(J,$){let Y=$||document.body,X=J.getBoundingClientRect(),q=Y.getBoundingClientRect(),K=Y===document.body?window.scrollY:Y.scrollTop,z=X.bottom-q.top+K+8,_=Math.max(0,Math.min(X.left-q.left,q.width-280-12));return Y.style.position="relative",{style:{position:"absolute",top:`${z}px`,left:`${_}px`},parent:Y}}import{jsxDEV as $1}from"react/jsx-dev-runtime";function f5({anchorEl:J,scrollContainer:$,onClose:Q,ignoreSelector:Z,zIndex:Y="50",padding:X="12px",width:q="280px",children:K}){let z=L0(null),_=L0(Q);_.current=Q;let{style:U,parent:G}=V5(J,$);return M0(()=>{let H=setTimeout(()=>{let F=(W)=>{if(z.current&&!z.current.contains(W.target)){if(Z&&W.target.closest?.(Z))return;_.current(),document.removeEventListener("mousedown",F)}};return document.addEventListener("mousedown",F),()=>document.removeEventListener("mousedown",F)},0);return()=>clearTimeout(H)},[Z]),O3($1("div",{ref:z,style:{...U,zIndex:Y,width:q,background:"var(--color-bg-elevated)",border:"1px solid var(--color-border-hover)",borderRadius:"8px",boxShadow:"0 4px 12px var(--color-shadow)",padding:X,fontFamily:"'Inter', sans-serif"},children:K},void 0,!1,void 0,this),G)}var k5=[{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"]}],D5=k5.flatMap((J)=>J.items);function g1({anchorEl:J,scrollContainer:$,snippet:Q,truncateAt:Z=100,header:Y,onAdd:X,onCancel:q}){let[K,z]=K0(""),[_,U]=K0(null),[G,H]=K0(!1),F=L0(null);M0(()=>{F.current?.focus()},[]);let W=r0(()=>{if(K.trim())X(K.trim());else q()},[K,X,q]),B=K.trim().length>0?D5.filter((P)=>P.toLowerCase().startsWith(K.trim().toLowerCase())):D5,T=G?[]:B.length===1&&B[0].toLowerCase()===K.trim().toLowerCase()?[]:B,M=new Set(T),y=k5.map((P)=>({label:P.label,items:P.items.filter((O)=>M.has(O))})).filter((P)=>P.items.length>0),L=y.map((P)=>P.items),C=L.flat(),R=g5(()=>{if(_===null)return 0;let P=0;for(let O=0;O<L.length;O++){if(_<P+L[O].length)return O;P+=L[O].length}return 0},[_,L]),D=g5(()=>{if(_===null)return 0;let P=0;for(let O=0;O<R;O++)P+=L[O].length;return _-P},[_,R,L]),V=(P,O)=>{let j=0;for(let o=0;o<P;o++)j+=L[o].length;return j+O};M0(()=>{U(null),H(!1)},[K]);let b=r0((P)=>{z(P)},[]),I=Q.length>Z?Q.slice(0,Z)+"...":Q;return $1(f5,{anchorEl:J,scrollContainer:$,onClose:q,width:"420px",children:[Y??$1("div",{style:{fontSize:"11px",color:"var(--color-text-tertiary)",fontStyle:"italic",marginBottom:"8px",lineHeight:"1.4",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden"},children:["“",I,"”"]},void 0,!0,void 0,this),$1("textarea",{ref:F,value:K,onChange:(P)=>z(P.target.value),onKeyDown:(P)=>{if(C.length>0&&(P.key==="ArrowDown"||P.key==="ArrowUp"||P.key==="ArrowLeft"||P.key==="ArrowRight")){if(P.preventDefault(),_===null){U(0);return}if(P.key==="ArrowDown"){let O=Math.min(D+1,L[R].length-1);U(V(R,O))}else if(P.key==="ArrowUp"){let O=Math.max(D-1,0);U(V(R,O))}else if(P.key==="ArrowRight"){let O=Math.min(R+1,L.length-1),j=Math.min(D,L[O].length-1);U(V(O,j))}else if(P.key==="ArrowLeft"){let O=Math.max(R-1,0),j=Math.min(D,L[O].length-1);U(V(O,j))}return}if(_!==null&&C.length>0){if(P.key==="Tab"){P.preventDefault(),b(C[_]);return}if(P.key==="Enter"&&!P.shiftKey){P.preventDefault(),X(C[_]);return}}if(P.key==="Enter"&&!P.shiftKey){P.preventDefault(),W();return}if(P.key==="Escape")if(C.length>0&&!G)H(!0);else q()},style:{width:"100%",minHeight:"60px",background:"transparent",border:"none",color:"var(--color-text-primary)",fontFamily:"'Inter', sans-serif",fontSize:"13px",lineHeight:"1.5",resize:"vertical",outline:"none"},placeholder:"Add your note..."},void 0,!1,void 0,this),$1("div",{style:{display:"flex",justifyContent:"flex-end",gap:"8px",marginTop:"8px"},children:[$1("button",{onClick:q,style:{fontSize:"11px",color:"var(--color-text-tertiary)",background:"none",border:"none",cursor:"pointer",padding:"4px 12px",fontFamily:"'Inter', sans-serif"},children:"Cancel"},void 0,!1,void 0,this),$1("button",{onClick:W,style:{fontSize:"11px",fontWeight:500,padding:"4px 12px",borderRadius:"6px",background:"var(--color-highlight-bg)",color:"var(--color-text-primary)",border:"1px solid var(--color-highlight-border)",cursor:"pointer",fontFamily:"'Inter', sans-serif"},children:"Add"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),C.length>0&&$1("div",{style:{marginTop:"6px",borderTop:"1px solid var(--color-border-subtle)",paddingTop:"8px",display:"flex",gap:"4px"},children:y.map((P)=>$1("div",{style:{flex:1},children:[$1("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:P.label},void 0,!1,void 0,this),P.items.map((O)=>{let j=C.indexOf(O);return $1("div",{onMouseDown:(o)=>{o.preventDefault(),o.stopPropagation(),b(O)},onMouseEnter:()=>U(j),style:{padding:"3px 6px",fontSize:"12px",borderRadius:"4px",fontFamily:"'Inter', sans-serif",color:j===_?"var(--color-text-primary)":"var(--color-text-secondary)",background:j===_?"var(--color-highlight-selected)":"transparent",cursor:"pointer"},children:[$1("span",{style:{fontWeight:500},children:O.slice(0,K.trim().length)},void 0,!1,void 0,this),O.slice(K.trim().length)]},O,!0,void 0,this)})]},P.label,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function D1({anchorEl:J,scrollContainer:$,initialNote:Q,onUpdate:Z,onDelete:Y,onClose:X}){let[q,K]=K0(Q),z=L0(null),[_,U]=K0(!1);M0(()=>{let H=z.current;if(H)H.style.height="auto",H.style.height=H.scrollHeight+"px",H.focus(),H.setSelectionRange(H.value.length,H.value.length)},[]);let G=r0(()=>{if(!q.trim()){Y(),X();return}Z(q),X()},[q,Z,Y,X]);return $1(f5,{anchorEl:J,scrollContainer:$,onClose:G,ignoreSelector:"[data-annotation-id]",zIndex:"60",padding:"10px 12px",children:[$1("textarea",{ref:z,value:q,onChange:(H)=>{K(H.target.value),Z(H.target.value),H.target.style.height="auto",H.target.style.height=H.target.scrollHeight+"px"},onKeyDown:(H)=>{if(H.key==="Enter"&&!H.shiftKey)H.preventDefault(),G();if(H.key==="Escape")G()},style:{width:"100%",background:"transparent",border:"none",color:"var(--color-text-primary)",fontFamily:"'Inter', sans-serif",fontSize:"13px",lineHeight:"1.5",resize:"none",outline:"none",overflow:"hidden"}},void 0,!1,void 0,this),$1("div",{style:{display:"flex",justifyContent:"flex-end",marginTop:"6px"},children:$1("button",{onClick:()=>{Y(),X()},onMouseEnter:()=>U(!0),onMouseLeave:()=>U(!1),style:{fontSize:"11px",color:_?"var(--color-accent-red)":"var(--color-text-tertiary)",background:"none",border:"none",cursor:"pointer",padding:"2px 0",fontFamily:"'Inter', sans-serif"},children:"Delete"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{jsxDEV as l,Fragment as E5}from"react/jsx-dev-runtime";var i0="[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']",a0="[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 v5({revision:J}){let $=B3(P3),[Q,Z]=X1(null),[Y,X]=X1(null),[q,K]=X1(!0),z=u5(null),{annotations:_,addAnnotationWithId:U,removeAnnotation:G,updateAnnotation:H,activeAnnotationId:F,setActiveAnnotationId:W}=q1(),[B,T]=X1(null),[M,y]=X1(null),[L,C]=X1(null),[R,D]=X1(null),[V,b]=X1(null),[I,P]=X1(null),[O,j]=X1(!1);H1(()=>{K(!0),X(null),P(null),import(`/api/session/${$}/plan.js?rev=${J}&t=${Date.now()}`).then((w)=>{Z(()=>w.default),K(!1)}).catch((w)=>{X(w.message),K(!1)})},[$,J]),H1(()=>{if(!Q||!z.current)return;let w=setTimeout(()=>{if(z.current)r1(z.current,_)},50);return()=>clearTimeout(w)},[Q]);let o=u5(null);H1(()=>{c1(F,o.current),o.current=F},[F]),H1(()=>{let w=z.current;if(!w)return;let m=(c)=>{let v=c.target.closest("[data-annotation-id]");if(!v)return;c.stopPropagation();let r=v.getAttribute("data-annotation-id");if(r===F)y({anchorEl:v,annId:r});else W(r)},p=(c)=>{let v=c.target.closest("[data-annotation-id]");if(v){let r=v.getAttribute("data-annotation-id");W(r)}},h=(c)=>{let v=c.target.closest("[data-annotation-id]"),r=c.relatedTarget?.closest?.("[data-annotation-id]");if(v&&!r){if(!document.getElementById("ann-inline-popover"))W(null)}};return w.addEventListener("click",m),w.addEventListener("mouseover",p),w.addEventListener("mouseout",h),()=>{w.removeEventListener("click",m),w.removeEventListener("mouseover",p),w.removeEventListener("mouseout",h)}},[Q,_,F]);let Z1=P0(()=>{let w=new Map;for(let m of _)if(m.snippet.startsWith("["))w.set(m.snippet,m.id);return w},[_]);H1(()=>{let w=z.current;if(!w)return;let m=(h)=>{if(V||L||M)return;let c=h.target;if(c.closest("[data-block-comment-btn]"))return;j(!1);let v=c.closest(i0);if(v&&w.contains(v)){let A=f1(w).indexOf(v);P(A>=0?A:null)}else P(null);let r=c.closest(a0);if(r&&w.contains(r)){D(r);let d=a1(r),A=d?Z1.get(d):void 0;if(A&&A!==F)W(A)}else D(null)},p=(h)=>{if(V||L||M)return;if(h.relatedTarget?.closest("[data-block-comment-btn]"))return;D(null),W(null)};return w.addEventListener("mousemove",m),w.addEventListener("mouseleave",p),()=>{w.removeEventListener("mousemove",m),w.removeEventListener("mouseleave",p)}},[Q,V,L,M,Z1,F]),H1(()=>{let w=(m)=>{let p=m.target.tagName;if(p==="INPUT"||p==="TEXTAREA"||m.target.isContentEditable)return;if(V||L||M)return;let h=z.current;if(!h)return;if(m.key==="ArrowDown"){m.preventDefault(),j(!0);let c=f1(h);if(c.length===0)return;P((v)=>{if(v===null)return 0;return Math.min(v+1,c.length-1)})}else if(m.key==="ArrowUp"){m.preventDefault(),j(!0);let c=f1(h);if(c.length===0)return;P((v)=>{if(v===null)return c.length-1;return Math.max(v-1,0)})}else if(m.key==="a"||m.key==="A"){if(I===null||!h)return;m.preventDefault();let v=f1(h)[I];if(!v)return;let r=a1(v);if(!r)return;let d=Z1.get(r);if(d)W(d),b({anchorEl:v,snippet:r,annId:d});else b({anchorEl:v,snippet:r})}else if(m.key===" "||m.key==="Enter"){if(I===null)return;let v=f1(h)[I];if(!v)return;let r=v.getAttribute("data-md");if(r==="choice-option"||r==="multichoice-option")m.preventDefault(),v.dispatchEvent(new CustomEvent("kb-select",{bubbles:!0}));else if(r==="userinput"){m.preventDefault();let d=v.querySelector("textarea");if(d){d.focus();let A=(f)=>{if(f.key==="Escape")f.preventDefault(),d.blur(),j(!0)};d.addEventListener("keydown",A),d.addEventListener("blur",()=>d.removeEventListener("keydown",A),{once:!0})}}else if(r==="rangeinput"){m.preventDefault();let d=v.querySelector("input[type='range']");if(d){d.focus();let A=(f)=>{if(f.key==="Escape"||f.key==="ArrowUp"||f.key==="ArrowDown")f.preventDefault(),d.blur(),j(!0)};d.addEventListener("keydown",A),d.addEventListener("blur",()=>d.removeEventListener("keydown",A),{once:!0})}}}else if(m.key==="Escape")P(null),j(!1),W(null)};return document.addEventListener("keydown",w),()=>document.removeEventListener("keydown",w)},[I,V,L,M,Z1]),H1(()=>{let w=z.current;if(!w||I===null||!O)return;let p=f1(w)[I];if(!p)return;p.style.outline="2px solid var(--color-accent-blue)",p.style.outlineOffset="-2px",p.style.borderRadius="8px",p.scrollIntoView({block:"nearest",behavior:"smooth"});let h=a1(p),c=h?Z1.get(h):void 0;if(c)W(c);return()=>{p.style.outline="",p.style.outlineOffset="",p.style.borderRadius=""}},[I,O,Z1]),H1(()=>{let w=()=>C1();return document.addEventListener("mouseup",w),()=>document.removeEventListener("mouseup",w)},[]);let C1=M3(()=>{let w=window.getSelection();if(!w||w.isCollapsed||!w.toString().trim())return;if(!z.current)return;let m=w.getRangeAt(0);if(!z.current.contains(m.startContainer))return;if(m.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let p=w.toString().trim();if(p.length<2)return;let h=m.cloneRange(),c=B0(m,z.current),v=`__pending_${Date.now()}`;try{L1(h,v)}catch{}window.getSelection()?.removeAllRanges();let r=document.querySelectorAll(`[data-annotation-id="${v}"]`),d=r[r.length-1];if(!d)return;C({anchorEl:d,tempId:v,snippet:p,ctx:c})},[U]),g=P0(()=>Q?l(Q,{},void 0,!1,void 0,this):null,[Q]);if(q)return l("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-body",children:"Loading canvas..."},void 0,!1,void 0,this);if(Y)return l("div",{className:"bg-accent-red-muted rounded-lg p-5",children:[l("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Compilation Error"},void 0,!1,void 0,this),l("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:Y},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(!Q)return l("div",{className:"text-text-tertiary text-center py-8 font-body text-body",children:"No canvas loaded"},void 0,!1,void 0,this);let i=document.getElementById("plan-scroll-container");return l(E5,{children:[l("div",{ref:z,className:"plan-content plan-updated",children:g},void 0,!1,void 0,this),B&&l(w3,{note:B.note,onSave:(w)=>{H(B.id,w),T(null)},onCancel:()=>T(null)},void 0,!1,void 0,this),M&&(()=>{let w=_.find((m)=>m.id===M.annId);if(!w)return null;return l(D1,{anchorEl:M.anchorEl,scrollContainer:i,initialNote:w.note,onUpdate:(m)=>H(M.annId,m),onDelete:()=>{G(M.annId),W(null)},onClose:()=>y(null)},void 0,!1,void 0,this)})(),L&&l(g1,{anchorEl:L.anchorEl,scrollContainer:i,snippet:L.snippet,truncateAt:80,onAdd:(w)=>{let m=G1();d1(L.tempId,m),U(m,L.snippet,w,void 0,L.ctx),C(null)},onCancel:()=>{l1(L.tempId),C(null)}},void 0,!1,void 0,this),l(S3,{containerRef:z,hoveredBlock:R,focusedBlockIndex:I,blockPopover:V,blockAnnotationMap:Z1,activeAnnotationId:F,onOpen:(w,m,p)=>{if(p)W(p),b({anchorEl:w,snippet:m,annId:p});else b({anchorEl:w,snippet:m})}},void 0,!1,void 0,this),V&&!V.annId&&l(g1,{anchorEl:V.anchorEl,scrollContainer:i,snippet:V.snippet,truncateAt:80,onAdd:(w)=>{let m=G1();U(m,V.snippet,w),b(null)},onCancel:()=>b(null)},void 0,!1,void 0,this),V?.annId&&(()=>{let w=_.find((m)=>m.id===V.annId);if(!w)return null;return l(D1,{anchorEl:V.anchorEl,scrollContainer:i,initialNote:w.note,onUpdate:(m)=>H(V.annId,m),onDelete:()=>{G(V.annId),W(null),b(null)},onClose:()=>b(null)},void 0,!1,void 0,this)})()]},void 0,!0,void 0,this)}function f1(J){return Array.from(J.querySelectorAll(i0))}function a1(J){let $=J.getAttribute("data-md");if($==="item"){let Q=J.getAttribute("data-md-label");return Q?`[Item] ${Q}`:null}if($==="section"){let Q=J.getAttribute("data-md-title");return Q?`[Section] ${Q}`:null}if($==="callout"){let Q=J.getAttribute("data-md-type")||"info",Z=J.textContent?.trim().slice(0,60)||"Callout";return`[Callout:${Q}] ${Z}`}if($==="note")return`[Note] ${J.textContent?.trim().slice(0,60)||"Note"}`;if(J.tagName==="TR"){let Q=Array.from(J.querySelectorAll("td")).map((Z)=>Z.textContent?.trim()).filter(Boolean);return Q.length?`[Row] ${Q.join(" | ")}`:null}if($==="checklist-item"){let Q=J.getAttribute("data-md-label");return Q?`[Checklist] ${Q}`:null}if($==="choice-option"||$==="multichoice-option"){let Q=J.getAttribute("data-md-label");return Q?`[Option] ${Q}`:null}if($==="userinput"){let Q=J.getAttribute("data-md-label");return Q?`[Input] ${Q}`:null}if($==="rangeinput"){let Q=J.getAttribute("data-md-label");return Q?`[Range] ${Q}`:null}if($==="image"){let Q=J.getAttribute("data-md-src");return Q?`[Image] ${Q}`:null}return null}function S3({containerRef:J,hoveredBlock:$,focusedBlockIndex:Q,blockPopover:Z,blockAnnotationMap:Y,activeAnnotationId:X,onOpen:q}){let[K,z]=X1([]);H1(()=>{let F=J.current;if(!F||Y.size===0){z([]);return}let W=[];for(let B of F.querySelectorAll(a0)){let T=a1(B);if(T&&Y.has(T))W.push(B)}z(W)},[Y,J.current]);let[_,U]=X1(null);H1(()=>{if(!X||!J.current){U(null);return}for(let F of J.current.querySelectorAll(i0)){let W=a1(F);if(W&&Y.get(W)===X){U(F);return}}U(null)},[X,Y]),H1(()=>{if(!_)return;return _.style.boxShadow="inset 0 0 0 1.5px var(--color-highlight-bg)",_.style.borderRadius="8px",()=>{_.style.boxShadow="",_.style.borderRadius=""}},[_]);let G=P0(()=>{if(Q===null||!J.current)return null;let F=f1(J.current)[Q];if(!F)return null;return F.matches(a0)?F:null},[Q,J.current]),H=P0(()=>{let F=new Set(K);if($)F.add($);if(G)F.add(G);if(Z?.anchorEl)F.add(Z.anchorEl);return Array.from(F)},[K,$,G,Z]);return l(E5,{children:H.map((F)=>l(b3,{block:F,isHovered:F===$||F===G||F===Z?.anchorEl,blockAnnotationMap:Y,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 b3({block:J,isHovered:$,blockAnnotationMap:Q,activeAnnotationId:Z,onOpen:Y}){let X=a1(J);if(!X)return null;let q=Q.get(X),K=!!q;return L3(l("button",{"data-block-comment-btn":!0,onClick:(_)=>{_.stopPropagation(),Y(_.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 ${K?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:K?"Edit annotation":"Add annotation",children:l("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:K?"currentColor":"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:l("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),J)}function w3({note:J,onSave:$,onCancel:Q}){let[Z,Y]=l0.useState(J),X=l0.useRef(null);return l0.useEffect(()=>{X.current?.focus(),X.current?.select()},[]),l("div",{className:"fixed inset-0 z-50 bg-black/40 flex items-center justify-center",onClick:Q,children:l("div",{className:"bg-bg-elevated border border-border-hover rounded-lg shadow-md p-4 w-80",onClick:(q)=>q.stopPropagation(),children:[l("div",{className:"text-tiny uppercase tracking-widest text-text-tertiary font-body mb-2",children:"Edit annotation"},void 0,!1,void 0,this),l("textarea",{ref:X,value:Z,onChange:(q)=>Y(q.target.value),className:"w-full bg-transparent border-none text-body font-body text-text-primary resize-vertical focus:outline-none min-h-[60px]",onKeyDown:(q)=>{if(q.key==="Enter"&&(q.ctrlKey||q.metaKey))$(Z.trim());if(q.key==="Escape")Q()}},void 0,!1,void 0,this),l("div",{className:"flex justify-end gap-2 mt-2",children:[l("button",{onClick:Q,className:"text-meta text-text-tertiary font-body px-3 py-1",children:"Cancel"},void 0,!1,void 0,this),l("button",{onClick:()=>$(Z.trim()),className:"text-meta font-medium font-body px-3 py-1 rounded-md bg-highlight-bg text-text-primary border border-highlight-border",children:"Save"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}import D3,{useRef as p5,useEffect as e0,useCallback as c5,useState as o1,useContext as n0}from"react";function _0(J,$,Q,Z){let Y=[],X=J.filter((G)=>G.filePath===U1),q=J.filter((G)=>!G.filePath),K=J.filter((G)=>G.filePath&&G.filePath!==U1),z=Q?Array.from(Q.values()).filter((G)=>s0(G)):[],_=Z?Array.from(Z.values()).filter((G)=>G.markdown.trim()):[];if(z.length>0||_.length>0){Y.push("## Responses"),Y.push("");for(let G of z)Y.push(R3(G));for(let G of _)Y.push(G.markdown.trim()),Y.push("")}if(X.length>0){Y.push("## Annotations on agent response"),Y.push("");for(let G of X)Y.push(o0(G))}if(q.length>0){Y.push("## Canvas annotations"),Y.push("");let G=j3(q);Y.push(x5(G))}if(K.length>0){let G={};for(let H of K){let F=H.filePath;if(!G[F])G[F]=[];G[F].push(H)}Y.push("## File annotations"),Y.push("");for(let[H,F]of Object.entries(G)){Y.push(`### ${H}`),Y.push("");for(let W of F)Y.push(o0(W))}}if($.trim())Y.push("## General notes"),Y.push(""),Y.push($.trim()),Y.push("");return Y.join(`
84
84
  `).trim()+`
85
- `}function l0(J){if(J.note?.trim())return!0;if(J.value===null||J.value===void 0)return!1;if(J.type==="text"&&!J.value.trim())return!1;if(J.type==="checkbox"&&J.value.length===0)return!1;return!0}function S3(J){let $=[];for(let Q of J.values()){if(!Q.required)continue;if(Q.value===null||Q.value===void 0){$.push(Q);continue}if(Q.type==="text"&&!Q.value.trim()){$.push(Q);continue}if(Q.type==="checkbox"&&Q.value.length===0){$.push(Q);continue}}return $}function b3(J){let $=[];for(let Q of J.values())if(Q.required&&!Q.markdown.trim())$.push(Q);return $}function L0(J,$){let Q=S3(J),Z=b3($);return[...Q.map((Y)=>Y.label),...Z.map((Y)=>Y.label||Y.id)]}function A3(J){let $=[];switch($.push(`**${J.label}**`),J.type){case"radio":case"select":$.push(`Answer: ${J.value}`);break;case"checkbox":for(let Q of J.value)$.push(`- [x] ${Q}`);break;case"text":$.push(""),$.push(J.value.trim());break;case"range":$.push(`Answer: ${J.value}`);break}if(J.note?.trim())$.push(""),$.push(`Note: ${J.note.trim()}`);return $.push(""),$.join(`
86
- `)}function u5(J){let $=[],Q=J.snippet.trim(),Z=J.context,Y=Z?.lineStart!=null;if(J.filePath&&Y){let X=Z.lineStart,q=Z.lineEnd??X,_=Q.split(`
87
- `);if(Q.length<30&&X===q&&(Z.before||Z.after)){let K=h0(J);$.push(`> L${X}: ${K}`)}else if(_.length<=6)for(let K=0;K<_.length;K++)$.push(`> ${X+K} | ${_[K]}`);else{for(let K=0;K<3;K++)$.push(`> ${X+K} | ${_[K]}`);$.push(`> ... (${_.length} lines)`);for(let K=_.length-3;K<_.length;K++)$.push(`> ${X+K} | ${_[K]}`)}}else{let X=h0(J);if(Q.split(`
85
+ `}function s0(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 C3(J){let $=[];for(let Q of J.values()){if(!Q.required)continue;if(Q.value===null||Q.value===void 0){$.push(Q);continue}if(Q.type==="text"&&!Q.value.trim()){$.push(Q);continue}if(Q.type==="checkbox"&&Q.value.length===0){$.push(Q);continue}}return $}function A3(J){let $=[];for(let Q of J.values())if(Q.required&&!Q.markdown.trim())$.push(Q);return $}function S0(J,$){let Q=C3(J),Z=A3($);return[...Q.map((Y)=>Y.label),...Z.map((Y)=>Y.label||Y.id)]}function R3(J){let $=[];switch($.push(`**${J.label}**`),J.type){case"radio":case"select":$.push(`Answer: ${J.value}`);break;case"checkbox":for(let Q of J.value)$.push(`- [x] ${Q}`);break;case"text":$.push(""),$.push(J.value.trim());break;case"range":$.push(`Answer: ${J.value}`);break}if(J.note?.trim())$.push(""),$.push(`Note: ${J.note.trim()}`);return $.push(""),$.join(`
86
+ `)}function o0(J){let $=[],Q=J.snippet.trim(),Z=J.context,Y=Z?.lineStart!=null;if(J.filePath&&Y){let X=Z.lineStart,q=Z.lineEnd??X,K=Q.split(`
87
+ `);if(Q.length<30&&X===q&&(Z.before||Z.after)){let _=d0(J);$.push(`> L${X}: ${_}`)}else if(K.length<=6)for(let _=0;_<K.length;_++)$.push(`> ${X+_} | ${K[_]}`);else{for(let _=0;_<3;_++)$.push(`> ${X+_} | ${K[_]}`);$.push(`> ... (${K.length} lines)`);for(let _=K.length-3;_<K.length;_++)$.push(`> ${X+_} | ${K[_]}`)}}else{let X=d0(J);if(Q.split(`
88
88
  `).length<=3)$.push(`> ${X.split(`
89
89
  `).join(`
90
90
  > `)}`);else{let q=Q.split(`
91
91
  `);$.push(`> ${q[0]}`),$.push(`> ... (${q.length} lines)`),$.push(`> ${q[q.length-1]}`)}}if(J.note.trim())$.push(""),$.push(J.note.trim());return $.push(""),$.join(`
92
- `)}function w3(J){let $={label:"",annotations:[],children:new Map};for(let Q of J){let Z=Q.context?.hierarchy||[],Y=$;for(let X of Z){if(!Y.children.has(X))Y.children.set(X,{label:X,annotations:[],children:new Map});Y=Y.children.get(X)}Y.annotations.push(Q)}return $}function v5(J,$=0){let Q=[];for(let Z of J.annotations)Q.push(u5(Z));for(let[,Z]of J.children){let Y=$===0?"###":"####";Q.push(`${Y} ${Z.label}`),Q.push(""),Q.push(v5(Z,$+1))}return Q.join(`
93
- `)}import{SessionContext as V3}from"#canvas/runtime";import{useEffect as a0,useState as P0,useRef as R3,useMemo as C3}from"react";import{jsxDEV as s}from"react/jsx-dev-runtime";function E5({open:J,onClose:$,onSubmit:Q}){let{annotations:Z,generalNote:Y,responses:X,feedbackEntries:q}=q1(),[_,z]=P0(""),[K,U]=P0(!1),[H,G]=P0(!1),[N,W]=P0(null),M=R3(null);if(a0(()=>{if(!J){U(!1),G(!1),W(null);return}if(K)return;z(Q0(Z,Y,X,q))},[Z,Y,X,q,K,J]),a0(()=>{if(J&&H&&M.current)M.current.focus()},[J,H]),a0(()=>{if(!J)return;let L=(y)=>{if(y.key==="Escape")$()};return window.addEventListener("keydown",L),()=>window.removeEventListener("keydown",L)},[J,$]),!J)return null;let F=_.trim().length>0;return s("div",{className:"fixed inset-0 z-50 bg-black/50 backdrop-blur-sm flex items-center justify-center p-8",onClick:$,children:s("div",{className:"bg-bg-surface border border-border-medium rounded-xl shadow-lg w-full max-w-2xl flex flex-col",style:{height:"80vh"},onClick:(L)=>L.stopPropagation(),children:[s("div",{className:"flex items-center justify-between px-5 py-3 border-b border-border-subtle flex-shrink-0",children:[s("div",{className:"flex items-center gap-3",children:[s("span",{className:"text-[13px] font-medium text-text-primary font-body",children:"Response preview"},void 0,!1,void 0,this),K&&s("button",{onClick:()=>{U(!1),G(!1)},className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body",children:"Reset"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),s("div",{className:"flex items-center gap-2",children:[s("div",{className:"flex items-center bg-bg-base rounded-md p-0.5",children:[s("button",{onClick:()=>G(!1),className:`px-2.5 py-1 rounded text-[11px] font-body font-medium transition-colors ${!H?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Preview"},void 0,!1,void 0,this),s("button",{onClick:()=>G(!0),className:`px-2.5 py-1 rounded text-[11px] font-body font-medium transition-colors ${H?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Edit"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),s("button",{onClick:$,className:"text-text-tertiary hover:text-text-secondary w-7 h-7 flex items-center justify-center rounded-md hover:bg-border-subtle transition-colors",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),H?s("textarea",{ref:M,value:_,onChange:(L)=>{z(L.target.value),U(!0)},className:"flex-1 w-full bg-bg-base p-5 text-[13px] font-mono text-text-code resize-none focus:outline-none leading-relaxed placeholder:text-text-disabled",placeholder:"Your feedback will appear here..."},void 0,!1,void 0,this):s("div",{className:"flex-1 overflow-y-auto p-5",children:s(S0,{text:_},void 0,!1,void 0,this)},void 0,!1,void 0,this),N&&s("div",{className:"px-5 py-2 text-[12px] text-accent-red font-body border-t border-border-subtle flex-shrink-0 flex items-center justify-between gap-2",children:[s("span",{children:N},void 0,!1,void 0,this),s("button",{onClick:()=>{W(null),Q(_)},className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body whitespace-nowrap underline",children:"Submit anyway"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),s("div",{className:"flex justify-end gap-2 px-5 py-3 border-t border-border-subtle flex-shrink-0",children:[s("button",{onClick:$,className:"px-4 py-2 rounded-lg text-[13px] font-body text-text-tertiary hover:text-text-secondary transition-colors",children:"Cancel"},void 0,!1,void 0,this),s("button",{onClick:()=>{let L=L0(X,q);if(L.length>0){W(`Please answer: ${L.join(", ")}`);return}W(null),Q(_)},disabled:!F,className:`px-6 py-2 rounded-lg font-body text-[13px] font-medium transition-all ${F?"bg-btn-primary text-btn-primary-text hover:opacity-90":"bg-bg-input text-text-disabled cursor-default"}`,children:"Submit feedback"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function S0({text:J}){let $=C3(()=>E.parse(J,{async:!1}),[J]);return s("div",{className:"prose-canvas font-body text-body text-text-primary leading-relaxed",dangerouslySetInnerHTML:{__html:$}},void 0,!1,void 0,this)}import{jsxDEV as j1}from"react/jsx-dev-runtime";var m3={ts:"#3178c6",tsx:"#3178c6",js:"#e8a32e",jsx:"#4ba0c8",html:"#e34c26",css:"#264de4",scss:"#c69",json:"#7a7568",yaml:"#cb171e",yml:"#cb171e",toml:"#9c4221",rs:"#dea584",go:"#00add8",c:"#6a6a6a",cpp:"#f34b7d",h:"#6a6a6a",py:"#3572a5",rb:"#cc342d",sh:"#5a8c3c",bash:"#5a8c3c",md:"#3573b5",txt:"#6b6560",lock:"#6b6560",gitignore:"#6b6560",svg:"#d9952e",png:"#6a9c2e",jpg:"#6a9c2e",gif:"#6a9c2e"},j3={ts:"TS",tsx:"TX",js:"JS",jsx:"JX",py:"PY",rs:"RS",go:"GO",rb:"RB",json:"{}",yaml:"YM",yml:"YM",toml:"TM",html:"<>",css:"#",scss:"#",md:"M↓",sh:"$",bash:"$",c:"C",cpp:"C+",h:"H",svg:"◇",png:"▣",jpg:"▣"};function E1({name:J,type:$,expanded:Q,className:Z=""}){if($==="dir")return j1("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",className:`flex-shrink-0 ${Z}`,children:Q?j1("path",{d:"M1.5 3.5h5l1.5 1.5h6.5v8h-13z",style:{fill:"var(--color-folder-fill-active)",stroke:"var(--color-folder-stroke-active)"},strokeWidth:"1"},void 0,!1,void 0,this):j1("path",{d:"M1.5 3.5h5l1.5 1.5h6.5v8h-13z",style:{fill:"var(--color-folder-fill)",stroke:"var(--color-folder-stroke)"},strokeWidth:"1"},void 0,!1,void 0,this)},void 0,!1,void 0,this);let Y=J.includes(".")?J.split(".").pop().toLowerCase():"",X=m3[Y]||"#6b6560",q=j3[Y];return j1("svg",{width:"14",height:"14",viewBox:"0 0 16 16",className:`flex-shrink-0 ${Z}`,children:[j1("path",{d:"M2 1.5h8l3.5 3.5v9.5a1 1 0 01-1 1H3a1 1 0 01-1-1v-12a1 1 0 011-1z",fill:X,opacity:"0.85"},void 0,!1,void 0,this),j1("path",{d:"M10 1.5v2.5a1 1 0 001 1h2.5",fill:"none",stroke:"white",strokeWidth:"0.5",opacity:"0.5"},void 0,!1,void 0,this),q&&j1("text",{x:"8",y:"11.5",textAnchor:"middle",fill:"white",fontSize:"5.5",fontFamily:"monospace",fontWeight:"600",children:q},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{jsxDEV as P,Fragment as v3}from"react/jsx-dev-runtime";function s0({onPreview:J,onSubmit:$,collapseButton:Q}){let{isReadOnly:Z,selectedRevision:Y,currentRevision:X,revisions:q}=i0(h1),_=i0(V3),z=Z&&Y===X,U=q.find((H)=>H.revision===Y)?.label||`Round ${Y}`;if(Z)return P(D3,{sessionId:_,revision:Y,label:U,waitingForUpdate:z,collapseButton:Q},void 0,!1,void 0,this);return P(u3,{onPreview:J,onSubmit:$,collapseButton:Q},void 0,!1,void 0,this)}function g3({sessionId:J,revision:$,label:Q,waitingForUpdate:Z,collapseButton:Y}){let[X,q]=x1(null),[_,z]=x1(!0);return o0(()=>{z(!0),fetch(`/api/session/${J}/revision/${$}/feedback`).then((K)=>K.json()).then((K)=>{q(K.feedback||null),z(!1)}).catch(()=>{q(null),z(!1)})},[J,$]),P("div",{className:"flex flex-col h-full",children:[P("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[P("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:Z?"Feedback sent":`Feedback — ${Q}`},void 0,!1,void 0,this),Y]},void 0,!0,void 0,this),Z&&P("div",{className:"mx-4 mb-3 px-3 py-2.5 rounded-lg bg-accent-green-muted flex items-center gap-2 flex-shrink-0",children:[P("span",{className:"w-2 h-2 rounded-full bg-accent-green animate-pulse"},void 0,!1,void 0,this),P("span",{className:"text-[12px] font-body text-accent-green",children:"Waiting for next revision..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),P("div",{className:"flex-1 overflow-y-auto px-4",children:_?P("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"Loading..."},void 0,!1,void 0,this):X?P(S0,{text:X},void 0,!1,void 0,this):P("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"No feedback was submitted for this revision."},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function D3({sessionId:J,revision:$,label:Q,waitingForUpdate:Z,collapseButton:Y}){let{annotations:X,generalNote:q,activeAnnotationId:_,setActiveAnnotationId:z}=q1(),{setActiveView:K}=i0(I1),U=X.length>0||q.trim().length>0,[H,G]=x1("feedback");if(!U)return P(g3,{sessionId:J,revision:$,label:Q,waitingForUpdate:Z,collapseButton:Y},void 0,!1,void 0,this);return P("div",{className:"flex flex-col h-full",children:[P("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[P("div",{className:"flex items-center gap-1 bg-bg-input rounded-md p-0.5",children:[P("button",{onClick:()=>G("feedback"),className:`px-2.5 py-1 rounded text-[11px] font-medium font-body transition-colors ${H==="feedback"?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Feedback"},void 0,!1,void 0,this),P("button",{onClick:()=>G("annotations"),className:`px-2.5 py-1 rounded text-[11px] font-medium font-body transition-colors flex items-center gap-1.5 ${H==="annotations"?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:["Annotations",P("span",{className:"inline-flex items-center justify-center min-w-[16px] h-[16px] px-1 rounded-full bg-border-subtle text-[10px] font-medium",children:X.length},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Y]},void 0,!0,void 0,this),Z&&P("div",{className:"mx-4 mb-3 px-3 py-2.5 rounded-lg bg-accent-green-muted flex items-center gap-2 flex-shrink-0",children:[P("span",{className:"w-2 h-2 rounded-full bg-accent-green animate-pulse"},void 0,!1,void 0,this),P("span",{className:"text-[12px] font-body text-accent-green",children:"Waiting for next revision..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),H==="feedback"?P(f3,{sessionId:J,revision:$},void 0,!1,void 0,this):P(k3,{annotations:X,generalNote:q,activeAnnotationId:_,setActiveAnnotationId:z,setActiveView:K},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function f3({sessionId:J,revision:$}){let[Q,Z]=x1(null),[Y,X]=x1(!0);return o0(()=>{X(!0),fetch(`/api/session/${J}/revision/${$}/feedback`).then((q)=>q.json()).then((q)=>{Z(q.feedback||null),X(!1)}).catch(()=>{Z(null),X(!1)})},[J,$]),P("div",{className:"flex-1 overflow-y-auto px-4",children:Y?P("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"Loading..."},void 0,!1,void 0,this):Q?P(S0,{text:Q},void 0,!1,void 0,this):P("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"No feedback was submitted for this revision."},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function k3({annotations:J,generalNote:$,activeAnnotationId:Q,setActiveAnnotationId:Z,setActiveView:Y}){let X=J.filter((G)=>!G.filePath),q=J.filter((G)=>G.filePath),_={};for(let G of q){let N=G.filePath;if(!_[N])_[N]=[];_[N].push(G)}let z=(G)=>{Z(G),C1(G,!0);let N=document.querySelector(`[data-annotation-id="${G}"]`);if(N)N.scrollIntoView({behavior:"smooth",block:"nearest"})},K=(G)=>{Z(null),C1(G,!1)},U=(G)=>{if(G.id===Q)Z(null);else if(Z(G.id),G.filePath)Y({type:"file",path:G.filePath}),setTimeout(()=>{let N=document.querySelector(`[data-annotation-id="${G.id}"]`);if(N)N.scrollIntoView({behavior:"smooth",block:"center"})},150)},H=(G)=>P("div",{className:`relative px-3 py-2.5 transition-colors duration-150 cursor-pointer ${Q===G.id?"bg-highlight-selected":"odd:bg-bg-elevated-half hover:bg-bg-input"}`,onMouseEnter:()=>z(G.id),onMouseLeave:()=>K(G.id),onClick:()=>U(G),children:[P("div",{className:"text-[11px] text-text-tertiary italic line-clamp-2 mb-1.5 leading-snug font-body border-l-2 border-border-medium pl-2",children:G.snippet.length>80?G.snippet.slice(0,80)+"...":G.snippet},void 0,!1,void 0,this),G.note.trim()&&P("div",{className:"text-[13px] font-body text-text-primary leading-relaxed",children:G.note},void 0,!1,void 0,this)]},G.id,!0,void 0,this);return P(v3,{children:[P("div",{className:"flex-1 overflow-y-auto",children:[X.length>0&&q.length>0&&P("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body px-3 mb-1 mt-1",children:"Plan"},void 0,!1,void 0,this),X.map(H),Object.entries(_).map(([G,N])=>P("div",{children:[P("button",{onClick:()=>Y({type:"file",path:G}),className:"flex items-center gap-1.5 text-[10px] uppercase tracking-widest text-text-tertiary hover:text-text-secondary font-body px-3 pt-3 pb-1 truncate transition-colors w-full text-left",title:G,children:[P(E1,{name:G.split("/").pop()||G,type:"file"},void 0,!1,void 0,this),P("span",{className:"truncate",children:G},void 0,!1,void 0,this)]},void 0,!0,void 0,this),N.map(H)]},G,!0,void 0,this))]},void 0,!0,void 0,this),$.trim()&&P("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:P("div",{className:"text-[13px] font-body text-text-primary leading-relaxed",children:$},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function u3({onPreview:J,onSubmit:$,collapseButton:Q}){let{annotations:Z,updateAnnotation:Y,removeAnnotation:X,generalNote:q,setGeneralNote:_,activeAnnotationId:z,setActiveAnnotationId:K,responses:U,feedbackEntries:H}=q1(),{setActiveView:G}=I3.useContext(I1),N=x5(null),W=x5(new Map),M=Z.filter((T)=>!T.filePath),F=Z.filter((T)=>T.filePath),L={};for(let T of F){let B=T.filePath;if(!L[B])L[B]=[];L[B].push(T)}o0(()=>{if(!z)return;let T=W.current.get(z);if(T)T.scrollIntoView({behavior:"smooth",block:"nearest"})},[z]);let y=h5((T)=>{K(T),C1(T,!0);let B=document.querySelector(`[data-annotation-id="${T}"]`);if(B)B.scrollIntoView({behavior:"smooth",block:"nearest"})},[K]),S=h5((T)=>{K(null),C1(T,!1)},[z]),R=Array.from(U.values()).some(l0),m=H.size>0,k=Z.length>0||q.trim().length>0||R||m,[V,w]=x1(null),I=(T)=>P("div",{ref:(B)=>{if(B)W.current.set(T.id,B);else W.current.delete(T.id)},className:`group/ann relative px-3 py-2.5 transition-colors duration-150 ${z===T.id?"bg-highlight-selected":"odd:bg-bg-elevated-half hover:bg-bg-input"}`,onMouseEnter:()=>y(T.id),onMouseLeave:()=>S(T.id),onClick:()=>{if(T.id===z)K(null);else if(K(T.id),T.filePath)G({type:"file",path:T.filePath}),setTimeout(()=>{let B=document.querySelector(`[data-annotation-id="${T.id}"]`);if(B)B.scrollIntoView({behavior:"smooth",block:"center"})},150)},children:[P("div",{className:"text-[11px] text-text-tertiary italic line-clamp-2 mb-1.5 leading-snug font-body border-l-2 border-border-medium pl-2",children:T.snippet.length>80?T.snippet.slice(0,80)+"...":T.snippet},void 0,!1,void 0,this),P("textarea",{value:T.note,onChange:(B)=>Y(T.id,B.target.value),onClick:(B)=>B.stopPropagation(),className:"w-full bg-transparent text-[13px] font-body text-text-primary resize-none focus:outline-none leading-relaxed p-0 border-none min-h-[20px]",rows:1,style:{height:"auto",overflow:"hidden"},onInput:(B)=>t1(B.target),ref:(B)=>{if(B)t1(B)}},void 0,!1,void 0,this),P("div",{className:"absolute top-1.5 right-1.5 opacity-0 group-hover/ann:opacity-100 transition-opacity duration-100",children:P("button",{onClick:(B)=>{B.stopPropagation(),X(T.id)},className:"w-5 h-5 flex items-center justify-center rounded text-text-tertiary hover:text-accent-red hover:bg-accent-red-muted transition-colors",title:"Delete annotation",children:P("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[P("polyline",{points:"3 6 5 6 21 6"},void 0,!1,void 0,this),P("path",{d:"M19 6v14a2 2 0 01-2 2H7a2 2 0 01-2-2V6m3 0V4a2 2 0 012-2h4a2 2 0 012 2v2"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},T.id,!0,void 0,this);return P("div",{className:"flex flex-col h-full",children:[P("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[P("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body flex items-center gap-2",children:["Annotations",Z.length>0&&P("span",{className:"inline-flex items-center justify-center min-w-[18px] h-[18px] px-1 rounded-full bg-border-subtle text-[10px] font-medium text-text-secondary",children:Z.length},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Q]},void 0,!0,void 0,this),P("div",{ref:N,className:"flex-1 overflow-y-auto",children:[Z.length===0&&P("p",{className:"text-[12px] text-text-tertiary px-3 py-4 leading-relaxed font-body",children:"Select text in the plan or in files to add annotations."},void 0,!1,void 0,this),M.length>0&&F.length>0&&P("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body px-3 mb-1 mt-1",children:"Plan"},void 0,!1,void 0,this),M.map(I),Object.entries(L).map(([T,B])=>P("div",{children:[P("button",{onClick:()=>G({type:"file",path:T}),className:"flex items-center gap-1.5 text-[10px] uppercase tracking-widest text-text-tertiary hover:text-text-secondary font-body px-3 pt-3 pb-1 truncate transition-colors w-full text-left",title:T,children:[P(E1,{name:T.split("/").pop()||T,type:"file"},void 0,!1,void 0,this),P("span",{className:"truncate",children:T},void 0,!1,void 0,this)]},void 0,!0,void 0,this),B.map(I)]},T,!0,void 0,this))]},void 0,!0,void 0,this),P("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:P("textarea",{value:q,onChange:(T)=>_(T.target.value),className:"w-full bg-transparent text-[13px] font-body text-text-primary resize-none leading-relaxed p-0 border-none ring-0 shadow-none outline-none focus:outline-none focus:ring-0 focus:border-none placeholder:text-text-disabled min-h-[40px]",placeholder:"General notes...",onInput:(T)=>t1(T.target,40),ref:(T)=>{if(T)t1(T,40)}},void 0,!1,void 0,this)},void 0,!1,void 0,this),V&&P("div",{className:"px-4 py-2 text-[12px] text-accent-red font-body border-t border-border-subtle flex-shrink-0 flex items-center justify-between gap-2",children:[P("span",{children:V},void 0,!1,void 0,this),P("button",{onClick:()=>{w(null);let T=Q0(Z,q,U,H);$(T)},className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body whitespace-nowrap underline",children:"Submit anyway"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),P("div",{className:"px-4 py-3 border-t border-border-subtle flex-shrink-0",children:k?P("div",{className:"flex gap-2",children:[P("button",{onClick:J,className:"flex-1 py-2 rounded-lg font-body text-[13px] font-medium transition-all bg-border-subtle text-text-secondary hover:bg-border-medium hover:text-text-primary",children:"Preview"},void 0,!1,void 0,this),P("button",{onClick:()=>{let T=L0(U,H);if(T.length>0){w(`Please answer: ${T.join(", ")}`);return}w(null);let B=Q0(Z,q,U,H);$(B)},className:"flex-1 py-2 rounded-lg font-body text-[13px] font-medium transition-all bg-btn-primary text-btn-primary-text hover:opacity-90 hover:-translate-y-px shadow-sm",children:"Submit"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):P("button",{onClick:()=>$("No feedback — looks good."),className:"w-full py-2 rounded-lg font-body text-[13px] font-medium border border-border-medium text-text-secondary hover:text-text-primary hover:border-border-hover hover:bg-bg-input transition-all",children:"Submit without feedback"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{useEffect as E3,useState as p5,useContext as c5,useMemo as x3}from"react";import{SessionContext as h3}from"#canvas/runtime";import{jsxDEV as f,Fragment as t0}from"react/jsx-dev-runtime";function d5({embedded:J}={}){let $=c5(h3),{annotations:Q,addAnnotation:Z}=q1(),{setActiveView:Y}=c5(I1),[X,q]=p5(!1),[_,z]=p5({}),{annCountMap:K,annotatedFiles:U}=x3(()=>{let y=new Map;for(let S of Q)if(S.filePath)y.set(S.filePath,(y.get(S.filePath)||0)+1);return{annCountMap:y,annotatedFiles:[...y.keys()]}},[Q]),H=async(y)=>{let R=await(await fetch(`/api/tree?session=${$}&path=${encodeURIComponent(y)}`)).json();if(R.entries)z((m)=>({...m,[y]:{entries:R.entries,expanded:!0,loaded:!0}}))};E3(()=>{if(!X&&!_[""])H("")},[X]);let G=(y)=>{if(_[y]?.loaded)z((S)=>({...S,[y]:{...S[y],expanded:!S[y].expanded}}));else H(y)},N=(y)=>{Y({type:"file",path:y})},W=async(y)=>{let R=await(await fetch(`/api/file?session=${$}&path=${encodeURIComponent(y)}`)).json();if(!R.error){let m=R.content.split(`
92
+ `)}function j3(J){let $={label:"",annotations:[],children:new Map};for(let Q of J){let Z=Q.context?.hierarchy||[],Y=$;for(let X of Z){if(!Y.children.has(X))Y.children.set(X,{label:X,annotations:[],children:new Map});Y=Y.children.get(X)}Y.annotations.push(Q)}return $}function x5(J,$=0){let Q=[];for(let Z of J.annotations)Q.push(o0(Z));for(let[,Z]of J.children){let Y=$===0?"###":"####";Q.push(`${Y} ${Z.label}`),Q.push(""),Q.push(x5(Z,$+1))}return Q.join(`
93
+ `)}import{SessionContext as f3}from"#canvas/runtime";import{useEffect as t0,useState as b0,useRef as m3,useMemo as I3}from"react";import{jsxDEV as s}from"react/jsx-dev-runtime";function h5({open:J,onClose:$,onSubmit:Q}){let{annotations:Z,generalNote:Y,responses:X,feedbackEntries:q}=q1(),[K,z]=b0(""),[_,U]=b0(!1),[G,H]=b0(!1),[F,W]=b0(null),B=m3(null);if(t0(()=>{if(!J){U(!1),H(!1),W(null);return}if(_)return;z(_0(Z,Y,X,q))},[Z,Y,X,q,_,J]),t0(()=>{if(J&&G&&B.current)B.current.focus()},[J,G]),t0(()=>{if(!J)return;let M=(y)=>{if(y.key==="Escape")$()};return window.addEventListener("keydown",M),()=>window.removeEventListener("keydown",M)},[J,$]),!J)return null;let T=K.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:(M)=>M.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),_&&s("button",{onClick:()=>{U(!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 ${!G?"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 ${G?"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),G?s("textarea",{ref:B,value:K,onChange:(M)=>{z(M.target.value),U(!0)},className:"flex-1 w-full bg-bg-base p-5 text-[13px] font-mono text-text-code resize-none focus:outline-none leading-relaxed placeholder:text-text-disabled",placeholder:"Your feedback will appear here..."},void 0,!1,void 0,this):s("div",{className:"flex-1 overflow-y-auto p-5",children:s(w0,{text:K},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),Q(K)},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 M=S0(X,q);if(M.length>0){W(`Please answer: ${M.join(", ")}`);return}W(null),Q(K)},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)}function w0({text:J}){let $=I3(()=>x.parse(J,{async:!1}),[J]);return s("div",{className:"prose-canvas font-body text-body text-text-primary leading-relaxed",dangerouslySetInnerHTML:{__html:$}},void 0,!1,void 0,this)}import{jsxDEV as k1}from"react/jsx-dev-runtime";var V3={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"},g3={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 i1({name:J,type:$,expanded:Q,className:Z=""}){if($==="dir")return k1("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",className:`flex-shrink-0 ${Z}`,children:Q?k1("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):k1("path",{d:"M1.5 3.5h5l1.5 1.5h6.5v8h-13z",style:{fill:"var(--color-folder-fill)",stroke:"var(--color-folder-stroke)"},strokeWidth:"1"},void 0,!1,void 0,this)},void 0,!1,void 0,this);let Y=J.includes(".")?J.split(".").pop().toLowerCase():"",X=V3[Y]||"#6b6560",q=g3[Y];return k1("svg",{width:"14",height:"14",viewBox:"0 0 16 16",className:`flex-shrink-0 ${Z}`,children:[k1("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),k1("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&&k1("text",{x:"8",y:"11.5",textAnchor:"middle",fill:"white",fontSize:"5.5",fontFamily:"monospace",fontWeight:"600",children:q},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{jsxDEV as S,Fragment as C0}from"react/jsx-dev-runtime";function $5({onPreview:J,onSubmit:$,collapseButton:Q}){let{isReadOnly:Z,selectedRevision:Y,currentRevision:X,revisions:q}=n0(s1),K=n0(f3),z=Z&&Y===X,U=q.find((G)=>G.revision===Y)?.label||`Round ${Y}`;if(Z)return S(u3,{sessionId:K,revision:Y,label:U,waitingForUpdate:z,collapseButton:Q},void 0,!1,void 0,this);return S(x3,{onPreview:J,onSubmit:$,collapseButton:Q},void 0,!1,void 0,this)}function k3({sessionId:J,revision:$,label:Q,waitingForUpdate:Z,collapseButton:Y}){let[X,q]=o1(null),[K,z]=o1(!0);return e0(()=>{z(!0),fetch(`/api/session/${J}/revision/${$}/feedback`).then((_)=>_.json()).then((_)=>{q(_.feedback||null),z(!1)}).catch(()=>{q(null),z(!1)})},[J,$]),S("div",{className:"flex flex-col h-full",children:[S("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[S("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:Z?"Feedback sent":`Feedback — ${Q}`},void 0,!1,void 0,this),Y]},void 0,!0,void 0,this),Z&&S("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:[S("span",{className:"w-2 h-2 rounded-full bg-accent-green animate-pulse"},void 0,!1,void 0,this),S("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),S("div",{className:"flex-1 overflow-y-auto px-4",children:K?S("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"Loading..."},void 0,!1,void 0,this):X?S(w0,{text:X},void 0,!1,void 0,this):S("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 u3({sessionId:J,revision:$,label:Q,waitingForUpdate:Z,collapseButton:Y}){let{annotations:X,generalNote:q,activeAnnotationId:K,setActiveAnnotationId:z}=q1(),{setActiveView:_}=n0(u1),U=X.length>0||q.trim().length>0,[G,H]=o1("feedback");if(!U)return S(k3,{sessionId:J,revision:$,label:Q,waitingForUpdate:Z,collapseButton:Y},void 0,!1,void 0,this);return S("div",{className:"flex flex-col h-full",children:[S("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[S("div",{className:"flex items-center gap-1 bg-bg-input rounded-md p-0.5",children:[S("button",{onClick:()=>H("feedback"),className:`px-2.5 py-1 rounded text-[11px] font-medium font-body transition-colors ${G==="feedback"?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Feedback"},void 0,!1,void 0,this),S("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 ${G==="annotations"?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:["Annotations",S("span",{className:"inline-flex items-center justify-center min-w-[16px] h-[16px] px-1 rounded-full bg-border-subtle text-[10px] font-medium",children:X.length},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Y]},void 0,!0,void 0,this),Z&&S("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:[S("span",{className:"w-2 h-2 rounded-full bg-accent-green animate-pulse"},void 0,!1,void 0,this),S("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),G==="feedback"?S(v3,{sessionId:J,revision:$},void 0,!1,void 0,this):S(E3,{annotations:X,generalNote:q,activeAnnotationId:K,setActiveAnnotationId:z,setActiveView:_},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function v3({sessionId:J,revision:$}){let[Q,Z]=o1(null),[Y,X]=o1(!0);return e0(()=>{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,$]),S("div",{className:"flex-1 overflow-y-auto px-4",children:Y?S("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"Loading..."},void 0,!1,void 0,this):Q?S(w0,{text:Q},void 0,!1,void 0,this):S("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 E3({annotations:J,generalNote:$,activeAnnotationId:Q,setActiveAnnotationId:Z,setActiveView:Y}){let X=J.filter((W)=>W.filePath===U1),q=J.filter((W)=>!W.filePath),K=J.filter((W)=>W.filePath&&W.filePath!==U1),z={};for(let W of K){let B=W.filePath;if(!z[B])z[B]=[];z[B].push(W)}let _=(W)=>{Z(W),V1(W,!0);let B=document.querySelector(`[data-annotation-id="${W}"]`);if(B)B.scrollIntoView({behavior:"smooth",block:"nearest"})},U=(W)=>{Z(null),V1(W,!1)},G=(W)=>{if(W.id===Q)Z(null);else if(Z(W.id),W.filePath)Y({type:"file",path:W.filePath}),setTimeout(()=>{let B=document.querySelector(`[data-annotation-id="${W.id}"]`);if(B)B.scrollIntoView({behavior:"smooth",block:"center"})},150)},H=(W)=>S("div",{className:`relative px-3 py-2.5 transition-colors duration-150 cursor-pointer ${Q===W.id?"bg-highlight-selected":"odd:bg-bg-elevated-half hover:bg-bg-input"}`,onMouseEnter:()=>_(W.id),onMouseLeave:()=>U(W.id),onClick:()=>G(W),children:[S("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()&&S("div",{className:"text-[13px] font-body text-text-primary leading-relaxed",children:W.note},void 0,!1,void 0,this)]},W.id,!0,void 0,this),F=[X,q,K].filter((W)=>W.length>0).length>1;return S(C0,{children:[S("div",{className:"flex-1 overflow-y-auto",children:[X.length>0&&S(C0,{children:[F&&S("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&&S(C0,{children:[F&&S("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,B])=>S("div",{children:[S("button",{onClick:()=>Y({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:[S(i1,{name:W.split("/").pop()||W,type:"file"},void 0,!1,void 0,this),S("span",{className:"truncate",children:W},void 0,!1,void 0,this)]},void 0,!0,void 0,this),B.map(H)]},W,!0,void 0,this))]},void 0,!0,void 0,this),$.trim()&&S("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:S("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 x3({onPreview:J,onSubmit:$,collapseButton:Q}){let{annotations:Z,updateAnnotation:Y,removeAnnotation:X,generalNote:q,setGeneralNote:K,activeAnnotationId:z,setActiveAnnotationId:_,responses:U,feedbackEntries:G}=q1(),{setActiveView:H}=D3.useContext(u1),F=p5(null),W=p5(new Map),B=Z.filter((O)=>O.filePath===U1),T=Z.filter((O)=>!O.filePath),M=Z.filter((O)=>O.filePath&&O.filePath!==U1),y={};for(let O of M){let j=O.filePath;if(!y[j])y[j]=[];y[j].push(O)}e0(()=>{if(!z)return;let O=W.current.get(z);if(O)O.scrollIntoView({behavior:"smooth",block:"nearest"})},[z]);let L=c5((O)=>{_(O),V1(O,!0);let j=document.querySelector(`[data-annotation-id="${O}"]`);if(j)j.scrollIntoView({behavior:"smooth",block:"nearest"})},[_]),C=c5((O)=>{_(null),V1(O,!1)},[z]),R=Array.from(U.values()).some(s0),D=G.size>0,V=Z.length>0||q.trim().length>0||R||D,[b,I]=o1(null),P=(O)=>S("div",{ref:(j)=>{if(j)W.current.set(O.id,j);else W.current.delete(O.id)},className:`group/ann relative px-3 py-2.5 transition-colors duration-150 ${z===O.id?"bg-highlight-selected":"odd:bg-bg-elevated-half hover:bg-bg-input"}`,onMouseEnter:()=>L(O.id),onMouseLeave:()=>C(O.id),onClick:()=>{if(O.id===z)_(null);else if(_(O.id),O.filePath)H({type:"file",path:O.filePath}),setTimeout(()=>{let j=document.querySelector(`[data-annotation-id="${O.id}"]`);if(j)j.scrollIntoView({behavior:"smooth",block:"center"})},150)},children:[S("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:O.snippet.length>80?O.snippet.slice(0,80)+"...":O.snippet},void 0,!1,void 0,this),S("textarea",{value:O.note,onChange:(j)=>Y(O.id,j.target.value),onClick:(j)=>j.stopPropagation(),className:"w-full bg-transparent text-[13px] font-body text-text-primary resize-none focus:outline-none leading-relaxed p-0 border-none min-h-[20px]",rows:1,style:{height:"auto",overflow:"hidden"},onInput:(j)=>q0(j.target),ref:(j)=>{if(j)q0(j)}},void 0,!1,void 0,this),S("div",{className:"absolute top-1.5 right-1.5 opacity-0 group-hover/ann:opacity-100 transition-opacity duration-100",children:S("button",{onClick:(j)=>{j.stopPropagation(),X(O.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:S("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[S("polyline",{points:"3 6 5 6 21 6"},void 0,!1,void 0,this),S("path",{d:"M19 6v14a2 2 0 01-2 2H7a2 2 0 01-2-2V6m3 0V4a2 2 0 012-2h4a2 2 0 012 2v2"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},O.id,!0,void 0,this);return S("div",{className:"flex flex-col h-full",children:[S("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[S("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body flex items-center gap-2",children:["Annotations",Z.length>0&&S("span",{className:"inline-flex items-center justify-center min-w-[18px] h-[18px] px-1 rounded-full bg-border-subtle text-[10px] font-medium text-text-secondary",children:Z.length},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Q]},void 0,!0,void 0,this),S("div",{ref:F,className:"flex-1 overflow-y-auto",children:[Z.length===0&&S("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),B.length>0&&S(C0,{children:[(T.length>0||M.length>0)&&S("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),B.map(P)]},void 0,!0,void 0,this),T.length>0&&(B.length>0||M.length>0)&&S("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),T.map(P),Object.entries(y).map(([O,j])=>S("div",{children:[S("button",{onClick:()=>H({type:"file",path:O}),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:O,children:[S(i1,{name:O.split("/").pop()||O,type:"file"},void 0,!1,void 0,this),S("span",{className:"truncate",children:O},void 0,!1,void 0,this)]},void 0,!0,void 0,this),j.map(P)]},O,!0,void 0,this))]},void 0,!0,void 0,this),S("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:S("textarea",{value:q,onChange:(O)=>K(O.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:(O)=>q0(O.target,40),ref:(O)=>{if(O)q0(O,40)}},void 0,!1,void 0,this)},void 0,!1,void 0,this),b&&S("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:[S("span",{children:b},void 0,!1,void 0,this),S("button",{onClick:()=>{I(null);let O=_0(Z,q,U,G);$(O)},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:"px-4 py-3 border-t border-border-subtle flex-shrink-0",children:V?S("div",{className:"flex gap-2",children:[S("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),S("button",{onClick:()=>{let O=S0(U,G);if(O.length>0){I(`Please answer: ${O.join(", ")}`);return}I(null);let j=_0(Z,q,U,G);$(j)},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):S("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 h3,useState as d5,useContext as r5,useMemo as p3}from"react";import{SessionContext as c3}from"#canvas/runtime";import{jsxDEV as u,Fragment as J5}from"react/jsx-dev-runtime";function l5({embedded:J}={}){let $=r5(c3),{annotations:Q,addAnnotation:Z}=q1(),{setActiveView:Y}=r5(u1),[X,q]=d5(!1),[K,z]=d5({}),{annCountMap:_,annotatedFiles:U}=p3(()=>{let y=new Map;for(let L of Q)if(L.filePath)y.set(L.filePath,(y.get(L.filePath)||0)+1);return{annCountMap:y,annotatedFiles:[...y.keys()]}},[Q]),G=async(y)=>{let C=await(await fetch(`/api/tree?session=${$}&path=${encodeURIComponent(y)}`)).json();if(C.entries)z((R)=>({...R,[y]:{entries:C.entries,expanded:!0,loaded:!0}}))};h3(()=>{if(!X&&!K[""])G("")},[X]);let H=(y)=>{if(K[y]?.loaded)z((L)=>({...L,[y]:{...L[y],expanded:!L[y].expanded}}));else G(y)},F=(y)=>{Y({type:"file",path:y})},W=async(y)=>{let C=await(await fetch(`/api/file?session=${$}&path=${encodeURIComponent(y)}`)).json();if(!C.error){let R=C.content.split(`
94
94
  `).slice(0,3).join(`
95
- `)+(R.content.split(`
95
+ `)+(C.content.split(`
96
96
  `).length>3?`
97
- ...`:"");Z(m,"Include this file for context",y)}},M=async(y)=>{let S=[];if(_[y]?.loaded)S=_[y].entries;else{let m=await(await fetch(`/api/tree?session=${$}&path=${encodeURIComponent(y)}`)).json();if(m.entries)S=m.entries}await Promise.all(S.filter((R)=>R.type==="file").map((R)=>W(y?`${y}/${R.name}`:R.name)))},F=(y)=>K.get(y)||0,L=(y,S=0)=>{let R=_[y];if(!R?.expanded)return null;return R.entries.map((m)=>{let k=y?`${y}/${m.name}`:m.name,V=F(k);return f("div",{children:[f("div",{className:"group/item flex items-center py-[3px] hover:bg-bg-elevated text-[13px] font-body cursor-default transition-colors duration-100",style:{paddingLeft:`${16+S*16}px`,paddingRight:"8px"},children:m.type==="dir"?f(t0,{children:[f("span",{onClick:()=>G(k),className:"flex items-center gap-1.5 flex-1 text-text-secondary hover:text-text-primary cursor-pointer truncate",children:[f(E1,{name:m.name,type:"dir",expanded:_[k]?.expanded},void 0,!1,void 0,this),f("span",{className:"truncate",children:m.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this),f("button",{onClick:(w)=>{w.stopPropagation(),M(k)},className:"text-[11px] text-text-tertiary hover:text-text-secondary opacity-0 group-hover/item:opacity-100 transition-opacity px-1 flex-shrink-0",title:"Add all files in folder",children:"+"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):f(t0,{children:[f("span",{onClick:()=>N(k),className:`flex-1 truncate cursor-pointer flex items-center gap-1.5 ${V>0?"text-text-primary":"text-text-secondary hover:text-text-primary"}`,children:[f(E1,{name:m.name,type:"file"},void 0,!1,void 0,this),f("span",{className:"truncate",children:m.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this),f("div",{className:"flex items-center gap-1 flex-shrink-0 ml-1",children:[V>0&&f("span",{className:"text-[10px] font-medium bg-badge-bg text-accent-amber px-1.5 py-px rounded-full min-w-[18px] text-center",children:V},void 0,!1,void 0,this),f("button",{onClick:(w)=>{w.stopPropagation(),W(k)},className:"text-[11px] text-text-tertiary hover:text-text-secondary opacity-0 group-hover/item:opacity-100 transition-opacity px-1",title:"Add file to context",children:"+"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),m.type==="dir"&&L(k,S+1)]},k,!0,void 0,this)})};if(J)return f(t0,{children:[f("div",{className:"flex items-center justify-between px-4 pt-3 pb-2 flex-shrink-0",children:f("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:"Files"},void 0,!1,void 0,this)},void 0,!1,void 0,this),f("div",{className:"flex-1 overflow-y-auto",children:L("")},void 0,!1,void 0,this),U.length>0&&f("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:[f("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body mb-1.5",children:"Referenced"},void 0,!1,void 0,this),U.map((y)=>f("div",{onClick:()=>N(y),className:"flex items-center justify-between text-[12px] font-body text-text-secondary hover:text-text-primary cursor-pointer py-0.5",children:[f("span",{className:"truncate",children:y.split("/").pop()},void 0,!1,void 0,this),f("span",{className:"text-[10px] font-medium bg-badge-bg text-accent-amber px-1.5 py-px rounded-full min-w-[18px] text-center flex-shrink-0 ml-1",children:F(y)},void 0,!1,void 0,this)]},y,!0,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);if(X)return f("div",{className:"hidden lg:flex w-8 border-r border-border-subtle bg-bg-surface flex-col items-center flex-shrink-0",children:f("button",{onClick:()=>q(!1),className:"mt-3 p-1 text-text-tertiary hover:text-text-secondary transition-colors",children:f("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:f("path",{d:"M5 3l4 4-4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this);return f("div",{className:"hidden lg:flex w-60 border-r border-border-subtle bg-bg-surface flex-col flex-shrink-0 overflow-hidden",children:[f("div",{className:"flex items-center justify-between px-4 pt-4 pb-3 flex-shrink-0",children:[f("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:"Files"},void 0,!1,void 0,this),f("button",{onClick:()=>q(!0),className:"text-text-tertiary hover:text-text-secondary transition-colors p-0.5",children:f("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:f("path",{d:"M9 3l-4 4 4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),f("div",{className:"flex-1 overflow-y-auto",children:L("")},void 0,!1,void 0,this),U.length>0&&f("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:[f("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body mb-1.5",children:"Referenced"},void 0,!1,void 0,this),U.map((y)=>f("div",{onClick:()=>N(y),className:"flex items-center justify-between text-[12px] font-body text-text-secondary hover:text-text-primary cursor-pointer py-0.5",children:[f("span",{className:"truncate",children:y.split("/").pop()},void 0,!1,void 0,this),f("span",{className:"text-[10px] font-medium bg-badge-bg text-accent-amber px-1.5 py-px rounded-full min-w-[18px] text-center flex-shrink-0 ml-1",children:F(y)},void 0,!1,void 0,this)]},y,!0,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}import{useEffect as p1,useState as T1,useContext as p3,useCallback as r5,useRef as M1,useMemo as l5}from"react";import{SessionContext as c3}from"#canvas/runtime";var b0={ts:"typescript",tsx:"typescript",js:"javascript",jsx:"javascript",py:"python",rs:"rust",go:"go",rb:"ruby",java:"java",json:"json",yaml:"yaml",yml:"yaml",md:"markdown",css:"css",html:"html",sh:"bash",bash:"bash",toml:"toml",sql:"sql",xml:"xml",c:"c",cpp:"cpp",h:"c"};import{jsxDEV as N1}from"react/jsx-dev-runtime";function a5(J){let $=J instanceof HTMLElement?J:J.parentElement;while($){if($.hasAttribute("data-line-num"))return $;$=$.parentElement}return null}function i5({path:J}){let $=p3(c3),{annotations:Q,addAnnotationWithId:Z,removeAnnotation:Y,updateAnnotation:X,activeAnnotationId:q,setActiveAnnotationId:_}=q1(),[z,K]=T1(null),[U,H]=T1("text"),[G,N]=T1(!0),[W,M]=T1(null),F=M1(null),[L,y]=T1(null),S=M1(""),[R,m]=T1(null),[k,V]=T1(null),w=M1(null),I=M1(null),T=M1([]),[B,c]=T1(null),[o,Z1]=T1(null),P1=Q.filter((A)=>A.filePath===J);p1(()=>{N(!0),M(null),fetch(`/api/file?session=${$}&path=${encodeURIComponent(J)}`).then((A)=>A.json()).then((A)=>{if(A.error)M(A.error),N(!1);else K(A.content),H(A.language||"text"),N(!1)}).catch(()=>{M("Failed to fetch file"),N(!1)})},[$,J]),p1(()=>{if(!z||!F.current)return;let A=setTimeout(()=>{if(F.current)O0(F.current,P1)},50);return()=>clearTimeout(A)},[z,J]);let j=M1(null);p1(()=>{W0(q,j.current),j.current=q},[q]),p1(()=>{let A=F.current;if(!A)return;let g=(t)=>{let $1=t.target.closest("[data-annotation-id]");if(!$1)return;t.stopPropagation();let O1=$1.getAttribute("data-annotation-id");if(O1===q)c({anchorEl:$1,annId:O1});else _(O1)},a=(t)=>{let $1=t.target.closest("[data-annotation-id]");if($1)_($1.getAttribute("data-annotation-id"))},n=(t)=>{let $1=t.target.closest("[data-annotation-id]"),O1=t.relatedTarget?.closest?.("[data-annotation-id]");if($1&&!O1&&!document.getElementById("ann-inline-popover"))_(null)};return A.addEventListener("click",g),A.addEventListener("mouseover",a),A.addEventListener("mouseout",n),()=>{A.removeEventListener("click",g),A.removeEventListener("mouseover",a),A.removeEventListener("mouseout",n)}},[z,Q,q]),p1(()=>{let A=()=>C();return document.addEventListener("mouseup",A),()=>document.removeEventListener("mouseup",A)},[]);let i=M1(J);i.current=J;let b=M1(Z);b.current=Z;let C=r5(()=>{let A=window.getSelection();if(!A||A.isCollapsed||!A.toString().trim())return;if(!F.current)return;let g=A.getRangeAt(0);if(!F.current.contains(g.startContainer))return;if(g.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let a=A.toString().trim();if(a.length<2)return;let n=a5(g.startContainer),t=a5(g.endContainer),$1=n?parseInt(n.getAttribute("data-line-num"),10):void 0,O1=t?parseInt(t.getAttribute("data-line-num"),10):void 0,D1="",f1="";if(a.length<30&&n&&n===t){let k1=n.querySelector("code");if(k1){let S1=k1.textContent||"",b1=S1.indexOf(a);if(b1>=0)D1=S1.slice(0,b1).trimStart(),f1=S1.slice(b1+a.length).trimEnd()}}let m0={before:D1,after:f1,hierarchy:[],lineStart:$1,lineEnd:O1},F1=`__pending_${Date.now()}`,z0=g.cloneRange();try{u1(z0,F1)}catch{}A.removeAllRanges();let r1=document.querySelectorAll(`[data-annotation-id="${F1}"]`),l1=r1[r1.length-1];if(!l1)return;S.current=a,y(F1),Z1({anchorEl:l1,tempId:F1,snippet:a,ctx:m0})},[]),h=r5((A,g)=>{A.preventDefault(),w.current=g,I.current=g,m(g),V(g)},[]);p1(()=>{let A=(a)=>{if(w.current===null)return;let n=a.target.closest("[data-line-num]");if(n){let t=parseInt(n.getAttribute("data-line-num"),10);I.current=t,V(t)}},g=()=>{let a=w.current;if(a===null)return;w.current=null;let n=I.current??a,t=Math.min(a,n),$1=Math.max(a,n),D1=T.current.slice(t-1,$1).join(`
98
- `);if(!D1.trim()){m(null),V(null);return}let f1=`__pending_${Date.now()}`,m0={before:"",after:"",hierarchy:[],lineStart:t,lineEnd:$1};if(F.current){let F1=F.current.querySelectorAll("[data-line-num]"),z0=F1[t-1],r1=F1[$1-1];if(z0&&r1){let k1=z0.querySelector("code"),S1=r1.querySelector("code");if(k1&&S1)try{let b1=document.createRange();b1.setStartBefore(k1.firstChild||k1),b1.setEndAfter(S1.lastChild||S1),u1(b1,f1)}catch{}}let l1=F1[$1-1];if(l1)S.current=D1,y(f1),Z1({anchorEl:l1,tempId:f1,snippet:D1,ctx:m0})}m(null),V(null)};return document.addEventListener("mousemove",A),document.addEventListener("mouseup",g),()=>{document.removeEventListener("mousemove",A),document.removeEventListener("mouseup",g)}},[]);let x=l5(()=>{if(!z)return null;let A=window.hljs;if(!A)return null;let g=J.split(".").pop()||"",a=b0[g];try{return(a?A.highlight(z,{language:a}):A.highlightAuto(z)).value.split(`
99
- `)}catch{return null}},[z,J]);if(G)return N1("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-[13px]",children:["Loading ",J,"..."]},void 0,!0,void 0,this);if(W)return N1("div",{className:"p-8 text-accent-red font-body text-[13px]",children:W},void 0,!1,void 0,this);if(!z)return null;let p=z.split(`
100
- `);T.current=p;let u=l5(()=>{if(R===null)return null;let A=k??R;return{start:Math.min(R,A),end:Math.max(R,A)}},[R,k]),r=()=>{let A=z.split(`
97
+ ...`:"");Z(R,"Include this file for context",y)}},B=async(y)=>{let L=[];if(K[y]?.loaded)L=K[y].entries;else{let R=await(await fetch(`/api/tree?session=${$}&path=${encodeURIComponent(y)}`)).json();if(R.entries)L=R.entries}await Promise.all(L.filter((C)=>C.type==="file").map((C)=>W(y?`${y}/${C.name}`:C.name)))},T=(y)=>_.get(y)||0,M=(y,L=0)=>{let C=K[y];if(!C?.expanded)return null;return C.entries.map((R)=>{let D=y?`${y}/${R.name}`:R.name,V=T(D);return u("div",{children:[u("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+L*16}px`,paddingRight:"8px"},children:R.type==="dir"?u(J5,{children:[u("span",{onClick:()=>H(D),className:"flex items-center gap-1.5 flex-1 text-text-secondary hover:text-text-primary cursor-pointer truncate",children:[u(i1,{name:R.name,type:"dir",expanded:K[D]?.expanded},void 0,!1,void 0,this),u("span",{className:"truncate",children:R.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this),u("button",{onClick:(b)=>{b.stopPropagation(),B(D)},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):u(J5,{children:[u("span",{onClick:()=>F(D),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:[u(i1,{name:R.name,type:"file"},void 0,!1,void 0,this),u("span",{className:"truncate",children:R.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this),u("div",{className:"flex items-center gap-1 flex-shrink-0 ml-1",children:[V>0&&u("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),u("button",{onClick:(b)=>{b.stopPropagation(),W(D)},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),R.type==="dir"&&M(D,L+1)]},D,!0,void 0,this)})};if(J)return u(J5,{children:[u("div",{className:"flex items-center justify-between px-4 pt-3 pb-2 flex-shrink-0",children:u("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),u("div",{className:"flex-1 overflow-y-auto",children:M("")},void 0,!1,void 0,this),U.length>0&&u("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:[u("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body mb-1.5",children:"Referenced"},void 0,!1,void 0,this),U.map((y)=>u("div",{onClick:()=>F(y),className:"flex items-center justify-between text-[12px] font-body text-text-secondary hover:text-text-primary cursor-pointer py-0.5",children:[u("span",{className:"truncate",children:y.split("/").pop()},void 0,!1,void 0,this),u("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(y)},void 0,!1,void 0,this)]},y,!0,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);if(X)return u("div",{className:"hidden lg:flex w-8 border-r border-border-subtle bg-bg-surface flex-col items-center flex-shrink-0",children:u("button",{onClick:()=>q(!1),className:"mt-3 p-1 text-text-tertiary hover:text-text-secondary transition-colors",children:u("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:u("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 u("div",{className:"hidden lg:flex w-60 border-r border-border-subtle bg-bg-surface flex-col flex-shrink-0 overflow-hidden",children:[u("div",{className:"flex items-center justify-between px-4 pt-4 pb-3 flex-shrink-0",children:[u("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:"Files"},void 0,!1,void 0,this),u("button",{onClick:()=>q(!0),className:"text-text-tertiary hover:text-text-secondary transition-colors p-0.5",children:u("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:u("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),u("div",{className:"flex-1 overflow-y-auto",children:M("")},void 0,!1,void 0,this),U.length>0&&u("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:[u("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body mb-1.5",children:"Referenced"},void 0,!1,void 0,this),U.map((y)=>u("div",{onClick:()=>F(y),className:"flex items-center justify-between text-[12px] font-body text-text-secondary hover:text-text-primary cursor-pointer py-0.5",children:[u("span",{className:"truncate",children:y.split("/").pop()},void 0,!1,void 0,this),u("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(y)},void 0,!1,void 0,this)]},y,!0,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}import{useEffect as t1,useState as N1,useContext as d3,useCallback as a5,useRef as P1,useMemo as i5}from"react";import{SessionContext as r3}from"#canvas/runtime";var A0={ts:"typescript",tsx:"typescript",js:"javascript",jsx:"javascript",py:"python",rs:"rust",go:"go",rb:"ruby",java:"java",json:"json",yaml:"yaml",yml:"yaml",md:"markdown",css:"css",html:"html",sh:"bash",bash:"bash",toml:"toml",sql:"sql",xml:"xml",c:"c",cpp:"cpp",h:"c"};import{jsxDEV as F1}from"react/jsx-dev-runtime";function o5(J){let $=J instanceof HTMLElement?J:J.parentElement;while($){if($.hasAttribute("data-line-num"))return $;$=$.parentElement}return null}function s5({path:J}){let $=d3(r3),{annotations:Q,addAnnotationWithId:Z,removeAnnotation:Y,updateAnnotation:X,activeAnnotationId:q,setActiveAnnotationId:K}=q1(),[z,_]=N1(null),[U,G]=N1("text"),[H,F]=N1(!0),[W,B]=N1(null),T=P1(null),[M,y]=N1(null),L=P1(""),[C,R]=N1(null),[D,V]=N1(null),b=P1(null),I=P1(null),P=P1([]),[O,j]=N1(null),[o,Z1]=N1(null),C1=Q.filter((A)=>A.filePath===J);t1(()=>{F(!0),B(null),fetch(`/api/file?session=${$}&path=${encodeURIComponent(J)}`).then((A)=>A.json()).then((A)=>{if(A.error)B(A.error),F(!1);else _(A.content),G(A.language||"text"),F(!1)}).catch(()=>{B("Failed to fetch file"),F(!1)})},[$,J]),t1(()=>{if(!z||!T.current)return;let A=setTimeout(()=>{if(T.current)r1(T.current,C1)},50);return()=>clearTimeout(A)},[z,J]);let g=P1(null);t1(()=>{c1(q,g.current),g.current=q},[q]),t1(()=>{let A=T.current;if(!A)return;let f=(t)=>{let J1=t.target.closest("[data-annotation-id]");if(!J1)return;t.stopPropagation();let O1=J1.getAttribute("data-annotation-id");if(O1===q)j({anchorEl:J1,annId:O1});else K(O1)},a=(t)=>{let J1=t.target.closest("[data-annotation-id]");if(J1)K(J1.getAttribute("data-annotation-id"))},n=(t)=>{let J1=t.target.closest("[data-annotation-id]"),O1=t.relatedTarget?.closest?.("[data-annotation-id]");if(J1&&!O1&&!document.getElementById("ann-inline-popover"))K(null)};return A.addEventListener("click",f),A.addEventListener("mouseover",a),A.addEventListener("mouseout",n),()=>{A.removeEventListener("click",f),A.removeEventListener("mouseover",a),A.removeEventListener("mouseout",n)}},[z,Q,q]),t1(()=>{let A=()=>m();return document.addEventListener("mouseup",A),()=>document.removeEventListener("mouseup",A)},[]);let i=P1(J);i.current=J;let w=P1(Z);w.current=Z;let m=a5(()=>{let A=window.getSelection();if(!A||A.isCollapsed||!A.toString().trim())return;if(!T.current)return;let f=A.getRangeAt(0);if(!T.current.contains(f.startContainer))return;if(f.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let a=A.toString().trim();if(a.length<2)return;let n=o5(f.startContainer),t=o5(f.endContainer),J1=n?parseInt(n.getAttribute("data-line-num"),10):void 0,O1=t?parseInt(t.getAttribute("data-line-num"),10):void 0,x1="",h1="";if(a.length<30&&n&&n===t){let p1=n.querySelector("code");if(p1){let A1=p1.textContent||"",R1=A1.indexOf(a);if(R1>=0)x1=A1.slice(0,R1).trimStart(),h1=A1.slice(R1+a.length).trimEnd()}}let V0={before:x1,after:h1,hierarchy:[],lineStart:J1,lineEnd:O1},B1=`__pending_${Date.now()}`,H0=f.cloneRange();try{L1(H0,B1)}catch{}A.removeAllRanges();let e1=document.querySelectorAll(`[data-annotation-id="${B1}"]`),$0=e1[e1.length-1];if(!$0)return;L.current=a,y(B1),Z1({anchorEl:$0,tempId:B1,snippet:a,ctx:V0})},[]),p=a5((A,f)=>{A.preventDefault(),b.current=f,I.current=f,R(f),V(f)},[]);t1(()=>{let A=(a)=>{if(b.current===null)return;let n=a.target.closest("[data-line-num]");if(n){let t=parseInt(n.getAttribute("data-line-num"),10);I.current=t,V(t)}},f=()=>{let a=b.current;if(a===null)return;b.current=null;let n=I.current??a,t=Math.min(a,n),J1=Math.max(a,n),x1=P.current.slice(t-1,J1).join(`
98
+ `);if(!x1.trim()){R(null),V(null);return}let h1=`__pending_${Date.now()}`,V0={before:"",after:"",hierarchy:[],lineStart:t,lineEnd:J1};if(T.current){let B1=T.current.querySelectorAll("[data-line-num]"),H0=B1[t-1],e1=B1[J1-1];if(H0&&e1){let p1=H0.querySelector("code"),A1=e1.querySelector("code");if(p1&&A1)try{let R1=document.createRange();R1.setStartBefore(p1.firstChild||p1),R1.setEndAfter(A1.lastChild||A1),L1(R1,h1)}catch{}}let $0=B1[J1-1];if($0)L.current=x1,y(h1),Z1({anchorEl:$0,tempId:h1,snippet:x1,ctx:V0})}R(null),V(null)};return document.addEventListener("mousemove",A),document.addEventListener("mouseup",f),()=>{document.removeEventListener("mousemove",A),document.removeEventListener("mouseup",f)}},[]);let h=i5(()=>{if(!z)return null;let A=window.hljs;if(!A)return null;let f=J.split(".").pop()||"",a=A0[f];try{return(a?A.highlight(z,{language:a}):A.highlightAuto(z)).value.split(`
99
+ `)}catch{return null}},[z,J]);if(H)return F1("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-[13px]",children:["Loading ",J,"..."]},void 0,!0,void 0,this);if(W)return F1("div",{className:"p-8 text-accent-red font-body text-[13px]",children:W},void 0,!1,void 0,this);if(!z)return null;let c=z.split(`
100
+ `);P.current=c;let v=i5(()=>{if(C===null)return null;let A=D??C;return{start:Math.min(C,A),end:Math.max(C,A)}},[C,D]),r=()=>{let A=z.split(`
101
101
  `).slice(0,3).join(`
102
- `)+(p.length>3?`
103
- ...`:""),g=H1();Z(g,A,"",J),_(g)},d=F.current?.closest("#plan-scroll-container");return N1("div",{children:[N1("pre",{ref:F,className:"text-code font-mono text-text-code bg-bg-base select-text cursor-text py-3 hljs",children:p.map((A,g)=>{let a=g+1,n=u&&a>=u.start&&a<=u.end;return N1("div",{"data-line-num":a,className:`flex px-5 ${n?"bg-accent-blue/10":"hover:bg-bg-elevated-half"}`,children:[N1("span",{className:"text-text-tertiary select-none w-10 text-right pr-4 shrink-0 py-px text-[12px] cursor-pointer opacity-40 hover:opacity-100 hover:text-accent-blue",onMouseDown:(t)=>h(t,a),children:a},void 0,!1,void 0,this),x?N1("code",{className:"py-px",dangerouslySetInnerHTML:{__html:x[g]||" "}},void 0,!1,void 0,this):N1("code",{className:"py-px",children:A||" "},void 0,!1,void 0,this)]},g,!0,void 0,this)})},void 0,!1,void 0,this),B&&(()=>{let A=Q.find((g)=>g.id===B.annId);if(!A)return null;return N1(Y0,{anchorEl:B.anchorEl,scrollContainer:d,initialNote:A.note,onUpdate:(g)=>X(B.annId,g),onDelete:()=>{Y(B.annId),_(null)},onClose:()=>c(null)},void 0,!1,void 0,this)})(),o&&N1(J0,{anchorEl:o.anchorEl,scrollContainer:d,snippet:o.snippet,onAdd:(A)=>{let g=H1();T0(o.tempId,g),Z(g,o.snippet,A,J,o.ctx),y(null),Z1(null)},onCancel:()=>{F0(o.tempId),y(null),Z1(null)}},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{useEffect as o5,useState as s5,useRef as d3}from"react";import{jsxDEV as W1}from"react/jsx-dev-runtime";function t5(J,$){if($){let Q=$.replace(/\/+$/,"").split("/");return Q[Q.length-1]||J}return J.length>30?J.slice(0,30)+"...":J}function n0({currentSessionId:J,projectRoot:$}){let[Q,Z]=s5([]),[Y,X]=s5(!1),q=d3(null);o5(()=>{let K=async()=>{try{let G=await(await fetch("/api/sessions")).json();Z((N)=>{let W=JSON.stringify(G);return JSON.stringify(N)===W?N:G})}catch{}};K();let U=setInterval(K,5000);return()=>clearInterval(U)},[]),o5(()=>{if(!Y)return;let K=(U)=>{if(q.current&&!q.current.contains(U.target))X(!1)};return document.addEventListener("mousedown",K),()=>document.removeEventListener("mousedown",K)},[Y]);let _=Q.filter((K)=>K.id!==J),z=t5(J,$);return W1("div",{className:"relative",ref:q,children:[W1("div",{className:"flex items-center gap-1.5 font-body text-body font-medium",children:[W1("a",{href:`/s/${J}`,className:"text-text-primary hover:text-text-secondary transition-colors",children:z},void 0,!1,void 0,this),_.length>0&&W1("button",{onClick:()=>X(!Y),className:"flex items-center justify-center text-text-tertiary hover:text-text-secondary transition-colors",children:W1("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:`transition-transform duration-200 ${Y?"rotate-180":""}`,children:W1("path",{d:"M3 5l3 3 3-3",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Y&&_.length>0&&W1("div",{className:"absolute top-full left-0 mt-2 w-64 bg-bg-elevated border border-border-hover rounded-lg shadow-lg z-50 py-1 overflow-hidden",children:_.map((K)=>W1("a",{href:`/s/${K.id}`,className:"flex items-center gap-2.5 px-4 py-2.5 text-body font-body text-text-secondary hover:bg-bg-surface hover:text-text-primary transition-colors",children:[W1("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${K.currentRevision>0?"bg-accent-green":"bg-border-hover"}`},void 0,!1,void 0,this),W1("span",{className:"truncate",children:t5(K.id,K.projectRoot)},void 0,!1,void 0,this)]},K.id,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function n5(J){let $=[];return A0(J,$,0),$.join(`
102
+ `)+(c.length>3?`
103
+ ...`:""),f=G1();Z(f,A,"",J),K(f)},d=T.current?.closest("#plan-scroll-container");return F1("div",{children:[F1("pre",{ref:T,className:"text-code font-mono text-text-code bg-bg-base select-text cursor-text py-3 hljs",children:c.map((A,f)=>{let a=f+1,n=v&&a>=v.start&&a<=v.end;return F1("div",{"data-line-num":a,className:`flex px-5 ${n?"bg-accent-blue/10":"hover:bg-bg-elevated-half"}`,children:[F1("span",{className:"text-text-tertiary select-none w-10 text-right pr-4 shrink-0 py-px text-[12px] cursor-pointer opacity-40 hover:opacity-100 hover:text-accent-blue",onMouseDown:(t)=>p(t,a),children:a},void 0,!1,void 0,this),h?F1("code",{className:"py-px",dangerouslySetInnerHTML:{__html:h[f]||" "}},void 0,!1,void 0,this):F1("code",{className:"py-px",children:A||" "},void 0,!1,void 0,this)]},f,!0,void 0,this)})},void 0,!1,void 0,this),O&&(()=>{let A=Q.find((f)=>f.id===O.annId);if(!A)return null;return F1(D1,{anchorEl:O.anchorEl,scrollContainer:d,initialNote:A.note,onUpdate:(f)=>X(O.annId,f),onDelete:()=>{Y(O.annId),K(null)},onClose:()=>j(null)},void 0,!1,void 0,this)})(),o&&F1(g1,{anchorEl:o.anchorEl,scrollContainer:d,snippet:o.snippet,onAdd:(A)=>{let f=G1();d1(o.tempId,f),Z(f,o.snippet,A,J,o.ctx),y(null),Z1(null)},onCancel:()=>{l1(o.tempId),y(null),Z1(null)}},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{useEffect as t5,useState as n5,useRef as l3}from"react";import{jsxDEV as y1}from"react/jsx-dev-runtime";function e5(J,$){if($){let Q=$.replace(/\/+$/,"").split("/");return Q[Q.length-1]||J}return J.length>30?J.slice(0,30)+"...":J}function Y5({currentSessionId:J,projectRoot:$}){let[Q,Z]=n5([]),[Y,X]=n5(!1),q=l3(null);t5(()=>{let _=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{}};_();let U=setInterval(_,5000);return()=>clearInterval(U)},[]),t5(()=>{if(!Y)return;let _=(U)=>{if(q.current&&!q.current.contains(U.target))X(!1)};return document.addEventListener("mousedown",_),()=>document.removeEventListener("mousedown",_)},[Y]);let K=Q.filter((_)=>_.id!==J),z=e5(J,$);return y1("div",{className:"relative",ref:q,children:[y1("div",{className:"flex items-center gap-1.5 font-body text-body font-medium",children:[y1("a",{href:`/s/${J}`,className:"text-text-primary hover:text-text-secondary transition-colors",children:z},void 0,!1,void 0,this),K.length>0&&y1("button",{onClick:()=>X(!Y),className:"flex items-center justify-center text-text-tertiary hover:text-text-secondary transition-colors",children:y1("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:`transition-transform duration-200 ${Y?"rotate-180":""}`,children:y1("path",{d:"M3 5l3 3 3-3",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Y&&K.length>0&&y1("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:K.map((_)=>y1("a",{href:`/s/${_.id}`,className:"flex items-center gap-2.5 px-4 py-2.5 text-body font-body text-text-secondary hover:bg-bg-surface hover:text-text-primary transition-colors",children:[y1("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${_.currentRevision>0?"bg-accent-green":"bg-border-hover"}`},void 0,!1,void 0,this),y1("span",{className:"truncate",children:e5(_.id,_.projectRoot)},void 0,!1,void 0,this)]},_.id,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function $2(J){let $=[];return R0(J,$,0),$.join(`
104
104
  `).replace(/\n{3,}/g,`
105
105
 
106
106
  `).trim()+`
107
- `}var r3=new Set(["CODE","SPAN","STRONG","EM","A","B","I","U","SMALL","SUB","SUP","MARK","ABBR"]);function A0(J,$,Q){if(l3(J)){let Z=a3(J);if(Z)$.push(Z,"");return}for(let Z of J.childNodes)if(Z.nodeType===Node.ELEMENT_NODE)i3(Z,$,Q);else if(Z.nodeType===Node.TEXT_NODE){let Y=Z.textContent?.trim();if(Y)$.push(Y,"")}}function l3(J){for(let $ of J.childNodes){if($.nodeType===Node.TEXT_NODE)continue;if($.nodeType===Node.ELEMENT_NODE){let Q=$;if(!r3.has(Q.tagName)||Q.hasAttribute("data-md"))return!1}}return J.childNodes.length>0}function a3(J){let $="";for(let Q of J.childNodes)if(Q.nodeType===Node.TEXT_NODE)$+=Q.textContent||"";else if(Q.nodeType===Node.ELEMENT_NODE){let Z=Q;if(Z.tagName==="CODE")$+="`"+(Z.textContent||"")+"`";else $+=Z.textContent||""}return $.trim()}function i3(J,$,Q){let Z=J.getAttribute("data-md");if(Z)switch(Z){case"section":return o3(J,$,Q);case"item":return s3(J,$);case"codeblock":return t3(J,$);case"callout":return n3(J,$);case"note":return e3(J,$);case"table":return $$(J,$);case"checklist":return J$(J,$);case"diff":return Y$(J,$);case"mermaid":return Q$(J,$);case"choice":return Z$(J,$);case"multichoice":return q$(J,$);case"choice-option":case"multichoice-option":return;case"userinput":return X$(J,$);case"rangeinput":return z$(J,$);case"checklist-item":return;case"filepreview":return _$(J,$);case"priority":return K$(J,$)}if(J.querySelector("button, input, select, textarea"))return;if(J.children.length>0)A0(J,$,Q);else{let Y=J.textContent?.trim();if(Y)$.push(Y,"")}}function o3(J,$,Q){let Z=J.getAttribute("data-md-title")||"Untitled",Y=Q===0?"##":"###";$.push(`${Y} ${Z}`,"");let X=J.querySelector(":scope > div:last-of-type");if(X)A0(X,$,Q+1)}function s3(J,$){let Q=J.getAttribute("data-md-label")||"",Z=J.getAttribute("data-md-status"),Y=J.getAttribute("data-md-badge"),X="-";if(Z==="done")X="- [x]";else if(Z)X="- [ ]";let q=`${X} **${Q}**`;if(Y)q+=` \`${Y}\``;$.push(q);let _=J.querySelector(".text-text-secondary");if(_){let z=[];A0(_,z,0);for(let K of z)$.push(K?` ${K}`:"")}$.push("")}function t3(J,$){let Q=J.getAttribute("data-md-language")||"",Y=J.querySelector("code")?.textContent||"";$.push(`\`\`\`${Q}`,Y,"```","")}function n3(J,$){let Q=J.getAttribute("data-md-type")||"info",Z={info:"Info",warning:"Warning",danger:"Danger",tip:"Tip"},Y=U$(J.querySelector(".text-text-secondary")||J);$.push(`> **${Z[Q]||Q}:** ${Y}`,"")}function e3(J,$){let Q=J.textContent?.trim()||"";$.push(`> *${Q}*`,"")}function $$(J,$){let Q=J.querySelector("table");if(!Q)return;let Z=[];for(let Y of Q.querySelectorAll("thead th"))Z.push(Y.textContent?.trim()||"");if(Z.length===0)return;$.push(`| ${Z.join(" | ")} |`),$.push(`| ${Z.map(()=>"---").join(" | ")} |`);for(let Y of Q.querySelectorAll("tbody tr")){let X=[];for(let q of Y.querySelectorAll("td"))X.push(q.textContent?.trim()||"");$.push(`| ${X.join(" | ")} |`)}$.push("")}function J$(J,$){for(let Q of J.querySelectorAll("li")){let Z=Q.querySelector(".bg-accent-green")!==null,Y=Q.textContent?.trim()||"";$.push(`- [${Z?"x":" "}] ${Y}`)}$.push("")}function Y$(J,$){let Q=J.getAttribute("data-md-language")||"";$.push(`\`\`\`diff${Q?` (${Q})`:""}`);for(let Z of J.querySelectorAll("[class*='flex']")){let Y=Z.querySelector(".text-accent-red")?"-":Z.querySelector(".text-accent-green")?"+":" ",X=Z.querySelector("code");if(X)$.push(`${Y} ${X.textContent}`)}$.push("```","")}function Q$(J,$){let Q=J.getAttribute("data-md-source")||"";if(Q)$.push("```mermaid",Q,"```","")}function Z$(J,$){let Q=J.getAttribute("data-md-label")||"";$.push(`**${Q}:**`);for(let Z of J.querySelectorAll("[data-md='choice-option']")){let Y=Z.getAttribute("data-md-label")||Z.textContent?.trim()||"",X=Z.querySelector(".bg-accent-amber")!==null;$.push(`- ${X?"(x)":"( )"} ${Y}`)}$.push("")}function q$(J,$){let Q=J.getAttribute("data-md-label")||"";$.push(`**${Q}:**`);for(let Z of J.querySelectorAll("[data-md='multichoice-option']")){let Y=Z.getAttribute("data-md-label")||Z.textContent?.trim()||"",X=Z.querySelector(".bg-accent-amber")!==null;$.push(`- [${X?"x":" "}] ${Y}`)}$.push("")}function X$(J,$){let Q=J.getAttribute("data-md-label")||"",Y=J.querySelector("textarea")?.value?.trim()||"";$.push(`**${Q}:** ${Y||"_empty_"}`,"")}function z$(J,$){let Q=J.getAttribute("data-md-label")||"",Z=J.querySelector("input[type='range']"),X=J.querySelector(".font-mono")?.textContent?.trim()||Z?.value||"—";$.push(`**${Q}:** ${X}`,"")}function _$(J,$){let Q=J.getAttribute("data-md-path")||"",Z=J.getAttribute("data-md-lines")||"",X=J.querySelector("code")?.textContent||"",q=Q.split(".").pop()||"",_=b0[q]||"",z=Z?`${Q} (L${Z})`:Q;$.push(z,"",`\`\`\`${_}`,X,"```","")}function K$(J,$){}function U$(J){return J?.textContent?.trim()||""}import A$,{useEffect as c1,useState as Y1,useRef as L1}from"react";import{useEffect as G$,useState as H$,useRef as N$,useContext as W$}from"react";import{jsxDEV as z1,Fragment as e5}from"react/jsx-dev-runtime";function T$(J){return J.label||`Round ${J.revision}`}function O$(J){let $=Date.now()-new Date(J).getTime(),Q=Math.floor($/1000);if(Q<60)return"just now";let Z=Math.floor(Q/60);if(Z<60)return`${Z}m ago`;let Y=Math.floor(Z/60);if(Y<24)return`${Y}h ago`;return`${Math.floor(Y/24)}d ago`}function Z0({value:J,onChange:$,accent:Q="default",className:Z}){let{currentRevision:Y,revisions:X}=W$(h1),[q,_]=H$(!1),z=N$(null);G$(()=>{if(!q)return;let H=(G)=>{if(z.current&&!z.current.contains(G.target))_(!1)};return document.addEventListener("mousedown",H),()=>document.removeEventListener("mousedown",H)},[q]);let K=X.find((H)=>H.revision===J);return z1("div",{className:"relative",ref:z,children:[z1("button",{onClick:()=>_(!q),className:`flex items-center gap-1.5 text-[12px] font-body font-medium px-2 py-1 rounded-md transition-colors hover:bg-bg-elevated ${{default:"text-text-secondary hover:text-text-primary",red:"text-accent-red",green:"text-accent-green",amber:"text-accent-amber bg-highlight-selected"}[Q]} ${Z||""}`,children:[K?T$(K):`Round ${J}`,z1("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",className:`text-text-tertiary transition-transform duration-200 ${q?"rotate-180":""}`,children:z1("path",{d:"M2.5 4l2.5 2.5L7.5 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),q&&z1("div",{className:"absolute top-full left-0 mt-1 w-64 bg-bg-elevated border border-border-hover rounded-lg shadow-lg z-50 py-1 max-h-80 overflow-y-auto",children:[...X].reverse().map((H)=>z1("button",{onClick:()=>{$(H.revision),_(!1)},className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] font-body transition-colors ${H.revision===J?"bg-bg-surface text-text-primary":"text-text-secondary hover:bg-bg-surface hover:text-text-primary"}`,children:[z1("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${H.revision===Y?"bg-accent-green":H.hasFeedback?"bg-accent-amber":"bg-border-hover"}`},void 0,!1,void 0,this),z1("span",{className:"flex-1 text-left truncate",children:H.label?z1(e5,{children:[H.label," ",z1("span",{className:"text-text-tertiary",children:["#",H.revision]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):z1(e5,{children:["Round ",H.revision]},void 0,!0,void 0,this)},void 0,!1,void 0,this),z1("span",{className:"text-[10px] text-text-tertiary flex-shrink-0",children:H.revision===Y?"current":H.hasFeedback?"sent":O$(H.createdAt)},void 0,!1,void 0,this)]},H.revision,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function B1(J,$){let Q=J.length,Z=$.length;if(Q===0||Z===0)return[];let Y=Array.from({length:Q+1},()=>Array(Z+1).fill(0));for(let z=1;z<=Q;z++)for(let K=1;K<=Z;K++)Y[z][K]=J[z-1]===$[K-1]?Y[z-1][K-1]+1:Math.max(Y[z-1][K],Y[z][K-1]);let X=[],q=Q,_=Z;while(q>0&&_>0)if(J[q-1]===$[_-1])X.unshift(J[q-1]),q--,_--;else if(Y[q-1][_]>Y[q][_-1])q--;else _--;return X}function $2(J){let $=[],Q=[],Z=document.createTreeWalker(J,NodeFilter.SHOW_TEXT,{acceptNode(X){let q=X.parentElement;if(!q)return NodeFilter.FILTER_REJECT;if(q.closest("svg, .select-none, [data-no-diff]"))return NodeFilter.FILTER_REJECT;return NodeFilter.FILTER_ACCEPT}}),Y;while(Y=Z.nextNode()){let q=(Y.nodeValue||"").match(/\S+|\s+/g);if(!q)continue;let _=0;for(let z of q)$.push(z),Q.push({text:z,node:Y,offset:_}),_+=z.length}return{words:$,map:Q}}function e0(J,$){if(J.length>5000||$.length>5000)return F$(J,$);return Q2(J,$)}function Q2(J,$){let Q=w0(J,$),Z=[],Y=[],X=0,q=0,_=0;while(X<J.length||q<$.length)if(_<Q.length&&X<J.length&&q<$.length&&J[X]===Q[_]&&$[q]===Q[_])Z.push({type:"same",index:X}),Y.push({type:"same",index:q}),X++,q++,_++;else if(X<J.length&&(_>=Q.length||J[X]!==Q[_]))Z.push({type:"removed",index:X}),X++;else if(q<$.length)Y.push({type:"added",index:q}),q++;return{oldOps:Z,newOps:Y}}function w0(J,$){let Q=J.length,Z=$.length;if(Q===0||Z===0)return[];if(Q===1)return $.includes(J[0])?[J[0]]:[];if(Z===1)return J.includes($[0])?[$[0]]:[];if(Q*Z<=1e6)return B1(J,$);let Y=Math.floor(Q/2),X=J.slice(0,Y),q=J.slice(Y),_=J2(X,$),z=J2([...q].reverse(),[...$].reverse()),K=0,U=0;for(let N=0;N<=Z;N++){let W=_[N]+z[Z-N];if(W>K)K=W,U=N}let H=$.slice(0,U),G=$.slice(U);return[...w0(X,H),...w0(q,G)]}function J2(J,$){let Q=$.length,Z=Array(Q+1).fill(0),Y=Array(Q+1).fill(0);for(let X=0;X<J.length;X++){for(let q=1;q<=Q;q++)Y[q]=J[X]===$[q-1]?Z[q-1]+1:Math.max(Z[q],Y[q-1]);[Z,Y]=[Y,Z],Y.fill(0)}return Z}function F$(J,$){let Z=(W)=>{let M=[];for(let F=0;F<W.length;F+=200){let L=Math.min(F+200,W.length);M.push({start:F,end:L,text:W.slice(F,L).join("")})}return M},Y=Z(J),X=Z($),q=Y.map((W)=>W.text),_=X.map((W)=>W.text),z=w0(q,_),K=[],U=[],H=0,G=0,N=0;while(H<Y.length||G<X.length)if(N<z.length&&H<Y.length&&G<X.length&&q[H]===z[N]&&_[G]===z[N]){for(let W=Y[H].start;W<Y[H].end;W++)K.push({type:"same",index:W});for(let W=X[G].start;W<X[G].end;W++)U.push({type:"same",index:W});H++,G++,N++}else if(H<Y.length&&(N>=z.length||q[H]!==z[N]))if(G<X.length&&(N>=z.length||_[G]!==z[N])){let W=Q2(J.slice(Y[H].start,Y[H].end),$.slice(X[G].start,X[G].end));for(let M of W.oldOps)K.push({type:M.type,index:M.index+Y[H].start});for(let M of W.newOps)U.push({type:M.type,index:M.index+X[G].start});H++,G++}else{for(let W=Y[H].start;W<Y[H].end;W++)K.push({type:"removed",index:W});H++}else if(G<X.length){for(let W=X[G].start;W<X[G].end;W++)U.push({type:"added",index:W});G++}return{oldOps:K,newOps:U}}function Y2(J,$,Q){let Z=new Map;for(let Y of J){if(Y.type==="same")continue;let X=$[Y.index];if(!X||!X.node.parentNode)continue;let q=Z.get(X.node);if(!q)q=[],Z.set(X.node,q);q.push({offset:X.offset,length:X.text.length})}for(let[Y,X]of Z){if(!Y.parentNode)continue;let q=Y.nodeValue||"";X.sort((H,G)=>H.offset-G.offset);let _=[];for(let H of X){let G=_[_.length-1];if(G&&H.offset<=G.offset+G.length)G.length=Math.max(G.length,H.offset+H.length-G.offset);else _.push({...H})}let z=Y.parentNode,K=document.createDocumentFragment(),U=0;for(let H of _){if(H.offset>U)K.appendChild(document.createTextNode(q.slice(U,H.offset)));let G=document.createElement("span");G.className=Q,G.textContent=q.slice(H.offset,H.offset+H.length),K.appendChild(G),U=H.offset+H.length}if(U<q.length)K.appendChild(document.createTextNode(q.slice(U)));z.replaceChild(K,Y)}}function Z2(J,$){let Q=y$(J,$),Z=$2(J),Y=$2($),{oldOps:X,newOps:q}=e0(Z.words,Y.words),_=X.some((z)=>z.type==="removed")||q.some((z)=>z.type==="added");return Y2(X,Z.map,"diff-removed"),Y2(q,Y.map,"diff-added"),_||Q}function y$(J,$){let Q=Array.from(J.querySelectorAll('[data-md="mermaid"]')),Z=Array.from($.querySelectorAll('[data-md="mermaid"]')),Y=!1,X=Math.max(Q.length,Z.length);for(let q=0;q<X;q++){let _=Q[q],z=Z[q];if(!_&&z){z.classList.add("diff-block-added"),z.style.position="relative",Y=!0;continue}if(_&&!z){_.classList.add("diff-block-removed"),_.style.position="relative",Y=!0;continue}if(!_||!z)continue;let K=(_.getAttribute("data-md-source")||"").trim(),U=(z.getAttribute("data-md-source")||"").trim();if(K===U)continue;Y=!0,_.style.borderLeft="3px solid var(--color-accent-red)",_.style.paddingLeft="8px",z.style.borderLeft="3px solid var(--color-accent-green)",z.style.paddingLeft="8px";let H=K.split(`
108
- `),G=U.split(`
109
- `),N=B1(H,G),W=(M,F,L)=>{let y=document.createElement("div");y.className="mt-2 bg-bg-code rounded-md overflow-hidden text-tiny font-mono",y.setAttribute("data-no-diff","true");let S=0,R=0;while(R<M.length){let m=document.createElement("div");if(m.className="px-3 py-0.5 whitespace-pre-wrap",S<F.length&&M[R]===F[S])m.textContent=" "+M[R],R++,S++;else m.classList.add(L==="old"?"diff-removed":"diff-added"),m.textContent=(L==="old"?"- ":"+ ")+M[R],R++;y.appendChild(m)}return y};_.appendChild(W(H,N,"old")),z.appendChild(W(G,N,"new"))}return Y}function $5(J){let $=[],Q=J.querySelectorAll(":scope > [data-md]");for(let Z of Q)$.push(q0(Z));if($.length===0){let Z=J.querySelectorAll("[data-md]"),Y=new Set;for(let X of Z){let q=X.parentElement?.closest("[data-md]");if(q&&J.contains(q))continue;if(Y.has(X))continue;Y.add(X),$.push(q0(X))}}return $}function q0(J){let $=J.getAttribute("data-md")||"unknown",Q=M$(J,$),Z=[];if($==="section"){let Y=J.querySelector(":scope > div.mt-6, :scope > div:last-child");if(Y)for(let X of Y.querySelectorAll(":scope > [data-md]"))Z.push(q0(X))}else if($==="table")for(let Y of J.querySelectorAll(":scope table > tbody > tr"))Z.push({key:"tr:"+(Y.textContent||"").slice(0,80),type:"tr",element:Y,children:[]});else if($==="checklist")for(let Y of J.querySelectorAll(":scope > [data-md='checklist-item']"))Z.push(q0(Y));else for(let Y of J.querySelectorAll("[data-md]"))if(Y.parentElement?.closest("[data-md]")===J)Z.push(q0(Y));return{key:Q,type:$,element:J,children:Z}}function M$(J,$){switch($){case"section":return"section:"+(J.getAttribute("data-md-title")||"");case"item":return"item:"+(J.getAttribute("data-task-id")||J.getAttribute("data-md-label")||"");case"codeblock":case"diff":return $+":"+(J.textContent||"").slice(0,80);case"checklist-item":return"checklist-item:"+(J.getAttribute("data-md-label")||J.textContent?.slice(0,60)||"");case"checklist":return"checklist:"+J.querySelectorAll("[data-md='checklist-item']").length;case"markdown":return"markdown:"+(J.getAttribute("data-md-file")||"inline");case"mermaid":return"mermaid:"+(J.getAttribute("data-md-source")||"").slice(0,80);case"callout":return"callout:"+(J.getAttribute("data-md-type")||"")+":"+(J.textContent||"").slice(0,60);default:return $+":"+(J.getAttribute("data-md-label")||J.textContent?.slice(0,60)||"")}}function J5(J,$){let Q=J.map((K)=>K.key),Z=$.map((K)=>K.key),Y=B1(Q,Z),X=[],q=0,_=0,z=0;while(q<J.length||_<$.length)if(z<Y.length&&q<J.length&&_<$.length&&Q[q]===Y[z]&&Z[_]===Y[z]){let K=J[q],U=$[_],H=K.children.length>0||U.children.length>0?J5(K.children,U.children):void 0;X.push({kind:"matched",oldBlock:K,newBlock:U,childMatches:H}),q++,_++,z++}else if(q<J.length&&(z>=Y.length||Q[q]!==Y[z]))X.push({kind:"removed",oldBlock:J[q]}),q++;else if(_<$.length)X.push({kind:"added",newBlock:$[_]}),_++;return X}function X2(J){let $=document.createDocumentFragment(),Q=!1;for(let Z of J)if(Z.kind==="removed")Q=!0,$.appendChild(z2(Z.oldBlock.element));else if(Z.kind==="added")Q=!0,$.appendChild(B$(Z.newBlock.element));else{let Y=Z.newBlock.element.cloneNode(!0),X=Z.newBlock.type;if(X==="mermaid"){if(G2(Z.oldBlock.element,Y))Q=!0}else if(Z.childMatches&&Z.childMatches.length>0&&(X==="table"||X==="checklist")){if(K2(Y,Z.childMatches,X))Q=!0}else if(Z.childMatches&&Z.childMatches.length>0){if(_2(Z.oldBlock,Y,Z.childMatches,X))Q=!0}else if(X==="markdown"){if(U2(Z.oldBlock.element,Y))Q=!0}else if(V1(Z.oldBlock.element,Y,!1))Q=!0;$.appendChild(Y)}return{fragment:$,hasChanges:Q}}function z2(J){let $=J.cloneNode(!0);return $.classList.add("diff-block-removed"),$.style.position="relative",Y5($,"Removed","var(--color-accent-red)"),$}function B$(J){let $=J.cloneNode(!0);return $.classList.add("diff-block-added"),$.style.position="relative",Y5($,"Added","var(--color-accent-green)"),$}function _2(J,$,Q,Z){let Y=!1,X=L$(J,$),q,_;if(Z==="section"){let z=J.element.querySelector(":scope > div:first-child"),K=$.querySelector(":scope > div:first-child");if(z&&K){if(V1(z,K,!1))Y=!0}q=J.element.querySelector(":scope > div.mt-6, :scope > div:last-child"),_=$.querySelector(":scope > div.mt-6, :scope > div:last-child")}else q=J.element,_=$;if(!q||!_)return Y;for(let z of Q)if(z.kind==="matched"){let K=X.newMap.get(z.newBlock.element);if(K){if(z.newBlock.type==="mermaid"){if(G2(z.oldBlock.element,K))Y=!0}else if(z.childMatches&&z.childMatches.length>0&&(z.newBlock.type==="table"||z.newBlock.type==="checklist")){if(K2(K,z.childMatches,z.newBlock.type))Y=!0}else if(z.childMatches&&z.childMatches.length>0){if(_2(z.oldBlock,K,z.childMatches,z.newBlock.type))Y=!0}else if(z.newBlock.type==="markdown"){if(U2(z.oldBlock.element,K))Y=!0}else if(V1(z.oldBlock.element,K,!1))Y=!0}}else if(z.kind==="removed"){Y=!0;let K=z2(z.oldBlock.element),U=S$(Q,z,X.newMap);_.insertBefore(K,U)}else if(z.kind==="added"){Y=!0;let K=X.newMap.get(z.newBlock.element);if(K)K.classList.add("diff-block-added"),K.style.position="relative",Y5(K,"Added","var(--color-accent-green)")}if(V1(q,_,!0))Y=!0;return Y}function K2(J,$,Q){let Z=Q==="table"?J.querySelector(":scope table > tbody"):J;if(!Z)return!1;let Y=!1;Z.innerHTML="";for(let X of $)if(X.kind==="removed"){Y=!0;let q=X.oldBlock.element.cloneNode(!0);q.classList.add(Q==="table"?"diff-row-removed":"diff-item-removed"),Z.appendChild(q)}else if(X.kind==="added"){Y=!0;let q=X.newBlock.element.cloneNode(!0);q.classList.add(Q==="table"?"diff-row-added":"diff-item-added"),Z.appendChild(q)}else{let q=X.newBlock.element.cloneNode(!0);if(V1(X.oldBlock.element,q,!1))Y=!0;Z.appendChild(q)}return Y}function L$(J,$){let Q=new Map,Z=J.element.querySelectorAll("[data-md]"),Y=$.querySelectorAll("[data-md]");return{newMap:{get(X){return P$($,X)}}}}function P$(J,$){let Q=$.getAttribute("data-md");if(!Q)return null;let Z=$.getAttribute("data-md-label"),Y=$.getAttribute("data-md-title"),X=`[data-md="${Q}"]`;if(Y)X+=`[data-md-title="${CSS.escape(Y)}"]`;else if(Z)X+=`[data-md-label="${CSS.escape(Z)}"]`;let q=J.querySelectorAll(X);if(q.length===1)return q[0];let _=($.textContent||"").slice(0,100),z=null,K=-1;for(let U of q){let H=(U.textContent||"").slice(0,100),G=0;for(let N=0;N<Math.min(_.length,H.length);N++)if(_[N]===H[N])G++;if(G>K)K=G,z=U}return z}function S$(J,$,Q){let Z=J.indexOf($);for(let Y=Z+1;Y<J.length;Y++){let X=J[Y];if((X.kind==="matched"||X.kind==="added")&&X.newBlock)return Q.get(X.newBlock.element)||null}return null}function U2(J,$){let Q=Array.from(J.children),Z=Array.from($.children);if(Q.length===0&&Z.length===0)return V1(J,$,!1);let Y=Q.map((G)=>G.tagName.toLowerCase()),X=Z.map((G)=>G.tagName.toLowerCase()),q=B1(Y,X),_=[],z=0,K=0,U=0;while(z<Q.length||K<Z.length)if(U<q.length&&z<Q.length&&K<Z.length&&Y[z]===q[U]&&X[K]===q[U])_.push({kind:"matched",oldChild:Q[z],newChild:Z[K]}),z++,K++,U++;else if(z<Q.length&&(U>=q.length||Y[z]!==q[U]))_.push({kind:"removed",oldChild:Q[z]}),z++;else if(K<Z.length)_.push({kind:"added",newChild:Z[K]}),K++;let H=!1;while($.firstChild)$.removeChild($.firstChild);for(let G of _)if(G.kind==="matched"){let N=(G.oldChild.textContent||"").match(/\S+/g)||[],W=(G.newChild.textContent||"").match(/\S+/g)||[],M=B1(N,W),F=Math.max(N.length,W.length);if((F>0?1-M.length/F:0)>0.5){H=!0;let y=G.oldChild.cloneNode(!0);y.classList.add("diff-block-removed"),$.appendChild(y),G.newChild.classList.add("diff-block-added"),$.appendChild(G.newChild)}else{if(V1(G.oldChild,G.newChild,!1))H=!0;$.appendChild(G.newChild)}}else if(G.kind==="removed"){H=!0;let N=G.oldChild.cloneNode(!0);N.classList.add("diff-block-removed"),$.appendChild(N)}else H=!0,G.newChild.classList.add("diff-block-added"),$.appendChild(G.newChild);return H}function q2(J,$){let Q=$?new Set(Array.from(J.querySelectorAll("[data-md]"))):new Set,Z=[],Y=[],X=document.createTreeWalker(J,NodeFilter.SHOW_TEXT,{acceptNode(_){let z=_.parentElement;if(!z)return NodeFilter.FILTER_REJECT;if(z.closest("svg, .select-none, [data-no-diff]"))return NodeFilter.FILTER_REJECT;if($){for(let K of Q)if(K.contains(_))return NodeFilter.FILTER_REJECT}return NodeFilter.FILTER_ACCEPT}}),q;while(q=X.nextNode()){let z=(q.nodeValue||"").match(/\S+|\s+/g);if(!z)continue;let K=0;for(let U of z)Z.push(U),Y.push({text:U,node:q,offset:K}),K+=U.length}return{words:Z,map:Y}}function V1(J,$,Q){let Z=q2(J,Q),Y=q2($,Q);if(Z.words.length===0&&Y.words.length===0)return!1;let{oldOps:X,newOps:q}=e0(Z.words,Y.words),_=X.some((F)=>F.type==="removed"),z=q.some((F)=>F.type==="added");if(!_&&!z)return!1;let K=[],U=[];for(let F of X)if(F.type==="same")K.push(F.index);for(let F of q)if(F.type==="same")U.push(F.index);let H=new Map;for(let F=0;F<K.length&&F<U.length;F++)H.set(K[F],U[F]);let G=[];{let F=[],L=-1;for(let y of X)if(y.type==="same"){if(F.length>0)G.push({text:F.join(""),anchorNewIdx:L>=0?H.get(L)??null:null}),F=[];L=y.index}else if(y.type==="removed")F.push(Z.words[y.index]);if(F.length>0)G.push({text:F.join(""),anchorNewIdx:L>=0?H.get(L)??null:null})}let N=new Map,W=new Map;for(let F of q){if(F.type!=="added")continue;let L=Y.map[F.index];if(!L?.node.parentNode)continue;let y=N.get(L.node);if(!y)y=[],N.set(L.node,y);y.push({start:L.offset,end:L.offset+L.text.length})}for(let F of G)if(F.anchorNewIdx===null){if(Y.map.length>0){let L=Y.map[0].node,y=W.get(L);if(!y)y=[],W.set(L,y);y.push({offset:0,text:F.text})}}else{let L=Y.map[F.anchorNewIdx];if(!L)continue;let y=W.get(L.node);if(!y)y=[],W.set(L.node,y);y.push({offset:L.offset+L.text.length,text:F.text})}let M=new Set([...N.keys(),...W.keys()]);for(let F of M)b$(F,N.get(F)||[],W.get(F)||[]);return!0}function b$(J,$,Q){if(!J.parentNode)return;let Z=J.nodeValue||"";$.sort((U,H)=>U.start-H.start);let Y=[];for(let U of $){let H=Y[Y.length-1];if(H&&U.start<=H.end)H.end=Math.max(H.end,U.end);else Y.push({...U})}Q.sort((U,H)=>U.offset-H.offset);let X=J.parentNode,q=document.createDocumentFragment(),_=0,z=0,K=0;while(_<=Z.length){let U=z<Y.length?Y[z].start:1/0,H=K<Q.length?Q[K].offset:1/0,G=Math.min(U,H);if(G===1/0){if(_<Z.length)q.appendChild(document.createTextNode(Z.slice(_)));break}let N=Math.max(G,_);if(N>_)q.appendChild(document.createTextNode(Z.slice(_,N))),_=N;while(K<Q.length&&Q[K].offset<=_){let W=document.createElement("span");W.className="diff-removed",W.textContent=Q[K].text,q.appendChild(W),K++}if(z<Y.length&&Y[z].start<=_){let W=Y[z],M=document.createElement("span");M.className="diff-added",M.textContent=Z.slice(_,W.end),q.appendChild(M),_=W.end,z++;while(K<Q.length&&Q[K].offset<=_){let F=document.createElement("span");F.className="diff-removed",F.textContent=Q[K].text,q.appendChild(F),K++}}}while(K<Q.length){let U=document.createElement("span");U.className="diff-removed",U.textContent=Q[K].text,q.appendChild(U),K++}X.replaceChild(q,J)}function G2(J,$){let Q=(J.getAttribute("data-md-source")||"").trim(),Z=($.getAttribute("data-md-source")||"").trim();if(Q===Z)return!1;let Y=Q.split(`
107
+ `}var a3=new Set(["CODE","SPAN","STRONG","EM","A","B","I","U","SMALL","SUB","SUP","MARK","ABBR"]);function R0(J,$,Q){if(i3(J)){let Z=o3(J);if(Z)$.push(Z,"");return}for(let Z of J.childNodes)if(Z.nodeType===Node.ELEMENT_NODE)s3(Z,$,Q);else if(Z.nodeType===Node.TEXT_NODE){let Y=Z.textContent?.trim();if(Y)$.push(Y,"")}}function i3(J){for(let $ of J.childNodes){if($.nodeType===Node.TEXT_NODE)continue;if($.nodeType===Node.ELEMENT_NODE){let Q=$;if(!a3.has(Q.tagName)||Q.hasAttribute("data-md"))return!1}}return J.childNodes.length>0}function o3(J){let $="";for(let Q of J.childNodes)if(Q.nodeType===Node.TEXT_NODE)$+=Q.textContent||"";else if(Q.nodeType===Node.ELEMENT_NODE){let Z=Q;if(Z.tagName==="CODE")$+="`"+(Z.textContent||"")+"`";else $+=Z.textContent||""}return $.trim()}function s3(J,$,Q){let Z=J.getAttribute("data-md");if(Z)switch(Z){case"section":return t3(J,$,Q);case"item":return n3(J,$);case"codeblock":return e3(J,$);case"callout":return $$(J,$);case"note":return J$(J,$);case"table":return Y$(J,$);case"checklist":return Q$(J,$);case"diff":return Z$(J,$);case"mermaid":return q$(J,$);case"choice":return X$(J,$);case"multichoice":return z$(J,$);case"choice-option":case"multichoice-option":return;case"userinput":return K$(J,$);case"rangeinput":return _$(J,$);case"checklist-item":return;case"filepreview":return U$(J,$);case"priority":return G$(J,$)}if(J.querySelector("button, input, select, textarea"))return;if(J.children.length>0)R0(J,$,Q);else{let Y=J.textContent?.trim();if(Y)$.push(Y,"")}}function t3(J,$,Q){let Z=J.getAttribute("data-md-title")||"Untitled",Y=Q===0?"##":"###";$.push(`${Y} ${Z}`,"");let X=J.querySelector(":scope > div:last-of-type");if(X)R0(X,$,Q+1)}function n3(J,$){let Q=J.getAttribute("data-md-label")||"",Z=J.getAttribute("data-md-status"),Y=J.getAttribute("data-md-badge"),X="-";if(Z==="done")X="- [x]";else if(Z)X="- [ ]";let q=`${X} **${Q}**`;if(Y)q+=` \`${Y}\``;$.push(q);let K=J.querySelector(".text-text-secondary");if(K){let z=[];R0(K,z,0);for(let _ of z)$.push(_?` ${_}`:"")}$.push("")}function e3(J,$){let Q=J.getAttribute("data-md-language")||"",Y=J.querySelector("code")?.textContent||"";$.push(`\`\`\`${Q}`,Y,"```","")}function $$(J,$){let Q=J.getAttribute("data-md-type")||"info",Z={info:"Info",warning:"Warning",danger:"Danger",tip:"Tip"},Y=H$(J.querySelector(".text-text-secondary")||J);$.push(`> **${Z[Q]||Q}:** ${Y}`,"")}function J$(J,$){let Q=J.textContent?.trim()||"";$.push(`> *${Q}*`,"")}function Y$(J,$){let Q=J.querySelector("table");if(!Q)return;let Z=[];for(let Y of Q.querySelectorAll("thead th"))Z.push(Y.textContent?.trim()||"");if(Z.length===0)return;$.push(`| ${Z.join(" | ")} |`),$.push(`| ${Z.map(()=>"---").join(" | ")} |`);for(let Y of Q.querySelectorAll("tbody tr")){let X=[];for(let q of Y.querySelectorAll("td"))X.push(q.textContent?.trim()||"");$.push(`| ${X.join(" | ")} |`)}$.push("")}function Q$(J,$){for(let Q of J.querySelectorAll("li")){let Z=Q.querySelector(".bg-accent-green")!==null,Y=Q.textContent?.trim()||"";$.push(`- [${Z?"x":" "}] ${Y}`)}$.push("")}function Z$(J,$){let Q=J.getAttribute("data-md-language")||"";$.push(`\`\`\`diff${Q?` (${Q})`:""}`);for(let Z of J.querySelectorAll("[class*='flex']")){let Y=Z.querySelector(".text-accent-red")?"-":Z.querySelector(".text-accent-green")?"+":" ",X=Z.querySelector("code");if(X)$.push(`${Y} ${X.textContent}`)}$.push("```","")}function q$(J,$){let Q=J.getAttribute("data-md-source")||"";if(Q)$.push("```mermaid",Q,"```","")}function X$(J,$){let Q=J.getAttribute("data-md-label")||"";$.push(`**${Q}:**`);for(let Z of J.querySelectorAll("[data-md='choice-option']")){let Y=Z.getAttribute("data-md-label")||Z.textContent?.trim()||"",X=Z.querySelector(".bg-accent-amber")!==null;$.push(`- ${X?"(x)":"( )"} ${Y}`)}$.push("")}function z$(J,$){let Q=J.getAttribute("data-md-label")||"";$.push(`**${Q}:**`);for(let Z of J.querySelectorAll("[data-md='multichoice-option']")){let Y=Z.getAttribute("data-md-label")||Z.textContent?.trim()||"",X=Z.querySelector(".bg-accent-amber")!==null;$.push(`- [${X?"x":" "}] ${Y}`)}$.push("")}function K$(J,$){let Q=J.getAttribute("data-md-label")||"",Y=J.querySelector("textarea")?.value?.trim()||"";$.push(`**${Q}:** ${Y||"_empty_"}`,"")}function _$(J,$){let Q=J.getAttribute("data-md-label")||"",Z=J.querySelector("input[type='range']"),X=J.querySelector(".font-mono")?.textContent?.trim()||Z?.value||"—";$.push(`**${Q}:** ${X}`,"")}function U$(J,$){let Q=J.getAttribute("data-md-path")||"",Z=J.getAttribute("data-md-lines")||"",X=J.querySelector("code")?.textContent||"",q=Q.split(".").pop()||"",K=A0[q]||"",z=Z?`${Q} (L${Z})`:Q;$.push(z,"",`\`\`\`${K}`,X,"```","")}function G$(J,$){}function H$(J){return J?.textContent?.trim()||""}import A$,{useEffect as n1,useState as Q1,useRef as b1}from"react";import{useEffect as W$,useState as F$,useRef as y$,useContext as N$}from"react";import{jsxDEV as z1,Fragment as J2}from"react/jsx-dev-runtime";function T$(J){return J.label||`Round ${J.revision}`}function O$(J){let $=Date.now()-new Date(J).getTime(),Q=Math.floor($/1000);if(Q<60)return"just now";let Z=Math.floor(Q/60);if(Z<60)return`${Z}m ago`;let Y=Math.floor(Z/60);if(Y<24)return`${Y}h ago`;return`${Math.floor(Y/24)}d ago`}function U0({value:J,onChange:$,accent:Q="default",className:Z}){let{currentRevision:Y,revisions:X}=N$(s1),[q,K]=F$(!1),z=y$(null);W$(()=>{if(!q)return;let G=(H)=>{if(z.current&&!z.current.contains(H.target))K(!1)};return document.addEventListener("mousedown",G),()=>document.removeEventListener("mousedown",G)},[q]);let _=X.find((G)=>G.revision===J);return z1("div",{className:"relative",ref:z,children:[z1("button",{onClick:()=>K(!q),className:`flex items-center gap-1.5 text-[12px] font-body font-medium px-2 py-1 rounded-md transition-colors hover:bg-bg-elevated ${{default:"text-text-secondary hover:text-text-primary",red:"text-accent-red",green:"text-accent-green",amber:"text-accent-amber bg-highlight-selected"}[Q]} ${Z||""}`,children:[_?T$(_):`Round ${J}`,z1("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",className:`text-text-tertiary transition-transform duration-200 ${q?"rotate-180":""}`,children:z1("path",{d:"M2.5 4l2.5 2.5L7.5 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),q&&z1("div",{className:"absolute top-full left-0 mt-1 w-64 bg-bg-elevated border border-border-hover rounded-lg shadow-lg z-50 py-1 max-h-80 overflow-y-auto",children:[...X].reverse().map((G)=>z1("button",{onClick:()=>{$(G.revision),K(!1)},className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] font-body transition-colors ${G.revision===J?"bg-bg-surface text-text-primary":"text-text-secondary hover:bg-bg-surface hover:text-text-primary"}`,children:[z1("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${G.revision===Y?"bg-accent-green":G.hasFeedback?"bg-accent-amber":"bg-border-hover"}`},void 0,!1,void 0,this),z1("span",{className:"flex-1 text-left truncate",children:G.label?z1(J2,{children:[G.label," ",z1("span",{className:"text-text-tertiary",children:["#",G.revision]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):z1(J2,{children:["Round ",G.revision]},void 0,!0,void 0,this)},void 0,!1,void 0,this),z1("span",{className:"text-[10px] text-text-tertiary flex-shrink-0",children:G.revision===Y?"current":G.hasFeedback?"sent":O$(G.createdAt)},void 0,!1,void 0,this)]},G.revision,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function S1(J,$){let Q=J.length,Z=$.length;if(Q===0||Z===0)return[];let Y=Array.from({length:Q+1},()=>Array(Z+1).fill(0));for(let z=1;z<=Q;z++)for(let _=1;_<=Z;_++)Y[z][_]=J[z-1]===$[_-1]?Y[z-1][_-1]+1:Math.max(Y[z-1][_],Y[z][_-1]);let X=[],q=Q,K=Z;while(q>0&&K>0)if(J[q-1]===$[K-1])X.unshift(J[q-1]),q--,K--;else if(Y[q-1][K]>Y[q][K-1])q--;else K--;return X}function Y2(J){let $=[],Q=[],Z=document.createTreeWalker(J,NodeFilter.SHOW_TEXT,{acceptNode(X){let q=X.parentElement;if(!q)return NodeFilter.FILTER_REJECT;if(q.closest("svg, .select-none, [data-no-diff]"))return NodeFilter.FILTER_REJECT;return NodeFilter.FILTER_ACCEPT}}),Y;while(Y=Z.nextNode()){let q=(Y.nodeValue||"").match(/\S+|\s+/g);if(!q)continue;let K=0;for(let z of q)$.push(z),Q.push({text:z,node:Y,offset:K}),K+=z.length}return{words:$,map:Q}}function Q5(J,$){if(J.length>5000||$.length>5000)return B$(J,$);return q2(J,$)}function q2(J,$){let Q=j0(J,$),Z=[],Y=[],X=0,q=0,K=0;while(X<J.length||q<$.length)if(K<Q.length&&X<J.length&&q<$.length&&J[X]===Q[K]&&$[q]===Q[K])Z.push({type:"same",index:X}),Y.push({type:"same",index:q}),X++,q++,K++;else if(X<J.length&&(K>=Q.length||J[X]!==Q[K]))Z.push({type:"removed",index:X}),X++;else if(q<$.length)Y.push({type:"added",index:q}),q++;return{oldOps:Z,newOps:Y}}function j0(J,$){let Q=J.length,Z=$.length;if(Q===0||Z===0)return[];if(Q===1)return $.includes(J[0])?[J[0]]:[];if(Z===1)return J.includes($[0])?[$[0]]:[];if(Q*Z<=1e6)return S1(J,$);let Y=Math.floor(Q/2),X=J.slice(0,Y),q=J.slice(Y),K=Q2(X,$),z=Q2([...q].reverse(),[...$].reverse()),_=0,U=0;for(let F=0;F<=Z;F++){let W=K[F]+z[Z-F];if(W>_)_=W,U=F}let G=$.slice(0,U),H=$.slice(U);return[...j0(X,G),...j0(q,H)]}function Q2(J,$){let Q=$.length,Z=Array(Q+1).fill(0),Y=Array(Q+1).fill(0);for(let X=0;X<J.length;X++){for(let q=1;q<=Q;q++)Y[q]=J[X]===$[q-1]?Z[q-1]+1:Math.max(Z[q],Y[q-1]);[Z,Y]=[Y,Z],Y.fill(0)}return Z}function B$(J,$){let Z=(W)=>{let B=[];for(let T=0;T<W.length;T+=200){let M=Math.min(T+200,W.length);B.push({start:T,end:M,text:W.slice(T,M).join("")})}return B},Y=Z(J),X=Z($),q=Y.map((W)=>W.text),K=X.map((W)=>W.text),z=j0(q,K),_=[],U=[],G=0,H=0,F=0;while(G<Y.length||H<X.length)if(F<z.length&&G<Y.length&&H<X.length&&q[G]===z[F]&&K[H]===z[F]){for(let W=Y[G].start;W<Y[G].end;W++)_.push({type:"same",index:W});for(let W=X[H].start;W<X[H].end;W++)U.push({type:"same",index:W});G++,H++,F++}else if(G<Y.length&&(F>=z.length||q[G]!==z[F]))if(H<X.length&&(F>=z.length||K[H]!==z[F])){let W=q2(J.slice(Y[G].start,Y[G].end),$.slice(X[H].start,X[H].end));for(let B of W.oldOps)_.push({type:B.type,index:B.index+Y[G].start});for(let B of W.newOps)U.push({type:B.type,index:B.index+X[H].start});G++,H++}else{for(let W=Y[G].start;W<Y[G].end;W++)_.push({type:"removed",index:W});G++}else if(H<X.length){for(let W=X[H].start;W<X[H].end;W++)U.push({type:"added",index:W});H++}return{oldOps:_,newOps:U}}function Z2(J,$,Q){let Z=new Map;for(let Y of J){if(Y.type==="same")continue;let X=$[Y.index];if(!X||!X.node.parentNode)continue;let q=Z.get(X.node);if(!q)q=[],Z.set(X.node,q);q.push({offset:X.offset,length:X.text.length})}for(let[Y,X]of Z){if(!Y.parentNode)continue;let q=Y.nodeValue||"";X.sort((G,H)=>G.offset-H.offset);let K=[];for(let G of X){let H=K[K.length-1];if(H&&G.offset<=H.offset+H.length)H.length=Math.max(H.length,G.offset+G.length-H.offset);else K.push({...G})}let z=Y.parentNode,_=document.createDocumentFragment(),U=0;for(let G of K){if(G.offset>U)_.appendChild(document.createTextNode(q.slice(U,G.offset)));let H=document.createElement("span");H.className=Q,H.textContent=q.slice(G.offset,G.offset+G.length),_.appendChild(H),U=G.offset+G.length}if(U<q.length)_.appendChild(document.createTextNode(q.slice(U)));z.replaceChild(_,Y)}}function X2(J,$){let Q=M$(J,$),Z=Y2(J),Y=Y2($),{oldOps:X,newOps:q}=Q5(Z.words,Y.words),K=X.some((z)=>z.type==="removed")||q.some((z)=>z.type==="added");return Z2(X,Z.map,"diff-removed"),Z2(q,Y.map,"diff-added"),K||Q}function M$(J,$){let Q=Array.from(J.querySelectorAll('[data-md="mermaid"]')),Z=Array.from($.querySelectorAll('[data-md="mermaid"]')),Y=!1,X=Math.max(Q.length,Z.length);for(let q=0;q<X;q++){let K=Q[q],z=Z[q];if(!K&&z){z.classList.add("diff-block-added"),z.style.position="relative",Y=!0;continue}if(K&&!z){K.classList.add("diff-block-removed"),K.style.position="relative",Y=!0;continue}if(!K||!z)continue;let _=(K.getAttribute("data-md-source")||"").trim(),U=(z.getAttribute("data-md-source")||"").trim();if(_===U)continue;Y=!0,K.style.borderLeft="3px solid var(--color-accent-red)",K.style.paddingLeft="8px",z.style.borderLeft="3px solid var(--color-accent-green)",z.style.paddingLeft="8px";let G=_.split(`
108
+ `),H=U.split(`
109
+ `),F=S1(G,H),W=(B,T,M)=>{let y=document.createElement("div");y.className="mt-2 bg-bg-code rounded-md overflow-hidden text-tiny font-mono",y.setAttribute("data-no-diff","true");let L=0,C=0;while(C<B.length){let R=document.createElement("div");if(R.className="px-3 py-0.5 whitespace-pre-wrap",L<T.length&&B[C]===T[L])R.textContent=" "+B[C],C++,L++;else R.classList.add(M==="old"?"diff-removed":"diff-added"),R.textContent=(M==="old"?"- ":"+ ")+B[C],C++;y.appendChild(R)}return y};K.appendChild(W(G,F,"old")),z.appendChild(W(H,F,"new"))}return Y}function Z5(J){let $=[],Q=J.querySelectorAll(":scope > [data-md]");for(let Z of Q)$.push(G0(Z));if($.length===0){let Z=J.querySelectorAll("[data-md]"),Y=new Set;for(let X of Z){let q=X.parentElement?.closest("[data-md]");if(q&&J.contains(q))continue;if(Y.has(X))continue;Y.add(X),$.push(G0(X))}}return $}function G0(J){let $=J.getAttribute("data-md")||"unknown",Q=L$(J,$),Z=[];if($==="section"){let Y=J.querySelector(":scope > div.mt-6, :scope > div:last-child");if(Y)for(let X of Y.querySelectorAll(":scope > [data-md]"))Z.push(G0(X))}else if($==="table")for(let Y of J.querySelectorAll(":scope table > tbody > tr"))Z.push({key:"tr:"+(Y.textContent||"").slice(0,80),type:"tr",element:Y,children:[]});else if($==="checklist")for(let Y of J.querySelectorAll(":scope > [data-md='checklist-item']"))Z.push(G0(Y));else for(let Y of J.querySelectorAll("[data-md]"))if(Y.parentElement?.closest("[data-md]")===J)Z.push(G0(Y));return{key:Q,type:$,element:J,children:Z}}function L$(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 q5(J,$){let Q=J.map((_)=>_.key),Z=$.map((_)=>_.key),Y=S1(Q,Z),X=[],q=0,K=0,z=0;while(q<J.length||K<$.length)if(z<Y.length&&q<J.length&&K<$.length&&Q[q]===Y[z]&&Z[K]===Y[z]){let _=J[q],U=$[K],G=_.children.length>0||U.children.length>0?q5(_.children,U.children):void 0;X.push({kind:"matched",oldBlock:_,newBlock:U,childMatches:G}),q++,K++,z++}else if(q<J.length&&(z>=Y.length||Q[q]!==Y[z]))X.push({kind:"removed",oldBlock:J[q]}),q++;else if(K<$.length)X.push({kind:"added",newBlock:$[K]}),K++;return X}function K2(J){let $=document.createDocumentFragment(),Q=!1;for(let Z of J)if(Z.kind==="removed")Q=!0,$.appendChild(_2(Z.oldBlock.element));else if(Z.kind==="added")Q=!0,$.appendChild(P$(Z.newBlock.element));else{let Y=Z.newBlock.element.cloneNode(!0),X=Z.newBlock.type;if(X==="mermaid"){if(W2(Z.oldBlock.element,Y))Q=!0}else if(Z.childMatches&&Z.childMatches.length>0&&(X==="table"||X==="checklist")){if(G2(Y,Z.childMatches,X))Q=!0}else if(Z.childMatches&&Z.childMatches.length>0){if(U2(Z.oldBlock,Y,Z.childMatches,X))Q=!0}else if(X==="markdown"){if(H2(Z.oldBlock.element,Y))Q=!0}else if(v1(Z.oldBlock.element,Y,!1))Q=!0;$.appendChild(Y)}return{fragment:$,hasChanges:Q}}function _2(J){let $=J.cloneNode(!0);return $.classList.add("diff-block-removed"),$.style.position="relative",X5($,"Removed","var(--color-accent-red)"),$}function P$(J){let $=J.cloneNode(!0);return $.classList.add("diff-block-added"),$.style.position="relative",X5($,"Added","var(--color-accent-green)"),$}function U2(J,$,Q,Z){let Y=!1,X=S$(J,$),q,K;if(Z==="section"){let z=J.element.querySelector(":scope > div:first-child"),_=$.querySelector(":scope > div:first-child");if(z&&_){if(v1(z,_,!1))Y=!0}q=J.element.querySelector(":scope > div.mt-6, :scope > div:last-child"),K=$.querySelector(":scope > div.mt-6, :scope > div:last-child")}else q=J.element,K=$;if(!q||!K)return Y;for(let z of Q)if(z.kind==="matched"){let _=X.newMap.get(z.newBlock.element);if(_){if(z.newBlock.type==="mermaid"){if(W2(z.oldBlock.element,_))Y=!0}else if(z.childMatches&&z.childMatches.length>0&&(z.newBlock.type==="table"||z.newBlock.type==="checklist")){if(G2(_,z.childMatches,z.newBlock.type))Y=!0}else if(z.childMatches&&z.childMatches.length>0){if(U2(z.oldBlock,_,z.childMatches,z.newBlock.type))Y=!0}else if(z.newBlock.type==="markdown"){if(H2(z.oldBlock.element,_))Y=!0}else if(v1(z.oldBlock.element,_,!1))Y=!0}}else if(z.kind==="removed"){Y=!0;let _=_2(z.oldBlock.element),U=w$(Q,z,X.newMap);K.insertBefore(_,U)}else if(z.kind==="added"){Y=!0;let _=X.newMap.get(z.newBlock.element);if(_)_.classList.add("diff-block-added"),_.style.position="relative",X5(_,"Added","var(--color-accent-green)")}if(v1(q,K,!0))Y=!0;return Y}function G2(J,$,Q){let Z=Q==="table"?J.querySelector(":scope table > tbody"):J;if(!Z)return!1;let Y=!1;Z.innerHTML="";for(let X of $)if(X.kind==="removed"){Y=!0;let q=X.oldBlock.element.cloneNode(!0);q.classList.add(Q==="table"?"diff-row-removed":"diff-item-removed"),Z.appendChild(q)}else if(X.kind==="added"){Y=!0;let q=X.newBlock.element.cloneNode(!0);q.classList.add(Q==="table"?"diff-row-added":"diff-item-added"),Z.appendChild(q)}else{let q=X.newBlock.element.cloneNode(!0);if(v1(X.oldBlock.element,q,!1))Y=!0;Z.appendChild(q)}return Y}function S$(J,$){let Q=new Map,Z=J.element.querySelectorAll("[data-md]"),Y=$.querySelectorAll("[data-md]");return{newMap:{get(X){return b$($,X)}}}}function b$(J,$){let Q=$.getAttribute("data-md");if(!Q)return null;let Z=$.getAttribute("data-md-label"),Y=$.getAttribute("data-md-title"),X=`[data-md="${Q}"]`;if(Y)X+=`[data-md-title="${CSS.escape(Y)}"]`;else if(Z)X+=`[data-md-label="${CSS.escape(Z)}"]`;let q=J.querySelectorAll(X);if(q.length===1)return q[0];let K=($.textContent||"").slice(0,100),z=null,_=-1;for(let U of q){let G=(U.textContent||"").slice(0,100),H=0;for(let F=0;F<Math.min(K.length,G.length);F++)if(K[F]===G[F])H++;if(H>_)_=H,z=U}return z}function w$(J,$,Q){let Z=J.indexOf($);for(let Y=Z+1;Y<J.length;Y++){let X=J[Y];if((X.kind==="matched"||X.kind==="added")&&X.newBlock)return Q.get(X.newBlock.element)||null}return null}function H2(J,$){let Q=Array.from(J.children),Z=Array.from($.children);if(Q.length===0&&Z.length===0)return v1(J,$,!1);let Y=Q.map((H)=>H.tagName.toLowerCase()),X=Z.map((H)=>H.tagName.toLowerCase()),q=S1(Y,X),K=[],z=0,_=0,U=0;while(z<Q.length||_<Z.length)if(U<q.length&&z<Q.length&&_<Z.length&&Y[z]===q[U]&&X[_]===q[U])K.push({kind:"matched",oldChild:Q[z],newChild:Z[_]}),z++,_++,U++;else if(z<Q.length&&(U>=q.length||Y[z]!==q[U]))K.push({kind:"removed",oldChild:Q[z]}),z++;else if(_<Z.length)K.push({kind:"added",newChild:Z[_]}),_++;let G=!1;while($.firstChild)$.removeChild($.firstChild);for(let H of K)if(H.kind==="matched"){let F=(H.oldChild.textContent||"").match(/\S+/g)||[],W=(H.newChild.textContent||"").match(/\S+/g)||[],B=S1(F,W),T=Math.max(F.length,W.length);if((T>0?1-B.length/T:0)>0.5){G=!0;let y=H.oldChild.cloneNode(!0);y.classList.add("diff-block-removed"),$.appendChild(y),H.newChild.classList.add("diff-block-added"),$.appendChild(H.newChild)}else{if(v1(H.oldChild,H.newChild,!1))G=!0;$.appendChild(H.newChild)}}else if(H.kind==="removed"){G=!0;let F=H.oldChild.cloneNode(!0);F.classList.add("diff-block-removed"),$.appendChild(F)}else G=!0,H.newChild.classList.add("diff-block-added"),$.appendChild(H.newChild);return G}function z2(J,$){let Q=$?new Set(Array.from(J.querySelectorAll("[data-md]"))):new Set,Z=[],Y=[],X=document.createTreeWalker(J,NodeFilter.SHOW_TEXT,{acceptNode(K){let z=K.parentElement;if(!z)return NodeFilter.FILTER_REJECT;if(z.closest("svg, .select-none, [data-no-diff]"))return NodeFilter.FILTER_REJECT;if($){for(let _ of Q)if(_.contains(K))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 _=0;for(let U of z)Z.push(U),Y.push({text:U,node:q,offset:_}),_+=U.length}return{words:Z,map:Y}}function v1(J,$,Q){let Z=z2(J,Q),Y=z2($,Q);if(Z.words.length===0&&Y.words.length===0)return!1;let{oldOps:X,newOps:q}=Q5(Z.words,Y.words),K=X.some((T)=>T.type==="removed"),z=q.some((T)=>T.type==="added");if(!K&&!z)return!1;let _=[],U=[];for(let T of X)if(T.type==="same")_.push(T.index);for(let T of q)if(T.type==="same")U.push(T.index);let G=new Map;for(let T=0;T<_.length&&T<U.length;T++)G.set(_[T],U[T]);let H=[];{let T=[],M=-1;for(let y of X)if(y.type==="same"){if(T.length>0)H.push({text:T.join(""),anchorNewIdx:M>=0?G.get(M)??null:null}),T=[];M=y.index}else if(y.type==="removed")T.push(Z.words[y.index]);if(T.length>0)H.push({text:T.join(""),anchorNewIdx:M>=0?G.get(M)??null:null})}let F=new Map,W=new Map;for(let T of q){if(T.type!=="added")continue;let M=Y.map[T.index];if(!M?.node.parentNode)continue;let y=F.get(M.node);if(!y)y=[],F.set(M.node,y);y.push({start:M.offset,end:M.offset+M.text.length})}for(let T of H)if(T.anchorNewIdx===null){if(Y.map.length>0){let M=Y.map[0].node,y=W.get(M);if(!y)y=[],W.set(M,y);y.push({offset:0,text:T.text})}}else{let M=Y.map[T.anchorNewIdx];if(!M)continue;let y=W.get(M.node);if(!y)y=[],W.set(M.node,y);y.push({offset:M.offset+M.text.length,text:T.text})}let B=new Set([...F.keys(),...W.keys()]);for(let T of B)C$(T,F.get(T)||[],W.get(T)||[]);return!0}function C$(J,$,Q){if(!J.parentNode)return;let Z=J.nodeValue||"";$.sort((U,G)=>U.start-G.start);let Y=[];for(let U of $){let G=Y[Y.length-1];if(G&&U.start<=G.end)G.end=Math.max(G.end,U.end);else Y.push({...U})}Q.sort((U,G)=>U.offset-G.offset);let X=J.parentNode,q=document.createDocumentFragment(),K=0,z=0,_=0;while(K<=Z.length){let U=z<Y.length?Y[z].start:1/0,G=_<Q.length?Q[_].offset:1/0,H=Math.min(U,G);if(H===1/0){if(K<Z.length)q.appendChild(document.createTextNode(Z.slice(K)));break}let F=Math.max(H,K);if(F>K)q.appendChild(document.createTextNode(Z.slice(K,F))),K=F;while(_<Q.length&&Q[_].offset<=K){let W=document.createElement("span");W.className="diff-removed",W.textContent=Q[_].text,q.appendChild(W),_++}if(z<Y.length&&Y[z].start<=K){let W=Y[z],B=document.createElement("span");B.className="diff-added",B.textContent=Z.slice(K,W.end),q.appendChild(B),K=W.end,z++;while(_<Q.length&&Q[_].offset<=K){let T=document.createElement("span");T.className="diff-removed",T.textContent=Q[_].text,q.appendChild(T),_++}}}while(_<Q.length){let U=document.createElement("span");U.className="diff-removed",U.textContent=Q[_].text,q.appendChild(U),_++}X.replaceChild(q,J)}function W2(J,$){let Q=(J.getAttribute("data-md-source")||"").trim(),Z=($.getAttribute("data-md-source")||"").trim();if(Q===Z)return!1;let Y=Q.split(`
110
110
  `),X=Z.split(`
111
- `),q=B1(Y,X),_=[],z=0,K=0,U=0;while(z<Y.length||K<X.length)if(U<q.length&&z<Y.length&&K<X.length&&Y[z]===q[U]&&X[K]===q[U])_.push({type:"same",line:Y[z]}),z++,K++,U++;else if(z<Y.length&&(U>=q.length||Y[z]!==q[U]))_.push({type:"removed",line:Y[z]}),z++;else if(K<X.length)_.push({type:"added",line:X[K]}),K++;let H=document.createElement("div");H.className="mt-2 bg-bg-code rounded-md overflow-hidden text-tiny font-mono",H.setAttribute("data-no-diff","true");for(let G of _){let N=document.createElement("div");if(N.className="px-3 py-0.5 whitespace-pre-wrap",G.type==="removed")N.classList.add("diff-removed"),N.textContent="- "+G.line;else if(G.type==="added")N.classList.add("diff-added"),N.textContent="+ "+G.line;else N.textContent=" "+G.line;H.appendChild(N)}return $.appendChild(H),!0}function Y5(J,$,Q){let Z=document.createElement("span");Z.className="diff-block-label",Z.textContent=$,Z.style.color=Q,Z.style.backgroundColor=`color-mix(in srgb, ${Q} 12%, transparent)`,J.appendChild(Z)}import{jsxDEV as D}from"react/jsx-dev-runtime";function H2({initialLeft:J,initialRight:$,sessionId:Q,onExit:Z}){let[Y,X]=Y1(J),[q,_]=Y1($),[z,K]=Y1("unified"),[U,H]=Y1(!0),[G,N]=Y1(!1);return D("div",{className:"flex flex-col h-screen",children:[D("div",{className:"flex items-center justify-between px-6 py-3 border-b border-border-subtle bg-bg-surface flex-shrink-0",children:[D("div",{className:"flex items-center gap-3",children:[D("span",{className:"text-[13px] font-body font-medium text-text-primary",children:"Compare"},void 0,!1,void 0,this),D(Z0,{value:Y,onChange:X,accent:"red"},void 0,!1,void 0,this),D("span",{className:"text-text-tertiary text-[13px]",children:"→"},void 0,!1,void 0,this),D(Z0,{value:q,onChange:_,accent:"green"},void 0,!1,void 0,this),G&&!U&&D("span",{className:"text-[11px] font-body text-text-tertiary bg-bg-elevated px-2 py-0.5 rounded",children:"No changes"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),D("div",{className:"flex items-center gap-4",children:[D("div",{className:"flex items-center bg-bg-elevated rounded-md p-0.5",children:[D("button",{onClick:()=>K("unified"),className:`text-[11px] font-body px-2.5 py-1 rounded transition-colors ${z==="unified"?"bg-bg-surface text-text-primary font-medium shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Unified"},void 0,!1,void 0,this),D("button",{onClick:()=>K("side-by-side"),className:`text-[11px] font-body px-2.5 py-1 rounded transition-colors ${z==="side-by-side"?"bg-bg-surface text-text-primary font-medium shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Side-by-side"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z==="side-by-side"&&D(w$,{},void 0,!1,void 0,this),D("button",{onClick:Z,className:"text-[12px] font-body font-medium text-text-secondary hover:text-text-primary px-3 py-1.5 rounded-md hover:bg-bg-elevated transition-colors",children:"Exit Compare"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),z==="unified"?D(R$,{sessionId:Q,leftRev:Y,rightRev:q,onDiffResult:(W,M)=>{N(W),H(M)}},`unified-${Y}-${q}`,!1,void 0,this):D(C$,{sessionId:Q,leftRev:Y,rightRev:q,onDiffResult:(W,M)=>{N(W),H(M)}},`sbs-${Y}-${q}`,!1,void 0,this)]},void 0,!0,void 0,this)}function w$(){let[J,$]=Y1(!0);return c1(()=>{return document.documentElement.dataset.syncScroll=J?"1":"0",()=>{delete document.documentElement.dataset.syncScroll}},[J]),D("label",{className:"flex items-center gap-1.5 cursor-pointer select-none",children:[D("input",{type:"checkbox",checked:J,onChange:(Q)=>$(Q.target.checked),className:"accent-accent-amber w-3.5 h-3.5"},void 0,!1,void 0,this),D("span",{className:"text-[11px] font-body text-text-secondary",children:"Sync scroll"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function R$({sessionId:J,leftRev:$,rightRev:Q,onDiffResult:Z}){let Y=L1(null),X=L1(null),q=L1(null),[_,z]=Y1(!1),[K,U]=Y1(!1),[H,G]=Y1(!1);return c1(()=>{if(!_||!K||H)return;if(!Y.current||!X.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!Y.current||!X.current||!q.current)return;let N=$5(Y.current),W=$5(X.current),M=J5(N,W),{fragment:F,hasChanges:L}=X2(M);q.current.innerHTML="",q.current.appendChild(F),G(!0),Z(!0,L)})})},[_,K,H]),D("div",{className:"flex-1 min-h-0 overflow-y-auto",children:[D("div",{style:{position:"absolute",left:-9999,visibility:"hidden",pointerEvents:"none",width:720},children:[D(R0,{ref:Y,sessionId:J,revision:$,onReady:()=>z(!0)},void 0,!1,void 0,this),D(R0,{ref:X,sessionId:J,revision:Q,onReady:()=>U(!0)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),D("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:[!H&&D("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-body",children:"Loading..."},void 0,!1,void 0,this),D("div",{ref:q},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function C$({sessionId:J,leftRev:$,rightRev:Q,onDiffResult:Z}){let Y=L1(null),X=L1(null),[q,_]=Y1(!1),[z,K]=Y1(!1),[U,H]=Y1(!1),G=L1(null),N=L1(null),W=L1(!1);return c1(()=>{if(!q||!z||U)return;if(!Y.current||!X.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!Y.current||!X.current)return;let M=Z2(Y.current,X.current);H(!0),Z(!0,M)})})},[q,z,U]),c1(()=>{let M=G.current,F=N.current;if(!M||!F)return;let L=(R,m)=>{if(document.documentElement.dataset.syncScroll==="0")return;if(W.current)return;W.current=!0;let k=R.scrollHeight-R.clientHeight,V=m.scrollHeight-m.clientHeight;if(k>0&&V>0)m.scrollTop=R.scrollTop/k*V;requestAnimationFrame(()=>{W.current=!1})},y=()=>L(M,F),S=()=>L(F,M);return M.addEventListener("scroll",y),F.addEventListener("scroll",S),()=>{M.removeEventListener("scroll",y),F.removeEventListener("scroll",S)}},[]),D("div",{className:"flex flex-1 min-h-0",children:[D("div",{ref:G,className:"w-1/2 overflow-y-auto border-r border-border-subtle",children:D("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:D(R0,{ref:Y,sessionId:J,revision:$,onReady:()=>_(!0)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),D("div",{ref:N,className:"w-1/2 overflow-y-auto",children:D("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:D(R0,{ref:X,sessionId:J,revision:Q,onReady:()=>K(!0)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var R0=A$.forwardRef(({sessionId:J,revision:$,onReady:Q},Z)=>{let[Y,X]=Y1(null),[q,_]=Y1(null),[z,K]=Y1(!0);if(c1(()=>{K(!0),_(null),import(`/api/session/${J}/plan.js?rev=${$}&t=${Date.now()}`).then((U)=>{X(()=>U.default),K(!1)}).catch((U)=>{_(U.message),K(!1)})},[J,$]),c1(()=>{if(!Y)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{Q()})})},[Y]),z)return D("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-body",children:"Loading..."},void 0,!1,void 0,this);if(q)return D("div",{className:"bg-accent-red-muted rounded-lg p-5",children:[D("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Error"},void 0,!1,void 0,this),D("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:q},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(!Y)return D("div",{className:"text-text-tertiary text-center py-8 font-body text-body",children:"No plan loaded"},void 0,!1,void 0,this);return D("div",{ref:Z,children:D(Y,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)});import{jsxDEV as O,Fragment as Q5}from"react/jsx-dev-runtime";var I1=W2({activeView:{type:"plan"},setActiveView:()=>{},openFiles:[],closeFile:()=>{}}),h1=W2({currentRevision:1,selectedRevision:1,revisions:[],setSelectedRevision:()=>{},isReadOnly:!1,compareRevision:null,setCompareRevision:()=>{}});function O2(){let[J,$]=Q1(()=>localStorage.getItem("canvas-theme")||document.documentElement.dataset.theme||"dark");return O("button",{onClick:()=>{let Z=J==="dark"?"light":"dark";document.documentElement.dataset.theme=Z,localStorage.setItem("canvas-theme",Z),$(Z)},className:"w-7 h-7 flex items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:J==="dark"?"Switch to light theme":"Switch to dark theme",children:J==="dark"?O("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[O("circle",{cx:"12",cy:"12",r:"5"},void 0,!1,void 0,this),O("line",{x1:"12",y1:"1",x2:"12",y2:"3"},void 0,!1,void 0,this),O("line",{x1:"12",y1:"21",x2:"12",y2:"23"},void 0,!1,void 0,this),O("line",{x1:"4.22",y1:"4.22",x2:"5.64",y2:"5.64"},void 0,!1,void 0,this),O("line",{x1:"18.36",y1:"18.36",x2:"19.78",y2:"19.78"},void 0,!1,void 0,this),O("line",{x1:"1",y1:"12",x2:"3",y2:"12"},void 0,!1,void 0,this),O("line",{x1:"21",y1:"12",x2:"23",y2:"12"},void 0,!1,void 0,this),O("line",{x1:"4.22",y1:"19.78",x2:"5.64",y2:"18.36"},void 0,!1,void 0,this),O("line",{x1:"18.36",y1:"5.64",x2:"19.78",y2:"4.22"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):O("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:O("path",{d:"M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function F2(){let{currentRevision:J,selectedRevision:$,revisions:Q,setSelectedRevision:Z,setCompareRevision:Y}=g1.useContext(h1);if(Q.length<=1){let _=Q[0]?.label||`Round ${J}`;return O("span",{className:"text-[11px] text-text-tertiary font-body",children:_},void 0,!1,void 0,this)}return O("div",{className:"flex flex-col gap-1",children:[O(Z0,{value:$,onChange:Z,accent:$===J?"default":"amber"},void 0,!1,void 0,this),O("button",{onClick:()=>{let _=Q.find((K)=>K.revision===$)?.sourceFile,z;if($===J)z=[...Q].reverse().find((U)=>U.revision<J&&(!_||U.sourceFile===_))?.revision??Math.max(1,J-1);else z=$;Y({left:z,right:J})},className:"text-[11px] font-body font-medium px-2 py-0.5 rounded-md text-accent-blue hover:bg-accent-blue-muted transition-colors self-start",children:"Compare"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function g$(){let J=window.location.pathname.replace("/s/","")||"",[$,Q]=Q1(1),[Z,Y]=Q1(1),[X,q]=Q1([]),[_,z]=Q1(null),[K,U]=Q1(!1),[H,G]=Q1(!1),[N,W]=Q1({type:"plan"}),[M,F]=Q1([]),L=d1(null),[y,S]=Q1(),[R,m]=Q1(!1),[k,V]=Q1(!1),[w,I]=Q1(!1);X0(()=>{let j=["Agent Canvas"];if(y){let i=y.replace(/\/+$/,"").split("/");j.push(i[i.length-1]||J)}else if(J)j.push(J);if(N.type==="file")j.push(N.path.split("/").pop()||N.path);else if(_)j.push("Compare");document.title=j.join(" — ")},[J,y,N,_]);let T=d1(new Map),B=X.find((j)=>j.revision===Z),c=Z!==$||!!B?.hasFeedback,o=C0((j)=>{if(T.current.set(N.type==="plan"?"plan":`file:${N.path}`,window.scrollY),W(j),j.type==="file")F((i)=>i.includes(j.path)?i:[...i,j.path])},[N]),Z1=C0((j)=>{T.current.delete(`file:${j}`),F((i)=>i.filter((b)=>b!==j)),W((i)=>{if(i.type==="file"&&i.path===j)return T.current.set(`file:${j}`,window.scrollY),{type:"plan"};return i})},[]);m$(()=>{let j=N.type==="plan"?"plan":`file:${N.path}`;window.scrollTo(0,T.current.get(j)||0)},[N]),X0(()=>{if(!J)return;fetch(`/api/session/${J}/meta`).then((j)=>j.json()).then((j)=>{if(j.currentRevision)Q(j.currentRevision),Y(j.currentRevision),q(j.revisions||[]);if(j.projectRoot)S(j.projectRoot)}).catch(()=>{})},[J]),X0(()=>{if(!J)return;let j=null,i=()=>{let b=window.location.protocol==="https:"?"wss:":"ws:",C=new WebSocket(`${b}//${window.location.host}/ws/session/${J}`);L.current=C,C.onopen=()=>U(!0),C.onclose=()=>{U(!1),j=setTimeout(i,2000)},C.onmessage=(h)=>{try{let x=JSON.parse(h.data);if(x.type==="plan-updated"){if(Q(x.currentRevision),Y(x.currentRevision),z(null),x.revisions)q(x.revisions)}if(x.type==="revision-updated"){if(x.revisions)q(x.revisions)}}catch{}}};return i(),()=>{if(j)clearTimeout(j);L.current?.close()}},[J]);let P1=C0((j)=>{if(L.current?.readyState===WebSocket.OPEN)L.current.send(JSON.stringify({type:"submit",feedback:j})),G(!1)},[]);if(!J)return O("div",{className:"flex items-center justify-center h-screen text-text-tertiary font-body",children:"No session selected."},void 0,!1,void 0,this);return O(T2.Provider,{value:J,children:O(h1.Provider,{value:{currentRevision:$,selectedRevision:Z,revisions:X,setSelectedRevision:Y,isReadOnly:c,compareRevision:_,setCompareRevision:z},children:O(b5,{sessionId:J,revision:Z,isReadOnly:c,children:O(I1.Provider,{value:{activeView:N,setActiveView:o,openFiles:M,closeFile:Z1},children:O(V$.Provider,{value:{setActiveView:o},children:O("div",{className:"min-h-screen bg-bg-base",children:[O(D$,{sessionId:J,projectRoot:y,connected:K,onMobileSidebar:()=>m(!R),collapsed:k,onToggle:()=>V((j)=>!j)},void 0,!1,void 0,this),_===null&&O(f$,{collapsed:w,onToggle:()=>I((j)=>!j),children:O(s0,{onPreview:()=>G(!0),onSubmit:P1},void 0,!1,void 0,this)},void 0,!1,void 0,this),_!==null?O("div",{className:`${k?"lg:ml-0":"lg:ml-60"} transition-[margin] duration-200`,children:O(H2,{initialLeft:_.left,initialRight:_.right,sessionId:J,onExit:()=>z(null)},void 0,!1,void 0,this)},void 0,!1,void 0,this):O("div",{className:`relative ${k?"lg:ml-0":"lg:ml-60"} ${w?"lg:mr-0":"lg:mr-[var(--sidebar-width,320px)]"} transition-[margin] duration-200`,id:"plan-scroll-container",children:[O("div",{className:"lg:hidden sticky top-0 z-20 flex items-center justify-between px-4 py-2 border-b border-border-subtle bg-bg-surface",children:[O("div",{className:"flex items-center gap-2",children:[O(n0,{currentSessionId:J,projectRoot:y},void 0,!1,void 0,this),O("span",{className:`w-1.5 h-1.5 rounded-full ${K?"bg-accent-green":"bg-accent-red"}`},void 0,!1,void 0,this)]},void 0,!0,void 0,this),O("div",{className:"flex items-center gap-1",children:[O(F2,{},void 0,!1,void 0,this),O("button",{onClick:()=>m(!R),className:"w-7 h-7 flex items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Annotations",children:O("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:O("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),O(O2,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),O(u$,{},void 0,!1,void 0,this),O("div",{style:{display:N.type==="plan"?void 0:"none"},children:O("div",{className:"relative max-w-[720px] mx-auto px-6 pt-12 pb-32",children:[O("button",{onClick:()=>{let j=document.querySelector(".plan-content");if(!j)return;let i=n5(j);navigator.clipboard.writeText(i).then(()=>{let b=document.getElementById("export-md-btn");if(b)b.setAttribute("data-copied","true"),setTimeout(()=>{b.removeAttribute("data-copied")},1500)})},id:"export-md-btn",className:"group absolute top-3 right-6 p-1.5 text-text-tertiary hover:text-text-secondary transition-colors z-10",title:"Copy as Markdown",children:[O("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"group-[[data-copied=true]]:hidden",children:[O("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"},void 0,!1,void 0,this),O("path",{d:"M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),O("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"hidden group-[[data-copied=true]]:block text-green-500",children:O("polyline",{points:"20 6 9 17 4 12"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),B?.response&&O(k$,{markdown:B.response},void 0,!1,void 0,this),O(f5,{revision:Z},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),M.map((j)=>O("div",{style:{display:N.type==="file"&&N.path===j?void 0:"none"},children:O(i5,{path:j},void 0,!1,void 0,this)},j,!1,void 0,this))]},void 0,!0,void 0,this),R&&O("div",{className:"lg:hidden fixed inset-0 z-40 flex",children:[O("div",{className:"flex-1",onClick:()=>m(!1)},void 0,!1,void 0,this),O("div",{className:"w-80 max-w-[85vw] bg-bg-surface border-l border-border-subtle flex flex-col shadow-lg",children:[O("div",{className:"flex items-center justify-between px-4 py-2 border-b border-border-subtle flex-shrink-0",children:[O("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:"Sidebar"},void 0,!1,void 0,this),O("button",{onClick:()=>m(!1),className:"text-text-tertiary hover:text-text-secondary w-7 h-7 flex items-center justify-center",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),O("div",{className:"flex-1 overflow-hidden",children:O(s0,{onPreview:()=>G(!0),onSubmit:P1},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),O(E5,{open:H,onClose:()=>G(!1),onSubmit:P1},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},`${J}:${Z}`,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function D$({sessionId:J,projectRoot:$,connected:Q,onMobileSidebar:Z,collapsed:Y,onToggle:X}){return O(Q5,{children:[Y&&O("button",{onClick:X,className:"hidden lg:flex fixed top-3 left-3 z-20 w-7 h-7 items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors bg-bg-surface border border-border-subtle",title:"Show sidebar",children:O("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[O("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"},void 0,!1,void 0,this),O("line",{x1:"9",y1:"3",x2:"9",y2:"21"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),O("div",{className:`hidden lg:flex w-60 flex-col fixed top-0 left-0 bottom-0 bg-bg-surface border-r border-border-subtle z-10 transition-transform duration-200 ${Y?"-translate-x-full":""}`,children:[O("div",{className:"px-4 pt-4 pb-3 flex-shrink-0 border-b border-border-subtle",children:[O("div",{className:"flex items-center gap-2 mb-2",children:[O("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",className:"text-text-tertiary flex-shrink-0",children:O("path",{d:"M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this),O(n0,{currentSessionId:J,projectRoot:$},void 0,!1,void 0,this),O("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${Q?"bg-accent-green":"bg-accent-red"}`},void 0,!1,void 0,this),O("button",{onClick:X,className:"ml-auto w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Hide sidebar",children:O("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[O("polyline",{points:"11 17 6 12 11 7"},void 0,!1,void 0,this),O("polyline",{points:"18 17 13 12 18 7"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),O(F2,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this),O("div",{className:"flex-1 flex flex-col overflow-hidden",children:O(d5,{embedded:!0},void 0,!1,void 0,this)},void 0,!1,void 0,this),O("div",{className:"px-4 py-3 border-t border-border-subtle flex items-center justify-between flex-shrink-0",children:[O("span",{className:"text-[10px] text-text-tertiary font-body uppercase tracking-widest",children:"Theme"},void 0,!1,void 0,this),O(O2,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function f$({children:J,collapsed:$,onToggle:Q}){let[Z,Y]=Q1(()=>{let U=localStorage.getItem("canvas-sidebar-width");return U?parseInt(U,10):320}),X=d1(!1),q=d1(0),_=d1(0),z=d1(Z);z.current=Z;let K=C0((U)=>{U.preventDefault(),X.current=!0,q.current=U.clientX,_.current=z.current;let H=(N)=>{if(!X.current)return;let W=q.current-N.clientX,M=Math.max(240,Math.min(600,_.current+W));Y(M),z.current=M},G=()=>{X.current=!1,localStorage.setItem("canvas-sidebar-width",String(z.current)),document.removeEventListener("mousemove",H),document.removeEventListener("mouseup",G),document.body.style.cursor="",document.body.style.userSelect=""};document.addEventListener("mousemove",H),document.addEventListener("mouseup",G),document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[]);return X0(()=>{return document.documentElement.style.setProperty("--sidebar-width",`${Z}px`),()=>{document.documentElement.style.removeProperty("--sidebar-width")}},[Z]),O(Q5,{children:[$&&O("button",{onClick:Q,className:"hidden lg:flex fixed top-3 right-3 z-20 w-7 h-7 items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors bg-bg-surface border border-border-subtle",title:"Show annotations",children:O("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:O("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),O("div",{className:`hidden lg:flex flex-col fixed top-0 right-0 bottom-0 bg-bg-surface border-l border-border-subtle z-10 transition-transform duration-200 ${$?"translate-x-full":""}`,style:{width:Z},children:[O("div",{onMouseDown:K,className:"absolute left-0 top-0 bottom-0 w-1 cursor-col-resize hover:bg-accent-blue/30 transition-colors z-20",style:{marginLeft:"-2px"}},void 0,!1,void 0,this),g1.Children.map(J,(U)=>g1.isValidElement(U)?g1.cloneElement(U,{collapseButton:O("button",{onClick:Q,className:"w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Hide annotations",children:O("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[O("polyline",{points:"13 17 18 12 13 7"},void 0,!1,void 0,this),O("polyline",{points:"6 17 11 12 6 7"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}):U)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function k$({markdown:J}){let[$,Q]=Q1(!1),Z=j$(()=>E.parse(J,{async:!1}),[J]);if(X0(()=>{Q(!1)},[J]),$)return null;return O("div",{className:"mb-6 rounded-lg border border-accent-blue/20 bg-accent-blue/5 relative",children:[O("button",{onClick:()=>Q(!0),className:"absolute top-2 right-2 w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",children:O("span",{className:"text-xs",children:"✕"},void 0,!1,void 0,this)},void 0,!1,void 0,this),O("div",{className:"px-4 py-3 pr-10",children:[O("div",{className:"flex items-center gap-2 mb-1.5",children:[O("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-accent-blue flex-shrink-0",children:O("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this),O("span",{className:"text-[11px] font-medium uppercase tracking-widest text-accent-blue font-body",children:"Agent Response"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),O("div",{className:"prose-canvas text-sm",dangerouslySetInnerHTML:{__html:Z}},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function u$(){let{activeView:J,setActiveView:$,openFiles:Q,closeFile:Z}=g1.useContext(I1),Y=g1.useContext(T2),{addAnnotationWithId:X,setActiveAnnotationId:q}=q1(),_=Q.length>0;if(!_)return null;return O("div",{className:"flex items-center border-b border-border-medium bg-bg-surface overflow-x-auto sticky top-0 z-10",children:[_&&O("button",{onClick:()=>$({type:"plan"}),className:`flex items-center gap-1.5 px-4 py-2.5 text-[13px] font-body whitespace-nowrap transition-colors relative ${J.type==="plan"?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[O("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",className:"opacity-60",children:O("path",{d:"M12 2L2 7l10 5 10-5-10-5z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this),"Plan",J.type==="plan"&&O("span",{className:"absolute bottom-0 left-3 right-3 h-[2px] bg-text-primary rounded-full"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),_&&O(Q5,{children:[O("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this),Q.map((z,K)=>{let U=z.split("/").pop()||z,H=J.type==="file"&&J.path===z;return O(g1.Fragment,{children:[O("div",{className:"flex items-center",children:[O("button",{onClick:()=>$({type:"file",path:z}),className:`flex items-center gap-1.5 pl-3 pr-1 py-2.5 text-[13px] font-mono whitespace-nowrap transition-colors relative ${H?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[U,H&&O("span",{className:"absolute bottom-0 left-3 right-1 h-[2px] bg-text-primary rounded-full"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),O("button",{onClick:(G)=>{G.stopPropagation(),Z(z)},className:"text-text-tertiary hover:text-text-secondary px-1.5 py-1 text-[10px] transition-colors rounded hover:bg-bg-input",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),K<Q.length-1&&O("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this)]},z,!0,void 0,this)})]},void 0,!0,void 0,this),O("div",{className:"ml-auto flex items-center gap-1 flex-shrink-0",children:J.type==="file"&&O("button",{onClick:async()=>{let z=J.path;try{let U=await(await fetch(`/api/file?session=${Y}&path=${encodeURIComponent(z)}`)).json();if(!U.error){let H=U.content.split(`
111
+ `),q=S1(Y,X),K=[],z=0,_=0,U=0;while(z<Y.length||_<X.length)if(U<q.length&&z<Y.length&&_<X.length&&Y[z]===q[U]&&X[_]===q[U])K.push({type:"same",line:Y[z]}),z++,_++,U++;else if(z<Y.length&&(U>=q.length||Y[z]!==q[U]))K.push({type:"removed",line:Y[z]}),z++;else if(_<X.length)K.push({type:"added",line:X[_]}),_++;let G=document.createElement("div");G.className="mt-2 bg-bg-code rounded-md overflow-hidden text-tiny font-mono",G.setAttribute("data-no-diff","true");for(let H of K){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;G.appendChild(F)}return $.appendChild(G),!0}function X5(J,$,Q){let Z=document.createElement("span");Z.className="diff-block-label",Z.textContent=$,Z.style.color=Q,Z.style.backgroundColor=`color-mix(in srgb, ${Q} 12%, transparent)`,J.appendChild(Z)}import{jsxDEV as k}from"react/jsx-dev-runtime";function F2({initialLeft:J,initialRight:$,sessionId:Q,onExit:Z}){let[Y,X]=Q1(J),[q,K]=Q1($),[z,_]=Q1("unified"),[U,G]=Q1(!0),[H,F]=Q1(!1);return k("div",{className:"flex flex-col h-screen",children:[k("div",{className:"flex items-center justify-between px-6 py-3 border-b border-border-subtle bg-bg-surface flex-shrink-0",children:[k("div",{className:"flex items-center gap-3",children:[k("span",{className:"text-[13px] font-body font-medium text-text-primary",children:"Compare"},void 0,!1,void 0,this),k(U0,{value:Y,onChange:X,accent:"red"},void 0,!1,void 0,this),k("span",{className:"text-text-tertiary text-[13px]",children:"→"},void 0,!1,void 0,this),k(U0,{value:q,onChange:K,accent:"green"},void 0,!1,void 0,this),H&&!U&&k("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),k("div",{className:"flex items-center gap-4",children:[k("div",{className:"flex items-center bg-bg-elevated rounded-md p-0.5",children:[k("button",{onClick:()=>_("unified"),className:`text-[11px] font-body px-2.5 py-1 rounded transition-colors ${z==="unified"?"bg-bg-surface text-text-primary font-medium shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Unified"},void 0,!1,void 0,this),k("button",{onClick:()=>_("side-by-side"),className:`text-[11px] font-body px-2.5 py-1 rounded transition-colors ${z==="side-by-side"?"bg-bg-surface text-text-primary font-medium shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Side-by-side"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z==="side-by-side"&&k(R$,{},void 0,!1,void 0,this),k("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"?k(j$,{sessionId:Q,leftRev:Y,rightRev:q,onDiffResult:(W,B)=>{F(W),G(B)}},`unified-${Y}-${q}`,!1,void 0,this):k(m$,{sessionId:Q,leftRev:Y,rightRev:q,onDiffResult:(W,B)=>{F(W),G(B)}},`sbs-${Y}-${q}`,!1,void 0,this)]},void 0,!0,void 0,this)}function R$(){let[J,$]=Q1(!0);return n1(()=>{return document.documentElement.dataset.syncScroll=J?"1":"0",()=>{delete document.documentElement.dataset.syncScroll}},[J]),k("label",{className:"flex items-center gap-1.5 cursor-pointer select-none",children:[k("input",{type:"checkbox",checked:J,onChange:(Q)=>$(Q.target.checked),className:"accent-accent-amber w-3.5 h-3.5"},void 0,!1,void 0,this),k("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 j$({sessionId:J,leftRev:$,rightRev:Q,onDiffResult:Z}){let Y=b1(null),X=b1(null),q=b1(null),[K,z]=Q1(!1),[_,U]=Q1(!1),[G,H]=Q1(!1);return n1(()=>{if(!K||!_||G)return;if(!Y.current||!X.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!Y.current||!X.current||!q.current)return;let F=Z5(Y.current),W=Z5(X.current),B=q5(F,W),{fragment:T,hasChanges:M}=K2(B);q.current.innerHTML="",q.current.appendChild(T),H(!0),Z(!0,M)})})},[K,_,G]),k("div",{className:"flex-1 min-h-0 overflow-y-auto",children:[k("div",{style:{position:"absolute",left:-9999,visibility:"hidden",pointerEvents:"none",width:720},children:[k(m0,{ref:Y,sessionId:J,revision:$,onReady:()=>z(!0)},void 0,!1,void 0,this),k(m0,{ref:X,sessionId:J,revision:Q,onReady:()=>U(!0)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),k("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:[!G&&k("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-body",children:"Loading..."},void 0,!1,void 0,this),k("div",{ref:q},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function m$({sessionId:J,leftRev:$,rightRev:Q,onDiffResult:Z}){let Y=b1(null),X=b1(null),[q,K]=Q1(!1),[z,_]=Q1(!1),[U,G]=Q1(!1),H=b1(null),F=b1(null),W=b1(!1);return n1(()=>{if(!q||!z||U)return;if(!Y.current||!X.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!Y.current||!X.current)return;let B=X2(Y.current,X.current);G(!0),Z(!0,B)})})},[q,z,U]),n1(()=>{let B=H.current,T=F.current;if(!B||!T)return;let M=(C,R)=>{if(document.documentElement.dataset.syncScroll==="0")return;if(W.current)return;W.current=!0;let D=C.scrollHeight-C.clientHeight,V=R.scrollHeight-R.clientHeight;if(D>0&&V>0)R.scrollTop=C.scrollTop/D*V;requestAnimationFrame(()=>{W.current=!1})},y=()=>M(B,T),L=()=>M(T,B);return B.addEventListener("scroll",y),T.addEventListener("scroll",L),()=>{B.removeEventListener("scroll",y),T.removeEventListener("scroll",L)}},[]),k("div",{className:"flex flex-1 min-h-0",children:[k("div",{ref:H,className:"w-1/2 overflow-y-auto border-r border-border-subtle",children:k("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:k(m0,{ref:Y,sessionId:J,revision:$,onReady:()=>K(!0)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),k("div",{ref:F,className:"w-1/2 overflow-y-auto",children:k("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:k(m0,{ref:X,sessionId:J,revision:Q,onReady:()=>_(!0)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var m0=A$.forwardRef(({sessionId:J,revision:$,onReady:Q},Z)=>{let[Y,X]=Q1(null),[q,K]=Q1(null),[z,_]=Q1(!0);if(n1(()=>{_(!0),K(null),import(`/api/session/${J}/plan.js?rev=${$}&t=${Date.now()}`).then((U)=>{X(()=>U.default),_(!1)}).catch((U)=>{K(U.message),_(!1)})},[J,$]),n1(()=>{if(!Y)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{Q()})})},[Y]),z)return k("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 k("div",{className:"bg-accent-red-muted rounded-lg p-5",children:[k("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Error"},void 0,!1,void 0,this),k("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 k("div",{className:"text-text-tertiary text-center py-8 font-body text-body",children:"No canvas loaded"},void 0,!1,void 0,this);return k("div",{ref:Z,children:k(Y,{},void 0,!1,void 0,this)},void 0,!1,void 0,this)});import{jsxDEV as N,Fragment as z5}from"react/jsx-dev-runtime";var u1=T2({activeView:{type:"plan"},setActiveView:()=>{},openFiles:[],closeFile:()=>{}}),s1=T2({currentRevision:1,selectedRevision:1,revisions:[],setSelectedRevision:()=>{},isReadOnly:!1,compareRevision:null,setCompareRevision:()=>{}});function B2(){let[J,$]=e(()=>localStorage.getItem("canvas-theme")||document.documentElement.dataset.theme||"dark");return N("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"?N("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[N("circle",{cx:"12",cy:"12",r:"5"},void 0,!1,void 0,this),N("line",{x1:"12",y1:"1",x2:"12",y2:"3"},void 0,!1,void 0,this),N("line",{x1:"12",y1:"21",x2:"12",y2:"23"},void 0,!1,void 0,this),N("line",{x1:"4.22",y1:"4.22",x2:"5.64",y2:"5.64"},void 0,!1,void 0,this),N("line",{x1:"18.36",y1:"18.36",x2:"19.78",y2:"19.78"},void 0,!1,void 0,this),N("line",{x1:"1",y1:"12",x2:"3",y2:"12"},void 0,!1,void 0,this),N("line",{x1:"21",y1:"12",x2:"23",y2:"12"},void 0,!1,void 0,this),N("line",{x1:"4.22",y1:"19.78",x2:"5.64",y2:"18.36"},void 0,!1,void 0,this),N("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):N("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:N("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 M2(){let{currentRevision:J,selectedRevision:$,revisions:Q,setSelectedRevision:Z,setCompareRevision:Y}=E1.useContext(s1);if(Q.length<=1){let K=Q[0]?.label||`Round ${J}`;return N("span",{className:"text-[11px] text-text-tertiary font-body",children:K},void 0,!1,void 0,this)}return N("div",{className:"flex flex-col gap-1",children:[N(U0,{value:$,onChange:Z,accent:$===J?"default":"amber"},void 0,!1,void 0,this),N("button",{onClick:()=>{let K=Q.find((_)=>_.revision===$)?.sourceFile,z;if($===J)z=[...Q].reverse().find((U)=>U.revision<J&&(!K||U.sourceFile===K))?.revision??Math.max(1,J-1);else z=$;Y({left:z,right:J})},className:"text-[11px] font-body font-medium px-2 py-0.5 rounded-md text-accent-blue hover:bg-accent-blue-muted transition-colors self-start",children:"Compare"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function D$(){let J=window.location.pathname.replace("/s/","")||"",[$,Q]=e(1),[Z,Y]=e(1),[X,q]=e([]),[K,z]=e(null),[_,U]=e(!1),[G,H]=e(!1),[F,W]=e({type:"plan"}),[B,T]=e([]),M=w1(null),[y,L]=e(),[C,R]=e(!1),[D,V]=e(!1),[b,I]=e(!1);T1(()=>{let g=["Agent Canvas"];if(y){let i=y.replace(/\/+$/,"").split("/");g.push(i[i.length-1]||J)}else if(J)g.push(J);if(F.type==="file")g.push(F.path.split("/").pop()||F.path);else if(K)g.push("Compare");document.title=g.join(" — ")},[J,y,F,K]);let P=w1(new Map),O=X.find((g)=>g.revision===Z),j=Z!==$||!!O?.hasFeedback,o=I0((g)=>{if(P.current.set(F.type==="plan"?"plan":`file:${F.path}`,window.scrollY),W(g),g.type==="file")T((i)=>i.includes(g.path)?i:[...i,g.path])},[F]),Z1=I0((g)=>{P.current.delete(`file:${g}`),T((i)=>i.filter((w)=>w!==g)),W((i)=>{if(i.type==="file"&&i.path===g)return P.current.set(`file:${g}`,window.scrollY),{type:"plan"};return i})},[]);I$(()=>{let g=F.type==="plan"?"plan":`file:${F.path}`;window.scrollTo(0,P.current.get(g)||0)},[F]),T1(()=>{if(!J)return;fetch(`/api/session/${J}/meta`).then((g)=>g.json()).then((g)=>{if(g.currentRevision)Q(g.currentRevision),Y(g.currentRevision),q(g.revisions||[]);if(g.projectRoot)L(g.projectRoot)}).catch(()=>{})},[J]),T1(()=>{if(!J)return;let g=null,i=()=>{let w=window.location.protocol==="https:"?"wss:":"ws:",m=new WebSocket(`${w}//${window.location.host}/ws/session/${J}`);M.current=m,m.onopen=()=>U(!0),m.onclose=()=>{U(!1),g=setTimeout(i,2000)},m.onmessage=(p)=>{try{let h=JSON.parse(p.data);if(h.type==="plan-updated"){if(Q(h.currentRevision),Y(h.currentRevision),z(null),h.revisions)q(h.revisions)}if(h.type==="revision-updated"){if(h.revisions)q(h.revisions)}}catch{}}};return i(),()=>{if(g)clearTimeout(g);M.current?.close()}},[J]);let C1=I0((g)=>{if(M.current?.readyState===WebSocket.OPEN)M.current.send(JSON.stringify({type:"submit",feedback:g})),H(!1)},[]);if(!J)return N("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 N(O2.Provider,{value:J,children:N(s1.Provider,{value:{currentRevision:$,selectedRevision:Z,revisions:X,setSelectedRevision:Y,isReadOnly:j,compareRevision:K,setCompareRevision:z},children:N(R5,{sessionId:J,revision:Z,isReadOnly:j,children:N(u1.Provider,{value:{activeView:F,setActiveView:o,openFiles:B,closeFile:Z1},children:N(g$.Provider,{value:{setActiveView:o},children:N("div",{className:"min-h-screen bg-bg-base",children:[N(f$,{sessionId:J,projectRoot:y,connected:_,onMobileSidebar:()=>R(!C),collapsed:D,onToggle:()=>V((g)=>!g)},void 0,!1,void 0,this),K===null&&N(k$,{collapsed:b,onToggle:()=>I((g)=>!g),children:N($5,{onPreview:()=>H(!0),onSubmit:C1},void 0,!1,void 0,this)},void 0,!1,void 0,this),K!==null?N("div",{className:`${D?"lg:ml-0":"lg:ml-60"} transition-[margin] duration-200`,children:N(F2,{initialLeft:K.left,initialRight:K.right,sessionId:J,onExit:()=>z(null)},void 0,!1,void 0,this)},void 0,!1,void 0,this):N("div",{className:`relative ${D?"lg:ml-0":"lg:ml-60"} ${b?"lg:mr-0":"lg:mr-[var(--sidebar-width,320px)]"} transition-[margin] duration-200`,id:"plan-scroll-container",children:[N("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:[N("div",{className:"flex items-center gap-2",children:[N(Y5,{currentSessionId:J,projectRoot:y},void 0,!1,void 0,this),N("span",{className:`w-1.5 h-1.5 rounded-full ${_?"bg-accent-green":"bg-accent-red"}`},void 0,!1,void 0,this)]},void 0,!0,void 0,this),N("div",{className:"flex items-center gap-1",children:[N(M2,{},void 0,!1,void 0,this),N("button",{onClick:()=>R(!C),className:"w-7 h-7 flex items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Annotations",children:N("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:N("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),N(B2,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),N(v$,{},void 0,!1,void 0,this),N("div",{style:{display:F.type==="plan"?void 0:"none"},children:N("div",{className:"relative max-w-[720px] mx-auto px-6 pt-12 pb-32",children:[N("button",{onClick:()=>{let g=document.querySelector(".plan-content");if(!g)return;let i=$2(g);navigator.clipboard.writeText(i).then(()=>{let w=document.getElementById("export-md-btn");if(w)w.setAttribute("data-copied","true"),setTimeout(()=>{w.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:[N("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:[N("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"},void 0,!1,void 0,this),N("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),N("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:N("polyline",{points:"20 6 9 17 4 12"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),O?.response&&N(u$,{markdown:O.response},void 0,!1,void 0,this),N(v5,{revision:Z},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),B.map((g)=>N("div",{style:{display:F.type==="file"&&F.path===g?void 0:"none"},children:N(s5,{path:g},void 0,!1,void 0,this)},g,!1,void 0,this))]},void 0,!0,void 0,this),C&&N("div",{className:"lg:hidden fixed inset-0 z-40 flex",children:[N("div",{className:"flex-1",onClick:()=>R(!1)},void 0,!1,void 0,this),N("div",{className:"w-80 max-w-[85vw] bg-bg-surface border-l border-border-subtle flex flex-col shadow-lg",children:[N("div",{className:"flex items-center justify-between px-4 py-2 border-b border-border-subtle flex-shrink-0",children:[N("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:"Sidebar"},void 0,!1,void 0,this),N("button",{onClick:()=>R(!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),N("div",{className:"flex-1 overflow-hidden",children:N($5,{onPreview:()=>H(!0),onSubmit:C1},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),N(h5,{open:G,onClose:()=>H(!1),onSubmit:C1},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 f$({sessionId:J,projectRoot:$,connected:Q,onMobileSidebar:Z,collapsed:Y,onToggle:X}){return N(z5,{children:[Y&&N("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:N("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[N("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"},void 0,!1,void 0,this),N("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),N("div",{className:`hidden lg:flex w-60 flex-col fixed top-0 left-0 bottom-0 bg-bg-surface border-r border-border-subtle z-10 transition-transform duration-200 ${Y?"-translate-x-full":""}`,children:[N("div",{className:"px-4 pt-4 pb-3 flex-shrink-0 border-b border-border-subtle",children:[N("div",{className:"flex items-center gap-2 mb-2",children:[N("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",className:"text-text-tertiary flex-shrink-0",children:N("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),N(Y5,{currentSessionId:J,projectRoot:$},void 0,!1,void 0,this),N("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${Q?"bg-accent-green":"bg-accent-red"}`},void 0,!1,void 0,this),N("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:N("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[N("polyline",{points:"11 17 6 12 11 7"},void 0,!1,void 0,this),N("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),N(M2,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this),N("div",{className:"flex-1 flex flex-col overflow-hidden",children:N(l5,{embedded:!0},void 0,!1,void 0,this)},void 0,!1,void 0,this),N("div",{className:"px-4 py-3 border-t border-border-subtle flex items-center justify-between flex-shrink-0",children:[N("span",{className:"text-[10px] text-text-tertiary font-body uppercase tracking-widest",children:"Theme"},void 0,!1,void 0,this),N(B2,{},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 k$({children:J,collapsed:$,onToggle:Q}){let[Z,Y]=e(()=>{let U=localStorage.getItem("canvas-sidebar-width");return U?parseInt(U,10):320}),X=w1(!1),q=w1(0),K=w1(0),z=w1(Z);z.current=Z;let _=I0((U)=>{U.preventDefault(),X.current=!0,q.current=U.clientX,K.current=z.current;let G=(F)=>{if(!X.current)return;let W=q.current-F.clientX,B=Math.max(240,Math.min(600,K.current+W));Y(B),z.current=B},H=()=>{X.current=!1,localStorage.setItem("canvas-sidebar-width",String(z.current)),document.removeEventListener("mousemove",G),document.removeEventListener("mouseup",H),document.body.style.cursor="",document.body.style.userSelect=""};document.addEventListener("mousemove",G),document.addEventListener("mouseup",H),document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[]);return T1(()=>{return document.documentElement.style.setProperty("--sidebar-width",`${Z}px`),()=>{document.documentElement.style.removeProperty("--sidebar-width")}},[Z]),N(z5,{children:[$&&N("button",{onClick:Q,className:"hidden lg:flex fixed top-3 right-3 z-20 w-7 h-7 items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors bg-bg-surface border border-border-subtle",title:"Show annotations",children:N("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:N("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),N("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:[N("div",{onMouseDown:_,className:"absolute left-0 top-0 bottom-0 w-1 cursor-col-resize hover:bg-accent-blue/30 transition-colors z-20",style:{marginLeft:"-2px"}},void 0,!1,void 0,this),E1.Children.map(J,(U)=>E1.isValidElement(U)?E1.cloneElement(U,{collapseButton:N("button",{onClick:Q,className:"w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Hide annotations",children:N("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[N("polyline",{points:"13 17 18 12 13 7"},void 0,!1,void 0,this),N("polyline",{points:"6 17 11 12 6 7"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}):U)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function u$({markdown:J}){let[$,Q]=e(!1),Z=y2(()=>x.parse(J,{async:!1}),[J]),Y=w1(null),{annotations:X,addAnnotationWithId:q,removeAnnotation:K,updateAnnotation:z,activeAnnotationId:_,setActiveAnnotationId:U}=q1(),[G,H]=e(null),[F,W]=e(null),B=y2(()=>X.filter((y)=>y.filePath===U1),[X]);T1(()=>{Q(!1)},[J]),T1(()=>{if(!Y.current||B.length===0)return;let y=setTimeout(()=>{if(Y.current)r1(Y.current,B)},50);return()=>clearTimeout(y)},[Z,B.length]);let T=w1(null);if(T1(()=>{c1(_,T.current),T.current=_},[_]),T1(()=>{let y=Y.current;if(!y)return;let L=(D)=>{let V=D.target.closest("[data-annotation-id]");if(!V)return;D.stopPropagation();let b=V.getAttribute("data-annotation-id");if(b===_)W({anchorEl:V,annId:b});else U(b)},C=(D)=>{let V=D.target.closest("[data-annotation-id]");if(V)U(V.getAttribute("data-annotation-id"))},R=(D)=>{let V=D.target.closest("[data-annotation-id]"),b=D.relatedTarget?.closest?.("[data-annotation-id]");if(V&&!b)U(null)};return y.addEventListener("click",L),y.addEventListener("mouseover",C),y.addEventListener("mouseout",R),()=>{y.removeEventListener("click",L),y.removeEventListener("mouseover",C),y.removeEventListener("mouseout",R)}},[Z,_]),T1(()=>{let y=()=>{let L=window.getSelection();if(!L||L.isCollapsed||!L.toString().trim())return;if(!Y.current)return;let C=L.getRangeAt(0);if(!Y.current.contains(C.startContainer))return;if(C.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let R=L.toString().trim();if(R.length<2)return;let D=C.cloneRange(),V=B0(C,Y.current),b=`__pending_${Date.now()}`;try{L1(D,b)}catch{}window.getSelection()?.removeAllRanges();let I=document.querySelectorAll(`[data-annotation-id="${b}"]`),P=I[I.length-1];if(!P)return;H({anchorEl:P,tempId:b,snippet:R,ctx:V})};return document.addEventListener("mouseup",y),()=>document.removeEventListener("mouseup",y)},[]),$)return null;let M=document.getElementById("plan-scroll-container");return N("div",{className:"mb-6 rounded-lg border border-accent-blue/20 bg-accent-blue/5 relative",children:[N("button",{onClick:()=>Q(!0),className:"absolute top-2 right-2 w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",children:N("span",{className:"text-xs",children:"✕"},void 0,!1,void 0,this)},void 0,!1,void 0,this),N("div",{className:"px-4 py-3 pr-10",children:[N("div",{className:"flex items-center gap-2 mb-1.5",children:[N("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:N("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),N("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),N("div",{ref:Y,className:"prose-canvas text-sm",dangerouslySetInnerHTML:{__html:Z}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),G&&N(g1,{anchorEl:G.anchorEl,scrollContainer:M,snippet:G.snippet,truncateAt:80,onAdd:(y)=>{let L=G1();d1(G.tempId,L),q(L,G.snippet,y,U1,G.ctx),H(null)},onCancel:()=>{l1(G.tempId),H(null)}},void 0,!1,void 0,this),F&&(()=>{let y=X.find((L)=>L.id===F.annId);if(!y)return null;return N(D1,{anchorEl:F.anchorEl,scrollContainer:M,initialNote:y.note,onUpdate:(L)=>z(F.annId,L),onDelete:()=>{K(F.annId),U(null)},onClose:()=>W(null)},void 0,!1,void 0,this)})()]},void 0,!0,void 0,this)}function v$(){let{activeView:J,setActiveView:$,openFiles:Q,closeFile:Z}=E1.useContext(u1),Y=E1.useContext(O2),{addAnnotationWithId:X,setActiveAnnotationId:q}=q1(),K=Q.length>0;if(!K)return null;return N("div",{className:"flex items-center border-b border-border-medium bg-bg-surface overflow-x-auto sticky top-0 z-10",children:[K&&N("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:[N("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",className:"opacity-60",children:N("path",{d:"M12 2L2 7l10 5 10-5-10-5z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this),"Canvas",J.type==="plan"&&N("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),K&&N(z5,{children:[N("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this),Q.map((z,_)=>{let U=z.split("/").pop()||z,G=J.type==="file"&&J.path===z;return N(E1.Fragment,{children:[N("div",{className:"flex items-center",children:[N("button",{onClick:()=>$({type:"file",path:z}),className:`flex items-center gap-1.5 pl-3 pr-1 py-2.5 text-[13px] font-mono whitespace-nowrap transition-colors relative ${G?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[U,G&&N("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),N("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),_<Q.length-1&&N("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),N("div",{className:"ml-auto flex items-center gap-1 flex-shrink-0",children:J.type==="file"&&N("button",{onClick:async()=>{let z=J.path;try{let U=await(await fetch(`/api/file?session=${Y}&path=${encodeURIComponent(z)}`)).json();if(!U.error){let G=U.content.split(`
112
112
  `).slice(0,3).join(`
113
113
  `)+(U.content.split(`
114
114
  `).length>3?`
115
- ...`:""),G=H1();X(G,H,"",z),q(G)}}catch{}},className:"flex items-center gap-1 px-3 py-1.5 text-[11px] font-medium font-body text-text-tertiary hover:text-text-secondary whitespace-nowrap transition-colors",children:[O("span",{className:"text-[13px] leading-none",children:"+"},void 0,!1,void 0,this),"Add to context"]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var N2=document.getElementById("root");if(N2)I$(N2).render(O(g$,{},void 0,!1,void 0,this));export{h1 as RevisionContext,I1 as ActiveViewContext};
115
+ ...`:""),H=G1();X(H,G,"",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:[N("span",{className:"text-[13px] leading-none",children:"+"},void 0,!1,void 0,this),"Add to context"]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var N2=document.getElementById("root");if(N2)V$(N2).render(N(D$,{},void 0,!1,void 0,this));export{s1 as RevisionContext,u1 as ActiveViewContext};