agent-canvas 0.9.0-dev.12 → 0.9.0-dev.14

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 (61) hide show
  1. package/README.md +28 -0
  2. package/bin/agent-canvas.ts +8 -1
  3. package/bin/lib/cli-auth.ts +31 -0
  4. package/bin/lib/commands/daemon.ts +2 -1
  5. package/bin/lib/commands/exec.ts +5 -4
  6. package/bin/lib/commands/fetch.ts +4 -4
  7. package/bin/lib/commands/push.ts +3 -2
  8. package/bin/lib/commands/reply.ts +45 -0
  9. package/bin/lib/commands/review.ts +4 -2
  10. package/bin/lib/commands/watch.ts +100 -5
  11. package/bin/lib/helpers.ts +121 -43
  12. package/bin/lib/instructions/component-download.md +28 -0
  13. package/bin/lib/instructions/component-filedrop.md +50 -0
  14. package/bin/lib/instructions/overview.md +41 -1
  15. package/bin/lib/instructions/template-dashboard.md +177 -0
  16. package/bin/lib/instructions/template-slides.md +196 -0
  17. package/bin/lib/instructions/theming.md +25 -0
  18. package/daemon/client/App.tsx +17 -5
  19. package/daemon/client/clientApi.ts +64 -5
  20. package/daemon/client/components/Download.tsx +28 -0
  21. package/daemon/client/components/FileDrop.tsx +164 -0
  22. package/daemon/client/components/index.ts +3 -1
  23. package/daemon/client/threadStore.ts +70 -0
  24. package/daemon/dist/client.css +1 -1
  25. package/daemon/dist/client.js +57 -56
  26. package/daemon/dist/components.js +52 -49
  27. package/daemon/src/admission.ts +102 -0
  28. package/daemon/src/assets.ts +16 -0
  29. package/daemon/src/components.ts +6 -1
  30. package/daemon/src/handlers/api.ts +7 -4
  31. package/daemon/src/handlers/assets.ts +126 -0
  32. package/daemon/src/handlers/files.ts +124 -19
  33. package/daemon/src/handlers/static.ts +65 -1
  34. package/daemon/src/handlers/theme.ts +150 -0
  35. package/daemon/src/handlers/threads.ts +93 -0
  36. package/daemon/src/review/server.ts +1 -1
  37. package/daemon/src/server.ts +81 -47
  38. package/daemon/src/threads.ts +132 -0
  39. package/package.json +4 -4
  40. package/skills/canvas/SKILL.md +5 -0
  41. package/types/bin/lib/cli-auth.d.ts +9 -0
  42. package/types/bin/lib/commands/reply.d.ts +2 -0
  43. package/types/bin/lib/commands/watch.d.ts +3 -1
  44. package/types/bin/lib/helpers.d.ts +102 -0
  45. package/types/daemon/client/clientApi.d.ts +14 -1
  46. package/types/daemon/client/components/Download.d.ts +9 -0
  47. package/types/daemon/client/components/FileDrop.d.ts +12 -0
  48. package/types/daemon/client/components/index.d.ts +2 -0
  49. package/types/daemon/client/threadStore.d.ts +15 -0
  50. package/types/daemon/src/admission.d.ts +24 -0
  51. package/types/daemon/src/assets.d.ts +23 -0
  52. package/types/daemon/src/components.d.ts +3 -1
  53. package/types/daemon/src/handlers/assets.d.ts +14 -0
  54. package/types/daemon/src/handlers/files.d.ts +8 -2
  55. package/types/daemon/src/handlers/static.d.ts +16 -0
  56. package/types/daemon/src/handlers/theme.d.ts +18 -0
  57. package/types/daemon/src/handlers/threads.d.ts +19 -0
  58. package/types/daemon/src/review/model.d.ts +24 -24
  59. package/types/daemon/src/review/remote.d.ts +8 -8
  60. package/types/daemon/src/review/server.d.ts +2 -0
  61. package/types/daemon/src/threads.d.ts +109 -0
@@ -1,88 +1,89 @@
1
- var D6=Object.defineProperty;var k6=($)=>$;function y6($,J){this[$]=k6.bind(null,J)}var E6=($,J)=>{for(var Q in J)D6($,Q,{get:J[Q],enumerable:!0,configurable:!0,set:y6.bind(J,Q)})};import{ActiveViewCtx as M7,SessionContext as V6}from"#canvas/runtime";import{AnnotationCtx as DY,AnnotationHostContext as kY,SessionContext as yY,useAnnotationHost as EY,useAnnotations as fY}from"@fabrika/annotations/runtime";function F1($,J){let Q=[],Y=K3($);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 I0($){let J=$.parentElement;if(J?.classList.contains("select-none"))return!1;if(J?.closest("[data-annotation-id]"))return!1;return!0}function K3($){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(!I0(q))continue;if($.intersectsNode(q))J.push(q)}return J}function f6($,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 B3($){let J="";for(let Q of K3($))J+=f6(Q,$);return J}function J0($,J){let Q=document.querySelectorAll(`[data-annotation-id="${$}"]`);for(let Y of Q)Y.classList.toggle("mark-active",J)}function D0($,J){if(J!=null&&J!==$)J0(J,!1);if($!=null)J0($,!0)}function k0($,J){let Q=document.querySelectorAll(`[data-annotation-id="${$}"]`);for(let Y of Q)Y.setAttribute("data-annotation-id",J)}function y0($,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}=v6($),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,K=W+Y.length,z=U3(G,U),B=U3(G,K);if(!z||!B)continue;try{let N=document.createRange();N.setStart(z.node,z.offset),N.setEnd(B.node,B.offset),F1(N,Q.id)}catch{}}}function v6($){let J=[],Q="",Y=document.createTreeWalker($,NodeFilter.SHOW_TEXT),q;while(q=Y.nextNode()){if(!I0(q))continue;J.push({node:q,start:Q.length}),Q+=q.textContent||""}return{fullText:Q,textNodes:J}}function U3($,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 E0($){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 A1($,J){let Q=z3($,"before",60),Y=z3($,"after",60),q=m6($.startContainer,J);return{before:Q,after:Y,hierarchy:q}}function z3($,J,Q){let Y=g6(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(!I0(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(!I0(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 g6($){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 m6($,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=x6(Y);if(G)Q.unshift(G);Y=Y.parentElement}return Q}function x6($){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 N2($){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 f0($){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 N3($){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 M2($,J,Q){return{selector:$,snippet:(Y)=>{let q=Y.getAttribute(Q);return q?`${J} ${q}`:null}}}var q4=[M2("[data-md='item']","[Item]","data-md-label"),M2("[data-md='section']","[Section]","data-md-title"),M2("[data-md='checklist-item']","[Checklist]","data-md-label"),M2("[data-md='image']","[Image]","data-md-src"),{selector:"[data-md='callout']",snippet:($)=>{return`[Callout:${$.getAttribute("data-md-type")||"info"}] ${N3($).slice(0,60)||"Callout"}`}},{selector:"[data-md='note']",snippet:($)=>`[Note] ${N3($).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}}],h6=["[data-md='choice-option']","[data-md='multichoice-option']","[data-md='userinput']","[data-md='rangeinput']"],S1=q4.map(($)=>$.selector).join(", "),Q0=[...q4.map(($)=>$.selector),...h6].join(", ");function a$($){for(let J of q4)if($.matches(J.selector))return J.snippet($);return null}var Y4={kind:"block",parse:($)=>$.startsWith("[")?{snippet:$}:null,format:($)=>$.snippet,find:($,J)=>{for(let Q of J.querySelectorAll(S1)){if(!(Q instanceof HTMLElement))continue;if(a$(Q)===$.snippet)return Q}return null}};var G4="data-annotation-image",u6=/^\[Region:(rect|ellipse)\] ([\s\S]+) @(0|[1-9]\d*),(0|[1-9]\d*),(0|[1-9]\d*),(0|[1-9]\d*)$/;function p6($){if($==="rect")return"rect";if($==="ellipse")return"ellipse";return null}function O2($){if($===void 0)return null;let J=Number($);if(!Number.isInteger(J)||J<0||J>1e4)return null;return J}function M3($){return Math.min(1e4,Math.max(0,$))}function _4($,J,Q){if(!($.width>0)||!($.height>0))return null;return{x:M3(Math.round(J/$.width*1e4)),y:M3(Math.round(Q/$.height*1e4))}}function F2($,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 H4($){return $.w>=30&&$.h>=30}function O3($){return{left:`${$.x/100}%`,top:`${$.y/100}%`,width:`${$.w/100}%`,height:`${$.h/100}%`}}function L2($){return`${($/100).toFixed(1).replace(/\.0$/,"")}%`}function A2($){let J=`${L2($.x)}-${L2($.x+$.w)}`,Q=`${L2($.y)}-${L2($.y+$.h)}`;return`[Region] ${$.src} — ${$.shape} x ${J}, y ${Q} of the image`}function X4($,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 S2($,J){let Q=O3(J);$.style.left=Q.left,$.style.top=Q.top,$.style.width=Q.width,$.style.height=Q.height}function P2($,J,Q){let Y=document.createElement("div");return Y.className="ann-region",Y.setAttribute("data-annotation-id",Q),Y.setAttribute("data-annotation-region",J),S2(Y,$),Y}var v0={kind:"region",parse:($)=>{let J=u6.exec($);if(!J)return null;let Q=p6(J[1]),Y=J[2],q=O2(J[3]),G=O2(J[4]),X=O2(J[5]),H=O2(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)=>X4($.src,J),restore:($,J,Q)=>{if(J.querySelector(`[data-annotation-id="${Q.id}"]`))return;let Y=X4($.src,J);if(!Y)return;Y.appendChild(P2($,$.shape,Q.id))},describe:A2};var W4={kind:"text",parse:($)=>$?{text:$}:null,format:($)=>$.text,find:()=>null,restore:($,J,Q)=>{y0(J,[Q])}};var w2=[f0(v0),f0(Y4),f0(W4)];function U4($,J){for(let Q of w2){let Y=Q.find($,J);if(Y)return Y}return null}function K4($,J){for(let Q of J){if(!Q.snippet)continue;for(let Y of w2)Y.restore($,Q)}}function g0($){for(let J of w2){let Q=J.describe($);if(Q!==null)return Q}return $}import{AnnotationCtx as Lq,SessionContext as Fq,useAnnotationHost as Aq}from"@fabrika/annotations/runtime";import{useEffect as wq,useRef as Tq,useState as jq}from"react";var L={};E6(L,{void:()=>V8,util:()=>Q$,unknown:()=>j8,union:()=>I8,undefined:()=>P8,tuple:()=>y8,transformer:()=>c8,symbol:()=>S8,string:()=>b3,strictObject:()=>R8,setErrorMap:()=>d6,set:()=>v8,record:()=>E8,quotelessJson:()=>c6,promise:()=>p8,preprocess:()=>r8,pipeline:()=>i8,ostring:()=>o8,optional:()=>l8,onumber:()=>a8,oboolean:()=>n8,objectUtil:()=>B4,object:()=>C8,number:()=>V3,nullable:()=>d8,null:()=>w8,never:()=>b8,nativeEnum:()=>u8,nan:()=>L8,map:()=>f8,makeIssue:()=>m0,literal:()=>x8,lazy:()=>m8,late:()=>M8,isValid:()=>P1,isDirty:()=>j2,isAsync:()=>Y0,isAborted:()=>T2,intersection:()=>k8,instanceof:()=>O8,getParsedType:()=>n$,getErrorMap:()=>q0,function:()=>g8,enum:()=>h8,effect:()=>c8,discriminatedUnion:()=>D8,defaultErrorMap:()=>_1,datetimeRegex:()=>w3,date:()=>A8,custom:()=>j3,coerce:()=>s8,boolean:()=>Z3,bigint:()=>F8,array:()=>Z8,any:()=>T8,addIssueToContext:()=>k,ZodVoid:()=>h0,ZodUnknown:()=>w1,ZodUnion:()=>U0,ZodUndefined:()=>H0,ZodType:()=>$$,ZodTuple:()=>t$,ZodTransformer:()=>h$,ZodSymbol:()=>x0,ZodString:()=>v$,ZodSet:()=>x1,ZodSchema:()=>$$,ZodRecord:()=>u0,ZodReadonly:()=>L0,ZodPromise:()=>h1,ZodPipeline:()=>l0,ZodParsedType:()=>Z,ZodOptional:()=>m$,ZodObject:()=>A$,ZodNumber:()=>T1,ZodNullable:()=>W1,ZodNull:()=>W0,ZodNever:()=>s$,ZodNativeEnum:()=>N0,ZodNaN:()=>c0,ZodMap:()=>p0,ZodLiteral:()=>z0,ZodLazy:()=>B0,ZodIssueCode:()=>b,ZodIntersection:()=>K0,ZodFunction:()=>G0,ZodFirstPartyTypeKind:()=>l,ZodError:()=>y$,ZodEnum:()=>b1,ZodEffects:()=>h$,ZodDiscriminatedUnion:()=>b2,ZodDefault:()=>M0,ZodDate:()=>g1,ZodCatch:()=>O0,ZodBranded:()=>V2,ZodBoolean:()=>_0,ZodBigInt:()=>j1,ZodArray:()=>g$,ZodAny:()=>m1,Schema:()=>$$,ParseStatus:()=>Z$,OK:()=>C$,NEVER:()=>t8,INVALID:()=>p,EMPTY_PATH:()=>r6,DIRTY:()=>v1,BRAND:()=>N8});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 B4;(function($){$.mergeShapes=(J,Q)=>{return{...J,...Q}}})(B4||(B4={}));var Z=Q$.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),n$=($)=>{switch(typeof $){case"undefined":return Z.undefined;case"string":return Z.string;case"number":return Number.isNaN($)?Z.nan:Z.number;case"boolean":return Z.boolean;case"function":return Z.function;case"bigint":return Z.bigint;case"symbol":return Z.symbol;case"object":if(Array.isArray($))return Z.array;if($===null)return Z.null;if($.then&&typeof $.then==="function"&&$.catch&&typeof $.catch==="function")return Z.promise;if(typeof Map<"u"&&$ instanceof Map)return Z.map;if(typeof Set<"u"&&$ instanceof Set)return Z.set;if(typeof Date<"u"&&$ instanceof Date)return Z.date;return Z.object;default:return Z.unknown}};var b=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"]),c6=($)=>{return JSON.stringify($,null,2).replace(/"([^"]+)":/g,"$1:")};class y$ 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 y$))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()}}y$.create=($)=>{return new y$($)};var l6=($,J)=>{let Q;switch($.code){case b.invalid_type:if($.received===Z.undefined)Q="Required";else Q=`Expected ${$.expected}, received ${$.received}`;break;case b.invalid_literal:Q=`Invalid literal value, expected ${JSON.stringify($.expected,Q$.jsonStringifyReplacer)}`;break;case b.unrecognized_keys:Q=`Unrecognized key(s) in object: ${Q$.joinValues($.keys,", ")}`;break;case b.invalid_union:Q="Invalid input";break;case b.invalid_union_discriminator:Q=`Invalid discriminator value. Expected ${Q$.joinValues($.options)}`;break;case b.invalid_enum_value:Q=`Invalid enum value. Expected ${Q$.joinValues($.options)}, received '${$.received}'`;break;case b.invalid_arguments:Q="Invalid function arguments";break;case b.invalid_return_type:Q="Invalid function return type";break;case b.invalid_date:Q="Invalid date";break;case b.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 b.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 b.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 b.custom:Q="Invalid input";break;case b.invalid_intersection_types:Q="Intersection results could not be merged";break;case b.not_multiple_of:Q=`Number must be a multiple of ${$.multipleOf}`;break;case b.not_finite:Q="Number must be finite";break;default:Q=J.defaultError,Q$.assertNever($)}return{message:Q}},_1=l6;var L3=_1;function d6($){L3=$}function q0(){return L3}var m0=($)=>{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}},r6=[];function k($,J){let Q=q0(),Y=m0({issueData:J,data:$.data,path:$.path,errorMaps:[$.common.contextualErrorMap,$.schemaErrorMap,Q,Q===_1?void 0:_1].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"}),v1=($)=>({status:"dirty",value:$}),C$=($)=>({status:"valid",value:$}),T2=($)=>$.status==="aborted",j2=($)=>$.status==="dirty",P1=($)=>$.status==="valid",Y0=($)=>typeof Promise<"u"&&$ instanceof Promise;var g;(function($){$.errToObj=(J)=>typeof J==="string"?{message:J}:J||{},$.toString=(J)=>typeof J==="string"?J:J?.message})(g||(g={}));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 F3=($,J)=>{if(P1(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 y$($.common.issues);return this._error=Q,this._error}}}};function e($){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 $${get description(){return this._def.description}_getType($){return n$($.data)}_getOrReturnCtx($,J){return J||{common:$.parent.common,data:$.data,parsedType:n$($.data),schemaErrorMap:this._def.errorMap,path:$.path,parent:$.parent}}_processInputParams($){return{status:new Z$,ctx:{common:$.parent.common,data:$.data,parsedType:n$($.data),schemaErrorMap:this._def.errorMap,path:$.path,parent:$.parent}}}_parseSync($){let J=this._parse($);if(Y0(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:n$($)},Y=this._parseSync({data:$,path:Q.path,parent:Q});return F3(Q,Y)}"~validate"($){let J={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:$,parsedType:n$($)};if(!this["~standard"].async)try{let Q=this._parseSync({data:$,path:[],parent:J});return P1(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)=>P1(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:n$($)},Y=this._parse({data:$,path:Q.path,parent:Q}),q=await(Y0(Y)?Y:Promise.resolve(Y));return F3(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:b.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:l.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 W1.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return g$.create(this)}promise(){return h1.create(this,this._def)}or($){return U0.create([this,$],this._def)}and($){return K0.create(this,$,this._def)}transform($){return new h$({...e(this._def),schema:this,typeName:l.ZodEffects,effect:{type:"transform",transform:$}})}default($){let J=typeof $==="function"?$:()=>$;return new M0({...e(this._def),innerType:this,defaultValue:J,typeName:l.ZodDefault})}brand(){return new V2({typeName:l.ZodBranded,type:this,...e(this._def)})}catch($){let J=typeof $==="function"?$:()=>$;return new O0({...e(this._def),innerType:this,catchValue:J,typeName:l.ZodCatch})}describe($){return new this.constructor({...this._def,description:$})}pipe($){return l0.create(this,$)}readonly(){return L0.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}var i6=/^c[^\s-]{8,}$/i,o6=/^[0-9a-z]+$/,a6=/^[0-9A-HJKMNP-TV-Z]{26}$/i,n6=/^[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,s6=/^[a-z0-9_-]{21}$/i,t6=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,e6=/^[-+]?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)?)??$/,$8=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,J8="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$",z4,Q8=/^(?:(?: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])$/,q8=/^(?:(?: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])$/,Y8=/^(([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]))$/,X8=/^(([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])$/,G8=/^([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}(=)?))?$/,S3="((\\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])))",H8=new RegExp(`^${S3}$`);function P3($){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 W8($){return new RegExp(`^${P3($)}$`)}function w3($){let J=`${S3}T${P3($)}`,Q=[];if(Q.push($.local?"Z?":"Z"),$.offset)Q.push("([+-]\\d{2}:?\\d{2})");return J=`${J}(${Q.join("|")})`,new RegExp(`^${J}$`)}function U8($,J){if((J==="v4"||!J)&&Q8.test($))return!0;if((J==="v6"||!J)&&Y8.test($))return!0;return!1}function K8($,J){if(!t6.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 B8($,J){if((J==="v4"||!J)&&q8.test($))return!0;if((J==="v6"||!J)&&X8.test($))return!0;return!1}class v$ extends $${_parse($){if(this._def.coerce)$.data=String($.data);if(this._getType($)!==Z.string){let q=this._getOrReturnCtx($);return k(q,{code:b.invalid_type,expected:Z.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:b.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:b.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:b.too_big,maximum:q.value,type:"string",inclusive:!0,exact:!0,message:q.message});else if(X)k(Y,{code:b.too_small,minimum:q.value,type:"string",inclusive:!0,exact:!0,message:q.message});Q.dirty()}}else if(q.kind==="email"){if(!$8.test($.data))Y=this._getOrReturnCtx($,Y),k(Y,{validation:"email",code:b.invalid_string,message:q.message}),Q.dirty()}else if(q.kind==="emoji"){if(!z4)z4=new RegExp(J8,"u");if(!z4.test($.data))Y=this._getOrReturnCtx($,Y),k(Y,{validation:"emoji",code:b.invalid_string,message:q.message}),Q.dirty()}else if(q.kind==="uuid"){if(!n6.test($.data))Y=this._getOrReturnCtx($,Y),k(Y,{validation:"uuid",code:b.invalid_string,message:q.message}),Q.dirty()}else if(q.kind==="nanoid"){if(!s6.test($.data))Y=this._getOrReturnCtx($,Y),k(Y,{validation:"nanoid",code:b.invalid_string,message:q.message}),Q.dirty()}else if(q.kind==="cuid"){if(!i6.test($.data))Y=this._getOrReturnCtx($,Y),k(Y,{validation:"cuid",code:b.invalid_string,message:q.message}),Q.dirty()}else if(q.kind==="cuid2"){if(!o6.test($.data))Y=this._getOrReturnCtx($,Y),k(Y,{validation:"cuid2",code:b.invalid_string,message:q.message}),Q.dirty()}else if(q.kind==="ulid"){if(!a6.test($.data))Y=this._getOrReturnCtx($,Y),k(Y,{validation:"ulid",code:b.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:b.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:b.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:b.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:b.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:b.invalid_string,validation:{endsWith:q.value},message:q.message}),Q.dirty()}else if(q.kind==="datetime"){if(!w3(q).test($.data))Y=this._getOrReturnCtx($,Y),k(Y,{code:b.invalid_string,validation:"datetime",message:q.message}),Q.dirty()}else if(q.kind==="date"){if(!H8.test($.data))Y=this._getOrReturnCtx($,Y),k(Y,{code:b.invalid_string,validation:"date",message:q.message}),Q.dirty()}else if(q.kind==="time"){if(!W8(q).test($.data))Y=this._getOrReturnCtx($,Y),k(Y,{code:b.invalid_string,validation:"time",message:q.message}),Q.dirty()}else if(q.kind==="duration"){if(!e6.test($.data))Y=this._getOrReturnCtx($,Y),k(Y,{validation:"duration",code:b.invalid_string,message:q.message}),Q.dirty()}else if(q.kind==="ip"){if(!U8($.data,q.version))Y=this._getOrReturnCtx($,Y),k(Y,{validation:"ip",code:b.invalid_string,message:q.message}),Q.dirty()}else if(q.kind==="jwt"){if(!K8($.data,q.alg))Y=this._getOrReturnCtx($,Y),k(Y,{validation:"jwt",code:b.invalid_string,message:q.message}),Q.dirty()}else if(q.kind==="cidr"){if(!B8($.data,q.version))Y=this._getOrReturnCtx($,Y),k(Y,{validation:"cidr",code:b.invalid_string,message:q.message}),Q.dirty()}else if(q.kind==="base64"){if(!G8.test($.data))Y=this._getOrReturnCtx($,Y),k(Y,{validation:"base64",code:b.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:b.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:b.invalid_string,...g.errToObj(Q)})}_addCheck($){return new v$({...this._def,checks:[...this._def.checks,$]})}email($){return this._addCheck({kind:"email",...g.errToObj($)})}url($){return this._addCheck({kind:"url",...g.errToObj($)})}emoji($){return this._addCheck({kind:"emoji",...g.errToObj($)})}uuid($){return this._addCheck({kind:"uuid",...g.errToObj($)})}nanoid($){return this._addCheck({kind:"nanoid",...g.errToObj($)})}cuid($){return this._addCheck({kind:"cuid",...g.errToObj($)})}cuid2($){return this._addCheck({kind:"cuid2",...g.errToObj($)})}ulid($){return this._addCheck({kind:"ulid",...g.errToObj($)})}base64($){return this._addCheck({kind:"base64",...g.errToObj($)})}base64url($){return this._addCheck({kind:"base64url",...g.errToObj($)})}jwt($){return this._addCheck({kind:"jwt",...g.errToObj($)})}ip($){return this._addCheck({kind:"ip",...g.errToObj($)})}cidr($){return this._addCheck({kind:"cidr",...g.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,...g.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,...g.errToObj($?.message)})}duration($){return this._addCheck({kind:"duration",...g.errToObj($)})}regex($,J){return this._addCheck({kind:"regex",regex:$,...g.errToObj(J)})}includes($,J){return this._addCheck({kind:"includes",value:$,position:J?.position,...g.errToObj(J?.message)})}startsWith($,J){return this._addCheck({kind:"startsWith",value:$,...g.errToObj(J)})}endsWith($,J){return this._addCheck({kind:"endsWith",value:$,...g.errToObj(J)})}min($,J){return this._addCheck({kind:"min",value:$,...g.errToObj(J)})}max($,J){return this._addCheck({kind:"max",value:$,...g.errToObj(J)})}length($,J){return this._addCheck({kind:"length",value:$,...g.errToObj(J)})}nonempty($){return this.min(1,g.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:l.ZodString,coerce:$?.coerce??!1,...e($)})};function z8($,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 T1 extends $${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($)!==Z.number){let q=this._getOrReturnCtx($);return k(q,{code:b.invalid_type,expected:Z.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:b.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:b.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:b.too_big,maximum:q.value,type:"number",inclusive:q.inclusive,exact:!1,message:q.message}),Y.dirty()}else if(q.kind==="multipleOf"){if(z8($.data,q.value)!==0)Q=this._getOrReturnCtx($,Q),k(Q,{code:b.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:b.not_finite,message:q.message}),Y.dirty()}else Q$.assertNever(q);return{status:Y.value,value:$.data}}gte($,J){return this.setLimit("min",$,!0,g.toString(J))}gt($,J){return this.setLimit("min",$,!1,g.toString(J))}lte($,J){return this.setLimit("max",$,!0,g.toString(J))}lt($,J){return this.setLimit("max",$,!1,g.toString(J))}setLimit($,J,Q,Y){return new T1({...this._def,checks:[...this._def.checks,{kind:$,value:J,inclusive:Q,message:g.toString(Y)}]})}_addCheck($){return new T1({...this._def,checks:[...this._def.checks,$]})}int($){return this._addCheck({kind:"int",message:g.toString($)})}positive($){return this._addCheck({kind:"min",value:0,inclusive:!1,message:g.toString($)})}negative($){return this._addCheck({kind:"max",value:0,inclusive:!1,message:g.toString($)})}nonpositive($){return this._addCheck({kind:"max",value:0,inclusive:!0,message:g.toString($)})}nonnegative($){return this._addCheck({kind:"min",value:0,inclusive:!0,message:g.toString($)})}multipleOf($,J){return this._addCheck({kind:"multipleOf",value:$,message:g.toString(J)})}finite($){return this._addCheck({kind:"finite",message:g.toString($)})}safe($){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:g.toString($)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:g.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($)}}T1.create=($)=>{return new T1({checks:[],typeName:l.ZodNumber,coerce:$?.coerce||!1,...e($)})};class j1 extends $${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($)!==Z.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:b.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:b.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:b.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:b.invalid_type,expected:Z.bigint,received:J.parsedType}),p}gte($,J){return this.setLimit("min",$,!0,g.toString(J))}gt($,J){return this.setLimit("min",$,!1,g.toString(J))}lte($,J){return this.setLimit("max",$,!0,g.toString(J))}lt($,J){return this.setLimit("max",$,!1,g.toString(J))}setLimit($,J,Q,Y){return new j1({...this._def,checks:[...this._def.checks,{kind:$,value:J,inclusive:Q,message:g.toString(Y)}]})}_addCheck($){return new j1({...this._def,checks:[...this._def.checks,$]})}positive($){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:g.toString($)})}negative($){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:g.toString($)})}nonpositive($){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:g.toString($)})}nonnegative($){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:g.toString($)})}multipleOf($,J){return this._addCheck({kind:"multipleOf",value:$,message:g.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 $}}j1.create=($)=>{return new j1({checks:[],typeName:l.ZodBigInt,coerce:$?.coerce??!1,...e($)})};class _0 extends $${_parse($){if(this._def.coerce)$.data=Boolean($.data);if(this._getType($)!==Z.boolean){let Q=this._getOrReturnCtx($);return k(Q,{code:b.invalid_type,expected:Z.boolean,received:Q.parsedType}),p}return C$($.data)}}_0.create=($)=>{return new _0({typeName:l.ZodBoolean,coerce:$?.coerce||!1,...e($)})};class g1 extends $${_parse($){if(this._def.coerce)$.data=new Date($.data);if(this._getType($)!==Z.date){let q=this._getOrReturnCtx($);return k(q,{code:b.invalid_type,expected:Z.date,received:q.parsedType}),p}if(Number.isNaN($.data.getTime())){let q=this._getOrReturnCtx($);return k(q,{code:b.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:b.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:b.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 g1({...this._def,checks:[...this._def.checks,$]})}min($,J){return this._addCheck({kind:"min",value:$.getTime(),message:g.toString(J)})}max($,J){return this._addCheck({kind:"max",value:$.getTime(),message:g.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}}g1.create=($)=>{return new g1({checks:[],coerce:$?.coerce||!1,typeName:l.ZodDate,...e($)})};class x0 extends $${_parse($){if(this._getType($)!==Z.symbol){let Q=this._getOrReturnCtx($);return k(Q,{code:b.invalid_type,expected:Z.symbol,received:Q.parsedType}),p}return C$($.data)}}x0.create=($)=>{return new x0({typeName:l.ZodSymbol,...e($)})};class H0 extends $${_parse($){if(this._getType($)!==Z.undefined){let Q=this._getOrReturnCtx($);return k(Q,{code:b.invalid_type,expected:Z.undefined,received:Q.parsedType}),p}return C$($.data)}}H0.create=($)=>{return new H0({typeName:l.ZodUndefined,...e($)})};class W0 extends $${_parse($){if(this._getType($)!==Z.null){let Q=this._getOrReturnCtx($);return k(Q,{code:b.invalid_type,expected:Z.null,received:Q.parsedType}),p}return C$($.data)}}W0.create=($)=>{return new W0({typeName:l.ZodNull,...e($)})};class m1 extends $${constructor(){super(...arguments);this._any=!0}_parse($){return C$($.data)}}m1.create=($)=>{return new m1({typeName:l.ZodAny,...e($)})};class w1 extends $${constructor(){super(...arguments);this._unknown=!0}_parse($){return C$($.data)}}w1.create=($)=>{return new w1({typeName:l.ZodUnknown,...e($)})};class s$ extends $${_parse($){let J=this._getOrReturnCtx($);return k(J,{code:b.invalid_type,expected:Z.never,received:J.parsedType}),p}}s$.create=($)=>{return new s$({typeName:l.ZodNever,...e($)})};class h0 extends $${_parse($){if(this._getType($)!==Z.undefined){let Q=this._getOrReturnCtx($);return k(Q,{code:b.invalid_type,expected:Z.void,received:Q.parsedType}),p}return C$($.data)}}h0.create=($)=>{return new h0({typeName:l.ZodVoid,...e($)})};class g$ extends $${_parse($){let{ctx:J,status:Q}=this._processInputParams($),Y=this._def;if(J.parsedType!==Z.array)return k(J,{code:b.invalid_type,expected:Z.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?b.too_big:b.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:b.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:b.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:g.toString(J)}})}max($,J){return new g$({...this._def,maxLength:{value:$,message:g.toString(J)}})}length($,J){return new g$({...this._def,exactLength:{value:$,message:g.toString(J)}})}nonempty($){return this.min(1,$)}}g$.create=($,J)=>{return new g$({type:$,minLength:null,maxLength:null,exactLength:null,typeName:l.ZodArray,...e(J)})};function X0($){if($ instanceof A$){let J={};for(let Q in $.shape){let Y=$.shape[Q];J[Q]=m$.create(X0(Y))}return new A$({...$._def,shape:()=>J})}else if($ instanceof g$)return new g$({...$._def,type:X0($.element)});else if($ instanceof m$)return m$.create(X0($.unwrap()));else if($ instanceof W1)return W1.create(X0($.unwrap()));else if($ instanceof t$)return t$.create($.items.map((J)=>X0(J)));else return $}class A$ extends $${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($)!==Z.object){let _=this._getOrReturnCtx($);return k(_,{code:b.invalid_type,expected:Z.object,received:_.parsedType}),p}let{status:Q,ctx:Y}=this._processInputParams($),{shape:q,keys:G}=this._getCached(),X=[];if(!(this._def.catchall instanceof s$&&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 s$){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:b.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,K=await W.value;_.push({key:U,value:K,alwaysSet:W.alwaysSet})}return _}).then((_)=>{return Z$.mergeObjectSync(Q,_)});else return Z$.mergeObjectSync(Q,H)}get shape(){return this._def.shape()}strict($){return g.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:g.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:l.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 X0(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 T3(Q$.objectKeys(this.shape))}}A$.create=($,J)=>{return new A$({shape:()=>$,unknownKeys:"strip",catchall:s$.create(),typeName:l.ZodObject,...e(J)})};A$.strictCreate=($,J)=>{return new A$({shape:()=>$,unknownKeys:"strict",catchall:s$.create(),typeName:l.ZodObject,...e(J)})};A$.lazycreate=($,J)=>{return new A$({shape:$,unknownKeys:"strip",catchall:s$.create(),typeName:l.ZodObject,...e(J)})};class U0 extends $${_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 y$(X.ctx.common.issues));return k(J,{code:b.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 y$(H));return k(J,{code:b.invalid_union,unionErrors:X}),p}}get options(){return this._def.options}}U0.create=($,J)=>{return new U0({options:$,typeName:l.ZodUnion,...e(J)})};var H1=($)=>{if($ instanceof B0)return H1($.schema);else if($ instanceof h$)return H1($.innerType());else if($ instanceof z0)return[$.value];else if($ instanceof b1)return $.options;else if($ instanceof N0)return Q$.objectValues($.enum);else if($ instanceof M0)return H1($._def.innerType);else if($ instanceof H0)return[void 0];else if($ instanceof W0)return[null];else if($ instanceof m$)return[void 0,...H1($.unwrap())];else if($ instanceof W1)return[null,...H1($.unwrap())];else if($ instanceof V2)return H1($.unwrap());else if($ instanceof L0)return H1($.unwrap());else if($ instanceof O0)return H1($._def.innerType);else return[]};class b2 extends $${_parse($){let{ctx:J}=this._processInputParams($);if(J.parsedType!==Z.object)return k(J,{code:b.invalid_type,expected:Z.object,received:J.parsedType}),p;let Q=this.discriminator,Y=J.data[Q],q=this.optionsMap.get(Y);if(!q)return k(J,{code:b.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=H1(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 b2({typeName:l.ZodDiscriminatedUnion,discriminator:$,options:J,optionsMap:Y,...e(Q)})}}function N4($,J){let Q=n$($),Y=n$(J);if($===J)return{valid:!0,data:$};else if(Q===Z.object&&Y===Z.object){let q=Q$.objectKeys(J),G=Q$.objectKeys($).filter((H)=>q.indexOf(H)!==-1),X={...$,...J};for(let H of G){let _=N4($[H],J[H]);if(!_.valid)return{valid:!1};X[H]=_.data}return{valid:!0,data:X}}else if(Q===Z.array&&Y===Z.array){if($.length!==J.length)return{valid:!1};let q=[];for(let G=0;G<$.length;G++){let X=$[G],H=J[G],_=N4(X,H);if(!_.valid)return{valid:!1};q.push(_.data)}return{valid:!0,data:q}}else if(Q===Z.date&&Y===Z.date&&+$===+J)return{valid:!0,data:$};else return{valid:!1}}class K0 extends $${_parse($){let{status:J,ctx:Q}=this._processInputParams($),Y=(q,G)=>{if(T2(q)||T2(G))return p;let X=N4(q.value,G.value);if(!X.valid)return k(Q,{code:b.invalid_intersection_types}),p;if(j2(q)||j2(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}))}}K0.create=($,J,Q)=>{return new K0({left:$,right:J,typeName:l.ZodIntersection,...e(Q)})};class t$ extends $${_parse($){let{status:J,ctx:Q}=this._processInputParams($);if(Q.parsedType!==Z.array)return k(Q,{code:b.invalid_type,expected:Z.array,received:Q.parsedType}),p;if(Q.data.length<this._def.items.length)return k(Q,{code:b.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:b.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 t$({...this._def,rest:$})}}t$.create=($,J)=>{if(!Array.isArray($))throw Error("You must pass an array of schemas to z.tuple([ ... ])");return new t$({items:$,typeName:l.ZodTuple,rest:null,...e(J)})};class u0 extends $${get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse($){let{status:J,ctx:Q}=this._processInputParams($);if(Q.parsedType!==Z.object)return k(Q,{code:b.invalid_type,expected:Z.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 $$)return new u0({keyType:$,valueType:J,typeName:l.ZodRecord,...e(Q)});return new u0({keyType:v$.create(),valueType:$,typeName:l.ZodRecord,...e(J)})}}class p0 extends $${get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse($){let{status:J,ctx:Q}=this._processInputParams($);if(Q.parsedType!==Z.map)return k(Q,{code:b.invalid_type,expected:Z.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}}}}p0.create=($,J,Q)=>{return new p0({valueType:J,keyType:$,typeName:l.ZodMap,...e(Q)})};class x1 extends $${_parse($){let{status:J,ctx:Q}=this._processInputParams($);if(Q.parsedType!==Z.set)return k(Q,{code:b.invalid_type,expected:Z.set,received:Q.parsedType}),p;let Y=this._def;if(Y.minSize!==null){if(Q.data.size<Y.minSize.value)k(Q,{code:b.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:b.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 x1({...this._def,minSize:{value:$,message:g.toString(J)}})}max($,J){return new x1({...this._def,maxSize:{value:$,message:g.toString(J)}})}size($,J){return this.min($,J).max($,J)}nonempty($){return this.min(1,$)}}x1.create=($,J)=>{return new x1({valueType:$,minSize:null,maxSize:null,typeName:l.ZodSet,...e(J)})};class G0 extends $${constructor(){super(...arguments);this.validate=this.implement}_parse($){let{ctx:J}=this._processInputParams($);if(J.parsedType!==Z.function)return k(J,{code:b.invalid_type,expected:Z.function,received:J.parsedType}),p;function Q(X,H){return m0({data:X,path:J.path,errorMaps:[J.common.contextualErrorMap,J.schemaErrorMap,q0(),_1].filter((_)=>!!_),issueData:{code:b.invalid_arguments,argumentsError:H}})}function Y(X,H){return m0({data:X,path:J.path,errorMaps:[J.common.contextualErrorMap,J.schemaErrorMap,q0(),_1].filter((_)=>!!_),issueData:{code:b.invalid_return_type,returnTypeError:H}})}let q={errorMap:J.common.contextualErrorMap},G=J.data;if(this._def.returns instanceof h1){let X=this;return C$(async function(...H){let _=new y$([]),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 y$([Q(H,_.error)]);let W=Reflect.apply(G,this,_.data),U=X._def.returns.safeParse(W,q);if(!U.success)throw new y$([Y(W,U.error)]);return U.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...$){return new G0({...this._def,args:t$.create($).rest(w1.create())})}returns($){return new G0({...this._def,returns:$})}implement($){return this.parse($)}strictImplement($){return this.parse($)}static create($,J,Q){return new G0({args:$?$:t$.create([]).rest(w1.create()),returns:J||w1.create(),typeName:l.ZodFunction,...e(Q)})}}class B0 extends $${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})}}B0.create=($,J)=>{return new B0({getter:$,typeName:l.ZodLazy,...e(J)})};class z0 extends $${_parse($){if($.data!==this._def.value){let J=this._getOrReturnCtx($);return k(J,{received:J.data,code:b.invalid_literal,expected:this._def.value}),p}return{status:"valid",value:$.data}}get value(){return this._def.value}}z0.create=($,J)=>{return new z0({value:$,typeName:l.ZodLiteral,...e(J)})};function T3($,J){return new b1({values:$,typeName:l.ZodEnum,...e(J)})}class b1 extends $${_parse($){if(typeof $.data!=="string"){let J=this._getOrReturnCtx($),Q=this._def.values;return k(J,{expected:Q$.joinValues(Q),received:J.parsedType,code:b.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:b.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 b1.create($,{...this._def,...J})}exclude($,J=this._def){return b1.create(this.options.filter((Q)=>!$.includes(Q)),{...this._def,...J})}}b1.create=T3;class N0 extends $${_parse($){let J=Q$.getValidEnumValues(this._def.values),Q=this._getOrReturnCtx($);if(Q.parsedType!==Z.string&&Q.parsedType!==Z.number){let Y=Q$.objectValues(J);return k(Q,{expected:Q$.joinValues(Y),received:Q.parsedType,code:b.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:b.invalid_enum_value,options:Y}),p}return C$($.data)}get enum(){return this._def.values}}N0.create=($,J)=>{return new N0({values:$,typeName:l.ZodNativeEnum,...e(J)})};class h1 extends $${unwrap(){return this._def.type}_parse($){let{ctx:J}=this._processInputParams($);if(J.parsedType!==Z.promise&&J.common.async===!1)return k(J,{code:b.invalid_type,expected:Z.promise,received:J.parsedType}),p;let Q=J.parsedType===Z.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})}))}}h1.create=($,J)=>{return new h1({type:$,typeName:l.ZodPromise,...e(J)})};class h$ extends $${innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===l.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 v1(H.value);if(J.value==="dirty")return v1(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 v1(X.value);if(J.value==="dirty")return v1(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(!P1(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(!P1(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:l.ZodEffects,effect:J,...e(Q)})};h$.createWithPreprocess=($,J,Q)=>{return new h$({schema:J,effect:{type:"preprocess",transform:$},typeName:l.ZodEffects,...e(Q)})};class m$ extends $${_parse($){if(this._getType($)===Z.undefined)return C$(void 0);return this._def.innerType._parse($)}unwrap(){return this._def.innerType}}m$.create=($,J)=>{return new m$({innerType:$,typeName:l.ZodOptional,...e(J)})};class W1 extends $${_parse($){if(this._getType($)===Z.null)return C$(null);return this._def.innerType._parse($)}unwrap(){return this._def.innerType}}W1.create=($,J)=>{return new W1({innerType:$,typeName:l.ZodNullable,...e(J)})};class M0 extends $${_parse($){let{ctx:J}=this._processInputParams($),Q=J.data;if(J.parsedType===Z.undefined)Q=this._def.defaultValue();return this._def.innerType._parse({data:Q,path:J.path,parent:J})}removeDefault(){return this._def.innerType}}M0.create=($,J)=>{return new M0({innerType:$,typeName:l.ZodDefault,defaultValue:typeof J.default==="function"?J.default:()=>J.default,...e(J)})};class O0 extends $${_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(Y0(Y))return Y.then((q)=>{return{status:"valid",value:q.status==="valid"?q.value:this._def.catchValue({get error(){return new y$(Q.common.issues)},input:Q.data})}});else return{status:"valid",value:Y.status==="valid"?Y.value:this._def.catchValue({get error(){return new y$(Q.common.issues)},input:Q.data})}}removeCatch(){return this._def.innerType}}O0.create=($,J)=>{return new O0({innerType:$,typeName:l.ZodCatch,catchValue:typeof J.catch==="function"?J.catch:()=>J.catch,...e(J)})};class c0 extends $${_parse($){if(this._getType($)!==Z.nan){let Q=this._getOrReturnCtx($);return k(Q,{code:b.invalid_type,expected:Z.nan,received:Q.parsedType}),p}return{status:"valid",value:$.data}}}c0.create=($)=>{return new c0({typeName:l.ZodNaN,...e($)})};var N8=Symbol("zod_brand");class V2 extends $${_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 l0 extends $${_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(),v1(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 l0({in:$,out:J,typeName:l.ZodPipeline})}}class L0 extends $${_parse($){let J=this._def.innerType._parse($),Q=(Y)=>{if(P1(Y))Y.value=Object.freeze(Y.value);return Y};return Y0(J)?J.then((Y)=>Q(Y)):Q(J)}unwrap(){return this._def.innerType}}L0.create=($,J)=>{return new L0({innerType:$,typeName:l.ZodReadonly,...e(J)})};function A3($,J){let Q=typeof $==="function"?$(J):typeof $==="string"?{message:$}:$;return typeof Q==="string"?{message:Q}:Q}function j3($,J={},Q){if($)return m1.create().superRefine((Y,q)=>{let G=$(Y);if(G instanceof Promise)return G.then((X)=>{if(!X){let H=A3(J,Y),_=H.fatal??Q??!0;q.addIssue({code:"custom",...H,fatal:_})}});if(!G){let X=A3(J,Y),H=X.fatal??Q??!0;q.addIssue({code:"custom",...X,fatal:H})}return});return m1.create()}var M8={object:A$.lazycreate},l;(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"})(l||(l={}));var O8=($,J={message:`Input not instance of ${$.name}`})=>j3((Q)=>Q instanceof $,J),b3=v$.create,V3=T1.create,L8=c0.create,F8=j1.create,Z3=_0.create,A8=g1.create,S8=x0.create,P8=H0.create,w8=W0.create,T8=m1.create,j8=w1.create,b8=s$.create,V8=h0.create,Z8=g$.create,C8=A$.create,R8=A$.strictCreate,I8=U0.create,D8=b2.create,k8=K0.create,y8=t$.create,E8=u0.create,f8=p0.create,v8=x1.create,g8=G0.create,m8=B0.create,x8=z0.create,h8=b1.create,u8=N0.create,p8=h1.create,c8=h$.create,l8=m$.create,d8=W1.create,r8=h$.createWithPreprocess,i8=l0.create,o8=()=>b3().optional(),a8=()=>V3().optional(),n8=()=>Z3().optional(),s8={string:($)=>v$.create({...$,coerce:!0}),number:($)=>T1.create({...$,coerce:!0}),boolean:($)=>_0.create({...$,coerce:!0}),bigint:($)=>j1.create({...$,coerce:!0}),date:($)=>g1.create({...$,coerce:!0})};var t8=p;var e8=L.object({before:L.string(),after:L.string(),hierarchy:L.array(L.string()),lineStart:L.number().optional(),lineEnd:L.number().optional()}).passthrough(),M4=L.object({id:L.string(),name:L.string()}).passthrough(),$9=L.object({url:L.string(),mime:L.string().optional()}).passthrough(),O4=L.object({id:L.string(),snippet:L.string(),note:L.string(),createdAt:L.string(),filePath:L.string().optional(),canvasFile:L.string().optional(),context:e8.optional(),images:L.array(L.string()).optional(),attachments:L.array($9).optional(),source:L.enum(["local","remote"]).optional(),author:M4.optional()}).passthrough(),J9=L.array(O4.optional().catch(void 0)).transform(($)=>$.filter((J)=>J!==void 0)).catch([]),L4=L.object({annotations:J9,generalNote:L.string().catch("")}).passthrough(),C3=L.object({path:L.string()}),R3=L.object({url:L.string()}),I3=L.object({error:L.string()});import{useCallback as p1,useMemo as Q9,useState as q9}from"react";var u$="__agent-response__";function u1($){return $.filePath&&$.filePath!=="__agent-response__"?$.filePath:void 0}function d0($){return $.uploadUrl!==null}var F4=["image/png","image/jpeg","image/gif","image/webp"],D3="Only PNG, JPEG, GIF and WebP images can be attached";function E$(){return`ann-${Date.now()}-${Math.random().toString(36).slice(2,6)}`}function V1($,J){$.style.height="auto",$.style.height=(J?Math.max(J,$.scrollHeight):$.scrollHeight)+"px"}function k3($){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 Z2({annotations:$,setAnnotations:J,generalNote:Q,setGeneralNote:Y,remoteAnnotations:q,isReadOnly:G,onClear:X}){let[H,_]=q9(null),W=Q9(()=>{if(!q?.length)return $;let T=new Set($.map((A)=>A.id)),O=q.filter((A)=>!T.has(A.id));return[...$,...O.map((A)=>({...A,source:"remote"}))]},[$,q]),U=p1((T,O,A,w,S,j,C)=>{J((y)=>[...y,{id:T,snippet:O,note:A,createdAt:new Date().toISOString(),filePath:w,context:S,...j?.length?{images:j}:{},...C?{canvasFile:C}:{}}])},[J]),K=p1((T,O,A)=>{U(E$(),T,O,A)},[U]),z=p1((T,O)=>{J((A)=>A.map((w)=>w.id===T?{...w,note:O}:w))},[J]),B=p1((T)=>{if(!$.some((O)=>O.id===T))return;k3(T),J((O)=>O.filter((A)=>A.id!==T)),_((O)=>O===T?null:O)},[$,J]),N=p1((T,O)=>{J((A)=>A.map((w)=>w.id===T?{...w,images:[...w.images||[],O]}:w))},[J]),P=p1((T,O)=>{J((A)=>A.map((w)=>w.id===T?{...w,images:(w.images||[]).filter((S)=>S!==O)}:w))},[J]),M=p1(()=>{k3(),J([]),Y(""),_(null),X?.()},[J,Y,X]);return{annotations:W,generalNote:Q,setGeneralNote:Y,activeAnnotationId:H,setActiveAnnotationId:_,addAnnotation:K,addAnnotationWithId:U,updateAnnotation:z,removeAnnotation:B,addAnnotationImage:N,removeAnnotationImage:P,clearAll:M,isReadOnly:G}}import{useAnnotations as Z1}from"@fabrika/annotations/runtime";import{jsxDEV as Rq}from"react/jsx-dev-runtime";import{jsxDEV as c1,Fragment as Y9}from"react/jsx-dev-runtime";function A4({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}=Z1();return c1(Y9,{children:[c1("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:c1("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)=>V1(U.currentTarget,40),ref:(U)=>{if(U)V1(U,40)}},void 0,!1,void 0,this)},void 0,!1,void 0,this),Y,c1("div",{className:"px-4 py-3 border-t border-border-subtle flex-shrink-0",children:$?c1("div",{className:"flex gap-2",children:[q,c1("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):c1("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 X9}from"@fabrika/annotations/runtime";import{useCallback as U1,useEffect as G9,useRef as S4,useState as C2}from"react";import{jsxDEV as j$}from"react/jsx-dev-runtime";function P4($){if($.startsWith("/s/")||$.startsWith("http://")||$.startsWith("https://"))return $;return`/api/uploads/${$.split("/").pop()}`}async function _9($,J){let Q=$.uploadUrl;if(!Q)return{error:"Uploads are not available here"};let Y=new FormData;Y.append("image",J);try{let q=await fetch(Q(),{method:"POST",body:Y}),G=await q.json();if(!q.ok){let X=I3.safeParse(G);return{error:X.success?X.data.error:`Upload failed (HTTP ${q.status})`}}return{path:$.isShared?R3.parse(G).url:C3.parse(G).path}}catch{return{error:"Upload failed"}}}function r0({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:K,textareaRef:z,textareaClassName:B,textareaStyle:N,minHeight:P,attachButton:M="always",openFilePickerRef:T}){let O=X9(),A=!W&&d0(O),[w,S]=C2(!1),[j,C]=C2(!1),[y,I]=C2(null),[V,f]=C2(!1),h=S4(0),o=S4(null),B$=S4(null),a=U1(()=>B$.current?.click(),[]);if(T)T.current=a;let U$=U1((E)=>{if(o.current=E,z)z.current=E;if(E&&_)V1(E,P)},[z,_,P]);G9(()=>{if(H&&o.current){let E=o.current;if(E.focus(),E.value)E.setSelectionRange(E.value.length,E.value.length)}},[H]);let q$=U1(async(E)=>{if(!F4.includes(E.type)){I(D3);return}I(null),C(!0);try{let R=await _9(O,E);if("path"in R)Y(R.path);else I(R.error)}finally{C(!1)}},[O,Y]),z$=U1((E)=>{for(let R of E.clipboardData?.items??[])if(R.type.startsWith("image/")){E.preventDefault();let x=R.getAsFile();if(x)q$(x);return}},[q$]),J$=U1((E)=>{if(E.preventDefault(),h.current++,h.current===1)S(!0)},[]),_$=U1((E)=>{E.preventDefault()},[]),L$=U1((E)=>{if(E.preventDefault(),h.current--,h.current===0)S(!1)},[]),n=U1((E)=>{E.preventDefault(),h.current=0,S(!1);for(let R of E.dataTransfer?.files??[])if(R.type.startsWith("image/"))q$(R)},[q$]),d=U1((E)=>{if(J(E.currentTarget.value),_)E.currentTarget.style.height="auto",E.currentTarget.style.height=(P?Math.max(P,E.currentTarget.scrollHeight):E.currentTarget.scrollHeight)+"px"},[J,_,P]),Y$="w-full bg-transparent text-[13px] font-body text-text-primary resize-none focus:outline-none leading-relaxed p-0 border-none",v={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"}},c=A&&(M==="always"||M==="on-focus"&&V);return j$("div",{style:{position:"relative"},onDragEnter:A?J$:void 0,onDragOver:A?_$:void 0,onDragLeave:A?L$:void 0,onDrop:A?n:void 0,children:[j$("textarea",{ref:U$,value:$,onChange:W?void 0:d,onPaste:A?z$:void 0,onKeyDown:U,onClick:K,onFocus:()=>f(!0),onBlur:()=>{setTimeout(()=>f(!1),150)},readOnly:W,placeholder:X,className:B??Y$,style:N??v,rows:_?1:void 0},void 0,!1,void 0,this),A&&j$("input",{ref:B$,type:"file",accept:F4.join(","),multiple:!0,style:{display:"none"},onChange:(E)=>{let R=E.currentTarget.files;if(R)for(let x of R)q$(x);E.currentTarget.value=""}},void 0,!1,void 0,this),(Q.length>0||c)&&j$("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"6px",alignItems:"center"},children:[Q.map((E)=>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:P4(E),alt:"",style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}},void 0,!1,void 0,this),!W&&j$("button",{onClick:(R)=>{R.stopPropagation(),q(E)},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)]},E,!0,void 0,this)),c&&j$(R2,{onClick:a},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),y&&j$("div",{role:"alert",style:{fontSize:"11px",color:"var(--color-accent-red)",fontFamily:"'Inter', sans-serif",marginTop:"4px"},children:y},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 R2({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 w4({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:P4(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 H9}from"@fabrika/annotations/runtime";import{useContext as W9,useEffect as U9,useRef as K9}from"react";import{jsxDEV as S$,Fragment as y3}from"react/jsx-dev-runtime";function B9($){let J=g0($);return J.length>80?J.slice(0,80)+"...":J}function i0({annotations:$,readOnly:J=!1,onSelect:Q,onReveal:Y,includedRemoteIds:q,onToggleRemoteId:G}){let{updateAnnotation:X,removeAnnotation:H,addAnnotationImage:_,removeAnnotationImage:W,activeAnnotationId:U,setActiveAnnotationId:K}=Z1(),z=W9(H9),B=K9(new Map);U9(()=>{if(J||!U)return;let A=B.current.get(U);if(A)A.scrollIntoView({behavior:"smooth",block:"nearest"})},[U,J]);let N=(A)=>{K(A),J0(A,!0)},P=(A)=>{K(null),J0(A,!1)},M=(A)=>{if(A.id===U){K(null);return}K(A.id),Q?.(A)},T=!!q&&!!G,O=(A)=>{let w=T&&A.source==="remote";return S$("div",{ref:(S)=>{if(S)B.current.set(A.id,S);else B.current.delete(A.id)},className:`group/ann relative px-3 py-2.5 transition-colors duration-150 ${J?"cursor-pointer ":""}${U===A.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(A.id),onMouseLeave:()=>P(A.id),onClick:()=>M(A),children:[w&&A.author&&S$("div",{className:"flex items-center gap-1.5 mb-1.5",children:[S$("input",{type:"checkbox",checked:q.has(A.id),onChange:(S)=>{S.stopPropagation(),G(A.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:A.author.name.charAt(0)},void 0,!1,void 0,this),S$("span",{className:"text-[11px] font-medium text-accent-purple font-body",children:A.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:B9(A.snippet)},void 0,!1,void 0,this),J?S$(y3,{children:[A.note.trim()&&S$("div",{className:"text-[13px] font-body text-text-primary leading-relaxed",children:A.note},void 0,!1,void 0,this),S$(w4,{images:A.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:A.note},void 0,!1,void 0,this):S$("div",{onClick:(S)=>S.stopPropagation(),children:S$(r0,{note:A.note,onNoteChange:(S)=>X(A.id,S),images:A.images||[],onAddImage:(S)=>_(A.id,S),onRemoveImage:(S)=>W(A.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(A)},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(A.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)]},A.id,!0,void 0,this)};return S$(y3,{children:$.map(O)},void 0,!1,void 0,this)}function o0($){let J=[],Q=$.snippet.trim(),Y=$.context,q=g0(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 K=N2($);J.push(`> L${H}: ${K}`)}else if(W.length<=6)for(let K=0;K<W.length;K++)J.push(`> ${H+K} | ${W[K]}`);else{for(let K=0;K<3;K++)J.push(`> ${H+K} | ${W[K]}`);J.push(`> ... (${W.length} lines)`);for(let K=W.length-3;K<W.length;K++)J.push(`> ${H+K} | ${W[K]}`)}}else{let H=N2($);if(Q.split(`
3
- `).length<=3)J.push(`> ${H.split(`
1
+ var Y8=Object.defineProperty;var X8=($)=>$;function G8($,Q){this[$]=X8.bind(null,Q)}var _8=($,Q)=>{for(var J in Q)Y8($,J,{get:Q[J],enumerable:!0,configurable:!0,set:G8.bind(Q,J)})};import{ActiveViewCtx as Kq,SessionContext as e6}from"#canvas/runtime";import{AnnotationCtx as VX,AnnotationHostContext as CX,SessionContext as RX,useAnnotationHost as DX,useAnnotations as IX}from"@fabrika/annotations/runtime";function A1($,Q){let J=[],Y=j3($);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 W=document.createElement("mark");W.setAttribute("data-annotation-id",Q);try{G.surroundContents(W)}catch{let _=G.extractContents();W.appendChild(_),G.insertNode(W)}J.push(W)}return J}function E0($){let Q=$.parentElement;if(Q?.classList.contains("select-none"))return!1;if(Q?.closest("[data-annotation-id]"))return!1;return!0}function j3($){let Q=[],J=$.commonAncestorContainer;if(J.nodeType===Node.TEXT_NODE)return Q.push(J),Q;let Y=document.createTreeWalker(J,NodeFilter.SHOW_TEXT),q;while(q=Y.nextNode()){if(!E0(q))continue;if($.intersectsNode(q))Q.push(q)}return Q}function W8($,Q){let J=document.createRange();if(J.selectNodeContents($),$===Q.startContainer)J.setStart($,Q.startOffset);if($===Q.endContainer)J.setEnd($,Q.endOffset);return J.toString()}function b3($){let Q="";for(let J of j3($))Q+=W8(J,$);return Q}function q0($,Q){let J=document.querySelectorAll(`[data-annotation-id="${$}"]`);for(let Y of J)Y.classList.toggle("mark-active",Q)}function v0($,Q){if(Q!=null&&Q!==$)q0(Q,!1);if($!=null)q0($,!0)}function g0($,Q){let J=document.querySelectorAll(`[data-annotation-id="${$}"]`);for(let Y of J)Y.setAttribute("data-annotation-id",Q)}function m0($,Q){for(let J of Q){if($.querySelector(`[data-annotation-id="${J.id}"]`))continue;let Y=J.snippet;if(!Y)continue;let{fullText:q,textNodes:G}=H8($),X=[],W=0;while(!0){let M=q.indexOf(Y,W);if(M===-1)break;X.push(M),W=M+1}let[_]=X;if(_===void 0)continue;let H=_;if(X.length>1&&J.context){let M=-1;for(let L of X){let F=0;if(J.context.before){let w=q.slice(Math.max(0,L-80),L);if(w.includes(J.context.before))F+=2;else if(J.context.before.length>10&&w.includes(J.context.before.slice(-10)))F+=1}if(J.context.after){let w=q.slice(L+Y.length,L+Y.length+80);if(w.includes(J.context.after))F+=2;else if(J.context.after.length>10&&w.includes(J.context.after.slice(0,10)))F+=1}if(F>M)M=F,H=L}}let U=H,K=H+Y.length,N=T3(G,U),O=T3(G,K);if(!N||!O)continue;try{let M=document.createRange();M.setStart(N.node,N.offset),M.setEnd(O.node,O.offset),A1(M,J.id)}catch{}}}function H8($){let Q=[],J="",Y=document.createTreeWalker($,NodeFilter.SHOW_TEXT),q;while(q=Y.nextNode()){if(!E0(q))continue;Q.push({node:q,start:J.length}),J+=q.textContent||""}return{fullText:J,textNodes:Q}}function T3($,Q){for(let J=$.length-1;J>=0;J--){let Y=$[J];if(!Y||Y.start>Q)continue;let q=Q-Y.start,G=Y.node.textContent?.length??0;if(q<=G)return{node:Y.node,offset:q}}return null}function x0($){let Q=document.querySelectorAll(`[data-annotation-id="${$}"]`);for(let J of Q){let Y=J.parentNode;if(!Y)continue;if(J.tagName!=="MARK"){Y.removeChild(J);continue}while(J.firstChild)Y.insertBefore(J.firstChild,J);Y.removeChild(J),Y.normalize()}}function P1($,Q){let J=Z3($,"before",60),Y=Z3($,"after",60),q=K8($.startContainer,Q);return{before:J,after:Y,hierarchy:q}}function Z3($,Q,J){let Y=U8(Q==="before"?$.startContainer:$.endContainer);if(!Y)return"";let q="";if(Q==="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(!E0(X))continue;q+=X.textContent||""}if(q.length>J){q=q.slice(-J);let W=q.indexOf(" ");if(W>0)q=q.slice(W+1)}}else{let G=document.createTreeWalker(Y,NodeFilter.SHOW_TEXT),X=!1,W;while(W=G.nextNode()){if(W===$.endContainer){q+=(W.textContent||"").slice($.endOffset),X=!0;continue}if(X){if(!E0(W))continue;q+=W.textContent||""}}if(q.length>J){q=q.slice(0,J);let _=q.lastIndexOf(" ");if(_>0)q=q.slice(0,_)}}return q.trim()}function U8($){let Q=new Set(["DIV","P","LI","PRE","BLOCKQUOTE","SECTION","ARTICLE"]),J=$.parentElement;while(J){if(Q.has(J.tagName))return J;J=J.parentElement}return null}function K8($,Q){let J=[],Y=$ instanceof Element?$:$.parentElement;while(Y&&Y!==Q){let q=Y.getAttribute?.("data-task-id");if(q){let X=Y.querySelector(".font-semibold");if(X)J.unshift(X.textContent?.trim()||q)}let G=B8(Y);if(G)J.unshift(G);Y=Y.parentElement}return J}function B8($){if($.getAttribute("data-md")==="section"){let J=$.getAttribute("data-md-title");if(J)return J}if($.tagName!=="DIV")return null;return $.querySelector(":scope > button > .font-heading, :scope > div > .font-heading")?.textContent?.trim()||null}function A2($){let Q=$.snippet.trim(),J=$.context,Y=Q.length<30;if(J&&Y&&(J.before||J.after)){let q=[];if(J.before)q.push(`...${J.before} `);if(q.push(`**${Q}**`),J.after)q.push(` ${J.after}...`);return q.join("")}return Q}function h0($){return{kind:$.kind,owns:(Q)=>$.parse(Q)!==null,find:(Q,J)=>{let Y=$.parse(Q);return Y===null?null:$.find(Y,J)},restore:(Q,J)=>{let Y=$.parse(J.snippet);if(Y===null)return;$.restore?.(Y,Q,J)},describe:(Q)=>{let J=$.parse(Q);if(J===null||!$.describe)return null;return $.describe(J)}}}function V3($){let Q=document.createTreeWalker($,NodeFilter.SHOW_TEXT),J="";for(let Y=Q.nextNode();Y;Y=Q.nextNode()){let q=Y.parentElement?.closest("[aria-hidden='true']");if(q&&$.contains(q))continue;J+=Y.textContent??""}return J.trim()}function P2($,Q,J){return{selector:$,snippet:(Y)=>{let q=Y.getAttribute(J);return q?`${Q} ${q}`:null}}}var H4=[P2("[data-md='item']","[Item]","data-md-label"),P2("[data-md='section']","[Section]","data-md-title"),P2("[data-md='checklist-item']","[Checklist]","data-md-label"),P2("[data-md='image']","[Image]","data-md-src"),{selector:"[data-md='callout']",snippet:($)=>{return`[Callout:${$.getAttribute("data-md-type")||"info"}] ${V3($).slice(0,60)||"Callout"}`}},{selector:"[data-md='note']",snippet:($)=>`[Note] ${V3($).slice(0,60)||"Note"}`},{selector:"[data-md='table'] tbody tr",snippet:($)=>{let Q=Array.from($.querySelectorAll("td")).map((J)=>J.textContent?.trim()).filter(Boolean);return Q.length?`[Row] ${Q.join(" | ")}`:null}}],N8=["[data-md='choice-option']","[data-md='multichoice-option']","[data-md='userinput']","[data-md='rangeinput']"],S1=H4.map(($)=>$.selector).join(", "),Y0=[...H4.map(($)=>$.selector),...N8].join(", ");function s$($){for(let Q of H4)if($.matches(Q.selector))return Q.snippet($);return null}var U4={kind:"block",parse:($)=>$.startsWith("[")?{snippet:$}:null,format:($)=>$.snippet,find:($,Q)=>{for(let J of Q.querySelectorAll(S1)){if(!(J instanceof HTMLElement))continue;if(s$(J)===$.snippet)return J}return null}};var B4="data-annotation-image",O8=/^\[Region:(rect|ellipse)\] ([\s\S]+) @(0|[1-9]\d*),(0|[1-9]\d*),(0|[1-9]\d*),(0|[1-9]\d*)$/;function z8($){if($==="rect")return"rect";if($==="ellipse")return"ellipse";return null}function S2($){if($===void 0)return null;let Q=Number($);if(!Number.isInteger(Q)||Q<0||Q>1e4)return null;return Q}function C3($){return Math.min(1e4,Math.max(0,$))}function N4($,Q,J){if(!($.width>0)||!($.height>0))return null;return{x:C3(Math.round(Q/$.width*1e4)),y:C3(Math.round(J/$.height*1e4))}}function T2($,Q){let J=Math.min($.x,Q.x),Y=Math.min($.y,Q.y);return{x:J,y:Y,w:Math.min(1e4-J,Math.abs($.x-Q.x)),h:Math.min(1e4-Y,Math.abs($.y-Q.y))}}function O4($){return $.w>=30&&$.h>=30}function R3($){return{left:`${$.x/100}%`,top:`${$.y/100}%`,width:`${$.w/100}%`,height:`${$.h/100}%`}}function w2($){return`${($/100).toFixed(1).replace(/\.0$/,"")}%`}function j2($){let Q=`${w2($.x)}-${w2($.x+$.w)}`,J=`${w2($.y)}-${w2($.y+$.h)}`;return`[Region] ${$.src} — ${$.shape} x ${Q}, y ${J} of the image`}function K4($,Q){for(let J of Q.querySelectorAll("[data-md='image']")){if(!(J instanceof HTMLElement))continue;if(J.getAttribute("data-md-src")!==$)continue;let Y=J.querySelector("[data-annotation-image]");if(Y instanceof HTMLElement)return Y}return null}function b2($,Q){let J=R3(Q);$.style.left=J.left,$.style.top=J.top,$.style.width=J.width,$.style.height=J.height}function Z2($,Q,J){let Y=document.createElement("div");return Y.className="ann-region",Y.setAttribute("data-annotation-id",J),Y.setAttribute("data-annotation-region",Q),b2(Y,$),Y}var u0={kind:"region",parse:($)=>{let Q=O8.exec($);if(!Q)return null;let J=z8(Q[1]),Y=Q[2],q=S2(Q[3]),G=S2(Q[4]),X=S2(Q[5]),W=S2(Q[6]);if(J===null||Y===void 0)return null;if(q===null||G===null||X===null||W===null)return null;if(X<1||W<1)return null;return{src:Y,shape:J,x:q,y:G,w:X,h:W}},format:($)=>`[Region:${$.shape}] ${$.src} @${$.x},${$.y},${$.w},${$.h}`,find:($,Q)=>K4($.src,Q),restore:($,Q,J)=>{if(Q.querySelector(`[data-annotation-id="${J.id}"]`))return;let Y=K4($.src,Q);if(!Y)return;Y.appendChild(Z2($,$.shape,J.id))},describe:j2};var z4={kind:"text",parse:($)=>$?{text:$}:null,format:($)=>$.text,find:()=>null,restore:($,Q,J)=>{m0(Q,[J])}};var V2=[h0(u0),h0(U4),h0(z4)];function M4($,Q){for(let J of V2){let Y=J.find($,Q);if(Y)return Y}return null}function F4($,Q){for(let J of Q){if(!J.snippet)continue;for(let Y of V2)Y.restore($,J)}}function p0($){for(let Q of V2){let J=Q.describe($);if(J!==null)return J}return $}import{AnnotationCtx as NY,SessionContext as OY,useAnnotationHost as zY}from"@fabrika/annotations/runtime";import{useEffect as LY,useRef as AY,useState as PY}from"react";var B={};_8(B,{void:()=>e8,util:()=>q$,unknown:()=>s8,union:()=>q9,undefined:()=>o8,tuple:()=>G9,transformer:()=>M9,symbol:()=>i8,string:()=>m3,strictObject:()=>J9,setErrorMap:()=>L8,set:()=>H9,record:()=>_9,quotelessJson:()=>M8,promise:()=>z9,preprocess:()=>A9,pipeline:()=>P9,ostring:()=>S9,optional:()=>F9,onumber:()=>w9,oboolean:()=>T9,objectUtil:()=>L4,object:()=>Q9,number:()=>x3,nullable:()=>L9,null:()=>a8,never:()=>t8,nativeEnum:()=>O9,nan:()=>l8,map:()=>W9,makeIssue:()=>c0,literal:()=>B9,lazy:()=>K9,late:()=>p8,isValid:()=>w1,isDirty:()=>R2,isAsync:()=>G0,isAborted:()=>C2,intersection:()=>X9,instanceof:()=>c8,getParsedType:()=>t$,getErrorMap:()=>X0,function:()=>U9,enum:()=>N9,effect:()=>M9,discriminatedUnion:()=>Y9,defaultErrorMap:()=>H1,datetimeRegex:()=>E3,date:()=>r8,custom:()=>g3,coerce:()=>j9,boolean:()=>h3,bigint:()=>d8,array:()=>$9,any:()=>n8,addIssueToContext:()=>k,ZodVoid:()=>d0,ZodUnknown:()=>T1,ZodUnion:()=>B0,ZodUndefined:()=>U0,ZodType:()=>$$,ZodTuple:()=>$1,ZodTransformer:()=>r$,ZodSymbol:()=>l0,ZodString:()=>p$,ZodSet:()=>u1,ZodSchema:()=>$$,ZodRecord:()=>r0,ZodReadonly:()=>A0,ZodPromise:()=>p1,ZodPipeline:()=>a0,ZodParsedType:()=>R,ZodOptional:()=>l$,ZodObject:()=>A$,ZodNumber:()=>j1,ZodNullable:()=>K1,ZodNull:()=>K0,ZodNever:()=>e$,ZodNativeEnum:()=>M0,ZodNaN:()=>o0,ZodMap:()=>i0,ZodLiteral:()=>z0,ZodLazy:()=>O0,ZodIssueCode:()=>b,ZodIntersection:()=>N0,ZodFunction:()=>W0,ZodFirstPartyTypeKind:()=>l,ZodError:()=>E$,ZodEnum:()=>Z1,ZodEffects:()=>r$,ZodDiscriminatedUnion:()=>D2,ZodDefault:()=>F0,ZodDate:()=>x1,ZodCatch:()=>L0,ZodBranded:()=>I2,ZodBoolean:()=>H0,ZodBigInt:()=>b1,ZodArray:()=>c$,ZodAny:()=>h1,Schema:()=>$$,ParseStatus:()=>V$,OK:()=>R$,NEVER:()=>b9,INVALID:()=>p,EMPTY_PATH:()=>A8,DIRTY:()=>m1,BRAND:()=>u8});var q$;(function($){$.assertEqual=(q)=>{};function Q(q){}$.assertIs=Q;function J(q){throw Error()}$.assertNever=J,$.arrayToEnum=(q)=>{let G={};for(let X of q)G[X]=X;return G},$.getValidEnumValues=(q)=>{let G=$.objectKeys(q).filter((W)=>typeof q[q[W]]!=="number"),X={};for(let W of G)X[W]=q[W];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 L4;(function($){$.mergeShapes=(Q,J)=>{return{...Q,...J}}})(L4||(L4={}));var R=q$.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),t$=($)=>{switch(typeof $){case"undefined":return R.undefined;case"string":return R.string;case"number":return Number.isNaN($)?R.nan:R.number;case"boolean":return R.boolean;case"function":return R.function;case"bigint":return R.bigint;case"symbol":return R.symbol;case"object":if(Array.isArray($))return R.array;if($===null)return R.null;if($.then&&typeof $.then==="function"&&$.catch&&typeof $.catch==="function")return R.promise;if(typeof Map<"u"&&$ instanceof Map)return R.map;if(typeof Set<"u"&&$ instanceof Set)return R.set;if(typeof Date<"u"&&$ instanceof Date)return R.date;return R.object;default:return R.unknown}};var b=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"]),M8=($)=>{return JSON.stringify($,null,2).replace(/"([^"]+)":/g,"$1:")};class E$ extends Error{get errors(){return this.issues}constructor($){super();this.issues=[],this.addIssue=(J)=>{this.issues=[...this.issues,J]},this.addIssues=(J=[])=>{this.issues=[...this.issues,...J]};let Q=new.target.prototype;if(Object.setPrototypeOf)Object.setPrototypeOf(this,Q);else this.__proto__=Q;this.name="ZodError",this.issues=$}format($){let Q=$||function(q){return q.message},J={_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)J._errors.push(Q(G));else{let X=J,W=0;while(W<G.path.length){let _=G.path[W];if(W!==G.path.length-1)X[_]=X[_]||{_errors:[]};else X[_]=X[_]||{_errors:[]},X[_]._errors.push(Q(G));X=X[_],W++}}};return Y(this),J}static assert($){if(!($ instanceof E$))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($=(Q)=>Q.message){let Q={},J=[];for(let Y of this.issues)if(Y.path.length>0){let q=Y.path[0];Q[q]=Q[q]||[],Q[q].push($(Y))}else J.push($(Y));return{formErrors:J,fieldErrors:Q}}get formErrors(){return this.flatten()}}E$.create=($)=>{return new E$($)};var F8=($,Q)=>{let J;switch($.code){case b.invalid_type:if($.received===R.undefined)J="Required";else J=`Expected ${$.expected}, received ${$.received}`;break;case b.invalid_literal:J=`Invalid literal value, expected ${JSON.stringify($.expected,q$.jsonStringifyReplacer)}`;break;case b.unrecognized_keys:J=`Unrecognized key(s) in object: ${q$.joinValues($.keys,", ")}`;break;case b.invalid_union:J="Invalid input";break;case b.invalid_union_discriminator:J=`Invalid discriminator value. Expected ${q$.joinValues($.options)}`;break;case b.invalid_enum_value:J=`Invalid enum value. Expected ${q$.joinValues($.options)}, received '${$.received}'`;break;case b.invalid_arguments:J="Invalid function arguments";break;case b.invalid_return_type:J="Invalid function return type";break;case b.invalid_date:J="Invalid date";break;case b.invalid_string:if(typeof $.validation==="object")if("includes"in $.validation){if(J=`Invalid input: must include "${$.validation.includes}"`,typeof $.validation.position==="number")J=`${J} at one or more positions greater than or equal to ${$.validation.position}`}else if("startsWith"in $.validation)J=`Invalid input: must start with "${$.validation.startsWith}"`;else if("endsWith"in $.validation)J=`Invalid input: must end with "${$.validation.endsWith}"`;else q$.assertNever($.validation);else if($.validation!=="regex")J=`Invalid ${$.validation}`;else J="Invalid";break;case b.too_small:if($.type==="array")J=`Array must contain ${$.exact?"exactly":$.inclusive?"at least":"more than"} ${$.minimum} element(s)`;else if($.type==="string")J=`String must contain ${$.exact?"exactly":$.inclusive?"at least":"over"} ${$.minimum} character(s)`;else if($.type==="number")J=`Number must be ${$.exact?"exactly equal to ":$.inclusive?"greater than or equal to ":"greater than "}${$.minimum}`;else if($.type==="bigint")J=`Number must be ${$.exact?"exactly equal to ":$.inclusive?"greater than or equal to ":"greater than "}${$.minimum}`;else if($.type==="date")J=`Date must be ${$.exact?"exactly equal to ":$.inclusive?"greater than or equal to ":"greater than "}${new Date(Number($.minimum))}`;else J="Invalid input";break;case b.too_big:if($.type==="array")J=`Array must contain ${$.exact?"exactly":$.inclusive?"at most":"less than"} ${$.maximum} element(s)`;else if($.type==="string")J=`String must contain ${$.exact?"exactly":$.inclusive?"at most":"under"} ${$.maximum} character(s)`;else if($.type==="number")J=`Number must be ${$.exact?"exactly":$.inclusive?"less than or equal to":"less than"} ${$.maximum}`;else if($.type==="bigint")J=`BigInt must be ${$.exact?"exactly":$.inclusive?"less than or equal to":"less than"} ${$.maximum}`;else if($.type==="date")J=`Date must be ${$.exact?"exactly":$.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number($.maximum))}`;else J="Invalid input";break;case b.custom:J="Invalid input";break;case b.invalid_intersection_types:J="Intersection results could not be merged";break;case b.not_multiple_of:J=`Number must be a multiple of ${$.multipleOf}`;break;case b.not_finite:J="Number must be finite";break;default:J=Q.defaultError,q$.assertNever($)}return{message:J}},H1=F8;var D3=H1;function L8($){D3=$}function X0(){return D3}var c0=($)=>{let{data:Q,path:J,errorMaps:Y,issueData:q}=$,G=[...J,...q.path||[]],X={...q,path:G};if(q.message!==void 0)return{...q,path:G,message:q.message};let W="",_=Y.filter((H)=>!!H).slice().reverse();for(let H of _)W=H(X,{data:Q,defaultError:W}).message;return{...q,path:G,message:W}},A8=[];function k($,Q){let J=X0(),Y=c0({issueData:Q,data:$.data,path:$.path,errorMaps:[$.common.contextualErrorMap,$.schemaErrorMap,J,J===H1?void 0:H1].filter((q)=>!!q)});$.common.issues.push(Y)}class V${constructor(){this.value="valid"}dirty(){if(this.value==="valid")this.value="dirty"}abort(){if(this.value!=="aborted")this.value="aborted"}static mergeArray($,Q){let J=[];for(let Y of Q){if(Y.status==="aborted")return p;if(Y.status==="dirty")$.dirty();J.push(Y.value)}return{status:$.value,value:J}}static async mergeObjectAsync($,Q){let J=[];for(let Y of Q){let q=await Y.key,G=await Y.value;J.push({key:q,value:G})}return V$.mergeObjectSync($,J)}static mergeObjectSync($,Q){let J={};for(let Y of Q){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))J[q.value]=G.value}return{status:$.value,value:J}}}var p=Object.freeze({status:"aborted"}),m1=($)=>({status:"dirty",value:$}),R$=($)=>({status:"valid",value:$}),C2=($)=>$.status==="aborted",R2=($)=>$.status==="dirty",w1=($)=>$.status==="valid",G0=($)=>typeof Promise<"u"&&$ instanceof Promise;var m;(function($){$.errToObj=(Q)=>typeof Q==="string"?{message:Q}:Q||{},$.toString=(Q)=>typeof Q==="string"?Q:Q?.message})(m||(m={}));class d${constructor($,Q,J,Y){this._cachedPath=[],this.parent=$,this.data=Q,this._path=J,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 I3=($,Q)=>{if(w1(Q))return{success:!0,data:Q.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 J=new E$($.common.issues);return this._error=J,this._error}}}};function t($){if(!$)return{};let{errorMap:Q,invalid_type_error:J,required_error:Y,description:q}=$;if(Q&&(J||Y))throw Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);if(Q)return{errorMap:Q,description:q};return{errorMap:(X,W)=>{let{message:_}=$;if(X.code==="invalid_enum_value")return{message:_??W.defaultError};if(typeof W.data>"u")return{message:_??Y??W.defaultError};if(X.code!=="invalid_type")return{message:W.defaultError};return{message:_??J??W.defaultError}},description:q}}class $${get description(){return this._def.description}_getType($){return t$($.data)}_getOrReturnCtx($,Q){return Q||{common:$.parent.common,data:$.data,parsedType:t$($.data),schemaErrorMap:this._def.errorMap,path:$.path,parent:$.parent}}_processInputParams($){return{status:new V$,ctx:{common:$.parent.common,data:$.data,parsedType:t$($.data),schemaErrorMap:this._def.errorMap,path:$.path,parent:$.parent}}}_parseSync($){let Q=this._parse($);if(G0(Q))throw Error("Synchronous parse encountered promise.");return Q}_parseAsync($){let Q=this._parse($);return Promise.resolve(Q)}parse($,Q){let J=this.safeParse($,Q);if(J.success)return J.data;throw J.error}safeParse($,Q){let J={common:{issues:[],async:Q?.async??!1,contextualErrorMap:Q?.errorMap},path:Q?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:$,parsedType:t$($)},Y=this._parseSync({data:$,path:J.path,parent:J});return I3(J,Y)}"~validate"($){let Q={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:$,parsedType:t$($)};if(!this["~standard"].async)try{let J=this._parseSync({data:$,path:[],parent:Q});return w1(J)?{value:J.value}:{issues:Q.common.issues}}catch(J){if(J?.message?.toLowerCase()?.includes("encountered"))this["~standard"].async=!0;Q.common={issues:[],async:!0}}return this._parseAsync({data:$,path:[],parent:Q}).then((J)=>w1(J)?{value:J.value}:{issues:Q.common.issues})}async parseAsync($,Q){let J=await this.safeParseAsync($,Q);if(J.success)return J.data;throw J.error}async safeParseAsync($,Q){let J={common:{issues:[],contextualErrorMap:Q?.errorMap,async:!0},path:Q?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:$,parsedType:t$($)},Y=this._parse({data:$,path:J.path,parent:J}),q=await(G0(Y)?Y:Promise.resolve(Y));return I3(J,q)}refine($,Q){let J=(Y)=>{if(typeof Q==="string"||typeof Q>"u")return{message:Q};else if(typeof Q==="function")return Q(Y);else return Q};return this._refinement((Y,q)=>{let G=$(Y),X=()=>q.addIssue({code:b.custom,...J(Y)});if(typeof Promise<"u"&&G instanceof Promise)return G.then((W)=>{if(!W)return X(),!1;else return!0});if(!G)return X(),!1;else return!0})}refinement($,Q){return this._refinement((J,Y)=>{if(!$(J))return Y.addIssue(typeof Q==="function"?Q(J,Y):Q),!1;else return!0})}_refinement($){return new r$({schema:this,typeName:l.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:(Q)=>this["~validate"](Q)}}optional(){return l$.create(this,this._def)}nullable(){return K1.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return c$.create(this)}promise(){return p1.create(this,this._def)}or($){return B0.create([this,$],this._def)}and($){return N0.create(this,$,this._def)}transform($){return new r$({...t(this._def),schema:this,typeName:l.ZodEffects,effect:{type:"transform",transform:$}})}default($){let Q=typeof $==="function"?$:()=>$;return new F0({...t(this._def),innerType:this,defaultValue:Q,typeName:l.ZodDefault})}brand(){return new I2({typeName:l.ZodBranded,type:this,...t(this._def)})}catch($){let Q=typeof $==="function"?$:()=>$;return new L0({...t(this._def),innerType:this,catchValue:Q,typeName:l.ZodCatch})}describe($){return new this.constructor({...this._def,description:$})}pipe($){return a0.create(this,$)}readonly(){return A0.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}var P8=/^c[^\s-]{8,}$/i,S8=/^[0-9a-z]+$/,w8=/^[0-9A-HJKMNP-TV-Z]{26}$/i,T8=/^[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,j8=/^[a-z0-9_-]{21}$/i,b8=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,Z8=/^[-+]?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)?)??$/,V8=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,C8="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$",A4,R8=/^(?:(?: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])$/,D8=/^(?:(?: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])$/,I8=/^(([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]))$/,k8=/^(([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])$/,y8=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,f8=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,y3="((\\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])))",E8=new RegExp(`^${y3}$`);function f3($){let Q="[0-5]\\d";if($.precision)Q=`${Q}\\.\\d{${$.precision}}`;else if($.precision==null)Q=`${Q}(\\.\\d+)?`;let J=$.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${Q})${J}`}function v8($){return new RegExp(`^${f3($)}$`)}function E3($){let Q=`${y3}T${f3($)}`,J=[];if(J.push($.local?"Z?":"Z"),$.offset)J.push("([+-]\\d{2}:?\\d{2})");return Q=`${Q}(${J.join("|")})`,new RegExp(`^${Q}$`)}function g8($,Q){if((Q==="v4"||!Q)&&R8.test($))return!0;if((Q==="v6"||!Q)&&I8.test($))return!0;return!1}function m8($,Q){if(!b8.test($))return!1;try{let[J]=$.split(".");if(!J)return!1;let Y=J.replace(/-/g,"+").replace(/_/g,"/").padEnd(J.length+(4-J.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(Q&&q.alg!==Q)return!1;return!0}catch{return!1}}function x8($,Q){if((Q==="v4"||!Q)&&D8.test($))return!0;if((Q==="v6"||!Q)&&k8.test($))return!0;return!1}class p$ extends $${_parse($){if(this._def.coerce)$.data=String($.data);if(this._getType($)!==R.string){let q=this._getOrReturnCtx($);return k(q,{code:b.invalid_type,expected:R.string,received:q.parsedType}),p}let J=new V$,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:b.too_small,minimum:q.value,type:"string",inclusive:!0,exact:!1,message:q.message}),J.dirty()}else if(q.kind==="max"){if($.data.length>q.value)Y=this._getOrReturnCtx($,Y),k(Y,{code:b.too_big,maximum:q.value,type:"string",inclusive:!0,exact:!1,message:q.message}),J.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:b.too_big,maximum:q.value,type:"string",inclusive:!0,exact:!0,message:q.message});else if(X)k(Y,{code:b.too_small,minimum:q.value,type:"string",inclusive:!0,exact:!0,message:q.message});J.dirty()}}else if(q.kind==="email"){if(!V8.test($.data))Y=this._getOrReturnCtx($,Y),k(Y,{validation:"email",code:b.invalid_string,message:q.message}),J.dirty()}else if(q.kind==="emoji"){if(!A4)A4=new RegExp(C8,"u");if(!A4.test($.data))Y=this._getOrReturnCtx($,Y),k(Y,{validation:"emoji",code:b.invalid_string,message:q.message}),J.dirty()}else if(q.kind==="uuid"){if(!T8.test($.data))Y=this._getOrReturnCtx($,Y),k(Y,{validation:"uuid",code:b.invalid_string,message:q.message}),J.dirty()}else if(q.kind==="nanoid"){if(!j8.test($.data))Y=this._getOrReturnCtx($,Y),k(Y,{validation:"nanoid",code:b.invalid_string,message:q.message}),J.dirty()}else if(q.kind==="cuid"){if(!P8.test($.data))Y=this._getOrReturnCtx($,Y),k(Y,{validation:"cuid",code:b.invalid_string,message:q.message}),J.dirty()}else if(q.kind==="cuid2"){if(!S8.test($.data))Y=this._getOrReturnCtx($,Y),k(Y,{validation:"cuid2",code:b.invalid_string,message:q.message}),J.dirty()}else if(q.kind==="ulid"){if(!w8.test($.data))Y=this._getOrReturnCtx($,Y),k(Y,{validation:"ulid",code:b.invalid_string,message:q.message}),J.dirty()}else if(q.kind==="url")try{new URL($.data)}catch{Y=this._getOrReturnCtx($,Y),k(Y,{validation:"url",code:b.invalid_string,message:q.message}),J.dirty()}else if(q.kind==="regex"){if(q.regex.lastIndex=0,!q.regex.test($.data))Y=this._getOrReturnCtx($,Y),k(Y,{validation:"regex",code:b.invalid_string,message:q.message}),J.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:b.invalid_string,validation:{includes:q.value,position:q.position},message:q.message}),J.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:b.invalid_string,validation:{startsWith:q.value},message:q.message}),J.dirty()}else if(q.kind==="endsWith"){if(!$.data.endsWith(q.value))Y=this._getOrReturnCtx($,Y),k(Y,{code:b.invalid_string,validation:{endsWith:q.value},message:q.message}),J.dirty()}else if(q.kind==="datetime"){if(!E3(q).test($.data))Y=this._getOrReturnCtx($,Y),k(Y,{code:b.invalid_string,validation:"datetime",message:q.message}),J.dirty()}else if(q.kind==="date"){if(!E8.test($.data))Y=this._getOrReturnCtx($,Y),k(Y,{code:b.invalid_string,validation:"date",message:q.message}),J.dirty()}else if(q.kind==="time"){if(!v8(q).test($.data))Y=this._getOrReturnCtx($,Y),k(Y,{code:b.invalid_string,validation:"time",message:q.message}),J.dirty()}else if(q.kind==="duration"){if(!Z8.test($.data))Y=this._getOrReturnCtx($,Y),k(Y,{validation:"duration",code:b.invalid_string,message:q.message}),J.dirty()}else if(q.kind==="ip"){if(!g8($.data,q.version))Y=this._getOrReturnCtx($,Y),k(Y,{validation:"ip",code:b.invalid_string,message:q.message}),J.dirty()}else if(q.kind==="jwt"){if(!m8($.data,q.alg))Y=this._getOrReturnCtx($,Y),k(Y,{validation:"jwt",code:b.invalid_string,message:q.message}),J.dirty()}else if(q.kind==="cidr"){if(!x8($.data,q.version))Y=this._getOrReturnCtx($,Y),k(Y,{validation:"cidr",code:b.invalid_string,message:q.message}),J.dirty()}else if(q.kind==="base64"){if(!y8.test($.data))Y=this._getOrReturnCtx($,Y),k(Y,{validation:"base64",code:b.invalid_string,message:q.message}),J.dirty()}else if(q.kind==="base64url"){if(!f8.test($.data))Y=this._getOrReturnCtx($,Y),k(Y,{validation:"base64url",code:b.invalid_string,message:q.message}),J.dirty()}else q$.assertNever(q);return{status:J.value,value:$.data}}_regex($,Q,J){return this.refinement((Y)=>$.test(Y),{validation:Q,code:b.invalid_string,...m.errToObj(J)})}_addCheck($){return new p$({...this._def,checks:[...this._def.checks,$]})}email($){return this._addCheck({kind:"email",...m.errToObj($)})}url($){return this._addCheck({kind:"url",...m.errToObj($)})}emoji($){return this._addCheck({kind:"emoji",...m.errToObj($)})}uuid($){return this._addCheck({kind:"uuid",...m.errToObj($)})}nanoid($){return this._addCheck({kind:"nanoid",...m.errToObj($)})}cuid($){return this._addCheck({kind:"cuid",...m.errToObj($)})}cuid2($){return this._addCheck({kind:"cuid2",...m.errToObj($)})}ulid($){return this._addCheck({kind:"ulid",...m.errToObj($)})}base64($){return this._addCheck({kind:"base64",...m.errToObj($)})}base64url($){return this._addCheck({kind:"base64url",...m.errToObj($)})}jwt($){return this._addCheck({kind:"jwt",...m.errToObj($)})}ip($){return this._addCheck({kind:"ip",...m.errToObj($)})}cidr($){return this._addCheck({kind:"cidr",...m.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,...m.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,...m.errToObj($?.message)})}duration($){return this._addCheck({kind:"duration",...m.errToObj($)})}regex($,Q){return this._addCheck({kind:"regex",regex:$,...m.errToObj(Q)})}includes($,Q){return this._addCheck({kind:"includes",value:$,position:Q?.position,...m.errToObj(Q?.message)})}startsWith($,Q){return this._addCheck({kind:"startsWith",value:$,...m.errToObj(Q)})}endsWith($,Q){return this._addCheck({kind:"endsWith",value:$,...m.errToObj(Q)})}min($,Q){return this._addCheck({kind:"min",value:$,...m.errToObj(Q)})}max($,Q){return this._addCheck({kind:"max",value:$,...m.errToObj(Q)})}length($,Q){return this._addCheck({kind:"length",value:$,...m.errToObj(Q)})}nonempty($){return this.min(1,m.errToObj($))}trim(){return new p$({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new p$({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new p$({...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 Q of this._def.checks)if(Q.kind==="min"){if($===null||Q.value>$)$=Q.value}return $}get maxLength(){let $=null;for(let Q of this._def.checks)if(Q.kind==="max"){if($===null||Q.value<$)$=Q.value}return $}}p$.create=($)=>{return new p$({checks:[],typeName:l.ZodString,coerce:$?.coerce??!1,...t($)})};function h8($,Q){let J=($.toString().split(".")[1]||"").length,Y=(Q.toString().split(".")[1]||"").length,q=J>Y?J:Y,G=Number.parseInt($.toFixed(q).replace(".","")),X=Number.parseInt(Q.toFixed(q).replace(".",""));return G%X/10**q}class j1 extends $${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($)!==R.number){let q=this._getOrReturnCtx($);return k(q,{code:b.invalid_type,expected:R.number,received:q.parsedType}),p}let J=void 0,Y=new V$;for(let q of this._def.checks)if(q.kind==="int"){if(!q$.isInteger($.data))J=this._getOrReturnCtx($,J),k(J,{code:b.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)J=this._getOrReturnCtx($,J),k(J,{code:b.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)J=this._getOrReturnCtx($,J),k(J,{code:b.too_big,maximum:q.value,type:"number",inclusive:q.inclusive,exact:!1,message:q.message}),Y.dirty()}else if(q.kind==="multipleOf"){if(h8($.data,q.value)!==0)J=this._getOrReturnCtx($,J),k(J,{code:b.not_multiple_of,multipleOf:q.value,message:q.message}),Y.dirty()}else if(q.kind==="finite"){if(!Number.isFinite($.data))J=this._getOrReturnCtx($,J),k(J,{code:b.not_finite,message:q.message}),Y.dirty()}else q$.assertNever(q);return{status:Y.value,value:$.data}}gte($,Q){return this.setLimit("min",$,!0,m.toString(Q))}gt($,Q){return this.setLimit("min",$,!1,m.toString(Q))}lte($,Q){return this.setLimit("max",$,!0,m.toString(Q))}lt($,Q){return this.setLimit("max",$,!1,m.toString(Q))}setLimit($,Q,J,Y){return new j1({...this._def,checks:[...this._def.checks,{kind:$,value:Q,inclusive:J,message:m.toString(Y)}]})}_addCheck($){return new j1({...this._def,checks:[...this._def.checks,$]})}int($){return this._addCheck({kind:"int",message:m.toString($)})}positive($){return this._addCheck({kind:"min",value:0,inclusive:!1,message:m.toString($)})}negative($){return this._addCheck({kind:"max",value:0,inclusive:!1,message:m.toString($)})}nonpositive($){return this._addCheck({kind:"max",value:0,inclusive:!0,message:m.toString($)})}nonnegative($){return this._addCheck({kind:"min",value:0,inclusive:!0,message:m.toString($)})}multipleOf($,Q){return this._addCheck({kind:"multipleOf",value:$,message:m.toString(Q)})}finite($){return this._addCheck({kind:"finite",message:m.toString($)})}safe($){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:m.toString($)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:m.toString($)})}get minValue(){let $=null;for(let Q of this._def.checks)if(Q.kind==="min"){if($===null||Q.value>$)$=Q.value}return $}get maxValue(){let $=null;for(let Q of this._def.checks)if(Q.kind==="max"){if($===null||Q.value<$)$=Q.value}return $}get isInt(){return!!this._def.checks.find(($)=>$.kind==="int"||$.kind==="multipleOf"&&q$.isInteger($.value))}get isFinite(){let $=null,Q=null;for(let J of this._def.checks)if(J.kind==="finite"||J.kind==="int"||J.kind==="multipleOf")return!0;else if(J.kind==="min"){if(Q===null||J.value>Q)Q=J.value}else if(J.kind==="max"){if($===null||J.value<$)$=J.value}return Number.isFinite(Q)&&Number.isFinite($)}}j1.create=($)=>{return new j1({checks:[],typeName:l.ZodNumber,coerce:$?.coerce||!1,...t($)})};class b1 extends $${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($)!==R.bigint)return this._getInvalidInput($);let J=void 0,Y=new V$;for(let q of this._def.checks)if(q.kind==="min"){if(q.inclusive?$.data<q.value:$.data<=q.value)J=this._getOrReturnCtx($,J),k(J,{code:b.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)J=this._getOrReturnCtx($,J),k(J,{code:b.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))J=this._getOrReturnCtx($,J),k(J,{code:b.not_multiple_of,multipleOf:q.value,message:q.message}),Y.dirty()}else q$.assertNever(q);return{status:Y.value,value:$.data}}_getInvalidInput($){let Q=this._getOrReturnCtx($);return k(Q,{code:b.invalid_type,expected:R.bigint,received:Q.parsedType}),p}gte($,Q){return this.setLimit("min",$,!0,m.toString(Q))}gt($,Q){return this.setLimit("min",$,!1,m.toString(Q))}lte($,Q){return this.setLimit("max",$,!0,m.toString(Q))}lt($,Q){return this.setLimit("max",$,!1,m.toString(Q))}setLimit($,Q,J,Y){return new b1({...this._def,checks:[...this._def.checks,{kind:$,value:Q,inclusive:J,message:m.toString(Y)}]})}_addCheck($){return new b1({...this._def,checks:[...this._def.checks,$]})}positive($){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:m.toString($)})}negative($){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:m.toString($)})}nonpositive($){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:m.toString($)})}nonnegative($){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:m.toString($)})}multipleOf($,Q){return this._addCheck({kind:"multipleOf",value:$,message:m.toString(Q)})}get minValue(){let $=null;for(let Q of this._def.checks)if(Q.kind==="min"){if($===null||Q.value>$)$=Q.value}return $}get maxValue(){let $=null;for(let Q of this._def.checks)if(Q.kind==="max"){if($===null||Q.value<$)$=Q.value}return $}}b1.create=($)=>{return new b1({checks:[],typeName:l.ZodBigInt,coerce:$?.coerce??!1,...t($)})};class H0 extends $${_parse($){if(this._def.coerce)$.data=Boolean($.data);if(this._getType($)!==R.boolean){let J=this._getOrReturnCtx($);return k(J,{code:b.invalid_type,expected:R.boolean,received:J.parsedType}),p}return R$($.data)}}H0.create=($)=>{return new H0({typeName:l.ZodBoolean,coerce:$?.coerce||!1,...t($)})};class x1 extends $${_parse($){if(this._def.coerce)$.data=new Date($.data);if(this._getType($)!==R.date){let q=this._getOrReturnCtx($);return k(q,{code:b.invalid_type,expected:R.date,received:q.parsedType}),p}if(Number.isNaN($.data.getTime())){let q=this._getOrReturnCtx($);return k(q,{code:b.invalid_date}),p}let J=new V$,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:b.too_small,message:q.message,inclusive:!0,exact:!1,minimum:q.value,type:"date"}),J.dirty()}else if(q.kind==="max"){if($.data.getTime()>q.value)Y=this._getOrReturnCtx($,Y),k(Y,{code:b.too_big,message:q.message,inclusive:!0,exact:!1,maximum:q.value,type:"date"}),J.dirty()}else q$.assertNever(q);return{status:J.value,value:new Date($.data.getTime())}}_addCheck($){return new x1({...this._def,checks:[...this._def.checks,$]})}min($,Q){return this._addCheck({kind:"min",value:$.getTime(),message:m.toString(Q)})}max($,Q){return this._addCheck({kind:"max",value:$.getTime(),message:m.toString(Q)})}get minDate(){let $=null;for(let Q of this._def.checks)if(Q.kind==="min"){if($===null||Q.value>$)$=Q.value}return $!=null?new Date($):null}get maxDate(){let $=null;for(let Q of this._def.checks)if(Q.kind==="max"){if($===null||Q.value<$)$=Q.value}return $!=null?new Date($):null}}x1.create=($)=>{return new x1({checks:[],coerce:$?.coerce||!1,typeName:l.ZodDate,...t($)})};class l0 extends $${_parse($){if(this._getType($)!==R.symbol){let J=this._getOrReturnCtx($);return k(J,{code:b.invalid_type,expected:R.symbol,received:J.parsedType}),p}return R$($.data)}}l0.create=($)=>{return new l0({typeName:l.ZodSymbol,...t($)})};class U0 extends $${_parse($){if(this._getType($)!==R.undefined){let J=this._getOrReturnCtx($);return k(J,{code:b.invalid_type,expected:R.undefined,received:J.parsedType}),p}return R$($.data)}}U0.create=($)=>{return new U0({typeName:l.ZodUndefined,...t($)})};class K0 extends $${_parse($){if(this._getType($)!==R.null){let J=this._getOrReturnCtx($);return k(J,{code:b.invalid_type,expected:R.null,received:J.parsedType}),p}return R$($.data)}}K0.create=($)=>{return new K0({typeName:l.ZodNull,...t($)})};class h1 extends $${constructor(){super(...arguments);this._any=!0}_parse($){return R$($.data)}}h1.create=($)=>{return new h1({typeName:l.ZodAny,...t($)})};class T1 extends $${constructor(){super(...arguments);this._unknown=!0}_parse($){return R$($.data)}}T1.create=($)=>{return new T1({typeName:l.ZodUnknown,...t($)})};class e$ extends $${_parse($){let Q=this._getOrReturnCtx($);return k(Q,{code:b.invalid_type,expected:R.never,received:Q.parsedType}),p}}e$.create=($)=>{return new e$({typeName:l.ZodNever,...t($)})};class d0 extends $${_parse($){if(this._getType($)!==R.undefined){let J=this._getOrReturnCtx($);return k(J,{code:b.invalid_type,expected:R.void,received:J.parsedType}),p}return R$($.data)}}d0.create=($)=>{return new d0({typeName:l.ZodVoid,...t($)})};class c$ extends $${_parse($){let{ctx:Q,status:J}=this._processInputParams($),Y=this._def;if(Q.parsedType!==R.array)return k(Q,{code:b.invalid_type,expected:R.array,received:Q.parsedType}),p;if(Y.exactLength!==null){let G=Q.data.length>Y.exactLength.value,X=Q.data.length<Y.exactLength.value;if(G||X)k(Q,{code:G?b.too_big:b.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}),J.dirty()}if(Y.minLength!==null){if(Q.data.length<Y.minLength.value)k(Q,{code:b.too_small,minimum:Y.minLength.value,type:"array",inclusive:!0,exact:!1,message:Y.minLength.message}),J.dirty()}if(Y.maxLength!==null){if(Q.data.length>Y.maxLength.value)k(Q,{code:b.too_big,maximum:Y.maxLength.value,type:"array",inclusive:!0,exact:!1,message:Y.maxLength.message}),J.dirty()}if(Q.common.async)return Promise.all([...Q.data].map((G,X)=>{return Y.type._parseAsync(new d$(Q,G,Q.path,X))})).then((G)=>{return V$.mergeArray(J,G)});let q=[...Q.data].map((G,X)=>{return Y.type._parseSync(new d$(Q,G,Q.path,X))});return V$.mergeArray(J,q)}get element(){return this._def.type}min($,Q){return new c$({...this._def,minLength:{value:$,message:m.toString(Q)}})}max($,Q){return new c$({...this._def,maxLength:{value:$,message:m.toString(Q)}})}length($,Q){return new c$({...this._def,exactLength:{value:$,message:m.toString(Q)}})}nonempty($){return this.min(1,$)}}c$.create=($,Q)=>{return new c$({type:$,minLength:null,maxLength:null,exactLength:null,typeName:l.ZodArray,...t(Q)})};function _0($){if($ instanceof A$){let Q={};for(let J in $.shape){let Y=$.shape[J];Q[J]=l$.create(_0(Y))}return new A$({...$._def,shape:()=>Q})}else if($ instanceof c$)return new c$({...$._def,type:_0($.element)});else if($ instanceof l$)return l$.create(_0($.unwrap()));else if($ instanceof K1)return K1.create(_0($.unwrap()));else if($ instanceof $1)return $1.create($.items.map((Q)=>_0(Q)));else return $}class A$ extends $${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(),Q=q$.objectKeys($);return this._cached={shape:$,keys:Q},this._cached}_parse($){if(this._getType($)!==R.object){let _=this._getOrReturnCtx($);return k(_,{code:b.invalid_type,expected:R.object,received:_.parsedType}),p}let{status:J,ctx:Y}=this._processInputParams($),{shape:q,keys:G}=this._getCached(),X=[];if(!(this._def.catchall instanceof e$&&this._def.unknownKeys==="strip")){for(let _ in Y.data)if(!G.includes(_))X.push(_)}let W=[];for(let _ of G){let H=q[_],U=Y.data[_];W.push({key:{status:"valid",value:_},value:H._parse(new d$(Y,U,Y.path,_)),alwaysSet:_ in Y.data})}if(this._def.catchall instanceof e$){let _=this._def.unknownKeys;if(_==="passthrough")for(let H of X)W.push({key:{status:"valid",value:H},value:{status:"valid",value:Y.data[H]}});else if(_==="strict"){if(X.length>0)k(Y,{code:b.unrecognized_keys,keys:X}),J.dirty()}else if(_==="strip");else throw Error("Internal ZodObject error: invalid unknownKeys value.")}else{let _=this._def.catchall;for(let H of X){let U=Y.data[H];W.push({key:{status:"valid",value:H},value:_._parse(new d$(Y,U,Y.path,H)),alwaysSet:H in Y.data})}}if(Y.common.async)return Promise.resolve().then(async()=>{let _=[];for(let H of W){let U=await H.key,K=await H.value;_.push({key:U,value:K,alwaysSet:H.alwaysSet})}return _}).then((_)=>{return V$.mergeObjectSync(J,_)});else return V$.mergeObjectSync(J,W)}get shape(){return this._def.shape()}strict($){return m.errToObj,new A$({...this._def,unknownKeys:"strict",...$!==void 0?{errorMap:(Q,J)=>{let Y=this._def.errorMap?.(Q,J).message??J.defaultError;if(Q.code==="unrecognized_keys")return{message:m.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:l.ZodObject})}setKey($,Q){return this.augment({[$]:Q})}catchall($){return new A$({...this._def,catchall:$})}pick($){let Q={};for(let J of q$.objectKeys($))if($[J]&&this.shape[J])Q[J]=this.shape[J];return new A$({...this._def,shape:()=>Q})}omit($){let Q={};for(let J of q$.objectKeys(this.shape))if(!$[J])Q[J]=this.shape[J];return new A$({...this._def,shape:()=>Q})}deepPartial(){return _0(this)}partial($){let Q={};for(let J of q$.objectKeys(this.shape)){let Y=this.shape[J];if($&&!$[J])Q[J]=Y;else Q[J]=Y.optional()}return new A$({...this._def,shape:()=>Q})}required($){let Q={};for(let J of q$.objectKeys(this.shape))if($&&!$[J])Q[J]=this.shape[J];else{let q=this.shape[J];while(q instanceof l$)q=q._def.innerType;Q[J]=q}return new A$({...this._def,shape:()=>Q})}keyof(){return v3(q$.objectKeys(this.shape))}}A$.create=($,Q)=>{return new A$({shape:()=>$,unknownKeys:"strip",catchall:e$.create(),typeName:l.ZodObject,...t(Q)})};A$.strictCreate=($,Q)=>{return new A$({shape:()=>$,unknownKeys:"strict",catchall:e$.create(),typeName:l.ZodObject,...t(Q)})};A$.lazycreate=($,Q)=>{return new A$({shape:$,unknownKeys:"strip",catchall:e$.create(),typeName:l.ZodObject,...t(Q)})};class B0 extends $${_parse($){let{ctx:Q}=this._processInputParams($),J=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 Q.common.issues.push(...X.ctx.common.issues),X.result;let G=q.map((X)=>new E$(X.ctx.common.issues));return k(Q,{code:b.invalid_union,unionErrors:G}),p}if(Q.common.async)return Promise.all(J.map(async(q)=>{let G={...Q,common:{...Q.common,issues:[]},parent:null};return{result:await q._parseAsync({data:Q.data,path:Q.path,parent:G}),ctx:G}})).then(Y);else{let q=void 0,G=[];for(let W of J){let _={...Q,common:{...Q.common,issues:[]},parent:null},H=W._parseSync({data:Q.data,path:Q.path,parent:_});if(H.status==="valid")return H;else if(H.status==="dirty"&&!q)q={result:H,ctx:_};if(_.common.issues.length)G.push(_.common.issues)}if(q)return Q.common.issues.push(...q.ctx.common.issues),q.result;let X=G.map((W)=>new E$(W));return k(Q,{code:b.invalid_union,unionErrors:X}),p}}get options(){return this._def.options}}B0.create=($,Q)=>{return new B0({options:$,typeName:l.ZodUnion,...t(Q)})};var U1=($)=>{if($ instanceof O0)return U1($.schema);else if($ instanceof r$)return U1($.innerType());else if($ instanceof z0)return[$.value];else if($ instanceof Z1)return $.options;else if($ instanceof M0)return q$.objectValues($.enum);else if($ instanceof F0)return U1($._def.innerType);else if($ instanceof U0)return[void 0];else if($ instanceof K0)return[null];else if($ instanceof l$)return[void 0,...U1($.unwrap())];else if($ instanceof K1)return[null,...U1($.unwrap())];else if($ instanceof I2)return U1($.unwrap());else if($ instanceof A0)return U1($.unwrap());else if($ instanceof L0)return U1($._def.innerType);else return[]};class D2 extends $${_parse($){let{ctx:Q}=this._processInputParams($);if(Q.parsedType!==R.object)return k(Q,{code:b.invalid_type,expected:R.object,received:Q.parsedType}),p;let J=this.discriminator,Y=Q.data[J],q=this.optionsMap.get(Y);if(!q)return k(Q,{code:b.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[J]}),p;if(Q.common.async)return q._parseAsync({data:Q.data,path:Q.path,parent:Q});else return q._parseSync({data:Q.data,path:Q.path,parent:Q})}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create($,Q,J){let Y=new Map;for(let q of Q){let G=U1(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 D2({typeName:l.ZodDiscriminatedUnion,discriminator:$,options:Q,optionsMap:Y,...t(J)})}}function P4($,Q){let J=t$($),Y=t$(Q);if($===Q)return{valid:!0,data:$};else if(J===R.object&&Y===R.object){let q=q$.objectKeys(Q),G=q$.objectKeys($).filter((W)=>q.indexOf(W)!==-1),X={...$,...Q};for(let W of G){let _=P4($[W],Q[W]);if(!_.valid)return{valid:!1};X[W]=_.data}return{valid:!0,data:X}}else if(J===R.array&&Y===R.array){if($.length!==Q.length)return{valid:!1};let q=[];for(let G=0;G<$.length;G++){let X=$[G],W=Q[G],_=P4(X,W);if(!_.valid)return{valid:!1};q.push(_.data)}return{valid:!0,data:q}}else if(J===R.date&&Y===R.date&&+$===+Q)return{valid:!0,data:$};else return{valid:!1}}class N0 extends $${_parse($){let{status:Q,ctx:J}=this._processInputParams($),Y=(q,G)=>{if(C2(q)||C2(G))return p;let X=P4(q.value,G.value);if(!X.valid)return k(J,{code:b.invalid_intersection_types}),p;if(R2(q)||R2(G))Q.dirty();return{status:Q.value,value:X.data}};if(J.common.async)return Promise.all([this._def.left._parseAsync({data:J.data,path:J.path,parent:J}),this._def.right._parseAsync({data:J.data,path:J.path,parent:J})]).then(([q,G])=>Y(q,G));else return Y(this._def.left._parseSync({data:J.data,path:J.path,parent:J}),this._def.right._parseSync({data:J.data,path:J.path,parent:J}))}}N0.create=($,Q,J)=>{return new N0({left:$,right:Q,typeName:l.ZodIntersection,...t(J)})};class $1 extends $${_parse($){let{status:Q,ctx:J}=this._processInputParams($);if(J.parsedType!==R.array)return k(J,{code:b.invalid_type,expected:R.array,received:J.parsedType}),p;if(J.data.length<this._def.items.length)return k(J,{code:b.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),p;if(!this._def.rest&&J.data.length>this._def.items.length)k(J,{code:b.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),Q.dirty();let q=[...J.data].map((G,X)=>{let W=this._def.items[X]||this._def.rest;if(!W)return null;return W._parse(new d$(J,G,J.path,X))}).filter((G)=>!!G);if(J.common.async)return Promise.all(q).then((G)=>{return V$.mergeArray(Q,G)});else return V$.mergeArray(Q,q)}get items(){return this._def.items}rest($){return new $1({...this._def,rest:$})}}$1.create=($,Q)=>{if(!Array.isArray($))throw Error("You must pass an array of schemas to z.tuple([ ... ])");return new $1({items:$,typeName:l.ZodTuple,rest:null,...t(Q)})};class r0 extends $${get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse($){let{status:Q,ctx:J}=this._processInputParams($);if(J.parsedType!==R.object)return k(J,{code:b.invalid_type,expected:R.object,received:J.parsedType}),p;let Y=[],q=this._def.keyType,G=this._def.valueType;for(let X in J.data)Y.push({key:q._parse(new d$(J,X,J.path,X)),value:G._parse(new d$(J,J.data[X],J.path,X)),alwaysSet:X in J.data});if(J.common.async)return V$.mergeObjectAsync(Q,Y);else return V$.mergeObjectSync(Q,Y)}get element(){return this._def.valueType}static create($,Q,J){if(Q instanceof $$)return new r0({keyType:$,valueType:Q,typeName:l.ZodRecord,...t(J)});return new r0({keyType:p$.create(),valueType:$,typeName:l.ZodRecord,...t(Q)})}}class i0 extends $${get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse($){let{status:Q,ctx:J}=this._processInputParams($);if(J.parsedType!==R.map)return k(J,{code:b.invalid_type,expected:R.map,received:J.parsedType}),p;let Y=this._def.keyType,q=this._def.valueType,G=[...J.data.entries()].map(([X,W],_)=>{return{key:Y._parse(new d$(J,X,J.path,[_,"key"])),value:q._parse(new d$(J,W,J.path,[_,"value"]))}});if(J.common.async){let X=new Map;return Promise.resolve().then(async()=>{for(let W of G){let _=await W.key,H=await W.value;if(_.status==="aborted"||H.status==="aborted")return p;if(_.status==="dirty"||H.status==="dirty")Q.dirty();X.set(_.value,H.value)}return{status:Q.value,value:X}})}else{let X=new Map;for(let W of G){let{key:_,value:H}=W;if(_.status==="aborted"||H.status==="aborted")return p;if(_.status==="dirty"||H.status==="dirty")Q.dirty();X.set(_.value,H.value)}return{status:Q.value,value:X}}}}i0.create=($,Q,J)=>{return new i0({valueType:Q,keyType:$,typeName:l.ZodMap,...t(J)})};class u1 extends $${_parse($){let{status:Q,ctx:J}=this._processInputParams($);if(J.parsedType!==R.set)return k(J,{code:b.invalid_type,expected:R.set,received:J.parsedType}),p;let Y=this._def;if(Y.minSize!==null){if(J.data.size<Y.minSize.value)k(J,{code:b.too_small,minimum:Y.minSize.value,type:"set",inclusive:!0,exact:!1,message:Y.minSize.message}),Q.dirty()}if(Y.maxSize!==null){if(J.data.size>Y.maxSize.value)k(J,{code:b.too_big,maximum:Y.maxSize.value,type:"set",inclusive:!0,exact:!1,message:Y.maxSize.message}),Q.dirty()}let q=this._def.valueType;function G(W){let _=new Set;for(let H of W){if(H.status==="aborted")return p;if(H.status==="dirty")Q.dirty();_.add(H.value)}return{status:Q.value,value:_}}let X=[...J.data.values()].map((W,_)=>q._parse(new d$(J,W,J.path,_)));if(J.common.async)return Promise.all(X).then((W)=>G(W));else return G(X)}min($,Q){return new u1({...this._def,minSize:{value:$,message:m.toString(Q)}})}max($,Q){return new u1({...this._def,maxSize:{value:$,message:m.toString(Q)}})}size($,Q){return this.min($,Q).max($,Q)}nonempty($){return this.min(1,$)}}u1.create=($,Q)=>{return new u1({valueType:$,minSize:null,maxSize:null,typeName:l.ZodSet,...t(Q)})};class W0 extends $${constructor(){super(...arguments);this.validate=this.implement}_parse($){let{ctx:Q}=this._processInputParams($);if(Q.parsedType!==R.function)return k(Q,{code:b.invalid_type,expected:R.function,received:Q.parsedType}),p;function J(X,W){return c0({data:X,path:Q.path,errorMaps:[Q.common.contextualErrorMap,Q.schemaErrorMap,X0(),H1].filter((_)=>!!_),issueData:{code:b.invalid_arguments,argumentsError:W}})}function Y(X,W){return c0({data:X,path:Q.path,errorMaps:[Q.common.contextualErrorMap,Q.schemaErrorMap,X0(),H1].filter((_)=>!!_),issueData:{code:b.invalid_return_type,returnTypeError:W}})}let q={errorMap:Q.common.contextualErrorMap},G=Q.data;if(this._def.returns instanceof p1){let X=this;return R$(async function(...W){let _=new E$([]),H=await X._def.args.parseAsync(W,q).catch((N)=>{throw _.addIssue(J(W,N)),_}),U=await Reflect.apply(G,this,H);return await X._def.returns._def.type.parseAsync(U,q).catch((N)=>{throw _.addIssue(Y(U,N)),_})})}else{let X=this;return R$(function(...W){let _=X._def.args.safeParse(W,q);if(!_.success)throw new E$([J(W,_.error)]);let H=Reflect.apply(G,this,_.data),U=X._def.returns.safeParse(H,q);if(!U.success)throw new E$([Y(H,U.error)]);return U.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...$){return new W0({...this._def,args:$1.create($).rest(T1.create())})}returns($){return new W0({...this._def,returns:$})}implement($){return this.parse($)}strictImplement($){return this.parse($)}static create($,Q,J){return new W0({args:$?$:$1.create([]).rest(T1.create()),returns:Q||T1.create(),typeName:l.ZodFunction,...t(J)})}}class O0 extends $${get schema(){return this._def.getter()}_parse($){let{ctx:Q}=this._processInputParams($);return this._def.getter()._parse({data:Q.data,path:Q.path,parent:Q})}}O0.create=($,Q)=>{return new O0({getter:$,typeName:l.ZodLazy,...t(Q)})};class z0 extends $${_parse($){if($.data!==this._def.value){let Q=this._getOrReturnCtx($);return k(Q,{received:Q.data,code:b.invalid_literal,expected:this._def.value}),p}return{status:"valid",value:$.data}}get value(){return this._def.value}}z0.create=($,Q)=>{return new z0({value:$,typeName:l.ZodLiteral,...t(Q)})};function v3($,Q){return new Z1({values:$,typeName:l.ZodEnum,...t(Q)})}class Z1 extends $${_parse($){if(typeof $.data!=="string"){let Q=this._getOrReturnCtx($),J=this._def.values;return k(Q,{expected:q$.joinValues(J),received:Q.parsedType,code:b.invalid_type}),p}if(!this._cache)this._cache=new Set(this._def.values);if(!this._cache.has($.data)){let Q=this._getOrReturnCtx($),J=this._def.values;return k(Q,{received:Q.data,code:b.invalid_enum_value,options:J}),p}return R$($.data)}get options(){return this._def.values}get enum(){let $={};for(let Q of this._def.values)$[Q]=Q;return $}get Values(){let $={};for(let Q of this._def.values)$[Q]=Q;return $}get Enum(){let $={};for(let Q of this._def.values)$[Q]=Q;return $}extract($,Q=this._def){return Z1.create($,{...this._def,...Q})}exclude($,Q=this._def){return Z1.create(this.options.filter((J)=>!$.includes(J)),{...this._def,...Q})}}Z1.create=v3;class M0 extends $${_parse($){let Q=q$.getValidEnumValues(this._def.values),J=this._getOrReturnCtx($);if(J.parsedType!==R.string&&J.parsedType!==R.number){let Y=q$.objectValues(Q);return k(J,{expected:q$.joinValues(Y),received:J.parsedType,code:b.invalid_type}),p}if(!this._cache)this._cache=new Set(q$.getValidEnumValues(this._def.values));if(!this._cache.has($.data)){let Y=q$.objectValues(Q);return k(J,{received:J.data,code:b.invalid_enum_value,options:Y}),p}return R$($.data)}get enum(){return this._def.values}}M0.create=($,Q)=>{return new M0({values:$,typeName:l.ZodNativeEnum,...t(Q)})};class p1 extends $${unwrap(){return this._def.type}_parse($){let{ctx:Q}=this._processInputParams($);if(Q.parsedType!==R.promise&&Q.common.async===!1)return k(Q,{code:b.invalid_type,expected:R.promise,received:Q.parsedType}),p;let J=Q.parsedType===R.promise?Q.data:Promise.resolve(Q.data);return R$(J.then((Y)=>{return this._def.type.parseAsync(Y,{path:Q.path,errorMap:Q.common.contextualErrorMap})}))}}p1.create=($,Q)=>{return new p1({type:$,typeName:l.ZodPromise,...t(Q)})};class r$ extends $${innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===l.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse($){let{status:Q,ctx:J}=this._processInputParams($),Y=this._def.effect||null,q={addIssue:(G)=>{if(k(J,G),G.fatal)Q.abort();else Q.dirty()},get path(){return J.path}};if(q.addIssue=q.addIssue.bind(q),Y.type==="preprocess"){let G=Y.transform(J.data,q);if(J.common.async)return Promise.resolve(G).then(async(X)=>{if(Q.value==="aborted")return p;let W=await this._def.schema._parseAsync({data:X,path:J.path,parent:J});if(W.status==="aborted")return p;if(W.status==="dirty")return m1(W.value);if(Q.value==="dirty")return m1(W.value);return W});else{if(Q.value==="aborted")return p;let X=this._def.schema._parseSync({data:G,path:J.path,parent:J});if(X.status==="aborted")return p;if(X.status==="dirty")return m1(X.value);if(Q.value==="dirty")return m1(X.value);return X}}if(Y.type==="refinement"){let G=(X)=>{let W=Y.refinement(X,q);if(J.common.async)return Promise.resolve(W);if(W instanceof Promise)throw Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return X};if(J.common.async===!1){let X=this._def.schema._parseSync({data:J.data,path:J.path,parent:J});if(X.status==="aborted")return p;if(X.status==="dirty")Q.dirty();return G(X.value),{status:Q.value,value:X.value}}else return this._def.schema._parseAsync({data:J.data,path:J.path,parent:J}).then((X)=>{if(X.status==="aborted")return p;if(X.status==="dirty")Q.dirty();return G(X.value).then(()=>{return{status:Q.value,value:X.value}})})}if(Y.type==="transform")if(J.common.async===!1){let G=this._def.schema._parseSync({data:J.data,path:J.path,parent:J});if(!w1(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:Q.value,value:X}}else return this._def.schema._parseAsync({data:J.data,path:J.path,parent:J}).then((G)=>{if(!w1(G))return p;return Promise.resolve(Y.transform(G.value,q)).then((X)=>({status:Q.value,value:X}))});q$.assertNever(Y)}}r$.create=($,Q,J)=>{return new r$({schema:$,typeName:l.ZodEffects,effect:Q,...t(J)})};r$.createWithPreprocess=($,Q,J)=>{return new r$({schema:Q,effect:{type:"preprocess",transform:$},typeName:l.ZodEffects,...t(J)})};class l$ extends $${_parse($){if(this._getType($)===R.undefined)return R$(void 0);return this._def.innerType._parse($)}unwrap(){return this._def.innerType}}l$.create=($,Q)=>{return new l$({innerType:$,typeName:l.ZodOptional,...t(Q)})};class K1 extends $${_parse($){if(this._getType($)===R.null)return R$(null);return this._def.innerType._parse($)}unwrap(){return this._def.innerType}}K1.create=($,Q)=>{return new K1({innerType:$,typeName:l.ZodNullable,...t(Q)})};class F0 extends $${_parse($){let{ctx:Q}=this._processInputParams($),J=Q.data;if(Q.parsedType===R.undefined)J=this._def.defaultValue();return this._def.innerType._parse({data:J,path:Q.path,parent:Q})}removeDefault(){return this._def.innerType}}F0.create=($,Q)=>{return new F0({innerType:$,typeName:l.ZodDefault,defaultValue:typeof Q.default==="function"?Q.default:()=>Q.default,...t(Q)})};class L0 extends $${_parse($){let{ctx:Q}=this._processInputParams($),J={...Q,common:{...Q.common,issues:[]}},Y=this._def.innerType._parse({data:J.data,path:J.path,parent:{...J}});if(G0(Y))return Y.then((q)=>{return{status:"valid",value:q.status==="valid"?q.value:this._def.catchValue({get error(){return new E$(J.common.issues)},input:J.data})}});else return{status:"valid",value:Y.status==="valid"?Y.value:this._def.catchValue({get error(){return new E$(J.common.issues)},input:J.data})}}removeCatch(){return this._def.innerType}}L0.create=($,Q)=>{return new L0({innerType:$,typeName:l.ZodCatch,catchValue:typeof Q.catch==="function"?Q.catch:()=>Q.catch,...t(Q)})};class o0 extends $${_parse($){if(this._getType($)!==R.nan){let J=this._getOrReturnCtx($);return k(J,{code:b.invalid_type,expected:R.nan,received:J.parsedType}),p}return{status:"valid",value:$.data}}}o0.create=($)=>{return new o0({typeName:l.ZodNaN,...t($)})};var u8=Symbol("zod_brand");class I2 extends $${_parse($){let{ctx:Q}=this._processInputParams($),J=Q.data;return this._def.type._parse({data:J,path:Q.path,parent:Q})}unwrap(){return this._def.type}}class a0 extends $${_parse($){let{status:Q,ctx:J}=this._processInputParams($);if(J.common.async)return(async()=>{let q=await this._def.in._parseAsync({data:J.data,path:J.path,parent:J});if(q.status==="aborted")return p;if(q.status==="dirty")return Q.dirty(),m1(q.value);else return this._def.out._parseAsync({data:q.value,path:J.path,parent:J})})();else{let Y=this._def.in._parseSync({data:J.data,path:J.path,parent:J});if(Y.status==="aborted")return p;if(Y.status==="dirty")return Q.dirty(),{status:"dirty",value:Y.value};else return this._def.out._parseSync({data:Y.value,path:J.path,parent:J})}}static create($,Q){return new a0({in:$,out:Q,typeName:l.ZodPipeline})}}class A0 extends $${_parse($){let Q=this._def.innerType._parse($),J=(Y)=>{if(w1(Y))Y.value=Object.freeze(Y.value);return Y};return G0(Q)?Q.then((Y)=>J(Y)):J(Q)}unwrap(){return this._def.innerType}}A0.create=($,Q)=>{return new A0({innerType:$,typeName:l.ZodReadonly,...t(Q)})};function k3($,Q){let J=typeof $==="function"?$(Q):typeof $==="string"?{message:$}:$;return typeof J==="string"?{message:J}:J}function g3($,Q={},J){if($)return h1.create().superRefine((Y,q)=>{let G=$(Y);if(G instanceof Promise)return G.then((X)=>{if(!X){let W=k3(Q,Y),_=W.fatal??J??!0;q.addIssue({code:"custom",...W,fatal:_})}});if(!G){let X=k3(Q,Y),W=X.fatal??J??!0;q.addIssue({code:"custom",...X,fatal:W})}return});return h1.create()}var p8={object:A$.lazycreate},l;(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"})(l||(l={}));var c8=($,Q={message:`Input not instance of ${$.name}`})=>g3((J)=>J instanceof $,Q),m3=p$.create,x3=j1.create,l8=o0.create,d8=b1.create,h3=H0.create,r8=x1.create,i8=l0.create,o8=U0.create,a8=K0.create,n8=h1.create,s8=T1.create,t8=e$.create,e8=d0.create,$9=c$.create,Q9=A$.create,J9=A$.strictCreate,q9=B0.create,Y9=D2.create,X9=N0.create,G9=$1.create,_9=r0.create,W9=i0.create,H9=u1.create,U9=W0.create,K9=O0.create,B9=z0.create,N9=Z1.create,O9=M0.create,z9=p1.create,M9=r$.create,F9=l$.create,L9=K1.create,A9=r$.createWithPreprocess,P9=a0.create,S9=()=>m3().optional(),w9=()=>x3().optional(),T9=()=>h3().optional(),j9={string:($)=>p$.create({...$,coerce:!0}),number:($)=>j1.create({...$,coerce:!0}),boolean:($)=>H0.create({...$,coerce:!0}),bigint:($)=>b1.create({...$,coerce:!0}),date:($)=>x1.create({...$,coerce:!0})};var b9=p;var Z9=B.object({before:B.string(),after:B.string(),hierarchy:B.array(B.string()),lineStart:B.number().optional(),lineEnd:B.number().optional()}).passthrough(),S4=B.object({id:B.string(),name:B.string()}).passthrough(),V9=B.object({url:B.string(),mime:B.string().optional()}).passthrough(),w4=B.object({id:B.string(),snippet:B.string(),note:B.string(),createdAt:B.string(),filePath:B.string().optional(),canvasFile:B.string().optional(),context:Z9.optional(),images:B.array(B.string()).optional(),attachments:B.array(V9).optional(),source:B.enum(["local","remote"]).optional(),author:S4.optional()}).passthrough(),C9=B.array(w4.optional().catch(void 0)).transform(($)=>$.filter((Q)=>Q!==void 0)).catch([]),T4=B.object({annotations:C9,generalNote:B.string().catch("")}).passthrough(),u3=B.object({path:B.string()}),p3=B.object({url:B.string()}),c3=B.object({error:B.string()});import{useCallback as l1,useMemo as R9,useState as D9}from"react";var g$="__agent-response__";function c1($){return $.filePath&&$.filePath!=="__agent-response__"?$.filePath:void 0}function n0($){return $.uploadUrl!==null}var j4=["image/png","image/jpeg","image/gif","image/webp"],l3="Only PNG, JPEG, GIF and WebP images can be attached";function x$(){return`ann-${Date.now()}-${Math.random().toString(36).slice(2,6)}`}function V1($,Q){$.style.height="auto",$.style.height=(Q?Math.max(Q,$.scrollHeight):$.scrollHeight)+"px"}function d3($){let Q=$?`[data-annotation-id="${CSS.escape($)}"]`:"[data-annotation-id]";for(let J of document.querySelectorAll(Q))if(J.tagName==="MARK"){let Y=J.parentNode;J.replaceWith(document.createTextNode(J.textContent||"")),Y?.normalize()}else J.remove()}function k2({annotations:$,setAnnotations:Q,generalNote:J,setGeneralNote:Y,remoteAnnotations:q,isReadOnly:G,onClear:X}){let[W,_]=D9(null),H=R9(()=>{if(!q?.length)return $;let w=new Set($.map((A)=>A.id)),z=q.filter((A)=>!w.has(A.id));return[...$,...z.map((A)=>({...A,source:"remote"}))]},[$,q]),U=l1((w,z,A,T,S,j,Z)=>{Q((y)=>[...y,{id:w,snippet:z,note:A,createdAt:new Date().toISOString(),filePath:T,context:S,...j?.length?{images:j}:{},...Z?{canvasFile:Z}:{}}])},[Q]),K=l1((w,z,A)=>{U(x$(),w,z,A)},[U]),N=l1((w,z)=>{Q((A)=>A.map((T)=>T.id===w?{...T,note:z}:T))},[Q]),O=l1((w)=>{if(!$.some((z)=>z.id===w))return;d3(w),Q((z)=>z.filter((A)=>A.id!==w)),_((z)=>z===w?null:z)},[$,Q]),M=l1((w,z)=>{Q((A)=>A.map((T)=>T.id===w?{...T,images:[...T.images||[],z]}:T))},[Q]),L=l1((w,z)=>{Q((A)=>A.map((T)=>T.id===w?{...T,images:(T.images||[]).filter((S)=>S!==z)}:T))},[Q]),F=l1(()=>{d3(),Q([]),Y(""),_(null),X?.()},[Q,Y,X]);return{annotations:H,generalNote:J,setGeneralNote:Y,activeAnnotationId:W,setActiveAnnotationId:_,addAnnotation:K,addAnnotationWithId:U,updateAnnotation:N,removeAnnotation:O,addAnnotationImage:M,removeAnnotationImage:L,clearAll:F,isReadOnly:G}}import{useAnnotations as C1}from"@fabrika/annotations/runtime";import{jsxDEV as bY}from"react/jsx-dev-runtime";import{jsxDEV as d1,Fragment as I9}from"react/jsx-dev-runtime";function b4({hasContent:$,onSubmit:Q,onSubmitEmpty:J,notice:Y,secondaryAction:q,placeholder:G="General notes...",submitLabel:X="Submit",emptyLabel:W="Submit without feedback"}){let{generalNote:_,setGeneralNote:H}=C1();return d1(I9,{children:[d1("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:d1("textarea",{value:_,onChange:(U)=>H(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)=>V1(U.currentTarget,40),ref:(U)=>{if(U)V1(U,40)}},void 0,!1,void 0,this)},void 0,!1,void 0,this),Y,d1("div",{className:"px-4 py-3 border-t border-border-subtle flex-shrink-0",children:$?d1("div",{className:"flex gap-2",children:[q,d1("button",{onClick:Q,className:"flex-1 py-2 rounded-lg font-body text-[13px] font-medium transition-all bg-btn-primary text-btn-primary-text hover:opacity-90 hover:-translate-y-px shadow-sm",children:X},void 0,!1,void 0,this)]},void 0,!0,void 0,this):d1("button",{onClick:J,className:"w-full py-2 rounded-lg font-body text-[13px] font-medium border border-border-medium text-text-secondary hover:text-text-primary hover:border-border-hover hover:bg-bg-input transition-all",children:W},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{useAnnotationHost as k9}from"@fabrika/annotations/runtime";import{useCallback as B1,useEffect as y9,useRef as Z4,useState as y2}from"react";import{jsxDEV as j$}from"react/jsx-dev-runtime";function V4($){if($.startsWith("/s/")||$.startsWith("http://")||$.startsWith("https://"))return $;return`/api/uploads/${$.split("/").pop()}`}async function f9($,Q){let J=$.uploadUrl;if(!J)return{error:"Uploads are not available here"};let Y=new FormData;Y.append("image",Q);try{let q=await fetch(J(),{method:"POST",body:Y}),G=await q.json();if(!q.ok){let X=c3.safeParse(G);return{error:X.success?X.data.error:`Upload failed (HTTP ${q.status})`}}return{path:$.isShared?p3.parse(G).url:u3.parse(G).path}}catch{return{error:"Upload failed"}}}function s0({note:$,onNoteChange:Q,images:J,onAddImage:Y,onRemoveImage:q,sessionId:G,placeholder:X="Add your note...",autoFocus:W=!1,autoResize:_=!1,readOnly:H=!1,onKeyDown:U,onTextareaClick:K,textareaRef:N,textareaClassName:O,textareaStyle:M,minHeight:L,attachButton:F="always",openFilePickerRef:w}){let z=k9(),A=!H&&n0(z),[T,S]=y2(!1),[j,Z]=y2(!1),[y,V]=y2(null),[C,v]=y2(!1),h=Z4(0),o=Z4(null),B$=Z4(null),a=B1(()=>B$.current?.click(),[]);if(w)w.current=a;let U$=B1((f)=>{if(o.current=f,N)N.current=f;if(f&&_)V1(f,L)},[N,_,L]);y9(()=>{if(W&&o.current){let f=o.current;if(f.focus(),f.value)f.setSelectionRange(f.value.length,f.value.length)}},[W]);let Y$=B1(async(f)=>{if(!j4.includes(f.type)){V(l3);return}V(null),Z(!0);try{let D=await f9(z,f);if("path"in D)Y(D.path);else V(D.error)}finally{Z(!1)}},[z,Y]),N$=B1((f)=>{for(let D of f.clipboardData?.items??[])if(D.type.startsWith("image/")){f.preventDefault();let x=D.getAsFile();if(x)Y$(x);return}},[Y$]),Q$=B1((f)=>{if(f.preventDefault(),h.current++,h.current===1)S(!0)},[]),_$=B1((f)=>{f.preventDefault()},[]),F$=B1((f)=>{if(f.preventDefault(),h.current--,h.current===0)S(!1)},[]),n=B1((f)=>{f.preventDefault(),h.current=0,S(!1);for(let D of f.dataTransfer?.files??[])if(D.type.startsWith("image/"))Y$(D)},[Y$]),d=B1((f)=>{if(Q(f.currentTarget.value),_)f.currentTarget.style.height="auto",f.currentTarget.style.height=(L?Math.max(L,f.currentTarget.scrollHeight):f.currentTarget.scrollHeight)+"px"},[Q,_,L]),X$="w-full bg-transparent text-[13px] font-body text-text-primary resize-none focus:outline-none leading-relaxed p-0 border-none",g={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"}},c=A&&(F==="always"||F==="on-focus"&&C);return j$("div",{style:{position:"relative"},onDragEnter:A?Q$:void 0,onDragOver:A?_$:void 0,onDragLeave:A?F$:void 0,onDrop:A?n:void 0,children:[j$("textarea",{ref:U$,value:$,onChange:H?void 0:d,onPaste:A?N$:void 0,onKeyDown:U,onClick:K,onFocus:()=>v(!0),onBlur:()=>{setTimeout(()=>v(!1),150)},readOnly:H,placeholder:X,className:O??X$,style:M??g,rows:_?1:void 0},void 0,!1,void 0,this),A&&j$("input",{ref:B$,type:"file",accept:j4.join(","),multiple:!0,style:{display:"none"},onChange:(f)=>{let D=f.currentTarget.files;if(D)for(let x of D)Y$(x);f.currentTarget.value=""}},void 0,!1,void 0,this),(J.length>0||c)&&j$("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"6px",alignItems:"center"},children:[J.map((f)=>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:V4(f),alt:"",style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}},void 0,!1,void 0,this),!H&&j$("button",{onClick:(D)=>{D.stopPropagation(),q(f)},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)]},f,!0,void 0,this)),c&&j$(f2,{onClick:a},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),y&&j$("div",{role:"alert",style:{fontSize:"11px",color:"var(--color-accent-red)",fontFamily:"'Inter', sans-serif",marginTop:"4px"},children:y},void 0,!1,void 0,this),T&&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 f2({onClick:$,size:Q=16}){return j$("button",{onClick:(J)=>{J.stopPropagation(),$()},style:{width:`${Q*2}px`,height:`${Q*2}px`,borderRadius:"6px",border:"none",background:"transparent",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--color-text-tertiary)",flexShrink:0,transition:"color 0.15s"},title:"Attach image",onMouseEnter:(J)=>{J.currentTarget.style.color="var(--color-text-secondary)"},onMouseLeave:(J)=>{J.currentTarget.style.color="var(--color-text-tertiary)"},children:j$("svg",{width:Q,height:Q,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 C4({images:$}){if(!$.length)return null;return j$("div",{style:{display:"flex",gap:"6px",flexWrap:"wrap",marginTop:"6px"},children:$.map((Q)=>j$("div",{style:{width:"56px",height:"56px",borderRadius:"6px",overflow:"hidden",border:"1px solid var(--color-border-subtle)",flexShrink:0},children:j$("img",{src:V4(Q),alt:"",style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}},void 0,!1,void 0,this)},Q,!1,void 0,this))},void 0,!1,void 0,this)}import{SessionContext as E9}from"@fabrika/annotations/runtime";import{useContext as v9,useEffect as g9,useRef as m9}from"react";import{jsxDEV as P$,Fragment as r3}from"react/jsx-dev-runtime";function x9($){let Q=p0($);return Q.length>80?Q.slice(0,80)+"...":Q}function t0({annotations:$,readOnly:Q=!1,onSelect:J,onReveal:Y,includedRemoteIds:q,onToggleRemoteId:G}){let{updateAnnotation:X,removeAnnotation:W,addAnnotationImage:_,removeAnnotationImage:H,activeAnnotationId:U,setActiveAnnotationId:K}=C1(),N=v9(E9),O=m9(new Map);g9(()=>{if(Q||!U)return;let A=O.current.get(U);if(A)A.scrollIntoView({behavior:"smooth",block:"nearest"})},[U,Q]);let M=(A)=>{K(A),q0(A,!0)},L=(A)=>{K(null),q0(A,!1)},F=(A)=>{if(A.id===U){K(null);return}K(A.id),J?.(A)},w=!!q&&!!G,z=(A)=>{let T=w&&A.source==="remote";return P$("div",{ref:(S)=>{if(S)O.current.set(A.id,S);else O.current.delete(A.id)},className:`group/ann relative px-3 py-2.5 transition-colors duration-150 ${Q?"cursor-pointer ":""}${U===A.id?"bg-highlight-selected":T?"bg-accent-purple-muted/30 hover:bg-accent-purple-muted/50":"odd:bg-bg-elevated-half hover:bg-bg-input"}`,onMouseEnter:()=>M(A.id),onMouseLeave:()=>L(A.id),onClick:()=>F(A),children:[T&&A.author&&P$("div",{className:"flex items-center gap-1.5 mb-1.5",children:[P$("input",{type:"checkbox",checked:q.has(A.id),onChange:(S)=>{S.stopPropagation(),G(A.id)},onClick:(S)=>S.stopPropagation(),className:"accent-accent-purple flex-shrink-0",title:"Include in submission"},void 0,!1,void 0,this),P$("span",{className:"inline-flex items-center justify-center w-4 h-4 rounded-full bg-accent-purple text-white text-[9px] font-medium uppercase",children:A.author.name.charAt(0)},void 0,!1,void 0,this),P$("span",{className:"text-[11px] font-medium text-accent-purple font-body",children:A.author.name},void 0,!1,void 0,this),P$("span",{className:"text-[10px] text-text-tertiary font-body uppercase tracking-widest",children:"Remote"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),P$("div",{className:"text-[11px] text-text-tertiary italic line-clamp-2 mb-1.5 leading-snug font-body border-l-2 border-border-medium pl-2",children:x9(A.snippet)},void 0,!1,void 0,this),Q?P$(r3,{children:[A.note.trim()&&P$("div",{className:"text-[13px] font-body text-text-primary leading-relaxed",children:A.note},void 0,!1,void 0,this),P$(C4,{images:A.images||[]},void 0,!1,void 0,this)]},void 0,!0,void 0,this):T?P$("div",{className:"text-[13px] font-body text-text-primary leading-relaxed whitespace-pre-wrap",children:A.note},void 0,!1,void 0,this):P$("div",{onClick:(S)=>S.stopPropagation(),children:P$(s0,{note:A.note,onNoteChange:(S)=>X(A.id,S),images:A.images||[],onAddImage:(S)=>_(A.id,S),onRemoveImage:(S)=>H(A.id,S),sessionId:N,autoResize:!0,minHeight:20,textareaClassName:"w-full bg-transparent text-[13px] font-body text-text-primary resize-none focus:outline-none leading-relaxed p-0 border-none min-h-[20px]",textareaStyle:{height:"auto",overflow:"hidden"},placeholder:"Add your note...",attachButton:"on-focus"},void 0,!1,void 0,this)},void 0,!1,void 0,this),P$("div",{className:"absolute top-1.5 right-1.5 opacity-0 group-hover/ann:opacity-100 transition-opacity duration-100 flex items-center gap-0.5",children:[Y&&P$("button",{onClick:(S)=>{S.stopPropagation(),Y(A)},className:"w-5 h-5 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-input transition-colors",title:"Scroll to annotation",children:P$("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[P$("circle",{cx:"12",cy:"12",r:"3"},void 0,!1,void 0,this),P$("path",{d:"M12 2v4M12 18v4M2 12h4M18 12h4"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),!Q&&!T&&P$("button",{onClick:(S)=>{S.stopPropagation(),W(A.id)},className:"w-5 h-5 flex items-center justify-center rounded text-text-tertiary hover:text-accent-red hover:bg-accent-red-muted transition-colors",title:"Delete annotation",children:P$("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[P$("polyline",{points:"3 6 5 6 21 6"},void 0,!1,void 0,this),P$("path",{d:"M19 6v14a2 2 0 01-2 2H7a2 2 0 01-2-2V6m3 0V4a2 2 0 012-2h4a2 2 0 012 2v2"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},A.id,!0,void 0,this)};return P$(r3,{children:$.map(z)},void 0,!1,void 0,this)}function E2($){let Q=[],J=$.snippet.trim(),Y=$.context,q=p0(J);if(q!==J)Q.push(`> ${q}`);else if($.filePath&&Y&&Y.lineStart!=null){let W=Y.lineStart,_=Y.lineEnd??W,H=J.split(`
2
+ `);if(J.length<30&&W===_&&(Y.before||Y.after)){let K=A2($);Q.push(`> L${W}: ${K}`)}else if(H.length<=6)for(let K=0;K<H.length;K++)Q.push(`> ${W+K} | ${H[K]}`);else{for(let K=0;K<3;K++)Q.push(`> ${W+K} | ${H[K]}`);Q.push(`> ... (${H.length} lines)`);for(let K=H.length-3;K<H.length;K++)Q.push(`> ${W+K} | ${H[K]}`)}}else{let W=A2($);if(J.split(`
3
+ `).length<=3)Q.push(`> ${W.split(`
4
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 z9,useAnnotationHost as N9}from"@fabrika/annotations/runtime";import{useCallback as I2,useContext as M9,useEffect as O9,useMemo as v3,useRef as D2,useState as F0}from"react";import{createPortal as L9}from"react-dom";function E3($){let J=/^(\d+(?:\.\d+)?)px$/.exec($.trim());return J?Number(J[1]):void 0}function f3($,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 F9}from"react/jsx-dev-runtime";function m3({anchorEl:$,scrollContainer:J,onClose:Q,ignoreSelector:Y,zIndex:q="50",padding:G="12px",width:X="280px",children:H}){let _=D2(null),W=D2(Q);W.current=Q;let{style:U,parent:K}=f3($,J,E3(X));return O9(()=>{let z=setTimeout(()=>{let B=(N)=>{if(_.current&&!_.current.contains(N.target)){if(Y&&N.target.closest?.(Y))return;W.current(),document.removeEventListener("mousedown",B)}};return document.addEventListener("mousedown",B),()=>document.removeEventListener("mousedown",B)},0);return()=>clearTimeout(z)},[Y]),L9(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),K)}var x3=[{label:"Clarity",items:["Unclear","Why?","Needs example","Missing context"]},{label:"Scope",items:["Overkill","Out of scope","Important","Risky"]},{label:"Action",items:["Simplify","Rethink","Expand on this","Skip this"]}],g3=x3.flatMap(($)=>$.items);function T4({anchorEl:$,scrollContainer:J,snippet:Q,truncateAt:Y=100,header:q,initialNote:G="",initialImages:X,onConfirm:H,onCancel:_,onDelete:W}){let U=M9(z9),K=N9(),z=d0(K),B=G!==""||!!W,[N,P]=F0(G),[M,T]=F0(X||[]),[O,A]=F0(null),[w,S]=F0(B),[j,C]=F0(!1),y=D2(null),I=D2(null),V=I2(()=>{if(N.trim()||M.length>0)H(N.trim(),M);else if(B&&W)W();else _()},[N,M,H,_,B,W]),f=I2(()=>{if(B){if(!N.trim()&&M.length===0&&W){W(),_();return}H(N,M);return}_()},[N,M,B,H,_,W]),h=!B,o=N.trim().length>0?g3.filter((R)=>R.toLowerCase().startsWith(N.trim().toLowerCase())):g3,B$=!h||w?[]:o.length===1&&o[0]?.toLowerCase()===N.trim().toLowerCase()?[]:o,a=new Set(B$),U$=x3.map((R)=>({label:R.label,items:R.items.filter((x)=>a.has(x))})).filter((R)=>R.items.length>0),q$=U$.map((R)=>R.items),z$=(R)=>q$[R]?.length??0,J$=q$.flat(),_$=v3(()=>{if(O===null)return 0;let R=0;for(let x=0;x<q$.length;x++){if(O<R+z$(x))return x;R+=z$(x)}return 0},[O,q$]),L$=v3(()=>{if(O===null)return 0;let R=0;for(let x=0;x<_$;x++)R+=z$(x);return O-R},[O,_$,q$]),n=(R,x)=>{let r=0;for(let M$=0;M$<R;M$++)r+=z$(M$);return r+x},[d,Y$]=F0(N);if(N!==d)Y$(N),A(null),S(B);let v=I2((R)=>{P(R)},[]),c=Q.length>Y?Q.slice(0,Y)+"...":Q,E=I2((R)=>{if(J$.length>0&&(R.key==="ArrowDown"||R.key==="ArrowUp"||R.key==="ArrowLeft"||R.key==="ArrowRight")){if(R.preventDefault(),O===null){A(0);return}if(R.key==="ArrowDown"){let r=Math.min(L$+1,z$(_$)-1);A(n(_$,r))}else if(R.key==="ArrowUp"){let r=Math.max(L$-1,0);A(n(_$,r))}else if(R.key==="ArrowRight"){let r=Math.min(_$+1,q$.length-1),M$=Math.min(L$,z$(r)-1);A(n(r,M$))}else if(R.key==="ArrowLeft"){let r=Math.max(_$-1,0),M$=Math.min(L$,z$(r)-1);A(n(r,M$))}return}let x=O===null?void 0:J$[O];if(x!==void 0){if(R.key==="Tab"){R.preventDefault(),v(x);return}if(R.key==="Enter"&&!R.shiftKey){R.preventDefault(),H(x,M);return}}if(R.key==="Enter"&&!R.shiftKey){R.preventDefault(),V();return}if(R.key==="Escape")if(J$.length>0&&!w)S(!0);else if(B)f();else _()},[J$,O,L$,_$,q$,n,v,H,M,V,w,B,f,_]);return b$(m3,{anchorEl:$,scrollContainer:J,onClose:B?f:_,ignoreSelector:B?"[data-annotation-id]":void 0,zIndex:B?"60":"50",padding:B?"10px 12px":"12px",width:"420px",children:[!B&&(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:["“",c,"”"]},void 0,!0,void 0,this)),b$(r0,{note:N,onNoteChange:P,images:M,onAddImage:(R)=>T((x)=>[...x,R]),onRemoveImage:(R)=>T((x)=>x.filter((r)=>r!==R)),sessionId:U,autoFocus:!0,autoResize:B,textareaRef:y,onKeyDown:E,attachButton:"none",openFilePickerRef:I,textareaStyle:B?{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:B?"6px":"8px"},children:[z&&b$(R2,{onClick:()=>I.current?.(),size:14},void 0,!1,void 0,this),b$("div",{style:{flex:1}},void 0,!1,void 0,this),B?b$("button",{onClick:()=>{if(W)W();_()},onMouseEnter:()=>C(!0),onMouseLeave:()=>C(!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$(F9,{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:V,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),J$.length>0&&b$("div",{style:{marginTop:"6px",borderTop:"1px solid var(--color-border-subtle)",paddingTop:"8px",display:"flex",gap:"4px"},children:U$.map((R)=>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:R.label},void 0,!1,void 0,this),R.items.map((x)=>{let r=J$.indexOf(x);return b$("div",{onMouseDown:(M$)=>{M$.preventDefault(),M$.stopPropagation(),v(x)},onMouseEnter:()=>A(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)})]},R.label,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function e$({anchorEl:$,scrollContainer:J,snippet:Q,truncateAt:Y,header:q,onAdd:G,onCancel:X}){return b$(T4,{anchorEl:$,scrollContainer:J,snippet:Q,truncateAt:Y,header:q,onConfirm:(H,_)=>G(H,_),onCancel:X},void 0,!1,void 0,this)}function l1({anchorEl:$,scrollContainer:J,initialNote:Q,initialImages:Y,onUpdate:q,onDelete:G,onClose:X}){return b$(T4,{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 A9,useRef as j4,useState as h3}from"react";import{jsxDEV as S9}from"react/jsx-dev-runtime";function b4($){let{containerRef:J,restoreKey:Q,shape:Y="rect",canvasFile:q,scrollContainer:G}=$,{addAnnotationWithId:X}=Z1(),[H,_]=h3(null),[W,U]=h3(!1),K=j4(X);K.current=X;let z=j4(q);z.current=q;let B=j4(Y);return B.current=Y,A9(()=>{let P=J.current;if(!P)return;let M=null;function T(C,y){let I=C.getBoundingClientRect();return _4(I,y.clientX-I.left,y.clientY-I.top)}function O(){if(!M)return;let{host:C,pointerId:y}=M;if(C.hasPointerCapture(y))C.releasePointerCapture(y);C.removeEventListener("pointermove",w),C.removeEventListener("pointerup",S),C.removeEventListener("pointercancel",j),M=null,U(!1)}function A(C){if(M||C.button!==0)return;let y=C.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(`[${G4}]`);if(!(I instanceof HTMLElement)||!P?.contains(I))return;let V=I.closest("[data-md='image']")?.getAttribute("data-md-src");if(!V)return;let f=T(I,C);if(!f)return;C.preventDefault(),I.setPointerCapture(C.pointerId);let h=E$(),o=P2({...f,w:0,h:0},B.current,h);o.classList.add("ann-region-draft"),I.appendChild(o),M={pointerId:C.pointerId,host:I,src:V,start:f,shape:B.current,overlay:o,id:h},I.addEventListener("pointermove",w),I.addEventListener("pointerup",S),I.addEventListener("pointercancel",j),U(!0)}function w(C){if(!M||M.pointerId!==C.pointerId)return;let y=T(M.host,C);if(!y)return;S2(M.overlay,F2(M.start,y))}function S(C){if(!M||M.pointerId!==C.pointerId)return;let{overlay:y,id:I,src:V,shape:f}=M,h=T(M.host,C)??M.start,o=F2(M.start,h);if(O(),!H4(o)){y.remove();return}S2(y,o);let B$={src:V,shape:f,...o};_({overlay:y,id:I,snippet:v0.format(B$),label:A2(B$)})}function j(C){if(!M||M.pointerId!==C.pointerId)return;M.overlay.remove(),O()}return P.addEventListener("pointerdown",A),()=>{if(P.removeEventListener("pointerdown",A),M)M.overlay.remove(),O()}},[Q]),{popovers:H?S9(e$,{anchorEl:H.overlay,scrollContainer:G,snippet:H.label,truncateAt:80,onAdd:(P,M)=>{H.overlay.classList.remove("ann-region-draft"),K.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 u3,useEffect as k2,useRef as d1,useState as p3}from"react";import{jsxDEV as V4,Fragment as P9}from"react/jsx-dev-runtime";function C1($){let{containerRef:J,restoreKey:Q,restoreAnnotations:Y,extractContext:q,filePath:G,canvasFile:X,scrollContainer:H}=$,{annotations:_,addAnnotationWithId:W,removeAnnotation:U,updateAnnotation:K,addAnnotationImage:z,removeAnnotationImage:B,activeAnnotationId:N,setActiveAnnotationId:P}=Z1(),[M,T]=p3(null),[O,A]=p3(null),w=d1(q);w.current=q;let S=d1(G);S.current=G;let j=d1(X);j.current=X;let C=d1(W);C.current=W;let y=d1(N);y.current=N;let I=d1(P);I.current=P;let V=Y.length;k2(()=>{if(!J.current)return;let a=setTimeout(()=>{if(J.current)K4(J.current,Y)},50);return()=>clearTimeout(a)},[Q,V]);let f=d1(null);k2(()=>{D0(N,f.current),f.current=N},[N]),k2(()=>{let a=J.current;if(!a)return;let U$=(J$)=>{let _$=J$.target.closest("[data-annotation-id]");if(!_$)return;J$.stopPropagation();let L$=_$.getAttribute("data-annotation-id");if(L$===y.current)T({anchorEl:_$,annId:L$});else I.current(L$)},q$=(J$)=>{let _$=J$.target.closest("[data-annotation-id]");if(_$)I.current(_$.getAttribute("data-annotation-id"))},z$=(J$)=>{let _$=J$.target.closest("[data-annotation-id]"),L$=J$.relatedTarget?.closest?.("[data-annotation-id]");if(_$&&!L$&&!document.getElementById("ann-inline-popover"))I.current(null)};return a.addEventListener("click",U$),a.addEventListener("mouseover",q$),a.addEventListener("mouseout",z$),()=>{a.removeEventListener("click",U$),a.removeEventListener("mouseover",q$),a.removeEventListener("mouseout",z$)}},[Q]),k2(()=>{let a=()=>h();return document.addEventListener("mouseup",a),()=>document.removeEventListener("mouseup",a)},[]);let h=u3(()=>{let a=window.getSelection();if(!a||a.isCollapsed||!a.toString().trim())return;if(!J.current)return;let U$=a.getRangeAt(0);if(!J.current.contains(U$.startContainer))return;if(U$.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let q$=B3(U$).trim();if(q$.length<2)return;let z$=w.current(U$),J$=U$.cloneRange(),_$=`__pending_${Date.now()}`;try{F1(J$,_$)}catch{}window.getSelection()?.removeAllRanges();let L$=document.querySelectorAll(`[data-annotation-id="${_$}"]`),n=L$[L$.length-1];if(!n)return;A({anchorEl:n,tempId:_$,snippet:q$,ctx:z$})},[]),o=u3((a,U$,q$,z$)=>{A({anchorEl:a,tempId:U$,snippet:q$,ctx:z$})},[]);return{popovers:V4(P9,{children:[M&&(()=>{let a=_.find((U$)=>U$.id===M.annId);if(!a)return null;return V4(l1,{anchorEl:M.anchorEl,scrollContainer:H,initialNote:a.note,initialImages:a.images,onUpdate:(U$,q$)=>{K(M.annId,U$);let z$=a.images||[];for(let J$ of q$)if(!z$.includes(J$))z(M.annId,J$);for(let J$ of z$)if(!q$.includes(J$))B(M.annId,J$)},onDelete:()=>{U(M.annId),P(null)},onClose:()=>T(null)},void 0,!1,void 0,this)})(),O&&V4(e$,{anchorEl:O.anchorEl,scrollContainer:H,snippet:O.snippet,truncateAt:80,onAdd:(a,U$)=>{let q$=E$();k0(O.tempId,q$),C.current(q$,O.snippet,a,S.current,O.ctx,U$,j.current),A(null)},onCancel:()=>{E0(O.tempId),A(null)}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),openCreatePopover:o,isPopoverOpen:!!(M||O)}}import{AnnotationCtx as I9}from"#canvas/runtime";import{AnnotationCtx as D9,AnnotationHostContext as k9}from"@fabrika/annotations/runtime";import{useCallback as P0,useEffect as t3,useMemo as y9,useRef as D4,useState as w0}from"react";var w9=L.object({}).passthrough(),T9=L.object({annotations:L.array(L.unknown()).catch([]),generalNote:L.string().catch(""),responses:L.array(L.unknown()).catch([])}),j9=L.tuple([L.unknown(),L.object({note:L.unknown(),value:L.unknown()})]);function $1($,J,Q="current"){let Y=`canvas:${$}:rev:${J}`;return Q==="next"?`${Y}:next-draft`:Y}function A0($,J){return`${$1($,J)}:draft-handled`}function r1($,J,Q){try{$.removeItem($1(J,Q)),$.removeItem(A0(J,Q))}catch{}}function Z4($){if(!$)return null;try{let J=JSON.parse($),Q=w9.safeParse(J);return Q.success?Q.data:null}catch{return null}}function b9($){let J=j9.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 C4($){if(!$)return!1;let{annotations:J,generalNote:Q,responses:Y}=T9.parse($);return J.length>0||Q.trim().length>0||Y.some(b9)}function y2($,J,Q,Y){try{let q=$1(J,Q);if(C4(Z4($.getItem(q))))return $.setItem(A0(J,Q),"1"),null;if($.getItem(A0(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 _=$1(J,X.revision,"next"),W=Z4($.getItem(_));if(!C4(W))return null;return $.setItem(q,JSON.stringify({...W,feedbackEntries:[]})),$.setItem(A0(J,Q),"1"),$.removeItem(_),X.revision}let H=Z4($.getItem($1(J,X.revision)));if(!C4(H)){if($.getItem(A0(J,X.revision))!==null)return null;continue}return $.setItem(q,JSON.stringify({...H,feedbackEntries:[]})),$.setItem(A0(J,Q),"1"),X.revision}}catch{}return null}function R4($,J){let Q=new Map;for(let[Y,q]of $)if(J.has(Y))Q.set(Y,q);return Q}function I4($,J){if(!$||$.length===0)return!1;return $.every((Q)=>J.has(Q))}function a0($,J,Q,Y,q){let G=[],X=$.filter((B)=>B.source!=="remote"||q&&q.has(B.id)),H=X.filter((B)=>B.filePath===u$),_=X.filter((B)=>!B.filePath),W=X.filter((B)=>B.filePath&&B.filePath!==u$),U=Q?Array.from(Q.values()).filter((B)=>E2(B)):[],K=Y?Array.from(Y.values()).filter((B)=>B.markdown.trim()):[];if(U.length>0||K.length>0){G.push("## Responses"),G.push("");for(let B of U)G.push(V9(B));for(let B of K)G.push(B.markdown.trim()),G.push("")}if(H.length>0){G.push("## Annotations on agent response"),G.push("");for(let B of H)G.push(o0(B))}if(_.length>0){G.push("## Canvas annotations"),G.push("");let B=new Map;for(let M of _){let T=M.canvasFile||"";if(!B.has(T))B.set(T,[]);B.get(T).push(M)}let N=[...B.keys()].sort(),P=N.length>1||N.length===1&&N[0]!=="";for(let M of N){let T=B.get(M);if(P&&M)G.push(`### ${M.replace(/\.jsx$/,"")}`),G.push("");let O=Z9(T);G.push(d3(O))}}if(W.length>0){let B={};for(let N of W){let P=N.filePath;if(!B[P])B[P]=[];B[P].push(N)}G.push("## File annotations"),G.push("");for(let[N,P]of Object.entries(B)){G.push(`### ${N}`),G.push("");for(let M of P)G.push(o0(M))}}if(J.trim())G.push("## General notes"),G.push(""),G.push(J.trim()),G.push("");return G.join(`
5
+ > `)}`);else{let _=J.split(`
6
+ `);Q.push(`> ${_[0]}`),Q.push(`> ... (${_.length} lines)`),Q.push(`> ${_[_.length-1]}`)}}if($.note.trim())Q.push(""),Q.push($.note.trim());let G=[...$.images??[]],X=new Set(G);for(let W of $.attachments??[]){if(X.has(W.url))continue;X.add(W.url),G.push(W.url)}if(G.length){Q.push("");for(let W of G)Q.push(`![screenshot](${W})`)}return Q.push(""),Q.join(`
7
+ `)}import{SessionContext as h9,useAnnotationHost as u9}from"@fabrika/annotations/runtime";import{useCallback as v2,useContext as p9,useEffect as c9,useMemo as a3,useRef as g2,useState as P0}from"react";import{createPortal as l9}from"react-dom";function i3($){let Q=/^(\d+(?:\.\d+)?)px$/.exec($.trim());return Q?Number(Q[1]):void 0}function o3($,Q,J=280){let q=Q||document.body,G=$.getBoundingClientRect(),X=q.getBoundingClientRect(),W=q===document.body?0:q.scrollTop,_=G.bottom-X.top+W+8,H=Math.max(0,Math.min(G.left-X.left,X.width-J-12));return q.style.position="relative",{style:{position:"absolute",top:`${_}px`,left:`${H}px`},parent:q}}import{jsxDEV as b$,Fragment as d9}from"react/jsx-dev-runtime";function s3({anchorEl:$,scrollContainer:Q,onClose:J,ignoreSelector:Y,zIndex:q="50",padding:G="12px",width:X="280px",children:W}){let _=g2(null),H=g2(J);H.current=J;let{style:U,parent:K}=o3($,Q,i3(X));return c9(()=>{let N=setTimeout(()=>{let O=(M)=>{if(_.current&&!_.current.contains(M.target)){if(Y&&M.target.closest?.(Y))return;H.current(),document.removeEventListener("mousedown",O)}};return document.addEventListener("mousedown",O),()=>document.removeEventListener("mousedown",O)},0);return()=>clearTimeout(N)},[Y]),l9(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:W},void 0,!1,void 0,this),K)}var t3=[{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"]}],n3=t3.flatMap(($)=>$.items);function R4({anchorEl:$,scrollContainer:Q,snippet:J,truncateAt:Y=100,header:q,initialNote:G="",initialImages:X,onConfirm:W,onCancel:_,onDelete:H}){let U=p9(h9),K=u9(),N=n0(K),O=G!==""||!!H,[M,L]=P0(G),[F,w]=P0(X||[]),[z,A]=P0(null),[T,S]=P0(O),[j,Z]=P0(!1),y=g2(null),V=g2(null),C=v2(()=>{if(M.trim()||F.length>0)W(M.trim(),F);else if(O&&H)H();else _()},[M,F,W,_,O,H]),v=v2(()=>{if(O){if(!M.trim()&&F.length===0&&H){H(),_();return}W(M,F);return}_()},[M,F,O,W,_,H]),h=!O,o=M.trim().length>0?n3.filter((D)=>D.toLowerCase().startsWith(M.trim().toLowerCase())):n3,B$=!h||T?[]:o.length===1&&o[0]?.toLowerCase()===M.trim().toLowerCase()?[]:o,a=new Set(B$),U$=t3.map((D)=>({label:D.label,items:D.items.filter((x)=>a.has(x))})).filter((D)=>D.items.length>0),Y$=U$.map((D)=>D.items),N$=(D)=>Y$[D]?.length??0,Q$=Y$.flat(),_$=a3(()=>{if(z===null)return 0;let D=0;for(let x=0;x<Y$.length;x++){if(z<D+N$(x))return x;D+=N$(x)}return 0},[z,Y$]),F$=a3(()=>{if(z===null)return 0;let D=0;for(let x=0;x<_$;x++)D+=N$(x);return z-D},[z,_$,Y$]),n=(D,x)=>{let r=0;for(let z$=0;z$<D;z$++)r+=N$(z$);return r+x},[d,X$]=P0(M);if(M!==d)X$(M),A(null),S(O);let g=v2((D)=>{L(D)},[]),c=J.length>Y?J.slice(0,Y)+"...":J,f=v2((D)=>{if(Q$.length>0&&(D.key==="ArrowDown"||D.key==="ArrowUp"||D.key==="ArrowLeft"||D.key==="ArrowRight")){if(D.preventDefault(),z===null){A(0);return}if(D.key==="ArrowDown"){let r=Math.min(F$+1,N$(_$)-1);A(n(_$,r))}else if(D.key==="ArrowUp"){let r=Math.max(F$-1,0);A(n(_$,r))}else if(D.key==="ArrowRight"){let r=Math.min(_$+1,Y$.length-1),z$=Math.min(F$,N$(r)-1);A(n(r,z$))}else if(D.key==="ArrowLeft"){let r=Math.max(_$-1,0),z$=Math.min(F$,N$(r)-1);A(n(r,z$))}return}let x=z===null?void 0:Q$[z];if(x!==void 0){if(D.key==="Tab"){D.preventDefault(),g(x);return}if(D.key==="Enter"&&!D.shiftKey){D.preventDefault(),W(x,F);return}}if(D.key==="Enter"&&!D.shiftKey){D.preventDefault(),C();return}if(D.key==="Escape")if(Q$.length>0&&!T)S(!0);else if(O)v();else _()},[Q$,z,F$,_$,Y$,n,g,W,F,C,T,O,v,_]);return b$(s3,{anchorEl:$,scrollContainer:Q,onClose:O?v:_,ignoreSelector:O?"[data-annotation-id]":void 0,zIndex:O?"60":"50",padding:O?"10px 12px":"12px",width:"420px",children:[!O&&(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:["“",c,"”"]},void 0,!0,void 0,this)),b$(s0,{note:M,onNoteChange:L,images:F,onAddImage:(D)=>w((x)=>[...x,D]),onRemoveImage:(D)=>w((x)=>x.filter((r)=>r!==D)),sessionId:U,autoFocus:!0,autoResize:O,textareaRef:y,onKeyDown:f,attachButton:"none",openFilePickerRef:V,textareaStyle:O?{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:O?"6px":"8px"},children:[N&&b$(f2,{onClick:()=>V.current?.(),size:14},void 0,!1,void 0,this),b$("div",{style:{flex:1}},void 0,!1,void 0,this),O?b$("button",{onClick:()=>{if(H)H();_()},onMouseEnter:()=>Z(!0),onMouseLeave:()=>Z(!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$(d9,{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:C,style:{fontSize:"11px",fontWeight:500,padding:"4px 12px",borderRadius:"6px",background:"var(--color-highlight-bg)",color:"var(--color-text-primary)",border:"1px solid var(--color-highlight-border)",cursor:"pointer",fontFamily:"'Inter', sans-serif"},children:"Add"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),Q$.length>0&&b$("div",{style:{marginTop:"6px",borderTop:"1px solid var(--color-border-subtle)",paddingTop:"8px",display:"flex",gap:"4px"},children:U$.map((D)=>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:D.label},void 0,!1,void 0,this),D.items.map((x)=>{let r=Q$.indexOf(x);return b$("div",{onMouseDown:(z$)=>{z$.preventDefault(),z$.stopPropagation(),g(x)},onMouseEnter:()=>A(r),style:{padding:"3px 6px",fontSize:"12px",borderRadius:"4px",fontFamily:"'Inter', sans-serif",color:r===z?"var(--color-text-primary)":"var(--color-text-secondary)",background:r===z?"var(--color-highlight-selected)":"transparent",cursor:"pointer"},children:[b$("span",{style:{fontWeight:500},children:x.slice(0,M.trim().length)},void 0,!1,void 0,this),x.slice(M.trim().length)]},x,!0,void 0,this)})]},D.label,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Q1({anchorEl:$,scrollContainer:Q,snippet:J,truncateAt:Y,header:q,onAdd:G,onCancel:X}){return b$(R4,{anchorEl:$,scrollContainer:Q,snippet:J,truncateAt:Y,header:q,onConfirm:(W,_)=>G(W,_),onCancel:X},void 0,!1,void 0,this)}function r1({anchorEl:$,scrollContainer:Q,initialNote:J,initialImages:Y,onUpdate:q,onDelete:G,onClose:X}){return b$(R4,{anchorEl:$,scrollContainer:Q,snippet:"",initialNote:J,initialImages:Y,onConfirm:(W,_)=>{q(W,_),X()},onDelete:G,onCancel:X},void 0,!1,void 0,this)}import{useEffect as r9,useRef as D4,useState as e3}from"react";import{jsxDEV as i9}from"react/jsx-dev-runtime";function I4($){let{containerRef:Q,restoreKey:J,shape:Y="rect",canvasFile:q,scrollContainer:G}=$,{addAnnotationWithId:X}=C1(),[W,_]=e3(null),[H,U]=e3(!1),K=D4(X);K.current=X;let N=D4(q);N.current=q;let O=D4(Y);return O.current=Y,r9(()=>{let L=Q.current;if(!L)return;let F=null;function w(Z,y){let V=Z.getBoundingClientRect();return N4(V,y.clientX-V.left,y.clientY-V.top)}function z(){if(!F)return;let{host:Z,pointerId:y}=F;if(Z.hasPointerCapture(y))Z.releasePointerCapture(y);Z.removeEventListener("pointermove",T),Z.removeEventListener("pointerup",S),Z.removeEventListener("pointercancel",j),F=null,U(!1)}function A(Z){if(F||Z.button!==0)return;let y=Z.target;if(!(y instanceof Element))return;if(y.closest("[data-block-comment-btn]"))return;if(y.closest("[data-annotation-id]"))return;let V=y.closest(`[${B4}]`);if(!(V instanceof HTMLElement)||!L?.contains(V))return;let C=V.closest("[data-md='image']")?.getAttribute("data-md-src");if(!C)return;let v=w(V,Z);if(!v)return;Z.preventDefault(),V.setPointerCapture(Z.pointerId);let h=x$(),o=Z2({...v,w:0,h:0},O.current,h);o.classList.add("ann-region-draft"),V.appendChild(o),F={pointerId:Z.pointerId,host:V,src:C,start:v,shape:O.current,overlay:o,id:h},V.addEventListener("pointermove",T),V.addEventListener("pointerup",S),V.addEventListener("pointercancel",j),U(!0)}function T(Z){if(!F||F.pointerId!==Z.pointerId)return;let y=w(F.host,Z);if(!y)return;b2(F.overlay,T2(F.start,y))}function S(Z){if(!F||F.pointerId!==Z.pointerId)return;let{overlay:y,id:V,src:C,shape:v}=F,h=w(F.host,Z)??F.start,o=T2(F.start,h);if(z(),!O4(o)){y.remove();return}b2(y,o);let B$={src:C,shape:v,...o};_({overlay:y,id:V,snippet:u0.format(B$),label:j2(B$)})}function j(Z){if(!F||F.pointerId!==Z.pointerId)return;F.overlay.remove(),z()}return L.addEventListener("pointerdown",A),()=>{if(L.removeEventListener("pointerdown",A),F)F.overlay.remove(),z()}},[J]),{popovers:W?i9(Q1,{anchorEl:W.overlay,scrollContainer:G,snippet:W.label,truncateAt:80,onAdd:(L,F)=>{W.overlay.classList.remove("ann-region-draft"),K.current(W.id,W.snippet,L,void 0,void 0,F,N.current),_(null)},onCancel:()=>{W.overlay.remove(),_(null)}},void 0,!1,void 0,this):null,isDrawing:H,isPopoverOpen:!!W}}import{useCallback as $5,useEffect as m2,useRef as i1,useState as Q5}from"react";import{jsxDEV as k4,Fragment as o9}from"react/jsx-dev-runtime";function R1($){let{containerRef:Q,restoreKey:J,restoreAnnotations:Y,extractContext:q,filePath:G,canvasFile:X,scrollContainer:W}=$,{annotations:_,addAnnotationWithId:H,removeAnnotation:U,updateAnnotation:K,addAnnotationImage:N,removeAnnotationImage:O,activeAnnotationId:M,setActiveAnnotationId:L}=C1(),[F,w]=Q5(null),[z,A]=Q5(null),T=i1(q);T.current=q;let S=i1(G);S.current=G;let j=i1(X);j.current=X;let Z=i1(H);Z.current=H;let y=i1(M);y.current=M;let V=i1(L);V.current=L;let C=Y.length;m2(()=>{if(!Q.current)return;let a=setTimeout(()=>{if(Q.current)F4(Q.current,Y)},50);return()=>clearTimeout(a)},[J,C]);let v=i1(null);m2(()=>{v0(M,v.current),v.current=M},[M]),m2(()=>{let a=Q.current;if(!a)return;let U$=(Q$)=>{let _$=Q$.target.closest("[data-annotation-id]");if(!_$)return;Q$.stopPropagation();let F$=_$.getAttribute("data-annotation-id");if(F$===y.current)w({anchorEl:_$,annId:F$});else V.current(F$)},Y$=(Q$)=>{let _$=Q$.target.closest("[data-annotation-id]");if(_$)V.current(_$.getAttribute("data-annotation-id"))},N$=(Q$)=>{let _$=Q$.target.closest("[data-annotation-id]"),F$=Q$.relatedTarget?.closest?.("[data-annotation-id]");if(_$&&!F$&&!document.getElementById("ann-inline-popover"))V.current(null)};return a.addEventListener("click",U$),a.addEventListener("mouseover",Y$),a.addEventListener("mouseout",N$),()=>{a.removeEventListener("click",U$),a.removeEventListener("mouseover",Y$),a.removeEventListener("mouseout",N$)}},[J]),m2(()=>{let a=()=>h();return document.addEventListener("mouseup",a),()=>document.removeEventListener("mouseup",a)},[]);let h=$5(()=>{let a=window.getSelection();if(!a||a.isCollapsed||!a.toString().trim())return;if(!Q.current)return;let U$=a.getRangeAt(0);if(!Q.current.contains(U$.startContainer))return;if(U$.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let Y$=b3(U$).trim();if(Y$.length<2)return;let N$=T.current(U$),Q$=U$.cloneRange(),_$=`__pending_${Date.now()}`;try{A1(Q$,_$)}catch{}window.getSelection()?.removeAllRanges();let F$=document.querySelectorAll(`[data-annotation-id="${_$}"]`),n=F$[F$.length-1];if(!n)return;A({anchorEl:n,tempId:_$,snippet:Y$,ctx:N$})},[]),o=$5((a,U$,Y$,N$)=>{A({anchorEl:a,tempId:U$,snippet:Y$,ctx:N$})},[]);return{popovers:k4(o9,{children:[F&&(()=>{let a=_.find((U$)=>U$.id===F.annId);if(!a)return null;return k4(r1,{anchorEl:F.anchorEl,scrollContainer:W,initialNote:a.note,initialImages:a.images,onUpdate:(U$,Y$)=>{K(F.annId,U$);let N$=a.images||[];for(let Q$ of Y$)if(!N$.includes(Q$))N(F.annId,Q$);for(let Q$ of N$)if(!Y$.includes(Q$))O(F.annId,Q$)},onDelete:()=>{U(F.annId),L(null)},onClose:()=>w(null)},void 0,!1,void 0,this)})(),z&&k4(Q1,{anchorEl:z.anchorEl,scrollContainer:W,snippet:z.snippet,truncateAt:80,onAdd:(a,U$)=>{let Y$=x$();g0(z.tempId,Y$),Z.current(Y$,z.snippet,a,S.current,z.ctx,U$,j.current),A(null)},onCancel:()=>{x0(z.tempId),A(null)}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),openCreatePopover:o,isPopoverOpen:!!(F||z)}}import{AnnotationCtx as YQ}from"#canvas/runtime";import{AnnotationCtx as XQ,AnnotationHostContext as GQ}from"@fabrika/annotations/runtime";import{useCallback as T0,useEffect as B5,useMemo as _Q,useRef as g4,useState as j0}from"react";var a9=B.object({}).passthrough(),n9=B.object({annotations:B.array(B.unknown()).catch([]),generalNote:B.string().catch(""),responses:B.array(B.unknown()).catch([])}),s9=B.tuple([B.unknown(),B.object({note:B.unknown(),value:B.unknown()})]);function J1($,Q,J="current"){let Y=`canvas:${$}:rev:${Q}`;return J==="next"?`${Y}:next-draft`:Y}function S0($,Q){return`${J1($,Q)}:draft-handled`}function o1($,Q,J){try{$.removeItem(J1(Q,J)),$.removeItem(S0(Q,J))}catch{}}function y4($){if(!$)return null;try{let Q=JSON.parse($),J=a9.safeParse(Q);return J.success?J.data:null}catch{return null}}function t9($){let Q=s9.safeParse($);if(!Q.success)return!1;let{note:J,value:Y}=Q.data[1];if(typeof J==="string"&&J.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 f4($){if(!$)return!1;let{annotations:Q,generalNote:J,responses:Y}=n9.parse($);return Q.length>0||J.trim().length>0||Y.some(t9)}function x2($,Q,J,Y){try{let q=J1(Q,J);if(f4(y4($.getItem(q))))return $.setItem(S0(Q,J),"1"),null;if($.getItem(S0(Q,J))!==null)return null;let G=Y.filter((X)=>X.revision<J).sort((X,W)=>W.revision-X.revision);for(let X of G){if(X.hasFeedback){let _=J1(Q,X.revision,"next"),H=y4($.getItem(_));if(!f4(H))return null;return $.setItem(q,JSON.stringify({...H,feedbackEntries:[]})),$.setItem(S0(Q,J),"1"),$.removeItem(_),X.revision}let W=y4($.getItem(J1(Q,X.revision)));if(!f4(W)){if($.getItem(S0(Q,X.revision))!==null)return null;continue}return $.setItem(q,JSON.stringify({...W,feedbackEntries:[]})),$.setItem(S0(Q,J),"1"),X.revision}}catch{}return null}function E4($,Q){let J=new Map;for(let[Y,q]of $)if(Q.has(Y))J.set(Y,q);return J}function v4($,Q){if(!$||$.length===0)return!1;return $.every((J)=>Q.has(J))}function e9($,Q){return $.filter((J)=>J.source!=="remote"||Q&&Q.has(J.id))}function e0($,Q,J,Y,q,G={}){let X=[],W=e9($,q),_=(L)=>G.annotationIds&&L.source!=="remote"?`Annotation \`${L.id}\`
8
+ ${E2(L)}`:E2(L),H=W.filter((L)=>L.filePath===g$),U=W.filter((L)=>!L.filePath),K=W.filter((L)=>L.filePath&&L.filePath!==g$),N=J?Array.from(J.values()).filter((L)=>$2(L)):[],O=Y?Array.from(Y.values()).filter((L)=>L.markdown.trim()):[];if(N.length>0||O.length>0){X.push("## Responses"),X.push("");for(let L of N)X.push($Q(L));for(let L of O)X.push(L.markdown.trim()),X.push("")}if(H.length>0){X.push("## Annotations on agent response"),X.push("");for(let L of H)X.push(_(L))}if(U.length>0){X.push("## Canvas annotations"),X.push("");let L=new Map;for(let z of U){let A=z.canvasFile||"";if(!L.has(A))L.set(A,[]);L.get(A).push(z)}let F=[...L.keys()].sort(),w=F.length>1||F.length===1&&F[0]!=="";for(let z of F){let A=L.get(z);if(w&&z)X.push(`### ${z.replace(/\.jsx$/,"")}`),X.push("");let T=QQ(A);X.push(X5(T,_))}}if(K.length>0){let L={};for(let F of K){let w=F.filePath;if(!L[w])L[w]=[];L[w].push(F)}X.push("## File annotations"),X.push("");for(let[F,w]of Object.entries(L)){X.push(`### ${F}`),X.push("");for(let z of w)X.push(_(z))}}if(Q.trim())X.push("## General notes"),X.push(""),X.push(Q.trim()),X.push("");return X.join(`
8
9
  `).trim()+`
9
- `}function E2($){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 c3($){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 l3($){let J=[];for(let Q of $.values())if(Q.required&&!Q.markdown.trim())J.push(Q);return J}function n0($,J){let Q=c3($),Y=l3(J);return[...Q.map((q)=>q.label),...Y.map((q)=>q.label||q.id)]}function V9($){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 Z9($){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 d3($,J=0){let Q=[];for(let Y of $.annotations)Q.push(o0(Y));for(let[,Y]of $.children){let q=J===0?"###":"####";Q.push(`${q} ${Y.label}`),Q.push(""),Q.push(d3(Y,J+1))}return Q.join(`
11
- `)}import{createContext as C9,useContext as R9}from"react";function r3(){if(typeof window>"u")return"";return window.location.pathname.replace("/s/","")}var i3={get sessionId(){return r3()},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/${r3()}/canvas/${encodeURIComponent(Q)}${Y}`)}},f2=C9(i3);function K1(){return R9(f2)}var o3=L.object({id:L.string(),type:L.enum(["select","radio","checkbox","text","range"]),label:L.string(),value:L.unknown(),options:L.array(L.string()).optional(),required:L.boolean().optional(),note:L.string().optional()}).passthrough().transform(($)=>({...$,value:$.value})),a3=L.object({id:L.string(),markdown:L.string(),label:L.string().optional(),required:L.boolean().optional()}).passthrough(),n3=L4.extend({responses:L.array(L.tuple([L.string(),o3]).optional().catch(void 0)).transform(($)=>$.filter((J)=>J!==void 0)).catch([]),feedbackEntries:L.array(L.tuple([L.string(),a3]).optional().catch(void 0)).transform(($)=>$.filter((J)=>J!==void 0)).optional().catch([])});function S0($){let J=n3.safeParse($);return J.success?J.data:null}var s3=L.object({feedback:L.string().nullish()}),R1=L.union([L.object({error:L.string().min(1)}),L.object({content:L.string(),language:L.string().nullish()})]);import{useAnnotations as i1}from"#canvas/runtime";import{jsxDEV as y4}from"react/jsx-dev-runtime";function e3($,J,Q){try{let Y=localStorage.getItem($1($,J,Q));if(!Y)return null;return S0(JSON.parse(Y))}catch{return null}}function E9($,J,Q,Y){try{localStorage.setItem($1($,J,Q),JSON.stringify(Y))}catch{}}function k4($){return{draft:$,responseIds:new Set,canvases:new Set}}function E4({sessionId:$,revision:J,isReadOnly:Q,draftPhase:Y,remoteAnnotations:q,canvasFiles:G,loadState:X,saveState:H,children:_}){let W=!!X,U=W?null:e3($,J,Y),K=D4(U),[z,B]=w0(()=>(U?.annotations??[]).map((n)=>({...n,source:n.source??"local"}))),[N,P]=w0(()=>U?.generalNote??""),[M,T]=w0(()=>U?.responses?new Map(U.responses):new Map),O=`${$}:${J}:${Y}`,A=D4(O);A.current=O;let[w,S]=w0(()=>k4(O)),[j,C]=w0(()=>U?.feedbackEntries?new Map(U.feedbackEntries):new Map),[y,I]=w0(!W);t3(()=>{let n=(d)=>{K.current=d,B((d?.annotations??[]).map((Y$)=>({...Y$,source:Y$.source??"local"}))),P(d?.generalNote??""),T(d?.responses?new Map(d.responses):new Map),C(d?.feedbackEntries?new Map(d.feedbackEntries):new Map),_$(null)};if(W){let d=!1;return I(!1),X($,J,Y).then((Y$)=>{if(d)return;n(S0(Y$)),I(!0)}),()=>{d=!0}}n(e3($,J,Y)),I(!0);return},[$,J,Y,W,X]);let V=D4(null);t3(()=>{if(Q&&Y!=="next")return;if(!y)return;if(V.current)clearTimeout(V.current);let n={...K.current,annotations:z,generalNote:N,responses:Array.from(M.entries()),feedbackEntries:Array.from(j.entries())},d=()=>{if(H)H($,J,n,Y);else E9($,J,Y,n)};if(Y==="next"){d();return}return V.current=setTimeout(d,300),()=>{if(V.current)clearTimeout(V.current)}},[z,N,M,j,$,J,Q,Y,y,H]);let f=P0((n,d)=>{T((Y$)=>{let v=new Map(Y$);return v.set(n,d),v})},[]),h=P0((n)=>{S((d)=>{let Y$=d.draft===A.current?d:k4(A.current);if(Y$.responseIds.has(n))return Y$;return{...Y$,responseIds:new Set(Y$.responseIds).add(n)}})},[]),o=P0((n)=>{S((d)=>{let Y$=d.draft===A.current?d:k4(A.current);if(Y$.canvases.has(n))return Y$;return{...Y$,canvases:new Set(Y$.canvases).add(n)}})},[]),B$=w.draft===O?w:null,a=y9(()=>{if(!B$||!I4(G,B$.canvases))return M;return R4(M,B$.responseIds)},[B$,G,M]),U$=P0((n,d)=>{C((Y$)=>{let v=Y$.get(n);if(v&&v.markdown===d.markdown&&v.label===d.label&&v.required===d.required)return Y$;let c=new Map(Y$);return c.set(n,d),c})},[]),q$=P0((n)=>{C((d)=>{if(!d.has(n))return d;let Y$=new Map(d);return Y$.delete(n),Y$})},[]),z$=P0(()=>{if(T(new Map),C(new Map),H)H($,J,{annotations:[],generalNote:"",responses:[],feedbackEntries:[]},Y);else if(Y==="next")localStorage.removeItem($1($,J,Y));else r1(localStorage,$,J)},[$,J,Y,H]),J$=Z2({annotations:z,setAnnotations:B,generalNote:N,setGeneralNote:P,remoteAnnotations:q,isReadOnly:Q,onClear:z$}),{setActiveAnnotationId:_$}=J$,L$=K1();return y4(k9.Provider,{value:L$,children:y4(D9.Provider,{value:J$,children:y4(I9.Provider,{value:{...J$,responses:M,setResponse:f,submittableResponses:a,registerResponse:h,registerCanvasRendered:o,feedbackEntries:j,setFeedbackEntry:U$,removeFeedbackEntry:q$},children:_},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}import{ActiveViewCtx as OW,AnnotationCtx as LW,CanvasFileCtx as FW,SessionContext as AW,useAnnotations as Y1,useCanvasFile as SW,useFeedback as PW,useResponseRegistration as wW}from"#canvas/runtime";function s0($){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 U4($.snippet,Q)}function $5($){$.classList.remove("ann-flash"),$.offsetWidth,$.classList.add("ann-flash"),$.addEventListener("animationend",()=>{$.classList.remove("ann-flash")},{once:!0})}function f4($,J){let Q=u1($);if(Q)J({type:"file",path:Q}),setTimeout(()=>{let Y=s0($);if(Y)Y.scrollIntoView({behavior:"smooth",block:"center"}),$5(Y)},150);else{let Y=s0($);if(Y)Y.scrollIntoView({behavior:"smooth",block:"center"}),$5(Y)}}import{SessionContext as ZJ}from"#canvas/runtime";import{useCallback as o4,useContext as a4,useEffect as S5,useMemo as CJ,useState as j0}from"react";import{createContext as J5}from"react";var J1=J5({activeView:{type:"overview"},setActiveView:()=>{},openFiles:[],closeFile:()=>{},canvasFiles:[]}),f$=J5({currentRevision:1,selectedRevision:1,revisions:[],setSelectedRevision:()=>{},isReadOnly:!1,compareRevision:null,setCompareRevision:()=>{},agentWatching:!1});import{jsxDEV as o1}from"react/jsx-dev-runtime";var f9={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"},v9={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 I1({name:$,type:J,expanded:Q,className:Y=""}){if(J==="dir")return o1("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",className:`flex-shrink-0 ${Y}`,children:Q?o1("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):o1("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=f9[q]||"#6b6560",X=v9[q];return o1("svg",{width:"14",height:"14",viewBox:"0 0 16 16",className:`flex-shrink-0 ${Y}`,children:[o1("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),o1("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&&o1("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 g4(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var s1=g4();function H5($){s1=$}var a1={exec:()=>null};function W$($,J=""){let Q=typeof $=="string"?$:$.source,Y={replace:(q,G)=>{let X=typeof G=="string"?G:G.source;return X=X.replace(D$.caret,"$1"),Q=Q.replace(q,X),Y},getRegex:()=>new RegExp(Q,J)};return Y}var g9=(()=>{try{return!!new RegExp("(?<=1)(?<!1)")}catch{return!1}})(),D$={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)}}>`)},m9=/^(?:[ \t]*(?:\n|$))+/,x9=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,h9=/^ {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+|$)/,u9=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,m4=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,W5=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,U5=W$(W5).replace(/bull/g,m4).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(),p9=W$(W5).replace(/bull/g,m4).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(),x4=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,c9=/^[^\n]+/,h4=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,l9=W$(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",h4).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),d9=W$(/^(bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,m4).getRegex(),h2="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",u4=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,r9=W$("^ {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",u4).replace("tag",h2).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),K5=W$(x4).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",h2).getRegex(),i9=W$(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",K5).getRegex(),p4={blockquote:i9,code:x9,def:l9,fences:h9,heading:u9,hr:J2,html:r9,lheading:U5,list:d9,newline:m9,paragraph:K5,table:a1,text:c9},Q5=W$("^ *([^\\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",h2).getRegex(),o9={...p4,lheading:p9,table:Q5,paragraph:W$(x4).replace("hr",J2).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",Q5).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",h2).getRegex()},a9={...p4,html:W$(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",u4).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:a1,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:W$(x4).replace("hr",J2).replace("heading",` *#{1,6} *[^
12
- ]`).replace("lheading",U5).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},n9=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,s9=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,B5=/^( {2,}|\\)\n(?!\s*$)/,t9=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,T0=/[\p{P}\p{S}]/u,u2=/[\s\p{P}\p{S}]/u,c4=/[^\s\p{P}\p{S}]/u,e9=W$(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,u2).getRegex(),z5=/(?!~)[\p{P}\p{S}]/u,$J=/(?!~)[\s\p{P}\p{S}]/u,JJ=/(?:[^\s\p{P}\p{S}]|~)/u,QJ=W$(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",g9?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),N5=/^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/,qJ=W$(N5,"u").replace(/punct/g,T0).getRegex(),YJ=W$(N5,"u").replace(/punct/g,z5).getRegex(),M5="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",XJ=W$(M5,"gu").replace(/notPunctSpace/g,c4).replace(/punctSpace/g,u2).replace(/punct/g,T0).getRegex(),GJ=W$(M5,"gu").replace(/notPunctSpace/g,JJ).replace(/punctSpace/g,$J).replace(/punct/g,z5).getRegex(),_J=W$("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,c4).replace(/punctSpace/g,u2).replace(/punct/g,T0).getRegex(),HJ=W$(/^~~?(?:((?!~)punct)|[^\s~])/,"u").replace(/punct/g,T0).getRegex(),WJ="^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)",UJ=W$(WJ,"gu").replace(/notPunctSpace/g,c4).replace(/punctSpace/g,u2).replace(/punct/g,T0).getRegex(),KJ=W$(/\\(punct)/,"gu").replace(/punct/g,T0).getRegex(),BJ=W$(/^<(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(),zJ=W$(u4).replace("(?:-->|$)","-->").getRegex(),NJ=W$("^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",zJ).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),g2=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/,MJ=W$(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace("label",g2).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),O5=W$(/^!?\[(label)\]\[(ref)\]/).replace("label",g2).replace("ref",h4).getRegex(),L5=W$(/^!?\[(ref)\](?:\[\])?/).replace("ref",h4).getRegex(),OJ=W$("reflink|nolink(?!\\()","g").replace("reflink",O5).replace("nolink",L5).getRegex(),q5=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,l4={_backpedal:a1,anyPunctuation:KJ,autolink:BJ,blockSkip:QJ,br:B5,code:s9,del:a1,delLDelim:a1,delRDelim:a1,emStrongLDelim:qJ,emStrongRDelimAst:XJ,emStrongRDelimUnd:_J,escape:n9,link:MJ,nolink:L5,punctuation:e9,reflink:O5,reflinkSearch:OJ,tag:NJ,text:t9,url:a1},LJ={...l4,link:W$(/^!?\[(label)\]\((.*?)\)/).replace("label",g2).getRegex(),reflink:W$(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",g2).getRegex()},v4={...l4,emStrongRDelimAst:GJ,emStrongLDelim:YJ,delLDelim:HJ,delRDelim:UJ,url:W$(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol",q5).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:W$(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace("protocol",q5).getRegex()},FJ={...v4,br:W$(B5).replace("{2,}","*").getRegex(),text:W$(v4.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},v2={normal:p4,gfm:o9,pedantic:a9},t0={normal:l4,gfm:v4,breaks:FJ,pedantic:LJ},AJ={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},Y5=($)=>AJ[$];function Q1($,J){if(J){if(D$.escapeTest.test($))return $.replace(D$.escapeReplace,Y5)}else if(D$.escapeTestNoEncode.test($))return $.replace(D$.escapeReplaceNoEncode,Y5);return $}function X5($){try{$=encodeURI($).replace(D$.percentDecode,"%")}catch{return null}return $}function G5($,J){let Q=$.replace(D$.findPipe,(G,X,H)=>{let _=!1,W=X;for(;--W>=0&&H[W]==="\\";)_=!_;return _?"|":" |"}),Y=Q.split(D$.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(D$.slashPipe,"|");return Y}function e0($,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 SJ($,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 PJ($,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 _5($,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 wJ($,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 m2=class{options;rules;lexer;constructor($){this.options=$||s1}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:e0(Q,`
15
- `)}}}fences($){let J=this.rules.block.fences.exec($);if(J){let Q=J[0],Y=wJ(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=e0(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:e0(J[0],`
16
- `)}}blockquote($){let J=this.rules.block.blockquote.exec($);if(J){let Q=e0(J[0],`
10
+ `}function J5($){return Array.from($.values()).filter($2).map(({id:Q,value:J})=>({id:Q,value:J}))}function $2($){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 q5($){let Q=[];for(let J of $.values()){if(!J.required)continue;if(J.value===null||J.value===void 0){Q.push(J);continue}if(J.type==="text"&&!J.value.trim()){Q.push(J);continue}if(J.type==="checkbox"&&J.value.length===0){Q.push(J);continue}}return Q}function Y5($){let Q=[];for(let J of $.values())if(J.required&&!J.markdown.trim())Q.push(J);return Q}function Q2($,Q){let J=q5($),Y=Y5(Q);return[...J.map((q)=>q.label),...Y.map((q)=>q.label||q.id)]}function $Q($){let Q=[];switch(Q.push(`**${$.label}**`),$.type){case"radio":case"select":Q.push(`Answer: ${$.value}`);break;case"checkbox":for(let J of $.value)Q.push(`- [x] ${J}`);break;case"text":Q.push(""),Q.push($.value.trim());break;case"range":Q.push(`Answer: ${$.value}`);break}if($.note?.trim())Q.push(""),Q.push(`Note: ${$.note.trim()}`);return Q.push(""),Q.join(`
11
+ `)}function QQ($){let Q={label:"",annotations:[],children:new Map};for(let J of $){let Y=J.context?.hierarchy||[],q=Q;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(J)}return Q}function X5($,Q,J=0){let Y=[];for(let q of $.annotations)Y.push(Q(q));for(let[,q]of $.children){let G=J===0?"###":"####";Y.push(`${G} ${q.label}`),Y.push(""),Y.push(X5(q,Q,J+1))}return Y.join(`
12
+ `)}import{createContext as JQ,useContext as qQ}from"react";function G5(){if(typeof window>"u")return"";return window.location.pathname.replace("/s/","")}var _5={get sessionId(){return G5()},isShared:!1,fsAvailable:!0,uploadUrl:null,loadCanvasModule:($,Q)=>{let J=$.replace(/\.jsx$/,".js"),Y=Q?`?rev=${Q}&t=${Date.now()}`:`?t=${Date.now()}`;return import(`/api/session/${G5()}/canvas/${encodeURIComponent(J)}${Y}`)},threads:null},h2=JQ(_5);function v$(){return qQ(h2)}var W5=B.object({id:B.string(),type:B.enum(["select","radio","checkbox","text","range"]),label:B.string(),value:B.unknown(),options:B.array(B.string()).optional(),required:B.boolean().optional(),note:B.string().optional()}).passthrough().transform(($)=>({...$,value:$.value})),H5=B.object({id:B.string(),markdown:B.string(),label:B.string().optional(),required:B.boolean().optional()}).passthrough(),U5=T4.extend({responses:B.array(B.tuple([B.string(),W5]).optional().catch(void 0)).transform(($)=>$.filter((Q)=>Q!==void 0)).catch([]),feedbackEntries:B.array(B.tuple([B.string(),H5]).optional().catch(void 0)).transform(($)=>$.filter((Q)=>Q!==void 0)).optional().catch([])});function w0($){let Q=U5.safeParse($);return Q.success?Q.data:null}var K5=B.object({feedback:B.string().nullish()}),D1=B.union([B.object({error:B.string().min(1)}),B.object({content:B.string(),language:B.string().nullish()})]);import{useAnnotations as a1}from"#canvas/runtime";import{jsxDEV as x4}from"react/jsx-dev-runtime";function N5($,Q,J){try{let Y=localStorage.getItem(J1($,Q,J));if(!Y)return null;return w0(JSON.parse(Y))}catch{return null}}function WQ($,Q,J,Y){try{localStorage.setItem(J1($,Q,J),JSON.stringify(Y))}catch{}}function m4($){return{draft:$,responseIds:new Set,canvases:new Set}}function h4({sessionId:$,revision:Q,isReadOnly:J,draftPhase:Y,remoteAnnotations:q,canvasFiles:G,loadState:X,saveState:W,children:_}){let H=!!X,U=H?null:N5($,Q,Y),K=g4(U),[N,O]=j0(()=>(U?.annotations??[]).map((n)=>({...n,source:n.source??"local"}))),[M,L]=j0(()=>U?.generalNote??""),[F,w]=j0(()=>U?.responses?new Map(U.responses):new Map),z=`${$}:${Q}:${Y}`,A=g4(z);A.current=z;let[T,S]=j0(()=>m4(z)),[j,Z]=j0(()=>U?.feedbackEntries?new Map(U.feedbackEntries):new Map),[y,V]=j0(!H);B5(()=>{let n=(d)=>{K.current=d,O((d?.annotations??[]).map((X$)=>({...X$,source:X$.source??"local"}))),L(d?.generalNote??""),w(d?.responses?new Map(d.responses):new Map),Z(d?.feedbackEntries?new Map(d.feedbackEntries):new Map),_$(null)};if(H){let d=!1;return V(!1),X($,Q,Y).then((X$)=>{if(d)return;n(w0(X$)),V(!0)}),()=>{d=!0}}n(N5($,Q,Y)),V(!0);return},[$,Q,Y,H,X]);let C=g4(null);B5(()=>{if(J&&Y!=="next")return;if(!y)return;if(C.current)clearTimeout(C.current);let n={...K.current,annotations:N,generalNote:M,responses:Array.from(F.entries()),feedbackEntries:Array.from(j.entries())},d=()=>{if(W)W($,Q,n,Y);else WQ($,Q,Y,n)};if(Y==="next"){d();return}return C.current=setTimeout(d,300),()=>{if(C.current)clearTimeout(C.current)}},[N,M,F,j,$,Q,J,Y,y,W]);let v=T0((n,d)=>{w((X$)=>{let g=new Map(X$);return g.set(n,d),g})},[]),h=T0((n)=>{S((d)=>{let X$=d.draft===A.current?d:m4(A.current);if(X$.responseIds.has(n))return X$;return{...X$,responseIds:new Set(X$.responseIds).add(n)}})},[]),o=T0((n)=>{S((d)=>{let X$=d.draft===A.current?d:m4(A.current);if(X$.canvases.has(n))return X$;return{...X$,canvases:new Set(X$.canvases).add(n)}})},[]),B$=T.draft===z?T:null,a=_Q(()=>{if(!B$||!v4(G,B$.canvases))return F;return E4(F,B$.responseIds)},[B$,G,F]),U$=T0((n,d)=>{Z((X$)=>{let g=X$.get(n);if(g&&g.markdown===d.markdown&&g.label===d.label&&g.required===d.required)return X$;let c=new Map(X$);return c.set(n,d),c})},[]),Y$=T0((n)=>{Z((d)=>{if(!d.has(n))return d;let X$=new Map(d);return X$.delete(n),X$})},[]),N$=T0(()=>{if(w(new Map),Z(new Map),W)W($,Q,{annotations:[],generalNote:"",responses:[],feedbackEntries:[]},Y);else if(Y==="next")localStorage.removeItem(J1($,Q,Y));else o1(localStorage,$,Q)},[$,Q,Y,W]),Q$=k2({annotations:N,setAnnotations:O,generalNote:M,setGeneralNote:L,remoteAnnotations:q,isReadOnly:J,onClear:N$}),{setActiveAnnotationId:_$}=Q$,F$=v$();return x4(GQ.Provider,{value:F$,children:x4(XQ.Provider,{value:Q$,children:x4(YQ.Provider,{value:{...Q$,responses:F,setResponse:v,submittableResponses:a,registerResponse:h,registerCanvasRendered:o,feedbackEntries:j,setFeedbackEntry:U$,removeFeedbackEntry:Y$},children:_},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)}import{ActiveViewCtx as PU,AnnotationCtx as SU,CanvasFileCtx as wU,SessionContext as TU,useAnnotations as G1,useCanvasFile as jU,useFeedback as bU,useResponseRegistration as ZU}from"#canvas/runtime";function J2($){let Q=document.querySelector(`[data-annotation-id="${$.id}"]`);if(Q instanceof HTMLElement)return Q;let J=$.canvasFile?document.querySelector(`[data-canvas-file="${$.canvasFile}"]`):document;if(!J)return null;return M4($.snippet,J)}function O5($){$.classList.remove("ann-flash"),$.offsetWidth,$.classList.add("ann-flash"),$.addEventListener("animationend",()=>{$.classList.remove("ann-flash")},{once:!0})}function u4($,Q){let J=c1($);if(J)Q({type:"file",path:J}),setTimeout(()=>{let Y=J2($);if(Y)Y.scrollIntoView({behavior:"smooth",block:"center"}),O5(Y)},150);else{let Y=J2($);if(Y)Y.scrollIntoView({behavior:"smooth",block:"center"}),O5(Y)}}import{SessionContext as HJ}from"#canvas/runtime";import{useCallback as q3,useContext as Y3,useEffect as m5,useMemo as UJ,useState as C0}from"react";import{createContext as z5}from"react";var q1=z5({activeView:{type:"overview"},setActiveView:()=>{},openFiles:[],closeFile:()=>{},canvasFiles:[]}),h$=z5({currentRevision:1,selectedRevision:1,revisions:[],setSelectedRevision:()=>{},isReadOnly:!1,compareRevision:null,setCompareRevision:()=>{},agentWatching:!1});import{jsxDEV as n1}from"react/jsx-dev-runtime";var HQ={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"},UQ={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 I1({name:$,type:Q,expanded:J,className:Y=""}){if(Q==="dir")return n1("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none",className:`flex-shrink-0 ${Y}`,children:J?n1("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):n1("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=HQ[q]||"#6b6560",X=UQ[q];return n1("svg",{width:"14",height:"14",viewBox:"0 0 16 16",className:`flex-shrink-0 ${Y}`,children:[n1("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),n1("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&&n1("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 c4(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var e1=c4();function w5($){e1=$}var s1={exec:()=>null};function H$($,Q=""){let J=typeof $=="string"?$:$.source,Y={replace:(q,G)=>{let X=typeof G=="string"?G:G.source;return X=X.replace(k$.caret,"$1"),J=J.replace(q,X),Y},getRegex:()=>new RegExp(J,Q)};return Y}var KQ=(()=>{try{return!!new RegExp("(?<=1)(?<!1)")}catch{return!1}})(),k$={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)}}>`)},BQ=/^(?:[ \t]*(?:\n|$))+/,NQ=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,OQ=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,G2=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,zQ=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,l4=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,T5=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,j5=H$(T5).replace(/bull/g,l4).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(),MQ=H$(T5).replace(/bull/g,l4).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(),d4=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,FQ=/^[^\n]+/,r4=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,LQ=H$(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",r4).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),AQ=H$(/^(bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,l4).getRegex(),d2="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",i4=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,PQ=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",i4).replace("tag",d2).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),b5=H$(d4).replace("hr",G2).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",d2).getRegex(),SQ=H$(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",b5).getRegex(),o4={blockquote:SQ,code:NQ,def:LQ,fences:OQ,heading:zQ,hr:G2,html:PQ,lheading:j5,list:AQ,newline:BQ,paragraph:b5,table:s1,text:FQ},M5=H$("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",G2).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",d2).getRegex(),wQ={...o4,lheading:MQ,table:M5,paragraph:H$(d4).replace("hr",G2).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",M5).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",d2).getRegex()},TQ={...o4,html:H$(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",i4).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:s1,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:H$(d4).replace("hr",G2).replace("heading",` *#{1,6} *[^
13
+ ]`).replace("lheading",j5).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},jQ=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,bQ=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,Z5=/^( {2,}|\\)\n(?!\s*$)/,ZQ=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,b0=/[\p{P}\p{S}]/u,r2=/[\s\p{P}\p{S}]/u,a4=/[^\s\p{P}\p{S}]/u,VQ=H$(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,r2).getRegex(),V5=/(?!~)[\p{P}\p{S}]/u,CQ=/(?!~)[\s\p{P}\p{S}]/u,RQ=/(?:[^\s\p{P}\p{S}]|~)/u,DQ=H$(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",KQ?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),C5=/^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/,IQ=H$(C5,"u").replace(/punct/g,b0).getRegex(),kQ=H$(C5,"u").replace(/punct/g,V5).getRegex(),R5="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",yQ=H$(R5,"gu").replace(/notPunctSpace/g,a4).replace(/punctSpace/g,r2).replace(/punct/g,b0).getRegex(),fQ=H$(R5,"gu").replace(/notPunctSpace/g,RQ).replace(/punctSpace/g,CQ).replace(/punct/g,V5).getRegex(),EQ=H$("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,a4).replace(/punctSpace/g,r2).replace(/punct/g,b0).getRegex(),vQ=H$(/^~~?(?:((?!~)punct)|[^\s~])/,"u").replace(/punct/g,b0).getRegex(),gQ="^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)",mQ=H$(gQ,"gu").replace(/notPunctSpace/g,a4).replace(/punctSpace/g,r2).replace(/punct/g,b0).getRegex(),xQ=H$(/\\(punct)/,"gu").replace(/punct/g,b0).getRegex(),hQ=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(),uQ=H$(i4).replace("(?:-->|$)","-->").getRegex(),pQ=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",uQ).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),p2=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/,cQ=H$(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace("label",p2).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),D5=H$(/^!?\[(label)\]\[(ref)\]/).replace("label",p2).replace("ref",r4).getRegex(),I5=H$(/^!?\[(ref)\](?:\[\])?/).replace("ref",r4).getRegex(),lQ=H$("reflink|nolink(?!\\()","g").replace("reflink",D5).replace("nolink",I5).getRegex(),F5=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,n4={_backpedal:s1,anyPunctuation:xQ,autolink:hQ,blockSkip:DQ,br:Z5,code:bQ,del:s1,delLDelim:s1,delRDelim:s1,emStrongLDelim:IQ,emStrongRDelimAst:yQ,emStrongRDelimUnd:EQ,escape:jQ,link:cQ,nolink:I5,punctuation:VQ,reflink:D5,reflinkSearch:lQ,tag:pQ,text:ZQ,url:s1},dQ={...n4,link:H$(/^!?\[(label)\]\((.*?)\)/).replace("label",p2).getRegex(),reflink:H$(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",p2).getRegex()},p4={...n4,emStrongRDelimAst:fQ,emStrongLDelim:kQ,delLDelim:vQ,delRDelim:mQ,url:H$(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol",F5).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",F5).getRegex()},rQ={...p4,br:H$(Z5).replace("{2,}","*").getRegex(),text:H$(p4.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},u2={normal:o4,gfm:wQ,pedantic:TQ},q2={normal:n4,gfm:p4,breaks:rQ,pedantic:dQ},iQ={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},L5=($)=>iQ[$];function Y1($,Q){if(Q){if(k$.escapeTest.test($))return $.replace(k$.escapeReplace,L5)}else if(k$.escapeTestNoEncode.test($))return $.replace(k$.escapeReplaceNoEncode,L5);return $}function A5($){try{$=encodeURI($).replace(k$.percentDecode,"%")}catch{return null}return $}function P5($,Q){let J=$.replace(k$.findPipe,(G,X,W)=>{let _=!1,H=X;for(;--H>=0&&W[H]==="\\";)_=!_;return _?"|":" |"}),Y=J.split(k$.splitPipe),q=0;if(Y[0].trim()||Y.shift(),Y.length>0&&!Y.at(-1)?.trim()&&Y.pop(),Q)if(Y.length>Q)Y.splice(Q);else for(;Y.length<Q;)Y.push("");for(;q<Y.length;q++)Y[q]=Y[q].trim().replace(k$.slashPipe,"|");return Y}function Y2($,Q,J){let Y=$.length;if(Y===0)return"";let q=0;for(;q<Y;){let G=$.charAt(Y-q-1);if(G===Q&&!J)q++;else if(G!==Q&&J)q++;else break}return $.slice(0,Y-q)}function oQ($,Q){if($.indexOf(Q[1])===-1)return-1;let J=0;for(let Y=0;Y<$.length;Y++)if($[Y]==="\\")Y++;else if($[Y]===Q[0])J++;else if($[Y]===Q[1]&&(J--,J<0))return Y;return J>0?-2:-1}function aQ($,Q=0){let J=Q,Y="";for(let q of $)if(q==="\t"){let G=4-J%4;Y+=" ".repeat(G),J+=G}else Y+=q,J++;return Y}function S5($,Q,J,Y,q){let G=Q.href,X=Q.title||null,W=$[1].replace(q.other.outputLinkReplace,"$1");Y.state.inLink=!0;let _={type:$[0].charAt(0)==="!"?"image":"link",raw:J,href:G,title:X,text:W,tokens:Y.inlineTokens(W)};return Y.state.inLink=!1,_}function nQ($,Q,J){let Y=$.match(J.other.indentCodeCompensation);if(Y===null)return Q;let q=Y[1];return Q.split(`
14
+ `).map((G)=>{let X=G.match(J.other.beginningSpace);if(X===null)return G;let[W]=X;return W.length>=q.length?G.slice(q.length):G}).join(`
15
+ `)}var c2=class{options;rules;lexer;constructor($){this.options=$||e1}space($){let Q=this.rules.block.newline.exec($);if(Q&&Q[0].length>0)return{type:"space",raw:Q[0]}}code($){let Q=this.rules.block.code.exec($);if(Q){let J=Q[0].replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:Q[0],codeBlockStyle:"indented",text:this.options.pedantic?J:Y2(J,`
16
+ `)}}}fences($){let Q=this.rules.block.fences.exec($);if(Q){let J=Q[0],Y=nQ(J,Q[3]||"",this.rules);return{type:"code",raw:J,lang:Q[2]?Q[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):Q[2],text:Y}}}heading($){let Q=this.rules.block.heading.exec($);if(Q){let J=Q[2].trim();if(this.rules.other.endingHash.test(J)){let Y=Y2(J,"#");(this.options.pedantic||!Y||this.rules.other.endingSpaceChar.test(Y))&&(J=Y.trim())}return{type:"heading",raw:Q[0],depth:Q[1].length,text:J,tokens:this.lexer.inline(J)}}}hr($){let Q=this.rules.block.hr.exec($);if(Q)return{type:"hr",raw:Y2(Q[0],`
17
+ `)}}blockquote($){let Q=this.rules.block.blockquote.exec($);if(Q){let J=Y2(Q[0],`
17
18
  `).split(`
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,`
19
+ `),Y="",q="",G=[];for(;J.length>0;){let X=!1,W=[],_;for(_=0;_<J.length;_++)if(this.rules.other.blockquoteStart.test(J[_]))W.push(J[_]),X=!0;else if(!X)W.push(J[_]);else break;J=J.slice(_);let H=W.join(`
20
+ `),U=H.replace(this.rules.other.blockquoteSetextReplace,`
20
21
  $1`).replace(this.rules.other.blockquoteSetextReplace2,"");Y=Y?`${Y}
21
- ${W}`:W,q=q?`${q}
22
- ${U}`:U;let K=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(U,G,!0),this.lexer.state.top=K,Q.length===0)break;let z=G.at(-1);if(z?.type==="code")break;if(z?.type==="blockquote"){let B=z,N=B.raw+`
23
- `+Q.join(`
24
- `),P=this.blockquote(N);G[G.length-1]=P,Y=Y.substring(0,Y.length-B.raw.length)+P.raw,q=q.substring(0,q.length-B.text.length)+P.text;break}else if(z?.type==="list"){let B=z,N=B.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-B.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 K=PJ(J[2].split(`
28
- `,1)[0],J[1].length),z=$.split(`
29
- `,1)[0],B=!K.trim(),N=0;if(this.options.pedantic?(N=2,U=K.trimStart()):B?N=J[1].length+1:(N=K.search(this.rules.other.nonSpaceChar),N=N>4?1:N,U=K.slice(N),N+=J[1].length),B&&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),A=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)||A.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(B||K.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||T.test(K)||O.test(K)||M.test(K))break;U+=`
33
- `+z}B=!z.trim(),W+=S+`
34
- `,$=$.substring(S.length+1),K=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((K)=>K.type==="space"),U=W.length>0&&W.some((K)=>this.rules.other.anyLine.test(K.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=G5(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(G5(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=e0(Q.slice(0,-1),"\\");if((Q.length-G.length)%2===0)return}else{let G=SJ(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)),_5(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 _5(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,K=$.slice(0,q+Y.index+U+X);if(Math.min(q,X)%2){let B=K.slice(1,-1);return{type:"em",raw:K,text:B,tokens:this.lexer.inlineTokens(B)}}let z=K.slice(2,-2);return{type:"strong",raw:K,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),K=U.slice(q,-q);return{type:"del",raw:U,text:K,tokens:this.lexer.inlineTokens(K)}}}}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||s1,this.options.tokenizer=this.options.tokenizer||new m2,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:D$,block:v2.normal,inline:t0.normal};this.options.pedantic?(Q.block=v2.pedantic,Q.inline=t0.pedantic):this.options.gfm&&(Q.block=v2.gfm,this.options.breaks?Q.inline=t0.breaks:Q.inline=t0.gfm),this.tokenizer.rules=Q}static get rules(){return{block:v2,inline:t0}}static lex(J,Q){return new $(Q).lex(J)}static lexInline(J,Q){return new $(Q).inlineTokens(J)}lex(J){J=J.replace(D$.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(D$.tabCharGlobal," ").replace(D$.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(`
22
+ ${H}`:H,q=q?`${q}
23
+ ${U}`:U;let K=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(U,G,!0),this.lexer.state.top=K,J.length===0)break;let N=G.at(-1);if(N?.type==="code")break;if(N?.type==="blockquote"){let O=N,M=O.raw+`
24
+ `+J.join(`
25
+ `),L=this.blockquote(M);G[G.length-1]=L,Y=Y.substring(0,Y.length-O.raw.length)+L.raw,q=q.substring(0,q.length-O.text.length)+L.text;break}else if(N?.type==="list"){let O=N,M=O.raw+`
26
+ `+J.join(`
27
+ `),L=this.list(M);G[G.length-1]=L,Y=Y.substring(0,Y.length-N.raw.length)+L.raw,q=q.substring(0,q.length-O.raw.length)+L.raw,J=M.substring(G.at(-1).raw.length).split(`
28
+ `);continue}}return{type:"blockquote",raw:Y,tokens:G,text:q}}}list($){let Q=this.rules.block.list.exec($);if(Q){let J=Q[1].trim(),Y=J.length>1,q={type:"list",raw:"",ordered:Y,start:Y?+J.slice(0,-1):"",loose:!1,items:[]};J=Y?`\\d{1,9}\\${J.slice(-1)}`:`\\${J}`,this.options.pedantic&&(J=Y?J:"[*+-]");let G=this.rules.other.listItemRegex(J),X=!1;for(;$;){let _=!1,H="",U="";if(!(Q=G.exec($))||this.rules.block.hr.test($))break;H=Q[0],$=$.substring(H.length);let K=aQ(Q[2].split(`
29
+ `,1)[0],Q[1].length),N=$.split(`
30
+ `,1)[0],O=!K.trim(),M=0;if(this.options.pedantic?(M=2,U=K.trimStart()):O?M=Q[1].length+1:(M=K.search(this.rules.other.nonSpaceChar),M=M>4?1:M,U=K.slice(M),M+=Q[1].length),O&&this.rules.other.blankLine.test(N)&&(H+=N+`
31
+ `,$=$.substring(N.length+1),_=!0),!_){let L=this.rules.other.nextBulletRegex(M),F=this.rules.other.hrRegex(M),w=this.rules.other.fencesBeginRegex(M),z=this.rules.other.headingBeginRegex(M),A=this.rules.other.htmlBeginRegex(M),T=this.rules.other.blockquoteBeginRegex(M);for(;$;){let S=$.split(`
32
+ `,1)[0],j;if(N=S,this.options.pedantic?(N=N.replace(this.rules.other.listReplaceNesting," "),j=N):j=N.replace(this.rules.other.tabCharGlobal," "),w.test(N)||z.test(N)||A.test(N)||T.test(N)||L.test(N)||F.test(N))break;if(j.search(this.rules.other.nonSpaceChar)>=M||!N.trim())U+=`
33
+ `+j.slice(M);else{if(O||K.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||w.test(K)||z.test(K)||F.test(K))break;U+=`
34
+ `+N}O=!N.trim(),H+=S+`
35
+ `,$=$.substring(S.length+1),K=j.slice(M)}}q.loose||(X?q.loose=!0:this.rules.other.doubleBlankLine.test(H)&&(X=!0)),q.items.push({type:"list_item",raw:H,task:!!this.options.gfm&&this.rules.other.listIsTask.test(U),loose:!1,text:U,tokens:[]}),q.raw+=H}let W=q.items.at(-1);if(W)W.raw=W.raw.trimEnd(),W.text=W.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 H=this.rules.other.listTaskCheckbox.exec(_.raw);if(H){let U={type:"checkbox",raw:H[0]+" ",checked:H[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 H=_.tokens.filter((K)=>K.type==="space"),U=H.length>0&&H.some((K)=>this.rules.other.anyLine.test(K.raw));q.loose=U}}if(q.loose)for(let _ of q.items){_.loose=!0;for(let H of _.tokens)H.type==="text"&&(H.type="paragraph")}return q}}html($){let Q=this.rules.block.html.exec($);if(Q)return{type:"html",block:!0,raw:Q[0],pre:Q[1]==="pre"||Q[1]==="script"||Q[1]==="style",text:Q[0]}}def($){let Q=this.rules.block.def.exec($);if(Q){let J=Q[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal," "),Y=Q[2]?Q[2].replace(this.rules.other.hrefBrackets,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",q=Q[3]?Q[3].substring(1,Q[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):Q[3];return{type:"def",tag:J,raw:Q[0],href:Y,title:q}}}table($){let Q=this.rules.block.table.exec($);if(!Q||!this.rules.other.tableDelimiter.test(Q[2]))return;let J=P5(Q[1]),Y=Q[2].replace(this.rules.other.tableAlignChars,"").split("|"),q=Q[3]?.trim()?Q[3].replace(this.rules.other.tableRowBlankLine,"").split(`
36
+ `):[],G={type:"table",raw:Q[0],header:[],align:[],rows:[]};if(J.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<J.length;X++)G.header.push({text:J[X],tokens:this.lexer.inline(J[X]),header:!0,align:G.align[X]});for(let X of q)G.rows.push(P5(X,G.header.length).map((W,_)=>({text:W,tokens:this.lexer.inline(W),header:!1,align:G.align[_]})));return G}}lheading($){let Q=this.rules.block.lheading.exec($);if(Q){let J=Q[1].trim();return{type:"heading",raw:Q[0],depth:Q[2].charAt(0)==="="?1:2,text:J,tokens:this.lexer.inline(J)}}}paragraph($){let Q=this.rules.block.paragraph.exec($);if(Q){let J=Q[1].charAt(Q[1].length-1)===`
37
+ `?Q[1].slice(0,-1):Q[1];return{type:"paragraph",raw:Q[0],text:J,tokens:this.lexer.inline(J)}}}text($){let Q=this.rules.block.text.exec($);if(Q)return{type:"text",raw:Q[0],text:Q[0],tokens:this.lexer.inline(Q[0])}}escape($){let Q=this.rules.inline.escape.exec($);if(Q)return{type:"escape",raw:Q[0],text:Q[1]}}tag($){let Q=this.rules.inline.tag.exec($);if(Q)return!this.lexer.state.inLink&&this.rules.other.startATag.test(Q[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test(Q[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test(Q[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test(Q[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:Q[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:Q[0]}}link($){let Q=this.rules.inline.link.exec($);if(Q){let J=Q[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(J)){if(!this.rules.other.endAngleBracket.test(J))return;let G=Y2(J.slice(0,-1),"\\");if((J.length-G.length)%2===0)return}else{let G=oQ(Q[2],"()");if(G===-2)return;if(G>-1){let X=(Q[0].indexOf("!")===0?5:4)+Q[1].length+G;Q[2]=Q[2].substring(0,G),Q[0]=Q[0].substring(0,X).trim(),Q[3]=""}}let Y=Q[2],q="";if(this.options.pedantic){let G=this.rules.other.pedanticHrefTitle.exec(Y);G&&(Y=G[1],q=G[3])}else q=Q[3]?Q[3].slice(1,-1):"";return Y=Y.trim(),this.rules.other.startAngleBracket.test(Y)&&(this.options.pedantic&&!this.rules.other.endAngleBracket.test(J)?Y=Y.slice(1):Y=Y.slice(1,-1)),S5(Q,{href:Y&&Y.replace(this.rules.inline.anyPunctuation,"$1"),title:q&&q.replace(this.rules.inline.anyPunctuation,"$1")},Q[0],this.lexer,this.rules)}}reflink($,Q){let J;if((J=this.rules.inline.reflink.exec($))||(J=this.rules.inline.nolink.exec($))){let Y=(J[2]||J[1]).replace(this.rules.other.multipleSpaceGlobal," "),q=Q[Y.toLowerCase()];if(!q){let G=J[0].charAt(0);return{type:"text",raw:G,text:G}}return S5(J,q,J[0],this.lexer,this.rules)}}emStrong($,Q,J=""){let Y=this.rules.inline.emStrongLDelim.exec($);if(!Y||!Y[1]&&!Y[2]&&!Y[3]&&!Y[4]||Y[4]&&J.match(this.rules.other.unicodeAlphaNumeric))return;if(!(Y[1]||Y[3])||!J||this.rules.inline.punctuation.exec(J)){let q=[...Y[0]].length-1,G,X,W=q,_=0,H=Y[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(H.lastIndex=0,Q=Q.slice(-1*$.length+q);(Y=H.exec(Q))!==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]){W+=X;continue}else if((Y[5]||Y[6])&&q%3&&!((q+X)%3)){_+=X;continue}if(W-=X,W>0)continue;X=Math.min(X,X+W+_);let U=[...Y[0]][0].length,K=$.slice(0,q+Y.index+U+X);if(Math.min(q,X)%2){let O=K.slice(1,-1);return{type:"em",raw:K,text:O,tokens:this.lexer.inlineTokens(O)}}let N=K.slice(2,-2);return{type:"strong",raw:K,text:N,tokens:this.lexer.inlineTokens(N)}}}}codespan($){let Q=this.rules.inline.code.exec($);if(Q){let J=Q[2].replace(this.rules.other.newLineCharGlobal," "),Y=this.rules.other.nonSpaceChar.test(J),q=this.rules.other.startingSpaceChar.test(J)&&this.rules.other.endingSpaceChar.test(J);return Y&&q&&(J=J.substring(1,J.length-1)),{type:"codespan",raw:Q[0],text:J}}}br($){let Q=this.rules.inline.br.exec($);if(Q)return{type:"br",raw:Q[0]}}del($,Q,J=""){let Y=this.rules.inline.delLDelim.exec($);if(!Y)return;if(!Y[1]||!J||this.rules.inline.punctuation.exec(J)){let q=[...Y[0]].length-1,G,X,W=q,_=this.rules.inline.delRDelim;for(_.lastIndex=0,Q=Q.slice(-1*$.length+q);(Y=_.exec(Q))!==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]){W+=X;continue}if(W-=X,W>0)continue;X=Math.min(X,X+W);let H=[...Y[0]][0].length,U=$.slice(0,q+Y.index+H+X),K=U.slice(q,-q);return{type:"del",raw:U,text:K,tokens:this.lexer.inlineTokens(K)}}}}autolink($){let Q=this.rules.inline.autolink.exec($);if(Q){let J,Y;return Q[2]==="@"?(J=Q[1],Y="mailto:"+J):(J=Q[1],Y=J),{type:"link",raw:Q[0],text:J,href:Y,tokens:[{type:"text",raw:J,text:J}]}}}url($){let Q;if(Q=this.rules.inline.url.exec($)){let J,Y;if(Q[2]==="@")J=Q[0],Y="mailto:"+J;else{let q;do q=Q[0],Q[0]=this.rules.inline._backpedal.exec(Q[0])?.[0]??"";while(q!==Q[0]);J=Q[0],Q[1]==="www."?Y="http://"+Q[0]:Y=Q[0]}return{type:"link",raw:Q[0],text:J,href:Y,tokens:[{type:"text",raw:J,text:J}]}}}inlineText($){let Q=this.rules.inline.text.exec($);if(Q){let J=this.lexer.state.inRawBlock;return{type:"text",raw:Q[0],text:Q[0],escaped:J}}}},i$=class ${tokens;options;state;inlineQueue;tokenizer;constructor(Q){this.tokens=[],this.tokens.links=Object.create(null),this.options=Q||e1,this.options.tokenizer=this.options.tokenizer||new c2,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};let J={other:k$,block:u2.normal,inline:q2.normal};this.options.pedantic?(J.block=u2.pedantic,J.inline=q2.pedantic):this.options.gfm&&(J.block=u2.gfm,this.options.breaks?J.inline=q2.breaks:J.inline=q2.gfm),this.tokenizer.rules=J}static get rules(){return{block:u2,inline:q2}}static lex(Q,J){return new $(J).lex(Q)}static lexInline(Q,J){return new $(J).inlineTokens(Q)}lex(Q){Q=Q.replace(k$.carriageReturn,`
38
+ `),this.blockTokens(Q,this.tokens);for(let J=0;J<this.inlineQueue.length;J++){let Y=this.inlineQueue[J];this.inlineTokens(Y.src,Y.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(Q,J=[],Y=!1){for(this.tokenizer.lexer=this,this.options.pedantic&&(Q=Q.replace(k$.tabCharGlobal," ").replace(k$.spaceLine,""));Q;){let q;if(this.options.extensions?.block?.some((X)=>(q=X.call({lexer:this},Q,J))?(Q=Q.substring(q.raw.length),J.push(q),!0):!1))continue;if(q=this.tokenizer.space(Q)){Q=Q.substring(q.raw.length);let X=J.at(-1);q.raw.length===1&&X!==void 0?X.raw+=`
39
+ `:J.push(q);continue}if(q=this.tokenizer.code(Q)){Q=Q.substring(q.raw.length);let X=J.at(-1);X?.type==="paragraph"||X?.type==="text"?(X.raw+=(X.raw.endsWith(`
39
40
  `)?"":`
40
41
  `)+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(`
42
+ `+q.text,this.inlineQueue.at(-1).src=X.text):J.push(q);continue}if(q=this.tokenizer.fences(Q)){Q=Q.substring(q.raw.length),J.push(q);continue}if(q=this.tokenizer.heading(Q)){Q=Q.substring(q.raw.length),J.push(q);continue}if(q=this.tokenizer.hr(Q)){Q=Q.substring(q.raw.length),J.push(q);continue}if(q=this.tokenizer.blockquote(Q)){Q=Q.substring(q.raw.length),J.push(q);continue}if(q=this.tokenizer.list(Q)){Q=Q.substring(q.raw.length),J.push(q);continue}if(q=this.tokenizer.html(Q)){Q=Q.substring(q.raw.length),J.push(q);continue}if(q=this.tokenizer.def(Q)){Q=Q.substring(q.raw.length);let X=J.at(-1);X?.type==="paragraph"||X?.type==="text"?(X.raw+=(X.raw.endsWith(`
42
43
  `)?"":`
43
44
  `)+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(`
45
+ `+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},J.push(q));continue}if(q=this.tokenizer.table(Q)){Q=Q.substring(q.raw.length),J.push(q);continue}if(q=this.tokenizer.lheading(Q)){Q=Q.substring(q.raw.length),J.push(q);continue}let G=Q;if(this.options.extensions?.startBlock){let X=1/0,W=Q.slice(1),_;this.options.extensions.startBlock.forEach((H)=>{_=H.call({lexer:this},W),typeof _=="number"&&_>=0&&(X=Math.min(X,_))}),X<1/0&&X>=0&&(G=Q.substring(0,X+1))}if(this.state.top&&(q=this.tokenizer.paragraph(G))){let X=J.at(-1);Y&&X?.type==="paragraph"?(X.raw+=(X.raw.endsWith(`
45
46
  `)?"":`
46
47
  `)+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(`
48
+ `+q.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=X.text):J.push(q),Y=G.length!==Q.length,Q=Q.substring(q.raw.length);continue}if(q=this.tokenizer.text(Q)){Q=Q.substring(q.raw.length);let X=J.at(-1);X?.type==="text"?(X.raw+=(X.raw.endsWith(`
48
49
  `)?"":`
49
50
  `)+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,K=J.slice(1),z;this.options.extensions.startInline.forEach((B)=>{z=B.call({lexer:this},K),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}},x2=class{options;parser;constructor($){this.options=$||s1}space($){return""}code({text:$,lang:J,escaped:Q}){let Y=(J||"").match(D$.notSpaceStart)?.[0],q=$.replace(D$.endingNewline,"")+`
51
- `;return Y?'<pre><code class="language-'+Q1(Y)+'">'+(Q?q:Q1(q,!0))+`</code></pre>
52
- `:"<pre><code>"+(Q?q:Q1(q,!0))+`</code></pre>
51
+ `+q.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=X.text):J.push(q);continue}if(Q){let X="Infinite loop on byte: "+Q.charCodeAt(0);if(this.options.silent){console.error(X);break}else throw Error(X)}}return this.state.top=!0,J}inline(Q,J=[]){return this.inlineQueue.push({src:Q,tokens:J}),J}inlineTokens(Q,J=[]){this.tokenizer.lexer=this;let Y=Q,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,W="";for(;Q;){X||(W=""),X=!1;let _;if(this.options.extensions?.inline?.some((U)=>(_=U.call({lexer:this},Q,J))?(Q=Q.substring(_.raw.length),J.push(_),!0):!1))continue;if(_=this.tokenizer.escape(Q)){Q=Q.substring(_.raw.length),J.push(_);continue}if(_=this.tokenizer.tag(Q)){Q=Q.substring(_.raw.length),J.push(_);continue}if(_=this.tokenizer.link(Q)){Q=Q.substring(_.raw.length),J.push(_);continue}if(_=this.tokenizer.reflink(Q,this.tokens.links)){Q=Q.substring(_.raw.length);let U=J.at(-1);_.type==="text"&&U?.type==="text"?(U.raw+=_.raw,U.text+=_.text):J.push(_);continue}if(_=this.tokenizer.emStrong(Q,Y,W)){Q=Q.substring(_.raw.length),J.push(_);continue}if(_=this.tokenizer.codespan(Q)){Q=Q.substring(_.raw.length),J.push(_);continue}if(_=this.tokenizer.br(Q)){Q=Q.substring(_.raw.length),J.push(_);continue}if(_=this.tokenizer.del(Q,Y,W)){Q=Q.substring(_.raw.length),J.push(_);continue}if(_=this.tokenizer.autolink(Q)){Q=Q.substring(_.raw.length),J.push(_);continue}if(!this.state.inLink&&(_=this.tokenizer.url(Q))){Q=Q.substring(_.raw.length),J.push(_);continue}let H=Q;if(this.options.extensions?.startInline){let U=1/0,K=Q.slice(1),N;this.options.extensions.startInline.forEach((O)=>{N=O.call({lexer:this},K),typeof N=="number"&&N>=0&&(U=Math.min(U,N))}),U<1/0&&U>=0&&(H=Q.substring(0,U+1))}if(_=this.tokenizer.inlineText(H)){Q=Q.substring(_.raw.length),_.raw.slice(-1)!=="_"&&(W=_.raw.slice(-1)),X=!0;let U=J.at(-1);U?.type==="text"?(U.raw+=_.raw,U.text+=_.text):J.push(_);continue}if(Q){let U="Infinite loop on byte: "+Q.charCodeAt(0);if(this.options.silent){console.error(U);break}else throw Error(U)}}return J}},l2=class{options;parser;constructor($){this.options=$||e1}space($){return""}code({text:$,lang:Q,escaped:J}){let Y=(Q||"").match(k$.notSpaceStart)?.[0],q=$.replace(k$.endingNewline,"")+`
52
+ `;return Y?'<pre><code class="language-'+Y1(Y)+'">'+(J?q:Y1(q,!0))+`</code></pre>
53
+ `:"<pre><code>"+(J?q:Y1(q,!0))+`</code></pre>
53
54
  `}blockquote({tokens:$}){return`<blockquote>
54
55
  ${this.parser.parse($)}</blockquote>
55
- `}html({text:$}){return $}def($){return""}heading({tokens:$,depth:J}){return`<h${J}>${this.parser.parseInline($)}</h${J}>
56
+ `}html({text:$}){return $}def($){return""}heading({tokens:$,depth:Q}){return`<h${Q}>${this.parser.parseInline($)}</h${Q}>
56
57
  `}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
+ `}list($){let{ordered:Q,start:J}=$,Y="";for(let X=0;X<$.items.length;X++){let W=$.items[X];Y+=this.listitem(W)}let q=Q?"ol":"ul",G=Q&&J!==1?' start="'+J+'"':"";return"<"+q+G+`>
58
59
  `+Y+"</"+q+`>
59
60
  `}listitem($){return`<li>${this.parser.parse($.tokens)}</li>
60
61
  `}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>
62
+ `}table($){let Q="",J="";for(let q=0;q<$.header.length;q++)J+=this.tablecell($.header[q]);Q+=this.tablerow({text:J});let Y="";for(let q=0;q<$.rows.length;q++){let G=$.rows[q];J="";for(let X=0;X<G.length;X++)J+=this.tablecell(G[X]);Y+=this.tablerow({text:J})}return Y&&(Y=`<tbody>${Y}</tbody>`),`<table>
62
63
  <thead>
63
- `+J+`</thead>
64
+ `+Q+`</thead>
64
65
  `+Y+`</table>
65
66
  `}tablerow({text:$}){return`<tr>
66
67
  ${$}</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>${Q1($,!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=X5($);if(q===null)return Y;$=q;let G='<a href="'+$+'"';return J&&(G+=' title="'+Q1(J)+'"'),G+=">"+Y+"</a>",G}image({href:$,title:J,text:Q,tokens:Y}){Y&&(Q=this.parser.parseInline(Y,this.parser.textRenderer));let q=X5($);if(q===null)return Q1(Q);$=q;let G=`<img src="${$}" alt="${Q1(Q)}"`;return J&&(G+=` title="${Q1(J)}"`),G+=">",G}text($){return"tokens"in $&&$.tokens?this.parser.parseInline($.tokens):("escaped"in $)&&$.escaped?$.text:Q1($.text)}},d4=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||s1,this.options.renderer=this.options.renderer||new x2,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new d4}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=$||s1}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}},TJ=class{defaults=g4();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=c$;Renderer=x2;TextRenderer=d4;Lexer=p$;Tokenizer=m2;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 x2(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 m2(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 K=await H.call(q,W);return _.call(q,K)})();let U=H.call(q,W);return _.call(q,U)}:q[X]=(...W)=>{if(this.defaults.async)return(async()=>{let K=await H.apply(q,W);return K===!1&&(K=await _.apply(q,W)),K})();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>"+Q1(Q.message+"",!0)+"</pre>";return J?Promise.resolve(Y):Y}if(J)return Promise.reject(Q);throw Q}}},n1=new TJ;function X$($,J){return n1.parse($,J)}X$.options=X$.setOptions=function($){return n1.setOptions($),X$.defaults=n1.defaults,H5(X$.defaults),X$};X$.getDefaults=g4;X$.defaults=s1;X$.use=function(...$){return n1.use(...$),X$.defaults=n1.defaults,H5(X$.defaults),X$};X$.walkTokens=function($,J){return n1.walkTokens($,J)};X$.parseInline=n1.parseInline;X$.Parser=c$;X$.parser=c$.parse;X$.Renderer=x2;X$.TextRenderer=d4;X$.Lexer=p$;X$.lexer=p$.lex;X$.Tokenizer=m2;X$.Hooks=$2;X$.parse=X$;var{options:VX,setOptions:ZX,use:CX,walkTokens:RX,parseInline:IX}=X$;var DX=c$.parse,kX=p$.lex;import{useEffect as F5,useMemo as r4,useRef as jJ,useState as Q2}from"react";import{jsxDEV as P$}from"react/jsx-dev-runtime";function i4({open:$,onClose:J,onSubmit:Q,includedRemoteIds:Y,onToggleRemoteId:q}){let{annotations:G,generalNote:X,submittableResponses:H,feedbackEntries:_}=i1(),[W,U]=Q2(""),[K,z]=Q2(!1),[B,N]=Q2(!1),[P,M]=Q2(null),T=jJ(null),[O,A]=Q2(!1),w=r4(()=>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)A($);let S=r4(()=>a0(G,X,H,_,Y),[G,X,H,_,Y]),j=K?W:S;if(F5(()=>{if($&&B&&T.current)T.current.focus()},[$,B]),F5(()=>{if(!$)return;let y=(I)=>{if(I.key==="Escape")J()};return window.addEventListener("keydown",y),()=>window.removeEventListener("keydown",y)},[$,J]),!$)return null;let C=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),K&&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 ${!B?"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 ${B?"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),B?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$(p2,{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=n0(H,_);if(y.length>0){M(`Please answer: ${y.join(", ")}`);return}M(null),Q(j)},disabled:!C,className:`px-6 py-2 rounded-lg font-body text-[13px] font-medium transition-all ${C?"bg-btn-primary text-btn-primary-text hover:opacity-90":"bg-bg-input text-text-disabled cursor-default"}`,children:"Submit feedback"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}var bJ=/!\[([^\]]*)\]\((\/tmp\/agent-canvas\/uploads\/([^)]+))\)/g;function VJ($){return $.replace(bJ,(J,Q,Y,q)=>`![${Q}](/api/uploads/${q})`)}function p2({text:$}){let J=r4(()=>X$.parse(VJ($),{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 m,Fragment as c2}from"react/jsx-dev-runtime";function l2({onSubmit:$,collapseButton:J}){let{isReadOnly:Q,selectedRevision:Y,currentRevision:q,revisions:G,agentWatching:X}=a4(f$),H=a4(ZJ),_=G.find((z)=>z.revision===Y),W=Q&&Y===q,U=!!_?.feedbackConsumed,K=_?.label||`Round ${Y}`;if(Q)return m(IJ,{sessionId:H,revision:Y,label:K,waitingForUpdate:W,feedbackConsumed:U,agentWatching:X,collapseButton:J},void 0,!1,void 0,this);return m(kJ,{onSubmit:$,agentWatching:X,collapseButton:J},void 0,!1,void 0,this)}function RJ({sessionId:$,revision:J,label:Q,waitingForUpdate:Y,feedbackConsumed:q,agentWatching:G,collapseButton:X}){let _=K1().isShared;return m("div",{className:"flex flex-col h-full",children:[m("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[m("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&&!_&&m(P5,{feedbackConsumed:q,agentWatching:G},void 0,!1,void 0,this),m(w5,{sessionId:$,revision:J},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function P5({feedbackConsumed:$,agentWatching:J}){if($)return m("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:[m("span",{className:"w-2 h-2 rounded-full bg-accent-green animate-pulse"},void 0,!1,void 0,this),m("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 m("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:[m("span",{className:"w-2 h-2 rounded-full bg-accent-blue animate-pulse"},void 0,!1,void 0,this),m("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 m("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:[m("span",{className:"w-2 h-2 rounded-full bg-accent-amber"},void 0,!1,void 0,this),m("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 IJ({sessionId:$,revision:J,label:Q,waitingForUpdate:Y,feedbackConsumed:q,agentWatching:G,collapseButton:X}){let{annotations:H,generalNote:_}=i1(),W=H.length>0||_.trim().length>0,[U,K]=j0("feedback");if(!W)return m(RJ,{sessionId:$,revision:J,label:Q,waitingForUpdate:Y,feedbackConsumed:q,agentWatching:G,collapseButton:X},void 0,!1,void 0,this);return m("div",{className:"flex flex-col h-full",children:[m("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[m("div",{className:"flex items-center gap-1 bg-bg-input rounded-md p-0.5",children:[m("button",{onClick:()=>K("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),m("button",{onClick:()=>K("annotations"),className:`px-2.5 py-1 rounded text-[11px] font-medium font-body transition-colors flex items-center gap-1.5 ${U==="annotations"?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:["Annotations",m("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&&m(P5,{feedbackConsumed:q,agentWatching:G},void 0,!1,void 0,this),U==="feedback"?m(w5,{sessionId:$,revision:J},void 0,!1,void 0,this):m(c2,{children:[m("div",{className:"flex-1 overflow-y-auto",children:m(T5,{annotations:H,readOnly:!0},void 0,!1,void 0,this)},void 0,!1,void 0,this),_.trim()&&m("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:m("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 w5({sessionId:$,revision:J}){let Q=K1(),[Y,q]=j0(null),[G,X]=j0(!0);return S5(()=>{if(X(!0),!Q.fsAvailable){q(null),X(!1);return}fetch(`/api/session/${$}/revision/${J}/feedback`).then((H)=>H.json()).then((H)=>{q(s3.parse(H).feedback||null),X(!1)}).catch(()=>{q(null),X(!1)})},[$,J]),m("div",{className:"flex-1 overflow-y-auto px-4",children:G?m("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"Loading..."},void 0,!1,void 0,this):Y?m(p2,{text:Y},void 0,!1,void 0,this):m("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 DJ($){let J=$.filter((X)=>X.filePath===u$),Q=$.filter((X)=>!X.filePath),Y=$.filter((X)=>u1(X)!==void 0),q={};for(let X of Y){let H=u1(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 A5({children:$}){return m("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 T5({annotations:$,readOnly:J,includedRemoteIds:Q,onToggleRemoteId:Y}){let{setActiveView:q}=a4(J1),{response:G,plan:X,fileGroups:H,hasMultipleGroups:_}=DJ($),W=o4((z)=>{let B=u1(z);if(!B)return;q({type:"file",path:B}),setTimeout(()=>{let N=s0(z);if(N)N.scrollIntoView({behavior:"smooth",block:"center"})},150)},[q]),U=o4((z)=>f4(z,q),[q]),K={readOnly:J,onSelect:W,onReveal:U,includedRemoteIds:Q,onToggleRemoteId:Y};return m(c2,{children:[G.length>0&&m(c2,{children:[_&&m(A5,{children:"Agent Response"},void 0,!1,void 0,this),m(i0,{annotations:G,...K},void 0,!1,void 0,this)]},void 0,!0,void 0,this),X.length>0&&m(c2,{children:[_&&m(A5,{children:"Canvas"},void 0,!1,void 0,this),m(i0,{annotations:X,...K},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Object.entries(H).map(([z,B])=>m("div",{children:[m("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:[m(I1,{name:z.split("/").pop()||z,type:"file"},void 0,!1,void 0,this),m("span",{className:"truncate",children:z},void 0,!1,void 0,this)]},void 0,!0,void 0,this),m(i0,{annotations:B,...K},void 0,!1,void 0,this)]},z,!0,void 0,this))]},void 0,!0,void 0,this)}function kJ({onSubmit:$,agentWatching:J,collapseButton:Q}){let Y=K1(),[q,G]=j0(!1),{annotations:X,generalNote:H,submittableResponses:_,feedbackEntries:W}=i1(),U=CJ(()=>X.filter((w)=>w.source==="remote"),[X]),[K,z]=j0(()=>new Set);S5(()=>{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 B=o4((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(E2),P=W.size>0,M=X.length>0||H.trim().length>0||N||P,[T,O]=j0(null),A=()=>{let w=a0(X,H,_,W,K);$(w)};return m("div",{className:"flex flex-col h-full",children:[m("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[m("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body flex items-center gap-2",children:["Annotations",X.length>0&&m("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&&m("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),m("div",{className:"flex-1 overflow-y-auto",children:[X.length===0&&m("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),m(T5,{annotations:X,includedRemoteIds:K,onToggleRemoteId:B},void 0,!1,void 0,this)]},void 0,!0,void 0,this),m(A4,{hasContent:M,onSubmit:()=>{let w=n0(_,W);if(w.length>0){O(`Please answer: ${w.join(", ")}`);return}O(null),A()},onSubmitEmpty:()=>$("No feedback — looks good."),notice:T&&m("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:[m("span",{children:T},void 0,!1,void 0,this),m("button",{onClick:()=>{O(null),A()},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:m("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),m(i4,{open:q,onClose:()=>G(!1),onSubmit:$,includedRemoteIds:K,onToggleRemoteId:B},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{useFeedback as xH}from"#canvas/runtime";import HG from"react";import{jsxDEV as UG}from"react/jsx-dev-runtime";X$.setOptions({gfm:!0,breaks:!1});import{jsxDEV as NG}from"react/jsx-dev-runtime";import{jsxDEV as LG}from"react/jsx-dev-runtime";import{useAnnotations as jG,useResponseRegistration as bG}from"#canvas/runtime";import{useEffect as ZG,useMemo as CG,useRef as RG,useState as IG}from"react";import{jsxDEV as PG}from"react/jsx-dev-runtime";import{jsxDEV as yG}from"react/jsx-dev-runtime";import{useEffect as mG,useRef as xG}from"react";function q2(){return window.hljs}import{jsxDEV as pG}from"react/jsx-dev-runtime";import{jsxDEV as oG}from"react/jsx-dev-runtime";import{ActiveViewCtx as sG,SessionContext as tG}from"#canvas/runtime";import{useContext as $_,useEffect as J_,useRef as Q_,useState as q_}from"react";import{jsxDEV as __}from"react/jsx-dev-runtime";import{SessionContext as U_}from"#canvas/runtime";import{useContext as B_,useState as z_}from"react";import{jsxDEV as M_}from"react/jsx-dev-runtime";import{useMemo as S_}from"react";import{jsxDEV as w_}from"react/jsx-dev-runtime";X$.setOptions({gfm:!0,breaks:!1});import{useAnnotations as V_,useCanvasFile as Z_}from"#canvas/runtime";import{useCallback as D_,useEffect as k_,useRef as y_,useState as E_}from"react";import v_ from"react-dom";import{jsxDEV as x_,Fragment as h_}from"react/jsx-dev-runtime";import{jsxDEV as l_}from"react/jsx-dev-runtime";import{jsxDEV as i_}from"react/jsx-dev-runtime";import{useState as s_}from"react";import{jsxDEV as $H}from"react/jsx-dev-runtime";import{jsxDEV as qH}from"react/jsx-dev-runtime";import{jsxDEV as _H}from"react/jsx-dev-runtime";import{useAnnotations as UH,useResponseRegistration as KH}from"#canvas/runtime";import{useRef as NH,useState as MH}from"react";import{jsxDEV as FH}from"react/jsx-dev-runtime";import{CanvasFileCtx as vJ,SessionContext as gJ}from"#canvas/runtime";import d2,{useContext as j5,useEffect as D1,useMemo as X2,useRef as mJ,useState as q1}from"react";import{createPortal as xJ}from"react-dom";import{createContext as fJ}from"react";var Y2=fJ(()=>{});import{jsxDEV as N$,Fragment as cJ}from"react/jsx-dev-runtime";class b5 extends d2.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$(V5,{message:this.state.error.message},void 0,!1,void 0,this)}}function V5({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 b0({revision:$,filename:J}){let Q=j5(gJ),Y=K1(),q=j5(Y2),[G,X]=q1(null),[H,_]=q1(null),[W,U]=q1(!0),K=mJ(null),{annotations:z,addAnnotationWithId:B,removeAnnotation:N,updateAnnotation:P,addAnnotationImage:M,removeAnnotationImage:T,activeAnnotationId:O,setActiveAnnotationId:A,registerCanvasRendered:w}=i1(),S=X2(()=>z.filter((v)=>!v.filePath&&(!v.canvasFile||v.canvasFile===J)),[z,J]),[j,C]=q1(null),[y,I]=q1(null),[V,f]=q1(null),[h,o]=q1(null),[B$,a]=q1(!1);D1(()=>{U(!0),_(null),o(null),Y.loadCanvasModule(J,$).then((v)=>{X(()=>v.default),U(!1)}).catch((v)=>{let c=v instanceof Error?v:Error(String(v));_(c.message),U(!1),q({revision:$,filename:J,message:c.message,...c.stack?{stack:c.stack}:{}})})},[Q,$,J,q]),D1(()=>{if(G)w(J)},[G,J,w]);let U$=document.getElementById("plan-scroll-container"),{popovers:q$,isPopoverOpen:z$}=C1({containerRef:K,restoreKey:G,restoreAnnotations:S,extractContext:(v)=>A1(v,K.current),canvasFile:J,scrollContainer:U$}),{popovers:J$,isDrawing:_$,isPopoverOpen:L$}=b4({containerRef:K,restoreKey:G,canvasFile:J,scrollContainer:U$}),n=z$||L$,d=X2(()=>{let v=new Map;for(let c of S)if(c.snippet.startsWith("["))v.set(c.snippet,c.id);return v},[S]);D1(()=>{let v=K.current;if(!v)return;let c=(R)=>{if(V||n||_$)return;let x=R.target;if(x.closest("[data-block-comment-btn]"))return;a(!1);let r=x.closest(Q0);if(r&&v.contains(r)){let w$=t1(v).indexOf(r);o(w$>=0?w$:null)}else o(null);let M$=x.closest(S1);if(M$&&v.contains(M$)){I(M$);let F$=a$(M$),w$=F$?d.get(F$):void 0;if(w$&&w$!==O)A(w$)}else I(null)},E=(R)=>{if(V||n)return;if(R.relatedTarget?.closest("[data-block-comment-btn]"))return;I(null),A(null)};return v.addEventListener("mousemove",c),v.addEventListener("mouseleave",E),()=>{v.removeEventListener("mousemove",c),v.removeEventListener("mouseleave",E)}},[G,V,n,_$,d,O]),D1(()=>{let v=(c)=>{let E=c.target.tagName;if(E==="INPUT"||E==="TEXTAREA"||c.target.isContentEditable)return;if(V||n)return;let R=K.current;if(!R)return;if(c.key==="ArrowDown"){c.preventDefault(),a(!0);let x=t1(R);if(x.length===0)return;o((r)=>{if(r===null)return 0;return Math.min(r+1,x.length-1)})}else if(c.key==="ArrowUp"){c.preventDefault(),a(!0);let x=t1(R);if(x.length===0)return;o((r)=>{if(r===null)return x.length-1;return Math.max(r-1,0)})}else if(c.key==="a"||c.key==="A"){if(h===null||!R)return;let r=t1(R)[h];if(!r)return;if(!r.matches(S1))return;c.preventDefault();let M$=a$(r);if(!M$)return;let F$=d.get(M$);if(F$)A(F$),f({anchorEl:r,snippet:M$,annId:F$});else f({anchorEl:r,snippet:M$})}else if(c.key===" "||c.key==="Enter"){if(h===null)return;let r=t1(R)[h];if(!r)return;let M$=r.getAttribute("data-md");if(M$==="choice-option"||M$==="multichoice-option")c.preventDefault(),r.dispatchEvent(new CustomEvent("kb-select",{bubbles:!0}));else if(M$==="userinput"){c.preventDefault();let F$=r.querySelector("textarea");if(F$){F$.focus();let w$=(r$)=>{if(r$.key==="Escape")r$.preventDefault(),F$.blur(),a(!0)};F$.addEventListener("keydown",w$),F$.addEventListener("blur",()=>F$.removeEventListener("keydown",w$),{once:!0})}}else if(M$==="rangeinput"){c.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(),a(!0)};F$.addEventListener("keydown",w$),F$.addEventListener("blur",()=>F$.removeEventListener("keydown",w$),{once:!0})}}}else if(c.key==="Escape")o(null),a(!1),A(null)};return document.addEventListener("keydown",v),()=>document.removeEventListener("keydown",v)},[h,V,n,d]),D1(()=>{let v=K.current;if(!v||h===null||!B$)return;let E=t1(v)[h];if(!E)return;E.style.outline="2px solid var(--color-accent-blue)",E.style.outlineOffset="-2px",E.style.borderRadius="8px",E.scrollIntoView({block:"nearest",behavior:"smooth"});let R=a$(E),x=R?d.get(R):void 0;if(x)A(x);return()=>{E.style.outline="",E.style.outlineOffset="",E.style.borderRadius=""}},[h,B$,d]);let Y$=X2(()=>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$(V5,{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$(vJ.Provider,{value:J,children:[N$("div",{ref:K,className:"plan-content plan-updated","data-canvas-file":J,children:N$(b5,{revision:$,filename:J,reportError:q,children:Y$},`${$}:${J}`,!1,void 0,this)},void 0,!1,void 0,this),j&&N$(pJ,{note:j.note,onSave:(v)=>{P(j.id,v),C(null)},onCancel:()=>C(null)},void 0,!1,void 0,this),q$,J$,N$(hJ,{containerRef:K,hoveredBlock:y,focusedBlockIndex:h,blockPopover:V,blockAnnotationMap:d,activeAnnotationId:O,onOpen:(v,c,E)=>{if(E)A(E),f({anchorEl:v,snippet:c,annId:E});else f({anchorEl:v,snippet:c})}},void 0,!1,void 0,this),V&&!V.annId&&N$(e$,{anchorEl:V.anchorEl,scrollContainer:U$,snippet:V.snippet,truncateAt:80,onAdd:(v,c)=>{let E=E$();B(E,V.snippet,v,void 0,void 0,c,J),f(null)},onCancel:()=>f(null)},void 0,!1,void 0,this),V?.annId&&(()=>{let v=S.find((c)=>c.id===V.annId);if(!v)return null;return N$(l1,{anchorEl:V.anchorEl,scrollContainer:U$,initialNote:v.note,initialImages:v.images,onUpdate:(c,E)=>{P(V.annId,c);let R=v.images||[];for(let x of E)if(!R.includes(x))M(V.annId,x);for(let x of R)if(!E.includes(x))T(V.annId,x)},onDelete:()=>{N(V.annId),A(null),f(null)},onClose:()=>f(null)},void 0,!1,void 0,this)})()]},void 0,!0,void 0,this)}function t1($){return Array.from($.querySelectorAll(Q0))}function hJ({containerRef:$,hoveredBlock:J,focusedBlockIndex:Q,blockPopover:Y,blockAnnotationMap:q,activeAnnotationId:G,onOpen:X}){let[H,_]=q1([]);D1(()=>{let B=$.current;if(!B||q.size===0){_([]);return}let N=[];for(let P of B.querySelectorAll(S1)){let M=a$(P);if(M&&q.has(M))N.push(P)}_(N)},[q,$.current]);let[W,U]=q1(null);D1(()=>{if(!G||!$.current){U(null);return}for(let B of $.current.querySelectorAll(Q0)){let N=a$(B);if(N&&q.get(N)===G){U(B);return}}U(null)},[G,q]),D1(()=>{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 K=X2(()=>{if(Q===null||!$.current)return null;let B=t1($.current)[Q];if(!B)return null;return B.matches(S1)?B:null},[Q,$.current]),z=X2(()=>{let B=new Set(H);if(J)B.add(J);if(K)B.add(K);if(Y?.anchorEl)B.add(Y.anchorEl);return Array.from(B)},[H,J,K,Y]);return N$(cJ,{children:z.map((B)=>N$(uJ,{block:B,isHovered:B===J||B===K||B===Y?.anchorEl,blockAnnotationMap:q,activeAnnotationId:G,onOpen:X},B.getAttribute("data-task-id")||B.getAttribute("data-md-title")||B.textContent?.slice(0,30)||"block",!1,void 0,this))},void 0,!1,void 0,this)}function uJ({block:$,isHovered:J,blockAnnotationMap:Q,activeAnnotationId:Y,onOpen:q}){let G=a$($);if(!G)return null;let X=Q.get(G),H=!!X;return xJ(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 pJ({note:$,onSave:J,onCancel:Q}){let[Y,q]=d2.useState($),G=d2.useRef(null);return d2.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 E1,{useCallback as Z0,useEffect as d$,useLayoutEffect as O7,useMemo as P6,useRef as G1,useState as O$}from"react";import{createRoot as L7}from"react-dom/client";var lJ=500,dJ=1e4,s4=L.string().max(dJ),Z5=L.object({id:L.string().min(1).max(200),type:L.enum(["select","radio","checkbox","text","range"]),label:L.string().max(1000),value:L.union([s4,L.array(s4).max(500),L.number(),L.null()]),note:s4.optional()}),fW=L.array(Z5).max(lJ);function C5($){return $.flatMap((J)=>{let Q=Z5.safeParse(J);if(!Q.success)return[];let{value:Y,note:q,...G}=Q.data,X=Array.isArray(Y)?Y.length>0:typeof Y==="string"?Y.trim()!=="":Y!==null,H=q?.trim()??"";if(!X&&!H)return[];return[{...G,value:Y,...H?{note:H}:{}}]})}var R5=L.object({shareId:L.string(),url:L.string(),revision:L.number(),createdAt:L.string(),ownerToken:L.string().optional(),expiresAt:L.string().optional(),lastFeedbackAt:L.string().optional(),encryptionKey:L.string().optional()}),rJ=L.object({revision:L.number(),label:L.string().optional(),canvasFiles:L.array(L.object({filename:L.string(),diffStats:L.object({added:L.number(),removed:L.number()}).optional()})),createdAt:L.string(),hasFeedback:L.boolean(),feedbackConsumed:L.boolean(),response:L.string().optional()}).passthrough(),I5=L.object({encryption:L.object({alg:L.literal("AES-GCM"),v:L.literal(1)}).optional(),origin:L.object({sessionId:L.string().optional(),label:L.string().optional(),revision:L.number().optional(),createdAt:L.string().optional()}).optional(),currentRevision:L.number().optional(),revisions:L.array(rJ).optional(),canvasFiles:L.array(L.string()).optional(),projectRoot:L.string().optional(),shares:L.array(R5).optional(),shareEnabled:L.boolean().optional()}).passthrough(),t4=L.object({entries:L.array(L.object({name:L.string(),type:L.enum(["file","dir"])}))}),iJ=L.object({id:L.string(),shareId:L.string(),revision:L.number(),submittedAt:L.string(),author:M4,annotations:L.array(O4.omit({source:!0,author:!0})),generalNote:L.string().optional()}),D5=L.object({entries:L.array(iJ)}),k5=L.union([L.object({ok:L.literal(!0),share:R5}),L.object({ok:L.literal(!1).optional(),error:L.string().optional()})]),y5=L.union([L.object({ok:L.literal(!0)}),L.object({ok:L.literal(!1).optional(),error:L.string().optional()})]);var E5={alg:"AES-GCM",v:1};async function f5($){let J=aJ($);return crypto.subtle.importKey("raw",J,{name:"AES-GCM",length:256},!1,["encrypt","decrypt"])}async function B1($,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),oJ(G)}async function G2($,J){let Q=v5(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 oJ($){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 v5($){let J=atob($),Q=new Uint8Array(J.length);for(let Y=0;Y<J.length;Y++)Q[Y]=J.charCodeAt(Y);return Q}function aJ($){let J=$.replace(/-/g,"+").replace(/_/g,"/")+"===".slice(($.length+3)%4);return v5(J)}function nJ(){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 sJ(){if(typeof window<"u"&&window.__CANVAS_SHARE__?.shareId){let J=nJ();return{isShared:!0,shareId:window.__CANVAS_SHARE__.shareId,encryptionKey:J?f5(J):null}}return{isShared:!1,sessionId:typeof window<"u"?window.location.pathname.replace("/s/",""):""}}var K$=sJ();function tJ(){return K$.isShared&&K$.encryptionKey!==null}function eJ(){return K$.isShared?K$.shareId:K$.sessionId}function $Q(){if(K$.isShared)return`/s/${K$.shareId}/meta`;return`/api/session/${K$.sessionId}/meta`}function JQ($,J){let Q=$.replace(/\.jsx$/,".js");if(K$.isShared)return`/s/${K$.shareId}/canvas/${encodeURIComponent(Q)}`;let Y=J?`?rev=${J}&t=${Date.now()}`:`?t=${Date.now()}`;return`/api/session/${K$.sessionId}/canvas/${encodeURIComponent(Q)}${Y}`}function QQ(){if(K$.isShared)return`/s/${K$.shareId}/upload`;return`/api/session/${K$.sessionId}/upload`}async function g5(){let $=await fetch($Q());if(!$.ok)throw Error(`meta ${$.status}`);let J=I5.parse(await $.json());if(J.encryption&&K$.isShared&&K$.encryptionKey){let Q=await K$.encryptionKey;if(J.origin){let Y={...J.origin};if(Y.sessionId)Y.sessionId=await G2(Q,Y.sessionId);if(Y.label)Y.label=await G2(Q,Y.label);J.origin=Y}for(let Y of J.revisions??[])if(Y.label)try{Y.label=await G2(Q,Y.label)}catch{}}return J}var qQ=async($,J)=>{let Q=JQ($,J);if(!tJ())return import(Q);let Y=await fetch(Q);if(!Y.ok)throw Error(`canvas ${Y.status}`);let q=await Y.text(),G=await K$.encryptionKey,X=await G2(G,q),H=new Blob([X],{type:"application/javascript"}),_=URL.createObjectURL(H);try{return await import(_)}finally{setTimeout(()=>URL.revokeObjectURL(_),0)}},m5="canvas-reviewer-identity";function e4(){try{let $=localStorage.getItem(m5);if(!$)return null;return JSON.parse($)}catch{return null}}function x5($){let J=e4();if(!J)J={id:crypto.randomUUID?.()||String(Date.now()),name:$};else J.name=$;return localStorage.setItem(m5,JSON.stringify(J)),J}async function YQ($,J){let Q=await Promise.all($.annotations.map(async(Y)=>{let q={id:Y.id,createdAt:Y.createdAt,snippet:await B1(J,String(Y.snippet??"")),note:await B1(J,String(Y.note??""))};if(Y.filePath)q.filePath=await B1(J,String(Y.filePath));if(Y.canvasFile)q.canvasFile=await B1(J,String(Y.canvasFile));if(Y.context!==void 0&&Y.context!==null)q.context=await B1(J,JSON.stringify(Y.context));if(Y.attachments)q.attachments=Y.attachments;return q}));return{author:{id:$.author.id,name:await B1(J,$.author.name)},revision:$.revision,annotations:Q,...$.generalNote?{generalNote:await B1(J,$.generalNote)}:{},...$.responses&&$.responses.length>0?{responses:await B1(J,JSON.stringify($.responses))}:{},encryption:E5}}async function h5($){if(!K$.isShared)throw Error("submitSharedFeedback called outside shared mode");let J=$;if(K$.encryptionKey){let Y=await K$.encryptionKey;J=await YQ($,Y)}let Q=await fetch(`/s/${K$.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 z1=!K$.isShared,u5=!K$.isShared,p5={get sessionId(){return eJ()},isShared:K$.isShared,fsAvailable:z1,uploadUrl:QQ,loadCanvasModule:qQ};import $6,{useCallback as J6,useContext as SQ,useEffect as y1,useMemo as a2,useRef as N1,useState as V$}from"react";function k1($,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 c5($){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 $3($,J){if($.length>5000||J.length>5000)return XQ($,J);return r5($,J)}function r5($,J){let Q=r2($,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 r2($,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 k1($,J);let q=Math.floor(Q/2),G=$.slice(0,q),X=$.slice(q),H=l5(G,J),_=l5([...X].reverse(),[...J].reverse()),W=0,U=0;for(let B=0;B<=Y;B++){let N=H[B]+_[Y-B];if(N>W)W=N,U=B}let K=J.slice(0,U),z=J.slice(U);return[...r2(G,K),...r2(X,z)]}function l5($,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 XQ($,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),_=r2(X,H),W=[],U=[],K=0,z=0,B=0;while(K<q.length||z<G.length)if(B<_.length&&K<q.length&&z<G.length&&X[K]===_[B]&&H[z]===_[B]){for(let N=q[K].start;N<q[K].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});K++,z++,B++}else if(K<q.length&&(B>=_.length||X[K]!==_[B]))if(z<G.length&&(B>=_.length||H[z]!==_[B])){let N=r5($.slice(q[K].start,q[K].end),J.slice(G[z].start,G[z].end));for(let P of N.oldOps)W.push({type:P.type,index:P.index+q[K].start});for(let P of N.newOps)U.push({type:P.type,index:P.index+G[z].start});K++,z++}else{for(let N=q[K].start;N<q[K].end;N++)W.push({type:"removed",index:N});K++}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 d5($,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((K,z)=>K.offset-z.offset);let H=[];for(let K of G){let z=H[H.length-1];if(z&&K.offset<=z.offset+z.length)z.length=Math.max(z.length,K.offset+K.length-z.offset);else H.push({...K})}let _=q.parentNode,W=document.createDocumentFragment(),U=0;for(let K of H){if(K.offset>U)W.appendChild(document.createTextNode(X.slice(U,K.offset)));let z=document.createElement("span");z.className=Q,z.textContent=X.slice(K.offset,K.offset+K.length),W.appendChild(z),U=K.offset+K.length}if(U<X.length)W.appendChild(document.createTextNode(X.slice(U)));_.replaceChild(W,q)}}function i2($,J){let Q=GQ($,J),Y=c5($),q=c5(J),{oldOps:G,newOps:X}=$3(Y.words,q.words),H=G.some((_)=>_.type==="removed")||X.some((_)=>_.type==="added");return d5(G,Y.map,"diff-removed"),d5(X,q.map,"diff-added"),H||Q}function GQ($,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 K=W.split(`
70
- `),z=U.split(`
71
- `),B=k1(K,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 A=0,w=0;while(w<P.length){let S=document.createElement("div");if(S.className="px-3 py-0.5 whitespace-pre-wrap",A<M.length&&P[w]===M[A])S.textContent=" "+P[w],w++,A++;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(K,B,"old")),_.appendChild(N(z,B,"new"))}return q}import{useContext as _Q,useEffect as HQ,useRef as WQ,useState as UQ}from"react";import{jsxDEV as k$,Fragment as i5}from"react/jsx-dev-runtime";function KQ($){return $.label||`Round ${$.revision}`}function BQ($){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 _2({value:$,onChange:J,accent:Q="default",className:Y}){let{currentRevision:q,revisions:G}=_Q(f$),[X,H]=UQ(!1),_=WQ(null);HQ(()=>{if(!X)return;let K=(z)=>{if(_.current&&!_.current.contains(z.target))H(!1)};return document.addEventListener("mousedown",K),()=>document.removeEventListener("mousedown",K)},[X]);let W=G.find((K)=>K.revision===$);return k$("div",{className:"relative",ref:_,children:[k$("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?KQ(W):`Round ${$}`,k$("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",className:`text-text-tertiary transition-transform duration-200 ${X?"rotate-180":""}`,children:k$("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&&k$("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((K)=>k$("button",{onClick:()=>{J(K.revision),H(!1)},className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] font-body transition-colors ${K.revision===$?"bg-bg-surface text-text-primary":"text-text-secondary hover:bg-bg-surface hover:text-text-primary"}`,children:[k$("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${K.revision===q?"bg-accent-green":K.hasFeedback?"bg-accent-amber":"bg-border-hover"}`},void 0,!1,void 0,this),k$("span",{className:"flex-1 text-left truncate",children:K.label?k$(i5,{children:[K.label," ",k$("span",{className:"text-text-tertiary",children:["#",K.revision]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):k$(i5,{children:["Round ",K.revision]},void 0,!0,void 0,this)},void 0,!1,void 0,this),k$("span",{className:"text-[10px] text-text-tertiary flex-shrink-0 flex items-center gap-1.5",children:[(()=>{let z=K.canvasFiles?.reduce((B,N)=>{if(N.diffStats)B.added+=N.diffStats.added,B.removed+=N.diffStats.removed;return B},{added:0,removed:0});if(z&&(z.added>0||z.removed>0))return k$("span",{className:"font-mono",children:[k$("span",{className:"text-accent-green",children:["+",z.added]},void 0,!0,void 0,this)," ",k$("span",{className:"text-accent-red",children:["-",z.removed]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);return null})(),K.revision===q?"current":K.hasFeedback?"sent":BQ(K.createdAt)]},void 0,!0,void 0,this)]},K.revision,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function V0($){let J=[],Q=$.querySelectorAll(":scope > [data-md]");for(let Y of Q)J.push(H2(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(H2(G))}}return J}function H2($){let J=$.getAttribute("data-md")||"unknown",Q=zQ($,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(H2(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(H2(q));else for(let q of $.querySelectorAll("[data-md]"))if(q.parentElement?.closest("[data-md]")===$)Y.push(H2(q));return{key:Q,type:J,element:$,children:Y}}function zQ($,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 W2($,J){let Q=$.map((W)=>W.key),Y=J.map((W)=>W.key),q=k1(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],K=W.children.length>0||U.children.length>0?W2(W.children,U.children):void 0;G.push({kind:"matched",oldBlock:W,newBlock:U,childMatches:K}),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 o2($){let J=document.createDocumentFragment(),Q=!1;for(let Y of $)if(Y.kind==="removed")Q=!0,J.appendChild(a5(Y.oldBlock.element));else if(Y.kind==="added")Q=!0,J.appendChild(NQ(Y.newBlock.element));else{let q=Y.newBlock.element.cloneNode(!0),G=Y.newBlock.type;if(G==="mermaid"){if(e5(Y.oldBlock.element,q))Q=!0}else if(Y.childMatches&&Y.childMatches.length>0&&(G==="table"||G==="checklist")){if(s5(q,Y.childMatches,G))Q=!0}else if(Y.childMatches&&Y.childMatches.length>0){if(n5(Y.oldBlock,q,Y.childMatches,G))Q=!0}else if(G==="markdown"){if(t5(Y.oldBlock.element,q))Q=!0}else if(e1(Y.oldBlock.element,q,!1))Q=!0;J.appendChild(q)}return{fragment:J,hasChanges:Q}}function a5($){let J=$.cloneNode(!0);return J.classList.add("diff-block-removed"),J.style.position="relative",J3(J,"Removed","var(--color-accent-red)"),J}function NQ($){let J=$.cloneNode(!0);return J.classList.add("diff-block-added"),J.style.position="relative",J3(J,"Added","var(--color-accent-green)"),J}function n5($,J,Q,Y){let q=!1,G=MQ($,J),X,H;if(Y==="section"){let _=$.element.querySelector(":scope > div:first-child"),W=J.querySelector(":scope > div:first-child");if(_&&W){if(e1(_,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(e5(_.oldBlock.element,W))q=!0}else if(_.childMatches&&_.childMatches.length>0&&(_.newBlock.type==="table"||_.newBlock.type==="checklist")){if(s5(W,_.childMatches,_.newBlock.type))q=!0}else if(_.childMatches&&_.childMatches.length>0){if(n5(_.oldBlock,W,_.childMatches,_.newBlock.type))q=!0}else if(_.newBlock.type==="markdown"){if(t5(_.oldBlock.element,W))q=!0}else if(e1(_.oldBlock.element,W,!1))q=!0}}else if(_.kind==="removed"){q=!0;let W=a5(_.oldBlock.element),U=LQ(Q,_,G.newMap),K=U?FQ(H,U):null;H.insertBefore(W,K)}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",J3(W,"Added","var(--color-accent-green)")}if(e1(X,H,!0))q=!0;return q}function s5($,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(e1(G.oldBlock.element,X,!1))q=!0;Y.appendChild(X)}return q}function MQ($,J){return{newMap:{get(Q){return OQ(J,Q)}}}}function OQ($,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 K=(U.textContent||"").slice(0,100),z=0;for(let B=0;B<Math.min(H.length,K.length);B++)if(H[B]===K[B])z++;if(z>W)W=z,_=U}return _}function LQ($,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 FQ($,J){let Q=J;while(Q&&Q.parentElement!==$)Q=Q.parentElement;return Q}function t5($,J){let Q=Array.from($.children),Y=Array.from(J.children);if(Q.length===0&&Y.length===0)return e1($,J,!1);let q=Q.map((z)=>z.tagName.toLowerCase()),G=Y.map((z)=>z.tagName.toLowerCase()),X=k1(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 K=!1;while(J.firstChild)J.removeChild(J.firstChild);for(let z of H)if(z.kind==="matched"){let B=(z.oldChild.textContent||"").match(/\S+/g)||[],N=(z.newChild.textContent||"").match(/\S+/g)||[],P=k1(B,N),M=Math.max(B.length,N.length);if((M>0?1-P.length/M:0)>0.5){K=!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(e1(z.oldChild,z.newChild,!1))K=!0;J.appendChild(z.newChild)}}else if(z.kind==="removed"){K=!0;let B=z.oldChild.cloneNode(!0);B.classList.add("diff-block-removed"),J.appendChild(B)}else K=!0,z.newChild.classList.add("diff-block-added"),J.appendChild(z.newChild);return K}function o5($,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 e1($,J,Q){let Y=o5($,Q),q=o5(J,Q);if(Y.words.length===0&&q.words.length===0)return!1;let{oldOps:G,newOps:X}=$3(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 K=new Map;for(let M=0;M<W.length&&M<U.length;M++)K.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?K.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?K.get(T)??null:null})}let B=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=B.get(T.node);if(!O)O=[],B.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([...B.keys(),...N.keys()]);for(let M of P)AQ(M,B.get(M)||[],N.get(M)||[]);return!0}function AQ($,J,Q){if(!$.parentNode)return;let Y=$.nodeValue||"";J.sort((U,K)=>U.start-K.start);let q=[];for(let U of J){let K=q[q.length-1];if(K&&U.start<=K.end)K.end=Math.max(K.end,U.end);else q.push({...U})}Q.sort((U,K)=>U.offset-K.offset);let G=$.parentNode,X=document.createDocumentFragment(),H=0,_=0,W=0;while(H<=Y.length){let U=_<q.length?q[_].start:1/0,K=W<Q.length?Q[W].offset:1/0,z=Math.min(U,K);if(z===1/0){if(H<Y.length)X.appendChild(document.createTextNode(Y.slice(H)));break}let B=Math.max(z,H);if(B>H)X.appendChild(document.createTextNode(Y.slice(H,B))),H=B;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 e5($,J){let Q=($.getAttribute("data-md-source")||"").trim(),Y=(J.getAttribute("data-md-source")||"").trim();if(Q===Y)return!1;let q=Q.split(`
68
+ `}tablecell($){let Q=this.parser.parseInline($.tokens),J=$.header?"th":"td";return($.align?`<${J} align="${$.align}">`:`<${J}>`)+Q+`</${J}>
69
+ `}strong({tokens:$}){return`<strong>${this.parser.parseInline($)}</strong>`}em({tokens:$}){return`<em>${this.parser.parseInline($)}</em>`}codespan({text:$}){return`<code>${Y1($,!0)}</code>`}br($){return"<br>"}del({tokens:$}){return`<del>${this.parser.parseInline($)}</del>`}link({href:$,title:Q,tokens:J}){let Y=this.parser.parseInline(J),q=A5($);if(q===null)return Y;$=q;let G='<a href="'+$+'"';return Q&&(G+=' title="'+Y1(Q)+'"'),G+=">"+Y+"</a>",G}image({href:$,title:Q,text:J,tokens:Y}){Y&&(J=this.parser.parseInline(Y,this.parser.textRenderer));let q=A5($);if(q===null)return Y1(J);$=q;let G=`<img src="${$}" alt="${Y1(J)}"`;return Q&&(G+=` title="${Y1(Q)}"`),G+=">",G}text($){return"tokens"in $&&$.tokens?this.parser.parseInline($.tokens):("escaped"in $)&&$.escaped?$.text:Y1($.text)}},s4=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 $}},o$=class ${options;renderer;textRenderer;constructor(Q){this.options=Q||e1,this.options.renderer=this.options.renderer||new l2,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new s4}static parse(Q,J){return new $(J).parse(Q)}static parseInline(Q,J){return new $(J).parseInline(Q)}parse(Q){this.renderer.parser=this;let J="";for(let Y=0;Y<Q.length;Y++){let q=Q[Y];if(this.options.extensions?.renderers?.[q.type]){let X=q,W=this.options.extensions.renderers[X.type].call({parser:this},X);if(W!==!1||!["space","hr","heading","code","table","blockquote","list","html","def","paragraph","text"].includes(X.type)){J+=W||"";continue}}let G=q;switch(G.type){case"space":{J+=this.renderer.space(G);break}case"hr":{J+=this.renderer.hr(G);break}case"heading":{J+=this.renderer.heading(G);break}case"code":{J+=this.renderer.code(G);break}case"table":{J+=this.renderer.table(G);break}case"blockquote":{J+=this.renderer.blockquote(G);break}case"list":{J+=this.renderer.list(G);break}case"checkbox":{J+=this.renderer.checkbox(G);break}case"html":{J+=this.renderer.html(G);break}case"def":{J+=this.renderer.def(G);break}case"paragraph":{J+=this.renderer.paragraph(G);break}case"text":{J+=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 J}parseInline(Q,J=this.renderer){this.renderer.parser=this;let Y="";for(let q=0;q<Q.length;q++){let G=Q[q];if(this.options.extensions?.renderers?.[G.type]){let W=this.options.extensions.renderers[G.type].call({parser:this},G);if(W!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(G.type)){Y+=W||"";continue}}let X=G;switch(X.type){case"escape":{Y+=J.text(X);break}case"html":{Y+=J.html(X);break}case"link":{Y+=J.link(X);break}case"image":{Y+=J.image(X);break}case"checkbox":{Y+=J.checkbox(X);break}case"strong":{Y+=J.strong(X);break}case"em":{Y+=J.em(X);break}case"codespan":{Y+=J.codespan(X);break}case"br":{Y+=J.br(X);break}case"del":{Y+=J.del(X);break}case"text":{Y+=J.text(X);break}default:{let W='Token with "'+X.type+'" type was not found.';if(this.options.silent)return console.error(W),"";throw Error(W)}}}return Y}},X2=class{options;block;constructor($){this.options=$||e1}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 $?i$.lex:i$.lexInline}provideParser($=this.block){return $?o$.parse:o$.parseInline}},t4=class{defaults=c4();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=o$;Renderer=l2;TextRenderer=s4;Lexer=i$;Tokenizer=c2;Hooks=X2;constructor(...$){this.use(...$)}walkTokens($,Q){let J=[];for(let Y of $)switch(J=J.concat(Q.call(this,Y)),Y.type){case"table":{let q=Y;for(let G of q.header)J=J.concat(this.walkTokens(G.tokens,Q));for(let G of q.rows)for(let X of G)J=J.concat(this.walkTokens(X.tokens,Q));break}case"list":{let q=Y;J=J.concat(this.walkTokens(q.items,Q));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);J=J.concat(this.walkTokens(X,Q))}):q.tokens&&(J=J.concat(this.walkTokens(q.tokens,Q)))}}return J}use(...$){let Q=this.defaults.extensions||{renderers:{},childTokens:{}};return $.forEach((J)=>{let Y={...J};if(Y.async=this.defaults.async||Y.async||!1,J.extensions&&(J.extensions.forEach((q)=>{if(!q.name)throw Error("extension name required");if("renderer"in q){let G=Q.renderers[q.name];G?Q.renderers[q.name]=function(...X){let W=q.renderer.apply(this,X);return W===!1&&(W=G.apply(this,X)),W}:Q.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=Q[q.level];G?G.unshift(q.tokenizer):Q[q.level]=[q.tokenizer],q.start&&(q.level==="block"?Q.startBlock?Q.startBlock.push(q.start):Q.startBlock=[q.start]:q.level==="inline"&&(Q.startInline?Q.startInline.push(q.start):Q.startInline=[q.start]))}"childTokens"in q&&q.childTokens&&(Q.childTokens[q.name]=q.childTokens)}),Y.extensions=Q),J.renderer){let q=this.defaults.renderer||new l2(this.defaults);for(let G in J.renderer){if(!(G in q))throw Error(`renderer '${G}' does not exist`);if(["options","parser"].includes(G))continue;let X=G,W=J.renderer[X],_=q[X];q[X]=(...H)=>{let U=W.apply(q,H);return U===!1&&(U=_.apply(q,H)),U||""}}Y.renderer=q}if(J.tokenizer){let q=this.defaults.tokenizer||new c2(this.defaults);for(let G in J.tokenizer){if(!(G in q))throw Error(`tokenizer '${G}' does not exist`);if(["options","rules","lexer"].includes(G))continue;let X=G,W=J.tokenizer[X],_=q[X];q[X]=(...H)=>{let U=W.apply(q,H);return U===!1&&(U=_.apply(q,H)),U}}Y.tokenizer=q}if(J.hooks){let q=this.defaults.hooks||new X2;for(let G in J.hooks){if(!(G in q))throw Error(`hook '${G}' does not exist`);if(["options","block"].includes(G))continue;let X=G,W=J.hooks[X],_=q[X];X2.passThroughHooks.has(G)?q[X]=(H)=>{if(this.defaults.async&&X2.passThroughHooksRespectAsync.has(G))return(async()=>{let K=await W.call(q,H);return _.call(q,K)})();let U=W.call(q,H);return _.call(q,U)}:q[X]=(...H)=>{if(this.defaults.async)return(async()=>{let K=await W.apply(q,H);return K===!1&&(K=await _.apply(q,H)),K})();let U=W.apply(q,H);return U===!1&&(U=_.apply(q,H)),U}}Y.hooks=q}if(J.walkTokens){let q=this.defaults.walkTokens,G=J.walkTokens;Y.walkTokens=function(X){let W=[];return W.push(G.call(this,X)),q&&(W=W.concat(q.call(this,X))),W}}this.defaults={...this.defaults,...Y}}),this}setOptions($){return this.defaults={...this.defaults,...$},this}lexer($,Q){return i$.lex($,Q??this.defaults)}parser($,Q){return o$.parse($,Q??this.defaults)}parseMarkdown($){return(Q,J)=>{let Y={...J},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 Q>"u"||Q===null)return G(Error("marked(): input parameter is undefined or null"));if(typeof Q!="string")return G(Error("marked(): input parameter is of type "+Object.prototype.toString.call(Q)+", string expected"));if(q.hooks&&(q.hooks.options=q,q.hooks.block=$),q.async)return(async()=>{let X=q.hooks?await q.hooks.preprocess(Q):Q,W=await(q.hooks?await q.hooks.provideLexer($):$?i$.lex:i$.lexInline)(X,q),_=q.hooks?await q.hooks.processAllTokens(W):W;q.walkTokens&&await Promise.all(this.walkTokens(_,q.walkTokens));let H=await(q.hooks?await q.hooks.provideParser($):$?o$.parse:o$.parseInline)(_,q);return q.hooks?await q.hooks.postprocess(H):H})().catch(G);try{q.hooks&&(Q=q.hooks.preprocess(Q));let X=(q.hooks?q.hooks.provideLexer($):$?i$.lex:i$.lexInline)(Q,q);q.hooks&&(X=q.hooks.processAllTokens(X)),q.walkTokens&&this.walkTokens(X,q.walkTokens);let W=(q.hooks?q.hooks.provideParser($):$?o$.parse:o$.parseInline)(X,q);return q.hooks&&(W=q.hooks.postprocess(W)),W}catch(X){return G(X)}}}onError($,Q){return(J)=>{if(J.message+=`
70
+ Please report this to https://github.com/markedjs/marked.`,$){let Y="<p>An error occurred:</p><pre>"+Y1(J.message+"",!0)+"</pre>";return Q?Promise.resolve(Y):Y}if(Q)return Promise.reject(J);throw J}}},t1=new t4;function K$($,Q){return t1.parse($,Q)}K$.options=K$.setOptions=function($){return t1.setOptions($),K$.defaults=t1.defaults,w5(K$.defaults),K$};K$.getDefaults=c4;K$.defaults=e1;K$.use=function(...$){return t1.use(...$),K$.defaults=t1.defaults,w5(K$.defaults),K$};K$.walkTokens=function($,Q){return t1.walkTokens($,Q)};K$.parseInline=t1.parseInline;K$.Parser=o$;K$.parser=o$.parse;K$.Renderer=l2;K$.TextRenderer=s4;K$.Lexer=i$;K$.lexer=i$.lex;K$.Tokenizer=c2;K$.Hooks=X2;K$.parse=K$;var{options:wG,setOptions:TG,use:jG,walkTokens:bG,parseInline:ZG}=K$;var VG=o$.parse,CG=i$.lex;import{useEffect as k5,useMemo as e4,useRef as sQ,useState as _2}from"react";import{jsxDEV as S$}from"react/jsx-dev-runtime";function $3({open:$,onClose:Q,onSubmit:J,includedRemoteIds:Y,onToggleRemoteId:q}){let{annotations:G,generalNote:X,submittableResponses:W,feedbackEntries:_}=a1(),H=v$().threads!==null,[U,K]=_2(""),[N,O]=_2(!1),[M,L]=_2(!1),[F,w]=_2(null),z=sQ(null),[A,T]=_2(!1),S=e4(()=>G.filter((V)=>V.source==="remote"),[G]);if($&&!A)O(!1),L(!1),w(null);if(!$&&A)O(!1),L(!1),w(null);if($!==A)T($);let j=e4(()=>e0(G,X,W,_,Y,{annotationIds:H}),[G,X,W,_,Y,H]),Z=N?U:j;if(k5(()=>{if($&&M&&z.current)z.current.focus()},[$,M]),k5(()=>{if(!$)return;let V=(C)=>{if(C.key==="Escape")Q()};return window.addEventListener("keydown",V),()=>window.removeEventListener("keydown",V)},[$,Q]),!$)return null;let y=Z.trim().length>0;return S$("div",{className:"fixed inset-0 z-50 bg-black/50 backdrop-blur-sm flex items-center justify-center p-8",onClick:Q,children:S$("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:(V)=>V.stopPropagation(),children:[S$("div",{className:"flex items-center justify-between px-5 py-3 border-b border-border-subtle flex-shrink-0",children:[S$("div",{className:"flex items-center gap-3",children:[S$("span",{className:"text-[13px] font-medium text-text-primary font-body",children:"Response preview"},void 0,!1,void 0,this),N&&S$("button",{onClick:()=>{O(!1),L(!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),S$("div",{className:"flex items-center gap-2",children:[S$("div",{className:"flex items-center bg-bg-base rounded-md p-0.5",children:[S$("button",{onClick:()=>L(!1),className:`px-2.5 py-1 rounded text-[11px] font-body font-medium transition-colors ${!M?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:"Preview"},void 0,!1,void 0,this),S$("button",{onClick:()=>L(!0),className:`px-2.5 py-1 rounded text-[11px] font-body font-medium transition-colors ${M?"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),S$("button",{onClick:Q,className:"text-text-tertiary hover:text-text-secondary w-7 h-7 flex items-center justify-center rounded-md hover:bg-border-subtle transition-colors",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),M?S$("textarea",{ref:z,value:Z,onChange:(V)=>{K(V.currentTarget.value),O(!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):S$("div",{className:"flex-1 overflow-y-auto p-5",children:S$(V0,{text:Z},void 0,!1,void 0,this)},void 0,!1,void 0,this),S.length>0&&S$("div",{className:"px-5 py-2 border-t border-border-subtle flex-shrink-0",children:S$("span",{className:"text-[12px] text-text-secondary font-body",children:["Reviewer feedback: ",Y.size,"/",S.length," included"]},void 0,!0,void 0,this)},void 0,!1,void 0,this),F&&S$("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:[S$("span",{children:F},void 0,!1,void 0,this),S$("button",{onClick:()=>{w(null),J(Z)},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),S$("div",{className:"flex justify-end gap-2 px-5 py-3 border-t border-border-subtle flex-shrink-0",children:[S$("button",{onClick:Q,className:"px-4 py-2 rounded-lg text-[13px] font-body text-text-tertiary hover:text-text-secondary transition-colors",children:"Cancel"},void 0,!1,void 0,this),S$("button",{onClick:()=>{let V=Q2(W,_);if(V.length>0){w(`Please answer: ${V.join(", ")}`);return}w(null),J(Z)},disabled:!y,className:`px-6 py-2 rounded-lg font-body text-[13px] font-medium transition-all ${y?"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 tQ=/!\[([^\]]*)\]\((\/tmp\/agent-canvas\/uploads\/([^)]+))\)/g;function eQ($){return $.replace(tQ,(Q,J,Y,q)=>`![${J}](/api/uploads/${q})`)}var E5={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},Z0=($)=>$.replace(/[&<>"']/g,(Q)=>E5[Q]??Q),$J=($)=>$.replace(/&(?!#?\w+;)|[<>"']/g,(Q)=>E5[Q]??Q),y5=($)=>/^(?:https?|mailto):/i.test($)||!/^[^/?#]*:/.test($),f5=($)=>$?` title="${Z0($)}"`:"",QJ=new t4({renderer:{html:({text:$})=>Z0($),text($){return"tokens"in $&&$.tokens?this.parser.parseInline($.tokens):$J($.text)},link($){let Q=this.parser.parseInline($.tokens);return y5($.href)?`<a href="${Z0($.href)}"${f5($.title)}>${Q}</a>`:Q},image:($)=>y5($.href)?`<img src="${Z0($.href)}" alt="${Z0($.text)}"${f5($.title)}>`:Z0($.text)}});function i2($){return QJ.parse($,{async:!1})}function V0({text:$}){let Q=e4(()=>i2(eQ($)),[$]);return S$("div",{className:"prose-canvas font-body text-body text-text-primary leading-relaxed",dangerouslySetInnerHTML:{__html:Q}},void 0,!1,void 0,this)}import{useId as JJ,useState as Q3,useSyncExternalStore as qJ}from"react";import{jsxDEV as w$}from"react/jsx-dev-runtime";var YJ=[],XJ=()=>()=>{},GJ=()=>YJ;function _J(){let $=v$().threads;return qJ($?.subscribe??XJ,$?.current??GJ)}var WJ={open:"Answered",queued:"Reply sent",working:"Agent is on it",resolved:"Resolved"};function J3(){let $=v$().threads,Q=_J(),[J,Y]=Q3(()=>new Map),q=(W,_)=>Y((H)=>new Map(H).set(W,_));if($===null||Q.length===0)return null;let G=Q.filter((W)=>W.state!=="resolved"),X=Q.filter((W)=>W.state==="resolved");return w$("section",{"aria-label":"Threads",className:"px-3 pt-1 pb-3 border-b border-border-subtle",children:[w$("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary font-body px-1 mb-1",children:"Threads"},void 0,!1,void 0,this),G.map((W)=>w$(v5,{thread:W,store:$,draft:J.get(W.id)??"",onDraft:(_)=>q(W.id,_)},W.id,!1,void 0,this)),X.length>0&&w$("details",{className:"mt-1",children:[w$("summary",{className:"text-[11px] text-text-tertiary font-body px-1 cursor-pointer",children:["Resolved (",X.length,")"]},void 0,!0,void 0,this),X.map((W)=>w$(v5,{thread:W,store:$,draft:J.get(W.id)??"",onDraft:(_)=>q(W.id,_)},W.id,!1,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function v5({thread:$,store:Q,draft:J,onDraft:Y}){let q=JJ(),[G,X]=Q3(null),[W,_]=Q3(!1),H=async(N)=>{_(!0),X(null);try{await N()}catch(O){X(O instanceof Error?O.message:String(O))}finally{_(!1)}},U=()=>H(async()=>{await Q.reply($.id,J.trim()),Y("")}),K=$.filePath===g$?"Agent response":$.filePath??$.canvasFile?.replace(/\.jsx$/,"");return w$("article",{className:"rounded-lg border border-border-subtle bg-bg-elevated px-3 py-2 mt-2","data-thread-id":$.id,children:[w$("div",{className:"flex items-center justify-between gap-2 text-[11px] text-text-tertiary font-body",children:[w$("span",{className:"truncate",children:[K?`${K} · `:"","Round ",$.revision]},void 0,!0,void 0,this),w$("span",{children:WJ[$.state]},void 0,!1,void 0,this)]},void 0,!0,void 0,this),$.snippet.trim()&&w$("blockquote",{className:"mt-1 border-l-2 border-border-medium pl-2 text-[12px] text-text-secondary font-body line-clamp-3",children:$.snippet},void 0,!1,void 0,this),w$("ol",{className:"mt-2 space-y-2",children:$.comments.map((N)=>w$("li",{className:"text-[13px] font-body",children:[w$("div",{className:"text-[10px] uppercase tracking-widest text-text-tertiary",children:N.author==="agent"?"Agent":"You"},void 0,!1,void 0,this),N.author==="agent"?w$(V0,{text:N.body},void 0,!1,void 0,this):w$("p",{className:"whitespace-pre-wrap text-text-primary",children:N.body},void 0,!1,void 0,this)]},N.id,!0,void 0,this))},void 0,!1,void 0,this),w$("label",{className:"sr-only",htmlFor:q,children:"Reply"},void 0,!1,void 0,this),w$("textarea",{id:q,value:J,onInput:(N)=>Y(N.currentTarget.value),placeholder:"Reply to the agent",rows:2,className:"mt-2 w-full rounded-md bg-bg-input px-2 py-1.5 text-[13px] font-body text-text-primary"},void 0,!1,void 0,this),G&&w$("p",{role:"alert",className:"text-[12px] text-accent-red font-body",children:G},void 0,!1,void 0,this),w$("div",{className:"mt-1 flex justify-end gap-2",children:[w$("button",{type:"button",disabled:W,onClick:()=>H(()=>Q.setResolved($.id,$.state!=="resolved")),className:"px-2.5 py-1 rounded text-[12px] font-body text-text-secondary hover:text-text-primary",children:$.state==="resolved"?"Reopen":"Resolve"},void 0,!1,void 0,this),w$("button",{type:"button",disabled:W||J.trim()==="",onClick:U,className:"px-2.5 py-1 rounded text-[12px] font-body font-medium bg-btn-primary text-btn-primary-text disabled:opacity-50",children:"Send"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}import{jsxDEV as E,Fragment as o2}from"react/jsx-dev-runtime";function a2({onSubmit:$,collapseButton:Q}){let{isReadOnly:J,selectedRevision:Y,currentRevision:q,revisions:G,agentWatching:X}=Y3(h$),W=Y3(HJ),_=G.find((N)=>N.revision===Y),H=J&&Y===q,U=!!_?.feedbackConsumed,K=_?.label||`Round ${Y}`;if(J)return E(BJ,{sessionId:W,revision:Y,label:K,waitingForUpdate:H,feedbackConsumed:U,agentWatching:X,collapseButton:Q},void 0,!1,void 0,this);return E(OJ,{onSubmit:$,agentWatching:X,collapseButton:Q},void 0,!1,void 0,this)}function KJ({sessionId:$,revision:Q,label:J,waitingForUpdate:Y,feedbackConsumed:q,agentWatching:G,collapseButton:X}){let _=v$().isShared;return E("div",{className:"flex flex-col h-full",children:[E("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[E("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:Y?"Feedback sent":`Feedback — ${J}`},void 0,!1,void 0,this),X]},void 0,!0,void 0,this),Y&&!_&&E(x5,{feedbackConsumed:q,agentWatching:G},void 0,!1,void 0,this),E(h5,{sessionId:$,revision:Q},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function x5({feedbackConsumed:$,agentWatching:Q}){if($)return E("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:[E("span",{className:"w-2 h-2 rounded-full bg-accent-green animate-pulse"},void 0,!1,void 0,this),E("span",{className:"text-[12px] font-body text-accent-green",children:"Feedback received — waiting for next revision..."},void 0,!1,void 0,this)]},void 0,!0,void 0,this);if(Q)return E("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:[E("span",{className:"w-2 h-2 rounded-full bg-accent-blue animate-pulse"},void 0,!1,void 0,this),E("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 E("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:[E("span",{className:"w-2 h-2 rounded-full bg-accent-amber"},void 0,!1,void 0,this),E("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 BJ({sessionId:$,revision:Q,label:J,waitingForUpdate:Y,feedbackConsumed:q,agentWatching:G,collapseButton:X}){let{annotations:W,generalNote:_}=a1(),H=W.length>0||_.trim().length>0,[U,K]=C0("feedback");if(!H)return E(KJ,{sessionId:$,revision:Q,label:J,waitingForUpdate:Y,feedbackConsumed:q,agentWatching:G,collapseButton:X},void 0,!1,void 0,this);return E("div",{className:"flex flex-col h-full",children:[E("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[E("div",{className:"flex items-center gap-1 bg-bg-input rounded-md p-0.5",children:[E("button",{onClick:()=>K("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),E("button",{onClick:()=>K("annotations"),className:`px-2.5 py-1 rounded text-[11px] font-medium font-body transition-colors flex items-center gap-1.5 ${U==="annotations"?"bg-bg-elevated text-text-primary shadow-sm":"text-text-tertiary hover:text-text-secondary"}`,children:["Annotations",E("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:W.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&&E(x5,{feedbackConsumed:q,agentWatching:G},void 0,!1,void 0,this),U==="feedback"?E(h5,{sessionId:$,revision:Q},void 0,!1,void 0,this):E(o2,{children:[E("div",{className:"flex-1 overflow-y-auto",children:E(u5,{annotations:W,readOnly:!0},void 0,!1,void 0,this)},void 0,!1,void 0,this),_.trim()&&E("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:E("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 h5({sessionId:$,revision:Q}){let J=v$(),[Y,q]=C0(null),[G,X]=C0(!0);return m5(()=>{if(X(!0),!J.fsAvailable){q(null),X(!1);return}fetch(`/api/session/${$}/revision/${Q}/feedback`).then((W)=>W.json()).then((W)=>{q(K5.parse(W).feedback||null),X(!1)}).catch(()=>{q(null),X(!1)})},[$,Q]),E("div",{className:"flex-1 overflow-y-auto px-4",children:[E("div",{className:"-mx-4",children:E(J3,{},void 0,!1,void 0,this)},void 0,!1,void 0,this),G?E("p",{className:"text-[12px] text-text-tertiary font-body py-4",children:"Loading..."},void 0,!1,void 0,this):Y?E(V0,{text:Y},void 0,!1,void 0,this):E("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,!0,void 0,this)}function NJ($){let Q=$.filter((X)=>X.filePath===g$),J=$.filter((X)=>!X.filePath),Y=$.filter((X)=>c1(X)!==void 0),q={};for(let X of Y){let W=c1(X);if(!W)continue;let _=q[W];if(_)_.push(X);else q[W]=[X]}let G=[Q,J,Y].filter((X)=>X.length>0).length>1;return{response:Q,plan:J,fileGroups:q,hasMultipleGroups:G}}function g5({children:$}){return E("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 u5({annotations:$,readOnly:Q,includedRemoteIds:J,onToggleRemoteId:Y}){let{setActiveView:q}=Y3(q1),{response:G,plan:X,fileGroups:W,hasMultipleGroups:_}=NJ($),H=q3((N)=>{let O=c1(N);if(!O)return;q({type:"file",path:O}),setTimeout(()=>{let M=J2(N);if(M)M.scrollIntoView({behavior:"smooth",block:"center"})},150)},[q]),U=q3((N)=>u4(N,q),[q]),K={readOnly:Q,onSelect:H,onReveal:U,includedRemoteIds:J,onToggleRemoteId:Y};return E(o2,{children:[G.length>0&&E(o2,{children:[_&&E(g5,{children:"Agent Response"},void 0,!1,void 0,this),E(t0,{annotations:G,...K},void 0,!1,void 0,this)]},void 0,!0,void 0,this),X.length>0&&E(o2,{children:[_&&E(g5,{children:"Canvas"},void 0,!1,void 0,this),E(t0,{annotations:X,...K},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Object.entries(W).map(([N,O])=>E("div",{children:[E("button",{onClick:()=>q({type:"file",path:N}),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:N,children:[E(I1,{name:N.split("/").pop()||N,type:"file"},void 0,!1,void 0,this),E("span",{className:"truncate",children:N},void 0,!1,void 0,this)]},void 0,!0,void 0,this),E(t0,{annotations:O,...K},void 0,!1,void 0,this)]},N,!0,void 0,this))]},void 0,!0,void 0,this)}function OJ({onSubmit:$,agentWatching:Q,collapseButton:J}){let Y=v$(),[q,G]=C0(!1),{annotations:X,generalNote:W,submittableResponses:_,feedbackEntries:H}=a1(),U=UJ(()=>X.filter((j)=>j.source==="remote"),[X]),[K,N]=C0(()=>new Set);m5(()=>{if(U.length===0)return;N((j)=>{let Z=new Set(j);for(let y of U)Z.add(y.id);return Z.size===j.size?j:Z})},[U]);let O=q3((j)=>{N((Z)=>{let y=new Set(Z);if(y.has(j))y.delete(j);else y.add(j);return y})},[]),M=Array.from(_.values()).some($2),L=H.size>0,F=X.length>0||W.trim().length>0||M||L,[w,z]=C0(null),A=Y.threads!==null,T=(j)=>{let Z=A?X.filter((y)=>y.source!=="remote").map(zJ):[];$(j,Z,J5(_))},S=()=>{T(e0(X,W,_,H,K,{annotationIds:A}))};return E("div",{className:"flex flex-col h-full",children:[E("div",{className:"px-4 py-3 flex items-center justify-between flex-shrink-0",children:[E("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body flex items-center gap-2",children:["Annotations",X.length>0&&E("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&&E("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${Q?"bg-accent-green":"bg-accent-amber"}`,title:Q?"Agent connected":"Agent disconnected"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),J]},void 0,!0,void 0,this),E("div",{className:"flex-1 overflow-y-auto",children:[E(J3,{},void 0,!1,void 0,this),X.length===0&&E("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),E(u5,{annotations:X,includedRemoteIds:K,onToggleRemoteId:O},void 0,!1,void 0,this)]},void 0,!0,void 0,this),E(b4,{hasContent:F,onSubmit:()=>{let j=Q2(_,H);if(j.length>0){z(`Please answer: ${j.join(", ")}`);return}z(null),S()},onSubmitEmpty:()=>$("No feedback — looks good.",[],[]),notice:w&&E("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:[E("span",{children:w},void 0,!1,void 0,this),E("button",{onClick:()=>{z(null),S()},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:E("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),E($3,{open:q,onClose:()=>G(!1),onSubmit:T,includedRemoteIds:K,onToggleRemoteId:O},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function zJ($){return{id:$.id,snippet:$.snippet,note:$.note,canvasFile:$.canvasFile,filePath:$.filePath}}import{useFeedback as cH}from"#canvas/runtime";import B_ from"react";import{jsxDEV as O_}from"react/jsx-dev-runtime";K$.setOptions({gfm:!0,breaks:!1});import{jsxDEV as L_}from"react/jsx-dev-runtime";import{jsxDEV as S_}from"react/jsx-dev-runtime";import{useAnnotations as C_,useResponseRegistration as R_}from"#canvas/runtime";import{useEffect as I_,useMemo as k_,useRef as y_,useState as f_}from"react";import{jsxDEV as b_}from"react/jsx-dev-runtime";import{jsxDEV as g_}from"react/jsx-dev-runtime";import{useEffect as p_,useRef as c_}from"react";function W2(){return window.hljs}import{jsxDEV as r_}from"react/jsx-dev-runtime";import{jsxDEV as t_}from"react/jsx-dev-runtime";import{ActiveViewCtx as QW,SessionContext as JW}from"#canvas/runtime";import{useContext as YW,useEffect as XW,useRef as GW,useState as _W}from"react";import{jsxDEV as KW}from"react/jsx-dev-runtime";import{SessionContext as OW}from"#canvas/runtime";import{useContext as MW,useState as FW}from"react";import{jsxDEV as AW}from"react/jsx-dev-runtime";import{useMemo as jW}from"react";import{jsxDEV as ZW}from"react/jsx-dev-runtime";K$.setOptions({gfm:!0,breaks:!1});import{useAnnotations as DW,useCanvasFile as IW}from"#canvas/runtime";import{useCallback as EW,useEffect as vW,useRef as gW,useState as mW}from"react";import hW from"react-dom";import{jsxDEV as cW,Fragment as lW}from"react/jsx-dev-runtime";import{jsxDEV as oW}from"react/jsx-dev-runtime";import{jsxDEV as sW}from"react/jsx-dev-runtime";import{useState as QH}from"react";import{jsxDEV as YH}from"react/jsx-dev-runtime";import{jsxDEV as _H}from"react/jsx-dev-runtime";import{jsxDEV as KH}from"react/jsx-dev-runtime";import{useAnnotations as OH,useResponseRegistration as zH}from"#canvas/runtime";import{useRef as LH,useState as AH}from"react";import{jsxDEV as wH}from"react/jsx-dev-runtime";import{CanvasFileCtx as AJ,SessionContext as PJ}from"#canvas/runtime";import n2,{useContext as p5,useEffect as k1,useMemo as U2,useRef as SJ,useState as X1}from"react";import{createPortal as wJ}from"react-dom";import{createContext as LJ}from"react";var H2=LJ(()=>{});import{jsxDEV as O$,Fragment as ZJ}from"react/jsx-dev-runtime";class c5 extends n2.Component{state={error:null};static getDerivedStateFromError($){return{error:$}}componentDidCatch($,Q){this.props.reportError({revision:this.props.revision,filename:this.props.filename,message:$.message,...$.stack?{stack:$.stack}:{},...Q.componentStack?{componentStack:Q.componentStack}:{}})}render(){if(!this.state.error)return this.props.children;return O$(l5,{message:this.state.error.message},void 0,!1,void 0,this)}}function l5({message:$}){return O$("div",{className:"bg-accent-red-muted rounded-lg p-5",children:[O$("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Canvas render failed"},void 0,!1,void 0,this),O$("pre",{className:"text-code font-mono text-text-secondary whitespace-pre-wrap",children:$},void 0,!1,void 0,this),O$("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 R0({revision:$,filename:Q}){let J=p5(PJ),Y=v$(),q=p5(H2),[G,X]=X1(null),[W,_]=X1(null),[H,U]=X1(!0),K=SJ(null),{annotations:N,addAnnotationWithId:O,removeAnnotation:M,updateAnnotation:L,addAnnotationImage:F,removeAnnotationImage:w,activeAnnotationId:z,setActiveAnnotationId:A,registerCanvasRendered:T}=a1(),S=U2(()=>N.filter((g)=>!g.filePath&&(!g.canvasFile||g.canvasFile===Q)),[N,Q]),[j,Z]=X1(null),[y,V]=X1(null),[C,v]=X1(null),[h,o]=X1(null),[B$,a]=X1(!1);k1(()=>{U(!0),_(null),o(null),Y.loadCanvasModule(Q,$).then((g)=>{X(()=>g.default),U(!1)}).catch((g)=>{let c=g instanceof Error?g:Error(String(g));_(c.message),U(!1),q({revision:$,filename:Q,message:c.message,...c.stack?{stack:c.stack}:{}})})},[J,$,Q,q]),k1(()=>{if(G)T(Q)},[G,Q,T]);let U$=document.getElementById("plan-scroll-container"),{popovers:Y$,isPopoverOpen:N$}=R1({containerRef:K,restoreKey:G,restoreAnnotations:S,extractContext:(g)=>P1(g,K.current),canvasFile:Q,scrollContainer:U$}),{popovers:Q$,isDrawing:_$,isPopoverOpen:F$}=I4({containerRef:K,restoreKey:G,canvasFile:Q,scrollContainer:U$}),n=N$||F$,d=U2(()=>{let g=new Map;for(let c of S)if(c.snippet.startsWith("["))g.set(c.snippet,c.id);return g},[S]);k1(()=>{let g=K.current;if(!g)return;let c=(D)=>{if(C||n||_$)return;let x=D.target;if(x.closest("[data-block-comment-btn]"))return;a(!1);let r=x.closest(Y0);if(r&&g.contains(r)){let C$=$0(g).indexOf(r);o(C$>=0?C$:null)}else o(null);let z$=x.closest(S1);if(z$&&g.contains(z$)){V(z$);let L$=s$(z$),C$=L$?d.get(L$):void 0;if(C$&&C$!==z)A(C$)}else V(null)},f=(D)=>{if(C||n)return;if(D.relatedTarget?.closest("[data-block-comment-btn]"))return;V(null),A(null)};return g.addEventListener("mousemove",c),g.addEventListener("mouseleave",f),()=>{g.removeEventListener("mousemove",c),g.removeEventListener("mouseleave",f)}},[G,C,n,_$,d,z]),k1(()=>{let g=(c)=>{let f=c.target.tagName;if(f==="INPUT"||f==="TEXTAREA"||c.target.isContentEditable)return;if(C||n)return;let D=K.current;if(!D)return;if(c.key==="ArrowDown"){c.preventDefault(),a(!0);let x=$0(D);if(x.length===0)return;o((r)=>{if(r===null)return 0;return Math.min(r+1,x.length-1)})}else if(c.key==="ArrowUp"){c.preventDefault(),a(!0);let x=$0(D);if(x.length===0)return;o((r)=>{if(r===null)return x.length-1;return Math.max(r-1,0)})}else if(c.key==="a"||c.key==="A"){if(h===null||!D)return;let r=$0(D)[h];if(!r)return;if(!r.matches(S1))return;c.preventDefault();let z$=s$(r);if(!z$)return;let L$=d.get(z$);if(L$)A(L$),v({anchorEl:r,snippet:z$,annId:L$});else v({anchorEl:r,snippet:z$})}else if(c.key===" "||c.key==="Enter"){if(h===null)return;let r=$0(D)[h];if(!r)return;let z$=r.getAttribute("data-md");if(z$==="choice-option"||z$==="multichoice-option")c.preventDefault(),r.dispatchEvent(new CustomEvent("kb-select",{bubbles:!0}));else if(z$==="userinput"){c.preventDefault();let L$=r.querySelector("textarea");if(L$){L$.focus();let C$=(f$)=>{if(f$.key==="Escape")f$.preventDefault(),L$.blur(),a(!0)};L$.addEventListener("keydown",C$),L$.addEventListener("blur",()=>L$.removeEventListener("keydown",C$),{once:!0})}}else if(z$==="rangeinput"){c.preventDefault();let L$=r.querySelector("input[type='range']");if(L$){L$.focus();let C$=(f$)=>{if(f$.key==="Escape"||f$.key==="ArrowUp"||f$.key==="ArrowDown")f$.preventDefault(),L$.blur(),a(!0)};L$.addEventListener("keydown",C$),L$.addEventListener("blur",()=>L$.removeEventListener("keydown",C$),{once:!0})}}}else if(c.key==="Escape")o(null),a(!1),A(null)};return document.addEventListener("keydown",g),()=>document.removeEventListener("keydown",g)},[h,C,n,d]),k1(()=>{let g=K.current;if(!g||h===null||!B$)return;let f=$0(g)[h];if(!f)return;f.style.outline="2px solid var(--color-accent-blue)",f.style.outlineOffset="-2px",f.style.borderRadius="8px",f.scrollIntoView({block:"nearest",behavior:"smooth"});let D=s$(f),x=D?d.get(D):void 0;if(x)A(x);return()=>{f.style.outline="",f.style.outlineOffset="",f.style.borderRadius=""}},[h,B$,d]);let X$=U2(()=>G?O$(G,{},void 0,!1,void 0,this):null,[G]);if(H)return O$("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(W)return O$(l5,{message:W},void 0,!1,void 0,this);if(!G)return O$("div",{className:"text-text-tertiary text-center py-8 font-body text-body",children:"No canvas loaded"},void 0,!1,void 0,this);return O$(AJ.Provider,{value:Q,children:[O$("div",{ref:K,className:"plan-content plan-updated","data-canvas-file":Q,children:O$(c5,{revision:$,filename:Q,reportError:q,children:X$},`${$}:${Q}`,!1,void 0,this)},void 0,!1,void 0,this),j&&O$(bJ,{note:j.note,onSave:(g)=>{L(j.id,g),Z(null)},onCancel:()=>Z(null)},void 0,!1,void 0,this),Y$,Q$,O$(TJ,{containerRef:K,hoveredBlock:y,focusedBlockIndex:h,blockPopover:C,blockAnnotationMap:d,activeAnnotationId:z,onOpen:(g,c,f)=>{if(f)A(f),v({anchorEl:g,snippet:c,annId:f});else v({anchorEl:g,snippet:c})}},void 0,!1,void 0,this),C&&!C.annId&&O$(Q1,{anchorEl:C.anchorEl,scrollContainer:U$,snippet:C.snippet,truncateAt:80,onAdd:(g,c)=>{let f=x$();O(f,C.snippet,g,void 0,void 0,c,Q),v(null)},onCancel:()=>v(null)},void 0,!1,void 0,this),C?.annId&&(()=>{let g=S.find((c)=>c.id===C.annId);if(!g)return null;return O$(r1,{anchorEl:C.anchorEl,scrollContainer:U$,initialNote:g.note,initialImages:g.images,onUpdate:(c,f)=>{L(C.annId,c);let D=g.images||[];for(let x of f)if(!D.includes(x))F(C.annId,x);for(let x of D)if(!f.includes(x))w(C.annId,x)},onDelete:()=>{M(C.annId),A(null),v(null)},onClose:()=>v(null)},void 0,!1,void 0,this)})()]},void 0,!0,void 0,this)}function $0($){return Array.from($.querySelectorAll(Y0))}function TJ({containerRef:$,hoveredBlock:Q,focusedBlockIndex:J,blockPopover:Y,blockAnnotationMap:q,activeAnnotationId:G,onOpen:X}){let[W,_]=X1([]);k1(()=>{let O=$.current;if(!O||q.size===0){_([]);return}let M=[];for(let L of O.querySelectorAll(S1)){let F=s$(L);if(F&&q.has(F))M.push(L)}_(M)},[q,$.current]);let[H,U]=X1(null);k1(()=>{if(!G||!$.current){U(null);return}for(let O of $.current.querySelectorAll(Y0)){let M=s$(O);if(M&&q.get(M)===G){U(O);return}}U(null)},[G,q]),k1(()=>{if(!H)return;return H.style.boxShadow="inset 0 0 0 1.5px var(--color-highlight-bg)",H.style.borderRadius="8px",()=>{H.style.boxShadow="",H.style.borderRadius=""}},[H]);let K=U2(()=>{if(J===null||!$.current)return null;let O=$0($.current)[J];if(!O)return null;return O.matches(S1)?O:null},[J,$.current]),N=U2(()=>{let O=new Set(W);if(Q)O.add(Q);if(K)O.add(K);if(Y?.anchorEl)O.add(Y.anchorEl);return Array.from(O)},[W,Q,K,Y]);return O$(ZJ,{children:N.map((O)=>O$(jJ,{block:O,isHovered:O===Q||O===K||O===Y?.anchorEl,blockAnnotationMap:q,activeAnnotationId:G,onOpen:X},O.getAttribute("data-task-id")||O.getAttribute("data-md-title")||O.textContent?.slice(0,30)||"block",!1,void 0,this))},void 0,!1,void 0,this)}function jJ({block:$,isHovered:Q,blockAnnotationMap:J,activeAnnotationId:Y,onOpen:q}){let G=s$($);if(!G)return null;let X=J.get(G),W=!!X;return wJ(O$("button",{"data-block-comment-btn":!0,onClick:(H)=>{H.stopPropagation(),q(H.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 ${W?X===Y?"text-accent-amber bg-accent-amber-muted":"text-accent-amber opacity-60 hover:opacity-100":Q?"text-text-disabled hover:text-text-tertiary opacity-50 hover:opacity-100":"text-text-disabled opacity-0 group-hover/section:opacity-20 hover:!opacity-80"}`,title:W?"Edit annotation":"Add annotation",children:O$("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:W?"currentColor":"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:O$("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 bJ({note:$,onSave:Q,onCancel:J}){let[Y,q]=n2.useState($),G=n2.useRef(null);return n2.useEffect(()=>{G.current?.focus(),G.current?.select()},[]),O$("div",{className:"fixed inset-0 z-50 bg-black/40 flex items-center justify-center",onClick:J,children:O$("div",{className:"bg-bg-elevated border border-border-hover rounded-lg shadow-md p-4 w-80",onClick:(X)=>X.stopPropagation(),children:[O$("div",{className:"text-tiny uppercase tracking-widest text-text-tertiary font-body mb-2",children:"Edit annotation"},void 0,!1,void 0,this),O$("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))Q(Y.trim());if(X.key==="Escape")J()}},void 0,!1,void 0,this),O$("div",{className:"flex justify-end gap-2 mt-2",children:[O$("button",{onClick:J,className:"text-meta text-text-tertiary font-body px-3 py-1",children:"Cancel"},void 0,!1,void 0,this),O$("button",{onClick:()=>Q(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 v1,{useCallback as k0,useEffect as u$,useLayoutEffect as Bq,useMemo as o6,useRef as W1,useState as M$}from"react";import{createRoot as Nq}from"react-dom/client";var VJ=500,CJ=1e4,G3=B.string().max(CJ),d5=B.object({id:B.string().min(1).max(200),type:B.enum(["select","radio","checkbox","text","range"]),label:B.string().max(1000),value:B.union([G3,B.array(G3).max(500),B.number(),B.null()]),note:G3.optional()}),xU=B.array(d5).max(VJ);function r5($){return $.flatMap((Q)=>{let J=d5.safeParse(Q);if(!J.success)return[];let{value:Y,note:q,...G}=J.data,X=Array.isArray(Y)?Y.length>0:typeof Y==="string"?Y.trim()!=="":Y!==null,W=q?.trim()??"";if(!X&&!W)return[];return[{...G,value:Y,...W?{note:W}:{}}]})}var i5=B.object({shareId:B.string(),url:B.string(),revision:B.number(),createdAt:B.string(),ownerToken:B.string().optional(),expiresAt:B.string().optional(),lastFeedbackAt:B.string().optional(),encryptionKey:B.string().optional()}),RJ=B.object({revision:B.number(),label:B.string().optional(),canvasFiles:B.array(B.object({filename:B.string(),diffStats:B.object({added:B.number(),removed:B.number()}).optional()})),createdAt:B.string(),hasFeedback:B.boolean(),feedbackConsumed:B.boolean(),response:B.string().optional()}).passthrough(),o5=B.object({encryption:B.object({alg:B.literal("AES-GCM"),v:B.literal(1)}).optional(),origin:B.object({sessionId:B.string().optional(),label:B.string().optional(),revision:B.number().optional(),createdAt:B.string().optional()}).optional(),currentRevision:B.number().optional(),revisions:B.array(RJ).optional(),canvasFiles:B.array(B.string()).optional(),projectRoot:B.string().optional(),shares:B.array(i5).optional(),shareEnabled:B.boolean().optional()}).passthrough(),_3=B.object({entries:B.array(B.object({name:B.string(),type:B.enum(["file","dir"])}))}),DJ=B.object({id:B.string(),shareId:B.string(),revision:B.number(),submittedAt:B.string(),author:S4,annotations:B.array(w4.omit({source:!0,author:!0})),generalNote:B.string().optional()}),a5=B.object({entries:B.array(DJ)}),n5=B.union([B.object({ok:B.literal(!0),share:i5}),B.object({ok:B.literal(!1).optional(),error:B.string().optional()})]),s5=B.union([B.object({ok:B.literal(!0)}),B.object({ok:B.literal(!1).optional(),error:B.string().optional()})]);var IJ=B.object({id:B.string(),name:B.string(),path:B.string(),size:B.number().int()});var t5={alg:"AES-GCM",v:1};async function e5($){let Q=yJ($);return crypto.subtle.importKey("raw",Q,{name:"AES-GCM",length:256},!1,["encrypt","decrypt"])}async function N1($,Q){let J=crypto.getRandomValues(new Uint8Array(12)),Y=new TextEncoder().encode(Q),q=await crypto.subtle.encrypt({name:"AES-GCM",iv:J},$,Y),G=new Uint8Array(J.byteLength+q.byteLength);return G.set(J,0),G.set(new Uint8Array(q),J.byteLength),kJ(G)}async function K2($,Q){let J=$6(Q);if(J.byteLength<28)throw Error("Ciphertext too short");let Y=J.subarray(0,12),q=J.subarray(12),G=await crypto.subtle.decrypt({name:"AES-GCM",iv:Y},$,q);return new TextDecoder().decode(G)}function kJ($){let Q="",J=32768;for(let Y=0;Y<$.byteLength;Y+=J)Q+=String.fromCharCode.apply(null,Array.from($.subarray(Y,Y+J)));return btoa(Q)}function $6($){let Q=atob($),J=new Uint8Array(Q.length);for(let Y=0;Y<Q.length;Y++)J[Y]=Q.charCodeAt(Y);return J}function yJ($){let Q=$.replace(/-/g,"+").replace(/_/g,"/")+"===".slice(($.length+3)%4);return $6(Q)}function fJ($){let Q;try{Q=new URL($)}catch{return!1}if(Q.protocol!=="http:"&&Q.protocol!=="https:")return!1;return Q.hostname==="localhost"||Q.hostname==="127.0.0.1"||Q.hostname==="[::1]"||Q.hostname.endsWith(".localhost")}var y1=B.string().max(500),EJ=4000,vJ=1000,gJ=1000,mJ=B.object({label:y1,file:B.string().max(vJ),line:B.number().int().positive(),column:B.number().int().nonnegative()}),J6=B.object({url:B.string().min(1).max(2000),selector:B.string().max(2000),role:y1.optional(),name:y1.optional(),text:y1.optional(),components:B.array(B.string().max(200)).max(20).optional(),sources:B.array(mJ).max(10).optional(),context:y1.optional(),browser:B.object({name:y1,viewport:B.object({width:B.number().int().nonnegative(),height:B.number().int().nonnegative(),scale:B.number().positive()}),colorScheme:B.enum(["light","dark"])}).optional(),style:B.string().max(gJ).optional(),html:B.string().max(EJ).optional(),quote:B.object({exact:B.string().min(1).max(2000),before:y1,after:y1}).optional()}),xJ=B.enum(["user","agent"]),W3=B.object({id:B.string(),author:xJ,body:B.string().min(1).max(20000),createdAt:B.string()}),H3=B.enum(["open","queued","working","resolved"]),hJ=B.object({id:B.string(),anchor:J6,state:H3,comments:B.array(W3).min(1),screenshot:B.string().optional(),createdAt:B.string(),updatedAt:B.string()}),oU=B.object({threads:B.array(hJ)}),U3=B.string().trim().min(1).max(20000),Q6="data:image/png;base64,",uJ=B.string().startsWith(Q6).max(8000000).transform(($)=>Uint8Array.from(atob($.slice(Q6.length)),(Q)=>Q.charCodeAt(0))),aU=B.object({anchor:J6,body:U3,send:B.boolean(),screenshot:uJ.optional()}),nU=B.object({body:U3,send:B.boolean()}),sU=B.object({body:U3,resolve:B.boolean()}),q6=B.string().url().refine(($)=>fJ($),"must be an http(s) URL on localhost"),tU=B.object({target:q6}),eU=B.object({target:q6,port:B.number().int().min(1).max(65535)});var B2=B.object({id:B.string(),state:H3,revision:B.number().int(),snippet:B.string(),canvasFile:B.string().optional(),filePath:B.string().optional(),comments:B.array(W3),createdAt:B.string(),updatedAt:B.string()}),UK=B.object({threads:B.array(B2)}),Y6=B.string().trim().min(1).max(20000),KK=B.object({body:Y6,resolve:B.boolean()}),BK=B.object({body:Y6}),NK=B.object({resolved:B.boolean()});var pJ=B.object({threads:B.array(B2)}),cJ=B.object({thread:B2});async function X6($){let Q=await $.json().catch(()=>null),J=B.object({error:B.string()}).safeParse(Q);return Error(J.success?J.data.error:`Thread request failed with status ${$.status}`)}function lJ($,Q){let J=new Map(Q.map((G)=>[G.id,G])),Y=$.map((G)=>{let X=J.get(G.id);return X!==void 0&&X.updatedAt>=G.updatedAt?X:G}),q=new Set($.map((G)=>G.id));return[...Y,...Q.filter((G)=>!q.has(G.id))]}function G6($){let Q=[],J=new Set,Y=`/api/session/${encodeURIComponent($)}/threads`,q=(X)=>{Q=lJ(Q,X);for(let W of J)W()},G=async(X,W)=>{let _=await fetch(`${Y}/${X}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(W)});if(!_.ok)throw await X6(_);q([cJ.parse(await _.json()).thread])};return{subscribe(X){return J.add(X),()=>J.delete(X)},current:()=>Q,async load(){let X=await fetch(Y,{cache:"no-store"});if(!X.ok)throw await X6(X);q(pJ.parse(await X.json()).threads)},receive(X){let W=B.array(B2).safeParse(X);if(W.success)q(W.data)},reply:(X,W)=>G(`${encodeURIComponent(X)}/comments`,{body:W}),setResolved:(X,W)=>G(`${encodeURIComponent(X)}/resolved`,{resolved:W})}}function dJ(){if(typeof window>"u")return null;let $=window.location.hash.replace(/^#/,"");if(!$)return null;for(let Q of $.split("&")){let[J,Y]=Q.split("=");if(J==="k"&&Y)return decodeURIComponent(Y)}return null}function rJ(){if(typeof window<"u"&&window.__CANVAS_SHARE__?.shareId){let Q=dJ();return{isShared:!0,shareId:window.__CANVAS_SHARE__.shareId,encryptionKey:Q?e5(Q):null}}return{isShared:!1,sessionId:typeof window<"u"?window.location.pathname.replace("/s/",""):""}}var W$=rJ();function iJ(){return W$.isShared&&W$.encryptionKey!==null}function oJ(){return W$.isShared?W$.shareId:W$.sessionId}function aJ(){if(W$.isShared)return`/s/${W$.shareId}/meta`;return`/api/session/${W$.sessionId}/meta`}function nJ($,Q){let J=$.replace(/\.jsx$/,".js");if(W$.isShared)return`/s/${W$.shareId}/canvas/${encodeURIComponent(J)}`;let Y=Q?`?rev=${Q}&t=${Date.now()}`:`?t=${Date.now()}`;return`/api/session/${W$.sessionId}/canvas/${encodeURIComponent(J)}${Y}`}function sJ(){if(W$.isShared)return`/s/${W$.shareId}/upload`;return`/api/session/${W$.sessionId}/upload`}async function tJ($){let Q=await $.json().catch(()=>null);if(typeof Q==="object"&&Q!==null&&"error"in Q&&typeof Q.error==="string")return Error(Q.error);return Error(`Request failed with status ${$.status}`)}var _6="agent-canvas-project-theme",W6=0;async function H6(){if(W$.isShared)return;let $=++W6,Q=await fetch(`/api/session/${encodeURIComponent(W$.sessionId)}/theme.css`,{cache:"no-store"}),J=Q.ok?await Q.text():"";if(!Q.ok)console.warn(`Project theme not applied: ${(await tJ(Q)).message}`);if($!==W6)return;let Y=document.getElementById(_6);if(Y===null)Y=document.createElement("style"),Y.id=_6,document.head.append(Y);Y.textContent=J}async function U6(){let $=await fetch(aJ());if(!$.ok)throw Error(`meta ${$.status}`);let Q=o5.parse(await $.json());if(Q.encryption&&W$.isShared&&W$.encryptionKey){let J=await W$.encryptionKey;if(Q.origin){let Y={...Q.origin};if(Y.sessionId)Y.sessionId=await K2(J,Y.sessionId);if(Y.label)Y.label=await K2(J,Y.label);Q.origin=Y}for(let Y of Q.revisions??[])if(Y.label)try{Y.label=await K2(J,Y.label)}catch{}}return Q}var eJ=async($,Q)=>{let J=nJ($,Q);if(!iJ())return import(J);let Y=await fetch(J);if(!Y.ok)throw Error(`canvas ${Y.status}`);let q=await Y.text(),G=await W$.encryptionKey,X=await K2(G,q),W=new Blob([X],{type:"application/javascript"}),_=URL.createObjectURL(W);try{return await import(_)}finally{setTimeout(()=>URL.revokeObjectURL(_),0)}},K6="canvas-reviewer-identity";function K3(){try{let $=localStorage.getItem(K6);if(!$)return null;return JSON.parse($)}catch{return null}}function B6($){let Q=K3();if(!Q)Q={id:crypto.randomUUID?.()||String(Date.now()),name:$};else Q.name=$;return localStorage.setItem(K6,JSON.stringify(Q)),Q}async function $7($,Q){let J=await Promise.all($.annotations.map(async(Y)=>{let q={id:Y.id,createdAt:Y.createdAt,snippet:await N1(Q,String(Y.snippet??"")),note:await N1(Q,String(Y.note??""))};if(Y.filePath)q.filePath=await N1(Q,String(Y.filePath));if(Y.canvasFile)q.canvasFile=await N1(Q,String(Y.canvasFile));if(Y.context!==void 0&&Y.context!==null)q.context=await N1(Q,JSON.stringify(Y.context));if(Y.attachments)q.attachments=Y.attachments;return q}));return{author:{id:$.author.id,name:await N1(Q,$.author.name)},revision:$.revision,annotations:J,...$.generalNote?{generalNote:await N1(Q,$.generalNote)}:{},...$.responses&&$.responses.length>0?{responses:await N1(Q,JSON.stringify($.responses))}:{},encryption:t5}}async function N6($){if(!W$.isShared)throw Error("submitSharedFeedback called outside shared mode");let Q=$;if(W$.encryptionKey){let Y=await W$.encryptionKey;Q=await $7($,Y)}let J=await fetch(`/s/${W$.shareId}/feedback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Q)});if(!J.ok){let Y=await J.text().catch(()=>"");throw Error(`Feedback submission failed: ${J.status} ${Y}`)}}var O1=!W$.isShared,O6=!W$.isShared,s2=W$.isShared?null:G6(W$.sessionId),z6={get sessionId(){return oJ()},isShared:W$.isShared,fsAvailable:O1,uploadUrl:sJ,loadCanvasModule:eJ,threads:s2};import V6,{useCallback as C6,useContext as M7,useEffect as E1,useMemo as Q4,useRef as z1,useState as Z$}from"react";function f1($,Q){let J=$.length,Y=Q.length;if(J===0||Y===0)return[];let q=Array.from({length:J+1},()=>Array(Y+1).fill(0));for(let _=1;_<=J;_++)for(let H=1;H<=Y;H++)q[_][H]=$[_-1]===Q[H-1]?q[_-1][H-1]+1:Math.max(q[_-1][H],q[_][H-1]);let G=[],X=J,W=Y;while(X>0&&W>0)if($[X-1]===Q[W-1])G.unshift($[X-1]),X--,W--;else if(q[X-1][W]>q[X][W-1])X--;else W--;return G}function M6($){let Q=[],J=[],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 W=0;for(let _ of X)Q.push(_),J.push({text:_,node:q,offset:W}),W+=_.length}return{words:Q,map:J}}function B3($,Q){if($.length>5000||Q.length>5000)return Q7($,Q);return A6($,Q)}function A6($,Q){let J=t2($,Q),Y=[],q=[],G=0,X=0,W=0;while(G<$.length||X<Q.length)if(W<J.length&&G<$.length&&X<Q.length&&$[G]===J[W]&&Q[X]===J[W])Y.push({type:"same",index:G}),q.push({type:"same",index:X}),G++,X++,W++;else if(G<$.length&&(W>=J.length||$[G]!==J[W]))Y.push({type:"removed",index:G}),G++;else if(X<Q.length)q.push({type:"added",index:X}),X++;return{oldOps:Y,newOps:q}}function t2($,Q){let J=$.length,Y=Q.length;if(J===0||Y===0)return[];if(J===1)return Q.includes($[0])?[$[0]]:[];if(Y===1)return $.includes(Q[0])?[Q[0]]:[];if(J*Y<=1e6)return f1($,Q);let q=Math.floor(J/2),G=$.slice(0,q),X=$.slice(q),W=F6(G,Q),_=F6([...X].reverse(),[...Q].reverse()),H=0,U=0;for(let O=0;O<=Y;O++){let M=W[O]+_[Y-O];if(M>H)H=M,U=O}let K=Q.slice(0,U),N=Q.slice(U);return[...t2(G,K),...t2(X,N)]}function F6($,Q){let J=Q.length,Y=Array(J+1).fill(0),q=Array(J+1).fill(0);for(let G=0;G<$.length;G++){for(let X=1;X<=J;X++)q[X]=$[G]===Q[X-1]?Y[X-1]+1:Math.max(Y[X],q[X-1]);[Y,q]=[q,Y],q.fill(0)}return Y}function Q7($,Q){let Y=(M)=>{let L=[];for(let F=0;F<M.length;F+=200){let w=Math.min(F+200,M.length);L.push({start:F,end:w,text:M.slice(F,w).join("")})}return L},q=Y($),G=Y(Q),X=q.map((M)=>M.text),W=G.map((M)=>M.text),_=t2(X,W),H=[],U=[],K=0,N=0,O=0;while(K<q.length||N<G.length)if(O<_.length&&K<q.length&&N<G.length&&X[K]===_[O]&&W[N]===_[O]){for(let M=q[K].start;M<q[K].end;M++)H.push({type:"same",index:M});for(let M=G[N].start;M<G[N].end;M++)U.push({type:"same",index:M});K++,N++,O++}else if(K<q.length&&(O>=_.length||X[K]!==_[O]))if(N<G.length&&(O>=_.length||W[N]!==_[O])){let M=A6($.slice(q[K].start,q[K].end),Q.slice(G[N].start,G[N].end));for(let L of M.oldOps)H.push({type:L.type,index:L.index+q[K].start});for(let L of M.newOps)U.push({type:L.type,index:L.index+G[N].start});K++,N++}else{for(let M=q[K].start;M<q[K].end;M++)H.push({type:"removed",index:M});K++}else if(N<G.length){for(let M=G[N].start;M<G[N].end;M++)U.push({type:"added",index:M});N++}return{oldOps:H,newOps:U}}function L6($,Q,J){let Y=new Map;for(let q of $){if(q.type==="same")continue;let G=Q[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((K,N)=>K.offset-N.offset);let W=[];for(let K of G){let N=W[W.length-1];if(N&&K.offset<=N.offset+N.length)N.length=Math.max(N.length,K.offset+K.length-N.offset);else W.push({...K})}let _=q.parentNode,H=document.createDocumentFragment(),U=0;for(let K of W){if(K.offset>U)H.appendChild(document.createTextNode(X.slice(U,K.offset)));let N=document.createElement("span");N.className=J,N.textContent=X.slice(K.offset,K.offset+K.length),H.appendChild(N),U=K.offset+K.length}if(U<X.length)H.appendChild(document.createTextNode(X.slice(U)));_.replaceChild(H,q)}}function e2($,Q){let J=J7($,Q),Y=M6($),q=M6(Q),{oldOps:G,newOps:X}=B3(Y.words,q.words),W=G.some((_)=>_.type==="removed")||X.some((_)=>_.type==="added");return L6(G,Y.map,"diff-removed"),L6(X,q.map,"diff-added"),W||J}function J7($,Q){let J=Array.from($.querySelectorAll('[data-md="mermaid"]')),Y=Array.from(Q.querySelectorAll('[data-md="mermaid"]')),q=!1,G=Math.max(J.length,Y.length);for(let X=0;X<G;X++){let W=J[X],_=Y[X];if(!W&&_){_.classList.add("diff-block-added"),_.style.position="relative",q=!0;continue}if(W&&!_){W.classList.add("diff-block-removed"),W.style.position="relative",q=!0;continue}if(!W||!_)continue;let H=(W.getAttribute("data-md-source")||"").trim(),U=(_.getAttribute("data-md-source")||"").trim();if(H===U)continue;q=!0,W.style.borderLeft="3px solid var(--color-accent-red)",W.style.paddingLeft="8px",_.style.borderLeft="3px solid var(--color-accent-green)",_.style.paddingLeft="8px";let K=H.split(`
71
+ `),N=U.split(`
72
+ `),O=f1(K,N),M=(L,F,w)=>{let z=document.createElement("div");z.className="mt-2 bg-bg-code rounded-md overflow-hidden text-tiny font-mono",z.setAttribute("data-no-diff","true");let A=0,T=0;while(T<L.length){let S=document.createElement("div");if(S.className="px-3 py-0.5 whitespace-pre-wrap",A<F.length&&L[T]===F[A])S.textContent=" "+L[T],T++,A++;else S.classList.add(w==="old"?"diff-removed":"diff-added"),S.textContent=(w==="old"?"- ":"+ ")+L[T],T++;z.appendChild(S)}return z};W.appendChild(M(K,O,"old")),_.appendChild(M(N,O,"new"))}return q}import{useContext as q7,useEffect as Y7,useRef as X7,useState as G7}from"react";import{jsxDEV as y$,Fragment as P6}from"react/jsx-dev-runtime";function _7($){return $.label||`Round ${$.revision}`}function W7($){let Q=Date.now()-new Date($).getTime(),J=Math.floor(Q/1000);if(J<60)return"just now";let Y=Math.floor(J/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 N2({value:$,onChange:Q,accent:J="default",className:Y}){let{currentRevision:q,revisions:G}=q7(h$),[X,W]=G7(!1),_=X7(null);Y7(()=>{if(!X)return;let K=(N)=>{if(_.current&&!_.current.contains(N.target))W(!1)};return document.addEventListener("mousedown",K),()=>document.removeEventListener("mousedown",K)},[X]);let H=G.find((K)=>K.revision===$);return y$("div",{className:"relative",ref:_,children:[y$("button",{onClick:()=>W(!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"}[J]} ${Y||""}`,children:[H?_7(H):`Round ${$}`,y$("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none",className:`text-text-tertiary transition-transform duration-200 ${X?"rotate-180":""}`,children:y$("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&&y$("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((K)=>y$("button",{onClick:()=>{Q(K.revision),W(!1)},className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] font-body transition-colors ${K.revision===$?"bg-bg-surface text-text-primary":"text-text-secondary hover:bg-bg-surface hover:text-text-primary"}`,children:[y$("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${K.revision===q?"bg-accent-green":K.hasFeedback?"bg-accent-amber":"bg-border-hover"}`},void 0,!1,void 0,this),y$("span",{className:"flex-1 text-left truncate",children:K.label?y$(P6,{children:[K.label," ",y$("span",{className:"text-text-tertiary",children:["#",K.revision]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):y$(P6,{children:["Round ",K.revision]},void 0,!0,void 0,this)},void 0,!1,void 0,this),y$("span",{className:"text-[10px] text-text-tertiary flex-shrink-0 flex items-center gap-1.5",children:[(()=>{let N=K.canvasFiles?.reduce((O,M)=>{if(M.diffStats)O.added+=M.diffStats.added,O.removed+=M.diffStats.removed;return O},{added:0,removed:0});if(N&&(N.added>0||N.removed>0))return y$("span",{className:"font-mono",children:[y$("span",{className:"text-accent-green",children:["+",N.added]},void 0,!0,void 0,this)," ",y$("span",{className:"text-accent-red",children:["-",N.removed]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);return null})(),K.revision===q?"current":K.hasFeedback?"sent":W7(K.createdAt)]},void 0,!0,void 0,this)]},K.revision,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function D0($){let Q=[],J=$.querySelectorAll(":scope > [data-md]");for(let Y of J)Q.push(O2(Y));if(Q.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),Q.push(O2(G))}}return Q}function O2($){let Q=$.getAttribute("data-md")||"unknown",J=H7($,Q),Y=[];if(Q==="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(O2(G))}else if(Q==="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(Q==="checklist")for(let q of $.querySelectorAll(":scope > [data-md='checklist-item']"))Y.push(O2(q));else for(let q of $.querySelectorAll("[data-md]"))if(q.parentElement?.closest("[data-md]")===$)Y.push(O2(q));return{key:J,type:Q,element:$,children:Y}}function H7($,Q){switch(Q){case"section":return"section:"+($.getAttribute("data-md-title")||"");case"item":return"item:"+($.getAttribute("data-task-id")||$.getAttribute("data-md-label")||"");case"codeblock":case"diff":return Q+":"+($.textContent||"").slice(0,80);case"checklist-item":return"checklist-item:"+($.getAttribute("data-md-label")||$.textContent?.slice(0,60)||"");case"checklist":return"checklist:"+$.querySelectorAll("[data-md='checklist-item']").length;case"markdown":return"markdown:"+($.getAttribute("data-md-file")||"inline");case"mermaid":return"mermaid:"+($.getAttribute("data-md-source")||"").slice(0,80);case"callout":return"callout:"+($.getAttribute("data-md-type")||"")+":"+($.textContent||"").slice(0,60);default:return Q+":"+($.getAttribute("data-md-label")||$.textContent?.slice(0,60)||"")}}function z2($,Q){let J=$.map((H)=>H.key),Y=Q.map((H)=>H.key),q=f1(J,Y),G=[],X=0,W=0,_=0;while(X<$.length||W<Q.length)if(_<q.length&&X<$.length&&W<Q.length&&J[X]===q[_]&&Y[W]===q[_]){let H=$[X],U=Q[W],K=H.children.length>0||U.children.length>0?z2(H.children,U.children):void 0;G.push({kind:"matched",oldBlock:H,newBlock:U,childMatches:K}),X++,W++,_++}else if(X<$.length&&(_>=q.length||J[X]!==q[_]))G.push({kind:"removed",oldBlock:$[X]}),X++;else if(W<Q.length)G.push({kind:"added",newBlock:Q[W]}),W++;return G}function $4($){let Q=document.createDocumentFragment(),J=!1;for(let Y of $)if(Y.kind==="removed")J=!0,Q.appendChild(w6(Y.oldBlock.element));else if(Y.kind==="added")J=!0,Q.appendChild(U7(Y.newBlock.element));else{let q=Y.newBlock.element.cloneNode(!0),G=Y.newBlock.type;if(G==="mermaid"){if(Z6(Y.oldBlock.element,q))J=!0}else if(Y.childMatches&&Y.childMatches.length>0&&(G==="table"||G==="checklist")){if(j6(q,Y.childMatches,G))J=!0}else if(Y.childMatches&&Y.childMatches.length>0){if(T6(Y.oldBlock,q,Y.childMatches,G))J=!0}else if(G==="markdown"){if(b6(Y.oldBlock.element,q))J=!0}else if(Q0(Y.oldBlock.element,q,!1))J=!0;Q.appendChild(q)}return{fragment:Q,hasChanges:J}}function w6($){let Q=$.cloneNode(!0);return Q.classList.add("diff-block-removed"),Q.style.position="relative",N3(Q,"Removed","var(--color-accent-red)"),Q}function U7($){let Q=$.cloneNode(!0);return Q.classList.add("diff-block-added"),Q.style.position="relative",N3(Q,"Added","var(--color-accent-green)"),Q}function T6($,Q,J,Y){let q=!1,G=K7($,Q),X,W;if(Y==="section"){let _=$.element.querySelector(":scope > div:first-child"),H=Q.querySelector(":scope > div:first-child");if(_&&H){if(Q0(_,H,!1))q=!0}X=$.element.querySelector(":scope > div.mt-6, :scope > div:last-child"),W=Q.querySelector(":scope > div.mt-6, :scope > div:last-child")}else X=$.element,W=Q;if(!X||!W)return q;for(let _ of J)if(_.kind==="matched"){let H=G.newMap.get(_.newBlock.element);if(H){if(_.newBlock.type==="mermaid"){if(Z6(_.oldBlock.element,H))q=!0}else if(_.childMatches&&_.childMatches.length>0&&(_.newBlock.type==="table"||_.newBlock.type==="checklist")){if(j6(H,_.childMatches,_.newBlock.type))q=!0}else if(_.childMatches&&_.childMatches.length>0){if(T6(_.oldBlock,H,_.childMatches,_.newBlock.type))q=!0}else if(_.newBlock.type==="markdown"){if(b6(_.oldBlock.element,H))q=!0}else if(Q0(_.oldBlock.element,H,!1))q=!0}}else if(_.kind==="removed"){q=!0;let H=w6(_.oldBlock.element),U=N7(J,_,G.newMap),K=U?O7(W,U):null;W.insertBefore(H,K)}else if(_.kind==="added"){q=!0;let H=G.newMap.get(_.newBlock.element);if(H)H.classList.add("diff-block-added"),H.style.position="relative",N3(H,"Added","var(--color-accent-green)")}if(Q0(X,W,!0))q=!0;return q}function j6($,Q,J){let Y=J==="table"?$.querySelector(":scope table > tbody"):$;if(!Y)return!1;let q=!1;Y.innerHTML="";for(let G of Q)if(G.kind==="removed"){q=!0;let X=G.oldBlock.element.cloneNode(!0);X.classList.add(J==="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(J==="table"?"diff-row-added":"diff-item-added"),Y.appendChild(X)}else{let X=G.newBlock.element.cloneNode(!0);if(Q0(G.oldBlock.element,X,!1))q=!0;Y.appendChild(X)}return q}function K7($,Q){return{newMap:{get(J){return B7(Q,J)}}}}function B7($,Q){let J=Q.getAttribute("data-md");if(!J)return null;let Y=Q.getAttribute("data-md-label"),q=Q.getAttribute("data-md-title"),G=`[data-md="${J}"]`;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 W=(Q.textContent||"").slice(0,100),_=null,H=-1;for(let U of X){let K=(U.textContent||"").slice(0,100),N=0;for(let O=0;O<Math.min(W.length,K.length);O++)if(W[O]===K[O])N++;if(N>H)H=N,_=U}return _}function N7($,Q,J){let Y=$.indexOf(Q);for(let q=Y+1;q<$.length;q++){let G=$[q];if((G.kind==="matched"||G.kind==="added")&&G.newBlock)return J.get(G.newBlock.element)||null}return null}function O7($,Q){let J=Q;while(J&&J.parentElement!==$)J=J.parentElement;return J}function b6($,Q){let J=Array.from($.children),Y=Array.from(Q.children);if(J.length===0&&Y.length===0)return Q0($,Q,!1);let q=J.map((N)=>N.tagName.toLowerCase()),G=Y.map((N)=>N.tagName.toLowerCase()),X=f1(q,G),W=[],_=0,H=0,U=0;while(_<J.length||H<Y.length)if(U<X.length&&_<J.length&&H<Y.length&&q[_]===X[U]&&G[H]===X[U])W.push({kind:"matched",oldChild:J[_],newChild:Y[H]}),_++,H++,U++;else if(_<J.length&&(U>=X.length||q[_]!==X[U]))W.push({kind:"removed",oldChild:J[_]}),_++;else if(H<Y.length)W.push({kind:"added",newChild:Y[H]}),H++;let K=!1;while(Q.firstChild)Q.removeChild(Q.firstChild);for(let N of W)if(N.kind==="matched"){let O=(N.oldChild.textContent||"").match(/\S+/g)||[],M=(N.newChild.textContent||"").match(/\S+/g)||[],L=f1(O,M),F=Math.max(O.length,M.length);if((F>0?1-L.length/F:0)>0.5){K=!0;let z=N.oldChild.cloneNode(!0);z.classList.add("diff-block-removed"),Q.appendChild(z),N.newChild.classList.add("diff-block-added"),Q.appendChild(N.newChild)}else{if(Q0(N.oldChild,N.newChild,!1))K=!0;Q.appendChild(N.newChild)}}else if(N.kind==="removed"){K=!0;let O=N.oldChild.cloneNode(!0);O.classList.add("diff-block-removed"),Q.appendChild(O)}else K=!0,N.newChild.classList.add("diff-block-added"),Q.appendChild(N.newChild);return K}function S6($,Q){let J=Q?new Set(Array.from($.querySelectorAll("[data-md]"))):new Set,Y=[],q=[],G=document.createTreeWalker($,NodeFilter.SHOW_TEXT,{acceptNode(W){let _=W.parentElement;if(!_)return NodeFilter.FILTER_REJECT;if(_.closest("svg, .select-none, [data-no-diff]"))return NodeFilter.FILTER_REJECT;if(Q){for(let H of J)if(H.contains(W))return NodeFilter.FILTER_REJECT}return NodeFilter.FILTER_ACCEPT}}),X;while(X=G.nextNode()){let _=(X.nodeValue||"").match(/\S+|\s+/g);if(!_)continue;let H=0;for(let U of _)Y.push(U),q.push({text:U,node:X,offset:H}),H+=U.length}return{words:Y,map:q}}function Q0($,Q,J){let Y=S6($,J),q=S6(Q,J);if(Y.words.length===0&&q.words.length===0)return!1;let{oldOps:G,newOps:X}=B3(Y.words,q.words),W=G.some((F)=>F.type==="removed"),_=X.some((F)=>F.type==="added");if(!W&&!_)return!1;let H=[],U=[];for(let F of G)if(F.type==="same")H.push(F.index);for(let F of X)if(F.type==="same")U.push(F.index);let K=new Map;for(let F=0;F<H.length&&F<U.length;F++)K.set(H[F],U[F]);let N=[];{let F=[],w=-1;for(let z of G)if(z.type==="same"){if(F.length>0)N.push({text:F.join(""),anchorNewIdx:w>=0?K.get(w)??null:null}),F=[];w=z.index}else if(z.type==="removed")F.push(Y.words[z.index]);if(F.length>0)N.push({text:F.join(""),anchorNewIdx:w>=0?K.get(w)??null:null})}let O=new Map,M=new Map;for(let F of X){if(F.type!=="added")continue;let w=q.map[F.index];if(!w?.node.parentNode)continue;let z=O.get(w.node);if(!z)z=[],O.set(w.node,z);z.push({start:w.offset,end:w.offset+w.text.length})}for(let F of N)if(F.anchorNewIdx===null){if(q.map.length>0){let w=q.map[0].node,z=M.get(w);if(!z)z=[],M.set(w,z);z.push({offset:0,text:F.text})}}else{let w=q.map[F.anchorNewIdx];if(!w)continue;let z=M.get(w.node);if(!z)z=[],M.set(w.node,z);z.push({offset:w.offset+w.text.length,text:F.text})}let L=new Set([...O.keys(),...M.keys()]);for(let F of L)z7(F,O.get(F)||[],M.get(F)||[]);return!0}function z7($,Q,J){if(!$.parentNode)return;let Y=$.nodeValue||"";Q.sort((U,K)=>U.start-K.start);let q=[];for(let U of Q){let K=q[q.length-1];if(K&&U.start<=K.end)K.end=Math.max(K.end,U.end);else q.push({...U})}J.sort((U,K)=>U.offset-K.offset);let G=$.parentNode,X=document.createDocumentFragment(),W=0,_=0,H=0;while(W<=Y.length){let U=_<q.length?q[_].start:1/0,K=H<J.length?J[H].offset:1/0,N=Math.min(U,K);if(N===1/0){if(W<Y.length)X.appendChild(document.createTextNode(Y.slice(W)));break}let O=Math.max(N,W);if(O>W)X.appendChild(document.createTextNode(Y.slice(W,O))),W=O;while(H<J.length&&J[H].offset<=W){let M=document.createElement("span");M.className="diff-removed",M.textContent=J[H].text,X.appendChild(M),H++}if(_<q.length&&q[_].start<=W){let M=q[_],L=document.createElement("span");L.className="diff-added",L.textContent=Y.slice(W,M.end),X.appendChild(L),W=M.end,_++;while(H<J.length&&J[H].offset<=W){let F=document.createElement("span");F.className="diff-removed",F.textContent=J[H].text,X.appendChild(F),H++}}}while(H<J.length){let U=document.createElement("span");U.className="diff-removed",U.textContent=J[H].text,X.appendChild(U),H++}G.replaceChild(X,$)}function Z6($,Q){let J=($.getAttribute("data-md-source")||"").trim(),Y=(Q.getAttribute("data-md-source")||"").trim();if(J===Y)return!1;let q=J.split(`
72
73
  `),G=Y.split(`
73
- `),X=k1(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 K=document.createElement("div");K.className="mt-2 bg-bg-code rounded-md overflow-hidden text-tiny font-mono",K.setAttribute("data-no-diff","true");for(let z of H){let B=document.createElement("div");if(B.className="px-3 py-0.5 whitespace-pre-wrap",z.type==="removed")B.classList.add("diff-removed"),B.textContent="- "+z.line;else if(z.type==="added")B.classList.add("diff-added"),B.textContent="+ "+z.line;else B.textContent=" "+z.line;K.appendChild(B)}return J.appendChild(K),!0}function J3($,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 u}from"react/jsx-dev-runtime";function PQ($,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 Q6({initialLeft:$,initialRight:J,sessionId:Q,onExit:Y}){let[q,G]=V$($),[X,H]=V$(J),[_,W]=V$("unified"),[U,K]=V$(!0),[z,B]=V$(!1),{revisions:N}=SQ(f$),P=a2(()=>PQ(N,q,X),[N,q,X]),[M,T]=V$(()=>P[0]||"plan.jsx");y1(()=>{if(!P.includes(M))T(P[0]||"plan.jsx")},[P,M]);let O=a2(()=>{return N.find((S)=>S.revision===q)?.canvasFiles.some((S)=>S.filename===M)??!1},[N,q,M]),A=a2(()=>{return N.find((S)=>S.revision===X)?.canvasFiles.some((S)=>S.filename===M)??!1},[N,X,M]);return u("div",{className:"flex flex-col h-screen",children:[u("div",{className:"flex items-center justify-between px-6 py-3 border-b border-border-subtle bg-bg-surface flex-shrink-0",children:[u("div",{className:"flex items-center gap-3",children:[u("span",{className:"text-[13px] font-body font-medium text-text-primary",children:"Compare"},void 0,!1,void 0,this),u(_2,{value:q,onChange:G,accent:"red"},void 0,!1,void 0,this),u("span",{className:"text-text-tertiary text-[13px]",children:"→"},void 0,!1,void 0,this),u(_2,{value:X,onChange:H,accent:"green"},void 0,!1,void 0,this),z&&!U&&u("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),u("div",{className:"flex items-center gap-4",children:[u("div",{className:"flex items-center bg-bg-elevated rounded-md p-0.5",children:[u("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),u("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"&&u(wQ,{},void 0,!1,void 0,this),u("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&&u("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,C=N.find((V)=>V.revision===q)?.canvasFiles.some((V)=>V.filename===w),y=N.find((V)=>V.revision===X)?.canvasFiles.some((V)=>V.filename===w),I=!C?" (added)":!y?" (removed)":"";return u("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&&u("span",{className:`ml-1 text-[10px] ${!C?"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||!A?u("div",{className:"flex-1 flex items-center justify-center",children:u("div",{className:"text-center text-text-tertiary font-body",children:[u("div",{className:"text-lg mb-2",children:!O?"New file":"Removed file"},void 0,!1,void 0,this),u("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"?u(TQ,{sessionId:Q,leftRev:q,rightRev:X,filename:M,onDiffResult:(w,S)=>{B(w),K(S)}},`unified-${q}-${X}-${M}`,!1,void 0,this):u(jQ,{sessionId:Q,leftRev:q,rightRev:X,filename:M,onDiffResult:(w,S)=>{B(w),K(S)}},`sbs-${q}-${X}-${M}`,!1,void 0,this)]},void 0,!0,void 0,this)}function wQ(){let[$,J]=V$(!0);return y1(()=>{return document.documentElement.dataset.syncScroll=$?"1":"0",()=>{delete document.documentElement.dataset.syncScroll}},[$]),u("label",{className:"flex items-center gap-1.5 cursor-pointer select-none",children:[u("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),u("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 TQ({sessionId:$,leftRev:J,rightRev:Q,filename:Y,onDiffResult:q}){let G=N1(null),X=N1(null),H=N1(null),[_,W]=V$(!1),[U,K]=V$(!1),[z,B]=V$(!1),[N,P]=V$(null),[M,T]=V$(!1),{annotations:O}=Y1(),A=O.filter((S)=>!S.filePath&&(!S.canvasFile||S.canvasFile===Y)),{popovers:w}=C1({containerRef:H,restoreKey:z,restoreAnnotations:A,extractContext:(S)=>A1(S,H.current)});return y1(()=>{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]),y1(()=>{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=V0(G.current),j=V0(X.current),C=W2(S,j),{fragment:y,hasChanges:I}=o2(C);H.current.innerHTML="",H.current.appendChild(y),B(!0),q(!0,I)}catch(S){console.error("[unified-diff] diff computation failed",S),P(S instanceof Error?S.message:String(S))}})})},[_,U,z]),u("div",{className:"flex-1 min-h-0 overflow-y-auto",children:[!z&&!N&&u("div",{style:{position:"absolute",left:-9999,visibility:"hidden",pointerEvents:"none",width:720},children:[u(M1,{ref:G,sessionId:$,revision:J,filename:Y,onReady:()=>W(!0),onError:(S)=>P(`Rev ${J}: ${S}`)},void 0,!1,void 0,this),u(M1,{ref:X,sessionId:$,revision:Q,filename:Y,onReady:()=>K(!0),onError:(S)=>P(`Rev ${Q}: ${S}`)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),u("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:[!z&&!N&&u("div",{className:"flex flex-col items-center justify-center h-64 text-text-tertiary font-body text-body gap-2",children:[u("span",{children:"Loading..."},void 0,!1,void 0,this),M&&u("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&&u("div",{className:"bg-accent-red-muted rounded-lg p-5 mt-8",children:[u("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Failed to load revision"},void 0,!1,void 0,this),u("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),u("div",{ref:H},void 0,!1,void 0,this)]},void 0,!0,void 0,this),w]},void 0,!0,void 0,this)}function jQ({sessionId:$,leftRev:J,rightRev:Q,filename:Y,onDiffResult:q}){let G=N1(null),X=N1(null),[H,_]=V$(!1),[W,U]=V$(!1),[K,z]=V$(!1),B=N1(null),N=N1(null),P=N1(null),M=N1(!1),T=J6(()=>_(!0),[]),O=J6(()=>U(!0),[]),{annotations:A}=Y1(),w=A.filter((j)=>!j.filePath&&(!j.canvasFile||j.canvasFile===Y)),{popovers:S}=C1({containerRef:B,restoreKey:K,restoreAnnotations:w,extractContext:(j)=>A1(j,B.current)});return y1(()=>{if(!H||!W||K)return;if(!G.current||!X.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!G.current||!X.current)return;let j=i2(G.current,X.current);z(!0),q(!0,j)})})},[H,W,K]),y1(()=>{let j=N.current,C=P.current;if(!j||!C)return;let y=(f,h)=>{if(document.documentElement.dataset.syncScroll==="0")return;if(M.current)return;M.current=!0;let o=f.scrollHeight-f.clientHeight,B$=h.scrollHeight-h.clientHeight;if(o>0&&B$>0)h.scrollTop=f.scrollTop/o*B$;requestAnimationFrame(()=>{M.current=!1})},I=()=>y(j,C),V=()=>y(C,j);return j.addEventListener("scroll",I),C.addEventListener("scroll",V),()=>{j.removeEventListener("scroll",I),C.removeEventListener("scroll",V)}},[]),u("div",{ref:B,className:"flex flex-1 min-h-0",children:[u("div",{ref:N,className:"w-1/2 overflow-y-auto border-r border-border-subtle",children:u("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:u(M1,{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),u("div",{ref:P,className:"w-1/2 overflow-y-auto",children:u("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:u(M1,{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 M1=$6.memo($6.forwardRef(({sessionId:$,revision:J,filename:Q,onReady:Y,onError:q},G)=>{let[X,H]=V$(null),[_,W]=V$(null),[U,K]=V$(!0);y1(()=>{K(!0),W(null);let B=Q.replace(/\.jsx$/,".js");import(`/api/session/${$}/canvas/${encodeURIComponent(B)}?rev=${J}&t=${Date.now()}`).then((N)=>{if(!N.default){W("Module has no default export"),K(!1),q?.("Module has no default export");return}H(()=>N.default),K(!1)}).catch((N)=>{W(N.message),K(!1),q?.(N.message)})},[$,J,Q]),y1(()=>{if(!X)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{Y()})})},[X]);let z=a2(()=>X?u(X,{},void 0,!1,void 0,this):null,[X]);if(U)return u("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 u("div",{className:"bg-accent-red-muted rounded-lg p-5",children:[u("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Error"},void 0,!1,void 0,this),u("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 u("div",{className:"text-text-tertiary text-center py-8 font-body text-body",children:"No canvas loaded"},void 0,!1,void 0,this);return u("div",{ref:G,children:z},void 0,!1,void 0,this)}));function U2($){return $ instanceof Error&&$.message?$.message:String($)}var n2={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 q6($){let J=[];return s2($,J,0),J.join(`
74
+ `),X=f1(q,G),W=[],_=0,H=0,U=0;while(_<q.length||H<G.length)if(U<X.length&&_<q.length&&H<G.length&&q[_]===X[U]&&G[H]===X[U])W.push({type:"same",line:q[_]}),_++,H++,U++;else if(_<q.length&&(U>=X.length||q[_]!==X[U]))W.push({type:"removed",line:q[_]}),_++;else if(H<G.length)W.push({type:"added",line:G[H]}),H++;let K=document.createElement("div");K.className="mt-2 bg-bg-code rounded-md overflow-hidden text-tiny font-mono",K.setAttribute("data-no-diff","true");for(let N of W){let O=document.createElement("div");if(O.className="px-3 py-0.5 whitespace-pre-wrap",N.type==="removed")O.classList.add("diff-removed"),O.textContent="- "+N.line;else if(N.type==="added")O.classList.add("diff-added"),O.textContent="+ "+N.line;else O.textContent=" "+N.line;K.appendChild(O)}return Q.appendChild(K),!0}function N3($,Q,J){let Y=document.createElement("span");Y.className="diff-block-label",Y.textContent=Q,Y.style.color=J,Y.style.backgroundColor=`color-mix(in srgb, ${J} 12%, transparent)`,$.appendChild(Y)}import{jsxDEV as u}from"react/jsx-dev-runtime";function F7($,Q,J){let Y=$.find((X)=>X.revision===Q),q=$.find((X)=>X.revision===J),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 R6({initialLeft:$,initialRight:Q,sessionId:J,onExit:Y}){let[q,G]=Z$($),[X,W]=Z$(Q),[_,H]=Z$("unified"),[U,K]=Z$(!0),[N,O]=Z$(!1),{revisions:M}=M7(h$),L=Q4(()=>F7(M,q,X),[M,q,X]),[F,w]=Z$(()=>L[0]||"plan.jsx");E1(()=>{if(!L.includes(F))w(L[0]||"plan.jsx")},[L,F]);let z=Q4(()=>{return M.find((S)=>S.revision===q)?.canvasFiles.some((S)=>S.filename===F)??!1},[M,q,F]),A=Q4(()=>{return M.find((S)=>S.revision===X)?.canvasFiles.some((S)=>S.filename===F)??!1},[M,X,F]);return u("div",{className:"flex flex-col h-screen",children:[u("div",{className:"flex items-center justify-between px-6 py-3 border-b border-border-subtle bg-bg-surface flex-shrink-0",children:[u("div",{className:"flex items-center gap-3",children:[u("span",{className:"text-[13px] font-body font-medium text-text-primary",children:"Compare"},void 0,!1,void 0,this),u(N2,{value:q,onChange:G,accent:"red"},void 0,!1,void 0,this),u("span",{className:"text-text-tertiary text-[13px]",children:"→"},void 0,!1,void 0,this),u(N2,{value:X,onChange:W,accent:"green"},void 0,!1,void 0,this),N&&!U&&u("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),u("div",{className:"flex items-center gap-4",children:[u("div",{className:"flex items-center bg-bg-elevated rounded-md p-0.5",children:[u("button",{onClick:()=>H("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),u("button",{onClick:()=>H("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"&&u(L7,{},void 0,!1,void 0,this),u("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),L.length>1&&u("div",{className:"flex items-center gap-1 px-6 py-2 border-b border-border-subtle bg-bg-surface flex-shrink-0 overflow-x-auto",children:L.map((T)=>{let S=T.replace(/\.jsx$/,""),j=T===F,Z=M.find((C)=>C.revision===q)?.canvasFiles.some((C)=>C.filename===T),y=M.find((C)=>C.revision===X)?.canvasFiles.some((C)=>C.filename===T),V=!Z?" (added)":!y?" (removed)":"";return u("button",{onClick:()=>w(T),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,V&&u("span",{className:`ml-1 text-[10px] ${!Z?"text-accent-green":"text-accent-red"}`,children:V},void 0,!1,void 0,this)]},T,!0,void 0,this)})},void 0,!1,void 0,this),!z||!A?u("div",{className:"flex-1 flex items-center justify-center",children:u("div",{className:"text-center text-text-tertiary font-body",children:[u("div",{className:"text-lg mb-2",children:!z?"New file":"Removed file"},void 0,!1,void 0,this),u("div",{className:"text-[13px]",children:[F.replace(/\.jsx$/,"")," ",!z?"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"?u(A7,{sessionId:J,leftRev:q,rightRev:X,filename:F,onDiffResult:(T,S)=>{O(T),K(S)}},`unified-${q}-${X}-${F}`,!1,void 0,this):u(P7,{sessionId:J,leftRev:q,rightRev:X,filename:F,onDiffResult:(T,S)=>{O(T),K(S)}},`sbs-${q}-${X}-${F}`,!1,void 0,this)]},void 0,!0,void 0,this)}function L7(){let[$,Q]=Z$(!0);return E1(()=>{return document.documentElement.dataset.syncScroll=$?"1":"0",()=>{delete document.documentElement.dataset.syncScroll}},[$]),u("label",{className:"flex items-center gap-1.5 cursor-pointer select-none",children:[u("input",{type:"checkbox",checked:$,onChange:(J)=>Q(J.target.checked),className:"accent-accent-amber w-3.5 h-3.5"},void 0,!1,void 0,this),u("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 A7({sessionId:$,leftRev:Q,rightRev:J,filename:Y,onDiffResult:q}){let G=z1(null),X=z1(null),W=z1(null),[_,H]=Z$(!1),[U,K]=Z$(!1),[N,O]=Z$(!1),[M,L]=Z$(null),[F,w]=Z$(!1),{annotations:z}=G1(),A=z.filter((S)=>!S.filePath&&(!S.canvasFile||S.canvasFile===Y)),{popovers:T}=R1({containerRef:W,restoreKey:N,restoreAnnotations:A,extractContext:(S)=>P1(S,W.current)});return E1(()=>{if(N||M)return;let S=setTimeout(()=>{console.warn("[unified-diff] still loading after 10s",{leftReady:_,rightReady:U,oldRef:!!G.current,newRef:!!X.current}),w(!0)},1e4);return()=>clearTimeout(S)},[N,M,_,U]),E1(()=>{if(!_||!U||N)return;if(!G.current||!X.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!G.current||!X.current||!W.current){console.warn("[unified-diff] refs lost between rAF frames",{old:!!G.current,new:!!X.current,unified:!!W.current});return}try{let S=D0(G.current),j=D0(X.current),Z=z2(S,j),{fragment:y,hasChanges:V}=$4(Z);W.current.innerHTML="",W.current.appendChild(y),O(!0),q(!0,V)}catch(S){console.error("[unified-diff] diff computation failed",S),L(S instanceof Error?S.message:String(S))}})})},[_,U,N]),u("div",{className:"flex-1 min-h-0 overflow-y-auto",children:[!N&&!M&&u("div",{style:{position:"absolute",left:-9999,visibility:"hidden",pointerEvents:"none",width:720},children:[u(M1,{ref:G,sessionId:$,revision:Q,filename:Y,onReady:()=>H(!0),onError:(S)=>L(`Rev ${Q}: ${S}`)},void 0,!1,void 0,this),u(M1,{ref:X,sessionId:$,revision:J,filename:Y,onReady:()=>K(!0),onError:(S)=>L(`Rev ${J}: ${S}`)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),u("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:[!N&&!M&&u("div",{className:"flex flex-col items-center justify-center h-64 text-text-tertiary font-body text-body gap-2",children:[u("span",{children:"Loading..."},void 0,!1,void 0,this),F&&u("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&&u("div",{className:"bg-accent-red-muted rounded-lg p-5 mt-8",children:[u("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Failed to load revision"},void 0,!1,void 0,this),u("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),u("div",{ref:W},void 0,!1,void 0,this)]},void 0,!0,void 0,this),T]},void 0,!0,void 0,this)}function P7({sessionId:$,leftRev:Q,rightRev:J,filename:Y,onDiffResult:q}){let G=z1(null),X=z1(null),[W,_]=Z$(!1),[H,U]=Z$(!1),[K,N]=Z$(!1),O=z1(null),M=z1(null),L=z1(null),F=z1(!1),w=C6(()=>_(!0),[]),z=C6(()=>U(!0),[]),{annotations:A}=G1(),T=A.filter((j)=>!j.filePath&&(!j.canvasFile||j.canvasFile===Y)),{popovers:S}=R1({containerRef:O,restoreKey:K,restoreAnnotations:T,extractContext:(j)=>P1(j,O.current)});return E1(()=>{if(!W||!H||K)return;if(!G.current||!X.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!G.current||!X.current)return;let j=e2(G.current,X.current);N(!0),q(!0,j)})})},[W,H,K]),E1(()=>{let j=M.current,Z=L.current;if(!j||!Z)return;let y=(v,h)=>{if(document.documentElement.dataset.syncScroll==="0")return;if(F.current)return;F.current=!0;let o=v.scrollHeight-v.clientHeight,B$=h.scrollHeight-h.clientHeight;if(o>0&&B$>0)h.scrollTop=v.scrollTop/o*B$;requestAnimationFrame(()=>{F.current=!1})},V=()=>y(j,Z),C=()=>y(Z,j);return j.addEventListener("scroll",V),Z.addEventListener("scroll",C),()=>{j.removeEventListener("scroll",V),Z.removeEventListener("scroll",C)}},[]),u("div",{ref:O,className:"flex flex-1 min-h-0",children:[u("div",{ref:M,className:"w-1/2 overflow-y-auto border-r border-border-subtle",children:u("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:u(M1,{ref:G,sessionId:$,revision:Q,filename:Y,onReady:w},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),u("div",{ref:L,className:"w-1/2 overflow-y-auto",children:u("div",{className:"max-w-[720px] mx-auto px-6 pt-8 pb-32",children:u(M1,{ref:X,sessionId:$,revision:J,filename:Y,onReady:z},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 M1=V6.memo(V6.forwardRef(({sessionId:$,revision:Q,filename:J,onReady:Y,onError:q},G)=>{let[X,W]=Z$(null),[_,H]=Z$(null),[U,K]=Z$(!0);E1(()=>{K(!0),H(null);let O=J.replace(/\.jsx$/,".js");import(`/api/session/${$}/canvas/${encodeURIComponent(O)}?rev=${Q}&t=${Date.now()}`).then((M)=>{if(!M.default){H("Module has no default export"),K(!1),q?.("Module has no default export");return}W(()=>M.default),K(!1)}).catch((M)=>{H(M.message),K(!1),q?.(M.message)})},[$,Q,J]),E1(()=>{if(!X)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{Y()})})},[X]);let N=Q4(()=>X?u(X,{},void 0,!1,void 0,this):null,[X]);if(U)return u("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 u("div",{className:"bg-accent-red-muted rounded-lg p-5",children:[u("h3",{className:"font-body font-semibold text-accent-red mb-2",children:"Error"},void 0,!1,void 0,this),u("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 u("div",{className:"text-text-tertiary text-center py-8 font-body text-body",children:"No canvas loaded"},void 0,!1,void 0,this);return u("div",{ref:G,children:N},void 0,!1,void 0,this)}));function I0($){return $ instanceof Error&&$.message?$.message:String($)}var J4={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 D6($){let Q=[];return q4($,Q,0),Q.join(`
74
75
  `).replace(/\n{3,}/g,`
75
76
 
76
77
  `).trim()+`
77
- `}var bQ=new Set(["CODE","SPAN","STRONG","EM","A","B","I","U","SMALL","SUB","SUP","MARK","ABBR"]);function s2($,J,Q){if(VQ($)){let Y=ZQ($);if(Y)J.push(Y,"");return}for(let Y of $.childNodes)if(Y.nodeType===Node.ELEMENT_NODE)CQ(Y,J,Q);else if(Y.nodeType===Node.TEXT_NODE){let q=Y.textContent?.trim();if(q)J.push(q,"")}}function VQ($){for(let J of $.childNodes){if(J.nodeType===Node.TEXT_NODE)continue;if(J.nodeType===Node.ELEMENT_NODE){let Q=J;if(!bQ.has(Q.tagName)||Q.hasAttribute("data-md"))return!1}}return $.childNodes.length>0}function ZQ($){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 CQ($,J,Q){let Y=$.getAttribute("data-md");if(Y)switch(Y){case"section":return RQ($,J,Q);case"item":return IQ($,J);case"codeblock":return DQ($,J);case"callout":return kQ($,J);case"note":return yQ($,J);case"markdown":return mQ($,J);case"table":return EQ($,J);case"checklist":return fQ($,J);case"diff":return vQ($,J);case"mermaid":return gQ($,J);case"choice":return xQ($,J);case"multichoice":return hQ($,J);case"choice-option":case"multichoice-option":return;case"userinput":return uQ($,J);case"rangeinput":return pQ($,J);case"checklist-item":return;case"filepreview":return cQ($,J);case"priority":return lQ($,J)}if($.querySelector("button, input, select, textarea"))return;if($.children.length>0)s2($,J,Q);else{let q=$.textContent?.trim();if(q)J.push(q,"")}}function RQ($,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)s2(G,J,Q+1)}function IQ($,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 _=[];s2(H,_,0);for(let W of _)J.push(W?` ${W}`:"")}J.push("")}function DQ($,J){let Q=$.getAttribute("data-md-language")||"",q=$.querySelector("code")?.textContent||"";J.push(`\`\`\`${Q}`,q,"```","")}function kQ($,J){let Q=$.getAttribute("data-md-type")||"info",Y={info:"Info",warning:"Warning",danger:"Danger",tip:"Tip"},q=dQ($.querySelector(".text-text-secondary")||$);J.push(`> **${Y[Q]||Q}:** ${q}`,"")}function yQ($,J){let Q=$.textContent?.trim()||"";J.push(`> *${Q}*`,"")}function EQ($,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 fQ($,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 vQ($,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 gQ($,J){let Q=$.getAttribute("data-md-source")||"";if(Q)J.push("```mermaid",Q,"```","")}function mQ($,J){let Q=$.getAttribute("data-md-source")||"";if(Q)J.push(Q,"")}function xQ($,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 hQ($,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 uQ($,J){let Q=$.getAttribute("data-md-label")||"",q=$.querySelector("textarea")?.value?.trim()||"";J.push(`**${Q}:** ${q||"_empty_"}`,"")}function pQ($,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 cQ($,J){let Q=$.getAttribute("data-md-path")||"",Y=$.getAttribute("data-md-lines")||"",G=$.querySelector("code")?.textContent||"",X=Q.split(".").pop()||"",H=n2[X]||"",_=Y?`${Q} (L${Y})`:Q;J.push(_,"",`\`\`\`${H}`,G,"```","")}function lQ($,J){}function dQ($){return $?.textContent?.trim()||""}import{SessionContext as rQ}from"#canvas/runtime";import{useContext as Y6,useEffect as iQ,useMemo as oQ,useState as X6}from"react";import{jsxDEV as s,Fragment as Q3}from"react/jsx-dev-runtime";function G6({embedded:$}={}){if(!z1)return s("div",{className:$?"px-4 py-3":"p-4",children:[s("div",{className:"text-[11px] uppercase tracking-widest text-text-tertiary font-body mb-2",children:"Files"},void 0,!1,void 0,this),s("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 s(aQ,{embedded:$},void 0,!1,void 0,this)}function aQ({embedded:$}){let J=Y6(rQ),{annotations:Q,addAnnotation:Y}=Y1(),{setActiveView:q}=Y6(J1),[G,X]=X6(!1),[H,_]=X6({}),{annCountMap:W,annotatedFiles:U}=oQ(()=>{let O=new Map;for(let A of Q)if(A.filePath&&A.filePath!==u$)O.set(A.filePath,(O.get(A.filePath)||0)+1);return{annCountMap:O,annotatedFiles:[...O.keys()]}},[Q]),K=async(O)=>{let A=await fetch(`/api/tree?session=${J}&path=${encodeURIComponent(O)}`),w=t4.safeParse(await A.json());if(w.success)_((S)=>({...S,[O]:{entries:w.data.entries,expanded:!0,loaded:!0}}))};iQ(()=>{if(!G&&!H[""])K("")},[G]);let z=(O)=>{if(H[O]?.loaded)_((A)=>({...A,[O]:{...A[O],expanded:!A[O].expanded}}));else K(O)},B=(O)=>{q({type:"file",path:O})},N=async(O)=>{let A=await fetch(`/api/file?session=${J}&path=${encodeURIComponent(O)}`),w=R1.safeParse(await A.json());if(w.success&&"content"in w.data){let{content:S}=w.data,j=S.split(`
78
+ `}var S7=new Set(["CODE","SPAN","STRONG","EM","A","B","I","U","SMALL","SUB","SUP","MARK","ABBR"]);function q4($,Q,J){if(w7($)){let Y=T7($);if(Y)Q.push(Y,"");return}for(let Y of $.childNodes)if(Y.nodeType===Node.ELEMENT_NODE)j7(Y,Q,J);else if(Y.nodeType===Node.TEXT_NODE){let q=Y.textContent?.trim();if(q)Q.push(q,"")}}function w7($){for(let Q of $.childNodes){if(Q.nodeType===Node.TEXT_NODE)continue;if(Q.nodeType===Node.ELEMENT_NODE){let J=Q;if(!S7.has(J.tagName)||J.hasAttribute("data-md"))return!1}}return $.childNodes.length>0}function T7($){let Q="";for(let J of $.childNodes)if(J.nodeType===Node.TEXT_NODE)Q+=J.textContent||"";else if(J.nodeType===Node.ELEMENT_NODE){let Y=J;if(Y.tagName==="CODE")Q+="`"+(Y.textContent||"")+"`";else Q+=Y.textContent||""}return Q.trim()}function j7($,Q,J){let Y=$.getAttribute("data-md");if(Y)switch(Y){case"section":return b7($,Q,J);case"item":return Z7($,Q);case"codeblock":return V7($,Q);case"callout":return C7($,Q);case"note":return R7($,Q);case"markdown":return f7($,Q);case"table":return D7($,Q);case"checklist":return I7($,Q);case"diff":return k7($,Q);case"mermaid":return y7($,Q);case"choice":return E7($,Q);case"multichoice":return v7($,Q);case"choice-option":case"multichoice-option":return;case"userinput":return g7($,Q);case"rangeinput":return m7($,Q);case"checklist-item":return;case"filepreview":return x7($,Q);case"priority":return h7($,Q)}if($.querySelector("button, input, select, textarea"))return;if($.children.length>0)q4($,Q,J);else{let q=$.textContent?.trim();if(q)Q.push(q,"")}}function b7($,Q,J){let Y=$.getAttribute("data-md-title")||"Untitled",q=J===0?"##":"###";Q.push(`${q} ${Y}`,"");let G=$.querySelector(":scope > div:last-of-type");if(G)q4(G,Q,J+1)}function Z7($,Q){let J=$.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} **${J}**`;if(q)X+=` \`${q}\``;Q.push(X);let W=$.querySelector(".text-text-secondary");if(W){let _=[];q4(W,_,0);for(let H of _)Q.push(H?` ${H}`:"")}Q.push("")}function V7($,Q){let J=$.getAttribute("data-md-language")||"",q=$.querySelector("code")?.textContent||"";Q.push(`\`\`\`${J}`,q,"```","")}function C7($,Q){let J=$.getAttribute("data-md-type")||"info",Y={info:"Info",warning:"Warning",danger:"Danger",tip:"Tip"},q=u7($.querySelector(".text-text-secondary")||$);Q.push(`> **${Y[J]||J}:** ${q}`,"")}function R7($,Q){let J=$.textContent?.trim()||"";Q.push(`> *${J}*`,"")}function D7($,Q){let J=$.querySelector("table");if(!J)return;let Y=[];for(let q of J.querySelectorAll("thead th"))Y.push(q.textContent?.trim()||"");if(Y.length===0)return;Q.push(`| ${Y.join(" | ")} |`),Q.push(`| ${Y.map(()=>"---").join(" | ")} |`);for(let q of J.querySelectorAll("tbody tr")){let G=[];for(let X of q.querySelectorAll("td"))G.push(X.textContent?.trim()||"");Q.push(`| ${G.join(" | ")} |`)}Q.push("")}function I7($,Q){for(let J of $.querySelectorAll("li")){let Y=J.querySelector(".bg-accent-green")!==null,q=J.textContent?.trim()||"";Q.push(`- [${Y?"x":" "}] ${q}`)}Q.push("")}function k7($,Q){let J=$.getAttribute("data-md-language")||"";Q.push(`\`\`\`diff${J?` (${J})`:""}`);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)Q.push(`${q} ${G.textContent}`)}Q.push("```","")}function y7($,Q){let J=$.getAttribute("data-md-source")||"";if(J)Q.push("```mermaid",J,"```","")}function f7($,Q){let J=$.getAttribute("data-md-source")||"";if(J)Q.push(J,"")}function E7($,Q){let J=$.getAttribute("data-md-label")||"";Q.push(`**${J}:**`);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;Q.push(`- ${G?"(x)":"( )"} ${q}`)}Q.push("")}function v7($,Q){let J=$.getAttribute("data-md-label")||"";Q.push(`**${J}:**`);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;Q.push(`- [${G?"x":" "}] ${q}`)}Q.push("")}function g7($,Q){let J=$.getAttribute("data-md-label")||"",q=$.querySelector("textarea")?.value?.trim()||"";Q.push(`**${J}:** ${q||"_empty_"}`,"")}function m7($,Q){let J=$.getAttribute("data-md-label")||"",Y=$.querySelector("input[type='range']"),G=$.querySelector(".font-mono")?.textContent?.trim()||Y?.value||"—";Q.push(`**${J}:** ${G}`,"")}function x7($,Q){let J=$.getAttribute("data-md-path")||"",Y=$.getAttribute("data-md-lines")||"",G=$.querySelector("code")?.textContent||"",X=J.split(".").pop()||"",W=J4[X]||"",_=Y?`${J} (L${Y})`:J;Q.push(_,"",`\`\`\`${W}`,G,"```","")}function h7($,Q){}function u7($){return $?.textContent?.trim()||""}import{SessionContext as p7}from"#canvas/runtime";import{useContext as I6,useEffect as c7,useMemo as l7,useState as k6}from"react";import{jsxDEV as s,Fragment as O3}from"react/jsx-dev-runtime";function y6({embedded:$}={}){if(!O1)return s("div",{className:$?"px-4 py-3":"p-4",children:[s("div",{className:"text-[11px] uppercase tracking-widest text-text-tertiary font-body mb-2",children:"Files"},void 0,!1,void 0,this),s("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 s(d7,{embedded:$},void 0,!1,void 0,this)}function d7({embedded:$}){let Q=I6(p7),{annotations:J,addAnnotation:Y}=G1(),{setActiveView:q}=I6(q1),[G,X]=k6(!1),[W,_]=k6({}),{annCountMap:H,annotatedFiles:U}=l7(()=>{let z=new Map;for(let A of J)if(A.filePath&&A.filePath!==g$)z.set(A.filePath,(z.get(A.filePath)||0)+1);return{annCountMap:z,annotatedFiles:[...z.keys()]}},[J]),K=async(z)=>{let A=await fetch(`/api/tree?session=${Q}&path=${encodeURIComponent(z)}`),T=_3.safeParse(await A.json());if(T.success)_((S)=>({...S,[z]:{entries:T.data.entries,expanded:!0,loaded:!0}}))};c7(()=>{if(!G&&!W[""])K("")},[G]);let N=(z)=>{if(W[z]?.loaded)_((A)=>({...A,[z]:{...A[z],expanded:!A[z].expanded}}));else K(z)},O=(z)=>{q({type:"file",path:z})},M=async(z)=>{let A=await fetch(`/api/file?session=${Q}&path=${encodeURIComponent(z)}`),T=D1.safeParse(await A.json());if(T.success&&"content"in T.data){let{content:S}=T.data,j=S.split(`
78
79
  `).slice(0,3).join(`
79
80
  `)+(S.split(`
80
81
  `).length>3?`
81
- ...`:"");Y(j,"Include this file for context",O)}},P=async(O)=>{let A=[];if(H[O]?.loaded)A=H[O].entries;else{let w=await fetch(`/api/tree?session=${J}&path=${encodeURIComponent(O)}`),S=t4.safeParse(await w.json());if(S.success)A=S.data.entries}await Promise.all(A.filter((w)=>w.type==="file").map((w)=>N(O?`${O}/${w.name}`:w.name)))},M=(O)=>W.get(O)||0,T=(O,A=0)=>{let w=H[O];if(!w?.expanded)return null;return w.entries.map((S)=>{let j=O?`${O}/${S.name}`:S.name,C=M(j);return s("div",{children:[s("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+A*16}px`,paddingRight:"8px"},children:S.type==="dir"?s(Q3,{children:[s("span",{onClick:()=>z(j),className:"flex items-center gap-1.5 flex-1 text-text-secondary hover:text-text-primary cursor-pointer truncate",children:[s(I1,{name:S.name,type:"dir",expanded:H[j]?.expanded},void 0,!1,void 0,this),s("span",{className:"truncate",children:S.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this),s("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):s(Q3,{children:[s("span",{onClick:()=>B(j),className:`flex-1 truncate cursor-pointer flex items-center gap-1.5 ${C>0?"text-text-primary":"text-text-secondary hover:text-text-primary"}`,children:[s(I1,{name:S.name,type:"file"},void 0,!1,void 0,this),s("span",{className:"truncate",children:S.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this),s("div",{className:"flex items-center gap-1 flex-shrink-0 ml-1",children:[C>0&&s("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:C},void 0,!1,void 0,this),s("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,A+1)]},j,!0,void 0,this)})};if($)return s(Q3,{children:[s("div",{className:"flex items-center justify-between px-4 pt-3 pb-2 flex-shrink-0",children:s("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),s("div",{className:"flex-1 overflow-y-auto",children:T("")},void 0,!1,void 0,this),U.length>0&&s("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:[s("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)=>s("div",{onClick:()=>B(O),className:"flex items-center justify-between text-[12px] font-body text-text-secondary hover:text-text-primary cursor-pointer py-0.5",children:[s("span",{className:"truncate",children:O.split("/").pop()},void 0,!1,void 0,this),s("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 s("div",{className:"hidden lg:flex w-8 border-r border-border-subtle bg-bg-surface flex-col items-center flex-shrink-0",children:s("button",{onClick:()=>X(!1),className:"mt-3 p-1 text-text-tertiary hover:text-text-secondary transition-colors",children:s("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:s("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 s("div",{className:"hidden lg:flex w-60 border-r border-border-subtle bg-bg-surface flex-col flex-shrink-0 overflow-hidden",children:[s("div",{className:"flex items-center justify-between px-4 pt-4 pb-3 flex-shrink-0",children:[s("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:"Files"},void 0,!1,void 0,this),s("button",{onClick:()=>X(!0),className:"text-text-tertiary hover:text-text-secondary transition-colors p-0.5",children:s("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:s("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),s("div",{className:"flex-1 overflow-y-auto",children:T("")},void 0,!1,void 0,this),U.length>0&&s("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:[s("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)=>s("div",{onClick:()=>B(O),className:"flex items-center justify-between text-[12px] font-body text-text-secondary hover:text-text-primary cursor-pointer py-0.5",children:[s("span",{className:"truncate",children:O.split("/").pop()},void 0,!1,void 0,this),s("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 nQ}from"#canvas/runtime";import{useCallback as sQ,useContext as tQ,useEffect as _6,useMemo as H6,useRef as t2,useState as K2}from"react";import{jsxDEV as R$}from"react/jsx-dev-runtime";function W6($){let J=$ instanceof HTMLElement?$:$.parentElement;while(J){if(J.hasAttribute("data-line-num"))return J;J=J.parentElement}return null}function eQ($){let J=$.toString().trim(),Q=W6($.startContainer),Y=W6($.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 $7({html:$}){return R$("code",{className:"py-px",dangerouslySetInnerHTML:{__html:$}},void 0,!1,void 0,this)}function U6({path:$}){if(!z1)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$(J7,{path:$},void 0,!1,void 0,this)}function J7({path:$}){let J=tQ(nQ),{annotations:Q}=Y1(),[Y,q]=K2(null),[G,X]=K2(!0),[H,_]=K2(null),W=t2(null),[U,K]=K2(null),[z,B]=K2(null),N=t2(null),P=t2(null),M=t2([]),T=Q.filter((I)=>I.filePath===$),O=W.current?.closest("#plan-scroll-container"),{popovers:A,openCreatePopover:w}=C1({containerRef:W,restoreKey:`${Y}:${$}`,restoreAnnotations:T,extractContext:eQ,filePath:$,scrollContainer:O});_6(()=>{X(!0),_(null),fetch(`/api/file?session=${J}&path=${encodeURIComponent($)}`).then((I)=>I.json()).then((I)=>{let V=R1.parse(I);if("error"in V)_(V.error),X(!1);else q(V.content),X(!1)}).catch(()=>{_("Failed to fetch file"),X(!1)})},[J,$]);let S=sQ((I,V)=>{I.preventDefault(),N.current=V,P.current=V,K(V),B(V)},[]);_6(()=>{let I=(f)=>{if(N.current===null)return;let h=f.target.closest("[data-line-num]");if(h){let o=parseInt(h.getAttribute("data-line-num"),10);P.current=o,B(o)}},V=()=>{let f=N.current;if(f===null)return;N.current=null;let h=P.current??f,o=Math.min(f,h),B$=Math.max(f,h),U$=M.current.slice(o-1,B$).join(`
82
- `);if(!U$.trim()){K(null),B(null);return}let q$=`__pending_${Date.now()}`,z$={before:"",after:"",hierarchy:[],lineStart:o,lineEnd:B$};if(W.current){let J$=W.current.querySelectorAll("[data-line-num]"),_$=J$[o-1],L$=J$[B$-1];if(_$&&L$){let d=_$.querySelector("code"),Y$=L$.querySelector("code");if(d&&Y$)try{let v=document.createRange();v.setStartBefore(d.firstChild||d),v.setEndAfter(Y$.lastChild||Y$),F1(v,q$)}catch{}}let n=J$[B$-1];if(n)w(n,q$,U$,z$)}K(null),B(null)};return document.addEventListener("mousemove",I),document.addEventListener("mouseup",V),()=>{document.removeEventListener("mousemove",I),document.removeEventListener("mouseup",V)}},[]);let j=H6(()=>{if(!Y)return null;let I=q2();if(!I)return null;let V=$.split(".").pop()||"",f=n2[V];try{return(f?I.highlight(Y,{language:f}):I.highlightAuto(Y)).value.split(`
83
- `)}catch{return null}},[Y,$]),C=H6(()=>{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,V)=>{let f=V+1,h=C&&f>=C.start&&f<=C.end;return R$("div",{"data-line-num":f,className:`flex px-5 ${h?"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$($7,{html:j[V]||" "},void 0,!1,void 0,this):R$("code",{className:"py-px",children:I||" "},void 0,!1,void 0,this)]},V,!0,void 0,this)})},void 0,!1,void 0,this),A]},void 0,!0,void 0,this)}import{SessionContext as Q7}from"#canvas/runtime";import{useCallback as K6,useContext as q3,useEffect as B6,useMemo as q7,useRef as B2,useState as O1}from"react";import{jsxDEV as i}from"react/jsx-dev-runtime";function Y3($,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 z6($){return $.filter((J)=>J.status!=="unchanged").map((J)=>J.filename)}function N6({revision:$,responseBanner:J}){let{setActiveView:Q}=q3(J1),{revisions:Y}=q3(f$),q=Y.find((W)=>W.revision===$),G=Y.find((W)=>W.revision===$-1),X=q7(()=>Y3(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(X7,{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(W7,{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 Y7({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 X7({change:$,revision:J,previousRevision:Q,onOpenTab:Y}){let q=$.filename.replace(/\.jsx$/,""),G=$.status==="new",X=$.diffStats,H=$.status==="changed"&&Q!=null,[_,W]=O1("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(Y7,{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(b0,{revision:J,filename:$.filename},void 0,!1,void 0,this)},void 0,!1,void 0,this):H&&Q!=null?i(G7,{filename:$.filename,leftRev:Q,rightRev:J,mode:_},`${_}-${J}-${Q}`,!1,void 0,this):null]},void 0,!0,void 0,this)}function G7({filename:$,leftRev:J,rightRev:Q,mode:Y}){let q=q3(Q7);if(Y==="unified")return i(_7,{sessionId:q,filename:$,leftRev:J,rightRev:Q},void 0,!1,void 0,this);return i(H7,{sessionId:q,filename:$,leftRev:J,rightRev:Q},void 0,!1,void 0,this)}function _7({sessionId:$,filename:J,leftRev:Q,rightRev:Y}){let q=B2(null),G=B2(null),X=B2(null),[H,_]=O1(!1),[W,U]=O1(!1),[K,z]=O1(!1),[B,N]=O1(null);return B6(()=>{if(!H||!W||K)return;if(!q.current||!G.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!q.current||!G.current||!X.current)return;try{let P=V0(q.current),M=V0(G.current),T=W2(P,M),{fragment:O}=o2(T);X.current.innerHTML="",X.current.appendChild(O),z(!0)}catch(P){N(P instanceof Error?P.message:String(P))}})})},[H,W,K]),i("div",{children:[!K&&!B&&i("div",{style:{position:"absolute",left:-9999,visibility:"hidden",pointerEvents:"none",width:720},children:[i(M1,{ref:q,sessionId:$,revision:Q,filename:J,onReady:()=>_(!0),onError:(P)=>N(P)},void 0,!1,void 0,this),i(M1,{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),!K&&!B&&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),B&&i("div",{className:"text-accent-red text-[13px] font-body p-3 bg-accent-red-muted rounded-lg",children:B},void 0,!1,void 0,this),i("div",{ref:X},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function H7({sessionId:$,filename:J,leftRev:Q,rightRev:Y}){let q=B2(null),G=B2(null),[X,H]=O1(!1),[_,W]=O1(!1),[U,K]=O1(!1),z=K6(()=>H(!0),[]),B=K6(()=>W(!0),[]);return B6(()=>{if(!X||!_||U)return;if(!q.current||!G.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!q.current||!G.current)return;i2(q.current,G.current),K(!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(M1,{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(M1,{ref:G,sessionId:$,revision:Y,filename:J,onReady:B},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 W7({change:$,revision:J,onOpenTab:Q}){let[Y,q]=O1(!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(b0,{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 U7,useRef as K7,useState as B7}from"react";import{jsxDEV as l$}from"react/jsx-dev-runtime";function M6({open:$,onClose:J,onSubmit:Q}){let[Y,q]=B7(""),G=K7(null);if(U7(()=>{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 O6,useRef as z7,useState as L6}from"react";import{jsxDEV as X1}from"react/jsx-dev-runtime";function F6($,J){if(J){let Q=J.replace(/\/+$/,"").split("/");return Q[Q.length-1]||$}return $.length>30?$.slice(0,30)+"...":$}function X3({currentSessionId:$,projectRoot:J}){let[Q,Y]=L6([]),[q,G]=L6(!1),X=z7(null);O6(()=>{if(!z1)return;let W=async()=>{try{let z=await(await fetch("/api/sessions")).json();Y((B)=>{let N=JSON.stringify(z);return JSON.stringify(B)===N?B:z})}catch{}};W();let U=setInterval(W,5000);return()=>clearInterval(U)},[]),O6(()=>{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!==$),_=F6($,J);return X1("div",{className:"relative",ref:X,children:[X1("div",{className:"flex items-center gap-1.5 font-body text-body font-medium",children:[X1("a",{href:`/s/${$}`,className:"text-text-primary hover:text-text-secondary transition-colors",children:_},void 0,!1,void 0,this),H.length>0&&X1("button",{onClick:()=>G(!q),className:"flex items-center justify-center text-text-tertiary hover:text-text-secondary transition-colors",children:X1("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:`transition-transform duration-200 ${q?"rotate-180":""}`,children:X1("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&&X1("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)=>X1("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:[X1("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),X1("span",{className:"truncate",children:F6(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 G3,useEffect as N7,useState as e2}from"react";import{jsxDEV as G$}from"react/jsx-dev-runtime";function A6({sessionId:$,revision:J,open:Q,shareEnabled:Y,existingShares:q,onClose:G,onShareCreated:X,onShareRevoked:H}){let[_,W]=e2(!1),[U,K]=e2(!1),[z,B]=e2(null),[N,P]=e2(!1),M=q.find((w)=>w.revision===J);N7(()=>{if(!Q)W(!1),K(!1),B(null),P(!1)},[Q]);let T=G3(async()=>{W(!0),B(null);try{let w=await fetch(`/api/session/${$}/revision/${J}/share`,{method:"POST"}),S=k5.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){B(U2(w))}finally{W(!1)}},[$,J,X]),O=G3(async(w)=>{if(!window.confirm("Revoke this share link? Reviewers will no longer be able to view or comment."))return;K(!0),B(null);try{let S=await fetch(`/api/session/${$}/shares/${w}/revoke`,{method:"POST"}),j=y5.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){B(U2(S))}finally{K(!1)}},[$,H]),A=G3((w)=>{navigator.clipboard.writeText(w).then(()=>{P(!0),setTimeout(()=>P(!1),1500)})},[]);if(!Q)return null;return G$("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:G,children:G$("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:[G$("div",{className:"flex items-center justify-between mb-3",children:[G$("h2",{className:"text-sm font-medium text-text-primary font-body",children:"Share this revision"},void 0,!1,void 0,this),G$("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:G$("span",{className:"text-xs",children:"✕"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!Y?G$("div",{className:"text-[13px] text-text-secondary font-body space-y-2",children:[G$("p",{children:"Canvas sharing is not configured."},void 0,!1,void 0,this),G$("p",{className:"text-text-tertiary",children:["Set ",G$("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"," ",G$("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?G$("div",{className:"space-y-3",children:[G$("p",{className:"text-[13px] text-text-secondary font-body",children:"This revision is shared:"},void 0,!1,void 0,this),G$("div",{className:"flex gap-2",children:[G$("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),G$("button",{onClick:()=>A(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&&G$("p",{className:"text-[11px] text-text-tertiary font-body",children:["Expires ",new Date(M.expiresAt).toLocaleDateString(),"."]},void 0,!0,void 0,this),M.encryptionKey&&G$("p",{className:"text-[11px] text-accent-green font-body flex items-center gap-1.5",children:[G$("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[G$("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"},void 0,!1,void 0,this),G$("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),G$("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),G$("div",{className:"flex items-center justify-between pt-1",children:[G$("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&&G$("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):G$("div",{className:"space-y-3",children:[G$("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),G$("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&&G$("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 S6({onClick:$,title:J="Share this revision",hasShare:Q}){return G$("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:G$("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[G$("circle",{cx:"18",cy:"5",r:"3"},void 0,!1,void 0,this),G$("circle",{cx:"6",cy:"12",r:"3"},void 0,!1,void 0,this),G$("circle",{cx:"18",cy:"19",r:"3"},void 0,!1,void 0,this),G$("line",{x1:"8.59",y1:"13.51",x2:"15.42",y2:"17.49"},void 0,!1,void 0,this),G$("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 F,Fragment as z2}from"react/jsx-dev-runtime";function w6($){let J=[];for(let Q of $)for(let Y of Q.annotations)J.push({...Y,source:"remote",author:Q.author});return J}function F7($){if($==="auto")return window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light";return $}function T6($){document.documentElement.dataset.theme=F7($)}function Z6(){let[$,J]=O$(()=>{let q=localStorage.getItem("canvas-theme");if(q==="light"||q==="dark"||q==="auto")return q;return"auto"});return d$(()=>{if(T6($),$!=="auto")return;let q=window.matchMedia("(prefers-color-scheme: dark)"),G=()=>T6("auto");return q.addEventListener("change",G),()=>q.removeEventListener("change",G)},[$]),F("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"?F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[F("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2",ry:"2"},void 0,!1,void 0,this),F("line",{x1:"8",y1:"21",x2:"16",y2:"21"},void 0,!1,void 0,this),F("line",{x1:"12",y1:"17",x2:"12",y2:"21"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):$==="dark"?F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:F("path",{d:"M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"},void 0,!1,void 0,this)},void 0,!1,void 0,this):F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[F("circle",{cx:"12",cy:"12",r:"5"},void 0,!1,void 0,this),F("line",{x1:"12",y1:"1",x2:"12",y2:"3"},void 0,!1,void 0,this),F("line",{x1:"12",y1:"21",x2:"12",y2:"23"},void 0,!1,void 0,this),F("line",{x1:"4.22",y1:"4.22",x2:"5.64",y2:"5.64"},void 0,!1,void 0,this),F("line",{x1:"18.36",y1:"18.36",x2:"19.78",y2:"19.78"},void 0,!1,void 0,this),F("line",{x1:"1",y1:"12",x2:"3",y2:"12"},void 0,!1,void 0,this),F("line",{x1:"21",y1:"12",x2:"23",y2:"12"},void 0,!1,void 0,this),F("line",{x1:"4.22",y1:"19.78",x2:"5.64",y2:"18.36"},void 0,!1,void 0,this),F("line",{x1:"18.36",y1:"5.64",x2:"19.78",y2:"4.22"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function C6(){let{currentRevision:$,selectedRevision:J,revisions:Q,setSelectedRevision:Y,setCompareRevision:q}=E1.useContext(f$);if(Q.length<=1){let H=Q[0]?.label||`Round ${$}`;return F("span",{className:"text-[11px] text-text-tertiary font-body",children:H},void 0,!1,void 0,this)}return F("div",{className:"flex flex-col gap-1",children:[F(_2,{value:J,onChange:Y,accent:J===$?"default":"amber"},void 0,!1,void 0,this),F("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 A7(){let $=K$.isShared?K$.shareId:K$.sessionId,J=K$.isShared,[Q,Y]=O$(1),[q,G]=O$(1),[X,H]=O$([]),[_,W]=O$(null),[U,K]=O$(!1),[z,B]=O$(!1),[N,P]=O$(!1),[M,T]=O$([]),[O,A]=O$({type:"overview"}),[w,S]=O$([]),j=G1(null),C=G1([]),y=G1(new Set),[I,V]=O$(),[f,h]=O$(!1),[o,B$]=O$(!1),[a,U$]=O$(!1),[q$,z$]=O$(!1),[J$,_$]=O$([]),[L$,n]=O$(!1),[d,Y$]=O$(new Map),[v,c]=O$(!1),[E,R]=O$(null),[x,r]=O$(null),M$=Z0((D)=>{if(J)return;let t=`${D.revision}\x00${D.filename}\x00${D.message}`;if(y.current.has(t))return;y.current.add(t);let H$=JSON.stringify({type:"render-error",error:D});if(j.current?.readyState===WebSocket.OPEN)j.current.send(H$);else C.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 t=I.replace(/\/+$/,"").split("/");D.push(t[t.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$=G1(new Map),w$=X.find((D)=>D.revision===q),r$=q!==Q||!!w$?.hasFeedback||z,_3=q===Q&&(!!w$?.hasFeedback||z)?"next":"current",H3=Z0((D)=>{let t=O.type==="overview"?"overview":O.type==="canvas"?`canvas:${O.filename}`:`file:${O.path}`;if(F$.current.set(t,window.scrollY),A(D),D.type==="file")S((H$)=>H$.includes(D.path)?H$:[...H$,D.path])},[O]),R6=Z0((D)=>{F$.current.delete(`file:${D}`),S((t)=>t.filter((H$)=>H$!==D)),A((t)=>{if(t.type==="file"&&t.path===D)return M.length>1?{type:"overview"}:{type:"canvas",filename:M[0]||""};return t})},[M]);O7(()=>{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;g5().then((D)=>{if(D.currentRevision){let t=D.revisions||[];for(let H$ of t)if(H$.hasFeedback)r1(localStorage,$,H$.revision);y2(localStorage,$,D.currentRevision,t),Y(D.currentRevision),G(D.currentRevision),H(t)}if(D.canvasFiles){let t=D.canvasFiles.sort();T(t),A((H$)=>{if(H$.type==="overview")return t.length>1?H$:{type:"canvas",filename:t[0]||""};if(H$.type==="canvas"&&(!H$.filename||!t.includes(H$.filename)))return{type:"canvas",filename:t[0]||""};return H$})}if(D.projectRoot)V(D.projectRoot);if(Array.isArray(D.shares))_$(D.shares);n(!!D.shareEnabled)}).catch(()=>{})},[$]),d$(()=>{if(!$||!q||J)return;fetch(`/api/session/${$}/revision/${q}/remote-feedback`).then((D)=>D.json()).then((D)=>{let t=D5.safeParse(D);if(!t.success)return;let H$=w6(t.data.entries);Y$((i$)=>{let o$=new Map(i$);return o$.set(q,H$),o$})}).catch(()=>{})},[$,q,J]),d$(()=>{if(!$)return;if(!u5){K(!0);return}let D=null,t=()=>{let H$=window.location.protocol==="https:"?"wss:":"ws:",i$=new WebSocket(`${H$}//${window.location.host}/ws/session/${$}`);j.current=i$,i$.onopen=()=>{K(!0);for(let o$ of C.current)i$.send(JSON.stringify({type:"render-error",error:o$}));C.current=[]},i$.onclose=()=>{K(!1),D=setTimeout(t,2000)},i$.onmessage=(o$)=>{try{let T$=JSON.parse(o$.data);if(T$.type==="plan-updated"){let I$=Array.isArray(T$.revisions)?T$.revisions:[];if(y2(localStorage,$,T$.currentRevision,I$),Y(T$.currentRevision),G(T$.currentRevision),W(null),I$.length>0){H(I$);let L1=I$.find((f1)=>f1.revision===T$.currentRevision);if(L1?.canvasFiles){let f1=L1.canvasFiles.map((R0)=>R0.filename).sort();T(f1);let J4=I$.find((R0)=>R0.revision===T$.currentRevision-1),C0=Y3(L1,J4),$0=z6(C0);if($0.length===1)A({type:"canvas",filename:$0[0]});else if($0.length>1||f1.length>1)A({type:"overview"});else A({type:"canvas",filename:f1[0]||""})}}}if(T$.type==="revision-updated"){if(Array.isArray(T$.revisions)){let I$=T$.revisions;for(let L1 of I$)if(L1.hasFeedback)r1(localStorage,$,L1.revision);H(I$)}}if(T$.type==="watcher-status")P(!!T$.watching);if(T$.type==="remote-feedback"){let I$=T$.revision,L1=T$.entries||[],f1=w6(L1);Y$((J4)=>{let C0=new Map(J4),$0=C0.get(I$)||[],R0=new Set($0.map((Q4)=>Q4.id)),I6=[...$0,...f1.filter((Q4)=>!R0.has(Q4.id))];return C0.set(I$,I6),C0})}}catch{}}};return t(),()=>{if(D)clearTimeout(D);j.current?.close()}},[$]);let $4=Z0(async(D,t)=>{try{let H$=localStorage.getItem(`canvas:${$}:rev:${q}`),i$=[],o$=[];if(H$)try{let T$=S0(JSON.parse(H$));i$=(T$?.annotations??[]).filter((I$)=>I$.source!=="remote"),o$=C5((T$?.responses??[]).map(([,I$])=>I$))}catch{}await h5({author:t,revision:q,annotations:i$,generalNote:D,...o$.length>0?{responses:o$}:{}}),r1(localStorage,$,q),B(!0),r({kind:"success",message:"Feedback submitted. The canvas author will see it shortly."})}catch(H$){r({kind:"error",message:`Failed to submit feedback: ${U2(H$)}`})}},[$,q]),W3=Z0(async(D)=>{if(J){let t=e4();if(!t){R(D),c(!0);return}await $4(D,t);return}if(j.current?.readyState===WebSocket.OPEN)j.current.send(JSON.stringify({type:"submit",feedback:D}))},[J,$4]);if(!$)return F("div",{className:"flex items-center justify-center h-screen text-text-tertiary font-body",children:"No session selected."},void 0,!1,void 0,this);return F(f2.Provider,{value:p5,children:F(V6.Provider,{value:$,children:F(Y2.Provider,{value:M$,children:F(f$.Provider,{value:{currentRevision:Q,selectedRevision:q,revisions:X,setSelectedRevision:G,isReadOnly:r$,compareRevision:_,setCompareRevision:W,agentWatching:N},children:F(E4,{sessionId:$,revision:q,isReadOnly:r$,draftPhase:_3,remoteAnnotations:d.get(q),canvasFiles:M,children:F(J1.Provider,{value:{activeView:O,setActiveView:H3,openFiles:w,closeFile:R6,canvasFiles:M},children:F(M7.Provider,{value:{setActiveView:H3},children:F("div",{className:"min-h-screen bg-bg-base",children:[F(S7,{sessionId:$,projectRoot:I,connected:U,onMobileSidebar:()=>h(!f),collapsed:o,onToggle:()=>B$((D)=>!D)},void 0,!1,void 0,this),F(P7,{collapsed:a,onToggle:()=>U$((D)=>!D),children:F(l2,{onSubmit:W3},void 0,!1,void 0,this)},void 0,!1,void 0,this),_!==null?F("div",{className:`${o?"lg:ml-0":"lg:ml-60"} ${a?"lg:mr-0":"lg:mr-[var(--sidebar-width,320px)]"} transition-[margin] duration-200`,children:F(Q6,{initialLeft:_.left,initialRight:_.right,sessionId:$,onExit:()=>W(null)},void 0,!1,void 0,this)},void 0,!1,void 0,this):F("div",{className:`relative ${o?"lg:ml-0":"lg:ml-60"} ${a?"lg:mr-0":"lg:mr-[var(--sidebar-width,320px)]"} transition-[margin] duration-200`,id:"plan-scroll-container",children:[F("div",{className:"lg:hidden sticky top-0 z-20 flex items-center justify-between px-4 py-2 border-b border-border-subtle bg-bg-surface",children:[F("div",{className:"flex items-center gap-2",children:[!J&&F(X3,{currentSessionId:$,projectRoot:I},void 0,!1,void 0,this),J&&F("span",{className:"text-[11px] text-text-tertiary font-body",children:"Shared canvas"},void 0,!1,void 0,this),!J&&F("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),F("div",{className:"flex items-center gap-1",children:[F(C6,{},void 0,!1,void 0,this),F("button",{onClick:()=>h(!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:F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:F("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),F(Z6,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),F(w7,{},void 0,!1,void 0,this),O.type==="overview"&&F(N6,{revision:q,responseBanner:w$?.response?F(j6,{markdown:w$.response},void 0,!1,void 0,this):void 0},void 0,!1,void 0,this),O.type==="canvas"&&M.includes(O.filename)&&F("div",{className:"relative max-w-[720px] mx-auto px-6 pt-12 pb-32",children:[L$&&F("div",{className:"absolute top-3 right-12 z-10",children:F(S6,{onClick:()=>z$(!0),hasShare:J$.some((D)=>D.revision===q),title:J$.some((D)=>D.revision===q)?"Manage share link":"Share this revision"},void 0,!1,void 0,this)},void 0,!1,void 0,this),F("button",{onClick:()=>{let D=document.querySelector(`[data-canvas-file="${O.filename}"] .plan-content`);if(!D)return;let t=q6(D);navigator.clipboard.writeText(t).then(()=>{let H$=document.getElementById("export-md-btn");if(H$)H$.setAttribute("data-copied","true"),setTimeout(()=>{H$.removeAttribute("data-copied")},1500)})},id:"export-md-btn",className:"group absolute top-3 right-6 p-1.5 text-text-tertiary hover:text-text-secondary transition-colors z-10",title:"Copy as Markdown",children:[F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"group-[[data-copied=true]]:hidden",children:[F("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"},void 0,!1,void 0,this),F("path",{d:"M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"hidden group-[[data-copied=true]]:block text-green-500",children:F("polyline",{points:"20 6 9 17 4 12"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),M.length<=1&&w$?.response&&F(j6,{markdown:w$.response},void 0,!1,void 0,this),F("div",{"data-canvas-file":O.filename,children:F(b0,{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)=>F("div",{style:{display:O.type==="file"&&O.path===D?void 0:"none"},children:F(U6,{path:D},void 0,!1,void 0,this)},D,!1,void 0,this))]},void 0,!0,void 0,this),f&&F("div",{className:"lg:hidden fixed inset-0 z-40 flex",children:[F("div",{className:"flex-1",onClick:()=>h(!1)},void 0,!1,void 0,this),F("div",{className:"w-80 max-w-[85vw] bg-bg-surface border-l border-border-subtle flex flex-col shadow-lg",children:[F("div",{className:"flex items-center justify-between px-4 py-2 border-b border-border-subtle flex-shrink-0",children:[F("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:"Sidebar"},void 0,!1,void 0,this),F("button",{onClick:()=>h(!1),className:"text-text-tertiary hover:text-text-secondary w-7 h-7 flex items-center justify-center",children:"✕"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("div",{className:"flex-1 overflow-hidden",children:F(l2,{onSubmit:W3},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),F(A6,{sessionId:$,revision:q,open:q$,shareEnabled:L$,existingShares:J$,onClose:()=>z$(!1),onShareCreated:(D)=>{_$((t)=>[...t.filter((H$)=>H$.shareId!==D.shareId),D]),r({kind:"success",message:"Share link created. Copy and send it to reviewers."})},onShareRevoked:(D)=>{_$((t)=>t.filter((H$)=>H$.shareId!==D)),r({kind:"success",message:"Share link revoked."})}},void 0,!1,void 0,this),F(M6,{open:v,onClose:()=>{c(!1),R(null)},onSubmit:async(D)=>{let t=x5(D);if(c(!1),E!==null)await $4(E,t),R(null)}},void 0,!1,void 0,this),x&&F("div",{className:`fixed bottom-4 left-1/2 -translate-x-1/2 z-50 px-4 py-2.5 rounded-lg shadow-lg text-[13px] font-body font-medium flex items-center gap-2 ${x.kind==="error"?"bg-accent-red text-white":"bg-accent-green text-white"}`,children:[x.message,F("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}:${_3}`,!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 S7({sessionId:$,projectRoot:J,connected:Q,onMobileSidebar:Y,collapsed:q,onToggle:G}){let X=K$.isShared;return F(z2,{children:[q&&F("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:F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[F("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"},void 0,!1,void 0,this),F("line",{x1:"9",y1:"3",x2:"9",y2:"21"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this),F("div",{className:`hidden lg:flex w-60 flex-col fixed top-0 left-0 bottom-0 bg-bg-surface border-r border-border-subtle z-10 transition-transform duration-200 ${q?"-translate-x-full":""}`,children:[F("div",{className:"px-4 pt-4 pb-3 flex-shrink-0 border-b border-border-subtle",children:[F("div",{className:"flex items-center gap-2 mb-2",children:[F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",className:"text-text-tertiary flex-shrink-0",children:F("path",{d:"M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this),X?F("span",{className:"text-[12px] font-body text-text-secondary truncate flex-1",children:"Shared canvas"},void 0,!1,void 0,this):F(z2,{children:[F(X3,{currentSessionId:$,projectRoot:J},void 0,!1,void 0,this),F("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${Q?"bg-accent-green":"bg-accent-red"}`},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("button",{onClick: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:F("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[F("polyline",{points:"11 17 6 12 11 7"},void 0,!1,void 0,this),F("polyline",{points:"18 17 13 12 18 7"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F(C6,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("div",{className:"flex-1 flex flex-col overflow-hidden",children:F(G6,{embedded:!0},void 0,!1,void 0,this)},void 0,!1,void 0,this),F("div",{className:"px-4 py-3 border-t border-border-subtle flex items-center justify-between flex-shrink-0",children:[F("span",{className:"text-[10px] text-text-tertiary font-body uppercase tracking-widest",children:"Theme"},void 0,!1,void 0,this),F(Z6,{},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 P7({children:$,collapsed:J,onToggle:Q}){let[Y,q]=O$(()=>{let U=localStorage.getItem("canvas-sidebar-width");return U?parseInt(U,10):320}),G=G1(!1),X=G1(0),H=G1(0),_=G1(Y);_.current=Y;let W=Z0((U)=>{U.preventDefault(),G.current=!0,X.current=U.clientX,H.current=_.current;let K=(B)=>{if(!G.current)return;let N=X.current-B.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",K),document.removeEventListener("mouseup",z),document.body.style.cursor="",document.body.style.userSelect=""};document.addEventListener("mousemove",K),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]),F(z2,{children:[J&&F("button",{onClick:Q,className:"hidden lg:flex fixed top-3 right-3 z-20 w-7 h-7 items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors bg-bg-surface border border-border-subtle",title:"Show annotations",children:F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:F("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this),F("div",{className:`hidden lg:flex flex-col fixed top-0 right-0 bottom-0 bg-bg-surface border-l border-border-subtle z-10 transition-transform duration-200 ${J?"translate-x-full":""}`,style:{width:Y},children:[F("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),E1.Children.map($,(U)=>E1.isValidElement(U)?E1.cloneElement(U,{collapseButton:F("button",{onClick:Q,className:"w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Hide annotations",children:F("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[F("polyline",{points:"13 17 18 12 13 7"},void 0,!1,void 0,this),F("polyline",{points:"6 17 11 12 6 7"},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}):U)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function j6({markdown:$}){let[J,Q]=O$(!1),Y=P6(()=>X$.parse($,{async:!1}),[$]),q=G1(null),{annotations:G,addAnnotationWithId:X,removeAnnotation:H,updateAnnotation:_,addAnnotationImage:W,removeAnnotationImage:U,activeAnnotationId:K,setActiveAnnotationId:z}=Y1(),[B,N]=O$(null),[P,M]=O$(null),T=P6(()=>G.filter((j)=>j.filePath===u$),[G]),[O,A]=O$($);if($!==O)A($),Q(!1);d$(()=>{if(!q.current||T.length===0)return;let j=setTimeout(()=>{if(q.current)y0(q.current,T)},50);return()=>clearTimeout(j)},[Y,T.length]);let w=G1(null);if(d$(()=>{D0(K,w.current),w.current=K},[K]),d$(()=>{let j=q.current;if(!j)return;let C=(V)=>{let f=V.target.closest("[data-annotation-id]");if(!f)return;V.stopPropagation();let h=f.getAttribute("data-annotation-id");if(h===K)M({anchorEl:f,annId:h});else z(h)},y=(V)=>{let f=V.target.closest("[data-annotation-id]");if(f)z(f.getAttribute("data-annotation-id"))},I=(V)=>{let f=V.target.closest("[data-annotation-id]"),h=V.relatedTarget?.closest?.("[data-annotation-id]");if(f&&!h)z(null)};return j.addEventListener("click",C),j.addEventListener("mouseover",y),j.addEventListener("mouseout",I),()=>{j.removeEventListener("click",C),j.removeEventListener("mouseover",y),j.removeEventListener("mouseout",I)}},[Y,K]),d$(()=>{let j=()=>{let C=window.getSelection();if(!C||C.isCollapsed||!C.toString().trim())return;if(!q.current)return;let y=C.getRangeAt(0);if(!q.current.contains(y.startContainer))return;if(y.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let I=C.toString().trim();if(I.length<2)return;let V=y.cloneRange(),f=A1(y,q.current),h=`__pending_${Date.now()}`;try{F1(V,h)}catch{}window.getSelection()?.removeAllRanges();let o=document.querySelectorAll(`[data-annotation-id="${h}"]`),B$=o[o.length-1];if(!B$)return;N({anchorEl:B$,tempId:h,snippet:I,ctx:f})};return document.addEventListener("mouseup",j),()=>document.removeEventListener("mouseup",j)},[]),J)return null;let S=document.getElementById("plan-scroll-container");return F("div",{className:"mb-6 rounded-lg border border-accent-blue/20 bg-accent-blue/5 relative",children:[F("button",{onClick:()=>Q(!0),className:"absolute top-2 right-2 w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",children:F("span",{className:"text-xs",children:"✕"},void 0,!1,void 0,this)},void 0,!1,void 0,this),F("div",{className:"px-4 py-3 pr-10",children:[F("div",{className:"flex items-center gap-2 mb-1.5",children:[F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-accent-blue flex-shrink-0",children:F("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},void 0,!1,void 0,this)},void 0,!1,void 0,this),F("span",{className:"text-[11px] font-medium uppercase tracking-widest text-accent-blue font-body",children:"Agent Response"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("div",{ref:q,className:"prose-canvas text-sm",dangerouslySetInnerHTML:{__html:Y}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),B&&F(e$,{anchorEl:B.anchorEl,scrollContainer:S,snippet:B.snippet,truncateAt:80,onAdd:(j,C)=>{let y=E$();k0(B.tempId,y),X(y,B.snippet,j,u$,B.ctx,C),N(null)},onCancel:()=>{E0(B.tempId),N(null)}},void 0,!1,void 0,this),P&&(()=>{let j=G.find((C)=>C.id===P.annId);if(!j)return null;return F(l1,{anchorEl:P.anchorEl,scrollContainer:S,initialNote:j.note,initialImages:j.images,onUpdate:(C,y)=>{_(P.annId,C);let I=j.images||[];for(let V of y)if(!I.includes(V))W(P.annId,V);for(let V of I)if(!y.includes(V))U(P.annId,V)},onDelete:()=>{H(P.annId),z(null)},onClose:()=>M(null)},void 0,!1,void 0,this)})()]},void 0,!0,void 0,this)}function w7(){let{activeView:$,setActiveView:J,openFiles:Q,closeFile:Y,canvasFiles:q}=E1.useContext(J1),G=E1.useContext(V6),{addAnnotationWithId:X,setActiveAnnotationId:H}=Y1();if(!(q.length>1||Q.length>0))return null;return F("div",{className:"flex items-center border-b border-border-medium bg-bg-surface overflow-x-auto sticky top-0 z-10",children:[q.length>1&&F(z2,{children:[F("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:[F("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",className:"opacity-60",children:F("path",{d:"M12 7L2 12l10 5 10-5-10-5z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},void 0,!1,void 0,this)},void 0,!1,void 0,this),"Overview",$.type==="overview"&&F("span",{className:"absolute bottom-0 left-3 right-3 h-[2px] bg-text-primary rounded-full"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),q.map((W,U)=>{let K=W.replace(/\.jsx$/,""),z=$.type==="canvas"&&$.filename===W;return F(E1.Fragment,{children:[F("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:[K,z&&F("span",{className:"absolute bottom-0 left-3 right-3 h-[2px] bg-text-primary rounded-full"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),U<q.length-1&&F("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&&F(z2,{children:[F("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this),Q.map((W,U)=>{let K=W.split("/").pop()||W,z=$.type==="file"&&$.path===W;return F(E1.Fragment,{children:[F("div",{className:"flex items-center",children:[F("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:[F(I1,{name:K,type:"file"},void 0,!1,void 0,this),K,z&&F("span",{className:"absolute bottom-0 left-3 right-1 h-[2px] bg-text-primary rounded-full"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),F("button",{onClick:(B)=>{B.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&&F("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),F("div",{className:"ml-auto flex items-center gap-1 flex-shrink-0",children:$.type==="file"&&z1&&F("button",{onClick:async()=>{let W=$.path;try{let U=await fetch(`/api/file?session=${G}&path=${encodeURIComponent(W)}`),K=R1.parse(await U.json());if("content"in K){let z=K.content.split(`
82
+ ...`:"");Y(j,"Include this file for context",z)}},L=async(z)=>{let A=[];if(W[z]?.loaded)A=W[z].entries;else{let T=await fetch(`/api/tree?session=${Q}&path=${encodeURIComponent(z)}`),S=_3.safeParse(await T.json());if(S.success)A=S.data.entries}await Promise.all(A.filter((T)=>T.type==="file").map((T)=>M(z?`${z}/${T.name}`:T.name)))},F=(z)=>H.get(z)||0,w=(z,A=0)=>{let T=W[z];if(!T?.expanded)return null;return T.entries.map((S)=>{let j=z?`${z}/${S.name}`:S.name,Z=F(j);return s("div",{children:[s("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+A*16}px`,paddingRight:"8px"},children:S.type==="dir"?s(O3,{children:[s("span",{onClick:()=>N(j),className:"flex items-center gap-1.5 flex-1 text-text-secondary hover:text-text-primary cursor-pointer truncate",children:[s(I1,{name:S.name,type:"dir",expanded:W[j]?.expanded},void 0,!1,void 0,this),s("span",{className:"truncate",children:S.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this),s("button",{onClick:(y)=>{y.stopPropagation(),L(j)},className:"text-[11px] text-text-tertiary hover:text-text-secondary opacity-0 group-hover/item:opacity-100 transition-opacity px-1 flex-shrink-0",title:"Add all files in folder",children:"+"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):s(O3,{children:[s("span",{onClick:()=>O(j),className:`flex-1 truncate cursor-pointer flex items-center gap-1.5 ${Z>0?"text-text-primary":"text-text-secondary hover:text-text-primary"}`,children:[s(I1,{name:S.name,type:"file"},void 0,!1,void 0,this),s("span",{className:"truncate",children:S.name},void 0,!1,void 0,this)]},void 0,!0,void 0,this),s("div",{className:"flex items-center gap-1 flex-shrink-0 ml-1",children:[Z>0&&s("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:Z},void 0,!1,void 0,this),s("button",{onClick:(y)=>{y.stopPropagation(),M(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"&&w(j,A+1)]},j,!0,void 0,this)})};if($)return s(O3,{children:[s("div",{className:"flex items-center justify-between px-4 pt-3 pb-2 flex-shrink-0",children:s("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),s("div",{className:"flex-1 overflow-y-auto",children:w("")},void 0,!1,void 0,this),U.length>0&&s("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:[s("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((z)=>s("div",{onClick:()=>O(z),className:"flex items-center justify-between text-[12px] font-body text-text-secondary hover:text-text-primary cursor-pointer py-0.5",children:[s("span",{className:"truncate",children:z.split("/").pop()},void 0,!1,void 0,this),s("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:F(z)},void 0,!1,void 0,this)]},z,!0,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this);if(G)return s("div",{className:"hidden lg:flex w-8 border-r border-border-subtle bg-bg-surface flex-col items-center flex-shrink-0",children:s("button",{onClick:()=>X(!1),className:"mt-3 p-1 text-text-tertiary hover:text-text-secondary transition-colors",children:s("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:s("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 s("div",{className:"hidden lg:flex w-60 border-r border-border-subtle bg-bg-surface flex-col flex-shrink-0 overflow-hidden",children:[s("div",{className:"flex items-center justify-between px-4 pt-4 pb-3 flex-shrink-0",children:[s("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:"Files"},void 0,!1,void 0,this),s("button",{onClick:()=>X(!0),className:"text-text-tertiary hover:text-text-secondary transition-colors p-0.5",children:s("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",children:s("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),s("div",{className:"flex-1 overflow-y-auto",children:w("")},void 0,!1,void 0,this),U.length>0&&s("div",{className:"border-t border-border-subtle px-4 py-3 flex-shrink-0",children:[s("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((z)=>s("div",{onClick:()=>O(z),className:"flex items-center justify-between text-[12px] font-body text-text-secondary hover:text-text-primary cursor-pointer py-0.5",children:[s("span",{className:"truncate",children:z.split("/").pop()},void 0,!1,void 0,this),s("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:F(z)},void 0,!1,void 0,this)]},z,!0,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}import{SessionContext as r7}from"#canvas/runtime";import{useCallback as i7,useContext as o7,useEffect as f6,useMemo as E6,useRef as Y4,useState as M2}from"react";import{jsxDEV as D$}from"react/jsx-dev-runtime";function v6($){let Q=$ instanceof HTMLElement?$:$.parentElement;while(Q){if(Q.hasAttribute("data-line-num"))return Q;Q=Q.parentElement}return null}function a7($){let Q=$.toString().trim(),J=v6($.startContainer),Y=v6($.endContainer),q=J?parseInt(J.getAttribute("data-line-num"),10):void 0,G=Y?parseInt(Y.getAttribute("data-line-num"),10):void 0,X="",W="";if(Q.length<30&&J&&J===Y){let _=J.querySelector("code");if(_){let H=_.textContent||"",U=H.indexOf(Q);if(U>=0)X=H.slice(0,U).trimStart(),W=H.slice(U+Q.length).trimEnd()}}return{before:X,after:W,hierarchy:[],lineStart:q,lineEnd:G}}function n7({html:$}){return D$("code",{className:"py-px",dangerouslySetInnerHTML:{__html:$}},void 0,!1,void 0,this)}function g6({path:$}){if(!O1)return D$("div",{className:"max-w-[720px] mx-auto px-6 pt-12 pb-32",children:D$("div",{className:"p-4 rounded-lg border border-border-subtle bg-bg-surface",children:[D$("div",{className:"text-[11px] uppercase tracking-widest text-text-tertiary font-body mb-2",children:"File not available"},void 0,!1,void 0,this),D$("p",{className:"text-[13px] text-text-secondary font-body leading-relaxed",children:["Opening ",D$("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"," ",D$("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 D$(s7,{path:$},void 0,!1,void 0,this)}function s7({path:$}){let Q=o7(r7),{annotations:J}=G1(),[Y,q]=M2(null),[G,X]=M2(!0),[W,_]=M2(null),H=Y4(null),[U,K]=M2(null),[N,O]=M2(null),M=Y4(null),L=Y4(null),F=Y4([]),w=J.filter((V)=>V.filePath===$),z=H.current?.closest("#plan-scroll-container"),{popovers:A,openCreatePopover:T}=R1({containerRef:H,restoreKey:`${Y}:${$}`,restoreAnnotations:w,extractContext:a7,filePath:$,scrollContainer:z});f6(()=>{X(!0),_(null),fetch(`/api/file?session=${Q}&path=${encodeURIComponent($)}`).then((V)=>V.json()).then((V)=>{let C=D1.parse(V);if("error"in C)_(C.error),X(!1);else q(C.content),X(!1)}).catch(()=>{_("Failed to fetch file"),X(!1)})},[Q,$]);let S=i7((V,C)=>{V.preventDefault(),M.current=C,L.current=C,K(C),O(C)},[]);f6(()=>{let V=(v)=>{if(M.current===null)return;let h=v.target.closest("[data-line-num]");if(h){let o=parseInt(h.getAttribute("data-line-num"),10);L.current=o,O(o)}},C=()=>{let v=M.current;if(v===null)return;M.current=null;let h=L.current??v,o=Math.min(v,h),B$=Math.max(v,h),U$=F.current.slice(o-1,B$).join(`
83
+ `);if(!U$.trim()){K(null),O(null);return}let Y$=`__pending_${Date.now()}`,N$={before:"",after:"",hierarchy:[],lineStart:o,lineEnd:B$};if(H.current){let Q$=H.current.querySelectorAll("[data-line-num]"),_$=Q$[o-1],F$=Q$[B$-1];if(_$&&F$){let d=_$.querySelector("code"),X$=F$.querySelector("code");if(d&&X$)try{let g=document.createRange();g.setStartBefore(d.firstChild||d),g.setEndAfter(X$.lastChild||X$),A1(g,Y$)}catch{}}let n=Q$[B$-1];if(n)T(n,Y$,U$,N$)}K(null),O(null)};return document.addEventListener("mousemove",V),document.addEventListener("mouseup",C),()=>{document.removeEventListener("mousemove",V),document.removeEventListener("mouseup",C)}},[]);let j=E6(()=>{if(!Y)return null;let V=W2();if(!V)return null;let C=$.split(".").pop()||"",v=J4[C];try{return(v?V.highlight(Y,{language:v}):V.highlightAuto(Y)).value.split(`
84
+ `)}catch{return null}},[Y,$]),Z=E6(()=>{if(U===null)return null;let V=N??U;return{start:Math.min(U,V),end:Math.max(U,V)}},[U,N]);if(G)return D$("div",{className:"flex items-center justify-center h-64 text-text-tertiary font-body text-[13px]",children:["Loading ",$,"..."]},void 0,!0,void 0,this);if(W)return D$("div",{className:"p-8 text-accent-red font-body text-[13px]",children:W},void 0,!1,void 0,this);if(!Y)return null;let y=Y.split(`
85
+ `);return F.current=y,D$("div",{children:[D$("pre",{ref:H,className:"text-code font-mono text-text-code bg-bg-base select-text cursor-text py-3 hljs",children:y.map((V,C)=>{let v=C+1,h=Z&&v>=Z.start&&v<=Z.end;return D$("div",{"data-line-num":v,className:`flex px-5 ${h?"bg-accent-blue/10":"hover:bg-bg-elevated-half"}`,children:[D$("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,v),children:v},void 0,!1,void 0,this),j?D$(n7,{html:j[C]||" "},void 0,!1,void 0,this):D$("code",{className:"py-px",children:V||" "},void 0,!1,void 0,this)]},C,!0,void 0,this)})},void 0,!1,void 0,this),A]},void 0,!0,void 0,this)}import{SessionContext as t7}from"#canvas/runtime";import{useCallback as m6,useContext as z3,useEffect as x6,useMemo as e7,useRef as F2,useState as F1}from"react";import{jsxDEV as i}from"react/jsx-dev-runtime";function M3($,Q){if(!$)return[];return $.canvasFiles.map((J)=>{if(!J.diffStats)return{filename:J.filename,status:"new"};if(J.diffStats.added===0&&J.diffStats.removed===0)return{filename:J.filename,status:"unchanged",diffStats:J.diffStats};return{filename:J.filename,status:"changed",diffStats:J.diffStats}})}function h6($){return $.filter((Q)=>Q.status!=="unchanged").map((Q)=>Q.filename)}function u6({revision:$,responseBanner:Q}){let{setActiveView:J}=z3(q1),{revisions:Y}=z3(h$),q=Y.find((H)=>H.revision===$),G=Y.find((H)=>H.revision===$-1),X=e7(()=>M3(q,G),[q,G]),W=X.filter((H)=>H.status!=="unchanged"),_=X.filter((H)=>H.status==="unchanged");return i("div",{className:"max-w-[720px] mx-auto px-6 pt-12 pb-32",children:[Q,W.map((H)=>i(Qq,{change:H,revision:$,previousRevision:G?.revision,onOpenTab:()=>J({type:"canvas",filename:H.filename})},H.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((H)=>i(Xq,{change:H,revision:$,onOpenTab:()=>J({type:"canvas",filename:H.filename})},H.filename,!1,void 0,this))]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function $q({mode:$,onChange:Q,showDiff:J}){if(!J)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:()=>Q(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 Qq({change:$,revision:Q,previousRevision:J,onOpenTab:Y}){let q=$.filename.replace(/\.jsx$/,""),G=$.status==="new",X=$.diffStats,W=$.status==="changed"&&J!=null,[_,H]=F1("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($q,{mode:_,onChange:H,showDiff:W},void 0,!1,void 0,this),i("button",{onClick:Y,className:`${W?"":"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(R0,{revision:Q,filename:$.filename},void 0,!1,void 0,this)},void 0,!1,void 0,this):W&&J!=null?i(Jq,{filename:$.filename,leftRev:J,rightRev:Q,mode:_},`${_}-${Q}-${J}`,!1,void 0,this):null]},void 0,!0,void 0,this)}function Jq({filename:$,leftRev:Q,rightRev:J,mode:Y}){let q=z3(t7);if(Y==="unified")return i(qq,{sessionId:q,filename:$,leftRev:Q,rightRev:J},void 0,!1,void 0,this);return i(Yq,{sessionId:q,filename:$,leftRev:Q,rightRev:J},void 0,!1,void 0,this)}function qq({sessionId:$,filename:Q,leftRev:J,rightRev:Y}){let q=F2(null),G=F2(null),X=F2(null),[W,_]=F1(!1),[H,U]=F1(!1),[K,N]=F1(!1),[O,M]=F1(null);return x6(()=>{if(!W||!H||K)return;if(!q.current||!G.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!q.current||!G.current||!X.current)return;try{let L=D0(q.current),F=D0(G.current),w=z2(L,F),{fragment:z}=$4(w);X.current.innerHTML="",X.current.appendChild(z),N(!0)}catch(L){M(L instanceof Error?L.message:String(L))}})})},[W,H,K]),i("div",{children:[!K&&!O&&i("div",{style:{position:"absolute",left:-9999,visibility:"hidden",pointerEvents:"none",width:720},children:[i(M1,{ref:q,sessionId:$,revision:J,filename:Q,onReady:()=>_(!0),onError:(L)=>M(L)},void 0,!1,void 0,this),i(M1,{ref:G,sessionId:$,revision:Y,filename:Q,onReady:()=>U(!0),onError:(L)=>M(L)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!K&&!O&&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),O&&i("div",{className:"text-accent-red text-[13px] font-body p-3 bg-accent-red-muted rounded-lg",children:O},void 0,!1,void 0,this),i("div",{ref:X},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function Yq({sessionId:$,filename:Q,leftRev:J,rightRev:Y}){let q=F2(null),G=F2(null),[X,W]=F1(!1),[_,H]=F1(!1),[U,K]=F1(!1),N=m6(()=>W(!0),[]),O=m6(()=>H(!0),[]);return x6(()=>{if(!X||!_||U)return;if(!q.current||!G.current)return;requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!q.current||!G.current)return;e2(q.current,G.current),K(!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 ",J]},void 0,!0,void 0,this),i("div",{className:"px-6 py-4 max-w-[600px] mx-auto",children:i(M1,{ref:q,sessionId:$,revision:J,filename:Q,onReady:N},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(M1,{ref:G,sessionId:$,revision:Y,filename:Q,onReady:O},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 Xq({change:$,revision:Q,onOpenTab:J}){let[Y,q]=F1(!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:J,className:"ml-auto text-[11px] font-body text-text-tertiary hover:text-accent-blue transition-colors",children:"Open in tab"},void 0,!1,void 0,this)]},void 0,!0,void 0,this),Y&&i("div",{className:"ml-5 mt-1 mb-3","data-canvas-file":$.filename,children:i(R0,{revision:Q,filename:$.filename},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{useEffect as Gq,useRef as _q,useState as Wq}from"react";import{jsxDEV as a$}from"react/jsx-dev-runtime";function p6({open:$,onClose:Q,onSubmit:J}){let[Y,q]=Wq(""),G=_q(null);if(Gq(()=>{if($)q(""),setTimeout(()=>G.current?.focus(),50)},[$]),!$)return null;let X=Y.trim(),W=X.length>=1&&X.length<=80,_=()=>{if(!W)return;J(X)};return a$("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:Q,children:a$("div",{className:"bg-bg-surface border border-border-medium rounded-lg shadow-xl w-full max-w-md mx-4 p-5",onClick:(H)=>H.stopPropagation(),children:[a$("div",{className:"flex items-center justify-between mb-3",children:[a$("h2",{className:"text-sm font-medium text-text-primary font-body",children:"Your name"},void 0,!1,void 0,this),a$("button",{onClick:Q,className:"w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",children:a$("span",{className:"text-xs",children:"✕"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),a$("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),a$("input",{ref:G,type:"text",value:Y,onChange:(H)=>q(H.target.value),onKeyDown:(H)=>{if(H.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),a$("div",{className:"flex justify-end gap-2 mt-4",children:[a$("button",{onClick:Q,className:"px-3 py-1.5 text-[12px] font-body font-medium rounded text-text-secondary hover:text-text-primary hover:bg-bg-elevated transition-colors",children:"Cancel"},void 0,!1,void 0,this),a$("button",{onClick:_,disabled:!W,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 c6,useRef as Hq,useState as l6}from"react";import{jsxDEV as _1}from"react/jsx-dev-runtime";function d6($,Q){if(Q){let J=Q.replace(/\/+$/,"").split("/");return J[J.length-1]||$}return $.length>30?$.slice(0,30)+"...":$}function F3({currentSessionId:$,projectRoot:Q}){let[J,Y]=l6([]),[q,G]=l6(!1),X=Hq(null);c6(()=>{if(!O1)return;let H=async()=>{try{let N=await(await fetch("/api/sessions")).json();Y((O)=>{let M=JSON.stringify(N);return JSON.stringify(O)===M?O:N})}catch{}};H();let U=setInterval(H,5000);return()=>clearInterval(U)},[]),c6(()=>{if(!q)return;let H=(U)=>{if(X.current&&!X.current.contains(U.target))G(!1)};return document.addEventListener("mousedown",H),()=>document.removeEventListener("mousedown",H)},[q]);let W=J.filter((H)=>H.id!==$),_=d6($,Q);return _1("div",{className:"relative",ref:X,children:[_1("div",{className:"flex items-center gap-1.5 font-body text-body font-medium",children:[_1("a",{href:`/s/${$}`,className:"text-text-primary hover:text-text-secondary transition-colors",children:_},void 0,!1,void 0,this),W.length>0&&_1("button",{onClick:()=>G(!q),className:"flex items-center justify-center text-text-tertiary hover:text-text-secondary transition-colors",children:_1("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"none",className:`transition-transform duration-200 ${q?"rotate-180":""}`,children:_1("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&&W.length>0&&_1("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:W.map((H)=>_1("a",{href:`/s/${H.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:[_1("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${H.currentRevision>0?"bg-accent-green":"bg-border-hover"}`},void 0,!1,void 0,this),_1("span",{className:"truncate",children:d6(H.id,H.projectRoot)},void 0,!1,void 0,this)]},H.id,!0,void 0,this))},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{useCallback as L3,useEffect as Uq,useState as X4}from"react";import{jsxDEV as G$}from"react/jsx-dev-runtime";function r6({sessionId:$,revision:Q,open:J,shareEnabled:Y,existingShares:q,onClose:G,onShareCreated:X,onShareRevoked:W}){let[_,H]=X4(!1),[U,K]=X4(!1),[N,O]=X4(null),[M,L]=X4(!1),F=q.find((T)=>T.revision===Q);Uq(()=>{if(!J)H(!1),K(!1),O(null),L(!1)},[J]);let w=L3(async()=>{H(!0),O(null);try{let T=await fetch(`/api/session/${$}/revision/${Q}/share`,{method:"POST"}),S=n5.parse(await T.json());if(!S.ok)throw Error(S.error||`HTTP ${T.status}`);if(!T.ok)throw Error(`HTTP ${T.status}`);X(S.share)}catch(T){O(I0(T))}finally{H(!1)}},[$,Q,X]),z=L3(async(T)=>{if(!window.confirm("Revoke this share link? Reviewers will no longer be able to view or comment."))return;K(!0),O(null);try{let S=await fetch(`/api/session/${$}/shares/${T}/revoke`,{method:"POST"}),j=s5.parse(await S.json());if(!j.ok)throw Error(j.error||`HTTP ${S.status}`);if(!S.ok)throw Error(`HTTP ${S.status}`);W(T)}catch(S){O(I0(S))}finally{K(!1)}},[$,W]),A=L3((T)=>{navigator.clipboard.writeText(T).then(()=>{L(!0),setTimeout(()=>L(!1),1500)})},[]);if(!J)return null;return G$("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:G,children:G$("div",{className:"bg-bg-surface border border-border-medium rounded-lg shadow-xl w-full max-w-md mx-4 p-5",onClick:(T)=>T.stopPropagation(),children:[G$("div",{className:"flex items-center justify-between mb-3",children:[G$("h2",{className:"text-sm font-medium text-text-primary font-body",children:"Share this revision"},void 0,!1,void 0,this),G$("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:G$("span",{className:"text-xs",children:"✕"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),!Y?G$("div",{className:"text-[13px] text-text-secondary font-body space-y-2",children:[G$("p",{children:"Canvas sharing is not configured."},void 0,!1,void 0,this),G$("p",{className:"text-text-tertiary",children:["Set ",G$("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"," ",G$("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):F?G$("div",{className:"space-y-3",children:[G$("p",{className:"text-[13px] text-text-secondary font-body",children:"This revision is shared:"},void 0,!1,void 0,this),G$("div",{className:"flex gap-2",children:[G$("input",{type:"text",readOnly:!0,value:F.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:(T)=>T.currentTarget.select()},void 0,!1,void 0,this),G$("button",{onClick:()=>A(F.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),F.expiresAt&&G$("p",{className:"text-[11px] text-text-tertiary font-body",children:["Expires ",new Date(F.expiresAt).toLocaleDateString(),"."]},void 0,!0,void 0,this),F.encryptionKey&&G$("p",{className:"text-[11px] text-accent-green font-body flex items-center gap-1.5",children:[G$("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[G$("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"},void 0,!1,void 0,this),G$("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),G$("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),G$("div",{className:"flex items-center justify-between pt-1",children:[G$("button",{onClick:w,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),F.ownerToken&&G$("button",{onClick:()=>z(F.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):G$("div",{className:"space-y-3",children:[G$("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),G$("button",{onClick:w,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),N&&G$("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:N},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function i6({onClick:$,title:Q="Share this revision",hasShare:J}){return G$("button",{onClick:$,className:`group p-1.5 transition-colors ${J?"text-accent-blue hover:opacity-80":"text-text-tertiary hover:text-text-secondary"}`,title:Q,children:G$("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[G$("circle",{cx:"18",cy:"5",r:"3"},void 0,!1,void 0,this),G$("circle",{cx:"6",cy:"12",r:"3"},void 0,!1,void 0,this),G$("circle",{cx:"18",cy:"19",r:"3"},void 0,!1,void 0,this),G$("line",{x1:"8.59",y1:"13.51",x2:"15.42",y2:"17.49"},void 0,!1,void 0,this),G$("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 P,Fragment as L2}from"react/jsx-dev-runtime";function a6($){let Q=[];for(let J of $)for(let Y of J.annotations)Q.push({...Y,source:"remote",author:J.author});return Q}function Oq($){if($==="auto")return window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light";return $}function n6($){document.documentElement.dataset.theme=Oq($)}function $8(){let[$,Q]=M$(()=>{let q=localStorage.getItem("canvas-theme");if(q==="light"||q==="dark"||q==="auto")return q;return"auto"});return u$(()=>{if(n6($),$!=="auto")return;let q=window.matchMedia("(prefers-color-scheme: dark)"),G=()=>n6("auto");return q.addEventListener("change",G),()=>q.removeEventListener("change",G)},[$]),P("button",{onClick:()=>{let q=$==="auto"?"light":$==="light"?"dark":"auto";localStorage.setItem("canvas-theme",q),Q(q)},className:"w-7 h-7 flex items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:{auto:"Theme: system (click for light)",light:"Theme: light (click for dark)",dark:"Theme: dark (click for system)"}[$],children:$==="auto"?P("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[P("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2",ry:"2"},void 0,!1,void 0,this),P("line",{x1:"8",y1:"21",x2:"16",y2:"21"},void 0,!1,void 0,this),P("line",{x1:"12",y1:"17",x2:"12",y2:"21"},void 0,!1,void 0,this)]},void 0,!0,void 0,this):$==="dark"?P("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:P("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):P("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[P("circle",{cx:"12",cy:"12",r:"5"},void 0,!1,void 0,this),P("line",{x1:"12",y1:"1",x2:"12",y2:"3"},void 0,!1,void 0,this),P("line",{x1:"12",y1:"21",x2:"12",y2:"23"},void 0,!1,void 0,this),P("line",{x1:"4.22",y1:"4.22",x2:"5.64",y2:"5.64"},void 0,!1,void 0,this),P("line",{x1:"18.36",y1:"18.36",x2:"19.78",y2:"19.78"},void 0,!1,void 0,this),P("line",{x1:"1",y1:"12",x2:"3",y2:"12"},void 0,!1,void 0,this),P("line",{x1:"21",y1:"12",x2:"23",y2:"12"},void 0,!1,void 0,this),P("line",{x1:"4.22",y1:"19.78",x2:"5.64",y2:"18.36"},void 0,!1,void 0,this),P("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 Q8(){let{currentRevision:$,selectedRevision:Q,revisions:J,setSelectedRevision:Y,setCompareRevision:q}=v1.useContext(h$);if(J.length<=1){let W=J[0]?.label||`Round ${$}`;return P("span",{className:"text-[11px] text-text-tertiary font-body",children:W},void 0,!1,void 0,this)}return P("div",{className:"flex flex-col gap-1",children:[P(N2,{value:Q,onChange:Y,accent:Q===$?"default":"amber"},void 0,!1,void 0,this),P("button",{onClick:()=>{let X;if(Q===$)X=[...J].reverse().find((_)=>_.revision<$)?.revision??Math.max(1,$-1);else X=Q;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 zq(){let $=W$.isShared?W$.shareId:W$.sessionId,Q=W$.isShared,[J,Y]=M$(1),[q,G]=M$(1),[X,W]=M$([]),[_,H]=M$(null),[U,K]=M$(!1),[N,O]=M$(!1),[M,L]=M$(!1),[F,w]=M$([]),[z,A]=M$({type:"overview"}),[T,S]=M$([]),j=W1(null),Z=W1([]),y=W1(new Set),[V,C]=M$(),[v,h]=M$(!1),[o,B$]=M$(!1),[a,U$]=M$(!1),[Y$,N$]=M$(!1),[Q$,_$]=M$([]),[F$,n]=M$(!1),[d,X$]=M$(new Map),[g,c]=M$(!1),[f,D]=M$(null),[x,r]=M$(null),z$=k0((I)=>{if(Q)return;let e=`${I.revision}\x00${I.filename}\x00${I.message}`;if(y.current.has(e))return;y.current.add(e);let J$=JSON.stringify({type:"render-error",error:I});if(j.current?.readyState===WebSocket.OPEN)j.current.send(J$);else Z.current.push(I)},[Q]);u$(()=>{if(!x)return;let I=setTimeout(()=>r(null),4000);return()=>clearTimeout(I)},[x]);let L$=Math.max(0,...X.map((I)=>I.revision));u$(()=>{if(Q||!V)return;H6().catch((I)=>console.warn("Project theme not applied:",I))},[Q,V,L$]),u$(()=>{let I=["Agent Canvas"];if(V){let e=V.replace(/\/+$/,"").split("/");I.push(e[e.length-1]||$)}else if($)I.push($);if(z.type==="file")I.push(z.path.split("/").pop()||z.path);else if(z.type==="overview")I.push("Overview");else if(z.type==="canvas"&&F.length>1&&z.filename)I.push(z.filename.replace(/\.jsx$/,""));else if(_)I.push("Compare");document.title=I.join(" — ")},[$,V,z,_]);let C$=W1(new Map),f$=X.find((I)=>I.revision===q),A3=q!==J||!!f$?.hasFeedback||N,P3=q===J&&(!!f$?.hasFeedback||N)?"next":"current",S3=k0((I)=>{let e=z.type==="overview"?"overview":z.type==="canvas"?`canvas:${z.filename}`:`file:${z.path}`;if(C$.current.set(e,window.scrollY),A(I),I.type==="file")S((J$)=>J$.includes(I.path)?J$:[...J$,I.path])},[z]),J8=k0((I)=>{C$.current.delete(`file:${I}`),S((e)=>e.filter((J$)=>J$!==I)),A((e)=>{if(e.type==="file"&&e.path===I)return F.length>1?{type:"overview"}:{type:"canvas",filename:F[0]||""};return e})},[F]);Bq(()=>{let I=z.type==="overview"?"overview":z.type==="canvas"?`canvas:${z.filename}`:`file:${z.path}`;window.scrollTo(0,C$.current.get(I)||0)},[z]),u$(()=>{if(!$)return;U6().then((I)=>{if(I.currentRevision){let e=I.revisions||[];for(let J$ of e)if(J$.hasFeedback)o1(localStorage,$,J$.revision);x2(localStorage,$,I.currentRevision,e),Y(I.currentRevision),G(I.currentRevision),W(e)}if(I.canvasFiles){let e=I.canvasFiles.sort();w(e),A((J$)=>{if(J$.type==="overview")return e.length>1?J$:{type:"canvas",filename:e[0]||""};if(J$.type==="canvas"&&(!J$.filename||!e.includes(J$.filename)))return{type:"canvas",filename:e[0]||""};return J$})}if(I.projectRoot)C(I.projectRoot);if(Array.isArray(I.shares))_$(I.shares);n(!!I.shareEnabled)}).catch(()=>{})},[$]),u$(()=>{if(!$||!q||Q)return;fetch(`/api/session/${$}/revision/${q}/remote-feedback`).then((I)=>I.json()).then((I)=>{let e=a5.safeParse(I);if(!e.success)return;let J$=a6(e.data.entries);X$((n$)=>{let m$=new Map(n$);return m$.set(q,J$),m$})}).catch(()=>{})},[$,q,Q]),u$(()=>{if(!$)return;if(!O6){K(!0);return}let I=null,e=()=>{let J$=window.location.protocol==="https:"?"wss:":"ws:",n$=new WebSocket(`${J$}//${window.location.host}/ws/session/${$}`);j.current=n$,n$.onopen=()=>{K(!0),s2?.load().catch((m$)=>console.warn(`[threads] ${I0(m$)}`));for(let m$ of Z.current)n$.send(JSON.stringify({type:"render-error",error:m$}));Z.current=[]},n$.onclose=()=>{K(!1),I=setTimeout(e,2000)},n$.onmessage=(m$)=>{try{let T$=JSON.parse(m$.data);if(T$.type==="plan-updated"){let I$=Array.isArray(T$.revisions)?T$.revisions:[];if(x2(localStorage,$,T$.currentRevision,I$),Y(T$.currentRevision),G(T$.currentRevision),H(null),I$.length>0){W(I$);let L1=I$.find((g1)=>g1.revision===T$.currentRevision);if(L1?.canvasFiles){let g1=L1.canvasFiles.map((f0)=>f0.filename).sort();w(g1);let _4=I$.find((f0)=>f0.revision===T$.currentRevision-1),y0=M3(L1,_4),J0=h6(y0);if(J0.length===1)A({type:"canvas",filename:J0[0]});else if(J0.length>1||g1.length>1)A({type:"overview"});else A({type:"canvas",filename:g1[0]||""})}}}if(T$.type==="revision-updated"){if(Array.isArray(T$.revisions)){let I$=T$.revisions;for(let L1 of I$)if(L1.hasFeedback)o1(localStorage,$,L1.revision);W(I$)}}if(T$.type==="threads")s2?.receive(T$.threads);if(T$.type==="watcher-status")L(!!T$.watching);if(T$.type==="remote-feedback"){let I$=T$.revision,L1=T$.entries||[],g1=a6(L1);X$((_4)=>{let y0=new Map(_4),J0=y0.get(I$)||[],f0=new Set(J0.map((W4)=>W4.id)),q8=[...J0,...g1.filter((W4)=>!f0.has(W4.id))];return y0.set(I$,q8),y0})}}catch{}}};return e(),()=>{if(I)clearTimeout(I);j.current?.close()}},[$]);let G4=k0(async(I,e)=>{try{let J$=localStorage.getItem(`canvas:${$}:rev:${q}`),n$=[],m$=[];if(J$)try{let T$=w0(JSON.parse(J$));n$=(T$?.annotations??[]).filter((I$)=>I$.source!=="remote"),m$=r5((T$?.responses??[]).map(([,I$])=>I$))}catch{}await N6({author:e,revision:q,annotations:n$,generalNote:I,...m$.length>0?{responses:m$}:{}}),o1(localStorage,$,q),O(!0),r({kind:"success",message:"Feedback submitted. The canvas author will see it shortly."})}catch(J$){r({kind:"error",message:`Failed to submit feedback: ${I0(J$)}`})}},[$,q]),w3=k0(async(I,e)=>{if(Q){let J$=K3();if(!J$){D(I),c(!0);return}await G4(I,J$);return}if(j.current?.readyState===WebSocket.OPEN)j.current.send(JSON.stringify({type:"submit",feedback:I,annotations:e}))},[Q,G4]);if(!$)return P("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 P(h2.Provider,{value:z6,children:P(e6.Provider,{value:$,children:P(H2.Provider,{value:z$,children:P(h$.Provider,{value:{currentRevision:J,selectedRevision:q,revisions:X,setSelectedRevision:G,isReadOnly:A3,compareRevision:_,setCompareRevision:H,agentWatching:M},children:P(h4,{sessionId:$,revision:q,isReadOnly:A3,draftPhase:P3,remoteAnnotations:d.get(q),canvasFiles:F,children:P(q1.Provider,{value:{activeView:z,setActiveView:S3,openFiles:T,closeFile:J8,canvasFiles:F},children:P(Kq.Provider,{value:{setActiveView:S3},children:P("div",{className:"min-h-screen bg-bg-base",children:[P(Mq,{sessionId:$,projectRoot:V,connected:U,onMobileSidebar:()=>h(!v),collapsed:o,onToggle:()=>B$((I)=>!I)},void 0,!1,void 0,this),P(Fq,{collapsed:a,onToggle:()=>U$((I)=>!I),children:P(a2,{onSubmit:w3},void 0,!1,void 0,this)},void 0,!1,void 0,this),_!==null?P("div",{className:`${o?"lg:ml-0":"lg:ml-60"} ${a?"lg:mr-0":"lg:mr-[var(--sidebar-width,320px)]"} transition-[margin] duration-200`,children:P(R6,{initialLeft:_.left,initialRight:_.right,sessionId:$,onExit:()=>H(null)},void 0,!1,void 0,this)},void 0,!1,void 0,this):P("div",{className:`relative ${o?"lg:ml-0":"lg:ml-60"} ${a?"lg:mr-0":"lg:mr-[var(--sidebar-width,320px)]"} transition-[margin] duration-200`,id:"plan-scroll-container",children:[P("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:[P("div",{className:"flex items-center gap-2",children:[!Q&&P(F3,{currentSessionId:$,projectRoot:V},void 0,!1,void 0,this),Q&&P("span",{className:"text-[11px] text-text-tertiary font-body",children:"Shared canvas"},void 0,!1,void 0,this),!Q&&P("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),P("div",{className:"flex items-center gap-1",children:[P(Q8,{},void 0,!1,void 0,this),P("button",{onClick:()=>h(!v),className:"w-7 h-7 flex items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Annotations",children:P("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:P("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),P($8,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),P(Lq,{},void 0,!1,void 0,this),z.type==="overview"&&P(u6,{revision:q,responseBanner:f$?.response?P(s6,{markdown:f$.response},void 0,!1,void 0,this):void 0},void 0,!1,void 0,this),z.type==="canvas"&&F.includes(z.filename)&&P("div",{className:"relative max-w-[720px] mx-auto px-6 pt-12 pb-32",children:[F$&&P("div",{className:"absolute top-3 right-12 z-10",children:P(i6,{onClick:()=>N$(!0),hasShare:Q$.some((I)=>I.revision===q),title:Q$.some((I)=>I.revision===q)?"Manage share link":"Share this revision"},void 0,!1,void 0,this)},void 0,!1,void 0,this),P("button",{onClick:()=>{let I=document.querySelector(`[data-canvas-file="${z.filename}"] .plan-content`);if(!I)return;let e=D6(I);navigator.clipboard.writeText(e).then(()=>{let J$=document.getElementById("export-md-btn");if(J$)J$.setAttribute("data-copied","true"),setTimeout(()=>{J$.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:[P("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:[P("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"},void 0,!1,void 0,this),P("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),P("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:P("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),F.length<=1&&f$?.response&&P(s6,{markdown:f$.response},void 0,!1,void 0,this),P("div",{"data-canvas-file":z.filename,children:P(R0,{revision:q,filename:z.filename},z.filename,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this),T.map((I)=>P("div",{style:{display:z.type==="file"&&z.path===I?void 0:"none"},children:P(g6,{path:I},void 0,!1,void 0,this)},I,!1,void 0,this))]},void 0,!0,void 0,this),v&&P("div",{className:"lg:hidden fixed inset-0 z-40 flex",children:[P("div",{className:"flex-1",onClick:()=>h(!1)},void 0,!1,void 0,this),P("div",{className:"w-80 max-w-[85vw] bg-bg-surface border-l border-border-subtle flex flex-col shadow-lg",children:[P("div",{className:"flex items-center justify-between px-4 py-2 border-b border-border-subtle flex-shrink-0",children:[P("span",{className:"text-[11px] font-medium uppercase tracking-widest text-text-tertiary font-body",children:"Sidebar"},void 0,!1,void 0,this),P("button",{onClick:()=>h(!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),P("div",{className:"flex-1 overflow-hidden",children:P(a2,{onSubmit:w3},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this),P(r6,{sessionId:$,revision:q,open:Y$,shareEnabled:F$,existingShares:Q$,onClose:()=>N$(!1),onShareCreated:(I)=>{_$((e)=>[...e.filter((J$)=>J$.shareId!==I.shareId),I]),r({kind:"success",message:"Share link created. Copy and send it to reviewers."})},onShareRevoked:(I)=>{_$((e)=>e.filter((J$)=>J$.shareId!==I)),r({kind:"success",message:"Share link revoked."})}},void 0,!1,void 0,this),P(p6,{open:g,onClose:()=>{c(!1),D(null)},onSubmit:async(I)=>{let e=B6(I);if(c(!1),f!==null)await G4(f,e),D(null)}},void 0,!1,void 0,this),x&&P("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,P("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}:${P3}`,!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 Mq({sessionId:$,projectRoot:Q,connected:J,onMobileSidebar:Y,collapsed:q,onToggle:G}){let X=W$.isShared;return P(L2,{children:[q&&P("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:P("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[P("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"},void 0,!1,void 0,this),P("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),P("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:[P("div",{className:"px-4 pt-4 pb-3 flex-shrink-0 border-b border-border-subtle",children:[P("div",{className:"flex items-center gap-2 mb-2",children:[P("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",className:"text-text-tertiary flex-shrink-0",children:P("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?P("span",{className:"text-[12px] font-body text-text-secondary truncate flex-1",children:"Shared canvas"},void 0,!1,void 0,this):P(L2,{children:[P(F3,{currentSessionId:$,projectRoot:Q},void 0,!1,void 0,this),P("span",{className:`w-1.5 h-1.5 rounded-full flex-shrink-0 ${J?"bg-accent-green":"bg-accent-red"}`},void 0,!1,void 0,this)]},void 0,!0,void 0,this),P("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:P("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[P("polyline",{points:"11 17 6 12 11 7"},void 0,!1,void 0,this),P("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),P(Q8,{},void 0,!1,void 0,this)]},void 0,!0,void 0,this),P("div",{className:"flex-1 flex flex-col overflow-hidden",children:P(y6,{embedded:!0},void 0,!1,void 0,this)},void 0,!1,void 0,this),P("div",{className:"px-4 py-3 border-t border-border-subtle flex items-center justify-between flex-shrink-0",children:[P("span",{className:"text-[10px] text-text-tertiary font-body uppercase tracking-widest",children:"Theme"},void 0,!1,void 0,this),P($8,{},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 Fq({children:$,collapsed:Q,onToggle:J}){let[Y,q]=M$(()=>{let U=localStorage.getItem("canvas-sidebar-width");return U?parseInt(U,10):320}),G=W1(!1),X=W1(0),W=W1(0),_=W1(Y);_.current=Y;let H=k0((U)=>{U.preventDefault(),G.current=!0,X.current=U.clientX,W.current=_.current;let K=(O)=>{if(!G.current)return;let M=X.current-O.clientX,L=Math.max(240,Math.min(600,W.current+M));q(L),_.current=L},N=()=>{G.current=!1,localStorage.setItem("canvas-sidebar-width",String(_.current)),document.removeEventListener("mousemove",K),document.removeEventListener("mouseup",N),document.body.style.cursor="",document.body.style.userSelect=""};document.addEventListener("mousemove",K),document.addEventListener("mouseup",N),document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[]);return u$(()=>{return document.documentElement.style.setProperty("--sidebar-width",`${Y}px`),()=>{document.documentElement.style.removeProperty("--sidebar-width")}},[Y]),P(L2,{children:[Q&&P("button",{onClick:J,className:"hidden lg:flex fixed top-3 right-3 z-20 w-7 h-7 items-center justify-center rounded-md text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors bg-bg-surface border border-border-subtle",title:"Show annotations",children:P("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:P("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),P("div",{className:`hidden lg:flex flex-col fixed top-0 right-0 bottom-0 bg-bg-surface border-l border-border-subtle z-10 transition-transform duration-200 ${Q?"translate-x-full":""}`,style:{width:Y},children:[P("div",{onMouseDown:H,className:"absolute left-0 top-0 bottom-0 w-1 cursor-col-resize hover:bg-accent-blue/30 transition-colors z-20",style:{marginLeft:"-2px"}},void 0,!1,void 0,this),v1.Children.map($,(U)=>v1.isValidElement(U)?v1.cloneElement(U,{collapseButton:P("button",{onClick:J,className:"w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",title:"Hide annotations",children:P("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[P("polyline",{points:"13 17 18 12 13 7"},void 0,!1,void 0,this),P("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 s6({markdown:$}){let[Q,J]=M$(!1),Y=o6(()=>i2($),[$]),q=W1(null),{annotations:G,addAnnotationWithId:X,removeAnnotation:W,updateAnnotation:_,addAnnotationImage:H,removeAnnotationImage:U,activeAnnotationId:K,setActiveAnnotationId:N}=G1(),[O,M]=M$(null),[L,F]=M$(null),w=o6(()=>G.filter((j)=>j.filePath===g$),[G]),[z,A]=M$($);if($!==z)A($),J(!1);u$(()=>{if(!q.current||w.length===0)return;let j=setTimeout(()=>{if(q.current)m0(q.current,w)},50);return()=>clearTimeout(j)},[Y,w.length]);let T=W1(null);if(u$(()=>{v0(K,T.current),T.current=K},[K]),u$(()=>{let j=q.current;if(!j)return;let Z=(C)=>{let v=C.target.closest("[data-annotation-id]");if(!v)return;C.stopPropagation();let h=v.getAttribute("data-annotation-id");if(h===K)F({anchorEl:v,annId:h});else N(h)},y=(C)=>{let v=C.target.closest("[data-annotation-id]");if(v)N(v.getAttribute("data-annotation-id"))},V=(C)=>{let v=C.target.closest("[data-annotation-id]"),h=C.relatedTarget?.closest?.("[data-annotation-id]");if(v&&!h)N(null)};return j.addEventListener("click",Z),j.addEventListener("mouseover",y),j.addEventListener("mouseout",V),()=>{j.removeEventListener("click",Z),j.removeEventListener("mouseover",y),j.removeEventListener("mouseout",V)}},[Y,K]),u$(()=>{let j=()=>{let Z=window.getSelection();if(!Z||Z.isCollapsed||!Z.toString().trim())return;if(!q.current)return;let y=Z.getRangeAt(0);if(!q.current.contains(y.startContainer))return;if(y.startContainer.parentElement?.closest?.("[data-annotation-id]"))return;let V=Z.toString().trim();if(V.length<2)return;let C=y.cloneRange(),v=P1(y,q.current),h=`__pending_${Date.now()}`;try{A1(C,h)}catch{}window.getSelection()?.removeAllRanges();let o=document.querySelectorAll(`[data-annotation-id="${h}"]`),B$=o[o.length-1];if(!B$)return;M({anchorEl:B$,tempId:h,snippet:V,ctx:v})};return document.addEventListener("mouseup",j),()=>document.removeEventListener("mouseup",j)},[]),Q)return null;let S=document.getElementById("plan-scroll-container");return P("div",{className:"mb-6 rounded-lg border border-accent-blue/20 bg-accent-blue/5 relative",children:[P("button",{onClick:()=>J(!0),className:"absolute top-2 right-2 w-6 h-6 flex items-center justify-center rounded text-text-tertiary hover:text-text-secondary hover:bg-bg-elevated transition-colors",children:P("span",{className:"text-xs",children:"✕"},void 0,!1,void 0,this)},void 0,!1,void 0,this),P("div",{className:"px-4 py-3 pr-10",children:[P("div",{className:"flex items-center gap-2 mb-1.5",children:[P("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:P("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),P("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),P("div",{ref:q,className:"prose-canvas text-sm",dangerouslySetInnerHTML:{__html:Y}},void 0,!1,void 0,this)]},void 0,!0,void 0,this),O&&P(Q1,{anchorEl:O.anchorEl,scrollContainer:S,snippet:O.snippet,truncateAt:80,onAdd:(j,Z)=>{let y=x$();g0(O.tempId,y),X(y,O.snippet,j,g$,O.ctx,Z),M(null)},onCancel:()=>{x0(O.tempId),M(null)}},void 0,!1,void 0,this),L&&(()=>{let j=G.find((Z)=>Z.id===L.annId);if(!j)return null;return P(r1,{anchorEl:L.anchorEl,scrollContainer:S,initialNote:j.note,initialImages:j.images,onUpdate:(Z,y)=>{_(L.annId,Z);let V=j.images||[];for(let C of y)if(!V.includes(C))H(L.annId,C);for(let C of V)if(!y.includes(C))U(L.annId,C)},onDelete:()=>{W(L.annId),N(null)},onClose:()=>F(null)},void 0,!1,void 0,this)})()]},void 0,!0,void 0,this)}function Lq(){let{activeView:$,setActiveView:Q,openFiles:J,closeFile:Y,canvasFiles:q}=v1.useContext(q1),G=v1.useContext(e6),{addAnnotationWithId:X,setActiveAnnotationId:W}=G1();if(!(q.length>1||J.length>0))return null;return P("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&&P(L2,{children:[P("button",{onClick:()=>Q({type:"overview"}),className:`flex items-center gap-1.5 px-4 py-2.5 text-[13px] font-body whitespace-nowrap transition-colors relative ${$.type==="overview"?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[P("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",className:"opacity-60",children:P("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"&&P("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),P("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((H,U)=>{let K=H.replace(/\.jsx$/,""),N=$.type==="canvas"&&$.filename===H;return P(v1.Fragment,{children:[P("button",{onClick:()=>Q({type:"canvas",filename:H}),className:`flex items-center gap-1.5 px-4 py-2.5 text-[13px] font-body whitespace-nowrap transition-colors relative ${N?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[K,N&&P("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&&P("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this)]},H,!0,void 0,this)}),J.length>0&&P(L2,{children:[P("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this),J.map((H,U)=>{let K=H.split("/").pop()||H,N=$.type==="file"&&$.path===H;return P(v1.Fragment,{children:[P("div",{className:"flex items-center",children:[P("button",{onClick:()=>Q({type:"file",path:H}),className:`flex items-center gap-1.5 pl-3 pr-1 py-2.5 text-[13px] font-body whitespace-nowrap transition-colors relative ${N?"text-text-primary":"text-text-tertiary hover:text-text-secondary"}`,children:[P(I1,{name:K,type:"file"},void 0,!1,void 0,this),K,N&&P("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),P("button",{onClick:(O)=>{O.stopPropagation(),Y(H)},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<J.length-1&&P("span",{className:"w-px h-4 bg-border-medium flex-shrink-0"},void 0,!1,void 0,this)]},H,!0,void 0,this)})]},void 0,!0,void 0,this),P("div",{className:"ml-auto flex items-center gap-1 flex-shrink-0",children:$.type==="file"&&O1&&P("button",{onClick:async()=>{let H=$.path;try{let U=await fetch(`/api/file?session=${G}&path=${encodeURIComponent(H)}`),K=D1.parse(await U.json());if("content"in K){let N=K.content.split(`
85
86
  `).slice(0,3).join(`
86
87
  `)+(K.content.split(`
87
88
  `).length>3?`
88
- ...`:""),B=E$();X(B,z,"",W),H(B)}}catch{}},className:"flex items-center gap-1 px-3 py-1.5 text-[11px] font-medium font-body text-text-tertiary hover:text-text-secondary whitespace-nowrap transition-colors",children:[F("span",{className:"text-[13px] leading-none",children:"+"},void 0,!1,void 0,this),"Add to context"]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}var b6=document.getElementById("root");if(b6)L7(b6).render(F(A7,{},void 0,!1,void 0,this));
89
+ ...`:""),O=x$();X(O,N,"",H),W(O)}}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:[P("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 t6=document.getElementById("root");if(t6)Nq(t6).render(P(zq,{},void 0,!1,void 0,this));