agent-canvas 0.1.16 → 0.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/agent-canvas.ts +3 -0
- package/bin/lib/commands/install.ts +7 -7
- package/bin/lib/commands/instructions.ts +66 -0
- package/bin/lib/instructions/component-callout.md +27 -0
- package/bin/lib/instructions/component-checklist.md +17 -0
- package/bin/lib/instructions/component-choice.md +27 -0
- package/bin/lib/instructions/component-codeblock.md +24 -0
- package/bin/lib/instructions/component-custom.md +34 -0
- package/bin/lib/instructions/component-diff.md +18 -0
- package/bin/lib/instructions/component-filepreview.md +15 -0
- package/bin/lib/instructions/component-image.md +17 -0
- package/bin/lib/instructions/component-item.md +43 -0
- package/bin/lib/instructions/component-markdown.md +33 -0
- package/bin/lib/instructions/component-mermaid.md +40 -0
- package/bin/lib/instructions/component-multichoice.md +19 -0
- package/bin/lib/instructions/component-note.md +11 -0
- package/bin/lib/instructions/component-priority.md +15 -0
- package/bin/lib/instructions/component-rangeinput.md +20 -0
- package/bin/lib/instructions/component-section.md +22 -0
- package/bin/lib/instructions/component-svg.md +31 -0
- package/bin/lib/instructions/component-table.md +21 -0
- package/bin/lib/instructions/component-usefeedback.md +33 -0
- package/bin/lib/instructions/component-userinput.md +17 -0
- package/bin/lib/instructions/flow-decision.md +53 -0
- package/bin/lib/instructions/flow-explain.md +47 -0
- package/bin/lib/instructions/flow-feature.md +188 -0
- package/bin/lib/instructions/flow-plan.md +106 -0
- package/bin/lib/instructions/flow-review.md +60 -0
- package/bin/lib/instructions/overview.md +173 -0
- package/bin/lib/instructions/theming.md +50 -0
- package/daemon/client/AnnotationSidebar.tsx +40 -20
- package/daemon/client/App.tsx +8 -1
- package/daemon/dist/client.js +35 -35
- package/daemon/src/compiler.ts +1 -0
- package/daemon/src/handlers/api.ts +3 -1
- package/daemon/src/server.ts +1 -1
- package/daemon/src/websocket.ts +62 -1
- package/package.json +1 -1
- package/skills/canvas/SKILL.md +9 -194
- package/skills/canvas/components.md +0 -403
- package/skills/canvas/flows.md +0 -406
package/daemon/dist/client.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import A1,{useEffect as
|
|
2
|
-
]`).replace("lheading",
|
|
1
|
+
import A1,{useEffect as B1,useLayoutEffect as M4,useState as e,useCallback as E0,useRef as I1,createContext as u2,useMemo as k2}from"react";import{createRoot as B4}from"react-dom/client";function h0(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var k1=h0();function P5(J){k1=J}var j1={exec:()=>null};function i(J,$=""){let Y=typeof J=="string"?J:J.source,Z={replace:(Q,q)=>{let X=typeof q=="string"?q:q.source;return X=X.replace(X1.caret,"$1"),Y=Y.replace(Q,X),Z},getRegex:()=>new RegExp(Y,$)};return Z}var x2=(()=>{try{return!!new RegExp("(?<=1)(?<!1)")}catch{return!1}})(),X1={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)}}>`)},f2=/^(?:[ \t]*(?:\n|$))+/,h2=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,p2=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,e1=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,c2=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,p0=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,S5=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,b5=i(S5).replace(/bull/g,p0).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(),d2=i(S5).replace(/bull/g,p0).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(),c0=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,r2=/^[^\n]+/,d0=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,l2=i(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",d0).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),i2=i(/^(bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,p0).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",r0=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,a2=i("^ {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",r0).replace("tag",T0).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),w5=i(c0).replace("hr",e1).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(),o2=i(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",w5).getRegex(),l0={blockquote:o2,code:h2,def:l2,fences:p2,heading:c2,hr:e1,html:a2,lheading:b5,list:i2,newline:f2,paragraph:w5,table:j1,text:r2},O5=i("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",e1).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(),s2={...l0,lheading:d2,table:O5,paragraph:i(c0).replace("hr",e1).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",O5).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()},t2={...l0,html:i(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",r0).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:i(c0).replace("hr",e1).replace("heading",` *#{1,6} *[^
|
|
2
|
+
]`).replace("lheading",b5).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},n2=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,e2=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,A5=/^( {2,}|\\)\n(?!\s*$)/,$3=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,O0=/[\p{P}\p{S}]/u,i0=/[\s\p{P}\p{S}]/u,I5=/[^\s\p{P}\p{S}]/u,J3=i(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,i0).getRegex(),C5=/(?!~)[\p{P}\p{S}]/u,Y3=/(?!~)[\s\p{P}\p{S}]/u,Q3=/(?:[^\s\p{P}\p{S}]|~)/u,j5=/(?![*_])[\p{P}\p{S}]/u,Z3=/(?![*_])[\s\p{P}\p{S}]/u,X3=/(?:[^\s\p{P}\p{S}]|[*_])/u,q3=i(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",x2?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),R5=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,_3=i(R5,"u").replace(/punct/g,O0).getRegex(),z3=i(R5,"u").replace(/punct/g,C5).getRegex(),k5="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",G3=i(k5,"gu").replace(/notPunctSpace/g,I5).replace(/punctSpace/g,i0).replace(/punct/g,O0).getRegex(),U3=i(k5,"gu").replace(/notPunctSpace/g,Q3).replace(/punctSpace/g,Y3).replace(/punct/g,C5).getRegex(),K3=i("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,I5).replace(/punctSpace/g,i0).replace(/punct/g,O0).getRegex(),H3=i(/^~~?(?:((?!~)punct)|[^\s~])/,"u").replace(/punct/g,j5).getRegex(),W3="^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)",N3=i(W3,"gu").replace(/notPunctSpace/g,X3).replace(/punctSpace/g,Z3).replace(/punct/g,j5).getRegex(),T3=i(/\\(punct)/,"gu").replace(/punct/g,O0).getRegex(),O3=i(/^<(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(),F3=i(r0).replace("(?:-->|$)","-->").getRegex(),L3=i("^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",F3).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),H0=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+[^`]*?`+(?!`)|[^\[\]\\`])*?/,y3=i(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace("label",H0).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),V5=i(/^!?\[(label)\]\[(ref)\]/).replace("label",H0).replace("ref",d0).getRegex(),D5=i(/^!?\[(ref)\](?:\[\])?/).replace("ref",d0).getRegex(),M3=i("reflink|nolink(?!\\()","g").replace("reflink",V5).replace("nolink",D5).getRegex(),F5=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,a0={_backpedal:j1,anyPunctuation:T3,autolink:O3,blockSkip:q3,br:A5,code:e2,del:j1,delLDelim:j1,delRDelim:j1,emStrongLDelim:_3,emStrongRDelimAst:G3,emStrongRDelimUnd:K3,escape:n2,link:y3,nolink:D5,punctuation:J3,reflink:V5,reflinkSearch:M3,tag:L3,text:$3,url:j1},B3={...a0,link:i(/^!?\[(label)\]\((.*?)\)/).replace("label",H0).getRegex(),reflink:i(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",H0).getRegex()},f0={...a0,emStrongRDelimAst:U3,emStrongLDelim:z3,delLDelim:H3,delRDelim:N3,url:i(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol",F5).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:i(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace("protocol",F5).getRegex()},P3={...f0,br:i(A5).replace("{2,}","*").getRegex(),text:i(f0.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},K0={normal:l0,gfm:s2,pedantic:t2},s1={normal:a0,gfm:f0,breaks:P3,pedantic:B3},S3={"&":"&","<":"<",">":">",'"':""","'":"'"},L5=(J)=>S3[J];function K1(J,$){if($){if(X1.escapeTest.test(J))return J.replace(X1.escapeReplace,L5)}else if(X1.escapeTestNoEncode.test(J))return J.replace(X1.escapeReplaceNoEncode,L5);return J}function y5(J){try{J=encodeURI(J).replace(X1.percentDecode,"%")}catch{return null}return J}function M5(J,$){let Y=J.replace(X1.findPipe,(q,X,G)=>{let _=!1,z=X;for(;--z>=0&&G[z]==="\\";)_=!_;return _?"|":" |"}),Z=Y.split(X1.splitPipe),Q=0;if(Z[0].trim()||Z.shift(),Z.length>0&&!Z.at(-1)?.trim()&&Z.pop(),$)if(Z.length>$)Z.splice($);else for(;Z.length<$;)Z.push("");for(;Q<Z.length;Q++)Z[Q]=Z[Q].trim().replace(X1.slashPipe,"|");return Z}function t1(J,$,Y){let Z=J.length;if(Z===0)return"";let Q=0;for(;Q<Z;){let q=J.charAt(Z-Q-1);if(q===$&&!Y)Q++;else if(q!==$&&Y)Q++;else break}return J.slice(0,Z-Q)}function b3(J,$){if(J.indexOf($[1])===-1)return-1;let Y=0;for(let Z=0;Z<J.length;Z++)if(J[Z]==="\\")Z++;else if(J[Z]===$[0])Y++;else if(J[Z]===$[1]&&(Y--,Y<0))return Z;return Y>0?-2:-1}function w3(J,$=0){let Y=$,Z="";for(let Q of J)if(Q==="\t"){let q=4-Y%4;Z+=" ".repeat(q),Y+=q}else Z+=Q,Y++;return Z}function B5(J,$,Y,Z,Q){let q=$.href,X=$.title||null,G=J[1].replace(Q.other.outputLinkReplace,"$1");Z.state.inLink=!0;let _={type:J[0].charAt(0)==="!"?"image":"link",raw:Y,href:q,title:X,text:G,tokens:Z.inlineTokens(G)};return Z.state.inLink=!1,_}function A3(J,$,Y){let Z=J.match(Y.other.indentCodeCompensation);if(Z===null)return $;let Q=Z[1];return $.split(`
|
|
3
3
|
`).map((q)=>{let X=q.match(Y.other.beginningSpace);if(X===null)return q;let[G]=X;return G.length>=Q.length?q.slice(Q.length):q}).join(`
|
|
4
|
-
`)}var
|
|
5
|
-
`)}}}fences(J){let $=this.rules.block.fences.exec(J);if($){let Y=$[0],Z=
|
|
6
|
-
`)}}blockquote(J){let $=this.rules.block.blockquote.exec(J);if($){let Y=
|
|
4
|
+
`)}var W0=class{options;rules;lexer;constructor(J){this.options=J||k1}space(J){let $=this.rules.block.newline.exec(J);if($&&$[0].length>0)return{type:"space",raw:$[0]}}code(J){let $=this.rules.block.code.exec(J);if($){let Y=$[0].replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:$[0],codeBlockStyle:"indented",text:this.options.pedantic?Y:t1(Y,`
|
|
5
|
+
`)}}}fences(J){let $=this.rules.block.fences.exec(J);if($){let Y=$[0],Z=A3(Y,$[3]||"",this.rules);return{type:"code",raw:Y,lang:$[2]?$[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):$[2],text:Z}}}heading(J){let $=this.rules.block.heading.exec(J);if($){let Y=$[2].trim();if(this.rules.other.endingHash.test(Y)){let Z=t1(Y,"#");(this.options.pedantic||!Z||this.rules.other.endingSpaceChar.test(Z))&&(Y=Z.trim())}return{type:"heading",raw:$[0],depth:$[1].length,text:Y,tokens:this.lexer.inline(Y)}}}hr(J){let $=this.rules.block.hr.exec(J);if($)return{type:"hr",raw:t1($[0],`
|
|
6
|
+
`)}}blockquote(J){let $=this.rules.block.blockquote.exec(J);if($){let Y=t1($[0],`
|
|
7
7
|
`).split(`
|
|
8
8
|
`),Z="",Q="",q=[];for(;Y.length>0;){let X=!1,G=[],_;for(_=0;_<Y.length;_++)if(this.rules.other.blockquoteStart.test(Y[_]))G.push(Y[_]),X=!0;else if(!X)G.push(Y[_]);else break;Y=Y.slice(_);let z=G.join(`
|
|
9
9
|
`),H=z.replace(this.rules.other.blockquoteSetextReplace,`
|
|
@@ -11,20 +11,20 @@ import A1,{useEffect as M1,useLayoutEffect as L4,useState as $1,useCallback as u
|
|
|
11
11
|
${z}`:z,Q=Q?`${Q}
|
|
12
12
|
${H}`:H;let U=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(H,q,!0),this.lexer.state.top=U,Y.length===0)break;let W=q.at(-1);if(W?.type==="code")break;if(W?.type==="blockquote"){let N=W,K=N.raw+`
|
|
13
13
|
`+Y.join(`
|
|
14
|
-
`),
|
|
14
|
+
`),F=this.blockquote(K);q[q.length-1]=F,Z=Z.substring(0,Z.length-N.raw.length)+F.raw,Q=Q.substring(0,Q.length-N.text.length)+F.text;break}else if(W?.type==="list"){let N=W,K=N.raw+`
|
|
15
15
|
`+Y.join(`
|
|
16
|
-
`),
|
|
17
|
-
`);continue}}return{type:"blockquote",raw:Z,tokens:q,text:Q}}}list(J){let $=this.rules.block.list.exec(J);if($){let Y=$[1].trim(),Z=Y.length>1,Q={type:"list",raw:"",ordered:Z,start:Z?+Y.slice(0,-1):"",loose:!1,items:[]};Y=Z?`\\d{1,9}\\${Y.slice(-1)}`:`\\${Y}`,this.options.pedantic&&(Y=Z?Y:"[*+-]");let q=this.rules.other.listItemRegex(Y),X=!1;for(;J;){let _=!1,z="",H="";if(!($=q.exec(J))||this.rules.block.hr.test(J))break;z=$[0],J=J.substring(z.length);let U=
|
|
16
|
+
`),F=this.list(K);q[q.length-1]=F,Z=Z.substring(0,Z.length-W.raw.length)+F.raw,Q=Q.substring(0,Q.length-N.raw.length)+F.raw,Y=K.substring(q.at(-1).raw.length).split(`
|
|
17
|
+
`);continue}}return{type:"blockquote",raw:Z,tokens:q,text:Q}}}list(J){let $=this.rules.block.list.exec(J);if($){let Y=$[1].trim(),Z=Y.length>1,Q={type:"list",raw:"",ordered:Z,start:Z?+Y.slice(0,-1):"",loose:!1,items:[]};Y=Z?`\\d{1,9}\\${Y.slice(-1)}`:`\\${Y}`,this.options.pedantic&&(Y=Z?Y:"[*+-]");let q=this.rules.other.listItemRegex(Y),X=!1;for(;J;){let _=!1,z="",H="";if(!($=q.exec(J))||this.rules.block.hr.test(J))break;z=$[0],J=J.substring(z.length);let U=w3($[2].split(`
|
|
18
18
|
`,1)[0],$[1].length),W=J.split(`
|
|
19
19
|
`,1)[0],N=!U.trim(),K=0;if(this.options.pedantic?(K=2,H=U.trimStart()):N?K=$[1].length+1:(K=U.search(this.rules.other.nonSpaceChar),K=K>4?1:K,H=U.slice(K),K+=$[1].length),N&&this.rules.other.blankLine.test(W)&&(z+=W+`
|
|
20
|
-
`,J=J.substring(W.length+1),_=!0),!_){let
|
|
21
|
-
`,1)[0],
|
|
22
|
-
`+
|
|
23
|
-
`+W}N=!W.trim(),z+=
|
|
24
|
-
`,J=J.substring(
|
|
25
|
-
`):[],q={type:"table",raw:$[0],header:[],align:[],rows:[]};if(Y.length===Z.length){for(let X of Z)this.rules.other.tableAlignRight.test(X)?q.align.push("right"):this.rules.other.tableAlignCenter.test(X)?q.align.push("center"):this.rules.other.tableAlignLeft.test(X)?q.align.push("left"):q.align.push(null);for(let X=0;X<Y.length;X++)q.header.push({text:Y[X],tokens:this.lexer.inline(Y[X]),header:!0,align:q.align[X]});for(let X of Q)q.rows.push(
|
|
26
|
-
`?$[1].slice(0,-1):$[1];return{type:"paragraph",raw:$[0],text:Y,tokens:this.lexer.inline(Y)}}}text(J){let $=this.rules.block.text.exec(J);if($)return{type:"text",raw:$[0],text:$[0],tokens:this.lexer.inline($[0])}}escape(J){let $=this.rules.inline.escape.exec(J);if($)return{type:"escape",raw:$[0],text:$[1]}}tag(J){let $=this.rules.inline.tag.exec(J);if($)return!this.lexer.state.inLink&&this.rules.other.startATag.test($[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test($[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test($[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test($[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:$[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:$[0]}}link(J){let $=this.rules.inline.link.exec(J);if($){let Y=$[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(Y)){if(!this.rules.other.endAngleBracket.test(Y))return;let q=
|
|
27
|
-
`),this.blockTokens($,this.tokens);for(let Y=0;Y<this.inlineQueue.length;Y++){let Z=this.inlineQueue[Y];this.inlineTokens(Z.src,Z.tokens)}return this.inlineQueue=[],this.tokens}blockTokens($,Y=[],Z=!1){for(this.options.pedantic&&($=$.replace(
|
|
20
|
+
`,J=J.substring(W.length+1),_=!0),!_){let F=this.rules.other.nextBulletRegex(K),T=this.rules.other.hrRegex(K),M=this.rules.other.fencesBeginRegex(K),L=this.rules.other.headingBeginRegex(K),j=this.rules.other.htmlBeginRegex(K),k=this.rules.other.blockquoteBeginRegex(K);for(;J;){let B=J.split(`
|
|
21
|
+
`,1)[0],w;if(W=B,this.options.pedantic?(W=W.replace(this.rules.other.listReplaceNesting," "),w=W):w=W.replace(this.rules.other.tabCharGlobal," "),M.test(W)||L.test(W)||j.test(W)||k.test(W)||F.test(W)||T.test(W))break;if(w.search(this.rules.other.nonSpaceChar)>=K||!W.trim())H+=`
|
|
22
|
+
`+w.slice(K);else{if(N||U.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||M.test(U)||L.test(U)||T.test(U))break;H+=`
|
|
23
|
+
`+W}N=!W.trim(),z+=B+`
|
|
24
|
+
`,J=J.substring(B.length+1),U=w.slice(K)}}Q.loose||(X?Q.loose=!0:this.rules.other.doubleBlankLine.test(z)&&(X=!0)),Q.items.push({type:"list_item",raw:z,task:!!this.options.gfm&&this.rules.other.listIsTask.test(H),loose:!1,text:H,tokens:[]}),Q.raw+=z}let G=Q.items.at(-1);if(G)G.raw=G.raw.trimEnd(),G.text=G.text.trimEnd();else return;Q.raw=Q.raw.trimEnd();for(let _ of Q.items){if(this.lexer.state.top=!1,_.tokens=this.lexer.blockTokens(_.text,[]),_.task){if(_.text=_.text.replace(this.rules.other.listReplaceTask,""),_.tokens[0]?.type==="text"||_.tokens[0]?.type==="paragraph"){_.tokens[0].raw=_.tokens[0].raw.replace(this.rules.other.listReplaceTask,""),_.tokens[0].text=_.tokens[0].text.replace(this.rules.other.listReplaceTask,"");for(let H=this.lexer.inlineQueue.length-1;H>=0;H--)if(this.rules.other.listIsTask.test(this.lexer.inlineQueue[H].src)){this.lexer.inlineQueue[H].src=this.lexer.inlineQueue[H].src.replace(this.rules.other.listReplaceTask,"");break}}let z=this.rules.other.listTaskCheckbox.exec(_.raw);if(z){let H={type:"checkbox",raw:z[0]+" ",checked:z[0]!=="[ ]"};_.checked=H.checked,Q.loose?_.tokens[0]&&["paragraph","text"].includes(_.tokens[0].type)&&"tokens"in _.tokens[0]&&_.tokens[0].tokens?(_.tokens[0].raw=H.raw+_.tokens[0].raw,_.tokens[0].text=H.raw+_.tokens[0].text,_.tokens[0].tokens.unshift(H)):_.tokens.unshift({type:"paragraph",raw:H.raw,text:H.raw,tokens:[H]}):_.tokens.unshift(H)}}if(!Q.loose){let z=_.tokens.filter((U)=>U.type==="space"),H=z.length>0&&z.some((U)=>this.rules.other.anyLine.test(U.raw));Q.loose=H}}if(Q.loose)for(let _ of Q.items){_.loose=!0;for(let z of _.tokens)z.type==="text"&&(z.type="paragraph")}return Q}}html(J){let $=this.rules.block.html.exec(J);if($)return{type:"html",block:!0,raw:$[0],pre:$[1]==="pre"||$[1]==="script"||$[1]==="style",text:$[0]}}def(J){let $=this.rules.block.def.exec(J);if($){let Y=$[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal," "),Z=$[2]?$[2].replace(this.rules.other.hrefBrackets,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",Q=$[3]?$[3].substring(1,$[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):$[3];return{type:"def",tag:Y,raw:$[0],href:Z,title:Q}}}table(J){let $=this.rules.block.table.exec(J);if(!$||!this.rules.other.tableDelimiter.test($[2]))return;let Y=M5($[1]),Z=$[2].replace(this.rules.other.tableAlignChars,"").split("|"),Q=$[3]?.trim()?$[3].replace(this.rules.other.tableRowBlankLine,"").split(`
|
|
25
|
+
`):[],q={type:"table",raw:$[0],header:[],align:[],rows:[]};if(Y.length===Z.length){for(let X of Z)this.rules.other.tableAlignRight.test(X)?q.align.push("right"):this.rules.other.tableAlignCenter.test(X)?q.align.push("center"):this.rules.other.tableAlignLeft.test(X)?q.align.push("left"):q.align.push(null);for(let X=0;X<Y.length;X++)q.header.push({text:Y[X],tokens:this.lexer.inline(Y[X]),header:!0,align:q.align[X]});for(let X of Q)q.rows.push(M5(X,q.header.length).map((G,_)=>({text:G,tokens:this.lexer.inline(G),header:!1,align:q.align[_]})));return q}}lheading(J){let $=this.rules.block.lheading.exec(J);if($)return{type:"heading",raw:$[0],depth:$[2].charAt(0)==="="?1:2,text:$[1],tokens:this.lexer.inline($[1])}}paragraph(J){let $=this.rules.block.paragraph.exec(J);if($){let Y=$[1].charAt($[1].length-1)===`
|
|
26
|
+
`?$[1].slice(0,-1):$[1];return{type:"paragraph",raw:$[0],text:Y,tokens:this.lexer.inline(Y)}}}text(J){let $=this.rules.block.text.exec(J);if($)return{type:"text",raw:$[0],text:$[0],tokens:this.lexer.inline($[0])}}escape(J){let $=this.rules.inline.escape.exec(J);if($)return{type:"escape",raw:$[0],text:$[1]}}tag(J){let $=this.rules.inline.tag.exec(J);if($)return!this.lexer.state.inLink&&this.rules.other.startATag.test($[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test($[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test($[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test($[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:$[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:$[0]}}link(J){let $=this.rules.inline.link.exec(J);if($){let Y=$[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(Y)){if(!this.rules.other.endAngleBracket.test(Y))return;let q=t1(Y.slice(0,-1),"\\");if((Y.length-q.length)%2===0)return}else{let q=b3($[2],"()");if(q===-2)return;if(q>-1){let X=($[0].indexOf("!")===0?5:4)+$[1].length+q;$[2]=$[2].substring(0,q),$[0]=$[0].substring(0,X).trim(),$[3]=""}}let Z=$[2],Q="";if(this.options.pedantic){let q=this.rules.other.pedanticHrefTitle.exec(Z);q&&(Z=q[1],Q=q[3])}else Q=$[3]?$[3].slice(1,-1):"";return Z=Z.trim(),this.rules.other.startAngleBracket.test(Z)&&(this.options.pedantic&&!this.rules.other.endAngleBracket.test(Y)?Z=Z.slice(1):Z=Z.slice(1,-1)),B5($,{href:Z&&Z.replace(this.rules.inline.anyPunctuation,"$1"),title:Q&&Q.replace(this.rules.inline.anyPunctuation,"$1")},$[0],this.lexer,this.rules)}}reflink(J,$){let Y;if((Y=this.rules.inline.reflink.exec(J))||(Y=this.rules.inline.nolink.exec(J))){let Z=(Y[2]||Y[1]).replace(this.rules.other.multipleSpaceGlobal," "),Q=$[Z.toLowerCase()];if(!Q){let q=Y[0].charAt(0);return{type:"text",raw:q,text:q}}return B5(Y,Q,Y[0],this.lexer,this.rules)}}emStrong(J,$,Y=""){let Z=this.rules.inline.emStrongLDelim.exec(J);if(!Z||Z[3]&&Y.match(this.rules.other.unicodeAlphaNumeric))return;if(!(Z[1]||Z[2])||!Y||this.rules.inline.punctuation.exec(Y)){let Q=[...Z[0]].length-1,q,X,G=Q,_=0,z=Z[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(z.lastIndex=0,$=$.slice(-1*J.length+Q);(Z=z.exec($))!=null;){if(q=Z[1]||Z[2]||Z[3]||Z[4]||Z[5]||Z[6],!q)continue;if(X=[...q].length,Z[3]||Z[4]){G+=X;continue}else if((Z[5]||Z[6])&&Q%3&&!((Q+X)%3)){_+=X;continue}if(G-=X,G>0)continue;X=Math.min(X,X+G+_);let H=[...Z[0]][0].length,U=J.slice(0,Q+Z.index+H+X);if(Math.min(Q,X)%2){let N=U.slice(1,-1);return{type:"em",raw:U,text:N,tokens:this.lexer.inlineTokens(N)}}let W=U.slice(2,-2);return{type:"strong",raw:U,text:W,tokens:this.lexer.inlineTokens(W)}}}}codespan(J){let $=this.rules.inline.code.exec(J);if($){let Y=$[2].replace(this.rules.other.newLineCharGlobal," "),Z=this.rules.other.nonSpaceChar.test(Y),Q=this.rules.other.startingSpaceChar.test(Y)&&this.rules.other.endingSpaceChar.test(Y);return Z&&Q&&(Y=Y.substring(1,Y.length-1)),{type:"codespan",raw:$[0],text:Y}}}br(J){let $=this.rules.inline.br.exec(J);if($)return{type:"br",raw:$[0]}}del(J,$,Y=""){let Z=this.rules.inline.delLDelim.exec(J);if(!Z)return;if(!Z[1]||!Y||this.rules.inline.punctuation.exec(Y)){let Q=[...Z[0]].length-1,q,X,G=Q,_=this.rules.inline.delRDelim;for(_.lastIndex=0,$=$.slice(-1*J.length+Q);(Z=_.exec($))!=null;){if(q=Z[1]||Z[2]||Z[3]||Z[4]||Z[5]||Z[6],!q||(X=[...q].length,X!==Q))continue;if(Z[3]||Z[4]){G+=X;continue}if(G-=X,G>0)continue;X=Math.min(X,X+G);let z=[...Z[0]][0].length,H=J.slice(0,Q+Z.index+z+X),U=H.slice(Q,-Q);return{type:"del",raw:H,text:U,tokens:this.lexer.inlineTokens(U)}}}}autolink(J){let $=this.rules.inline.autolink.exec(J);if($){let Y,Z;return $[2]==="@"?(Y=$[1],Z="mailto:"+Y):(Y=$[1],Z=Y),{type:"link",raw:$[0],text:Y,href:Z,tokens:[{type:"text",raw:Y,text:Y}]}}}url(J){let $;if($=this.rules.inline.url.exec(J)){let Y,Z;if($[2]==="@")Y=$[0],Z="mailto:"+Y;else{let Q;do Q=$[0],$[0]=this.rules.inline._backpedal.exec($[0])?.[0]??"";while(Q!==$[0]);Y=$[0],$[1]==="www."?Z="http://"+$[0]:Z=$[0]}return{type:"link",raw:$[0],text:Y,href:Z,tokens:[{type:"text",raw:Y,text:Y}]}}}inlineText(J){let $=this.rules.inline.text.exec(J);if($){let Y=this.lexer.state.inRawBlock;return{type:"text",raw:$[0],text:$[0],escaped:Y}}}},z1=class J{tokens;options;state;inlineQueue;tokenizer;constructor($){this.tokens=[],this.tokens.links=Object.create(null),this.options=$||k1,this.options.tokenizer=this.options.tokenizer||new W0,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};let Y={other:X1,block:K0.normal,inline:s1.normal};this.options.pedantic?(Y.block=K0.pedantic,Y.inline=s1.pedantic):this.options.gfm&&(Y.block=K0.gfm,this.options.breaks?Y.inline=s1.breaks:Y.inline=s1.gfm),this.tokenizer.rules=Y}static get rules(){return{block:K0,inline:s1}}static lex($,Y){return new J(Y).lex($)}static lexInline($,Y){return new J(Y).inlineTokens($)}lex($){$=$.replace(X1.carriageReturn,`
|
|
27
|
+
`),this.blockTokens($,this.tokens);for(let Y=0;Y<this.inlineQueue.length;Y++){let Z=this.inlineQueue[Y];this.inlineTokens(Z.src,Z.tokens)}return this.inlineQueue=[],this.tokens}blockTokens($,Y=[],Z=!1){for(this.options.pedantic&&($=$.replace(X1.tabCharGlobal," ").replace(X1.spaceLine,""));$;){let Q;if(this.options.extensions?.block?.some((X)=>(Q=X.call({lexer:this},$,Y))?($=$.substring(Q.raw.length),Y.push(Q),!0):!1))continue;if(Q=this.tokenizer.space($)){$=$.substring(Q.raw.length);let X=Y.at(-1);Q.raw.length===1&&X!==void 0?X.raw+=`
|
|
28
28
|
`:Y.push(Q);continue}if(Q=this.tokenizer.code($)){$=$.substring(Q.raw.length);let X=Y.at(-1);X?.type==="paragraph"||X?.type==="text"?(X.raw+=(X.raw.endsWith(`
|
|
29
29
|
`)?"":`
|
|
30
30
|
`)+Q.raw,X.text+=`
|
|
@@ -37,7 +37,7 @@ ${H}`:H;let U=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTo
|
|
|
37
37
|
`+Q.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=X.text):Y.push(Q),Z=q.length!==$.length,$=$.substring(Q.raw.length);continue}if(Q=this.tokenizer.text($)){$=$.substring(Q.raw.length);let X=Y.at(-1);X?.type==="text"?(X.raw+=(X.raw.endsWith(`
|
|
38
38
|
`)?"":`
|
|
39
39
|
`)+Q.raw,X.text+=`
|
|
40
|
-
`+Q.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=X.text):Y.push(Q);continue}if($){let X="Infinite loop on byte: "+$.charCodeAt(0);if(this.options.silent){console.error(X);break}else throw Error(X)}}return this.state.top=!0,Y}inline($,Y=[]){return this.inlineQueue.push({src:$,tokens:Y}),Y}inlineTokens($,Y=[]){let Z=$,Q=null;if(this.tokens.links){let _=Object.keys(this.tokens.links);if(_.length>0)for(;(Q=this.tokenizer.rules.inline.reflinkSearch.exec(Z))!=null;)_.includes(Q[0].slice(Q[0].lastIndexOf("[")+1,-1))&&(Z=Z.slice(0,Q.index)+"["+"a".repeat(Q[0].length-2)+"]"+Z.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(Q=this.tokenizer.rules.inline.anyPunctuation.exec(Z))!=null;)Z=Z.slice(0,Q.index)+"++"+Z.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);let q;for(;(Q=this.tokenizer.rules.inline.blockSkip.exec(Z))!=null;)q=Q[2]?Q[2].length:0,Z=Z.slice(0,Q.index+q)+"["+"a".repeat(Q[0].length-q-2)+"]"+Z.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);Z=this.options.hooks?.emStrongMask?.call({lexer:this},Z)??Z;let X=!1,G="";for(;$;){X||(G=""),X=!1;let _;if(this.options.extensions?.inline?.some((H)=>(_=H.call({lexer:this},$,Y))?($=$.substring(_.raw.length),Y.push(_),!0):!1))continue;if(_=this.tokenizer.escape($)){$=$.substring(_.raw.length),Y.push(_);continue}if(_=this.tokenizer.tag($)){$=$.substring(_.raw.length),Y.push(_);continue}if(_=this.tokenizer.link($)){$=$.substring(_.raw.length),Y.push(_);continue}if(_=this.tokenizer.reflink($,this.tokens.links)){$=$.substring(_.raw.length);let H=Y.at(-1);_.type==="text"&&H?.type==="text"?(H.raw+=_.raw,H.text+=_.text):Y.push(_);continue}if(_=this.tokenizer.emStrong($,Z,G)){$=$.substring(_.raw.length),Y.push(_);continue}if(_=this.tokenizer.codespan($)){$=$.substring(_.raw.length),Y.push(_);continue}if(_=this.tokenizer.br($)){$=$.substring(_.raw.length),Y.push(_);continue}if(_=this.tokenizer.del($,Z,G)){$=$.substring(_.raw.length),Y.push(_);continue}if(_=this.tokenizer.autolink($)){$=$.substring(_.raw.length),Y.push(_);continue}if(!this.state.inLink&&(_=this.tokenizer.url($))){$=$.substring(_.raw.length),Y.push(_);continue}let z=$;if(this.options.extensions?.startInline){let H=1/0,U=$.slice(1),W;this.options.extensions.startInline.forEach((N)=>{W=N.call({lexer:this},U),typeof W=="number"&&W>=0&&(H=Math.min(H,W))}),H<1/0&&H>=0&&(z=$.substring(0,H+1))}if(_=this.tokenizer.inlineText(z)){$=$.substring(_.raw.length),_.raw.slice(-1)!=="_"&&(G=_.raw.slice(-1)),X=!0;let H=Y.at(-1);H?.type==="text"?(H.raw+=_.raw,H.text+=_.text):Y.push(_);continue}if($){let H="Infinite loop on byte: "+$.charCodeAt(0);if(this.options.silent){console.error(H);break}else throw Error(H)}}return Y}},
|
|
40
|
+
`+Q.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=X.text):Y.push(Q);continue}if($){let X="Infinite loop on byte: "+$.charCodeAt(0);if(this.options.silent){console.error(X);break}else throw Error(X)}}return this.state.top=!0,Y}inline($,Y=[]){return this.inlineQueue.push({src:$,tokens:Y}),Y}inlineTokens($,Y=[]){let Z=$,Q=null;if(this.tokens.links){let _=Object.keys(this.tokens.links);if(_.length>0)for(;(Q=this.tokenizer.rules.inline.reflinkSearch.exec(Z))!=null;)_.includes(Q[0].slice(Q[0].lastIndexOf("[")+1,-1))&&(Z=Z.slice(0,Q.index)+"["+"a".repeat(Q[0].length-2)+"]"+Z.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(Q=this.tokenizer.rules.inline.anyPunctuation.exec(Z))!=null;)Z=Z.slice(0,Q.index)+"++"+Z.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);let q;for(;(Q=this.tokenizer.rules.inline.blockSkip.exec(Z))!=null;)q=Q[2]?Q[2].length:0,Z=Z.slice(0,Q.index+q)+"["+"a".repeat(Q[0].length-q-2)+"]"+Z.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);Z=this.options.hooks?.emStrongMask?.call({lexer:this},Z)??Z;let X=!1,G="";for(;$;){X||(G=""),X=!1;let _;if(this.options.extensions?.inline?.some((H)=>(_=H.call({lexer:this},$,Y))?($=$.substring(_.raw.length),Y.push(_),!0):!1))continue;if(_=this.tokenizer.escape($)){$=$.substring(_.raw.length),Y.push(_);continue}if(_=this.tokenizer.tag($)){$=$.substring(_.raw.length),Y.push(_);continue}if(_=this.tokenizer.link($)){$=$.substring(_.raw.length),Y.push(_);continue}if(_=this.tokenizer.reflink($,this.tokens.links)){$=$.substring(_.raw.length);let H=Y.at(-1);_.type==="text"&&H?.type==="text"?(H.raw+=_.raw,H.text+=_.text):Y.push(_);continue}if(_=this.tokenizer.emStrong($,Z,G)){$=$.substring(_.raw.length),Y.push(_);continue}if(_=this.tokenizer.codespan($)){$=$.substring(_.raw.length),Y.push(_);continue}if(_=this.tokenizer.br($)){$=$.substring(_.raw.length),Y.push(_);continue}if(_=this.tokenizer.del($,Z,G)){$=$.substring(_.raw.length),Y.push(_);continue}if(_=this.tokenizer.autolink($)){$=$.substring(_.raw.length),Y.push(_);continue}if(!this.state.inLink&&(_=this.tokenizer.url($))){$=$.substring(_.raw.length),Y.push(_);continue}let z=$;if(this.options.extensions?.startInline){let H=1/0,U=$.slice(1),W;this.options.extensions.startInline.forEach((N)=>{W=N.call({lexer:this},U),typeof W=="number"&&W>=0&&(H=Math.min(H,W))}),H<1/0&&H>=0&&(z=$.substring(0,H+1))}if(_=this.tokenizer.inlineText(z)){$=$.substring(_.raw.length),_.raw.slice(-1)!=="_"&&(G=_.raw.slice(-1)),X=!0;let H=Y.at(-1);H?.type==="text"?(H.raw+=_.raw,H.text+=_.text):Y.push(_);continue}if($){let H="Infinite loop on byte: "+$.charCodeAt(0);if(this.options.silent){console.error(H);break}else throw Error(H)}}return Y}},N0=class{options;parser;constructor(J){this.options=J||k1}space(J){return""}code({text:J,lang:$,escaped:Y}){let Z=($||"").match(X1.notSpaceStart)?.[0],Q=J.replace(X1.endingNewline,"")+`
|
|
41
41
|
`;return Z?'<pre><code class="language-'+K1(Z)+'">'+(Y?Q:K1(Q,!0))+`</code></pre>
|
|
42
42
|
`:"<pre><code>"+(Y?Q:K1(Q,!0))+`</code></pre>
|
|
43
43
|
`}blockquote({tokens:J}){return`<blockquote>
|
|
@@ -55,37 +55,37 @@ ${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),Y=J.header?"th":"td";return(J.align?`<${Y} align="${J.align}">`:`<${Y}>`)+$+`</${Y}>
|
|
58
|
-
`}strong({tokens:J}){return`<strong>${this.parser.parseInline(J)}</strong>`}em({tokens:J}){return`<em>${this.parser.parseInline(J)}</em>`}codespan({text:J}){return`<code>${K1(J,!0)}</code>`}br(J){return"<br>"}del({tokens:J}){return`<del>${this.parser.parseInline(J)}</del>`}link({href:J,title:$,tokens:Y}){let Z=this.parser.parseInline(Y),Q=
|
|
59
|
-
Please report this to https://github.com/markedjs/marked.`,J){let Z="<p>An error occurred:</p><pre>"+K1(Y.message+"",!0)+"</pre>";return $?Promise.resolve(Z):Z}if($)return Promise.reject(Y);throw Y}}},k1=new w3;function a(J,$){return k1.parse(J,$)}a.options=a.setOptions=function(J){return k1.setOptions(J),a.defaults=k1.defaults,M5(a.defaults),a};a.getDefaults=f0;a.defaults=V1;a.use=function(...J){return k1.use(...J),a.defaults=k1.defaults,M5(a.defaults),a};a.walkTokens=function(J,$){return k1.walkTokens(J,$)};a.parseInline=k1.parseInline;a.Parser=G1;a.parser=G1.parse;a.Renderer=W0;a.TextRenderer=a0;a.Lexer=z1;a.lexer=z1.lex;a.Tokenizer=H0;a.Hooks=t1;a.parse=a;var{options:A4,setOptions:I4,use:C4,walkTokens:j4,parseInline:R4}=a;var k4=G1.parse,V4=z1.lex;import{SessionContext as m2,ActiveViewCtx as y4}from"#canvas/runtime";import{useState as $0,useCallback as H1,useEffect as A3,useRef as I3}from"react";import{AnnotationCtx as C3}from"#canvas/runtime";var q1="__agent-response__";function U1(){return`ann-${Date.now()}-${Math.random().toString(36).slice(2,6)}`}function e1(J,$){J.style.height="auto",J.style.height=($?Math.max($,J.scrollHeight):J.scrollHeight)+"px"}import{useAnnotations as e}from"#canvas/runtime";import{jsxDEV as V3}from"react/jsx-dev-runtime";function o0(J,$){return`canvas:${J}:rev:${$}`}function O0(J,$){try{let Y=localStorage.getItem(o0(J,$));if(!Y)return null;return JSON.parse(Y)}catch{return null}}function j3(J,$,Y){try{localStorage.setItem(o0(J,$),JSON.stringify(Y))}catch{}}function R3(J,$){try{localStorage.removeItem(o0(J,$))}catch{}}function D5({sessionId:J,revision:$,isReadOnly:Y,children:Z}){let[Q,q]=$0(()=>{return O0(J,$)?.annotations??[]}),[X,G]=$0(()=>{return O0(J,$)?.generalNote??""}),[_,z]=$0(null),[H,U]=$0(()=>{let C=O0(J,$);return C?.responses?new Map(C.responses):new Map}),[W,N]=$0(()=>{let C=O0(J,$);return C?.feedbackEntries?new Map(C.feedbackEntries):new Map}),K=I3(null);A3(()=>{if(Y)return;if(K.current)clearTimeout(K.current);return K.current=setTimeout(()=>{j3(J,$,{annotations:Q,generalNote:X,responses:Array.from(H.entries()),feedbackEntries:Array.from(W.entries())})},300),()=>{if(K.current)clearTimeout(K.current)}},[Q,X,H,W,J,$,Y]);let T=H1((C,R,v,m,c,y,P)=>{q((x)=>[...x,{id:C,snippet:R,note:v,createdAt:new Date().toISOString(),filePath:m,context:c,...y?.length?{images:y}:{},...P?{canvasFile:P}:{}}])},[]),O=H1((C,R,v)=>{T(U1(),C,R,v)},[T]),S=H1((C,R)=>{q((v)=>v.map((m)=>m.id===C?{...m,note:R}:m))},[]),L=H1((C)=>{k3(C),q((R)=>R.filter((v)=>v.id!==C)),z((R)=>R===C?null:R)},[]),j=H1((C,R)=>{q((v)=>v.map((m)=>m.id===C?{...m,images:[...m.images||[],R]}:m))},[]),V=H1((C,R)=>{q((v)=>v.map((m)=>m.id===C?{...m,images:(m.images||[]).filter((c)=>c!==R)}:m))},[]),M=H1((C,R)=>{U((v)=>{let m=new Map(v);return m.set(C,R),m})},[]),I=H1((C,R)=>{N((v)=>{let m=v.get(C);if(m&&m.markdown===R.markdown&&m.label===R.label&&m.required===R.required)return v;let c=new Map(v);return c.set(C,R),c})},[]),D=H1((C)=>{N((R)=>{if(!R.has(C))return R;let v=new Map(R);return v.delete(C),v})},[]),E=H1(()=>{for(let C of document.querySelectorAll("[data-annotation-id]"))m5(C);q([]),G(""),z(null),U(new Map),N(new Map),R3(J,$)},[J,$]);return V3(C3.Provider,{value:{annotations:Q,addAnnotation:O,addAnnotationWithId:T,updateAnnotation:S,removeAnnotation:L,addAnnotationImage:j,removeAnnotationImage:V,generalNote:X,setGeneralNote:G,clearAll:E,activeAnnotationId:_,setActiveAnnotationId:z,responses:H,setResponse:M,feedbackEntries:W,setFeedbackEntry:I,removeFeedbackEntry:D},children:Z},void 0,!1,void 0,this)}function k3(J){let $=document.querySelectorAll(`[data-annotation-id="${J}"]`);for(let Y of $)m5(Y)}function m5(J){let $=J.parentNode;if(!$)return;let Y=document.createTextNode(J.textContent||"");$.replaceChild(Y,J),$.normalize()}import J5,{useEffect as x1,useState as W1,useRef as r3,useContext as l3,useMemo as J0}from"react";import{createPortal as i3}from"react-dom";import{SessionContext as a3,CanvasFileCtx as o3}from"#canvas/runtime";function D1(J,$){let Y=g5(J,"before",60),Z=g5(J,"after",60),Q=m3(J.startContainer,$);return{before:Y,after:Z,hierarchy:Q}}function g5(J,$,Y){let Z=D3($==="before"?J.startContainer:J.endContainer);if(!Z)return"";let Q="";if($==="before"){let q=document.createTreeWalker(Z,NodeFilter.SHOW_TEXT),X;while(X=q.nextNode()){if(X===J.startContainer){Q+=(X.textContent||"").slice(0,J.startOffset);break}if(X.parentElement?.hasAttribute("data-annotation-id"))continue;Q+=X.textContent||""}if(Q.length>Y){Q=Q.slice(-Y);let G=Q.indexOf(" ");if(G>0)Q=Q.slice(G+1)}}else{let q=document.createTreeWalker(Z,NodeFilter.SHOW_TEXT),X=!1,G;while(G=q.nextNode()){if(G===J.endContainer){Q+=(G.textContent||"").slice(J.endOffset),X=!0;continue}if(X){if(G.parentElement?.hasAttribute("data-annotation-id"))continue;Q+=G.textContent||""}}if(Q.length>Y){Q=Q.slice(0,Y);let _=Q.lastIndexOf(" ");if(_>0)Q=Q.slice(0,_)}}return Q.trim()}function D3(J){let $=new Set(["DIV","P","LI","PRE","BLOCKQUOTE","SECTION","ARTICLE"]),Y=J.parentElement;while(Y){if($.has(Y.tagName))return Y;Y=Y.parentElement}return null}function m3(J,$){let Y=[],Z=J instanceof Element?J:J.parentElement;while(Z&&Z!==$){let Q=Z.getAttribute?.("data-task-id");if(Q){let q=Z.querySelector(".font-semibold");if(q)Y.unshift(q.textContent?.trim()||Q)}if(Z.tagName==="DIV"&&Z.querySelector(":scope > button .font-heading, :scope > div .font-heading")){let q=Z.querySelector(".font-heading");if(q)Y.unshift(q.textContent?.trim()||"")}Z=Z.parentElement}return Y}function s0(J){let $=J.snippet.trim(),Y=J.context,Z=$.length<30;if(Y&&Z&&(Y.before||Y.after)){let Q=[];if(Y.before)Q.push(`...${Y.before} `);if(Q.push(`**${$}**`),Y.after)Q.push(` ${Y.after}...`);return Q.join("")}return $}import{useEffect as E3,useRef as B0,useState as p1,useCallback as L0,useMemo as x5,useContext as v3}from"react";import{createPortal as x3}from"react-dom";function u5(J,$){let Q=$||document.body,q=J.getBoundingClientRect(),X=Q.getBoundingClientRect(),G=Q===document.body?window.scrollY:Q.scrollTop,_=q.bottom-X.top+G+8,z=Math.max(0,Math.min(q.left-X.left,X.width-280-12));return Q.style.position="relative",{style:{position:"absolute",top:`${_}px`,left:`${z}px`},parent:Q}}import{useState as t0,useRef as n0,useCallback as O1,useEffect as g3}from"react";import{jsxDEV as J1}from"react/jsx-dev-runtime";function E5(J){return`/api/uploads/${J.split("/").pop()}`}async function u3(J,$){let Y=new FormData;Y.append("image",$);try{return(await(await fetch(`/api/session/${J}/upload`,{method:"POST",body:Y})).json()).path||null}catch{return null}}function F0({note:J,onNoteChange:$,images:Y,onAddImage:Z,onRemoveImage:Q,sessionId:q,placeholder:X="Add your note...",autoFocus:G=!1,autoResize:_=!1,readOnly:z=!1,onKeyDown:H,onTextareaClick:U,textareaRef:W,textareaClassName:N,textareaStyle:K,minHeight:T,attachButton:O="always",openFilePickerRef:S}){let[L,j]=t0(!1),[V,M]=t0(!1),[I,D]=t0(!1),E=n0(0),C=n0(null),R=n0(null),v=O1(()=>R.current?.click(),[]);if(S)S.current=v;let m=O1((k)=>{if(C.current=k,W)W.current=k;if(k&&_)e1(k,T)},[W,_,T]);g3(()=>{if(G&&C.current){let k=C.current;if(k.focus(),k.value)k.setSelectionRange(k.value.length,k.value.length)}},[G]);let c=O1(async(k)=>{if(!k.type.startsWith("image/"))return;M(!0);try{let r=await u3(q,k);if(r)Z(r)}finally{M(!1)}},[q,Z]),y=O1((k)=>{let r=k.clipboardData.items;for(let A of r)if(A.type.startsWith("image/")){k.preventDefault();let u=A.getAsFile();if(u)c(u);return}},[c]),P=O1((k)=>{if(k.preventDefault(),E.current++,E.current===1)j(!0)},[]),x=O1((k)=>{k.preventDefault()},[]),p=O1((k)=>{if(k.preventDefault(),E.current--,E.current===0)j(!1)},[]),B=O1((k)=>{k.preventDefault(),E.current=0,j(!1);for(let r of k.dataTransfer.files)if(r.type.startsWith("image/"))c(r)},[c]),b=O1((k)=>{if($(k.target.value),_)k.target.style.height="auto",k.target.style.height=(T?Math.max(T,k.target.scrollHeight):k.target.scrollHeight)+"px"},[$,_,T]),g="w-full bg-transparent text-[13px] font-body text-text-primary resize-none focus:outline-none leading-relaxed p-0 border-none",o={width:"100%",background:"transparent",border:"none",color:"var(--color-text-primary)",fontFamily:"'Inter', sans-serif",fontSize:"13px",lineHeight:"1.5",outline:"none",..._?{resize:"none",overflow:"hidden"}:{resize:"vertical"}},i=!z&&(O==="always"||O==="on-focus"&&I);return J1("div",{style:{position:"relative"},onDragEnter:z?void 0:P,onDragOver:z?void 0:x,onDragLeave:z?void 0:p,onDrop:z?void 0:B,children:[J1("textarea",{ref:m,value:J,onChange:z?void 0:b,onPaste:z?void 0:y,onKeyDown:H,onClick:U,onFocus:()=>D(!0),onBlur:()=>{setTimeout(()=>D(!1),150)},readOnly:z,placeholder:X,className:N??g,style:K??o,rows:_?1:void 0},void 0,!1,void 0,this),!z&&J1("input",{ref:R,type:"file",accept:"image/*",multiple:!0,style:{display:"none"},onChange:(k)=>{let r=k.target.files;if(r)for(let A of r)c(A);k.target.value=""}},void 0,!1,void 0,this),(Y.length>0||i)&&J1("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"6px",alignItems:"center"},children:[Y.map((k)=>J1("div",{style:{position:"relative",width:"56px",height:"56px",borderRadius:"6px",overflow:"hidden",border:"1px solid var(--color-border-subtle)",flexShrink:0},children:[J1("img",{src:E5(k),alt:"",style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}},void 0,!1,void 0,this),!z&&J1("button",{onClick:(r)=>{r.stopPropagation(),Q(k)},style:{position:"absolute",top:"2px",right:"2px",width:"16px",height:"16px",borderRadius:"50%",background:"rgba(0,0,0,0.6)",color:"white",border:"none",cursor:"pointer",fontSize:"11px",display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1,padding:0},title:"Remove image",children:"×"},void 0,!1,void 0,this)]},k,!0,void 0,this)),i&&J1(e0,{onClick:v},void 0,!1,void 0,this)]},void 0,!0,void 0,this),V&&J1("div",{style:{fontSize:"11px",color:"var(--color-text-tertiary)",fontFamily:"'Inter', sans-serif",marginTop:"4px"},children:"Uploading..."},void 0,!1,void 0,this),L&&J1("div",{style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",background:"var(--color-highlight-bg)",opacity:0.9,border:"2px dashed var(--color-highlight-border)",borderRadius:"6px",zIndex:10,pointerEvents:"none",fontSize:"12px",fontFamily:"'Inter', sans-serif",color:"var(--color-text-secondary)"},children:"Drop image"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function e0({onClick:J,size:$=16}){return J1("button",{onClick:(Y)=>{Y.stopPropagation(),J()},style:{width:`${$*2}px`,height:`${$*2}px`,borderRadius:"6px",border:"none",background:"transparent",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--color-text-tertiary)",flexShrink:0,transition:"color 0.15s"},title:"Attach image",onMouseEnter:(Y)=>{Y.currentTarget.style.color="var(--color-text-secondary)"},onMouseLeave:(Y)=>{Y.currentTarget.style.color="var(--color-text-tertiary)"},children:J1("svg",{width:$,height:$,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[J1("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"},void 0,!1,void 0,this),J1("circle",{cx:"8.5",cy:"8.5",r:"1.5"},void 0,!1,void 0,this),J1("polyline",{points:"21 15 16 10 5 21"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function v5({images:J}){if(!J.length)return null;return J1("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"6px"},children:J.map(($)=>J1("div",{style:{width:"56px",height:"56px",borderRadius:"6px",overflow:"hidden",border:"1px solid var(--color-border-subtle)",flexShrink:0},children:J1("img",{src:E5($),alt:"",style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}},void 0,!1,void 0,this)},$,!1,void 0,this))},void 0,!1,void 0,this)}import{SessionContext as f3}from"#canvas/runtime";import{jsxDEV as Y1,Fragment as p3}from"react/jsx-dev-runtime";function h3({anchorEl:J,scrollContainer:$,onClose:Y,ignoreSelector:Z,zIndex:Q="50",padding:q="12px",width:X="280px",children:G}){let _=B0(null),z=B0(Y);z.current=Y;let{style:H,parent:U}=u5(J,$);return E3(()=>{let W=setTimeout(()=>{let N=(K)=>{if(_.current&&!_.current.contains(K.target)){if(Z&&K.target.closest?.(Z))return;z.current(),document.removeEventListener("mousedown",N)}};return document.addEventListener("mousedown",N),()=>document.removeEventListener("mousedown",N)},0);return()=>clearTimeout(W)},[Z]),x3(Y1("div",{ref:_,style:{...H,zIndex:Q,width:X,background:"var(--color-bg-elevated)",border:"1px solid var(--color-border-hover)",borderRadius:"8px",boxShadow:"0 4px 12px var(--color-shadow)",padding:q,fontFamily:"'Inter', sans-serif"},children:G},void 0,!1,void 0,this),U)}var h5=[{label:"Clarity",items:["Unclear","Why?","Needs example","Missing context"]},{label:"Scope",items:["Overkill","Out of scope","Important","Risky"]},{label:"Action",items:["Simplify","Rethink","Expand on this","Skip this"]}],f5=h5.flatMap((J)=>J.items);function p5({anchorEl:J,scrollContainer:$,snippet:Y,truncateAt:Z=100,header:Q,initialNote:q="",initialImages:X,onConfirm:G,onCancel:_,onDelete:z}){let H=v3(f3),U=q!==""||!!z,[W,N]=p1(q),[K,T]=p1(X||[]),[O,S]=p1(null),[L,j]=p1(U),[V,M]=p1(!1),I=B0(null),D=B0(null),E=L0(()=>{if(W.trim()||K.length>0)G(W.trim(),K);else if(U&&z)z();else _()},[W,K,G,_,U,z]),C=L0(()=>{if(U){if(!W.trim()&&K.length===0&&z){z(),_();return}G(W,K);return}_()},[W,K,U,G,_,z]),R=!U,v=W.trim().length>0?f5.filter((A)=>A.toLowerCase().startsWith(W.trim().toLowerCase())):f5,m=!R||L?[]:v.length===1&&v[0].toLowerCase()===W.trim().toLowerCase()?[]:v,c=new Set(m),y=h5.map((A)=>({label:A.label,items:A.items.filter((u)=>c.has(u))})).filter((A)=>A.items.length>0),P=y.map((A)=>A.items),x=P.flat(),p=x5(()=>{if(O===null)return 0;let A=0;for(let u=0;u<P.length;u++){if(O<A+P[u].length)return u;A+=P[u].length}return 0},[O,P]),B=x5(()=>{if(O===null)return 0;let A=0;for(let u=0;u<p;u++)A+=P[u].length;return O-A},[O,p,P]),b=(A,u)=>{let s=0;for(let _1=0;_1<A;_1++)s+=P[_1].length;return s+u},[g,o]=p1(W);if(W!==g)o(W),S(null),j(U);let i=L0((A)=>{N(A)},[]),k=Y.length>Z?Y.slice(0,Z)+"...":Y,r=L0((A)=>{if(x.length>0&&(A.key==="ArrowDown"||A.key==="ArrowUp"||A.key==="ArrowLeft"||A.key==="ArrowRight")){if(A.preventDefault(),O===null){S(0);return}if(A.key==="ArrowDown"){let u=Math.min(B+1,P[p].length-1);S(b(p,u))}else if(A.key==="ArrowUp"){let u=Math.max(B-1,0);S(b(p,u))}else if(A.key==="ArrowRight"){let u=Math.min(p+1,P.length-1),s=Math.min(B,P[u].length-1);S(b(u,s))}else if(A.key==="ArrowLeft"){let u=Math.max(p-1,0),s=Math.min(B,P[u].length-1);S(b(u,s))}return}if(O!==null&&x.length>0){if(A.key==="Tab"){A.preventDefault(),i(x[O]);return}if(A.key==="Enter"&&!A.shiftKey){A.preventDefault(),G(x[O],K);return}}if(A.key==="Enter"&&!A.shiftKey){A.preventDefault(),E();return}if(A.key==="Escape")if(x.length>0&&!L)j(!0);else if(U)C();else _()},[x,O,B,p,P,b,i,G,K,E,L,U,C,_]);return Y1(h3,{anchorEl:J,scrollContainer:$,onClose:U?C:_,ignoreSelector:U?"[data-annotation-id]":void 0,zIndex:U?"60":"50",padding:U?"10px 12px":"12px",width:"420px",children:[!U&&(Q??Y1("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:["“",k,"”"]},void 0,!0,void 0,this)),Y1(F0,{note:W,onNoteChange:N,images:K,onAddImage:(A)=>T((u)=>[...u,A]),onRemoveImage:(A)=>T((u)=>u.filter((s)=>s!==A)),sessionId:H,autoFocus:!0,autoResize:U,textareaRef:I,onKeyDown:r,attachButton:"none",openFilePickerRef:D,textareaStyle:U?{width:"100%",background:"transparent",border:"none",color:"var(--color-text-primary)",fontFamily:"'Inter', sans-serif",fontSize:"13px",lineHeight:"1.5",resize:"none",outline:"none",overflow:"hidden"}:{width:"100%",minHeight:"60px",background:"transparent",border:"none",color:"var(--color-text-primary)",fontFamily:"'Inter', sans-serif",fontSize:"13px",lineHeight:"1.5",resize:"vertical",outline:"none"},placeholder:"Add your note..."},void 0,!1,void 0,this),Y1("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginTop:U?"6px":"8px"},children:[Y1(e0,{onClick:()=>D.current?.(),size:14},void 0,!1,void 0,this),Y1("div",{style:{flex:1}},void 0,!1,void 0,this),U?Y1("button",{onClick:()=>{if(z)z();_()},onMouseEnter:()=>M(!0),onMouseLeave:()=>M(!1),style:{fontSize:"11px",color:V?"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):Y1(p3,{children:[Y1("button",{onClick:_,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),Y1("button",{onClick:E,style:{fontSize:"11px",fontWeight:500,padding:"4px 12px",borderRadius:"6px",background:"var(--color-highlight-bg)",color:"var(--color-text-primary)",border:"1px solid var(--color-highlight-border)",cursor:"pointer",fontFamily:"'Inter', sans-serif"},children:"Add"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),x.length>0&&Y1("div",{style:{marginTop:"6px",borderTop:"1px solid var(--color-border-subtle)",paddingTop:"8px",display:"flex",gap:"4px"},children:y.map((A)=>Y1("div",{style:{flex:1},children:[Y1("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:A.label},void 0,!1,void 0,this),A.items.map((u)=>{let s=x.indexOf(u);return Y1("div",{onMouseDown:(_1)=>{_1.preventDefault(),_1.stopPropagation(),i(u)},onMouseEnter:()=>S(s),style:{padding:"3px 6px",fontSize:"12px",borderRadius:"4px",fontFamily:"'Inter', sans-serif",color:s===O?"var(--color-text-primary)":"var(--color-text-secondary)",background:s===O?"var(--color-highlight-selected)":"transparent",cursor:"pointer"},children:[Y1("span",{style:{fontWeight:500},children:u.slice(0,W.trim().length)},void 0,!1,void 0,this),u.slice(W.trim().length)]},u,!0,void 0,this)})]},A.label,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function c1({anchorEl:J,scrollContainer:$,snippet:Y,truncateAt:Z,header:Q,onAdd:q,onCancel:X}){return Y1(p5,{anchorEl:J,scrollContainer:$,snippet:Y,truncateAt:Z,header:Q,onConfirm:(G,_)=>q(G,_),onCancel:X},void 0,!1,void 0,this)}function d1({anchorEl:J,scrollContainer:$,initialNote:Y,initialImages:Z,onUpdate:Q,onDelete:q,onClose:X}){return Y1(p5,{anchorEl:J,scrollContainer:$,snippet:"",initialNote:Y,initialImages:Z,onConfirm:(G,_)=>{Q(G,_),X()},onDelete:q,onCancel:X},void 0,!1,void 0,this)}import{useEffect as b0,useState as d5,useRef as u1,useCallback as r5}from"react";function g1(J,$){let Y=[],Z=c3(J);for(let Q of Z){let q=document.createRange();if(q.selectNodeContents(Q),Q===J.startContainer)q.setStart(Q,J.startOffset);if(Q===J.endContainer)q.setEnd(Q,J.endOffset);let X=q.toString();if(!X||!X.trim())continue;let G=document.createElement("mark");G.setAttribute("data-annotation-id",$);try{q.surroundContents(G)}catch{let _=q.extractContents();G.appendChild(_),q.insertNode(G)}Y.push(G)}return Y}function c3(J){let $=[],Y=J.commonAncestorContainer;if(Y.nodeType===Node.TEXT_NODE)return $.push(Y),$;let Z=document.createTreeWalker(Y,NodeFilter.SHOW_TEXT),Q;while(Q=Z.nextNode()){if(Q.parentElement?.classList.contains("select-none"))continue;if(J.intersectsNode(Q))$.push(Q)}return $}function m1(J,$){let Y=document.querySelectorAll(`[data-annotation-id="${J}"]`);for(let Z of Y)Z.classList.toggle("mark-active",$)}function y0(J,$){if($!=null&&$!==J)m1($,!1);if(J!=null)m1(J,!0)}function M0(J,$){let Y=document.querySelectorAll(`[data-annotation-id="${J}"]`);for(let Z of Y)Z.setAttribute("data-annotation-id",$)}function P0(J,$){let Y=$.filter((G)=>!document.querySelector(`[data-annotation-id="${G.id}"]`));if(!Y.length)return;let Z=[],Q="",q=document.createTreeWalker(J,NodeFilter.SHOW_TEXT),X;while(X=q.nextNode()){if(X.parentElement?.classList.contains("select-none"))continue;Z.push({node:X,start:Q.length}),Q+=X.textContent||""}for(let G of Y){let _=G.snippet;if(!_)continue;let z=[],H=0;while(!0){let O=Q.indexOf(_,H);if(O===-1)break;z.push(O),H=O+1}if(z.length===0)continue;let U=z[0];if(z.length>1&&G.context){let O=-1;for(let S of z){let L=0;if(G.context.before){let j=Q.slice(Math.max(0,S-80),S);if(j.includes(G.context.before))L+=2;else if(G.context.before.length>10&&j.includes(G.context.before.slice(-10)))L+=1}if(G.context.after){let j=Q.slice(S+_.length,S+_.length+80);if(j.includes(G.context.after))L+=2;else if(G.context.after.length>10&&j.includes(G.context.after.slice(0,10)))L+=1}if(L>O)O=L,U=S}}let W=U,N=U+_.length,K=c5(Z,W),T=c5(Z,N);if(!K||!T)continue;try{let O=document.createRange();O.setStart(K.node,K.offset),O.setEnd(T.node,T.offset),g1(O,G.id)}catch{}}}function c5(J,$){for(let Y=J.length-1;Y>=0;Y--)if(J[Y].start<=$){let Z=$-J[Y].start,Q=J[Y].node.textContent?.length??0;if(Z<=Q)return{node:J[Y].node,offset:Z}}return null}function S0(J){let $=document.querySelectorAll(`[data-annotation-id="${J}"]`);for(let Y of $){let Z=Y.parentNode;if(!Z)continue;while(Y.firstChild)Z.insertBefore(Y.firstChild,Y);Z.removeChild(Y),Z.normalize()}}import{jsxDEV as $5,Fragment as d3}from"react/jsx-dev-runtime";function E1(J){let{containerRef:$,restoreKey:Y,restoreAnnotations:Z,extractContext:Q,filePath:q,canvasFile:X,scrollContainer:G}=J,{annotations:_,addAnnotationWithId:z,removeAnnotation:H,updateAnnotation:U,addAnnotationImage:W,removeAnnotationImage:N,activeAnnotationId:K,setActiveAnnotationId:T}=e(),[O,S]=d5(null),[L,j]=d5(null),V=u1(Q);V.current=Q;let M=u1(q);M.current=q;let I=u1(X);I.current=X;let D=u1(z);D.current=z;let E=u1(K);E.current=K;let C=u1(T);C.current=T,b0(()=>{if(!$.current)return;let y=setTimeout(()=>{if($.current)P0($.current,Z)},50);return()=>clearTimeout(y)},[Y]);let R=u1(null);b0(()=>{y0(K,R.current),R.current=K},[K]),b0(()=>{let y=$.current;if(!y)return;let P=(B)=>{let b=B.target.closest("[data-annotation-id]");if(!b)return;B.stopPropagation();let g=b.getAttribute("data-annotation-id");if(g===E.current)S({anchorEl:b,annId:g});else C.current(g)},x=(B)=>{let b=B.target.closest("[data-annotation-id]");if(b)C.current(b.getAttribute("data-annotation-id"))},p=(B)=>{let b=B.target.closest("[data-annotation-id]"),g=B.relatedTarget?.closest?.("[data-annotation-id]");if(b&&!g&&!document.getElementById("ann-inline-popover"))C.current(null)};return y.addEventListener("click",P),y.addEventListener("mouseover",x),y.addEventListener("mouseout",p),()=>{y.removeEventListener("click",P),y.removeEventListener("mouseover",x),y.removeEventListener("mouseout",p)}},[Y]),b0(()=>{let y=()=>v();return document.addEventListener("mouseup",y),()=>document.removeEventListener("mouseup",y)},[]);let v=r5(()=>{let y=window.getSelection();if(!y||y.isCollapsed||!y.toString().trim())return;if(!$.current)return;let P=y.getRangeAt(0);if(!$.current.contains(P.startContainer))return;if(P.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let x=y.toString().trim();if(x.length<2)return;let p=V.current(P),B=P.cloneRange(),b=`__pending_${Date.now()}`;try{g1(B,b)}catch{}window.getSelection()?.removeAllRanges();let g=document.querySelectorAll(`[data-annotation-id="${b}"]`),o=g[g.length-1];if(!o)return;j({anchorEl:o,tempId:b,snippet:x,ctx:p})},[]),m=r5((y,P,x,p)=>{j({anchorEl:y,tempId:P,snippet:x,ctx:p})},[]);return{popovers:$5(d3,{children:[O&&(()=>{let y=_.find((P)=>P.id===O.annId);if(!y)return null;return $5(d1,{anchorEl:O.anchorEl,scrollContainer:G,initialNote:y.note,initialImages:y.images,onUpdate:(P,x)=>{U(O.annId,P);let p=y.images||[];for(let B of x)if(!p.includes(B))W(O.annId,B);for(let B of p)if(!x.includes(B))N(O.annId,B)},onDelete:()=>{H(O.annId),T(null)},onClose:()=>S(null)},void 0,!1,void 0,this)})(),L&&$5(c1,{anchorEl:L.anchorEl,scrollContainer:G,snippet:L.snippet,truncateAt:80,onAdd:(y,P)=>{let x=U1();M0(L.tempId,x),D.current(x,L.snippet,y,M.current,L.ctx,P,I.current),j(null)},onCancel:()=>{S0(L.tempId),j(null)}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),openCreatePopover:m,isPopoverOpen:!!(O||L)}}import{jsxDEV as t,Fragment as e3}from"react/jsx-dev-runtime";var Q5="[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']",Y5="[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 Y0({revision:J,filename:$}){let Y=l3(a3),[Z,Q]=W1(null),[q,X]=W1(null),[G,_]=W1(!0),z=r3(null),{annotations:H,addAnnotationWithId:U,removeAnnotation:W,updateAnnotation:N,addAnnotationImage:K,removeAnnotationImage:T,activeAnnotationId:O,setActiveAnnotationId:S}=e(),L=J0(()=>H.filter((B)=>!B.filePath&&(!B.canvasFile||B.canvasFile===$)),[H,$]),[j,V]=W1(null),[M,I]=W1(null),[D,E]=W1(null),[C,R]=W1(null),[v,m]=W1(!1);x1(()=>{_(!0),X(null),R(null);let B=$.replace(/\.jsx$/,".js");import(`/api/session/${Y}/canvas/${encodeURIComponent(B)}?rev=${J}&t=${Date.now()}`).then((b)=>{Q(()=>b.default),_(!1)}).catch((b)=>{X(b.message),_(!1)})},[Y,J,$]);let c=document.getElementById("plan-scroll-container"),{popovers:y,isPopoverOpen:P}=E1({containerRef:z,restoreKey:Z,restoreAnnotations:L,extractContext:(B)=>D1(B,z.current),canvasFile:$,scrollContainer:c}),x=J0(()=>{let B=new Map;for(let b of L)if(b.snippet.startsWith("["))B.set(b.snippet,b.id);return B},[L]);x1(()=>{let B=z.current;if(!B)return;let b=(o)=>{if(D||P)return;let i=o.target;if(i.closest("[data-block-comment-btn]"))return;m(!1);let k=i.closest(Q5);if(k&&B.contains(k)){let u=v1(B).indexOf(k);R(u>=0?u:null)}else R(null);let r=i.closest(Y5);if(r&&B.contains(r)){I(r);let A=r1(r),u=A?x.get(A):void 0;if(u&&u!==O)S(u)}else I(null)},g=(o)=>{if(D||P)return;if(o.relatedTarget?.closest("[data-block-comment-btn]"))return;I(null),S(null)};return B.addEventListener("mousemove",b),B.addEventListener("mouseleave",g),()=>{B.removeEventListener("mousemove",b),B.removeEventListener("mouseleave",g)}},[Z,D,P,x,O]),x1(()=>{let B=(b)=>{let g=b.target.tagName;if(g==="INPUT"||g==="TEXTAREA"||b.target.isContentEditable)return;if(D||P)return;let o=z.current;if(!o)return;if(b.key==="ArrowDown"){b.preventDefault(),m(!0);let i=v1(o);if(i.length===0)return;R((k)=>{if(k===null)return 0;return Math.min(k+1,i.length-1)})}else if(b.key==="ArrowUp"){b.preventDefault(),m(!0);let i=v1(o);if(i.length===0)return;R((k)=>{if(k===null)return i.length-1;return Math.max(k-1,0)})}else if(b.key==="a"||b.key==="A"){if(C===null||!o)return;b.preventDefault();let k=v1(o)[C];if(!k)return;let r=r1(k);if(!r)return;let A=x.get(r);if(A)S(A),E({anchorEl:k,snippet:r,annId:A});else E({anchorEl:k,snippet:r})}else if(b.key===" "||b.key==="Enter"){if(C===null)return;let k=v1(o)[C];if(!k)return;let r=k.getAttribute("data-md");if(r==="choice-option"||r==="multichoice-option")b.preventDefault(),k.dispatchEvent(new CustomEvent("kb-select",{bubbles:!0}));else if(r==="userinput"){b.preventDefault();let A=k.querySelector("textarea");if(A){A.focus();let u=(s)=>{if(s.key==="Escape")s.preventDefault(),A.blur(),m(!0)};A.addEventListener("keydown",u),A.addEventListener("blur",()=>A.removeEventListener("keydown",u),{once:!0})}}else if(r==="rangeinput"){b.preventDefault();let A=k.querySelector("input[type='range']");if(A){A.focus();let u=(s)=>{if(s.key==="Escape"||s.key==="ArrowUp"||s.key==="ArrowDown")s.preventDefault(),A.blur(),m(!0)};A.addEventListener("keydown",u),A.addEventListener("blur",()=>A.removeEventListener("keydown",u),{once:!0})}}}else if(b.key==="Escape")R(null),m(!1),S(null)};return document.addEventListener("keydown",B),()=>document.removeEventListener("keydown",B)},[C,D,P,x]),x1(()=>{let B=z.current;if(!B||C===null||!v)return;let g=v1(B)[C];if(!g)return;g.style.outline="2px solid var(--color-accent-blue)",g.style.outlineOffset="-2px",g.style.borderRadius="8px",g.scrollIntoView({block:"nearest",behavior:"smooth"});let o=r1(g),i=o?x.get(o):void 0;if(i)S(i);return()=>{g.style.outline="",g.style.outlineOffset="",g.style.borderRadius=""}},[C,v,x]);let p=J0(()=>Z?t(Z,{},void 0,!1,void 0,this):null,[Z]);if(G)return t("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-body",children:"Loading canvas..."},void 0,!1,void 0,this);if(q)return t("div",{className:"bg-accent-red-muted rounded-lg p-5",children:[t("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Compilation Error"},void 0,!1,void 0,this),t("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(!Z)return t("div",{className:"text-text-tertiary text-center py-8 font-body text-body",children:"No canvas loaded"},void 0,!1,void 0,this);return t(o3.Provider,{value:$,children:[t("div",{ref:z,className:"plan-content plan-updated",children:p},void 0,!1,void 0,this),j&&t(n3,{note:j.note,onSave:(B)=>{N(j.id,B),V(null)},onCancel:()=>V(null)},void 0,!1,void 0,this),y,t(s3,{containerRef:z,hoveredBlock:M,focusedBlockIndex:C,blockPopover:D,blockAnnotationMap:x,activeAnnotationId:O,onOpen:(B,b,g)=>{if(g)S(g),E({anchorEl:B,snippet:b,annId:g});else E({anchorEl:B,snippet:b})}},void 0,!1,void 0,this),D&&!D.annId&&t(c1,{anchorEl:D.anchorEl,scrollContainer:c,snippet:D.snippet,truncateAt:80,onAdd:(B,b)=>{let g=U1();U(g,D.snippet,B,void 0,void 0,b,$),E(null)},onCancel:()=>E(null)},void 0,!1,void 0,this),D?.annId&&(()=>{let B=L.find((b)=>b.id===D.annId);if(!B)return null;return t(d1,{anchorEl:D.anchorEl,scrollContainer:c,initialNote:B.note,initialImages:B.images,onUpdate:(b,g)=>{N(D.annId,b);let o=B.images||[];for(let i of g)if(!o.includes(i))K(D.annId,i);for(let i of o)if(!g.includes(i))T(D.annId,i)},onDelete:()=>{W(D.annId),S(null),E(null)},onClose:()=>E(null)},void 0,!1,void 0,this)})()]},void 0,!0,void 0,this)}function v1(J){return Array.from(J.querySelectorAll(Q5))}function r1(J){let $=J.getAttribute("data-md");if($==="item"){let Y=J.getAttribute("data-md-label");return Y?`[Item] ${Y}`:null}if($==="section"){let Y=J.getAttribute("data-md-title");return Y?`[Section] ${Y}`:null}if($==="callout"){let Y=J.getAttribute("data-md-type")||"info",Z=J.textContent?.trim().slice(0,60)||"Callout";return`[Callout:${Y}] ${Z}`}if($==="note")return`[Note] ${J.textContent?.trim().slice(0,60)||"Note"}`;if(J.tagName==="TR"){let Y=Array.from(J.querySelectorAll("td")).map((Z)=>Z.textContent?.trim()).filter(Boolean);return Y.length?`[Row] ${Y.join(" | ")}`:null}if($==="checklist-item"){let Y=J.getAttribute("data-md-label");return Y?`[Checklist] ${Y}`:null}if($==="choice-option"||$==="multichoice-option"){let Y=J.getAttribute("data-md-label");return Y?`[Option] ${Y}`:null}if($==="userinput"){let Y=J.getAttribute("data-md-label");return Y?`[Input] ${Y}`:null}if($==="rangeinput"){let Y=J.getAttribute("data-md-label");return Y?`[Range] ${Y}`:null}if($==="image"){let Y=J.getAttribute("data-md-src");return Y?`[Image] ${Y}`:null}return null}function s3({containerRef:J,hoveredBlock:$,focusedBlockIndex:Y,blockPopover:Z,blockAnnotationMap:Q,activeAnnotationId:q,onOpen:X}){let[G,_]=W1([]);x1(()=>{let N=J.current;if(!N||Q.size===0){_([]);return}let K=[];for(let T of N.querySelectorAll(Y5)){let O=r1(T);if(O&&Q.has(O))K.push(T)}_(K)},[Q,J.current]);let[z,H]=W1(null);x1(()=>{if(!q||!J.current){H(null);return}for(let N of J.current.querySelectorAll(Q5)){let K=r1(N);if(K&&Q.get(K)===q){H(N);return}}H(null)},[q,Q]),x1(()=>{if(!z)return;return z.style.boxShadow="inset 0 0 0 1.5px var(--color-highlight-bg)",z.style.borderRadius="8px",()=>{z.style.boxShadow="",z.style.borderRadius=""}},[z]);let U=J0(()=>{if(Y===null||!J.current)return null;let N=v1(J.current)[Y];if(!N)return null;return N.matches(Y5)?N:null},[Y,J.current]),W=J0(()=>{let N=new Set(G);if($)N.add($);if(U)N.add(U);if(Z?.anchorEl)N.add(Z.anchorEl);return Array.from(N)},[G,$,U,Z]);return t(e3,{children:W.map((N)=>t(t3,{block:N,isHovered:N===$||N===U||N===Z?.anchorEl,blockAnnotationMap:Q,activeAnnotationId:q,onOpen:X},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 t3({block:J,isHovered:$,blockAnnotationMap:Y,activeAnnotationId:Z,onOpen:Q}){let q=r1(J);if(!q)return null;let X=Y.get(q),G=!!X;return i3(t("button",{"data-block-comment-btn":!0,onClick:(z)=>{z.stopPropagation(),Q(z.currentTarget,q,X)},className:`absolute top-1 right-1 z-10 w-6 h-6 flex items-center justify-center rounded transition-all duration-150 ${G?X===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:G?"Edit annotation":"Add annotation",children:t("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:G?"currentColor":"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:t("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),J)}function n3({note:J,onSave:$,onCancel:Y}){let[Z,Q]=J5.useState(J),q=J5.useRef(null);return J5.useEffect(()=>{q.current?.focus(),q.current?.select()},[]),t("div",{className:"fixed inset-0 z-50 bg-black/40 flex items-center justify-center",onClick:Y,children:t("div",{className:"bg-bg-elevated border border-border-hover rounded-lg shadow-md p-4 w-80",onClick:(X)=>X.stopPropagation(),children:[t("div",{className:"text-tiny uppercase tracking-widest text-text-tertiary font-body mb-2",children:"Edit annotation"},void 0,!1,void 0,this),t("textarea",{ref:q,value:Z,onChange:(X)=>Q(X.target.value),className:"w-full bg-transparent border-none text-body font-body text-text-primary resize-vertical focus:outline-none min-h-[60px]",onKeyDown:(X)=>{if(X.key==="Enter"&&(X.ctrlKey||X.metaKey))$(Z.trim());if(X.key==="Escape")Y()}},void 0,!1,void 0,this),t("div",{className:"flex justify-end gap-2 mt-2",children:[t("button",{onClick:Y,className:"text-meta text-text-tertiary font-body px-3 py-1",children:"Cancel"},void 0,!1,void 0,this),t("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 U$,{useRef as t5,useEffect as _5,useCallback as n5,useState as l1,useContext as C0}from"react";function Q0(J,$,Y,Z){let Q=[],q=J.filter((U)=>U.filePath===q1),X=J.filter((U)=>!U.filePath),G=J.filter((U)=>U.filePath&&U.filePath!==q1),_=Y?Array.from(Y.values()).filter((U)=>X5(U)):[],z=Z?Array.from(Z.values()).filter((U)=>U.markdown.trim()):[];if(_.length>0||z.length>0){Q.push("## Responses"),Q.push("");for(let U of _)Q.push(Y$(U));for(let U of z)Q.push(U.markdown.trim()),Q.push("")}if(q.length>0){Q.push("## Annotations on agent response"),Q.push("");for(let U of q)Q.push(Z5(U))}if(X.length>0){Q.push("## Canvas annotations"),Q.push("");let U=new Map;for(let K of X){let T=K.canvasFile||"";if(!U.has(T))U.set(T,[]);U.get(T).push(K)}let W=[...U.keys()].sort(),N=W.length>1||W.length===1&&W[0]!=="";for(let K of W){let T=U.get(K);if(N&&K)Q.push(`### ${K.replace(/\.jsx$/,"")}`),Q.push("");let O=Q$(T);Q.push(l5(O))}}if(G.length>0){let U={};for(let W of G){let N=W.filePath;if(!U[N])U[N]=[];U[N].push(W)}Q.push("## File annotations"),Q.push("");for(let[W,N]of Object.entries(U)){Q.push(`### ${W}`),Q.push("");for(let K of N)Q.push(Z5(K))}}if($.trim())Q.push("## General notes"),Q.push(""),Q.push($.trim()),Q.push("");return Q.join(`
|
|
58
|
+
`}strong({tokens:J}){return`<strong>${this.parser.parseInline(J)}</strong>`}em({tokens:J}){return`<em>${this.parser.parseInline(J)}</em>`}codespan({text:J}){return`<code>${K1(J,!0)}</code>`}br(J){return"<br>"}del({tokens:J}){return`<del>${this.parser.parseInline(J)}</del>`}link({href:J,title:$,tokens:Y}){let Z=this.parser.parseInline(Y),Q=y5(J);if(Q===null)return Z;J=Q;let q='<a href="'+J+'"';return $&&(q+=' title="'+K1($)+'"'),q+=">"+Z+"</a>",q}image({href:J,title:$,text:Y,tokens:Z}){Z&&(Y=this.parser.parseInline(Z,this.parser.textRenderer));let Q=y5(J);if(Q===null)return K1(Y);J=Q;let q=`<img src="${J}" alt="${K1(Y)}"`;return $&&(q+=` title="${K1($)}"`),q+=">",q}text(J){return"tokens"in J&&J.tokens?this.parser.parseInline(J.tokens):("escaped"in J)&&J.escaped?J.text:K1(J.text)}},o0=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}},G1=class J{options;renderer;textRenderer;constructor($){this.options=$||k1,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 o0}static parse($,Y){return new J(Y).parse($)}static parseInline($,Y){return new J(Y).parseInline($)}parse($){let Y="";for(let Z=0;Z<$.length;Z++){let Q=$[Z];if(this.options.extensions?.renderers?.[Q.type]){let X=Q,G=this.options.extensions.renderers[X.type].call({parser:this},X);if(G!==!1||!["space","hr","heading","code","table","blockquote","list","html","def","paragraph","text"].includes(X.type)){Y+=G||"";continue}}let q=Q;switch(q.type){case"space":{Y+=this.renderer.space(q);break}case"hr":{Y+=this.renderer.hr(q);break}case"heading":{Y+=this.renderer.heading(q);break}case"code":{Y+=this.renderer.code(q);break}case"table":{Y+=this.renderer.table(q);break}case"blockquote":{Y+=this.renderer.blockquote(q);break}case"list":{Y+=this.renderer.list(q);break}case"checkbox":{Y+=this.renderer.checkbox(q);break}case"html":{Y+=this.renderer.html(q);break}case"def":{Y+=this.renderer.def(q);break}case"paragraph":{Y+=this.renderer.paragraph(q);break}case"text":{Y+=this.renderer.text(q);break}default:{let X='Token with "'+q.type+'" type was not found.';if(this.options.silent)return console.error(X),"";throw Error(X)}}}return Y}parseInline($,Y=this.renderer){let Z="";for(let Q=0;Q<$.length;Q++){let q=$[Q];if(this.options.extensions?.renderers?.[q.type]){let G=this.options.extensions.renderers[q.type].call({parser:this},q);if(G!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(q.type)){Z+=G||"";continue}}let X=q;switch(X.type){case"escape":{Z+=Y.text(X);break}case"html":{Z+=Y.html(X);break}case"link":{Z+=Y.link(X);break}case"image":{Z+=Y.image(X);break}case"checkbox":{Z+=Y.checkbox(X);break}case"strong":{Z+=Y.strong(X);break}case"em":{Z+=Y.em(X);break}case"codespan":{Z+=Y.codespan(X);break}case"br":{Z+=Y.br(X);break}case"del":{Z+=Y.del(X);break}case"text":{Z+=Y.text(X);break}default:{let G='Token with "'+X.type+'" type was not found.';if(this.options.silent)return console.error(G),"";throw Error(G)}}}return Z}},n1=class{options;block;constructor(J){this.options=J||k1}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?z1.lex:z1.lexInline}provideParser(){return this.block?G1.parse:G1.parseInline}},I3=class{defaults=h0();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=G1;Renderer=N0;TextRenderer=o0;Lexer=z1;Tokenizer=W0;Hooks=n1;constructor(...J){this.use(...J)}walkTokens(J,$){let Y=[];for(let Z of J)switch(Y=Y.concat($.call(this,Z)),Z.type){case"table":{let Q=Z;for(let q of Q.header)Y=Y.concat(this.walkTokens(q.tokens,$));for(let q of Q.rows)for(let X of q)Y=Y.concat(this.walkTokens(X.tokens,$));break}case"list":{let Q=Z;Y=Y.concat(this.walkTokens(Q.items,$));break}default:{let Q=Z;this.defaults.extensions?.childTokens?.[Q.type]?this.defaults.extensions.childTokens[Q.type].forEach((q)=>{let X=Q[q].flat(1/0);Y=Y.concat(this.walkTokens(X,$))}):Q.tokens&&(Y=Y.concat(this.walkTokens(Q.tokens,$)))}}return Y}use(...J){let $=this.defaults.extensions||{renderers:{},childTokens:{}};return J.forEach((Y)=>{let Z={...Y};if(Z.async=this.defaults.async||Z.async||!1,Y.extensions&&(Y.extensions.forEach((Q)=>{if(!Q.name)throw Error("extension name required");if("renderer"in Q){let q=$.renderers[Q.name];q?$.renderers[Q.name]=function(...X){let G=Q.renderer.apply(this,X);return G===!1&&(G=q.apply(this,X)),G}:$.renderers[Q.name]=Q.renderer}if("tokenizer"in Q){if(!Q.level||Q.level!=="block"&&Q.level!=="inline")throw Error("extension level must be 'block' or 'inline'");let q=$[Q.level];q?q.unshift(Q.tokenizer):$[Q.level]=[Q.tokenizer],Q.start&&(Q.level==="block"?$.startBlock?$.startBlock.push(Q.start):$.startBlock=[Q.start]:Q.level==="inline"&&($.startInline?$.startInline.push(Q.start):$.startInline=[Q.start]))}"childTokens"in Q&&Q.childTokens&&($.childTokens[Q.name]=Q.childTokens)}),Z.extensions=$),Y.renderer){let Q=this.defaults.renderer||new N0(this.defaults);for(let q in Y.renderer){if(!(q in Q))throw Error(`renderer '${q}' does not exist`);if(["options","parser"].includes(q))continue;let X=q,G=Y.renderer[X],_=Q[X];Q[X]=(...z)=>{let H=G.apply(Q,z);return H===!1&&(H=_.apply(Q,z)),H||""}}Z.renderer=Q}if(Y.tokenizer){let Q=this.defaults.tokenizer||new W0(this.defaults);for(let q in Y.tokenizer){if(!(q in Q))throw Error(`tokenizer '${q}' does not exist`);if(["options","rules","lexer"].includes(q))continue;let X=q,G=Y.tokenizer[X],_=Q[X];Q[X]=(...z)=>{let H=G.apply(Q,z);return H===!1&&(H=_.apply(Q,z)),H}}Z.tokenizer=Q}if(Y.hooks){let Q=this.defaults.hooks||new n1;for(let q in Y.hooks){if(!(q in Q))throw Error(`hook '${q}' does not exist`);if(["options","block"].includes(q))continue;let X=q,G=Y.hooks[X],_=Q[X];n1.passThroughHooks.has(q)?Q[X]=(z)=>{if(this.defaults.async&&n1.passThroughHooksRespectAsync.has(q))return(async()=>{let U=await G.call(Q,z);return _.call(Q,U)})();let H=G.call(Q,z);return _.call(Q,H)}:Q[X]=(...z)=>{if(this.defaults.async)return(async()=>{let U=await G.apply(Q,z);return U===!1&&(U=await _.apply(Q,z)),U})();let H=G.apply(Q,z);return H===!1&&(H=_.apply(Q,z)),H}}Z.hooks=Q}if(Y.walkTokens){let Q=this.defaults.walkTokens,q=Y.walkTokens;Z.walkTokens=function(X){let G=[];return G.push(q.call(this,X)),Q&&(G=G.concat(Q.call(this,X))),G}}this.defaults={...this.defaults,...Z}}),this}setOptions(J){return this.defaults={...this.defaults,...J},this}lexer(J,$){return z1.lex(J,$??this.defaults)}parser(J,$){return G1.parse(J,$??this.defaults)}parseMarkdown(J){return($,Y)=>{let Z={...Y},Q={...this.defaults,...Z},q=this.onError(!!Q.silent,!!Q.async);if(this.defaults.async===!0&&Z.async===!1)return q(Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(typeof $>"u"||$===null)return q(Error("marked(): input parameter is undefined or null"));if(typeof $!="string")return q(Error("marked(): input parameter is of type "+Object.prototype.toString.call($)+", string expected"));if(Q.hooks&&(Q.hooks.options=Q,Q.hooks.block=J),Q.async)return(async()=>{let X=Q.hooks?await Q.hooks.preprocess($):$,G=await(Q.hooks?await Q.hooks.provideLexer():J?z1.lex:z1.lexInline)(X,Q),_=Q.hooks?await Q.hooks.processAllTokens(G):G;Q.walkTokens&&await Promise.all(this.walkTokens(_,Q.walkTokens));let z=await(Q.hooks?await Q.hooks.provideParser():J?G1.parse:G1.parseInline)(_,Q);return Q.hooks?await Q.hooks.postprocess(z):z})().catch(q);try{Q.hooks&&($=Q.hooks.preprocess($));let X=(Q.hooks?Q.hooks.provideLexer():J?z1.lex:z1.lexInline)($,Q);Q.hooks&&(X=Q.hooks.processAllTokens(X)),Q.walkTokens&&this.walkTokens(X,Q.walkTokens);let G=(Q.hooks?Q.hooks.provideParser():J?G1.parse:G1.parseInline)(X,Q);return Q.hooks&&(G=Q.hooks.postprocess(G)),G}catch(X){return q(X)}}}onError(J,$){return(Y)=>{if(Y.message+=`
|
|
59
|
+
Please report this to https://github.com/markedjs/marked.`,J){let Z="<p>An error occurred:</p><pre>"+K1(Y.message+"",!0)+"</pre>";return $?Promise.resolve(Z):Z}if($)return Promise.reject(Y);throw Y}}},R1=new I3;function o(J,$){return R1.parse(J,$)}o.options=o.setOptions=function(J){return R1.setOptions(J),o.defaults=R1.defaults,P5(o.defaults),o};o.getDefaults=h0;o.defaults=k1;o.use=function(...J){return R1.use(...J),o.defaults=R1.defaults,P5(o.defaults),o};o.walkTokens=function(J,$){return R1.walkTokens(J,$)};o.parseInline=R1.parseInline;o.Parser=G1;o.parser=G1.parse;o.Renderer=N0;o.TextRenderer=o0;o.Lexer=z1;o.lexer=z1.lex;o.Tokenizer=W0;o.Hooks=n1;o.parse=o;var{options:C4,setOptions:j4,use:R4,walkTokens:k4,parseInline:V4}=o;var D4=G1.parse,m4=z1.lex;import{SessionContext as g2,ActiveViewCtx as P4}from"#canvas/runtime";import{useState as J0,useCallback as H1,useEffect as C3,useRef as j3}from"react";import{AnnotationCtx as R3}from"#canvas/runtime";var _1="__agent-response__";function U1(){return`ann-${Date.now()}-${Math.random().toString(36).slice(2,6)}`}function $0(J,$){J.style.height="auto",J.style.height=($?Math.max($,J.scrollHeight):J.scrollHeight)+"px"}import{useAnnotations as $1}from"#canvas/runtime";import{jsxDEV as m3}from"react/jsx-dev-runtime";function s0(J,$){return`canvas:${J}:rev:${$}`}function F0(J,$){try{let Y=localStorage.getItem(s0(J,$));if(!Y)return null;return JSON.parse(Y)}catch{return null}}function k3(J,$,Y){try{localStorage.setItem(s0(J,$),JSON.stringify(Y))}catch{}}function V3(J,$){try{localStorage.removeItem(s0(J,$))}catch{}}function m5({sessionId:J,revision:$,isReadOnly:Y,children:Z}){let[Q,q]=J0(()=>{return F0(J,$)?.annotations??[]}),[X,G]=J0(()=>{return F0(J,$)?.generalNote??""}),[_,z]=J0(null),[H,U]=J0(()=>{let A=F0(J,$);return A?.responses?new Map(A.responses):new Map}),[W,N]=J0(()=>{let A=F0(J,$);return A?.feedbackEntries?new Map(A.feedbackEntries):new Map}),K=j3(null);C3(()=>{if(Y)return;if(K.current)clearTimeout(K.current);return K.current=setTimeout(()=>{k3(J,$,{annotations:Q,generalNote:X,responses:Array.from(H.entries()),feedbackEntries:Array.from(W.entries())})},300),()=>{if(K.current)clearTimeout(K.current)}},[Q,X,H,W,J,$,Y]);let F=H1((A,C,v,u,l,x,y)=>{q((I)=>[...I,{id:A,snippet:C,note:v,createdAt:new Date().toISOString(),filePath:u,context:l,...x?.length?{images:x}:{},...y?{canvasFile:y}:{}}])},[]),T=H1((A,C,v)=>{F(U1(),A,C,v)},[F]),M=H1((A,C)=>{q((v)=>v.map((u)=>u.id===A?{...u,note:C}:u))},[]),L=H1((A)=>{D3(A),q((C)=>C.filter((v)=>v.id!==A)),z((C)=>C===A?null:C)},[]),j=H1((A,C)=>{q((v)=>v.map((u)=>u.id===A?{...u,images:[...u.images||[],C]}:u))},[]),k=H1((A,C)=>{q((v)=>v.map((u)=>u.id===A?{...u,images:(u.images||[]).filter((l)=>l!==C)}:u))},[]),B=H1((A,C)=>{U((v)=>{let u=new Map(v);return u.set(A,C),u})},[]),w=H1((A,C)=>{N((v)=>{let u=v.get(A);if(u&&u.markdown===C.markdown&&u.label===C.label&&u.required===C.required)return v;let l=new Map(v);return l.set(A,C),l})},[]),m=H1((A)=>{N((C)=>{if(!C.has(A))return C;let v=new Map(C);return v.delete(A),v})},[]),g=H1(()=>{for(let A of document.querySelectorAll("[data-annotation-id]"))u5(A);q([]),G(""),z(null),U(new Map),N(new Map),V3(J,$)},[J,$]);return m3(R3.Provider,{value:{annotations:Q,addAnnotation:T,addAnnotationWithId:F,updateAnnotation:M,removeAnnotation:L,addAnnotationImage:j,removeAnnotationImage:k,generalNote:X,setGeneralNote:G,clearAll:g,activeAnnotationId:_,setActiveAnnotationId:z,responses:H,setResponse:B,feedbackEntries:W,setFeedbackEntry:w,removeFeedbackEntry:m},children:Z},void 0,!1,void 0,this)}function D3(J){let $=document.querySelectorAll(`[data-annotation-id="${J}"]`);for(let Y of $)u5(Y)}function u5(J){let $=J.parentNode;if(!$)return;let Y=document.createTextNode(J.textContent||"");$.replaceChild(Y,J),$.normalize()}import Y5,{useEffect as v1,useState as W1,useRef as i3,useContext as a3,useMemo as Y0}from"react";import{createPortal as o3}from"react-dom";import{SessionContext as s3,CanvasFileCtx as t3}from"#canvas/runtime";function V1(J,$){let Y=g5(J,"before",60),Z=g5(J,"after",60),Q=g3(J.startContainer,$);return{before:Y,after:Z,hierarchy:Q}}function g5(J,$,Y){let Z=u3($==="before"?J.startContainer:J.endContainer);if(!Z)return"";let Q="";if($==="before"){let q=document.createTreeWalker(Z,NodeFilter.SHOW_TEXT),X;while(X=q.nextNode()){if(X===J.startContainer){Q+=(X.textContent||"").slice(0,J.startOffset);break}if(X.parentElement?.hasAttribute("data-annotation-id"))continue;Q+=X.textContent||""}if(Q.length>Y){Q=Q.slice(-Y);let G=Q.indexOf(" ");if(G>0)Q=Q.slice(G+1)}}else{let q=document.createTreeWalker(Z,NodeFilter.SHOW_TEXT),X=!1,G;while(G=q.nextNode()){if(G===J.endContainer){Q+=(G.textContent||"").slice(J.endOffset),X=!0;continue}if(X){if(G.parentElement?.hasAttribute("data-annotation-id"))continue;Q+=G.textContent||""}}if(Q.length>Y){Q=Q.slice(0,Y);let _=Q.lastIndexOf(" ");if(_>0)Q=Q.slice(0,_)}}return Q.trim()}function u3(J){let $=new Set(["DIV","P","LI","PRE","BLOCKQUOTE","SECTION","ARTICLE"]),Y=J.parentElement;while(Y){if($.has(Y.tagName))return Y;Y=Y.parentElement}return null}function g3(J,$){let Y=[],Z=J instanceof Element?J:J.parentElement;while(Z&&Z!==$){let Q=Z.getAttribute?.("data-task-id");if(Q){let q=Z.querySelector(".font-semibold");if(q)Y.unshift(q.textContent?.trim()||Q)}if(Z.tagName==="DIV"&&Z.querySelector(":scope > button .font-heading, :scope > div .font-heading")){let q=Z.querySelector(".font-heading");if(q)Y.unshift(q.textContent?.trim()||"")}Z=Z.parentElement}return Y}function t0(J){let $=J.snippet.trim(),Y=J.context,Z=$.length<30;if(Y&&Z&&(Y.before||Y.after)){let Q=[];if(Y.before)Q.push(`...${Y.before} `);if(Q.push(`**${$}**`),Y.after)Q.push(` ${Y.after}...`);return Q.join("")}return $}import{useEffect as x3,useRef as M0,useState as h1,useCallback as y0,useMemo as f5,useContext as f3}from"react";import{createPortal as h3}from"react-dom";function E5(J,$){let Q=$||document.body,q=J.getBoundingClientRect(),X=Q.getBoundingClientRect(),G=Q===document.body?window.scrollY:Q.scrollTop,_=q.bottom-X.top+G+8,z=Math.max(0,Math.min(q.left-X.left,X.width-280-12));return Q.style.position="relative",{style:{position:"absolute",top:`${_}px`,left:`${z}px`},parent:Q}}import{useState as n0,useRef as e0,useCallback as O1,useEffect as E3}from"react";import{jsxDEV as J1}from"react/jsx-dev-runtime";function v5(J){return`/api/uploads/${J.split("/").pop()}`}async function v3(J,$){let Y=new FormData;Y.append("image",$);try{return(await(await fetch(`/api/session/${J}/upload`,{method:"POST",body:Y})).json()).path||null}catch{return null}}function L0({note:J,onNoteChange:$,images:Y,onAddImage:Z,onRemoveImage:Q,sessionId:q,placeholder:X="Add your note...",autoFocus:G=!1,autoResize:_=!1,readOnly:z=!1,onKeyDown:H,onTextareaClick:U,textareaRef:W,textareaClassName:N,textareaStyle:K,minHeight:F,attachButton:T="always",openFilePickerRef:M}){let[L,j]=n0(!1),[k,B]=n0(!1),[w,m]=n0(!1),g=e0(0),A=e0(null),C=e0(null),v=O1(()=>C.current?.click(),[]);if(M)M.current=v;let u=O1((D)=>{if(A.current=D,W)W.current=D;if(D&&_)$0(D,F)},[W,_,F]);E3(()=>{if(G&&A.current){let D=A.current;if(D.focus(),D.value)D.setSelectionRange(D.value.length,D.value.length)}},[G]);let l=O1(async(D)=>{if(!D.type.startsWith("image/"))return;B(!0);try{let a=await v3(q,D);if(a)Z(a)}finally{B(!1)}},[q,Z]),x=O1((D)=>{let a=D.clipboardData.items;for(let b of a)if(b.type.startsWith("image/")){D.preventDefault();let E=b.getAsFile();if(E)l(E);return}},[l]),y=O1((D)=>{if(D.preventDefault(),g.current++,g.current===1)j(!0)},[]),I=O1((D)=>{D.preventDefault()},[]),d=O1((D)=>{if(D.preventDefault(),g.current--,g.current===0)j(!1)},[]),R=O1((D)=>{D.preventDefault(),g.current=0,j(!1);for(let a of D.dataTransfer.files)if(a.type.startsWith("image/"))l(a)},[l]),V=O1((D)=>{if($(D.target.value),_)D.target.style.height="auto",D.target.style.height=(F?Math.max(F,D.target.scrollHeight):D.target.scrollHeight)+"px"},[$,_,F]),P="w-full bg-transparent text-[13px] font-body text-text-primary resize-none focus:outline-none leading-relaxed p-0 border-none",p={width:"100%",background:"transparent",border:"none",color:"var(--color-text-primary)",fontFamily:"'Inter', sans-serif",fontSize:"13px",lineHeight:"1.5",outline:"none",..._?{resize:"none",overflow:"hidden"}:{resize:"vertical"}},h=!z&&(T==="always"||T==="on-focus"&&w);return J1("div",{style:{position:"relative"},onDragEnter:z?void 0:y,onDragOver:z?void 0:I,onDragLeave:z?void 0:d,onDrop:z?void 0:R,children:[J1("textarea",{ref:u,value:J,onChange:z?void 0:V,onPaste:z?void 0:x,onKeyDown:H,onClick:U,onFocus:()=>m(!0),onBlur:()=>{setTimeout(()=>m(!1),150)},readOnly:z,placeholder:X,className:N??P,style:K??p,rows:_?1:void 0},void 0,!1,void 0,this),!z&&J1("input",{ref:C,type:"file",accept:"image/*",multiple:!0,style:{display:"none"},onChange:(D)=>{let a=D.target.files;if(a)for(let b of a)l(b);D.target.value=""}},void 0,!1,void 0,this),(Y.length>0||h)&&J1("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"6px",alignItems:"center"},children:[Y.map((D)=>J1("div",{style:{position:"relative",width:"56px",height:"56px",borderRadius:"6px",overflow:"hidden",border:"1px solid var(--color-border-subtle)",flexShrink:0},children:[J1("img",{src:v5(D),alt:"",style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}},void 0,!1,void 0,this),!z&&J1("button",{onClick:(a)=>{a.stopPropagation(),Q(D)},style:{position:"absolute",top:"2px",right:"2px",width:"16px",height:"16px",borderRadius:"50%",background:"rgba(0,0,0,0.6)",color:"white",border:"none",cursor:"pointer",fontSize:"11px",display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1,padding:0},title:"Remove image",children:"×"},void 0,!1,void 0,this)]},D,!0,void 0,this)),h&&J1($5,{onClick:v},void 0,!1,void 0,this)]},void 0,!0,void 0,this),k&&J1("div",{style:{fontSize:"11px",color:"var(--color-text-tertiary)",fontFamily:"'Inter', sans-serif",marginTop:"4px"},children:"Uploading..."},void 0,!1,void 0,this),L&&J1("div",{style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",background:"var(--color-highlight-bg)",opacity:0.9,border:"2px dashed var(--color-highlight-border)",borderRadius:"6px",zIndex:10,pointerEvents:"none",fontSize:"12px",fontFamily:"'Inter', sans-serif",color:"var(--color-text-secondary)"},children:"Drop image"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function $5({onClick:J,size:$=16}){return J1("button",{onClick:(Y)=>{Y.stopPropagation(),J()},style:{width:`${$*2}px`,height:`${$*2}px`,borderRadius:"6px",border:"none",background:"transparent",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--color-text-tertiary)",flexShrink:0,transition:"color 0.15s"},title:"Attach image",onMouseEnter:(Y)=>{Y.currentTarget.style.color="var(--color-text-secondary)"},onMouseLeave:(Y)=>{Y.currentTarget.style.color="var(--color-text-tertiary)"},children:J1("svg",{width:$,height:$,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[J1("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"},void 0,!1,void 0,this),J1("circle",{cx:"8.5",cy:"8.5",r:"1.5"},void 0,!1,void 0,this),J1("polyline",{points:"21 15 16 10 5 21"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function x5({images:J}){if(!J.length)return null;return J1("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"6px"},children:J.map(($)=>J1("div",{style:{width:"56px",height:"56px",borderRadius:"6px",overflow:"hidden",border:"1px solid var(--color-border-subtle)",flexShrink:0},children:J1("img",{src:v5($),alt:"",style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}},void 0,!1,void 0,this)},$,!1,void 0,this))},void 0,!1,void 0,this)}import{SessionContext as p3}from"#canvas/runtime";import{jsxDEV as Y1,Fragment as d3}from"react/jsx-dev-runtime";function c3({anchorEl:J,scrollContainer:$,onClose:Y,ignoreSelector:Z,zIndex:Q="50",padding:q="12px",width:X="280px",children:G}){let _=M0(null),z=M0(Y);z.current=Y;let{style:H,parent:U}=E5(J,$);return x3(()=>{let W=setTimeout(()=>{let N=(K)=>{if(_.current&&!_.current.contains(K.target)){if(Z&&K.target.closest?.(Z))return;z.current(),document.removeEventListener("mousedown",N)}};return document.addEventListener("mousedown",N),()=>document.removeEventListener("mousedown",N)},0);return()=>clearTimeout(W)},[Z]),h3(Y1("div",{ref:_,style:{...H,zIndex:Q,width:X,background:"var(--color-bg-elevated)",border:"1px solid var(--color-border-hover)",borderRadius:"8px",boxShadow:"0 4px 12px var(--color-shadow)",padding:q,fontFamily:"'Inter', sans-serif"},children:G},void 0,!1,void 0,this),U)}var p5=[{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"]}],h5=p5.flatMap((J)=>J.items);function c5({anchorEl:J,scrollContainer:$,snippet:Y,truncateAt:Z=100,header:Q,initialNote:q="",initialImages:X,onConfirm:G,onCancel:_,onDelete:z}){let H=f3(p3),U=q!==""||!!z,[W,N]=h1(q),[K,F]=h1(X||[]),[T,M]=h1(null),[L,j]=h1(U),[k,B]=h1(!1),w=M0(null),m=M0(null),g=y0(()=>{if(W.trim()||K.length>0)G(W.trim(),K);else if(U&&z)z();else _()},[W,K,G,_,U,z]),A=y0(()=>{if(U){if(!W.trim()&&K.length===0&&z){z(),_();return}G(W,K);return}_()},[W,K,U,G,_,z]),C=!U,v=W.trim().length>0?h5.filter((b)=>b.toLowerCase().startsWith(W.trim().toLowerCase())):h5,u=!C||L?[]:v.length===1&&v[0].toLowerCase()===W.trim().toLowerCase()?[]:v,l=new Set(u),x=p5.map((b)=>({label:b.label,items:b.items.filter((E)=>l.has(E))})).filter((b)=>b.items.length>0),y=x.map((b)=>b.items),I=y.flat(),d=f5(()=>{if(T===null)return 0;let b=0;for(let E=0;E<y.length;E++){if(T<b+y[E].length)return E;b+=y[E].length}return 0},[T,y]),R=f5(()=>{if(T===null)return 0;let b=0;for(let E=0;E<d;E++)b+=y[E].length;return T-b},[T,d,y]),V=(b,E)=>{let s=0;for(let Z1=0;Z1<b;Z1++)s+=y[Z1].length;return s+E},[P,p]=h1(W);if(W!==P)p(W),M(null),j(U);let h=y0((b)=>{N(b)},[]),D=Y.length>Z?Y.slice(0,Z)+"...":Y,a=y0((b)=>{if(I.length>0&&(b.key==="ArrowDown"||b.key==="ArrowUp"||b.key==="ArrowLeft"||b.key==="ArrowRight")){if(b.preventDefault(),T===null){M(0);return}if(b.key==="ArrowDown"){let E=Math.min(R+1,y[d].length-1);M(V(d,E))}else if(b.key==="ArrowUp"){let E=Math.max(R-1,0);M(V(d,E))}else if(b.key==="ArrowRight"){let E=Math.min(d+1,y.length-1),s=Math.min(R,y[E].length-1);M(V(E,s))}else if(b.key==="ArrowLeft"){let E=Math.max(d-1,0),s=Math.min(R,y[E].length-1);M(V(E,s))}return}if(T!==null&&I.length>0){if(b.key==="Tab"){b.preventDefault(),h(I[T]);return}if(b.key==="Enter"&&!b.shiftKey){b.preventDefault(),G(I[T],K);return}}if(b.key==="Enter"&&!b.shiftKey){b.preventDefault(),g();return}if(b.key==="Escape")if(I.length>0&&!L)j(!0);else if(U)A();else _()},[I,T,R,d,y,V,h,G,K,g,L,U,A,_]);return Y1(c3,{anchorEl:J,scrollContainer:$,onClose:U?A:_,ignoreSelector:U?"[data-annotation-id]":void 0,zIndex:U?"60":"50",padding:U?"10px 12px":"12px",width:"420px",children:[!U&&(Q??Y1("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:["“",D,"”"]},void 0,!0,void 0,this)),Y1(L0,{note:W,onNoteChange:N,images:K,onAddImage:(b)=>F((E)=>[...E,b]),onRemoveImage:(b)=>F((E)=>E.filter((s)=>s!==b)),sessionId:H,autoFocus:!0,autoResize:U,textareaRef:w,onKeyDown:a,attachButton:"none",openFilePickerRef:m,textareaStyle:U?{width:"100%",background:"transparent",border:"none",color:"var(--color-text-primary)",fontFamily:"'Inter', sans-serif",fontSize:"13px",lineHeight:"1.5",resize:"none",outline:"none",overflow:"hidden"}:{width:"100%",minHeight:"60px",background:"transparent",border:"none",color:"var(--color-text-primary)",fontFamily:"'Inter', sans-serif",fontSize:"13px",lineHeight:"1.5",resize:"vertical",outline:"none"},placeholder:"Add your note..."},void 0,!1,void 0,this),Y1("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginTop:U?"6px":"8px"},children:[Y1($5,{onClick:()=>m.current?.(),size:14},void 0,!1,void 0,this),Y1("div",{style:{flex:1}},void 0,!1,void 0,this),U?Y1("button",{onClick:()=>{if(z)z();_()},onMouseEnter:()=>B(!0),onMouseLeave:()=>B(!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):Y1(d3,{children:[Y1("button",{onClick:_,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),Y1("button",{onClick:g,style:{fontSize:"11px",fontWeight:500,padding:"4px 12px",borderRadius:"6px",background:"var(--color-highlight-bg)",color:"var(--color-text-primary)",border:"1px solid var(--color-highlight-border)",cursor:"pointer",fontFamily:"'Inter', sans-serif"},children:"Add"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),I.length>0&&Y1("div",{style:{marginTop:"6px",borderTop:"1px solid var(--color-border-subtle)",paddingTop:"8px",display:"flex",gap:"4px"},children:x.map((b)=>Y1("div",{style:{flex:1},children:[Y1("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:b.label},void 0,!1,void 0,this),b.items.map((E)=>{let s=I.indexOf(E);return Y1("div",{onMouseDown:(Z1)=>{Z1.preventDefault(),Z1.stopPropagation(),h(E)},onMouseEnter:()=>M(s),style:{padding:"3px 6px",fontSize:"12px",borderRadius:"4px",fontFamily:"'Inter', sans-serif",color:s===T?"var(--color-text-primary)":"var(--color-text-secondary)",background:s===T?"var(--color-highlight-selected)":"transparent",cursor:"pointer"},children:[Y1("span",{style:{fontWeight:500},children:E.slice(0,W.trim().length)},void 0,!1,void 0,this),E.slice(W.trim().length)]},E,!0,void 0,this)})]},b.label,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function p1({anchorEl:J,scrollContainer:$,snippet:Y,truncateAt:Z,header:Q,onAdd:q,onCancel:X}){return Y1(c5,{anchorEl:J,scrollContainer:$,snippet:Y,truncateAt:Z,header:Q,onConfirm:(G,_)=>q(G,_),onCancel:X},void 0,!1,void 0,this)}function c1({anchorEl:J,scrollContainer:$,initialNote:Y,initialImages:Z,onUpdate:Q,onDelete:q,onClose:X}){return Y1(c5,{anchorEl:J,scrollContainer:$,snippet:"",initialNote:Y,initialImages:Z,onConfirm:(G,_)=>{Q(G,_),X()},onDelete:q,onCancel:X},void 0,!1,void 0,this)}import{useEffect as w0,useState as r5,useRef as u1,useCallback as l5}from"react";function m1(J,$){let Y=[],Z=r3(J);for(let Q of Z){let q=document.createRange();if(q.selectNodeContents(Q),Q===J.startContainer)q.setStart(Q,J.startOffset);if(Q===J.endContainer)q.setEnd(Q,J.endOffset);let X=q.toString();if(!X||!X.trim())continue;let G=document.createElement("mark");G.setAttribute("data-annotation-id",$);try{q.surroundContents(G)}catch{let _=q.extractContents();G.appendChild(_),q.insertNode(G)}Y.push(G)}return Y}function r3(J){let $=[],Y=J.commonAncestorContainer;if(Y.nodeType===Node.TEXT_NODE)return $.push(Y),$;let Z=document.createTreeWalker(Y,NodeFilter.SHOW_TEXT),Q;while(Q=Z.nextNode()){if(Q.parentElement?.classList.contains("select-none"))continue;if(J.intersectsNode(Q))$.push(Q)}return $}function D1(J,$){let Y=document.querySelectorAll(`[data-annotation-id="${J}"]`);for(let Z of Y)Z.classList.toggle("mark-active",$)}function B0(J,$){if($!=null&&$!==J)D1($,!1);if(J!=null)D1(J,!0)}function P0(J,$){let Y=document.querySelectorAll(`[data-annotation-id="${J}"]`);for(let Z of Y)Z.setAttribute("data-annotation-id",$)}function S0(J,$){let Y=$.filter((G)=>!document.querySelector(`[data-annotation-id="${G.id}"]`));if(!Y.length)return;let Z=[],Q="",q=document.createTreeWalker(J,NodeFilter.SHOW_TEXT),X;while(X=q.nextNode()){if(X.parentElement?.classList.contains("select-none"))continue;Z.push({node:X,start:Q.length}),Q+=X.textContent||""}for(let G of Y){let _=G.snippet;if(!_)continue;let z=[],H=0;while(!0){let T=Q.indexOf(_,H);if(T===-1)break;z.push(T),H=T+1}if(z.length===0)continue;let U=z[0];if(z.length>1&&G.context){let T=-1;for(let M of z){let L=0;if(G.context.before){let j=Q.slice(Math.max(0,M-80),M);if(j.includes(G.context.before))L+=2;else if(G.context.before.length>10&&j.includes(G.context.before.slice(-10)))L+=1}if(G.context.after){let j=Q.slice(M+_.length,M+_.length+80);if(j.includes(G.context.after))L+=2;else if(G.context.after.length>10&&j.includes(G.context.after.slice(0,10)))L+=1}if(L>T)T=L,U=M}}let W=U,N=U+_.length,K=d5(Z,W),F=d5(Z,N);if(!K||!F)continue;try{let T=document.createRange();T.setStart(K.node,K.offset),T.setEnd(F.node,F.offset),m1(T,G.id)}catch{}}}function d5(J,$){for(let Y=J.length-1;Y>=0;Y--)if(J[Y].start<=$){let Z=$-J[Y].start,Q=J[Y].node.textContent?.length??0;if(Z<=Q)return{node:J[Y].node,offset:Z}}return null}function b0(J){let $=document.querySelectorAll(`[data-annotation-id="${J}"]`);for(let Y of $){let Z=Y.parentNode;if(!Z)continue;while(Y.firstChild)Z.insertBefore(Y.firstChild,Y);Z.removeChild(Y),Z.normalize()}}import{jsxDEV as J5,Fragment as l3}from"react/jsx-dev-runtime";function g1(J){let{containerRef:$,restoreKey:Y,restoreAnnotations:Z,extractContext:Q,filePath:q,canvasFile:X,scrollContainer:G}=J,{annotations:_,addAnnotationWithId:z,removeAnnotation:H,updateAnnotation:U,addAnnotationImage:W,removeAnnotationImage:N,activeAnnotationId:K,setActiveAnnotationId:F}=$1(),[T,M]=r5(null),[L,j]=r5(null),k=u1(Q);k.current=Q;let B=u1(q);B.current=q;let w=u1(X);w.current=X;let m=u1(z);m.current=z;let g=u1(K);g.current=K;let A=u1(F);A.current=F,w0(()=>{if(!$.current)return;let x=setTimeout(()=>{if($.current)S0($.current,Z)},50);return()=>clearTimeout(x)},[Y]);let C=u1(null);w0(()=>{B0(K,C.current),C.current=K},[K]),w0(()=>{let x=$.current;if(!x)return;let y=(R)=>{let V=R.target.closest("[data-annotation-id]");if(!V)return;R.stopPropagation();let P=V.getAttribute("data-annotation-id");if(P===g.current)M({anchorEl:V,annId:P});else A.current(P)},I=(R)=>{let V=R.target.closest("[data-annotation-id]");if(V)A.current(V.getAttribute("data-annotation-id"))},d=(R)=>{let V=R.target.closest("[data-annotation-id]"),P=R.relatedTarget?.closest?.("[data-annotation-id]");if(V&&!P&&!document.getElementById("ann-inline-popover"))A.current(null)};return x.addEventListener("click",y),x.addEventListener("mouseover",I),x.addEventListener("mouseout",d),()=>{x.removeEventListener("click",y),x.removeEventListener("mouseover",I),x.removeEventListener("mouseout",d)}},[Y]),w0(()=>{let x=()=>v();return document.addEventListener("mouseup",x),()=>document.removeEventListener("mouseup",x)},[]);let v=l5(()=>{let x=window.getSelection();if(!x||x.isCollapsed||!x.toString().trim())return;if(!$.current)return;let y=x.getRangeAt(0);if(!$.current.contains(y.startContainer))return;if(y.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let I=x.toString().trim();if(I.length<2)return;let d=k.current(y),R=y.cloneRange(),V=`__pending_${Date.now()}`;try{m1(R,V)}catch{}window.getSelection()?.removeAllRanges();let P=document.querySelectorAll(`[data-annotation-id="${V}"]`),p=P[P.length-1];if(!p)return;j({anchorEl:p,tempId:V,snippet:I,ctx:d})},[]),u=l5((x,y,I,d)=>{j({anchorEl:x,tempId:y,snippet:I,ctx:d})},[]);return{popovers:J5(l3,{children:[T&&(()=>{let x=_.find((y)=>y.id===T.annId);if(!x)return null;return J5(c1,{anchorEl:T.anchorEl,scrollContainer:G,initialNote:x.note,initialImages:x.images,onUpdate:(y,I)=>{U(T.annId,y);let d=x.images||[];for(let R of I)if(!d.includes(R))W(T.annId,R);for(let R of d)if(!I.includes(R))N(T.annId,R)},onDelete:()=>{H(T.annId),F(null)},onClose:()=>M(null)},void 0,!1,void 0,this)})(),L&&J5(p1,{anchorEl:L.anchorEl,scrollContainer:G,snippet:L.snippet,truncateAt:80,onAdd:(x,y)=>{let I=U1();P0(L.tempId,I),m.current(I,L.snippet,x,B.current,L.ctx,y,w.current),j(null)},onCancel:()=>{b0(L.tempId),j(null)}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),openCreatePopover:u,isPopoverOpen:!!(T||L)}}import{jsxDEV as t,Fragment as J$}from"react/jsx-dev-runtime";var Z5="[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']",Q5="[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 Q0({revision:J,filename:$}){let Y=a3(s3),[Z,Q]=W1(null),[q,X]=W1(null),[G,_]=W1(!0),z=i3(null),{annotations:H,addAnnotationWithId:U,removeAnnotation:W,updateAnnotation:N,addAnnotationImage:K,removeAnnotationImage:F,activeAnnotationId:T,setActiveAnnotationId:M}=$1(),L=Y0(()=>H.filter((R)=>!R.filePath&&(!R.canvasFile||R.canvasFile===$)),[H,$]),[j,k]=W1(null),[B,w]=W1(null),[m,g]=W1(null),[A,C]=W1(null),[v,u]=W1(!1);v1(()=>{_(!0),X(null),C(null);let R=$.replace(/\.jsx$/,".js");import(`/api/session/${Y}/canvas/${encodeURIComponent(R)}?rev=${J}&t=${Date.now()}`).then((V)=>{Q(()=>V.default),_(!1)}).catch((V)=>{X(V.message),_(!1)})},[Y,J,$]);let l=document.getElementById("plan-scroll-container"),{popovers:x,isPopoverOpen:y}=g1({containerRef:z,restoreKey:Z,restoreAnnotations:L,extractContext:(R)=>V1(R,z.current),canvasFile:$,scrollContainer:l}),I=Y0(()=>{let R=new Map;for(let V of L)if(V.snippet.startsWith("["))R.set(V.snippet,V.id);return R},[L]);v1(()=>{let R=z.current;if(!R)return;let V=(p)=>{if(m||y)return;let h=p.target;if(h.closest("[data-block-comment-btn]"))return;u(!1);let D=h.closest(Z5);if(D&&R.contains(D)){let E=E1(R).indexOf(D);C(E>=0?E:null)}else C(null);let a=h.closest(Q5);if(a&&R.contains(a)){w(a);let b=d1(a),E=b?I.get(b):void 0;if(E&&E!==T)M(E)}else w(null)},P=(p)=>{if(m||y)return;if(p.relatedTarget?.closest("[data-block-comment-btn]"))return;w(null),M(null)};return R.addEventListener("mousemove",V),R.addEventListener("mouseleave",P),()=>{R.removeEventListener("mousemove",V),R.removeEventListener("mouseleave",P)}},[Z,m,y,I,T]),v1(()=>{let R=(V)=>{let P=V.target.tagName;if(P==="INPUT"||P==="TEXTAREA"||V.target.isContentEditable)return;if(m||y)return;let p=z.current;if(!p)return;if(V.key==="ArrowDown"){V.preventDefault(),u(!0);let h=E1(p);if(h.length===0)return;C((D)=>{if(D===null)return 0;return Math.min(D+1,h.length-1)})}else if(V.key==="ArrowUp"){V.preventDefault(),u(!0);let h=E1(p);if(h.length===0)return;C((D)=>{if(D===null)return h.length-1;return Math.max(D-1,0)})}else if(V.key==="a"||V.key==="A"){if(A===null||!p)return;V.preventDefault();let D=E1(p)[A];if(!D)return;let a=d1(D);if(!a)return;let b=I.get(a);if(b)M(b),g({anchorEl:D,snippet:a,annId:b});else g({anchorEl:D,snippet:a})}else if(V.key===" "||V.key==="Enter"){if(A===null)return;let D=E1(p)[A];if(!D)return;let a=D.getAttribute("data-md");if(a==="choice-option"||a==="multichoice-option")V.preventDefault(),D.dispatchEvent(new CustomEvent("kb-select",{bubbles:!0}));else if(a==="userinput"){V.preventDefault();let b=D.querySelector("textarea");if(b){b.focus();let E=(s)=>{if(s.key==="Escape")s.preventDefault(),b.blur(),u(!0)};b.addEventListener("keydown",E),b.addEventListener("blur",()=>b.removeEventListener("keydown",E),{once:!0})}}else if(a==="rangeinput"){V.preventDefault();let b=D.querySelector("input[type='range']");if(b){b.focus();let E=(s)=>{if(s.key==="Escape"||s.key==="ArrowUp"||s.key==="ArrowDown")s.preventDefault(),b.blur(),u(!0)};b.addEventListener("keydown",E),b.addEventListener("blur",()=>b.removeEventListener("keydown",E),{once:!0})}}}else if(V.key==="Escape")C(null),u(!1),M(null)};return document.addEventListener("keydown",R),()=>document.removeEventListener("keydown",R)},[A,m,y,I]),v1(()=>{let R=z.current;if(!R||A===null||!v)return;let P=E1(R)[A];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 p=d1(P),h=p?I.get(p):void 0;if(h)M(h);return()=>{P.style.outline="",P.style.outlineOffset="",P.style.borderRadius=""}},[A,v,I]);let d=Y0(()=>Z?t(Z,{},void 0,!1,void 0,this):null,[Z]);if(G)return t("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-body",children:"Loading canvas..."},void 0,!1,void 0,this);if(q)return t("div",{className:"bg-accent-red-muted rounded-lg p-5",children:[t("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Compilation Error"},void 0,!1,void 0,this),t("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(!Z)return t("div",{className:"text-text-tertiary text-center py-8 font-body text-body",children:"No canvas loaded"},void 0,!1,void 0,this);return t(t3.Provider,{value:$,children:[t("div",{ref:z,className:"plan-content plan-updated",children:d},void 0,!1,void 0,this),j&&t($$,{note:j.note,onSave:(R)=>{N(j.id,R),k(null)},onCancel:()=>k(null)},void 0,!1,void 0,this),x,t(n3,{containerRef:z,hoveredBlock:B,focusedBlockIndex:A,blockPopover:m,blockAnnotationMap:I,activeAnnotationId:T,onOpen:(R,V,P)=>{if(P)M(P),g({anchorEl:R,snippet:V,annId:P});else g({anchorEl:R,snippet:V})}},void 0,!1,void 0,this),m&&!m.annId&&t(p1,{anchorEl:m.anchorEl,scrollContainer:l,snippet:m.snippet,truncateAt:80,onAdd:(R,V)=>{let P=U1();U(P,m.snippet,R,void 0,void 0,V,$),g(null)},onCancel:()=>g(null)},void 0,!1,void 0,this),m?.annId&&(()=>{let R=L.find((V)=>V.id===m.annId);if(!R)return null;return t(c1,{anchorEl:m.anchorEl,scrollContainer:l,initialNote:R.note,initialImages:R.images,onUpdate:(V,P)=>{N(m.annId,V);let p=R.images||[];for(let h of P)if(!p.includes(h))K(m.annId,h);for(let h of p)if(!P.includes(h))F(m.annId,h)},onDelete:()=>{W(m.annId),M(null),g(null)},onClose:()=>g(null)},void 0,!1,void 0,this)})()]},void 0,!0,void 0,this)}function E1(J){return Array.from(J.querySelectorAll(Z5))}function d1(J){let $=J.getAttribute("data-md");if($==="item"){let Y=J.getAttribute("data-md-label");return Y?`[Item] ${Y}`:null}if($==="section"){let Y=J.getAttribute("data-md-title");return Y?`[Section] ${Y}`:null}if($==="callout"){let Y=J.getAttribute("data-md-type")||"info",Z=J.textContent?.trim().slice(0,60)||"Callout";return`[Callout:${Y}] ${Z}`}if($==="note")return`[Note] ${J.textContent?.trim().slice(0,60)||"Note"}`;if(J.tagName==="TR"){let Y=Array.from(J.querySelectorAll("td")).map((Z)=>Z.textContent?.trim()).filter(Boolean);return Y.length?`[Row] ${Y.join(" | ")}`:null}if($==="checklist-item"){let Y=J.getAttribute("data-md-label");return Y?`[Checklist] ${Y}`:null}if($==="choice-option"||$==="multichoice-option"){let Y=J.getAttribute("data-md-label");return Y?`[Option] ${Y}`:null}if($==="userinput"){let Y=J.getAttribute("data-md-label");return Y?`[Input] ${Y}`:null}if($==="rangeinput"){let Y=J.getAttribute("data-md-label");return Y?`[Range] ${Y}`:null}if($==="image"){let Y=J.getAttribute("data-md-src");return Y?`[Image] ${Y}`:null}return null}function n3({containerRef:J,hoveredBlock:$,focusedBlockIndex:Y,blockPopover:Z,blockAnnotationMap:Q,activeAnnotationId:q,onOpen:X}){let[G,_]=W1([]);v1(()=>{let N=J.current;if(!N||Q.size===0){_([]);return}let K=[];for(let F of N.querySelectorAll(Q5)){let T=d1(F);if(T&&Q.has(T))K.push(F)}_(K)},[Q,J.current]);let[z,H]=W1(null);v1(()=>{if(!q||!J.current){H(null);return}for(let N of J.current.querySelectorAll(Z5)){let K=d1(N);if(K&&Q.get(K)===q){H(N);return}}H(null)},[q,Q]),v1(()=>{if(!z)return;return z.style.boxShadow="inset 0 0 0 1.5px var(--color-highlight-bg)",z.style.borderRadius="8px",()=>{z.style.boxShadow="",z.style.borderRadius=""}},[z]);let U=Y0(()=>{if(Y===null||!J.current)return null;let N=E1(J.current)[Y];if(!N)return null;return N.matches(Q5)?N:null},[Y,J.current]),W=Y0(()=>{let N=new Set(G);if($)N.add($);if(U)N.add(U);if(Z?.anchorEl)N.add(Z.anchorEl);return Array.from(N)},[G,$,U,Z]);return t(J$,{children:W.map((N)=>t(e3,{block:N,isHovered:N===$||N===U||N===Z?.anchorEl,blockAnnotationMap:Q,activeAnnotationId:q,onOpen:X},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 e3({block:J,isHovered:$,blockAnnotationMap:Y,activeAnnotationId:Z,onOpen:Q}){let q=d1(J);if(!q)return null;let X=Y.get(q),G=!!X;return o3(t("button",{"data-block-comment-btn":!0,onClick:(z)=>{z.stopPropagation(),Q(z.currentTarget,q,X)},className:`absolute top-1 right-1 z-10 w-6 h-6 flex items-center justify-center rounded transition-all duration-150 ${G?X===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:G?"Edit annotation":"Add annotation",children:t("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:G?"currentColor":"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:t("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),J)}function $$({note:J,onSave:$,onCancel:Y}){let[Z,Q]=Y5.useState(J),q=Y5.useRef(null);return Y5.useEffect(()=>{q.current?.focus(),q.current?.select()},[]),t("div",{className:"fixed inset-0 z-50 bg-black/40 flex items-center justify-center",onClick:Y,children:t("div",{className:"bg-bg-elevated border border-border-hover rounded-lg shadow-md p-4 w-80",onClick:(X)=>X.stopPropagation(),children:[t("div",{className:"text-tiny uppercase tracking-widest text-text-tertiary font-body mb-2",children:"Edit annotation"},void 0,!1,void 0,this),t("textarea",{ref:q,value:Z,onChange:(X)=>Q(X.target.value),className:"w-full bg-transparent border-none text-body font-body text-text-primary resize-vertical focus:outline-none min-h-[60px]",onKeyDown:(X)=>{if(X.key==="Enter"&&(X.ctrlKey||X.metaKey))$(Z.trim());if(X.key==="Escape")Y()}},void 0,!1,void 0,this),t("div",{className:"flex justify-end gap-2 mt-2",children:[t("button",{onClick:Y,className:"text-meta text-text-tertiary font-body px-3 py-1",children:"Cancel"},void 0,!1,void 0,this),t("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 H$,{useRef as n5,useEffect as z5,useCallback as e5,useState as r1,useContext as j0}from"react";function Z0(J,$,Y,Z){let Q=[],q=J.filter((U)=>U.filePath===_1),X=J.filter((U)=>!U.filePath),G=J.filter((U)=>U.filePath&&U.filePath!==_1),_=Y?Array.from(Y.values()).filter((U)=>q5(U)):[],z=Z?Array.from(Z.values()).filter((U)=>U.markdown.trim()):[];if(_.length>0||z.length>0){Q.push("## Responses"),Q.push("");for(let U of _)Q.push(Z$(U));for(let U of z)Q.push(U.markdown.trim()),Q.push("")}if(q.length>0){Q.push("## Annotations on agent response"),Q.push("");for(let U of q)Q.push(X5(U))}if(X.length>0){Q.push("## Canvas annotations"),Q.push("");let U=new Map;for(let K of X){let F=K.canvasFile||"";if(!U.has(F))U.set(F,[]);U.get(F).push(K)}let W=[...U.keys()].sort(),N=W.length>1||W.length===1&&W[0]!=="";for(let K of W){let F=U.get(K);if(N&&K)Q.push(`### ${K.replace(/\.jsx$/,"")}`),Q.push("");let T=X$(F);Q.push(i5(T))}}if(G.length>0){let U={};for(let W of G){let N=W.filePath;if(!U[N])U[N]=[];U[N].push(W)}Q.push("## File annotations"),Q.push("");for(let[W,N]of Object.entries(U)){Q.push(`### ${W}`),Q.push("");for(let K of N)Q.push(X5(K))}}if($.trim())Q.push("## General notes"),Q.push(""),Q.push($.trim()),Q.push("");return Q.join(`
|
|
60
60
|
`).trim()+`
|
|
61
|
-
`}function
|
|
62
|
-
`)}function
|
|
63
|
-
`);if(Y.length<30&&q===X&&(Z.before||Z.after)){let z=
|
|
61
|
+
`}function q5(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 Y$(J){let $=[];for(let Y of J.values()){if(!Y.required)continue;if(Y.value===null||Y.value===void 0){$.push(Y);continue}if(Y.type==="text"&&!Y.value.trim()){$.push(Y);continue}if(Y.type==="checkbox"&&Y.value.length===0){$.push(Y);continue}}return $}function Q$(J){let $=[];for(let Y of J.values())if(Y.required&&!Y.markdown.trim())$.push(Y);return $}function A0(J,$){let Y=Y$(J),Z=Q$($);return[...Y.map((Q)=>Q.label),...Z.map((Q)=>Q.label||Q.id)]}function Z$(J){let $=[];switch($.push(`**${J.label}**`),J.type){case"radio":case"select":$.push(`Answer: ${J.value}`);break;case"checkbox":for(let Y of J.value)$.push(`- [x] ${Y}`);break;case"text":$.push(""),$.push(J.value.trim());break;case"range":$.push(`Answer: ${J.value}`);break}if(J.note?.trim())$.push(""),$.push(`Note: ${J.note.trim()}`);return $.push(""),$.join(`
|
|
62
|
+
`)}function X5(J){let $=[],Y=J.snippet.trim(),Z=J.context,Q=Z?.lineStart!=null;if(J.filePath&&Q){let q=Z.lineStart,X=Z.lineEnd??q,G=Y.split(`
|
|
63
|
+
`);if(Y.length<30&&q===X&&(Z.before||Z.after)){let z=t0(J);$.push(`> L${q}: ${z}`)}else if(G.length<=6)for(let z=0;z<G.length;z++)$.push(`> ${q+z} | ${G[z]}`);else{for(let z=0;z<3;z++)$.push(`> ${q+z} | ${G[z]}`);$.push(`> ... (${G.length} lines)`);for(let z=G.length-3;z<G.length;z++)$.push(`> ${q+z} | ${G[z]}`)}}else{let q=t0(J);if(Y.split(`
|
|
64
64
|
`).length<=3)$.push(`> ${q.split(`
|
|
65
65
|
`).join(`
|
|
66
66
|
> `)}`);else{let X=Y.split(`
|
|
67
67
|
`);$.push(`> ${X[0]}`),$.push(`> ... (${X.length} lines)`),$.push(`> ${X[X.length-1]}`)}}if(J.note.trim())$.push(""),$.push(J.note.trim());if(J.images?.length){$.push("");for(let q of J.images)$.push(``)}return $.push(""),$.join(`
|
|
68
|
-
`)}function
|
|
69
|
-
`)}import{SessionContext as e5}from"#canvas/runtime";import{useEffect as i5,useState as Z0,useRef as Z$,useMemo as a5}from"react";import{jsxDEV as n}from"react/jsx-dev-runtime";function o5({open:J,onClose:$,onSubmit:Y}){let{annotations:Z,generalNote:Q,responses:q,feedbackEntries:X}=e(),[G,_]=Z0(""),[z,H]=Z0(!1),[U,W]=Z0(!1),[N,K]=Z0(null),T=Z$(null),[O,S]=Z0(!1);if(J&&!O)H(!1),W(!1),K(null);if(!J&&O)H(!1),W(!1),K(null);if(J!==O)S(J);let L=a5(()=>Q0(Z,Q,q,X),[Z,Q,q,X]),j=z?G:L;if(i5(()=>{if(J&&U&&T.current)T.current.focus()},[J,U]),i5(()=>{if(!J)return;let M=(I)=>{if(I.key==="Escape")$()};return window.addEventListener("keydown",M),()=>window.removeEventListener("keydown",M)},[J,$]),!J)return null;let V=j.trim().length>0;return n("div",{className:"fixed inset-0 z-50 bg-black/50 backdrop-blur-sm flex items-center justify-center p-8",onClick:$,children:n("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:[n("div",{className:"flex items-center justify-between px-5 py-3 border-b border-border-subtle flex-shrink-0",children:[n("div",{className:"flex items-center gap-3",children:[n("span",{className:"text-[13px] font-medium text-text-primary font-body",children:"Response preview"},void 0,!1,void 0,this),z&&n("button",{onClick:()=>{H(!1),W(!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),n("div",{className:"flex items-center gap-2",children:[n("div",{className:"flex items-center bg-bg-base rounded-md p-0.5",children:[n("button",{onClick:()=>W(!1),className:`px-2.5 py-1 rounded text-[11px] font-body font-medium transition-colors ${!U?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Preview"},void 0,!1,void 0,this),n("button",{onClick:()=>W(!0),className:`px-2.5 py-1 rounded text-[11px] font-body font-medium transition-colors ${U?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Edit"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),n("button",{onClick:$,className:"text-text-tertiary hover:text-text-secondary w-7 h-7 flex items-center justify-center rounded-md hover:bg-border-subtle transition-colors",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),U?n("textarea",{ref:T,value:j,onChange:(M)=>{_(M.target.value),H(!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):n("div",{className:"flex-1 overflow-y-auto p-5",children:n(A0,{text:j},void 0,!1,void 0,this)},void 0,!1,void 0,this),N&&n("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:[n("span",{children:N},void 0,!1,void 0,this),n("button",{onClick:()=>{K(null),Y(j)},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),n("div",{className:"flex justify-end gap-2 px-5 py-3 border-t border-border-subtle flex-shrink-0",children:[n("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),n("button",{onClick:()=>{let M=w0(q,X);if(M.length>0){K(`Please answer: ${M.join(", ")}`);return}K(null),Y(j)},disabled:!V,className:`px-6 py-2 rounded-lg font-body text-[13px] font-medium transition-all ${V?"bg-btn-primary text-btn-primary-text hover:opacity-90":"bg-bg-input text-text-disabled cursor-default"}`,children:"Submit feedback"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}var X$=/!\[([^\]]*)\]\((\/tmp\/agent-canvas\/uploads\/([^)]+))\)/g;function q$(J){return J.replace(X$,($,Y,Z,Q)=>``)}function A0({text:J}){let $=a5(()=>a.parse(q$(J),{async:!1}),[J]);return n("div",{className:"prose-canvas font-body text-body text-text-primary leading-relaxed",dangerouslySetInnerHTML:{__html:$}},void 0,!1,void 0,this)}import{jsxDEV as f1}from"react/jsx-dev-runtime";var _$={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"},z$={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 P1({name:J,type:$,expanded:Y,className:Z=""}){if($==="dir")return f1("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",className:`flex-shrink-0 ${Z}`,children:Y?f1("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):f1("path",{d:"M1.5 3.5h5l1.5 1.5h6.5v8h-13z",style:{fill:"var(--color-folder-fill)",stroke:"var(--color-folder-stroke)"},strokeWidth:"1"},void 0,!1,void 0,this)},void 0,!1,void 0,this);let Q=J.includes(".")?J.split(".").pop().toLowerCase():"",q=_$[Q]||"#6b6560",X=z$[Q];return f1("svg",{width:"14",height:"14",viewBox:"0 0 16 16",className:`flex-shrink-0 ${Z}`,children:[f1("path",{d:"M2 1.5h8l3.5 3.5v9.5a1 1 0 01-1 1H3a1 1 0 01-1-1v-12a1 1 0 011-1z",fill:q,opacity:"0.85"},void 0,!1,void 0,this),f1("path",{d:"M10 1.5v2.5a1 1 0 001 1h2.5",fill:"none",stroke:"white",strokeWidth:"0.5",opacity:"0.5"},void 0,!1,void 0,this),X&&f1("text",{x:"8",y:"11.5",textAnchor:"middle",fill:"white",fontSize:"5.5",fontFamily:"monospace",fontWeight:"600",children:X},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function G$(J){let $=J.getAttribute("data-md");if($==="item"){let Y=J.getAttribute("data-md-label");return Y?`[Item] ${Y}`:null}if($==="section"){let Y=J.getAttribute("data-md-title");return Y?`[Section] ${Y}`:null}if($==="callout"){let Y=J.getAttribute("data-md-type")||"info",Z=J.textContent?.trim().slice(0,60)||"Callout";return`[Callout:${Y}] ${Z}`}if($==="note")return`[Note] ${J.textContent?.trim().slice(0,60)||"Note"}`;if(J.tagName==="TR"){let Y=Array.from(J.querySelectorAll("td")).map((Z)=>Z.textContent?.trim()).filter(Boolean);return Y.length?`[Row] ${Y.join(" | ")}`:null}if($==="checklist-item"){let Y=J.getAttribute("data-md-label");return Y?`[Checklist] ${Y}`:null}if($==="choice-option"||$==="multichoice-option"){let Y=J.getAttribute("data-md-label");return Y?`[Option] ${Y}`:null}if($==="userinput"){let Y=J.getAttribute("data-md-label");return Y?`[Input] ${Y}`:null}if($==="rangeinput"){let Y=J.getAttribute("data-md-label");return Y?`[Range] ${Y}`:null}if($==="image"){let Y=J.getAttribute("data-md-src");return Y?`[Image] ${Y}`:null}return null}function X0(J){let $=document.querySelector(`[data-annotation-id="${J.id}"]`);if($)return $;if(J.snippet.startsWith("[")){for(let Y of document.querySelectorAll("[data-md='item'], [data-md='section'], [data-md='table'] tbody tr, [data-md='callout'], [data-md='note'], [data-md='checklist-item'], [data-md='image']"))if(G$(Y)===J.snippet)return Y}return null}function s5(J){J.classList.remove("ann-flash"),J.offsetWidth,J.classList.add("ann-flash"),J.addEventListener("animationend",()=>{J.classList.remove("ann-flash")},{once:!0})}function q5(J,$){if(J.filePath)$({type:"file",path:J.filePath}),setTimeout(()=>{let Y=X0(J);if(Y)Y.scrollIntoView({behavior:"smooth",block:"center"}),s5(Y)},150);else{let Y=X0(J);if(Y)Y.scrollIntoView({behavior:"smooth",block:"center"}),s5(Y)}}import{jsxDEV as w,Fragment as I0}from"react/jsx-dev-runtime";function z5({onPreview:J,onSubmit:$,collapseButton:Y}){let{isReadOnly:Z,selectedRevision:Q,currentRevision:q,revisions:X}=C0(N1),G=C0(e5),_=Z&&Q===q,H=X.find((U)=>U.revision===Q)?.label||`Round ${Q}`;if(Z)return w(H$,{sessionId:G,revision:Q,label:H,waitingForUpdate:_,collapseButton:Y},void 0,!1,void 0,this);return w(T$,{onPreview:J,onSubmit:$,collapseButton:Y},void 0,!1,void 0,this)}function K$({sessionId:J,revision:$,label:Y,waitingForUpdate:Z,collapseButton:Q}){let[q,X]=l1(null),[G,_]=l1(!0);return _5(()=>{_(!0),fetch(`/api/session/${J}/revision/${$}/feedback`).then((z)=>z.json()).then((z)=>{X(z.feedback||null),_(!1)}).catch(()=>{X(null),_(!1)})},[J,$]),w("div",{className:"flex flex-col h-full",children:[w("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[w("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:Z?"Feedback sent":`Feedback — ${Y}`},void 0,!1,void 0,this),Q]},void 0,!0,void 0,this),Z&&w("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:[w("span",{className:"w-2 h-2 rounded-full bg-accent-green animate-pulse"},void 0,!1,void 0,this),w("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),w("div",{className:"flex-1 overflow-y-auto px-4",children:G?w("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"Loading..."},void 0,!1,void 0,this):q?w(A0,{text:q},void 0,!1,void 0,this):w("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 H$({sessionId:J,revision:$,label:Y,waitingForUpdate:Z,collapseButton:Q}){let{annotations:q,generalNote:X,activeAnnotationId:G,setActiveAnnotationId:_}=e(),{setActiveView:z}=C0(F1),H=q.length>0||X.trim().length>0,[U,W]=l1("feedback");if(!H)return w(K$,{sessionId:J,revision:$,label:Y,waitingForUpdate:Z,collapseButton:Q},void 0,!1,void 0,this);return w("div",{className:"flex flex-col h-full",children:[w("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[w("div",{className:"flex items-center gap-1 bg-bg-input rounded-md p-0.5",children:[w("button",{onClick:()=>W("feedback"),className:`px-2.5 py-1 rounded text-[11px] font-medium font-body transition-colors ${U==="feedback"?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Feedback"},void 0,!1,void 0,this),w("button",{onClick:()=>W("annotations"),className:`px-2.5 py-1 rounded text-[11px] font-medium font-body transition-colors flex items-center gap-1.5 ${U==="annotations"?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:["Annotations",w("span",{className:"inline-flex items-center justify-center min-w-[16px] h-[16px] px-1 rounded-full bg-border-subtle text-[10px] font-medium",children:q.length},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Q]},void 0,!0,void 0,this),Z&&w("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:[w("span",{className:"w-2 h-2 rounded-full bg-accent-green animate-pulse"},void 0,!1,void 0,this),w("span",{className:"text-[12px] font-body text-accent-green",children:"Waiting for next revision..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this),U==="feedback"?w(W$,{sessionId:J,revision:$},void 0,!1,void 0,this):w(N$,{annotations:q,generalNote:X,activeAnnotationId:G,setActiveAnnotationId:_,setActiveView:z},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function W$({sessionId:J,revision:$}){let[Y,Z]=l1(null),[Q,q]=l1(!0);return _5(()=>{q(!0),fetch(`/api/session/${J}/revision/${$}/feedback`).then((X)=>X.json()).then((X)=>{Z(X.feedback||null),q(!1)}).catch(()=>{Z(null),q(!1)})},[J,$]),w("div",{className:"flex-1 overflow-y-auto px-4",children:Q?w("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"Loading..."},void 0,!1,void 0,this):Y?w(A0,{text:Y},void 0,!1,void 0,this):w("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 N$({annotations:J,generalNote:$,activeAnnotationId:Y,setActiveAnnotationId:Z,setActiveView:Q}){let q=J.filter((K)=>K.filePath===q1),X=J.filter((K)=>!K.filePath),G=J.filter((K)=>K.filePath&&K.filePath!==q1),_={};for(let K of G){let T=K.filePath;if(!_[T])_[T]=[];_[T].push(K)}let z=(K)=>{Z(K),m1(K,!0)},H=(K)=>{Z(null),m1(K,!1)},U=(K)=>{if(K.id===Y)Z(null);else if(Z(K.id),K.filePath)Q({type:"file",path:K.filePath}),setTimeout(()=>{let T=X0(K);if(T)T.scrollIntoView({behavior:"smooth",block:"center"})},150)},W=(K)=>w("div",{className:`group/ann relative px-3 py-2.5 transition-colors duration-150 cursor-pointer ${Y===K.id?"bg-highlight-selected":"odd:bg-bg-elevated-half hover:bg-bg-input"}`,onMouseEnter:()=>z(K.id),onMouseLeave:()=>H(K.id),onClick:()=>U(K),children:[w("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:K.snippet.length>80?K.snippet.slice(0,80)+"...":K.snippet},void 0,!1,void 0,this),K.note.trim()&&w("div",{className:"text-[13px] font-body text-text-primary leading-relaxed",children:K.note},void 0,!1,void 0,this),w(v5,{images:K.images||[]},void 0,!1,void 0,this),w("div",{className:"absolute top-1.5 right-1.5 opacity-0 group-hover/ann:opacity-100 transition-opacity duration-100",children:w("button",{onClick:(T)=>{T.stopPropagation(),q5(K,Q)},className:"w-5 h-5 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-input transition-colors",title:"Scroll to annotation",children:w("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[w("circle",{cx:"12",cy:"12",r:"3"},void 0,!1,void 0,this),w("path",{d:"M12 2v4M12 18v4M2 12h4M18 12h4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},K.id,!0,void 0,this),N=[q,X,G].filter((K)=>K.length>0).length>1;return w(I0,{children:[w("div",{className:"flex-1 overflow-y-auto",children:[q.length>0&&w(I0,{children:[N&&w("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body px-3 mb-1 mt-1",children:"Agent Response"},void 0,!1,void 0,this),q.map(W)]},void 0,!0,void 0,this),X.length>0&&w(I0,{children:[N&&w("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body px-3 mb-1 mt-1",children:"Canvas"},void 0,!1,void 0,this),X.map(W)]},void 0,!0,void 0,this),Object.entries(_).map(([K,T])=>w("div",{children:[w("button",{onClick:()=>Q({type:"file",path:K}),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:K,children:[w(P1,{name:K.split("/").pop()||K,type:"file"},void 0,!1,void 0,this),w("span",{className:"truncate",children:K},void 0,!1,void 0,this)]},void 0,!0,void 0,this),T.map(W)]},K,!0,void 0,this))]},void 0,!0,void 0,this),$.trim()&&w("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:w("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 T$({onPreview:J,onSubmit:$,collapseButton:Y}){let{annotations:Z,updateAnnotation:Q,removeAnnotation:q,addAnnotationImage:X,removeAnnotationImage:G,generalNote:_,setGeneralNote:z,activeAnnotationId:H,setActiveAnnotationId:U,responses:W,feedbackEntries:N}=e(),K=C0(e5),{setActiveView:T}=U$.useContext(F1),O=t5(null),S=t5(new Map),L=Z.filter((y)=>y.filePath===q1),j=Z.filter((y)=>!y.filePath),V=Z.filter((y)=>y.filePath&&y.filePath!==q1),M={};for(let y of V){let P=y.filePath;if(!M[P])M[P]=[];M[P].push(y)}_5(()=>{if(!H)return;let y=S.current.get(H);if(y)y.scrollIntoView({behavior:"smooth",block:"nearest"})},[H]);let I=n5((y)=>{U(y),m1(y,!0)},[U]),D=n5((y)=>{U(null),m1(y,!1)},[H]),E=Array.from(W.values()).some(X5),C=N.size>0,R=Z.length>0||_.trim().length>0||E||C,[v,m]=l1(null),c=(y)=>w("div",{ref:(P)=>{if(P)S.current.set(y.id,P);else S.current.delete(y.id)},className:`group/ann relative px-3 py-2.5 transition-colors duration-150 ${H===y.id?"bg-highlight-selected":"odd:bg-bg-elevated-half hover:bg-bg-input"}`,onMouseEnter:()=>I(y.id),onMouseLeave:()=>D(y.id),onClick:()=>{if(y.id===H)U(null);else if(U(y.id),y.filePath)T({type:"file",path:y.filePath}),setTimeout(()=>{let P=X0(y);if(P)P.scrollIntoView({behavior:"smooth",block:"center"})},150)},children:[w("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:y.snippet.length>80?y.snippet.slice(0,80)+"...":y.snippet},void 0,!1,void 0,this),w("div",{onClick:(P)=>P.stopPropagation(),children:w(F0,{note:y.note,onNoteChange:(P)=>Q(y.id,P),images:y.images||[],onAddImage:(P)=>X(y.id,P),onRemoveImage:(P)=>G(y.id,P),sessionId:K,autoResize:!0,minHeight:20,textareaClassName:"w-full bg-transparent text-[13px] font-body text-text-primary resize-none focus:outline-none leading-relaxed p-0 border-none min-h-[20px]",textareaStyle:{height:"auto",overflow:"hidden"},placeholder:"Add your note...",attachButton:"on-focus"},void 0,!1,void 0,this)},void 0,!1,void 0,this),w("div",{className:"absolute top-1.5 right-1.5 opacity-0 group-hover/ann:opacity-100 transition-opacity duration-100 flex items-center gap-0.5",children:[w("button",{onClick:(P)=>{P.stopPropagation(),q5(y,T)},className:"w-5 h-5 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-input transition-colors",title:"Scroll to annotation",children:w("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[w("circle",{cx:"12",cy:"12",r:"3"},void 0,!1,void 0,this),w("path",{d:"M12 2v4M12 18v4M2 12h4M18 12h4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),w("button",{onClick:(P)=>{P.stopPropagation(),q(y.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:w("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[w("polyline",{points:"3 6 5 6 21 6"},void 0,!1,void 0,this),w("path",{d:"M19 6v14a2 2 0 01-2 2H7a2 2 0 01-2-2V6m3 0V4a2 2 0 012-2h4a2 2 0 012 2v2"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},y.id,!0,void 0,this);return w("div",{className:"flex flex-col h-full",children:[w("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[w("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body flex items-center gap-2",children:["Annotations",Z.length>0&&w("span",{className:"inline-flex items-center justify-center min-w-[18px] h-[18px] px-1 rounded-full bg-border-subtle text-[10px] font-medium text-text-secondary",children:Z.length},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Y]},void 0,!0,void 0,this),w("div",{ref:O,className:"flex-1 overflow-y-auto",children:[Z.length===0&&w("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),L.length>0&&w(I0,{children:[(j.length>0||V.length>0)&&w("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),L.map(c)]},void 0,!0,void 0,this),j.length>0&&(L.length>0||V.length>0)&&w("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),j.map(c),Object.entries(M).map(([y,P])=>w("div",{children:[w("button",{onClick:()=>T({type:"file",path:y}),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:y,children:[w(P1,{name:y.split("/").pop()||y,type:"file"},void 0,!1,void 0,this),w("span",{className:"truncate",children:y},void 0,!1,void 0,this)]},void 0,!0,void 0,this),P.map(c)]},y,!0,void 0,this))]},void 0,!0,void 0,this),w("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:w("textarea",{value:_,onChange:(y)=>z(y.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:(y)=>e1(y.target,40),ref:(y)=>{if(y)e1(y,40)}},void 0,!1,void 0,this)},void 0,!1,void 0,this),v&&w("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:[w("span",{children:v},void 0,!1,void 0,this),w("button",{onClick:()=>{m(null);let y=Q0(Z,_,W,N);$(y)},className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body whitespace-nowrap underline",children:"Submit anyway"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),w("div",{className:"px-4 py-3 border-t border-border-subtle flex-shrink-0",children:R?w("div",{className:"flex gap-2",children:[w("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),w("button",{onClick:()=>{let y=w0(W,N);if(y.length>0){m(`Please answer: ${y.join(", ")}`);return}m(null);let P=Q0(Z,_,W,N);$(P)},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):w("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 O$,useState as $2,useContext as J2,useMemo as F$}from"react";import{SessionContext as L$}from"#canvas/runtime";import{jsxDEV as d,Fragment as G5}from"react/jsx-dev-runtime";function Y2({embedded:J}={}){let $=J2(L$),{annotations:Y,addAnnotation:Z}=e(),{setActiveView:Q}=J2(F1),[q,X]=$2(!1),[G,_]=$2({}),{annCountMap:z,annotatedFiles:H}=F$(()=>{let L=new Map;for(let j of Y)if(j.filePath&&j.filePath!==q1)L.set(j.filePath,(L.get(j.filePath)||0)+1);return{annCountMap:L,annotatedFiles:[...L.keys()]}},[Y]),U=async(L)=>{let V=await(await fetch(`/api/tree?session=${$}&path=${encodeURIComponent(L)}`)).json();if(V.entries)_((M)=>({...M,[L]:{entries:V.entries,expanded:!0,loaded:!0}}))};O$(()=>{if(!q&&!G[""])U("")},[q]);let W=(L)=>{if(G[L]?.loaded)_((j)=>({...j,[L]:{...j[L],expanded:!j[L].expanded}}));else U(L)},N=(L)=>{Q({type:"file",path:L})},K=async(L)=>{let V=await(await fetch(`/api/file?session=${$}&path=${encodeURIComponent(L)}`)).json();if(!V.error){let M=V.content.split(`
|
|
68
|
+
`)}function X$(J){let $={label:"",annotations:[],children:new Map};for(let Y of J){let Z=Y.context?.hierarchy||[],Q=$;for(let q of Z){if(!Q.children.has(q))Q.children.set(q,{label:q,annotations:[],children:new Map});Q=Q.children.get(q)}Q.annotations.push(Y)}return $}function i5(J,$=0){let Y=[];for(let Z of J.annotations)Y.push(X5(Z));for(let[,Z]of J.children){let Q=$===0?"###":"####";Y.push(`${Q} ${Z.label}`),Y.push(""),Y.push(i5(Z,$+1))}return Y.join(`
|
|
69
|
+
`)}import{SessionContext as $2}from"#canvas/runtime";import{useEffect as a5,useState as X0,useRef as q$,useMemo as o5}from"react";import{jsxDEV as n}from"react/jsx-dev-runtime";function s5({open:J,onClose:$,onSubmit:Y}){let{annotations:Z,generalNote:Q,responses:q,feedbackEntries:X}=$1(),[G,_]=X0(""),[z,H]=X0(!1),[U,W]=X0(!1),[N,K]=X0(null),F=q$(null),[T,M]=X0(!1);if(J&&!T)H(!1),W(!1),K(null);if(!J&&T)H(!1),W(!1),K(null);if(J!==T)M(J);let L=o5(()=>Z0(Z,Q,q,X),[Z,Q,q,X]),j=z?G:L;if(a5(()=>{if(J&&U&&F.current)F.current.focus()},[J,U]),a5(()=>{if(!J)return;let B=(w)=>{if(w.key==="Escape")$()};return window.addEventListener("keydown",B),()=>window.removeEventListener("keydown",B)},[J,$]),!J)return null;let k=j.trim().length>0;return n("div",{className:"fixed inset-0 z-50 bg-black/50 backdrop-blur-sm flex items-center justify-center p-8",onClick:$,children:n("div",{className:"bg-bg-surface border border-border-medium rounded-xl shadow-lg w-full max-w-2xl flex flex-col",style:{height:"80vh"},onClick:(B)=>B.stopPropagation(),children:[n("div",{className:"flex items-center justify-between px-5 py-3 border-b border-border-subtle flex-shrink-0",children:[n("div",{className:"flex items-center gap-3",children:[n("span",{className:"text-[13px] font-medium text-text-primary font-body",children:"Response preview"},void 0,!1,void 0,this),z&&n("button",{onClick:()=>{H(!1),W(!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),n("div",{className:"flex items-center gap-2",children:[n("div",{className:"flex items-center bg-bg-base rounded-md p-0.5",children:[n("button",{onClick:()=>W(!1),className:`px-2.5 py-1 rounded text-[11px] font-body font-medium transition-colors ${!U?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Preview"},void 0,!1,void 0,this),n("button",{onClick:()=>W(!0),className:`px-2.5 py-1 rounded text-[11px] font-body font-medium transition-colors ${U?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Edit"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),n("button",{onClick:$,className:"text-text-tertiary hover:text-text-secondary w-7 h-7 flex items-center justify-center rounded-md hover:bg-border-subtle transition-colors",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),U?n("textarea",{ref:F,value:j,onChange:(B)=>{_(B.target.value),H(!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):n("div",{className:"flex-1 overflow-y-auto p-5",children:n(I0,{text:j},void 0,!1,void 0,this)},void 0,!1,void 0,this),N&&n("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:[n("span",{children:N},void 0,!1,void 0,this),n("button",{onClick:()=>{K(null),Y(j)},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),n("div",{className:"flex justify-end gap-2 px-5 py-3 border-t border-border-subtle flex-shrink-0",children:[n("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),n("button",{onClick:()=>{let B=A0(q,X);if(B.length>0){K(`Please answer: ${B.join(", ")}`);return}K(null),Y(j)},disabled:!k,className:`px-6 py-2 rounded-lg font-body text-[13px] font-medium transition-all ${k?"bg-btn-primary text-btn-primary-text hover:opacity-90":"bg-bg-input text-text-disabled cursor-default"}`,children:"Submit feedback"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}var _$=/!\[([^\]]*)\]\((\/tmp\/agent-canvas\/uploads\/([^)]+))\)/g;function z$(J){return J.replace(_$,($,Y,Z,Q)=>``)}function I0({text:J}){let $=o5(()=>o.parse(z$(J),{async:!1}),[J]);return n("div",{className:"prose-canvas font-body text-body text-text-primary leading-relaxed",dangerouslySetInnerHTML:{__html:$}},void 0,!1,void 0,this)}import{jsxDEV as x1}from"react/jsx-dev-runtime";var G$={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"},U$={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 P1({name:J,type:$,expanded:Y,className:Z=""}){if($==="dir")return x1("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",className:`flex-shrink-0 ${Z}`,children:Y?x1("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):x1("path",{d:"M1.5 3.5h5l1.5 1.5h6.5v8h-13z",style:{fill:"var(--color-folder-fill)",stroke:"var(--color-folder-stroke)"},strokeWidth:"1"},void 0,!1,void 0,this)},void 0,!1,void 0,this);let Q=J.includes(".")?J.split(".").pop().toLowerCase():"",q=G$[Q]||"#6b6560",X=U$[Q];return x1("svg",{width:"14",height:"14",viewBox:"0 0 16 16",className:`flex-shrink-0 ${Z}`,children:[x1("path",{d:"M2 1.5h8l3.5 3.5v9.5a1 1 0 01-1 1H3a1 1 0 01-1-1v-12a1 1 0 011-1z",fill:q,opacity:"0.85"},void 0,!1,void 0,this),x1("path",{d:"M10 1.5v2.5a1 1 0 001 1h2.5",fill:"none",stroke:"white",strokeWidth:"0.5",opacity:"0.5"},void 0,!1,void 0,this),X&&x1("text",{x:"8",y:"11.5",textAnchor:"middle",fill:"white",fontSize:"5.5",fontFamily:"monospace",fontWeight:"600",children:X},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function K$(J){let $=J.getAttribute("data-md");if($==="item"){let Y=J.getAttribute("data-md-label");return Y?`[Item] ${Y}`:null}if($==="section"){let Y=J.getAttribute("data-md-title");return Y?`[Section] ${Y}`:null}if($==="callout"){let Y=J.getAttribute("data-md-type")||"info",Z=J.textContent?.trim().slice(0,60)||"Callout";return`[Callout:${Y}] ${Z}`}if($==="note")return`[Note] ${J.textContent?.trim().slice(0,60)||"Note"}`;if(J.tagName==="TR"){let Y=Array.from(J.querySelectorAll("td")).map((Z)=>Z.textContent?.trim()).filter(Boolean);return Y.length?`[Row] ${Y.join(" | ")}`:null}if($==="checklist-item"){let Y=J.getAttribute("data-md-label");return Y?`[Checklist] ${Y}`:null}if($==="choice-option"||$==="multichoice-option"){let Y=J.getAttribute("data-md-label");return Y?`[Option] ${Y}`:null}if($==="userinput"){let Y=J.getAttribute("data-md-label");return Y?`[Input] ${Y}`:null}if($==="rangeinput"){let Y=J.getAttribute("data-md-label");return Y?`[Range] ${Y}`:null}if($==="image"){let Y=J.getAttribute("data-md-src");return Y?`[Image] ${Y}`:null}return null}function q0(J){let $=document.querySelector(`[data-annotation-id="${J.id}"]`);if($)return $;if(J.snippet.startsWith("[")){for(let Y of document.querySelectorAll("[data-md='item'], [data-md='section'], [data-md='table'] tbody tr, [data-md='callout'], [data-md='note'], [data-md='checklist-item'], [data-md='image']"))if(K$(Y)===J.snippet)return Y}return null}function t5(J){J.classList.remove("ann-flash"),J.offsetWidth,J.classList.add("ann-flash"),J.addEventListener("animationend",()=>{J.classList.remove("ann-flash")},{once:!0})}function _5(J,$){if(J.filePath)$({type:"file",path:J.filePath}),setTimeout(()=>{let Y=q0(J);if(Y)Y.scrollIntoView({behavior:"smooth",block:"center"}),t5(Y)},150);else{let Y=q0(J);if(Y)Y.scrollIntoView({behavior:"smooth",block:"center"}),t5(Y)}}import{jsxDEV as S,Fragment as C0}from"react/jsx-dev-runtime";function G5({onPreview:J,onSubmit:$,collapseButton:Y}){let{isReadOnly:Z,selectedRevision:Q,currentRevision:q,revisions:X,agentWatching:G}=j0(N1),_=j0($2),z=X.find((N)=>N.revision===Q),H=Z&&Q===q,U=!!z?.feedbackConsumed,W=z?.label||`Round ${Q}`;if(Z)return S(N$,{sessionId:_,revision:Q,label:W,waitingForUpdate:H,feedbackConsumed:U,agentWatching:G,collapseButton:Y},void 0,!1,void 0,this);return S(F$,{onPreview:J,onSubmit:$,agentWatching:G,collapseButton:Y},void 0,!1,void 0,this)}function W$({sessionId:J,revision:$,label:Y,waitingForUpdate:Z,feedbackConsumed:Q,agentWatching:q,collapseButton:X}){let[G,_]=r1(null),[z,H]=r1(!0);return z5(()=>{H(!0),fetch(`/api/session/${J}/revision/${$}/feedback`).then((U)=>U.json()).then((U)=>{_(U.feedback||null),H(!1)}).catch(()=>{_(null),H(!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 — ${Y}`},void 0,!1,void 0,this),X]},void 0,!0,void 0,this),Z&&S(J2,{feedbackConsumed:Q,agentWatching:q},void 0,!1,void 0,this),S("div",{className:"flex-1 overflow-y-auto px-4",children:z?S("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"Loading..."},void 0,!1,void 0,this):G?S(I0,{text:G},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 J2({feedbackConsumed:J,agentWatching:$}){if(J)return 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:"Feedback received — waiting for next revision..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if($)return S("div",{className:"mx-4 mb-3 px-3 py-2.5 rounded-lg bg-accent-blue-muted flex items-center gap-2 flex-shrink-0",children:[S("span",{className:"w-2 h-2 rounded-full bg-accent-blue animate-pulse"},void 0,!1,void 0,this),S("span",{className:"text-[12px] font-body text-accent-blue",children:"Waiting for agent to pick up feedback..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return S("div",{className:"mx-4 mb-3 px-3 py-2.5 rounded-lg bg-accent-amber-muted flex items-center gap-2 flex-shrink-0",children:[S("span",{className:"w-2 h-2 rounded-full bg-accent-amber"},void 0,!1,void 0,this),S("span",{className:"text-[12px] font-body text-accent-amber",children:"Agent disconnected — tell Claude to check feedback"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function N$({sessionId:J,revision:$,label:Y,waitingForUpdate:Z,feedbackConsumed:Q,agentWatching:q,collapseButton:X}){let{annotations:G,generalNote:_,activeAnnotationId:z,setActiveAnnotationId:H}=$1(),{setActiveView:U}=j0(F1),W=G.length>0||_.trim().length>0,[N,K]=r1("feedback");if(!W)return S(W$,{sessionId:J,revision:$,label:Y,waitingForUpdate:Z,feedbackConsumed:Q,agentWatching:q,collapseButton:X},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:()=>K("feedback"),className:`px-2.5 py-1 rounded text-[11px] font-medium font-body transition-colors ${N==="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:()=>K("annotations"),className:`px-2.5 py-1 rounded text-[11px] font-medium font-body transition-colors flex items-center gap-1.5 ${N==="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:G.length},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),X]},void 0,!0,void 0,this),Z&&S(J2,{feedbackConsumed:Q,agentWatching:q},void 0,!1,void 0,this),N==="feedback"?S(T$,{sessionId:J,revision:$},void 0,!1,void 0,this):S(O$,{annotations:G,generalNote:_,activeAnnotationId:z,setActiveAnnotationId:H,setActiveView:U},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function T$({sessionId:J,revision:$}){let[Y,Z]=r1(null),[Q,q]=r1(!0);return z5(()=>{q(!0),fetch(`/api/session/${J}/revision/${$}/feedback`).then((X)=>X.json()).then((X)=>{Z(X.feedback||null),q(!1)}).catch(()=>{Z(null),q(!1)})},[J,$]),S("div",{className:"flex-1 overflow-y-auto px-4",children:Q?S("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"Loading..."},void 0,!1,void 0,this):Y?S(I0,{text:Y},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 O$({annotations:J,generalNote:$,activeAnnotationId:Y,setActiveAnnotationId:Z,setActiveView:Q}){let q=J.filter((K)=>K.filePath===_1),X=J.filter((K)=>!K.filePath),G=J.filter((K)=>K.filePath&&K.filePath!==_1),_={};for(let K of G){let F=K.filePath;if(!_[F])_[F]=[];_[F].push(K)}let z=(K)=>{Z(K),D1(K,!0)},H=(K)=>{Z(null),D1(K,!1)},U=(K)=>{if(K.id===Y)Z(null);else if(Z(K.id),K.filePath)Q({type:"file",path:K.filePath}),setTimeout(()=>{let F=q0(K);if(F)F.scrollIntoView({behavior:"smooth",block:"center"})},150)},W=(K)=>S("div",{className:`group/ann relative px-3 py-2.5 transition-colors duration-150 cursor-pointer ${Y===K.id?"bg-highlight-selected":"odd:bg-bg-elevated-half hover:bg-bg-input"}`,onMouseEnter:()=>z(K.id),onMouseLeave:()=>H(K.id),onClick:()=>U(K),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:K.snippet.length>80?K.snippet.slice(0,80)+"...":K.snippet},void 0,!1,void 0,this),K.note.trim()&&S("div",{className:"text-[13px] font-body text-text-primary leading-relaxed",children:K.note},void 0,!1,void 0,this),S(x5,{images:K.images||[]},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:(F)=>{F.stopPropagation(),_5(K,Q)},className:"w-5 h-5 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-input transition-colors",title:"Scroll to annotation",children:S("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[S("circle",{cx:"12",cy:"12",r:"3"},void 0,!1,void 0,this),S("path",{d:"M12 2v4M12 18v4M2 12h4M18 12h4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},K.id,!0,void 0,this),N=[q,X,G].filter((K)=>K.length>0).length>1;return S(C0,{children:[S("div",{className:"flex-1 overflow-y-auto",children:[q.length>0&&S(C0,{children:[N&&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),q.map(W)]},void 0,!0,void 0,this),X.length>0&&S(C0,{children:[N&&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),X.map(W)]},void 0,!0,void 0,this),Object.entries(_).map(([K,F])=>S("div",{children:[S("button",{onClick:()=>Q({type:"file",path:K}),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:K,children:[S(P1,{name:K.split("/").pop()||K,type:"file"},void 0,!1,void 0,this),S("span",{className:"truncate",children:K},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F.map(W)]},K,!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 F$({onPreview:J,onSubmit:$,agentWatching:Y,collapseButton:Z}){let{annotations:Q,updateAnnotation:q,removeAnnotation:X,addAnnotationImage:G,removeAnnotationImage:_,generalNote:z,setGeneralNote:H,activeAnnotationId:U,setActiveAnnotationId:W,responses:N,feedbackEntries:K}=$1(),F=j0($2),{setActiveView:T}=H$.useContext(F1),M=n5(null),L=n5(new Map),j=Q.filter((y)=>y.filePath===_1),k=Q.filter((y)=>!y.filePath),B=Q.filter((y)=>y.filePath&&y.filePath!==_1),w={};for(let y of B){let I=y.filePath;if(!w[I])w[I]=[];w[I].push(y)}z5(()=>{if(!U)return;let y=L.current.get(U);if(y)y.scrollIntoView({behavior:"smooth",block:"nearest"})},[U]);let m=e5((y)=>{W(y),D1(y,!0)},[W]),g=e5((y)=>{W(null),D1(y,!1)},[U]),A=Array.from(N.values()).some(q5),C=K.size>0,v=Q.length>0||z.trim().length>0||A||C,[u,l]=r1(null),x=(y)=>S("div",{ref:(I)=>{if(I)L.current.set(y.id,I);else L.current.delete(y.id)},className:`group/ann relative px-3 py-2.5 transition-colors duration-150 ${U===y.id?"bg-highlight-selected":"odd:bg-bg-elevated-half hover:bg-bg-input"}`,onMouseEnter:()=>m(y.id),onMouseLeave:()=>g(y.id),onClick:()=>{if(y.id===U)W(null);else if(W(y.id),y.filePath)T({type:"file",path:y.filePath}),setTimeout(()=>{let I=q0(y);if(I)I.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:y.snippet.length>80?y.snippet.slice(0,80)+"...":y.snippet},void 0,!1,void 0,this),S("div",{onClick:(I)=>I.stopPropagation(),children:S(L0,{note:y.note,onNoteChange:(I)=>q(y.id,I),images:y.images||[],onAddImage:(I)=>G(y.id,I),onRemoveImage:(I)=>_(y.id,I),sessionId:F,autoResize:!0,minHeight:20,textareaClassName:"w-full bg-transparent text-[13px] font-body text-text-primary resize-none focus:outline-none leading-relaxed p-0 border-none min-h-[20px]",textareaStyle:{height:"auto",overflow:"hidden"},placeholder:"Add your note...",attachButton:"on-focus"},void 0,!1,void 0,this)},void 0,!1,void 0,this),S("div",{className:"absolute top-1.5 right-1.5 opacity-0 group-hover/ann:opacity-100 transition-opacity duration-100 flex items-center gap-0.5",children:[S("button",{onClick:(I)=>{I.stopPropagation(),_5(y,T)},className:"w-5 h-5 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-input transition-colors",title:"Scroll to annotation",children:S("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[S("circle",{cx:"12",cy:"12",r:"3"},void 0,!1,void 0,this),S("path",{d:"M12 2v4M12 18v4M2 12h4M18 12h4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),S("button",{onClick:(I)=>{I.stopPropagation(),X(y.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,!0,void 0,this)]},y.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",Q.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:Q.length},void 0,!1,void 0,this),S("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${Y?"bg-accent-green":"bg-accent-amber"}`,title:Y?"Agent connected":"Agent disconnected"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Z]},void 0,!0,void 0,this),S("div",{ref:M,className:"flex-1 overflow-y-auto",children:[Q.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),j.length>0&&S(C0,{children:[(k.length>0||B.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),j.map(x)]},void 0,!0,void 0,this),k.length>0&&(j.length>0||B.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),k.map(x),Object.entries(w).map(([y,I])=>S("div",{children:[S("button",{onClick:()=>T({type:"file",path:y}),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:y,children:[S(P1,{name:y.split("/").pop()||y,type:"file"},void 0,!1,void 0,this),S("span",{className:"truncate",children:y},void 0,!1,void 0,this)]},void 0,!0,void 0,this),I.map(x)]},y,!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:z,onChange:(y)=>H(y.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:(y)=>$0(y.target,40),ref:(y)=>{if(y)$0(y,40)}},void 0,!1,void 0,this)},void 0,!1,void 0,this),u&&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:u},void 0,!1,void 0,this),S("button",{onClick:()=>{l(null);let y=Z0(Q,z,N,K);$(y)},className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body whitespace-nowrap underline",children:"Submit anyway"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),S("div",{className:"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 y=A0(N,K);if(y.length>0){l(`Please answer: ${y.join(", ")}`);return}l(null);let I=Z0(Q,z,N,K);$(I)},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 L$,useState as Y2,useContext as Q2,useMemo as y$}from"react";import{SessionContext as M$}from"#canvas/runtime";import{jsxDEV as r,Fragment as U5}from"react/jsx-dev-runtime";function Z2({embedded:J}={}){let $=Q2(M$),{annotations:Y,addAnnotation:Z}=$1(),{setActiveView:Q}=Q2(F1),[q,X]=Y2(!1),[G,_]=Y2({}),{annCountMap:z,annotatedFiles:H}=y$(()=>{let L=new Map;for(let j of Y)if(j.filePath&&j.filePath!==_1)L.set(j.filePath,(L.get(j.filePath)||0)+1);return{annCountMap:L,annotatedFiles:[...L.keys()]}},[Y]),U=async(L)=>{let k=await(await fetch(`/api/tree?session=${$}&path=${encodeURIComponent(L)}`)).json();if(k.entries)_((B)=>({...B,[L]:{entries:k.entries,expanded:!0,loaded:!0}}))};L$(()=>{if(!q&&!G[""])U("")},[q]);let W=(L)=>{if(G[L]?.loaded)_((j)=>({...j,[L]:{...j[L],expanded:!j[L].expanded}}));else U(L)},N=(L)=>{Q({type:"file",path:L})},K=async(L)=>{let k=await(await fetch(`/api/file?session=${$}&path=${encodeURIComponent(L)}`)).json();if(!k.error){let B=k.content.split(`
|
|
70
70
|
`).slice(0,3).join(`
|
|
71
|
-
`)+(
|
|
71
|
+
`)+(k.content.split(`
|
|
72
72
|
`).length>3?`
|
|
73
|
-
...`:"");Z(
|
|
74
|
-
`);if(!
|
|
75
|
-
`)}catch{return null}},[X,J]);if(H)return S1("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 S1("div",{className:"p-8 text-accent-red font-body text-[13px]",children:W},void 0,!1,void 0,this);if(!X)return null;let
|
|
76
|
-
`);
|
|
73
|
+
...`:"");Z(B,"Include this file for context",L)}},F=async(L)=>{let j=[];if(G[L]?.loaded)j=G[L].entries;else{let B=await(await fetch(`/api/tree?session=${$}&path=${encodeURIComponent(L)}`)).json();if(B.entries)j=B.entries}await Promise.all(j.filter((k)=>k.type==="file").map((k)=>K(L?`${L}/${k.name}`:k.name)))},T=(L)=>z.get(L)||0,M=(L,j=0)=>{let k=G[L];if(!k?.expanded)return null;return k.entries.map((B)=>{let w=L?`${L}/${B.name}`:B.name,m=T(w);return r("div",{children:[r("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+j*16}px`,paddingRight:"8px"},children:B.type==="dir"?r(U5,{children:[r("span",{onClick:()=>W(w),className:"flex items-center gap-1.5 flex-1 text-text-secondary hover:text-text-primary cursor-pointer truncate",children:[r(P1,{name:B.name,type:"dir",expanded:G[w]?.expanded},void 0,!1,void 0,this),r("span",{className:"truncate",children:B.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("button",{onClick:(g)=>{g.stopPropagation(),F(w)},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):r(U5,{children:[r("span",{onClick:()=>N(w),className:`flex-1 truncate cursor-pointer flex items-center gap-1.5 ${m>0?"text-text-primary":"text-text-secondary hover:text-text-primary"}`,children:[r(P1,{name:B.name,type:"file"},void 0,!1,void 0,this),r("span",{className:"truncate",children:B.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("div",{className:"flex items-center gap-1 flex-shrink-0 ml-1",children:[m>0&&r("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:m},void 0,!1,void 0,this),r("button",{onClick:(g)=>{g.stopPropagation(),K(w)},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),B.type==="dir"&&M(w,j+1)]},w,!0,void 0,this)})};if(J)return r(U5,{children:[r("div",{className:"flex items-center justify-between px-4 pt-3 pb-2 flex-shrink-0",children:r("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),r("div",{className:"flex-1 overflow-y-auto",children:M("")},void 0,!1,void 0,this),H.length>0&&r("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:[r("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body mb-1.5",children:"Referenced"},void 0,!1,void 0,this),H.map((L)=>r("div",{onClick:()=>N(L),className:"flex items-center justify-between text-[12px] font-body text-text-secondary hover:text-text-primary cursor-pointer py-0.5",children:[r("span",{className:"truncate",children:L.split("/").pop()},void 0,!1,void 0,this),r("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(L)},void 0,!1,void 0,this)]},L,!0,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);if(q)return r("div",{className:"hidden lg:flex w-8 border-r border-border-subtle bg-bg-surface flex-col items-center flex-shrink-0",children:r("button",{onClick:()=>X(!1),className:"mt-3 p-1 text-text-tertiary hover:text-text-secondary transition-colors",children:r("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:r("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 r("div",{className:"hidden lg:flex w-60 border-r border-border-subtle bg-bg-surface flex-col flex-shrink-0 overflow-hidden",children:[r("div",{className:"flex items-center justify-between px-4 pt-4 pb-3 flex-shrink-0",children:[r("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:"Files"},void 0,!1,void 0,this),r("button",{onClick:()=>X(!0),className:"text-text-tertiary hover:text-text-secondary transition-colors p-0.5",children:r("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:r("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),r("div",{className:"flex-1 overflow-y-auto",children:M("")},void 0,!1,void 0,this),H.length>0&&r("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:[r("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body mb-1.5",children:"Referenced"},void 0,!1,void 0,this),H.map((L)=>r("div",{onClick:()=>N(L),className:"flex items-center justify-between text-[12px] font-body text-text-secondary hover:text-text-primary cursor-pointer py-0.5",children:[r("span",{className:"truncate",children:L.split("/").pop()},void 0,!1,void 0,this),r("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(L)},void 0,!1,void 0,this)]},L,!0,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}import{useEffect as X2,useState as l1,useContext as B$,useCallback as P$,useRef as k0,useMemo as q2}from"react";import{SessionContext as S$}from"#canvas/runtime";var R0={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 S1}from"react/jsx-dev-runtime";function _2(J){let $=J instanceof HTMLElement?J:J.parentElement;while($){if($.hasAttribute("data-line-num"))return $;$=$.parentElement}return null}function b$(J){let $=J.toString().trim(),Y=_2(J.startContainer),Z=_2(J.endContainer),Q=Y?parseInt(Y.getAttribute("data-line-num"),10):void 0,q=Z?parseInt(Z.getAttribute("data-line-num"),10):void 0,X="",G="";if($.length<30&&Y&&Y===Z){let _=Y.querySelector("code");if(_){let z=_.textContent||"",H=z.indexOf($);if(H>=0)X=z.slice(0,H).trimStart(),G=z.slice(H+$.length).trimEnd()}}return{before:X,after:G,hierarchy:[],lineStart:Q,lineEnd:q}}function z2({path:J}){let $=B$(S$),{annotations:Y,addAnnotationWithId:Z,activeAnnotationId:Q,setActiveAnnotationId:q}=$1(),[X,G]=l1(null),[_,z]=l1("text"),[H,U]=l1(!0),[W,N]=l1(null),K=k0(null),[F,T]=l1(null),[M,L]=l1(null),j=k0(null),k=k0(null),B=k0([]),w=Y.filter((y)=>y.filePath===J),m=K.current?.closest("#plan-scroll-container"),{popovers:g,openCreatePopover:A}=g1({containerRef:K,restoreKey:`${X}:${J}`,restoreAnnotations:w,extractContext:b$,filePath:J,scrollContainer:m});X2(()=>{U(!0),N(null),fetch(`/api/file?session=${$}&path=${encodeURIComponent(J)}`).then((y)=>y.json()).then((y)=>{if(y.error)N(y.error),U(!1);else G(y.content),z(y.language||"text"),U(!1)}).catch(()=>{N("Failed to fetch file"),U(!1)})},[$,J]);let C=P$((y,I)=>{y.preventDefault(),j.current=I,k.current=I,T(I),L(I)},[]);X2(()=>{let y=(d)=>{if(j.current===null)return;let R=d.target.closest("[data-line-num]");if(R){let V=parseInt(R.getAttribute("data-line-num"),10);k.current=V,L(V)}},I=()=>{let d=j.current;if(d===null)return;j.current=null;let R=k.current??d,V=Math.min(d,R),P=Math.max(d,R),h=B.current.slice(V-1,P).join(`
|
|
74
|
+
`);if(!h.trim()){T(null),L(null);return}let D=`__pending_${Date.now()}`,a={before:"",after:"",hierarchy:[],lineStart:V,lineEnd:P};if(K.current){let b=K.current.querySelectorAll("[data-line-num]"),E=b[V-1],s=b[P-1];if(E&&s){let a1=E.querySelector("code"),o1=s.querySelector("code");if(a1&&o1)try{let C1=document.createRange();C1.setStartBefore(a1.firstChild||a1),C1.setEndAfter(o1.lastChild||o1),m1(C1,D)}catch{}}let Z1=b[P-1];if(Z1)A(Z1,D,h,a)}T(null),L(null)};return document.addEventListener("mousemove",y),document.addEventListener("mouseup",I),()=>{document.removeEventListener("mousemove",y),document.removeEventListener("mouseup",I)}},[]);let v=q2(()=>{if(!X)return null;let y=window.hljs;if(!y)return null;let I=J.split(".").pop()||"",d=R0[I];try{return(d?y.highlight(X,{language:d}):y.highlightAuto(X)).value.split(`
|
|
75
|
+
`)}catch{return null}},[X,J]);if(H)return S1("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 S1("div",{className:"p-8 text-accent-red font-body text-[13px]",children:W},void 0,!1,void 0,this);if(!X)return null;let u=X.split(`
|
|
76
|
+
`);B.current=u;let l=q2(()=>{if(F===null)return null;let y=M??F;return{start:Math.min(F,y),end:Math.max(F,y)}},[F,M]),x=()=>{let y=X.split(`
|
|
77
77
|
`).slice(0,3).join(`
|
|
78
|
-
`)+(
|
|
79
|
-
...`:""),
|
|
78
|
+
`)+(u.length>3?`
|
|
79
|
+
...`:""),I=U1();Z(I,y,"",J),q(I)};return S1("div",{children:[S1("pre",{ref:K,className:"text-code font-mono text-text-code bg-bg-base select-text cursor-text py-3 hljs",children:u.map((y,I)=>{let d=I+1,R=l&&d>=l.start&&d<=l.end;return S1("div",{"data-line-num":d,className:`flex px-5 ${R?"bg-accent-blue/10":"hover:bg-bg-elevated-half"}`,children:[S1("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:(V)=>C(V,d),children:d},void 0,!1,void 0,this),v?S1("code",{className:"py-px",dangerouslySetInnerHTML:{__html:v[I]||" "}},void 0,!1,void 0,this):S1("code",{className:"py-px",children:y||" "},void 0,!1,void 0,this)]},I,!0,void 0,this)})},void 0,!1,void 0,this),g]},void 0,!0,void 0,this)}import{useEffect as G2,useState as U2,useRef as w$}from"react";import{jsxDEV as T1}from"react/jsx-dev-runtime";function K2(J,$){if($){let Y=$.replace(/\/+$/,"").split("/");return Y[Y.length-1]||J}return J.length>30?J.slice(0,30)+"...":J}function K5({currentSessionId:J,projectRoot:$}){let[Y,Z]=U2([]),[Q,q]=U2(!1),X=w$(null);G2(()=>{let z=async()=>{try{let W=await(await fetch("/api/sessions")).json();Z((N)=>{let K=JSON.stringify(W);return JSON.stringify(N)===K?N:W})}catch{}};z();let H=setInterval(z,5000);return()=>clearInterval(H)},[]),G2(()=>{if(!Q)return;let z=(H)=>{if(X.current&&!X.current.contains(H.target))q(!1)};return document.addEventListener("mousedown",z),()=>document.removeEventListener("mousedown",z)},[Q]);let G=Y.filter((z)=>z.id!==J),_=K2(J,$);return T1("div",{className:"relative",ref:X,children:[T1("div",{className:"flex items-center gap-1.5 font-body text-body font-medium",children:[T1("a",{href:`/s/${J}`,className:"text-text-primary hover:text-text-secondary transition-colors",children:_},void 0,!1,void 0,this),G.length>0&&T1("button",{onClick:()=>q(!Q),className:"flex items-center justify-center text-text-tertiary hover:text-text-secondary transition-colors",children:T1("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:`transition-transform duration-200 ${Q?"rotate-180":""}`,children:T1("path",{d:"M3 5l3 3 3-3",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Q&&G.length>0&&T1("div",{className:"absolute top-full left-0 mt-2 w-64 bg-bg-elevated border border-border-hover rounded-lg shadow-lg z-50 py-1 overflow-hidden",children:G.map((z)=>T1("a",{href:`/s/${z.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:[T1("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${z.currentRevision>0?"bg-accent-green":"bg-border-hover"}`},void 0,!1,void 0,this),T1("span",{className:"truncate",children:K2(z.id,z.projectRoot)},void 0,!1,void 0,this)]},z.id,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function H2(J){let $=[];return V0(J,$,0),$.join(`
|
|
80
80
|
`).replace(/\n{3,}/g,`
|
|
81
81
|
|
|
82
82
|
`).trim()+`
|
|
83
|
-
`}var b$=new Set(["CODE","SPAN","STRONG","EM","A","B","I","U","SMALL","SUB","SUP","MARK","ABBR"]);function k0(J,$,Y){if(w$(J)){let Z=A$(J);if(Z)$.push(Z,"");return}for(let Z of J.childNodes)if(Z.nodeType===Node.ELEMENT_NODE)I$(Z,$,Y);else if(Z.nodeType===Node.TEXT_NODE){let Q=Z.textContent?.trim();if(Q)$.push(Q,"")}}function w$(J){for(let $ of J.childNodes){if($.nodeType===Node.TEXT_NODE)continue;if($.nodeType===Node.ELEMENT_NODE){let Y=$;if(!b$.has(Y.tagName)||Y.hasAttribute("data-md"))return!1}}return J.childNodes.length>0}function A$(J){let $="";for(let Y of J.childNodes)if(Y.nodeType===Node.TEXT_NODE)$+=Y.textContent||"";else if(Y.nodeType===Node.ELEMENT_NODE){let Z=Y;if(Z.tagName==="CODE")$+="`"+(Z.textContent||"")+"`";else $+=Z.textContent||""}return $.trim()}function I$(J,$,Y){let Z=J.getAttribute("data-md");if(Z)switch(Z){case"section":return C$(J,$,Y);case"item":return j$(J,$);case"codeblock":return R$(J,$);case"callout":return k$(J,$);case"note":return V$(J,$);case"table":return D$(J,$);case"checklist":return m$(J,$);case"diff":return g$(J,$);case"mermaid":return u$(J,$);case"choice":return E$(J,$);case"multichoice":return v$(J,$);case"choice-option":case"multichoice-option":return;case"userinput":return x$(J,$);case"rangeinput":return f$(J,$);case"checklist-item":return;case"filepreview":return h$(J,$);case"priority":return p$(J,$)}if(J.querySelector("button, input, select, textarea"))return;if(J.children.length>0)k0(J,$,Y);else{let Q=J.textContent?.trim();if(Q)$.push(Q,"")}}function C$(J,$,Y){let Z=J.getAttribute("data-md-title")||"Untitled",Q=Y===0?"##":"###";$.push(`${Q} ${Z}`,"");let q=J.querySelector(":scope > div:last-of-type");if(q)k0(q,$,Y+1)}function j$(J,$){let Y=J.getAttribute("data-md-label")||"",Z=J.getAttribute("data-md-status"),Q=J.getAttribute("data-md-badge"),q="-";if(Z==="done")q="- [x]";else if(Z)q="- [ ]";let X=`${q} **${Y}**`;if(Q)X+=` \`${Q}\``;$.push(X);let G=J.querySelector(".text-text-secondary");if(G){let _=[];k0(G,_,0);for(let z of _)$.push(z?` ${z}`:"")}$.push("")}function R$(J,$){let Y=J.getAttribute("data-md-language")||"",Q=J.querySelector("code")?.textContent||"";$.push(`\`\`\`${Y}`,Q,"```","")}function k$(J,$){let Y=J.getAttribute("data-md-type")||"info",Z={info:"Info",warning:"Warning",danger:"Danger",tip:"Tip"},Q=c$(J.querySelector(".text-text-secondary")||J);$.push(`> **${Z[Y]||Y}:** ${Q}`,"")}function V$(J,$){let Y=J.textContent?.trim()||"";$.push(`> *${Y}*`,"")}function D$(J,$){let Y=J.querySelector("table");if(!Y)return;let Z=[];for(let Q of Y.querySelectorAll("thead th"))Z.push(Q.textContent?.trim()||"");if(Z.length===0)return;$.push(`| ${Z.join(" | ")} |`),$.push(`| ${Z.map(()=>"---").join(" | ")} |`);for(let Q of Y.querySelectorAll("tbody tr")){let q=[];for(let X of Q.querySelectorAll("td"))q.push(X.textContent?.trim()||"");$.push(`| ${q.join(" | ")} |`)}$.push("")}function m$(J,$){for(let Y of J.querySelectorAll("li")){let Z=Y.querySelector(".bg-accent-green")!==null,Q=Y.textContent?.trim()||"";$.push(`- [${Z?"x":" "}] ${Q}`)}$.push("")}function g$(J,$){let Y=J.getAttribute("data-md-language")||"";$.push(`\`\`\`diff${Y?` (${Y})`:""}`);for(let Z of J.querySelectorAll("[class*='flex']")){let Q=Z.querySelector(".text-accent-red")?"-":Z.querySelector(".text-accent-green")?"+":" ",q=Z.querySelector("code");if(q)$.push(`${Q} ${q.textContent}`)}$.push("```","")}function u$(J,$){let Y=J.getAttribute("data-md-source")||"";if(Y)$.push("```mermaid",Y,"```","")}function E$(J,$){let Y=J.getAttribute("data-md-label")||"";$.push(`**${Y}:**`);for(let Z of J.querySelectorAll("[data-md='choice-option']")){let Q=Z.getAttribute("data-md-label")||Z.textContent?.trim()||"",q=Z.querySelector(".bg-accent-amber")!==null;$.push(`- ${q?"(x)":"( )"} ${Q}`)}$.push("")}function v$(J,$){let Y=J.getAttribute("data-md-label")||"";$.push(`**${Y}:**`);for(let Z of J.querySelectorAll("[data-md='multichoice-option']")){let Q=Z.getAttribute("data-md-label")||Z.textContent?.trim()||"",q=Z.querySelector(".bg-accent-amber")!==null;$.push(`- [${q?"x":" "}] ${Q}`)}$.push("")}function x$(J,$){let Y=J.getAttribute("data-md-label")||"",Q=J.querySelector("textarea")?.value?.trim()||"";$.push(`**${Y}:** ${Q||"_empty_"}`,"")}function f$(J,$){let Y=J.getAttribute("data-md-label")||"",Z=J.querySelector("input[type='range']"),q=J.querySelector(".font-mono")?.textContent?.trim()||Z?.value||"—";$.push(`**${Y}:** ${q}`,"")}function h$(J,$){let Y=J.getAttribute("data-md-path")||"",Z=J.getAttribute("data-md-lines")||"",q=J.querySelector("code")?.textContent||"",X=Y.split(".").pop()||"",G=j0[X]||"",_=Z?`${Y} (L${Z})`:Y;$.push(_,"",`\`\`\`${G}`,q,"```","")}function p$(J,$){}function c$(J){return J?.textContent?.trim()||""}import P2,{useEffect as w1,useState as Q1,useRef as L1,useCallback as S2,useMemo as g0,useContext as X4}from"react";import{useEffect as d$,useState as r$,useRef as l$,useContext as i$}from"react";import{jsxDEV as X1,Fragment as K2}from"react/jsx-dev-runtime";function a$(J){return J.label||`Round ${J.revision}`}function o$(J){let $=Date.now()-new Date(J).getTime(),Y=Math.floor($/1000);if(Y<60)return"just now";let Z=Math.floor(Y/60);if(Z<60)return`${Z}m ago`;let Q=Math.floor(Z/60);if(Q<24)return`${Q}h ago`;return`${Math.floor(Q/24)}d ago`}function q0({value:J,onChange:$,accent:Y="default",className:Z}){let{currentRevision:Q,revisions:q}=i$(N1),[X,G]=r$(!1),_=l$(null);d$(()=>{if(!X)return;let U=(W)=>{if(_.current&&!_.current.contains(W.target))G(!1)};return document.addEventListener("mousedown",U),()=>document.removeEventListener("mousedown",U)},[X]);let z=q.find((U)=>U.revision===J);return X1("div",{className:"relative",ref:_,children:[X1("button",{onClick:()=>G(!X),className:`flex items-center gap-1.5 text-[12px] font-body font-medium px-2 py-1 rounded-md transition-colors hover:bg-bg-elevated ${{default:"text-text-secondary hover:text-text-primary",red:"text-accent-red",green:"text-accent-green",amber:"text-accent-amber bg-highlight-selected"}[Y]} ${Z||""}`,children:[z?a$(z):`Round ${J}`,X1("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",className:`text-text-tertiary transition-transform duration-200 ${X?"rotate-180":""}`,children:X1("path",{d:"M2.5 4l2.5 2.5L7.5 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),X&&X1("div",{className:"absolute top-full left-0 mt-1 w-64 bg-bg-elevated border border-border-hover rounded-lg shadow-lg z-50 py-1 max-h-80 overflow-y-auto",children:[...q].reverse().map((U)=>X1("button",{onClick:()=>{$(U.revision),G(!1)},className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] font-body transition-colors ${U.revision===J?"bg-bg-surface text-text-primary":"text-text-secondary hover:bg-bg-surface hover:text-text-primary"}`,children:[X1("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${U.revision===Q?"bg-accent-green":U.hasFeedback?"bg-accent-amber":"bg-border-hover"}`},void 0,!1,void 0,this),X1("span",{className:"flex-1 text-left truncate",children:U.label?X1(K2,{children:[U.label," ",X1("span",{className:"text-text-tertiary",children:["#",U.revision]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):X1(K2,{children:["Round ",U.revision]},void 0,!0,void 0,this)},void 0,!1,void 0,this),X1("span",{className:"text-[10px] text-text-tertiary flex-shrink-0 flex items-center gap-1.5",children:[(()=>{let W=U.canvasFiles?.reduce((N,K)=>{if(K.diffStats)N.added+=K.diffStats.added,N.removed+=K.diffStats.removed;return N},{added:0,removed:0});if(W&&(W.added>0||W.removed>0))return X1("span",{className:"font-mono",children:[X1("span",{className:"text-accent-green",children:["+",W.added]},void 0,!0,void 0,this)," ",X1("span",{className:"text-accent-red",children:["-",W.removed]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);return null})(),U.revision===Q?"current":U.hasFeedback?"sent":o$(U.createdAt)]},void 0,!0,void 0,this)]},U.revision,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function b1(J,$){let Y=J.length,Z=$.length;if(Y===0||Z===0)return[];let Q=Array.from({length:Y+1},()=>Array(Z+1).fill(0));for(let _=1;_<=Y;_++)for(let z=1;z<=Z;z++)Q[_][z]=J[_-1]===$[z-1]?Q[_-1][z-1]+1:Math.max(Q[_-1][z],Q[_][z-1]);let q=[],X=Y,G=Z;while(X>0&&G>0)if(J[X-1]===$[G-1])q.unshift(J[X-1]),X--,G--;else if(Q[X-1][G]>Q[X][G-1])X--;else G--;return q}function H2(J){let $=[],Y=[],Z=document.createTreeWalker(J,NodeFilter.SHOW_TEXT,{acceptNode(q){let X=q.parentElement;if(!X)return NodeFilter.FILTER_REJECT;if(X.closest("svg, .select-none, [data-no-diff]"))return NodeFilter.FILTER_REJECT;return NodeFilter.FILTER_ACCEPT}}),Q;while(Q=Z.nextNode()){let X=(Q.nodeValue||"").match(/\S+|\s+/g);if(!X)continue;let G=0;for(let _ of X)$.push(_),Y.push({text:_,node:Q,offset:G}),G+=_.length}return{words:$,map:Y}}function K5(J,$){if(J.length>5000||$.length>5000)return s$(J,$);return T2(J,$)}function T2(J,$){let Y=V0(J,$),Z=[],Q=[],q=0,X=0,G=0;while(q<J.length||X<$.length)if(G<Y.length&&q<J.length&&X<$.length&&J[q]===Y[G]&&$[X]===Y[G])Z.push({type:"same",index:q}),Q.push({type:"same",index:X}),q++,X++,G++;else if(q<J.length&&(G>=Y.length||J[q]!==Y[G]))Z.push({type:"removed",index:q}),q++;else if(X<$.length)Q.push({type:"added",index:X}),X++;return{oldOps:Z,newOps:Q}}function V0(J,$){let Y=J.length,Z=$.length;if(Y===0||Z===0)return[];if(Y===1)return $.includes(J[0])?[J[0]]:[];if(Z===1)return J.includes($[0])?[$[0]]:[];if(Y*Z<=1e6)return b1(J,$);let Q=Math.floor(Y/2),q=J.slice(0,Q),X=J.slice(Q),G=W2(q,$),_=W2([...X].reverse(),[...$].reverse()),z=0,H=0;for(let N=0;N<=Z;N++){let K=G[N]+_[Z-N];if(K>z)z=K,H=N}let U=$.slice(0,H),W=$.slice(H);return[...V0(q,U),...V0(X,W)]}function W2(J,$){let Y=$.length,Z=Array(Y+1).fill(0),Q=Array(Y+1).fill(0);for(let q=0;q<J.length;q++){for(let X=1;X<=Y;X++)Q[X]=J[q]===$[X-1]?Z[X-1]+1:Math.max(Z[X],Q[X-1]);[Z,Q]=[Q,Z],Q.fill(0)}return Z}function s$(J,$){let Z=(K)=>{let T=[];for(let O=0;O<K.length;O+=200){let S=Math.min(O+200,K.length);T.push({start:O,end:S,text:K.slice(O,S).join("")})}return T},Q=Z(J),q=Z($),X=Q.map((K)=>K.text),G=q.map((K)=>K.text),_=V0(X,G),z=[],H=[],U=0,W=0,N=0;while(U<Q.length||W<q.length)if(N<_.length&&U<Q.length&&W<q.length&&X[U]===_[N]&&G[W]===_[N]){for(let K=Q[U].start;K<Q[U].end;K++)z.push({type:"same",index:K});for(let K=q[W].start;K<q[W].end;K++)H.push({type:"same",index:K});U++,W++,N++}else if(U<Q.length&&(N>=_.length||X[U]!==_[N]))if(W<q.length&&(N>=_.length||G[W]!==_[N])){let K=T2(J.slice(Q[U].start,Q[U].end),$.slice(q[W].start,q[W].end));for(let T of K.oldOps)z.push({type:T.type,index:T.index+Q[U].start});for(let T of K.newOps)H.push({type:T.type,index:T.index+q[W].start});U++,W++}else{for(let K=Q[U].start;K<Q[U].end;K++)z.push({type:"removed",index:K});U++}else if(W<q.length){for(let K=q[W].start;K<q[W].end;K++)H.push({type:"added",index:K});W++}return{oldOps:z,newOps:H}}function N2(J,$,Y){let Z=new Map;for(let Q of J){if(Q.type==="same")continue;let q=$[Q.index];if(!q||!q.node.parentNode)continue;let X=Z.get(q.node);if(!X)X=[],Z.set(q.node,X);X.push({offset:q.offset,length:q.text.length})}for(let[Q,q]of Z){if(!Q.parentNode)continue;let X=Q.nodeValue||"";q.sort((U,W)=>U.offset-W.offset);let G=[];for(let U of q){let W=G[G.length-1];if(W&&U.offset<=W.offset+W.length)W.length=Math.max(W.length,U.offset+U.length-W.offset);else G.push({...U})}let _=Q.parentNode,z=document.createDocumentFragment(),H=0;for(let U of G){if(U.offset>H)z.appendChild(document.createTextNode(X.slice(H,U.offset)));let W=document.createElement("span");W.className=Y,W.textContent=X.slice(U.offset,U.offset+U.length),z.appendChild(W),H=U.offset+U.length}if(H<X.length)z.appendChild(document.createTextNode(X.slice(H)));_.replaceChild(z,Q)}}function D0(J,$){let Y=t$(J,$),Z=H2(J),Q=H2($),{oldOps:q,newOps:X}=K5(Z.words,Q.words),G=q.some((_)=>_.type==="removed")||X.some((_)=>_.type==="added");return N2(q,Z.map,"diff-removed"),N2(X,Q.map,"diff-added"),G||Y}function t$(J,$){let Y=Array.from(J.querySelectorAll('[data-md="mermaid"]')),Z=Array.from($.querySelectorAll('[data-md="mermaid"]')),Q=!1,q=Math.max(Y.length,Z.length);for(let X=0;X<q;X++){let G=Y[X],_=Z[X];if(!G&&_){_.classList.add("diff-block-added"),_.style.position="relative",Q=!0;continue}if(G&&!_){G.classList.add("diff-block-removed"),G.style.position="relative",Q=!0;continue}if(!G||!_)continue;let z=(G.getAttribute("data-md-source")||"").trim(),H=(_.getAttribute("data-md-source")||"").trim();if(z===H)continue;Q=!0,G.style.borderLeft="3px solid var(--color-accent-red)",G.style.paddingLeft="8px",_.style.borderLeft="3px solid var(--color-accent-green)",_.style.paddingLeft="8px";let U=z.split(`
|
|
83
|
+
`}var A$=new Set(["CODE","SPAN","STRONG","EM","A","B","I","U","SMALL","SUB","SUP","MARK","ABBR"]);function V0(J,$,Y){if(I$(J)){let Z=C$(J);if(Z)$.push(Z,"");return}for(let Z of J.childNodes)if(Z.nodeType===Node.ELEMENT_NODE)j$(Z,$,Y);else if(Z.nodeType===Node.TEXT_NODE){let Q=Z.textContent?.trim();if(Q)$.push(Q,"")}}function I$(J){for(let $ of J.childNodes){if($.nodeType===Node.TEXT_NODE)continue;if($.nodeType===Node.ELEMENT_NODE){let Y=$;if(!A$.has(Y.tagName)||Y.hasAttribute("data-md"))return!1}}return J.childNodes.length>0}function C$(J){let $="";for(let Y of J.childNodes)if(Y.nodeType===Node.TEXT_NODE)$+=Y.textContent||"";else if(Y.nodeType===Node.ELEMENT_NODE){let Z=Y;if(Z.tagName==="CODE")$+="`"+(Z.textContent||"")+"`";else $+=Z.textContent||""}return $.trim()}function j$(J,$,Y){let Z=J.getAttribute("data-md");if(Z)switch(Z){case"section":return R$(J,$,Y);case"item":return k$(J,$);case"codeblock":return V$(J,$);case"callout":return D$(J,$);case"note":return m$(J,$);case"table":return u$(J,$);case"checklist":return g$(J,$);case"diff":return E$(J,$);case"mermaid":return v$(J,$);case"choice":return x$(J,$);case"multichoice":return f$(J,$);case"choice-option":case"multichoice-option":return;case"userinput":return h$(J,$);case"rangeinput":return p$(J,$);case"checklist-item":return;case"filepreview":return c$(J,$);case"priority":return d$(J,$)}if(J.querySelector("button, input, select, textarea"))return;if(J.children.length>0)V0(J,$,Y);else{let Q=J.textContent?.trim();if(Q)$.push(Q,"")}}function R$(J,$,Y){let Z=J.getAttribute("data-md-title")||"Untitled",Q=Y===0?"##":"###";$.push(`${Q} ${Z}`,"");let q=J.querySelector(":scope > div:last-of-type");if(q)V0(q,$,Y+1)}function k$(J,$){let Y=J.getAttribute("data-md-label")||"",Z=J.getAttribute("data-md-status"),Q=J.getAttribute("data-md-badge"),q="-";if(Z==="done")q="- [x]";else if(Z)q="- [ ]";let X=`${q} **${Y}**`;if(Q)X+=` \`${Q}\``;$.push(X);let G=J.querySelector(".text-text-secondary");if(G){let _=[];V0(G,_,0);for(let z of _)$.push(z?` ${z}`:"")}$.push("")}function V$(J,$){let Y=J.getAttribute("data-md-language")||"",Q=J.querySelector("code")?.textContent||"";$.push(`\`\`\`${Y}`,Q,"```","")}function D$(J,$){let Y=J.getAttribute("data-md-type")||"info",Z={info:"Info",warning:"Warning",danger:"Danger",tip:"Tip"},Q=r$(J.querySelector(".text-text-secondary")||J);$.push(`> **${Z[Y]||Y}:** ${Q}`,"")}function m$(J,$){let Y=J.textContent?.trim()||"";$.push(`> *${Y}*`,"")}function u$(J,$){let Y=J.querySelector("table");if(!Y)return;let Z=[];for(let Q of Y.querySelectorAll("thead th"))Z.push(Q.textContent?.trim()||"");if(Z.length===0)return;$.push(`| ${Z.join(" | ")} |`),$.push(`| ${Z.map(()=>"---").join(" | ")} |`);for(let Q of Y.querySelectorAll("tbody tr")){let q=[];for(let X of Q.querySelectorAll("td"))q.push(X.textContent?.trim()||"");$.push(`| ${q.join(" | ")} |`)}$.push("")}function g$(J,$){for(let Y of J.querySelectorAll("li")){let Z=Y.querySelector(".bg-accent-green")!==null,Q=Y.textContent?.trim()||"";$.push(`- [${Z?"x":" "}] ${Q}`)}$.push("")}function E$(J,$){let Y=J.getAttribute("data-md-language")||"";$.push(`\`\`\`diff${Y?` (${Y})`:""}`);for(let Z of J.querySelectorAll("[class*='flex']")){let Q=Z.querySelector(".text-accent-red")?"-":Z.querySelector(".text-accent-green")?"+":" ",q=Z.querySelector("code");if(q)$.push(`${Q} ${q.textContent}`)}$.push("```","")}function v$(J,$){let Y=J.getAttribute("data-md-source")||"";if(Y)$.push("```mermaid",Y,"```","")}function x$(J,$){let Y=J.getAttribute("data-md-label")||"";$.push(`**${Y}:**`);for(let Z of J.querySelectorAll("[data-md='choice-option']")){let Q=Z.getAttribute("data-md-label")||Z.textContent?.trim()||"",q=Z.querySelector(".bg-accent-amber")!==null;$.push(`- ${q?"(x)":"( )"} ${Q}`)}$.push("")}function f$(J,$){let Y=J.getAttribute("data-md-label")||"";$.push(`**${Y}:**`);for(let Z of J.querySelectorAll("[data-md='multichoice-option']")){let Q=Z.getAttribute("data-md-label")||Z.textContent?.trim()||"",q=Z.querySelector(".bg-accent-amber")!==null;$.push(`- [${q?"x":" "}] ${Q}`)}$.push("")}function h$(J,$){let Y=J.getAttribute("data-md-label")||"",Q=J.querySelector("textarea")?.value?.trim()||"";$.push(`**${Y}:** ${Q||"_empty_"}`,"")}function p$(J,$){let Y=J.getAttribute("data-md-label")||"",Z=J.querySelector("input[type='range']"),q=J.querySelector(".font-mono")?.textContent?.trim()||Z?.value||"—";$.push(`**${Y}:** ${q}`,"")}function c$(J,$){let Y=J.getAttribute("data-md-path")||"",Z=J.getAttribute("data-md-lines")||"",q=J.querySelector("code")?.textContent||"",X=Y.split(".").pop()||"",G=R0[X]||"",_=Z?`${Y} (L${Z})`:Y;$.push(_,"",`\`\`\`${G}`,q,"```","")}function d$(J,$){}function r$(J){return J?.textContent?.trim()||""}import b2,{useEffect as w1,useState as Q1,useRef as L1,useCallback as w2,useMemo as g0,useContext as _4}from"react";import{useEffect as l$,useState as i$,useRef as a$,useContext as o$}from"react";import{jsxDEV as q1,Fragment as W2}from"react/jsx-dev-runtime";function s$(J){return J.label||`Round ${J.revision}`}function t$(J){let $=Date.now()-new Date(J).getTime(),Y=Math.floor($/1000);if(Y<60)return"just now";let Z=Math.floor(Y/60);if(Z<60)return`${Z}m ago`;let Q=Math.floor(Z/60);if(Q<24)return`${Q}h ago`;return`${Math.floor(Q/24)}d ago`}function _0({value:J,onChange:$,accent:Y="default",className:Z}){let{currentRevision:Q,revisions:q}=o$(N1),[X,G]=i$(!1),_=a$(null);l$(()=>{if(!X)return;let U=(W)=>{if(_.current&&!_.current.contains(W.target))G(!1)};return document.addEventListener("mousedown",U),()=>document.removeEventListener("mousedown",U)},[X]);let z=q.find((U)=>U.revision===J);return q1("div",{className:"relative",ref:_,children:[q1("button",{onClick:()=>G(!X),className:`flex items-center gap-1.5 text-[12px] font-body font-medium px-2 py-1 rounded-md transition-colors hover:bg-bg-elevated ${{default:"text-text-secondary hover:text-text-primary",red:"text-accent-red",green:"text-accent-green",amber:"text-accent-amber bg-highlight-selected"}[Y]} ${Z||""}`,children:[z?s$(z):`Round ${J}`,q1("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",className:`text-text-tertiary transition-transform duration-200 ${X?"rotate-180":""}`,children:q1("path",{d:"M2.5 4l2.5 2.5L7.5 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),X&&q1("div",{className:"absolute top-full left-0 mt-1 w-64 bg-bg-elevated border border-border-hover rounded-lg shadow-lg z-50 py-1 max-h-80 overflow-y-auto",children:[...q].reverse().map((U)=>q1("button",{onClick:()=>{$(U.revision),G(!1)},className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] font-body transition-colors ${U.revision===J?"bg-bg-surface text-text-primary":"text-text-secondary hover:bg-bg-surface hover:text-text-primary"}`,children:[q1("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${U.revision===Q?"bg-accent-green":U.hasFeedback?"bg-accent-amber":"bg-border-hover"}`},void 0,!1,void 0,this),q1("span",{className:"flex-1 text-left truncate",children:U.label?q1(W2,{children:[U.label," ",q1("span",{className:"text-text-tertiary",children:["#",U.revision]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):q1(W2,{children:["Round ",U.revision]},void 0,!0,void 0,this)},void 0,!1,void 0,this),q1("span",{className:"text-[10px] text-text-tertiary flex-shrink-0 flex items-center gap-1.5",children:[(()=>{let W=U.canvasFiles?.reduce((N,K)=>{if(K.diffStats)N.added+=K.diffStats.added,N.removed+=K.diffStats.removed;return N},{added:0,removed:0});if(W&&(W.added>0||W.removed>0))return q1("span",{className:"font-mono",children:[q1("span",{className:"text-accent-green",children:["+",W.added]},void 0,!0,void 0,this)," ",q1("span",{className:"text-accent-red",children:["-",W.removed]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);return null})(),U.revision===Q?"current":U.hasFeedback?"sent":t$(U.createdAt)]},void 0,!0,void 0,this)]},U.revision,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function b1(J,$){let Y=J.length,Z=$.length;if(Y===0||Z===0)return[];let Q=Array.from({length:Y+1},()=>Array(Z+1).fill(0));for(let _=1;_<=Y;_++)for(let z=1;z<=Z;z++)Q[_][z]=J[_-1]===$[z-1]?Q[_-1][z-1]+1:Math.max(Q[_-1][z],Q[_][z-1]);let q=[],X=Y,G=Z;while(X>0&&G>0)if(J[X-1]===$[G-1])q.unshift(J[X-1]),X--,G--;else if(Q[X-1][G]>Q[X][G-1])X--;else G--;return q}function N2(J){let $=[],Y=[],Z=document.createTreeWalker(J,NodeFilter.SHOW_TEXT,{acceptNode(q){let X=q.parentElement;if(!X)return NodeFilter.FILTER_REJECT;if(X.closest("svg, .select-none, [data-no-diff]"))return NodeFilter.FILTER_REJECT;return NodeFilter.FILTER_ACCEPT}}),Q;while(Q=Z.nextNode()){let X=(Q.nodeValue||"").match(/\S+|\s+/g);if(!X)continue;let G=0;for(let _ of X)$.push(_),Y.push({text:_,node:Q,offset:G}),G+=_.length}return{words:$,map:Y}}function H5(J,$){if(J.length>5000||$.length>5000)return n$(J,$);return F2(J,$)}function F2(J,$){let Y=D0(J,$),Z=[],Q=[],q=0,X=0,G=0;while(q<J.length||X<$.length)if(G<Y.length&&q<J.length&&X<$.length&&J[q]===Y[G]&&$[X]===Y[G])Z.push({type:"same",index:q}),Q.push({type:"same",index:X}),q++,X++,G++;else if(q<J.length&&(G>=Y.length||J[q]!==Y[G]))Z.push({type:"removed",index:q}),q++;else if(X<$.length)Q.push({type:"added",index:X}),X++;return{oldOps:Z,newOps:Q}}function D0(J,$){let Y=J.length,Z=$.length;if(Y===0||Z===0)return[];if(Y===1)return $.includes(J[0])?[J[0]]:[];if(Z===1)return J.includes($[0])?[$[0]]:[];if(Y*Z<=1e6)return b1(J,$);let Q=Math.floor(Y/2),q=J.slice(0,Q),X=J.slice(Q),G=T2(q,$),_=T2([...X].reverse(),[...$].reverse()),z=0,H=0;for(let N=0;N<=Z;N++){let K=G[N]+_[Z-N];if(K>z)z=K,H=N}let U=$.slice(0,H),W=$.slice(H);return[...D0(q,U),...D0(X,W)]}function T2(J,$){let Y=$.length,Z=Array(Y+1).fill(0),Q=Array(Y+1).fill(0);for(let q=0;q<J.length;q++){for(let X=1;X<=Y;X++)Q[X]=J[q]===$[X-1]?Z[X-1]+1:Math.max(Z[X],Q[X-1]);[Z,Q]=[Q,Z],Q.fill(0)}return Z}function n$(J,$){let Z=(K)=>{let F=[];for(let T=0;T<K.length;T+=200){let M=Math.min(T+200,K.length);F.push({start:T,end:M,text:K.slice(T,M).join("")})}return F},Q=Z(J),q=Z($),X=Q.map((K)=>K.text),G=q.map((K)=>K.text),_=D0(X,G),z=[],H=[],U=0,W=0,N=0;while(U<Q.length||W<q.length)if(N<_.length&&U<Q.length&&W<q.length&&X[U]===_[N]&&G[W]===_[N]){for(let K=Q[U].start;K<Q[U].end;K++)z.push({type:"same",index:K});for(let K=q[W].start;K<q[W].end;K++)H.push({type:"same",index:K});U++,W++,N++}else if(U<Q.length&&(N>=_.length||X[U]!==_[N]))if(W<q.length&&(N>=_.length||G[W]!==_[N])){let K=F2(J.slice(Q[U].start,Q[U].end),$.slice(q[W].start,q[W].end));for(let F of K.oldOps)z.push({type:F.type,index:F.index+Q[U].start});for(let F of K.newOps)H.push({type:F.type,index:F.index+q[W].start});U++,W++}else{for(let K=Q[U].start;K<Q[U].end;K++)z.push({type:"removed",index:K});U++}else if(W<q.length){for(let K=q[W].start;K<q[W].end;K++)H.push({type:"added",index:K});W++}return{oldOps:z,newOps:H}}function O2(J,$,Y){let Z=new Map;for(let Q of J){if(Q.type==="same")continue;let q=$[Q.index];if(!q||!q.node.parentNode)continue;let X=Z.get(q.node);if(!X)X=[],Z.set(q.node,X);X.push({offset:q.offset,length:q.text.length})}for(let[Q,q]of Z){if(!Q.parentNode)continue;let X=Q.nodeValue||"";q.sort((U,W)=>U.offset-W.offset);let G=[];for(let U of q){let W=G[G.length-1];if(W&&U.offset<=W.offset+W.length)W.length=Math.max(W.length,U.offset+U.length-W.offset);else G.push({...U})}let _=Q.parentNode,z=document.createDocumentFragment(),H=0;for(let U of G){if(U.offset>H)z.appendChild(document.createTextNode(X.slice(H,U.offset)));let W=document.createElement("span");W.className=Y,W.textContent=X.slice(U.offset,U.offset+U.length),z.appendChild(W),H=U.offset+U.length}if(H<X.length)z.appendChild(document.createTextNode(X.slice(H)));_.replaceChild(z,Q)}}function m0(J,$){let Y=e$(J,$),Z=N2(J),Q=N2($),{oldOps:q,newOps:X}=H5(Z.words,Q.words),G=q.some((_)=>_.type==="removed")||X.some((_)=>_.type==="added");return O2(q,Z.map,"diff-removed"),O2(X,Q.map,"diff-added"),G||Y}function e$(J,$){let Y=Array.from(J.querySelectorAll('[data-md="mermaid"]')),Z=Array.from($.querySelectorAll('[data-md="mermaid"]')),Q=!1,q=Math.max(Y.length,Z.length);for(let X=0;X<q;X++){let G=Y[X],_=Z[X];if(!G&&_){_.classList.add("diff-block-added"),_.style.position="relative",Q=!0;continue}if(G&&!_){G.classList.add("diff-block-removed"),G.style.position="relative",Q=!0;continue}if(!G||!_)continue;let z=(G.getAttribute("data-md-source")||"").trim(),H=(_.getAttribute("data-md-source")||"").trim();if(z===H)continue;Q=!0,G.style.borderLeft="3px solid var(--color-accent-red)",G.style.paddingLeft="8px",_.style.borderLeft="3px solid var(--color-accent-green)",_.style.paddingLeft="8px";let U=z.split(`
|
|
84
84
|
`),W=H.split(`
|
|
85
|
-
`),N=b1(U,W),K=(T,O,S)=>{let L=document.createElement("div");L.className="mt-2 bg-bg-code rounded-md overflow-hidden text-tiny font-mono",L.setAttribute("data-no-diff","true");let j=0,V=0;while(V<T.length){let M=document.createElement("div");if(M.className="px-3 py-0.5 whitespace-pre-wrap",j<O.length&&T[V]===O[j])M.textContent=" "+T[V],V++,j++;else M.classList.add(S==="old"?"diff-removed":"diff-added"),M.textContent=(S==="old"?"- ":"+ ")+T[V],V++;L.appendChild(M)}return L};G.appendChild(K(U,N,"old")),_.appendChild(K(W,N,"new"))}return Q}function a1(J){let $=[],Y=J.querySelectorAll(":scope > [data-md]");for(let Z of Y)$.push(_0(Z));if($.length===0){let Z=J.querySelectorAll("[data-md]"),Q=new Set;for(let q of Z){let X=q.parentElement?.closest("[data-md]");if(X&&J.contains(X))continue;if(Q.has(q))continue;Q.add(q),$.push(_0(q))}}return $}function _0(J){let $=J.getAttribute("data-md")||"unknown",Y=n$(J,$),Z=[];if($==="section"){let Q=J.querySelector(":scope > div.mt-6, :scope > div:last-child");if(Q)for(let q of Q.querySelectorAll(":scope > [data-md]"))Z.push(_0(q))}else if($==="table")for(let Q of J.querySelectorAll(":scope table > tbody > tr"))Z.push({key:"tr:"+(Q.textContent||"").slice(0,80),type:"tr",element:Q,children:[]});else if($==="checklist")for(let Q of J.querySelectorAll(":scope > [data-md='checklist-item']"))Z.push(_0(Q));else for(let Q of J.querySelectorAll("[data-md]"))if(Q.parentElement?.closest("[data-md]")===J)Z.push(_0(Q));return{key:Y,type:$,element:J,children:Z}}function n$(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 z0(J,$){let Y=J.map((z)=>z.key),Z=$.map((z)=>z.key),Q=b1(Y,Z),q=[],X=0,G=0,_=0;while(X<J.length||G<$.length)if(_<Q.length&&X<J.length&&G<$.length&&Y[X]===Q[_]&&Z[G]===Q[_]){let z=J[X],H=$[G],U=z.children.length>0||H.children.length>0?z0(z.children,H.children):void 0;q.push({kind:"matched",oldBlock:z,newBlock:H,childMatches:U}),X++,G++,_++}else if(X<J.length&&(_>=Q.length||Y[X]!==Q[_]))q.push({kind:"removed",oldBlock:J[X]}),X++;else if(G<$.length)q.push({kind:"added",newBlock:$[G]}),G++;return q}function m0(J){let $=document.createDocumentFragment(),Y=!1;for(let Z of J)if(Z.kind==="removed")Y=!0,$.appendChild(F2(Z.oldBlock.element));else if(Z.kind==="added")Y=!0,$.appendChild(e$(Z.newBlock.element));else{let Q=Z.newBlock.element.cloneNode(!0),q=Z.newBlock.type;if(q==="mermaid"){if(M2(Z.oldBlock.element,Q))Y=!0}else if(Z.childMatches&&Z.childMatches.length>0&&(q==="table"||q==="checklist")){if(B2(Q,Z.childMatches,q))Y=!0}else if(Z.childMatches&&Z.childMatches.length>0){if(L2(Z.oldBlock,Q,Z.childMatches,q))Y=!0}else if(q==="markdown"){if(y2(Z.oldBlock.element,Q))Y=!0}else if(h1(Z.oldBlock.element,Q,!1))Y=!0;$.appendChild(Q)}return{fragment:$,hasChanges:Y}}function F2(J){let $=J.cloneNode(!0);return $.classList.add("diff-block-removed"),$.style.position="relative",H5($,"Removed","var(--color-accent-red)"),$}function e$(J){let $=J.cloneNode(!0);return $.classList.add("diff-block-added"),$.style.position="relative",H5($,"Added","var(--color-accent-green)"),$}function L2(J,$,Y,Z){let Q=!1,q=$4(J,$),X,G;if(Z==="section"){let _=J.element.querySelector(":scope > div:first-child"),z=$.querySelector(":scope > div:first-child");if(_&&z){if(h1(_,z,!1))Q=!0}X=J.element.querySelector(":scope > div.mt-6, :scope > div:last-child"),G=$.querySelector(":scope > div.mt-6, :scope > div:last-child")}else X=J.element,G=$;if(!X||!G)return Q;for(let _ of Y)if(_.kind==="matched"){let z=q.newMap.get(_.newBlock.element);if(z){if(_.newBlock.type==="mermaid"){if(M2(_.oldBlock.element,z))Q=!0}else if(_.childMatches&&_.childMatches.length>0&&(_.newBlock.type==="table"||_.newBlock.type==="checklist")){if(B2(z,_.childMatches,_.newBlock.type))Q=!0}else if(_.childMatches&&_.childMatches.length>0){if(L2(_.oldBlock,z,_.childMatches,_.newBlock.type))Q=!0}else if(_.newBlock.type==="markdown"){if(y2(_.oldBlock.element,z))Q=!0}else if(h1(_.oldBlock.element,z,!1))Q=!0}}else if(_.kind==="removed"){Q=!0;let z=F2(_.oldBlock.element),H=Y4(Y,_,q.newMap),U=H?Q4(G,H):null;G.insertBefore(z,U)}else if(_.kind==="added"){Q=!0;let z=q.newMap.get(_.newBlock.element);if(z)z.classList.add("diff-block-added"),z.style.position="relative",H5(z,"Added","var(--color-accent-green)")}if(h1(X,G,!0))Q=!0;return Q}function B2(J,$,Y){let Z=Y==="table"?J.querySelector(":scope table > tbody"):J;if(!Z)return!1;let Q=!1;Z.innerHTML="";for(let q of $)if(q.kind==="removed"){Q=!0;let X=q.oldBlock.element.cloneNode(!0);X.classList.add(Y==="table"?"diff-row-removed":"diff-item-removed"),Z.appendChild(X)}else if(q.kind==="added"){Q=!0;let X=q.newBlock.element.cloneNode(!0);X.classList.add(Y==="table"?"diff-row-added":"diff-item-added"),Z.appendChild(X)}else{let X=q.newBlock.element.cloneNode(!0);if(h1(q.oldBlock.element,X,!1))Q=!0;Z.appendChild(X)}return Q}function $4(J,$){let Y=new Map,Z=J.element.querySelectorAll("[data-md]"),Q=$.querySelectorAll("[data-md]");return{newMap:{get(q){return J4($,q)}}}}function J4(J,$){let Y=$.getAttribute("data-md");if(!Y)return null;let Z=$.getAttribute("data-md-label"),Q=$.getAttribute("data-md-title"),q=`[data-md="${Y}"]`;if(Q)q+=`[data-md-title="${CSS.escape(Q)}"]`;else if(Z)q+=`[data-md-label="${CSS.escape(Z)}"]`;let X=J.querySelectorAll(q);if(X.length===1)return X[0];let G=($.textContent||"").slice(0,100),_=null,z=-1;for(let H of X){let U=(H.textContent||"").slice(0,100),W=0;for(let N=0;N<Math.min(G.length,U.length);N++)if(G[N]===U[N])W++;if(W>z)z=W,_=H}return _}function Y4(J,$,Y){let Z=J.indexOf($);for(let Q=Z+1;Q<J.length;Q++){let q=J[Q];if((q.kind==="matched"||q.kind==="added")&&q.newBlock)return Y.get(q.newBlock.element)||null}return null}function Q4(J,$){let Y=$;while(Y&&Y.parentElement!==J)Y=Y.parentElement;return Y}function y2(J,$){let Y=Array.from(J.children),Z=Array.from($.children);if(Y.length===0&&Z.length===0)return h1(J,$,!1);let Q=Y.map((W)=>W.tagName.toLowerCase()),q=Z.map((W)=>W.tagName.toLowerCase()),X=b1(Q,q),G=[],_=0,z=0,H=0;while(_<Y.length||z<Z.length)if(H<X.length&&_<Y.length&&z<Z.length&&Q[_]===X[H]&&q[z]===X[H])G.push({kind:"matched",oldChild:Y[_],newChild:Z[z]}),_++,z++,H++;else if(_<Y.length&&(H>=X.length||Q[_]!==X[H]))G.push({kind:"removed",oldChild:Y[_]}),_++;else if(z<Z.length)G.push({kind:"added",newChild:Z[z]}),z++;let U=!1;while($.firstChild)$.removeChild($.firstChild);for(let W of G)if(W.kind==="matched"){let N=(W.oldChild.textContent||"").match(/\S+/g)||[],K=(W.newChild.textContent||"").match(/\S+/g)||[],T=b1(N,K),O=Math.max(N.length,K.length);if((O>0?1-T.length/O:0)>0.5){U=!0;let L=W.oldChild.cloneNode(!0);L.classList.add("diff-block-removed"),$.appendChild(L),W.newChild.classList.add("diff-block-added"),$.appendChild(W.newChild)}else{if(h1(W.oldChild,W.newChild,!1))U=!0;$.appendChild(W.newChild)}}else if(W.kind==="removed"){U=!0;let N=W.oldChild.cloneNode(!0);N.classList.add("diff-block-removed"),$.appendChild(N)}else U=!0,W.newChild.classList.add("diff-block-added"),$.appendChild(W.newChild);return U}function O2(J,$){let Y=$?new Set(Array.from(J.querySelectorAll("[data-md]"))):new Set,Z=[],Q=[],q=document.createTreeWalker(J,NodeFilter.SHOW_TEXT,{acceptNode(G){let _=G.parentElement;if(!_)return NodeFilter.FILTER_REJECT;if(_.closest("svg, .select-none, [data-no-diff]"))return NodeFilter.FILTER_REJECT;if($){for(let z of Y)if(z.contains(G))return NodeFilter.FILTER_REJECT}return NodeFilter.FILTER_ACCEPT}}),X;while(X=q.nextNode()){let _=(X.nodeValue||"").match(/\S+|\s+/g);if(!_)continue;let z=0;for(let H of _)Z.push(H),Q.push({text:H,node:X,offset:z}),z+=H.length}return{words:Z,map:Q}}function h1(J,$,Y){let Z=O2(J,Y),Q=O2($,Y);if(Z.words.length===0&&Q.words.length===0)return!1;let{oldOps:q,newOps:X}=K5(Z.words,Q.words),G=q.some((O)=>O.type==="removed"),_=X.some((O)=>O.type==="added");if(!G&&!_)return!1;let z=[],H=[];for(let O of q)if(O.type==="same")z.push(O.index);for(let O of X)if(O.type==="same")H.push(O.index);let U=new Map;for(let O=0;O<z.length&&O<H.length;O++)U.set(z[O],H[O]);let W=[];{let O=[],S=-1;for(let L of q)if(L.type==="same"){if(O.length>0)W.push({text:O.join(""),anchorNewIdx:S>=0?U.get(S)??null:null}),O=[];S=L.index}else if(L.type==="removed")O.push(Z.words[L.index]);if(O.length>0)W.push({text:O.join(""),anchorNewIdx:S>=0?U.get(S)??null:null})}let N=new Map,K=new Map;for(let O of X){if(O.type!=="added")continue;let S=Q.map[O.index];if(!S?.node.parentNode)continue;let L=N.get(S.node);if(!L)L=[],N.set(S.node,L);L.push({start:S.offset,end:S.offset+S.text.length})}for(let O of W)if(O.anchorNewIdx===null){if(Q.map.length>0){let S=Q.map[0].node,L=K.get(S);if(!L)L=[],K.set(S,L);L.push({offset:0,text:O.text})}}else{let S=Q.map[O.anchorNewIdx];if(!S)continue;let L=K.get(S.node);if(!L)L=[],K.set(S.node,L);L.push({offset:S.offset+S.text.length,text:O.text})}let T=new Set([...N.keys(),...K.keys()]);for(let O of T)Z4(O,N.get(O)||[],K.get(O)||[]);return!0}function Z4(J,$,Y){if(!J.parentNode)return;let Z=J.nodeValue||"";$.sort((H,U)=>H.start-U.start);let Q=[];for(let H of $){let U=Q[Q.length-1];if(U&&H.start<=U.end)U.end=Math.max(U.end,H.end);else Q.push({...H})}Y.sort((H,U)=>H.offset-U.offset);let q=J.parentNode,X=document.createDocumentFragment(),G=0,_=0,z=0;while(G<=Z.length){let H=_<Q.length?Q[_].start:1/0,U=z<Y.length?Y[z].offset:1/0,W=Math.min(H,U);if(W===1/0){if(G<Z.length)X.appendChild(document.createTextNode(Z.slice(G)));break}let N=Math.max(W,G);if(N>G)X.appendChild(document.createTextNode(Z.slice(G,N))),G=N;while(z<Y.length&&Y[z].offset<=G){let K=document.createElement("span");K.className="diff-removed",K.textContent=Y[z].text,X.appendChild(K),z++}if(_<Q.length&&Q[_].start<=G){let K=Q[_],T=document.createElement("span");T.className="diff-added",T.textContent=Z.slice(G,K.end),X.appendChild(T),G=K.end,_++;while(z<Y.length&&Y[z].offset<=G){let O=document.createElement("span");O.className="diff-removed",O.textContent=Y[z].text,X.appendChild(O),z++}}}while(z<Y.length){let H=document.createElement("span");H.className="diff-removed",H.textContent=Y[z].text,X.appendChild(H),z++}q.replaceChild(X,J)}function M2(J,$){let Y=(J.getAttribute("data-md-source")||"").trim(),Z=($.getAttribute("data-md-source")||"").trim();if(Y===Z)return!1;let Q=Y.split(`
|
|
85
|
+
`),N=b1(U,W),K=(F,T,M)=>{let L=document.createElement("div");L.className="mt-2 bg-bg-code rounded-md overflow-hidden text-tiny font-mono",L.setAttribute("data-no-diff","true");let j=0,k=0;while(k<F.length){let B=document.createElement("div");if(B.className="px-3 py-0.5 whitespace-pre-wrap",j<T.length&&F[k]===T[j])B.textContent=" "+F[k],k++,j++;else B.classList.add(M==="old"?"diff-removed":"diff-added"),B.textContent=(M==="old"?"- ":"+ ")+F[k],k++;L.appendChild(B)}return L};G.appendChild(K(U,N,"old")),_.appendChild(K(W,N,"new"))}return Q}function i1(J){let $=[],Y=J.querySelectorAll(":scope > [data-md]");for(let Z of Y)$.push(z0(Z));if($.length===0){let Z=J.querySelectorAll("[data-md]"),Q=new Set;for(let q of Z){let X=q.parentElement?.closest("[data-md]");if(X&&J.contains(X))continue;if(Q.has(q))continue;Q.add(q),$.push(z0(q))}}return $}function z0(J){let $=J.getAttribute("data-md")||"unknown",Y=$4(J,$),Z=[];if($==="section"){let Q=J.querySelector(":scope > div.mt-6, :scope > div:last-child");if(Q)for(let q of Q.querySelectorAll(":scope > [data-md]"))Z.push(z0(q))}else if($==="table")for(let Q of J.querySelectorAll(":scope table > tbody > tr"))Z.push({key:"tr:"+(Q.textContent||"").slice(0,80),type:"tr",element:Q,children:[]});else if($==="checklist")for(let Q of J.querySelectorAll(":scope > [data-md='checklist-item']"))Z.push(z0(Q));else for(let Q of J.querySelectorAll("[data-md]"))if(Q.parentElement?.closest("[data-md]")===J)Z.push(z0(Q));return{key:Y,type:$,element:J,children:Z}}function $4(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 G0(J,$){let Y=J.map((z)=>z.key),Z=$.map((z)=>z.key),Q=b1(Y,Z),q=[],X=0,G=0,_=0;while(X<J.length||G<$.length)if(_<Q.length&&X<J.length&&G<$.length&&Y[X]===Q[_]&&Z[G]===Q[_]){let z=J[X],H=$[G],U=z.children.length>0||H.children.length>0?G0(z.children,H.children):void 0;q.push({kind:"matched",oldBlock:z,newBlock:H,childMatches:U}),X++,G++,_++}else if(X<J.length&&(_>=Q.length||Y[X]!==Q[_]))q.push({kind:"removed",oldBlock:J[X]}),X++;else if(G<$.length)q.push({kind:"added",newBlock:$[G]}),G++;return q}function u0(J){let $=document.createDocumentFragment(),Y=!1;for(let Z of J)if(Z.kind==="removed")Y=!0,$.appendChild(y2(Z.oldBlock.element));else if(Z.kind==="added")Y=!0,$.appendChild(J4(Z.newBlock.element));else{let Q=Z.newBlock.element.cloneNode(!0),q=Z.newBlock.type;if(q==="mermaid"){if(S2(Z.oldBlock.element,Q))Y=!0}else if(Z.childMatches&&Z.childMatches.length>0&&(q==="table"||q==="checklist")){if(B2(Q,Z.childMatches,q))Y=!0}else if(Z.childMatches&&Z.childMatches.length>0){if(M2(Z.oldBlock,Q,Z.childMatches,q))Y=!0}else if(q==="markdown"){if(P2(Z.oldBlock.element,Q))Y=!0}else if(f1(Z.oldBlock.element,Q,!1))Y=!0;$.appendChild(Q)}return{fragment:$,hasChanges:Y}}function y2(J){let $=J.cloneNode(!0);return $.classList.add("diff-block-removed"),$.style.position="relative",W5($,"Removed","var(--color-accent-red)"),$}function J4(J){let $=J.cloneNode(!0);return $.classList.add("diff-block-added"),$.style.position="relative",W5($,"Added","var(--color-accent-green)"),$}function M2(J,$,Y,Z){let Q=!1,q=Y4(J,$),X,G;if(Z==="section"){let _=J.element.querySelector(":scope > div:first-child"),z=$.querySelector(":scope > div:first-child");if(_&&z){if(f1(_,z,!1))Q=!0}X=J.element.querySelector(":scope > div.mt-6, :scope > div:last-child"),G=$.querySelector(":scope > div.mt-6, :scope > div:last-child")}else X=J.element,G=$;if(!X||!G)return Q;for(let _ of Y)if(_.kind==="matched"){let z=q.newMap.get(_.newBlock.element);if(z){if(_.newBlock.type==="mermaid"){if(S2(_.oldBlock.element,z))Q=!0}else if(_.childMatches&&_.childMatches.length>0&&(_.newBlock.type==="table"||_.newBlock.type==="checklist")){if(B2(z,_.childMatches,_.newBlock.type))Q=!0}else if(_.childMatches&&_.childMatches.length>0){if(M2(_.oldBlock,z,_.childMatches,_.newBlock.type))Q=!0}else if(_.newBlock.type==="markdown"){if(P2(_.oldBlock.element,z))Q=!0}else if(f1(_.oldBlock.element,z,!1))Q=!0}}else if(_.kind==="removed"){Q=!0;let z=y2(_.oldBlock.element),H=Z4(Y,_,q.newMap),U=H?X4(G,H):null;G.insertBefore(z,U)}else if(_.kind==="added"){Q=!0;let z=q.newMap.get(_.newBlock.element);if(z)z.classList.add("diff-block-added"),z.style.position="relative",W5(z,"Added","var(--color-accent-green)")}if(f1(X,G,!0))Q=!0;return Q}function B2(J,$,Y){let Z=Y==="table"?J.querySelector(":scope table > tbody"):J;if(!Z)return!1;let Q=!1;Z.innerHTML="";for(let q of $)if(q.kind==="removed"){Q=!0;let X=q.oldBlock.element.cloneNode(!0);X.classList.add(Y==="table"?"diff-row-removed":"diff-item-removed"),Z.appendChild(X)}else if(q.kind==="added"){Q=!0;let X=q.newBlock.element.cloneNode(!0);X.classList.add(Y==="table"?"diff-row-added":"diff-item-added"),Z.appendChild(X)}else{let X=q.newBlock.element.cloneNode(!0);if(f1(q.oldBlock.element,X,!1))Q=!0;Z.appendChild(X)}return Q}function Y4(J,$){let Y=new Map,Z=J.element.querySelectorAll("[data-md]"),Q=$.querySelectorAll("[data-md]");return{newMap:{get(q){return Q4($,q)}}}}function Q4(J,$){let Y=$.getAttribute("data-md");if(!Y)return null;let Z=$.getAttribute("data-md-label"),Q=$.getAttribute("data-md-title"),q=`[data-md="${Y}"]`;if(Q)q+=`[data-md-title="${CSS.escape(Q)}"]`;else if(Z)q+=`[data-md-label="${CSS.escape(Z)}"]`;let X=J.querySelectorAll(q);if(X.length===1)return X[0];let G=($.textContent||"").slice(0,100),_=null,z=-1;for(let H of X){let U=(H.textContent||"").slice(0,100),W=0;for(let N=0;N<Math.min(G.length,U.length);N++)if(G[N]===U[N])W++;if(W>z)z=W,_=H}return _}function Z4(J,$,Y){let Z=J.indexOf($);for(let Q=Z+1;Q<J.length;Q++){let q=J[Q];if((q.kind==="matched"||q.kind==="added")&&q.newBlock)return Y.get(q.newBlock.element)||null}return null}function X4(J,$){let Y=$;while(Y&&Y.parentElement!==J)Y=Y.parentElement;return Y}function P2(J,$){let Y=Array.from(J.children),Z=Array.from($.children);if(Y.length===0&&Z.length===0)return f1(J,$,!1);let Q=Y.map((W)=>W.tagName.toLowerCase()),q=Z.map((W)=>W.tagName.toLowerCase()),X=b1(Q,q),G=[],_=0,z=0,H=0;while(_<Y.length||z<Z.length)if(H<X.length&&_<Y.length&&z<Z.length&&Q[_]===X[H]&&q[z]===X[H])G.push({kind:"matched",oldChild:Y[_],newChild:Z[z]}),_++,z++,H++;else if(_<Y.length&&(H>=X.length||Q[_]!==X[H]))G.push({kind:"removed",oldChild:Y[_]}),_++;else if(z<Z.length)G.push({kind:"added",newChild:Z[z]}),z++;let U=!1;while($.firstChild)$.removeChild($.firstChild);for(let W of G)if(W.kind==="matched"){let N=(W.oldChild.textContent||"").match(/\S+/g)||[],K=(W.newChild.textContent||"").match(/\S+/g)||[],F=b1(N,K),T=Math.max(N.length,K.length);if((T>0?1-F.length/T:0)>0.5){U=!0;let L=W.oldChild.cloneNode(!0);L.classList.add("diff-block-removed"),$.appendChild(L),W.newChild.classList.add("diff-block-added"),$.appendChild(W.newChild)}else{if(f1(W.oldChild,W.newChild,!1))U=!0;$.appendChild(W.newChild)}}else if(W.kind==="removed"){U=!0;let N=W.oldChild.cloneNode(!0);N.classList.add("diff-block-removed"),$.appendChild(N)}else U=!0,W.newChild.classList.add("diff-block-added"),$.appendChild(W.newChild);return U}function L2(J,$){let Y=$?new Set(Array.from(J.querySelectorAll("[data-md]"))):new Set,Z=[],Q=[],q=document.createTreeWalker(J,NodeFilter.SHOW_TEXT,{acceptNode(G){let _=G.parentElement;if(!_)return NodeFilter.FILTER_REJECT;if(_.closest("svg, .select-none, [data-no-diff]"))return NodeFilter.FILTER_REJECT;if($){for(let z of Y)if(z.contains(G))return NodeFilter.FILTER_REJECT}return NodeFilter.FILTER_ACCEPT}}),X;while(X=q.nextNode()){let _=(X.nodeValue||"").match(/\S+|\s+/g);if(!_)continue;let z=0;for(let H of _)Z.push(H),Q.push({text:H,node:X,offset:z}),z+=H.length}return{words:Z,map:Q}}function f1(J,$,Y){let Z=L2(J,Y),Q=L2($,Y);if(Z.words.length===0&&Q.words.length===0)return!1;let{oldOps:q,newOps:X}=H5(Z.words,Q.words),G=q.some((T)=>T.type==="removed"),_=X.some((T)=>T.type==="added");if(!G&&!_)return!1;let z=[],H=[];for(let T of q)if(T.type==="same")z.push(T.index);for(let T of X)if(T.type==="same")H.push(T.index);let U=new Map;for(let T=0;T<z.length&&T<H.length;T++)U.set(z[T],H[T]);let W=[];{let T=[],M=-1;for(let L of q)if(L.type==="same"){if(T.length>0)W.push({text:T.join(""),anchorNewIdx:M>=0?U.get(M)??null:null}),T=[];M=L.index}else if(L.type==="removed")T.push(Z.words[L.index]);if(T.length>0)W.push({text:T.join(""),anchorNewIdx:M>=0?U.get(M)??null:null})}let N=new Map,K=new Map;for(let T of X){if(T.type!=="added")continue;let M=Q.map[T.index];if(!M?.node.parentNode)continue;let L=N.get(M.node);if(!L)L=[],N.set(M.node,L);L.push({start:M.offset,end:M.offset+M.text.length})}for(let T of W)if(T.anchorNewIdx===null){if(Q.map.length>0){let M=Q.map[0].node,L=K.get(M);if(!L)L=[],K.set(M,L);L.push({offset:0,text:T.text})}}else{let M=Q.map[T.anchorNewIdx];if(!M)continue;let L=K.get(M.node);if(!L)L=[],K.set(M.node,L);L.push({offset:M.offset+M.text.length,text:T.text})}let F=new Set([...N.keys(),...K.keys()]);for(let T of F)q4(T,N.get(T)||[],K.get(T)||[]);return!0}function q4(J,$,Y){if(!J.parentNode)return;let Z=J.nodeValue||"";$.sort((H,U)=>H.start-U.start);let Q=[];for(let H of $){let U=Q[Q.length-1];if(U&&H.start<=U.end)U.end=Math.max(U.end,H.end);else Q.push({...H})}Y.sort((H,U)=>H.offset-U.offset);let q=J.parentNode,X=document.createDocumentFragment(),G=0,_=0,z=0;while(G<=Z.length){let H=_<Q.length?Q[_].start:1/0,U=z<Y.length?Y[z].offset:1/0,W=Math.min(H,U);if(W===1/0){if(G<Z.length)X.appendChild(document.createTextNode(Z.slice(G)));break}let N=Math.max(W,G);if(N>G)X.appendChild(document.createTextNode(Z.slice(G,N))),G=N;while(z<Y.length&&Y[z].offset<=G){let K=document.createElement("span");K.className="diff-removed",K.textContent=Y[z].text,X.appendChild(K),z++}if(_<Q.length&&Q[_].start<=G){let K=Q[_],F=document.createElement("span");F.className="diff-added",F.textContent=Z.slice(G,K.end),X.appendChild(F),G=K.end,_++;while(z<Y.length&&Y[z].offset<=G){let T=document.createElement("span");T.className="diff-removed",T.textContent=Y[z].text,X.appendChild(T),z++}}}while(z<Y.length){let H=document.createElement("span");H.className="diff-removed",H.textContent=Y[z].text,X.appendChild(H),z++}q.replaceChild(X,J)}function S2(J,$){let Y=(J.getAttribute("data-md-source")||"").trim(),Z=($.getAttribute("data-md-source")||"").trim();if(Y===Z)return!1;let Q=Y.split(`
|
|
86
86
|
`),q=Z.split(`
|
|
87
|
-
`),X=b1(Q,q),G=[],_=0,z=0,H=0;while(_<Q.length||z<q.length)if(H<X.length&&_<Q.length&&z<q.length&&Q[_]===X[H]&&q[z]===X[H])G.push({type:"same",line:Q[_]}),_++,z++,H++;else if(_<Q.length&&(H>=X.length||Q[_]!==X[H]))G.push({type:"removed",line:Q[_]}),_++;else if(z<q.length)G.push({type:"added",line:q[z]}),z++;let U=document.createElement("div");U.className="mt-2 bg-bg-code rounded-md overflow-hidden text-tiny font-mono",U.setAttribute("data-no-diff","true");for(let W of G){let N=document.createElement("div");if(N.className="px-3 py-0.5 whitespace-pre-wrap",W.type==="removed")N.classList.add("diff-removed"),N.textContent="- "+W.line;else if(W.type==="added")N.classList.add("diff-added"),N.textContent="+ "+W.line;else N.textContent=" "+W.line;U.appendChild(N)}return $.appendChild(U),!0}function H5(J,$,Y){let Z=document.createElement("span");Z.className="diff-block-label",Z.textContent=$,Z.style.color=Y,Z.style.backgroundColor=`color-mix(in srgb, ${Y} 12%, transparent)`,J.appendChild(Z)}import{jsxDEV as f}from"react/jsx-dev-runtime";function q4(J,$,Y){let Z=J.find((X)=>X.revision===$),Q=J.find((X)=>X.revision===Y),q=new Set;for(let X of Z?.canvasFiles||[])q.add(X.filename);for(let X of Q?.canvasFiles||[])q.add(X.filename);return[...q].sort()}function b2({initialLeft:J,initialRight:$,sessionId:Y,onExit:Z}){let[Q,q]=Q1(J),[X,G]=Q1($),[_,z]=Q1("unified"),[H,U]=Q1(!0),[W,N]=Q1(!1),{revisions:K}=X4(N1),T=g0(()=>q4(K,Q,X),[K,Q,X]),[O,S]=Q1(()=>T[0]||"plan.jsx");w1(()=>{if(!T.includes(O))S(T[0]||"plan.jsx")},[T,O]);let L=g0(()=>{return K.find((M)=>M.revision===Q)?.canvasFiles.some((M)=>M.filename===O)??!1},[K,Q,O]),j=g0(()=>{return K.find((M)=>M.revision===X)?.canvasFiles.some((M)=>M.filename===O)??!1},[K,X,O]);return f("div",{className:"flex flex-col h-screen",children:[f("div",{className:"flex items-center justify-between px-6 py-3 border-b border-border-subtle bg-bg-surface flex-shrink-0",children:[f("div",{className:"flex items-center gap-3",children:[f("span",{className:"text-[13px] font-body font-medium text-text-primary",children:"Compare"},void 0,!1,void 0,this),f(q0,{value:Q,onChange:q,accent:"red"},void 0,!1,void 0,this),f("span",{className:"text-text-tertiary text-[13px]",children:"→"},void 0,!1,void 0,this),f(q0,{value:X,onChange:G,accent:"green"},void 0,!1,void 0,this),W&&!H&&f("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),f("div",{className:"flex items-center gap-4",children:[f("div",{className:"flex items-center bg-bg-elevated rounded-md p-0.5",children:[f("button",{onClick:()=>z("unified"),className:`text-[11px] font-body px-2.5 py-1 rounded transition-colors ${_==="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),f("button",{onClick:()=>z("side-by-side"),className:`text-[11px] font-body px-2.5 py-1 rounded transition-colors ${_==="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),_==="side-by-side"&&f(_4,{},void 0,!1,void 0,this),f("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),T.length>1&&f("div",{className:"flex items-center gap-1 px-6 py-2 border-b border-border-subtle bg-bg-surface flex-shrink-0 overflow-x-auto",children:T.map((V)=>{let M=V.replace(/\.jsx$/,""),I=V===O,D=K.find((R)=>R.revision===Q)?.canvasFiles.some((R)=>R.filename===V),E=K.find((R)=>R.revision===X)?.canvasFiles.some((R)=>R.filename===V),C=!D?" (added)":!E?" (removed)":"";return f("button",{onClick:()=>S(V),className:`text-[12px] font-body px-3 py-1 rounded-md transition-colors whitespace-nowrap ${I?"bg-bg-elevated text-text-primary font-medium":"text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated"}`,children:[M,C&&f("span",{className:`ml-1 text-[10px] ${!D?"text-accent-green":"text-accent-red"}`,children:C},void 0,!1,void 0,this)]},V,!0,void 0,this)})},void 0,!1,void 0,this),!L||!j?f("div",{className:"flex-1 flex items-center justify-center",children:f("div",{className:"text-center text-text-tertiary font-body",children:[f("div",{className:"text-lg mb-2",children:!L?"New file":"Removed file"},void 0,!1,void 0,this),f("div",{className:"text-[13px]",children:[O.replace(/\.jsx$/,"")," ",!L?"was added":"was removed"," in this revision"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this):_==="unified"?f(z4,{sessionId:Y,leftRev:Q,rightRev:X,filename:O,onDiffResult:(V,M)=>{N(V),U(M)}},`unified-${Q}-${X}-${O}`,!1,void 0,this):f(G4,{sessionId:Y,leftRev:Q,rightRev:X,filename:O,onDiffResult:(V,M)=>{N(V),U(M)}},`sbs-${Q}-${X}-${O}`,!1,void 0,this)]},void 0,!0,void 0,this)}function _4(){let[J,$]=Q1(!0);return w1(()=>{return document.documentElement.dataset.syncScroll=J?"1":"0",()=>{delete document.documentElement.dataset.syncScroll}},[J]),f("label",{className:"flex items-center gap-1.5 cursor-pointer select-none",children:[f("input",{type:"checkbox",checked:J,onChange:(Y)=>$(Y.target.checked),className:"accent-accent-amber w-3.5 h-3.5"},void 0,!1,void 0,this),f("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 z4({sessionId:J,leftRev:$,rightRev:Y,filename:Z,onDiffResult:Q}){let q=L1(null),X=L1(null),G=L1(null),[_,z]=Q1(!1),[H,U]=Q1(!1),[W,N]=Q1(!1),[K,T]=Q1(null),[O,S]=Q1(!1),{annotations:L}=e(),j=L.filter((M)=>!M.filePath&&(!M.canvasFile||M.canvasFile===Z)),{popovers:V}=E1({containerRef:G,restoreKey:W,restoreAnnotations:j,extractContext:(M)=>D1(M,G.current)});return w1(()=>{if(W||K)return;let M=setTimeout(()=>{console.warn("[unified-diff] still loading after 10s",{leftReady:_,rightReady:H,oldRef:!!q.current,newRef:!!X.current}),S(!0)},1e4);return()=>clearTimeout(M)},[W,K,_,H]),w1(()=>{if(!_||!H||W)return;if(!q.current||!X.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!q.current||!X.current||!G.current){console.warn("[unified-diff] refs lost between rAF frames",{old:!!q.current,new:!!X.current,unified:!!G.current});return}try{let M=a1(q.current),I=a1(X.current),D=z0(M,I),{fragment:E,hasChanges:C}=m0(D);G.current.innerHTML="",G.current.appendChild(E),N(!0),Q(!0,C)}catch(M){console.error("[unified-diff] diff computation failed",M),T(M instanceof Error?M.message:String(M))}})})},[_,H,W]),f("div",{className:"flex-1 min-h-0 overflow-y-auto",children:[!W&&!K&&f("div",{style:{position:"absolute",left:-9999,visibility:"hidden",pointerEvents:"none",width:720},children:[f(B1,{ref:q,sessionId:J,revision:$,filename:Z,onReady:()=>z(!0),onError:(M)=>T(`Rev ${$}: ${M}`)},void 0,!1,void 0,this),f(B1,{ref:X,sessionId:J,revision:Y,filename:Z,onReady:()=>U(!0),onError:(M)=>T(`Rev ${Y}: ${M}`)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),f("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:[!W&&!K&&f("div",{className:"flex flex-col items-center justify-center h-64 text-text-tertiary font-body text-body gap-2",children:[f("span",{children:"Loading..."},void 0,!1,void 0,this),O&&f("span",{className:"text-[11px]",children:"Taking longer than expected — check Network tab for pending requests"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),K&&f("div",{className:"bg-accent-red-muted rounded-lg p-5 mt-8",children:[f("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Failed to load revision"},void 0,!1,void 0,this),f("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:K},void 0,!1,void 0,this)]},void 0,!0,void 0,this),f("div",{ref:G},void 0,!1,void 0,this)]},void 0,!0,void 0,this),V]},void 0,!0,void 0,this)}function G4({sessionId:J,leftRev:$,rightRev:Y,filename:Z,onDiffResult:Q}){let q=L1(null),X=L1(null),[G,_]=Q1(!1),[z,H]=Q1(!1),[U,W]=Q1(!1),N=L1(null),K=L1(null),T=L1(null),O=L1(!1),S=S2(()=>_(!0),[]),L=S2(()=>H(!0),[]),{annotations:j}=e(),V=j.filter((I)=>!I.filePath&&(!I.canvasFile||I.canvasFile===Z)),{popovers:M}=E1({containerRef:N,restoreKey:U,restoreAnnotations:V,extractContext:(I)=>D1(I,N.current)});return w1(()=>{if(!G||!z||U)return;if(!q.current||!X.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!q.current||!X.current)return;let I=D0(q.current,X.current);W(!0),Q(!0,I)})})},[G,z,U]),w1(()=>{let I=K.current,D=T.current;if(!I||!D)return;let E=(v,m)=>{if(document.documentElement.dataset.syncScroll==="0")return;if(O.current)return;O.current=!0;let c=v.scrollHeight-v.clientHeight,y=m.scrollHeight-m.clientHeight;if(c>0&&y>0)m.scrollTop=v.scrollTop/c*y;requestAnimationFrame(()=>{O.current=!1})},C=()=>E(I,D),R=()=>E(D,I);return I.addEventListener("scroll",C),D.addEventListener("scroll",R),()=>{I.removeEventListener("scroll",C),D.removeEventListener("scroll",R)}},[]),f("div",{ref:N,className:"flex flex-1 min-h-0",children:[f("div",{ref:K,className:"w-1/2 overflow-y-auto border-r border-border-subtle",children:f("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:f(B1,{ref:q,sessionId:J,revision:$,filename:Z,onReady:S},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),f("div",{ref:T,className:"w-1/2 overflow-y-auto",children:f("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:f(B1,{ref:X,sessionId:J,revision:Y,filename:Z,onReady:L},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),M]},void 0,!0,void 0,this)}var B1=P2.memo(P2.forwardRef(({sessionId:J,revision:$,filename:Y,onReady:Z,onError:Q},q)=>{let[X,G]=Q1(null),[_,z]=Q1(null),[H,U]=Q1(!0);w1(()=>{U(!0),z(null);let N=Y.replace(/\.jsx$/,".js");import(`/api/session/${J}/canvas/${encodeURIComponent(N)}?rev=${$}&t=${Date.now()}`).then((K)=>{if(!K.default){z("Module has no default export"),U(!1),Q?.("Module has no default export");return}G(()=>K.default),U(!1)}).catch((K)=>{z(K.message),U(!1),Q?.(K.message)})},[J,$,Y]),w1(()=>{if(!X)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{Z()})})},[X]);let W=g0(()=>X?f(X,{},void 0,!1,void 0,this):null,[X]);if(H)return f("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(_)return f("div",{className:"bg-accent-red-muted rounded-lg p-5",children:[f("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Error"},void 0,!1,void 0,this),f("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:_},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(!X)return f("div",{className:"text-text-tertiary text-center py-8 font-body text-body",children:"No canvas loaded"},void 0,!1,void 0,this);return f("div",{ref:q,children:W},void 0,!1,void 0,this)}));import{useState as y1,useContext as W5,useMemo as U4,useRef as G0,useEffect as A2,useCallback as w2}from"react";import{SessionContext as K4}from"#canvas/runtime";import{jsxDEV as h}from"react/jsx-dev-runtime";function N5(J,$){if(!J)return[];return J.canvasFiles.map((Y)=>{if(!Y.diffStats)return{filename:Y.filename,status:"new"};if(Y.diffStats.added===0&&Y.diffStats.removed===0)return{filename:Y.filename,status:"unchanged",diffStats:Y.diffStats};return{filename:Y.filename,status:"changed",diffStats:Y.diffStats}})}function I2(J){return J.filter(($)=>$.status!=="unchanged").map(($)=>$.filename)}function C2({revision:J,responseBanner:$}){let{setActiveView:Y}=W5(F1),{revisions:Z}=W5(N1),Q=Z.find((z)=>z.revision===J),q=Z.find((z)=>z.revision===J-1),X=U4(()=>N5(Q,q),[Q,q]),G=X.filter((z)=>z.status!=="unchanged"),_=X.filter((z)=>z.status==="unchanged");return h("div",{className:"max-w-[720px] mx-auto px-6 pt-12 pb-32",children:[$,G.map((z)=>h(W4,{change:z,revision:J,previousRevision:q?.revision,onOpenTab:()=>Y({type:"canvas",filename:z.filename})},z.filename,!1,void 0,this)),_.length>0&&h("div",{className:"mt-8 border-t border-border-subtle pt-4",children:[h("div",{className:"text-[11px] font-body font-medium uppercase tracking-widest text-text-tertiary mb-3",children:"Unchanged"},void 0,!1,void 0,this),_.map((z)=>h(F4,{change:z,revision:J,onOpenTab:()=>Y({type:"canvas",filename:z.filename})},z.filename,!1,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function H4({mode:J,onChange:$,showDiff:Y}){if(!Y)return null;return h("div",{className:"flex items-center bg-bg-elevated rounded-md p-0.5",children:["rendered","unified","side-by-side"].map((Z)=>h("button",{onClick:()=>$(Z),className:`text-[10px] font-body px-2 py-0.5 rounded transition-colors ${J===Z?"bg-bg-surface text-text-primary font-medium shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:Z==="rendered"?"Full":Z==="unified"?"Unified":"Split"},Z,!1,void 0,this))},void 0,!1,void 0,this)}function W4({change:J,revision:$,previousRevision:Y,onOpenTab:Z}){let Q=J.filename.replace(/\.jsx$/,""),q=J.status==="new",X=J.diffStats,G=J.status==="changed"&&Y!=null,[_,z]=y1("rendered");return h("div",{className:"mb-8",children:[h("div",{className:"flex items-center gap-2 mb-3 pb-2 border-b border-border-subtle",children:[h("span",{className:`text-[11px] font-mono px-1.5 py-0.5 rounded ${q?"bg-accent-green/10 text-accent-green border border-accent-green/20":"bg-accent-amber/10 text-accent-amber border border-accent-amber/20"}`,children:q?"new":"modified"},void 0,!1,void 0,this),h("span",{className:"text-[14px] font-body font-medium text-text-primary",children:Q},void 0,!1,void 0,this),X&&(X.added>0||X.removed>0)&&h("span",{className:"text-[11px] font-mono text-text-tertiary",children:[h("span",{className:"text-accent-green",children:["+",X.added]},void 0,!0,void 0,this)," ",h("span",{className:"text-accent-red",children:["-",X.removed]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),h(H4,{mode:_,onChange:z,showDiff:G},void 0,!1,void 0,this),h("button",{onClick:Z,className:`${G?"":"ml-auto"} text-[11px] font-body font-medium text-accent-blue hover:text-accent-blue/80 transition-colors`,children:"Open in tab"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),_==="rendered"?h("div",{"data-canvas-file":J.filename,children:h(Y0,{revision:$,filename:J.filename},void 0,!1,void 0,this)},void 0,!1,void 0,this):G&&Y!=null?h(N4,{filename:J.filename,leftRev:Y,rightRev:$,mode:_},`${_}-${$}-${Y}`,!1,void 0,this):null]},void 0,!0,void 0,this)}function N4({filename:J,leftRev:$,rightRev:Y,mode:Z}){let Q=W5(K4);if(Z==="unified")return h(T4,{sessionId:Q,filename:J,leftRev:$,rightRev:Y},void 0,!1,void 0,this);return h(O4,{sessionId:Q,filename:J,leftRev:$,rightRev:Y},void 0,!1,void 0,this)}function T4({sessionId:J,filename:$,leftRev:Y,rightRev:Z}){let Q=G0(null),q=G0(null),X=G0(null),[G,_]=y1(!1),[z,H]=y1(!1),[U,W]=y1(!1),[N,K]=y1(null);return A2(()=>{if(!G||!z||U)return;if(!Q.current||!q.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!Q.current||!q.current||!X.current)return;try{let T=a1(Q.current),O=a1(q.current),S=z0(T,O),{fragment:L}=m0(S);X.current.innerHTML="",X.current.appendChild(L),W(!0)}catch(T){K(T instanceof Error?T.message:String(T))}})})},[G,z,U]),h("div",{children:[!U&&!N&&h("div",{style:{position:"absolute",left:-9999,visibility:"hidden",pointerEvents:"none",width:720},children:[h(B1,{ref:Q,sessionId:J,revision:Y,filename:$,onReady:()=>_(!0),onError:(T)=>K(T)},void 0,!1,void 0,this),h(B1,{ref:q,sessionId:J,revision:Z,filename:$,onReady:()=>H(!0),onError:(T)=>K(T)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!U&&!N&&h("div",{className:"flex items-center justify-center h-24 text-text-tertiary font-body text-[13px]",children:"Computing diff..."},void 0,!1,void 0,this),N&&h("div",{className:"text-accent-red text-[13px] font-body p-3 bg-accent-red-muted rounded-lg",children:N},void 0,!1,void 0,this),h("div",{ref:X},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function O4({sessionId:J,filename:$,leftRev:Y,rightRev:Z}){let Q=G0(null),q=G0(null),[X,G]=y1(!1),[_,z]=y1(!1),[H,U]=y1(!1),W=w2(()=>G(!0),[]),N=w2(()=>z(!0),[]);return A2(()=>{if(!X||!_||H)return;if(!Q.current||!q.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!Q.current||!q.current)return;D0(Q.current,q.current),U(!0)})})},[X,_,H]),h("div",{className:"flex gap-0 border-y border-border-subtle overflow-hidden w-screen relative left-1/2 -translate-x-1/2",children:[h("div",{className:"w-1/2 border-r border-border-subtle",children:[h("div",{className:"px-2 py-1 text-[10px] font-body font-medium text-text-tertiary bg-bg-elevated border-b border-border-subtle",children:["Rev ",Y]},void 0,!0,void 0,this),h("div",{className:"px-6 py-4 max-w-[600px] mx-auto",children:h(B1,{ref:Q,sessionId:J,revision:Y,filename:$,onReady:W},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),h("div",{className:"w-1/2",children:[h("div",{className:"px-2 py-1 text-[10px] font-body font-medium text-text-tertiary bg-bg-elevated border-b border-border-subtle",children:["Rev ",Z]},void 0,!0,void 0,this),h("div",{className:"px-6 py-4 max-w-[600px] mx-auto",children:h(B1,{ref:q,sessionId:J,revision:Z,filename:$,onReady:N},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function F4({change:J,revision:$,onOpenTab:Y}){let[Z,Q]=y1(!1),q=J.filename.replace(/\.jsx$/,"");return h("div",{className:"mb-2",children:[h("div",{className:"flex items-center gap-2 py-1.5",children:[h("button",{onClick:()=>Q(!Z),className:"text-text-tertiary hover:text-text-secondary transition-colors",children:h("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",className:`transition-transform duration-150 ${Z?"rotate-90":""}`,children:h("path",{d:"M3.5 2L6.5 5L3.5 8",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),h("span",{className:"text-[13px] font-body text-text-secondary",children:q},void 0,!1,void 0,this),h("button",{onClick:Y,className:"ml-auto text-[11px] font-body text-text-tertiary hover:text-accent-blue transition-colors",children:"Open in tab"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Z&&h("div",{className:"ml-5 mt-1 mb-3","data-canvas-file":J.filename,children:h(Y0,{revision:$,filename:J.filename},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{jsxDEV as F,Fragment as E0}from"react/jsx-dev-runtime";var F1=D2({activeView:{type:"overview"},setActiveView:()=>{},openFiles:[],closeFile:()=>{},canvasFiles:[]}),N1=D2({currentRevision:1,selectedRevision:1,revisions:[],setSelectedRevision:()=>{},isReadOnly:!1,compareRevision:null,setCompareRevision:()=>{}});function M4(J){if(J==="auto")return window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light";return J}function R2(J){document.documentElement.dataset.theme=M4(J)}function g2(){let[J,$]=$1(()=>{let Q=localStorage.getItem("canvas-theme");if(Q==="light"||Q==="dark"||Q==="auto")return Q;return"auto"});return M1(()=>{if(R2(J),J!=="auto")return;let Q=window.matchMedia("(prefers-color-scheme: dark)"),q=()=>R2("auto");return Q.addEventListener("change",q),()=>Q.removeEventListener("change",q)},[J]),F("button",{onClick:()=>{let Q=J==="auto"?"light":J==="light"?"dark":"auto";localStorage.setItem("canvas-theme",Q),$(Q)},className:"w-7 h-7 flex items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:{auto:"Theme: system (click for light)",light:"Theme: light (click for dark)",dark:"Theme: dark (click for system)"}[J],children:J==="auto"?F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[F("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2",ry:"2"},void 0,!1,void 0,this),F("line",{x1:"8",y1:"21",x2:"16",y2:"21"},void 0,!1,void 0,this),F("line",{x1:"12",y1:"17",x2:"12",y2:"21"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):J==="dark"?F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:F("path",{d:"M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"},void 0,!1,void 0,this)},void 0,!1,void 0,this):F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[F("circle",{cx:"12",cy:"12",r:"5"},void 0,!1,void 0,this),F("line",{x1:"12",y1:"1",x2:"12",y2:"3"},void 0,!1,void 0,this),F("line",{x1:"12",y1:"21",x2:"12",y2:"23"},void 0,!1,void 0,this),F("line",{x1:"4.22",y1:"4.22",x2:"5.64",y2:"5.64"},void 0,!1,void 0,this),F("line",{x1:"18.36",y1:"18.36",x2:"19.78",y2:"19.78"},void 0,!1,void 0,this),F("line",{x1:"1",y1:"12",x2:"3",y2:"12"},void 0,!1,void 0,this),F("line",{x1:"21",y1:"12",x2:"23",y2:"12"},void 0,!1,void 0,this),F("line",{x1:"4.22",y1:"19.78",x2:"5.64",y2:"18.36"},void 0,!1,void 0,this),F("line",{x1:"18.36",y1:"5.64",x2:"19.78",y2:"4.22"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function u2(){let{currentRevision:J,selectedRevision:$,revisions:Y,setSelectedRevision:Z,setCompareRevision:Q}=A1.useContext(N1);if(Y.length<=1){let G=Y[0]?.label||`Round ${J}`;return F("span",{className:"text-[11px] text-text-tertiary font-body",children:G},void 0,!1,void 0,this)}return F("div",{className:"flex flex-col gap-1",children:[F(q0,{value:$,onChange:Z,accent:$===J?"default":"amber"},void 0,!1,void 0,this),F("button",{onClick:()=>{let X;if($===J)X=[...Y].reverse().find((_)=>_.revision<J)?.revision??Math.max(1,J-1);else X=$;Q({left:X,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 P4(){let J=window.location.pathname.replace("/s/","")||"",[$,Y]=$1(1),[Z,Q]=$1(1),[q,X]=$1([]),[G,_]=$1(null),[z,H]=$1(!1),[U,W]=$1(!1),[N,K]=$1([]),[T,O]=$1({type:"overview"}),[S,L]=$1([]),j=I1(null),[V,M]=$1(),[I,D]=$1(!1),[E,C]=$1(!1),[R,v]=$1(!1);M1(()=>{let B=["Agent Canvas"];if(V){let b=V.replace(/\/+$/,"").split("/");B.push(b[b.length-1]||J)}else if(J)B.push(J);if(T.type==="file")B.push(T.path.split("/").pop()||T.path);else if(T.type==="overview")B.push("Overview");else if(T.type==="canvas"&&N.length>1&&T.filename)B.push(T.filename.replace(/\.jsx$/,""));else if(G)B.push("Compare");document.title=B.join(" — ")},[J,V,T,G]);let m=I1(new Map),c=q.find((B)=>B.revision===Z),y=Z!==$||!!c?.hasFeedback,P=u0((B)=>{let b=T.type==="overview"?"overview":T.type==="canvas"?`canvas:${T.filename}`:`file:${T.path}`;if(m.current.set(b,window.scrollY),O(B),B.type==="file")L((g)=>g.includes(B.path)?g:[...g,B.path])},[T]),x=u0((B)=>{m.current.delete(`file:${B}`),L((b)=>b.filter((g)=>g!==B)),O((b)=>{if(b.type==="file"&&b.path===B)return N.length>1?{type:"overview"}:{type:"canvas",filename:N[0]||""};return b})},[N]);L4(()=>{let B=T.type==="overview"?"overview":T.type==="canvas"?`canvas:${T.filename}`:`file:${T.path}`;window.scrollTo(0,m.current.get(B)||0)},[T]),M1(()=>{if(!J)return;fetch(`/api/session/${J}/meta`).then((B)=>B.json()).then((B)=>{if(B.currentRevision)Y(B.currentRevision),Q(B.currentRevision),X(B.revisions||[]);if(B.canvasFiles){let b=B.canvasFiles.sort();K(b),O((g)=>{if(g.type==="overview")return b.length>1?g:{type:"canvas",filename:b[0]||""};if(g.type==="canvas"&&(!g.filename||!b.includes(g.filename)))return{type:"canvas",filename:b[0]||""};return g})}if(B.projectRoot)M(B.projectRoot)}).catch(()=>{})},[J]),M1(()=>{if(!J)return;let B=null,b=()=>{let g=window.location.protocol==="https:"?"wss:":"ws:",o=new WebSocket(`${g}//${window.location.host}/ws/session/${J}`);j.current=o,o.onopen=()=>H(!0),o.onclose=()=>{H(!1),B=setTimeout(b,2000)},o.onmessage=(i)=>{try{let k=JSON.parse(i.data);if(k.type==="plan-updated"){if(Y(k.currentRevision),Q(k.currentRevision),_(null),k.revisions){let r=k.revisions;X(r);let A=r.find((u)=>u.revision===k.currentRevision);if(A?.canvasFiles){let u=A.canvasFiles.map((j1)=>j1.filename).sort();K(u);let s=r.find((j1)=>j1.revision===k.currentRevision-1),_1=N5(A,s),C1=I2(_1);if(C1.length===1)O({type:"canvas",filename:C1[0]});else if(C1.length>1||u.length>1)O({type:"overview"});else O({type:"canvas",filename:u[0]||""})}}}if(k.type==="revision-updated"){if(k.revisions)X(k.revisions)}}catch{}}};return b(),()=>{if(B)clearTimeout(B);j.current?.close()}},[J]);let p=u0((B)=>{if(j.current?.readyState===WebSocket.OPEN)j.current.send(JSON.stringify({type:"submit",feedback:B})),W(!1)},[]);if(!J)return F("div",{className:"flex items-center justify-center h-screen text-text-tertiary font-body",children:"No session selected."},void 0,!1,void 0,this);return F(m2.Provider,{value:J,children:F(N1.Provider,{value:{currentRevision:$,selectedRevision:Z,revisions:q,setSelectedRevision:Q,isReadOnly:y,compareRevision:G,setCompareRevision:_},children:F(D5,{sessionId:J,revision:Z,isReadOnly:y,children:F(F1.Provider,{value:{activeView:T,setActiveView:P,openFiles:S,closeFile:x,canvasFiles:N},children:F(y4.Provider,{value:{setActiveView:P},children:F("div",{className:"min-h-screen bg-bg-base",children:[F(S4,{sessionId:J,projectRoot:V,connected:z,onMobileSidebar:()=>D(!I),collapsed:E,onToggle:()=>C((B)=>!B)},void 0,!1,void 0,this),F(b4,{collapsed:R,onToggle:()=>v((B)=>!B),children:F(z5,{onPreview:()=>W(!0),onSubmit:p},void 0,!1,void 0,this)},void 0,!1,void 0,this),G!==null?F("div",{className:`${E?"lg:ml-0":"lg:ml-60"} ${R?"lg:mr-0":"lg:mr-[var(--sidebar-width,320px)]"} transition-[margin] duration-200`,children:F(b2,{initialLeft:G.left,initialRight:G.right,sessionId:J,onExit:()=>_(null)},void 0,!1,void 0,this)},void 0,!1,void 0,this):F("div",{className:`relative ${E?"lg:ml-0":"lg:ml-60"} ${R?"lg:mr-0":"lg:mr-[var(--sidebar-width,320px)]"} transition-[margin] duration-200`,id:"plan-scroll-container",children:[F("div",{className:"lg:hidden sticky top-0 z-20 flex items-center justify-between px-4 py-2 border-b border-border-subtle bg-bg-surface",children:[F("div",{className:"flex items-center gap-2",children:[F(U5,{currentSessionId:J,projectRoot:V},void 0,!1,void 0,this),F("span",{className:`w-1.5 h-1.5 rounded-full ${z?"bg-accent-green":"bg-accent-red"}`},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("div",{className:"flex items-center gap-1",children:[F(u2,{},void 0,!1,void 0,this),F("button",{onClick:()=>D(!I),className:"w-7 h-7 flex items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Annotations",children:F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:F("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),F(g2,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),F(w4,{},void 0,!1,void 0,this),T.type==="overview"&&F(C2,{revision:Z,responseBanner:c?.response?F(k2,{markdown:c.response},void 0,!1,void 0,this):void 0},void 0,!1,void 0,this),T.type==="canvas"&&N.includes(T.filename)&&F("div",{className:"relative max-w-[720px] mx-auto px-6 pt-12 pb-32",children:[F("button",{onClick:()=>{let B=document.querySelector(`[data-canvas-file="${T.filename}"] .plan-content`);if(!B)return;let b=U2(B);navigator.clipboard.writeText(b).then(()=>{let g=document.getElementById("export-md-btn");if(g)g.setAttribute("data-copied","true"),setTimeout(()=>{g.removeAttribute("data-copied")},1500)})},id:"export-md-btn",className:"group absolute top-3 right-6 p-1.5 text-text-tertiary hover:text-text-secondary transition-colors z-10",title:"Copy as Markdown",children:[F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"group-[[data-copied=true]]:hidden",children:[F("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"},void 0,!1,void 0,this),F("path",{d:"M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"hidden group-[[data-copied=true]]:block text-green-500",children:F("polyline",{points:"20 6 9 17 4 12"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),N.length<=1&&c?.response&&F(k2,{markdown:c.response},void 0,!1,void 0,this),F("div",{"data-canvas-file":T.filename,children:F(Y0,{revision:Z,filename:T.filename},T.filename,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),S.map((B)=>F("div",{style:{display:T.type==="file"&&T.path===B?void 0:"none"},children:F(q2,{path:B},void 0,!1,void 0,this)},B,!1,void 0,this))]},void 0,!0,void 0,this),I&&F("div",{className:"lg:hidden fixed inset-0 z-40 flex",children:[F("div",{className:"flex-1",onClick:()=>D(!1)},void 0,!1,void 0,this),F("div",{className:"w-80 max-w-[85vw] bg-bg-surface border-l border-border-subtle flex flex-col shadow-lg",children:[F("div",{className:"flex items-center justify-between px-4 py-2 border-b border-border-subtle flex-shrink-0",children:[F("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:"Sidebar"},void 0,!1,void 0,this),F("button",{onClick:()=>D(!1),className:"text-text-tertiary hover:text-text-secondary w-7 h-7 flex items-center justify-center",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("div",{className:"flex-1 overflow-hidden",children:F(z5,{onPreview:()=>W(!0),onSubmit:p},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),F(o5,{open:U,onClose:()=>W(!1),onSubmit:p},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 S4({sessionId:J,projectRoot:$,connected:Y,onMobileSidebar:Z,collapsed:Q,onToggle:q}){return F(E0,{children:[Q&&F("button",{onClick:q,className:"hidden lg:flex fixed top-3 left-3 z-20 w-7 h-7 items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors bg-bg-surface border border-border-subtle",title:"Show sidebar",children:F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[F("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"},void 0,!1,void 0,this),F("line",{x1:"9",y1:"3",x2:"9",y2:"21"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),F("div",{className:`hidden lg:flex w-60 flex-col fixed top-0 left-0 bottom-0 bg-bg-surface border-r border-border-subtle z-10 transition-transform duration-200 ${Q?"-translate-x-full":""}`,children:[F("div",{className:"px-4 pt-4 pb-3 flex-shrink-0 border-b border-border-subtle",children:[F("div",{className:"flex items-center gap-2 mb-2",children:[F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",className:"text-text-tertiary flex-shrink-0",children:F("path",{d:"M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this),F(U5,{currentSessionId:J,projectRoot:$},void 0,!1,void 0,this),F("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${Y?"bg-accent-green":"bg-accent-red"}`},void 0,!1,void 0,this),F("button",{onClick:q,className:"ml-auto w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Hide sidebar",children:F("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[F("polyline",{points:"11 17 6 12 11 7"},void 0,!1,void 0,this),F("polyline",{points:"18 17 13 12 18 7"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F(u2,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("div",{className:"flex-1 flex flex-col overflow-hidden",children:F(Y2,{embedded:!0},void 0,!1,void 0,this)},void 0,!1,void 0,this),F("div",{className:"px-4 py-3 border-t border-border-subtle flex items-center justify-between flex-shrink-0",children:[F("span",{className:"text-[10px] text-text-tertiary font-body uppercase tracking-widest",children:"Theme"},void 0,!1,void 0,this),F(g2,{},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 b4({children:J,collapsed:$,onToggle:Y}){let[Z,Q]=$1(()=>{let H=localStorage.getItem("canvas-sidebar-width");return H?parseInt(H,10):320}),q=I1(!1),X=I1(0),G=I1(0),_=I1(Z);_.current=Z;let z=u0((H)=>{H.preventDefault(),q.current=!0,X.current=H.clientX,G.current=_.current;let U=(N)=>{if(!q.current)return;let K=X.current-N.clientX,T=Math.max(240,Math.min(600,G.current+K));Q(T),_.current=T},W=()=>{q.current=!1,localStorage.setItem("canvas-sidebar-width",String(_.current)),document.removeEventListener("mousemove",U),document.removeEventListener("mouseup",W),document.body.style.cursor="",document.body.style.userSelect=""};document.addEventListener("mousemove",U),document.addEventListener("mouseup",W),document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[]);return M1(()=>{return document.documentElement.style.setProperty("--sidebar-width",`${Z}px`),()=>{document.documentElement.style.removeProperty("--sidebar-width")}},[Z]),F(E0,{children:[$&&F("button",{onClick:Y,className:"hidden lg:flex fixed top-3 right-3 z-20 w-7 h-7 items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors bg-bg-surface border border-border-subtle",title:"Show annotations",children:F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:F("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),F("div",{className:`hidden lg:flex flex-col fixed top-0 right-0 bottom-0 bg-bg-surface border-l border-border-subtle z-10 transition-transform duration-200 ${$?"translate-x-full":""}`,style:{width:Z},children:[F("div",{onMouseDown:z,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),A1.Children.map(J,(H)=>A1.isValidElement(H)?A1.cloneElement(H,{collapseButton:F("button",{onClick:Y,className:"w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Hide annotations",children:F("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[F("polyline",{points:"13 17 18 12 13 7"},void 0,!1,void 0,this),F("polyline",{points:"6 17 11 12 6 7"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}):H)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function k2({markdown:J}){let[$,Y]=$1(!1),Z=j2(()=>a.parse(J,{async:!1}),[J]),Q=I1(null),{annotations:q,addAnnotationWithId:X,removeAnnotation:G,updateAnnotation:_,addAnnotationImage:z,removeAnnotationImage:H,activeAnnotationId:U,setActiveAnnotationId:W}=e(),[N,K]=$1(null),[T,O]=$1(null),S=j2(()=>q.filter((I)=>I.filePath===q1),[q]),[L,j]=$1(J);if(J!==L)j(J),Y(!1);M1(()=>{if(!Q.current||S.length===0)return;let I=setTimeout(()=>{if(Q.current)P0(Q.current,S)},50);return()=>clearTimeout(I)},[Z,S.length]);let V=I1(null);if(M1(()=>{y0(U,V.current),V.current=U},[U]),M1(()=>{let I=Q.current;if(!I)return;let D=(R)=>{let v=R.target.closest("[data-annotation-id]");if(!v)return;R.stopPropagation();let m=v.getAttribute("data-annotation-id");if(m===U)O({anchorEl:v,annId:m});else W(m)},E=(R)=>{let v=R.target.closest("[data-annotation-id]");if(v)W(v.getAttribute("data-annotation-id"))},C=(R)=>{let v=R.target.closest("[data-annotation-id]"),m=R.relatedTarget?.closest?.("[data-annotation-id]");if(v&&!m)W(null)};return I.addEventListener("click",D),I.addEventListener("mouseover",E),I.addEventListener("mouseout",C),()=>{I.removeEventListener("click",D),I.removeEventListener("mouseover",E),I.removeEventListener("mouseout",C)}},[Z,U]),M1(()=>{let I=()=>{let D=window.getSelection();if(!D||D.isCollapsed||!D.toString().trim())return;if(!Q.current)return;let E=D.getRangeAt(0);if(!Q.current.contains(E.startContainer))return;if(E.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let C=D.toString().trim();if(C.length<2)return;let R=E.cloneRange(),v=D1(E,Q.current),m=`__pending_${Date.now()}`;try{g1(R,m)}catch{}window.getSelection()?.removeAllRanges();let c=document.querySelectorAll(`[data-annotation-id="${m}"]`),y=c[c.length-1];if(!y)return;K({anchorEl:y,tempId:m,snippet:C,ctx:v})};return document.addEventListener("mouseup",I),()=>document.removeEventListener("mouseup",I)},[]),$)return null;let M=document.getElementById("plan-scroll-container");return F("div",{className:"mb-6 rounded-lg border border-accent-blue/20 bg-accent-blue/5 relative",children:[F("button",{onClick:()=>Y(!0),className:"absolute top-2 right-2 w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",children:F("span",{className:"text-xs",children:"✕"},void 0,!1,void 0,this)},void 0,!1,void 0,this),F("div",{className:"px-4 py-3 pr-10",children:[F("div",{className:"flex items-center gap-2 mb-1.5",children:[F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-accent-blue flex-shrink-0",children:F("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this),F("span",{className:"text-[11px] font-medium uppercase tracking-widest text-accent-blue font-body",children:"Agent Response"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("div",{ref:Q,className:"prose-canvas text-sm",dangerouslySetInnerHTML:{__html:Z}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),N&&F(c1,{anchorEl:N.anchorEl,scrollContainer:M,snippet:N.snippet,truncateAt:80,onAdd:(I,D)=>{let E=U1();M0(N.tempId,E),X(E,N.snippet,I,q1,N.ctx,D),K(null)},onCancel:()=>{S0(N.tempId),K(null)}},void 0,!1,void 0,this),T&&(()=>{let I=q.find((D)=>D.id===T.annId);if(!I)return null;return F(d1,{anchorEl:T.anchorEl,scrollContainer:M,initialNote:I.note,initialImages:I.images,onUpdate:(D,E)=>{_(T.annId,D);let C=I.images||[];for(let R of E)if(!C.includes(R))z(T.annId,R);for(let R of C)if(!E.includes(R))H(T.annId,R)},onDelete:()=>{G(T.annId),W(null)},onClose:()=>O(null)},void 0,!1,void 0,this)})()]},void 0,!0,void 0,this)}function w4(){let{activeView:J,setActiveView:$,openFiles:Y,closeFile:Z,canvasFiles:Q}=A1.useContext(F1),q=A1.useContext(m2),{addAnnotationWithId:X,setActiveAnnotationId:G}=e();if(!(Q.length>1||Y.length>0))return null;return F("div",{className:"flex items-center border-b border-border-medium bg-bg-surface overflow-x-auto sticky top-0 z-10",children:[Q.length>1&&F(E0,{children:[F("button",{onClick:()=>$({type:"overview"}),className:`flex items-center gap-1.5 px-4 py-2.5 text-[13px] font-body whitespace-nowrap transition-colors relative ${J.type==="overview"?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",className:"opacity-60",children:F("path",{d:"M12 7L2 12l10 5 10-5-10-5z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this),"Overview",J.type==="overview"&&F("span",{className:"absolute bottom-0 left-3 right-3 h-[2px] bg-text-primary rounded-full"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Q.map((z,H)=>{let U=z.replace(/\.jsx$/,""),W=J.type==="canvas"&&J.filename===z;return F(A1.Fragment,{children:[F("button",{onClick:()=>$({type:"canvas",filename:z}),className:`flex items-center gap-1.5 px-4 py-2.5 text-[13px] font-body whitespace-nowrap transition-colors relative ${W?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[U,W&&F("span",{className:"absolute bottom-0 left-3 right-3 h-[2px] bg-text-primary rounded-full"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),H<Q.length-1&&F("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this)]},z,!0,void 0,this)}),Y.length>0&&F(E0,{children:[F("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this),Y.map((z,H)=>{let U=z.split("/").pop()||z,W=J.type==="file"&&J.path===z;return F(A1.Fragment,{children:[F("div",{className:"flex items-center",children:[F("button",{onClick:()=>$({type:"file",path:z}),className:`flex items-center gap-1.5 pl-3 pr-1 py-2.5 text-[13px] font-body whitespace-nowrap transition-colors relative ${W?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[F(P1,{name:U,type:"file"},void 0,!1,void 0,this),U,W&&F("span",{className:"absolute bottom-0 left-3 right-1 h-[2px] bg-text-primary rounded-full"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("button",{onClick:(N)=>{N.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),H<Y.length-1&&F("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),F("div",{className:"ml-auto flex items-center gap-1 flex-shrink-0",children:J.type==="file"&&F("button",{onClick:async()=>{let z=J.path;try{let U=await(await fetch(`/api/file?session=${q}&path=${encodeURIComponent(z)}`)).json();if(!U.error){let W=U.content.split(`
|
|
87
|
+
`),X=b1(Q,q),G=[],_=0,z=0,H=0;while(_<Q.length||z<q.length)if(H<X.length&&_<Q.length&&z<q.length&&Q[_]===X[H]&&q[z]===X[H])G.push({type:"same",line:Q[_]}),_++,z++,H++;else if(_<Q.length&&(H>=X.length||Q[_]!==X[H]))G.push({type:"removed",line:Q[_]}),_++;else if(z<q.length)G.push({type:"added",line:q[z]}),z++;let U=document.createElement("div");U.className="mt-2 bg-bg-code rounded-md overflow-hidden text-tiny font-mono",U.setAttribute("data-no-diff","true");for(let W of G){let N=document.createElement("div");if(N.className="px-3 py-0.5 whitespace-pre-wrap",W.type==="removed")N.classList.add("diff-removed"),N.textContent="- "+W.line;else if(W.type==="added")N.classList.add("diff-added"),N.textContent="+ "+W.line;else N.textContent=" "+W.line;U.appendChild(N)}return $.appendChild(U),!0}function W5(J,$,Y){let Z=document.createElement("span");Z.className="diff-block-label",Z.textContent=$,Z.style.color=Y,Z.style.backgroundColor=`color-mix(in srgb, ${Y} 12%, transparent)`,J.appendChild(Z)}import{jsxDEV as f}from"react/jsx-dev-runtime";function z4(J,$,Y){let Z=J.find((X)=>X.revision===$),Q=J.find((X)=>X.revision===Y),q=new Set;for(let X of Z?.canvasFiles||[])q.add(X.filename);for(let X of Q?.canvasFiles||[])q.add(X.filename);return[...q].sort()}function A2({initialLeft:J,initialRight:$,sessionId:Y,onExit:Z}){let[Q,q]=Q1(J),[X,G]=Q1($),[_,z]=Q1("unified"),[H,U]=Q1(!0),[W,N]=Q1(!1),{revisions:K}=_4(N1),F=g0(()=>z4(K,Q,X),[K,Q,X]),[T,M]=Q1(()=>F[0]||"plan.jsx");w1(()=>{if(!F.includes(T))M(F[0]||"plan.jsx")},[F,T]);let L=g0(()=>{return K.find((B)=>B.revision===Q)?.canvasFiles.some((B)=>B.filename===T)??!1},[K,Q,T]),j=g0(()=>{return K.find((B)=>B.revision===X)?.canvasFiles.some((B)=>B.filename===T)??!1},[K,X,T]);return f("div",{className:"flex flex-col h-screen",children:[f("div",{className:"flex items-center justify-between px-6 py-3 border-b border-border-subtle bg-bg-surface flex-shrink-0",children:[f("div",{className:"flex items-center gap-3",children:[f("span",{className:"text-[13px] font-body font-medium text-text-primary",children:"Compare"},void 0,!1,void 0,this),f(_0,{value:Q,onChange:q,accent:"red"},void 0,!1,void 0,this),f("span",{className:"text-text-tertiary text-[13px]",children:"→"},void 0,!1,void 0,this),f(_0,{value:X,onChange:G,accent:"green"},void 0,!1,void 0,this),W&&!H&&f("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),f("div",{className:"flex items-center gap-4",children:[f("div",{className:"flex items-center bg-bg-elevated rounded-md p-0.5",children:[f("button",{onClick:()=>z("unified"),className:`text-[11px] font-body px-2.5 py-1 rounded transition-colors ${_==="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),f("button",{onClick:()=>z("side-by-side"),className:`text-[11px] font-body px-2.5 py-1 rounded transition-colors ${_==="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),_==="side-by-side"&&f(G4,{},void 0,!1,void 0,this),f("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),F.length>1&&f("div",{className:"flex items-center gap-1 px-6 py-2 border-b border-border-subtle bg-bg-surface flex-shrink-0 overflow-x-auto",children:F.map((k)=>{let B=k.replace(/\.jsx$/,""),w=k===T,m=K.find((C)=>C.revision===Q)?.canvasFiles.some((C)=>C.filename===k),g=K.find((C)=>C.revision===X)?.canvasFiles.some((C)=>C.filename===k),A=!m?" (added)":!g?" (removed)":"";return f("button",{onClick:()=>M(k),className:`text-[12px] font-body px-3 py-1 rounded-md transition-colors whitespace-nowrap ${w?"bg-bg-elevated text-text-primary font-medium":"text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated"}`,children:[B,A&&f("span",{className:`ml-1 text-[10px] ${!m?"text-accent-green":"text-accent-red"}`,children:A},void 0,!1,void 0,this)]},k,!0,void 0,this)})},void 0,!1,void 0,this),!L||!j?f("div",{className:"flex-1 flex items-center justify-center",children:f("div",{className:"text-center text-text-tertiary font-body",children:[f("div",{className:"text-lg mb-2",children:!L?"New file":"Removed file"},void 0,!1,void 0,this),f("div",{className:"text-[13px]",children:[T.replace(/\.jsx$/,"")," ",!L?"was added":"was removed"," in this revision"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this):_==="unified"?f(U4,{sessionId:Y,leftRev:Q,rightRev:X,filename:T,onDiffResult:(k,B)=>{N(k),U(B)}},`unified-${Q}-${X}-${T}`,!1,void 0,this):f(K4,{sessionId:Y,leftRev:Q,rightRev:X,filename:T,onDiffResult:(k,B)=>{N(k),U(B)}},`sbs-${Q}-${X}-${T}`,!1,void 0,this)]},void 0,!0,void 0,this)}function G4(){let[J,$]=Q1(!0);return w1(()=>{return document.documentElement.dataset.syncScroll=J?"1":"0",()=>{delete document.documentElement.dataset.syncScroll}},[J]),f("label",{className:"flex items-center gap-1.5 cursor-pointer select-none",children:[f("input",{type:"checkbox",checked:J,onChange:(Y)=>$(Y.target.checked),className:"accent-accent-amber w-3.5 h-3.5"},void 0,!1,void 0,this),f("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 U4({sessionId:J,leftRev:$,rightRev:Y,filename:Z,onDiffResult:Q}){let q=L1(null),X=L1(null),G=L1(null),[_,z]=Q1(!1),[H,U]=Q1(!1),[W,N]=Q1(!1),[K,F]=Q1(null),[T,M]=Q1(!1),{annotations:L}=$1(),j=L.filter((B)=>!B.filePath&&(!B.canvasFile||B.canvasFile===Z)),{popovers:k}=g1({containerRef:G,restoreKey:W,restoreAnnotations:j,extractContext:(B)=>V1(B,G.current)});return w1(()=>{if(W||K)return;let B=setTimeout(()=>{console.warn("[unified-diff] still loading after 10s",{leftReady:_,rightReady:H,oldRef:!!q.current,newRef:!!X.current}),M(!0)},1e4);return()=>clearTimeout(B)},[W,K,_,H]),w1(()=>{if(!_||!H||W)return;if(!q.current||!X.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!q.current||!X.current||!G.current){console.warn("[unified-diff] refs lost between rAF frames",{old:!!q.current,new:!!X.current,unified:!!G.current});return}try{let B=i1(q.current),w=i1(X.current),m=G0(B,w),{fragment:g,hasChanges:A}=u0(m);G.current.innerHTML="",G.current.appendChild(g),N(!0),Q(!0,A)}catch(B){console.error("[unified-diff] diff computation failed",B),F(B instanceof Error?B.message:String(B))}})})},[_,H,W]),f("div",{className:"flex-1 min-h-0 overflow-y-auto",children:[!W&&!K&&f("div",{style:{position:"absolute",left:-9999,visibility:"hidden",pointerEvents:"none",width:720},children:[f(y1,{ref:q,sessionId:J,revision:$,filename:Z,onReady:()=>z(!0),onError:(B)=>F(`Rev ${$}: ${B}`)},void 0,!1,void 0,this),f(y1,{ref:X,sessionId:J,revision:Y,filename:Z,onReady:()=>U(!0),onError:(B)=>F(`Rev ${Y}: ${B}`)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),f("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:[!W&&!K&&f("div",{className:"flex flex-col items-center justify-center h-64 text-text-tertiary font-body text-body gap-2",children:[f("span",{children:"Loading..."},void 0,!1,void 0,this),T&&f("span",{className:"text-[11px]",children:"Taking longer than expected — check Network tab for pending requests"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),K&&f("div",{className:"bg-accent-red-muted rounded-lg p-5 mt-8",children:[f("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Failed to load revision"},void 0,!1,void 0,this),f("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:K},void 0,!1,void 0,this)]},void 0,!0,void 0,this),f("div",{ref:G},void 0,!1,void 0,this)]},void 0,!0,void 0,this),k]},void 0,!0,void 0,this)}function K4({sessionId:J,leftRev:$,rightRev:Y,filename:Z,onDiffResult:Q}){let q=L1(null),X=L1(null),[G,_]=Q1(!1),[z,H]=Q1(!1),[U,W]=Q1(!1),N=L1(null),K=L1(null),F=L1(null),T=L1(!1),M=w2(()=>_(!0),[]),L=w2(()=>H(!0),[]),{annotations:j}=$1(),k=j.filter((w)=>!w.filePath&&(!w.canvasFile||w.canvasFile===Z)),{popovers:B}=g1({containerRef:N,restoreKey:U,restoreAnnotations:k,extractContext:(w)=>V1(w,N.current)});return w1(()=>{if(!G||!z||U)return;if(!q.current||!X.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!q.current||!X.current)return;let w=m0(q.current,X.current);W(!0),Q(!0,w)})})},[G,z,U]),w1(()=>{let w=K.current,m=F.current;if(!w||!m)return;let g=(v,u)=>{if(document.documentElement.dataset.syncScroll==="0")return;if(T.current)return;T.current=!0;let l=v.scrollHeight-v.clientHeight,x=u.scrollHeight-u.clientHeight;if(l>0&&x>0)u.scrollTop=v.scrollTop/l*x;requestAnimationFrame(()=>{T.current=!1})},A=()=>g(w,m),C=()=>g(m,w);return w.addEventListener("scroll",A),m.addEventListener("scroll",C),()=>{w.removeEventListener("scroll",A),m.removeEventListener("scroll",C)}},[]),f("div",{ref:N,className:"flex flex-1 min-h-0",children:[f("div",{ref:K,className:"w-1/2 overflow-y-auto border-r border-border-subtle",children:f("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:f(y1,{ref:q,sessionId:J,revision:$,filename:Z,onReady:M},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),f("div",{ref:F,className:"w-1/2 overflow-y-auto",children:f("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:f(y1,{ref:X,sessionId:J,revision:Y,filename:Z,onReady:L},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),B]},void 0,!0,void 0,this)}var y1=b2.memo(b2.forwardRef(({sessionId:J,revision:$,filename:Y,onReady:Z,onError:Q},q)=>{let[X,G]=Q1(null),[_,z]=Q1(null),[H,U]=Q1(!0);w1(()=>{U(!0),z(null);let N=Y.replace(/\.jsx$/,".js");import(`/api/session/${J}/canvas/${encodeURIComponent(N)}?rev=${$}&t=${Date.now()}`).then((K)=>{if(!K.default){z("Module has no default export"),U(!1),Q?.("Module has no default export");return}G(()=>K.default),U(!1)}).catch((K)=>{z(K.message),U(!1),Q?.(K.message)})},[J,$,Y]),w1(()=>{if(!X)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{Z()})})},[X]);let W=g0(()=>X?f(X,{},void 0,!1,void 0,this):null,[X]);if(H)return f("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(_)return f("div",{className:"bg-accent-red-muted rounded-lg p-5",children:[f("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Error"},void 0,!1,void 0,this),f("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:_},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(!X)return f("div",{className:"text-text-tertiary text-center py-8 font-body text-body",children:"No canvas loaded"},void 0,!1,void 0,this);return f("div",{ref:q,children:W},void 0,!1,void 0,this)}));import{useState as M1,useContext as N5,useMemo as H4,useRef as U0,useEffect as C2,useCallback as I2}from"react";import{SessionContext as W4}from"#canvas/runtime";import{jsxDEV as c}from"react/jsx-dev-runtime";function T5(J,$){if(!J)return[];return J.canvasFiles.map((Y)=>{if(!Y.diffStats)return{filename:Y.filename,status:"new"};if(Y.diffStats.added===0&&Y.diffStats.removed===0)return{filename:Y.filename,status:"unchanged",diffStats:Y.diffStats};return{filename:Y.filename,status:"changed",diffStats:Y.diffStats}})}function j2(J){return J.filter(($)=>$.status!=="unchanged").map(($)=>$.filename)}function R2({revision:J,responseBanner:$}){let{setActiveView:Y}=N5(F1),{revisions:Z}=N5(N1),Q=Z.find((z)=>z.revision===J),q=Z.find((z)=>z.revision===J-1),X=H4(()=>T5(Q,q),[Q,q]),G=X.filter((z)=>z.status!=="unchanged"),_=X.filter((z)=>z.status==="unchanged");return c("div",{className:"max-w-[720px] mx-auto px-6 pt-12 pb-32",children:[$,G.map((z)=>c(T4,{change:z,revision:J,previousRevision:q?.revision,onOpenTab:()=>Y({type:"canvas",filename:z.filename})},z.filename,!1,void 0,this)),_.length>0&&c("div",{className:"mt-8 border-t border-border-subtle pt-4",children:[c("div",{className:"text-[11px] font-body font-medium uppercase tracking-widest text-text-tertiary mb-3",children:"Unchanged"},void 0,!1,void 0,this),_.map((z)=>c(y4,{change:z,revision:J,onOpenTab:()=>Y({type:"canvas",filename:z.filename})},z.filename,!1,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function N4({mode:J,onChange:$,showDiff:Y}){if(!Y)return null;return c("div",{className:"flex items-center bg-bg-elevated rounded-md p-0.5",children:["rendered","unified","side-by-side"].map((Z)=>c("button",{onClick:()=>$(Z),className:`text-[10px] font-body px-2 py-0.5 rounded transition-colors ${J===Z?"bg-bg-surface text-text-primary font-medium shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:Z==="rendered"?"Full":Z==="unified"?"Unified":"Split"},Z,!1,void 0,this))},void 0,!1,void 0,this)}function T4({change:J,revision:$,previousRevision:Y,onOpenTab:Z}){let Q=J.filename.replace(/\.jsx$/,""),q=J.status==="new",X=J.diffStats,G=J.status==="changed"&&Y!=null,[_,z]=M1("rendered");return c("div",{className:"mb-8",children:[c("div",{className:"flex items-center gap-2 mb-3 pb-2 border-b border-border-subtle",children:[c("span",{className:`text-[11px] font-mono px-1.5 py-0.5 rounded ${q?"bg-accent-green/10 text-accent-green border border-accent-green/20":"bg-accent-amber/10 text-accent-amber border border-accent-amber/20"}`,children:q?"new":"modified"},void 0,!1,void 0,this),c("span",{className:"text-[14px] font-body font-medium text-text-primary",children:Q},void 0,!1,void 0,this),X&&(X.added>0||X.removed>0)&&c("span",{className:"text-[11px] font-mono text-text-tertiary",children:[c("span",{className:"text-accent-green",children:["+",X.added]},void 0,!0,void 0,this)," ",c("span",{className:"text-accent-red",children:["-",X.removed]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),c(N4,{mode:_,onChange:z,showDiff:G},void 0,!1,void 0,this),c("button",{onClick:Z,className:`${G?"":"ml-auto"} text-[11px] font-body font-medium text-accent-blue hover:text-accent-blue/80 transition-colors`,children:"Open in tab"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),_==="rendered"?c("div",{"data-canvas-file":J.filename,children:c(Q0,{revision:$,filename:J.filename},void 0,!1,void 0,this)},void 0,!1,void 0,this):G&&Y!=null?c(O4,{filename:J.filename,leftRev:Y,rightRev:$,mode:_},`${_}-${$}-${Y}`,!1,void 0,this):null]},void 0,!0,void 0,this)}function O4({filename:J,leftRev:$,rightRev:Y,mode:Z}){let Q=N5(W4);if(Z==="unified")return c(F4,{sessionId:Q,filename:J,leftRev:$,rightRev:Y},void 0,!1,void 0,this);return c(L4,{sessionId:Q,filename:J,leftRev:$,rightRev:Y},void 0,!1,void 0,this)}function F4({sessionId:J,filename:$,leftRev:Y,rightRev:Z}){let Q=U0(null),q=U0(null),X=U0(null),[G,_]=M1(!1),[z,H]=M1(!1),[U,W]=M1(!1),[N,K]=M1(null);return C2(()=>{if(!G||!z||U)return;if(!Q.current||!q.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!Q.current||!q.current||!X.current)return;try{let F=i1(Q.current),T=i1(q.current),M=G0(F,T),{fragment:L}=u0(M);X.current.innerHTML="",X.current.appendChild(L),W(!0)}catch(F){K(F instanceof Error?F.message:String(F))}})})},[G,z,U]),c("div",{children:[!U&&!N&&c("div",{style:{position:"absolute",left:-9999,visibility:"hidden",pointerEvents:"none",width:720},children:[c(y1,{ref:Q,sessionId:J,revision:Y,filename:$,onReady:()=>_(!0),onError:(F)=>K(F)},void 0,!1,void 0,this),c(y1,{ref:q,sessionId:J,revision:Z,filename:$,onReady:()=>H(!0),onError:(F)=>K(F)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!U&&!N&&c("div",{className:"flex items-center justify-center h-24 text-text-tertiary font-body text-[13px]",children:"Computing diff..."},void 0,!1,void 0,this),N&&c("div",{className:"text-accent-red text-[13px] font-body p-3 bg-accent-red-muted rounded-lg",children:N},void 0,!1,void 0,this),c("div",{ref:X},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function L4({sessionId:J,filename:$,leftRev:Y,rightRev:Z}){let Q=U0(null),q=U0(null),[X,G]=M1(!1),[_,z]=M1(!1),[H,U]=M1(!1),W=I2(()=>G(!0),[]),N=I2(()=>z(!0),[]);return C2(()=>{if(!X||!_||H)return;if(!Q.current||!q.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!Q.current||!q.current)return;m0(Q.current,q.current),U(!0)})})},[X,_,H]),c("div",{className:"flex gap-0 border-y border-border-subtle overflow-hidden w-screen relative left-1/2 -translate-x-1/2",children:[c("div",{className:"w-1/2 border-r border-border-subtle",children:[c("div",{className:"px-2 py-1 text-[10px] font-body font-medium text-text-tertiary bg-bg-elevated border-b border-border-subtle",children:["Rev ",Y]},void 0,!0,void 0,this),c("div",{className:"px-6 py-4 max-w-[600px] mx-auto",children:c(y1,{ref:Q,sessionId:J,revision:Y,filename:$,onReady:W},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),c("div",{className:"w-1/2",children:[c("div",{className:"px-2 py-1 text-[10px] font-body font-medium text-text-tertiary bg-bg-elevated border-b border-border-subtle",children:["Rev ",Z]},void 0,!0,void 0,this),c("div",{className:"px-6 py-4 max-w-[600px] mx-auto",children:c(y1,{ref:q,sessionId:J,revision:Z,filename:$,onReady:N},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function y4({change:J,revision:$,onOpenTab:Y}){let[Z,Q]=M1(!1),q=J.filename.replace(/\.jsx$/,"");return c("div",{className:"mb-2",children:[c("div",{className:"flex items-center gap-2 py-1.5",children:[c("button",{onClick:()=>Q(!Z),className:"text-text-tertiary hover:text-text-secondary transition-colors",children:c("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",className:`transition-transform duration-150 ${Z?"rotate-90":""}`,children:c("path",{d:"M3.5 2L6.5 5L3.5 8",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),c("span",{className:"text-[13px] font-body text-text-secondary",children:q},void 0,!1,void 0,this),c("button",{onClick:Y,className:"ml-auto text-[11px] font-body text-text-tertiary hover:text-accent-blue transition-colors",children:"Open in tab"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Z&&c("div",{className:"ml-5 mt-1 mb-3","data-canvas-file":J.filename,children:c(Q0,{revision:$,filename:J.filename},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{jsxDEV as O,Fragment as v0}from"react/jsx-dev-runtime";var F1=u2({activeView:{type:"overview"},setActiveView:()=>{},openFiles:[],closeFile:()=>{},canvasFiles:[]}),N1=u2({currentRevision:1,selectedRevision:1,revisions:[],setSelectedRevision:()=>{},isReadOnly:!1,compareRevision:null,setCompareRevision:()=>{},agentWatching:!1});function S4(J){if(J==="auto")return window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light";return J}function V2(J){document.documentElement.dataset.theme=S4(J)}function E2(){let[J,$]=e(()=>{let Q=localStorage.getItem("canvas-theme");if(Q==="light"||Q==="dark"||Q==="auto")return Q;return"auto"});return B1(()=>{if(V2(J),J!=="auto")return;let Q=window.matchMedia("(prefers-color-scheme: dark)"),q=()=>V2("auto");return Q.addEventListener("change",q),()=>Q.removeEventListener("change",q)},[J]),O("button",{onClick:()=>{let Q=J==="auto"?"light":J==="light"?"dark":"auto";localStorage.setItem("canvas-theme",Q),$(Q)},className:"w-7 h-7 flex items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:{auto:"Theme: system (click for light)",light:"Theme: light (click for dark)",dark:"Theme: dark (click for system)"}[J],children:J==="auto"?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:"2",y:"3",width:"20",height:"14",rx:"2",ry:"2"},void 0,!1,void 0,this),O("line",{x1:"8",y1:"21",x2:"16",y2:"21"},void 0,!1,void 0,this),O("line",{x1:"12",y1:"17",x2:"12",y2:"21"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):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("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):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)},void 0,!1,void 0,this)}function v2(){let{currentRevision:J,selectedRevision:$,revisions:Y,setSelectedRevision:Z,setCompareRevision:Q}=A1.useContext(N1);if(Y.length<=1){let G=Y[0]?.label||`Round ${J}`;return O("span",{className:"text-[11px] text-text-tertiary font-body",children:G},void 0,!1,void 0,this)}return O("div",{className:"flex flex-col gap-1",children:[O(_0,{value:$,onChange:Z,accent:$===J?"default":"amber"},void 0,!1,void 0,this),O("button",{onClick:()=>{let X;if($===J)X=[...Y].reverse().find((_)=>_.revision<J)?.revision??Math.max(1,J-1);else X=$;Q({left:X,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 b4(){let J=window.location.pathname.replace("/s/","")||"",[$,Y]=e(1),[Z,Q]=e(1),[q,X]=e([]),[G,_]=e(null),[z,H]=e(!1),[U,W]=e(!1),[N,K]=e(!1),[F,T]=e([]),[M,L]=e({type:"overview"}),[j,k]=e([]),B=I1(null),[w,m]=e(),[g,A]=e(!1),[C,v]=e(!1),[u,l]=e(!1);B1(()=>{let P=["Agent Canvas"];if(w){let p=w.replace(/\/+$/,"").split("/");P.push(p[p.length-1]||J)}else if(J)P.push(J);if(M.type==="file")P.push(M.path.split("/").pop()||M.path);else if(M.type==="overview")P.push("Overview");else if(M.type==="canvas"&&F.length>1&&M.filename)P.push(M.filename.replace(/\.jsx$/,""));else if(G)P.push("Compare");document.title=P.join(" — ")},[J,w,M,G]);let x=I1(new Map),y=q.find((P)=>P.revision===Z),I=Z!==$||!!y?.hasFeedback,d=E0((P)=>{let p=M.type==="overview"?"overview":M.type==="canvas"?`canvas:${M.filename}`:`file:${M.path}`;if(x.current.set(p,window.scrollY),L(P),P.type==="file")k((h)=>h.includes(P.path)?h:[...h,P.path])},[M]),R=E0((P)=>{x.current.delete(`file:${P}`),k((p)=>p.filter((h)=>h!==P)),L((p)=>{if(p.type==="file"&&p.path===P)return F.length>1?{type:"overview"}:{type:"canvas",filename:F[0]||""};return p})},[F]);M4(()=>{let P=M.type==="overview"?"overview":M.type==="canvas"?`canvas:${M.filename}`:`file:${M.path}`;window.scrollTo(0,x.current.get(P)||0)},[M]),B1(()=>{if(!J)return;fetch(`/api/session/${J}/meta`).then((P)=>P.json()).then((P)=>{if(P.currentRevision)Y(P.currentRevision),Q(P.currentRevision),X(P.revisions||[]);if(P.canvasFiles){let p=P.canvasFiles.sort();T(p),L((h)=>{if(h.type==="overview")return p.length>1?h:{type:"canvas",filename:p[0]||""};if(h.type==="canvas"&&(!h.filename||!p.includes(h.filename)))return{type:"canvas",filename:p[0]||""};return h})}if(P.projectRoot)m(P.projectRoot)}).catch(()=>{})},[J]),B1(()=>{if(!J)return;let P=null,p=()=>{let h=window.location.protocol==="https:"?"wss:":"ws:",D=new WebSocket(`${h}//${window.location.host}/ws/session/${J}`);B.current=D,D.onopen=()=>H(!0),D.onclose=()=>{H(!1),P=setTimeout(p,2000)},D.onmessage=(a)=>{try{let b=JSON.parse(a.data);if(b.type==="plan-updated"){if(Y(b.currentRevision),Q(b.currentRevision),_(null),b.revisions){let E=b.revisions;X(E);let s=E.find((Z1)=>Z1.revision===b.currentRevision);if(s?.canvasFiles){let Z1=s.canvasFiles.map((x0)=>x0.filename).sort();T(Z1);let a1=E.find((x0)=>x0.revision===b.currentRevision-1),o1=T5(s,a1),C1=j2(o1);if(C1.length===1)L({type:"canvas",filename:C1[0]});else if(C1.length>1||Z1.length>1)L({type:"overview"});else L({type:"canvas",filename:Z1[0]||""})}}}if(b.type==="revision-updated"){if(b.revisions)X(b.revisions)}if(b.type==="watcher-status")W(!!b.watching)}catch{}}};return p(),()=>{if(P)clearTimeout(P);B.current?.close()}},[J]);let V=E0((P)=>{if(B.current?.readyState===WebSocket.OPEN)B.current.send(JSON.stringify({type:"submit",feedback:P})),K(!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(g2.Provider,{value:J,children:O(N1.Provider,{value:{currentRevision:$,selectedRevision:Z,revisions:q,setSelectedRevision:Q,isReadOnly:I,compareRevision:G,setCompareRevision:_,agentWatching:U},children:O(m5,{sessionId:J,revision:Z,isReadOnly:I,children:O(F1.Provider,{value:{activeView:M,setActiveView:d,openFiles:j,closeFile:R,canvasFiles:F},children:O(P4.Provider,{value:{setActiveView:d},children:O("div",{className:"min-h-screen bg-bg-base",children:[O(w4,{sessionId:J,projectRoot:w,connected:z,onMobileSidebar:()=>A(!g),collapsed:C,onToggle:()=>v((P)=>!P)},void 0,!1,void 0,this),O(A4,{collapsed:u,onToggle:()=>l((P)=>!P),children:O(G5,{onPreview:()=>K(!0),onSubmit:V},void 0,!1,void 0,this)},void 0,!1,void 0,this),G!==null?O("div",{className:`${C?"lg:ml-0":"lg:ml-60"} ${u?"lg:mr-0":"lg:mr-[var(--sidebar-width,320px)]"} transition-[margin] duration-200`,children:O(A2,{initialLeft:G.left,initialRight:G.right,sessionId:J,onExit:()=>_(null)},void 0,!1,void 0,this)},void 0,!1,void 0,this):O("div",{className:`relative ${C?"lg:ml-0":"lg:ml-60"} ${u?"lg:mr-0":"lg:mr-[var(--sidebar-width,320px)]"} transition-[margin] duration-200`,id:"plan-scroll-container",children:[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(K5,{currentSessionId:J,projectRoot:w},void 0,!1,void 0,this),O("span",{className:`w-1.5 h-1.5 rounded-full ${z?"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(v2,{},void 0,!1,void 0,this),O("button",{onClick:()=>A(!g),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(E2,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),O(I4,{},void 0,!1,void 0,this),M.type==="overview"&&O(R2,{revision:Z,responseBanner:y?.response?O(D2,{markdown:y.response},void 0,!1,void 0,this):void 0},void 0,!1,void 0,this),M.type==="canvas"&&F.includes(M.filename)&&O("div",{className:"relative max-w-[720px] mx-auto px-6 pt-12 pb-32",children:[O("button",{onClick:()=>{let P=document.querySelector(`[data-canvas-file="${M.filename}"] .plan-content`);if(!P)return;let p=H2(P);navigator.clipboard.writeText(p).then(()=>{let h=document.getElementById("export-md-btn");if(h)h.setAttribute("data-copied","true"),setTimeout(()=>{h.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),F.length<=1&&y?.response&&O(D2,{markdown:y.response},void 0,!1,void 0,this),O("div",{"data-canvas-file":M.filename,children:O(Q0,{revision:Z,filename:M.filename},M.filename,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),j.map((P)=>O("div",{style:{display:M.type==="file"&&M.path===P?void 0:"none"},children:O(z2,{path:P},void 0,!1,void 0,this)},P,!1,void 0,this))]},void 0,!0,void 0,this),g&&O("div",{className:"lg:hidden fixed inset-0 z-40 flex",children:[O("div",{className:"flex-1",onClick:()=>A(!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:()=>A(!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(G5,{onPreview:()=>K(!0),onSubmit:V},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(s5,{open:N,onClose:()=>K(!1),onSubmit:V},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 w4({sessionId:J,projectRoot:$,connected:Y,onMobileSidebar:Z,collapsed:Q,onToggle:q}){return O(v0,{children:[Q&&O("button",{onClick:q,className:"hidden lg:flex fixed top-3 left-3 z-20 w-7 h-7 items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors bg-bg-surface border border-border-subtle",title:"Show sidebar",children: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 ${Q?"-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(K5,{currentSessionId:J,projectRoot:$},void 0,!1,void 0,this),O("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${Y?"bg-accent-green":"bg-accent-red"}`},void 0,!1,void 0,this),O("button",{onClick:q,className:"ml-auto w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Hide sidebar",children: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(v2,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this),O("div",{className:"flex-1 flex flex-col overflow-hidden",children:O(Z2,{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(E2,{},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 A4({children:J,collapsed:$,onToggle:Y}){let[Z,Q]=e(()=>{let H=localStorage.getItem("canvas-sidebar-width");return H?parseInt(H,10):320}),q=I1(!1),X=I1(0),G=I1(0),_=I1(Z);_.current=Z;let z=E0((H)=>{H.preventDefault(),q.current=!0,X.current=H.clientX,G.current=_.current;let U=(N)=>{if(!q.current)return;let K=X.current-N.clientX,F=Math.max(240,Math.min(600,G.current+K));Q(F),_.current=F},W=()=>{q.current=!1,localStorage.setItem("canvas-sidebar-width",String(_.current)),document.removeEventListener("mousemove",U),document.removeEventListener("mouseup",W),document.body.style.cursor="",document.body.style.userSelect=""};document.addEventListener("mousemove",U),document.addEventListener("mouseup",W),document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[]);return B1(()=>{return document.documentElement.style.setProperty("--sidebar-width",`${Z}px`),()=>{document.documentElement.style.removeProperty("--sidebar-width")}},[Z]),O(v0,{children:[$&&O("button",{onClick:Y,className:"hidden lg:flex fixed top-3 right-3 z-20 w-7 h-7 items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors bg-bg-surface border border-border-subtle",title:"Show annotations",children: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:z,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),A1.Children.map(J,(H)=>A1.isValidElement(H)?A1.cloneElement(H,{collapseButton:O("button",{onClick:Y,className:"w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Hide annotations",children: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)}):H)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function D2({markdown:J}){let[$,Y]=e(!1),Z=k2(()=>o.parse(J,{async:!1}),[J]),Q=I1(null),{annotations:q,addAnnotationWithId:X,removeAnnotation:G,updateAnnotation:_,addAnnotationImage:z,removeAnnotationImage:H,activeAnnotationId:U,setActiveAnnotationId:W}=$1(),[N,K]=e(null),[F,T]=e(null),M=k2(()=>q.filter((w)=>w.filePath===_1),[q]),[L,j]=e(J);if(J!==L)j(J),Y(!1);B1(()=>{if(!Q.current||M.length===0)return;let w=setTimeout(()=>{if(Q.current)S0(Q.current,M)},50);return()=>clearTimeout(w)},[Z,M.length]);let k=I1(null);if(B1(()=>{B0(U,k.current),k.current=U},[U]),B1(()=>{let w=Q.current;if(!w)return;let m=(C)=>{let v=C.target.closest("[data-annotation-id]");if(!v)return;C.stopPropagation();let u=v.getAttribute("data-annotation-id");if(u===U)T({anchorEl:v,annId:u});else W(u)},g=(C)=>{let v=C.target.closest("[data-annotation-id]");if(v)W(v.getAttribute("data-annotation-id"))},A=(C)=>{let v=C.target.closest("[data-annotation-id]"),u=C.relatedTarget?.closest?.("[data-annotation-id]");if(v&&!u)W(null)};return w.addEventListener("click",m),w.addEventListener("mouseover",g),w.addEventListener("mouseout",A),()=>{w.removeEventListener("click",m),w.removeEventListener("mouseover",g),w.removeEventListener("mouseout",A)}},[Z,U]),B1(()=>{let w=()=>{let m=window.getSelection();if(!m||m.isCollapsed||!m.toString().trim())return;if(!Q.current)return;let g=m.getRangeAt(0);if(!Q.current.contains(g.startContainer))return;if(g.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let A=m.toString().trim();if(A.length<2)return;let C=g.cloneRange(),v=V1(g,Q.current),u=`__pending_${Date.now()}`;try{m1(C,u)}catch{}window.getSelection()?.removeAllRanges();let l=document.querySelectorAll(`[data-annotation-id="${u}"]`),x=l[l.length-1];if(!x)return;K({anchorEl:x,tempId:u,snippet:A,ctx:v})};return document.addEventListener("mouseup",w),()=>document.removeEventListener("mouseup",w)},[]),$)return null;let B=document.getElementById("plan-scroll-container");return O("div",{className:"mb-6 rounded-lg border border-accent-blue/20 bg-accent-blue/5 relative",children:[O("button",{onClick:()=>Y(!0),className:"absolute top-2 right-2 w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",children: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",{ref:Q,className:"prose-canvas text-sm",dangerouslySetInnerHTML:{__html:Z}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),N&&O(p1,{anchorEl:N.anchorEl,scrollContainer:B,snippet:N.snippet,truncateAt:80,onAdd:(w,m)=>{let g=U1();P0(N.tempId,g),X(g,N.snippet,w,_1,N.ctx,m),K(null)},onCancel:()=>{b0(N.tempId),K(null)}},void 0,!1,void 0,this),F&&(()=>{let w=q.find((m)=>m.id===F.annId);if(!w)return null;return O(c1,{anchorEl:F.anchorEl,scrollContainer:B,initialNote:w.note,initialImages:w.images,onUpdate:(m,g)=>{_(F.annId,m);let A=w.images||[];for(let C of g)if(!A.includes(C))z(F.annId,C);for(let C of A)if(!g.includes(C))H(F.annId,C)},onDelete:()=>{G(F.annId),W(null)},onClose:()=>T(null)},void 0,!1,void 0,this)})()]},void 0,!0,void 0,this)}function I4(){let{activeView:J,setActiveView:$,openFiles:Y,closeFile:Z,canvasFiles:Q}=A1.useContext(F1),q=A1.useContext(g2),{addAnnotationWithId:X,setActiveAnnotationId:G}=$1();if(!(Q.length>1||Y.length>0))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:[Q.length>1&&O(v0,{children:[O("button",{onClick:()=>$({type:"overview"}),className:`flex items-center gap-1.5 px-4 py-2.5 text-[13px] font-body whitespace-nowrap transition-colors relative ${J.type==="overview"?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[O("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",className:"opacity-60",children:O("path",{d:"M12 7L2 12l10 5 10-5-10-5z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this),"Overview",J.type==="overview"&&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("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Q.map((z,H)=>{let U=z.replace(/\.jsx$/,""),W=J.type==="canvas"&&J.filename===z;return O(A1.Fragment,{children:[O("button",{onClick:()=>$({type:"canvas",filename:z}),className:`flex items-center gap-1.5 px-4 py-2.5 text-[13px] font-body whitespace-nowrap transition-colors relative ${W?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[U,W&&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),H<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)}),Y.length>0&&O(v0,{children:[O("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this),Y.map((z,H)=>{let U=z.split("/").pop()||z,W=J.type==="file"&&J.path===z;return O(A1.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-body whitespace-nowrap transition-colors relative ${W?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[O(P1,{name:U,type:"file"},void 0,!1,void 0,this),U,W&&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:(N)=>{N.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),H<Y.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=${q}&path=${encodeURIComponent(z)}`)).json();if(!U.error){let W=U.content.split(`
|
|
88
88
|
`).slice(0,3).join(`
|
|
89
89
|
`)+(U.content.split(`
|
|
90
90
|
`).length>3?`
|
|
91
|
-
...`:""),N=U1();X(N,W,"",z),G(N)}}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:[
|
|
91
|
+
...`:""),N=U1();X(N,W,"",z),G(N)}}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 m2=document.getElementById("root");if(m2)B4(m2).render(O(b4,{},void 0,!1,void 0,this));export{N1 as RevisionContext,F1 as ActiveViewContext};
|