agent-canvas 0.1.15 → 0.1.16

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.
@@ -250,7 +250,9 @@ function processBlockWithChildren(
250
250
  } else if (cm.kind === "removed") {
251
251
  hasChanges = true;
252
252
  const ghost = ghostBlock(cm.oldBlock!.element);
253
- const insertBefore = findInsertionPoint(childMatches, cm, cloneMap.newMap);
253
+ const refNode = findInsertionPoint(childMatches, cm, cloneMap.newMap);
254
+ // refNode may be deeply nested — walk up to find a direct child of the container
255
+ const insertBefore = refNode ? directChildOf(newContainer, refNode) : null;
254
256
  newContainer.insertBefore(ghost, insertBefore);
255
257
  } else if (cm.kind === "added") {
256
258
  hasChanges = true;
@@ -374,6 +376,15 @@ function findInsertionPoint(
374
376
  return null;
375
377
  }
376
378
 
379
+ /** Walk up from `el` to find the ancestor that is a direct child of `container`. */
380
+ function directChildOf(container: HTMLElement, el: HTMLElement): HTMLElement | null {
381
+ let node: HTMLElement | null = el;
382
+ while (node && node.parentElement !== container) {
383
+ node = node.parentElement;
384
+ }
385
+ return node;
386
+ }
387
+
377
388
  /* ── Element-level diff for blocks with rich internal structure (e.g. markdown) ── */
378
389
 
379
390
  /**
@@ -1,4 +1,4 @@
1
- import A1,{useEffect as M1,useLayoutEffect as F4,useState as $1,useCallback as u0,useRef as I1,createContext as D2,useMemo as j2}from"react";import{createRoot as L4}from"react-dom/client";function f0(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var V1=f0();function M5(J){V1=J}var R1={exec:()=>null};function l(J,$=""){let Y=typeof J=="string"?J:J.source,Z={replace:(Q,q)=>{let X=typeof q=="string"?q:q.source;return X=X.replace(Z1.caret,"$1"),Y=Y.replace(Q,X),Z},getRegex:()=>new RegExp(Y,$)};return Z}var E2=(()=>{try{return!!new RegExp("(?<=1)(?<!1)")}catch{return!1}})(),Z1={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] +\S/,listReplaceTask:/^\[[ xX]\] +/,listTaskCheckbox:/\[[ xX]\]/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:(J)=>new RegExp(`^( {0,3}${J})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:(J)=>new RegExp(`^ {0,${Math.min(3,J-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:(J)=>new RegExp(`^ {0,${Math.min(3,J-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:(J)=>new RegExp(`^ {0,${Math.min(3,J-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:(J)=>new RegExp(`^ {0,${Math.min(3,J-1)}}#`),htmlBeginRegex:(J)=>new RegExp(`^ {0,${Math.min(3,J-1)}}<(?:[a-z].*>|!--)`,"i"),blockquoteBeginRegex:(J)=>new RegExp(`^ {0,${Math.min(3,J-1)}}>`)},v2=/^(?:[ \t]*(?:\n|$))+/,x2=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,f2=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,n1=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,h2=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,h0=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,P5=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,S5=l(P5).replace(/bull/g,h0).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(),p2=l(P5).replace(/bull/g,h0).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(),p0=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,c2=/^[^\n]+/,c0=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,d2=l(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",c0).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),r2=l(/^(bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,h0).getRegex(),N0="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",d0=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,l2=l("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$))","i").replace("comment",d0).replace("tag",N0).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),b5=l(p0).replace("hr",n1).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",N0).getRegex(),i2=l(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",b5).getRegex(),r0={blockquote:i2,code:x2,def:d2,fences:f2,heading:h2,hr:n1,html:l2,lheading:S5,list:r2,newline:v2,paragraph:b5,table:R1,text:c2},T5=l("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",n1).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",N0).getRegex(),a2={...r0,lheading:p2,table:T5,paragraph:l(p0).replace("hr",n1).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",T5).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",N0).getRegex()},o2={...r0,html:l(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",d0).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:R1,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:l(p0).replace("hr",n1).replace("heading",` *#{1,6} *[^
1
+ import A1,{useEffect as M1,useLayoutEffect as L4,useState as $1,useCallback as u0,useRef as I1,createContext as D2,useMemo as j2}from"react";import{createRoot as B4}from"react-dom/client";function f0(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var V1=f0();function M5(J){V1=J}var R1={exec:()=>null};function l(J,$=""){let Y=typeof J=="string"?J:J.source,Z={replace:(Q,q)=>{let X=typeof q=="string"?q:q.source;return X=X.replace(Z1.caret,"$1"),Y=Y.replace(Q,X),Z},getRegex:()=>new RegExp(Y,$)};return Z}var E2=(()=>{try{return!!new RegExp("(?<=1)(?<!1)")}catch{return!1}})(),Z1={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] +\S/,listReplaceTask:/^\[[ xX]\] +/,listTaskCheckbox:/\[[ xX]\]/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:(J)=>new RegExp(`^( {0,3}${J})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:(J)=>new RegExp(`^ {0,${Math.min(3,J-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:(J)=>new RegExp(`^ {0,${Math.min(3,J-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:(J)=>new RegExp(`^ {0,${Math.min(3,J-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:(J)=>new RegExp(`^ {0,${Math.min(3,J-1)}}#`),htmlBeginRegex:(J)=>new RegExp(`^ {0,${Math.min(3,J-1)}}<(?:[a-z].*>|!--)`,"i"),blockquoteBeginRegex:(J)=>new RegExp(`^ {0,${Math.min(3,J-1)}}>`)},v2=/^(?:[ \t]*(?:\n|$))+/,x2=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,f2=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,n1=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,h2=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,h0=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,P5=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,S5=l(P5).replace(/bull/g,h0).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(),p2=l(P5).replace(/bull/g,h0).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(),p0=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,c2=/^[^\n]+/,c0=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,d2=l(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",c0).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),r2=l(/^(bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,h0).getRegex(),N0="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",d0=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,l2=l("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$))","i").replace("comment",d0).replace("tag",N0).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),b5=l(p0).replace("hr",n1).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",N0).getRegex(),i2=l(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",b5).getRegex(),r0={blockquote:i2,code:x2,def:d2,fences:f2,heading:h2,hr:n1,html:l2,lheading:S5,list:r2,newline:v2,paragraph:b5,table:R1,text:c2},T5=l("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",n1).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",N0).getRegex(),a2={...r0,lheading:p2,table:T5,paragraph:l(p0).replace("hr",n1).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",T5).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",N0).getRegex()},o2={...r0,html:l(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",d0).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:R1,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:l(p0).replace("hr",n1).replace("heading",` *#{1,6} *[^
2
2
  ]`).replace("lheading",S5).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},s2=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,t2=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,w5=/^( {2,}|\\)\n(?!\s*$)/,n2=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,T0=/[\p{P}\p{S}]/u,l0=/[\s\p{P}\p{S}]/u,A5=/[^\s\p{P}\p{S}]/u,e2=l(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,l0).getRegex(),I5=/(?!~)[\p{P}\p{S}]/u,$3=/(?!~)[\s\p{P}\p{S}]/u,J3=/(?:[^\s\p{P}\p{S}]|~)/u,C5=/(?![*_])[\p{P}\p{S}]/u,Y3=/(?![*_])[\s\p{P}\p{S}]/u,Q3=/(?:[^\s\p{P}\p{S}]|[*_])/u,Z3=l(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",E2?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),j5=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,X3=l(j5,"u").replace(/punct/g,T0).getRegex(),q3=l(j5,"u").replace(/punct/g,I5).getRegex(),R5="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",_3=l(R5,"gu").replace(/notPunctSpace/g,A5).replace(/punctSpace/g,l0).replace(/punct/g,T0).getRegex(),z3=l(R5,"gu").replace(/notPunctSpace/g,J3).replace(/punctSpace/g,$3).replace(/punct/g,I5).getRegex(),G3=l("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,A5).replace(/punctSpace/g,l0).replace(/punct/g,T0).getRegex(),U3=l(/^~~?(?:((?!~)punct)|[^\s~])/,"u").replace(/punct/g,C5).getRegex(),K3="^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)",H3=l(K3,"gu").replace(/notPunctSpace/g,Q3).replace(/punctSpace/g,Y3).replace(/punct/g,C5).getRegex(),W3=l(/\\(punct)/,"gu").replace(/punct/g,T0).getRegex(),N3=l(/^<(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(),T3=l(d0).replace("(?:-->|$)","-->").getRegex(),O3=l("^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",T3).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),K0=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+[^`]*?`+(?!`)|[^\[\]\\`])*?/,F3=l(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace("label",K0).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),k5=l(/^!?\[(label)\]\[(ref)\]/).replace("label",K0).replace("ref",c0).getRegex(),V5=l(/^!?\[(ref)\](?:\[\])?/).replace("ref",c0).getRegex(),L3=l("reflink|nolink(?!\\()","g").replace("reflink",k5).replace("nolink",V5).getRegex(),O5=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,i0={_backpedal:R1,anyPunctuation:W3,autolink:N3,blockSkip:Z3,br:w5,code:t2,del:R1,delLDelim:R1,delRDelim:R1,emStrongLDelim:X3,emStrongRDelimAst:_3,emStrongRDelimUnd:G3,escape:s2,link:F3,nolink:V5,punctuation:e2,reflink:k5,reflinkSearch:L3,tag:O3,text:n2,url:R1},B3={...i0,link:l(/^!?\[(label)\]\((.*?)\)/).replace("label",K0).getRegex(),reflink:l(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",K0).getRegex()},x0={...i0,emStrongRDelimAst:z3,emStrongLDelim:q3,delLDelim:U3,delRDelim:H3,url:l(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol",O5).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:l(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace("protocol",O5).getRegex()},y3={...x0,br:l(w5).replace("{2,}","*").getRegex(),text:l(x0.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},U0={normal:r0,gfm:a2,pedantic:o2},o1={normal:i0,gfm:x0,breaks:y3,pedantic:B3},M3={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},F5=(J)=>M3[J];function K1(J,$){if($){if(Z1.escapeTest.test(J))return J.replace(Z1.escapeReplace,F5)}else if(Z1.escapeTestNoEncode.test(J))return J.replace(Z1.escapeReplaceNoEncode,F5);return J}function L5(J){try{J=encodeURI(J).replace(Z1.percentDecode,"%")}catch{return null}return J}function B5(J,$){let Y=J.replace(Z1.findPipe,(q,X,G)=>{let _=!1,z=X;for(;--z>=0&&G[z]==="\\";)_=!_;return _?"|":" |"}),Z=Y.split(Z1.splitPipe),Q=0;if(Z[0].trim()||Z.shift(),Z.length>0&&!Z.at(-1)?.trim()&&Z.pop(),$)if(Z.length>$)Z.splice($);else for(;Z.length<$;)Z.push("");for(;Q<Z.length;Q++)Z[Q]=Z[Q].trim().replace(Z1.slashPipe,"|");return Z}function s1(J,$,Y){let Z=J.length;if(Z===0)return"";let Q=0;for(;Q<Z;){let q=J.charAt(Z-Q-1);if(q===$&&!Y)Q++;else if(q!==$&&Y)Q++;else break}return J.slice(0,Z-Q)}function P3(J,$){if(J.indexOf($[1])===-1)return-1;let Y=0;for(let Z=0;Z<J.length;Z++)if(J[Z]==="\\")Z++;else if(J[Z]===$[0])Y++;else if(J[Z]===$[1]&&(Y--,Y<0))return Z;return Y>0?-2:-1}function S3(J,$=0){let Y=$,Z="";for(let Q of J)if(Q==="\t"){let q=4-Y%4;Z+=" ".repeat(q),Y+=q}else Z+=Q,Y++;return Z}function y5(J,$,Y,Z,Q){let q=$.href,X=$.title||null,G=J[1].replace(Q.other.outputLinkReplace,"$1");Z.state.inLink=!0;let _={type:J[0].charAt(0)==="!"?"image":"link",raw:Y,href:q,title:X,text:G,tokens:Z.inlineTokens(G)};return Z.state.inLink=!1,_}function b3(J,$,Y){let Z=J.match(Y.other.indentCodeCompensation);if(Z===null)return $;let Q=Z[1];return $.split(`
3
3
  `).map((q)=>{let X=q.match(Y.other.beginningSpace);if(X===null)return q;let[G]=X;return G.length>=Q.length?q.slice(Q.length):q}).join(`
4
4
  `)}var H0=class{options;rules;lexer;constructor(J){this.options=J||V1}space(J){let $=this.rules.block.newline.exec(J);if($&&$[0].length>0)return{type:"space",raw:$[0]}}code(J){let $=this.rules.block.code.exec(J);if($){let Y=$[0].replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:$[0],codeBlockStyle:"indented",text:this.options.pedantic?Y:s1(Y,`
@@ -56,7 +56,7 @@ ${this.parser.parse(J)}</blockquote>
56
56
  ${J}</tr>
57
57
  `}tablecell(J){let $=this.parser.parseInline(J.tokens),Y=J.header?"th":"td";return(J.align?`<${Y} align="${J.align}">`:`<${Y}>`)+$+`</${Y}>
58
58
  `}strong({tokens:J}){return`<strong>${this.parser.parseInline(J)}</strong>`}em({tokens:J}){return`<em>${this.parser.parseInline(J)}</em>`}codespan({text:J}){return`<code>${K1(J,!0)}</code>`}br(J){return"<br>"}del({tokens:J}){return`<del>${this.parser.parseInline(J)}</del>`}link({href:J,title:$,tokens:Y}){let Z=this.parser.parseInline(Y),Q=L5(J);if(Q===null)return Z;J=Q;let q='<a href="'+J+'"';return $&&(q+=' title="'+K1($)+'"'),q+=">"+Z+"</a>",q}image({href:J,title:$,text:Y,tokens:Z}){Z&&(Y=this.parser.parseInline(Z,this.parser.textRenderer));let Q=L5(J);if(Q===null)return K1(Y);J=Q;let q=`<img src="${J}" alt="${K1(Y)}"`;return $&&(q+=` title="${K1($)}"`),q+=">",q}text(J){return"tokens"in J&&J.tokens?this.parser.parseInline(J.tokens):("escaped"in J)&&J.escaped?J.text:K1(J.text)}},a0=class{strong({text:J}){return J}em({text:J}){return J}codespan({text:J}){return J}del({text:J}){return J}html({text:J}){return J}text({text:J}){return J}link({text:J}){return""+J}image({text:J}){return""+J}br(){return""}checkbox({raw:J}){return J}},G1=class J{options;renderer;textRenderer;constructor($){this.options=$||V1,this.options.renderer=this.options.renderer||new W0,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new a0}static parse($,Y){return new J(Y).parse($)}static parseInline($,Y){return new J(Y).parseInline($)}parse($){let Y="";for(let Z=0;Z<$.length;Z++){let Q=$[Z];if(this.options.extensions?.renderers?.[Q.type]){let X=Q,G=this.options.extensions.renderers[X.type].call({parser:this},X);if(G!==!1||!["space","hr","heading","code","table","blockquote","list","html","def","paragraph","text"].includes(X.type)){Y+=G||"";continue}}let q=Q;switch(q.type){case"space":{Y+=this.renderer.space(q);break}case"hr":{Y+=this.renderer.hr(q);break}case"heading":{Y+=this.renderer.heading(q);break}case"code":{Y+=this.renderer.code(q);break}case"table":{Y+=this.renderer.table(q);break}case"blockquote":{Y+=this.renderer.blockquote(q);break}case"list":{Y+=this.renderer.list(q);break}case"checkbox":{Y+=this.renderer.checkbox(q);break}case"html":{Y+=this.renderer.html(q);break}case"def":{Y+=this.renderer.def(q);break}case"paragraph":{Y+=this.renderer.paragraph(q);break}case"text":{Y+=this.renderer.text(q);break}default:{let X='Token with "'+q.type+'" type was not found.';if(this.options.silent)return console.error(X),"";throw Error(X)}}}return Y}parseInline($,Y=this.renderer){let Z="";for(let Q=0;Q<$.length;Q++){let q=$[Q];if(this.options.extensions?.renderers?.[q.type]){let G=this.options.extensions.renderers[q.type].call({parser:this},q);if(G!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(q.type)){Z+=G||"";continue}}let X=q;switch(X.type){case"escape":{Z+=Y.text(X);break}case"html":{Z+=Y.html(X);break}case"link":{Z+=Y.link(X);break}case"image":{Z+=Y.image(X);break}case"checkbox":{Z+=Y.checkbox(X);break}case"strong":{Z+=Y.strong(X);break}case"em":{Z+=Y.em(X);break}case"codespan":{Z+=Y.codespan(X);break}case"br":{Z+=Y.br(X);break}case"del":{Z+=Y.del(X);break}case"text":{Z+=Y.text(X);break}default:{let G='Token with "'+X.type+'" type was not found.';if(this.options.silent)return console.error(G),"";throw Error(G)}}}return Z}},t1=class{options;block;constructor(J){this.options=J||V1}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens","emStrongMask"]);static passThroughHooksRespectAsync=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(J){return J}postprocess(J){return J}processAllTokens(J){return J}emStrongMask(J){return J}provideLexer(){return this.block?z1.lex:z1.lexInline}provideParser(){return this.block?G1.parse:G1.parseInline}},w3=class{defaults=f0();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=G1;Renderer=W0;TextRenderer=a0;Lexer=z1;Tokenizer=H0;Hooks=t1;constructor(...J){this.use(...J)}walkTokens(J,$){let Y=[];for(let Z of J)switch(Y=Y.concat($.call(this,Z)),Z.type){case"table":{let Q=Z;for(let q of Q.header)Y=Y.concat(this.walkTokens(q.tokens,$));for(let q of Q.rows)for(let X of q)Y=Y.concat(this.walkTokens(X.tokens,$));break}case"list":{let Q=Z;Y=Y.concat(this.walkTokens(Q.items,$));break}default:{let Q=Z;this.defaults.extensions?.childTokens?.[Q.type]?this.defaults.extensions.childTokens[Q.type].forEach((q)=>{let X=Q[q].flat(1/0);Y=Y.concat(this.walkTokens(X,$))}):Q.tokens&&(Y=Y.concat(this.walkTokens(Q.tokens,$)))}}return Y}use(...J){let $=this.defaults.extensions||{renderers:{},childTokens:{}};return J.forEach((Y)=>{let Z={...Y};if(Z.async=this.defaults.async||Z.async||!1,Y.extensions&&(Y.extensions.forEach((Q)=>{if(!Q.name)throw Error("extension name required");if("renderer"in Q){let q=$.renderers[Q.name];q?$.renderers[Q.name]=function(...X){let G=Q.renderer.apply(this,X);return G===!1&&(G=q.apply(this,X)),G}:$.renderers[Q.name]=Q.renderer}if("tokenizer"in Q){if(!Q.level||Q.level!=="block"&&Q.level!=="inline")throw Error("extension level must be 'block' or 'inline'");let q=$[Q.level];q?q.unshift(Q.tokenizer):$[Q.level]=[Q.tokenizer],Q.start&&(Q.level==="block"?$.startBlock?$.startBlock.push(Q.start):$.startBlock=[Q.start]:Q.level==="inline"&&($.startInline?$.startInline.push(Q.start):$.startInline=[Q.start]))}"childTokens"in Q&&Q.childTokens&&($.childTokens[Q.name]=Q.childTokens)}),Z.extensions=$),Y.renderer){let Q=this.defaults.renderer||new W0(this.defaults);for(let q in Y.renderer){if(!(q in Q))throw Error(`renderer '${q}' does not exist`);if(["options","parser"].includes(q))continue;let X=q,G=Y.renderer[X],_=Q[X];Q[X]=(...z)=>{let H=G.apply(Q,z);return H===!1&&(H=_.apply(Q,z)),H||""}}Z.renderer=Q}if(Y.tokenizer){let Q=this.defaults.tokenizer||new H0(this.defaults);for(let q in Y.tokenizer){if(!(q in Q))throw Error(`tokenizer '${q}' does not exist`);if(["options","rules","lexer"].includes(q))continue;let X=q,G=Y.tokenizer[X],_=Q[X];Q[X]=(...z)=>{let H=G.apply(Q,z);return H===!1&&(H=_.apply(Q,z)),H}}Z.tokenizer=Q}if(Y.hooks){let Q=this.defaults.hooks||new t1;for(let q in Y.hooks){if(!(q in Q))throw Error(`hook '${q}' does not exist`);if(["options","block"].includes(q))continue;let X=q,G=Y.hooks[X],_=Q[X];t1.passThroughHooks.has(q)?Q[X]=(z)=>{if(this.defaults.async&&t1.passThroughHooksRespectAsync.has(q))return(async()=>{let U=await G.call(Q,z);return _.call(Q,U)})();let H=G.call(Q,z);return _.call(Q,H)}:Q[X]=(...z)=>{if(this.defaults.async)return(async()=>{let U=await G.apply(Q,z);return U===!1&&(U=await _.apply(Q,z)),U})();let H=G.apply(Q,z);return H===!1&&(H=_.apply(Q,z)),H}}Z.hooks=Q}if(Y.walkTokens){let Q=this.defaults.walkTokens,q=Y.walkTokens;Z.walkTokens=function(X){let G=[];return G.push(q.call(this,X)),Q&&(G=G.concat(Q.call(this,X))),G}}this.defaults={...this.defaults,...Z}}),this}setOptions(J){return this.defaults={...this.defaults,...J},this}lexer(J,$){return z1.lex(J,$??this.defaults)}parser(J,$){return G1.parse(J,$??this.defaults)}parseMarkdown(J){return($,Y)=>{let Z={...Y},Q={...this.defaults,...Z},q=this.onError(!!Q.silent,!!Q.async);if(this.defaults.async===!0&&Z.async===!1)return q(Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(typeof $>"u"||$===null)return q(Error("marked(): input parameter is undefined or null"));if(typeof $!="string")return q(Error("marked(): input parameter is of type "+Object.prototype.toString.call($)+", string expected"));if(Q.hooks&&(Q.hooks.options=Q,Q.hooks.block=J),Q.async)return(async()=>{let X=Q.hooks?await Q.hooks.preprocess($):$,G=await(Q.hooks?await Q.hooks.provideLexer():J?z1.lex:z1.lexInline)(X,Q),_=Q.hooks?await Q.hooks.processAllTokens(G):G;Q.walkTokens&&await Promise.all(this.walkTokens(_,Q.walkTokens));let z=await(Q.hooks?await Q.hooks.provideParser():J?G1.parse:G1.parseInline)(_,Q);return Q.hooks?await Q.hooks.postprocess(z):z})().catch(q);try{Q.hooks&&($=Q.hooks.preprocess($));let X=(Q.hooks?Q.hooks.provideLexer():J?z1.lex:z1.lexInline)($,Q);Q.hooks&&(X=Q.hooks.processAllTokens(X)),Q.walkTokens&&this.walkTokens(X,Q.walkTokens);let G=(Q.hooks?Q.hooks.provideParser():J?G1.parse:G1.parseInline)(X,Q);return Q.hooks&&(G=Q.hooks.postprocess(G)),G}catch(X){return q(X)}}}onError(J,$){return(Y)=>{if(Y.message+=`
59
- Please report this to https://github.com/markedjs/marked.`,J){let Z="<p>An error occurred:</p><pre>"+K1(Y.message+"",!0)+"</pre>";return $?Promise.resolve(Z):Z}if($)return Promise.reject(Y);throw Y}}},k1=new w3;function a(J,$){return k1.parse(J,$)}a.options=a.setOptions=function(J){return k1.setOptions(J),a.defaults=k1.defaults,M5(a.defaults),a};a.getDefaults=f0;a.defaults=V1;a.use=function(...J){return k1.use(...J),a.defaults=k1.defaults,M5(a.defaults),a};a.walkTokens=function(J,$){return k1.walkTokens(J,$)};a.parseInline=k1.parseInline;a.Parser=G1;a.parser=G1.parse;a.Renderer=W0;a.TextRenderer=a0;a.Lexer=z1;a.lexer=z1.lex;a.Tokenizer=H0;a.Hooks=t1;a.parse=a;var{options:w4,setOptions:A4,use:I4,walkTokens:C4,parseInline:j4}=a;var R4=G1.parse,k4=z1.lex;import{SessionContext as m2,ActiveViewCtx as B4}from"#canvas/runtime";import{useState as $0,useCallback as H1,useEffect as A3,useRef as I3}from"react";import{AnnotationCtx as C3}from"#canvas/runtime";var q1="__agent-response__";function U1(){return`ann-${Date.now()}-${Math.random().toString(36).slice(2,6)}`}function e1(J,$){J.style.height="auto",J.style.height=($?Math.max($,J.scrollHeight):J.scrollHeight)+"px"}import{useAnnotations as e}from"#canvas/runtime";import{jsxDEV as V3}from"react/jsx-dev-runtime";function o0(J,$){return`canvas:${J}:rev:${$}`}function O0(J,$){try{let Y=localStorage.getItem(o0(J,$));if(!Y)return null;return JSON.parse(Y)}catch{return null}}function j3(J,$,Y){try{localStorage.setItem(o0(J,$),JSON.stringify(Y))}catch{}}function R3(J,$){try{localStorage.removeItem(o0(J,$))}catch{}}function D5({sessionId:J,revision:$,isReadOnly:Y,children:Z}){let[Q,q]=$0(()=>{return O0(J,$)?.annotations??[]}),[X,G]=$0(()=>{return O0(J,$)?.generalNote??""}),[_,z]=$0(null),[H,U]=$0(()=>{let C=O0(J,$);return C?.responses?new Map(C.responses):new Map}),[W,N]=$0(()=>{let C=O0(J,$);return C?.feedbackEntries?new Map(C.feedbackEntries):new Map}),K=I3(null);A3(()=>{if(Y)return;if(K.current)clearTimeout(K.current);return K.current=setTimeout(()=>{j3(J,$,{annotations:Q,generalNote:X,responses:Array.from(H.entries()),feedbackEntries:Array.from(W.entries())})},300),()=>{if(K.current)clearTimeout(K.current)}},[Q,X,H,W,J,$,Y]);let T=H1((C,R,v,m,c,y,P)=>{q((x)=>[...x,{id:C,snippet:R,note:v,createdAt:new Date().toISOString(),filePath:m,context:c,...y?.length?{images:y}:{},...P?{canvasFile:P}:{}}])},[]),O=H1((C,R,v)=>{T(U1(),C,R,v)},[T]),S=H1((C,R)=>{q((v)=>v.map((m)=>m.id===C?{...m,note:R}:m))},[]),L=H1((C)=>{k3(C),q((R)=>R.filter((v)=>v.id!==C)),z((R)=>R===C?null:R)},[]),j=H1((C,R)=>{q((v)=>v.map((m)=>m.id===C?{...m,images:[...m.images||[],R]}:m))},[]),V=H1((C,R)=>{q((v)=>v.map((m)=>m.id===C?{...m,images:(m.images||[]).filter((c)=>c!==R)}:m))},[]),M=H1((C,R)=>{U((v)=>{let m=new Map(v);return m.set(C,R),m})},[]),I=H1((C,R)=>{N((v)=>{let m=v.get(C);if(m&&m.markdown===R.markdown&&m.label===R.label&&m.required===R.required)return v;let c=new Map(v);return c.set(C,R),c})},[]),D=H1((C)=>{N((R)=>{if(!R.has(C))return R;let v=new Map(R);return v.delete(C),v})},[]),E=H1(()=>{for(let C of document.querySelectorAll("[data-annotation-id]"))m5(C);q([]),G(""),z(null),U(new Map),N(new Map),R3(J,$)},[J,$]);return V3(C3.Provider,{value:{annotations:Q,addAnnotation:O,addAnnotationWithId:T,updateAnnotation:S,removeAnnotation:L,addAnnotationImage:j,removeAnnotationImage:V,generalNote:X,setGeneralNote:G,clearAll:E,activeAnnotationId:_,setActiveAnnotationId:z,responses:H,setResponse:M,feedbackEntries:W,setFeedbackEntry:I,removeFeedbackEntry:D},children:Z},void 0,!1,void 0,this)}function k3(J){let $=document.querySelectorAll(`[data-annotation-id="${J}"]`);for(let Y of $)m5(Y)}function m5(J){let $=J.parentNode;if(!$)return;let Y=document.createTextNode(J.textContent||"");$.replaceChild(Y,J),$.normalize()}import J5,{useEffect as x1,useState as W1,useRef as r3,useContext as l3,useMemo as J0}from"react";import{createPortal as i3}from"react-dom";import{SessionContext as a3,CanvasFileCtx as o3}from"#canvas/runtime";function D1(J,$){let Y=g5(J,"before",60),Z=g5(J,"after",60),Q=m3(J.startContainer,$);return{before:Y,after:Z,hierarchy:Q}}function g5(J,$,Y){let Z=D3($==="before"?J.startContainer:J.endContainer);if(!Z)return"";let Q="";if($==="before"){let q=document.createTreeWalker(Z,NodeFilter.SHOW_TEXT),X;while(X=q.nextNode()){if(X===J.startContainer){Q+=(X.textContent||"").slice(0,J.startOffset);break}if(X.parentElement?.hasAttribute("data-annotation-id"))continue;Q+=X.textContent||""}if(Q.length>Y){Q=Q.slice(-Y);let G=Q.indexOf(" ");if(G>0)Q=Q.slice(G+1)}}else{let q=document.createTreeWalker(Z,NodeFilter.SHOW_TEXT),X=!1,G;while(G=q.nextNode()){if(G===J.endContainer){Q+=(G.textContent||"").slice(J.endOffset),X=!0;continue}if(X){if(G.parentElement?.hasAttribute("data-annotation-id"))continue;Q+=G.textContent||""}}if(Q.length>Y){Q=Q.slice(0,Y);let _=Q.lastIndexOf(" ");if(_>0)Q=Q.slice(0,_)}}return Q.trim()}function D3(J){let $=new Set(["DIV","P","LI","PRE","BLOCKQUOTE","SECTION","ARTICLE"]),Y=J.parentElement;while(Y){if($.has(Y.tagName))return Y;Y=Y.parentElement}return null}function m3(J,$){let Y=[],Z=J instanceof Element?J:J.parentElement;while(Z&&Z!==$){let Q=Z.getAttribute?.("data-task-id");if(Q){let q=Z.querySelector(".font-semibold");if(q)Y.unshift(q.textContent?.trim()||Q)}if(Z.tagName==="DIV"&&Z.querySelector(":scope > button .font-heading, :scope > div .font-heading")){let q=Z.querySelector(".font-heading");if(q)Y.unshift(q.textContent?.trim()||"")}Z=Z.parentElement}return Y}function s0(J){let $=J.snippet.trim(),Y=J.context,Z=$.length<30;if(Y&&Z&&(Y.before||Y.after)){let Q=[];if(Y.before)Q.push(`...${Y.before} `);if(Q.push(`**${$}**`),Y.after)Q.push(` ${Y.after}...`);return Q.join("")}return $}import{useEffect as E3,useRef as B0,useState as p1,useCallback as L0,useMemo as x5,useContext as v3}from"react";import{createPortal as x3}from"react-dom";function u5(J,$){let Q=$||document.body,q=J.getBoundingClientRect(),X=Q.getBoundingClientRect(),G=Q===document.body?window.scrollY:Q.scrollTop,_=q.bottom-X.top+G+8,z=Math.max(0,Math.min(q.left-X.left,X.width-280-12));return Q.style.position="relative",{style:{position:"absolute",top:`${_}px`,left:`${z}px`},parent:Q}}import{useState as t0,useRef as n0,useCallback as O1,useEffect as g3}from"react";import{jsxDEV as J1}from"react/jsx-dev-runtime";function E5(J){return`/api/uploads/${J.split("/").pop()}`}async function u3(J,$){let Y=new FormData;Y.append("image",$);try{return(await(await fetch(`/api/session/${J}/upload`,{method:"POST",body:Y})).json()).path||null}catch{return null}}function F0({note:J,onNoteChange:$,images:Y,onAddImage:Z,onRemoveImage:Q,sessionId:q,placeholder:X="Add your note...",autoFocus:G=!1,autoResize:_=!1,readOnly:z=!1,onKeyDown:H,onTextareaClick:U,textareaRef:W,textareaClassName:N,textareaStyle:K,minHeight:T,attachButton:O="always",openFilePickerRef:S}){let[L,j]=t0(!1),[V,M]=t0(!1),[I,D]=t0(!1),E=n0(0),C=n0(null),R=n0(null),v=O1(()=>R.current?.click(),[]);if(S)S.current=v;let m=O1((k)=>{if(C.current=k,W)W.current=k;if(k&&_)e1(k,T)},[W,_,T]);g3(()=>{if(G&&C.current){let k=C.current;if(k.focus(),k.value)k.setSelectionRange(k.value.length,k.value.length)}},[G]);let c=O1(async(k)=>{if(!k.type.startsWith("image/"))return;M(!0);try{let r=await u3(q,k);if(r)Z(r)}finally{M(!1)}},[q,Z]),y=O1((k)=>{let r=k.clipboardData.items;for(let A of r)if(A.type.startsWith("image/")){k.preventDefault();let u=A.getAsFile();if(u)c(u);return}},[c]),P=O1((k)=>{if(k.preventDefault(),E.current++,E.current===1)j(!0)},[]),x=O1((k)=>{k.preventDefault()},[]),p=O1((k)=>{if(k.preventDefault(),E.current--,E.current===0)j(!1)},[]),B=O1((k)=>{k.preventDefault(),E.current=0,j(!1);for(let r of k.dataTransfer.files)if(r.type.startsWith("image/"))c(r)},[c]),b=O1((k)=>{if($(k.target.value),_)k.target.style.height="auto",k.target.style.height=(T?Math.max(T,k.target.scrollHeight):k.target.scrollHeight)+"px"},[$,_,T]),g="w-full bg-transparent text-[13px] font-body text-text-primary resize-none focus:outline-none leading-relaxed p-0 border-none",o={width:"100%",background:"transparent",border:"none",color:"var(--color-text-primary)",fontFamily:"'Inter', sans-serif",fontSize:"13px",lineHeight:"1.5",outline:"none",..._?{resize:"none",overflow:"hidden"}:{resize:"vertical"}},i=!z&&(O==="always"||O==="on-focus"&&I);return J1("div",{style:{position:"relative"},onDragEnter:z?void 0:P,onDragOver:z?void 0:x,onDragLeave:z?void 0:p,onDrop:z?void 0:B,children:[J1("textarea",{ref:m,value:J,onChange:z?void 0:b,onPaste:z?void 0:y,onKeyDown:H,onClick:U,onFocus:()=>D(!0),onBlur:()=>{setTimeout(()=>D(!1),150)},readOnly:z,placeholder:X,className:N??g,style:K??o,rows:_?1:void 0},void 0,!1,void 0,this),!z&&J1("input",{ref:R,type:"file",accept:"image/*",multiple:!0,style:{display:"none"},onChange:(k)=>{let r=k.target.files;if(r)for(let A of r)c(A);k.target.value=""}},void 0,!1,void 0,this),(Y.length>0||i)&&J1("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"6px",alignItems:"center"},children:[Y.map((k)=>J1("div",{style:{position:"relative",width:"56px",height:"56px",borderRadius:"6px",overflow:"hidden",border:"1px solid var(--color-border-subtle)",flexShrink:0},children:[J1("img",{src:E5(k),alt:"",style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}},void 0,!1,void 0,this),!z&&J1("button",{onClick:(r)=>{r.stopPropagation(),Q(k)},style:{position:"absolute",top:"2px",right:"2px",width:"16px",height:"16px",borderRadius:"50%",background:"rgba(0,0,0,0.6)",color:"white",border:"none",cursor:"pointer",fontSize:"11px",display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1,padding:0},title:"Remove image",children:"×"},void 0,!1,void 0,this)]},k,!0,void 0,this)),i&&J1(e0,{onClick:v},void 0,!1,void 0,this)]},void 0,!0,void 0,this),V&&J1("div",{style:{fontSize:"11px",color:"var(--color-text-tertiary)",fontFamily:"'Inter', sans-serif",marginTop:"4px"},children:"Uploading..."},void 0,!1,void 0,this),L&&J1("div",{style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",background:"var(--color-highlight-bg)",opacity:0.9,border:"2px dashed var(--color-highlight-border)",borderRadius:"6px",zIndex:10,pointerEvents:"none",fontSize:"12px",fontFamily:"'Inter', sans-serif",color:"var(--color-text-secondary)"},children:"Drop image"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function e0({onClick:J,size:$=16}){return J1("button",{onClick:(Y)=>{Y.stopPropagation(),J()},style:{width:`${$*2}px`,height:`${$*2}px`,borderRadius:"6px",border:"none",background:"transparent",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--color-text-tertiary)",flexShrink:0,transition:"color 0.15s"},title:"Attach image",onMouseEnter:(Y)=>{Y.currentTarget.style.color="var(--color-text-secondary)"},onMouseLeave:(Y)=>{Y.currentTarget.style.color="var(--color-text-tertiary)"},children:J1("svg",{width:$,height:$,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[J1("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"},void 0,!1,void 0,this),J1("circle",{cx:"8.5",cy:"8.5",r:"1.5"},void 0,!1,void 0,this),J1("polyline",{points:"21 15 16 10 5 21"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function v5({images:J}){if(!J.length)return null;return J1("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"6px"},children:J.map(($)=>J1("div",{style:{width:"56px",height:"56px",borderRadius:"6px",overflow:"hidden",border:"1px solid var(--color-border-subtle)",flexShrink:0},children:J1("img",{src:E5($),alt:"",style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}},void 0,!1,void 0,this)},$,!1,void 0,this))},void 0,!1,void 0,this)}import{SessionContext as f3}from"#canvas/runtime";import{jsxDEV as Y1,Fragment as p3}from"react/jsx-dev-runtime";function h3({anchorEl:J,scrollContainer:$,onClose:Y,ignoreSelector:Z,zIndex:Q="50",padding:q="12px",width:X="280px",children:G}){let _=B0(null),z=B0(Y);z.current=Y;let{style:H,parent:U}=u5(J,$);return E3(()=>{let W=setTimeout(()=>{let N=(K)=>{if(_.current&&!_.current.contains(K.target)){if(Z&&K.target.closest?.(Z))return;z.current(),document.removeEventListener("mousedown",N)}};return document.addEventListener("mousedown",N),()=>document.removeEventListener("mousedown",N)},0);return()=>clearTimeout(W)},[Z]),x3(Y1("div",{ref:_,style:{...H,zIndex:Q,width:X,background:"var(--color-bg-elevated)",border:"1px solid var(--color-border-hover)",borderRadius:"8px",boxShadow:"0 4px 12px var(--color-shadow)",padding:q,fontFamily:"'Inter', sans-serif"},children:G},void 0,!1,void 0,this),U)}var h5=[{label:"Clarity",items:["Unclear","Why?","Needs example","Missing context"]},{label:"Scope",items:["Overkill","Out of scope","Important","Risky"]},{label:"Action",items:["Simplify","Rethink","Expand on this","Skip this"]}],f5=h5.flatMap((J)=>J.items);function p5({anchorEl:J,scrollContainer:$,snippet:Y,truncateAt:Z=100,header:Q,initialNote:q="",initialImages:X,onConfirm:G,onCancel:_,onDelete:z}){let H=v3(f3),U=q!==""||!!z,[W,N]=p1(q),[K,T]=p1(X||[]),[O,S]=p1(null),[L,j]=p1(U),[V,M]=p1(!1),I=B0(null),D=B0(null),E=L0(()=>{if(W.trim()||K.length>0)G(W.trim(),K);else if(U&&z)z();else _()},[W,K,G,_,U,z]),C=L0(()=>{if(U){if(!W.trim()&&K.length===0&&z){z(),_();return}G(W,K);return}_()},[W,K,U,G,_,z]),R=!U,v=W.trim().length>0?f5.filter((A)=>A.toLowerCase().startsWith(W.trim().toLowerCase())):f5,m=!R||L?[]:v.length===1&&v[0].toLowerCase()===W.trim().toLowerCase()?[]:v,c=new Set(m),y=h5.map((A)=>({label:A.label,items:A.items.filter((u)=>c.has(u))})).filter((A)=>A.items.length>0),P=y.map((A)=>A.items),x=P.flat(),p=x5(()=>{if(O===null)return 0;let A=0;for(let u=0;u<P.length;u++){if(O<A+P[u].length)return u;A+=P[u].length}return 0},[O,P]),B=x5(()=>{if(O===null)return 0;let A=0;for(let u=0;u<p;u++)A+=P[u].length;return O-A},[O,p,P]),b=(A,u)=>{let s=0;for(let _1=0;_1<A;_1++)s+=P[_1].length;return s+u},[g,o]=p1(W);if(W!==g)o(W),S(null),j(U);let i=L0((A)=>{N(A)},[]),k=Y.length>Z?Y.slice(0,Z)+"...":Y,r=L0((A)=>{if(x.length>0&&(A.key==="ArrowDown"||A.key==="ArrowUp"||A.key==="ArrowLeft"||A.key==="ArrowRight")){if(A.preventDefault(),O===null){S(0);return}if(A.key==="ArrowDown"){let u=Math.min(B+1,P[p].length-1);S(b(p,u))}else if(A.key==="ArrowUp"){let u=Math.max(B-1,0);S(b(p,u))}else if(A.key==="ArrowRight"){let u=Math.min(p+1,P.length-1),s=Math.min(B,P[u].length-1);S(b(u,s))}else if(A.key==="ArrowLeft"){let u=Math.max(p-1,0),s=Math.min(B,P[u].length-1);S(b(u,s))}return}if(O!==null&&x.length>0){if(A.key==="Tab"){A.preventDefault(),i(x[O]);return}if(A.key==="Enter"&&!A.shiftKey){A.preventDefault(),G(x[O],K);return}}if(A.key==="Enter"&&!A.shiftKey){A.preventDefault(),E();return}if(A.key==="Escape")if(x.length>0&&!L)j(!0);else if(U)C();else _()},[x,O,B,p,P,b,i,G,K,E,L,U,C,_]);return Y1(h3,{anchorEl:J,scrollContainer:$,onClose:U?C:_,ignoreSelector:U?"[data-annotation-id]":void 0,zIndex:U?"60":"50",padding:U?"10px 12px":"12px",width:"420px",children:[!U&&(Q??Y1("div",{style:{fontSize:"11px",color:"var(--color-text-tertiary)",fontStyle:"italic",marginBottom:"8px",lineHeight:"1.4",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden"},children:["“",k,"”"]},void 0,!0,void 0,this)),Y1(F0,{note:W,onNoteChange:N,images:K,onAddImage:(A)=>T((u)=>[...u,A]),onRemoveImage:(A)=>T((u)=>u.filter((s)=>s!==A)),sessionId:H,autoFocus:!0,autoResize:U,textareaRef:I,onKeyDown:r,attachButton:"none",openFilePickerRef:D,textareaStyle:U?{width:"100%",background:"transparent",border:"none",color:"var(--color-text-primary)",fontFamily:"'Inter', sans-serif",fontSize:"13px",lineHeight:"1.5",resize:"none",outline:"none",overflow:"hidden"}:{width:"100%",minHeight:"60px",background:"transparent",border:"none",color:"var(--color-text-primary)",fontFamily:"'Inter', sans-serif",fontSize:"13px",lineHeight:"1.5",resize:"vertical",outline:"none"},placeholder:"Add your note..."},void 0,!1,void 0,this),Y1("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginTop:U?"6px":"8px"},children:[Y1(e0,{onClick:()=>D.current?.(),size:14},void 0,!1,void 0,this),Y1("div",{style:{flex:1}},void 0,!1,void 0,this),U?Y1("button",{onClick:()=>{if(z)z();_()},onMouseEnter:()=>M(!0),onMouseLeave:()=>M(!1),style:{fontSize:"11px",color:V?"var(--color-accent-red)":"var(--color-text-tertiary)",background:"none",border:"none",cursor:"pointer",padding:"2px 0",fontFamily:"'Inter', sans-serif"},children:"Delete"},void 0,!1,void 0,this):Y1(p3,{children:[Y1("button",{onClick:_,style:{fontSize:"11px",color:"var(--color-text-tertiary)",background:"none",border:"none",cursor:"pointer",padding:"4px 12px",fontFamily:"'Inter', sans-serif"},children:"Cancel"},void 0,!1,void 0,this),Y1("button",{onClick:E,style:{fontSize:"11px",fontWeight:500,padding:"4px 12px",borderRadius:"6px",background:"var(--color-highlight-bg)",color:"var(--color-text-primary)",border:"1px solid var(--color-highlight-border)",cursor:"pointer",fontFamily:"'Inter', sans-serif"},children:"Add"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),x.length>0&&Y1("div",{style:{marginTop:"6px",borderTop:"1px solid var(--color-border-subtle)",paddingTop:"8px",display:"flex",gap:"4px"},children:y.map((A)=>Y1("div",{style:{flex:1},children:[Y1("div",{style:{fontSize:"10px",fontWeight:600,color:"var(--color-text-disabled)",textTransform:"uppercase",letterSpacing:"0.05em",padding:"2px 6px",marginBottom:"2px",fontFamily:"'Inter', sans-serif"},children:A.label},void 0,!1,void 0,this),A.items.map((u)=>{let s=x.indexOf(u);return Y1("div",{onMouseDown:(_1)=>{_1.preventDefault(),_1.stopPropagation(),i(u)},onMouseEnter:()=>S(s),style:{padding:"3px 6px",fontSize:"12px",borderRadius:"4px",fontFamily:"'Inter', sans-serif",color:s===O?"var(--color-text-primary)":"var(--color-text-secondary)",background:s===O?"var(--color-highlight-selected)":"transparent",cursor:"pointer"},children:[Y1("span",{style:{fontWeight:500},children:u.slice(0,W.trim().length)},void 0,!1,void 0,this),u.slice(W.trim().length)]},u,!0,void 0,this)})]},A.label,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function c1({anchorEl:J,scrollContainer:$,snippet:Y,truncateAt:Z,header:Q,onAdd:q,onCancel:X}){return Y1(p5,{anchorEl:J,scrollContainer:$,snippet:Y,truncateAt:Z,header:Q,onConfirm:(G,_)=>q(G,_),onCancel:X},void 0,!1,void 0,this)}function d1({anchorEl:J,scrollContainer:$,initialNote:Y,initialImages:Z,onUpdate:Q,onDelete:q,onClose:X}){return Y1(p5,{anchorEl:J,scrollContainer:$,snippet:"",initialNote:Y,initialImages:Z,onConfirm:(G,_)=>{Q(G,_),X()},onDelete:q,onCancel:X},void 0,!1,void 0,this)}import{useEffect as b0,useState as d5,useRef as u1,useCallback as r5}from"react";function g1(J,$){let Y=[],Z=c3(J);for(let Q of Z){let q=document.createRange();if(q.selectNodeContents(Q),Q===J.startContainer)q.setStart(Q,J.startOffset);if(Q===J.endContainer)q.setEnd(Q,J.endOffset);let X=q.toString();if(!X||!X.trim())continue;let G=document.createElement("mark");G.setAttribute("data-annotation-id",$);try{q.surroundContents(G)}catch{let _=q.extractContents();G.appendChild(_),q.insertNode(G)}Y.push(G)}return Y}function c3(J){let $=[],Y=J.commonAncestorContainer;if(Y.nodeType===Node.TEXT_NODE)return $.push(Y),$;let Z=document.createTreeWalker(Y,NodeFilter.SHOW_TEXT),Q;while(Q=Z.nextNode()){if(Q.parentElement?.classList.contains("select-none"))continue;if(J.intersectsNode(Q))$.push(Q)}return $}function m1(J,$){let Y=document.querySelectorAll(`[data-annotation-id="${J}"]`);for(let Z of Y)Z.classList.toggle("mark-active",$)}function y0(J,$){if($!=null&&$!==J)m1($,!1);if(J!=null)m1(J,!0)}function M0(J,$){let Y=document.querySelectorAll(`[data-annotation-id="${J}"]`);for(let Z of Y)Z.setAttribute("data-annotation-id",$)}function P0(J,$){let Y=$.filter((G)=>!document.querySelector(`[data-annotation-id="${G.id}"]`));if(!Y.length)return;let Z=[],Q="",q=document.createTreeWalker(J,NodeFilter.SHOW_TEXT),X;while(X=q.nextNode()){if(X.parentElement?.classList.contains("select-none"))continue;Z.push({node:X,start:Q.length}),Q+=X.textContent||""}for(let G of Y){let _=G.snippet;if(!_)continue;let z=[],H=0;while(!0){let O=Q.indexOf(_,H);if(O===-1)break;z.push(O),H=O+1}if(z.length===0)continue;let U=z[0];if(z.length>1&&G.context){let O=-1;for(let S of z){let L=0;if(G.context.before){let j=Q.slice(Math.max(0,S-80),S);if(j.includes(G.context.before))L+=2;else if(G.context.before.length>10&&j.includes(G.context.before.slice(-10)))L+=1}if(G.context.after){let j=Q.slice(S+_.length,S+_.length+80);if(j.includes(G.context.after))L+=2;else if(G.context.after.length>10&&j.includes(G.context.after.slice(0,10)))L+=1}if(L>O)O=L,U=S}}let W=U,N=U+_.length,K=c5(Z,W),T=c5(Z,N);if(!K||!T)continue;try{let O=document.createRange();O.setStart(K.node,K.offset),O.setEnd(T.node,T.offset),g1(O,G.id)}catch{}}}function c5(J,$){for(let Y=J.length-1;Y>=0;Y--)if(J[Y].start<=$){let Z=$-J[Y].start,Q=J[Y].node.textContent?.length??0;if(Z<=Q)return{node:J[Y].node,offset:Z}}return null}function S0(J){let $=document.querySelectorAll(`[data-annotation-id="${J}"]`);for(let Y of $){let Z=Y.parentNode;if(!Z)continue;while(Y.firstChild)Z.insertBefore(Y.firstChild,Y);Z.removeChild(Y),Z.normalize()}}import{jsxDEV as $5,Fragment as d3}from"react/jsx-dev-runtime";function E1(J){let{containerRef:$,restoreKey:Y,restoreAnnotations:Z,extractContext:Q,filePath:q,canvasFile:X,scrollContainer:G}=J,{annotations:_,addAnnotationWithId:z,removeAnnotation:H,updateAnnotation:U,addAnnotationImage:W,removeAnnotationImage:N,activeAnnotationId:K,setActiveAnnotationId:T}=e(),[O,S]=d5(null),[L,j]=d5(null),V=u1(Q);V.current=Q;let M=u1(q);M.current=q;let I=u1(X);I.current=X;let D=u1(z);D.current=z;let E=u1(K);E.current=K;let C=u1(T);C.current=T,b0(()=>{if(!$.current)return;let y=setTimeout(()=>{if($.current)P0($.current,Z)},50);return()=>clearTimeout(y)},[Y]);let R=u1(null);b0(()=>{y0(K,R.current),R.current=K},[K]),b0(()=>{let y=$.current;if(!y)return;let P=(B)=>{let b=B.target.closest("[data-annotation-id]");if(!b)return;B.stopPropagation();let g=b.getAttribute("data-annotation-id");if(g===E.current)S({anchorEl:b,annId:g});else C.current(g)},x=(B)=>{let b=B.target.closest("[data-annotation-id]");if(b)C.current(b.getAttribute("data-annotation-id"))},p=(B)=>{let b=B.target.closest("[data-annotation-id]"),g=B.relatedTarget?.closest?.("[data-annotation-id]");if(b&&!g&&!document.getElementById("ann-inline-popover"))C.current(null)};return y.addEventListener("click",P),y.addEventListener("mouseover",x),y.addEventListener("mouseout",p),()=>{y.removeEventListener("click",P),y.removeEventListener("mouseover",x),y.removeEventListener("mouseout",p)}},[Y]),b0(()=>{let y=()=>v();return document.addEventListener("mouseup",y),()=>document.removeEventListener("mouseup",y)},[]);let v=r5(()=>{let y=window.getSelection();if(!y||y.isCollapsed||!y.toString().trim())return;if(!$.current)return;let P=y.getRangeAt(0);if(!$.current.contains(P.startContainer))return;if(P.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let x=y.toString().trim();if(x.length<2)return;let p=V.current(P),B=P.cloneRange(),b=`__pending_${Date.now()}`;try{g1(B,b)}catch{}window.getSelection()?.removeAllRanges();let g=document.querySelectorAll(`[data-annotation-id="${b}"]`),o=g[g.length-1];if(!o)return;j({anchorEl:o,tempId:b,snippet:x,ctx:p})},[]),m=r5((y,P,x,p)=>{j({anchorEl:y,tempId:P,snippet:x,ctx:p})},[]);return{popovers:$5(d3,{children:[O&&(()=>{let y=_.find((P)=>P.id===O.annId);if(!y)return null;return $5(d1,{anchorEl:O.anchorEl,scrollContainer:G,initialNote:y.note,initialImages:y.images,onUpdate:(P,x)=>{U(O.annId,P);let p=y.images||[];for(let B of x)if(!p.includes(B))W(O.annId,B);for(let B of p)if(!x.includes(B))N(O.annId,B)},onDelete:()=>{H(O.annId),T(null)},onClose:()=>S(null)},void 0,!1,void 0,this)})(),L&&$5(c1,{anchorEl:L.anchorEl,scrollContainer:G,snippet:L.snippet,truncateAt:80,onAdd:(y,P)=>{let x=U1();M0(L.tempId,x),D.current(x,L.snippet,y,M.current,L.ctx,P,I.current),j(null)},onCancel:()=>{S0(L.tempId),j(null)}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),openCreatePopover:m,isPopoverOpen:!!(O||L)}}import{jsxDEV as t,Fragment as e3}from"react/jsx-dev-runtime";var Q5="[data-md='item'], [data-md='section'], [data-md='table'] tbody tr, [data-md='callout'], [data-md='note'], [data-md='checklist-item'], [data-md='choice-option'], [data-md='multichoice-option'], [data-md='userinput'], [data-md='rangeinput'], [data-md='image']",Y5="[data-md='item'], [data-md='section'], [data-md='table'] tbody tr, [data-md='callout'], [data-md='note'], [data-md='checklist-item'], [data-md='image']";function Y0({revision:J,filename:$}){let Y=l3(a3),[Z,Q]=W1(null),[q,X]=W1(null),[G,_]=W1(!0),z=r3(null),{annotations:H,addAnnotationWithId:U,removeAnnotation:W,updateAnnotation:N,addAnnotationImage:K,removeAnnotationImage:T,activeAnnotationId:O,setActiveAnnotationId:S}=e(),L=J0(()=>H.filter((B)=>!B.filePath&&(!B.canvasFile||B.canvasFile===$)),[H,$]),[j,V]=W1(null),[M,I]=W1(null),[D,E]=W1(null),[C,R]=W1(null),[v,m]=W1(!1);x1(()=>{_(!0),X(null),R(null);let B=$.replace(/\.jsx$/,".js");import(`/api/session/${Y}/canvas/${encodeURIComponent(B)}?rev=${J}&t=${Date.now()}`).then((b)=>{Q(()=>b.default),_(!1)}).catch((b)=>{X(b.message),_(!1)})},[Y,J,$]);let c=document.getElementById("plan-scroll-container"),{popovers:y,isPopoverOpen:P}=E1({containerRef:z,restoreKey:Z,restoreAnnotations:L,extractContext:(B)=>D1(B,z.current),canvasFile:$,scrollContainer:c}),x=J0(()=>{let B=new Map;for(let b of L)if(b.snippet.startsWith("["))B.set(b.snippet,b.id);return B},[L]);x1(()=>{let B=z.current;if(!B)return;let b=(o)=>{if(D||P)return;let i=o.target;if(i.closest("[data-block-comment-btn]"))return;m(!1);let k=i.closest(Q5);if(k&&B.contains(k)){let u=v1(B).indexOf(k);R(u>=0?u:null)}else R(null);let r=i.closest(Y5);if(r&&B.contains(r)){I(r);let A=r1(r),u=A?x.get(A):void 0;if(u&&u!==O)S(u)}else I(null)},g=(o)=>{if(D||P)return;if(o.relatedTarget?.closest("[data-block-comment-btn]"))return;I(null),S(null)};return B.addEventListener("mousemove",b),B.addEventListener("mouseleave",g),()=>{B.removeEventListener("mousemove",b),B.removeEventListener("mouseleave",g)}},[Z,D,P,x,O]),x1(()=>{let B=(b)=>{let g=b.target.tagName;if(g==="INPUT"||g==="TEXTAREA"||b.target.isContentEditable)return;if(D||P)return;let o=z.current;if(!o)return;if(b.key==="ArrowDown"){b.preventDefault(),m(!0);let i=v1(o);if(i.length===0)return;R((k)=>{if(k===null)return 0;return Math.min(k+1,i.length-1)})}else if(b.key==="ArrowUp"){b.preventDefault(),m(!0);let i=v1(o);if(i.length===0)return;R((k)=>{if(k===null)return i.length-1;return Math.max(k-1,0)})}else if(b.key==="a"||b.key==="A"){if(C===null||!o)return;b.preventDefault();let k=v1(o)[C];if(!k)return;let r=r1(k);if(!r)return;let A=x.get(r);if(A)S(A),E({anchorEl:k,snippet:r,annId:A});else E({anchorEl:k,snippet:r})}else if(b.key===" "||b.key==="Enter"){if(C===null)return;let k=v1(o)[C];if(!k)return;let r=k.getAttribute("data-md");if(r==="choice-option"||r==="multichoice-option")b.preventDefault(),k.dispatchEvent(new CustomEvent("kb-select",{bubbles:!0}));else if(r==="userinput"){b.preventDefault();let A=k.querySelector("textarea");if(A){A.focus();let u=(s)=>{if(s.key==="Escape")s.preventDefault(),A.blur(),m(!0)};A.addEventListener("keydown",u),A.addEventListener("blur",()=>A.removeEventListener("keydown",u),{once:!0})}}else if(r==="rangeinput"){b.preventDefault();let A=k.querySelector("input[type='range']");if(A){A.focus();let u=(s)=>{if(s.key==="Escape"||s.key==="ArrowUp"||s.key==="ArrowDown")s.preventDefault(),A.blur(),m(!0)};A.addEventListener("keydown",u),A.addEventListener("blur",()=>A.removeEventListener("keydown",u),{once:!0})}}}else if(b.key==="Escape")R(null),m(!1),S(null)};return document.addEventListener("keydown",B),()=>document.removeEventListener("keydown",B)},[C,D,P,x]),x1(()=>{let B=z.current;if(!B||C===null||!v)return;let g=v1(B)[C];if(!g)return;g.style.outline="2px solid var(--color-accent-blue)",g.style.outlineOffset="-2px",g.style.borderRadius="8px",g.scrollIntoView({block:"nearest",behavior:"smooth"});let o=r1(g),i=o?x.get(o):void 0;if(i)S(i);return()=>{g.style.outline="",g.style.outlineOffset="",g.style.borderRadius=""}},[C,v,x]);let p=J0(()=>Z?t(Z,{},void 0,!1,void 0,this):null,[Z]);if(G)return t("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-body",children:"Loading canvas..."},void 0,!1,void 0,this);if(q)return t("div",{className:"bg-accent-red-muted rounded-lg p-5",children:[t("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Compilation Error"},void 0,!1,void 0,this),t("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:q},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(!Z)return t("div",{className:"text-text-tertiary text-center py-8 font-body text-body",children:"No canvas loaded"},void 0,!1,void 0,this);return t(o3.Provider,{value:$,children:[t("div",{ref:z,className:"plan-content plan-updated",children:p},void 0,!1,void 0,this),j&&t(n3,{note:j.note,onSave:(B)=>{N(j.id,B),V(null)},onCancel:()=>V(null)},void 0,!1,void 0,this),y,t(s3,{containerRef:z,hoveredBlock:M,focusedBlockIndex:C,blockPopover:D,blockAnnotationMap:x,activeAnnotationId:O,onOpen:(B,b,g)=>{if(g)S(g),E({anchorEl:B,snippet:b,annId:g});else E({anchorEl:B,snippet:b})}},void 0,!1,void 0,this),D&&!D.annId&&t(c1,{anchorEl:D.anchorEl,scrollContainer:c,snippet:D.snippet,truncateAt:80,onAdd:(B,b)=>{let g=U1();U(g,D.snippet,B,void 0,void 0,b,$),E(null)},onCancel:()=>E(null)},void 0,!1,void 0,this),D?.annId&&(()=>{let B=L.find((b)=>b.id===D.annId);if(!B)return null;return t(d1,{anchorEl:D.anchorEl,scrollContainer:c,initialNote:B.note,initialImages:B.images,onUpdate:(b,g)=>{N(D.annId,b);let o=B.images||[];for(let i of g)if(!o.includes(i))K(D.annId,i);for(let i of o)if(!g.includes(i))T(D.annId,i)},onDelete:()=>{W(D.annId),S(null),E(null)},onClose:()=>E(null)},void 0,!1,void 0,this)})()]},void 0,!0,void 0,this)}function v1(J){return Array.from(J.querySelectorAll(Q5))}function r1(J){let $=J.getAttribute("data-md");if($==="item"){let Y=J.getAttribute("data-md-label");return Y?`[Item] ${Y}`:null}if($==="section"){let Y=J.getAttribute("data-md-title");return Y?`[Section] ${Y}`:null}if($==="callout"){let Y=J.getAttribute("data-md-type")||"info",Z=J.textContent?.trim().slice(0,60)||"Callout";return`[Callout:${Y}] ${Z}`}if($==="note")return`[Note] ${J.textContent?.trim().slice(0,60)||"Note"}`;if(J.tagName==="TR"){let Y=Array.from(J.querySelectorAll("td")).map((Z)=>Z.textContent?.trim()).filter(Boolean);return Y.length?`[Row] ${Y.join(" | ")}`:null}if($==="checklist-item"){let Y=J.getAttribute("data-md-label");return Y?`[Checklist] ${Y}`:null}if($==="choice-option"||$==="multichoice-option"){let Y=J.getAttribute("data-md-label");return Y?`[Option] ${Y}`:null}if($==="userinput"){let Y=J.getAttribute("data-md-label");return Y?`[Input] ${Y}`:null}if($==="rangeinput"){let Y=J.getAttribute("data-md-label");return Y?`[Range] ${Y}`:null}if($==="image"){let Y=J.getAttribute("data-md-src");return Y?`[Image] ${Y}`:null}return null}function s3({containerRef:J,hoveredBlock:$,focusedBlockIndex:Y,blockPopover:Z,blockAnnotationMap:Q,activeAnnotationId:q,onOpen:X}){let[G,_]=W1([]);x1(()=>{let N=J.current;if(!N||Q.size===0){_([]);return}let K=[];for(let T of N.querySelectorAll(Y5)){let O=r1(T);if(O&&Q.has(O))K.push(T)}_(K)},[Q,J.current]);let[z,H]=W1(null);x1(()=>{if(!q||!J.current){H(null);return}for(let N of J.current.querySelectorAll(Q5)){let K=r1(N);if(K&&Q.get(K)===q){H(N);return}}H(null)},[q,Q]),x1(()=>{if(!z)return;return z.style.boxShadow="inset 0 0 0 1.5px var(--color-highlight-bg)",z.style.borderRadius="8px",()=>{z.style.boxShadow="",z.style.borderRadius=""}},[z]);let U=J0(()=>{if(Y===null||!J.current)return null;let N=v1(J.current)[Y];if(!N)return null;return N.matches(Y5)?N:null},[Y,J.current]),W=J0(()=>{let N=new Set(G);if($)N.add($);if(U)N.add(U);if(Z?.anchorEl)N.add(Z.anchorEl);return Array.from(N)},[G,$,U,Z]);return t(e3,{children:W.map((N)=>t(t3,{block:N,isHovered:N===$||N===U||N===Z?.anchorEl,blockAnnotationMap:Q,activeAnnotationId:q,onOpen:X},N.getAttribute("data-task-id")||N.getAttribute("data-md-title")||N.textContent?.slice(0,30)||"block",!1,void 0,this))},void 0,!1,void 0,this)}function t3({block:J,isHovered:$,blockAnnotationMap:Y,activeAnnotationId:Z,onOpen:Q}){let q=r1(J);if(!q)return null;let X=Y.get(q),G=!!X;return i3(t("button",{"data-block-comment-btn":!0,onClick:(z)=>{z.stopPropagation(),Q(z.currentTarget,q,X)},className:`absolute top-1 right-1 z-10 w-6 h-6 flex items-center justify-center rounded transition-all duration-150 ${G?X===Z?"text-accent-amber bg-accent-amber-muted":"text-accent-amber opacity-60 hover:opacity-100":$?"text-text-disabled hover:text-text-tertiary opacity-50 hover:opacity-100":"text-text-disabled opacity-0 group-hover/section:opacity-20 hover:!opacity-80"}`,title:G?"Edit annotation":"Add annotation",children:t("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:G?"currentColor":"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:t("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),J)}function n3({note:J,onSave:$,onCancel:Y}){let[Z,Q]=J5.useState(J),q=J5.useRef(null);return J5.useEffect(()=>{q.current?.focus(),q.current?.select()},[]),t("div",{className:"fixed inset-0 z-50 bg-black/40 flex items-center justify-center",onClick:Y,children:t("div",{className:"bg-bg-elevated border border-border-hover rounded-lg shadow-md p-4 w-80",onClick:(X)=>X.stopPropagation(),children:[t("div",{className:"text-tiny uppercase tracking-widest text-text-tertiary font-body mb-2",children:"Edit annotation"},void 0,!1,void 0,this),t("textarea",{ref:q,value:Z,onChange:(X)=>Q(X.target.value),className:"w-full bg-transparent border-none text-body font-body text-text-primary resize-vertical focus:outline-none min-h-[60px]",onKeyDown:(X)=>{if(X.key==="Enter"&&(X.ctrlKey||X.metaKey))$(Z.trim());if(X.key==="Escape")Y()}},void 0,!1,void 0,this),t("div",{className:"flex justify-end gap-2 mt-2",children:[t("button",{onClick:Y,className:"text-meta text-text-tertiary font-body px-3 py-1",children:"Cancel"},void 0,!1,void 0,this),t("button",{onClick:()=>$(Z.trim()),className:"text-meta font-medium font-body px-3 py-1 rounded-md bg-highlight-bg text-text-primary border border-highlight-border",children:"Save"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}import U$,{useRef as t5,useEffect as _5,useCallback as n5,useState as l1,useContext as C0}from"react";function Q0(J,$,Y,Z){let Q=[],q=J.filter((U)=>U.filePath===q1),X=J.filter((U)=>!U.filePath),G=J.filter((U)=>U.filePath&&U.filePath!==q1),_=Y?Array.from(Y.values()).filter((U)=>X5(U)):[],z=Z?Array.from(Z.values()).filter((U)=>U.markdown.trim()):[];if(_.length>0||z.length>0){Q.push("## Responses"),Q.push("");for(let U of _)Q.push(Y$(U));for(let U of z)Q.push(U.markdown.trim()),Q.push("")}if(q.length>0){Q.push("## Annotations on agent response"),Q.push("");for(let U of q)Q.push(Z5(U))}if(X.length>0){Q.push("## Canvas annotations"),Q.push("");let U=new Map;for(let K of X){let T=K.canvasFile||"";if(!U.has(T))U.set(T,[]);U.get(T).push(K)}let W=[...U.keys()].sort(),N=W.length>1||W.length===1&&W[0]!=="";for(let K of W){let T=U.get(K);if(N&&K)Q.push(`### ${K.replace(/\.jsx$/,"")}`),Q.push("");let O=Q$(T);Q.push(l5(O))}}if(G.length>0){let U={};for(let W of G){let N=W.filePath;if(!U[N])U[N]=[];U[N].push(W)}Q.push("## File annotations"),Q.push("");for(let[W,N]of Object.entries(U)){Q.push(`### ${W}`),Q.push("");for(let K of N)Q.push(Z5(K))}}if($.trim())Q.push("## General notes"),Q.push(""),Q.push($.trim()),Q.push("");return Q.join(`
59
+ Please report this to https://github.com/markedjs/marked.`,J){let Z="<p>An error occurred:</p><pre>"+K1(Y.message+"",!0)+"</pre>";return $?Promise.resolve(Z):Z}if($)return Promise.reject(Y);throw Y}}},k1=new w3;function a(J,$){return k1.parse(J,$)}a.options=a.setOptions=function(J){return k1.setOptions(J),a.defaults=k1.defaults,M5(a.defaults),a};a.getDefaults=f0;a.defaults=V1;a.use=function(...J){return k1.use(...J),a.defaults=k1.defaults,M5(a.defaults),a};a.walkTokens=function(J,$){return k1.walkTokens(J,$)};a.parseInline=k1.parseInline;a.Parser=G1;a.parser=G1.parse;a.Renderer=W0;a.TextRenderer=a0;a.Lexer=z1;a.lexer=z1.lex;a.Tokenizer=H0;a.Hooks=t1;a.parse=a;var{options:A4,setOptions:I4,use:C4,walkTokens:j4,parseInline:R4}=a;var k4=G1.parse,V4=z1.lex;import{SessionContext as m2,ActiveViewCtx as y4}from"#canvas/runtime";import{useState as $0,useCallback as H1,useEffect as A3,useRef as I3}from"react";import{AnnotationCtx as C3}from"#canvas/runtime";var q1="__agent-response__";function U1(){return`ann-${Date.now()}-${Math.random().toString(36).slice(2,6)}`}function e1(J,$){J.style.height="auto",J.style.height=($?Math.max($,J.scrollHeight):J.scrollHeight)+"px"}import{useAnnotations as e}from"#canvas/runtime";import{jsxDEV as V3}from"react/jsx-dev-runtime";function o0(J,$){return`canvas:${J}:rev:${$}`}function O0(J,$){try{let Y=localStorage.getItem(o0(J,$));if(!Y)return null;return JSON.parse(Y)}catch{return null}}function j3(J,$,Y){try{localStorage.setItem(o0(J,$),JSON.stringify(Y))}catch{}}function R3(J,$){try{localStorage.removeItem(o0(J,$))}catch{}}function D5({sessionId:J,revision:$,isReadOnly:Y,children:Z}){let[Q,q]=$0(()=>{return O0(J,$)?.annotations??[]}),[X,G]=$0(()=>{return O0(J,$)?.generalNote??""}),[_,z]=$0(null),[H,U]=$0(()=>{let C=O0(J,$);return C?.responses?new Map(C.responses):new Map}),[W,N]=$0(()=>{let C=O0(J,$);return C?.feedbackEntries?new Map(C.feedbackEntries):new Map}),K=I3(null);A3(()=>{if(Y)return;if(K.current)clearTimeout(K.current);return K.current=setTimeout(()=>{j3(J,$,{annotations:Q,generalNote:X,responses:Array.from(H.entries()),feedbackEntries:Array.from(W.entries())})},300),()=>{if(K.current)clearTimeout(K.current)}},[Q,X,H,W,J,$,Y]);let T=H1((C,R,v,m,c,y,P)=>{q((x)=>[...x,{id:C,snippet:R,note:v,createdAt:new Date().toISOString(),filePath:m,context:c,...y?.length?{images:y}:{},...P?{canvasFile:P}:{}}])},[]),O=H1((C,R,v)=>{T(U1(),C,R,v)},[T]),S=H1((C,R)=>{q((v)=>v.map((m)=>m.id===C?{...m,note:R}:m))},[]),L=H1((C)=>{k3(C),q((R)=>R.filter((v)=>v.id!==C)),z((R)=>R===C?null:R)},[]),j=H1((C,R)=>{q((v)=>v.map((m)=>m.id===C?{...m,images:[...m.images||[],R]}:m))},[]),V=H1((C,R)=>{q((v)=>v.map((m)=>m.id===C?{...m,images:(m.images||[]).filter((c)=>c!==R)}:m))},[]),M=H1((C,R)=>{U((v)=>{let m=new Map(v);return m.set(C,R),m})},[]),I=H1((C,R)=>{N((v)=>{let m=v.get(C);if(m&&m.markdown===R.markdown&&m.label===R.label&&m.required===R.required)return v;let c=new Map(v);return c.set(C,R),c})},[]),D=H1((C)=>{N((R)=>{if(!R.has(C))return R;let v=new Map(R);return v.delete(C),v})},[]),E=H1(()=>{for(let C of document.querySelectorAll("[data-annotation-id]"))m5(C);q([]),G(""),z(null),U(new Map),N(new Map),R3(J,$)},[J,$]);return V3(C3.Provider,{value:{annotations:Q,addAnnotation:O,addAnnotationWithId:T,updateAnnotation:S,removeAnnotation:L,addAnnotationImage:j,removeAnnotationImage:V,generalNote:X,setGeneralNote:G,clearAll:E,activeAnnotationId:_,setActiveAnnotationId:z,responses:H,setResponse:M,feedbackEntries:W,setFeedbackEntry:I,removeFeedbackEntry:D},children:Z},void 0,!1,void 0,this)}function k3(J){let $=document.querySelectorAll(`[data-annotation-id="${J}"]`);for(let Y of $)m5(Y)}function m5(J){let $=J.parentNode;if(!$)return;let Y=document.createTextNode(J.textContent||"");$.replaceChild(Y,J),$.normalize()}import J5,{useEffect as x1,useState as W1,useRef as r3,useContext as l3,useMemo as J0}from"react";import{createPortal as i3}from"react-dom";import{SessionContext as a3,CanvasFileCtx as o3}from"#canvas/runtime";function D1(J,$){let Y=g5(J,"before",60),Z=g5(J,"after",60),Q=m3(J.startContainer,$);return{before:Y,after:Z,hierarchy:Q}}function g5(J,$,Y){let Z=D3($==="before"?J.startContainer:J.endContainer);if(!Z)return"";let Q="";if($==="before"){let q=document.createTreeWalker(Z,NodeFilter.SHOW_TEXT),X;while(X=q.nextNode()){if(X===J.startContainer){Q+=(X.textContent||"").slice(0,J.startOffset);break}if(X.parentElement?.hasAttribute("data-annotation-id"))continue;Q+=X.textContent||""}if(Q.length>Y){Q=Q.slice(-Y);let G=Q.indexOf(" ");if(G>0)Q=Q.slice(G+1)}}else{let q=document.createTreeWalker(Z,NodeFilter.SHOW_TEXT),X=!1,G;while(G=q.nextNode()){if(G===J.endContainer){Q+=(G.textContent||"").slice(J.endOffset),X=!0;continue}if(X){if(G.parentElement?.hasAttribute("data-annotation-id"))continue;Q+=G.textContent||""}}if(Q.length>Y){Q=Q.slice(0,Y);let _=Q.lastIndexOf(" ");if(_>0)Q=Q.slice(0,_)}}return Q.trim()}function D3(J){let $=new Set(["DIV","P","LI","PRE","BLOCKQUOTE","SECTION","ARTICLE"]),Y=J.parentElement;while(Y){if($.has(Y.tagName))return Y;Y=Y.parentElement}return null}function m3(J,$){let Y=[],Z=J instanceof Element?J:J.parentElement;while(Z&&Z!==$){let Q=Z.getAttribute?.("data-task-id");if(Q){let q=Z.querySelector(".font-semibold");if(q)Y.unshift(q.textContent?.trim()||Q)}if(Z.tagName==="DIV"&&Z.querySelector(":scope > button .font-heading, :scope > div .font-heading")){let q=Z.querySelector(".font-heading");if(q)Y.unshift(q.textContent?.trim()||"")}Z=Z.parentElement}return Y}function s0(J){let $=J.snippet.trim(),Y=J.context,Z=$.length<30;if(Y&&Z&&(Y.before||Y.after)){let Q=[];if(Y.before)Q.push(`...${Y.before} `);if(Q.push(`**${$}**`),Y.after)Q.push(` ${Y.after}...`);return Q.join("")}return $}import{useEffect as E3,useRef as B0,useState as p1,useCallback as L0,useMemo as x5,useContext as v3}from"react";import{createPortal as x3}from"react-dom";function u5(J,$){let Q=$||document.body,q=J.getBoundingClientRect(),X=Q.getBoundingClientRect(),G=Q===document.body?window.scrollY:Q.scrollTop,_=q.bottom-X.top+G+8,z=Math.max(0,Math.min(q.left-X.left,X.width-280-12));return Q.style.position="relative",{style:{position:"absolute",top:`${_}px`,left:`${z}px`},parent:Q}}import{useState as t0,useRef as n0,useCallback as O1,useEffect as g3}from"react";import{jsxDEV as J1}from"react/jsx-dev-runtime";function E5(J){return`/api/uploads/${J.split("/").pop()}`}async function u3(J,$){let Y=new FormData;Y.append("image",$);try{return(await(await fetch(`/api/session/${J}/upload`,{method:"POST",body:Y})).json()).path||null}catch{return null}}function F0({note:J,onNoteChange:$,images:Y,onAddImage:Z,onRemoveImage:Q,sessionId:q,placeholder:X="Add your note...",autoFocus:G=!1,autoResize:_=!1,readOnly:z=!1,onKeyDown:H,onTextareaClick:U,textareaRef:W,textareaClassName:N,textareaStyle:K,minHeight:T,attachButton:O="always",openFilePickerRef:S}){let[L,j]=t0(!1),[V,M]=t0(!1),[I,D]=t0(!1),E=n0(0),C=n0(null),R=n0(null),v=O1(()=>R.current?.click(),[]);if(S)S.current=v;let m=O1((k)=>{if(C.current=k,W)W.current=k;if(k&&_)e1(k,T)},[W,_,T]);g3(()=>{if(G&&C.current){let k=C.current;if(k.focus(),k.value)k.setSelectionRange(k.value.length,k.value.length)}},[G]);let c=O1(async(k)=>{if(!k.type.startsWith("image/"))return;M(!0);try{let r=await u3(q,k);if(r)Z(r)}finally{M(!1)}},[q,Z]),y=O1((k)=>{let r=k.clipboardData.items;for(let A of r)if(A.type.startsWith("image/")){k.preventDefault();let u=A.getAsFile();if(u)c(u);return}},[c]),P=O1((k)=>{if(k.preventDefault(),E.current++,E.current===1)j(!0)},[]),x=O1((k)=>{k.preventDefault()},[]),p=O1((k)=>{if(k.preventDefault(),E.current--,E.current===0)j(!1)},[]),B=O1((k)=>{k.preventDefault(),E.current=0,j(!1);for(let r of k.dataTransfer.files)if(r.type.startsWith("image/"))c(r)},[c]),b=O1((k)=>{if($(k.target.value),_)k.target.style.height="auto",k.target.style.height=(T?Math.max(T,k.target.scrollHeight):k.target.scrollHeight)+"px"},[$,_,T]),g="w-full bg-transparent text-[13px] font-body text-text-primary resize-none focus:outline-none leading-relaxed p-0 border-none",o={width:"100%",background:"transparent",border:"none",color:"var(--color-text-primary)",fontFamily:"'Inter', sans-serif",fontSize:"13px",lineHeight:"1.5",outline:"none",..._?{resize:"none",overflow:"hidden"}:{resize:"vertical"}},i=!z&&(O==="always"||O==="on-focus"&&I);return J1("div",{style:{position:"relative"},onDragEnter:z?void 0:P,onDragOver:z?void 0:x,onDragLeave:z?void 0:p,onDrop:z?void 0:B,children:[J1("textarea",{ref:m,value:J,onChange:z?void 0:b,onPaste:z?void 0:y,onKeyDown:H,onClick:U,onFocus:()=>D(!0),onBlur:()=>{setTimeout(()=>D(!1),150)},readOnly:z,placeholder:X,className:N??g,style:K??o,rows:_?1:void 0},void 0,!1,void 0,this),!z&&J1("input",{ref:R,type:"file",accept:"image/*",multiple:!0,style:{display:"none"},onChange:(k)=>{let r=k.target.files;if(r)for(let A of r)c(A);k.target.value=""}},void 0,!1,void 0,this),(Y.length>0||i)&&J1("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"6px",alignItems:"center"},children:[Y.map((k)=>J1("div",{style:{position:"relative",width:"56px",height:"56px",borderRadius:"6px",overflow:"hidden",border:"1px solid var(--color-border-subtle)",flexShrink:0},children:[J1("img",{src:E5(k),alt:"",style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}},void 0,!1,void 0,this),!z&&J1("button",{onClick:(r)=>{r.stopPropagation(),Q(k)},style:{position:"absolute",top:"2px",right:"2px",width:"16px",height:"16px",borderRadius:"50%",background:"rgba(0,0,0,0.6)",color:"white",border:"none",cursor:"pointer",fontSize:"11px",display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1,padding:0},title:"Remove image",children:"×"},void 0,!1,void 0,this)]},k,!0,void 0,this)),i&&J1(e0,{onClick:v},void 0,!1,void 0,this)]},void 0,!0,void 0,this),V&&J1("div",{style:{fontSize:"11px",color:"var(--color-text-tertiary)",fontFamily:"'Inter', sans-serif",marginTop:"4px"},children:"Uploading..."},void 0,!1,void 0,this),L&&J1("div",{style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",background:"var(--color-highlight-bg)",opacity:0.9,border:"2px dashed var(--color-highlight-border)",borderRadius:"6px",zIndex:10,pointerEvents:"none",fontSize:"12px",fontFamily:"'Inter', sans-serif",color:"var(--color-text-secondary)"},children:"Drop image"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function e0({onClick:J,size:$=16}){return J1("button",{onClick:(Y)=>{Y.stopPropagation(),J()},style:{width:`${$*2}px`,height:`${$*2}px`,borderRadius:"6px",border:"none",background:"transparent",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--color-text-tertiary)",flexShrink:0,transition:"color 0.15s"},title:"Attach image",onMouseEnter:(Y)=>{Y.currentTarget.style.color="var(--color-text-secondary)"},onMouseLeave:(Y)=>{Y.currentTarget.style.color="var(--color-text-tertiary)"},children:J1("svg",{width:$,height:$,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[J1("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"},void 0,!1,void 0,this),J1("circle",{cx:"8.5",cy:"8.5",r:"1.5"},void 0,!1,void 0,this),J1("polyline",{points:"21 15 16 10 5 21"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function v5({images:J}){if(!J.length)return null;return J1("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"6px"},children:J.map(($)=>J1("div",{style:{width:"56px",height:"56px",borderRadius:"6px",overflow:"hidden",border:"1px solid var(--color-border-subtle)",flexShrink:0},children:J1("img",{src:E5($),alt:"",style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}},void 0,!1,void 0,this)},$,!1,void 0,this))},void 0,!1,void 0,this)}import{SessionContext as f3}from"#canvas/runtime";import{jsxDEV as Y1,Fragment as p3}from"react/jsx-dev-runtime";function h3({anchorEl:J,scrollContainer:$,onClose:Y,ignoreSelector:Z,zIndex:Q="50",padding:q="12px",width:X="280px",children:G}){let _=B0(null),z=B0(Y);z.current=Y;let{style:H,parent:U}=u5(J,$);return E3(()=>{let W=setTimeout(()=>{let N=(K)=>{if(_.current&&!_.current.contains(K.target)){if(Z&&K.target.closest?.(Z))return;z.current(),document.removeEventListener("mousedown",N)}};return document.addEventListener("mousedown",N),()=>document.removeEventListener("mousedown",N)},0);return()=>clearTimeout(W)},[Z]),x3(Y1("div",{ref:_,style:{...H,zIndex:Q,width:X,background:"var(--color-bg-elevated)",border:"1px solid var(--color-border-hover)",borderRadius:"8px",boxShadow:"0 4px 12px var(--color-shadow)",padding:q,fontFamily:"'Inter', sans-serif"},children:G},void 0,!1,void 0,this),U)}var h5=[{label:"Clarity",items:["Unclear","Why?","Needs example","Missing context"]},{label:"Scope",items:["Overkill","Out of scope","Important","Risky"]},{label:"Action",items:["Simplify","Rethink","Expand on this","Skip this"]}],f5=h5.flatMap((J)=>J.items);function p5({anchorEl:J,scrollContainer:$,snippet:Y,truncateAt:Z=100,header:Q,initialNote:q="",initialImages:X,onConfirm:G,onCancel:_,onDelete:z}){let H=v3(f3),U=q!==""||!!z,[W,N]=p1(q),[K,T]=p1(X||[]),[O,S]=p1(null),[L,j]=p1(U),[V,M]=p1(!1),I=B0(null),D=B0(null),E=L0(()=>{if(W.trim()||K.length>0)G(W.trim(),K);else if(U&&z)z();else _()},[W,K,G,_,U,z]),C=L0(()=>{if(U){if(!W.trim()&&K.length===0&&z){z(),_();return}G(W,K);return}_()},[W,K,U,G,_,z]),R=!U,v=W.trim().length>0?f5.filter((A)=>A.toLowerCase().startsWith(W.trim().toLowerCase())):f5,m=!R||L?[]:v.length===1&&v[0].toLowerCase()===W.trim().toLowerCase()?[]:v,c=new Set(m),y=h5.map((A)=>({label:A.label,items:A.items.filter((u)=>c.has(u))})).filter((A)=>A.items.length>0),P=y.map((A)=>A.items),x=P.flat(),p=x5(()=>{if(O===null)return 0;let A=0;for(let u=0;u<P.length;u++){if(O<A+P[u].length)return u;A+=P[u].length}return 0},[O,P]),B=x5(()=>{if(O===null)return 0;let A=0;for(let u=0;u<p;u++)A+=P[u].length;return O-A},[O,p,P]),b=(A,u)=>{let s=0;for(let _1=0;_1<A;_1++)s+=P[_1].length;return s+u},[g,o]=p1(W);if(W!==g)o(W),S(null),j(U);let i=L0((A)=>{N(A)},[]),k=Y.length>Z?Y.slice(0,Z)+"...":Y,r=L0((A)=>{if(x.length>0&&(A.key==="ArrowDown"||A.key==="ArrowUp"||A.key==="ArrowLeft"||A.key==="ArrowRight")){if(A.preventDefault(),O===null){S(0);return}if(A.key==="ArrowDown"){let u=Math.min(B+1,P[p].length-1);S(b(p,u))}else if(A.key==="ArrowUp"){let u=Math.max(B-1,0);S(b(p,u))}else if(A.key==="ArrowRight"){let u=Math.min(p+1,P.length-1),s=Math.min(B,P[u].length-1);S(b(u,s))}else if(A.key==="ArrowLeft"){let u=Math.max(p-1,0),s=Math.min(B,P[u].length-1);S(b(u,s))}return}if(O!==null&&x.length>0){if(A.key==="Tab"){A.preventDefault(),i(x[O]);return}if(A.key==="Enter"&&!A.shiftKey){A.preventDefault(),G(x[O],K);return}}if(A.key==="Enter"&&!A.shiftKey){A.preventDefault(),E();return}if(A.key==="Escape")if(x.length>0&&!L)j(!0);else if(U)C();else _()},[x,O,B,p,P,b,i,G,K,E,L,U,C,_]);return Y1(h3,{anchorEl:J,scrollContainer:$,onClose:U?C:_,ignoreSelector:U?"[data-annotation-id]":void 0,zIndex:U?"60":"50",padding:U?"10px 12px":"12px",width:"420px",children:[!U&&(Q??Y1("div",{style:{fontSize:"11px",color:"var(--color-text-tertiary)",fontStyle:"italic",marginBottom:"8px",lineHeight:"1.4",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden"},children:["“",k,"”"]},void 0,!0,void 0,this)),Y1(F0,{note:W,onNoteChange:N,images:K,onAddImage:(A)=>T((u)=>[...u,A]),onRemoveImage:(A)=>T((u)=>u.filter((s)=>s!==A)),sessionId:H,autoFocus:!0,autoResize:U,textareaRef:I,onKeyDown:r,attachButton:"none",openFilePickerRef:D,textareaStyle:U?{width:"100%",background:"transparent",border:"none",color:"var(--color-text-primary)",fontFamily:"'Inter', sans-serif",fontSize:"13px",lineHeight:"1.5",resize:"none",outline:"none",overflow:"hidden"}:{width:"100%",minHeight:"60px",background:"transparent",border:"none",color:"var(--color-text-primary)",fontFamily:"'Inter', sans-serif",fontSize:"13px",lineHeight:"1.5",resize:"vertical",outline:"none"},placeholder:"Add your note..."},void 0,!1,void 0,this),Y1("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginTop:U?"6px":"8px"},children:[Y1(e0,{onClick:()=>D.current?.(),size:14},void 0,!1,void 0,this),Y1("div",{style:{flex:1}},void 0,!1,void 0,this),U?Y1("button",{onClick:()=>{if(z)z();_()},onMouseEnter:()=>M(!0),onMouseLeave:()=>M(!1),style:{fontSize:"11px",color:V?"var(--color-accent-red)":"var(--color-text-tertiary)",background:"none",border:"none",cursor:"pointer",padding:"2px 0",fontFamily:"'Inter', sans-serif"},children:"Delete"},void 0,!1,void 0,this):Y1(p3,{children:[Y1("button",{onClick:_,style:{fontSize:"11px",color:"var(--color-text-tertiary)",background:"none",border:"none",cursor:"pointer",padding:"4px 12px",fontFamily:"'Inter', sans-serif"},children:"Cancel"},void 0,!1,void 0,this),Y1("button",{onClick:E,style:{fontSize:"11px",fontWeight:500,padding:"4px 12px",borderRadius:"6px",background:"var(--color-highlight-bg)",color:"var(--color-text-primary)",border:"1px solid var(--color-highlight-border)",cursor:"pointer",fontFamily:"'Inter', sans-serif"},children:"Add"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),x.length>0&&Y1("div",{style:{marginTop:"6px",borderTop:"1px solid var(--color-border-subtle)",paddingTop:"8px",display:"flex",gap:"4px"},children:y.map((A)=>Y1("div",{style:{flex:1},children:[Y1("div",{style:{fontSize:"10px",fontWeight:600,color:"var(--color-text-disabled)",textTransform:"uppercase",letterSpacing:"0.05em",padding:"2px 6px",marginBottom:"2px",fontFamily:"'Inter', sans-serif"},children:A.label},void 0,!1,void 0,this),A.items.map((u)=>{let s=x.indexOf(u);return Y1("div",{onMouseDown:(_1)=>{_1.preventDefault(),_1.stopPropagation(),i(u)},onMouseEnter:()=>S(s),style:{padding:"3px 6px",fontSize:"12px",borderRadius:"4px",fontFamily:"'Inter', sans-serif",color:s===O?"var(--color-text-primary)":"var(--color-text-secondary)",background:s===O?"var(--color-highlight-selected)":"transparent",cursor:"pointer"},children:[Y1("span",{style:{fontWeight:500},children:u.slice(0,W.trim().length)},void 0,!1,void 0,this),u.slice(W.trim().length)]},u,!0,void 0,this)})]},A.label,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function c1({anchorEl:J,scrollContainer:$,snippet:Y,truncateAt:Z,header:Q,onAdd:q,onCancel:X}){return Y1(p5,{anchorEl:J,scrollContainer:$,snippet:Y,truncateAt:Z,header:Q,onConfirm:(G,_)=>q(G,_),onCancel:X},void 0,!1,void 0,this)}function d1({anchorEl:J,scrollContainer:$,initialNote:Y,initialImages:Z,onUpdate:Q,onDelete:q,onClose:X}){return Y1(p5,{anchorEl:J,scrollContainer:$,snippet:"",initialNote:Y,initialImages:Z,onConfirm:(G,_)=>{Q(G,_),X()},onDelete:q,onCancel:X},void 0,!1,void 0,this)}import{useEffect as b0,useState as d5,useRef as u1,useCallback as r5}from"react";function g1(J,$){let Y=[],Z=c3(J);for(let Q of Z){let q=document.createRange();if(q.selectNodeContents(Q),Q===J.startContainer)q.setStart(Q,J.startOffset);if(Q===J.endContainer)q.setEnd(Q,J.endOffset);let X=q.toString();if(!X||!X.trim())continue;let G=document.createElement("mark");G.setAttribute("data-annotation-id",$);try{q.surroundContents(G)}catch{let _=q.extractContents();G.appendChild(_),q.insertNode(G)}Y.push(G)}return Y}function c3(J){let $=[],Y=J.commonAncestorContainer;if(Y.nodeType===Node.TEXT_NODE)return $.push(Y),$;let Z=document.createTreeWalker(Y,NodeFilter.SHOW_TEXT),Q;while(Q=Z.nextNode()){if(Q.parentElement?.classList.contains("select-none"))continue;if(J.intersectsNode(Q))$.push(Q)}return $}function m1(J,$){let Y=document.querySelectorAll(`[data-annotation-id="${J}"]`);for(let Z of Y)Z.classList.toggle("mark-active",$)}function y0(J,$){if($!=null&&$!==J)m1($,!1);if(J!=null)m1(J,!0)}function M0(J,$){let Y=document.querySelectorAll(`[data-annotation-id="${J}"]`);for(let Z of Y)Z.setAttribute("data-annotation-id",$)}function P0(J,$){let Y=$.filter((G)=>!document.querySelector(`[data-annotation-id="${G.id}"]`));if(!Y.length)return;let Z=[],Q="",q=document.createTreeWalker(J,NodeFilter.SHOW_TEXT),X;while(X=q.nextNode()){if(X.parentElement?.classList.contains("select-none"))continue;Z.push({node:X,start:Q.length}),Q+=X.textContent||""}for(let G of Y){let _=G.snippet;if(!_)continue;let z=[],H=0;while(!0){let O=Q.indexOf(_,H);if(O===-1)break;z.push(O),H=O+1}if(z.length===0)continue;let U=z[0];if(z.length>1&&G.context){let O=-1;for(let S of z){let L=0;if(G.context.before){let j=Q.slice(Math.max(0,S-80),S);if(j.includes(G.context.before))L+=2;else if(G.context.before.length>10&&j.includes(G.context.before.slice(-10)))L+=1}if(G.context.after){let j=Q.slice(S+_.length,S+_.length+80);if(j.includes(G.context.after))L+=2;else if(G.context.after.length>10&&j.includes(G.context.after.slice(0,10)))L+=1}if(L>O)O=L,U=S}}let W=U,N=U+_.length,K=c5(Z,W),T=c5(Z,N);if(!K||!T)continue;try{let O=document.createRange();O.setStart(K.node,K.offset),O.setEnd(T.node,T.offset),g1(O,G.id)}catch{}}}function c5(J,$){for(let Y=J.length-1;Y>=0;Y--)if(J[Y].start<=$){let Z=$-J[Y].start,Q=J[Y].node.textContent?.length??0;if(Z<=Q)return{node:J[Y].node,offset:Z}}return null}function S0(J){let $=document.querySelectorAll(`[data-annotation-id="${J}"]`);for(let Y of $){let Z=Y.parentNode;if(!Z)continue;while(Y.firstChild)Z.insertBefore(Y.firstChild,Y);Z.removeChild(Y),Z.normalize()}}import{jsxDEV as $5,Fragment as d3}from"react/jsx-dev-runtime";function E1(J){let{containerRef:$,restoreKey:Y,restoreAnnotations:Z,extractContext:Q,filePath:q,canvasFile:X,scrollContainer:G}=J,{annotations:_,addAnnotationWithId:z,removeAnnotation:H,updateAnnotation:U,addAnnotationImage:W,removeAnnotationImage:N,activeAnnotationId:K,setActiveAnnotationId:T}=e(),[O,S]=d5(null),[L,j]=d5(null),V=u1(Q);V.current=Q;let M=u1(q);M.current=q;let I=u1(X);I.current=X;let D=u1(z);D.current=z;let E=u1(K);E.current=K;let C=u1(T);C.current=T,b0(()=>{if(!$.current)return;let y=setTimeout(()=>{if($.current)P0($.current,Z)},50);return()=>clearTimeout(y)},[Y]);let R=u1(null);b0(()=>{y0(K,R.current),R.current=K},[K]),b0(()=>{let y=$.current;if(!y)return;let P=(B)=>{let b=B.target.closest("[data-annotation-id]");if(!b)return;B.stopPropagation();let g=b.getAttribute("data-annotation-id");if(g===E.current)S({anchorEl:b,annId:g});else C.current(g)},x=(B)=>{let b=B.target.closest("[data-annotation-id]");if(b)C.current(b.getAttribute("data-annotation-id"))},p=(B)=>{let b=B.target.closest("[data-annotation-id]"),g=B.relatedTarget?.closest?.("[data-annotation-id]");if(b&&!g&&!document.getElementById("ann-inline-popover"))C.current(null)};return y.addEventListener("click",P),y.addEventListener("mouseover",x),y.addEventListener("mouseout",p),()=>{y.removeEventListener("click",P),y.removeEventListener("mouseover",x),y.removeEventListener("mouseout",p)}},[Y]),b0(()=>{let y=()=>v();return document.addEventListener("mouseup",y),()=>document.removeEventListener("mouseup",y)},[]);let v=r5(()=>{let y=window.getSelection();if(!y||y.isCollapsed||!y.toString().trim())return;if(!$.current)return;let P=y.getRangeAt(0);if(!$.current.contains(P.startContainer))return;if(P.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let x=y.toString().trim();if(x.length<2)return;let p=V.current(P),B=P.cloneRange(),b=`__pending_${Date.now()}`;try{g1(B,b)}catch{}window.getSelection()?.removeAllRanges();let g=document.querySelectorAll(`[data-annotation-id="${b}"]`),o=g[g.length-1];if(!o)return;j({anchorEl:o,tempId:b,snippet:x,ctx:p})},[]),m=r5((y,P,x,p)=>{j({anchorEl:y,tempId:P,snippet:x,ctx:p})},[]);return{popovers:$5(d3,{children:[O&&(()=>{let y=_.find((P)=>P.id===O.annId);if(!y)return null;return $5(d1,{anchorEl:O.anchorEl,scrollContainer:G,initialNote:y.note,initialImages:y.images,onUpdate:(P,x)=>{U(O.annId,P);let p=y.images||[];for(let B of x)if(!p.includes(B))W(O.annId,B);for(let B of p)if(!x.includes(B))N(O.annId,B)},onDelete:()=>{H(O.annId),T(null)},onClose:()=>S(null)},void 0,!1,void 0,this)})(),L&&$5(c1,{anchorEl:L.anchorEl,scrollContainer:G,snippet:L.snippet,truncateAt:80,onAdd:(y,P)=>{let x=U1();M0(L.tempId,x),D.current(x,L.snippet,y,M.current,L.ctx,P,I.current),j(null)},onCancel:()=>{S0(L.tempId),j(null)}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),openCreatePopover:m,isPopoverOpen:!!(O||L)}}import{jsxDEV as t,Fragment as e3}from"react/jsx-dev-runtime";var Q5="[data-md='item'], [data-md='section'], [data-md='table'] tbody tr, [data-md='callout'], [data-md='note'], [data-md='checklist-item'], [data-md='choice-option'], [data-md='multichoice-option'], [data-md='userinput'], [data-md='rangeinput'], [data-md='image']",Y5="[data-md='item'], [data-md='section'], [data-md='table'] tbody tr, [data-md='callout'], [data-md='note'], [data-md='checklist-item'], [data-md='image']";function Y0({revision:J,filename:$}){let Y=l3(a3),[Z,Q]=W1(null),[q,X]=W1(null),[G,_]=W1(!0),z=r3(null),{annotations:H,addAnnotationWithId:U,removeAnnotation:W,updateAnnotation:N,addAnnotationImage:K,removeAnnotationImage:T,activeAnnotationId:O,setActiveAnnotationId:S}=e(),L=J0(()=>H.filter((B)=>!B.filePath&&(!B.canvasFile||B.canvasFile===$)),[H,$]),[j,V]=W1(null),[M,I]=W1(null),[D,E]=W1(null),[C,R]=W1(null),[v,m]=W1(!1);x1(()=>{_(!0),X(null),R(null);let B=$.replace(/\.jsx$/,".js");import(`/api/session/${Y}/canvas/${encodeURIComponent(B)}?rev=${J}&t=${Date.now()}`).then((b)=>{Q(()=>b.default),_(!1)}).catch((b)=>{X(b.message),_(!1)})},[Y,J,$]);let c=document.getElementById("plan-scroll-container"),{popovers:y,isPopoverOpen:P}=E1({containerRef:z,restoreKey:Z,restoreAnnotations:L,extractContext:(B)=>D1(B,z.current),canvasFile:$,scrollContainer:c}),x=J0(()=>{let B=new Map;for(let b of L)if(b.snippet.startsWith("["))B.set(b.snippet,b.id);return B},[L]);x1(()=>{let B=z.current;if(!B)return;let b=(o)=>{if(D||P)return;let i=o.target;if(i.closest("[data-block-comment-btn]"))return;m(!1);let k=i.closest(Q5);if(k&&B.contains(k)){let u=v1(B).indexOf(k);R(u>=0?u:null)}else R(null);let r=i.closest(Y5);if(r&&B.contains(r)){I(r);let A=r1(r),u=A?x.get(A):void 0;if(u&&u!==O)S(u)}else I(null)},g=(o)=>{if(D||P)return;if(o.relatedTarget?.closest("[data-block-comment-btn]"))return;I(null),S(null)};return B.addEventListener("mousemove",b),B.addEventListener("mouseleave",g),()=>{B.removeEventListener("mousemove",b),B.removeEventListener("mouseleave",g)}},[Z,D,P,x,O]),x1(()=>{let B=(b)=>{let g=b.target.tagName;if(g==="INPUT"||g==="TEXTAREA"||b.target.isContentEditable)return;if(D||P)return;let o=z.current;if(!o)return;if(b.key==="ArrowDown"){b.preventDefault(),m(!0);let i=v1(o);if(i.length===0)return;R((k)=>{if(k===null)return 0;return Math.min(k+1,i.length-1)})}else if(b.key==="ArrowUp"){b.preventDefault(),m(!0);let i=v1(o);if(i.length===0)return;R((k)=>{if(k===null)return i.length-1;return Math.max(k-1,0)})}else if(b.key==="a"||b.key==="A"){if(C===null||!o)return;b.preventDefault();let k=v1(o)[C];if(!k)return;let r=r1(k);if(!r)return;let A=x.get(r);if(A)S(A),E({anchorEl:k,snippet:r,annId:A});else E({anchorEl:k,snippet:r})}else if(b.key===" "||b.key==="Enter"){if(C===null)return;let k=v1(o)[C];if(!k)return;let r=k.getAttribute("data-md");if(r==="choice-option"||r==="multichoice-option")b.preventDefault(),k.dispatchEvent(new CustomEvent("kb-select",{bubbles:!0}));else if(r==="userinput"){b.preventDefault();let A=k.querySelector("textarea");if(A){A.focus();let u=(s)=>{if(s.key==="Escape")s.preventDefault(),A.blur(),m(!0)};A.addEventListener("keydown",u),A.addEventListener("blur",()=>A.removeEventListener("keydown",u),{once:!0})}}else if(r==="rangeinput"){b.preventDefault();let A=k.querySelector("input[type='range']");if(A){A.focus();let u=(s)=>{if(s.key==="Escape"||s.key==="ArrowUp"||s.key==="ArrowDown")s.preventDefault(),A.blur(),m(!0)};A.addEventListener("keydown",u),A.addEventListener("blur",()=>A.removeEventListener("keydown",u),{once:!0})}}}else if(b.key==="Escape")R(null),m(!1),S(null)};return document.addEventListener("keydown",B),()=>document.removeEventListener("keydown",B)},[C,D,P,x]),x1(()=>{let B=z.current;if(!B||C===null||!v)return;let g=v1(B)[C];if(!g)return;g.style.outline="2px solid var(--color-accent-blue)",g.style.outlineOffset="-2px",g.style.borderRadius="8px",g.scrollIntoView({block:"nearest",behavior:"smooth"});let o=r1(g),i=o?x.get(o):void 0;if(i)S(i);return()=>{g.style.outline="",g.style.outlineOffset="",g.style.borderRadius=""}},[C,v,x]);let p=J0(()=>Z?t(Z,{},void 0,!1,void 0,this):null,[Z]);if(G)return t("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-body",children:"Loading canvas..."},void 0,!1,void 0,this);if(q)return t("div",{className:"bg-accent-red-muted rounded-lg p-5",children:[t("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Compilation Error"},void 0,!1,void 0,this),t("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:q},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(!Z)return t("div",{className:"text-text-tertiary text-center py-8 font-body text-body",children:"No canvas loaded"},void 0,!1,void 0,this);return t(o3.Provider,{value:$,children:[t("div",{ref:z,className:"plan-content plan-updated",children:p},void 0,!1,void 0,this),j&&t(n3,{note:j.note,onSave:(B)=>{N(j.id,B),V(null)},onCancel:()=>V(null)},void 0,!1,void 0,this),y,t(s3,{containerRef:z,hoveredBlock:M,focusedBlockIndex:C,blockPopover:D,blockAnnotationMap:x,activeAnnotationId:O,onOpen:(B,b,g)=>{if(g)S(g),E({anchorEl:B,snippet:b,annId:g});else E({anchorEl:B,snippet:b})}},void 0,!1,void 0,this),D&&!D.annId&&t(c1,{anchorEl:D.anchorEl,scrollContainer:c,snippet:D.snippet,truncateAt:80,onAdd:(B,b)=>{let g=U1();U(g,D.snippet,B,void 0,void 0,b,$),E(null)},onCancel:()=>E(null)},void 0,!1,void 0,this),D?.annId&&(()=>{let B=L.find((b)=>b.id===D.annId);if(!B)return null;return t(d1,{anchorEl:D.anchorEl,scrollContainer:c,initialNote:B.note,initialImages:B.images,onUpdate:(b,g)=>{N(D.annId,b);let o=B.images||[];for(let i of g)if(!o.includes(i))K(D.annId,i);for(let i of o)if(!g.includes(i))T(D.annId,i)},onDelete:()=>{W(D.annId),S(null),E(null)},onClose:()=>E(null)},void 0,!1,void 0,this)})()]},void 0,!0,void 0,this)}function v1(J){return Array.from(J.querySelectorAll(Q5))}function r1(J){let $=J.getAttribute("data-md");if($==="item"){let Y=J.getAttribute("data-md-label");return Y?`[Item] ${Y}`:null}if($==="section"){let Y=J.getAttribute("data-md-title");return Y?`[Section] ${Y}`:null}if($==="callout"){let Y=J.getAttribute("data-md-type")||"info",Z=J.textContent?.trim().slice(0,60)||"Callout";return`[Callout:${Y}] ${Z}`}if($==="note")return`[Note] ${J.textContent?.trim().slice(0,60)||"Note"}`;if(J.tagName==="TR"){let Y=Array.from(J.querySelectorAll("td")).map((Z)=>Z.textContent?.trim()).filter(Boolean);return Y.length?`[Row] ${Y.join(" | ")}`:null}if($==="checklist-item"){let Y=J.getAttribute("data-md-label");return Y?`[Checklist] ${Y}`:null}if($==="choice-option"||$==="multichoice-option"){let Y=J.getAttribute("data-md-label");return Y?`[Option] ${Y}`:null}if($==="userinput"){let Y=J.getAttribute("data-md-label");return Y?`[Input] ${Y}`:null}if($==="rangeinput"){let Y=J.getAttribute("data-md-label");return Y?`[Range] ${Y}`:null}if($==="image"){let Y=J.getAttribute("data-md-src");return Y?`[Image] ${Y}`:null}return null}function s3({containerRef:J,hoveredBlock:$,focusedBlockIndex:Y,blockPopover:Z,blockAnnotationMap:Q,activeAnnotationId:q,onOpen:X}){let[G,_]=W1([]);x1(()=>{let N=J.current;if(!N||Q.size===0){_([]);return}let K=[];for(let T of N.querySelectorAll(Y5)){let O=r1(T);if(O&&Q.has(O))K.push(T)}_(K)},[Q,J.current]);let[z,H]=W1(null);x1(()=>{if(!q||!J.current){H(null);return}for(let N of J.current.querySelectorAll(Q5)){let K=r1(N);if(K&&Q.get(K)===q){H(N);return}}H(null)},[q,Q]),x1(()=>{if(!z)return;return z.style.boxShadow="inset 0 0 0 1.5px var(--color-highlight-bg)",z.style.borderRadius="8px",()=>{z.style.boxShadow="",z.style.borderRadius=""}},[z]);let U=J0(()=>{if(Y===null||!J.current)return null;let N=v1(J.current)[Y];if(!N)return null;return N.matches(Y5)?N:null},[Y,J.current]),W=J0(()=>{let N=new Set(G);if($)N.add($);if(U)N.add(U);if(Z?.anchorEl)N.add(Z.anchorEl);return Array.from(N)},[G,$,U,Z]);return t(e3,{children:W.map((N)=>t(t3,{block:N,isHovered:N===$||N===U||N===Z?.anchorEl,blockAnnotationMap:Q,activeAnnotationId:q,onOpen:X},N.getAttribute("data-task-id")||N.getAttribute("data-md-title")||N.textContent?.slice(0,30)||"block",!1,void 0,this))},void 0,!1,void 0,this)}function t3({block:J,isHovered:$,blockAnnotationMap:Y,activeAnnotationId:Z,onOpen:Q}){let q=r1(J);if(!q)return null;let X=Y.get(q),G=!!X;return i3(t("button",{"data-block-comment-btn":!0,onClick:(z)=>{z.stopPropagation(),Q(z.currentTarget,q,X)},className:`absolute top-1 right-1 z-10 w-6 h-6 flex items-center justify-center rounded transition-all duration-150 ${G?X===Z?"text-accent-amber bg-accent-amber-muted":"text-accent-amber opacity-60 hover:opacity-100":$?"text-text-disabled hover:text-text-tertiary opacity-50 hover:opacity-100":"text-text-disabled opacity-0 group-hover/section:opacity-20 hover:!opacity-80"}`,title:G?"Edit annotation":"Add annotation",children:t("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:G?"currentColor":"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:t("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),J)}function n3({note:J,onSave:$,onCancel:Y}){let[Z,Q]=J5.useState(J),q=J5.useRef(null);return J5.useEffect(()=>{q.current?.focus(),q.current?.select()},[]),t("div",{className:"fixed inset-0 z-50 bg-black/40 flex items-center justify-center",onClick:Y,children:t("div",{className:"bg-bg-elevated border border-border-hover rounded-lg shadow-md p-4 w-80",onClick:(X)=>X.stopPropagation(),children:[t("div",{className:"text-tiny uppercase tracking-widest text-text-tertiary font-body mb-2",children:"Edit annotation"},void 0,!1,void 0,this),t("textarea",{ref:q,value:Z,onChange:(X)=>Q(X.target.value),className:"w-full bg-transparent border-none text-body font-body text-text-primary resize-vertical focus:outline-none min-h-[60px]",onKeyDown:(X)=>{if(X.key==="Enter"&&(X.ctrlKey||X.metaKey))$(Z.trim());if(X.key==="Escape")Y()}},void 0,!1,void 0,this),t("div",{className:"flex justify-end gap-2 mt-2",children:[t("button",{onClick:Y,className:"text-meta text-text-tertiary font-body px-3 py-1",children:"Cancel"},void 0,!1,void 0,this),t("button",{onClick:()=>$(Z.trim()),className:"text-meta font-medium font-body px-3 py-1 rounded-md bg-highlight-bg text-text-primary border border-highlight-border",children:"Save"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}import U$,{useRef as t5,useEffect as _5,useCallback as n5,useState as l1,useContext as C0}from"react";function Q0(J,$,Y,Z){let Q=[],q=J.filter((U)=>U.filePath===q1),X=J.filter((U)=>!U.filePath),G=J.filter((U)=>U.filePath&&U.filePath!==q1),_=Y?Array.from(Y.values()).filter((U)=>X5(U)):[],z=Z?Array.from(Z.values()).filter((U)=>U.markdown.trim()):[];if(_.length>0||z.length>0){Q.push("## Responses"),Q.push("");for(let U of _)Q.push(Y$(U));for(let U of z)Q.push(U.markdown.trim()),Q.push("")}if(q.length>0){Q.push("## Annotations on agent response"),Q.push("");for(let U of q)Q.push(Z5(U))}if(X.length>0){Q.push("## Canvas annotations"),Q.push("");let U=new Map;for(let K of X){let T=K.canvasFile||"";if(!U.has(T))U.set(T,[]);U.get(T).push(K)}let W=[...U.keys()].sort(),N=W.length>1||W.length===1&&W[0]!=="";for(let K of W){let T=U.get(K);if(N&&K)Q.push(`### ${K.replace(/\.jsx$/,"")}`),Q.push("");let O=Q$(T);Q.push(l5(O))}}if(G.length>0){let U={};for(let W of G){let N=W.filePath;if(!U[N])U[N]=[];U[N].push(W)}Q.push("## File annotations"),Q.push("");for(let[W,N]of Object.entries(U)){Q.push(`### ${W}`),Q.push("");for(let K of N)Q.push(Z5(K))}}if($.trim())Q.push("## General notes"),Q.push(""),Q.push($.trim()),Q.push("");return Q.join(`
60
60
  `).trim()+`
61
61
  `}function X5(J){if(J.note?.trim())return!0;if(J.value===null||J.value===void 0)return!1;if(J.type==="text"&&!J.value.trim())return!1;if(J.type==="checkbox"&&J.value.length===0)return!1;return!0}function $$(J){let $=[];for(let Y of J.values()){if(!Y.required)continue;if(Y.value===null||Y.value===void 0){$.push(Y);continue}if(Y.type==="text"&&!Y.value.trim()){$.push(Y);continue}if(Y.type==="checkbox"&&Y.value.length===0){$.push(Y);continue}}return $}function J$(J){let $=[];for(let Y of J.values())if(Y.required&&!Y.markdown.trim())$.push(Y);return $}function w0(J,$){let Y=$$(J),Z=J$($);return[...Y.map((Q)=>Q.label),...Z.map((Q)=>Q.label||Q.id)]}function Y$(J){let $=[];switch($.push(`**${J.label}**`),J.type){case"radio":case"select":$.push(`Answer: ${J.value}`);break;case"checkbox":for(let Y of J.value)$.push(`- [x] ${Y}`);break;case"text":$.push(""),$.push(J.value.trim());break;case"range":$.push(`Answer: ${J.value}`);break}if(J.note?.trim())$.push(""),$.push(`Note: ${J.note.trim()}`);return $.push(""),$.join(`
62
62
  `)}function Z5(J){let $=[],Y=J.snippet.trim(),Z=J.context,Q=Z?.lineStart!=null;if(J.filePath&&Q){let q=Z.lineStart,X=Z.lineEnd??q,G=Y.split(`
@@ -80,12 +80,12 @@ Please report this to https://github.com/markedjs/marked.`,J){let Z="<p>An error
80
80
  `).replace(/\n{3,}/g,`
81
81
 
82
82
  `).trim()+`
83
- `}var b$=new Set(["CODE","SPAN","STRONG","EM","A","B","I","U","SMALL","SUB","SUP","MARK","ABBR"]);function k0(J,$,Y){if(w$(J)){let Z=A$(J);if(Z)$.push(Z,"");return}for(let Z of J.childNodes)if(Z.nodeType===Node.ELEMENT_NODE)I$(Z,$,Y);else if(Z.nodeType===Node.TEXT_NODE){let Q=Z.textContent?.trim();if(Q)$.push(Q,"")}}function w$(J){for(let $ of J.childNodes){if($.nodeType===Node.TEXT_NODE)continue;if($.nodeType===Node.ELEMENT_NODE){let Y=$;if(!b$.has(Y.tagName)||Y.hasAttribute("data-md"))return!1}}return J.childNodes.length>0}function A$(J){let $="";for(let Y of J.childNodes)if(Y.nodeType===Node.TEXT_NODE)$+=Y.textContent||"";else if(Y.nodeType===Node.ELEMENT_NODE){let Z=Y;if(Z.tagName==="CODE")$+="`"+(Z.textContent||"")+"`";else $+=Z.textContent||""}return $.trim()}function I$(J,$,Y){let Z=J.getAttribute("data-md");if(Z)switch(Z){case"section":return C$(J,$,Y);case"item":return j$(J,$);case"codeblock":return R$(J,$);case"callout":return k$(J,$);case"note":return V$(J,$);case"table":return D$(J,$);case"checklist":return m$(J,$);case"diff":return g$(J,$);case"mermaid":return u$(J,$);case"choice":return E$(J,$);case"multichoice":return v$(J,$);case"choice-option":case"multichoice-option":return;case"userinput":return x$(J,$);case"rangeinput":return f$(J,$);case"checklist-item":return;case"filepreview":return h$(J,$);case"priority":return p$(J,$)}if(J.querySelector("button, input, select, textarea"))return;if(J.children.length>0)k0(J,$,Y);else{let Q=J.textContent?.trim();if(Q)$.push(Q,"")}}function C$(J,$,Y){let Z=J.getAttribute("data-md-title")||"Untitled",Q=Y===0?"##":"###";$.push(`${Q} ${Z}`,"");let q=J.querySelector(":scope > div:last-of-type");if(q)k0(q,$,Y+1)}function j$(J,$){let Y=J.getAttribute("data-md-label")||"",Z=J.getAttribute("data-md-status"),Q=J.getAttribute("data-md-badge"),q="-";if(Z==="done")q="- [x]";else if(Z)q="- [ ]";let X=`${q} **${Y}**`;if(Q)X+=` \`${Q}\``;$.push(X);let G=J.querySelector(".text-text-secondary");if(G){let _=[];k0(G,_,0);for(let z of _)$.push(z?` ${z}`:"")}$.push("")}function R$(J,$){let Y=J.getAttribute("data-md-language")||"",Q=J.querySelector("code")?.textContent||"";$.push(`\`\`\`${Y}`,Q,"```","")}function k$(J,$){let Y=J.getAttribute("data-md-type")||"info",Z={info:"Info",warning:"Warning",danger:"Danger",tip:"Tip"},Q=c$(J.querySelector(".text-text-secondary")||J);$.push(`> **${Z[Y]||Y}:** ${Q}`,"")}function V$(J,$){let Y=J.textContent?.trim()||"";$.push(`> *${Y}*`,"")}function D$(J,$){let Y=J.querySelector("table");if(!Y)return;let Z=[];for(let Q of Y.querySelectorAll("thead th"))Z.push(Q.textContent?.trim()||"");if(Z.length===0)return;$.push(`| ${Z.join(" | ")} |`),$.push(`| ${Z.map(()=>"---").join(" | ")} |`);for(let Q of Y.querySelectorAll("tbody tr")){let q=[];for(let X of Q.querySelectorAll("td"))q.push(X.textContent?.trim()||"");$.push(`| ${q.join(" | ")} |`)}$.push("")}function m$(J,$){for(let Y of J.querySelectorAll("li")){let Z=Y.querySelector(".bg-accent-green")!==null,Q=Y.textContent?.trim()||"";$.push(`- [${Z?"x":" "}] ${Q}`)}$.push("")}function g$(J,$){let Y=J.getAttribute("data-md-language")||"";$.push(`\`\`\`diff${Y?` (${Y})`:""}`);for(let Z of J.querySelectorAll("[class*='flex']")){let Q=Z.querySelector(".text-accent-red")?"-":Z.querySelector(".text-accent-green")?"+":" ",q=Z.querySelector("code");if(q)$.push(`${Q} ${q.textContent}`)}$.push("```","")}function u$(J,$){let Y=J.getAttribute("data-md-source")||"";if(Y)$.push("```mermaid",Y,"```","")}function E$(J,$){let Y=J.getAttribute("data-md-label")||"";$.push(`**${Y}:**`);for(let Z of J.querySelectorAll("[data-md='choice-option']")){let Q=Z.getAttribute("data-md-label")||Z.textContent?.trim()||"",q=Z.querySelector(".bg-accent-amber")!==null;$.push(`- ${q?"(x)":"( )"} ${Q}`)}$.push("")}function v$(J,$){let Y=J.getAttribute("data-md-label")||"";$.push(`**${Y}:**`);for(let Z of J.querySelectorAll("[data-md='multichoice-option']")){let Q=Z.getAttribute("data-md-label")||Z.textContent?.trim()||"",q=Z.querySelector(".bg-accent-amber")!==null;$.push(`- [${q?"x":" "}] ${Q}`)}$.push("")}function x$(J,$){let Y=J.getAttribute("data-md-label")||"",Q=J.querySelector("textarea")?.value?.trim()||"";$.push(`**${Y}:** ${Q||"_empty_"}`,"")}function f$(J,$){let Y=J.getAttribute("data-md-label")||"",Z=J.querySelector("input[type='range']"),q=J.querySelector(".font-mono")?.textContent?.trim()||Z?.value||"—";$.push(`**${Y}:** ${q}`,"")}function h$(J,$){let Y=J.getAttribute("data-md-path")||"",Z=J.getAttribute("data-md-lines")||"",q=J.querySelector("code")?.textContent||"",X=Y.split(".").pop()||"",G=j0[X]||"",_=Z?`${Y} (L${Z})`:Y;$.push(_,"",`\`\`\`${G}`,q,"```","")}function p$(J,$){}function c$(J){return J?.textContent?.trim()||""}import P2,{useEffect as w1,useState as Q1,useRef as L1,useCallback as S2,useMemo as g0,useContext as Z4}from"react";import{useEffect as d$,useState as r$,useRef as l$,useContext as i$}from"react";import{jsxDEV as X1,Fragment as K2}from"react/jsx-dev-runtime";function a$(J){return J.label||`Round ${J.revision}`}function o$(J){let $=Date.now()-new Date(J).getTime(),Y=Math.floor($/1000);if(Y<60)return"just now";let Z=Math.floor(Y/60);if(Z<60)return`${Z}m ago`;let Q=Math.floor(Z/60);if(Q<24)return`${Q}h ago`;return`${Math.floor(Q/24)}d ago`}function q0({value:J,onChange:$,accent:Y="default",className:Z}){let{currentRevision:Q,revisions:q}=i$(N1),[X,G]=r$(!1),_=l$(null);d$(()=>{if(!X)return;let U=(W)=>{if(_.current&&!_.current.contains(W.target))G(!1)};return document.addEventListener("mousedown",U),()=>document.removeEventListener("mousedown",U)},[X]);let z=q.find((U)=>U.revision===J);return X1("div",{className:"relative",ref:_,children:[X1("button",{onClick:()=>G(!X),className:`flex items-center gap-1.5 text-[12px] font-body font-medium px-2 py-1 rounded-md transition-colors hover:bg-bg-elevated ${{default:"text-text-secondary hover:text-text-primary",red:"text-accent-red",green:"text-accent-green",amber:"text-accent-amber bg-highlight-selected"}[Y]} ${Z||""}`,children:[z?a$(z):`Round ${J}`,X1("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",className:`text-text-tertiary transition-transform duration-200 ${X?"rotate-180":""}`,children:X1("path",{d:"M2.5 4l2.5 2.5L7.5 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),X&&X1("div",{className:"absolute top-full left-0 mt-1 w-64 bg-bg-elevated border border-border-hover rounded-lg shadow-lg z-50 py-1 max-h-80 overflow-y-auto",children:[...q].reverse().map((U)=>X1("button",{onClick:()=>{$(U.revision),G(!1)},className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] font-body transition-colors ${U.revision===J?"bg-bg-surface text-text-primary":"text-text-secondary hover:bg-bg-surface hover:text-text-primary"}`,children:[X1("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${U.revision===Q?"bg-accent-green":U.hasFeedback?"bg-accent-amber":"bg-border-hover"}`},void 0,!1,void 0,this),X1("span",{className:"flex-1 text-left truncate",children:U.label?X1(K2,{children:[U.label," ",X1("span",{className:"text-text-tertiary",children:["#",U.revision]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):X1(K2,{children:["Round ",U.revision]},void 0,!0,void 0,this)},void 0,!1,void 0,this),X1("span",{className:"text-[10px] text-text-tertiary flex-shrink-0 flex items-center gap-1.5",children:[(()=>{let W=U.canvasFiles?.reduce((N,K)=>{if(K.diffStats)N.added+=K.diffStats.added,N.removed+=K.diffStats.removed;return N},{added:0,removed:0});if(W&&(W.added>0||W.removed>0))return X1("span",{className:"font-mono",children:[X1("span",{className:"text-accent-green",children:["+",W.added]},void 0,!0,void 0,this)," ",X1("span",{className:"text-accent-red",children:["-",W.removed]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);return null})(),U.revision===Q?"current":U.hasFeedback?"sent":o$(U.createdAt)]},void 0,!0,void 0,this)]},U.revision,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function b1(J,$){let Y=J.length,Z=$.length;if(Y===0||Z===0)return[];let Q=Array.from({length:Y+1},()=>Array(Z+1).fill(0));for(let _=1;_<=Y;_++)for(let z=1;z<=Z;z++)Q[_][z]=J[_-1]===$[z-1]?Q[_-1][z-1]+1:Math.max(Q[_-1][z],Q[_][z-1]);let q=[],X=Y,G=Z;while(X>0&&G>0)if(J[X-1]===$[G-1])q.unshift(J[X-1]),X--,G--;else if(Q[X-1][G]>Q[X][G-1])X--;else G--;return q}function H2(J){let $=[],Y=[],Z=document.createTreeWalker(J,NodeFilter.SHOW_TEXT,{acceptNode(q){let X=q.parentElement;if(!X)return NodeFilter.FILTER_REJECT;if(X.closest("svg, .select-none, [data-no-diff]"))return NodeFilter.FILTER_REJECT;return NodeFilter.FILTER_ACCEPT}}),Q;while(Q=Z.nextNode()){let X=(Q.nodeValue||"").match(/\S+|\s+/g);if(!X)continue;let G=0;for(let _ of X)$.push(_),Y.push({text:_,node:Q,offset:G}),G+=_.length}return{words:$,map:Y}}function K5(J,$){if(J.length>5000||$.length>5000)return s$(J,$);return T2(J,$)}function T2(J,$){let Y=V0(J,$),Z=[],Q=[],q=0,X=0,G=0;while(q<J.length||X<$.length)if(G<Y.length&&q<J.length&&X<$.length&&J[q]===Y[G]&&$[X]===Y[G])Z.push({type:"same",index:q}),Q.push({type:"same",index:X}),q++,X++,G++;else if(q<J.length&&(G>=Y.length||J[q]!==Y[G]))Z.push({type:"removed",index:q}),q++;else if(X<$.length)Q.push({type:"added",index:X}),X++;return{oldOps:Z,newOps:Q}}function V0(J,$){let Y=J.length,Z=$.length;if(Y===0||Z===0)return[];if(Y===1)return $.includes(J[0])?[J[0]]:[];if(Z===1)return J.includes($[0])?[$[0]]:[];if(Y*Z<=1e6)return b1(J,$);let Q=Math.floor(Y/2),q=J.slice(0,Q),X=J.slice(Q),G=W2(q,$),_=W2([...X].reverse(),[...$].reverse()),z=0,H=0;for(let N=0;N<=Z;N++){let K=G[N]+_[Z-N];if(K>z)z=K,H=N}let U=$.slice(0,H),W=$.slice(H);return[...V0(q,U),...V0(X,W)]}function W2(J,$){let Y=$.length,Z=Array(Y+1).fill(0),Q=Array(Y+1).fill(0);for(let q=0;q<J.length;q++){for(let X=1;X<=Y;X++)Q[X]=J[q]===$[X-1]?Z[X-1]+1:Math.max(Z[X],Q[X-1]);[Z,Q]=[Q,Z],Q.fill(0)}return Z}function s$(J,$){let Z=(K)=>{let T=[];for(let O=0;O<K.length;O+=200){let S=Math.min(O+200,K.length);T.push({start:O,end:S,text:K.slice(O,S).join("")})}return T},Q=Z(J),q=Z($),X=Q.map((K)=>K.text),G=q.map((K)=>K.text),_=V0(X,G),z=[],H=[],U=0,W=0,N=0;while(U<Q.length||W<q.length)if(N<_.length&&U<Q.length&&W<q.length&&X[U]===_[N]&&G[W]===_[N]){for(let K=Q[U].start;K<Q[U].end;K++)z.push({type:"same",index:K});for(let K=q[W].start;K<q[W].end;K++)H.push({type:"same",index:K});U++,W++,N++}else if(U<Q.length&&(N>=_.length||X[U]!==_[N]))if(W<q.length&&(N>=_.length||G[W]!==_[N])){let K=T2(J.slice(Q[U].start,Q[U].end),$.slice(q[W].start,q[W].end));for(let T of K.oldOps)z.push({type:T.type,index:T.index+Q[U].start});for(let T of K.newOps)H.push({type:T.type,index:T.index+q[W].start});U++,W++}else{for(let K=Q[U].start;K<Q[U].end;K++)z.push({type:"removed",index:K});U++}else if(W<q.length){for(let K=q[W].start;K<q[W].end;K++)H.push({type:"added",index:K});W++}return{oldOps:z,newOps:H}}function N2(J,$,Y){let Z=new Map;for(let Q of J){if(Q.type==="same")continue;let q=$[Q.index];if(!q||!q.node.parentNode)continue;let X=Z.get(q.node);if(!X)X=[],Z.set(q.node,X);X.push({offset:q.offset,length:q.text.length})}for(let[Q,q]of Z){if(!Q.parentNode)continue;let X=Q.nodeValue||"";q.sort((U,W)=>U.offset-W.offset);let G=[];for(let U of q){let W=G[G.length-1];if(W&&U.offset<=W.offset+W.length)W.length=Math.max(W.length,U.offset+U.length-W.offset);else G.push({...U})}let _=Q.parentNode,z=document.createDocumentFragment(),H=0;for(let U of G){if(U.offset>H)z.appendChild(document.createTextNode(X.slice(H,U.offset)));let W=document.createElement("span");W.className=Y,W.textContent=X.slice(U.offset,U.offset+U.length),z.appendChild(W),H=U.offset+U.length}if(H<X.length)z.appendChild(document.createTextNode(X.slice(H)));_.replaceChild(z,Q)}}function D0(J,$){let Y=t$(J,$),Z=H2(J),Q=H2($),{oldOps:q,newOps:X}=K5(Z.words,Q.words),G=q.some((_)=>_.type==="removed")||X.some((_)=>_.type==="added");return N2(q,Z.map,"diff-removed"),N2(X,Q.map,"diff-added"),G||Y}function t$(J,$){let Y=Array.from(J.querySelectorAll('[data-md="mermaid"]')),Z=Array.from($.querySelectorAll('[data-md="mermaid"]')),Q=!1,q=Math.max(Y.length,Z.length);for(let X=0;X<q;X++){let G=Y[X],_=Z[X];if(!G&&_){_.classList.add("diff-block-added"),_.style.position="relative",Q=!0;continue}if(G&&!_){G.classList.add("diff-block-removed"),G.style.position="relative",Q=!0;continue}if(!G||!_)continue;let z=(G.getAttribute("data-md-source")||"").trim(),H=(_.getAttribute("data-md-source")||"").trim();if(z===H)continue;Q=!0,G.style.borderLeft="3px solid var(--color-accent-red)",G.style.paddingLeft="8px",_.style.borderLeft="3px solid var(--color-accent-green)",_.style.paddingLeft="8px";let U=z.split(`
83
+ `}var b$=new Set(["CODE","SPAN","STRONG","EM","A","B","I","U","SMALL","SUB","SUP","MARK","ABBR"]);function k0(J,$,Y){if(w$(J)){let Z=A$(J);if(Z)$.push(Z,"");return}for(let Z of J.childNodes)if(Z.nodeType===Node.ELEMENT_NODE)I$(Z,$,Y);else if(Z.nodeType===Node.TEXT_NODE){let Q=Z.textContent?.trim();if(Q)$.push(Q,"")}}function w$(J){for(let $ of J.childNodes){if($.nodeType===Node.TEXT_NODE)continue;if($.nodeType===Node.ELEMENT_NODE){let Y=$;if(!b$.has(Y.tagName)||Y.hasAttribute("data-md"))return!1}}return J.childNodes.length>0}function A$(J){let $="";for(let Y of J.childNodes)if(Y.nodeType===Node.TEXT_NODE)$+=Y.textContent||"";else if(Y.nodeType===Node.ELEMENT_NODE){let Z=Y;if(Z.tagName==="CODE")$+="`"+(Z.textContent||"")+"`";else $+=Z.textContent||""}return $.trim()}function I$(J,$,Y){let Z=J.getAttribute("data-md");if(Z)switch(Z){case"section":return C$(J,$,Y);case"item":return j$(J,$);case"codeblock":return R$(J,$);case"callout":return k$(J,$);case"note":return V$(J,$);case"table":return D$(J,$);case"checklist":return m$(J,$);case"diff":return g$(J,$);case"mermaid":return u$(J,$);case"choice":return E$(J,$);case"multichoice":return v$(J,$);case"choice-option":case"multichoice-option":return;case"userinput":return x$(J,$);case"rangeinput":return f$(J,$);case"checklist-item":return;case"filepreview":return h$(J,$);case"priority":return p$(J,$)}if(J.querySelector("button, input, select, textarea"))return;if(J.children.length>0)k0(J,$,Y);else{let Q=J.textContent?.trim();if(Q)$.push(Q,"")}}function C$(J,$,Y){let Z=J.getAttribute("data-md-title")||"Untitled",Q=Y===0?"##":"###";$.push(`${Q} ${Z}`,"");let q=J.querySelector(":scope > div:last-of-type");if(q)k0(q,$,Y+1)}function j$(J,$){let Y=J.getAttribute("data-md-label")||"",Z=J.getAttribute("data-md-status"),Q=J.getAttribute("data-md-badge"),q="-";if(Z==="done")q="- [x]";else if(Z)q="- [ ]";let X=`${q} **${Y}**`;if(Q)X+=` \`${Q}\``;$.push(X);let G=J.querySelector(".text-text-secondary");if(G){let _=[];k0(G,_,0);for(let z of _)$.push(z?` ${z}`:"")}$.push("")}function R$(J,$){let Y=J.getAttribute("data-md-language")||"",Q=J.querySelector("code")?.textContent||"";$.push(`\`\`\`${Y}`,Q,"```","")}function k$(J,$){let Y=J.getAttribute("data-md-type")||"info",Z={info:"Info",warning:"Warning",danger:"Danger",tip:"Tip"},Q=c$(J.querySelector(".text-text-secondary")||J);$.push(`> **${Z[Y]||Y}:** ${Q}`,"")}function V$(J,$){let Y=J.textContent?.trim()||"";$.push(`> *${Y}*`,"")}function D$(J,$){let Y=J.querySelector("table");if(!Y)return;let Z=[];for(let Q of Y.querySelectorAll("thead th"))Z.push(Q.textContent?.trim()||"");if(Z.length===0)return;$.push(`| ${Z.join(" | ")} |`),$.push(`| ${Z.map(()=>"---").join(" | ")} |`);for(let Q of Y.querySelectorAll("tbody tr")){let q=[];for(let X of Q.querySelectorAll("td"))q.push(X.textContent?.trim()||"");$.push(`| ${q.join(" | ")} |`)}$.push("")}function m$(J,$){for(let Y of J.querySelectorAll("li")){let Z=Y.querySelector(".bg-accent-green")!==null,Q=Y.textContent?.trim()||"";$.push(`- [${Z?"x":" "}] ${Q}`)}$.push("")}function g$(J,$){let Y=J.getAttribute("data-md-language")||"";$.push(`\`\`\`diff${Y?` (${Y})`:""}`);for(let Z of J.querySelectorAll("[class*='flex']")){let Q=Z.querySelector(".text-accent-red")?"-":Z.querySelector(".text-accent-green")?"+":" ",q=Z.querySelector("code");if(q)$.push(`${Q} ${q.textContent}`)}$.push("```","")}function u$(J,$){let Y=J.getAttribute("data-md-source")||"";if(Y)$.push("```mermaid",Y,"```","")}function E$(J,$){let Y=J.getAttribute("data-md-label")||"";$.push(`**${Y}:**`);for(let Z of J.querySelectorAll("[data-md='choice-option']")){let Q=Z.getAttribute("data-md-label")||Z.textContent?.trim()||"",q=Z.querySelector(".bg-accent-amber")!==null;$.push(`- ${q?"(x)":"( )"} ${Q}`)}$.push("")}function v$(J,$){let Y=J.getAttribute("data-md-label")||"";$.push(`**${Y}:**`);for(let Z of J.querySelectorAll("[data-md='multichoice-option']")){let Q=Z.getAttribute("data-md-label")||Z.textContent?.trim()||"",q=Z.querySelector(".bg-accent-amber")!==null;$.push(`- [${q?"x":" "}] ${Q}`)}$.push("")}function x$(J,$){let Y=J.getAttribute("data-md-label")||"",Q=J.querySelector("textarea")?.value?.trim()||"";$.push(`**${Y}:** ${Q||"_empty_"}`,"")}function f$(J,$){let Y=J.getAttribute("data-md-label")||"",Z=J.querySelector("input[type='range']"),q=J.querySelector(".font-mono")?.textContent?.trim()||Z?.value||"—";$.push(`**${Y}:** ${q}`,"")}function h$(J,$){let Y=J.getAttribute("data-md-path")||"",Z=J.getAttribute("data-md-lines")||"",q=J.querySelector("code")?.textContent||"",X=Y.split(".").pop()||"",G=j0[X]||"",_=Z?`${Y} (L${Z})`:Y;$.push(_,"",`\`\`\`${G}`,q,"```","")}function p$(J,$){}function c$(J){return J?.textContent?.trim()||""}import P2,{useEffect as w1,useState as Q1,useRef as L1,useCallback as S2,useMemo as g0,useContext as X4}from"react";import{useEffect as d$,useState as r$,useRef as l$,useContext as i$}from"react";import{jsxDEV as X1,Fragment as K2}from"react/jsx-dev-runtime";function a$(J){return J.label||`Round ${J.revision}`}function o$(J){let $=Date.now()-new Date(J).getTime(),Y=Math.floor($/1000);if(Y<60)return"just now";let Z=Math.floor(Y/60);if(Z<60)return`${Z}m ago`;let Q=Math.floor(Z/60);if(Q<24)return`${Q}h ago`;return`${Math.floor(Q/24)}d ago`}function q0({value:J,onChange:$,accent:Y="default",className:Z}){let{currentRevision:Q,revisions:q}=i$(N1),[X,G]=r$(!1),_=l$(null);d$(()=>{if(!X)return;let U=(W)=>{if(_.current&&!_.current.contains(W.target))G(!1)};return document.addEventListener("mousedown",U),()=>document.removeEventListener("mousedown",U)},[X]);let z=q.find((U)=>U.revision===J);return X1("div",{className:"relative",ref:_,children:[X1("button",{onClick:()=>G(!X),className:`flex items-center gap-1.5 text-[12px] font-body font-medium px-2 py-1 rounded-md transition-colors hover:bg-bg-elevated ${{default:"text-text-secondary hover:text-text-primary",red:"text-accent-red",green:"text-accent-green",amber:"text-accent-amber bg-highlight-selected"}[Y]} ${Z||""}`,children:[z?a$(z):`Round ${J}`,X1("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",className:`text-text-tertiary transition-transform duration-200 ${X?"rotate-180":""}`,children:X1("path",{d:"M2.5 4l2.5 2.5L7.5 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),X&&X1("div",{className:"absolute top-full left-0 mt-1 w-64 bg-bg-elevated border border-border-hover rounded-lg shadow-lg z-50 py-1 max-h-80 overflow-y-auto",children:[...q].reverse().map((U)=>X1("button",{onClick:()=>{$(U.revision),G(!1)},className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] font-body transition-colors ${U.revision===J?"bg-bg-surface text-text-primary":"text-text-secondary hover:bg-bg-surface hover:text-text-primary"}`,children:[X1("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${U.revision===Q?"bg-accent-green":U.hasFeedback?"bg-accent-amber":"bg-border-hover"}`},void 0,!1,void 0,this),X1("span",{className:"flex-1 text-left truncate",children:U.label?X1(K2,{children:[U.label," ",X1("span",{className:"text-text-tertiary",children:["#",U.revision]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):X1(K2,{children:["Round ",U.revision]},void 0,!0,void 0,this)},void 0,!1,void 0,this),X1("span",{className:"text-[10px] text-text-tertiary flex-shrink-0 flex items-center gap-1.5",children:[(()=>{let W=U.canvasFiles?.reduce((N,K)=>{if(K.diffStats)N.added+=K.diffStats.added,N.removed+=K.diffStats.removed;return N},{added:0,removed:0});if(W&&(W.added>0||W.removed>0))return X1("span",{className:"font-mono",children:[X1("span",{className:"text-accent-green",children:["+",W.added]},void 0,!0,void 0,this)," ",X1("span",{className:"text-accent-red",children:["-",W.removed]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);return null})(),U.revision===Q?"current":U.hasFeedback?"sent":o$(U.createdAt)]},void 0,!0,void 0,this)]},U.revision,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function b1(J,$){let Y=J.length,Z=$.length;if(Y===0||Z===0)return[];let Q=Array.from({length:Y+1},()=>Array(Z+1).fill(0));for(let _=1;_<=Y;_++)for(let z=1;z<=Z;z++)Q[_][z]=J[_-1]===$[z-1]?Q[_-1][z-1]+1:Math.max(Q[_-1][z],Q[_][z-1]);let q=[],X=Y,G=Z;while(X>0&&G>0)if(J[X-1]===$[G-1])q.unshift(J[X-1]),X--,G--;else if(Q[X-1][G]>Q[X][G-1])X--;else G--;return q}function H2(J){let $=[],Y=[],Z=document.createTreeWalker(J,NodeFilter.SHOW_TEXT,{acceptNode(q){let X=q.parentElement;if(!X)return NodeFilter.FILTER_REJECT;if(X.closest("svg, .select-none, [data-no-diff]"))return NodeFilter.FILTER_REJECT;return NodeFilter.FILTER_ACCEPT}}),Q;while(Q=Z.nextNode()){let X=(Q.nodeValue||"").match(/\S+|\s+/g);if(!X)continue;let G=0;for(let _ of X)$.push(_),Y.push({text:_,node:Q,offset:G}),G+=_.length}return{words:$,map:Y}}function K5(J,$){if(J.length>5000||$.length>5000)return s$(J,$);return T2(J,$)}function T2(J,$){let Y=V0(J,$),Z=[],Q=[],q=0,X=0,G=0;while(q<J.length||X<$.length)if(G<Y.length&&q<J.length&&X<$.length&&J[q]===Y[G]&&$[X]===Y[G])Z.push({type:"same",index:q}),Q.push({type:"same",index:X}),q++,X++,G++;else if(q<J.length&&(G>=Y.length||J[q]!==Y[G]))Z.push({type:"removed",index:q}),q++;else if(X<$.length)Q.push({type:"added",index:X}),X++;return{oldOps:Z,newOps:Q}}function V0(J,$){let Y=J.length,Z=$.length;if(Y===0||Z===0)return[];if(Y===1)return $.includes(J[0])?[J[0]]:[];if(Z===1)return J.includes($[0])?[$[0]]:[];if(Y*Z<=1e6)return b1(J,$);let Q=Math.floor(Y/2),q=J.slice(0,Q),X=J.slice(Q),G=W2(q,$),_=W2([...X].reverse(),[...$].reverse()),z=0,H=0;for(let N=0;N<=Z;N++){let K=G[N]+_[Z-N];if(K>z)z=K,H=N}let U=$.slice(0,H),W=$.slice(H);return[...V0(q,U),...V0(X,W)]}function W2(J,$){let Y=$.length,Z=Array(Y+1).fill(0),Q=Array(Y+1).fill(0);for(let q=0;q<J.length;q++){for(let X=1;X<=Y;X++)Q[X]=J[q]===$[X-1]?Z[X-1]+1:Math.max(Z[X],Q[X-1]);[Z,Q]=[Q,Z],Q.fill(0)}return Z}function s$(J,$){let Z=(K)=>{let T=[];for(let O=0;O<K.length;O+=200){let S=Math.min(O+200,K.length);T.push({start:O,end:S,text:K.slice(O,S).join("")})}return T},Q=Z(J),q=Z($),X=Q.map((K)=>K.text),G=q.map((K)=>K.text),_=V0(X,G),z=[],H=[],U=0,W=0,N=0;while(U<Q.length||W<q.length)if(N<_.length&&U<Q.length&&W<q.length&&X[U]===_[N]&&G[W]===_[N]){for(let K=Q[U].start;K<Q[U].end;K++)z.push({type:"same",index:K});for(let K=q[W].start;K<q[W].end;K++)H.push({type:"same",index:K});U++,W++,N++}else if(U<Q.length&&(N>=_.length||X[U]!==_[N]))if(W<q.length&&(N>=_.length||G[W]!==_[N])){let K=T2(J.slice(Q[U].start,Q[U].end),$.slice(q[W].start,q[W].end));for(let T of K.oldOps)z.push({type:T.type,index:T.index+Q[U].start});for(let T of K.newOps)H.push({type:T.type,index:T.index+q[W].start});U++,W++}else{for(let K=Q[U].start;K<Q[U].end;K++)z.push({type:"removed",index:K});U++}else if(W<q.length){for(let K=q[W].start;K<q[W].end;K++)H.push({type:"added",index:K});W++}return{oldOps:z,newOps:H}}function N2(J,$,Y){let Z=new Map;for(let Q of J){if(Q.type==="same")continue;let q=$[Q.index];if(!q||!q.node.parentNode)continue;let X=Z.get(q.node);if(!X)X=[],Z.set(q.node,X);X.push({offset:q.offset,length:q.text.length})}for(let[Q,q]of Z){if(!Q.parentNode)continue;let X=Q.nodeValue||"";q.sort((U,W)=>U.offset-W.offset);let G=[];for(let U of q){let W=G[G.length-1];if(W&&U.offset<=W.offset+W.length)W.length=Math.max(W.length,U.offset+U.length-W.offset);else G.push({...U})}let _=Q.parentNode,z=document.createDocumentFragment(),H=0;for(let U of G){if(U.offset>H)z.appendChild(document.createTextNode(X.slice(H,U.offset)));let W=document.createElement("span");W.className=Y,W.textContent=X.slice(U.offset,U.offset+U.length),z.appendChild(W),H=U.offset+U.length}if(H<X.length)z.appendChild(document.createTextNode(X.slice(H)));_.replaceChild(z,Q)}}function D0(J,$){let Y=t$(J,$),Z=H2(J),Q=H2($),{oldOps:q,newOps:X}=K5(Z.words,Q.words),G=q.some((_)=>_.type==="removed")||X.some((_)=>_.type==="added");return N2(q,Z.map,"diff-removed"),N2(X,Q.map,"diff-added"),G||Y}function t$(J,$){let Y=Array.from(J.querySelectorAll('[data-md="mermaid"]')),Z=Array.from($.querySelectorAll('[data-md="mermaid"]')),Q=!1,q=Math.max(Y.length,Z.length);for(let X=0;X<q;X++){let G=Y[X],_=Z[X];if(!G&&_){_.classList.add("diff-block-added"),_.style.position="relative",Q=!0;continue}if(G&&!_){G.classList.add("diff-block-removed"),G.style.position="relative",Q=!0;continue}if(!G||!_)continue;let z=(G.getAttribute("data-md-source")||"").trim(),H=(_.getAttribute("data-md-source")||"").trim();if(z===H)continue;Q=!0,G.style.borderLeft="3px solid var(--color-accent-red)",G.style.paddingLeft="8px",_.style.borderLeft="3px solid var(--color-accent-green)",_.style.paddingLeft="8px";let U=z.split(`
84
84
  `),W=H.split(`
85
- `),N=b1(U,W),K=(T,O,S)=>{let L=document.createElement("div");L.className="mt-2 bg-bg-code rounded-md overflow-hidden text-tiny font-mono",L.setAttribute("data-no-diff","true");let j=0,V=0;while(V<T.length){let M=document.createElement("div");if(M.className="px-3 py-0.5 whitespace-pre-wrap",j<O.length&&T[V]===O[j])M.textContent=" "+T[V],V++,j++;else M.classList.add(S==="old"?"diff-removed":"diff-added"),M.textContent=(S==="old"?"- ":"+ ")+T[V],V++;L.appendChild(M)}return L};G.appendChild(K(U,N,"old")),_.appendChild(K(W,N,"new"))}return Q}function a1(J){let $=[],Y=J.querySelectorAll(":scope > [data-md]");for(let Z of Y)$.push(_0(Z));if($.length===0){let Z=J.querySelectorAll("[data-md]"),Q=new Set;for(let q of Z){let X=q.parentElement?.closest("[data-md]");if(X&&J.contains(X))continue;if(Q.has(q))continue;Q.add(q),$.push(_0(q))}}return $}function _0(J){let $=J.getAttribute("data-md")||"unknown",Y=n$(J,$),Z=[];if($==="section"){let Q=J.querySelector(":scope > div.mt-6, :scope > div:last-child");if(Q)for(let q of Q.querySelectorAll(":scope > [data-md]"))Z.push(_0(q))}else if($==="table")for(let Q of J.querySelectorAll(":scope table > tbody > tr"))Z.push({key:"tr:"+(Q.textContent||"").slice(0,80),type:"tr",element:Q,children:[]});else if($==="checklist")for(let Q of J.querySelectorAll(":scope > [data-md='checklist-item']"))Z.push(_0(Q));else for(let Q of J.querySelectorAll("[data-md]"))if(Q.parentElement?.closest("[data-md]")===J)Z.push(_0(Q));return{key:Y,type:$,element:J,children:Z}}function n$(J,$){switch($){case"section":return"section:"+(J.getAttribute("data-md-title")||"");case"item":return"item:"+(J.getAttribute("data-task-id")||J.getAttribute("data-md-label")||"");case"codeblock":case"diff":return $+":"+(J.textContent||"").slice(0,80);case"checklist-item":return"checklist-item:"+(J.getAttribute("data-md-label")||J.textContent?.slice(0,60)||"");case"checklist":return"checklist:"+J.querySelectorAll("[data-md='checklist-item']").length;case"markdown":return"markdown:"+(J.getAttribute("data-md-file")||"inline");case"mermaid":return"mermaid:"+(J.getAttribute("data-md-source")||"").slice(0,80);case"callout":return"callout:"+(J.getAttribute("data-md-type")||"")+":"+(J.textContent||"").slice(0,60);default:return $+":"+(J.getAttribute("data-md-label")||J.textContent?.slice(0,60)||"")}}function z0(J,$){let Y=J.map((z)=>z.key),Z=$.map((z)=>z.key),Q=b1(Y,Z),q=[],X=0,G=0,_=0;while(X<J.length||G<$.length)if(_<Q.length&&X<J.length&&G<$.length&&Y[X]===Q[_]&&Z[G]===Q[_]){let z=J[X],H=$[G],U=z.children.length>0||H.children.length>0?z0(z.children,H.children):void 0;q.push({kind:"matched",oldBlock:z,newBlock:H,childMatches:U}),X++,G++,_++}else if(X<J.length&&(_>=Q.length||Y[X]!==Q[_]))q.push({kind:"removed",oldBlock:J[X]}),X++;else if(G<$.length)q.push({kind:"added",newBlock:$[G]}),G++;return q}function m0(J){let $=document.createDocumentFragment(),Y=!1;for(let Z of J)if(Z.kind==="removed")Y=!0,$.appendChild(F2(Z.oldBlock.element));else if(Z.kind==="added")Y=!0,$.appendChild(e$(Z.newBlock.element));else{let Q=Z.newBlock.element.cloneNode(!0),q=Z.newBlock.type;if(q==="mermaid"){if(M2(Z.oldBlock.element,Q))Y=!0}else if(Z.childMatches&&Z.childMatches.length>0&&(q==="table"||q==="checklist")){if(B2(Q,Z.childMatches,q))Y=!0}else if(Z.childMatches&&Z.childMatches.length>0){if(L2(Z.oldBlock,Q,Z.childMatches,q))Y=!0}else if(q==="markdown"){if(y2(Z.oldBlock.element,Q))Y=!0}else if(h1(Z.oldBlock.element,Q,!1))Y=!0;$.appendChild(Q)}return{fragment:$,hasChanges:Y}}function F2(J){let $=J.cloneNode(!0);return $.classList.add("diff-block-removed"),$.style.position="relative",H5($,"Removed","var(--color-accent-red)"),$}function e$(J){let $=J.cloneNode(!0);return $.classList.add("diff-block-added"),$.style.position="relative",H5($,"Added","var(--color-accent-green)"),$}function L2(J,$,Y,Z){let Q=!1,q=$4(J,$),X,G;if(Z==="section"){let _=J.element.querySelector(":scope > div:first-child"),z=$.querySelector(":scope > div:first-child");if(_&&z){if(h1(_,z,!1))Q=!0}X=J.element.querySelector(":scope > div.mt-6, :scope > div:last-child"),G=$.querySelector(":scope > div.mt-6, :scope > div:last-child")}else X=J.element,G=$;if(!X||!G)return Q;for(let _ of Y)if(_.kind==="matched"){let z=q.newMap.get(_.newBlock.element);if(z){if(_.newBlock.type==="mermaid"){if(M2(_.oldBlock.element,z))Q=!0}else if(_.childMatches&&_.childMatches.length>0&&(_.newBlock.type==="table"||_.newBlock.type==="checklist")){if(B2(z,_.childMatches,_.newBlock.type))Q=!0}else if(_.childMatches&&_.childMatches.length>0){if(L2(_.oldBlock,z,_.childMatches,_.newBlock.type))Q=!0}else if(_.newBlock.type==="markdown"){if(y2(_.oldBlock.element,z))Q=!0}else if(h1(_.oldBlock.element,z,!1))Q=!0}}else if(_.kind==="removed"){Q=!0;let z=F2(_.oldBlock.element),H=Y4(Y,_,q.newMap);G.insertBefore(z,H)}else if(_.kind==="added"){Q=!0;let z=q.newMap.get(_.newBlock.element);if(z)z.classList.add("diff-block-added"),z.style.position="relative",H5(z,"Added","var(--color-accent-green)")}if(h1(X,G,!0))Q=!0;return Q}function B2(J,$,Y){let Z=Y==="table"?J.querySelector(":scope table > tbody"):J;if(!Z)return!1;let Q=!1;Z.innerHTML="";for(let q of $)if(q.kind==="removed"){Q=!0;let X=q.oldBlock.element.cloneNode(!0);X.classList.add(Y==="table"?"diff-row-removed":"diff-item-removed"),Z.appendChild(X)}else if(q.kind==="added"){Q=!0;let X=q.newBlock.element.cloneNode(!0);X.classList.add(Y==="table"?"diff-row-added":"diff-item-added"),Z.appendChild(X)}else{let X=q.newBlock.element.cloneNode(!0);if(h1(q.oldBlock.element,X,!1))Q=!0;Z.appendChild(X)}return Q}function $4(J,$){let Y=new Map,Z=J.element.querySelectorAll("[data-md]"),Q=$.querySelectorAll("[data-md]");return{newMap:{get(q){return J4($,q)}}}}function J4(J,$){let Y=$.getAttribute("data-md");if(!Y)return null;let Z=$.getAttribute("data-md-label"),Q=$.getAttribute("data-md-title"),q=`[data-md="${Y}"]`;if(Q)q+=`[data-md-title="${CSS.escape(Q)}"]`;else if(Z)q+=`[data-md-label="${CSS.escape(Z)}"]`;let X=J.querySelectorAll(q);if(X.length===1)return X[0];let G=($.textContent||"").slice(0,100),_=null,z=-1;for(let H of X){let U=(H.textContent||"").slice(0,100),W=0;for(let N=0;N<Math.min(G.length,U.length);N++)if(G[N]===U[N])W++;if(W>z)z=W,_=H}return _}function Y4(J,$,Y){let Z=J.indexOf($);for(let Q=Z+1;Q<J.length;Q++){let q=J[Q];if((q.kind==="matched"||q.kind==="added")&&q.newBlock)return Y.get(q.newBlock.element)||null}return null}function y2(J,$){let Y=Array.from(J.children),Z=Array.from($.children);if(Y.length===0&&Z.length===0)return h1(J,$,!1);let Q=Y.map((W)=>W.tagName.toLowerCase()),q=Z.map((W)=>W.tagName.toLowerCase()),X=b1(Q,q),G=[],_=0,z=0,H=0;while(_<Y.length||z<Z.length)if(H<X.length&&_<Y.length&&z<Z.length&&Q[_]===X[H]&&q[z]===X[H])G.push({kind:"matched",oldChild:Y[_],newChild:Z[z]}),_++,z++,H++;else if(_<Y.length&&(H>=X.length||Q[_]!==X[H]))G.push({kind:"removed",oldChild:Y[_]}),_++;else if(z<Z.length)G.push({kind:"added",newChild:Z[z]}),z++;let U=!1;while($.firstChild)$.removeChild($.firstChild);for(let W of G)if(W.kind==="matched"){let N=(W.oldChild.textContent||"").match(/\S+/g)||[],K=(W.newChild.textContent||"").match(/\S+/g)||[],T=b1(N,K),O=Math.max(N.length,K.length);if((O>0?1-T.length/O:0)>0.5){U=!0;let L=W.oldChild.cloneNode(!0);L.classList.add("diff-block-removed"),$.appendChild(L),W.newChild.classList.add("diff-block-added"),$.appendChild(W.newChild)}else{if(h1(W.oldChild,W.newChild,!1))U=!0;$.appendChild(W.newChild)}}else if(W.kind==="removed"){U=!0;let N=W.oldChild.cloneNode(!0);N.classList.add("diff-block-removed"),$.appendChild(N)}else U=!0,W.newChild.classList.add("diff-block-added"),$.appendChild(W.newChild);return U}function O2(J,$){let Y=$?new Set(Array.from(J.querySelectorAll("[data-md]"))):new Set,Z=[],Q=[],q=document.createTreeWalker(J,NodeFilter.SHOW_TEXT,{acceptNode(G){let _=G.parentElement;if(!_)return NodeFilter.FILTER_REJECT;if(_.closest("svg, .select-none, [data-no-diff]"))return NodeFilter.FILTER_REJECT;if($){for(let z of Y)if(z.contains(G))return NodeFilter.FILTER_REJECT}return NodeFilter.FILTER_ACCEPT}}),X;while(X=q.nextNode()){let _=(X.nodeValue||"").match(/\S+|\s+/g);if(!_)continue;let z=0;for(let H of _)Z.push(H),Q.push({text:H,node:X,offset:z}),z+=H.length}return{words:Z,map:Q}}function h1(J,$,Y){let Z=O2(J,Y),Q=O2($,Y);if(Z.words.length===0&&Q.words.length===0)return!1;let{oldOps:q,newOps:X}=K5(Z.words,Q.words),G=q.some((O)=>O.type==="removed"),_=X.some((O)=>O.type==="added");if(!G&&!_)return!1;let z=[],H=[];for(let O of q)if(O.type==="same")z.push(O.index);for(let O of X)if(O.type==="same")H.push(O.index);let U=new Map;for(let O=0;O<z.length&&O<H.length;O++)U.set(z[O],H[O]);let W=[];{let O=[],S=-1;for(let L of q)if(L.type==="same"){if(O.length>0)W.push({text:O.join(""),anchorNewIdx:S>=0?U.get(S)??null:null}),O=[];S=L.index}else if(L.type==="removed")O.push(Z.words[L.index]);if(O.length>0)W.push({text:O.join(""),anchorNewIdx:S>=0?U.get(S)??null:null})}let N=new Map,K=new Map;for(let O of X){if(O.type!=="added")continue;let S=Q.map[O.index];if(!S?.node.parentNode)continue;let L=N.get(S.node);if(!L)L=[],N.set(S.node,L);L.push({start:S.offset,end:S.offset+S.text.length})}for(let O of W)if(O.anchorNewIdx===null){if(Q.map.length>0){let S=Q.map[0].node,L=K.get(S);if(!L)L=[],K.set(S,L);L.push({offset:0,text:O.text})}}else{let S=Q.map[O.anchorNewIdx];if(!S)continue;let L=K.get(S.node);if(!L)L=[],K.set(S.node,L);L.push({offset:S.offset+S.text.length,text:O.text})}let T=new Set([...N.keys(),...K.keys()]);for(let O of T)Q4(O,N.get(O)||[],K.get(O)||[]);return!0}function Q4(J,$,Y){if(!J.parentNode)return;let Z=J.nodeValue||"";$.sort((H,U)=>H.start-U.start);let Q=[];for(let H of $){let U=Q[Q.length-1];if(U&&H.start<=U.end)U.end=Math.max(U.end,H.end);else Q.push({...H})}Y.sort((H,U)=>H.offset-U.offset);let q=J.parentNode,X=document.createDocumentFragment(),G=0,_=0,z=0;while(G<=Z.length){let H=_<Q.length?Q[_].start:1/0,U=z<Y.length?Y[z].offset:1/0,W=Math.min(H,U);if(W===1/0){if(G<Z.length)X.appendChild(document.createTextNode(Z.slice(G)));break}let N=Math.max(W,G);if(N>G)X.appendChild(document.createTextNode(Z.slice(G,N))),G=N;while(z<Y.length&&Y[z].offset<=G){let K=document.createElement("span");K.className="diff-removed",K.textContent=Y[z].text,X.appendChild(K),z++}if(_<Q.length&&Q[_].start<=G){let K=Q[_],T=document.createElement("span");T.className="diff-added",T.textContent=Z.slice(G,K.end),X.appendChild(T),G=K.end,_++;while(z<Y.length&&Y[z].offset<=G){let O=document.createElement("span");O.className="diff-removed",O.textContent=Y[z].text,X.appendChild(O),z++}}}while(z<Y.length){let H=document.createElement("span");H.className="diff-removed",H.textContent=Y[z].text,X.appendChild(H),z++}q.replaceChild(X,J)}function M2(J,$){let Y=(J.getAttribute("data-md-source")||"").trim(),Z=($.getAttribute("data-md-source")||"").trim();if(Y===Z)return!1;let Q=Y.split(`
85
+ `),N=b1(U,W),K=(T,O,S)=>{let L=document.createElement("div");L.className="mt-2 bg-bg-code rounded-md overflow-hidden text-tiny font-mono",L.setAttribute("data-no-diff","true");let j=0,V=0;while(V<T.length){let M=document.createElement("div");if(M.className="px-3 py-0.5 whitespace-pre-wrap",j<O.length&&T[V]===O[j])M.textContent=" "+T[V],V++,j++;else M.classList.add(S==="old"?"diff-removed":"diff-added"),M.textContent=(S==="old"?"- ":"+ ")+T[V],V++;L.appendChild(M)}return L};G.appendChild(K(U,N,"old")),_.appendChild(K(W,N,"new"))}return Q}function a1(J){let $=[],Y=J.querySelectorAll(":scope > [data-md]");for(let Z of Y)$.push(_0(Z));if($.length===0){let Z=J.querySelectorAll("[data-md]"),Q=new Set;for(let q of Z){let X=q.parentElement?.closest("[data-md]");if(X&&J.contains(X))continue;if(Q.has(q))continue;Q.add(q),$.push(_0(q))}}return $}function _0(J){let $=J.getAttribute("data-md")||"unknown",Y=n$(J,$),Z=[];if($==="section"){let Q=J.querySelector(":scope > div.mt-6, :scope > div:last-child");if(Q)for(let q of Q.querySelectorAll(":scope > [data-md]"))Z.push(_0(q))}else if($==="table")for(let Q of J.querySelectorAll(":scope table > tbody > tr"))Z.push({key:"tr:"+(Q.textContent||"").slice(0,80),type:"tr",element:Q,children:[]});else if($==="checklist")for(let Q of J.querySelectorAll(":scope > [data-md='checklist-item']"))Z.push(_0(Q));else for(let Q of J.querySelectorAll("[data-md]"))if(Q.parentElement?.closest("[data-md]")===J)Z.push(_0(Q));return{key:Y,type:$,element:J,children:Z}}function n$(J,$){switch($){case"section":return"section:"+(J.getAttribute("data-md-title")||"");case"item":return"item:"+(J.getAttribute("data-task-id")||J.getAttribute("data-md-label")||"");case"codeblock":case"diff":return $+":"+(J.textContent||"").slice(0,80);case"checklist-item":return"checklist-item:"+(J.getAttribute("data-md-label")||J.textContent?.slice(0,60)||"");case"checklist":return"checklist:"+J.querySelectorAll("[data-md='checklist-item']").length;case"markdown":return"markdown:"+(J.getAttribute("data-md-file")||"inline");case"mermaid":return"mermaid:"+(J.getAttribute("data-md-source")||"").slice(0,80);case"callout":return"callout:"+(J.getAttribute("data-md-type")||"")+":"+(J.textContent||"").slice(0,60);default:return $+":"+(J.getAttribute("data-md-label")||J.textContent?.slice(0,60)||"")}}function z0(J,$){let Y=J.map((z)=>z.key),Z=$.map((z)=>z.key),Q=b1(Y,Z),q=[],X=0,G=0,_=0;while(X<J.length||G<$.length)if(_<Q.length&&X<J.length&&G<$.length&&Y[X]===Q[_]&&Z[G]===Q[_]){let z=J[X],H=$[G],U=z.children.length>0||H.children.length>0?z0(z.children,H.children):void 0;q.push({kind:"matched",oldBlock:z,newBlock:H,childMatches:U}),X++,G++,_++}else if(X<J.length&&(_>=Q.length||Y[X]!==Q[_]))q.push({kind:"removed",oldBlock:J[X]}),X++;else if(G<$.length)q.push({kind:"added",newBlock:$[G]}),G++;return q}function m0(J){let $=document.createDocumentFragment(),Y=!1;for(let Z of J)if(Z.kind==="removed")Y=!0,$.appendChild(F2(Z.oldBlock.element));else if(Z.kind==="added")Y=!0,$.appendChild(e$(Z.newBlock.element));else{let Q=Z.newBlock.element.cloneNode(!0),q=Z.newBlock.type;if(q==="mermaid"){if(M2(Z.oldBlock.element,Q))Y=!0}else if(Z.childMatches&&Z.childMatches.length>0&&(q==="table"||q==="checklist")){if(B2(Q,Z.childMatches,q))Y=!0}else if(Z.childMatches&&Z.childMatches.length>0){if(L2(Z.oldBlock,Q,Z.childMatches,q))Y=!0}else if(q==="markdown"){if(y2(Z.oldBlock.element,Q))Y=!0}else if(h1(Z.oldBlock.element,Q,!1))Y=!0;$.appendChild(Q)}return{fragment:$,hasChanges:Y}}function F2(J){let $=J.cloneNode(!0);return $.classList.add("diff-block-removed"),$.style.position="relative",H5($,"Removed","var(--color-accent-red)"),$}function e$(J){let $=J.cloneNode(!0);return $.classList.add("diff-block-added"),$.style.position="relative",H5($,"Added","var(--color-accent-green)"),$}function L2(J,$,Y,Z){let Q=!1,q=$4(J,$),X,G;if(Z==="section"){let _=J.element.querySelector(":scope > div:first-child"),z=$.querySelector(":scope > div:first-child");if(_&&z){if(h1(_,z,!1))Q=!0}X=J.element.querySelector(":scope > div.mt-6, :scope > div:last-child"),G=$.querySelector(":scope > div.mt-6, :scope > div:last-child")}else X=J.element,G=$;if(!X||!G)return Q;for(let _ of Y)if(_.kind==="matched"){let z=q.newMap.get(_.newBlock.element);if(z){if(_.newBlock.type==="mermaid"){if(M2(_.oldBlock.element,z))Q=!0}else if(_.childMatches&&_.childMatches.length>0&&(_.newBlock.type==="table"||_.newBlock.type==="checklist")){if(B2(z,_.childMatches,_.newBlock.type))Q=!0}else if(_.childMatches&&_.childMatches.length>0){if(L2(_.oldBlock,z,_.childMatches,_.newBlock.type))Q=!0}else if(_.newBlock.type==="markdown"){if(y2(_.oldBlock.element,z))Q=!0}else if(h1(_.oldBlock.element,z,!1))Q=!0}}else if(_.kind==="removed"){Q=!0;let z=F2(_.oldBlock.element),H=Y4(Y,_,q.newMap),U=H?Q4(G,H):null;G.insertBefore(z,U)}else if(_.kind==="added"){Q=!0;let z=q.newMap.get(_.newBlock.element);if(z)z.classList.add("diff-block-added"),z.style.position="relative",H5(z,"Added","var(--color-accent-green)")}if(h1(X,G,!0))Q=!0;return Q}function B2(J,$,Y){let Z=Y==="table"?J.querySelector(":scope table > tbody"):J;if(!Z)return!1;let Q=!1;Z.innerHTML="";for(let q of $)if(q.kind==="removed"){Q=!0;let X=q.oldBlock.element.cloneNode(!0);X.classList.add(Y==="table"?"diff-row-removed":"diff-item-removed"),Z.appendChild(X)}else if(q.kind==="added"){Q=!0;let X=q.newBlock.element.cloneNode(!0);X.classList.add(Y==="table"?"diff-row-added":"diff-item-added"),Z.appendChild(X)}else{let X=q.newBlock.element.cloneNode(!0);if(h1(q.oldBlock.element,X,!1))Q=!0;Z.appendChild(X)}return Q}function $4(J,$){let Y=new Map,Z=J.element.querySelectorAll("[data-md]"),Q=$.querySelectorAll("[data-md]");return{newMap:{get(q){return J4($,q)}}}}function J4(J,$){let Y=$.getAttribute("data-md");if(!Y)return null;let Z=$.getAttribute("data-md-label"),Q=$.getAttribute("data-md-title"),q=`[data-md="${Y}"]`;if(Q)q+=`[data-md-title="${CSS.escape(Q)}"]`;else if(Z)q+=`[data-md-label="${CSS.escape(Z)}"]`;let X=J.querySelectorAll(q);if(X.length===1)return X[0];let G=($.textContent||"").slice(0,100),_=null,z=-1;for(let H of X){let U=(H.textContent||"").slice(0,100),W=0;for(let N=0;N<Math.min(G.length,U.length);N++)if(G[N]===U[N])W++;if(W>z)z=W,_=H}return _}function Y4(J,$,Y){let Z=J.indexOf($);for(let Q=Z+1;Q<J.length;Q++){let q=J[Q];if((q.kind==="matched"||q.kind==="added")&&q.newBlock)return Y.get(q.newBlock.element)||null}return null}function Q4(J,$){let Y=$;while(Y&&Y.parentElement!==J)Y=Y.parentElement;return Y}function y2(J,$){let Y=Array.from(J.children),Z=Array.from($.children);if(Y.length===0&&Z.length===0)return h1(J,$,!1);let Q=Y.map((W)=>W.tagName.toLowerCase()),q=Z.map((W)=>W.tagName.toLowerCase()),X=b1(Q,q),G=[],_=0,z=0,H=0;while(_<Y.length||z<Z.length)if(H<X.length&&_<Y.length&&z<Z.length&&Q[_]===X[H]&&q[z]===X[H])G.push({kind:"matched",oldChild:Y[_],newChild:Z[z]}),_++,z++,H++;else if(_<Y.length&&(H>=X.length||Q[_]!==X[H]))G.push({kind:"removed",oldChild:Y[_]}),_++;else if(z<Z.length)G.push({kind:"added",newChild:Z[z]}),z++;let U=!1;while($.firstChild)$.removeChild($.firstChild);for(let W of G)if(W.kind==="matched"){let N=(W.oldChild.textContent||"").match(/\S+/g)||[],K=(W.newChild.textContent||"").match(/\S+/g)||[],T=b1(N,K),O=Math.max(N.length,K.length);if((O>0?1-T.length/O:0)>0.5){U=!0;let L=W.oldChild.cloneNode(!0);L.classList.add("diff-block-removed"),$.appendChild(L),W.newChild.classList.add("diff-block-added"),$.appendChild(W.newChild)}else{if(h1(W.oldChild,W.newChild,!1))U=!0;$.appendChild(W.newChild)}}else if(W.kind==="removed"){U=!0;let N=W.oldChild.cloneNode(!0);N.classList.add("diff-block-removed"),$.appendChild(N)}else U=!0,W.newChild.classList.add("diff-block-added"),$.appendChild(W.newChild);return U}function O2(J,$){let Y=$?new Set(Array.from(J.querySelectorAll("[data-md]"))):new Set,Z=[],Q=[],q=document.createTreeWalker(J,NodeFilter.SHOW_TEXT,{acceptNode(G){let _=G.parentElement;if(!_)return NodeFilter.FILTER_REJECT;if(_.closest("svg, .select-none, [data-no-diff]"))return NodeFilter.FILTER_REJECT;if($){for(let z of Y)if(z.contains(G))return NodeFilter.FILTER_REJECT}return NodeFilter.FILTER_ACCEPT}}),X;while(X=q.nextNode()){let _=(X.nodeValue||"").match(/\S+|\s+/g);if(!_)continue;let z=0;for(let H of _)Z.push(H),Q.push({text:H,node:X,offset:z}),z+=H.length}return{words:Z,map:Q}}function h1(J,$,Y){let Z=O2(J,Y),Q=O2($,Y);if(Z.words.length===0&&Q.words.length===0)return!1;let{oldOps:q,newOps:X}=K5(Z.words,Q.words),G=q.some((O)=>O.type==="removed"),_=X.some((O)=>O.type==="added");if(!G&&!_)return!1;let z=[],H=[];for(let O of q)if(O.type==="same")z.push(O.index);for(let O of X)if(O.type==="same")H.push(O.index);let U=new Map;for(let O=0;O<z.length&&O<H.length;O++)U.set(z[O],H[O]);let W=[];{let O=[],S=-1;for(let L of q)if(L.type==="same"){if(O.length>0)W.push({text:O.join(""),anchorNewIdx:S>=0?U.get(S)??null:null}),O=[];S=L.index}else if(L.type==="removed")O.push(Z.words[L.index]);if(O.length>0)W.push({text:O.join(""),anchorNewIdx:S>=0?U.get(S)??null:null})}let N=new Map,K=new Map;for(let O of X){if(O.type!=="added")continue;let S=Q.map[O.index];if(!S?.node.parentNode)continue;let L=N.get(S.node);if(!L)L=[],N.set(S.node,L);L.push({start:S.offset,end:S.offset+S.text.length})}for(let O of W)if(O.anchorNewIdx===null){if(Q.map.length>0){let S=Q.map[0].node,L=K.get(S);if(!L)L=[],K.set(S,L);L.push({offset:0,text:O.text})}}else{let S=Q.map[O.anchorNewIdx];if(!S)continue;let L=K.get(S.node);if(!L)L=[],K.set(S.node,L);L.push({offset:S.offset+S.text.length,text:O.text})}let T=new Set([...N.keys(),...K.keys()]);for(let O of T)Z4(O,N.get(O)||[],K.get(O)||[]);return!0}function Z4(J,$,Y){if(!J.parentNode)return;let Z=J.nodeValue||"";$.sort((H,U)=>H.start-U.start);let Q=[];for(let H of $){let U=Q[Q.length-1];if(U&&H.start<=U.end)U.end=Math.max(U.end,H.end);else Q.push({...H})}Y.sort((H,U)=>H.offset-U.offset);let q=J.parentNode,X=document.createDocumentFragment(),G=0,_=0,z=0;while(G<=Z.length){let H=_<Q.length?Q[_].start:1/0,U=z<Y.length?Y[z].offset:1/0,W=Math.min(H,U);if(W===1/0){if(G<Z.length)X.appendChild(document.createTextNode(Z.slice(G)));break}let N=Math.max(W,G);if(N>G)X.appendChild(document.createTextNode(Z.slice(G,N))),G=N;while(z<Y.length&&Y[z].offset<=G){let K=document.createElement("span");K.className="diff-removed",K.textContent=Y[z].text,X.appendChild(K),z++}if(_<Q.length&&Q[_].start<=G){let K=Q[_],T=document.createElement("span");T.className="diff-added",T.textContent=Z.slice(G,K.end),X.appendChild(T),G=K.end,_++;while(z<Y.length&&Y[z].offset<=G){let O=document.createElement("span");O.className="diff-removed",O.textContent=Y[z].text,X.appendChild(O),z++}}}while(z<Y.length){let H=document.createElement("span");H.className="diff-removed",H.textContent=Y[z].text,X.appendChild(H),z++}q.replaceChild(X,J)}function M2(J,$){let Y=(J.getAttribute("data-md-source")||"").trim(),Z=($.getAttribute("data-md-source")||"").trim();if(Y===Z)return!1;let Q=Y.split(`
86
86
  `),q=Z.split(`
87
- `),X=b1(Q,q),G=[],_=0,z=0,H=0;while(_<Q.length||z<q.length)if(H<X.length&&_<Q.length&&z<q.length&&Q[_]===X[H]&&q[z]===X[H])G.push({type:"same",line:Q[_]}),_++,z++,H++;else if(_<Q.length&&(H>=X.length||Q[_]!==X[H]))G.push({type:"removed",line:Q[_]}),_++;else if(z<q.length)G.push({type:"added",line:q[z]}),z++;let U=document.createElement("div");U.className="mt-2 bg-bg-code rounded-md overflow-hidden text-tiny font-mono",U.setAttribute("data-no-diff","true");for(let W of G){let N=document.createElement("div");if(N.className="px-3 py-0.5 whitespace-pre-wrap",W.type==="removed")N.classList.add("diff-removed"),N.textContent="- "+W.line;else if(W.type==="added")N.classList.add("diff-added"),N.textContent="+ "+W.line;else N.textContent=" "+W.line;U.appendChild(N)}return $.appendChild(U),!0}function H5(J,$,Y){let Z=document.createElement("span");Z.className="diff-block-label",Z.textContent=$,Z.style.color=Y,Z.style.backgroundColor=`color-mix(in srgb, ${Y} 12%, transparent)`,J.appendChild(Z)}import{jsxDEV as f}from"react/jsx-dev-runtime";function X4(J,$,Y){let Z=J.find((X)=>X.revision===$),Q=J.find((X)=>X.revision===Y),q=new Set;for(let X of Z?.canvasFiles||[])q.add(X.filename);for(let X of Q?.canvasFiles||[])q.add(X.filename);return[...q].sort()}function b2({initialLeft:J,initialRight:$,sessionId:Y,onExit:Z}){let[Q,q]=Q1(J),[X,G]=Q1($),[_,z]=Q1("unified"),[H,U]=Q1(!0),[W,N]=Q1(!1),{revisions:K}=Z4(N1),T=g0(()=>X4(K,Q,X),[K,Q,X]),[O,S]=Q1(()=>T[0]||"plan.jsx");w1(()=>{if(!T.includes(O))S(T[0]||"plan.jsx")},[T,O]);let L=g0(()=>{return K.find((M)=>M.revision===Q)?.canvasFiles.some((M)=>M.filename===O)??!1},[K,Q,O]),j=g0(()=>{return K.find((M)=>M.revision===X)?.canvasFiles.some((M)=>M.filename===O)??!1},[K,X,O]);return f("div",{className:"flex flex-col h-screen",children:[f("div",{className:"flex items-center justify-between px-6 py-3 border-b border-border-subtle bg-bg-surface flex-shrink-0",children:[f("div",{className:"flex items-center gap-3",children:[f("span",{className:"text-[13px] font-body font-medium text-text-primary",children:"Compare"},void 0,!1,void 0,this),f(q0,{value:Q,onChange:q,accent:"red"},void 0,!1,void 0,this),f("span",{className:"text-text-tertiary text-[13px]",children:"→"},void 0,!1,void 0,this),f(q0,{value:X,onChange:G,accent:"green"},void 0,!1,void 0,this),W&&!H&&f("span",{className:"text-[11px] font-body text-text-tertiary bg-bg-elevated px-2 py-0.5 rounded",children:"No changes"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),f("div",{className:"flex items-center gap-4",children:[f("div",{className:"flex items-center bg-bg-elevated rounded-md p-0.5",children:[f("button",{onClick:()=>z("unified"),className:`text-[11px] font-body px-2.5 py-1 rounded transition-colors ${_==="unified"?"bg-bg-surface text-text-primary font-medium shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Unified"},void 0,!1,void 0,this),f("button",{onClick:()=>z("side-by-side"),className:`text-[11px] font-body px-2.5 py-1 rounded transition-colors ${_==="side-by-side"?"bg-bg-surface text-text-primary font-medium shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Side-by-side"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),_==="side-by-side"&&f(q4,{},void 0,!1,void 0,this),f("button",{onClick:Z,className:"text-[12px] font-body font-medium text-text-secondary hover:text-text-primary px-3 py-1.5 rounded-md hover:bg-bg-elevated transition-colors",children:"Exit Compare"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),T.length>1&&f("div",{className:"flex items-center gap-1 px-6 py-2 border-b border-border-subtle bg-bg-surface flex-shrink-0 overflow-x-auto",children:T.map((V)=>{let M=V.replace(/\.jsx$/,""),I=V===O,D=K.find((R)=>R.revision===Q)?.canvasFiles.some((R)=>R.filename===V),E=K.find((R)=>R.revision===X)?.canvasFiles.some((R)=>R.filename===V),C=!D?" (added)":!E?" (removed)":"";return f("button",{onClick:()=>S(V),className:`text-[12px] font-body px-3 py-1 rounded-md transition-colors whitespace-nowrap ${I?"bg-bg-elevated text-text-primary font-medium":"text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated"}`,children:[M,C&&f("span",{className:`ml-1 text-[10px] ${!D?"text-accent-green":"text-accent-red"}`,children:C},void 0,!1,void 0,this)]},V,!0,void 0,this)})},void 0,!1,void 0,this),!L||!j?f("div",{className:"flex-1 flex items-center justify-center",children:f("div",{className:"text-center text-text-tertiary font-body",children:[f("div",{className:"text-lg mb-2",children:!L?"New file":"Removed file"},void 0,!1,void 0,this),f("div",{className:"text-[13px]",children:[O.replace(/\.jsx$/,"")," ",!L?"was added":"was removed"," in this revision"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this):_==="unified"?f(_4,{sessionId:Y,leftRev:Q,rightRev:X,filename:O,onDiffResult:(V,M)=>{N(V),U(M)}},`unified-${Q}-${X}-${O}`,!1,void 0,this):f(z4,{sessionId:Y,leftRev:Q,rightRev:X,filename:O,onDiffResult:(V,M)=>{N(V),U(M)}},`sbs-${Q}-${X}-${O}`,!1,void 0,this)]},void 0,!0,void 0,this)}function q4(){let[J,$]=Q1(!0);return w1(()=>{return document.documentElement.dataset.syncScroll=J?"1":"0",()=>{delete document.documentElement.dataset.syncScroll}},[J]),f("label",{className:"flex items-center gap-1.5 cursor-pointer select-none",children:[f("input",{type:"checkbox",checked:J,onChange:(Y)=>$(Y.target.checked),className:"accent-accent-amber w-3.5 h-3.5"},void 0,!1,void 0,this),f("span",{className:"text-[11px] font-body text-text-secondary",children:"Sync scroll"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function _4({sessionId:J,leftRev:$,rightRev:Y,filename:Z,onDiffResult:Q}){let q=L1(null),X=L1(null),G=L1(null),[_,z]=Q1(!1),[H,U]=Q1(!1),[W,N]=Q1(!1),[K,T]=Q1(null),[O,S]=Q1(!1),{annotations:L}=e(),j=L.filter((M)=>!M.filePath&&(!M.canvasFile||M.canvasFile===Z)),{popovers:V}=E1({containerRef:G,restoreKey:W,restoreAnnotations:j,extractContext:(M)=>D1(M,G.current)});return w1(()=>{if(W||K)return;let M=setTimeout(()=>{console.warn("[unified-diff] still loading after 10s",{leftReady:_,rightReady:H,oldRef:!!q.current,newRef:!!X.current}),S(!0)},1e4);return()=>clearTimeout(M)},[W,K,_,H]),w1(()=>{if(!_||!H||W)return;if(!q.current||!X.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!q.current||!X.current||!G.current){console.warn("[unified-diff] refs lost between rAF frames",{old:!!q.current,new:!!X.current,unified:!!G.current});return}try{let M=a1(q.current),I=a1(X.current),D=z0(M,I),{fragment:E,hasChanges:C}=m0(D);G.current.innerHTML="",G.current.appendChild(E),N(!0),Q(!0,C)}catch(M){console.error("[unified-diff] diff computation failed",M),T(M instanceof Error?M.message:String(M))}})})},[_,H,W]),f("div",{className:"flex-1 min-h-0 overflow-y-auto",children:[!W&&!K&&f("div",{style:{position:"absolute",left:-9999,visibility:"hidden",pointerEvents:"none",width:720},children:[f(B1,{ref:q,sessionId:J,revision:$,filename:Z,onReady:()=>z(!0),onError:(M)=>T(`Rev ${$}: ${M}`)},void 0,!1,void 0,this),f(B1,{ref:X,sessionId:J,revision:Y,filename:Z,onReady:()=>U(!0),onError:(M)=>T(`Rev ${Y}: ${M}`)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),f("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:[!W&&!K&&f("div",{className:"flex flex-col items-center justify-center h-64 text-text-tertiary font-body text-body gap-2",children:[f("span",{children:"Loading..."},void 0,!1,void 0,this),O&&f("span",{className:"text-[11px]",children:"Taking longer than expected — check Network tab for pending requests"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),K&&f("div",{className:"bg-accent-red-muted rounded-lg p-5 mt-8",children:[f("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Failed to load revision"},void 0,!1,void 0,this),f("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:K},void 0,!1,void 0,this)]},void 0,!0,void 0,this),f("div",{ref:G},void 0,!1,void 0,this)]},void 0,!0,void 0,this),V]},void 0,!0,void 0,this)}function z4({sessionId:J,leftRev:$,rightRev:Y,filename:Z,onDiffResult:Q}){let q=L1(null),X=L1(null),[G,_]=Q1(!1),[z,H]=Q1(!1),[U,W]=Q1(!1),N=L1(null),K=L1(null),T=L1(null),O=L1(!1),S=S2(()=>_(!0),[]),L=S2(()=>H(!0),[]),{annotations:j}=e(),V=j.filter((I)=>!I.filePath&&(!I.canvasFile||I.canvasFile===Z)),{popovers:M}=E1({containerRef:N,restoreKey:U,restoreAnnotations:V,extractContext:(I)=>D1(I,N.current)});return w1(()=>{if(!G||!z||U)return;if(!q.current||!X.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!q.current||!X.current)return;let I=D0(q.current,X.current);W(!0),Q(!0,I)})})},[G,z,U]),w1(()=>{let I=K.current,D=T.current;if(!I||!D)return;let E=(v,m)=>{if(document.documentElement.dataset.syncScroll==="0")return;if(O.current)return;O.current=!0;let c=v.scrollHeight-v.clientHeight,y=m.scrollHeight-m.clientHeight;if(c>0&&y>0)m.scrollTop=v.scrollTop/c*y;requestAnimationFrame(()=>{O.current=!1})},C=()=>E(I,D),R=()=>E(D,I);return I.addEventListener("scroll",C),D.addEventListener("scroll",R),()=>{I.removeEventListener("scroll",C),D.removeEventListener("scroll",R)}},[]),f("div",{ref:N,className:"flex flex-1 min-h-0",children:[f("div",{ref:K,className:"w-1/2 overflow-y-auto border-r border-border-subtle",children:f("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:f(B1,{ref:q,sessionId:J,revision:$,filename:Z,onReady:S},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),f("div",{ref:T,className:"w-1/2 overflow-y-auto",children:f("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:f(B1,{ref:X,sessionId:J,revision:Y,filename:Z,onReady:L},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),M]},void 0,!0,void 0,this)}var B1=P2.memo(P2.forwardRef(({sessionId:J,revision:$,filename:Y,onReady:Z,onError:Q},q)=>{let[X,G]=Q1(null),[_,z]=Q1(null),[H,U]=Q1(!0);w1(()=>{U(!0),z(null);let N=Y.replace(/\.jsx$/,".js");import(`/api/session/${J}/canvas/${encodeURIComponent(N)}?rev=${$}&t=${Date.now()}`).then((K)=>{if(!K.default){z("Module has no default export"),U(!1),Q?.("Module has no default export");return}G(()=>K.default),U(!1)}).catch((K)=>{z(K.message),U(!1),Q?.(K.message)})},[J,$,Y]),w1(()=>{if(!X)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{Z()})})},[X]);let W=g0(()=>X?f(X,{},void 0,!1,void 0,this):null,[X]);if(H)return f("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-body",children:"Loading..."},void 0,!1,void 0,this);if(_)return f("div",{className:"bg-accent-red-muted rounded-lg p-5",children:[f("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Error"},void 0,!1,void 0,this),f("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:_},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(!X)return f("div",{className:"text-text-tertiary text-center py-8 font-body text-body",children:"No canvas loaded"},void 0,!1,void 0,this);return f("div",{ref:q,children:W},void 0,!1,void 0,this)}));import{useState as y1,useContext as W5,useMemo as G4,useRef as G0,useEffect as A2,useCallback as w2}from"react";import{SessionContext as U4}from"#canvas/runtime";import{jsxDEV as h}from"react/jsx-dev-runtime";function N5(J,$){if(!J)return[];return J.canvasFiles.map((Y)=>{if(!Y.diffStats)return{filename:Y.filename,status:"new"};if(Y.diffStats.added===0&&Y.diffStats.removed===0)return{filename:Y.filename,status:"unchanged",diffStats:Y.diffStats};return{filename:Y.filename,status:"changed",diffStats:Y.diffStats}})}function I2(J){return J.filter(($)=>$.status!=="unchanged").map(($)=>$.filename)}function C2({revision:J,responseBanner:$}){let{setActiveView:Y}=W5(F1),{revisions:Z}=W5(N1),Q=Z.find((z)=>z.revision===J),q=Z.find((z)=>z.revision===J-1),X=G4(()=>N5(Q,q),[Q,q]),G=X.filter((z)=>z.status!=="unchanged"),_=X.filter((z)=>z.status==="unchanged");return h("div",{className:"max-w-[720px] mx-auto px-6 pt-12 pb-32",children:[$,G.map((z)=>h(H4,{change:z,revision:J,previousRevision:q?.revision,onOpenTab:()=>Y({type:"canvas",filename:z.filename})},z.filename,!1,void 0,this)),_.length>0&&h("div",{className:"mt-8 border-t border-border-subtle pt-4",children:[h("div",{className:"text-[11px] font-body font-medium uppercase tracking-widest text-text-tertiary mb-3",children:"Unchanged"},void 0,!1,void 0,this),_.map((z)=>h(O4,{change:z,revision:J,onOpenTab:()=>Y({type:"canvas",filename:z.filename})},z.filename,!1,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function K4({mode:J,onChange:$,showDiff:Y}){if(!Y)return null;return h("div",{className:"flex items-center bg-bg-elevated rounded-md p-0.5",children:["rendered","unified","side-by-side"].map((Z)=>h("button",{onClick:()=>$(Z),className:`text-[10px] font-body px-2 py-0.5 rounded transition-colors ${J===Z?"bg-bg-surface text-text-primary font-medium shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:Z==="rendered"?"Full":Z==="unified"?"Unified":"Split"},Z,!1,void 0,this))},void 0,!1,void 0,this)}function H4({change:J,revision:$,previousRevision:Y,onOpenTab:Z}){let Q=J.filename.replace(/\.jsx$/,""),q=J.status==="new",X=J.diffStats,G=J.status==="changed"&&Y!=null,[_,z]=y1("rendered");return h("div",{className:"mb-8",children:[h("div",{className:"flex items-center gap-2 mb-3 pb-2 border-b border-border-subtle",children:[h("span",{className:`text-[11px] font-mono px-1.5 py-0.5 rounded ${q?"bg-accent-green/10 text-accent-green border border-accent-green/20":"bg-accent-amber/10 text-accent-amber border border-accent-amber/20"}`,children:q?"new":"modified"},void 0,!1,void 0,this),h("span",{className:"text-[14px] font-body font-medium text-text-primary",children:Q},void 0,!1,void 0,this),X&&(X.added>0||X.removed>0)&&h("span",{className:"text-[11px] font-mono text-text-tertiary",children:[h("span",{className:"text-accent-green",children:["+",X.added]},void 0,!0,void 0,this)," ",h("span",{className:"text-accent-red",children:["-",X.removed]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),h(K4,{mode:_,onChange:z,showDiff:G},void 0,!1,void 0,this),h("button",{onClick:Z,className:`${G?"":"ml-auto"} text-[11px] font-body font-medium text-accent-blue hover:text-accent-blue/80 transition-colors`,children:"Open in tab"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),_==="rendered"?h("div",{"data-canvas-file":J.filename,children:h(Y0,{revision:$,filename:J.filename},void 0,!1,void 0,this)},void 0,!1,void 0,this):G&&Y!=null?h(W4,{filename:J.filename,leftRev:Y,rightRev:$,mode:_},`${_}-${$}-${Y}`,!1,void 0,this):null]},void 0,!0,void 0,this)}function W4({filename:J,leftRev:$,rightRev:Y,mode:Z}){let Q=W5(U4);if(Z==="unified")return h(N4,{sessionId:Q,filename:J,leftRev:$,rightRev:Y},void 0,!1,void 0,this);return h(T4,{sessionId:Q,filename:J,leftRev:$,rightRev:Y},void 0,!1,void 0,this)}function N4({sessionId:J,filename:$,leftRev:Y,rightRev:Z}){let Q=G0(null),q=G0(null),X=G0(null),[G,_]=y1(!1),[z,H]=y1(!1),[U,W]=y1(!1),[N,K]=y1(null);return A2(()=>{if(!G||!z||U)return;if(!Q.current||!q.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!Q.current||!q.current||!X.current)return;try{let T=a1(Q.current),O=a1(q.current),S=z0(T,O),{fragment:L}=m0(S);X.current.innerHTML="",X.current.appendChild(L),W(!0)}catch(T){K(T instanceof Error?T.message:String(T))}})})},[G,z,U]),h("div",{children:[!U&&!N&&h("div",{style:{position:"absolute",left:-9999,visibility:"hidden",pointerEvents:"none",width:720},children:[h(B1,{ref:Q,sessionId:J,revision:Y,filename:$,onReady:()=>_(!0),onError:(T)=>K(T)},void 0,!1,void 0,this),h(B1,{ref:q,sessionId:J,revision:Z,filename:$,onReady:()=>H(!0),onError:(T)=>K(T)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!U&&!N&&h("div",{className:"flex items-center justify-center h-24 text-text-tertiary font-body text-[13px]",children:"Computing diff..."},void 0,!1,void 0,this),N&&h("div",{className:"text-accent-red text-[13px] font-body p-3 bg-accent-red-muted rounded-lg",children:N},void 0,!1,void 0,this),h("div",{ref:X},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function T4({sessionId:J,filename:$,leftRev:Y,rightRev:Z}){let Q=G0(null),q=G0(null),[X,G]=y1(!1),[_,z]=y1(!1),[H,U]=y1(!1),W=w2(()=>G(!0),[]),N=w2(()=>z(!0),[]);return A2(()=>{if(!X||!_||H)return;if(!Q.current||!q.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!Q.current||!q.current)return;D0(Q.current,q.current),U(!0)})})},[X,_,H]),h("div",{className:"flex gap-0 border-y border-border-subtle overflow-hidden w-screen relative left-1/2 -translate-x-1/2",children:[h("div",{className:"w-1/2 border-r border-border-subtle",children:[h("div",{className:"px-2 py-1 text-[10px] font-body font-medium text-text-tertiary bg-bg-elevated border-b border-border-subtle",children:["Rev ",Y]},void 0,!0,void 0,this),h("div",{className:"px-6 py-4 max-w-[600px] mx-auto",children:h(B1,{ref:Q,sessionId:J,revision:Y,filename:$,onReady:W},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),h("div",{className:"w-1/2",children:[h("div",{className:"px-2 py-1 text-[10px] font-body font-medium text-text-tertiary bg-bg-elevated border-b border-border-subtle",children:["Rev ",Z]},void 0,!0,void 0,this),h("div",{className:"px-6 py-4 max-w-[600px] mx-auto",children:h(B1,{ref:q,sessionId:J,revision:Z,filename:$,onReady:N},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function O4({change:J,revision:$,onOpenTab:Y}){let[Z,Q]=y1(!1),q=J.filename.replace(/\.jsx$/,"");return h("div",{className:"mb-2",children:[h("div",{className:"flex items-center gap-2 py-1.5",children:[h("button",{onClick:()=>Q(!Z),className:"text-text-tertiary hover:text-text-secondary transition-colors",children:h("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",className:`transition-transform duration-150 ${Z?"rotate-90":""}`,children:h("path",{d:"M3.5 2L6.5 5L3.5 8",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),h("span",{className:"text-[13px] font-body text-text-secondary",children:q},void 0,!1,void 0,this),h("button",{onClick:Y,className:"ml-auto text-[11px] font-body text-text-tertiary hover:text-accent-blue transition-colors",children:"Open in tab"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Z&&h("div",{className:"ml-5 mt-1 mb-3","data-canvas-file":J.filename,children:h(Y0,{revision:$,filename:J.filename},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{jsxDEV as F,Fragment as E0}from"react/jsx-dev-runtime";var F1=D2({activeView:{type:"overview"},setActiveView:()=>{},openFiles:[],closeFile:()=>{},canvasFiles:[]}),N1=D2({currentRevision:1,selectedRevision:1,revisions:[],setSelectedRevision:()=>{},isReadOnly:!1,compareRevision:null,setCompareRevision:()=>{}});function y4(J){if(J==="auto")return window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light";return J}function R2(J){document.documentElement.dataset.theme=y4(J)}function g2(){let[J,$]=$1(()=>{let Q=localStorage.getItem("canvas-theme");if(Q==="light"||Q==="dark"||Q==="auto")return Q;return"auto"});return M1(()=>{if(R2(J),J!=="auto")return;let Q=window.matchMedia("(prefers-color-scheme: dark)"),q=()=>R2("auto");return Q.addEventListener("change",q),()=>Q.removeEventListener("change",q)},[J]),F("button",{onClick:()=>{let Q=J==="auto"?"light":J==="light"?"dark":"auto";localStorage.setItem("canvas-theme",Q),$(Q)},className:"w-7 h-7 flex items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:{auto:"Theme: system (click for light)",light:"Theme: light (click for dark)",dark:"Theme: dark (click for system)"}[J],children:J==="auto"?F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[F("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2",ry:"2"},void 0,!1,void 0,this),F("line",{x1:"8",y1:"21",x2:"16",y2:"21"},void 0,!1,void 0,this),F("line",{x1:"12",y1:"17",x2:"12",y2:"21"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):J==="dark"?F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:F("path",{d:"M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"},void 0,!1,void 0,this)},void 0,!1,void 0,this):F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[F("circle",{cx:"12",cy:"12",r:"5"},void 0,!1,void 0,this),F("line",{x1:"12",y1:"1",x2:"12",y2:"3"},void 0,!1,void 0,this),F("line",{x1:"12",y1:"21",x2:"12",y2:"23"},void 0,!1,void 0,this),F("line",{x1:"4.22",y1:"4.22",x2:"5.64",y2:"5.64"},void 0,!1,void 0,this),F("line",{x1:"18.36",y1:"18.36",x2:"19.78",y2:"19.78"},void 0,!1,void 0,this),F("line",{x1:"1",y1:"12",x2:"3",y2:"12"},void 0,!1,void 0,this),F("line",{x1:"21",y1:"12",x2:"23",y2:"12"},void 0,!1,void 0,this),F("line",{x1:"4.22",y1:"19.78",x2:"5.64",y2:"18.36"},void 0,!1,void 0,this),F("line",{x1:"18.36",y1:"5.64",x2:"19.78",y2:"4.22"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function u2(){let{currentRevision:J,selectedRevision:$,revisions:Y,setSelectedRevision:Z,setCompareRevision:Q}=A1.useContext(N1);if(Y.length<=1){let G=Y[0]?.label||`Round ${J}`;return F("span",{className:"text-[11px] text-text-tertiary font-body",children:G},void 0,!1,void 0,this)}return F("div",{className:"flex flex-col gap-1",children:[F(q0,{value:$,onChange:Z,accent:$===J?"default":"amber"},void 0,!1,void 0,this),F("button",{onClick:()=>{let X;if($===J)X=[...Y].reverse().find((_)=>_.revision<J)?.revision??Math.max(1,J-1);else X=$;Q({left:X,right:J})},className:"text-[11px] font-body font-medium px-2 py-0.5 rounded-md text-accent-blue hover:bg-accent-blue-muted transition-colors self-start",children:"Compare"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function M4(){let J=window.location.pathname.replace("/s/","")||"",[$,Y]=$1(1),[Z,Q]=$1(1),[q,X]=$1([]),[G,_]=$1(null),[z,H]=$1(!1),[U,W]=$1(!1),[N,K]=$1([]),[T,O]=$1({type:"overview"}),[S,L]=$1([]),j=I1(null),[V,M]=$1(),[I,D]=$1(!1),[E,C]=$1(!1),[R,v]=$1(!1);M1(()=>{let B=["Agent Canvas"];if(V){let b=V.replace(/\/+$/,"").split("/");B.push(b[b.length-1]||J)}else if(J)B.push(J);if(T.type==="file")B.push(T.path.split("/").pop()||T.path);else if(T.type==="overview")B.push("Overview");else if(T.type==="canvas"&&N.length>1&&T.filename)B.push(T.filename.replace(/\.jsx$/,""));else if(G)B.push("Compare");document.title=B.join(" — ")},[J,V,T,G]);let m=I1(new Map),c=q.find((B)=>B.revision===Z),y=Z!==$||!!c?.hasFeedback,P=u0((B)=>{let b=T.type==="overview"?"overview":T.type==="canvas"?`canvas:${T.filename}`:`file:${T.path}`;if(m.current.set(b,window.scrollY),O(B),B.type==="file")L((g)=>g.includes(B.path)?g:[...g,B.path])},[T]),x=u0((B)=>{m.current.delete(`file:${B}`),L((b)=>b.filter((g)=>g!==B)),O((b)=>{if(b.type==="file"&&b.path===B)return N.length>1?{type:"overview"}:{type:"canvas",filename:N[0]||""};return b})},[N]);F4(()=>{let B=T.type==="overview"?"overview":T.type==="canvas"?`canvas:${T.filename}`:`file:${T.path}`;window.scrollTo(0,m.current.get(B)||0)},[T]),M1(()=>{if(!J)return;fetch(`/api/session/${J}/meta`).then((B)=>B.json()).then((B)=>{if(B.currentRevision)Y(B.currentRevision),Q(B.currentRevision),X(B.revisions||[]);if(B.canvasFiles){let b=B.canvasFiles.sort();K(b),O((g)=>{if(g.type==="overview")return b.length>1?g:{type:"canvas",filename:b[0]||""};if(g.type==="canvas"&&(!g.filename||!b.includes(g.filename)))return{type:"canvas",filename:b[0]||""};return g})}if(B.projectRoot)M(B.projectRoot)}).catch(()=>{})},[J]),M1(()=>{if(!J)return;let B=null,b=()=>{let g=window.location.protocol==="https:"?"wss:":"ws:",o=new WebSocket(`${g}//${window.location.host}/ws/session/${J}`);j.current=o,o.onopen=()=>H(!0),o.onclose=()=>{H(!1),B=setTimeout(b,2000)},o.onmessage=(i)=>{try{let k=JSON.parse(i.data);if(k.type==="plan-updated"){if(Y(k.currentRevision),Q(k.currentRevision),_(null),k.revisions){let r=k.revisions;X(r);let A=r.find((u)=>u.revision===k.currentRevision);if(A?.canvasFiles){let u=A.canvasFiles.map((j1)=>j1.filename).sort();K(u);let s=r.find((j1)=>j1.revision===k.currentRevision-1),_1=N5(A,s),C1=I2(_1);if(C1.length===1)O({type:"canvas",filename:C1[0]});else if(C1.length>1||u.length>1)O({type:"overview"});else O({type:"canvas",filename:u[0]||""})}}}if(k.type==="revision-updated"){if(k.revisions)X(k.revisions)}}catch{}}};return b(),()=>{if(B)clearTimeout(B);j.current?.close()}},[J]);let p=u0((B)=>{if(j.current?.readyState===WebSocket.OPEN)j.current.send(JSON.stringify({type:"submit",feedback:B})),W(!1)},[]);if(!J)return F("div",{className:"flex items-center justify-center h-screen text-text-tertiary font-body",children:"No session selected."},void 0,!1,void 0,this);return F(m2.Provider,{value:J,children:F(N1.Provider,{value:{currentRevision:$,selectedRevision:Z,revisions:q,setSelectedRevision:Q,isReadOnly:y,compareRevision:G,setCompareRevision:_},children:F(D5,{sessionId:J,revision:Z,isReadOnly:y,children:F(F1.Provider,{value:{activeView:T,setActiveView:P,openFiles:S,closeFile:x,canvasFiles:N},children:F(B4.Provider,{value:{setActiveView:P},children:F("div",{className:"min-h-screen bg-bg-base",children:[F(P4,{sessionId:J,projectRoot:V,connected:z,onMobileSidebar:()=>D(!I),collapsed:E,onToggle:()=>C((B)=>!B)},void 0,!1,void 0,this),F(S4,{collapsed:R,onToggle:()=>v((B)=>!B),children:F(z5,{onPreview:()=>W(!0),onSubmit:p},void 0,!1,void 0,this)},void 0,!1,void 0,this),G!==null?F("div",{className:`${E?"lg:ml-0":"lg:ml-60"} ${R?"lg:mr-0":"lg:mr-[var(--sidebar-width,320px)]"} transition-[margin] duration-200`,children:F(b2,{initialLeft:G.left,initialRight:G.right,sessionId:J,onExit:()=>_(null)},void 0,!1,void 0,this)},void 0,!1,void 0,this):F("div",{className:`relative ${E?"lg:ml-0":"lg:ml-60"} ${R?"lg:mr-0":"lg:mr-[var(--sidebar-width,320px)]"} transition-[margin] duration-200`,id:"plan-scroll-container",children:[F("div",{className:"lg:hidden sticky top-0 z-20 flex items-center justify-between px-4 py-2 border-b border-border-subtle bg-bg-surface",children:[F("div",{className:"flex items-center gap-2",children:[F(U5,{currentSessionId:J,projectRoot:V},void 0,!1,void 0,this),F("span",{className:`w-1.5 h-1.5 rounded-full ${z?"bg-accent-green":"bg-accent-red"}`},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("div",{className:"flex items-center gap-1",children:[F(u2,{},void 0,!1,void 0,this),F("button",{onClick:()=>D(!I),className:"w-7 h-7 flex items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Annotations",children:F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:F("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),F(g2,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),F(b4,{},void 0,!1,void 0,this),T.type==="overview"&&F(C2,{revision:Z,responseBanner:c?.response?F(k2,{markdown:c.response},void 0,!1,void 0,this):void 0},void 0,!1,void 0,this),T.type==="canvas"&&N.includes(T.filename)&&F("div",{className:"relative max-w-[720px] mx-auto px-6 pt-12 pb-32",children:[F("button",{onClick:()=>{let B=document.querySelector(`[data-canvas-file="${T.filename}"] .plan-content`);if(!B)return;let b=U2(B);navigator.clipboard.writeText(b).then(()=>{let g=document.getElementById("export-md-btn");if(g)g.setAttribute("data-copied","true"),setTimeout(()=>{g.removeAttribute("data-copied")},1500)})},id:"export-md-btn",className:"group absolute top-3 right-6 p-1.5 text-text-tertiary hover:text-text-secondary transition-colors z-10",title:"Copy as Markdown",children:[F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"group-[[data-copied=true]]:hidden",children:[F("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"},void 0,!1,void 0,this),F("path",{d:"M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"hidden group-[[data-copied=true]]:block text-green-500",children:F("polyline",{points:"20 6 9 17 4 12"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),N.length<=1&&c?.response&&F(k2,{markdown:c.response},void 0,!1,void 0,this),F("div",{"data-canvas-file":T.filename,children:F(Y0,{revision:Z,filename:T.filename},T.filename,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),S.map((B)=>F("div",{style:{display:T.type==="file"&&T.path===B?void 0:"none"},children:F(q2,{path:B},void 0,!1,void 0,this)},B,!1,void 0,this))]},void 0,!0,void 0,this),I&&F("div",{className:"lg:hidden fixed inset-0 z-40 flex",children:[F("div",{className:"flex-1",onClick:()=>D(!1)},void 0,!1,void 0,this),F("div",{className:"w-80 max-w-[85vw] bg-bg-surface border-l border-border-subtle flex flex-col shadow-lg",children:[F("div",{className:"flex items-center justify-between px-4 py-2 border-b border-border-subtle flex-shrink-0",children:[F("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:"Sidebar"},void 0,!1,void 0,this),F("button",{onClick:()=>D(!1),className:"text-text-tertiary hover:text-text-secondary w-7 h-7 flex items-center justify-center",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("div",{className:"flex-1 overflow-hidden",children:F(z5,{onPreview:()=>W(!0),onSubmit:p},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),F(o5,{open:U,onClose:()=>W(!1),onSubmit:p},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},`${J}:${Z}`,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function P4({sessionId:J,projectRoot:$,connected:Y,onMobileSidebar:Z,collapsed:Q,onToggle:q}){return F(E0,{children:[Q&&F("button",{onClick:q,className:"hidden lg:flex fixed top-3 left-3 z-20 w-7 h-7 items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors bg-bg-surface border border-border-subtle",title:"Show sidebar",children:F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[F("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"},void 0,!1,void 0,this),F("line",{x1:"9",y1:"3",x2:"9",y2:"21"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),F("div",{className:`hidden lg:flex w-60 flex-col fixed top-0 left-0 bottom-0 bg-bg-surface border-r border-border-subtle z-10 transition-transform duration-200 ${Q?"-translate-x-full":""}`,children:[F("div",{className:"px-4 pt-4 pb-3 flex-shrink-0 border-b border-border-subtle",children:[F("div",{className:"flex items-center gap-2 mb-2",children:[F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",className:"text-text-tertiary flex-shrink-0",children:F("path",{d:"M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this),F(U5,{currentSessionId:J,projectRoot:$},void 0,!1,void 0,this),F("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${Y?"bg-accent-green":"bg-accent-red"}`},void 0,!1,void 0,this),F("button",{onClick:q,className:"ml-auto w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Hide sidebar",children:F("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[F("polyline",{points:"11 17 6 12 11 7"},void 0,!1,void 0,this),F("polyline",{points:"18 17 13 12 18 7"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F(u2,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("div",{className:"flex-1 flex flex-col overflow-hidden",children:F(Y2,{embedded:!0},void 0,!1,void 0,this)},void 0,!1,void 0,this),F("div",{className:"px-4 py-3 border-t border-border-subtle flex items-center justify-between flex-shrink-0",children:[F("span",{className:"text-[10px] text-text-tertiary font-body uppercase tracking-widest",children:"Theme"},void 0,!1,void 0,this),F(g2,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function S4({children:J,collapsed:$,onToggle:Y}){let[Z,Q]=$1(()=>{let H=localStorage.getItem("canvas-sidebar-width");return H?parseInt(H,10):320}),q=I1(!1),X=I1(0),G=I1(0),_=I1(Z);_.current=Z;let z=u0((H)=>{H.preventDefault(),q.current=!0,X.current=H.clientX,G.current=_.current;let U=(N)=>{if(!q.current)return;let K=X.current-N.clientX,T=Math.max(240,Math.min(600,G.current+K));Q(T),_.current=T},W=()=>{q.current=!1,localStorage.setItem("canvas-sidebar-width",String(_.current)),document.removeEventListener("mousemove",U),document.removeEventListener("mouseup",W),document.body.style.cursor="",document.body.style.userSelect=""};document.addEventListener("mousemove",U),document.addEventListener("mouseup",W),document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[]);return M1(()=>{return document.documentElement.style.setProperty("--sidebar-width",`${Z}px`),()=>{document.documentElement.style.removeProperty("--sidebar-width")}},[Z]),F(E0,{children:[$&&F("button",{onClick:Y,className:"hidden lg:flex fixed top-3 right-3 z-20 w-7 h-7 items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors bg-bg-surface border border-border-subtle",title:"Show annotations",children:F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:F("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),F("div",{className:`hidden lg:flex flex-col fixed top-0 right-0 bottom-0 bg-bg-surface border-l border-border-subtle z-10 transition-transform duration-200 ${$?"translate-x-full":""}`,style:{width:Z},children:[F("div",{onMouseDown:z,className:"absolute left-0 top-0 bottom-0 w-1 cursor-col-resize hover:bg-accent-blue/30 transition-colors z-20",style:{marginLeft:"-2px"}},void 0,!1,void 0,this),A1.Children.map(J,(H)=>A1.isValidElement(H)?A1.cloneElement(H,{collapseButton:F("button",{onClick:Y,className:"w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Hide annotations",children:F("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[F("polyline",{points:"13 17 18 12 13 7"},void 0,!1,void 0,this),F("polyline",{points:"6 17 11 12 6 7"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}):H)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function k2({markdown:J}){let[$,Y]=$1(!1),Z=j2(()=>a.parse(J,{async:!1}),[J]),Q=I1(null),{annotations:q,addAnnotationWithId:X,removeAnnotation:G,updateAnnotation:_,addAnnotationImage:z,removeAnnotationImage:H,activeAnnotationId:U,setActiveAnnotationId:W}=e(),[N,K]=$1(null),[T,O]=$1(null),S=j2(()=>q.filter((I)=>I.filePath===q1),[q]),[L,j]=$1(J);if(J!==L)j(J),Y(!1);M1(()=>{if(!Q.current||S.length===0)return;let I=setTimeout(()=>{if(Q.current)P0(Q.current,S)},50);return()=>clearTimeout(I)},[Z,S.length]);let V=I1(null);if(M1(()=>{y0(U,V.current),V.current=U},[U]),M1(()=>{let I=Q.current;if(!I)return;let D=(R)=>{let v=R.target.closest("[data-annotation-id]");if(!v)return;R.stopPropagation();let m=v.getAttribute("data-annotation-id");if(m===U)O({anchorEl:v,annId:m});else W(m)},E=(R)=>{let v=R.target.closest("[data-annotation-id]");if(v)W(v.getAttribute("data-annotation-id"))},C=(R)=>{let v=R.target.closest("[data-annotation-id]"),m=R.relatedTarget?.closest?.("[data-annotation-id]");if(v&&!m)W(null)};return I.addEventListener("click",D),I.addEventListener("mouseover",E),I.addEventListener("mouseout",C),()=>{I.removeEventListener("click",D),I.removeEventListener("mouseover",E),I.removeEventListener("mouseout",C)}},[Z,U]),M1(()=>{let I=()=>{let D=window.getSelection();if(!D||D.isCollapsed||!D.toString().trim())return;if(!Q.current)return;let E=D.getRangeAt(0);if(!Q.current.contains(E.startContainer))return;if(E.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let C=D.toString().trim();if(C.length<2)return;let R=E.cloneRange(),v=D1(E,Q.current),m=`__pending_${Date.now()}`;try{g1(R,m)}catch{}window.getSelection()?.removeAllRanges();let c=document.querySelectorAll(`[data-annotation-id="${m}"]`),y=c[c.length-1];if(!y)return;K({anchorEl:y,tempId:m,snippet:C,ctx:v})};return document.addEventListener("mouseup",I),()=>document.removeEventListener("mouseup",I)},[]),$)return null;let M=document.getElementById("plan-scroll-container");return F("div",{className:"mb-6 rounded-lg border border-accent-blue/20 bg-accent-blue/5 relative",children:[F("button",{onClick:()=>Y(!0),className:"absolute top-2 right-2 w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",children:F("span",{className:"text-xs",children:"✕"},void 0,!1,void 0,this)},void 0,!1,void 0,this),F("div",{className:"px-4 py-3 pr-10",children:[F("div",{className:"flex items-center gap-2 mb-1.5",children:[F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-accent-blue flex-shrink-0",children:F("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this),F("span",{className:"text-[11px] font-medium uppercase tracking-widest text-accent-blue font-body",children:"Agent Response"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("div",{ref:Q,className:"prose-canvas text-sm",dangerouslySetInnerHTML:{__html:Z}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),N&&F(c1,{anchorEl:N.anchorEl,scrollContainer:M,snippet:N.snippet,truncateAt:80,onAdd:(I,D)=>{let E=U1();M0(N.tempId,E),X(E,N.snippet,I,q1,N.ctx,D),K(null)},onCancel:()=>{S0(N.tempId),K(null)}},void 0,!1,void 0,this),T&&(()=>{let I=q.find((D)=>D.id===T.annId);if(!I)return null;return F(d1,{anchorEl:T.anchorEl,scrollContainer:M,initialNote:I.note,initialImages:I.images,onUpdate:(D,E)=>{_(T.annId,D);let C=I.images||[];for(let R of E)if(!C.includes(R))z(T.annId,R);for(let R of C)if(!E.includes(R))H(T.annId,R)},onDelete:()=>{G(T.annId),W(null)},onClose:()=>O(null)},void 0,!1,void 0,this)})()]},void 0,!0,void 0,this)}function b4(){let{activeView:J,setActiveView:$,openFiles:Y,closeFile:Z,canvasFiles:Q}=A1.useContext(F1),q=A1.useContext(m2),{addAnnotationWithId:X,setActiveAnnotationId:G}=e();if(!(Q.length>1||Y.length>0))return null;return F("div",{className:"flex items-center border-b border-border-medium bg-bg-surface overflow-x-auto sticky top-0 z-10",children:[Q.length>1&&F(E0,{children:[F("button",{onClick:()=>$({type:"overview"}),className:`flex items-center gap-1.5 px-4 py-2.5 text-[13px] font-body whitespace-nowrap transition-colors relative ${J.type==="overview"?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",className:"opacity-60",children:F("path",{d:"M12 7L2 12l10 5 10-5-10-5z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this),"Overview",J.type==="overview"&&F("span",{className:"absolute bottom-0 left-3 right-3 h-[2px] bg-text-primary rounded-full"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Q.map((z,H)=>{let U=z.replace(/\.jsx$/,""),W=J.type==="canvas"&&J.filename===z;return F(A1.Fragment,{children:[F("button",{onClick:()=>$({type:"canvas",filename:z}),className:`flex items-center gap-1.5 px-4 py-2.5 text-[13px] font-body whitespace-nowrap transition-colors relative ${W?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[U,W&&F("span",{className:"absolute bottom-0 left-3 right-3 h-[2px] bg-text-primary rounded-full"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),H<Q.length-1&&F("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this)]},z,!0,void 0,this)}),Y.length>0&&F(E0,{children:[F("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this),Y.map((z,H)=>{let U=z.split("/").pop()||z,W=J.type==="file"&&J.path===z;return F(A1.Fragment,{children:[F("div",{className:"flex items-center",children:[F("button",{onClick:()=>$({type:"file",path:z}),className:`flex items-center gap-1.5 pl-3 pr-1 py-2.5 text-[13px] font-body whitespace-nowrap transition-colors relative ${W?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[F(P1,{name:U,type:"file"},void 0,!1,void 0,this),U,W&&F("span",{className:"absolute bottom-0 left-3 right-1 h-[2px] bg-text-primary rounded-full"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("button",{onClick:(N)=>{N.stopPropagation(),Z(z)},className:"text-text-tertiary hover:text-text-secondary px-1.5 py-1 text-[10px] transition-colors rounded hover:bg-bg-input",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),H<Y.length-1&&F("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this)]},z,!0,void 0,this)})]},void 0,!0,void 0,this),F("div",{className:"ml-auto flex items-center gap-1 flex-shrink-0",children:J.type==="file"&&F("button",{onClick:async()=>{let z=J.path;try{let U=await(await fetch(`/api/file?session=${q}&path=${encodeURIComponent(z)}`)).json();if(!U.error){let W=U.content.split(`
87
+ `),X=b1(Q,q),G=[],_=0,z=0,H=0;while(_<Q.length||z<q.length)if(H<X.length&&_<Q.length&&z<q.length&&Q[_]===X[H]&&q[z]===X[H])G.push({type:"same",line:Q[_]}),_++,z++,H++;else if(_<Q.length&&(H>=X.length||Q[_]!==X[H]))G.push({type:"removed",line:Q[_]}),_++;else if(z<q.length)G.push({type:"added",line:q[z]}),z++;let U=document.createElement("div");U.className="mt-2 bg-bg-code rounded-md overflow-hidden text-tiny font-mono",U.setAttribute("data-no-diff","true");for(let W of G){let N=document.createElement("div");if(N.className="px-3 py-0.5 whitespace-pre-wrap",W.type==="removed")N.classList.add("diff-removed"),N.textContent="- "+W.line;else if(W.type==="added")N.classList.add("diff-added"),N.textContent="+ "+W.line;else N.textContent=" "+W.line;U.appendChild(N)}return $.appendChild(U),!0}function H5(J,$,Y){let Z=document.createElement("span");Z.className="diff-block-label",Z.textContent=$,Z.style.color=Y,Z.style.backgroundColor=`color-mix(in srgb, ${Y} 12%, transparent)`,J.appendChild(Z)}import{jsxDEV as f}from"react/jsx-dev-runtime";function q4(J,$,Y){let Z=J.find((X)=>X.revision===$),Q=J.find((X)=>X.revision===Y),q=new Set;for(let X of Z?.canvasFiles||[])q.add(X.filename);for(let X of Q?.canvasFiles||[])q.add(X.filename);return[...q].sort()}function b2({initialLeft:J,initialRight:$,sessionId:Y,onExit:Z}){let[Q,q]=Q1(J),[X,G]=Q1($),[_,z]=Q1("unified"),[H,U]=Q1(!0),[W,N]=Q1(!1),{revisions:K}=X4(N1),T=g0(()=>q4(K,Q,X),[K,Q,X]),[O,S]=Q1(()=>T[0]||"plan.jsx");w1(()=>{if(!T.includes(O))S(T[0]||"plan.jsx")},[T,O]);let L=g0(()=>{return K.find((M)=>M.revision===Q)?.canvasFiles.some((M)=>M.filename===O)??!1},[K,Q,O]),j=g0(()=>{return K.find((M)=>M.revision===X)?.canvasFiles.some((M)=>M.filename===O)??!1},[K,X,O]);return f("div",{className:"flex flex-col h-screen",children:[f("div",{className:"flex items-center justify-between px-6 py-3 border-b border-border-subtle bg-bg-surface flex-shrink-0",children:[f("div",{className:"flex items-center gap-3",children:[f("span",{className:"text-[13px] font-body font-medium text-text-primary",children:"Compare"},void 0,!1,void 0,this),f(q0,{value:Q,onChange:q,accent:"red"},void 0,!1,void 0,this),f("span",{className:"text-text-tertiary text-[13px]",children:"→"},void 0,!1,void 0,this),f(q0,{value:X,onChange:G,accent:"green"},void 0,!1,void 0,this),W&&!H&&f("span",{className:"text-[11px] font-body text-text-tertiary bg-bg-elevated px-2 py-0.5 rounded",children:"No changes"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),f("div",{className:"flex items-center gap-4",children:[f("div",{className:"flex items-center bg-bg-elevated rounded-md p-0.5",children:[f("button",{onClick:()=>z("unified"),className:`text-[11px] font-body px-2.5 py-1 rounded transition-colors ${_==="unified"?"bg-bg-surface text-text-primary font-medium shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Unified"},void 0,!1,void 0,this),f("button",{onClick:()=>z("side-by-side"),className:`text-[11px] font-body px-2.5 py-1 rounded transition-colors ${_==="side-by-side"?"bg-bg-surface text-text-primary font-medium shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Side-by-side"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),_==="side-by-side"&&f(_4,{},void 0,!1,void 0,this),f("button",{onClick:Z,className:"text-[12px] font-body font-medium text-text-secondary hover:text-text-primary px-3 py-1.5 rounded-md hover:bg-bg-elevated transition-colors",children:"Exit Compare"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),T.length>1&&f("div",{className:"flex items-center gap-1 px-6 py-2 border-b border-border-subtle bg-bg-surface flex-shrink-0 overflow-x-auto",children:T.map((V)=>{let M=V.replace(/\.jsx$/,""),I=V===O,D=K.find((R)=>R.revision===Q)?.canvasFiles.some((R)=>R.filename===V),E=K.find((R)=>R.revision===X)?.canvasFiles.some((R)=>R.filename===V),C=!D?" (added)":!E?" (removed)":"";return f("button",{onClick:()=>S(V),className:`text-[12px] font-body px-3 py-1 rounded-md transition-colors whitespace-nowrap ${I?"bg-bg-elevated text-text-primary font-medium":"text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated"}`,children:[M,C&&f("span",{className:`ml-1 text-[10px] ${!D?"text-accent-green":"text-accent-red"}`,children:C},void 0,!1,void 0,this)]},V,!0,void 0,this)})},void 0,!1,void 0,this),!L||!j?f("div",{className:"flex-1 flex items-center justify-center",children:f("div",{className:"text-center text-text-tertiary font-body",children:[f("div",{className:"text-lg mb-2",children:!L?"New file":"Removed file"},void 0,!1,void 0,this),f("div",{className:"text-[13px]",children:[O.replace(/\.jsx$/,"")," ",!L?"was added":"was removed"," in this revision"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this):_==="unified"?f(z4,{sessionId:Y,leftRev:Q,rightRev:X,filename:O,onDiffResult:(V,M)=>{N(V),U(M)}},`unified-${Q}-${X}-${O}`,!1,void 0,this):f(G4,{sessionId:Y,leftRev:Q,rightRev:X,filename:O,onDiffResult:(V,M)=>{N(V),U(M)}},`sbs-${Q}-${X}-${O}`,!1,void 0,this)]},void 0,!0,void 0,this)}function _4(){let[J,$]=Q1(!0);return w1(()=>{return document.documentElement.dataset.syncScroll=J?"1":"0",()=>{delete document.documentElement.dataset.syncScroll}},[J]),f("label",{className:"flex items-center gap-1.5 cursor-pointer select-none",children:[f("input",{type:"checkbox",checked:J,onChange:(Y)=>$(Y.target.checked),className:"accent-accent-amber w-3.5 h-3.5"},void 0,!1,void 0,this),f("span",{className:"text-[11px] font-body text-text-secondary",children:"Sync scroll"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function z4({sessionId:J,leftRev:$,rightRev:Y,filename:Z,onDiffResult:Q}){let q=L1(null),X=L1(null),G=L1(null),[_,z]=Q1(!1),[H,U]=Q1(!1),[W,N]=Q1(!1),[K,T]=Q1(null),[O,S]=Q1(!1),{annotations:L}=e(),j=L.filter((M)=>!M.filePath&&(!M.canvasFile||M.canvasFile===Z)),{popovers:V}=E1({containerRef:G,restoreKey:W,restoreAnnotations:j,extractContext:(M)=>D1(M,G.current)});return w1(()=>{if(W||K)return;let M=setTimeout(()=>{console.warn("[unified-diff] still loading after 10s",{leftReady:_,rightReady:H,oldRef:!!q.current,newRef:!!X.current}),S(!0)},1e4);return()=>clearTimeout(M)},[W,K,_,H]),w1(()=>{if(!_||!H||W)return;if(!q.current||!X.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!q.current||!X.current||!G.current){console.warn("[unified-diff] refs lost between rAF frames",{old:!!q.current,new:!!X.current,unified:!!G.current});return}try{let M=a1(q.current),I=a1(X.current),D=z0(M,I),{fragment:E,hasChanges:C}=m0(D);G.current.innerHTML="",G.current.appendChild(E),N(!0),Q(!0,C)}catch(M){console.error("[unified-diff] diff computation failed",M),T(M instanceof Error?M.message:String(M))}})})},[_,H,W]),f("div",{className:"flex-1 min-h-0 overflow-y-auto",children:[!W&&!K&&f("div",{style:{position:"absolute",left:-9999,visibility:"hidden",pointerEvents:"none",width:720},children:[f(B1,{ref:q,sessionId:J,revision:$,filename:Z,onReady:()=>z(!0),onError:(M)=>T(`Rev ${$}: ${M}`)},void 0,!1,void 0,this),f(B1,{ref:X,sessionId:J,revision:Y,filename:Z,onReady:()=>U(!0),onError:(M)=>T(`Rev ${Y}: ${M}`)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),f("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:[!W&&!K&&f("div",{className:"flex flex-col items-center justify-center h-64 text-text-tertiary font-body text-body gap-2",children:[f("span",{children:"Loading..."},void 0,!1,void 0,this),O&&f("span",{className:"text-[11px]",children:"Taking longer than expected — check Network tab for pending requests"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),K&&f("div",{className:"bg-accent-red-muted rounded-lg p-5 mt-8",children:[f("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Failed to load revision"},void 0,!1,void 0,this),f("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:K},void 0,!1,void 0,this)]},void 0,!0,void 0,this),f("div",{ref:G},void 0,!1,void 0,this)]},void 0,!0,void 0,this),V]},void 0,!0,void 0,this)}function G4({sessionId:J,leftRev:$,rightRev:Y,filename:Z,onDiffResult:Q}){let q=L1(null),X=L1(null),[G,_]=Q1(!1),[z,H]=Q1(!1),[U,W]=Q1(!1),N=L1(null),K=L1(null),T=L1(null),O=L1(!1),S=S2(()=>_(!0),[]),L=S2(()=>H(!0),[]),{annotations:j}=e(),V=j.filter((I)=>!I.filePath&&(!I.canvasFile||I.canvasFile===Z)),{popovers:M}=E1({containerRef:N,restoreKey:U,restoreAnnotations:V,extractContext:(I)=>D1(I,N.current)});return w1(()=>{if(!G||!z||U)return;if(!q.current||!X.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!q.current||!X.current)return;let I=D0(q.current,X.current);W(!0),Q(!0,I)})})},[G,z,U]),w1(()=>{let I=K.current,D=T.current;if(!I||!D)return;let E=(v,m)=>{if(document.documentElement.dataset.syncScroll==="0")return;if(O.current)return;O.current=!0;let c=v.scrollHeight-v.clientHeight,y=m.scrollHeight-m.clientHeight;if(c>0&&y>0)m.scrollTop=v.scrollTop/c*y;requestAnimationFrame(()=>{O.current=!1})},C=()=>E(I,D),R=()=>E(D,I);return I.addEventListener("scroll",C),D.addEventListener("scroll",R),()=>{I.removeEventListener("scroll",C),D.removeEventListener("scroll",R)}},[]),f("div",{ref:N,className:"flex flex-1 min-h-0",children:[f("div",{ref:K,className:"w-1/2 overflow-y-auto border-r border-border-subtle",children:f("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:f(B1,{ref:q,sessionId:J,revision:$,filename:Z,onReady:S},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),f("div",{ref:T,className:"w-1/2 overflow-y-auto",children:f("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:f(B1,{ref:X,sessionId:J,revision:Y,filename:Z,onReady:L},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),M]},void 0,!0,void 0,this)}var B1=P2.memo(P2.forwardRef(({sessionId:J,revision:$,filename:Y,onReady:Z,onError:Q},q)=>{let[X,G]=Q1(null),[_,z]=Q1(null),[H,U]=Q1(!0);w1(()=>{U(!0),z(null);let N=Y.replace(/\.jsx$/,".js");import(`/api/session/${J}/canvas/${encodeURIComponent(N)}?rev=${$}&t=${Date.now()}`).then((K)=>{if(!K.default){z("Module has no default export"),U(!1),Q?.("Module has no default export");return}G(()=>K.default),U(!1)}).catch((K)=>{z(K.message),U(!1),Q?.(K.message)})},[J,$,Y]),w1(()=>{if(!X)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{Z()})})},[X]);let W=g0(()=>X?f(X,{},void 0,!1,void 0,this):null,[X]);if(H)return f("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-body",children:"Loading..."},void 0,!1,void 0,this);if(_)return f("div",{className:"bg-accent-red-muted rounded-lg p-5",children:[f("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Error"},void 0,!1,void 0,this),f("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:_},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(!X)return f("div",{className:"text-text-tertiary text-center py-8 font-body text-body",children:"No canvas loaded"},void 0,!1,void 0,this);return f("div",{ref:q,children:W},void 0,!1,void 0,this)}));import{useState as y1,useContext as W5,useMemo as U4,useRef as G0,useEffect as A2,useCallback as w2}from"react";import{SessionContext as K4}from"#canvas/runtime";import{jsxDEV as h}from"react/jsx-dev-runtime";function N5(J,$){if(!J)return[];return J.canvasFiles.map((Y)=>{if(!Y.diffStats)return{filename:Y.filename,status:"new"};if(Y.diffStats.added===0&&Y.diffStats.removed===0)return{filename:Y.filename,status:"unchanged",diffStats:Y.diffStats};return{filename:Y.filename,status:"changed",diffStats:Y.diffStats}})}function I2(J){return J.filter(($)=>$.status!=="unchanged").map(($)=>$.filename)}function C2({revision:J,responseBanner:$}){let{setActiveView:Y}=W5(F1),{revisions:Z}=W5(N1),Q=Z.find((z)=>z.revision===J),q=Z.find((z)=>z.revision===J-1),X=U4(()=>N5(Q,q),[Q,q]),G=X.filter((z)=>z.status!=="unchanged"),_=X.filter((z)=>z.status==="unchanged");return h("div",{className:"max-w-[720px] mx-auto px-6 pt-12 pb-32",children:[$,G.map((z)=>h(W4,{change:z,revision:J,previousRevision:q?.revision,onOpenTab:()=>Y({type:"canvas",filename:z.filename})},z.filename,!1,void 0,this)),_.length>0&&h("div",{className:"mt-8 border-t border-border-subtle pt-4",children:[h("div",{className:"text-[11px] font-body font-medium uppercase tracking-widest text-text-tertiary mb-3",children:"Unchanged"},void 0,!1,void 0,this),_.map((z)=>h(F4,{change:z,revision:J,onOpenTab:()=>Y({type:"canvas",filename:z.filename})},z.filename,!1,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function H4({mode:J,onChange:$,showDiff:Y}){if(!Y)return null;return h("div",{className:"flex items-center bg-bg-elevated rounded-md p-0.5",children:["rendered","unified","side-by-side"].map((Z)=>h("button",{onClick:()=>$(Z),className:`text-[10px] font-body px-2 py-0.5 rounded transition-colors ${J===Z?"bg-bg-surface text-text-primary font-medium shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:Z==="rendered"?"Full":Z==="unified"?"Unified":"Split"},Z,!1,void 0,this))},void 0,!1,void 0,this)}function W4({change:J,revision:$,previousRevision:Y,onOpenTab:Z}){let Q=J.filename.replace(/\.jsx$/,""),q=J.status==="new",X=J.diffStats,G=J.status==="changed"&&Y!=null,[_,z]=y1("rendered");return h("div",{className:"mb-8",children:[h("div",{className:"flex items-center gap-2 mb-3 pb-2 border-b border-border-subtle",children:[h("span",{className:`text-[11px] font-mono px-1.5 py-0.5 rounded ${q?"bg-accent-green/10 text-accent-green border border-accent-green/20":"bg-accent-amber/10 text-accent-amber border border-accent-amber/20"}`,children:q?"new":"modified"},void 0,!1,void 0,this),h("span",{className:"text-[14px] font-body font-medium text-text-primary",children:Q},void 0,!1,void 0,this),X&&(X.added>0||X.removed>0)&&h("span",{className:"text-[11px] font-mono text-text-tertiary",children:[h("span",{className:"text-accent-green",children:["+",X.added]},void 0,!0,void 0,this)," ",h("span",{className:"text-accent-red",children:["-",X.removed]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),h(H4,{mode:_,onChange:z,showDiff:G},void 0,!1,void 0,this),h("button",{onClick:Z,className:`${G?"":"ml-auto"} text-[11px] font-body font-medium text-accent-blue hover:text-accent-blue/80 transition-colors`,children:"Open in tab"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),_==="rendered"?h("div",{"data-canvas-file":J.filename,children:h(Y0,{revision:$,filename:J.filename},void 0,!1,void 0,this)},void 0,!1,void 0,this):G&&Y!=null?h(N4,{filename:J.filename,leftRev:Y,rightRev:$,mode:_},`${_}-${$}-${Y}`,!1,void 0,this):null]},void 0,!0,void 0,this)}function N4({filename:J,leftRev:$,rightRev:Y,mode:Z}){let Q=W5(K4);if(Z==="unified")return h(T4,{sessionId:Q,filename:J,leftRev:$,rightRev:Y},void 0,!1,void 0,this);return h(O4,{sessionId:Q,filename:J,leftRev:$,rightRev:Y},void 0,!1,void 0,this)}function T4({sessionId:J,filename:$,leftRev:Y,rightRev:Z}){let Q=G0(null),q=G0(null),X=G0(null),[G,_]=y1(!1),[z,H]=y1(!1),[U,W]=y1(!1),[N,K]=y1(null);return A2(()=>{if(!G||!z||U)return;if(!Q.current||!q.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!Q.current||!q.current||!X.current)return;try{let T=a1(Q.current),O=a1(q.current),S=z0(T,O),{fragment:L}=m0(S);X.current.innerHTML="",X.current.appendChild(L),W(!0)}catch(T){K(T instanceof Error?T.message:String(T))}})})},[G,z,U]),h("div",{children:[!U&&!N&&h("div",{style:{position:"absolute",left:-9999,visibility:"hidden",pointerEvents:"none",width:720},children:[h(B1,{ref:Q,sessionId:J,revision:Y,filename:$,onReady:()=>_(!0),onError:(T)=>K(T)},void 0,!1,void 0,this),h(B1,{ref:q,sessionId:J,revision:Z,filename:$,onReady:()=>H(!0),onError:(T)=>K(T)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!U&&!N&&h("div",{className:"flex items-center justify-center h-24 text-text-tertiary font-body text-[13px]",children:"Computing diff..."},void 0,!1,void 0,this),N&&h("div",{className:"text-accent-red text-[13px] font-body p-3 bg-accent-red-muted rounded-lg",children:N},void 0,!1,void 0,this),h("div",{ref:X},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function O4({sessionId:J,filename:$,leftRev:Y,rightRev:Z}){let Q=G0(null),q=G0(null),[X,G]=y1(!1),[_,z]=y1(!1),[H,U]=y1(!1),W=w2(()=>G(!0),[]),N=w2(()=>z(!0),[]);return A2(()=>{if(!X||!_||H)return;if(!Q.current||!q.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!Q.current||!q.current)return;D0(Q.current,q.current),U(!0)})})},[X,_,H]),h("div",{className:"flex gap-0 border-y border-border-subtle overflow-hidden w-screen relative left-1/2 -translate-x-1/2",children:[h("div",{className:"w-1/2 border-r border-border-subtle",children:[h("div",{className:"px-2 py-1 text-[10px] font-body font-medium text-text-tertiary bg-bg-elevated border-b border-border-subtle",children:["Rev ",Y]},void 0,!0,void 0,this),h("div",{className:"px-6 py-4 max-w-[600px] mx-auto",children:h(B1,{ref:Q,sessionId:J,revision:Y,filename:$,onReady:W},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),h("div",{className:"w-1/2",children:[h("div",{className:"px-2 py-1 text-[10px] font-body font-medium text-text-tertiary bg-bg-elevated border-b border-border-subtle",children:["Rev ",Z]},void 0,!0,void 0,this),h("div",{className:"px-6 py-4 max-w-[600px] mx-auto",children:h(B1,{ref:q,sessionId:J,revision:Z,filename:$,onReady:N},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function F4({change:J,revision:$,onOpenTab:Y}){let[Z,Q]=y1(!1),q=J.filename.replace(/\.jsx$/,"");return h("div",{className:"mb-2",children:[h("div",{className:"flex items-center gap-2 py-1.5",children:[h("button",{onClick:()=>Q(!Z),className:"text-text-tertiary hover:text-text-secondary transition-colors",children:h("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",className:`transition-transform duration-150 ${Z?"rotate-90":""}`,children:h("path",{d:"M3.5 2L6.5 5L3.5 8",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),h("span",{className:"text-[13px] font-body text-text-secondary",children:q},void 0,!1,void 0,this),h("button",{onClick:Y,className:"ml-auto text-[11px] font-body text-text-tertiary hover:text-accent-blue transition-colors",children:"Open in tab"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Z&&h("div",{className:"ml-5 mt-1 mb-3","data-canvas-file":J.filename,children:h(Y0,{revision:$,filename:J.filename},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{jsxDEV as F,Fragment as E0}from"react/jsx-dev-runtime";var F1=D2({activeView:{type:"overview"},setActiveView:()=>{},openFiles:[],closeFile:()=>{},canvasFiles:[]}),N1=D2({currentRevision:1,selectedRevision:1,revisions:[],setSelectedRevision:()=>{},isReadOnly:!1,compareRevision:null,setCompareRevision:()=>{}});function M4(J){if(J==="auto")return window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light";return J}function R2(J){document.documentElement.dataset.theme=M4(J)}function g2(){let[J,$]=$1(()=>{let Q=localStorage.getItem("canvas-theme");if(Q==="light"||Q==="dark"||Q==="auto")return Q;return"auto"});return M1(()=>{if(R2(J),J!=="auto")return;let Q=window.matchMedia("(prefers-color-scheme: dark)"),q=()=>R2("auto");return Q.addEventListener("change",q),()=>Q.removeEventListener("change",q)},[J]),F("button",{onClick:()=>{let Q=J==="auto"?"light":J==="light"?"dark":"auto";localStorage.setItem("canvas-theme",Q),$(Q)},className:"w-7 h-7 flex items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:{auto:"Theme: system (click for light)",light:"Theme: light (click for dark)",dark:"Theme: dark (click for system)"}[J],children:J==="auto"?F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[F("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2",ry:"2"},void 0,!1,void 0,this),F("line",{x1:"8",y1:"21",x2:"16",y2:"21"},void 0,!1,void 0,this),F("line",{x1:"12",y1:"17",x2:"12",y2:"21"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):J==="dark"?F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:F("path",{d:"M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"},void 0,!1,void 0,this)},void 0,!1,void 0,this):F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[F("circle",{cx:"12",cy:"12",r:"5"},void 0,!1,void 0,this),F("line",{x1:"12",y1:"1",x2:"12",y2:"3"},void 0,!1,void 0,this),F("line",{x1:"12",y1:"21",x2:"12",y2:"23"},void 0,!1,void 0,this),F("line",{x1:"4.22",y1:"4.22",x2:"5.64",y2:"5.64"},void 0,!1,void 0,this),F("line",{x1:"18.36",y1:"18.36",x2:"19.78",y2:"19.78"},void 0,!1,void 0,this),F("line",{x1:"1",y1:"12",x2:"3",y2:"12"},void 0,!1,void 0,this),F("line",{x1:"21",y1:"12",x2:"23",y2:"12"},void 0,!1,void 0,this),F("line",{x1:"4.22",y1:"19.78",x2:"5.64",y2:"18.36"},void 0,!1,void 0,this),F("line",{x1:"18.36",y1:"5.64",x2:"19.78",y2:"4.22"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function u2(){let{currentRevision:J,selectedRevision:$,revisions:Y,setSelectedRevision:Z,setCompareRevision:Q}=A1.useContext(N1);if(Y.length<=1){let G=Y[0]?.label||`Round ${J}`;return F("span",{className:"text-[11px] text-text-tertiary font-body",children:G},void 0,!1,void 0,this)}return F("div",{className:"flex flex-col gap-1",children:[F(q0,{value:$,onChange:Z,accent:$===J?"default":"amber"},void 0,!1,void 0,this),F("button",{onClick:()=>{let X;if($===J)X=[...Y].reverse().find((_)=>_.revision<J)?.revision??Math.max(1,J-1);else X=$;Q({left:X,right:J})},className:"text-[11px] font-body font-medium px-2 py-0.5 rounded-md text-accent-blue hover:bg-accent-blue-muted transition-colors self-start",children:"Compare"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function P4(){let J=window.location.pathname.replace("/s/","")||"",[$,Y]=$1(1),[Z,Q]=$1(1),[q,X]=$1([]),[G,_]=$1(null),[z,H]=$1(!1),[U,W]=$1(!1),[N,K]=$1([]),[T,O]=$1({type:"overview"}),[S,L]=$1([]),j=I1(null),[V,M]=$1(),[I,D]=$1(!1),[E,C]=$1(!1),[R,v]=$1(!1);M1(()=>{let B=["Agent Canvas"];if(V){let b=V.replace(/\/+$/,"").split("/");B.push(b[b.length-1]||J)}else if(J)B.push(J);if(T.type==="file")B.push(T.path.split("/").pop()||T.path);else if(T.type==="overview")B.push("Overview");else if(T.type==="canvas"&&N.length>1&&T.filename)B.push(T.filename.replace(/\.jsx$/,""));else if(G)B.push("Compare");document.title=B.join(" — ")},[J,V,T,G]);let m=I1(new Map),c=q.find((B)=>B.revision===Z),y=Z!==$||!!c?.hasFeedback,P=u0((B)=>{let b=T.type==="overview"?"overview":T.type==="canvas"?`canvas:${T.filename}`:`file:${T.path}`;if(m.current.set(b,window.scrollY),O(B),B.type==="file")L((g)=>g.includes(B.path)?g:[...g,B.path])},[T]),x=u0((B)=>{m.current.delete(`file:${B}`),L((b)=>b.filter((g)=>g!==B)),O((b)=>{if(b.type==="file"&&b.path===B)return N.length>1?{type:"overview"}:{type:"canvas",filename:N[0]||""};return b})},[N]);L4(()=>{let B=T.type==="overview"?"overview":T.type==="canvas"?`canvas:${T.filename}`:`file:${T.path}`;window.scrollTo(0,m.current.get(B)||0)},[T]),M1(()=>{if(!J)return;fetch(`/api/session/${J}/meta`).then((B)=>B.json()).then((B)=>{if(B.currentRevision)Y(B.currentRevision),Q(B.currentRevision),X(B.revisions||[]);if(B.canvasFiles){let b=B.canvasFiles.sort();K(b),O((g)=>{if(g.type==="overview")return b.length>1?g:{type:"canvas",filename:b[0]||""};if(g.type==="canvas"&&(!g.filename||!b.includes(g.filename)))return{type:"canvas",filename:b[0]||""};return g})}if(B.projectRoot)M(B.projectRoot)}).catch(()=>{})},[J]),M1(()=>{if(!J)return;let B=null,b=()=>{let g=window.location.protocol==="https:"?"wss:":"ws:",o=new WebSocket(`${g}//${window.location.host}/ws/session/${J}`);j.current=o,o.onopen=()=>H(!0),o.onclose=()=>{H(!1),B=setTimeout(b,2000)},o.onmessage=(i)=>{try{let k=JSON.parse(i.data);if(k.type==="plan-updated"){if(Y(k.currentRevision),Q(k.currentRevision),_(null),k.revisions){let r=k.revisions;X(r);let A=r.find((u)=>u.revision===k.currentRevision);if(A?.canvasFiles){let u=A.canvasFiles.map((j1)=>j1.filename).sort();K(u);let s=r.find((j1)=>j1.revision===k.currentRevision-1),_1=N5(A,s),C1=I2(_1);if(C1.length===1)O({type:"canvas",filename:C1[0]});else if(C1.length>1||u.length>1)O({type:"overview"});else O({type:"canvas",filename:u[0]||""})}}}if(k.type==="revision-updated"){if(k.revisions)X(k.revisions)}}catch{}}};return b(),()=>{if(B)clearTimeout(B);j.current?.close()}},[J]);let p=u0((B)=>{if(j.current?.readyState===WebSocket.OPEN)j.current.send(JSON.stringify({type:"submit",feedback:B})),W(!1)},[]);if(!J)return F("div",{className:"flex items-center justify-center h-screen text-text-tertiary font-body",children:"No session selected."},void 0,!1,void 0,this);return F(m2.Provider,{value:J,children:F(N1.Provider,{value:{currentRevision:$,selectedRevision:Z,revisions:q,setSelectedRevision:Q,isReadOnly:y,compareRevision:G,setCompareRevision:_},children:F(D5,{sessionId:J,revision:Z,isReadOnly:y,children:F(F1.Provider,{value:{activeView:T,setActiveView:P,openFiles:S,closeFile:x,canvasFiles:N},children:F(y4.Provider,{value:{setActiveView:P},children:F("div",{className:"min-h-screen bg-bg-base",children:[F(S4,{sessionId:J,projectRoot:V,connected:z,onMobileSidebar:()=>D(!I),collapsed:E,onToggle:()=>C((B)=>!B)},void 0,!1,void 0,this),F(b4,{collapsed:R,onToggle:()=>v((B)=>!B),children:F(z5,{onPreview:()=>W(!0),onSubmit:p},void 0,!1,void 0,this)},void 0,!1,void 0,this),G!==null?F("div",{className:`${E?"lg:ml-0":"lg:ml-60"} ${R?"lg:mr-0":"lg:mr-[var(--sidebar-width,320px)]"} transition-[margin] duration-200`,children:F(b2,{initialLeft:G.left,initialRight:G.right,sessionId:J,onExit:()=>_(null)},void 0,!1,void 0,this)},void 0,!1,void 0,this):F("div",{className:`relative ${E?"lg:ml-0":"lg:ml-60"} ${R?"lg:mr-0":"lg:mr-[var(--sidebar-width,320px)]"} transition-[margin] duration-200`,id:"plan-scroll-container",children:[F("div",{className:"lg:hidden sticky top-0 z-20 flex items-center justify-between px-4 py-2 border-b border-border-subtle bg-bg-surface",children:[F("div",{className:"flex items-center gap-2",children:[F(U5,{currentSessionId:J,projectRoot:V},void 0,!1,void 0,this),F("span",{className:`w-1.5 h-1.5 rounded-full ${z?"bg-accent-green":"bg-accent-red"}`},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("div",{className:"flex items-center gap-1",children:[F(u2,{},void 0,!1,void 0,this),F("button",{onClick:()=>D(!I),className:"w-7 h-7 flex items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Annotations",children:F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:F("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),F(g2,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),F(w4,{},void 0,!1,void 0,this),T.type==="overview"&&F(C2,{revision:Z,responseBanner:c?.response?F(k2,{markdown:c.response},void 0,!1,void 0,this):void 0},void 0,!1,void 0,this),T.type==="canvas"&&N.includes(T.filename)&&F("div",{className:"relative max-w-[720px] mx-auto px-6 pt-12 pb-32",children:[F("button",{onClick:()=>{let B=document.querySelector(`[data-canvas-file="${T.filename}"] .plan-content`);if(!B)return;let b=U2(B);navigator.clipboard.writeText(b).then(()=>{let g=document.getElementById("export-md-btn");if(g)g.setAttribute("data-copied","true"),setTimeout(()=>{g.removeAttribute("data-copied")},1500)})},id:"export-md-btn",className:"group absolute top-3 right-6 p-1.5 text-text-tertiary hover:text-text-secondary transition-colors z-10",title:"Copy as Markdown",children:[F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"group-[[data-copied=true]]:hidden",children:[F("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"},void 0,!1,void 0,this),F("path",{d:"M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"hidden group-[[data-copied=true]]:block text-green-500",children:F("polyline",{points:"20 6 9 17 4 12"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),N.length<=1&&c?.response&&F(k2,{markdown:c.response},void 0,!1,void 0,this),F("div",{"data-canvas-file":T.filename,children:F(Y0,{revision:Z,filename:T.filename},T.filename,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),S.map((B)=>F("div",{style:{display:T.type==="file"&&T.path===B?void 0:"none"},children:F(q2,{path:B},void 0,!1,void 0,this)},B,!1,void 0,this))]},void 0,!0,void 0,this),I&&F("div",{className:"lg:hidden fixed inset-0 z-40 flex",children:[F("div",{className:"flex-1",onClick:()=>D(!1)},void 0,!1,void 0,this),F("div",{className:"w-80 max-w-[85vw] bg-bg-surface border-l border-border-subtle flex flex-col shadow-lg",children:[F("div",{className:"flex items-center justify-between px-4 py-2 border-b border-border-subtle flex-shrink-0",children:[F("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:"Sidebar"},void 0,!1,void 0,this),F("button",{onClick:()=>D(!1),className:"text-text-tertiary hover:text-text-secondary w-7 h-7 flex items-center justify-center",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("div",{className:"flex-1 overflow-hidden",children:F(z5,{onPreview:()=>W(!0),onSubmit:p},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),F(o5,{open:U,onClose:()=>W(!1),onSubmit:p},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},`${J}:${Z}`,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function S4({sessionId:J,projectRoot:$,connected:Y,onMobileSidebar:Z,collapsed:Q,onToggle:q}){return F(E0,{children:[Q&&F("button",{onClick:q,className:"hidden lg:flex fixed top-3 left-3 z-20 w-7 h-7 items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors bg-bg-surface border border-border-subtle",title:"Show sidebar",children:F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[F("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"},void 0,!1,void 0,this),F("line",{x1:"9",y1:"3",x2:"9",y2:"21"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),F("div",{className:`hidden lg:flex w-60 flex-col fixed top-0 left-0 bottom-0 bg-bg-surface border-r border-border-subtle z-10 transition-transform duration-200 ${Q?"-translate-x-full":""}`,children:[F("div",{className:"px-4 pt-4 pb-3 flex-shrink-0 border-b border-border-subtle",children:[F("div",{className:"flex items-center gap-2 mb-2",children:[F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",className:"text-text-tertiary flex-shrink-0",children:F("path",{d:"M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this),F(U5,{currentSessionId:J,projectRoot:$},void 0,!1,void 0,this),F("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${Y?"bg-accent-green":"bg-accent-red"}`},void 0,!1,void 0,this),F("button",{onClick:q,className:"ml-auto w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Hide sidebar",children:F("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[F("polyline",{points:"11 17 6 12 11 7"},void 0,!1,void 0,this),F("polyline",{points:"18 17 13 12 18 7"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F(u2,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("div",{className:"flex-1 flex flex-col overflow-hidden",children:F(Y2,{embedded:!0},void 0,!1,void 0,this)},void 0,!1,void 0,this),F("div",{className:"px-4 py-3 border-t border-border-subtle flex items-center justify-between flex-shrink-0",children:[F("span",{className:"text-[10px] text-text-tertiary font-body uppercase tracking-widest",children:"Theme"},void 0,!1,void 0,this),F(g2,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function b4({children:J,collapsed:$,onToggle:Y}){let[Z,Q]=$1(()=>{let H=localStorage.getItem("canvas-sidebar-width");return H?parseInt(H,10):320}),q=I1(!1),X=I1(0),G=I1(0),_=I1(Z);_.current=Z;let z=u0((H)=>{H.preventDefault(),q.current=!0,X.current=H.clientX,G.current=_.current;let U=(N)=>{if(!q.current)return;let K=X.current-N.clientX,T=Math.max(240,Math.min(600,G.current+K));Q(T),_.current=T},W=()=>{q.current=!1,localStorage.setItem("canvas-sidebar-width",String(_.current)),document.removeEventListener("mousemove",U),document.removeEventListener("mouseup",W),document.body.style.cursor="",document.body.style.userSelect=""};document.addEventListener("mousemove",U),document.addEventListener("mouseup",W),document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[]);return M1(()=>{return document.documentElement.style.setProperty("--sidebar-width",`${Z}px`),()=>{document.documentElement.style.removeProperty("--sidebar-width")}},[Z]),F(E0,{children:[$&&F("button",{onClick:Y,className:"hidden lg:flex fixed top-3 right-3 z-20 w-7 h-7 items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors bg-bg-surface border border-border-subtle",title:"Show annotations",children:F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:F("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),F("div",{className:`hidden lg:flex flex-col fixed top-0 right-0 bottom-0 bg-bg-surface border-l border-border-subtle z-10 transition-transform duration-200 ${$?"translate-x-full":""}`,style:{width:Z},children:[F("div",{onMouseDown:z,className:"absolute left-0 top-0 bottom-0 w-1 cursor-col-resize hover:bg-accent-blue/30 transition-colors z-20",style:{marginLeft:"-2px"}},void 0,!1,void 0,this),A1.Children.map(J,(H)=>A1.isValidElement(H)?A1.cloneElement(H,{collapseButton:F("button",{onClick:Y,className:"w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Hide annotations",children:F("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[F("polyline",{points:"13 17 18 12 13 7"},void 0,!1,void 0,this),F("polyline",{points:"6 17 11 12 6 7"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}):H)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function k2({markdown:J}){let[$,Y]=$1(!1),Z=j2(()=>a.parse(J,{async:!1}),[J]),Q=I1(null),{annotations:q,addAnnotationWithId:X,removeAnnotation:G,updateAnnotation:_,addAnnotationImage:z,removeAnnotationImage:H,activeAnnotationId:U,setActiveAnnotationId:W}=e(),[N,K]=$1(null),[T,O]=$1(null),S=j2(()=>q.filter((I)=>I.filePath===q1),[q]),[L,j]=$1(J);if(J!==L)j(J),Y(!1);M1(()=>{if(!Q.current||S.length===0)return;let I=setTimeout(()=>{if(Q.current)P0(Q.current,S)},50);return()=>clearTimeout(I)},[Z,S.length]);let V=I1(null);if(M1(()=>{y0(U,V.current),V.current=U},[U]),M1(()=>{let I=Q.current;if(!I)return;let D=(R)=>{let v=R.target.closest("[data-annotation-id]");if(!v)return;R.stopPropagation();let m=v.getAttribute("data-annotation-id");if(m===U)O({anchorEl:v,annId:m});else W(m)},E=(R)=>{let v=R.target.closest("[data-annotation-id]");if(v)W(v.getAttribute("data-annotation-id"))},C=(R)=>{let v=R.target.closest("[data-annotation-id]"),m=R.relatedTarget?.closest?.("[data-annotation-id]");if(v&&!m)W(null)};return I.addEventListener("click",D),I.addEventListener("mouseover",E),I.addEventListener("mouseout",C),()=>{I.removeEventListener("click",D),I.removeEventListener("mouseover",E),I.removeEventListener("mouseout",C)}},[Z,U]),M1(()=>{let I=()=>{let D=window.getSelection();if(!D||D.isCollapsed||!D.toString().trim())return;if(!Q.current)return;let E=D.getRangeAt(0);if(!Q.current.contains(E.startContainer))return;if(E.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let C=D.toString().trim();if(C.length<2)return;let R=E.cloneRange(),v=D1(E,Q.current),m=`__pending_${Date.now()}`;try{g1(R,m)}catch{}window.getSelection()?.removeAllRanges();let c=document.querySelectorAll(`[data-annotation-id="${m}"]`),y=c[c.length-1];if(!y)return;K({anchorEl:y,tempId:m,snippet:C,ctx:v})};return document.addEventListener("mouseup",I),()=>document.removeEventListener("mouseup",I)},[]),$)return null;let M=document.getElementById("plan-scroll-container");return F("div",{className:"mb-6 rounded-lg border border-accent-blue/20 bg-accent-blue/5 relative",children:[F("button",{onClick:()=>Y(!0),className:"absolute top-2 right-2 w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",children:F("span",{className:"text-xs",children:"✕"},void 0,!1,void 0,this)},void 0,!1,void 0,this),F("div",{className:"px-4 py-3 pr-10",children:[F("div",{className:"flex items-center gap-2 mb-1.5",children:[F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-accent-blue flex-shrink-0",children:F("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this),F("span",{className:"text-[11px] font-medium uppercase tracking-widest text-accent-blue font-body",children:"Agent Response"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("div",{ref:Q,className:"prose-canvas text-sm",dangerouslySetInnerHTML:{__html:Z}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),N&&F(c1,{anchorEl:N.anchorEl,scrollContainer:M,snippet:N.snippet,truncateAt:80,onAdd:(I,D)=>{let E=U1();M0(N.tempId,E),X(E,N.snippet,I,q1,N.ctx,D),K(null)},onCancel:()=>{S0(N.tempId),K(null)}},void 0,!1,void 0,this),T&&(()=>{let I=q.find((D)=>D.id===T.annId);if(!I)return null;return F(d1,{anchorEl:T.anchorEl,scrollContainer:M,initialNote:I.note,initialImages:I.images,onUpdate:(D,E)=>{_(T.annId,D);let C=I.images||[];for(let R of E)if(!C.includes(R))z(T.annId,R);for(let R of C)if(!E.includes(R))H(T.annId,R)},onDelete:()=>{G(T.annId),W(null)},onClose:()=>O(null)},void 0,!1,void 0,this)})()]},void 0,!0,void 0,this)}function w4(){let{activeView:J,setActiveView:$,openFiles:Y,closeFile:Z,canvasFiles:Q}=A1.useContext(F1),q=A1.useContext(m2),{addAnnotationWithId:X,setActiveAnnotationId:G}=e();if(!(Q.length>1||Y.length>0))return null;return F("div",{className:"flex items-center border-b border-border-medium bg-bg-surface overflow-x-auto sticky top-0 z-10",children:[Q.length>1&&F(E0,{children:[F("button",{onClick:()=>$({type:"overview"}),className:`flex items-center gap-1.5 px-4 py-2.5 text-[13px] font-body whitespace-nowrap transition-colors relative ${J.type==="overview"?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",className:"opacity-60",children:F("path",{d:"M12 7L2 12l10 5 10-5-10-5z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this),"Overview",J.type==="overview"&&F("span",{className:"absolute bottom-0 left-3 right-3 h-[2px] bg-text-primary rounded-full"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Q.map((z,H)=>{let U=z.replace(/\.jsx$/,""),W=J.type==="canvas"&&J.filename===z;return F(A1.Fragment,{children:[F("button",{onClick:()=>$({type:"canvas",filename:z}),className:`flex items-center gap-1.5 px-4 py-2.5 text-[13px] font-body whitespace-nowrap transition-colors relative ${W?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[U,W&&F("span",{className:"absolute bottom-0 left-3 right-3 h-[2px] bg-text-primary rounded-full"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),H<Q.length-1&&F("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this)]},z,!0,void 0,this)}),Y.length>0&&F(E0,{children:[F("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this),Y.map((z,H)=>{let U=z.split("/").pop()||z,W=J.type==="file"&&J.path===z;return F(A1.Fragment,{children:[F("div",{className:"flex items-center",children:[F("button",{onClick:()=>$({type:"file",path:z}),className:`flex items-center gap-1.5 pl-3 pr-1 py-2.5 text-[13px] font-body whitespace-nowrap transition-colors relative ${W?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[F(P1,{name:U,type:"file"},void 0,!1,void 0,this),U,W&&F("span",{className:"absolute bottom-0 left-3 right-1 h-[2px] bg-text-primary rounded-full"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("button",{onClick:(N)=>{N.stopPropagation(),Z(z)},className:"text-text-tertiary hover:text-text-secondary px-1.5 py-1 text-[10px] transition-colors rounded hover:bg-bg-input",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),H<Y.length-1&&F("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this)]},z,!0,void 0,this)})]},void 0,!0,void 0,this),F("div",{className:"ml-auto flex items-center gap-1 flex-shrink-0",children:J.type==="file"&&F("button",{onClick:async()=>{let z=J.path;try{let U=await(await fetch(`/api/file?session=${q}&path=${encodeURIComponent(z)}`)).json();if(!U.error){let W=U.content.split(`
88
88
  `).slice(0,3).join(`
89
89
  `)+(U.content.split(`
90
90
  `).length>3?`
91
- ...`:""),N=U1();X(N,W,"",z),G(N)}}catch{}},className:"flex items-center gap-1 px-3 py-1.5 text-[11px] font-medium font-body text-text-tertiary hover:text-text-secondary whitespace-nowrap transition-colors",children:[F("span",{className:"text-[13px] leading-none",children:"+"},void 0,!1,void 0,this),"Add to context"]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var V2=document.getElementById("root");if(V2)L4(V2).render(F(M4,{},void 0,!1,void 0,this));export{N1 as RevisionContext,F1 as ActiveViewContext};
91
+ ...`:""),N=U1();X(N,W,"",z),G(N)}}catch{}},className:"flex items-center gap-1 px-3 py-1.5 text-[11px] font-medium font-body text-text-tertiary hover:text-text-secondary whitespace-nowrap transition-colors",children:[F("span",{className:"text-[13px] leading-none",children:"+"},void 0,!1,void 0,this),"Add to context"]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var V2=document.getElementById("root");if(V2)B4(V2).render(F(P4,{},void 0,!1,void 0,this));export{N1 as RevisionContext,F1 as ActiveViewContext};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-canvas",
3
- "version": "0.1.15",
3
+ "version": "0.1.16",
4
4
  "description": "Interactive visual canvas for Claude Code — rich annotatable documents in the browser",
5
5
  "bin": {
6
6
  "agent-canvas": "bin/agent-canvas.js"