agent-canvas 0.2.1 → 0.7.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.
Files changed (99) hide show
  1. package/README.md +42 -17
  2. package/bin/agent-canvas.js +7 -7
  3. package/bin/agent-canvas.ts +48 -37
  4. package/bin/lib/commands/daemon.ts +46 -43
  5. package/bin/lib/commands/exec.ts +100 -100
  6. package/bin/lib/commands/fetch.ts +15 -15
  7. package/bin/lib/commands/install.ts +36 -36
  8. package/bin/lib/commands/instructions.ts +51 -51
  9. package/bin/lib/commands/push.ts +115 -97
  10. package/bin/lib/commands/review.ts +190 -0
  11. package/bin/lib/commands/watch.ts +24 -24
  12. package/bin/lib/config.ts +12 -12
  13. package/bin/lib/daemon-lifecycle.ts +47 -51
  14. package/bin/lib/helpers.ts +82 -76
  15. package/bin/lib/instructions/app-review.md +88 -0
  16. package/bin/lib/instructions/component-checklist.md +7 -5
  17. package/bin/lib/instructions/component-custom.md +20 -14
  18. package/bin/lib/instructions/component-diff.md +4 -3
  19. package/bin/lib/instructions/component-item.md +18 -8
  20. package/bin/lib/instructions/component-markdown.md +4 -2
  21. package/bin/lib/instructions/component-mermaid.md +12 -6
  22. package/bin/lib/instructions/component-multichoice.md +6 -2
  23. package/bin/lib/instructions/component-note.md +1 -1
  24. package/bin/lib/instructions/component-priority.md +1 -1
  25. package/bin/lib/instructions/component-rangeinput.md +9 -2
  26. package/bin/lib/instructions/component-secretinput.md +12 -11
  27. package/bin/lib/instructions/component-svg.md +62 -16
  28. package/bin/lib/instructions/component-table.md +6 -6
  29. package/bin/lib/instructions/component-usefeedback.md +8 -8
  30. package/bin/lib/instructions/component-userinput.md +6 -2
  31. package/bin/lib/instructions/flow-feature.md +22 -5
  32. package/bin/lib/instructions/flow-plan.md +5 -5
  33. package/bin/lib/instructions/flow-runbook.md +28 -25
  34. package/bin/lib/instructions/overview.md +27 -18
  35. package/bin/lib/instructions/theming.md +5 -0
  36. package/daemon/build.ts +171 -152
  37. package/daemon/client/App.tsx +1205 -1077
  38. package/daemon/client/CompareView.tsx +478 -458
  39. package/daemon/client/FileBrowser.tsx +241 -203
  40. package/daemon/client/FileViewer.tsx +220 -211
  41. package/daemon/client/OverviewView.tsx +283 -267
  42. package/daemon/client/ReviewerIdentityDialog.tsx +72 -71
  43. package/daemon/client/RevisionSelect.tsx +111 -95
  44. package/daemon/client/SessionSwitcher.tsx +81 -81
  45. package/daemon/client/ShareDialog.tsx +211 -212
  46. package/daemon/client/apiSchemas.ts +78 -0
  47. package/daemon/client/canvas-runtime.ts +1 -1
  48. package/daemon/client/clientApi.ts +194 -206
  49. package/daemon/client/components/SecretInput.tsx +138 -138
  50. package/daemon/client/components/index.ts +2 -2
  51. package/daemon/client/domDiff.ts +341 -333
  52. package/daemon/client/errorMessage.ts +3 -0
  53. package/daemon/client/exportMarkdown.ts +222 -201
  54. package/daemon/client/lcs.ts +19 -14
  55. package/daemon/client/shareCrypto.ts +57 -57
  56. package/daemon/client/unifiedDiff.ts +660 -649
  57. package/daemon/dist/annotations-runtime.js +1 -1
  58. package/daemon/dist/client.css +2 -2
  59. package/daemon/dist/client.js +77 -80
  60. package/daemon/dist/components.js +59 -59
  61. package/daemon/dist/preact-compat.js +1 -1
  62. package/daemon/dist/review.js +361 -0
  63. package/daemon/dist/runtime.js +1 -1
  64. package/daemon/langMap.ts +24 -6
  65. package/daemon/review-widget/anchor.ts +187 -0
  66. package/daemon/review-widget/client.ts +95 -0
  67. package/daemon/review-widget/index.tsx +36 -0
  68. package/daemon/review-widget/markup.ts +71 -0
  69. package/daemon/review-widget/screenshot.ts +91 -0
  70. package/daemon/review-widget/source.ts +103 -0
  71. package/daemon/review-widget/styles.css +359 -0
  72. package/daemon/review-widget/text-modules.d.ts +4 -0
  73. package/daemon/review-widget/tsconfig.json +16 -0
  74. package/daemon/review-widget/widget.tsx +436 -0
  75. package/daemon/src/components.ts +3 -3
  76. package/daemon/src/handlers/api.ts +330 -328
  77. package/daemon/src/handlers/files.ts +112 -106
  78. package/daemon/src/handlers/static.ts +47 -46
  79. package/daemon/src/handlers/uploads.ts +61 -56
  80. package/daemon/src/paths.ts +13 -10
  81. package/daemon/src/remote-feedback.ts +192 -192
  82. package/daemon/src/review/markdown.ts +52 -0
  83. package/daemon/src/review/model.ts +132 -0
  84. package/daemon/src/review/proxy.ts +177 -0
  85. package/daemon/src/review/server.ts +199 -0
  86. package/daemon/src/review/store.ts +151 -0
  87. package/daemon/src/server.ts +127 -86
  88. package/daemon/src/share.ts +163 -169
  89. package/daemon/src/stubFetch.ts +7 -0
  90. package/daemon/tsconfig.json +19 -19
  91. package/package.json +47 -47
  92. package/skills/canvas/SKILL.md +5 -1
  93. package/bin/lib/commands/exec.test.ts +0 -27
  94. package/bin/lib/helpers.test.ts +0 -79
  95. package/daemon/src/files-api.test.ts +0 -78
  96. package/daemon/src/remote-feedback.test.ts +0 -165
  97. package/daemon/src/secrets-api.test.ts +0 -123
  98. package/daemon/src/share-e2e.test.ts +0 -277
  99. package/daemon/src/share.test.ts +0 -289
@@ -1,91 +1,88 @@
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={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},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],`
1
+ var j6=Object.defineProperty;var b6=($)=>$;function V6($,J){this[$]=b6.bind(null,J)}var Z6=($,J)=>{for(var Q in J)j6($,Q,{get:J[Q],enumerable:!0,configurable:!0,set:V6.bind(J,Q)})};import{ActiveViewCtx as _7,SessionContext as A6}from"#canvas/runtime";import{AnnotationCtx as TY,AnnotationHostContext as jY,SessionContext as bY,useAnnotationHost as VY,useAnnotations as ZY}from"@fabrika/annotations/runtime";function O0($,J){let Q=[],Y=H3($);for(let q of Y){let G=document.createRange();if(G.selectNodeContents(q),q===$.startContainer)G.setStart(q,$.startOffset);if(q===$.endContainer)G.setEnd(q,$.endOffset);let X=G.toString();if(!X||!X.trim())continue;let H=document.createElement("mark");H.setAttribute("data-annotation-id",J);try{G.surroundContents(H)}catch{let _=G.extractContents();H.appendChild(_),G.insertNode(H)}Q.push(H)}return Q}function I1($){let J=$.parentElement;if(J?.classList.contains("select-none"))return!1;if(J?.closest("[data-annotation-id]"))return!1;return!0}function H3($){let J=[],Q=$.commonAncestorContainer;if(Q.nodeType===Node.TEXT_NODE)return J.push(Q),J;let Y=document.createTreeWalker(Q,NodeFilter.SHOW_TEXT),q;while(q=Y.nextNode()){if(!I1(q))continue;if($.intersectsNode(q))J.push(q)}return J}function C6($,J){let Q=document.createRange();if(Q.selectNodeContents($),$===J.startContainer)Q.setStart($,J.startOffset);if($===J.endContainer)Q.setEnd($,J.endOffset);return Q.toString()}function W3($){let J="";for(let Q of H3($))J+=C6(Q,$);return J}function J1($,J){let Q=document.querySelectorAll(`[data-annotation-id="${$}"]`);for(let Y of Q)Y.classList.toggle("mark-active",J)}function D1($,J){if(J!=null&&J!==$)J1(J,!1);if($!=null)J1($,!0)}function k1($,J){let Q=document.querySelectorAll(`[data-annotation-id="${$}"]`);for(let Y of Q)Y.setAttribute("data-annotation-id",J)}function y1($,J){for(let Q of J){if($.querySelector(`[data-annotation-id="${Q.id}"]`))continue;let Y=Q.snippet;if(!Y)continue;let{fullText:q,textNodes:G}=R6($),X=[],H=0;while(!0){let N=q.indexOf(Y,H);if(N===-1)break;X.push(N),H=N+1}let[_]=X;if(_===void 0)continue;let W=_;if(X.length>1&&Q.context){let N=-1;for(let P of X){let M=0;if(Q.context.before){let T=q.slice(Math.max(0,P-80),P);if(T.includes(Q.context.before))M+=2;else if(Q.context.before.length>10&&T.includes(Q.context.before.slice(-10)))M+=1}if(Q.context.after){let T=q.slice(P+Y.length,P+Y.length+80);if(T.includes(Q.context.after))M+=2;else if(Q.context.after.length>10&&T.includes(Q.context.after.slice(0,10)))M+=1}if(M>N)N=M,W=P}}let U=W,B=W+Y.length,z=_3(G,U),K=_3(G,B);if(!z||!K)continue;try{let N=document.createRange();N.setStart(z.node,z.offset),N.setEnd(K.node,K.offset),O0(N,Q.id)}catch{}}}function R6($){let J=[],Q="",Y=document.createTreeWalker($,NodeFilter.SHOW_TEXT),q;while(q=Y.nextNode()){if(!I1(q))continue;J.push({node:q,start:Q.length}),Q+=q.textContent||""}return{fullText:Q,textNodes:J}}function _3($,J){for(let Q=$.length-1;Q>=0;Q--){let Y=$[Q];if(!Y||Y.start>J)continue;let q=J-Y.start,G=Y.node.textContent?.length??0;if(q<=G)return{node:Y.node,offset:q}}return null}function E1($){let J=document.querySelectorAll(`[data-annotation-id="${$}"]`);for(let Q of J){let Y=Q.parentNode;if(!Y)continue;if(Q.tagName!=="MARK"){Y.removeChild(Q);continue}while(Q.firstChild)Y.insertBefore(Q.firstChild,Q);Y.removeChild(Q),Y.normalize()}}function L0($,J){let Q=U3($,"before",60),Y=U3($,"after",60),q=D6($.startContainer,J);return{before:Q,after:Y,hierarchy:q}}function U3($,J,Q){let Y=I6(J==="before"?$.startContainer:$.endContainer);if(!Y)return"";let q="";if(J==="before"){let G=document.createTreeWalker(Y,NodeFilter.SHOW_TEXT),X;while(X=G.nextNode()){if(X===$.startContainer){q+=(X.textContent||"").slice(0,$.startOffset);break}if(!I1(X))continue;q+=X.textContent||""}if(q.length>Q){q=q.slice(-Q);let H=q.indexOf(" ");if(H>0)q=q.slice(H+1)}}else{let G=document.createTreeWalker(Y,NodeFilter.SHOW_TEXT),X=!1,H;while(H=G.nextNode()){if(H===$.endContainer){q+=(H.textContent||"").slice($.endOffset),X=!0;continue}if(X){if(!I1(H))continue;q+=H.textContent||""}}if(q.length>Q){q=q.slice(0,Q);let _=q.lastIndexOf(" ");if(_>0)q=q.slice(0,_)}}return q.trim()}function I6($){let J=new Set(["DIV","P","LI","PRE","BLOCKQUOTE","SECTION","ARTICLE"]),Q=$.parentElement;while(Q){if(J.has(Q.tagName))return Q;Q=Q.parentElement}return null}function D6($,J){let Q=[],Y=$ instanceof Element?$:$.parentElement;while(Y&&Y!==J){let q=Y.getAttribute?.("data-task-id");if(q){let X=Y.querySelector(".font-semibold");if(X)Q.unshift(X.textContent?.trim()||q)}let G=k6(Y);if(G)Q.unshift(G);Y=Y.parentElement}return Q}function k6($){if($.getAttribute("data-md")==="section"){let Q=$.getAttribute("data-md-title");if(Q)return Q}if($.tagName!=="DIV")return null;return $.querySelector(":scope > button > .font-heading, :scope > div > .font-heading")?.textContent?.trim()||null}function z2($){let J=$.snippet.trim(),Q=$.context,Y=J.length<30;if(Q&&Y&&(Q.before||Q.after)){let q=[];if(Q.before)q.push(`...${Q.before} `);if(q.push(`**${J}**`),Q.after)q.push(` ${Q.after}...`);return q.join("")}return J}function f1($){return{kind:$.kind,owns:(J)=>$.parse(J)!==null,find:(J,Q)=>{let Y=$.parse(J);return Y===null?null:$.find(Y,Q)},restore:(J,Q)=>{let Y=$.parse(Q.snippet);if(Y===null)return;$.restore?.(Y,J,Q)},describe:(J)=>{let Q=$.parse(J);if(Q===null||!$.describe)return null;return $.describe(Q)}}}function B3($){let J=document.createTreeWalker($,NodeFilter.SHOW_TEXT),Q="";for(let Y=J.nextNode();Y;Y=J.nextNode()){let q=Y.parentElement?.closest("[aria-hidden='true']");if(q&&$.contains(q))continue;Q+=Y.textContent??""}return Q.trim()}function N2($,J,Q){return{selector:$,snippet:(Y)=>{let q=Y.getAttribute(Q);return q?`${J} ${q}`:null}}}var J4=[N2("[data-md='item']","[Item]","data-md-label"),N2("[data-md='section']","[Section]","data-md-title"),N2("[data-md='checklist-item']","[Checklist]","data-md-label"),N2("[data-md='image']","[Image]","data-md-src"),{selector:"[data-md='callout']",snippet:($)=>{return`[Callout:${$.getAttribute("data-md-type")||"info"}] ${B3($).slice(0,60)||"Callout"}`}},{selector:"[data-md='note']",snippet:($)=>`[Note] ${B3($).slice(0,60)||"Note"}`},{selector:"[data-md='table'] tbody tr",snippet:($)=>{let J=Array.from($.querySelectorAll("td")).map((Q)=>Q.textContent?.trim()).filter(Boolean);return J.length?`[Row] ${J.join(" | ")}`:null}}],y6=["[data-md='choice-option']","[data-md='multichoice-option']","[data-md='userinput']","[data-md='rangeinput']"],F0=J4.map(($)=>$.selector).join(", "),Q1=[...J4.map(($)=>$.selector),...y6].join(", ");function o$($){for(let J of J4)if($.matches(J.selector))return J.snippet($);return null}var Q4={kind:"block",parse:($)=>$.startsWith("[")?{snippet:$}:null,format:($)=>$.snippet,find:($,J)=>{for(let Q of J.querySelectorAll(F0)){if(!(Q instanceof HTMLElement))continue;if(o$(Q)===$.snippet)return Q}return null}};var Y4="data-annotation-image",E6=/^\[Region:(rect|ellipse)\] ([\s\S]+) @(0|[1-9]\d*),(0|[1-9]\d*),(0|[1-9]\d*),(0|[1-9]\d*)$/;function f6($){if($==="rect")return"rect";if($==="ellipse")return"ellipse";return null}function M2($){if($===void 0)return null;let J=Number($);if(!Number.isInteger(J)||J<0||J>1e4)return null;return J}function K3($){return Math.min(1e4,Math.max(0,$))}function X4($,J,Q){if(!($.width>0)||!($.height>0))return null;return{x:K3(Math.round(J/$.width*1e4)),y:K3(Math.round(Q/$.height*1e4))}}function L2($,J){let Q=Math.min($.x,J.x),Y=Math.min($.y,J.y);return{x:Q,y:Y,w:Math.min(1e4-Q,Math.abs($.x-J.x)),h:Math.min(1e4-Y,Math.abs($.y-J.y))}}function G4($){return $.w>=30&&$.h>=30}function z3($){return{left:`${$.x/100}%`,top:`${$.y/100}%`,width:`${$.w/100}%`,height:`${$.h/100}%`}}function O2($){return`${($/100).toFixed(1).replace(/\.0$/,"")}%`}function F2($){let J=`${O2($.x)}-${O2($.x+$.w)}`,Q=`${O2($.y)}-${O2($.y+$.h)}`;return`[Region] ${$.src} — ${$.shape} x ${J}, y ${Q} of the image`}function q4($,J){for(let Q of J.querySelectorAll("[data-md='image']")){if(!(Q instanceof HTMLElement))continue;if(Q.getAttribute("data-md-src")!==$)continue;let Y=Q.querySelector("[data-annotation-image]");if(Y instanceof HTMLElement)return Y}return null}function A2($,J){let Q=z3(J);$.style.left=Q.left,$.style.top=Q.top,$.style.width=Q.width,$.style.height=Q.height}function S2($,J,Q){let Y=document.createElement("div");return Y.className="ann-region",Y.setAttribute("data-annotation-id",Q),Y.setAttribute("data-annotation-region",J),A2(Y,$),Y}var v1={kind:"region",parse:($)=>{let J=E6.exec($);if(!J)return null;let Q=f6(J[1]),Y=J[2],q=M2(J[3]),G=M2(J[4]),X=M2(J[5]),H=M2(J[6]);if(Q===null||Y===void 0)return null;if(q===null||G===null||X===null||H===null)return null;if(X<1||H<1)return null;return{src:Y,shape:Q,x:q,y:G,w:X,h:H}},format:($)=>`[Region:${$.shape}] ${$.src} @${$.x},${$.y},${$.w},${$.h}`,find:($,J)=>q4($.src,J),restore:($,J,Q)=>{if(J.querySelector(`[data-annotation-id="${Q.id}"]`))return;let Y=q4($.src,J);if(!Y)return;Y.appendChild(S2($,$.shape,Q.id))},describe:F2};var _4={kind:"text",parse:($)=>$?{text:$}:null,format:($)=>$.text,find:()=>null,restore:($,J,Q)=>{y1(J,[Q])}};var P2=[f1(v1),f1(Q4),f1(_4)];function H4($,J){for(let Q of P2){let Y=Q.find($,J);if(Y)return Y}return null}function W4($,J){for(let Q of J){if(!Q.snippet)continue;for(let Y of P2)Y.restore($,Q)}}function g1($){for(let J of P2){let Q=J.describe($);if(Q!==null)return Q}return $}import{AnnotationCtx as Wq,SessionContext as Uq,useAnnotationHost as Bq}from"@fabrika/annotations/runtime";import{useEffect as Nq,useRef as Mq,useState as Oq}from"react";var A={};Z6(A,{void:()=>A8,util:()=>Q$,unknown:()=>L8,union:()=>T8,undefined:()=>N8,tuple:()=>V8,transformer:()=>v8,symbol:()=>z8,string:()=>w3,strictObject:()=>w8,setErrorMap:()=>m6,set:()=>R8,record:()=>Z8,quotelessJson:()=>v6,promise:()=>f8,preprocess:()=>x8,pipeline:()=>h8,ostring:()=>u8,optional:()=>g8,onumber:()=>p8,oboolean:()=>c8,objectUtil:()=>U4,object:()=>P8,number:()=>T3,nullable:()=>m8,null:()=>M8,never:()=>F8,nativeEnum:()=>E8,nan:()=>U8,map:()=>C8,makeIssue:()=>m1,literal:()=>k8,lazy:()=>D8,late:()=>H8,isValid:()=>A0,isDirty:()=>T2,isAsync:()=>Y1,isAborted:()=>w2,intersection:()=>b8,instanceof:()=>W8,getParsedType:()=>a$,getErrorMap:()=>q1,function:()=>I8,enum:()=>y8,effect:()=>v8,discriminatedUnion:()=>j8,defaultErrorMap:()=>G0,datetimeRegex:()=>A3,date:()=>K8,custom:()=>P3,coerce:()=>l8,boolean:()=>j3,bigint:()=>B8,array:()=>S8,any:()=>O8,addIssueToContext:()=>k,ZodVoid:()=>h1,ZodUnknown:()=>S0,ZodUnion:()=>U1,ZodUndefined:()=>H1,ZodType:()=>e,ZodTuple:()=>s$,ZodTransformer:()=>h$,ZodSymbol:()=>x1,ZodString:()=>v$,ZodSet:()=>x0,ZodSchema:()=>e,ZodRecord:()=>u1,ZodReadonly:()=>L1,ZodPromise:()=>h0,ZodPipeline:()=>l1,ZodParsedType:()=>C,ZodOptional:()=>m$,ZodObject:()=>A$,ZodNumber:()=>P0,ZodNullable:()=>H0,ZodNull:()=>W1,ZodNever:()=>n$,ZodNativeEnum:()=>N1,ZodNaN:()=>c1,ZodMap:()=>p1,ZodLiteral:()=>z1,ZodLazy:()=>K1,ZodIssueCode:()=>V,ZodIntersection:()=>B1,ZodFunction:()=>G1,ZodFirstPartyTypeKind:()=>c,ZodError:()=>k$,ZodEnum:()=>T0,ZodEffects:()=>h$,ZodDiscriminatedUnion:()=>j2,ZodDefault:()=>M1,ZodDate:()=>g0,ZodCatch:()=>O1,ZodBranded:()=>b2,ZodBoolean:()=>_1,ZodBigInt:()=>w0,ZodArray:()=>g$,ZodAny:()=>m0,Schema:()=>e,ParseStatus:()=>Z$,OK:()=>C$,NEVER:()=>d8,INVALID:()=>p,EMPTY_PATH:()=>x6,DIRTY:()=>v0,BRAND:()=>_8});var Q$;(function($){$.assertEqual=(q)=>{};function J(q){}$.assertIs=J;function Q(q){throw Error()}$.assertNever=Q,$.arrayToEnum=(q)=>{let G={};for(let X of q)G[X]=X;return G},$.getValidEnumValues=(q)=>{let G=$.objectKeys(q).filter((H)=>typeof q[q[H]]!=="number"),X={};for(let H of G)X[H]=q[H];return $.objectValues(X)},$.objectValues=(q)=>{return $.objectKeys(q).map(function(G){return q[G]})},$.objectKeys=typeof Object.keys==="function"?(q)=>Object.keys(q):(q)=>{let G=[];for(let X in q)if(Object.prototype.hasOwnProperty.call(q,X))G.push(X);return G},$.find=(q,G)=>{for(let X of q)if(G(X))return X;return},$.isInteger=typeof Number.isInteger==="function"?(q)=>Number.isInteger(q):(q)=>typeof q==="number"&&Number.isFinite(q)&&Math.floor(q)===q;function Y(q,G=" | "){return q.map((X)=>typeof X==="string"?`'${X}'`:X).join(G)}$.joinValues=Y,$.jsonStringifyReplacer=(q,G)=>{if(typeof G==="bigint")return G.toString();return G}})(Q$||(Q$={}));var U4;(function($){$.mergeShapes=(J,Q)=>{return{...J,...Q}}})(U4||(U4={}));var C=Q$.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),a$=($)=>{switch(typeof $){case"undefined":return C.undefined;case"string":return C.string;case"number":return Number.isNaN($)?C.nan:C.number;case"boolean":return C.boolean;case"function":return C.function;case"bigint":return C.bigint;case"symbol":return C.symbol;case"object":if(Array.isArray($))return C.array;if($===null)return C.null;if($.then&&typeof $.then==="function"&&$.catch&&typeof $.catch==="function")return C.promise;if(typeof Map<"u"&&$ instanceof Map)return C.map;if(typeof Set<"u"&&$ instanceof Set)return C.set;if(typeof Date<"u"&&$ instanceof Date)return C.date;return C.object;default:return C.unknown}};var V=Q$.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]),v6=($)=>{return JSON.stringify($,null,2).replace(/"([^"]+)":/g,"$1:")};class k$ extends Error{get errors(){return this.issues}constructor($){super();this.issues=[],this.addIssue=(Q)=>{this.issues=[...this.issues,Q]},this.addIssues=(Q=[])=>{this.issues=[...this.issues,...Q]};let J=new.target.prototype;if(Object.setPrototypeOf)Object.setPrototypeOf(this,J);else this.__proto__=J;this.name="ZodError",this.issues=$}format($){let J=$||function(q){return q.message},Q={_errors:[]},Y=(q)=>{for(let G of q.issues)if(G.code==="invalid_union")G.unionErrors.map(Y);else if(G.code==="invalid_return_type")Y(G.returnTypeError);else if(G.code==="invalid_arguments")Y(G.argumentsError);else if(G.path.length===0)Q._errors.push(J(G));else{let X=Q,H=0;while(H<G.path.length){let _=G.path[H];if(H!==G.path.length-1)X[_]=X[_]||{_errors:[]};else X[_]=X[_]||{_errors:[]},X[_]._errors.push(J(G));X=X[_],H++}}};return Y(this),Q}static assert($){if(!($ instanceof k$))throw Error(`Not a ZodError: ${$}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,Q$.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten($=(J)=>J.message){let J={},Q=[];for(let Y of this.issues)if(Y.path.length>0){let q=Y.path[0];J[q]=J[q]||[],J[q].push($(Y))}else Q.push($(Y));return{formErrors:Q,fieldErrors:J}}get formErrors(){return this.flatten()}}k$.create=($)=>{return new k$($)};var g6=($,J)=>{let Q;switch($.code){case V.invalid_type:if($.received===C.undefined)Q="Required";else Q=`Expected ${$.expected}, received ${$.received}`;break;case V.invalid_literal:Q=`Invalid literal value, expected ${JSON.stringify($.expected,Q$.jsonStringifyReplacer)}`;break;case V.unrecognized_keys:Q=`Unrecognized key(s) in object: ${Q$.joinValues($.keys,", ")}`;break;case V.invalid_union:Q="Invalid input";break;case V.invalid_union_discriminator:Q=`Invalid discriminator value. Expected ${Q$.joinValues($.options)}`;break;case V.invalid_enum_value:Q=`Invalid enum value. Expected ${Q$.joinValues($.options)}, received '${$.received}'`;break;case V.invalid_arguments:Q="Invalid function arguments";break;case V.invalid_return_type:Q="Invalid function return type";break;case V.invalid_date:Q="Invalid date";break;case V.invalid_string:if(typeof $.validation==="object")if("includes"in $.validation){if(Q=`Invalid input: must include "${$.validation.includes}"`,typeof $.validation.position==="number")Q=`${Q} at one or more positions greater than or equal to ${$.validation.position}`}else if("startsWith"in $.validation)Q=`Invalid input: must start with "${$.validation.startsWith}"`;else if("endsWith"in $.validation)Q=`Invalid input: must end with "${$.validation.endsWith}"`;else Q$.assertNever($.validation);else if($.validation!=="regex")Q=`Invalid ${$.validation}`;else Q="Invalid";break;case V.too_small:if($.type==="array")Q=`Array must contain ${$.exact?"exactly":$.inclusive?"at least":"more than"} ${$.minimum} element(s)`;else if($.type==="string")Q=`String must contain ${$.exact?"exactly":$.inclusive?"at least":"over"} ${$.minimum} character(s)`;else if($.type==="number")Q=`Number must be ${$.exact?"exactly equal to ":$.inclusive?"greater than or equal to ":"greater than "}${$.minimum}`;else if($.type==="bigint")Q=`Number must be ${$.exact?"exactly equal to ":$.inclusive?"greater than or equal to ":"greater than "}${$.minimum}`;else if($.type==="date")Q=`Date must be ${$.exact?"exactly equal to ":$.inclusive?"greater than or equal to ":"greater than "}${new Date(Number($.minimum))}`;else Q="Invalid input";break;case V.too_big:if($.type==="array")Q=`Array must contain ${$.exact?"exactly":$.inclusive?"at most":"less than"} ${$.maximum} element(s)`;else if($.type==="string")Q=`String must contain ${$.exact?"exactly":$.inclusive?"at most":"under"} ${$.maximum} character(s)`;else if($.type==="number")Q=`Number must be ${$.exact?"exactly":$.inclusive?"less than or equal to":"less than"} ${$.maximum}`;else if($.type==="bigint")Q=`BigInt must be ${$.exact?"exactly":$.inclusive?"less than or equal to":"less than"} ${$.maximum}`;else if($.type==="date")Q=`Date must be ${$.exact?"exactly":$.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number($.maximum))}`;else Q="Invalid input";break;case V.custom:Q="Invalid input";break;case V.invalid_intersection_types:Q="Intersection results could not be merged";break;case V.not_multiple_of:Q=`Number must be a multiple of ${$.multipleOf}`;break;case V.not_finite:Q="Number must be finite";break;default:Q=J.defaultError,Q$.assertNever($)}return{message:Q}},G0=g6;var N3=G0;function m6($){N3=$}function q1(){return N3}var m1=($)=>{let{data:J,path:Q,errorMaps:Y,issueData:q}=$,G=[...Q,...q.path||[]],X={...q,path:G};if(q.message!==void 0)return{...q,path:G,message:q.message};let H="",_=Y.filter((W)=>!!W).slice().reverse();for(let W of _)H=W(X,{data:J,defaultError:H}).message;return{...q,path:G,message:H}},x6=[];function k($,J){let Q=q1(),Y=m1({issueData:J,data:$.data,path:$.path,errorMaps:[$.common.contextualErrorMap,$.schemaErrorMap,Q,Q===G0?void 0:G0].filter((q)=>!!q)});$.common.issues.push(Y)}class Z${constructor(){this.value="valid"}dirty(){if(this.value==="valid")this.value="dirty"}abort(){if(this.value!=="aborted")this.value="aborted"}static mergeArray($,J){let Q=[];for(let Y of J){if(Y.status==="aborted")return p;if(Y.status==="dirty")$.dirty();Q.push(Y.value)}return{status:$.value,value:Q}}static async mergeObjectAsync($,J){let Q=[];for(let Y of J){let q=await Y.key,G=await Y.value;Q.push({key:q,value:G})}return Z$.mergeObjectSync($,Q)}static mergeObjectSync($,J){let Q={};for(let Y of J){let{key:q,value:G}=Y;if(q.status==="aborted")return p;if(G.status==="aborted")return p;if(q.status==="dirty")$.dirty();if(G.status==="dirty")$.dirty();if(q.value!=="__proto__"&&(typeof G.value<"u"||Y.alwaysSet))Q[q.value]=G.value}return{status:$.value,value:Q}}}var p=Object.freeze({status:"aborted"}),v0=($)=>({status:"dirty",value:$}),C$=($)=>({status:"valid",value:$}),w2=($)=>$.status==="aborted",T2=($)=>$.status==="dirty",A0=($)=>$.status==="valid",Y1=($)=>typeof Promise<"u"&&$ instanceof Promise;var v;(function($){$.errToObj=(J)=>typeof J==="string"?{message:J}:J||{},$.toString=(J)=>typeof J==="string"?J:J?.message})(v||(v={}));class x${constructor($,J,Q,Y){this._cachedPath=[],this.parent=$,this.data=J,this._path=Q,this._key=Y}get path(){if(!this._cachedPath.length)if(Array.isArray(this._key))this._cachedPath.push(...this._path,...this._key);else this._cachedPath.push(...this._path,this._key);return this._cachedPath}}var M3=($,J)=>{if(A0(J))return{success:!0,data:J.value};else{if(!$.common.issues.length)throw Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;let Q=new k$($.common.issues);return this._error=Q,this._error}}}};function t($){if(!$)return{};let{errorMap:J,invalid_type_error:Q,required_error:Y,description:q}=$;if(J&&(Q||Y))throw Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);if(J)return{errorMap:J,description:q};return{errorMap:(X,H)=>{let{message:_}=$;if(X.code==="invalid_enum_value")return{message:_??H.defaultError};if(typeof H.data>"u")return{message:_??Y??H.defaultError};if(X.code!=="invalid_type")return{message:H.defaultError};return{message:_??Q??H.defaultError}},description:q}}class e{get description(){return this._def.description}_getType($){return a$($.data)}_getOrReturnCtx($,J){return J||{common:$.parent.common,data:$.data,parsedType:a$($.data),schemaErrorMap:this._def.errorMap,path:$.path,parent:$.parent}}_processInputParams($){return{status:new Z$,ctx:{common:$.parent.common,data:$.data,parsedType:a$($.data),schemaErrorMap:this._def.errorMap,path:$.path,parent:$.parent}}}_parseSync($){let J=this._parse($);if(Y1(J))throw Error("Synchronous parse encountered promise.");return J}_parseAsync($){let J=this._parse($);return Promise.resolve(J)}parse($,J){let Q=this.safeParse($,J);if(Q.success)return Q.data;throw Q.error}safeParse($,J){let Q={common:{issues:[],async:J?.async??!1,contextualErrorMap:J?.errorMap},path:J?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:$,parsedType:a$($)},Y=this._parseSync({data:$,path:Q.path,parent:Q});return M3(Q,Y)}"~validate"($){let J={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:$,parsedType:a$($)};if(!this["~standard"].async)try{let Q=this._parseSync({data:$,path:[],parent:J});return A0(Q)?{value:Q.value}:{issues:J.common.issues}}catch(Q){if(Q?.message?.toLowerCase()?.includes("encountered"))this["~standard"].async=!0;J.common={issues:[],async:!0}}return this._parseAsync({data:$,path:[],parent:J}).then((Q)=>A0(Q)?{value:Q.value}:{issues:J.common.issues})}async parseAsync($,J){let Q=await this.safeParseAsync($,J);if(Q.success)return Q.data;throw Q.error}async safeParseAsync($,J){let Q={common:{issues:[],contextualErrorMap:J?.errorMap,async:!0},path:J?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:$,parsedType:a$($)},Y=this._parse({data:$,path:Q.path,parent:Q}),q=await(Y1(Y)?Y:Promise.resolve(Y));return M3(Q,q)}refine($,J){let Q=(Y)=>{if(typeof J==="string"||typeof J>"u")return{message:J};else if(typeof J==="function")return J(Y);else return J};return this._refinement((Y,q)=>{let G=$(Y),X=()=>q.addIssue({code:V.custom,...Q(Y)});if(typeof Promise<"u"&&G instanceof Promise)return G.then((H)=>{if(!H)return X(),!1;else return!0});if(!G)return X(),!1;else return!0})}refinement($,J){return this._refinement((Q,Y)=>{if(!$(Q))return Y.addIssue(typeof J==="function"?J(Q,Y):J),!1;else return!0})}_refinement($){return new h$({schema:this,typeName:c.ZodEffects,effect:{type:"refinement",refinement:$}})}superRefine($){return this._refinement($)}constructor($){this.spa=this.safeParseAsync,this._def=$,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:(J)=>this["~validate"](J)}}optional(){return m$.create(this,this._def)}nullable(){return H0.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return g$.create(this)}promise(){return h0.create(this,this._def)}or($){return U1.create([this,$],this._def)}and($){return B1.create(this,$,this._def)}transform($){return new h$({...t(this._def),schema:this,typeName:c.ZodEffects,effect:{type:"transform",transform:$}})}default($){let J=typeof $==="function"?$:()=>$;return new M1({...t(this._def),innerType:this,defaultValue:J,typeName:c.ZodDefault})}brand(){return new b2({typeName:c.ZodBranded,type:this,...t(this._def)})}catch($){let J=typeof $==="function"?$:()=>$;return new O1({...t(this._def),innerType:this,catchValue:J,typeName:c.ZodCatch})}describe($){return new this.constructor({...this._def,description:$})}pipe($){return l1.create(this,$)}readonly(){return L1.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}var h6=/^c[^\s-]{8,}$/i,u6=/^[0-9a-z]+$/,p6=/^[0-9A-HJKMNP-TV-Z]{26}$/i,c6=/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i,l6=/^[a-z0-9_-]{21}$/i,d6=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,r6=/^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/,i6=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,o6="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$",B4,a6=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,n6=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,s6=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,t6=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,e6=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,$8=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,L3="((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))",J8=new RegExp(`^${L3}$`);function F3($){let J="[0-5]\\d";if($.precision)J=`${J}\\.\\d{${$.precision}}`;else if($.precision==null)J=`${J}(\\.\\d+)?`;let Q=$.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${J})${Q}`}function Q8($){return new RegExp(`^${F3($)}$`)}function A3($){let J=`${L3}T${F3($)}`,Q=[];if(Q.push($.local?"Z?":"Z"),$.offset)Q.push("([+-]\\d{2}:?\\d{2})");return J=`${J}(${Q.join("|")})`,new RegExp(`^${J}$`)}function q8($,J){if((J==="v4"||!J)&&a6.test($))return!0;if((J==="v6"||!J)&&s6.test($))return!0;return!1}function Y8($,J){if(!d6.test($))return!1;try{let[Q]=$.split(".");if(!Q)return!1;let Y=Q.replace(/-/g,"+").replace(/_/g,"/").padEnd(Q.length+(4-Q.length%4)%4,"="),q=JSON.parse(atob(Y));if(typeof q!=="object"||q===null)return!1;if("typ"in q&&q?.typ!=="JWT")return!1;if(!q.alg)return!1;if(J&&q.alg!==J)return!1;return!0}catch{return!1}}function X8($,J){if((J==="v4"||!J)&&n6.test($))return!0;if((J==="v6"||!J)&&t6.test($))return!0;return!1}class v$ extends e{_parse($){if(this._def.coerce)$.data=String($.data);if(this._getType($)!==C.string){let q=this._getOrReturnCtx($);return k(q,{code:V.invalid_type,expected:C.string,received:q.parsedType}),p}let Q=new Z$,Y=void 0;for(let q of this._def.checks)if(q.kind==="min"){if($.data.length<q.value)Y=this._getOrReturnCtx($,Y),k(Y,{code:V.too_small,minimum:q.value,type:"string",inclusive:!0,exact:!1,message:q.message}),Q.dirty()}else if(q.kind==="max"){if($.data.length>q.value)Y=this._getOrReturnCtx($,Y),k(Y,{code:V.too_big,maximum:q.value,type:"string",inclusive:!0,exact:!1,message:q.message}),Q.dirty()}else if(q.kind==="length"){let G=$.data.length>q.value,X=$.data.length<q.value;if(G||X){if(Y=this._getOrReturnCtx($,Y),G)k(Y,{code:V.too_big,maximum:q.value,type:"string",inclusive:!0,exact:!0,message:q.message});else if(X)k(Y,{code:V.too_small,minimum:q.value,type:"string",inclusive:!0,exact:!0,message:q.message});Q.dirty()}}else if(q.kind==="email"){if(!i6.test($.data))Y=this._getOrReturnCtx($,Y),k(Y,{validation:"email",code:V.invalid_string,message:q.message}),Q.dirty()}else if(q.kind==="emoji"){if(!B4)B4=new RegExp(o6,"u");if(!B4.test($.data))Y=this._getOrReturnCtx($,Y),k(Y,{validation:"emoji",code:V.invalid_string,message:q.message}),Q.dirty()}else if(q.kind==="uuid"){if(!c6.test($.data))Y=this._getOrReturnCtx($,Y),k(Y,{validation:"uuid",code:V.invalid_string,message:q.message}),Q.dirty()}else if(q.kind==="nanoid"){if(!l6.test($.data))Y=this._getOrReturnCtx($,Y),k(Y,{validation:"nanoid",code:V.invalid_string,message:q.message}),Q.dirty()}else if(q.kind==="cuid"){if(!h6.test($.data))Y=this._getOrReturnCtx($,Y),k(Y,{validation:"cuid",code:V.invalid_string,message:q.message}),Q.dirty()}else if(q.kind==="cuid2"){if(!u6.test($.data))Y=this._getOrReturnCtx($,Y),k(Y,{validation:"cuid2",code:V.invalid_string,message:q.message}),Q.dirty()}else if(q.kind==="ulid"){if(!p6.test($.data))Y=this._getOrReturnCtx($,Y),k(Y,{validation:"ulid",code:V.invalid_string,message:q.message}),Q.dirty()}else if(q.kind==="url")try{new URL($.data)}catch{Y=this._getOrReturnCtx($,Y),k(Y,{validation:"url",code:V.invalid_string,message:q.message}),Q.dirty()}else if(q.kind==="regex"){if(q.regex.lastIndex=0,!q.regex.test($.data))Y=this._getOrReturnCtx($,Y),k(Y,{validation:"regex",code:V.invalid_string,message:q.message}),Q.dirty()}else if(q.kind==="trim")$.data=$.data.trim();else if(q.kind==="includes"){if(!$.data.includes(q.value,q.position))Y=this._getOrReturnCtx($,Y),k(Y,{code:V.invalid_string,validation:{includes:q.value,position:q.position},message:q.message}),Q.dirty()}else if(q.kind==="toLowerCase")$.data=$.data.toLowerCase();else if(q.kind==="toUpperCase")$.data=$.data.toUpperCase();else if(q.kind==="startsWith"){if(!$.data.startsWith(q.value))Y=this._getOrReturnCtx($,Y),k(Y,{code:V.invalid_string,validation:{startsWith:q.value},message:q.message}),Q.dirty()}else if(q.kind==="endsWith"){if(!$.data.endsWith(q.value))Y=this._getOrReturnCtx($,Y),k(Y,{code:V.invalid_string,validation:{endsWith:q.value},message:q.message}),Q.dirty()}else if(q.kind==="datetime"){if(!A3(q).test($.data))Y=this._getOrReturnCtx($,Y),k(Y,{code:V.invalid_string,validation:"datetime",message:q.message}),Q.dirty()}else if(q.kind==="date"){if(!J8.test($.data))Y=this._getOrReturnCtx($,Y),k(Y,{code:V.invalid_string,validation:"date",message:q.message}),Q.dirty()}else if(q.kind==="time"){if(!Q8(q).test($.data))Y=this._getOrReturnCtx($,Y),k(Y,{code:V.invalid_string,validation:"time",message:q.message}),Q.dirty()}else if(q.kind==="duration"){if(!r6.test($.data))Y=this._getOrReturnCtx($,Y),k(Y,{validation:"duration",code:V.invalid_string,message:q.message}),Q.dirty()}else if(q.kind==="ip"){if(!q8($.data,q.version))Y=this._getOrReturnCtx($,Y),k(Y,{validation:"ip",code:V.invalid_string,message:q.message}),Q.dirty()}else if(q.kind==="jwt"){if(!Y8($.data,q.alg))Y=this._getOrReturnCtx($,Y),k(Y,{validation:"jwt",code:V.invalid_string,message:q.message}),Q.dirty()}else if(q.kind==="cidr"){if(!X8($.data,q.version))Y=this._getOrReturnCtx($,Y),k(Y,{validation:"cidr",code:V.invalid_string,message:q.message}),Q.dirty()}else if(q.kind==="base64"){if(!e6.test($.data))Y=this._getOrReturnCtx($,Y),k(Y,{validation:"base64",code:V.invalid_string,message:q.message}),Q.dirty()}else if(q.kind==="base64url"){if(!$8.test($.data))Y=this._getOrReturnCtx($,Y),k(Y,{validation:"base64url",code:V.invalid_string,message:q.message}),Q.dirty()}else Q$.assertNever(q);return{status:Q.value,value:$.data}}_regex($,J,Q){return this.refinement((Y)=>$.test(Y),{validation:J,code:V.invalid_string,...v.errToObj(Q)})}_addCheck($){return new v$({...this._def,checks:[...this._def.checks,$]})}email($){return this._addCheck({kind:"email",...v.errToObj($)})}url($){return this._addCheck({kind:"url",...v.errToObj($)})}emoji($){return this._addCheck({kind:"emoji",...v.errToObj($)})}uuid($){return this._addCheck({kind:"uuid",...v.errToObj($)})}nanoid($){return this._addCheck({kind:"nanoid",...v.errToObj($)})}cuid($){return this._addCheck({kind:"cuid",...v.errToObj($)})}cuid2($){return this._addCheck({kind:"cuid2",...v.errToObj($)})}ulid($){return this._addCheck({kind:"ulid",...v.errToObj($)})}base64($){return this._addCheck({kind:"base64",...v.errToObj($)})}base64url($){return this._addCheck({kind:"base64url",...v.errToObj($)})}jwt($){return this._addCheck({kind:"jwt",...v.errToObj($)})}ip($){return this._addCheck({kind:"ip",...v.errToObj($)})}cidr($){return this._addCheck({kind:"cidr",...v.errToObj($)})}datetime($){if(typeof $==="string")return this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:$});return this._addCheck({kind:"datetime",precision:typeof $?.precision>"u"?null:$?.precision,offset:$?.offset??!1,local:$?.local??!1,...v.errToObj($?.message)})}date($){return this._addCheck({kind:"date",message:$})}time($){if(typeof $==="string")return this._addCheck({kind:"time",precision:null,message:$});return this._addCheck({kind:"time",precision:typeof $?.precision>"u"?null:$?.precision,...v.errToObj($?.message)})}duration($){return this._addCheck({kind:"duration",...v.errToObj($)})}regex($,J){return this._addCheck({kind:"regex",regex:$,...v.errToObj(J)})}includes($,J){return this._addCheck({kind:"includes",value:$,position:J?.position,...v.errToObj(J?.message)})}startsWith($,J){return this._addCheck({kind:"startsWith",value:$,...v.errToObj(J)})}endsWith($,J){return this._addCheck({kind:"endsWith",value:$,...v.errToObj(J)})}min($,J){return this._addCheck({kind:"min",value:$,...v.errToObj(J)})}max($,J){return this._addCheck({kind:"max",value:$,...v.errToObj(J)})}length($,J){return this._addCheck({kind:"length",value:$,...v.errToObj(J)})}nonempty($){return this.min(1,v.errToObj($))}trim(){return new v$({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new v$({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new v$({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(($)=>$.kind==="datetime")}get isDate(){return!!this._def.checks.find(($)=>$.kind==="date")}get isTime(){return!!this._def.checks.find(($)=>$.kind==="time")}get isDuration(){return!!this._def.checks.find(($)=>$.kind==="duration")}get isEmail(){return!!this._def.checks.find(($)=>$.kind==="email")}get isURL(){return!!this._def.checks.find(($)=>$.kind==="url")}get isEmoji(){return!!this._def.checks.find(($)=>$.kind==="emoji")}get isUUID(){return!!this._def.checks.find(($)=>$.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(($)=>$.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(($)=>$.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(($)=>$.kind==="cuid2")}get isULID(){return!!this._def.checks.find(($)=>$.kind==="ulid")}get isIP(){return!!this._def.checks.find(($)=>$.kind==="ip")}get isCIDR(){return!!this._def.checks.find(($)=>$.kind==="cidr")}get isBase64(){return!!this._def.checks.find(($)=>$.kind==="base64")}get isBase64url(){return!!this._def.checks.find(($)=>$.kind==="base64url")}get minLength(){let $=null;for(let J of this._def.checks)if(J.kind==="min"){if($===null||J.value>$)$=J.value}return $}get maxLength(){let $=null;for(let J of this._def.checks)if(J.kind==="max"){if($===null||J.value<$)$=J.value}return $}}v$.create=($)=>{return new v$({checks:[],typeName:c.ZodString,coerce:$?.coerce??!1,...t($)})};function G8($,J){let Q=($.toString().split(".")[1]||"").length,Y=(J.toString().split(".")[1]||"").length,q=Q>Y?Q:Y,G=Number.parseInt($.toFixed(q).replace(".","")),X=Number.parseInt(J.toFixed(q).replace(".",""));return G%X/10**q}class P0 extends e{constructor(){super(...arguments);this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse($){if(this._def.coerce)$.data=Number($.data);if(this._getType($)!==C.number){let q=this._getOrReturnCtx($);return k(q,{code:V.invalid_type,expected:C.number,received:q.parsedType}),p}let Q=void 0,Y=new Z$;for(let q of this._def.checks)if(q.kind==="int"){if(!Q$.isInteger($.data))Q=this._getOrReturnCtx($,Q),k(Q,{code:V.invalid_type,expected:"integer",received:"float",message:q.message}),Y.dirty()}else if(q.kind==="min"){if(q.inclusive?$.data<q.value:$.data<=q.value)Q=this._getOrReturnCtx($,Q),k(Q,{code:V.too_small,minimum:q.value,type:"number",inclusive:q.inclusive,exact:!1,message:q.message}),Y.dirty()}else if(q.kind==="max"){if(q.inclusive?$.data>q.value:$.data>=q.value)Q=this._getOrReturnCtx($,Q),k(Q,{code:V.too_big,maximum:q.value,type:"number",inclusive:q.inclusive,exact:!1,message:q.message}),Y.dirty()}else if(q.kind==="multipleOf"){if(G8($.data,q.value)!==0)Q=this._getOrReturnCtx($,Q),k(Q,{code:V.not_multiple_of,multipleOf:q.value,message:q.message}),Y.dirty()}else if(q.kind==="finite"){if(!Number.isFinite($.data))Q=this._getOrReturnCtx($,Q),k(Q,{code:V.not_finite,message:q.message}),Y.dirty()}else Q$.assertNever(q);return{status:Y.value,value:$.data}}gte($,J){return this.setLimit("min",$,!0,v.toString(J))}gt($,J){return this.setLimit("min",$,!1,v.toString(J))}lte($,J){return this.setLimit("max",$,!0,v.toString(J))}lt($,J){return this.setLimit("max",$,!1,v.toString(J))}setLimit($,J,Q,Y){return new P0({...this._def,checks:[...this._def.checks,{kind:$,value:J,inclusive:Q,message:v.toString(Y)}]})}_addCheck($){return new P0({...this._def,checks:[...this._def.checks,$]})}int($){return this._addCheck({kind:"int",message:v.toString($)})}positive($){return this._addCheck({kind:"min",value:0,inclusive:!1,message:v.toString($)})}negative($){return this._addCheck({kind:"max",value:0,inclusive:!1,message:v.toString($)})}nonpositive($){return this._addCheck({kind:"max",value:0,inclusive:!0,message:v.toString($)})}nonnegative($){return this._addCheck({kind:"min",value:0,inclusive:!0,message:v.toString($)})}multipleOf($,J){return this._addCheck({kind:"multipleOf",value:$,message:v.toString(J)})}finite($){return this._addCheck({kind:"finite",message:v.toString($)})}safe($){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:v.toString($)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:v.toString($)})}get minValue(){let $=null;for(let J of this._def.checks)if(J.kind==="min"){if($===null||J.value>$)$=J.value}return $}get maxValue(){let $=null;for(let J of this._def.checks)if(J.kind==="max"){if($===null||J.value<$)$=J.value}return $}get isInt(){return!!this._def.checks.find(($)=>$.kind==="int"||$.kind==="multipleOf"&&Q$.isInteger($.value))}get isFinite(){let $=null,J=null;for(let Q of this._def.checks)if(Q.kind==="finite"||Q.kind==="int"||Q.kind==="multipleOf")return!0;else if(Q.kind==="min"){if(J===null||Q.value>J)J=Q.value}else if(Q.kind==="max"){if($===null||Q.value<$)$=Q.value}return Number.isFinite(J)&&Number.isFinite($)}}P0.create=($)=>{return new P0({checks:[],typeName:c.ZodNumber,coerce:$?.coerce||!1,...t($)})};class w0 extends e{constructor(){super(...arguments);this.min=this.gte,this.max=this.lte}_parse($){if(this._def.coerce)try{$.data=BigInt($.data)}catch{return this._getInvalidInput($)}if(this._getType($)!==C.bigint)return this._getInvalidInput($);let Q=void 0,Y=new Z$;for(let q of this._def.checks)if(q.kind==="min"){if(q.inclusive?$.data<q.value:$.data<=q.value)Q=this._getOrReturnCtx($,Q),k(Q,{code:V.too_small,type:"bigint",minimum:q.value,inclusive:q.inclusive,message:q.message}),Y.dirty()}else if(q.kind==="max"){if(q.inclusive?$.data>q.value:$.data>=q.value)Q=this._getOrReturnCtx($,Q),k(Q,{code:V.too_big,type:"bigint",maximum:q.value,inclusive:q.inclusive,message:q.message}),Y.dirty()}else if(q.kind==="multipleOf"){if($.data%q.value!==BigInt(0))Q=this._getOrReturnCtx($,Q),k(Q,{code:V.not_multiple_of,multipleOf:q.value,message:q.message}),Y.dirty()}else Q$.assertNever(q);return{status:Y.value,value:$.data}}_getInvalidInput($){let J=this._getOrReturnCtx($);return k(J,{code:V.invalid_type,expected:C.bigint,received:J.parsedType}),p}gte($,J){return this.setLimit("min",$,!0,v.toString(J))}gt($,J){return this.setLimit("min",$,!1,v.toString(J))}lte($,J){return this.setLimit("max",$,!0,v.toString(J))}lt($,J){return this.setLimit("max",$,!1,v.toString(J))}setLimit($,J,Q,Y){return new w0({...this._def,checks:[...this._def.checks,{kind:$,value:J,inclusive:Q,message:v.toString(Y)}]})}_addCheck($){return new w0({...this._def,checks:[...this._def.checks,$]})}positive($){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:v.toString($)})}negative($){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:v.toString($)})}nonpositive($){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:v.toString($)})}nonnegative($){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:v.toString($)})}multipleOf($,J){return this._addCheck({kind:"multipleOf",value:$,message:v.toString(J)})}get minValue(){let $=null;for(let J of this._def.checks)if(J.kind==="min"){if($===null||J.value>$)$=J.value}return $}get maxValue(){let $=null;for(let J of this._def.checks)if(J.kind==="max"){if($===null||J.value<$)$=J.value}return $}}w0.create=($)=>{return new w0({checks:[],typeName:c.ZodBigInt,coerce:$?.coerce??!1,...t($)})};class _1 extends e{_parse($){if(this._def.coerce)$.data=Boolean($.data);if(this._getType($)!==C.boolean){let Q=this._getOrReturnCtx($);return k(Q,{code:V.invalid_type,expected:C.boolean,received:Q.parsedType}),p}return C$($.data)}}_1.create=($)=>{return new _1({typeName:c.ZodBoolean,coerce:$?.coerce||!1,...t($)})};class g0 extends e{_parse($){if(this._def.coerce)$.data=new Date($.data);if(this._getType($)!==C.date){let q=this._getOrReturnCtx($);return k(q,{code:V.invalid_type,expected:C.date,received:q.parsedType}),p}if(Number.isNaN($.data.getTime())){let q=this._getOrReturnCtx($);return k(q,{code:V.invalid_date}),p}let Q=new Z$,Y=void 0;for(let q of this._def.checks)if(q.kind==="min"){if($.data.getTime()<q.value)Y=this._getOrReturnCtx($,Y),k(Y,{code:V.too_small,message:q.message,inclusive:!0,exact:!1,minimum:q.value,type:"date"}),Q.dirty()}else if(q.kind==="max"){if($.data.getTime()>q.value)Y=this._getOrReturnCtx($,Y),k(Y,{code:V.too_big,message:q.message,inclusive:!0,exact:!1,maximum:q.value,type:"date"}),Q.dirty()}else Q$.assertNever(q);return{status:Q.value,value:new Date($.data.getTime())}}_addCheck($){return new g0({...this._def,checks:[...this._def.checks,$]})}min($,J){return this._addCheck({kind:"min",value:$.getTime(),message:v.toString(J)})}max($,J){return this._addCheck({kind:"max",value:$.getTime(),message:v.toString(J)})}get minDate(){let $=null;for(let J of this._def.checks)if(J.kind==="min"){if($===null||J.value>$)$=J.value}return $!=null?new Date($):null}get maxDate(){let $=null;for(let J of this._def.checks)if(J.kind==="max"){if($===null||J.value<$)$=J.value}return $!=null?new Date($):null}}g0.create=($)=>{return new g0({checks:[],coerce:$?.coerce||!1,typeName:c.ZodDate,...t($)})};class x1 extends e{_parse($){if(this._getType($)!==C.symbol){let Q=this._getOrReturnCtx($);return k(Q,{code:V.invalid_type,expected:C.symbol,received:Q.parsedType}),p}return C$($.data)}}x1.create=($)=>{return new x1({typeName:c.ZodSymbol,...t($)})};class H1 extends e{_parse($){if(this._getType($)!==C.undefined){let Q=this._getOrReturnCtx($);return k(Q,{code:V.invalid_type,expected:C.undefined,received:Q.parsedType}),p}return C$($.data)}}H1.create=($)=>{return new H1({typeName:c.ZodUndefined,...t($)})};class W1 extends e{_parse($){if(this._getType($)!==C.null){let Q=this._getOrReturnCtx($);return k(Q,{code:V.invalid_type,expected:C.null,received:Q.parsedType}),p}return C$($.data)}}W1.create=($)=>{return new W1({typeName:c.ZodNull,...t($)})};class m0 extends e{constructor(){super(...arguments);this._any=!0}_parse($){return C$($.data)}}m0.create=($)=>{return new m0({typeName:c.ZodAny,...t($)})};class S0 extends e{constructor(){super(...arguments);this._unknown=!0}_parse($){return C$($.data)}}S0.create=($)=>{return new S0({typeName:c.ZodUnknown,...t($)})};class n$ extends e{_parse($){let J=this._getOrReturnCtx($);return k(J,{code:V.invalid_type,expected:C.never,received:J.parsedType}),p}}n$.create=($)=>{return new n$({typeName:c.ZodNever,...t($)})};class h1 extends e{_parse($){if(this._getType($)!==C.undefined){let Q=this._getOrReturnCtx($);return k(Q,{code:V.invalid_type,expected:C.void,received:Q.parsedType}),p}return C$($.data)}}h1.create=($)=>{return new h1({typeName:c.ZodVoid,...t($)})};class g$ extends e{_parse($){let{ctx:J,status:Q}=this._processInputParams($),Y=this._def;if(J.parsedType!==C.array)return k(J,{code:V.invalid_type,expected:C.array,received:J.parsedType}),p;if(Y.exactLength!==null){let G=J.data.length>Y.exactLength.value,X=J.data.length<Y.exactLength.value;if(G||X)k(J,{code:G?V.too_big:V.too_small,minimum:X?Y.exactLength.value:void 0,maximum:G?Y.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:Y.exactLength.message}),Q.dirty()}if(Y.minLength!==null){if(J.data.length<Y.minLength.value)k(J,{code:V.too_small,minimum:Y.minLength.value,type:"array",inclusive:!0,exact:!1,message:Y.minLength.message}),Q.dirty()}if(Y.maxLength!==null){if(J.data.length>Y.maxLength.value)k(J,{code:V.too_big,maximum:Y.maxLength.value,type:"array",inclusive:!0,exact:!1,message:Y.maxLength.message}),Q.dirty()}if(J.common.async)return Promise.all([...J.data].map((G,X)=>{return Y.type._parseAsync(new x$(J,G,J.path,X))})).then((G)=>{return Z$.mergeArray(Q,G)});let q=[...J.data].map((G,X)=>{return Y.type._parseSync(new x$(J,G,J.path,X))});return Z$.mergeArray(Q,q)}get element(){return this._def.type}min($,J){return new g$({...this._def,minLength:{value:$,message:v.toString(J)}})}max($,J){return new g$({...this._def,maxLength:{value:$,message:v.toString(J)}})}length($,J){return new g$({...this._def,exactLength:{value:$,message:v.toString(J)}})}nonempty($){return this.min(1,$)}}g$.create=($,J)=>{return new g$({type:$,minLength:null,maxLength:null,exactLength:null,typeName:c.ZodArray,...t(J)})};function X1($){if($ instanceof A$){let J={};for(let Q in $.shape){let Y=$.shape[Q];J[Q]=m$.create(X1(Y))}return new A$({...$._def,shape:()=>J})}else if($ instanceof g$)return new g$({...$._def,type:X1($.element)});else if($ instanceof m$)return m$.create(X1($.unwrap()));else if($ instanceof H0)return H0.create(X1($.unwrap()));else if($ instanceof s$)return s$.create($.items.map((J)=>X1(J)));else return $}class A$ extends e{constructor(){super(...arguments);this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;let $=this._def.shape(),J=Q$.objectKeys($);return this._cached={shape:$,keys:J},this._cached}_parse($){if(this._getType($)!==C.object){let _=this._getOrReturnCtx($);return k(_,{code:V.invalid_type,expected:C.object,received:_.parsedType}),p}let{status:Q,ctx:Y}=this._processInputParams($),{shape:q,keys:G}=this._getCached(),X=[];if(!(this._def.catchall instanceof n$&&this._def.unknownKeys==="strip")){for(let _ in Y.data)if(!G.includes(_))X.push(_)}let H=[];for(let _ of G){let W=q[_],U=Y.data[_];H.push({key:{status:"valid",value:_},value:W._parse(new x$(Y,U,Y.path,_)),alwaysSet:_ in Y.data})}if(this._def.catchall instanceof n$){let _=this._def.unknownKeys;if(_==="passthrough")for(let W of X)H.push({key:{status:"valid",value:W},value:{status:"valid",value:Y.data[W]}});else if(_==="strict"){if(X.length>0)k(Y,{code:V.unrecognized_keys,keys:X}),Q.dirty()}else if(_==="strip");else throw Error("Internal ZodObject error: invalid unknownKeys value.")}else{let _=this._def.catchall;for(let W of X){let U=Y.data[W];H.push({key:{status:"valid",value:W},value:_._parse(new x$(Y,U,Y.path,W)),alwaysSet:W in Y.data})}}if(Y.common.async)return Promise.resolve().then(async()=>{let _=[];for(let W of H){let U=await W.key,B=await W.value;_.push({key:U,value:B,alwaysSet:W.alwaysSet})}return _}).then((_)=>{return Z$.mergeObjectSync(Q,_)});else return Z$.mergeObjectSync(Q,H)}get shape(){return this._def.shape()}strict($){return v.errToObj,new A$({...this._def,unknownKeys:"strict",...$!==void 0?{errorMap:(J,Q)=>{let Y=this._def.errorMap?.(J,Q).message??Q.defaultError;if(J.code==="unrecognized_keys")return{message:v.errToObj($).message??Y};return{message:Y}}}:{}})}strip(){return new A$({...this._def,unknownKeys:"strip"})}passthrough(){return new A$({...this._def,unknownKeys:"passthrough"})}extend($){return new A$({...this._def,shape:()=>({...this._def.shape(),...$})})}merge($){return new A$({unknownKeys:$._def.unknownKeys,catchall:$._def.catchall,shape:()=>({...this._def.shape(),...$._def.shape()}),typeName:c.ZodObject})}setKey($,J){return this.augment({[$]:J})}catchall($){return new A$({...this._def,catchall:$})}pick($){let J={};for(let Q of Q$.objectKeys($))if($[Q]&&this.shape[Q])J[Q]=this.shape[Q];return new A$({...this._def,shape:()=>J})}omit($){let J={};for(let Q of Q$.objectKeys(this.shape))if(!$[Q])J[Q]=this.shape[Q];return new A$({...this._def,shape:()=>J})}deepPartial(){return X1(this)}partial($){let J={};for(let Q of Q$.objectKeys(this.shape)){let Y=this.shape[Q];if($&&!$[Q])J[Q]=Y;else J[Q]=Y.optional()}return new A$({...this._def,shape:()=>J})}required($){let J={};for(let Q of Q$.objectKeys(this.shape))if($&&!$[Q])J[Q]=this.shape[Q];else{let q=this.shape[Q];while(q instanceof m$)q=q._def.innerType;J[Q]=q}return new A$({...this._def,shape:()=>J})}keyof(){return S3(Q$.objectKeys(this.shape))}}A$.create=($,J)=>{return new A$({shape:()=>$,unknownKeys:"strip",catchall:n$.create(),typeName:c.ZodObject,...t(J)})};A$.strictCreate=($,J)=>{return new A$({shape:()=>$,unknownKeys:"strict",catchall:n$.create(),typeName:c.ZodObject,...t(J)})};A$.lazycreate=($,J)=>{return new A$({shape:$,unknownKeys:"strip",catchall:n$.create(),typeName:c.ZodObject,...t(J)})};class U1 extends e{_parse($){let{ctx:J}=this._processInputParams($),Q=this._def.options;function Y(q){for(let X of q)if(X.result.status==="valid")return X.result;for(let X of q)if(X.result.status==="dirty")return J.common.issues.push(...X.ctx.common.issues),X.result;let G=q.map((X)=>new k$(X.ctx.common.issues));return k(J,{code:V.invalid_union,unionErrors:G}),p}if(J.common.async)return Promise.all(Q.map(async(q)=>{let G={...J,common:{...J.common,issues:[]},parent:null};return{result:await q._parseAsync({data:J.data,path:J.path,parent:G}),ctx:G}})).then(Y);else{let q=void 0,G=[];for(let H of Q){let _={...J,common:{...J.common,issues:[]},parent:null},W=H._parseSync({data:J.data,path:J.path,parent:_});if(W.status==="valid")return W;else if(W.status==="dirty"&&!q)q={result:W,ctx:_};if(_.common.issues.length)G.push(_.common.issues)}if(q)return J.common.issues.push(...q.ctx.common.issues),q.result;let X=G.map((H)=>new k$(H));return k(J,{code:V.invalid_union,unionErrors:X}),p}}get options(){return this._def.options}}U1.create=($,J)=>{return new U1({options:$,typeName:c.ZodUnion,...t(J)})};var _0=($)=>{if($ instanceof K1)return _0($.schema);else if($ instanceof h$)return _0($.innerType());else if($ instanceof z1)return[$.value];else if($ instanceof T0)return $.options;else if($ instanceof N1)return Q$.objectValues($.enum);else if($ instanceof M1)return _0($._def.innerType);else if($ instanceof H1)return[void 0];else if($ instanceof W1)return[null];else if($ instanceof m$)return[void 0,..._0($.unwrap())];else if($ instanceof H0)return[null,..._0($.unwrap())];else if($ instanceof b2)return _0($.unwrap());else if($ instanceof L1)return _0($.unwrap());else if($ instanceof O1)return _0($._def.innerType);else return[]};class j2 extends e{_parse($){let{ctx:J}=this._processInputParams($);if(J.parsedType!==C.object)return k(J,{code:V.invalid_type,expected:C.object,received:J.parsedType}),p;let Q=this.discriminator,Y=J.data[Q],q=this.optionsMap.get(Y);if(!q)return k(J,{code:V.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[Q]}),p;if(J.common.async)return q._parseAsync({data:J.data,path:J.path,parent:J});else return q._parseSync({data:J.data,path:J.path,parent:J})}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create($,J,Q){let Y=new Map;for(let q of J){let G=_0(q.shape[$]);if(!G.length)throw Error(`A discriminator value for key \`${$}\` could not be extracted from all schema options`);for(let X of G){if(Y.has(X))throw Error(`Discriminator property ${String($)} has duplicate value ${String(X)}`);Y.set(X,q)}}return new j2({typeName:c.ZodDiscriminatedUnion,discriminator:$,options:J,optionsMap:Y,...t(Q)})}}function K4($,J){let Q=a$($),Y=a$(J);if($===J)return{valid:!0,data:$};else if(Q===C.object&&Y===C.object){let q=Q$.objectKeys(J),G=Q$.objectKeys($).filter((H)=>q.indexOf(H)!==-1),X={...$,...J};for(let H of G){let _=K4($[H],J[H]);if(!_.valid)return{valid:!1};X[H]=_.data}return{valid:!0,data:X}}else if(Q===C.array&&Y===C.array){if($.length!==J.length)return{valid:!1};let q=[];for(let G=0;G<$.length;G++){let X=$[G],H=J[G],_=K4(X,H);if(!_.valid)return{valid:!1};q.push(_.data)}return{valid:!0,data:q}}else if(Q===C.date&&Y===C.date&&+$===+J)return{valid:!0,data:$};else return{valid:!1}}class B1 extends e{_parse($){let{status:J,ctx:Q}=this._processInputParams($),Y=(q,G)=>{if(w2(q)||w2(G))return p;let X=K4(q.value,G.value);if(!X.valid)return k(Q,{code:V.invalid_intersection_types}),p;if(T2(q)||T2(G))J.dirty();return{status:J.value,value:X.data}};if(Q.common.async)return Promise.all([this._def.left._parseAsync({data:Q.data,path:Q.path,parent:Q}),this._def.right._parseAsync({data:Q.data,path:Q.path,parent:Q})]).then(([q,G])=>Y(q,G));else return Y(this._def.left._parseSync({data:Q.data,path:Q.path,parent:Q}),this._def.right._parseSync({data:Q.data,path:Q.path,parent:Q}))}}B1.create=($,J,Q)=>{return new B1({left:$,right:J,typeName:c.ZodIntersection,...t(Q)})};class s$ extends e{_parse($){let{status:J,ctx:Q}=this._processInputParams($);if(Q.parsedType!==C.array)return k(Q,{code:V.invalid_type,expected:C.array,received:Q.parsedType}),p;if(Q.data.length<this._def.items.length)return k(Q,{code:V.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),p;if(!this._def.rest&&Q.data.length>this._def.items.length)k(Q,{code:V.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),J.dirty();let q=[...Q.data].map((G,X)=>{let H=this._def.items[X]||this._def.rest;if(!H)return null;return H._parse(new x$(Q,G,Q.path,X))}).filter((G)=>!!G);if(Q.common.async)return Promise.all(q).then((G)=>{return Z$.mergeArray(J,G)});else return Z$.mergeArray(J,q)}get items(){return this._def.items}rest($){return new s$({...this._def,rest:$})}}s$.create=($,J)=>{if(!Array.isArray($))throw Error("You must pass an array of schemas to z.tuple([ ... ])");return new s$({items:$,typeName:c.ZodTuple,rest:null,...t(J)})};class u1 extends e{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse($){let{status:J,ctx:Q}=this._processInputParams($);if(Q.parsedType!==C.object)return k(Q,{code:V.invalid_type,expected:C.object,received:Q.parsedType}),p;let Y=[],q=this._def.keyType,G=this._def.valueType;for(let X in Q.data)Y.push({key:q._parse(new x$(Q,X,Q.path,X)),value:G._parse(new x$(Q,Q.data[X],Q.path,X)),alwaysSet:X in Q.data});if(Q.common.async)return Z$.mergeObjectAsync(J,Y);else return Z$.mergeObjectSync(J,Y)}get element(){return this._def.valueType}static create($,J,Q){if(J instanceof e)return new u1({keyType:$,valueType:J,typeName:c.ZodRecord,...t(Q)});return new u1({keyType:v$.create(),valueType:$,typeName:c.ZodRecord,...t(J)})}}class p1 extends e{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse($){let{status:J,ctx:Q}=this._processInputParams($);if(Q.parsedType!==C.map)return k(Q,{code:V.invalid_type,expected:C.map,received:Q.parsedType}),p;let Y=this._def.keyType,q=this._def.valueType,G=[...Q.data.entries()].map(([X,H],_)=>{return{key:Y._parse(new x$(Q,X,Q.path,[_,"key"])),value:q._parse(new x$(Q,H,Q.path,[_,"value"]))}});if(Q.common.async){let X=new Map;return Promise.resolve().then(async()=>{for(let H of G){let _=await H.key,W=await H.value;if(_.status==="aborted"||W.status==="aborted")return p;if(_.status==="dirty"||W.status==="dirty")J.dirty();X.set(_.value,W.value)}return{status:J.value,value:X}})}else{let X=new Map;for(let H of G){let{key:_,value:W}=H;if(_.status==="aborted"||W.status==="aborted")return p;if(_.status==="dirty"||W.status==="dirty")J.dirty();X.set(_.value,W.value)}return{status:J.value,value:X}}}}p1.create=($,J,Q)=>{return new p1({valueType:J,keyType:$,typeName:c.ZodMap,...t(Q)})};class x0 extends e{_parse($){let{status:J,ctx:Q}=this._processInputParams($);if(Q.parsedType!==C.set)return k(Q,{code:V.invalid_type,expected:C.set,received:Q.parsedType}),p;let Y=this._def;if(Y.minSize!==null){if(Q.data.size<Y.minSize.value)k(Q,{code:V.too_small,minimum:Y.minSize.value,type:"set",inclusive:!0,exact:!1,message:Y.minSize.message}),J.dirty()}if(Y.maxSize!==null){if(Q.data.size>Y.maxSize.value)k(Q,{code:V.too_big,maximum:Y.maxSize.value,type:"set",inclusive:!0,exact:!1,message:Y.maxSize.message}),J.dirty()}let q=this._def.valueType;function G(H){let _=new Set;for(let W of H){if(W.status==="aborted")return p;if(W.status==="dirty")J.dirty();_.add(W.value)}return{status:J.value,value:_}}let X=[...Q.data.values()].map((H,_)=>q._parse(new x$(Q,H,Q.path,_)));if(Q.common.async)return Promise.all(X).then((H)=>G(H));else return G(X)}min($,J){return new x0({...this._def,minSize:{value:$,message:v.toString(J)}})}max($,J){return new x0({...this._def,maxSize:{value:$,message:v.toString(J)}})}size($,J){return this.min($,J).max($,J)}nonempty($){return this.min(1,$)}}x0.create=($,J)=>{return new x0({valueType:$,minSize:null,maxSize:null,typeName:c.ZodSet,...t(J)})};class G1 extends e{constructor(){super(...arguments);this.validate=this.implement}_parse($){let{ctx:J}=this._processInputParams($);if(J.parsedType!==C.function)return k(J,{code:V.invalid_type,expected:C.function,received:J.parsedType}),p;function Q(X,H){return m1({data:X,path:J.path,errorMaps:[J.common.contextualErrorMap,J.schemaErrorMap,q1(),G0].filter((_)=>!!_),issueData:{code:V.invalid_arguments,argumentsError:H}})}function Y(X,H){return m1({data:X,path:J.path,errorMaps:[J.common.contextualErrorMap,J.schemaErrorMap,q1(),G0].filter((_)=>!!_),issueData:{code:V.invalid_return_type,returnTypeError:H}})}let q={errorMap:J.common.contextualErrorMap},G=J.data;if(this._def.returns instanceof h0){let X=this;return C$(async function(...H){let _=new k$([]),W=await X._def.args.parseAsync(H,q).catch((z)=>{throw _.addIssue(Q(H,z)),_}),U=await Reflect.apply(G,this,W);return await X._def.returns._def.type.parseAsync(U,q).catch((z)=>{throw _.addIssue(Y(U,z)),_})})}else{let X=this;return C$(function(...H){let _=X._def.args.safeParse(H,q);if(!_.success)throw new k$([Q(H,_.error)]);let W=Reflect.apply(G,this,_.data),U=X._def.returns.safeParse(W,q);if(!U.success)throw new k$([Y(W,U.error)]);return U.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...$){return new G1({...this._def,args:s$.create($).rest(S0.create())})}returns($){return new G1({...this._def,returns:$})}implement($){return this.parse($)}strictImplement($){return this.parse($)}static create($,J,Q){return new G1({args:$?$:s$.create([]).rest(S0.create()),returns:J||S0.create(),typeName:c.ZodFunction,...t(Q)})}}class K1 extends e{get schema(){return this._def.getter()}_parse($){let{ctx:J}=this._processInputParams($);return this._def.getter()._parse({data:J.data,path:J.path,parent:J})}}K1.create=($,J)=>{return new K1({getter:$,typeName:c.ZodLazy,...t(J)})};class z1 extends e{_parse($){if($.data!==this._def.value){let J=this._getOrReturnCtx($);return k(J,{received:J.data,code:V.invalid_literal,expected:this._def.value}),p}return{status:"valid",value:$.data}}get value(){return this._def.value}}z1.create=($,J)=>{return new z1({value:$,typeName:c.ZodLiteral,...t(J)})};function S3($,J){return new T0({values:$,typeName:c.ZodEnum,...t(J)})}class T0 extends e{_parse($){if(typeof $.data!=="string"){let J=this._getOrReturnCtx($),Q=this._def.values;return k(J,{expected:Q$.joinValues(Q),received:J.parsedType,code:V.invalid_type}),p}if(!this._cache)this._cache=new Set(this._def.values);if(!this._cache.has($.data)){let J=this._getOrReturnCtx($),Q=this._def.values;return k(J,{received:J.data,code:V.invalid_enum_value,options:Q}),p}return C$($.data)}get options(){return this._def.values}get enum(){let $={};for(let J of this._def.values)$[J]=J;return $}get Values(){let $={};for(let J of this._def.values)$[J]=J;return $}get Enum(){let $={};for(let J of this._def.values)$[J]=J;return $}extract($,J=this._def){return T0.create($,{...this._def,...J})}exclude($,J=this._def){return T0.create(this.options.filter((Q)=>!$.includes(Q)),{...this._def,...J})}}T0.create=S3;class N1 extends e{_parse($){let J=Q$.getValidEnumValues(this._def.values),Q=this._getOrReturnCtx($);if(Q.parsedType!==C.string&&Q.parsedType!==C.number){let Y=Q$.objectValues(J);return k(Q,{expected:Q$.joinValues(Y),received:Q.parsedType,code:V.invalid_type}),p}if(!this._cache)this._cache=new Set(Q$.getValidEnumValues(this._def.values));if(!this._cache.has($.data)){let Y=Q$.objectValues(J);return k(Q,{received:Q.data,code:V.invalid_enum_value,options:Y}),p}return C$($.data)}get enum(){return this._def.values}}N1.create=($,J)=>{return new N1({values:$,typeName:c.ZodNativeEnum,...t(J)})};class h0 extends e{unwrap(){return this._def.type}_parse($){let{ctx:J}=this._processInputParams($);if(J.parsedType!==C.promise&&J.common.async===!1)return k(J,{code:V.invalid_type,expected:C.promise,received:J.parsedType}),p;let Q=J.parsedType===C.promise?J.data:Promise.resolve(J.data);return C$(Q.then((Y)=>{return this._def.type.parseAsync(Y,{path:J.path,errorMap:J.common.contextualErrorMap})}))}}h0.create=($,J)=>{return new h0({type:$,typeName:c.ZodPromise,...t(J)})};class h$ extends e{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===c.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse($){let{status:J,ctx:Q}=this._processInputParams($),Y=this._def.effect||null,q={addIssue:(G)=>{if(k(Q,G),G.fatal)J.abort();else J.dirty()},get path(){return Q.path}};if(q.addIssue=q.addIssue.bind(q),Y.type==="preprocess"){let G=Y.transform(Q.data,q);if(Q.common.async)return Promise.resolve(G).then(async(X)=>{if(J.value==="aborted")return p;let H=await this._def.schema._parseAsync({data:X,path:Q.path,parent:Q});if(H.status==="aborted")return p;if(H.status==="dirty")return v0(H.value);if(J.value==="dirty")return v0(H.value);return H});else{if(J.value==="aborted")return p;let X=this._def.schema._parseSync({data:G,path:Q.path,parent:Q});if(X.status==="aborted")return p;if(X.status==="dirty")return v0(X.value);if(J.value==="dirty")return v0(X.value);return X}}if(Y.type==="refinement"){let G=(X)=>{let H=Y.refinement(X,q);if(Q.common.async)return Promise.resolve(H);if(H instanceof Promise)throw Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return X};if(Q.common.async===!1){let X=this._def.schema._parseSync({data:Q.data,path:Q.path,parent:Q});if(X.status==="aborted")return p;if(X.status==="dirty")J.dirty();return G(X.value),{status:J.value,value:X.value}}else return this._def.schema._parseAsync({data:Q.data,path:Q.path,parent:Q}).then((X)=>{if(X.status==="aborted")return p;if(X.status==="dirty")J.dirty();return G(X.value).then(()=>{return{status:J.value,value:X.value}})})}if(Y.type==="transform")if(Q.common.async===!1){let G=this._def.schema._parseSync({data:Q.data,path:Q.path,parent:Q});if(!A0(G))return p;let X=Y.transform(G.value,q);if(X instanceof Promise)throw Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:J.value,value:X}}else return this._def.schema._parseAsync({data:Q.data,path:Q.path,parent:Q}).then((G)=>{if(!A0(G))return p;return Promise.resolve(Y.transform(G.value,q)).then((X)=>({status:J.value,value:X}))});Q$.assertNever(Y)}}h$.create=($,J,Q)=>{return new h$({schema:$,typeName:c.ZodEffects,effect:J,...t(Q)})};h$.createWithPreprocess=($,J,Q)=>{return new h$({schema:J,effect:{type:"preprocess",transform:$},typeName:c.ZodEffects,...t(Q)})};class m$ extends e{_parse($){if(this._getType($)===C.undefined)return C$(void 0);return this._def.innerType._parse($)}unwrap(){return this._def.innerType}}m$.create=($,J)=>{return new m$({innerType:$,typeName:c.ZodOptional,...t(J)})};class H0 extends e{_parse($){if(this._getType($)===C.null)return C$(null);return this._def.innerType._parse($)}unwrap(){return this._def.innerType}}H0.create=($,J)=>{return new H0({innerType:$,typeName:c.ZodNullable,...t(J)})};class M1 extends e{_parse($){let{ctx:J}=this._processInputParams($),Q=J.data;if(J.parsedType===C.undefined)Q=this._def.defaultValue();return this._def.innerType._parse({data:Q,path:J.path,parent:J})}removeDefault(){return this._def.innerType}}M1.create=($,J)=>{return new M1({innerType:$,typeName:c.ZodDefault,defaultValue:typeof J.default==="function"?J.default:()=>J.default,...t(J)})};class O1 extends e{_parse($){let{ctx:J}=this._processInputParams($),Q={...J,common:{...J.common,issues:[]}},Y=this._def.innerType._parse({data:Q.data,path:Q.path,parent:{...Q}});if(Y1(Y))return Y.then((q)=>{return{status:"valid",value:q.status==="valid"?q.value:this._def.catchValue({get error(){return new k$(Q.common.issues)},input:Q.data})}});else return{status:"valid",value:Y.status==="valid"?Y.value:this._def.catchValue({get error(){return new k$(Q.common.issues)},input:Q.data})}}removeCatch(){return this._def.innerType}}O1.create=($,J)=>{return new O1({innerType:$,typeName:c.ZodCatch,catchValue:typeof J.catch==="function"?J.catch:()=>J.catch,...t(J)})};class c1 extends e{_parse($){if(this._getType($)!==C.nan){let Q=this._getOrReturnCtx($);return k(Q,{code:V.invalid_type,expected:C.nan,received:Q.parsedType}),p}return{status:"valid",value:$.data}}}c1.create=($)=>{return new c1({typeName:c.ZodNaN,...t($)})};var _8=Symbol("zod_brand");class b2 extends e{_parse($){let{ctx:J}=this._processInputParams($),Q=J.data;return this._def.type._parse({data:Q,path:J.path,parent:J})}unwrap(){return this._def.type}}class l1 extends e{_parse($){let{status:J,ctx:Q}=this._processInputParams($);if(Q.common.async)return(async()=>{let q=await this._def.in._parseAsync({data:Q.data,path:Q.path,parent:Q});if(q.status==="aborted")return p;if(q.status==="dirty")return J.dirty(),v0(q.value);else return this._def.out._parseAsync({data:q.value,path:Q.path,parent:Q})})();else{let Y=this._def.in._parseSync({data:Q.data,path:Q.path,parent:Q});if(Y.status==="aborted")return p;if(Y.status==="dirty")return J.dirty(),{status:"dirty",value:Y.value};else return this._def.out._parseSync({data:Y.value,path:Q.path,parent:Q})}}static create($,J){return new l1({in:$,out:J,typeName:c.ZodPipeline})}}class L1 extends e{_parse($){let J=this._def.innerType._parse($),Q=(Y)=>{if(A0(Y))Y.value=Object.freeze(Y.value);return Y};return Y1(J)?J.then((Y)=>Q(Y)):Q(J)}unwrap(){return this._def.innerType}}L1.create=($,J)=>{return new L1({innerType:$,typeName:c.ZodReadonly,...t(J)})};function O3($,J){let Q=typeof $==="function"?$(J):typeof $==="string"?{message:$}:$;return typeof Q==="string"?{message:Q}:Q}function P3($,J={},Q){if($)return m0.create().superRefine((Y,q)=>{let G=$(Y);if(G instanceof Promise)return G.then((X)=>{if(!X){let H=O3(J,Y),_=H.fatal??Q??!0;q.addIssue({code:"custom",...H,fatal:_})}});if(!G){let X=O3(J,Y),H=X.fatal??Q??!0;q.addIssue({code:"custom",...X,fatal:H})}return});return m0.create()}var H8={object:A$.lazycreate},c;(function($){$.ZodString="ZodString",$.ZodNumber="ZodNumber",$.ZodNaN="ZodNaN",$.ZodBigInt="ZodBigInt",$.ZodBoolean="ZodBoolean",$.ZodDate="ZodDate",$.ZodSymbol="ZodSymbol",$.ZodUndefined="ZodUndefined",$.ZodNull="ZodNull",$.ZodAny="ZodAny",$.ZodUnknown="ZodUnknown",$.ZodNever="ZodNever",$.ZodVoid="ZodVoid",$.ZodArray="ZodArray",$.ZodObject="ZodObject",$.ZodUnion="ZodUnion",$.ZodDiscriminatedUnion="ZodDiscriminatedUnion",$.ZodIntersection="ZodIntersection",$.ZodTuple="ZodTuple",$.ZodRecord="ZodRecord",$.ZodMap="ZodMap",$.ZodSet="ZodSet",$.ZodFunction="ZodFunction",$.ZodLazy="ZodLazy",$.ZodLiteral="ZodLiteral",$.ZodEnum="ZodEnum",$.ZodEffects="ZodEffects",$.ZodNativeEnum="ZodNativeEnum",$.ZodOptional="ZodOptional",$.ZodNullable="ZodNullable",$.ZodDefault="ZodDefault",$.ZodCatch="ZodCatch",$.ZodPromise="ZodPromise",$.ZodBranded="ZodBranded",$.ZodPipeline="ZodPipeline",$.ZodReadonly="ZodReadonly"})(c||(c={}));var W8=($,J={message:`Input not instance of ${$.name}`})=>P3((Q)=>Q instanceof $,J),w3=v$.create,T3=P0.create,U8=c1.create,B8=w0.create,j3=_1.create,K8=g0.create,z8=x1.create,N8=H1.create,M8=W1.create,O8=m0.create,L8=S0.create,F8=n$.create,A8=h1.create,S8=g$.create,P8=A$.create,w8=A$.strictCreate,T8=U1.create,j8=j2.create,b8=B1.create,V8=s$.create,Z8=u1.create,C8=p1.create,R8=x0.create,I8=G1.create,D8=K1.create,k8=z1.create,y8=T0.create,E8=N1.create,f8=h0.create,v8=h$.create,g8=m$.create,m8=H0.create,x8=h$.createWithPreprocess,h8=l1.create,u8=()=>w3().optional(),p8=()=>T3().optional(),c8=()=>j3().optional(),l8={string:($)=>v$.create({...$,coerce:!0}),number:($)=>P0.create({...$,coerce:!0}),boolean:($)=>_1.create({...$,coerce:!0}),bigint:($)=>w0.create({...$,coerce:!0}),date:($)=>g0.create({...$,coerce:!0})};var d8=p;var r8=A.object({before:A.string(),after:A.string(),hierarchy:A.array(A.string()),lineStart:A.number().optional(),lineEnd:A.number().optional()}).passthrough(),z4=A.object({id:A.string(),name:A.string()}).passthrough(),i8=A.object({url:A.string(),mime:A.string().optional()}).passthrough(),N4=A.object({id:A.string(),snippet:A.string(),note:A.string(),createdAt:A.string(),filePath:A.string().optional(),canvasFile:A.string().optional(),context:r8.optional(),images:A.array(A.string()).optional(),attachments:A.array(i8).optional(),source:A.enum(["local","remote"]).optional(),author:z4.optional()}).passthrough(),o8=A.array(N4.optional().catch(void 0)).transform(($)=>$.filter((J)=>J!==void 0)).catch([]),M4=A.object({annotations:o8,generalNote:A.string().catch("")}).passthrough(),b3=A.object({path:A.string()}),V3=A.object({url:A.string()});import{useCallback as p0,useMemo as a8,useState as n8}from"react";var u$="__agent-response__";function u0($){return $.filePath&&$.filePath!=="__agent-response__"?$.filePath:void 0}function d1($){return $.uploadUrl!==null}function y$(){return`ann-${Date.now()}-${Math.random().toString(36).slice(2,6)}`}function j0($,J){$.style.height="auto",$.style.height=(J?Math.max(J,$.scrollHeight):$.scrollHeight)+"px"}function Z3($){let J=$?`[data-annotation-id="${CSS.escape($)}"]`:"[data-annotation-id]";for(let Q of document.querySelectorAll(J))if(Q.tagName==="MARK"){let Y=Q.parentNode;Q.replaceWith(document.createTextNode(Q.textContent||"")),Y?.normalize()}else Q.remove()}function V2({annotations:$,setAnnotations:J,generalNote:Q,setGeneralNote:Y,remoteAnnotations:q,isReadOnly:G,onClear:X}){let[H,_]=n8(null),W=a8(()=>{if(!q?.length)return $;let T=new Set($.map((F)=>F.id)),O=q.filter((F)=>!T.has(F.id));return[...$,...O.map((F)=>({...F,source:"remote"}))]},[$,q]),U=p0((T,O,F,w,S,j,R)=>{J((y)=>[...y,{id:T,snippet:O,note:F,createdAt:new Date().toISOString(),filePath:w,context:S,...j?.length?{images:j}:{},...R?{canvasFile:R}:{}}])},[J]),B=p0((T,O,F)=>{U(y$(),T,O,F)},[U]),z=p0((T,O)=>{J((F)=>F.map((w)=>w.id===T?{...w,note:O}:w))},[J]),K=p0((T)=>{if(!$.some((O)=>O.id===T))return;Z3(T),J((O)=>O.filter((F)=>F.id!==T)),_((O)=>O===T?null:O)},[$,J]),N=p0((T,O)=>{J((F)=>F.map((w)=>w.id===T?{...w,images:[...w.images||[],O]}:w))},[J]),P=p0((T,O)=>{J((F)=>F.map((w)=>w.id===T?{...w,images:(w.images||[]).filter((S)=>S!==O)}:w))},[J]),M=p0(()=>{Z3(),J([]),Y(""),_(null),X?.()},[J,Y,X]);return{annotations:W,generalNote:Q,setGeneralNote:Y,activeAnnotationId:H,setActiveAnnotationId:_,addAnnotation:B,addAnnotationWithId:U,updateAnnotation:z,removeAnnotation:K,addAnnotationImage:N,removeAnnotationImage:P,clearAll:M,isReadOnly:G}}import{useAnnotations as b0}from"@fabrika/annotations/runtime";import{jsxDEV as Pq}from"react/jsx-dev-runtime";import{jsxDEV as c0,Fragment as s8}from"react/jsx-dev-runtime";function O4({hasContent:$,onSubmit:J,onSubmitEmpty:Q,notice:Y,secondaryAction:q,placeholder:G="General notes...",submitLabel:X="Submit",emptyLabel:H="Submit without feedback"}){let{generalNote:_,setGeneralNote:W}=b0();return c0(s8,{children:[c0("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:c0("textarea",{value:_,onChange:(U)=>W(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:G,onInput:(U)=>j0(U.currentTarget,40),ref:(U)=>{if(U)j0(U,40)}},void 0,!1,void 0,this)},void 0,!1,void 0,this),Y,c0("div",{className:"px-4 py-3 border-t border-border-subtle flex-shrink-0",children:$?c0("div",{className:"flex gap-2",children:[q,c0("button",{onClick:J,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:X},void 0,!1,void 0,this)]},void 0,!0,void 0,this):c0("button",{onClick:Q,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:H},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{useAnnotationHost as t8}from"@fabrika/annotations/runtime";import{useCallback as W0,useEffect as e8,useRef as L4,useState as F4}from"react";import{jsxDEV as j$}from"react/jsx-dev-runtime";function A4($){if($.startsWith("/s/")||$.startsWith("http://")||$.startsWith("https://"))return $;return`/api/uploads/${$.split("/").pop()}`}async function $9($,J){let Q=$.uploadUrl;if(!Q)return null;let Y=new FormData;Y.append("image",J);try{let G=await(await fetch(Q(),{method:"POST",body:Y})).json();if($.isShared)return V3.parse(G).url||null;return b3.parse(G).path||null}catch{return null}}function r1({note:$,onNoteChange:J,images:Q,onAddImage:Y,onRemoveImage:q,sessionId:G,placeholder:X="Add your note...",autoFocus:H=!1,autoResize:_=!1,readOnly:W=!1,onKeyDown:U,onTextareaClick:B,textareaRef:z,textareaClassName:K,textareaStyle:N,minHeight:P,attachButton:M="always",openFilePickerRef:T}){let O=t8(),F=!W&&d1(O),[w,S]=F4(!1),[j,R]=F4(!1),[y,I]=F4(!1),Z=L4(0),f=L4(null),u=L4(null),o=W0(()=>u.current?.click(),[]);if(T)T.current=o;let K$=W0((b)=>{if(f.current=b,z)z.current=b;if(b&&_)j0(b,P)},[z,_,P]);e8(()=>{if(H&&f.current){let b=f.current;if(b.focus(),b.value)b.setSelectionRange(b.value.length,b.value.length)}},[H]);let l=W0(async(b)=>{if(!b.type.startsWith("image/"))return;R(!0);try{let m=await $9(O,b);if(m)Y(m)}finally{R(!1)}},[O,Y]),W$=W0((b)=>{for(let m of b.clipboardData?.items??[])if(m.type.startsWith("image/")){b.preventDefault();let G$=m.getAsFile();if(G$)l(G$);return}},[l]),U$=W0((b)=>{if(b.preventDefault(),Z.current++,Z.current===1)S(!0)},[]),z$=W0((b)=>{b.preventDefault()},[]),$$=W0((b)=>{if(b.preventDefault(),Z.current--,Z.current===0)S(!1)},[]),X$=W0((b)=>{b.preventDefault(),Z.current=0,S(!1);for(let m of b.dataTransfer?.files??[])if(m.type.startsWith("image/"))l(m)},[l]),L$=W0((b)=>{if(J(b.currentTarget.value),_)b.currentTarget.style.height="auto",b.currentTarget.style.height=(P?Math.max(P,b.currentTarget.scrollHeight):b.currentTarget.scrollHeight)+"px"},[J,_,P]),a="w-full bg-transparent text-[13px] font-body text-text-primary resize-none focus:outline-none leading-relaxed p-0 border-none",d={width:"100%",background:"transparent",border:"none",color:"var(--color-text-primary)",fontFamily:"'Inter', sans-serif",fontSize:"13px",lineHeight:"1.5",outline:"none",..._?{resize:"none",overflow:"hidden"}:{resize:"vertical"}},J$=F&&(M==="always"||M==="on-focus"&&y);return j$("div",{style:{position:"relative"},onDragEnter:F?U$:void 0,onDragOver:F?z$:void 0,onDragLeave:F?$$:void 0,onDrop:F?X$:void 0,children:[j$("textarea",{ref:K$,value:$,onChange:W?void 0:L$,onPaste:F?W$:void 0,onKeyDown:U,onClick:B,onFocus:()=>I(!0),onBlur:()=>{setTimeout(()=>I(!1),150)},readOnly:W,placeholder:X,className:K??a,style:N??d,rows:_?1:void 0},void 0,!1,void 0,this),F&&j$("input",{ref:u,type:"file",accept:"image/*",multiple:!0,style:{display:"none"},onChange:(b)=>{let m=b.currentTarget.files;if(m)for(let G$ of m)l(G$);b.currentTarget.value=""}},void 0,!1,void 0,this),(Q.length>0||J$)&&j$("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"6px",alignItems:"center"},children:[Q.map((b)=>j$("div",{style:{position:"relative",width:"56px",height:"56px",borderRadius:"6px",overflow:"hidden",border:"1px solid var(--color-border-subtle)",flexShrink:0},children:[j$("img",{src:A4(b),alt:"",style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}},void 0,!1,void 0,this),!W&&j$("button",{onClick:(m)=>{m.stopPropagation(),q(b)},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)]},b,!0,void 0,this)),J$&&j$(Z2,{onClick:o},void 0,!1,void 0,this)]},void 0,!0,void 0,this),j&&j$("div",{style:{fontSize:"11px",color:"var(--color-text-tertiary)",fontFamily:"'Inter', sans-serif",marginTop:"4px"},children:"Uploading..."},void 0,!1,void 0,this),w&&j$("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 Z2({onClick:$,size:J=16}){return j$("button",{onClick:(Q)=>{Q.stopPropagation(),$()},style:{width:`${J*2}px`,height:`${J*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:j$("svg",{width:J,height:J,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[j$("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"},void 0,!1,void 0,this),j$("circle",{cx:"8.5",cy:"8.5",r:"1.5"},void 0,!1,void 0,this),j$("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 S4({images:$}){if(!$.length)return null;return j$("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"6px"},children:$.map((J)=>j$("div",{style:{width:"56px",height:"56px",borderRadius:"6px",overflow:"hidden",border:"1px solid var(--color-border-subtle)",flexShrink:0},children:j$("img",{src:A4(J),alt:"",style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}},void 0,!1,void 0,this)},J,!1,void 0,this))},void 0,!1,void 0,this)}import{SessionContext as J9}from"@fabrika/annotations/runtime";import{useContext as Q9,useEffect as q9,useRef as Y9}from"react";import{jsxDEV as S$,Fragment as C3}from"react/jsx-dev-runtime";function X9($){let J=g1($);return J.length>80?J.slice(0,80)+"...":J}function i1({annotations:$,readOnly:J=!1,onSelect:Q,onReveal:Y,includedRemoteIds:q,onToggleRemoteId:G}){let{updateAnnotation:X,removeAnnotation:H,addAnnotationImage:_,removeAnnotationImage:W,activeAnnotationId:U,setActiveAnnotationId:B}=b0(),z=Q9(J9),K=Y9(new Map);q9(()=>{if(J||!U)return;let F=K.current.get(U);if(F)F.scrollIntoView({behavior:"smooth",block:"nearest"})},[U,J]);let N=(F)=>{B(F),J1(F,!0)},P=(F)=>{B(null),J1(F,!1)},M=(F)=>{if(F.id===U){B(null);return}B(F.id),Q?.(F)},T=!!q&&!!G,O=(F)=>{let w=T&&F.source==="remote";return S$("div",{ref:(S)=>{if(S)K.current.set(F.id,S);else K.current.delete(F.id)},className:`group/ann relative px-3 py-2.5 transition-colors duration-150 ${J?"cursor-pointer ":""}${U===F.id?"bg-highlight-selected":w?"bg-accent-purple-muted/30 hover:bg-accent-purple-muted/50":"odd:bg-bg-elevated-half hover:bg-bg-input"}`,onMouseEnter:()=>N(F.id),onMouseLeave:()=>P(F.id),onClick:()=>M(F),children:[w&&F.author&&S$("div",{className:"flex items-center gap-1.5 mb-1.5",children:[S$("input",{type:"checkbox",checked:q.has(F.id),onChange:(S)=>{S.stopPropagation(),G(F.id)},onClick:(S)=>S.stopPropagation(),className:"accent-accent-purple flex-shrink-0",title:"Include in submission"},void 0,!1,void 0,this),S$("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),S$("span",{className:"text-[11px] font-medium text-accent-purple font-body",children:F.author.name},void 0,!1,void 0,this),S$("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),S$("div",{className:"text-[11px] text-text-tertiary italic line-clamp-2 mb-1.5 leading-snug font-body border-l-2 border-border-medium pl-2",children:X9(F.snippet)},void 0,!1,void 0,this),J?S$(C3,{children:[F.note.trim()&&S$("div",{className:"text-[13px] font-body text-text-primary leading-relaxed",children:F.note},void 0,!1,void 0,this),S$(S4,{images:F.images||[]},void 0,!1,void 0,this)]},void 0,!0,void 0,this):w?S$("div",{className:"text-[13px] font-body text-text-primary leading-relaxed whitespace-pre-wrap",children:F.note},void 0,!1,void 0,this):S$("div",{onClick:(S)=>S.stopPropagation(),children:S$(r1,{note:F.note,onNoteChange:(S)=>X(F.id,S),images:F.images||[],onAddImage:(S)=>_(F.id,S),onRemoveImage:(S)=>W(F.id,S),sessionId:z,autoResize:!0,minHeight:20,textareaClassName:"w-full bg-transparent text-[13px] font-body text-text-primary resize-none focus:outline-none leading-relaxed p-0 border-none min-h-[20px]",textareaStyle:{height:"auto",overflow:"hidden"},placeholder:"Add your note...",attachButton:"on-focus"},void 0,!1,void 0,this)},void 0,!1,void 0,this),S$("div",{className:"absolute top-1.5 right-1.5 opacity-0 group-hover/ann:opacity-100 transition-opacity duration-100 flex items-center gap-0.5",children:[Y&&S$("button",{onClick:(S)=>{S.stopPropagation(),Y(F)},className:"w-5 h-5 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-input transition-colors",title:"Scroll to annotation",children:S$("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[S$("circle",{cx:"12",cy:"12",r:"3"},void 0,!1,void 0,this),S$("path",{d:"M12 2v4M12 18v4M2 12h4M18 12h4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),!J&&!w&&S$("button",{onClick:(S)=>{S.stopPropagation(),H(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:S$("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[S$("polyline",{points:"3 6 5 6 21 6"},void 0,!1,void 0,this),S$("path",{d:"M19 6v14a2 2 0 01-2 2H7a2 2 0 01-2-2V6m3 0V4a2 2 0 012-2h4a2 2 0 012 2v2"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},F.id,!0,void 0,this)};return S$(C3,{children:$.map(O)},void 0,!1,void 0,this)}function o1($){let J=[],Q=$.snippet.trim(),Y=$.context,q=g1(Q);if(q!==Q)J.push(`> ${q}`);else if($.filePath&&Y&&Y.lineStart!=null){let H=Y.lineStart,_=Y.lineEnd??H,W=Q.split(`
2
+ `);if(Q.length<30&&H===_&&(Y.before||Y.after)){let B=z2($);J.push(`> L${H}: ${B}`)}else if(W.length<=6)for(let B=0;B<W.length;B++)J.push(`> ${H+B} | ${W[B]}`);else{for(let B=0;B<3;B++)J.push(`> ${H+B} | ${W[B]}`);J.push(`> ... (${W.length} lines)`);for(let B=W.length-3;B<W.length;B++)J.push(`> ${H+B} | ${W[B]}`)}}else{let H=z2($);if(Q.split(`
3
+ `).length<=3)J.push(`> ${H.split(`
4
+ `).join(`
5
+ > `)}`);else{let _=Q.split(`
6
+ `);J.push(`> ${_[0]}`),J.push(`> ... (${_.length} lines)`),J.push(`> ${_[_.length-1]}`)}}if($.note.trim())J.push(""),J.push($.note.trim());let G=[...$.images??[]],X=new Set(G);for(let H of $.attachments??[]){if(X.has(H.url))continue;X.add(H.url),G.push(H.url)}if(G.length){J.push("");for(let H of G)J.push(`![screenshot](${H})`)}return J.push(""),J.join(`
7
+ `)}import{SessionContext as G9,useAnnotationHost as _9}from"@fabrika/annotations/runtime";import{useCallback as C2,useContext as H9,useEffect as W9,useMemo as D3,useRef as R2,useState as F1}from"react";import{createPortal as U9}from"react-dom";function R3($){let J=/^(\d+(?:\.\d+)?)px$/.exec($.trim());return J?Number(J[1]):void 0}function I3($,J,Q=280){let q=J||document.body,G=$.getBoundingClientRect(),X=q.getBoundingClientRect(),H=q===document.body?0:q.scrollTop,_=G.bottom-X.top+H+8,W=Math.max(0,Math.min(G.left-X.left,X.width-Q-12));return q.style.position="relative",{style:{position:"absolute",top:`${_}px`,left:`${W}px`},parent:q}}import{jsxDEV as b$,Fragment as B9}from"react/jsx-dev-runtime";function y3({anchorEl:$,scrollContainer:J,onClose:Q,ignoreSelector:Y,zIndex:q="50",padding:G="12px",width:X="280px",children:H}){let _=R2(null),W=R2(Q);W.current=Q;let{style:U,parent:B}=I3($,J,R3(X));return W9(()=>{let z=setTimeout(()=>{let K=(N)=>{if(_.current&&!_.current.contains(N.target)){if(Y&&N.target.closest?.(Y))return;W.current(),document.removeEventListener("mousedown",K)}};return document.addEventListener("mousedown",K),()=>document.removeEventListener("mousedown",K)},0);return()=>clearTimeout(z)},[Y]),U9(b$("div",{ref:_,style:{...U,zIndex:q,width:X,background:"var(--color-bg-elevated)",border:"1px solid var(--color-border-hover)",borderRadius:"8px",boxShadow:"0 4px 12px var(--color-shadow)",padding:G,fontFamily:"'Inter', sans-serif"},children:H},void 0,!1,void 0,this),B)}var E3=[{label:"Clarity",items:["Unclear","Why?","Needs example","Missing context"]},{label:"Scope",items:["Overkill","Out of scope","Important","Risky"]},{label:"Action",items:["Simplify","Rethink","Expand on this","Skip this"]}],k3=E3.flatMap(($)=>$.items);function P4({anchorEl:$,scrollContainer:J,snippet:Q,truncateAt:Y=100,header:q,initialNote:G="",initialImages:X,onConfirm:H,onCancel:_,onDelete:W}){let U=H9(G9),B=_9(),z=d1(B),K=G!==""||!!W,[N,P]=F1(G),[M,T]=F1(X||[]),[O,F]=F1(null),[w,S]=F1(K),[j,R]=F1(!1),y=R2(null),I=R2(null),Z=C2(()=>{if(N.trim()||M.length>0)H(N.trim(),M);else if(K&&W)W();else _()},[N,M,H,_,K,W]),f=C2(()=>{if(K){if(!N.trim()&&M.length===0&&W){W(),_();return}H(N,M);return}_()},[N,M,K,H,_,W]),u=!K,o=N.trim().length>0?k3.filter((E)=>E.toLowerCase().startsWith(N.trim().toLowerCase())):k3,K$=!u||w?[]:o.length===1&&o[0]?.toLowerCase()===N.trim().toLowerCase()?[]:o,l=new Set(K$),W$=E3.map((E)=>({label:E.label,items:E.items.filter((x)=>l.has(x))})).filter((E)=>E.items.length>0),U$=W$.map((E)=>E.items),z$=(E)=>U$[E]?.length??0,$$=U$.flat(),X$=D3(()=>{if(O===null)return 0;let E=0;for(let x=0;x<U$.length;x++){if(O<E+z$(x))return x;E+=z$(x)}return 0},[O,U$]),L$=D3(()=>{if(O===null)return 0;let E=0;for(let x=0;x<X$;x++)E+=z$(x);return O-E},[O,X$,U$]),a=(E,x)=>{let r=0;for(let M$=0;M$<E;M$++)r+=z$(M$);return r+x},[d,J$]=F1(N);if(N!==d)J$(N),F(null),S(K);let b=C2((E)=>{P(E)},[]),m=Q.length>Y?Q.slice(0,Y)+"...":Q,G$=C2((E)=>{if($$.length>0&&(E.key==="ArrowDown"||E.key==="ArrowUp"||E.key==="ArrowLeft"||E.key==="ArrowRight")){if(E.preventDefault(),O===null){F(0);return}if(E.key==="ArrowDown"){let r=Math.min(L$+1,z$(X$)-1);F(a(X$,r))}else if(E.key==="ArrowUp"){let r=Math.max(L$-1,0);F(a(X$,r))}else if(E.key==="ArrowRight"){let r=Math.min(X$+1,U$.length-1),M$=Math.min(L$,z$(r)-1);F(a(r,M$))}else if(E.key==="ArrowLeft"){let r=Math.max(X$-1,0),M$=Math.min(L$,z$(r)-1);F(a(r,M$))}return}let x=O===null?void 0:$$[O];if(x!==void 0){if(E.key==="Tab"){E.preventDefault(),b(x);return}if(E.key==="Enter"&&!E.shiftKey){E.preventDefault(),H(x,M);return}}if(E.key==="Enter"&&!E.shiftKey){E.preventDefault(),Z();return}if(E.key==="Escape")if($$.length>0&&!w)S(!0);else if(K)f();else _()},[$$,O,L$,X$,U$,a,b,H,M,Z,w,K,f,_]);return b$(y3,{anchorEl:$,scrollContainer:J,onClose:K?f:_,ignoreSelector:K?"[data-annotation-id]":void 0,zIndex:K?"60":"50",padding:K?"10px 12px":"12px",width:"420px",children:[!K&&(q??b$("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:["“",m,"”"]},void 0,!0,void 0,this)),b$(r1,{note:N,onNoteChange:P,images:M,onAddImage:(E)=>T((x)=>[...x,E]),onRemoveImage:(E)=>T((x)=>x.filter((r)=>r!==E)),sessionId:U,autoFocus:!0,autoResize:K,textareaRef:y,onKeyDown:G$,attachButton:"none",openFilePickerRef:I,textareaStyle:K?{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),b$("div",{style:{display:"flex",alignItems:"center",gap:"8px",marginTop:K?"6px":"8px"},children:[z&&b$(Z2,{onClick:()=>I.current?.(),size:14},void 0,!1,void 0,this),b$("div",{style:{flex:1}},void 0,!1,void 0,this),K?b$("button",{onClick:()=>{if(W)W();_()},onMouseEnter:()=>R(!0),onMouseLeave:()=>R(!1),style:{fontSize:"11px",color:j?"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):b$(B9,{children:[b$("button",{onClick:_,style:{fontSize:"11px",color:"var(--color-text-tertiary)",background:"none",border:"none",cursor:"pointer",padding:"4px 12px",fontFamily:"'Inter', sans-serif"},children:"Cancel"},void 0,!1,void 0,this),b$("button",{onClick:Z,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),$$.length>0&&b$("div",{style:{marginTop:"6px",borderTop:"1px solid var(--color-border-subtle)",paddingTop:"8px",display:"flex",gap:"4px"},children:W$.map((E)=>b$("div",{style:{flex:1},children:[b$("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:E.label},void 0,!1,void 0,this),E.items.map((x)=>{let r=$$.indexOf(x);return b$("div",{onMouseDown:(M$)=>{M$.preventDefault(),M$.stopPropagation(),b(x)},onMouseEnter:()=>F(r),style:{padding:"3px 6px",fontSize:"12px",borderRadius:"4px",fontFamily:"'Inter', sans-serif",color:r===O?"var(--color-text-primary)":"var(--color-text-secondary)",background:r===O?"var(--color-highlight-selected)":"transparent",cursor:"pointer"},children:[b$("span",{style:{fontWeight:500},children:x.slice(0,N.trim().length)},void 0,!1,void 0,this),x.slice(N.trim().length)]},x,!0,void 0,this)})]},E.label,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function t$({anchorEl:$,scrollContainer:J,snippet:Q,truncateAt:Y,header:q,onAdd:G,onCancel:X}){return b$(P4,{anchorEl:$,scrollContainer:J,snippet:Q,truncateAt:Y,header:q,onConfirm:(H,_)=>G(H,_),onCancel:X},void 0,!1,void 0,this)}function l0({anchorEl:$,scrollContainer:J,initialNote:Q,initialImages:Y,onUpdate:q,onDelete:G,onClose:X}){return b$(P4,{anchorEl:$,scrollContainer:J,snippet:"",initialNote:Q,initialImages:Y,onConfirm:(H,_)=>{q(H,_),X()},onDelete:G,onCancel:X},void 0,!1,void 0,this)}import{useEffect as K9,useRef as w4,useState as f3}from"react";import{jsxDEV as z9}from"react/jsx-dev-runtime";function T4($){let{containerRef:J,restoreKey:Q,shape:Y="rect",canvasFile:q,scrollContainer:G}=$,{addAnnotationWithId:X}=b0(),[H,_]=f3(null),[W,U]=f3(!1),B=w4(X);B.current=X;let z=w4(q);z.current=q;let K=w4(Y);return K.current=Y,K9(()=>{let P=J.current;if(!P)return;let M=null;function T(R,y){let I=R.getBoundingClientRect();return X4(I,y.clientX-I.left,y.clientY-I.top)}function O(){if(!M)return;let{host:R,pointerId:y}=M;if(R.hasPointerCapture(y))R.releasePointerCapture(y);R.removeEventListener("pointermove",w),R.removeEventListener("pointerup",S),R.removeEventListener("pointercancel",j),M=null,U(!1)}function F(R){if(M||R.button!==0)return;let y=R.target;if(!(y instanceof Element))return;if(y.closest("[data-block-comment-btn]"))return;if(y.closest("[data-annotation-id]"))return;let I=y.closest(`[${Y4}]`);if(!(I instanceof HTMLElement)||!P?.contains(I))return;let Z=I.closest("[data-md='image']")?.getAttribute("data-md-src");if(!Z)return;let f=T(I,R);if(!f)return;R.preventDefault(),I.setPointerCapture(R.pointerId);let u=y$(),o=S2({...f,w:0,h:0},K.current,u);o.classList.add("ann-region-draft"),I.appendChild(o),M={pointerId:R.pointerId,host:I,src:Z,start:f,shape:K.current,overlay:o,id:u},I.addEventListener("pointermove",w),I.addEventListener("pointerup",S),I.addEventListener("pointercancel",j),U(!0)}function w(R){if(!M||M.pointerId!==R.pointerId)return;let y=T(M.host,R);if(!y)return;A2(M.overlay,L2(M.start,y))}function S(R){if(!M||M.pointerId!==R.pointerId)return;let{overlay:y,id:I,src:Z,shape:f}=M,u=T(M.host,R)??M.start,o=L2(M.start,u);if(O(),!G4(o)){y.remove();return}A2(y,o);let K$={src:Z,shape:f,...o};_({overlay:y,id:I,snippet:v1.format(K$),label:F2(K$)})}function j(R){if(!M||M.pointerId!==R.pointerId)return;M.overlay.remove(),O()}return P.addEventListener("pointerdown",F),()=>{if(P.removeEventListener("pointerdown",F),M)M.overlay.remove(),O()}},[Q]),{popovers:H?z9(t$,{anchorEl:H.overlay,scrollContainer:G,snippet:H.label,truncateAt:80,onAdd:(P,M)=>{H.overlay.classList.remove("ann-region-draft"),B.current(H.id,H.snippet,P,void 0,void 0,M,z.current),_(null)},onCancel:()=>{H.overlay.remove(),_(null)}},void 0,!1,void 0,this):null,isDrawing:W,isPopoverOpen:!!H}}import{useCallback as v3,useEffect as I2,useRef as d0,useState as g3}from"react";import{jsxDEV as j4,Fragment as N9}from"react/jsx-dev-runtime";function V0($){let{containerRef:J,restoreKey:Q,restoreAnnotations:Y,extractContext:q,filePath:G,canvasFile:X,scrollContainer:H}=$,{annotations:_,addAnnotationWithId:W,removeAnnotation:U,updateAnnotation:B,addAnnotationImage:z,removeAnnotationImage:K,activeAnnotationId:N,setActiveAnnotationId:P}=b0(),[M,T]=g3(null),[O,F]=g3(null),w=d0(q);w.current=q;let S=d0(G);S.current=G;let j=d0(X);j.current=X;let R=d0(W);R.current=W;let y=d0(N);y.current=N;let I=d0(P);I.current=P;let Z=Y.length;I2(()=>{if(!J.current)return;let l=setTimeout(()=>{if(J.current)W4(J.current,Y)},50);return()=>clearTimeout(l)},[Q,Z]);let f=d0(null);I2(()=>{D1(N,f.current),f.current=N},[N]),I2(()=>{let l=J.current;if(!l)return;let W$=($$)=>{let X$=$$.target.closest("[data-annotation-id]");if(!X$)return;$$.stopPropagation();let L$=X$.getAttribute("data-annotation-id");if(L$===y.current)T({anchorEl:X$,annId:L$});else I.current(L$)},U$=($$)=>{let X$=$$.target.closest("[data-annotation-id]");if(X$)I.current(X$.getAttribute("data-annotation-id"))},z$=($$)=>{let X$=$$.target.closest("[data-annotation-id]"),L$=$$.relatedTarget?.closest?.("[data-annotation-id]");if(X$&&!L$&&!document.getElementById("ann-inline-popover"))I.current(null)};return l.addEventListener("click",W$),l.addEventListener("mouseover",U$),l.addEventListener("mouseout",z$),()=>{l.removeEventListener("click",W$),l.removeEventListener("mouseover",U$),l.removeEventListener("mouseout",z$)}},[Q]),I2(()=>{let l=()=>u();return document.addEventListener("mouseup",l),()=>document.removeEventListener("mouseup",l)},[]);let u=v3(()=>{let l=window.getSelection();if(!l||l.isCollapsed||!l.toString().trim())return;if(!J.current)return;let W$=l.getRangeAt(0);if(!J.current.contains(W$.startContainer))return;if(W$.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let U$=W3(W$).trim();if(U$.length<2)return;let z$=w.current(W$),$$=W$.cloneRange(),X$=`__pending_${Date.now()}`;try{O0($$,X$)}catch{}window.getSelection()?.removeAllRanges();let L$=document.querySelectorAll(`[data-annotation-id="${X$}"]`),a=L$[L$.length-1];if(!a)return;F({anchorEl:a,tempId:X$,snippet:U$,ctx:z$})},[]),o=v3((l,W$,U$,z$)=>{F({anchorEl:l,tempId:W$,snippet:U$,ctx:z$})},[]);return{popovers:j4(N9,{children:[M&&(()=>{let l=_.find((W$)=>W$.id===M.annId);if(!l)return null;return j4(l0,{anchorEl:M.anchorEl,scrollContainer:H,initialNote:l.note,initialImages:l.images,onUpdate:(W$,U$)=>{B(M.annId,W$);let z$=l.images||[];for(let $$ of U$)if(!z$.includes($$))z(M.annId,$$);for(let $$ of z$)if(!U$.includes($$))K(M.annId,$$)},onDelete:()=>{U(M.annId),P(null)},onClose:()=>T(null)},void 0,!1,void 0,this)})(),O&&j4(t$,{anchorEl:O.anchorEl,scrollContainer:H,snippet:O.snippet,truncateAt:80,onAdd:(l,W$)=>{let U$=y$();k1(O.tempId,U$),R.current(U$,O.snippet,l,S.current,O.ctx,W$,j.current),F(null)},onCancel:()=>{E1(O.tempId),F(null)}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),openCreatePopover:o,isPopoverOpen:!!(M||O)}}import{AnnotationCtx as T9}from"#canvas/runtime";import{AnnotationCtx as j9,AnnotationHostContext as b9}from"@fabrika/annotations/runtime";import{useCallback as P1,useEffect as i3,useMemo as V9,useRef as R4,useState as w1}from"react";var M9=A.object({}).passthrough(),O9=A.object({annotations:A.array(A.unknown()).catch([]),generalNote:A.string().catch(""),responses:A.array(A.unknown()).catch([])}),L9=A.tuple([A.unknown(),A.object({note:A.unknown(),value:A.unknown()})]);function e$($,J,Q="current"){let Y=`canvas:${$}:rev:${J}`;return Q==="next"?`${Y}:next-draft`:Y}function A1($,J){return`${e$($,J)}:draft-handled`}function r0($,J,Q){try{$.removeItem(e$(J,Q)),$.removeItem(A1(J,Q))}catch{}}function b4($){if(!$)return null;try{let J=JSON.parse($),Q=M9.safeParse(J);return Q.success?Q.data:null}catch{return null}}function F9($){let J=L9.safeParse($);if(!J.success)return!1;let{note:Q,value:Y}=J.data[1];if(typeof Q==="string"&&Q.trim().length>0)return!0;if(typeof Y==="string")return Y.trim().length>0;if(Array.isArray(Y))return Y.length>0;return Y!==null&&Y!==void 0}function V4($){if(!$)return!1;let{annotations:J,generalNote:Q,responses:Y}=O9.parse($);return J.length>0||Q.trim().length>0||Y.some(F9)}function D2($,J,Q,Y){try{let q=e$(J,Q);if(V4(b4($.getItem(q))))return $.setItem(A1(J,Q),"1"),null;if($.getItem(A1(J,Q))!==null)return null;let G=Y.filter((X)=>X.revision<Q).sort((X,H)=>H.revision-X.revision);for(let X of G){if(X.hasFeedback){let _=e$(J,X.revision,"next"),W=b4($.getItem(_));if(!V4(W))return null;return $.setItem(q,JSON.stringify({...W,feedbackEntries:[]})),$.setItem(A1(J,Q),"1"),$.removeItem(_),X.revision}let H=b4($.getItem(e$(J,X.revision)));if(!V4(H)){if($.getItem(A1(J,X.revision))!==null)return null;continue}return $.setItem(q,JSON.stringify({...H,feedbackEntries:[]})),$.setItem(A1(J,Q),"1"),X.revision}}catch{}return null}function Z4($,J){let Q=new Map;for(let[Y,q]of $)if(J.has(Y))Q.set(Y,q);return Q}function C4($,J){if(!$||$.length===0)return!1;return $.every((Q)=>J.has(Q))}function a1($,J,Q,Y,q){let G=[],X=$.filter((K)=>K.source!=="remote"||q&&q.has(K.id)),H=X.filter((K)=>K.filePath===u$),_=X.filter((K)=>!K.filePath),W=X.filter((K)=>K.filePath&&K.filePath!==u$),U=Q?Array.from(Q.values()).filter((K)=>k2(K)):[],B=Y?Array.from(Y.values()).filter((K)=>K.markdown.trim()):[];if(U.length>0||B.length>0){G.push("## Responses"),G.push("");for(let K of U)G.push(A9(K));for(let K of B)G.push(K.markdown.trim()),G.push("")}if(H.length>0){G.push("## Annotations on agent response"),G.push("");for(let K of H)G.push(o1(K))}if(_.length>0){G.push("## Canvas annotations"),G.push("");let K=new Map;for(let M of _){let T=M.canvasFile||"";if(!K.has(T))K.set(T,[]);K.get(T).push(M)}let N=[...K.keys()].sort(),P=N.length>1||N.length===1&&N[0]!=="";for(let M of N){let T=K.get(M);if(P&&M)G.push(`### ${M.replace(/\.jsx$/,"")}`),G.push("");let O=S9(T);G.push(h3(O))}}if(W.length>0){let K={};for(let N of W){let P=N.filePath;if(!K[P])K[P]=[];K[P].push(N)}G.push("## File annotations"),G.push("");for(let[N,P]of Object.entries(K)){G.push(`### ${N}`),G.push("");for(let M of P)G.push(o1(M))}}if(J.trim())G.push("## General notes"),G.push(""),G.push(J.trim()),G.push("");return G.join(`
8
+ `).trim()+`
9
+ `}function k2($){if($.note?.trim())return!0;if($.value===null||$.value===void 0)return!1;if($.type==="text"&&!$.value.trim())return!1;if($.type==="checkbox"&&$.value.length===0)return!1;return!0}function m3($){let J=[];for(let Q of $.values()){if(!Q.required)continue;if(Q.value===null||Q.value===void 0){J.push(Q);continue}if(Q.type==="text"&&!Q.value.trim()){J.push(Q);continue}if(Q.type==="checkbox"&&Q.value.length===0){J.push(Q);continue}}return J}function x3($){let J=[];for(let Q of $.values())if(Q.required&&!Q.markdown.trim())J.push(Q);return J}function n1($,J){let Q=m3($),Y=x3(J);return[...Q.map((q)=>q.label),...Y.map((q)=>q.label||q.id)]}function A9($){let J=[];switch(J.push(`**${$.label}**`),$.type){case"radio":case"select":J.push(`Answer: ${$.value}`);break;case"checkbox":for(let Q of $.value)J.push(`- [x] ${Q}`);break;case"text":J.push(""),J.push($.value.trim());break;case"range":J.push(`Answer: ${$.value}`);break}if($.note?.trim())J.push(""),J.push(`Note: ${$.note.trim()}`);return J.push(""),J.join(`
10
+ `)}function S9($){let J={label:"",annotations:[],children:new Map};for(let Q of $){let Y=Q.context?.hierarchy||[],q=J;for(let G of Y){if(!q.children.has(G))q.children.set(G,{label:G,annotations:[],children:new Map});q=q.children.get(G)}q.annotations.push(Q)}return J}function h3($,J=0){let Q=[];for(let Y of $.annotations)Q.push(o1(Y));for(let[,Y]of $.children){let q=J===0?"###":"####";Q.push(`${q} ${Y.label}`),Q.push(""),Q.push(h3(Y,J+1))}return Q.join(`
11
+ `)}import{createContext as P9,useContext as w9}from"react";function u3(){if(typeof window>"u")return"";return window.location.pathname.replace("/s/","")}var p3={get sessionId(){return u3()},isShared:!1,fsAvailable:!0,uploadUrl:null,loadCanvasModule:($,J)=>{let Q=$.replace(/\.jsx$/,".js"),Y=J?`?rev=${J}&t=${Date.now()}`:`?t=${Date.now()}`;return import(`/api/session/${u3()}/canvas/${encodeURIComponent(Q)}${Y}`)}},y2=P9(p3);function U0(){return w9(y2)}var c3=A.object({id:A.string(),type:A.enum(["select","radio","checkbox","text","range"]),label:A.string(),value:A.unknown(),options:A.array(A.string()).optional(),required:A.boolean().optional(),note:A.string().optional()}).passthrough().transform(($)=>({...$,value:$.value})),l3=A.object({id:A.string(),markdown:A.string(),label:A.string().optional(),required:A.boolean().optional()}).passthrough(),d3=M4.extend({responses:A.array(A.tuple([A.string(),c3]).optional().catch(void 0)).transform(($)=>$.filter((J)=>J!==void 0)).catch([]),feedbackEntries:A.array(A.tuple([A.string(),l3]).optional().catch(void 0)).transform(($)=>$.filter((J)=>J!==void 0)).optional().catch([])});function S1($){let J=d3.safeParse($);return J.success?J.data:null}var r3=A.object({feedback:A.string().nullish()}),Z0=A.union([A.object({error:A.string().min(1)}),A.object({content:A.string(),language:A.string().nullish()})]);import{useAnnotations as i0}from"#canvas/runtime";import{jsxDEV as D4}from"react/jsx-dev-runtime";function o3($,J,Q){try{let Y=localStorage.getItem(e$($,J,Q));if(!Y)return null;return S1(JSON.parse(Y))}catch{return null}}function Z9($,J,Q,Y){try{localStorage.setItem(e$($,J,Q),JSON.stringify(Y))}catch{}}function I4($){return{draft:$,responseIds:new Set,canvases:new Set}}function k4({sessionId:$,revision:J,isReadOnly:Q,draftPhase:Y,remoteAnnotations:q,canvasFiles:G,loadState:X,saveState:H,children:_}){let W=!!X,U=W?null:o3($,J,Y),B=R4(U),[z,K]=w1(()=>(U?.annotations??[]).map((a)=>({...a,source:a.source??"local"}))),[N,P]=w1(()=>U?.generalNote??""),[M,T]=w1(()=>U?.responses?new Map(U.responses):new Map),O=`${$}:${J}:${Y}`,F=R4(O);F.current=O;let[w,S]=w1(()=>I4(O)),[j,R]=w1(()=>U?.feedbackEntries?new Map(U.feedbackEntries):new Map),[y,I]=w1(!W);i3(()=>{let a=(d)=>{B.current=d,K((d?.annotations??[]).map((J$)=>({...J$,source:J$.source??"local"}))),P(d?.generalNote??""),T(d?.responses?new Map(d.responses):new Map),R(d?.feedbackEntries?new Map(d.feedbackEntries):new Map),X$(null)};if(W){let d=!1;return I(!1),X($,J,Y).then((J$)=>{if(d)return;a(S1(J$)),I(!0)}),()=>{d=!0}}a(o3($,J,Y)),I(!0);return},[$,J,Y,W,X]);let Z=R4(null);i3(()=>{if(Q&&Y!=="next")return;if(!y)return;if(Z.current)clearTimeout(Z.current);let a={...B.current,annotations:z,generalNote:N,responses:Array.from(M.entries()),feedbackEntries:Array.from(j.entries())},d=()=>{if(H)H($,J,a,Y);else Z9($,J,Y,a)};if(Y==="next"){d();return}return Z.current=setTimeout(d,300),()=>{if(Z.current)clearTimeout(Z.current)}},[z,N,M,j,$,J,Q,Y,y,H]);let f=P1((a,d)=>{T((J$)=>{let b=new Map(J$);return b.set(a,d),b})},[]),u=P1((a)=>{S((d)=>{let J$=d.draft===F.current?d:I4(F.current);if(J$.responseIds.has(a))return J$;return{...J$,responseIds:new Set(J$.responseIds).add(a)}})},[]),o=P1((a)=>{S((d)=>{let J$=d.draft===F.current?d:I4(F.current);if(J$.canvases.has(a))return J$;return{...J$,canvases:new Set(J$.canvases).add(a)}})},[]),K$=w.draft===O?w:null,l=V9(()=>{if(!K$||!C4(G,K$.canvases))return M;return Z4(M,K$.responseIds)},[K$,G,M]),W$=P1((a,d)=>{R((J$)=>{let b=J$.get(a);if(b&&b.markdown===d.markdown&&b.label===d.label&&b.required===d.required)return J$;let m=new Map(J$);return m.set(a,d),m})},[]),U$=P1((a)=>{R((d)=>{if(!d.has(a))return d;let J$=new Map(d);return J$.delete(a),J$})},[]),z$=P1(()=>{if(T(new Map),R(new Map),H)H($,J,{annotations:[],generalNote:"",responses:[],feedbackEntries:[]},Y);else if(Y==="next")localStorage.removeItem(e$($,J,Y));else r0(localStorage,$,J)},[$,J,Y,H]),$$=V2({annotations:z,setAnnotations:K,generalNote:N,setGeneralNote:P,remoteAnnotations:q,isReadOnly:Q,onClear:z$}),{setActiveAnnotationId:X$}=$$,L$=U0();return D4(b9.Provider,{value:L$,children:D4(j9.Provider,{value:$$,children:D4(T9.Provider,{value:{...$$,responses:M,setResponse:f,submittableResponses:l,registerResponse:u,registerCanvasRendered:o,feedbackEntries:j,setFeedbackEntry:W$,removeFeedbackEntry:U$},children:_},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}import{ActiveViewCtx as HW,AnnotationCtx as WW,CanvasFileCtx as UW,SessionContext as BW,useAnnotations as q0,useCanvasFile as KW,useFeedback as zW,useResponseRegistration as NW}from"#canvas/runtime";function s1($){let J=document.querySelector(`[data-annotation-id="${$.id}"]`);if(J instanceof HTMLElement)return J;let Q=$.canvasFile?document.querySelector(`[data-canvas-file="${$.canvasFile}"]`):document;if(!Q)return null;return H4($.snippet,Q)}function a3($){$.classList.remove("ann-flash"),$.offsetWidth,$.classList.add("ann-flash"),$.addEventListener("animationend",()=>{$.classList.remove("ann-flash")},{once:!0})}function y4($,J){let Q=u0($);if(Q)J({type:"file",path:Q}),setTimeout(()=>{let Y=s1($);if(Y)Y.scrollIntoView({behavior:"smooth",block:"center"}),a3(Y)},150);else{let Y=s1($);if(Y)Y.scrollIntoView({behavior:"smooth",block:"center"}),a3(Y)}}import{SessionContext as SJ}from"#canvas/runtime";import{useCallback as r4,useContext as i4,useEffect as M5,useMemo as PJ,useState as j1}from"react";import{createContext as n3}from"react";var $0=n3({activeView:{type:"overview"},setActiveView:()=>{},openFiles:[],closeFile:()=>{},canvasFiles:[]}),E$=n3({currentRevision:1,selectedRevision:1,revisions:[],setSelectedRevision:()=>{},isReadOnly:!1,compareRevision:null,setCompareRevision:()=>{},agentWatching:!1});import{jsxDEV as o0}from"react/jsx-dev-runtime";var C9={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"},R9={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 C0({name:$,type:J,expanded:Q,className:Y=""}){if(J==="dir")return o0("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",className:`flex-shrink-0 ${Y}`,children:Q?o0("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):o0("path",{d:"M1.5 3.5h5l1.5 1.5h6.5v8h-13z",style:{fill:"var(--color-folder-fill)",stroke:"var(--color-folder-stroke)"},strokeWidth:"1"},void 0,!1,void 0,this)},void 0,!1,void 0,this);let q=$.includes(".")?$.split(".").pop().toLowerCase():"",G=C9[q]||"#6b6560",X=R9[q];return o0("svg",{width:"14",height:"14",viewBox:"0 0 16 16",className:`flex-shrink-0 ${Y}`,children:[o0("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:G,opacity:"0.85"},void 0,!1,void 0,this),o0("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&&o0("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(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var s0=f4();function q5($){s0=$}var a0={exec:()=>null};function H$($,J=""){let Q=typeof $=="string"?$:$.source,Y={replace:(q,G)=>{let X=typeof G=="string"?G:G.source;return X=X.replace(I$.caret,"$1"),Q=Q.replace(q,X),Y},getRegex:()=>new RegExp(Q,J)};return Y}var I9=(()=>{try{return!!new RegExp("(?<=1)(?<!1)")}catch{return!1}})(),I$={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] +\S/,listReplaceTask:/^\[[ xX]\] +/,listTaskCheckbox:/\[[ xX]\]/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:($)=>new RegExp(`^( {0,3}${$})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:($)=>new RegExp(`^ {0,${Math.min(3,$-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:($)=>new RegExp(`^ {0,${Math.min(3,$-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:($)=>new RegExp(`^ {0,${Math.min(3,$-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:($)=>new RegExp(`^ {0,${Math.min(3,$-1)}}#`),htmlBeginRegex:($)=>new RegExp(`^ {0,${Math.min(3,$-1)}}<(?:[a-z].*>|!--)`,"i"),blockquoteBeginRegex:($)=>new RegExp(`^ {0,${Math.min(3,$-1)}}>`)},D9=/^(?:[ \t]*(?:\n|$))+/,k9=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,y9=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,J2=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,E9=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,v4=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,Y5=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,X5=H$(Y5).replace(/bull/g,v4).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(),f9=H$(Y5).replace(/bull/g,v4).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(),g4=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,v9=/^[^\n]+/,m4=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,g9=H$(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",m4).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),m9=H$(/^(bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,v4).getRegex(),m2="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",x4=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,x9=H$("^ {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",x4).replace("tag",m2).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),G5=H$(g4).replace("hr",J2).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",m2).getRegex(),h9=H$(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",G5).getRegex(),h4={blockquote:h9,code:k9,def:g9,fences:y9,heading:E9,hr:J2,html:x9,lheading:X5,list:m9,newline:D9,paragraph:G5,table:a0,text:v9},s3=H$("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",J2).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",m2).getRegex(),u9={...h4,lheading:f9,table:s3,paragraph:H$(g4).replace("hr",J2).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",s3).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",m2).getRegex()},p9={...h4,html:H$(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",x4).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:a0,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:H$(g4).replace("hr",J2).replace("heading",` *#{1,6} *[^
12
+ ]`).replace("lheading",X5).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},c9=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,l9=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,_5=/^( {2,}|\\)\n(?!\s*$)/,d9=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,T1=/[\p{P}\p{S}]/u,x2=/[\s\p{P}\p{S}]/u,u4=/[^\s\p{P}\p{S}]/u,r9=H$(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,x2).getRegex(),H5=/(?!~)[\p{P}\p{S}]/u,i9=/(?!~)[\s\p{P}\p{S}]/u,o9=/(?:[^\s\p{P}\p{S}]|~)/u,a9=H$(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",I9?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),W5=/^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/,n9=H$(W5,"u").replace(/punct/g,T1).getRegex(),s9=H$(W5,"u").replace(/punct/g,H5).getRegex(),U5="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",t9=H$(U5,"gu").replace(/notPunctSpace/g,u4).replace(/punctSpace/g,x2).replace(/punct/g,T1).getRegex(),e9=H$(U5,"gu").replace(/notPunctSpace/g,o9).replace(/punctSpace/g,i9).replace(/punct/g,H5).getRegex(),$J=H$("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,u4).replace(/punctSpace/g,x2).replace(/punct/g,T1).getRegex(),JJ=H$(/^~~?(?:((?!~)punct)|[^\s~])/,"u").replace(/punct/g,T1).getRegex(),QJ="^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)",qJ=H$(QJ,"gu").replace(/notPunctSpace/g,u4).replace(/punctSpace/g,x2).replace(/punct/g,T1).getRegex(),YJ=H$(/\\(punct)/,"gu").replace(/punct/g,T1).getRegex(),XJ=H$(/^<(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(),GJ=H$(x4).replace("(?:-->|$)","-->").getRegex(),_J=H$("^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",GJ).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),f2=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/,HJ=H$(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace("label",f2).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),B5=H$(/^!?\[(label)\]\[(ref)\]/).replace("label",f2).replace("ref",m4).getRegex(),K5=H$(/^!?\[(ref)\](?:\[\])?/).replace("ref",m4).getRegex(),WJ=H$("reflink|nolink(?!\\()","g").replace("reflink",B5).replace("nolink",K5).getRegex(),t3=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,p4={_backpedal:a0,anyPunctuation:YJ,autolink:XJ,blockSkip:a9,br:_5,code:l9,del:a0,delLDelim:a0,delRDelim:a0,emStrongLDelim:n9,emStrongRDelimAst:t9,emStrongRDelimUnd:$J,escape:c9,link:HJ,nolink:K5,punctuation:r9,reflink:B5,reflinkSearch:WJ,tag:_J,text:d9,url:a0},UJ={...p4,link:H$(/^!?\[(label)\]\((.*?)\)/).replace("label",f2).getRegex(),reflink:H$(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",f2).getRegex()},E4={...p4,emStrongRDelimAst:e9,emStrongLDelim:s9,delLDelim:JJ,delRDelim:qJ,url:H$(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol",t3).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:H$(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace("protocol",t3).getRegex()},BJ={...E4,br:H$(_5).replace("{2,}","*").getRegex(),text:H$(E4.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},E2={normal:h4,gfm:u9,pedantic:p9},t1={normal:p4,gfm:E4,breaks:BJ,pedantic:UJ},KJ={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},e3=($)=>KJ[$];function J0($,J){if(J){if(I$.escapeTest.test($))return $.replace(I$.escapeReplace,e3)}else if(I$.escapeTestNoEncode.test($))return $.replace(I$.escapeReplaceNoEncode,e3);return $}function $5($){try{$=encodeURI($).replace(I$.percentDecode,"%")}catch{return null}return $}function J5($,J){let Q=$.replace(I$.findPipe,(G,X,H)=>{let _=!1,W=X;for(;--W>=0&&H[W]==="\\";)_=!_;return _?"|":" |"}),Y=Q.split(I$.splitPipe),q=0;if(Y[0].trim()||Y.shift(),Y.length>0&&!Y.at(-1)?.trim()&&Y.pop(),J)if(Y.length>J)Y.splice(J);else for(;Y.length<J;)Y.push("");for(;q<Y.length;q++)Y[q]=Y[q].trim().replace(I$.slashPipe,"|");return Y}function e1($,J,Q){let Y=$.length;if(Y===0)return"";let q=0;for(;q<Y;){let G=$.charAt(Y-q-1);if(G===J&&!Q)q++;else if(G!==J&&Q)q++;else break}return $.slice(0,Y-q)}function zJ($,J){if($.indexOf(J[1])===-1)return-1;let Q=0;for(let Y=0;Y<$.length;Y++)if($[Y]==="\\")Y++;else if($[Y]===J[0])Q++;else if($[Y]===J[1]&&(Q--,Q<0))return Y;return Q>0?-2:-1}function NJ($,J=0){let Q=J,Y="";for(let q of $)if(q==="\t"){let G=4-Q%4;Y+=" ".repeat(G),Q+=G}else Y+=q,Q++;return Y}function Q5($,J,Q,Y,q){let G=J.href,X=J.title||null,H=$[1].replace(q.other.outputLinkReplace,"$1");Y.state.inLink=!0;let _={type:$[0].charAt(0)==="!"?"image":"link",raw:Q,href:G,title:X,text:H,tokens:Y.inlineTokens(H)};return Y.state.inLink=!1,_}function MJ($,J,Q){let Y=$.match(Q.other.indentCodeCompensation);if(Y===null)return J;let q=Y[1];return J.split(`
13
+ `).map((G)=>{let X=G.match(Q.other.beginningSpace);if(X===null)return G;let[H]=X;return H.length>=q.length?G.slice(q.length):G}).join(`
14
+ `)}var v2=class{options;rules;lexer;constructor($){this.options=$||s0}space($){let J=this.rules.block.newline.exec($);if(J&&J[0].length>0)return{type:"space",raw:J[0]}}code($){let J=this.rules.block.code.exec($);if(J){let Q=J[0].replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:J[0],codeBlockStyle:"indented",text:this.options.pedantic?Q:e1(Q,`
15
+ `)}}}fences($){let J=this.rules.block.fences.exec($);if(J){let Q=J[0],Y=MJ(Q,J[3]||"",this.rules);return{type:"code",raw:Q,lang:J[2]?J[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):J[2],text:Y}}}heading($){let J=this.rules.block.heading.exec($);if(J){let Q=J[2].trim();if(this.rules.other.endingHash.test(Q)){let Y=e1(Q,"#");(this.options.pedantic||!Y||this.rules.other.endingSpaceChar.test(Y))&&(Q=Y.trim())}return{type:"heading",raw:J[0],depth:J[1].length,text:Q,tokens:this.lexer.inline(Q)}}}hr($){let J=this.rules.block.hr.exec($);if(J)return{type:"hr",raw:e1(J[0],`
16
+ `)}}blockquote($){let J=this.rules.block.blockquote.exec($);if(J){let Q=e1(J[0],`
7
17
  `).split(`
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(`
18
+ `),Y="",q="",G=[];for(;Q.length>0;){let X=!1,H=[],_;for(_=0;_<Q.length;_++)if(this.rules.other.blockquoteStart.test(Q[_]))H.push(Q[_]),X=!0;else if(!X)H.push(Q[_]);else break;Q=Q.slice(_);let W=H.join(`
19
+ `),U=W.replace(this.rules.other.blockquoteSetextReplace,`
20
+ $1`).replace(this.rules.other.blockquoteSetextReplace2,"");Y=Y?`${Y}
21
+ ${W}`:W,q=q?`${q}
22
+ ${U}`:U;let B=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(U,G,!0),this.lexer.state.top=B,Q.length===0)break;let z=G.at(-1);if(z?.type==="code")break;if(z?.type==="blockquote"){let K=z,N=K.raw+`
23
+ `+Q.join(`
24
+ `),P=this.blockquote(N);G[G.length-1]=P,Y=Y.substring(0,Y.length-K.raw.length)+P.raw,q=q.substring(0,q.length-K.text.length)+P.text;break}else if(z?.type==="list"){let K=z,N=K.raw+`
25
+ `+Q.join(`
26
+ `),P=this.list(N);G[G.length-1]=P,Y=Y.substring(0,Y.length-z.raw.length)+P.raw,q=q.substring(0,q.length-K.raw.length)+P.raw,Q=N.substring(G.at(-1).raw.length).split(`
27
+ `);continue}}return{type:"blockquote",raw:Y,tokens:G,text:q}}}list($){let J=this.rules.block.list.exec($);if(J){let Q=J[1].trim(),Y=Q.length>1,q={type:"list",raw:"",ordered:Y,start:Y?+Q.slice(0,-1):"",loose:!1,items:[]};Q=Y?`\\d{1,9}\\${Q.slice(-1)}`:`\\${Q}`,this.options.pedantic&&(Q=Y?Q:"[*+-]");let G=this.rules.other.listItemRegex(Q),X=!1;for(;$;){let _=!1,W="",U="";if(!(J=G.exec($))||this.rules.block.hr.test($))break;W=J[0],$=$.substring(W.length);let B=NJ(J[2].split(`
28
+ `,1)[0],J[1].length),z=$.split(`
29
+ `,1)[0],K=!B.trim(),N=0;if(this.options.pedantic?(N=2,U=B.trimStart()):K?N=J[1].length+1:(N=B.search(this.rules.other.nonSpaceChar),N=N>4?1:N,U=B.slice(N),N+=J[1].length),K&&this.rules.other.blankLine.test(z)&&(W+=z+`
30
+ `,$=$.substring(z.length+1),_=!0),!_){let P=this.rules.other.nextBulletRegex(N),M=this.rules.other.hrRegex(N),T=this.rules.other.fencesBeginRegex(N),O=this.rules.other.headingBeginRegex(N),F=this.rules.other.htmlBeginRegex(N),w=this.rules.other.blockquoteBeginRegex(N);for(;$;){let S=$.split(`
31
+ `,1)[0],j;if(z=S,this.options.pedantic?(z=z.replace(this.rules.other.listReplaceNesting," "),j=z):j=z.replace(this.rules.other.tabCharGlobal," "),T.test(z)||O.test(z)||F.test(z)||w.test(z)||P.test(z)||M.test(z))break;if(j.search(this.rules.other.nonSpaceChar)>=N||!z.trim())U+=`
32
+ `+j.slice(N);else{if(K||B.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||T.test(B)||O.test(B)||M.test(B))break;U+=`
33
+ `+z}K=!z.trim(),W+=S+`
34
+ `,$=$.substring(S.length+1),B=j.slice(N)}}q.loose||(X?q.loose=!0:this.rules.other.doubleBlankLine.test(W)&&(X=!0)),q.items.push({type:"list_item",raw:W,task:!!this.options.gfm&&this.rules.other.listIsTask.test(U),loose:!1,text:U,tokens:[]}),q.raw+=W}let H=q.items.at(-1);if(H)H.raw=H.raw.trimEnd(),H.text=H.text.trimEnd();else return;q.raw=q.raw.trimEnd();for(let _ of q.items){if(this.lexer.state.top=!1,_.tokens=this.lexer.blockTokens(_.text,[]),_.task){if(_.text=_.text.replace(this.rules.other.listReplaceTask,""),_.tokens[0]?.type==="text"||_.tokens[0]?.type==="paragraph"){_.tokens[0].raw=_.tokens[0].raw.replace(this.rules.other.listReplaceTask,""),_.tokens[0].text=_.tokens[0].text.replace(this.rules.other.listReplaceTask,"");for(let 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 W=this.rules.other.listTaskCheckbox.exec(_.raw);if(W){let U={type:"checkbox",raw:W[0]+" ",checked:W[0]!=="[ ]"};_.checked=U.checked,q.loose?_.tokens[0]&&["paragraph","text"].includes(_.tokens[0].type)&&"tokens"in _.tokens[0]&&_.tokens[0].tokens?(_.tokens[0].raw=U.raw+_.tokens[0].raw,_.tokens[0].text=U.raw+_.tokens[0].text,_.tokens[0].tokens.unshift(U)):_.tokens.unshift({type:"paragraph",raw:U.raw,text:U.raw,tokens:[U]}):_.tokens.unshift(U)}}if(!q.loose){let W=_.tokens.filter((B)=>B.type==="space"),U=W.length>0&&W.some((B)=>this.rules.other.anyLine.test(B.raw));q.loose=U}}if(q.loose)for(let _ of q.items){_.loose=!0;for(let W of _.tokens)W.type==="text"&&(W.type="paragraph")}return q}}html($){let J=this.rules.block.html.exec($);if(J)return{type:"html",block:!0,raw:J[0],pre:J[1]==="pre"||J[1]==="script"||J[1]==="style",text:J[0]}}def($){let J=this.rules.block.def.exec($);if(J){let Q=J[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal," "),Y=J[2]?J[2].replace(this.rules.other.hrefBrackets,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",q=J[3]?J[3].substring(1,J[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):J[3];return{type:"def",tag:Q,raw:J[0],href:Y,title:q}}}table($){let J=this.rules.block.table.exec($);if(!J||!this.rules.other.tableDelimiter.test(J[2]))return;let Q=J5(J[1]),Y=J[2].replace(this.rules.other.tableAlignChars,"").split("|"),q=J[3]?.trim()?J[3].replace(this.rules.other.tableRowBlankLine,"").split(`
35
+ `):[],G={type:"table",raw:J[0],header:[],align:[],rows:[]};if(Q.length===Y.length){for(let X of Y)this.rules.other.tableAlignRight.test(X)?G.align.push("right"):this.rules.other.tableAlignCenter.test(X)?G.align.push("center"):this.rules.other.tableAlignLeft.test(X)?G.align.push("left"):G.align.push(null);for(let X=0;X<Q.length;X++)G.header.push({text:Q[X],tokens:this.lexer.inline(Q[X]),header:!0,align:G.align[X]});for(let X of q)G.rows.push(J5(X,G.header.length).map((H,_)=>({text:H,tokens:this.lexer.inline(H),header:!1,align:G.align[_]})));return G}}lheading($){let J=this.rules.block.lheading.exec($);if(J){let Q=J[1].trim();return{type:"heading",raw:J[0],depth:J[2].charAt(0)==="="?1:2,text:Q,tokens:this.lexer.inline(Q)}}}paragraph($){let J=this.rules.block.paragraph.exec($);if(J){let Q=J[1].charAt(J[1].length-1)===`
36
+ `?J[1].slice(0,-1):J[1];return{type:"paragraph",raw:J[0],text:Q,tokens:this.lexer.inline(Q)}}}text($){let J=this.rules.block.text.exec($);if(J)return{type:"text",raw:J[0],text:J[0],tokens:this.lexer.inline(J[0])}}escape($){let J=this.rules.inline.escape.exec($);if(J)return{type:"escape",raw:J[0],text:J[1]}}tag($){let J=this.rules.inline.tag.exec($);if(J)return!this.lexer.state.inLink&&this.rules.other.startATag.test(J[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test(J[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test(J[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test(J[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:J[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:J[0]}}link($){let J=this.rules.inline.link.exec($);if(J){let Q=J[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(Q)){if(!this.rules.other.endAngleBracket.test(Q))return;let G=e1(Q.slice(0,-1),"\\");if((Q.length-G.length)%2===0)return}else{let G=zJ(J[2],"()");if(G===-2)return;if(G>-1){let X=(J[0].indexOf("!")===0?5:4)+J[1].length+G;J[2]=J[2].substring(0,G),J[0]=J[0].substring(0,X).trim(),J[3]=""}}let Y=J[2],q="";if(this.options.pedantic){let G=this.rules.other.pedanticHrefTitle.exec(Y);G&&(Y=G[1],q=G[3])}else q=J[3]?J[3].slice(1,-1):"";return Y=Y.trim(),this.rules.other.startAngleBracket.test(Y)&&(this.options.pedantic&&!this.rules.other.endAngleBracket.test(Q)?Y=Y.slice(1):Y=Y.slice(1,-1)),Q5(J,{href:Y&&Y.replace(this.rules.inline.anyPunctuation,"$1"),title:q&&q.replace(this.rules.inline.anyPunctuation,"$1")},J[0],this.lexer,this.rules)}}reflink($,J){let Q;if((Q=this.rules.inline.reflink.exec($))||(Q=this.rules.inline.nolink.exec($))){let Y=(Q[2]||Q[1]).replace(this.rules.other.multipleSpaceGlobal," "),q=J[Y.toLowerCase()];if(!q){let G=Q[0].charAt(0);return{type:"text",raw:G,text:G}}return Q5(Q,q,Q[0],this.lexer,this.rules)}}emStrong($,J,Q=""){let Y=this.rules.inline.emStrongLDelim.exec($);if(!Y||!Y[1]&&!Y[2]&&!Y[3]&&!Y[4]||Y[4]&&Q.match(this.rules.other.unicodeAlphaNumeric))return;if(!(Y[1]||Y[3])||!Q||this.rules.inline.punctuation.exec(Q)){let q=[...Y[0]].length-1,G,X,H=q,_=0,W=Y[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(W.lastIndex=0,J=J.slice(-1*$.length+q);(Y=W.exec(J))!==null;){if(G=Y[1]||Y[2]||Y[3]||Y[4]||Y[5]||Y[6],!G)continue;if(X=[...G].length,Y[3]||Y[4]){H+=X;continue}else if((Y[5]||Y[6])&&q%3&&!((q+X)%3)){_+=X;continue}if(H-=X,H>0)continue;X=Math.min(X,X+H+_);let U=[...Y[0]][0].length,B=$.slice(0,q+Y.index+U+X);if(Math.min(q,X)%2){let K=B.slice(1,-1);return{type:"em",raw:B,text:K,tokens:this.lexer.inlineTokens(K)}}let z=B.slice(2,-2);return{type:"strong",raw:B,text:z,tokens:this.lexer.inlineTokens(z)}}}}codespan($){let J=this.rules.inline.code.exec($);if(J){let Q=J[2].replace(this.rules.other.newLineCharGlobal," "),Y=this.rules.other.nonSpaceChar.test(Q),q=this.rules.other.startingSpaceChar.test(Q)&&this.rules.other.endingSpaceChar.test(Q);return Y&&q&&(Q=Q.substring(1,Q.length-1)),{type:"codespan",raw:J[0],text:Q}}}br($){let J=this.rules.inline.br.exec($);if(J)return{type:"br",raw:J[0]}}del($,J,Q=""){let Y=this.rules.inline.delLDelim.exec($);if(!Y)return;if(!Y[1]||!Q||this.rules.inline.punctuation.exec(Q)){let q=[...Y[0]].length-1,G,X,H=q,_=this.rules.inline.delRDelim;for(_.lastIndex=0,J=J.slice(-1*$.length+q);(Y=_.exec(J))!==null;){if(G=Y[1]||Y[2]||Y[3]||Y[4]||Y[5]||Y[6],!G||(X=[...G].length,X!==q))continue;if(Y[3]||Y[4]){H+=X;continue}if(H-=X,H>0)continue;X=Math.min(X,X+H);let W=[...Y[0]][0].length,U=$.slice(0,q+Y.index+W+X),B=U.slice(q,-q);return{type:"del",raw:U,text:B,tokens:this.lexer.inlineTokens(B)}}}}autolink($){let J=this.rules.inline.autolink.exec($);if(J){let Q,Y;return J[2]==="@"?(Q=J[1],Y="mailto:"+Q):(Q=J[1],Y=Q),{type:"link",raw:J[0],text:Q,href:Y,tokens:[{type:"text",raw:Q,text:Q}]}}}url($){let J;if(J=this.rules.inline.url.exec($)){let Q,Y;if(J[2]==="@")Q=J[0],Y="mailto:"+Q;else{let q;do q=J[0],J[0]=this.rules.inline._backpedal.exec(J[0])?.[0]??"";while(q!==J[0]);Q=J[0],J[1]==="www."?Y="http://"+J[0]:Y=J[0]}return{type:"link",raw:J[0],text:Q,href:Y,tokens:[{type:"text",raw:Q,text:Q}]}}}inlineText($){let J=this.rules.inline.text.exec($);if(J){let Q=this.lexer.state.inRawBlock;return{type:"text",raw:J[0],text:J[0],escaped:Q}}}},p$=class ${tokens;options;state;inlineQueue;tokenizer;constructor(J){this.tokens=[],this.tokens.links=Object.create(null),this.options=J||s0,this.options.tokenizer=this.options.tokenizer||new v2,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};let Q={other:I$,block:E2.normal,inline:t1.normal};this.options.pedantic?(Q.block=E2.pedantic,Q.inline=t1.pedantic):this.options.gfm&&(Q.block=E2.gfm,this.options.breaks?Q.inline=t1.breaks:Q.inline=t1.gfm),this.tokenizer.rules=Q}static get rules(){return{block:E2,inline:t1}}static lex(J,Q){return new $(Q).lex(J)}static lexInline(J,Q){return new $(Q).inlineTokens(J)}lex(J){J=J.replace(I$.carriageReturn,`
37
+ `),this.blockTokens(J,this.tokens);for(let Q=0;Q<this.inlineQueue.length;Q++){let Y=this.inlineQueue[Q];this.inlineTokens(Y.src,Y.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(J,Q=[],Y=!1){for(this.tokenizer.lexer=this,this.options.pedantic&&(J=J.replace(I$.tabCharGlobal," ").replace(I$.spaceLine,""));J;){let q;if(this.options.extensions?.block?.some((X)=>(q=X.call({lexer:this},J,Q))?(J=J.substring(q.raw.length),Q.push(q),!0):!1))continue;if(q=this.tokenizer.space(J)){J=J.substring(q.raw.length);let X=Q.at(-1);q.raw.length===1&&X!==void 0?X.raw+=`
38
+ `:Q.push(q);continue}if(q=this.tokenizer.code(J)){J=J.substring(q.raw.length);let X=Q.at(-1);X?.type==="paragraph"||X?.type==="text"?(X.raw+=(X.raw.endsWith(`
29
39
  `)?"":`
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(`
40
+ `)+q.raw,X.text+=`
41
+ `+q.text,this.inlineQueue.at(-1).src=X.text):Q.push(q);continue}if(q=this.tokenizer.fences(J)){J=J.substring(q.raw.length),Q.push(q);continue}if(q=this.tokenizer.heading(J)){J=J.substring(q.raw.length),Q.push(q);continue}if(q=this.tokenizer.hr(J)){J=J.substring(q.raw.length),Q.push(q);continue}if(q=this.tokenizer.blockquote(J)){J=J.substring(q.raw.length),Q.push(q);continue}if(q=this.tokenizer.list(J)){J=J.substring(q.raw.length),Q.push(q);continue}if(q=this.tokenizer.html(J)){J=J.substring(q.raw.length),Q.push(q);continue}if(q=this.tokenizer.def(J)){J=J.substring(q.raw.length);let X=Q.at(-1);X?.type==="paragraph"||X?.type==="text"?(X.raw+=(X.raw.endsWith(`
32
42
  `)?"":`
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(`
43
+ `)+q.raw,X.text+=`
44
+ `+q.raw,this.inlineQueue.at(-1).src=X.text):this.tokens.links[q.tag]||(this.tokens.links[q.tag]={href:q.href,title:q.title},Q.push(q));continue}if(q=this.tokenizer.table(J)){J=J.substring(q.raw.length),Q.push(q);continue}if(q=this.tokenizer.lheading(J)){J=J.substring(q.raw.length),Q.push(q);continue}let G=J;if(this.options.extensions?.startBlock){let X=1/0,H=J.slice(1),_;this.options.extensions.startBlock.forEach((W)=>{_=W.call({lexer:this},H),typeof _=="number"&&_>=0&&(X=Math.min(X,_))}),X<1/0&&X>=0&&(G=J.substring(0,X+1))}if(this.state.top&&(q=this.tokenizer.paragraph(G))){let X=Q.at(-1);Y&&X?.type==="paragraph"?(X.raw+=(X.raw.endsWith(`
35
45
  `)?"":`
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(`
46
+ `)+q.raw,X.text+=`
47
+ `+q.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=X.text):Q.push(q),Y=G.length!==J.length,J=J.substring(q.raw.length);continue}if(q=this.tokenizer.text(J)){J=J.substring(q.raw.length);let X=Q.at(-1);X?.type==="text"?(X.raw+=(X.raw.endsWith(`
38
48
  `)?"":`
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>
49
+ `)+q.raw,X.text+=`
50
+ `+q.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=X.text):Q.push(q);continue}if(J){let X="Infinite loop on byte: "+J.charCodeAt(0);if(this.options.silent){console.error(X);break}else throw Error(X)}}return this.state.top=!0,Q}inline(J,Q=[]){return this.inlineQueue.push({src:J,tokens:Q}),Q}inlineTokens(J,Q=[]){this.tokenizer.lexer=this;let Y=J,q=null;if(this.tokens.links){let _=Object.keys(this.tokens.links);if(_.length>0)for(;(q=this.tokenizer.rules.inline.reflinkSearch.exec(Y))!==null;)_.includes(q[0].slice(q[0].lastIndexOf("[")+1,-1))&&(Y=Y.slice(0,q.index)+"["+"a".repeat(q[0].length-2)+"]"+Y.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(q=this.tokenizer.rules.inline.anyPunctuation.exec(Y))!==null;)Y=Y.slice(0,q.index)+"++"+Y.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);let G;for(;(q=this.tokenizer.rules.inline.blockSkip.exec(Y))!==null;)G=q[2]?q[2].length:0,Y=Y.slice(0,q.index+G)+"["+"a".repeat(q[0].length-G-2)+"]"+Y.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);Y=this.options.hooks?.emStrongMask?.call({lexer:this},Y)??Y;let X=!1,H="";for(;J;){X||(H=""),X=!1;let _;if(this.options.extensions?.inline?.some((U)=>(_=U.call({lexer:this},J,Q))?(J=J.substring(_.raw.length),Q.push(_),!0):!1))continue;if(_=this.tokenizer.escape(J)){J=J.substring(_.raw.length),Q.push(_);continue}if(_=this.tokenizer.tag(J)){J=J.substring(_.raw.length),Q.push(_);continue}if(_=this.tokenizer.link(J)){J=J.substring(_.raw.length),Q.push(_);continue}if(_=this.tokenizer.reflink(J,this.tokens.links)){J=J.substring(_.raw.length);let U=Q.at(-1);_.type==="text"&&U?.type==="text"?(U.raw+=_.raw,U.text+=_.text):Q.push(_);continue}if(_=this.tokenizer.emStrong(J,Y,H)){J=J.substring(_.raw.length),Q.push(_);continue}if(_=this.tokenizer.codespan(J)){J=J.substring(_.raw.length),Q.push(_);continue}if(_=this.tokenizer.br(J)){J=J.substring(_.raw.length),Q.push(_);continue}if(_=this.tokenizer.del(J,Y,H)){J=J.substring(_.raw.length),Q.push(_);continue}if(_=this.tokenizer.autolink(J)){J=J.substring(_.raw.length),Q.push(_);continue}if(!this.state.inLink&&(_=this.tokenizer.url(J))){J=J.substring(_.raw.length),Q.push(_);continue}let W=J;if(this.options.extensions?.startInline){let U=1/0,B=J.slice(1),z;this.options.extensions.startInline.forEach((K)=>{z=K.call({lexer:this},B),typeof z=="number"&&z>=0&&(U=Math.min(U,z))}),U<1/0&&U>=0&&(W=J.substring(0,U+1))}if(_=this.tokenizer.inlineText(W)){J=J.substring(_.raw.length),_.raw.slice(-1)!=="_"&&(H=_.raw.slice(-1)),X=!0;let U=Q.at(-1);U?.type==="text"?(U.raw+=_.raw,U.text+=_.text):Q.push(_);continue}if(J){let U="Infinite loop on byte: "+J.charCodeAt(0);if(this.options.silent){console.error(U);break}else throw Error(U)}}return Q}},g2=class{options;parser;constructor($){this.options=$||s0}space($){return""}code({text:$,lang:J,escaped:Q}){let Y=(J||"").match(I$.notSpaceStart)?.[0],q=$.replace(I$.endingNewline,"")+`
51
+ `;return Y?'<pre><code class="language-'+J0(Y)+'">'+(Q?q:J0(q,!0))+`</code></pre>
52
+ `:"<pre><code>"+(Q?q:J0(q,!0))+`</code></pre>
53
+ `}blockquote({tokens:$}){return`<blockquote>
54
+ ${this.parser.parse($)}</blockquote>
55
+ `}html({text:$}){return $}def($){return""}heading({tokens:$,depth:J}){return`<h${J}>${this.parser.parseInline($)}</h${J}>
56
+ `}hr($){return`<hr>
57
+ `}list($){let{ordered:J,start:Q}=$,Y="";for(let X=0;X<$.items.length;X++){let H=$.items[X];Y+=this.listitem(H)}let q=J?"ol":"ul",G=J&&Q!==1?' start="'+Q+'"':"";return"<"+q+G+`>
58
+ `+Y+"</"+q+`>
59
+ `}listitem($){return`<li>${this.parser.parse($.tokens)}</li>
60
+ `}checkbox({checked:$}){return"<input "+($?'checked="" ':"")+'disabled="" type="checkbox"> '}paragraph({tokens:$}){return`<p>${this.parser.parseInline($)}</p>
61
+ `}table($){let J="",Q="";for(let q=0;q<$.header.length;q++)Q+=this.tablecell($.header[q]);J+=this.tablerow({text:Q});let Y="";for(let q=0;q<$.rows.length;q++){let G=$.rows[q];Q="";for(let X=0;X<G.length;X++)Q+=this.tablecell(G[X]);Y+=this.tablerow({text:Q})}return Y&&(Y=`<tbody>${Y}</tbody>`),`<table>
52
62
  <thead>
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(`
62
- `).join(`
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(`![screenshot](${l})`)}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)=>`![${n}](/api/uploads/${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
- `).slice(0,3).join(`
71
- `)+(k.content.split(`
72
- `).length>3?`
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
- `).slice(0,3).join(`
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(`
63
+ `+J+`</thead>
64
+ `+Y+`</table>
65
+ `}tablerow({text:$}){return`<tr>
66
+ ${$}</tr>
67
+ `}tablecell($){let J=this.parser.parseInline($.tokens),Q=$.header?"th":"td";return($.align?`<${Q} align="${$.align}">`:`<${Q}>`)+J+`</${Q}>
68
+ `}strong({tokens:$}){return`<strong>${this.parser.parseInline($)}</strong>`}em({tokens:$}){return`<em>${this.parser.parseInline($)}</em>`}codespan({text:$}){return`<code>${J0($,!0)}</code>`}br($){return"<br>"}del({tokens:$}){return`<del>${this.parser.parseInline($)}</del>`}link({href:$,title:J,tokens:Q}){let Y=this.parser.parseInline(Q),q=$5($);if(q===null)return Y;$=q;let G='<a href="'+$+'"';return J&&(G+=' title="'+J0(J)+'"'),G+=">"+Y+"</a>",G}image({href:$,title:J,text:Q,tokens:Y}){Y&&(Q=this.parser.parseInline(Y,this.parser.textRenderer));let q=$5($);if(q===null)return J0(Q);$=q;let G=`<img src="${$}" alt="${J0(Q)}"`;return J&&(G+=` title="${J0(J)}"`),G+=">",G}text($){return"tokens"in $&&$.tokens?this.parser.parseInline($.tokens):("escaped"in $)&&$.escaped?$.text:J0($.text)}},c4=class{strong({text:$}){return $}em({text:$}){return $}codespan({text:$}){return $}del({text:$}){return $}html({text:$}){return $}text({text:$}){return $}link({text:$}){return""+$}image({text:$}){return""+$}br(){return""}checkbox({raw:$}){return $}},c$=class ${options;renderer;textRenderer;constructor(J){this.options=J||s0,this.options.renderer=this.options.renderer||new g2,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new c4}static parse(J,Q){return new $(Q).parse(J)}static parseInline(J,Q){return new $(Q).parseInline(J)}parse(J){this.renderer.parser=this;let Q="";for(let Y=0;Y<J.length;Y++){let q=J[Y];if(this.options.extensions?.renderers?.[q.type]){let X=q,H=this.options.extensions.renderers[X.type].call({parser:this},X);if(H!==!1||!["space","hr","heading","code","table","blockquote","list","html","def","paragraph","text"].includes(X.type)){Q+=H||"";continue}}let G=q;switch(G.type){case"space":{Q+=this.renderer.space(G);break}case"hr":{Q+=this.renderer.hr(G);break}case"heading":{Q+=this.renderer.heading(G);break}case"code":{Q+=this.renderer.code(G);break}case"table":{Q+=this.renderer.table(G);break}case"blockquote":{Q+=this.renderer.blockquote(G);break}case"list":{Q+=this.renderer.list(G);break}case"checkbox":{Q+=this.renderer.checkbox(G);break}case"html":{Q+=this.renderer.html(G);break}case"def":{Q+=this.renderer.def(G);break}case"paragraph":{Q+=this.renderer.paragraph(G);break}case"text":{Q+=this.renderer.text(G);break}default:{let X='Token with "'+G.type+'" type was not found.';if(this.options.silent)return console.error(X),"";throw Error(X)}}}return Q}parseInline(J,Q=this.renderer){this.renderer.parser=this;let Y="";for(let q=0;q<J.length;q++){let G=J[q];if(this.options.extensions?.renderers?.[G.type]){let H=this.options.extensions.renderers[G.type].call({parser:this},G);if(H!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(G.type)){Y+=H||"";continue}}let X=G;switch(X.type){case"escape":{Y+=Q.text(X);break}case"html":{Y+=Q.html(X);break}case"link":{Y+=Q.link(X);break}case"image":{Y+=Q.image(X);break}case"checkbox":{Y+=Q.checkbox(X);break}case"strong":{Y+=Q.strong(X);break}case"em":{Y+=Q.em(X);break}case"codespan":{Y+=Q.codespan(X);break}case"br":{Y+=Q.br(X);break}case"del":{Y+=Q.del(X);break}case"text":{Y+=Q.text(X);break}default:{let H='Token with "'+X.type+'" type was not found.';if(this.options.silent)return console.error(H),"";throw Error(H)}}}return Y}},$2=class{options;block;constructor($){this.options=$||s0}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens","emStrongMask"]);static passThroughHooksRespectAsync=new Set(["preprocess","postprocess","processAllTokens"]);preprocess($){return $}postprocess($){return $}processAllTokens($){return $}emStrongMask($){return $}provideLexer($=this.block){return $?p$.lex:p$.lexInline}provideParser($=this.block){return $?c$.parse:c$.parseInline}},OJ=class{defaults=f4();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=c$;Renderer=g2;TextRenderer=c4;Lexer=p$;Tokenizer=v2;Hooks=$2;constructor(...$){this.use(...$)}walkTokens($,J){let Q=[];for(let Y of $)switch(Q=Q.concat(J.call(this,Y)),Y.type){case"table":{let q=Y;for(let G of q.header)Q=Q.concat(this.walkTokens(G.tokens,J));for(let G of q.rows)for(let X of G)Q=Q.concat(this.walkTokens(X.tokens,J));break}case"list":{let q=Y;Q=Q.concat(this.walkTokens(q.items,J));break}default:{let q=Y;this.defaults.extensions?.childTokens?.[q.type]?this.defaults.extensions.childTokens[q.type].forEach((G)=>{let X=q[G].flat(1/0);Q=Q.concat(this.walkTokens(X,J))}):q.tokens&&(Q=Q.concat(this.walkTokens(q.tokens,J)))}}return Q}use(...$){let J=this.defaults.extensions||{renderers:{},childTokens:{}};return $.forEach((Q)=>{let Y={...Q};if(Y.async=this.defaults.async||Y.async||!1,Q.extensions&&(Q.extensions.forEach((q)=>{if(!q.name)throw Error("extension name required");if("renderer"in q){let G=J.renderers[q.name];G?J.renderers[q.name]=function(...X){let H=q.renderer.apply(this,X);return H===!1&&(H=G.apply(this,X)),H}:J.renderers[q.name]=q.renderer}if("tokenizer"in q){if(!q.level||q.level!=="block"&&q.level!=="inline")throw Error("extension level must be 'block' or 'inline'");let G=J[q.level];G?G.unshift(q.tokenizer):J[q.level]=[q.tokenizer],q.start&&(q.level==="block"?J.startBlock?J.startBlock.push(q.start):J.startBlock=[q.start]:q.level==="inline"&&(J.startInline?J.startInline.push(q.start):J.startInline=[q.start]))}"childTokens"in q&&q.childTokens&&(J.childTokens[q.name]=q.childTokens)}),Y.extensions=J),Q.renderer){let q=this.defaults.renderer||new g2(this.defaults);for(let G in Q.renderer){if(!(G in q))throw Error(`renderer '${G}' does not exist`);if(["options","parser"].includes(G))continue;let X=G,H=Q.renderer[X],_=q[X];q[X]=(...W)=>{let U=H.apply(q,W);return U===!1&&(U=_.apply(q,W)),U||""}}Y.renderer=q}if(Q.tokenizer){let q=this.defaults.tokenizer||new v2(this.defaults);for(let G in Q.tokenizer){if(!(G in q))throw Error(`tokenizer '${G}' does not exist`);if(["options","rules","lexer"].includes(G))continue;let X=G,H=Q.tokenizer[X],_=q[X];q[X]=(...W)=>{let U=H.apply(q,W);return U===!1&&(U=_.apply(q,W)),U}}Y.tokenizer=q}if(Q.hooks){let q=this.defaults.hooks||new $2;for(let G in Q.hooks){if(!(G in q))throw Error(`hook '${G}' does not exist`);if(["options","block"].includes(G))continue;let X=G,H=Q.hooks[X],_=q[X];$2.passThroughHooks.has(G)?q[X]=(W)=>{if(this.defaults.async&&$2.passThroughHooksRespectAsync.has(G))return(async()=>{let B=await H.call(q,W);return _.call(q,B)})();let U=H.call(q,W);return _.call(q,U)}:q[X]=(...W)=>{if(this.defaults.async)return(async()=>{let B=await H.apply(q,W);return B===!1&&(B=await _.apply(q,W)),B})();let U=H.apply(q,W);return U===!1&&(U=_.apply(q,W)),U}}Y.hooks=q}if(Q.walkTokens){let q=this.defaults.walkTokens,G=Q.walkTokens;Y.walkTokens=function(X){let H=[];return H.push(G.call(this,X)),q&&(H=H.concat(q.call(this,X))),H}}this.defaults={...this.defaults,...Y}}),this}setOptions($){return this.defaults={...this.defaults,...$},this}lexer($,J){return p$.lex($,J??this.defaults)}parser($,J){return c$.parse($,J??this.defaults)}parseMarkdown($){return(J,Q)=>{let Y={...Q},q={...this.defaults,...Y},G=this.onError(!!q.silent,!!q.async);if(this.defaults.async===!0&&Y.async===!1)return G(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 J>"u"||J===null)return G(Error("marked(): input parameter is undefined or null"));if(typeof J!="string")return G(Error("marked(): input parameter is of type "+Object.prototype.toString.call(J)+", string expected"));if(q.hooks&&(q.hooks.options=q,q.hooks.block=$),q.async)return(async()=>{let X=q.hooks?await q.hooks.preprocess(J):J,H=await(q.hooks?await q.hooks.provideLexer($):$?p$.lex:p$.lexInline)(X,q),_=q.hooks?await q.hooks.processAllTokens(H):H;q.walkTokens&&await Promise.all(this.walkTokens(_,q.walkTokens));let W=await(q.hooks?await q.hooks.provideParser($):$?c$.parse:c$.parseInline)(_,q);return q.hooks?await q.hooks.postprocess(W):W})().catch(G);try{q.hooks&&(J=q.hooks.preprocess(J));let X=(q.hooks?q.hooks.provideLexer($):$?p$.lex:p$.lexInline)(J,q);q.hooks&&(X=q.hooks.processAllTokens(X)),q.walkTokens&&this.walkTokens(X,q.walkTokens);let H=(q.hooks?q.hooks.provideParser($):$?c$.parse:c$.parseInline)(X,q);return q.hooks&&(H=q.hooks.postprocess(H)),H}catch(X){return G(X)}}}onError($,J){return(Q)=>{if(Q.message+=`
69
+ Please report this to https://github.com/markedjs/marked.`,$){let Y="<p>An error occurred:</p><pre>"+J0(Q.message+"",!0)+"</pre>";return J?Promise.resolve(Y):Y}if(J)return Promise.reject(Q);throw Q}}},n0=new OJ;function q$($,J){return n0.parse($,J)}q$.options=q$.setOptions=function($){return n0.setOptions($),q$.defaults=n0.defaults,q5(q$.defaults),q$};q$.getDefaults=f4;q$.defaults=s0;q$.use=function(...$){return n0.use(...$),q$.defaults=n0.defaults,q5(q$.defaults),q$};q$.walkTokens=function($,J){return n0.walkTokens($,J)};q$.parseInline=n0.parseInline;q$.Parser=c$;q$.parser=c$.parse;q$.Renderer=g2;q$.TextRenderer=c4;q$.Lexer=p$;q$.lexer=p$.lex;q$.Tokenizer=v2;q$.Hooks=$2;q$.parse=q$;var{options:FX,setOptions:AX,use:SX,walkTokens:PX,parseInline:wX}=q$;var TX=c$.parse,jX=p$.lex;import{useEffect as z5,useMemo as l4,useRef as LJ,useState as Q2}from"react";import{jsxDEV as P$}from"react/jsx-dev-runtime";function d4({open:$,onClose:J,onSubmit:Q,includedRemoteIds:Y,onToggleRemoteId:q}){let{annotations:G,generalNote:X,submittableResponses:H,feedbackEntries:_}=i0(),[W,U]=Q2(""),[B,z]=Q2(!1),[K,N]=Q2(!1),[P,M]=Q2(null),T=LJ(null),[O,F]=Q2(!1),w=l4(()=>G.filter((y)=>y.source==="remote"),[G]);if($&&!O)z(!1),N(!1),M(null);if(!$&&O)z(!1),N(!1),M(null);if($!==O)F($);let S=l4(()=>a1(G,X,H,_,Y),[G,X,H,_,Y]),j=B?W:S;if(z5(()=>{if($&&K&&T.current)T.current.focus()},[$,K]),z5(()=>{if(!$)return;let y=(I)=>{if(I.key==="Escape")J()};return window.addEventListener("keydown",y),()=>window.removeEventListener("keydown",y)},[$,J]),!$)return null;let R=j.trim().length>0;return P$("div",{className:"fixed inset-0 z-50 bg-black/50 backdrop-blur-sm flex items-center justify-center p-8",onClick:J,children:P$("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:(y)=>y.stopPropagation(),children:[P$("div",{className:"flex items-center justify-between px-5 py-3 border-b border-border-subtle flex-shrink-0",children:[P$("div",{className:"flex items-center gap-3",children:[P$("span",{className:"text-[13px] font-medium text-text-primary font-body",children:"Response preview"},void 0,!1,void 0,this),B&&P$("button",{onClick:()=>{z(!1),N(!1)},className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body",children:"Reset"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),P$("div",{className:"flex items-center gap-2",children:[P$("div",{className:"flex items-center bg-bg-base rounded-md p-0.5",children:[P$("button",{onClick:()=>N(!1),className:`px-2.5 py-1 rounded text-[11px] font-body font-medium transition-colors ${!K?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Preview"},void 0,!1,void 0,this),P$("button",{onClick:()=>N(!0),className:`px-2.5 py-1 rounded text-[11px] font-body font-medium transition-colors ${K?"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),P$("button",{onClick:J,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),K?P$("textarea",{ref:T,value:j,onChange:(y)=>{U(y.currentTarget.value),z(!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):P$("div",{className:"flex-1 overflow-y-auto p-5",children:P$(h2,{text:j},void 0,!1,void 0,this)},void 0,!1,void 0,this),w.length>0&&P$("div",{className:"px-5 py-2 border-t border-border-subtle flex-shrink-0",children:P$("span",{className:"text-[12px] text-text-secondary font-body",children:["Reviewer feedback: ",Y.size,"/",w.length," included"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),P&&P$("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:[P$("span",{children:P},void 0,!1,void 0,this),P$("button",{onClick:()=>{M(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),P$("div",{className:"flex justify-end gap-2 px-5 py-3 border-t border-border-subtle flex-shrink-0",children:[P$("button",{onClick:J,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),P$("button",{onClick:()=>{let y=n1(H,_);if(y.length>0){M(`Please answer: ${y.join(", ")}`);return}M(null),Q(j)},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 FJ=/!\[([^\]]*)\]\((\/tmp\/agent-canvas\/uploads\/([^)]+))\)/g;function AJ($){return $.replace(FJ,(J,Q,Y,q)=>`![${Q}](/api/uploads/${q})`)}function h2({text:$}){let J=l4(()=>q$.parse(AJ($),{async:!1}),[$]);return P$("div",{className:"prose-canvas font-body text-body text-text-primary leading-relaxed",dangerouslySetInnerHTML:{__html:J}},void 0,!1,void 0,this)}import{jsxDEV as g,Fragment as u2}from"react/jsx-dev-runtime";function p2({onSubmit:$,collapseButton:J}){let{isReadOnly:Q,selectedRevision:Y,currentRevision:q,revisions:G,agentWatching:X}=i4(E$),H=i4(SJ),_=G.find((z)=>z.revision===Y),W=Q&&Y===q,U=!!_?.feedbackConsumed,B=_?.label||`Round ${Y}`;if(Q)return g(TJ,{sessionId:H,revision:Y,label:B,waitingForUpdate:W,feedbackConsumed:U,agentWatching:X,collapseButton:J},void 0,!1,void 0,this);return g(bJ,{onSubmit:$,agentWatching:X,collapseButton:J},void 0,!1,void 0,this)}function wJ({sessionId:$,revision:J,label:Q,waitingForUpdate:Y,feedbackConsumed:q,agentWatching:G,collapseButton:X}){let _=U0().isShared;return g("div",{className:"flex flex-col h-full",children:[g("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[g("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:Y?"Feedback sent":`Feedback — ${Q}`},void 0,!1,void 0,this),X]},void 0,!0,void 0,this),Y&&!_&&g(O5,{feedbackConsumed:q,agentWatching:G},void 0,!1,void 0,this),g(L5,{sessionId:$,revision:J},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function O5({feedbackConsumed:$,agentWatching:J}){if($)return g("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:[g("span",{className:"w-2 h-2 rounded-full bg-accent-green animate-pulse"},void 0,!1,void 0,this),g("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(J)return g("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:[g("span",{className:"w-2 h-2 rounded-full bg-accent-blue animate-pulse"},void 0,!1,void 0,this),g("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 g("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:[g("span",{className:"w-2 h-2 rounded-full bg-accent-amber"},void 0,!1,void 0,this),g("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 TJ({sessionId:$,revision:J,label:Q,waitingForUpdate:Y,feedbackConsumed:q,agentWatching:G,collapseButton:X}){let{annotations:H,generalNote:_}=i0(),W=H.length>0||_.trim().length>0,[U,B]=j1("feedback");if(!W)return g(wJ,{sessionId:$,revision:J,label:Q,waitingForUpdate:Y,feedbackConsumed:q,agentWatching:G,collapseButton:X},void 0,!1,void 0,this);return g("div",{className:"flex flex-col h-full",children:[g("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[g("div",{className:"flex items-center gap-1 bg-bg-input rounded-md p-0.5",children:[g("button",{onClick:()=>B("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),g("button",{onClick:()=>B("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",g("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:H.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),Y&&g(O5,{feedbackConsumed:q,agentWatching:G},void 0,!1,void 0,this),U==="feedback"?g(L5,{sessionId:$,revision:J},void 0,!1,void 0,this):g(u2,{children:[g("div",{className:"flex-1 overflow-y-auto",children:g(F5,{annotations:H,readOnly:!0},void 0,!1,void 0,this)},void 0,!1,void 0,this),_.trim()&&g("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:g("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)]},void 0,!0,void 0,this)}function L5({sessionId:$,revision:J}){let Q=U0(),[Y,q]=j1(null),[G,X]=j1(!0);return M5(()=>{if(X(!0),!Q.fsAvailable){q(null),X(!1);return}fetch(`/api/session/${$}/revision/${J}/feedback`).then((H)=>H.json()).then((H)=>{q(r3.parse(H).feedback||null),X(!1)}).catch(()=>{q(null),X(!1)})},[$,J]),g("div",{className:"flex-1 overflow-y-auto px-4",children:G?g("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"Loading..."},void 0,!1,void 0,this):Y?g(h2,{text:Y},void 0,!1,void 0,this):g("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 jJ($){let J=$.filter((X)=>X.filePath===u$),Q=$.filter((X)=>!X.filePath),Y=$.filter((X)=>u0(X)!==void 0),q={};for(let X of Y){let H=u0(X);if(!H)continue;let _=q[H];if(_)_.push(X);else q[H]=[X]}let G=[J,Q,Y].filter((X)=>X.length>0).length>1;return{response:J,plan:Q,fileGroups:q,hasMultipleGroups:G}}function N5({children:$}){return g("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body px-3 mb-1 mt-1",children:$},void 0,!1,void 0,this)}function F5({annotations:$,readOnly:J,includedRemoteIds:Q,onToggleRemoteId:Y}){let{setActiveView:q}=i4($0),{response:G,plan:X,fileGroups:H,hasMultipleGroups:_}=jJ($),W=r4((z)=>{let K=u0(z);if(!K)return;q({type:"file",path:K}),setTimeout(()=>{let N=s1(z);if(N)N.scrollIntoView({behavior:"smooth",block:"center"})},150)},[q]),U=r4((z)=>y4(z,q),[q]),B={readOnly:J,onSelect:W,onReveal:U,includedRemoteIds:Q,onToggleRemoteId:Y};return g(u2,{children:[G.length>0&&g(u2,{children:[_&&g(N5,{children:"Agent Response"},void 0,!1,void 0,this),g(i1,{annotations:G,...B},void 0,!1,void 0,this)]},void 0,!0,void 0,this),X.length>0&&g(u2,{children:[_&&g(N5,{children:"Canvas"},void 0,!1,void 0,this),g(i1,{annotations:X,...B},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Object.entries(H).map(([z,K])=>g("div",{children:[g("button",{onClick:()=>q({type:"file",path:z}),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:z,children:[g(C0,{name:z.split("/").pop()||z,type:"file"},void 0,!1,void 0,this),g("span",{className:"truncate",children:z},void 0,!1,void 0,this)]},void 0,!0,void 0,this),g(i1,{annotations:K,...B},void 0,!1,void 0,this)]},z,!0,void 0,this))]},void 0,!0,void 0,this)}function bJ({onSubmit:$,agentWatching:J,collapseButton:Q}){let Y=U0(),[q,G]=j1(!1),{annotations:X,generalNote:H,submittableResponses:_,feedbackEntries:W}=i0(),U=PJ(()=>X.filter((w)=>w.source==="remote"),[X]),[B,z]=j1(()=>new Set);M5(()=>{if(U.length===0)return;z((w)=>{let S=new Set(w);for(let j of U)S.add(j.id);return S.size===w.size?w:S})},[U]);let K=r4((w)=>{z((S)=>{let j=new Set(S);if(j.has(w))j.delete(w);else j.add(w);return j})},[]),N=Array.from(_.values()).some(k2),P=W.size>0,M=X.length>0||H.trim().length>0||N||P,[T,O]=j1(null),F=()=>{let w=a1(X,H,_,W,B);$(w)};return g("div",{className:"flex flex-col h-full",children:[g("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[g("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body flex items-center gap-2",children:["Annotations",X.length>0&&g("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:X.length},void 0,!1,void 0,this),!Y.isShared&&g("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${J?"bg-accent-green":"bg-accent-amber"}`,title:J?"Agent connected":"Agent disconnected"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Q]},void 0,!0,void 0,this),g("div",{className:"flex-1 overflow-y-auto",children:[X.length===0&&g("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),g(F5,{annotations:X,includedRemoteIds:B,onToggleRemoteId:K},void 0,!1,void 0,this)]},void 0,!0,void 0,this),g(O4,{hasContent:M,onSubmit:()=>{let w=n1(_,W);if(w.length>0){O(`Please answer: ${w.join(", ")}`);return}O(null),F()},onSubmitEmpty:()=>$("No feedback — looks good."),notice:T&&g("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:[g("span",{children:T},void 0,!1,void 0,this),g("button",{onClick:()=>{O(null),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),secondaryAction:g("button",{onClick:()=>G(!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),g(d4,{open:q,onClose:()=>G(!1),onSubmit:$,includedRemoteIds:B,onToggleRemoteId:K},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{useFeedback as DH}from"#canvas/runtime";import $G from"react";import{jsxDEV as QG}from"react/jsx-dev-runtime";q$.setOptions({gfm:!0,breaks:!1});import{jsxDEV as GG}from"react/jsx-dev-runtime";import{jsxDEV as WG}from"react/jsx-dev-runtime";import{useAnnotations as OG,useResponseRegistration as LG}from"#canvas/runtime";import{useEffect as AG,useMemo as SG,useRef as PG,useState as wG}from"react";import{jsxDEV as zG}from"react/jsx-dev-runtime";import{jsxDEV as bG}from"react/jsx-dev-runtime";import{useEffect as IG,useRef as DG}from"react";import{jsxDEV as EG}from"react/jsx-dev-runtime";import{jsxDEV as hG}from"react/jsx-dev-runtime";import{ActiveViewCtx as cG,SessionContext as lG}from"#canvas/runtime";import{useContext as rG,useEffect as iG,useRef as oG,useState as aG}from"react";import{jsxDEV as eG}from"react/jsx-dev-runtime";import{SessionContext as Q_}from"#canvas/runtime";import{useContext as Y_,useState as X_}from"react";import{jsxDEV as __}from"react/jsx-dev-runtime";import{useMemo as K_}from"react";import{jsxDEV as N_}from"react/jsx-dev-runtime";q$.setOptions({gfm:!0,breaks:!1});import{useAnnotations as F_,useCanvasFile as A_}from"#canvas/runtime";import{useCallback as T_,useEffect as j_,useRef as b_,useState as V_}from"react";import C_ from"react-dom";import{jsxDEV as D_,Fragment as k_}from"react/jsx-dev-runtime";import{jsxDEV as v_}from"react/jsx-dev-runtime";import{jsxDEV as x_}from"react/jsx-dev-runtime";import{useState as c_}from"react";import{jsxDEV as r_}from"react/jsx-dev-runtime";import{jsxDEV as a_}from"react/jsx-dev-runtime";import{jsxDEV as e_}from"react/jsx-dev-runtime";import{useAnnotations as QH,useResponseRegistration as qH}from"#canvas/runtime";import{useRef as GH,useState as _H}from"react";import{jsxDEV as UH}from"react/jsx-dev-runtime";import{CanvasFileCtx as IJ,SessionContext as DJ}from"#canvas/runtime";import c2,{useContext as A5,useEffect as R0,useMemo as Y2,useRef as kJ,useState as Q0}from"react";import{createPortal as yJ}from"react-dom";import{createContext as RJ}from"react";var q2=RJ(()=>{});import{jsxDEV as N$,Fragment as gJ}from"react/jsx-dev-runtime";class S5 extends c2.Component{state={error:null};static getDerivedStateFromError($){return{error:$}}componentDidCatch($,J){this.props.reportError({revision:this.props.revision,filename:this.props.filename,message:$.message,...$.stack?{stack:$.stack}:{},...J.componentStack?{componentStack:J.componentStack}:{}})}render(){if(!this.state.error)return this.props.children;return N$(P5,{message:this.state.error.message},void 0,!1,void 0,this)}}function P5({message:$}){return N$("div",{className:"bg-accent-red-muted rounded-lg p-5",children:[N$("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Canvas render failed"},void 0,!1,void 0,this),N$("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:$},void 0,!1,void 0,this),N$("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 b1({revision:$,filename:J}){let Q=A5(DJ),Y=U0(),q=A5(q2),[G,X]=Q0(null),[H,_]=Q0(null),[W,U]=Q0(!0),B=kJ(null),{annotations:z,addAnnotationWithId:K,removeAnnotation:N,updateAnnotation:P,addAnnotationImage:M,removeAnnotationImage:T,activeAnnotationId:O,setActiveAnnotationId:F,registerCanvasRendered:w}=i0(),S=Y2(()=>z.filter((b)=>!b.filePath&&(!b.canvasFile||b.canvasFile===J)),[z,J]),[j,R]=Q0(null),[y,I]=Q0(null),[Z,f]=Q0(null),[u,o]=Q0(null),[K$,l]=Q0(!1);R0(()=>{U(!0),_(null),o(null),Y.loadCanvasModule(J,$).then((b)=>{X(()=>b.default),U(!1)}).catch((b)=>{let m=b instanceof Error?b:Error(String(b));_(m.message),U(!1),q({revision:$,filename:J,message:m.message,...m.stack?{stack:m.stack}:{}})})},[Q,$,J,q]),R0(()=>{if(G)w(J)},[G,J,w]);let W$=document.getElementById("plan-scroll-container"),{popovers:U$,isPopoverOpen:z$}=V0({containerRef:B,restoreKey:G,restoreAnnotations:S,extractContext:(b)=>L0(b,B.current),canvasFile:J,scrollContainer:W$}),{popovers:$$,isDrawing:X$,isPopoverOpen:L$}=T4({containerRef:B,restoreKey:G,canvasFile:J,scrollContainer:W$}),a=z$||L$,d=Y2(()=>{let b=new Map;for(let m of S)if(m.snippet.startsWith("["))b.set(m.snippet,m.id);return b},[S]);R0(()=>{let b=B.current;if(!b)return;let m=(E)=>{if(Z||a||X$)return;let x=E.target;if(x.closest("[data-block-comment-btn]"))return;l(!1);let r=x.closest(Q1);if(r&&b.contains(r)){let w$=t0(b).indexOf(r);o(w$>=0?w$:null)}else o(null);let M$=x.closest(F0);if(M$&&b.contains(M$)){I(M$);let F$=o$(M$),w$=F$?d.get(F$):void 0;if(w$&&w$!==O)F(w$)}else I(null)},G$=(E)=>{if(Z||a)return;if(E.relatedTarget?.closest("[data-block-comment-btn]"))return;I(null),F(null)};return b.addEventListener("mousemove",m),b.addEventListener("mouseleave",G$),()=>{b.removeEventListener("mousemove",m),b.removeEventListener("mouseleave",G$)}},[G,Z,a,X$,d,O]),R0(()=>{let b=(m)=>{let G$=m.target.tagName;if(G$==="INPUT"||G$==="TEXTAREA"||m.target.isContentEditable)return;if(Z||a)return;let E=B.current;if(!E)return;if(m.key==="ArrowDown"){m.preventDefault(),l(!0);let x=t0(E);if(x.length===0)return;o((r)=>{if(r===null)return 0;return Math.min(r+1,x.length-1)})}else if(m.key==="ArrowUp"){m.preventDefault(),l(!0);let x=t0(E);if(x.length===0)return;o((r)=>{if(r===null)return x.length-1;return Math.max(r-1,0)})}else if(m.key==="a"||m.key==="A"){if(u===null||!E)return;let r=t0(E)[u];if(!r)return;if(!r.matches(F0))return;m.preventDefault();let M$=o$(r);if(!M$)return;let F$=d.get(M$);if(F$)F(F$),f({anchorEl:r,snippet:M$,annId:F$});else f({anchorEl:r,snippet:M$})}else if(m.key===" "||m.key==="Enter"){if(u===null)return;let r=t0(E)[u];if(!r)return;let M$=r.getAttribute("data-md");if(M$==="choice-option"||M$==="multichoice-option")m.preventDefault(),r.dispatchEvent(new CustomEvent("kb-select",{bubbles:!0}));else if(M$==="userinput"){m.preventDefault();let F$=r.querySelector("textarea");if(F$){F$.focus();let w$=(r$)=>{if(r$.key==="Escape")r$.preventDefault(),F$.blur(),l(!0)};F$.addEventListener("keydown",w$),F$.addEventListener("blur",()=>F$.removeEventListener("keydown",w$),{once:!0})}}else if(M$==="rangeinput"){m.preventDefault();let F$=r.querySelector("input[type='range']");if(F$){F$.focus();let w$=(r$)=>{if(r$.key==="Escape"||r$.key==="ArrowUp"||r$.key==="ArrowDown")r$.preventDefault(),F$.blur(),l(!0)};F$.addEventListener("keydown",w$),F$.addEventListener("blur",()=>F$.removeEventListener("keydown",w$),{once:!0})}}}else if(m.key==="Escape")o(null),l(!1),F(null)};return document.addEventListener("keydown",b),()=>document.removeEventListener("keydown",b)},[u,Z,a,d]),R0(()=>{let b=B.current;if(!b||u===null||!K$)return;let G$=t0(b)[u];if(!G$)return;G$.style.outline="2px solid var(--color-accent-blue)",G$.style.outlineOffset="-2px",G$.style.borderRadius="8px",G$.scrollIntoView({block:"nearest",behavior:"smooth"});let E=o$(G$),x=E?d.get(E):void 0;if(x)F(x);return()=>{G$.style.outline="",G$.style.outlineOffset="",G$.style.borderRadius=""}},[u,K$,d]);let J$=Y2(()=>G?N$(G,{},void 0,!1,void 0,this):null,[G]);if(W)return N$("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(H)return N$(P5,{message:H},void 0,!1,void 0,this);if(!G)return N$("div",{className:"text-text-tertiary text-center py-8 font-body text-body",children:"No canvas loaded"},void 0,!1,void 0,this);return N$(IJ.Provider,{value:J,children:[N$("div",{ref:B,className:"plan-content plan-updated","data-canvas-file":J,children:N$(S5,{revision:$,filename:J,reportError:q,children:J$},`${$}:${J}`,!1,void 0,this)},void 0,!1,void 0,this),j&&N$(vJ,{note:j.note,onSave:(b)=>{P(j.id,b),R(null)},onCancel:()=>R(null)},void 0,!1,void 0,this),U$,$$,N$(EJ,{containerRef:B,hoveredBlock:y,focusedBlockIndex:u,blockPopover:Z,blockAnnotationMap:d,activeAnnotationId:O,onOpen:(b,m,G$)=>{if(G$)F(G$),f({anchorEl:b,snippet:m,annId:G$});else f({anchorEl:b,snippet:m})}},void 0,!1,void 0,this),Z&&!Z.annId&&N$(t$,{anchorEl:Z.anchorEl,scrollContainer:W$,snippet:Z.snippet,truncateAt:80,onAdd:(b,m)=>{let G$=y$();K(G$,Z.snippet,b,void 0,void 0,m,J),f(null)},onCancel:()=>f(null)},void 0,!1,void 0,this),Z?.annId&&(()=>{let b=S.find((m)=>m.id===Z.annId);if(!b)return null;return N$(l0,{anchorEl:Z.anchorEl,scrollContainer:W$,initialNote:b.note,initialImages:b.images,onUpdate:(m,G$)=>{P(Z.annId,m);let E=b.images||[];for(let x of G$)if(!E.includes(x))M(Z.annId,x);for(let x of E)if(!G$.includes(x))T(Z.annId,x)},onDelete:()=>{N(Z.annId),F(null),f(null)},onClose:()=>f(null)},void 0,!1,void 0,this)})()]},void 0,!0,void 0,this)}function t0($){return Array.from($.querySelectorAll(Q1))}function EJ({containerRef:$,hoveredBlock:J,focusedBlockIndex:Q,blockPopover:Y,blockAnnotationMap:q,activeAnnotationId:G,onOpen:X}){let[H,_]=Q0([]);R0(()=>{let K=$.current;if(!K||q.size===0){_([]);return}let N=[];for(let P of K.querySelectorAll(F0)){let M=o$(P);if(M&&q.has(M))N.push(P)}_(N)},[q,$.current]);let[W,U]=Q0(null);R0(()=>{if(!G||!$.current){U(null);return}for(let K of $.current.querySelectorAll(Q1)){let N=o$(K);if(N&&q.get(N)===G){U(K);return}}U(null)},[G,q]),R0(()=>{if(!W)return;return W.style.boxShadow="inset 0 0 0 1.5px var(--color-highlight-bg)",W.style.borderRadius="8px",()=>{W.style.boxShadow="",W.style.borderRadius=""}},[W]);let B=Y2(()=>{if(Q===null||!$.current)return null;let K=t0($.current)[Q];if(!K)return null;return K.matches(F0)?K:null},[Q,$.current]),z=Y2(()=>{let K=new Set(H);if(J)K.add(J);if(B)K.add(B);if(Y?.anchorEl)K.add(Y.anchorEl);return Array.from(K)},[H,J,B,Y]);return N$(gJ,{children:z.map((K)=>N$(fJ,{block:K,isHovered:K===J||K===B||K===Y?.anchorEl,blockAnnotationMap:q,activeAnnotationId:G,onOpen:X},K.getAttribute("data-task-id")||K.getAttribute("data-md-title")||K.textContent?.slice(0,30)||"block",!1,void 0,this))},void 0,!1,void 0,this)}function fJ({block:$,isHovered:J,blockAnnotationMap:Q,activeAnnotationId:Y,onOpen:q}){let G=o$($);if(!G)return null;let X=Q.get(G),H=!!X;return yJ(N$("button",{"data-block-comment-btn":!0,onClick:(W)=>{W.stopPropagation(),q(W.currentTarget,G,X)},className:`absolute top-1 right-1 z-10 w-6 h-6 flex items-center justify-center rounded transition-all duration-150 ${H?X===Y?"text-accent-amber bg-accent-amber-muted":"text-accent-amber opacity-60 hover:opacity-100":J?"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:H?"Edit annotation":"Add annotation",children:N$("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:H?"currentColor":"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:N$("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),$)}function vJ({note:$,onSave:J,onCancel:Q}){let[Y,q]=c2.useState($),G=c2.useRef(null);return c2.useEffect(()=>{G.current?.focus(),G.current?.select()},[]),N$("div",{className:"fixed inset-0 z-50 bg-black/40 flex items-center justify-center",onClick:Q,children:N$("div",{className:"bg-bg-elevated border border-border-hover rounded-lg shadow-md p-4 w-80",onClick:(X)=>X.stopPropagation(),children:[N$("div",{className:"text-tiny uppercase tracking-widest text-text-tertiary font-body mb-2",children:"Edit annotation"},void 0,!1,void 0,this),N$("textarea",{ref:G,value:Y,onChange:(X)=>q(X.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:(X)=>{if(X.key==="Enter"&&(X.ctrlKey||X.metaKey))J(Y.trim());if(X.key==="Escape")Q()}},void 0,!1,void 0,this),N$("div",{className:"flex justify-end gap-2 mt-2",children:[N$("button",{onClick:Q,className:"text-meta text-text-tertiary font-body px-3 py-1",children:"Cancel"},void 0,!1,void 0,this),N$("button",{onClick:()=>J(Y.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 y0,{useCallback as Z1,useEffect as d$,useLayoutEffect as H7,useMemo as N6,useRef as X0,useState as O$}from"react";import{createRoot as W7}from"react-dom/client";var w5=A.object({shareId:A.string(),url:A.string(),revision:A.number(),createdAt:A.string(),ownerToken:A.string().optional(),expiresAt:A.string().optional(),lastFeedbackAt:A.string().optional(),encryptionKey:A.string().optional()}),mJ=A.object({revision:A.number(),label:A.string().optional(),canvasFiles:A.array(A.object({filename:A.string(),diffStats:A.object({added:A.number(),removed:A.number()}).optional()})),createdAt:A.string(),hasFeedback:A.boolean(),feedbackConsumed:A.boolean(),response:A.string().optional()}).passthrough(),T5=A.object({encryption:A.object({alg:A.literal("AES-GCM"),v:A.literal(1)}).optional(),origin:A.object({sessionId:A.string().optional(),label:A.string().optional(),revision:A.number().optional(),createdAt:A.string().optional()}).optional(),currentRevision:A.number().optional(),revisions:A.array(mJ).optional(),canvasFiles:A.array(A.string()).optional(),projectRoot:A.string().optional(),shares:A.array(w5).optional(),shareEnabled:A.boolean().optional()}).passthrough(),a4=A.object({entries:A.array(A.object({name:A.string(),type:A.enum(["file","dir"])}))}),xJ=A.object({id:A.string(),shareId:A.string(),revision:A.number(),submittedAt:A.string(),author:z4,annotations:A.array(N4.omit({source:!0,author:!0})),generalNote:A.string().optional()}),j5=A.object({entries:A.array(xJ)}),b5=A.union([A.object({ok:A.literal(!0),share:w5}),A.object({ok:A.literal(!1).optional(),error:A.string().optional()})]),V5=A.union([A.object({ok:A.literal(!0)}),A.object({ok:A.literal(!1).optional(),error:A.string().optional()})]);var Z5={alg:"AES-GCM",v:1};async function C5($){let J=uJ($);return crypto.subtle.importKey("raw",J,{name:"AES-GCM",length:256},!1,["encrypt","decrypt"])}async function I0($,J){let Q=crypto.getRandomValues(new Uint8Array(12)),Y=new TextEncoder().encode(J),q=await crypto.subtle.encrypt({name:"AES-GCM",iv:Q},$,Y),G=new Uint8Array(Q.byteLength+q.byteLength);return G.set(Q,0),G.set(new Uint8Array(q),Q.byteLength),hJ(G)}async function X2($,J){let Q=R5(J);if(Q.byteLength<28)throw Error("Ciphertext too short");let Y=Q.subarray(0,12),q=Q.subarray(12),G=await crypto.subtle.decrypt({name:"AES-GCM",iv:Y},$,q);return new TextDecoder().decode(G)}function hJ($){let J="",Q=32768;for(let Y=0;Y<$.byteLength;Y+=Q)J+=String.fromCharCode.apply(null,Array.from($.subarray(Y,Y+Q)));return btoa(J)}function R5($){let J=atob($),Q=new Uint8Array(J.length);for(let Y=0;Y<J.length;Y++)Q[Y]=J.charCodeAt(Y);return Q}function uJ($){let J=$.replace(/-/g,"+").replace(/_/g,"/")+"===".slice(($.length+3)%4);return R5(J)}function pJ(){if(typeof window>"u")return null;let $=window.location.hash.replace(/^#/,"");if(!$)return null;for(let J of $.split("&")){let[Q,Y]=J.split("=");if(Q==="k"&&Y)return decodeURIComponent(Y)}return null}function cJ(){if(typeof window<"u"&&window.__CANVAS_SHARE__?.shareId){let J=pJ();return{isShared:!0,shareId:window.__CANVAS_SHARE__.shareId,encryptionKey:J?C5(J):null}}return{isShared:!1,sessionId:typeof window<"u"?window.location.pathname.replace("/s/",""):""}}var B$=cJ();function lJ(){return B$.isShared&&B$.encryptionKey!==null}function dJ(){return B$.isShared?B$.shareId:B$.sessionId}function rJ(){if(B$.isShared)return`/s/${B$.shareId}/meta`;return`/api/session/${B$.sessionId}/meta`}function iJ($,J){let Q=$.replace(/\.jsx$/,".js");if(B$.isShared)return`/s/${B$.shareId}/canvas/${encodeURIComponent(Q)}`;let Y=J?`?rev=${J}&t=${Date.now()}`:`?t=${Date.now()}`;return`/api/session/${B$.sessionId}/canvas/${encodeURIComponent(Q)}${Y}`}function oJ(){if(B$.isShared)return`/s/${B$.shareId}/upload`;return`/api/session/${B$.sessionId}/upload`}async function I5(){let $=await fetch(rJ());if(!$.ok)throw Error(`meta ${$.status}`);let J=T5.parse(await $.json());if(J.encryption&&B$.isShared&&B$.encryptionKey){let Q=await B$.encryptionKey;if(J.origin){let Y={...J.origin};if(Y.sessionId)Y.sessionId=await X2(Q,Y.sessionId);if(Y.label)Y.label=await X2(Q,Y.label);J.origin=Y}for(let Y of J.revisions??[])if(Y.label)try{Y.label=await X2(Q,Y.label)}catch{}}return J}var aJ=async($,J)=>{let Q=iJ($,J);if(!lJ())return import(Q);let Y=await fetch(Q);if(!Y.ok)throw Error(`canvas ${Y.status}`);let q=await Y.text(),G=await B$.encryptionKey,X=await X2(G,q),H=new Blob([X],{type:"application/javascript"}),_=URL.createObjectURL(H);try{return await import(_)}finally{setTimeout(()=>URL.revokeObjectURL(_),0)}},D5="canvas-reviewer-identity";function n4(){try{let $=localStorage.getItem(D5);if(!$)return null;return JSON.parse($)}catch{return null}}function k5($){let J=n4();if(!J)J={id:crypto.randomUUID?.()||String(Date.now()),name:$};else J.name=$;return localStorage.setItem(D5,JSON.stringify(J)),J}async function nJ($,J){let Q=await Promise.all($.annotations.map(async(Y)=>{let q={id:Y.id,createdAt:Y.createdAt,snippet:await I0(J,String(Y.snippet??"")),note:await I0(J,String(Y.note??""))};if(Y.filePath)q.filePath=await I0(J,String(Y.filePath));if(Y.canvasFile)q.canvasFile=await I0(J,String(Y.canvasFile));if(Y.context!==void 0&&Y.context!==null)q.context=await I0(J,JSON.stringify(Y.context));if(Y.attachments)q.attachments=Y.attachments;return q}));return{author:{id:$.author.id,name:await I0(J,$.author.name)},revision:$.revision,annotations:Q,...$.generalNote?{generalNote:await I0(J,$.generalNote)}:{},encryption:Z5}}async function y5($){if(!B$.isShared)throw Error("submitSharedFeedback called outside shared mode");let J=$;if(B$.encryptionKey){let Y=await B$.encryptionKey;J=await nJ($,Y)}let Q=await fetch(`/s/${B$.shareId}/feedback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(J)});if(!Q.ok){let Y=await Q.text().catch(()=>"");throw Error(`Feedback submission failed: ${Q.status} ${Y}`)}}var B0=!B$.isShared,E5=!B$.isShared,f5={get sessionId(){return dJ()},isShared:B$.isShared,fsAvailable:B0,uploadUrl:oJ,loadCanvasModule:aJ};import i5,{useCallback as o5,useContext as KQ,useEffect as k0,useMemo as i2,useRef as K0,useState as V$}from"react";function D0($,J){let Q=$.length,Y=J.length;if(Q===0||Y===0)return[];let q=Array.from({length:Q+1},()=>Array(Y+1).fill(0));for(let _=1;_<=Q;_++)for(let W=1;W<=Y;W++)q[_][W]=$[_-1]===J[W-1]?q[_-1][W-1]+1:Math.max(q[_-1][W],q[_][W-1]);let G=[],X=Q,H=Y;while(X>0&&H>0)if($[X-1]===J[H-1])G.unshift($[X-1]),X--,H--;else if(q[X-1][H]>q[X][H-1])X--;else H--;return G}function v5($){let J=[],Q=[],Y=document.createTreeWalker($,NodeFilter.SHOW_TEXT,{acceptNode(G){let X=G.parentElement;if(!X)return NodeFilter.FILTER_REJECT;if(X.closest("svg, .select-none, [data-no-diff]"))return NodeFilter.FILTER_REJECT;return NodeFilter.FILTER_ACCEPT}}),q;while(q=Y.nextNode()){let X=(q.nodeValue||"").match(/\S+|\s+/g);if(!X)continue;let H=0;for(let _ of X)J.push(_),Q.push({text:_,node:q,offset:H}),H+=_.length}return{words:J,map:Q}}function s4($,J){if($.length>5000||J.length>5000)return sJ($,J);return x5($,J)}function x5($,J){let Q=l2($,J),Y=[],q=[],G=0,X=0,H=0;while(G<$.length||X<J.length)if(H<Q.length&&G<$.length&&X<J.length&&$[G]===Q[H]&&J[X]===Q[H])Y.push({type:"same",index:G}),q.push({type:"same",index:X}),G++,X++,H++;else if(G<$.length&&(H>=Q.length||$[G]!==Q[H]))Y.push({type:"removed",index:G}),G++;else if(X<J.length)q.push({type:"added",index:X}),X++;return{oldOps:Y,newOps:q}}function l2($,J){let Q=$.length,Y=J.length;if(Q===0||Y===0)return[];if(Q===1)return J.includes($[0])?[$[0]]:[];if(Y===1)return $.includes(J[0])?[J[0]]:[];if(Q*Y<=1e6)return D0($,J);let q=Math.floor(Q/2),G=$.slice(0,q),X=$.slice(q),H=g5(G,J),_=g5([...X].reverse(),[...J].reverse()),W=0,U=0;for(let K=0;K<=Y;K++){let N=H[K]+_[Y-K];if(N>W)W=N,U=K}let B=J.slice(0,U),z=J.slice(U);return[...l2(G,B),...l2(X,z)]}function g5($,J){let Q=J.length,Y=Array(Q+1).fill(0),q=Array(Q+1).fill(0);for(let G=0;G<$.length;G++){for(let X=1;X<=Q;X++)q[X]=$[G]===J[X-1]?Y[X-1]+1:Math.max(Y[X],q[X-1]);[Y,q]=[q,Y],q.fill(0)}return Y}function sJ($,J){let Y=(N)=>{let P=[];for(let M=0;M<N.length;M+=200){let T=Math.min(M+200,N.length);P.push({start:M,end:T,text:N.slice(M,T).join("")})}return P},q=Y($),G=Y(J),X=q.map((N)=>N.text),H=G.map((N)=>N.text),_=l2(X,H),W=[],U=[],B=0,z=0,K=0;while(B<q.length||z<G.length)if(K<_.length&&B<q.length&&z<G.length&&X[B]===_[K]&&H[z]===_[K]){for(let N=q[B].start;N<q[B].end;N++)W.push({type:"same",index:N});for(let N=G[z].start;N<G[z].end;N++)U.push({type:"same",index:N});B++,z++,K++}else if(B<q.length&&(K>=_.length||X[B]!==_[K]))if(z<G.length&&(K>=_.length||H[z]!==_[K])){let N=x5($.slice(q[B].start,q[B].end),J.slice(G[z].start,G[z].end));for(let P of N.oldOps)W.push({type:P.type,index:P.index+q[B].start});for(let P of N.newOps)U.push({type:P.type,index:P.index+G[z].start});B++,z++}else{for(let N=q[B].start;N<q[B].end;N++)W.push({type:"removed",index:N});B++}else if(z<G.length){for(let N=G[z].start;N<G[z].end;N++)U.push({type:"added",index:N});z++}return{oldOps:W,newOps:U}}function m5($,J,Q){let Y=new Map;for(let q of $){if(q.type==="same")continue;let G=J[q.index];if(!G||!G.node.parentNode)continue;let X=Y.get(G.node);if(!X)X=[],Y.set(G.node,X);X.push({offset:G.offset,length:G.text.length})}for(let[q,G]of Y){if(!q.parentNode)continue;let X=q.nodeValue||"";G.sort((B,z)=>B.offset-z.offset);let H=[];for(let B of G){let z=H[H.length-1];if(z&&B.offset<=z.offset+z.length)z.length=Math.max(z.length,B.offset+B.length-z.offset);else H.push({...B})}let _=q.parentNode,W=document.createDocumentFragment(),U=0;for(let B of H){if(B.offset>U)W.appendChild(document.createTextNode(X.slice(U,B.offset)));let z=document.createElement("span");z.className=Q,z.textContent=X.slice(B.offset,B.offset+B.length),W.appendChild(z),U=B.offset+B.length}if(U<X.length)W.appendChild(document.createTextNode(X.slice(U)));_.replaceChild(W,q)}}function d2($,J){let Q=tJ($,J),Y=v5($),q=v5(J),{oldOps:G,newOps:X}=s4(Y.words,q.words),H=G.some((_)=>_.type==="removed")||X.some((_)=>_.type==="added");return m5(G,Y.map,"diff-removed"),m5(X,q.map,"diff-added"),H||Q}function tJ($,J){let Q=Array.from($.querySelectorAll('[data-md="mermaid"]')),Y=Array.from(J.querySelectorAll('[data-md="mermaid"]')),q=!1,G=Math.max(Q.length,Y.length);for(let X=0;X<G;X++){let H=Q[X],_=Y[X];if(!H&&_){_.classList.add("diff-block-added"),_.style.position="relative",q=!0;continue}if(H&&!_){H.classList.add("diff-block-removed"),H.style.position="relative",q=!0;continue}if(!H||!_)continue;let W=(H.getAttribute("data-md-source")||"").trim(),U=(_.getAttribute("data-md-source")||"").trim();if(W===U)continue;q=!0,H.style.borderLeft="3px solid var(--color-accent-red)",H.style.paddingLeft="8px",_.style.borderLeft="3px solid var(--color-accent-green)",_.style.paddingLeft="8px";let B=W.split(`
70
+ `),z=U.split(`
71
+ `),K=D0(B,z),N=(P,M,T)=>{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 F=0,w=0;while(w<P.length){let S=document.createElement("div");if(S.className="px-3 py-0.5 whitespace-pre-wrap",F<M.length&&P[w]===M[F])S.textContent=" "+P[w],w++,F++;else S.classList.add(T==="old"?"diff-removed":"diff-added"),S.textContent=(T==="old"?"- ":"+ ")+P[w],w++;O.appendChild(S)}return O};H.appendChild(N(B,K,"old")),_.appendChild(N(z,K,"new"))}return q}import{useContext as eJ,useEffect as $Q,useRef as JQ,useState as QQ}from"react";import{jsxDEV as D$,Fragment as h5}from"react/jsx-dev-runtime";function qQ($){return $.label||`Round ${$.revision}`}function YQ($){let J=Date.now()-new Date($).getTime(),Q=Math.floor(J/1000);if(Q<60)return"just now";let Y=Math.floor(Q/60);if(Y<60)return`${Y}m ago`;let q=Math.floor(Y/60);if(q<24)return`${q}h ago`;return`${Math.floor(q/24)}d ago`}function G2({value:$,onChange:J,accent:Q="default",className:Y}){let{currentRevision:q,revisions:G}=eJ(E$),[X,H]=QQ(!1),_=JQ(null);$Q(()=>{if(!X)return;let B=(z)=>{if(_.current&&!_.current.contains(z.target))H(!1)};return document.addEventListener("mousedown",B),()=>document.removeEventListener("mousedown",B)},[X]);let W=G.find((B)=>B.revision===$);return D$("div",{className:"relative",ref:_,children:[D$("button",{onClick:()=>H(!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]} ${Y||""}`,children:[W?qQ(W):`Round ${$}`,D$("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",className:`text-text-tertiary transition-transform duration-200 ${X?"rotate-180":""}`,children:D$("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&&D$("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:[...G].reverse().map((B)=>D$("button",{onClick:()=>{J(B.revision),H(!1)},className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] font-body transition-colors ${B.revision===$?"bg-bg-surface text-text-primary":"text-text-secondary hover:bg-bg-surface hover:text-text-primary"}`,children:[D$("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${B.revision===q?"bg-accent-green":B.hasFeedback?"bg-accent-amber":"bg-border-hover"}`},void 0,!1,void 0,this),D$("span",{className:"flex-1 text-left truncate",children:B.label?D$(h5,{children:[B.label," ",D$("span",{className:"text-text-tertiary",children:["#",B.revision]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):D$(h5,{children:["Round ",B.revision]},void 0,!0,void 0,this)},void 0,!1,void 0,this),D$("span",{className:"text-[10px] text-text-tertiary flex-shrink-0 flex items-center gap-1.5",children:[(()=>{let z=B.canvasFiles?.reduce((K,N)=>{if(N.diffStats)K.added+=N.diffStats.added,K.removed+=N.diffStats.removed;return K},{added:0,removed:0});if(z&&(z.added>0||z.removed>0))return D$("span",{className:"font-mono",children:[D$("span",{className:"text-accent-green",children:["+",z.added]},void 0,!0,void 0,this)," ",D$("span",{className:"text-accent-red",children:["-",z.removed]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);return null})(),B.revision===q?"current":B.hasFeedback?"sent":YQ(B.createdAt)]},void 0,!0,void 0,this)]},B.revision,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function V1($){let J=[],Q=$.querySelectorAll(":scope > [data-md]");for(let Y of Q)J.push(_2(Y));if(J.length===0){let Y=$.querySelectorAll("[data-md]"),q=new Set;for(let G of Y){let X=G.parentElement?.closest("[data-md]");if(X&&$.contains(X))continue;if(q.has(G))continue;q.add(G),J.push(_2(G))}}return J}function _2($){let J=$.getAttribute("data-md")||"unknown",Q=XQ($,J),Y=[];if(J==="section"){let q=$.querySelector(":scope > div.mt-6, :scope > div:last-child");if(q)for(let G of q.querySelectorAll(":scope > [data-md]"))Y.push(_2(G))}else if(J==="table")for(let q of $.querySelectorAll(":scope table > tbody > tr"))Y.push({key:"tr:"+(q.textContent||"").slice(0,80),type:"tr",element:q,children:[]});else if(J==="checklist")for(let q of $.querySelectorAll(":scope > [data-md='checklist-item']"))Y.push(_2(q));else for(let q of $.querySelectorAll("[data-md]"))if(q.parentElement?.closest("[data-md]")===$)Y.push(_2(q));return{key:Q,type:J,element:$,children:Y}}function XQ($,J){switch(J){case"section":return"section:"+($.getAttribute("data-md-title")||"");case"item":return"item:"+($.getAttribute("data-task-id")||$.getAttribute("data-md-label")||"");case"codeblock":case"diff":return J+":"+($.textContent||"").slice(0,80);case"checklist-item":return"checklist-item:"+($.getAttribute("data-md-label")||$.textContent?.slice(0,60)||"");case"checklist":return"checklist:"+$.querySelectorAll("[data-md='checklist-item']").length;case"markdown":return"markdown:"+($.getAttribute("data-md-file")||"inline");case"mermaid":return"mermaid:"+($.getAttribute("data-md-source")||"").slice(0,80);case"callout":return"callout:"+($.getAttribute("data-md-type")||"")+":"+($.textContent||"").slice(0,60);default:return J+":"+($.getAttribute("data-md-label")||$.textContent?.slice(0,60)||"")}}function H2($,J){let Q=$.map((W)=>W.key),Y=J.map((W)=>W.key),q=D0(Q,Y),G=[],X=0,H=0,_=0;while(X<$.length||H<J.length)if(_<q.length&&X<$.length&&H<J.length&&Q[X]===q[_]&&Y[H]===q[_]){let W=$[X],U=J[H],B=W.children.length>0||U.children.length>0?H2(W.children,U.children):void 0;G.push({kind:"matched",oldBlock:W,newBlock:U,childMatches:B}),X++,H++,_++}else if(X<$.length&&(_>=q.length||Q[X]!==q[_]))G.push({kind:"removed",oldBlock:$[X]}),X++;else if(H<J.length)G.push({kind:"added",newBlock:J[H]}),H++;return G}function r2($){let J=document.createDocumentFragment(),Q=!1;for(let Y of $)if(Y.kind==="removed")Q=!0,J.appendChild(p5(Y.oldBlock.element));else if(Y.kind==="added")Q=!0,J.appendChild(GQ(Y.newBlock.element));else{let q=Y.newBlock.element.cloneNode(!0),G=Y.newBlock.type;if(G==="mermaid"){if(r5(Y.oldBlock.element,q))Q=!0}else if(Y.childMatches&&Y.childMatches.length>0&&(G==="table"||G==="checklist")){if(l5(q,Y.childMatches,G))Q=!0}else if(Y.childMatches&&Y.childMatches.length>0){if(c5(Y.oldBlock,q,Y.childMatches,G))Q=!0}else if(G==="markdown"){if(d5(Y.oldBlock.element,q))Q=!0}else if(e0(Y.oldBlock.element,q,!1))Q=!0;J.appendChild(q)}return{fragment:J,hasChanges:Q}}function p5($){let J=$.cloneNode(!0);return J.classList.add("diff-block-removed"),J.style.position="relative",t4(J,"Removed","var(--color-accent-red)"),J}function GQ($){let J=$.cloneNode(!0);return J.classList.add("diff-block-added"),J.style.position="relative",t4(J,"Added","var(--color-accent-green)"),J}function c5($,J,Q,Y){let q=!1,G=_Q($,J),X,H;if(Y==="section"){let _=$.element.querySelector(":scope > div:first-child"),W=J.querySelector(":scope > div:first-child");if(_&&W){if(e0(_,W,!1))q=!0}X=$.element.querySelector(":scope > div.mt-6, :scope > div:last-child"),H=J.querySelector(":scope > div.mt-6, :scope > div:last-child")}else X=$.element,H=J;if(!X||!H)return q;for(let _ of Q)if(_.kind==="matched"){let W=G.newMap.get(_.newBlock.element);if(W){if(_.newBlock.type==="mermaid"){if(r5(_.oldBlock.element,W))q=!0}else if(_.childMatches&&_.childMatches.length>0&&(_.newBlock.type==="table"||_.newBlock.type==="checklist")){if(l5(W,_.childMatches,_.newBlock.type))q=!0}else if(_.childMatches&&_.childMatches.length>0){if(c5(_.oldBlock,W,_.childMatches,_.newBlock.type))q=!0}else if(_.newBlock.type==="markdown"){if(d5(_.oldBlock.element,W))q=!0}else if(e0(_.oldBlock.element,W,!1))q=!0}}else if(_.kind==="removed"){q=!0;let W=p5(_.oldBlock.element),U=WQ(Q,_,G.newMap),B=U?UQ(H,U):null;H.insertBefore(W,B)}else if(_.kind==="added"){q=!0;let W=G.newMap.get(_.newBlock.element);if(W)W.classList.add("diff-block-added"),W.style.position="relative",t4(W,"Added","var(--color-accent-green)")}if(e0(X,H,!0))q=!0;return q}function l5($,J,Q){let Y=Q==="table"?$.querySelector(":scope table > tbody"):$;if(!Y)return!1;let q=!1;Y.innerHTML="";for(let G of J)if(G.kind==="removed"){q=!0;let X=G.oldBlock.element.cloneNode(!0);X.classList.add(Q==="table"?"diff-row-removed":"diff-item-removed"),Y.appendChild(X)}else if(G.kind==="added"){q=!0;let X=G.newBlock.element.cloneNode(!0);X.classList.add(Q==="table"?"diff-row-added":"diff-item-added"),Y.appendChild(X)}else{let X=G.newBlock.element.cloneNode(!0);if(e0(G.oldBlock.element,X,!1))q=!0;Y.appendChild(X)}return q}function _Q($,J){return{newMap:{get(Q){return HQ(J,Q)}}}}function HQ($,J){let Q=J.getAttribute("data-md");if(!Q)return null;let Y=J.getAttribute("data-md-label"),q=J.getAttribute("data-md-title"),G=`[data-md="${Q}"]`;if(q)G+=`[data-md-title="${CSS.escape(q)}"]`;else if(Y)G+=`[data-md-label="${CSS.escape(Y)}"]`;let X=$.querySelectorAll(G);if(X.length===1)return X[0];let H=(J.textContent||"").slice(0,100),_=null,W=-1;for(let U of X){let B=(U.textContent||"").slice(0,100),z=0;for(let K=0;K<Math.min(H.length,B.length);K++)if(H[K]===B[K])z++;if(z>W)W=z,_=U}return _}function WQ($,J,Q){let Y=$.indexOf(J);for(let q=Y+1;q<$.length;q++){let G=$[q];if((G.kind==="matched"||G.kind==="added")&&G.newBlock)return Q.get(G.newBlock.element)||null}return null}function UQ($,J){let Q=J;while(Q&&Q.parentElement!==$)Q=Q.parentElement;return Q}function d5($,J){let Q=Array.from($.children),Y=Array.from(J.children);if(Q.length===0&&Y.length===0)return e0($,J,!1);let q=Q.map((z)=>z.tagName.toLowerCase()),G=Y.map((z)=>z.tagName.toLowerCase()),X=D0(q,G),H=[],_=0,W=0,U=0;while(_<Q.length||W<Y.length)if(U<X.length&&_<Q.length&&W<Y.length&&q[_]===X[U]&&G[W]===X[U])H.push({kind:"matched",oldChild:Q[_],newChild:Y[W]}),_++,W++,U++;else if(_<Q.length&&(U>=X.length||q[_]!==X[U]))H.push({kind:"removed",oldChild:Q[_]}),_++;else if(W<Y.length)H.push({kind:"added",newChild:Y[W]}),W++;let B=!1;while(J.firstChild)J.removeChild(J.firstChild);for(let z of H)if(z.kind==="matched"){let K=(z.oldChild.textContent||"").match(/\S+/g)||[],N=(z.newChild.textContent||"").match(/\S+/g)||[],P=D0(K,N),M=Math.max(K.length,N.length);if((M>0?1-P.length/M:0)>0.5){B=!0;let O=z.oldChild.cloneNode(!0);O.classList.add("diff-block-removed"),J.appendChild(O),z.newChild.classList.add("diff-block-added"),J.appendChild(z.newChild)}else{if(e0(z.oldChild,z.newChild,!1))B=!0;J.appendChild(z.newChild)}}else if(z.kind==="removed"){B=!0;let K=z.oldChild.cloneNode(!0);K.classList.add("diff-block-removed"),J.appendChild(K)}else B=!0,z.newChild.classList.add("diff-block-added"),J.appendChild(z.newChild);return B}function u5($,J){let Q=J?new Set(Array.from($.querySelectorAll("[data-md]"))):new Set,Y=[],q=[],G=document.createTreeWalker($,NodeFilter.SHOW_TEXT,{acceptNode(H){let _=H.parentElement;if(!_)return NodeFilter.FILTER_REJECT;if(_.closest("svg, .select-none, [data-no-diff]"))return NodeFilter.FILTER_REJECT;if(J){for(let W of Q)if(W.contains(H))return NodeFilter.FILTER_REJECT}return NodeFilter.FILTER_ACCEPT}}),X;while(X=G.nextNode()){let _=(X.nodeValue||"").match(/\S+|\s+/g);if(!_)continue;let W=0;for(let U of _)Y.push(U),q.push({text:U,node:X,offset:W}),W+=U.length}return{words:Y,map:q}}function e0($,J,Q){let Y=u5($,Q),q=u5(J,Q);if(Y.words.length===0&&q.words.length===0)return!1;let{oldOps:G,newOps:X}=s4(Y.words,q.words),H=G.some((M)=>M.type==="removed"),_=X.some((M)=>M.type==="added");if(!H&&!_)return!1;let W=[],U=[];for(let M of G)if(M.type==="same")W.push(M.index);for(let M of X)if(M.type==="same")U.push(M.index);let B=new Map;for(let M=0;M<W.length&&M<U.length;M++)B.set(W[M],U[M]);let z=[];{let M=[],T=-1;for(let O of G)if(O.type==="same"){if(M.length>0)z.push({text:M.join(""),anchorNewIdx:T>=0?B.get(T)??null:null}),M=[];T=O.index}else if(O.type==="removed")M.push(Y.words[O.index]);if(M.length>0)z.push({text:M.join(""),anchorNewIdx:T>=0?B.get(T)??null:null})}let K=new Map,N=new Map;for(let M of X){if(M.type!=="added")continue;let T=q.map[M.index];if(!T?.node.parentNode)continue;let O=K.get(T.node);if(!O)O=[],K.set(T.node,O);O.push({start:T.offset,end:T.offset+T.text.length})}for(let M of z)if(M.anchorNewIdx===null){if(q.map.length>0){let T=q.map[0].node,O=N.get(T);if(!O)O=[],N.set(T,O);O.push({offset:0,text:M.text})}}else{let T=q.map[M.anchorNewIdx];if(!T)continue;let O=N.get(T.node);if(!O)O=[],N.set(T.node,O);O.push({offset:T.offset+T.text.length,text:M.text})}let P=new Set([...K.keys(),...N.keys()]);for(let M of P)BQ(M,K.get(M)||[],N.get(M)||[]);return!0}function BQ($,J,Q){if(!$.parentNode)return;let Y=$.nodeValue||"";J.sort((U,B)=>U.start-B.start);let q=[];for(let U of J){let B=q[q.length-1];if(B&&U.start<=B.end)B.end=Math.max(B.end,U.end);else q.push({...U})}Q.sort((U,B)=>U.offset-B.offset);let G=$.parentNode,X=document.createDocumentFragment(),H=0,_=0,W=0;while(H<=Y.length){let U=_<q.length?q[_].start:1/0,B=W<Q.length?Q[W].offset:1/0,z=Math.min(U,B);if(z===1/0){if(H<Y.length)X.appendChild(document.createTextNode(Y.slice(H)));break}let K=Math.max(z,H);if(K>H)X.appendChild(document.createTextNode(Y.slice(H,K))),H=K;while(W<Q.length&&Q[W].offset<=H){let N=document.createElement("span");N.className="diff-removed",N.textContent=Q[W].text,X.appendChild(N),W++}if(_<q.length&&q[_].start<=H){let N=q[_],P=document.createElement("span");P.className="diff-added",P.textContent=Y.slice(H,N.end),X.appendChild(P),H=N.end,_++;while(W<Q.length&&Q[W].offset<=H){let M=document.createElement("span");M.className="diff-removed",M.textContent=Q[W].text,X.appendChild(M),W++}}}while(W<Q.length){let U=document.createElement("span");U.className="diff-removed",U.textContent=Q[W].text,X.appendChild(U),W++}G.replaceChild(X,$)}function r5($,J){let Q=($.getAttribute("data-md-source")||"").trim(),Y=(J.getAttribute("data-md-source")||"").trim();if(Q===Y)return!1;let q=Q.split(`
72
+ `),G=Y.split(`
73
+ `),X=D0(q,G),H=[],_=0,W=0,U=0;while(_<q.length||W<G.length)if(U<X.length&&_<q.length&&W<G.length&&q[_]===X[U]&&G[W]===X[U])H.push({type:"same",line:q[_]}),_++,W++,U++;else if(_<q.length&&(U>=X.length||q[_]!==X[U]))H.push({type:"removed",line:q[_]}),_++;else if(W<G.length)H.push({type:"added",line:G[W]}),W++;let B=document.createElement("div");B.className="mt-2 bg-bg-code rounded-md overflow-hidden text-tiny font-mono",B.setAttribute("data-no-diff","true");for(let z of H){let K=document.createElement("div");if(K.className="px-3 py-0.5 whitespace-pre-wrap",z.type==="removed")K.classList.add("diff-removed"),K.textContent="- "+z.line;else if(z.type==="added")K.classList.add("diff-added"),K.textContent="+ "+z.line;else K.textContent=" "+z.line;B.appendChild(K)}return J.appendChild(B),!0}function t4($,J,Q){let Y=document.createElement("span");Y.className="diff-block-label",Y.textContent=J,Y.style.color=Q,Y.style.backgroundColor=`color-mix(in srgb, ${Q} 12%, transparent)`,$.appendChild(Y)}import{jsxDEV as h}from"react/jsx-dev-runtime";function zQ($,J,Q){let Y=$.find((X)=>X.revision===J),q=$.find((X)=>X.revision===Q),G=new Set;for(let X of Y?.canvasFiles||[])G.add(X.filename);for(let X of q?.canvasFiles||[])G.add(X.filename);return[...G].sort()}function a5({initialLeft:$,initialRight:J,sessionId:Q,onExit:Y}){let[q,G]=V$($),[X,H]=V$(J),[_,W]=V$("unified"),[U,B]=V$(!0),[z,K]=V$(!1),{revisions:N}=KQ(E$),P=i2(()=>zQ(N,q,X),[N,q,X]),[M,T]=V$(()=>P[0]||"plan.jsx");k0(()=>{if(!P.includes(M))T(P[0]||"plan.jsx")},[P,M]);let O=i2(()=>{return N.find((S)=>S.revision===q)?.canvasFiles.some((S)=>S.filename===M)??!1},[N,q,M]),F=i2(()=>{return N.find((S)=>S.revision===X)?.canvasFiles.some((S)=>S.filename===M)??!1},[N,X,M]);return h("div",{className:"flex flex-col h-screen",children:[h("div",{className:"flex items-center justify-between px-6 py-3 border-b border-border-subtle bg-bg-surface flex-shrink-0",children:[h("div",{className:"flex items-center gap-3",children:[h("span",{className:"text-[13px] font-body font-medium text-text-primary",children:"Compare"},void 0,!1,void 0,this),h(G2,{value:q,onChange:G,accent:"red"},void 0,!1,void 0,this),h("span",{className:"text-text-tertiary text-[13px]",children:"→"},void 0,!1,void 0,this),h(G2,{value:X,onChange:H,accent:"green"},void 0,!1,void 0,this),z&&!U&&h("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),h("div",{className:"flex items-center gap-4",children:[h("div",{className:"flex items-center bg-bg-elevated rounded-md p-0.5",children:[h("button",{onClick:()=>W("unified"),className:`text-[11px] font-body px-2.5 py-1 rounded transition-colors ${_==="unified"?"bg-bg-surface text-text-primary font-medium shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Unified"},void 0,!1,void 0,this),h("button",{onClick:()=>W("side-by-side"),className:`text-[11px] font-body px-2.5 py-1 rounded transition-colors ${_==="side-by-side"?"bg-bg-surface text-text-primary font-medium shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Side-by-side"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),_==="side-by-side"&&h(NQ,{},void 0,!1,void 0,this),h("button",{onClick:Y,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),P.length>1&&h("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:P.map((w)=>{let S=w.replace(/\.jsx$/,""),j=w===M,R=N.find((Z)=>Z.revision===q)?.canvasFiles.some((Z)=>Z.filename===w),y=N.find((Z)=>Z.revision===X)?.canvasFiles.some((Z)=>Z.filename===w),I=!R?" (added)":!y?" (removed)":"";return h("button",{onClick:()=>T(w),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:[S,I&&h("span",{className:`ml-1 text-[10px] ${!R?"text-accent-green":"text-accent-red"}`,children:I},void 0,!1,void 0,this)]},w,!0,void 0,this)})},void 0,!1,void 0,this),!O||!F?h("div",{className:"flex-1 flex items-center justify-center",children:h("div",{className:"text-center text-text-tertiary font-body",children:[h("div",{className:"text-lg mb-2",children:!O?"New file":"Removed file"},void 0,!1,void 0,this),h("div",{className:"text-[13px]",children:[M.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):_==="unified"?h(MQ,{sessionId:Q,leftRev:q,rightRev:X,filename:M,onDiffResult:(w,S)=>{K(w),B(S)}},`unified-${q}-${X}-${M}`,!1,void 0,this):h(OQ,{sessionId:Q,leftRev:q,rightRev:X,filename:M,onDiffResult:(w,S)=>{K(w),B(S)}},`sbs-${q}-${X}-${M}`,!1,void 0,this)]},void 0,!0,void 0,this)}function NQ(){let[$,J]=V$(!0);return k0(()=>{return document.documentElement.dataset.syncScroll=$?"1":"0",()=>{delete document.documentElement.dataset.syncScroll}},[$]),h("label",{className:"flex items-center gap-1.5 cursor-pointer select-none",children:[h("input",{type:"checkbox",checked:$,onChange:(Q)=>J(Q.target.checked),className:"accent-accent-amber w-3.5 h-3.5"},void 0,!1,void 0,this),h("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 MQ({sessionId:$,leftRev:J,rightRev:Q,filename:Y,onDiffResult:q}){let G=K0(null),X=K0(null),H=K0(null),[_,W]=V$(!1),[U,B]=V$(!1),[z,K]=V$(!1),[N,P]=V$(null),[M,T]=V$(!1),{annotations:O}=q0(),F=O.filter((S)=>!S.filePath&&(!S.canvasFile||S.canvasFile===Y)),{popovers:w}=V0({containerRef:H,restoreKey:z,restoreAnnotations:F,extractContext:(S)=>L0(S,H.current)});return k0(()=>{if(z||N)return;let S=setTimeout(()=>{console.warn("[unified-diff] still loading after 10s",{leftReady:_,rightReady:U,oldRef:!!G.current,newRef:!!X.current}),T(!0)},1e4);return()=>clearTimeout(S)},[z,N,_,U]),k0(()=>{if(!_||!U||z)return;if(!G.current||!X.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!G.current||!X.current||!H.current){console.warn("[unified-diff] refs lost between rAF frames",{old:!!G.current,new:!!X.current,unified:!!H.current});return}try{let S=V1(G.current),j=V1(X.current),R=H2(S,j),{fragment:y,hasChanges:I}=r2(R);H.current.innerHTML="",H.current.appendChild(y),K(!0),q(!0,I)}catch(S){console.error("[unified-diff] diff computation failed",S),P(S instanceof Error?S.message:String(S))}})})},[_,U,z]),h("div",{className:"flex-1 min-h-0 overflow-y-auto",children:[!z&&!N&&h("div",{style:{position:"absolute",left:-9999,visibility:"hidden",pointerEvents:"none",width:720},children:[h(z0,{ref:G,sessionId:$,revision:J,filename:Y,onReady:()=>W(!0),onError:(S)=>P(`Rev ${J}: ${S}`)},void 0,!1,void 0,this),h(z0,{ref:X,sessionId:$,revision:Q,filename:Y,onReady:()=>B(!0),onError:(S)=>P(`Rev ${Q}: ${S}`)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),h("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:[!z&&!N&&h("div",{className:"flex flex-col items-center justify-center h-64 text-text-tertiary font-body text-body gap-2",children:[h("span",{children:"Loading..."},void 0,!1,void 0,this),M&&h("span",{className:"text-[11px]",children:"Taking longer than expected — check Network tab for pending requests"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),N&&h("div",{className:"bg-accent-red-muted rounded-lg p-5 mt-8",children:[h("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Failed to load revision"},void 0,!1,void 0,this),h("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:N},void 0,!1,void 0,this)]},void 0,!0,void 0,this),h("div",{ref:H},void 0,!1,void 0,this)]},void 0,!0,void 0,this),w]},void 0,!0,void 0,this)}function OQ({sessionId:$,leftRev:J,rightRev:Q,filename:Y,onDiffResult:q}){let G=K0(null),X=K0(null),[H,_]=V$(!1),[W,U]=V$(!1),[B,z]=V$(!1),K=K0(null),N=K0(null),P=K0(null),M=K0(!1),T=o5(()=>_(!0),[]),O=o5(()=>U(!0),[]),{annotations:F}=q0(),w=F.filter((j)=>!j.filePath&&(!j.canvasFile||j.canvasFile===Y)),{popovers:S}=V0({containerRef:K,restoreKey:B,restoreAnnotations:w,extractContext:(j)=>L0(j,K.current)});return k0(()=>{if(!H||!W||B)return;if(!G.current||!X.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!G.current||!X.current)return;let j=d2(G.current,X.current);z(!0),q(!0,j)})})},[H,W,B]),k0(()=>{let j=N.current,R=P.current;if(!j||!R)return;let y=(f,u)=>{if(document.documentElement.dataset.syncScroll==="0")return;if(M.current)return;M.current=!0;let o=f.scrollHeight-f.clientHeight,K$=u.scrollHeight-u.clientHeight;if(o>0&&K$>0)u.scrollTop=f.scrollTop/o*K$;requestAnimationFrame(()=>{M.current=!1})},I=()=>y(j,R),Z=()=>y(R,j);return j.addEventListener("scroll",I),R.addEventListener("scroll",Z),()=>{j.removeEventListener("scroll",I),R.removeEventListener("scroll",Z)}},[]),h("div",{ref:K,className:"flex flex-1 min-h-0",children:[h("div",{ref:N,className:"w-1/2 overflow-y-auto border-r border-border-subtle",children:h("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:h(z0,{ref:G,sessionId:$,revision:J,filename:Y,onReady:T},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),h("div",{ref:P,className:"w-1/2 overflow-y-auto",children:h("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:h(z0,{ref:X,sessionId:$,revision:Q,filename:Y,onReady:O},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),S]},void 0,!0,void 0,this)}var z0=i5.memo(i5.forwardRef(({sessionId:$,revision:J,filename:Q,onReady:Y,onError:q},G)=>{let[X,H]=V$(null),[_,W]=V$(null),[U,B]=V$(!0);k0(()=>{B(!0),W(null);let K=Q.replace(/\.jsx$/,".js");import(`/api/session/${$}/canvas/${encodeURIComponent(K)}?rev=${J}&t=${Date.now()}`).then((N)=>{if(!N.default){W("Module has no default export"),B(!1),q?.("Module has no default export");return}H(()=>N.default),B(!1)}).catch((N)=>{W(N.message),B(!1),q?.(N.message)})},[$,J,Q]),k0(()=>{if(!X)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{Y()})})},[X]);let z=i2(()=>X?h(X,{},void 0,!1,void 0,this):null,[X]);if(U)return h("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-body",children:"Loading..."},void 0,!1,void 0,this);if(_)return h("div",{className:"bg-accent-red-muted rounded-lg p-5",children:[h("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Error"},void 0,!1,void 0,this),h("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:_},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(!X)return h("div",{className:"text-text-tertiary text-center py-8 font-body text-body",children:"No canvas loaded"},void 0,!1,void 0,this);return h("div",{ref:G,children:z},void 0,!1,void 0,this)}));function W2($){return $ instanceof Error&&$.message?$.message:String($)}var o2={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"};function n5($){let J=[];return a2($,J,0),J.join(`
80
74
  `).replace(/\n{3,}/g,`
81
75
 
82
76
  `).trim()+`
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(`
77
+ `}var LQ=new Set(["CODE","SPAN","STRONG","EM","A","B","I","U","SMALL","SUB","SUP","MARK","ABBR"]);function a2($,J,Q){if(FQ($)){let Y=AQ($);if(Y)J.push(Y,"");return}for(let Y of $.childNodes)if(Y.nodeType===Node.ELEMENT_NODE)SQ(Y,J,Q);else if(Y.nodeType===Node.TEXT_NODE){let q=Y.textContent?.trim();if(q)J.push(q,"")}}function FQ($){for(let J of $.childNodes){if(J.nodeType===Node.TEXT_NODE)continue;if(J.nodeType===Node.ELEMENT_NODE){let Q=J;if(!LQ.has(Q.tagName)||Q.hasAttribute("data-md"))return!1}}return $.childNodes.length>0}function AQ($){let J="";for(let Q of $.childNodes)if(Q.nodeType===Node.TEXT_NODE)J+=Q.textContent||"";else if(Q.nodeType===Node.ELEMENT_NODE){let Y=Q;if(Y.tagName==="CODE")J+="`"+(Y.textContent||"")+"`";else J+=Y.textContent||""}return J.trim()}function SQ($,J,Q){let Y=$.getAttribute("data-md");if(Y)switch(Y){case"section":return PQ($,J,Q);case"item":return wQ($,J);case"codeblock":return TQ($,J);case"callout":return jQ($,J);case"note":return bQ($,J);case"markdown":return IQ($,J);case"table":return VQ($,J);case"checklist":return ZQ($,J);case"diff":return CQ($,J);case"mermaid":return RQ($,J);case"choice":return DQ($,J);case"multichoice":return kQ($,J);case"choice-option":case"multichoice-option":return;case"userinput":return yQ($,J);case"rangeinput":return EQ($,J);case"checklist-item":return;case"filepreview":return fQ($,J);case"priority":return vQ($,J)}if($.querySelector("button, input, select, textarea"))return;if($.children.length>0)a2($,J,Q);else{let q=$.textContent?.trim();if(q)J.push(q,"")}}function PQ($,J,Q){let Y=$.getAttribute("data-md-title")||"Untitled",q=Q===0?"##":"###";J.push(`${q} ${Y}`,"");let G=$.querySelector(":scope > div:last-of-type");if(G)a2(G,J,Q+1)}function wQ($,J){let Q=$.getAttribute("data-md-label")||"",Y=$.getAttribute("data-md-status"),q=$.getAttribute("data-md-badge"),G="-";if(Y==="done")G="- [x]";else if(Y)G="- [ ]";let X=`${G} **${Q}**`;if(q)X+=` \`${q}\``;J.push(X);let H=$.querySelector(".text-text-secondary");if(H){let _=[];a2(H,_,0);for(let W of _)J.push(W?` ${W}`:"")}J.push("")}function TQ($,J){let Q=$.getAttribute("data-md-language")||"",q=$.querySelector("code")?.textContent||"";J.push(`\`\`\`${Q}`,q,"```","")}function jQ($,J){let Q=$.getAttribute("data-md-type")||"info",Y={info:"Info",warning:"Warning",danger:"Danger",tip:"Tip"},q=gQ($.querySelector(".text-text-secondary")||$);J.push(`> **${Y[Q]||Q}:** ${q}`,"")}function bQ($,J){let Q=$.textContent?.trim()||"";J.push(`> *${Q}*`,"")}function VQ($,J){let Q=$.querySelector("table");if(!Q)return;let Y=[];for(let q of Q.querySelectorAll("thead th"))Y.push(q.textContent?.trim()||"");if(Y.length===0)return;J.push(`| ${Y.join(" | ")} |`),J.push(`| ${Y.map(()=>"---").join(" | ")} |`);for(let q of Q.querySelectorAll("tbody tr")){let G=[];for(let X of q.querySelectorAll("td"))G.push(X.textContent?.trim()||"");J.push(`| ${G.join(" | ")} |`)}J.push("")}function ZQ($,J){for(let Q of $.querySelectorAll("li")){let Y=Q.querySelector(".bg-accent-green")!==null,q=Q.textContent?.trim()||"";J.push(`- [${Y?"x":" "}] ${q}`)}J.push("")}function CQ($,J){let Q=$.getAttribute("data-md-language")||"";J.push(`\`\`\`diff${Q?` (${Q})`:""}`);for(let Y of $.querySelectorAll("[class*='flex']")){let q=Y.querySelector(".text-accent-red")?"-":Y.querySelector(".text-accent-green")?"+":" ",G=Y.querySelector("code");if(G)J.push(`${q} ${G.textContent}`)}J.push("```","")}function RQ($,J){let Q=$.getAttribute("data-md-source")||"";if(Q)J.push("```mermaid",Q,"```","")}function IQ($,J){let Q=$.getAttribute("data-md-source")||"";if(Q)J.push(Q,"")}function DQ($,J){let Q=$.getAttribute("data-md-label")||"";J.push(`**${Q}:**`);for(let Y of $.querySelectorAll("[data-md='choice-option']")){let q=Y.getAttribute("data-md-label")||Y.textContent?.trim()||"",G=Y.querySelector(".bg-accent-amber")!==null;J.push(`- ${G?"(x)":"( )"} ${q}`)}J.push("")}function kQ($,J){let Q=$.getAttribute("data-md-label")||"";J.push(`**${Q}:**`);for(let Y of $.querySelectorAll("[data-md='multichoice-option']")){let q=Y.getAttribute("data-md-label")||Y.textContent?.trim()||"",G=Y.querySelector(".bg-accent-amber")!==null;J.push(`- [${G?"x":" "}] ${q}`)}J.push("")}function yQ($,J){let Q=$.getAttribute("data-md-label")||"",q=$.querySelector("textarea")?.value?.trim()||"";J.push(`**${Q}:** ${q||"_empty_"}`,"")}function EQ($,J){let Q=$.getAttribute("data-md-label")||"",Y=$.querySelector("input[type='range']"),G=$.querySelector(".font-mono")?.textContent?.trim()||Y?.value||"—";J.push(`**${Q}:** ${G}`,"")}function fQ($,J){let Q=$.getAttribute("data-md-path")||"",Y=$.getAttribute("data-md-lines")||"",G=$.querySelector("code")?.textContent||"",X=Q.split(".").pop()||"",H=o2[X]||"",_=Y?`${Q} (L${Y})`:Q;J.push(_,"",`\`\`\`${H}`,G,"```","")}function vQ($,J){}function gQ($){return $?.textContent?.trim()||""}import{SessionContext as mQ}from"#canvas/runtime";import{useContext as s5,useEffect as xQ,useMemo as hQ,useState as t5}from"react";import{jsxDEV as n,Fragment as e4}from"react/jsx-dev-runtime";function e5({embedded:$}={}){if(!B0)return n("div",{className:$?"px-4 py-3":"p-4",children:[n("div",{className:"text-[11px] uppercase tracking-widest text-text-tertiary font-body mb-2",children:"Files"},void 0,!1,void 0,this),n("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);return n(uQ,{embedded:$},void 0,!1,void 0,this)}function uQ({embedded:$}){let J=s5(mQ),{annotations:Q,addAnnotation:Y}=q0(),{setActiveView:q}=s5($0),[G,X]=t5(!1),[H,_]=t5({}),{annCountMap:W,annotatedFiles:U}=hQ(()=>{let O=new Map;for(let F of Q)if(F.filePath&&F.filePath!==u$)O.set(F.filePath,(O.get(F.filePath)||0)+1);return{annCountMap:O,annotatedFiles:[...O.keys()]}},[Q]),B=async(O)=>{let F=await fetch(`/api/tree?session=${J}&path=${encodeURIComponent(O)}`),w=a4.safeParse(await F.json());if(w.success)_((S)=>({...S,[O]:{entries:w.data.entries,expanded:!0,loaded:!0}}))};xQ(()=>{if(!G&&!H[""])B("")},[G]);let z=(O)=>{if(H[O]?.loaded)_((F)=>({...F,[O]:{...F[O],expanded:!F[O].expanded}}));else B(O)},K=(O)=>{q({type:"file",path:O})},N=async(O)=>{let F=await fetch(`/api/file?session=${J}&path=${encodeURIComponent(O)}`),w=Z0.safeParse(await F.json());if(w.success&&"content"in w.data){let{content:S}=w.data,j=S.split(`
78
+ `).slice(0,3).join(`
79
+ `)+(S.split(`
80
+ `).length>3?`
81
+ ...`:"");Y(j,"Include this file for context",O)}},P=async(O)=>{let F=[];if(H[O]?.loaded)F=H[O].entries;else{let w=await fetch(`/api/tree?session=${J}&path=${encodeURIComponent(O)}`),S=a4.safeParse(await w.json());if(S.success)F=S.data.entries}await Promise.all(F.filter((w)=>w.type==="file").map((w)=>N(O?`${O}/${w.name}`:w.name)))},M=(O)=>W.get(O)||0,T=(O,F=0)=>{let w=H[O];if(!w?.expanded)return null;return w.entries.map((S)=>{let j=O?`${O}/${S.name}`:S.name,R=M(j);return n("div",{children:[n("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+F*16}px`,paddingRight:"8px"},children:S.type==="dir"?n(e4,{children:[n("span",{onClick:()=>z(j),className:"flex items-center gap-1.5 flex-1 text-text-secondary hover:text-text-primary cursor-pointer truncate",children:[n(C0,{name:S.name,type:"dir",expanded:H[j]?.expanded},void 0,!1,void 0,this),n("span",{className:"truncate",children:S.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this),n("button",{onClick:(y)=>{y.stopPropagation(),P(j)},className:"text-[11px] text-text-tertiary hover:text-text-secondary opacity-0 group-hover/item:opacity-100 transition-opacity px-1 flex-shrink-0",title:"Add all files in folder",children:"+"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):n(e4,{children:[n("span",{onClick:()=>K(j),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:[n(C0,{name:S.name,type:"file"},void 0,!1,void 0,this),n("span",{className:"truncate",children:S.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this),n("div",{className:"flex items-center gap-1 flex-shrink-0 ml-1",children:[R>0&&n("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),n("button",{onClick:(y)=>{y.stopPropagation(),N(j)},className:"text-[11px] text-text-tertiary hover:text-text-secondary opacity-0 group-hover/item:opacity-100 transition-opacity px-1",title:"Add file to context",children:"+"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),S.type==="dir"&&T(j,F+1)]},j,!0,void 0,this)})};if($)return n(e4,{children:[n("div",{className:"flex items-center justify-between px-4 pt-3 pb-2 flex-shrink-0",children:n("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),n("div",{className:"flex-1 overflow-y-auto",children:T("")},void 0,!1,void 0,this),U.length>0&&n("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:[n("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((O)=>n("div",{onClick:()=>K(O),className:"flex items-center justify-between text-[12px] font-body text-text-secondary hover:text-text-primary cursor-pointer py-0.5",children:[n("span",{className:"truncate",children:O.split("/").pop()},void 0,!1,void 0,this),n("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:M(O)},void 0,!1,void 0,this)]},O,!0,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);if(G)return n("div",{className:"hidden lg:flex w-8 border-r border-border-subtle bg-bg-surface flex-col items-center flex-shrink-0",children:n("button",{onClick:()=>X(!1),className:"mt-3 p-1 text-text-tertiary hover:text-text-secondary transition-colors",children:n("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:n("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 n("div",{className:"hidden lg:flex w-60 border-r border-border-subtle bg-bg-surface flex-col flex-shrink-0 overflow-hidden",children:[n("div",{className:"flex items-center justify-between px-4 pt-4 pb-3 flex-shrink-0",children:[n("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:"Files"},void 0,!1,void 0,this),n("button",{onClick:()=>X(!0),className:"text-text-tertiary hover:text-text-secondary transition-colors p-0.5",children:n("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:n("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),n("div",{className:"flex-1 overflow-y-auto",children:T("")},void 0,!1,void 0,this),U.length>0&&n("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:[n("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((O)=>n("div",{onClick:()=>K(O),className:"flex items-center justify-between text-[12px] font-body text-text-secondary hover:text-text-primary cursor-pointer py-0.5",children:[n("span",{className:"truncate",children:O.split("/").pop()},void 0,!1,void 0,this),n("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:M(O)},void 0,!1,void 0,this)]},O,!0,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}import{SessionContext as pQ}from"#canvas/runtime";import{useCallback as cQ,useContext as lQ,useEffect as $6,useMemo as J6,useRef as n2,useState as U2}from"react";import{jsxDEV as R$}from"react/jsx-dev-runtime";function Q6($){let J=$ instanceof HTMLElement?$:$.parentElement;while(J){if(J.hasAttribute("data-line-num"))return J;J=J.parentElement}return null}function dQ($){let J=$.toString().trim(),Q=Q6($.startContainer),Y=Q6($.endContainer),q=Q?parseInt(Q.getAttribute("data-line-num"),10):void 0,G=Y?parseInt(Y.getAttribute("data-line-num"),10):void 0,X="",H="";if(J.length<30&&Q&&Q===Y){let _=Q.querySelector("code");if(_){let W=_.textContent||"",U=W.indexOf(J);if(U>=0)X=W.slice(0,U).trimStart(),H=W.slice(U+J.length).trimEnd()}}return{before:X,after:H,hierarchy:[],lineStart:q,lineEnd:G}}function rQ({html:$}){return R$("code",{className:"py-px",dangerouslySetInnerHTML:{__html:$}},void 0,!1,void 0,this)}function q6({path:$}){if(!B0)return R$("div",{className:"max-w-[720px] mx-auto px-6 pt-12 pb-32",children:R$("div",{className:"p-4 rounded-lg border border-border-subtle bg-bg-surface",children:[R$("div",{className:"text-[11px] uppercase tracking-widest text-text-tertiary font-body mb-2",children:"File not available"},void 0,!1,void 0,this),R$("p",{className:"text-[13px] text-text-secondary font-body leading-relaxed",children:["Opening ",R$("code",{className:"px-1 py-0.5 rounded bg-bg-elevated text-text-primary text-[11px]",children:$},void 0,!1,void 0,this)," ","requires filesystem access, which isn't available in shared view. If the canvas author wanted this file visible, they should embed it as a"," ",R$("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);return R$(iQ,{path:$},void 0,!1,void 0,this)}function iQ({path:$}){let J=lQ(pQ),{annotations:Q}=q0(),[Y,q]=U2(null),[G,X]=U2(!0),[H,_]=U2(null),W=n2(null),[U,B]=U2(null),[z,K]=U2(null),N=n2(null),P=n2(null),M=n2([]),T=Q.filter((I)=>I.filePath===$),O=W.current?.closest("#plan-scroll-container"),{popovers:F,openCreatePopover:w}=V0({containerRef:W,restoreKey:`${Y}:${$}`,restoreAnnotations:T,extractContext:dQ,filePath:$,scrollContainer:O});$6(()=>{X(!0),_(null),fetch(`/api/file?session=${J}&path=${encodeURIComponent($)}`).then((I)=>I.json()).then((I)=>{let Z=Z0.parse(I);if("error"in Z)_(Z.error),X(!1);else q(Z.content),X(!1)}).catch(()=>{_("Failed to fetch file"),X(!1)})},[J,$]);let S=cQ((I,Z)=>{I.preventDefault(),N.current=Z,P.current=Z,B(Z),K(Z)},[]);$6(()=>{let I=(f)=>{if(N.current===null)return;let u=f.target.closest("[data-line-num]");if(u){let o=parseInt(u.getAttribute("data-line-num"),10);P.current=o,K(o)}},Z=()=>{let f=N.current;if(f===null)return;N.current=null;let u=P.current??f,o=Math.min(f,u),K$=Math.max(f,u),W$=M.current.slice(o-1,K$).join(`
82
+ `);if(!W$.trim()){B(null),K(null);return}let U$=`__pending_${Date.now()}`,z$={before:"",after:"",hierarchy:[],lineStart:o,lineEnd:K$};if(W.current){let $$=W.current.querySelectorAll("[data-line-num]"),X$=$$[o-1],L$=$$[K$-1];if(X$&&L$){let d=X$.querySelector("code"),J$=L$.querySelector("code");if(d&&J$)try{let b=document.createRange();b.setStartBefore(d.firstChild||d),b.setEndAfter(J$.lastChild||J$),O0(b,U$)}catch{}}let a=$$[K$-1];if(a)w(a,U$,W$,z$)}B(null),K(null)};return document.addEventListener("mousemove",I),document.addEventListener("mouseup",Z),()=>{document.removeEventListener("mousemove",I),document.removeEventListener("mouseup",Z)}},[]);let j=J6(()=>{if(!Y)return null;let I=window.hljs;if(!I)return null;let Z=$.split(".").pop()||"",f=o2[Z];try{return(f?I.highlight(Y,{language:f}):I.highlightAuto(Y)).value.split(`
83
+ `)}catch{return null}},[Y,$]),R=J6(()=>{if(U===null)return null;let I=z??U;return{start:Math.min(U,I),end:Math.max(U,I)}},[U,z]);if(G)return R$("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-[13px]",children:["Loading ",$,"..."]},void 0,!0,void 0,this);if(H)return R$("div",{className:"p-8 text-accent-red font-body text-[13px]",children:H},void 0,!1,void 0,this);if(!Y)return null;let y=Y.split(`
84
+ `);return M.current=y,R$("div",{children:[R$("pre",{ref:W,className:"text-code font-mono text-text-code bg-bg-base select-text cursor-text py-3 hljs",children:y.map((I,Z)=>{let f=Z+1,u=R&&f>=R.start&&f<=R.end;return R$("div",{"data-line-num":f,className:`flex px-5 ${u?"bg-accent-blue/10":"hover:bg-bg-elevated-half"}`,children:[R$("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:(o)=>S(o,f),children:f},void 0,!1,void 0,this),j?R$(rQ,{html:j[Z]||" "},void 0,!1,void 0,this):R$("code",{className:"py-px",children:I||" "},void 0,!1,void 0,this)]},Z,!0,void 0,this)})},void 0,!1,void 0,this),F]},void 0,!0,void 0,this)}import{SessionContext as oQ}from"#canvas/runtime";import{useCallback as Y6,useContext as $3,useEffect as X6,useMemo as aQ,useRef as B2,useState as N0}from"react";import{jsxDEV as i}from"react/jsx-dev-runtime";function J3($,J){if(!$)return[];return $.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 G6($){return $.filter((J)=>J.status!=="unchanged").map((J)=>J.filename)}function _6({revision:$,responseBanner:J}){let{setActiveView:Q}=$3($0),{revisions:Y}=$3(E$),q=Y.find((W)=>W.revision===$),G=Y.find((W)=>W.revision===$-1),X=aQ(()=>J3(q,G),[q,G]),H=X.filter((W)=>W.status!=="unchanged"),_=X.filter((W)=>W.status==="unchanged");return i("div",{className:"max-w-[720px] mx-auto px-6 pt-12 pb-32",children:[J,H.map((W)=>i(sQ,{change:W,revision:$,previousRevision:G?.revision,onOpenTab:()=>Q({type:"canvas",filename:W.filename})},W.filename,!1,void 0,this)),_.length>0&&i("div",{className:"mt-8 border-t border-border-subtle pt-4",children:[i("div",{className:"text-[11px] font-body font-medium uppercase tracking-widest text-text-tertiary mb-3",children:"Unchanged"},void 0,!1,void 0,this),_.map((W)=>i(J7,{change:W,revision:$,onOpenTab:()=>Q({type:"canvas",filename:W.filename})},W.filename,!1,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function nQ({mode:$,onChange:J,showDiff:Q}){if(!Q)return null;return i("div",{className:"flex items-center bg-bg-elevated rounded-md p-0.5",children:["rendered","unified","side-by-side"].map((Y)=>i("button",{onClick:()=>J(Y),className:`text-[10px] font-body px-2 py-0.5 rounded transition-colors ${$===Y?"bg-bg-surface text-text-primary font-medium shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:Y==="rendered"?"Full":Y==="unified"?"Unified":"Split"},Y,!1,void 0,this))},void 0,!1,void 0,this)}function sQ({change:$,revision:J,previousRevision:Q,onOpenTab:Y}){let q=$.filename.replace(/\.jsx$/,""),G=$.status==="new",X=$.diffStats,H=$.status==="changed"&&Q!=null,[_,W]=N0("rendered");return i("div",{className:"mb-8",children:[i("div",{className:"flex items-center gap-2 mb-3 pb-2 border-b border-border-subtle",children:[i("span",{className:`text-[11px] font-mono px-1.5 py-0.5 rounded ${G?"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:G?"new":"modified"},void 0,!1,void 0,this),i("span",{className:"text-[14px] font-body font-medium text-text-primary",children:q},void 0,!1,void 0,this),X&&(X.added>0||X.removed>0)&&i("span",{className:"text-[11px] font-mono text-text-tertiary",children:[i("span",{className:"text-accent-green",children:["+",X.added]},void 0,!0,void 0,this)," ",i("span",{className:"text-accent-red",children:["-",X.removed]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),i(nQ,{mode:_,onChange:W,showDiff:H},void 0,!1,void 0,this),i("button",{onClick:Y,className:`${H?"":"ml-auto"} text-[11px] font-body font-medium text-accent-blue hover:text-accent-blue/80 transition-colors`,children:"Open in tab"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),_==="rendered"?i("div",{"data-canvas-file":$.filename,children:i(b1,{revision:J,filename:$.filename},void 0,!1,void 0,this)},void 0,!1,void 0,this):H&&Q!=null?i(tQ,{filename:$.filename,leftRev:Q,rightRev:J,mode:_},`${_}-${J}-${Q}`,!1,void 0,this):null]},void 0,!0,void 0,this)}function tQ({filename:$,leftRev:J,rightRev:Q,mode:Y}){let q=$3(oQ);if(Y==="unified")return i(eQ,{sessionId:q,filename:$,leftRev:J,rightRev:Q},void 0,!1,void 0,this);return i($7,{sessionId:q,filename:$,leftRev:J,rightRev:Q},void 0,!1,void 0,this)}function eQ({sessionId:$,filename:J,leftRev:Q,rightRev:Y}){let q=B2(null),G=B2(null),X=B2(null),[H,_]=N0(!1),[W,U]=N0(!1),[B,z]=N0(!1),[K,N]=N0(null);return X6(()=>{if(!H||!W||B)return;if(!q.current||!G.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!q.current||!G.current||!X.current)return;try{let P=V1(q.current),M=V1(G.current),T=H2(P,M),{fragment:O}=r2(T);X.current.innerHTML="",X.current.appendChild(O),z(!0)}catch(P){N(P instanceof Error?P.message:String(P))}})})},[H,W,B]),i("div",{children:[!B&&!K&&i("div",{style:{position:"absolute",left:-9999,visibility:"hidden",pointerEvents:"none",width:720},children:[i(z0,{ref:q,sessionId:$,revision:Q,filename:J,onReady:()=>_(!0),onError:(P)=>N(P)},void 0,!1,void 0,this),i(z0,{ref:G,sessionId:$,revision:Y,filename:J,onReady:()=>U(!0),onError:(P)=>N(P)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!B&&!K&&i("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),K&&i("div",{className:"text-accent-red text-[13px] font-body p-3 bg-accent-red-muted rounded-lg",children:K},void 0,!1,void 0,this),i("div",{ref:X},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function $7({sessionId:$,filename:J,leftRev:Q,rightRev:Y}){let q=B2(null),G=B2(null),[X,H]=N0(!1),[_,W]=N0(!1),[U,B]=N0(!1),z=Y6(()=>H(!0),[]),K=Y6(()=>W(!0),[]);return X6(()=>{if(!X||!_||U)return;if(!q.current||!G.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!q.current||!G.current)return;d2(q.current,G.current),B(!0)})})},[X,_,U]),i("div",{className:"flex gap-0 border-y border-border-subtle overflow-hidden w-screen relative left-1/2 -translate-x-1/2",children:[i("div",{className:"w-1/2 border-r border-border-subtle",children:[i("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),i("div",{className:"px-6 py-4 max-w-[600px] mx-auto",children:i(z0,{ref:q,sessionId:$,revision:Q,filename:J,onReady:z},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),i("div",{className:"w-1/2",children:[i("div",{className:"px-2 py-1 text-[10px] font-body font-medium text-text-tertiary bg-bg-elevated border-b border-border-subtle",children:["Rev ",Y]},void 0,!0,void 0,this),i("div",{className:"px-6 py-4 max-w-[600px] mx-auto",children:i(z0,{ref:G,sessionId:$,revision:Y,filename:J,onReady:K},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 J7({change:$,revision:J,onOpenTab:Q}){let[Y,q]=N0(!1),G=$.filename.replace(/\.jsx$/,"");return i("div",{className:"mb-2",children:[i("div",{className:"flex items-center gap-2 py-1.5",children:[i("button",{onClick:()=>q(!Y),className:"text-text-tertiary hover:text-text-secondary transition-colors",children:i("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",className:`transition-transform duration-150 ${Y?"rotate-90":""}`,children:i("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),i("span",{className:"text-[13px] font-body text-text-secondary",children:G},void 0,!1,void 0,this),i("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),Y&&i("div",{className:"ml-5 mt-1 mb-3","data-canvas-file":$.filename,children:i(b1,{revision:J,filename:$.filename},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{useEffect as Q7,useRef as q7,useState as Y7}from"react";import{jsxDEV as l$}from"react/jsx-dev-runtime";function H6({open:$,onClose:J,onSubmit:Q}){let[Y,q]=Y7(""),G=q7(null);if(Q7(()=>{if($)q(""),setTimeout(()=>G.current?.focus(),50)},[$]),!$)return null;let X=Y.trim(),H=X.length>=1&&X.length<=80,_=()=>{if(!H)return;Q(X)};return l$("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:J,children:l$("div",{className:"bg-bg-surface border border-border-medium rounded-lg shadow-xl w-full max-w-md mx-4 p-5",onClick:(W)=>W.stopPropagation(),children:[l$("div",{className:"flex items-center justify-between mb-3",children:[l$("h2",{className:"text-sm font-medium text-text-primary font-body",children:"Your name"},void 0,!1,void 0,this),l$("button",{onClick:J,className:"w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",children:l$("span",{className:"text-xs",children:"✕"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),l$("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),l$("input",{ref:G,type:"text",value:Y,onChange:(W)=>q(W.target.value),onKeyDown:(W)=>{if(W.key==="Enter")_()},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),l$("div",{className:"flex justify-end gap-2 mt-4",children:[l$("button",{onClick:J,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),l$("button",{onClick:_,disabled:!H,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{useEffect as W6,useRef as X7,useState as U6}from"react";import{jsxDEV as Y0}from"react/jsx-dev-runtime";function B6($,J){if(J){let Q=J.replace(/\/+$/,"").split("/");return Q[Q.length-1]||$}return $.length>30?$.slice(0,30)+"...":$}function Q3({currentSessionId:$,projectRoot:J}){let[Q,Y]=U6([]),[q,G]=U6(!1),X=X7(null);W6(()=>{if(!B0)return;let W=async()=>{try{let z=await(await fetch("/api/sessions")).json();Y((K)=>{let N=JSON.stringify(z);return JSON.stringify(K)===N?K:z})}catch{}};W();let U=setInterval(W,5000);return()=>clearInterval(U)},[]),W6(()=>{if(!q)return;let W=(U)=>{if(X.current&&!X.current.contains(U.target))G(!1)};return document.addEventListener("mousedown",W),()=>document.removeEventListener("mousedown",W)},[q]);let H=Q.filter((W)=>W.id!==$),_=B6($,J);return Y0("div",{className:"relative",ref:X,children:[Y0("div",{className:"flex items-center gap-1.5 font-body text-body font-medium",children:[Y0("a",{href:`/s/${$}`,className:"text-text-primary hover:text-text-secondary transition-colors",children:_},void 0,!1,void 0,this),H.length>0&&Y0("button",{onClick:()=>G(!q),className:"flex items-center justify-center text-text-tertiary hover:text-text-secondary transition-colors",children:Y0("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:`transition-transform duration-200 ${q?"rotate-180":""}`,children:Y0("path",{d:"M3 5l3 3 3-3",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),q&&H.length>0&&Y0("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:H.map((W)=>Y0("a",{href:`/s/${W.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:[Y0("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${W.currentRevision>0?"bg-accent-green":"bg-border-hover"}`},void 0,!1,void 0,this),Y0("span",{className:"truncate",children:B6(W.id,W.projectRoot)},void 0,!1,void 0,this)]},W.id,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{useCallback as q3,useEffect as G7,useState as s2}from"react";import{jsxDEV as Y$}from"react/jsx-dev-runtime";function K6({sessionId:$,revision:J,open:Q,shareEnabled:Y,existingShares:q,onClose:G,onShareCreated:X,onShareRevoked:H}){let[_,W]=s2(!1),[U,B]=s2(!1),[z,K]=s2(null),[N,P]=s2(!1),M=q.find((w)=>w.revision===J);G7(()=>{if(!Q)W(!1),B(!1),K(null),P(!1)},[Q]);let T=q3(async()=>{W(!0),K(null);try{let w=await fetch(`/api/session/${$}/revision/${J}/share`,{method:"POST"}),S=b5.parse(await w.json());if(!S.ok)throw Error(S.error||`HTTP ${w.status}`);if(!w.ok)throw Error(`HTTP ${w.status}`);X(S.share)}catch(w){K(W2(w))}finally{W(!1)}},[$,J,X]),O=q3(async(w)=>{if(!window.confirm("Revoke this share link? Reviewers will no longer be able to view or comment."))return;B(!0),K(null);try{let S=await fetch(`/api/session/${$}/shares/${w}/revoke`,{method:"POST"}),j=V5.parse(await S.json());if(!j.ok)throw Error(j.error||`HTTP ${S.status}`);if(!S.ok)throw Error(`HTTP ${S.status}`);H(w)}catch(S){K(W2(S))}finally{B(!1)}},[$,H]),F=q3((w)=>{navigator.clipboard.writeText(w).then(()=>{P(!0),setTimeout(()=>P(!1),1500)})},[]);if(!Q)return null;return Y$("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:G,children:Y$("div",{className:"bg-bg-surface border border-border-medium rounded-lg shadow-xl w-full max-w-md mx-4 p-5",onClick:(w)=>w.stopPropagation(),children:[Y$("div",{className:"flex items-center justify-between mb-3",children:[Y$("h2",{className:"text-sm font-medium text-text-primary font-body",children:"Share this revision"},void 0,!1,void 0,this),Y$("button",{onClick:G,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:Y$("span",{className:"text-xs",children:"✕"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!Y?Y$("div",{className:"text-[13px] text-text-secondary font-body space-y-2",children:[Y$("p",{children:"Canvas sharing is not configured."},void 0,!1,void 0,this),Y$("p",{className:"text-text-tertiary",children:["Set ",Y$("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"," ",Y$("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):M?Y$("div",{className:"space-y-3",children:[Y$("p",{className:"text-[13px] text-text-secondary font-body",children:"This revision is shared:"},void 0,!1,void 0,this),Y$("div",{className:"flex gap-2",children:[Y$("input",{type:"text",readOnly:!0,value:M.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:(w)=>w.currentTarget.select()},void 0,!1,void 0,this),Y$("button",{onClick:()=>F(M.url),className:"px-3 py-1.5 text-[12px] font-body font-medium rounded bg-accent-blue text-white hover:opacity-90 transition-opacity whitespace-nowrap",children:N?"Copied!":"Copy"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),M.expiresAt&&Y$("p",{className:"text-[11px] text-text-tertiary font-body",children:["Expires ",new Date(M.expiresAt).toLocaleDateString(),"."]},void 0,!0,void 0,this),M.encryptionKey&&Y$("p",{className:"text-[11px] text-accent-green font-body flex items-center gap-1.5",children:[Y$("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[Y$("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"},void 0,!1,void 0,this),Y$("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),Y$("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),Y$("div",{className:"flex items-center justify-between pt-1",children:[Y$("button",{onClick:T,disabled:_||U,className:"text-[11px] text-text-tertiary hover:text-text-secondary font-body underline disabled:opacity-50",children:_?"Creating...":"Create a new link"},void 0,!1,void 0,this),M.ownerToken&&Y$("button",{onClick:()=>O(M.shareId),disabled:_||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):Y$("div",{className:"space-y-3",children:[Y$("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),Y$("button",{onClick:T,disabled:_,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:_?"Creating share link...":"Create share link"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),z&&Y$("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:z},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function z6({onClick:$,title:J="Share this revision",hasShare:Q}){return Y$("button",{onClick:$,className:`group p-1.5 transition-colors ${Q?"text-accent-blue hover:opacity-80":"text-text-tertiary hover:text-text-secondary"}`,title:J,children:Y$("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[Y$("circle",{cx:"18",cy:"5",r:"3"},void 0,!1,void 0,this),Y$("circle",{cx:"6",cy:"12",r:"3"},void 0,!1,void 0,this),Y$("circle",{cx:"18",cy:"19",r:"3"},void 0,!1,void 0,this),Y$("line",{x1:"8.59",y1:"13.51",x2:"15.42",y2:"17.49"},void 0,!1,void 0,this),Y$("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{jsxDEV as L,Fragment as K2}from"react/jsx-dev-runtime";function M6($){let J=[];for(let Q of $)for(let Y of Q.annotations)J.push({...Y,source:"remote",author:Q.author});return J}function U7($){if($==="auto")return window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light";return $}function O6($){document.documentElement.dataset.theme=U7($)}function S6(){let[$,J]=O$(()=>{let q=localStorage.getItem("canvas-theme");if(q==="light"||q==="dark"||q==="auto")return q;return"auto"});return d$(()=>{if(O6($),$!=="auto")return;let q=window.matchMedia("(prefers-color-scheme: dark)"),G=()=>O6("auto");return q.addEventListener("change",G),()=>q.removeEventListener("change",G)},[$]),L("button",{onClick:()=>{let q=$==="auto"?"light":$==="light"?"dark":"auto";localStorage.setItem("canvas-theme",q),J(q)},className:"w-7 h-7 flex items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:{auto:"Theme: system (click for light)",light:"Theme: light (click for dark)",dark:"Theme: dark (click for system)"}[$],children:$==="auto"?L("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[L("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2",ry:"2"},void 0,!1,void 0,this),L("line",{x1:"8",y1:"21",x2:"16",y2:"21"},void 0,!1,void 0,this),L("line",{x1:"12",y1:"17",x2:"12",y2:"21"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):$==="dark"?L("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:L("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):L("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[L("circle",{cx:"12",cy:"12",r:"5"},void 0,!1,void 0,this),L("line",{x1:"12",y1:"1",x2:"12",y2:"3"},void 0,!1,void 0,this),L("line",{x1:"12",y1:"21",x2:"12",y2:"23"},void 0,!1,void 0,this),L("line",{x1:"4.22",y1:"4.22",x2:"5.64",y2:"5.64"},void 0,!1,void 0,this),L("line",{x1:"18.36",y1:"18.36",x2:"19.78",y2:"19.78"},void 0,!1,void 0,this),L("line",{x1:"1",y1:"12",x2:"3",y2:"12"},void 0,!1,void 0,this),L("line",{x1:"21",y1:"12",x2:"23",y2:"12"},void 0,!1,void 0,this),L("line",{x1:"4.22",y1:"19.78",x2:"5.64",y2:"18.36"},void 0,!1,void 0,this),L("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 P6(){let{currentRevision:$,selectedRevision:J,revisions:Q,setSelectedRevision:Y,setCompareRevision:q}=y0.useContext(E$);if(Q.length<=1){let H=Q[0]?.label||`Round ${$}`;return L("span",{className:"text-[11px] text-text-tertiary font-body",children:H},void 0,!1,void 0,this)}return L("div",{className:"flex flex-col gap-1",children:[L(G2,{value:J,onChange:Y,accent:J===$?"default":"amber"},void 0,!1,void 0,this),L("button",{onClick:()=>{let X;if(J===$)X=[...Q].reverse().find((_)=>_.revision<$)?.revision??Math.max(1,$-1);else X=J;q({left:X,right:$})},className:"text-[11px] font-body font-medium px-2 py-0.5 rounded-md text-accent-blue hover:bg-accent-blue-muted transition-colors self-start",children:"Compare"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function B7(){let $=B$.isShared?B$.shareId:B$.sessionId,J=B$.isShared,[Q,Y]=O$(1),[q,G]=O$(1),[X,H]=O$([]),[_,W]=O$(null),[U,B]=O$(!1),[z,K]=O$(!1),[N,P]=O$(!1),[M,T]=O$([]),[O,F]=O$({type:"overview"}),[w,S]=O$([]),j=X0(null),R=X0([]),y=X0(new Set),[I,Z]=O$(),[f,u]=O$(!1),[o,K$]=O$(!1),[l,W$]=O$(!1),[U$,z$]=O$(!1),[$$,X$]=O$([]),[L$,a]=O$(!1),[d,J$]=O$(new Map),[b,m]=O$(!1),[G$,E]=O$(null),[x,r]=O$(null),M$=Z1((D)=>{if(J)return;let s=`${D.revision}\x00${D.filename}\x00${D.message}`;if(y.current.has(s))return;y.current.add(s);let _$=JSON.stringify({type:"render-error",error:D});if(j.current?.readyState===WebSocket.OPEN)j.current.send(_$);else R.current.push(D)},[J]);d$(()=>{if(!x)return;let D=setTimeout(()=>r(null),4000);return()=>clearTimeout(D)},[x]),d$(()=>{let D=["Agent Canvas"];if(I){let s=I.replace(/\/+$/,"").split("/");D.push(s[s.length-1]||$)}else if($)D.push($);if(O.type==="file")D.push(O.path.split("/").pop()||O.path);else if(O.type==="overview")D.push("Overview");else if(O.type==="canvas"&&M.length>1&&O.filename)D.push(O.filename.replace(/\.jsx$/,""));else if(_)D.push("Compare");document.title=D.join(" — ")},[$,I,O,_]);let F$=X0(new Map),w$=X.find((D)=>D.revision===q),r$=q!==Q||!!w$?.hasFeedback||z,Y3=q===Q&&(!!w$?.hasFeedback||z)?"next":"current",X3=Z1((D)=>{let s=O.type==="overview"?"overview":O.type==="canvas"?`canvas:${O.filename}`:`file:${O.path}`;if(F$.current.set(s,window.scrollY),F(D),D.type==="file")S((_$)=>_$.includes(D.path)?_$:[..._$,D.path])},[O]),w6=Z1((D)=>{F$.current.delete(`file:${D}`),S((s)=>s.filter((_$)=>_$!==D)),F((s)=>{if(s.type==="file"&&s.path===D)return M.length>1?{type:"overview"}:{type:"canvas",filename:M[0]||""};return s})},[M]);H7(()=>{let D=O.type==="overview"?"overview":O.type==="canvas"?`canvas:${O.filename}`:`file:${O.path}`;window.scrollTo(0,F$.current.get(D)||0)},[O]),d$(()=>{if(!$)return;I5().then((D)=>{if(D.currentRevision){let s=D.revisions||[];for(let _$ of s)if(_$.hasFeedback)r0(localStorage,$,_$.revision);D2(localStorage,$,D.currentRevision,s),Y(D.currentRevision),G(D.currentRevision),H(s)}if(D.canvasFiles){let s=D.canvasFiles.sort();T(s),F((_$)=>{if(_$.type==="overview")return s.length>1?_$:{type:"canvas",filename:s[0]||""};if(_$.type==="canvas"&&(!_$.filename||!s.includes(_$.filename)))return{type:"canvas",filename:s[0]||""};return _$})}if(D.projectRoot)Z(D.projectRoot);if(Array.isArray(D.shares))X$(D.shares);a(!!D.shareEnabled)}).catch(()=>{})},[$]),d$(()=>{if(!$||!q||J)return;fetch(`/api/session/${$}/revision/${q}/remote-feedback`).then((D)=>D.json()).then((D)=>{let s=j5.safeParse(D);if(!s.success)return;let _$=M6(s.data.entries);J$((i$)=>{let E0=new Map(i$);return E0.set(q,_$),E0})}).catch(()=>{})},[$,q,J]),d$(()=>{if(!$)return;if(!E5){B(!0);return}let D=null,s=()=>{let _$=window.location.protocol==="https:"?"wss:":"ws:",i$=new WebSocket(`${_$}//${window.location.host}/ws/session/${$}`);j.current=i$,i$.onopen=()=>{B(!0);for(let E0 of R.current)i$.send(JSON.stringify({type:"render-error",error:E0}));R.current=[]},i$.onclose=()=>{B(!1),D=setTimeout(s,2000)},i$.onmessage=(E0)=>{try{let T$=JSON.parse(E0.data);if(T$.type==="plan-updated"){let f$=Array.isArray(T$.revisions)?T$.revisions:[];if(D2(localStorage,$,T$.currentRevision,f$),Y(T$.currentRevision),G(T$.currentRevision),W(null),f$.length>0){H(f$);let M0=f$.find((f0)=>f0.revision===T$.currentRevision);if(M0?.canvasFiles){let f0=M0.canvasFiles.map((R1)=>R1.filename).sort();T(f0);let e2=f$.find((R1)=>R1.revision===T$.currentRevision-1),C1=J3(M0,e2),$1=G6(C1);if($1.length===1)F({type:"canvas",filename:$1[0]});else if($1.length>1||f0.length>1)F({type:"overview"});else F({type:"canvas",filename:f0[0]||""})}}}if(T$.type==="revision-updated"){if(Array.isArray(T$.revisions)){let f$=T$.revisions;for(let M0 of f$)if(M0.hasFeedback)r0(localStorage,$,M0.revision);H(f$)}}if(T$.type==="watcher-status")P(!!T$.watching);if(T$.type==="remote-feedback"){let f$=T$.revision,M0=T$.entries||[],f0=M6(M0);J$((e2)=>{let C1=new Map(e2),$1=C1.get(f$)||[],R1=new Set($1.map(($4)=>$4.id)),T6=[...$1,...f0.filter(($4)=>!R1.has($4.id))];return C1.set(f$,T6),C1})}}catch{}}};return s(),()=>{if(D)clearTimeout(D);j.current?.close()}},[$]);let t2=Z1(async(D,s)=>{try{let _$=localStorage.getItem(`canvas:${$}:rev:${q}`),i$=[];if(_$)try{i$=(S1(JSON.parse(_$))?.annotations??[]).filter((T$)=>T$.source!=="remote")}catch{}await y5({author:s,revision:q,annotations:i$,generalNote:D}),r0(localStorage,$,q),K(!0),r({kind:"success",message:"Feedback submitted. The canvas author will see it shortly."})}catch(_$){r({kind:"error",message:`Failed to submit feedback: ${W2(_$)}`})}},[$,q]),G3=Z1(async(D)=>{if(J){let s=n4();if(!s){E(D),m(!0);return}await t2(D,s);return}if(j.current?.readyState===WebSocket.OPEN)j.current.send(JSON.stringify({type:"submit",feedback:D}))},[J,t2]);if(!$)return L("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 L(y2.Provider,{value:f5,children:L(A6.Provider,{value:$,children:L(q2.Provider,{value:M$,children:L(E$.Provider,{value:{currentRevision:Q,selectedRevision:q,revisions:X,setSelectedRevision:G,isReadOnly:r$,compareRevision:_,setCompareRevision:W,agentWatching:N},children:L(k4,{sessionId:$,revision:q,isReadOnly:r$,draftPhase:Y3,remoteAnnotations:d.get(q),canvasFiles:M,children:L($0.Provider,{value:{activeView:O,setActiveView:X3,openFiles:w,closeFile:w6,canvasFiles:M},children:L(_7.Provider,{value:{setActiveView:X3},children:L("div",{className:"min-h-screen bg-bg-base",children:[L(K7,{sessionId:$,projectRoot:I,connected:U,onMobileSidebar:()=>u(!f),collapsed:o,onToggle:()=>K$((D)=>!D)},void 0,!1,void 0,this),L(z7,{collapsed:l,onToggle:()=>W$((D)=>!D),children:L(p2,{onSubmit:G3},void 0,!1,void 0,this)},void 0,!1,void 0,this),_!==null?L("div",{className:`${o?"lg:ml-0":"lg:ml-60"} ${l?"lg:mr-0":"lg:mr-[var(--sidebar-width,320px)]"} transition-[margin] duration-200`,children:L(a5,{initialLeft:_.left,initialRight:_.right,sessionId:$,onExit:()=>W(null)},void 0,!1,void 0,this)},void 0,!1,void 0,this):L("div",{className:`relative ${o?"lg:ml-0":"lg:ml-60"} ${l?"lg:mr-0":"lg:mr-[var(--sidebar-width,320px)]"} transition-[margin] duration-200`,id:"plan-scroll-container",children:[L("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:[L("div",{className:"flex items-center gap-2",children:[!J&&L(Q3,{currentSessionId:$,projectRoot:I},void 0,!1,void 0,this),J&&L("span",{className:"text-[11px] text-text-tertiary font-body",children:"Shared canvas"},void 0,!1,void 0,this),!J&&L("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),L("div",{className:"flex items-center gap-1",children:[L(P6,{},void 0,!1,void 0,this),L("button",{onClick:()=>u(!f),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:L("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:L("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),L(S6,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),L(N7,{},void 0,!1,void 0,this),O.type==="overview"&&L(_6,{revision:q,responseBanner:w$?.response?L(L6,{markdown:w$.response},void 0,!1,void 0,this):void 0},void 0,!1,void 0,this),O.type==="canvas"&&M.includes(O.filename)&&L("div",{className:"relative max-w-[720px] mx-auto px-6 pt-12 pb-32",children:[L$&&L("div",{className:"absolute top-3 right-12 z-10",children:L(z6,{onClick:()=>z$(!0),hasShare:$$.some((D)=>D.revision===q),title:$$.some((D)=>D.revision===q)?"Manage share link":"Share this revision"},void 0,!1,void 0,this)},void 0,!1,void 0,this),L("button",{onClick:()=>{let D=document.querySelector(`[data-canvas-file="${O.filename}"] .plan-content`);if(!D)return;let s=n5(D);navigator.clipboard.writeText(s).then(()=>{let _$=document.getElementById("export-md-btn");if(_$)_$.setAttribute("data-copied","true"),setTimeout(()=>{_$.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:[L("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:[L("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"},void 0,!1,void 0,this),L("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),L("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:L("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),M.length<=1&&w$?.response&&L(L6,{markdown:w$.response},void 0,!1,void 0,this),L("div",{"data-canvas-file":O.filename,children:L(b1,{revision:q,filename:O.filename},O.filename,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),w.map((D)=>L("div",{style:{display:O.type==="file"&&O.path===D?void 0:"none"},children:L(q6,{path:D},void 0,!1,void 0,this)},D,!1,void 0,this))]},void 0,!0,void 0,this),f&&L("div",{className:"lg:hidden fixed inset-0 z-40 flex",children:[L("div",{className:"flex-1",onClick:()=>u(!1)},void 0,!1,void 0,this),L("div",{className:"w-80 max-w-[85vw] bg-bg-surface border-l border-border-subtle flex flex-col shadow-lg",children:[L("div",{className:"flex items-center justify-between px-4 py-2 border-b border-border-subtle flex-shrink-0",children:[L("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:"Sidebar"},void 0,!1,void 0,this),L("button",{onClick:()=>u(!1),className:"text-text-tertiary hover:text-text-secondary w-7 h-7 flex items-center justify-center",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),L("div",{className:"flex-1 overflow-hidden",children:L(p2,{onSubmit:G3},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),L(K6,{sessionId:$,revision:q,open:U$,shareEnabled:L$,existingShares:$$,onClose:()=>z$(!1),onShareCreated:(D)=>{X$((s)=>[...s.filter((_$)=>_$.shareId!==D.shareId),D]),r({kind:"success",message:"Share link created. Copy and send it to reviewers."})},onShareRevoked:(D)=>{X$((s)=>s.filter((_$)=>_$.shareId!==D)),r({kind:"success",message:"Share link revoked."})}},void 0,!1,void 0,this),L(H6,{open:b,onClose:()=>{m(!1),E(null)},onSubmit:async(D)=>{let s=k5(D);if(m(!1),G$!==null)await t2(G$,s),E(null)}},void 0,!1,void 0,this),x&&L("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 ${x.kind==="error"?"bg-accent-red text-white":"bg-accent-green text-white"}`,children:[x.message,L("button",{onClick:()=>r(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)},`${$}:${q}:${Y3}`,!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 K7({sessionId:$,projectRoot:J,connected:Q,onMobileSidebar:Y,collapsed:q,onToggle:G}){let X=B$.isShared;return L(K2,{children:[q&&L("button",{onClick:G,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:L("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[L("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"},void 0,!1,void 0,this),L("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),L("div",{className:`hidden lg:flex w-60 flex-col fixed top-0 left-0 bottom-0 bg-bg-surface border-r border-border-subtle z-10 transition-transform duration-200 ${q?"-translate-x-full":""}`,children:[L("div",{className:"px-4 pt-4 pb-3 flex-shrink-0 border-b border-border-subtle",children:[L("div",{className:"flex items-center gap-2 mb-2",children:[L("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",className:"text-text-tertiary flex-shrink-0",children:L("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?L("span",{className:"text-[12px] font-body text-text-secondary truncate flex-1",children:"Shared canvas"},void 0,!1,void 0,this):L(K2,{children:[L(Q3,{currentSessionId:$,projectRoot:J},void 0,!1,void 0,this),L("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),L("button",{onClick:G,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:L("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[L("polyline",{points:"11 17 6 12 11 7"},void 0,!1,void 0,this),L("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),L(P6,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this),L("div",{className:"flex-1 flex flex-col overflow-hidden",children:L(e5,{embedded:!0},void 0,!1,void 0,this)},void 0,!1,void 0,this),L("div",{className:"px-4 py-3 border-t border-border-subtle flex items-center justify-between flex-shrink-0",children:[L("span",{className:"text-[10px] text-text-tertiary font-body uppercase tracking-widest",children:"Theme"},void 0,!1,void 0,this),L(S6,{},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 z7({children:$,collapsed:J,onToggle:Q}){let[Y,q]=O$(()=>{let U=localStorage.getItem("canvas-sidebar-width");return U?parseInt(U,10):320}),G=X0(!1),X=X0(0),H=X0(0),_=X0(Y);_.current=Y;let W=Z1((U)=>{U.preventDefault(),G.current=!0,X.current=U.clientX,H.current=_.current;let B=(K)=>{if(!G.current)return;let N=X.current-K.clientX,P=Math.max(240,Math.min(600,H.current+N));q(P),_.current=P},z=()=>{G.current=!1,localStorage.setItem("canvas-sidebar-width",String(_.current)),document.removeEventListener("mousemove",B),document.removeEventListener("mouseup",z),document.body.style.cursor="",document.body.style.userSelect=""};document.addEventListener("mousemove",B),document.addEventListener("mouseup",z),document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[]);return d$(()=>{return document.documentElement.style.setProperty("--sidebar-width",`${Y}px`),()=>{document.documentElement.style.removeProperty("--sidebar-width")}},[Y]),L(K2,{children:[J&&L("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:L("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:L("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),L("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 ${J?"translate-x-full":""}`,style:{width:Y},children:[L("div",{onMouseDown:W,className:"absolute left-0 top-0 bottom-0 w-1 cursor-col-resize hover:bg-accent-blue/30 transition-colors z-20",style:{marginLeft:"-2px"}},void 0,!1,void 0,this),y0.Children.map($,(U)=>y0.isValidElement(U)?y0.cloneElement(U,{collapseButton:L("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:L("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[L("polyline",{points:"13 17 18 12 13 7"},void 0,!1,void 0,this),L("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 L6({markdown:$}){let[J,Q]=O$(!1),Y=N6(()=>q$.parse($,{async:!1}),[$]),q=X0(null),{annotations:G,addAnnotationWithId:X,removeAnnotation:H,updateAnnotation:_,addAnnotationImage:W,removeAnnotationImage:U,activeAnnotationId:B,setActiveAnnotationId:z}=q0(),[K,N]=O$(null),[P,M]=O$(null),T=N6(()=>G.filter((j)=>j.filePath===u$),[G]),[O,F]=O$($);if($!==O)F($),Q(!1);d$(()=>{if(!q.current||T.length===0)return;let j=setTimeout(()=>{if(q.current)y1(q.current,T)},50);return()=>clearTimeout(j)},[Y,T.length]);let w=X0(null);if(d$(()=>{D1(B,w.current),w.current=B},[B]),d$(()=>{let j=q.current;if(!j)return;let R=(Z)=>{let f=Z.target.closest("[data-annotation-id]");if(!f)return;Z.stopPropagation();let u=f.getAttribute("data-annotation-id");if(u===B)M({anchorEl:f,annId:u});else z(u)},y=(Z)=>{let f=Z.target.closest("[data-annotation-id]");if(f)z(f.getAttribute("data-annotation-id"))},I=(Z)=>{let f=Z.target.closest("[data-annotation-id]"),u=Z.relatedTarget?.closest?.("[data-annotation-id]");if(f&&!u)z(null)};return j.addEventListener("click",R),j.addEventListener("mouseover",y),j.addEventListener("mouseout",I),()=>{j.removeEventListener("click",R),j.removeEventListener("mouseover",y),j.removeEventListener("mouseout",I)}},[Y,B]),d$(()=>{let j=()=>{let R=window.getSelection();if(!R||R.isCollapsed||!R.toString().trim())return;if(!q.current)return;let y=R.getRangeAt(0);if(!q.current.contains(y.startContainer))return;if(y.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let I=R.toString().trim();if(I.length<2)return;let Z=y.cloneRange(),f=L0(y,q.current),u=`__pending_${Date.now()}`;try{O0(Z,u)}catch{}window.getSelection()?.removeAllRanges();let o=document.querySelectorAll(`[data-annotation-id="${u}"]`),K$=o[o.length-1];if(!K$)return;N({anchorEl:K$,tempId:u,snippet:I,ctx:f})};return document.addEventListener("mouseup",j),()=>document.removeEventListener("mouseup",j)},[]),J)return null;let S=document.getElementById("plan-scroll-container");return L("div",{className:"mb-6 rounded-lg border border-accent-blue/20 bg-accent-blue/5 relative",children:[L("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:L("span",{className:"text-xs",children:"✕"},void 0,!1,void 0,this)},void 0,!1,void 0,this),L("div",{className:"px-4 py-3 pr-10",children:[L("div",{className:"flex items-center gap-2 mb-1.5",children:[L("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:L("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),L("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),L("div",{ref:q,className:"prose-canvas text-sm",dangerouslySetInnerHTML:{__html:Y}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),K&&L(t$,{anchorEl:K.anchorEl,scrollContainer:S,snippet:K.snippet,truncateAt:80,onAdd:(j,R)=>{let y=y$();k1(K.tempId,y),X(y,K.snippet,j,u$,K.ctx,R),N(null)},onCancel:()=>{E1(K.tempId),N(null)}},void 0,!1,void 0,this),P&&(()=>{let j=G.find((R)=>R.id===P.annId);if(!j)return null;return L(l0,{anchorEl:P.anchorEl,scrollContainer:S,initialNote:j.note,initialImages:j.images,onUpdate:(R,y)=>{_(P.annId,R);let I=j.images||[];for(let Z of y)if(!I.includes(Z))W(P.annId,Z);for(let Z of I)if(!y.includes(Z))U(P.annId,Z)},onDelete:()=>{H(P.annId),z(null)},onClose:()=>M(null)},void 0,!1,void 0,this)})()]},void 0,!0,void 0,this)}function N7(){let{activeView:$,setActiveView:J,openFiles:Q,closeFile:Y,canvasFiles:q}=y0.useContext($0),G=y0.useContext(A6),{addAnnotationWithId:X,setActiveAnnotationId:H}=q0();if(!(q.length>1||Q.length>0))return null;return L("div",{className:"flex items-center border-b border-border-medium bg-bg-surface overflow-x-auto sticky top-0 z-10",children:[q.length>1&&L(K2,{children:[L("button",{onClick:()=>J({type:"overview"}),className:`flex items-center gap-1.5 px-4 py-2.5 text-[13px] font-body whitespace-nowrap transition-colors relative ${$.type==="overview"?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[L("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",className:"opacity-60",children:L("path",{d:"M12 7L2 12l10 5 10-5-10-5z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this),"Overview",$.type==="overview"&&L("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),L("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),q.map((W,U)=>{let B=W.replace(/\.jsx$/,""),z=$.type==="canvas"&&$.filename===W;return L(y0.Fragment,{children:[L("button",{onClick:()=>J({type:"canvas",filename:W}),className:`flex items-center gap-1.5 px-4 py-2.5 text-[13px] font-body whitespace-nowrap transition-colors relative ${z?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[B,z&&L("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<q.length-1&&L("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this)]},W,!0,void 0,this)}),Q.length>0&&L(K2,{children:[L("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this),Q.map((W,U)=>{let B=W.split("/").pop()||W,z=$.type==="file"&&$.path===W;return L(y0.Fragment,{children:[L("div",{className:"flex items-center",children:[L("button",{onClick:()=>J({type:"file",path:W}),className:`flex items-center gap-1.5 pl-3 pr-1 py-2.5 text-[13px] font-body whitespace-nowrap transition-colors relative ${z?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[L(C0,{name:B,type:"file"},void 0,!1,void 0,this),B,z&&L("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),L("button",{onClick:(K)=>{K.stopPropagation(),Y(W)},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<Q.length-1&&L("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this)]},W,!0,void 0,this)})]},void 0,!0,void 0,this),L("div",{className:"ml-auto flex items-center gap-1 flex-shrink-0",children:$.type==="file"&&B0&&L("button",{onClick:async()=>{let W=$.path;try{let U=await fetch(`/api/file?session=${G}&path=${encodeURIComponent(W)}`),B=Z0.parse(await U.json());if("content"in B){let z=B.content.split(`
88
85
  `).slice(0,3).join(`
89
- `)+(d.content.split(`
86
+ `)+(B.content.split(`
90
87
  `).length>3?`
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));
88
+ ...`:""),K=y$();X(K,z,"",W),H(K)}}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:[L("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 F6=document.getElementById("root");if(F6)W7(F6).render(L(B7,{},void 0,!1,void 0,this));