agent-canvas 0.1.44 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -0
- package/bin/lib/commands/daemon.ts +3 -6
- package/bin/lib/commands/push.ts +1 -1
- package/bin/lib/daemon-lifecycle.ts +65 -72
- package/bin/lib/helpers.test.ts +1 -0
- package/bin/lib/helpers.ts +30 -74
- package/daemon/build.ts +37 -16
- package/daemon/client/App.tsx +27 -61
- package/daemon/client/CompareView.tsx +4 -4
- package/daemon/client/FileBrowser.tsx +4 -4
- package/daemon/client/FileViewer.tsx +4 -4
- package/daemon/client/OverviewView.tsx +2 -2
- package/daemon/client/RevisionSelect.tsx +1 -1
- package/daemon/client/canvas-runtime.ts +1 -0
- package/daemon/client/clientApi.ts +18 -0
- package/daemon/client/components/index.ts +3 -16
- package/daemon/client/styles.css +4 -457
- package/daemon/dist/annotations-runtime.js +1 -0
- package/daemon/dist/client.css +1 -1
- package/daemon/dist/client.js +76 -76
- package/daemon/dist/components.js +59 -59
- package/daemon/dist/index.html +1 -0
- package/daemon/dist/preact-compat.js +1 -1
- package/daemon/dist/runtime.js +1 -1
- package/daemon/src/components.ts +13 -0
- package/daemon/src/handlers/api.ts +13 -9
- package/daemon/src/handlers/files.ts +2 -3
- package/daemon/src/handlers/static.ts +1 -1
- package/daemon/src/handlers/uploads.ts +2 -3
- package/daemon/src/paths.ts +10 -24
- package/daemon/src/remote-feedback.test.ts +1 -1
- package/daemon/src/remote-feedback.ts +1 -1
- package/daemon/src/secrets-api.test.ts +2 -2
- package/daemon/src/server.ts +11 -10
- package/daemon/src/share-e2e.test.ts +1 -1
- package/daemon/src/share.test.ts +1 -1
- package/daemon/src/share.ts +1 -1
- package/daemon/tsconfig.json +1 -3
- package/package.json +11 -4
- package/.github/dark.png +0 -0
- package/.github/light.png +0 -0
- package/.github/workflows/ci.yml +0 -48
- package/.github/workflows/deploy-worker-prod.yml +0 -19
- package/.github/workflows/deploy-worker-stage.yml +0 -21
- package/.github/workflows/deploy-worker.yml +0 -72
- package/.github/workflows/release.yml +0 -36
- package/CLAUDE.md +0 -86
- package/bun.lock +0 -377
- package/daemon/client/AnnotationEditor.tsx +0 -315
- package/daemon/client/AnnotationProvider.tsx +0 -195
- package/daemon/client/AnnotationSidebar.tsx +0 -627
- package/daemon/client/FileIcon.tsx +0 -76
- package/daemon/client/PlanRenderer.tsx +0 -614
- package/daemon/client/Popover.tsx +0 -350
- package/daemon/client/RenderErrorContext.ts +0 -11
- package/daemon/client/ResponsePreview.tsx +0 -186
- package/daemon/client/SessionContext.tsx +0 -3
- package/daemon/client/annotationContext.ts +0 -114
- package/daemon/client/annotationDom.ts +0 -104
- package/daemon/client/annotationDraft.test.ts +0 -188
- package/daemon/client/annotationDraft.ts +0 -130
- package/daemon/client/compat/preact-all.ts +0 -4
- package/daemon/client/components/Callout.tsx +0 -26
- package/daemon/client/components/Checklist.tsx +0 -37
- package/daemon/client/components/Choice.tsx +0 -176
- package/daemon/client/components/CodeBlock.tsx +0 -35
- package/daemon/client/components/Diff.tsx +0 -65
- package/daemon/client/components/FilePreview.tsx +0 -88
- package/daemon/client/components/Image.tsx +0 -45
- package/daemon/client/components/Markdown.tsx +0 -44
- package/daemon/client/components/Mermaid.tsx +0 -565
- package/daemon/client/components/Note.tsx +0 -14
- package/daemon/client/components/Priority.tsx +0 -19
- package/daemon/client/components/ResponseNote.tsx +0 -19
- package/daemon/client/components/Section.tsx +0 -33
- package/daemon/client/components/Table.tsx +0 -35
- package/daemon/client/components/Task.tsx +0 -76
- package/daemon/client/components/UserInput.tsx +0 -174
- package/daemon/client/components/renderMarkdownChildren.tsx +0 -97
- package/daemon/client/generateMarkdown.ts +0 -273
- package/daemon/client/highlightRange.ts +0 -224
- package/daemon/client/popoverPosition.ts +0 -31
- package/daemon/client/runtime.ts +0 -123
- package/daemon/client/theme.css +0 -66
- package/daemon/client/useTextAnnotation.tsx +0 -188
- package/daemon/client/utils.ts +0 -13
- package/daemon/src/compiler.test.ts +0 -57
- package/daemon/src/compiler.ts +0 -360
- package/daemon/src/handlers/utils.ts +0 -14
- package/daemon/src/router.ts +0 -16
- package/daemon/src/session-secrets.test.ts +0 -83
- package/daemon/src/session.ts +0 -612
- package/daemon/src/watcher.ts +0 -71
- package/daemon/src/websocket.test.ts +0 -99
- package/daemon/src/websocket.ts +0 -211
- package/tsconfig.json +0 -14
- package/workers/canvas-share/README.md +0 -159
- package/workers/canvas-share/oblaka.ts +0 -56
- package/workers/canvas-share/package.json +0 -25
- package/workers/canvas-share/public/assets/.gitkeep +0 -0
- package/workers/canvas-share/public/assets/client.css +0 -2
- package/workers/canvas-share/public/assets/client.js +0 -91
- package/workers/canvas-share/public/assets/components.js +0 -65
- package/workers/canvas-share/public/assets/jsx-runtime.js +0 -3
- package/workers/canvas-share/public/assets/preact-compat.js +0 -1
- package/workers/canvas-share/public/assets/runtime.js +0 -1
- package/workers/canvas-share/public/index.html +0 -385
- package/workers/canvas-share/public/screenshot-dark.png +0 -0
- package/workers/canvas-share/public/screenshot-light.png +0 -0
- package/workers/canvas-share/src/index.test.ts +0 -209
- package/workers/canvas-share/src/index.ts +0 -518
- package/workers/canvas-share/src/types.ts +0 -119
- package/workers/canvas-share/src/util.ts +0 -156
- package/workers/canvas-share/src/validation.ts +0 -160
- package/workers/canvas-share/tsconfig.json +0 -16
package/daemon/dist/client.js
CHANGED
|
@@ -1,91 +1,91 @@
|
|
|
1
|
-
import
|
|
2
|
-
]`).replace("lheading",
|
|
3
|
-
`).map((
|
|
4
|
-
`)}var
|
|
5
|
-
`)}}}fences(
|
|
6
|
-
`)}}blockquote(
|
|
1
|
+
import ot,{useEffect as Ne,useLayoutEffect as Ql,useState as ie,useCallback as Lt,useRef as Fe,useMemo as Is}from"react";import{createRoot as ec}from"react-dom/client";function Kn(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var at=Kn();function Yo(e){at=e}var st={exec:()=>null};function ne(e,t=""){let n=typeof e=="string"?e:e.source,r={replace:(o,i)=>{let s=typeof i=="string"?i:i.source;return s=s.replace(xe.caret,"$1"),n=n.replace(o,s),r},getRegex:()=>new RegExp(n,t)};return r}var qs=(()=>{try{return!!new RegExp("(?<=1)(?<!1)")}catch{return!1}})(),xe={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:(e)=>new RegExp(`^( {0,3}${e})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:(e)=>new RegExp(`^ {0,${Math.min(3,e-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:(e)=>new RegExp(`^ {0,${Math.min(3,e-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:(e)=>new RegExp(`^ {0,${Math.min(3,e-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:(e)=>new RegExp(`^ {0,${Math.min(3,e-1)}}#`),htmlBeginRegex:(e)=>new RegExp(`^ {0,${Math.min(3,e-1)}}<(?:[a-z].*>|!--)`,"i"),blockquoteBeginRegex:(e)=>new RegExp(`^ {0,${Math.min(3,e-1)}}>`)},zs=/^(?:[ \t]*(?:\n|$))+/,Vs=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,Ws=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,Dt=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,Us=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,Zn=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,Qo=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,er=ne(Qo).replace(/bull/g,Zn).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(),Gs=ne(Qo).replace(/bull/g,Zn).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(),Xn=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,Ks=/^[^\n]+/,Jn=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,Zs=ne(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",Jn).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),Xs=ne(/^(bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,Zn).getRegex(),fn="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",Yn=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,Js=ne("^ {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",Yn).replace("tag",fn).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),tr=ne(Xn).replace("hr",Dt).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",fn).getRegex(),Ys=ne(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",tr).getRegex(),Qn={blockquote:Ys,code:Vs,def:Zs,fences:Ws,heading:Us,hr:Dt,html:Js,lheading:er,list:Xs,newline:zs,paragraph:tr,table:st,text:Ks},Uo=ne("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",Dt).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",fn).getRegex(),Qs={...Qn,lheading:Gs,table:Uo,paragraph:ne(Xn).replace("hr",Dt).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",Uo).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",fn).getRegex()},ei={...Qn,html:ne(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",Yn).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:st,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:ne(Xn).replace("hr",Dt).replace("heading",` *#{1,6} *[^
|
|
2
|
+
]`).replace("lheading",er).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},ti=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,ni=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,nr=/^( {2,}|\\)\n(?!\s*$)/,oi=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,vt=/[\p{P}\p{S}]/u,mn=/[\s\p{P}\p{S}]/u,eo=/[^\s\p{P}\p{S}]/u,ri=ne(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,mn).getRegex(),or=/(?!~)[\p{P}\p{S}]/u,si=/(?!~)[\s\p{P}\p{S}]/u,ii=/(?:[^\s\p{P}\p{S}]|~)/u,ai=ne(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",qs?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),rr=/^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/,li=ne(rr,"u").replace(/punct/g,vt).getRegex(),ci=ne(rr,"u").replace(/punct/g,or).getRegex(),sr="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",di=ne(sr,"gu").replace(/notPunctSpace/g,eo).replace(/punctSpace/g,mn).replace(/punct/g,vt).getRegex(),ui=ne(sr,"gu").replace(/notPunctSpace/g,ii).replace(/punctSpace/g,si).replace(/punct/g,or).getRegex(),pi=ne("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,eo).replace(/punctSpace/g,mn).replace(/punct/g,vt).getRegex(),fi=ne(/^~~?(?:((?!~)punct)|[^\s~])/,"u").replace(/punct/g,vt).getRegex(),mi="^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)",hi=ne(mi,"gu").replace(/notPunctSpace/g,eo).replace(/punctSpace/g,mn).replace(/punct/g,vt).getRegex(),gi=ne(/\\(punct)/,"gu").replace(/punct/g,vt).getRegex(),xi=ne(/^<(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(),bi=ne(Yn).replace("(?:-->|$)","-->").getRegex(),vi=ne("^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",bi).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),dn=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/,yi=ne(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace("label",dn).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),ir=ne(/^!?\[(label)\]\[(ref)\]/).replace("label",dn).replace("ref",Jn).getRegex(),ar=ne(/^!?\[(ref)\](?:\[\])?/).replace("ref",Jn).getRegex(),ki=ne("reflink|nolink(?!\\()","g").replace("reflink",ir).replace("nolink",ar).getRegex(),Go=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,to={_backpedal:st,anyPunctuation:gi,autolink:xi,blockSkip:ai,br:nr,code:ni,del:st,delLDelim:st,delRDelim:st,emStrongLDelim:li,emStrongRDelimAst:di,emStrongRDelimUnd:pi,escape:ti,link:yi,nolink:ar,punctuation:ri,reflink:ir,reflinkSearch:ki,tag:vi,text:oi,url:st},wi={...to,link:ne(/^!?\[(label)\]\((.*?)\)/).replace("label",dn).getRegex(),reflink:ne(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",dn).getRegex()},Gn={...to,emStrongRDelimAst:ui,emStrongLDelim:ci,delLDelim:fi,delRDelim:hi,url:ne(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol",Go).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:ne(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace("protocol",Go).getRegex()},Ei={...Gn,br:ne(nr).replace("{2,}","*").getRegex(),text:ne(Gn.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},cn={normal:Qn,gfm:Qs,pedantic:ei},Pt={normal:to,gfm:Gn,breaks:Ei,pedantic:wi},Ai={"&":"&","<":"<",">":">",'"':""","'":"'"},Ko=(e)=>Ai[e];function Le(e,t){if(t){if(xe.escapeTest.test(e))return e.replace(xe.escapeReplace,Ko)}else if(xe.escapeTestNoEncode.test(e))return e.replace(xe.escapeReplaceNoEncode,Ko);return e}function Zo(e){try{e=encodeURI(e).replace(xe.percentDecode,"%")}catch{return null}return e}function Xo(e,t){let n=e.replace(xe.findPipe,(i,s,l)=>{let a=!1,c=s;for(;--c>=0&&l[c]==="\\";)a=!a;return a?"|":" |"}),r=n.split(xe.splitPipe),o=0;if(r[0].trim()||r.shift(),r.length>0&&!r.at(-1)?.trim()&&r.pop(),t)if(r.length>t)r.splice(t);else for(;r.length<t;)r.push("");for(;o<r.length;o++)r[o]=r[o].trim().replace(xe.slashPipe,"|");return r}function $t(e,t,n){let r=e.length;if(r===0)return"";let o=0;for(;o<r;){let i=e.charAt(r-o-1);if(i===t&&!n)o++;else if(i!==t&&n)o++;else break}return e.slice(0,r-o)}function Ri(e,t){if(e.indexOf(t[1])===-1)return-1;let n=0;for(let r=0;r<e.length;r++)if(e[r]==="\\")r++;else if(e[r]===t[0])n++;else if(e[r]===t[1]&&(n--,n<0))return r;return n>0?-2:-1}function Si(e,t=0){let n=t,r="";for(let o of e)if(o==="\t"){let i=4-n%4;r+=" ".repeat(i),n+=i}else r+=o,n++;return r}function Jo(e,t,n,r,o){let i=t.href,s=t.title||null,l=e[1].replace(o.other.outputLinkReplace,"$1");r.state.inLink=!0;let a={type:e[0].charAt(0)==="!"?"image":"link",raw:n,href:i,title:s,text:l,tokens:r.inlineTokens(l)};return r.state.inLink=!1,a}function Ci(e,t,n){let r=e.match(n.other.indentCodeCompensation);if(r===null)return t;let o=r[1];return t.split(`
|
|
3
|
+
`).map((i)=>{let s=i.match(n.other.beginningSpace);if(s===null)return i;let[l]=s;return l.length>=o.length?i.slice(o.length):i}).join(`
|
|
4
|
+
`)}var un=class{options;rules;lexer;constructor(e){this.options=e||at}space(e){let t=this.rules.block.newline.exec(e);if(t&&t[0].length>0)return{type:"space",raw:t[0]}}code(e){let t=this.rules.block.code.exec(e);if(t){let n=t[0].replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:t[0],codeBlockStyle:"indented",text:this.options.pedantic?n:$t(n,`
|
|
5
|
+
`)}}}fences(e){let t=this.rules.block.fences.exec(e);if(t){let n=t[0],r=Ci(n,t[3]||"",this.rules);return{type:"code",raw:n,lang:t[2]?t[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):t[2],text:r}}}heading(e){let t=this.rules.block.heading.exec(e);if(t){let n=t[2].trim();if(this.rules.other.endingHash.test(n)){let r=$t(n,"#");(this.options.pedantic||!r||this.rules.other.endingSpaceChar.test(r))&&(n=r.trim())}return{type:"heading",raw:t[0],depth:t[1].length,text:n,tokens:this.lexer.inline(n)}}}hr(e){let t=this.rules.block.hr.exec(e);if(t)return{type:"hr",raw:$t(t[0],`
|
|
6
|
+
`)}}blockquote(e){let t=this.rules.block.blockquote.exec(e);if(t){let n=$t(t[0],`
|
|
7
7
|
`).split(`
|
|
8
|
-
`),
|
|
9
|
-
`),
|
|
10
|
-
$1`).replace(this.rules.other.blockquoteSetextReplace2,"");
|
|
11
|
-
${
|
|
12
|
-
${
|
|
13
|
-
`+
|
|
14
|
-
`),
|
|
15
|
-
`+
|
|
16
|
-
`),
|
|
17
|
-
`);continue}}return{type:"blockquote",raw:
|
|
18
|
-
`,1)[0]
|
|
19
|
-
`,1)[0],
|
|
20
|
-
`,
|
|
21
|
-
`,1)[0],
|
|
22
|
-
`+
|
|
23
|
-
`+
|
|
24
|
-
`,
|
|
25
|
-
`):[],
|
|
26
|
-
|
|
27
|
-
`),this.blockTokens(
|
|
28
|
-
`:
|
|
8
|
+
`),r="",o="",i=[];for(;n.length>0;){let s=!1,l=[],a;for(a=0;a<n.length;a++)if(this.rules.other.blockquoteStart.test(n[a]))l.push(n[a]),s=!0;else if(!s)l.push(n[a]);else break;n=n.slice(a);let c=l.join(`
|
|
9
|
+
`),u=c.replace(this.rules.other.blockquoteSetextReplace,`
|
|
10
|
+
$1`).replace(this.rules.other.blockquoteSetextReplace2,"");r=r?`${r}
|
|
11
|
+
${c}`:c,o=o?`${o}
|
|
12
|
+
${u}`:u;let d=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(u,i,!0),this.lexer.state.top=d,n.length===0)break;let f=i.at(-1);if(f?.type==="code")break;if(f?.type==="blockquote"){let p=f,m=p.raw+`
|
|
13
|
+
`+n.join(`
|
|
14
|
+
`),v=this.blockquote(m);i[i.length-1]=v,r=r.substring(0,r.length-p.raw.length)+v.raw,o=o.substring(0,o.length-p.text.length)+v.text;break}else if(f?.type==="list"){let p=f,m=p.raw+`
|
|
15
|
+
`+n.join(`
|
|
16
|
+
`),v=this.list(m);i[i.length-1]=v,r=r.substring(0,r.length-f.raw.length)+v.raw,o=o.substring(0,o.length-p.raw.length)+v.raw,n=m.substring(i.at(-1).raw.length).split(`
|
|
17
|
+
`);continue}}return{type:"blockquote",raw:r,tokens:i,text:o}}}list(e){let t=this.rules.block.list.exec(e);if(t){let n=t[1].trim(),r=n.length>1,o={type:"list",raw:"",ordered:r,start:r?+n.slice(0,-1):"",loose:!1,items:[]};n=r?`\\d{1,9}\\${n.slice(-1)}`:`\\${n}`,this.options.pedantic&&(n=r?n:"[*+-]");let i=this.rules.other.listItemRegex(n),s=!1;for(;e;){let a=!1,c="",u="";if(!(t=i.exec(e))||this.rules.block.hr.test(e))break;c=t[0],e=e.substring(c.length);let d=Si(t[2].split(`
|
|
18
|
+
`,1)[0],t[1].length),f=e.split(`
|
|
19
|
+
`,1)[0],p=!d.trim(),m=0;if(this.options.pedantic?(m=2,u=d.trimStart()):p?m=t[1].length+1:(m=d.search(this.rules.other.nonSpaceChar),m=m>4?1:m,u=d.slice(m),m+=t[1].length),p&&this.rules.other.blankLine.test(f)&&(c+=f+`
|
|
20
|
+
`,e=e.substring(f.length+1),a=!0),!a){let v=this.rules.other.nextBulletRegex(m),g=this.rules.other.hrRegex(m),w=this.rules.other.fencesBeginRegex(m),h=this.rules.other.headingBeginRegex(m),b=this.rules.other.htmlBeginRegex(m),k=this.rules.other.blockquoteBeginRegex(m);for(;e;){let y=e.split(`
|
|
21
|
+
`,1)[0],E;if(f=y,this.options.pedantic?(f=f.replace(this.rules.other.listReplaceNesting," "),E=f):E=f.replace(this.rules.other.tabCharGlobal," "),w.test(f)||h.test(f)||b.test(f)||k.test(f)||v.test(f)||g.test(f))break;if(E.search(this.rules.other.nonSpaceChar)>=m||!f.trim())u+=`
|
|
22
|
+
`+E.slice(m);else{if(p||d.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||w.test(d)||h.test(d)||g.test(d))break;u+=`
|
|
23
|
+
`+f}p=!f.trim(),c+=y+`
|
|
24
|
+
`,e=e.substring(y.length+1),d=E.slice(m)}}o.loose||(s?o.loose=!0:this.rules.other.doubleBlankLine.test(c)&&(s=!0)),o.items.push({type:"list_item",raw:c,task:!!this.options.gfm&&this.rules.other.listIsTask.test(u),loose:!1,text:u,tokens:[]}),o.raw+=c}let l=o.items.at(-1);if(l)l.raw=l.raw.trimEnd(),l.text=l.text.trimEnd();else return;o.raw=o.raw.trimEnd();for(let a of o.items){if(this.lexer.state.top=!1,a.tokens=this.lexer.blockTokens(a.text,[]),a.task){if(a.text=a.text.replace(this.rules.other.listReplaceTask,""),a.tokens[0]?.type==="text"||a.tokens[0]?.type==="paragraph"){a.tokens[0].raw=a.tokens[0].raw.replace(this.rules.other.listReplaceTask,""),a.tokens[0].text=a.tokens[0].text.replace(this.rules.other.listReplaceTask,"");for(let u=this.lexer.inlineQueue.length-1;u>=0;u--)if(this.rules.other.listIsTask.test(this.lexer.inlineQueue[u].src)){this.lexer.inlineQueue[u].src=this.lexer.inlineQueue[u].src.replace(this.rules.other.listReplaceTask,"");break}}let c=this.rules.other.listTaskCheckbox.exec(a.raw);if(c){let u={type:"checkbox",raw:c[0]+" ",checked:c[0]!=="[ ]"};a.checked=u.checked,o.loose?a.tokens[0]&&["paragraph","text"].includes(a.tokens[0].type)&&"tokens"in a.tokens[0]&&a.tokens[0].tokens?(a.tokens[0].raw=u.raw+a.tokens[0].raw,a.tokens[0].text=u.raw+a.tokens[0].text,a.tokens[0].tokens.unshift(u)):a.tokens.unshift({type:"paragraph",raw:u.raw,text:u.raw,tokens:[u]}):a.tokens.unshift(u)}}if(!o.loose){let c=a.tokens.filter((d)=>d.type==="space"),u=c.length>0&&c.some((d)=>this.rules.other.anyLine.test(d.raw));o.loose=u}}if(o.loose)for(let a of o.items){a.loose=!0;for(let c of a.tokens)c.type==="text"&&(c.type="paragraph")}return o}}html(e){let t=this.rules.block.html.exec(e);if(t)return{type:"html",block:!0,raw:t[0],pre:t[1]==="pre"||t[1]==="script"||t[1]==="style",text:t[0]}}def(e){let t=this.rules.block.def.exec(e);if(t){let n=t[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal," "),r=t[2]?t[2].replace(this.rules.other.hrefBrackets,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",o=t[3]?t[3].substring(1,t[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):t[3];return{type:"def",tag:n,raw:t[0],href:r,title:o}}}table(e){let t=this.rules.block.table.exec(e);if(!t||!this.rules.other.tableDelimiter.test(t[2]))return;let n=Xo(t[1]),r=t[2].replace(this.rules.other.tableAlignChars,"").split("|"),o=t[3]?.trim()?t[3].replace(this.rules.other.tableRowBlankLine,"").split(`
|
|
25
|
+
`):[],i={type:"table",raw:t[0],header:[],align:[],rows:[]};if(n.length===r.length){for(let s of r)this.rules.other.tableAlignRight.test(s)?i.align.push("right"):this.rules.other.tableAlignCenter.test(s)?i.align.push("center"):this.rules.other.tableAlignLeft.test(s)?i.align.push("left"):i.align.push(null);for(let s=0;s<n.length;s++)i.header.push({text:n[s],tokens:this.lexer.inline(n[s]),header:!0,align:i.align[s]});for(let s of o)i.rows.push(Xo(s,i.header.length).map((l,a)=>({text:l,tokens:this.lexer.inline(l),header:!1,align:i.align[a]})));return i}}lheading(e){let t=this.rules.block.lheading.exec(e);if(t){let n=t[1].trim();return{type:"heading",raw:t[0],depth:t[2].charAt(0)==="="?1:2,text:n,tokens:this.lexer.inline(n)}}}paragraph(e){let t=this.rules.block.paragraph.exec(e);if(t){let n=t[1].charAt(t[1].length-1)===`
|
|
26
|
+
`?t[1].slice(0,-1):t[1];return{type:"paragraph",raw:t[0],text:n,tokens:this.lexer.inline(n)}}}text(e){let t=this.rules.block.text.exec(e);if(t)return{type:"text",raw:t[0],text:t[0],tokens:this.lexer.inline(t[0])}}escape(e){let t=this.rules.inline.escape.exec(e);if(t)return{type:"escape",raw:t[0],text:t[1]}}tag(e){let t=this.rules.inline.tag.exec(e);if(t)return!this.lexer.state.inLink&&this.rules.other.startATag.test(t[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test(t[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test(t[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test(t[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:t[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:t[0]}}link(e){let t=this.rules.inline.link.exec(e);if(t){let n=t[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(n)){if(!this.rules.other.endAngleBracket.test(n))return;let i=$t(n.slice(0,-1),"\\");if((n.length-i.length)%2===0)return}else{let i=Ri(t[2],"()");if(i===-2)return;if(i>-1){let s=(t[0].indexOf("!")===0?5:4)+t[1].length+i;t[2]=t[2].substring(0,i),t[0]=t[0].substring(0,s).trim(),t[3]=""}}let r=t[2],o="";if(this.options.pedantic){let i=this.rules.other.pedanticHrefTitle.exec(r);i&&(r=i[1],o=i[3])}else o=t[3]?t[3].slice(1,-1):"";return r=r.trim(),this.rules.other.startAngleBracket.test(r)&&(this.options.pedantic&&!this.rules.other.endAngleBracket.test(n)?r=r.slice(1):r=r.slice(1,-1)),Jo(t,{href:r&&r.replace(this.rules.inline.anyPunctuation,"$1"),title:o&&o.replace(this.rules.inline.anyPunctuation,"$1")},t[0],this.lexer,this.rules)}}reflink(e,t){let n;if((n=this.rules.inline.reflink.exec(e))||(n=this.rules.inline.nolink.exec(e))){let r=(n[2]||n[1]).replace(this.rules.other.multipleSpaceGlobal," "),o=t[r.toLowerCase()];if(!o){let i=n[0].charAt(0);return{type:"text",raw:i,text:i}}return Jo(n,o,n[0],this.lexer,this.rules)}}emStrong(e,t,n=""){let r=this.rules.inline.emStrongLDelim.exec(e);if(!r||!r[1]&&!r[2]&&!r[3]&&!r[4]||r[4]&&n.match(this.rules.other.unicodeAlphaNumeric))return;if(!(r[1]||r[3])||!n||this.rules.inline.punctuation.exec(n)){let o=[...r[0]].length-1,i,s,l=o,a=0,c=r[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(c.lastIndex=0,t=t.slice(-1*e.length+o);(r=c.exec(t))!==null;){if(i=r[1]||r[2]||r[3]||r[4]||r[5]||r[6],!i)continue;if(s=[...i].length,r[3]||r[4]){l+=s;continue}else if((r[5]||r[6])&&o%3&&!((o+s)%3)){a+=s;continue}if(l-=s,l>0)continue;s=Math.min(s,s+l+a);let u=[...r[0]][0].length,d=e.slice(0,o+r.index+u+s);if(Math.min(o,s)%2){let p=d.slice(1,-1);return{type:"em",raw:d,text:p,tokens:this.lexer.inlineTokens(p)}}let f=d.slice(2,-2);return{type:"strong",raw:d,text:f,tokens:this.lexer.inlineTokens(f)}}}}codespan(e){let t=this.rules.inline.code.exec(e);if(t){let n=t[2].replace(this.rules.other.newLineCharGlobal," "),r=this.rules.other.nonSpaceChar.test(n),o=this.rules.other.startingSpaceChar.test(n)&&this.rules.other.endingSpaceChar.test(n);return r&&o&&(n=n.substring(1,n.length-1)),{type:"codespan",raw:t[0],text:n}}}br(e){let t=this.rules.inline.br.exec(e);if(t)return{type:"br",raw:t[0]}}del(e,t,n=""){let r=this.rules.inline.delLDelim.exec(e);if(!r)return;if(!r[1]||!n||this.rules.inline.punctuation.exec(n)){let o=[...r[0]].length-1,i,s,l=o,a=this.rules.inline.delRDelim;for(a.lastIndex=0,t=t.slice(-1*e.length+o);(r=a.exec(t))!==null;){if(i=r[1]||r[2]||r[3]||r[4]||r[5]||r[6],!i||(s=[...i].length,s!==o))continue;if(r[3]||r[4]){l+=s;continue}if(l-=s,l>0)continue;s=Math.min(s,s+l);let c=[...r[0]][0].length,u=e.slice(0,o+r.index+c+s),d=u.slice(o,-o);return{type:"del",raw:u,text:d,tokens:this.lexer.inlineTokens(d)}}}}autolink(e){let t=this.rules.inline.autolink.exec(e);if(t){let n,r;return t[2]==="@"?(n=t[1],r="mailto:"+n):(n=t[1],r=n),{type:"link",raw:t[0],text:n,href:r,tokens:[{type:"text",raw:n,text:n}]}}}url(e){let t;if(t=this.rules.inline.url.exec(e)){let n,r;if(t[2]==="@")n=t[0],r="mailto:"+n;else{let o;do o=t[0],t[0]=this.rules.inline._backpedal.exec(t[0])?.[0]??"";while(o!==t[0]);n=t[0],t[1]==="www."?r="http://"+t[0]:r=t[0]}return{type:"link",raw:t[0],text:n,href:r,tokens:[{type:"text",raw:n,text:n}]}}}inlineText(e){let t=this.rules.inline.text.exec(e);if(t){let n=this.lexer.state.inRawBlock;return{type:"text",raw:t[0],text:t[0],escaped:n}}}},Ae=class e{tokens;options;state;inlineQueue;tokenizer;constructor(t){this.tokens=[],this.tokens.links=Object.create(null),this.options=t||at,this.options.tokenizer=this.options.tokenizer||new un,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 n={other:xe,block:cn.normal,inline:Pt.normal};this.options.pedantic?(n.block=cn.pedantic,n.inline=Pt.pedantic):this.options.gfm&&(n.block=cn.gfm,this.options.breaks?n.inline=Pt.breaks:n.inline=Pt.gfm),this.tokenizer.rules=n}static get rules(){return{block:cn,inline:Pt}}static lex(t,n){return new e(n).lex(t)}static lexInline(t,n){return new e(n).inlineTokens(t)}lex(t){t=t.replace(xe.carriageReturn,`
|
|
27
|
+
`),this.blockTokens(t,this.tokens);for(let n=0;n<this.inlineQueue.length;n++){let r=this.inlineQueue[n];this.inlineTokens(r.src,r.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(t,n=[],r=!1){for(this.tokenizer.lexer=this,this.options.pedantic&&(t=t.replace(xe.tabCharGlobal," ").replace(xe.spaceLine,""));t;){let o;if(this.options.extensions?.block?.some((s)=>(o=s.call({lexer:this},t,n))?(t=t.substring(o.raw.length),n.push(o),!0):!1))continue;if(o=this.tokenizer.space(t)){t=t.substring(o.raw.length);let s=n.at(-1);o.raw.length===1&&s!==void 0?s.raw+=`
|
|
28
|
+
`:n.push(o);continue}if(o=this.tokenizer.code(t)){t=t.substring(o.raw.length);let s=n.at(-1);s?.type==="paragraph"||s?.type==="text"?(s.raw+=(s.raw.endsWith(`
|
|
29
29
|
`)?"":`
|
|
30
|
-
`)+
|
|
31
|
-
`+
|
|
30
|
+
`)+o.raw,s.text+=`
|
|
31
|
+
`+o.text,this.inlineQueue.at(-1).src=s.text):n.push(o);continue}if(o=this.tokenizer.fences(t)){t=t.substring(o.raw.length),n.push(o);continue}if(o=this.tokenizer.heading(t)){t=t.substring(o.raw.length),n.push(o);continue}if(o=this.tokenizer.hr(t)){t=t.substring(o.raw.length),n.push(o);continue}if(o=this.tokenizer.blockquote(t)){t=t.substring(o.raw.length),n.push(o);continue}if(o=this.tokenizer.list(t)){t=t.substring(o.raw.length),n.push(o);continue}if(o=this.tokenizer.html(t)){t=t.substring(o.raw.length),n.push(o);continue}if(o=this.tokenizer.def(t)){t=t.substring(o.raw.length);let s=n.at(-1);s?.type==="paragraph"||s?.type==="text"?(s.raw+=(s.raw.endsWith(`
|
|
32
32
|
`)?"":`
|
|
33
|
-
`)+
|
|
34
|
-
`+
|
|
33
|
+
`)+o.raw,s.text+=`
|
|
34
|
+
`+o.raw,this.inlineQueue.at(-1).src=s.text):this.tokens.links[o.tag]||(this.tokens.links[o.tag]={href:o.href,title:o.title},n.push(o));continue}if(o=this.tokenizer.table(t)){t=t.substring(o.raw.length),n.push(o);continue}if(o=this.tokenizer.lheading(t)){t=t.substring(o.raw.length),n.push(o);continue}let i=t;if(this.options.extensions?.startBlock){let s=1/0,l=t.slice(1),a;this.options.extensions.startBlock.forEach((c)=>{a=c.call({lexer:this},l),typeof a=="number"&&a>=0&&(s=Math.min(s,a))}),s<1/0&&s>=0&&(i=t.substring(0,s+1))}if(this.state.top&&(o=this.tokenizer.paragraph(i))){let s=n.at(-1);r&&s?.type==="paragraph"?(s.raw+=(s.raw.endsWith(`
|
|
35
35
|
`)?"":`
|
|
36
|
-
`)+
|
|
37
|
-
`+
|
|
36
|
+
`)+o.raw,s.text+=`
|
|
37
|
+
`+o.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=s.text):n.push(o),r=i.length!==t.length,t=t.substring(o.raw.length);continue}if(o=this.tokenizer.text(t)){t=t.substring(o.raw.length);let s=n.at(-1);s?.type==="text"?(s.raw+=(s.raw.endsWith(`
|
|
38
38
|
`)?"":`
|
|
39
|
-
`)+
|
|
40
|
-
`+
|
|
41
|
-
`;return
|
|
42
|
-
`:"<pre><code>"+(
|
|
43
|
-
`}blockquote({tokens:
|
|
44
|
-
${this.parser.parse(
|
|
45
|
-
`}html({text:
|
|
46
|
-
`}hr(
|
|
47
|
-
`}list(
|
|
48
|
-
`+
|
|
49
|
-
`}listitem(
|
|
50
|
-
`}checkbox({checked:
|
|
51
|
-
`}table(
|
|
39
|
+
`)+o.raw,s.text+=`
|
|
40
|
+
`+o.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=s.text):n.push(o);continue}if(t){let s="Infinite loop on byte: "+t.charCodeAt(0);if(this.options.silent){console.error(s);break}else throw Error(s)}}return this.state.top=!0,n}inline(t,n=[]){return this.inlineQueue.push({src:t,tokens:n}),n}inlineTokens(t,n=[]){this.tokenizer.lexer=this;let r=t,o=null;if(this.tokens.links){let a=Object.keys(this.tokens.links);if(a.length>0)for(;(o=this.tokenizer.rules.inline.reflinkSearch.exec(r))!==null;)a.includes(o[0].slice(o[0].lastIndexOf("[")+1,-1))&&(r=r.slice(0,o.index)+"["+"a".repeat(o[0].length-2)+"]"+r.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(o=this.tokenizer.rules.inline.anyPunctuation.exec(r))!==null;)r=r.slice(0,o.index)+"++"+r.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);let i;for(;(o=this.tokenizer.rules.inline.blockSkip.exec(r))!==null;)i=o[2]?o[2].length:0,r=r.slice(0,o.index+i)+"["+"a".repeat(o[0].length-i-2)+"]"+r.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);r=this.options.hooks?.emStrongMask?.call({lexer:this},r)??r;let s=!1,l="";for(;t;){s||(l=""),s=!1;let a;if(this.options.extensions?.inline?.some((u)=>(a=u.call({lexer:this},t,n))?(t=t.substring(a.raw.length),n.push(a),!0):!1))continue;if(a=this.tokenizer.escape(t)){t=t.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.tag(t)){t=t.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.link(t)){t=t.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.reflink(t,this.tokens.links)){t=t.substring(a.raw.length);let u=n.at(-1);a.type==="text"&&u?.type==="text"?(u.raw+=a.raw,u.text+=a.text):n.push(a);continue}if(a=this.tokenizer.emStrong(t,r,l)){t=t.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.codespan(t)){t=t.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.br(t)){t=t.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.del(t,r,l)){t=t.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.autolink(t)){t=t.substring(a.raw.length),n.push(a);continue}if(!this.state.inLink&&(a=this.tokenizer.url(t))){t=t.substring(a.raw.length),n.push(a);continue}let c=t;if(this.options.extensions?.startInline){let u=1/0,d=t.slice(1),f;this.options.extensions.startInline.forEach((p)=>{f=p.call({lexer:this},d),typeof f=="number"&&f>=0&&(u=Math.min(u,f))}),u<1/0&&u>=0&&(c=t.substring(0,u+1))}if(a=this.tokenizer.inlineText(c)){t=t.substring(a.raw.length),a.raw.slice(-1)!=="_"&&(l=a.raw.slice(-1)),s=!0;let u=n.at(-1);u?.type==="text"?(u.raw+=a.raw,u.text+=a.text):n.push(a);continue}if(t){let u="Infinite loop on byte: "+t.charCodeAt(0);if(this.options.silent){console.error(u);break}else throw Error(u)}}return n}},pn=class{options;parser;constructor(e){this.options=e||at}space(e){return""}code({text:e,lang:t,escaped:n}){let r=(t||"").match(xe.notSpaceStart)?.[0],o=e.replace(xe.endingNewline,"")+`
|
|
41
|
+
`;return r?'<pre><code class="language-'+Le(r)+'">'+(n?o:Le(o,!0))+`</code></pre>
|
|
42
|
+
`:"<pre><code>"+(n?o:Le(o,!0))+`</code></pre>
|
|
43
|
+
`}blockquote({tokens:e}){return`<blockquote>
|
|
44
|
+
${this.parser.parse(e)}</blockquote>
|
|
45
|
+
`}html({text:e}){return e}def(e){return""}heading({tokens:e,depth:t}){return`<h${t}>${this.parser.parseInline(e)}</h${t}>
|
|
46
|
+
`}hr(e){return`<hr>
|
|
47
|
+
`}list(e){let{ordered:t,start:n}=e,r="";for(let s=0;s<e.items.length;s++){let l=e.items[s];r+=this.listitem(l)}let o=t?"ol":"ul",i=t&&n!==1?' start="'+n+'"':"";return"<"+o+i+`>
|
|
48
|
+
`+r+"</"+o+`>
|
|
49
|
+
`}listitem(e){return`<li>${this.parser.parse(e.tokens)}</li>
|
|
50
|
+
`}checkbox({checked:e}){return"<input "+(e?'checked="" ':"")+'disabled="" type="checkbox"> '}paragraph({tokens:e}){return`<p>${this.parser.parseInline(e)}</p>
|
|
51
|
+
`}table(e){let t="",n="";for(let o=0;o<e.header.length;o++)n+=this.tablecell(e.header[o]);t+=this.tablerow({text:n});let r="";for(let o=0;o<e.rows.length;o++){let i=e.rows[o];n="";for(let s=0;s<i.length;s++)n+=this.tablecell(i[s]);r+=this.tablerow({text:n})}return r&&(r=`<tbody>${r}</tbody>`),`<table>
|
|
52
52
|
<thead>
|
|
53
|
-
|
|
54
|
-
`+
|
|
55
|
-
`}tablerow({text:
|
|
56
|
-
${
|
|
57
|
-
`}tablecell(
|
|
58
|
-
`}strong({tokens:
|
|
59
|
-
Please report this to https://github.com/markedjs/marked.`,Z){let Q="<p>An error occurred:</p><pre>"+b1(q.message+"",!0)+"</pre>";return $?Promise.resolve(Q):Q}if($)return Promise.reject(q);throw q}}},r1=new j8;function e(Z,$){return r1.parse(Z,$)}e.options=e.setOptions=function(Z){return r1.setOptions(Z),e.defaults=r1.defaults,X3(e.defaults),e};e.getDefaults=B2;e.defaults=i1;e.use=function(...Z){return r1.use(...Z),e.defaults=r1.defaults,X3(e.defaults),e};e.walkTokens=function(Z,$){return r1.walkTokens(Z,$)};e.parseInline=r1.parseInline;e.Parser=F1;e.parser=F1.parse;e.Renderer=f0;e.TextRenderer=j2;e.Lexer=B1;e.lexer=B1.lex;e.Tokenizer=g0;e.Hooks=M0;e.parse=e;var{options:h6,setOptions:p6,use:c6,walkTokens:d6,parseInline:l6}=e;var r6=F1.parse,i6=B1.lex;import{SessionContext as E5,ActiveViewCtx as x6}from"#canvas/runtime";import{useState as S0,useCallback as j1,useEffect as A8,useRef as C8,useMemo as V8}from"react";import{AnnotationCtx as I8}from"#canvas/runtime";function R1(Z,$,q="current"){let Q=`canvas:${Z}:rev:${$}`;return q==="next"?`${Q}:next-draft`:Q}function X0(Z,$){return`${R1(Z,$)}:draft-handled`}function z0(Z,$,q){try{Z.removeItem(R1($,q)),Z.removeItem(X0($,q))}catch{}}function w2(Z){if(!Z)return null;try{let $=JSON.parse(Z);return typeof $==="object"&&$!==null&&!Array.isArray($)?$:null}catch{return null}}function w8(Z){if(!Array.isArray(Z)||Z.length<2)return!1;let $=Z[1];if(typeof $!=="object"||$===null||Array.isArray($))return!1;let q=Reflect.get($,"note");if(typeof q==="string"&&q.trim().length>0)return!0;let Q=Reflect.get($,"value");if(typeof Q==="string")return Q.trim().length>0;if(Array.isArray(Q))return Q.length>0;return Q!==null&&Q!==void 0}function A2(Z){if(!Z)return!1;let $=Reflect.get(Z,"annotations");if(Array.isArray($)&&$.length>0)return!0;let q=Reflect.get(Z,"generalNote");if(typeof q==="string"&&q.trim().length>0)return!0;let Q=Reflect.get(Z,"responses");return Array.isArray(Q)&&Q.some(w8)}function C2(Z,$,q,Q){try{let J=R1($,q);if(A2(w2(Z.getItem(J))))return Z.setItem(X0($,q),"1"),null;if(Z.getItem(X0($,q))!==null)return null;let Y=Q.filter((X)=>X.revision<q).sort((X,G)=>G.revision-X.revision);for(let X of Y){if(X.hasFeedback){let z=R1($,X.revision,"next"),_=w2(Z.getItem(z));if(!A2(_))return null;return Z.setItem(J,JSON.stringify({..._,feedbackEntries:[]})),Z.setItem(X0($,q),"1"),Z.removeItem(z),X.revision}let G=w2(Z.getItem(R1($,X.revision)));if(!A2(G)){if(Z.getItem(X0($,X.revision))!==null)return null;continue}return Z.setItem(J,JSON.stringify({...G,feedbackEntries:[]})),Z.setItem(X0($,q),"1"),X.revision}}catch{}return null}var T1="__agent-response__";function L1(){return`ann-${Date.now()}-${Math.random().toString(36).slice(2,6)}`}function y0(Z,$){Z.style.height="auto",Z.style.height=($?Math.max($,Z.scrollHeight):Z.scrollHeight)+"px"}import{useAnnotations as X1}from"#canvas/runtime";import{jsxDEV as D8}from"react/jsx-dev-runtime";function p0(Z,$,q){try{let Q=localStorage.getItem(R1(Z,$,q));if(!Q)return null;return JSON.parse(Q)}catch{return null}}function O3(Z,$,q,Q){try{localStorage.setItem(R1(Z,$,q),JSON.stringify(Q))}catch{}}function B3({sessionId:Z,revision:$,isReadOnly:q,draftPhase:Q,remoteAnnotations:J,children:Y}){let[X,G]=S0(()=>{return(p0(Z,$,Q)?.annotations??[]).map((E)=>({...E,source:E.source??"local"}))}),z=V8(()=>{if(!J||J.length===0)return X;let V=new Set(X.map((c)=>c.id)),E=J.filter((c)=>!V.has(c.id));return[...X,...E.map((c)=>({...c,source:"remote"}))]},[X,J]),[_,H]=S0(()=>{return p0(Z,$,Q)?.generalNote??""}),[U,W]=S0(null),[T,K]=S0(()=>{let V=p0(Z,$,Q);return V?.responses?new Map(V.responses):new Map}),[L,N]=S0(()=>{let V=p0(Z,$,Q);return V?.feedbackEntries?new Map(V.feedbackEntries):new Map}),S=C8(null);A8(()=>{if(q&&Q!=="next")return;if(S.current)clearTimeout(S.current);let V={annotations:X,generalNote:_,responses:Array.from(T.entries()),feedbackEntries:Array.from(L.entries())};if(Q==="next"){O3(Z,$,Q,V);return}return S.current=setTimeout(()=>O3(Z,$,Q,V),300),()=>{if(S.current)clearTimeout(S.current)}},[X,_,T,L,Z,$,q,Q]);let O=j1((V,E,c,P,x,f,o)=>{G((w)=>[...w,{id:V,snippet:E,note:c,createdAt:new Date().toISOString(),filePath:P,context:x,...f?.length?{images:f}:{},...o?{canvasFile:o}:{}}])},[]),R=j1((V,E,c)=>{O(L1(),V,E,c)},[O]),b=j1((V,E)=>{G((c)=>c.map((P)=>P.id===V?{...P,note:E}:P))},[]),M=j1((V)=>{R8(V),G((E)=>E.filter((c)=>c.id!==V)),W((E)=>E===V?null:E)},[]),j=j1((V,E)=>{G((c)=>c.map((P)=>P.id===V?{...P,images:[...P.images||[],E]}:P))},[]),g=j1((V,E)=>{G((c)=>c.map((P)=>P.id===V?{...P,images:(P.images||[]).filter((x)=>x!==E)}:P))},[]),C=j1((V,E)=>{K((c)=>{let P=new Map(c);return P.set(V,E),P})},[]),h=j1((V,E)=>{N((c)=>{let P=c.get(V);if(P&&P.markdown===E.markdown&&P.label===E.label&&P.required===E.required)return c;let x=new Map(c);return x.set(V,E),x})},[]),v=j1((V)=>{N((E)=>{if(!E.has(V))return E;let c=new Map(E);return c.delete(V),c})},[]),l=j1(()=>{for(let V of document.querySelectorAll("[data-annotation-id]"))F3(V);if(G([]),H(""),W(null),K(new Map),N(new Map),Q==="next")localStorage.removeItem(R1(Z,$,Q));else z0(localStorage,Z,$)},[Z,$,Q]);return D8(I8.Provider,{value:{annotations:z,addAnnotation:R,addAnnotationWithId:O,updateAnnotation:b,removeAnnotation:M,addAnnotationImage:j,removeAnnotationImage:g,generalNote:_,setGeneralNote:H,clearAll:l,activeAnnotationId:U,setActiveAnnotationId:W,responses:T,setResponse:C,feedbackEntries:L,setFeedbackEntry:h,removeFeedbackEntry:v},children:Y},void 0,!1,void 0,this)}function R8(Z){let $=document.querySelectorAll(`[data-annotation-id="${Z}"]`);for(let q of $)F3(q)}function F3(Z){let $=Z.parentNode;if(!$)return;let q=document.createTextNode(Z.textContent||"");$.replaceChild(q,Z),$.normalize()}import n0,{useEffect as $0,useState as w1,useRef as Z4,useContext as v3,useMemo as j0}from"react";import{createPortal as q4}from"react-dom";import{SessionContext as J4,CanvasFileCtx as Q4}from"#canvas/runtime";function a1(Z,$){let q=L3(Z,"before",60),Q=L3(Z,"after",60),J=E8(Z.startContainer,$);return{before:q,after:Q,hierarchy:J}}function L3(Z,$,q){let Q=k8($==="before"?Z.startContainer:Z.endContainer);if(!Q)return"";let J="";if($==="before"){let Y=document.createTreeWalker(Q,NodeFilter.SHOW_TEXT),X;while(X=Y.nextNode()){if(X===Z.startContainer){J+=(X.textContent||"").slice(0,Z.startOffset);break}if(X.parentElement?.hasAttribute("data-annotation-id"))continue;J+=X.textContent||""}if(J.length>q){J=J.slice(-q);let G=J.indexOf(" ");if(G>0)J=J.slice(G+1)}}else{let Y=document.createTreeWalker(Q,NodeFilter.SHOW_TEXT),X=!1,G;while(G=Y.nextNode()){if(G===Z.endContainer){J+=(G.textContent||"").slice(Z.endOffset),X=!0;continue}if(X){if(G.parentElement?.hasAttribute("data-annotation-id"))continue;J+=G.textContent||""}}if(J.length>q){J=J.slice(0,q);let z=J.lastIndexOf(" ");if(z>0)J=J.slice(0,z)}}return J.trim()}function k8(Z){let $=new Set(["DIV","P","LI","PRE","BLOCKQUOTE","SECTION","ARTICLE"]),q=Z.parentElement;while(q){if($.has(q.tagName))return q;q=q.parentElement}return null}function E8(Z,$){let q=[],Q=Z instanceof Element?Z:Z.parentElement;while(Q&&Q!==$){let J=Q.getAttribute?.("data-task-id");if(J){let Y=Q.querySelector(".font-semibold");if(Y)q.unshift(Y.textContent?.trim()||J)}if(Q.tagName==="DIV"&&Q.querySelector(":scope > button .font-heading, :scope > div .font-heading")){let Y=Q.querySelector(".font-heading");if(Y)q.unshift(Y.textContent?.trim()||"")}Q=Q.parentElement}return q}function V2(Z){let $=Z.snippet.trim(),q=Z.context,Q=$.length<30;if(q&&Q&&(q.before||q.after)){let J=[];if(q.before)J.push(`...${q.before} `);if(J.push(`**${$}**`),q.after)J.push(` ${q.after}...`);return J.join("")}return $}import{useEffect as l8,useRef as l0,useState as _0,useCallback as d0,useMemo as k3,useContext as r8}from"react";import{createPortal as i8}from"react-dom";function M3(Z,$){let J=$||document.body,Y=Z.getBoundingClientRect(),X=J.getBoundingClientRect(),G=J===document.body?window.scrollY:J.scrollTop,z=Y.bottom-X.top+G+8,_=Math.max(0,Math.min(Y.left-X.left,X.width-280-12));return J.style.position="relative",{style:{position:"absolute",top:`${z}px`,left:`${_}px`},parent:J}}import{useState as R2,useRef as D2,useCallback as D1,useEffect as c8}from"react";var P3={alg:"AES-GCM",v:1};async function y3(Z){let $=m8(Z);return crypto.subtle.importKey("raw",$,{name:"AES-GCM",length:256},!1,["encrypt","decrypt"])}async function g1(Z,$){let q=crypto.getRandomValues(new Uint8Array(12)),Q=new TextEncoder().encode($),J=await crypto.subtle.encrypt({name:"AES-GCM",iv:q},Z,Q),Y=new Uint8Array(q.byteLength+J.byteLength);return Y.set(q,0),Y.set(new Uint8Array(J),q.byteLength),x8(Y)}async function b0(Z,$){let q=S3($);if(q.byteLength<28)throw Error("Ciphertext too short");let Q=q.subarray(0,12),J=q.subarray(12),Y=await crypto.subtle.decrypt({name:"AES-GCM",iv:Q},Z,J);return new TextDecoder().decode(Y)}function x8(Z){let $="",q=32768;for(let Q=0;Q<Z.byteLength;Q+=q)$+=String.fromCharCode.apply(null,Array.from(Z.subarray(Q,Q+q)));return btoa($)}function S3(Z){let $=atob(Z),q=new Uint8Array($.length);for(let Q=0;Q<$.length;Q++)q[Q]=$.charCodeAt(Q);return q}function m8(Z){let $=Z.replace(/-/g,"+").replace(/_/g,"/")+"===".slice((Z.length+3)%4);return S3($)}function u8(){if(typeof window>"u")return null;let Z=window.location.hash.replace(/^#/,"");if(!Z)return null;for(let $ of Z.split("&")){let[q,Q]=$.split("=");if(q==="k"&&Q)return decodeURIComponent(Q)}return null}function g8(){if(typeof window<"u"&&window.__CANVAS_SHARE__?.shareId){let $=u8();return{isShared:!0,shareId:window.__CANVAS_SHARE__.shareId,encryptionKey:$?y3($):null}}return{isShared:!1,sessionId:typeof window<"u"?window.location.pathname.replace("/s/",""):""}}var $1=g8();function f8(){return $1.isShared&&$1.encryptionKey!==null}function v8(){if($1.isShared)return`/s/${$1.shareId}/meta`;return`/api/session/${$1.sessionId}/meta`}function h8(Z,$){let q=Z.replace(/\.jsx$/,".js");if($1.isShared)return`/s/${$1.shareId}/canvas/${encodeURIComponent(q)}`;let Q=$?`?rev=${$}&t=${Date.now()}`:`?t=${Date.now()}`;return`/api/session/${$1.sessionId}/canvas/${encodeURIComponent(q)}${Q}`}function b3(){if($1.isShared)return`/s/${$1.shareId}/upload`;return`/api/session/${$1.sessionId}/upload`}async function j3(){let Z=await fetch(v8());if(!Z.ok)throw Error(`meta ${Z.status}`);let $=await Z.json();if($.encryption&&$1.isShared&&$1.encryptionKey){let q=await $1.encryptionKey;if($.origin){let J={...$.origin};if(J.sessionId)J.sessionId=await b0(q,J.sessionId);if(J.label)J.label=await b0(q,J.label);$.origin=J}let Q=$.revisions;if(Array.isArray(Q)){for(let J of Q)if(J.label)try{J.label=await b0(q,J.label)}catch{}}}return $}async function w3(Z,$){let q=h8(Z,$);if(!f8())return import(q);let Q=await fetch(q);if(!Q.ok)throw Error(`canvas ${Q.status}`);let J=await Q.text(),Y=await $1.encryptionKey,X=await b0(Y,J),G=new Blob([X],{type:"application/javascript"}),z=URL.createObjectURL(G);try{return await import(z)}finally{setTimeout(()=>URL.revokeObjectURL(z),0)}}var A3="canvas-reviewer-identity";function I2(){try{let Z=localStorage.getItem(A3);if(!Z)return null;return JSON.parse(Z)}catch{return null}}function C3(Z){let $=I2();if(!$)$={id:crypto.randomUUID?.()||String(Date.now()),name:Z};else $.name=Z;return localStorage.setItem(A3,JSON.stringify($)),$}async function p8(Z,$){let q=await Promise.all(Z.annotations.map(async(Q)=>{let J={id:Q.id,createdAt:Q.createdAt,snippet:await g1($,String(Q.snippet??"")),note:await g1($,String(Q.note??""))};if(Q.filePath)J.filePath=await g1($,String(Q.filePath));if(Q.canvasFile)J.canvasFile=await g1($,String(Q.canvasFile));if(Q.context!==void 0&&Q.context!==null)J.context=await g1($,JSON.stringify(Q.context));if(Q.attachments)J.attachments=Q.attachments;return J}));return{author:{id:Z.author.id,name:await g1($,Z.author.name)},revision:Z.revision,annotations:q,...Z.generalNote?{generalNote:await g1($,Z.generalNote)}:{},encryption:P3}}async function V3(Z){if(!$1.isShared)throw Error("submitSharedFeedback called outside shared mode");let $=Z;if($1.encryptionKey){let Q=await $1.encryptionKey;$=await p8(Z,Q)}let q=await fetch(`/s/${$1.shareId}/feedback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify($)});if(!q.ok){let Q=await q.text().catch(()=>"");throw Error(`Feedback submission failed: ${q.status} ${Q}`)}}var M1=!$1.isShared,I3=!$1.isShared;import{jsxDEV as _1}from"react/jsx-dev-runtime";function R3(Z){if(Z.startsWith("/s/")||Z.startsWith("http://")||Z.startsWith("https://"))return Z;return`/api/uploads/${Z.split("/").pop()}`}async function d8(Z,$){let q=new FormData;q.append("image",$);try{let J=await(await fetch(b3(),{method:"POST",body:q})).json();if($1.isShared)return J.url||null;return J.path||null}catch{return null}}function c0({note:Z,onNoteChange:$,images:q,onAddImage:Q,onRemoveImage:J,sessionId:Y,placeholder:X="Add your note...",autoFocus:G=!1,autoResize:z=!1,readOnly:_=!1,onKeyDown:H,onTextareaClick:U,textareaRef:W,textareaClassName:T,textareaStyle:K,minHeight:L,attachButton:N="always",openFilePickerRef:S}){let[O,R]=R2(!1),[b,M]=R2(!1),[j,g]=R2(!1),C=D2(0),h=D2(null),v=D2(null),l=D1(()=>v.current?.click(),[]);if(S)S.current=l;let V=D1((D)=>{if(h.current=D,W)W.current=D;if(D&&z)y0(D,L)},[W,z,L]);c8(()=>{if(G&&h.current){let D=h.current;if(D.focus(),D.value)D.setSelectionRange(D.value.length,D.value.length)}},[G]);let E=D1(async(D)=>{if(!D.type.startsWith("image/"))return;M(!0);try{let a=await d8(Y,D);if(a)Q(a)}finally{M(!1)}},[Y,Q]),c=D1((D)=>{let a=D.clipboardData.items;for(let I of a)if(I.type.startsWith("image/")){D.preventDefault();let k=I.getAsFile();if(k)E(k);return}},[E]),P=D1((D)=>{if(D.preventDefault(),C.current++,C.current===1)R(!0)},[]),x=D1((D)=>{D.preventDefault()},[]),f=D1((D)=>{if(D.preventDefault(),C.current--,C.current===0)R(!1)},[]),o=D1((D)=>{D.preventDefault(),C.current=0,R(!1);for(let a of D.dataTransfer.files)if(a.type.startsWith("image/"))E(a)},[E]),w=D1((D)=>{if($(D.target.value),z)D.target.style.height="auto",D.target.style.height=(L?Math.max(L,D.target.scrollHeight):D.target.scrollHeight)+"px"},[$,z,L]),F="w-full bg-transparent text-[13px] font-body text-text-primary resize-none focus:outline-none leading-relaxed p-0 border-none",m={width:"100%",background:"transparent",border:"none",color:"var(--color-text-primary)",fontFamily:"'Inter', sans-serif",fontSize:"13px",lineHeight:"1.5",outline:"none",...z?{resize:"none",overflow:"hidden"}:{resize:"vertical"}},u=!_&&(N==="always"||N==="on-focus"&&j);return _1("div",{style:{position:"relative"},onDragEnter:_?void 0:P,onDragOver:_?void 0:x,onDragLeave:_?void 0:f,onDrop:_?void 0:o,children:[_1("textarea",{ref:V,value:Z,onChange:_?void 0:w,onPaste:_?void 0:c,onKeyDown:H,onClick:U,onFocus:()=>g(!0),onBlur:()=>{setTimeout(()=>g(!1),150)},readOnly:_,placeholder:X,className:T??F,style:K??m,rows:z?1:void 0},void 0,!1,void 0,this),!_&&_1("input",{ref:v,type:"file",accept:"image/*",multiple:!0,style:{display:"none"},onChange:(D)=>{let a=D.target.files;if(a)for(let I of a)E(I);D.target.value=""}},void 0,!1,void 0,this),(q.length>0||u)&&_1("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"6px",alignItems:"center"},children:[q.map((D)=>_1("div",{style:{position:"relative",width:"56px",height:"56px",borderRadius:"6px",overflow:"hidden",border:"1px solid var(--color-border-subtle)",flexShrink:0},children:[_1("img",{src:R3(D),alt:"",style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}},void 0,!1,void 0,this),!_&&_1("button",{onClick:(a)=>{a.stopPropagation(),J(D)},style:{position:"absolute",top:"2px",right:"2px",width:"16px",height:"16px",borderRadius:"50%",background:"rgba(0,0,0,0.6)",color:"white",border:"none",cursor:"pointer",fontSize:"11px",display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1,padding:0},title:"Remove image",children:"×"},void 0,!1,void 0,this)]},D,!0,void 0,this)),u&&_1(k2,{onClick:l},void 0,!1,void 0,this)]},void 0,!0,void 0,this),b&&_1("div",{style:{fontSize:"11px",color:"var(--color-text-tertiary)",fontFamily:"'Inter', sans-serif",marginTop:"4px"},children:"Uploading..."},void 0,!1,void 0,this),O&&_1("div",{style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",background:"var(--color-highlight-bg)",opacity:0.9,border:"2px dashed var(--color-highlight-border)",borderRadius:"6px",zIndex:10,pointerEvents:"none",fontSize:"12px",fontFamily:"'Inter', sans-serif",color:"var(--color-text-secondary)"},children:"Drop image"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function k2({onClick:Z,size:$=16}){return _1("button",{onClick:(q)=>{q.stopPropagation(),Z()},style:{width:`${$*2}px`,height:`${$*2}px`,borderRadius:"6px",border:"none",background:"transparent",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--color-text-tertiary)",flexShrink:0,transition:"color 0.15s"},title:"Attach image",onMouseEnter:(q)=>{q.currentTarget.style.color="var(--color-text-secondary)"},onMouseLeave:(q)=>{q.currentTarget.style.color="var(--color-text-tertiary)"},children:_1("svg",{width:$,height:$,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[_1("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"},void 0,!1,void 0,this),_1("circle",{cx:"8.5",cy:"8.5",r:"1.5"},void 0,!1,void 0,this),_1("polyline",{points:"21 15 16 10 5 21"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function D3({images:Z}){if(!Z.length)return null;return _1("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"6px"},children:Z.map(($)=>_1("div",{style:{width:"56px",height:"56px",borderRadius:"6px",overflow:"hidden",border:"1px solid var(--color-border-subtle)",flexShrink:0},children:_1("img",{src:R3($),alt:"",style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}},void 0,!1,void 0,this)},$,!1,void 0,this))},void 0,!1,void 0,this)}import{SessionContext as a8}from"#canvas/runtime";import{jsxDEV as G1,Fragment as s8}from"react/jsx-dev-runtime";function o8({anchorEl:Z,scrollContainer:$,onClose:q,ignoreSelector:Q,zIndex:J="50",padding:Y="12px",width:X="280px",children:G}){let z=l0(null),_=l0(q);_.current=q;let{style:H,parent:U}=M3(Z,$);return l8(()=>{let W=setTimeout(()=>{let T=(K)=>{if(z.current&&!z.current.contains(K.target)){if(Q&&K.target.closest?.(Q))return;_.current(),document.removeEventListener("mousedown",T)}};return document.addEventListener("mousedown",T),()=>document.removeEventListener("mousedown",T)},0);return()=>clearTimeout(W)},[Q]),i8(G1("div",{ref:z,style:{...H,zIndex:J,width:X,background:"var(--color-bg-elevated)",border:"1px solid var(--color-border-hover)",borderRadius:"8px",boxShadow:"0 4px 12px var(--color-shadow)",padding:Y,fontFamily:"'Inter', sans-serif"},children:G},void 0,!1,void 0,this),U)}var x3=[{label:"Clarity",items:["Unclear","Why?","Needs example","Missing context"]},{label:"Scope",items:["Overkill","Out of scope","Important","Risky"]},{label:"Action",items:["Simplify","Rethink","Expand on this","Skip this"]}],E3=x3.flatMap((Z)=>Z.items);function m3({anchorEl:Z,scrollContainer:$,snippet:q,truncateAt:Q=100,header:J,initialNote:Y="",initialImages:X,onConfirm:G,onCancel:z,onDelete:_}){let H=r8(a8),U=Y!==""||!!_,[W,T]=_0(Y),[K,L]=_0(X||[]),[N,S]=_0(null),[O,R]=_0(U),[b,M]=_0(!1),j=l0(null),g=l0(null),C=d0(()=>{if(W.trim()||K.length>0)G(W.trim(),K);else if(U&&_)_();else z()},[W,K,G,z,U,_]),h=d0(()=>{if(U){if(!W.trim()&&K.length===0&&_){_(),z();return}G(W,K);return}z()},[W,K,U,G,z,_]),v=!U,l=W.trim().length>0?E3.filter((I)=>I.toLowerCase().startsWith(W.trim().toLowerCase())):E3,V=!v||O?[]:l.length===1&&l[0].toLowerCase()===W.trim().toLowerCase()?[]:l,E=new Set(V),c=x3.map((I)=>({label:I.label,items:I.items.filter((k)=>E.has(k))})).filter((I)=>I.items.length>0),P=c.map((I)=>I.items),x=P.flat(),f=k3(()=>{if(N===null)return 0;let I=0;for(let k=0;k<P.length;k++){if(N<I+P[k].length)return k;I+=P[k].length}return 0},[N,P]),o=k3(()=>{if(N===null)return 0;let I=0;for(let k=0;k<f;k++)I+=P[k].length;return N-I},[N,f,P]),w=(I,k)=>{let Z1=0;for(let Y1=0;Y1<I;Y1++)Z1+=P[Y1].length;return Z1+k},[F,m]=_0(W);if(W!==F)m(W),S(null),R(U);let u=d0((I)=>{T(I)},[]),D=q.length>Q?q.slice(0,Q)+"...":q,a=d0((I)=>{if(x.length>0&&(I.key==="ArrowDown"||I.key==="ArrowUp"||I.key==="ArrowLeft"||I.key==="ArrowRight")){if(I.preventDefault(),N===null){S(0);return}if(I.key==="ArrowDown"){let k=Math.min(o+1,P[f].length-1);S(w(f,k))}else if(I.key==="ArrowUp"){let k=Math.max(o-1,0);S(w(f,k))}else if(I.key==="ArrowRight"){let k=Math.min(f+1,P.length-1),Z1=Math.min(o,P[k].length-1);S(w(k,Z1))}else if(I.key==="ArrowLeft"){let k=Math.max(f-1,0),Z1=Math.min(o,P[k].length-1);S(w(k,Z1))}return}if(N!==null&&x.length>0){if(I.key==="Tab"){I.preventDefault(),u(x[N]);return}if(I.key==="Enter"&&!I.shiftKey){I.preventDefault(),G(x[N],K);return}}if(I.key==="Enter"&&!I.shiftKey){I.preventDefault(),C();return}if(I.key==="Escape")if(x.length>0&&!O)R(!0);else if(U)h();else z()},[x,N,o,f,P,w,u,G,K,C,O,U,h,z]);return G1(o8,{anchorEl:Z,scrollContainer:$,onClose:U?h:z,ignoreSelector:U?"[data-annotation-id]":void 0,zIndex:U?"60":"50",padding:U?"10px 12px":"12px",width:"420px",children:[!U&&(J??G1("div",{style:{fontSize:"11px",color:"var(--color-text-tertiary)",fontStyle:"italic",marginBottom:"8px",lineHeight:"1.4",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden"},children:["“",D,"”"]},void 0,!0,void 0,this)),G1(c0,{note:W,onNoteChange:T,images:K,onAddImage:(I)=>L((k)=>[...k,I]),onRemoveImage:(I)=>L((k)=>k.filter((Z1)=>Z1!==I)),sessionId:H,autoFocus:!0,autoResize:U,textareaRef:j,onKeyDown:a,attachButton:"none",openFilePickerRef:g,textareaStyle:U?{width:"100%",background:"transparent",border:"none",color:"var(--color-text-primary)",fontFamily:"'Inter', sans-serif",fontSize:"13px",lineHeight:"1.5",resize:"none",outline:"none",overflow:"hidden"}:{width:"100%",minHeight:"60px",background:"transparent",border:"none",color:"var(--color-text-primary)",fontFamily:"'Inter', sans-serif",fontSize:"13px",lineHeight:"1.5",resize:"vertical",outline:"none"},placeholder:"Add your note..."},void 0,!1,void 0,this),G1("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginTop:U?"6px":"8px"},children:[G1(k2,{onClick:()=>g.current?.(),size:14},void 0,!1,void 0,this),G1("div",{style:{flex:1}},void 0,!1,void 0,this),U?G1("button",{onClick:()=>{if(_)_();z()},onMouseEnter:()=>M(!0),onMouseLeave:()=>M(!1),style:{fontSize:"11px",color:b?"var(--color-accent-red)":"var(--color-text-tertiary)",background:"none",border:"none",cursor:"pointer",padding:"2px 0",fontFamily:"'Inter', sans-serif"},children:"Delete"},void 0,!1,void 0,this):G1(s8,{children:[G1("button",{onClick:z,style:{fontSize:"11px",color:"var(--color-text-tertiary)",background:"none",border:"none",cursor:"pointer",padding:"4px 12px",fontFamily:"'Inter', sans-serif"},children:"Cancel"},void 0,!1,void 0,this),G1("button",{onClick:C,style:{fontSize:"11px",fontWeight:500,padding:"4px 12px",borderRadius:"6px",background:"var(--color-highlight-bg)",color:"var(--color-text-primary)",border:"1px solid var(--color-highlight-border)",cursor:"pointer",fontFamily:"'Inter', sans-serif"},children:"Add"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),x.length>0&&G1("div",{style:{marginTop:"6px",borderTop:"1px solid var(--color-border-subtle)",paddingTop:"8px",display:"flex",gap:"4px"},children:c.map((I)=>G1("div",{style:{flex:1},children:[G1("div",{style:{fontSize:"10px",fontWeight:600,color:"var(--color-text-disabled)",textTransform:"uppercase",letterSpacing:"0.05em",padding:"2px 6px",marginBottom:"2px",fontFamily:"'Inter', sans-serif"},children:I.label},void 0,!1,void 0,this),I.items.map((k)=>{let Z1=x.indexOf(k);return G1("div",{onMouseDown:(Y1)=>{Y1.preventDefault(),Y1.stopPropagation(),u(k)},onMouseEnter:()=>S(Z1),style:{padding:"3px 6px",fontSize:"12px",borderRadius:"4px",fontFamily:"'Inter', sans-serif",color:Z1===N?"var(--color-text-primary)":"var(--color-text-secondary)",background:Z1===N?"var(--color-highlight-selected)":"transparent",cursor:"pointer"},children:[G1("span",{style:{fontWeight:500},children:k.slice(0,W.trim().length)},void 0,!1,void 0,this),k.slice(W.trim().length)]},k,!0,void 0,this)})]},I.label,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function G0({anchorEl:Z,scrollContainer:$,snippet:q,truncateAt:Q,header:J,onAdd:Y,onCancel:X}){return G1(m3,{anchorEl:Z,scrollContainer:$,snippet:q,truncateAt:Q,header:J,onConfirm:(G,z)=>Y(G,z),onCancel:X},void 0,!1,void 0,this)}function U0({anchorEl:Z,scrollContainer:$,initialNote:q,initialImages:Q,onUpdate:J,onDelete:Y,onClose:X}){return G1(m3,{anchorEl:Z,scrollContainer:$,snippet:"",initialNote:q,initialImages:Q,onConfirm:(G,z)=>{J(G,z),X()},onDelete:Y,onCancel:X},void 0,!1,void 0,this)}import{useEffect as s0,useState as g3,useRef as t1,useCallback as f3}from"react";function s1(Z,$){let q=[],Q=t8(Z);for(let J of Q){let Y=document.createRange();if(Y.selectNodeContents(J),J===Z.startContainer)Y.setStart(J,Z.startOffset);if(J===Z.endContainer)Y.setEnd(J,Z.endOffset);let X=Y.toString();if(!X||!X.trim())continue;let G=document.createElement("mark");G.setAttribute("data-annotation-id",$);try{Y.surroundContents(G)}catch{let z=Y.extractContents();G.appendChild(z),Y.insertNode(G)}q.push(G)}return q}function t8(Z){let $=[],q=Z.commonAncestorContainer;if(q.nodeType===Node.TEXT_NODE)return $.push(q),$;let Q=document.createTreeWalker(q,NodeFilter.SHOW_TEXT),J;while(J=Q.nextNode()){let Y=J.parentElement;if(Y?.classList.contains("select-none"))continue;if(Y?.closest("[data-annotation-id]"))continue;if(Z.intersectsNode(J))$.push(J)}return $}function o1(Z,$){let q=document.querySelectorAll(`[data-annotation-id="${Z}"]`);for(let Q of q)Q.classList.toggle("mark-active",$)}function r0(Z,$){if($!=null&&$!==Z)o1($,!1);if(Z!=null)o1(Z,!0)}function i0(Z,$){let q=document.querySelectorAll(`[data-annotation-id="${Z}"]`);for(let Q of q)Q.setAttribute("data-annotation-id",$)}function a0(Z,$){for(let q of $){if(Z.querySelector(`[data-annotation-id="${q.id}"]`))continue;let Q=q.snippet;if(!Q)continue;let{fullText:J,textNodes:Y}=n8(Z),X=[],G=0;while(!0){let T=J.indexOf(Q,G);if(T===-1)break;X.push(T),G=T+1}if(X.length===0)continue;let z=X[0];if(X.length>1&&q.context){let T=-1;for(let K of X){let L=0;if(q.context.before){let N=J.slice(Math.max(0,K-80),K);if(N.includes(q.context.before))L+=2;else if(q.context.before.length>10&&N.includes(q.context.before.slice(-10)))L+=1}if(q.context.after){let N=J.slice(K+Q.length,K+Q.length+80);if(N.includes(q.context.after))L+=2;else if(q.context.after.length>10&&N.includes(q.context.after.slice(0,10)))L+=1}if(L>T)T=L,z=K}}let _=z,H=z+Q.length,U=u3(Y,_),W=u3(Y,H);if(!U||!W)continue;try{let T=document.createRange();T.setStart(U.node,U.offset),T.setEnd(W.node,W.offset),s1(T,q.id)}catch{}}}function n8(Z){let $=[],q="",Q=document.createTreeWalker(Z,NodeFilter.SHOW_TEXT),J;while(J=Q.nextNode()){let Y=J.parentElement;if(Y?.classList.contains("select-none"))continue;if(Y?.closest("[data-annotation-id]"))continue;$.push({node:J,start:q.length}),q+=J.textContent||""}return{fullText:q,textNodes:$}}function u3(Z,$){for(let q=Z.length-1;q>=0;q--)if(Z[q].start<=$){let Q=$-Z[q].start,J=Z[q].node.textContent?.length??0;if(Q<=J)return{node:Z[q].node,offset:Q}}return null}function o0(Z){let $=document.querySelectorAll(`[data-annotation-id="${Z}"]`);for(let q of $){let Q=q.parentNode;if(!Q)continue;while(q.firstChild)Q.insertBefore(q.firstChild,q);Q.removeChild(q),Q.normalize()}}import{jsxDEV as E2,Fragment as e8}from"react/jsx-dev-runtime";function n1(Z){let{containerRef:$,restoreKey:q,restoreAnnotations:Q,extractContext:J,filePath:Y,canvasFile:X,scrollContainer:G}=Z,{annotations:z,addAnnotationWithId:_,removeAnnotation:H,updateAnnotation:U,addAnnotationImage:W,removeAnnotationImage:T,activeAnnotationId:K,setActiveAnnotationId:L}=X1(),[N,S]=g3(null),[O,R]=g3(null),b=t1(J);b.current=J;let M=t1(Y);M.current=Y;let j=t1(X);j.current=X;let g=t1(_);g.current=_;let C=t1(K);C.current=K;let h=t1(L);h.current=L;let v=Q.length;s0(()=>{if(!$.current)return;let P=setTimeout(()=>{if($.current)a0($.current,Q)},50);return()=>clearTimeout(P)},[q,v]);let l=t1(null);s0(()=>{r0(K,l.current),l.current=K},[K]),s0(()=>{let P=$.current;if(!P)return;let x=(w)=>{let F=w.target.closest("[data-annotation-id]");if(!F)return;w.stopPropagation();let m=F.getAttribute("data-annotation-id");if(m===C.current)S({anchorEl:F,annId:m});else h.current(m)},f=(w)=>{let F=w.target.closest("[data-annotation-id]");if(F)h.current(F.getAttribute("data-annotation-id"))},o=(w)=>{let F=w.target.closest("[data-annotation-id]"),m=w.relatedTarget?.closest?.("[data-annotation-id]");if(F&&!m&&!document.getElementById("ann-inline-popover"))h.current(null)};return P.addEventListener("click",x),P.addEventListener("mouseover",f),P.addEventListener("mouseout",o),()=>{P.removeEventListener("click",x),P.removeEventListener("mouseover",f),P.removeEventListener("mouseout",o)}},[q]),s0(()=>{let P=()=>V();return document.addEventListener("mouseup",P),()=>document.removeEventListener("mouseup",P)},[]);let V=f3(()=>{let P=window.getSelection();if(!P||P.isCollapsed||!P.toString().trim())return;if(!$.current)return;let x=P.getRangeAt(0);if(!$.current.contains(x.startContainer))return;if(x.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let f=P.toString().trim();if(f.length<2)return;let o=b.current(x),w=x.cloneRange(),F=`__pending_${Date.now()}`;try{s1(w,F)}catch{}window.getSelection()?.removeAllRanges();let m=document.querySelectorAll(`[data-annotation-id="${F}"]`),u=m[m.length-1];if(!u)return;R({anchorEl:u,tempId:F,snippet:f,ctx:o})},[]),E=f3((P,x,f,o)=>{R({anchorEl:P,tempId:x,snippet:f,ctx:o})},[]);return{popovers:E2(e8,{children:[N&&(()=>{let P=z.find((x)=>x.id===N.annId);if(!P)return null;return E2(U0,{anchorEl:N.anchorEl,scrollContainer:G,initialNote:P.note,initialImages:P.images,onUpdate:(x,f)=>{U(N.annId,x);let o=P.images||[];for(let w of f)if(!o.includes(w))W(N.annId,w);for(let w of o)if(!f.includes(w))T(N.annId,w)},onDelete:()=>{H(N.annId),L(null)},onClose:()=>S(null)},void 0,!1,void 0,this)})(),O&&E2(G0,{anchorEl:O.anchorEl,scrollContainer:G,snippet:O.snippet,truncateAt:80,onAdd:(P,x)=>{let f=L1();i0(O.tempId,f),g.current(f,O.snippet,P,M.current,O.ctx,x,j.current),R(null)},onCancel:()=>{o0(O.tempId),R(null)}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),openCreatePopover:E,isPopoverOpen:!!(N||O)}}import{createContext as $4}from"react";var t0=$4(()=>{});import{jsxDEV as q1,Fragment as _4}from"react/jsx-dev-runtime";var m2="[data-md='item'], [data-md='section'], [data-md='table'] tbody tr, [data-md='callout'], [data-md='note'], [data-md='checklist-item'], [data-md='choice-option'], [data-md='multichoice-option'], [data-md='userinput'], [data-md='rangeinput'], [data-md='image']",x2="[data-md='item'], [data-md='section'], [data-md='table'] tbody tr, [data-md='callout'], [data-md='note'], [data-md='checklist-item'], [data-md='image']";class h3 extends n0.Component{state={error:null};static getDerivedStateFromError(Z){return{error:Z}}componentDidCatch(Z,$){this.props.reportError({revision:this.props.revision,filename:this.props.filename,message:Z.message,...Z.stack?{stack:Z.stack}:{},...$.componentStack?{componentStack:$.componentStack}:{}})}render(){if(!this.state.error)return this.props.children;return q1(p3,{message:this.state.error.message},void 0,!1,void 0,this)}}function p3({message:Z}){return q1("div",{className:"bg-accent-red-muted rounded-lg p-5",children:[q1("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Canvas render failed"},void 0,!1,void 0,this),q1("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:Z},void 0,!1,void 0,this),q1("p",{className:"text-meta font-body text-text-tertiary mt-3",children:"The error was sent back to the canvas author."},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function w0({revision:Z,filename:$}){let q=v3(J4),Q=v3(t0),[J,Y]=w1(null),[X,G]=w1(null),[z,_]=w1(!0),H=Z4(null),{annotations:U,addAnnotationWithId:W,removeAnnotation:T,updateAnnotation:K,addAnnotationImage:L,removeAnnotationImage:N,activeAnnotationId:S,setActiveAnnotationId:O}=X1(),R=j0(()=>U.filter((w)=>!w.filePath&&(!w.canvasFile||w.canvasFile===$)),[U,$]),[b,M]=w1(null),[j,g]=w1(null),[C,h]=w1(null),[v,l]=w1(null),[V,E]=w1(!1);$0(()=>{_(!0),G(null),l(null),w3($,Z).then((w)=>{Y(()=>w.default),_(!1)}).catch((w)=>{let F=w instanceof Error?w:Error(String(w));G(F.message),_(!1),Q({revision:Z,filename:$,message:F.message,...F.stack?{stack:F.stack}:{}})})},[q,Z,$,Q]);let c=document.getElementById("plan-scroll-container"),{popovers:P,isPopoverOpen:x}=n1({containerRef:H,restoreKey:J,restoreAnnotations:R,extractContext:(w)=>a1(w,H.current),canvasFile:$,scrollContainer:c}),f=j0(()=>{let w=new Map;for(let F of R)if(F.snippet.startsWith("["))w.set(F.snippet,F.id);return w},[R]);$0(()=>{let w=H.current;if(!w)return;let F=(u)=>{if(C||x)return;let D=u.target;if(D.closest("[data-block-comment-btn]"))return;E(!1);let a=D.closest(m2);if(a&&w.contains(a)){let Z1=e1(w).indexOf(a);l(Z1>=0?Z1:null)}else l(null);let I=D.closest(x2);if(I&&w.contains(I)){g(I);let k=K0(I),Z1=k?f.get(k):void 0;if(Z1&&Z1!==S)O(Z1)}else g(null)},m=(u)=>{if(C||x)return;if(u.relatedTarget?.closest("[data-block-comment-btn]"))return;g(null),O(null)};return w.addEventListener("mousemove",F),w.addEventListener("mouseleave",m),()=>{w.removeEventListener("mousemove",F),w.removeEventListener("mouseleave",m)}},[J,C,x,f,S]),$0(()=>{let w=(F)=>{let m=F.target.tagName;if(m==="INPUT"||m==="TEXTAREA"||F.target.isContentEditable)return;if(C||x)return;let u=H.current;if(!u)return;if(F.key==="ArrowDown"){F.preventDefault(),E(!0);let D=e1(u);if(D.length===0)return;l((a)=>{if(a===null)return 0;return Math.min(a+1,D.length-1)})}else if(F.key==="ArrowUp"){F.preventDefault(),E(!0);let D=e1(u);if(D.length===0)return;l((a)=>{if(a===null)return D.length-1;return Math.max(a-1,0)})}else if(F.key==="a"||F.key==="A"){if(v===null||!u)return;F.preventDefault();let a=e1(u)[v];if(!a)return;let I=K0(a);if(!I)return;let k=f.get(I);if(k)O(k),h({anchorEl:a,snippet:I,annId:k});else h({anchorEl:a,snippet:I})}else if(F.key===" "||F.key==="Enter"){if(v===null)return;let a=e1(u)[v];if(!a)return;let I=a.getAttribute("data-md");if(I==="choice-option"||I==="multichoice-option")F.preventDefault(),a.dispatchEvent(new CustomEvent("kb-select",{bubbles:!0}));else if(I==="userinput"){F.preventDefault();let k=a.querySelector("textarea");if(k){k.focus();let Z1=(Y1)=>{if(Y1.key==="Escape")Y1.preventDefault(),k.blur(),E(!0)};k.addEventListener("keydown",Z1),k.addEventListener("blur",()=>k.removeEventListener("keydown",Z1),{once:!0})}}else if(I==="rangeinput"){F.preventDefault();let k=a.querySelector("input[type='range']");if(k){k.focus();let Z1=(Y1)=>{if(Y1.key==="Escape"||Y1.key==="ArrowUp"||Y1.key==="ArrowDown")Y1.preventDefault(),k.blur(),E(!0)};k.addEventListener("keydown",Z1),k.addEventListener("blur",()=>k.removeEventListener("keydown",Z1),{once:!0})}}}else if(F.key==="Escape")l(null),E(!1),O(null)};return document.addEventListener("keydown",w),()=>document.removeEventListener("keydown",w)},[v,C,x,f]),$0(()=>{let w=H.current;if(!w||v===null||!V)return;let m=e1(w)[v];if(!m)return;m.style.outline="2px solid var(--color-accent-blue)",m.style.outlineOffset="-2px",m.style.borderRadius="8px",m.scrollIntoView({block:"nearest",behavior:"smooth"});let u=K0(m),D=u?f.get(u):void 0;if(D)O(D);return()=>{m.style.outline="",m.style.outlineOffset="",m.style.borderRadius=""}},[v,V,f]);let o=j0(()=>J?q1(J,{},void 0,!1,void 0,this):null,[J]);if(z)return q1("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-body",children:"Loading canvas..."},void 0,!1,void 0,this);if(X)return q1(p3,{message:X},void 0,!1,void 0,this);if(!J)return q1("div",{className:"text-text-tertiary text-center py-8 font-body text-body",children:"No canvas loaded"},void 0,!1,void 0,this);return q1(Q4.Provider,{value:$,children:[q1("div",{ref:H,className:"plan-content plan-updated",children:q1(h3,{revision:Z,filename:$,reportError:Q,children:o},`${Z}:${$}`,!1,void 0,this)},void 0,!1,void 0,this),b&&q1(z4,{note:b.note,onSave:(w)=>{K(b.id,w),M(null)},onCancel:()=>M(null)},void 0,!1,void 0,this),P,q1(Y4,{containerRef:H,hoveredBlock:j,focusedBlockIndex:v,blockPopover:C,blockAnnotationMap:f,activeAnnotationId:S,onOpen:(w,F,m)=>{if(m)O(m),h({anchorEl:w,snippet:F,annId:m});else h({anchorEl:w,snippet:F})}},void 0,!1,void 0,this),C&&!C.annId&&q1(G0,{anchorEl:C.anchorEl,scrollContainer:c,snippet:C.snippet,truncateAt:80,onAdd:(w,F)=>{let m=L1();W(m,C.snippet,w,void 0,void 0,F,$),h(null)},onCancel:()=>h(null)},void 0,!1,void 0,this),C?.annId&&(()=>{let w=R.find((F)=>F.id===C.annId);if(!w)return null;return q1(U0,{anchorEl:C.anchorEl,scrollContainer:c,initialNote:w.note,initialImages:w.images,onUpdate:(F,m)=>{K(C.annId,F);let u=w.images||[];for(let D of m)if(!u.includes(D))L(C.annId,D);for(let D of u)if(!m.includes(D))N(C.annId,D)},onDelete:()=>{T(C.annId),O(null),h(null)},onClose:()=>h(null)},void 0,!1,void 0,this)})()]},void 0,!0,void 0,this)}function e1(Z){return Array.from(Z.querySelectorAll(m2))}function K0(Z){let $=Z.getAttribute("data-md");if($==="item"){let q=Z.getAttribute("data-md-label");return q?`[Item] ${q}`:null}if($==="section"){let q=Z.getAttribute("data-md-title");return q?`[Section] ${q}`:null}if($==="callout"){let q=Z.getAttribute("data-md-type")||"info",Q=Z.textContent?.trim().slice(0,60)||"Callout";return`[Callout:${q}] ${Q}`}if($==="note")return`[Note] ${Z.textContent?.trim().slice(0,60)||"Note"}`;if(Z.tagName==="TR"){let q=Array.from(Z.querySelectorAll("td")).map((Q)=>Q.textContent?.trim()).filter(Boolean);return q.length?`[Row] ${q.join(" | ")}`:null}if($==="checklist-item"){let q=Z.getAttribute("data-md-label");return q?`[Checklist] ${q}`:null}if($==="choice-option"||$==="multichoice-option"){let q=Z.getAttribute("data-md-label");return q?`[Option] ${q}`:null}if($==="userinput"){let q=Z.getAttribute("data-md-label");return q?`[Input] ${q}`:null}if($==="rangeinput"){let q=Z.getAttribute("data-md-label");return q?`[Range] ${q}`:null}if($==="image"){let q=Z.getAttribute("data-md-src");return q?`[Image] ${q}`:null}return null}function Y4({containerRef:Z,hoveredBlock:$,focusedBlockIndex:q,blockPopover:Q,blockAnnotationMap:J,activeAnnotationId:Y,onOpen:X}){let[G,z]=w1([]);$0(()=>{let T=Z.current;if(!T||J.size===0){z([]);return}let K=[];for(let L of T.querySelectorAll(x2)){let N=K0(L);if(N&&J.has(N))K.push(L)}z(K)},[J,Z.current]);let[_,H]=w1(null);$0(()=>{if(!Y||!Z.current){H(null);return}for(let T of Z.current.querySelectorAll(m2)){let K=K0(T);if(K&&J.get(K)===Y){H(T);return}}H(null)},[Y,J]),$0(()=>{if(!_)return;return _.style.boxShadow="inset 0 0 0 1.5px var(--color-highlight-bg)",_.style.borderRadius="8px",()=>{_.style.boxShadow="",_.style.borderRadius=""}},[_]);let U=j0(()=>{if(q===null||!Z.current)return null;let T=e1(Z.current)[q];if(!T)return null;return T.matches(x2)?T:null},[q,Z.current]),W=j0(()=>{let T=new Set(G);if($)T.add($);if(U)T.add(U);if(Q?.anchorEl)T.add(Q.anchorEl);return Array.from(T)},[G,$,U,Q]);return q1(_4,{children:W.map((T)=>q1(X4,{block:T,isHovered:T===$||T===U||T===Q?.anchorEl,blockAnnotationMap:J,activeAnnotationId:Y,onOpen:X},T.getAttribute("data-task-id")||T.getAttribute("data-md-title")||T.textContent?.slice(0,30)||"block",!1,void 0,this))},void 0,!1,void 0,this)}function X4({block:Z,isHovered:$,blockAnnotationMap:q,activeAnnotationId:Q,onOpen:J}){let Y=K0(Z);if(!Y)return null;let X=q.get(Y),G=!!X;return q4(q1("button",{"data-block-comment-btn":!0,onClick:(_)=>{_.stopPropagation(),J(_.currentTarget,Y,X)},className:`absolute top-1 right-1 z-10 w-6 h-6 flex items-center justify-center rounded transition-all duration-150 ${G?X===Q?"text-accent-amber bg-accent-amber-muted":"text-accent-amber opacity-60 hover:opacity-100":$?"text-text-disabled hover:text-text-tertiary opacity-50 hover:opacity-100":"text-text-disabled opacity-0 group-hover/section:opacity-20 hover:!opacity-80"}`,title:G?"Edit annotation":"Add annotation",children:q1("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:G?"currentColor":"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:q1("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),Z)}function z4({note:Z,onSave:$,onCancel:q}){let[Q,J]=n0.useState(Z),Y=n0.useRef(null);return n0.useEffect(()=>{Y.current?.focus(),Y.current?.select()},[]),q1("div",{className:"fixed inset-0 z-50 bg-black/40 flex items-center justify-center",onClick:q,children:q1("div",{className:"bg-bg-elevated border border-border-hover rounded-lg shadow-md p-4 w-80",onClick:(X)=>X.stopPropagation(),children:[q1("div",{className:"text-tiny uppercase tracking-widest text-text-tertiary font-body mb-2",children:"Edit annotation"},void 0,!1,void 0,this),q1("textarea",{ref:Y,value:Q,onChange:(X)=>J(X.target.value),className:"w-full bg-transparent border-none text-body font-body text-text-primary resize-vertical focus:outline-none min-h-[60px]",onKeyDown:(X)=>{if(X.key==="Enter"&&(X.ctrlKey||X.metaKey))$(Q.trim());if(X.key==="Escape")q()}},void 0,!1,void 0,this),q1("div",{className:"flex justify-end gap-2 mt-2",children:[q1("button",{onClick:q,className:"text-meta text-text-tertiary font-body px-3 py-1",children:"Cancel"},void 0,!1,void 0,this),q1("button",{onClick:()=>$(Q.trim()),className:"text-meta font-medium font-body px-3 py-1 rounded-md bg-highlight-bg text-text-primary border border-highlight-border",children:"Save"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}import L4,{useRef as i3,useEffect as q2,useCallback as h2,useState as v1,useContext as J2,useMemo as M4}from"react";function A0(Z,$,q,Q,J){let Y=[],X=Z.filter((T)=>T.source!=="remote"||J&&J.has(T.id)),G=X.filter((T)=>T.filePath===T1),z=X.filter((T)=>!T.filePath),_=X.filter((T)=>T.filePath&&T.filePath!==T1),H=q?Array.from(q.values()).filter((T)=>g2(T)):[],U=Q?Array.from(Q.values()).filter((T)=>T.markdown.trim()):[];if(H.length>0||U.length>0){Y.push("## Responses"),Y.push("");for(let T of H)Y.push(K4(T));for(let T of U)Y.push(T.markdown.trim()),Y.push("")}if(G.length>0){Y.push("## Annotations on agent response"),Y.push("");for(let T of G)Y.push(u2(T))}if(z.length>0){Y.push("## Canvas annotations"),Y.push("");let T=new Map;for(let N of z){let S=N.canvasFile||"";if(!T.has(S))T.set(S,[]);T.get(S).push(N)}let K=[...T.keys()].sort(),L=K.length>1||K.length===1&&K[0]!=="";for(let N of K){let S=T.get(N);if(L&&N)Y.push(`### ${N.replace(/\.jsx$/,"")}`),Y.push("");let O=H4(S);Y.push(c3(O))}}if(_.length>0){let T={};for(let K of _){let L=K.filePath;if(!T[L])T[L]=[];T[L].push(K)}Y.push("## File annotations"),Y.push("");for(let[K,L]of Object.entries(T)){Y.push(`### ${K}`),Y.push("");for(let N of L)Y.push(u2(N))}}if($.trim())Y.push("## General notes"),Y.push(""),Y.push($.trim()),Y.push("");return Y.join(`
|
|
60
|
-
`).
|
|
61
|
-
`
|
|
62
|
-
`)}function u2(Z){let $=[],q=Z.snippet.trim(),Q=Z.context,J=Q?.lineStart!=null;if(Z.filePath&&J){let Y=Q.lineStart,X=Q.lineEnd??Y,G=q.split(`
|
|
63
|
-
`);if(q.length<30&&Y===X&&(Q.before||Q.after)){let _=V2(Z);$.push(`> L${Y}: ${_}`)}else if(G.length<=6)for(let _=0;_<G.length;_++)$.push(`> ${Y+_} | ${G[_]}`);else{for(let _=0;_<3;_++)$.push(`> ${Y+_} | ${G[_]}`);$.push(`> ... (${G.length} lines)`);for(let _=G.length-3;_<G.length;_++)$.push(`> ${Y+_} | ${G[_]}`)}}else{let Y=V2(Z);if(q.split(`
|
|
64
|
-
`).length<=3)$.push(`> ${Y.split(`
|
|
53
|
+
`+t+`</thead>
|
|
54
|
+
`+r+`</table>
|
|
55
|
+
`}tablerow({text:e}){return`<tr>
|
|
56
|
+
${e}</tr>
|
|
57
|
+
`}tablecell(e){let t=this.parser.parseInline(e.tokens),n=e.header?"th":"td";return(e.align?`<${n} align="${e.align}">`:`<${n}>`)+t+`</${n}>
|
|
58
|
+
`}strong({tokens:e}){return`<strong>${this.parser.parseInline(e)}</strong>`}em({tokens:e}){return`<em>${this.parser.parseInline(e)}</em>`}codespan({text:e}){return`<code>${Le(e,!0)}</code>`}br(e){return"<br>"}del({tokens:e}){return`<del>${this.parser.parseInline(e)}</del>`}link({href:e,title:t,tokens:n}){let r=this.parser.parseInline(n),o=Zo(e);if(o===null)return r;e=o;let i='<a href="'+e+'"';return t&&(i+=' title="'+Le(t)+'"'),i+=">"+r+"</a>",i}image({href:e,title:t,text:n,tokens:r}){r&&(n=this.parser.parseInline(r,this.parser.textRenderer));let o=Zo(e);if(o===null)return Le(n);e=o;let i=`<img src="${e}" alt="${Le(n)}"`;return t&&(i+=` title="${Le(t)}"`),i+=">",i}text(e){return"tokens"in e&&e.tokens?this.parser.parseInline(e.tokens):("escaped"in e)&&e.escaped?e.text:Le(e.text)}},no=class{strong({text:e}){return e}em({text:e}){return e}codespan({text:e}){return e}del({text:e}){return e}html({text:e}){return e}text({text:e}){return e}link({text:e}){return""+e}image({text:e}){return""+e}br(){return""}checkbox({raw:e}){return e}},Re=class e{options;renderer;textRenderer;constructor(t){this.options=t||at,this.options.renderer=this.options.renderer||new pn,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new no}static parse(t,n){return new e(n).parse(t)}static parseInline(t,n){return new e(n).parseInline(t)}parse(t){this.renderer.parser=this;let n="";for(let r=0;r<t.length;r++){let o=t[r];if(this.options.extensions?.renderers?.[o.type]){let s=o,l=this.options.extensions.renderers[s.type].call({parser:this},s);if(l!==!1||!["space","hr","heading","code","table","blockquote","list","html","def","paragraph","text"].includes(s.type)){n+=l||"";continue}}let i=o;switch(i.type){case"space":{n+=this.renderer.space(i);break}case"hr":{n+=this.renderer.hr(i);break}case"heading":{n+=this.renderer.heading(i);break}case"code":{n+=this.renderer.code(i);break}case"table":{n+=this.renderer.table(i);break}case"blockquote":{n+=this.renderer.blockquote(i);break}case"list":{n+=this.renderer.list(i);break}case"checkbox":{n+=this.renderer.checkbox(i);break}case"html":{n+=this.renderer.html(i);break}case"def":{n+=this.renderer.def(i);break}case"paragraph":{n+=this.renderer.paragraph(i);break}case"text":{n+=this.renderer.text(i);break}default:{let s='Token with "'+i.type+'" type was not found.';if(this.options.silent)return console.error(s),"";throw Error(s)}}}return n}parseInline(t,n=this.renderer){this.renderer.parser=this;let r="";for(let o=0;o<t.length;o++){let i=t[o];if(this.options.extensions?.renderers?.[i.type]){let l=this.options.extensions.renderers[i.type].call({parser:this},i);if(l!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(i.type)){r+=l||"";continue}}let s=i;switch(s.type){case"escape":{r+=n.text(s);break}case"html":{r+=n.html(s);break}case"link":{r+=n.link(s);break}case"image":{r+=n.image(s);break}case"checkbox":{r+=n.checkbox(s);break}case"strong":{r+=n.strong(s);break}case"em":{r+=n.em(s);break}case"codespan":{r+=n.codespan(s);break}case"br":{r+=n.br(s);break}case"del":{r+=n.del(s);break}case"text":{r+=n.text(s);break}default:{let l='Token with "'+s.type+'" type was not found.';if(this.options.silent)return console.error(l),"";throw Error(l)}}}return r}},Ht=class{options;block;constructor(e){this.options=e||at}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens","emStrongMask"]);static passThroughHooksRespectAsync=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(e){return e}postprocess(e){return e}processAllTokens(e){return e}emStrongMask(e){return e}provideLexer(e=this.block){return e?Ae.lex:Ae.lexInline}provideParser(e=this.block){return e?Re.parse:Re.parseInline}},Ni=class{defaults=Kn();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=Re;Renderer=pn;TextRenderer=no;Lexer=Ae;Tokenizer=un;Hooks=Ht;constructor(...e){this.use(...e)}walkTokens(e,t){let n=[];for(let r of e)switch(n=n.concat(t.call(this,r)),r.type){case"table":{let o=r;for(let i of o.header)n=n.concat(this.walkTokens(i.tokens,t));for(let i of o.rows)for(let s of i)n=n.concat(this.walkTokens(s.tokens,t));break}case"list":{let o=r;n=n.concat(this.walkTokens(o.items,t));break}default:{let o=r;this.defaults.extensions?.childTokens?.[o.type]?this.defaults.extensions.childTokens[o.type].forEach((i)=>{let s=o[i].flat(1/0);n=n.concat(this.walkTokens(s,t))}):o.tokens&&(n=n.concat(this.walkTokens(o.tokens,t)))}}return n}use(...e){let t=this.defaults.extensions||{renderers:{},childTokens:{}};return e.forEach((n)=>{let r={...n};if(r.async=this.defaults.async||r.async||!1,n.extensions&&(n.extensions.forEach((o)=>{if(!o.name)throw Error("extension name required");if("renderer"in o){let i=t.renderers[o.name];i?t.renderers[o.name]=function(...s){let l=o.renderer.apply(this,s);return l===!1&&(l=i.apply(this,s)),l}:t.renderers[o.name]=o.renderer}if("tokenizer"in o){if(!o.level||o.level!=="block"&&o.level!=="inline")throw Error("extension level must be 'block' or 'inline'");let i=t[o.level];i?i.unshift(o.tokenizer):t[o.level]=[o.tokenizer],o.start&&(o.level==="block"?t.startBlock?t.startBlock.push(o.start):t.startBlock=[o.start]:o.level==="inline"&&(t.startInline?t.startInline.push(o.start):t.startInline=[o.start]))}"childTokens"in o&&o.childTokens&&(t.childTokens[o.name]=o.childTokens)}),r.extensions=t),n.renderer){let o=this.defaults.renderer||new pn(this.defaults);for(let i in n.renderer){if(!(i in o))throw Error(`renderer '${i}' does not exist`);if(["options","parser"].includes(i))continue;let s=i,l=n.renderer[s],a=o[s];o[s]=(...c)=>{let u=l.apply(o,c);return u===!1&&(u=a.apply(o,c)),u||""}}r.renderer=o}if(n.tokenizer){let o=this.defaults.tokenizer||new un(this.defaults);for(let i in n.tokenizer){if(!(i in o))throw Error(`tokenizer '${i}' does not exist`);if(["options","rules","lexer"].includes(i))continue;let s=i,l=n.tokenizer[s],a=o[s];o[s]=(...c)=>{let u=l.apply(o,c);return u===!1&&(u=a.apply(o,c)),u}}r.tokenizer=o}if(n.hooks){let o=this.defaults.hooks||new Ht;for(let i in n.hooks){if(!(i in o))throw Error(`hook '${i}' does not exist`);if(["options","block"].includes(i))continue;let s=i,l=n.hooks[s],a=o[s];Ht.passThroughHooks.has(i)?o[s]=(c)=>{if(this.defaults.async&&Ht.passThroughHooksRespectAsync.has(i))return(async()=>{let d=await l.call(o,c);return a.call(o,d)})();let u=l.call(o,c);return a.call(o,u)}:o[s]=(...c)=>{if(this.defaults.async)return(async()=>{let d=await l.apply(o,c);return d===!1&&(d=await a.apply(o,c)),d})();let u=l.apply(o,c);return u===!1&&(u=a.apply(o,c)),u}}r.hooks=o}if(n.walkTokens){let o=this.defaults.walkTokens,i=n.walkTokens;r.walkTokens=function(s){let l=[];return l.push(i.call(this,s)),o&&(l=l.concat(o.call(this,s))),l}}this.defaults={...this.defaults,...r}}),this}setOptions(e){return this.defaults={...this.defaults,...e},this}lexer(e,t){return Ae.lex(e,t??this.defaults)}parser(e,t){return Re.parse(e,t??this.defaults)}parseMarkdown(e){return(t,n)=>{let r={...n},o={...this.defaults,...r},i=this.onError(!!o.silent,!!o.async);if(this.defaults.async===!0&&r.async===!1)return i(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 t>"u"||t===null)return i(Error("marked(): input parameter is undefined or null"));if(typeof t!="string")return i(Error("marked(): input parameter is of type "+Object.prototype.toString.call(t)+", string expected"));if(o.hooks&&(o.hooks.options=o,o.hooks.block=e),o.async)return(async()=>{let s=o.hooks?await o.hooks.preprocess(t):t,l=await(o.hooks?await o.hooks.provideLexer(e):e?Ae.lex:Ae.lexInline)(s,o),a=o.hooks?await o.hooks.processAllTokens(l):l;o.walkTokens&&await Promise.all(this.walkTokens(a,o.walkTokens));let c=await(o.hooks?await o.hooks.provideParser(e):e?Re.parse:Re.parseInline)(a,o);return o.hooks?await o.hooks.postprocess(c):c})().catch(i);try{o.hooks&&(t=o.hooks.preprocess(t));let s=(o.hooks?o.hooks.provideLexer(e):e?Ae.lex:Ae.lexInline)(t,o);o.hooks&&(s=o.hooks.processAllTokens(s)),o.walkTokens&&this.walkTokens(s,o.walkTokens);let l=(o.hooks?o.hooks.provideParser(e):e?Re.parse:Re.parseInline)(s,o);return o.hooks&&(l=o.hooks.postprocess(l)),l}catch(s){return i(s)}}}onError(e,t){return(n)=>{if(n.message+=`
|
|
59
|
+
Please report this to https://github.com/markedjs/marked.`,e){let r="<p>An error occurred:</p><pre>"+Le(n.message+"",!0)+"</pre>";return t?Promise.resolve(r):r}if(t)return Promise.reject(n);throw n}}},it=new Ni;function Q(e,t){return it.parse(e,t)}Q.options=Q.setOptions=function(e){return it.setOptions(e),Q.defaults=it.defaults,Yo(Q.defaults),Q};Q.getDefaults=Kn;Q.defaults=at;Q.use=function(...e){return it.use(...e),Q.defaults=it.defaults,Yo(Q.defaults),Q};Q.walkTokens=function(e,t){return it.walkTokens(e,t)};Q.parseInline=it.parseInline;Q.Parser=Re;Q.parser=Re.parse;Q.Renderer=pn;Q.TextRenderer=no;Q.Lexer=Ae;Q.lexer=Ae.lex;Q.Tokenizer=un;Q.Hooks=Ht;Q.parse=Q;var{options:ac,setOptions:lc,use:cc,walkTokens:dc,parseInline:uc}=Q;var pc=Re.parse,fc=Ae.lex;import{SessionContext as Os,ActiveViewCtx as tc}from"#canvas/runtime";import{AnnotationCtx as la}from"#canvas/runtime";import{AnnotationCtx as Kd,AnnotationHostContext as Zd,SessionContext as Xd,useAnnotationHost as Jd,useAnnotations as Yd}from"@fabrika/annotations/runtime";function Ue(e,t){let n=[],r=cr(e);for(let o of r){let i=document.createRange();if(i.selectNodeContents(o),o===e.startContainer)i.setStart(o,e.startOffset);if(o===e.endContainer)i.setEnd(o,e.endOffset);let s=i.toString();if(!s||!s.trim())continue;let l=document.createElement("mark");l.setAttribute("data-annotation-id",t);try{i.surroundContents(l)}catch{let a=i.extractContents();l.appendChild(a),i.insertNode(l)}n.push(l)}return n}function Ot(e){let t=e.parentElement;if(t?.classList.contains("select-none"))return!1;if(t?.closest("[data-annotation-id]"))return!1;return!0}function cr(e){let t=[],n=e.commonAncestorContainer;if(n.nodeType===Node.TEXT_NODE)return t.push(n),t;let r=document.createTreeWalker(n,NodeFilter.SHOW_TEXT),o;while(o=r.nextNode()){if(!Ot(o))continue;if(e.intersectsNode(o))t.push(o)}return t}function Ti(e,t){let n=document.createRange();if(n.selectNodeContents(e),e===t.startContainer)n.setStart(e,t.startOffset);if(e===t.endContainer)n.setEnd(e,t.endOffset);return n.toString()}function dr(e){let t="";for(let n of cr(e))t+=Ti(n,e);return t}function yt(e,t){let n=document.querySelectorAll(`[data-annotation-id="${e}"]`);for(let r of n)r.classList.toggle("mark-active",t)}function Ft(e,t){if(t!=null&&t!==e)yt(t,!1);if(e!=null)yt(e,!0)}function Bt(e,t){let n=document.querySelectorAll(`[data-annotation-id="${e}"]`);for(let r of n)r.setAttribute("data-annotation-id",t)}function _t(e,t){for(let n of t){if(e.querySelector(`[data-annotation-id="${n.id}"]`))continue;let r=n.snippet;if(!r)continue;let{fullText:o,textNodes:i}=Li(e),s=[],l=0;while(!0){let m=o.indexOf(r,l);if(m===-1)break;s.push(m),l=m+1}let[a]=s;if(a===void 0)continue;let c=a;if(s.length>1&&n.context){let m=-1;for(let v of s){let g=0;if(n.context.before){let w=o.slice(Math.max(0,v-80),v);if(w.includes(n.context.before))g+=2;else if(n.context.before.length>10&&w.includes(n.context.before.slice(-10)))g+=1}if(n.context.after){let w=o.slice(v+r.length,v+r.length+80);if(w.includes(n.context.after))g+=2;else if(n.context.after.length>10&&w.includes(n.context.after.slice(0,10)))g+=1}if(g>m)m=g,c=v}}let u=c,d=c+r.length,f=lr(i,u),p=lr(i,d);if(!f||!p)continue;try{let m=document.createRange();m.setStart(f.node,f.offset),m.setEnd(p.node,p.offset),Ue(m,n.id)}catch{}}}function Li(e){let t=[],n="",r=document.createTreeWalker(e,NodeFilter.SHOW_TEXT),o;while(o=r.nextNode()){if(!Ot(o))continue;t.push({node:o,start:n.length}),n+=o.textContent||""}return{fullText:n,textNodes:t}}function lr(e,t){for(let n=e.length-1;n>=0;n--){let r=e[n];if(!r||r.start>t)continue;let o=t-r.start,i=r.node.textContent?.length??0;if(o<=i)return{node:r.node,offset:o}}return null}function jt(e){let t=document.querySelectorAll(`[data-annotation-id="${e}"]`);for(let n of t){let r=n.parentNode;if(!r)continue;if(n.tagName!=="MARK"){r.removeChild(n);continue}while(n.firstChild)r.insertBefore(n.firstChild,n);r.removeChild(n),r.normalize()}}function Ge(e,t){let n=ur(e,"before",60),r=ur(e,"after",60),o=Ii(e.startContainer,t);return{before:n,after:r,hierarchy:o}}function ur(e,t,n){let r=Mi(t==="before"?e.startContainer:e.endContainer);if(!r)return"";let o="";if(t==="before"){let i=document.createTreeWalker(r,NodeFilter.SHOW_TEXT),s;while(s=i.nextNode()){if(s===e.startContainer){o+=(s.textContent||"").slice(0,e.startOffset);break}if(!Ot(s))continue;o+=s.textContent||""}if(o.length>n){o=o.slice(-n);let l=o.indexOf(" ");if(l>0)o=o.slice(l+1)}}else{let i=document.createTreeWalker(r,NodeFilter.SHOW_TEXT),s=!1,l;while(l=i.nextNode()){if(l===e.endContainer){o+=(l.textContent||"").slice(e.endOffset),s=!0;continue}if(s){if(!Ot(l))continue;o+=l.textContent||""}}if(o.length>n){o=o.slice(0,n);let a=o.lastIndexOf(" ");if(a>0)o=o.slice(0,a)}}return o.trim()}function Mi(e){let t=new Set(["DIV","P","LI","PRE","BLOCKQUOTE","SECTION","ARTICLE"]),n=e.parentElement;while(n){if(t.has(n.tagName))return n;n=n.parentElement}return null}function Ii(e,t){let n=[],r=e instanceof Element?e:e.parentElement;while(r&&r!==t){let o=r.getAttribute?.("data-task-id");if(o){let s=r.querySelector(".font-semibold");if(s)n.unshift(s.textContent?.trim()||o)}let i=Pi(r);if(i)n.unshift(i);r=r.parentElement}return n}function Pi(e){if(e.getAttribute("data-md")==="section"){let n=e.getAttribute("data-md-title");if(n)return n}if(e.tagName!=="DIV")return null;return e.querySelector(":scope > button > .font-heading, :scope > div > .font-heading")?.textContent?.trim()||null}function hn(e){let t=e.snippet.trim(),n=e.context,r=t.length<30;if(n&&r&&(n.before||n.after)){let o=[];if(n.before)o.push(`...${n.before} `);if(o.push(`**${t}**`),n.after)o.push(` ${n.after}...`);return o.join("")}return t}function qt(e){return{kind:e.kind,owns:(t)=>e.parse(t)!==null,find:(t,n)=>{let r=e.parse(t);return r===null?null:e.find(r,n)},restore:(t,n)=>{let r=e.parse(n.snippet);if(r===null)return;e.restore?.(r,t,n)},describe:(t)=>{let n=e.parse(t);if(n===null||!e.describe)return null;return e.describe(n)}}}function pr(e){let t=document.createTreeWalker(e,NodeFilter.SHOW_TEXT),n="";for(let r=t.nextNode();r;r=t.nextNode()){let o=r.parentElement?.closest("[aria-hidden='true']");if(o&&e.contains(o))continue;n+=r.textContent??""}return n.trim()}function gn(e,t,n){return{selector:e,snippet:(r)=>{let o=r.getAttribute(n);return o?`${t} ${o}`:null}}}var oo=[gn("[data-md='item']","[Item]","data-md-label"),gn("[data-md='section']","[Section]","data-md-title"),gn("[data-md='checklist-item']","[Checklist]","data-md-label"),gn("[data-md='image']","[Image]","data-md-src"),{selector:"[data-md='callout']",snippet:(e)=>`[Callout:${e.getAttribute("data-md-type")||"info"}] ${pr(e).slice(0,60)||"Callout"}`},{selector:"[data-md='note']",snippet:(e)=>`[Note] ${pr(e).slice(0,60)||"Note"}`},{selector:"[data-md='table'] tbody tr",snippet:(e)=>{let t=Array.from(e.querySelectorAll("td")).map((n)=>n.textContent?.trim()).filter(Boolean);return t.length?`[Row] ${t.join(" | ")}`:null}}],$i=["[data-md='choice-option']","[data-md='multichoice-option']","[data-md='userinput']","[data-md='rangeinput']"],Ke=oo.map((e)=>e.selector).join(", "),kt=[...oo.map((e)=>e.selector),...$i].join(", ");function Me(e){for(let t of oo)if(e.matches(t.selector))return t.snippet(e);return null}var ro={kind:"block",parse:(e)=>e.startsWith("[")?{snippet:e}:null,format:(e)=>e.snippet,find:(e,t)=>{for(let n of t.querySelectorAll(Ke)){if(!(n instanceof HTMLElement))continue;if(Me(n)===e.snippet)return n}return null}};var io="data-annotation-image",Hi=/^\[Region:(rect|ellipse)\] ([\s\S]+) @(0|[1-9]\d*),(0|[1-9]\d*),(0|[1-9]\d*),(0|[1-9]\d*)$/;function Di(e){if(e==="rect")return"rect";if(e==="ellipse")return"ellipse";return null}function xn(e){if(e===void 0)return null;let t=Number(e);if(!Number.isInteger(t)||t<0||t>1e4)return null;return t}function fr(e){return Math.min(1e4,Math.max(0,e))}function ao(e,t,n){if(!(e.width>0)||!(e.height>0))return null;return{x:fr(Math.round(t/e.width*1e4)),y:fr(Math.round(n/e.height*1e4))}}function vn(e,t){let n=Math.min(e.x,t.x),r=Math.min(e.y,t.y);return{x:n,y:r,w:Math.min(1e4-n,Math.abs(e.x-t.x)),h:Math.min(1e4-r,Math.abs(e.y-t.y))}}function lo(e){return e.w>=30&&e.h>=30}function mr(e){return{left:`${e.x/100}%`,top:`${e.y/100}%`,width:`${e.w/100}%`,height:`${e.h/100}%`}}function bn(e){return`${(e/100).toFixed(1).replace(/\.0$/,"")}%`}function yn(e){let t=`${bn(e.x)}-${bn(e.x+e.w)}`,n=`${bn(e.y)}-${bn(e.y+e.h)}`;return`[Region] ${e.src} — ${e.shape} x ${t}, y ${n} of the image`}function so(e,t){for(let n of t.querySelectorAll("[data-md='image']")){if(!(n instanceof HTMLElement))continue;if(n.getAttribute("data-md-src")!==e)continue;let r=n.querySelector("[data-annotation-image]");if(r instanceof HTMLElement)return r}return null}function kn(e,t){let n=mr(t);e.style.left=n.left,e.style.top=n.top,e.style.width=n.width,e.style.height=n.height}function wn(e,t,n){let r=document.createElement("div");return r.className="ann-region",r.setAttribute("data-annotation-id",n),r.setAttribute("data-annotation-region",t),kn(r,e),r}var zt={kind:"region",parse:(e)=>{let t=Hi.exec(e);if(!t)return null;let n=Di(t[1]),r=t[2],o=xn(t[3]),i=xn(t[4]),s=xn(t[5]),l=xn(t[6]);if(n===null||r===void 0)return null;if(o===null||i===null||s===null||l===null)return null;if(s<1||l<1)return null;return{src:r,shape:n,x:o,y:i,w:s,h:l}},format:(e)=>`[Region:${e.shape}] ${e.src} @${e.x},${e.y},${e.w},${e.h}`,find:(e,t)=>so(e.src,t),restore:(e,t,n)=>{if(t.querySelector(`[data-annotation-id="${n.id}"]`))return;let r=so(e.src,t);if(!r)return;r.appendChild(wn(e,e.shape,n.id))},describe:yn};var co={kind:"text",parse:(e)=>e?{text:e}:null,format:(e)=>e.text,find:()=>null,restore:(e,t,n)=>{_t(t,[n])}};var En=[qt(zt),qt(ro),qt(co)];function uo(e,t){for(let n of En){let r=n.find(e,t);if(r)return r}return null}function po(e,t){for(let n of t){if(!n.snippet)continue;for(let r of En)r.restore(e,n)}}function Vt(e){for(let t of En){let n=t.describe(e);if(n!==null)return n}return e}import{AnnotationCtx as Bc,SessionContext as _c,useAnnotationHost as jc}from"@fabrika/annotations/runtime";import{useEffect as Vc,useState as Wc}from"react";import{useCallback as ct,useMemo as Oi,useState as Fi}from"react";var Se="__agent-response__";function lt(e){return e.filePath&&e.filePath!=="__agent-response__"?e.filePath:void 0}function Wt(e){return e.uploadUrl!==null}function ve(){return`ann-${Date.now()}-${Math.random().toString(36).slice(2,6)}`}function Ze(e,t){e.style.height="auto",e.style.height=(t?Math.max(t,e.scrollHeight):e.scrollHeight)+"px"}function hr(e){let t=e?`[data-annotation-id="${CSS.escape(e)}"]`:"[data-annotation-id]";for(let n of document.querySelectorAll(t))if(n.tagName==="MARK"){let r=n.parentNode;n.replaceWith(document.createTextNode(n.textContent||"")),r?.normalize()}else n.remove()}function An({annotations:e,setAnnotations:t,generalNote:n,setGeneralNote:r,remoteAnnotations:o,isReadOnly:i,onClear:s}){let[l,a]=Fi(null),c=Oi(()=>{if(!o?.length)return e;let w=new Set(e.map((b)=>b.id)),h=o.filter((b)=>!w.has(b.id));return[...e,...h.map((b)=>({...b,source:"remote"}))]},[e,o]),u=ct((w,h,b,k,y,E,R)=>{t((C)=>[...C,{id:w,snippet:h,note:b,createdAt:new Date().toISOString(),filePath:k,context:y,...E?.length?{images:E}:{},...R?{canvasFile:R}:{}}])},[t]),d=ct((w,h,b)=>{u(ve(),w,h,b)},[u]),f=ct((w,h)=>{t((b)=>b.map((k)=>k.id===w?{...k,note:h}:k))},[t]),p=ct((w)=>{if(!e.some((h)=>h.id===w))return;hr(w),t((h)=>h.filter((b)=>b.id!==w)),a((h)=>h===w?null:h)},[e,t]),m=ct((w,h)=>{t((b)=>b.map((k)=>k.id===w?{...k,images:[...k.images||[],h]}:k))},[t]),v=ct((w,h)=>{t((b)=>b.map((k)=>k.id===w?{...k,images:(k.images||[]).filter((y)=>y!==h)}:k))},[t]),g=ct(()=>{hr(),t([]),r(""),a(null),s?.()},[t,r,s]);return{annotations:c,generalNote:n,setGeneralNote:r,activeAnnotationId:l,setActiveAnnotationId:a,addAnnotation:d,addAnnotationWithId:u,updateAnnotation:f,removeAnnotation:p,addAnnotationImage:m,removeAnnotationImage:v,clearAll:g,isReadOnly:i}}import{useAnnotations as Xe}from"@fabrika/annotations/runtime";import{jsxDEV as dt,Fragment as Bi}from"react/jsx-dev-runtime";function fo({hasContent:e,onSubmit:t,onSubmitEmpty:n,notice:r,secondaryAction:o,placeholder:i="General notes...",submitLabel:s="Submit",emptyLabel:l="Submit without feedback"}){let{generalNote:a,setGeneralNote:c}=Xe();return dt(Bi,{children:[dt("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:dt("textarea",{value:a,onChange:(u)=>c(u.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:i,onInput:(u)=>Ze(u.currentTarget,40),ref:(u)=>{if(u)Ze(u,40)}},void 0,!1,void 0,this)},void 0,!1,void 0,this),r,dt("div",{className:"px-4 py-3 border-t border-border-subtle flex-shrink-0",children:e?dt("div",{className:"flex gap-2",children:[o,dt("button",{onClick:t,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:s},void 0,!1,void 0,this)]},void 0,!0,void 0,this):dt("button",{onClick:n,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:l},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{useAnnotationHost as _i}from"@fabrika/annotations/runtime";import{useCallback as Be,useEffect as ji,useRef as mo,useState as ho}from"react";import{jsxDEV as me}from"react/jsx-dev-runtime";function go(e){if(e.startsWith("/s/")||e.startsWith("http://")||e.startsWith("https://"))return e;return`/api/uploads/${e.split("/").pop()}`}async function qi(e,t){let n=e.uploadUrl;if(!n)return null;let r=new FormData;r.append("image",t);try{let i=await(await fetch(n(),{method:"POST",body:r})).json();if(e.isShared)return i.url||null;return i.path||null}catch{return null}}function Ut({note:e,onNoteChange:t,images:n,onAddImage:r,onRemoveImage:o,sessionId:i,placeholder:s="Add your note...",autoFocus:l=!1,autoResize:a=!1,readOnly:c=!1,onKeyDown:u,onTextareaClick:d,textareaRef:f,textareaClassName:p,textareaStyle:m,minHeight:v,attachButton:g="always",openFilePickerRef:w}){let h=_i(),b=!c&&Wt(h),[k,y]=ho(!1),[E,R]=ho(!1),[C,M]=ho(!1),L=mo(0),B=mo(null),j=mo(null),W=Be(()=>j.current?.click(),[]);if(w)w.current=W;let de=Be((A)=>{if(B.current=A,f)f.current=A;if(A&&a)Ze(A,v)},[f,a,v]);ji(()=>{if(l&&B.current){let A=B.current;if(A.focus(),A.value)A.setSelectionRange(A.value.length,A.value.length)}},[l]);let N=Be(async(A)=>{if(!A.type.startsWith("image/"))return;R(!0);try{let P=await qi(h,A);if(P)r(P)}finally{R(!1)}},[h,r]),_=Be((A)=>{for(let P of A.clipboardData?.items??[])if(P.type.startsWith("image/")){A.preventDefault();let Y=P.getAsFile();if(Y)N(Y);return}},[N]),z=Be((A)=>{if(A.preventDefault(),L.current++,L.current===1)y(!0)},[]),X=Be((A)=>{A.preventDefault()},[]),G=Be((A)=>{if(A.preventDefault(),L.current--,L.current===0)y(!1)},[]),J=Be((A)=>{A.preventDefault(),L.current=0,y(!1);for(let P of A.dataTransfer?.files??[])if(P.type.startsWith("image/"))N(P)},[N]),V=Be((A)=>{if(t(A.currentTarget.value),a)A.currentTarget.style.height="auto",A.currentTarget.style.height=(v?Math.max(v,A.currentTarget.scrollHeight):A.currentTarget.scrollHeight)+"px"},[t,a,v]),O="w-full bg-transparent text-[13px] font-body text-text-primary resize-none focus:outline-none leading-relaxed p-0 border-none",Z={width:"100%",background:"transparent",border:"none",color:"var(--color-text-primary)",fontFamily:"'Inter', sans-serif",fontSize:"13px",lineHeight:"1.5",outline:"none",...a?{resize:"none",overflow:"hidden"}:{resize:"vertical"}},ue=b&&(g==="always"||g==="on-focus"&&C);return me("div",{style:{position:"relative"},onDragEnter:b?z:void 0,onDragOver:b?X:void 0,onDragLeave:b?G:void 0,onDrop:b?J:void 0,children:[me("textarea",{ref:de,value:e,onChange:c?void 0:V,onPaste:b?_:void 0,onKeyDown:u,onClick:d,onFocus:()=>M(!0),onBlur:()=>{setTimeout(()=>M(!1),150)},readOnly:c,placeholder:s,className:p??O,style:m??Z,rows:a?1:void 0},void 0,!1,void 0,this),b&&me("input",{ref:j,type:"file",accept:"image/*",multiple:!0,style:{display:"none"},onChange:(A)=>{let P=A.currentTarget.files;if(P)for(let Y of P)N(Y);A.currentTarget.value=""}},void 0,!1,void 0,this),(n.length>0||ue)&&me("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"6px",alignItems:"center"},children:[n.map((A)=>me("div",{style:{position:"relative",width:"56px",height:"56px",borderRadius:"6px",overflow:"hidden",border:"1px solid var(--color-border-subtle)",flexShrink:0},children:[me("img",{src:go(A),alt:"",style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}},void 0,!1,void 0,this),!c&&me("button",{onClick:(P)=>{P.stopPropagation(),o(A)},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)]},A,!0,void 0,this)),ue&&me(Rn,{onClick:W},void 0,!1,void 0,this)]},void 0,!0,void 0,this),E&&me("div",{style:{fontSize:"11px",color:"var(--color-text-tertiary)",fontFamily:"'Inter', sans-serif",marginTop:"4px"},children:"Uploading..."},void 0,!1,void 0,this),k&&me("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 Rn({onClick:e,size:t=16}){return me("button",{onClick:(n)=>{n.stopPropagation(),e()},style:{width:`${t*2}px`,height:`${t*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:(n)=>{n.currentTarget.style.color="var(--color-text-secondary)"},onMouseLeave:(n)=>{n.currentTarget.style.color="var(--color-text-tertiary)"},children:me("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[me("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"},void 0,!1,void 0,this),me("circle",{cx:"8.5",cy:"8.5",r:"1.5"},void 0,!1,void 0,this),me("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 xo({images:e}){if(!e.length)return null;return me("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"6px"},children:e.map((t)=>me("div",{style:{width:"56px",height:"56px",borderRadius:"6px",overflow:"hidden",border:"1px solid var(--color-border-subtle)",flexShrink:0},children:me("img",{src:go(t),alt:"",style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}},void 0,!1,void 0,this)},t,!1,void 0,this))},void 0,!1,void 0,this)}import{SessionContext as zi}from"@fabrika/annotations/runtime";import{useContext as Vi,useEffect as Wi,useRef as Ui}from"react";import{jsxDEV as le,Fragment as gr}from"react/jsx-dev-runtime";function Gi(e){let t=Vt(e);return t.length>80?t.slice(0,80)+"...":t}function Gt({annotations:e,readOnly:t=!1,onSelect:n,onReveal:r,includedRemoteIds:o,onToggleRemoteId:i}){let{updateAnnotation:s,removeAnnotation:l,addAnnotationImage:a,removeAnnotationImage:c,activeAnnotationId:u,setActiveAnnotationId:d}=Xe(),f=Vi(zi),p=Ui(new Map);Wi(()=>{if(t||!u)return;let b=p.current.get(u);if(b)b.scrollIntoView({behavior:"smooth",block:"nearest"})},[u,t]);let m=(b)=>{d(b),yt(b,!0)},v=(b)=>{d(null),yt(b,!1)},g=(b)=>{if(b.id===u){d(null);return}d(b.id),n?.(b)},w=!!o&&!!i,h=(b)=>{let k=w&&b.source==="remote";return le("div",{ref:(y)=>{if(y)p.current.set(b.id,y);else p.current.delete(b.id)},className:`group/ann relative px-3 py-2.5 transition-colors duration-150 ${t?"cursor-pointer ":""}${u===b.id?"bg-highlight-selected":k?"bg-accent-purple-muted/30 hover:bg-accent-purple-muted/50":"odd:bg-bg-elevated-half hover:bg-bg-input"}`,onMouseEnter:()=>m(b.id),onMouseLeave:()=>v(b.id),onClick:()=>g(b),children:[k&&b.author&&le("div",{className:"flex items-center gap-1.5 mb-1.5",children:[le("input",{type:"checkbox",checked:o.has(b.id),onChange:(y)=>{y.stopPropagation(),i(b.id)},onClick:(y)=>y.stopPropagation(),className:"accent-accent-purple flex-shrink-0",title:"Include in submission"},void 0,!1,void 0,this),le("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),le("span",{className:"text-[11px] font-medium text-accent-purple font-body",children:b.author.name},void 0,!1,void 0,this),le("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),le("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:Gi(b.snippet)},void 0,!1,void 0,this),t?le(gr,{children:[b.note.trim()&&le("div",{className:"text-[13px] font-body text-text-primary leading-relaxed",children:b.note},void 0,!1,void 0,this),le(xo,{images:b.images||[]},void 0,!1,void 0,this)]},void 0,!0,void 0,this):k?le("div",{className:"text-[13px] font-body text-text-primary leading-relaxed whitespace-pre-wrap",children:b.note},void 0,!1,void 0,this):le("div",{onClick:(y)=>y.stopPropagation(),children:le(Ut,{note:b.note,onNoteChange:(y)=>s(b.id,y),images:b.images||[],onAddImage:(y)=>a(b.id,y),onRemoveImage:(y)=>c(b.id,y),sessionId:f,autoResize:!0,minHeight:20,textareaClassName:"w-full bg-transparent text-[13px] font-body text-text-primary resize-none focus:outline-none leading-relaxed p-0 border-none min-h-[20px]",textareaStyle:{height:"auto",overflow:"hidden"},placeholder:"Add your note...",attachButton:"on-focus"},void 0,!1,void 0,this)},void 0,!1,void 0,this),le("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:[r&&le("button",{onClick:(y)=>{y.stopPropagation(),r(b)},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:le("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[le("circle",{cx:"12",cy:"12",r:"3"},void 0,!1,void 0,this),le("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),!t&&!k&&le("button",{onClick:(y)=>{y.stopPropagation(),l(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:le("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[le("polyline",{points:"3 6 5 6 21 6"},void 0,!1,void 0,this),le("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 le(gr,{children:e.map(h)},void 0,!1,void 0,this)}function Kt(e){let t=[],n=e.snippet.trim(),r=e.context,o=Vt(n);if(o!==n)t.push(`> ${o}`);else if(e.filePath&&r&&r.lineStart!=null){let l=r.lineStart,a=r.lineEnd??l,c=n.split(`
|
|
60
|
+
`);if(n.length<30&&l===a&&(r.before||r.after)){let d=hn(e);t.push(`> L${l}: ${d}`)}else if(c.length<=6)for(let d=0;d<c.length;d++)t.push(`> ${l+d} | ${c[d]}`);else{for(let d=0;d<3;d++)t.push(`> ${l+d} | ${c[d]}`);t.push(`> ... (${c.length} lines)`);for(let d=c.length-3;d<c.length;d++)t.push(`> ${l+d} | ${c[d]}`)}}else{let l=hn(e);if(n.split(`
|
|
61
|
+
`).length<=3)t.push(`> ${l.split(`
|
|
65
62
|
`).join(`
|
|
66
|
-
> `)}`);else{let
|
|
67
|
-
`)
|
|
68
|
-
`)}function H4(Z){let $={label:"",annotations:[],children:new Map};for(let q of Z){let Q=q.context?.hierarchy||[],J=$;for(let Y of Q){if(!J.children.has(Y))J.children.set(Y,{label:Y,annotations:[],children:new Map});J=J.children.get(Y)}J.annotations.push(q)}return $}function c3(Z,$=0){let q=[];for(let Q of Z.annotations)q.push(u2(Q));for(let[,Q]of Z.children){let J=$===0?"###":"####";q.push(`${J} ${Q.label}`),q.push(""),q.push(c3(Q,$+1))}return q.join(`
|
|
69
|
-
`)}import{SessionContext as a3}from"#canvas/runtime";import{useEffect as d3,useState as C0,useRef as W4,useMemo as f2}from"react";import{jsxDEV as Q1}from"react/jsx-dev-runtime";function l3({open:Z,onClose:$,onSubmit:q,includedRemoteIds:Q,onToggleRemoteId:J}){let{annotations:Y,generalNote:X,responses:G,feedbackEntries:z}=X1(),[_,H]=C0(""),[U,W]=C0(!1),[T,K]=C0(!1),[L,N]=C0(null),S=W4(null),[O,R]=C0(!1),b=f2(()=>Y.filter((C)=>C.source==="remote"),[Y]);if(Z&&!O)W(!1),K(!1),N(null);if(!Z&&O)W(!1),K(!1),N(null);if(Z!==O)R(Z);let M=f2(()=>A0(Y,X,G,z,Q),[Y,X,G,z,Q]),j=U?_:M;if(d3(()=>{if(Z&&T&&S.current)S.current.focus()},[Z,T]),d3(()=>{if(!Z)return;let C=(h)=>{if(h.key==="Escape")$()};return window.addEventListener("keydown",C),()=>window.removeEventListener("keydown",C)},[Z,$]),!Z)return null;let g=j.trim().length>0;return Q1("div",{className:"fixed inset-0 z-50 bg-black/50 backdrop-blur-sm flex items-center justify-center p-8",onClick:$,children:Q1("div",{className:"bg-bg-surface border border-border-medium rounded-xl shadow-lg w-full max-w-2xl flex flex-col",style:{height:"80vh"},onClick:(C)=>C.stopPropagation(),children:[Q1("div",{className:"flex items-center justify-between px-5 py-3 border-b border-border-subtle flex-shrink-0",children:[Q1("div",{className:"flex items-center gap-3",children:[Q1("span",{className:"text-[13px] font-medium text-text-primary font-body",children:"Response preview"},void 0,!1,void 0,this),U&&Q1("button",{onClick:()=>{W(!1),K(!1)},className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body",children:"Reset"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Q1("div",{className:"flex items-center gap-2",children:[Q1("div",{className:"flex items-center bg-bg-base rounded-md p-0.5",children:[Q1("button",{onClick:()=>K(!1),className:`px-2.5 py-1 rounded text-[11px] font-body font-medium transition-colors ${!T?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Preview"},void 0,!1,void 0,this),Q1("button",{onClick:()=>K(!0),className:`px-2.5 py-1 rounded text-[11px] font-body font-medium transition-colors ${T?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Edit"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Q1("button",{onClick:$,className:"text-text-tertiary hover:text-text-secondary w-7 h-7 flex items-center justify-center rounded-md hover:bg-border-subtle transition-colors",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),T?Q1("textarea",{ref:S,value:j,onChange:(C)=>{H(C.target.value),W(!0)},className:"flex-1 w-full bg-bg-base p-5 text-[13px] font-mono text-text-code resize-none focus:outline-none leading-relaxed placeholder:text-text-disabled",placeholder:"Your feedback will appear here..."},void 0,!1,void 0,this):Q1("div",{className:"flex-1 overflow-y-auto p-5",children:Q1($2,{text:j},void 0,!1,void 0,this)},void 0,!1,void 0,this),b.length>0&&Q1("div",{className:"px-5 py-2 border-t border-border-subtle flex-shrink-0",children:Q1("span",{className:"text-[12px] text-text-secondary font-body",children:["Reviewer feedback: ",Q.size,"/",b.length," included"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),L&&Q1("div",{className:"px-5 py-2 text-[12px] text-accent-red font-body border-t border-border-subtle flex-shrink-0 flex items-center justify-between gap-2",children:[Q1("span",{children:L},void 0,!1,void 0,this),Q1("button",{onClick:()=>{N(null),q(j)},className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body whitespace-nowrap underline",children:"Submit anyway"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Q1("div",{className:"flex justify-end gap-2 px-5 py-3 border-t border-border-subtle flex-shrink-0",children:[Q1("button",{onClick:$,className:"px-4 py-2 rounded-lg text-[13px] font-body text-text-tertiary hover:text-text-secondary transition-colors",children:"Cancel"},void 0,!1,void 0,this),Q1("button",{onClick:()=>{let C=e0(G,z);if(C.length>0){N(`Please answer: ${C.join(", ")}`);return}N(null),q(j)},disabled:!g,className:`px-6 py-2 rounded-lg font-body text-[13px] font-medium transition-all ${g?"bg-btn-primary text-btn-primary-text hover:opacity-90":"bg-bg-input text-text-disabled cursor-default"}`,children:"Submit feedback"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}var T4=/!\[([^\]]*)\]\((\/tmp\/agent-canvas\/uploads\/([^)]+))\)/g;function N4(Z){return Z.replace(T4,($,q,Q,J)=>``)}function $2({text:Z}){let $=f2(()=>e.parse(N4(Z),{async:!1}),[Z]);return Q1("div",{className:"prose-canvas font-body text-body text-text-primary leading-relaxed",dangerouslySetInnerHTML:{__html:$}},void 0,!1,void 0,this)}import{jsxDEV as Z0}from"react/jsx-dev-runtime";var O4={ts:"#3178c6",tsx:"#3178c6",js:"#e8a32e",jsx:"#4ba0c8",html:"#e34c26",css:"#264de4",scss:"#c69",json:"#7a7568",yaml:"#cb171e",yml:"#cb171e",toml:"#9c4221",rs:"#dea584",go:"#00add8",c:"#6a6a6a",cpp:"#f34b7d",h:"#6a6a6a",py:"#3572a5",rb:"#cc342d",sh:"#5a8c3c",bash:"#5a8c3c",md:"#3573b5",txt:"#6b6560",lock:"#6b6560",gitignore:"#6b6560",svg:"#d9952e",png:"#6a9c2e",jpg:"#6a9c2e",gif:"#6a9c2e"},B4={ts:"TS",tsx:"TX",js:"JS",jsx:"JX",py:"PY",rs:"RS",go:"GO",rb:"RB",json:"{}",yaml:"YM",yml:"YM",toml:"TM",html:"<>",css:"#",scss:"#",md:"M↓",sh:"$",bash:"$",c:"C",cpp:"C+",h:"H",svg:"◇",png:"▣",jpg:"▣"};function f1({name:Z,type:$,expanded:q,className:Q=""}){if($==="dir")return Z0("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",className:`flex-shrink-0 ${Q}`,children:q?Z0("path",{d:"M1.5 3.5h5l1.5 1.5h6.5v8h-13z",style:{fill:"var(--color-folder-fill-active)",stroke:"var(--color-folder-stroke-active)"},strokeWidth:"1"},void 0,!1,void 0,this):Z0("path",{d:"M1.5 3.5h5l1.5 1.5h6.5v8h-13z",style:{fill:"var(--color-folder-fill)",stroke:"var(--color-folder-stroke)"},strokeWidth:"1"},void 0,!1,void 0,this)},void 0,!1,void 0,this);let J=Z.includes(".")?Z.split(".").pop().toLowerCase():"",Y=O4[J]||"#6b6560",X=B4[J];return Z0("svg",{width:"14",height:"14",viewBox:"0 0 16 16",className:`flex-shrink-0 ${Q}`,children:[Z0("path",{d:"M2 1.5h8l3.5 3.5v9.5a1 1 0 01-1 1H3a1 1 0 01-1-1v-12a1 1 0 011-1z",fill:Y,opacity:"0.85"},void 0,!1,void 0,this),Z0("path",{d:"M10 1.5v2.5a1 1 0 001 1h2.5",fill:"none",stroke:"white",strokeWidth:"0.5",opacity:"0.5"},void 0,!1,void 0,this),X&&Z0("text",{x:"8",y:"11.5",textAnchor:"middle",fill:"white",fontSize:"5.5",fontFamily:"monospace",fontWeight:"600",children:X},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function F4(Z){let $=Z.getAttribute("data-md");if($==="item"){let q=Z.getAttribute("data-md-label");return q?`[Item] ${q}`:null}if($==="section"){let q=Z.getAttribute("data-md-title");return q?`[Section] ${q}`:null}if($==="callout"){let q=Z.getAttribute("data-md-type")||"info",Q=Z.textContent?.trim().slice(0,60)||"Callout";return`[Callout:${q}] ${Q}`}if($==="note")return`[Note] ${Z.textContent?.trim().slice(0,60)||"Note"}`;if(Z.tagName==="TR"){let q=Array.from(Z.querySelectorAll("td")).map((Q)=>Q.textContent?.trim()).filter(Boolean);return q.length?`[Row] ${q.join(" | ")}`:null}if($==="checklist-item"){let q=Z.getAttribute("data-md-label");return q?`[Checklist] ${q}`:null}if($==="choice-option"||$==="multichoice-option"){let q=Z.getAttribute("data-md-label");return q?`[Option] ${q}`:null}if($==="userinput"){let q=Z.getAttribute("data-md-label");return q?`[Input] ${q}`:null}if($==="rangeinput"){let q=Z.getAttribute("data-md-label");return q?`[Range] ${q}`:null}if($==="image"){let q=Z.getAttribute("data-md-src");return q?`[Image] ${q}`:null}return null}function V0(Z){let $=document.querySelector(`[data-annotation-id="${Z.id}"]`);if($)return $;if(Z.snippet.startsWith("[")){for(let q of document.querySelectorAll("[data-md='item'], [data-md='section'], [data-md='table'] tbody tr, [data-md='callout'], [data-md='note'], [data-md='checklist-item'], [data-md='image']"))if(F4(q)===Z.snippet)return q}return null}function r3(Z){Z.classList.remove("ann-flash"),Z.offsetWidth,Z.classList.add("ann-flash"),Z.addEventListener("animationend",()=>{Z.classList.remove("ann-flash")},{once:!0})}function v2(Z,$){if(Z.filePath)$({type:"file",path:Z.filePath}),setTimeout(()=>{let q=V0(Z);if(q)q.scrollIntoView({behavior:"smooth",block:"center"}),r3(q)},150);else{let q=V0(Z);if(q)q.scrollIntoView({behavior:"smooth",block:"center"}),r3(q)}}import{jsxDEV as y,Fragment as Z2}from"react/jsx-dev-runtime";function p2({onSubmit:Z,collapseButton:$}){let{isReadOnly:q,selectedRevision:Q,currentRevision:J,revisions:Y,agentWatching:X}=J2(A1),G=J2(a3),z=Y.find((W)=>W.revision===Q),_=q&&Q===J,H=!!z?.feedbackConsumed,U=z?.label||`Round ${Q}`;if(q)return y(y4,{sessionId:G,revision:Q,label:U,waitingForUpdate:_,feedbackConsumed:H,agentWatching:X,collapseButton:$},void 0,!1,void 0,this);return y(j4,{onSubmit:Z,agentWatching:X,collapseButton:$},void 0,!1,void 0,this)}function P4({sessionId:Z,revision:$,label:q,waitingForUpdate:Q,feedbackConsumed:J,agentWatching:Y,collapseButton:X}){let G=$1.isShared,[z,_]=v1(null),[H,U]=v1(!0);return q2(()=>{if(U(!0),!M1){_(null),U(!1);return}fetch(`/api/session/${Z}/revision/${$}/feedback`).then((W)=>W.json()).then((W)=>{_(W.feedback||null),U(!1)}).catch(()=>{_(null),U(!1)})},[Z,$]),y("div",{className:"flex flex-col h-full",children:[y("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[y("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:Q?"Feedback sent":`Feedback — ${q}`},void 0,!1,void 0,this),X]},void 0,!0,void 0,this),Q&&!G&&y(o3,{feedbackConsumed:J,agentWatching:Y},void 0,!1,void 0,this),y("div",{className:"flex-1 overflow-y-auto px-4",children:H?y("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"Loading..."},void 0,!1,void 0,this):z?y($2,{text:z},void 0,!1,void 0,this):y("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"No feedback was submitted for this revision."},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function o3({feedbackConsumed:Z,agentWatching:$}){if(Z)return y("div",{className:"mx-4 mb-3 px-3 py-2.5 rounded-lg bg-accent-green-muted flex items-center gap-2 flex-shrink-0",children:[y("span",{className:"w-2 h-2 rounded-full bg-accent-green animate-pulse"},void 0,!1,void 0,this),y("span",{className:"text-[12px] font-body text-accent-green",children:"Feedback received — waiting for next revision..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if($)return y("div",{className:"mx-4 mb-3 px-3 py-2.5 rounded-lg bg-accent-blue-muted flex items-center gap-2 flex-shrink-0",children:[y("span",{className:"w-2 h-2 rounded-full bg-accent-blue animate-pulse"},void 0,!1,void 0,this),y("span",{className:"text-[12px] font-body text-accent-blue",children:"Waiting for agent to pick up feedback..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return y("div",{className:"mx-4 mb-3 px-3 py-2.5 rounded-lg bg-accent-amber-muted flex items-center gap-2 flex-shrink-0",children:[y("span",{className:"w-2 h-2 rounded-full bg-accent-amber"},void 0,!1,void 0,this),y("span",{className:"text-[12px] font-body text-accent-amber",children:"Agent disconnected — tell Claude to check feedback"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function y4({sessionId:Z,revision:$,label:q,waitingForUpdate:Q,feedbackConsumed:J,agentWatching:Y,collapseButton:X}){let{annotations:G,generalNote:z,activeAnnotationId:_,setActiveAnnotationId:H}=X1(),{setActiveView:U}=J2(k1),W=G.length>0||z.trim().length>0,[T,K]=v1("feedback");if(!W)return y(P4,{sessionId:Z,revision:$,label:q,waitingForUpdate:Q,feedbackConsumed:J,agentWatching:Y,collapseButton:X},void 0,!1,void 0,this);return y("div",{className:"flex flex-col h-full",children:[y("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[y("div",{className:"flex items-center gap-1 bg-bg-input rounded-md p-0.5",children:[y("button",{onClick:()=>K("feedback"),className:`px-2.5 py-1 rounded text-[11px] font-medium font-body transition-colors ${T==="feedback"?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Feedback"},void 0,!1,void 0,this),y("button",{onClick:()=>K("annotations"),className:`px-2.5 py-1 rounded text-[11px] font-medium font-body transition-colors flex items-center gap-1.5 ${T==="annotations"?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:["Annotations",y("span",{className:"inline-flex items-center justify-center min-w-[16px] h-[16px] px-1 rounded-full bg-border-subtle text-[10px] font-medium",children:G.length},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),X]},void 0,!0,void 0,this),Q&&y(o3,{feedbackConsumed:J,agentWatching:Y},void 0,!1,void 0,this),T==="feedback"?y(S4,{sessionId:Z,revision:$},void 0,!1,void 0,this):y(b4,{annotations:G,generalNote:z,activeAnnotationId:_,setActiveAnnotationId:H,setActiveView:U},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function S4({sessionId:Z,revision:$}){let[q,Q]=v1(null),[J,Y]=v1(!0);return q2(()=>{if(Y(!0),!M1){Q(null),Y(!1);return}fetch(`/api/session/${Z}/revision/${$}/feedback`).then((X)=>X.json()).then((X)=>{Q(X.feedback||null),Y(!1)}).catch(()=>{Q(null),Y(!1)})},[Z,$]),y("div",{className:"flex-1 overflow-y-auto px-4",children:J?y("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"Loading..."},void 0,!1,void 0,this):q?y($2,{text:q},void 0,!1,void 0,this):y("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"No feedback was submitted for this revision."},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function b4({annotations:Z,generalNote:$,activeAnnotationId:q,setActiveAnnotationId:Q,setActiveView:J}){let Y=Z.filter((K)=>K.filePath===T1),X=Z.filter((K)=>!K.filePath),G=Z.filter((K)=>K.filePath&&K.filePath!==T1),z={};for(let K of G){let L=K.filePath;if(!z[L])z[L]=[];z[L].push(K)}let _=(K)=>{Q(K),o1(K,!0)},H=(K)=>{Q(null),o1(K,!1)},U=(K)=>{if(K.id===q)Q(null);else if(Q(K.id),K.filePath)J({type:"file",path:K.filePath}),setTimeout(()=>{let L=V0(K);if(L)L.scrollIntoView({behavior:"smooth",block:"center"})},150)},W=(K)=>y("div",{className:`group/ann relative px-3 py-2.5 transition-colors duration-150 cursor-pointer ${q===K.id?"bg-highlight-selected":"odd:bg-bg-elevated-half hover:bg-bg-input"}`,onMouseEnter:()=>_(K.id),onMouseLeave:()=>H(K.id),onClick:()=>U(K),children:[y("div",{className:"text-[11px] text-text-tertiary italic line-clamp-2 mb-1.5 leading-snug font-body border-l-2 border-border-medium pl-2",children:K.snippet.length>80?K.snippet.slice(0,80)+"...":K.snippet},void 0,!1,void 0,this),K.note.trim()&&y("div",{className:"text-[13px] font-body text-text-primary leading-relaxed",children:K.note},void 0,!1,void 0,this),y(D3,{images:K.images||[]},void 0,!1,void 0,this),y("div",{className:"absolute top-1.5 right-1.5 opacity-0 group-hover/ann:opacity-100 transition-opacity duration-100",children:y("button",{onClick:(L)=>{L.stopPropagation(),v2(K,J)},className:"w-5 h-5 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-input transition-colors",title:"Scroll to annotation",children:y("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[y("circle",{cx:"12",cy:"12",r:"3"},void 0,!1,void 0,this),y("path",{d:"M12 2v4M12 18v4M2 12h4M18 12h4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},K.id,!0,void 0,this),T=[Y,X,G].filter((K)=>K.length>0).length>1;return y(Z2,{children:[y("div",{className:"flex-1 overflow-y-auto",children:[Y.length>0&&y(Z2,{children:[T&&y("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body px-3 mb-1 mt-1",children:"Agent Response"},void 0,!1,void 0,this),Y.map(W)]},void 0,!0,void 0,this),X.length>0&&y(Z2,{children:[T&&y("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body px-3 mb-1 mt-1",children:"Canvas"},void 0,!1,void 0,this),X.map(W)]},void 0,!0,void 0,this),Object.entries(z).map(([K,L])=>y("div",{children:[y("button",{onClick:()=>J({type:"file",path:K}),className:"flex items-center gap-1.5 text-[10px] uppercase tracking-widest text-text-tertiary hover:text-text-secondary font-body px-3 pt-3 pb-1 truncate transition-colors w-full text-left",title:K,children:[y(f1,{name:K.split("/").pop()||K,type:"file"},void 0,!1,void 0,this),y("span",{className:"truncate",children:K},void 0,!1,void 0,this)]},void 0,!0,void 0,this),L.map(W)]},K,!0,void 0,this))]},void 0,!0,void 0,this),$.trim()&&y("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:y("div",{className:"text-[13px] font-body text-text-primary leading-relaxed",children:$},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function j4({onSubmit:Z,agentWatching:$,collapseButton:q}){let[Q,J]=v1(!1),{annotations:Y,updateAnnotation:X,removeAnnotation:G,addAnnotationImage:z,removeAnnotationImage:_,generalNote:H,setGeneralNote:U,activeAnnotationId:W,setActiveAnnotationId:T,responses:K,feedbackEntries:L}=X1(),N=J2(a3),{setActiveView:S}=L4.useContext(k1),O=i3(null),R=i3(new Map),b=Y.filter((F)=>F.filePath===T1),M=Y.filter((F)=>!F.filePath),j=Y.filter((F)=>F.filePath&&F.filePath!==T1),g={};for(let F of j){let m=F.filePath;if(!g[m])g[m]=[];g[m].push(F)}q2(()=>{if(!W)return;let F=R.current.get(W);if(F)F.scrollIntoView({behavior:"smooth",block:"nearest"})},[W]);let C=h2((F)=>{T(F),o1(F,!0)},[T]),h=h2((F)=>{T(null),o1(F,!1)},[W]),v=M4(()=>Y.filter((F)=>F.source==="remote"),[Y]),[l,V]=v1(()=>new Set);q2(()=>{if(v.length===0)return;V((F)=>{let m=new Set(F);for(let u of v)m.add(u.id);return m.size===F.size?F:m})},[v]);let E=h2((F)=>{V((m)=>{let u=new Set(m);if(u.has(F))u.delete(F);else u.add(F);return u})},[]),c=Array.from(K.values()).some(g2),P=L.size>0,x=Y.length>0||H.trim().length>0||c||P,[f,o]=v1(null),w=(F)=>{let m=F.source==="remote";return y("div",{ref:(u)=>{if(u)R.current.set(F.id,u);else R.current.delete(F.id)},className:`group/ann relative px-3 py-2.5 transition-colors duration-150 ${W===F.id?"bg-highlight-selected":m?"bg-accent-purple-muted/30 hover:bg-accent-purple-muted/50":"odd:bg-bg-elevated-half hover:bg-bg-input"}`,onMouseEnter:()=>C(F.id),onMouseLeave:()=>h(F.id),onClick:()=>{if(F.id===W)T(null);else if(T(F.id),F.filePath)S({type:"file",path:F.filePath}),setTimeout(()=>{let u=V0(F);if(u)u.scrollIntoView({behavior:"smooth",block:"center"})},150)},children:[m&&F.author&&y("div",{className:"flex items-center gap-1.5 mb-1.5",children:[y("input",{type:"checkbox",checked:l.has(F.id),onChange:(u)=>{u.stopPropagation(),E(F.id)},onClick:(u)=>u.stopPropagation(),className:"accent-accent-purple flex-shrink-0",title:"Include in submission"},void 0,!1,void 0,this),y("span",{className:"inline-flex items-center justify-center w-4 h-4 rounded-full bg-accent-purple text-white text-[9px] font-medium uppercase",children:F.author.name.charAt(0)},void 0,!1,void 0,this),y("span",{className:"text-[11px] font-medium text-accent-purple font-body",children:F.author.name},void 0,!1,void 0,this),y("span",{className:"text-[10px] text-text-tertiary font-body uppercase tracking-widest",children:"Remote"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),y("div",{className:"text-[11px] text-text-tertiary italic line-clamp-2 mb-1.5 leading-snug font-body border-l-2 border-border-medium pl-2",children:F.snippet.length>80?F.snippet.slice(0,80)+"...":F.snippet},void 0,!1,void 0,this),m?y("div",{className:"text-[13px] font-body text-text-primary leading-relaxed whitespace-pre-wrap",children:F.note},void 0,!1,void 0,this):y("div",{onClick:(u)=>u.stopPropagation(),children:y(c0,{note:F.note,onNoteChange:(u)=>X(F.id,u),images:F.images||[],onAddImage:(u)=>z(F.id,u),onRemoveImage:(u)=>_(F.id,u),sessionId:N,autoResize:!0,minHeight:20,textareaClassName:"w-full bg-transparent text-[13px] font-body text-text-primary resize-none focus:outline-none leading-relaxed p-0 border-none min-h-[20px]",textareaStyle:{height:"auto",overflow:"hidden"},placeholder:"Add your note...",attachButton:"on-focus"},void 0,!1,void 0,this)},void 0,!1,void 0,this),y("div",{className:"absolute top-1.5 right-1.5 opacity-0 group-hover/ann:opacity-100 transition-opacity duration-100 flex items-center gap-0.5",children:[y("button",{onClick:(u)=>{u.stopPropagation(),v2(F,S)},className:"w-5 h-5 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-input transition-colors",title:"Scroll to annotation",children:y("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[y("circle",{cx:"12",cy:"12",r:"3"},void 0,!1,void 0,this),y("path",{d:"M12 2v4M12 18v4M2 12h4M18 12h4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),!m&&y("button",{onClick:(u)=>{u.stopPropagation(),G(F.id)},className:"w-5 h-5 flex items-center justify-center rounded text-text-tertiary hover:text-accent-red hover:bg-accent-red-muted transition-colors",title:"Delete annotation",children:y("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[y("polyline",{points:"3 6 5 6 21 6"},void 0,!1,void 0,this),y("path",{d:"M19 6v14a2 2 0 01-2 2H7a2 2 0 01-2-2V6m3 0V4a2 2 0 012-2h4a2 2 0 012 2v2"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},F.id,!0,void 0,this)};return y("div",{className:"flex flex-col h-full",children:[y("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[y("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body flex items-center gap-2",children:["Annotations",Y.length>0&&y("span",{className:"inline-flex items-center justify-center min-w-[18px] h-[18px] px-1 rounded-full bg-border-subtle text-[10px] font-medium text-text-secondary",children:Y.length},void 0,!1,void 0,this),!$1.isShared&&y("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${$?"bg-accent-green":"bg-accent-amber"}`,title:$?"Agent connected":"Agent disconnected"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),q]},void 0,!0,void 0,this),y("div",{ref:O,className:"flex-1 overflow-y-auto",children:[Y.length===0&&y("p",{className:"text-[12px] text-text-tertiary px-3 py-4 leading-relaxed font-body",children:"Select text in the canvas or in files to add annotations."},void 0,!1,void 0,this),b.length>0&&y(Z2,{children:[(M.length>0||j.length>0)&&y("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body px-3 mb-1 mt-1",children:"Agent Response"},void 0,!1,void 0,this),b.map(w)]},void 0,!0,void 0,this),M.length>0&&(b.length>0||j.length>0)&&y("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body px-3 mb-1 mt-1",children:"Canvas"},void 0,!1,void 0,this),M.map(w),Object.entries(g).map(([F,m])=>y("div",{children:[y("button",{onClick:()=>S({type:"file",path:F}),className:"flex items-center gap-1.5 text-[10px] uppercase tracking-widest text-text-tertiary hover:text-text-secondary font-body px-3 pt-3 pb-1 truncate transition-colors w-full text-left",title:F,children:[y(f1,{name:F.split("/").pop()||F,type:"file"},void 0,!1,void 0,this),y("span",{className:"truncate",children:F},void 0,!1,void 0,this)]},void 0,!0,void 0,this),m.map(w)]},F,!0,void 0,this))]},void 0,!0,void 0,this),y("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:y("textarea",{value:H,onChange:(F)=>U(F.target.value),className:"w-full bg-transparent text-[13px] font-body text-text-primary resize-none leading-relaxed p-0 border-none ring-0 shadow-none outline-none focus:outline-none focus:ring-0 focus:border-none placeholder:text-text-disabled min-h-[40px]",placeholder:"General notes...",onInput:(F)=>y0(F.target,40),ref:(F)=>{if(F)y0(F,40)}},void 0,!1,void 0,this)},void 0,!1,void 0,this),f&&y("div",{className:"px-4 py-2 text-[12px] text-accent-red font-body border-t border-border-subtle flex-shrink-0 flex items-center justify-between gap-2",children:[y("span",{children:f},void 0,!1,void 0,this),y("button",{onClick:()=>{o(null);let F=A0(Y,H,K,L,l);Z(F)},className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body whitespace-nowrap underline",children:"Submit anyway"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),y("div",{className:"px-4 py-3 border-t border-border-subtle flex-shrink-0",children:x?y("div",{className:"flex gap-2",children:[y("button",{onClick:()=>J(!0),className:"flex-1 py-2 rounded-lg font-body text-[13px] font-medium transition-all bg-border-subtle text-text-secondary hover:bg-border-medium hover:text-text-primary",children:"Preview"},void 0,!1,void 0,this),y("button",{onClick:()=>{let F=e0(K,L);if(F.length>0){o(`Please answer: ${F.join(", ")}`);return}o(null);let m=A0(Y,H,K,L,l);Z(m)},className:"flex-1 py-2 rounded-lg font-body text-[13px] font-medium transition-all bg-btn-primary text-btn-primary-text hover:opacity-90 hover:-translate-y-px shadow-sm",children:"Submit"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):y("button",{onClick:()=>Z("No feedback — looks good."),className:"w-full py-2 rounded-lg font-body text-[13px] font-medium border border-border-medium text-text-secondary hover:text-text-primary hover:border-border-hover hover:bg-bg-input transition-all",children:"Submit without feedback"},void 0,!1,void 0,this)},void 0,!1,void 0,this),y(l3,{open:Q,onClose:()=>J(!1),onSubmit:Z,includedRemoteIds:l,onToggleRemoteId:E},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{useEffect as w4,useState as s3,useContext as t3,useMemo as A4}from"react";import{SessionContext as C4}from"#canvas/runtime";import{jsxDEV as r,Fragment as c2}from"react/jsx-dev-runtime";function n3({embedded:Z}={}){let $=t3(C4),{annotations:q,addAnnotation:Q}=X1(),{setActiveView:J}=t3(k1),[Y,X]=s3(!1),[G,z]=s3({});if(!M1)return r("div",{className:Z?"px-4 py-3":"p-4",children:[r("div",{className:"text-[11px] uppercase tracking-widest text-text-tertiary font-body mb-2",children:"Files"},void 0,!1,void 0,this),r("p",{className:"text-[11px] text-text-tertiary font-body leading-relaxed",children:"File browsing is not available in shared view. File previews embedded in the canvas still work."},void 0,!1,void 0,this)]},void 0,!0,void 0,this);let{annCountMap:_,annotatedFiles:H}=A4(()=>{let O=new Map;for(let R of q)if(R.filePath&&R.filePath!==T1)O.set(R.filePath,(O.get(R.filePath)||0)+1);return{annCountMap:O,annotatedFiles:[...O.keys()]}},[q]),U=async(O)=>{let b=await(await fetch(`/api/tree?session=${$}&path=${encodeURIComponent(O)}`)).json();if(b.entries)z((M)=>({...M,[O]:{entries:b.entries,expanded:!0,loaded:!0}}))};w4(()=>{if(!Y&&!G[""])U("")},[Y]);let W=(O)=>{if(G[O]?.loaded)z((R)=>({...R,[O]:{...R[O],expanded:!R[O].expanded}}));else U(O)},T=(O)=>{J({type:"file",path:O})},K=async(O)=>{let b=await(await fetch(`/api/file?session=${$}&path=${encodeURIComponent(O)}`)).json();if(!b.error){let M=b.content.split(`
|
|
63
|
+
> `)}`);else{let a=n.split(`
|
|
64
|
+
`);t.push(`> ${a[0]}`),t.push(`> ... (${a.length} lines)`),t.push(`> ${a[a.length-1]}`)}}if(e.note.trim())t.push(""),t.push(e.note.trim());let i=[...e.images??[]],s=new Set(i);for(let l of e.attachments??[]){if(s.has(l.url))continue;s.add(l.url),i.push(l.url)}if(i.length){t.push("");for(let l of i)t.push(``)}return t.push(""),t.join(`
|
|
65
|
+
`)}import{SessionContext as Ki,useAnnotationHost as Zi}from"@fabrika/annotations/runtime";import{useCallback as Sn,useContext as Xi,useEffect as Ji,useMemo as vr,useRef as Cn,useState as wt}from"react";import{createPortal as Yi}from"react-dom";function xr(e){let t=/^(\d+(?:\.\d+)?)px$/.exec(e.trim());return t?Number(t[1]):void 0}function br(e,t,n=280){let o=t||document.body,i=e.getBoundingClientRect(),s=o.getBoundingClientRect(),l=o===document.body?0:o.scrollTop,a=i.bottom-s.top+l+8,c=Math.max(0,Math.min(i.left-s.left,s.width-n-12));return o.style.position="relative",{style:{position:"absolute",top:`${a}px`,left:`${c}px`},parent:o}}import{jsxDEV as he,Fragment as Qi}from"react/jsx-dev-runtime";function kr({anchorEl:e,scrollContainer:t,onClose:n,ignoreSelector:r,zIndex:o="50",padding:i="12px",width:s="280px",children:l}){let a=Cn(null),c=Cn(n);c.current=n;let{style:u,parent:d}=br(e,t,xr(s));return Ji(()=>{let f=setTimeout(()=>{let p=(m)=>{if(a.current&&!a.current.contains(m.target)){if(r&&m.target.closest?.(r))return;c.current(),document.removeEventListener("mousedown",p)}};return document.addEventListener("mousedown",p),()=>document.removeEventListener("mousedown",p)},0);return()=>clearTimeout(f)},[r]),Yi(he("div",{ref:a,style:{...u,zIndex:o,width:s,background:"var(--color-bg-elevated)",border:"1px solid var(--color-border-hover)",borderRadius:"8px",boxShadow:"0 4px 12px var(--color-shadow)",padding:i,fontFamily:"'Inter', sans-serif"},children:l},void 0,!1,void 0,this),d)}var wr=[{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"]}],yr=wr.flatMap((e)=>e.items);function bo({anchorEl:e,scrollContainer:t,snippet:n,truncateAt:r=100,header:o,initialNote:i="",initialImages:s,onConfirm:l,onCancel:a,onDelete:c}){let u=Xi(Ki),d=Zi(),f=Wt(d),p=i!==""||!!c,[m,v]=wt(i),[g,w]=wt(s||[]),[h,b]=wt(null),[k,y]=wt(p),[E,R]=wt(!1),C=Cn(null),M=Cn(null),L=Sn(()=>{if(m.trim()||g.length>0)l(m.trim(),g);else if(p&&c)c();else a()},[m,g,l,a,p,c]),B=Sn(()=>{if(p){if(!m.trim()&&g.length===0&&c){c(),a();return}l(m,g);return}a()},[m,g,p,l,a,c]),j=!p,W=m.trim().length>0?yr.filter((T)=>T.toLowerCase().startsWith(m.trim().toLowerCase())):yr,de=!j||k?[]:W.length===1&&W[0]?.toLowerCase()===m.trim().toLowerCase()?[]:W,N=new Set(de),_=wr.map((T)=>({label:T.label,items:T.items.filter((H)=>N.has(H))})).filter((T)=>T.items.length>0),z=_.map((T)=>T.items),X=(T)=>z[T]?.length??0,G=z.flat(),J=vr(()=>{if(h===null)return 0;let T=0;for(let H=0;H<z.length;H++){if(h<T+X(H))return H;T+=X(H)}return 0},[h,z]),V=vr(()=>{if(h===null)return 0;let T=0;for(let H=0;H<J;H++)T+=X(H);return h-T},[h,J,z]),O=(T,H)=>{let F=0;for(let oe=0;oe<T;oe++)F+=X(oe);return F+H},[Z,ue]=wt(m);if(m!==Z)ue(m),b(null),y(p);let A=Sn((T)=>{v(T)},[]),P=n.length>r?n.slice(0,r)+"...":n,Y=Sn((T)=>{if(G.length>0&&(T.key==="ArrowDown"||T.key==="ArrowUp"||T.key==="ArrowLeft"||T.key==="ArrowRight")){if(T.preventDefault(),h===null){b(0);return}if(T.key==="ArrowDown"){let F=Math.min(V+1,X(J)-1);b(O(J,F))}else if(T.key==="ArrowUp"){let F=Math.max(V-1,0);b(O(J,F))}else if(T.key==="ArrowRight"){let F=Math.min(J+1,z.length-1),oe=Math.min(V,X(F)-1);b(O(F,oe))}else if(T.key==="ArrowLeft"){let F=Math.max(J-1,0),oe=Math.min(V,X(F)-1);b(O(F,oe))}return}let H=h===null?void 0:G[h];if(H!==void 0){if(T.key==="Tab"){T.preventDefault(),A(H);return}if(T.key==="Enter"&&!T.shiftKey){T.preventDefault(),l(H,g);return}}if(T.key==="Enter"&&!T.shiftKey){T.preventDefault(),L();return}if(T.key==="Escape")if(G.length>0&&!k)y(!0);else if(p)B();else a()},[G,h,V,J,z,O,A,l,g,L,k,p,B,a]);return he(kr,{anchorEl:e,scrollContainer:t,onClose:p?B:a,ignoreSelector:p?"[data-annotation-id]":void 0,zIndex:p?"60":"50",padding:p?"10px 12px":"12px",width:"420px",children:[!p&&(o??he("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:["“",P,"”"]},void 0,!0,void 0,this)),he(Ut,{note:m,onNoteChange:v,images:g,onAddImage:(T)=>w((H)=>[...H,T]),onRemoveImage:(T)=>w((H)=>H.filter((F)=>F!==T)),sessionId:u,autoFocus:!0,autoResize:p,textareaRef:C,onKeyDown:Y,attachButton:"none",openFilePickerRef:M,textareaStyle:p?{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),he("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginTop:p?"6px":"8px"},children:[f&&he(Rn,{onClick:()=>M.current?.(),size:14},void 0,!1,void 0,this),he("div",{style:{flex:1}},void 0,!1,void 0,this),p?he("button",{onClick:()=>{if(c)c();a()},onMouseEnter:()=>R(!0),onMouseLeave:()=>R(!1),style:{fontSize:"11px",color:E?"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):he(Qi,{children:[he("button",{onClick:a,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),he("button",{onClick:L,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),G.length>0&&he("div",{style:{marginTop:"6px",borderTop:"1px solid var(--color-border-subtle)",paddingTop:"8px",display:"flex",gap:"4px"},children:_.map((T)=>he("div",{style:{flex:1},children:[he("div",{style:{fontSize:"10px",fontWeight:600,color:"var(--color-text-disabled)",textTransform:"uppercase",letterSpacing:"0.05em",padding:"2px 6px",marginBottom:"2px",fontFamily:"'Inter', sans-serif"},children:T.label},void 0,!1,void 0,this),T.items.map((H)=>{let F=G.indexOf(H);return he("div",{onMouseDown:(oe)=>{oe.preventDefault(),oe.stopPropagation(),A(H)},onMouseEnter:()=>b(F),style:{padding:"3px 6px",fontSize:"12px",borderRadius:"4px",fontFamily:"'Inter', sans-serif",color:F===h?"var(--color-text-primary)":"var(--color-text-secondary)",background:F===h?"var(--color-highlight-selected)":"transparent",cursor:"pointer"},children:[he("span",{style:{fontWeight:500},children:H.slice(0,m.trim().length)},void 0,!1,void 0,this),H.slice(m.trim().length)]},H,!0,void 0,this)})]},T.label,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Ie({anchorEl:e,scrollContainer:t,snippet:n,truncateAt:r,header:o,onAdd:i,onCancel:s}){return he(bo,{anchorEl:e,scrollContainer:t,snippet:n,truncateAt:r,header:o,onConfirm:(l,a)=>i(l,a),onCancel:s},void 0,!1,void 0,this)}function ut({anchorEl:e,scrollContainer:t,initialNote:n,initialImages:r,onUpdate:o,onDelete:i,onClose:s}){return he(bo,{anchorEl:e,scrollContainer:t,snippet:"",initialNote:n,initialImages:r,onConfirm:(l,a)=>{o(l,a),s()},onDelete:i,onCancel:s},void 0,!1,void 0,this)}import{useEffect as ea,useRef as vo,useState as Er}from"react";import{jsxDEV as ta}from"react/jsx-dev-runtime";function yo(e){let{containerRef:t,restoreKey:n,shape:r="rect",canvasFile:o,scrollContainer:i}=e,{addAnnotationWithId:s}=Xe(),[l,a]=Er(null),[c,u]=Er(!1),d=vo(s);d.current=s;let f=vo(o);f.current=o;let p=vo(r);return p.current=r,ea(()=>{let v=t.current;if(!v)return;let g=null;function w(R,C){let M=R.getBoundingClientRect();return ao(M,C.clientX-M.left,C.clientY-M.top)}function h(){if(!g)return;let{host:R,pointerId:C}=g;if(R.hasPointerCapture(C))R.releasePointerCapture(C);R.removeEventListener("pointermove",k),R.removeEventListener("pointerup",y),R.removeEventListener("pointercancel",E),g=null,u(!1)}function b(R){if(g||R.button!==0)return;let C=R.target;if(!(C instanceof Element))return;if(C.closest("[data-block-comment-btn]"))return;if(C.closest("[data-annotation-id]"))return;let M=C.closest(`[${io}]`);if(!(M instanceof HTMLElement)||!v?.contains(M))return;let L=M.closest("[data-md='image']")?.getAttribute("data-md-src");if(!L)return;let B=w(M,R);if(!B)return;R.preventDefault(),M.setPointerCapture(R.pointerId);let j=ve(),W=wn({...B,w:0,h:0},p.current,j);W.classList.add("ann-region-draft"),M.appendChild(W),g={pointerId:R.pointerId,host:M,src:L,start:B,shape:p.current,overlay:W,id:j},M.addEventListener("pointermove",k),M.addEventListener("pointerup",y),M.addEventListener("pointercancel",E),u(!0)}function k(R){if(!g||g.pointerId!==R.pointerId)return;let C=w(g.host,R);if(!C)return;kn(g.overlay,vn(g.start,C))}function y(R){if(!g||g.pointerId!==R.pointerId)return;let{overlay:C,id:M,src:L,shape:B}=g,j=w(g.host,R)??g.start,W=vn(g.start,j);if(h(),!lo(W)){C.remove();return}kn(C,W);let de={src:L,shape:B,...W};a({overlay:C,id:M,snippet:zt.format(de),label:yn(de)})}function E(R){if(!g||g.pointerId!==R.pointerId)return;g.overlay.remove(),h()}return v.addEventListener("pointerdown",b),()=>{if(v.removeEventListener("pointerdown",b),g)g.overlay.remove(),h()}},[n]),{popovers:l?ta(Ie,{anchorEl:l.overlay,scrollContainer:i,snippet:l.label,truncateAt:80,onAdd:(v,g)=>{l.overlay.classList.remove("ann-region-draft"),d.current(l.id,l.snippet,v,void 0,void 0,g,f.current),a(null)},onCancel:()=>{l.overlay.remove(),a(null)}},void 0,!1,void 0,this):null,isDrawing:c,isPopoverOpen:!!l}}import{useCallback as Ar,useEffect as Nn,useRef as pt,useState as Rr}from"react";import{jsxDEV as ko,Fragment as na}from"react/jsx-dev-runtime";function Je(e){let{containerRef:t,restoreKey:n,restoreAnnotations:r,extractContext:o,filePath:i,canvasFile:s,scrollContainer:l}=e,{annotations:a,addAnnotationWithId:c,removeAnnotation:u,updateAnnotation:d,addAnnotationImage:f,removeAnnotationImage:p,activeAnnotationId:m,setActiveAnnotationId:v}=Xe(),[g,w]=Rr(null),[h,b]=Rr(null),k=pt(o);k.current=o;let y=pt(i);y.current=i;let E=pt(s);E.current=s;let R=pt(c);R.current=c;let C=pt(m);C.current=m;let M=pt(v);M.current=v;let L=r.length;Nn(()=>{if(!t.current)return;let N=setTimeout(()=>{if(t.current)po(t.current,r)},50);return()=>clearTimeout(N)},[n,L]);let B=pt(null);Nn(()=>{Ft(m,B.current),B.current=m},[m]),Nn(()=>{let N=t.current;if(!N)return;let _=(G)=>{let J=G.target.closest("[data-annotation-id]");if(!J)return;G.stopPropagation();let V=J.getAttribute("data-annotation-id");if(V===C.current)w({anchorEl:J,annId:V});else M.current(V)},z=(G)=>{let J=G.target.closest("[data-annotation-id]");if(J)M.current(J.getAttribute("data-annotation-id"))},X=(G)=>{let J=G.target.closest("[data-annotation-id]"),V=G.relatedTarget?.closest?.("[data-annotation-id]");if(J&&!V&&!document.getElementById("ann-inline-popover"))M.current(null)};return N.addEventListener("click",_),N.addEventListener("mouseover",z),N.addEventListener("mouseout",X),()=>{N.removeEventListener("click",_),N.removeEventListener("mouseover",z),N.removeEventListener("mouseout",X)}},[n]),Nn(()=>{let N=()=>j();return document.addEventListener("mouseup",N),()=>document.removeEventListener("mouseup",N)},[]);let j=Ar(()=>{let N=window.getSelection();if(!N||N.isCollapsed||!N.toString().trim())return;if(!t.current)return;let _=N.getRangeAt(0);if(!t.current.contains(_.startContainer))return;if(_.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let z=dr(_).trim();if(z.length<2)return;let X=k.current(_),G=_.cloneRange(),J=`__pending_${Date.now()}`;try{Ue(G,J)}catch{}window.getSelection()?.removeAllRanges();let V=document.querySelectorAll(`[data-annotation-id="${J}"]`),O=V[V.length-1];if(!O)return;b({anchorEl:O,tempId:J,snippet:z,ctx:X})},[]),W=Ar((N,_,z,X)=>{b({anchorEl:N,tempId:_,snippet:z,ctx:X})},[]);return{popovers:ko(na,{children:[g&&(()=>{let N=a.find((_)=>_.id===g.annId);if(!N)return null;return ko(ut,{anchorEl:g.anchorEl,scrollContainer:l,initialNote:N.note,initialImages:N.images,onUpdate:(_,z)=>{d(g.annId,_);let X=N.images||[];for(let G of z)if(!X.includes(G))f(g.annId,G);for(let G of X)if(!z.includes(G))p(g.annId,G)},onDelete:()=>{u(g.annId),v(null)},onClose:()=>w(null)},void 0,!1,void 0,this)})(),h&&ko(Ie,{anchorEl:h.anchorEl,scrollContainer:l,snippet:h.snippet,truncateAt:80,onAdd:(N,_)=>{let z=ve();Bt(h.tempId,z),R.current(z,h.snippet,N,y.current,h.ctx,_,E.current),b(null)},onCancel:()=>{jt(h.tempId),b(null)}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),openCreatePopover:W,isPopoverOpen:!!(g||h)}}import{AnnotationCtx as ca,AnnotationHostContext as da}from"@fabrika/annotations/runtime";import{useCallback as At,useEffect as Mr,useMemo as ua,useRef as Ir,useState as Rt}from"react";function Pe(e,t,n="current"){let r=`canvas:${e}:rev:${t}`;return n==="next"?`${r}:next-draft`:r}function Et(e,t){return`${Pe(e,t)}:draft-handled`}function ft(e,t,n){try{e.removeItem(Pe(t,n)),e.removeItem(Et(t,n))}catch{}}function wo(e){if(!e)return null;try{let t=JSON.parse(e);return typeof t==="object"&&t!==null&&!Array.isArray(t)?t:null}catch{return null}}function oa(e){if(!Array.isArray(e)||e.length<2)return!1;let t=e[1];if(typeof t!=="object"||t===null||Array.isArray(t))return!1;let n=Reflect.get(t,"note");if(typeof n==="string"&&n.trim().length>0)return!0;let r=Reflect.get(t,"value");if(typeof r==="string")return r.trim().length>0;if(Array.isArray(r))return r.length>0;return r!==null&&r!==void 0}function Eo(e){if(!e)return!1;let t=Reflect.get(e,"annotations");if(Array.isArray(t)&&t.length>0)return!0;let n=Reflect.get(e,"generalNote");if(typeof n==="string"&&n.trim().length>0)return!0;let r=Reflect.get(e,"responses");return Array.isArray(r)&&r.some(oa)}function Tn(e,t,n,r){try{let o=Pe(t,n);if(Eo(wo(e.getItem(o))))return e.setItem(Et(t,n),"1"),null;if(e.getItem(Et(t,n))!==null)return null;let i=r.filter((s)=>s.revision<n).sort((s,l)=>l.revision-s.revision);for(let s of i){if(s.hasFeedback){let a=Pe(t,s.revision,"next"),c=wo(e.getItem(a));if(!Eo(c))return null;return e.setItem(o,JSON.stringify({...c,feedbackEntries:[]})),e.setItem(Et(t,n),"1"),e.removeItem(a),s.revision}let l=wo(e.getItem(Pe(t,s.revision)));if(!Eo(l)){if(e.getItem(Et(t,s.revision))!==null)return null;continue}return e.setItem(o,JSON.stringify({...l,feedbackEntries:[]})),e.setItem(Et(t,n),"1"),s.revision}}catch{}return null}function Ao(e,t){let n=new Map;for(let[r,o]of e)if(t.has(r))n.set(r,o);return n}function Ro(e,t){if(!e||e.length===0)return!1;return e.every((n)=>t.has(n))}function Zt(e,t,n,r,o){let i=[],s=e.filter((p)=>p.source!=="remote"||o&&o.has(p.id)),l=s.filter((p)=>p.filePath===Se),a=s.filter((p)=>!p.filePath),c=s.filter((p)=>p.filePath&&p.filePath!==Se),u=n?Array.from(n.values()).filter((p)=>Ln(p)):[],d=r?Array.from(r.values()).filter((p)=>p.markdown.trim()):[];if(u.length>0||d.length>0){i.push("## Responses"),i.push("");for(let p of u)i.push(ra(p));for(let p of d)i.push(p.markdown.trim()),i.push("")}if(l.length>0){i.push("## Annotations on agent response"),i.push("");for(let p of l)i.push(Kt(p))}if(a.length>0){i.push("## Canvas annotations"),i.push("");let p=new Map;for(let g of a){let w=g.canvasFile||"";if(!p.has(w))p.set(w,[]);p.get(w).push(g)}let m=[...p.keys()].sort(),v=m.length>1||m.length===1&&m[0]!=="";for(let g of m){let w=p.get(g);if(v&&g)i.push(`### ${g.replace(/\.jsx$/,"")}`),i.push("");let h=sa(w);i.push(Nr(h))}}if(c.length>0){let p={};for(let m of c){let v=m.filePath;if(!p[v])p[v]=[];p[v].push(m)}i.push("## File annotations"),i.push("");for(let[m,v]of Object.entries(p)){i.push(`### ${m}`),i.push("");for(let g of v)i.push(Kt(g))}}if(t.trim())i.push("## General notes"),i.push(""),i.push(t.trim()),i.push("");return i.join(`
|
|
66
|
+
`).trim()+`
|
|
67
|
+
`}function Ln(e){if(e.note?.trim())return!0;if(e.value===null||e.value===void 0)return!1;if(e.type==="text"&&!e.value.trim())return!1;if(e.type==="checkbox"&&e.value.length===0)return!1;return!0}function Sr(e){let t=[];for(let n of e.values()){if(!n.required)continue;if(n.value===null||n.value===void 0){t.push(n);continue}if(n.type==="text"&&!n.value.trim()){t.push(n);continue}if(n.type==="checkbox"&&n.value.length===0){t.push(n);continue}}return t}function Cr(e){let t=[];for(let n of e.values())if(n.required&&!n.markdown.trim())t.push(n);return t}function Xt(e,t){let n=Sr(e),r=Cr(t);return[...n.map((o)=>o.label),...r.map((o)=>o.label||o.id)]}function ra(e){let t=[];switch(t.push(`**${e.label}**`),e.type){case"radio":case"select":t.push(`Answer: ${e.value}`);break;case"checkbox":for(let n of e.value)t.push(`- [x] ${n}`);break;case"text":t.push(""),t.push(e.value.trim());break;case"range":t.push(`Answer: ${e.value}`);break}if(e.note?.trim())t.push(""),t.push(`Note: ${e.note.trim()}`);return t.push(""),t.join(`
|
|
68
|
+
`)}function sa(e){let t={label:"",annotations:[],children:new Map};for(let n of e){let r=n.context?.hierarchy||[],o=t;for(let i of r){if(!o.children.has(i))o.children.set(i,{label:i,annotations:[],children:new Map});o=o.children.get(i)}o.annotations.push(n)}return t}function Nr(e,t=0){let n=[];for(let r of e.annotations)n.push(Kt(r));for(let[,r]of e.children){let o=t===0?"###":"####";n.push(`${o} ${r.label}`),n.push(""),n.push(Nr(r,t+1))}return n.join(`
|
|
69
|
+
`)}import{createContext as ia,useContext as aa}from"react";function Tr(){if(typeof window>"u")return"";return window.location.pathname.replace("/s/","")}var Lr={get sessionId(){return Tr()},isShared:!1,fsAvailable:!0,uploadUrl:null,loadCanvasModule:(e,t)=>{let n=e.replace(/\.jsx$/,".js"),r=t?`?rev=${t}&t=${Date.now()}`:`?t=${Date.now()}`;return import(`/api/session/${Tr()}/canvas/${encodeURIComponent(n)}${r}`)}},Mn=ia(Lr);function _e(){return aa(Mn)}import{useAnnotations as mt}from"#canvas/runtime";import{jsxDEV as Co}from"react/jsx-dev-runtime";function Pr(e,t,n){try{let r=localStorage.getItem(Pe(e,t,n));if(!r)return null;return JSON.parse(r)}catch{return null}}function pa(e,t,n,r){try{localStorage.setItem(Pe(e,t,n),JSON.stringify(r))}catch{}}function So(e){return{draft:e,responseIds:new Set,canvases:new Set}}function No({sessionId:e,revision:t,isReadOnly:n,draftPhase:r,remoteAnnotations:o,canvasFiles:i,loadState:s,saveState:l,children:a}){let c=!!s,u=c?null:Pr(e,t,r),[d,f]=Rt(()=>(u?.annotations??[]).map((V)=>({...V,source:V.source??"local"}))),[p,m]=Rt(()=>u?.generalNote??""),[v,g]=Rt(()=>u?.responses?new Map(u.responses):new Map),w=`${e}:${t}:${r}`,h=Ir(w);h.current=w;let[b,k]=Rt(()=>So(w)),[y,E]=Rt(()=>u?.feedbackEntries?new Map(u.feedbackEntries):new Map),[R,C]=Rt(!c);Mr(()=>{let V=(O)=>{f((O?.annotations??[]).map((Z)=>({...Z,source:Z.source??"local"}))),m(O?.generalNote??""),g(O?.responses?new Map(O.responses):new Map),E(O?.feedbackEntries?new Map(O.feedbackEntries):new Map),G(null)};if(c){let O=!1;return C(!1),s(e,t,r).then((Z)=>{if(O)return;V(Z),C(!0)}),()=>{O=!0}}V(Pr(e,t,r)),C(!0);return},[e,t,r,c,s]);let M=Ir(null);Mr(()=>{if(n&&r!=="next")return;if(!R)return;if(M.current)clearTimeout(M.current);let V={annotations:d,generalNote:p,responses:Array.from(v.entries()),feedbackEntries:Array.from(y.entries())},O=()=>{if(l)l(e,t,V,r);else pa(e,t,r,V)};if(r==="next"){O();return}return M.current=setTimeout(O,300),()=>{if(M.current)clearTimeout(M.current)}},[d,p,v,y,e,t,n,r,R,l]);let L=At((V,O)=>{g((Z)=>{let ue=new Map(Z);return ue.set(V,O),ue})},[]),B=At((V)=>{k((O)=>{let Z=O.draft===h.current?O:So(h.current);if(Z.responseIds.has(V))return Z;return{...Z,responseIds:new Set(Z.responseIds).add(V)}})},[]),j=At((V)=>{k((O)=>{let Z=O.draft===h.current?O:So(h.current);if(Z.canvases.has(V))return Z;return{...Z,canvases:new Set(Z.canvases).add(V)}})},[]),W=b.draft===w?b:null,de=ua(()=>{if(!W||!Ro(i,W.canvases))return v;return Ao(v,W.responseIds)},[W,i,v]),N=At((V,O)=>{E((Z)=>{let ue=Z.get(V);if(ue&&ue.markdown===O.markdown&&ue.label===O.label&&ue.required===O.required)return Z;let A=new Map(Z);return A.set(V,O),A})},[]),_=At((V)=>{E((O)=>{if(!O.has(V))return O;let Z=new Map(O);return Z.delete(V),Z})},[]),z=At(()=>{if(g(new Map),E(new Map),l)l(e,t,{annotations:[],generalNote:"",responses:[],feedbackEntries:[]},r);else if(r==="next")localStorage.removeItem(Pe(e,t,r));else ft(localStorage,e,t)},[e,t,r,l]),X=An({annotations:d,setAnnotations:f,generalNote:p,setGeneralNote:m,remoteAnnotations:o,isReadOnly:n,onClear:z}),{setActiveAnnotationId:G}=X,J=_e();return Co(da.Provider,{value:J,children:Co(ca.Provider,{value:X,children:Co(la.Provider,{value:{...X,responses:v,setResponse:L,submittableResponses:de,registerResponse:B,registerCanvasRendered:j,feedbackEntries:y,setFeedbackEntry:N,removeFeedbackEntry:_},children:a},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}import{ActiveViewCtx as Im,AnnotationCtx as Pm,CanvasFileCtx as $m,SessionContext as Hm,useAnnotations as De,useCanvasFile as Dm,useFeedback as Om,useResponseRegistration as Fm}from"#canvas/runtime";function Jt(e){let t=document.querySelector(`[data-annotation-id="${e.id}"]`);if(t instanceof HTMLElement)return t;let n=e.canvasFile?document.querySelector(`[data-canvas-file="${e.canvasFile}"]`):document;if(!n)return null;return uo(e.snippet,n)}function $r(e){e.classList.remove("ann-flash"),e.offsetWidth,e.classList.add("ann-flash"),e.addEventListener("animationend",()=>{e.classList.remove("ann-flash")},{once:!0})}function To(e,t){let n=lt(e);if(n)t({type:"file",path:n}),setTimeout(()=>{let r=Jt(e);if(r)r.scrollIntoView({behavior:"smooth",block:"center"}),$r(r)},150);else{let r=Jt(e);if(r)r.scrollIntoView({behavior:"smooth",block:"center"}),$r(r)}}import{SessionContext as ba}from"#canvas/runtime";import{useCallback as Io,useContext as Po,useEffect as Fr,useMemo as va,useState as St}from"react";import{createContext as Hr}from"react";var $e=Hr({activeView:{type:"overview"},setActiveView:()=>{},openFiles:[],closeFile:()=>{},canvasFiles:[]}),ke=Hr({currentRevision:1,selectedRevision:1,revisions:[],setSelectedRevision:()=>{},isReadOnly:!1,compareRevision:null,setCompareRevision:()=>{},agentWatching:!1});import{jsxDEV as ht}from"react/jsx-dev-runtime";var fa={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"},ma={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 Ye({name:e,type:t,expanded:n,className:r=""}){if(t==="dir")return ht("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",className:`flex-shrink-0 ${r}`,children:n?ht("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):ht("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 o=e.includes(".")?e.split(".").pop().toLowerCase():"",i=fa[o]||"#6b6560",s=ma[o];return ht("svg",{width:"14",height:"14",viewBox:"0 0 16 16",className:`flex-shrink-0 ${r}`,children:[ht("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:i,opacity:"0.85"},void 0,!1,void 0,this),ht("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),s&&ht("text",{x:"8",y:"11.5",textAnchor:"middle",fill:"white",fontSize:"5.5",fontFamily:"monospace",fontWeight:"600",children:s},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{useEffect as Dr,useMemo as Lo,useRef as ha,useState as Yt}from"react";import{jsxDEV as ce}from"react/jsx-dev-runtime";function Mo({open:e,onClose:t,onSubmit:n,includedRemoteIds:r,onToggleRemoteId:o}){let{annotations:i,generalNote:s,submittableResponses:l,feedbackEntries:a}=mt(),[c,u]=Yt(""),[d,f]=Yt(!1),[p,m]=Yt(!1),[v,g]=Yt(null),w=ha(null),[h,b]=Yt(!1),k=Lo(()=>i.filter((C)=>C.source==="remote"),[i]);if(e&&!h)f(!1),m(!1),g(null);if(!e&&h)f(!1),m(!1),g(null);if(e!==h)b(e);let y=Lo(()=>Zt(i,s,l,a,r),[i,s,l,a,r]),E=d?c:y;if(Dr(()=>{if(e&&p&&w.current)w.current.focus()},[e,p]),Dr(()=>{if(!e)return;let C=(M)=>{if(M.key==="Escape")t()};return window.addEventListener("keydown",C),()=>window.removeEventListener("keydown",C)},[e,t]),!e)return null;let R=E.trim().length>0;return ce("div",{className:"fixed inset-0 z-50 bg-black/50 backdrop-blur-sm flex items-center justify-center p-8",onClick:t,children:ce("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:[ce("div",{className:"flex items-center justify-between px-5 py-3 border-b border-border-subtle flex-shrink-0",children:[ce("div",{className:"flex items-center gap-3",children:[ce("span",{className:"text-[13px] font-medium text-text-primary font-body",children:"Response preview"},void 0,!1,void 0,this),d&&ce("button",{onClick:()=>{f(!1),m(!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),ce("div",{className:"flex items-center gap-2",children:[ce("div",{className:"flex items-center bg-bg-base rounded-md p-0.5",children:[ce("button",{onClick:()=>m(!1),className:`px-2.5 py-1 rounded text-[11px] font-body font-medium transition-colors ${!p?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Preview"},void 0,!1,void 0,this),ce("button",{onClick:()=>m(!0),className:`px-2.5 py-1 rounded text-[11px] font-body font-medium transition-colors ${p?"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),ce("button",{onClick:t,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),p?ce("textarea",{ref:w,value:E,onChange:(C)=>{u(C.currentTarget.value),f(!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):ce("div",{className:"flex-1 overflow-y-auto p-5",children:ce(In,{text:E},void 0,!1,void 0,this)},void 0,!1,void 0,this),k.length>0&&ce("div",{className:"px-5 py-2 border-t border-border-subtle flex-shrink-0",children:ce("span",{className:"text-[12px] text-text-secondary font-body",children:["Reviewer feedback: ",r.size,"/",k.length," included"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),v&&ce("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:[ce("span",{children:v},void 0,!1,void 0,this),ce("button",{onClick:()=>{g(null),n(E)},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),ce("div",{className:"flex justify-end gap-2 px-5 py-3 border-t border-border-subtle flex-shrink-0",children:[ce("button",{onClick:t,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),ce("button",{onClick:()=>{let C=Xt(l,a);if(C.length>0){g(`Please answer: ${C.join(", ")}`);return}g(null),n(E)},disabled:!R,className:`px-6 py-2 rounded-lg font-body text-[13px] font-medium transition-all ${R?"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 ga=/!\[([^\]]*)\]\((\/tmp\/agent-canvas\/uploads\/([^)]+))\)/g;function xa(e){return e.replace(ga,(t,n,r,o)=>``)}function In({text:e}){let t=Lo(()=>Q.parse(xa(e),{async:!1}),[e]);return ce("div",{className:"prose-canvas font-body text-body text-text-primary leading-relaxed",dangerouslySetInnerHTML:{__html:t}},void 0,!1,void 0,this)}import{jsxDEV as I,Fragment as Pn}from"react/jsx-dev-runtime";function $n({onSubmit:e,collapseButton:t}){let{isReadOnly:n,selectedRevision:r,currentRevision:o,revisions:i,agentWatching:s}=Po(ke),l=Po(ba),a=i.find((f)=>f.revision===r),c=n&&r===o,u=!!a?.feedbackConsumed,d=a?.label||`Round ${r}`;if(n)return I(ka,{sessionId:l,revision:r,label:d,waitingForUpdate:c,feedbackConsumed:u,agentWatching:s,collapseButton:t},void 0,!1,void 0,this);return I(Ea,{onSubmit:e,agentWatching:s,collapseButton:t},void 0,!1,void 0,this)}function ya({sessionId:e,revision:t,label:n,waitingForUpdate:r,feedbackConsumed:o,agentWatching:i,collapseButton:s}){let a=_e().isShared;return I("div",{className:"flex flex-col h-full",children:[I("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[I("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:r?"Feedback sent":`Feedback — ${n}`},void 0,!1,void 0,this),s]},void 0,!0,void 0,this),r&&!a&&I(Br,{feedbackConsumed:o,agentWatching:i},void 0,!1,void 0,this),I(_r,{sessionId:e,revision:t},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Br({feedbackConsumed:e,agentWatching:t}){if(e)return I("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:[I("span",{className:"w-2 h-2 rounded-full bg-accent-green animate-pulse"},void 0,!1,void 0,this),I("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(t)return I("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:[I("span",{className:"w-2 h-2 rounded-full bg-accent-blue animate-pulse"},void 0,!1,void 0,this),I("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 I("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:[I("span",{className:"w-2 h-2 rounded-full bg-accent-amber"},void 0,!1,void 0,this),I("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 ka({sessionId:e,revision:t,label:n,waitingForUpdate:r,feedbackConsumed:o,agentWatching:i,collapseButton:s}){let{annotations:l,generalNote:a}=mt(),c=l.length>0||a.trim().length>0,[u,d]=St("feedback");if(!c)return I(ya,{sessionId:e,revision:t,label:n,waitingForUpdate:r,feedbackConsumed:o,agentWatching:i,collapseButton:s},void 0,!1,void 0,this);return I("div",{className:"flex flex-col h-full",children:[I("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[I("div",{className:"flex items-center gap-1 bg-bg-input rounded-md p-0.5",children:[I("button",{onClick:()=>d("feedback"),className:`px-2.5 py-1 rounded text-[11px] font-medium font-body transition-colors ${u==="feedback"?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Feedback"},void 0,!1,void 0,this),I("button",{onClick:()=>d("annotations"),className:`px-2.5 py-1 rounded text-[11px] font-medium font-body transition-colors flex items-center gap-1.5 ${u==="annotations"?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:["Annotations",I("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:l.length},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),s]},void 0,!0,void 0,this),r&&I(Br,{feedbackConsumed:o,agentWatching:i},void 0,!1,void 0,this),u==="feedback"?I(_r,{sessionId:e,revision:t},void 0,!1,void 0,this):I(Pn,{children:[I("div",{className:"flex-1 overflow-y-auto",children:I(jr,{annotations:l,readOnly:!0},void 0,!1,void 0,this)},void 0,!1,void 0,this),a.trim()&&I("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:I("div",{className:"text-[13px] font-body text-text-primary leading-relaxed",children:a},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 _r({sessionId:e,revision:t}){let n=_e(),[r,o]=St(null),[i,s]=St(!0);return Fr(()=>{if(s(!0),!n.fsAvailable){o(null),s(!1);return}fetch(`/api/session/${e}/revision/${t}/feedback`).then((l)=>l.json()).then((l)=>{o(l.feedback||null),s(!1)}).catch(()=>{o(null),s(!1)})},[e,t]),I("div",{className:"flex-1 overflow-y-auto px-4",children:i?I("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"Loading..."},void 0,!1,void 0,this):r?I(In,{text:r},void 0,!1,void 0,this):I("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 wa(e){let t=e.filter((s)=>s.filePath===Se),n=e.filter((s)=>!s.filePath),r=e.filter((s)=>lt(s)!==void 0),o={};for(let s of r){let l=lt(s);if(!l)continue;let a=o[l];if(a)a.push(s);else o[l]=[s]}let i=[t,n,r].filter((s)=>s.length>0).length>1;return{response:t,plan:n,fileGroups:o,hasMultipleGroups:i}}function Or({children:e}){return I("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body px-3 mb-1 mt-1",children:e},void 0,!1,void 0,this)}function jr({annotations:e,readOnly:t,includedRemoteIds:n,onToggleRemoteId:r}){let{setActiveView:o}=Po($e),{response:i,plan:s,fileGroups:l,hasMultipleGroups:a}=wa(e),c=Io((f)=>{let p=lt(f);if(!p)return;o({type:"file",path:p}),setTimeout(()=>{let m=Jt(f);if(m)m.scrollIntoView({behavior:"smooth",block:"center"})},150)},[o]),u=Io((f)=>To(f,o),[o]),d={readOnly:t,onSelect:c,onReveal:u,includedRemoteIds:n,onToggleRemoteId:r};return I(Pn,{children:[i.length>0&&I(Pn,{children:[a&&I(Or,{children:"Agent Response"},void 0,!1,void 0,this),I(Gt,{annotations:i,...d},void 0,!1,void 0,this)]},void 0,!0,void 0,this),s.length>0&&I(Pn,{children:[a&&I(Or,{children:"Canvas"},void 0,!1,void 0,this),I(Gt,{annotations:s,...d},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Object.entries(l).map(([f,p])=>I("div",{children:[I("button",{onClick:()=>o({type:"file",path:f}),className:"flex items-center gap-1.5 text-[10px] uppercase tracking-widest text-text-tertiary hover:text-text-secondary font-body px-3 pt-3 pb-1 truncate transition-colors w-full text-left",title:f,children:[I(Ye,{name:f.split("/").pop()||f,type:"file"},void 0,!1,void 0,this),I("span",{className:"truncate",children:f},void 0,!1,void 0,this)]},void 0,!0,void 0,this),I(Gt,{annotations:p,...d},void 0,!1,void 0,this)]},f,!0,void 0,this))]},void 0,!0,void 0,this)}function Ea({onSubmit:e,agentWatching:t,collapseButton:n}){let r=_e(),[o,i]=St(!1),{annotations:s,generalNote:l,submittableResponses:a,feedbackEntries:c}=mt(),u=va(()=>s.filter((k)=>k.source==="remote"),[s]),[d,f]=St(()=>new Set);Fr(()=>{if(u.length===0)return;f((k)=>{let y=new Set(k);for(let E of u)y.add(E.id);return y.size===k.size?k:y})},[u]);let p=Io((k)=>{f((y)=>{let E=new Set(y);if(E.has(k))E.delete(k);else E.add(k);return E})},[]),m=Array.from(a.values()).some(Ln),v=c.size>0,g=s.length>0||l.trim().length>0||m||v,[w,h]=St(null),b=()=>{let k=Zt(s,l,a,c,d);e(k)};return I("div",{className:"flex flex-col h-full",children:[I("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[I("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body flex items-center gap-2",children:["Annotations",s.length>0&&I("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:s.length},void 0,!1,void 0,this),!r.isShared&&I("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${t?"bg-accent-green":"bg-accent-amber"}`,title:t?"Agent connected":"Agent disconnected"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),n]},void 0,!0,void 0,this),I("div",{className:"flex-1 overflow-y-auto",children:[s.length===0&&I("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),I(jr,{annotations:s,includedRemoteIds:d,onToggleRemoteId:p},void 0,!1,void 0,this)]},void 0,!0,void 0,this),I(fo,{hasContent:g,onSubmit:()=>{let k=Xt(a,c);if(k.length>0){h(`Please answer: ${k.join(", ")}`);return}h(null),b()},onSubmitEmpty:()=>e("No feedback — looks good."),notice:w&&I("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:[I("span",{children:w},void 0,!1,void 0,this),I("button",{onClick:()=>{h(null),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),secondaryAction:I("button",{onClick:()=>i(!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),I(Mo,{open:o,onClose:()=>i(!1),onSubmit:e,includedRemoteIds:d,onToggleRemoteId:p},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{useFeedback as nm}from"#canvas/runtime";import ap from"react";Q.setOptions({gfm:!0,breaks:!1});import{useAnnotations as hp,useResponseRegistration as gp}from"#canvas/runtime";import{useEffect as vp,useMemo as yp,useRef as kp,useState as wp}from"react";import{useEffect as Cp,useRef as Np}from"react";import{ActiveViewCtx as Hp,SessionContext as Dp}from"#canvas/runtime";import{useContext as Bp,useEffect as _p,useRef as jp,useState as qp}from"react";import{SessionContext as Wp}from"#canvas/runtime";import{useContext as Kp,useState as Zp}from"react";import{useMemo as ef}from"react";Q.setOptions({gfm:!0,breaks:!1});import{useAnnotations as of,useCanvasFile as rf}from"#canvas/runtime";import{useCallback as cf,useEffect as df,useRef as uf,useState as pf}from"react";import mf from"react-dom";import{useState as kf}from"react";import{useAnnotations as Nf,useResponseRegistration as Tf}from"#canvas/runtime";import{useRef as Pf,useState as $f}from"react";import{CanvasFileCtx as Ca,SessionContext as Na}from"#canvas/runtime";import Hn,{useContext as qr,useEffect as Qe,useMemo as en,useRef as Ta,useState as He}from"react";import{createPortal as La}from"react-dom";import{createContext as Sa}from"react";var Qt=Sa(()=>{});import{jsxDEV as se,Fragment as $a}from"react/jsx-dev-runtime";class zr extends Hn.Component{state={error:null};static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,t){this.props.reportError({revision:this.props.revision,filename:this.props.filename,message:e.message,...e.stack?{stack:e.stack}:{},...t.componentStack?{componentStack:t.componentStack}:{}})}render(){if(!this.state.error)return this.props.children;return se(Vr,{message:this.state.error.message},void 0,!1,void 0,this)}}function Vr({message:e}){return se("div",{className:"bg-accent-red-muted rounded-lg p-5",children:[se("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Canvas render failed"},void 0,!1,void 0,this),se("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:e},void 0,!1,void 0,this),se("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 Ct({revision:e,filename:t}){let n=qr(Na),r=_e(),o=qr(Qt),[i,s]=He(null),[l,a]=He(null),[c,u]=He(!0),d=Ta(null),{annotations:f,addAnnotationWithId:p,removeAnnotation:m,updateAnnotation:v,addAnnotationImage:g,removeAnnotationImage:w,activeAnnotationId:h,setActiveAnnotationId:b,registerCanvasRendered:k}=mt(),y=en(()=>f.filter((A)=>!A.filePath&&(!A.canvasFile||A.canvasFile===t)),[f,t]),[E,R]=He(null),[C,M]=He(null),[L,B]=He(null),[j,W]=He(null),[de,N]=He(!1);Qe(()=>{u(!0),a(null),W(null),r.loadCanvasModule(t,e).then((A)=>{s(()=>A.default),u(!1)}).catch((A)=>{let P=A instanceof Error?A:Error(String(A));a(P.message),u(!1),o({revision:e,filename:t,message:P.message,...P.stack?{stack:P.stack}:{}})})},[n,e,t,o]),Qe(()=>{if(i)k(t)},[i,t,k]);let _=document.getElementById("plan-scroll-container"),{popovers:z,isPopoverOpen:X}=Je({containerRef:d,restoreKey:i,restoreAnnotations:y,extractContext:(A)=>Ge(A,d.current),canvasFile:t,scrollContainer:_}),{popovers:G,isDrawing:J,isPopoverOpen:V}=yo({containerRef:d,restoreKey:i,canvasFile:t,scrollContainer:_}),O=X||V,Z=en(()=>{let A=new Map;for(let P of y)if(P.snippet.startsWith("["))A.set(P.snippet,P.id);return A},[y]);Qe(()=>{let A=d.current;if(!A)return;let P=(T)=>{if(L||O||J)return;let H=T.target;if(H.closest("[data-block-comment-btn]"))return;N(!1);let F=H.closest(kt);if(F&&A.contains(F)){let pe=gt(A).indexOf(F);W(pe>=0?pe:null)}else W(null);let oe=H.closest(Ke);if(oe&&A.contains(oe)){M(oe);let ae=Me(oe),pe=ae?Z.get(ae):void 0;if(pe&&pe!==h)b(pe)}else M(null)},Y=(T)=>{if(L||O)return;if(T.relatedTarget?.closest("[data-block-comment-btn]"))return;M(null),b(null)};return A.addEventListener("mousemove",P),A.addEventListener("mouseleave",Y),()=>{A.removeEventListener("mousemove",P),A.removeEventListener("mouseleave",Y)}},[i,L,O,J,Z,h]),Qe(()=>{let A=(P)=>{let Y=P.target.tagName;if(Y==="INPUT"||Y==="TEXTAREA"||P.target.isContentEditable)return;if(L||O)return;let T=d.current;if(!T)return;if(P.key==="ArrowDown"){P.preventDefault(),N(!0);let H=gt(T);if(H.length===0)return;W((F)=>{if(F===null)return 0;return Math.min(F+1,H.length-1)})}else if(P.key==="ArrowUp"){P.preventDefault(),N(!0);let H=gt(T);if(H.length===0)return;W((F)=>{if(F===null)return H.length-1;return Math.max(F-1,0)})}else if(P.key==="a"||P.key==="A"){if(j===null||!T)return;let F=gt(T)[j];if(!F)return;if(!F.matches(Ke))return;P.preventDefault();let oe=Me(F);if(!oe)return;let ae=Z.get(oe);if(ae)b(ae),B({anchorEl:F,snippet:oe,annId:ae});else B({anchorEl:F,snippet:oe})}else if(P.key===" "||P.key==="Enter"){if(j===null)return;let F=gt(T)[j];if(!F)return;let oe=F.getAttribute("data-md");if(oe==="choice-option"||oe==="multichoice-option")P.preventDefault(),F.dispatchEvent(new CustomEvent("kb-select",{bubbles:!0}));else if(oe==="userinput"){P.preventDefault();let ae=F.querySelector("textarea");if(ae){ae.focus();let pe=(Te)=>{if(Te.key==="Escape")Te.preventDefault(),ae.blur(),N(!0)};ae.addEventListener("keydown",pe),ae.addEventListener("blur",()=>ae.removeEventListener("keydown",pe),{once:!0})}}else if(oe==="rangeinput"){P.preventDefault();let ae=F.querySelector("input[type='range']");if(ae){ae.focus();let pe=(Te)=>{if(Te.key==="Escape"||Te.key==="ArrowUp"||Te.key==="ArrowDown")Te.preventDefault(),ae.blur(),N(!0)};ae.addEventListener("keydown",pe),ae.addEventListener("blur",()=>ae.removeEventListener("keydown",pe),{once:!0})}}}else if(P.key==="Escape")W(null),N(!1),b(null)};return document.addEventListener("keydown",A),()=>document.removeEventListener("keydown",A)},[j,L,O,Z]),Qe(()=>{let A=d.current;if(!A||j===null||!de)return;let Y=gt(A)[j];if(!Y)return;Y.style.outline="2px solid var(--color-accent-blue)",Y.style.outlineOffset="-2px",Y.style.borderRadius="8px",Y.scrollIntoView({block:"nearest",behavior:"smooth"});let T=Me(Y),H=T?Z.get(T):void 0;if(H)b(H);return()=>{Y.style.outline="",Y.style.outlineOffset="",Y.style.borderRadius=""}},[j,de,Z]);let ue=en(()=>i?se(i,{},void 0,!1,void 0,this):null,[i]);if(c)return se("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(l)return se(Vr,{message:l},void 0,!1,void 0,this);if(!i)return se("div",{className:"text-text-tertiary text-center py-8 font-body text-body",children:"No canvas loaded"},void 0,!1,void 0,this);return se(Ca.Provider,{value:t,children:[se("div",{ref:d,className:"plan-content plan-updated","data-canvas-file":t,children:se(zr,{revision:e,filename:t,reportError:o,children:ue},`${e}:${t}`,!1,void 0,this)},void 0,!1,void 0,this),E&&se(Pa,{note:E.note,onSave:(A)=>{v(E.id,A),R(null)},onCancel:()=>R(null)},void 0,!1,void 0,this),z,G,se(Ma,{containerRef:d,hoveredBlock:C,focusedBlockIndex:j,blockPopover:L,blockAnnotationMap:Z,activeAnnotationId:h,onOpen:(A,P,Y)=>{if(Y)b(Y),B({anchorEl:A,snippet:P,annId:Y});else B({anchorEl:A,snippet:P})}},void 0,!1,void 0,this),L&&!L.annId&&se(Ie,{anchorEl:L.anchorEl,scrollContainer:_,snippet:L.snippet,truncateAt:80,onAdd:(A,P)=>{let Y=ve();p(Y,L.snippet,A,void 0,void 0,P,t),B(null)},onCancel:()=>B(null)},void 0,!1,void 0,this),L?.annId&&(()=>{let A=y.find((P)=>P.id===L.annId);if(!A)return null;return se(ut,{anchorEl:L.anchorEl,scrollContainer:_,initialNote:A.note,initialImages:A.images,onUpdate:(P,Y)=>{v(L.annId,P);let T=A.images||[];for(let H of Y)if(!T.includes(H))g(L.annId,H);for(let H of T)if(!Y.includes(H))w(L.annId,H)},onDelete:()=>{m(L.annId),b(null),B(null)},onClose:()=>B(null)},void 0,!1,void 0,this)})()]},void 0,!0,void 0,this)}function gt(e){return Array.from(e.querySelectorAll(kt))}function Ma({containerRef:e,hoveredBlock:t,focusedBlockIndex:n,blockPopover:r,blockAnnotationMap:o,activeAnnotationId:i,onOpen:s}){let[l,a]=He([]);Qe(()=>{let p=e.current;if(!p||o.size===0){a([]);return}let m=[];for(let v of p.querySelectorAll(Ke)){let g=Me(v);if(g&&o.has(g))m.push(v)}a(m)},[o,e.current]);let[c,u]=He(null);Qe(()=>{if(!i||!e.current){u(null);return}for(let p of e.current.querySelectorAll(kt)){let m=Me(p);if(m&&o.get(m)===i){u(p);return}}u(null)},[i,o]),Qe(()=>{if(!c)return;return c.style.boxShadow="inset 0 0 0 1.5px var(--color-highlight-bg)",c.style.borderRadius="8px",()=>{c.style.boxShadow="",c.style.borderRadius=""}},[c]);let d=en(()=>{if(n===null||!e.current)return null;let p=gt(e.current)[n];if(!p)return null;return p.matches(Ke)?p:null},[n,e.current]),f=en(()=>{let p=new Set(l);if(t)p.add(t);if(d)p.add(d);if(r?.anchorEl)p.add(r.anchorEl);return Array.from(p)},[l,t,d,r]);return se($a,{children:f.map((p)=>se(Ia,{block:p,isHovered:p===t||p===d||p===r?.anchorEl,blockAnnotationMap:o,activeAnnotationId:i,onOpen:s},p.getAttribute("data-task-id")||p.getAttribute("data-md-title")||p.textContent?.slice(0,30)||"block",!1,void 0,this))},void 0,!1,void 0,this)}function Ia({block:e,isHovered:t,blockAnnotationMap:n,activeAnnotationId:r,onOpen:o}){let i=Me(e);if(!i)return null;let s=n.get(i),l=!!s;return La(se("button",{"data-block-comment-btn":!0,onClick:(c)=>{c.stopPropagation(),o(c.currentTarget,i,s)},className:`absolute top-1 right-1 z-10 w-6 h-6 flex items-center justify-center rounded transition-all duration-150 ${l?s===r?"text-accent-amber bg-accent-amber-muted":"text-accent-amber opacity-60 hover:opacity-100":t?"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:l?"Edit annotation":"Add annotation",children:se("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:l?"currentColor":"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:se("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),e)}function Pa({note:e,onSave:t,onCancel:n}){let[r,o]=Hn.useState(e),i=Hn.useRef(null);return Hn.useEffect(()=>{i.current?.focus(),i.current?.select()},[]),se("div",{className:"fixed inset-0 z-50 bg-black/40 flex items-center justify-center",onClick:n,children:se("div",{className:"bg-bg-elevated border border-border-hover rounded-lg shadow-md p-4 w-80",onClick:(s)=>s.stopPropagation(),children:[se("div",{className:"text-tiny uppercase tracking-widest text-text-tertiary font-body mb-2",children:"Edit annotation"},void 0,!1,void 0,this),se("textarea",{ref:i,value:r,onChange:(s)=>o(s.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:(s)=>{if(s.key==="Enter"&&(s.ctrlKey||s.metaKey))t(r.trim());if(s.key==="Escape")n()}},void 0,!1,void 0,this),se("div",{className:"flex justify-end gap-2 mt-2",children:[se("button",{onClick:n,className:"text-meta text-text-tertiary font-body px-3 py-1",children:"Cancel"},void 0,!1,void 0,this),se("button",{onClick:()=>t(r.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{useEffect as Ua,useState as es,useContext as ts,useMemo as Ga}from"react";import{SessionContext as Ka}from"#canvas/runtime";var Wr={alg:"AES-GCM",v:1};async function Ur(e){let t=Da(e);return crypto.subtle.importKey("raw",t,{name:"AES-GCM",length:256},!1,["encrypt","decrypt"])}async function et(e,t){let n=crypto.getRandomValues(new Uint8Array(12)),r=new TextEncoder().encode(t),o=await crypto.subtle.encrypt({name:"AES-GCM",iv:n},e,r),i=new Uint8Array(n.byteLength+o.byteLength);return i.set(n,0),i.set(new Uint8Array(o),n.byteLength),Ha(i)}async function tn(e,t){let n=Gr(t);if(n.byteLength<28)throw Error("Ciphertext too short");let r=n.subarray(0,12),o=n.subarray(12),i=await crypto.subtle.decrypt({name:"AES-GCM",iv:r},e,o);return new TextDecoder().decode(i)}function Ha(e){let t="",n=32768;for(let r=0;r<e.byteLength;r+=n)t+=String.fromCharCode.apply(null,Array.from(e.subarray(r,r+n)));return btoa(t)}function Gr(e){let t=atob(e),n=new Uint8Array(t.length);for(let r=0;r<t.length;r++)n[r]=t.charCodeAt(r);return n}function Da(e){let t=e.replace(/-/g,"+").replace(/_/g,"/")+"===".slice((e.length+3)%4);return Gr(t)}function Oa(){if(typeof window>"u")return null;let e=window.location.hash.replace(/^#/,"");if(!e)return null;for(let t of e.split("&")){let[n,r]=t.split("=");if(n==="k"&&r)return decodeURIComponent(r)}return null}function Fa(){if(typeof window<"u"&&window.__CANVAS_SHARE__?.shareId){let t=Oa();return{isShared:!0,shareId:window.__CANVAS_SHARE__.shareId,encryptionKey:t?Ur(t):null}}return{isShared:!1,sessionId:typeof window<"u"?window.location.pathname.replace("/s/",""):""}}var re=Fa();function Ba(){return re.isShared&&re.encryptionKey!==null}function _a(){return re.isShared?re.shareId:re.sessionId}function ja(){if(re.isShared)return`/s/${re.shareId}/meta`;return`/api/session/${re.sessionId}/meta`}function qa(e,t){let n=e.replace(/\.jsx$/,".js");if(re.isShared)return`/s/${re.shareId}/canvas/${encodeURIComponent(n)}`;let r=t?`?rev=${t}&t=${Date.now()}`:`?t=${Date.now()}`;return`/api/session/${re.sessionId}/canvas/${encodeURIComponent(n)}${r}`}function za(){if(re.isShared)return`/s/${re.shareId}/upload`;return`/api/session/${re.sessionId}/upload`}async function Kr(){let e=await fetch(ja());if(!e.ok)throw Error(`meta ${e.status}`);let t=await e.json();if(t.encryption&&re.isShared&&re.encryptionKey){let n=await re.encryptionKey;if(t.origin){let o={...t.origin};if(o.sessionId)o.sessionId=await tn(n,o.sessionId);if(o.label)o.label=await tn(n,o.label);t.origin=o}let r=t.revisions;if(Array.isArray(r)){for(let o of r)if(o.label)try{o.label=await tn(n,o.label)}catch{}}}return t}async function Va(e,t){let n=qa(e,t);if(!Ba())return import(n);let r=await fetch(n);if(!r.ok)throw Error(`canvas ${r.status}`);let o=await r.text(),i=await re.encryptionKey,s=await tn(i,o),l=new Blob([s],{type:"application/javascript"}),a=URL.createObjectURL(l);try{return await import(a)}finally{setTimeout(()=>URL.revokeObjectURL(a),0)}}var Zr="canvas-reviewer-identity";function Ho(){try{let e=localStorage.getItem(Zr);if(!e)return null;return JSON.parse(e)}catch{return null}}function Xr(e){let t=Ho();if(!t)t={id:crypto.randomUUID?.()||String(Date.now()),name:e};else t.name=e;return localStorage.setItem(Zr,JSON.stringify(t)),t}async function Wa(e,t){let n=await Promise.all(e.annotations.map(async(r)=>{let o={id:r.id,createdAt:r.createdAt,snippet:await et(t,String(r.snippet??"")),note:await et(t,String(r.note??""))};if(r.filePath)o.filePath=await et(t,String(r.filePath));if(r.canvasFile)o.canvasFile=await et(t,String(r.canvasFile));if(r.context!==void 0&&r.context!==null)o.context=await et(t,JSON.stringify(r.context));if(r.attachments)o.attachments=r.attachments;return o}));return{author:{id:e.author.id,name:await et(t,e.author.name)},revision:e.revision,annotations:n,...e.generalNote?{generalNote:await et(t,e.generalNote)}:{},encryption:Wr}}async function Jr(e){if(!re.isShared)throw Error("submitSharedFeedback called outside shared mode");let t=e;if(re.encryptionKey){let r=await re.encryptionKey;t=await Wa(e,r)}let n=await fetch(`/s/${re.shareId}/feedback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!n.ok){let r=await n.text().catch(()=>"");throw Error(`Feedback submission failed: ${n.status} ${r}`)}}var je=!re.isShared,Yr=!re.isShared,Qr={get sessionId(){return _a()},isShared:re.isShared,fsAvailable:je,uploadUrl:za,loadCanvasModule:Va};import{jsxDEV as U,Fragment as Do}from"react/jsx-dev-runtime";function ns({embedded:e}={}){let t=ts(Ka),{annotations:n,addAnnotation:r}=De(),{setActiveView:o}=ts($e),[i,s]=es(!1),[l,a]=es({});if(!je)return U("div",{className:e?"px-4 py-3":"p-4",children:[U("div",{className:"text-[11px] uppercase tracking-widest text-text-tertiary font-body mb-2",children:"Files"},void 0,!1,void 0,this),U("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:c,annotatedFiles:u}=Ga(()=>{let h=new Map;for(let b of n)if(b.filePath&&b.filePath!==Se)h.set(b.filePath,(h.get(b.filePath)||0)+1);return{annCountMap:h,annotatedFiles:[...h.keys()]}},[n]),d=async(h)=>{let k=await(await fetch(`/api/tree?session=${t}&path=${encodeURIComponent(h)}`)).json();if(k.entries)a((y)=>({...y,[h]:{entries:k.entries,expanded:!0,loaded:!0}}))};Ua(()=>{if(!i&&!l[""])d("")},[i]);let f=(h)=>{if(l[h]?.loaded)a((b)=>({...b,[h]:{...b[h],expanded:!b[h].expanded}}));else d(h)},p=(h)=>{o({type:"file",path:h})},m=async(h)=>{let k=await(await fetch(`/api/file?session=${t}&path=${encodeURIComponent(h)}`)).json();if(!k.error){let y=k.content.split(`
|
|
70
70
|
`).slice(0,3).join(`
|
|
71
|
-
`)+(
|
|
71
|
+
`)+(k.content.split(`
|
|
72
72
|
`).length>3?`
|
|
73
|
-
...`:"");
|
|
74
|
-
`);if(!
|
|
75
|
-
`)}catch{return null}},[
|
|
76
|
-
`);
|
|
73
|
+
...`:"");r(y,"Include this file for context",h)}},v=async(h)=>{let b=[];if(l[h]?.loaded)b=l[h].entries;else{let y=await(await fetch(`/api/tree?session=${t}&path=${encodeURIComponent(h)}`)).json();if(y.entries)b=y.entries}await Promise.all(b.filter((k)=>k.type==="file").map((k)=>m(h?`${h}/${k.name}`:k.name)))},g=(h)=>c.get(h)||0,w=(h,b=0)=>{let k=l[h];if(!k?.expanded)return null;return k.entries.map((y)=>{let E=h?`${h}/${y.name}`:y.name,R=g(E);return U("div",{children:[U("div",{className:"group/item flex items-center py-[3px] hover:bg-bg-elevated text-[13px] font-body cursor-default transition-colors duration-100",style:{paddingLeft:`${16+b*16}px`,paddingRight:"8px"},children:y.type==="dir"?U(Do,{children:[U("span",{onClick:()=>f(E),className:"flex items-center gap-1.5 flex-1 text-text-secondary hover:text-text-primary cursor-pointer truncate",children:[U(Ye,{name:y.name,type:"dir",expanded:l[E]?.expanded},void 0,!1,void 0,this),U("span",{className:"truncate",children:y.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this),U("button",{onClick:(C)=>{C.stopPropagation(),v(E)},className:"text-[11px] text-text-tertiary hover:text-text-secondary opacity-0 group-hover/item:opacity-100 transition-opacity px-1 flex-shrink-0",title:"Add all files in folder",children:"+"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):U(Do,{children:[U("span",{onClick:()=>p(E),className:`flex-1 truncate cursor-pointer flex items-center gap-1.5 ${R>0?"text-text-primary":"text-text-secondary hover:text-text-primary"}`,children:[U(Ye,{name:y.name,type:"file"},void 0,!1,void 0,this),U("span",{className:"truncate",children:y.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this),U("div",{className:"flex items-center gap-1 flex-shrink-0 ml-1",children:[R>0&&U("span",{className:"text-[10px] font-medium bg-badge-bg text-accent-amber px-1.5 py-px rounded-full min-w-[18px] text-center",children:R},void 0,!1,void 0,this),U("button",{onClick:(C)=>{C.stopPropagation(),m(E)},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),y.type==="dir"&&w(E,b+1)]},E,!0,void 0,this)})};if(e)return U(Do,{children:[U("div",{className:"flex items-center justify-between px-4 pt-3 pb-2 flex-shrink-0",children:U("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:"Files"},void 0,!1,void 0,this)},void 0,!1,void 0,this),U("div",{className:"flex-1 overflow-y-auto",children:w("")},void 0,!1,void 0,this),u.length>0&&U("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:[U("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body mb-1.5",children:"Referenced"},void 0,!1,void 0,this),u.map((h)=>U("div",{onClick:()=>p(h),className:"flex items-center justify-between text-[12px] font-body text-text-secondary hover:text-text-primary cursor-pointer py-0.5",children:[U("span",{className:"truncate",children:h.split("/").pop()},void 0,!1,void 0,this),U("span",{className:"text-[10px] font-medium bg-badge-bg text-accent-amber px-1.5 py-px rounded-full min-w-[18px] text-center flex-shrink-0 ml-1",children:g(h)},void 0,!1,void 0,this)]},h,!0,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);if(i)return U("div",{className:"hidden lg:flex w-8 border-r border-border-subtle bg-bg-surface flex-col items-center flex-shrink-0",children:U("button",{onClick:()=>s(!1),className:"mt-3 p-1 text-text-tertiary hover:text-text-secondary transition-colors",children:U("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:U("path",{d:"M5 3l4 4-4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this);return U("div",{className:"hidden lg:flex w-60 border-r border-border-subtle bg-bg-surface flex-col flex-shrink-0 overflow-hidden",children:[U("div",{className:"flex items-center justify-between px-4 pt-4 pb-3 flex-shrink-0",children:[U("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:"Files"},void 0,!1,void 0,this),U("button",{onClick:()=>s(!0),className:"text-text-tertiary hover:text-text-secondary transition-colors p-0.5",children:U("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:U("path",{d:"M9 3l-4 4 4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),U("div",{className:"flex-1 overflow-y-auto",children:w("")},void 0,!1,void 0,this),u.length>0&&U("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:[U("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body mb-1.5",children:"Referenced"},void 0,!1,void 0,this),u.map((h)=>U("div",{onClick:()=>p(h),className:"flex items-center justify-between text-[12px] font-body text-text-secondary hover:text-text-primary cursor-pointer py-0.5",children:[U("span",{className:"truncate",children:h.split("/").pop()},void 0,!1,void 0,this),U("span",{className:"text-[10px] font-medium bg-badge-bg text-accent-amber px-1.5 py-px rounded-full min-w-[18px] text-center flex-shrink-0 ml-1",children:g(h)},void 0,!1,void 0,this)]},h,!0,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}import{useEffect as os,useState as Nt,useContext as Za,useCallback as Xa,useRef as On,useMemo as rs}from"react";import{SessionContext as Ja}from"#canvas/runtime";var Dn={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 ye}from"react/jsx-dev-runtime";function ss(e){let t=e instanceof HTMLElement?e:e.parentElement;while(t){if(t.hasAttribute("data-line-num"))return t;t=t.parentElement}return null}function Ya(e){let t=e.toString().trim(),n=ss(e.startContainer),r=ss(e.endContainer),o=n?parseInt(n.getAttribute("data-line-num"),10):void 0,i=r?parseInt(r.getAttribute("data-line-num"),10):void 0,s="",l="";if(t.length<30&&n&&n===r){let a=n.querySelector("code");if(a){let c=a.textContent||"",u=c.indexOf(t);if(u>=0)s=c.slice(0,u).trimStart(),l=c.slice(u+t.length).trimEnd()}}return{before:s,after:l,hierarchy:[],lineStart:o,lineEnd:i}}function is({path:e}){if(!je)return ye("div",{className:"max-w-[720px] mx-auto px-6 pt-12 pb-32",children:ye("div",{className:"p-4 rounded-lg border border-border-subtle bg-bg-surface",children:[ye("div",{className:"text-[11px] uppercase tracking-widest text-text-tertiary font-body mb-2",children:"File not available"},void 0,!1,void 0,this),ye("p",{className:"text-[13px] text-text-secondary font-body leading-relaxed",children:["Opening ",ye("code",{className:"px-1 py-0.5 rounded bg-bg-elevated text-text-primary text-[11px]",children:e},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 ",ye("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 t=Za(Ja),{annotations:n,addAnnotationWithId:r,activeAnnotationId:o,setActiveAnnotationId:i}=De(),[s,l]=Nt(null),[a,c]=Nt("text"),[u,d]=Nt(!0),[f,p]=Nt(null),m=On(null),[v,g]=Nt(null),[w,h]=Nt(null),b=On(null),k=On(null),y=On([]),E=n.filter((N)=>N.filePath===e),R=m.current?.closest("#plan-scroll-container"),{popovers:C,openCreatePopover:M}=Je({containerRef:m,restoreKey:`${s}:${e}`,restoreAnnotations:E,extractContext:Ya,filePath:e,scrollContainer:R});os(()=>{d(!0),p(null),fetch(`/api/file?session=${t}&path=${encodeURIComponent(e)}`).then((N)=>N.json()).then((N)=>{if(N.error)p(N.error),d(!1);else l(N.content),c(N.language||"text"),d(!1)}).catch(()=>{p("Failed to fetch file"),d(!1)})},[t,e]);let L=Xa((N,_)=>{N.preventDefault(),b.current=_,k.current=_,g(_),h(_)},[]);os(()=>{let N=(z)=>{if(b.current===null)return;let X=z.target.closest("[data-line-num]");if(X){let G=parseInt(X.getAttribute("data-line-num"),10);k.current=G,h(G)}},_=()=>{let z=b.current;if(z===null)return;b.current=null;let X=k.current??z,G=Math.min(z,X),J=Math.max(z,X),O=y.current.slice(G-1,J).join(`
|
|
74
|
+
`);if(!O.trim()){g(null),h(null);return}let Z=`__pending_${Date.now()}`,ue={before:"",after:"",hierarchy:[],lineStart:G,lineEnd:J};if(m.current){let A=m.current.querySelectorAll("[data-line-num]"),P=A[G-1],Y=A[J-1];if(P&&Y){let H=P.querySelector("code"),F=Y.querySelector("code");if(H&&F)try{let oe=document.createRange();oe.setStartBefore(H.firstChild||H),oe.setEndAfter(F.lastChild||F),Ue(oe,Z)}catch{}}let T=A[J-1];if(T)M(T,Z,O,ue)}g(null),h(null)};return document.addEventListener("mousemove",N),document.addEventListener("mouseup",_),()=>{document.removeEventListener("mousemove",N),document.removeEventListener("mouseup",_)}},[]);let B=rs(()=>{if(!s)return null;let N=window.hljs;if(!N)return null;let _=e.split(".").pop()||"",z=Dn[_];try{return(z?N.highlight(s,{language:z}):N.highlightAuto(s)).value.split(`
|
|
75
|
+
`)}catch{return null}},[s,e]);if(u)return ye("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-[13px]",children:["Loading ",e,"..."]},void 0,!0,void 0,this);if(f)return ye("div",{className:"p-8 text-accent-red font-body text-[13px]",children:f},void 0,!1,void 0,this);if(!s)return null;let j=s.split(`
|
|
76
|
+
`);y.current=j;let W=rs(()=>{if(v===null)return null;let N=w??v;return{start:Math.min(v,N),end:Math.max(v,N)}},[v,w]),de=()=>{let N=s.split(`
|
|
77
77
|
`).slice(0,3).join(`
|
|
78
|
-
`)+(
|
|
79
|
-
...`:""),
|
|
78
|
+
`)+(j.length>3?`
|
|
79
|
+
...`:""),_=ve();r(_,N,"",e),i(_)};return ye("div",{children:[ye("pre",{ref:m,className:"text-code font-mono text-text-code bg-bg-base select-text cursor-text py-3 hljs",children:j.map((N,_)=>{let z=_+1,X=W&&z>=W.start&&z<=W.end;return ye("div",{"data-line-num":z,className:`flex px-5 ${X?"bg-accent-blue/10":"hover:bg-bg-elevated-half"}`,children:[ye("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:(G)=>L(G,z),children:z},void 0,!1,void 0,this),B?ye("code",{className:"py-px",dangerouslySetInnerHTML:{__html:B[_]||" "}},void 0,!1,void 0,this):ye("code",{className:"py-px",children:N||" "},void 0,!1,void 0,this)]},_,!0,void 0,this)})},void 0,!1,void 0,this),C]},void 0,!0,void 0,this)}import{useEffect as as,useState as ls,useRef as Qa}from"react";import{jsxDEV as Oe}from"react/jsx-dev-runtime";function cs(e,t){if(t){let n=t.replace(/\/+$/,"").split("/");return n[n.length-1]||e}return e.length>30?e.slice(0,30)+"...":e}function Oo({currentSessionId:e,projectRoot:t}){let[n,r]=ls([]),[o,i]=ls(!1),s=Qa(null);as(()=>{if(!je)return;let c=async()=>{try{let f=await(await fetch("/api/sessions")).json();r((p)=>{let m=JSON.stringify(f);return JSON.stringify(p)===m?p:f})}catch{}};c();let u=setInterval(c,5000);return()=>clearInterval(u)},[]),as(()=>{if(!o)return;let c=(u)=>{if(s.current&&!s.current.contains(u.target))i(!1)};return document.addEventListener("mousedown",c),()=>document.removeEventListener("mousedown",c)},[o]);let l=n.filter((c)=>c.id!==e),a=cs(e,t);return Oe("div",{className:"relative",ref:s,children:[Oe("div",{className:"flex items-center gap-1.5 font-body text-body font-medium",children:[Oe("a",{href:`/s/${e}`,className:"text-text-primary hover:text-text-secondary transition-colors",children:a},void 0,!1,void 0,this),l.length>0&&Oe("button",{onClick:()=>i(!o),className:"flex items-center justify-center text-text-tertiary hover:text-text-secondary transition-colors",children:Oe("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:`transition-transform duration-200 ${o?"rotate-180":""}`,children:Oe("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),o&&l.length>0&&Oe("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:l.map((c)=>Oe("a",{href:`/s/${c.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:[Oe("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${c.currentRevision>0?"bg-accent-green":"bg-border-hover"}`},void 0,!1,void 0,this),Oe("span",{className:"truncate",children:cs(c.id,c.projectRoot)},void 0,!1,void 0,this)]},c.id,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function ds(e){let t=[];return Fn(e,t,0),t.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 p1,useState as U1,useRef as E1,useCallback as L5,useMemo as U2,useContext as O6}from"react";import{useEffect as Z6,useState as q6,useRef as J6,useContext as Q6}from"react";import{jsxDEV as H1,Fragment as z5}from"react/jsx-dev-runtime";function Y6(Z){return Z.label||`Round ${Z.revision}`}function X6(Z){let $=Date.now()-new Date(Z).getTime(),q=Math.floor($/1000);if(q<60)return"just now";let Q=Math.floor(q/60);if(Q<60)return`${Q}m ago`;let J=Math.floor(Q/60);if(J<24)return`${J}h ago`;return`${Math.floor(J/24)}d ago`}function I0({value:Z,onChange:$,accent:q="default",className:Q}){let{currentRevision:J,revisions:Y}=Q6(A1),[X,G]=q6(!1),z=J6(null);Z6(()=>{if(!X)return;let U=(W)=>{if(z.current&&!z.current.contains(W.target))G(!1)};return document.addEventListener("mousedown",U),()=>document.removeEventListener("mousedown",U)},[X]);let _=Y.find((U)=>U.revision===Z);return H1("div",{className:"relative",ref:z,children:[H1("button",{onClick:()=>G(!X),className:`flex items-center gap-1.5 text-[12px] font-body font-medium px-2 py-1 rounded-md transition-colors hover:bg-bg-elevated ${{default:"text-text-secondary hover:text-text-primary",red:"text-accent-red",green:"text-accent-green",amber:"text-accent-amber bg-highlight-selected"}[q]} ${Q||""}`,children:[_?Y6(_):`Round ${Z}`,H1("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",className:`text-text-tertiary transition-transform duration-200 ${X?"rotate-180":""}`,children:H1("path",{d:"M2.5 4l2.5 2.5L7.5 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),X&&H1("div",{className:"absolute top-full left-0 mt-1 w-64 bg-bg-elevated border border-border-hover rounded-lg shadow-lg z-50 py-1 max-h-80 overflow-y-auto",children:[...Y].reverse().map((U)=>H1("button",{onClick:()=>{$(U.revision),G(!1)},className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] font-body transition-colors ${U.revision===Z?"bg-bg-surface text-text-primary":"text-text-secondary hover:bg-bg-surface hover:text-text-primary"}`,children:[H1("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${U.revision===J?"bg-accent-green":U.hasFeedback?"bg-accent-amber":"bg-border-hover"}`},void 0,!1,void 0,this),H1("span",{className:"flex-1 text-left truncate",children:U.label?H1(z5,{children:[U.label," ",H1("span",{className:"text-text-tertiary",children:["#",U.revision]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):H1(z5,{children:["Round ",U.revision]},void 0,!0,void 0,this)},void 0,!1,void 0,this),H1("span",{className:"text-[10px] text-text-tertiary flex-shrink-0 flex items-center gap-1.5",children:[(()=>{let W=U.canvasFiles?.reduce((T,K)=>{if(K.diffStats)T.added+=K.diffStats.added,T.removed+=K.diffStats.removed;return T},{added:0,removed:0});if(W&&(W.added>0||W.removed>0))return H1("span",{className:"font-mono",children:[H1("span",{className:"text-accent-green",children:["+",W.added]},void 0,!0,void 0,this)," ",H1("span",{className:"text-accent-red",children:["-",W.removed]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);return null})(),U.revision===J?"current":U.hasFeedback?"sent":X6(U.createdAt)]},void 0,!0,void 0,this)]},U.revision,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function h1(Z,$){let q=Z.length,Q=$.length;if(q===0||Q===0)return[];let J=Array.from({length:q+1},()=>Array(Q+1).fill(0));for(let z=1;z<=q;z++)for(let _=1;_<=Q;_++)J[z][_]=Z[z-1]===$[_-1]?J[z-1][_-1]+1:Math.max(J[z-1][_],J[z][_-1]);let Y=[],X=q,G=Q;while(X>0&&G>0)if(Z[X-1]===$[G-1])Y.unshift(Z[X-1]),X--,G--;else if(J[X-1][G]>J[X][G-1])X--;else G--;return Y}function _5(Z){let $=[],q=[],Q=document.createTreeWalker(Z,NodeFilter.SHOW_TEXT,{acceptNode(Y){let X=Y.parentElement;if(!X)return NodeFilter.FILTER_REJECT;if(X.closest("svg, .select-none, [data-no-diff]"))return NodeFilter.FILTER_REJECT;return NodeFilter.FILTER_ACCEPT}}),J;while(J=Q.nextNode()){let X=(J.nodeValue||"").match(/\S+|\s+/g);if(!X)continue;let G=0;for(let z of X)$.push(z),q.push({text:z,node:J,offset:G}),G+=z.length}return{words:$,map:q}}function l2(Z,$){if(Z.length>5000||$.length>5000)return z6(Z,$);return K5(Z,$)}function K5(Z,$){let q=z2(Z,$),Q=[],J=[],Y=0,X=0,G=0;while(Y<Z.length||X<$.length)if(G<q.length&&Y<Z.length&&X<$.length&&Z[Y]===q[G]&&$[X]===q[G])Q.push({type:"same",index:Y}),J.push({type:"same",index:X}),Y++,X++,G++;else if(Y<Z.length&&(G>=q.length||Z[Y]!==q[G]))Q.push({type:"removed",index:Y}),Y++;else if(X<$.length)J.push({type:"added",index:X}),X++;return{oldOps:Q,newOps:J}}function z2(Z,$){let q=Z.length,Q=$.length;if(q===0||Q===0)return[];if(q===1)return $.includes(Z[0])?[Z[0]]:[];if(Q===1)return Z.includes($[0])?[$[0]]:[];if(q*Q<=1e6)return h1(Z,$);let J=Math.floor(q/2),Y=Z.slice(0,J),X=Z.slice(J),G=G5(Y,$),z=G5([...X].reverse(),[...$].reverse()),_=0,H=0;for(let T=0;T<=Q;T++){let K=G[T]+z[Q-T];if(K>_)_=K,H=T}let U=$.slice(0,H),W=$.slice(H);return[...z2(Y,U),...z2(X,W)]}function G5(Z,$){let q=$.length,Q=Array(q+1).fill(0),J=Array(q+1).fill(0);for(let Y=0;Y<Z.length;Y++){for(let X=1;X<=q;X++)J[X]=Z[Y]===$[X-1]?Q[X-1]+1:Math.max(Q[X],J[X-1]);[Q,J]=[J,Q],J.fill(0)}return Q}function z6(Z,$){let Q=(K)=>{let L=[];for(let N=0;N<K.length;N+=200){let S=Math.min(N+200,K.length);L.push({start:N,end:S,text:K.slice(N,S).join("")})}return L},J=Q(Z),Y=Q($),X=J.map((K)=>K.text),G=Y.map((K)=>K.text),z=z2(X,G),_=[],H=[],U=0,W=0,T=0;while(U<J.length||W<Y.length)if(T<z.length&&U<J.length&&W<Y.length&&X[U]===z[T]&&G[W]===z[T]){for(let K=J[U].start;K<J[U].end;K++)_.push({type:"same",index:K});for(let K=Y[W].start;K<Y[W].end;K++)H.push({type:"same",index:K});U++,W++,T++}else if(U<J.length&&(T>=z.length||X[U]!==z[T]))if(W<Y.length&&(T>=z.length||G[W]!==z[T])){let K=K5(Z.slice(J[U].start,J[U].end),$.slice(Y[W].start,Y[W].end));for(let L of K.oldOps)_.push({type:L.type,index:L.index+J[U].start});for(let L of K.newOps)H.push({type:L.type,index:L.index+Y[W].start});U++,W++}else{for(let K=J[U].start;K<J[U].end;K++)_.push({type:"removed",index:K});U++}else if(W<Y.length){for(let K=Y[W].start;K<Y[W].end;K++)H.push({type:"added",index:K});W++}return{oldOps:_,newOps:H}}function U5(Z,$,q){let Q=new Map;for(let J of Z){if(J.type==="same")continue;let Y=$[J.index];if(!Y||!Y.node.parentNode)continue;let X=Q.get(Y.node);if(!X)X=[],Q.set(Y.node,X);X.push({offset:Y.offset,length:Y.text.length})}for(let[J,Y]of Q){if(!J.parentNode)continue;let X=J.nodeValue||"";Y.sort((U,W)=>U.offset-W.offset);let G=[];for(let U of Y){let W=G[G.length-1];if(W&&U.offset<=W.offset+W.length)W.length=Math.max(W.length,U.offset+U.length-W.offset);else G.push({...U})}let z=J.parentNode,_=document.createDocumentFragment(),H=0;for(let U of G){if(U.offset>H)_.appendChild(document.createTextNode(X.slice(H,U.offset)));let W=document.createElement("span");W.className=q,W.textContent=X.slice(U.offset,U.offset+U.length),_.appendChild(W),H=U.offset+U.length}if(H<X.length)_.appendChild(document.createTextNode(X.slice(H)));z.replaceChild(_,J)}}function _2(Z,$){let q=_6(Z,$),Q=_5(Z),J=_5($),{oldOps:Y,newOps:X}=l2(Q.words,J.words),G=Y.some((z)=>z.type==="removed")||X.some((z)=>z.type==="added");return U5(Y,Q.map,"diff-removed"),U5(X,J.map,"diff-added"),G||q}function _6(Z,$){let q=Array.from(Z.querySelectorAll('[data-md="mermaid"]')),Q=Array.from($.querySelectorAll('[data-md="mermaid"]')),J=!1,Y=Math.max(q.length,Q.length);for(let X=0;X<Y;X++){let G=q[X],z=Q[X];if(!G&&z){z.classList.add("diff-block-added"),z.style.position="relative",J=!0;continue}if(G&&!z){G.classList.add("diff-block-removed"),G.style.position="relative",J=!0;continue}if(!G||!z)continue;let _=(G.getAttribute("data-md-source")||"").trim(),H=(z.getAttribute("data-md-source")||"").trim();if(_===H)continue;J=!0,G.style.borderLeft="3px solid var(--color-accent-red)",G.style.paddingLeft="8px",z.style.borderLeft="3px solid var(--color-accent-green)",z.style.paddingLeft="8px";let U=_.split(`
|
|
84
|
-
`),
|
|
85
|
-
`),T=h1(U,W),K=(L,N,S)=>{let O=document.createElement("div");O.className="mt-2 bg-bg-code rounded-md overflow-hidden text-tiny font-mono",O.setAttribute("data-no-diff","true");let R=0,b=0;while(b<L.length){let M=document.createElement("div");if(M.className="px-3 py-0.5 whitespace-pre-wrap",R<N.length&&L[b]===N[R])M.textContent=" "+L[b],b++,R++;else M.classList.add(S==="old"?"diff-removed":"diff-added"),M.textContent=(S==="old"?"- ":"+ ")+L[b],b++;O.appendChild(M)}return O};G.appendChild(K(U,T,"old")),z.appendChild(K(W,T,"new"))}return J}function W0(Z){let $=[],q=Z.querySelectorAll(":scope > [data-md]");for(let Q of q)$.push(R0(Q));if($.length===0){let Q=Z.querySelectorAll("[data-md]"),J=new Set;for(let Y of Q){let X=Y.parentElement?.closest("[data-md]");if(X&&Z.contains(X))continue;if(J.has(Y))continue;J.add(Y),$.push(R0(Y))}}return $}function R0(Z){let $=Z.getAttribute("data-md")||"unknown",q=G6(Z,$),Q=[];if($==="section"){let J=Z.querySelector(":scope > div.mt-6, :scope > div:last-child");if(J)for(let Y of J.querySelectorAll(":scope > [data-md]"))Q.push(R0(Y))}else if($==="table")for(let J of Z.querySelectorAll(":scope table > tbody > tr"))Q.push({key:"tr:"+(J.textContent||"").slice(0,80),type:"tr",element:J,children:[]});else if($==="checklist")for(let J of Z.querySelectorAll(":scope > [data-md='checklist-item']"))Q.push(R0(J));else for(let J of Z.querySelectorAll("[data-md]"))if(J.parentElement?.closest("[data-md]")===Z)Q.push(R0(J));return{key:q,type:$,element:Z,children:Q}}function G6(Z,$){switch($){case"section":return"section:"+(Z.getAttribute("data-md-title")||"");case"item":return"item:"+(Z.getAttribute("data-task-id")||Z.getAttribute("data-md-label")||"");case"codeblock":case"diff":return $+":"+(Z.textContent||"").slice(0,80);case"checklist-item":return"checklist-item:"+(Z.getAttribute("data-md-label")||Z.textContent?.slice(0,60)||"");case"checklist":return"checklist:"+Z.querySelectorAll("[data-md='checklist-item']").length;case"markdown":return"markdown:"+(Z.getAttribute("data-md-file")||"inline");case"mermaid":return"mermaid:"+(Z.getAttribute("data-md-source")||"").slice(0,80);case"callout":return"callout:"+(Z.getAttribute("data-md-type")||"")+":"+(Z.textContent||"").slice(0,60);default:return $+":"+(Z.getAttribute("data-md-label")||Z.textContent?.slice(0,60)||"")}}function D0(Z,$){let q=Z.map((_)=>_.key),Q=$.map((_)=>_.key),J=h1(q,Q),Y=[],X=0,G=0,z=0;while(X<Z.length||G<$.length)if(z<J.length&&X<Z.length&&G<$.length&&q[X]===J[z]&&Q[G]===J[z]){let _=Z[X],H=$[G],U=_.children.length>0||H.children.length>0?D0(_.children,H.children):void 0;Y.push({kind:"matched",oldBlock:_,newBlock:H,childMatches:U}),X++,G++,z++}else if(X<Z.length&&(z>=J.length||q[X]!==J[z]))Y.push({kind:"removed",oldBlock:Z[X]}),X++;else if(G<$.length)Y.push({kind:"added",newBlock:$[G]}),G++;return Y}function G2(Z){let $=document.createDocumentFragment(),q=!1;for(let Q of Z)if(Q.kind==="removed")q=!0,$.appendChild(W5(Q.oldBlock.element));else if(Q.kind==="added")q=!0,$.appendChild(U6(Q.newBlock.element));else{let J=Q.newBlock.element.cloneNode(!0),Y=Q.newBlock.type;if(Y==="mermaid"){if(B5(Q.oldBlock.element,J))q=!0}else if(Q.childMatches&&Q.childMatches.length>0&&(Y==="table"||Y==="checklist")){if(N5(J,Q.childMatches,Y))q=!0}else if(Q.childMatches&&Q.childMatches.length>0){if(T5(Q.oldBlock,J,Q.childMatches,Y))q=!0}else if(Y==="markdown"){if(O5(Q.oldBlock.element,J))q=!0}else if(q0(Q.oldBlock.element,J,!1))q=!0;$.appendChild(J)}return{fragment:$,hasChanges:q}}function W5(Z){let $=Z.cloneNode(!0);return $.classList.add("diff-block-removed"),$.style.position="relative",r2($,"Removed","var(--color-accent-red)"),$}function U6(Z){let $=Z.cloneNode(!0);return $.classList.add("diff-block-added"),$.style.position="relative",r2($,"Added","var(--color-accent-green)"),$}function T5(Z,$,q,Q){let J=!1,Y=K6(Z,$),X,G;if(Q==="section"){let z=Z.element.querySelector(":scope > div:first-child"),_=$.querySelector(":scope > div:first-child");if(z&&_){if(q0(z,_,!1))J=!0}X=Z.element.querySelector(":scope > div.mt-6, :scope > div:last-child"),G=$.querySelector(":scope > div.mt-6, :scope > div:last-child")}else X=Z.element,G=$;if(!X||!G)return J;for(let z of q)if(z.kind==="matched"){let _=Y.newMap.get(z.newBlock.element);if(_){if(z.newBlock.type==="mermaid"){if(B5(z.oldBlock.element,_))J=!0}else if(z.childMatches&&z.childMatches.length>0&&(z.newBlock.type==="table"||z.newBlock.type==="checklist")){if(N5(_,z.childMatches,z.newBlock.type))J=!0}else if(z.childMatches&&z.childMatches.length>0){if(T5(z.oldBlock,_,z.childMatches,z.newBlock.type))J=!0}else if(z.newBlock.type==="markdown"){if(O5(z.oldBlock.element,_))J=!0}else if(q0(z.oldBlock.element,_,!1))J=!0}}else if(z.kind==="removed"){J=!0;let _=W5(z.oldBlock.element),H=W6(q,z,Y.newMap),U=H?T6(G,H):null;G.insertBefore(_,U)}else if(z.kind==="added"){J=!0;let _=Y.newMap.get(z.newBlock.element);if(_)_.classList.add("diff-block-added"),_.style.position="relative",r2(_,"Added","var(--color-accent-green)")}if(q0(X,G,!0))J=!0;return J}function N5(Z,$,q){let Q=q==="table"?Z.querySelector(":scope table > tbody"):Z;if(!Q)return!1;let J=!1;Q.innerHTML="";for(let Y of $)if(Y.kind==="removed"){J=!0;let X=Y.oldBlock.element.cloneNode(!0);X.classList.add(q==="table"?"diff-row-removed":"diff-item-removed"),Q.appendChild(X)}else if(Y.kind==="added"){J=!0;let X=Y.newBlock.element.cloneNode(!0);X.classList.add(q==="table"?"diff-row-added":"diff-item-added"),Q.appendChild(X)}else{let X=Y.newBlock.element.cloneNode(!0);if(q0(Y.oldBlock.element,X,!1))J=!0;Q.appendChild(X)}return J}function K6(Z,$){let q=new Map,Q=Z.element.querySelectorAll("[data-md]"),J=$.querySelectorAll("[data-md]");return{newMap:{get(Y){return H6($,Y)}}}}function H6(Z,$){let q=$.getAttribute("data-md");if(!q)return null;let Q=$.getAttribute("data-md-label"),J=$.getAttribute("data-md-title"),Y=`[data-md="${q}"]`;if(J)Y+=`[data-md-title="${CSS.escape(J)}"]`;else if(Q)Y+=`[data-md-label="${CSS.escape(Q)}"]`;let X=Z.querySelectorAll(Y);if(X.length===1)return X[0];let G=($.textContent||"").slice(0,100),z=null,_=-1;for(let H of X){let U=(H.textContent||"").slice(0,100),W=0;for(let T=0;T<Math.min(G.length,U.length);T++)if(G[T]===U[T])W++;if(W>_)_=W,z=H}return z}function W6(Z,$,q){let Q=Z.indexOf($);for(let J=Q+1;J<Z.length;J++){let Y=Z[J];if((Y.kind==="matched"||Y.kind==="added")&&Y.newBlock)return q.get(Y.newBlock.element)||null}return null}function T6(Z,$){let q=$;while(q&&q.parentElement!==Z)q=q.parentElement;return q}function O5(Z,$){let q=Array.from(Z.children),Q=Array.from($.children);if(q.length===0&&Q.length===0)return q0(Z,$,!1);let J=q.map((W)=>W.tagName.toLowerCase()),Y=Q.map((W)=>W.tagName.toLowerCase()),X=h1(J,Y),G=[],z=0,_=0,H=0;while(z<q.length||_<Q.length)if(H<X.length&&z<q.length&&_<Q.length&&J[z]===X[H]&&Y[_]===X[H])G.push({kind:"matched",oldChild:q[z],newChild:Q[_]}),z++,_++,H++;else if(z<q.length&&(H>=X.length||J[z]!==X[H]))G.push({kind:"removed",oldChild:q[z]}),z++;else if(_<Q.length)G.push({kind:"added",newChild:Q[_]}),_++;let U=!1;while($.firstChild)$.removeChild($.firstChild);for(let W of G)if(W.kind==="matched"){let T=(W.oldChild.textContent||"").match(/\S+/g)||[],K=(W.newChild.textContent||"").match(/\S+/g)||[],L=h1(T,K),N=Math.max(T.length,K.length);if((N>0?1-L.length/N:0)>0.5){U=!0;let O=W.oldChild.cloneNode(!0);O.classList.add("diff-block-removed"),$.appendChild(O),W.newChild.classList.add("diff-block-added"),$.appendChild(W.newChild)}else{if(q0(W.oldChild,W.newChild,!1))U=!0;$.appendChild(W.newChild)}}else if(W.kind==="removed"){U=!0;let T=W.oldChild.cloneNode(!0);T.classList.add("diff-block-removed"),$.appendChild(T)}else U=!0,W.newChild.classList.add("diff-block-added"),$.appendChild(W.newChild);return U}function H5(Z,$){let q=$?new Set(Array.from(Z.querySelectorAll("[data-md]"))):new Set,Q=[],J=[],Y=document.createTreeWalker(Z,NodeFilter.SHOW_TEXT,{acceptNode(G){let z=G.parentElement;if(!z)return NodeFilter.FILTER_REJECT;if(z.closest("svg, .select-none, [data-no-diff]"))return NodeFilter.FILTER_REJECT;if($){for(let _ of q)if(_.contains(G))return NodeFilter.FILTER_REJECT}return NodeFilter.FILTER_ACCEPT}}),X;while(X=Y.nextNode()){let z=(X.nodeValue||"").match(/\S+|\s+/g);if(!z)continue;let _=0;for(let H of z)Q.push(H),J.push({text:H,node:X,offset:_}),_+=H.length}return{words:Q,map:J}}function q0(Z,$,q){let Q=H5(Z,q),J=H5($,q);if(Q.words.length===0&&J.words.length===0)return!1;let{oldOps:Y,newOps:X}=l2(Q.words,J.words),G=Y.some((N)=>N.type==="removed"),z=X.some((N)=>N.type==="added");if(!G&&!z)return!1;let _=[],H=[];for(let N of Y)if(N.type==="same")_.push(N.index);for(let N of X)if(N.type==="same")H.push(N.index);let U=new Map;for(let N=0;N<_.length&&N<H.length;N++)U.set(_[N],H[N]);let W=[];{let N=[],S=-1;for(let O of Y)if(O.type==="same"){if(N.length>0)W.push({text:N.join(""),anchorNewIdx:S>=0?U.get(S)??null:null}),N=[];S=O.index}else if(O.type==="removed")N.push(Q.words[O.index]);if(N.length>0)W.push({text:N.join(""),anchorNewIdx:S>=0?U.get(S)??null:null})}let T=new Map,K=new Map;for(let N of X){if(N.type!=="added")continue;let S=J.map[N.index];if(!S?.node.parentNode)continue;let O=T.get(S.node);if(!O)O=[],T.set(S.node,O);O.push({start:S.offset,end:S.offset+S.text.length})}for(let N of W)if(N.anchorNewIdx===null){if(J.map.length>0){let S=J.map[0].node,O=K.get(S);if(!O)O=[],K.set(S,O);O.push({offset:0,text:N.text})}}else{let S=J.map[N.anchorNewIdx];if(!S)continue;let O=K.get(S.node);if(!O)O=[],K.set(S.node,O);O.push({offset:S.offset+S.text.length,text:N.text})}let L=new Set([...T.keys(),...K.keys()]);for(let N of L)N6(N,T.get(N)||[],K.get(N)||[]);return!0}function N6(Z,$,q){if(!Z.parentNode)return;let Q=Z.nodeValue||"";$.sort((H,U)=>H.start-U.start);let J=[];for(let H of $){let U=J[J.length-1];if(U&&H.start<=U.end)U.end=Math.max(U.end,H.end);else J.push({...H})}q.sort((H,U)=>H.offset-U.offset);let Y=Z.parentNode,X=document.createDocumentFragment(),G=0,z=0,_=0;while(G<=Q.length){let H=z<J.length?J[z].start:1/0,U=_<q.length?q[_].offset:1/0,W=Math.min(H,U);if(W===1/0){if(G<Q.length)X.appendChild(document.createTextNode(Q.slice(G)));break}let T=Math.max(W,G);if(T>G)X.appendChild(document.createTextNode(Q.slice(G,T))),G=T;while(_<q.length&&q[_].offset<=G){let K=document.createElement("span");K.className="diff-removed",K.textContent=q[_].text,X.appendChild(K),_++}if(z<J.length&&J[z].start<=G){let K=J[z],L=document.createElement("span");L.className="diff-added",L.textContent=Q.slice(G,K.end),X.appendChild(L),G=K.end,z++;while(_<q.length&&q[_].offset<=G){let N=document.createElement("span");N.className="diff-removed",N.textContent=q[_].text,X.appendChild(N),_++}}}while(_<q.length){let H=document.createElement("span");H.className="diff-removed",H.textContent=q[_].text,X.appendChild(H),_++}Y.replaceChild(X,Z)}function B5(Z,$){let q=(Z.getAttribute("data-md-source")||"").trim(),Q=($.getAttribute("data-md-source")||"").trim();if(q===Q)return!1;let J=q.split(`
|
|
86
|
-
`),
|
|
87
|
-
`),X=h1(J,Y),G=[],z=0,_=0,H=0;while(z<J.length||_<Y.length)if(H<X.length&&z<J.length&&_<Y.length&&J[z]===X[H]&&Y[_]===X[H])G.push({type:"same",line:J[z]}),z++,_++,H++;else if(z<J.length&&(H>=X.length||J[z]!==X[H]))G.push({type:"removed",line:J[z]}),z++;else if(_<Y.length)G.push({type:"added",line:Y[_]}),_++;let U=document.createElement("div");U.className="mt-2 bg-bg-code rounded-md overflow-hidden text-tiny font-mono",U.setAttribute("data-no-diff","true");for(let W of G){let T=document.createElement("div");if(T.className="px-3 py-0.5 whitespace-pre-wrap",W.type==="removed")T.classList.add("diff-removed"),T.textContent="- "+W.line;else if(W.type==="added")T.classList.add("diff-added"),T.textContent="+ "+W.line;else T.textContent=" "+W.line;U.appendChild(T)}return $.appendChild(U),!0}function r2(Z,$,q){let Q=document.createElement("span");Q.className="diff-block-label",Q.textContent=$,Q.style.color=q,Q.style.backgroundColor=`color-mix(in srgb, ${q} 12%, transparent)`,Z.appendChild(Q)}import{jsxDEV as p}from"react/jsx-dev-runtime";function B6(Z,$,q){let Q=Z.find((X)=>X.revision===$),J=Z.find((X)=>X.revision===q),Y=new Set;for(let X of Q?.canvasFiles||[])Y.add(X.filename);for(let X of J?.canvasFiles||[])Y.add(X.filename);return[...Y].sort()}function M5({initialLeft:Z,initialRight:$,sessionId:q,onExit:Q}){let[J,Y]=U1(Z),[X,G]=U1($),[z,_]=U1("unified"),[H,U]=U1(!0),[W,T]=U1(!1),{revisions:K}=O6(A1),L=U2(()=>B6(K,J,X),[K,J,X]),[N,S]=U1(()=>L[0]||"plan.jsx");p1(()=>{if(!L.includes(N))S(L[0]||"plan.jsx")},[L,N]);let O=U2(()=>{return K.find((M)=>M.revision===J)?.canvasFiles.some((M)=>M.filename===N)??!1},[K,J,N]),R=U2(()=>{return K.find((M)=>M.revision===X)?.canvasFiles.some((M)=>M.filename===N)??!1},[K,X,N]);return p("div",{className:"flex flex-col h-screen",children:[p("div",{className:"flex items-center justify-between px-6 py-3 border-b border-border-subtle bg-bg-surface flex-shrink-0",children:[p("div",{className:"flex items-center gap-3",children:[p("span",{className:"text-[13px] font-body font-medium text-text-primary",children:"Compare"},void 0,!1,void 0,this),p(I0,{value:J,onChange:Y,accent:"red"},void 0,!1,void 0,this),p("span",{className:"text-text-tertiary text-[13px]",children:"→"},void 0,!1,void 0,this),p(I0,{value:X,onChange:G,accent:"green"},void 0,!1,void 0,this),W&&!H&&p("span",{className:"text-[11px] font-body text-text-tertiary bg-bg-elevated px-2 py-0.5 rounded",children:"No changes"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),p("div",{className:"flex items-center gap-4",children:[p("div",{className:"flex items-center bg-bg-elevated rounded-md p-0.5",children:[p("button",{onClick:()=>_("unified"),className:`text-[11px] font-body px-2.5 py-1 rounded transition-colors ${z==="unified"?"bg-bg-surface text-text-primary font-medium shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Unified"},void 0,!1,void 0,this),p("button",{onClick:()=>_("side-by-side"),className:`text-[11px] font-body px-2.5 py-1 rounded transition-colors ${z==="side-by-side"?"bg-bg-surface text-text-primary font-medium shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Side-by-side"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z==="side-by-side"&&p(F6,{},void 0,!1,void 0,this),p("button",{onClick:Q,className:"text-[12px] font-body font-medium text-text-secondary hover:text-text-primary px-3 py-1.5 rounded-md hover:bg-bg-elevated transition-colors",children:"Exit Compare"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),L.length>1&&p("div",{className:"flex items-center gap-1 px-6 py-2 border-b border-border-subtle bg-bg-surface flex-shrink-0 overflow-x-auto",children:L.map((b)=>{let M=b.replace(/\.jsx$/,""),j=b===N,g=K.find((v)=>v.revision===J)?.canvasFiles.some((v)=>v.filename===b),C=K.find((v)=>v.revision===X)?.canvasFiles.some((v)=>v.filename===b),h=!g?" (added)":!C?" (removed)":"";return p("button",{onClick:()=>S(b),className:`text-[12px] font-body px-3 py-1 rounded-md transition-colors whitespace-nowrap ${j?"bg-bg-elevated text-text-primary font-medium":"text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated"}`,children:[M,h&&p("span",{className:`ml-1 text-[10px] ${!g?"text-accent-green":"text-accent-red"}`,children:h},void 0,!1,void 0,this)]},b,!0,void 0,this)})},void 0,!1,void 0,this),!O||!R?p("div",{className:"flex-1 flex items-center justify-center",children:p("div",{className:"text-center text-text-tertiary font-body",children:[p("div",{className:"text-lg mb-2",children:!O?"New file":"Removed file"},void 0,!1,void 0,this),p("div",{className:"text-[13px]",children:[N.replace(/\.jsx$/,"")," ",!O?"was added":"was removed"," in this revision"]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this):z==="unified"?p(L6,{sessionId:q,leftRev:J,rightRev:X,filename:N,onDiffResult:(b,M)=>{T(b),U(M)}},`unified-${J}-${X}-${N}`,!1,void 0,this):p(M6,{sessionId:q,leftRev:J,rightRev:X,filename:N,onDiffResult:(b,M)=>{T(b),U(M)}},`sbs-${J}-${X}-${N}`,!1,void 0,this)]},void 0,!0,void 0,this)}function F6(){let[Z,$]=U1(!0);return p1(()=>{return document.documentElement.dataset.syncScroll=Z?"1":"0",()=>{delete document.documentElement.dataset.syncScroll}},[Z]),p("label",{className:"flex items-center gap-1.5 cursor-pointer select-none",children:[p("input",{type:"checkbox",checked:Z,onChange:(q)=>$(q.target.checked),className:"accent-accent-amber w-3.5 h-3.5"},void 0,!1,void 0,this),p("span",{className:"text-[11px] font-body text-text-secondary",children:"Sync scroll"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function L6({sessionId:Z,leftRev:$,rightRev:q,filename:Q,onDiffResult:J}){let Y=E1(null),X=E1(null),G=E1(null),[z,_]=U1(!1),[H,U]=U1(!1),[W,T]=U1(!1),[K,L]=U1(null),[N,S]=U1(!1),{annotations:O}=X1(),R=O.filter((M)=>!M.filePath&&(!M.canvasFile||M.canvasFile===Q)),{popovers:b}=n1({containerRef:G,restoreKey:W,restoreAnnotations:R,extractContext:(M)=>a1(M,G.current)});return p1(()=>{if(W||K)return;let M=setTimeout(()=>{console.warn("[unified-diff] still loading after 10s",{leftReady:z,rightReady:H,oldRef:!!Y.current,newRef:!!X.current}),S(!0)},1e4);return()=>clearTimeout(M)},[W,K,z,H]),p1(()=>{if(!z||!H||W)return;if(!Y.current||!X.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!Y.current||!X.current||!G.current){console.warn("[unified-diff] refs lost between rAF frames",{old:!!Y.current,new:!!X.current,unified:!!G.current});return}try{let M=W0(Y.current),j=W0(X.current),g=D0(M,j),{fragment:C,hasChanges:h}=G2(g);G.current.innerHTML="",G.current.appendChild(C),T(!0),J(!0,h)}catch(M){console.error("[unified-diff] diff computation failed",M),L(M instanceof Error?M.message:String(M))}})})},[z,H,W]),p("div",{className:"flex-1 min-h-0 overflow-y-auto",children:[!W&&!K&&p("div",{style:{position:"absolute",left:-9999,visibility:"hidden",pointerEvents:"none",width:720},children:[p(x1,{ref:Y,sessionId:Z,revision:$,filename:Q,onReady:()=>_(!0),onError:(M)=>L(`Rev ${$}: ${M}`)},void 0,!1,void 0,this),p(x1,{ref:X,sessionId:Z,revision:q,filename:Q,onReady:()=>U(!0),onError:(M)=>L(`Rev ${q}: ${M}`)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),p("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:[!W&&!K&&p("div",{className:"flex flex-col items-center justify-center h-64 text-text-tertiary font-body text-body gap-2",children:[p("span",{children:"Loading..."},void 0,!1,void 0,this),N&&p("span",{className:"text-[11px]",children:"Taking longer than expected — check Network tab for pending requests"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),K&&p("div",{className:"bg-accent-red-muted rounded-lg p-5 mt-8",children:[p("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Failed to load revision"},void 0,!1,void 0,this),p("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:K},void 0,!1,void 0,this)]},void 0,!0,void 0,this),p("div",{ref:G},void 0,!1,void 0,this)]},void 0,!0,void 0,this),b]},void 0,!0,void 0,this)}function M6({sessionId:Z,leftRev:$,rightRev:q,filename:Q,onDiffResult:J}){let Y=E1(null),X=E1(null),[G,z]=U1(!1),[_,H]=U1(!1),[U,W]=U1(!1),T=E1(null),K=E1(null),L=E1(null),N=E1(!1),S=L5(()=>z(!0),[]),O=L5(()=>H(!0),[]),{annotations:R}=X1(),b=R.filter((j)=>!j.filePath&&(!j.canvasFile||j.canvasFile===Q)),{popovers:M}=n1({containerRef:T,restoreKey:U,restoreAnnotations:b,extractContext:(j)=>a1(j,T.current)});return p1(()=>{if(!G||!_||U)return;if(!Y.current||!X.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!Y.current||!X.current)return;let j=_2(Y.current,X.current);W(!0),J(!0,j)})})},[G,_,U]),p1(()=>{let j=K.current,g=L.current;if(!j||!g)return;let C=(l,V)=>{if(document.documentElement.dataset.syncScroll==="0")return;if(N.current)return;N.current=!0;let E=l.scrollHeight-l.clientHeight,c=V.scrollHeight-V.clientHeight;if(E>0&&c>0)V.scrollTop=l.scrollTop/E*c;requestAnimationFrame(()=>{N.current=!1})},h=()=>C(j,g),v=()=>C(g,j);return j.addEventListener("scroll",h),g.addEventListener("scroll",v),()=>{j.removeEventListener("scroll",h),g.removeEventListener("scroll",v)}},[]),p("div",{ref:T,className:"flex flex-1 min-h-0",children:[p("div",{ref:K,className:"w-1/2 overflow-y-auto border-r border-border-subtle",children:p("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:p(x1,{ref:Y,sessionId:Z,revision:$,filename:Q,onReady:S},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),p("div",{ref:L,className:"w-1/2 overflow-y-auto",children:p("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:p(x1,{ref:X,sessionId:Z,revision:q,filename:Q,onReady:O},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),M]},void 0,!0,void 0,this)}var x1=F5.memo(F5.forwardRef(({sessionId:Z,revision:$,filename:q,onReady:Q,onError:J},Y)=>{let[X,G]=U1(null),[z,_]=U1(null),[H,U]=U1(!0);p1(()=>{U(!0),_(null);let T=q.replace(/\.jsx$/,".js");import(`/api/session/${Z}/canvas/${encodeURIComponent(T)}?rev=${$}&t=${Date.now()}`).then((K)=>{if(!K.default){_("Module has no default export"),U(!1),J?.("Module has no default export");return}G(()=>K.default),U(!1)}).catch((K)=>{_(K.message),U(!1),J?.(K.message)})},[Z,$,q]),p1(()=>{if(!X)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{Q()})})},[X]);let W=U2(()=>X?p(X,{},void 0,!1,void 0,this):null,[X]);if(H)return p("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-body",children:"Loading..."},void 0,!1,void 0,this);if(z)return p("div",{className:"bg-accent-red-muted rounded-lg p-5",children:[p("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Error"},void 0,!1,void 0,this),p("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:z},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(!X)return p("div",{className:"text-text-tertiary text-center py-8 font-body text-body",children:"No canvas loaded"},void 0,!1,void 0,this);return p("div",{ref:Y,children:W},void 0,!1,void 0,this)}));import{useState as m1,useContext as i2,useMemo as P6,useRef as k0,useEffect as y5,useCallback as P5}from"react";import{SessionContext as y6}from"#canvas/runtime";import{jsxDEV as d}from"react/jsx-dev-runtime";function a2(Z,$){if(!Z)return[];return Z.canvasFiles.map((q)=>{if(!q.diffStats)return{filename:q.filename,status:"new"};if(q.diffStats.added===0&&q.diffStats.removed===0)return{filename:q.filename,status:"unchanged",diffStats:q.diffStats};return{filename:q.filename,status:"changed",diffStats:q.diffStats}})}function S5(Z){return Z.filter(($)=>$.status!=="unchanged").map(($)=>$.filename)}function b5({revision:Z,responseBanner:$}){let{setActiveView:q}=i2(k1),{revisions:Q}=i2(A1),J=Q.find((_)=>_.revision===Z),Y=Q.find((_)=>_.revision===Z-1),X=P6(()=>a2(J,Y),[J,Y]),G=X.filter((_)=>_.status!=="unchanged"),z=X.filter((_)=>_.status==="unchanged");return d("div",{className:"max-w-[720px] mx-auto px-6 pt-12 pb-32",children:[$,G.map((_)=>d(b6,{change:_,revision:Z,previousRevision:Y?.revision,onOpenTab:()=>q({type:"canvas",filename:_.filename})},_.filename,!1,void 0,this)),z.length>0&&d("div",{className:"mt-8 border-t border-border-subtle pt-4",children:[d("div",{className:"text-[11px] font-body font-medium uppercase tracking-widest text-text-tertiary mb-3",children:"Unchanged"},void 0,!1,void 0,this),z.map((_)=>d(C6,{change:_,revision:Z,onOpenTab:()=>q({type:"canvas",filename:_.filename})},_.filename,!1,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function S6({mode:Z,onChange:$,showDiff:q}){if(!q)return null;return d("div",{className:"flex items-center bg-bg-elevated rounded-md p-0.5",children:["rendered","unified","side-by-side"].map((Q)=>d("button",{onClick:()=>$(Q),className:`text-[10px] font-body px-2 py-0.5 rounded transition-colors ${Z===Q?"bg-bg-surface text-text-primary font-medium shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:Q==="rendered"?"Full":Q==="unified"?"Unified":"Split"},Q,!1,void 0,this))},void 0,!1,void 0,this)}function b6({change:Z,revision:$,previousRevision:q,onOpenTab:Q}){let J=Z.filename.replace(/\.jsx$/,""),Y=Z.status==="new",X=Z.diffStats,G=Z.status==="changed"&&q!=null,[z,_]=m1("rendered");return d("div",{className:"mb-8",children:[d("div",{className:"flex items-center gap-2 mb-3 pb-2 border-b border-border-subtle",children:[d("span",{className:`text-[11px] font-mono px-1.5 py-0.5 rounded ${Y?"bg-accent-green/10 text-accent-green border border-accent-green/20":"bg-accent-amber/10 text-accent-amber border border-accent-amber/20"}`,children:Y?"new":"modified"},void 0,!1,void 0,this),d("span",{className:"text-[14px] font-body font-medium text-text-primary",children:J},void 0,!1,void 0,this),X&&(X.added>0||X.removed>0)&&d("span",{className:"text-[11px] font-mono text-text-tertiary",children:[d("span",{className:"text-accent-green",children:["+",X.added]},void 0,!0,void 0,this)," ",d("span",{className:"text-accent-red",children:["-",X.removed]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),d(S6,{mode:z,onChange:_,showDiff:G},void 0,!1,void 0,this),d("button",{onClick:Q,className:`${G?"":"ml-auto"} text-[11px] font-body font-medium text-accent-blue hover:text-accent-blue/80 transition-colors`,children:"Open in tab"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z==="rendered"?d("div",{"data-canvas-file":Z.filename,children:d(w0,{revision:$,filename:Z.filename},void 0,!1,void 0,this)},void 0,!1,void 0,this):G&&q!=null?d(j6,{filename:Z.filename,leftRev:q,rightRev:$,mode:z},`${z}-${$}-${q}`,!1,void 0,this):null]},void 0,!0,void 0,this)}function j6({filename:Z,leftRev:$,rightRev:q,mode:Q}){let J=i2(y6);if(Q==="unified")return d(w6,{sessionId:J,filename:Z,leftRev:$,rightRev:q},void 0,!1,void 0,this);return d(A6,{sessionId:J,filename:Z,leftRev:$,rightRev:q},void 0,!1,void 0,this)}function w6({sessionId:Z,filename:$,leftRev:q,rightRev:Q}){let J=k0(null),Y=k0(null),X=k0(null),[G,z]=m1(!1),[_,H]=m1(!1),[U,W]=m1(!1),[T,K]=m1(null);return y5(()=>{if(!G||!_||U)return;if(!J.current||!Y.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!J.current||!Y.current||!X.current)return;try{let L=W0(J.current),N=W0(Y.current),S=D0(L,N),{fragment:O}=G2(S);X.current.innerHTML="",X.current.appendChild(O),W(!0)}catch(L){K(L instanceof Error?L.message:String(L))}})})},[G,_,U]),d("div",{children:[!U&&!T&&d("div",{style:{position:"absolute",left:-9999,visibility:"hidden",pointerEvents:"none",width:720},children:[d(x1,{ref:J,sessionId:Z,revision:q,filename:$,onReady:()=>z(!0),onError:(L)=>K(L)},void 0,!1,void 0,this),d(x1,{ref:Y,sessionId:Z,revision:Q,filename:$,onReady:()=>H(!0),onError:(L)=>K(L)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!U&&!T&&d("div",{className:"flex items-center justify-center h-24 text-text-tertiary font-body text-[13px]",children:"Computing diff..."},void 0,!1,void 0,this),T&&d("div",{className:"text-accent-red text-[13px] font-body p-3 bg-accent-red-muted rounded-lg",children:T},void 0,!1,void 0,this),d("div",{ref:X},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function A6({sessionId:Z,filename:$,leftRev:q,rightRev:Q}){let J=k0(null),Y=k0(null),[X,G]=m1(!1),[z,_]=m1(!1),[H,U]=m1(!1),W=P5(()=>G(!0),[]),T=P5(()=>_(!0),[]);return y5(()=>{if(!X||!z||H)return;if(!J.current||!Y.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!J.current||!Y.current)return;_2(J.current,Y.current),U(!0)})})},[X,z,H]),d("div",{className:"flex gap-0 border-y border-border-subtle overflow-hidden w-screen relative left-1/2 -translate-x-1/2",children:[d("div",{className:"w-1/2 border-r border-border-subtle",children:[d("div",{className:"px-2 py-1 text-[10px] font-body font-medium text-text-tertiary bg-bg-elevated border-b border-border-subtle",children:["Rev ",q]},void 0,!0,void 0,this),d("div",{className:"px-6 py-4 max-w-[600px] mx-auto",children:d(x1,{ref:J,sessionId:Z,revision:q,filename:$,onReady:W},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),d("div",{className:"w-1/2",children:[d("div",{className:"px-2 py-1 text-[10px] font-body font-medium text-text-tertiary bg-bg-elevated border-b border-border-subtle",children:["Rev ",Q]},void 0,!0,void 0,this),d("div",{className:"px-6 py-4 max-w-[600px] mx-auto",children:d(x1,{ref:Y,sessionId:Z,revision:Q,filename:$,onReady:T},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function C6({change:Z,revision:$,onOpenTab:q}){let[Q,J]=m1(!1),Y=Z.filename.replace(/\.jsx$/,"");return d("div",{className:"mb-2",children:[d("div",{className:"flex items-center gap-2 py-1.5",children:[d("button",{onClick:()=>J(!Q),className:"text-text-tertiary hover:text-text-secondary transition-colors",children:d("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",className:`transition-transform duration-150 ${Q?"rotate-90":""}`,children:d("path",{d:"M3.5 2L6.5 5L3.5 8",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),d("span",{className:"text-[13px] font-body text-text-secondary",children:Y},void 0,!1,void 0,this),d("button",{onClick:q,className:"ml-auto text-[11px] font-body text-text-tertiary hover:text-accent-blue transition-colors",children:"Open in tab"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Q&&d("div",{className:"ml-5 mt-1 mb-3","data-canvas-file":Z.filename,children:d(w0,{revision:$,filename:Z.filename},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{useState as K2,useEffect as V6,useCallback as o2}from"react";import{jsxDEV as s}from"react/jsx-dev-runtime";function j5({sessionId:Z,revision:$,open:q,shareEnabled:Q,existingShares:J,onClose:Y,onShareCreated:X,onShareRevoked:G}){let[z,_]=K2(!1),[H,U]=K2(!1),[W,T]=K2(null),[K,L]=K2(!1),N=J.find((b)=>b.revision===$);V6(()=>{if(!q)_(!1),U(!1),T(null),L(!1)},[q]);let S=o2(async()=>{_(!0),T(null);try{let b=await fetch(`/api/session/${Z}/revision/${$}/share`,{method:"POST"}),M=await b.json();if(!b.ok||!M.ok)throw Error(M.error||`HTTP ${b.status}`);X(M.share)}catch(b){T(b.message||String(b))}finally{_(!1)}},[Z,$,X]),O=o2(async(b)=>{if(!window.confirm("Revoke this share link? Reviewers will no longer be able to view or comment."))return;U(!0),T(null);try{let M=await fetch(`/api/session/${Z}/shares/${b}/revoke`,{method:"POST"}),j=await M.json();if(!M.ok||!j.ok)throw Error(j.error||`HTTP ${M.status}`);G(b)}catch(M){T(M.message||String(M))}finally{U(!1)}},[Z,G]),R=o2((b)=>{navigator.clipboard.writeText(b).then(()=>{L(!0),setTimeout(()=>L(!1),1500)})},[]);if(!q)return null;return s("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:Y,children:s("div",{className:"bg-bg-surface border border-border-medium rounded-lg shadow-xl w-full max-w-md mx-4 p-5",onClick:(b)=>b.stopPropagation(),children:[s("div",{className:"flex items-center justify-between mb-3",children:[s("h2",{className:"text-sm font-medium text-text-primary font-body",children:"Share this revision"},void 0,!1,void 0,this),s("button",{onClick:Y,className:"w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",children:s("span",{className:"text-xs",children:"✕"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!Q?s("div",{className:"text-[13px] text-text-secondary font-body space-y-2",children:[s("p",{children:"Canvas sharing is not configured."},void 0,!1,void 0,this),s("p",{className:"text-text-tertiary",children:["Set ",s("code",{className:"px-1 py-0.5 rounded bg-bg-elevated text-text-primary text-[11px]",children:"CANVAS_SHARE_ENDPOINT"},void 0,!1,void 0,this)," to the URL of a deployed"," ",s("code",{className:"px-1 py-0.5 rounded bg-bg-elevated text-text-primary text-[11px]",children:"canvas-share"},void 0,!1,void 0,this)," worker and restart the daemon."]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):N?s("div",{className:"space-y-3",children:[s("p",{className:"text-[13px] text-text-secondary font-body",children:"This revision is shared:"},void 0,!1,void 0,this),s("div",{className:"flex gap-2",children:[s("input",{type:"text",readOnly:!0,value:N.url,className:"flex-1 px-2 py-1.5 text-[12px] font-mono bg-bg-input border border-border-medium rounded text-text-primary",onFocus:(b)=>b.currentTarget.select()},void 0,!1,void 0,this),s("button",{onClick:()=>R(N.url),className:"px-3 py-1.5 text-[12px] font-body font-medium rounded bg-accent-blue text-white hover:opacity-90 transition-opacity whitespace-nowrap",children:K?"Copied!":"Copy"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),N.expiresAt&&s("p",{className:"text-[11px] text-text-tertiary font-body",children:["Expires ",new Date(N.expiresAt).toLocaleDateString(),"."]},void 0,!0,void 0,this),N.encryptionKey&&s("p",{className:"text-[11px] text-accent-green font-body flex items-center gap-1.5",children:[s("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[s("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"},void 0,!1,void 0,this),s("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),"End-to-end encrypted — the key is part of the link and never leaves your browser."]},void 0,!0,void 0,this),s("p",{className:"text-[11px] text-text-tertiary font-body",children:"Anyone with this link can view and leave feedback. Reviewer feedback will appear in your annotation sidebar within seconds."},void 0,!1,void 0,this),s("div",{className:"flex items-center justify-between pt-1",children:[s("button",{onClick:S,disabled:z||H,className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body underline disabled:opacity-50",children:z?"Creating...":"Create a new link"},void 0,!1,void 0,this),N.ownerToken&&s("button",{onClick:()=>O(N.shareId),disabled:z||H,className:"text-[11px] text-accent-red hover:opacity-80 font-body underline disabled:opacity-50",children:H?"Revoking...":"Revoke link"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):s("div",{className:"space-y-3",children:[s("p",{className:"text-[13px] text-text-secondary font-body",children:"Create a public link to this revision. Anyone with the link can view the canvas and leave feedback. Reviewer feedback will sync back here automatically."},void 0,!1,void 0,this),s("button",{onClick:S,disabled:z,className:"w-full px-3 py-2 text-[13px] font-body font-medium rounded bg-accent-blue text-white hover:opacity-90 transition-opacity disabled:opacity-50",children:z?"Creating share link...":"Create share link"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),W&&s("div",{className:"mt-3 px-3 py-2 rounded bg-accent-red/10 border border-accent-red/20 text-[12px] text-accent-red font-body",children:W},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function w5({onClick:Z,title:$="Share this revision",hasShare:q}){return s("button",{onClick:Z,className:`group p-1.5 transition-colors ${q?"text-accent-blue hover:opacity-80":"text-text-tertiary hover:text-text-secondary"}`,title:$,children:s("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[s("circle",{cx:"18",cy:"5",r:"3"},void 0,!1,void 0,this),s("circle",{cx:"6",cy:"12",r:"3"},void 0,!1,void 0,this),s("circle",{cx:"18",cy:"19",r:"3"},void 0,!1,void 0,this),s("line",{x1:"8.59",y1:"13.51",x2:"15.42",y2:"17.49"},void 0,!1,void 0,this),s("line",{x1:"15.41",y1:"6.51",x2:"8.59",y2:"10.49"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}import{useState as I6,useEffect as R6,useRef as D6}from"react";import{jsxDEV as P1}from"react/jsx-dev-runtime";function A5({open:Z,onClose:$,onSubmit:q}){let[Q,J]=I6(""),Y=D6(null);if(R6(()=>{if(Z)J(""),setTimeout(()=>Y.current?.focus(),50)},[Z]),!Z)return null;let X=Q.trim(),G=X.length>=1&&X.length<=80,z=()=>{if(!G)return;q(X)};return P1("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:$,children:P1("div",{className:"bg-bg-surface border border-border-medium rounded-lg shadow-xl w-full max-w-md mx-4 p-5",onClick:(_)=>_.stopPropagation(),children:[P1("div",{className:"flex items-center justify-between mb-3",children:[P1("h2",{className:"text-sm font-medium text-text-primary font-body",children:"Your name"},void 0,!1,void 0,this),P1("button",{onClick:$,className:"w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",children:P1("span",{className:"text-xs",children:"✕"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),P1("p",{className:"text-[13px] text-text-secondary font-body mb-3 leading-relaxed",children:"Before you leave feedback, please enter a name so the canvas author knows who reviewed it. This is stored locally in your browser."},void 0,!1,void 0,this),P1("input",{ref:Y,type:"text",value:Q,onChange:(_)=>J(_.target.value),onKeyDown:(_)=>{if(_.key==="Enter")z()},maxLength:80,placeholder:"e.g. Alice",className:"w-full px-3 py-2 text-[13px] font-body bg-bg-input border border-border-medium rounded text-text-primary placeholder:text-text-disabled focus:outline-none focus:border-accent-blue"},void 0,!1,void 0,this),P1("div",{className:"flex justify-end gap-2 mt-4",children:[P1("button",{onClick:$,className:"px-3 py-1.5 text-[12px] font-body font-medium rounded text-text-secondary hover:text-text-primary hover:bg-bg-elevated transition-colors",children:"Cancel"},void 0,!1,void 0,this),P1("button",{onClick:z,disabled:!G,className:"px-3 py-1.5 text-[12px] font-body font-medium rounded bg-accent-blue text-white hover:opacity-90 transition-opacity disabled:opacity-50",children:"Submit feedback"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}import{jsxDEV as B,Fragment as E0}from"react/jsx-dev-runtime";function V5(Z){let $=[];for(let q of Z)for(let Q of q.annotations)$.push({...Q,source:"remote",author:q.author});return $}var k1=k5({activeView:{type:"overview"},setActiveView:()=>{},openFiles:[],closeFile:()=>{},canvasFiles:[]}),A1=k5({currentRevision:1,selectedRevision:1,revisions:[],setSelectedRevision:()=>{},isReadOnly:!1,compareRevision:null,setCompareRevision:()=>{},agentWatching:!1});function m6(Z){if(Z==="auto")return window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light";return Z}function I5(Z){document.documentElement.dataset.theme=m6(Z)}function x5(){let[Z,$]=J1(()=>{let J=localStorage.getItem("canvas-theme");if(J==="light"||J==="dark"||J==="auto")return J;return"auto"});return y1(()=>{if(I5(Z),Z!=="auto")return;let J=window.matchMedia("(prefers-color-scheme: dark)"),Y=()=>I5("auto");return J.addEventListener("change",Y),()=>J.removeEventListener("change",Y)},[Z]),B("button",{onClick:()=>{let J=Z==="auto"?"light":Z==="light"?"dark":"auto";localStorage.setItem("canvas-theme",J),$(J)},className:"w-7 h-7 flex items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:{auto:"Theme: system (click for light)",light:"Theme: light (click for dark)",dark:"Theme: dark (click for system)"}[Z],children:Z==="auto"?B("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[B("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2",ry:"2"},void 0,!1,void 0,this),B("line",{x1:"8",y1:"21",x2:"16",y2:"21"},void 0,!1,void 0,this),B("line",{x1:"12",y1:"17",x2:"12",y2:"21"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):Z==="dark"?B("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:B("path",{d:"M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"},void 0,!1,void 0,this)},void 0,!1,void 0,this):B("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[B("circle",{cx:"12",cy:"12",r:"5"},void 0,!1,void 0,this),B("line",{x1:"12",y1:"1",x2:"12",y2:"3"},void 0,!1,void 0,this),B("line",{x1:"12",y1:"21",x2:"12",y2:"23"},void 0,!1,void 0,this),B("line",{x1:"4.22",y1:"4.22",x2:"5.64",y2:"5.64"},void 0,!1,void 0,this),B("line",{x1:"18.36",y1:"18.36",x2:"19.78",y2:"19.78"},void 0,!1,void 0,this),B("line",{x1:"1",y1:"12",x2:"3",y2:"12"},void 0,!1,void 0,this),B("line",{x1:"21",y1:"12",x2:"23",y2:"12"},void 0,!1,void 0,this),B("line",{x1:"4.22",y1:"19.78",x2:"5.64",y2:"18.36"},void 0,!1,void 0,this),B("line",{x1:"18.36",y1:"5.64",x2:"19.78",y2:"4.22"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function m5(){let{currentRevision:Z,selectedRevision:$,revisions:q,setSelectedRevision:Q,setCompareRevision:J}=c1.useContext(A1);if(q.length<=1){let G=q[0]?.label||`Round ${Z}`;return B("span",{className:"text-[11px] text-text-tertiary font-body",children:G},void 0,!1,void 0,this)}return B("div",{className:"flex flex-col gap-1",children:[B(I0,{value:$,onChange:Q,accent:$===Z?"default":"amber"},void 0,!1,void 0,this),B("button",{onClick:()=>{let X;if($===Z)X=[...q].reverse().find((z)=>z.revision<Z)?.revision??Math.max(1,Z-1);else X=$;J({left:X,right:Z})},className:"text-[11px] font-body font-medium px-2 py-0.5 rounded-md text-accent-blue hover:bg-accent-blue-muted transition-colors self-start",children:"Compare"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function u6(){let Z=$1.isShared?$1.shareId:$1.sessionId,$=$1.isShared,[q,Q]=J1(1),[J,Y]=J1(1),[X,G]=J1([]),[z,_]=J1(null),[H,U]=J1(!1),[W,T]=J1(!1),[K,L]=J1(!1),[N,S]=J1([]),[O,R]=J1({type:"overview"}),[b,M]=J1([]),j=V1(null),g=V1([]),C=V1(new Set),[h,v]=J1(),[l,V]=J1(!1),[E,c]=J1(!1),[P,x]=J1(!1),[f,o]=J1(!1),[w,F]=J1([]),[m,u]=J1(!1),[D,a]=J1(new Map),[I,k]=J1(!1),[Z1,Y1]=J1(null),[I1,S1]=J1(null),N0=T0((A)=>{if($)return;let i=`${A.revision}\x00${A.filename}\x00${A.message}`;if(C.current.has(i))return;C.current.add(i);let t=JSON.stringify({type:"render-error",error:A});if(j.current?.readyState===WebSocket.OPEN)j.current.send(t);else g.current.push(A)},[$]);y1(()=>{if(!I1)return;let A=setTimeout(()=>S1(null),4000);return()=>clearTimeout(A)},[I1]),y1(()=>{let A=["Agent Canvas"];if(h){let i=h.replace(/\/+$/,"").split("/");A.push(i[i.length-1]||Z)}else if(Z)A.push(Z);if(O.type==="file")A.push(O.path.split("/").pop()||O.path);else if(O.type==="overview")A.push("Overview");else if(O.type==="canvas"&&N.length>1&&O.filename)A.push(O.filename.replace(/\.jsx$/,""));else if(z)A.push("Compare");document.title=A.join(" — ")},[Z,h,O,z]);let H2=V1(new Map),J0=X.find((A)=>A.revision===J),s2=J!==q||!!J0?.hasFeedback||W,t2=J===q&&(!!J0?.hasFeedback||W)?"next":"current",n2=T0((A)=>{let i=O.type==="overview"?"overview":O.type==="canvas"?`canvas:${O.filename}`:`file:${O.path}`;if(H2.current.set(i,window.scrollY),R(A),A.type==="file")M((t)=>t.includes(A.path)?t:[...t,A.path])},[O]),u5=T0((A)=>{H2.current.delete(`file:${A}`),M((i)=>i.filter((t)=>t!==A)),R((i)=>{if(i.type==="file"&&i.path===A)return N.length>1?{type:"overview"}:{type:"canvas",filename:N[0]||""};return i})},[N]);k6(()=>{let A=O.type==="overview"?"overview":O.type==="canvas"?`canvas:${O.filename}`:`file:${O.path}`;window.scrollTo(0,H2.current.get(A)||0)},[O]),y1(()=>{if(!Z)return;j3().then((A)=>{if(A.currentRevision){let i=A.revisions||[];for(let t of i)if(t.hasFeedback)z0(localStorage,Z,t.revision);C2(localStorage,Z,A.currentRevision,i),Q(A.currentRevision),Y(A.currentRevision),G(i)}if(A.canvasFiles){let i=A.canvasFiles.sort();S(i),R((t)=>{if(t.type==="overview")return i.length>1?t:{type:"canvas",filename:i[0]||""};if(t.type==="canvas"&&(!t.filename||!i.includes(t.filename)))return{type:"canvas",filename:i[0]||""};return t})}if(A.projectRoot)v(A.projectRoot);if(Array.isArray(A.shares))F(A.shares);u(!!A.shareEnabled)}).catch(()=>{})},[Z]),y1(()=>{if(!Z||!J||$)return;fetch(`/api/session/${Z}/revision/${J}/remote-feedback`).then((A)=>A.json()).then((A)=>{if(!Array.isArray(A.entries))return;let i=V5(A.entries);a((t)=>{let N1=new Map(t);return N1.set(J,i),N1})}).catch(()=>{})},[Z,J,$]),y1(()=>{if(!Z)return;if(!I3){U(!0);return}let A=null,i=()=>{let t=window.location.protocol==="https:"?"wss:":"ws:",N1=new WebSocket(`${t}//${window.location.host}/ws/session/${Z}`);j.current=N1,N1.onopen=()=>{U(!0);for(let x0 of g.current)N1.send(JSON.stringify({type:"render-error",error:x0}));g.current=[]},N1.onclose=()=>{U(!1),A=setTimeout(i,2000)},N1.onmessage=(x0)=>{try{let z1=JSON.parse(x0.data);if(z1.type==="plan-updated"){let O1=Array.isArray(z1.revisions)?z1.revisions:[];if(C2(localStorage,Z,z1.currentRevision,O1),Q(z1.currentRevision),Y(z1.currentRevision),_(null),O1.length>0){G(O1);let u1=O1.find((d1)=>d1.revision===z1.currentRevision);if(u1?.canvasFiles){let d1=u1.canvasFiles.map((B0)=>B0.filename).sort();S(d1);let T2=O1.find((B0)=>B0.revision===z1.currentRevision-1),O0=a2(u1,T2),Q0=S5(O0);if(Q0.length===1)R({type:"canvas",filename:Q0[0]});else if(Q0.length>1||d1.length>1)R({type:"overview"});else R({type:"canvas",filename:d1[0]||""})}}}if(z1.type==="revision-updated"){if(Array.isArray(z1.revisions)){let O1=z1.revisions;for(let u1 of O1)if(u1.hasFeedback)z0(localStorage,Z,u1.revision);G(O1)}}if(z1.type==="watcher-status")L(!!z1.watching);if(z1.type==="remote-feedback"){let O1=z1.revision,u1=z1.entries||[],d1=V5(u1);a((T2)=>{let O0=new Map(T2),Q0=O0.get(O1)||[],B0=new Set(Q0.map((N2)=>N2.id)),g5=[...Q0,...d1.filter((N2)=>!B0.has(N2.id))];return O0.set(O1,g5),O0})}}catch{}}};return i(),()=>{if(A)clearTimeout(A);j.current?.close()}},[Z]);let W2=T0(async(A,i)=>{try{let t=localStorage.getItem(`canvas:${Z}:rev:${J}`),N1=[];if(t)try{N1=(JSON.parse(t).annotations||[]).filter((z1)=>z1.source!=="remote")}catch{}await V3({author:i,revision:J,annotations:N1,generalNote:A}),z0(localStorage,Z,J),T(!0),S1({kind:"success",message:"Feedback submitted. The canvas author will see it shortly."})}catch(t){S1({kind:"error",message:`Failed to submit feedback: ${t.message||t}`})}},[Z,J]),e2=T0(async(A)=>{if($){let i=I2();if(!i){Y1(A),k(!0);return}await W2(A,i);return}if(j.current?.readyState===WebSocket.OPEN)j.current.send(JSON.stringify({type:"submit",feedback:A}))},[$,W2]);if(!Z)return B("div",{className:"flex items-center justify-center h-screen text-text-tertiary font-body",children:"No session selected."},void 0,!1,void 0,this);return B(E5.Provider,{value:Z,children:B(t0.Provider,{value:N0,children:B(A1.Provider,{value:{currentRevision:q,selectedRevision:J,revisions:X,setSelectedRevision:Y,isReadOnly:s2,compareRevision:z,setCompareRevision:_,agentWatching:K},children:B(B3,{sessionId:Z,revision:J,isReadOnly:s2,draftPhase:t2,remoteAnnotations:D.get(J),children:B(k1.Provider,{value:{activeView:O,setActiveView:n2,openFiles:b,closeFile:u5,canvasFiles:N},children:B(x6.Provider,{value:{setActiveView:n2},children:B("div",{className:"min-h-screen bg-bg-base",children:[B(g6,{sessionId:Z,projectRoot:h,connected:H,onMobileSidebar:()=>V(!l),collapsed:E,onToggle:()=>c((A)=>!A)},void 0,!1,void 0,this),B(f6,{collapsed:P,onToggle:()=>x((A)=>!A),children:B(p2,{onSubmit:e2},void 0,!1,void 0,this)},void 0,!1,void 0,this),z!==null?B("div",{className:`${E?"lg:ml-0":"lg:ml-60"} ${P?"lg:mr-0":"lg:mr-[var(--sidebar-width,320px)]"} transition-[margin] duration-200`,children:B(M5,{initialLeft:z.left,initialRight:z.right,sessionId:Z,onExit:()=>_(null)},void 0,!1,void 0,this)},void 0,!1,void 0,this):B("div",{className:`relative ${E?"lg:ml-0":"lg:ml-60"} ${P?"lg:mr-0":"lg:mr-[var(--sidebar-width,320px)]"} transition-[margin] duration-200`,id:"plan-scroll-container",children:[B("div",{className:"lg:hidden sticky top-0 z-20 flex items-center justify-between px-4 py-2 border-b border-border-subtle bg-bg-surface",children:[B("div",{className:"flex items-center gap-2",children:[!$&&B(d2,{currentSessionId:Z,projectRoot:h},void 0,!1,void 0,this),$&&B("span",{className:"text-[11px] text-text-tertiary font-body",children:"Shared canvas"},void 0,!1,void 0,this),!$&&B("span",{className:`w-1.5 h-1.5 rounded-full ${H?"bg-accent-green":"bg-accent-red"}`},void 0,!1,void 0,this)]},void 0,!0,void 0,this),B("div",{className:"flex items-center gap-1",children:[B(m5,{},void 0,!1,void 0,this),B("button",{onClick:()=>V(!l),className:"w-7 h-7 flex items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Annotations",children:B("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:B("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),B(x5,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),B(v6,{},void 0,!1,void 0,this),O.type==="overview"&&B(b5,{revision:J,responseBanner:J0?.response?B(R5,{markdown:J0.response},void 0,!1,void 0,this):void 0},void 0,!1,void 0,this),O.type==="canvas"&&N.includes(O.filename)&&B("div",{className:"relative max-w-[720px] mx-auto px-6 pt-12 pb-32",children:[m&&B("div",{className:"absolute top-3 right-12 z-10",children:B(w5,{onClick:()=>o(!0),hasShare:w.some((A)=>A.revision===J),title:w.some((A)=>A.revision===J)?"Manage share link":"Share this revision"},void 0,!1,void 0,this)},void 0,!1,void 0,this),B("button",{onClick:()=>{let A=document.querySelector(`[data-canvas-file="${O.filename}"] .plan-content`);if(!A)return;let i=X5(A);navigator.clipboard.writeText(i).then(()=>{let t=document.getElementById("export-md-btn");if(t)t.setAttribute("data-copied","true"),setTimeout(()=>{t.removeAttribute("data-copied")},1500)})},id:"export-md-btn",className:"group absolute top-3 right-6 p-1.5 text-text-tertiary hover:text-text-secondary transition-colors z-10",title:"Copy as Markdown",children:[B("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"group-[[data-copied=true]]:hidden",children:[B("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"},void 0,!1,void 0,this),B("path",{d:"M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),B("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"hidden group-[[data-copied=true]]:block text-green-500",children:B("polyline",{points:"20 6 9 17 4 12"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),N.length<=1&&J0?.response&&B(R5,{markdown:J0.response},void 0,!1,void 0,this),B("div",{"data-canvas-file":O.filename,children:B(w0,{revision:J,filename:O.filename},O.filename,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),b.map((A)=>B("div",{style:{display:O.type==="file"&&O.path===A?void 0:"none"},children:B(q5,{path:A},void 0,!1,void 0,this)},A,!1,void 0,this))]},void 0,!0,void 0,this),l&&B("div",{className:"lg:hidden fixed inset-0 z-40 flex",children:[B("div",{className:"flex-1",onClick:()=>V(!1)},void 0,!1,void 0,this),B("div",{className:"w-80 max-w-[85vw] bg-bg-surface border-l border-border-subtle flex flex-col shadow-lg",children:[B("div",{className:"flex items-center justify-between px-4 py-2 border-b border-border-subtle flex-shrink-0",children:[B("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:"Sidebar"},void 0,!1,void 0,this),B("button",{onClick:()=>V(!1),className:"text-text-tertiary hover:text-text-secondary w-7 h-7 flex items-center justify-center",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),B("div",{className:"flex-1 overflow-hidden",children:B(p2,{onSubmit:e2},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),B(j5,{sessionId:Z,revision:J,open:f,shareEnabled:m,existingShares:w,onClose:()=>o(!1),onShareCreated:(A)=>{F((i)=>[...i.filter((t)=>t.shareId!==A.shareId),A]),S1({kind:"success",message:"Share link created. Copy and send it to reviewers."})},onShareRevoked:(A)=>{F((i)=>i.filter((t)=>t.shareId!==A)),S1({kind:"success",message:"Share link revoked."})}},void 0,!1,void 0,this),B(A5,{open:I,onClose:()=>{k(!1),Y1(null)},onSubmit:async(A)=>{let i=C3(A);if(k(!1),Z1!==null)await W2(Z1,i),Y1(null)}},void 0,!1,void 0,this),I1&&B("div",{className:`fixed bottom-4 left-1/2 -translate-x-1/2 z-50 px-4 py-2.5 rounded-lg shadow-lg text-[13px] font-body font-medium flex items-center gap-2 ${I1.kind==="error"?"bg-accent-red text-white":"bg-accent-green text-white"}`,children:[I1.message,B("button",{onClick:()=>S1(null),className:"ml-2 opacity-70 hover:opacity-100",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},`${Z}:${J}:${t2}`,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function g6({sessionId:Z,projectRoot:$,connected:q,onMobileSidebar:Q,collapsed:J,onToggle:Y}){let X=$1.isShared;return B(E0,{children:[J&&B("button",{onClick:Y,className:"hidden lg:flex fixed top-3 left-3 z-20 w-7 h-7 items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors bg-bg-surface border border-border-subtle",title:"Show sidebar",children:B("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[B("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"},void 0,!1,void 0,this),B("line",{x1:"9",y1:"3",x2:"9",y2:"21"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),B("div",{className:`hidden lg:flex w-60 flex-col fixed top-0 left-0 bottom-0 bg-bg-surface border-r border-border-subtle z-10 transition-transform duration-200 ${J?"-translate-x-full":""}`,children:[B("div",{className:"px-4 pt-4 pb-3 flex-shrink-0 border-b border-border-subtle",children:[B("div",{className:"flex items-center gap-2 mb-2",children:[B("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",className:"text-text-tertiary flex-shrink-0",children:B("path",{d:"M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this),X?B("span",{className:"text-[12px] font-body text-text-secondary truncate flex-1",children:"Shared canvas"},void 0,!1,void 0,this):B(E0,{children:[B(d2,{currentSessionId:Z,projectRoot:$},void 0,!1,void 0,this),B("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${q?"bg-accent-green":"bg-accent-red"}`},void 0,!1,void 0,this)]},void 0,!0,void 0,this),B("button",{onClick:Y,className:"ml-auto w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Hide sidebar",children:B("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[B("polyline",{points:"11 17 6 12 11 7"},void 0,!1,void 0,this),B("polyline",{points:"18 17 13 12 18 7"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),B(m5,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this),B("div",{className:"flex-1 flex flex-col overflow-hidden",children:B(n3,{embedded:!0},void 0,!1,void 0,this)},void 0,!1,void 0,this),B("div",{className:"px-4 py-3 border-t border-border-subtle flex items-center justify-between flex-shrink-0",children:[B("span",{className:"text-[10px] text-text-tertiary font-body uppercase tracking-widest",children:"Theme"},void 0,!1,void 0,this),B(x5,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function f6({children:Z,collapsed:$,onToggle:q}){let[Q,J]=J1(()=>{let H=localStorage.getItem("canvas-sidebar-width");return H?parseInt(H,10):320}),Y=V1(!1),X=V1(0),G=V1(0),z=V1(Q);z.current=Q;let _=T0((H)=>{H.preventDefault(),Y.current=!0,X.current=H.clientX,G.current=z.current;let U=(T)=>{if(!Y.current)return;let K=X.current-T.clientX,L=Math.max(240,Math.min(600,G.current+K));J(L),z.current=L},W=()=>{Y.current=!1,localStorage.setItem("canvas-sidebar-width",String(z.current)),document.removeEventListener("mousemove",U),document.removeEventListener("mouseup",W),document.body.style.cursor="",document.body.style.userSelect=""};document.addEventListener("mousemove",U),document.addEventListener("mouseup",W),document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[]);return y1(()=>{return document.documentElement.style.setProperty("--sidebar-width",`${Q}px`),()=>{document.documentElement.style.removeProperty("--sidebar-width")}},[Q]),B(E0,{children:[$&&B("button",{onClick:q,className:"hidden lg:flex fixed top-3 right-3 z-20 w-7 h-7 items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors bg-bg-surface border border-border-subtle",title:"Show annotations",children:B("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:B("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),B("div",{className:`hidden lg:flex flex-col fixed top-0 right-0 bottom-0 bg-bg-surface border-l border-border-subtle z-10 transition-transform duration-200 ${$?"translate-x-full":""}`,style:{width:Q},children:[B("div",{onMouseDown:_,className:"absolute left-0 top-0 bottom-0 w-1 cursor-col-resize hover:bg-accent-blue/30 transition-colors z-20",style:{marginLeft:"-2px"}},void 0,!1,void 0,this),c1.Children.map(Z,(H)=>c1.isValidElement(H)?c1.cloneElement(H,{collapseButton:B("button",{onClick:q,className:"w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Hide annotations",children:B("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[B("polyline",{points:"13 17 18 12 13 7"},void 0,!1,void 0,this),B("polyline",{points:"6 17 11 12 6 7"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}):H)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function R5({markdown:Z}){let[$,q]=J1(!1),Q=C5(()=>e.parse(Z,{async:!1}),[Z]),J=V1(null),{annotations:Y,addAnnotationWithId:X,removeAnnotation:G,updateAnnotation:z,addAnnotationImage:_,removeAnnotationImage:H,activeAnnotationId:U,setActiveAnnotationId:W}=X1(),[T,K]=J1(null),[L,N]=J1(null),S=C5(()=>Y.filter((j)=>j.filePath===T1),[Y]),[O,R]=J1(Z);if(Z!==O)R(Z),q(!1);y1(()=>{if(!J.current||S.length===0)return;let j=setTimeout(()=>{if(J.current)a0(J.current,S)},50);return()=>clearTimeout(j)},[Q,S.length]);let b=V1(null);if(y1(()=>{r0(U,b.current),b.current=U},[U]),y1(()=>{let j=J.current;if(!j)return;let g=(v)=>{let l=v.target.closest("[data-annotation-id]");if(!l)return;v.stopPropagation();let V=l.getAttribute("data-annotation-id");if(V===U)N({anchorEl:l,annId:V});else W(V)},C=(v)=>{let l=v.target.closest("[data-annotation-id]");if(l)W(l.getAttribute("data-annotation-id"))},h=(v)=>{let l=v.target.closest("[data-annotation-id]"),V=v.relatedTarget?.closest?.("[data-annotation-id]");if(l&&!V)W(null)};return j.addEventListener("click",g),j.addEventListener("mouseover",C),j.addEventListener("mouseout",h),()=>{j.removeEventListener("click",g),j.removeEventListener("mouseover",C),j.removeEventListener("mouseout",h)}},[Q,U]),y1(()=>{let j=()=>{let g=window.getSelection();if(!g||g.isCollapsed||!g.toString().trim())return;if(!J.current)return;let C=g.getRangeAt(0);if(!J.current.contains(C.startContainer))return;if(C.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let h=g.toString().trim();if(h.length<2)return;let v=C.cloneRange(),l=a1(C,J.current),V=`__pending_${Date.now()}`;try{s1(v,V)}catch{}window.getSelection()?.removeAllRanges();let E=document.querySelectorAll(`[data-annotation-id="${V}"]`),c=E[E.length-1];if(!c)return;K({anchorEl:c,tempId:V,snippet:h,ctx:l})};return document.addEventListener("mouseup",j),()=>document.removeEventListener("mouseup",j)},[]),$)return null;let M=document.getElementById("plan-scroll-container");return B("div",{className:"mb-6 rounded-lg border border-accent-blue/20 bg-accent-blue/5 relative",children:[B("button",{onClick:()=>q(!0),className:"absolute top-2 right-2 w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",children:B("span",{className:"text-xs",children:"✕"},void 0,!1,void 0,this)},void 0,!1,void 0,this),B("div",{className:"px-4 py-3 pr-10",children:[B("div",{className:"flex items-center gap-2 mb-1.5",children:[B("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-accent-blue flex-shrink-0",children:B("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this),B("span",{className:"text-[11px] font-medium uppercase tracking-widest text-accent-blue font-body",children:"Agent Response"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),B("div",{ref:J,className:"prose-canvas text-sm",dangerouslySetInnerHTML:{__html:Q}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),T&&B(G0,{anchorEl:T.anchorEl,scrollContainer:M,snippet:T.snippet,truncateAt:80,onAdd:(j,g)=>{let C=L1();i0(T.tempId,C),X(C,T.snippet,j,T1,T.ctx,g),K(null)},onCancel:()=>{o0(T.tempId),K(null)}},void 0,!1,void 0,this),L&&(()=>{let j=Y.find((g)=>g.id===L.annId);if(!j)return null;return B(U0,{anchorEl:L.anchorEl,scrollContainer:M,initialNote:j.note,initialImages:j.images,onUpdate:(g,C)=>{z(L.annId,g);let h=j.images||[];for(let v of C)if(!h.includes(v))_(L.annId,v);for(let v of h)if(!C.includes(v))H(L.annId,v)},onDelete:()=>{G(L.annId),W(null)},onClose:()=>N(null)},void 0,!1,void 0,this)})()]},void 0,!0,void 0,this)}function v6(){let{activeView:Z,setActiveView:$,openFiles:q,closeFile:Q,canvasFiles:J}=c1.useContext(k1),Y=c1.useContext(E5),{addAnnotationWithId:X,setActiveAnnotationId:G}=X1();if(!(J.length>1||q.length>0))return null;return B("div",{className:"flex items-center border-b border-border-medium bg-bg-surface overflow-x-auto sticky top-0 z-10",children:[J.length>1&&B(E0,{children:[B("button",{onClick:()=>$({type:"overview"}),className:`flex items-center gap-1.5 px-4 py-2.5 text-[13px] font-body whitespace-nowrap transition-colors relative ${Z.type==="overview"?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[B("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",className:"opacity-60",children:B("path",{d:"M12 7L2 12l10 5 10-5-10-5z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this),"Overview",Z.type==="overview"&&B("span",{className:"absolute bottom-0 left-3 right-3 h-[2px] bg-text-primary rounded-full"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),B("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),J.map((_,H)=>{let U=_.replace(/\.jsx$/,""),W=Z.type==="canvas"&&Z.filename===_;return B(c1.Fragment,{children:[B("button",{onClick:()=>$({type:"canvas",filename:_}),className:`flex items-center gap-1.5 px-4 py-2.5 text-[13px] font-body whitespace-nowrap transition-colors relative ${W?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[U,W&&B("span",{className:"absolute bottom-0 left-3 right-3 h-[2px] bg-text-primary rounded-full"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),H<J.length-1&&B("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this)]},_,!0,void 0,this)}),q.length>0&&B(E0,{children:[B("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this),q.map((_,H)=>{let U=_.split("/").pop()||_,W=Z.type==="file"&&Z.path===_;return B(c1.Fragment,{children:[B("div",{className:"flex items-center",children:[B("button",{onClick:()=>$({type:"file",path:_}),className:`flex items-center gap-1.5 pl-3 pr-1 py-2.5 text-[13px] font-body whitespace-nowrap transition-colors relative ${W?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[B(f1,{name:U,type:"file"},void 0,!1,void 0,this),U,W&&B("span",{className:"absolute bottom-0 left-3 right-1 h-[2px] bg-text-primary rounded-full"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),B("button",{onClick:(T)=>{T.stopPropagation(),Q(_)},className:"text-text-tertiary hover:text-text-secondary px-1.5 py-1 text-[10px] transition-colors rounded hover:bg-bg-input",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),H<q.length-1&&B("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this)]},_,!0,void 0,this)})]},void 0,!0,void 0,this),B("div",{className:"ml-auto flex items-center gap-1 flex-shrink-0",children:Z.type==="file"&&M1&&B("button",{onClick:async()=>{let _=Z.path;try{let U=await(await fetch(`/api/file?session=${Y}&path=${encodeURIComponent(_)}`)).json();if(!U.error){let W=U.content.split(`
|
|
83
|
+
`}var el=new Set(["CODE","SPAN","STRONG","EM","A","B","I","U","SMALL","SUB","SUP","MARK","ABBR"]);function Fn(e,t,n){if(tl(e)){let r=nl(e);if(r)t.push(r,"");return}for(let r of e.childNodes)if(r.nodeType===Node.ELEMENT_NODE)ol(r,t,n);else if(r.nodeType===Node.TEXT_NODE){let o=r.textContent?.trim();if(o)t.push(o,"")}}function tl(e){for(let t of e.childNodes){if(t.nodeType===Node.TEXT_NODE)continue;if(t.nodeType===Node.ELEMENT_NODE){let n=t;if(!el.has(n.tagName)||n.hasAttribute("data-md"))return!1}}return e.childNodes.length>0}function nl(e){let t="";for(let n of e.childNodes)if(n.nodeType===Node.TEXT_NODE)t+=n.textContent||"";else if(n.nodeType===Node.ELEMENT_NODE){let r=n;if(r.tagName==="CODE")t+="`"+(r.textContent||"")+"`";else t+=r.textContent||""}return t.trim()}function ol(e,t,n){let r=e.getAttribute("data-md");if(r)switch(r){case"section":return rl(e,t,n);case"item":return sl(e,t);case"codeblock":return il(e,t);case"callout":return al(e,t);case"note":return ll(e,t);case"markdown":return fl(e,t);case"table":return cl(e,t);case"checklist":return dl(e,t);case"diff":return ul(e,t);case"mermaid":return pl(e,t);case"choice":return ml(e,t);case"multichoice":return hl(e,t);case"choice-option":case"multichoice-option":return;case"userinput":return gl(e,t);case"rangeinput":return xl(e,t);case"checklist-item":return;case"filepreview":return bl(e,t);case"priority":return vl(e,t)}if(e.querySelector("button, input, select, textarea"))return;if(e.children.length>0)Fn(e,t,n);else{let o=e.textContent?.trim();if(o)t.push(o,"")}}function rl(e,t,n){let r=e.getAttribute("data-md-title")||"Untitled",o=n===0?"##":"###";t.push(`${o} ${r}`,"");let i=e.querySelector(":scope > div:last-of-type");if(i)Fn(i,t,n+1)}function sl(e,t){let n=e.getAttribute("data-md-label")||"",r=e.getAttribute("data-md-status"),o=e.getAttribute("data-md-badge"),i="-";if(r==="done")i="- [x]";else if(r)i="- [ ]";let s=`${i} **${n}**`;if(o)s+=` \`${o}\``;t.push(s);let l=e.querySelector(".text-text-secondary");if(l){let a=[];Fn(l,a,0);for(let c of a)t.push(c?` ${c}`:"")}t.push("")}function il(e,t){let n=e.getAttribute("data-md-language")||"",o=e.querySelector("code")?.textContent||"";t.push(`\`\`\`${n}`,o,"```","")}function al(e,t){let n=e.getAttribute("data-md-type")||"info",r={info:"Info",warning:"Warning",danger:"Danger",tip:"Tip"},o=yl(e.querySelector(".text-text-secondary")||e);t.push(`> **${r[n]||n}:** ${o}`,"")}function ll(e,t){let n=e.textContent?.trim()||"";t.push(`> *${n}*`,"")}function cl(e,t){let n=e.querySelector("table");if(!n)return;let r=[];for(let o of n.querySelectorAll("thead th"))r.push(o.textContent?.trim()||"");if(r.length===0)return;t.push(`| ${r.join(" | ")} |`),t.push(`| ${r.map(()=>"---").join(" | ")} |`);for(let o of n.querySelectorAll("tbody tr")){let i=[];for(let s of o.querySelectorAll("td"))i.push(s.textContent?.trim()||"");t.push(`| ${i.join(" | ")} |`)}t.push("")}function dl(e,t){for(let n of e.querySelectorAll("li")){let r=n.querySelector(".bg-accent-green")!==null,o=n.textContent?.trim()||"";t.push(`- [${r?"x":" "}] ${o}`)}t.push("")}function ul(e,t){let n=e.getAttribute("data-md-language")||"";t.push(`\`\`\`diff${n?` (${n})`:""}`);for(let r of e.querySelectorAll("[class*='flex']")){let o=r.querySelector(".text-accent-red")?"-":r.querySelector(".text-accent-green")?"+":" ",i=r.querySelector("code");if(i)t.push(`${o} ${i.textContent}`)}t.push("```","")}function pl(e,t){let n=e.getAttribute("data-md-source")||"";if(n)t.push("```mermaid",n,"```","")}function fl(e,t){let n=e.getAttribute("data-md-source")||"";if(n)t.push(n,"")}function ml(e,t){let n=e.getAttribute("data-md-label")||"";t.push(`**${n}:**`);for(let r of e.querySelectorAll("[data-md='choice-option']")){let o=r.getAttribute("data-md-label")||r.textContent?.trim()||"",i=r.querySelector(".bg-accent-amber")!==null;t.push(`- ${i?"(x)":"( )"} ${o}`)}t.push("")}function hl(e,t){let n=e.getAttribute("data-md-label")||"";t.push(`**${n}:**`);for(let r of e.querySelectorAll("[data-md='multichoice-option']")){let o=r.getAttribute("data-md-label")||r.textContent?.trim()||"",i=r.querySelector(".bg-accent-amber")!==null;t.push(`- [${i?"x":" "}] ${o}`)}t.push("")}function gl(e,t){let n=e.getAttribute("data-md-label")||"",o=e.querySelector("textarea")?.value?.trim()||"";t.push(`**${n}:** ${o||"_empty_"}`,"")}function xl(e,t){let n=e.getAttribute("data-md-label")||"",r=e.querySelector("input[type='range']"),i=e.querySelector(".font-mono")?.textContent?.trim()||r?.value||"—";t.push(`**${n}:** ${i}`,"")}function bl(e,t){let n=e.getAttribute("data-md-path")||"",r=e.getAttribute("data-md-lines")||"",i=e.querySelector("code")?.textContent||"",s=n.split(".").pop()||"",l=Dn[s]||"",a=r?`${n} (L${r})`:n;t.push(a,"",`\`\`\`${l}`,i,"```","")}function vl(e,t){}function yl(e){return e?.textContent?.trim()||""}import ws,{useEffect as nt,useState as ge,useRef as qe,useCallback as Es,useMemo as qn,useContext as Dl}from"react";import{useEffect as kl,useState as wl,useRef as El,useContext as Al}from"react";import{jsxDEV as be,Fragment as us}from"react/jsx-dev-runtime";function Rl(e){return e.label||`Round ${e.revision}`}function Sl(e){let t=Date.now()-new Date(e).getTime(),n=Math.floor(t/1000);if(n<60)return"just now";let r=Math.floor(n/60);if(r<60)return`${r}m ago`;let o=Math.floor(r/60);if(o<24)return`${o}h ago`;return`${Math.floor(o/24)}d ago`}function nn({value:e,onChange:t,accent:n="default",className:r}){let{currentRevision:o,revisions:i}=Al(ke),[s,l]=wl(!1),a=El(null);kl(()=>{if(!s)return;let d=(f)=>{if(a.current&&!a.current.contains(f.target))l(!1)};return document.addEventListener("mousedown",d),()=>document.removeEventListener("mousedown",d)},[s]);let c=i.find((d)=>d.revision===e);return be("div",{className:"relative",ref:a,children:[be("button",{onClick:()=>l(!s),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"}[n]} ${r||""}`,children:[c?Rl(c):`Round ${e}`,be("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",className:`text-text-tertiary transition-transform duration-200 ${s?"rotate-180":""}`,children:be("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),s&&be("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:[...i].reverse().map((d)=>be("button",{onClick:()=>{t(d.revision),l(!1)},className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] font-body transition-colors ${d.revision===e?"bg-bg-surface text-text-primary":"text-text-secondary hover:bg-bg-surface hover:text-text-primary"}`,children:[be("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${d.revision===o?"bg-accent-green":d.hasFeedback?"bg-accent-amber":"bg-border-hover"}`},void 0,!1,void 0,this),be("span",{className:"flex-1 text-left truncate",children:d.label?be(us,{children:[d.label," ",be("span",{className:"text-text-tertiary",children:["#",d.revision]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):be(us,{children:["Round ",d.revision]},void 0,!0,void 0,this)},void 0,!1,void 0,this),be("span",{className:"text-[10px] text-text-tertiary flex-shrink-0 flex items-center gap-1.5",children:[(()=>{let f=d.canvasFiles?.reduce((p,m)=>{if(m.diffStats)p.added+=m.diffStats.added,p.removed+=m.diffStats.removed;return p},{added:0,removed:0});if(f&&(f.added>0||f.removed>0))return be("span",{className:"font-mono",children:[be("span",{className:"text-accent-green",children:["+",f.added]},void 0,!0,void 0,this)," ",be("span",{className:"text-accent-red",children:["-",f.removed]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);return null})(),d.revision===o?"current":d.hasFeedback?"sent":Sl(d.createdAt)]},void 0,!0,void 0,this)]},d.revision,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function tt(e,t){let n=e.length,r=t.length;if(n===0||r===0)return[];let o=Array.from({length:n+1},()=>Array(r+1).fill(0));for(let a=1;a<=n;a++)for(let c=1;c<=r;c++)o[a][c]=e[a-1]===t[c-1]?o[a-1][c-1]+1:Math.max(o[a-1][c],o[a][c-1]);let i=[],s=n,l=r;while(s>0&&l>0)if(e[s-1]===t[l-1])i.unshift(e[s-1]),s--,l--;else if(o[s-1][l]>o[s][l-1])s--;else l--;return i}function ps(e){let t=[],n=[],r=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,{acceptNode(i){let s=i.parentElement;if(!s)return NodeFilter.FILTER_REJECT;if(s.closest("svg, .select-none, [data-no-diff]"))return NodeFilter.FILTER_REJECT;return NodeFilter.FILTER_ACCEPT}}),o;while(o=r.nextNode()){let s=(o.nodeValue||"").match(/\S+|\s+/g);if(!s)continue;let l=0;for(let a of s)t.push(a),n.push({text:a,node:o,offset:l}),l+=a.length}return{words:t,map:n}}function Fo(e,t){if(e.length>5000||t.length>5000)return Cl(e,t);return hs(e,t)}function hs(e,t){let n=Bn(e,t),r=[],o=[],i=0,s=0,l=0;while(i<e.length||s<t.length)if(l<n.length&&i<e.length&&s<t.length&&e[i]===n[l]&&t[s]===n[l])r.push({type:"same",index:i}),o.push({type:"same",index:s}),i++,s++,l++;else if(i<e.length&&(l>=n.length||e[i]!==n[l]))r.push({type:"removed",index:i}),i++;else if(s<t.length)o.push({type:"added",index:s}),s++;return{oldOps:r,newOps:o}}function Bn(e,t){let n=e.length,r=t.length;if(n===0||r===0)return[];if(n===1)return t.includes(e[0])?[e[0]]:[];if(r===1)return e.includes(t[0])?[t[0]]:[];if(n*r<=1e6)return tt(e,t);let o=Math.floor(n/2),i=e.slice(0,o),s=e.slice(o),l=fs(i,t),a=fs([...s].reverse(),[...t].reverse()),c=0,u=0;for(let p=0;p<=r;p++){let m=l[p]+a[r-p];if(m>c)c=m,u=p}let d=t.slice(0,u),f=t.slice(u);return[...Bn(i,d),...Bn(s,f)]}function fs(e,t){let n=t.length,r=Array(n+1).fill(0),o=Array(n+1).fill(0);for(let i=0;i<e.length;i++){for(let s=1;s<=n;s++)o[s]=e[i]===t[s-1]?r[s-1]+1:Math.max(r[s],o[s-1]);[r,o]=[o,r],o.fill(0)}return r}function Cl(e,t){let r=(m)=>{let v=[];for(let g=0;g<m.length;g+=200){let w=Math.min(g+200,m.length);v.push({start:g,end:w,text:m.slice(g,w).join("")})}return v},o=r(e),i=r(t),s=o.map((m)=>m.text),l=i.map((m)=>m.text),a=Bn(s,l),c=[],u=[],d=0,f=0,p=0;while(d<o.length||f<i.length)if(p<a.length&&d<o.length&&f<i.length&&s[d]===a[p]&&l[f]===a[p]){for(let m=o[d].start;m<o[d].end;m++)c.push({type:"same",index:m});for(let m=i[f].start;m<i[f].end;m++)u.push({type:"same",index:m});d++,f++,p++}else if(d<o.length&&(p>=a.length||s[d]!==a[p]))if(f<i.length&&(p>=a.length||l[f]!==a[p])){let m=hs(e.slice(o[d].start,o[d].end),t.slice(i[f].start,i[f].end));for(let v of m.oldOps)c.push({type:v.type,index:v.index+o[d].start});for(let v of m.newOps)u.push({type:v.type,index:v.index+i[f].start});d++,f++}else{for(let m=o[d].start;m<o[d].end;m++)c.push({type:"removed",index:m});d++}else if(f<i.length){for(let m=i[f].start;m<i[f].end;m++)u.push({type:"added",index:m});f++}return{oldOps:c,newOps:u}}function ms(e,t,n){let r=new Map;for(let o of e){if(o.type==="same")continue;let i=t[o.index];if(!i||!i.node.parentNode)continue;let s=r.get(i.node);if(!s)s=[],r.set(i.node,s);s.push({offset:i.offset,length:i.text.length})}for(let[o,i]of r){if(!o.parentNode)continue;let s=o.nodeValue||"";i.sort((d,f)=>d.offset-f.offset);let l=[];for(let d of i){let f=l[l.length-1];if(f&&d.offset<=f.offset+f.length)f.length=Math.max(f.length,d.offset+d.length-f.offset);else l.push({...d})}let a=o.parentNode,c=document.createDocumentFragment(),u=0;for(let d of l){if(d.offset>u)c.appendChild(document.createTextNode(s.slice(u,d.offset)));let f=document.createElement("span");f.className=n,f.textContent=s.slice(d.offset,d.offset+d.length),c.appendChild(f),u=d.offset+d.length}if(u<s.length)c.appendChild(document.createTextNode(s.slice(u)));a.replaceChild(c,o)}}function _n(e,t){let n=Nl(e,t),r=ps(e),o=ps(t),{oldOps:i,newOps:s}=Fo(r.words,o.words),l=i.some((a)=>a.type==="removed")||s.some((a)=>a.type==="added");return ms(i,r.map,"diff-removed"),ms(s,o.map,"diff-added"),l||n}function Nl(e,t){let n=Array.from(e.querySelectorAll('[data-md="mermaid"]')),r=Array.from(t.querySelectorAll('[data-md="mermaid"]')),o=!1,i=Math.max(n.length,r.length);for(let s=0;s<i;s++){let l=n[s],a=r[s];if(!l&&a){a.classList.add("diff-block-added"),a.style.position="relative",o=!0;continue}if(l&&!a){l.classList.add("diff-block-removed"),l.style.position="relative",o=!0;continue}if(!l||!a)continue;let c=(l.getAttribute("data-md-source")||"").trim(),u=(a.getAttribute("data-md-source")||"").trim();if(c===u)continue;o=!0,l.style.borderLeft="3px solid var(--color-accent-red)",l.style.paddingLeft="8px",a.style.borderLeft="3px solid var(--color-accent-green)",a.style.paddingLeft="8px";let d=c.split(`
|
|
84
|
+
`),f=u.split(`
|
|
85
|
+
`),p=tt(d,f),m=(v,g,w)=>{let h=document.createElement("div");h.className="mt-2 bg-bg-code rounded-md overflow-hidden text-tiny font-mono",h.setAttribute("data-no-diff","true");let b=0,k=0;while(k<v.length){let y=document.createElement("div");if(y.className="px-3 py-0.5 whitespace-pre-wrap",b<g.length&&v[k]===g[b])y.textContent=" "+v[k],k++,b++;else y.classList.add(w==="old"?"diff-removed":"diff-added"),y.textContent=(w==="old"?"- ":"+ ")+v[k],k++;h.appendChild(y)}return h};l.appendChild(m(d,p,"old")),a.appendChild(m(f,p,"new"))}return o}function Tt(e){let t=[],n=e.querySelectorAll(":scope > [data-md]");for(let r of n)t.push(on(r));if(t.length===0){let r=e.querySelectorAll("[data-md]"),o=new Set;for(let i of r){let s=i.parentElement?.closest("[data-md]");if(s&&e.contains(s))continue;if(o.has(i))continue;o.add(i),t.push(on(i))}}return t}function on(e){let t=e.getAttribute("data-md")||"unknown",n=Tl(e,t),r=[];if(t==="section"){let o=e.querySelector(":scope > div.mt-6, :scope > div:last-child");if(o)for(let i of o.querySelectorAll(":scope > [data-md]"))r.push(on(i))}else if(t==="table")for(let o of e.querySelectorAll(":scope table > tbody > tr"))r.push({key:"tr:"+(o.textContent||"").slice(0,80),type:"tr",element:o,children:[]});else if(t==="checklist")for(let o of e.querySelectorAll(":scope > [data-md='checklist-item']"))r.push(on(o));else for(let o of e.querySelectorAll("[data-md]"))if(o.parentElement?.closest("[data-md]")===e)r.push(on(o));return{key:n,type:t,element:e,children:r}}function Tl(e,t){switch(t){case"section":return"section:"+(e.getAttribute("data-md-title")||"");case"item":return"item:"+(e.getAttribute("data-task-id")||e.getAttribute("data-md-label")||"");case"codeblock":case"diff":return t+":"+(e.textContent||"").slice(0,80);case"checklist-item":return"checklist-item:"+(e.getAttribute("data-md-label")||e.textContent?.slice(0,60)||"");case"checklist":return"checklist:"+e.querySelectorAll("[data-md='checklist-item']").length;case"markdown":return"markdown:"+(e.getAttribute("data-md-file")||"inline");case"mermaid":return"mermaid:"+(e.getAttribute("data-md-source")||"").slice(0,80);case"callout":return"callout:"+(e.getAttribute("data-md-type")||"")+":"+(e.textContent||"").slice(0,60);default:return t+":"+(e.getAttribute("data-md-label")||e.textContent?.slice(0,60)||"")}}function rn(e,t){let n=e.map((c)=>c.key),r=t.map((c)=>c.key),o=tt(n,r),i=[],s=0,l=0,a=0;while(s<e.length||l<t.length)if(a<o.length&&s<e.length&&l<t.length&&n[s]===o[a]&&r[l]===o[a]){let c=e[s],u=t[l],d=c.children.length>0||u.children.length>0?rn(c.children,u.children):void 0;i.push({kind:"matched",oldBlock:c,newBlock:u,childMatches:d}),s++,l++,a++}else if(s<e.length&&(a>=o.length||n[s]!==o[a]))i.push({kind:"removed",oldBlock:e[s]}),s++;else if(l<t.length)i.push({kind:"added",newBlock:t[l]}),l++;return i}function jn(e){let t=document.createDocumentFragment(),n=!1;for(let r of e)if(r.kind==="removed")n=!0,t.appendChild(xs(r.oldBlock.element));else if(r.kind==="added")n=!0,t.appendChild(Ll(r.newBlock.element));else{let o=r.newBlock.element.cloneNode(!0),i=r.newBlock.type;if(i==="mermaid"){if(ks(r.oldBlock.element,o))n=!0}else if(r.childMatches&&r.childMatches.length>0&&(i==="table"||i==="checklist")){if(vs(o,r.childMatches,i))n=!0}else if(r.childMatches&&r.childMatches.length>0){if(bs(r.oldBlock,o,r.childMatches,i))n=!0}else if(i==="markdown"){if(ys(r.oldBlock.element,o))n=!0}else if(xt(r.oldBlock.element,o,!1))n=!0;t.appendChild(o)}return{fragment:t,hasChanges:n}}function xs(e){let t=e.cloneNode(!0);return t.classList.add("diff-block-removed"),t.style.position="relative",Bo(t,"Removed","var(--color-accent-red)"),t}function Ll(e){let t=e.cloneNode(!0);return t.classList.add("diff-block-added"),t.style.position="relative",Bo(t,"Added","var(--color-accent-green)"),t}function bs(e,t,n,r){let o=!1,i=Ml(e,t),s,l;if(r==="section"){let a=e.element.querySelector(":scope > div:first-child"),c=t.querySelector(":scope > div:first-child");if(a&&c){if(xt(a,c,!1))o=!0}s=e.element.querySelector(":scope > div.mt-6, :scope > div:last-child"),l=t.querySelector(":scope > div.mt-6, :scope > div:last-child")}else s=e.element,l=t;if(!s||!l)return o;for(let a of n)if(a.kind==="matched"){let c=i.newMap.get(a.newBlock.element);if(c){if(a.newBlock.type==="mermaid"){if(ks(a.oldBlock.element,c))o=!0}else if(a.childMatches&&a.childMatches.length>0&&(a.newBlock.type==="table"||a.newBlock.type==="checklist")){if(vs(c,a.childMatches,a.newBlock.type))o=!0}else if(a.childMatches&&a.childMatches.length>0){if(bs(a.oldBlock,c,a.childMatches,a.newBlock.type))o=!0}else if(a.newBlock.type==="markdown"){if(ys(a.oldBlock.element,c))o=!0}else if(xt(a.oldBlock.element,c,!1))o=!0}}else if(a.kind==="removed"){o=!0;let c=xs(a.oldBlock.element),u=Pl(n,a,i.newMap),d=u?$l(l,u):null;l.insertBefore(c,d)}else if(a.kind==="added"){o=!0;let c=i.newMap.get(a.newBlock.element);if(c)c.classList.add("diff-block-added"),c.style.position="relative",Bo(c,"Added","var(--color-accent-green)")}if(xt(s,l,!0))o=!0;return o}function vs(e,t,n){let r=n==="table"?e.querySelector(":scope table > tbody"):e;if(!r)return!1;let o=!1;r.innerHTML="";for(let i of t)if(i.kind==="removed"){o=!0;let s=i.oldBlock.element.cloneNode(!0);s.classList.add(n==="table"?"diff-row-removed":"diff-item-removed"),r.appendChild(s)}else if(i.kind==="added"){o=!0;let s=i.newBlock.element.cloneNode(!0);s.classList.add(n==="table"?"diff-row-added":"diff-item-added"),r.appendChild(s)}else{let s=i.newBlock.element.cloneNode(!0);if(xt(i.oldBlock.element,s,!1))o=!0;r.appendChild(s)}return o}function Ml(e,t){let n=new Map,r=e.element.querySelectorAll("[data-md]"),o=t.querySelectorAll("[data-md]");return{newMap:{get(i){return Il(t,i)}}}}function Il(e,t){let n=t.getAttribute("data-md");if(!n)return null;let r=t.getAttribute("data-md-label"),o=t.getAttribute("data-md-title"),i=`[data-md="${n}"]`;if(o)i+=`[data-md-title="${CSS.escape(o)}"]`;else if(r)i+=`[data-md-label="${CSS.escape(r)}"]`;let s=e.querySelectorAll(i);if(s.length===1)return s[0];let l=(t.textContent||"").slice(0,100),a=null,c=-1;for(let u of s){let d=(u.textContent||"").slice(0,100),f=0;for(let p=0;p<Math.min(l.length,d.length);p++)if(l[p]===d[p])f++;if(f>c)c=f,a=u}return a}function Pl(e,t,n){let r=e.indexOf(t);for(let o=r+1;o<e.length;o++){let i=e[o];if((i.kind==="matched"||i.kind==="added")&&i.newBlock)return n.get(i.newBlock.element)||null}return null}function $l(e,t){let n=t;while(n&&n.parentElement!==e)n=n.parentElement;return n}function ys(e,t){let n=Array.from(e.children),r=Array.from(t.children);if(n.length===0&&r.length===0)return xt(e,t,!1);let o=n.map((f)=>f.tagName.toLowerCase()),i=r.map((f)=>f.tagName.toLowerCase()),s=tt(o,i),l=[],a=0,c=0,u=0;while(a<n.length||c<r.length)if(u<s.length&&a<n.length&&c<r.length&&o[a]===s[u]&&i[c]===s[u])l.push({kind:"matched",oldChild:n[a],newChild:r[c]}),a++,c++,u++;else if(a<n.length&&(u>=s.length||o[a]!==s[u]))l.push({kind:"removed",oldChild:n[a]}),a++;else if(c<r.length)l.push({kind:"added",newChild:r[c]}),c++;let d=!1;while(t.firstChild)t.removeChild(t.firstChild);for(let f of l)if(f.kind==="matched"){let p=(f.oldChild.textContent||"").match(/\S+/g)||[],m=(f.newChild.textContent||"").match(/\S+/g)||[],v=tt(p,m),g=Math.max(p.length,m.length);if((g>0?1-v.length/g:0)>0.5){d=!0;let h=f.oldChild.cloneNode(!0);h.classList.add("diff-block-removed"),t.appendChild(h),f.newChild.classList.add("diff-block-added"),t.appendChild(f.newChild)}else{if(xt(f.oldChild,f.newChild,!1))d=!0;t.appendChild(f.newChild)}}else if(f.kind==="removed"){d=!0;let p=f.oldChild.cloneNode(!0);p.classList.add("diff-block-removed"),t.appendChild(p)}else d=!0,f.newChild.classList.add("diff-block-added"),t.appendChild(f.newChild);return d}function gs(e,t){let n=t?new Set(Array.from(e.querySelectorAll("[data-md]"))):new Set,r=[],o=[],i=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,{acceptNode(l){let a=l.parentElement;if(!a)return NodeFilter.FILTER_REJECT;if(a.closest("svg, .select-none, [data-no-diff]"))return NodeFilter.FILTER_REJECT;if(t){for(let c of n)if(c.contains(l))return NodeFilter.FILTER_REJECT}return NodeFilter.FILTER_ACCEPT}}),s;while(s=i.nextNode()){let a=(s.nodeValue||"").match(/\S+|\s+/g);if(!a)continue;let c=0;for(let u of a)r.push(u),o.push({text:u,node:s,offset:c}),c+=u.length}return{words:r,map:o}}function xt(e,t,n){let r=gs(e,n),o=gs(t,n);if(r.words.length===0&&o.words.length===0)return!1;let{oldOps:i,newOps:s}=Fo(r.words,o.words),l=i.some((g)=>g.type==="removed"),a=s.some((g)=>g.type==="added");if(!l&&!a)return!1;let c=[],u=[];for(let g of i)if(g.type==="same")c.push(g.index);for(let g of s)if(g.type==="same")u.push(g.index);let d=new Map;for(let g=0;g<c.length&&g<u.length;g++)d.set(c[g],u[g]);let f=[];{let g=[],w=-1;for(let h of i)if(h.type==="same"){if(g.length>0)f.push({text:g.join(""),anchorNewIdx:w>=0?d.get(w)??null:null}),g=[];w=h.index}else if(h.type==="removed")g.push(r.words[h.index]);if(g.length>0)f.push({text:g.join(""),anchorNewIdx:w>=0?d.get(w)??null:null})}let p=new Map,m=new Map;for(let g of s){if(g.type!=="added")continue;let w=o.map[g.index];if(!w?.node.parentNode)continue;let h=p.get(w.node);if(!h)h=[],p.set(w.node,h);h.push({start:w.offset,end:w.offset+w.text.length})}for(let g of f)if(g.anchorNewIdx===null){if(o.map.length>0){let w=o.map[0].node,h=m.get(w);if(!h)h=[],m.set(w,h);h.push({offset:0,text:g.text})}}else{let w=o.map[g.anchorNewIdx];if(!w)continue;let h=m.get(w.node);if(!h)h=[],m.set(w.node,h);h.push({offset:w.offset+w.text.length,text:g.text})}let v=new Set([...p.keys(),...m.keys()]);for(let g of v)Hl(g,p.get(g)||[],m.get(g)||[]);return!0}function Hl(e,t,n){if(!e.parentNode)return;let r=e.nodeValue||"";t.sort((u,d)=>u.start-d.start);let o=[];for(let u of t){let d=o[o.length-1];if(d&&u.start<=d.end)d.end=Math.max(d.end,u.end);else o.push({...u})}n.sort((u,d)=>u.offset-d.offset);let i=e.parentNode,s=document.createDocumentFragment(),l=0,a=0,c=0;while(l<=r.length){let u=a<o.length?o[a].start:1/0,d=c<n.length?n[c].offset:1/0,f=Math.min(u,d);if(f===1/0){if(l<r.length)s.appendChild(document.createTextNode(r.slice(l)));break}let p=Math.max(f,l);if(p>l)s.appendChild(document.createTextNode(r.slice(l,p))),l=p;while(c<n.length&&n[c].offset<=l){let m=document.createElement("span");m.className="diff-removed",m.textContent=n[c].text,s.appendChild(m),c++}if(a<o.length&&o[a].start<=l){let m=o[a],v=document.createElement("span");v.className="diff-added",v.textContent=r.slice(l,m.end),s.appendChild(v),l=m.end,a++;while(c<n.length&&n[c].offset<=l){let g=document.createElement("span");g.className="diff-removed",g.textContent=n[c].text,s.appendChild(g),c++}}}while(c<n.length){let u=document.createElement("span");u.className="diff-removed",u.textContent=n[c].text,s.appendChild(u),c++}i.replaceChild(s,e)}function ks(e,t){let n=(e.getAttribute("data-md-source")||"").trim(),r=(t.getAttribute("data-md-source")||"").trim();if(n===r)return!1;let o=n.split(`
|
|
86
|
+
`),i=r.split(`
|
|
87
|
+
`),s=tt(o,i),l=[],a=0,c=0,u=0;while(a<o.length||c<i.length)if(u<s.length&&a<o.length&&c<i.length&&o[a]===s[u]&&i[c]===s[u])l.push({type:"same",line:o[a]}),a++,c++,u++;else if(a<o.length&&(u>=s.length||o[a]!==s[u]))l.push({type:"removed",line:o[a]}),a++;else if(c<i.length)l.push({type:"added",line:i[c]}),c++;let d=document.createElement("div");d.className="mt-2 bg-bg-code rounded-md overflow-hidden text-tiny font-mono",d.setAttribute("data-no-diff","true");for(let f of l){let p=document.createElement("div");if(p.className="px-3 py-0.5 whitespace-pre-wrap",f.type==="removed")p.classList.add("diff-removed"),p.textContent="- "+f.line;else if(f.type==="added")p.classList.add("diff-added"),p.textContent="+ "+f.line;else p.textContent=" "+f.line;d.appendChild(p)}return t.appendChild(d),!0}function Bo(e,t,n){let r=document.createElement("span");r.className="diff-block-label",r.textContent=t,r.style.color=n,r.style.backgroundColor=`color-mix(in srgb, ${n} 12%, transparent)`,e.appendChild(r)}import{jsxDEV as D}from"react/jsx-dev-runtime";function Ol(e,t,n){let r=e.find((s)=>s.revision===t),o=e.find((s)=>s.revision===n),i=new Set;for(let s of r?.canvasFiles||[])i.add(s.filename);for(let s of o?.canvasFiles||[])i.add(s.filename);return[...i].sort()}function As({initialLeft:e,initialRight:t,sessionId:n,onExit:r}){let[o,i]=ge(e),[s,l]=ge(t),[a,c]=ge("unified"),[u,d]=ge(!0),[f,p]=ge(!1),{revisions:m}=Dl(ke),v=qn(()=>Ol(m,o,s),[m,o,s]),[g,w]=ge(()=>v[0]||"plan.jsx");nt(()=>{if(!v.includes(g))w(v[0]||"plan.jsx")},[v,g]);let h=qn(()=>m.find((y)=>y.revision===o)?.canvasFiles.some((y)=>y.filename===g)??!1,[m,o,g]),b=qn(()=>m.find((y)=>y.revision===s)?.canvasFiles.some((y)=>y.filename===g)??!1,[m,s,g]);return D("div",{className:"flex flex-col h-screen",children:[D("div",{className:"flex items-center justify-between px-6 py-3 border-b border-border-subtle bg-bg-surface flex-shrink-0",children:[D("div",{className:"flex items-center gap-3",children:[D("span",{className:"text-[13px] font-body font-medium text-text-primary",children:"Compare"},void 0,!1,void 0,this),D(nn,{value:o,onChange:i,accent:"red"},void 0,!1,void 0,this),D("span",{className:"text-text-tertiary text-[13px]",children:"→"},void 0,!1,void 0,this),D(nn,{value:s,onChange:l,accent:"green"},void 0,!1,void 0,this),f&&!u&&D("span",{className:"text-[11px] font-body text-text-tertiary bg-bg-elevated px-2 py-0.5 rounded",children:"No changes"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),D("div",{className:"flex items-center gap-4",children:[D("div",{className:"flex items-center bg-bg-elevated rounded-md p-0.5",children:[D("button",{onClick:()=>c("unified"),className:`text-[11px] font-body px-2.5 py-1 rounded transition-colors ${a==="unified"?"bg-bg-surface text-text-primary font-medium shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Unified"},void 0,!1,void 0,this),D("button",{onClick:()=>c("side-by-side"),className:`text-[11px] font-body px-2.5 py-1 rounded transition-colors ${a==="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),a==="side-by-side"&&D(Fl,{},void 0,!1,void 0,this),D("button",{onClick:r,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),v.length>1&&D("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:v.map((k)=>{let y=k.replace(/\.jsx$/,""),E=k===g,R=m.find((L)=>L.revision===o)?.canvasFiles.some((L)=>L.filename===k),C=m.find((L)=>L.revision===s)?.canvasFiles.some((L)=>L.filename===k),M=!R?" (added)":!C?" (removed)":"";return D("button",{onClick:()=>w(k),className:`text-[12px] font-body px-3 py-1 rounded-md transition-colors whitespace-nowrap ${E?"bg-bg-elevated text-text-primary font-medium":"text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated"}`,children:[y,M&&D("span",{className:`ml-1 text-[10px] ${!R?"text-accent-green":"text-accent-red"}`,children:M},void 0,!1,void 0,this)]},k,!0,void 0,this)})},void 0,!1,void 0,this),!h||!b?D("div",{className:"flex-1 flex items-center justify-center",children:D("div",{className:"text-center text-text-tertiary font-body",children:[D("div",{className:"text-lg mb-2",children:!h?"New file":"Removed file"},void 0,!1,void 0,this),D("div",{className:"text-[13px]",children:[g.replace(/\.jsx$/,"")," ",!h?"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):a==="unified"?D(Bl,{sessionId:n,leftRev:o,rightRev:s,filename:g,onDiffResult:(k,y)=>{p(k),d(y)}},`unified-${o}-${s}-${g}`,!1,void 0,this):D(_l,{sessionId:n,leftRev:o,rightRev:s,filename:g,onDiffResult:(k,y)=>{p(k),d(y)}},`sbs-${o}-${s}-${g}`,!1,void 0,this)]},void 0,!0,void 0,this)}function Fl(){let[e,t]=ge(!0);return nt(()=>(document.documentElement.dataset.syncScroll=e?"1":"0",()=>{delete document.documentElement.dataset.syncScroll}),[e]),D("label",{className:"flex items-center gap-1.5 cursor-pointer select-none",children:[D("input",{type:"checkbox",checked:e,onChange:(n)=>t(n.target.checked),className:"accent-accent-amber w-3.5 h-3.5"},void 0,!1,void 0,this),D("span",{className:"text-[11px] font-body text-text-secondary",children:"Sync scroll"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Bl({sessionId:e,leftRev:t,rightRev:n,filename:r,onDiffResult:o}){let i=qe(null),s=qe(null),l=qe(null),[a,c]=ge(!1),[u,d]=ge(!1),[f,p]=ge(!1),[m,v]=ge(null),[g,w]=ge(!1),{annotations:h}=De(),b=h.filter((y)=>!y.filePath&&(!y.canvasFile||y.canvasFile===r)),{popovers:k}=Je({containerRef:l,restoreKey:f,restoreAnnotations:b,extractContext:(y)=>Ge(y,l.current)});return nt(()=>{if(f||m)return;let y=setTimeout(()=>{console.warn("[unified-diff] still loading after 10s",{leftReady:a,rightReady:u,oldRef:!!i.current,newRef:!!s.current}),w(!0)},1e4);return()=>clearTimeout(y)},[f,m,a,u]),nt(()=>{if(!a||!u||f)return;if(!i.current||!s.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!i.current||!s.current||!l.current){console.warn("[unified-diff] refs lost between rAF frames",{old:!!i.current,new:!!s.current,unified:!!l.current});return}try{let y=Tt(i.current),E=Tt(s.current),R=rn(y,E),{fragment:C,hasChanges:M}=jn(R);l.current.innerHTML="",l.current.appendChild(C),p(!0),o(!0,M)}catch(y){console.error("[unified-diff] diff computation failed",y),v(y instanceof Error?y.message:String(y))}})})},[a,u,f]),D("div",{className:"flex-1 min-h-0 overflow-y-auto",children:[!f&&!m&&D("div",{style:{position:"absolute",left:-9999,visibility:"hidden",pointerEvents:"none",width:720},children:[D(ze,{ref:i,sessionId:e,revision:t,filename:r,onReady:()=>c(!0),onError:(y)=>v(`Rev ${t}: ${y}`)},void 0,!1,void 0,this),D(ze,{ref:s,sessionId:e,revision:n,filename:r,onReady:()=>d(!0),onError:(y)=>v(`Rev ${n}: ${y}`)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),D("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:[!f&&!m&&D("div",{className:"flex flex-col items-center justify-center h-64 text-text-tertiary font-body text-body gap-2",children:[D("span",{children:"Loading..."},void 0,!1,void 0,this),g&&D("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),m&&D("div",{className:"bg-accent-red-muted rounded-lg p-5 mt-8",children:[D("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Failed to load revision"},void 0,!1,void 0,this),D("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:m},void 0,!1,void 0,this)]},void 0,!0,void 0,this),D("div",{ref:l},void 0,!1,void 0,this)]},void 0,!0,void 0,this),k]},void 0,!0,void 0,this)}function _l({sessionId:e,leftRev:t,rightRev:n,filename:r,onDiffResult:o}){let i=qe(null),s=qe(null),[l,a]=ge(!1),[c,u]=ge(!1),[d,f]=ge(!1),p=qe(null),m=qe(null),v=qe(null),g=qe(!1),w=Es(()=>a(!0),[]),h=Es(()=>u(!0),[]),{annotations:b}=De(),k=b.filter((E)=>!E.filePath&&(!E.canvasFile||E.canvasFile===r)),{popovers:y}=Je({containerRef:p,restoreKey:d,restoreAnnotations:k,extractContext:(E)=>Ge(E,p.current)});return nt(()=>{if(!l||!c||d)return;if(!i.current||!s.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!i.current||!s.current)return;let E=_n(i.current,s.current);f(!0),o(!0,E)})})},[l,c,d]),nt(()=>{let E=m.current,R=v.current;if(!E||!R)return;let C=(B,j)=>{if(document.documentElement.dataset.syncScroll==="0")return;if(g.current)return;g.current=!0;let W=B.scrollHeight-B.clientHeight,de=j.scrollHeight-j.clientHeight;if(W>0&&de>0)j.scrollTop=B.scrollTop/W*de;requestAnimationFrame(()=>{g.current=!1})},M=()=>C(E,R),L=()=>C(R,E);return E.addEventListener("scroll",M),R.addEventListener("scroll",L),()=>{E.removeEventListener("scroll",M),R.removeEventListener("scroll",L)}},[]),D("div",{ref:p,className:"flex flex-1 min-h-0",children:[D("div",{ref:m,className:"w-1/2 overflow-y-auto border-r border-border-subtle",children:D("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:D(ze,{ref:i,sessionId:e,revision:t,filename:r,onReady:w},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),D("div",{ref:v,className:"w-1/2 overflow-y-auto",children:D("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:D(ze,{ref:s,sessionId:e,revision:n,filename:r,onReady:h},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),y]},void 0,!0,void 0,this)}var ze=ws.memo(ws.forwardRef(({sessionId:e,revision:t,filename:n,onReady:r,onError:o},i)=>{let[s,l]=ge(null),[a,c]=ge(null),[u,d]=ge(!0);nt(()=>{d(!0),c(null);let p=n.replace(/\.jsx$/,".js");import(`/api/session/${e}/canvas/${encodeURIComponent(p)}?rev=${t}&t=${Date.now()}`).then((m)=>{if(!m.default){c("Module has no default export"),d(!1),o?.("Module has no default export");return}l(()=>m.default),d(!1)}).catch((m)=>{c(m.message),d(!1),o?.(m.message)})},[e,t,n]),nt(()=>{if(!s)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{r()})})},[s]);let f=qn(()=>s?D(s,{},void 0,!1,void 0,this):null,[s]);if(u)return D("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-body",children:"Loading..."},void 0,!1,void 0,this);if(a)return D("div",{className:"bg-accent-red-muted rounded-lg p-5",children:[D("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Error"},void 0,!1,void 0,this),D("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:a},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(!s)return D("div",{className:"text-text-tertiary text-center py-8 font-body text-body",children:"No canvas loaded"},void 0,!1,void 0,this);return D("div",{ref:i,children:f},void 0,!1,void 0,this)}));import{useState as Ve,useContext as _o,useMemo as jl,useRef as sn,useEffect as Ss,useCallback as Rs}from"react";import{SessionContext as ql}from"#canvas/runtime";import{jsxDEV as q}from"react/jsx-dev-runtime";function jo(e,t){if(!e)return[];return e.canvasFiles.map((n)=>{if(!n.diffStats)return{filename:n.filename,status:"new"};if(n.diffStats.added===0&&n.diffStats.removed===0)return{filename:n.filename,status:"unchanged",diffStats:n.diffStats};return{filename:n.filename,status:"changed",diffStats:n.diffStats}})}function Cs(e){return e.filter((t)=>t.status!=="unchanged").map((t)=>t.filename)}function Ns({revision:e,responseBanner:t}){let{setActiveView:n}=_o($e),{revisions:r}=_o(ke),o=r.find((c)=>c.revision===e),i=r.find((c)=>c.revision===e-1),s=jl(()=>jo(o,i),[o,i]),l=s.filter((c)=>c.status!=="unchanged"),a=s.filter((c)=>c.status==="unchanged");return q("div",{className:"max-w-[720px] mx-auto px-6 pt-12 pb-32",children:[t,l.map((c)=>q(Vl,{change:c,revision:e,previousRevision:i?.revision,onOpenTab:()=>n({type:"canvas",filename:c.filename})},c.filename,!1,void 0,this)),a.length>0&&q("div",{className:"mt-8 border-t border-border-subtle pt-4",children:[q("div",{className:"text-[11px] font-body font-medium uppercase tracking-widest text-text-tertiary mb-3",children:"Unchanged"},void 0,!1,void 0,this),a.map((c)=>q(Kl,{change:c,revision:e,onOpenTab:()=>n({type:"canvas",filename:c.filename})},c.filename,!1,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function zl({mode:e,onChange:t,showDiff:n}){if(!n)return null;return q("div",{className:"flex items-center bg-bg-elevated rounded-md p-0.5",children:["rendered","unified","side-by-side"].map((r)=>q("button",{onClick:()=>t(r),className:`text-[10px] font-body px-2 py-0.5 rounded transition-colors ${e===r?"bg-bg-surface text-text-primary font-medium shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:r==="rendered"?"Full":r==="unified"?"Unified":"Split"},r,!1,void 0,this))},void 0,!1,void 0,this)}function Vl({change:e,revision:t,previousRevision:n,onOpenTab:r}){let o=e.filename.replace(/\.jsx$/,""),i=e.status==="new",s=e.diffStats,l=e.status==="changed"&&n!=null,[a,c]=Ve("rendered");return q("div",{className:"mb-8",children:[q("div",{className:"flex items-center gap-2 mb-3 pb-2 border-b border-border-subtle",children:[q("span",{className:`text-[11px] font-mono px-1.5 py-0.5 rounded ${i?"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:i?"new":"modified"},void 0,!1,void 0,this),q("span",{className:"text-[14px] font-body font-medium text-text-primary",children:o},void 0,!1,void 0,this),s&&(s.added>0||s.removed>0)&&q("span",{className:"text-[11px] font-mono text-text-tertiary",children:[q("span",{className:"text-accent-green",children:["+",s.added]},void 0,!0,void 0,this)," ",q("span",{className:"text-accent-red",children:["-",s.removed]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),q(zl,{mode:a,onChange:c,showDiff:l},void 0,!1,void 0,this),q("button",{onClick:r,className:`${l?"":"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),a==="rendered"?q("div",{"data-canvas-file":e.filename,children:q(Ct,{revision:t,filename:e.filename},void 0,!1,void 0,this)},void 0,!1,void 0,this):l&&n!=null?q(Wl,{filename:e.filename,leftRev:n,rightRev:t,mode:a},`${a}-${t}-${n}`,!1,void 0,this):null]},void 0,!0,void 0,this)}function Wl({filename:e,leftRev:t,rightRev:n,mode:r}){let o=_o(ql);if(r==="unified")return q(Ul,{sessionId:o,filename:e,leftRev:t,rightRev:n},void 0,!1,void 0,this);return q(Gl,{sessionId:o,filename:e,leftRev:t,rightRev:n},void 0,!1,void 0,this)}function Ul({sessionId:e,filename:t,leftRev:n,rightRev:r}){let o=sn(null),i=sn(null),s=sn(null),[l,a]=Ve(!1),[c,u]=Ve(!1),[d,f]=Ve(!1),[p,m]=Ve(null);return Ss(()=>{if(!l||!c||d)return;if(!o.current||!i.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!o.current||!i.current||!s.current)return;try{let v=Tt(o.current),g=Tt(i.current),w=rn(v,g),{fragment:h}=jn(w);s.current.innerHTML="",s.current.appendChild(h),f(!0)}catch(v){m(v instanceof Error?v.message:String(v))}})})},[l,c,d]),q("div",{children:[!d&&!p&&q("div",{style:{position:"absolute",left:-9999,visibility:"hidden",pointerEvents:"none",width:720},children:[q(ze,{ref:o,sessionId:e,revision:n,filename:t,onReady:()=>a(!0),onError:(v)=>m(v)},void 0,!1,void 0,this),q(ze,{ref:i,sessionId:e,revision:r,filename:t,onReady:()=>u(!0),onError:(v)=>m(v)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!d&&!p&&q("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),p&&q("div",{className:"text-accent-red text-[13px] font-body p-3 bg-accent-red-muted rounded-lg",children:p},void 0,!1,void 0,this),q("div",{ref:s},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Gl({sessionId:e,filename:t,leftRev:n,rightRev:r}){let o=sn(null),i=sn(null),[s,l]=Ve(!1),[a,c]=Ve(!1),[u,d]=Ve(!1),f=Rs(()=>l(!0),[]),p=Rs(()=>c(!0),[]);return Ss(()=>{if(!s||!a||u)return;if(!o.current||!i.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!o.current||!i.current)return;_n(o.current,i.current),d(!0)})})},[s,a,u]),q("div",{className:"flex gap-0 border-y border-border-subtle overflow-hidden w-screen relative left-1/2 -translate-x-1/2",children:[q("div",{className:"w-1/2 border-r border-border-subtle",children:[q("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 ",n]},void 0,!0,void 0,this),q("div",{className:"px-6 py-4 max-w-[600px] mx-auto",children:q(ze,{ref:o,sessionId:e,revision:n,filename:t,onReady:f},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),q("div",{className:"w-1/2",children:[q("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 ",r]},void 0,!0,void 0,this),q("div",{className:"px-6 py-4 max-w-[600px] mx-auto",children:q(ze,{ref:i,sessionId:e,revision:r,filename:t,onReady:p},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function Kl({change:e,revision:t,onOpenTab:n}){let[r,o]=Ve(!1),i=e.filename.replace(/\.jsx$/,"");return q("div",{className:"mb-2",children:[q("div",{className:"flex items-center gap-2 py-1.5",children:[q("button",{onClick:()=>o(!r),className:"text-text-tertiary hover:text-text-secondary transition-colors",children:q("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",className:`transition-transform duration-150 ${r?"rotate-90":""}`,children:q("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),q("span",{className:"text-[13px] font-body text-text-secondary",children:i},void 0,!1,void 0,this),q("button",{onClick:n,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),r&&q("div",{className:"ml-5 mt-1 mb-3","data-canvas-file":e.filename,children:q(Ct,{revision:t,filename:e.filename},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{useState as zn,useEffect as Zl,useCallback as qo}from"react";import{jsxDEV as ee}from"react/jsx-dev-runtime";function Ts({sessionId:e,revision:t,open:n,shareEnabled:r,existingShares:o,onClose:i,onShareCreated:s,onShareRevoked:l}){let[a,c]=zn(!1),[u,d]=zn(!1),[f,p]=zn(null),[m,v]=zn(!1),g=o.find((k)=>k.revision===t);Zl(()=>{if(!n)c(!1),d(!1),p(null),v(!1)},[n]);let w=qo(async()=>{c(!0),p(null);try{let k=await fetch(`/api/session/${e}/revision/${t}/share`,{method:"POST"}),y=await k.json();if(!k.ok||!y.ok)throw Error(y.error||`HTTP ${k.status}`);s(y.share)}catch(k){p(k.message||String(k))}finally{c(!1)}},[e,t,s]),h=qo(async(k)=>{if(!window.confirm("Revoke this share link? Reviewers will no longer be able to view or comment."))return;d(!0),p(null);try{let y=await fetch(`/api/session/${e}/shares/${k}/revoke`,{method:"POST"}),E=await y.json();if(!y.ok||!E.ok)throw Error(E.error||`HTTP ${y.status}`);l(k)}catch(y){p(y.message||String(y))}finally{d(!1)}},[e,l]),b=qo((k)=>{navigator.clipboard.writeText(k).then(()=>{v(!0),setTimeout(()=>v(!1),1500)})},[]);if(!n)return null;return ee("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:i,children:ee("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:[ee("div",{className:"flex items-center justify-between mb-3",children:[ee("h2",{className:"text-sm font-medium text-text-primary font-body",children:"Share this revision"},void 0,!1,void 0,this),ee("button",{onClick:i,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:ee("span",{className:"text-xs",children:"✕"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!r?ee("div",{className:"text-[13px] text-text-secondary font-body space-y-2",children:[ee("p",{children:"Canvas sharing is not configured."},void 0,!1,void 0,this),ee("p",{className:"text-text-tertiary",children:["Set ",ee("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"," ",ee("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):g?ee("div",{className:"space-y-3",children:[ee("p",{className:"text-[13px] text-text-secondary font-body",children:"This revision is shared:"},void 0,!1,void 0,this),ee("div",{className:"flex gap-2",children:[ee("input",{type:"text",readOnly:!0,value:g.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:(k)=>k.currentTarget.select()},void 0,!1,void 0,this),ee("button",{onClick:()=>b(g.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:m?"Copied!":"Copy"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),g.expiresAt&&ee("p",{className:"text-[11px] text-text-tertiary font-body",children:["Expires ",new Date(g.expiresAt).toLocaleDateString(),"."]},void 0,!0,void 0,this),g.encryptionKey&&ee("p",{className:"text-[11px] text-accent-green font-body flex items-center gap-1.5",children:[ee("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[ee("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"},void 0,!1,void 0,this),ee("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),ee("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),ee("div",{className:"flex items-center justify-between pt-1",children:[ee("button",{onClick:w,disabled:a||u,className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body underline disabled:opacity-50",children:a?"Creating...":"Create a new link"},void 0,!1,void 0,this),g.ownerToken&&ee("button",{onClick:()=>h(g.shareId),disabled:a||u,className:"text-[11px] text-accent-red hover:opacity-80 font-body underline disabled:opacity-50",children:u?"Revoking...":"Revoke link"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):ee("div",{className:"space-y-3",children:[ee("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),ee("button",{onClick:w,disabled:a,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:a?"Creating share link...":"Create share link"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),f&&ee("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:f},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function Ls({onClick:e,title:t="Share this revision",hasShare:n}){return ee("button",{onClick:e,className:`group p-1.5 transition-colors ${n?"text-accent-blue hover:opacity-80":"text-text-tertiary hover:text-text-secondary"}`,title:t,children:ee("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[ee("circle",{cx:"18",cy:"5",r:"3"},void 0,!1,void 0,this),ee("circle",{cx:"6",cy:"12",r:"3"},void 0,!1,void 0,this),ee("circle",{cx:"18",cy:"19",r:"3"},void 0,!1,void 0,this),ee("line",{x1:"8.59",y1:"13.51",x2:"15.42",y2:"17.49"},void 0,!1,void 0,this),ee("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 Xl,useEffect as Jl,useRef as Yl}from"react";import{jsxDEV as Ce}from"react/jsx-dev-runtime";function Ms({open:e,onClose:t,onSubmit:n}){let[r,o]=Xl(""),i=Yl(null);if(Jl(()=>{if(e)o(""),setTimeout(()=>i.current?.focus(),50)},[e]),!e)return null;let s=r.trim(),l=s.length>=1&&s.length<=80,a=()=>{if(!l)return;n(s)};return Ce("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:t,children:Ce("div",{className:"bg-bg-surface border border-border-medium rounded-lg shadow-xl w-full max-w-md mx-4 p-5",onClick:(c)=>c.stopPropagation(),children:[Ce("div",{className:"flex items-center justify-between mb-3",children:[Ce("h2",{className:"text-sm font-medium text-text-primary font-body",children:"Your name"},void 0,!1,void 0,this),Ce("button",{onClick:t,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:Ce("span",{className:"text-xs",children:"✕"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Ce("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),Ce("input",{ref:i,type:"text",value:r,onChange:(c)=>o(c.target.value),onKeyDown:(c)=>{if(c.key==="Enter")a()},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),Ce("div",{className:"flex justify-end gap-2 mt-4",children:[Ce("button",{onClick:t,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),Ce("button",{onClick:a,disabled:!l,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 x,Fragment as an}from"react/jsx-dev-runtime";function Ps(e){let t=[];for(let n of e)for(let r of n.annotations)t.push({...r,source:"remote",author:n.author});return t}function nc(e){if(e==="auto")return window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light";return e}function $s(e){document.documentElement.dataset.theme=nc(e)}function Fs(){let[e,t]=ie(()=>{let o=localStorage.getItem("canvas-theme");if(o==="light"||o==="dark"||o==="auto")return o;return"auto"});return Ne(()=>{if($s(e),e!=="auto")return;let o=window.matchMedia("(prefers-color-scheme: dark)"),i=()=>$s("auto");return o.addEventListener("change",i),()=>o.removeEventListener("change",i)},[e]),x("button",{onClick:()=>{let o=e==="auto"?"light":e==="light"?"dark":"auto";localStorage.setItem("canvas-theme",o),t(o)},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)"}[e],children:e==="auto"?x("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[x("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2",ry:"2"},void 0,!1,void 0,this),x("line",{x1:"8",y1:"21",x2:"16",y2:"21"},void 0,!1,void 0,this),x("line",{x1:"12",y1:"17",x2:"12",y2:"21"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):e==="dark"?x("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:x("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):x("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[x("circle",{cx:"12",cy:"12",r:"5"},void 0,!1,void 0,this),x("line",{x1:"12",y1:"1",x2:"12",y2:"3"},void 0,!1,void 0,this),x("line",{x1:"12",y1:"21",x2:"12",y2:"23"},void 0,!1,void 0,this),x("line",{x1:"4.22",y1:"4.22",x2:"5.64",y2:"5.64"},void 0,!1,void 0,this),x("line",{x1:"18.36",y1:"18.36",x2:"19.78",y2:"19.78"},void 0,!1,void 0,this),x("line",{x1:"1",y1:"12",x2:"3",y2:"12"},void 0,!1,void 0,this),x("line",{x1:"21",y1:"12",x2:"23",y2:"12"},void 0,!1,void 0,this),x("line",{x1:"4.22",y1:"19.78",x2:"5.64",y2:"18.36"},void 0,!1,void 0,this),x("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 Bs(){let{currentRevision:e,selectedRevision:t,revisions:n,setSelectedRevision:r,setCompareRevision:o}=ot.useContext(ke);if(n.length<=1){let l=n[0]?.label||`Round ${e}`;return x("span",{className:"text-[11px] text-text-tertiary font-body",children:l},void 0,!1,void 0,this)}return x("div",{className:"flex flex-col gap-1",children:[x(nn,{value:t,onChange:r,accent:t===e?"default":"amber"},void 0,!1,void 0,this),x("button",{onClick:()=>{let s;if(t===e)s=[...n].reverse().find((a)=>a.revision<e)?.revision??Math.max(1,e-1);else s=t;o({left:s,right:e})},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 oc(){let e=re.isShared?re.shareId:re.sessionId,t=re.isShared,[n,r]=ie(1),[o,i]=ie(1),[s,l]=ie([]),[a,c]=ie(null),[u,d]=ie(!1),[f,p]=ie(!1),[m,v]=ie(!1),[g,w]=ie([]),[h,b]=ie({type:"overview"}),[k,y]=ie([]),E=Fe(null),R=Fe([]),C=Fe(new Set),[M,L]=ie(),[B,j]=ie(!1),[W,de]=ie(!1),[N,_]=ie(!1),[z,X]=ie(!1),[G,J]=ie([]),[V,O]=ie(!1),[Z,ue]=ie(new Map),[A,P]=ie(!1),[Y,T]=ie(null),[H,F]=ie(null),oe=Lt((S)=>{if(t)return;let K=`${S.revision}\x00${S.filename}\x00${S.message}`;if(C.current.has(K))return;C.current.add(K);let te=JSON.stringify({type:"render-error",error:S});if(E.current?.readyState===WebSocket.OPEN)E.current.send(te);else R.current.push(S)},[t]);Ne(()=>{if(!H)return;let S=setTimeout(()=>F(null),4000);return()=>clearTimeout(S)},[H]),Ne(()=>{let S=["Agent Canvas"];if(M){let K=M.replace(/\/+$/,"").split("/");S.push(K[K.length-1]||e)}else if(e)S.push(e);if(h.type==="file")S.push(h.path.split("/").pop()||h.path);else if(h.type==="overview")S.push("Overview");else if(h.type==="canvas"&&g.length>1&&h.filename)S.push(h.filename.replace(/\.jsx$/,""));else if(a)S.push("Compare");document.title=S.join(" — ")},[e,M,h,a]);let ae=Fe(new Map),pe=s.find((S)=>S.revision===o),Te=o!==n||!!pe?.hasFeedback||f,zo=o===n&&(!!pe?.hasFeedback||f)?"next":"current",Vo=Lt((S)=>{let K=h.type==="overview"?"overview":h.type==="canvas"?`canvas:${h.filename}`:`file:${h.path}`;if(ae.current.set(K,window.scrollY),b(S),S.type==="file")y((te)=>te.includes(S.path)?te:[...te,S.path])},[h]),_s=Lt((S)=>{ae.current.delete(`file:${S}`),y((K)=>K.filter((te)=>te!==S)),b((K)=>{if(K.type==="file"&&K.path===S)return g.length>1?{type:"overview"}:{type:"canvas",filename:g[0]||""};return K})},[g]);Ql(()=>{let S=h.type==="overview"?"overview":h.type==="canvas"?`canvas:${h.filename}`:`file:${h.path}`;window.scrollTo(0,ae.current.get(S)||0)},[h]),Ne(()=>{if(!e)return;Kr().then((S)=>{if(S.currentRevision){let K=S.revisions||[];for(let te of K)if(te.hasFeedback)ft(localStorage,e,te.revision);Tn(localStorage,e,S.currentRevision,K),r(S.currentRevision),i(S.currentRevision),l(K)}if(S.canvasFiles){let K=S.canvasFiles.sort();w(K),b((te)=>{if(te.type==="overview")return K.length>1?te:{type:"canvas",filename:K[0]||""};if(te.type==="canvas"&&(!te.filename||!K.includes(te.filename)))return{type:"canvas",filename:K[0]||""};return te})}if(S.projectRoot)L(S.projectRoot);if(Array.isArray(S.shares))J(S.shares);O(!!S.shareEnabled)}).catch(()=>{})},[e]),Ne(()=>{if(!e||!o||t)return;fetch(`/api/session/${e}/revision/${o}/remote-feedback`).then((S)=>S.json()).then((S)=>{if(!Array.isArray(S.entries))return;let K=Ps(S.entries);ue((te)=>{let we=new Map(te);return we.set(o,K),we})}).catch(()=>{})},[e,o,t]),Ne(()=>{if(!e)return;if(!Yr){d(!0);return}let S=null,K=()=>{let te=window.location.protocol==="https:"?"wss:":"ws:",we=new WebSocket(`${te}//${window.location.host}/ws/session/${e}`);E.current=we,we.onopen=()=>{d(!0);for(let ln of R.current)we.send(JSON.stringify({type:"render-error",error:ln}));R.current=[]},we.onclose=()=>{d(!1),S=setTimeout(K,2000)},we.onmessage=(ln)=>{try{let fe=JSON.parse(ln.data);if(fe.type==="plan-updated"){let Ee=Array.isArray(fe.revisions)?fe.revisions:[];if(Tn(localStorage,e,fe.currentRevision,Ee),r(fe.currentRevision),i(fe.currentRevision),c(null),Ee.length>0){l(Ee);let We=Ee.find((rt)=>rt.revision===fe.currentRevision);if(We?.canvasFiles){let rt=We.canvasFiles.map((It)=>It.filename).sort();w(rt);let Wn=Ee.find((It)=>It.revision===fe.currentRevision-1),Mt=jo(We,Wn),bt=Cs(Mt);if(bt.length===1)b({type:"canvas",filename:bt[0]});else if(bt.length>1||rt.length>1)b({type:"overview"});else b({type:"canvas",filename:rt[0]||""})}}}if(fe.type==="revision-updated"){if(Array.isArray(fe.revisions)){let Ee=fe.revisions;for(let We of Ee)if(We.hasFeedback)ft(localStorage,e,We.revision);l(Ee)}}if(fe.type==="watcher-status")v(!!fe.watching);if(fe.type==="remote-feedback"){let Ee=fe.revision,We=fe.entries||[],rt=Ps(We);ue((Wn)=>{let Mt=new Map(Wn),bt=Mt.get(Ee)||[],It=new Set(bt.map((Un)=>Un.id)),js=[...bt,...rt.filter((Un)=>!It.has(Un.id))];return Mt.set(Ee,js),Mt})}}catch{}}};return K(),()=>{if(S)clearTimeout(S);E.current?.close()}},[e]);let Vn=Lt(async(S,K)=>{try{let te=localStorage.getItem(`canvas:${e}:rev:${o}`),we=[];if(te)try{we=(JSON.parse(te).annotations||[]).filter((fe)=>fe.source!=="remote")}catch{}await Jr({author:K,revision:o,annotations:we,generalNote:S}),ft(localStorage,e,o),p(!0),F({kind:"success",message:"Feedback submitted. The canvas author will see it shortly."})}catch(te){F({kind:"error",message:`Failed to submit feedback: ${te.message||te}`})}},[e,o]),Wo=Lt(async(S)=>{if(t){let K=Ho();if(!K){T(S),P(!0);return}await Vn(S,K);return}if(E.current?.readyState===WebSocket.OPEN)E.current.send(JSON.stringify({type:"submit",feedback:S}))},[t,Vn]);if(!e)return x("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 x(Mn.Provider,{value:Qr,children:x(Os.Provider,{value:e,children:x(Qt.Provider,{value:oe,children:x(ke.Provider,{value:{currentRevision:n,selectedRevision:o,revisions:s,setSelectedRevision:i,isReadOnly:Te,compareRevision:a,setCompareRevision:c,agentWatching:m},children:x(No,{sessionId:e,revision:o,isReadOnly:Te,draftPhase:zo,remoteAnnotations:Z.get(o),canvasFiles:g,children:x($e.Provider,{value:{activeView:h,setActiveView:Vo,openFiles:k,closeFile:_s,canvasFiles:g},children:x(tc.Provider,{value:{setActiveView:Vo},children:x("div",{className:"min-h-screen bg-bg-base",children:[x(rc,{sessionId:e,projectRoot:M,connected:u,onMobileSidebar:()=>j(!B),collapsed:W,onToggle:()=>de((S)=>!S)},void 0,!1,void 0,this),x(sc,{collapsed:N,onToggle:()=>_((S)=>!S),children:x($n,{onSubmit:Wo},void 0,!1,void 0,this)},void 0,!1,void 0,this),a!==null?x("div",{className:`${W?"lg:ml-0":"lg:ml-60"} ${N?"lg:mr-0":"lg:mr-[var(--sidebar-width,320px)]"} transition-[margin] duration-200`,children:x(As,{initialLeft:a.left,initialRight:a.right,sessionId:e,onExit:()=>c(null)},void 0,!1,void 0,this)},void 0,!1,void 0,this):x("div",{className:`relative ${W?"lg:ml-0":"lg:ml-60"} ${N?"lg:mr-0":"lg:mr-[var(--sidebar-width,320px)]"} transition-[margin] duration-200`,id:"plan-scroll-container",children:[x("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:[x("div",{className:"flex items-center gap-2",children:[!t&&x(Oo,{currentSessionId:e,projectRoot:M},void 0,!1,void 0,this),t&&x("span",{className:"text-[11px] text-text-tertiary font-body",children:"Shared canvas"},void 0,!1,void 0,this),!t&&x("span",{className:`w-1.5 h-1.5 rounded-full ${u?"bg-accent-green":"bg-accent-red"}`},void 0,!1,void 0,this)]},void 0,!0,void 0,this),x("div",{className:"flex items-center gap-1",children:[x(Bs,{},void 0,!1,void 0,this),x("button",{onClick:()=>j(!B),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:x("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:x("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),x(Fs,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),x(ic,{},void 0,!1,void 0,this),h.type==="overview"&&x(Ns,{revision:o,responseBanner:pe?.response?x(Hs,{markdown:pe.response},void 0,!1,void 0,this):void 0},void 0,!1,void 0,this),h.type==="canvas"&&g.includes(h.filename)&&x("div",{className:"relative max-w-[720px] mx-auto px-6 pt-12 pb-32",children:[V&&x("div",{className:"absolute top-3 right-12 z-10",children:x(Ls,{onClick:()=>X(!0),hasShare:G.some((S)=>S.revision===o),title:G.some((S)=>S.revision===o)?"Manage share link":"Share this revision"},void 0,!1,void 0,this)},void 0,!1,void 0,this),x("button",{onClick:()=>{let S=document.querySelector(`[data-canvas-file="${h.filename}"] .plan-content`);if(!S)return;let K=ds(S);navigator.clipboard.writeText(K).then(()=>{let te=document.getElementById("export-md-btn");if(te)te.setAttribute("data-copied","true"),setTimeout(()=>{te.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:[x("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:[x("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"},void 0,!1,void 0,this),x("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),x("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:x("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),g.length<=1&&pe?.response&&x(Hs,{markdown:pe.response},void 0,!1,void 0,this),x("div",{"data-canvas-file":h.filename,children:x(Ct,{revision:o,filename:h.filename},h.filename,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),k.map((S)=>x("div",{style:{display:h.type==="file"&&h.path===S?void 0:"none"},children:x(is,{path:S},void 0,!1,void 0,this)},S,!1,void 0,this))]},void 0,!0,void 0,this),B&&x("div",{className:"lg:hidden fixed inset-0 z-40 flex",children:[x("div",{className:"flex-1",onClick:()=>j(!1)},void 0,!1,void 0,this),x("div",{className:"w-80 max-w-[85vw] bg-bg-surface border-l border-border-subtle flex flex-col shadow-lg",children:[x("div",{className:"flex items-center justify-between px-4 py-2 border-b border-border-subtle flex-shrink-0",children:[x("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:"Sidebar"},void 0,!1,void 0,this),x("button",{onClick:()=>j(!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),x("div",{className:"flex-1 overflow-hidden",children:x($n,{onSubmit:Wo},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),x(Ts,{sessionId:e,revision:o,open:z,shareEnabled:V,existingShares:G,onClose:()=>X(!1),onShareCreated:(S)=>{J((K)=>[...K.filter((te)=>te.shareId!==S.shareId),S]),F({kind:"success",message:"Share link created. Copy and send it to reviewers."})},onShareRevoked:(S)=>{J((K)=>K.filter((te)=>te.shareId!==S)),F({kind:"success",message:"Share link revoked."})}},void 0,!1,void 0,this),x(Ms,{open:A,onClose:()=>{P(!1),T(null)},onSubmit:async(S)=>{let K=Xr(S);if(P(!1),Y!==null)await Vn(Y,K),T(null)}},void 0,!1,void 0,this),H&&x("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 ${H.kind==="error"?"bg-accent-red text-white":"bg-accent-green text-white"}`,children:[H.message,x("button",{onClick:()=>F(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)},`${e}:${o}:${zo}`,!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 rc({sessionId:e,projectRoot:t,connected:n,onMobileSidebar:r,collapsed:o,onToggle:i}){let s=re.isShared;return x(an,{children:[o&&x("button",{onClick:i,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:x("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[x("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"},void 0,!1,void 0,this),x("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),x("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 ${o?"-translate-x-full":""}`,children:[x("div",{className:"px-4 pt-4 pb-3 flex-shrink-0 border-b border-border-subtle",children:[x("div",{className:"flex items-center gap-2 mb-2",children:[x("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",className:"text-text-tertiary flex-shrink-0",children:x("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),s?x("span",{className:"text-[12px] font-body text-text-secondary truncate flex-1",children:"Shared canvas"},void 0,!1,void 0,this):x(an,{children:[x(Oo,{currentSessionId:e,projectRoot:t},void 0,!1,void 0,this),x("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${n?"bg-accent-green":"bg-accent-red"}`},void 0,!1,void 0,this)]},void 0,!0,void 0,this),x("button",{onClick:i,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:x("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[x("polyline",{points:"11 17 6 12 11 7"},void 0,!1,void 0,this),x("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),x(Bs,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this),x("div",{className:"flex-1 flex flex-col overflow-hidden",children:x(ns,{embedded:!0},void 0,!1,void 0,this)},void 0,!1,void 0,this),x("div",{className:"px-4 py-3 border-t border-border-subtle flex items-center justify-between flex-shrink-0",children:[x("span",{className:"text-[10px] text-text-tertiary font-body uppercase tracking-widest",children:"Theme"},void 0,!1,void 0,this),x(Fs,{},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 sc({children:e,collapsed:t,onToggle:n}){let[r,o]=ie(()=>{let u=localStorage.getItem("canvas-sidebar-width");return u?parseInt(u,10):320}),i=Fe(!1),s=Fe(0),l=Fe(0),a=Fe(r);a.current=r;let c=Lt((u)=>{u.preventDefault(),i.current=!0,s.current=u.clientX,l.current=a.current;let d=(p)=>{if(!i.current)return;let m=s.current-p.clientX,v=Math.max(240,Math.min(600,l.current+m));o(v),a.current=v},f=()=>{i.current=!1,localStorage.setItem("canvas-sidebar-width",String(a.current)),document.removeEventListener("mousemove",d),document.removeEventListener("mouseup",f),document.body.style.cursor="",document.body.style.userSelect=""};document.addEventListener("mousemove",d),document.addEventListener("mouseup",f),document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[]);return Ne(()=>(document.documentElement.style.setProperty("--sidebar-width",`${r}px`),()=>{document.documentElement.style.removeProperty("--sidebar-width")}),[r]),x(an,{children:[t&&x("button",{onClick:n,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:x("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:x("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),x("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 ${t?"translate-x-full":""}`,style:{width:r},children:[x("div",{onMouseDown:c,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),ot.Children.map(e,(u)=>ot.isValidElement(u)?ot.cloneElement(u,{collapseButton:x("button",{onClick:n,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:x("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[x("polyline",{points:"13 17 18 12 13 7"},void 0,!1,void 0,this),x("polyline",{points:"6 17 11 12 6 7"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}):u)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function Hs({markdown:e}){let[t,n]=ie(!1),r=Is(()=>Q.parse(e,{async:!1}),[e]),o=Fe(null),{annotations:i,addAnnotationWithId:s,removeAnnotation:l,updateAnnotation:a,addAnnotationImage:c,removeAnnotationImage:u,activeAnnotationId:d,setActiveAnnotationId:f}=De(),[p,m]=ie(null),[v,g]=ie(null),w=Is(()=>i.filter((E)=>E.filePath===Se),[i]),[h,b]=ie(e);if(e!==h)b(e),n(!1);Ne(()=>{if(!o.current||w.length===0)return;let E=setTimeout(()=>{if(o.current)_t(o.current,w)},50);return()=>clearTimeout(E)},[r,w.length]);let k=Fe(null);if(Ne(()=>{Ft(d,k.current),k.current=d},[d]),Ne(()=>{let E=o.current;if(!E)return;let R=(L)=>{let B=L.target.closest("[data-annotation-id]");if(!B)return;L.stopPropagation();let j=B.getAttribute("data-annotation-id");if(j===d)g({anchorEl:B,annId:j});else f(j)},C=(L)=>{let B=L.target.closest("[data-annotation-id]");if(B)f(B.getAttribute("data-annotation-id"))},M=(L)=>{let B=L.target.closest("[data-annotation-id]"),j=L.relatedTarget?.closest?.("[data-annotation-id]");if(B&&!j)f(null)};return E.addEventListener("click",R),E.addEventListener("mouseover",C),E.addEventListener("mouseout",M),()=>{E.removeEventListener("click",R),E.removeEventListener("mouseover",C),E.removeEventListener("mouseout",M)}},[r,d]),Ne(()=>{let E=()=>{let R=window.getSelection();if(!R||R.isCollapsed||!R.toString().trim())return;if(!o.current)return;let C=R.getRangeAt(0);if(!o.current.contains(C.startContainer))return;if(C.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let M=R.toString().trim();if(M.length<2)return;let L=C.cloneRange(),B=Ge(C,o.current),j=`__pending_${Date.now()}`;try{Ue(L,j)}catch{}window.getSelection()?.removeAllRanges();let W=document.querySelectorAll(`[data-annotation-id="${j}"]`),de=W[W.length-1];if(!de)return;m({anchorEl:de,tempId:j,snippet:M,ctx:B})};return document.addEventListener("mouseup",E),()=>document.removeEventListener("mouseup",E)},[]),t)return null;let y=document.getElementById("plan-scroll-container");return x("div",{className:"mb-6 rounded-lg border border-accent-blue/20 bg-accent-blue/5 relative",children:[x("button",{onClick:()=>n(!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:x("span",{className:"text-xs",children:"✕"},void 0,!1,void 0,this)},void 0,!1,void 0,this),x("div",{className:"px-4 py-3 pr-10",children:[x("div",{className:"flex items-center gap-2 mb-1.5",children:[x("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:x("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),x("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),x("div",{ref:o,className:"prose-canvas text-sm",dangerouslySetInnerHTML:{__html:r}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),p&&x(Ie,{anchorEl:p.anchorEl,scrollContainer:y,snippet:p.snippet,truncateAt:80,onAdd:(E,R)=>{let C=ve();Bt(p.tempId,C),s(C,p.snippet,E,Se,p.ctx,R),m(null)},onCancel:()=>{jt(p.tempId),m(null)}},void 0,!1,void 0,this),v&&(()=>{let E=i.find((R)=>R.id===v.annId);if(!E)return null;return x(ut,{anchorEl:v.anchorEl,scrollContainer:y,initialNote:E.note,initialImages:E.images,onUpdate:(R,C)=>{a(v.annId,R);let M=E.images||[];for(let L of C)if(!M.includes(L))c(v.annId,L);for(let L of M)if(!C.includes(L))u(v.annId,L)},onDelete:()=>{l(v.annId),f(null)},onClose:()=>g(null)},void 0,!1,void 0,this)})()]},void 0,!0,void 0,this)}function ic(){let{activeView:e,setActiveView:t,openFiles:n,closeFile:r,canvasFiles:o}=ot.useContext($e),i=ot.useContext(Os),{addAnnotationWithId:s,setActiveAnnotationId:l}=De();if(!(o.length>1||n.length>0))return null;return x("div",{className:"flex items-center border-b border-border-medium bg-bg-surface overflow-x-auto sticky top-0 z-10",children:[o.length>1&&x(an,{children:[x("button",{onClick:()=>t({type:"overview"}),className:`flex items-center gap-1.5 px-4 py-2.5 text-[13px] font-body whitespace-nowrap transition-colors relative ${e.type==="overview"?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[x("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",className:"opacity-60",children:x("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",e.type==="overview"&&x("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),x("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),o.map((c,u)=>{let d=c.replace(/\.jsx$/,""),f=e.type==="canvas"&&e.filename===c;return x(ot.Fragment,{children:[x("button",{onClick:()=>t({type:"canvas",filename:c}),className:`flex items-center gap-1.5 px-4 py-2.5 text-[13px] font-body whitespace-nowrap transition-colors relative ${f?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[d,f&&x("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),u<o.length-1&&x("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this)]},c,!0,void 0,this)}),n.length>0&&x(an,{children:[x("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this),n.map((c,u)=>{let d=c.split("/").pop()||c,f=e.type==="file"&&e.path===c;return x(ot.Fragment,{children:[x("div",{className:"flex items-center",children:[x("button",{onClick:()=>t({type:"file",path:c}),className:`flex items-center gap-1.5 pl-3 pr-1 py-2.5 text-[13px] font-body whitespace-nowrap transition-colors relative ${f?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[x(Ye,{name:d,type:"file"},void 0,!1,void 0,this),d,f&&x("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),x("button",{onClick:(p)=>{p.stopPropagation(),r(c)},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),u<n.length-1&&x("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this)]},c,!0,void 0,this)})]},void 0,!0,void 0,this),x("div",{className:"ml-auto flex items-center gap-1 flex-shrink-0",children:e.type==="file"&&je&&x("button",{onClick:async()=>{let c=e.path;try{let d=await(await fetch(`/api/file?session=${i}&path=${encodeURIComponent(c)}`)).json();if(!d.error){let f=d.content.split(`
|
|
88
88
|
`).slice(0,3).join(`
|
|
89
|
-
`)+(
|
|
89
|
+
`)+(d.content.split(`
|
|
90
90
|
`).length>3?`
|
|
91
|
-
...`:""),
|
|
91
|
+
...`:""),p=ve();s(p,f,"",c),l(p)}}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:[x("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 Ds=document.getElementById("root");if(Ds)ec(Ds).render(x(oc,{},void 0,!1,void 0,this));
|