agent-canvas 0.1.43 → 0.1.45

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.
Files changed (110) hide show
  1. package/bin/lib/commands/daemon.ts +3 -6
  2. package/bin/lib/commands/push.ts +1 -1
  3. package/bin/lib/daemon-lifecycle.ts +65 -72
  4. package/bin/lib/helpers.test.ts +1 -0
  5. package/bin/lib/helpers.ts +30 -74
  6. package/daemon/build.ts +16 -13
  7. package/daemon/client/App.tsx +38 -62
  8. package/daemon/client/CompareView.tsx +4 -4
  9. package/daemon/client/FileBrowser.tsx +4 -4
  10. package/daemon/client/FileViewer.tsx +4 -4
  11. package/daemon/client/OverviewView.tsx +2 -2
  12. package/daemon/client/RevisionSelect.tsx +1 -1
  13. package/daemon/client/clientApi.ts +18 -0
  14. package/daemon/client/components/index.ts +3 -16
  15. package/daemon/client/styles.css +4 -457
  16. package/daemon/dist/client.css +1 -1
  17. package/daemon/dist/client.js +76 -76
  18. package/daemon/dist/components.js +29 -29
  19. package/daemon/dist/runtime.js +1 -1
  20. package/daemon/src/components.ts +13 -0
  21. package/daemon/src/handlers/api.ts +14 -9
  22. package/daemon/src/handlers/files.ts +1 -3
  23. package/daemon/src/handlers/static.ts +1 -1
  24. package/daemon/src/handlers/uploads.ts +1 -3
  25. package/daemon/src/paths.ts +10 -24
  26. package/daemon/src/remote-feedback.test.ts +1 -1
  27. package/daemon/src/remote-feedback.ts +1 -1
  28. package/daemon/src/secrets-api.test.ts +1 -2
  29. package/daemon/src/server.ts +13 -10
  30. package/daemon/src/share-e2e.test.ts +1 -1
  31. package/daemon/src/share.test.ts +1 -1
  32. package/daemon/src/share.ts +1 -1
  33. package/daemon/tsconfig.json +1 -3
  34. package/package.json +10 -2
  35. package/.github/dark.png +0 -0
  36. package/.github/light.png +0 -0
  37. package/.github/workflows/ci.yml +0 -48
  38. package/.github/workflows/deploy-worker-prod.yml +0 -19
  39. package/.github/workflows/deploy-worker-stage.yml +0 -21
  40. package/.github/workflows/deploy-worker.yml +0 -72
  41. package/.github/workflows/release.yml +0 -36
  42. package/CLAUDE.md +0 -86
  43. package/bun.lock +0 -377
  44. package/daemon/client/AnnotationEditor.tsx +0 -315
  45. package/daemon/client/AnnotationProvider.tsx +0 -191
  46. package/daemon/client/AnnotationSidebar.tsx +0 -627
  47. package/daemon/client/FileIcon.tsx +0 -76
  48. package/daemon/client/PlanRenderer.tsx +0 -614
  49. package/daemon/client/Popover.tsx +0 -350
  50. package/daemon/client/RenderErrorContext.ts +0 -11
  51. package/daemon/client/ResponsePreview.tsx +0 -186
  52. package/daemon/client/SessionContext.tsx +0 -3
  53. package/daemon/client/annotationContext.ts +0 -114
  54. package/daemon/client/annotationDom.ts +0 -104
  55. package/daemon/client/annotationDraft.test.ts +0 -149
  56. package/daemon/client/annotationDraft.ts +0 -110
  57. package/daemon/client/compat/preact-all.ts +0 -4
  58. package/daemon/client/components/Callout.tsx +0 -26
  59. package/daemon/client/components/Checklist.tsx +0 -37
  60. package/daemon/client/components/Choice.tsx +0 -176
  61. package/daemon/client/components/CodeBlock.tsx +0 -35
  62. package/daemon/client/components/Diff.tsx +0 -65
  63. package/daemon/client/components/FilePreview.tsx +0 -88
  64. package/daemon/client/components/Image.tsx +0 -45
  65. package/daemon/client/components/Markdown.tsx +0 -44
  66. package/daemon/client/components/Mermaid.tsx +0 -565
  67. package/daemon/client/components/Note.tsx +0 -14
  68. package/daemon/client/components/Priority.tsx +0 -19
  69. package/daemon/client/components/ResponseNote.tsx +0 -19
  70. package/daemon/client/components/Section.tsx +0 -33
  71. package/daemon/client/components/Table.tsx +0 -35
  72. package/daemon/client/components/Task.tsx +0 -76
  73. package/daemon/client/components/UserInput.tsx +0 -174
  74. package/daemon/client/components/renderMarkdownChildren.tsx +0 -97
  75. package/daemon/client/generateMarkdown.ts +0 -273
  76. package/daemon/client/highlightRange.ts +0 -224
  77. package/daemon/client/popoverPosition.ts +0 -31
  78. package/daemon/client/runtime.ts +0 -123
  79. package/daemon/client/theme.css +0 -66
  80. package/daemon/client/useTextAnnotation.tsx +0 -188
  81. package/daemon/client/utils.ts +0 -13
  82. package/daemon/src/compiler.test.ts +0 -57
  83. package/daemon/src/compiler.ts +0 -360
  84. package/daemon/src/handlers/utils.ts +0 -14
  85. package/daemon/src/router.ts +0 -16
  86. package/daemon/src/session-secrets.test.ts +0 -83
  87. package/daemon/src/session.ts +0 -612
  88. package/daemon/src/watcher.ts +0 -71
  89. package/daemon/src/websocket.test.ts +0 -99
  90. package/daemon/src/websocket.ts +0 -211
  91. package/tsconfig.json +0 -14
  92. package/workers/canvas-share/README.md +0 -159
  93. package/workers/canvas-share/oblaka.ts +0 -56
  94. package/workers/canvas-share/package.json +0 -25
  95. package/workers/canvas-share/public/assets/.gitkeep +0 -0
  96. package/workers/canvas-share/public/assets/client.css +0 -2
  97. package/workers/canvas-share/public/assets/client.js +0 -91
  98. package/workers/canvas-share/public/assets/components.js +0 -65
  99. package/workers/canvas-share/public/assets/jsx-runtime.js +0 -3
  100. package/workers/canvas-share/public/assets/preact-compat.js +0 -1
  101. package/workers/canvas-share/public/assets/runtime.js +0 -1
  102. package/workers/canvas-share/public/index.html +0 -385
  103. package/workers/canvas-share/public/screenshot-dark.png +0 -0
  104. package/workers/canvas-share/public/screenshot-light.png +0 -0
  105. package/workers/canvas-share/src/index.test.ts +0 -209
  106. package/workers/canvas-share/src/index.ts +0 -518
  107. package/workers/canvas-share/src/types.ts +0 -119
  108. package/workers/canvas-share/src/util.ts +0 -156
  109. package/workers/canvas-share/src/validation.ts +0 -160
  110. package/workers/canvas-share/tsconfig.json +0 -16
@@ -1,91 +1,91 @@
1
- import p1,{useEffect as y1,useLayoutEffect as k6,useState as J1,useCallback as K0,useRef as V1,createContext as D5,useMemo as A5}from"react";import{createRoot as E6}from"react-dom/client";function F2(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var r1=F2();function J3(Z){r1=Z}var d1={exec:()=>null};function n(Z,$=""){let q=typeof Z=="string"?Z:Z.source,Q={replace:(J,Y)=>{let X=typeof Y=="string"?Y:Y.source;return X=X.replace(K1.caret,"$1"),q=q.replace(J,X),Q},getRegex:()=>new RegExp(q,$)};return Q}var g5=(()=>{try{return!!new RegExp("(?<=1)(?<!1)")}catch{return!1}})(),K1={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] +\S/,listReplaceTask:/^\[[ xX]\] +/,listTaskCheckbox:/\[[ xX]\]/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:(Z)=>new RegExp(`^( {0,3}${Z})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:(Z)=>new RegExp(`^ {0,${Math.min(3,Z-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:(Z)=>new RegExp(`^ {0,${Math.min(3,Z-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:(Z)=>new RegExp(`^ {0,${Math.min(3,Z-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:(Z)=>new RegExp(`^ {0,${Math.min(3,Z-1)}}#`),htmlBeginRegex:(Z)=>new RegExp(`^ {0,${Math.min(3,Z-1)}}<(?:[a-z].*>|!--)`,"i"),blockquoteBeginRegex:(Z)=>new RegExp(`^ {0,${Math.min(3,Z-1)}}>`)},f5=/^(?:[ \t]*(?:\n|$))+/,v5=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,h5=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,L0=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,p5=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,B2=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,Q3=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,Y3=n(Q3).replace(/bull/g,B2).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(),c5=n(Q3).replace(/bull/g,B2).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),L2=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,d5=/^[^\n]+/,M2=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,l5=n(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",M2).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),r5=n(/^(bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,B2).getRegex(),f0="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",P2=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,i5=n("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$))","i").replace("comment",P2).replace("tag",f0).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),X3=n(L2).replace("hr",L0).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",f0).getRegex(),a5=n(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",X3).getRegex(),y2={blockquote:a5,code:v5,def:l5,fences:h5,heading:p5,hr:L0,html:i5,lheading:Y3,list:r5,newline:f5,paragraph:X3,table:d1,text:d5},t2=n("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",L0).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",f0).getRegex(),o5={...y2,lheading:c5,table:t2,paragraph:n(L2).replace("hr",L0).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",t2).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",f0).getRegex()},s5={...y2,html:n(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",P2).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:d1,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:n(L2).replace("hr",L0).replace("heading",` *#{1,6} *[^
2
- ]`).replace("lheading",Y3).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},t5=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,n5=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,z3=/^( {2,}|\\)\n(?!\s*$)/,e5=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,J0=/[\p{P}\p{S}]/u,v0=/[\s\p{P}\p{S}]/u,S2=/[^\s\p{P}\p{S}]/u,$8=n(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,v0).getRegex(),_3=/(?!~)[\p{P}\p{S}]/u,Z8=/(?!~)[\s\p{P}\p{S}]/u,q8=/(?:[^\s\p{P}\p{S}]|~)/u,J8=n(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",g5?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),G3=/^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/,Q8=n(G3,"u").replace(/punct/g,J0).getRegex(),Y8=n(G3,"u").replace(/punct/g,_3).getRegex(),U3="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",X8=n(U3,"gu").replace(/notPunctSpace/g,S2).replace(/punctSpace/g,v0).replace(/punct/g,J0).getRegex(),z8=n(U3,"gu").replace(/notPunctSpace/g,q8).replace(/punctSpace/g,Z8).replace(/punct/g,_3).getRegex(),_8=n("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,S2).replace(/punctSpace/g,v0).replace(/punct/g,J0).getRegex(),G8=n(/^~~?(?:((?!~)punct)|[^\s~])/,"u").replace(/punct/g,J0).getRegex(),U8="^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)",K8=n(U8,"gu").replace(/notPunctSpace/g,S2).replace(/punctSpace/g,v0).replace(/punct/g,J0).getRegex(),H8=n(/\\(punct)/,"gu").replace(/punct/g,J0).getRegex(),W8=n(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme",/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email",/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),T8=n(P2).replace("(?:-->|$)","-->").getRegex(),N8=n("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment",T8).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),m0=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/,O8=n(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace("label",m0).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),K3=n(/^!?\[(label)\]\[(ref)\]/).replace("label",m0).replace("ref",M2).getRegex(),H3=n(/^!?\[(ref)\](?:\[\])?/).replace("ref",M2).getRegex(),F8=n("reflink|nolink(?!\\()","g").replace("reflink",K3).replace("nolink",H3).getRegex(),n2=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,b2={_backpedal:d1,anyPunctuation:H8,autolink:W8,blockSkip:J8,br:z3,code:n5,del:d1,delLDelim:d1,delRDelim:d1,emStrongLDelim:Q8,emStrongRDelimAst:X8,emStrongRDelimUnd:_8,escape:t5,link:O8,nolink:H3,punctuation:$8,reflink:K3,reflinkSearch:F8,tag:N8,text:e5,url:d1},B8={...b2,link:n(/^!?\[(label)\]\((.*?)\)/).replace("label",m0).getRegex(),reflink:n(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",m0).getRegex()},O2={...b2,emStrongRDelimAst:z8,emStrongLDelim:Y8,delLDelim:G8,delRDelim:K8,url:n(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol",n2).replace("email",/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/,text:n(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace("protocol",n2).getRegex()},L8={...O2,br:n(z3).replace("{2,}","*").getRegex(),text:n(O2.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},x0={normal:y2,gfm:o5,pedantic:s5},O0={normal:b2,gfm:O2,breaks:L8,pedantic:B8},M8={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},e2=(Z)=>M8[Z];function b1(Z,$){if($){if(K1.escapeTest.test(Z))return Z.replace(K1.escapeReplace,e2)}else if(K1.escapeTestNoEncode.test(Z))return Z.replace(K1.escapeReplaceNoEncode,e2);return Z}function $3(Z){try{Z=encodeURI(Z).replace(K1.percentDecode,"%")}catch{return null}return Z}function Z3(Z,$){let q=Z.replace(K1.findPipe,(Y,X,G)=>{let z=!1,_=X;for(;--_>=0&&G[_]==="\\";)z=!z;return z?"|":" |"}),Q=q.split(K1.splitPipe),J=0;if(Q[0].trim()||Q.shift(),Q.length>0&&!Q.at(-1)?.trim()&&Q.pop(),$)if(Q.length>$)Q.splice($);else for(;Q.length<$;)Q.push("");for(;J<Q.length;J++)Q[J]=Q[J].trim().replace(K1.slashPipe,"|");return Q}function F0(Z,$,q){let Q=Z.length;if(Q===0)return"";let J=0;for(;J<Q;){let Y=Z.charAt(Q-J-1);if(Y===$&&!q)J++;else if(Y!==$&&q)J++;else break}return Z.slice(0,Q-J)}function P8(Z,$){if(Z.indexOf($[1])===-1)return-1;let q=0;for(let Q=0;Q<Z.length;Q++)if(Z[Q]==="\\")Q++;else if(Z[Q]===$[0])q++;else if(Z[Q]===$[1]&&(q--,q<0))return Q;return q>0?-2:-1}function y8(Z,$=0){let q=$,Q="";for(let J of Z)if(J==="\t"){let Y=4-q%4;Q+=" ".repeat(Y),q+=Y}else Q+=J,q++;return Q}function q3(Z,$,q,Q,J){let Y=$.href,X=$.title||null,G=Z[1].replace(J.other.outputLinkReplace,"$1");Q.state.inLink=!0;let z={type:Z[0].charAt(0)==="!"?"image":"link",raw:q,href:Y,title:X,text:G,tokens:Q.inlineTokens(G)};return Q.state.inLink=!1,z}function S8(Z,$,q){let Q=Z.match(q.other.indentCodeCompensation);if(Q===null)return $;let J=Q[1];return $.split(`
3
- `).map((Y)=>{let X=Y.match(q.other.beginningSpace);if(X===null)return Y;let[G]=X;return G.length>=J.length?Y.slice(J.length):Y}).join(`
4
- `)}var u0=class{options;rules;lexer;constructor(Z){this.options=Z||r1}space(Z){let $=this.rules.block.newline.exec(Z);if($&&$[0].length>0)return{type:"space",raw:$[0]}}code(Z){let $=this.rules.block.code.exec(Z);if($){let q=$[0].replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:$[0],codeBlockStyle:"indented",text:this.options.pedantic?q:F0(q,`
5
- `)}}}fences(Z){let $=this.rules.block.fences.exec(Z);if($){let q=$[0],Q=S8(q,$[3]||"",this.rules);return{type:"code",raw:q,lang:$[2]?$[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):$[2],text:Q}}}heading(Z){let $=this.rules.block.heading.exec(Z);if($){let q=$[2].trim();if(this.rules.other.endingHash.test(q)){let Q=F0(q,"#");(this.options.pedantic||!Q||this.rules.other.endingSpaceChar.test(Q))&&(q=Q.trim())}return{type:"heading",raw:$[0],depth:$[1].length,text:q,tokens:this.lexer.inline(q)}}}hr(Z){let $=this.rules.block.hr.exec(Z);if($)return{type:"hr",raw:F0($[0],`
6
- `)}}blockquote(Z){let $=this.rules.block.blockquote.exec(Z);if($){let q=F0($[0],`
1
+ import Y0,{useEffect as k1,useLayoutEffect as p8,useState as Y1,useCallback as b0,useRef as g1,useMemo as C4}from"react";import{createRoot as c8}from"react-dom/client";function p2(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var G0=p2();function c5($){G0=$}var q0={exec:()=>null};function e($,Q=""){let J=typeof $=="string"?$:$.source,X={replace:(Y,Z)=>{let q=typeof Z=="string"?Z:Z.source;return q=q.replace(B1.caret,"$1"),J=J.replace(Y,q),X},getRegex:()=>new RegExp(J,Q)};return X}var x4=(()=>{try{return!!new RegExp("(?<=1)(?<!1)")}catch{return!1}})(),B1={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:($)=>new RegExp(`^( {0,3}${$})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:($)=>new RegExp(`^ {0,${Math.min(3,$-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:($)=>new RegExp(`^ {0,${Math.min(3,$-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:($)=>new RegExp(`^ {0,${Math.min(3,$-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:($)=>new RegExp(`^ {0,${Math.min(3,$-1)}}#`),htmlBeginRegex:($)=>new RegExp(`^ {0,${Math.min(3,$-1)}}<(?:[a-z].*>|!--)`,"i"),blockquoteBeginRegex:($)=>new RegExp(`^ {0,${Math.min(3,$-1)}}>`)},f4=/^(?:[ \t]*(?:\n|$))+/,v4=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,u4=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,D0=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,g4=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,c2=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,d5=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,l5=e(d5).replace(/bull/g,c2).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(),h4=e(d5).replace(/bull/g,c2).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(),d2=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,p4=/^[^\n]+/,l2=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,c4=e(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",l2).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),d4=e(/^(bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,c2).getRegex(),K2="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",r2=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,l4=e("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$))","i").replace("comment",r2).replace("tag",K2).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),r5=e(d2).replace("hr",D0).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",K2).getRegex(),r4=e(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",r5).getRegex(),i2={blockquote:r4,code:v4,def:c4,fences:u4,heading:g4,hr:D0,html:l4,lheading:l5,list:d4,newline:f4,paragraph:r5,table:q0,text:p4},f5=e("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",D0).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",K2).getRegex(),i4={...i2,lheading:h4,table:f5,paragraph:e(d2).replace("hr",D0).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",f5).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",K2).getRegex()},o4={...i2,html:e(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",r2).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:q0,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:e(d2).replace("hr",D0).replace("heading",` *#{1,6} *[^
2
+ ]`).replace("lheading",l5).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},a4=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,s4=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,i5=/^( {2,}|\\)\n(?!\s*$)/,t4=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,O0=/[\p{P}\p{S}]/u,z2=/[\s\p{P}\p{S}]/u,o2=/[^\s\p{P}\p{S}]/u,n4=e(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,z2).getRegex(),o5=/(?!~)[\p{P}\p{S}]/u,e4=/(?!~)[\s\p{P}\p{S}]/u,$6=/(?:[^\s\p{P}\p{S}]|~)/u,Q6=e(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",x4?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),a5=/^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/,J6=e(a5,"u").replace(/punct/g,O0).getRegex(),Y6=e(a5,"u").replace(/punct/g,o5).getRegex(),s5="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",X6=e(s5,"gu").replace(/notPunctSpace/g,o2).replace(/punctSpace/g,z2).replace(/punct/g,O0).getRegex(),q6=e(s5,"gu").replace(/notPunctSpace/g,$6).replace(/punctSpace/g,e4).replace(/punct/g,o5).getRegex(),Z6=e("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,o2).replace(/punctSpace/g,z2).replace(/punct/g,O0).getRegex(),G6=e(/^~~?(?:((?!~)punct)|[^\s~])/,"u").replace(/punct/g,O0).getRegex(),U6="^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)",K6=e(U6,"gu").replace(/notPunctSpace/g,o2).replace(/punctSpace/g,z2).replace(/punct/g,O0).getRegex(),z6=e(/\\(punct)/,"gu").replace(/punct/g,O0).getRegex(),_6=e(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme",/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email",/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),H6=e(r2).replace("(?:-->|$)","-->").getRegex(),W6=e("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment",H6).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),Z2=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/,N6=e(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace("label",Z2).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),t5=e(/^!?\[(label)\]\[(ref)\]/).replace("label",Z2).replace("ref",l2).getRegex(),n5=e(/^!?\[(ref)\](?:\[\])?/).replace("ref",l2).getRegex(),B6=e("reflink|nolink(?!\\()","g").replace("reflink",t5).replace("nolink",n5).getRegex(),v5=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,a2={_backpedal:q0,anyPunctuation:z6,autolink:_6,blockSkip:Q6,br:i5,code:s4,del:q0,delLDelim:q0,delRDelim:q0,emStrongLDelim:J6,emStrongRDelimAst:X6,emStrongRDelimUnd:Z6,escape:a4,link:N6,nolink:n5,punctuation:n4,reflink:t5,reflinkSearch:B6,tag:W6,text:t4,url:q0},T6={...a2,link:e(/^!?\[(label)\]\((.*?)\)/).replace("label",Z2).getRegex(),reflink:e(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",Z2).getRegex()},h2={...a2,emStrongRDelimAst:q6,emStrongLDelim:Y6,delLDelim:G6,delRDelim:K6,url:e(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol",v5).replace("email",/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/,text:e(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace("protocol",v5).getRegex()},F6={...h2,br:e(i5).replace("{2,}","*").getRegex(),text:e(h2.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},q2={normal:i2,gfm:i4,pedantic:o4},V0={normal:a2,gfm:h2,breaks:F6,pedantic:T6},O6={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},u5=($)=>O6[$];function R1($,Q){if(Q){if(B1.escapeTest.test($))return $.replace(B1.escapeReplace,u5)}else if(B1.escapeTestNoEncode.test($))return $.replace(B1.escapeReplaceNoEncode,u5);return $}function g5($){try{$=encodeURI($).replace(B1.percentDecode,"%")}catch{return null}return $}function h5($,Q){let J=$.replace(B1.findPipe,(Z,q,U)=>{let G=!1,K=q;for(;--K>=0&&U[K]==="\\";)G=!G;return G?"|":" |"}),X=J.split(B1.splitPipe),Y=0;if(X[0].trim()||X.shift(),X.length>0&&!X.at(-1)?.trim()&&X.pop(),Q)if(X.length>Q)X.splice(Q);else for(;X.length<Q;)X.push("");for(;Y<X.length;Y++)X[Y]=X[Y].trim().replace(B1.slashPipe,"|");return X}function k0($,Q,J){let X=$.length;if(X===0)return"";let Y=0;for(;Y<X;){let Z=$.charAt(X-Y-1);if(Z===Q&&!J)Y++;else if(Z!==Q&&J)Y++;else break}return $.slice(0,X-Y)}function L6($,Q){if($.indexOf(Q[1])===-1)return-1;let J=0;for(let X=0;X<$.length;X++)if($[X]==="\\")X++;else if($[X]===Q[0])J++;else if($[X]===Q[1]&&(J--,J<0))return X;return J>0?-2:-1}function M6($,Q=0){let J=Q,X="";for(let Y of $)if(Y==="\t"){let Z=4-J%4;X+=" ".repeat(Z),J+=Z}else X+=Y,J++;return X}function p5($,Q,J,X,Y){let Z=Q.href,q=Q.title||null,U=$[1].replace(Y.other.outputLinkReplace,"$1");X.state.inLink=!0;let G={type:$[0].charAt(0)==="!"?"image":"link",raw:J,href:Z,title:q,text:U,tokens:X.inlineTokens(U)};return X.state.inLink=!1,G}function P6($,Q,J){let X=$.match(J.other.indentCodeCompensation);if(X===null)return Q;let Y=X[1];return Q.split(`
3
+ `).map((Z)=>{let q=Z.match(J.other.beginningSpace);if(q===null)return Z;let[U]=q;return U.length>=Y.length?Z.slice(Y.length):Z}).join(`
4
+ `)}var G2=class{options;rules;lexer;constructor($){this.options=$||G0}space($){let Q=this.rules.block.newline.exec($);if(Q&&Q[0].length>0)return{type:"space",raw:Q[0]}}code($){let Q=this.rules.block.code.exec($);if(Q){let J=Q[0].replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:Q[0],codeBlockStyle:"indented",text:this.options.pedantic?J:k0(J,`
5
+ `)}}}fences($){let Q=this.rules.block.fences.exec($);if(Q){let J=Q[0],X=P6(J,Q[3]||"",this.rules);return{type:"code",raw:J,lang:Q[2]?Q[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):Q[2],text:X}}}heading($){let Q=this.rules.block.heading.exec($);if(Q){let J=Q[2].trim();if(this.rules.other.endingHash.test(J)){let X=k0(J,"#");(this.options.pedantic||!X||this.rules.other.endingSpaceChar.test(X))&&(J=X.trim())}return{type:"heading",raw:Q[0],depth:Q[1].length,text:J,tokens:this.lexer.inline(J)}}}hr($){let Q=this.rules.block.hr.exec($);if(Q)return{type:"hr",raw:k0(Q[0],`
6
+ `)}}blockquote($){let Q=this.rules.block.blockquote.exec($);if(Q){let J=k0(Q[0],`
7
7
  `).split(`
8
- `),Q="",J="",Y=[];for(;q.length>0;){let X=!1,G=[],z;for(z=0;z<q.length;z++)if(this.rules.other.blockquoteStart.test(q[z]))G.push(q[z]),X=!0;else if(!X)G.push(q[z]);else break;q=q.slice(z);let _=G.join(`
9
- `),H=_.replace(this.rules.other.blockquoteSetextReplace,`
10
- $1`).replace(this.rules.other.blockquoteSetextReplace2,"");Q=Q?`${Q}
11
- ${_}`:_,J=J?`${J}
12
- ${H}`:H;let U=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(H,Y,!0),this.lexer.state.top=U,q.length===0)break;let W=Y.at(-1);if(W?.type==="code")break;if(W?.type==="blockquote"){let T=W,K=T.raw+`
13
- `+q.join(`
14
- `),L=this.blockquote(K);Y[Y.length-1]=L,Q=Q.substring(0,Q.length-T.raw.length)+L.raw,J=J.substring(0,J.length-T.text.length)+L.text;break}else if(W?.type==="list"){let T=W,K=T.raw+`
15
- `+q.join(`
16
- `),L=this.list(K);Y[Y.length-1]=L,Q=Q.substring(0,Q.length-W.raw.length)+L.raw,J=J.substring(0,J.length-T.raw.length)+L.raw,q=K.substring(Y.at(-1).raw.length).split(`
17
- `);continue}}return{type:"blockquote",raw:Q,tokens:Y,text:J}}}list(Z){let $=this.rules.block.list.exec(Z);if($){let q=$[1].trim(),Q=q.length>1,J={type:"list",raw:"",ordered:Q,start:Q?+q.slice(0,-1):"",loose:!1,items:[]};q=Q?`\\d{1,9}\\${q.slice(-1)}`:`\\${q}`,this.options.pedantic&&(q=Q?q:"[*+-]");let Y=this.rules.other.listItemRegex(q),X=!1;for(;Z;){let z=!1,_="",H="";if(!($=Y.exec(Z))||this.rules.block.hr.test(Z))break;_=$[0],Z=Z.substring(_.length);let U=y8($[2].split(`
18
- `,1)[0],$[1].length),W=Z.split(`
19
- `,1)[0],T=!U.trim(),K=0;if(this.options.pedantic?(K=2,H=U.trimStart()):T?K=$[1].length+1:(K=U.search(this.rules.other.nonSpaceChar),K=K>4?1:K,H=U.slice(K),K+=$[1].length),T&&this.rules.other.blankLine.test(W)&&(_+=W+`
20
- `,Z=Z.substring(W.length+1),z=!0),!z){let L=this.rules.other.nextBulletRegex(K),N=this.rules.other.hrRegex(K),y=this.rules.other.fencesBeginRegex(K),O=this.rules.other.headingBeginRegex(K),R=this.rules.other.htmlBeginRegex(K),S=this.rules.other.blockquoteBeginRegex(K);for(;Z;){let M=Z.split(`
21
- `,1)[0],b;if(W=M,this.options.pedantic?(W=W.replace(this.rules.other.listReplaceNesting," "),b=W):b=W.replace(this.rules.other.tabCharGlobal," "),y.test(W)||O.test(W)||R.test(W)||S.test(W)||L.test(W)||N.test(W))break;if(b.search(this.rules.other.nonSpaceChar)>=K||!W.trim())H+=`
22
- `+b.slice(K);else{if(T||U.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||y.test(U)||O.test(U)||N.test(U))break;H+=`
23
- `+W}T=!W.trim(),_+=M+`
24
- `,Z=Z.substring(M.length+1),U=b.slice(K)}}J.loose||(X?J.loose=!0:this.rules.other.doubleBlankLine.test(_)&&(X=!0)),J.items.push({type:"list_item",raw:_,task:!!this.options.gfm&&this.rules.other.listIsTask.test(H),loose:!1,text:H,tokens:[]}),J.raw+=_}let G=J.items.at(-1);if(G)G.raw=G.raw.trimEnd(),G.text=G.text.trimEnd();else return;J.raw=J.raw.trimEnd();for(let z of J.items){if(this.lexer.state.top=!1,z.tokens=this.lexer.blockTokens(z.text,[]),z.task){if(z.text=z.text.replace(this.rules.other.listReplaceTask,""),z.tokens[0]?.type==="text"||z.tokens[0]?.type==="paragraph"){z.tokens[0].raw=z.tokens[0].raw.replace(this.rules.other.listReplaceTask,""),z.tokens[0].text=z.tokens[0].text.replace(this.rules.other.listReplaceTask,"");for(let H=this.lexer.inlineQueue.length-1;H>=0;H--)if(this.rules.other.listIsTask.test(this.lexer.inlineQueue[H].src)){this.lexer.inlineQueue[H].src=this.lexer.inlineQueue[H].src.replace(this.rules.other.listReplaceTask,"");break}}let _=this.rules.other.listTaskCheckbox.exec(z.raw);if(_){let H={type:"checkbox",raw:_[0]+" ",checked:_[0]!=="[ ]"};z.checked=H.checked,J.loose?z.tokens[0]&&["paragraph","text"].includes(z.tokens[0].type)&&"tokens"in z.tokens[0]&&z.tokens[0].tokens?(z.tokens[0].raw=H.raw+z.tokens[0].raw,z.tokens[0].text=H.raw+z.tokens[0].text,z.tokens[0].tokens.unshift(H)):z.tokens.unshift({type:"paragraph",raw:H.raw,text:H.raw,tokens:[H]}):z.tokens.unshift(H)}}if(!J.loose){let _=z.tokens.filter((U)=>U.type==="space"),H=_.length>0&&_.some((U)=>this.rules.other.anyLine.test(U.raw));J.loose=H}}if(J.loose)for(let z of J.items){z.loose=!0;for(let _ of z.tokens)_.type==="text"&&(_.type="paragraph")}return J}}html(Z){let $=this.rules.block.html.exec(Z);if($)return{type:"html",block:!0,raw:$[0],pre:$[1]==="pre"||$[1]==="script"||$[1]==="style",text:$[0]}}def(Z){let $=this.rules.block.def.exec(Z);if($){let q=$[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal," "),Q=$[2]?$[2].replace(this.rules.other.hrefBrackets,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",J=$[3]?$[3].substring(1,$[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):$[3];return{type:"def",tag:q,raw:$[0],href:Q,title:J}}}table(Z){let $=this.rules.block.table.exec(Z);if(!$||!this.rules.other.tableDelimiter.test($[2]))return;let q=Z3($[1]),Q=$[2].replace(this.rules.other.tableAlignChars,"").split("|"),J=$[3]?.trim()?$[3].replace(this.rules.other.tableRowBlankLine,"").split(`
25
- `):[],Y={type:"table",raw:$[0],header:[],align:[],rows:[]};if(q.length===Q.length){for(let X of Q)this.rules.other.tableAlignRight.test(X)?Y.align.push("right"):this.rules.other.tableAlignCenter.test(X)?Y.align.push("center"):this.rules.other.tableAlignLeft.test(X)?Y.align.push("left"):Y.align.push(null);for(let X=0;X<q.length;X++)Y.header.push({text:q[X],tokens:this.lexer.inline(q[X]),header:!0,align:Y.align[X]});for(let X of J)Y.rows.push(Z3(X,Y.header.length).map((G,z)=>({text:G,tokens:this.lexer.inline(G),header:!1,align:Y.align[z]})));return Y}}lheading(Z){let $=this.rules.block.lheading.exec(Z);if($){let q=$[1].trim();return{type:"heading",raw:$[0],depth:$[2].charAt(0)==="="?1:2,text:q,tokens:this.lexer.inline(q)}}}paragraph(Z){let $=this.rules.block.paragraph.exec(Z);if($){let q=$[1].charAt($[1].length-1)===`
26
- `?$[1].slice(0,-1):$[1];return{type:"paragraph",raw:$[0],text:q,tokens:this.lexer.inline(q)}}}text(Z){let $=this.rules.block.text.exec(Z);if($)return{type:"text",raw:$[0],text:$[0],tokens:this.lexer.inline($[0])}}escape(Z){let $=this.rules.inline.escape.exec(Z);if($)return{type:"escape",raw:$[0],text:$[1]}}tag(Z){let $=this.rules.inline.tag.exec(Z);if($)return!this.lexer.state.inLink&&this.rules.other.startATag.test($[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test($[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test($[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test($[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:$[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:$[0]}}link(Z){let $=this.rules.inline.link.exec(Z);if($){let q=$[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(q)){if(!this.rules.other.endAngleBracket.test(q))return;let Y=F0(q.slice(0,-1),"\\");if((q.length-Y.length)%2===0)return}else{let Y=P8($[2],"()");if(Y===-2)return;if(Y>-1){let X=($[0].indexOf("!")===0?5:4)+$[1].length+Y;$[2]=$[2].substring(0,Y),$[0]=$[0].substring(0,X).trim(),$[3]=""}}let Q=$[2],J="";if(this.options.pedantic){let Y=this.rules.other.pedanticHrefTitle.exec(Q);Y&&(Q=Y[1],J=Y[3])}else J=$[3]?$[3].slice(1,-1):"";return Q=Q.trim(),this.rules.other.startAngleBracket.test(Q)&&(this.options.pedantic&&!this.rules.other.endAngleBracket.test(q)?Q=Q.slice(1):Q=Q.slice(1,-1)),q3($,{href:Q&&Q.replace(this.rules.inline.anyPunctuation,"$1"),title:J&&J.replace(this.rules.inline.anyPunctuation,"$1")},$[0],this.lexer,this.rules)}}reflink(Z,$){let q;if((q=this.rules.inline.reflink.exec(Z))||(q=this.rules.inline.nolink.exec(Z))){let Q=(q[2]||q[1]).replace(this.rules.other.multipleSpaceGlobal," "),J=$[Q.toLowerCase()];if(!J){let Y=q[0].charAt(0);return{type:"text",raw:Y,text:Y}}return q3(q,J,q[0],this.lexer,this.rules)}}emStrong(Z,$,q=""){let Q=this.rules.inline.emStrongLDelim.exec(Z);if(!Q||!Q[1]&&!Q[2]&&!Q[3]&&!Q[4]||Q[4]&&q.match(this.rules.other.unicodeAlphaNumeric))return;if(!(Q[1]||Q[3])||!q||this.rules.inline.punctuation.exec(q)){let J=[...Q[0]].length-1,Y,X,G=J,z=0,_=Q[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(_.lastIndex=0,$=$.slice(-1*Z.length+J);(Q=_.exec($))!==null;){if(Y=Q[1]||Q[2]||Q[3]||Q[4]||Q[5]||Q[6],!Y)continue;if(X=[...Y].length,Q[3]||Q[4]){G+=X;continue}else if((Q[5]||Q[6])&&J%3&&!((J+X)%3)){z+=X;continue}if(G-=X,G>0)continue;X=Math.min(X,X+G+z);let H=[...Q[0]][0].length,U=Z.slice(0,J+Q.index+H+X);if(Math.min(J,X)%2){let T=U.slice(1,-1);return{type:"em",raw:U,text:T,tokens:this.lexer.inlineTokens(T)}}let W=U.slice(2,-2);return{type:"strong",raw:U,text:W,tokens:this.lexer.inlineTokens(W)}}}}codespan(Z){let $=this.rules.inline.code.exec(Z);if($){let q=$[2].replace(this.rules.other.newLineCharGlobal," "),Q=this.rules.other.nonSpaceChar.test(q),J=this.rules.other.startingSpaceChar.test(q)&&this.rules.other.endingSpaceChar.test(q);return Q&&J&&(q=q.substring(1,q.length-1)),{type:"codespan",raw:$[0],text:q}}}br(Z){let $=this.rules.inline.br.exec(Z);if($)return{type:"br",raw:$[0]}}del(Z,$,q=""){let Q=this.rules.inline.delLDelim.exec(Z);if(!Q)return;if(!Q[1]||!q||this.rules.inline.punctuation.exec(q)){let J=[...Q[0]].length-1,Y,X,G=J,z=this.rules.inline.delRDelim;for(z.lastIndex=0,$=$.slice(-1*Z.length+J);(Q=z.exec($))!==null;){if(Y=Q[1]||Q[2]||Q[3]||Q[4]||Q[5]||Q[6],!Y||(X=[...Y].length,X!==J))continue;if(Q[3]||Q[4]){G+=X;continue}if(G-=X,G>0)continue;X=Math.min(X,X+G);let _=[...Q[0]][0].length,H=Z.slice(0,J+Q.index+_+X),U=H.slice(J,-J);return{type:"del",raw:H,text:U,tokens:this.lexer.inlineTokens(U)}}}}autolink(Z){let $=this.rules.inline.autolink.exec(Z);if($){let q,Q;return $[2]==="@"?(q=$[1],Q="mailto:"+q):(q=$[1],Q=q),{type:"link",raw:$[0],text:q,href:Q,tokens:[{type:"text",raw:q,text:q}]}}}url(Z){let $;if($=this.rules.inline.url.exec(Z)){let q,Q;if($[2]==="@")q=$[0],Q="mailto:"+q;else{let J;do J=$[0],$[0]=this.rules.inline._backpedal.exec($[0])?.[0]??"";while(J!==$[0]);q=$[0],$[1]==="www."?Q="http://"+$[0]:Q=$[0]}return{type:"link",raw:$[0],text:q,href:Q,tokens:[{type:"text",raw:q,text:q}]}}}inlineText(Z){let $=this.rules.inline.text.exec(Z);if($){let q=this.lexer.state.inRawBlock;return{type:"text",raw:$[0],text:$[0],escaped:q}}}},F1=class Z{tokens;options;state;inlineQueue;tokenizer;constructor($){this.tokens=[],this.tokens.links=Object.create(null),this.options=$||r1,this.options.tokenizer=this.options.tokenizer||new u0,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};let q={other:K1,block:x0.normal,inline:O0.normal};this.options.pedantic?(q.block=x0.pedantic,q.inline=O0.pedantic):this.options.gfm&&(q.block=x0.gfm,this.options.breaks?q.inline=O0.breaks:q.inline=O0.gfm),this.tokenizer.rules=q}static get rules(){return{block:x0,inline:O0}}static lex($,q){return new Z(q).lex($)}static lexInline($,q){return new Z(q).inlineTokens($)}lex($){$=$.replace(K1.carriageReturn,`
27
- `),this.blockTokens($,this.tokens);for(let q=0;q<this.inlineQueue.length;q++){let Q=this.inlineQueue[q];this.inlineTokens(Q.src,Q.tokens)}return this.inlineQueue=[],this.tokens}blockTokens($,q=[],Q=!1){for(this.tokenizer.lexer=this,this.options.pedantic&&($=$.replace(K1.tabCharGlobal," ").replace(K1.spaceLine,""));$;){let J;if(this.options.extensions?.block?.some((X)=>(J=X.call({lexer:this},$,q))?($=$.substring(J.raw.length),q.push(J),!0):!1))continue;if(J=this.tokenizer.space($)){$=$.substring(J.raw.length);let X=q.at(-1);J.raw.length===1&&X!==void 0?X.raw+=`
28
- `:q.push(J);continue}if(J=this.tokenizer.code($)){$=$.substring(J.raw.length);let X=q.at(-1);X?.type==="paragraph"||X?.type==="text"?(X.raw+=(X.raw.endsWith(`
8
+ `),X="",Y="",Z=[];for(;J.length>0;){let q=!1,U=[],G;for(G=0;G<J.length;G++)if(this.rules.other.blockquoteStart.test(J[G]))U.push(J[G]),q=!0;else if(!q)U.push(J[G]);else break;J=J.slice(G);let K=U.join(`
9
+ `),_=K.replace(this.rules.other.blockquoteSetextReplace,`
10
+ $1`).replace(this.rules.other.blockquoteSetextReplace2,"");X=X?`${X}
11
+ ${K}`:K,Y=Y?`${Y}
12
+ ${_}`:_;let z=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(_,Z,!0),this.lexer.state.top=z,J.length===0)break;let W=Z.at(-1);if(W?.type==="code")break;if(W?.type==="blockquote"){let H=W,N=H.raw+`
13
+ `+J.join(`
14
+ `),O=this.blockquote(N);Z[Z.length-1]=O,X=X.substring(0,X.length-H.raw.length)+O.raw,Y=Y.substring(0,Y.length-H.text.length)+O.text;break}else if(W?.type==="list"){let H=W,N=H.raw+`
15
+ `+J.join(`
16
+ `),O=this.list(N);Z[Z.length-1]=O,X=X.substring(0,X.length-W.raw.length)+O.raw,Y=Y.substring(0,Y.length-H.raw.length)+O.raw,J=N.substring(Z.at(-1).raw.length).split(`
17
+ `);continue}}return{type:"blockquote",raw:X,tokens:Z,text:Y}}}list($){let Q=this.rules.block.list.exec($);if(Q){let J=Q[1].trim(),X=J.length>1,Y={type:"list",raw:"",ordered:X,start:X?+J.slice(0,-1):"",loose:!1,items:[]};J=X?`\\d{1,9}\\${J.slice(-1)}`:`\\${J}`,this.options.pedantic&&(J=X?J:"[*+-]");let Z=this.rules.other.listItemRegex(J),q=!1;for(;$;){let G=!1,K="",_="";if(!(Q=Z.exec($))||this.rules.block.hr.test($))break;K=Q[0],$=$.substring(K.length);let z=M6(Q[2].split(`
18
+ `,1)[0],Q[1].length),W=$.split(`
19
+ `,1)[0],H=!z.trim(),N=0;if(this.options.pedantic?(N=2,_=z.trimStart()):H?N=Q[1].length+1:(N=z.search(this.rules.other.nonSpaceChar),N=N>4?1:N,_=z.slice(N),N+=Q[1].length),H&&this.rules.other.blankLine.test(W)&&(K+=W+`
20
+ `,$=$.substring(W.length+1),G=!0),!G){let O=this.rules.other.nextBulletRegex(N),B=this.rules.other.hrRegex(N),A=this.rules.other.fencesBeginRegex(N),T=this.rules.other.headingBeginRegex(N),M=this.rules.other.htmlBeginRegex(N),y=this.rules.other.blockquoteBeginRegex(N);for(;$;){let L=$.split(`
21
+ `,1)[0],w;if(W=L,this.options.pedantic?(W=W.replace(this.rules.other.listReplaceNesting," "),w=W):w=W.replace(this.rules.other.tabCharGlobal," "),A.test(W)||T.test(W)||M.test(W)||y.test(W)||O.test(W)||B.test(W))break;if(w.search(this.rules.other.nonSpaceChar)>=N||!W.trim())_+=`
22
+ `+w.slice(N);else{if(H||z.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||A.test(z)||T.test(z)||B.test(z))break;_+=`
23
+ `+W}H=!W.trim(),K+=L+`
24
+ `,$=$.substring(L.length+1),z=w.slice(N)}}Y.loose||(q?Y.loose=!0:this.rules.other.doubleBlankLine.test(K)&&(q=!0)),Y.items.push({type:"list_item",raw:K,task:!!this.options.gfm&&this.rules.other.listIsTask.test(_),loose:!1,text:_,tokens:[]}),Y.raw+=K}let U=Y.items.at(-1);if(U)U.raw=U.raw.trimEnd(),U.text=U.text.trimEnd();else return;Y.raw=Y.raw.trimEnd();for(let G of Y.items){if(this.lexer.state.top=!1,G.tokens=this.lexer.blockTokens(G.text,[]),G.task){if(G.text=G.text.replace(this.rules.other.listReplaceTask,""),G.tokens[0]?.type==="text"||G.tokens[0]?.type==="paragraph"){G.tokens[0].raw=G.tokens[0].raw.replace(this.rules.other.listReplaceTask,""),G.tokens[0].text=G.tokens[0].text.replace(this.rules.other.listReplaceTask,"");for(let _=this.lexer.inlineQueue.length-1;_>=0;_--)if(this.rules.other.listIsTask.test(this.lexer.inlineQueue[_].src)){this.lexer.inlineQueue[_].src=this.lexer.inlineQueue[_].src.replace(this.rules.other.listReplaceTask,"");break}}let K=this.rules.other.listTaskCheckbox.exec(G.raw);if(K){let _={type:"checkbox",raw:K[0]+" ",checked:K[0]!=="[ ]"};G.checked=_.checked,Y.loose?G.tokens[0]&&["paragraph","text"].includes(G.tokens[0].type)&&"tokens"in G.tokens[0]&&G.tokens[0].tokens?(G.tokens[0].raw=_.raw+G.tokens[0].raw,G.tokens[0].text=_.raw+G.tokens[0].text,G.tokens[0].tokens.unshift(_)):G.tokens.unshift({type:"paragraph",raw:_.raw,text:_.raw,tokens:[_]}):G.tokens.unshift(_)}}if(!Y.loose){let K=G.tokens.filter((z)=>z.type==="space"),_=K.length>0&&K.some((z)=>this.rules.other.anyLine.test(z.raw));Y.loose=_}}if(Y.loose)for(let G of Y.items){G.loose=!0;for(let K of G.tokens)K.type==="text"&&(K.type="paragraph")}return Y}}html($){let Q=this.rules.block.html.exec($);if(Q)return{type:"html",block:!0,raw:Q[0],pre:Q[1]==="pre"||Q[1]==="script"||Q[1]==="style",text:Q[0]}}def($){let Q=this.rules.block.def.exec($);if(Q){let J=Q[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal," "),X=Q[2]?Q[2].replace(this.rules.other.hrefBrackets,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",Y=Q[3]?Q[3].substring(1,Q[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):Q[3];return{type:"def",tag:J,raw:Q[0],href:X,title:Y}}}table($){let Q=this.rules.block.table.exec($);if(!Q||!this.rules.other.tableDelimiter.test(Q[2]))return;let J=h5(Q[1]),X=Q[2].replace(this.rules.other.tableAlignChars,"").split("|"),Y=Q[3]?.trim()?Q[3].replace(this.rules.other.tableRowBlankLine,"").split(`
25
+ `):[],Z={type:"table",raw:Q[0],header:[],align:[],rows:[]};if(J.length===X.length){for(let q of X)this.rules.other.tableAlignRight.test(q)?Z.align.push("right"):this.rules.other.tableAlignCenter.test(q)?Z.align.push("center"):this.rules.other.tableAlignLeft.test(q)?Z.align.push("left"):Z.align.push(null);for(let q=0;q<J.length;q++)Z.header.push({text:J[q],tokens:this.lexer.inline(J[q]),header:!0,align:Z.align[q]});for(let q of Y)Z.rows.push(h5(q,Z.header.length).map((U,G)=>({text:U,tokens:this.lexer.inline(U),header:!1,align:Z.align[G]})));return Z}}lheading($){let Q=this.rules.block.lheading.exec($);if(Q){let J=Q[1].trim();return{type:"heading",raw:Q[0],depth:Q[2].charAt(0)==="="?1:2,text:J,tokens:this.lexer.inline(J)}}}paragraph($){let Q=this.rules.block.paragraph.exec($);if(Q){let J=Q[1].charAt(Q[1].length-1)===`
26
+ `?Q[1].slice(0,-1):Q[1];return{type:"paragraph",raw:Q[0],text:J,tokens:this.lexer.inline(J)}}}text($){let Q=this.rules.block.text.exec($);if(Q)return{type:"text",raw:Q[0],text:Q[0],tokens:this.lexer.inline(Q[0])}}escape($){let Q=this.rules.inline.escape.exec($);if(Q)return{type:"escape",raw:Q[0],text:Q[1]}}tag($){let Q=this.rules.inline.tag.exec($);if(Q)return!this.lexer.state.inLink&&this.rules.other.startATag.test(Q[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test(Q[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test(Q[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test(Q[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:Q[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:Q[0]}}link($){let Q=this.rules.inline.link.exec($);if(Q){let J=Q[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(J)){if(!this.rules.other.endAngleBracket.test(J))return;let Z=k0(J.slice(0,-1),"\\");if((J.length-Z.length)%2===0)return}else{let Z=L6(Q[2],"()");if(Z===-2)return;if(Z>-1){let q=(Q[0].indexOf("!")===0?5:4)+Q[1].length+Z;Q[2]=Q[2].substring(0,Z),Q[0]=Q[0].substring(0,q).trim(),Q[3]=""}}let X=Q[2],Y="";if(this.options.pedantic){let Z=this.rules.other.pedanticHrefTitle.exec(X);Z&&(X=Z[1],Y=Z[3])}else Y=Q[3]?Q[3].slice(1,-1):"";return X=X.trim(),this.rules.other.startAngleBracket.test(X)&&(this.options.pedantic&&!this.rules.other.endAngleBracket.test(J)?X=X.slice(1):X=X.slice(1,-1)),p5(Q,{href:X&&X.replace(this.rules.inline.anyPunctuation,"$1"),title:Y&&Y.replace(this.rules.inline.anyPunctuation,"$1")},Q[0],this.lexer,this.rules)}}reflink($,Q){let J;if((J=this.rules.inline.reflink.exec($))||(J=this.rules.inline.nolink.exec($))){let X=(J[2]||J[1]).replace(this.rules.other.multipleSpaceGlobal," "),Y=Q[X.toLowerCase()];if(!Y){let Z=J[0].charAt(0);return{type:"text",raw:Z,text:Z}}return p5(J,Y,J[0],this.lexer,this.rules)}}emStrong($,Q,J=""){let X=this.rules.inline.emStrongLDelim.exec($);if(!X||!X[1]&&!X[2]&&!X[3]&&!X[4]||X[4]&&J.match(this.rules.other.unicodeAlphaNumeric))return;if(!(X[1]||X[3])||!J||this.rules.inline.punctuation.exec(J)){let Y=[...X[0]].length-1,Z,q,U=Y,G=0,K=X[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(K.lastIndex=0,Q=Q.slice(-1*$.length+Y);(X=K.exec(Q))!==null;){if(Z=X[1]||X[2]||X[3]||X[4]||X[5]||X[6],!Z)continue;if(q=[...Z].length,X[3]||X[4]){U+=q;continue}else if((X[5]||X[6])&&Y%3&&!((Y+q)%3)){G+=q;continue}if(U-=q,U>0)continue;q=Math.min(q,q+U+G);let _=[...X[0]][0].length,z=$.slice(0,Y+X.index+_+q);if(Math.min(Y,q)%2){let H=z.slice(1,-1);return{type:"em",raw:z,text:H,tokens:this.lexer.inlineTokens(H)}}let W=z.slice(2,-2);return{type:"strong",raw:z,text:W,tokens:this.lexer.inlineTokens(W)}}}}codespan($){let Q=this.rules.inline.code.exec($);if(Q){let J=Q[2].replace(this.rules.other.newLineCharGlobal," "),X=this.rules.other.nonSpaceChar.test(J),Y=this.rules.other.startingSpaceChar.test(J)&&this.rules.other.endingSpaceChar.test(J);return X&&Y&&(J=J.substring(1,J.length-1)),{type:"codespan",raw:Q[0],text:J}}}br($){let Q=this.rules.inline.br.exec($);if(Q)return{type:"br",raw:Q[0]}}del($,Q,J=""){let X=this.rules.inline.delLDelim.exec($);if(!X)return;if(!X[1]||!J||this.rules.inline.punctuation.exec(J)){let Y=[...X[0]].length-1,Z,q,U=Y,G=this.rules.inline.delRDelim;for(G.lastIndex=0,Q=Q.slice(-1*$.length+Y);(X=G.exec(Q))!==null;){if(Z=X[1]||X[2]||X[3]||X[4]||X[5]||X[6],!Z||(q=[...Z].length,q!==Y))continue;if(X[3]||X[4]){U+=q;continue}if(U-=q,U>0)continue;q=Math.min(q,q+U);let K=[...X[0]][0].length,_=$.slice(0,Y+X.index+K+q),z=_.slice(Y,-Y);return{type:"del",raw:_,text:z,tokens:this.lexer.inlineTokens(z)}}}}autolink($){let Q=this.rules.inline.autolink.exec($);if(Q){let J,X;return Q[2]==="@"?(J=Q[1],X="mailto:"+J):(J=Q[1],X=J),{type:"link",raw:Q[0],text:J,href:X,tokens:[{type:"text",raw:J,text:J}]}}}url($){let Q;if(Q=this.rules.inline.url.exec($)){let J,X;if(Q[2]==="@")J=Q[0],X="mailto:"+J;else{let Y;do Y=Q[0],Q[0]=this.rules.inline._backpedal.exec(Q[0])?.[0]??"";while(Y!==Q[0]);J=Q[0],Q[1]==="www."?X="http://"+Q[0]:X=Q[0]}return{type:"link",raw:Q[0],text:J,href:X,tokens:[{type:"text",raw:J,text:J}]}}}inlineText($){let Q=this.rules.inline.text.exec($);if(Q){let J=this.lexer.state.inRawBlock;return{type:"text",raw:Q[0],text:Q[0],escaped:J}}}},C1=class ${tokens;options;state;inlineQueue;tokenizer;constructor(Q){this.tokens=[],this.tokens.links=Object.create(null),this.options=Q||G0,this.options.tokenizer=this.options.tokenizer||new G2,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};let J={other:B1,block:q2.normal,inline:V0.normal};this.options.pedantic?(J.block=q2.pedantic,J.inline=V0.pedantic):this.options.gfm&&(J.block=q2.gfm,this.options.breaks?J.inline=V0.breaks:J.inline=V0.gfm),this.tokenizer.rules=J}static get rules(){return{block:q2,inline:V0}}static lex(Q,J){return new $(J).lex(Q)}static lexInline(Q,J){return new $(J).inlineTokens(Q)}lex(Q){Q=Q.replace(B1.carriageReturn,`
27
+ `),this.blockTokens(Q,this.tokens);for(let J=0;J<this.inlineQueue.length;J++){let X=this.inlineQueue[J];this.inlineTokens(X.src,X.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(Q,J=[],X=!1){for(this.tokenizer.lexer=this,this.options.pedantic&&(Q=Q.replace(B1.tabCharGlobal," ").replace(B1.spaceLine,""));Q;){let Y;if(this.options.extensions?.block?.some((q)=>(Y=q.call({lexer:this},Q,J))?(Q=Q.substring(Y.raw.length),J.push(Y),!0):!1))continue;if(Y=this.tokenizer.space(Q)){Q=Q.substring(Y.raw.length);let q=J.at(-1);Y.raw.length===1&&q!==void 0?q.raw+=`
28
+ `:J.push(Y);continue}if(Y=this.tokenizer.code(Q)){Q=Q.substring(Y.raw.length);let q=J.at(-1);q?.type==="paragraph"||q?.type==="text"?(q.raw+=(q.raw.endsWith(`
29
29
  `)?"":`
30
- `)+J.raw,X.text+=`
31
- `+J.text,this.inlineQueue.at(-1).src=X.text):q.push(J);continue}if(J=this.tokenizer.fences($)){$=$.substring(J.raw.length),q.push(J);continue}if(J=this.tokenizer.heading($)){$=$.substring(J.raw.length),q.push(J);continue}if(J=this.tokenizer.hr($)){$=$.substring(J.raw.length),q.push(J);continue}if(J=this.tokenizer.blockquote($)){$=$.substring(J.raw.length),q.push(J);continue}if(J=this.tokenizer.list($)){$=$.substring(J.raw.length),q.push(J);continue}if(J=this.tokenizer.html($)){$=$.substring(J.raw.length),q.push(J);continue}if(J=this.tokenizer.def($)){$=$.substring(J.raw.length);let X=q.at(-1);X?.type==="paragraph"||X?.type==="text"?(X.raw+=(X.raw.endsWith(`
30
+ `)+Y.raw,q.text+=`
31
+ `+Y.text,this.inlineQueue.at(-1).src=q.text):J.push(Y);continue}if(Y=this.tokenizer.fences(Q)){Q=Q.substring(Y.raw.length),J.push(Y);continue}if(Y=this.tokenizer.heading(Q)){Q=Q.substring(Y.raw.length),J.push(Y);continue}if(Y=this.tokenizer.hr(Q)){Q=Q.substring(Y.raw.length),J.push(Y);continue}if(Y=this.tokenizer.blockquote(Q)){Q=Q.substring(Y.raw.length),J.push(Y);continue}if(Y=this.tokenizer.list(Q)){Q=Q.substring(Y.raw.length),J.push(Y);continue}if(Y=this.tokenizer.html(Q)){Q=Q.substring(Y.raw.length),J.push(Y);continue}if(Y=this.tokenizer.def(Q)){Q=Q.substring(Y.raw.length);let q=J.at(-1);q?.type==="paragraph"||q?.type==="text"?(q.raw+=(q.raw.endsWith(`
32
32
  `)?"":`
33
- `)+J.raw,X.text+=`
34
- `+J.raw,this.inlineQueue.at(-1).src=X.text):this.tokens.links[J.tag]||(this.tokens.links[J.tag]={href:J.href,title:J.title},q.push(J));continue}if(J=this.tokenizer.table($)){$=$.substring(J.raw.length),q.push(J);continue}if(J=this.tokenizer.lheading($)){$=$.substring(J.raw.length),q.push(J);continue}let Y=$;if(this.options.extensions?.startBlock){let X=1/0,G=$.slice(1),z;this.options.extensions.startBlock.forEach((_)=>{z=_.call({lexer:this},G),typeof z=="number"&&z>=0&&(X=Math.min(X,z))}),X<1/0&&X>=0&&(Y=$.substring(0,X+1))}if(this.state.top&&(J=this.tokenizer.paragraph(Y))){let X=q.at(-1);Q&&X?.type==="paragraph"?(X.raw+=(X.raw.endsWith(`
33
+ `)+Y.raw,q.text+=`
34
+ `+Y.raw,this.inlineQueue.at(-1).src=q.text):this.tokens.links[Y.tag]||(this.tokens.links[Y.tag]={href:Y.href,title:Y.title},J.push(Y));continue}if(Y=this.tokenizer.table(Q)){Q=Q.substring(Y.raw.length),J.push(Y);continue}if(Y=this.tokenizer.lheading(Q)){Q=Q.substring(Y.raw.length),J.push(Y);continue}let Z=Q;if(this.options.extensions?.startBlock){let q=1/0,U=Q.slice(1),G;this.options.extensions.startBlock.forEach((K)=>{G=K.call({lexer:this},U),typeof G=="number"&&G>=0&&(q=Math.min(q,G))}),q<1/0&&q>=0&&(Z=Q.substring(0,q+1))}if(this.state.top&&(Y=this.tokenizer.paragraph(Z))){let q=J.at(-1);X&&q?.type==="paragraph"?(q.raw+=(q.raw.endsWith(`
35
35
  `)?"":`
36
- `)+J.raw,X.text+=`
37
- `+J.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=X.text):q.push(J),Q=Y.length!==$.length,$=$.substring(J.raw.length);continue}if(J=this.tokenizer.text($)){$=$.substring(J.raw.length);let X=q.at(-1);X?.type==="text"?(X.raw+=(X.raw.endsWith(`
36
+ `)+Y.raw,q.text+=`
37
+ `+Y.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=q.text):J.push(Y),X=Z.length!==Q.length,Q=Q.substring(Y.raw.length);continue}if(Y=this.tokenizer.text(Q)){Q=Q.substring(Y.raw.length);let q=J.at(-1);q?.type==="text"?(q.raw+=(q.raw.endsWith(`
38
38
  `)?"":`
39
- `)+J.raw,X.text+=`
40
- `+J.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=X.text):q.push(J);continue}if($){let X="Infinite loop on byte: "+$.charCodeAt(0);if(this.options.silent){console.error(X);break}else throw Error(X)}}return this.state.top=!0,q}inline($,q=[]){return this.inlineQueue.push({src:$,tokens:q}),q}inlineTokens($,q=[]){this.tokenizer.lexer=this;let Q=$,J=null;if(this.tokens.links){let z=Object.keys(this.tokens.links);if(z.length>0)for(;(J=this.tokenizer.rules.inline.reflinkSearch.exec(Q))!==null;)z.includes(J[0].slice(J[0].lastIndexOf("[")+1,-1))&&(Q=Q.slice(0,J.index)+"["+"a".repeat(J[0].length-2)+"]"+Q.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(J=this.tokenizer.rules.inline.anyPunctuation.exec(Q))!==null;)Q=Q.slice(0,J.index)+"++"+Q.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);let Y;for(;(J=this.tokenizer.rules.inline.blockSkip.exec(Q))!==null;)Y=J[2]?J[2].length:0,Q=Q.slice(0,J.index+Y)+"["+"a".repeat(J[0].length-Y-2)+"]"+Q.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);Q=this.options.hooks?.emStrongMask?.call({lexer:this},Q)??Q;let X=!1,G="";for(;$;){X||(G=""),X=!1;let z;if(this.options.extensions?.inline?.some((H)=>(z=H.call({lexer:this},$,q))?($=$.substring(z.raw.length),q.push(z),!0):!1))continue;if(z=this.tokenizer.escape($)){$=$.substring(z.raw.length),q.push(z);continue}if(z=this.tokenizer.tag($)){$=$.substring(z.raw.length),q.push(z);continue}if(z=this.tokenizer.link($)){$=$.substring(z.raw.length),q.push(z);continue}if(z=this.tokenizer.reflink($,this.tokens.links)){$=$.substring(z.raw.length);let H=q.at(-1);z.type==="text"&&H?.type==="text"?(H.raw+=z.raw,H.text+=z.text):q.push(z);continue}if(z=this.tokenizer.emStrong($,Q,G)){$=$.substring(z.raw.length),q.push(z);continue}if(z=this.tokenizer.codespan($)){$=$.substring(z.raw.length),q.push(z);continue}if(z=this.tokenizer.br($)){$=$.substring(z.raw.length),q.push(z);continue}if(z=this.tokenizer.del($,Q,G)){$=$.substring(z.raw.length),q.push(z);continue}if(z=this.tokenizer.autolink($)){$=$.substring(z.raw.length),q.push(z);continue}if(!this.state.inLink&&(z=this.tokenizer.url($))){$=$.substring(z.raw.length),q.push(z);continue}let _=$;if(this.options.extensions?.startInline){let H=1/0,U=$.slice(1),W;this.options.extensions.startInline.forEach((T)=>{W=T.call({lexer:this},U),typeof W=="number"&&W>=0&&(H=Math.min(H,W))}),H<1/0&&H>=0&&(_=$.substring(0,H+1))}if(z=this.tokenizer.inlineText(_)){$=$.substring(z.raw.length),z.raw.slice(-1)!=="_"&&(G=z.raw.slice(-1)),X=!0;let H=q.at(-1);H?.type==="text"?(H.raw+=z.raw,H.text+=z.text):q.push(z);continue}if($){let H="Infinite loop on byte: "+$.charCodeAt(0);if(this.options.silent){console.error(H);break}else throw Error(H)}}return q}},g0=class{options;parser;constructor(Z){this.options=Z||r1}space(Z){return""}code({text:Z,lang:$,escaped:q}){let Q=($||"").match(K1.notSpaceStart)?.[0],J=Z.replace(K1.endingNewline,"")+`
41
- `;return Q?'<pre><code class="language-'+b1(Q)+'">'+(q?J:b1(J,!0))+`</code></pre>
42
- `:"<pre><code>"+(q?J:b1(J,!0))+`</code></pre>
43
- `}blockquote({tokens:Z}){return`<blockquote>
44
- ${this.parser.parse(Z)}</blockquote>
45
- `}html({text:Z}){return Z}def(Z){return""}heading({tokens:Z,depth:$}){return`<h${$}>${this.parser.parseInline(Z)}</h${$}>
46
- `}hr(Z){return`<hr>
47
- `}list(Z){let{ordered:$,start:q}=Z,Q="";for(let X=0;X<Z.items.length;X++){let G=Z.items[X];Q+=this.listitem(G)}let J=$?"ol":"ul",Y=$&&q!==1?' start="'+q+'"':"";return"<"+J+Y+`>
48
- `+Q+"</"+J+`>
49
- `}listitem(Z){return`<li>${this.parser.parse(Z.tokens)}</li>
50
- `}checkbox({checked:Z}){return"<input "+(Z?'checked="" ':"")+'disabled="" type="checkbox"> '}paragraph({tokens:Z}){return`<p>${this.parser.parseInline(Z)}</p>
51
- `}table(Z){let $="",q="";for(let J=0;J<Z.header.length;J++)q+=this.tablecell(Z.header[J]);$+=this.tablerow({text:q});let Q="";for(let J=0;J<Z.rows.length;J++){let Y=Z.rows[J];q="";for(let X=0;X<Y.length;X++)q+=this.tablecell(Y[X]);Q+=this.tablerow({text:q})}return Q&&(Q=`<tbody>${Q}</tbody>`),`<table>
39
+ `)+Y.raw,q.text+=`
40
+ `+Y.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=q.text):J.push(Y);continue}if(Q){let q="Infinite loop on byte: "+Q.charCodeAt(0);if(this.options.silent){console.error(q);break}else throw Error(q)}}return this.state.top=!0,J}inline(Q,J=[]){return this.inlineQueue.push({src:Q,tokens:J}),J}inlineTokens(Q,J=[]){this.tokenizer.lexer=this;let X=Q,Y=null;if(this.tokens.links){let G=Object.keys(this.tokens.links);if(G.length>0)for(;(Y=this.tokenizer.rules.inline.reflinkSearch.exec(X))!==null;)G.includes(Y[0].slice(Y[0].lastIndexOf("[")+1,-1))&&(X=X.slice(0,Y.index)+"["+"a".repeat(Y[0].length-2)+"]"+X.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(Y=this.tokenizer.rules.inline.anyPunctuation.exec(X))!==null;)X=X.slice(0,Y.index)+"++"+X.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);let Z;for(;(Y=this.tokenizer.rules.inline.blockSkip.exec(X))!==null;)Z=Y[2]?Y[2].length:0,X=X.slice(0,Y.index+Z)+"["+"a".repeat(Y[0].length-Z-2)+"]"+X.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);X=this.options.hooks?.emStrongMask?.call({lexer:this},X)??X;let q=!1,U="";for(;Q;){q||(U=""),q=!1;let G;if(this.options.extensions?.inline?.some((_)=>(G=_.call({lexer:this},Q,J))?(Q=Q.substring(G.raw.length),J.push(G),!0):!1))continue;if(G=this.tokenizer.escape(Q)){Q=Q.substring(G.raw.length),J.push(G);continue}if(G=this.tokenizer.tag(Q)){Q=Q.substring(G.raw.length),J.push(G);continue}if(G=this.tokenizer.link(Q)){Q=Q.substring(G.raw.length),J.push(G);continue}if(G=this.tokenizer.reflink(Q,this.tokens.links)){Q=Q.substring(G.raw.length);let _=J.at(-1);G.type==="text"&&_?.type==="text"?(_.raw+=G.raw,_.text+=G.text):J.push(G);continue}if(G=this.tokenizer.emStrong(Q,X,U)){Q=Q.substring(G.raw.length),J.push(G);continue}if(G=this.tokenizer.codespan(Q)){Q=Q.substring(G.raw.length),J.push(G);continue}if(G=this.tokenizer.br(Q)){Q=Q.substring(G.raw.length),J.push(G);continue}if(G=this.tokenizer.del(Q,X,U)){Q=Q.substring(G.raw.length),J.push(G);continue}if(G=this.tokenizer.autolink(Q)){Q=Q.substring(G.raw.length),J.push(G);continue}if(!this.state.inLink&&(G=this.tokenizer.url(Q))){Q=Q.substring(G.raw.length),J.push(G);continue}let K=Q;if(this.options.extensions?.startInline){let _=1/0,z=Q.slice(1),W;this.options.extensions.startInline.forEach((H)=>{W=H.call({lexer:this},z),typeof W=="number"&&W>=0&&(_=Math.min(_,W))}),_<1/0&&_>=0&&(K=Q.substring(0,_+1))}if(G=this.tokenizer.inlineText(K)){Q=Q.substring(G.raw.length),G.raw.slice(-1)!=="_"&&(U=G.raw.slice(-1)),q=!0;let _=J.at(-1);_?.type==="text"?(_.raw+=G.raw,_.text+=G.text):J.push(G);continue}if(Q){let _="Infinite loop on byte: "+Q.charCodeAt(0);if(this.options.silent){console.error(_);break}else throw Error(_)}}return J}},U2=class{options;parser;constructor($){this.options=$||G0}space($){return""}code({text:$,lang:Q,escaped:J}){let X=(Q||"").match(B1.notSpaceStart)?.[0],Y=$.replace(B1.endingNewline,"")+`
41
+ `;return X?'<pre><code class="language-'+R1(X)+'">'+(J?Y:R1(Y,!0))+`</code></pre>
42
+ `:"<pre><code>"+(J?Y:R1(Y,!0))+`</code></pre>
43
+ `}blockquote({tokens:$}){return`<blockquote>
44
+ ${this.parser.parse($)}</blockquote>
45
+ `}html({text:$}){return $}def($){return""}heading({tokens:$,depth:Q}){return`<h${Q}>${this.parser.parseInline($)}</h${Q}>
46
+ `}hr($){return`<hr>
47
+ `}list($){let{ordered:Q,start:J}=$,X="";for(let q=0;q<$.items.length;q++){let U=$.items[q];X+=this.listitem(U)}let Y=Q?"ol":"ul",Z=Q&&J!==1?' start="'+J+'"':"";return"<"+Y+Z+`>
48
+ `+X+"</"+Y+`>
49
+ `}listitem($){return`<li>${this.parser.parse($.tokens)}</li>
50
+ `}checkbox({checked:$}){return"<input "+($?'checked="" ':"")+'disabled="" type="checkbox"> '}paragraph({tokens:$}){return`<p>${this.parser.parseInline($)}</p>
51
+ `}table($){let Q="",J="";for(let Y=0;Y<$.header.length;Y++)J+=this.tablecell($.header[Y]);Q+=this.tablerow({text:J});let X="";for(let Y=0;Y<$.rows.length;Y++){let Z=$.rows[Y];J="";for(let q=0;q<Z.length;q++)J+=this.tablecell(Z[q]);X+=this.tablerow({text:J})}return X&&(X=`<tbody>${X}</tbody>`),`<table>
52
52
  <thead>
53
- `+$+`</thead>
54
- `+Q+`</table>
55
- `}tablerow({text:Z}){return`<tr>
56
- ${Z}</tr>
57
- `}tablecell(Z){let $=this.parser.parseInline(Z.tokens),q=Z.header?"th":"td";return(Z.align?`<${q} align="${Z.align}">`:`<${q}>`)+$+`</${q}>
58
- `}strong({tokens:Z}){return`<strong>${this.parser.parseInline(Z)}</strong>`}em({tokens:Z}){return`<em>${this.parser.parseInline(Z)}</em>`}codespan({text:Z}){return`<code>${b1(Z,!0)}</code>`}br(Z){return"<br>"}del({tokens:Z}){return`<del>${this.parser.parseInline(Z)}</del>`}link({href:Z,title:$,tokens:q}){let Q=this.parser.parseInline(q),J=$3(Z);if(J===null)return Q;Z=J;let Y='<a href="'+Z+'"';return $&&(Y+=' title="'+b1($)+'"'),Y+=">"+Q+"</a>",Y}image({href:Z,title:$,text:q,tokens:Q}){Q&&(q=this.parser.parseInline(Q,this.parser.textRenderer));let J=$3(Z);if(J===null)return b1(q);Z=J;let Y=`<img src="${Z}" alt="${b1(q)}"`;return $&&(Y+=` title="${b1($)}"`),Y+=">",Y}text(Z){return"tokens"in Z&&Z.tokens?this.parser.parseInline(Z.tokens):("escaped"in Z)&&Z.escaped?Z.text:b1(Z.text)}},j2=class{strong({text:Z}){return Z}em({text:Z}){return Z}codespan({text:Z}){return Z}del({text:Z}){return Z}html({text:Z}){return Z}text({text:Z}){return Z}link({text:Z}){return""+Z}image({text:Z}){return""+Z}br(){return""}checkbox({raw:Z}){return Z}},B1=class Z{options;renderer;textRenderer;constructor($){this.options=$||r1,this.options.renderer=this.options.renderer||new g0,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new j2}static parse($,q){return new Z(q).parse($)}static parseInline($,q){return new Z(q).parseInline($)}parse($){this.renderer.parser=this;let q="";for(let Q=0;Q<$.length;Q++){let J=$[Q];if(this.options.extensions?.renderers?.[J.type]){let X=J,G=this.options.extensions.renderers[X.type].call({parser:this},X);if(G!==!1||!["space","hr","heading","code","table","blockquote","list","html","def","paragraph","text"].includes(X.type)){q+=G||"";continue}}let Y=J;switch(Y.type){case"space":{q+=this.renderer.space(Y);break}case"hr":{q+=this.renderer.hr(Y);break}case"heading":{q+=this.renderer.heading(Y);break}case"code":{q+=this.renderer.code(Y);break}case"table":{q+=this.renderer.table(Y);break}case"blockquote":{q+=this.renderer.blockquote(Y);break}case"list":{q+=this.renderer.list(Y);break}case"checkbox":{q+=this.renderer.checkbox(Y);break}case"html":{q+=this.renderer.html(Y);break}case"def":{q+=this.renderer.def(Y);break}case"paragraph":{q+=this.renderer.paragraph(Y);break}case"text":{q+=this.renderer.text(Y);break}default:{let X='Token with "'+Y.type+'" type was not found.';if(this.options.silent)return console.error(X),"";throw Error(X)}}}return q}parseInline($,q=this.renderer){this.renderer.parser=this;let Q="";for(let J=0;J<$.length;J++){let Y=$[J];if(this.options.extensions?.renderers?.[Y.type]){let G=this.options.extensions.renderers[Y.type].call({parser:this},Y);if(G!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(Y.type)){Q+=G||"";continue}}let X=Y;switch(X.type){case"escape":{Q+=q.text(X);break}case"html":{Q+=q.html(X);break}case"link":{Q+=q.link(X);break}case"image":{Q+=q.image(X);break}case"checkbox":{Q+=q.checkbox(X);break}case"strong":{Q+=q.strong(X);break}case"em":{Q+=q.em(X);break}case"codespan":{Q+=q.codespan(X);break}case"br":{Q+=q.br(X);break}case"del":{Q+=q.del(X);break}case"text":{Q+=q.text(X);break}default:{let G='Token with "'+X.type+'" type was not found.';if(this.options.silent)return console.error(G),"";throw Error(G)}}}return Q}},B0=class{options;block;constructor(Z){this.options=Z||r1}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens","emStrongMask"]);static passThroughHooksRespectAsync=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(Z){return Z}postprocess(Z){return Z}processAllTokens(Z){return Z}emStrongMask(Z){return Z}provideLexer(Z=this.block){return Z?F1.lex:F1.lexInline}provideParser(Z=this.block){return Z?B1.parse:B1.parseInline}},b8=class{defaults=F2();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=B1;Renderer=g0;TextRenderer=j2;Lexer=F1;Tokenizer=u0;Hooks=B0;constructor(...Z){this.use(...Z)}walkTokens(Z,$){let q=[];for(let Q of Z)switch(q=q.concat($.call(this,Q)),Q.type){case"table":{let J=Q;for(let Y of J.header)q=q.concat(this.walkTokens(Y.tokens,$));for(let Y of J.rows)for(let X of Y)q=q.concat(this.walkTokens(X.tokens,$));break}case"list":{let J=Q;q=q.concat(this.walkTokens(J.items,$));break}default:{let J=Q;this.defaults.extensions?.childTokens?.[J.type]?this.defaults.extensions.childTokens[J.type].forEach((Y)=>{let X=J[Y].flat(1/0);q=q.concat(this.walkTokens(X,$))}):J.tokens&&(q=q.concat(this.walkTokens(J.tokens,$)))}}return q}use(...Z){let $=this.defaults.extensions||{renderers:{},childTokens:{}};return Z.forEach((q)=>{let Q={...q};if(Q.async=this.defaults.async||Q.async||!1,q.extensions&&(q.extensions.forEach((J)=>{if(!J.name)throw Error("extension name required");if("renderer"in J){let Y=$.renderers[J.name];Y?$.renderers[J.name]=function(...X){let G=J.renderer.apply(this,X);return G===!1&&(G=Y.apply(this,X)),G}:$.renderers[J.name]=J.renderer}if("tokenizer"in J){if(!J.level||J.level!=="block"&&J.level!=="inline")throw Error("extension level must be 'block' or 'inline'");let Y=$[J.level];Y?Y.unshift(J.tokenizer):$[J.level]=[J.tokenizer],J.start&&(J.level==="block"?$.startBlock?$.startBlock.push(J.start):$.startBlock=[J.start]:J.level==="inline"&&($.startInline?$.startInline.push(J.start):$.startInline=[J.start]))}"childTokens"in J&&J.childTokens&&($.childTokens[J.name]=J.childTokens)}),Q.extensions=$),q.renderer){let J=this.defaults.renderer||new g0(this.defaults);for(let Y in q.renderer){if(!(Y in J))throw Error(`renderer '${Y}' does not exist`);if(["options","parser"].includes(Y))continue;let X=Y,G=q.renderer[X],z=J[X];J[X]=(..._)=>{let H=G.apply(J,_);return H===!1&&(H=z.apply(J,_)),H||""}}Q.renderer=J}if(q.tokenizer){let J=this.defaults.tokenizer||new u0(this.defaults);for(let Y in q.tokenizer){if(!(Y in J))throw Error(`tokenizer '${Y}' does not exist`);if(["options","rules","lexer"].includes(Y))continue;let X=Y,G=q.tokenizer[X],z=J[X];J[X]=(..._)=>{let H=G.apply(J,_);return H===!1&&(H=z.apply(J,_)),H}}Q.tokenizer=J}if(q.hooks){let J=this.defaults.hooks||new B0;for(let Y in q.hooks){if(!(Y in J))throw Error(`hook '${Y}' does not exist`);if(["options","block"].includes(Y))continue;let X=Y,G=q.hooks[X],z=J[X];B0.passThroughHooks.has(Y)?J[X]=(_)=>{if(this.defaults.async&&B0.passThroughHooksRespectAsync.has(Y))return(async()=>{let U=await G.call(J,_);return z.call(J,U)})();let H=G.call(J,_);return z.call(J,H)}:J[X]=(..._)=>{if(this.defaults.async)return(async()=>{let U=await G.apply(J,_);return U===!1&&(U=await z.apply(J,_)),U})();let H=G.apply(J,_);return H===!1&&(H=z.apply(J,_)),H}}Q.hooks=J}if(q.walkTokens){let J=this.defaults.walkTokens,Y=q.walkTokens;Q.walkTokens=function(X){let G=[];return G.push(Y.call(this,X)),J&&(G=G.concat(J.call(this,X))),G}}this.defaults={...this.defaults,...Q}}),this}setOptions(Z){return this.defaults={...this.defaults,...Z},this}lexer(Z,$){return F1.lex(Z,$??this.defaults)}parser(Z,$){return B1.parse(Z,$??this.defaults)}parseMarkdown(Z){return($,q)=>{let Q={...q},J={...this.defaults,...Q},Y=this.onError(!!J.silent,!!J.async);if(this.defaults.async===!0&&Q.async===!1)return Y(Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(typeof $>"u"||$===null)return Y(Error("marked(): input parameter is undefined or null"));if(typeof $!="string")return Y(Error("marked(): input parameter is of type "+Object.prototype.toString.call($)+", string expected"));if(J.hooks&&(J.hooks.options=J,J.hooks.block=Z),J.async)return(async()=>{let X=J.hooks?await J.hooks.preprocess($):$,G=await(J.hooks?await J.hooks.provideLexer(Z):Z?F1.lex:F1.lexInline)(X,J),z=J.hooks?await J.hooks.processAllTokens(G):G;J.walkTokens&&await Promise.all(this.walkTokens(z,J.walkTokens));let _=await(J.hooks?await J.hooks.provideParser(Z):Z?B1.parse:B1.parseInline)(z,J);return J.hooks?await J.hooks.postprocess(_):_})().catch(Y);try{J.hooks&&($=J.hooks.preprocess($));let X=(J.hooks?J.hooks.provideLexer(Z):Z?F1.lex:F1.lexInline)($,J);J.hooks&&(X=J.hooks.processAllTokens(X)),J.walkTokens&&this.walkTokens(X,J.walkTokens);let G=(J.hooks?J.hooks.provideParser(Z):Z?B1.parse:B1.parseInline)(X,J);return J.hooks&&(G=J.hooks.postprocess(G)),G}catch(X){return Y(X)}}}onError(Z,$){return(q)=>{if(q.message+=`
59
- Please report this to https://github.com/markedjs/marked.`,Z){let Q="<p>An error occurred:</p><pre>"+b1(q.message+"",!0)+"</pre>";return $?Promise.resolve(Q):Q}if($)return Promise.reject(q);throw q}}},l1=new b8;function e(Z,$){return l1.parse(Z,$)}e.options=e.setOptions=function(Z){return l1.setOptions(Z),e.defaults=l1.defaults,J3(e.defaults),e};e.getDefaults=F2;e.defaults=r1;e.use=function(...Z){return l1.use(...Z),e.defaults=l1.defaults,J3(e.defaults),e};e.walkTokens=function(Z,$){return l1.walkTokens(Z,$)};e.parseInline=l1.parseInline;e.Parser=B1;e.parser=B1.parse;e.Renderer=g0;e.TextRenderer=j2;e.Lexer=F1;e.lexer=F1.lex;e.Tokenizer=u0;e.Hooks=B0;e.parse=e;var{options:h6,setOptions:p6,use:c6,walkTokens:d6,parseInline:l6}=e;var r6=B1.parse,i6=F1.lex;import{SessionContext as k5,ActiveViewCtx as x6}from"#canvas/runtime";import{useState as y0,useCallback as j1,useEffect as w8,useRef as A8,useMemo as C8}from"react";import{AnnotationCtx as V8}from"#canvas/runtime";function h0(Z,$){return`canvas:${Z}:rev:${$}`}function M0(Z,$){return`${h0(Z,$)}:draft-handled`}function Q0(Z,$,q){try{Z.removeItem(h0($,q)),Z.removeItem(M0($,q))}catch{}}function W3(Z){if(!Z)return null;try{let $=JSON.parse(Z);return typeof $==="object"&&$!==null&&!Array.isArray($)?$:null}catch{return null}}function j8(Z){if(!Array.isArray(Z)||Z.length<2)return!1;let $=Z[1];if(typeof $!=="object"||$===null||Array.isArray($))return!1;let q=Reflect.get($,"note");if(typeof q==="string"&&q.trim().length>0)return!0;let Q=Reflect.get($,"value");if(typeof Q==="string")return Q.trim().length>0;if(Array.isArray(Q))return Q.length>0;return Q!==null&&Q!==void 0}function T3(Z){if(!Z)return!1;let $=Reflect.get(Z,"annotations");if(Array.isArray($)&&$.length>0)return!0;let q=Reflect.get(Z,"generalNote");if(typeof q==="string"&&q.trim().length>0)return!0;let Q=Reflect.get(Z,"responses");return Array.isArray(Q)&&Q.some(j8)}function w2(Z,$,q,Q){try{let J=h0($,q);if(T3(W3(Z.getItem(J))))return Z.setItem(M0($,q),"1"),null;if(Z.getItem(M0($,q))!==null)return null;let Y=Q.filter((X)=>X.revision<q).sort((X,G)=>G.revision-X.revision);for(let X of Y){if(X.hasFeedback)return null;let G=W3(Z.getItem(h0($,X.revision)));if(!T3(G)){if(Z.getItem(M0($,X.revision))!==null)return null;continue}return Z.setItem(J,JSON.stringify({...G,feedbackEntries:[]})),Z.setItem(M0($,q),"1"),X.revision}}catch{}return null}var T1="__agent-response__";function L1(){return`ann-${Date.now()}-${Math.random().toString(36).slice(2,6)}`}function P0(Z,$){Z.style.height="auto",Z.style.height=($?Math.max($,Z.scrollHeight):Z.scrollHeight)+"px"}import{useAnnotations as X1}from"#canvas/runtime";import{jsxDEV as D8}from"react/jsx-dev-runtime";function N3(Z,$){return`canvas:${Z}:rev:${$}`}function p0(Z,$){try{let q=localStorage.getItem(N3(Z,$));if(!q)return null;return JSON.parse(q)}catch{return null}}function I8(Z,$,q){try{localStorage.setItem(N3(Z,$),JSON.stringify(q))}catch{}}function O3({sessionId:Z,revision:$,isReadOnly:q,remoteAnnotations:Q,children:J}){let[Y,X]=y0(()=>{return(p0(Z,$)?.annotations??[]).map((k)=>({...k,source:k.source??"local"}))}),G=C8(()=>{if(!Q||Q.length===0)return Y;let V=new Set(Y.map((x)=>x.id)),k=Q.filter((x)=>!V.has(x.id));return[...Y,...k.map((x)=>({...x,source:"remote"}))]},[Y,Q]),[z,_]=y0(()=>{return p0(Z,$)?.generalNote??""}),[H,U]=y0(null),[W,T]=y0(()=>{let V=p0(Z,$);return V?.responses?new Map(V.responses):new Map}),[K,L]=y0(()=>{let V=p0(Z,$);return V?.feedbackEntries?new Map(V.feedbackEntries):new Map}),N=A8(null);w8(()=>{if(q)return;if(N.current)clearTimeout(N.current);return N.current=setTimeout(()=>{I8(Z,$,{annotations:Y,generalNote:z,responses:Array.from(W.entries()),feedbackEntries:Array.from(K.entries())})},300),()=>{if(N.current)clearTimeout(N.current)}},[Y,z,W,K,Z,$,q]);let y=j1((V,k,x,l,j,f,v)=>{X((o)=>[...o,{id:V,snippet:k,note:x,createdAt:new Date().toISOString(),filePath:l,context:j,...f?.length?{images:f}:{},...v?{canvasFile:v}:{}}])},[]),O=j1((V,k,x)=>{y(L1(),V,k,x)},[y]),R=j1((V,k)=>{X((x)=>x.map((l)=>l.id===V?{...l,note:k}:l))},[]),S=j1((V)=>{R8(V),X((k)=>k.filter((x)=>x.id!==V)),U((k)=>k===V?null:k)},[]),M=j1((V,k)=>{X((x)=>x.map((l)=>l.id===V?{...l,images:[...l.images||[],k]}:l))},[]),b=j1((V,k)=>{X((x)=>x.map((l)=>l.id===V?{...l,images:(l.images||[]).filter((j)=>j!==k)}:l))},[]),g=j1((V,k)=>{T((x)=>{let l=new Map(x);return l.set(V,k),l})},[]),C=j1((V,k)=>{L((x)=>{let l=x.get(V);if(l&&l.markdown===k.markdown&&l.label===k.label&&l.required===k.required)return x;let j=new Map(x);return j.set(V,k),j})},[]),p=j1((V)=>{L((k)=>{if(!k.has(V))return k;let x=new Map(k);return x.delete(V),x})},[]),h=j1(()=>{for(let V of document.querySelectorAll("[data-annotation-id]"))F3(V);X([]),_(""),U(null),T(new Map),L(new Map),Q0(localStorage,Z,$)},[Z,$]);return D8(V8.Provider,{value:{annotations:G,addAnnotation:O,addAnnotationWithId:y,updateAnnotation:R,removeAnnotation:S,addAnnotationImage:M,removeAnnotationImage:b,generalNote:z,setGeneralNote:_,clearAll:h,activeAnnotationId:H,setActiveAnnotationId:U,responses:W,setResponse:g,feedbackEntries:K,setFeedbackEntry:C,removeFeedbackEntry:p},children:J},void 0,!1,void 0,this)}function R8(Z){let $=document.querySelectorAll(`[data-annotation-id="${Z}"]`);for(let q of $)F3(q)}function F3(Z){let $=Z.parentNode;if(!$)return;let q=document.createTextNode(Z.textContent||"");$.replaceChild(q,Z),$.normalize()}import n0,{useEffect as e1,useState as w1,useRef as Z4,useContext as f3,useMemo as b0}from"react";import{createPortal as q4}from"react-dom";import{SessionContext as J4,CanvasFileCtx as Q4}from"#canvas/runtime";function i1(Z,$){let q=B3(Z,"before",60),Q=B3(Z,"after",60),J=E8(Z.startContainer,$);return{before:q,after:Q,hierarchy:J}}function B3(Z,$,q){let Q=k8($==="before"?Z.startContainer:Z.endContainer);if(!Q)return"";let J="";if($==="before"){let Y=document.createTreeWalker(Q,NodeFilter.SHOW_TEXT),X;while(X=Y.nextNode()){if(X===Z.startContainer){J+=(X.textContent||"").slice(0,Z.startOffset);break}if(X.parentElement?.hasAttribute("data-annotation-id"))continue;J+=X.textContent||""}if(J.length>q){J=J.slice(-q);let G=J.indexOf(" ");if(G>0)J=J.slice(G+1)}}else{let Y=document.createTreeWalker(Q,NodeFilter.SHOW_TEXT),X=!1,G;while(G=Y.nextNode()){if(G===Z.endContainer){J+=(G.textContent||"").slice(Z.endOffset),X=!0;continue}if(X){if(G.parentElement?.hasAttribute("data-annotation-id"))continue;J+=G.textContent||""}}if(J.length>q){J=J.slice(0,q);let z=J.lastIndexOf(" ");if(z>0)J=J.slice(0,z)}}return J.trim()}function k8(Z){let $=new Set(["DIV","P","LI","PRE","BLOCKQUOTE","SECTION","ARTICLE"]),q=Z.parentElement;while(q){if($.has(q.tagName))return q;q=q.parentElement}return null}function E8(Z,$){let q=[],Q=Z instanceof Element?Z:Z.parentElement;while(Q&&Q!==$){let J=Q.getAttribute?.("data-task-id");if(J){let Y=Q.querySelector(".font-semibold");if(Y)q.unshift(Y.textContent?.trim()||J)}if(Q.tagName==="DIV"&&Q.querySelector(":scope > button .font-heading, :scope > div .font-heading")){let Y=Q.querySelector(".font-heading");if(Y)q.unshift(Y.textContent?.trim()||"")}Q=Q.parentElement}return q}function A2(Z){let $=Z.snippet.trim(),q=Z.context,Q=$.length<30;if(q&&Q&&(q.before||q.after)){let J=[];if(q.before)J.push(`...${q.before} `);if(J.push(`**${$}**`),q.after)J.push(` ${q.after}...`);return J.join("")}return $}import{useEffect as l8,useRef as l0,useState as Y0,useCallback as d0,useMemo as D3,useContext as r8}from"react";import{createPortal as i8}from"react-dom";function L3(Z,$){let J=$||document.body,Y=Z.getBoundingClientRect(),X=J.getBoundingClientRect(),G=J===document.body?window.scrollY:J.scrollTop,z=Y.bottom-X.top+G+8,_=Math.max(0,Math.min(Y.left-X.left,X.width-280-12));return J.style.position="relative",{style:{position:"absolute",top:`${z}px`,left:`${_}px`},parent:J}}import{useState as V2,useRef as I2,useCallback as R1,useEffect as c8}from"react";var M3={alg:"AES-GCM",v:1};async function P3(Z){let $=m8(Z);return crypto.subtle.importKey("raw",$,{name:"AES-GCM",length:256},!1,["encrypt","decrypt"])}async function u1(Z,$){let q=crypto.getRandomValues(new Uint8Array(12)),Q=new TextEncoder().encode($),J=await crypto.subtle.encrypt({name:"AES-GCM",iv:q},Z,Q),Y=new Uint8Array(q.byteLength+J.byteLength);return Y.set(q,0),Y.set(new Uint8Array(J),q.byteLength),x8(Y)}async function S0(Z,$){let q=y3($);if(q.byteLength<28)throw Error("Ciphertext too short");let Q=q.subarray(0,12),J=q.subarray(12),Y=await crypto.subtle.decrypt({name:"AES-GCM",iv:Q},Z,J);return new TextDecoder().decode(Y)}function x8(Z){let $="",q=32768;for(let Q=0;Q<Z.byteLength;Q+=q)$+=String.fromCharCode.apply(null,Array.from(Z.subarray(Q,Q+q)));return btoa($)}function y3(Z){let $=atob(Z),q=new Uint8Array($.length);for(let Q=0;Q<$.length;Q++)q[Q]=$.charCodeAt(Q);return q}function m8(Z){let $=Z.replace(/-/g,"+").replace(/_/g,"/")+"===".slice((Z.length+3)%4);return y3($)}function u8(){if(typeof window>"u")return null;let Z=window.location.hash.replace(/^#/,"");if(!Z)return null;for(let $ of Z.split("&")){let[q,Q]=$.split("=");if(q==="k"&&Q)return decodeURIComponent(Q)}return null}function g8(){if(typeof window<"u"&&window.__CANVAS_SHARE__?.shareId){let $=u8();return{isShared:!0,shareId:window.__CANVAS_SHARE__.shareId,encryptionKey:$?P3($):null}}return{isShared:!1,sessionId:typeof window<"u"?window.location.pathname.replace("/s/",""):""}}var $1=g8();function f8(){return $1.isShared&&$1.encryptionKey!==null}function v8(){if($1.isShared)return`/s/${$1.shareId}/meta`;return`/api/session/${$1.sessionId}/meta`}function h8(Z,$){let q=Z.replace(/\.jsx$/,".js");if($1.isShared)return`/s/${$1.shareId}/canvas/${encodeURIComponent(q)}`;let Q=$?`?rev=${$}&t=${Date.now()}`:`?t=${Date.now()}`;return`/api/session/${$1.sessionId}/canvas/${encodeURIComponent(q)}${Q}`}function S3(){if($1.isShared)return`/s/${$1.shareId}/upload`;return`/api/session/${$1.sessionId}/upload`}async function b3(){let Z=await fetch(v8());if(!Z.ok)throw Error(`meta ${Z.status}`);let $=await Z.json();if($.encryption&&$1.isShared&&$1.encryptionKey){let q=await $1.encryptionKey;if($.origin){let J={...$.origin};if(J.sessionId)J.sessionId=await S0(q,J.sessionId);if(J.label)J.label=await S0(q,J.label);$.origin=J}let Q=$.revisions;if(Array.isArray(Q)){for(let J of Q)if(J.label)try{J.label=await S0(q,J.label)}catch{}}}return $}async function j3(Z,$){let q=h8(Z,$);if(!f8())return import(q);let Q=await fetch(q);if(!Q.ok)throw Error(`canvas ${Q.status}`);let J=await Q.text(),Y=await $1.encryptionKey,X=await S0(Y,J),G=new Blob([X],{type:"application/javascript"}),z=URL.createObjectURL(G);try{return await import(z)}finally{setTimeout(()=>URL.revokeObjectURL(z),0)}}var w3="canvas-reviewer-identity";function C2(){try{let Z=localStorage.getItem(w3);if(!Z)return null;return JSON.parse(Z)}catch{return null}}function A3(Z){let $=C2();if(!$)$={id:crypto.randomUUID?.()||String(Date.now()),name:Z};else $.name=Z;return localStorage.setItem(w3,JSON.stringify($)),$}async function p8(Z,$){let q=await Promise.all(Z.annotations.map(async(Q)=>{let J={id:Q.id,createdAt:Q.createdAt,snippet:await u1($,String(Q.snippet??"")),note:await u1($,String(Q.note??""))};if(Q.filePath)J.filePath=await u1($,String(Q.filePath));if(Q.canvasFile)J.canvasFile=await u1($,String(Q.canvasFile));if(Q.context!==void 0&&Q.context!==null)J.context=await u1($,JSON.stringify(Q.context));if(Q.attachments)J.attachments=Q.attachments;return J}));return{author:{id:Z.author.id,name:await u1($,Z.author.name)},revision:Z.revision,annotations:q,...Z.generalNote?{generalNote:await u1($,Z.generalNote)}:{},encryption:M3}}async function C3(Z){if(!$1.isShared)throw Error("submitSharedFeedback called outside shared mode");let $=Z;if($1.encryptionKey){let Q=await $1.encryptionKey;$=await p8(Z,Q)}let q=await fetch(`/s/${$1.shareId}/feedback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify($)});if(!q.ok){let Q=await q.text().catch(()=>"");throw Error(`Feedback submission failed: ${q.status} ${Q}`)}}var M1=!$1.isShared,V3=!$1.isShared;import{jsxDEV as _1}from"react/jsx-dev-runtime";function I3(Z){if(Z.startsWith("/s/")||Z.startsWith("http://")||Z.startsWith("https://"))return Z;return`/api/uploads/${Z.split("/").pop()}`}async function d8(Z,$){let q=new FormData;q.append("image",$);try{let J=await(await fetch(S3(),{method:"POST",body:q})).json();if($1.isShared)return J.url||null;return J.path||null}catch{return null}}function c0({note:Z,onNoteChange:$,images:q,onAddImage:Q,onRemoveImage:J,sessionId:Y,placeholder:X="Add your note...",autoFocus:G=!1,autoResize:z=!1,readOnly:_=!1,onKeyDown:H,onTextareaClick:U,textareaRef:W,textareaClassName:T,textareaStyle:K,minHeight:L,attachButton:N="always",openFilePickerRef:y}){let[O,R]=V2(!1),[S,M]=V2(!1),[b,g]=V2(!1),C=I2(0),p=I2(null),h=I2(null),V=R1(()=>h.current?.click(),[]);if(y)y.current=V;let k=R1((D)=>{if(p.current=D,W)W.current=D;if(D&&z)P0(D,L)},[W,z,L]);c8(()=>{if(G&&p.current){let D=p.current;if(D.focus(),D.value)D.setSelectionRange(D.value.length,D.value.length)}},[G]);let x=R1(async(D)=>{if(!D.type.startsWith("image/"))return;M(!0);try{let a=await d8(Y,D);if(a)Q(a)}finally{M(!1)}},[Y,Q]),l=R1((D)=>{let a=D.clipboardData.items;for(let I of a)if(I.type.startsWith("image/")){D.preventDefault();let E=I.getAsFile();if(E)x(E);return}},[x]),j=R1((D)=>{if(D.preventDefault(),C.current++,C.current===1)R(!0)},[]),f=R1((D)=>{D.preventDefault()},[]),v=R1((D)=>{if(D.preventDefault(),C.current--,C.current===0)R(!1)},[]),o=R1((D)=>{D.preventDefault(),C.current=0,R(!1);for(let a of D.dataTransfer.files)if(a.type.startsWith("image/"))x(a)},[x]),w=R1((D)=>{if($(D.target.value),z)D.target.style.height="auto",D.target.style.height=(L?Math.max(L,D.target.scrollHeight):D.target.scrollHeight)+"px"},[$,z,L]),B="w-full bg-transparent text-[13px] font-body text-text-primary resize-none focus:outline-none leading-relaxed p-0 border-none",m={width:"100%",background:"transparent",border:"none",color:"var(--color-text-primary)",fontFamily:"'Inter', sans-serif",fontSize:"13px",lineHeight:"1.5",outline:"none",...z?{resize:"none",overflow:"hidden"}:{resize:"vertical"}},u=!_&&(N==="always"||N==="on-focus"&&b);return _1("div",{style:{position:"relative"},onDragEnter:_?void 0:j,onDragOver:_?void 0:f,onDragLeave:_?void 0:v,onDrop:_?void 0:o,children:[_1("textarea",{ref:k,value:Z,onChange:_?void 0:w,onPaste:_?void 0:l,onKeyDown:H,onClick:U,onFocus:()=>g(!0),onBlur:()=>{setTimeout(()=>g(!1),150)},readOnly:_,placeholder:X,className:T??B,style:K??m,rows:z?1:void 0},void 0,!1,void 0,this),!_&&_1("input",{ref:h,type:"file",accept:"image/*",multiple:!0,style:{display:"none"},onChange:(D)=>{let a=D.target.files;if(a)for(let I of a)x(I);D.target.value=""}},void 0,!1,void 0,this),(q.length>0||u)&&_1("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"6px",alignItems:"center"},children:[q.map((D)=>_1("div",{style:{position:"relative",width:"56px",height:"56px",borderRadius:"6px",overflow:"hidden",border:"1px solid var(--color-border-subtle)",flexShrink:0},children:[_1("img",{src:I3(D),alt:"",style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}},void 0,!1,void 0,this),!_&&_1("button",{onClick:(a)=>{a.stopPropagation(),J(D)},style:{position:"absolute",top:"2px",right:"2px",width:"16px",height:"16px",borderRadius:"50%",background:"rgba(0,0,0,0.6)",color:"white",border:"none",cursor:"pointer",fontSize:"11px",display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1,padding:0},title:"Remove image",children:"×"},void 0,!1,void 0,this)]},D,!0,void 0,this)),u&&_1(R2,{onClick:V},void 0,!1,void 0,this)]},void 0,!0,void 0,this),S&&_1("div",{style:{fontSize:"11px",color:"var(--color-text-tertiary)",fontFamily:"'Inter', sans-serif",marginTop:"4px"},children:"Uploading..."},void 0,!1,void 0,this),O&&_1("div",{style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",background:"var(--color-highlight-bg)",opacity:0.9,border:"2px dashed var(--color-highlight-border)",borderRadius:"6px",zIndex:10,pointerEvents:"none",fontSize:"12px",fontFamily:"'Inter', sans-serif",color:"var(--color-text-secondary)"},children:"Drop image"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function R2({onClick:Z,size:$=16}){return _1("button",{onClick:(q)=>{q.stopPropagation(),Z()},style:{width:`${$*2}px`,height:`${$*2}px`,borderRadius:"6px",border:"none",background:"transparent",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--color-text-tertiary)",flexShrink:0,transition:"color 0.15s"},title:"Attach image",onMouseEnter:(q)=>{q.currentTarget.style.color="var(--color-text-secondary)"},onMouseLeave:(q)=>{q.currentTarget.style.color="var(--color-text-tertiary)"},children:_1("svg",{width:$,height:$,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[_1("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"},void 0,!1,void 0,this),_1("circle",{cx:"8.5",cy:"8.5",r:"1.5"},void 0,!1,void 0,this),_1("polyline",{points:"21 15 16 10 5 21"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function R3({images:Z}){if(!Z.length)return null;return _1("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"6px"},children:Z.map(($)=>_1("div",{style:{width:"56px",height:"56px",borderRadius:"6px",overflow:"hidden",border:"1px solid var(--color-border-subtle)",flexShrink:0},children:_1("img",{src:I3($),alt:"",style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}},void 0,!1,void 0,this)},$,!1,void 0,this))},void 0,!1,void 0,this)}import{SessionContext as a8}from"#canvas/runtime";import{jsxDEV as G1,Fragment as s8}from"react/jsx-dev-runtime";function o8({anchorEl:Z,scrollContainer:$,onClose:q,ignoreSelector:Q,zIndex:J="50",padding:Y="12px",width:X="280px",children:G}){let z=l0(null),_=l0(q);_.current=q;let{style:H,parent:U}=L3(Z,$);return l8(()=>{let W=setTimeout(()=>{let T=(K)=>{if(z.current&&!z.current.contains(K.target)){if(Q&&K.target.closest?.(Q))return;_.current(),document.removeEventListener("mousedown",T)}};return document.addEventListener("mousedown",T),()=>document.removeEventListener("mousedown",T)},0);return()=>clearTimeout(W)},[Q]),i8(G1("div",{ref:z,style:{...H,zIndex:J,width:X,background:"var(--color-bg-elevated)",border:"1px solid var(--color-border-hover)",borderRadius:"8px",boxShadow:"0 4px 12px var(--color-shadow)",padding:Y,fontFamily:"'Inter', sans-serif"},children:G},void 0,!1,void 0,this),U)}var E3=[{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"]}],k3=E3.flatMap((Z)=>Z.items);function x3({anchorEl:Z,scrollContainer:$,snippet:q,truncateAt:Q=100,header:J,initialNote:Y="",initialImages:X,onConfirm:G,onCancel:z,onDelete:_}){let H=r8(a8),U=Y!==""||!!_,[W,T]=Y0(Y),[K,L]=Y0(X||[]),[N,y]=Y0(null),[O,R]=Y0(U),[S,M]=Y0(!1),b=l0(null),g=l0(null),C=d0(()=>{if(W.trim()||K.length>0)G(W.trim(),K);else if(U&&_)_();else z()},[W,K,G,z,U,_]),p=d0(()=>{if(U){if(!W.trim()&&K.length===0&&_){_(),z();return}G(W,K);return}z()},[W,K,U,G,z,_]),h=!U,V=W.trim().length>0?k3.filter((I)=>I.toLowerCase().startsWith(W.trim().toLowerCase())):k3,k=!h||O?[]:V.length===1&&V[0].toLowerCase()===W.trim().toLowerCase()?[]:V,x=new Set(k),l=E3.map((I)=>({label:I.label,items:I.items.filter((E)=>x.has(E))})).filter((I)=>I.items.length>0),j=l.map((I)=>I.items),f=j.flat(),v=D3(()=>{if(N===null)return 0;let I=0;for(let E=0;E<j.length;E++){if(N<I+j[E].length)return E;I+=j[E].length}return 0},[N,j]),o=D3(()=>{if(N===null)return 0;let I=0;for(let E=0;E<v;E++)I+=j[E].length;return N-I},[N,v,j]),w=(I,E)=>{let Z1=0;for(let Y1=0;Y1<I;Y1++)Z1+=j[Y1].length;return Z1+E},[B,m]=Y0(W);if(W!==B)m(W),y(null),R(U);let u=d0((I)=>{T(I)},[]),D=q.length>Q?q.slice(0,Q)+"...":q,a=d0((I)=>{if(f.length>0&&(I.key==="ArrowDown"||I.key==="ArrowUp"||I.key==="ArrowLeft"||I.key==="ArrowRight")){if(I.preventDefault(),N===null){y(0);return}if(I.key==="ArrowDown"){let E=Math.min(o+1,j[v].length-1);y(w(v,E))}else if(I.key==="ArrowUp"){let E=Math.max(o-1,0);y(w(v,E))}else if(I.key==="ArrowRight"){let E=Math.min(v+1,j.length-1),Z1=Math.min(o,j[E].length-1);y(w(E,Z1))}else if(I.key==="ArrowLeft"){let E=Math.max(v-1,0),Z1=Math.min(o,j[E].length-1);y(w(E,Z1))}return}if(N!==null&&f.length>0){if(I.key==="Tab"){I.preventDefault(),u(f[N]);return}if(I.key==="Enter"&&!I.shiftKey){I.preventDefault(),G(f[N],K);return}}if(I.key==="Enter"&&!I.shiftKey){I.preventDefault(),C();return}if(I.key==="Escape")if(f.length>0&&!O)R(!0);else if(U)p();else z()},[f,N,o,v,j,w,u,G,K,C,O,U,p,z]);return G1(o8,{anchorEl:Z,scrollContainer:$,onClose:U?p:z,ignoreSelector:U?"[data-annotation-id]":void 0,zIndex:U?"60":"50",padding:U?"10px 12px":"12px",width:"420px",children:[!U&&(J??G1("div",{style:{fontSize:"11px",color:"var(--color-text-tertiary)",fontStyle:"italic",marginBottom:"8px",lineHeight:"1.4",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden"},children:["“",D,"”"]},void 0,!0,void 0,this)),G1(c0,{note:W,onNoteChange:T,images:K,onAddImage:(I)=>L((E)=>[...E,I]),onRemoveImage:(I)=>L((E)=>E.filter((Z1)=>Z1!==I)),sessionId:H,autoFocus:!0,autoResize:U,textareaRef:b,onKeyDown:a,attachButton:"none",openFilePickerRef:g,textareaStyle:U?{width:"100%",background:"transparent",border:"none",color:"var(--color-text-primary)",fontFamily:"'Inter', sans-serif",fontSize:"13px",lineHeight:"1.5",resize:"none",outline:"none",overflow:"hidden"}:{width:"100%",minHeight:"60px",background:"transparent",border:"none",color:"var(--color-text-primary)",fontFamily:"'Inter', sans-serif",fontSize:"13px",lineHeight:"1.5",resize:"vertical",outline:"none"},placeholder:"Add your note..."},void 0,!1,void 0,this),G1("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginTop:U?"6px":"8px"},children:[G1(R2,{onClick:()=>g.current?.(),size:14},void 0,!1,void 0,this),G1("div",{style:{flex:1}},void 0,!1,void 0,this),U?G1("button",{onClick:()=>{if(_)_();z()},onMouseEnter:()=>M(!0),onMouseLeave:()=>M(!1),style:{fontSize:"11px",color:S?"var(--color-accent-red)":"var(--color-text-tertiary)",background:"none",border:"none",cursor:"pointer",padding:"2px 0",fontFamily:"'Inter', sans-serif"},children:"Delete"},void 0,!1,void 0,this):G1(s8,{children:[G1("button",{onClick:z,style:{fontSize:"11px",color:"var(--color-text-tertiary)",background:"none",border:"none",cursor:"pointer",padding:"4px 12px",fontFamily:"'Inter', sans-serif"},children:"Cancel"},void 0,!1,void 0,this),G1("button",{onClick:C,style:{fontSize:"11px",fontWeight:500,padding:"4px 12px",borderRadius:"6px",background:"var(--color-highlight-bg)",color:"var(--color-text-primary)",border:"1px solid var(--color-highlight-border)",cursor:"pointer",fontFamily:"'Inter', sans-serif"},children:"Add"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),f.length>0&&G1("div",{style:{marginTop:"6px",borderTop:"1px solid var(--color-border-subtle)",paddingTop:"8px",display:"flex",gap:"4px"},children:l.map((I)=>G1("div",{style:{flex:1},children:[G1("div",{style:{fontSize:"10px",fontWeight:600,color:"var(--color-text-disabled)",textTransform:"uppercase",letterSpacing:"0.05em",padding:"2px 6px",marginBottom:"2px",fontFamily:"'Inter', sans-serif"},children:I.label},void 0,!1,void 0,this),I.items.map((E)=>{let Z1=f.indexOf(E);return G1("div",{onMouseDown:(Y1)=>{Y1.preventDefault(),Y1.stopPropagation(),u(E)},onMouseEnter:()=>y(Z1),style:{padding:"3px 6px",fontSize:"12px",borderRadius:"4px",fontFamily:"'Inter', sans-serif",color:Z1===N?"var(--color-text-primary)":"var(--color-text-secondary)",background:Z1===N?"var(--color-highlight-selected)":"transparent",cursor:"pointer"},children:[G1("span",{style:{fontWeight:500},children:E.slice(0,W.trim().length)},void 0,!1,void 0,this),E.slice(W.trim().length)]},E,!0,void 0,this)})]},I.label,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function X0({anchorEl:Z,scrollContainer:$,snippet:q,truncateAt:Q,header:J,onAdd:Y,onCancel:X}){return G1(x3,{anchorEl:Z,scrollContainer:$,snippet:q,truncateAt:Q,header:J,onConfirm:(G,z)=>Y(G,z),onCancel:X},void 0,!1,void 0,this)}function z0({anchorEl:Z,scrollContainer:$,initialNote:q,initialImages:Q,onUpdate:J,onDelete:Y,onClose:X}){return G1(x3,{anchorEl:Z,scrollContainer:$,snippet:"",initialNote:q,initialImages:Q,onConfirm:(G,z)=>{J(G,z),X()},onDelete:Y,onCancel:X},void 0,!1,void 0,this)}import{useEffect as s0,useState as u3,useRef as s1,useCallback as g3}from"react";function o1(Z,$){let q=[],Q=t8(Z);for(let J of Q){let Y=document.createRange();if(Y.selectNodeContents(J),J===Z.startContainer)Y.setStart(J,Z.startOffset);if(J===Z.endContainer)Y.setEnd(J,Z.endOffset);let X=Y.toString();if(!X||!X.trim())continue;let G=document.createElement("mark");G.setAttribute("data-annotation-id",$);try{Y.surroundContents(G)}catch{let z=Y.extractContents();G.appendChild(z),Y.insertNode(G)}q.push(G)}return q}function t8(Z){let $=[],q=Z.commonAncestorContainer;if(q.nodeType===Node.TEXT_NODE)return $.push(q),$;let Q=document.createTreeWalker(q,NodeFilter.SHOW_TEXT),J;while(J=Q.nextNode()){let Y=J.parentElement;if(Y?.classList.contains("select-none"))continue;if(Y?.closest("[data-annotation-id]"))continue;if(Z.intersectsNode(J))$.push(J)}return $}function a1(Z,$){let q=document.querySelectorAll(`[data-annotation-id="${Z}"]`);for(let Q of q)Q.classList.toggle("mark-active",$)}function r0(Z,$){if($!=null&&$!==Z)a1($,!1);if(Z!=null)a1(Z,!0)}function i0(Z,$){let q=document.querySelectorAll(`[data-annotation-id="${Z}"]`);for(let Q of q)Q.setAttribute("data-annotation-id",$)}function a0(Z,$){for(let q of $){if(Z.querySelector(`[data-annotation-id="${q.id}"]`))continue;let Q=q.snippet;if(!Q)continue;let{fullText:J,textNodes:Y}=n8(Z),X=[],G=0;while(!0){let T=J.indexOf(Q,G);if(T===-1)break;X.push(T),G=T+1}if(X.length===0)continue;let z=X[0];if(X.length>1&&q.context){let T=-1;for(let K of X){let L=0;if(q.context.before){let N=J.slice(Math.max(0,K-80),K);if(N.includes(q.context.before))L+=2;else if(q.context.before.length>10&&N.includes(q.context.before.slice(-10)))L+=1}if(q.context.after){let N=J.slice(K+Q.length,K+Q.length+80);if(N.includes(q.context.after))L+=2;else if(q.context.after.length>10&&N.includes(q.context.after.slice(0,10)))L+=1}if(L>T)T=L,z=K}}let _=z,H=z+Q.length,U=m3(Y,_),W=m3(Y,H);if(!U||!W)continue;try{let T=document.createRange();T.setStart(U.node,U.offset),T.setEnd(W.node,W.offset),o1(T,q.id)}catch{}}}function n8(Z){let $=[],q="",Q=document.createTreeWalker(Z,NodeFilter.SHOW_TEXT),J;while(J=Q.nextNode()){let Y=J.parentElement;if(Y?.classList.contains("select-none"))continue;if(Y?.closest("[data-annotation-id]"))continue;$.push({node:J,start:q.length}),q+=J.textContent||""}return{fullText:q,textNodes:$}}function m3(Z,$){for(let q=Z.length-1;q>=0;q--)if(Z[q].start<=$){let Q=$-Z[q].start,J=Z[q].node.textContent?.length??0;if(Q<=J)return{node:Z[q].node,offset:Q}}return null}function o0(Z){let $=document.querySelectorAll(`[data-annotation-id="${Z}"]`);for(let q of $){let Q=q.parentNode;if(!Q)continue;while(q.firstChild)Q.insertBefore(q.firstChild,q);Q.removeChild(q),Q.normalize()}}import{jsxDEV as D2,Fragment as e8}from"react/jsx-dev-runtime";function t1(Z){let{containerRef:$,restoreKey:q,restoreAnnotations:Q,extractContext:J,filePath:Y,canvasFile:X,scrollContainer:G}=Z,{annotations:z,addAnnotationWithId:_,removeAnnotation:H,updateAnnotation:U,addAnnotationImage:W,removeAnnotationImage:T,activeAnnotationId:K,setActiveAnnotationId:L}=X1(),[N,y]=u3(null),[O,R]=u3(null),S=s1(J);S.current=J;let M=s1(Y);M.current=Y;let b=s1(X);b.current=X;let g=s1(_);g.current=_;let C=s1(K);C.current=K;let p=s1(L);p.current=L;let h=Q.length;s0(()=>{if(!$.current)return;let j=setTimeout(()=>{if($.current)a0($.current,Q)},50);return()=>clearTimeout(j)},[q,h]);let V=s1(null);s0(()=>{r0(K,V.current),V.current=K},[K]),s0(()=>{let j=$.current;if(!j)return;let f=(w)=>{let B=w.target.closest("[data-annotation-id]");if(!B)return;w.stopPropagation();let m=B.getAttribute("data-annotation-id");if(m===C.current)y({anchorEl:B,annId:m});else p.current(m)},v=(w)=>{let B=w.target.closest("[data-annotation-id]");if(B)p.current(B.getAttribute("data-annotation-id"))},o=(w)=>{let B=w.target.closest("[data-annotation-id]"),m=w.relatedTarget?.closest?.("[data-annotation-id]");if(B&&!m&&!document.getElementById("ann-inline-popover"))p.current(null)};return j.addEventListener("click",f),j.addEventListener("mouseover",v),j.addEventListener("mouseout",o),()=>{j.removeEventListener("click",f),j.removeEventListener("mouseover",v),j.removeEventListener("mouseout",o)}},[q]),s0(()=>{let j=()=>k();return document.addEventListener("mouseup",j),()=>document.removeEventListener("mouseup",j)},[]);let k=g3(()=>{let j=window.getSelection();if(!j||j.isCollapsed||!j.toString().trim())return;if(!$.current)return;let f=j.getRangeAt(0);if(!$.current.contains(f.startContainer))return;if(f.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let v=j.toString().trim();if(v.length<2)return;let o=S.current(f),w=f.cloneRange(),B=`__pending_${Date.now()}`;try{o1(w,B)}catch{}window.getSelection()?.removeAllRanges();let m=document.querySelectorAll(`[data-annotation-id="${B}"]`),u=m[m.length-1];if(!u)return;R({anchorEl:u,tempId:B,snippet:v,ctx:o})},[]),x=g3((j,f,v,o)=>{R({anchorEl:j,tempId:f,snippet:v,ctx:o})},[]);return{popovers:D2(e8,{children:[N&&(()=>{let j=z.find((f)=>f.id===N.annId);if(!j)return null;return D2(z0,{anchorEl:N.anchorEl,scrollContainer:G,initialNote:j.note,initialImages:j.images,onUpdate:(f,v)=>{U(N.annId,f);let o=j.images||[];for(let w of v)if(!o.includes(w))W(N.annId,w);for(let w of o)if(!v.includes(w))T(N.annId,w)},onDelete:()=>{H(N.annId),L(null)},onClose:()=>y(null)},void 0,!1,void 0,this)})(),O&&D2(X0,{anchorEl:O.anchorEl,scrollContainer:G,snippet:O.snippet,truncateAt:80,onAdd:(j,f)=>{let v=L1();i0(O.tempId,v),g.current(v,O.snippet,j,M.current,O.ctx,f,b.current),R(null)},onCancel:()=>{o0(O.tempId),R(null)}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),openCreatePopover:x,isPopoverOpen:!!(N||O)}}import{createContext as $4}from"react";var t0=$4(()=>{});import{jsxDEV as q1,Fragment as _4}from"react/jsx-dev-runtime";var E2="[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']",k2="[data-md='item'], [data-md='section'], [data-md='table'] tbody tr, [data-md='callout'], [data-md='note'], [data-md='checklist-item'], [data-md='image']";class v3 extends n0.Component{state={error:null};static getDerivedStateFromError(Z){return{error:Z}}componentDidCatch(Z,$){this.props.reportError({revision:this.props.revision,filename:this.props.filename,message:Z.message,...Z.stack?{stack:Z.stack}:{},...$.componentStack?{componentStack:$.componentStack}:{}})}render(){if(!this.state.error)return this.props.children;return q1(h3,{message:this.state.error.message},void 0,!1,void 0,this)}}function h3({message:Z}){return q1("div",{className:"bg-accent-red-muted rounded-lg p-5",children:[q1("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Canvas render failed"},void 0,!1,void 0,this),q1("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:Z},void 0,!1,void 0,this),q1("p",{className:"text-meta font-body text-text-tertiary mt-3",children:"The error was sent back to the canvas author."},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function j0({revision:Z,filename:$}){let q=f3(J4),Q=f3(t0),[J,Y]=w1(null),[X,G]=w1(null),[z,_]=w1(!0),H=Z4(null),{annotations:U,addAnnotationWithId:W,removeAnnotation:T,updateAnnotation:K,addAnnotationImage:L,removeAnnotationImage:N,activeAnnotationId:y,setActiveAnnotationId:O}=X1(),R=b0(()=>U.filter((w)=>!w.filePath&&(!w.canvasFile||w.canvasFile===$)),[U,$]),[S,M]=w1(null),[b,g]=w1(null),[C,p]=w1(null),[h,V]=w1(null),[k,x]=w1(!1);e1(()=>{_(!0),G(null),V(null),j3($,Z).then((w)=>{Y(()=>w.default),_(!1)}).catch((w)=>{let B=w instanceof Error?w:Error(String(w));G(B.message),_(!1),Q({revision:Z,filename:$,message:B.message,...B.stack?{stack:B.stack}:{}})})},[q,Z,$,Q]);let l=document.getElementById("plan-scroll-container"),{popovers:j,isPopoverOpen:f}=t1({containerRef:H,restoreKey:J,restoreAnnotations:R,extractContext:(w)=>i1(w,H.current),canvasFile:$,scrollContainer:l}),v=b0(()=>{let w=new Map;for(let B of R)if(B.snippet.startsWith("["))w.set(B.snippet,B.id);return w},[R]);e1(()=>{let w=H.current;if(!w)return;let B=(u)=>{if(C||f)return;let D=u.target;if(D.closest("[data-block-comment-btn]"))return;x(!1);let a=D.closest(E2);if(a&&w.contains(a)){let Z1=n1(w).indexOf(a);V(Z1>=0?Z1:null)}else V(null);let I=D.closest(k2);if(I&&w.contains(I)){g(I);let E=_0(I),Z1=E?v.get(E):void 0;if(Z1&&Z1!==y)O(Z1)}else g(null)},m=(u)=>{if(C||f)return;if(u.relatedTarget?.closest("[data-block-comment-btn]"))return;g(null),O(null)};return w.addEventListener("mousemove",B),w.addEventListener("mouseleave",m),()=>{w.removeEventListener("mousemove",B),w.removeEventListener("mouseleave",m)}},[J,C,f,v,y]),e1(()=>{let w=(B)=>{let m=B.target.tagName;if(m==="INPUT"||m==="TEXTAREA"||B.target.isContentEditable)return;if(C||f)return;let u=H.current;if(!u)return;if(B.key==="ArrowDown"){B.preventDefault(),x(!0);let D=n1(u);if(D.length===0)return;V((a)=>{if(a===null)return 0;return Math.min(a+1,D.length-1)})}else if(B.key==="ArrowUp"){B.preventDefault(),x(!0);let D=n1(u);if(D.length===0)return;V((a)=>{if(a===null)return D.length-1;return Math.max(a-1,0)})}else if(B.key==="a"||B.key==="A"){if(h===null||!u)return;B.preventDefault();let a=n1(u)[h];if(!a)return;let I=_0(a);if(!I)return;let E=v.get(I);if(E)O(E),p({anchorEl:a,snippet:I,annId:E});else p({anchorEl:a,snippet:I})}else if(B.key===" "||B.key==="Enter"){if(h===null)return;let a=n1(u)[h];if(!a)return;let I=a.getAttribute("data-md");if(I==="choice-option"||I==="multichoice-option")B.preventDefault(),a.dispatchEvent(new CustomEvent("kb-select",{bubbles:!0}));else if(I==="userinput"){B.preventDefault();let E=a.querySelector("textarea");if(E){E.focus();let Z1=(Y1)=>{if(Y1.key==="Escape")Y1.preventDefault(),E.blur(),x(!0)};E.addEventListener("keydown",Z1),E.addEventListener("blur",()=>E.removeEventListener("keydown",Z1),{once:!0})}}else if(I==="rangeinput"){B.preventDefault();let E=a.querySelector("input[type='range']");if(E){E.focus();let Z1=(Y1)=>{if(Y1.key==="Escape"||Y1.key==="ArrowUp"||Y1.key==="ArrowDown")Y1.preventDefault(),E.blur(),x(!0)};E.addEventListener("keydown",Z1),E.addEventListener("blur",()=>E.removeEventListener("keydown",Z1),{once:!0})}}}else if(B.key==="Escape")V(null),x(!1),O(null)};return document.addEventListener("keydown",w),()=>document.removeEventListener("keydown",w)},[h,C,f,v]),e1(()=>{let w=H.current;if(!w||h===null||!k)return;let m=n1(w)[h];if(!m)return;m.style.outline="2px solid var(--color-accent-blue)",m.style.outlineOffset="-2px",m.style.borderRadius="8px",m.scrollIntoView({block:"nearest",behavior:"smooth"});let u=_0(m),D=u?v.get(u):void 0;if(D)O(D);return()=>{m.style.outline="",m.style.outlineOffset="",m.style.borderRadius=""}},[h,k,v]);let o=b0(()=>J?q1(J,{},void 0,!1,void 0,this):null,[J]);if(z)return q1("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-body",children:"Loading canvas..."},void 0,!1,void 0,this);if(X)return q1(h3,{message:X},void 0,!1,void 0,this);if(!J)return q1("div",{className:"text-text-tertiary text-center py-8 font-body text-body",children:"No canvas loaded"},void 0,!1,void 0,this);return q1(Q4.Provider,{value:$,children:[q1("div",{ref:H,className:"plan-content plan-updated",children:q1(v3,{revision:Z,filename:$,reportError:Q,children:o},`${Z}:${$}`,!1,void 0,this)},void 0,!1,void 0,this),S&&q1(z4,{note:S.note,onSave:(w)=>{K(S.id,w),M(null)},onCancel:()=>M(null)},void 0,!1,void 0,this),j,q1(Y4,{containerRef:H,hoveredBlock:b,focusedBlockIndex:h,blockPopover:C,blockAnnotationMap:v,activeAnnotationId:y,onOpen:(w,B,m)=>{if(m)O(m),p({anchorEl:w,snippet:B,annId:m});else p({anchorEl:w,snippet:B})}},void 0,!1,void 0,this),C&&!C.annId&&q1(X0,{anchorEl:C.anchorEl,scrollContainer:l,snippet:C.snippet,truncateAt:80,onAdd:(w,B)=>{let m=L1();W(m,C.snippet,w,void 0,void 0,B,$),p(null)},onCancel:()=>p(null)},void 0,!1,void 0,this),C?.annId&&(()=>{let w=R.find((B)=>B.id===C.annId);if(!w)return null;return q1(z0,{anchorEl:C.anchorEl,scrollContainer:l,initialNote:w.note,initialImages:w.images,onUpdate:(B,m)=>{K(C.annId,B);let u=w.images||[];for(let D of m)if(!u.includes(D))L(C.annId,D);for(let D of u)if(!m.includes(D))N(C.annId,D)},onDelete:()=>{T(C.annId),O(null),p(null)},onClose:()=>p(null)},void 0,!1,void 0,this)})()]},void 0,!0,void 0,this)}function n1(Z){return Array.from(Z.querySelectorAll(E2))}function _0(Z){let $=Z.getAttribute("data-md");if($==="item"){let q=Z.getAttribute("data-md-label");return q?`[Item] ${q}`:null}if($==="section"){let q=Z.getAttribute("data-md-title");return q?`[Section] ${q}`:null}if($==="callout"){let q=Z.getAttribute("data-md-type")||"info",Q=Z.textContent?.trim().slice(0,60)||"Callout";return`[Callout:${q}] ${Q}`}if($==="note")return`[Note] ${Z.textContent?.trim().slice(0,60)||"Note"}`;if(Z.tagName==="TR"){let q=Array.from(Z.querySelectorAll("td")).map((Q)=>Q.textContent?.trim()).filter(Boolean);return q.length?`[Row] ${q.join(" | ")}`:null}if($==="checklist-item"){let q=Z.getAttribute("data-md-label");return q?`[Checklist] ${q}`:null}if($==="choice-option"||$==="multichoice-option"){let q=Z.getAttribute("data-md-label");return q?`[Option] ${q}`:null}if($==="userinput"){let q=Z.getAttribute("data-md-label");return q?`[Input] ${q}`:null}if($==="rangeinput"){let q=Z.getAttribute("data-md-label");return q?`[Range] ${q}`:null}if($==="image"){let q=Z.getAttribute("data-md-src");return q?`[Image] ${q}`:null}return null}function Y4({containerRef:Z,hoveredBlock:$,focusedBlockIndex:q,blockPopover:Q,blockAnnotationMap:J,activeAnnotationId:Y,onOpen:X}){let[G,z]=w1([]);e1(()=>{let T=Z.current;if(!T||J.size===0){z([]);return}let K=[];for(let L of T.querySelectorAll(k2)){let N=_0(L);if(N&&J.has(N))K.push(L)}z(K)},[J,Z.current]);let[_,H]=w1(null);e1(()=>{if(!Y||!Z.current){H(null);return}for(let T of Z.current.querySelectorAll(E2)){let K=_0(T);if(K&&J.get(K)===Y){H(T);return}}H(null)},[Y,J]),e1(()=>{if(!_)return;return _.style.boxShadow="inset 0 0 0 1.5px var(--color-highlight-bg)",_.style.borderRadius="8px",()=>{_.style.boxShadow="",_.style.borderRadius=""}},[_]);let U=b0(()=>{if(q===null||!Z.current)return null;let T=n1(Z.current)[q];if(!T)return null;return T.matches(k2)?T:null},[q,Z.current]),W=b0(()=>{let T=new Set(G);if($)T.add($);if(U)T.add(U);if(Q?.anchorEl)T.add(Q.anchorEl);return Array.from(T)},[G,$,U,Q]);return q1(_4,{children:W.map((T)=>q1(X4,{block:T,isHovered:T===$||T===U||T===Q?.anchorEl,blockAnnotationMap:J,activeAnnotationId:Y,onOpen:X},T.getAttribute("data-task-id")||T.getAttribute("data-md-title")||T.textContent?.slice(0,30)||"block",!1,void 0,this))},void 0,!1,void 0,this)}function X4({block:Z,isHovered:$,blockAnnotationMap:q,activeAnnotationId:Q,onOpen:J}){let Y=_0(Z);if(!Y)return null;let X=q.get(Y),G=!!X;return q4(q1("button",{"data-block-comment-btn":!0,onClick:(_)=>{_.stopPropagation(),J(_.currentTarget,Y,X)},className:`absolute top-1 right-1 z-10 w-6 h-6 flex items-center justify-center rounded transition-all duration-150 ${G?X===Q?"text-accent-amber bg-accent-amber-muted":"text-accent-amber opacity-60 hover:opacity-100":$?"text-text-disabled hover:text-text-tertiary opacity-50 hover:opacity-100":"text-text-disabled opacity-0 group-hover/section:opacity-20 hover:!opacity-80"}`,title:G?"Edit annotation":"Add annotation",children:q1("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:G?"currentColor":"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:q1("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),Z)}function z4({note:Z,onSave:$,onCancel:q}){let[Q,J]=n0.useState(Z),Y=n0.useRef(null);return n0.useEffect(()=>{Y.current?.focus(),Y.current?.select()},[]),q1("div",{className:"fixed inset-0 z-50 bg-black/40 flex items-center justify-center",onClick:q,children:q1("div",{className:"bg-bg-elevated border border-border-hover rounded-lg shadow-md p-4 w-80",onClick:(X)=>X.stopPropagation(),children:[q1("div",{className:"text-tiny uppercase tracking-widest text-text-tertiary font-body mb-2",children:"Edit annotation"},void 0,!1,void 0,this),q1("textarea",{ref:Y,value:Q,onChange:(X)=>J(X.target.value),className:"w-full bg-transparent border-none text-body font-body text-text-primary resize-vertical focus:outline-none min-h-[60px]",onKeyDown:(X)=>{if(X.key==="Enter"&&(X.ctrlKey||X.metaKey))$(Q.trim());if(X.key==="Escape")q()}},void 0,!1,void 0,this),q1("div",{className:"flex justify-end gap-2 mt-2",children:[q1("button",{onClick:q,className:"text-meta text-text-tertiary font-body px-3 py-1",children:"Cancel"},void 0,!1,void 0,this),q1("button",{onClick:()=>$(Q.trim()),className:"text-meta font-medium font-body px-3 py-1 rounded-md bg-highlight-bg text-text-primary border border-highlight-border",children:"Save"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}import L4,{useRef as r3,useEffect as q2,useCallback as f2,useState as f1,useContext as J2,useMemo as M4}from"react";function w0(Z,$,q,Q,J){let Y=[],X=Z.filter((T)=>T.source!=="remote"||J&&J.has(T.id)),G=X.filter((T)=>T.filePath===T1),z=X.filter((T)=>!T.filePath),_=X.filter((T)=>T.filePath&&T.filePath!==T1),H=q?Array.from(q.values()).filter((T)=>m2(T)):[],U=Q?Array.from(Q.values()).filter((T)=>T.markdown.trim()):[];if(H.length>0||U.length>0){Y.push("## Responses"),Y.push("");for(let T of H)Y.push(K4(T));for(let T of U)Y.push(T.markdown.trim()),Y.push("")}if(G.length>0){Y.push("## Annotations on agent response"),Y.push("");for(let T of G)Y.push(x2(T))}if(z.length>0){Y.push("## Canvas annotations"),Y.push("");let T=new Map;for(let N of z){let y=N.canvasFile||"";if(!T.has(y))T.set(y,[]);T.get(y).push(N)}let K=[...T.keys()].sort(),L=K.length>1||K.length===1&&K[0]!=="";for(let N of K){let y=T.get(N);if(L&&N)Y.push(`### ${N.replace(/\.jsx$/,"")}`),Y.push("");let O=H4(y);Y.push(p3(O))}}if(_.length>0){let T={};for(let K of _){let L=K.filePath;if(!T[L])T[L]=[];T[L].push(K)}Y.push("## File annotations"),Y.push("");for(let[K,L]of Object.entries(T)){Y.push(`### ${K}`),Y.push("");for(let N of L)Y.push(x2(N))}}if($.trim())Y.push("## General notes"),Y.push(""),Y.push($.trim()),Y.push("");return Y.join(`
60
- `).trim()+`
61
- `}function m2(Z){if(Z.note?.trim())return!0;if(Z.value===null||Z.value===void 0)return!1;if(Z.type==="text"&&!Z.value.trim())return!1;if(Z.type==="checkbox"&&Z.value.length===0)return!1;return!0}function G4(Z){let $=[];for(let q of Z.values()){if(!q.required)continue;if(q.value===null||q.value===void 0){$.push(q);continue}if(q.type==="text"&&!q.value.trim()){$.push(q);continue}if(q.type==="checkbox"&&q.value.length===0){$.push(q);continue}}return $}function U4(Z){let $=[];for(let q of Z.values())if(q.required&&!q.markdown.trim())$.push(q);return $}function e0(Z,$){let q=G4(Z),Q=U4($);return[...q.map((J)=>J.label),...Q.map((J)=>J.label||J.id)]}function K4(Z){let $=[];switch($.push(`**${Z.label}**`),Z.type){case"radio":case"select":$.push(`Answer: ${Z.value}`);break;case"checkbox":for(let q of Z.value)$.push(`- [x] ${q}`);break;case"text":$.push(""),$.push(Z.value.trim());break;case"range":$.push(`Answer: ${Z.value}`);break}if(Z.note?.trim())$.push(""),$.push(`Note: ${Z.note.trim()}`);return $.push(""),$.join(`
62
- `)}function x2(Z){let $=[],q=Z.snippet.trim(),Q=Z.context,J=Q?.lineStart!=null;if(Z.filePath&&J){let Y=Q.lineStart,X=Q.lineEnd??Y,G=q.split(`
63
- `);if(q.length<30&&Y===X&&(Q.before||Q.after)){let _=A2(Z);$.push(`> L${Y}: ${_}`)}else if(G.length<=6)for(let _=0;_<G.length;_++)$.push(`> ${Y+_} | ${G[_]}`);else{for(let _=0;_<3;_++)$.push(`> ${Y+_} | ${G[_]}`);$.push(`> ... (${G.length} lines)`);for(let _=G.length-3;_<G.length;_++)$.push(`> ${Y+_} | ${G[_]}`)}}else{let Y=A2(Z);if(q.split(`
64
- `).length<=3)$.push(`> ${Y.split(`
53
+ `+Q+`</thead>
54
+ `+X+`</table>
55
+ `}tablerow({text:$}){return`<tr>
56
+ ${$}</tr>
57
+ `}tablecell($){let Q=this.parser.parseInline($.tokens),J=$.header?"th":"td";return($.align?`<${J} align="${$.align}">`:`<${J}>`)+Q+`</${J}>
58
+ `}strong({tokens:$}){return`<strong>${this.parser.parseInline($)}</strong>`}em({tokens:$}){return`<em>${this.parser.parseInline($)}</em>`}codespan({text:$}){return`<code>${R1($,!0)}</code>`}br($){return"<br>"}del({tokens:$}){return`<del>${this.parser.parseInline($)}</del>`}link({href:$,title:Q,tokens:J}){let X=this.parser.parseInline(J),Y=g5($);if(Y===null)return X;$=Y;let Z='<a href="'+$+'"';return Q&&(Z+=' title="'+R1(Q)+'"'),Z+=">"+X+"</a>",Z}image({href:$,title:Q,text:J,tokens:X}){X&&(J=this.parser.parseInline(X,this.parser.textRenderer));let Y=g5($);if(Y===null)return R1(J);$=Y;let Z=`<img src="${$}" alt="${R1(J)}"`;return Q&&(Z+=` title="${R1(Q)}"`),Z+=">",Z}text($){return"tokens"in $&&$.tokens?this.parser.parseInline($.tokens):("escaped"in $)&&$.escaped?$.text:R1($.text)}},s2=class{strong({text:$}){return $}em({text:$}){return $}codespan({text:$}){return $}del({text:$}){return $}html({text:$}){return $}text({text:$}){return $}link({text:$}){return""+$}image({text:$}){return""+$}br(){return""}checkbox({raw:$}){return $}},b1=class ${options;renderer;textRenderer;constructor(Q){this.options=Q||G0,this.options.renderer=this.options.renderer||new U2,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new s2}static parse(Q,J){return new $(J).parse(Q)}static parseInline(Q,J){return new $(J).parseInline(Q)}parse(Q){this.renderer.parser=this;let J="";for(let X=0;X<Q.length;X++){let Y=Q[X];if(this.options.extensions?.renderers?.[Y.type]){let q=Y,U=this.options.extensions.renderers[q.type].call({parser:this},q);if(U!==!1||!["space","hr","heading","code","table","blockquote","list","html","def","paragraph","text"].includes(q.type)){J+=U||"";continue}}let Z=Y;switch(Z.type){case"space":{J+=this.renderer.space(Z);break}case"hr":{J+=this.renderer.hr(Z);break}case"heading":{J+=this.renderer.heading(Z);break}case"code":{J+=this.renderer.code(Z);break}case"table":{J+=this.renderer.table(Z);break}case"blockquote":{J+=this.renderer.blockquote(Z);break}case"list":{J+=this.renderer.list(Z);break}case"checkbox":{J+=this.renderer.checkbox(Z);break}case"html":{J+=this.renderer.html(Z);break}case"def":{J+=this.renderer.def(Z);break}case"paragraph":{J+=this.renderer.paragraph(Z);break}case"text":{J+=this.renderer.text(Z);break}default:{let q='Token with "'+Z.type+'" type was not found.';if(this.options.silent)return console.error(q),"";throw Error(q)}}}return J}parseInline(Q,J=this.renderer){this.renderer.parser=this;let X="";for(let Y=0;Y<Q.length;Y++){let Z=Q[Y];if(this.options.extensions?.renderers?.[Z.type]){let U=this.options.extensions.renderers[Z.type].call({parser:this},Z);if(U!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(Z.type)){X+=U||"";continue}}let q=Z;switch(q.type){case"escape":{X+=J.text(q);break}case"html":{X+=J.html(q);break}case"link":{X+=J.link(q);break}case"image":{X+=J.image(q);break}case"checkbox":{X+=J.checkbox(q);break}case"strong":{X+=J.strong(q);break}case"em":{X+=J.em(q);break}case"codespan":{X+=J.codespan(q);break}case"br":{X+=J.br(q);break}case"del":{X+=J.del(q);break}case"text":{X+=J.text(q);break}default:{let U='Token with "'+q.type+'" type was not found.';if(this.options.silent)return console.error(U),"";throw Error(U)}}}return X}},R0=class{options;block;constructor($){this.options=$||G0}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens","emStrongMask"]);static passThroughHooksRespectAsync=new Set(["preprocess","postprocess","processAllTokens"]);preprocess($){return $}postprocess($){return $}processAllTokens($){return $}emStrongMask($){return $}provideLexer($=this.block){return $?C1.lex:C1.lexInline}provideParser($=this.block){return $?b1.parse:b1.parseInline}},y6=class{defaults=p2();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=b1;Renderer=U2;TextRenderer=s2;Lexer=C1;Tokenizer=G2;Hooks=R0;constructor(...$){this.use(...$)}walkTokens($,Q){let J=[];for(let X of $)switch(J=J.concat(Q.call(this,X)),X.type){case"table":{let Y=X;for(let Z of Y.header)J=J.concat(this.walkTokens(Z.tokens,Q));for(let Z of Y.rows)for(let q of Z)J=J.concat(this.walkTokens(q.tokens,Q));break}case"list":{let Y=X;J=J.concat(this.walkTokens(Y.items,Q));break}default:{let Y=X;this.defaults.extensions?.childTokens?.[Y.type]?this.defaults.extensions.childTokens[Y.type].forEach((Z)=>{let q=Y[Z].flat(1/0);J=J.concat(this.walkTokens(q,Q))}):Y.tokens&&(J=J.concat(this.walkTokens(Y.tokens,Q)))}}return J}use(...$){let Q=this.defaults.extensions||{renderers:{},childTokens:{}};return $.forEach((J)=>{let X={...J};if(X.async=this.defaults.async||X.async||!1,J.extensions&&(J.extensions.forEach((Y)=>{if(!Y.name)throw Error("extension name required");if("renderer"in Y){let Z=Q.renderers[Y.name];Z?Q.renderers[Y.name]=function(...q){let U=Y.renderer.apply(this,q);return U===!1&&(U=Z.apply(this,q)),U}:Q.renderers[Y.name]=Y.renderer}if("tokenizer"in Y){if(!Y.level||Y.level!=="block"&&Y.level!=="inline")throw Error("extension level must be 'block' or 'inline'");let Z=Q[Y.level];Z?Z.unshift(Y.tokenizer):Q[Y.level]=[Y.tokenizer],Y.start&&(Y.level==="block"?Q.startBlock?Q.startBlock.push(Y.start):Q.startBlock=[Y.start]:Y.level==="inline"&&(Q.startInline?Q.startInline.push(Y.start):Q.startInline=[Y.start]))}"childTokens"in Y&&Y.childTokens&&(Q.childTokens[Y.name]=Y.childTokens)}),X.extensions=Q),J.renderer){let Y=this.defaults.renderer||new U2(this.defaults);for(let Z in J.renderer){if(!(Z in Y))throw Error(`renderer '${Z}' does not exist`);if(["options","parser"].includes(Z))continue;let q=Z,U=J.renderer[q],G=Y[q];Y[q]=(...K)=>{let _=U.apply(Y,K);return _===!1&&(_=G.apply(Y,K)),_||""}}X.renderer=Y}if(J.tokenizer){let Y=this.defaults.tokenizer||new G2(this.defaults);for(let Z in J.tokenizer){if(!(Z in Y))throw Error(`tokenizer '${Z}' does not exist`);if(["options","rules","lexer"].includes(Z))continue;let q=Z,U=J.tokenizer[q],G=Y[q];Y[q]=(...K)=>{let _=U.apply(Y,K);return _===!1&&(_=G.apply(Y,K)),_}}X.tokenizer=Y}if(J.hooks){let Y=this.defaults.hooks||new R0;for(let Z in J.hooks){if(!(Z in Y))throw Error(`hook '${Z}' does not exist`);if(["options","block"].includes(Z))continue;let q=Z,U=J.hooks[q],G=Y[q];R0.passThroughHooks.has(Z)?Y[q]=(K)=>{if(this.defaults.async&&R0.passThroughHooksRespectAsync.has(Z))return(async()=>{let z=await U.call(Y,K);return G.call(Y,z)})();let _=U.call(Y,K);return G.call(Y,_)}:Y[q]=(...K)=>{if(this.defaults.async)return(async()=>{let z=await U.apply(Y,K);return z===!1&&(z=await G.apply(Y,K)),z})();let _=U.apply(Y,K);return _===!1&&(_=G.apply(Y,K)),_}}X.hooks=Y}if(J.walkTokens){let Y=this.defaults.walkTokens,Z=J.walkTokens;X.walkTokens=function(q){let U=[];return U.push(Z.call(this,q)),Y&&(U=U.concat(Y.call(this,q))),U}}this.defaults={...this.defaults,...X}}),this}setOptions($){return this.defaults={...this.defaults,...$},this}lexer($,Q){return C1.lex($,Q??this.defaults)}parser($,Q){return b1.parse($,Q??this.defaults)}parseMarkdown($){return(Q,J)=>{let X={...J},Y={...this.defaults,...X},Z=this.onError(!!Y.silent,!!Y.async);if(this.defaults.async===!0&&X.async===!1)return Z(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 Q>"u"||Q===null)return Z(Error("marked(): input parameter is undefined or null"));if(typeof Q!="string")return Z(Error("marked(): input parameter is of type "+Object.prototype.toString.call(Q)+", string expected"));if(Y.hooks&&(Y.hooks.options=Y,Y.hooks.block=$),Y.async)return(async()=>{let q=Y.hooks?await Y.hooks.preprocess(Q):Q,U=await(Y.hooks?await Y.hooks.provideLexer($):$?C1.lex:C1.lexInline)(q,Y),G=Y.hooks?await Y.hooks.processAllTokens(U):U;Y.walkTokens&&await Promise.all(this.walkTokens(G,Y.walkTokens));let K=await(Y.hooks?await Y.hooks.provideParser($):$?b1.parse:b1.parseInline)(G,Y);return Y.hooks?await Y.hooks.postprocess(K):K})().catch(Z);try{Y.hooks&&(Q=Y.hooks.preprocess(Q));let q=(Y.hooks?Y.hooks.provideLexer($):$?C1.lex:C1.lexInline)(Q,Y);Y.hooks&&(q=Y.hooks.processAllTokens(q)),Y.walkTokens&&this.walkTokens(q,Y.walkTokens);let U=(Y.hooks?Y.hooks.provideParser($):$?b1.parse:b1.parseInline)(q,Y);return Y.hooks&&(U=Y.hooks.postprocess(U)),U}catch(q){return Z(q)}}}onError($,Q){return(J)=>{if(J.message+=`
59
+ Please report this to https://github.com/markedjs/marked.`,$){let X="<p>An error occurred:</p><pre>"+R1(J.message+"",!0)+"</pre>";return Q?Promise.resolve(X):X}if(Q)return Promise.reject(J);throw J}}},Z0=new y6;function a($,Q){return Z0.parse($,Q)}a.options=a.setOptions=function($){return Z0.setOptions($),a.defaults=Z0.defaults,c5(a.defaults),a};a.getDefaults=p2;a.defaults=G0;a.use=function(...$){return Z0.use(...$),a.defaults=Z0.defaults,c5(a.defaults),a};a.walkTokens=function($,Q){return Z0.walkTokens($,Q)};a.parseInline=Z0.parseInline;a.Parser=b1;a.parser=b1.parse;a.Renderer=U2;a.TextRenderer=s2;a.Lexer=C1;a.lexer=C1.lex;a.Tokenizer=G2;a.Hooks=R0;a.parse=a;var{options:s8,setOptions:t8,use:n8,walkTokens:e8,parseInline:$9}=a;var Q9=b1.parse,J9=C1.lex;import{SessionContext as k4,ActiveViewCtx as d8}from"#canvas/runtime";import{useState as z0,useCallback as y1,useEffect as _3,useRef as H3,useMemo as W3}from"react";import{AnnotationCtx as m6}from"#canvas/runtime";function D1($,Q,J="current"){let X=`canvas:${$}:rev:${Q}`;return J==="next"?`${X}:next-draft`:X}function L0($,Q){return`${D1($,Q)}:draft-handled`}function U0($,Q,J){try{$.removeItem(D1(Q,J)),$.removeItem(L0(Q,J))}catch{}}function t2($){if(!$)return null;try{let Q=JSON.parse($);return typeof Q==="object"&&Q!==null&&!Array.isArray(Q)?Q:null}catch{return null}}function S6($){if(!Array.isArray($)||$.length<2)return!1;let Q=$[1];if(typeof Q!=="object"||Q===null||Array.isArray(Q))return!1;let J=Reflect.get(Q,"note");if(typeof J==="string"&&J.trim().length>0)return!0;let X=Reflect.get(Q,"value");if(typeof X==="string")return X.trim().length>0;if(Array.isArray(X))return X.length>0;return X!==null&&X!==void 0}function n2($){if(!$)return!1;let Q=Reflect.get($,"annotations");if(Array.isArray(Q)&&Q.length>0)return!0;let J=Reflect.get($,"generalNote");if(typeof J==="string"&&J.trim().length>0)return!0;let X=Reflect.get($,"responses");return Array.isArray(X)&&X.some(S6)}function _2($,Q,J,X){try{let Y=D1(Q,J);if(n2(t2($.getItem(Y))))return $.setItem(L0(Q,J),"1"),null;if($.getItem(L0(Q,J))!==null)return null;let Z=X.filter((q)=>q.revision<J).sort((q,U)=>U.revision-q.revision);for(let q of Z){if(q.hasFeedback){let G=D1(Q,q.revision,"next"),K=t2($.getItem(G));if(!n2(K))return null;return $.setItem(Y,JSON.stringify({...K,feedbackEntries:[]})),$.setItem(L0(Q,J),"1"),$.removeItem(G),q.revision}let U=t2($.getItem(D1(Q,q.revision)));if(!n2(U)){if($.getItem(L0(Q,q.revision))!==null)return null;continue}return $.setItem(Y,JSON.stringify({...U,feedbackEntries:[]})),$.setItem(L0(Q,J),"1"),q.revision}}catch{}return null}function i1($,Q){let J=[],X=$3($);for(let Y of X){let Z=document.createRange();if(Z.selectNodeContents(Y),Y===$.startContainer)Z.setStart(Y,$.startOffset);if(Y===$.endContainer)Z.setEnd(Y,$.endOffset);let q=Z.toString();if(!q||!q.trim())continue;let U=document.createElement("mark");U.setAttribute("data-annotation-id",Q);try{Z.surroundContents(U)}catch{let G=Z.extractContents();U.appendChild(G),Z.insertNode(U)}J.push(U)}return J}function m0($){let Q=$.parentElement;if(Q?.classList.contains("select-none"))return!1;if(Q?.closest("[data-annotation-id]"))return!1;return!0}function $3($){let Q=[],J=$.commonAncestorContainer;if(J.nodeType===Node.TEXT_NODE)return Q.push(J),Q;let X=document.createTreeWalker(J,NodeFilter.SHOW_TEXT),Y;while(Y=X.nextNode()){if(!m0(Y))continue;if($.intersectsNode(Y))Q.push(Y)}return Q}function A6($,Q){let J=document.createRange();if(J.selectNodeContents($),$===Q.startContainer)J.setStart($,Q.startOffset);if($===Q.endContainer)J.setEnd($,Q.endOffset);return J.toString()}function Q3($){let Q="";for(let J of $3($))Q+=A6(J,$);return Q}function M0($,Q){let J=document.querySelectorAll(`[data-annotation-id="${$}"]`);for(let X of J)X.classList.toggle("mark-active",Q)}function E0($,Q){if(Q!=null&&Q!==$)M0(Q,!1);if($!=null)M0($,!0)}function x0($,Q){let J=document.querySelectorAll(`[data-annotation-id="${$}"]`);for(let X of J)X.setAttribute("data-annotation-id",Q)}function f0($,Q){for(let J of Q){if($.querySelector(`[data-annotation-id="${J.id}"]`))continue;let X=J.snippet;if(!X)continue;let{fullText:Y,textNodes:Z}=w6($),q=[],U=0;while(!0){let N=Y.indexOf(X,U);if(N===-1)break;q.push(N),U=N+1}let[G]=q;if(G===void 0)continue;let K=G;if(q.length>1&&J.context){let N=-1;for(let O of q){let B=0;if(J.context.before){let A=Y.slice(Math.max(0,O-80),O);if(A.includes(J.context.before))B+=2;else if(J.context.before.length>10&&A.includes(J.context.before.slice(-10)))B+=1}if(J.context.after){let A=Y.slice(O+X.length,O+X.length+80);if(A.includes(J.context.after))B+=2;else if(J.context.after.length>10&&A.includes(J.context.after.slice(0,10)))B+=1}if(B>N)N=B,K=O}}let _=K,z=K+X.length,W=e5(Z,_),H=e5(Z,z);if(!W||!H)continue;try{let N=document.createRange();N.setStart(W.node,W.offset),N.setEnd(H.node,H.offset),i1(N,J.id)}catch{}}}function w6($){let Q=[],J="",X=document.createTreeWalker($,NodeFilter.SHOW_TEXT),Y;while(Y=X.nextNode()){if(!m0(Y))continue;Q.push({node:Y,start:J.length}),J+=Y.textContent||""}return{fullText:J,textNodes:Q}}function e5($,Q){for(let J=$.length-1;J>=0;J--){let X=$[J];if(!X||X.start>Q)continue;let Y=Q-X.start,Z=X.node.textContent?.length??0;if(Y<=Z)return{node:X.node,offset:Y}}return null}function v0($){let Q=document.querySelectorAll(`[data-annotation-id="${$}"]`);for(let J of Q){let X=J.parentNode;if(!X)continue;if(J.tagName!=="MARK"){X.removeChild(J);continue}while(J.firstChild)X.insertBefore(J.firstChild,J);X.removeChild(J),X.normalize()}}function o1($,Q){let J=J3($,"before",60),X=J3($,"after",60),Y=b6($.startContainer,Q);return{before:J,after:X,hierarchy:Y}}function J3($,Q,J){let X=C6(Q==="before"?$.startContainer:$.endContainer);if(!X)return"";let Y="";if(Q==="before"){let Z=document.createTreeWalker(X,NodeFilter.SHOW_TEXT),q;while(q=Z.nextNode()){if(q===$.startContainer){Y+=(q.textContent||"").slice(0,$.startOffset);break}if(!m0(q))continue;Y+=q.textContent||""}if(Y.length>J){Y=Y.slice(-J);let U=Y.indexOf(" ");if(U>0)Y=Y.slice(U+1)}}else{let Z=document.createTreeWalker(X,NodeFilter.SHOW_TEXT),q=!1,U;while(U=Z.nextNode()){if(U===$.endContainer){Y+=(U.textContent||"").slice($.endOffset),q=!0;continue}if(q){if(!m0(U))continue;Y+=U.textContent||""}}if(Y.length>J){Y=Y.slice(0,J);let G=Y.lastIndexOf(" ");if(G>0)Y=Y.slice(0,G)}}return Y.trim()}function C6($){let Q=new Set(["DIV","P","LI","PRE","BLOCKQUOTE","SECTION","ARTICLE"]),J=$.parentElement;while(J){if(Q.has(J.tagName))return J;J=J.parentElement}return null}function b6($,Q){let J=[],X=$ instanceof Element?$:$.parentElement;while(X&&X!==Q){let Y=X.getAttribute?.("data-task-id");if(Y){let q=X.querySelector(".font-semibold");if(q)J.unshift(q.textContent?.trim()||Y)}let Z=I6(X);if(Z)J.unshift(Z);X=X.parentElement}return J}function I6($){if($.getAttribute("data-md")==="section"){let J=$.getAttribute("data-md-title");if(J)return J}if($.tagName!=="DIV")return null;return $.querySelector(":scope > button > .font-heading, :scope > div > .font-heading")?.textContent?.trim()||null}function H2($){let Q=$.snippet.trim(),J=$.context,X=Q.length<30;if(J&&X&&(J.before||J.after)){let Y=[];if(J.before)Y.push(`...${J.before} `);if(Y.push(`**${Q}**`),J.after)Y.push(` ${J.after}...`);return Y.join("")}return Q}function u0($){return{kind:$.kind,owns:(Q)=>$.parse(Q)!==null,find:(Q,J)=>{let X=$.parse(Q);return X===null?null:$.find(X,J)},restore:(Q,J)=>{let X=$.parse(J.snippet);if(X===null)return;$.restore?.(X,Q,J)},describe:(Q)=>{let J=$.parse(Q);if(J===null||!$.describe)return null;return $.describe(J)}}}function Y3($){let Q=document.createTreeWalker($,NodeFilter.SHOW_TEXT),J="";for(let X=Q.nextNode();X;X=Q.nextNode()){let Y=X.parentElement?.closest("[aria-hidden='true']");if(Y&&$.contains(Y))continue;J+=X.textContent??""}return J.trim()}function W2($,Q,J){return{selector:$,snippet:(X)=>{let Y=X.getAttribute(J);return Y?`${Q} ${Y}`:null}}}var e2=[W2("[data-md='item']","[Item]","data-md-label"),W2("[data-md='section']","[Section]","data-md-title"),W2("[data-md='checklist-item']","[Checklist]","data-md-label"),W2("[data-md='image']","[Image]","data-md-src"),{selector:"[data-md='callout']",snippet:($)=>{return`[Callout:${$.getAttribute("data-md-type")||"info"}] ${Y3($).slice(0,60)||"Callout"}`}},{selector:"[data-md='note']",snippet:($)=>`[Note] ${Y3($).slice(0,60)||"Note"}`},{selector:"[data-md='table'] tbody tr",snippet:($)=>{let Q=Array.from($.querySelectorAll("td")).map((J)=>J.textContent?.trim()).filter(Boolean);return Q.length?`[Row] ${Q.join(" | ")}`:null}}],j6=["[data-md='choice-option']","[data-md='multichoice-option']","[data-md='userinput']","[data-md='rangeinput']"],a1=e2.map(($)=>$.selector).join(", "),P0=[...e2.map(($)=>$.selector),...j6].join(", ");function m1($){for(let Q of e2)if($.matches(Q.selector))return Q.snippet($);return null}var $5={kind:"block",parse:($)=>$.startsWith("[")?{snippet:$}:null,format:($)=>$.snippet,find:($,Q)=>{for(let J of Q.querySelectorAll(a1)){if(!(J instanceof HTMLElement))continue;if(m1(J)===$.snippet)return J}return null}};var J5="data-annotation-image",V6=/^\[Region:(rect|ellipse)\] ([\s\S]+) @(0|[1-9]\d*),(0|[1-9]\d*),(0|[1-9]\d*),(0|[1-9]\d*)$/;function k6($){if($==="rect")return"rect";if($==="ellipse")return"ellipse";return null}function N2($){if($===void 0)return null;let Q=Number($);if(!Number.isInteger(Q)||Q<0||Q>1e4)return null;return Q}function X3($){return Math.min(1e4,Math.max(0,$))}function Y5($,Q,J){if(!($.width>0)||!($.height>0))return null;return{x:X3(Math.round(Q/$.width*1e4)),y:X3(Math.round(J/$.height*1e4))}}function T2($,Q){let J=Math.min($.x,Q.x),X=Math.min($.y,Q.y);return{x:J,y:X,w:Math.min(1e4-J,Math.abs($.x-Q.x)),h:Math.min(1e4-X,Math.abs($.y-Q.y))}}function X5($){return $.w>=30&&$.h>=30}function q3($){return{left:`${$.x/100}%`,top:`${$.y/100}%`,width:`${$.w/100}%`,height:`${$.h/100}%`}}function B2($){return`${($/100).toFixed(1).replace(/\.0$/,"")}%`}function F2($){let Q=`${B2($.x)}-${B2($.x+$.w)}`,J=`${B2($.y)}-${B2($.y+$.h)}`;return`[Region] ${$.src} — ${$.shape} x ${Q}, y ${J} of the image`}function Q5($,Q){for(let J of Q.querySelectorAll("[data-md='image']")){if(!(J instanceof HTMLElement))continue;if(J.getAttribute("data-md-src")!==$)continue;let X=J.querySelector("[data-annotation-image]");if(X instanceof HTMLElement)return X}return null}function O2($,Q){let J=q3(Q);$.style.left=J.left,$.style.top=J.top,$.style.width=J.width,$.style.height=J.height}function L2($,Q,J){let X=document.createElement("div");return X.className="ann-region",X.setAttribute("data-annotation-id",J),X.setAttribute("data-annotation-region",Q),O2(X,$),X}var g0={kind:"region",parse:($)=>{let Q=V6.exec($);if(!Q)return null;let J=k6(Q[1]),X=Q[2],Y=N2(Q[3]),Z=N2(Q[4]),q=N2(Q[5]),U=N2(Q[6]);if(J===null||X===void 0)return null;if(Y===null||Z===null||q===null||U===null)return null;if(q<1||U<1)return null;return{src:X,shape:J,x:Y,y:Z,w:q,h:U}},format:($)=>`[Region:${$.shape}] ${$.src} @${$.x},${$.y},${$.w},${$.h}`,find:($,Q)=>Q5($.src,Q),restore:($,Q,J)=>{if(Q.querySelector(`[data-annotation-id="${J.id}"]`))return;let X=Q5($.src,Q);if(!X)return;X.appendChild(L2($,$.shape,J.id))},describe:F2};var q5={kind:"text",parse:($)=>$?{text:$}:null,format:($)=>$.text,find:()=>null,restore:($,Q,J)=>{f0(Q,[J])}};var I1="__agent-response__";function K0($){return $.filePath&&$.filePath!=="__agent-response__"?$.filePath:void 0}function h0($){return $.uploadUrl!==null}function O1(){return`ann-${Date.now()}-${Math.random().toString(36).slice(2,6)}`}function s1($,Q){$.style.height="auto",$.style.height=(Q?Math.max(Q,$.scrollHeight):$.scrollHeight)+"px"}var M2=[u0(g0),u0($5),u0(q5)];function G3($,Q){for(let J of M2){let X=J.find($,Q);if(X)return X}return null}function Z5($,Q){for(let J of Q){if(!J.snippet)continue;for(let X of M2)X.restore($,J)}}function c0($){for(let Q of M2){let J=Q.describe($);if(J!==null)return J}return $}function p0($){let Q=document.querySelector(`[data-annotation-id="${$.id}"]`);if(Q instanceof HTMLElement)return Q;let J=$.canvasFile?document.querySelector(`[data-canvas-file="${$.canvasFile}"]`):document;if(!J)return null;return G3($.snippet,J)}function Z3($){$.classList.remove("ann-flash"),$.offsetWidth,$.classList.add("ann-flash"),$.addEventListener("animationend",()=>{$.classList.remove("ann-flash")},{once:!0})}function G5($,Q){let J=K0($);if(J)Q({type:"file",path:J}),setTimeout(()=>{let X=p0($);if(X)X.scrollIntoView({behavior:"smooth",block:"center"}),Z3(X)},150);else{let X=p0($);if(X)X.scrollIntoView({behavior:"smooth",block:"center"}),Z3(X)}}function d0($){let Q=[],J=$.snippet.trim(),X=$.context,Y=c0(J);if(Y!==J)Q.push(`> ${Y}`);else if($.filePath&&X&&X.lineStart!=null){let U=X.lineStart,G=X.lineEnd??U,K=J.split(`
60
+ `);if(J.length<30&&U===G&&(X.before||X.after)){let z=H2($);Q.push(`> L${U}: ${z}`)}else if(K.length<=6)for(let z=0;z<K.length;z++)Q.push(`> ${U+z} | ${K[z]}`);else{for(let z=0;z<3;z++)Q.push(`> ${U+z} | ${K[z]}`);Q.push(`> ... (${K.length} lines)`);for(let z=K.length-3;z<K.length;z++)Q.push(`> ${U+z} | ${K[z]}`)}}else{let U=H2($);if(J.split(`
61
+ `).length<=3)Q.push(`> ${U.split(`
65
62
  `).join(`
66
- > `)}`);else{let X=q.split(`
67
- `);$.push(`> ${X[0]}`),$.push(`> ... (${X.length} lines)`),$.push(`> ${X[X.length-1]}`)}}if(Z.note.trim())$.push(""),$.push(Z.note.trim());if(Z.images?.length){$.push("");for(let Y of Z.images)$.push(`![screenshot](${Y})`)}return $.push(""),$.join(`
68
- `)}function H4(Z){let $={label:"",annotations:[],children:new Map};for(let q of Z){let Q=q.context?.hierarchy||[],J=$;for(let Y of Q){if(!J.children.has(Y))J.children.set(Y,{label:Y,annotations:[],children:new Map});J=J.children.get(Y)}J.annotations.push(q)}return $}function p3(Z,$=0){let q=[];for(let Q of Z.annotations)q.push(x2(Q));for(let[,Q]of Z.children){let J=$===0?"###":"####";q.push(`${J} ${Q.label}`),q.push(""),q.push(p3(Q,$+1))}return q.join(`
69
- `)}import{SessionContext as i3}from"#canvas/runtime";import{useEffect as c3,useState as A0,useRef as W4,useMemo as u2}from"react";import{jsxDEV as Q1}from"react/jsx-dev-runtime";function d3({open:Z,onClose:$,onSubmit:q,includedRemoteIds:Q,onToggleRemoteId:J}){let{annotations:Y,generalNote:X,responses:G,feedbackEntries:z}=X1(),[_,H]=A0(""),[U,W]=A0(!1),[T,K]=A0(!1),[L,N]=A0(null),y=W4(null),[O,R]=A0(!1),S=u2(()=>Y.filter((C)=>C.source==="remote"),[Y]);if(Z&&!O)W(!1),K(!1),N(null);if(!Z&&O)W(!1),K(!1),N(null);if(Z!==O)R(Z);let M=u2(()=>w0(Y,X,G,z,Q),[Y,X,G,z,Q]),b=U?_:M;if(c3(()=>{if(Z&&T&&y.current)y.current.focus()},[Z,T]),c3(()=>{if(!Z)return;let C=(p)=>{if(p.key==="Escape")$()};return window.addEventListener("keydown",C),()=>window.removeEventListener("keydown",C)},[Z,$]),!Z)return null;let g=b.trim().length>0;return Q1("div",{className:"fixed inset-0 z-50 bg-black/50 backdrop-blur-sm flex items-center justify-center p-8",onClick:$,children:Q1("div",{className:"bg-bg-surface border border-border-medium rounded-xl shadow-lg w-full max-w-2xl flex flex-col",style:{height:"80vh"},onClick:(C)=>C.stopPropagation(),children:[Q1("div",{className:"flex items-center justify-between px-5 py-3 border-b border-border-subtle flex-shrink-0",children:[Q1("div",{className:"flex items-center gap-3",children:[Q1("span",{className:"text-[13px] font-medium text-text-primary font-body",children:"Response preview"},void 0,!1,void 0,this),U&&Q1("button",{onClick:()=>{W(!1),K(!1)},className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body",children:"Reset"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Q1("div",{className:"flex items-center gap-2",children:[Q1("div",{className:"flex items-center bg-bg-base rounded-md p-0.5",children:[Q1("button",{onClick:()=>K(!1),className:`px-2.5 py-1 rounded text-[11px] font-body font-medium transition-colors ${!T?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Preview"},void 0,!1,void 0,this),Q1("button",{onClick:()=>K(!0),className:`px-2.5 py-1 rounded text-[11px] font-body font-medium transition-colors ${T?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Edit"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Q1("button",{onClick:$,className:"text-text-tertiary hover:text-text-secondary w-7 h-7 flex items-center justify-center rounded-md hover:bg-border-subtle transition-colors",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),T?Q1("textarea",{ref:y,value:b,onChange:(C)=>{H(C.target.value),W(!0)},className:"flex-1 w-full bg-bg-base p-5 text-[13px] font-mono text-text-code resize-none focus:outline-none leading-relaxed placeholder:text-text-disabled",placeholder:"Your feedback will appear here..."},void 0,!1,void 0,this):Q1("div",{className:"flex-1 overflow-y-auto p-5",children:Q1($2,{text:b},void 0,!1,void 0,this)},void 0,!1,void 0,this),S.length>0&&Q1("div",{className:"px-5 py-2 border-t border-border-subtle flex-shrink-0",children:Q1("span",{className:"text-[12px] text-text-secondary font-body",children:["Reviewer feedback: ",Q.size,"/",S.length," included"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),L&&Q1("div",{className:"px-5 py-2 text-[12px] text-accent-red font-body border-t border-border-subtle flex-shrink-0 flex items-center justify-between gap-2",children:[Q1("span",{children:L},void 0,!1,void 0,this),Q1("button",{onClick:()=>{N(null),q(b)},className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body whitespace-nowrap underline",children:"Submit anyway"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Q1("div",{className:"flex justify-end gap-2 px-5 py-3 border-t border-border-subtle flex-shrink-0",children:[Q1("button",{onClick:$,className:"px-4 py-2 rounded-lg text-[13px] font-body text-text-tertiary hover:text-text-secondary transition-colors",children:"Cancel"},void 0,!1,void 0,this),Q1("button",{onClick:()=>{let C=e0(G,z);if(C.length>0){N(`Please answer: ${C.join(", ")}`);return}N(null),q(b)},disabled:!g,className:`px-6 py-2 rounded-lg font-body text-[13px] font-medium transition-all ${g?"bg-btn-primary text-btn-primary-text hover:opacity-90":"bg-bg-input text-text-disabled cursor-default"}`,children:"Submit feedback"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}var T4=/!\[([^\]]*)\]\((\/tmp\/agent-canvas\/uploads\/([^)]+))\)/g;function N4(Z){return Z.replace(T4,($,q,Q,J)=>`![${q}](/api/uploads/${J})`)}function $2({text:Z}){let $=u2(()=>e.parse(N4(Z),{async:!1}),[Z]);return Q1("div",{className:"prose-canvas font-body text-body text-text-primary leading-relaxed",dangerouslySetInnerHTML:{__html:$}},void 0,!1,void 0,this)}import{jsxDEV as $0}from"react/jsx-dev-runtime";var O4={ts:"#3178c6",tsx:"#3178c6",js:"#e8a32e",jsx:"#4ba0c8",html:"#e34c26",css:"#264de4",scss:"#c69",json:"#7a7568",yaml:"#cb171e",yml:"#cb171e",toml:"#9c4221",rs:"#dea584",go:"#00add8",c:"#6a6a6a",cpp:"#f34b7d",h:"#6a6a6a",py:"#3572a5",rb:"#cc342d",sh:"#5a8c3c",bash:"#5a8c3c",md:"#3573b5",txt:"#6b6560",lock:"#6b6560",gitignore:"#6b6560",svg:"#d9952e",png:"#6a9c2e",jpg:"#6a9c2e",gif:"#6a9c2e"},F4={ts:"TS",tsx:"TX",js:"JS",jsx:"JX",py:"PY",rs:"RS",go:"GO",rb:"RB",json:"{}",yaml:"YM",yml:"YM",toml:"TM",html:"<>",css:"#",scss:"#",md:"M↓",sh:"$",bash:"$",c:"C",cpp:"C+",h:"H",svg:"◇",png:"▣",jpg:"▣"};function g1({name:Z,type:$,expanded:q,className:Q=""}){if($==="dir")return $0("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",className:`flex-shrink-0 ${Q}`,children:q?$0("path",{d:"M1.5 3.5h5l1.5 1.5h6.5v8h-13z",style:{fill:"var(--color-folder-fill-active)",stroke:"var(--color-folder-stroke-active)"},strokeWidth:"1"},void 0,!1,void 0,this):$0("path",{d:"M1.5 3.5h5l1.5 1.5h6.5v8h-13z",style:{fill:"var(--color-folder-fill)",stroke:"var(--color-folder-stroke)"},strokeWidth:"1"},void 0,!1,void 0,this)},void 0,!1,void 0,this);let J=Z.includes(".")?Z.split(".").pop().toLowerCase():"",Y=O4[J]||"#6b6560",X=F4[J];return $0("svg",{width:"14",height:"14",viewBox:"0 0 16 16",className:`flex-shrink-0 ${Q}`,children:[$0("path",{d:"M2 1.5h8l3.5 3.5v9.5a1 1 0 01-1 1H3a1 1 0 01-1-1v-12a1 1 0 011-1z",fill:Y,opacity:"0.85"},void 0,!1,void 0,this),$0("path",{d:"M10 1.5v2.5a1 1 0 001 1h2.5",fill:"none",stroke:"white",strokeWidth:"0.5",opacity:"0.5"},void 0,!1,void 0,this),X&&$0("text",{x:"8",y:"11.5",textAnchor:"middle",fill:"white",fontSize:"5.5",fontFamily:"monospace",fontWeight:"600",children:X},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function B4(Z){let $=Z.getAttribute("data-md");if($==="item"){let q=Z.getAttribute("data-md-label");return q?`[Item] ${q}`:null}if($==="section"){let q=Z.getAttribute("data-md-title");return q?`[Section] ${q}`:null}if($==="callout"){let q=Z.getAttribute("data-md-type")||"info",Q=Z.textContent?.trim().slice(0,60)||"Callout";return`[Callout:${q}] ${Q}`}if($==="note")return`[Note] ${Z.textContent?.trim().slice(0,60)||"Note"}`;if(Z.tagName==="TR"){let q=Array.from(Z.querySelectorAll("td")).map((Q)=>Q.textContent?.trim()).filter(Boolean);return q.length?`[Row] ${q.join(" | ")}`:null}if($==="checklist-item"){let q=Z.getAttribute("data-md-label");return q?`[Checklist] ${q}`:null}if($==="choice-option"||$==="multichoice-option"){let q=Z.getAttribute("data-md-label");return q?`[Option] ${q}`:null}if($==="userinput"){let q=Z.getAttribute("data-md-label");return q?`[Input] ${q}`:null}if($==="rangeinput"){let q=Z.getAttribute("data-md-label");return q?`[Range] ${q}`:null}if($==="image"){let q=Z.getAttribute("data-md-src");return q?`[Image] ${q}`:null}return null}function C0(Z){let $=document.querySelector(`[data-annotation-id="${Z.id}"]`);if($)return $;if(Z.snippet.startsWith("[")){for(let q of document.querySelectorAll("[data-md='item'], [data-md='section'], [data-md='table'] tbody tr, [data-md='callout'], [data-md='note'], [data-md='checklist-item'], [data-md='image']"))if(B4(q)===Z.snippet)return q}return null}function l3(Z){Z.classList.remove("ann-flash"),Z.offsetWidth,Z.classList.add("ann-flash"),Z.addEventListener("animationend",()=>{Z.classList.remove("ann-flash")},{once:!0})}function g2(Z,$){if(Z.filePath)$({type:"file",path:Z.filePath}),setTimeout(()=>{let q=C0(Z);if(q)q.scrollIntoView({behavior:"smooth",block:"center"}),l3(q)},150);else{let q=C0(Z);if(q)q.scrollIntoView({behavior:"smooth",block:"center"}),l3(q)}}import{jsxDEV as P,Fragment as Z2}from"react/jsx-dev-runtime";function v2({onSubmit:Z,collapseButton:$}){let{isReadOnly:q,selectedRevision:Q,currentRevision:J,revisions:Y,agentWatching:X}=J2(A1),G=J2(i3),z=Y.find((W)=>W.revision===Q),_=q&&Q===J,H=!!z?.feedbackConsumed,U=z?.label||`Round ${Q}`;if(q)return P(y4,{sessionId:G,revision:Q,label:U,waitingForUpdate:_,feedbackConsumed:H,agentWatching:X,collapseButton:$},void 0,!1,void 0,this);return P(j4,{onSubmit:Z,agentWatching:X,collapseButton:$},void 0,!1,void 0,this)}function P4({sessionId:Z,revision:$,label:q,waitingForUpdate:Q,feedbackConsumed:J,agentWatching:Y,collapseButton:X}){let G=$1.isShared,[z,_]=f1(null),[H,U]=f1(!0);return q2(()=>{if(U(!0),!M1){_(null),U(!1);return}fetch(`/api/session/${Z}/revision/${$}/feedback`).then((W)=>W.json()).then((W)=>{_(W.feedback||null),U(!1)}).catch(()=>{_(null),U(!1)})},[Z,$]),P("div",{className:"flex flex-col h-full",children:[P("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[P("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:Q?"Feedback sent":`Feedback — ${q}`},void 0,!1,void 0,this),X]},void 0,!0,void 0,this),Q&&!G&&P(a3,{feedbackConsumed:J,agentWatching:Y},void 0,!1,void 0,this),P("div",{className:"flex-1 overflow-y-auto px-4",children:H?P("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"Loading..."},void 0,!1,void 0,this):z?P($2,{text:z},void 0,!1,void 0,this):P("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"No feedback was submitted for this revision."},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function a3({feedbackConsumed:Z,agentWatching:$}){if(Z)return P("div",{className:"mx-4 mb-3 px-3 py-2.5 rounded-lg bg-accent-green-muted flex items-center gap-2 flex-shrink-0",children:[P("span",{className:"w-2 h-2 rounded-full bg-accent-green animate-pulse"},void 0,!1,void 0,this),P("span",{className:"text-[12px] font-body text-accent-green",children:"Feedback received — waiting for next revision..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if($)return P("div",{className:"mx-4 mb-3 px-3 py-2.5 rounded-lg bg-accent-blue-muted flex items-center gap-2 flex-shrink-0",children:[P("span",{className:"w-2 h-2 rounded-full bg-accent-blue animate-pulse"},void 0,!1,void 0,this),P("span",{className:"text-[12px] font-body text-accent-blue",children:"Waiting for agent to pick up feedback..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return P("div",{className:"mx-4 mb-3 px-3 py-2.5 rounded-lg bg-accent-amber-muted flex items-center gap-2 flex-shrink-0",children:[P("span",{className:"w-2 h-2 rounded-full bg-accent-amber"},void 0,!1,void 0,this),P("span",{className:"text-[12px] font-body text-accent-amber",children:"Agent disconnected — tell Claude to check feedback"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function y4({sessionId:Z,revision:$,label:q,waitingForUpdate:Q,feedbackConsumed:J,agentWatching:Y,collapseButton:X}){let{annotations:G,generalNote:z,activeAnnotationId:_,setActiveAnnotationId:H}=X1(),{setActiveView:U}=J2(D1),W=G.length>0||z.trim().length>0,[T,K]=f1("feedback");if(!W)return P(P4,{sessionId:Z,revision:$,label:q,waitingForUpdate:Q,feedbackConsumed:J,agentWatching:Y,collapseButton:X},void 0,!1,void 0,this);return P("div",{className:"flex flex-col h-full",children:[P("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[P("div",{className:"flex items-center gap-1 bg-bg-input rounded-md p-0.5",children:[P("button",{onClick:()=>K("feedback"),className:`px-2.5 py-1 rounded text-[11px] font-medium font-body transition-colors ${T==="feedback"?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Feedback"},void 0,!1,void 0,this),P("button",{onClick:()=>K("annotations"),className:`px-2.5 py-1 rounded text-[11px] font-medium font-body transition-colors flex items-center gap-1.5 ${T==="annotations"?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:["Annotations",P("span",{className:"inline-flex items-center justify-center min-w-[16px] h-[16px] px-1 rounded-full bg-border-subtle text-[10px] font-medium",children:G.length},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),X]},void 0,!0,void 0,this),Q&&P(a3,{feedbackConsumed:J,agentWatching:Y},void 0,!1,void 0,this),T==="feedback"?P(S4,{sessionId:Z,revision:$},void 0,!1,void 0,this):P(b4,{annotations:G,generalNote:z,activeAnnotationId:_,setActiveAnnotationId:H,setActiveView:U},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function S4({sessionId:Z,revision:$}){let[q,Q]=f1(null),[J,Y]=f1(!0);return q2(()=>{if(Y(!0),!M1){Q(null),Y(!1);return}fetch(`/api/session/${Z}/revision/${$}/feedback`).then((X)=>X.json()).then((X)=>{Q(X.feedback||null),Y(!1)}).catch(()=>{Q(null),Y(!1)})},[Z,$]),P("div",{className:"flex-1 overflow-y-auto px-4",children:J?P("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"Loading..."},void 0,!1,void 0,this):q?P($2,{text:q},void 0,!1,void 0,this):P("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"No feedback was submitted for this revision."},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function b4({annotations:Z,generalNote:$,activeAnnotationId:q,setActiveAnnotationId:Q,setActiveView:J}){let Y=Z.filter((K)=>K.filePath===T1),X=Z.filter((K)=>!K.filePath),G=Z.filter((K)=>K.filePath&&K.filePath!==T1),z={};for(let K of G){let L=K.filePath;if(!z[L])z[L]=[];z[L].push(K)}let _=(K)=>{Q(K),a1(K,!0)},H=(K)=>{Q(null),a1(K,!1)},U=(K)=>{if(K.id===q)Q(null);else if(Q(K.id),K.filePath)J({type:"file",path:K.filePath}),setTimeout(()=>{let L=C0(K);if(L)L.scrollIntoView({behavior:"smooth",block:"center"})},150)},W=(K)=>P("div",{className:`group/ann relative px-3 py-2.5 transition-colors duration-150 cursor-pointer ${q===K.id?"bg-highlight-selected":"odd:bg-bg-elevated-half hover:bg-bg-input"}`,onMouseEnter:()=>_(K.id),onMouseLeave:()=>H(K.id),onClick:()=>U(K),children:[P("div",{className:"text-[11px] text-text-tertiary italic line-clamp-2 mb-1.5 leading-snug font-body border-l-2 border-border-medium pl-2",children:K.snippet.length>80?K.snippet.slice(0,80)+"...":K.snippet},void 0,!1,void 0,this),K.note.trim()&&P("div",{className:"text-[13px] font-body text-text-primary leading-relaxed",children:K.note},void 0,!1,void 0,this),P(R3,{images:K.images||[]},void 0,!1,void 0,this),P("div",{className:"absolute top-1.5 right-1.5 opacity-0 group-hover/ann:opacity-100 transition-opacity duration-100",children:P("button",{onClick:(L)=>{L.stopPropagation(),g2(K,J)},className:"w-5 h-5 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-input transition-colors",title:"Scroll to annotation",children:P("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[P("circle",{cx:"12",cy:"12",r:"3"},void 0,!1,void 0,this),P("path",{d:"M12 2v4M12 18v4M2 12h4M18 12h4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},K.id,!0,void 0,this),T=[Y,X,G].filter((K)=>K.length>0).length>1;return P(Z2,{children:[P("div",{className:"flex-1 overflow-y-auto",children:[Y.length>0&&P(Z2,{children:[T&&P("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body px-3 mb-1 mt-1",children:"Agent Response"},void 0,!1,void 0,this),Y.map(W)]},void 0,!0,void 0,this),X.length>0&&P(Z2,{children:[T&&P("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body px-3 mb-1 mt-1",children:"Canvas"},void 0,!1,void 0,this),X.map(W)]},void 0,!0,void 0,this),Object.entries(z).map(([K,L])=>P("div",{children:[P("button",{onClick:()=>J({type:"file",path:K}),className:"flex items-center gap-1.5 text-[10px] uppercase tracking-widest text-text-tertiary hover:text-text-secondary font-body px-3 pt-3 pb-1 truncate transition-colors w-full text-left",title:K,children:[P(g1,{name:K.split("/").pop()||K,type:"file"},void 0,!1,void 0,this),P("span",{className:"truncate",children:K},void 0,!1,void 0,this)]},void 0,!0,void 0,this),L.map(W)]},K,!0,void 0,this))]},void 0,!0,void 0,this),$.trim()&&P("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:P("div",{className:"text-[13px] font-body text-text-primary leading-relaxed",children:$},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function j4({onSubmit:Z,agentWatching:$,collapseButton:q}){let[Q,J]=f1(!1),{annotations:Y,updateAnnotation:X,removeAnnotation:G,addAnnotationImage:z,removeAnnotationImage:_,generalNote:H,setGeneralNote:U,activeAnnotationId:W,setActiveAnnotationId:T,responses:K,feedbackEntries:L}=X1(),N=J2(i3),{setActiveView:y}=L4.useContext(D1),O=r3(null),R=r3(new Map),S=Y.filter((B)=>B.filePath===T1),M=Y.filter((B)=>!B.filePath),b=Y.filter((B)=>B.filePath&&B.filePath!==T1),g={};for(let B of b){let m=B.filePath;if(!g[m])g[m]=[];g[m].push(B)}q2(()=>{if(!W)return;let B=R.current.get(W);if(B)B.scrollIntoView({behavior:"smooth",block:"nearest"})},[W]);let C=f2((B)=>{T(B),a1(B,!0)},[T]),p=f2((B)=>{T(null),a1(B,!1)},[W]),h=M4(()=>Y.filter((B)=>B.source==="remote"),[Y]),[V,k]=f1(()=>new Set);q2(()=>{if(h.length===0)return;k((B)=>{let m=new Set(B);for(let u of h)m.add(u.id);return m.size===B.size?B:m})},[h]);let x=f2((B)=>{k((m)=>{let u=new Set(m);if(u.has(B))u.delete(B);else u.add(B);return u})},[]),l=Array.from(K.values()).some(m2),j=L.size>0,f=Y.length>0||H.trim().length>0||l||j,[v,o]=f1(null),w=(B)=>{let m=B.source==="remote";return P("div",{ref:(u)=>{if(u)R.current.set(B.id,u);else R.current.delete(B.id)},className:`group/ann relative px-3 py-2.5 transition-colors duration-150 ${W===B.id?"bg-highlight-selected":m?"bg-accent-purple-muted/30 hover:bg-accent-purple-muted/50":"odd:bg-bg-elevated-half hover:bg-bg-input"}`,onMouseEnter:()=>C(B.id),onMouseLeave:()=>p(B.id),onClick:()=>{if(B.id===W)T(null);else if(T(B.id),B.filePath)y({type:"file",path:B.filePath}),setTimeout(()=>{let u=C0(B);if(u)u.scrollIntoView({behavior:"smooth",block:"center"})},150)},children:[m&&B.author&&P("div",{className:"flex items-center gap-1.5 mb-1.5",children:[P("input",{type:"checkbox",checked:V.has(B.id),onChange:(u)=>{u.stopPropagation(),x(B.id)},onClick:(u)=>u.stopPropagation(),className:"accent-accent-purple flex-shrink-0",title:"Include in submission"},void 0,!1,void 0,this),P("span",{className:"inline-flex items-center justify-center w-4 h-4 rounded-full bg-accent-purple text-white text-[9px] font-medium uppercase",children:B.author.name.charAt(0)},void 0,!1,void 0,this),P("span",{className:"text-[11px] font-medium text-accent-purple font-body",children:B.author.name},void 0,!1,void 0,this),P("span",{className:"text-[10px] text-text-tertiary font-body uppercase tracking-widest",children:"Remote"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),P("div",{className:"text-[11px] text-text-tertiary italic line-clamp-2 mb-1.5 leading-snug font-body border-l-2 border-border-medium pl-2",children:B.snippet.length>80?B.snippet.slice(0,80)+"...":B.snippet},void 0,!1,void 0,this),m?P("div",{className:"text-[13px] font-body text-text-primary leading-relaxed whitespace-pre-wrap",children:B.note},void 0,!1,void 0,this):P("div",{onClick:(u)=>u.stopPropagation(),children:P(c0,{note:B.note,onNoteChange:(u)=>X(B.id,u),images:B.images||[],onAddImage:(u)=>z(B.id,u),onRemoveImage:(u)=>_(B.id,u),sessionId:N,autoResize:!0,minHeight:20,textareaClassName:"w-full bg-transparent text-[13px] font-body text-text-primary resize-none focus:outline-none leading-relaxed p-0 border-none min-h-[20px]",textareaStyle:{height:"auto",overflow:"hidden"},placeholder:"Add your note...",attachButton:"on-focus"},void 0,!1,void 0,this)},void 0,!1,void 0,this),P("div",{className:"absolute top-1.5 right-1.5 opacity-0 group-hover/ann:opacity-100 transition-opacity duration-100 flex items-center gap-0.5",children:[P("button",{onClick:(u)=>{u.stopPropagation(),g2(B,y)},className:"w-5 h-5 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-input transition-colors",title:"Scroll to annotation",children:P("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[P("circle",{cx:"12",cy:"12",r:"3"},void 0,!1,void 0,this),P("path",{d:"M12 2v4M12 18v4M2 12h4M18 12h4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),!m&&P("button",{onClick:(u)=>{u.stopPropagation(),G(B.id)},className:"w-5 h-5 flex items-center justify-center rounded text-text-tertiary hover:text-accent-red hover:bg-accent-red-muted transition-colors",title:"Delete annotation",children:P("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[P("polyline",{points:"3 6 5 6 21 6"},void 0,!1,void 0,this),P("path",{d:"M19 6v14a2 2 0 01-2 2H7a2 2 0 01-2-2V6m3 0V4a2 2 0 012-2h4a2 2 0 012 2v2"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},B.id,!0,void 0,this)};return P("div",{className:"flex flex-col h-full",children:[P("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[P("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body flex items-center gap-2",children:["Annotations",Y.length>0&&P("span",{className:"inline-flex items-center justify-center min-w-[18px] h-[18px] px-1 rounded-full bg-border-subtle text-[10px] font-medium text-text-secondary",children:Y.length},void 0,!1,void 0,this),!$1.isShared&&P("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${$?"bg-accent-green":"bg-accent-amber"}`,title:$?"Agent connected":"Agent disconnected"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),q]},void 0,!0,void 0,this),P("div",{ref:O,className:"flex-1 overflow-y-auto",children:[Y.length===0&&P("p",{className:"text-[12px] text-text-tertiary px-3 py-4 leading-relaxed font-body",children:"Select text in the canvas or in files to add annotations."},void 0,!1,void 0,this),S.length>0&&P(Z2,{children:[(M.length>0||b.length>0)&&P("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body px-3 mb-1 mt-1",children:"Agent Response"},void 0,!1,void 0,this),S.map(w)]},void 0,!0,void 0,this),M.length>0&&(S.length>0||b.length>0)&&P("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body px-3 mb-1 mt-1",children:"Canvas"},void 0,!1,void 0,this),M.map(w),Object.entries(g).map(([B,m])=>P("div",{children:[P("button",{onClick:()=>y({type:"file",path:B}),className:"flex items-center gap-1.5 text-[10px] uppercase tracking-widest text-text-tertiary hover:text-text-secondary font-body px-3 pt-3 pb-1 truncate transition-colors w-full text-left",title:B,children:[P(g1,{name:B.split("/").pop()||B,type:"file"},void 0,!1,void 0,this),P("span",{className:"truncate",children:B},void 0,!1,void 0,this)]},void 0,!0,void 0,this),m.map(w)]},B,!0,void 0,this))]},void 0,!0,void 0,this),P("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:P("textarea",{value:H,onChange:(B)=>U(B.target.value),className:"w-full bg-transparent text-[13px] font-body text-text-primary resize-none leading-relaxed p-0 border-none ring-0 shadow-none outline-none focus:outline-none focus:ring-0 focus:border-none placeholder:text-text-disabled min-h-[40px]",placeholder:"General notes...",onInput:(B)=>P0(B.target,40),ref:(B)=>{if(B)P0(B,40)}},void 0,!1,void 0,this)},void 0,!1,void 0,this),v&&P("div",{className:"px-4 py-2 text-[12px] text-accent-red font-body border-t border-border-subtle flex-shrink-0 flex items-center justify-between gap-2",children:[P("span",{children:v},void 0,!1,void 0,this),P("button",{onClick:()=>{o(null);let B=w0(Y,H,K,L,V);Z(B)},className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body whitespace-nowrap underline",children:"Submit anyway"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),P("div",{className:"px-4 py-3 border-t border-border-subtle flex-shrink-0",children:f?P("div",{className:"flex gap-2",children:[P("button",{onClick:()=>J(!0),className:"flex-1 py-2 rounded-lg font-body text-[13px] font-medium transition-all bg-border-subtle text-text-secondary hover:bg-border-medium hover:text-text-primary",children:"Preview"},void 0,!1,void 0,this),P("button",{onClick:()=>{let B=e0(K,L);if(B.length>0){o(`Please answer: ${B.join(", ")}`);return}o(null);let m=w0(Y,H,K,L,V);Z(m)},className:"flex-1 py-2 rounded-lg font-body text-[13px] font-medium transition-all bg-btn-primary text-btn-primary-text hover:opacity-90 hover:-translate-y-px shadow-sm",children:"Submit"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):P("button",{onClick:()=>Z("No feedback — looks good."),className:"w-full py-2 rounded-lg font-body text-[13px] font-medium border border-border-medium text-text-secondary hover:text-text-primary hover:border-border-hover hover:bg-bg-input transition-all",children:"Submit without feedback"},void 0,!1,void 0,this)},void 0,!1,void 0,this),P(d3,{open:Q,onClose:()=>J(!1),onSubmit:Z,includedRemoteIds:V,onToggleRemoteId:x},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{useEffect as w4,useState as o3,useContext as s3,useMemo as A4}from"react";import{SessionContext as C4}from"#canvas/runtime";import{jsxDEV as r,Fragment as h2}from"react/jsx-dev-runtime";function t3({embedded:Z}={}){let $=s3(C4),{annotations:q,addAnnotation:Q}=X1(),{setActiveView:J}=s3(D1),[Y,X]=o3(!1),[G,z]=o3({});if(!M1)return r("div",{className:Z?"px-4 py-3":"p-4",children:[r("div",{className:"text-[11px] uppercase tracking-widest text-text-tertiary font-body mb-2",children:"Files"},void 0,!1,void 0,this),r("p",{className:"text-[11px] text-text-tertiary font-body leading-relaxed",children:"File browsing is not available in shared view. File previews embedded in the canvas still work."},void 0,!1,void 0,this)]},void 0,!0,void 0,this);let{annCountMap:_,annotatedFiles:H}=A4(()=>{let O=new Map;for(let R of q)if(R.filePath&&R.filePath!==T1)O.set(R.filePath,(O.get(R.filePath)||0)+1);return{annCountMap:O,annotatedFiles:[...O.keys()]}},[q]),U=async(O)=>{let S=await(await fetch(`/api/tree?session=${$}&path=${encodeURIComponent(O)}`)).json();if(S.entries)z((M)=>({...M,[O]:{entries:S.entries,expanded:!0,loaded:!0}}))};w4(()=>{if(!Y&&!G[""])U("")},[Y]);let W=(O)=>{if(G[O]?.loaded)z((R)=>({...R,[O]:{...R[O],expanded:!R[O].expanded}}));else U(O)},T=(O)=>{J({type:"file",path:O})},K=async(O)=>{let S=await(await fetch(`/api/file?session=${$}&path=${encodeURIComponent(O)}`)).json();if(!S.error){let M=S.content.split(`
63
+ > `)}`);else{let G=J.split(`
64
+ `);Q.push(`> ${G[0]}`),Q.push(`> ... (${G.length} lines)`),Q.push(`> ${G[G.length-1]}`)}}if($.note.trim())Q.push(""),Q.push($.note.trim());let Z=[...$.images??[]],q=new Set(Z);for(let U of $.attachments??[]){if(q.has(U.url))continue;q.add(U.url),Z.push(U.url)}if(Z.length){Q.push("");for(let U of Z)Q.push(`![screenshot](${U})`)}return Q.push(""),Q.join(`
65
+ `)}function U5($,Q){let J=new Map;for(let[X,Y]of $)if(Q.has(X))J.set(X,Y);return J}function K5($,Q){if(!$||$.length===0)return!1;return $.every((J)=>Q.has(J))}function l0($,Q,J,X,Y){let Z=[],q=$.filter((H)=>H.source!=="remote"||Y&&Y.has(H.id)),U=q.filter((H)=>H.filePath===I1),G=q.filter((H)=>!H.filePath),K=q.filter((H)=>H.filePath&&H.filePath!==I1),_=J?Array.from(J.values()).filter((H)=>P2(H)):[],z=X?Array.from(X.values()).filter((H)=>H.markdown.trim()):[];if(_.length>0||z.length>0){Z.push("## Responses"),Z.push("");for(let H of _)Z.push(R6(H));for(let H of z)Z.push(H.markdown.trim()),Z.push("")}if(U.length>0){Z.push("## Annotations on agent response"),Z.push("");for(let H of U)Z.push(d0(H))}if(G.length>0){Z.push("## Canvas annotations"),Z.push("");let H=new Map;for(let B of G){let A=B.canvasFile||"";if(!H.has(A))H.set(A,[]);H.get(A).push(B)}let N=[...H.keys()].sort(),O=N.length>1||N.length===1&&N[0]!=="";for(let B of N){let A=H.get(B);if(O&&B)Z.push(`### ${B.replace(/\.jsx$/,"")}`),Z.push("");let T=D6(A);Z.push(z3(T))}}if(K.length>0){let H={};for(let N of K){let O=N.filePath;if(!H[O])H[O]=[];H[O].push(N)}Z.push("## File annotations"),Z.push("");for(let[N,O]of Object.entries(H)){Z.push(`### ${N}`),Z.push("");for(let B of O)Z.push(d0(B))}}if(Q.trim())Z.push("## General notes"),Z.push(""),Z.push(Q.trim()),Z.push("");return Z.join(`
66
+ `).trim()+`
67
+ `}function P2($){if($.note?.trim())return!0;if($.value===null||$.value===void 0)return!1;if($.type==="text"&&!$.value.trim())return!1;if($.type==="checkbox"&&$.value.length===0)return!1;return!0}function U3($){let Q=[];for(let J of $.values()){if(!J.required)continue;if(J.value===null||J.value===void 0){Q.push(J);continue}if(J.type==="text"&&!J.value.trim()){Q.push(J);continue}if(J.type==="checkbox"&&J.value.length===0){Q.push(J);continue}}return Q}function K3($){let Q=[];for(let J of $.values())if(J.required&&!J.markdown.trim())Q.push(J);return Q}function r0($,Q){let J=U3($),X=K3(Q);return[...J.map((Y)=>Y.label),...X.map((Y)=>Y.label||Y.id)]}function R6($){let Q=[];switch(Q.push(`**${$.label}**`),$.type){case"radio":case"select":Q.push(`Answer: ${$.value}`);break;case"checkbox":for(let J of $.value)Q.push(`- [x] ${J}`);break;case"text":Q.push(""),Q.push($.value.trim());break;case"range":Q.push(`Answer: ${$.value}`);break}if($.note?.trim())Q.push(""),Q.push(`Note: ${$.note.trim()}`);return Q.push(""),Q.join(`
68
+ `)}function D6($){let Q={label:"",annotations:[],children:new Map};for(let J of $){let X=J.context?.hierarchy||[],Y=Q;for(let Z of X){if(!Y.children.has(Z))Y.children.set(Z,{label:Z,annotations:[],children:new Map});Y=Y.children.get(Z)}Y.annotations.push(J)}return Q}function z3($,Q=0){let J=[];for(let X of $.annotations)J.push(d0(X));for(let[,X]of $.children){let Y=Q===0?"###":"####";J.push(`${Y} ${X.label}`),J.push(""),J.push(z3(X,Q+1))}return J.join(`
69
+ `)}import{useAnnotations as T1}from"#canvas/runtime";import{jsxDEV as f6}from"react/jsx-dev-runtime";function N3($,Q,J){try{let X=localStorage.getItem(D1($,Q,J));if(!X)return null;return JSON.parse(X)}catch{return null}}function E6($,Q,J,X){try{localStorage.setItem(D1($,Q,J),JSON.stringify(X))}catch{}}function z5($){return{draft:$,responseIds:new Set,canvases:new Set}}function _5({sessionId:$,revision:Q,isReadOnly:J,draftPhase:X,remoteAnnotations:Y,canvasFiles:Z,loadState:q,saveState:U,children:G}){let K=!!q,_=K?null:N3($,Q,X),[z,W]=z0(()=>(_?.annotations??[]).map((b)=>({...b,source:b.source??"local"}))),H=W3(()=>{if(!Y||Y.length===0)return z;let b=new Set(z.map((S)=>S.id)),P=Y.filter((S)=>!b.has(S.id));return[...z,...P.map((S)=>({...S,source:"remote"}))]},[z,Y]),[N,O]=z0(()=>_?.generalNote??""),[B,A]=z0(null),[T,M]=z0(()=>_?.responses?new Map(_.responses):new Map),y=`${$}:${Q}:${X}`,L=H3(y);L.current=y;let[w,j]=z0(()=>z5(y)),[k,m]=z0(()=>_?.feedbackEntries?new Map(_.feedbackEntries):new Map),[D,v]=z0(!K);_3(()=>{let b=(P)=>{W((P?.annotations??[]).map((S)=>({...S,source:S.source??"local"}))),O(P?.generalNote??""),M(P?.responses?new Map(P.responses):new Map),m(P?.feedbackEntries?new Map(P.feedbackEntries):new Map),A(null)};if(K){let P=!1;return v(!1),q($,Q,X).then((S)=>{if(P)return;b(S),v(!0)}),()=>{P=!0}}b(N3($,Q,X)),v(!0);return},[$,Q,X,K,q]);let u=H3(null);_3(()=>{if(J&&X!=="next")return;if(!D)return;if(u.current)clearTimeout(u.current);let b={annotations:z,generalNote:N,responses:Array.from(T.entries()),feedbackEntries:Array.from(k.entries())},P=()=>{if(U)U($,Q,b,X);else E6($,Q,X,b)};if(X==="next"){P();return}return u.current=setTimeout(P,300),()=>{if(u.current)clearTimeout(u.current)}},[z,N,T,k,$,Q,J,X,D,U]);let d=y1((b,P,S,V,i,Q1,U1)=>{W((P1)=>[...P1,{id:b,snippet:P,note:S,createdAt:new Date().toISOString(),filePath:V,context:i,...Q1?.length?{images:Q1}:{},...U1?{canvasFile:U1}:{}}])},[]),K1=y1((b,P,S)=>{d(O1(),b,P,S)},[d]),R=y1((b,P)=>{W((S)=>S.map((V)=>V.id===b?{...V,note:P}:V))},[]),g=y1((b)=>{x6(b),W((P)=>P.filter((S)=>S.id!==b)),A((P)=>P===b?null:P)},[]),p=y1((b,P)=>{W((S)=>S.map((V)=>V.id===b?{...V,images:[...V.images||[],P]}:V))},[]),t=y1((b,P)=>{W((S)=>S.map((V)=>V.id===b?{...V,images:(V.images||[]).filter((i)=>i!==P)}:V))},[]),l=y1((b,P)=>{M((S)=>{let V=new Map(S);return V.set(b,P),V})},[]),o=y1((b)=>{j((P)=>{let S=P.draft===L.current?P:z5(L.current);if(S.responseIds.has(b))return S;return{...S,responseIds:new Set(S.responseIds).add(b)}})},[]),q1=y1((b)=>{j((P)=>{let S=P.draft===L.current?P:z5(L.current);if(S.canvases.has(b))return S;return{...S,canvases:new Set(S.canvases).add(b)}})},[]),X1=w.draft===y?w:null,z1=W3(()=>{if(!X1||!K5(Z,X1.canvases))return T;return U5(T,X1.responseIds)},[X1,Z,T]),M1=y1((b,P)=>{m((S)=>{let V=S.get(b);if(V&&V.markdown===P.markdown&&V.label===P.label&&V.required===P.required)return S;let i=new Map(S);return i.set(b,P),i})},[]),C=y1((b)=>{m((P)=>{if(!P.has(b))return P;let S=new Map(P);return S.delete(b),S})},[]),E=y1(()=>{for(let b of document.querySelectorAll("[data-annotation-id]"))B3(b);if(W([]),O(""),A(null),M(new Map),m(new Map),U)U($,Q,{annotations:[],generalNote:"",responses:[],feedbackEntries:[]},X);else if(X==="next")localStorage.removeItem(D1($,Q,X));else U0(localStorage,$,Q)},[$,Q,X,U]);return f6(m6.Provider,{value:{annotations:H,addAnnotation:K1,addAnnotationWithId:d,updateAnnotation:R,removeAnnotation:g,addAnnotationImage:p,removeAnnotationImage:t,generalNote:N,setGeneralNote:O,clearAll:E,activeAnnotationId:B,setActiveAnnotationId:A,responses:T,setResponse:l,submittableResponses:z1,registerResponse:o,registerCanvasRendered:q1,feedbackEntries:k,setFeedbackEntry:M1,removeFeedbackEntry:C,isReadOnly:J},children:G},void 0,!1,void 0,this)}function x6($){let Q=document.querySelectorAll(`[data-annotation-id="${$}"]`);for(let J of Q)B3(J)}function B3($){let Q=$.parentNode;if(!Q)return;if($.tagName!=="MARK"){Q.removeChild($);return}let J=document.createTextNode($.textContent||"");Q.replaceChild(J,$),Q.normalize()}import{useAnnotations as v1,useFeedback as PX,useCanvasFile as yX,useResponseRegistration as SX,AnnotationCtx as AX,SessionContext as wX,ActiveViewCtx as CX,CanvasFileCtx as bX}from"#canvas/runtime";import{useEffect as S3,useState as y0,useContext as L5,useMemo as e6,useCallback as M5}from"react";import{createContext as T3}from"react";var E1=T3({activeView:{type:"overview"},setActiveView:()=>{},openFiles:[],closeFile:()=>{},canvasFiles:[]}),S1=T3({currentRevision:1,selectedRevision:1,revisions:[],setSelectedRevision:()=>{},isReadOnly:!1,compareRevision:null,setCompareRevision:()=>{},agentWatching:!1});import{SessionContext as $$}from"#canvas/runtime";import{useEffect as F3,useState as i0,useRef as v6,useMemo as H5}from"react";import{jsxDEV as Z1}from"react/jsx-dev-runtime";function W5({open:$,onClose:Q,onSubmit:J,includedRemoteIds:X,onToggleRemoteId:Y}){let{annotations:Z,generalNote:q,submittableResponses:U,feedbackEntries:G}=T1(),[K,_]=i0(""),[z,W]=i0(!1),[H,N]=i0(!1),[O,B]=i0(null),A=v6(null),[T,M]=i0(!1),y=H5(()=>Z.filter((k)=>k.source==="remote"),[Z]);if($&&!T)W(!1),N(!1),B(null);if(!$&&T)W(!1),N(!1),B(null);if($!==T)M($);let L=H5(()=>l0(Z,q,U,G,X),[Z,q,U,G,X]),w=z?K:L;if(F3(()=>{if($&&H&&A.current)A.current.focus()},[$,H]),F3(()=>{if(!$)return;let k=(m)=>{if(m.key==="Escape")Q()};return window.addEventListener("keydown",k),()=>window.removeEventListener("keydown",k)},[$,Q]),!$)return null;let j=w.trim().length>0;return Z1("div",{className:"fixed inset-0 z-50 bg-black/50 backdrop-blur-sm flex items-center justify-center p-8",onClick:Q,children:Z1("div",{className:"bg-bg-surface border border-border-medium rounded-xl shadow-lg w-full max-w-2xl flex flex-col",style:{height:"80vh"},onClick:(k)=>k.stopPropagation(),children:[Z1("div",{className:"flex items-center justify-between px-5 py-3 border-b border-border-subtle flex-shrink-0",children:[Z1("div",{className:"flex items-center gap-3",children:[Z1("span",{className:"text-[13px] font-medium text-text-primary font-body",children:"Response preview"},void 0,!1,void 0,this),z&&Z1("button",{onClick:()=>{W(!1),N(!1)},className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body",children:"Reset"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Z1("div",{className:"flex items-center gap-2",children:[Z1("div",{className:"flex items-center bg-bg-base rounded-md p-0.5",children:[Z1("button",{onClick:()=>N(!1),className:`px-2.5 py-1 rounded text-[11px] font-body font-medium transition-colors ${!H?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Preview"},void 0,!1,void 0,this),Z1("button",{onClick:()=>N(!0),className:`px-2.5 py-1 rounded text-[11px] font-body font-medium transition-colors ${H?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Edit"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Z1("button",{onClick:Q,className:"text-text-tertiary hover:text-text-secondary w-7 h-7 flex items-center justify-center rounded-md hover:bg-border-subtle transition-colors",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),H?Z1("textarea",{ref:A,value:w,onChange:(k)=>{_(k.currentTarget.value),W(!0)},className:"flex-1 w-full bg-bg-base p-5 text-[13px] font-mono text-text-code resize-none focus:outline-none leading-relaxed placeholder:text-text-disabled",placeholder:"Your feedback will appear here..."},void 0,!1,void 0,this):Z1("div",{className:"flex-1 overflow-y-auto p-5",children:Z1(y2,{text:w},void 0,!1,void 0,this)},void 0,!1,void 0,this),y.length>0&&Z1("div",{className:"px-5 py-2 border-t border-border-subtle flex-shrink-0",children:Z1("span",{className:"text-[12px] text-text-secondary font-body",children:["Reviewer feedback: ",X.size,"/",y.length," included"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),O&&Z1("div",{className:"px-5 py-2 text-[12px] text-accent-red font-body border-t border-border-subtle flex-shrink-0 flex items-center justify-between gap-2",children:[Z1("span",{children:O},void 0,!1,void 0,this),Z1("button",{onClick:()=>{B(null),J(w)},className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body whitespace-nowrap underline",children:"Submit anyway"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Z1("div",{className:"flex justify-end gap-2 px-5 py-3 border-t border-border-subtle flex-shrink-0",children:[Z1("button",{onClick:Q,className:"px-4 py-2 rounded-lg text-[13px] font-body text-text-tertiary hover:text-text-secondary transition-colors",children:"Cancel"},void 0,!1,void 0,this),Z1("button",{onClick:()=>{let k=r0(U,G);if(k.length>0){B(`Please answer: ${k.join(", ")}`);return}B(null),J(w)},disabled:!j,className:`px-6 py-2 rounded-lg font-body text-[13px] font-medium transition-all ${j?"bg-btn-primary text-btn-primary-text hover:opacity-90":"bg-bg-input text-text-disabled cursor-default"}`,children:"Submit feedback"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}var u6=/!\[([^\]]*)\]\((\/tmp\/agent-canvas\/uploads\/([^)]+))\)/g;function g6($){return $.replace(u6,(Q,J,X,Y)=>`![${J}](/api/uploads/${Y})`)}function y2({text:$}){let Q=H5(()=>a.parse(g6($),{async:!1}),[$]);return Z1("div",{className:"prose-canvas font-body text-body text-text-primary leading-relaxed",dangerouslySetInnerHTML:{__html:Q}},void 0,!1,void 0,this)}import{jsxDEV as _0}from"react/jsx-dev-runtime";var h6={ts:"#3178c6",tsx:"#3178c6",js:"#e8a32e",jsx:"#4ba0c8",html:"#e34c26",css:"#264de4",scss:"#c69",json:"#7a7568",yaml:"#cb171e",yml:"#cb171e",toml:"#9c4221",rs:"#dea584",go:"#00add8",c:"#6a6a6a",cpp:"#f34b7d",h:"#6a6a6a",py:"#3572a5",rb:"#cc342d",sh:"#5a8c3c",bash:"#5a8c3c",md:"#3573b5",txt:"#6b6560",lock:"#6b6560",gitignore:"#6b6560",svg:"#d9952e",png:"#6a9c2e",jpg:"#6a9c2e",gif:"#6a9c2e"},p6={ts:"TS",tsx:"TX",js:"JS",jsx:"JX",py:"PY",rs:"RS",go:"GO",rb:"RB",json:"{}",yaml:"YM",yml:"YM",toml:"TM",html:"<>",css:"#",scss:"#",md:"M↓",sh:"$",bash:"$",c:"C",cpp:"C+",h:"H",svg:"◇",png:"▣",jpg:"▣"};function t1({name:$,type:Q,expanded:J,className:X=""}){if(Q==="dir")return _0("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",className:`flex-shrink-0 ${X}`,children:J?_0("path",{d:"M1.5 3.5h5l1.5 1.5h6.5v8h-13z",style:{fill:"var(--color-folder-fill-active)",stroke:"var(--color-folder-stroke-active)"},strokeWidth:"1"},void 0,!1,void 0,this):_0("path",{d:"M1.5 3.5h5l1.5 1.5h6.5v8h-13z",style:{fill:"var(--color-folder-fill)",stroke:"var(--color-folder-stroke)"},strokeWidth:"1"},void 0,!1,void 0,this)},void 0,!1,void 0,this);let Y=$.includes(".")?$.split(".").pop().toLowerCase():"",Z=h6[Y]||"#6b6560",q=p6[Y];return _0("svg",{width:"14",height:"14",viewBox:"0 0 16 16",className:`flex-shrink-0 ${X}`,children:[_0("path",{d:"M2 1.5h8l3.5 3.5v9.5a1 1 0 01-1 1H3a1 1 0 01-1-1v-12a1 1 0 011-1z",fill:Z,opacity:"0.85"},void 0,!1,void 0,this),_0("path",{d:"M10 1.5v2.5a1 1 0 001 1h2.5",fill:"none",stroke:"white",strokeWidth:"0.5",opacity:"0.5"},void 0,!1,void 0,this),q&&_0("text",{x:"8",y:"11.5",textAnchor:"middle",fill:"white",fontSize:"5.5",fontFamily:"monospace",fontWeight:"600",children:q},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{useContext as i6,useEffect as o6,useRef as a6}from"react";import{SessionContext as s6}from"#canvas/runtime";import{useState as N5,useRef as B5,useCallback as h1,useEffect as l6}from"react";import{createContext as c6,useContext as d6}from"react";function O3(){if(typeof window>"u")return"";return window.location.pathname.replace("/s/","")}var L3={get sessionId(){return O3()},isShared:!1,fsAvailable:!0,uploadUrl:null,loadCanvasModule:($,Q)=>{let J=$.replace(/\.jsx$/,".js"),X=Q?`?rev=${Q}&t=${Date.now()}`:`?t=${Date.now()}`;return import(`/api/session/${O3()}/canvas/${encodeURIComponent(J)}${X}`)}},S2=c6(L3);function j1(){return d6(S2)}import{jsxDEV as H1}from"react/jsx-dev-runtime";function T5($){if($.startsWith("/s/")||$.startsWith("http://")||$.startsWith("https://"))return $;return`/api/uploads/${$.split("/").pop()}`}async function r6($,Q){let J=$.uploadUrl;if(!J)return null;let X=new FormData;X.append("image",Q);try{let Z=await(await fetch(J(),{method:"POST",body:X})).json();if($.isShared)return Z.url||null;return Z.path||null}catch{return null}}function o0({note:$,onNoteChange:Q,images:J,onAddImage:X,onRemoveImage:Y,sessionId:Z,placeholder:q="Add your note...",autoFocus:U=!1,autoResize:G=!1,readOnly:K=!1,onKeyDown:_,onTextareaClick:z,textareaRef:W,textareaClassName:H,textareaStyle:N,minHeight:O,attachButton:B="always",openFilePickerRef:A}){let T=j1(),M=!K&&h0(T),[y,L]=N5(!1),[w,j]=N5(!1),[k,m]=N5(!1),D=B5(0),v=B5(null),u=B5(null),d=h1(()=>u.current?.click(),[]);if(A)A.current=d;let K1=h1((C)=>{if(v.current=C,W)W.current=C;if(C&&G)s1(C,O)},[W,G,O]);l6(()=>{if(U&&v.current){let C=v.current;if(C.focus(),C.value)C.setSelectionRange(C.value.length,C.value.length)}},[U]);let R=h1(async(C)=>{if(!C.type.startsWith("image/"))return;j(!0);try{let E=await r6(T,C);if(E)X(E)}finally{j(!1)}},[T,X]),g=h1((C)=>{for(let E of C.clipboardData?.items??[])if(E.type.startsWith("image/")){C.preventDefault();let b=E.getAsFile();if(b)R(b);return}},[R]),p=h1((C)=>{if(C.preventDefault(),D.current++,D.current===1)L(!0)},[]),t=h1((C)=>{C.preventDefault()},[]),l=h1((C)=>{if(C.preventDefault(),D.current--,D.current===0)L(!1)},[]),o=h1((C)=>{C.preventDefault(),D.current=0,L(!1);for(let E of C.dataTransfer?.files??[])if(E.type.startsWith("image/"))R(E)},[R]),q1=h1((C)=>{if(Q(C.currentTarget.value),G)C.currentTarget.style.height="auto",C.currentTarget.style.height=(O?Math.max(O,C.currentTarget.scrollHeight):C.currentTarget.scrollHeight)+"px"},[Q,G,O]),X1="w-full bg-transparent text-[13px] font-body text-text-primary resize-none focus:outline-none leading-relaxed p-0 border-none",z1={width:"100%",background:"transparent",border:"none",color:"var(--color-text-primary)",fontFamily:"'Inter', sans-serif",fontSize:"13px",lineHeight:"1.5",outline:"none",...G?{resize:"none",overflow:"hidden"}:{resize:"vertical"}},M1=M&&(B==="always"||B==="on-focus"&&k);return H1("div",{style:{position:"relative"},onDragEnter:M?p:void 0,onDragOver:M?t:void 0,onDragLeave:M?l:void 0,onDrop:M?o:void 0,children:[H1("textarea",{ref:K1,value:$,onChange:K?void 0:q1,onPaste:M?g:void 0,onKeyDown:_,onClick:z,onFocus:()=>m(!0),onBlur:()=>{setTimeout(()=>m(!1),150)},readOnly:K,placeholder:q,className:H??X1,style:N??z1,rows:G?1:void 0},void 0,!1,void 0,this),M&&H1("input",{ref:u,type:"file",accept:"image/*",multiple:!0,style:{display:"none"},onChange:(C)=>{let E=C.currentTarget.files;if(E)for(let b of E)R(b);C.currentTarget.value=""}},void 0,!1,void 0,this),(J.length>0||M1)&&H1("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"6px",alignItems:"center"},children:[J.map((C)=>H1("div",{style:{position:"relative",width:"56px",height:"56px",borderRadius:"6px",overflow:"hidden",border:"1px solid var(--color-border-subtle)",flexShrink:0},children:[H1("img",{src:T5(C),alt:"",style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}},void 0,!1,void 0,this),!K&&H1("button",{onClick:(E)=>{E.stopPropagation(),Y(C)},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)]},C,!0,void 0,this)),M1&&H1(F5,{onClick:d},void 0,!1,void 0,this)]},void 0,!0,void 0,this),w&&H1("div",{style:{fontSize:"11px",color:"var(--color-text-tertiary)",fontFamily:"'Inter', sans-serif",marginTop:"4px"},children:"Uploading..."},void 0,!1,void 0,this),y&&H1("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 F5({onClick:$,size:Q=16}){return H1("button",{onClick:(J)=>{J.stopPropagation(),$()},style:{width:`${Q*2}px`,height:`${Q*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:(J)=>{J.currentTarget.style.color="var(--color-text-secondary)"},onMouseLeave:(J)=>{J.currentTarget.style.color="var(--color-text-tertiary)"},children:H1("svg",{width:Q,height:Q,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[H1("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"},void 0,!1,void 0,this),H1("circle",{cx:"8.5",cy:"8.5",r:"1.5"},void 0,!1,void 0,this),H1("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 M3({images:$}){if(!$.length)return null;return H1("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"6px"},children:$.map((Q)=>H1("div",{style:{width:"56px",height:"56px",borderRadius:"6px",overflow:"hidden",border:"1px solid var(--color-border-subtle)",flexShrink:0},children:H1("img",{src:T5(Q),alt:"",style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}},void 0,!1,void 0,this)},Q,!1,void 0,this))},void 0,!1,void 0,this)}import{jsxDEV as G1,Fragment as P3}from"react/jsx-dev-runtime";function t6($){let Q=c0($);return Q.length>80?Q.slice(0,80)+"...":Q}function a0({annotations:$,readOnly:Q=!1,onSelect:J,onReveal:X,includedRemoteIds:Y,onToggleRemoteId:Z}){let{updateAnnotation:q,removeAnnotation:U,addAnnotationImage:G,removeAnnotationImage:K,activeAnnotationId:_,setActiveAnnotationId:z}=T1(),W=i6(s6),H=a6(new Map);o6(()=>{if(Q||!_)return;let M=H.current.get(_);if(M)M.scrollIntoView({behavior:"smooth",block:"nearest"})},[_,Q]);let N=(M)=>{z(M),M0(M,!0)},O=(M)=>{z(null),M0(M,!1)},B=(M)=>{if(M.id===_){z(null);return}z(M.id),J?.(M)},A=!!Y&&!!Z,T=(M)=>{let y=A&&M.source==="remote";return G1("div",{ref:(L)=>{if(L)H.current.set(M.id,L);else H.current.delete(M.id)},className:`group/ann relative px-3 py-2.5 transition-colors duration-150 ${Q?"cursor-pointer ":""}${_===M.id?"bg-highlight-selected":y?"bg-accent-purple-muted/30 hover:bg-accent-purple-muted/50":"odd:bg-bg-elevated-half hover:bg-bg-input"}`,onMouseEnter:()=>N(M.id),onMouseLeave:()=>O(M.id),onClick:()=>B(M),children:[y&&M.author&&G1("div",{className:"flex items-center gap-1.5 mb-1.5",children:[G1("input",{type:"checkbox",checked:Y.has(M.id),onChange:(L)=>{L.stopPropagation(),Z(M.id)},onClick:(L)=>L.stopPropagation(),className:"accent-accent-purple flex-shrink-0",title:"Include in submission"},void 0,!1,void 0,this),G1("span",{className:"inline-flex items-center justify-center w-4 h-4 rounded-full bg-accent-purple text-white text-[9px] font-medium uppercase",children:M.author.name.charAt(0)},void 0,!1,void 0,this),G1("span",{className:"text-[11px] font-medium text-accent-purple font-body",children:M.author.name},void 0,!1,void 0,this),G1("span",{className:"text-[10px] text-text-tertiary font-body uppercase tracking-widest",children:"Remote"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),G1("div",{className:"text-[11px] text-text-tertiary italic line-clamp-2 mb-1.5 leading-snug font-body border-l-2 border-border-medium pl-2",children:t6(M.snippet)},void 0,!1,void 0,this),Q?G1(P3,{children:[M.note.trim()&&G1("div",{className:"text-[13px] font-body text-text-primary leading-relaxed",children:M.note},void 0,!1,void 0,this),G1(M3,{images:M.images||[]},void 0,!1,void 0,this)]},void 0,!0,void 0,this):y?G1("div",{className:"text-[13px] font-body text-text-primary leading-relaxed whitespace-pre-wrap",children:M.note},void 0,!1,void 0,this):G1("div",{onClick:(L)=>L.stopPropagation(),children:G1(o0,{note:M.note,onNoteChange:(L)=>q(M.id,L),images:M.images||[],onAddImage:(L)=>G(M.id,L),onRemoveImage:(L)=>K(M.id,L),sessionId:W,autoResize:!0,minHeight:20,textareaClassName:"w-full bg-transparent text-[13px] font-body text-text-primary resize-none focus:outline-none leading-relaxed p-0 border-none min-h-[20px]",textareaStyle:{height:"auto",overflow:"hidden"},placeholder:"Add your note...",attachButton:"on-focus"},void 0,!1,void 0,this)},void 0,!1,void 0,this),G1("div",{className:"absolute top-1.5 right-1.5 opacity-0 group-hover/ann:opacity-100 transition-opacity duration-100 flex items-center gap-0.5",children:[X&&G1("button",{onClick:(L)=>{L.stopPropagation(),X(M)},className:"w-5 h-5 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-input transition-colors",title:"Scroll to annotation",children:G1("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[G1("circle",{cx:"12",cy:"12",r:"3"},void 0,!1,void 0,this),G1("path",{d:"M12 2v4M12 18v4M2 12h4M18 12h4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),!Q&&!y&&G1("button",{onClick:(L)=>{L.stopPropagation(),U(M.id)},className:"w-5 h-5 flex items-center justify-center rounded text-text-tertiary hover:text-accent-red hover:bg-accent-red-muted transition-colors",title:"Delete annotation",children:G1("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[G1("polyline",{points:"3 6 5 6 21 6"},void 0,!1,void 0,this),G1("path",{d:"M19 6v14a2 2 0 01-2 2H7a2 2 0 01-2-2V6m3 0V4a2 2 0 012-2h4a2 2 0 012 2v2"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},M.id,!0,void 0,this)};return G1(P3,{children:$.map(T)},void 0,!1,void 0,this)}import{jsxDEV as H0,Fragment as n6}from"react/jsx-dev-runtime";function O5({hasContent:$,onSubmit:Q,onSubmitEmpty:J,notice:X,secondaryAction:Y,placeholder:Z="General notes...",submitLabel:q="Submit",emptyLabel:U="Submit without feedback"}){let{generalNote:G,setGeneralNote:K}=T1();return H0(n6,{children:[H0("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:H0("textarea",{value:G,onChange:(_)=>K(_.currentTarget.value),className:"w-full bg-transparent text-[13px] font-body text-text-primary resize-none leading-relaxed p-0 border-none ring-0 shadow-none outline-none focus:outline-none focus:ring-0 focus:border-none placeholder:text-text-disabled min-h-[40px]",placeholder:Z,onInput:(_)=>s1(_.currentTarget,40),ref:(_)=>{if(_)s1(_,40)}},void 0,!1,void 0,this)},void 0,!1,void 0,this),X,H0("div",{className:"px-4 py-3 border-t border-border-subtle flex-shrink-0",children:$?H0("div",{className:"flex gap-2",children:[Y,H0("button",{onClick:Q,className:"flex-1 py-2 rounded-lg font-body text-[13px] font-medium transition-all bg-btn-primary text-btn-primary-text hover:opacity-90 hover:-translate-y-px shadow-sm",children:q},void 0,!1,void 0,this)]},void 0,!0,void 0,this):H0("button",{onClick:J,className:"w-full py-2 rounded-lg font-body text-[13px] font-medium border border-border-medium text-text-secondary hover:text-text-primary hover:border-border-hover hover:bg-bg-input transition-all",children:U},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{jsxDEV as x,Fragment as A2}from"react/jsx-dev-runtime";function w2({onSubmit:$,collapseButton:Q}){let{isReadOnly:J,selectedRevision:X,currentRevision:Y,revisions:Z,agentWatching:q}=L5(S1),U=L5($$),G=Z.find((W)=>W.revision===X),K=J&&X===Y,_=!!G?.feedbackConsumed,z=G?.label||`Round ${X}`;if(J)return x(J$,{sessionId:U,revision:X,label:z,waitingForUpdate:K,feedbackConsumed:_,agentWatching:q,collapseButton:Q},void 0,!1,void 0,this);return x(X$,{onSubmit:$,agentWatching:q,collapseButton:Q},void 0,!1,void 0,this)}function Q$({sessionId:$,revision:Q,label:J,waitingForUpdate:X,feedbackConsumed:Y,agentWatching:Z,collapseButton:q}){let G=j1().isShared;return x("div",{className:"flex flex-col h-full",children:[x("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[x("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:X?"Feedback sent":`Feedback — ${J}`},void 0,!1,void 0,this),q]},void 0,!0,void 0,this),X&&!G&&x(A3,{feedbackConsumed:Y,agentWatching:Z},void 0,!1,void 0,this),x(w3,{sessionId:$,revision:Q},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function A3({feedbackConsumed:$,agentWatching:Q}){if($)return x("div",{className:"mx-4 mb-3 px-3 py-2.5 rounded-lg bg-accent-green-muted flex items-center gap-2 flex-shrink-0",children:[x("span",{className:"w-2 h-2 rounded-full bg-accent-green animate-pulse"},void 0,!1,void 0,this),x("span",{className:"text-[12px] font-body text-accent-green",children:"Feedback received — waiting for next revision..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(Q)return x("div",{className:"mx-4 mb-3 px-3 py-2.5 rounded-lg bg-accent-blue-muted flex items-center gap-2 flex-shrink-0",children:[x("span",{className:"w-2 h-2 rounded-full bg-accent-blue animate-pulse"},void 0,!1,void 0,this),x("span",{className:"text-[12px] font-body text-accent-blue",children:"Waiting for agent to pick up feedback..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return x("div",{className:"mx-4 mb-3 px-3 py-2.5 rounded-lg bg-accent-amber-muted flex items-center gap-2 flex-shrink-0",children:[x("span",{className:"w-2 h-2 rounded-full bg-accent-amber"},void 0,!1,void 0,this),x("span",{className:"text-[12px] font-body text-accent-amber",children:"Agent disconnected — tell Claude to check feedback"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function J$({sessionId:$,revision:Q,label:J,waitingForUpdate:X,feedbackConsumed:Y,agentWatching:Z,collapseButton:q}){let{annotations:U,generalNote:G}=T1(),K=U.length>0||G.trim().length>0,[_,z]=y0("feedback");if(!K)return x(Q$,{sessionId:$,revision:Q,label:J,waitingForUpdate:X,feedbackConsumed:Y,agentWatching:Z,collapseButton:q},void 0,!1,void 0,this);return x("div",{className:"flex flex-col h-full",children:[x("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[x("div",{className:"flex items-center gap-1 bg-bg-input rounded-md p-0.5",children:[x("button",{onClick:()=>z("feedback"),className:`px-2.5 py-1 rounded text-[11px] font-medium font-body transition-colors ${_==="feedback"?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Feedback"},void 0,!1,void 0,this),x("button",{onClick:()=>z("annotations"),className:`px-2.5 py-1 rounded text-[11px] font-medium font-body transition-colors flex items-center gap-1.5 ${_==="annotations"?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:["Annotations",x("span",{className:"inline-flex items-center justify-center min-w-[16px] h-[16px] px-1 rounded-full bg-border-subtle text-[10px] font-medium",children:U.length},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),q]},void 0,!0,void 0,this),X&&x(A3,{feedbackConsumed:Y,agentWatching:Z},void 0,!1,void 0,this),_==="feedback"?x(w3,{sessionId:$,revision:Q},void 0,!1,void 0,this):x(A2,{children:[x("div",{className:"flex-1 overflow-y-auto",children:x(C3,{annotations:U,readOnly:!0},void 0,!1,void 0,this)},void 0,!1,void 0,this),G.trim()&&x("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:x("div",{className:"text-[13px] font-body text-text-primary leading-relaxed",children:G},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 w3({sessionId:$,revision:Q}){let J=j1(),[X,Y]=y0(null),[Z,q]=y0(!0);return S3(()=>{if(q(!0),!J.fsAvailable){Y(null),q(!1);return}fetch(`/api/session/${$}/revision/${Q}/feedback`).then((U)=>U.json()).then((U)=>{Y(U.feedback||null),q(!1)}).catch(()=>{Y(null),q(!1)})},[$,Q]),x("div",{className:"flex-1 overflow-y-auto px-4",children:Z?x("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"Loading..."},void 0,!1,void 0,this):X?x(y2,{text:X},void 0,!1,void 0,this):x("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"No feedback was submitted for this revision."},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function Y$($){let Q=$.filter((q)=>q.filePath===I1),J=$.filter((q)=>!q.filePath),X=$.filter((q)=>K0(q)!==void 0),Y={};for(let q of X){let U=K0(q);if(!U)continue;let G=Y[U];if(G)G.push(q);else Y[U]=[q]}let Z=[Q,J,X].filter((q)=>q.length>0).length>1;return{response:Q,plan:J,fileGroups:Y,hasMultipleGroups:Z}}function y3({children:$}){return x("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body px-3 mb-1 mt-1",children:$},void 0,!1,void 0,this)}function C3({annotations:$,readOnly:Q,includedRemoteIds:J,onToggleRemoteId:X}){let{setActiveView:Y}=L5(E1),{response:Z,plan:q,fileGroups:U,hasMultipleGroups:G}=Y$($),K=M5((W)=>{let H=K0(W);if(!H)return;Y({type:"file",path:H}),setTimeout(()=>{let N=p0(W);if(N)N.scrollIntoView({behavior:"smooth",block:"center"})},150)},[Y]),_=M5((W)=>G5(W,Y),[Y]),z={readOnly:Q,onSelect:K,onReveal:_,includedRemoteIds:J,onToggleRemoteId:X};return x(A2,{children:[Z.length>0&&x(A2,{children:[G&&x(y3,{children:"Agent Response"},void 0,!1,void 0,this),x(a0,{annotations:Z,...z},void 0,!1,void 0,this)]},void 0,!0,void 0,this),q.length>0&&x(A2,{children:[G&&x(y3,{children:"Canvas"},void 0,!1,void 0,this),x(a0,{annotations:q,...z},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Object.entries(U).map(([W,H])=>x("div",{children:[x("button",{onClick:()=>Y({type:"file",path:W}),className:"flex items-center gap-1.5 text-[10px] uppercase tracking-widest text-text-tertiary hover:text-text-secondary font-body px-3 pt-3 pb-1 truncate transition-colors w-full text-left",title:W,children:[x(t1,{name:W.split("/").pop()||W,type:"file"},void 0,!1,void 0,this),x("span",{className:"truncate",children:W},void 0,!1,void 0,this)]},void 0,!0,void 0,this),x(a0,{annotations:H,...z},void 0,!1,void 0,this)]},W,!0,void 0,this))]},void 0,!0,void 0,this)}function X$({onSubmit:$,agentWatching:Q,collapseButton:J}){let X=j1(),[Y,Z]=y0(!1),{annotations:q,generalNote:U,submittableResponses:G,feedbackEntries:K}=T1(),_=e6(()=>q.filter((y)=>y.source==="remote"),[q]),[z,W]=y0(()=>new Set);S3(()=>{if(_.length===0)return;W((y)=>{let L=new Set(y);for(let w of _)L.add(w.id);return L.size===y.size?y:L})},[_]);let H=M5((y)=>{W((L)=>{let w=new Set(L);if(w.has(y))w.delete(y);else w.add(y);return w})},[]),N=Array.from(G.values()).some(P2),O=K.size>0,B=q.length>0||U.trim().length>0||N||O,[A,T]=y0(null),M=()=>{let y=l0(q,U,G,K,z);$(y)};return x("div",{className:"flex flex-col h-full",children:[x("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[x("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body flex items-center gap-2",children:["Annotations",q.length>0&&x("span",{className:"inline-flex items-center justify-center min-w-[18px] h-[18px] px-1 rounded-full bg-border-subtle text-[10px] font-medium text-text-secondary",children:q.length},void 0,!1,void 0,this),!X.isShared&&x("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${Q?"bg-accent-green":"bg-accent-amber"}`,title:Q?"Agent connected":"Agent disconnected"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),J]},void 0,!0,void 0,this),x("div",{className:"flex-1 overflow-y-auto",children:[q.length===0&&x("p",{className:"text-[12px] text-text-tertiary px-3 py-4 leading-relaxed font-body",children:"Select text in the canvas or in files to add annotations."},void 0,!1,void 0,this),x(C3,{annotations:q,includedRemoteIds:z,onToggleRemoteId:H},void 0,!1,void 0,this)]},void 0,!0,void 0,this),x(O5,{hasContent:B,onSubmit:()=>{let y=r0(G,K);if(y.length>0){T(`Please answer: ${y.join(", ")}`);return}T(null),M()},onSubmitEmpty:()=>$("No feedback — looks good."),notice:A&&x("div",{className:"px-4 py-2 text-[12px] text-accent-red font-body border-t border-border-subtle flex-shrink-0 flex items-center justify-between gap-2",children:[x("span",{children:A},void 0,!1,void 0,this),x("button",{onClick:()=>{T(null),M()},className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body whitespace-nowrap underline",children:"Submit anyway"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),secondaryAction:x("button",{onClick:()=>Z(!0),className:"flex-1 py-2 rounded-lg font-body text-[13px] font-medium transition-all bg-border-subtle text-text-secondary hover:bg-border-medium hover:text-text-primary",children:"Preview"},void 0,!1,void 0,this)},void 0,!1,void 0,this),x(W5,{open:Y,onClose:()=>Z(!1),onSubmit:$,includedRemoteIds:z,onToggleRemoteId:H},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import j2,{useEffect as e1,useState as f1,useRef as N$,useContext as x3,useMemo as t0}from"react";import{createPortal as B$}from"react-dom";import{SessionContext as T$,CanvasFileCtx as F$}from"#canvas/runtime";import{useEffect as q$,useRef as b2,useState as S0,useCallback as C2,useMemo as j3,useContext as Z$}from"react";import{createPortal as G$}from"react-dom";function b3($){let Q=/^(\d+(?:\.\d+)?)px$/.exec($.trim());return Q?Number(Q[1]):void 0}function I3($,Q,J=280){let Y=Q||document.body,Z=$.getBoundingClientRect(),q=Y.getBoundingClientRect(),U=Y===document.body?0:Y.scrollTop,G=Z.bottom-q.top+U+8,K=Math.max(0,Math.min(Z.left-q.left,q.width-J-12));return Y.style.position="relative",{style:{position:"absolute",top:`${G}px`,left:`${K}px`},parent:Y}}import{SessionContext as U$}from"#canvas/runtime";import{jsxDEV as W1,Fragment as K$}from"react/jsx-dev-runtime";function k3({anchorEl:$,scrollContainer:Q,onClose:J,ignoreSelector:X,zIndex:Y="50",padding:Z="12px",width:q="280px",children:U}){let G=b2(null),K=b2(J);K.current=J;let{style:_,parent:z}=I3($,Q,b3(q));return q$(()=>{let W=setTimeout(()=>{let H=(N)=>{if(G.current&&!G.current.contains(N.target)){if(X&&N.target.closest?.(X))return;K.current(),document.removeEventListener("mousedown",H)}};return document.addEventListener("mousedown",H),()=>document.removeEventListener("mousedown",H)},0);return()=>clearTimeout(W)},[X]),G$(W1("div",{ref:G,style:{..._,zIndex:Y,width:q,background:"var(--color-bg-elevated)",border:"1px solid var(--color-border-hover)",borderRadius:"8px",boxShadow:"0 4px 12px var(--color-shadow)",padding:Z,fontFamily:"'Inter', sans-serif"},children:U},void 0,!1,void 0,this),z)}var R3=[{label:"Clarity",items:["Unclear","Why?","Needs example","Missing context"]},{label:"Scope",items:["Overkill","Out of scope","Important","Risky"]},{label:"Action",items:["Simplify","Rethink","Expand on this","Skip this"]}],V3=R3.flatMap(($)=>$.items);function P5({anchorEl:$,scrollContainer:Q,snippet:J,truncateAt:X=100,header:Y,initialNote:Z="",initialImages:q,onConfirm:U,onCancel:G,onDelete:K}){let _=Z$(U$),z=j1(),W=h0(z),H=Z!==""||!!K,[N,O]=S0(Z),[B,A]=S0(q||[]),[T,M]=S0(null),[y,L]=S0(H),[w,j]=S0(!1),k=b2(null),m=b2(null),D=C2(()=>{if(N.trim()||B.length>0)U(N.trim(),B);else if(H&&K)K();else G()},[N,B,U,G,H,K]),v=C2(()=>{if(H){if(!N.trim()&&B.length===0&&K){K(),G();return}U(N,B);return}G()},[N,B,H,U,G,K]),u=!H,d=N.trim().length>0?V3.filter((P)=>P.toLowerCase().startsWith(N.trim().toLowerCase())):V3,K1=!u||y?[]:d.length===1&&d[0]?.toLowerCase()===N.trim().toLowerCase()?[]:d,R=new Set(K1),g=R3.map((P)=>({label:P.label,items:P.items.filter((S)=>R.has(S))})).filter((P)=>P.items.length>0),p=g.map((P)=>P.items),t=(P)=>p[P]?.length??0,l=p.flat(),o=j3(()=>{if(T===null)return 0;let P=0;for(let S=0;S<p.length;S++){if(T<P+t(S))return S;P+=t(S)}return 0},[T,p]),q1=j3(()=>{if(T===null)return 0;let P=0;for(let S=0;S<o;S++)P+=t(S);return T-P},[T,o,p]),X1=(P,S)=>{let V=0;for(let i=0;i<P;i++)V+=t(i);return V+S},[z1,M1]=S0(N);if(N!==z1)M1(N),M(null),L(H);let C=C2((P)=>{O(P)},[]),E=J.length>X?J.slice(0,X)+"...":J,b=C2((P)=>{if(l.length>0&&(P.key==="ArrowDown"||P.key==="ArrowUp"||P.key==="ArrowLeft"||P.key==="ArrowRight")){if(P.preventDefault(),T===null){M(0);return}if(P.key==="ArrowDown"){let V=Math.min(q1+1,t(o)-1);M(X1(o,V))}else if(P.key==="ArrowUp"){let V=Math.max(q1-1,0);M(X1(o,V))}else if(P.key==="ArrowRight"){let V=Math.min(o+1,p.length-1),i=Math.min(q1,t(V)-1);M(X1(V,i))}else if(P.key==="ArrowLeft"){let V=Math.max(o-1,0),i=Math.min(q1,t(V)-1);M(X1(V,i))}return}let S=T===null?void 0:l[T];if(S!==void 0){if(P.key==="Tab"){P.preventDefault(),C(S);return}if(P.key==="Enter"&&!P.shiftKey){P.preventDefault(),U(S,B);return}}if(P.key==="Enter"&&!P.shiftKey){P.preventDefault(),D();return}if(P.key==="Escape")if(l.length>0&&!y)L(!0);else if(H)v();else G()},[l,T,q1,o,p,X1,C,U,B,D,y,H,v,G]);return W1(k3,{anchorEl:$,scrollContainer:Q,onClose:H?v:G,ignoreSelector:H?"[data-annotation-id]":void 0,zIndex:H?"60":"50",padding:H?"10px 12px":"12px",width:"420px",children:[!H&&(Y??W1("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:["“",E,"”"]},void 0,!0,void 0,this)),W1(o0,{note:N,onNoteChange:O,images:B,onAddImage:(P)=>A((S)=>[...S,P]),onRemoveImage:(P)=>A((S)=>S.filter((V)=>V!==P)),sessionId:_,autoFocus:!0,autoResize:H,textareaRef:k,onKeyDown:b,attachButton:"none",openFilePickerRef:m,textareaStyle:H?{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),W1("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginTop:H?"6px":"8px"},children:[W&&W1(F5,{onClick:()=>m.current?.(),size:14},void 0,!1,void 0,this),W1("div",{style:{flex:1}},void 0,!1,void 0,this),H?W1("button",{onClick:()=>{if(K)K();G()},onMouseEnter:()=>j(!0),onMouseLeave:()=>j(!1),style:{fontSize:"11px",color:w?"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):W1(K$,{children:[W1("button",{onClick:G,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),W1("button",{onClick:D,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),l.length>0&&W1("div",{style:{marginTop:"6px",borderTop:"1px solid var(--color-border-subtle)",paddingTop:"8px",display:"flex",gap:"4px"},children:g.map((P)=>W1("div",{style:{flex:1},children:[W1("div",{style:{fontSize:"10px",fontWeight:600,color:"var(--color-text-disabled)",textTransform:"uppercase",letterSpacing:"0.05em",padding:"2px 6px",marginBottom:"2px",fontFamily:"'Inter', sans-serif"},children:P.label},void 0,!1,void 0,this),P.items.map((S)=>{let V=l.indexOf(S);return W1("div",{onMouseDown:(i)=>{i.preventDefault(),i.stopPropagation(),C(S)},onMouseEnter:()=>M(V),style:{padding:"3px 6px",fontSize:"12px",borderRadius:"4px",fontFamily:"'Inter', sans-serif",color:V===T?"var(--color-text-primary)":"var(--color-text-secondary)",background:V===T?"var(--color-highlight-selected)":"transparent",cursor:"pointer"},children:[W1("span",{style:{fontWeight:500},children:S.slice(0,N.trim().length)},void 0,!1,void 0,this),S.slice(N.trim().length)]},S,!0,void 0,this)})]},P.label,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function x1({anchorEl:$,scrollContainer:Q,snippet:J,truncateAt:X,header:Y,onAdd:Z,onCancel:q}){return W1(P5,{anchorEl:$,scrollContainer:Q,snippet:J,truncateAt:X,header:Y,onConfirm:(U,G)=>Z(U,G),onCancel:q},void 0,!1,void 0,this)}function W0({anchorEl:$,scrollContainer:Q,initialNote:J,initialImages:X,onUpdate:Y,onDelete:Z,onClose:q}){return W1(P5,{anchorEl:$,scrollContainer:Q,snippet:"",initialNote:J,initialImages:X,onConfirm:(U,G)=>{Y(U,G),q()},onDelete:Z,onCancel:q},void 0,!1,void 0,this)}import{useEffect as I2,useState as D3,useRef as N0,useCallback as m3}from"react";import{jsxDEV as y5,Fragment as z$}from"react/jsx-dev-runtime";function n1($){let{containerRef:Q,restoreKey:J,restoreAnnotations:X,extractContext:Y,filePath:Z,canvasFile:q,scrollContainer:U}=$,{annotations:G,addAnnotationWithId:K,removeAnnotation:_,updateAnnotation:z,addAnnotationImage:W,removeAnnotationImage:H,activeAnnotationId:N,setActiveAnnotationId:O}=T1(),[B,A]=D3(null),[T,M]=D3(null),y=N0(Y);y.current=Y;let L=N0(Z);L.current=Z;let w=N0(q);w.current=q;let j=N0(K);j.current=K;let k=N0(N);k.current=N;let m=N0(O);m.current=O;let D=X.length;I2(()=>{if(!Q.current)return;let R=setTimeout(()=>{if(Q.current)Z5(Q.current,X)},50);return()=>clearTimeout(R)},[J,D]);let v=N0(null);I2(()=>{E0(N,v.current),v.current=N},[N]),I2(()=>{let R=Q.current;if(!R)return;let g=(l)=>{let o=l.target.closest("[data-annotation-id]");if(!o)return;l.stopPropagation();let q1=o.getAttribute("data-annotation-id");if(q1===k.current)A({anchorEl:o,annId:q1});else m.current(q1)},p=(l)=>{let o=l.target.closest("[data-annotation-id]");if(o)m.current(o.getAttribute("data-annotation-id"))},t=(l)=>{let o=l.target.closest("[data-annotation-id]"),q1=l.relatedTarget?.closest?.("[data-annotation-id]");if(o&&!q1&&!document.getElementById("ann-inline-popover"))m.current(null)};return R.addEventListener("click",g),R.addEventListener("mouseover",p),R.addEventListener("mouseout",t),()=>{R.removeEventListener("click",g),R.removeEventListener("mouseover",p),R.removeEventListener("mouseout",t)}},[J]),I2(()=>{let R=()=>u();return document.addEventListener("mouseup",R),()=>document.removeEventListener("mouseup",R)},[]);let u=m3(()=>{let R=window.getSelection();if(!R||R.isCollapsed||!R.toString().trim())return;if(!Q.current)return;let g=R.getRangeAt(0);if(!Q.current.contains(g.startContainer))return;if(g.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let p=Q3(g).trim();if(p.length<2)return;let t=y.current(g),l=g.cloneRange(),o=`__pending_${Date.now()}`;try{i1(l,o)}catch{}window.getSelection()?.removeAllRanges();let q1=document.querySelectorAll(`[data-annotation-id="${o}"]`),X1=q1[q1.length-1];if(!X1)return;M({anchorEl:X1,tempId:o,snippet:p,ctx:t})},[]),d=m3((R,g,p,t)=>{M({anchorEl:R,tempId:g,snippet:p,ctx:t})},[]);return{popovers:y5(z$,{children:[B&&(()=>{let R=G.find((g)=>g.id===B.annId);if(!R)return null;return y5(W0,{anchorEl:B.anchorEl,scrollContainer:U,initialNote:R.note,initialImages:R.images,onUpdate:(g,p)=>{z(B.annId,g);let t=R.images||[];for(let l of p)if(!t.includes(l))W(B.annId,l);for(let l of t)if(!p.includes(l))H(B.annId,l)},onDelete:()=>{_(B.annId),O(null)},onClose:()=>A(null)},void 0,!1,void 0,this)})(),T&&y5(x1,{anchorEl:T.anchorEl,scrollContainer:U,snippet:T.snippet,truncateAt:80,onAdd:(R,g)=>{let p=O1();x0(T.tempId,p),j.current(p,T.snippet,R,L.current,T.ctx,g,w.current),M(null)},onCancel:()=>{v0(T.tempId),M(null)}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),openCreatePopover:d,isPopoverOpen:!!(B||T)}}import{useEffect as _$,useRef as S5,useState as E3}from"react";import{jsxDEV as H$}from"react/jsx-dev-runtime";function A5($){let{containerRef:Q,restoreKey:J,shape:X="rect",canvasFile:Y,scrollContainer:Z}=$,{addAnnotationWithId:q}=T1(),[U,G]=E3(null),[K,_]=E3(!1),z=S5(q);z.current=q;let W=S5(Y);W.current=Y;let H=S5(X);return H.current=X,_$(()=>{let O=Q.current;if(!O)return;let B=null;function A(j,k){let m=j.getBoundingClientRect();return Y5(m,k.clientX-m.left,k.clientY-m.top)}function T(){if(!B)return;let{host:j,pointerId:k}=B;if(j.hasPointerCapture(k))j.releasePointerCapture(k);j.removeEventListener("pointermove",y),j.removeEventListener("pointerup",L),j.removeEventListener("pointercancel",w),B=null,_(!1)}function M(j){if(B||j.button!==0)return;let k=j.target;if(!(k instanceof Element))return;if(k.closest("[data-block-comment-btn]"))return;if(k.closest("[data-annotation-id]"))return;let m=k.closest(`[${J5}]`);if(!(m instanceof HTMLElement)||!O?.contains(m))return;let D=m.closest("[data-md='image']")?.getAttribute("data-md-src");if(!D)return;let v=A(m,j);if(!v)return;j.preventDefault(),m.setPointerCapture(j.pointerId);let u=O1(),d=L2({...v,w:0,h:0},H.current,u);d.classList.add("ann-region-draft"),m.appendChild(d),B={pointerId:j.pointerId,host:m,src:D,start:v,shape:H.current,overlay:d,id:u},m.addEventListener("pointermove",y),m.addEventListener("pointerup",L),m.addEventListener("pointercancel",w),_(!0)}function y(j){if(!B||B.pointerId!==j.pointerId)return;let k=A(B.host,j);if(!k)return;O2(B.overlay,T2(B.start,k))}function L(j){if(!B||B.pointerId!==j.pointerId)return;let{overlay:k,id:m,src:D,shape:v}=B,u=A(B.host,j)??B.start,d=T2(B.start,u);if(T(),!X5(d)){k.remove();return}O2(k,d);let K1={src:D,shape:v,...d};G({overlay:k,id:m,snippet:g0.format(K1),label:F2(K1)})}function w(j){if(!B||B.pointerId!==j.pointerId)return;B.overlay.remove(),T()}return O.addEventListener("pointerdown",M),()=>{if(O.removeEventListener("pointerdown",M),B)B.overlay.remove(),T()}},[J]),{popovers:U?H$(x1,{anchorEl:U.overlay,scrollContainer:Z,snippet:U.label,truncateAt:80,onAdd:(O,B)=>{U.overlay.classList.remove("ann-region-draft"),z.current(U.id,U.snippet,O,void 0,void 0,B,W.current),G(null)},onCancel:()=>{U.overlay.remove(),G(null)}},void 0,!1,void 0,this):null,isDrawing:K,isPopoverOpen:!!U}}import{createContext as W$}from"react";var s0=W$(()=>{});import{jsxDEV as J1,Fragment as P$}from"react/jsx-dev-runtime";class f3 extends j2.Component{state={error:null};static getDerivedStateFromError($){return{error:$}}componentDidCatch($,Q){this.props.reportError({revision:this.props.revision,filename:this.props.filename,message:$.message,...$.stack?{stack:$.stack}:{},...Q.componentStack?{componentStack:Q.componentStack}:{}})}render(){if(!this.state.error)return this.props.children;return J1(v3,{message:this.state.error.message},void 0,!1,void 0,this)}}function v3({message:$}){return J1("div",{className:"bg-accent-red-muted rounded-lg p-5",children:[J1("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Canvas render failed"},void 0,!1,void 0,this),J1("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:$},void 0,!1,void 0,this),J1("p",{className:"text-meta font-body text-text-tertiary mt-3",children:"The error was sent back to the canvas author."},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function A0({revision:$,filename:Q}){let J=x3(T$),X=j1(),Y=x3(s0),[Z,q]=f1(null),[U,G]=f1(null),[K,_]=f1(!0),z=N$(null),{annotations:W,addAnnotationWithId:H,removeAnnotation:N,updateAnnotation:O,addAnnotationImage:B,removeAnnotationImage:A,activeAnnotationId:T,setActiveAnnotationId:M,registerCanvasRendered:y}=T1(),L=t0(()=>W.filter((C)=>!C.filePath&&(!C.canvasFile||C.canvasFile===Q)),[W,Q]),[w,j]=f1(null),[k,m]=f1(null),[D,v]=f1(null),[u,d]=f1(null),[K1,R]=f1(!1);e1(()=>{_(!0),G(null),d(null),X.loadCanvasModule(Q,$).then((C)=>{q(()=>C.default),_(!1)}).catch((C)=>{let E=C instanceof Error?C:Error(String(C));G(E.message),_(!1),Y({revision:$,filename:Q,message:E.message,...E.stack?{stack:E.stack}:{}})})},[J,$,Q,Y]),e1(()=>{if(Z)y(Q)},[Z,Q,y]);let g=document.getElementById("plan-scroll-container"),{popovers:p,isPopoverOpen:t}=n1({containerRef:z,restoreKey:Z,restoreAnnotations:L,extractContext:(C)=>o1(C,z.current),canvasFile:Q,scrollContainer:g}),{popovers:l,isDrawing:o,isPopoverOpen:q1}=A5({containerRef:z,restoreKey:Z,canvasFile:Q,scrollContainer:g}),X1=t||q1,z1=t0(()=>{let C=new Map;for(let E of L)if(E.snippet.startsWith("["))C.set(E.snippet,E.id);return C},[L]);e1(()=>{let C=z.current;if(!C)return;let E=(P)=>{if(D||X1||o)return;let S=P.target;if(S.closest("[data-block-comment-btn]"))return;R(!1);let V=S.closest(P0);if(V&&C.contains(V)){let U1=B0(C).indexOf(V);d(U1>=0?U1:null)}else d(null);let i=S.closest(a1);if(i&&C.contains(i)){m(i);let Q1=m1(i),U1=Q1?z1.get(Q1):void 0;if(U1&&U1!==T)M(U1)}else m(null)},b=(P)=>{if(D||X1)return;if(P.relatedTarget?.closest("[data-block-comment-btn]"))return;m(null),M(null)};return C.addEventListener("mousemove",E),C.addEventListener("mouseleave",b),()=>{C.removeEventListener("mousemove",E),C.removeEventListener("mouseleave",b)}},[Z,D,X1,o,z1,T]),e1(()=>{let C=(E)=>{let b=E.target.tagName;if(b==="INPUT"||b==="TEXTAREA"||E.target.isContentEditable)return;if(D||X1)return;let P=z.current;if(!P)return;if(E.key==="ArrowDown"){E.preventDefault(),R(!0);let S=B0(P);if(S.length===0)return;d((V)=>{if(V===null)return 0;return Math.min(V+1,S.length-1)})}else if(E.key==="ArrowUp"){E.preventDefault(),R(!0);let S=B0(P);if(S.length===0)return;d((V)=>{if(V===null)return S.length-1;return Math.max(V-1,0)})}else if(E.key==="a"||E.key==="A"){if(u===null||!P)return;let V=B0(P)[u];if(!V)return;if(!V.matches(a1))return;E.preventDefault();let i=m1(V);if(!i)return;let Q1=z1.get(i);if(Q1)M(Q1),v({anchorEl:V,snippet:i,annId:Q1});else v({anchorEl:V,snippet:i})}else if(E.key===" "||E.key==="Enter"){if(u===null)return;let V=B0(P)[u];if(!V)return;let i=V.getAttribute("data-md");if(i==="choice-option"||i==="multichoice-option")E.preventDefault(),V.dispatchEvent(new CustomEvent("kb-select",{bubbles:!0}));else if(i==="userinput"){E.preventDefault();let Q1=V.querySelector("textarea");if(Q1){Q1.focus();let U1=(P1)=>{if(P1.key==="Escape")P1.preventDefault(),Q1.blur(),R(!0)};Q1.addEventListener("keydown",U1),Q1.addEventListener("blur",()=>Q1.removeEventListener("keydown",U1),{once:!0})}}else if(i==="rangeinput"){E.preventDefault();let Q1=V.querySelector("input[type='range']");if(Q1){Q1.focus();let U1=(P1)=>{if(P1.key==="Escape"||P1.key==="ArrowUp"||P1.key==="ArrowDown")P1.preventDefault(),Q1.blur(),R(!0)};Q1.addEventListener("keydown",U1),Q1.addEventListener("blur",()=>Q1.removeEventListener("keydown",U1),{once:!0})}}}else if(E.key==="Escape")d(null),R(!1),M(null)};return document.addEventListener("keydown",C),()=>document.removeEventListener("keydown",C)},[u,D,X1,z1]),e1(()=>{let C=z.current;if(!C||u===null||!K1)return;let b=B0(C)[u];if(!b)return;b.style.outline="2px solid var(--color-accent-blue)",b.style.outlineOffset="-2px",b.style.borderRadius="8px",b.scrollIntoView({block:"nearest",behavior:"smooth"});let P=m1(b),S=P?z1.get(P):void 0;if(S)M(S);return()=>{b.style.outline="",b.style.outlineOffset="",b.style.borderRadius=""}},[u,K1,z1]);let M1=t0(()=>Z?J1(Z,{},void 0,!1,void 0,this):null,[Z]);if(K)return J1("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-body",children:"Loading canvas..."},void 0,!1,void 0,this);if(U)return J1(v3,{message:U},void 0,!1,void 0,this);if(!Z)return J1("div",{className:"text-text-tertiary text-center py-8 font-body text-body",children:"No canvas loaded"},void 0,!1,void 0,this);return J1(F$.Provider,{value:Q,children:[J1("div",{ref:z,className:"plan-content plan-updated","data-canvas-file":Q,children:J1(f3,{revision:$,filename:Q,reportError:Y,children:M1},`${$}:${Q}`,!1,void 0,this)},void 0,!1,void 0,this),w&&J1(M$,{note:w.note,onSave:(C)=>{O(w.id,C),j(null)},onCancel:()=>j(null)},void 0,!1,void 0,this),p,l,J1(O$,{containerRef:z,hoveredBlock:k,focusedBlockIndex:u,blockPopover:D,blockAnnotationMap:z1,activeAnnotationId:T,onOpen:(C,E,b)=>{if(b)M(b),v({anchorEl:C,snippet:E,annId:b});else v({anchorEl:C,snippet:E})}},void 0,!1,void 0,this),D&&!D.annId&&J1(x1,{anchorEl:D.anchorEl,scrollContainer:g,snippet:D.snippet,truncateAt:80,onAdd:(C,E)=>{let b=O1();H(b,D.snippet,C,void 0,void 0,E,Q),v(null)},onCancel:()=>v(null)},void 0,!1,void 0,this),D?.annId&&(()=>{let C=L.find((E)=>E.id===D.annId);if(!C)return null;return J1(W0,{anchorEl:D.anchorEl,scrollContainer:g,initialNote:C.note,initialImages:C.images,onUpdate:(E,b)=>{O(D.annId,E);let P=C.images||[];for(let S of b)if(!P.includes(S))B(D.annId,S);for(let S of P)if(!b.includes(S))A(D.annId,S)},onDelete:()=>{N(D.annId),M(null),v(null)},onClose:()=>v(null)},void 0,!1,void 0,this)})()]},void 0,!0,void 0,this)}function B0($){return Array.from($.querySelectorAll(P0))}function O$({containerRef:$,hoveredBlock:Q,focusedBlockIndex:J,blockPopover:X,blockAnnotationMap:Y,activeAnnotationId:Z,onOpen:q}){let[U,G]=f1([]);e1(()=>{let H=$.current;if(!H||Y.size===0){G([]);return}let N=[];for(let O of H.querySelectorAll(a1)){let B=m1(O);if(B&&Y.has(B))N.push(O)}G(N)},[Y,$.current]);let[K,_]=f1(null);e1(()=>{if(!Z||!$.current){_(null);return}for(let H of $.current.querySelectorAll(P0)){let N=m1(H);if(N&&Y.get(N)===Z){_(H);return}}_(null)},[Z,Y]),e1(()=>{if(!K)return;return K.style.boxShadow="inset 0 0 0 1.5px var(--color-highlight-bg)",K.style.borderRadius="8px",()=>{K.style.boxShadow="",K.style.borderRadius=""}},[K]);let z=t0(()=>{if(J===null||!$.current)return null;let H=B0($.current)[J];if(!H)return null;return H.matches(a1)?H:null},[J,$.current]),W=t0(()=>{let H=new Set(U);if(Q)H.add(Q);if(z)H.add(z);if(X?.anchorEl)H.add(X.anchorEl);return Array.from(H)},[U,Q,z,X]);return J1(P$,{children:W.map((H)=>J1(L$,{block:H,isHovered:H===Q||H===z||H===X?.anchorEl,blockAnnotationMap:Y,activeAnnotationId:Z,onOpen:q},H.getAttribute("data-task-id")||H.getAttribute("data-md-title")||H.textContent?.slice(0,30)||"block",!1,void 0,this))},void 0,!1,void 0,this)}function L$({block:$,isHovered:Q,blockAnnotationMap:J,activeAnnotationId:X,onOpen:Y}){let Z=m1($);if(!Z)return null;let q=J.get(Z),U=!!q;return B$(J1("button",{"data-block-comment-btn":!0,onClick:(K)=>{K.stopPropagation(),Y(K.currentTarget,Z,q)},className:`absolute top-1 right-1 z-10 w-6 h-6 flex items-center justify-center rounded transition-all duration-150 ${U?q===X?"text-accent-amber bg-accent-amber-muted":"text-accent-amber opacity-60 hover:opacity-100":Q?"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:U?"Edit annotation":"Add annotation",children:J1("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:U?"currentColor":"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:J1("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),$)}function M$({note:$,onSave:Q,onCancel:J}){let[X,Y]=j2.useState($),Z=j2.useRef(null);return j2.useEffect(()=>{Z.current?.focus(),Z.current?.select()},[]),J1("div",{className:"fixed inset-0 z-50 bg-black/40 flex items-center justify-center",onClick:J,children:J1("div",{className:"bg-bg-elevated border border-border-hover rounded-lg shadow-md p-4 w-80",onClick:(q)=>q.stopPropagation(),children:[J1("div",{className:"text-tiny uppercase tracking-widest text-text-tertiary font-body mb-2",children:"Edit annotation"},void 0,!1,void 0,this),J1("textarea",{ref:Z,value:X,onChange:(q)=>Y(q.currentTarget.value),className:"w-full bg-transparent border-none text-body font-body text-text-primary resize-vertical focus:outline-none min-h-[60px]",onKeyDown:(q)=>{if(q.key==="Enter"&&(q.ctrlKey||q.metaKey))Q(X.trim());if(q.key==="Escape")J()}},void 0,!1,void 0,this),J1("div",{className:"flex justify-end gap-2 mt-2",children:[J1("button",{onClick:J,className:"text-meta text-text-tertiary font-body px-3 py-1",children:"Cancel"},void 0,!1,void 0,this),J1("button",{onClick:()=>Q(X.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{useState as RQ}from"react";import wQ from"react";import{jsxDEV as IQ}from"react/jsx-dev-runtime";a.setOptions({gfm:!0,breaks:!1});import{jsxDEV as EQ}from"react/jsx-dev-runtime";import{jsxDEV as uQ}from"react/jsx-dev-runtime";import{useEffect as cQ,useRef as dQ}from"react";import{jsxDEV as rQ}from"react/jsx-dev-runtime";import{jsxDEV as sQ}from"react/jsx-dev-runtime";import{jsxDEV as $J}from"react/jsx-dev-runtime";import{jsxDEV as YJ}from"react/jsx-dev-runtime";import{jsxDEV as ZJ}from"react/jsx-dev-runtime";import{jsxDEV as KJ}from"react/jsx-dev-runtime";import{useEffect as WJ,useState as NJ,useContext as BJ,useRef as TJ}from"react";import{SessionContext as OJ,ActiveViewCtx as LJ}from"#canvas/runtime";import{jsxDEV as PJ}from"react/jsx-dev-runtime";import{useEffect as wJ,useRef as CJ,useState as bJ,useCallback as IJ}from"react";import VJ from"react-dom";import{useAnnotations as RJ,useCanvasFile as DJ}from"#canvas/runtime";import{jsxDEV as xJ,Fragment as fJ}from"react/jsx-dev-runtime";import{jsxDEV as cJ}from"react/jsx-dev-runtime";import{useEffect as tJ,useMemo as nJ,useRef as eJ,useState as $Y}from"react";import{useAnnotations as JY,useResponseRegistration as YY}from"#canvas/runtime";import{jsxDEV as iJ}from"react/jsx-dev-runtime";import{jsxDEV as ZY}from"react/jsx-dev-runtime";import{useRef as zY,useState as _Y}from"react";import{useAnnotations as WY,useResponseRegistration as NY}from"#canvas/runtime";import{jsxDEV as OY}from"react/jsx-dev-runtime";import{useContext as yY,useState as SY}from"react";import{SessionContext as wY}from"#canvas/runtime";import{jsxDEV as bY}from"react/jsx-dev-runtime";import{useMemo as kY}from"react";import{jsxDEV as mY}from"react/jsx-dev-runtime";a.setOptions({gfm:!0,breaks:!1});import{useFeedback as TX}from"#canvas/runtime";import{useEffect as E$,useState as o3,useContext as a3,useMemo as x$}from"react";import{SessionContext as f$}from"#canvas/runtime";var u3={alg:"AES-GCM",v:1};async function g3($){let Q=w$($);return crypto.subtle.importKey("raw",Q,{name:"AES-GCM",length:256},!1,["encrypt","decrypt"])}async function $0($,Q){let J=crypto.getRandomValues(new Uint8Array(12)),X=new TextEncoder().encode(Q),Y=await crypto.subtle.encrypt({name:"AES-GCM",iv:J},$,X),Z=new Uint8Array(J.byteLength+Y.byteLength);return Z.set(J,0),Z.set(new Uint8Array(Y),J.byteLength),A$(Z)}async function n0($,Q){let J=h3(Q);if(J.byteLength<28)throw Error("Ciphertext too short");let X=J.subarray(0,12),Y=J.subarray(12),Z=await crypto.subtle.decrypt({name:"AES-GCM",iv:X},$,Y);return new TextDecoder().decode(Z)}function A$($){let Q="",J=32768;for(let X=0;X<$.byteLength;X+=J)Q+=String.fromCharCode.apply(null,Array.from($.subarray(X,X+J)));return btoa(Q)}function h3($){let Q=atob($),J=new Uint8Array(Q.length);for(let X=0;X<Q.length;X++)J[X]=Q.charCodeAt(X);return J}function w$($){let Q=$.replace(/-/g,"+").replace(/_/g,"/")+"===".slice(($.length+3)%4);return h3(Q)}function C$(){if(typeof window>"u")return null;let $=window.location.hash.replace(/^#/,"");if(!$)return null;for(let Q of $.split("&")){let[J,X]=Q.split("=");if(J==="k"&&X)return decodeURIComponent(X)}return null}function b$(){if(typeof window<"u"&&window.__CANVAS_SHARE__?.shareId){let Q=C$();return{isShared:!0,shareId:window.__CANVAS_SHARE__.shareId,encryptionKey:Q?g3(Q):null}}return{isShared:!1,sessionId:typeof window<"u"?window.location.pathname.replace("/s/",""):""}}var $1=b$();function I$(){return $1.isShared&&$1.encryptionKey!==null}function j$(){return $1.isShared?$1.shareId:$1.sessionId}function V$(){if($1.isShared)return`/s/${$1.shareId}/meta`;return`/api/session/${$1.sessionId}/meta`}function k$($,Q){let J=$.replace(/\.jsx$/,".js");if($1.isShared)return`/s/${$1.shareId}/canvas/${encodeURIComponent(J)}`;let X=Q?`?rev=${Q}&t=${Date.now()}`:`?t=${Date.now()}`;return`/api/session/${$1.sessionId}/canvas/${encodeURIComponent(J)}${X}`}function R$(){if($1.isShared)return`/s/${$1.shareId}/upload`;return`/api/session/${$1.sessionId}/upload`}async function p3(){let $=await fetch(V$());if(!$.ok)throw Error(`meta ${$.status}`);let Q=await $.json();if(Q.encryption&&$1.isShared&&$1.encryptionKey){let J=await $1.encryptionKey;if(Q.origin){let Y={...Q.origin};if(Y.sessionId)Y.sessionId=await n0(J,Y.sessionId);if(Y.label)Y.label=await n0(J,Y.label);Q.origin=Y}let X=Q.revisions;if(Array.isArray(X)){for(let Y of X)if(Y.label)try{Y.label=await n0(J,Y.label)}catch{}}}return Q}async function D$($,Q){let J=k$($,Q);if(!I$())return import(J);let X=await fetch(J);if(!X.ok)throw Error(`canvas ${X.status}`);let Y=await X.text(),Z=await $1.encryptionKey,q=await n0(Z,Y),U=new Blob([q],{type:"application/javascript"}),G=URL.createObjectURL(U);try{return await import(G)}finally{setTimeout(()=>URL.revokeObjectURL(G),0)}}var c3="canvas-reviewer-identity";function C5(){try{let $=localStorage.getItem(c3);if(!$)return null;return JSON.parse($)}catch{return null}}function d3($){let Q=C5();if(!Q)Q={id:crypto.randomUUID?.()||String(Date.now()),name:$};else Q.name=$;return localStorage.setItem(c3,JSON.stringify(Q)),Q}async function m$($,Q){let J=await Promise.all($.annotations.map(async(X)=>{let Y={id:X.id,createdAt:X.createdAt,snippet:await $0(Q,String(X.snippet??"")),note:await $0(Q,String(X.note??""))};if(X.filePath)Y.filePath=await $0(Q,String(X.filePath));if(X.canvasFile)Y.canvasFile=await $0(Q,String(X.canvasFile));if(X.context!==void 0&&X.context!==null)Y.context=await $0(Q,JSON.stringify(X.context));if(X.attachments)Y.attachments=X.attachments;return Y}));return{author:{id:$.author.id,name:await $0(Q,$.author.name)},revision:$.revision,annotations:J,...$.generalNote?{generalNote:await $0(Q,$.generalNote)}:{},encryption:u3}}async function l3($){if(!$1.isShared)throw Error("submitSharedFeedback called outside shared mode");let Q=$;if($1.encryptionKey){let X=await $1.encryptionKey;Q=await m$($,X)}let J=await fetch(`/s/${$1.shareId}/feedback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Q)});if(!J.ok){let X=await J.text().catch(()=>"");throw Error(`Feedback submission failed: ${J.status} ${X}`)}}var p1=!$1.isShared,r3=!$1.isShared,i3={get sessionId(){return j$()},isShared:$1.isShared,fsAvailable:p1,uploadUrl:R$,loadCanvasModule:D$};import{jsxDEV as c,Fragment as b5}from"react/jsx-dev-runtime";function s3({embedded:$}={}){let Q=a3(f$),{annotations:J,addAnnotation:X}=v1(),{setActiveView:Y}=a3(E1),[Z,q]=o3(!1),[U,G]=o3({});if(!p1)return c("div",{className:$?"px-4 py-3":"p-4",children:[c("div",{className:"text-[11px] uppercase tracking-widest text-text-tertiary font-body mb-2",children:"Files"},void 0,!1,void 0,this),c("p",{className:"text-[11px] text-text-tertiary font-body leading-relaxed",children:"File browsing is not available in shared view. File previews embedded in the canvas still work."},void 0,!1,void 0,this)]},void 0,!0,void 0,this);let{annCountMap:K,annotatedFiles:_}=x$(()=>{let T=new Map;for(let M of J)if(M.filePath&&M.filePath!==I1)T.set(M.filePath,(T.get(M.filePath)||0)+1);return{annCountMap:T,annotatedFiles:[...T.keys()]}},[J]),z=async(T)=>{let y=await(await fetch(`/api/tree?session=${Q}&path=${encodeURIComponent(T)}`)).json();if(y.entries)G((L)=>({...L,[T]:{entries:y.entries,expanded:!0,loaded:!0}}))};E$(()=>{if(!Z&&!U[""])z("")},[Z]);let W=(T)=>{if(U[T]?.loaded)G((M)=>({...M,[T]:{...M[T],expanded:!M[T].expanded}}));else z(T)},H=(T)=>{Y({type:"file",path:T})},N=async(T)=>{let y=await(await fetch(`/api/file?session=${Q}&path=${encodeURIComponent(T)}`)).json();if(!y.error){let L=y.content.split(`
70
70
  `).slice(0,3).join(`
71
- `)+(S.content.split(`
71
+ `)+(y.content.split(`
72
72
  `).length>3?`
73
- ...`:"");Q(M,"Include this file for context",O)}},L=async(O)=>{let R=[];if(G[O]?.loaded)R=G[O].entries;else{let M=await(await fetch(`/api/tree?session=${$}&path=${encodeURIComponent(O)}`)).json();if(M.entries)R=M.entries}await Promise.all(R.filter((S)=>S.type==="file").map((S)=>K(O?`${O}/${S.name}`:S.name)))},N=(O)=>_.get(O)||0,y=(O,R=0)=>{let S=G[O];if(!S?.expanded)return null;return S.entries.map((M)=>{let b=O?`${O}/${M.name}`:M.name,g=N(b);return r("div",{children:[r("div",{className:"group/item flex items-center py-[3px] hover:bg-bg-elevated text-[13px] font-body cursor-default transition-colors duration-100",style:{paddingLeft:`${16+R*16}px`,paddingRight:"8px"},children:M.type==="dir"?r(h2,{children:[r("span",{onClick:()=>W(b),className:"flex items-center gap-1.5 flex-1 text-text-secondary hover:text-text-primary cursor-pointer truncate",children:[r(g1,{name:M.name,type:"dir",expanded:G[b]?.expanded},void 0,!1,void 0,this),r("span",{className:"truncate",children:M.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("button",{onClick:(C)=>{C.stopPropagation(),L(b)},className:"text-[11px] text-text-tertiary hover:text-text-secondary opacity-0 group-hover/item:opacity-100 transition-opacity px-1 flex-shrink-0",title:"Add all files in folder",children:"+"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):r(h2,{children:[r("span",{onClick:()=>T(b),className:`flex-1 truncate cursor-pointer flex items-center gap-1.5 ${g>0?"text-text-primary":"text-text-secondary hover:text-text-primary"}`,children:[r(g1,{name:M.name,type:"file"},void 0,!1,void 0,this),r("span",{className:"truncate",children:M.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("div",{className:"flex items-center gap-1 flex-shrink-0 ml-1",children:[g>0&&r("span",{className:"text-[10px] font-medium bg-badge-bg text-accent-amber px-1.5 py-px rounded-full min-w-[18px] text-center",children:g},void 0,!1,void 0,this),r("button",{onClick:(C)=>{C.stopPropagation(),K(b)},className:"text-[11px] text-text-tertiary hover:text-text-secondary opacity-0 group-hover/item:opacity-100 transition-opacity px-1",title:"Add file to context",children:"+"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),M.type==="dir"&&y(b,R+1)]},b,!0,void 0,this)})};if(Z)return r(h2,{children:[r("div",{className:"flex items-center justify-between px-4 pt-3 pb-2 flex-shrink-0",children:r("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:"Files"},void 0,!1,void 0,this)},void 0,!1,void 0,this),r("div",{className:"flex-1 overflow-y-auto",children:y("")},void 0,!1,void 0,this),H.length>0&&r("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:[r("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body mb-1.5",children:"Referenced"},void 0,!1,void 0,this),H.map((O)=>r("div",{onClick:()=>T(O),className:"flex items-center justify-between text-[12px] font-body text-text-secondary hover:text-text-primary cursor-pointer py-0.5",children:[r("span",{className:"truncate",children:O.split("/").pop()},void 0,!1,void 0,this),r("span",{className:"text-[10px] font-medium bg-badge-bg text-accent-amber px-1.5 py-px rounded-full min-w-[18px] text-center flex-shrink-0 ml-1",children:N(O)},void 0,!1,void 0,this)]},O,!0,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);if(Y)return r("div",{className:"hidden lg:flex w-8 border-r border-border-subtle bg-bg-surface flex-col items-center flex-shrink-0",children:r("button",{onClick:()=>X(!1),className:"mt-3 p-1 text-text-tertiary hover:text-text-secondary transition-colors",children:r("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:r("path",{d:"M5 3l4 4-4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this);return r("div",{className:"hidden lg:flex w-60 border-r border-border-subtle bg-bg-surface flex-col flex-shrink-0 overflow-hidden",children:[r("div",{className:"flex items-center justify-between px-4 pt-4 pb-3 flex-shrink-0",children:[r("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:"Files"},void 0,!1,void 0,this),r("button",{onClick:()=>X(!0),className:"text-text-tertiary hover:text-text-secondary transition-colors p-0.5",children:r("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:r("path",{d:"M9 3l-4 4 4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),r("div",{className:"flex-1 overflow-y-auto",children:y("")},void 0,!1,void 0,this),H.length>0&&r("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:[r("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body mb-1.5",children:"Referenced"},void 0,!1,void 0,this),H.map((O)=>r("div",{onClick:()=>T(O),className:"flex items-center justify-between text-[12px] font-body text-text-secondary hover:text-text-primary cursor-pointer py-0.5",children:[r("span",{className:"truncate",children:O.split("/").pop()},void 0,!1,void 0,this),r("span",{className:"text-[10px] font-medium bg-badge-bg text-accent-amber px-1.5 py-px rounded-full min-w-[18px] text-center flex-shrink-0 ml-1",children:N(O)},void 0,!1,void 0,this)]},O,!0,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}import{useEffect as n3,useState as G0,useContext as V4,useCallback as I4,useRef as Y2,useMemo as e3}from"react";import{SessionContext as R4}from"#canvas/runtime";var Q2={ts:"typescript",tsx:"typescript",js:"javascript",jsx:"javascript",py:"python",rs:"rust",go:"go",rb:"ruby",java:"java",json:"json",yaml:"yaml",yml:"yaml",md:"markdown",css:"css",html:"html",sh:"bash",bash:"bash",toml:"toml",sql:"sql",xml:"xml",c:"c",cpp:"cpp",h:"c"};import{jsxDEV as W1}from"react/jsx-dev-runtime";function $5(Z){let $=Z instanceof HTMLElement?Z:Z.parentElement;while($){if($.hasAttribute("data-line-num"))return $;$=$.parentElement}return null}function D4(Z){let $=Z.toString().trim(),q=$5(Z.startContainer),Q=$5(Z.endContainer),J=q?parseInt(q.getAttribute("data-line-num"),10):void 0,Y=Q?parseInt(Q.getAttribute("data-line-num"),10):void 0,X="",G="";if($.length<30&&q&&q===Q){let z=q.querySelector("code");if(z){let _=z.textContent||"",H=_.indexOf($);if(H>=0)X=_.slice(0,H).trimStart(),G=_.slice(H+$.length).trimEnd()}}return{before:X,after:G,hierarchy:[],lineStart:J,lineEnd:Y}}function Z5({path:Z}){if(!M1)return W1("div",{className:"max-w-[720px] mx-auto px-6 pt-12 pb-32",children:W1("div",{className:"p-4 rounded-lg border border-border-subtle bg-bg-surface",children:[W1("div",{className:"text-[11px] uppercase tracking-widest text-text-tertiary font-body mb-2",children:"File not available"},void 0,!1,void 0,this),W1("p",{className:"text-[13px] text-text-secondary font-body leading-relaxed",children:["Opening ",W1("code",{className:"px-1 py-0.5 rounded bg-bg-elevated text-text-primary text-[11px]",children:Z},void 0,!1,void 0,this)," requires filesystem access, which isn't available in shared view. If the canvas author wanted this file visible, they should embed it as a ",W1("code",{className:"px-1 py-0.5 rounded bg-bg-elevated text-text-primary text-[11px]",children:"<FilePreview>"},void 0,!1,void 0,this)," in the canvas."]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this);let $=V4(R4),{annotations:q,addAnnotationWithId:Q,activeAnnotationId:J,setActiveAnnotationId:Y}=X1(),[X,G]=G0(null),[z,_]=G0("text"),[H,U]=G0(!0),[W,T]=G0(null),K=Y2(null),[L,N]=G0(null),[y,O]=G0(null),R=Y2(null),S=Y2(null),M=Y2([]),b=q.filter((j)=>j.filePath===Z),g=K.current?.closest("#plan-scroll-container"),{popovers:C,openCreatePopover:p}=t1({containerRef:K,restoreKey:`${X}:${Z}`,restoreAnnotations:b,extractContext:D4,filePath:Z,scrollContainer:g});n3(()=>{U(!0),T(null),fetch(`/api/file?session=${$}&path=${encodeURIComponent(Z)}`).then((j)=>j.json()).then((j)=>{if(j.error)T(j.error),U(!1);else G(j.content),_(j.language||"text"),U(!1)}).catch(()=>{T("Failed to fetch file"),U(!1)})},[$,Z]);let h=I4((j,f)=>{j.preventDefault(),R.current=f,S.current=f,N(f),O(f)},[]);n3(()=>{let j=(v)=>{if(R.current===null)return;let o=v.target.closest("[data-line-num]");if(o){let w=parseInt(o.getAttribute("data-line-num"),10);S.current=w,O(w)}},f=()=>{let v=R.current;if(v===null)return;R.current=null;let o=S.current??v,w=Math.min(v,o),B=Math.max(v,o),u=M.current.slice(w-1,B).join(`
74
- `);if(!u.trim()){N(null),O(null);return}let D=`__pending_${Date.now()}`,a={before:"",after:"",hierarchy:[],lineStart:w,lineEnd:B};if(K.current){let I=K.current.querySelectorAll("[data-line-num]"),E=I[w-1],Z1=I[B-1];if(E&&Z1){let I1=E.querySelector("code"),S1=Z1.querySelector("code");if(I1&&S1)try{let H0=document.createRange();H0.setStartBefore(I1.firstChild||I1),H0.setEndAfter(S1.lastChild||S1),o1(H0,D)}catch{}}let Y1=I[B-1];if(Y1)p(Y1,D,u,a)}N(null),O(null)};return document.addEventListener("mousemove",j),document.addEventListener("mouseup",f),()=>{document.removeEventListener("mousemove",j),document.removeEventListener("mouseup",f)}},[]);let V=e3(()=>{if(!X)return null;let j=window.hljs;if(!j)return null;let f=Z.split(".").pop()||"",v=Q2[f];try{return(v?j.highlight(X,{language:v}):j.highlightAuto(X)).value.split(`
75
- `)}catch{return null}},[X,Z]);if(H)return W1("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-[13px]",children:["Loading ",Z,"..."]},void 0,!0,void 0,this);if(W)return W1("div",{className:"p-8 text-accent-red font-body text-[13px]",children:W},void 0,!1,void 0,this);if(!X)return null;let k=X.split(`
76
- `);M.current=k;let x=e3(()=>{if(L===null)return null;let j=y??L;return{start:Math.min(L,j),end:Math.max(L,j)}},[L,y]),l=()=>{let j=X.split(`
73
+ ...`:"");X(L,"Include this file for context",T)}},O=async(T)=>{let M=[];if(U[T]?.loaded)M=U[T].entries;else{let L=await(await fetch(`/api/tree?session=${Q}&path=${encodeURIComponent(T)}`)).json();if(L.entries)M=L.entries}await Promise.all(M.filter((y)=>y.type==="file").map((y)=>N(T?`${T}/${y.name}`:y.name)))},B=(T)=>K.get(T)||0,A=(T,M=0)=>{let y=U[T];if(!y?.expanded)return null;return y.entries.map((L)=>{let w=T?`${T}/${L.name}`:L.name,j=B(w);return c("div",{children:[c("div",{className:"group/item flex items-center py-[3px] hover:bg-bg-elevated text-[13px] font-body cursor-default transition-colors duration-100",style:{paddingLeft:`${16+M*16}px`,paddingRight:"8px"},children:L.type==="dir"?c(b5,{children:[c("span",{onClick:()=>W(w),className:"flex items-center gap-1.5 flex-1 text-text-secondary hover:text-text-primary cursor-pointer truncate",children:[c(t1,{name:L.name,type:"dir",expanded:U[w]?.expanded},void 0,!1,void 0,this),c("span",{className:"truncate",children:L.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this),c("button",{onClick:(k)=>{k.stopPropagation(),O(w)},className:"text-[11px] text-text-tertiary hover:text-text-secondary opacity-0 group-hover/item:opacity-100 transition-opacity px-1 flex-shrink-0",title:"Add all files in folder",children:"+"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):c(b5,{children:[c("span",{onClick:()=>H(w),className:`flex-1 truncate cursor-pointer flex items-center gap-1.5 ${j>0?"text-text-primary":"text-text-secondary hover:text-text-primary"}`,children:[c(t1,{name:L.name,type:"file"},void 0,!1,void 0,this),c("span",{className:"truncate",children:L.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this),c("div",{className:"flex items-center gap-1 flex-shrink-0 ml-1",children:[j>0&&c("span",{className:"text-[10px] font-medium bg-badge-bg text-accent-amber px-1.5 py-px rounded-full min-w-[18px] text-center",children:j},void 0,!1,void 0,this),c("button",{onClick:(k)=>{k.stopPropagation(),N(w)},className:"text-[11px] text-text-tertiary hover:text-text-secondary opacity-0 group-hover/item:opacity-100 transition-opacity px-1",title:"Add file to context",children:"+"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),L.type==="dir"&&A(w,M+1)]},w,!0,void 0,this)})};if($)return c(b5,{children:[c("div",{className:"flex items-center justify-between px-4 pt-3 pb-2 flex-shrink-0",children:c("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:"Files"},void 0,!1,void 0,this)},void 0,!1,void 0,this),c("div",{className:"flex-1 overflow-y-auto",children:A("")},void 0,!1,void 0,this),_.length>0&&c("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:[c("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body mb-1.5",children:"Referenced"},void 0,!1,void 0,this),_.map((T)=>c("div",{onClick:()=>H(T),className:"flex items-center justify-between text-[12px] font-body text-text-secondary hover:text-text-primary cursor-pointer py-0.5",children:[c("span",{className:"truncate",children:T.split("/").pop()},void 0,!1,void 0,this),c("span",{className:"text-[10px] font-medium bg-badge-bg text-accent-amber px-1.5 py-px rounded-full min-w-[18px] text-center flex-shrink-0 ml-1",children:B(T)},void 0,!1,void 0,this)]},T,!0,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);if(Z)return c("div",{className:"hidden lg:flex w-8 border-r border-border-subtle bg-bg-surface flex-col items-center flex-shrink-0",children:c("button",{onClick:()=>q(!1),className:"mt-3 p-1 text-text-tertiary hover:text-text-secondary transition-colors",children:c("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:c("path",{d:"M5 3l4 4-4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this);return c("div",{className:"hidden lg:flex w-60 border-r border-border-subtle bg-bg-surface flex-col flex-shrink-0 overflow-hidden",children:[c("div",{className:"flex items-center justify-between px-4 pt-4 pb-3 flex-shrink-0",children:[c("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:"Files"},void 0,!1,void 0,this),c("button",{onClick:()=>q(!0),className:"text-text-tertiary hover:text-text-secondary transition-colors p-0.5",children:c("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:c("path",{d:"M9 3l-4 4 4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),c("div",{className:"flex-1 overflow-y-auto",children:A("")},void 0,!1,void 0,this),_.length>0&&c("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:[c("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body mb-1.5",children:"Referenced"},void 0,!1,void 0,this),_.map((T)=>c("div",{onClick:()=>H(T),className:"flex items-center justify-between text-[12px] font-body text-text-secondary hover:text-text-primary cursor-pointer py-0.5",children:[c("span",{className:"truncate",children:T.split("/").pop()},void 0,!1,void 0,this),c("span",{className:"text-[10px] font-medium bg-badge-bg text-accent-amber px-1.5 py-px rounded-full min-w-[18px] text-center flex-shrink-0 ml-1",children:B(T)},void 0,!1,void 0,this)]},T,!0,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}import{useEffect as t3,useState as w0,useContext as v$,useCallback as u$,useRef as k2,useMemo as n3}from"react";import{SessionContext as g$}from"#canvas/runtime";var V2={ts:"typescript",tsx:"typescript",js:"javascript",jsx:"javascript",py:"python",rs:"rust",go:"go",rb:"ruby",java:"java",json:"json",yaml:"yaml",yml:"yaml",md:"markdown",css:"css",html:"html",sh:"bash",bash:"bash",toml:"toml",sql:"sql",xml:"xml",c:"c",cpp:"cpp",h:"c"};import{jsxDEV as L1}from"react/jsx-dev-runtime";function e3($){let Q=$ instanceof HTMLElement?$:$.parentElement;while(Q){if(Q.hasAttribute("data-line-num"))return Q;Q=Q.parentElement}return null}function h$($){let Q=$.toString().trim(),J=e3($.startContainer),X=e3($.endContainer),Y=J?parseInt(J.getAttribute("data-line-num"),10):void 0,Z=X?parseInt(X.getAttribute("data-line-num"),10):void 0,q="",U="";if(Q.length<30&&J&&J===X){let G=J.querySelector("code");if(G){let K=G.textContent||"",_=K.indexOf(Q);if(_>=0)q=K.slice(0,_).trimStart(),U=K.slice(_+Q.length).trimEnd()}}return{before:q,after:U,hierarchy:[],lineStart:Y,lineEnd:Z}}function $4({path:$}){if(!p1)return L1("div",{className:"max-w-[720px] mx-auto px-6 pt-12 pb-32",children:L1("div",{className:"p-4 rounded-lg border border-border-subtle bg-bg-surface",children:[L1("div",{className:"text-[11px] uppercase tracking-widest text-text-tertiary font-body mb-2",children:"File not available"},void 0,!1,void 0,this),L1("p",{className:"text-[13px] text-text-secondary font-body leading-relaxed",children:["Opening ",L1("code",{className:"px-1 py-0.5 rounded bg-bg-elevated text-text-primary text-[11px]",children:$},void 0,!1,void 0,this)," requires filesystem access, which isn't available in shared view. If the canvas author wanted this file visible, they should embed it as a ",L1("code",{className:"px-1 py-0.5 rounded bg-bg-elevated text-text-primary text-[11px]",children:"<FilePreview>"},void 0,!1,void 0,this)," in the canvas."]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this);let Q=v$(g$),{annotations:J,addAnnotationWithId:X,activeAnnotationId:Y,setActiveAnnotationId:Z}=v1(),[q,U]=w0(null),[G,K]=w0("text"),[_,z]=w0(!0),[W,H]=w0(null),N=k2(null),[O,B]=w0(null),[A,T]=w0(null),M=k2(null),y=k2(null),L=k2([]),w=J.filter((R)=>R.filePath===$),j=N.current?.closest("#plan-scroll-container"),{popovers:k,openCreatePopover:m}=n1({containerRef:N,restoreKey:`${q}:${$}`,restoreAnnotations:w,extractContext:h$,filePath:$,scrollContainer:j});t3(()=>{z(!0),H(null),fetch(`/api/file?session=${Q}&path=${encodeURIComponent($)}`).then((R)=>R.json()).then((R)=>{if(R.error)H(R.error),z(!1);else U(R.content),K(R.language||"text"),z(!1)}).catch(()=>{H("Failed to fetch file"),z(!1)})},[Q,$]);let D=u$((R,g)=>{R.preventDefault(),M.current=g,y.current=g,B(g),T(g)},[]);t3(()=>{let R=(p)=>{if(M.current===null)return;let t=p.target.closest("[data-line-num]");if(t){let l=parseInt(t.getAttribute("data-line-num"),10);y.current=l,T(l)}},g=()=>{let p=M.current;if(p===null)return;M.current=null;let t=y.current??p,l=Math.min(p,t),o=Math.max(p,t),X1=L.current.slice(l-1,o).join(`
74
+ `);if(!X1.trim()){B(null),T(null);return}let z1=`__pending_${Date.now()}`,M1={before:"",after:"",hierarchy:[],lineStart:l,lineEnd:o};if(N.current){let C=N.current.querySelectorAll("[data-line-num]"),E=C[l-1],b=C[o-1];if(E&&b){let S=E.querySelector("code"),V=b.querySelector("code");if(S&&V)try{let i=document.createRange();i.setStartBefore(S.firstChild||S),i.setEndAfter(V.lastChild||V),i1(i,z1)}catch{}}let P=C[o-1];if(P)m(P,z1,X1,M1)}B(null),T(null)};return document.addEventListener("mousemove",R),document.addEventListener("mouseup",g),()=>{document.removeEventListener("mousemove",R),document.removeEventListener("mouseup",g)}},[]);let v=n3(()=>{if(!q)return null;let R=window.hljs;if(!R)return null;let g=$.split(".").pop()||"",p=V2[g];try{return(p?R.highlight(q,{language:p}):R.highlightAuto(q)).value.split(`
75
+ `)}catch{return null}},[q,$]);if(_)return L1("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-[13px]",children:["Loading ",$,"..."]},void 0,!0,void 0,this);if(W)return L1("div",{className:"p-8 text-accent-red font-body text-[13px]",children:W},void 0,!1,void 0,this);if(!q)return null;let u=q.split(`
76
+ `);L.current=u;let d=n3(()=>{if(O===null)return null;let R=A??O;return{start:Math.min(O,R),end:Math.max(O,R)}},[O,A]),K1=()=>{let R=q.split(`
77
77
  `).slice(0,3).join(`
78
- `)+(k.length>3?`
79
- ...`:""),f=L1();Q(f,j,"",Z),Y(f)};return W1("div",{children:[W1("pre",{ref:K,className:"text-code font-mono text-text-code bg-bg-base select-text cursor-text py-3 hljs",children:k.map((j,f)=>{let v=f+1,o=x&&v>=x.start&&v<=x.end;return W1("div",{"data-line-num":v,className:`flex px-5 ${o?"bg-accent-blue/10":"hover:bg-bg-elevated-half"}`,children:[W1("span",{className:"text-text-tertiary select-none w-10 text-right pr-4 shrink-0 py-px text-[12px] cursor-pointer opacity-40 hover:opacity-100 hover:text-accent-blue",onMouseDown:(w)=>h(w,v),children:v},void 0,!1,void 0,this),V?W1("code",{className:"py-px",dangerouslySetInnerHTML:{__html:V[f]||" "}},void 0,!1,void 0,this):W1("code",{className:"py-px",children:j||" "},void 0,!1,void 0,this)]},f,!0,void 0,this)})},void 0,!1,void 0,this),C]},void 0,!0,void 0,this)}import{useEffect as q5,useState as J5,useRef as k4}from"react";import{jsxDEV as C1}from"react/jsx-dev-runtime";function Q5(Z,$){if($){let q=$.replace(/\/+$/,"").split("/");return q[q.length-1]||Z}return Z.length>30?Z.slice(0,30)+"...":Z}function p2({currentSessionId:Z,projectRoot:$}){let[q,Q]=J5([]),[J,Y]=J5(!1),X=k4(null);q5(()=>{if(!M1)return;let _=async()=>{try{let W=await(await fetch("/api/sessions")).json();Q((T)=>{let K=JSON.stringify(W);return JSON.stringify(T)===K?T:W})}catch{}};_();let H=setInterval(_,5000);return()=>clearInterval(H)},[]),q5(()=>{if(!J)return;let _=(H)=>{if(X.current&&!X.current.contains(H.target))Y(!1)};return document.addEventListener("mousedown",_),()=>document.removeEventListener("mousedown",_)},[J]);let G=q.filter((_)=>_.id!==Z),z=Q5(Z,$);return C1("div",{className:"relative",ref:X,children:[C1("div",{className:"flex items-center gap-1.5 font-body text-body font-medium",children:[C1("a",{href:`/s/${Z}`,className:"text-text-primary hover:text-text-secondary transition-colors",children:z},void 0,!1,void 0,this),G.length>0&&C1("button",{onClick:()=>Y(!J),className:"flex items-center justify-center text-text-tertiary hover:text-text-secondary transition-colors",children:C1("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:`transition-transform duration-200 ${J?"rotate-180":""}`,children:C1("path",{d:"M3 5l3 3 3-3",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),J&&G.length>0&&C1("div",{className:"absolute top-full left-0 mt-2 w-64 bg-bg-elevated border border-border-hover rounded-lg shadow-lg z-50 py-1 overflow-hidden",children:G.map((_)=>C1("a",{href:`/s/${_.id}`,className:"flex items-center gap-2.5 px-4 py-2.5 text-body font-body text-text-secondary hover:bg-bg-surface hover:text-text-primary transition-colors",children:[C1("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${_.currentRevision>0?"bg-accent-green":"bg-border-hover"}`},void 0,!1,void 0,this),C1("span",{className:"truncate",children:Q5(_.id,_.projectRoot)},void 0,!1,void 0,this)]},_.id,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Y5(Z){let $=[];return X2(Z,$,0),$.join(`
78
+ `)+(u.length>3?`
79
+ ...`:""),g=O1();X(g,R,"",$),Z(g)};return L1("div",{children:[L1("pre",{ref:N,className:"text-code font-mono text-text-code bg-bg-base select-text cursor-text py-3 hljs",children:u.map((R,g)=>{let p=g+1,t=d&&p>=d.start&&p<=d.end;return L1("div",{"data-line-num":p,className:`flex px-5 ${t?"bg-accent-blue/10":"hover:bg-bg-elevated-half"}`,children:[L1("span",{className:"text-text-tertiary select-none w-10 text-right pr-4 shrink-0 py-px text-[12px] cursor-pointer opacity-40 hover:opacity-100 hover:text-accent-blue",onMouseDown:(l)=>D(l,p),children:p},void 0,!1,void 0,this),v?L1("code",{className:"py-px",dangerouslySetInnerHTML:{__html:v[g]||" "}},void 0,!1,void 0,this):L1("code",{className:"py-px",children:R||" "},void 0,!1,void 0,this)]},g,!0,void 0,this)})},void 0,!1,void 0,this),k]},void 0,!0,void 0,this)}import{useEffect as Q4,useState as J4,useRef as p$}from"react";import{jsxDEV as u1}from"react/jsx-dev-runtime";function Y4($,Q){if(Q){let J=Q.replace(/\/+$/,"").split("/");return J[J.length-1]||$}return $.length>30?$.slice(0,30)+"...":$}function I5({currentSessionId:$,projectRoot:Q}){let[J,X]=J4([]),[Y,Z]=J4(!1),q=p$(null);Q4(()=>{if(!p1)return;let K=async()=>{try{let W=await(await fetch("/api/sessions")).json();X((H)=>{let N=JSON.stringify(W);return JSON.stringify(H)===N?H:W})}catch{}};K();let _=setInterval(K,5000);return()=>clearInterval(_)},[]),Q4(()=>{if(!Y)return;let K=(_)=>{if(q.current&&!q.current.contains(_.target))Z(!1)};return document.addEventListener("mousedown",K),()=>document.removeEventListener("mousedown",K)},[Y]);let U=J.filter((K)=>K.id!==$),G=Y4($,Q);return u1("div",{className:"relative",ref:q,children:[u1("div",{className:"flex items-center gap-1.5 font-body text-body font-medium",children:[u1("a",{href:`/s/${$}`,className:"text-text-primary hover:text-text-secondary transition-colors",children:G},void 0,!1,void 0,this),U.length>0&&u1("button",{onClick:()=>Z(!Y),className:"flex items-center justify-center text-text-tertiary hover:text-text-secondary transition-colors",children:u1("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:`transition-transform duration-200 ${Y?"rotate-180":""}`,children:u1("path",{d:"M3 5l3 3 3-3",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Y&&U.length>0&&u1("div",{className:"absolute top-full left-0 mt-2 w-64 bg-bg-elevated border border-border-hover rounded-lg shadow-lg z-50 py-1 overflow-hidden",children:U.map((K)=>u1("a",{href:`/s/${K.id}`,className:"flex items-center gap-2.5 px-4 py-2.5 text-body font-body text-text-secondary hover:bg-bg-surface hover:text-text-primary transition-colors",children:[u1("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${K.currentRevision>0?"bg-accent-green":"bg-border-hover"}`},void 0,!1,void 0,this),u1("span",{className:"truncate",children:Y4(K.id,K.projectRoot)},void 0,!1,void 0,this)]},K.id,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function X4($){let Q=[];return R2($,Q,0),Q.join(`
80
80
  `).replace(/\n{3,}/g,`
81
81
 
82
82
  `).trim()+`
83
- `}var E4=new Set(["CODE","SPAN","STRONG","EM","A","B","I","U","SMALL","SUB","SUP","MARK","ABBR"]);function X2(Z,$,q){if(x4(Z)){let Q=m4(Z);if(Q)$.push(Q,"");return}for(let Q of Z.childNodes)if(Q.nodeType===Node.ELEMENT_NODE)u4(Q,$,q);else if(Q.nodeType===Node.TEXT_NODE){let J=Q.textContent?.trim();if(J)$.push(J,"")}}function x4(Z){for(let $ of Z.childNodes){if($.nodeType===Node.TEXT_NODE)continue;if($.nodeType===Node.ELEMENT_NODE){let q=$;if(!E4.has(q.tagName)||q.hasAttribute("data-md"))return!1}}return Z.childNodes.length>0}function m4(Z){let $="";for(let q of Z.childNodes)if(q.nodeType===Node.TEXT_NODE)$+=q.textContent||"";else if(q.nodeType===Node.ELEMENT_NODE){let Q=q;if(Q.tagName==="CODE")$+="`"+(Q.textContent||"")+"`";else $+=Q.textContent||""}return $.trim()}function u4(Z,$,q){let Q=Z.getAttribute("data-md");if(Q)switch(Q){case"section":return g4(Z,$,q);case"item":return f4(Z,$);case"codeblock":return v4(Z,$);case"callout":return h4(Z,$);case"note":return p4(Z,$);case"markdown":return i4(Z,$);case"table":return c4(Z,$);case"checklist":return d4(Z,$);case"diff":return l4(Z,$);case"mermaid":return r4(Z,$);case"choice":return a4(Z,$);case"multichoice":return o4(Z,$);case"choice-option":case"multichoice-option":return;case"userinput":return s4(Z,$);case"rangeinput":return t4(Z,$);case"checklist-item":return;case"filepreview":return n4(Z,$);case"priority":return e4(Z,$)}if(Z.querySelector("button, input, select, textarea"))return;if(Z.children.length>0)X2(Z,$,q);else{let J=Z.textContent?.trim();if(J)$.push(J,"")}}function g4(Z,$,q){let Q=Z.getAttribute("data-md-title")||"Untitled",J=q===0?"##":"###";$.push(`${J} ${Q}`,"");let Y=Z.querySelector(":scope > div:last-of-type");if(Y)X2(Y,$,q+1)}function f4(Z,$){let q=Z.getAttribute("data-md-label")||"",Q=Z.getAttribute("data-md-status"),J=Z.getAttribute("data-md-badge"),Y="-";if(Q==="done")Y="- [x]";else if(Q)Y="- [ ]";let X=`${Y} **${q}**`;if(J)X+=` \`${J}\``;$.push(X);let G=Z.querySelector(".text-text-secondary");if(G){let z=[];X2(G,z,0);for(let _ of z)$.push(_?` ${_}`:"")}$.push("")}function v4(Z,$){let q=Z.getAttribute("data-md-language")||"",J=Z.querySelector("code")?.textContent||"";$.push(`\`\`\`${q}`,J,"```","")}function h4(Z,$){let q=Z.getAttribute("data-md-type")||"info",Q={info:"Info",warning:"Warning",danger:"Danger",tip:"Tip"},J=$6(Z.querySelector(".text-text-secondary")||Z);$.push(`> **${Q[q]||q}:** ${J}`,"")}function p4(Z,$){let q=Z.textContent?.trim()||"";$.push(`> *${q}*`,"")}function c4(Z,$){let q=Z.querySelector("table");if(!q)return;let Q=[];for(let J of q.querySelectorAll("thead th"))Q.push(J.textContent?.trim()||"");if(Q.length===0)return;$.push(`| ${Q.join(" | ")} |`),$.push(`| ${Q.map(()=>"---").join(" | ")} |`);for(let J of q.querySelectorAll("tbody tr")){let Y=[];for(let X of J.querySelectorAll("td"))Y.push(X.textContent?.trim()||"");$.push(`| ${Y.join(" | ")} |`)}$.push("")}function d4(Z,$){for(let q of Z.querySelectorAll("li")){let Q=q.querySelector(".bg-accent-green")!==null,J=q.textContent?.trim()||"";$.push(`- [${Q?"x":" "}] ${J}`)}$.push("")}function l4(Z,$){let q=Z.getAttribute("data-md-language")||"";$.push(`\`\`\`diff${q?` (${q})`:""}`);for(let Q of Z.querySelectorAll("[class*='flex']")){let J=Q.querySelector(".text-accent-red")?"-":Q.querySelector(".text-accent-green")?"+":" ",Y=Q.querySelector("code");if(Y)$.push(`${J} ${Y.textContent}`)}$.push("```","")}function r4(Z,$){let q=Z.getAttribute("data-md-source")||"";if(q)$.push("```mermaid",q,"```","")}function i4(Z,$){let q=Z.getAttribute("data-md-source")||"";if(q)$.push(q,"")}function a4(Z,$){let q=Z.getAttribute("data-md-label")||"";$.push(`**${q}:**`);for(let Q of Z.querySelectorAll("[data-md='choice-option']")){let J=Q.getAttribute("data-md-label")||Q.textContent?.trim()||"",Y=Q.querySelector(".bg-accent-amber")!==null;$.push(`- ${Y?"(x)":"( )"} ${J}`)}$.push("")}function o4(Z,$){let q=Z.getAttribute("data-md-label")||"";$.push(`**${q}:**`);for(let Q of Z.querySelectorAll("[data-md='multichoice-option']")){let J=Q.getAttribute("data-md-label")||Q.textContent?.trim()||"",Y=Q.querySelector(".bg-accent-amber")!==null;$.push(`- [${Y?"x":" "}] ${J}`)}$.push("")}function s4(Z,$){let q=Z.getAttribute("data-md-label")||"",J=Z.querySelector("textarea")?.value?.trim()||"";$.push(`**${q}:** ${J||"_empty_"}`,"")}function t4(Z,$){let q=Z.getAttribute("data-md-label")||"",Q=Z.querySelector("input[type='range']"),Y=Z.querySelector(".font-mono")?.textContent?.trim()||Q?.value||"—";$.push(`**${q}:** ${Y}`,"")}function n4(Z,$){let q=Z.getAttribute("data-md-path")||"",Q=Z.getAttribute("data-md-lines")||"",Y=Z.querySelector("code")?.textContent||"",X=q.split(".").pop()||"",G=Q2[X]||"",z=Q?`${q} (L${Q})`:q;$.push(z,"",`\`\`\`${G}`,Y,"```","")}function e4(Z,$){}function $6(Z){return Z?.textContent?.trim()||""}import F5,{useEffect as h1,useState as U1,useRef as k1,useCallback as B5,useMemo as U2,useContext as O6}from"react";import{useEffect as Z6,useState as q6,useRef as J6,useContext as Q6}from"react";import{jsxDEV as H1,Fragment as X5}from"react/jsx-dev-runtime";function Y6(Z){return Z.label||`Round ${Z.revision}`}function X6(Z){let $=Date.now()-new Date(Z).getTime(),q=Math.floor($/1000);if(q<60)return"just now";let Q=Math.floor(q/60);if(Q<60)return`${Q}m ago`;let J=Math.floor(Q/60);if(J<24)return`${J}h ago`;return`${Math.floor(J/24)}d ago`}function V0({value:Z,onChange:$,accent:q="default",className:Q}){let{currentRevision:J,revisions:Y}=Q6(A1),[X,G]=q6(!1),z=J6(null);Z6(()=>{if(!X)return;let U=(W)=>{if(z.current&&!z.current.contains(W.target))G(!1)};return document.addEventListener("mousedown",U),()=>document.removeEventListener("mousedown",U)},[X]);let _=Y.find((U)=>U.revision===Z);return H1("div",{className:"relative",ref:z,children:[H1("button",{onClick:()=>G(!X),className:`flex items-center gap-1.5 text-[12px] font-body font-medium px-2 py-1 rounded-md transition-colors hover:bg-bg-elevated ${{default:"text-text-secondary hover:text-text-primary",red:"text-accent-red",green:"text-accent-green",amber:"text-accent-amber bg-highlight-selected"}[q]} ${Q||""}`,children:[_?Y6(_):`Round ${Z}`,H1("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",className:`text-text-tertiary transition-transform duration-200 ${X?"rotate-180":""}`,children:H1("path",{d:"M2.5 4l2.5 2.5L7.5 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),X&&H1("div",{className:"absolute top-full left-0 mt-1 w-64 bg-bg-elevated border border-border-hover rounded-lg shadow-lg z-50 py-1 max-h-80 overflow-y-auto",children:[...Y].reverse().map((U)=>H1("button",{onClick:()=>{$(U.revision),G(!1)},className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] font-body transition-colors ${U.revision===Z?"bg-bg-surface text-text-primary":"text-text-secondary hover:bg-bg-surface hover:text-text-primary"}`,children:[H1("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${U.revision===J?"bg-accent-green":U.hasFeedback?"bg-accent-amber":"bg-border-hover"}`},void 0,!1,void 0,this),H1("span",{className:"flex-1 text-left truncate",children:U.label?H1(X5,{children:[U.label," ",H1("span",{className:"text-text-tertiary",children:["#",U.revision]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):H1(X5,{children:["Round ",U.revision]},void 0,!0,void 0,this)},void 0,!1,void 0,this),H1("span",{className:"text-[10px] text-text-tertiary flex-shrink-0 flex items-center gap-1.5",children:[(()=>{let W=U.canvasFiles?.reduce((T,K)=>{if(K.diffStats)T.added+=K.diffStats.added,T.removed+=K.diffStats.removed;return T},{added:0,removed:0});if(W&&(W.added>0||W.removed>0))return H1("span",{className:"font-mono",children:[H1("span",{className:"text-accent-green",children:["+",W.added]},void 0,!0,void 0,this)," ",H1("span",{className:"text-accent-red",children:["-",W.removed]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);return null})(),U.revision===J?"current":U.hasFeedback?"sent":X6(U.createdAt)]},void 0,!0,void 0,this)]},U.revision,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function v1(Z,$){let q=Z.length,Q=$.length;if(q===0||Q===0)return[];let J=Array.from({length:q+1},()=>Array(Q+1).fill(0));for(let z=1;z<=q;z++)for(let _=1;_<=Q;_++)J[z][_]=Z[z-1]===$[_-1]?J[z-1][_-1]+1:Math.max(J[z-1][_],J[z][_-1]);let Y=[],X=q,G=Q;while(X>0&&G>0)if(Z[X-1]===$[G-1])Y.unshift(Z[X-1]),X--,G--;else if(J[X-1][G]>J[X][G-1])X--;else G--;return Y}function z5(Z){let $=[],q=[],Q=document.createTreeWalker(Z,NodeFilter.SHOW_TEXT,{acceptNode(Y){let X=Y.parentElement;if(!X)return NodeFilter.FILTER_REJECT;if(X.closest("svg, .select-none, [data-no-diff]"))return NodeFilter.FILTER_REJECT;return NodeFilter.FILTER_ACCEPT}}),J;while(J=Q.nextNode()){let X=(J.nodeValue||"").match(/\S+|\s+/g);if(!X)continue;let G=0;for(let z of X)$.push(z),q.push({text:z,node:J,offset:G}),G+=z.length}return{words:$,map:q}}function c2(Z,$){if(Z.length>5000||$.length>5000)return z6(Z,$);return U5(Z,$)}function U5(Z,$){let q=z2(Z,$),Q=[],J=[],Y=0,X=0,G=0;while(Y<Z.length||X<$.length)if(G<q.length&&Y<Z.length&&X<$.length&&Z[Y]===q[G]&&$[X]===q[G])Q.push({type:"same",index:Y}),J.push({type:"same",index:X}),Y++,X++,G++;else if(Y<Z.length&&(G>=q.length||Z[Y]!==q[G]))Q.push({type:"removed",index:Y}),Y++;else if(X<$.length)J.push({type:"added",index:X}),X++;return{oldOps:Q,newOps:J}}function z2(Z,$){let q=Z.length,Q=$.length;if(q===0||Q===0)return[];if(q===1)return $.includes(Z[0])?[Z[0]]:[];if(Q===1)return Z.includes($[0])?[$[0]]:[];if(q*Q<=1e6)return v1(Z,$);let J=Math.floor(q/2),Y=Z.slice(0,J),X=Z.slice(J),G=_5(Y,$),z=_5([...X].reverse(),[...$].reverse()),_=0,H=0;for(let T=0;T<=Q;T++){let K=G[T]+z[Q-T];if(K>_)_=K,H=T}let U=$.slice(0,H),W=$.slice(H);return[...z2(Y,U),...z2(X,W)]}function _5(Z,$){let q=$.length,Q=Array(q+1).fill(0),J=Array(q+1).fill(0);for(let Y=0;Y<Z.length;Y++){for(let X=1;X<=q;X++)J[X]=Z[Y]===$[X-1]?Q[X-1]+1:Math.max(Q[X],J[X-1]);[Q,J]=[J,Q],J.fill(0)}return Q}function z6(Z,$){let Q=(K)=>{let L=[];for(let N=0;N<K.length;N+=200){let y=Math.min(N+200,K.length);L.push({start:N,end:y,text:K.slice(N,y).join("")})}return L},J=Q(Z),Y=Q($),X=J.map((K)=>K.text),G=Y.map((K)=>K.text),z=z2(X,G),_=[],H=[],U=0,W=0,T=0;while(U<J.length||W<Y.length)if(T<z.length&&U<J.length&&W<Y.length&&X[U]===z[T]&&G[W]===z[T]){for(let K=J[U].start;K<J[U].end;K++)_.push({type:"same",index:K});for(let K=Y[W].start;K<Y[W].end;K++)H.push({type:"same",index:K});U++,W++,T++}else if(U<J.length&&(T>=z.length||X[U]!==z[T]))if(W<Y.length&&(T>=z.length||G[W]!==z[T])){let K=U5(Z.slice(J[U].start,J[U].end),$.slice(Y[W].start,Y[W].end));for(let L of K.oldOps)_.push({type:L.type,index:L.index+J[U].start});for(let L of K.newOps)H.push({type:L.type,index:L.index+Y[W].start});U++,W++}else{for(let K=J[U].start;K<J[U].end;K++)_.push({type:"removed",index:K});U++}else if(W<Y.length){for(let K=Y[W].start;K<Y[W].end;K++)H.push({type:"added",index:K});W++}return{oldOps:_,newOps:H}}function G5(Z,$,q){let Q=new Map;for(let J of Z){if(J.type==="same")continue;let Y=$[J.index];if(!Y||!Y.node.parentNode)continue;let X=Q.get(Y.node);if(!X)X=[],Q.set(Y.node,X);X.push({offset:Y.offset,length:Y.text.length})}for(let[J,Y]of Q){if(!J.parentNode)continue;let X=J.nodeValue||"";Y.sort((U,W)=>U.offset-W.offset);let G=[];for(let U of Y){let W=G[G.length-1];if(W&&U.offset<=W.offset+W.length)W.length=Math.max(W.length,U.offset+U.length-W.offset);else G.push({...U})}let z=J.parentNode,_=document.createDocumentFragment(),H=0;for(let U of G){if(U.offset>H)_.appendChild(document.createTextNode(X.slice(H,U.offset)));let W=document.createElement("span");W.className=q,W.textContent=X.slice(U.offset,U.offset+U.length),_.appendChild(W),H=U.offset+U.length}if(H<X.length)_.appendChild(document.createTextNode(X.slice(H)));z.replaceChild(_,J)}}function _2(Z,$){let q=_6(Z,$),Q=z5(Z),J=z5($),{oldOps:Y,newOps:X}=c2(Q.words,J.words),G=Y.some((z)=>z.type==="removed")||X.some((z)=>z.type==="added");return G5(Y,Q.map,"diff-removed"),G5(X,J.map,"diff-added"),G||q}function _6(Z,$){let q=Array.from(Z.querySelectorAll('[data-md="mermaid"]')),Q=Array.from($.querySelectorAll('[data-md="mermaid"]')),J=!1,Y=Math.max(q.length,Q.length);for(let X=0;X<Y;X++){let G=q[X],z=Q[X];if(!G&&z){z.classList.add("diff-block-added"),z.style.position="relative",J=!0;continue}if(G&&!z){G.classList.add("diff-block-removed"),G.style.position="relative",J=!0;continue}if(!G||!z)continue;let _=(G.getAttribute("data-md-source")||"").trim(),H=(z.getAttribute("data-md-source")||"").trim();if(_===H)continue;J=!0,G.style.borderLeft="3px solid var(--color-accent-red)",G.style.paddingLeft="8px",z.style.borderLeft="3px solid var(--color-accent-green)",z.style.paddingLeft="8px";let U=_.split(`
84
- `),W=H.split(`
85
- `),T=v1(U,W),K=(L,N,y)=>{let O=document.createElement("div");O.className="mt-2 bg-bg-code rounded-md overflow-hidden text-tiny font-mono",O.setAttribute("data-no-diff","true");let R=0,S=0;while(S<L.length){let M=document.createElement("div");if(M.className="px-3 py-0.5 whitespace-pre-wrap",R<N.length&&L[S]===N[R])M.textContent=" "+L[S],S++,R++;else M.classList.add(y==="old"?"diff-removed":"diff-added"),M.textContent=(y==="old"?"- ":"+ ")+L[S],S++;O.appendChild(M)}return O};G.appendChild(K(U,T,"old")),z.appendChild(K(W,T,"new"))}return J}function U0(Z){let $=[],q=Z.querySelectorAll(":scope > [data-md]");for(let Q of q)$.push(I0(Q));if($.length===0){let Q=Z.querySelectorAll("[data-md]"),J=new Set;for(let Y of Q){let X=Y.parentElement?.closest("[data-md]");if(X&&Z.contains(X))continue;if(J.has(Y))continue;J.add(Y),$.push(I0(Y))}}return $}function I0(Z){let $=Z.getAttribute("data-md")||"unknown",q=G6(Z,$),Q=[];if($==="section"){let J=Z.querySelector(":scope > div.mt-6, :scope > div:last-child");if(J)for(let Y of J.querySelectorAll(":scope > [data-md]"))Q.push(I0(Y))}else if($==="table")for(let J of Z.querySelectorAll(":scope table > tbody > tr"))Q.push({key:"tr:"+(J.textContent||"").slice(0,80),type:"tr",element:J,children:[]});else if($==="checklist")for(let J of Z.querySelectorAll(":scope > [data-md='checklist-item']"))Q.push(I0(J));else for(let J of Z.querySelectorAll("[data-md]"))if(J.parentElement?.closest("[data-md]")===Z)Q.push(I0(J));return{key:q,type:$,element:Z,children:Q}}function G6(Z,$){switch($){case"section":return"section:"+(Z.getAttribute("data-md-title")||"");case"item":return"item:"+(Z.getAttribute("data-task-id")||Z.getAttribute("data-md-label")||"");case"codeblock":case"diff":return $+":"+(Z.textContent||"").slice(0,80);case"checklist-item":return"checklist-item:"+(Z.getAttribute("data-md-label")||Z.textContent?.slice(0,60)||"");case"checklist":return"checklist:"+Z.querySelectorAll("[data-md='checklist-item']").length;case"markdown":return"markdown:"+(Z.getAttribute("data-md-file")||"inline");case"mermaid":return"mermaid:"+(Z.getAttribute("data-md-source")||"").slice(0,80);case"callout":return"callout:"+(Z.getAttribute("data-md-type")||"")+":"+(Z.textContent||"").slice(0,60);default:return $+":"+(Z.getAttribute("data-md-label")||Z.textContent?.slice(0,60)||"")}}function R0(Z,$){let q=Z.map((_)=>_.key),Q=$.map((_)=>_.key),J=v1(q,Q),Y=[],X=0,G=0,z=0;while(X<Z.length||G<$.length)if(z<J.length&&X<Z.length&&G<$.length&&q[X]===J[z]&&Q[G]===J[z]){let _=Z[X],H=$[G],U=_.children.length>0||H.children.length>0?R0(_.children,H.children):void 0;Y.push({kind:"matched",oldBlock:_,newBlock:H,childMatches:U}),X++,G++,z++}else if(X<Z.length&&(z>=J.length||q[X]!==J[z]))Y.push({kind:"removed",oldBlock:Z[X]}),X++;else if(G<$.length)Y.push({kind:"added",newBlock:$[G]}),G++;return Y}function G2(Z){let $=document.createDocumentFragment(),q=!1;for(let Q of Z)if(Q.kind==="removed")q=!0,$.appendChild(H5(Q.oldBlock.element));else if(Q.kind==="added")q=!0,$.appendChild(U6(Q.newBlock.element));else{let J=Q.newBlock.element.cloneNode(!0),Y=Q.newBlock.type;if(Y==="mermaid"){if(O5(Q.oldBlock.element,J))q=!0}else if(Q.childMatches&&Q.childMatches.length>0&&(Y==="table"||Y==="checklist")){if(T5(J,Q.childMatches,Y))q=!0}else if(Q.childMatches&&Q.childMatches.length>0){if(W5(Q.oldBlock,J,Q.childMatches,Y))q=!0}else if(Y==="markdown"){if(N5(Q.oldBlock.element,J))q=!0}else if(Z0(Q.oldBlock.element,J,!1))q=!0;$.appendChild(J)}return{fragment:$,hasChanges:q}}function H5(Z){let $=Z.cloneNode(!0);return $.classList.add("diff-block-removed"),$.style.position="relative",d2($,"Removed","var(--color-accent-red)"),$}function U6(Z){let $=Z.cloneNode(!0);return $.classList.add("diff-block-added"),$.style.position="relative",d2($,"Added","var(--color-accent-green)"),$}function W5(Z,$,q,Q){let J=!1,Y=K6(Z,$),X,G;if(Q==="section"){let z=Z.element.querySelector(":scope > div:first-child"),_=$.querySelector(":scope > div:first-child");if(z&&_){if(Z0(z,_,!1))J=!0}X=Z.element.querySelector(":scope > div.mt-6, :scope > div:last-child"),G=$.querySelector(":scope > div.mt-6, :scope > div:last-child")}else X=Z.element,G=$;if(!X||!G)return J;for(let z of q)if(z.kind==="matched"){let _=Y.newMap.get(z.newBlock.element);if(_){if(z.newBlock.type==="mermaid"){if(O5(z.oldBlock.element,_))J=!0}else if(z.childMatches&&z.childMatches.length>0&&(z.newBlock.type==="table"||z.newBlock.type==="checklist")){if(T5(_,z.childMatches,z.newBlock.type))J=!0}else if(z.childMatches&&z.childMatches.length>0){if(W5(z.oldBlock,_,z.childMatches,z.newBlock.type))J=!0}else if(z.newBlock.type==="markdown"){if(N5(z.oldBlock.element,_))J=!0}else if(Z0(z.oldBlock.element,_,!1))J=!0}}else if(z.kind==="removed"){J=!0;let _=H5(z.oldBlock.element),H=W6(q,z,Y.newMap),U=H?T6(G,H):null;G.insertBefore(_,U)}else if(z.kind==="added"){J=!0;let _=Y.newMap.get(z.newBlock.element);if(_)_.classList.add("diff-block-added"),_.style.position="relative",d2(_,"Added","var(--color-accent-green)")}if(Z0(X,G,!0))J=!0;return J}function T5(Z,$,q){let Q=q==="table"?Z.querySelector(":scope table > tbody"):Z;if(!Q)return!1;let J=!1;Q.innerHTML="";for(let Y of $)if(Y.kind==="removed"){J=!0;let X=Y.oldBlock.element.cloneNode(!0);X.classList.add(q==="table"?"diff-row-removed":"diff-item-removed"),Q.appendChild(X)}else if(Y.kind==="added"){J=!0;let X=Y.newBlock.element.cloneNode(!0);X.classList.add(q==="table"?"diff-row-added":"diff-item-added"),Q.appendChild(X)}else{let X=Y.newBlock.element.cloneNode(!0);if(Z0(Y.oldBlock.element,X,!1))J=!0;Q.appendChild(X)}return J}function K6(Z,$){let q=new Map,Q=Z.element.querySelectorAll("[data-md]"),J=$.querySelectorAll("[data-md]");return{newMap:{get(Y){return H6($,Y)}}}}function H6(Z,$){let q=$.getAttribute("data-md");if(!q)return null;let Q=$.getAttribute("data-md-label"),J=$.getAttribute("data-md-title"),Y=`[data-md="${q}"]`;if(J)Y+=`[data-md-title="${CSS.escape(J)}"]`;else if(Q)Y+=`[data-md-label="${CSS.escape(Q)}"]`;let X=Z.querySelectorAll(Y);if(X.length===1)return X[0];let G=($.textContent||"").slice(0,100),z=null,_=-1;for(let H of X){let U=(H.textContent||"").slice(0,100),W=0;for(let T=0;T<Math.min(G.length,U.length);T++)if(G[T]===U[T])W++;if(W>_)_=W,z=H}return z}function W6(Z,$,q){let Q=Z.indexOf($);for(let J=Q+1;J<Z.length;J++){let Y=Z[J];if((Y.kind==="matched"||Y.kind==="added")&&Y.newBlock)return q.get(Y.newBlock.element)||null}return null}function T6(Z,$){let q=$;while(q&&q.parentElement!==Z)q=q.parentElement;return q}function N5(Z,$){let q=Array.from(Z.children),Q=Array.from($.children);if(q.length===0&&Q.length===0)return Z0(Z,$,!1);let J=q.map((W)=>W.tagName.toLowerCase()),Y=Q.map((W)=>W.tagName.toLowerCase()),X=v1(J,Y),G=[],z=0,_=0,H=0;while(z<q.length||_<Q.length)if(H<X.length&&z<q.length&&_<Q.length&&J[z]===X[H]&&Y[_]===X[H])G.push({kind:"matched",oldChild:q[z],newChild:Q[_]}),z++,_++,H++;else if(z<q.length&&(H>=X.length||J[z]!==X[H]))G.push({kind:"removed",oldChild:q[z]}),z++;else if(_<Q.length)G.push({kind:"added",newChild:Q[_]}),_++;let U=!1;while($.firstChild)$.removeChild($.firstChild);for(let W of G)if(W.kind==="matched"){let T=(W.oldChild.textContent||"").match(/\S+/g)||[],K=(W.newChild.textContent||"").match(/\S+/g)||[],L=v1(T,K),N=Math.max(T.length,K.length);if((N>0?1-L.length/N:0)>0.5){U=!0;let O=W.oldChild.cloneNode(!0);O.classList.add("diff-block-removed"),$.appendChild(O),W.newChild.classList.add("diff-block-added"),$.appendChild(W.newChild)}else{if(Z0(W.oldChild,W.newChild,!1))U=!0;$.appendChild(W.newChild)}}else if(W.kind==="removed"){U=!0;let T=W.oldChild.cloneNode(!0);T.classList.add("diff-block-removed"),$.appendChild(T)}else U=!0,W.newChild.classList.add("diff-block-added"),$.appendChild(W.newChild);return U}function K5(Z,$){let q=$?new Set(Array.from(Z.querySelectorAll("[data-md]"))):new Set,Q=[],J=[],Y=document.createTreeWalker(Z,NodeFilter.SHOW_TEXT,{acceptNode(G){let z=G.parentElement;if(!z)return NodeFilter.FILTER_REJECT;if(z.closest("svg, .select-none, [data-no-diff]"))return NodeFilter.FILTER_REJECT;if($){for(let _ of q)if(_.contains(G))return NodeFilter.FILTER_REJECT}return NodeFilter.FILTER_ACCEPT}}),X;while(X=Y.nextNode()){let z=(X.nodeValue||"").match(/\S+|\s+/g);if(!z)continue;let _=0;for(let H of z)Q.push(H),J.push({text:H,node:X,offset:_}),_+=H.length}return{words:Q,map:J}}function Z0(Z,$,q){let Q=K5(Z,q),J=K5($,q);if(Q.words.length===0&&J.words.length===0)return!1;let{oldOps:Y,newOps:X}=c2(Q.words,J.words),G=Y.some((N)=>N.type==="removed"),z=X.some((N)=>N.type==="added");if(!G&&!z)return!1;let _=[],H=[];for(let N of Y)if(N.type==="same")_.push(N.index);for(let N of X)if(N.type==="same")H.push(N.index);let U=new Map;for(let N=0;N<_.length&&N<H.length;N++)U.set(_[N],H[N]);let W=[];{let N=[],y=-1;for(let O of Y)if(O.type==="same"){if(N.length>0)W.push({text:N.join(""),anchorNewIdx:y>=0?U.get(y)??null:null}),N=[];y=O.index}else if(O.type==="removed")N.push(Q.words[O.index]);if(N.length>0)W.push({text:N.join(""),anchorNewIdx:y>=0?U.get(y)??null:null})}let T=new Map,K=new Map;for(let N of X){if(N.type!=="added")continue;let y=J.map[N.index];if(!y?.node.parentNode)continue;let O=T.get(y.node);if(!O)O=[],T.set(y.node,O);O.push({start:y.offset,end:y.offset+y.text.length})}for(let N of W)if(N.anchorNewIdx===null){if(J.map.length>0){let y=J.map[0].node,O=K.get(y);if(!O)O=[],K.set(y,O);O.push({offset:0,text:N.text})}}else{let y=J.map[N.anchorNewIdx];if(!y)continue;let O=K.get(y.node);if(!O)O=[],K.set(y.node,O);O.push({offset:y.offset+y.text.length,text:N.text})}let L=new Set([...T.keys(),...K.keys()]);for(let N of L)N6(N,T.get(N)||[],K.get(N)||[]);return!0}function N6(Z,$,q){if(!Z.parentNode)return;let Q=Z.nodeValue||"";$.sort((H,U)=>H.start-U.start);let J=[];for(let H of $){let U=J[J.length-1];if(U&&H.start<=U.end)U.end=Math.max(U.end,H.end);else J.push({...H})}q.sort((H,U)=>H.offset-U.offset);let Y=Z.parentNode,X=document.createDocumentFragment(),G=0,z=0,_=0;while(G<=Q.length){let H=z<J.length?J[z].start:1/0,U=_<q.length?q[_].offset:1/0,W=Math.min(H,U);if(W===1/0){if(G<Q.length)X.appendChild(document.createTextNode(Q.slice(G)));break}let T=Math.max(W,G);if(T>G)X.appendChild(document.createTextNode(Q.slice(G,T))),G=T;while(_<q.length&&q[_].offset<=G){let K=document.createElement("span");K.className="diff-removed",K.textContent=q[_].text,X.appendChild(K),_++}if(z<J.length&&J[z].start<=G){let K=J[z],L=document.createElement("span");L.className="diff-added",L.textContent=Q.slice(G,K.end),X.appendChild(L),G=K.end,z++;while(_<q.length&&q[_].offset<=G){let N=document.createElement("span");N.className="diff-removed",N.textContent=q[_].text,X.appendChild(N),_++}}}while(_<q.length){let H=document.createElement("span");H.className="diff-removed",H.textContent=q[_].text,X.appendChild(H),_++}Y.replaceChild(X,Z)}function O5(Z,$){let q=(Z.getAttribute("data-md-source")||"").trim(),Q=($.getAttribute("data-md-source")||"").trim();if(q===Q)return!1;let J=q.split(`
86
- `),Y=Q.split(`
87
- `),X=v1(J,Y),G=[],z=0,_=0,H=0;while(z<J.length||_<Y.length)if(H<X.length&&z<J.length&&_<Y.length&&J[z]===X[H]&&Y[_]===X[H])G.push({type:"same",line:J[z]}),z++,_++,H++;else if(z<J.length&&(H>=X.length||J[z]!==X[H]))G.push({type:"removed",line:J[z]}),z++;else if(_<Y.length)G.push({type:"added",line:Y[_]}),_++;let U=document.createElement("div");U.className="mt-2 bg-bg-code rounded-md overflow-hidden text-tiny font-mono",U.setAttribute("data-no-diff","true");for(let W of G){let T=document.createElement("div");if(T.className="px-3 py-0.5 whitespace-pre-wrap",W.type==="removed")T.classList.add("diff-removed"),T.textContent="- "+W.line;else if(W.type==="added")T.classList.add("diff-added"),T.textContent="+ "+W.line;else T.textContent=" "+W.line;U.appendChild(T)}return $.appendChild(U),!0}function d2(Z,$,q){let Q=document.createElement("span");Q.className="diff-block-label",Q.textContent=$,Q.style.color=q,Q.style.backgroundColor=`color-mix(in srgb, ${q} 12%, transparent)`,Z.appendChild(Q)}import{jsxDEV as c}from"react/jsx-dev-runtime";function F6(Z,$,q){let Q=Z.find((X)=>X.revision===$),J=Z.find((X)=>X.revision===q),Y=new Set;for(let X of Q?.canvasFiles||[])Y.add(X.filename);for(let X of J?.canvasFiles||[])Y.add(X.filename);return[...Y].sort()}function L5({initialLeft:Z,initialRight:$,sessionId:q,onExit:Q}){let[J,Y]=U1(Z),[X,G]=U1($),[z,_]=U1("unified"),[H,U]=U1(!0),[W,T]=U1(!1),{revisions:K}=O6(A1),L=U2(()=>F6(K,J,X),[K,J,X]),[N,y]=U1(()=>L[0]||"plan.jsx");h1(()=>{if(!L.includes(N))y(L[0]||"plan.jsx")},[L,N]);let O=U2(()=>{return K.find((M)=>M.revision===J)?.canvasFiles.some((M)=>M.filename===N)??!1},[K,J,N]),R=U2(()=>{return K.find((M)=>M.revision===X)?.canvasFiles.some((M)=>M.filename===N)??!1},[K,X,N]);return c("div",{className:"flex flex-col h-screen",children:[c("div",{className:"flex items-center justify-between px-6 py-3 border-b border-border-subtle bg-bg-surface flex-shrink-0",children:[c("div",{className:"flex items-center gap-3",children:[c("span",{className:"text-[13px] font-body font-medium text-text-primary",children:"Compare"},void 0,!1,void 0,this),c(V0,{value:J,onChange:Y,accent:"red"},void 0,!1,void 0,this),c("span",{className:"text-text-tertiary text-[13px]",children:"→"},void 0,!1,void 0,this),c(V0,{value:X,onChange:G,accent:"green"},void 0,!1,void 0,this),W&&!H&&c("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),c("div",{className:"flex items-center gap-4",children:[c("div",{className:"flex items-center bg-bg-elevated rounded-md p-0.5",children:[c("button",{onClick:()=>_("unified"),className:`text-[11px] font-body px-2.5 py-1 rounded transition-colors ${z==="unified"?"bg-bg-surface text-text-primary font-medium shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Unified"},void 0,!1,void 0,this),c("button",{onClick:()=>_("side-by-side"),className:`text-[11px] font-body px-2.5 py-1 rounded transition-colors ${z==="side-by-side"?"bg-bg-surface text-text-primary font-medium shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Side-by-side"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z==="side-by-side"&&c(B6,{},void 0,!1,void 0,this),c("button",{onClick:Q,className:"text-[12px] font-body font-medium text-text-secondary hover:text-text-primary px-3 py-1.5 rounded-md hover:bg-bg-elevated transition-colors",children:"Exit Compare"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),L.length>1&&c("div",{className:"flex items-center gap-1 px-6 py-2 border-b border-border-subtle bg-bg-surface flex-shrink-0 overflow-x-auto",children:L.map((S)=>{let M=S.replace(/\.jsx$/,""),b=S===N,g=K.find((h)=>h.revision===J)?.canvasFiles.some((h)=>h.filename===S),C=K.find((h)=>h.revision===X)?.canvasFiles.some((h)=>h.filename===S),p=!g?" (added)":!C?" (removed)":"";return c("button",{onClick:()=>y(S),className:`text-[12px] font-body px-3 py-1 rounded-md transition-colors whitespace-nowrap ${b?"bg-bg-elevated text-text-primary font-medium":"text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated"}`,children:[M,p&&c("span",{className:`ml-1 text-[10px] ${!g?"text-accent-green":"text-accent-red"}`,children:p},void 0,!1,void 0,this)]},S,!0,void 0,this)})},void 0,!1,void 0,this),!O||!R?c("div",{className:"flex-1 flex items-center justify-center",children:c("div",{className:"text-center text-text-tertiary font-body",children:[c("div",{className:"text-lg mb-2",children:!O?"New file":"Removed file"},void 0,!1,void 0,this),c("div",{className:"text-[13px]",children:[N.replace(/\.jsx$/,"")," ",!O?"was added":"was removed"," in this revision"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this):z==="unified"?c(L6,{sessionId:q,leftRev:J,rightRev:X,filename:N,onDiffResult:(S,M)=>{T(S),U(M)}},`unified-${J}-${X}-${N}`,!1,void 0,this):c(M6,{sessionId:q,leftRev:J,rightRev:X,filename:N,onDiffResult:(S,M)=>{T(S),U(M)}},`sbs-${J}-${X}-${N}`,!1,void 0,this)]},void 0,!0,void 0,this)}function B6(){let[Z,$]=U1(!0);return h1(()=>{return document.documentElement.dataset.syncScroll=Z?"1":"0",()=>{delete document.documentElement.dataset.syncScroll}},[Z]),c("label",{className:"flex items-center gap-1.5 cursor-pointer select-none",children:[c("input",{type:"checkbox",checked:Z,onChange:(q)=>$(q.target.checked),className:"accent-accent-amber w-3.5 h-3.5"},void 0,!1,void 0,this),c("span",{className:"text-[11px] font-body text-text-secondary",children:"Sync scroll"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function L6({sessionId:Z,leftRev:$,rightRev:q,filename:Q,onDiffResult:J}){let Y=k1(null),X=k1(null),G=k1(null),[z,_]=U1(!1),[H,U]=U1(!1),[W,T]=U1(!1),[K,L]=U1(null),[N,y]=U1(!1),{annotations:O}=X1(),R=O.filter((M)=>!M.filePath&&(!M.canvasFile||M.canvasFile===Q)),{popovers:S}=t1({containerRef:G,restoreKey:W,restoreAnnotations:R,extractContext:(M)=>i1(M,G.current)});return h1(()=>{if(W||K)return;let M=setTimeout(()=>{console.warn("[unified-diff] still loading after 10s",{leftReady:z,rightReady:H,oldRef:!!Y.current,newRef:!!X.current}),y(!0)},1e4);return()=>clearTimeout(M)},[W,K,z,H]),h1(()=>{if(!z||!H||W)return;if(!Y.current||!X.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!Y.current||!X.current||!G.current){console.warn("[unified-diff] refs lost between rAF frames",{old:!!Y.current,new:!!X.current,unified:!!G.current});return}try{let M=U0(Y.current),b=U0(X.current),g=R0(M,b),{fragment:C,hasChanges:p}=G2(g);G.current.innerHTML="",G.current.appendChild(C),T(!0),J(!0,p)}catch(M){console.error("[unified-diff] diff computation failed",M),L(M instanceof Error?M.message:String(M))}})})},[z,H,W]),c("div",{className:"flex-1 min-h-0 overflow-y-auto",children:[!W&&!K&&c("div",{style:{position:"absolute",left:-9999,visibility:"hidden",pointerEvents:"none",width:720},children:[c(E1,{ref:Y,sessionId:Z,revision:$,filename:Q,onReady:()=>_(!0),onError:(M)=>L(`Rev ${$}: ${M}`)},void 0,!1,void 0,this),c(E1,{ref:X,sessionId:Z,revision:q,filename:Q,onReady:()=>U(!0),onError:(M)=>L(`Rev ${q}: ${M}`)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),c("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:[!W&&!K&&c("div",{className:"flex flex-col items-center justify-center h-64 text-text-tertiary font-body text-body gap-2",children:[c("span",{children:"Loading..."},void 0,!1,void 0,this),N&&c("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&&c("div",{className:"bg-accent-red-muted rounded-lg p-5 mt-8",children:[c("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Failed to load revision"},void 0,!1,void 0,this),c("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),c("div",{ref:G},void 0,!1,void 0,this)]},void 0,!0,void 0,this),S]},void 0,!0,void 0,this)}function M6({sessionId:Z,leftRev:$,rightRev:q,filename:Q,onDiffResult:J}){let Y=k1(null),X=k1(null),[G,z]=U1(!1),[_,H]=U1(!1),[U,W]=U1(!1),T=k1(null),K=k1(null),L=k1(null),N=k1(!1),y=B5(()=>z(!0),[]),O=B5(()=>H(!0),[]),{annotations:R}=X1(),S=R.filter((b)=>!b.filePath&&(!b.canvasFile||b.canvasFile===Q)),{popovers:M}=t1({containerRef:T,restoreKey:U,restoreAnnotations:S,extractContext:(b)=>i1(b,T.current)});return h1(()=>{if(!G||!_||U)return;if(!Y.current||!X.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!Y.current||!X.current)return;let b=_2(Y.current,X.current);W(!0),J(!0,b)})})},[G,_,U]),h1(()=>{let b=K.current,g=L.current;if(!b||!g)return;let C=(V,k)=>{if(document.documentElement.dataset.syncScroll==="0")return;if(N.current)return;N.current=!0;let x=V.scrollHeight-V.clientHeight,l=k.scrollHeight-k.clientHeight;if(x>0&&l>0)k.scrollTop=V.scrollTop/x*l;requestAnimationFrame(()=>{N.current=!1})},p=()=>C(b,g),h=()=>C(g,b);return b.addEventListener("scroll",p),g.addEventListener("scroll",h),()=>{b.removeEventListener("scroll",p),g.removeEventListener("scroll",h)}},[]),c("div",{ref:T,className:"flex flex-1 min-h-0",children:[c("div",{ref:K,className:"w-1/2 overflow-y-auto border-r border-border-subtle",children:c("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:c(E1,{ref:Y,sessionId:Z,revision:$,filename:Q,onReady:y},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),c("div",{ref:L,className:"w-1/2 overflow-y-auto",children:c("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:c(E1,{ref:X,sessionId:Z,revision:q,filename:Q,onReady:O},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),M]},void 0,!0,void 0,this)}var E1=F5.memo(F5.forwardRef(({sessionId:Z,revision:$,filename:q,onReady:Q,onError:J},Y)=>{let[X,G]=U1(null),[z,_]=U1(null),[H,U]=U1(!0);h1(()=>{U(!0),_(null);let T=q.replace(/\.jsx$/,".js");import(`/api/session/${Z}/canvas/${encodeURIComponent(T)}?rev=${$}&t=${Date.now()}`).then((K)=>{if(!K.default){_("Module has no default export"),U(!1),J?.("Module has no default export");return}G(()=>K.default),U(!1)}).catch((K)=>{_(K.message),U(!1),J?.(K.message)})},[Z,$,q]),h1(()=>{if(!X)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{Q()})})},[X]);let W=U2(()=>X?c(X,{},void 0,!1,void 0,this):null,[X]);if(H)return c("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-body",children:"Loading..."},void 0,!1,void 0,this);if(z)return c("div",{className:"bg-accent-red-muted rounded-lg p-5",children:[c("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Error"},void 0,!1,void 0,this),c("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:z},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(!X)return c("div",{className:"text-text-tertiary text-center py-8 font-body text-body",children:"No canvas loaded"},void 0,!1,void 0,this);return c("div",{ref:Y,children:W},void 0,!1,void 0,this)}));import{useState as x1,useContext as l2,useMemo as P6,useRef as D0,useEffect as P5,useCallback as M5}from"react";import{SessionContext as y6}from"#canvas/runtime";import{jsxDEV as d}from"react/jsx-dev-runtime";function r2(Z,$){if(!Z)return[];return Z.canvasFiles.map((q)=>{if(!q.diffStats)return{filename:q.filename,status:"new"};if(q.diffStats.added===0&&q.diffStats.removed===0)return{filename:q.filename,status:"unchanged",diffStats:q.diffStats};return{filename:q.filename,status:"changed",diffStats:q.diffStats}})}function y5(Z){return Z.filter(($)=>$.status!=="unchanged").map(($)=>$.filename)}function S5({revision:Z,responseBanner:$}){let{setActiveView:q}=l2(D1),{revisions:Q}=l2(A1),J=Q.find((_)=>_.revision===Z),Y=Q.find((_)=>_.revision===Z-1),X=P6(()=>r2(J,Y),[J,Y]),G=X.filter((_)=>_.status!=="unchanged"),z=X.filter((_)=>_.status==="unchanged");return d("div",{className:"max-w-[720px] mx-auto px-6 pt-12 pb-32",children:[$,G.map((_)=>d(b6,{change:_,revision:Z,previousRevision:Y?.revision,onOpenTab:()=>q({type:"canvas",filename:_.filename})},_.filename,!1,void 0,this)),z.length>0&&d("div",{className:"mt-8 border-t border-border-subtle pt-4",children:[d("div",{className:"text-[11px] font-body font-medium uppercase tracking-widest text-text-tertiary mb-3",children:"Unchanged"},void 0,!1,void 0,this),z.map((_)=>d(C6,{change:_,revision:Z,onOpenTab:()=>q({type:"canvas",filename:_.filename})},_.filename,!1,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function S6({mode:Z,onChange:$,showDiff:q}){if(!q)return null;return d("div",{className:"flex items-center bg-bg-elevated rounded-md p-0.5",children:["rendered","unified","side-by-side"].map((Q)=>d("button",{onClick:()=>$(Q),className:`text-[10px] font-body px-2 py-0.5 rounded transition-colors ${Z===Q?"bg-bg-surface text-text-primary font-medium shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:Q==="rendered"?"Full":Q==="unified"?"Unified":"Split"},Q,!1,void 0,this))},void 0,!1,void 0,this)}function b6({change:Z,revision:$,previousRevision:q,onOpenTab:Q}){let J=Z.filename.replace(/\.jsx$/,""),Y=Z.status==="new",X=Z.diffStats,G=Z.status==="changed"&&q!=null,[z,_]=x1("rendered");return d("div",{className:"mb-8",children:[d("div",{className:"flex items-center gap-2 mb-3 pb-2 border-b border-border-subtle",children:[d("span",{className:`text-[11px] font-mono px-1.5 py-0.5 rounded ${Y?"bg-accent-green/10 text-accent-green border border-accent-green/20":"bg-accent-amber/10 text-accent-amber border border-accent-amber/20"}`,children:Y?"new":"modified"},void 0,!1,void 0,this),d("span",{className:"text-[14px] font-body font-medium text-text-primary",children:J},void 0,!1,void 0,this),X&&(X.added>0||X.removed>0)&&d("span",{className:"text-[11px] font-mono text-text-tertiary",children:[d("span",{className:"text-accent-green",children:["+",X.added]},void 0,!0,void 0,this)," ",d("span",{className:"text-accent-red",children:["-",X.removed]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),d(S6,{mode:z,onChange:_,showDiff:G},void 0,!1,void 0,this),d("button",{onClick:Q,className:`${G?"":"ml-auto"} text-[11px] font-body font-medium text-accent-blue hover:text-accent-blue/80 transition-colors`,children:"Open in tab"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z==="rendered"?d("div",{"data-canvas-file":Z.filename,children:d(j0,{revision:$,filename:Z.filename},void 0,!1,void 0,this)},void 0,!1,void 0,this):G&&q!=null?d(j6,{filename:Z.filename,leftRev:q,rightRev:$,mode:z},`${z}-${$}-${q}`,!1,void 0,this):null]},void 0,!0,void 0,this)}function j6({filename:Z,leftRev:$,rightRev:q,mode:Q}){let J=l2(y6);if(Q==="unified")return d(w6,{sessionId:J,filename:Z,leftRev:$,rightRev:q},void 0,!1,void 0,this);return d(A6,{sessionId:J,filename:Z,leftRev:$,rightRev:q},void 0,!1,void 0,this)}function w6({sessionId:Z,filename:$,leftRev:q,rightRev:Q}){let J=D0(null),Y=D0(null),X=D0(null),[G,z]=x1(!1),[_,H]=x1(!1),[U,W]=x1(!1),[T,K]=x1(null);return P5(()=>{if(!G||!_||U)return;if(!J.current||!Y.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!J.current||!Y.current||!X.current)return;try{let L=U0(J.current),N=U0(Y.current),y=R0(L,N),{fragment:O}=G2(y);X.current.innerHTML="",X.current.appendChild(O),W(!0)}catch(L){K(L instanceof Error?L.message:String(L))}})})},[G,_,U]),d("div",{children:[!U&&!T&&d("div",{style:{position:"absolute",left:-9999,visibility:"hidden",pointerEvents:"none",width:720},children:[d(E1,{ref:J,sessionId:Z,revision:q,filename:$,onReady:()=>z(!0),onError:(L)=>K(L)},void 0,!1,void 0,this),d(E1,{ref:Y,sessionId:Z,revision:Q,filename:$,onReady:()=>H(!0),onError:(L)=>K(L)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!U&&!T&&d("div",{className:"flex items-center justify-center h-24 text-text-tertiary font-body text-[13px]",children:"Computing diff..."},void 0,!1,void 0,this),T&&d("div",{className:"text-accent-red text-[13px] font-body p-3 bg-accent-red-muted rounded-lg",children:T},void 0,!1,void 0,this),d("div",{ref:X},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function A6({sessionId:Z,filename:$,leftRev:q,rightRev:Q}){let J=D0(null),Y=D0(null),[X,G]=x1(!1),[z,_]=x1(!1),[H,U]=x1(!1),W=M5(()=>G(!0),[]),T=M5(()=>_(!0),[]);return P5(()=>{if(!X||!z||H)return;if(!J.current||!Y.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!J.current||!Y.current)return;_2(J.current,Y.current),U(!0)})})},[X,z,H]),d("div",{className:"flex gap-0 border-y border-border-subtle overflow-hidden w-screen relative left-1/2 -translate-x-1/2",children:[d("div",{className:"w-1/2 border-r border-border-subtle",children:[d("div",{className:"px-2 py-1 text-[10px] font-body font-medium text-text-tertiary bg-bg-elevated border-b border-border-subtle",children:["Rev ",q]},void 0,!0,void 0,this),d("div",{className:"px-6 py-4 max-w-[600px] mx-auto",children:d(E1,{ref:J,sessionId:Z,revision:q,filename:$,onReady:W},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),d("div",{className:"w-1/2",children:[d("div",{className:"px-2 py-1 text-[10px] font-body font-medium text-text-tertiary bg-bg-elevated border-b border-border-subtle",children:["Rev ",Q]},void 0,!0,void 0,this),d("div",{className:"px-6 py-4 max-w-[600px] mx-auto",children:d(E1,{ref:Y,sessionId:Z,revision:Q,filename:$,onReady:T},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function C6({change:Z,revision:$,onOpenTab:q}){let[Q,J]=x1(!1),Y=Z.filename.replace(/\.jsx$/,"");return d("div",{className:"mb-2",children:[d("div",{className:"flex items-center gap-2 py-1.5",children:[d("button",{onClick:()=>J(!Q),className:"text-text-tertiary hover:text-text-secondary transition-colors",children:d("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",className:`transition-transform duration-150 ${Q?"rotate-90":""}`,children:d("path",{d:"M3.5 2L6.5 5L3.5 8",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),d("span",{className:"text-[13px] font-body text-text-secondary",children:Y},void 0,!1,void 0,this),d("button",{onClick:q,className:"ml-auto text-[11px] font-body text-text-tertiary hover:text-accent-blue transition-colors",children:"Open in tab"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Q&&d("div",{className:"ml-5 mt-1 mb-3","data-canvas-file":Z.filename,children:d(j0,{revision:$,filename:Z.filename},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{useState as K2,useEffect as V6,useCallback as i2}from"react";import{jsxDEV as s}from"react/jsx-dev-runtime";function b5({sessionId:Z,revision:$,open:q,shareEnabled:Q,existingShares:J,onClose:Y,onShareCreated:X,onShareRevoked:G}){let[z,_]=K2(!1),[H,U]=K2(!1),[W,T]=K2(null),[K,L]=K2(!1),N=J.find((S)=>S.revision===$);V6(()=>{if(!q)_(!1),U(!1),T(null),L(!1)},[q]);let y=i2(async()=>{_(!0),T(null);try{let S=await fetch(`/api/session/${Z}/revision/${$}/share`,{method:"POST"}),M=await S.json();if(!S.ok||!M.ok)throw Error(M.error||`HTTP ${S.status}`);X(M.share)}catch(S){T(S.message||String(S))}finally{_(!1)}},[Z,$,X]),O=i2(async(S)=>{if(!window.confirm("Revoke this share link? Reviewers will no longer be able to view or comment."))return;U(!0),T(null);try{let M=await fetch(`/api/session/${Z}/shares/${S}/revoke`,{method:"POST"}),b=await M.json();if(!M.ok||!b.ok)throw Error(b.error||`HTTP ${M.status}`);G(S)}catch(M){T(M.message||String(M))}finally{U(!1)}},[Z,G]),R=i2((S)=>{navigator.clipboard.writeText(S).then(()=>{L(!0),setTimeout(()=>L(!1),1500)})},[]);if(!q)return null;return s("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:Y,children:s("div",{className:"bg-bg-surface border border-border-medium rounded-lg shadow-xl w-full max-w-md mx-4 p-5",onClick:(S)=>S.stopPropagation(),children:[s("div",{className:"flex items-center justify-between mb-3",children:[s("h2",{className:"text-sm font-medium text-text-primary font-body",children:"Share this revision"},void 0,!1,void 0,this),s("button",{onClick:Y,className:"w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",children:s("span",{className:"text-xs",children:"✕"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!Q?s("div",{className:"text-[13px] text-text-secondary font-body space-y-2",children:[s("p",{children:"Canvas sharing is not configured."},void 0,!1,void 0,this),s("p",{className:"text-text-tertiary",children:["Set ",s("code",{className:"px-1 py-0.5 rounded bg-bg-elevated text-text-primary text-[11px]",children:"CANVAS_SHARE_ENDPOINT"},void 0,!1,void 0,this)," to the URL of a deployed"," ",s("code",{className:"px-1 py-0.5 rounded bg-bg-elevated text-text-primary text-[11px]",children:"canvas-share"},void 0,!1,void 0,this)," worker and restart the daemon."]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):N?s("div",{className:"space-y-3",children:[s("p",{className:"text-[13px] text-text-secondary font-body",children:"This revision is shared:"},void 0,!1,void 0,this),s("div",{className:"flex gap-2",children:[s("input",{type:"text",readOnly:!0,value:N.url,className:"flex-1 px-2 py-1.5 text-[12px] font-mono bg-bg-input border border-border-medium rounded text-text-primary",onFocus:(S)=>S.currentTarget.select()},void 0,!1,void 0,this),s("button",{onClick:()=>R(N.url),className:"px-3 py-1.5 text-[12px] font-body font-medium rounded bg-accent-blue text-white hover:opacity-90 transition-opacity whitespace-nowrap",children:K?"Copied!":"Copy"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),N.expiresAt&&s("p",{className:"text-[11px] text-text-tertiary font-body",children:["Expires ",new Date(N.expiresAt).toLocaleDateString(),"."]},void 0,!0,void 0,this),N.encryptionKey&&s("p",{className:"text-[11px] text-accent-green font-body flex items-center gap-1.5",children:[s("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[s("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"},void 0,!1,void 0,this),s("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),"End-to-end encrypted — the key is part of the link and never leaves your browser."]},void 0,!0,void 0,this),s("p",{className:"text-[11px] text-text-tertiary font-body",children:"Anyone with this link can view and leave feedback. Reviewer feedback will appear in your annotation sidebar within seconds."},void 0,!1,void 0,this),s("div",{className:"flex items-center justify-between pt-1",children:[s("button",{onClick:y,disabled:z||H,className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body underline disabled:opacity-50",children:z?"Creating...":"Create a new link"},void 0,!1,void 0,this),N.ownerToken&&s("button",{onClick:()=>O(N.shareId),disabled:z||H,className:"text-[11px] text-accent-red hover:opacity-80 font-body underline disabled:opacity-50",children:H?"Revoking...":"Revoke link"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):s("div",{className:"space-y-3",children:[s("p",{className:"text-[13px] text-text-secondary font-body",children:"Create a public link to this revision. Anyone with the link can view the canvas and leave feedback. Reviewer feedback will sync back here automatically."},void 0,!1,void 0,this),s("button",{onClick:y,disabled:z,className:"w-full px-3 py-2 text-[13px] font-body font-medium rounded bg-accent-blue text-white hover:opacity-90 transition-opacity disabled:opacity-50",children:z?"Creating share link...":"Create share link"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),W&&s("div",{className:"mt-3 px-3 py-2 rounded bg-accent-red/10 border border-accent-red/20 text-[12px] text-accent-red font-body",children:W},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function j5({onClick:Z,title:$="Share this revision",hasShare:q}){return s("button",{onClick:Z,className:`group p-1.5 transition-colors ${q?"text-accent-blue hover:opacity-80":"text-text-tertiary hover:text-text-secondary"}`,title:$,children:s("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[s("circle",{cx:"18",cy:"5",r:"3"},void 0,!1,void 0,this),s("circle",{cx:"6",cy:"12",r:"3"},void 0,!1,void 0,this),s("circle",{cx:"18",cy:"19",r:"3"},void 0,!1,void 0,this),s("line",{x1:"8.59",y1:"13.51",x2:"15.42",y2:"17.49"},void 0,!1,void 0,this),s("line",{x1:"15.41",y1:"6.51",x2:"8.59",y2:"10.49"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}import{useState as I6,useEffect as R6,useRef as D6}from"react";import{jsxDEV as P1}from"react/jsx-dev-runtime";function w5({open:Z,onClose:$,onSubmit:q}){let[Q,J]=I6(""),Y=D6(null);if(R6(()=>{if(Z)J(""),setTimeout(()=>Y.current?.focus(),50)},[Z]),!Z)return null;let X=Q.trim(),G=X.length>=1&&X.length<=80,z=()=>{if(!G)return;q(X)};return P1("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:$,children:P1("div",{className:"bg-bg-surface border border-border-medium rounded-lg shadow-xl w-full max-w-md mx-4 p-5",onClick:(_)=>_.stopPropagation(),children:[P1("div",{className:"flex items-center justify-between mb-3",children:[P1("h2",{className:"text-sm font-medium text-text-primary font-body",children:"Your name"},void 0,!1,void 0,this),P1("button",{onClick:$,className:"w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",children:P1("span",{className:"text-xs",children:"✕"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),P1("p",{className:"text-[13px] text-text-secondary font-body mb-3 leading-relaxed",children:"Before you leave feedback, please enter a name so the canvas author knows who reviewed it. This is stored locally in your browser."},void 0,!1,void 0,this),P1("input",{ref:Y,type:"text",value:Q,onChange:(_)=>J(_.target.value),onKeyDown:(_)=>{if(_.key==="Enter")z()},maxLength:80,placeholder:"e.g. Alice",className:"w-full px-3 py-2 text-[13px] font-body bg-bg-input border border-border-medium rounded text-text-primary placeholder:text-text-disabled focus:outline-none focus:border-accent-blue"},void 0,!1,void 0,this),P1("div",{className:"flex justify-end gap-2 mt-4",children:[P1("button",{onClick:$,className:"px-3 py-1.5 text-[12px] font-body font-medium rounded text-text-secondary hover:text-text-primary hover:bg-bg-elevated transition-colors",children:"Cancel"},void 0,!1,void 0,this),P1("button",{onClick:z,disabled:!G,className:"px-3 py-1.5 text-[12px] font-body font-medium rounded bg-accent-blue text-white hover:opacity-90 transition-opacity disabled:opacity-50",children:"Submit feedback"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}import{jsxDEV as F,Fragment as k0}from"react/jsx-dev-runtime";function C5(Z){let $=[];for(let q of Z)for(let Q of q.annotations)$.push({...Q,source:"remote",author:q.author});return $}var D1=D5({activeView:{type:"overview"},setActiveView:()=>{},openFiles:[],closeFile:()=>{},canvasFiles:[]}),A1=D5({currentRevision:1,selectedRevision:1,revisions:[],setSelectedRevision:()=>{},isReadOnly:!1,compareRevision:null,setCompareRevision:()=>{},agentWatching:!1});function m6(Z){if(Z==="auto")return window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light";return Z}function V5(Z){document.documentElement.dataset.theme=m6(Z)}function E5(){let[Z,$]=J1(()=>{let J=localStorage.getItem("canvas-theme");if(J==="light"||J==="dark"||J==="auto")return J;return"auto"});return y1(()=>{if(V5(Z),Z!=="auto")return;let J=window.matchMedia("(prefers-color-scheme: dark)"),Y=()=>V5("auto");return J.addEventListener("change",Y),()=>J.removeEventListener("change",Y)},[Z]),F("button",{onClick:()=>{let J=Z==="auto"?"light":Z==="light"?"dark":"auto";localStorage.setItem("canvas-theme",J),$(J)},className:"w-7 h-7 flex items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:{auto:"Theme: system (click for light)",light:"Theme: light (click for dark)",dark:"Theme: dark (click for system)"}[Z],children:Z==="auto"?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):Z==="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 x5(){let{currentRevision:Z,selectedRevision:$,revisions:q,setSelectedRevision:Q,setCompareRevision:J}=p1.useContext(A1);if(q.length<=1){let G=q[0]?.label||`Round ${Z}`;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(V0,{value:$,onChange:Q,accent:$===Z?"default":"amber"},void 0,!1,void 0,this),F("button",{onClick:()=>{let X;if($===Z)X=[...q].reverse().find((z)=>z.revision<Z)?.revision??Math.max(1,Z-1);else X=$;J({left:X,right:Z})},className:"text-[11px] font-body font-medium px-2 py-0.5 rounded-md text-accent-blue hover:bg-accent-blue-muted transition-colors self-start",children:"Compare"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function u6(){let Z=$1.isShared?$1.shareId:$1.sessionId,$=$1.isShared,[q,Q]=J1(1),[J,Y]=J1(1),[X,G]=J1([]),[z,_]=J1(null),[H,U]=J1(!1),[W,T]=J1(!1),[K,L]=J1(!1),[N,y]=J1([]),[O,R]=J1({type:"overview"}),[S,M]=J1([]),b=V1(null),g=V1([]),C=V1(new Set),[p,h]=J1(),[V,k]=J1(!1),[x,l]=J1(!1),[j,f]=J1(!1),[v,o]=J1(!1),[w,B]=J1([]),[m,u]=J1(!1),[D,a]=J1(new Map),[I,E]=J1(!1),[Z1,Y1]=J1(null),[I1,S1]=J1(null),H0=K0((A)=>{if($)return;let i=`${A.revision}\x00${A.filename}\x00${A.message}`;if(C.current.has(i))return;C.current.add(i);let t=JSON.stringify({type:"render-error",error:A});if(b.current?.readyState===WebSocket.OPEN)b.current.send(t);else g.current.push(A)},[$]);y1(()=>{if(!I1)return;let A=setTimeout(()=>S1(null),4000);return()=>clearTimeout(A)},[I1]),y1(()=>{let A=["Agent Canvas"];if(p){let i=p.replace(/\/+$/,"").split("/");A.push(i[i.length-1]||Z)}else if(Z)A.push(Z);if(O.type==="file")A.push(O.path.split("/").pop()||O.path);else if(O.type==="overview")A.push("Overview");else if(O.type==="canvas"&&N.length>1&&O.filename)A.push(O.filename.replace(/\.jsx$/,""));else if(z)A.push("Compare");document.title=A.join(" — ")},[Z,p,O,z]);let H2=V1(new Map),W0=X.find((A)=>A.revision===J),a2=J!==q||!!W0?.hasFeedback||W,o2=K0((A)=>{let i=O.type==="overview"?"overview":O.type==="canvas"?`canvas:${O.filename}`:`file:${O.path}`;if(H2.current.set(i,window.scrollY),R(A),A.type==="file")M((t)=>t.includes(A.path)?t:[...t,A.path])},[O]),m5=K0((A)=>{H2.current.delete(`file:${A}`),M((i)=>i.filter((t)=>t!==A)),R((i)=>{if(i.type==="file"&&i.path===A)return N.length>1?{type:"overview"}:{type:"canvas",filename:N[0]||""};return i})},[N]);k6(()=>{let A=O.type==="overview"?"overview":O.type==="canvas"?`canvas:${O.filename}`:`file:${O.path}`;window.scrollTo(0,H2.current.get(A)||0)},[O]),y1(()=>{if(!Z)return;b3().then((A)=>{if(A.currentRevision){let i=A.revisions||[];for(let t of i)if(t.hasFeedback)Q0(localStorage,Z,t.revision);w2(localStorage,Z,A.currentRevision,i),Q(A.currentRevision),Y(A.currentRevision),G(i)}if(A.canvasFiles){let i=A.canvasFiles.sort();y(i),R((t)=>{if(t.type==="overview")return i.length>1?t:{type:"canvas",filename:i[0]||""};if(t.type==="canvas"&&(!t.filename||!i.includes(t.filename)))return{type:"canvas",filename:i[0]||""};return t})}if(A.projectRoot)h(A.projectRoot);if(Array.isArray(A.shares))B(A.shares);u(!!A.shareEnabled)}).catch(()=>{})},[Z]),y1(()=>{if(!Z||!J||$)return;fetch(`/api/session/${Z}/revision/${J}/remote-feedback`).then((A)=>A.json()).then((A)=>{if(!Array.isArray(A.entries))return;let i=C5(A.entries);a((t)=>{let N1=new Map(t);return N1.set(J,i),N1})}).catch(()=>{})},[Z,J,$]),y1(()=>{if(!Z)return;if(!V3){U(!0);return}let A=null,i=()=>{let t=window.location.protocol==="https:"?"wss:":"ws:",N1=new WebSocket(`${t}//${window.location.host}/ws/session/${Z}`);b.current=N1,N1.onopen=()=>{U(!0);for(let E0 of g.current)N1.send(JSON.stringify({type:"render-error",error:E0}));g.current=[]},N1.onclose=()=>{U(!1),A=setTimeout(i,2000)},N1.onmessage=(E0)=>{try{let z1=JSON.parse(E0.data);if(z1.type==="plan-updated"){let O1=Array.isArray(z1.revisions)?z1.revisions:[];if(w2(localStorage,Z,z1.currentRevision,O1),Q(z1.currentRevision),Y(z1.currentRevision),_(null),O1.length>0){G(O1);let m1=O1.find((c1)=>c1.revision===z1.currentRevision);if(m1?.canvasFiles){let c1=m1.canvasFiles.map((N0)=>N0.filename).sort();y(c1);let T2=O1.find((N0)=>N0.revision===z1.currentRevision-1),T0=r2(m1,T2),q0=y5(T0);if(q0.length===1)R({type:"canvas",filename:q0[0]});else if(q0.length>1||c1.length>1)R({type:"overview"});else R({type:"canvas",filename:c1[0]||""})}}}if(z1.type==="revision-updated"){if(Array.isArray(z1.revisions)){let O1=z1.revisions;for(let m1 of O1)if(m1.hasFeedback)Q0(localStorage,Z,m1.revision);G(O1)}}if(z1.type==="watcher-status")L(!!z1.watching);if(z1.type==="remote-feedback"){let O1=z1.revision,m1=z1.entries||[],c1=C5(m1);a((T2)=>{let T0=new Map(T2),q0=T0.get(O1)||[],N0=new Set(q0.map((N2)=>N2.id)),u5=[...q0,...c1.filter((N2)=>!N0.has(N2.id))];return T0.set(O1,u5),T0})}}catch{}}};return i(),()=>{if(A)clearTimeout(A);b.current?.close()}},[Z]);let W2=K0(async(A,i)=>{try{let t=localStorage.getItem(`canvas:${Z}:rev:${J}`),N1=[];if(t)try{N1=(JSON.parse(t).annotations||[]).filter((z1)=>z1.source!=="remote")}catch{}await C3({author:i,revision:J,annotations:N1,generalNote:A}),Q0(localStorage,Z,J),T(!0),S1({kind:"success",message:"Feedback submitted. The canvas author will see it shortly."})}catch(t){S1({kind:"error",message:`Failed to submit feedback: ${t.message||t}`})}},[Z,J]),s2=K0(async(A)=>{if($){let i=C2();if(!i){Y1(A),E(!0);return}await W2(A,i);return}if(b.current?.readyState===WebSocket.OPEN)b.current.send(JSON.stringify({type:"submit",feedback:A}))},[$,W2]);if(!Z)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(k5.Provider,{value:Z,children:F(t0.Provider,{value:H0,children:F(A1.Provider,{value:{currentRevision:q,selectedRevision:J,revisions:X,setSelectedRevision:Y,isReadOnly:a2,compareRevision:z,setCompareRevision:_,agentWatching:K},children:F(O3,{sessionId:Z,revision:J,isReadOnly:a2,remoteAnnotations:D.get(J),children:F(D1.Provider,{value:{activeView:O,setActiveView:o2,openFiles:S,closeFile:m5,canvasFiles:N},children:F(x6.Provider,{value:{setActiveView:o2},children:F("div",{className:"min-h-screen bg-bg-base",children:[F(g6,{sessionId:Z,projectRoot:p,connected:H,onMobileSidebar:()=>k(!V),collapsed:x,onToggle:()=>l((A)=>!A)},void 0,!1,void 0,this),F(f6,{collapsed:j,onToggle:()=>f((A)=>!A),children:F(v2,{onSubmit:s2},void 0,!1,void 0,this)},void 0,!1,void 0,this),z!==null?F("div",{className:`${x?"lg:ml-0":"lg:ml-60"} ${j?"lg:mr-0":"lg:mr-[var(--sidebar-width,320px)]"} transition-[margin] duration-200`,children:F(L5,{initialLeft:z.left,initialRight:z.right,sessionId:Z,onExit:()=>_(null)},void 0,!1,void 0,this)},void 0,!1,void 0,this):F("div",{className:`relative ${x?"lg:ml-0":"lg:ml-60"} ${j?"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(p2,{currentSessionId:Z,projectRoot:p},void 0,!1,void 0,this),$&&F("span",{className:"text-[11px] text-text-tertiary font-body",children:"Shared canvas"},void 0,!1,void 0,this),!$&&F("span",{className:`w-1.5 h-1.5 rounded-full ${H?"bg-accent-green":"bg-accent-red"}`},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("div",{className:"flex items-center gap-1",children:[F(x5,{},void 0,!1,void 0,this),F("button",{onClick:()=>k(!V),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(E5,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),F(v6,{},void 0,!1,void 0,this),O.type==="overview"&&F(S5,{revision:J,responseBanner:W0?.response?F(I5,{markdown:W0.response},void 0,!1,void 0,this):void 0},void 0,!1,void 0,this),O.type==="canvas"&&N.includes(O.filename)&&F("div",{className:"relative max-w-[720px] mx-auto px-6 pt-12 pb-32",children:[m&&F("div",{className:"absolute top-3 right-12 z-10",children:F(j5,{onClick:()=>o(!0),hasShare:w.some((A)=>A.revision===J),title:w.some((A)=>A.revision===J)?"Manage share link":"Share this revision"},void 0,!1,void 0,this)},void 0,!1,void 0,this),F("button",{onClick:()=>{let A=document.querySelector(`[data-canvas-file="${O.filename}"] .plan-content`);if(!A)return;let i=Y5(A);navigator.clipboard.writeText(i).then(()=>{let t=document.getElementById("export-md-btn");if(t)t.setAttribute("data-copied","true"),setTimeout(()=>{t.removeAttribute("data-copied")},1500)})},id:"export-md-btn",className:"group absolute top-3 right-6 p-1.5 text-text-tertiary hover:text-text-secondary transition-colors z-10",title:"Copy as Markdown",children:[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&&W0?.response&&F(I5,{markdown:W0.response},void 0,!1,void 0,this),F("div",{"data-canvas-file":O.filename,children:F(j0,{revision:J,filename:O.filename},O.filename,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),S.map((A)=>F("div",{style:{display:O.type==="file"&&O.path===A?void 0:"none"},children:F(Z5,{path:A},void 0,!1,void 0,this)},A,!1,void 0,this))]},void 0,!0,void 0,this),V&&F("div",{className:"lg:hidden fixed inset-0 z-40 flex",children:[F("div",{className:"flex-1",onClick:()=>k(!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:()=>k(!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(v2,{onSubmit:s2},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(b5,{sessionId:Z,revision:J,open:v,shareEnabled:m,existingShares:w,onClose:()=>o(!1),onShareCreated:(A)=>{B((i)=>[...i.filter((t)=>t.shareId!==A.shareId),A]),S1({kind:"success",message:"Share link created. Copy and send it to reviewers."})},onShareRevoked:(A)=>{B((i)=>i.filter((t)=>t.shareId!==A)),S1({kind:"success",message:"Share link revoked."})}},void 0,!1,void 0,this),F(w5,{open:I,onClose:()=>{E(!1),Y1(null)},onSubmit:async(A)=>{let i=A3(A);if(E(!1),Z1!==null)await W2(Z1,i),Y1(null)}},void 0,!1,void 0,this),I1&&F("div",{className:`fixed bottom-4 left-1/2 -translate-x-1/2 z-50 px-4 py-2.5 rounded-lg shadow-lg text-[13px] font-body font-medium flex items-center gap-2 ${I1.kind==="error"?"bg-accent-red text-white":"bg-accent-green text-white"}`,children:[I1.message,F("button",{onClick:()=>S1(null),className:"ml-2 opacity-70 hover:opacity-100",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},`${Z}:${J}`,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function g6({sessionId:Z,projectRoot:$,connected:q,onMobileSidebar:Q,collapsed:J,onToggle:Y}){let X=$1.isShared;return F(k0,{children:[J&&F("button",{onClick:Y,className:"hidden lg:flex fixed top-3 left-3 z-20 w-7 h-7 items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors bg-bg-surface border border-border-subtle",title:"Show sidebar",children: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 ${J?"-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),X?F("span",{className:"text-[12px] font-body text-text-secondary truncate flex-1",children:"Shared canvas"},void 0,!1,void 0,this):F(k0,{children:[F(p2,{currentSessionId:Z,projectRoot:$},void 0,!1,void 0,this),F("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${q?"bg-accent-green":"bg-accent-red"}`},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("button",{onClick:Y,className:"ml-auto w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Hide sidebar",children: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(x5,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("div",{className:"flex-1 flex flex-col overflow-hidden",children:F(t3,{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(E5,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function f6({children:Z,collapsed:$,onToggle:q}){let[Q,J]=J1(()=>{let H=localStorage.getItem("canvas-sidebar-width");return H?parseInt(H,10):320}),Y=V1(!1),X=V1(0),G=V1(0),z=V1(Q);z.current=Q;let _=K0((H)=>{H.preventDefault(),Y.current=!0,X.current=H.clientX,G.current=z.current;let U=(T)=>{if(!Y.current)return;let K=X.current-T.clientX,L=Math.max(240,Math.min(600,G.current+K));J(L),z.current=L},W=()=>{Y.current=!1,localStorage.setItem("canvas-sidebar-width",String(z.current)),document.removeEventListener("mousemove",U),document.removeEventListener("mouseup",W),document.body.style.cursor="",document.body.style.userSelect=""};document.addEventListener("mousemove",U),document.addEventListener("mouseup",W),document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[]);return y1(()=>{return document.documentElement.style.setProperty("--sidebar-width",`${Q}px`),()=>{document.documentElement.style.removeProperty("--sidebar-width")}},[Q]),F(k0,{children:[$&&F("button",{onClick:q,className:"hidden lg:flex fixed top-3 right-3 z-20 w-7 h-7 items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors bg-bg-surface border border-border-subtle",title:"Show annotations",children: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:Q},children:[F("div",{onMouseDown:_,className:"absolute left-0 top-0 bottom-0 w-1 cursor-col-resize hover:bg-accent-blue/30 transition-colors z-20",style:{marginLeft:"-2px"}},void 0,!1,void 0,this),p1.Children.map(Z,(H)=>p1.isValidElement(H)?p1.cloneElement(H,{collapseButton:F("button",{onClick:q,className:"w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Hide annotations",children: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 I5({markdown:Z}){let[$,q]=J1(!1),Q=A5(()=>e.parse(Z,{async:!1}),[Z]),J=V1(null),{annotations:Y,addAnnotationWithId:X,removeAnnotation:G,updateAnnotation:z,addAnnotationImage:_,removeAnnotationImage:H,activeAnnotationId:U,setActiveAnnotationId:W}=X1(),[T,K]=J1(null),[L,N]=J1(null),y=A5(()=>Y.filter((b)=>b.filePath===T1),[Y]),[O,R]=J1(Z);if(Z!==O)R(Z),q(!1);y1(()=>{if(!J.current||y.length===0)return;let b=setTimeout(()=>{if(J.current)a0(J.current,y)},50);return()=>clearTimeout(b)},[Q,y.length]);let S=V1(null);if(y1(()=>{r0(U,S.current),S.current=U},[U]),y1(()=>{let b=J.current;if(!b)return;let g=(h)=>{let V=h.target.closest("[data-annotation-id]");if(!V)return;h.stopPropagation();let k=V.getAttribute("data-annotation-id");if(k===U)N({anchorEl:V,annId:k});else W(k)},C=(h)=>{let V=h.target.closest("[data-annotation-id]");if(V)W(V.getAttribute("data-annotation-id"))},p=(h)=>{let V=h.target.closest("[data-annotation-id]"),k=h.relatedTarget?.closest?.("[data-annotation-id]");if(V&&!k)W(null)};return b.addEventListener("click",g),b.addEventListener("mouseover",C),b.addEventListener("mouseout",p),()=>{b.removeEventListener("click",g),b.removeEventListener("mouseover",C),b.removeEventListener("mouseout",p)}},[Q,U]),y1(()=>{let b=()=>{let g=window.getSelection();if(!g||g.isCollapsed||!g.toString().trim())return;if(!J.current)return;let C=g.getRangeAt(0);if(!J.current.contains(C.startContainer))return;if(C.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let p=g.toString().trim();if(p.length<2)return;let h=C.cloneRange(),V=i1(C,J.current),k=`__pending_${Date.now()}`;try{o1(h,k)}catch{}window.getSelection()?.removeAllRanges();let x=document.querySelectorAll(`[data-annotation-id="${k}"]`),l=x[x.length-1];if(!l)return;K({anchorEl:l,tempId:k,snippet:p,ctx:V})};return document.addEventListener("mouseup",b),()=>document.removeEventListener("mouseup",b)},[]),$)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:()=>q(!0),className:"absolute top-2 right-2 w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",children: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:J,className:"prose-canvas text-sm",dangerouslySetInnerHTML:{__html:Q}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),T&&F(X0,{anchorEl:T.anchorEl,scrollContainer:M,snippet:T.snippet,truncateAt:80,onAdd:(b,g)=>{let C=L1();i0(T.tempId,C),X(C,T.snippet,b,T1,T.ctx,g),K(null)},onCancel:()=>{o0(T.tempId),K(null)}},void 0,!1,void 0,this),L&&(()=>{let b=Y.find((g)=>g.id===L.annId);if(!b)return null;return F(z0,{anchorEl:L.anchorEl,scrollContainer:M,initialNote:b.note,initialImages:b.images,onUpdate:(g,C)=>{z(L.annId,g);let p=b.images||[];for(let h of C)if(!p.includes(h))_(L.annId,h);for(let h of p)if(!C.includes(h))H(L.annId,h)},onDelete:()=>{G(L.annId),W(null)},onClose:()=>N(null)},void 0,!1,void 0,this)})()]},void 0,!0,void 0,this)}function v6(){let{activeView:Z,setActiveView:$,openFiles:q,closeFile:Q,canvasFiles:J}=p1.useContext(D1),Y=p1.useContext(k5),{addAnnotationWithId:X,setActiveAnnotationId:G}=X1();if(!(J.length>1||q.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:[J.length>1&&F(k0,{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 ${Z.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",Z.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),J.map((_,H)=>{let U=_.replace(/\.jsx$/,""),W=Z.type==="canvas"&&Z.filename===_;return F(p1.Fragment,{children:[F("button",{onClick:()=>$({type:"canvas",filename:_}),className:`flex items-center gap-1.5 px-4 py-2.5 text-[13px] font-body whitespace-nowrap transition-colors relative ${W?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[U,W&&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<J.length-1&&F("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this)]},_,!0,void 0,this)}),q.length>0&&F(k0,{children:[F("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this),q.map((_,H)=>{let U=_.split("/").pop()||_,W=Z.type==="file"&&Z.path===_;return F(p1.Fragment,{children:[F("div",{className:"flex items-center",children:[F("button",{onClick:()=>$({type:"file",path:_}),className:`flex items-center gap-1.5 pl-3 pr-1 py-2.5 text-[13px] font-body whitespace-nowrap transition-colors relative ${W?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[F(g1,{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:(T)=>{T.stopPropagation(),Q(_)},className:"text-text-tertiary hover:text-text-secondary px-1.5 py-1 text-[10px] transition-colors rounded hover:bg-bg-input",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),H<q.length-1&&F("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this)]},_,!0,void 0,this)})]},void 0,!0,void 0,this),F("div",{className:"ml-auto flex items-center gap-1 flex-shrink-0",children:Z.type==="file"&&M1&&F("button",{onClick:async()=>{let _=Z.path;try{let U=await(await fetch(`/api/file?session=${Y}&path=${encodeURIComponent(_)}`)).json();if(!U.error){let W=U.content.split(`
83
+ `}var c$=new Set(["CODE","SPAN","STRONG","EM","A","B","I","U","SMALL","SUB","SUP","MARK","ABBR"]);function R2($,Q,J){if(d$($)){let X=l$($);if(X)Q.push(X,"");return}for(let X of $.childNodes)if(X.nodeType===Node.ELEMENT_NODE)r$(X,Q,J);else if(X.nodeType===Node.TEXT_NODE){let Y=X.textContent?.trim();if(Y)Q.push(Y,"")}}function d$($){for(let Q of $.childNodes){if(Q.nodeType===Node.TEXT_NODE)continue;if(Q.nodeType===Node.ELEMENT_NODE){let J=Q;if(!c$.has(J.tagName)||J.hasAttribute("data-md"))return!1}}return $.childNodes.length>0}function l$($){let Q="";for(let J of $.childNodes)if(J.nodeType===Node.TEXT_NODE)Q+=J.textContent||"";else if(J.nodeType===Node.ELEMENT_NODE){let X=J;if(X.tagName==="CODE")Q+="`"+(X.textContent||"")+"`";else Q+=X.textContent||""}return Q.trim()}function r$($,Q,J){let X=$.getAttribute("data-md");if(X)switch(X){case"section":return i$($,Q,J);case"item":return o$($,Q);case"codeblock":return a$($,Q);case"callout":return s$($,Q);case"note":return t$($,Q);case"markdown":return J8($,Q);case"table":return n$($,Q);case"checklist":return e$($,Q);case"diff":return $8($,Q);case"mermaid":return Q8($,Q);case"choice":return Y8($,Q);case"multichoice":return X8($,Q);case"choice-option":case"multichoice-option":return;case"userinput":return q8($,Q);case"rangeinput":return Z8($,Q);case"checklist-item":return;case"filepreview":return G8($,Q);case"priority":return U8($,Q)}if($.querySelector("button, input, select, textarea"))return;if($.children.length>0)R2($,Q,J);else{let Y=$.textContent?.trim();if(Y)Q.push(Y,"")}}function i$($,Q,J){let X=$.getAttribute("data-md-title")||"Untitled",Y=J===0?"##":"###";Q.push(`${Y} ${X}`,"");let Z=$.querySelector(":scope > div:last-of-type");if(Z)R2(Z,Q,J+1)}function o$($,Q){let J=$.getAttribute("data-md-label")||"",X=$.getAttribute("data-md-status"),Y=$.getAttribute("data-md-badge"),Z="-";if(X==="done")Z="- [x]";else if(X)Z="- [ ]";let q=`${Z} **${J}**`;if(Y)q+=` \`${Y}\``;Q.push(q);let U=$.querySelector(".text-text-secondary");if(U){let G=[];R2(U,G,0);for(let K of G)Q.push(K?` ${K}`:"")}Q.push("")}function a$($,Q){let J=$.getAttribute("data-md-language")||"",Y=$.querySelector("code")?.textContent||"";Q.push(`\`\`\`${J}`,Y,"```","")}function s$($,Q){let J=$.getAttribute("data-md-type")||"info",X={info:"Info",warning:"Warning",danger:"Danger",tip:"Tip"},Y=K8($.querySelector(".text-text-secondary")||$);Q.push(`> **${X[J]||J}:** ${Y}`,"")}function t$($,Q){let J=$.textContent?.trim()||"";Q.push(`> *${J}*`,"")}function n$($,Q){let J=$.querySelector("table");if(!J)return;let X=[];for(let Y of J.querySelectorAll("thead th"))X.push(Y.textContent?.trim()||"");if(X.length===0)return;Q.push(`| ${X.join(" | ")} |`),Q.push(`| ${X.map(()=>"---").join(" | ")} |`);for(let Y of J.querySelectorAll("tbody tr")){let Z=[];for(let q of Y.querySelectorAll("td"))Z.push(q.textContent?.trim()||"");Q.push(`| ${Z.join(" | ")} |`)}Q.push("")}function e$($,Q){for(let J of $.querySelectorAll("li")){let X=J.querySelector(".bg-accent-green")!==null,Y=J.textContent?.trim()||"";Q.push(`- [${X?"x":" "}] ${Y}`)}Q.push("")}function $8($,Q){let J=$.getAttribute("data-md-language")||"";Q.push(`\`\`\`diff${J?` (${J})`:""}`);for(let X of $.querySelectorAll("[class*='flex']")){let Y=X.querySelector(".text-accent-red")?"-":X.querySelector(".text-accent-green")?"+":" ",Z=X.querySelector("code");if(Z)Q.push(`${Y} ${Z.textContent}`)}Q.push("```","")}function Q8($,Q){let J=$.getAttribute("data-md-source")||"";if(J)Q.push("```mermaid",J,"```","")}function J8($,Q){let J=$.getAttribute("data-md-source")||"";if(J)Q.push(J,"")}function Y8($,Q){let J=$.getAttribute("data-md-label")||"";Q.push(`**${J}:**`);for(let X of $.querySelectorAll("[data-md='choice-option']")){let Y=X.getAttribute("data-md-label")||X.textContent?.trim()||"",Z=X.querySelector(".bg-accent-amber")!==null;Q.push(`- ${Z?"(x)":"( )"} ${Y}`)}Q.push("")}function X8($,Q){let J=$.getAttribute("data-md-label")||"";Q.push(`**${J}:**`);for(let X of $.querySelectorAll("[data-md='multichoice-option']")){let Y=X.getAttribute("data-md-label")||X.textContent?.trim()||"",Z=X.querySelector(".bg-accent-amber")!==null;Q.push(`- [${Z?"x":" "}] ${Y}`)}Q.push("")}function q8($,Q){let J=$.getAttribute("data-md-label")||"",Y=$.querySelector("textarea")?.value?.trim()||"";Q.push(`**${J}:** ${Y||"_empty_"}`,"")}function Z8($,Q){let J=$.getAttribute("data-md-label")||"",X=$.querySelector("input[type='range']"),Z=$.querySelector(".font-mono")?.textContent?.trim()||X?.value||"—";Q.push(`**${J}:** ${Z}`,"")}function G8($,Q){let J=$.getAttribute("data-md-path")||"",X=$.getAttribute("data-md-lines")||"",Z=$.querySelector("code")?.textContent||"",q=J.split(".").pop()||"",U=V2[q]||"",G=X?`${J} (L${X})`:J;Q.push(G,"",`\`\`\`${U}`,Z,"```","")}function U8($,Q){}function K8($){return $?.textContent?.trim()||""}import T4,{useEffect as J0,useState as N1,useRef as c1,useCallback as F4,useMemo as x2,useContext as w8}from"react";import{useEffect as z8,useState as _8,useRef as H8,useContext as W8}from"react";import{jsxDEV as F1,Fragment as q4}from"react/jsx-dev-runtime";function N8($){return $.label||`Round ${$.revision}`}function B8($){let Q=Date.now()-new Date($).getTime(),J=Math.floor(Q/1000);if(J<60)return"just now";let X=Math.floor(J/60);if(X<60)return`${X}m ago`;let Y=Math.floor(X/60);if(Y<24)return`${Y}h ago`;return`${Math.floor(Y/24)}d ago`}function e0({value:$,onChange:Q,accent:J="default",className:X}){let{currentRevision:Y,revisions:Z}=W8(S1),[q,U]=_8(!1),G=H8(null);z8(()=>{if(!q)return;let z=(W)=>{if(G.current&&!G.current.contains(W.target))U(!1)};return document.addEventListener("mousedown",z),()=>document.removeEventListener("mousedown",z)},[q]);let K=Z.find((z)=>z.revision===$);return F1("div",{className:"relative",ref:G,children:[F1("button",{onClick:()=>U(!q),className:`flex items-center gap-1.5 text-[12px] font-body font-medium px-2 py-1 rounded-md transition-colors hover:bg-bg-elevated ${{default:"text-text-secondary hover:text-text-primary",red:"text-accent-red",green:"text-accent-green",amber:"text-accent-amber bg-highlight-selected"}[J]} ${X||""}`,children:[K?N8(K):`Round ${$}`,F1("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",className:`text-text-tertiary transition-transform duration-200 ${q?"rotate-180":""}`,children:F1("path",{d:"M2.5 4l2.5 2.5L7.5 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),q&&F1("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:[...Z].reverse().map((z)=>F1("button",{onClick:()=>{Q(z.revision),U(!1)},className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] font-body transition-colors ${z.revision===$?"bg-bg-surface text-text-primary":"text-text-secondary hover:bg-bg-surface hover:text-text-primary"}`,children:[F1("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${z.revision===Y?"bg-accent-green":z.hasFeedback?"bg-accent-amber":"bg-border-hover"}`},void 0,!1,void 0,this),F1("span",{className:"flex-1 text-left truncate",children:z.label?F1(q4,{children:[z.label," ",F1("span",{className:"text-text-tertiary",children:["#",z.revision]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):F1(q4,{children:["Round ",z.revision]},void 0,!0,void 0,this)},void 0,!1,void 0,this),F1("span",{className:"text-[10px] text-text-tertiary flex-shrink-0 flex items-center gap-1.5",children:[(()=>{let W=z.canvasFiles?.reduce((H,N)=>{if(N.diffStats)H.added+=N.diffStats.added,H.removed+=N.diffStats.removed;return H},{added:0,removed:0});if(W&&(W.added>0||W.removed>0))return F1("span",{className:"font-mono",children:[F1("span",{className:"text-accent-green",children:["+",W.added]},void 0,!0,void 0,this)," ",F1("span",{className:"text-accent-red",children:["-",W.removed]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);return null})(),z.revision===Y?"current":z.hasFeedback?"sent":B8(z.createdAt)]},void 0,!0,void 0,this)]},z.revision,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Q0($,Q){let J=$.length,X=Q.length;if(J===0||X===0)return[];let Y=Array.from({length:J+1},()=>Array(X+1).fill(0));for(let G=1;G<=J;G++)for(let K=1;K<=X;K++)Y[G][K]=$[G-1]===Q[K-1]?Y[G-1][K-1]+1:Math.max(Y[G-1][K],Y[G][K-1]);let Z=[],q=J,U=X;while(q>0&&U>0)if($[q-1]===Q[U-1])Z.unshift($[q-1]),q--,U--;else if(Y[q-1][U]>Y[q][U-1])q--;else U--;return Z}function Z4($){let Q=[],J=[],X=document.createTreeWalker($,NodeFilter.SHOW_TEXT,{acceptNode(Z){let q=Z.parentElement;if(!q)return NodeFilter.FILTER_REJECT;if(q.closest("svg, .select-none, [data-no-diff]"))return NodeFilter.FILTER_REJECT;return NodeFilter.FILTER_ACCEPT}}),Y;while(Y=X.nextNode()){let q=(Y.nodeValue||"").match(/\S+|\s+/g);if(!q)continue;let U=0;for(let G of q)Q.push(G),J.push({text:G,node:Y,offset:U}),U+=G.length}return{words:Q,map:J}}function j5($,Q){if($.length>5000||Q.length>5000)return T8($,Q);return K4($,Q)}function K4($,Q){let J=D2($,Q),X=[],Y=[],Z=0,q=0,U=0;while(Z<$.length||q<Q.length)if(U<J.length&&Z<$.length&&q<Q.length&&$[Z]===J[U]&&Q[q]===J[U])X.push({type:"same",index:Z}),Y.push({type:"same",index:q}),Z++,q++,U++;else if(Z<$.length&&(U>=J.length||$[Z]!==J[U]))X.push({type:"removed",index:Z}),Z++;else if(q<Q.length)Y.push({type:"added",index:q}),q++;return{oldOps:X,newOps:Y}}function D2($,Q){let J=$.length,X=Q.length;if(J===0||X===0)return[];if(J===1)return Q.includes($[0])?[$[0]]:[];if(X===1)return $.includes(Q[0])?[Q[0]]:[];if(J*X<=1e6)return Q0($,Q);let Y=Math.floor(J/2),Z=$.slice(0,Y),q=$.slice(Y),U=G4(Z,Q),G=G4([...q].reverse(),[...Q].reverse()),K=0,_=0;for(let H=0;H<=X;H++){let N=U[H]+G[X-H];if(N>K)K=N,_=H}let z=Q.slice(0,_),W=Q.slice(_);return[...D2(Z,z),...D2(q,W)]}function G4($,Q){let J=Q.length,X=Array(J+1).fill(0),Y=Array(J+1).fill(0);for(let Z=0;Z<$.length;Z++){for(let q=1;q<=J;q++)Y[q]=$[Z]===Q[q-1]?X[q-1]+1:Math.max(X[q],Y[q-1]);[X,Y]=[Y,X],Y.fill(0)}return X}function T8($,Q){let X=(N)=>{let O=[];for(let B=0;B<N.length;B+=200){let A=Math.min(B+200,N.length);O.push({start:B,end:A,text:N.slice(B,A).join("")})}return O},Y=X($),Z=X(Q),q=Y.map((N)=>N.text),U=Z.map((N)=>N.text),G=D2(q,U),K=[],_=[],z=0,W=0,H=0;while(z<Y.length||W<Z.length)if(H<G.length&&z<Y.length&&W<Z.length&&q[z]===G[H]&&U[W]===G[H]){for(let N=Y[z].start;N<Y[z].end;N++)K.push({type:"same",index:N});for(let N=Z[W].start;N<Z[W].end;N++)_.push({type:"same",index:N});z++,W++,H++}else if(z<Y.length&&(H>=G.length||q[z]!==G[H]))if(W<Z.length&&(H>=G.length||U[W]!==G[H])){let N=K4($.slice(Y[z].start,Y[z].end),Q.slice(Z[W].start,Z[W].end));for(let O of N.oldOps)K.push({type:O.type,index:O.index+Y[z].start});for(let O of N.newOps)_.push({type:O.type,index:O.index+Z[W].start});z++,W++}else{for(let N=Y[z].start;N<Y[z].end;N++)K.push({type:"removed",index:N});z++}else if(W<Z.length){for(let N=Z[W].start;N<Z[W].end;N++)_.push({type:"added",index:N});W++}return{oldOps:K,newOps:_}}function U4($,Q,J){let X=new Map;for(let Y of $){if(Y.type==="same")continue;let Z=Q[Y.index];if(!Z||!Z.node.parentNode)continue;let q=X.get(Z.node);if(!q)q=[],X.set(Z.node,q);q.push({offset:Z.offset,length:Z.text.length})}for(let[Y,Z]of X){if(!Y.parentNode)continue;let q=Y.nodeValue||"";Z.sort((z,W)=>z.offset-W.offset);let U=[];for(let z of Z){let W=U[U.length-1];if(W&&z.offset<=W.offset+W.length)W.length=Math.max(W.length,z.offset+z.length-W.offset);else U.push({...z})}let G=Y.parentNode,K=document.createDocumentFragment(),_=0;for(let z of U){if(z.offset>_)K.appendChild(document.createTextNode(q.slice(_,z.offset)));let W=document.createElement("span");W.className=J,W.textContent=q.slice(z.offset,z.offset+z.length),K.appendChild(W),_=z.offset+z.length}if(_<q.length)K.appendChild(document.createTextNode(q.slice(_)));G.replaceChild(K,Y)}}function m2($,Q){let J=F8($,Q),X=Z4($),Y=Z4(Q),{oldOps:Z,newOps:q}=j5(X.words,Y.words),U=Z.some((G)=>G.type==="removed")||q.some((G)=>G.type==="added");return U4(Z,X.map,"diff-removed"),U4(q,Y.map,"diff-added"),U||J}function F8($,Q){let J=Array.from($.querySelectorAll('[data-md="mermaid"]')),X=Array.from(Q.querySelectorAll('[data-md="mermaid"]')),Y=!1,Z=Math.max(J.length,X.length);for(let q=0;q<Z;q++){let U=J[q],G=X[q];if(!U&&G){G.classList.add("diff-block-added"),G.style.position="relative",Y=!0;continue}if(U&&!G){U.classList.add("diff-block-removed"),U.style.position="relative",Y=!0;continue}if(!U||!G)continue;let K=(U.getAttribute("data-md-source")||"").trim(),_=(G.getAttribute("data-md-source")||"").trim();if(K===_)continue;Y=!0,U.style.borderLeft="3px solid var(--color-accent-red)",U.style.paddingLeft="8px",G.style.borderLeft="3px solid var(--color-accent-green)",G.style.paddingLeft="8px";let z=K.split(`
84
+ `),W=_.split(`
85
+ `),H=Q0(z,W),N=(O,B,A)=>{let T=document.createElement("div");T.className="mt-2 bg-bg-code rounded-md overflow-hidden text-tiny font-mono",T.setAttribute("data-no-diff","true");let M=0,y=0;while(y<O.length){let L=document.createElement("div");if(L.className="px-3 py-0.5 whitespace-pre-wrap",M<B.length&&O[y]===B[M])L.textContent=" "+O[y],y++,M++;else L.classList.add(A==="old"?"diff-removed":"diff-added"),L.textContent=(A==="old"?"- ":"+ ")+O[y],y++;T.appendChild(L)}return T};U.appendChild(N(z,H,"old")),G.appendChild(N(W,H,"new"))}return Y}function C0($){let Q=[],J=$.querySelectorAll(":scope > [data-md]");for(let X of J)Q.push($2(X));if(Q.length===0){let X=$.querySelectorAll("[data-md]"),Y=new Set;for(let Z of X){let q=Z.parentElement?.closest("[data-md]");if(q&&$.contains(q))continue;if(Y.has(Z))continue;Y.add(Z),Q.push($2(Z))}}return Q}function $2($){let Q=$.getAttribute("data-md")||"unknown",J=O8($,Q),X=[];if(Q==="section"){let Y=$.querySelector(":scope > div.mt-6, :scope > div:last-child");if(Y)for(let Z of Y.querySelectorAll(":scope > [data-md]"))X.push($2(Z))}else if(Q==="table")for(let Y of $.querySelectorAll(":scope table > tbody > tr"))X.push({key:"tr:"+(Y.textContent||"").slice(0,80),type:"tr",element:Y,children:[]});else if(Q==="checklist")for(let Y of $.querySelectorAll(":scope > [data-md='checklist-item']"))X.push($2(Y));else for(let Y of $.querySelectorAll("[data-md]"))if(Y.parentElement?.closest("[data-md]")===$)X.push($2(Y));return{key:J,type:Q,element:$,children:X}}function O8($,Q){switch(Q){case"section":return"section:"+($.getAttribute("data-md-title")||"");case"item":return"item:"+($.getAttribute("data-task-id")||$.getAttribute("data-md-label")||"");case"codeblock":case"diff":return Q+":"+($.textContent||"").slice(0,80);case"checklist-item":return"checklist-item:"+($.getAttribute("data-md-label")||$.textContent?.slice(0,60)||"");case"checklist":return"checklist:"+$.querySelectorAll("[data-md='checklist-item']").length;case"markdown":return"markdown:"+($.getAttribute("data-md-file")||"inline");case"mermaid":return"mermaid:"+($.getAttribute("data-md-source")||"").slice(0,80);case"callout":return"callout:"+($.getAttribute("data-md-type")||"")+":"+($.textContent||"").slice(0,60);default:return Q+":"+($.getAttribute("data-md-label")||$.textContent?.slice(0,60)||"")}}function Q2($,Q){let J=$.map((K)=>K.key),X=Q.map((K)=>K.key),Y=Q0(J,X),Z=[],q=0,U=0,G=0;while(q<$.length||U<Q.length)if(G<Y.length&&q<$.length&&U<Q.length&&J[q]===Y[G]&&X[U]===Y[G]){let K=$[q],_=Q[U],z=K.children.length>0||_.children.length>0?Q2(K.children,_.children):void 0;Z.push({kind:"matched",oldBlock:K,newBlock:_,childMatches:z}),q++,U++,G++}else if(q<$.length&&(G>=Y.length||J[q]!==Y[G]))Z.push({kind:"removed",oldBlock:$[q]}),q++;else if(U<Q.length)Z.push({kind:"added",newBlock:Q[U]}),U++;return Z}function E2($){let Q=document.createDocumentFragment(),J=!1;for(let X of $)if(X.kind==="removed")J=!0,Q.appendChild(_4(X.oldBlock.element));else if(X.kind==="added")J=!0,Q.appendChild(L8(X.newBlock.element));else{let Y=X.newBlock.element.cloneNode(!0),Z=X.newBlock.type;if(Z==="mermaid"){if(B4(X.oldBlock.element,Y))J=!0}else if(X.childMatches&&X.childMatches.length>0&&(Z==="table"||Z==="checklist")){if(W4(Y,X.childMatches,Z))J=!0}else if(X.childMatches&&X.childMatches.length>0){if(H4(X.oldBlock,Y,X.childMatches,Z))J=!0}else if(Z==="markdown"){if(N4(X.oldBlock.element,Y))J=!0}else if(T0(X.oldBlock.element,Y,!1))J=!0;Q.appendChild(Y)}return{fragment:Q,hasChanges:J}}function _4($){let Q=$.cloneNode(!0);return Q.classList.add("diff-block-removed"),Q.style.position="relative",V5(Q,"Removed","var(--color-accent-red)"),Q}function L8($){let Q=$.cloneNode(!0);return Q.classList.add("diff-block-added"),Q.style.position="relative",V5(Q,"Added","var(--color-accent-green)"),Q}function H4($,Q,J,X){let Y=!1,Z=M8($,Q),q,U;if(X==="section"){let G=$.element.querySelector(":scope > div:first-child"),K=Q.querySelector(":scope > div:first-child");if(G&&K){if(T0(G,K,!1))Y=!0}q=$.element.querySelector(":scope > div.mt-6, :scope > div:last-child"),U=Q.querySelector(":scope > div.mt-6, :scope > div:last-child")}else q=$.element,U=Q;if(!q||!U)return Y;for(let G of J)if(G.kind==="matched"){let K=Z.newMap.get(G.newBlock.element);if(K){if(G.newBlock.type==="mermaid"){if(B4(G.oldBlock.element,K))Y=!0}else if(G.childMatches&&G.childMatches.length>0&&(G.newBlock.type==="table"||G.newBlock.type==="checklist")){if(W4(K,G.childMatches,G.newBlock.type))Y=!0}else if(G.childMatches&&G.childMatches.length>0){if(H4(G.oldBlock,K,G.childMatches,G.newBlock.type))Y=!0}else if(G.newBlock.type==="markdown"){if(N4(G.oldBlock.element,K))Y=!0}else if(T0(G.oldBlock.element,K,!1))Y=!0}}else if(G.kind==="removed"){Y=!0;let K=_4(G.oldBlock.element),_=y8(J,G,Z.newMap),z=_?S8(U,_):null;U.insertBefore(K,z)}else if(G.kind==="added"){Y=!0;let K=Z.newMap.get(G.newBlock.element);if(K)K.classList.add("diff-block-added"),K.style.position="relative",V5(K,"Added","var(--color-accent-green)")}if(T0(q,U,!0))Y=!0;return Y}function W4($,Q,J){let X=J==="table"?$.querySelector(":scope table > tbody"):$;if(!X)return!1;let Y=!1;X.innerHTML="";for(let Z of Q)if(Z.kind==="removed"){Y=!0;let q=Z.oldBlock.element.cloneNode(!0);q.classList.add(J==="table"?"diff-row-removed":"diff-item-removed"),X.appendChild(q)}else if(Z.kind==="added"){Y=!0;let q=Z.newBlock.element.cloneNode(!0);q.classList.add(J==="table"?"diff-row-added":"diff-item-added"),X.appendChild(q)}else{let q=Z.newBlock.element.cloneNode(!0);if(T0(Z.oldBlock.element,q,!1))Y=!0;X.appendChild(q)}return Y}function M8($,Q){let J=new Map,X=$.element.querySelectorAll("[data-md]"),Y=Q.querySelectorAll("[data-md]");return{newMap:{get(Z){return P8(Q,Z)}}}}function P8($,Q){let J=Q.getAttribute("data-md");if(!J)return null;let X=Q.getAttribute("data-md-label"),Y=Q.getAttribute("data-md-title"),Z=`[data-md="${J}"]`;if(Y)Z+=`[data-md-title="${CSS.escape(Y)}"]`;else if(X)Z+=`[data-md-label="${CSS.escape(X)}"]`;let q=$.querySelectorAll(Z);if(q.length===1)return q[0];let U=(Q.textContent||"").slice(0,100),G=null,K=-1;for(let _ of q){let z=(_.textContent||"").slice(0,100),W=0;for(let H=0;H<Math.min(U.length,z.length);H++)if(U[H]===z[H])W++;if(W>K)K=W,G=_}return G}function y8($,Q,J){let X=$.indexOf(Q);for(let Y=X+1;Y<$.length;Y++){let Z=$[Y];if((Z.kind==="matched"||Z.kind==="added")&&Z.newBlock)return J.get(Z.newBlock.element)||null}return null}function S8($,Q){let J=Q;while(J&&J.parentElement!==$)J=J.parentElement;return J}function N4($,Q){let J=Array.from($.children),X=Array.from(Q.children);if(J.length===0&&X.length===0)return T0($,Q,!1);let Y=J.map((W)=>W.tagName.toLowerCase()),Z=X.map((W)=>W.tagName.toLowerCase()),q=Q0(Y,Z),U=[],G=0,K=0,_=0;while(G<J.length||K<X.length)if(_<q.length&&G<J.length&&K<X.length&&Y[G]===q[_]&&Z[K]===q[_])U.push({kind:"matched",oldChild:J[G],newChild:X[K]}),G++,K++,_++;else if(G<J.length&&(_>=q.length||Y[G]!==q[_]))U.push({kind:"removed",oldChild:J[G]}),G++;else if(K<X.length)U.push({kind:"added",newChild:X[K]}),K++;let z=!1;while(Q.firstChild)Q.removeChild(Q.firstChild);for(let W of U)if(W.kind==="matched"){let H=(W.oldChild.textContent||"").match(/\S+/g)||[],N=(W.newChild.textContent||"").match(/\S+/g)||[],O=Q0(H,N),B=Math.max(H.length,N.length);if((B>0?1-O.length/B:0)>0.5){z=!0;let T=W.oldChild.cloneNode(!0);T.classList.add("diff-block-removed"),Q.appendChild(T),W.newChild.classList.add("diff-block-added"),Q.appendChild(W.newChild)}else{if(T0(W.oldChild,W.newChild,!1))z=!0;Q.appendChild(W.newChild)}}else if(W.kind==="removed"){z=!0;let H=W.oldChild.cloneNode(!0);H.classList.add("diff-block-removed"),Q.appendChild(H)}else z=!0,W.newChild.classList.add("diff-block-added"),Q.appendChild(W.newChild);return z}function z4($,Q){let J=Q?new Set(Array.from($.querySelectorAll("[data-md]"))):new Set,X=[],Y=[],Z=document.createTreeWalker($,NodeFilter.SHOW_TEXT,{acceptNode(U){let G=U.parentElement;if(!G)return NodeFilter.FILTER_REJECT;if(G.closest("svg, .select-none, [data-no-diff]"))return NodeFilter.FILTER_REJECT;if(Q){for(let K of J)if(K.contains(U))return NodeFilter.FILTER_REJECT}return NodeFilter.FILTER_ACCEPT}}),q;while(q=Z.nextNode()){let G=(q.nodeValue||"").match(/\S+|\s+/g);if(!G)continue;let K=0;for(let _ of G)X.push(_),Y.push({text:_,node:q,offset:K}),K+=_.length}return{words:X,map:Y}}function T0($,Q,J){let X=z4($,J),Y=z4(Q,J);if(X.words.length===0&&Y.words.length===0)return!1;let{oldOps:Z,newOps:q}=j5(X.words,Y.words),U=Z.some((B)=>B.type==="removed"),G=q.some((B)=>B.type==="added");if(!U&&!G)return!1;let K=[],_=[];for(let B of Z)if(B.type==="same")K.push(B.index);for(let B of q)if(B.type==="same")_.push(B.index);let z=new Map;for(let B=0;B<K.length&&B<_.length;B++)z.set(K[B],_[B]);let W=[];{let B=[],A=-1;for(let T of Z)if(T.type==="same"){if(B.length>0)W.push({text:B.join(""),anchorNewIdx:A>=0?z.get(A)??null:null}),B=[];A=T.index}else if(T.type==="removed")B.push(X.words[T.index]);if(B.length>0)W.push({text:B.join(""),anchorNewIdx:A>=0?z.get(A)??null:null})}let H=new Map,N=new Map;for(let B of q){if(B.type!=="added")continue;let A=Y.map[B.index];if(!A?.node.parentNode)continue;let T=H.get(A.node);if(!T)T=[],H.set(A.node,T);T.push({start:A.offset,end:A.offset+A.text.length})}for(let B of W)if(B.anchorNewIdx===null){if(Y.map.length>0){let A=Y.map[0].node,T=N.get(A);if(!T)T=[],N.set(A,T);T.push({offset:0,text:B.text})}}else{let A=Y.map[B.anchorNewIdx];if(!A)continue;let T=N.get(A.node);if(!T)T=[],N.set(A.node,T);T.push({offset:A.offset+A.text.length,text:B.text})}let O=new Set([...H.keys(),...N.keys()]);for(let B of O)A8(B,H.get(B)||[],N.get(B)||[]);return!0}function A8($,Q,J){if(!$.parentNode)return;let X=$.nodeValue||"";Q.sort((_,z)=>_.start-z.start);let Y=[];for(let _ of Q){let z=Y[Y.length-1];if(z&&_.start<=z.end)z.end=Math.max(z.end,_.end);else Y.push({..._})}J.sort((_,z)=>_.offset-z.offset);let Z=$.parentNode,q=document.createDocumentFragment(),U=0,G=0,K=0;while(U<=X.length){let _=G<Y.length?Y[G].start:1/0,z=K<J.length?J[K].offset:1/0,W=Math.min(_,z);if(W===1/0){if(U<X.length)q.appendChild(document.createTextNode(X.slice(U)));break}let H=Math.max(W,U);if(H>U)q.appendChild(document.createTextNode(X.slice(U,H))),U=H;while(K<J.length&&J[K].offset<=U){let N=document.createElement("span");N.className="diff-removed",N.textContent=J[K].text,q.appendChild(N),K++}if(G<Y.length&&Y[G].start<=U){let N=Y[G],O=document.createElement("span");O.className="diff-added",O.textContent=X.slice(U,N.end),q.appendChild(O),U=N.end,G++;while(K<J.length&&J[K].offset<=U){let B=document.createElement("span");B.className="diff-removed",B.textContent=J[K].text,q.appendChild(B),K++}}}while(K<J.length){let _=document.createElement("span");_.className="diff-removed",_.textContent=J[K].text,q.appendChild(_),K++}Z.replaceChild(q,$)}function B4($,Q){let J=($.getAttribute("data-md-source")||"").trim(),X=(Q.getAttribute("data-md-source")||"").trim();if(J===X)return!1;let Y=J.split(`
86
+ `),Z=X.split(`
87
+ `),q=Q0(Y,Z),U=[],G=0,K=0,_=0;while(G<Y.length||K<Z.length)if(_<q.length&&G<Y.length&&K<Z.length&&Y[G]===q[_]&&Z[K]===q[_])U.push({type:"same",line:Y[G]}),G++,K++,_++;else if(G<Y.length&&(_>=q.length||Y[G]!==q[_]))U.push({type:"removed",line:Y[G]}),G++;else if(K<Z.length)U.push({type:"added",line:Z[K]}),K++;let z=document.createElement("div");z.className="mt-2 bg-bg-code rounded-md overflow-hidden text-tiny font-mono",z.setAttribute("data-no-diff","true");for(let W of U){let H=document.createElement("div");if(H.className="px-3 py-0.5 whitespace-pre-wrap",W.type==="removed")H.classList.add("diff-removed"),H.textContent="- "+W.line;else if(W.type==="added")H.classList.add("diff-added"),H.textContent="+ "+W.line;else H.textContent=" "+W.line;z.appendChild(H)}return Q.appendChild(z),!0}function V5($,Q,J){let X=document.createElement("span");X.className="diff-block-label",X.textContent=Q,X.style.color=J,X.style.backgroundColor=`color-mix(in srgb, ${J} 12%, transparent)`,$.appendChild(X)}import{jsxDEV as f}from"react/jsx-dev-runtime";function C8($,Q,J){let X=$.find((q)=>q.revision===Q),Y=$.find((q)=>q.revision===J),Z=new Set;for(let q of X?.canvasFiles||[])Z.add(q.filename);for(let q of Y?.canvasFiles||[])Z.add(q.filename);return[...Z].sort()}function O4({initialLeft:$,initialRight:Q,sessionId:J,onExit:X}){let[Y,Z]=N1($),[q,U]=N1(Q),[G,K]=N1("unified"),[_,z]=N1(!0),[W,H]=N1(!1),{revisions:N}=w8(S1),O=x2(()=>C8(N,Y,q),[N,Y,q]),[B,A]=N1(()=>O[0]||"plan.jsx");J0(()=>{if(!O.includes(B))A(O[0]||"plan.jsx")},[O,B]);let T=x2(()=>{return N.find((L)=>L.revision===Y)?.canvasFiles.some((L)=>L.filename===B)??!1},[N,Y,B]),M=x2(()=>{return N.find((L)=>L.revision===q)?.canvasFiles.some((L)=>L.filename===B)??!1},[N,q,B]);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(e0,{value:Y,onChange:Z,accent:"red"},void 0,!1,void 0,this),f("span",{className:"text-text-tertiary text-[13px]",children:"→"},void 0,!1,void 0,this),f(e0,{value:q,onChange:U,accent:"green"},void 0,!1,void 0,this),W&&!_&&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:()=>K("unified"),className:`text-[11px] font-body px-2.5 py-1 rounded transition-colors ${G==="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:()=>K("side-by-side"),className:`text-[11px] font-body px-2.5 py-1 rounded transition-colors ${G==="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),G==="side-by-side"&&f(b8,{},void 0,!1,void 0,this),f("button",{onClick:X,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),O.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:O.map((y)=>{let L=y.replace(/\.jsx$/,""),w=y===B,j=N.find((D)=>D.revision===Y)?.canvasFiles.some((D)=>D.filename===y),k=N.find((D)=>D.revision===q)?.canvasFiles.some((D)=>D.filename===y),m=!j?" (added)":!k?" (removed)":"";return f("button",{onClick:()=>A(y),className:`text-[12px] font-body px-3 py-1 rounded-md transition-colors whitespace-nowrap ${w?"bg-bg-elevated text-text-primary font-medium":"text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated"}`,children:[L,m&&f("span",{className:`ml-1 text-[10px] ${!j?"text-accent-green":"text-accent-red"}`,children:m},void 0,!1,void 0,this)]},y,!0,void 0,this)})},void 0,!1,void 0,this),!T||!M?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:!T?"New file":"Removed file"},void 0,!1,void 0,this),f("div",{className:"text-[13px]",children:[B.replace(/\.jsx$/,"")," ",!T?"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):G==="unified"?f(I8,{sessionId:J,leftRev:Y,rightRev:q,filename:B,onDiffResult:(y,L)=>{H(y),z(L)}},`unified-${Y}-${q}-${B}`,!1,void 0,this):f(j8,{sessionId:J,leftRev:Y,rightRev:q,filename:B,onDiffResult:(y,L)=>{H(y),z(L)}},`sbs-${Y}-${q}-${B}`,!1,void 0,this)]},void 0,!0,void 0,this)}function b8(){let[$,Q]=N1(!0);return J0(()=>{return document.documentElement.dataset.syncScroll=$?"1":"0",()=>{delete document.documentElement.dataset.syncScroll}},[$]),f("label",{className:"flex items-center gap-1.5 cursor-pointer select-none",children:[f("input",{type:"checkbox",checked:$,onChange:(J)=>Q(J.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 I8({sessionId:$,leftRev:Q,rightRev:J,filename:X,onDiffResult:Y}){let Z=c1(null),q=c1(null),U=c1(null),[G,K]=N1(!1),[_,z]=N1(!1),[W,H]=N1(!1),[N,O]=N1(null),[B,A]=N1(!1),{annotations:T}=v1(),M=T.filter((L)=>!L.filePath&&(!L.canvasFile||L.canvasFile===X)),{popovers:y}=n1({containerRef:U,restoreKey:W,restoreAnnotations:M,extractContext:(L)=>o1(L,U.current)});return J0(()=>{if(W||N)return;let L=setTimeout(()=>{console.warn("[unified-diff] still loading after 10s",{leftReady:G,rightReady:_,oldRef:!!Z.current,newRef:!!q.current}),A(!0)},1e4);return()=>clearTimeout(L)},[W,N,G,_]),J0(()=>{if(!G||!_||W)return;if(!Z.current||!q.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!Z.current||!q.current||!U.current){console.warn("[unified-diff] refs lost between rAF frames",{old:!!Z.current,new:!!q.current,unified:!!U.current});return}try{let L=C0(Z.current),w=C0(q.current),j=Q2(L,w),{fragment:k,hasChanges:m}=E2(j);U.current.innerHTML="",U.current.appendChild(k),H(!0),Y(!0,m)}catch(L){console.error("[unified-diff] diff computation failed",L),O(L instanceof Error?L.message:String(L))}})})},[G,_,W]),f("div",{className:"flex-1 min-h-0 overflow-y-auto",children:[!W&&!N&&f("div",{style:{position:"absolute",left:-9999,visibility:"hidden",pointerEvents:"none",width:720},children:[f(d1,{ref:Z,sessionId:$,revision:Q,filename:X,onReady:()=>K(!0),onError:(L)=>O(`Rev ${Q}: ${L}`)},void 0,!1,void 0,this),f(d1,{ref:q,sessionId:$,revision:J,filename:X,onReady:()=>z(!0),onError:(L)=>O(`Rev ${J}: ${L}`)},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&&!N&&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),B&&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),N&&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:N},void 0,!1,void 0,this)]},void 0,!0,void 0,this),f("div",{ref:U},void 0,!1,void 0,this)]},void 0,!0,void 0,this),y]},void 0,!0,void 0,this)}function j8({sessionId:$,leftRev:Q,rightRev:J,filename:X,onDiffResult:Y}){let Z=c1(null),q=c1(null),[U,G]=N1(!1),[K,_]=N1(!1),[z,W]=N1(!1),H=c1(null),N=c1(null),O=c1(null),B=c1(!1),A=F4(()=>G(!0),[]),T=F4(()=>_(!0),[]),{annotations:M}=v1(),y=M.filter((w)=>!w.filePath&&(!w.canvasFile||w.canvasFile===X)),{popovers:L}=n1({containerRef:H,restoreKey:z,restoreAnnotations:y,extractContext:(w)=>o1(w,H.current)});return J0(()=>{if(!U||!K||z)return;if(!Z.current||!q.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!Z.current||!q.current)return;let w=m2(Z.current,q.current);W(!0),Y(!0,w)})})},[U,K,z]),J0(()=>{let w=N.current,j=O.current;if(!w||!j)return;let k=(v,u)=>{if(document.documentElement.dataset.syncScroll==="0")return;if(B.current)return;B.current=!0;let d=v.scrollHeight-v.clientHeight,K1=u.scrollHeight-u.clientHeight;if(d>0&&K1>0)u.scrollTop=v.scrollTop/d*K1;requestAnimationFrame(()=>{B.current=!1})},m=()=>k(w,j),D=()=>k(j,w);return w.addEventListener("scroll",m),j.addEventListener("scroll",D),()=>{w.removeEventListener("scroll",m),j.removeEventListener("scroll",D)}},[]),f("div",{ref:H,className:"flex flex-1 min-h-0",children:[f("div",{ref:N,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(d1,{ref:Z,sessionId:$,revision:Q,filename:X,onReady:A},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),f("div",{ref:O,className:"w-1/2 overflow-y-auto",children:f("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:f(d1,{ref:q,sessionId:$,revision:J,filename:X,onReady:T},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),L]},void 0,!0,void 0,this)}var d1=T4.memo(T4.forwardRef(({sessionId:$,revision:Q,filename:J,onReady:X,onError:Y},Z)=>{let[q,U]=N1(null),[G,K]=N1(null),[_,z]=N1(!0);J0(()=>{z(!0),K(null);let H=J.replace(/\.jsx$/,".js");import(`/api/session/${$}/canvas/${encodeURIComponent(H)}?rev=${Q}&t=${Date.now()}`).then((N)=>{if(!N.default){K("Module has no default export"),z(!1),Y?.("Module has no default export");return}U(()=>N.default),z(!1)}).catch((N)=>{K(N.message),z(!1),Y?.(N.message)})},[$,Q,J]),J0(()=>{if(!q)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{X()})})},[q]);let W=x2(()=>q?f(q,{},void 0,!1,void 0,this):null,[q]);if(_)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(G)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:G},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(!q)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:Z,children:W},void 0,!1,void 0,this)}));import{useState as l1,useContext as k5,useMemo as V8,useRef as J2,useEffect as M4,useCallback as L4}from"react";import{SessionContext as k8}from"#canvas/runtime";import{jsxDEV as h}from"react/jsx-dev-runtime";function R5($,Q){if(!$)return[];return $.canvasFiles.map((J)=>{if(!J.diffStats)return{filename:J.filename,status:"new"};if(J.diffStats.added===0&&J.diffStats.removed===0)return{filename:J.filename,status:"unchanged",diffStats:J.diffStats};return{filename:J.filename,status:"changed",diffStats:J.diffStats}})}function P4($){return $.filter((Q)=>Q.status!=="unchanged").map((Q)=>Q.filename)}function y4({revision:$,responseBanner:Q}){let{setActiveView:J}=k5(E1),{revisions:X}=k5(S1),Y=X.find((K)=>K.revision===$),Z=X.find((K)=>K.revision===$-1),q=V8(()=>R5(Y,Z),[Y,Z]),U=q.filter((K)=>K.status!=="unchanged"),G=q.filter((K)=>K.status==="unchanged");return h("div",{className:"max-w-[720px] mx-auto px-6 pt-12 pb-32",children:[Q,U.map((K)=>h(D8,{change:K,revision:$,previousRevision:Z?.revision,onOpenTab:()=>J({type:"canvas",filename:K.filename})},K.filename,!1,void 0,this)),G.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),G.map((K)=>h(f8,{change:K,revision:$,onOpenTab:()=>J({type:"canvas",filename:K.filename})},K.filename,!1,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function R8({mode:$,onChange:Q,showDiff:J}){if(!J)return null;return h("div",{className:"flex items-center bg-bg-elevated rounded-md p-0.5",children:["rendered","unified","side-by-side"].map((X)=>h("button",{onClick:()=>Q(X),className:`text-[10px] font-body px-2 py-0.5 rounded transition-colors ${$===X?"bg-bg-surface text-text-primary font-medium shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:X==="rendered"?"Full":X==="unified"?"Unified":"Split"},X,!1,void 0,this))},void 0,!1,void 0,this)}function D8({change:$,revision:Q,previousRevision:J,onOpenTab:X}){let Y=$.filename.replace(/\.jsx$/,""),Z=$.status==="new",q=$.diffStats,U=$.status==="changed"&&J!=null,[G,K]=l1("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 ${Z?"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:Z?"new":"modified"},void 0,!1,void 0,this),h("span",{className:"text-[14px] font-body font-medium text-text-primary",children:Y},void 0,!1,void 0,this),q&&(q.added>0||q.removed>0)&&h("span",{className:"text-[11px] font-mono text-text-tertiary",children:[h("span",{className:"text-accent-green",children:["+",q.added]},void 0,!0,void 0,this)," ",h("span",{className:"text-accent-red",children:["-",q.removed]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),h(R8,{mode:G,onChange:K,showDiff:U},void 0,!1,void 0,this),h("button",{onClick:X,className:`${U?"":"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),G==="rendered"?h("div",{"data-canvas-file":$.filename,children:h(A0,{revision:Q,filename:$.filename},void 0,!1,void 0,this)},void 0,!1,void 0,this):U&&J!=null?h(m8,{filename:$.filename,leftRev:J,rightRev:Q,mode:G},`${G}-${Q}-${J}`,!1,void 0,this):null]},void 0,!0,void 0,this)}function m8({filename:$,leftRev:Q,rightRev:J,mode:X}){let Y=k5(k8);if(X==="unified")return h(E8,{sessionId:Y,filename:$,leftRev:Q,rightRev:J},void 0,!1,void 0,this);return h(x8,{sessionId:Y,filename:$,leftRev:Q,rightRev:J},void 0,!1,void 0,this)}function E8({sessionId:$,filename:Q,leftRev:J,rightRev:X}){let Y=J2(null),Z=J2(null),q=J2(null),[U,G]=l1(!1),[K,_]=l1(!1),[z,W]=l1(!1),[H,N]=l1(null);return M4(()=>{if(!U||!K||z)return;if(!Y.current||!Z.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!Y.current||!Z.current||!q.current)return;try{let O=C0(Y.current),B=C0(Z.current),A=Q2(O,B),{fragment:T}=E2(A);q.current.innerHTML="",q.current.appendChild(T),W(!0)}catch(O){N(O instanceof Error?O.message:String(O))}})})},[U,K,z]),h("div",{children:[!z&&!H&&h("div",{style:{position:"absolute",left:-9999,visibility:"hidden",pointerEvents:"none",width:720},children:[h(d1,{ref:Y,sessionId:$,revision:J,filename:Q,onReady:()=>G(!0),onError:(O)=>N(O)},void 0,!1,void 0,this),h(d1,{ref:Z,sessionId:$,revision:X,filename:Q,onReady:()=>_(!0),onError:(O)=>N(O)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!z&&!H&&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),H&&h("div",{className:"text-accent-red text-[13px] font-body p-3 bg-accent-red-muted rounded-lg",children:H},void 0,!1,void 0,this),h("div",{ref:q},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function x8({sessionId:$,filename:Q,leftRev:J,rightRev:X}){let Y=J2(null),Z=J2(null),[q,U]=l1(!1),[G,K]=l1(!1),[_,z]=l1(!1),W=L4(()=>U(!0),[]),H=L4(()=>K(!0),[]);return M4(()=>{if(!q||!G||_)return;if(!Y.current||!Z.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!Y.current||!Z.current)return;m2(Y.current,Z.current),z(!0)})})},[q,G,_]),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 ",J]},void 0,!0,void 0,this),h("div",{className:"px-6 py-4 max-w-[600px] mx-auto",children:h(d1,{ref:Y,sessionId:$,revision:J,filename:Q,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 ",X]},void 0,!0,void 0,this),h("div",{className:"px-6 py-4 max-w-[600px] mx-auto",children:h(d1,{ref:Z,sessionId:$,revision:X,filename:Q,onReady:H},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 f8({change:$,revision:Q,onOpenTab:J}){let[X,Y]=l1(!1),Z=$.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:()=>Y(!X),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 ${X?"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:Z},void 0,!1,void 0,this),h("button",{onClick:J,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),X&&h("div",{className:"ml-5 mt-1 mb-3","data-canvas-file":$.filename,children:h(A0,{revision:Q,filename:$.filename},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{useState as f2,useEffect as v8,useCallback as D5}from"react";import{jsxDEV as s}from"react/jsx-dev-runtime";function S4({sessionId:$,revision:Q,open:J,shareEnabled:X,existingShares:Y,onClose:Z,onShareCreated:q,onShareRevoked:U}){let[G,K]=f2(!1),[_,z]=f2(!1),[W,H]=f2(null),[N,O]=f2(!1),B=Y.find((y)=>y.revision===Q);v8(()=>{if(!J)K(!1),z(!1),H(null),O(!1)},[J]);let A=D5(async()=>{K(!0),H(null);try{let y=await fetch(`/api/session/${$}/revision/${Q}/share`,{method:"POST"}),L=await y.json();if(!y.ok||!L.ok)throw Error(L.error||`HTTP ${y.status}`);q(L.share)}catch(y){H(y.message||String(y))}finally{K(!1)}},[$,Q,q]),T=D5(async(y)=>{if(!window.confirm("Revoke this share link? Reviewers will no longer be able to view or comment."))return;z(!0),H(null);try{let L=await fetch(`/api/session/${$}/shares/${y}/revoke`,{method:"POST"}),w=await L.json();if(!L.ok||!w.ok)throw Error(w.error||`HTTP ${L.status}`);U(y)}catch(L){H(L.message||String(L))}finally{z(!1)}},[$,U]),M=D5((y)=>{navigator.clipboard.writeText(y).then(()=>{O(!0),setTimeout(()=>O(!1),1500)})},[]);if(!J)return null;return s("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:Z,children:s("div",{className:"bg-bg-surface border border-border-medium rounded-lg shadow-xl w-full max-w-md mx-4 p-5",onClick:(y)=>y.stopPropagation(),children:[s("div",{className:"flex items-center justify-between mb-3",children:[s("h2",{className:"text-sm font-medium text-text-primary font-body",children:"Share this revision"},void 0,!1,void 0,this),s("button",{onClick:Z,className:"w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",children:s("span",{className:"text-xs",children:"✕"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!X?s("div",{className:"text-[13px] text-text-secondary font-body space-y-2",children:[s("p",{children:"Canvas sharing is not configured."},void 0,!1,void 0,this),s("p",{className:"text-text-tertiary",children:["Set ",s("code",{className:"px-1 py-0.5 rounded bg-bg-elevated text-text-primary text-[11px]",children:"CANVAS_SHARE_ENDPOINT"},void 0,!1,void 0,this)," to the URL of a deployed"," ",s("code",{className:"px-1 py-0.5 rounded bg-bg-elevated text-text-primary text-[11px]",children:"canvas-share"},void 0,!1,void 0,this)," worker and restart the daemon."]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):B?s("div",{className:"space-y-3",children:[s("p",{className:"text-[13px] text-text-secondary font-body",children:"This revision is shared:"},void 0,!1,void 0,this),s("div",{className:"flex gap-2",children:[s("input",{type:"text",readOnly:!0,value:B.url,className:"flex-1 px-2 py-1.5 text-[12px] font-mono bg-bg-input border border-border-medium rounded text-text-primary",onFocus:(y)=>y.currentTarget.select()},void 0,!1,void 0,this),s("button",{onClick:()=>M(B.url),className:"px-3 py-1.5 text-[12px] font-body font-medium rounded bg-accent-blue text-white hover:opacity-90 transition-opacity whitespace-nowrap",children:N?"Copied!":"Copy"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),B.expiresAt&&s("p",{className:"text-[11px] text-text-tertiary font-body",children:["Expires ",new Date(B.expiresAt).toLocaleDateString(),"."]},void 0,!0,void 0,this),B.encryptionKey&&s("p",{className:"text-[11px] text-accent-green font-body flex items-center gap-1.5",children:[s("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[s("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"},void 0,!1,void 0,this),s("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),"End-to-end encrypted — the key is part of the link and never leaves your browser."]},void 0,!0,void 0,this),s("p",{className:"text-[11px] text-text-tertiary font-body",children:"Anyone with this link can view and leave feedback. Reviewer feedback will appear in your annotation sidebar within seconds."},void 0,!1,void 0,this),s("div",{className:"flex items-center justify-between pt-1",children:[s("button",{onClick:A,disabled:G||_,className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body underline disabled:opacity-50",children:G?"Creating...":"Create a new link"},void 0,!1,void 0,this),B.ownerToken&&s("button",{onClick:()=>T(B.shareId),disabled:G||_,className:"text-[11px] text-accent-red hover:opacity-80 font-body underline disabled:opacity-50",children:_?"Revoking...":"Revoke link"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):s("div",{className:"space-y-3",children:[s("p",{className:"text-[13px] text-text-secondary font-body",children:"Create a public link to this revision. Anyone with the link can view the canvas and leave feedback. Reviewer feedback will sync back here automatically."},void 0,!1,void 0,this),s("button",{onClick:A,disabled:G,className:"w-full px-3 py-2 text-[13px] font-body font-medium rounded bg-accent-blue text-white hover:opacity-90 transition-opacity disabled:opacity-50",children:G?"Creating share link...":"Create share link"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),W&&s("div",{className:"mt-3 px-3 py-2 rounded bg-accent-red/10 border border-accent-red/20 text-[12px] text-accent-red font-body",children:W},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function A4({onClick:$,title:Q="Share this revision",hasShare:J}){return s("button",{onClick:$,className:`group p-1.5 transition-colors ${J?"text-accent-blue hover:opacity-80":"text-text-tertiary hover:text-text-secondary"}`,title:Q,children:s("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[s("circle",{cx:"18",cy:"5",r:"3"},void 0,!1,void 0,this),s("circle",{cx:"6",cy:"12",r:"3"},void 0,!1,void 0,this),s("circle",{cx:"18",cy:"19",r:"3"},void 0,!1,void 0,this),s("line",{x1:"8.59",y1:"13.51",x2:"15.42",y2:"17.49"},void 0,!1,void 0,this),s("line",{x1:"15.41",y1:"6.51",x2:"8.59",y2:"10.49"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}import{useState as u8,useEffect as g8,useRef as h8}from"react";import{jsxDEV as V1}from"react/jsx-dev-runtime";function w4({open:$,onClose:Q,onSubmit:J}){let[X,Y]=u8(""),Z=h8(null);if(g8(()=>{if($)Y(""),setTimeout(()=>Z.current?.focus(),50)},[$]),!$)return null;let q=X.trim(),U=q.length>=1&&q.length<=80,G=()=>{if(!U)return;J(q)};return V1("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:Q,children:V1("div",{className:"bg-bg-surface border border-border-medium rounded-lg shadow-xl w-full max-w-md mx-4 p-5",onClick:(K)=>K.stopPropagation(),children:[V1("div",{className:"flex items-center justify-between mb-3",children:[V1("h2",{className:"text-sm font-medium text-text-primary font-body",children:"Your name"},void 0,!1,void 0,this),V1("button",{onClick:Q,className:"w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",children:V1("span",{className:"text-xs",children:"✕"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),V1("p",{className:"text-[13px] text-text-secondary font-body mb-3 leading-relaxed",children:"Before you leave feedback, please enter a name so the canvas author knows who reviewed it. This is stored locally in your browser."},void 0,!1,void 0,this),V1("input",{ref:Z,type:"text",value:X,onChange:(K)=>Y(K.target.value),onKeyDown:(K)=>{if(K.key==="Enter")G()},maxLength:80,placeholder:"e.g. Alice",className:"w-full px-3 py-2 text-[13px] font-body bg-bg-input border border-border-medium rounded text-text-primary placeholder:text-text-disabled focus:outline-none focus:border-accent-blue"},void 0,!1,void 0,this),V1("div",{className:"flex justify-end gap-2 mt-4",children:[V1("button",{onClick:Q,className:"px-3 py-1.5 text-[12px] font-body font-medium rounded text-text-secondary hover:text-text-primary hover:bg-bg-elevated transition-colors",children:"Cancel"},void 0,!1,void 0,this),V1("button",{onClick:G,disabled:!U,className:"px-3 py-1.5 text-[12px] font-body font-medium rounded bg-accent-blue text-white hover:opacity-90 transition-opacity disabled:opacity-50",children:"Submit feedback"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}import{jsxDEV as F,Fragment as Y2}from"react/jsx-dev-runtime";function b4($){let Q=[];for(let J of $)for(let X of J.annotations)Q.push({...X,source:"remote",author:J.author});return Q}function l8($){if($==="auto")return window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light";return $}function I4($){document.documentElement.dataset.theme=l8($)}function R4(){let[$,Q]=Y1(()=>{let Y=localStorage.getItem("canvas-theme");if(Y==="light"||Y==="dark"||Y==="auto")return Y;return"auto"});return k1(()=>{if(I4($),$!=="auto")return;let Y=window.matchMedia("(prefers-color-scheme: dark)"),Z=()=>I4("auto");return Y.addEventListener("change",Z),()=>Y.removeEventListener("change",Z)},[$]),F("button",{onClick:()=>{let Y=$==="auto"?"light":$==="light"?"dark":"auto";localStorage.setItem("canvas-theme",Y),Q(Y)},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)"}[$],children:$==="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):$==="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 D4(){let{currentRevision:$,selectedRevision:Q,revisions:J,setSelectedRevision:X,setCompareRevision:Y}=Y0.useContext(S1);if(J.length<=1){let U=J[0]?.label||`Round ${$}`;return F("span",{className:"text-[11px] text-text-tertiary font-body",children:U},void 0,!1,void 0,this)}return F("div",{className:"flex flex-col gap-1",children:[F(e0,{value:Q,onChange:X,accent:Q===$?"default":"amber"},void 0,!1,void 0,this),F("button",{onClick:()=>{let q;if(Q===$)q=[...J].reverse().find((G)=>G.revision<$)?.revision??Math.max(1,$-1);else q=Q;Y({left:q,right:$})},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 r8(){let $=$1.isShared?$1.shareId:$1.sessionId,Q=$1.isShared,[J,X]=Y1(1),[Y,Z]=Y1(1),[q,U]=Y1([]),[G,K]=Y1(null),[_,z]=Y1(!1),[W,H]=Y1(!1),[N,O]=Y1(!1),[B,A]=Y1([]),[T,M]=Y1({type:"overview"}),[y,L]=Y1([]),w=g1(null),j=g1([]),k=g1(new Set),[m,D]=Y1(),[v,u]=Y1(!1),[d,K1]=Y1(!1),[R,g]=Y1(!1),[p,t]=Y1(!1),[l,o]=Y1([]),[q1,X1]=Y1(!1),[z1,M1]=Y1(new Map),[C,E]=Y1(!1),[b,P]=Y1(null),[S,V]=Y1(null),i=b0((I)=>{if(Q)return;let r=`${I.revision}\x00${I.filename}\x00${I.message}`;if(k.current.has(r))return;k.current.add(r);let n=JSON.stringify({type:"render-error",error:I});if(w.current?.readyState===WebSocket.OPEN)w.current.send(n);else j.current.push(I)},[Q]);k1(()=>{if(!S)return;let I=setTimeout(()=>V(null),4000);return()=>clearTimeout(I)},[S]),k1(()=>{let I=["Agent Canvas"];if(m){let r=m.replace(/\/+$/,"").split("/");I.push(r[r.length-1]||$)}else if($)I.push($);if(T.type==="file")I.push(T.path.split("/").pop()||T.path);else if(T.type==="overview")I.push("Overview");else if(T.type==="canvas"&&B.length>1&&T.filename)I.push(T.filename.replace(/\.jsx$/,""));else if(G)I.push("Compare");document.title=I.join(" — ")},[$,m,T,G]);let Q1=g1(new Map),U1=q.find((I)=>I.revision===Y),P1=Y!==J||!!U1?.hasFeedback||W,m5=Y===J&&(!!U1?.hasFeedback||W)?"next":"current",E5=b0((I)=>{let r=T.type==="overview"?"overview":T.type==="canvas"?`canvas:${T.filename}`:`file:${T.path}`;if(Q1.current.set(r,window.scrollY),M(I),I.type==="file")L((n)=>n.includes(I.path)?n:[...n,I.path])},[T]),m4=b0((I)=>{Q1.current.delete(`file:${I}`),L((r)=>r.filter((n)=>n!==I)),M((r)=>{if(r.type==="file"&&r.path===I)return B.length>1?{type:"overview"}:{type:"canvas",filename:B[0]||""};return r})},[B]);p8(()=>{let I=T.type==="overview"?"overview":T.type==="canvas"?`canvas:${T.filename}`:`file:${T.path}`;window.scrollTo(0,Q1.current.get(I)||0)},[T]),k1(()=>{if(!$)return;p3().then((I)=>{if(I.currentRevision){let r=I.revisions||[];for(let n of r)if(n.hasFeedback)U0(localStorage,$,n.revision);_2(localStorage,$,I.currentRevision,r),X(I.currentRevision),Z(I.currentRevision),U(r)}if(I.canvasFiles){let r=I.canvasFiles.sort();A(r),M((n)=>{if(n.type==="overview")return r.length>1?n:{type:"canvas",filename:r[0]||""};if(n.type==="canvas"&&(!n.filename||!r.includes(n.filename)))return{type:"canvas",filename:r[0]||""};return n})}if(I.projectRoot)D(I.projectRoot);if(Array.isArray(I.shares))o(I.shares);X1(!!I.shareEnabled)}).catch(()=>{})},[$]),k1(()=>{if(!$||!Y||Q)return;fetch(`/api/session/${$}/revision/${Y}/remote-feedback`).then((I)=>I.json()).then((I)=>{if(!Array.isArray(I.entries))return;let r=b4(I.entries);M1((n)=>{let A1=new Map(n);return A1.set(Y,r),A1})}).catch(()=>{})},[$,Y,Q]),k1(()=>{if(!$)return;if(!r3){z(!0);return}let I=null,r=()=>{let n=window.location.protocol==="https:"?"wss:":"ws:",A1=new WebSocket(`${n}//${window.location.host}/ws/session/${$}`);w.current=A1,A1.onopen=()=>{z(!0);for(let X2 of j.current)A1.send(JSON.stringify({type:"render-error",error:X2}));j.current=[]},A1.onclose=()=>{z(!1),I=setTimeout(r,2000)},A1.onmessage=(X2)=>{try{let _1=JSON.parse(X2.data);if(_1.type==="plan-updated"){let w1=Array.isArray(_1.revisions)?_1.revisions:[];if(_2(localStorage,$,_1.currentRevision,w1),X(_1.currentRevision),Z(_1.currentRevision),K(null),w1.length>0){U(w1);let r1=w1.find((X0)=>X0.revision===_1.currentRevision);if(r1?.canvasFiles){let X0=r1.canvasFiles.map((j0)=>j0.filename).sort();A(X0);let u2=w1.find((j0)=>j0.revision===_1.currentRevision-1),I0=R5(r1,u2),F0=P4(I0);if(F0.length===1)M({type:"canvas",filename:F0[0]});else if(F0.length>1||X0.length>1)M({type:"overview"});else M({type:"canvas",filename:X0[0]||""})}}}if(_1.type==="revision-updated"){if(Array.isArray(_1.revisions)){let w1=_1.revisions;for(let r1 of w1)if(r1.hasFeedback)U0(localStorage,$,r1.revision);U(w1)}}if(_1.type==="watcher-status")O(!!_1.watching);if(_1.type==="remote-feedback"){let w1=_1.revision,r1=_1.entries||[],X0=b4(r1);M1((u2)=>{let I0=new Map(u2),F0=I0.get(w1)||[],j0=new Set(F0.map((g2)=>g2.id)),E4=[...F0,...X0.filter((g2)=>!j0.has(g2.id))];return I0.set(w1,E4),I0})}}catch{}}};return r(),()=>{if(I)clearTimeout(I);w.current?.close()}},[$]);let v2=b0(async(I,r)=>{try{let n=localStorage.getItem(`canvas:${$}:rev:${Y}`),A1=[];if(n)try{A1=(JSON.parse(n).annotations||[]).filter((_1)=>_1.source!=="remote")}catch{}await l3({author:r,revision:Y,annotations:A1,generalNote:I}),U0(localStorage,$,Y),H(!0),V({kind:"success",message:"Feedback submitted. The canvas author will see it shortly."})}catch(n){V({kind:"error",message:`Failed to submit feedback: ${n.message||n}`})}},[$,Y]),x5=b0(async(I)=>{if(Q){let r=C5();if(!r){P(I),E(!0);return}await v2(I,r);return}if(w.current?.readyState===WebSocket.OPEN)w.current.send(JSON.stringify({type:"submit",feedback:I}))},[Q,v2]);if(!$)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(S2.Provider,{value:i3,children:F(k4.Provider,{value:$,children:F(s0.Provider,{value:i,children:F(S1.Provider,{value:{currentRevision:J,selectedRevision:Y,revisions:q,setSelectedRevision:Z,isReadOnly:P1,compareRevision:G,setCompareRevision:K,agentWatching:N},children:F(_5,{sessionId:$,revision:Y,isReadOnly:P1,draftPhase:m5,remoteAnnotations:z1.get(Y),canvasFiles:B,children:F(E1.Provider,{value:{activeView:T,setActiveView:E5,openFiles:y,closeFile:m4,canvasFiles:B},children:F(d8.Provider,{value:{setActiveView:E5},children:F("div",{className:"min-h-screen bg-bg-base",children:[F(i8,{sessionId:$,projectRoot:m,connected:_,onMobileSidebar:()=>u(!v),collapsed:d,onToggle:()=>K1((I)=>!I)},void 0,!1,void 0,this),F(o8,{collapsed:R,onToggle:()=>g((I)=>!I),children:F(w2,{onSubmit:x5},void 0,!1,void 0,this)},void 0,!1,void 0,this),G!==null?F("div",{className:`${d?"lg:ml-0":"lg:ml-60"} ${R?"lg:mr-0":"lg:mr-[var(--sidebar-width,320px)]"} transition-[margin] duration-200`,children:F(O4,{initialLeft:G.left,initialRight:G.right,sessionId:$,onExit:()=>K(null)},void 0,!1,void 0,this)},void 0,!1,void 0,this):F("div",{className:`relative ${d?"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:[!Q&&F(I5,{currentSessionId:$,projectRoot:m},void 0,!1,void 0,this),Q&&F("span",{className:"text-[11px] text-text-tertiary font-body",children:"Shared canvas"},void 0,!1,void 0,this),!Q&&F("span",{className:`w-1.5 h-1.5 rounded-full ${_?"bg-accent-green":"bg-accent-red"}`},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("div",{className:"flex items-center gap-1",children:[F(D4,{},void 0,!1,void 0,this),F("button",{onClick:()=>u(!v),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(R4,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),F(a8,{},void 0,!1,void 0,this),T.type==="overview"&&F(y4,{revision:Y,responseBanner:U1?.response?F(j4,{markdown:U1.response},void 0,!1,void 0,this):void 0},void 0,!1,void 0,this),T.type==="canvas"&&B.includes(T.filename)&&F("div",{className:"relative max-w-[720px] mx-auto px-6 pt-12 pb-32",children:[q1&&F("div",{className:"absolute top-3 right-12 z-10",children:F(A4,{onClick:()=>t(!0),hasShare:l.some((I)=>I.revision===Y),title:l.some((I)=>I.revision===Y)?"Manage share link":"Share this revision"},void 0,!1,void 0,this)},void 0,!1,void 0,this),F("button",{onClick:()=>{let I=document.querySelector(`[data-canvas-file="${T.filename}"] .plan-content`);if(!I)return;let r=X4(I);navigator.clipboard.writeText(r).then(()=>{let n=document.getElementById("export-md-btn");if(n)n.setAttribute("data-copied","true"),setTimeout(()=>{n.removeAttribute("data-copied")},1500)})},id:"export-md-btn",className:"group absolute top-3 right-6 p-1.5 text-text-tertiary hover:text-text-secondary transition-colors z-10",title:"Copy as Markdown",children:[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),B.length<=1&&U1?.response&&F(j4,{markdown:U1.response},void 0,!1,void 0,this),F("div",{"data-canvas-file":T.filename,children:F(A0,{revision:Y,filename:T.filename},T.filename,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),y.map((I)=>F("div",{style:{display:T.type==="file"&&T.path===I?void 0:"none"},children:F($4,{path:I},void 0,!1,void 0,this)},I,!1,void 0,this))]},void 0,!0,void 0,this),v&&F("div",{className:"lg:hidden fixed inset-0 z-40 flex",children:[F("div",{className:"flex-1",onClick:()=>u(!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:()=>u(!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(w2,{onSubmit:x5},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(S4,{sessionId:$,revision:Y,open:p,shareEnabled:q1,existingShares:l,onClose:()=>t(!1),onShareCreated:(I)=>{o((r)=>[...r.filter((n)=>n.shareId!==I.shareId),I]),V({kind:"success",message:"Share link created. Copy and send it to reviewers."})},onShareRevoked:(I)=>{o((r)=>r.filter((n)=>n.shareId!==I)),V({kind:"success",message:"Share link revoked."})}},void 0,!1,void 0,this),F(w4,{open:C,onClose:()=>{E(!1),P(null)},onSubmit:async(I)=>{let r=d3(I);if(E(!1),b!==null)await v2(b,r),P(null)}},void 0,!1,void 0,this),S&&F("div",{className:`fixed bottom-4 left-1/2 -translate-x-1/2 z-50 px-4 py-2.5 rounded-lg shadow-lg text-[13px] font-body font-medium flex items-center gap-2 ${S.kind==="error"?"bg-accent-red text-white":"bg-accent-green text-white"}`,children:[S.message,F("button",{onClick:()=>V(null),className:"ml-2 opacity-70 hover:opacity-100",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},`${$}:${Y}:${m5}`,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function i8({sessionId:$,projectRoot:Q,connected:J,onMobileSidebar:X,collapsed:Y,onToggle:Z}){let q=$1.isShared;return F(Y2,{children:[Y&&F("button",{onClick:Z,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 ${Y?"-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),q?F("span",{className:"text-[12px] font-body text-text-secondary truncate flex-1",children:"Shared canvas"},void 0,!1,void 0,this):F(Y2,{children:[F(I5,{currentSessionId:$,projectRoot:Q},void 0,!1,void 0,this),F("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${J?"bg-accent-green":"bg-accent-red"}`},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("button",{onClick:Z,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(D4,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("div",{className:"flex-1 flex flex-col overflow-hidden",children:F(s3,{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(R4,{},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 o8({children:$,collapsed:Q,onToggle:J}){let[X,Y]=Y1(()=>{let _=localStorage.getItem("canvas-sidebar-width");return _?parseInt(_,10):320}),Z=g1(!1),q=g1(0),U=g1(0),G=g1(X);G.current=X;let K=b0((_)=>{_.preventDefault(),Z.current=!0,q.current=_.clientX,U.current=G.current;let z=(H)=>{if(!Z.current)return;let N=q.current-H.clientX,O=Math.max(240,Math.min(600,U.current+N));Y(O),G.current=O},W=()=>{Z.current=!1,localStorage.setItem("canvas-sidebar-width",String(G.current)),document.removeEventListener("mousemove",z),document.removeEventListener("mouseup",W),document.body.style.cursor="",document.body.style.userSelect=""};document.addEventListener("mousemove",z),document.addEventListener("mouseup",W),document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[]);return k1(()=>{return document.documentElement.style.setProperty("--sidebar-width",`${X}px`),()=>{document.documentElement.style.removeProperty("--sidebar-width")}},[X]),F(Y2,{children:[Q&&F("button",{onClick:J,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 ${Q?"translate-x-full":""}`,style:{width:X},children:[F("div",{onMouseDown:K,className:"absolute left-0 top-0 bottom-0 w-1 cursor-col-resize hover:bg-accent-blue/30 transition-colors z-20",style:{marginLeft:"-2px"}},void 0,!1,void 0,this),Y0.Children.map($,(_)=>Y0.isValidElement(_)?Y0.cloneElement(_,{collapseButton:F("button",{onClick:J,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)}):_)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function j4({markdown:$}){let[Q,J]=Y1(!1),X=C4(()=>a.parse($,{async:!1}),[$]),Y=g1(null),{annotations:Z,addAnnotationWithId:q,removeAnnotation:U,updateAnnotation:G,addAnnotationImage:K,removeAnnotationImage:_,activeAnnotationId:z,setActiveAnnotationId:W}=v1(),[H,N]=Y1(null),[O,B]=Y1(null),A=C4(()=>Z.filter((w)=>w.filePath===I1),[Z]),[T,M]=Y1($);if($!==T)M($),J(!1);k1(()=>{if(!Y.current||A.length===0)return;let w=setTimeout(()=>{if(Y.current)f0(Y.current,A)},50);return()=>clearTimeout(w)},[X,A.length]);let y=g1(null);if(k1(()=>{E0(z,y.current),y.current=z},[z]),k1(()=>{let w=Y.current;if(!w)return;let j=(D)=>{let v=D.target.closest("[data-annotation-id]");if(!v)return;D.stopPropagation();let u=v.getAttribute("data-annotation-id");if(u===z)B({anchorEl:v,annId:u});else W(u)},k=(D)=>{let v=D.target.closest("[data-annotation-id]");if(v)W(v.getAttribute("data-annotation-id"))},m=(D)=>{let v=D.target.closest("[data-annotation-id]"),u=D.relatedTarget?.closest?.("[data-annotation-id]");if(v&&!u)W(null)};return w.addEventListener("click",j),w.addEventListener("mouseover",k),w.addEventListener("mouseout",m),()=>{w.removeEventListener("click",j),w.removeEventListener("mouseover",k),w.removeEventListener("mouseout",m)}},[X,z]),k1(()=>{let w=()=>{let j=window.getSelection();if(!j||j.isCollapsed||!j.toString().trim())return;if(!Y.current)return;let k=j.getRangeAt(0);if(!Y.current.contains(k.startContainer))return;if(k.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let m=j.toString().trim();if(m.length<2)return;let D=k.cloneRange(),v=o1(k,Y.current),u=`__pending_${Date.now()}`;try{i1(D,u)}catch{}window.getSelection()?.removeAllRanges();let d=document.querySelectorAll(`[data-annotation-id="${u}"]`),K1=d[d.length-1];if(!K1)return;N({anchorEl:K1,tempId:u,snippet:m,ctx:v})};return document.addEventListener("mouseup",w),()=>document.removeEventListener("mouseup",w)},[]),Q)return null;let L=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:()=>J(!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:Y,className:"prose-canvas text-sm",dangerouslySetInnerHTML:{__html:X}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),H&&F(x1,{anchorEl:H.anchorEl,scrollContainer:L,snippet:H.snippet,truncateAt:80,onAdd:(w,j)=>{let k=O1();x0(H.tempId,k),q(k,H.snippet,w,I1,H.ctx,j),N(null)},onCancel:()=>{v0(H.tempId),N(null)}},void 0,!1,void 0,this),O&&(()=>{let w=Z.find((j)=>j.id===O.annId);if(!w)return null;return F(W0,{anchorEl:O.anchorEl,scrollContainer:L,initialNote:w.note,initialImages:w.images,onUpdate:(j,k)=>{G(O.annId,j);let m=w.images||[];for(let D of k)if(!m.includes(D))K(O.annId,D);for(let D of m)if(!k.includes(D))_(O.annId,D)},onDelete:()=>{U(O.annId),W(null)},onClose:()=>B(null)},void 0,!1,void 0,this)})()]},void 0,!0,void 0,this)}function a8(){let{activeView:$,setActiveView:Q,openFiles:J,closeFile:X,canvasFiles:Y}=Y0.useContext(E1),Z=Y0.useContext(k4),{addAnnotationWithId:q,setActiveAnnotationId:U}=v1();if(!(Y.length>1||J.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:[Y.length>1&&F(Y2,{children:[F("button",{onClick:()=>Q({type:"overview"}),className:`flex items-center gap-1.5 px-4 py-2.5 text-[13px] font-body whitespace-nowrap transition-colors relative ${$.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",$.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),Y.map((K,_)=>{let z=K.replace(/\.jsx$/,""),W=$.type==="canvas"&&$.filename===K;return F(Y0.Fragment,{children:[F("button",{onClick:()=>Q({type:"canvas",filename:K}),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:[z,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),_<Y.length-1&&F("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this)]},K,!0,void 0,this)}),J.length>0&&F(Y2,{children:[F("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this),J.map((K,_)=>{let z=K.split("/").pop()||K,W=$.type==="file"&&$.path===K;return F(Y0.Fragment,{children:[F("div",{className:"flex items-center",children:[F("button",{onClick:()=>Q({type:"file",path:K}),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(t1,{name:z,type:"file"},void 0,!1,void 0,this),z,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:(H)=>{H.stopPropagation(),X(K)},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),_<J.length-1&&F("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this)]},K,!0,void 0,this)})]},void 0,!0,void 0,this),F("div",{className:"ml-auto flex items-center gap-1 flex-shrink-0",children:$.type==="file"&&p1&&F("button",{onClick:async()=>{let K=$.path;try{let z=await(await fetch(`/api/file?session=${Z}&path=${encodeURIComponent(K)}`)).json();if(!z.error){let W=z.content.split(`
88
88
  `).slice(0,3).join(`
89
- `)+(U.content.split(`
89
+ `)+(z.content.split(`
90
90
  `).length>3?`
91
- ...`:""),T=L1();X(T,W,"",_),G(T)}}catch{}},className:"flex items-center gap-1 px-3 py-1.5 text-[11px] font-medium font-body text-text-tertiary hover:text-text-secondary whitespace-nowrap transition-colors",children:[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 R5=document.getElementById("root");if(R5)E6(R5).render(F(u6,{},void 0,!1,void 0,this));export{A1 as RevisionContext,D1 as ActiveViewContext};
91
+ ...`:""),H=O1();q(H,W,"",K),U(H)}}catch{}},className:"flex items-center gap-1 px-3 py-1.5 text-[11px] font-medium font-body text-text-tertiary hover:text-text-secondary whitespace-nowrap transition-colors",children:[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 V4=document.getElementById("root");if(V4)c8(V4).render(F(r8,{},void 0,!1,void 0,this));