agent-canvas 0.1.42 → 0.1.44
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/lib/helpers.test.ts +30 -0
- package/bin/lib/helpers.ts +27 -0
- package/bin/lib/instructions/overview.md +5 -0
- package/daemon/client/AnnotationProvider.tsx +32 -28
- package/daemon/client/App.tsx +43 -12
- package/daemon/client/PlanRenderer.tsx +67 -10
- package/daemon/client/RenderErrorContext.ts +11 -0
- package/daemon/client/annotationDraft.test.ts +41 -2
- package/daemon/client/annotationDraft.ts +27 -7
- package/daemon/dist/client.js +40 -40
- package/daemon/src/compiler.test.ts +13 -0
- package/daemon/src/compiler.ts +39 -5
- package/daemon/src/websocket.test.ts +99 -0
- package/daemon/src/websocket.ts +64 -10
- package/package.json +1 -1
- package/workers/canvas-share/public/assets/client.js +40 -40
package/daemon/dist/client.js
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import
|
|
2
|
-
]`).replace("lheading",
|
|
1
|
+
import c1,{useEffect as y1,useLayoutEffect as k6,useState as J1,useCallback as T0,useRef as V1,createContext as k5,useMemo as C5}from"react";import{createRoot as E6}from"react-dom/client";function B2(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var i1=B2();function X3(Z){i1=Z}var l1={exec:()=>null};function n(Z,$=""){let q=typeof Z=="string"?Z:Z.source,Q={replace:(J,Y)=>{let X=typeof Y=="string"?Y:Y.source;return X=X.replace(K1.caret,"$1"),q=q.replace(J,X),Q},getRegex:()=>new RegExp(q,$)};return Q}var f5=(()=>{try{return!!new RegExp("(?<=1)(?<!1)")}catch{return!1}})(),K1={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:(Z)=>new RegExp(`^( {0,3}${Z})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:(Z)=>new RegExp(`^ {0,${Math.min(3,Z-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:(Z)=>new RegExp(`^ {0,${Math.min(3,Z-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:(Z)=>new RegExp(`^ {0,${Math.min(3,Z-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:(Z)=>new RegExp(`^ {0,${Math.min(3,Z-1)}}#`),htmlBeginRegex:(Z)=>new RegExp(`^ {0,${Math.min(3,Z-1)}}<(?:[a-z].*>|!--)`,"i"),blockquoteBeginRegex:(Z)=>new RegExp(`^ {0,${Math.min(3,Z-1)}}>`)},v5=/^(?:[ \t]*(?:\n|$))+/,h5=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,p5=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,P0=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,c5=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,F2=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,z3=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,_3=n(z3).replace(/bull/g,F2).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(),d5=n(z3).replace(/bull/g,F2).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(),L2=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,l5=/^[^\n]+/,M2=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,r5=n(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",M2).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),i5=n(/^(bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,F2).getRegex(),v0="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",P2=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,a5=n("^ {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",P2).replace("tag",v0).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),G3=n(L2).replace("hr",P0).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",v0).getRegex(),o5=n(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",G3).getRegex(),y2={blockquote:o5,code:h5,def:r5,fences:p5,heading:c5,hr:P0,html:a5,lheading:_3,list:i5,newline:v5,paragraph:G3,table:l1,text:l5},$3=n("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",P0).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",v0).getRegex(),s5={...y2,lheading:d5,table:$3,paragraph:n(L2).replace("hr",P0).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",$3).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",v0).getRegex()},t5={...y2,html:n(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",P2).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:l1,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:n(L2).replace("hr",P0).replace("heading",` *#{1,6} *[^
|
|
2
|
+
]`).replace("lheading",_3).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},n5=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,e5=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,U3=/^( {2,}|\\)\n(?!\s*$)/,$8=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,Y0=/[\p{P}\p{S}]/u,h0=/[\s\p{P}\p{S}]/u,S2=/[^\s\p{P}\p{S}]/u,Z8=n(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,h0).getRegex(),K3=/(?!~)[\p{P}\p{S}]/u,q8=/(?!~)[\s\p{P}\p{S}]/u,J8=/(?:[^\s\p{P}\p{S}]|~)/u,Q8=n(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",f5?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),H3=/^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/,Y8=n(H3,"u").replace(/punct/g,Y0).getRegex(),X8=n(H3,"u").replace(/punct/g,K3).getRegex(),W3="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",z8=n(W3,"gu").replace(/notPunctSpace/g,S2).replace(/punctSpace/g,h0).replace(/punct/g,Y0).getRegex(),_8=n(W3,"gu").replace(/notPunctSpace/g,J8).replace(/punctSpace/g,q8).replace(/punct/g,K3).getRegex(),G8=n("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,S2).replace(/punctSpace/g,h0).replace(/punct/g,Y0).getRegex(),U8=n(/^~~?(?:((?!~)punct)|[^\s~])/,"u").replace(/punct/g,Y0).getRegex(),K8="^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)",H8=n(K8,"gu").replace(/notPunctSpace/g,S2).replace(/punctSpace/g,h0).replace(/punct/g,Y0).getRegex(),W8=n(/\\(punct)/,"gu").replace(/punct/g,Y0).getRegex(),T8=n(/^<(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(),N8=n(P2).replace("(?:-->|$)","-->").getRegex(),O8=n("^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",N8).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),u0=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/,B8=n(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace("label",u0).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),T3=n(/^!?\[(label)\]\[(ref)\]/).replace("label",u0).replace("ref",M2).getRegex(),N3=n(/^!?\[(ref)\](?:\[\])?/).replace("ref",M2).getRegex(),F8=n("reflink|nolink(?!\\()","g").replace("reflink",T3).replace("nolink",N3).getRegex(),Z3=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,b2={_backpedal:l1,anyPunctuation:W8,autolink:T8,blockSkip:Q8,br:U3,code:e5,del:l1,delLDelim:l1,delRDelim:l1,emStrongLDelim:Y8,emStrongRDelimAst:z8,emStrongRDelimUnd:G8,escape:n5,link:B8,nolink:N3,punctuation:Z8,reflink:T3,reflinkSearch:F8,tag:O8,text:$8,url:l1},L8={...b2,link:n(/^!?\[(label)\]\((.*?)\)/).replace("label",u0).getRegex(),reflink:n(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",u0).getRegex()},O2={...b2,emStrongRDelimAst:_8,emStrongLDelim:X8,delLDelim:U8,delRDelim:H8,url:n(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol",Z3).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:n(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace("protocol",Z3).getRegex()},M8={...O2,br:n(U3).replace("{2,}","*").getRegex(),text:n(O2.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},m0={normal:y2,gfm:s5,pedantic:t5},F0={normal:b2,gfm:O2,breaks:M8,pedantic:L8},P8={"&":"&","<":"<",">":">",'"':""","'":"'"},q3=(Z)=>P8[Z];function b1(Z,$){if($){if(K1.escapeTest.test(Z))return Z.replace(K1.escapeReplace,q3)}else if(K1.escapeTestNoEncode.test(Z))return Z.replace(K1.escapeReplaceNoEncode,q3);return Z}function J3(Z){try{Z=encodeURI(Z).replace(K1.percentDecode,"%")}catch{return null}return Z}function Q3(Z,$){let q=Z.replace(K1.findPipe,(Y,X,G)=>{let z=!1,_=X;for(;--_>=0&&G[_]==="\\";)z=!z;return z?"|":" |"}),Q=q.split(K1.splitPipe),J=0;if(Q[0].trim()||Q.shift(),Q.length>0&&!Q.at(-1)?.trim()&&Q.pop(),$)if(Q.length>$)Q.splice($);else for(;Q.length<$;)Q.push("");for(;J<Q.length;J++)Q[J]=Q[J].trim().replace(K1.slashPipe,"|");return Q}function L0(Z,$,q){let Q=Z.length;if(Q===0)return"";let J=0;for(;J<Q;){let Y=Z.charAt(Q-J-1);if(Y===$&&!q)J++;else if(Y!==$&&q)J++;else break}return Z.slice(0,Q-J)}function y8(Z,$){if(Z.indexOf($[1])===-1)return-1;let q=0;for(let Q=0;Q<Z.length;Q++)if(Z[Q]==="\\")Q++;else if(Z[Q]===$[0])q++;else if(Z[Q]===$[1]&&(q--,q<0))return Q;return q>0?-2:-1}function S8(Z,$=0){let q=$,Q="";for(let J of Z)if(J==="\t"){let Y=4-q%4;Q+=" ".repeat(Y),q+=Y}else Q+=J,q++;return Q}function Y3(Z,$,q,Q,J){let Y=$.href,X=$.title||null,G=Z[1].replace(J.other.outputLinkReplace,"$1");Q.state.inLink=!0;let z={type:Z[0].charAt(0)==="!"?"image":"link",raw:q,href:Y,title:X,text:G,tokens:Q.inlineTokens(G)};return Q.state.inLink=!1,z}function b8(Z,$,q){let Q=Z.match(q.other.indentCodeCompensation);if(Q===null)return $;let J=Q[1];return $.split(`
|
|
3
3
|
`).map((Y)=>{let X=Y.match(q.other.beginningSpace);if(X===null)return Y;let[G]=X;return G.length>=J.length?Y.slice(J.length):Y}).join(`
|
|
4
|
-
`)}var
|
|
5
|
-
`)}}}fences(Z){let $=this.rules.block.fences.exec(Z);if($){let q=$[0],Q=
|
|
6
|
-
`)}}blockquote(Z){let $=this.rules.block.blockquote.exec(Z);if($){let q=
|
|
4
|
+
`)}var g0=class{options;rules;lexer;constructor(Z){this.options=Z||i1}space(Z){let $=this.rules.block.newline.exec(Z);if($&&$[0].length>0)return{type:"space",raw:$[0]}}code(Z){let $=this.rules.block.code.exec(Z);if($){let q=$[0].replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:$[0],codeBlockStyle:"indented",text:this.options.pedantic?q:L0(q,`
|
|
5
|
+
`)}}}fences(Z){let $=this.rules.block.fences.exec(Z);if($){let q=$[0],Q=b8(q,$[3]||"",this.rules);return{type:"code",raw:q,lang:$[2]?$[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):$[2],text:Q}}}heading(Z){let $=this.rules.block.heading.exec(Z);if($){let q=$[2].trim();if(this.rules.other.endingHash.test(q)){let Q=L0(q,"#");(this.options.pedantic||!Q||this.rules.other.endingSpaceChar.test(Q))&&(q=Q.trim())}return{type:"heading",raw:$[0],depth:$[1].length,text:q,tokens:this.lexer.inline(q)}}}hr(Z){let $=this.rules.block.hr.exec(Z);if($)return{type:"hr",raw:L0($[0],`
|
|
6
|
+
`)}}blockquote(Z){let $=this.rules.block.blockquote.exec(Z);if($){let q=L0($[0],`
|
|
7
7
|
`).split(`
|
|
8
8
|
`),Q="",J="",Y=[];for(;q.length>0;){let X=!1,G=[],z;for(z=0;z<q.length;z++)if(this.rules.other.blockquoteStart.test(q[z]))G.push(q[z]),X=!0;else if(!X)G.push(q[z]);else break;q=q.slice(z);let _=G.join(`
|
|
9
9
|
`),H=_.replace(this.rules.other.blockquoteSetextReplace,`
|
|
10
10
|
$1`).replace(this.rules.other.blockquoteSetextReplace2,"");Q=Q?`${Q}
|
|
11
11
|
${_}`:_,J=J?`${J}
|
|
12
|
-
${H}`:H;let U=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(H,Y,!0),this.lexer.state.top=U,q.length===0)break;let
|
|
12
|
+
${H}`:H;let U=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(H,Y,!0),this.lexer.state.top=U,q.length===0)break;let W=Y.at(-1);if(W?.type==="code")break;if(W?.type==="blockquote"){let T=W,K=T.raw+`
|
|
13
13
|
`+q.join(`
|
|
14
|
-
`),
|
|
14
|
+
`),L=this.blockquote(K);Y[Y.length-1]=L,Q=Q.substring(0,Q.length-T.raw.length)+L.raw,J=J.substring(0,J.length-T.text.length)+L.text;break}else if(W?.type==="list"){let T=W,K=T.raw+`
|
|
15
15
|
`+q.join(`
|
|
16
|
-
`),
|
|
17
|
-
`);continue}}return{type:"blockquote",raw:Q,tokens:Y,text:J}}}list(Z){let $=this.rules.block.list.exec(Z);if($){let q=$[1].trim(),Q=q.length>1,J={type:"list",raw:"",ordered:Q,start:Q?+q.slice(0,-1):"",loose:!1,items:[]};q=Q?`\\d{1,9}\\${q.slice(-1)}`:`\\${q}`,this.options.pedantic&&(q=Q?q:"[*+-]");let Y=this.rules.other.listItemRegex(q),X=!1;for(;Z;){let z=!1,_="",H="";if(!($=Y.exec(Z))||this.rules.block.hr.test(Z))break;_=$[0],Z=Z.substring(_.length);let U=
|
|
18
|
-
`,1)[0],$[1].length),
|
|
19
|
-
`,1)[0],
|
|
20
|
-
`,Z=Z.substring(
|
|
21
|
-
`,1)[0],
|
|
22
|
-
`+
|
|
23
|
-
`+T
|
|
24
|
-
`,Z=Z.substring(M.length+1),U=
|
|
25
|
-
`):[],Y={type:"table",raw:$[0],header:[],align:[],rows:[]};if(q.length===Q.length){for(let X of Q)this.rules.other.tableAlignRight.test(X)?Y.align.push("right"):this.rules.other.tableAlignCenter.test(X)?Y.align.push("center"):this.rules.other.tableAlignLeft.test(X)?Y.align.push("left"):Y.align.push(null);for(let X=0;X<q.length;X++)Y.header.push({text:q[X],tokens:this.lexer.inline(q[X]),header:!0,align:Y.align[X]});for(let X of J)Y.rows.push(
|
|
26
|
-
`?$[1].slice(0,-1):$[1];return{type:"paragraph",raw:$[0],text:q,tokens:this.lexer.inline(q)}}}text(Z){let $=this.rules.block.text.exec(Z);if($)return{type:"text",raw:$[0],text:$[0],tokens:this.lexer.inline($[0])}}escape(Z){let $=this.rules.inline.escape.exec(Z);if($)return{type:"escape",raw:$[0],text:$[1]}}tag(Z){let $=this.rules.inline.tag.exec(Z);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(Z){let $=this.rules.inline.link.exec(Z);if($){let q=$[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(q)){if(!this.rules.other.endAngleBracket.test(q))return;let Y=
|
|
16
|
+
`),L=this.list(K);Y[Y.length-1]=L,Q=Q.substring(0,Q.length-W.raw.length)+L.raw,J=J.substring(0,J.length-T.raw.length)+L.raw,q=K.substring(Y.at(-1).raw.length).split(`
|
|
17
|
+
`);continue}}return{type:"blockquote",raw:Q,tokens:Y,text:J}}}list(Z){let $=this.rules.block.list.exec(Z);if($){let q=$[1].trim(),Q=q.length>1,J={type:"list",raw:"",ordered:Q,start:Q?+q.slice(0,-1):"",loose:!1,items:[]};q=Q?`\\d{1,9}\\${q.slice(-1)}`:`\\${q}`,this.options.pedantic&&(q=Q?q:"[*+-]");let Y=this.rules.other.listItemRegex(q),X=!1;for(;Z;){let z=!1,_="",H="";if(!($=Y.exec(Z))||this.rules.block.hr.test(Z))break;_=$[0],Z=Z.substring(_.length);let U=S8($[2].split(`
|
|
18
|
+
`,1)[0],$[1].length),W=Z.split(`
|
|
19
|
+
`,1)[0],T=!U.trim(),K=0;if(this.options.pedantic?(K=2,H=U.trimStart()):T?K=$[1].length+1:(K=U.search(this.rules.other.nonSpaceChar),K=K>4?1:K,H=U.slice(K),K+=$[1].length),T&&this.rules.other.blankLine.test(W)&&(_+=W+`
|
|
20
|
+
`,Z=Z.substring(W.length+1),z=!0),!z){let L=this.rules.other.nextBulletRegex(K),N=this.rules.other.hrRegex(K),S=this.rules.other.fencesBeginRegex(K),O=this.rules.other.headingBeginRegex(K),R=this.rules.other.htmlBeginRegex(K),b=this.rules.other.blockquoteBeginRegex(K);for(;Z;){let M=Z.split(`
|
|
21
|
+
`,1)[0],j;if(W=M,this.options.pedantic?(W=W.replace(this.rules.other.listReplaceNesting," "),j=W):j=W.replace(this.rules.other.tabCharGlobal," "),S.test(W)||O.test(W)||R.test(W)||b.test(W)||L.test(W)||N.test(W))break;if(j.search(this.rules.other.nonSpaceChar)>=K||!W.trim())H+=`
|
|
22
|
+
`+j.slice(K);else{if(T||U.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||S.test(U)||O.test(U)||N.test(U))break;H+=`
|
|
23
|
+
`+W}T=!W.trim(),_+=M+`
|
|
24
|
+
`,Z=Z.substring(M.length+1),U=j.slice(K)}}J.loose||(X?J.loose=!0:this.rules.other.doubleBlankLine.test(_)&&(X=!0)),J.items.push({type:"list_item",raw:_,task:!!this.options.gfm&&this.rules.other.listIsTask.test(H),loose:!1,text:H,tokens:[]}),J.raw+=_}let G=J.items.at(-1);if(G)G.raw=G.raw.trimEnd(),G.text=G.text.trimEnd();else return;J.raw=J.raw.trimEnd();for(let z of J.items){if(this.lexer.state.top=!1,z.tokens=this.lexer.blockTokens(z.text,[]),z.task){if(z.text=z.text.replace(this.rules.other.listReplaceTask,""),z.tokens[0]?.type==="text"||z.tokens[0]?.type==="paragraph"){z.tokens[0].raw=z.tokens[0].raw.replace(this.rules.other.listReplaceTask,""),z.tokens[0].text=z.tokens[0].text.replace(this.rules.other.listReplaceTask,"");for(let H=this.lexer.inlineQueue.length-1;H>=0;H--)if(this.rules.other.listIsTask.test(this.lexer.inlineQueue[H].src)){this.lexer.inlineQueue[H].src=this.lexer.inlineQueue[H].src.replace(this.rules.other.listReplaceTask,"");break}}let _=this.rules.other.listTaskCheckbox.exec(z.raw);if(_){let H={type:"checkbox",raw:_[0]+" ",checked:_[0]!=="[ ]"};z.checked=H.checked,J.loose?z.tokens[0]&&["paragraph","text"].includes(z.tokens[0].type)&&"tokens"in z.tokens[0]&&z.tokens[0].tokens?(z.tokens[0].raw=H.raw+z.tokens[0].raw,z.tokens[0].text=H.raw+z.tokens[0].text,z.tokens[0].tokens.unshift(H)):z.tokens.unshift({type:"paragraph",raw:H.raw,text:H.raw,tokens:[H]}):z.tokens.unshift(H)}}if(!J.loose){let _=z.tokens.filter((U)=>U.type==="space"),H=_.length>0&&_.some((U)=>this.rules.other.anyLine.test(U.raw));J.loose=H}}if(J.loose)for(let z of J.items){z.loose=!0;for(let _ of z.tokens)_.type==="text"&&(_.type="paragraph")}return J}}html(Z){let $=this.rules.block.html.exec(Z);if($)return{type:"html",block:!0,raw:$[0],pre:$[1]==="pre"||$[1]==="script"||$[1]==="style",text:$[0]}}def(Z){let $=this.rules.block.def.exec(Z);if($){let q=$[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal," "),Q=$[2]?$[2].replace(this.rules.other.hrefBrackets,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",J=$[3]?$[3].substring(1,$[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):$[3];return{type:"def",tag:q,raw:$[0],href:Q,title:J}}}table(Z){let $=this.rules.block.table.exec(Z);if(!$||!this.rules.other.tableDelimiter.test($[2]))return;let q=Q3($[1]),Q=$[2].replace(this.rules.other.tableAlignChars,"").split("|"),J=$[3]?.trim()?$[3].replace(this.rules.other.tableRowBlankLine,"").split(`
|
|
25
|
+
`):[],Y={type:"table",raw:$[0],header:[],align:[],rows:[]};if(q.length===Q.length){for(let X of Q)this.rules.other.tableAlignRight.test(X)?Y.align.push("right"):this.rules.other.tableAlignCenter.test(X)?Y.align.push("center"):this.rules.other.tableAlignLeft.test(X)?Y.align.push("left"):Y.align.push(null);for(let X=0;X<q.length;X++)Y.header.push({text:q[X],tokens:this.lexer.inline(q[X]),header:!0,align:Y.align[X]});for(let X of J)Y.rows.push(Q3(X,Y.header.length).map((G,z)=>({text:G,tokens:this.lexer.inline(G),header:!1,align:Y.align[z]})));return Y}}lheading(Z){let $=this.rules.block.lheading.exec(Z);if($){let q=$[1].trim();return{type:"heading",raw:$[0],depth:$[2].charAt(0)==="="?1:2,text:q,tokens:this.lexer.inline(q)}}}paragraph(Z){let $=this.rules.block.paragraph.exec(Z);if($){let q=$[1].charAt($[1].length-1)===`
|
|
26
|
+
`?$[1].slice(0,-1):$[1];return{type:"paragraph",raw:$[0],text:q,tokens:this.lexer.inline(q)}}}text(Z){let $=this.rules.block.text.exec(Z);if($)return{type:"text",raw:$[0],text:$[0],tokens:this.lexer.inline($[0])}}escape(Z){let $=this.rules.inline.escape.exec(Z);if($)return{type:"escape",raw:$[0],text:$[1]}}tag(Z){let $=this.rules.inline.tag.exec(Z);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(Z){let $=this.rules.inline.link.exec(Z);if($){let q=$[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(q)){if(!this.rules.other.endAngleBracket.test(q))return;let Y=L0(q.slice(0,-1),"\\");if((q.length-Y.length)%2===0)return}else{let Y=y8($[2],"()");if(Y===-2)return;if(Y>-1){let X=($[0].indexOf("!")===0?5:4)+$[1].length+Y;$[2]=$[2].substring(0,Y),$[0]=$[0].substring(0,X).trim(),$[3]=""}}let Q=$[2],J="";if(this.options.pedantic){let Y=this.rules.other.pedanticHrefTitle.exec(Q);Y&&(Q=Y[1],J=Y[3])}else J=$[3]?$[3].slice(1,-1):"";return Q=Q.trim(),this.rules.other.startAngleBracket.test(Q)&&(this.options.pedantic&&!this.rules.other.endAngleBracket.test(q)?Q=Q.slice(1):Q=Q.slice(1,-1)),Y3($,{href:Q&&Q.replace(this.rules.inline.anyPunctuation,"$1"),title:J&&J.replace(this.rules.inline.anyPunctuation,"$1")},$[0],this.lexer,this.rules)}}reflink(Z,$){let q;if((q=this.rules.inline.reflink.exec(Z))||(q=this.rules.inline.nolink.exec(Z))){let Q=(q[2]||q[1]).replace(this.rules.other.multipleSpaceGlobal," "),J=$[Q.toLowerCase()];if(!J){let Y=q[0].charAt(0);return{type:"text",raw:Y,text:Y}}return Y3(q,J,q[0],this.lexer,this.rules)}}emStrong(Z,$,q=""){let Q=this.rules.inline.emStrongLDelim.exec(Z);if(!Q||!Q[1]&&!Q[2]&&!Q[3]&&!Q[4]||Q[4]&&q.match(this.rules.other.unicodeAlphaNumeric))return;if(!(Q[1]||Q[3])||!q||this.rules.inline.punctuation.exec(q)){let J=[...Q[0]].length-1,Y,X,G=J,z=0,_=Q[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(_.lastIndex=0,$=$.slice(-1*Z.length+J);(Q=_.exec($))!==null;){if(Y=Q[1]||Q[2]||Q[3]||Q[4]||Q[5]||Q[6],!Y)continue;if(X=[...Y].length,Q[3]||Q[4]){G+=X;continue}else if((Q[5]||Q[6])&&J%3&&!((J+X)%3)){z+=X;continue}if(G-=X,G>0)continue;X=Math.min(X,X+G+z);let H=[...Q[0]][0].length,U=Z.slice(0,J+Q.index+H+X);if(Math.min(J,X)%2){let T=U.slice(1,-1);return{type:"em",raw:U,text:T,tokens:this.lexer.inlineTokens(T)}}let W=U.slice(2,-2);return{type:"strong",raw:U,text:W,tokens:this.lexer.inlineTokens(W)}}}}codespan(Z){let $=this.rules.inline.code.exec(Z);if($){let q=$[2].replace(this.rules.other.newLineCharGlobal," "),Q=this.rules.other.nonSpaceChar.test(q),J=this.rules.other.startingSpaceChar.test(q)&&this.rules.other.endingSpaceChar.test(q);return Q&&J&&(q=q.substring(1,q.length-1)),{type:"codespan",raw:$[0],text:q}}}br(Z){let $=this.rules.inline.br.exec(Z);if($)return{type:"br",raw:$[0]}}del(Z,$,q=""){let Q=this.rules.inline.delLDelim.exec(Z);if(!Q)return;if(!Q[1]||!q||this.rules.inline.punctuation.exec(q)){let J=[...Q[0]].length-1,Y,X,G=J,z=this.rules.inline.delRDelim;for(z.lastIndex=0,$=$.slice(-1*Z.length+J);(Q=z.exec($))!==null;){if(Y=Q[1]||Q[2]||Q[3]||Q[4]||Q[5]||Q[6],!Y||(X=[...Y].length,X!==J))continue;if(Q[3]||Q[4]){G+=X;continue}if(G-=X,G>0)continue;X=Math.min(X,X+G);let _=[...Q[0]][0].length,H=Z.slice(0,J+Q.index+_+X),U=H.slice(J,-J);return{type:"del",raw:H,text:U,tokens:this.lexer.inlineTokens(U)}}}}autolink(Z){let $=this.rules.inline.autolink.exec(Z);if($){let q,Q;return $[2]==="@"?(q=$[1],Q="mailto:"+q):(q=$[1],Q=q),{type:"link",raw:$[0],text:q,href:Q,tokens:[{type:"text",raw:q,text:q}]}}}url(Z){let $;if($=this.rules.inline.url.exec(Z)){let q,Q;if($[2]==="@")q=$[0],Q="mailto:"+q;else{let J;do J=$[0],$[0]=this.rules.inline._backpedal.exec($[0])?.[0]??"";while(J!==$[0]);q=$[0],$[1]==="www."?Q="http://"+$[0]:Q=$[0]}return{type:"link",raw:$[0],text:q,href:Q,tokens:[{type:"text",raw:q,text:q}]}}}inlineText(Z){let $=this.rules.inline.text.exec(Z);if($){let q=this.lexer.state.inRawBlock;return{type:"text",raw:$[0],text:$[0],escaped:q}}}},B1=class Z{tokens;options;state;inlineQueue;tokenizer;constructor($){this.tokens=[],this.tokens.links=Object.create(null),this.options=$||i1,this.options.tokenizer=this.options.tokenizer||new g0,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};let q={other:K1,block:m0.normal,inline:F0.normal};this.options.pedantic?(q.block=m0.pedantic,q.inline=F0.pedantic):this.options.gfm&&(q.block=m0.gfm,this.options.breaks?q.inline=F0.breaks:q.inline=F0.gfm),this.tokenizer.rules=q}static get rules(){return{block:m0,inline:F0}}static lex($,q){return new Z(q).lex($)}static lexInline($,q){return new Z(q).inlineTokens($)}lex($){$=$.replace(K1.carriageReturn,`
|
|
27
27
|
`),this.blockTokens($,this.tokens);for(let q=0;q<this.inlineQueue.length;q++){let Q=this.inlineQueue[q];this.inlineTokens(Q.src,Q.tokens)}return this.inlineQueue=[],this.tokens}blockTokens($,q=[],Q=!1){for(this.tokenizer.lexer=this,this.options.pedantic&&($=$.replace(K1.tabCharGlobal," ").replace(K1.spaceLine,""));$;){let J;if(this.options.extensions?.block?.some((X)=>(J=X.call({lexer:this},$,q))?($=$.substring(J.raw.length),q.push(J),!0):!1))continue;if(J=this.tokenizer.space($)){$=$.substring(J.raw.length);let X=q.at(-1);J.raw.length===1&&X!==void 0?X.raw+=`
|
|
28
28
|
`:q.push(J);continue}if(J=this.tokenizer.code($)){$=$.substring(J.raw.length);let X=q.at(-1);X?.type==="paragraph"||X?.type==="text"?(X.raw+=(X.raw.endsWith(`
|
|
29
29
|
`)?"":`
|
|
@@ -37,9 +37,9 @@ ${H}`:H;let U=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTo
|
|
|
37
37
|
`+J.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=X.text):q.push(J),Q=Y.length!==$.length,$=$.substring(J.raw.length);continue}if(J=this.tokenizer.text($)){$=$.substring(J.raw.length);let X=q.at(-1);X?.type==="text"?(X.raw+=(X.raw.endsWith(`
|
|
38
38
|
`)?"":`
|
|
39
39
|
`)+J.raw,X.text+=`
|
|
40
|
-
`+J.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=X.text):q.push(J);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,q}inline($,q=[]){return this.inlineQueue.push({src:$,tokens:q}),q}inlineTokens($,q=[]){this.tokenizer.lexer=this;let Q=$,J=null;if(this.tokens.links){let z=Object.keys(this.tokens.links);if(z.length>0)for(;(J=this.tokenizer.rules.inline.reflinkSearch.exec(Q))!==null;)z.includes(J[0].slice(J[0].lastIndexOf("[")+1,-1))&&(Q=Q.slice(0,J.index)+"["+"a".repeat(J[0].length-2)+"]"+Q.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(J=this.tokenizer.rules.inline.anyPunctuation.exec(Q))!==null;)Q=Q.slice(0,J.index)+"++"+Q.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);let Y;for(;(J=this.tokenizer.rules.inline.blockSkip.exec(Q))!==null;)Y=J[2]?J[2].length:0,Q=Q.slice(0,J.index+Y)+"["+"a".repeat(J[0].length-Y-2)+"]"+Q.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);Q=this.options.hooks?.emStrongMask?.call({lexer:this},Q)??Q;let X=!1,G="";for(;$;){X||(G=""),X=!1;let z;if(this.options.extensions?.inline?.some((H)=>(z=H.call({lexer:this},$,q))?($=$.substring(z.raw.length),q.push(z),!0):!1))continue;if(z=this.tokenizer.escape($)){$=$.substring(z.raw.length),q.push(z);continue}if(z=this.tokenizer.tag($)){$=$.substring(z.raw.length),q.push(z);continue}if(z=this.tokenizer.link($)){$=$.substring(z.raw.length),q.push(z);continue}if(z=this.tokenizer.reflink($,this.tokens.links)){$=$.substring(z.raw.length);let H=q.at(-1);z.type==="text"&&H?.type==="text"?(H.raw+=z.raw,H.text+=z.text):q.push(z);continue}if(z=this.tokenizer.emStrong($,Q,G)){$=$.substring(z.raw.length),q.push(z);continue}if(z=this.tokenizer.codespan($)){$=$.substring(z.raw.length),q.push(z);continue}if(z=this.tokenizer.br($)){$=$.substring(z.raw.length),q.push(z);continue}if(z=this.tokenizer.del($,Q,G)){$=$.substring(z.raw.length),q.push(z);continue}if(z=this.tokenizer.autolink($)){$=$.substring(z.raw.length),q.push(z);continue}if(!this.state.inLink&&(z=this.tokenizer.url($))){$=$.substring(z.raw.length),q.push(z);continue}let _=$;if(this.options.extensions?.startInline){let H=1/0,U=$.slice(1),
|
|
41
|
-
`;return Q?'<pre><code class="language-'+
|
|
42
|
-
`:"<pre><code>"+(q?J:
|
|
40
|
+
`+J.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=X.text):q.push(J);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,q}inline($,q=[]){return this.inlineQueue.push({src:$,tokens:q}),q}inlineTokens($,q=[]){this.tokenizer.lexer=this;let Q=$,J=null;if(this.tokens.links){let z=Object.keys(this.tokens.links);if(z.length>0)for(;(J=this.tokenizer.rules.inline.reflinkSearch.exec(Q))!==null;)z.includes(J[0].slice(J[0].lastIndexOf("[")+1,-1))&&(Q=Q.slice(0,J.index)+"["+"a".repeat(J[0].length-2)+"]"+Q.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(J=this.tokenizer.rules.inline.anyPunctuation.exec(Q))!==null;)Q=Q.slice(0,J.index)+"++"+Q.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);let Y;for(;(J=this.tokenizer.rules.inline.blockSkip.exec(Q))!==null;)Y=J[2]?J[2].length:0,Q=Q.slice(0,J.index+Y)+"["+"a".repeat(J[0].length-Y-2)+"]"+Q.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);Q=this.options.hooks?.emStrongMask?.call({lexer:this},Q)??Q;let X=!1,G="";for(;$;){X||(G=""),X=!1;let z;if(this.options.extensions?.inline?.some((H)=>(z=H.call({lexer:this},$,q))?($=$.substring(z.raw.length),q.push(z),!0):!1))continue;if(z=this.tokenizer.escape($)){$=$.substring(z.raw.length),q.push(z);continue}if(z=this.tokenizer.tag($)){$=$.substring(z.raw.length),q.push(z);continue}if(z=this.tokenizer.link($)){$=$.substring(z.raw.length),q.push(z);continue}if(z=this.tokenizer.reflink($,this.tokens.links)){$=$.substring(z.raw.length);let H=q.at(-1);z.type==="text"&&H?.type==="text"?(H.raw+=z.raw,H.text+=z.text):q.push(z);continue}if(z=this.tokenizer.emStrong($,Q,G)){$=$.substring(z.raw.length),q.push(z);continue}if(z=this.tokenizer.codespan($)){$=$.substring(z.raw.length),q.push(z);continue}if(z=this.tokenizer.br($)){$=$.substring(z.raw.length),q.push(z);continue}if(z=this.tokenizer.del($,Q,G)){$=$.substring(z.raw.length),q.push(z);continue}if(z=this.tokenizer.autolink($)){$=$.substring(z.raw.length),q.push(z);continue}if(!this.state.inLink&&(z=this.tokenizer.url($))){$=$.substring(z.raw.length),q.push(z);continue}let _=$;if(this.options.extensions?.startInline){let H=1/0,U=$.slice(1),W;this.options.extensions.startInline.forEach((T)=>{W=T.call({lexer:this},U),typeof W=="number"&&W>=0&&(H=Math.min(H,W))}),H<1/0&&H>=0&&(_=$.substring(0,H+1))}if(z=this.tokenizer.inlineText(_)){$=$.substring(z.raw.length),z.raw.slice(-1)!=="_"&&(G=z.raw.slice(-1)),X=!0;let H=q.at(-1);H?.type==="text"?(H.raw+=z.raw,H.text+=z.text):q.push(z);continue}if($){let H="Infinite loop on byte: "+$.charCodeAt(0);if(this.options.silent){console.error(H);break}else throw Error(H)}}return q}},f0=class{options;parser;constructor(Z){this.options=Z||i1}space(Z){return""}code({text:Z,lang:$,escaped:q}){let Q=($||"").match(K1.notSpaceStart)?.[0],J=Z.replace(K1.endingNewline,"")+`
|
|
41
|
+
`;return Q?'<pre><code class="language-'+b1(Q)+'">'+(q?J:b1(J,!0))+`</code></pre>
|
|
42
|
+
`:"<pre><code>"+(q?J:b1(J,!0))+`</code></pre>
|
|
43
43
|
`}blockquote({tokens:Z}){return`<blockquote>
|
|
44
44
|
${this.parser.parse(Z)}</blockquote>
|
|
45
45
|
`}html({text:Z}){return Z}def(Z){return""}heading({tokens:Z,depth:$}){return`<h${$}>${this.parser.parseInline(Z)}</h${$}>
|
|
@@ -55,37 +55,37 @@ ${this.parser.parse(Z)}</blockquote>
|
|
|
55
55
|
`}tablerow({text:Z}){return`<tr>
|
|
56
56
|
${Z}</tr>
|
|
57
57
|
`}tablecell(Z){let $=this.parser.parseInline(Z.tokens),q=Z.header?"th":"td";return(Z.align?`<${q} align="${Z.align}">`:`<${q}>`)+$+`</${q}>
|
|
58
|
-
`}strong({tokens:Z}){return`<strong>${this.parser.parseInline(Z)}</strong>`}em({tokens:Z}){return`<em>${this.parser.parseInline(Z)}</em>`}codespan({text:Z}){return`<code>${
|
|
59
|
-
Please report this to https://github.com/markedjs/marked.`,Z){let Q="<p>An error occurred:</p><pre>"+S1(q.message+"",!0)+"</pre>";return $?Promise.resolve(Q):Q}if($)return Promise.reject(q);throw q}}},r1=new B8;function e(Z,$){return r1.parse(Z,$)}e.options=e.setOptions=function(Z){return r1.setOptions(Z),e.defaults=r1.defaults,e2(e.defaults),e};e.getDefaults=H2;e.defaults=l1;e.use=function(...Z){return r1.use(...Z),e.defaults=r1.defaults,e2(e.defaults),e};e.walkTokens=function(Z,$){return r1.walkTokens(Z,$)};e.parseInline=r1.parseInline;e.Parser=B1;e.parser=B1.parse;e.Renderer=x0;e.TextRenderer=M2;e.Lexer=O1;e.lexer=O1.lex;e.Tokenizer=m0;e.Hooks=O0;e.parse=e;var{options:E6,setOptions:m6,use:x6,walkTokens:u6,parseInline:g6}=e;var f6=B1.parse,v6=O1.lex;import{SessionContext as w5,ActiveViewCtx as C6}from"#canvas/runtime";import{useState as M0,useCallback as b1,useEffect as L8,useRef as M8,useMemo as P8}from"react";import{AnnotationCtx as y8}from"#canvas/runtime";function f0(Z,$){return`canvas:${Z}:rev:${$}`}function F0(Z,$){return`${f0(Z,$)}:draft-handled`}function Y0(Z,$,q){try{Z.removeItem(f0($,q)),Z.removeItem(F0($,q))}catch{}}function G3(Z){if(!Z)return null;try{let $=JSON.parse(Z);return typeof $==="object"&&$!==null&&!Array.isArray($)?$:null}catch{return null}}function F8(Z){if(!Array.isArray(Z)||Z.length<2)return!1;let $=Z[1];if(typeof $!=="object"||$===null||Array.isArray($))return!1;let q=Reflect.get($,"note");if(typeof q==="string"&&q.trim().length>0)return!0;let Q=Reflect.get($,"value");if(typeof Q==="string")return Q.trim().length>0;if(Array.isArray(Q))return Q.length>0;return Q!==null&&Q!==void 0}function U3(Z){if(!Z)return!1;let $=Reflect.get(Z,"annotations");if(Array.isArray($)&&$.length>0)return!0;let q=Reflect.get(Z,"generalNote");if(typeof q==="string"&&q.trim().length>0)return!0;let Q=Reflect.get(Z,"responses");return Array.isArray(Q)&&Q.some(F8)}function P2(Z,$,q,Q){try{let J=f0($,q);if(U3(G3(Z.getItem(J))))return Z.setItem(F0($,q),"1"),null;if(Z.getItem(F0($,q))!==null)return null;let Y=Q.filter((X)=>X.revision<q).sort((X,G)=>G.revision-X.revision);for(let X of Y){if(X.hasFeedback)return null;let G=G3(Z.getItem(f0($,X.revision)));if(!U3(G)){if(Z.getItem(F0($,X.revision))!==null)return null;continue}return Z.setItem(J,JSON.stringify({...G,feedbackEntries:[]})),Z.setItem(F0($,q),"1"),X.revision}}catch{}return null}var T1="__agent-response__";function F1(){return`ann-${Date.now()}-${Math.random().toString(36).slice(2,6)}`}function L0(Z,$){Z.style.height="auto",Z.style.height=($?Math.max($,Z.scrollHeight):Z.scrollHeight)+"px"}import{useAnnotations as Y1}from"#canvas/runtime";import{jsxDEV as j8}from"react/jsx-dev-runtime";function K3(Z,$){return`canvas:${Z}:rev:${$}`}function v0(Z,$){try{let q=localStorage.getItem(K3(Z,$));if(!q)return null;return JSON.parse(q)}catch{return null}}function S8(Z,$,q){try{localStorage.setItem(K3(Z,$),JSON.stringify(q))}catch{}}function H3({sessionId:Z,revision:$,isReadOnly:q,remoteAnnotations:Q,children:J}){let[Y,X]=M0(()=>{return(v0(Z,$)?.annotations??[]).map((E)=>({...E,source:E.source??"local"}))}),G=P8(()=>{if(!Q||Q.length===0)return Y;let V=new Set(Y.map((g)=>g.id)),E=Q.filter((g)=>!V.has(g.id));return[...Y,...E.map((g)=>({...g,source:"remote"}))]},[Y,Q]),[z,_]=M0(()=>{return v0(Z,$)?.generalNote??""}),[H,U]=M0(null),[T,W]=M0(()=>{let V=v0(Z,$);return V?.responses?new Map(V.responses):new Map}),[K,F]=M0(()=>{let V=v0(Z,$);return V?.feedbackEntries?new Map(V.feedbackEntries):new Map}),N=M8(null);L8(()=>{if(q)return;if(N.current)clearTimeout(N.current);return N.current=setTimeout(()=>{S8(Z,$,{annotations:Y,generalNote:z,responses:Array.from(T.entries()),feedbackEntries:Array.from(K.entries())})},300),()=>{if(N.current)clearTimeout(N.current)}},[Y,z,T,K,Z,$,q]);let y=b1((V,E,g,l,j,u,h)=>{X((A)=>[...A,{id:V,snippet:E,note:g,createdAt:new Date().toISOString(),filePath:l,context:j,...u?.length?{images:u}:{},...h?{canvasFile:h}:{}}])},[]),O=b1((V,E,g)=>{y(F1(),V,E,g)},[y]),D=b1((V,E)=>{X((g)=>g.map((l)=>l.id===V?{...l,note:E}:l))},[]),S=b1((V)=>{b8(V),X((E)=>E.filter((g)=>g.id!==V)),U((E)=>E===V?null:E)},[]),M=b1((V,E)=>{X((g)=>g.map((l)=>l.id===V?{...l,images:[...l.images||[],E]}:l))},[]),b=b1((V,E)=>{X((g)=>g.map((l)=>l.id===V?{...l,images:(l.images||[]).filter((j)=>j!==E)}:l))},[]),C=b1((V,E)=>{W((g)=>{let l=new Map(g);return l.set(V,E),l})},[]),k=b1((V,E)=>{F((g)=>{let l=g.get(V);if(l&&l.markdown===E.markdown&&l.label===E.label&&l.required===E.required)return g;let j=new Map(g);return j.set(V,E),j})},[]),c=b1((V)=>{F((E)=>{if(!E.has(V))return E;let g=new Map(E);return g.delete(V),g})},[]),v=b1(()=>{for(let V of document.querySelectorAll("[data-annotation-id]"))W3(V);X([]),_(""),U(null),W(new Map),F(new Map),Y0(localStorage,Z,$)},[Z,$]);return j8(y8.Provider,{value:{annotations:G,addAnnotation:O,addAnnotationWithId:y,updateAnnotation:D,removeAnnotation:S,addAnnotationImage:M,removeAnnotationImage:b,generalNote:z,setGeneralNote:_,clearAll:v,activeAnnotationId:H,setActiveAnnotationId:U,responses:T,setResponse:C,feedbackEntries:K,setFeedbackEntry:k,removeFeedbackEntry:c},children:J},void 0,!1,void 0,this)}function b8(Z){let $=document.querySelectorAll(`[data-annotation-id="${Z}"]`);for(let q of $)W3(q)}function W3(Z){let $=Z.parentNode;if(!$)return;let q=document.createTextNode(Z.textContent||"");$.replaceChild(q,Z),$.normalize()}import C2,{useEffect as e1,useState as j1,useRef as i8,useContext as a8,useMemo as y0}from"react";import{createPortal as o8}from"react-dom";import{SessionContext as s8,CanvasFileCtx as t8}from"#canvas/runtime";function i1(Z,$){let q=T3(Z,"before",60),Q=T3(Z,"after",60),J=A8(Z.startContainer,$);return{before:q,after:Q,hierarchy:J}}function T3(Z,$,q){let Q=w8($==="before"?Z.startContainer:Z.endContainer);if(!Q)return"";let J="";if($==="before"){let Y=document.createTreeWalker(Q,NodeFilter.SHOW_TEXT),X;while(X=Y.nextNode()){if(X===Z.startContainer){J+=(X.textContent||"").slice(0,Z.startOffset);break}if(X.parentElement?.hasAttribute("data-annotation-id"))continue;J+=X.textContent||""}if(J.length>q){J=J.slice(-q);let G=J.indexOf(" ");if(G>0)J=J.slice(G+1)}}else{let Y=document.createTreeWalker(Q,NodeFilter.SHOW_TEXT),X=!1,G;while(G=Y.nextNode()){if(G===Z.endContainer){J+=(G.textContent||"").slice(Z.endOffset),X=!0;continue}if(X){if(G.parentElement?.hasAttribute("data-annotation-id"))continue;J+=G.textContent||""}}if(J.length>q){J=J.slice(0,q);let z=J.lastIndexOf(" ");if(z>0)J=J.slice(0,z)}}return J.trim()}function w8(Z){let $=new Set(["DIV","P","LI","PRE","BLOCKQUOTE","SECTION","ARTICLE"]),q=Z.parentElement;while(q){if($.has(q.tagName))return q;q=q.parentElement}return null}function A8(Z,$){let q=[],Q=Z instanceof Element?Z:Z.parentElement;while(Q&&Q!==$){let J=Q.getAttribute?.("data-task-id");if(J){let Y=Q.querySelector(".font-semibold");if(Y)q.unshift(Y.textContent?.trim()||J)}if(Q.tagName==="DIV"&&Q.querySelector(":scope > button .font-heading, :scope > div .font-heading")){let Y=Q.querySelector(".font-heading");if(Y)q.unshift(Y.textContent?.trim()||"")}Q=Q.parentElement}return q}function y2(Z){let $=Z.snippet.trim(),q=Z.context,Q=$.length<30;if(q&&Q&&(q.before||q.after)){let J=[];if(q.before)J.push(`...${q.before} `);if(J.push(`**${$}**`),q.after)J.push(` ${q.after}...`);return J.join("")}return $}import{useEffect as g8,useRef as c0,useState as X0,useCallback as p0,useMemo as C3,useContext as f8}from"react";import{createPortal as v8}from"react-dom";function N3(Z,$){let J=$||document.body,Y=Z.getBoundingClientRect(),X=J.getBoundingClientRect(),G=J===document.body?window.scrollY:J.scrollTop,z=Y.bottom-X.top+G+8,_=Math.max(0,Math.min(Y.left-X.left,X.width-280-12));return J.style.position="relative",{style:{position:"absolute",top:`${z}px`,left:`${_}px`},parent:J}}import{useState as b2,useRef as j2,useCallback as V1,useEffect as x8}from"react";var O3={alg:"AES-GCM",v:1};async function B3(Z){let $=V8(Z);return crypto.subtle.importKey("raw",$,{name:"AES-GCM",length:256},!1,["encrypt","decrypt"])}async function m1(Z,$){let q=crypto.getRandomValues(new Uint8Array(12)),Q=new TextEncoder().encode($),J=await crypto.subtle.encrypt({name:"AES-GCM",iv:q},Z,Q),Y=new Uint8Array(q.byteLength+J.byteLength);return Y.set(q,0),Y.set(new Uint8Array(J),q.byteLength),C8(Y)}async function P0(Z,$){let q=F3($);if(q.byteLength<28)throw Error("Ciphertext too short");let Q=q.subarray(0,12),J=q.subarray(12),Y=await crypto.subtle.decrypt({name:"AES-GCM",iv:Q},Z,J);return new TextDecoder().decode(Y)}function C8(Z){let $="",q=32768;for(let Q=0;Q<Z.byteLength;Q+=q)$+=String.fromCharCode.apply(null,Array.from(Z.subarray(Q,Q+q)));return btoa($)}function F3(Z){let $=atob(Z),q=new Uint8Array($.length);for(let Q=0;Q<$.length;Q++)q[Q]=$.charCodeAt(Q);return q}function V8(Z){let $=Z.replace(/-/g,"+").replace(/_/g,"/")+"===".slice((Z.length+3)%4);return F3($)}function I8(){if(typeof window>"u")return null;let Z=window.location.hash.replace(/^#/,"");if(!Z)return null;for(let $ of Z.split("&")){let[q,Q]=$.split("=");if(q==="k"&&Q)return decodeURIComponent(Q)}return null}function R8(){if(typeof window<"u"&&window.__CANVAS_SHARE__?.shareId){let $=I8();return{isShared:!0,shareId:window.__CANVAS_SHARE__.shareId,encryptionKey:$?B3($):null}}return{isShared:!1,sessionId:typeof window<"u"?window.location.pathname.replace("/s/",""):""}}var $1=R8();function D8(){return $1.isShared&&$1.encryptionKey!==null}function k8(){if($1.isShared)return`/s/${$1.shareId}/meta`;return`/api/session/${$1.sessionId}/meta`}function E8(Z,$){let q=Z.replace(/\.jsx$/,".js");if($1.isShared)return`/s/${$1.shareId}/canvas/${encodeURIComponent(q)}`;let Q=$?`?rev=${$}&t=${Date.now()}`:`?t=${Date.now()}`;return`/api/session/${$1.sessionId}/canvas/${encodeURIComponent(q)}${Q}`}function L3(){if($1.isShared)return`/s/${$1.shareId}/upload`;return`/api/session/${$1.sessionId}/upload`}async function M3(){let Z=await fetch(k8());if(!Z.ok)throw Error(`meta ${Z.status}`);let $=await Z.json();if($.encryption&&$1.isShared&&$1.encryptionKey){let q=await $1.encryptionKey;if($.origin){let J={...$.origin};if(J.sessionId)J.sessionId=await P0(q,J.sessionId);if(J.label)J.label=await P0(q,J.label);$.origin=J}let Q=$.revisions;if(Array.isArray(Q)){for(let J of Q)if(J.label)try{J.label=await P0(q,J.label)}catch{}}}return $}async function P3(Z,$){let q=E8(Z,$);if(!D8())return import(q);let Q=await fetch(q);if(!Q.ok)throw Error(`canvas ${Q.status}`);let J=await Q.text(),Y=await $1.encryptionKey,X=await P0(Y,J),G=new Blob([X],{type:"application/javascript"}),z=URL.createObjectURL(G);try{return await import(z)}finally{setTimeout(()=>URL.revokeObjectURL(z),0)}}var y3="canvas-reviewer-identity";function S2(){try{let Z=localStorage.getItem(y3);if(!Z)return null;return JSON.parse(Z)}catch{return null}}function S3(Z){let $=S2();if(!$)$={id:crypto.randomUUID?.()||String(Date.now()),name:Z};else $.name=Z;return localStorage.setItem(y3,JSON.stringify($)),$}async function m8(Z,$){let q=await Promise.all(Z.annotations.map(async(Q)=>{let J={id:Q.id,createdAt:Q.createdAt,snippet:await m1($,String(Q.snippet??"")),note:await m1($,String(Q.note??""))};if(Q.filePath)J.filePath=await m1($,String(Q.filePath));if(Q.canvasFile)J.canvasFile=await m1($,String(Q.canvasFile));if(Q.context!==void 0&&Q.context!==null)J.context=await m1($,JSON.stringify(Q.context));if(Q.attachments)J.attachments=Q.attachments;return J}));return{author:{id:Z.author.id,name:await m1($,Z.author.name)},revision:Z.revision,annotations:q,...Z.generalNote?{generalNote:await m1($,Z.generalNote)}:{},encryption:O3}}async function b3(Z){if(!$1.isShared)throw Error("submitSharedFeedback called outside shared mode");let $=Z;if($1.encryptionKey){let Q=await $1.encryptionKey;$=await m8(Z,Q)}let q=await fetch(`/s/${$1.shareId}/feedback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify($)});if(!q.ok){let Q=await q.text().catch(()=>"");throw Error(`Feedback submission failed: ${q.status} ${Q}`)}}var L1=!$1.isShared,j3=!$1.isShared;import{jsxDEV as z1}from"react/jsx-dev-runtime";function w3(Z){if(Z.startsWith("/s/")||Z.startsWith("http://")||Z.startsWith("https://"))return Z;return`/api/uploads/${Z.split("/").pop()}`}async function u8(Z,$){let q=new FormData;q.append("image",$);try{let J=await(await fetch(L3(),{method:"POST",body:q})).json();if($1.isShared)return J.url||null;return J.path||null}catch{return null}}function h0({note:Z,onNoteChange:$,images:q,onAddImage:Q,onRemoveImage:J,sessionId:Y,placeholder:X="Add your note...",autoFocus:G=!1,autoResize:z=!1,readOnly:_=!1,onKeyDown:H,onTextareaClick:U,textareaRef:T,textareaClassName:W,textareaStyle:K,minHeight:F,attachButton:N="always",openFilePickerRef:y}){let[O,D]=b2(!1),[S,M]=b2(!1),[b,C]=b2(!1),k=j2(0),c=j2(null),v=j2(null),V=V1(()=>v.current?.click(),[]);if(y)y.current=V;let E=V1((x)=>{if(c.current=x,T)T.current=x;if(x&&z)L0(x,F)},[T,z,F]);x8(()=>{if(G&&c.current){let x=c.current;if(x.focus(),x.value)x.setSelectionRange(x.value.length,x.value.length)}},[G]);let g=V1(async(x)=>{if(!x.type.startsWith("image/"))return;M(!0);try{let s=await u8(Y,x);if(s)Q(s)}finally{M(!1)}},[Y,Q]),l=V1((x)=>{let s=x.clipboardData.items;for(let w of s)if(w.type.startsWith("image/")){x.preventDefault();let f=w.getAsFile();if(f)g(f);return}},[g]),j=V1((x)=>{if(x.preventDefault(),k.current++,k.current===1)D(!0)},[]),u=V1((x)=>{x.preventDefault()},[]),h=V1((x)=>{if(x.preventDefault(),k.current--,k.current===0)D(!1)},[]),A=V1((x)=>{x.preventDefault(),k.current=0,D(!1);for(let s of x.dataTransfer.files)if(s.type.startsWith("image/"))g(s)},[g]),I=V1((x)=>{if($(x.target.value),z)x.target.style.height="auto",x.target.style.height=(F?Math.max(F,x.target.scrollHeight):x.target.scrollHeight)+"px"},[$,z,F]),L="w-full bg-transparent text-[13px] font-body text-text-primary resize-none focus:outline-none leading-relaxed p-0 border-none",d={width:"100%",background:"transparent",border:"none",color:"var(--color-text-primary)",fontFamily:"'Inter', sans-serif",fontSize:"13px",lineHeight:"1.5",outline:"none",...z?{resize:"none",overflow:"hidden"}:{resize:"vertical"}},m=!_&&(N==="always"||N==="on-focus"&&b);return z1("div",{style:{position:"relative"},onDragEnter:_?void 0:j,onDragOver:_?void 0:u,onDragLeave:_?void 0:h,onDrop:_?void 0:A,children:[z1("textarea",{ref:E,value:Z,onChange:_?void 0:I,onPaste:_?void 0:l,onKeyDown:H,onClick:U,onFocus:()=>C(!0),onBlur:()=>{setTimeout(()=>C(!1),150)},readOnly:_,placeholder:X,className:W??L,style:K??d,rows:z?1:void 0},void 0,!1,void 0,this),!_&&z1("input",{ref:v,type:"file",accept:"image/*",multiple:!0,style:{display:"none"},onChange:(x)=>{let s=x.target.files;if(s)for(let w of s)g(w);x.target.value=""}},void 0,!1,void 0,this),(q.length>0||m)&&z1("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"6px",alignItems:"center"},children:[q.map((x)=>z1("div",{style:{position:"relative",width:"56px",height:"56px",borderRadius:"6px",overflow:"hidden",border:"1px solid var(--color-border-subtle)",flexShrink:0},children:[z1("img",{src:w3(x),alt:"",style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}},void 0,!1,void 0,this),!_&&z1("button",{onClick:(s)=>{s.stopPropagation(),J(x)},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)]},x,!0,void 0,this)),m&&z1(w2,{onClick:V},void 0,!1,void 0,this)]},void 0,!0,void 0,this),S&&z1("div",{style:{fontSize:"11px",color:"var(--color-text-tertiary)",fontFamily:"'Inter', sans-serif",marginTop:"4px"},children:"Uploading..."},void 0,!1,void 0,this),O&&z1("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 w2({onClick:Z,size:$=16}){return z1("button",{onClick:(q)=>{q.stopPropagation(),Z()},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:(q)=>{q.currentTarget.style.color="var(--color-text-secondary)"},onMouseLeave:(q)=>{q.currentTarget.style.color="var(--color-text-tertiary)"},children:z1("svg",{width:$,height:$,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[z1("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"},void 0,!1,void 0,this),z1("circle",{cx:"8.5",cy:"8.5",r:"1.5"},void 0,!1,void 0,this),z1("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 A3({images:Z}){if(!Z.length)return null;return z1("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"6px"},children:Z.map(($)=>z1("div",{style:{width:"56px",height:"56px",borderRadius:"6px",overflow:"hidden",border:"1px solid var(--color-border-subtle)",flexShrink:0},children:z1("img",{src:w3($),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 h8}from"#canvas/runtime";import{jsxDEV as _1,Fragment as c8}from"react/jsx-dev-runtime";function p8({anchorEl:Z,scrollContainer:$,onClose:q,ignoreSelector:Q,zIndex:J="50",padding:Y="12px",width:X="280px",children:G}){let z=c0(null),_=c0(q);_.current=q;let{style:H,parent:U}=N3(Z,$);return g8(()=>{let T=setTimeout(()=>{let W=(K)=>{if(z.current&&!z.current.contains(K.target)){if(Q&&K.target.closest?.(Q))return;_.current(),document.removeEventListener("mousedown",W)}};return document.addEventListener("mousedown",W),()=>document.removeEventListener("mousedown",W)},0);return()=>clearTimeout(T)},[Q]),v8(_1("div",{ref:z,style:{...H,zIndex:J,width:X,background:"var(--color-bg-elevated)",border:"1px solid var(--color-border-hover)",borderRadius:"8px",boxShadow:"0 4px 12px var(--color-shadow)",padding:Y,fontFamily:"'Inter', sans-serif"},children:G},void 0,!1,void 0,this),U)}var I3=[{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"]}],V3=I3.flatMap((Z)=>Z.items);function R3({anchorEl:Z,scrollContainer:$,snippet:q,truncateAt:Q=100,header:J,initialNote:Y="",initialImages:X,onConfirm:G,onCancel:z,onDelete:_}){let H=f8(h8),U=Y!==""||!!_,[T,W]=X0(Y),[K,F]=X0(X||[]),[N,y]=X0(null),[O,D]=X0(U),[S,M]=X0(!1),b=c0(null),C=c0(null),k=p0(()=>{if(T.trim()||K.length>0)G(T.trim(),K);else if(U&&_)_();else z()},[T,K,G,z,U,_]),c=p0(()=>{if(U){if(!T.trim()&&K.length===0&&_){_(),z();return}G(T,K);return}z()},[T,K,U,G,z,_]),v=!U,V=T.trim().length>0?V3.filter((w)=>w.toLowerCase().startsWith(T.trim().toLowerCase())):V3,E=!v||O?[]:V.length===1&&V[0].toLowerCase()===T.trim().toLowerCase()?[]:V,g=new Set(E),l=I3.map((w)=>({label:w.label,items:w.items.filter((f)=>g.has(f))})).filter((w)=>w.items.length>0),j=l.map((w)=>w.items),u=j.flat(),h=C3(()=>{if(N===null)return 0;let w=0;for(let f=0;f<j.length;f++){if(N<w+j[f].length)return f;w+=j[f].length}return 0},[N,j]),A=C3(()=>{if(N===null)return 0;let w=0;for(let f=0;f<h;f++)w+=j[f].length;return N-w},[N,h,j]),I=(w,f)=>{let Z1=0;for(let U1=0;U1<w;U1++)Z1+=j[U1].length;return Z1+f},[L,d]=X0(T);if(T!==L)d(T),y(null),D(U);let m=p0((w)=>{W(w)},[]),x=q.length>Q?q.slice(0,Q)+"...":q,s=p0((w)=>{if(u.length>0&&(w.key==="ArrowDown"||w.key==="ArrowUp"||w.key==="ArrowLeft"||w.key==="ArrowRight")){if(w.preventDefault(),N===null){y(0);return}if(w.key==="ArrowDown"){let f=Math.min(A+1,j[h].length-1);y(I(h,f))}else if(w.key==="ArrowUp"){let f=Math.max(A-1,0);y(I(h,f))}else if(w.key==="ArrowRight"){let f=Math.min(h+1,j.length-1),Z1=Math.min(A,j[f].length-1);y(I(f,Z1))}else if(w.key==="ArrowLeft"){let f=Math.max(h-1,0),Z1=Math.min(A,j[f].length-1);y(I(f,Z1))}return}if(N!==null&&u.length>0){if(w.key==="Tab"){w.preventDefault(),m(u[N]);return}if(w.key==="Enter"&&!w.shiftKey){w.preventDefault(),G(u[N],K);return}}if(w.key==="Enter"&&!w.shiftKey){w.preventDefault(),k();return}if(w.key==="Escape")if(u.length>0&&!O)D(!0);else if(U)c();else z()},[u,N,A,h,j,I,m,G,K,k,O,U,c,z]);return _1(p8,{anchorEl:Z,scrollContainer:$,onClose:U?c:z,ignoreSelector:U?"[data-annotation-id]":void 0,zIndex:U?"60":"50",padding:U?"10px 12px":"12px",width:"420px",children:[!U&&(J??_1("div",{style:{fontSize:"11px",color:"var(--color-text-tertiary)",fontStyle:"italic",marginBottom:"8px",lineHeight:"1.4",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden"},children:["“",x,"”"]},void 0,!0,void 0,this)),_1(h0,{note:T,onNoteChange:W,images:K,onAddImage:(w)=>F((f)=>[...f,w]),onRemoveImage:(w)=>F((f)=>f.filter((Z1)=>Z1!==w)),sessionId:H,autoFocus:!0,autoResize:U,textareaRef:b,onKeyDown:s,attachButton:"none",openFilePickerRef:C,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),_1("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginTop:U?"6px":"8px"},children:[_1(w2,{onClick:()=>C.current?.(),size:14},void 0,!1,void 0,this),_1("div",{style:{flex:1}},void 0,!1,void 0,this),U?_1("button",{onClick:()=>{if(_)_();z()},onMouseEnter:()=>M(!0),onMouseLeave:()=>M(!1),style:{fontSize:"11px",color:S?"var(--color-accent-red)":"var(--color-text-tertiary)",background:"none",border:"none",cursor:"pointer",padding:"2px 0",fontFamily:"'Inter', sans-serif"},children:"Delete"},void 0,!1,void 0,this):_1(c8,{children:[_1("button",{onClick:z,style:{fontSize:"11px",color:"var(--color-text-tertiary)",background:"none",border:"none",cursor:"pointer",padding:"4px 12px",fontFamily:"'Inter', sans-serif"},children:"Cancel"},void 0,!1,void 0,this),_1("button",{onClick:k,style:{fontSize:"11px",fontWeight:500,padding:"4px 12px",borderRadius:"6px",background:"var(--color-highlight-bg)",color:"var(--color-text-primary)",border:"1px solid var(--color-highlight-border)",cursor:"pointer",fontFamily:"'Inter', sans-serif"},children:"Add"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),u.length>0&&_1("div",{style:{marginTop:"6px",borderTop:"1px solid var(--color-border-subtle)",paddingTop:"8px",display:"flex",gap:"4px"},children:l.map((w)=>_1("div",{style:{flex:1},children:[_1("div",{style:{fontSize:"10px",fontWeight:600,color:"var(--color-text-disabled)",textTransform:"uppercase",letterSpacing:"0.05em",padding:"2px 6px",marginBottom:"2px",fontFamily:"'Inter', sans-serif"},children:w.label},void 0,!1,void 0,this),w.items.map((f)=>{let Z1=u.indexOf(f);return _1("div",{onMouseDown:(U1)=>{U1.preventDefault(),U1.stopPropagation(),m(f)},onMouseEnter:()=>y(Z1),style:{padding:"3px 6px",fontSize:"12px",borderRadius:"4px",fontFamily:"'Inter', sans-serif",color:Z1===N?"var(--color-text-primary)":"var(--color-text-secondary)",background:Z1===N?"var(--color-highlight-selected)":"transparent",cursor:"pointer"},children:[_1("span",{style:{fontWeight:500},children:f.slice(0,T.trim().length)},void 0,!1,void 0,this),f.slice(T.trim().length)]},f,!0,void 0,this)})]},w.label,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function z0({anchorEl:Z,scrollContainer:$,snippet:q,truncateAt:Q,header:J,onAdd:Y,onCancel:X}){return _1(R3,{anchorEl:Z,scrollContainer:$,snippet:q,truncateAt:Q,header:J,onConfirm:(G,z)=>Y(G,z),onCancel:X},void 0,!1,void 0,this)}function _0({anchorEl:Z,scrollContainer:$,initialNote:q,initialImages:Q,onUpdate:J,onDelete:Y,onClose:X}){return _1(R3,{anchorEl:Z,scrollContainer:$,snippet:"",initialNote:q,initialImages:Q,onConfirm:(G,z)=>{J(G,z),X()},onDelete:Y,onCancel:X},void 0,!1,void 0,this)}import{useEffect as a0,useState as k3,useRef as s1,useCallback as E3}from"react";function o1(Z,$){let q=[],Q=d8(Z);for(let J of Q){let Y=document.createRange();if(Y.selectNodeContents(J),J===Z.startContainer)Y.setStart(J,Z.startOffset);if(J===Z.endContainer)Y.setEnd(J,Z.endOffset);let X=Y.toString();if(!X||!X.trim())continue;let G=document.createElement("mark");G.setAttribute("data-annotation-id",$);try{Y.surroundContents(G)}catch{let z=Y.extractContents();G.appendChild(z),Y.insertNode(G)}q.push(G)}return q}function d8(Z){let $=[],q=Z.commonAncestorContainer;if(q.nodeType===Node.TEXT_NODE)return $.push(q),$;let Q=document.createTreeWalker(q,NodeFilter.SHOW_TEXT),J;while(J=Q.nextNode()){let Y=J.parentElement;if(Y?.classList.contains("select-none"))continue;if(Y?.closest("[data-annotation-id]"))continue;if(Z.intersectsNode(J))$.push(J)}return $}function a1(Z,$){let q=document.querySelectorAll(`[data-annotation-id="${Z}"]`);for(let Q of q)Q.classList.toggle("mark-active",$)}function d0(Z,$){if($!=null&&$!==Z)a1($,!1);if(Z!=null)a1(Z,!0)}function r0(Z,$){let q=document.querySelectorAll(`[data-annotation-id="${Z}"]`);for(let Q of q)Q.setAttribute("data-annotation-id",$)}function l0(Z,$){for(let q of $){if(Z.querySelector(`[data-annotation-id="${q.id}"]`))continue;let Q=q.snippet;if(!Q)continue;let{fullText:J,textNodes:Y}=r8(Z),X=[],G=0;while(!0){let W=J.indexOf(Q,G);if(W===-1)break;X.push(W),G=W+1}if(X.length===0)continue;let z=X[0];if(X.length>1&&q.context){let W=-1;for(let K of X){let F=0;if(q.context.before){let N=J.slice(Math.max(0,K-80),K);if(N.includes(q.context.before))F+=2;else if(q.context.before.length>10&&N.includes(q.context.before.slice(-10)))F+=1}if(q.context.after){let N=J.slice(K+Q.length,K+Q.length+80);if(N.includes(q.context.after))F+=2;else if(q.context.after.length>10&&N.includes(q.context.after.slice(0,10)))F+=1}if(F>W)W=F,z=K}}let _=z,H=z+Q.length,U=D3(Y,_),T=D3(Y,H);if(!U||!T)continue;try{let W=document.createRange();W.setStart(U.node,U.offset),W.setEnd(T.node,T.offset),o1(W,q.id)}catch{}}}function r8(Z){let $=[],q="",Q=document.createTreeWalker(Z,NodeFilter.SHOW_TEXT),J;while(J=Q.nextNode()){let Y=J.parentElement;if(Y?.classList.contains("select-none"))continue;if(Y?.closest("[data-annotation-id]"))continue;$.push({node:J,start:q.length}),q+=J.textContent||""}return{fullText:q,textNodes:$}}function D3(Z,$){for(let q=Z.length-1;q>=0;q--)if(Z[q].start<=$){let Q=$-Z[q].start,J=Z[q].node.textContent?.length??0;if(Q<=J)return{node:Z[q].node,offset:Q}}return null}function i0(Z){let $=document.querySelectorAll(`[data-annotation-id="${Z}"]`);for(let q of $){let Q=q.parentNode;if(!Q)continue;while(q.firstChild)Q.insertBefore(q.firstChild,q);Q.removeChild(q),Q.normalize()}}import{jsxDEV as A2,Fragment as l8}from"react/jsx-dev-runtime";function t1(Z){let{containerRef:$,restoreKey:q,restoreAnnotations:Q,extractContext:J,filePath:Y,canvasFile:X,scrollContainer:G}=Z,{annotations:z,addAnnotationWithId:_,removeAnnotation:H,updateAnnotation:U,addAnnotationImage:T,removeAnnotationImage:W,activeAnnotationId:K,setActiveAnnotationId:F}=Y1(),[N,y]=k3(null),[O,D]=k3(null),S=s1(J);S.current=J;let M=s1(Y);M.current=Y;let b=s1(X);b.current=X;let C=s1(_);C.current=_;let k=s1(K);k.current=K;let c=s1(F);c.current=F;let v=Q.length;a0(()=>{if(!$.current)return;let j=setTimeout(()=>{if($.current)l0($.current,Q)},50);return()=>clearTimeout(j)},[q,v]);let V=s1(null);a0(()=>{d0(K,V.current),V.current=K},[K]),a0(()=>{let j=$.current;if(!j)return;let u=(I)=>{let L=I.target.closest("[data-annotation-id]");if(!L)return;I.stopPropagation();let d=L.getAttribute("data-annotation-id");if(d===k.current)y({anchorEl:L,annId:d});else c.current(d)},h=(I)=>{let L=I.target.closest("[data-annotation-id]");if(L)c.current(L.getAttribute("data-annotation-id"))},A=(I)=>{let L=I.target.closest("[data-annotation-id]"),d=I.relatedTarget?.closest?.("[data-annotation-id]");if(L&&!d&&!document.getElementById("ann-inline-popover"))c.current(null)};return j.addEventListener("click",u),j.addEventListener("mouseover",h),j.addEventListener("mouseout",A),()=>{j.removeEventListener("click",u),j.removeEventListener("mouseover",h),j.removeEventListener("mouseout",A)}},[q]),a0(()=>{let j=()=>E();return document.addEventListener("mouseup",j),()=>document.removeEventListener("mouseup",j)},[]);let E=E3(()=>{let j=window.getSelection();if(!j||j.isCollapsed||!j.toString().trim())return;if(!$.current)return;let u=j.getRangeAt(0);if(!$.current.contains(u.startContainer))return;if(u.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let h=j.toString().trim();if(h.length<2)return;let A=S.current(u),I=u.cloneRange(),L=`__pending_${Date.now()}`;try{o1(I,L)}catch{}window.getSelection()?.removeAllRanges();let d=document.querySelectorAll(`[data-annotation-id="${L}"]`),m=d[d.length-1];if(!m)return;D({anchorEl:m,tempId:L,snippet:h,ctx:A})},[]),g=E3((j,u,h,A)=>{D({anchorEl:j,tempId:u,snippet:h,ctx:A})},[]);return{popovers:A2(l8,{children:[N&&(()=>{let j=z.find((u)=>u.id===N.annId);if(!j)return null;return A2(_0,{anchorEl:N.anchorEl,scrollContainer:G,initialNote:j.note,initialImages:j.images,onUpdate:(u,h)=>{U(N.annId,u);let A=j.images||[];for(let I of h)if(!A.includes(I))T(N.annId,I);for(let I of A)if(!h.includes(I))W(N.annId,I)},onDelete:()=>{H(N.annId),F(null)},onClose:()=>y(null)},void 0,!1,void 0,this)})(),O&&A2(z0,{anchorEl:O.anchorEl,scrollContainer:G,snippet:O.snippet,truncateAt:80,onAdd:(j,u)=>{let h=F1();r0(O.tempId,h),C.current(h,O.snippet,j,M.current,O.ctx,u,b.current),D(null)},onCancel:()=>{i0(O.tempId),D(null)}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),openCreatePopover:g,isPopoverOpen:!!(N||O)}}import{jsxDEV as J1,Fragment as Z4}from"react/jsx-dev-runtime";var I2="[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']",V2="[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 S0({revision:Z,filename:$}){let q=a8(s8),[Q,J]=j1(null),[Y,X]=j1(null),[G,z]=j1(!0),_=i8(null),{annotations:H,addAnnotationWithId:U,removeAnnotation:T,updateAnnotation:W,addAnnotationImage:K,removeAnnotationImage:F,activeAnnotationId:N,setActiveAnnotationId:y}=Y1(),O=y0(()=>H.filter((A)=>!A.filePath&&(!A.canvasFile||A.canvasFile===$)),[H,$]),[D,S]=j1(null),[M,b]=j1(null),[C,k]=j1(null),[c,v]=j1(null),[V,E]=j1(!1);e1(()=>{z(!0),X(null),v(null),P3($,Z).then((A)=>{J(()=>A.default),z(!1)}).catch((A)=>{X(A.message),z(!1)})},[q,Z,$]);let g=document.getElementById("plan-scroll-container"),{popovers:l,isPopoverOpen:j}=t1({containerRef:_,restoreKey:Q,restoreAnnotations:O,extractContext:(A)=>i1(A,_.current),canvasFile:$,scrollContainer:g}),u=y0(()=>{let A=new Map;for(let I of O)if(I.snippet.startsWith("["))A.set(I.snippet,I.id);return A},[O]);e1(()=>{let A=_.current;if(!A)return;let I=(d)=>{if(C||j)return;let m=d.target;if(m.closest("[data-block-comment-btn]"))return;E(!1);let x=m.closest(I2);if(x&&A.contains(x)){let f=n1(A).indexOf(x);v(f>=0?f:null)}else v(null);let s=m.closest(V2);if(s&&A.contains(s)){b(s);let w=G0(s),f=w?u.get(w):void 0;if(f&&f!==N)y(f)}else b(null)},L=(d)=>{if(C||j)return;if(d.relatedTarget?.closest("[data-block-comment-btn]"))return;b(null),y(null)};return A.addEventListener("mousemove",I),A.addEventListener("mouseleave",L),()=>{A.removeEventListener("mousemove",I),A.removeEventListener("mouseleave",L)}},[Q,C,j,u,N]),e1(()=>{let A=(I)=>{let L=I.target.tagName;if(L==="INPUT"||L==="TEXTAREA"||I.target.isContentEditable)return;if(C||j)return;let d=_.current;if(!d)return;if(I.key==="ArrowDown"){I.preventDefault(),E(!0);let m=n1(d);if(m.length===0)return;v((x)=>{if(x===null)return 0;return Math.min(x+1,m.length-1)})}else if(I.key==="ArrowUp"){I.preventDefault(),E(!0);let m=n1(d);if(m.length===0)return;v((x)=>{if(x===null)return m.length-1;return Math.max(x-1,0)})}else if(I.key==="a"||I.key==="A"){if(c===null||!d)return;I.preventDefault();let x=n1(d)[c];if(!x)return;let s=G0(x);if(!s)return;let w=u.get(s);if(w)y(w),k({anchorEl:x,snippet:s,annId:w});else k({anchorEl:x,snippet:s})}else if(I.key===" "||I.key==="Enter"){if(c===null)return;let x=n1(d)[c];if(!x)return;let s=x.getAttribute("data-md");if(s==="choice-option"||s==="multichoice-option")I.preventDefault(),x.dispatchEvent(new CustomEvent("kb-select",{bubbles:!0}));else if(s==="userinput"){I.preventDefault();let w=x.querySelector("textarea");if(w){w.focus();let f=(Z1)=>{if(Z1.key==="Escape")Z1.preventDefault(),w.blur(),E(!0)};w.addEventListener("keydown",f),w.addEventListener("blur",()=>w.removeEventListener("keydown",f),{once:!0})}}else if(s==="rangeinput"){I.preventDefault();let w=x.querySelector("input[type='range']");if(w){w.focus();let f=(Z1)=>{if(Z1.key==="Escape"||Z1.key==="ArrowUp"||Z1.key==="ArrowDown")Z1.preventDefault(),w.blur(),E(!0)};w.addEventListener("keydown",f),w.addEventListener("blur",()=>w.removeEventListener("keydown",f),{once:!0})}}}else if(I.key==="Escape")v(null),E(!1),y(null)};return document.addEventListener("keydown",A),()=>document.removeEventListener("keydown",A)},[c,C,j,u]),e1(()=>{let A=_.current;if(!A||c===null||!V)return;let L=n1(A)[c];if(!L)return;L.style.outline="2px solid var(--color-accent-blue)",L.style.outlineOffset="-2px",L.style.borderRadius="8px",L.scrollIntoView({block:"nearest",behavior:"smooth"});let d=G0(L),m=d?u.get(d):void 0;if(m)y(m);return()=>{L.style.outline="",L.style.outlineOffset="",L.style.borderRadius=""}},[c,V,u]);let h=y0(()=>Q?J1(Q,{},void 0,!1,void 0,this):null,[Q]);if(G)return J1("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-body",children:"Loading canvas..."},void 0,!1,void 0,this);if(Y)return J1("div",{className:"bg-accent-red-muted rounded-lg p-5",children:[J1("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Compilation Error"},void 0,!1,void 0,this),J1("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:Y},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(!Q)return J1("div",{className:"text-text-tertiary text-center py-8 font-body text-body",children:"No canvas loaded"},void 0,!1,void 0,this);return J1(t8.Provider,{value:$,children:[J1("div",{ref:_,className:"plan-content plan-updated",children:h},void 0,!1,void 0,this),D&&J1($4,{note:D.note,onSave:(A)=>{W(D.id,A),S(null)},onCancel:()=>S(null)},void 0,!1,void 0,this),l,J1(n8,{containerRef:_,hoveredBlock:M,focusedBlockIndex:c,blockPopover:C,blockAnnotationMap:u,activeAnnotationId:N,onOpen:(A,I,L)=>{if(L)y(L),k({anchorEl:A,snippet:I,annId:L});else k({anchorEl:A,snippet:I})}},void 0,!1,void 0,this),C&&!C.annId&&J1(z0,{anchorEl:C.anchorEl,scrollContainer:g,snippet:C.snippet,truncateAt:80,onAdd:(A,I)=>{let L=F1();U(L,C.snippet,A,void 0,void 0,I,$),k(null)},onCancel:()=>k(null)},void 0,!1,void 0,this),C?.annId&&(()=>{let A=O.find((I)=>I.id===C.annId);if(!A)return null;return J1(_0,{anchorEl:C.anchorEl,scrollContainer:g,initialNote:A.note,initialImages:A.images,onUpdate:(I,L)=>{W(C.annId,I);let d=A.images||[];for(let m of L)if(!d.includes(m))K(C.annId,m);for(let m of d)if(!L.includes(m))F(C.annId,m)},onDelete:()=>{T(C.annId),y(null),k(null)},onClose:()=>k(null)},void 0,!1,void 0,this)})()]},void 0,!0,void 0,this)}function n1(Z){return Array.from(Z.querySelectorAll(I2))}function G0(Z){let $=Z.getAttribute("data-md");if($==="item"){let q=Z.getAttribute("data-md-label");return q?`[Item] ${q}`:null}if($==="section"){let q=Z.getAttribute("data-md-title");return q?`[Section] ${q}`:null}if($==="callout"){let q=Z.getAttribute("data-md-type")||"info",Q=Z.textContent?.trim().slice(0,60)||"Callout";return`[Callout:${q}] ${Q}`}if($==="note")return`[Note] ${Z.textContent?.trim().slice(0,60)||"Note"}`;if(Z.tagName==="TR"){let q=Array.from(Z.querySelectorAll("td")).map((Q)=>Q.textContent?.trim()).filter(Boolean);return q.length?`[Row] ${q.join(" | ")}`:null}if($==="checklist-item"){let q=Z.getAttribute("data-md-label");return q?`[Checklist] ${q}`:null}if($==="choice-option"||$==="multichoice-option"){let q=Z.getAttribute("data-md-label");return q?`[Option] ${q}`:null}if($==="userinput"){let q=Z.getAttribute("data-md-label");return q?`[Input] ${q}`:null}if($==="rangeinput"){let q=Z.getAttribute("data-md-label");return q?`[Range] ${q}`:null}if($==="image"){let q=Z.getAttribute("data-md-src");return q?`[Image] ${q}`:null}return null}function n8({containerRef:Z,hoveredBlock:$,focusedBlockIndex:q,blockPopover:Q,blockAnnotationMap:J,activeAnnotationId:Y,onOpen:X}){let[G,z]=j1([]);e1(()=>{let W=Z.current;if(!W||J.size===0){z([]);return}let K=[];for(let F of W.querySelectorAll(V2)){let N=G0(F);if(N&&J.has(N))K.push(F)}z(K)},[J,Z.current]);let[_,H]=j1(null);e1(()=>{if(!Y||!Z.current){H(null);return}for(let W of Z.current.querySelectorAll(I2)){let K=G0(W);if(K&&J.get(K)===Y){H(W);return}}H(null)},[Y,J]),e1(()=>{if(!_)return;return _.style.boxShadow="inset 0 0 0 1.5px var(--color-highlight-bg)",_.style.borderRadius="8px",()=>{_.style.boxShadow="",_.style.borderRadius=""}},[_]);let U=y0(()=>{if(q===null||!Z.current)return null;let W=n1(Z.current)[q];if(!W)return null;return W.matches(V2)?W:null},[q,Z.current]),T=y0(()=>{let W=new Set(G);if($)W.add($);if(U)W.add(U);if(Q?.anchorEl)W.add(Q.anchorEl);return Array.from(W)},[G,$,U,Q]);return J1(Z4,{children:T.map((W)=>J1(e8,{block:W,isHovered:W===$||W===U||W===Q?.anchorEl,blockAnnotationMap:J,activeAnnotationId:Y,onOpen:X},W.getAttribute("data-task-id")||W.getAttribute("data-md-title")||W.textContent?.slice(0,30)||"block",!1,void 0,this))},void 0,!1,void 0,this)}function e8({block:Z,isHovered:$,blockAnnotationMap:q,activeAnnotationId:Q,onOpen:J}){let Y=G0(Z);if(!Y)return null;let X=q.get(Y),G=!!X;return o8(J1("button",{"data-block-comment-btn":!0,onClick:(_)=>{_.stopPropagation(),J(_.currentTarget,Y,X)},className:`absolute top-1 right-1 z-10 w-6 h-6 flex items-center justify-center rounded transition-all duration-150 ${G?X===Q?"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:J1("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:G?"currentColor":"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:J1("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),Z)}function $4({note:Z,onSave:$,onCancel:q}){let[Q,J]=C2.useState(Z),Y=C2.useRef(null);return C2.useEffect(()=>{Y.current?.focus(),Y.current?.select()},[]),J1("div",{className:"fixed inset-0 z-50 bg-black/40 flex items-center justify-center",onClick:q,children:J1("div",{className:"bg-bg-elevated border border-border-hover rounded-lg shadow-md p-4 w-80",onClick:(X)=>X.stopPropagation(),children:[J1("div",{className:"text-tiny uppercase tracking-widest text-text-tertiary font-body mb-2",children:"Edit annotation"},void 0,!1,void 0,this),J1("textarea",{ref:Y,value:Q,onChange:(X)=>J(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))$(Q.trim());if(X.key==="Escape")q()}},void 0,!1,void 0,this),J1("div",{className:"flex justify-end gap-2 mt-2",children:[J1("button",{onClick:q,className:"text-meta text-text-tertiary font-body px-3 py-1",children:"Cancel"},void 0,!1,void 0,this),J1("button",{onClick:()=>$(Q.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 H4,{useRef as f3,useEffect as n0,useCallback as m2,useState as u1,useContext as e0,useMemo as W4}from"react";function b0(Z,$,q,Q,J){let Y=[],X=Z.filter((W)=>W.source!=="remote"||J&&J.has(W.id)),G=X.filter((W)=>W.filePath===T1),z=X.filter((W)=>!W.filePath),_=X.filter((W)=>W.filePath&&W.filePath!==T1),H=q?Array.from(q.values()).filter((W)=>D2(W)):[],U=Q?Array.from(Q.values()).filter((W)=>W.markdown.trim()):[];if(H.length>0||U.length>0){Y.push("## Responses"),Y.push("");for(let W of H)Y.push(Q4(W));for(let W of U)Y.push(W.markdown.trim()),Y.push("")}if(G.length>0){Y.push("## Annotations on agent response"),Y.push("");for(let W of G)Y.push(R2(W))}if(z.length>0){Y.push("## Canvas annotations"),Y.push("");let W=new Map;for(let N of z){let y=N.canvasFile||"";if(!W.has(y))W.set(y,[]);W.get(y).push(N)}let K=[...W.keys()].sort(),F=K.length>1||K.length===1&&K[0]!=="";for(let N of K){let y=W.get(N);if(F&&N)Y.push(`### ${N.replace(/\.jsx$/,"")}`),Y.push("");let O=Y4(y);Y.push(m3(O))}}if(_.length>0){let W={};for(let K of _){let F=K.filePath;if(!W[F])W[F]=[];W[F].push(K)}Y.push("## File annotations"),Y.push("");for(let[K,F]of Object.entries(W)){Y.push(`### ${K}`),Y.push("");for(let N of F)Y.push(R2(N))}}if($.trim())Y.push("## General notes"),Y.push(""),Y.push($.trim()),Y.push("");return Y.join(`
|
|
58
|
+
`}strong({tokens:Z}){return`<strong>${this.parser.parseInline(Z)}</strong>`}em({tokens:Z}){return`<em>${this.parser.parseInline(Z)}</em>`}codespan({text:Z}){return`<code>${b1(Z,!0)}</code>`}br(Z){return"<br>"}del({tokens:Z}){return`<del>${this.parser.parseInline(Z)}</del>`}link({href:Z,title:$,tokens:q}){let Q=this.parser.parseInline(q),J=J3(Z);if(J===null)return Q;Z=J;let Y='<a href="'+Z+'"';return $&&(Y+=' title="'+b1($)+'"'),Y+=">"+Q+"</a>",Y}image({href:Z,title:$,text:q,tokens:Q}){Q&&(q=this.parser.parseInline(Q,this.parser.textRenderer));let J=J3(Z);if(J===null)return b1(q);Z=J;let Y=`<img src="${Z}" alt="${b1(q)}"`;return $&&(Y+=` title="${b1($)}"`),Y+=">",Y}text(Z){return"tokens"in Z&&Z.tokens?this.parser.parseInline(Z.tokens):("escaped"in Z)&&Z.escaped?Z.text:b1(Z.text)}},j2=class{strong({text:Z}){return Z}em({text:Z}){return Z}codespan({text:Z}){return Z}del({text:Z}){return Z}html({text:Z}){return Z}text({text:Z}){return Z}link({text:Z}){return""+Z}image({text:Z}){return""+Z}br(){return""}checkbox({raw:Z}){return Z}},F1=class Z{options;renderer;textRenderer;constructor($){this.options=$||i1,this.options.renderer=this.options.renderer||new f0,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new j2}static parse($,q){return new Z(q).parse($)}static parseInline($,q){return new Z(q).parseInline($)}parse($){this.renderer.parser=this;let q="";for(let Q=0;Q<$.length;Q++){let J=$[Q];if(this.options.extensions?.renderers?.[J.type]){let X=J,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)){q+=G||"";continue}}let Y=J;switch(Y.type){case"space":{q+=this.renderer.space(Y);break}case"hr":{q+=this.renderer.hr(Y);break}case"heading":{q+=this.renderer.heading(Y);break}case"code":{q+=this.renderer.code(Y);break}case"table":{q+=this.renderer.table(Y);break}case"blockquote":{q+=this.renderer.blockquote(Y);break}case"list":{q+=this.renderer.list(Y);break}case"checkbox":{q+=this.renderer.checkbox(Y);break}case"html":{q+=this.renderer.html(Y);break}case"def":{q+=this.renderer.def(Y);break}case"paragraph":{q+=this.renderer.paragraph(Y);break}case"text":{q+=this.renderer.text(Y);break}default:{let X='Token with "'+Y.type+'" type was not found.';if(this.options.silent)return console.error(X),"";throw Error(X)}}}return q}parseInline($,q=this.renderer){this.renderer.parser=this;let Q="";for(let J=0;J<$.length;J++){let Y=$[J];if(this.options.extensions?.renderers?.[Y.type]){let G=this.options.extensions.renderers[Y.type].call({parser:this},Y);if(G!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(Y.type)){Q+=G||"";continue}}let X=Y;switch(X.type){case"escape":{Q+=q.text(X);break}case"html":{Q+=q.html(X);break}case"link":{Q+=q.link(X);break}case"image":{Q+=q.image(X);break}case"checkbox":{Q+=q.checkbox(X);break}case"strong":{Q+=q.strong(X);break}case"em":{Q+=q.em(X);break}case"codespan":{Q+=q.codespan(X);break}case"br":{Q+=q.br(X);break}case"del":{Q+=q.del(X);break}case"text":{Q+=q.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 Q}},M0=class{options;block;constructor(Z){this.options=Z||i1}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens","emStrongMask"]);static passThroughHooksRespectAsync=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(Z){return Z}postprocess(Z){return Z}processAllTokens(Z){return Z}emStrongMask(Z){return Z}provideLexer(Z=this.block){return Z?B1.lex:B1.lexInline}provideParser(Z=this.block){return Z?F1.parse:F1.parseInline}},j8=class{defaults=B2();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=F1;Renderer=f0;TextRenderer=j2;Lexer=B1;Tokenizer=g0;Hooks=M0;constructor(...Z){this.use(...Z)}walkTokens(Z,$){let q=[];for(let Q of Z)switch(q=q.concat($.call(this,Q)),Q.type){case"table":{let J=Q;for(let Y of J.header)q=q.concat(this.walkTokens(Y.tokens,$));for(let Y of J.rows)for(let X of Y)q=q.concat(this.walkTokens(X.tokens,$));break}case"list":{let J=Q;q=q.concat(this.walkTokens(J.items,$));break}default:{let J=Q;this.defaults.extensions?.childTokens?.[J.type]?this.defaults.extensions.childTokens[J.type].forEach((Y)=>{let X=J[Y].flat(1/0);q=q.concat(this.walkTokens(X,$))}):J.tokens&&(q=q.concat(this.walkTokens(J.tokens,$)))}}return q}use(...Z){let $=this.defaults.extensions||{renderers:{},childTokens:{}};return Z.forEach((q)=>{let Q={...q};if(Q.async=this.defaults.async||Q.async||!1,q.extensions&&(q.extensions.forEach((J)=>{if(!J.name)throw Error("extension name required");if("renderer"in J){let Y=$.renderers[J.name];Y?$.renderers[J.name]=function(...X){let G=J.renderer.apply(this,X);return G===!1&&(G=Y.apply(this,X)),G}:$.renderers[J.name]=J.renderer}if("tokenizer"in J){if(!J.level||J.level!=="block"&&J.level!=="inline")throw Error("extension level must be 'block' or 'inline'");let Y=$[J.level];Y?Y.unshift(J.tokenizer):$[J.level]=[J.tokenizer],J.start&&(J.level==="block"?$.startBlock?$.startBlock.push(J.start):$.startBlock=[J.start]:J.level==="inline"&&($.startInline?$.startInline.push(J.start):$.startInline=[J.start]))}"childTokens"in J&&J.childTokens&&($.childTokens[J.name]=J.childTokens)}),Q.extensions=$),q.renderer){let J=this.defaults.renderer||new f0(this.defaults);for(let Y in q.renderer){if(!(Y in J))throw Error(`renderer '${Y}' does not exist`);if(["options","parser"].includes(Y))continue;let X=Y,G=q.renderer[X],z=J[X];J[X]=(..._)=>{let H=G.apply(J,_);return H===!1&&(H=z.apply(J,_)),H||""}}Q.renderer=J}if(q.tokenizer){let J=this.defaults.tokenizer||new g0(this.defaults);for(let Y in q.tokenizer){if(!(Y in J))throw Error(`tokenizer '${Y}' does not exist`);if(["options","rules","lexer"].includes(Y))continue;let X=Y,G=q.tokenizer[X],z=J[X];J[X]=(..._)=>{let H=G.apply(J,_);return H===!1&&(H=z.apply(J,_)),H}}Q.tokenizer=J}if(q.hooks){let J=this.defaults.hooks||new M0;for(let Y in q.hooks){if(!(Y in J))throw Error(`hook '${Y}' does not exist`);if(["options","block"].includes(Y))continue;let X=Y,G=q.hooks[X],z=J[X];M0.passThroughHooks.has(Y)?J[X]=(_)=>{if(this.defaults.async&&M0.passThroughHooksRespectAsync.has(Y))return(async()=>{let U=await G.call(J,_);return z.call(J,U)})();let H=G.call(J,_);return z.call(J,H)}:J[X]=(..._)=>{if(this.defaults.async)return(async()=>{let U=await G.apply(J,_);return U===!1&&(U=await z.apply(J,_)),U})();let H=G.apply(J,_);return H===!1&&(H=z.apply(J,_)),H}}Q.hooks=J}if(q.walkTokens){let J=this.defaults.walkTokens,Y=q.walkTokens;Q.walkTokens=function(X){let G=[];return G.push(Y.call(this,X)),J&&(G=G.concat(J.call(this,X))),G}}this.defaults={...this.defaults,...Q}}),this}setOptions(Z){return this.defaults={...this.defaults,...Z},this}lexer(Z,$){return B1.lex(Z,$??this.defaults)}parser(Z,$){return F1.parse(Z,$??this.defaults)}parseMarkdown(Z){return($,q)=>{let Q={...q},J={...this.defaults,...Q},Y=this.onError(!!J.silent,!!J.async);if(this.defaults.async===!0&&Q.async===!1)return Y(Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(typeof $>"u"||$===null)return Y(Error("marked(): input parameter is undefined or null"));if(typeof $!="string")return Y(Error("marked(): input parameter is of type "+Object.prototype.toString.call($)+", string expected"));if(J.hooks&&(J.hooks.options=J,J.hooks.block=Z),J.async)return(async()=>{let X=J.hooks?await J.hooks.preprocess($):$,G=await(J.hooks?await J.hooks.provideLexer(Z):Z?B1.lex:B1.lexInline)(X,J),z=J.hooks?await J.hooks.processAllTokens(G):G;J.walkTokens&&await Promise.all(this.walkTokens(z,J.walkTokens));let _=await(J.hooks?await J.hooks.provideParser(Z):Z?F1.parse:F1.parseInline)(z,J);return J.hooks?await J.hooks.postprocess(_):_})().catch(Y);try{J.hooks&&($=J.hooks.preprocess($));let X=(J.hooks?J.hooks.provideLexer(Z):Z?B1.lex:B1.lexInline)($,J);J.hooks&&(X=J.hooks.processAllTokens(X)),J.walkTokens&&this.walkTokens(X,J.walkTokens);let G=(J.hooks?J.hooks.provideParser(Z):Z?F1.parse:F1.parseInline)(X,J);return J.hooks&&(G=J.hooks.postprocess(G)),G}catch(X){return Y(X)}}}onError(Z,$){return(q)=>{if(q.message+=`
|
|
59
|
+
Please report this to https://github.com/markedjs/marked.`,Z){let Q="<p>An error occurred:</p><pre>"+b1(q.message+"",!0)+"</pre>";return $?Promise.resolve(Q):Q}if($)return Promise.reject(q);throw q}}},r1=new j8;function e(Z,$){return r1.parse(Z,$)}e.options=e.setOptions=function(Z){return r1.setOptions(Z),e.defaults=r1.defaults,X3(e.defaults),e};e.getDefaults=B2;e.defaults=i1;e.use=function(...Z){return r1.use(...Z),e.defaults=r1.defaults,X3(e.defaults),e};e.walkTokens=function(Z,$){return r1.walkTokens(Z,$)};e.parseInline=r1.parseInline;e.Parser=F1;e.parser=F1.parse;e.Renderer=f0;e.TextRenderer=j2;e.Lexer=B1;e.lexer=B1.lex;e.Tokenizer=g0;e.Hooks=M0;e.parse=e;var{options:h6,setOptions:p6,use:c6,walkTokens:d6,parseInline:l6}=e;var r6=F1.parse,i6=B1.lex;import{SessionContext as E5,ActiveViewCtx as x6}from"#canvas/runtime";import{useState as S0,useCallback as j1,useEffect as A8,useRef as C8,useMemo as V8}from"react";import{AnnotationCtx as I8}from"#canvas/runtime";function R1(Z,$,q="current"){let Q=`canvas:${Z}:rev:${$}`;return q==="next"?`${Q}:next-draft`:Q}function X0(Z,$){return`${R1(Z,$)}:draft-handled`}function z0(Z,$,q){try{Z.removeItem(R1($,q)),Z.removeItem(X0($,q))}catch{}}function w2(Z){if(!Z)return null;try{let $=JSON.parse(Z);return typeof $==="object"&&$!==null&&!Array.isArray($)?$:null}catch{return null}}function w8(Z){if(!Array.isArray(Z)||Z.length<2)return!1;let $=Z[1];if(typeof $!=="object"||$===null||Array.isArray($))return!1;let q=Reflect.get($,"note");if(typeof q==="string"&&q.trim().length>0)return!0;let Q=Reflect.get($,"value");if(typeof Q==="string")return Q.trim().length>0;if(Array.isArray(Q))return Q.length>0;return Q!==null&&Q!==void 0}function A2(Z){if(!Z)return!1;let $=Reflect.get(Z,"annotations");if(Array.isArray($)&&$.length>0)return!0;let q=Reflect.get(Z,"generalNote");if(typeof q==="string"&&q.trim().length>0)return!0;let Q=Reflect.get(Z,"responses");return Array.isArray(Q)&&Q.some(w8)}function C2(Z,$,q,Q){try{let J=R1($,q);if(A2(w2(Z.getItem(J))))return Z.setItem(X0($,q),"1"),null;if(Z.getItem(X0($,q))!==null)return null;let Y=Q.filter((X)=>X.revision<q).sort((X,G)=>G.revision-X.revision);for(let X of Y){if(X.hasFeedback){let z=R1($,X.revision,"next"),_=w2(Z.getItem(z));if(!A2(_))return null;return Z.setItem(J,JSON.stringify({..._,feedbackEntries:[]})),Z.setItem(X0($,q),"1"),Z.removeItem(z),X.revision}let G=w2(Z.getItem(R1($,X.revision)));if(!A2(G)){if(Z.getItem(X0($,X.revision))!==null)return null;continue}return Z.setItem(J,JSON.stringify({...G,feedbackEntries:[]})),Z.setItem(X0($,q),"1"),X.revision}}catch{}return null}var T1="__agent-response__";function L1(){return`ann-${Date.now()}-${Math.random().toString(36).slice(2,6)}`}function y0(Z,$){Z.style.height="auto",Z.style.height=($?Math.max($,Z.scrollHeight):Z.scrollHeight)+"px"}import{useAnnotations as X1}from"#canvas/runtime";import{jsxDEV as D8}from"react/jsx-dev-runtime";function p0(Z,$,q){try{let Q=localStorage.getItem(R1(Z,$,q));if(!Q)return null;return JSON.parse(Q)}catch{return null}}function O3(Z,$,q,Q){try{localStorage.setItem(R1(Z,$,q),JSON.stringify(Q))}catch{}}function B3({sessionId:Z,revision:$,isReadOnly:q,draftPhase:Q,remoteAnnotations:J,children:Y}){let[X,G]=S0(()=>{return(p0(Z,$,Q)?.annotations??[]).map((E)=>({...E,source:E.source??"local"}))}),z=V8(()=>{if(!J||J.length===0)return X;let V=new Set(X.map((c)=>c.id)),E=J.filter((c)=>!V.has(c.id));return[...X,...E.map((c)=>({...c,source:"remote"}))]},[X,J]),[_,H]=S0(()=>{return p0(Z,$,Q)?.generalNote??""}),[U,W]=S0(null),[T,K]=S0(()=>{let V=p0(Z,$,Q);return V?.responses?new Map(V.responses):new Map}),[L,N]=S0(()=>{let V=p0(Z,$,Q);return V?.feedbackEntries?new Map(V.feedbackEntries):new Map}),S=C8(null);A8(()=>{if(q&&Q!=="next")return;if(S.current)clearTimeout(S.current);let V={annotations:X,generalNote:_,responses:Array.from(T.entries()),feedbackEntries:Array.from(L.entries())};if(Q==="next"){O3(Z,$,Q,V);return}return S.current=setTimeout(()=>O3(Z,$,Q,V),300),()=>{if(S.current)clearTimeout(S.current)}},[X,_,T,L,Z,$,q,Q]);let O=j1((V,E,c,P,x,f,o)=>{G((w)=>[...w,{id:V,snippet:E,note:c,createdAt:new Date().toISOString(),filePath:P,context:x,...f?.length?{images:f}:{},...o?{canvasFile:o}:{}}])},[]),R=j1((V,E,c)=>{O(L1(),V,E,c)},[O]),b=j1((V,E)=>{G((c)=>c.map((P)=>P.id===V?{...P,note:E}:P))},[]),M=j1((V)=>{R8(V),G((E)=>E.filter((c)=>c.id!==V)),W((E)=>E===V?null:E)},[]),j=j1((V,E)=>{G((c)=>c.map((P)=>P.id===V?{...P,images:[...P.images||[],E]}:P))},[]),g=j1((V,E)=>{G((c)=>c.map((P)=>P.id===V?{...P,images:(P.images||[]).filter((x)=>x!==E)}:P))},[]),C=j1((V,E)=>{K((c)=>{let P=new Map(c);return P.set(V,E),P})},[]),h=j1((V,E)=>{N((c)=>{let P=c.get(V);if(P&&P.markdown===E.markdown&&P.label===E.label&&P.required===E.required)return c;let x=new Map(c);return x.set(V,E),x})},[]),v=j1((V)=>{N((E)=>{if(!E.has(V))return E;let c=new Map(E);return c.delete(V),c})},[]),l=j1(()=>{for(let V of document.querySelectorAll("[data-annotation-id]"))F3(V);if(G([]),H(""),W(null),K(new Map),N(new Map),Q==="next")localStorage.removeItem(R1(Z,$,Q));else z0(localStorage,Z,$)},[Z,$,Q]);return D8(I8.Provider,{value:{annotations:z,addAnnotation:R,addAnnotationWithId:O,updateAnnotation:b,removeAnnotation:M,addAnnotationImage:j,removeAnnotationImage:g,generalNote:_,setGeneralNote:H,clearAll:l,activeAnnotationId:U,setActiveAnnotationId:W,responses:T,setResponse:C,feedbackEntries:L,setFeedbackEntry:h,removeFeedbackEntry:v},children:Y},void 0,!1,void 0,this)}function R8(Z){let $=document.querySelectorAll(`[data-annotation-id="${Z}"]`);for(let q of $)F3(q)}function F3(Z){let $=Z.parentNode;if(!$)return;let q=document.createTextNode(Z.textContent||"");$.replaceChild(q,Z),$.normalize()}import n0,{useEffect as $0,useState as w1,useRef as Z4,useContext as v3,useMemo as j0}from"react";import{createPortal as q4}from"react-dom";import{SessionContext as J4,CanvasFileCtx as Q4}from"#canvas/runtime";function a1(Z,$){let q=L3(Z,"before",60),Q=L3(Z,"after",60),J=E8(Z.startContainer,$);return{before:q,after:Q,hierarchy:J}}function L3(Z,$,q){let Q=k8($==="before"?Z.startContainer:Z.endContainer);if(!Q)return"";let J="";if($==="before"){let Y=document.createTreeWalker(Q,NodeFilter.SHOW_TEXT),X;while(X=Y.nextNode()){if(X===Z.startContainer){J+=(X.textContent||"").slice(0,Z.startOffset);break}if(X.parentElement?.hasAttribute("data-annotation-id"))continue;J+=X.textContent||""}if(J.length>q){J=J.slice(-q);let G=J.indexOf(" ");if(G>0)J=J.slice(G+1)}}else{let Y=document.createTreeWalker(Q,NodeFilter.SHOW_TEXT),X=!1,G;while(G=Y.nextNode()){if(G===Z.endContainer){J+=(G.textContent||"").slice(Z.endOffset),X=!0;continue}if(X){if(G.parentElement?.hasAttribute("data-annotation-id"))continue;J+=G.textContent||""}}if(J.length>q){J=J.slice(0,q);let z=J.lastIndexOf(" ");if(z>0)J=J.slice(0,z)}}return J.trim()}function k8(Z){let $=new Set(["DIV","P","LI","PRE","BLOCKQUOTE","SECTION","ARTICLE"]),q=Z.parentElement;while(q){if($.has(q.tagName))return q;q=q.parentElement}return null}function E8(Z,$){let q=[],Q=Z instanceof Element?Z:Z.parentElement;while(Q&&Q!==$){let J=Q.getAttribute?.("data-task-id");if(J){let Y=Q.querySelector(".font-semibold");if(Y)q.unshift(Y.textContent?.trim()||J)}if(Q.tagName==="DIV"&&Q.querySelector(":scope > button .font-heading, :scope > div .font-heading")){let Y=Q.querySelector(".font-heading");if(Y)q.unshift(Y.textContent?.trim()||"")}Q=Q.parentElement}return q}function V2(Z){let $=Z.snippet.trim(),q=Z.context,Q=$.length<30;if(q&&Q&&(q.before||q.after)){let J=[];if(q.before)J.push(`...${q.before} `);if(J.push(`**${$}**`),q.after)J.push(` ${q.after}...`);return J.join("")}return $}import{useEffect as l8,useRef as l0,useState as _0,useCallback as d0,useMemo as k3,useContext as r8}from"react";import{createPortal as i8}from"react-dom";function M3(Z,$){let J=$||document.body,Y=Z.getBoundingClientRect(),X=J.getBoundingClientRect(),G=J===document.body?window.scrollY:J.scrollTop,z=Y.bottom-X.top+G+8,_=Math.max(0,Math.min(Y.left-X.left,X.width-280-12));return J.style.position="relative",{style:{position:"absolute",top:`${z}px`,left:`${_}px`},parent:J}}import{useState as R2,useRef as D2,useCallback as D1,useEffect as c8}from"react";var P3={alg:"AES-GCM",v:1};async function y3(Z){let $=m8(Z);return crypto.subtle.importKey("raw",$,{name:"AES-GCM",length:256},!1,["encrypt","decrypt"])}async function g1(Z,$){let q=crypto.getRandomValues(new Uint8Array(12)),Q=new TextEncoder().encode($),J=await crypto.subtle.encrypt({name:"AES-GCM",iv:q},Z,Q),Y=new Uint8Array(q.byteLength+J.byteLength);return Y.set(q,0),Y.set(new Uint8Array(J),q.byteLength),x8(Y)}async function b0(Z,$){let q=S3($);if(q.byteLength<28)throw Error("Ciphertext too short");let Q=q.subarray(0,12),J=q.subarray(12),Y=await crypto.subtle.decrypt({name:"AES-GCM",iv:Q},Z,J);return new TextDecoder().decode(Y)}function x8(Z){let $="",q=32768;for(let Q=0;Q<Z.byteLength;Q+=q)$+=String.fromCharCode.apply(null,Array.from(Z.subarray(Q,Q+q)));return btoa($)}function S3(Z){let $=atob(Z),q=new Uint8Array($.length);for(let Q=0;Q<$.length;Q++)q[Q]=$.charCodeAt(Q);return q}function m8(Z){let $=Z.replace(/-/g,"+").replace(/_/g,"/")+"===".slice((Z.length+3)%4);return S3($)}function u8(){if(typeof window>"u")return null;let Z=window.location.hash.replace(/^#/,"");if(!Z)return null;for(let $ of Z.split("&")){let[q,Q]=$.split("=");if(q==="k"&&Q)return decodeURIComponent(Q)}return null}function g8(){if(typeof window<"u"&&window.__CANVAS_SHARE__?.shareId){let $=u8();return{isShared:!0,shareId:window.__CANVAS_SHARE__.shareId,encryptionKey:$?y3($):null}}return{isShared:!1,sessionId:typeof window<"u"?window.location.pathname.replace("/s/",""):""}}var $1=g8();function f8(){return $1.isShared&&$1.encryptionKey!==null}function v8(){if($1.isShared)return`/s/${$1.shareId}/meta`;return`/api/session/${$1.sessionId}/meta`}function h8(Z,$){let q=Z.replace(/\.jsx$/,".js");if($1.isShared)return`/s/${$1.shareId}/canvas/${encodeURIComponent(q)}`;let Q=$?`?rev=${$}&t=${Date.now()}`:`?t=${Date.now()}`;return`/api/session/${$1.sessionId}/canvas/${encodeURIComponent(q)}${Q}`}function b3(){if($1.isShared)return`/s/${$1.shareId}/upload`;return`/api/session/${$1.sessionId}/upload`}async function j3(){let Z=await fetch(v8());if(!Z.ok)throw Error(`meta ${Z.status}`);let $=await Z.json();if($.encryption&&$1.isShared&&$1.encryptionKey){let q=await $1.encryptionKey;if($.origin){let J={...$.origin};if(J.sessionId)J.sessionId=await b0(q,J.sessionId);if(J.label)J.label=await b0(q,J.label);$.origin=J}let Q=$.revisions;if(Array.isArray(Q)){for(let J of Q)if(J.label)try{J.label=await b0(q,J.label)}catch{}}}return $}async function w3(Z,$){let q=h8(Z,$);if(!f8())return import(q);let Q=await fetch(q);if(!Q.ok)throw Error(`canvas ${Q.status}`);let J=await Q.text(),Y=await $1.encryptionKey,X=await b0(Y,J),G=new Blob([X],{type:"application/javascript"}),z=URL.createObjectURL(G);try{return await import(z)}finally{setTimeout(()=>URL.revokeObjectURL(z),0)}}var A3="canvas-reviewer-identity";function I2(){try{let Z=localStorage.getItem(A3);if(!Z)return null;return JSON.parse(Z)}catch{return null}}function C3(Z){let $=I2();if(!$)$={id:crypto.randomUUID?.()||String(Date.now()),name:Z};else $.name=Z;return localStorage.setItem(A3,JSON.stringify($)),$}async function p8(Z,$){let q=await Promise.all(Z.annotations.map(async(Q)=>{let J={id:Q.id,createdAt:Q.createdAt,snippet:await g1($,String(Q.snippet??"")),note:await g1($,String(Q.note??""))};if(Q.filePath)J.filePath=await g1($,String(Q.filePath));if(Q.canvasFile)J.canvasFile=await g1($,String(Q.canvasFile));if(Q.context!==void 0&&Q.context!==null)J.context=await g1($,JSON.stringify(Q.context));if(Q.attachments)J.attachments=Q.attachments;return J}));return{author:{id:Z.author.id,name:await g1($,Z.author.name)},revision:Z.revision,annotations:q,...Z.generalNote?{generalNote:await g1($,Z.generalNote)}:{},encryption:P3}}async function V3(Z){if(!$1.isShared)throw Error("submitSharedFeedback called outside shared mode");let $=Z;if($1.encryptionKey){let Q=await $1.encryptionKey;$=await p8(Z,Q)}let q=await fetch(`/s/${$1.shareId}/feedback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify($)});if(!q.ok){let Q=await q.text().catch(()=>"");throw Error(`Feedback submission failed: ${q.status} ${Q}`)}}var M1=!$1.isShared,I3=!$1.isShared;import{jsxDEV as _1}from"react/jsx-dev-runtime";function R3(Z){if(Z.startsWith("/s/")||Z.startsWith("http://")||Z.startsWith("https://"))return Z;return`/api/uploads/${Z.split("/").pop()}`}async function d8(Z,$){let q=new FormData;q.append("image",$);try{let J=await(await fetch(b3(),{method:"POST",body:q})).json();if($1.isShared)return J.url||null;return J.path||null}catch{return null}}function c0({note:Z,onNoteChange:$,images:q,onAddImage:Q,onRemoveImage:J,sessionId:Y,placeholder:X="Add your note...",autoFocus:G=!1,autoResize:z=!1,readOnly:_=!1,onKeyDown:H,onTextareaClick:U,textareaRef:W,textareaClassName:T,textareaStyle:K,minHeight:L,attachButton:N="always",openFilePickerRef:S}){let[O,R]=R2(!1),[b,M]=R2(!1),[j,g]=R2(!1),C=D2(0),h=D2(null),v=D2(null),l=D1(()=>v.current?.click(),[]);if(S)S.current=l;let V=D1((D)=>{if(h.current=D,W)W.current=D;if(D&&z)y0(D,L)},[W,z,L]);c8(()=>{if(G&&h.current){let D=h.current;if(D.focus(),D.value)D.setSelectionRange(D.value.length,D.value.length)}},[G]);let E=D1(async(D)=>{if(!D.type.startsWith("image/"))return;M(!0);try{let a=await d8(Y,D);if(a)Q(a)}finally{M(!1)}},[Y,Q]),c=D1((D)=>{let a=D.clipboardData.items;for(let I of a)if(I.type.startsWith("image/")){D.preventDefault();let k=I.getAsFile();if(k)E(k);return}},[E]),P=D1((D)=>{if(D.preventDefault(),C.current++,C.current===1)R(!0)},[]),x=D1((D)=>{D.preventDefault()},[]),f=D1((D)=>{if(D.preventDefault(),C.current--,C.current===0)R(!1)},[]),o=D1((D)=>{D.preventDefault(),C.current=0,R(!1);for(let a of D.dataTransfer.files)if(a.type.startsWith("image/"))E(a)},[E]),w=D1((D)=>{if($(D.target.value),z)D.target.style.height="auto",D.target.style.height=(L?Math.max(L,D.target.scrollHeight):D.target.scrollHeight)+"px"},[$,z,L]),F="w-full bg-transparent text-[13px] font-body text-text-primary resize-none focus:outline-none leading-relaxed p-0 border-none",m={width:"100%",background:"transparent",border:"none",color:"var(--color-text-primary)",fontFamily:"'Inter', sans-serif",fontSize:"13px",lineHeight:"1.5",outline:"none",...z?{resize:"none",overflow:"hidden"}:{resize:"vertical"}},u=!_&&(N==="always"||N==="on-focus"&&j);return _1("div",{style:{position:"relative"},onDragEnter:_?void 0:P,onDragOver:_?void 0:x,onDragLeave:_?void 0:f,onDrop:_?void 0:o,children:[_1("textarea",{ref:V,value:Z,onChange:_?void 0:w,onPaste:_?void 0:c,onKeyDown:H,onClick:U,onFocus:()=>g(!0),onBlur:()=>{setTimeout(()=>g(!1),150)},readOnly:_,placeholder:X,className:T??F,style:K??m,rows:z?1:void 0},void 0,!1,void 0,this),!_&&_1("input",{ref:v,type:"file",accept:"image/*",multiple:!0,style:{display:"none"},onChange:(D)=>{let a=D.target.files;if(a)for(let I of a)E(I);D.target.value=""}},void 0,!1,void 0,this),(q.length>0||u)&&_1("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"6px",alignItems:"center"},children:[q.map((D)=>_1("div",{style:{position:"relative",width:"56px",height:"56px",borderRadius:"6px",overflow:"hidden",border:"1px solid var(--color-border-subtle)",flexShrink:0},children:[_1("img",{src:R3(D),alt:"",style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}},void 0,!1,void 0,this),!_&&_1("button",{onClick:(a)=>{a.stopPropagation(),J(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)),u&&_1(k2,{onClick:l},void 0,!1,void 0,this)]},void 0,!0,void 0,this),b&&_1("div",{style:{fontSize:"11px",color:"var(--color-text-tertiary)",fontFamily:"'Inter', sans-serif",marginTop:"4px"},children:"Uploading..."},void 0,!1,void 0,this),O&&_1("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 k2({onClick:Z,size:$=16}){return _1("button",{onClick:(q)=>{q.stopPropagation(),Z()},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:(q)=>{q.currentTarget.style.color="var(--color-text-secondary)"},onMouseLeave:(q)=>{q.currentTarget.style.color="var(--color-text-tertiary)"},children:_1("svg",{width:$,height:$,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[_1("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"},void 0,!1,void 0,this),_1("circle",{cx:"8.5",cy:"8.5",r:"1.5"},void 0,!1,void 0,this),_1("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 D3({images:Z}){if(!Z.length)return null;return _1("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"6px"},children:Z.map(($)=>_1("div",{style:{width:"56px",height:"56px",borderRadius:"6px",overflow:"hidden",border:"1px solid var(--color-border-subtle)",flexShrink:0},children:_1("img",{src:R3($),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 a8}from"#canvas/runtime";import{jsxDEV as G1,Fragment as s8}from"react/jsx-dev-runtime";function o8({anchorEl:Z,scrollContainer:$,onClose:q,ignoreSelector:Q,zIndex:J="50",padding:Y="12px",width:X="280px",children:G}){let z=l0(null),_=l0(q);_.current=q;let{style:H,parent:U}=M3(Z,$);return l8(()=>{let W=setTimeout(()=>{let T=(K)=>{if(z.current&&!z.current.contains(K.target)){if(Q&&K.target.closest?.(Q))return;_.current(),document.removeEventListener("mousedown",T)}};return document.addEventListener("mousedown",T),()=>document.removeEventListener("mousedown",T)},0);return()=>clearTimeout(W)},[Q]),i8(G1("div",{ref:z,style:{...H,zIndex:J,width:X,background:"var(--color-bg-elevated)",border:"1px solid var(--color-border-hover)",borderRadius:"8px",boxShadow:"0 4px 12px var(--color-shadow)",padding:Y,fontFamily:"'Inter', sans-serif"},children:G},void 0,!1,void 0,this),U)}var x3=[{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"]}],E3=x3.flatMap((Z)=>Z.items);function m3({anchorEl:Z,scrollContainer:$,snippet:q,truncateAt:Q=100,header:J,initialNote:Y="",initialImages:X,onConfirm:G,onCancel:z,onDelete:_}){let H=r8(a8),U=Y!==""||!!_,[W,T]=_0(Y),[K,L]=_0(X||[]),[N,S]=_0(null),[O,R]=_0(U),[b,M]=_0(!1),j=l0(null),g=l0(null),C=d0(()=>{if(W.trim()||K.length>0)G(W.trim(),K);else if(U&&_)_();else z()},[W,K,G,z,U,_]),h=d0(()=>{if(U){if(!W.trim()&&K.length===0&&_){_(),z();return}G(W,K);return}z()},[W,K,U,G,z,_]),v=!U,l=W.trim().length>0?E3.filter((I)=>I.toLowerCase().startsWith(W.trim().toLowerCase())):E3,V=!v||O?[]:l.length===1&&l[0].toLowerCase()===W.trim().toLowerCase()?[]:l,E=new Set(V),c=x3.map((I)=>({label:I.label,items:I.items.filter((k)=>E.has(k))})).filter((I)=>I.items.length>0),P=c.map((I)=>I.items),x=P.flat(),f=k3(()=>{if(N===null)return 0;let I=0;for(let k=0;k<P.length;k++){if(N<I+P[k].length)return k;I+=P[k].length}return 0},[N,P]),o=k3(()=>{if(N===null)return 0;let I=0;for(let k=0;k<f;k++)I+=P[k].length;return N-I},[N,f,P]),w=(I,k)=>{let Z1=0;for(let Y1=0;Y1<I;Y1++)Z1+=P[Y1].length;return Z1+k},[F,m]=_0(W);if(W!==F)m(W),S(null),R(U);let u=d0((I)=>{T(I)},[]),D=q.length>Q?q.slice(0,Q)+"...":q,a=d0((I)=>{if(x.length>0&&(I.key==="ArrowDown"||I.key==="ArrowUp"||I.key==="ArrowLeft"||I.key==="ArrowRight")){if(I.preventDefault(),N===null){S(0);return}if(I.key==="ArrowDown"){let k=Math.min(o+1,P[f].length-1);S(w(f,k))}else if(I.key==="ArrowUp"){let k=Math.max(o-1,0);S(w(f,k))}else if(I.key==="ArrowRight"){let k=Math.min(f+1,P.length-1),Z1=Math.min(o,P[k].length-1);S(w(k,Z1))}else if(I.key==="ArrowLeft"){let k=Math.max(f-1,0),Z1=Math.min(o,P[k].length-1);S(w(k,Z1))}return}if(N!==null&&x.length>0){if(I.key==="Tab"){I.preventDefault(),u(x[N]);return}if(I.key==="Enter"&&!I.shiftKey){I.preventDefault(),G(x[N],K);return}}if(I.key==="Enter"&&!I.shiftKey){I.preventDefault(),C();return}if(I.key==="Escape")if(x.length>0&&!O)R(!0);else if(U)h();else z()},[x,N,o,f,P,w,u,G,K,C,O,U,h,z]);return G1(o8,{anchorEl:Z,scrollContainer:$,onClose:U?h:z,ignoreSelector:U?"[data-annotation-id]":void 0,zIndex:U?"60":"50",padding:U?"10px 12px":"12px",width:"420px",children:[!U&&(J??G1("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)),G1(c0,{note:W,onNoteChange:T,images:K,onAddImage:(I)=>L((k)=>[...k,I]),onRemoveImage:(I)=>L((k)=>k.filter((Z1)=>Z1!==I)),sessionId:H,autoFocus:!0,autoResize:U,textareaRef:j,onKeyDown:a,attachButton:"none",openFilePickerRef:g,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),G1("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginTop:U?"6px":"8px"},children:[G1(k2,{onClick:()=>g.current?.(),size:14},void 0,!1,void 0,this),G1("div",{style:{flex:1}},void 0,!1,void 0,this),U?G1("button",{onClick:()=>{if(_)_();z()},onMouseEnter:()=>M(!0),onMouseLeave:()=>M(!1),style:{fontSize:"11px",color:b?"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):G1(s8,{children:[G1("button",{onClick:z,style:{fontSize:"11px",color:"var(--color-text-tertiary)",background:"none",border:"none",cursor:"pointer",padding:"4px 12px",fontFamily:"'Inter', sans-serif"},children:"Cancel"},void 0,!1,void 0,this),G1("button",{onClick:C,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&&G1("div",{style:{marginTop:"6px",borderTop:"1px solid var(--color-border-subtle)",paddingTop:"8px",display:"flex",gap:"4px"},children:c.map((I)=>G1("div",{style:{flex:1},children:[G1("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:I.label},void 0,!1,void 0,this),I.items.map((k)=>{let Z1=x.indexOf(k);return G1("div",{onMouseDown:(Y1)=>{Y1.preventDefault(),Y1.stopPropagation(),u(k)},onMouseEnter:()=>S(Z1),style:{padding:"3px 6px",fontSize:"12px",borderRadius:"4px",fontFamily:"'Inter', sans-serif",color:Z1===N?"var(--color-text-primary)":"var(--color-text-secondary)",background:Z1===N?"var(--color-highlight-selected)":"transparent",cursor:"pointer"},children:[G1("span",{style:{fontWeight:500},children:k.slice(0,W.trim().length)},void 0,!1,void 0,this),k.slice(W.trim().length)]},k,!0,void 0,this)})]},I.label,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function G0({anchorEl:Z,scrollContainer:$,snippet:q,truncateAt:Q,header:J,onAdd:Y,onCancel:X}){return G1(m3,{anchorEl:Z,scrollContainer:$,snippet:q,truncateAt:Q,header:J,onConfirm:(G,z)=>Y(G,z),onCancel:X},void 0,!1,void 0,this)}function U0({anchorEl:Z,scrollContainer:$,initialNote:q,initialImages:Q,onUpdate:J,onDelete:Y,onClose:X}){return G1(m3,{anchorEl:Z,scrollContainer:$,snippet:"",initialNote:q,initialImages:Q,onConfirm:(G,z)=>{J(G,z),X()},onDelete:Y,onCancel:X},void 0,!1,void 0,this)}import{useEffect as s0,useState as g3,useRef as t1,useCallback as f3}from"react";function s1(Z,$){let q=[],Q=t8(Z);for(let J of Q){let Y=document.createRange();if(Y.selectNodeContents(J),J===Z.startContainer)Y.setStart(J,Z.startOffset);if(J===Z.endContainer)Y.setEnd(J,Z.endOffset);let X=Y.toString();if(!X||!X.trim())continue;let G=document.createElement("mark");G.setAttribute("data-annotation-id",$);try{Y.surroundContents(G)}catch{let z=Y.extractContents();G.appendChild(z),Y.insertNode(G)}q.push(G)}return q}function t8(Z){let $=[],q=Z.commonAncestorContainer;if(q.nodeType===Node.TEXT_NODE)return $.push(q),$;let Q=document.createTreeWalker(q,NodeFilter.SHOW_TEXT),J;while(J=Q.nextNode()){let Y=J.parentElement;if(Y?.classList.contains("select-none"))continue;if(Y?.closest("[data-annotation-id]"))continue;if(Z.intersectsNode(J))$.push(J)}return $}function o1(Z,$){let q=document.querySelectorAll(`[data-annotation-id="${Z}"]`);for(let Q of q)Q.classList.toggle("mark-active",$)}function r0(Z,$){if($!=null&&$!==Z)o1($,!1);if(Z!=null)o1(Z,!0)}function i0(Z,$){let q=document.querySelectorAll(`[data-annotation-id="${Z}"]`);for(let Q of q)Q.setAttribute("data-annotation-id",$)}function a0(Z,$){for(let q of $){if(Z.querySelector(`[data-annotation-id="${q.id}"]`))continue;let Q=q.snippet;if(!Q)continue;let{fullText:J,textNodes:Y}=n8(Z),X=[],G=0;while(!0){let T=J.indexOf(Q,G);if(T===-1)break;X.push(T),G=T+1}if(X.length===0)continue;let z=X[0];if(X.length>1&&q.context){let T=-1;for(let K of X){let L=0;if(q.context.before){let N=J.slice(Math.max(0,K-80),K);if(N.includes(q.context.before))L+=2;else if(q.context.before.length>10&&N.includes(q.context.before.slice(-10)))L+=1}if(q.context.after){let N=J.slice(K+Q.length,K+Q.length+80);if(N.includes(q.context.after))L+=2;else if(q.context.after.length>10&&N.includes(q.context.after.slice(0,10)))L+=1}if(L>T)T=L,z=K}}let _=z,H=z+Q.length,U=u3(Y,_),W=u3(Y,H);if(!U||!W)continue;try{let T=document.createRange();T.setStart(U.node,U.offset),T.setEnd(W.node,W.offset),s1(T,q.id)}catch{}}}function n8(Z){let $=[],q="",Q=document.createTreeWalker(Z,NodeFilter.SHOW_TEXT),J;while(J=Q.nextNode()){let Y=J.parentElement;if(Y?.classList.contains("select-none"))continue;if(Y?.closest("[data-annotation-id]"))continue;$.push({node:J,start:q.length}),q+=J.textContent||""}return{fullText:q,textNodes:$}}function u3(Z,$){for(let q=Z.length-1;q>=0;q--)if(Z[q].start<=$){let Q=$-Z[q].start,J=Z[q].node.textContent?.length??0;if(Q<=J)return{node:Z[q].node,offset:Q}}return null}function o0(Z){let $=document.querySelectorAll(`[data-annotation-id="${Z}"]`);for(let q of $){let Q=q.parentNode;if(!Q)continue;while(q.firstChild)Q.insertBefore(q.firstChild,q);Q.removeChild(q),Q.normalize()}}import{jsxDEV as E2,Fragment as e8}from"react/jsx-dev-runtime";function n1(Z){let{containerRef:$,restoreKey:q,restoreAnnotations:Q,extractContext:J,filePath:Y,canvasFile:X,scrollContainer:G}=Z,{annotations:z,addAnnotationWithId:_,removeAnnotation:H,updateAnnotation:U,addAnnotationImage:W,removeAnnotationImage:T,activeAnnotationId:K,setActiveAnnotationId:L}=X1(),[N,S]=g3(null),[O,R]=g3(null),b=t1(J);b.current=J;let M=t1(Y);M.current=Y;let j=t1(X);j.current=X;let g=t1(_);g.current=_;let C=t1(K);C.current=K;let h=t1(L);h.current=L;let v=Q.length;s0(()=>{if(!$.current)return;let P=setTimeout(()=>{if($.current)a0($.current,Q)},50);return()=>clearTimeout(P)},[q,v]);let l=t1(null);s0(()=>{r0(K,l.current),l.current=K},[K]),s0(()=>{let P=$.current;if(!P)return;let x=(w)=>{let F=w.target.closest("[data-annotation-id]");if(!F)return;w.stopPropagation();let m=F.getAttribute("data-annotation-id");if(m===C.current)S({anchorEl:F,annId:m});else h.current(m)},f=(w)=>{let F=w.target.closest("[data-annotation-id]");if(F)h.current(F.getAttribute("data-annotation-id"))},o=(w)=>{let F=w.target.closest("[data-annotation-id]"),m=w.relatedTarget?.closest?.("[data-annotation-id]");if(F&&!m&&!document.getElementById("ann-inline-popover"))h.current(null)};return P.addEventListener("click",x),P.addEventListener("mouseover",f),P.addEventListener("mouseout",o),()=>{P.removeEventListener("click",x),P.removeEventListener("mouseover",f),P.removeEventListener("mouseout",o)}},[q]),s0(()=>{let P=()=>V();return document.addEventListener("mouseup",P),()=>document.removeEventListener("mouseup",P)},[]);let V=f3(()=>{let P=window.getSelection();if(!P||P.isCollapsed||!P.toString().trim())return;if(!$.current)return;let x=P.getRangeAt(0);if(!$.current.contains(x.startContainer))return;if(x.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let f=P.toString().trim();if(f.length<2)return;let o=b.current(x),w=x.cloneRange(),F=`__pending_${Date.now()}`;try{s1(w,F)}catch{}window.getSelection()?.removeAllRanges();let m=document.querySelectorAll(`[data-annotation-id="${F}"]`),u=m[m.length-1];if(!u)return;R({anchorEl:u,tempId:F,snippet:f,ctx:o})},[]),E=f3((P,x,f,o)=>{R({anchorEl:P,tempId:x,snippet:f,ctx:o})},[]);return{popovers:E2(e8,{children:[N&&(()=>{let P=z.find((x)=>x.id===N.annId);if(!P)return null;return E2(U0,{anchorEl:N.anchorEl,scrollContainer:G,initialNote:P.note,initialImages:P.images,onUpdate:(x,f)=>{U(N.annId,x);let o=P.images||[];for(let w of f)if(!o.includes(w))W(N.annId,w);for(let w of o)if(!f.includes(w))T(N.annId,w)},onDelete:()=>{H(N.annId),L(null)},onClose:()=>S(null)},void 0,!1,void 0,this)})(),O&&E2(G0,{anchorEl:O.anchorEl,scrollContainer:G,snippet:O.snippet,truncateAt:80,onAdd:(P,x)=>{let f=L1();i0(O.tempId,f),g.current(f,O.snippet,P,M.current,O.ctx,x,j.current),R(null)},onCancel:()=>{o0(O.tempId),R(null)}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),openCreatePopover:E,isPopoverOpen:!!(N||O)}}import{createContext as $4}from"react";var t0=$4(()=>{});import{jsxDEV as q1,Fragment as _4}from"react/jsx-dev-runtime";var m2="[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']",x2="[data-md='item'], [data-md='section'], [data-md='table'] tbody tr, [data-md='callout'], [data-md='note'], [data-md='checklist-item'], [data-md='image']";class h3 extends n0.Component{state={error:null};static getDerivedStateFromError(Z){return{error:Z}}componentDidCatch(Z,$){this.props.reportError({revision:this.props.revision,filename:this.props.filename,message:Z.message,...Z.stack?{stack:Z.stack}:{},...$.componentStack?{componentStack:$.componentStack}:{}})}render(){if(!this.state.error)return this.props.children;return q1(p3,{message:this.state.error.message},void 0,!1,void 0,this)}}function p3({message:Z}){return q1("div",{className:"bg-accent-red-muted rounded-lg p-5",children:[q1("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Canvas render failed"},void 0,!1,void 0,this),q1("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:Z},void 0,!1,void 0,this),q1("p",{className:"text-meta font-body text-text-tertiary mt-3",children:"The error was sent back to the canvas author."},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function w0({revision:Z,filename:$}){let q=v3(J4),Q=v3(t0),[J,Y]=w1(null),[X,G]=w1(null),[z,_]=w1(!0),H=Z4(null),{annotations:U,addAnnotationWithId:W,removeAnnotation:T,updateAnnotation:K,addAnnotationImage:L,removeAnnotationImage:N,activeAnnotationId:S,setActiveAnnotationId:O}=X1(),R=j0(()=>U.filter((w)=>!w.filePath&&(!w.canvasFile||w.canvasFile===$)),[U,$]),[b,M]=w1(null),[j,g]=w1(null),[C,h]=w1(null),[v,l]=w1(null),[V,E]=w1(!1);$0(()=>{_(!0),G(null),l(null),w3($,Z).then((w)=>{Y(()=>w.default),_(!1)}).catch((w)=>{let F=w instanceof Error?w:Error(String(w));G(F.message),_(!1),Q({revision:Z,filename:$,message:F.message,...F.stack?{stack:F.stack}:{}})})},[q,Z,$,Q]);let c=document.getElementById("plan-scroll-container"),{popovers:P,isPopoverOpen:x}=n1({containerRef:H,restoreKey:J,restoreAnnotations:R,extractContext:(w)=>a1(w,H.current),canvasFile:$,scrollContainer:c}),f=j0(()=>{let w=new Map;for(let F of R)if(F.snippet.startsWith("["))w.set(F.snippet,F.id);return w},[R]);$0(()=>{let w=H.current;if(!w)return;let F=(u)=>{if(C||x)return;let D=u.target;if(D.closest("[data-block-comment-btn]"))return;E(!1);let a=D.closest(m2);if(a&&w.contains(a)){let Z1=e1(w).indexOf(a);l(Z1>=0?Z1:null)}else l(null);let I=D.closest(x2);if(I&&w.contains(I)){g(I);let k=K0(I),Z1=k?f.get(k):void 0;if(Z1&&Z1!==S)O(Z1)}else g(null)},m=(u)=>{if(C||x)return;if(u.relatedTarget?.closest("[data-block-comment-btn]"))return;g(null),O(null)};return w.addEventListener("mousemove",F),w.addEventListener("mouseleave",m),()=>{w.removeEventListener("mousemove",F),w.removeEventListener("mouseleave",m)}},[J,C,x,f,S]),$0(()=>{let w=(F)=>{let m=F.target.tagName;if(m==="INPUT"||m==="TEXTAREA"||F.target.isContentEditable)return;if(C||x)return;let u=H.current;if(!u)return;if(F.key==="ArrowDown"){F.preventDefault(),E(!0);let D=e1(u);if(D.length===0)return;l((a)=>{if(a===null)return 0;return Math.min(a+1,D.length-1)})}else if(F.key==="ArrowUp"){F.preventDefault(),E(!0);let D=e1(u);if(D.length===0)return;l((a)=>{if(a===null)return D.length-1;return Math.max(a-1,0)})}else if(F.key==="a"||F.key==="A"){if(v===null||!u)return;F.preventDefault();let a=e1(u)[v];if(!a)return;let I=K0(a);if(!I)return;let k=f.get(I);if(k)O(k),h({anchorEl:a,snippet:I,annId:k});else h({anchorEl:a,snippet:I})}else if(F.key===" "||F.key==="Enter"){if(v===null)return;let a=e1(u)[v];if(!a)return;let I=a.getAttribute("data-md");if(I==="choice-option"||I==="multichoice-option")F.preventDefault(),a.dispatchEvent(new CustomEvent("kb-select",{bubbles:!0}));else if(I==="userinput"){F.preventDefault();let k=a.querySelector("textarea");if(k){k.focus();let Z1=(Y1)=>{if(Y1.key==="Escape")Y1.preventDefault(),k.blur(),E(!0)};k.addEventListener("keydown",Z1),k.addEventListener("blur",()=>k.removeEventListener("keydown",Z1),{once:!0})}}else if(I==="rangeinput"){F.preventDefault();let k=a.querySelector("input[type='range']");if(k){k.focus();let Z1=(Y1)=>{if(Y1.key==="Escape"||Y1.key==="ArrowUp"||Y1.key==="ArrowDown")Y1.preventDefault(),k.blur(),E(!0)};k.addEventListener("keydown",Z1),k.addEventListener("blur",()=>k.removeEventListener("keydown",Z1),{once:!0})}}}else if(F.key==="Escape")l(null),E(!1),O(null)};return document.addEventListener("keydown",w),()=>document.removeEventListener("keydown",w)},[v,C,x,f]),$0(()=>{let w=H.current;if(!w||v===null||!V)return;let m=e1(w)[v];if(!m)return;m.style.outline="2px solid var(--color-accent-blue)",m.style.outlineOffset="-2px",m.style.borderRadius="8px",m.scrollIntoView({block:"nearest",behavior:"smooth"});let u=K0(m),D=u?f.get(u):void 0;if(D)O(D);return()=>{m.style.outline="",m.style.outlineOffset="",m.style.borderRadius=""}},[v,V,f]);let o=j0(()=>J?q1(J,{},void 0,!1,void 0,this):null,[J]);if(z)return q1("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-body",children:"Loading canvas..."},void 0,!1,void 0,this);if(X)return q1(p3,{message:X},void 0,!1,void 0,this);if(!J)return q1("div",{className:"text-text-tertiary text-center py-8 font-body text-body",children:"No canvas loaded"},void 0,!1,void 0,this);return q1(Q4.Provider,{value:$,children:[q1("div",{ref:H,className:"plan-content plan-updated",children:q1(h3,{revision:Z,filename:$,reportError:Q,children:o},`${Z}:${$}`,!1,void 0,this)},void 0,!1,void 0,this),b&&q1(z4,{note:b.note,onSave:(w)=>{K(b.id,w),M(null)},onCancel:()=>M(null)},void 0,!1,void 0,this),P,q1(Y4,{containerRef:H,hoveredBlock:j,focusedBlockIndex:v,blockPopover:C,blockAnnotationMap:f,activeAnnotationId:S,onOpen:(w,F,m)=>{if(m)O(m),h({anchorEl:w,snippet:F,annId:m});else h({anchorEl:w,snippet:F})}},void 0,!1,void 0,this),C&&!C.annId&&q1(G0,{anchorEl:C.anchorEl,scrollContainer:c,snippet:C.snippet,truncateAt:80,onAdd:(w,F)=>{let m=L1();W(m,C.snippet,w,void 0,void 0,F,$),h(null)},onCancel:()=>h(null)},void 0,!1,void 0,this),C?.annId&&(()=>{let w=R.find((F)=>F.id===C.annId);if(!w)return null;return q1(U0,{anchorEl:C.anchorEl,scrollContainer:c,initialNote:w.note,initialImages:w.images,onUpdate:(F,m)=>{K(C.annId,F);let u=w.images||[];for(let D of m)if(!u.includes(D))L(C.annId,D);for(let D of u)if(!m.includes(D))N(C.annId,D)},onDelete:()=>{T(C.annId),O(null),h(null)},onClose:()=>h(null)},void 0,!1,void 0,this)})()]},void 0,!0,void 0,this)}function e1(Z){return Array.from(Z.querySelectorAll(m2))}function K0(Z){let $=Z.getAttribute("data-md");if($==="item"){let q=Z.getAttribute("data-md-label");return q?`[Item] ${q}`:null}if($==="section"){let q=Z.getAttribute("data-md-title");return q?`[Section] ${q}`:null}if($==="callout"){let q=Z.getAttribute("data-md-type")||"info",Q=Z.textContent?.trim().slice(0,60)||"Callout";return`[Callout:${q}] ${Q}`}if($==="note")return`[Note] ${Z.textContent?.trim().slice(0,60)||"Note"}`;if(Z.tagName==="TR"){let q=Array.from(Z.querySelectorAll("td")).map((Q)=>Q.textContent?.trim()).filter(Boolean);return q.length?`[Row] ${q.join(" | ")}`:null}if($==="checklist-item"){let q=Z.getAttribute("data-md-label");return q?`[Checklist] ${q}`:null}if($==="choice-option"||$==="multichoice-option"){let q=Z.getAttribute("data-md-label");return q?`[Option] ${q}`:null}if($==="userinput"){let q=Z.getAttribute("data-md-label");return q?`[Input] ${q}`:null}if($==="rangeinput"){let q=Z.getAttribute("data-md-label");return q?`[Range] ${q}`:null}if($==="image"){let q=Z.getAttribute("data-md-src");return q?`[Image] ${q}`:null}return null}function Y4({containerRef:Z,hoveredBlock:$,focusedBlockIndex:q,blockPopover:Q,blockAnnotationMap:J,activeAnnotationId:Y,onOpen:X}){let[G,z]=w1([]);$0(()=>{let T=Z.current;if(!T||J.size===0){z([]);return}let K=[];for(let L of T.querySelectorAll(x2)){let N=K0(L);if(N&&J.has(N))K.push(L)}z(K)},[J,Z.current]);let[_,H]=w1(null);$0(()=>{if(!Y||!Z.current){H(null);return}for(let T of Z.current.querySelectorAll(m2)){let K=K0(T);if(K&&J.get(K)===Y){H(T);return}}H(null)},[Y,J]),$0(()=>{if(!_)return;return _.style.boxShadow="inset 0 0 0 1.5px var(--color-highlight-bg)",_.style.borderRadius="8px",()=>{_.style.boxShadow="",_.style.borderRadius=""}},[_]);let U=j0(()=>{if(q===null||!Z.current)return null;let T=e1(Z.current)[q];if(!T)return null;return T.matches(x2)?T:null},[q,Z.current]),W=j0(()=>{let T=new Set(G);if($)T.add($);if(U)T.add(U);if(Q?.anchorEl)T.add(Q.anchorEl);return Array.from(T)},[G,$,U,Q]);return q1(_4,{children:W.map((T)=>q1(X4,{block:T,isHovered:T===$||T===U||T===Q?.anchorEl,blockAnnotationMap:J,activeAnnotationId:Y,onOpen:X},T.getAttribute("data-task-id")||T.getAttribute("data-md-title")||T.textContent?.slice(0,30)||"block",!1,void 0,this))},void 0,!1,void 0,this)}function X4({block:Z,isHovered:$,blockAnnotationMap:q,activeAnnotationId:Q,onOpen:J}){let Y=K0(Z);if(!Y)return null;let X=q.get(Y),G=!!X;return q4(q1("button",{"data-block-comment-btn":!0,onClick:(_)=>{_.stopPropagation(),J(_.currentTarget,Y,X)},className:`absolute top-1 right-1 z-10 w-6 h-6 flex items-center justify-center rounded transition-all duration-150 ${G?X===Q?"text-accent-amber bg-accent-amber-muted":"text-accent-amber opacity-60 hover:opacity-100":$?"text-text-disabled hover:text-text-tertiary opacity-50 hover:opacity-100":"text-text-disabled opacity-0 group-hover/section:opacity-20 hover:!opacity-80"}`,title:G?"Edit annotation":"Add annotation",children:q1("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:G?"currentColor":"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:q1("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),Z)}function z4({note:Z,onSave:$,onCancel:q}){let[Q,J]=n0.useState(Z),Y=n0.useRef(null);return n0.useEffect(()=>{Y.current?.focus(),Y.current?.select()},[]),q1("div",{className:"fixed inset-0 z-50 bg-black/40 flex items-center justify-center",onClick:q,children:q1("div",{className:"bg-bg-elevated border border-border-hover rounded-lg shadow-md p-4 w-80",onClick:(X)=>X.stopPropagation(),children:[q1("div",{className:"text-tiny uppercase tracking-widest text-text-tertiary font-body mb-2",children:"Edit annotation"},void 0,!1,void 0,this),q1("textarea",{ref:Y,value:Q,onChange:(X)=>J(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))$(Q.trim());if(X.key==="Escape")q()}},void 0,!1,void 0,this),q1("div",{className:"flex justify-end gap-2 mt-2",children:[q1("button",{onClick:q,className:"text-meta text-text-tertiary font-body px-3 py-1",children:"Cancel"},void 0,!1,void 0,this),q1("button",{onClick:()=>$(Q.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 L4,{useRef as i3,useEffect as q2,useCallback as h2,useState as v1,useContext as J2,useMemo as M4}from"react";function A0(Z,$,q,Q,J){let Y=[],X=Z.filter((T)=>T.source!=="remote"||J&&J.has(T.id)),G=X.filter((T)=>T.filePath===T1),z=X.filter((T)=>!T.filePath),_=X.filter((T)=>T.filePath&&T.filePath!==T1),H=q?Array.from(q.values()).filter((T)=>g2(T)):[],U=Q?Array.from(Q.values()).filter((T)=>T.markdown.trim()):[];if(H.length>0||U.length>0){Y.push("## Responses"),Y.push("");for(let T of H)Y.push(K4(T));for(let T of U)Y.push(T.markdown.trim()),Y.push("")}if(G.length>0){Y.push("## Annotations on agent response"),Y.push("");for(let T of G)Y.push(u2(T))}if(z.length>0){Y.push("## Canvas annotations"),Y.push("");let T=new Map;for(let N of z){let S=N.canvasFile||"";if(!T.has(S))T.set(S,[]);T.get(S).push(N)}let K=[...T.keys()].sort(),L=K.length>1||K.length===1&&K[0]!=="";for(let N of K){let S=T.get(N);if(L&&N)Y.push(`### ${N.replace(/\.jsx$/,"")}`),Y.push("");let O=H4(S);Y.push(c3(O))}}if(_.length>0){let T={};for(let K of _){let L=K.filePath;if(!T[L])T[L]=[];T[L].push(K)}Y.push("## File annotations"),Y.push("");for(let[K,L]of Object.entries(T)){Y.push(`### ${K}`),Y.push("");for(let N of L)Y.push(u2(N))}}if($.trim())Y.push("## General notes"),Y.push(""),Y.push($.trim()),Y.push("");return Y.join(`
|
|
60
60
|
`).trim()+`
|
|
61
|
-
`}function
|
|
62
|
-
`)}function
|
|
63
|
-
`);if(q.length<30&&Y===X&&(Q.before||Q.after)){let _=
|
|
61
|
+
`}function g2(Z){if(Z.note?.trim())return!0;if(Z.value===null||Z.value===void 0)return!1;if(Z.type==="text"&&!Z.value.trim())return!1;if(Z.type==="checkbox"&&Z.value.length===0)return!1;return!0}function G4(Z){let $=[];for(let q of Z.values()){if(!q.required)continue;if(q.value===null||q.value===void 0){$.push(q);continue}if(q.type==="text"&&!q.value.trim()){$.push(q);continue}if(q.type==="checkbox"&&q.value.length===0){$.push(q);continue}}return $}function U4(Z){let $=[];for(let q of Z.values())if(q.required&&!q.markdown.trim())$.push(q);return $}function e0(Z,$){let q=G4(Z),Q=U4($);return[...q.map((J)=>J.label),...Q.map((J)=>J.label||J.id)]}function K4(Z){let $=[];switch($.push(`**${Z.label}**`),Z.type){case"radio":case"select":$.push(`Answer: ${Z.value}`);break;case"checkbox":for(let q of Z.value)$.push(`- [x] ${q}`);break;case"text":$.push(""),$.push(Z.value.trim());break;case"range":$.push(`Answer: ${Z.value}`);break}if(Z.note?.trim())$.push(""),$.push(`Note: ${Z.note.trim()}`);return $.push(""),$.join(`
|
|
62
|
+
`)}function u2(Z){let $=[],q=Z.snippet.trim(),Q=Z.context,J=Q?.lineStart!=null;if(Z.filePath&&J){let Y=Q.lineStart,X=Q.lineEnd??Y,G=q.split(`
|
|
63
|
+
`);if(q.length<30&&Y===X&&(Q.before||Q.after)){let _=V2(Z);$.push(`> L${Y}: ${_}`)}else if(G.length<=6)for(let _=0;_<G.length;_++)$.push(`> ${Y+_} | ${G[_]}`);else{for(let _=0;_<3;_++)$.push(`> ${Y+_} | ${G[_]}`);$.push(`> ... (${G.length} lines)`);for(let _=G.length-3;_<G.length;_++)$.push(`> ${Y+_} | ${G[_]}`)}}else{let Y=V2(Z);if(q.split(`
|
|
64
64
|
`).length<=3)$.push(`> ${Y.split(`
|
|
65
65
|
`).join(`
|
|
66
66
|
> `)}`);else{let X=q.split(`
|
|
67
67
|
`);$.push(`> ${X[0]}`),$.push(`> ... (${X.length} lines)`),$.push(`> ${X[X.length-1]}`)}}if(Z.note.trim())$.push(""),$.push(Z.note.trim());if(Z.images?.length){$.push("");for(let Y of Z.images)$.push(``)}return $.push(""),$.join(`
|
|
68
|
-
`)}function
|
|
69
|
-
`)}import{SessionContext as v3}from"#canvas/runtime";import{useEffect as x3,useState as j0,useRef as X4,useMemo as k2}from"react";import{jsxDEV as Q1}from"react/jsx-dev-runtime";function u3({open:Z,onClose:$,onSubmit:q,includedRemoteIds:Q,onToggleRemoteId:J}){let{annotations:Y,generalNote:X,responses:G,feedbackEntries:z}=Y1(),[_,H]=j0(""),[U,T]=j0(!1),[W,K]=j0(!1),[F,N]=j0(null),y=X4(null),[O,D]=j0(!1),S=k2(()=>Y.filter((k)=>k.source==="remote"),[Y]);if(Z&&!O)T(!1),K(!1),N(null);if(!Z&&O)T(!1),K(!1),N(null);if(Z!==O)D(Z);let M=k2(()=>b0(Y,X,G,z,Q),[Y,X,G,z,Q]),b=U?_:M;if(x3(()=>{if(Z&&W&&y.current)y.current.focus()},[Z,W]),x3(()=>{if(!Z)return;let k=(c)=>{if(c.key==="Escape")$()};return window.addEventListener("keydown",k),()=>window.removeEventListener("keydown",k)},[Z,$]),!Z)return null;let C=b.trim().length>0;return Q1("div",{className:"fixed inset-0 z-50 bg-black/50 backdrop-blur-sm flex items-center justify-center p-8",onClick:$,children:Q1("div",{className:"bg-bg-surface border border-border-medium rounded-xl shadow-lg w-full max-w-2xl flex flex-col",style:{height:"80vh"},onClick:(k)=>k.stopPropagation(),children:[Q1("div",{className:"flex items-center justify-between px-5 py-3 border-b border-border-subtle flex-shrink-0",children:[Q1("div",{className:"flex items-center gap-3",children:[Q1("span",{className:"text-[13px] font-medium text-text-primary font-body",children:"Response preview"},void 0,!1,void 0,this),U&&Q1("button",{onClick:()=>{T(!1),K(!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),Q1("div",{className:"flex items-center gap-2",children:[Q1("div",{className:"flex items-center bg-bg-base rounded-md p-0.5",children:[Q1("button",{onClick:()=>K(!1),className:`px-2.5 py-1 rounded text-[11px] font-body font-medium transition-colors ${!W?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Preview"},void 0,!1,void 0,this),Q1("button",{onClick:()=>K(!0),className:`px-2.5 py-1 rounded text-[11px] font-body font-medium transition-colors ${W?"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),Q1("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),W?Q1("textarea",{ref:y,value:b,onChange:(k)=>{H(k.target.value),T(!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):Q1("div",{className:"flex-1 overflow-y-auto p-5",children:Q1(s0,{text:b},void 0,!1,void 0,this)},void 0,!1,void 0,this),S.length>0&&Q1("div",{className:"px-5 py-2 border-t border-border-subtle flex-shrink-0",children:Q1("span",{className:"text-[12px] text-text-secondary font-body",children:["Reviewer feedback: ",Q.size,"/",S.length," included"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),F&&Q1("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:[Q1("span",{children:F},void 0,!1,void 0,this),Q1("button",{onClick:()=>{N(null),q(b)},className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body whitespace-nowrap underline",children:"Submit anyway"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Q1("div",{className:"flex justify-end gap-2 px-5 py-3 border-t border-border-subtle flex-shrink-0",children:[Q1("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),Q1("button",{onClick:()=>{let k=o0(G,z);if(k.length>0){N(`Please answer: ${k.join(", ")}`);return}N(null),q(b)},disabled:!C,className:`px-6 py-2 rounded-lg font-body text-[13px] font-medium transition-all ${C?"bg-btn-primary text-btn-primary-text hover:opacity-90":"bg-bg-input text-text-disabled cursor-default"}`,children:"Submit feedback"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}var z4=/!\[([^\]]*)\]\((\/tmp\/agent-canvas\/uploads\/([^)]+))\)/g;function _4(Z){return Z.replace(z4,($,q,Q,J)=>``)}function s0({text:Z}){let $=k2(()=>e.parse(_4(Z),{async:!1}),[Z]);return Q1("div",{className:"prose-canvas font-body text-body text-text-primary leading-relaxed",dangerouslySetInnerHTML:{__html:$}},void 0,!1,void 0,this)}import{jsxDEV as $0}from"react/jsx-dev-runtime";var G4={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"},U4={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 x1({name:Z,type:$,expanded:q,className:Q=""}){if($==="dir")return $0("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",className:`flex-shrink-0 ${Q}`,children:q?$0("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):$0("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 J=Z.includes(".")?Z.split(".").pop().toLowerCase():"",Y=G4[J]||"#6b6560",X=U4[J];return $0("svg",{width:"14",height:"14",viewBox:"0 0 16 16",className:`flex-shrink-0 ${Q}`,children:[$0("path",{d:"M2 1.5h8l3.5 3.5v9.5a1 1 0 01-1 1H3a1 1 0 01-1-1v-12a1 1 0 011-1z",fill:Y,opacity:"0.85"},void 0,!1,void 0,this),$0("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&&$0("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 K4(Z){let $=Z.getAttribute("data-md");if($==="item"){let q=Z.getAttribute("data-md-label");return q?`[Item] ${q}`:null}if($==="section"){let q=Z.getAttribute("data-md-title");return q?`[Section] ${q}`:null}if($==="callout"){let q=Z.getAttribute("data-md-type")||"info",Q=Z.textContent?.trim().slice(0,60)||"Callout";return`[Callout:${q}] ${Q}`}if($==="note")return`[Note] ${Z.textContent?.trim().slice(0,60)||"Note"}`;if(Z.tagName==="TR"){let q=Array.from(Z.querySelectorAll("td")).map((Q)=>Q.textContent?.trim()).filter(Boolean);return q.length?`[Row] ${q.join(" | ")}`:null}if($==="checklist-item"){let q=Z.getAttribute("data-md-label");return q?`[Checklist] ${q}`:null}if($==="choice-option"||$==="multichoice-option"){let q=Z.getAttribute("data-md-label");return q?`[Option] ${q}`:null}if($==="userinput"){let q=Z.getAttribute("data-md-label");return q?`[Input] ${q}`:null}if($==="rangeinput"){let q=Z.getAttribute("data-md-label");return q?`[Range] ${q}`:null}if($==="image"){let q=Z.getAttribute("data-md-src");return q?`[Image] ${q}`:null}return null}function w0(Z){let $=document.querySelector(`[data-annotation-id="${Z.id}"]`);if($)return $;if(Z.snippet.startsWith("[")){for(let q 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(K4(q)===Z.snippet)return q}return null}function g3(Z){Z.classList.remove("ann-flash"),Z.offsetWidth,Z.classList.add("ann-flash"),Z.addEventListener("animationend",()=>{Z.classList.remove("ann-flash")},{once:!0})}function E2(Z,$){if(Z.filePath)$({type:"file",path:Z.filePath}),setTimeout(()=>{let q=w0(Z);if(q)q.scrollIntoView({behavior:"smooth",block:"center"}),g3(q)},150);else{let q=w0(Z);if(q)q.scrollIntoView({behavior:"smooth",block:"center"}),g3(q)}}import{jsxDEV as P,Fragment as t0}from"react/jsx-dev-runtime";function x2({onSubmit:Z,collapseButton:$}){let{isReadOnly:q,selectedRevision:Q,currentRevision:J,revisions:Y,agentWatching:X}=e0(w1),G=e0(v3),z=Y.find((T)=>T.revision===Q),_=q&&Q===J,H=!!z?.feedbackConsumed,U=z?.label||`Round ${Q}`;if(q)return P(N4,{sessionId:G,revision:Q,label:U,waitingForUpdate:_,feedbackConsumed:H,agentWatching:X,collapseButton:$},void 0,!1,void 0,this);return P(F4,{onSubmit:Z,agentWatching:X,collapseButton:$},void 0,!1,void 0,this)}function T4({sessionId:Z,revision:$,label:q,waitingForUpdate:Q,feedbackConsumed:J,agentWatching:Y,collapseButton:X}){let G=$1.isShared,[z,_]=u1(null),[H,U]=u1(!0);return n0(()=>{if(U(!0),!L1){_(null),U(!1);return}fetch(`/api/session/${Z}/revision/${$}/feedback`).then((T)=>T.json()).then((T)=>{_(T.feedback||null),U(!1)}).catch(()=>{_(null),U(!1)})},[Z,$]),P("div",{className:"flex flex-col h-full",children:[P("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[P("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:Q?"Feedback sent":`Feedback — ${q}`},void 0,!1,void 0,this),X]},void 0,!0,void 0,this),Q&&!G&&P(h3,{feedbackConsumed:J,agentWatching:Y},void 0,!1,void 0,this),P("div",{className:"flex-1 overflow-y-auto px-4",children:H?P("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"Loading..."},void 0,!1,void 0,this):z?P(s0,{text:z},void 0,!1,void 0,this):P("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"No feedback was submitted for this revision."},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function h3({feedbackConsumed:Z,agentWatching:$}){if(Z)return P("div",{className:"mx-4 mb-3 px-3 py-2.5 rounded-lg bg-accent-green-muted flex items-center gap-2 flex-shrink-0",children:[P("span",{className:"w-2 h-2 rounded-full bg-accent-green animate-pulse"},void 0,!1,void 0,this),P("span",{className:"text-[12px] font-body text-accent-green",children:"Feedback received — waiting for next revision..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if($)return P("div",{className:"mx-4 mb-3 px-3 py-2.5 rounded-lg bg-accent-blue-muted flex items-center gap-2 flex-shrink-0",children:[P("span",{className:"w-2 h-2 rounded-full bg-accent-blue animate-pulse"},void 0,!1,void 0,this),P("span",{className:"text-[12px] font-body text-accent-blue",children:"Waiting for agent to pick up feedback..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return P("div",{className:"mx-4 mb-3 px-3 py-2.5 rounded-lg bg-accent-amber-muted flex items-center gap-2 flex-shrink-0",children:[P("span",{className:"w-2 h-2 rounded-full bg-accent-amber"},void 0,!1,void 0,this),P("span",{className:"text-[12px] font-body text-accent-amber",children:"Agent disconnected — tell Claude to check feedback"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function N4({sessionId:Z,revision:$,label:q,waitingForUpdate:Q,feedbackConsumed:J,agentWatching:Y,collapseButton:X}){let{annotations:G,generalNote:z,activeAnnotationId:_,setActiveAnnotationId:H}=Y1(),{setActiveView:U}=e0(I1),T=G.length>0||z.trim().length>0,[W,K]=u1("feedback");if(!T)return P(T4,{sessionId:Z,revision:$,label:q,waitingForUpdate:Q,feedbackConsumed:J,agentWatching:Y,collapseButton:X},void 0,!1,void 0,this);return P("div",{className:"flex flex-col h-full",children:[P("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[P("div",{className:"flex items-center gap-1 bg-bg-input rounded-md p-0.5",children:[P("button",{onClick:()=>K("feedback"),className:`px-2.5 py-1 rounded text-[11px] font-medium font-body transition-colors ${W==="feedback"?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Feedback"},void 0,!1,void 0,this),P("button",{onClick:()=>K("annotations"),className:`px-2.5 py-1 rounded text-[11px] font-medium font-body transition-colors flex items-center gap-1.5 ${W==="annotations"?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:["Annotations",P("span",{className:"inline-flex items-center justify-center min-w-[16px] h-[16px] px-1 rounded-full bg-border-subtle text-[10px] font-medium",children:G.length},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),X]},void 0,!0,void 0,this),Q&&P(h3,{feedbackConsumed:J,agentWatching:Y},void 0,!1,void 0,this),W==="feedback"?P(O4,{sessionId:Z,revision:$},void 0,!1,void 0,this):P(B4,{annotations:G,generalNote:z,activeAnnotationId:_,setActiveAnnotationId:H,setActiveView:U},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function O4({sessionId:Z,revision:$}){let[q,Q]=u1(null),[J,Y]=u1(!0);return n0(()=>{if(Y(!0),!L1){Q(null),Y(!1);return}fetch(`/api/session/${Z}/revision/${$}/feedback`).then((X)=>X.json()).then((X)=>{Q(X.feedback||null),Y(!1)}).catch(()=>{Q(null),Y(!1)})},[Z,$]),P("div",{className:"flex-1 overflow-y-auto px-4",children:J?P("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"Loading..."},void 0,!1,void 0,this):q?P(s0,{text:q},void 0,!1,void 0,this):P("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"No feedback was submitted for this revision."},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function B4({annotations:Z,generalNote:$,activeAnnotationId:q,setActiveAnnotationId:Q,setActiveView:J}){let Y=Z.filter((K)=>K.filePath===T1),X=Z.filter((K)=>!K.filePath),G=Z.filter((K)=>K.filePath&&K.filePath!==T1),z={};for(let K of G){let F=K.filePath;if(!z[F])z[F]=[];z[F].push(K)}let _=(K)=>{Q(K),a1(K,!0)},H=(K)=>{Q(null),a1(K,!1)},U=(K)=>{if(K.id===q)Q(null);else if(Q(K.id),K.filePath)J({type:"file",path:K.filePath}),setTimeout(()=>{let F=w0(K);if(F)F.scrollIntoView({behavior:"smooth",block:"center"})},150)},T=(K)=>P("div",{className:`group/ann relative px-3 py-2.5 transition-colors duration-150 cursor-pointer ${q===K.id?"bg-highlight-selected":"odd:bg-bg-elevated-half hover:bg-bg-input"}`,onMouseEnter:()=>_(K.id),onMouseLeave:()=>H(K.id),onClick:()=>U(K),children:[P("div",{className:"text-[11px] text-text-tertiary italic line-clamp-2 mb-1.5 leading-snug font-body border-l-2 border-border-medium pl-2",children:K.snippet.length>80?K.snippet.slice(0,80)+"...":K.snippet},void 0,!1,void 0,this),K.note.trim()&&P("div",{className:"text-[13px] font-body text-text-primary leading-relaxed",children:K.note},void 0,!1,void 0,this),P(A3,{images:K.images||[]},void 0,!1,void 0,this),P("div",{className:"absolute top-1.5 right-1.5 opacity-0 group-hover/ann:opacity-100 transition-opacity duration-100",children:P("button",{onClick:(F)=>{F.stopPropagation(),E2(K,J)},className:"w-5 h-5 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-input transition-colors",title:"Scroll to annotation",children:P("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[P("circle",{cx:"12",cy:"12",r:"3"},void 0,!1,void 0,this),P("path",{d:"M12 2v4M12 18v4M2 12h4M18 12h4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},K.id,!0,void 0,this),W=[Y,X,G].filter((K)=>K.length>0).length>1;return P(t0,{children:[P("div",{className:"flex-1 overflow-y-auto",children:[Y.length>0&&P(t0,{children:[W&&P("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body px-3 mb-1 mt-1",children:"Agent Response"},void 0,!1,void 0,this),Y.map(T)]},void 0,!0,void 0,this),X.length>0&&P(t0,{children:[W&&P("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body px-3 mb-1 mt-1",children:"Canvas"},void 0,!1,void 0,this),X.map(T)]},void 0,!0,void 0,this),Object.entries(z).map(([K,F])=>P("div",{children:[P("button",{onClick:()=>J({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:[P(x1,{name:K.split("/").pop()||K,type:"file"},void 0,!1,void 0,this),P("span",{className:"truncate",children:K},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F.map(T)]},K,!0,void 0,this))]},void 0,!0,void 0,this),$.trim()&&P("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:P("div",{className:"text-[13px] font-body text-text-primary leading-relaxed",children:$},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function F4({onSubmit:Z,agentWatching:$,collapseButton:q}){let[Q,J]=u1(!1),{annotations:Y,updateAnnotation:X,removeAnnotation:G,addAnnotationImage:z,removeAnnotationImage:_,generalNote:H,setGeneralNote:U,activeAnnotationId:T,setActiveAnnotationId:W,responses:K,feedbackEntries:F}=Y1(),N=e0(v3),{setActiveView:y}=H4.useContext(I1),O=f3(null),D=f3(new Map),S=Y.filter((L)=>L.filePath===T1),M=Y.filter((L)=>!L.filePath),b=Y.filter((L)=>L.filePath&&L.filePath!==T1),C={};for(let L of b){let d=L.filePath;if(!C[d])C[d]=[];C[d].push(L)}n0(()=>{if(!T)return;let L=D.current.get(T);if(L)L.scrollIntoView({behavior:"smooth",block:"nearest"})},[T]);let k=m2((L)=>{W(L),a1(L,!0)},[W]),c=m2((L)=>{W(null),a1(L,!1)},[T]),v=W4(()=>Y.filter((L)=>L.source==="remote"),[Y]),[V,E]=u1(()=>new Set);n0(()=>{if(v.length===0)return;E((L)=>{let d=new Set(L);for(let m of v)d.add(m.id);return d.size===L.size?L:d})},[v]);let g=m2((L)=>{E((d)=>{let m=new Set(d);if(m.has(L))m.delete(L);else m.add(L);return m})},[]),l=Array.from(K.values()).some(D2),j=F.size>0,u=Y.length>0||H.trim().length>0||l||j,[h,A]=u1(null),I=(L)=>{let d=L.source==="remote";return P("div",{ref:(m)=>{if(m)D.current.set(L.id,m);else D.current.delete(L.id)},className:`group/ann relative px-3 py-2.5 transition-colors duration-150 ${T===L.id?"bg-highlight-selected":d?"bg-accent-purple-muted/30 hover:bg-accent-purple-muted/50":"odd:bg-bg-elevated-half hover:bg-bg-input"}`,onMouseEnter:()=>k(L.id),onMouseLeave:()=>c(L.id),onClick:()=>{if(L.id===T)W(null);else if(W(L.id),L.filePath)y({type:"file",path:L.filePath}),setTimeout(()=>{let m=w0(L);if(m)m.scrollIntoView({behavior:"smooth",block:"center"})},150)},children:[d&&L.author&&P("div",{className:"flex items-center gap-1.5 mb-1.5",children:[P("input",{type:"checkbox",checked:V.has(L.id),onChange:(m)=>{m.stopPropagation(),g(L.id)},onClick:(m)=>m.stopPropagation(),className:"accent-accent-purple flex-shrink-0",title:"Include in submission"},void 0,!1,void 0,this),P("span",{className:"inline-flex items-center justify-center w-4 h-4 rounded-full bg-accent-purple text-white text-[9px] font-medium uppercase",children:L.author.name.charAt(0)},void 0,!1,void 0,this),P("span",{className:"text-[11px] font-medium text-accent-purple font-body",children:L.author.name},void 0,!1,void 0,this),P("span",{className:"text-[10px] text-text-tertiary font-body uppercase tracking-widest",children:"Remote"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),P("div",{className:"text-[11px] text-text-tertiary italic line-clamp-2 mb-1.5 leading-snug font-body border-l-2 border-border-medium pl-2",children:L.snippet.length>80?L.snippet.slice(0,80)+"...":L.snippet},void 0,!1,void 0,this),d?P("div",{className:"text-[13px] font-body text-text-primary leading-relaxed whitespace-pre-wrap",children:L.note},void 0,!1,void 0,this):P("div",{onClick:(m)=>m.stopPropagation(),children:P(h0,{note:L.note,onNoteChange:(m)=>X(L.id,m),images:L.images||[],onAddImage:(m)=>z(L.id,m),onRemoveImage:(m)=>_(L.id,m),sessionId:N,autoResize:!0,minHeight:20,textareaClassName:"w-full bg-transparent text-[13px] font-body text-text-primary resize-none focus:outline-none leading-relaxed p-0 border-none min-h-[20px]",textareaStyle:{height:"auto",overflow:"hidden"},placeholder:"Add your note...",attachButton:"on-focus"},void 0,!1,void 0,this)},void 0,!1,void 0,this),P("div",{className:"absolute top-1.5 right-1.5 opacity-0 group-hover/ann:opacity-100 transition-opacity duration-100 flex items-center gap-0.5",children:[P("button",{onClick:(m)=>{m.stopPropagation(),E2(L,y)},className:"w-5 h-5 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-input transition-colors",title:"Scroll to annotation",children:P("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[P("circle",{cx:"12",cy:"12",r:"3"},void 0,!1,void 0,this),P("path",{d:"M12 2v4M12 18v4M2 12h4M18 12h4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),!d&&P("button",{onClick:(m)=>{m.stopPropagation(),G(L.id)},className:"w-5 h-5 flex items-center justify-center rounded text-text-tertiary hover:text-accent-red hover:bg-accent-red-muted transition-colors",title:"Delete annotation",children:P("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[P("polyline",{points:"3 6 5 6 21 6"},void 0,!1,void 0,this),P("path",{d:"M19 6v14a2 2 0 01-2 2H7a2 2 0 01-2-2V6m3 0V4a2 2 0 012-2h4a2 2 0 012 2v2"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},L.id,!0,void 0,this)};return P("div",{className:"flex flex-col h-full",children:[P("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[P("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body flex items-center gap-2",children:["Annotations",Y.length>0&&P("span",{className:"inline-flex items-center justify-center min-w-[18px] h-[18px] px-1 rounded-full bg-border-subtle text-[10px] font-medium text-text-secondary",children:Y.length},void 0,!1,void 0,this),!$1.isShared&&P("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${$?"bg-accent-green":"bg-accent-amber"}`,title:$?"Agent connected":"Agent disconnected"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),q]},void 0,!0,void 0,this),P("div",{ref:O,className:"flex-1 overflow-y-auto",children:[Y.length===0&&P("p",{className:"text-[12px] text-text-tertiary px-3 py-4 leading-relaxed font-body",children:"Select text in the canvas or in files to add annotations."},void 0,!1,void 0,this),S.length>0&&P(t0,{children:[(M.length>0||b.length>0)&&P("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body px-3 mb-1 mt-1",children:"Agent Response"},void 0,!1,void 0,this),S.map(I)]},void 0,!0,void 0,this),M.length>0&&(S.length>0||b.length>0)&&P("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body px-3 mb-1 mt-1",children:"Canvas"},void 0,!1,void 0,this),M.map(I),Object.entries(C).map(([L,d])=>P("div",{children:[P("button",{onClick:()=>y({type:"file",path:L}),className:"flex items-center gap-1.5 text-[10px] uppercase tracking-widest text-text-tertiary hover:text-text-secondary font-body px-3 pt-3 pb-1 truncate transition-colors w-full text-left",title:L,children:[P(x1,{name:L.split("/").pop()||L,type:"file"},void 0,!1,void 0,this),P("span",{className:"truncate",children:L},void 0,!1,void 0,this)]},void 0,!0,void 0,this),d.map(I)]},L,!0,void 0,this))]},void 0,!0,void 0,this),P("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:P("textarea",{value:H,onChange:(L)=>U(L.target.value),className:"w-full bg-transparent text-[13px] font-body text-text-primary resize-none leading-relaxed p-0 border-none ring-0 shadow-none outline-none focus:outline-none focus:ring-0 focus:border-none placeholder:text-text-disabled min-h-[40px]",placeholder:"General notes...",onInput:(L)=>L0(L.target,40),ref:(L)=>{if(L)L0(L,40)}},void 0,!1,void 0,this)},void 0,!1,void 0,this),h&&P("div",{className:"px-4 py-2 text-[12px] text-accent-red font-body border-t border-border-subtle flex-shrink-0 flex items-center justify-between gap-2",children:[P("span",{children:h},void 0,!1,void 0,this),P("button",{onClick:()=>{A(null);let L=b0(Y,H,K,F,V);Z(L)},className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body whitespace-nowrap underline",children:"Submit anyway"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),P("div",{className:"px-4 py-3 border-t border-border-subtle flex-shrink-0",children:u?P("div",{className:"flex gap-2",children:[P("button",{onClick:()=>J(!0),className:"flex-1 py-2 rounded-lg font-body text-[13px] font-medium transition-all bg-border-subtle text-text-secondary hover:bg-border-medium hover:text-text-primary",children:"Preview"},void 0,!1,void 0,this),P("button",{onClick:()=>{let L=o0(K,F);if(L.length>0){A(`Please answer: ${L.join(", ")}`);return}A(null);let d=b0(Y,H,K,F,V);Z(d)},className:"flex-1 py-2 rounded-lg font-body text-[13px] font-medium transition-all bg-btn-primary text-btn-primary-text hover:opacity-90 hover:-translate-y-px shadow-sm",children:"Submit"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):P("button",{onClick:()=>Z("No feedback — looks good."),className:"w-full py-2 rounded-lg font-body text-[13px] font-medium border border-border-medium text-text-secondary hover:text-text-primary hover:border-border-hover hover:bg-bg-input transition-all",children:"Submit without feedback"},void 0,!1,void 0,this)},void 0,!1,void 0,this),P(u3,{open:Q,onClose:()=>J(!1),onSubmit:Z,includedRemoteIds:V,onToggleRemoteId:g},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{useEffect as L4,useState as p3,useContext as c3,useMemo as M4}from"react";import{SessionContext as P4}from"#canvas/runtime";import{jsxDEV as i,Fragment as u2}from"react/jsx-dev-runtime";function d3({embedded:Z}={}){let $=c3(P4),{annotations:q,addAnnotation:Q}=Y1(),{setActiveView:J}=c3(I1),[Y,X]=p3(!1),[G,z]=p3({});if(!L1)return i("div",{className:Z?"px-4 py-3":"p-4",children:[i("div",{className:"text-[11px] uppercase tracking-widest text-text-tertiary font-body mb-2",children:"Files"},void 0,!1,void 0,this),i("p",{className:"text-[11px] text-text-tertiary font-body leading-relaxed",children:"File browsing is not available in shared view. File previews embedded in the canvas still work."},void 0,!1,void 0,this)]},void 0,!0,void 0,this);let{annCountMap:_,annotatedFiles:H}=M4(()=>{let O=new Map;for(let D of q)if(D.filePath&&D.filePath!==T1)O.set(D.filePath,(O.get(D.filePath)||0)+1);return{annCountMap:O,annotatedFiles:[...O.keys()]}},[q]),U=async(O)=>{let S=await(await fetch(`/api/tree?session=${$}&path=${encodeURIComponent(O)}`)).json();if(S.entries)z((M)=>({...M,[O]:{entries:S.entries,expanded:!0,loaded:!0}}))};L4(()=>{if(!Y&&!G[""])U("")},[Y]);let T=(O)=>{if(G[O]?.loaded)z((D)=>({...D,[O]:{...D[O],expanded:!D[O].expanded}}));else U(O)},W=(O)=>{J({type:"file",path:O})},K=async(O)=>{let S=await(await fetch(`/api/file?session=${$}&path=${encodeURIComponent(O)}`)).json();if(!S.error){let M=S.content.split(`
|
|
68
|
+
`)}function H4(Z){let $={label:"",annotations:[],children:new Map};for(let q of Z){let Q=q.context?.hierarchy||[],J=$;for(let Y of Q){if(!J.children.has(Y))J.children.set(Y,{label:Y,annotations:[],children:new Map});J=J.children.get(Y)}J.annotations.push(q)}return $}function c3(Z,$=0){let q=[];for(let Q of Z.annotations)q.push(u2(Q));for(let[,Q]of Z.children){let J=$===0?"###":"####";q.push(`${J} ${Q.label}`),q.push(""),q.push(c3(Q,$+1))}return q.join(`
|
|
69
|
+
`)}import{SessionContext as a3}from"#canvas/runtime";import{useEffect as d3,useState as C0,useRef as W4,useMemo as f2}from"react";import{jsxDEV as Q1}from"react/jsx-dev-runtime";function l3({open:Z,onClose:$,onSubmit:q,includedRemoteIds:Q,onToggleRemoteId:J}){let{annotations:Y,generalNote:X,responses:G,feedbackEntries:z}=X1(),[_,H]=C0(""),[U,W]=C0(!1),[T,K]=C0(!1),[L,N]=C0(null),S=W4(null),[O,R]=C0(!1),b=f2(()=>Y.filter((C)=>C.source==="remote"),[Y]);if(Z&&!O)W(!1),K(!1),N(null);if(!Z&&O)W(!1),K(!1),N(null);if(Z!==O)R(Z);let M=f2(()=>A0(Y,X,G,z,Q),[Y,X,G,z,Q]),j=U?_:M;if(d3(()=>{if(Z&&T&&S.current)S.current.focus()},[Z,T]),d3(()=>{if(!Z)return;let C=(h)=>{if(h.key==="Escape")$()};return window.addEventListener("keydown",C),()=>window.removeEventListener("keydown",C)},[Z,$]),!Z)return null;let g=j.trim().length>0;return Q1("div",{className:"fixed inset-0 z-50 bg-black/50 backdrop-blur-sm flex items-center justify-center p-8",onClick:$,children:Q1("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:(C)=>C.stopPropagation(),children:[Q1("div",{className:"flex items-center justify-between px-5 py-3 border-b border-border-subtle flex-shrink-0",children:[Q1("div",{className:"flex items-center gap-3",children:[Q1("span",{className:"text-[13px] font-medium text-text-primary font-body",children:"Response preview"},void 0,!1,void 0,this),U&&Q1("button",{onClick:()=>{W(!1),K(!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),Q1("div",{className:"flex items-center gap-2",children:[Q1("div",{className:"flex items-center bg-bg-base rounded-md p-0.5",children:[Q1("button",{onClick:()=>K(!1),className:`px-2.5 py-1 rounded text-[11px] font-body font-medium transition-colors ${!T?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Preview"},void 0,!1,void 0,this),Q1("button",{onClick:()=>K(!0),className:`px-2.5 py-1 rounded text-[11px] font-body font-medium transition-colors ${T?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Edit"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Q1("button",{onClick:$,className:"text-text-tertiary hover:text-text-secondary w-7 h-7 flex items-center justify-center rounded-md hover:bg-border-subtle transition-colors",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),T?Q1("textarea",{ref:S,value:j,onChange:(C)=>{H(C.target.value),W(!0)},className:"flex-1 w-full bg-bg-base p-5 text-[13px] font-mono text-text-code resize-none focus:outline-none leading-relaxed placeholder:text-text-disabled",placeholder:"Your feedback will appear here..."},void 0,!1,void 0,this):Q1("div",{className:"flex-1 overflow-y-auto p-5",children:Q1($2,{text:j},void 0,!1,void 0,this)},void 0,!1,void 0,this),b.length>0&&Q1("div",{className:"px-5 py-2 border-t border-border-subtle flex-shrink-0",children:Q1("span",{className:"text-[12px] text-text-secondary font-body",children:["Reviewer feedback: ",Q.size,"/",b.length," included"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),L&&Q1("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:[Q1("span",{children:L},void 0,!1,void 0,this),Q1("button",{onClick:()=>{N(null),q(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),Q1("div",{className:"flex justify-end gap-2 px-5 py-3 border-t border-border-subtle flex-shrink-0",children:[Q1("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),Q1("button",{onClick:()=>{let C=e0(G,z);if(C.length>0){N(`Please answer: ${C.join(", ")}`);return}N(null),q(j)},disabled:!g,className:`px-6 py-2 rounded-lg font-body text-[13px] font-medium transition-all ${g?"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 T4=/!\[([^\]]*)\]\((\/tmp\/agent-canvas\/uploads\/([^)]+))\)/g;function N4(Z){return Z.replace(T4,($,q,Q,J)=>``)}function $2({text:Z}){let $=f2(()=>e.parse(N4(Z),{async:!1}),[Z]);return Q1("div",{className:"prose-canvas font-body text-body text-text-primary leading-relaxed",dangerouslySetInnerHTML:{__html:$}},void 0,!1,void 0,this)}import{jsxDEV as Z0}from"react/jsx-dev-runtime";var O4={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"},B4={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 f1({name:Z,type:$,expanded:q,className:Q=""}){if($==="dir")return Z0("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",className:`flex-shrink-0 ${Q}`,children:q?Z0("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):Z0("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 J=Z.includes(".")?Z.split(".").pop().toLowerCase():"",Y=O4[J]||"#6b6560",X=B4[J];return Z0("svg",{width:"14",height:"14",viewBox:"0 0 16 16",className:`flex-shrink-0 ${Q}`,children:[Z0("path",{d:"M2 1.5h8l3.5 3.5v9.5a1 1 0 01-1 1H3a1 1 0 01-1-1v-12a1 1 0 011-1z",fill:Y,opacity:"0.85"},void 0,!1,void 0,this),Z0("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&&Z0("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 F4(Z){let $=Z.getAttribute("data-md");if($==="item"){let q=Z.getAttribute("data-md-label");return q?`[Item] ${q}`:null}if($==="section"){let q=Z.getAttribute("data-md-title");return q?`[Section] ${q}`:null}if($==="callout"){let q=Z.getAttribute("data-md-type")||"info",Q=Z.textContent?.trim().slice(0,60)||"Callout";return`[Callout:${q}] ${Q}`}if($==="note")return`[Note] ${Z.textContent?.trim().slice(0,60)||"Note"}`;if(Z.tagName==="TR"){let q=Array.from(Z.querySelectorAll("td")).map((Q)=>Q.textContent?.trim()).filter(Boolean);return q.length?`[Row] ${q.join(" | ")}`:null}if($==="checklist-item"){let q=Z.getAttribute("data-md-label");return q?`[Checklist] ${q}`:null}if($==="choice-option"||$==="multichoice-option"){let q=Z.getAttribute("data-md-label");return q?`[Option] ${q}`:null}if($==="userinput"){let q=Z.getAttribute("data-md-label");return q?`[Input] ${q}`:null}if($==="rangeinput"){let q=Z.getAttribute("data-md-label");return q?`[Range] ${q}`:null}if($==="image"){let q=Z.getAttribute("data-md-src");return q?`[Image] ${q}`:null}return null}function V0(Z){let $=document.querySelector(`[data-annotation-id="${Z.id}"]`);if($)return $;if(Z.snippet.startsWith("[")){for(let q 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(F4(q)===Z.snippet)return q}return null}function r3(Z){Z.classList.remove("ann-flash"),Z.offsetWidth,Z.classList.add("ann-flash"),Z.addEventListener("animationend",()=>{Z.classList.remove("ann-flash")},{once:!0})}function v2(Z,$){if(Z.filePath)$({type:"file",path:Z.filePath}),setTimeout(()=>{let q=V0(Z);if(q)q.scrollIntoView({behavior:"smooth",block:"center"}),r3(q)},150);else{let q=V0(Z);if(q)q.scrollIntoView({behavior:"smooth",block:"center"}),r3(q)}}import{jsxDEV as y,Fragment as Z2}from"react/jsx-dev-runtime";function p2({onSubmit:Z,collapseButton:$}){let{isReadOnly:q,selectedRevision:Q,currentRevision:J,revisions:Y,agentWatching:X}=J2(A1),G=J2(a3),z=Y.find((W)=>W.revision===Q),_=q&&Q===J,H=!!z?.feedbackConsumed,U=z?.label||`Round ${Q}`;if(q)return y(y4,{sessionId:G,revision:Q,label:U,waitingForUpdate:_,feedbackConsumed:H,agentWatching:X,collapseButton:$},void 0,!1,void 0,this);return y(j4,{onSubmit:Z,agentWatching:X,collapseButton:$},void 0,!1,void 0,this)}function P4({sessionId:Z,revision:$,label:q,waitingForUpdate:Q,feedbackConsumed:J,agentWatching:Y,collapseButton:X}){let G=$1.isShared,[z,_]=v1(null),[H,U]=v1(!0);return q2(()=>{if(U(!0),!M1){_(null),U(!1);return}fetch(`/api/session/${Z}/revision/${$}/feedback`).then((W)=>W.json()).then((W)=>{_(W.feedback||null),U(!1)}).catch(()=>{_(null),U(!1)})},[Z,$]),y("div",{className:"flex flex-col h-full",children:[y("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[y("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:Q?"Feedback sent":`Feedback — ${q}`},void 0,!1,void 0,this),X]},void 0,!0,void 0,this),Q&&!G&&y(o3,{feedbackConsumed:J,agentWatching:Y},void 0,!1,void 0,this),y("div",{className:"flex-1 overflow-y-auto px-4",children:H?y("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"Loading..."},void 0,!1,void 0,this):z?y($2,{text:z},void 0,!1,void 0,this):y("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"No feedback was submitted for this revision."},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function o3({feedbackConsumed:Z,agentWatching:$}){if(Z)return y("div",{className:"mx-4 mb-3 px-3 py-2.5 rounded-lg bg-accent-green-muted flex items-center gap-2 flex-shrink-0",children:[y("span",{className:"w-2 h-2 rounded-full bg-accent-green animate-pulse"},void 0,!1,void 0,this),y("span",{className:"text-[12px] font-body text-accent-green",children:"Feedback received — waiting for next revision..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if($)return y("div",{className:"mx-4 mb-3 px-3 py-2.5 rounded-lg bg-accent-blue-muted flex items-center gap-2 flex-shrink-0",children:[y("span",{className:"w-2 h-2 rounded-full bg-accent-blue animate-pulse"},void 0,!1,void 0,this),y("span",{className:"text-[12px] font-body text-accent-blue",children:"Waiting for agent to pick up feedback..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return y("div",{className:"mx-4 mb-3 px-3 py-2.5 rounded-lg bg-accent-amber-muted flex items-center gap-2 flex-shrink-0",children:[y("span",{className:"w-2 h-2 rounded-full bg-accent-amber"},void 0,!1,void 0,this),y("span",{className:"text-[12px] font-body text-accent-amber",children:"Agent disconnected — tell Claude to check feedback"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function y4({sessionId:Z,revision:$,label:q,waitingForUpdate:Q,feedbackConsumed:J,agentWatching:Y,collapseButton:X}){let{annotations:G,generalNote:z,activeAnnotationId:_,setActiveAnnotationId:H}=X1(),{setActiveView:U}=J2(k1),W=G.length>0||z.trim().length>0,[T,K]=v1("feedback");if(!W)return y(P4,{sessionId:Z,revision:$,label:q,waitingForUpdate:Q,feedbackConsumed:J,agentWatching:Y,collapseButton:X},void 0,!1,void 0,this);return y("div",{className:"flex flex-col h-full",children:[y("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[y("div",{className:"flex items-center gap-1 bg-bg-input rounded-md p-0.5",children:[y("button",{onClick:()=>K("feedback"),className:`px-2.5 py-1 rounded text-[11px] font-medium font-body transition-colors ${T==="feedback"?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Feedback"},void 0,!1,void 0,this),y("button",{onClick:()=>K("annotations"),className:`px-2.5 py-1 rounded text-[11px] font-medium font-body transition-colors flex items-center gap-1.5 ${T==="annotations"?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:["Annotations",y("span",{className:"inline-flex items-center justify-center min-w-[16px] h-[16px] px-1 rounded-full bg-border-subtle text-[10px] font-medium",children:G.length},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),X]},void 0,!0,void 0,this),Q&&y(o3,{feedbackConsumed:J,agentWatching:Y},void 0,!1,void 0,this),T==="feedback"?y(S4,{sessionId:Z,revision:$},void 0,!1,void 0,this):y(b4,{annotations:G,generalNote:z,activeAnnotationId:_,setActiveAnnotationId:H,setActiveView:U},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function S4({sessionId:Z,revision:$}){let[q,Q]=v1(null),[J,Y]=v1(!0);return q2(()=>{if(Y(!0),!M1){Q(null),Y(!1);return}fetch(`/api/session/${Z}/revision/${$}/feedback`).then((X)=>X.json()).then((X)=>{Q(X.feedback||null),Y(!1)}).catch(()=>{Q(null),Y(!1)})},[Z,$]),y("div",{className:"flex-1 overflow-y-auto px-4",children:J?y("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"Loading..."},void 0,!1,void 0,this):q?y($2,{text:q},void 0,!1,void 0,this):y("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"No feedback was submitted for this revision."},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function b4({annotations:Z,generalNote:$,activeAnnotationId:q,setActiveAnnotationId:Q,setActiveView:J}){let Y=Z.filter((K)=>K.filePath===T1),X=Z.filter((K)=>!K.filePath),G=Z.filter((K)=>K.filePath&&K.filePath!==T1),z={};for(let K of G){let L=K.filePath;if(!z[L])z[L]=[];z[L].push(K)}let _=(K)=>{Q(K),o1(K,!0)},H=(K)=>{Q(null),o1(K,!1)},U=(K)=>{if(K.id===q)Q(null);else if(Q(K.id),K.filePath)J({type:"file",path:K.filePath}),setTimeout(()=>{let L=V0(K);if(L)L.scrollIntoView({behavior:"smooth",block:"center"})},150)},W=(K)=>y("div",{className:`group/ann relative px-3 py-2.5 transition-colors duration-150 cursor-pointer ${q===K.id?"bg-highlight-selected":"odd:bg-bg-elevated-half hover:bg-bg-input"}`,onMouseEnter:()=>_(K.id),onMouseLeave:()=>H(K.id),onClick:()=>U(K),children:[y("div",{className:"text-[11px] text-text-tertiary italic line-clamp-2 mb-1.5 leading-snug font-body border-l-2 border-border-medium pl-2",children:K.snippet.length>80?K.snippet.slice(0,80)+"...":K.snippet},void 0,!1,void 0,this),K.note.trim()&&y("div",{className:"text-[13px] font-body text-text-primary leading-relaxed",children:K.note},void 0,!1,void 0,this),y(D3,{images:K.images||[]},void 0,!1,void 0,this),y("div",{className:"absolute top-1.5 right-1.5 opacity-0 group-hover/ann:opacity-100 transition-opacity duration-100",children:y("button",{onClick:(L)=>{L.stopPropagation(),v2(K,J)},className:"w-5 h-5 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-input transition-colors",title:"Scroll to annotation",children:y("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[y("circle",{cx:"12",cy:"12",r:"3"},void 0,!1,void 0,this),y("path",{d:"M12 2v4M12 18v4M2 12h4M18 12h4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},K.id,!0,void 0,this),T=[Y,X,G].filter((K)=>K.length>0).length>1;return y(Z2,{children:[y("div",{className:"flex-1 overflow-y-auto",children:[Y.length>0&&y(Z2,{children:[T&&y("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body px-3 mb-1 mt-1",children:"Agent Response"},void 0,!1,void 0,this),Y.map(W)]},void 0,!0,void 0,this),X.length>0&&y(Z2,{children:[T&&y("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body px-3 mb-1 mt-1",children:"Canvas"},void 0,!1,void 0,this),X.map(W)]},void 0,!0,void 0,this),Object.entries(z).map(([K,L])=>y("div",{children:[y("button",{onClick:()=>J({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:[y(f1,{name:K.split("/").pop()||K,type:"file"},void 0,!1,void 0,this),y("span",{className:"truncate",children:K},void 0,!1,void 0,this)]},void 0,!0,void 0,this),L.map(W)]},K,!0,void 0,this))]},void 0,!0,void 0,this),$.trim()&&y("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:y("div",{className:"text-[13px] font-body text-text-primary leading-relaxed",children:$},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function j4({onSubmit:Z,agentWatching:$,collapseButton:q}){let[Q,J]=v1(!1),{annotations:Y,updateAnnotation:X,removeAnnotation:G,addAnnotationImage:z,removeAnnotationImage:_,generalNote:H,setGeneralNote:U,activeAnnotationId:W,setActiveAnnotationId:T,responses:K,feedbackEntries:L}=X1(),N=J2(a3),{setActiveView:S}=L4.useContext(k1),O=i3(null),R=i3(new Map),b=Y.filter((F)=>F.filePath===T1),M=Y.filter((F)=>!F.filePath),j=Y.filter((F)=>F.filePath&&F.filePath!==T1),g={};for(let F of j){let m=F.filePath;if(!g[m])g[m]=[];g[m].push(F)}q2(()=>{if(!W)return;let F=R.current.get(W);if(F)F.scrollIntoView({behavior:"smooth",block:"nearest"})},[W]);let C=h2((F)=>{T(F),o1(F,!0)},[T]),h=h2((F)=>{T(null),o1(F,!1)},[W]),v=M4(()=>Y.filter((F)=>F.source==="remote"),[Y]),[l,V]=v1(()=>new Set);q2(()=>{if(v.length===0)return;V((F)=>{let m=new Set(F);for(let u of v)m.add(u.id);return m.size===F.size?F:m})},[v]);let E=h2((F)=>{V((m)=>{let u=new Set(m);if(u.has(F))u.delete(F);else u.add(F);return u})},[]),c=Array.from(K.values()).some(g2),P=L.size>0,x=Y.length>0||H.trim().length>0||c||P,[f,o]=v1(null),w=(F)=>{let m=F.source==="remote";return y("div",{ref:(u)=>{if(u)R.current.set(F.id,u);else R.current.delete(F.id)},className:`group/ann relative px-3 py-2.5 transition-colors duration-150 ${W===F.id?"bg-highlight-selected":m?"bg-accent-purple-muted/30 hover:bg-accent-purple-muted/50":"odd:bg-bg-elevated-half hover:bg-bg-input"}`,onMouseEnter:()=>C(F.id),onMouseLeave:()=>h(F.id),onClick:()=>{if(F.id===W)T(null);else if(T(F.id),F.filePath)S({type:"file",path:F.filePath}),setTimeout(()=>{let u=V0(F);if(u)u.scrollIntoView({behavior:"smooth",block:"center"})},150)},children:[m&&F.author&&y("div",{className:"flex items-center gap-1.5 mb-1.5",children:[y("input",{type:"checkbox",checked:l.has(F.id),onChange:(u)=>{u.stopPropagation(),E(F.id)},onClick:(u)=>u.stopPropagation(),className:"accent-accent-purple flex-shrink-0",title:"Include in submission"},void 0,!1,void 0,this),y("span",{className:"inline-flex items-center justify-center w-4 h-4 rounded-full bg-accent-purple text-white text-[9px] font-medium uppercase",children:F.author.name.charAt(0)},void 0,!1,void 0,this),y("span",{className:"text-[11px] font-medium text-accent-purple font-body",children:F.author.name},void 0,!1,void 0,this),y("span",{className:"text-[10px] text-text-tertiary font-body uppercase tracking-widest",children:"Remote"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),y("div",{className:"text-[11px] text-text-tertiary italic line-clamp-2 mb-1.5 leading-snug font-body border-l-2 border-border-medium pl-2",children:F.snippet.length>80?F.snippet.slice(0,80)+"...":F.snippet},void 0,!1,void 0,this),m?y("div",{className:"text-[13px] font-body text-text-primary leading-relaxed whitespace-pre-wrap",children:F.note},void 0,!1,void 0,this):y("div",{onClick:(u)=>u.stopPropagation(),children:y(c0,{note:F.note,onNoteChange:(u)=>X(F.id,u),images:F.images||[],onAddImage:(u)=>z(F.id,u),onRemoveImage:(u)=>_(F.id,u),sessionId:N,autoResize:!0,minHeight:20,textareaClassName:"w-full bg-transparent text-[13px] font-body text-text-primary resize-none focus:outline-none leading-relaxed p-0 border-none min-h-[20px]",textareaStyle:{height:"auto",overflow:"hidden"},placeholder:"Add your note...",attachButton:"on-focus"},void 0,!1,void 0,this)},void 0,!1,void 0,this),y("div",{className:"absolute top-1.5 right-1.5 opacity-0 group-hover/ann:opacity-100 transition-opacity duration-100 flex items-center gap-0.5",children:[y("button",{onClick:(u)=>{u.stopPropagation(),v2(F,S)},className:"w-5 h-5 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-input transition-colors",title:"Scroll to annotation",children:y("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[y("circle",{cx:"12",cy:"12",r:"3"},void 0,!1,void 0,this),y("path",{d:"M12 2v4M12 18v4M2 12h4M18 12h4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),!m&&y("button",{onClick:(u)=>{u.stopPropagation(),G(F.id)},className:"w-5 h-5 flex items-center justify-center rounded text-text-tertiary hover:text-accent-red hover:bg-accent-red-muted transition-colors",title:"Delete annotation",children:y("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[y("polyline",{points:"3 6 5 6 21 6"},void 0,!1,void 0,this),y("path",{d:"M19 6v14a2 2 0 01-2 2H7a2 2 0 01-2-2V6m3 0V4a2 2 0 012-2h4a2 2 0 012 2v2"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},F.id,!0,void 0,this)};return y("div",{className:"flex flex-col h-full",children:[y("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[y("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body flex items-center gap-2",children:["Annotations",Y.length>0&&y("span",{className:"inline-flex items-center justify-center min-w-[18px] h-[18px] px-1 rounded-full bg-border-subtle text-[10px] font-medium text-text-secondary",children:Y.length},void 0,!1,void 0,this),!$1.isShared&&y("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${$?"bg-accent-green":"bg-accent-amber"}`,title:$?"Agent connected":"Agent disconnected"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),q]},void 0,!0,void 0,this),y("div",{ref:O,className:"flex-1 overflow-y-auto",children:[Y.length===0&&y("p",{className:"text-[12px] text-text-tertiary px-3 py-4 leading-relaxed font-body",children:"Select text in the canvas or in files to add annotations."},void 0,!1,void 0,this),b.length>0&&y(Z2,{children:[(M.length>0||j.length>0)&&y("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body px-3 mb-1 mt-1",children:"Agent Response"},void 0,!1,void 0,this),b.map(w)]},void 0,!0,void 0,this),M.length>0&&(b.length>0||j.length>0)&&y("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body px-3 mb-1 mt-1",children:"Canvas"},void 0,!1,void 0,this),M.map(w),Object.entries(g).map(([F,m])=>y("div",{children:[y("button",{onClick:()=>S({type:"file",path:F}),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:F,children:[y(f1,{name:F.split("/").pop()||F,type:"file"},void 0,!1,void 0,this),y("span",{className:"truncate",children:F},void 0,!1,void 0,this)]},void 0,!0,void 0,this),m.map(w)]},F,!0,void 0,this))]},void 0,!0,void 0,this),y("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:y("textarea",{value:H,onChange:(F)=>U(F.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:(F)=>y0(F.target,40),ref:(F)=>{if(F)y0(F,40)}},void 0,!1,void 0,this)},void 0,!1,void 0,this),f&&y("div",{className:"px-4 py-2 text-[12px] text-accent-red font-body border-t border-border-subtle flex-shrink-0 flex items-center justify-between gap-2",children:[y("span",{children:f},void 0,!1,void 0,this),y("button",{onClick:()=>{o(null);let F=A0(Y,H,K,L,l);Z(F)},className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body whitespace-nowrap underline",children:"Submit anyway"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),y("div",{className:"px-4 py-3 border-t border-border-subtle flex-shrink-0",children:x?y("div",{className:"flex gap-2",children:[y("button",{onClick:()=>J(!0),className:"flex-1 py-2 rounded-lg font-body text-[13px] font-medium transition-all bg-border-subtle text-text-secondary hover:bg-border-medium hover:text-text-primary",children:"Preview"},void 0,!1,void 0,this),y("button",{onClick:()=>{let F=e0(K,L);if(F.length>0){o(`Please answer: ${F.join(", ")}`);return}o(null);let m=A0(Y,H,K,L,l);Z(m)},className:"flex-1 py-2 rounded-lg font-body text-[13px] font-medium transition-all bg-btn-primary text-btn-primary-text hover:opacity-90 hover:-translate-y-px shadow-sm",children:"Submit"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):y("button",{onClick:()=>Z("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),y(l3,{open:Q,onClose:()=>J(!1),onSubmit:Z,includedRemoteIds:l,onToggleRemoteId:E},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{useEffect as w4,useState as s3,useContext as t3,useMemo as A4}from"react";import{SessionContext as C4}from"#canvas/runtime";import{jsxDEV as r,Fragment as c2}from"react/jsx-dev-runtime";function n3({embedded:Z}={}){let $=t3(C4),{annotations:q,addAnnotation:Q}=X1(),{setActiveView:J}=t3(k1),[Y,X]=s3(!1),[G,z]=s3({});if(!M1)return r("div",{className:Z?"px-4 py-3":"p-4",children:[r("div",{className:"text-[11px] uppercase tracking-widest text-text-tertiary font-body mb-2",children:"Files"},void 0,!1,void 0,this),r("p",{className:"text-[11px] text-text-tertiary font-body leading-relaxed",children:"File browsing is not available in shared view. File previews embedded in the canvas still work."},void 0,!1,void 0,this)]},void 0,!0,void 0,this);let{annCountMap:_,annotatedFiles:H}=A4(()=>{let O=new Map;for(let R of q)if(R.filePath&&R.filePath!==T1)O.set(R.filePath,(O.get(R.filePath)||0)+1);return{annCountMap:O,annotatedFiles:[...O.keys()]}},[q]),U=async(O)=>{let b=await(await fetch(`/api/tree?session=${$}&path=${encodeURIComponent(O)}`)).json();if(b.entries)z((M)=>({...M,[O]:{entries:b.entries,expanded:!0,loaded:!0}}))};w4(()=>{if(!Y&&!G[""])U("")},[Y]);let W=(O)=>{if(G[O]?.loaded)z((R)=>({...R,[O]:{...R[O],expanded:!R[O].expanded}}));else U(O)},T=(O)=>{J({type:"file",path:O})},K=async(O)=>{let b=await(await fetch(`/api/file?session=${$}&path=${encodeURIComponent(O)}`)).json();if(!b.error){let M=b.content.split(`
|
|
70
70
|
`).slice(0,3).join(`
|
|
71
|
-
`)+(
|
|
71
|
+
`)+(b.content.split(`
|
|
72
72
|
`).length>3?`
|
|
73
|
-
...`:"");Q(M,"Include this file for context",O)}},
|
|
74
|
-
`);if(!
|
|
75
|
-
`)}catch{return null}},[X,Z]);if(H)return W1("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-[13px]",children:["Loading ",Z,"..."]},void 0,!0,void 0,this);if(
|
|
76
|
-
`);M.current=
|
|
73
|
+
...`:"");Q(M,"Include this file for context",O)}},L=async(O)=>{let R=[];if(G[O]?.loaded)R=G[O].entries;else{let M=await(await fetch(`/api/tree?session=${$}&path=${encodeURIComponent(O)}`)).json();if(M.entries)R=M.entries}await Promise.all(R.filter((b)=>b.type==="file").map((b)=>K(O?`${O}/${b.name}`:b.name)))},N=(O)=>_.get(O)||0,S=(O,R=0)=>{let b=G[O];if(!b?.expanded)return null;return b.entries.map((M)=>{let j=O?`${O}/${M.name}`:M.name,g=N(j);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+R*16}px`,paddingRight:"8px"},children:M.type==="dir"?r(c2,{children:[r("span",{onClick:()=>W(j),className:"flex items-center gap-1.5 flex-1 text-text-secondary hover:text-text-primary cursor-pointer truncate",children:[r(f1,{name:M.name,type:"dir",expanded:G[j]?.expanded},void 0,!1,void 0,this),r("span",{className:"truncate",children:M.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("button",{onClick:(C)=>{C.stopPropagation(),L(j)},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(c2,{children:[r("span",{onClick:()=>T(j),className:`flex-1 truncate cursor-pointer flex items-center gap-1.5 ${g>0?"text-text-primary":"text-text-secondary hover:text-text-primary"}`,children:[r(f1,{name:M.name,type:"file"},void 0,!1,void 0,this),r("span",{className:"truncate",children:M.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:[g>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:g},void 0,!1,void 0,this),r("button",{onClick:(C)=>{C.stopPropagation(),K(j)},className:"text-[11px] text-text-tertiary hover:text-text-secondary opacity-0 group-hover/item:opacity-100 transition-opacity px-1",title:"Add file to context",children:"+"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),M.type==="dir"&&S(j,R+1)]},j,!0,void 0,this)})};if(Z)return r(c2,{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:S("")},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((O)=>r("div",{onClick:()=>T(O),className:"flex items-center justify-between text-[12px] font-body text-text-secondary hover:text-text-primary cursor-pointer py-0.5",children:[r("span",{className:"truncate",children:O.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:N(O)},void 0,!1,void 0,this)]},O,!0,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);if(Y)return 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:S("")},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((O)=>r("div",{onClick:()=>T(O),className:"flex items-center justify-between text-[12px] font-body text-text-secondary hover:text-text-primary cursor-pointer py-0.5",children:[r("span",{className:"truncate",children:O.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:N(O)},void 0,!1,void 0,this)]},O,!0,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}import{useEffect as e3,useState as H0,useContext as V4,useCallback as I4,useRef as Y2,useMemo as $5}from"react";import{SessionContext as R4}from"#canvas/runtime";var Q2={ts:"typescript",tsx:"typescript",js:"javascript",jsx:"javascript",py:"python",rs:"rust",go:"go",rb:"ruby",java:"java",json:"json",yaml:"yaml",yml:"yaml",md:"markdown",css:"css",html:"html",sh:"bash",bash:"bash",toml:"toml",sql:"sql",xml:"xml",c:"c",cpp:"cpp",h:"c"};import{jsxDEV as W1}from"react/jsx-dev-runtime";function Z5(Z){let $=Z instanceof HTMLElement?Z:Z.parentElement;while($){if($.hasAttribute("data-line-num"))return $;$=$.parentElement}return null}function D4(Z){let $=Z.toString().trim(),q=Z5(Z.startContainer),Q=Z5(Z.endContainer),J=q?parseInt(q.getAttribute("data-line-num"),10):void 0,Y=Q?parseInt(Q.getAttribute("data-line-num"),10):void 0,X="",G="";if($.length<30&&q&&q===Q){let z=q.querySelector("code");if(z){let _=z.textContent||"",H=_.indexOf($);if(H>=0)X=_.slice(0,H).trimStart(),G=_.slice(H+$.length).trimEnd()}}return{before:X,after:G,hierarchy:[],lineStart:J,lineEnd:Y}}function q5({path:Z}){if(!M1)return W1("div",{className:"max-w-[720px] mx-auto px-6 pt-12 pb-32",children:W1("div",{className:"p-4 rounded-lg border border-border-subtle bg-bg-surface",children:[W1("div",{className:"text-[11px] uppercase tracking-widest text-text-tertiary font-body mb-2",children:"File not available"},void 0,!1,void 0,this),W1("p",{className:"text-[13px] text-text-secondary font-body leading-relaxed",children:["Opening ",W1("code",{className:"px-1 py-0.5 rounded bg-bg-elevated text-text-primary text-[11px]",children:Z},void 0,!1,void 0,this)," requires filesystem access, which isn't available in shared view. If the canvas author wanted this file visible, they should embed it as a ",W1("code",{className:"px-1 py-0.5 rounded bg-bg-elevated text-text-primary text-[11px]",children:"<FilePreview>"},void 0,!1,void 0,this)," in the canvas."]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this);let $=V4(R4),{annotations:q,addAnnotationWithId:Q,activeAnnotationId:J,setActiveAnnotationId:Y}=X1(),[X,G]=H0(null),[z,_]=H0("text"),[H,U]=H0(!0),[W,T]=H0(null),K=Y2(null),[L,N]=H0(null),[S,O]=H0(null),R=Y2(null),b=Y2(null),M=Y2([]),j=q.filter((P)=>P.filePath===Z),g=K.current?.closest("#plan-scroll-container"),{popovers:C,openCreatePopover:h}=n1({containerRef:K,restoreKey:`${X}:${Z}`,restoreAnnotations:j,extractContext:D4,filePath:Z,scrollContainer:g});e3(()=>{U(!0),T(null),fetch(`/api/file?session=${$}&path=${encodeURIComponent(Z)}`).then((P)=>P.json()).then((P)=>{if(P.error)T(P.error),U(!1);else G(P.content),_(P.language||"text"),U(!1)}).catch(()=>{T("Failed to fetch file"),U(!1)})},[$,Z]);let v=I4((P,x)=>{P.preventDefault(),R.current=x,b.current=x,N(x),O(x)},[]);e3(()=>{let P=(f)=>{if(R.current===null)return;let o=f.target.closest("[data-line-num]");if(o){let w=parseInt(o.getAttribute("data-line-num"),10);b.current=w,O(w)}},x=()=>{let f=R.current;if(f===null)return;R.current=null;let o=b.current??f,w=Math.min(f,o),F=Math.max(f,o),u=M.current.slice(w-1,F).join(`
|
|
74
|
+
`);if(!u.trim()){N(null),O(null);return}let D=`__pending_${Date.now()}`,a={before:"",after:"",hierarchy:[],lineStart:w,lineEnd:F};if(K.current){let I=K.current.querySelectorAll("[data-line-num]"),k=I[w-1],Z1=I[F-1];if(k&&Z1){let I1=k.querySelector("code"),S1=Z1.querySelector("code");if(I1&&S1)try{let N0=document.createRange();N0.setStartBefore(I1.firstChild||I1),N0.setEndAfter(S1.lastChild||S1),s1(N0,D)}catch{}}let Y1=I[F-1];if(Y1)h(Y1,D,u,a)}N(null),O(null)};return document.addEventListener("mousemove",P),document.addEventListener("mouseup",x),()=>{document.removeEventListener("mousemove",P),document.removeEventListener("mouseup",x)}},[]);let l=$5(()=>{if(!X)return null;let P=window.hljs;if(!P)return null;let x=Z.split(".").pop()||"",f=Q2[x];try{return(f?P.highlight(X,{language:f}):P.highlightAuto(X)).value.split(`
|
|
75
|
+
`)}catch{return null}},[X,Z]);if(H)return W1("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-[13px]",children:["Loading ",Z,"..."]},void 0,!0,void 0,this);if(W)return W1("div",{className:"p-8 text-accent-red font-body text-[13px]",children:W},void 0,!1,void 0,this);if(!X)return null;let V=X.split(`
|
|
76
|
+
`);M.current=V;let E=$5(()=>{if(L===null)return null;let P=S??L;return{start:Math.min(L,P),end:Math.max(L,P)}},[L,S]),c=()=>{let P=X.split(`
|
|
77
77
|
`).slice(0,3).join(`
|
|
78
|
-
`)+(
|
|
79
|
-
...`:""),
|
|
78
|
+
`)+(V.length>3?`
|
|
79
|
+
...`:""),x=L1();Q(x,P,"",Z),Y(x)};return W1("div",{children:[W1("pre",{ref:K,className:"text-code font-mono text-text-code bg-bg-base select-text cursor-text py-3 hljs",children:V.map((P,x)=>{let f=x+1,o=E&&f>=E.start&&f<=E.end;return W1("div",{"data-line-num":f,className:`flex px-5 ${o?"bg-accent-blue/10":"hover:bg-bg-elevated-half"}`,children:[W1("span",{className:"text-text-tertiary select-none w-10 text-right pr-4 shrink-0 py-px text-[12px] cursor-pointer opacity-40 hover:opacity-100 hover:text-accent-blue",onMouseDown:(w)=>v(w,f),children:f},void 0,!1,void 0,this),l?W1("code",{className:"py-px",dangerouslySetInnerHTML:{__html:l[x]||" "}},void 0,!1,void 0,this):W1("code",{className:"py-px",children:P||" "},void 0,!1,void 0,this)]},x,!0,void 0,this)})},void 0,!1,void 0,this),C]},void 0,!0,void 0,this)}import{useEffect as J5,useState as Q5,useRef as k4}from"react";import{jsxDEV as C1}from"react/jsx-dev-runtime";function Y5(Z,$){if($){let q=$.replace(/\/+$/,"").split("/");return q[q.length-1]||Z}return Z.length>30?Z.slice(0,30)+"...":Z}function d2({currentSessionId:Z,projectRoot:$}){let[q,Q]=Q5([]),[J,Y]=Q5(!1),X=k4(null);J5(()=>{if(!M1)return;let _=async()=>{try{let W=await(await fetch("/api/sessions")).json();Q((T)=>{let K=JSON.stringify(W);return JSON.stringify(T)===K?T:W})}catch{}};_();let H=setInterval(_,5000);return()=>clearInterval(H)},[]),J5(()=>{if(!J)return;let _=(H)=>{if(X.current&&!X.current.contains(H.target))Y(!1)};return document.addEventListener("mousedown",_),()=>document.removeEventListener("mousedown",_)},[J]);let G=q.filter((_)=>_.id!==Z),z=Y5(Z,$);return C1("div",{className:"relative",ref:X,children:[C1("div",{className:"flex items-center gap-1.5 font-body text-body font-medium",children:[C1("a",{href:`/s/${Z}`,className:"text-text-primary hover:text-text-secondary transition-colors",children:z},void 0,!1,void 0,this),G.length>0&&C1("button",{onClick:()=>Y(!J),className:"flex items-center justify-center text-text-tertiary hover:text-text-secondary transition-colors",children:C1("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:`transition-transform duration-200 ${J?"rotate-180":""}`,children:C1("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),J&&G.length>0&&C1("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((_)=>C1("a",{href:`/s/${_.id}`,className:"flex items-center gap-2.5 px-4 py-2.5 text-body font-body text-text-secondary hover:bg-bg-surface hover:text-text-primary transition-colors",children:[C1("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${_.currentRevision>0?"bg-accent-green":"bg-border-hover"}`},void 0,!1,void 0,this),C1("span",{className:"truncate",children:Y5(_.id,_.projectRoot)},void 0,!1,void 0,this)]},_.id,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function X5(Z){let $=[];return X2(Z,$,0),$.join(`
|
|
80
80
|
`).replace(/\n{3,}/g,`
|
|
81
81
|
|
|
82
82
|
`).trim()+`
|
|
83
|
-
`}var A4=new Set(["CODE","SPAN","STRONG","EM","A","B","I","U","SMALL","SUB","SUP","MARK","ABBR"]);function q2(Z,$,q){if(C4(Z)){let Q=V4(Z);if(Q)$.push(Q,"");return}for(let Q of Z.childNodes)if(Q.nodeType===Node.ELEMENT_NODE)I4(Q,$,q);else if(Q.nodeType===Node.TEXT_NODE){let J=Q.textContent?.trim();if(J)$.push(J,"")}}function C4(Z){for(let $ of Z.childNodes){if($.nodeType===Node.TEXT_NODE)continue;if($.nodeType===Node.ELEMENT_NODE){let q=$;if(!A4.has(q.tagName)||q.hasAttribute("data-md"))return!1}}return Z.childNodes.length>0}function V4(Z){let $="";for(let q of Z.childNodes)if(q.nodeType===Node.TEXT_NODE)$+=q.textContent||"";else if(q.nodeType===Node.ELEMENT_NODE){let Q=q;if(Q.tagName==="CODE")$+="`"+(Q.textContent||"")+"`";else $+=Q.textContent||""}return $.trim()}function I4(Z,$,q){let Q=Z.getAttribute("data-md");if(Q)switch(Q){case"section":return R4(Z,$,q);case"item":return D4(Z,$);case"codeblock":return k4(Z,$);case"callout":return E4(Z,$);case"note":return m4(Z,$);case"markdown":return v4(Z,$);case"table":return x4(Z,$);case"checklist":return u4(Z,$);case"diff":return g4(Z,$);case"mermaid":return f4(Z,$);case"choice":return h4(Z,$);case"multichoice":return p4(Z,$);case"choice-option":case"multichoice-option":return;case"userinput":return c4(Z,$);case"rangeinput":return d4(Z,$);case"checklist-item":return;case"filepreview":return r4(Z,$);case"priority":return l4(Z,$)}if(Z.querySelector("button, input, select, textarea"))return;if(Z.children.length>0)q2(Z,$,q);else{let J=Z.textContent?.trim();if(J)$.push(J,"")}}function R4(Z,$,q){let Q=Z.getAttribute("data-md-title")||"Untitled",J=q===0?"##":"###";$.push(`${J} ${Q}`,"");let Y=Z.querySelector(":scope > div:last-of-type");if(Y)q2(Y,$,q+1)}function D4(Z,$){let q=Z.getAttribute("data-md-label")||"",Q=Z.getAttribute("data-md-status"),J=Z.getAttribute("data-md-badge"),Y="-";if(Q==="done")Y="- [x]";else if(Q)Y="- [ ]";let X=`${Y} **${q}**`;if(J)X+=` \`${J}\``;$.push(X);let G=Z.querySelector(".text-text-secondary");if(G){let z=[];q2(G,z,0);for(let _ of z)$.push(_?` ${_}`:"")}$.push("")}function k4(Z,$){let q=Z.getAttribute("data-md-language")||"",J=Z.querySelector("code")?.textContent||"";$.push(`\`\`\`${q}`,J,"```","")}function E4(Z,$){let q=Z.getAttribute("data-md-type")||"info",Q={info:"Info",warning:"Warning",danger:"Danger",tip:"Tip"},J=i4(Z.querySelector(".text-text-secondary")||Z);$.push(`> **${Q[q]||q}:** ${J}`,"")}function m4(Z,$){let q=Z.textContent?.trim()||"";$.push(`> *${q}*`,"")}function x4(Z,$){let q=Z.querySelector("table");if(!q)return;let Q=[];for(let J of q.querySelectorAll("thead th"))Q.push(J.textContent?.trim()||"");if(Q.length===0)return;$.push(`| ${Q.join(" | ")} |`),$.push(`| ${Q.map(()=>"---").join(" | ")} |`);for(let J of q.querySelectorAll("tbody tr")){let Y=[];for(let X of J.querySelectorAll("td"))Y.push(X.textContent?.trim()||"");$.push(`| ${Y.join(" | ")} |`)}$.push("")}function u4(Z,$){for(let q of Z.querySelectorAll("li")){let Q=q.querySelector(".bg-accent-green")!==null,J=q.textContent?.trim()||"";$.push(`- [${Q?"x":" "}] ${J}`)}$.push("")}function g4(Z,$){let q=Z.getAttribute("data-md-language")||"";$.push(`\`\`\`diff${q?` (${q})`:""}`);for(let Q of Z.querySelectorAll("[class*='flex']")){let J=Q.querySelector(".text-accent-red")?"-":Q.querySelector(".text-accent-green")?"+":" ",Y=Q.querySelector("code");if(Y)$.push(`${J} ${Y.textContent}`)}$.push("```","")}function f4(Z,$){let q=Z.getAttribute("data-md-source")||"";if(q)$.push("```mermaid",q,"```","")}function v4(Z,$){let q=Z.getAttribute("data-md-source")||"";if(q)$.push(q,"")}function h4(Z,$){let q=Z.getAttribute("data-md-label")||"";$.push(`**${q}:**`);for(let Q of Z.querySelectorAll("[data-md='choice-option']")){let J=Q.getAttribute("data-md-label")||Q.textContent?.trim()||"",Y=Q.querySelector(".bg-accent-amber")!==null;$.push(`- ${Y?"(x)":"( )"} ${J}`)}$.push("")}function p4(Z,$){let q=Z.getAttribute("data-md-label")||"";$.push(`**${q}:**`);for(let Q of Z.querySelectorAll("[data-md='multichoice-option']")){let J=Q.getAttribute("data-md-label")||Q.textContent?.trim()||"",Y=Q.querySelector(".bg-accent-amber")!==null;$.push(`- [${Y?"x":" "}] ${J}`)}$.push("")}function c4(Z,$){let q=Z.getAttribute("data-md-label")||"",J=Z.querySelector("textarea")?.value?.trim()||"";$.push(`**${q}:** ${J||"_empty_"}`,"")}function d4(Z,$){let q=Z.getAttribute("data-md-label")||"",Q=Z.querySelector("input[type='range']"),Y=Z.querySelector(".font-mono")?.textContent?.trim()||Q?.value||"—";$.push(`**${q}:** ${Y}`,"")}function r4(Z,$){let q=Z.getAttribute("data-md-path")||"",Q=Z.getAttribute("data-md-lines")||"",Y=Z.querySelector("code")?.textContent||"",X=q.split(".").pop()||"",G=$2[X]||"",z=Q?`${q} (L${Q})`:q;$.push(z,"",`\`\`\`${G}`,Y,"```","")}function l4(Z,$){}function i4(Z){return Z?.textContent?.trim()||""}import U5,{useEffect as f1,useState as G1,useRef as R1,useCallback as K5,useMemo as X2,useContext as G6}from"react";import{useEffect as a4,useState as o4,useRef as s4,useContext as t4}from"react";import{jsxDEV as H1,Fragment as e3}from"react/jsx-dev-runtime";function n4(Z){return Z.label||`Round ${Z.revision}`}function e4(Z){let $=Date.now()-new Date(Z).getTime(),q=Math.floor($/1000);if(q<60)return"just now";let Q=Math.floor(q/60);if(Q<60)return`${Q}m ago`;let J=Math.floor(Q/60);if(J<24)return`${J}h ago`;return`${Math.floor(J/24)}d ago`}function A0({value:Z,onChange:$,accent:q="default",className:Q}){let{currentRevision:J,revisions:Y}=t4(w1),[X,G]=o4(!1),z=s4(null);a4(()=>{if(!X)return;let U=(T)=>{if(z.current&&!z.current.contains(T.target))G(!1)};return document.addEventListener("mousedown",U),()=>document.removeEventListener("mousedown",U)},[X]);let _=Y.find((U)=>U.revision===Z);return H1("div",{className:"relative",ref:z,children:[H1("button",{onClick:()=>G(!X),className:`flex items-center gap-1.5 text-[12px] font-body font-medium px-2 py-1 rounded-md transition-colors hover:bg-bg-elevated ${{default:"text-text-secondary hover:text-text-primary",red:"text-accent-red",green:"text-accent-green",amber:"text-accent-amber bg-highlight-selected"}[q]} ${Q||""}`,children:[_?n4(_):`Round ${Z}`,H1("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",className:`text-text-tertiary transition-transform duration-200 ${X?"rotate-180":""}`,children:H1("path",{d:"M2.5 4l2.5 2.5L7.5 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),X&&H1("div",{className:"absolute top-full left-0 mt-1 w-64 bg-bg-elevated border border-border-hover rounded-lg shadow-lg z-50 py-1 max-h-80 overflow-y-auto",children:[...Y].reverse().map((U)=>H1("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===Z?"bg-bg-surface text-text-primary":"text-text-secondary hover:bg-bg-surface hover:text-text-primary"}`,children:[H1("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${U.revision===J?"bg-accent-green":U.hasFeedback?"bg-accent-amber":"bg-border-hover"}`},void 0,!1,void 0,this),H1("span",{className:"flex-1 text-left truncate",children:U.label?H1(e3,{children:[U.label," ",H1("span",{className:"text-text-tertiary",children:["#",U.revision]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):H1(e3,{children:["Round ",U.revision]},void 0,!0,void 0,this)},void 0,!1,void 0,this),H1("span",{className:"text-[10px] text-text-tertiary flex-shrink-0 flex items-center gap-1.5",children:[(()=>{let T=U.canvasFiles?.reduce((W,K)=>{if(K.diffStats)W.added+=K.diffStats.added,W.removed+=K.diffStats.removed;return W},{added:0,removed:0});if(T&&(T.added>0||T.removed>0))return H1("span",{className:"font-mono",children:[H1("span",{className:"text-accent-green",children:["+",T.added]},void 0,!0,void 0,this)," ",H1("span",{className:"text-accent-red",children:["-",T.removed]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);return null})(),U.revision===J?"current":U.hasFeedback?"sent":e4(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 g1(Z,$){let q=Z.length,Q=$.length;if(q===0||Q===0)return[];let J=Array.from({length:q+1},()=>Array(Q+1).fill(0));for(let z=1;z<=q;z++)for(let _=1;_<=Q;_++)J[z][_]=Z[z-1]===$[_-1]?J[z-1][_-1]+1:Math.max(J[z-1][_],J[z][_-1]);let Y=[],X=q,G=Q;while(X>0&&G>0)if(Z[X-1]===$[G-1])Y.unshift(Z[X-1]),X--,G--;else if(J[X-1][G]>J[X][G-1])X--;else G--;return Y}function $5(Z){let $=[],q=[],Q=document.createTreeWalker(Z,NodeFilter.SHOW_TEXT,{acceptNode(Y){let X=Y.parentElement;if(!X)return NodeFilter.FILTER_REJECT;if(X.closest("svg, .select-none, [data-no-diff]"))return NodeFilter.FILTER_REJECT;return NodeFilter.FILTER_ACCEPT}}),J;while(J=Q.nextNode()){let X=(J.nodeValue||"").match(/\S+|\s+/g);if(!X)continue;let G=0;for(let z of X)$.push(z),q.push({text:z,node:J,offset:G}),G+=z.length}return{words:$,map:q}}function f2(Z,$){if(Z.length>5000||$.length>5000)return $6(Z,$);return J5(Z,$)}function J5(Z,$){let q=J2(Z,$),Q=[],J=[],Y=0,X=0,G=0;while(Y<Z.length||X<$.length)if(G<q.length&&Y<Z.length&&X<$.length&&Z[Y]===q[G]&&$[X]===q[G])Q.push({type:"same",index:Y}),J.push({type:"same",index:X}),Y++,X++,G++;else if(Y<Z.length&&(G>=q.length||Z[Y]!==q[G]))Q.push({type:"removed",index:Y}),Y++;else if(X<$.length)J.push({type:"added",index:X}),X++;return{oldOps:Q,newOps:J}}function J2(Z,$){let q=Z.length,Q=$.length;if(q===0||Q===0)return[];if(q===1)return $.includes(Z[0])?[Z[0]]:[];if(Q===1)return Z.includes($[0])?[$[0]]:[];if(q*Q<=1e6)return g1(Z,$);let J=Math.floor(q/2),Y=Z.slice(0,J),X=Z.slice(J),G=Z5(Y,$),z=Z5([...X].reverse(),[...$].reverse()),_=0,H=0;for(let W=0;W<=Q;W++){let K=G[W]+z[Q-W];if(K>_)_=K,H=W}let U=$.slice(0,H),T=$.slice(H);return[...J2(Y,U),...J2(X,T)]}function Z5(Z,$){let q=$.length,Q=Array(q+1).fill(0),J=Array(q+1).fill(0);for(let Y=0;Y<Z.length;Y++){for(let X=1;X<=q;X++)J[X]=Z[Y]===$[X-1]?Q[X-1]+1:Math.max(Q[X],J[X-1]);[Q,J]=[J,Q],J.fill(0)}return Q}function $6(Z,$){let Q=(K)=>{let F=[];for(let N=0;N<K.length;N+=200){let y=Math.min(N+200,K.length);F.push({start:N,end:y,text:K.slice(N,y).join("")})}return F},J=Q(Z),Y=Q($),X=J.map((K)=>K.text),G=Y.map((K)=>K.text),z=J2(X,G),_=[],H=[],U=0,T=0,W=0;while(U<J.length||T<Y.length)if(W<z.length&&U<J.length&&T<Y.length&&X[U]===z[W]&&G[T]===z[W]){for(let K=J[U].start;K<J[U].end;K++)_.push({type:"same",index:K});for(let K=Y[T].start;K<Y[T].end;K++)H.push({type:"same",index:K});U++,T++,W++}else if(U<J.length&&(W>=z.length||X[U]!==z[W]))if(T<Y.length&&(W>=z.length||G[T]!==z[W])){let K=J5(Z.slice(J[U].start,J[U].end),$.slice(Y[T].start,Y[T].end));for(let F of K.oldOps)_.push({type:F.type,index:F.index+J[U].start});for(let F of K.newOps)H.push({type:F.type,index:F.index+Y[T].start});U++,T++}else{for(let K=J[U].start;K<J[U].end;K++)_.push({type:"removed",index:K});U++}else if(T<Y.length){for(let K=Y[T].start;K<Y[T].end;K++)H.push({type:"added",index:K});T++}return{oldOps:_,newOps:H}}function q5(Z,$,q){let Q=new Map;for(let J of Z){if(J.type==="same")continue;let Y=$[J.index];if(!Y||!Y.node.parentNode)continue;let X=Q.get(Y.node);if(!X)X=[],Q.set(Y.node,X);X.push({offset:Y.offset,length:Y.text.length})}for(let[J,Y]of Q){if(!J.parentNode)continue;let X=J.nodeValue||"";Y.sort((U,T)=>U.offset-T.offset);let G=[];for(let U of Y){let T=G[G.length-1];if(T&&U.offset<=T.offset+T.length)T.length=Math.max(T.length,U.offset+U.length-T.offset);else G.push({...U})}let z=J.parentNode,_=document.createDocumentFragment(),H=0;for(let U of G){if(U.offset>H)_.appendChild(document.createTextNode(X.slice(H,U.offset)));let T=document.createElement("span");T.className=q,T.textContent=X.slice(U.offset,U.offset+U.length),_.appendChild(T),H=U.offset+U.length}if(H<X.length)_.appendChild(document.createTextNode(X.slice(H)));z.replaceChild(_,J)}}function Q2(Z,$){let q=Z6(Z,$),Q=$5(Z),J=$5($),{oldOps:Y,newOps:X}=f2(Q.words,J.words),G=Y.some((z)=>z.type==="removed")||X.some((z)=>z.type==="added");return q5(Y,Q.map,"diff-removed"),q5(X,J.map,"diff-added"),G||q}function Z6(Z,$){let q=Array.from(Z.querySelectorAll('[data-md="mermaid"]')),Q=Array.from($.querySelectorAll('[data-md="mermaid"]')),J=!1,Y=Math.max(q.length,Q.length);for(let X=0;X<Y;X++){let G=q[X],z=Q[X];if(!G&&z){z.classList.add("diff-block-added"),z.style.position="relative",J=!0;continue}if(G&&!z){G.classList.add("diff-block-removed"),G.style.position="relative",J=!0;continue}if(!G||!z)continue;let _=(G.getAttribute("data-md-source")||"").trim(),H=(z.getAttribute("data-md-source")||"").trim();if(_===H)continue;J=!0,G.style.borderLeft="3px solid var(--color-accent-red)",G.style.paddingLeft="8px",z.style.borderLeft="3px solid var(--color-accent-green)",z.style.paddingLeft="8px";let U=_.split(`
|
|
84
|
-
`),
|
|
85
|
-
`),W=g1(U,T),K=(F,N,y)=>{let O=document.createElement("div");O.className="mt-2 bg-bg-code rounded-md overflow-hidden text-tiny font-mono",O.setAttribute("data-no-diff","true");let D=0,S=0;while(S<F.length){let M=document.createElement("div");if(M.className="px-3 py-0.5 whitespace-pre-wrap",D<N.length&&F[S]===N[D])M.textContent=" "+F[S],S++,D++;else M.classList.add(y==="old"?"diff-removed":"diff-added"),M.textContent=(y==="old"?"- ":"+ ")+F[S],S++;O.appendChild(M)}return O};G.appendChild(K(U,W,"old")),z.appendChild(K(T,W,"new"))}return J}function K0(Z){let $=[],q=Z.querySelectorAll(":scope > [data-md]");for(let Q of q)$.push(C0(Q));if($.length===0){let Q=Z.querySelectorAll("[data-md]"),J=new Set;for(let Y of Q){let X=Y.parentElement?.closest("[data-md]");if(X&&Z.contains(X))continue;if(J.has(Y))continue;J.add(Y),$.push(C0(Y))}}return $}function C0(Z){let $=Z.getAttribute("data-md")||"unknown",q=q6(Z,$),Q=[];if($==="section"){let J=Z.querySelector(":scope > div.mt-6, :scope > div:last-child");if(J)for(let Y of J.querySelectorAll(":scope > [data-md]"))Q.push(C0(Y))}else if($==="table")for(let J of Z.querySelectorAll(":scope table > tbody > tr"))Q.push({key:"tr:"+(J.textContent||"").slice(0,80),type:"tr",element:J,children:[]});else if($==="checklist")for(let J of Z.querySelectorAll(":scope > [data-md='checklist-item']"))Q.push(C0(J));else for(let J of Z.querySelectorAll("[data-md]"))if(J.parentElement?.closest("[data-md]")===Z)Q.push(C0(J));return{key:q,type:$,element:Z,children:Q}}function q6(Z,$){switch($){case"section":return"section:"+(Z.getAttribute("data-md-title")||"");case"item":return"item:"+(Z.getAttribute("data-task-id")||Z.getAttribute("data-md-label")||"");case"codeblock":case"diff":return $+":"+(Z.textContent||"").slice(0,80);case"checklist-item":return"checklist-item:"+(Z.getAttribute("data-md-label")||Z.textContent?.slice(0,60)||"");case"checklist":return"checklist:"+Z.querySelectorAll("[data-md='checklist-item']").length;case"markdown":return"markdown:"+(Z.getAttribute("data-md-file")||"inline");case"mermaid":return"mermaid:"+(Z.getAttribute("data-md-source")||"").slice(0,80);case"callout":return"callout:"+(Z.getAttribute("data-md-type")||"")+":"+(Z.textContent||"").slice(0,60);default:return $+":"+(Z.getAttribute("data-md-label")||Z.textContent?.slice(0,60)||"")}}function V0(Z,$){let q=Z.map((_)=>_.key),Q=$.map((_)=>_.key),J=g1(q,Q),Y=[],X=0,G=0,z=0;while(X<Z.length||G<$.length)if(z<J.length&&X<Z.length&&G<$.length&&q[X]===J[z]&&Q[G]===J[z]){let _=Z[X],H=$[G],U=_.children.length>0||H.children.length>0?V0(_.children,H.children):void 0;Y.push({kind:"matched",oldBlock:_,newBlock:H,childMatches:U}),X++,G++,z++}else if(X<Z.length&&(z>=J.length||q[X]!==J[z]))Y.push({kind:"removed",oldBlock:Z[X]}),X++;else if(G<$.length)Y.push({kind:"added",newBlock:$[G]}),G++;return Y}function Y2(Z){let $=document.createDocumentFragment(),q=!1;for(let Q of Z)if(Q.kind==="removed")q=!0,$.appendChild(Y5(Q.oldBlock.element));else if(Q.kind==="added")q=!0,$.appendChild(J6(Q.newBlock.element));else{let J=Q.newBlock.element.cloneNode(!0),Y=Q.newBlock.type;if(Y==="mermaid"){if(G5(Q.oldBlock.element,J))q=!0}else if(Q.childMatches&&Q.childMatches.length>0&&(Y==="table"||Y==="checklist")){if(z5(J,Q.childMatches,Y))q=!0}else if(Q.childMatches&&Q.childMatches.length>0){if(X5(Q.oldBlock,J,Q.childMatches,Y))q=!0}else if(Y==="markdown"){if(_5(Q.oldBlock.element,J))q=!0}else if(Z0(Q.oldBlock.element,J,!1))q=!0;$.appendChild(J)}return{fragment:$,hasChanges:q}}function Y5(Z){let $=Z.cloneNode(!0);return $.classList.add("diff-block-removed"),$.style.position="relative",v2($,"Removed","var(--color-accent-red)"),$}function J6(Z){let $=Z.cloneNode(!0);return $.classList.add("diff-block-added"),$.style.position="relative",v2($,"Added","var(--color-accent-green)"),$}function X5(Z,$,q,Q){let J=!1,Y=Q6(Z,$),X,G;if(Q==="section"){let z=Z.element.querySelector(":scope > div:first-child"),_=$.querySelector(":scope > div:first-child");if(z&&_){if(Z0(z,_,!1))J=!0}X=Z.element.querySelector(":scope > div.mt-6, :scope > div:last-child"),G=$.querySelector(":scope > div.mt-6, :scope > div:last-child")}else X=Z.element,G=$;if(!X||!G)return J;for(let z of q)if(z.kind==="matched"){let _=Y.newMap.get(z.newBlock.element);if(_){if(z.newBlock.type==="mermaid"){if(G5(z.oldBlock.element,_))J=!0}else if(z.childMatches&&z.childMatches.length>0&&(z.newBlock.type==="table"||z.newBlock.type==="checklist")){if(z5(_,z.childMatches,z.newBlock.type))J=!0}else if(z.childMatches&&z.childMatches.length>0){if(X5(z.oldBlock,_,z.childMatches,z.newBlock.type))J=!0}else if(z.newBlock.type==="markdown"){if(_5(z.oldBlock.element,_))J=!0}else if(Z0(z.oldBlock.element,_,!1))J=!0}}else if(z.kind==="removed"){J=!0;let _=Y5(z.oldBlock.element),H=X6(q,z,Y.newMap),U=H?z6(G,H):null;G.insertBefore(_,U)}else if(z.kind==="added"){J=!0;let _=Y.newMap.get(z.newBlock.element);if(_)_.classList.add("diff-block-added"),_.style.position="relative",v2(_,"Added","var(--color-accent-green)")}if(Z0(X,G,!0))J=!0;return J}function z5(Z,$,q){let Q=q==="table"?Z.querySelector(":scope table > tbody"):Z;if(!Q)return!1;let J=!1;Q.innerHTML="";for(let Y of $)if(Y.kind==="removed"){J=!0;let X=Y.oldBlock.element.cloneNode(!0);X.classList.add(q==="table"?"diff-row-removed":"diff-item-removed"),Q.appendChild(X)}else if(Y.kind==="added"){J=!0;let X=Y.newBlock.element.cloneNode(!0);X.classList.add(q==="table"?"diff-row-added":"diff-item-added"),Q.appendChild(X)}else{let X=Y.newBlock.element.cloneNode(!0);if(Z0(Y.oldBlock.element,X,!1))J=!0;Q.appendChild(X)}return J}function Q6(Z,$){let q=new Map,Q=Z.element.querySelectorAll("[data-md]"),J=$.querySelectorAll("[data-md]");return{newMap:{get(Y){return Y6($,Y)}}}}function Y6(Z,$){let q=$.getAttribute("data-md");if(!q)return null;let Q=$.getAttribute("data-md-label"),J=$.getAttribute("data-md-title"),Y=`[data-md="${q}"]`;if(J)Y+=`[data-md-title="${CSS.escape(J)}"]`;else if(Q)Y+=`[data-md-label="${CSS.escape(Q)}"]`;let X=Z.querySelectorAll(Y);if(X.length===1)return X[0];let G=($.textContent||"").slice(0,100),z=null,_=-1;for(let H of X){let U=(H.textContent||"").slice(0,100),T=0;for(let W=0;W<Math.min(G.length,U.length);W++)if(G[W]===U[W])T++;if(T>_)_=T,z=H}return z}function X6(Z,$,q){let Q=Z.indexOf($);for(let J=Q+1;J<Z.length;J++){let Y=Z[J];if((Y.kind==="matched"||Y.kind==="added")&&Y.newBlock)return q.get(Y.newBlock.element)||null}return null}function z6(Z,$){let q=$;while(q&&q.parentElement!==Z)q=q.parentElement;return q}function _5(Z,$){let q=Array.from(Z.children),Q=Array.from($.children);if(q.length===0&&Q.length===0)return Z0(Z,$,!1);let J=q.map((T)=>T.tagName.toLowerCase()),Y=Q.map((T)=>T.tagName.toLowerCase()),X=g1(J,Y),G=[],z=0,_=0,H=0;while(z<q.length||_<Q.length)if(H<X.length&&z<q.length&&_<Q.length&&J[z]===X[H]&&Y[_]===X[H])G.push({kind:"matched",oldChild:q[z],newChild:Q[_]}),z++,_++,H++;else if(z<q.length&&(H>=X.length||J[z]!==X[H]))G.push({kind:"removed",oldChild:q[z]}),z++;else if(_<Q.length)G.push({kind:"added",newChild:Q[_]}),_++;let U=!1;while($.firstChild)$.removeChild($.firstChild);for(let T of G)if(T.kind==="matched"){let W=(T.oldChild.textContent||"").match(/\S+/g)||[],K=(T.newChild.textContent||"").match(/\S+/g)||[],F=g1(W,K),N=Math.max(W.length,K.length);if((N>0?1-F.length/N:0)>0.5){U=!0;let O=T.oldChild.cloneNode(!0);O.classList.add("diff-block-removed"),$.appendChild(O),T.newChild.classList.add("diff-block-added"),$.appendChild(T.newChild)}else{if(Z0(T.oldChild,T.newChild,!1))U=!0;$.appendChild(T.newChild)}}else if(T.kind==="removed"){U=!0;let W=T.oldChild.cloneNode(!0);W.classList.add("diff-block-removed"),$.appendChild(W)}else U=!0,T.newChild.classList.add("diff-block-added"),$.appendChild(T.newChild);return U}function Q5(Z,$){let q=$?new Set(Array.from(Z.querySelectorAll("[data-md]"))):new Set,Q=[],J=[],Y=document.createTreeWalker(Z,NodeFilter.SHOW_TEXT,{acceptNode(G){let z=G.parentElement;if(!z)return NodeFilter.FILTER_REJECT;if(z.closest("svg, .select-none, [data-no-diff]"))return NodeFilter.FILTER_REJECT;if($){for(let _ of q)if(_.contains(G))return NodeFilter.FILTER_REJECT}return NodeFilter.FILTER_ACCEPT}}),X;while(X=Y.nextNode()){let z=(X.nodeValue||"").match(/\S+|\s+/g);if(!z)continue;let _=0;for(let H of z)Q.push(H),J.push({text:H,node:X,offset:_}),_+=H.length}return{words:Q,map:J}}function Z0(Z,$,q){let Q=Q5(Z,q),J=Q5($,q);if(Q.words.length===0&&J.words.length===0)return!1;let{oldOps:Y,newOps:X}=f2(Q.words,J.words),G=Y.some((N)=>N.type==="removed"),z=X.some((N)=>N.type==="added");if(!G&&!z)return!1;let _=[],H=[];for(let N of Y)if(N.type==="same")_.push(N.index);for(let N of X)if(N.type==="same")H.push(N.index);let U=new Map;for(let N=0;N<_.length&&N<H.length;N++)U.set(_[N],H[N]);let T=[];{let N=[],y=-1;for(let O of Y)if(O.type==="same"){if(N.length>0)T.push({text:N.join(""),anchorNewIdx:y>=0?U.get(y)??null:null}),N=[];y=O.index}else if(O.type==="removed")N.push(Q.words[O.index]);if(N.length>0)T.push({text:N.join(""),anchorNewIdx:y>=0?U.get(y)??null:null})}let W=new Map,K=new Map;for(let N of X){if(N.type!=="added")continue;let y=J.map[N.index];if(!y?.node.parentNode)continue;let O=W.get(y.node);if(!O)O=[],W.set(y.node,O);O.push({start:y.offset,end:y.offset+y.text.length})}for(let N of T)if(N.anchorNewIdx===null){if(J.map.length>0){let y=J.map[0].node,O=K.get(y);if(!O)O=[],K.set(y,O);O.push({offset:0,text:N.text})}}else{let y=J.map[N.anchorNewIdx];if(!y)continue;let O=K.get(y.node);if(!O)O=[],K.set(y.node,O);O.push({offset:y.offset+y.text.length,text:N.text})}let F=new Set([...W.keys(),...K.keys()]);for(let N of F)_6(N,W.get(N)||[],K.get(N)||[]);return!0}function _6(Z,$,q){if(!Z.parentNode)return;let Q=Z.nodeValue||"";$.sort((H,U)=>H.start-U.start);let J=[];for(let H of $){let U=J[J.length-1];if(U&&H.start<=U.end)U.end=Math.max(U.end,H.end);else J.push({...H})}q.sort((H,U)=>H.offset-U.offset);let Y=Z.parentNode,X=document.createDocumentFragment(),G=0,z=0,_=0;while(G<=Q.length){let H=z<J.length?J[z].start:1/0,U=_<q.length?q[_].offset:1/0,T=Math.min(H,U);if(T===1/0){if(G<Q.length)X.appendChild(document.createTextNode(Q.slice(G)));break}let W=Math.max(T,G);if(W>G)X.appendChild(document.createTextNode(Q.slice(G,W))),G=W;while(_<q.length&&q[_].offset<=G){let K=document.createElement("span");K.className="diff-removed",K.textContent=q[_].text,X.appendChild(K),_++}if(z<J.length&&J[z].start<=G){let K=J[z],F=document.createElement("span");F.className="diff-added",F.textContent=Q.slice(G,K.end),X.appendChild(F),G=K.end,z++;while(_<q.length&&q[_].offset<=G){let N=document.createElement("span");N.className="diff-removed",N.textContent=q[_].text,X.appendChild(N),_++}}}while(_<q.length){let H=document.createElement("span");H.className="diff-removed",H.textContent=q[_].text,X.appendChild(H),_++}Y.replaceChild(X,Z)}function G5(Z,$){let q=(Z.getAttribute("data-md-source")||"").trim(),Q=($.getAttribute("data-md-source")||"").trim();if(q===Q)return!1;let J=q.split(`
|
|
83
|
+
`}var E4=new Set(["CODE","SPAN","STRONG","EM","A","B","I","U","SMALL","SUB","SUP","MARK","ABBR"]);function X2(Z,$,q){if(x4(Z)){let Q=m4(Z);if(Q)$.push(Q,"");return}for(let Q of Z.childNodes)if(Q.nodeType===Node.ELEMENT_NODE)u4(Q,$,q);else if(Q.nodeType===Node.TEXT_NODE){let J=Q.textContent?.trim();if(J)$.push(J,"")}}function x4(Z){for(let $ of Z.childNodes){if($.nodeType===Node.TEXT_NODE)continue;if($.nodeType===Node.ELEMENT_NODE){let q=$;if(!E4.has(q.tagName)||q.hasAttribute("data-md"))return!1}}return Z.childNodes.length>0}function m4(Z){let $="";for(let q of Z.childNodes)if(q.nodeType===Node.TEXT_NODE)$+=q.textContent||"";else if(q.nodeType===Node.ELEMENT_NODE){let Q=q;if(Q.tagName==="CODE")$+="`"+(Q.textContent||"")+"`";else $+=Q.textContent||""}return $.trim()}function u4(Z,$,q){let Q=Z.getAttribute("data-md");if(Q)switch(Q){case"section":return g4(Z,$,q);case"item":return f4(Z,$);case"codeblock":return v4(Z,$);case"callout":return h4(Z,$);case"note":return p4(Z,$);case"markdown":return i4(Z,$);case"table":return c4(Z,$);case"checklist":return d4(Z,$);case"diff":return l4(Z,$);case"mermaid":return r4(Z,$);case"choice":return a4(Z,$);case"multichoice":return o4(Z,$);case"choice-option":case"multichoice-option":return;case"userinput":return s4(Z,$);case"rangeinput":return t4(Z,$);case"checklist-item":return;case"filepreview":return n4(Z,$);case"priority":return e4(Z,$)}if(Z.querySelector("button, input, select, textarea"))return;if(Z.children.length>0)X2(Z,$,q);else{let J=Z.textContent?.trim();if(J)$.push(J,"")}}function g4(Z,$,q){let Q=Z.getAttribute("data-md-title")||"Untitled",J=q===0?"##":"###";$.push(`${J} ${Q}`,"");let Y=Z.querySelector(":scope > div:last-of-type");if(Y)X2(Y,$,q+1)}function f4(Z,$){let q=Z.getAttribute("data-md-label")||"",Q=Z.getAttribute("data-md-status"),J=Z.getAttribute("data-md-badge"),Y="-";if(Q==="done")Y="- [x]";else if(Q)Y="- [ ]";let X=`${Y} **${q}**`;if(J)X+=` \`${J}\``;$.push(X);let G=Z.querySelector(".text-text-secondary");if(G){let z=[];X2(G,z,0);for(let _ of z)$.push(_?` ${_}`:"")}$.push("")}function v4(Z,$){let q=Z.getAttribute("data-md-language")||"",J=Z.querySelector("code")?.textContent||"";$.push(`\`\`\`${q}`,J,"```","")}function h4(Z,$){let q=Z.getAttribute("data-md-type")||"info",Q={info:"Info",warning:"Warning",danger:"Danger",tip:"Tip"},J=$6(Z.querySelector(".text-text-secondary")||Z);$.push(`> **${Q[q]||q}:** ${J}`,"")}function p4(Z,$){let q=Z.textContent?.trim()||"";$.push(`> *${q}*`,"")}function c4(Z,$){let q=Z.querySelector("table");if(!q)return;let Q=[];for(let J of q.querySelectorAll("thead th"))Q.push(J.textContent?.trim()||"");if(Q.length===0)return;$.push(`| ${Q.join(" | ")} |`),$.push(`| ${Q.map(()=>"---").join(" | ")} |`);for(let J of q.querySelectorAll("tbody tr")){let Y=[];for(let X of J.querySelectorAll("td"))Y.push(X.textContent?.trim()||"");$.push(`| ${Y.join(" | ")} |`)}$.push("")}function d4(Z,$){for(let q of Z.querySelectorAll("li")){let Q=q.querySelector(".bg-accent-green")!==null,J=q.textContent?.trim()||"";$.push(`- [${Q?"x":" "}] ${J}`)}$.push("")}function l4(Z,$){let q=Z.getAttribute("data-md-language")||"";$.push(`\`\`\`diff${q?` (${q})`:""}`);for(let Q of Z.querySelectorAll("[class*='flex']")){let J=Q.querySelector(".text-accent-red")?"-":Q.querySelector(".text-accent-green")?"+":" ",Y=Q.querySelector("code");if(Y)$.push(`${J} ${Y.textContent}`)}$.push("```","")}function r4(Z,$){let q=Z.getAttribute("data-md-source")||"";if(q)$.push("```mermaid",q,"```","")}function i4(Z,$){let q=Z.getAttribute("data-md-source")||"";if(q)$.push(q,"")}function a4(Z,$){let q=Z.getAttribute("data-md-label")||"";$.push(`**${q}:**`);for(let Q of Z.querySelectorAll("[data-md='choice-option']")){let J=Q.getAttribute("data-md-label")||Q.textContent?.trim()||"",Y=Q.querySelector(".bg-accent-amber")!==null;$.push(`- ${Y?"(x)":"( )"} ${J}`)}$.push("")}function o4(Z,$){let q=Z.getAttribute("data-md-label")||"";$.push(`**${q}:**`);for(let Q of Z.querySelectorAll("[data-md='multichoice-option']")){let J=Q.getAttribute("data-md-label")||Q.textContent?.trim()||"",Y=Q.querySelector(".bg-accent-amber")!==null;$.push(`- [${Y?"x":" "}] ${J}`)}$.push("")}function s4(Z,$){let q=Z.getAttribute("data-md-label")||"",J=Z.querySelector("textarea")?.value?.trim()||"";$.push(`**${q}:** ${J||"_empty_"}`,"")}function t4(Z,$){let q=Z.getAttribute("data-md-label")||"",Q=Z.querySelector("input[type='range']"),Y=Z.querySelector(".font-mono")?.textContent?.trim()||Q?.value||"—";$.push(`**${q}:** ${Y}`,"")}function n4(Z,$){let q=Z.getAttribute("data-md-path")||"",Q=Z.getAttribute("data-md-lines")||"",Y=Z.querySelector("code")?.textContent||"",X=q.split(".").pop()||"",G=Q2[X]||"",z=Q?`${q} (L${Q})`:q;$.push(z,"",`\`\`\`${G}`,Y,"```","")}function e4(Z,$){}function $6(Z){return Z?.textContent?.trim()||""}import F5,{useEffect as p1,useState as U1,useRef as E1,useCallback as L5,useMemo as U2,useContext as O6}from"react";import{useEffect as Z6,useState as q6,useRef as J6,useContext as Q6}from"react";import{jsxDEV as H1,Fragment as z5}from"react/jsx-dev-runtime";function Y6(Z){return Z.label||`Round ${Z.revision}`}function X6(Z){let $=Date.now()-new Date(Z).getTime(),q=Math.floor($/1000);if(q<60)return"just now";let Q=Math.floor(q/60);if(Q<60)return`${Q}m ago`;let J=Math.floor(Q/60);if(J<24)return`${J}h ago`;return`${Math.floor(J/24)}d ago`}function I0({value:Z,onChange:$,accent:q="default",className:Q}){let{currentRevision:J,revisions:Y}=Q6(A1),[X,G]=q6(!1),z=J6(null);Z6(()=>{if(!X)return;let U=(W)=>{if(z.current&&!z.current.contains(W.target))G(!1)};return document.addEventListener("mousedown",U),()=>document.removeEventListener("mousedown",U)},[X]);let _=Y.find((U)=>U.revision===Z);return H1("div",{className:"relative",ref:z,children:[H1("button",{onClick:()=>G(!X),className:`flex items-center gap-1.5 text-[12px] font-body font-medium px-2 py-1 rounded-md transition-colors hover:bg-bg-elevated ${{default:"text-text-secondary hover:text-text-primary",red:"text-accent-red",green:"text-accent-green",amber:"text-accent-amber bg-highlight-selected"}[q]} ${Q||""}`,children:[_?Y6(_):`Round ${Z}`,H1("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",className:`text-text-tertiary transition-transform duration-200 ${X?"rotate-180":""}`,children:H1("path",{d:"M2.5 4l2.5 2.5L7.5 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),X&&H1("div",{className:"absolute top-full left-0 mt-1 w-64 bg-bg-elevated border border-border-hover rounded-lg shadow-lg z-50 py-1 max-h-80 overflow-y-auto",children:[...Y].reverse().map((U)=>H1("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===Z?"bg-bg-surface text-text-primary":"text-text-secondary hover:bg-bg-surface hover:text-text-primary"}`,children:[H1("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${U.revision===J?"bg-accent-green":U.hasFeedback?"bg-accent-amber":"bg-border-hover"}`},void 0,!1,void 0,this),H1("span",{className:"flex-1 text-left truncate",children:U.label?H1(z5,{children:[U.label," ",H1("span",{className:"text-text-tertiary",children:["#",U.revision]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):H1(z5,{children:["Round ",U.revision]},void 0,!0,void 0,this)},void 0,!1,void 0,this),H1("span",{className:"text-[10px] text-text-tertiary flex-shrink-0 flex items-center gap-1.5",children:[(()=>{let W=U.canvasFiles?.reduce((T,K)=>{if(K.diffStats)T.added+=K.diffStats.added,T.removed+=K.diffStats.removed;return T},{added:0,removed:0});if(W&&(W.added>0||W.removed>0))return H1("span",{className:"font-mono",children:[H1("span",{className:"text-accent-green",children:["+",W.added]},void 0,!0,void 0,this)," ",H1("span",{className:"text-accent-red",children:["-",W.removed]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);return null})(),U.revision===J?"current":U.hasFeedback?"sent":X6(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 h1(Z,$){let q=Z.length,Q=$.length;if(q===0||Q===0)return[];let J=Array.from({length:q+1},()=>Array(Q+1).fill(0));for(let z=1;z<=q;z++)for(let _=1;_<=Q;_++)J[z][_]=Z[z-1]===$[_-1]?J[z-1][_-1]+1:Math.max(J[z-1][_],J[z][_-1]);let Y=[],X=q,G=Q;while(X>0&&G>0)if(Z[X-1]===$[G-1])Y.unshift(Z[X-1]),X--,G--;else if(J[X-1][G]>J[X][G-1])X--;else G--;return Y}function _5(Z){let $=[],q=[],Q=document.createTreeWalker(Z,NodeFilter.SHOW_TEXT,{acceptNode(Y){let X=Y.parentElement;if(!X)return NodeFilter.FILTER_REJECT;if(X.closest("svg, .select-none, [data-no-diff]"))return NodeFilter.FILTER_REJECT;return NodeFilter.FILTER_ACCEPT}}),J;while(J=Q.nextNode()){let X=(J.nodeValue||"").match(/\S+|\s+/g);if(!X)continue;let G=0;for(let z of X)$.push(z),q.push({text:z,node:J,offset:G}),G+=z.length}return{words:$,map:q}}function l2(Z,$){if(Z.length>5000||$.length>5000)return z6(Z,$);return K5(Z,$)}function K5(Z,$){let q=z2(Z,$),Q=[],J=[],Y=0,X=0,G=0;while(Y<Z.length||X<$.length)if(G<q.length&&Y<Z.length&&X<$.length&&Z[Y]===q[G]&&$[X]===q[G])Q.push({type:"same",index:Y}),J.push({type:"same",index:X}),Y++,X++,G++;else if(Y<Z.length&&(G>=q.length||Z[Y]!==q[G]))Q.push({type:"removed",index:Y}),Y++;else if(X<$.length)J.push({type:"added",index:X}),X++;return{oldOps:Q,newOps:J}}function z2(Z,$){let q=Z.length,Q=$.length;if(q===0||Q===0)return[];if(q===1)return $.includes(Z[0])?[Z[0]]:[];if(Q===1)return Z.includes($[0])?[$[0]]:[];if(q*Q<=1e6)return h1(Z,$);let J=Math.floor(q/2),Y=Z.slice(0,J),X=Z.slice(J),G=G5(Y,$),z=G5([...X].reverse(),[...$].reverse()),_=0,H=0;for(let T=0;T<=Q;T++){let K=G[T]+z[Q-T];if(K>_)_=K,H=T}let U=$.slice(0,H),W=$.slice(H);return[...z2(Y,U),...z2(X,W)]}function G5(Z,$){let q=$.length,Q=Array(q+1).fill(0),J=Array(q+1).fill(0);for(let Y=0;Y<Z.length;Y++){for(let X=1;X<=q;X++)J[X]=Z[Y]===$[X-1]?Q[X-1]+1:Math.max(Q[X],J[X-1]);[Q,J]=[J,Q],J.fill(0)}return Q}function z6(Z,$){let Q=(K)=>{let L=[];for(let N=0;N<K.length;N+=200){let S=Math.min(N+200,K.length);L.push({start:N,end:S,text:K.slice(N,S).join("")})}return L},J=Q(Z),Y=Q($),X=J.map((K)=>K.text),G=Y.map((K)=>K.text),z=z2(X,G),_=[],H=[],U=0,W=0,T=0;while(U<J.length||W<Y.length)if(T<z.length&&U<J.length&&W<Y.length&&X[U]===z[T]&&G[W]===z[T]){for(let K=J[U].start;K<J[U].end;K++)_.push({type:"same",index:K});for(let K=Y[W].start;K<Y[W].end;K++)H.push({type:"same",index:K});U++,W++,T++}else if(U<J.length&&(T>=z.length||X[U]!==z[T]))if(W<Y.length&&(T>=z.length||G[W]!==z[T])){let K=K5(Z.slice(J[U].start,J[U].end),$.slice(Y[W].start,Y[W].end));for(let L of K.oldOps)_.push({type:L.type,index:L.index+J[U].start});for(let L of K.newOps)H.push({type:L.type,index:L.index+Y[W].start});U++,W++}else{for(let K=J[U].start;K<J[U].end;K++)_.push({type:"removed",index:K});U++}else if(W<Y.length){for(let K=Y[W].start;K<Y[W].end;K++)H.push({type:"added",index:K});W++}return{oldOps:_,newOps:H}}function U5(Z,$,q){let Q=new Map;for(let J of Z){if(J.type==="same")continue;let Y=$[J.index];if(!Y||!Y.node.parentNode)continue;let X=Q.get(Y.node);if(!X)X=[],Q.set(Y.node,X);X.push({offset:Y.offset,length:Y.text.length})}for(let[J,Y]of Q){if(!J.parentNode)continue;let X=J.nodeValue||"";Y.sort((U,W)=>U.offset-W.offset);let G=[];for(let U of Y){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 z=J.parentNode,_=document.createDocumentFragment(),H=0;for(let U of G){if(U.offset>H)_.appendChild(document.createTextNode(X.slice(H,U.offset)));let W=document.createElement("span");W.className=q,W.textContent=X.slice(U.offset,U.offset+U.length),_.appendChild(W),H=U.offset+U.length}if(H<X.length)_.appendChild(document.createTextNode(X.slice(H)));z.replaceChild(_,J)}}function _2(Z,$){let q=_6(Z,$),Q=_5(Z),J=_5($),{oldOps:Y,newOps:X}=l2(Q.words,J.words),G=Y.some((z)=>z.type==="removed")||X.some((z)=>z.type==="added");return U5(Y,Q.map,"diff-removed"),U5(X,J.map,"diff-added"),G||q}function _6(Z,$){let q=Array.from(Z.querySelectorAll('[data-md="mermaid"]')),Q=Array.from($.querySelectorAll('[data-md="mermaid"]')),J=!1,Y=Math.max(q.length,Q.length);for(let X=0;X<Y;X++){let G=q[X],z=Q[X];if(!G&&z){z.classList.add("diff-block-added"),z.style.position="relative",J=!0;continue}if(G&&!z){G.classList.add("diff-block-removed"),G.style.position="relative",J=!0;continue}if(!G||!z)continue;let _=(G.getAttribute("data-md-source")||"").trim(),H=(z.getAttribute("data-md-source")||"").trim();if(_===H)continue;J=!0,G.style.borderLeft="3px solid var(--color-accent-red)",G.style.paddingLeft="8px",z.style.borderLeft="3px solid var(--color-accent-green)",z.style.paddingLeft="8px";let U=_.split(`
|
|
84
|
+
`),W=H.split(`
|
|
85
|
+
`),T=h1(U,W),K=(L,N,S)=>{let O=document.createElement("div");O.className="mt-2 bg-bg-code rounded-md overflow-hidden text-tiny font-mono",O.setAttribute("data-no-diff","true");let R=0,b=0;while(b<L.length){let M=document.createElement("div");if(M.className="px-3 py-0.5 whitespace-pre-wrap",R<N.length&&L[b]===N[R])M.textContent=" "+L[b],b++,R++;else M.classList.add(S==="old"?"diff-removed":"diff-added"),M.textContent=(S==="old"?"- ":"+ ")+L[b],b++;O.appendChild(M)}return O};G.appendChild(K(U,T,"old")),z.appendChild(K(W,T,"new"))}return J}function W0(Z){let $=[],q=Z.querySelectorAll(":scope > [data-md]");for(let Q of q)$.push(R0(Q));if($.length===0){let Q=Z.querySelectorAll("[data-md]"),J=new Set;for(let Y of Q){let X=Y.parentElement?.closest("[data-md]");if(X&&Z.contains(X))continue;if(J.has(Y))continue;J.add(Y),$.push(R0(Y))}}return $}function R0(Z){let $=Z.getAttribute("data-md")||"unknown",q=G6(Z,$),Q=[];if($==="section"){let J=Z.querySelector(":scope > div.mt-6, :scope > div:last-child");if(J)for(let Y of J.querySelectorAll(":scope > [data-md]"))Q.push(R0(Y))}else if($==="table")for(let J of Z.querySelectorAll(":scope table > tbody > tr"))Q.push({key:"tr:"+(J.textContent||"").slice(0,80),type:"tr",element:J,children:[]});else if($==="checklist")for(let J of Z.querySelectorAll(":scope > [data-md='checklist-item']"))Q.push(R0(J));else for(let J of Z.querySelectorAll("[data-md]"))if(J.parentElement?.closest("[data-md]")===Z)Q.push(R0(J));return{key:q,type:$,element:Z,children:Q}}function G6(Z,$){switch($){case"section":return"section:"+(Z.getAttribute("data-md-title")||"");case"item":return"item:"+(Z.getAttribute("data-task-id")||Z.getAttribute("data-md-label")||"");case"codeblock":case"diff":return $+":"+(Z.textContent||"").slice(0,80);case"checklist-item":return"checklist-item:"+(Z.getAttribute("data-md-label")||Z.textContent?.slice(0,60)||"");case"checklist":return"checklist:"+Z.querySelectorAll("[data-md='checklist-item']").length;case"markdown":return"markdown:"+(Z.getAttribute("data-md-file")||"inline");case"mermaid":return"mermaid:"+(Z.getAttribute("data-md-source")||"").slice(0,80);case"callout":return"callout:"+(Z.getAttribute("data-md-type")||"")+":"+(Z.textContent||"").slice(0,60);default:return $+":"+(Z.getAttribute("data-md-label")||Z.textContent?.slice(0,60)||"")}}function D0(Z,$){let q=Z.map((_)=>_.key),Q=$.map((_)=>_.key),J=h1(q,Q),Y=[],X=0,G=0,z=0;while(X<Z.length||G<$.length)if(z<J.length&&X<Z.length&&G<$.length&&q[X]===J[z]&&Q[G]===J[z]){let _=Z[X],H=$[G],U=_.children.length>0||H.children.length>0?D0(_.children,H.children):void 0;Y.push({kind:"matched",oldBlock:_,newBlock:H,childMatches:U}),X++,G++,z++}else if(X<Z.length&&(z>=J.length||q[X]!==J[z]))Y.push({kind:"removed",oldBlock:Z[X]}),X++;else if(G<$.length)Y.push({kind:"added",newBlock:$[G]}),G++;return Y}function G2(Z){let $=document.createDocumentFragment(),q=!1;for(let Q of Z)if(Q.kind==="removed")q=!0,$.appendChild(W5(Q.oldBlock.element));else if(Q.kind==="added")q=!0,$.appendChild(U6(Q.newBlock.element));else{let J=Q.newBlock.element.cloneNode(!0),Y=Q.newBlock.type;if(Y==="mermaid"){if(B5(Q.oldBlock.element,J))q=!0}else if(Q.childMatches&&Q.childMatches.length>0&&(Y==="table"||Y==="checklist")){if(N5(J,Q.childMatches,Y))q=!0}else if(Q.childMatches&&Q.childMatches.length>0){if(T5(Q.oldBlock,J,Q.childMatches,Y))q=!0}else if(Y==="markdown"){if(O5(Q.oldBlock.element,J))q=!0}else if(q0(Q.oldBlock.element,J,!1))q=!0;$.appendChild(J)}return{fragment:$,hasChanges:q}}function W5(Z){let $=Z.cloneNode(!0);return $.classList.add("diff-block-removed"),$.style.position="relative",r2($,"Removed","var(--color-accent-red)"),$}function U6(Z){let $=Z.cloneNode(!0);return $.classList.add("diff-block-added"),$.style.position="relative",r2($,"Added","var(--color-accent-green)"),$}function T5(Z,$,q,Q){let J=!1,Y=K6(Z,$),X,G;if(Q==="section"){let z=Z.element.querySelector(":scope > div:first-child"),_=$.querySelector(":scope > div:first-child");if(z&&_){if(q0(z,_,!1))J=!0}X=Z.element.querySelector(":scope > div.mt-6, :scope > div:last-child"),G=$.querySelector(":scope > div.mt-6, :scope > div:last-child")}else X=Z.element,G=$;if(!X||!G)return J;for(let z of q)if(z.kind==="matched"){let _=Y.newMap.get(z.newBlock.element);if(_){if(z.newBlock.type==="mermaid"){if(B5(z.oldBlock.element,_))J=!0}else if(z.childMatches&&z.childMatches.length>0&&(z.newBlock.type==="table"||z.newBlock.type==="checklist")){if(N5(_,z.childMatches,z.newBlock.type))J=!0}else if(z.childMatches&&z.childMatches.length>0){if(T5(z.oldBlock,_,z.childMatches,z.newBlock.type))J=!0}else if(z.newBlock.type==="markdown"){if(O5(z.oldBlock.element,_))J=!0}else if(q0(z.oldBlock.element,_,!1))J=!0}}else if(z.kind==="removed"){J=!0;let _=W5(z.oldBlock.element),H=W6(q,z,Y.newMap),U=H?T6(G,H):null;G.insertBefore(_,U)}else if(z.kind==="added"){J=!0;let _=Y.newMap.get(z.newBlock.element);if(_)_.classList.add("diff-block-added"),_.style.position="relative",r2(_,"Added","var(--color-accent-green)")}if(q0(X,G,!0))J=!0;return J}function N5(Z,$,q){let Q=q==="table"?Z.querySelector(":scope table > tbody"):Z;if(!Q)return!1;let J=!1;Q.innerHTML="";for(let Y of $)if(Y.kind==="removed"){J=!0;let X=Y.oldBlock.element.cloneNode(!0);X.classList.add(q==="table"?"diff-row-removed":"diff-item-removed"),Q.appendChild(X)}else if(Y.kind==="added"){J=!0;let X=Y.newBlock.element.cloneNode(!0);X.classList.add(q==="table"?"diff-row-added":"diff-item-added"),Q.appendChild(X)}else{let X=Y.newBlock.element.cloneNode(!0);if(q0(Y.oldBlock.element,X,!1))J=!0;Q.appendChild(X)}return J}function K6(Z,$){let q=new Map,Q=Z.element.querySelectorAll("[data-md]"),J=$.querySelectorAll("[data-md]");return{newMap:{get(Y){return H6($,Y)}}}}function H6(Z,$){let q=$.getAttribute("data-md");if(!q)return null;let Q=$.getAttribute("data-md-label"),J=$.getAttribute("data-md-title"),Y=`[data-md="${q}"]`;if(J)Y+=`[data-md-title="${CSS.escape(J)}"]`;else if(Q)Y+=`[data-md-label="${CSS.escape(Q)}"]`;let X=Z.querySelectorAll(Y);if(X.length===1)return X[0];let G=($.textContent||"").slice(0,100),z=null,_=-1;for(let H of X){let U=(H.textContent||"").slice(0,100),W=0;for(let T=0;T<Math.min(G.length,U.length);T++)if(G[T]===U[T])W++;if(W>_)_=W,z=H}return z}function W6(Z,$,q){let Q=Z.indexOf($);for(let J=Q+1;J<Z.length;J++){let Y=Z[J];if((Y.kind==="matched"||Y.kind==="added")&&Y.newBlock)return q.get(Y.newBlock.element)||null}return null}function T6(Z,$){let q=$;while(q&&q.parentElement!==Z)q=q.parentElement;return q}function O5(Z,$){let q=Array.from(Z.children),Q=Array.from($.children);if(q.length===0&&Q.length===0)return q0(Z,$,!1);let J=q.map((W)=>W.tagName.toLowerCase()),Y=Q.map((W)=>W.tagName.toLowerCase()),X=h1(J,Y),G=[],z=0,_=0,H=0;while(z<q.length||_<Q.length)if(H<X.length&&z<q.length&&_<Q.length&&J[z]===X[H]&&Y[_]===X[H])G.push({kind:"matched",oldChild:q[z],newChild:Q[_]}),z++,_++,H++;else if(z<q.length&&(H>=X.length||J[z]!==X[H]))G.push({kind:"removed",oldChild:q[z]}),z++;else if(_<Q.length)G.push({kind:"added",newChild:Q[_]}),_++;let U=!1;while($.firstChild)$.removeChild($.firstChild);for(let W of G)if(W.kind==="matched"){let T=(W.oldChild.textContent||"").match(/\S+/g)||[],K=(W.newChild.textContent||"").match(/\S+/g)||[],L=h1(T,K),N=Math.max(T.length,K.length);if((N>0?1-L.length/N:0)>0.5){U=!0;let O=W.oldChild.cloneNode(!0);O.classList.add("diff-block-removed"),$.appendChild(O),W.newChild.classList.add("diff-block-added"),$.appendChild(W.newChild)}else{if(q0(W.oldChild,W.newChild,!1))U=!0;$.appendChild(W.newChild)}}else if(W.kind==="removed"){U=!0;let T=W.oldChild.cloneNode(!0);T.classList.add("diff-block-removed"),$.appendChild(T)}else U=!0,W.newChild.classList.add("diff-block-added"),$.appendChild(W.newChild);return U}function H5(Z,$){let q=$?new Set(Array.from(Z.querySelectorAll("[data-md]"))):new Set,Q=[],J=[],Y=document.createTreeWalker(Z,NodeFilter.SHOW_TEXT,{acceptNode(G){let z=G.parentElement;if(!z)return NodeFilter.FILTER_REJECT;if(z.closest("svg, .select-none, [data-no-diff]"))return NodeFilter.FILTER_REJECT;if($){for(let _ of q)if(_.contains(G))return NodeFilter.FILTER_REJECT}return NodeFilter.FILTER_ACCEPT}}),X;while(X=Y.nextNode()){let z=(X.nodeValue||"").match(/\S+|\s+/g);if(!z)continue;let _=0;for(let H of z)Q.push(H),J.push({text:H,node:X,offset:_}),_+=H.length}return{words:Q,map:J}}function q0(Z,$,q){let Q=H5(Z,q),J=H5($,q);if(Q.words.length===0&&J.words.length===0)return!1;let{oldOps:Y,newOps:X}=l2(Q.words,J.words),G=Y.some((N)=>N.type==="removed"),z=X.some((N)=>N.type==="added");if(!G&&!z)return!1;let _=[],H=[];for(let N of Y)if(N.type==="same")_.push(N.index);for(let N of X)if(N.type==="same")H.push(N.index);let U=new Map;for(let N=0;N<_.length&&N<H.length;N++)U.set(_[N],H[N]);let W=[];{let N=[],S=-1;for(let O of Y)if(O.type==="same"){if(N.length>0)W.push({text:N.join(""),anchorNewIdx:S>=0?U.get(S)??null:null}),N=[];S=O.index}else if(O.type==="removed")N.push(Q.words[O.index]);if(N.length>0)W.push({text:N.join(""),anchorNewIdx:S>=0?U.get(S)??null:null})}let T=new Map,K=new Map;for(let N of X){if(N.type!=="added")continue;let S=J.map[N.index];if(!S?.node.parentNode)continue;let O=T.get(S.node);if(!O)O=[],T.set(S.node,O);O.push({start:S.offset,end:S.offset+S.text.length})}for(let N of W)if(N.anchorNewIdx===null){if(J.map.length>0){let S=J.map[0].node,O=K.get(S);if(!O)O=[],K.set(S,O);O.push({offset:0,text:N.text})}}else{let S=J.map[N.anchorNewIdx];if(!S)continue;let O=K.get(S.node);if(!O)O=[],K.set(S.node,O);O.push({offset:S.offset+S.text.length,text:N.text})}let L=new Set([...T.keys(),...K.keys()]);for(let N of L)N6(N,T.get(N)||[],K.get(N)||[]);return!0}function N6(Z,$,q){if(!Z.parentNode)return;let Q=Z.nodeValue||"";$.sort((H,U)=>H.start-U.start);let J=[];for(let H of $){let U=J[J.length-1];if(U&&H.start<=U.end)U.end=Math.max(U.end,H.end);else J.push({...H})}q.sort((H,U)=>H.offset-U.offset);let Y=Z.parentNode,X=document.createDocumentFragment(),G=0,z=0,_=0;while(G<=Q.length){let H=z<J.length?J[z].start:1/0,U=_<q.length?q[_].offset:1/0,W=Math.min(H,U);if(W===1/0){if(G<Q.length)X.appendChild(document.createTextNode(Q.slice(G)));break}let T=Math.max(W,G);if(T>G)X.appendChild(document.createTextNode(Q.slice(G,T))),G=T;while(_<q.length&&q[_].offset<=G){let K=document.createElement("span");K.className="diff-removed",K.textContent=q[_].text,X.appendChild(K),_++}if(z<J.length&&J[z].start<=G){let K=J[z],L=document.createElement("span");L.className="diff-added",L.textContent=Q.slice(G,K.end),X.appendChild(L),G=K.end,z++;while(_<q.length&&q[_].offset<=G){let N=document.createElement("span");N.className="diff-removed",N.textContent=q[_].text,X.appendChild(N),_++}}}while(_<q.length){let H=document.createElement("span");H.className="diff-removed",H.textContent=q[_].text,X.appendChild(H),_++}Y.replaceChild(X,Z)}function B5(Z,$){let q=(Z.getAttribute("data-md-source")||"").trim(),Q=($.getAttribute("data-md-source")||"").trim();if(q===Q)return!1;let J=q.split(`
|
|
86
86
|
`),Y=Q.split(`
|
|
87
|
-
`),X=g1(J,Y),G=[],z=0,_=0,H=0;while(z<J.length||_<Y.length)if(H<X.length&&z<J.length&&_<Y.length&&J[z]===X[H]&&Y[_]===X[H])G.push({type:"same",line:J[z]}),z++,_++,H++;else if(z<J.length&&(H>=X.length||J[z]!==X[H]))G.push({type:"removed",line:J[z]}),z++;else if(_<Y.length)G.push({type:"added",line:Y[_]}),_++;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 T of G){let W=document.createElement("div");if(W.className="px-3 py-0.5 whitespace-pre-wrap",T.type==="removed")W.classList.add("diff-removed"),W.textContent="- "+T.line;else if(T.type==="added")W.classList.add("diff-added"),W.textContent="+ "+T.line;else W.textContent=" "+T.line;U.appendChild(W)}return $.appendChild(U),!0}function v2(Z,$,q){let Q=document.createElement("span");Q.className="diff-block-label",Q.textContent=$,Q.style.color=q,Q.style.backgroundColor=`color-mix(in srgb, ${q} 12%, transparent)`,Z.appendChild(Q)}import{jsxDEV as p}from"react/jsx-dev-runtime";function U6(Z,$,q){let Q=Z.find((X)=>X.revision===$),J=Z.find((X)=>X.revision===q),Y=new Set;for(let X of Q?.canvasFiles||[])Y.add(X.filename);for(let X of J?.canvasFiles||[])Y.add(X.filename);return[...Y].sort()}function H5({initialLeft:Z,initialRight:$,sessionId:q,onExit:Q}){let[J,Y]=G1(Z),[X,G]=G1($),[z,_]=G1("unified"),[H,U]=G1(!0),[T,W]=G1(!1),{revisions:K}=G6(w1),F=X2(()=>U6(K,J,X),[K,J,X]),[N,y]=G1(()=>F[0]||"plan.jsx");f1(()=>{if(!F.includes(N))y(F[0]||"plan.jsx")},[F,N]);let O=X2(()=>{return K.find((M)=>M.revision===J)?.canvasFiles.some((M)=>M.filename===N)??!1},[K,J,N]),D=X2(()=>{return K.find((M)=>M.revision===X)?.canvasFiles.some((M)=>M.filename===N)??!1},[K,X,N]);return p("div",{className:"flex flex-col h-screen",children:[p("div",{className:"flex items-center justify-between px-6 py-3 border-b border-border-subtle bg-bg-surface flex-shrink-0",children:[p("div",{className:"flex items-center gap-3",children:[p("span",{className:"text-[13px] font-body font-medium text-text-primary",children:"Compare"},void 0,!1,void 0,this),p(A0,{value:J,onChange:Y,accent:"red"},void 0,!1,void 0,this),p("span",{className:"text-text-tertiary text-[13px]",children:"→"},void 0,!1,void 0,this),p(A0,{value:X,onChange:G,accent:"green"},void 0,!1,void 0,this),T&&!H&&p("span",{className:"text-[11px] font-body text-text-tertiary bg-bg-elevated px-2 py-0.5 rounded",children:"No changes"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),p("div",{className:"flex items-center gap-4",children:[p("div",{className:"flex items-center bg-bg-elevated rounded-md p-0.5",children:[p("button",{onClick:()=>_("unified"),className:`text-[11px] font-body px-2.5 py-1 rounded transition-colors ${z==="unified"?"bg-bg-surface text-text-primary font-medium shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Unified"},void 0,!1,void 0,this),p("button",{onClick:()=>_("side-by-side"),className:`text-[11px] font-body px-2.5 py-1 rounded transition-colors ${z==="side-by-side"?"bg-bg-surface text-text-primary font-medium shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Side-by-side"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z==="side-by-side"&&p(K6,{},void 0,!1,void 0,this),p("button",{onClick:Q,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&&p("div",{className:"flex items-center gap-1 px-6 py-2 border-b border-border-subtle bg-bg-surface flex-shrink-0 overflow-x-auto",children:F.map((S)=>{let M=S.replace(/\.jsx$/,""),b=S===N,C=K.find((v)=>v.revision===J)?.canvasFiles.some((v)=>v.filename===S),k=K.find((v)=>v.revision===X)?.canvasFiles.some((v)=>v.filename===S),c=!C?" (added)":!k?" (removed)":"";return p("button",{onClick:()=>y(S),className:`text-[12px] font-body px-3 py-1 rounded-md transition-colors whitespace-nowrap ${b?"bg-bg-elevated text-text-primary font-medium":"text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated"}`,children:[M,c&&p("span",{className:`ml-1 text-[10px] ${!C?"text-accent-green":"text-accent-red"}`,children:c},void 0,!1,void 0,this)]},S,!0,void 0,this)})},void 0,!1,void 0,this),!O||!D?p("div",{className:"flex-1 flex items-center justify-center",children:p("div",{className:"text-center text-text-tertiary font-body",children:[p("div",{className:"text-lg mb-2",children:!O?"New file":"Removed file"},void 0,!1,void 0,this),p("div",{className:"text-[13px]",children:[N.replace(/\.jsx$/,"")," ",!O?"was added":"was removed"," in this revision"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this):z==="unified"?p(H6,{sessionId:q,leftRev:J,rightRev:X,filename:N,onDiffResult:(S,M)=>{W(S),U(M)}},`unified-${J}-${X}-${N}`,!1,void 0,this):p(W6,{sessionId:q,leftRev:J,rightRev:X,filename:N,onDiffResult:(S,M)=>{W(S),U(M)}},`sbs-${J}-${X}-${N}`,!1,void 0,this)]},void 0,!0,void 0,this)}function K6(){let[Z,$]=G1(!0);return f1(()=>{return document.documentElement.dataset.syncScroll=Z?"1":"0",()=>{delete document.documentElement.dataset.syncScroll}},[Z]),p("label",{className:"flex items-center gap-1.5 cursor-pointer select-none",children:[p("input",{type:"checkbox",checked:Z,onChange:(q)=>$(q.target.checked),className:"accent-accent-amber w-3.5 h-3.5"},void 0,!1,void 0,this),p("span",{className:"text-[11px] font-body text-text-secondary",children:"Sync scroll"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function H6({sessionId:Z,leftRev:$,rightRev:q,filename:Q,onDiffResult:J}){let Y=R1(null),X=R1(null),G=R1(null),[z,_]=G1(!1),[H,U]=G1(!1),[T,W]=G1(!1),[K,F]=G1(null),[N,y]=G1(!1),{annotations:O}=Y1(),D=O.filter((M)=>!M.filePath&&(!M.canvasFile||M.canvasFile===Q)),{popovers:S}=t1({containerRef:G,restoreKey:T,restoreAnnotations:D,extractContext:(M)=>i1(M,G.current)});return f1(()=>{if(T||K)return;let M=setTimeout(()=>{console.warn("[unified-diff] still loading after 10s",{leftReady:z,rightReady:H,oldRef:!!Y.current,newRef:!!X.current}),y(!0)},1e4);return()=>clearTimeout(M)},[T,K,z,H]),f1(()=>{if(!z||!H||T)return;if(!Y.current||!X.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!Y.current||!X.current||!G.current){console.warn("[unified-diff] refs lost between rAF frames",{old:!!Y.current,new:!!X.current,unified:!!G.current});return}try{let M=K0(Y.current),b=K0(X.current),C=V0(M,b),{fragment:k,hasChanges:c}=Y2(C);G.current.innerHTML="",G.current.appendChild(k),W(!0),J(!0,c)}catch(M){console.error("[unified-diff] diff computation failed",M),F(M instanceof Error?M.message:String(M))}})})},[z,H,T]),p("div",{className:"flex-1 min-h-0 overflow-y-auto",children:[!T&&!K&&p("div",{style:{position:"absolute",left:-9999,visibility:"hidden",pointerEvents:"none",width:720},children:[p(D1,{ref:Y,sessionId:Z,revision:$,filename:Q,onReady:()=>_(!0),onError:(M)=>F(`Rev ${$}: ${M}`)},void 0,!1,void 0,this),p(D1,{ref:X,sessionId:Z,revision:q,filename:Q,onReady:()=>U(!0),onError:(M)=>F(`Rev ${q}: ${M}`)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),p("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:[!T&&!K&&p("div",{className:"flex flex-col items-center justify-center h-64 text-text-tertiary font-body text-body gap-2",children:[p("span",{children:"Loading..."},void 0,!1,void 0,this),N&&p("span",{className:"text-[11px]",children:"Taking longer than expected — check Network tab for pending requests"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),K&&p("div",{className:"bg-accent-red-muted rounded-lg p-5 mt-8",children:[p("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Failed to load revision"},void 0,!1,void 0,this),p("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:K},void 0,!1,void 0,this)]},void 0,!0,void 0,this),p("div",{ref:G},void 0,!1,void 0,this)]},void 0,!0,void 0,this),S]},void 0,!0,void 0,this)}function W6({sessionId:Z,leftRev:$,rightRev:q,filename:Q,onDiffResult:J}){let Y=R1(null),X=R1(null),[G,z]=G1(!1),[_,H]=G1(!1),[U,T]=G1(!1),W=R1(null),K=R1(null),F=R1(null),N=R1(!1),y=K5(()=>z(!0),[]),O=K5(()=>H(!0),[]),{annotations:D}=Y1(),S=D.filter((b)=>!b.filePath&&(!b.canvasFile||b.canvasFile===Q)),{popovers:M}=t1({containerRef:W,restoreKey:U,restoreAnnotations:S,extractContext:(b)=>i1(b,W.current)});return f1(()=>{if(!G||!_||U)return;if(!Y.current||!X.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!Y.current||!X.current)return;let b=Q2(Y.current,X.current);T(!0),J(!0,b)})})},[G,_,U]),f1(()=>{let b=K.current,C=F.current;if(!b||!C)return;let k=(V,E)=>{if(document.documentElement.dataset.syncScroll==="0")return;if(N.current)return;N.current=!0;let g=V.scrollHeight-V.clientHeight,l=E.scrollHeight-E.clientHeight;if(g>0&&l>0)E.scrollTop=V.scrollTop/g*l;requestAnimationFrame(()=>{N.current=!1})},c=()=>k(b,C),v=()=>k(C,b);return b.addEventListener("scroll",c),C.addEventListener("scroll",v),()=>{b.removeEventListener("scroll",c),C.removeEventListener("scroll",v)}},[]),p("div",{ref:W,className:"flex flex-1 min-h-0",children:[p("div",{ref:K,className:"w-1/2 overflow-y-auto border-r border-border-subtle",children:p("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:p(D1,{ref:Y,sessionId:Z,revision:$,filename:Q,onReady:y},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),p("div",{ref:F,className:"w-1/2 overflow-y-auto",children:p("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:p(D1,{ref:X,sessionId:Z,revision:q,filename:Q,onReady:O},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),M]},void 0,!0,void 0,this)}var D1=U5.memo(U5.forwardRef(({sessionId:Z,revision:$,filename:q,onReady:Q,onError:J},Y)=>{let[X,G]=G1(null),[z,_]=G1(null),[H,U]=G1(!0);f1(()=>{U(!0),_(null);let W=q.replace(/\.jsx$/,".js");import(`/api/session/${Z}/canvas/${encodeURIComponent(W)}?rev=${$}&t=${Date.now()}`).then((K)=>{if(!K.default){_("Module has no default export"),U(!1),J?.("Module has no default export");return}G(()=>K.default),U(!1)}).catch((K)=>{_(K.message),U(!1),J?.(K.message)})},[Z,$,q]),f1(()=>{if(!X)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{Q()})})},[X]);let T=X2(()=>X?p(X,{},void 0,!1,void 0,this):null,[X]);if(H)return p("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-body",children:"Loading..."},void 0,!1,void 0,this);if(z)return p("div",{className:"bg-accent-red-muted rounded-lg p-5",children:[p("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Error"},void 0,!1,void 0,this),p("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:z},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(!X)return p("div",{className:"text-text-tertiary text-center py-8 font-body text-body",children:"No canvas loaded"},void 0,!1,void 0,this);return p("div",{ref:Y,children:T},void 0,!1,void 0,this)}));import{useState as k1,useContext as h2,useMemo as T6,useRef as I0,useEffect as T5,useCallback as W5}from"react";import{SessionContext as N6}from"#canvas/runtime";import{jsxDEV as r}from"react/jsx-dev-runtime";function p2(Z,$){if(!Z)return[];return Z.canvasFiles.map((q)=>{if(!q.diffStats)return{filename:q.filename,status:"new"};if(q.diffStats.added===0&&q.diffStats.removed===0)return{filename:q.filename,status:"unchanged",diffStats:q.diffStats};return{filename:q.filename,status:"changed",diffStats:q.diffStats}})}function N5(Z){return Z.filter(($)=>$.status!=="unchanged").map(($)=>$.filename)}function O5({revision:Z,responseBanner:$}){let{setActiveView:q}=h2(I1),{revisions:Q}=h2(w1),J=Q.find((_)=>_.revision===Z),Y=Q.find((_)=>_.revision===Z-1),X=T6(()=>p2(J,Y),[J,Y]),G=X.filter((_)=>_.status!=="unchanged"),z=X.filter((_)=>_.status==="unchanged");return r("div",{className:"max-w-[720px] mx-auto px-6 pt-12 pb-32",children:[$,G.map((_)=>r(B6,{change:_,revision:Z,previousRevision:Y?.revision,onOpenTab:()=>q({type:"canvas",filename:_.filename})},_.filename,!1,void 0,this)),z.length>0&&r("div",{className:"mt-8 border-t border-border-subtle pt-4",children:[r("div",{className:"text-[11px] font-body font-medium uppercase tracking-widest text-text-tertiary mb-3",children:"Unchanged"},void 0,!1,void 0,this),z.map((_)=>r(P6,{change:_,revision:Z,onOpenTab:()=>q({type:"canvas",filename:_.filename})},_.filename,!1,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function O6({mode:Z,onChange:$,showDiff:q}){if(!q)return null;return r("div",{className:"flex items-center bg-bg-elevated rounded-md p-0.5",children:["rendered","unified","side-by-side"].map((Q)=>r("button",{onClick:()=>$(Q),className:`text-[10px] font-body px-2 py-0.5 rounded transition-colors ${Z===Q?"bg-bg-surface text-text-primary font-medium shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:Q==="rendered"?"Full":Q==="unified"?"Unified":"Split"},Q,!1,void 0,this))},void 0,!1,void 0,this)}function B6({change:Z,revision:$,previousRevision:q,onOpenTab:Q}){let J=Z.filename.replace(/\.jsx$/,""),Y=Z.status==="new",X=Z.diffStats,G=Z.status==="changed"&&q!=null,[z,_]=k1("rendered");return r("div",{className:"mb-8",children:[r("div",{className:"flex items-center gap-2 mb-3 pb-2 border-b border-border-subtle",children:[r("span",{className:`text-[11px] font-mono px-1.5 py-0.5 rounded ${Y?"bg-accent-green/10 text-accent-green border border-accent-green/20":"bg-accent-amber/10 text-accent-amber border border-accent-amber/20"}`,children:Y?"new":"modified"},void 0,!1,void 0,this),r("span",{className:"text-[14px] font-body font-medium text-text-primary",children:J},void 0,!1,void 0,this),X&&(X.added>0||X.removed>0)&&r("span",{className:"text-[11px] font-mono text-text-tertiary",children:[r("span",{className:"text-accent-green",children:["+",X.added]},void 0,!0,void 0,this)," ",r("span",{className:"text-accent-red",children:["-",X.removed]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),r(O6,{mode:z,onChange:_,showDiff:G},void 0,!1,void 0,this),r("button",{onClick:Q,className:`${G?"":"ml-auto"} text-[11px] font-body font-medium text-accent-blue hover:text-accent-blue/80 transition-colors`,children:"Open in tab"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z==="rendered"?r("div",{"data-canvas-file":Z.filename,children:r(S0,{revision:$,filename:Z.filename},void 0,!1,void 0,this)},void 0,!1,void 0,this):G&&q!=null?r(F6,{filename:Z.filename,leftRev:q,rightRev:$,mode:z},`${z}-${$}-${q}`,!1,void 0,this):null]},void 0,!0,void 0,this)}function F6({filename:Z,leftRev:$,rightRev:q,mode:Q}){let J=h2(N6);if(Q==="unified")return r(L6,{sessionId:J,filename:Z,leftRev:$,rightRev:q},void 0,!1,void 0,this);return r(M6,{sessionId:J,filename:Z,leftRev:$,rightRev:q},void 0,!1,void 0,this)}function L6({sessionId:Z,filename:$,leftRev:q,rightRev:Q}){let J=I0(null),Y=I0(null),X=I0(null),[G,z]=k1(!1),[_,H]=k1(!1),[U,T]=k1(!1),[W,K]=k1(null);return T5(()=>{if(!G||!_||U)return;if(!J.current||!Y.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!J.current||!Y.current||!X.current)return;try{let F=K0(J.current),N=K0(Y.current),y=V0(F,N),{fragment:O}=Y2(y);X.current.innerHTML="",X.current.appendChild(O),T(!0)}catch(F){K(F instanceof Error?F.message:String(F))}})})},[G,_,U]),r("div",{children:[!U&&!W&&r("div",{style:{position:"absolute",left:-9999,visibility:"hidden",pointerEvents:"none",width:720},children:[r(D1,{ref:J,sessionId:Z,revision:q,filename:$,onReady:()=>z(!0),onError:(F)=>K(F)},void 0,!1,void 0,this),r(D1,{ref:Y,sessionId:Z,revision:Q,filename:$,onReady:()=>H(!0),onError:(F)=>K(F)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!U&&!W&&r("div",{className:"flex items-center justify-center h-24 text-text-tertiary font-body text-[13px]",children:"Computing diff..."},void 0,!1,void 0,this),W&&r("div",{className:"text-accent-red text-[13px] font-body p-3 bg-accent-red-muted rounded-lg",children:W},void 0,!1,void 0,this),r("div",{ref:X},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function M6({sessionId:Z,filename:$,leftRev:q,rightRev:Q}){let J=I0(null),Y=I0(null),[X,G]=k1(!1),[z,_]=k1(!1),[H,U]=k1(!1),T=W5(()=>G(!0),[]),W=W5(()=>_(!0),[]);return T5(()=>{if(!X||!z||H)return;if(!J.current||!Y.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!J.current||!Y.current)return;Q2(J.current,Y.current),U(!0)})})},[X,z,H]),r("div",{className:"flex gap-0 border-y border-border-subtle overflow-hidden w-screen relative left-1/2 -translate-x-1/2",children:[r("div",{className:"w-1/2 border-r border-border-subtle",children:[r("div",{className:"px-2 py-1 text-[10px] font-body font-medium text-text-tertiary bg-bg-elevated border-b border-border-subtle",children:["Rev ",q]},void 0,!0,void 0,this),r("div",{className:"px-6 py-4 max-w-[600px] mx-auto",children:r(D1,{ref:J,sessionId:Z,revision:q,filename:$,onReady:T},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("div",{className:"w-1/2",children:[r("div",{className:"px-2 py-1 text-[10px] font-body font-medium text-text-tertiary bg-bg-elevated border-b border-border-subtle",children:["Rev ",Q]},void 0,!0,void 0,this),r("div",{className:"px-6 py-4 max-w-[600px] mx-auto",children:r(D1,{ref:Y,sessionId:Z,revision:Q,filename:$,onReady:W},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function P6({change:Z,revision:$,onOpenTab:q}){let[Q,J]=k1(!1),Y=Z.filename.replace(/\.jsx$/,"");return r("div",{className:"mb-2",children:[r("div",{className:"flex items-center gap-2 py-1.5",children:[r("button",{onClick:()=>J(!Q),className:"text-text-tertiary hover:text-text-secondary transition-colors",children:r("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",className:`transition-transform duration-150 ${Q?"rotate-90":""}`,children:r("path",{d:"M3.5 2L6.5 5L3.5 8",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),r("span",{className:"text-[13px] font-body text-text-secondary",children:Y},void 0,!1,void 0,this),r("button",{onClick:q,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),Q&&r("div",{className:"ml-5 mt-1 mb-3","data-canvas-file":Z.filename,children:r(S0,{revision:$,filename:Z.filename},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{useState as z2,useEffect as y6,useCallback as c2}from"react";import{jsxDEV as o}from"react/jsx-dev-runtime";function B5({sessionId:Z,revision:$,open:q,shareEnabled:Q,existingShares:J,onClose:Y,onShareCreated:X,onShareRevoked:G}){let[z,_]=z2(!1),[H,U]=z2(!1),[T,W]=z2(null),[K,F]=z2(!1),N=J.find((S)=>S.revision===$);y6(()=>{if(!q)_(!1),U(!1),W(null),F(!1)},[q]);let y=c2(async()=>{_(!0),W(null);try{let S=await fetch(`/api/session/${Z}/revision/${$}/share`,{method:"POST"}),M=await S.json();if(!S.ok||!M.ok)throw Error(M.error||`HTTP ${S.status}`);X(M.share)}catch(S){W(S.message||String(S))}finally{_(!1)}},[Z,$,X]),O=c2(async(S)=>{if(!window.confirm("Revoke this share link? Reviewers will no longer be able to view or comment."))return;U(!0),W(null);try{let M=await fetch(`/api/session/${Z}/shares/${S}/revoke`,{method:"POST"}),b=await M.json();if(!M.ok||!b.ok)throw Error(b.error||`HTTP ${M.status}`);G(S)}catch(M){W(M.message||String(M))}finally{U(!1)}},[Z,G]),D=c2((S)=>{navigator.clipboard.writeText(S).then(()=>{F(!0),setTimeout(()=>F(!1),1500)})},[]);if(!q)return null;return o("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:Y,children:o("div",{className:"bg-bg-surface border border-border-medium rounded-lg shadow-xl w-full max-w-md mx-4 p-5",onClick:(S)=>S.stopPropagation(),children:[o("div",{className:"flex items-center justify-between mb-3",children:[o("h2",{className:"text-sm font-medium text-text-primary font-body",children:"Share this revision"},void 0,!1,void 0,this),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",children:o("span",{className:"text-xs",children:"✕"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!Q?o("div",{className:"text-[13px] text-text-secondary font-body space-y-2",children:[o("p",{children:"Canvas sharing is not configured."},void 0,!1,void 0,this),o("p",{className:"text-text-tertiary",children:["Set ",o("code",{className:"px-1 py-0.5 rounded bg-bg-elevated text-text-primary text-[11px]",children:"CANVAS_SHARE_ENDPOINT"},void 0,!1,void 0,this)," to the URL of a deployed"," ",o("code",{className:"px-1 py-0.5 rounded bg-bg-elevated text-text-primary text-[11px]",children:"canvas-share"},void 0,!1,void 0,this)," worker and restart the daemon."]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):N?o("div",{className:"space-y-3",children:[o("p",{className:"text-[13px] text-text-secondary font-body",children:"This revision is shared:"},void 0,!1,void 0,this),o("div",{className:"flex gap-2",children:[o("input",{type:"text",readOnly:!0,value:N.url,className:"flex-1 px-2 py-1.5 text-[12px] font-mono bg-bg-input border border-border-medium rounded text-text-primary",onFocus:(S)=>S.currentTarget.select()},void 0,!1,void 0,this),o("button",{onClick:()=>D(N.url),className:"px-3 py-1.5 text-[12px] font-body font-medium rounded bg-accent-blue text-white hover:opacity-90 transition-opacity whitespace-nowrap",children:K?"Copied!":"Copy"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),N.expiresAt&&o("p",{className:"text-[11px] text-text-tertiary font-body",children:["Expires ",new Date(N.expiresAt).toLocaleDateString(),"."]},void 0,!0,void 0,this),N.encryptionKey&&o("p",{className:"text-[11px] text-accent-green font-body flex items-center gap-1.5",children:[o("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[o("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"},void 0,!1,void 0,this),o("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),"End-to-end encrypted — the key is part of the link and never leaves your browser."]},void 0,!0,void 0,this),o("p",{className:"text-[11px] text-text-tertiary font-body",children:"Anyone with this link can view and leave feedback. Reviewer feedback will appear in your annotation sidebar within seconds."},void 0,!1,void 0,this),o("div",{className:"flex items-center justify-between pt-1",children:[o("button",{onClick:y,disabled:z||H,className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body underline disabled:opacity-50",children:z?"Creating...":"Create a new link"},void 0,!1,void 0,this),N.ownerToken&&o("button",{onClick:()=>O(N.shareId),disabled:z||H,className:"text-[11px] text-accent-red hover:opacity-80 font-body underline disabled:opacity-50",children:H?"Revoking...":"Revoke link"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):o("div",{className:"space-y-3",children:[o("p",{className:"text-[13px] text-text-secondary font-body",children:"Create a public link to this revision. Anyone with the link can view the canvas and leave feedback. Reviewer feedback will sync back here automatically."},void 0,!1,void 0,this),o("button",{onClick:y,disabled:z,className:"w-full px-3 py-2 text-[13px] font-body font-medium rounded bg-accent-blue text-white hover:opacity-90 transition-opacity disabled:opacity-50",children:z?"Creating share link...":"Create share link"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),T&&o("div",{className:"mt-3 px-3 py-2 rounded bg-accent-red/10 border border-accent-red/20 text-[12px] text-accent-red font-body",children:T},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function F5({onClick:Z,title:$="Share this revision",hasShare:q}){return o("button",{onClick:Z,className:`group p-1.5 transition-colors ${q?"text-accent-blue hover:opacity-80":"text-text-tertiary hover:text-text-secondary"}`,title:$,children: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:"18",cy:"5",r:"3"},void 0,!1,void 0,this),o("circle",{cx:"6",cy:"12",r:"3"},void 0,!1,void 0,this),o("circle",{cx:"18",cy:"19",r:"3"},void 0,!1,void 0,this),o("line",{x1:"8.59",y1:"13.51",x2:"15.42",y2:"17.49"},void 0,!1,void 0,this),o("line",{x1:"15.41",y1:"6.51",x2:"8.59",y2:"10.49"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}import{useState as S6,useEffect as b6,useRef as j6}from"react";import{jsxDEV as M1}from"react/jsx-dev-runtime";function L5({open:Z,onClose:$,onSubmit:q}){let[Q,J]=S6(""),Y=j6(null);if(b6(()=>{if(Z)J(""),setTimeout(()=>Y.current?.focus(),50)},[Z]),!Z)return null;let X=Q.trim(),G=X.length>=1&&X.length<=80,z=()=>{if(!G)return;q(X)};return M1("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:$,children:M1("div",{className:"bg-bg-surface border border-border-medium rounded-lg shadow-xl w-full max-w-md mx-4 p-5",onClick:(_)=>_.stopPropagation(),children:[M1("div",{className:"flex items-center justify-between mb-3",children:[M1("h2",{className:"text-sm font-medium text-text-primary font-body",children:"Your name"},void 0,!1,void 0,this),M1("button",{onClick:$,className:"w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",children:M1("span",{className:"text-xs",children:"✕"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),M1("p",{className:"text-[13px] text-text-secondary font-body mb-3 leading-relaxed",children:"Before you leave feedback, please enter a name so the canvas author knows who reviewed it. This is stored locally in your browser."},void 0,!1,void 0,this),M1("input",{ref:Y,type:"text",value:Q,onChange:(_)=>J(_.target.value),onKeyDown:(_)=>{if(_.key==="Enter")z()},maxLength:80,placeholder:"e.g. Alice",className:"w-full px-3 py-2 text-[13px] font-body bg-bg-input border border-border-medium rounded text-text-primary placeholder:text-text-disabled focus:outline-none focus:border-accent-blue"},void 0,!1,void 0,this),M1("div",{className:"flex justify-end gap-2 mt-4",children:[M1("button",{onClick:$,className:"px-3 py-1.5 text-[12px] font-body font-medium rounded text-text-secondary hover:text-text-primary hover:bg-bg-elevated transition-colors",children:"Cancel"},void 0,!1,void 0,this),M1("button",{onClick:z,disabled:!G,className:"px-3 py-1.5 text-[12px] font-body font-medium rounded bg-accent-blue text-white hover:opacity-90 transition-opacity disabled:opacity-50",children:"Submit feedback"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}import{jsxDEV as B,Fragment as D0}from"react/jsx-dev-runtime";function P5(Z){let $=[];for(let q of Z)for(let Q of q.annotations)$.push({...Q,source:"remote",author:q.author});return $}var I1=j5({activeView:{type:"overview"},setActiveView:()=>{},openFiles:[],closeFile:()=>{},canvasFiles:[]}),w1=j5({currentRevision:1,selectedRevision:1,revisions:[],setSelectedRevision:()=>{},isReadOnly:!1,compareRevision:null,setCompareRevision:()=>{},agentWatching:!1});function V6(Z){if(Z==="auto")return window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light";return Z}function y5(Z){document.documentElement.dataset.theme=V6(Z)}function A5(){let[Z,$]=q1(()=>{let J=localStorage.getItem("canvas-theme");if(J==="light"||J==="dark"||J==="auto")return J;return"auto"});return P1(()=>{if(y5(Z),Z!=="auto")return;let J=window.matchMedia("(prefers-color-scheme: dark)"),Y=()=>y5("auto");return J.addEventListener("change",Y),()=>J.removeEventListener("change",Y)},[Z]),B("button",{onClick:()=>{let J=Z==="auto"?"light":Z==="light"?"dark":"auto";localStorage.setItem("canvas-theme",J),$(J)},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)"}[Z],children:Z==="auto"?B("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[B("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2",ry:"2"},void 0,!1,void 0,this),B("line",{x1:"8",y1:"21",x2:"16",y2:"21"},void 0,!1,void 0,this),B("line",{x1:"12",y1:"17",x2:"12",y2:"21"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):Z==="dark"?B("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:B("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):B("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[B("circle",{cx:"12",cy:"12",r:"5"},void 0,!1,void 0,this),B("line",{x1:"12",y1:"1",x2:"12",y2:"3"},void 0,!1,void 0,this),B("line",{x1:"12",y1:"21",x2:"12",y2:"23"},void 0,!1,void 0,this),B("line",{x1:"4.22",y1:"4.22",x2:"5.64",y2:"5.64"},void 0,!1,void 0,this),B("line",{x1:"18.36",y1:"18.36",x2:"19.78",y2:"19.78"},void 0,!1,void 0,this),B("line",{x1:"1",y1:"12",x2:"3",y2:"12"},void 0,!1,void 0,this),B("line",{x1:"21",y1:"12",x2:"23",y2:"12"},void 0,!1,void 0,this),B("line",{x1:"4.22",y1:"19.78",x2:"5.64",y2:"18.36"},void 0,!1,void 0,this),B("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 C5(){let{currentRevision:Z,selectedRevision:$,revisions:q,setSelectedRevision:Q,setCompareRevision:J}=v1.useContext(w1);if(q.length<=1){let G=q[0]?.label||`Round ${Z}`;return B("span",{className:"text-[11px] text-text-tertiary font-body",children:G},void 0,!1,void 0,this)}return B("div",{className:"flex flex-col gap-1",children:[B(A0,{value:$,onChange:Q,accent:$===Z?"default":"amber"},void 0,!1,void 0,this),B("button",{onClick:()=>{let X;if($===Z)X=[...q].reverse().find((z)=>z.revision<Z)?.revision??Math.max(1,Z-1);else X=$;J({left:X,right:Z})},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 I6(){let Z=$1.isShared?$1.shareId:$1.sessionId,$=$1.isShared,[q,Q]=q1(1),[J,Y]=q1(1),[X,G]=q1([]),[z,_]=q1(null),[H,U]=q1(!1),[T,W]=q1(!1),[K,F]=q1(!1),[N,y]=q1([]),[O,D]=q1({type:"overview"}),[S,M]=q1([]),b=h1(null),[C,k]=q1(),[c,v]=q1(!1),[V,E]=q1(!1),[g,l]=q1(!1),[j,u]=q1(!1),[h,A]=q1([]),[I,L]=q1(!1),[d,m]=q1(new Map),[x,s]=q1(!1),[w,f]=q1(null),[Z1,U1]=q1(null);P1(()=>{if(!Z1)return;let R=setTimeout(()=>U1(null),4000);return()=>clearTimeout(R)},[Z1]),P1(()=>{let R=["Agent Canvas"];if(C){let a=C.replace(/\/+$/,"").split("/");R.push(a[a.length-1]||Z)}else if(Z)R.push(Z);if(O.type==="file")R.push(O.path.split("/").pop()||O.path);else if(O.type==="overview")R.push("Overview");else if(O.type==="canvas"&&N.length>1&&O.filename)R.push(O.filename.replace(/\.jsx$/,""));else if(z)R.push("Compare");document.title=R.join(" — ")},[Z,C,O,z]);let p1=h1(new Map),C1=X.find((R)=>R.revision===J),q0=J!==q||!!C1?.hasFeedback||T,d2=R0((R)=>{let a=O.type==="overview"?"overview":O.type==="canvas"?`canvas:${O.filename}`:`file:${O.path}`;if(p1.current.set(a,window.scrollY),D(R),R.type==="file")M((n)=>n.includes(R.path)?n:[...n,R.path])},[O]),V5=R0((R)=>{p1.current.delete(`file:${R}`),M((a)=>a.filter((n)=>n!==R)),D((a)=>{if(a.type==="file"&&a.path===R)return N.length>1?{type:"overview"}:{type:"canvas",filename:N[0]||""};return a})},[N]);w6(()=>{let R=O.type==="overview"?"overview":O.type==="canvas"?`canvas:${O.filename}`:`file:${O.path}`;window.scrollTo(0,p1.current.get(R)||0)},[O]),P1(()=>{if(!Z)return;M3().then((R)=>{if(R.currentRevision){let a=R.revisions||[];for(let n of a)if(n.hasFeedback)Y0(localStorage,Z,n.revision);P2(localStorage,Z,R.currentRevision,a),Q(R.currentRevision),Y(R.currentRevision),G(a)}if(R.canvasFiles){let a=R.canvasFiles.sort();y(a),D((n)=>{if(n.type==="overview")return a.length>1?n:{type:"canvas",filename:a[0]||""};if(n.type==="canvas"&&(!n.filename||!a.includes(n.filename)))return{type:"canvas",filename:a[0]||""};return n})}if(R.projectRoot)k(R.projectRoot);if(Array.isArray(R.shares))A(R.shares);L(!!R.shareEnabled)}).catch(()=>{})},[Z]),P1(()=>{if(!Z||!J||$)return;fetch(`/api/session/${Z}/revision/${J}/remote-feedback`).then((R)=>R.json()).then((R)=>{if(!Array.isArray(R.entries))return;let a=P5(R.entries);m((n)=>{let y1=new Map(n);return y1.set(J,a),y1})}).catch(()=>{})},[Z,J,$]),P1(()=>{if(!Z)return;if(!j3){U(!0);return}let R=null,a=()=>{let n=window.location.protocol==="https:"?"wss:":"ws:",y1=new WebSocket(`${n}//${window.location.host}/ws/session/${Z}`);b.current=y1,y1.onopen=()=>U(!0),y1.onclose=()=>{U(!1),R=setTimeout(a,2000)},y1.onmessage=(l2)=>{try{let X1=JSON.parse(l2.data);if(X1.type==="plan-updated"){let N1=Array.isArray(X1.revisions)?X1.revisions:[];if(P2(localStorage,Z,X1.currentRevision,N1),Q(X1.currentRevision),Y(X1.currentRevision),_(null),N1.length>0){G(N1);let E1=N1.find((c1)=>c1.revision===X1.currentRevision);if(E1?.canvasFiles){let c1=E1.canvasFiles.map((W0)=>W0.filename).sort();y(c1);let G2=N1.find((W0)=>W0.revision===X1.currentRevision-1),H0=p2(E1,G2),J0=N5(H0);if(J0.length===1)D({type:"canvas",filename:J0[0]});else if(J0.length>1||c1.length>1)D({type:"overview"});else D({type:"canvas",filename:c1[0]||""})}}}if(X1.type==="revision-updated"){if(Array.isArray(X1.revisions)){let N1=X1.revisions;for(let E1 of N1)if(E1.hasFeedback)Y0(localStorage,Z,E1.revision);G(N1)}}if(X1.type==="watcher-status")F(!!X1.watching);if(X1.type==="remote-feedback"){let N1=X1.revision,E1=X1.entries||[],c1=P5(E1);m((G2)=>{let H0=new Map(G2),J0=H0.get(N1)||[],W0=new Set(J0.map((U2)=>U2.id)),I5=[...J0,...c1.filter((U2)=>!W0.has(U2.id))];return H0.set(N1,I5),H0})}}catch{}}};return a(),()=>{if(R)clearTimeout(R);b.current?.close()}},[Z]);let _2=R0(async(R,a)=>{try{let n=localStorage.getItem(`canvas:${Z}:rev:${J}`),y1=[];if(n)try{y1=(JSON.parse(n).annotations||[]).filter((X1)=>X1.source!=="remote")}catch{}await b3({author:a,revision:J,annotations:y1,generalNote:R}),Y0(localStorage,Z,J),W(!0),U1({kind:"success",message:"Feedback submitted. The canvas author will see it shortly."})}catch(n){U1({kind:"error",message:`Failed to submit feedback: ${n.message||n}`})}},[Z,J]),r2=R0(async(R)=>{if($){let a=S2();if(!a){f(R),s(!0);return}await _2(R,a);return}if(b.current?.readyState===WebSocket.OPEN)b.current.send(JSON.stringify({type:"submit",feedback:R}))},[$,_2]);if(!Z)return B("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 B(w5.Provider,{value:Z,children:B(w1.Provider,{value:{currentRevision:q,selectedRevision:J,revisions:X,setSelectedRevision:Y,isReadOnly:q0,compareRevision:z,setCompareRevision:_,agentWatching:K},children:B(H3,{sessionId:Z,revision:J,isReadOnly:q0,remoteAnnotations:d.get(J),children:B(I1.Provider,{value:{activeView:O,setActiveView:d2,openFiles:S,closeFile:V5,canvasFiles:N},children:B(C6.Provider,{value:{setActiveView:d2},children:B("div",{className:"min-h-screen bg-bg-base",children:[B(R6,{sessionId:Z,projectRoot:C,connected:H,onMobileSidebar:()=>v(!c),collapsed:V,onToggle:()=>E((R)=>!R)},void 0,!1,void 0,this),B(D6,{collapsed:g,onToggle:()=>l((R)=>!R),children:B(x2,{onSubmit:r2},void 0,!1,void 0,this)},void 0,!1,void 0,this),z!==null?B("div",{className:`${V?"lg:ml-0":"lg:ml-60"} ${g?"lg:mr-0":"lg:mr-[var(--sidebar-width,320px)]"} transition-[margin] duration-200`,children:B(H5,{initialLeft:z.left,initialRight:z.right,sessionId:Z,onExit:()=>_(null)},void 0,!1,void 0,this)},void 0,!1,void 0,this):B("div",{className:`relative ${V?"lg:ml-0":"lg:ml-60"} ${g?"lg:mr-0":"lg:mr-[var(--sidebar-width,320px)]"} transition-[margin] duration-200`,id:"plan-scroll-container",children:[B("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:[B("div",{className:"flex items-center gap-2",children:[!$&&B(g2,{currentSessionId:Z,projectRoot:C},void 0,!1,void 0,this),$&&B("span",{className:"text-[11px] text-text-tertiary font-body",children:"Shared canvas"},void 0,!1,void 0,this),!$&&B("span",{className:`w-1.5 h-1.5 rounded-full ${H?"bg-accent-green":"bg-accent-red"}`},void 0,!1,void 0,this)]},void 0,!0,void 0,this),B("div",{className:"flex items-center gap-1",children:[B(C5,{},void 0,!1,void 0,this),B("button",{onClick:()=>v(!c),className:"w-7 h-7 flex items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Annotations",children:B("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:B("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),B(A5,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),B(k6,{},void 0,!1,void 0,this),O.type==="overview"&&B(O5,{revision:J,responseBanner:C1?.response?B(S5,{markdown:C1.response},void 0,!1,void 0,this):void 0},void 0,!1,void 0,this),O.type==="canvas"&&N.includes(O.filename)&&B("div",{className:"relative max-w-[720px] mx-auto px-6 pt-12 pb-32",children:[I&&B("div",{className:"absolute top-3 right-12 z-10",children:B(F5,{onClick:()=>u(!0),hasShare:h.some((R)=>R.revision===J),title:h.some((R)=>R.revision===J)?"Manage share link":"Share this revision"},void 0,!1,void 0,this)},void 0,!1,void 0,this),B("button",{onClick:()=>{let R=document.querySelector(`[data-canvas-file="${O.filename}"] .plan-content`);if(!R)return;let a=n3(R);navigator.clipboard.writeText(a).then(()=>{let n=document.getElementById("export-md-btn");if(n)n.setAttribute("data-copied","true"),setTimeout(()=>{n.removeAttribute("data-copied")},1500)})},id:"export-md-btn",className:"group absolute top-3 right-6 p-1.5 text-text-tertiary hover:text-text-secondary transition-colors z-10",title:"Copy as Markdown",children:[B("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:[B("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"},void 0,!1,void 0,this),B("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),B("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:B("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&&C1?.response&&B(S5,{markdown:C1.response},void 0,!1,void 0,this),B("div",{"data-canvas-file":O.filename,children:B(S0,{revision:J,filename:O.filename},O.filename,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),S.map((R)=>B("div",{style:{display:O.type==="file"&&O.path===R?void 0:"none"},children:B(a3,{path:R},void 0,!1,void 0,this)},R,!1,void 0,this))]},void 0,!0,void 0,this),c&&B("div",{className:"lg:hidden fixed inset-0 z-40 flex",children:[B("div",{className:"flex-1",onClick:()=>v(!1)},void 0,!1,void 0,this),B("div",{className:"w-80 max-w-[85vw] bg-bg-surface border-l border-border-subtle flex flex-col shadow-lg",children:[B("div",{className:"flex items-center justify-between px-4 py-2 border-b border-border-subtle flex-shrink-0",children:[B("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:"Sidebar"},void 0,!1,void 0,this),B("button",{onClick:()=>v(!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),B("div",{className:"flex-1 overflow-hidden",children:B(x2,{onSubmit:r2},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),B(B5,{sessionId:Z,revision:J,open:j,shareEnabled:I,existingShares:h,onClose:()=>u(!1),onShareCreated:(R)=>{A((a)=>[...a.filter((n)=>n.shareId!==R.shareId),R]),U1({kind:"success",message:"Share link created. Copy and send it to reviewers."})},onShareRevoked:(R)=>{A((a)=>a.filter((n)=>n.shareId!==R)),U1({kind:"success",message:"Share link revoked."})}},void 0,!1,void 0,this),B(L5,{open:x,onClose:()=>{s(!1),f(null)},onSubmit:async(R)=>{let a=S3(R);if(s(!1),w!==null)await _2(w,a),f(null)}},void 0,!1,void 0,this),Z1&&B("div",{className:`fixed bottom-4 left-1/2 -translate-x-1/2 z-50 px-4 py-2.5 rounded-lg shadow-lg text-[13px] font-body font-medium flex items-center gap-2 ${Z1.kind==="error"?"bg-accent-red text-white":"bg-accent-green text-white"}`,children:[Z1.message,B("button",{onClick:()=>U1(null),className:"ml-2 opacity-70 hover:opacity-100",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},`${Z}:${J}`,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function R6({sessionId:Z,projectRoot:$,connected:q,onMobileSidebar:Q,collapsed:J,onToggle:Y}){let X=$1.isShared;return B(D0,{children:[J&&B("button",{onClick:Y,className:"hidden lg:flex fixed top-3 left-3 z-20 w-7 h-7 items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors bg-bg-surface border border-border-subtle",title:"Show sidebar",children:B("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[B("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"},void 0,!1,void 0,this),B("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),B("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 ${J?"-translate-x-full":""}`,children:[B("div",{className:"px-4 pt-4 pb-3 flex-shrink-0 border-b border-border-subtle",children:[B("div",{className:"flex items-center gap-2 mb-2",children:[B("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",className:"text-text-tertiary flex-shrink-0",children:B("path",{d:"M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this),X?B("span",{className:"text-[12px] font-body text-text-secondary truncate flex-1",children:"Shared canvas"},void 0,!1,void 0,this):B(D0,{children:[B(g2,{currentSessionId:Z,projectRoot:$},void 0,!1,void 0,this),B("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${q?"bg-accent-green":"bg-accent-red"}`},void 0,!1,void 0,this)]},void 0,!0,void 0,this),B("button",{onClick:Y,className:"ml-auto w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Hide sidebar",children:B("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[B("polyline",{points:"11 17 6 12 11 7"},void 0,!1,void 0,this),B("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),B(C5,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this),B("div",{className:"flex-1 flex flex-col overflow-hidden",children:B(d3,{embedded:!0},void 0,!1,void 0,this)},void 0,!1,void 0,this),B("div",{className:"px-4 py-3 border-t border-border-subtle flex items-center justify-between flex-shrink-0",children:[B("span",{className:"text-[10px] text-text-tertiary font-body uppercase tracking-widest",children:"Theme"},void 0,!1,void 0,this),B(A5,{},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 D6({children:Z,collapsed:$,onToggle:q}){let[Q,J]=q1(()=>{let H=localStorage.getItem("canvas-sidebar-width");return H?parseInt(H,10):320}),Y=h1(!1),X=h1(0),G=h1(0),z=h1(Q);z.current=Q;let _=R0((H)=>{H.preventDefault(),Y.current=!0,X.current=H.clientX,G.current=z.current;let U=(W)=>{if(!Y.current)return;let K=X.current-W.clientX,F=Math.max(240,Math.min(600,G.current+K));J(F),z.current=F},T=()=>{Y.current=!1,localStorage.setItem("canvas-sidebar-width",String(z.current)),document.removeEventListener("mousemove",U),document.removeEventListener("mouseup",T),document.body.style.cursor="",document.body.style.userSelect=""};document.addEventListener("mousemove",U),document.addEventListener("mouseup",T),document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[]);return P1(()=>{return document.documentElement.style.setProperty("--sidebar-width",`${Q}px`),()=>{document.documentElement.style.removeProperty("--sidebar-width")}},[Q]),B(D0,{children:[$&&B("button",{onClick:q,className:"hidden lg:flex fixed top-3 right-3 z-20 w-7 h-7 items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors bg-bg-surface border border-border-subtle",title:"Show annotations",children:B("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:B("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),B("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:Q},children:[B("div",{onMouseDown:_,className:"absolute left-0 top-0 bottom-0 w-1 cursor-col-resize hover:bg-accent-blue/30 transition-colors z-20",style:{marginLeft:"-2px"}},void 0,!1,void 0,this),v1.Children.map(Z,(H)=>v1.isValidElement(H)?v1.cloneElement(H,{collapseButton:B("button",{onClick:q,className:"w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Hide annotations",children:B("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[B("polyline",{points:"13 17 18 12 13 7"},void 0,!1,void 0,this),B("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 S5({markdown:Z}){let[$,q]=q1(!1),Q=M5(()=>e.parse(Z,{async:!1}),[Z]),J=h1(null),{annotations:Y,addAnnotationWithId:X,removeAnnotation:G,updateAnnotation:z,addAnnotationImage:_,removeAnnotationImage:H,activeAnnotationId:U,setActiveAnnotationId:T}=Y1(),[W,K]=q1(null),[F,N]=q1(null),y=M5(()=>Y.filter((b)=>b.filePath===T1),[Y]),[O,D]=q1(Z);if(Z!==O)D(Z),q(!1);P1(()=>{if(!J.current||y.length===0)return;let b=setTimeout(()=>{if(J.current)l0(J.current,y)},50);return()=>clearTimeout(b)},[Q,y.length]);let S=h1(null);if(P1(()=>{d0(U,S.current),S.current=U},[U]),P1(()=>{let b=J.current;if(!b)return;let C=(v)=>{let V=v.target.closest("[data-annotation-id]");if(!V)return;v.stopPropagation();let E=V.getAttribute("data-annotation-id");if(E===U)N({anchorEl:V,annId:E});else T(E)},k=(v)=>{let V=v.target.closest("[data-annotation-id]");if(V)T(V.getAttribute("data-annotation-id"))},c=(v)=>{let V=v.target.closest("[data-annotation-id]"),E=v.relatedTarget?.closest?.("[data-annotation-id]");if(V&&!E)T(null)};return b.addEventListener("click",C),b.addEventListener("mouseover",k),b.addEventListener("mouseout",c),()=>{b.removeEventListener("click",C),b.removeEventListener("mouseover",k),b.removeEventListener("mouseout",c)}},[Q,U]),P1(()=>{let b=()=>{let C=window.getSelection();if(!C||C.isCollapsed||!C.toString().trim())return;if(!J.current)return;let k=C.getRangeAt(0);if(!J.current.contains(k.startContainer))return;if(k.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let c=C.toString().trim();if(c.length<2)return;let v=k.cloneRange(),V=i1(k,J.current),E=`__pending_${Date.now()}`;try{o1(v,E)}catch{}window.getSelection()?.removeAllRanges();let g=document.querySelectorAll(`[data-annotation-id="${E}"]`),l=g[g.length-1];if(!l)return;K({anchorEl:l,tempId:E,snippet:c,ctx:V})};return document.addEventListener("mouseup",b),()=>document.removeEventListener("mouseup",b)},[]),$)return null;let M=document.getElementById("plan-scroll-container");return B("div",{className:"mb-6 rounded-lg border border-accent-blue/20 bg-accent-blue/5 relative",children:[B("button",{onClick:()=>q(!0),className:"absolute top-2 right-2 w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",children:B("span",{className:"text-xs",children:"✕"},void 0,!1,void 0,this)},void 0,!1,void 0,this),B("div",{className:"px-4 py-3 pr-10",children:[B("div",{className:"flex items-center gap-2 mb-1.5",children:[B("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:B("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),B("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),B("div",{ref:J,className:"prose-canvas text-sm",dangerouslySetInnerHTML:{__html:Q}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),W&&B(z0,{anchorEl:W.anchorEl,scrollContainer:M,snippet:W.snippet,truncateAt:80,onAdd:(b,C)=>{let k=F1();r0(W.tempId,k),X(k,W.snippet,b,T1,W.ctx,C),K(null)},onCancel:()=>{i0(W.tempId),K(null)}},void 0,!1,void 0,this),F&&(()=>{let b=Y.find((C)=>C.id===F.annId);if(!b)return null;return B(_0,{anchorEl:F.anchorEl,scrollContainer:M,initialNote:b.note,initialImages:b.images,onUpdate:(C,k)=>{z(F.annId,C);let c=b.images||[];for(let v of k)if(!c.includes(v))_(F.annId,v);for(let v of c)if(!k.includes(v))H(F.annId,v)},onDelete:()=>{G(F.annId),T(null)},onClose:()=>N(null)},void 0,!1,void 0,this)})()]},void 0,!0,void 0,this)}function k6(){let{activeView:Z,setActiveView:$,openFiles:q,closeFile:Q,canvasFiles:J}=v1.useContext(I1),Y=v1.useContext(w5),{addAnnotationWithId:X,setActiveAnnotationId:G}=Y1();if(!(J.length>1||q.length>0))return null;return B("div",{className:"flex items-center border-b border-border-medium bg-bg-surface overflow-x-auto sticky top-0 z-10",children:[J.length>1&&B(D0,{children:[B("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 ${Z.type==="overview"?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[B("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",className:"opacity-60",children:B("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",Z.type==="overview"&&B("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),B("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),J.map((_,H)=>{let U=_.replace(/\.jsx$/,""),T=Z.type==="canvas"&&Z.filename===_;return B(v1.Fragment,{children:[B("button",{onClick:()=>$({type:"canvas",filename:_}),className:`flex items-center gap-1.5 px-4 py-2.5 text-[13px] font-body whitespace-nowrap transition-colors relative ${T?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[U,T&&B("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<J.length-1&&B("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this)]},_,!0,void 0,this)}),q.length>0&&B(D0,{children:[B("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this),q.map((_,H)=>{let U=_.split("/").pop()||_,T=Z.type==="file"&&Z.path===_;return B(v1.Fragment,{children:[B("div",{className:"flex items-center",children:[B("button",{onClick:()=>$({type:"file",path:_}),className:`flex items-center gap-1.5 pl-3 pr-1 py-2.5 text-[13px] font-body whitespace-nowrap transition-colors relative ${T?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[B(x1,{name:U,type:"file"},void 0,!1,void 0,this),U,T&&B("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),B("button",{onClick:(W)=>{W.stopPropagation(),Q(_)},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<q.length-1&&B("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this)]},_,!0,void 0,this)})]},void 0,!0,void 0,this),B("div",{className:"ml-auto flex items-center gap-1 flex-shrink-0",children:Z.type==="file"&&L1&&B("button",{onClick:async()=>{let _=Z.path;try{let U=await(await fetch(`/api/file?session=${Y}&path=${encodeURIComponent(_)}`)).json();if(!U.error){let T=U.content.split(`
|
|
87
|
+
`),X=h1(J,Y),G=[],z=0,_=0,H=0;while(z<J.length||_<Y.length)if(H<X.length&&z<J.length&&_<Y.length&&J[z]===X[H]&&Y[_]===X[H])G.push({type:"same",line:J[z]}),z++,_++,H++;else if(z<J.length&&(H>=X.length||J[z]!==X[H]))G.push({type:"removed",line:J[z]}),z++;else if(_<Y.length)G.push({type:"added",line:Y[_]}),_++;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 T=document.createElement("div");if(T.className="px-3 py-0.5 whitespace-pre-wrap",W.type==="removed")T.classList.add("diff-removed"),T.textContent="- "+W.line;else if(W.type==="added")T.classList.add("diff-added"),T.textContent="+ "+W.line;else T.textContent=" "+W.line;U.appendChild(T)}return $.appendChild(U),!0}function r2(Z,$,q){let Q=document.createElement("span");Q.className="diff-block-label",Q.textContent=$,Q.style.color=q,Q.style.backgroundColor=`color-mix(in srgb, ${q} 12%, transparent)`,Z.appendChild(Q)}import{jsxDEV as p}from"react/jsx-dev-runtime";function B6(Z,$,q){let Q=Z.find((X)=>X.revision===$),J=Z.find((X)=>X.revision===q),Y=new Set;for(let X of Q?.canvasFiles||[])Y.add(X.filename);for(let X of J?.canvasFiles||[])Y.add(X.filename);return[...Y].sort()}function M5({initialLeft:Z,initialRight:$,sessionId:q,onExit:Q}){let[J,Y]=U1(Z),[X,G]=U1($),[z,_]=U1("unified"),[H,U]=U1(!0),[W,T]=U1(!1),{revisions:K}=O6(A1),L=U2(()=>B6(K,J,X),[K,J,X]),[N,S]=U1(()=>L[0]||"plan.jsx");p1(()=>{if(!L.includes(N))S(L[0]||"plan.jsx")},[L,N]);let O=U2(()=>{return K.find((M)=>M.revision===J)?.canvasFiles.some((M)=>M.filename===N)??!1},[K,J,N]),R=U2(()=>{return K.find((M)=>M.revision===X)?.canvasFiles.some((M)=>M.filename===N)??!1},[K,X,N]);return p("div",{className:"flex flex-col h-screen",children:[p("div",{className:"flex items-center justify-between px-6 py-3 border-b border-border-subtle bg-bg-surface flex-shrink-0",children:[p("div",{className:"flex items-center gap-3",children:[p("span",{className:"text-[13px] font-body font-medium text-text-primary",children:"Compare"},void 0,!1,void 0,this),p(I0,{value:J,onChange:Y,accent:"red"},void 0,!1,void 0,this),p("span",{className:"text-text-tertiary text-[13px]",children:"→"},void 0,!1,void 0,this),p(I0,{value:X,onChange:G,accent:"green"},void 0,!1,void 0,this),W&&!H&&p("span",{className:"text-[11px] font-body text-text-tertiary bg-bg-elevated px-2 py-0.5 rounded",children:"No changes"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),p("div",{className:"flex items-center gap-4",children:[p("div",{className:"flex items-center bg-bg-elevated rounded-md p-0.5",children:[p("button",{onClick:()=>_("unified"),className:`text-[11px] font-body px-2.5 py-1 rounded transition-colors ${z==="unified"?"bg-bg-surface text-text-primary font-medium shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Unified"},void 0,!1,void 0,this),p("button",{onClick:()=>_("side-by-side"),className:`text-[11px] font-body px-2.5 py-1 rounded transition-colors ${z==="side-by-side"?"bg-bg-surface text-text-primary font-medium shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Side-by-side"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z==="side-by-side"&&p(F6,{},void 0,!1,void 0,this),p("button",{onClick:Q,className:"text-[12px] font-body font-medium text-text-secondary hover:text-text-primary px-3 py-1.5 rounded-md hover:bg-bg-elevated transition-colors",children:"Exit Compare"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),L.length>1&&p("div",{className:"flex items-center gap-1 px-6 py-2 border-b border-border-subtle bg-bg-surface flex-shrink-0 overflow-x-auto",children:L.map((b)=>{let M=b.replace(/\.jsx$/,""),j=b===N,g=K.find((v)=>v.revision===J)?.canvasFiles.some((v)=>v.filename===b),C=K.find((v)=>v.revision===X)?.canvasFiles.some((v)=>v.filename===b),h=!g?" (added)":!C?" (removed)":"";return p("button",{onClick:()=>S(b),className:`text-[12px] font-body px-3 py-1 rounded-md transition-colors whitespace-nowrap ${j?"bg-bg-elevated text-text-primary font-medium":"text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated"}`,children:[M,h&&p("span",{className:`ml-1 text-[10px] ${!g?"text-accent-green":"text-accent-red"}`,children:h},void 0,!1,void 0,this)]},b,!0,void 0,this)})},void 0,!1,void 0,this),!O||!R?p("div",{className:"flex-1 flex items-center justify-center",children:p("div",{className:"text-center text-text-tertiary font-body",children:[p("div",{className:"text-lg mb-2",children:!O?"New file":"Removed file"},void 0,!1,void 0,this),p("div",{className:"text-[13px]",children:[N.replace(/\.jsx$/,"")," ",!O?"was added":"was removed"," in this revision"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this):z==="unified"?p(L6,{sessionId:q,leftRev:J,rightRev:X,filename:N,onDiffResult:(b,M)=>{T(b),U(M)}},`unified-${J}-${X}-${N}`,!1,void 0,this):p(M6,{sessionId:q,leftRev:J,rightRev:X,filename:N,onDiffResult:(b,M)=>{T(b),U(M)}},`sbs-${J}-${X}-${N}`,!1,void 0,this)]},void 0,!0,void 0,this)}function F6(){let[Z,$]=U1(!0);return p1(()=>{return document.documentElement.dataset.syncScroll=Z?"1":"0",()=>{delete document.documentElement.dataset.syncScroll}},[Z]),p("label",{className:"flex items-center gap-1.5 cursor-pointer select-none",children:[p("input",{type:"checkbox",checked:Z,onChange:(q)=>$(q.target.checked),className:"accent-accent-amber w-3.5 h-3.5"},void 0,!1,void 0,this),p("span",{className:"text-[11px] font-body text-text-secondary",children:"Sync scroll"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function L6({sessionId:Z,leftRev:$,rightRev:q,filename:Q,onDiffResult:J}){let Y=E1(null),X=E1(null),G=E1(null),[z,_]=U1(!1),[H,U]=U1(!1),[W,T]=U1(!1),[K,L]=U1(null),[N,S]=U1(!1),{annotations:O}=X1(),R=O.filter((M)=>!M.filePath&&(!M.canvasFile||M.canvasFile===Q)),{popovers:b}=n1({containerRef:G,restoreKey:W,restoreAnnotations:R,extractContext:(M)=>a1(M,G.current)});return p1(()=>{if(W||K)return;let M=setTimeout(()=>{console.warn("[unified-diff] still loading after 10s",{leftReady:z,rightReady:H,oldRef:!!Y.current,newRef:!!X.current}),S(!0)},1e4);return()=>clearTimeout(M)},[W,K,z,H]),p1(()=>{if(!z||!H||W)return;if(!Y.current||!X.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!Y.current||!X.current||!G.current){console.warn("[unified-diff] refs lost between rAF frames",{old:!!Y.current,new:!!X.current,unified:!!G.current});return}try{let M=W0(Y.current),j=W0(X.current),g=D0(M,j),{fragment:C,hasChanges:h}=G2(g);G.current.innerHTML="",G.current.appendChild(C),T(!0),J(!0,h)}catch(M){console.error("[unified-diff] diff computation failed",M),L(M instanceof Error?M.message:String(M))}})})},[z,H,W]),p("div",{className:"flex-1 min-h-0 overflow-y-auto",children:[!W&&!K&&p("div",{style:{position:"absolute",left:-9999,visibility:"hidden",pointerEvents:"none",width:720},children:[p(x1,{ref:Y,sessionId:Z,revision:$,filename:Q,onReady:()=>_(!0),onError:(M)=>L(`Rev ${$}: ${M}`)},void 0,!1,void 0,this),p(x1,{ref:X,sessionId:Z,revision:q,filename:Q,onReady:()=>U(!0),onError:(M)=>L(`Rev ${q}: ${M}`)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),p("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:[!W&&!K&&p("div",{className:"flex flex-col items-center justify-center h-64 text-text-tertiary font-body text-body gap-2",children:[p("span",{children:"Loading..."},void 0,!1,void 0,this),N&&p("span",{className:"text-[11px]",children:"Taking longer than expected — check Network tab for pending requests"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),K&&p("div",{className:"bg-accent-red-muted rounded-lg p-5 mt-8",children:[p("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Failed to load revision"},void 0,!1,void 0,this),p("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:K},void 0,!1,void 0,this)]},void 0,!0,void 0,this),p("div",{ref:G},void 0,!1,void 0,this)]},void 0,!0,void 0,this),b]},void 0,!0,void 0,this)}function M6({sessionId:Z,leftRev:$,rightRev:q,filename:Q,onDiffResult:J}){let Y=E1(null),X=E1(null),[G,z]=U1(!1),[_,H]=U1(!1),[U,W]=U1(!1),T=E1(null),K=E1(null),L=E1(null),N=E1(!1),S=L5(()=>z(!0),[]),O=L5(()=>H(!0),[]),{annotations:R}=X1(),b=R.filter((j)=>!j.filePath&&(!j.canvasFile||j.canvasFile===Q)),{popovers:M}=n1({containerRef:T,restoreKey:U,restoreAnnotations:b,extractContext:(j)=>a1(j,T.current)});return p1(()=>{if(!G||!_||U)return;if(!Y.current||!X.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!Y.current||!X.current)return;let j=_2(Y.current,X.current);W(!0),J(!0,j)})})},[G,_,U]),p1(()=>{let j=K.current,g=L.current;if(!j||!g)return;let C=(l,V)=>{if(document.documentElement.dataset.syncScroll==="0")return;if(N.current)return;N.current=!0;let E=l.scrollHeight-l.clientHeight,c=V.scrollHeight-V.clientHeight;if(E>0&&c>0)V.scrollTop=l.scrollTop/E*c;requestAnimationFrame(()=>{N.current=!1})},h=()=>C(j,g),v=()=>C(g,j);return j.addEventListener("scroll",h),g.addEventListener("scroll",v),()=>{j.removeEventListener("scroll",h),g.removeEventListener("scroll",v)}},[]),p("div",{ref:T,className:"flex flex-1 min-h-0",children:[p("div",{ref:K,className:"w-1/2 overflow-y-auto border-r border-border-subtle",children:p("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:p(x1,{ref:Y,sessionId:Z,revision:$,filename:Q,onReady:S},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),p("div",{ref:L,className:"w-1/2 overflow-y-auto",children:p("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:p(x1,{ref:X,sessionId:Z,revision:q,filename:Q,onReady:O},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),M]},void 0,!0,void 0,this)}var x1=F5.memo(F5.forwardRef(({sessionId:Z,revision:$,filename:q,onReady:Q,onError:J},Y)=>{let[X,G]=U1(null),[z,_]=U1(null),[H,U]=U1(!0);p1(()=>{U(!0),_(null);let T=q.replace(/\.jsx$/,".js");import(`/api/session/${Z}/canvas/${encodeURIComponent(T)}?rev=${$}&t=${Date.now()}`).then((K)=>{if(!K.default){_("Module has no default export"),U(!1),J?.("Module has no default export");return}G(()=>K.default),U(!1)}).catch((K)=>{_(K.message),U(!1),J?.(K.message)})},[Z,$,q]),p1(()=>{if(!X)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{Q()})})},[X]);let W=U2(()=>X?p(X,{},void 0,!1,void 0,this):null,[X]);if(H)return p("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-body",children:"Loading..."},void 0,!1,void 0,this);if(z)return p("div",{className:"bg-accent-red-muted rounded-lg p-5",children:[p("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Error"},void 0,!1,void 0,this),p("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:z},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(!X)return p("div",{className:"text-text-tertiary text-center py-8 font-body text-body",children:"No canvas loaded"},void 0,!1,void 0,this);return p("div",{ref:Y,children:W},void 0,!1,void 0,this)}));import{useState as m1,useContext as i2,useMemo as P6,useRef as k0,useEffect as y5,useCallback as P5}from"react";import{SessionContext as y6}from"#canvas/runtime";import{jsxDEV as d}from"react/jsx-dev-runtime";function a2(Z,$){if(!Z)return[];return Z.canvasFiles.map((q)=>{if(!q.diffStats)return{filename:q.filename,status:"new"};if(q.diffStats.added===0&&q.diffStats.removed===0)return{filename:q.filename,status:"unchanged",diffStats:q.diffStats};return{filename:q.filename,status:"changed",diffStats:q.diffStats}})}function S5(Z){return Z.filter(($)=>$.status!=="unchanged").map(($)=>$.filename)}function b5({revision:Z,responseBanner:$}){let{setActiveView:q}=i2(k1),{revisions:Q}=i2(A1),J=Q.find((_)=>_.revision===Z),Y=Q.find((_)=>_.revision===Z-1),X=P6(()=>a2(J,Y),[J,Y]),G=X.filter((_)=>_.status!=="unchanged"),z=X.filter((_)=>_.status==="unchanged");return d("div",{className:"max-w-[720px] mx-auto px-6 pt-12 pb-32",children:[$,G.map((_)=>d(b6,{change:_,revision:Z,previousRevision:Y?.revision,onOpenTab:()=>q({type:"canvas",filename:_.filename})},_.filename,!1,void 0,this)),z.length>0&&d("div",{className:"mt-8 border-t border-border-subtle pt-4",children:[d("div",{className:"text-[11px] font-body font-medium uppercase tracking-widest text-text-tertiary mb-3",children:"Unchanged"},void 0,!1,void 0,this),z.map((_)=>d(C6,{change:_,revision:Z,onOpenTab:()=>q({type:"canvas",filename:_.filename})},_.filename,!1,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function S6({mode:Z,onChange:$,showDiff:q}){if(!q)return null;return d("div",{className:"flex items-center bg-bg-elevated rounded-md p-0.5",children:["rendered","unified","side-by-side"].map((Q)=>d("button",{onClick:()=>$(Q),className:`text-[10px] font-body px-2 py-0.5 rounded transition-colors ${Z===Q?"bg-bg-surface text-text-primary font-medium shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:Q==="rendered"?"Full":Q==="unified"?"Unified":"Split"},Q,!1,void 0,this))},void 0,!1,void 0,this)}function b6({change:Z,revision:$,previousRevision:q,onOpenTab:Q}){let J=Z.filename.replace(/\.jsx$/,""),Y=Z.status==="new",X=Z.diffStats,G=Z.status==="changed"&&q!=null,[z,_]=m1("rendered");return d("div",{className:"mb-8",children:[d("div",{className:"flex items-center gap-2 mb-3 pb-2 border-b border-border-subtle",children:[d("span",{className:`text-[11px] font-mono px-1.5 py-0.5 rounded ${Y?"bg-accent-green/10 text-accent-green border border-accent-green/20":"bg-accent-amber/10 text-accent-amber border border-accent-amber/20"}`,children:Y?"new":"modified"},void 0,!1,void 0,this),d("span",{className:"text-[14px] font-body font-medium text-text-primary",children:J},void 0,!1,void 0,this),X&&(X.added>0||X.removed>0)&&d("span",{className:"text-[11px] font-mono text-text-tertiary",children:[d("span",{className:"text-accent-green",children:["+",X.added]},void 0,!0,void 0,this)," ",d("span",{className:"text-accent-red",children:["-",X.removed]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),d(S6,{mode:z,onChange:_,showDiff:G},void 0,!1,void 0,this),d("button",{onClick:Q,className:`${G?"":"ml-auto"} text-[11px] font-body font-medium text-accent-blue hover:text-accent-blue/80 transition-colors`,children:"Open in tab"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z==="rendered"?d("div",{"data-canvas-file":Z.filename,children:d(w0,{revision:$,filename:Z.filename},void 0,!1,void 0,this)},void 0,!1,void 0,this):G&&q!=null?d(j6,{filename:Z.filename,leftRev:q,rightRev:$,mode:z},`${z}-${$}-${q}`,!1,void 0,this):null]},void 0,!0,void 0,this)}function j6({filename:Z,leftRev:$,rightRev:q,mode:Q}){let J=i2(y6);if(Q==="unified")return d(w6,{sessionId:J,filename:Z,leftRev:$,rightRev:q},void 0,!1,void 0,this);return d(A6,{sessionId:J,filename:Z,leftRev:$,rightRev:q},void 0,!1,void 0,this)}function w6({sessionId:Z,filename:$,leftRev:q,rightRev:Q}){let J=k0(null),Y=k0(null),X=k0(null),[G,z]=m1(!1),[_,H]=m1(!1),[U,W]=m1(!1),[T,K]=m1(null);return y5(()=>{if(!G||!_||U)return;if(!J.current||!Y.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!J.current||!Y.current||!X.current)return;try{let L=W0(J.current),N=W0(Y.current),S=D0(L,N),{fragment:O}=G2(S);X.current.innerHTML="",X.current.appendChild(O),W(!0)}catch(L){K(L instanceof Error?L.message:String(L))}})})},[G,_,U]),d("div",{children:[!U&&!T&&d("div",{style:{position:"absolute",left:-9999,visibility:"hidden",pointerEvents:"none",width:720},children:[d(x1,{ref:J,sessionId:Z,revision:q,filename:$,onReady:()=>z(!0),onError:(L)=>K(L)},void 0,!1,void 0,this),d(x1,{ref:Y,sessionId:Z,revision:Q,filename:$,onReady:()=>H(!0),onError:(L)=>K(L)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!U&&!T&&d("div",{className:"flex items-center justify-center h-24 text-text-tertiary font-body text-[13px]",children:"Computing diff..."},void 0,!1,void 0,this),T&&d("div",{className:"text-accent-red text-[13px] font-body p-3 bg-accent-red-muted rounded-lg",children:T},void 0,!1,void 0,this),d("div",{ref:X},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function A6({sessionId:Z,filename:$,leftRev:q,rightRev:Q}){let J=k0(null),Y=k0(null),[X,G]=m1(!1),[z,_]=m1(!1),[H,U]=m1(!1),W=P5(()=>G(!0),[]),T=P5(()=>_(!0),[]);return y5(()=>{if(!X||!z||H)return;if(!J.current||!Y.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!J.current||!Y.current)return;_2(J.current,Y.current),U(!0)})})},[X,z,H]),d("div",{className:"flex gap-0 border-y border-border-subtle overflow-hidden w-screen relative left-1/2 -translate-x-1/2",children:[d("div",{className:"w-1/2 border-r border-border-subtle",children:[d("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 ",q]},void 0,!0,void 0,this),d("div",{className:"px-6 py-4 max-w-[600px] mx-auto",children:d(x1,{ref:J,sessionId:Z,revision:q,filename:$,onReady:W},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),d("div",{className:"w-1/2",children:[d("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 ",Q]},void 0,!0,void 0,this),d("div",{className:"px-6 py-4 max-w-[600px] mx-auto",children:d(x1,{ref:Y,sessionId:Z,revision:Q,filename:$,onReady:T},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function C6({change:Z,revision:$,onOpenTab:q}){let[Q,J]=m1(!1),Y=Z.filename.replace(/\.jsx$/,"");return d("div",{className:"mb-2",children:[d("div",{className:"flex items-center gap-2 py-1.5",children:[d("button",{onClick:()=>J(!Q),className:"text-text-tertiary hover:text-text-secondary transition-colors",children:d("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",className:`transition-transform duration-150 ${Q?"rotate-90":""}`,children:d("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),d("span",{className:"text-[13px] font-body text-text-secondary",children:Y},void 0,!1,void 0,this),d("button",{onClick:q,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),Q&&d("div",{className:"ml-5 mt-1 mb-3","data-canvas-file":Z.filename,children:d(w0,{revision:$,filename:Z.filename},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{useState as K2,useEffect as V6,useCallback as o2}from"react";import{jsxDEV as s}from"react/jsx-dev-runtime";function j5({sessionId:Z,revision:$,open:q,shareEnabled:Q,existingShares:J,onClose:Y,onShareCreated:X,onShareRevoked:G}){let[z,_]=K2(!1),[H,U]=K2(!1),[W,T]=K2(null),[K,L]=K2(!1),N=J.find((b)=>b.revision===$);V6(()=>{if(!q)_(!1),U(!1),T(null),L(!1)},[q]);let S=o2(async()=>{_(!0),T(null);try{let b=await fetch(`/api/session/${Z}/revision/${$}/share`,{method:"POST"}),M=await b.json();if(!b.ok||!M.ok)throw Error(M.error||`HTTP ${b.status}`);X(M.share)}catch(b){T(b.message||String(b))}finally{_(!1)}},[Z,$,X]),O=o2(async(b)=>{if(!window.confirm("Revoke this share link? Reviewers will no longer be able to view or comment."))return;U(!0),T(null);try{let M=await fetch(`/api/session/${Z}/shares/${b}/revoke`,{method:"POST"}),j=await M.json();if(!M.ok||!j.ok)throw Error(j.error||`HTTP ${M.status}`);G(b)}catch(M){T(M.message||String(M))}finally{U(!1)}},[Z,G]),R=o2((b)=>{navigator.clipboard.writeText(b).then(()=>{L(!0),setTimeout(()=>L(!1),1500)})},[]);if(!q)return null;return s("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:Y,children:s("div",{className:"bg-bg-surface border border-border-medium rounded-lg shadow-xl w-full max-w-md mx-4 p-5",onClick:(b)=>b.stopPropagation(),children:[s("div",{className:"flex items-center justify-between mb-3",children:[s("h2",{className:"text-sm font-medium text-text-primary font-body",children:"Share this revision"},void 0,!1,void 0,this),s("button",{onClick:Y,className:"w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",children:s("span",{className:"text-xs",children:"✕"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!Q?s("div",{className:"text-[13px] text-text-secondary font-body space-y-2",children:[s("p",{children:"Canvas sharing is not configured."},void 0,!1,void 0,this),s("p",{className:"text-text-tertiary",children:["Set ",s("code",{className:"px-1 py-0.5 rounded bg-bg-elevated text-text-primary text-[11px]",children:"CANVAS_SHARE_ENDPOINT"},void 0,!1,void 0,this)," to the URL of a deployed"," ",s("code",{className:"px-1 py-0.5 rounded bg-bg-elevated text-text-primary text-[11px]",children:"canvas-share"},void 0,!1,void 0,this)," worker and restart the daemon."]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):N?s("div",{className:"space-y-3",children:[s("p",{className:"text-[13px] text-text-secondary font-body",children:"This revision is shared:"},void 0,!1,void 0,this),s("div",{className:"flex gap-2",children:[s("input",{type:"text",readOnly:!0,value:N.url,className:"flex-1 px-2 py-1.5 text-[12px] font-mono bg-bg-input border border-border-medium rounded text-text-primary",onFocus:(b)=>b.currentTarget.select()},void 0,!1,void 0,this),s("button",{onClick:()=>R(N.url),className:"px-3 py-1.5 text-[12px] font-body font-medium rounded bg-accent-blue text-white hover:opacity-90 transition-opacity whitespace-nowrap",children:K?"Copied!":"Copy"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),N.expiresAt&&s("p",{className:"text-[11px] text-text-tertiary font-body",children:["Expires ",new Date(N.expiresAt).toLocaleDateString(),"."]},void 0,!0,void 0,this),N.encryptionKey&&s("p",{className:"text-[11px] text-accent-green font-body flex items-center gap-1.5",children:[s("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[s("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"},void 0,!1,void 0,this),s("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),"End-to-end encrypted — the key is part of the link and never leaves your browser."]},void 0,!0,void 0,this),s("p",{className:"text-[11px] text-text-tertiary font-body",children:"Anyone with this link can view and leave feedback. Reviewer feedback will appear in your annotation sidebar within seconds."},void 0,!1,void 0,this),s("div",{className:"flex items-center justify-between pt-1",children:[s("button",{onClick:S,disabled:z||H,className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body underline disabled:opacity-50",children:z?"Creating...":"Create a new link"},void 0,!1,void 0,this),N.ownerToken&&s("button",{onClick:()=>O(N.shareId),disabled:z||H,className:"text-[11px] text-accent-red hover:opacity-80 font-body underline disabled:opacity-50",children:H?"Revoking...":"Revoke link"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):s("div",{className:"space-y-3",children:[s("p",{className:"text-[13px] text-text-secondary font-body",children:"Create a public link to this revision. Anyone with the link can view the canvas and leave feedback. Reviewer feedback will sync back here automatically."},void 0,!1,void 0,this),s("button",{onClick:S,disabled:z,className:"w-full px-3 py-2 text-[13px] font-body font-medium rounded bg-accent-blue text-white hover:opacity-90 transition-opacity disabled:opacity-50",children:z?"Creating share link...":"Create share link"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),W&&s("div",{className:"mt-3 px-3 py-2 rounded bg-accent-red/10 border border-accent-red/20 text-[12px] text-accent-red font-body",children:W},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function w5({onClick:Z,title:$="Share this revision",hasShare:q}){return s("button",{onClick:Z,className:`group p-1.5 transition-colors ${q?"text-accent-blue hover:opacity-80":"text-text-tertiary hover:text-text-secondary"}`,title:$,children:s("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[s("circle",{cx:"18",cy:"5",r:"3"},void 0,!1,void 0,this),s("circle",{cx:"6",cy:"12",r:"3"},void 0,!1,void 0,this),s("circle",{cx:"18",cy:"19",r:"3"},void 0,!1,void 0,this),s("line",{x1:"8.59",y1:"13.51",x2:"15.42",y2:"17.49"},void 0,!1,void 0,this),s("line",{x1:"15.41",y1:"6.51",x2:"8.59",y2:"10.49"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}import{useState as I6,useEffect as R6,useRef as D6}from"react";import{jsxDEV as P1}from"react/jsx-dev-runtime";function A5({open:Z,onClose:$,onSubmit:q}){let[Q,J]=I6(""),Y=D6(null);if(R6(()=>{if(Z)J(""),setTimeout(()=>Y.current?.focus(),50)},[Z]),!Z)return null;let X=Q.trim(),G=X.length>=1&&X.length<=80,z=()=>{if(!G)return;q(X)};return P1("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:$,children:P1("div",{className:"bg-bg-surface border border-border-medium rounded-lg shadow-xl w-full max-w-md mx-4 p-5",onClick:(_)=>_.stopPropagation(),children:[P1("div",{className:"flex items-center justify-between mb-3",children:[P1("h2",{className:"text-sm font-medium text-text-primary font-body",children:"Your name"},void 0,!1,void 0,this),P1("button",{onClick:$,className:"w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",children:P1("span",{className:"text-xs",children:"✕"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),P1("p",{className:"text-[13px] text-text-secondary font-body mb-3 leading-relaxed",children:"Before you leave feedback, please enter a name so the canvas author knows who reviewed it. This is stored locally in your browser."},void 0,!1,void 0,this),P1("input",{ref:Y,type:"text",value:Q,onChange:(_)=>J(_.target.value),onKeyDown:(_)=>{if(_.key==="Enter")z()},maxLength:80,placeholder:"e.g. Alice",className:"w-full px-3 py-2 text-[13px] font-body bg-bg-input border border-border-medium rounded text-text-primary placeholder:text-text-disabled focus:outline-none focus:border-accent-blue"},void 0,!1,void 0,this),P1("div",{className:"flex justify-end gap-2 mt-4",children:[P1("button",{onClick:$,className:"px-3 py-1.5 text-[12px] font-body font-medium rounded text-text-secondary hover:text-text-primary hover:bg-bg-elevated transition-colors",children:"Cancel"},void 0,!1,void 0,this),P1("button",{onClick:z,disabled:!G,className:"px-3 py-1.5 text-[12px] font-body font-medium rounded bg-accent-blue text-white hover:opacity-90 transition-opacity disabled:opacity-50",children:"Submit feedback"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}import{jsxDEV as B,Fragment as E0}from"react/jsx-dev-runtime";function V5(Z){let $=[];for(let q of Z)for(let Q of q.annotations)$.push({...Q,source:"remote",author:q.author});return $}var k1=k5({activeView:{type:"overview"},setActiveView:()=>{},openFiles:[],closeFile:()=>{},canvasFiles:[]}),A1=k5({currentRevision:1,selectedRevision:1,revisions:[],setSelectedRevision:()=>{},isReadOnly:!1,compareRevision:null,setCompareRevision:()=>{},agentWatching:!1});function m6(Z){if(Z==="auto")return window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light";return Z}function I5(Z){document.documentElement.dataset.theme=m6(Z)}function x5(){let[Z,$]=J1(()=>{let J=localStorage.getItem("canvas-theme");if(J==="light"||J==="dark"||J==="auto")return J;return"auto"});return y1(()=>{if(I5(Z),Z!=="auto")return;let J=window.matchMedia("(prefers-color-scheme: dark)"),Y=()=>I5("auto");return J.addEventListener("change",Y),()=>J.removeEventListener("change",Y)},[Z]),B("button",{onClick:()=>{let J=Z==="auto"?"light":Z==="light"?"dark":"auto";localStorage.setItem("canvas-theme",J),$(J)},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)"}[Z],children:Z==="auto"?B("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[B("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2",ry:"2"},void 0,!1,void 0,this),B("line",{x1:"8",y1:"21",x2:"16",y2:"21"},void 0,!1,void 0,this),B("line",{x1:"12",y1:"17",x2:"12",y2:"21"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):Z==="dark"?B("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:B("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):B("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[B("circle",{cx:"12",cy:"12",r:"5"},void 0,!1,void 0,this),B("line",{x1:"12",y1:"1",x2:"12",y2:"3"},void 0,!1,void 0,this),B("line",{x1:"12",y1:"21",x2:"12",y2:"23"},void 0,!1,void 0,this),B("line",{x1:"4.22",y1:"4.22",x2:"5.64",y2:"5.64"},void 0,!1,void 0,this),B("line",{x1:"18.36",y1:"18.36",x2:"19.78",y2:"19.78"},void 0,!1,void 0,this),B("line",{x1:"1",y1:"12",x2:"3",y2:"12"},void 0,!1,void 0,this),B("line",{x1:"21",y1:"12",x2:"23",y2:"12"},void 0,!1,void 0,this),B("line",{x1:"4.22",y1:"19.78",x2:"5.64",y2:"18.36"},void 0,!1,void 0,this),B("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 m5(){let{currentRevision:Z,selectedRevision:$,revisions:q,setSelectedRevision:Q,setCompareRevision:J}=c1.useContext(A1);if(q.length<=1){let G=q[0]?.label||`Round ${Z}`;return B("span",{className:"text-[11px] text-text-tertiary font-body",children:G},void 0,!1,void 0,this)}return B("div",{className:"flex flex-col gap-1",children:[B(I0,{value:$,onChange:Q,accent:$===Z?"default":"amber"},void 0,!1,void 0,this),B("button",{onClick:()=>{let X;if($===Z)X=[...q].reverse().find((z)=>z.revision<Z)?.revision??Math.max(1,Z-1);else X=$;J({left:X,right:Z})},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 u6(){let Z=$1.isShared?$1.shareId:$1.sessionId,$=$1.isShared,[q,Q]=J1(1),[J,Y]=J1(1),[X,G]=J1([]),[z,_]=J1(null),[H,U]=J1(!1),[W,T]=J1(!1),[K,L]=J1(!1),[N,S]=J1([]),[O,R]=J1({type:"overview"}),[b,M]=J1([]),j=V1(null),g=V1([]),C=V1(new Set),[h,v]=J1(),[l,V]=J1(!1),[E,c]=J1(!1),[P,x]=J1(!1),[f,o]=J1(!1),[w,F]=J1([]),[m,u]=J1(!1),[D,a]=J1(new Map),[I,k]=J1(!1),[Z1,Y1]=J1(null),[I1,S1]=J1(null),N0=T0((A)=>{if($)return;let i=`${A.revision}\x00${A.filename}\x00${A.message}`;if(C.current.has(i))return;C.current.add(i);let t=JSON.stringify({type:"render-error",error:A});if(j.current?.readyState===WebSocket.OPEN)j.current.send(t);else g.current.push(A)},[$]);y1(()=>{if(!I1)return;let A=setTimeout(()=>S1(null),4000);return()=>clearTimeout(A)},[I1]),y1(()=>{let A=["Agent Canvas"];if(h){let i=h.replace(/\/+$/,"").split("/");A.push(i[i.length-1]||Z)}else if(Z)A.push(Z);if(O.type==="file")A.push(O.path.split("/").pop()||O.path);else if(O.type==="overview")A.push("Overview");else if(O.type==="canvas"&&N.length>1&&O.filename)A.push(O.filename.replace(/\.jsx$/,""));else if(z)A.push("Compare");document.title=A.join(" — ")},[Z,h,O,z]);let H2=V1(new Map),J0=X.find((A)=>A.revision===J),s2=J!==q||!!J0?.hasFeedback||W,t2=J===q&&(!!J0?.hasFeedback||W)?"next":"current",n2=T0((A)=>{let i=O.type==="overview"?"overview":O.type==="canvas"?`canvas:${O.filename}`:`file:${O.path}`;if(H2.current.set(i,window.scrollY),R(A),A.type==="file")M((t)=>t.includes(A.path)?t:[...t,A.path])},[O]),u5=T0((A)=>{H2.current.delete(`file:${A}`),M((i)=>i.filter((t)=>t!==A)),R((i)=>{if(i.type==="file"&&i.path===A)return N.length>1?{type:"overview"}:{type:"canvas",filename:N[0]||""};return i})},[N]);k6(()=>{let A=O.type==="overview"?"overview":O.type==="canvas"?`canvas:${O.filename}`:`file:${O.path}`;window.scrollTo(0,H2.current.get(A)||0)},[O]),y1(()=>{if(!Z)return;j3().then((A)=>{if(A.currentRevision){let i=A.revisions||[];for(let t of i)if(t.hasFeedback)z0(localStorage,Z,t.revision);C2(localStorage,Z,A.currentRevision,i),Q(A.currentRevision),Y(A.currentRevision),G(i)}if(A.canvasFiles){let i=A.canvasFiles.sort();S(i),R((t)=>{if(t.type==="overview")return i.length>1?t:{type:"canvas",filename:i[0]||""};if(t.type==="canvas"&&(!t.filename||!i.includes(t.filename)))return{type:"canvas",filename:i[0]||""};return t})}if(A.projectRoot)v(A.projectRoot);if(Array.isArray(A.shares))F(A.shares);u(!!A.shareEnabled)}).catch(()=>{})},[Z]),y1(()=>{if(!Z||!J||$)return;fetch(`/api/session/${Z}/revision/${J}/remote-feedback`).then((A)=>A.json()).then((A)=>{if(!Array.isArray(A.entries))return;let i=V5(A.entries);a((t)=>{let N1=new Map(t);return N1.set(J,i),N1})}).catch(()=>{})},[Z,J,$]),y1(()=>{if(!Z)return;if(!I3){U(!0);return}let A=null,i=()=>{let t=window.location.protocol==="https:"?"wss:":"ws:",N1=new WebSocket(`${t}//${window.location.host}/ws/session/${Z}`);j.current=N1,N1.onopen=()=>{U(!0);for(let x0 of g.current)N1.send(JSON.stringify({type:"render-error",error:x0}));g.current=[]},N1.onclose=()=>{U(!1),A=setTimeout(i,2000)},N1.onmessage=(x0)=>{try{let z1=JSON.parse(x0.data);if(z1.type==="plan-updated"){let O1=Array.isArray(z1.revisions)?z1.revisions:[];if(C2(localStorage,Z,z1.currentRevision,O1),Q(z1.currentRevision),Y(z1.currentRevision),_(null),O1.length>0){G(O1);let u1=O1.find((d1)=>d1.revision===z1.currentRevision);if(u1?.canvasFiles){let d1=u1.canvasFiles.map((B0)=>B0.filename).sort();S(d1);let T2=O1.find((B0)=>B0.revision===z1.currentRevision-1),O0=a2(u1,T2),Q0=S5(O0);if(Q0.length===1)R({type:"canvas",filename:Q0[0]});else if(Q0.length>1||d1.length>1)R({type:"overview"});else R({type:"canvas",filename:d1[0]||""})}}}if(z1.type==="revision-updated"){if(Array.isArray(z1.revisions)){let O1=z1.revisions;for(let u1 of O1)if(u1.hasFeedback)z0(localStorage,Z,u1.revision);G(O1)}}if(z1.type==="watcher-status")L(!!z1.watching);if(z1.type==="remote-feedback"){let O1=z1.revision,u1=z1.entries||[],d1=V5(u1);a((T2)=>{let O0=new Map(T2),Q0=O0.get(O1)||[],B0=new Set(Q0.map((N2)=>N2.id)),g5=[...Q0,...d1.filter((N2)=>!B0.has(N2.id))];return O0.set(O1,g5),O0})}}catch{}}};return i(),()=>{if(A)clearTimeout(A);j.current?.close()}},[Z]);let W2=T0(async(A,i)=>{try{let t=localStorage.getItem(`canvas:${Z}:rev:${J}`),N1=[];if(t)try{N1=(JSON.parse(t).annotations||[]).filter((z1)=>z1.source!=="remote")}catch{}await V3({author:i,revision:J,annotations:N1,generalNote:A}),z0(localStorage,Z,J),T(!0),S1({kind:"success",message:"Feedback submitted. The canvas author will see it shortly."})}catch(t){S1({kind:"error",message:`Failed to submit feedback: ${t.message||t}`})}},[Z,J]),e2=T0(async(A)=>{if($){let i=I2();if(!i){Y1(A),k(!0);return}await W2(A,i);return}if(j.current?.readyState===WebSocket.OPEN)j.current.send(JSON.stringify({type:"submit",feedback:A}))},[$,W2]);if(!Z)return B("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 B(E5.Provider,{value:Z,children:B(t0.Provider,{value:N0,children:B(A1.Provider,{value:{currentRevision:q,selectedRevision:J,revisions:X,setSelectedRevision:Y,isReadOnly:s2,compareRevision:z,setCompareRevision:_,agentWatching:K},children:B(B3,{sessionId:Z,revision:J,isReadOnly:s2,draftPhase:t2,remoteAnnotations:D.get(J),children:B(k1.Provider,{value:{activeView:O,setActiveView:n2,openFiles:b,closeFile:u5,canvasFiles:N},children:B(x6.Provider,{value:{setActiveView:n2},children:B("div",{className:"min-h-screen bg-bg-base",children:[B(g6,{sessionId:Z,projectRoot:h,connected:H,onMobileSidebar:()=>V(!l),collapsed:E,onToggle:()=>c((A)=>!A)},void 0,!1,void 0,this),B(f6,{collapsed:P,onToggle:()=>x((A)=>!A),children:B(p2,{onSubmit:e2},void 0,!1,void 0,this)},void 0,!1,void 0,this),z!==null?B("div",{className:`${E?"lg:ml-0":"lg:ml-60"} ${P?"lg:mr-0":"lg:mr-[var(--sidebar-width,320px)]"} transition-[margin] duration-200`,children:B(M5,{initialLeft:z.left,initialRight:z.right,sessionId:Z,onExit:()=>_(null)},void 0,!1,void 0,this)},void 0,!1,void 0,this):B("div",{className:`relative ${E?"lg:ml-0":"lg:ml-60"} ${P?"lg:mr-0":"lg:mr-[var(--sidebar-width,320px)]"} transition-[margin] duration-200`,id:"plan-scroll-container",children:[B("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:[B("div",{className:"flex items-center gap-2",children:[!$&&B(d2,{currentSessionId:Z,projectRoot:h},void 0,!1,void 0,this),$&&B("span",{className:"text-[11px] text-text-tertiary font-body",children:"Shared canvas"},void 0,!1,void 0,this),!$&&B("span",{className:`w-1.5 h-1.5 rounded-full ${H?"bg-accent-green":"bg-accent-red"}`},void 0,!1,void 0,this)]},void 0,!0,void 0,this),B("div",{className:"flex items-center gap-1",children:[B(m5,{},void 0,!1,void 0,this),B("button",{onClick:()=>V(!l),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:B("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:B("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),B(x5,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),B(v6,{},void 0,!1,void 0,this),O.type==="overview"&&B(b5,{revision:J,responseBanner:J0?.response?B(R5,{markdown:J0.response},void 0,!1,void 0,this):void 0},void 0,!1,void 0,this),O.type==="canvas"&&N.includes(O.filename)&&B("div",{className:"relative max-w-[720px] mx-auto px-6 pt-12 pb-32",children:[m&&B("div",{className:"absolute top-3 right-12 z-10",children:B(w5,{onClick:()=>o(!0),hasShare:w.some((A)=>A.revision===J),title:w.some((A)=>A.revision===J)?"Manage share link":"Share this revision"},void 0,!1,void 0,this)},void 0,!1,void 0,this),B("button",{onClick:()=>{let A=document.querySelector(`[data-canvas-file="${O.filename}"] .plan-content`);if(!A)return;let i=X5(A);navigator.clipboard.writeText(i).then(()=>{let t=document.getElementById("export-md-btn");if(t)t.setAttribute("data-copied","true"),setTimeout(()=>{t.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:[B("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:[B("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"},void 0,!1,void 0,this),B("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),B("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:B("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&&J0?.response&&B(R5,{markdown:J0.response},void 0,!1,void 0,this),B("div",{"data-canvas-file":O.filename,children:B(w0,{revision:J,filename:O.filename},O.filename,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),b.map((A)=>B("div",{style:{display:O.type==="file"&&O.path===A?void 0:"none"},children:B(q5,{path:A},void 0,!1,void 0,this)},A,!1,void 0,this))]},void 0,!0,void 0,this),l&&B("div",{className:"lg:hidden fixed inset-0 z-40 flex",children:[B("div",{className:"flex-1",onClick:()=>V(!1)},void 0,!1,void 0,this),B("div",{className:"w-80 max-w-[85vw] bg-bg-surface border-l border-border-subtle flex flex-col shadow-lg",children:[B("div",{className:"flex items-center justify-between px-4 py-2 border-b border-border-subtle flex-shrink-0",children:[B("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:"Sidebar"},void 0,!1,void 0,this),B("button",{onClick:()=>V(!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),B("div",{className:"flex-1 overflow-hidden",children:B(p2,{onSubmit:e2},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),B(j5,{sessionId:Z,revision:J,open:f,shareEnabled:m,existingShares:w,onClose:()=>o(!1),onShareCreated:(A)=>{F((i)=>[...i.filter((t)=>t.shareId!==A.shareId),A]),S1({kind:"success",message:"Share link created. Copy and send it to reviewers."})},onShareRevoked:(A)=>{F((i)=>i.filter((t)=>t.shareId!==A)),S1({kind:"success",message:"Share link revoked."})}},void 0,!1,void 0,this),B(A5,{open:I,onClose:()=>{k(!1),Y1(null)},onSubmit:async(A)=>{let i=C3(A);if(k(!1),Z1!==null)await W2(Z1,i),Y1(null)}},void 0,!1,void 0,this),I1&&B("div",{className:`fixed bottom-4 left-1/2 -translate-x-1/2 z-50 px-4 py-2.5 rounded-lg shadow-lg text-[13px] font-body font-medium flex items-center gap-2 ${I1.kind==="error"?"bg-accent-red text-white":"bg-accent-green text-white"}`,children:[I1.message,B("button",{onClick:()=>S1(null),className:"ml-2 opacity-70 hover:opacity-100",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},`${Z}:${J}:${t2}`,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function g6({sessionId:Z,projectRoot:$,connected:q,onMobileSidebar:Q,collapsed:J,onToggle:Y}){let X=$1.isShared;return B(E0,{children:[J&&B("button",{onClick:Y,className:"hidden lg:flex fixed top-3 left-3 z-20 w-7 h-7 items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors bg-bg-surface border border-border-subtle",title:"Show sidebar",children:B("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[B("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"},void 0,!1,void 0,this),B("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),B("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 ${J?"-translate-x-full":""}`,children:[B("div",{className:"px-4 pt-4 pb-3 flex-shrink-0 border-b border-border-subtle",children:[B("div",{className:"flex items-center gap-2 mb-2",children:[B("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",className:"text-text-tertiary flex-shrink-0",children:B("path",{d:"M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this),X?B("span",{className:"text-[12px] font-body text-text-secondary truncate flex-1",children:"Shared canvas"},void 0,!1,void 0,this):B(E0,{children:[B(d2,{currentSessionId:Z,projectRoot:$},void 0,!1,void 0,this),B("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${q?"bg-accent-green":"bg-accent-red"}`},void 0,!1,void 0,this)]},void 0,!0,void 0,this),B("button",{onClick:Y,className:"ml-auto w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Hide sidebar",children:B("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[B("polyline",{points:"11 17 6 12 11 7"},void 0,!1,void 0,this),B("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),B(m5,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this),B("div",{className:"flex-1 flex flex-col overflow-hidden",children:B(n3,{embedded:!0},void 0,!1,void 0,this)},void 0,!1,void 0,this),B("div",{className:"px-4 py-3 border-t border-border-subtle flex items-center justify-between flex-shrink-0",children:[B("span",{className:"text-[10px] text-text-tertiary font-body uppercase tracking-widest",children:"Theme"},void 0,!1,void 0,this),B(x5,{},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 f6({children:Z,collapsed:$,onToggle:q}){let[Q,J]=J1(()=>{let H=localStorage.getItem("canvas-sidebar-width");return H?parseInt(H,10):320}),Y=V1(!1),X=V1(0),G=V1(0),z=V1(Q);z.current=Q;let _=T0((H)=>{H.preventDefault(),Y.current=!0,X.current=H.clientX,G.current=z.current;let U=(T)=>{if(!Y.current)return;let K=X.current-T.clientX,L=Math.max(240,Math.min(600,G.current+K));J(L),z.current=L},W=()=>{Y.current=!1,localStorage.setItem("canvas-sidebar-width",String(z.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 y1(()=>{return document.documentElement.style.setProperty("--sidebar-width",`${Q}px`),()=>{document.documentElement.style.removeProperty("--sidebar-width")}},[Q]),B(E0,{children:[$&&B("button",{onClick:q,className:"hidden lg:flex fixed top-3 right-3 z-20 w-7 h-7 items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors bg-bg-surface border border-border-subtle",title:"Show annotations",children:B("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:B("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),B("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:Q},children:[B("div",{onMouseDown:_,className:"absolute left-0 top-0 bottom-0 w-1 cursor-col-resize hover:bg-accent-blue/30 transition-colors z-20",style:{marginLeft:"-2px"}},void 0,!1,void 0,this),c1.Children.map(Z,(H)=>c1.isValidElement(H)?c1.cloneElement(H,{collapseButton:B("button",{onClick:q,className:"w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Hide annotations",children:B("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[B("polyline",{points:"13 17 18 12 13 7"},void 0,!1,void 0,this),B("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 R5({markdown:Z}){let[$,q]=J1(!1),Q=C5(()=>e.parse(Z,{async:!1}),[Z]),J=V1(null),{annotations:Y,addAnnotationWithId:X,removeAnnotation:G,updateAnnotation:z,addAnnotationImage:_,removeAnnotationImage:H,activeAnnotationId:U,setActiveAnnotationId:W}=X1(),[T,K]=J1(null),[L,N]=J1(null),S=C5(()=>Y.filter((j)=>j.filePath===T1),[Y]),[O,R]=J1(Z);if(Z!==O)R(Z),q(!1);y1(()=>{if(!J.current||S.length===0)return;let j=setTimeout(()=>{if(J.current)a0(J.current,S)},50);return()=>clearTimeout(j)},[Q,S.length]);let b=V1(null);if(y1(()=>{r0(U,b.current),b.current=U},[U]),y1(()=>{let j=J.current;if(!j)return;let g=(v)=>{let l=v.target.closest("[data-annotation-id]");if(!l)return;v.stopPropagation();let V=l.getAttribute("data-annotation-id");if(V===U)N({anchorEl:l,annId:V});else W(V)},C=(v)=>{let l=v.target.closest("[data-annotation-id]");if(l)W(l.getAttribute("data-annotation-id"))},h=(v)=>{let l=v.target.closest("[data-annotation-id]"),V=v.relatedTarget?.closest?.("[data-annotation-id]");if(l&&!V)W(null)};return j.addEventListener("click",g),j.addEventListener("mouseover",C),j.addEventListener("mouseout",h),()=>{j.removeEventListener("click",g),j.removeEventListener("mouseover",C),j.removeEventListener("mouseout",h)}},[Q,U]),y1(()=>{let j=()=>{let g=window.getSelection();if(!g||g.isCollapsed||!g.toString().trim())return;if(!J.current)return;let C=g.getRangeAt(0);if(!J.current.contains(C.startContainer))return;if(C.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let h=g.toString().trim();if(h.length<2)return;let v=C.cloneRange(),l=a1(C,J.current),V=`__pending_${Date.now()}`;try{s1(v,V)}catch{}window.getSelection()?.removeAllRanges();let E=document.querySelectorAll(`[data-annotation-id="${V}"]`),c=E[E.length-1];if(!c)return;K({anchorEl:c,tempId:V,snippet:h,ctx:l})};return document.addEventListener("mouseup",j),()=>document.removeEventListener("mouseup",j)},[]),$)return null;let M=document.getElementById("plan-scroll-container");return B("div",{className:"mb-6 rounded-lg border border-accent-blue/20 bg-accent-blue/5 relative",children:[B("button",{onClick:()=>q(!0),className:"absolute top-2 right-2 w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",children:B("span",{className:"text-xs",children:"✕"},void 0,!1,void 0,this)},void 0,!1,void 0,this),B("div",{className:"px-4 py-3 pr-10",children:[B("div",{className:"flex items-center gap-2 mb-1.5",children:[B("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:B("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),B("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),B("div",{ref:J,className:"prose-canvas text-sm",dangerouslySetInnerHTML:{__html:Q}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),T&&B(G0,{anchorEl:T.anchorEl,scrollContainer:M,snippet:T.snippet,truncateAt:80,onAdd:(j,g)=>{let C=L1();i0(T.tempId,C),X(C,T.snippet,j,T1,T.ctx,g),K(null)},onCancel:()=>{o0(T.tempId),K(null)}},void 0,!1,void 0,this),L&&(()=>{let j=Y.find((g)=>g.id===L.annId);if(!j)return null;return B(U0,{anchorEl:L.anchorEl,scrollContainer:M,initialNote:j.note,initialImages:j.images,onUpdate:(g,C)=>{z(L.annId,g);let h=j.images||[];for(let v of C)if(!h.includes(v))_(L.annId,v);for(let v of h)if(!C.includes(v))H(L.annId,v)},onDelete:()=>{G(L.annId),W(null)},onClose:()=>N(null)},void 0,!1,void 0,this)})()]},void 0,!0,void 0,this)}function v6(){let{activeView:Z,setActiveView:$,openFiles:q,closeFile:Q,canvasFiles:J}=c1.useContext(k1),Y=c1.useContext(E5),{addAnnotationWithId:X,setActiveAnnotationId:G}=X1();if(!(J.length>1||q.length>0))return null;return B("div",{className:"flex items-center border-b border-border-medium bg-bg-surface overflow-x-auto sticky top-0 z-10",children:[J.length>1&&B(E0,{children:[B("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 ${Z.type==="overview"?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[B("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",className:"opacity-60",children:B("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",Z.type==="overview"&&B("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),B("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),J.map((_,H)=>{let U=_.replace(/\.jsx$/,""),W=Z.type==="canvas"&&Z.filename===_;return B(c1.Fragment,{children:[B("button",{onClick:()=>$({type:"canvas",filename:_}),className:`flex items-center gap-1.5 px-4 py-2.5 text-[13px] font-body whitespace-nowrap transition-colors relative ${W?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[U,W&&B("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<J.length-1&&B("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this)]},_,!0,void 0,this)}),q.length>0&&B(E0,{children:[B("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this),q.map((_,H)=>{let U=_.split("/").pop()||_,W=Z.type==="file"&&Z.path===_;return B(c1.Fragment,{children:[B("div",{className:"flex items-center",children:[B("button",{onClick:()=>$({type:"file",path:_}),className:`flex items-center gap-1.5 pl-3 pr-1 py-2.5 text-[13px] font-body whitespace-nowrap transition-colors relative ${W?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[B(f1,{name:U,type:"file"},void 0,!1,void 0,this),U,W&&B("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),B("button",{onClick:(T)=>{T.stopPropagation(),Q(_)},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<q.length-1&&B("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this)]},_,!0,void 0,this)})]},void 0,!0,void 0,this),B("div",{className:"ml-auto flex items-center gap-1 flex-shrink-0",children:Z.type==="file"&&M1&&B("button",{onClick:async()=>{let _=Z.path;try{let U=await(await fetch(`/api/file?session=${Y}&path=${encodeURIComponent(_)}`)).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
|
-
...`:""),
|
|
91
|
+
...`:""),T=L1();X(T,W,"",_),G(T)}}catch{}},className:"flex items-center gap-1 px-3 py-1.5 text-[11px] font-medium font-body text-text-tertiary hover:text-text-secondary whitespace-nowrap transition-colors",children:[B("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 D5=document.getElementById("root");if(D5)E6(D5).render(B(u6,{},void 0,!1,void 0,this));export{A1 as RevisionContext,k1 as ActiveViewContext};
|