@fork-api/chat-sdk 0.1.181 → 0.1.182
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
scrollbar-width: thin;
|
|
57
57
|
scrollbar-color: rgba(0, 0, 0, 0.12) transparent;
|
|
58
58
|
}
|
|
59
|
-
`}),ls.jsxs("div",{className:"__fork-panel",style:rs,children:[ls.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"0 16px",height:54,boxSizing:"border-box",borderBottom:"1px solid rgba(229, 231, 235, 0.8)",flexShrink:0},children:[ls.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0,flex:1},children:[c||A?ls.jsxs(ls.Fragment,{children:[ls.jsx("button",{onClick:()=>{y(null),z(false),Q.current=false;},style:{width:30,height:30,borderRadius:9,background:"#ffffff",border:"1px solid #e5e7eb",color:"#111827",cursor:"pointer",display:"inline-flex",alignItems:"center",justifyContent:"center",padding:0,flexShrink:0,transition:"background 0.12s, border-color 0.12s"},onMouseEnter:a=>{a.currentTarget.style.background="#f9fafb",a.currentTarget.style.borderColor="#d1d5db";},onMouseLeave:a=>{a.currentTarget.style.background="#ffffff",a.currentTarget.style.borderColor="#e5e7eb";},title:"Back to all forks",children:ls.jsx(lucideReact.ChevronLeft,{style:{width:15,height:15}})}),(()=>{let a=c?o[c]:void 0,B=(a?a.events.find(G=>{let le=G.data;return G.type==="status"&&le.summary})?.data?.summary??a.fork.summary:void 0)||vn?.summary||"New Feature";return ls.jsx("span",{style:{fontSize:13.5,fontWeight:700,color:"#111827",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",minWidth:0},title:B,children:B})})()]}):ls.jsxs(ls.Fragment,{children:[ls.jsx("span",{onDoubleClick:async a=>{if(a.stopPropagation(),!re&&confirm("Kill all forks in this container?")){Ae(true);try{let T=await zo();`${T?.deleted??0}`,ft([]),y(null),z(!1),P("");}catch(T){console.error("[Fork] Reset failed:",T);}finally{Ae(false);}}},style:{display:"inline-flex",alignItems:"center",justifyContent:"center",padding:4,margin:-4,cursor:"pointer",flexShrink:0},children:ls.jsx(nn,{style:{width:16,height:16,color:"#111827",pointerEvents:"none"}})}),De==="running"?ls.jsx("span",{style:{fontSize:13,fontWeight:600,color:"#111827",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:Qo}):Te.length===0&&!Vt?ls.jsx("span",{style:{fontSize:13,fontWeight:600,color:"#111827",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:"Fork"}):Vt?ls.jsxs("div",{ref:Yt,style:{position:"relative",minWidth:0,display:"inline-flex"},children:[ls.jsxs("button",{type:"button",onClick:()=>{ke(a=>!a);},onMouseEnter:()=>Bt(true),onMouseLeave:()=>Bt(false),"aria-haspopup":"menu","aria-expanded":$e,style:{display:"inline-flex",alignItems:"center",gap:4,padding:"3px 6px",border:"1px solid transparent",borderRadius:6,background:hn||$e?"#f3f4f6":"transparent",fontSize:13,fontWeight:600,color:"#111827",fontFamily:"inherit",cursor:"pointer",maxWidth:180,minWidth:0,transition:"background-color 0.12s"},children:[ls.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:Mr}),ls.jsx(lucideReact.ChevronDown,{style:{width:12,height:12,color:"#6b7280",flexShrink:0,transform:$e?"rotate(180deg)":void 0,transition:"transform 0.15s"}})]}),$e&&ls.jsxs("div",{role:"menu",style:{position:"absolute",top:"calc(100% + 4px)",left:0,minWidth:200,maxWidth:260,background:"#ffffff",border:"1px solid #e5e7eb",borderRadius:8,boxShadow:"0 4px 12px rgba(0,0,0,0.08), 0 1px 3px rgba(0,0,0,0.06)",padding:4,zIndex:2147483001},children:[Te.map(a=>{let T=a.id===Se,B=yn===a.id,G=ge===a.id;return ls.jsxs("button",{type:"button",role:"menuitem",onMouseEnter:()=>Dt(a.id),onMouseLeave:()=>Dt(null),onClick:()=>{a.id!==Se&&ns(a.id);},disabled:!!ge,style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"6px 8px",border:"none",background:B?"#f3f4f6":"transparent",borderRadius:4,fontSize:13,fontFamily:"inherit",color:"#111827",cursor:ge?"default":"pointer",textAlign:"left",fontWeight:T?600:400,opacity:ge&&!G?.55:1},children:[ls.jsx("span",{style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:14,height:14,color:"#111827",flexShrink:0},children:T&&ls.jsx(lucideReact.Check,{style:{width:12,height:12}})}),ls.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:G?"Switching...":a.name})]},a.id)}),ls.jsx("div",{style:{height:1,background:"#e5e7eb",margin:"4px 0"}}),bt?ls.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4,padding:"4px 4px"},children:[ls.jsx("input",{ref:wt,type:"text",value:Be,placeholder:"Container name",disabled:ge==="__new__",onChange:a=>Xe(a.target.value),onKeyDown:a=>{a.key==="Enter"?(a.preventDefault(),Rr(Be)):a.key==="Escape"&&(a.preventDefault(),a.stopPropagation(),ut(false),Xe(""));},style:{flex:1,minWidth:0,padding:"5px 8px",border:"1px solid #d1d5db",borderRadius:4,fontSize:13,fontFamily:"inherit",color:"#111827",background:"#ffffff",outline:"none"},onFocus:a=>{a.currentTarget.style.borderColor="#111827",a.currentTarget.style.boxShadow="0 0 0 2px rgba(17,24,39,0.15)";},onBlur:a=>{a.currentTarget.style.borderColor="#d1d5db",a.currentTarget.style.boxShadow="none";}}),ls.jsx("button",{type:"button",onClick:()=>{Rr(Be);},disabled:!Be.trim()||ge==="__new__",title:"Create",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:26,height:26,border:"none",borderRadius:4,background:!Be.trim()||ge==="__new__"?"#e5e7eb":"#111827",color:!Be.trim()||ge==="__new__"?"#9ca3af":"#ffffff",cursor:!Be.trim()||ge==="__new__"?"default":"pointer",flexShrink:0},children:ge==="__new__"?ls.jsx("span",{style:{width:10,height:10,border:"1.5px solid currentColor",borderTopColor:"transparent",borderRadius:"50%",animation:"__fork-spin 0.7s linear infinite"}}):ls.jsx(lucideReact.Check,{style:{width:12,height:12}})})]}):ls.jsx("button",{type:"button",role:"menuitem",onMouseEnter:()=>jt(true),onMouseLeave:()=>jt(false),onClick:()=>{ge||(Fe(null),Xe(""),ut(true));},disabled:!!ge,style:{display:"flex",alignItems:"center",width:"100%",padding:"6px 8px",border:"none",background:tt?"#f3f4f6":"transparent",borderRadius:4,fontSize:13,fontFamily:"inherit",color:"#111827",cursor:ge?"default":"pointer",textAlign:"left",opacity:ge&&ge!=="__new__"?.55:1},children:"+ New container"}),Kt&&ls.jsx("div",{style:{padding:"6px 8px",fontSize:11,lineHeight:1.35,color:"#b91c1c"},children:Kt})]})]}):ls.jsx("span",{style:{fontSize:13,fontWeight:600,color:"#111827",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:Mr})]}),De==="running"&&ls.jsx("span",{title:nt?`Estimated ~${nt} min`:"Estimating\u2026",style:{fontSize:10,fontWeight:600,color:nt?"#111827":"#9ca3af",backgroundColor:nt?"rgba(17, 24, 39, 0.08)":"rgba(156, 163, 175, 0.12)",padding:"1px 6px",borderRadius:999,flexShrink:0,fontVariantNumeric:"tabular-nums",animation:nt?void 0:"__fork-pulse 1.4s ease-in-out infinite",minWidth:28,textAlign:"center"},children:nt?`~${nt}m`:"~ m"})]}),ls.jsxs("div",{style:{display:"flex",alignItems:"center",gap:2,flexShrink:0},children:[Vo&&ls.jsx("button",{type:"button",role:"switch","aria-checked":!mt,"aria-label":mt?"Turn Fork back on":"Turn Fork off",title:mt?"Fork is off \u2014 you're seeing the original app. Turn it back on. Only affects you.":"Turn Fork off to see the original app. Only affects you.",onClick:()=>{Jo(!mt);},onMouseEnter:()=>gr(true),onMouseLeave:()=>gr(false),style:{position:"relative",width:26,height:15,borderRadius:999,border:"none",padding:0,marginRight:6,flexShrink:0,cursor:"pointer",backgroundColor:mt?mr?"#9ca3af":"#d1d5db":mr?"#374151":"#111827",transition:"background-color 0.18s ease",outline:"none",boxSizing:"border-box"},children:ls.jsx("span",{"aria-hidden":true,style:{position:"absolute",top:2,left:mt?2:13,width:11,height:11,borderRadius:"50%",backgroundColor:"#ffffff",boxShadow:"0 1px 2px rgba(15, 23, 42, 0.25)",transition:"left 0.18s cubic-bezier(0.16, 1, 0.3, 1)"}})}),!S&&ls.jsxs(ls.Fragment,{children:[yr&&ls.jsx("button",{onClick:Oe?qo:Xo,onMouseEnter:()=>V(true),onMouseLeave:()=>V(false),title:Oe?"Redock to sidebar":"Pop out into window",style:{padding:6,borderRadius:6,color:K?"#4b5563":"#9ca3af",backgroundColor:K?"#f3f4f6":"transparent",border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",transition:"background-color 0.15s, color 0.15s"},children:Oe?ls.jsx(lucideReact.PictureInPicture,{style:{width:16,height:16}}):ls.jsx(lucideReact.PictureInPicture2,{style:{width:16,height:16}})}),ls.jsx("button",{onClick:Cr,onMouseEnter:()=>D(true),onMouseLeave:()=>D(false),style:{padding:6,borderRadius:6,color:H?"#4b5563":"#9ca3af",backgroundColor:H?"#f3f4f6":"transparent",border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",transition:"background-color 0.15s, color 0.15s"},children:ls.jsx(lucideReact.X,{style:{width:16,height:16}})})]})]})]}),ls.jsxs("div",{ref:ne,style:{flex:1,overflowY:"auto",minHeight:0,display:"flex",flexDirection:"column"},children:[!c&&!A&&ls.jsxs("div",{style:{display:"flex",flexDirection:"column"},children:[Ne.length===0&&ls.jsx("div",{style:{padding:"24px 20px",textAlign:"center",fontSize:13,color:"#6b7280"},children:"No forks yet. Describe a feature below to start one."}),Ne.length>0&&ls.jsx("div",{style:{display:"flex",flexDirection:"column"},children:Ne.map((a,T)=>{let B=o[a.id],le=(B?B.events.find(Ye=>{let ss=Ye.data;return Ye.type==="status"&&ss.summary})?.data?.summary??B.fork.summary:void 0)||a.summary||"Untitled fork",je=!!fr.find(Ye=>Ye.id===a.id)?.unread,Me=o[a.id]?.state??a.status,os=Me==="running"||Me==="building"||Me==="pending";return ls.jsxs(Pn.Fragment,{children:[ls.jsxs("button",{onClick:()=>{z(false),y(a.id);},style:{textAlign:"left",padding:"12px 16px",background:"transparent",border:"none",cursor:"pointer",display:"flex",alignItems:"flex-start",gap:8,width:"100%",transition:"background 0.12s",fontFamily:"inherit"},onMouseEnter:Ye=>{Ye.currentTarget.style.background="#fafafa";},onMouseLeave:Ye=>{Ye.currentTarget.style.background="transparent";},children:[je&&ls.jsx("span",{"aria-label":"Not viewed yet",title:"Not viewed yet",style:{width:7,height:7,borderRadius:"50%",backgroundColor:"#111827",flexShrink:0,marginTop:5}}),ls.jsxs("div",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:5,alignItems:"flex-start"},children:[ls.jsx("span",{style:{fontSize:13.5,fontWeight:600,color:"#111827",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",maxWidth:"100%"},children:le}),ls.jsx("span",{style:{fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, "Liberation Mono", "Courier New", monospace',fontSize:10,color:"#9ca3af",background:"#f8f9fa",borderRadius:5,padding:"1px 6px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",maxWidth:"100%",boxSizing:"border-box"},children:a.targetId})]}),os&&ls.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:5,background:"#fff7ed",border:"1px solid #fed7aa",color:"#c2410c",borderRadius:999,padding:"2px 9px",fontSize:11,fontWeight:600,flexShrink:0},children:[ls.jsx("span",{style:{width:6,height:6,borderRadius:"50%",background:"#f59e0b",animation:"__fork-pulse 1.4s ease-in-out infinite"}}),"Running"]}),Me==="error"&&ls.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:5,background:"#fef2f2",border:"1px solid #fecaca",color:"#b91c1c",borderRadius:999,padding:"2px 9px",fontSize:11,fontWeight:600,flexShrink:0},children:"Failed"}),ls.jsx("span",{style:{fontSize:11.5,color:"#9ca3af",flexShrink:0,marginTop:2},children:Kn(a.updatedAt)})]}),T<Ne.length-1&&ls.jsx("div",{style:{height:1,background:"#f3f4f6",margin:"0 16px",flexShrink:0}})]},a.id)})})]}),c&&xt.length>0&&ls.jsx("div",{style:{margin:"16px 16px 0 16px"},children:xt.map((a,T)=>ls.jsx("div",{style:{marginBottom:T<xt.length-1?12:0},children:a.type==="user"?ls.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:ls.jsxs("div",{style:{backgroundColor:"#f3f4f6",borderRadius:12,padding:"10px 14px",fontSize:13,color:"#374151",lineHeight:1.5,maxWidth:"85%"},children:[a.attachments&&a.attachments.length>0&&ls.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,marginBottom:6},children:a.attachments.map((B,G)=>ls.jsx("img",{src:B.dataUrl,alt:"attachment",style:{maxWidth:150,maxHeight:110,borderRadius:8,border:"1px solid #e5e7eb",display:"block",objectFit:"cover"}},G))}),a.selectedElement&&ls.jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:4,background:"#eef2ff",border:"1px solid #c7d2fe",color:"#4338ca",borderRadius:999,padding:"2px 8px",fontSize:10.5,fontWeight:500,marginBottom:5,marginRight:6,maxWidth:"100%"},children:[ls.jsx(lucideReact.MousePointer2,{style:{width:10,height:10,flexShrink:0}}),ls.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"ui-monospace, SFMono-Regular, Menlo, monospace"},children:a.selectedElement.label})]}),a.text]})}):I==="item"&&T===xt.length-1?ls.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:12,padding:12,borderRadius:8,border:"1px solid #e4e4e7",background:"#ffffff"},children:[ls.jsx("div",{style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:28,height:28,flexShrink:0,borderRadius:6,background:"#f4f4f5",color:"#0a0a0a"},children:ls.jsx(lucideReact.BadgeCheck,{style:{width:16,height:16}})}),ls.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:2,flex:1,minWidth:0},children:[ls.jsx("div",{style:{fontSize:13,fontWeight:500,color:"#0a0a0a",lineHeight:1.3},children:"Feature applied"}),ls.jsx("div",{style:{fontSize:13,color:"#71717a",lineHeight:1.4},children:a.text})]}),b&&De!=="running"&&ls.jsx("button",{onClick:B=>{B.stopPropagation(),Ir();},disabled:p,style:{padding:"4px 10px",fontSize:12,fontWeight:500,borderRadius:6,border:"1px solid #e4e4e7",background:"#ffffff",color:"#0a0a0a",cursor:p?"default":"pointer",opacity:p?.4:1,height:28,flexShrink:0},children:"Undo"})]}):ls.jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:8,background:"#ffffff",border:"1px solid #e5e7eb",borderRadius:10,boxShadow:"0 1px 2px rgba(0, 0, 0, 0.03)",padding:"9px 12px",maxWidth:"90%",boxSizing:"border-box"},children:[ls.jsx("span",{style:{width:7,height:7,borderRadius:"50%",background:"#94a3b8",flexShrink:0}}),ls.jsx("span",{style:{fontSize:12.5,fontWeight:600,color:"#334155",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:a.text}),a.timestamp&&ls.jsx("span",{style:{fontSize:11,color:"#9ca3af",flexShrink:0},children:Kn(a.timestamp)}),b&&T===xt.length-1&&De!=="running"&&ls.jsxs("button",{onClick:B=>{B.stopPropagation(),Ir();},onMouseEnter:()=>q(T),onMouseLeave:()=>q(null),disabled:p,style:{position:"relative",padding:2,borderRadius:4,border:"none",background:x===T?"rgba(0,0,0,0.06)":"transparent",color:x===T?"#6b7280":"#d1d5db",cursor:p?"default":"pointer",display:"flex",alignItems:"center",justifyContent:"center",transition:"color 0.15s, background 0.15s",opacity:p?.4:1,flexShrink:0},children:[ls.jsx(lucideReact.Undo2,{style:{width:12,height:12}}),x===T&&ls.jsx("span",{style:{position:"absolute",bottom:"calc(100% + 4px)",right:0,fontSize:10,fontWeight:500,color:"#fff",background:"#374151",borderRadius:4,padding:"2px 6px",whiteSpace:"nowrap",pointerEvents:"none",lineHeight:"16px"},children:"Undo"})]})]})},T))}),De==="running"&&ls.jsx("div",{style:{margin:"12px 16px 0 16px"},children:ls.jsxs("div",{onClick:()=>w(!M),style:{background:"#ffffff",border:"1px solid #e5e7eb",borderRadius:10,boxShadow:"0 1px 2px rgba(0, 0, 0, 0.03)",overflow:"hidden",cursor:"pointer",transition:"all 0.3s cubic-bezier(0.22, 1, 0.36, 1)"},children:[ls.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"9px 12px"},children:[ls.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[ls.jsx("span",{style:{width:7,height:7,borderRadius:"50%",background:"#f59e0b",flexShrink:0,animation:"__fork-pulse 1.4s ease-in-out infinite"}}),ls.jsx(Ci,{events:ht},c??"__compose__")]}),ls.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flexShrink:0,marginLeft:8},children:[ht[0]?.timestamp&&ls.jsx("span",{style:{fontSize:11,color:"#9ca3af"},children:Kn(ht[0].timestamp)}),ls.jsx("div",{style:{color:"#9ca3af",transition:"transform 0.2s ease",transform:M?"rotate(180deg)":"rotate(0deg)",display:"flex"},children:ls.jsx(lucideReact.ChevronDown,{style:{width:14,height:14}})})]})]}),ls.jsx("div",{style:{maxHeight:M?320:0,opacity:M?1:0,transition:"max-height 0.35s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.25s ease",overflow:"hidden"},children:ls.jsx("div",{style:{background:"#1a1a2e",borderTop:"1px solid #e5e7eb",maxHeight:320,overflowY:"auto"},children:ls.jsx(Zr,{events:ht},c??"__compose__")})})]})}),De==="error"&&ls.jsxs("div",{style:{padding:"20px 16px",textAlign:"center"},children:[ls.jsx("div",{style:{width:36,height:36,backgroundColor:"#fef2f2",borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",margin:"0 auto 10px auto"},children:ls.jsx(lucideReact.X,{style:{width:18,height:18,color:"#ef4444"}})}),ls.jsx("p",{style:{fontSize:12,color:"#6b7280",marginBottom:10,maxWidth:260,margin:"0 auto 10px auto"},children:Yo??r}),ls.jsxs("button",{onClick:()=>{let a=Sn?.prompt||qt.current;a&&h(a,vt);},onMouseEnter:()=>C(true),onMouseLeave:()=>C(false),style:{display:"inline-flex",alignItems:"center",gap:6,padding:"6px 12px",borderRadius:8,fontSize:12,fontWeight:500,color:"#111827",backgroundColor:U?"#e5e7eb":"#f3f4f6",border:"none",cursor:"pointer",transition:"background-color 0.15s",fontFamily:"inherit"},children:[ls.jsx(lucideReact.RotateCcw,{style:{width:12,height:12}})," Try Again"]})]})]}),!(c?De==="running":A&&e==="running")&&ls.jsxs("div",{style:{padding:"8px 12px 12px 12px",borderTop:"1px solid rgba(229, 231, 235, 0.6)",flexShrink:0,position:"relative"},children:[pt&&ls.jsx("div",{style:{position:"absolute",top:-42,left:"50%",transform:"translateX(-50%)",background:"#111827",color:"#ffffff",fontSize:12,fontWeight:500,padding:"7px 14px",borderRadius:999,boxShadow:"0 4px 16px rgba(0, 0, 0, 0.22)",whiteSpace:"nowrap",maxWidth:jn-32,overflow:"hidden",textOverflow:"ellipsis",pointerEvents:"none",zIndex:5},children:pt}),ls.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6,borderRadius:14,padding:"10px 10px 8px 12px",background:"#ffffff",border:"1px solid #e5e7eb",boxShadow:"0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 14px -6px rgba(0, 0, 0, 0.08)"},children:[(ie.length>0||ce)&&ls.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:6,alignItems:"center"},children:[ie.map(a=>ls.jsxs("div",{onMouseEnter:()=>ur(a.id),onMouseLeave:()=>ur(null),style:{position:"relative",width:44,height:44,borderRadius:8,overflow:"hidden",border:"1px solid #e5e7eb",flexShrink:0},children:[ls.jsx("img",{src:a.dataUrl,alt:"attachment",style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}}),ls.jsx("button",{onClick:()=>be(T=>T.filter(B=>B.id!==a.id)),title:"Remove image",style:{position:"absolute",top:2,right:2,width:15,height:15,borderRadius:"50%",background:"rgba(17, 24, 39, 0.78)",color:"#ffffff",border:"none",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",padding:0,opacity:Ko===a.id?1:.6,transition:"opacity 0.12s"},children:ls.jsx(lucideReact.X,{style:{width:9,height:9}})})]},a.id)),ce&&ls.jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:5,background:"#eef2ff",border:"1px solid #c7d2fe",color:"#4338ca",borderRadius:999,padding:"4px 6px 4px 9px",fontSize:11,fontWeight:500,maxWidth:"100%",minWidth:0},children:[ls.jsx(lucideReact.MousePointer2,{style:{width:11,height:11,flexShrink:0}}),ls.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"ui-monospace, SFMono-Regular, Menlo, monospace"},children:an(ce)}),ls.jsx("button",{onClick:()=>me(null),title:"Remove element context",style:{width:14,height:14,borderRadius:"50%",background:"transparent",color:"#6366f1",border:"none",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",padding:0,flexShrink:0},children:ls.jsx(lucideReact.X,{style:{width:10,height:10}})})]})]}),ls.jsx("textarea",{ref:Z,value:m,onChange:a=>P(a.target.value),onPaste:a=>{let T=eo(a.nativeEvent);T.length>0&&(a.preventDefault(),vr(T));},onKeyDown:a=>{a.key==="Enter"&&!a.shiftKey&&(a.preventDefault(),xr()),a.key==="Escape"&&!S&&Cr();},placeholder:c?"Iterate on this feature...":"Start building a new Fork...",rows:1,style:{width:"100%",backgroundColor:"transparent",fontSize:13,color:"#111827",border:"none",outline:"none",padding:0,fontFamily:"inherit",resize:"none",lineHeight:1.5,maxHeight:160,overflow:"auto",boxSizing:"border-box"}}),ls.jsxs("div",{style:{display:"flex",alignItems:"center",gap:2},children:[ls.jsx("button",{onClick:()=>ir.current?.click(),onMouseEnter:()=>ar(true),onMouseLeave:()=>ar(false),title:"Attach an image",style:{width:28,height:28,borderRadius:8,display:"flex",alignItems:"center",justifyContent:"center",background:Bo?"rgba(0, 0, 0, 0.05)":"transparent",color:"#6b7280",border:"none",cursor:"pointer",padding:0,flexShrink:0,transition:"background 0.12s"},children:ls.jsx(lucideReact.ImagePlus,{style:{width:16,height:16}})}),ls.jsx("button",{onClick:es,onMouseEnter:()=>lr(true),onMouseLeave:()=>lr(false),title:ae?"Cancel element selection":"Select an element on the page",style:{width:28,height:28,borderRadius:8,display:"flex",alignItems:"center",justifyContent:"center",background:ae?"#eef2ff":Do?"rgba(0, 0, 0, 0.05)":"transparent",color:ae?"#4f46e5":"#6b7280",border:"none",cursor:"pointer",padding:0,flexShrink:0,transition:"background 0.12s, color 0.12s"},children:ls.jsx(lucideReact.MousePointer2,{style:{width:16,height:16}})}),ls.jsx("div",{style:{flex:1}}),ls.jsx("button",{onClick:ts,onMouseEnter:()=>cr(true),onMouseLeave:()=>cr(false),title:fe?"Stop voice input":"Voice input",style:{width:28,height:28,borderRadius:8,display:"flex",alignItems:"center",justifyContent:"center",background:fe?"#fef2f2":jo?"rgba(0, 0, 0, 0.05)":"transparent",color:fe?"#dc2626":"#6b7280",border:"none",cursor:"pointer",padding:0,flexShrink:0,transition:"background 0.12s, color 0.12s",animation:fe?"__fork-pulse 1.4s ease-in-out infinite":void 0},children:ls.jsx(lucideReact.Mic,{style:{width:16,height:16}})}),ls.jsx("button",{onClick:xr,disabled:!yt,onMouseEnter:()=>X(true),onMouseLeave:()=>X(false),title:"Send",style:{width:28,height:28,borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",color:"#ffffff",opacity:yt?1:.35,transform:W&&yt?"scale(1.08)":"scale(1)",background:yt?"#111827":"rgba(0, 0, 0, 0.12)",border:"none",cursor:yt?"pointer":"default",flexShrink:0,transition:"transform 0.15s, opacity 0.15s, background 0.15s",padding:0,marginLeft:4},children:ls.jsx(lucideReact.ArrowUp,{style:{width:14,height:14}})})]})]}),ls.jsx("input",{ref:ir,type:"file",accept:"image/*",multiple:true,style:{display:"none"},onChange:a=>{let T=Array.from(a.target.files??[]);a.target.value="",vr(T);}})]})]})]});return S?Fn:Oe&&Ie?as.createPortal(Fn,Ie.document.body):ls.jsx(Mi,{children:Fn})}function uo(e){if("target"in e&&e.target)return e.target;if("boundaryId"in e&&e.boundaryId)return {type:"boundary",id:e.boundaryId,title:e.title};if("slotId"in e&&e.slotId)return {type:"slot",id:e.slotId,title:e.title??e.slotLabel};throw new Error("Fork chat target requires either target, slotId, or boundaryId.")}function zn(e){let{apiKey:t,userId:n,userHash:r,baseUrl:o,appId:s,adminContext:i,refreshModuleManifest:l,queueBoundaryAnimation:u,trackForkActivity:h,recordForkActivityEvent:b}=ve(),[d,k]=Pn.useState({}),[R,v]=Pn.useState(null),[f,g]=Pn.useState("idle"),[S,I]=Pn.useState(false),[m,P]=Pn.useState(null),L=Pn.useRef(new Map),j=Pn.useCallback((C,M)=>{k(w=>{let $=w[C]??{forkId:C,state:"running",fork:M.fork,events:[],error:null};return {...w,[C]:{...$,...M}}});},[]),O=Pn.useCallback((C,M)=>{k(w=>{let p=w[C];return p?{...w,[C]:{...p,events:[...p.events,M]}}:w});},[]),N=Pn.useCallback(C=>{let M=L.current.get(C);M&&(M.close(),L.current.delete(C));},[]),oe=Pn.useCallback(()=>{g("prompting"),P(null),I(false),v(null);},[]),Y=Pn.useCallback(()=>{g("idle"),I(false),P(null),v(null);for(let C of L.current.values())C.close();L.current.clear(),k({});},[]),_=Pn.useCallback((C,M)=>{N(C.id);let w=new URLSearchParams({key:t});n&&w.set("userId",n),r&&w.set("userHash",r),i.isAdmin&&i.containerId&&w.set("containerId",i.containerId);let p=new EventSource(`${o}/api/v1/forks/${C.id}/events?${w.toString()}`);L.current.set(C.id,p),p.onmessage=$=>{try{let x=JSON.parse($.data);if(b(C.id,x),O(C.id,x),x.type==="complete"){let q=x.data;u(M,C.id),l().catch(()=>{}).finally(()=>{let re={...C,status:"complete",moduleUrl:q.moduleUrl,cssUrls:q.cssUrls,summary:q.summary,completedAt:new Date().toISOString()};j(C.id,{state:"complete",fork:re}),N(C.id);});}else if(x.type==="error"){let q=x.data;j(C.id,{state:"error",error:q.error||"Unknown error"}),N(C.id);}}catch{}},p.onerror=()=>{let $={Authorization:`Bearer ${t}`,...pe()};n&&($["X-Fork-User-Id"]=n),r&&($["X-Fork-User-Hash"]=r),fetch(`${o}/api/v1/forks/${C.id}`,{headers:$}).then(x=>x.json()).then(x=>{x.status==="complete"?(u(M,x.id),l().catch(()=>{}),j(C.id,{state:"complete",fork:x})):x.status==="error"?j(C.id,{state:"error",fork:x,error:x.error||"Fork generation failed"}):j(C.id,{fork:x});}).catch(()=>{j(C.id,{state:"error",error:"Connection lost"});}),N(C.id);};},[i.containerId,i.isAdmin,t,O,o,N,u,b,l,j,r,n]),F=Pn.useCallback(async(C,M,w)=>{try{if(!s)throw new Error("ForkProvider requires appId for module boundary prompts.");I(!0),P(null),v(null);let p;if(w?.forkId){let $={prompt:C};n&&($.userId=n),r&&($.userHash=r),w?.attachments?.length&&($.attachments=w.attachments),w?.selectedElement&&($.selectedElement=w.selectedElement);let x=await fetch(`${o}/api/v1/forks/${encodeURIComponent(w.forkId)}/prompts`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`,...pe()},body:JSON.stringify($)});if(!x.ok){let q=await x.json().catch(()=>({}));throw new Error(q.error||`API error: ${x.status}`)}p=await x.json();}else {let $={userId:n,prompt:C,boundaryId:e,appId:s};M?$.containerId=M:i.isAdmin&&i.containerId&&($.containerId=i.containerId),r&&($.userHash=r),w?.forceNew&&($.force_new=!0),w?.attachments?.length&&($.attachments=w.attachments),w?.selectedElement&&($.selectedElement=w.selectedElement);let x=await fetch(`${o}/api/v1/forks`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`,...pe()},body:JSON.stringify($)});if(!x.ok){let q=await x.json().catch(()=>({}));throw new Error(q.error||`API error: ${x.status}`)}p=await x.json();}k($=>({...$,[p.id]:{forkId:p.id,state:"running",fork:p,events:[],error:null}})),v(p.id),I(!1),h(p,{targetKind:"module",targetId:e}),_(p,p.boundaryId??e);}catch(p){P(p.message),I(false);}},[i.containerId,i.isAdmin,t,s,o,e,_,h,r,n]),H=Pn.useCallback(async C=>{try{let M={Authorization:`Bearer ${t}`,...pe()};n&&(M["X-Fork-User-Id"]=n),r&&(M["X-Fork-User-Hash"]=r);let w=await fetch(`${o}/api/v1/forks/${C}`,{headers:M});if(!w.ok)return;let p=await w.json(),$=p.boundaryId??e;if(h(p,{targetKind:"module",targetId:$}),p.status==="complete"){k(x=>({...x,[p.id]:{forkId:p.id,state:"complete",fork:p,events:[],error:null}})),v(p.id);return}if(p.status==="error"){k(x=>({...x,[p.id]:{forkId:p.id,state:"error",fork:p,events:[],error:p.error||"Fork generation failed"}})),v(p.id);return}if(p.status!=="pending"&&p.status!=="running"&&p.status!=="building")return;k(x=>({...x,[p.id]:{forkId:p.id,state:"running",fork:p,events:[],error:null}})),v(p.id),_(p,$);}catch{}},[t,o,e,_,h,r,n]),D=Pn.useCallback(async C=>{try{if(!s)throw new Error("ForkProvider requires appId for boundary undo.");let M={userId:n,boundaryId:e,appId:s};r&&(M.userHash=r),C&&(M.fork_id=C);let w=await fetch(`${o}/api/v1/forks/undo`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`},body:JSON.stringify(M)});if(!w.ok){let $=await w.json().catch(()=>({}));throw new Error($.error||`API error: ${w.status}`)}let p=await w.json();if(await l().catch(()=>{}),p.removed)k($=>{let x={};for(let[q,re]of Object.entries($))(re.fork.boundaryId??e)!==e&&(x[q]=re);return x}),v(null),g("prompting");else if(p.fork){let $=p.fork;j($.id,{state:"complete",fork:$}),v($.id);}return p}catch(M){throw P(M.message),M}},[t,s,o,e,l,j,r,n]),K=R?d[R]??null:null,V=S?"running":m?"error":K?K.state:f,W=K?.fork??null,X=K?.events??[],U=m??K?.error??null;return {state:V,fork:W,events:X,error:U,runs:d,open:oe,close:Y,startFork:F,undoFork:D,adoptRunningFork:H}}var Pi=0;function mo(e){let{state:t,fork:n,events:r,error:o,runs:s,open:i,close:l,startFork:u,undoFork:h,adoptRunningFork:b}=zn(e),[d,k]=Pn.useState(false),R=Pn.useRef(null),v=Pn.useRef(t),f=Pn.useCallback(()=>{R.current!==null&&(clearTimeout(R.current),R.current=null);},[]),g=Pn.useCallback(()=>{f(),k(true),i();},[f,i]),S=Pn.useCallback(()=>{f(),k(false),l();},[f,l]),I=Pn.useCallback(async P=>{f(),k(true),await b(P);},[b,f]),m=Object.values(s).filter(P=>P.state==="running").length;return Pn.useEffect(()=>{let P=v.current;v.current=t,t==="complete"&&P==="running"&&d&&m===0&&(f(),R.current=setTimeout(()=>{R.current=null,k(false),l();},Pi)),(t==="running"||t==="prompting")&&f();},[t,d,m,f,l]),Pn.useEffect(()=>f,[f]),{state:t,fork:n,events:r,error:o,runs:s,isOpen:d,open:g,close:S,submit:u,undo:h,adoptRunningFork:I}}function Wn(){let{apiKey:e,userId:t,userHash:n,baseUrl:r,adminContext:o,setSlotFork:s,clearSlotFork:i,skipAnimationForSlot:l,trackForkActivity:u,recordForkActivityEvent:h}=ve(),[b,d]=Pn.useState({}),[k,R]=Pn.useState(null),[v,f]=Pn.useState("idle"),[g,S]=Pn.useState(false),[I,m]=Pn.useState(null),P=Pn.useRef(new Map),L=Pn.useCallback((U,C)=>{d(M=>{let p=M[U]??{forkId:U,state:"running",fork:C.fork,events:[],error:null};return {...M,[U]:{...p,...C}}});},[]),j=Pn.useCallback((U,C)=>{d(M=>{let w=M[U];return w?{...M,[U]:{...w,events:[...w.events,C]}}:M});},[]),O=Pn.useCallback(U=>{let C=P.current.get(U);C&&(C.close(),P.current.delete(U));},[]),N=Pn.useCallback(()=>{f("prompting"),m(null),S(false),R(null);},[]),oe=Pn.useCallback(()=>{f("idle"),S(false),m(null),R(null);for(let U of P.current.values())U.close();P.current.clear(),d({});},[]),Y=Pn.useCallback((U,C)=>{O(U.id);let M=new URLSearchParams({key:e});t&&M.set("userId",t),n&&M.set("userHash",n),o.isAdmin&&o.containerId&&M.set("containerId",o.containerId);let w=new EventSource(`${r}/api/v1/forks/${U.id}/events?${M.toString()}`);P.current.set(U.id,w),w.onmessage=p=>{try{let $=JSON.parse(p.data);if(h(U.id,$),j(U.id,$),$.type==="complete"){let x=$.data,q={...U,status:"complete",bundleUrl:x.bundleUrl,summary:x.summary,revealPending:!0,completedAt:new Date().toISOString()};L(U.id,{state:"complete",fork:q});let re=C??U.slotId;re&&x.bundleUrl&&s(re,q),O(U.id);}else if($.type==="error"){let x=$.data;L(U.id,{state:"error",error:x.error||"Unknown error"}),O(U.id);}}catch{}},w.onerror=()=>{let p={Authorization:`Bearer ${e}`,...pe()};t&&(p["X-Fork-User-Id"]=t),n&&(p["X-Fork-User-Hash"]=n),fetch(`${r}/api/v1/forks/${U.id}`,{headers:p}).then($=>$.json()).then($=>{if($.status==="complete"){L(U.id,{state:"complete",fork:{...$,revealPending:true}});let x=C??$.slotId;x&&$.bundleUrl&&s(x,{...$,revealPending:true});}else $.status==="error"?L(U.id,{state:"error",fork:$,error:$.error||"Fork generation failed"}):L(U.id,{fork:$});}).catch(()=>{L(U.id,{state:"error",error:"Connection lost"});}),O(U.id);};},[o.containerId,o.isAdmin,e,j,r,O,h,s,L,n,t]),_=Pn.useCallback(async(U,C,M,w)=>{try{S(!0),m(null),R(null);let p;if(w?.forkId){let x={prompt:U};t&&(x.userId=t),n&&(x.userHash=n),w?.attachments?.length&&(x.attachments=w.attachments),w?.selectedElement&&(x.selectedElement=w.selectedElement);let q=await fetch(`${r}/api/v1/forks/${encodeURIComponent(w.forkId)}/prompts`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`,...pe()},body:JSON.stringify(x)});if(!q.ok){let re=await q.json().catch(()=>({}));throw new Error(re.error||`API error: ${q.status}`)}p=await q.json();}else {let x={userId:t,prompt:U};C&&(x.slotId=C),M?x.containerId=M:o.isAdmin&&o.containerId&&(x.containerId=o.containerId),n&&(x.userHash=n),w?.forceNew&&(x.force_new=!0),w?.attachments?.length&&(x.attachments=w.attachments),w?.selectedElement&&(x.selectedElement=w.selectedElement);let q=await fetch(`${r}/api/v1/forks`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`,...pe()},body:JSON.stringify(x)});if(!q.ok){let re=await q.json().catch(()=>({}));throw new Error(re.error||`API error: ${q.status}`)}p=await q.json();}d(x=>({...x,[p.id]:{forkId:p.id,state:"running",fork:p,events:[],error:null}})),R(p.id),S(!1);let $=C??p.slotId;$&&u(p,{targetKind:"slot",targetId:$}),Y(p,C);}catch(p){m(p.message),S(false);}},[o.containerId,o.isAdmin,e,r,Y,u,n,t]),F=Pn.useCallback(async U=>{try{let C={Authorization:`Bearer ${e}`,...pe()};t&&(C["X-Fork-User-Id"]=t),n&&(C["X-Fork-User-Hash"]=n);let M=await fetch(`${r}/api/v1/forks/${U}`,{headers:C});if(!M.ok)return;let w=await M.json();if(w.slotId&&u(w,{targetKind:"slot",targetId:w.slotId}),w.status==="complete"){d(p=>({...p,[w.id]:{forkId:w.id,state:"complete",fork:w,events:[],error:null}})),R(w.id);return}if(w.status==="error"){d(p=>({...p,[w.id]:{forkId:w.id,state:"error",fork:w,events:[],error:w.error||"Fork generation failed"}})),R(w.id);return}if(w.status!=="pending"&&w.status!=="running"&&w.status!=="building")return;d(p=>({...p,[w.id]:{forkId:w.id,state:"running",fork:w,events:[],error:null}})),R(w.id),Y(w,w.slotId);}catch{}},[e,r,Y,u,n,t]),H=Pn.useCallback(async U=>{try{let C={userId:t,slotId:U};n&&(C.userHash=n);let M=await fetch(`${r}/api/v1/forks/undo`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`},body:JSON.stringify(C)});if(!M.ok){let p=await M.json().catch(()=>({}));throw new Error(p.error||`API error: ${M.status}`)}let w=await M.json();if(l(U),w.removed)i(U),d(p=>{let $={};for(let[x,q]of Object.entries(p))q.fork.slotId!==U&&($[x]=q);return $}),R(null),f("prompting");else if(w.fork){s(U,w.fork);let p=w.fork;L(p.id,{state:"complete",fork:p});}return w}catch(C){throw m(C.message),C}},[e,t,n,r,i,s,l,L]),D=k?b[k]??null:null,K=g?"running":I?"error":D?D.state:v,V=D?.fork??null,W=D?.events??[],X=I??D?.error??null;return {state:K,fork:V,events:W,error:X,runs:b,open:N,close:oe,startFork:_,undoFork:H,adoptRunningFork:F}}var Hi=0;function yo(){let{state:e,fork:t,events:n,error:r,runs:o,open:s,close:i,startFork:l,undoFork:u,adoptRunningFork:h}=Wn(),[b,d]=Pn.useState(false),k=Pn.useRef(null),R=Pn.useRef(e),v=Pn.useCallback(()=>{k.current!==null&&(clearTimeout(k.current),k.current=null);},[]),f=Pn.useCallback(()=>{v(),d(true),s();},[v,s]),g=Pn.useCallback(()=>{v(),d(false),i();},[v,i]),S=Pn.useCallback(async m=>{v(),d(true),await h(m);},[h,v]),I=Object.values(o).filter(m=>m.state==="running").length;return Pn.useEffect(()=>{let m=R.current;R.current=e,e==="complete"&&m==="running"&&b&&I===0&&(v(),k.current=setTimeout(()=>{k.current=null,d(false),i();},Hi)),(e==="running"||e==="prompting")&&v();},[e,b,I,v,i]),Pn.useEffect(()=>v,[v]),{state:e,fork:t,events:n,error:r,runs:o,isOpen:b,open:f,close:g,submit:l,undo:u,adoptRunningFork:S}}var Oi=new Set(["pending","running","building"]);function Vn(e){let t=uo(e),n=yo(),r=mo(t.type==="boundary"?t.id:""),{baseUrl:o,apiKey:s,userId:i,userHash:l,appId:u,activitySummary:h,forkActivities:b}=ve(),d=t.type==="slot"?n:r,k=t.type==="slot"?"slot":"boundary",R=t.id,v=t.title,f=t.type==="slot"?"slot":"module",g=b.find(L=>L.targetKind===f&&L.targetId===t.id&&Oi.has(L.status)),S=b.find(L=>L.targetKind===f&&L.targetId===t.id&&L.status==="complete"&&L.unread),I=Pn.useCallback(()=>{let L=g??S;if(L){d.adoptRunningFork(L.id);return}d.open();},[d,g,S]),m=Pn.useCallback((L,j,O,N)=>t.type==="slot"?n.submit(L,j??t.id,O,N):r.submit(L,O,N),[r,n,t]),P=Pn.useCallback((L,j)=>t.type==="slot"?n.undo(L??t.id):r.undo(j),[r,n,t]);return {...d,open:I,target:t,targetId:R,targetLabel:v,historyMode:k,submit:m,undo:P,buttonProps:{onClick:I,hasNotification:h.unreadCompletedCount>0,activity:h},panelProps:{state:d.state,fork:d.fork,events:d.events,error:d.error,runs:d.runs,...t.type==="slot"?{slotId:R,targetLabel:v,historyMode:k}:{targetId:R,targetLabel:v,historyMode:k},onSubmit:m,onUndo:P,onClose:d.close,baseUrl:o,apiKey:s,userId:i,userHash:l,appId:u}}}function _t(e){let{embedded:t,completeVariant:n}=e,r=Vn(e);return t?ls.jsx(dn,{...r.panelProps,embedded:true,completeVariant:n}):r.isOpen?ls.jsx(dn,{...r.panelProps,completeVariant:n}):ls.jsx(Nn,{...r.buttonProps})}function Ni({boundaryId:e,title:t}){return ls.jsx(_t,{boundaryId:e,title:t})}function qn(e){let t=Array.from(e.children).filter(r=>r instanceof HTMLElement);return t.length===1?t[0]:getComputedStyle(e).display==="contents"?null:e}function ko(e){let t=e.getBoundingClientRect(),n=e.cloneNode(true);n.setAttribute("data-fork-clone-overlay","true"),n.style.position="fixed",n.style.top=`${t.top}px`,n.style.left=`${t.left}px`,n.style.width=`${t.width}px`,n.style.height=`${t.height}px`,n.style.flex="none",n.style.minHeight="auto",n.style.zIndex="9998",n.style.pointerEvents="none",n.style.overflow="hidden";let r=getComputedStyle(e).backgroundColor;n.style.backgroundColor=r&&r!=="rgba(0, 0, 0, 0)"&&r!=="transparent"?r:getComputedStyle(document.body).backgroundColor||"#ffffff",document.body.appendChild(n);let o=e.querySelectorAll("*"),s=n.querySelectorAll("*");for(let i=0;i<o.length;i+=1)o[i].scrollTop!==0&&(s[i].scrollTop=o[i].scrollTop),o[i].scrollLeft!==0&&(s[i].scrollLeft=o[i].scrollLeft);return n}function Gn(e){let t=[],n=e.querySelectorAll("*");for(let r of n){if(!(r instanceof HTMLElement))continue;let o=r.getBoundingClientRect();if(o.width<10||o.height<10||["SCRIPT","STYLE","META","LINK"].includes(r.tagName))continue;let s=getComputedStyle(r),i=parseFloat(s.borderTopLeftRadius)||0;t.push({tag:r.tagName,className:r.className||"",text:(r.textContent||"").slice(0,50).trim(),rect:o,borderRadius:i});}return t}function bo(e,t){let n=[];for(let r of t)if(!(e.find(i=>i.tag===r.tag&&i.className===r.className&&Math.abs(i.rect.top-r.rect.top)<20&&Math.abs(i.rect.left-r.rect.left)<20)||n.some(i=>r.rect.top>=i.rect.top&&r.rect.left>=i.rect.left&&r.rect.right<=i.rect.right&&r.rect.bottom<=i.rect.bottom))){for(let i=n.length-1;i>=0;i-=1){let l=n[i];l.rect.top>=r.rect.top&&l.rect.left>=r.rect.left&&l.rect.right<=r.rect.right&&l.rect.bottom<=r.rect.bottom&&n.splice(i,1);}n.push({rect:r.rect,borderRadius:r.borderRadius});}return n}function wo(e,t){let n=[];for(let r of e)if(!(t.find(i=>i.tag===r.tag&&i.className===r.className&&Math.abs(i.rect.top-r.rect.top)<20&&Math.abs(i.rect.left-r.rect.left)<20)||n.some(i=>r.rect.top>=i.rect.top&&r.rect.left>=i.rect.left&&r.rect.right<=i.rect.right&&r.rect.bottom<=i.rect.bottom))){for(let i=n.length-1;i>=0;i-=1){let l=n[i];l.rect.top>=r.rect.top&&l.rect.left>=r.rect.left&&l.rect.right<=r.rect.right&&l.rect.bottom<=r.rect.bottom&&n.splice(i,1);}n.push({rect:r.rect,borderRadius:r.borderRadius});}return n}function vo(e,t,n,r,o){let s=Math.max(0,Math.min(o,n/2,r/2));return s===0?`M ${e} ${t} L ${e+n} ${t} L ${e+n} ${t+r} L ${e} ${t+r} Z`:[`M ${e+s} ${t}`,`L ${e+n-s} ${t}`,`A ${s} ${s} 0 0 1 ${e+n} ${t+s}`,`L ${e+n} ${t+r-s}`,`A ${s} ${s} 0 0 1 ${e+n-s} ${t+r}`,`L ${e+s} ${t+r}`,`A ${s} ${s} 0 0 1 ${e} ${t+r-s}`,`L ${e} ${t+s}`,`A ${s} ${s} 0 0 1 ${e+s} ${t}`,"Z"].join(" ")}function Yn(e){let t="http://www.w3.org/2000/svg",n=document.createElement("div");n.setAttribute("data-fork-highlights","true"),n.style.cssText="position:fixed;top:0;left:0;width:100%;height:100%;pointer-events:none;z-index:9999;";let r=document.createElementNS(t,"svg");r.setAttribute("width","100%"),r.setAttribute("height","100%"),r.style.cssText="position:absolute;top:0;left:0;overflow:visible;";let o=document.createElementNS(t,"defs");r.appendChild(o);let s=[];for(let b=0;b<e.length;b+=1){let{rect:d,borderRadius:k}=e[b],R=d.left-.5,v=d.top-.5,f=d.width+1,g=d.height+1,S=Math.min(k+.5,f/2,g/2),I=vo(R,v,f,g,S),m=`__fork-glow-${b}`,P=document.createElementNS(t,"filter");P.setAttribute("id",m),P.setAttribute("x","-100%"),P.setAttribute("y","-100%"),P.setAttribute("width","300%"),P.setAttribute("height","300%");let L=document.createElementNS(t,"feGaussianBlur");L.setAttribute("in","SourceGraphic"),L.setAttribute("stdDeviation","8"),P.appendChild(L),o.appendChild(P);let j=`__fork-mask-${b}`,O=document.createElementNS(t,"mask");O.setAttribute("id",j),O.setAttribute("maskUnits","userSpaceOnUse"),O.setAttribute("x",String(R-200)),O.setAttribute("y",String(v-200)),O.setAttribute("width",String(f+400)),O.setAttribute("height",String(g+400));let N=document.createElementNS(t,"rect");N.setAttribute("x",String(R-200)),N.setAttribute("y",String(v-200)),N.setAttribute("width",String(f+400)),N.setAttribute("height",String(g+400)),N.setAttribute("fill","white"),O.appendChild(N);let oe=document.createElementNS(t,"path");oe.setAttribute("d",I),oe.setAttribute("fill","black"),O.appendChild(oe),o.appendChild(O);let Y=document.createElementNS(t,"g");Y.setAttribute("mask",`url(#${j})`),Y.setAttribute("opacity","0");let _=document.createElementNS(t,"g");_.setAttribute("filter",`url(#${m})`);let F=document.createElementNS(t,"path");F.setAttribute("d",I),F.setAttribute("fill","none"),F.setAttribute("stroke","rgba(150, 185, 220, 0.6)"),F.setAttribute("stroke-width","6"),F.setAttribute("stroke-linecap","round"),_.appendChild(F),Y.appendChild(_),r.appendChild(Y);let H=document.createElementNS(t,"path");H.setAttribute("d",I),H.setAttribute("fill","none"),H.setAttribute("stroke","rgba(150, 185, 220, 0.35)"),H.setAttribute("stroke-width","2"),H.setAttribute("stroke-linecap","round"),H.setAttribute("opacity","0"),r.appendChild(H),s.push(F,H),F.__group=Y;}n.appendChild(r),document.body.appendChild(n);let i=[];for(let b=0;b<s.length;b+=2){let d=s[b],k=s[b+1],R=d.__group;if(!R)continue;let v=k.getTotalLength(),f=d.getTotalLength();if(v<=0)continue;let g=v*.35;k.setAttribute("stroke-dasharray",`${g} ${v-g}`),k.setAttribute("stroke-dashoffset","0"),i.push(k.animate([{strokeDashoffset:0,opacity:0,offset:0},{strokeDashoffset:-0.2*v,opacity:.92,offset:.06},{strokeDashoffset:-2*v,opacity:.92,offset:.92},{strokeDashoffset:-2.25*v,opacity:0,offset:1}],{duration:14e3,easing:"ease-in-out",fill:"forwards"}));let S=f*.35;d.setAttribute("stroke-dasharray",`${S} ${f-S}`),d.setAttribute("stroke-dashoffset","0"),i.push(d.animate([{strokeDashoffset:0,offset:0},{strokeDashoffset:-0.2*f,offset:.06},{strokeDashoffset:-2*f,offset:.92},{strokeDashoffset:-2.25*f,offset:1}],{duration:14e3,easing:"ease-in-out",fill:"forwards"})),i.push(R.animate([{opacity:0,offset:0},{opacity:.92,offset:.06},{opacity:.92,offset:.92},{opacity:0,offset:1}],{duration:14e3,easing:"ease-in-out",fill:"forwards"}));}let l=false,u=()=>{if(l)return;l=true,clearTimeout(h);for(let d of i)try{d.cancel();}catch{}let b=n.animate([{opacity:1},{opacity:0}],{duration:400,fill:"forwards"});b.onfinish=()=>n.remove(),window.removeEventListener("click",u);},h=setTimeout(u,14500);return setTimeout(()=>{l||window.addEventListener("click",u);},500),u}function So(e){let t="http://www.w3.org/2000/svg",n=document.createElement("div");n.setAttribute("data-fork-removed","true"),n.style.cssText="position:fixed;top:0;left:0;width:100%;height:100%;pointer-events:none;z-index:9999;";let r=document.createElementNS(t,"svg");r.setAttribute("width","100%"),r.setAttribute("height","100%"),r.style.cssText="position:absolute;top:0;left:0;overflow:visible;";let o=document.createElementNS(t,"defs"),s=document.createElementNS(t,"filter");s.setAttribute("id","__fork-removed-shadow"),s.setAttribute("x","-10%"),s.setAttribute("y","-10%"),s.setAttribute("width","120%"),s.setAttribute("height","120%");let i=document.createElementNS(t,"feDropShadow");i.setAttribute("dx","0"),i.setAttribute("dy","1"),i.setAttribute("stdDeviation","2"),i.setAttribute("flood-color","rgba(0,0,0,0.15)"),s.appendChild(i),o.appendChild(s),r.appendChild(o);for(let{rect:l,borderRadius:u}of e){let h=document.createElementNS(t,"path");h.setAttribute("d",vo(l.left,l.top,l.width,l.height,u)),h.setAttribute("fill","none"),h.setAttribute("stroke","rgba(120, 125, 135, 0.6)"),h.setAttribute("stroke-width","1.5"),h.setAttribute("stroke-dasharray","8 4"),h.setAttribute("stroke-linecap","round"),h.setAttribute("filter","url(#__fork-removed-shadow)"),h.setAttribute("opacity","0"),r.appendChild(h),h.animate([{opacity:0,offset:0},{opacity:.6,offset:.08},{opacity:.05,offset:.45},{opacity:.6,offset:.85},{opacity:.05,offset:1}],{duration:5e3,easing:"ease-in-out",fill:"forwards"});}return n.appendChild(r),document.body.appendChild(n),n}function Ao(e,t){if(Bi(t.selector))return xo(e,t);let r=xo(e,t);if(r)return r;try{let s=document.querySelector(t.selector);if(s instanceof HTMLElement&&s!==e&&e.contains(s))return s}catch{}if(Fo(t.selector))try{let s=e.querySelector(t.selector);if(s instanceof HTMLElement&&s!==e)return s}catch{}if(t.textHint){let s=t.textHint.trim();if(s){let i=Qn(e,b=>b===s);if(i)return i;let l=s.toLowerCase(),u=Qn(e,b=>b.toLowerCase()===l);if(u)return u;let h=Qn(e,b=>b.toLowerCase().includes(l));if(h)return h}}let o=Di(t.selector);if(o&&o!==t.selector&&Fo(o))try{let s=e.querySelector(o);if(s instanceof HTMLElement&&s!==e)return s}catch{}return null}function Fo(e){let t=e.split(/\s+|>|~|\+/),n=t[t.length-1]??"";return /[#\[]|:not\(|:nth-/.test(n)}function xo(e,t){let n=Array.from(e.querySelectorAll("[data-fork-new]"));if(n.length===0)return null;let r=Zn(t.label),o=Zn(t.textHint);return n.find(i=>{let l=Zn(i.getAttribute("data-fork-new"));return !!l&&(l===r||l===o)})??null}function Bi(e){return e.trim()==="[data-fork-new]"}function Zn(e){return e?.trim().replace(/\s+/g," ").toLowerCase()||null}function Di(e){return e.replace(/\[class[\*~|^$]?=("[^"]*"|'[^']*'|[^\]]+)\]/g,"").replace(/\.[A-Za-z_][\w-]*/g,"").replace(/\s+/g," ").trim()}function Qn(e,t){let n=null,r=1/0,o=e.querySelectorAll("*");for(let s of o){let i=s.textContent?.trim();if(!i||!t(i))continue;let l=s.getBoundingClientRect();if(l.width<4||l.height<4)continue;let u=l.width*l.height;u<r&&(n=s,r=u);}return n}var er=2147483600,ji=1600,Ki=3e4,zi=300,Qe=10;function Wi(e){let n=getComputedStyle(e).borderTopLeftRadius;if(!n)return 4;if(n.endsWith("%")){let i=parseFloat(n);if(!Number.isFinite(i)||i<=0)return 4;let l=e.getBoundingClientRect(),u=Math.min(l.width,l.height);return Math.max(4,i/100*u)}let r=parseFloat(n);if(!Number.isFinite(r)||r<=0)return 4;let o=e.getBoundingClientRect(),s=Math.min(o.width,o.height)/2;return r>=s?s:Math.min(r,16)}function Ji(e,t,n,r){let s=window.innerWidth,i=window.innerHeight,l=e;l==="top"&&t.top<r+Qe+8?l="bottom":l==="bottom"&&i-t.bottom<r+Qe+8?l="top":l==="left"&&t.left<n+Qe+8?l="right":l==="right"&&s-t.right<n+Qe+8&&(l="left");let u=0,h=0;return l==="top"?(u=t.top-r-Qe,h=t.left+t.width/2-n/2):l==="bottom"?(u=t.bottom+Qe,h=t.left+t.width/2-n/2):l==="left"?(u=t.top+t.height/2-r/2,h=t.left-n-Qe):(u=t.top+t.height/2-r/2,h=t.right+Qe),h=Math.max(8,Math.min(h,s-n-8)),u=Math.max(8,Math.min(u,i-r-8)),{top:u,left:h,placement:l}}function Vi(e){let t=document.createElement("div");t.setAttribute("data-fork-highlight-outline","true"),t.style.cssText=["position:fixed","pointer-events:none",`z-index:${er}`,"border:1.5px solid rgba(59,130,246,0.85)","box-sizing:border-box","opacity:0","transition:opacity 200ms ease-out"].join(";");let n=document.createElement("div");n.setAttribute("data-fork-highlight-glow","true"),n.style.cssText=["position:fixed","pointer-events:none",`z-index:${er-1}`,"box-sizing:border-box","border:1px solid rgba(59,130,246,0.36)","box-shadow:0 0 0 4px rgba(59,130,246,0.16), 0 0 18px 2px rgba(59,130,246,0.31)","opacity:0","transition:opacity 200ms ease-out"].join(";");let r=document.createElement("div");return r.setAttribute("data-fork-highlight-tooltip","true"),r.style.cssText=["position:fixed","pointer-events:none",`z-index:${er+1}`,"padding:6px 10px","font:500 12px/1.2 -apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif","color:#ffffff","background:linear-gradient(135deg,#64748b,#475569)","border-radius:999px","box-shadow:0 4px 14px rgba(71,85,105,0.31),0 1px 2px rgba(0,0,0,0.1)","white-space:nowrap","opacity:0","transform:translateY(-2px)","transition:opacity 200ms ease-out, transform 200ms ease-out"].join(";"),r.textContent=`New: ${e}`,{outline:t,glow:n,tooltip:r}}function Xi(){if(document.getElementById("__fork-highlight-keyframes"))return;let e=document.createElement("style");e.id="__fork-highlight-keyframes",e.textContent=`
|
|
59
|
+
`}),ls.jsxs("div",{className:"__fork-panel",style:rs,children:[ls.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"0 16px",height:54,boxSizing:"border-box",borderBottom:"1px solid rgba(229, 231, 235, 0.8)",flexShrink:0},children:[ls.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0,flex:1},children:[c||A?ls.jsxs(ls.Fragment,{children:[ls.jsx("button",{onClick:()=>{y(null),z(false),Q.current=false;},style:{width:30,height:30,borderRadius:9,background:"#ffffff",border:"1px solid #e5e7eb",color:"#111827",cursor:"pointer",display:"inline-flex",alignItems:"center",justifyContent:"center",padding:0,flexShrink:0,transition:"background 0.12s, border-color 0.12s"},onMouseEnter:a=>{a.currentTarget.style.background="#f9fafb",a.currentTarget.style.borderColor="#d1d5db";},onMouseLeave:a=>{a.currentTarget.style.background="#ffffff",a.currentTarget.style.borderColor="#e5e7eb";},title:"Back to all forks",children:ls.jsx(lucideReact.ChevronLeft,{style:{width:15,height:15}})}),(()=>{let a=c?o[c]:void 0,B=(a?a.events.find(G=>{let le=G.data;return G.type==="status"&&le.summary})?.data?.summary??a.fork.summary:void 0)||vn?.summary||"New Feature";return ls.jsx("span",{style:{fontSize:13.5,fontWeight:700,color:"#111827",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",minWidth:0},title:B,children:B})})()]}):ls.jsxs(ls.Fragment,{children:[ls.jsx("span",{onDoubleClick:async a=>{if(a.stopPropagation(),!re&&confirm("Kill all forks in this container?")){Ae(true);try{let T=await zo();`${T?.deleted??0}`,ft([]),y(null),z(!1),P("");}catch(T){console.error("[Fork] Reset failed:",T);}finally{Ae(false);}}},style:{display:"inline-flex",alignItems:"center",justifyContent:"center",padding:4,margin:-4,cursor:"pointer",flexShrink:0},children:ls.jsx(nn,{style:{width:16,height:16,color:"#111827",pointerEvents:"none"}})}),De==="running"?ls.jsx("span",{style:{fontSize:13,fontWeight:600,color:"#111827",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:Qo}):Te.length===0&&!Vt?ls.jsx("span",{style:{fontSize:13,fontWeight:600,color:"#111827",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:"Fork"}):Vt?ls.jsxs("div",{ref:Yt,style:{position:"relative",minWidth:0,display:"inline-flex"},children:[ls.jsxs("button",{type:"button",onClick:()=>{ke(a=>!a);},onMouseEnter:()=>Bt(true),onMouseLeave:()=>Bt(false),"aria-haspopup":"menu","aria-expanded":$e,style:{display:"inline-flex",alignItems:"center",gap:4,padding:"3px 6px",border:"1px solid transparent",borderRadius:6,background:hn||$e?"#f3f4f6":"transparent",fontSize:13,fontWeight:600,color:"#111827",fontFamily:"inherit",cursor:"pointer",maxWidth:180,minWidth:0,transition:"background-color 0.12s"},children:[ls.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:Mr}),ls.jsx(lucideReact.ChevronDown,{style:{width:12,height:12,color:"#6b7280",flexShrink:0,transform:$e?"rotate(180deg)":void 0,transition:"transform 0.15s"}})]}),$e&&ls.jsxs("div",{role:"menu",style:{position:"absolute",top:"calc(100% + 4px)",left:0,minWidth:200,maxWidth:260,background:"#ffffff",border:"1px solid #e5e7eb",borderRadius:8,boxShadow:"0 4px 12px rgba(0,0,0,0.08), 0 1px 3px rgba(0,0,0,0.06)",padding:4,zIndex:2147483001},children:[Te.map(a=>{let T=a.id===Se,B=yn===a.id,G=ge===a.id;return ls.jsxs("button",{type:"button",role:"menuitem",onMouseEnter:()=>Dt(a.id),onMouseLeave:()=>Dt(null),onClick:()=>{a.id!==Se&&ns(a.id);},disabled:!!ge,style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"6px 8px",border:"none",background:B?"#f3f4f6":"transparent",borderRadius:4,fontSize:13,fontFamily:"inherit",color:"#111827",cursor:ge?"default":"pointer",textAlign:"left",fontWeight:T?600:400,opacity:ge&&!G?.55:1},children:[ls.jsx("span",{style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:14,height:14,color:"#111827",flexShrink:0},children:T&&ls.jsx(lucideReact.Check,{style:{width:12,height:12}})}),ls.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:G?"Switching...":a.name})]},a.id)}),ls.jsx("div",{style:{height:1,background:"#e5e7eb",margin:"4px 0"}}),bt?ls.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4,padding:"4px 4px"},children:[ls.jsx("input",{ref:wt,type:"text",value:Be,placeholder:"Container name",disabled:ge==="__new__",onChange:a=>Xe(a.target.value),onKeyDown:a=>{a.key==="Enter"?(a.preventDefault(),Rr(Be)):a.key==="Escape"&&(a.preventDefault(),a.stopPropagation(),ut(false),Xe(""));},style:{flex:1,minWidth:0,padding:"5px 8px",border:"1px solid #d1d5db",borderRadius:4,fontSize:13,fontFamily:"inherit",color:"#111827",background:"#ffffff",outline:"none"},onFocus:a=>{a.currentTarget.style.borderColor="#111827",a.currentTarget.style.boxShadow="0 0 0 2px rgba(17,24,39,0.15)";},onBlur:a=>{a.currentTarget.style.borderColor="#d1d5db",a.currentTarget.style.boxShadow="none";}}),ls.jsx("button",{type:"button",onClick:()=>{Rr(Be);},disabled:!Be.trim()||ge==="__new__",title:"Create",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:26,height:26,border:"none",borderRadius:4,background:!Be.trim()||ge==="__new__"?"#e5e7eb":"#111827",color:!Be.trim()||ge==="__new__"?"#9ca3af":"#ffffff",cursor:!Be.trim()||ge==="__new__"?"default":"pointer",flexShrink:0},children:ge==="__new__"?ls.jsx("span",{style:{width:10,height:10,border:"1.5px solid currentColor",borderTopColor:"transparent",borderRadius:"50%",animation:"__fork-spin 0.7s linear infinite"}}):ls.jsx(lucideReact.Check,{style:{width:12,height:12}})})]}):ls.jsx("button",{type:"button",role:"menuitem",onMouseEnter:()=>jt(true),onMouseLeave:()=>jt(false),onClick:()=>{ge||(Fe(null),Xe(""),ut(true));},disabled:!!ge,style:{display:"flex",alignItems:"center",width:"100%",padding:"6px 8px",border:"none",background:tt?"#f3f4f6":"transparent",borderRadius:4,fontSize:13,fontFamily:"inherit",color:"#111827",cursor:ge?"default":"pointer",textAlign:"left",opacity:ge&&ge!=="__new__"?.55:1},children:"+ New container"}),Kt&&ls.jsx("div",{style:{padding:"6px 8px",fontSize:11,lineHeight:1.35,color:"#b91c1c"},children:Kt})]})]}):ls.jsx("span",{style:{fontSize:13,fontWeight:600,color:"#111827",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:Mr})]}),De==="running"&&ls.jsx("span",{title:nt?`Estimated ~${nt} min`:"Estimating\u2026",style:{fontSize:10,fontWeight:600,color:nt?"#111827":"#9ca3af",backgroundColor:nt?"rgba(17, 24, 39, 0.08)":"rgba(156, 163, 175, 0.12)",padding:"1px 6px",borderRadius:999,flexShrink:0,fontVariantNumeric:"tabular-nums",animation:nt?void 0:"__fork-pulse 1.4s ease-in-out infinite",minWidth:28,textAlign:"center"},children:nt?`~${nt}m`:"~ m"})]}),ls.jsxs("div",{style:{display:"flex",alignItems:"center",gap:2,flexShrink:0},children:[Vo&&ls.jsx("button",{type:"button",role:"switch","aria-checked":!mt,"aria-label":mt?"Turn Fork back on":"Turn Fork off",title:mt?"Fork is off \u2014 you're seeing the original app. Turn it back on. Only affects you.":"Turn Fork off to see the original app. Only affects you.",onClick:()=>{Jo(!mt);},onMouseEnter:()=>gr(true),onMouseLeave:()=>gr(false),style:{position:"relative",width:26,height:15,borderRadius:999,border:"none",padding:0,marginRight:6,flexShrink:0,cursor:"pointer",backgroundColor:mt?mr?"#9ca3af":"#d1d5db":mr?"#374151":"#111827",transition:"background-color 0.18s ease",outline:"none",boxSizing:"border-box"},children:ls.jsx("span",{"aria-hidden":true,style:{position:"absolute",top:2,left:mt?2:13,width:11,height:11,borderRadius:"50%",backgroundColor:"#ffffff",boxShadow:"0 1px 2px rgba(15, 23, 42, 0.25)",transition:"left 0.18s cubic-bezier(0.16, 1, 0.3, 1)"}})}),!S&&ls.jsxs(ls.Fragment,{children:[yr&&ls.jsx("button",{onClick:Oe?qo:Xo,onMouseEnter:()=>V(true),onMouseLeave:()=>V(false),title:Oe?"Redock to sidebar":"Pop out into window",style:{padding:6,borderRadius:6,color:K?"#4b5563":"#9ca3af",backgroundColor:K?"#f3f4f6":"transparent",border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",transition:"background-color 0.15s, color 0.15s"},children:Oe?ls.jsx(lucideReact.PictureInPicture,{style:{width:16,height:16}}):ls.jsx(lucideReact.PictureInPicture2,{style:{width:16,height:16}})}),ls.jsx("button",{onClick:Cr,onMouseEnter:()=>D(true),onMouseLeave:()=>D(false),style:{padding:6,borderRadius:6,color:H?"#4b5563":"#9ca3af",backgroundColor:H?"#f3f4f6":"transparent",border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",transition:"background-color 0.15s, color 0.15s"},children:ls.jsx(lucideReact.X,{style:{width:16,height:16}})})]})]})]}),ls.jsxs("div",{ref:ne,style:{flex:1,overflowY:"auto",minHeight:0,display:"flex",flexDirection:"column"},children:[!c&&!A&&ls.jsxs("div",{style:{display:"flex",flexDirection:"column"},children:[Ne.length===0&&ls.jsx("div",{style:{padding:"24px 20px",textAlign:"center",fontSize:13,color:"#6b7280"},children:"No forks yet. Describe a feature below to start one."}),Ne.length>0&&ls.jsx("div",{style:{display:"flex",flexDirection:"column"},children:Ne.map((a,T)=>{let B=o[a.id],le=(B?B.events.find(Ye=>{let ss=Ye.data;return Ye.type==="status"&&ss.summary})?.data?.summary??B.fork.summary:void 0)||a.summary||"Untitled fork",je=!!fr.find(Ye=>Ye.id===a.id)?.unread,Me=o[a.id]?.state??a.status,os=Me==="running"||Me==="building"||Me==="pending";return ls.jsxs(Pn.Fragment,{children:[ls.jsxs("button",{onClick:()=>{z(false),y(a.id);},style:{textAlign:"left",padding:"12px 16px",background:"transparent",border:"none",cursor:"pointer",display:"flex",alignItems:"flex-start",gap:8,width:"100%",transition:"background 0.12s",fontFamily:"inherit"},onMouseEnter:Ye=>{Ye.currentTarget.style.background="#fafafa";},onMouseLeave:Ye=>{Ye.currentTarget.style.background="transparent";},children:[je&&ls.jsx("span",{"aria-label":"Not viewed yet",title:"Not viewed yet",style:{width:7,height:7,borderRadius:"50%",backgroundColor:"#111827",flexShrink:0,marginTop:5}}),ls.jsxs("div",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:5,alignItems:"flex-start"},children:[ls.jsx("span",{style:{fontSize:13.5,fontWeight:600,color:"#111827",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",maxWidth:"100%"},children:le}),ls.jsx("span",{style:{fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, "Liberation Mono", "Courier New", monospace',fontSize:10,color:"#9ca3af",background:"#f8f9fa",borderRadius:5,padding:"1px 6px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",maxWidth:"100%",boxSizing:"border-box"},children:a.targetId})]}),os&&ls.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:5,background:"#fff7ed",border:"1px solid #fed7aa",color:"#c2410c",borderRadius:999,padding:"2px 9px",fontSize:11,fontWeight:600,flexShrink:0},children:[ls.jsx("span",{style:{width:6,height:6,borderRadius:"50%",background:"#f59e0b",animation:"__fork-pulse 1.4s ease-in-out infinite"}}),"Running"]}),Me==="error"&&ls.jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:5,background:"#fef2f2",border:"1px solid #fecaca",color:"#b91c1c",borderRadius:999,padding:"2px 9px",fontSize:11,fontWeight:600,flexShrink:0},children:"Failed"}),ls.jsx("span",{style:{fontSize:11.5,color:"#9ca3af",flexShrink:0,marginTop:2},children:Kn(a.updatedAt)})]}),T<Ne.length-1&&ls.jsx("div",{style:{height:1,background:"#f3f4f6",margin:"0 16px",flexShrink:0}})]},a.id)})})]}),c&&xt.length>0&&ls.jsx("div",{style:{margin:"16px 16px 0 16px"},children:xt.map((a,T)=>ls.jsx("div",{style:{marginBottom:T<xt.length-1?12:0},children:a.type==="user"?ls.jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:ls.jsxs("div",{style:{backgroundColor:"#f3f4f6",borderRadius:12,padding:"10px 14px",fontSize:13,color:"#374151",lineHeight:1.5,maxWidth:"85%"},children:[a.attachments&&a.attachments.length>0&&ls.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,marginBottom:6},children:a.attachments.map((B,G)=>ls.jsx("img",{src:B.dataUrl,alt:"attachment",style:{maxWidth:150,maxHeight:110,borderRadius:8,border:"1px solid #e5e7eb",display:"block",objectFit:"cover"}},G))}),a.selectedElement&&ls.jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:4,background:"#eef2ff",border:"1px solid #c7d2fe",color:"#4338ca",borderRadius:999,padding:"2px 8px",fontSize:10.5,fontWeight:500,marginRight:6,maxWidth:"100%"},children:[ls.jsx(lucideReact.MousePointer2,{style:{width:10,height:10,flexShrink:0}}),ls.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"ui-monospace, SFMono-Regular, Menlo, monospace"},children:a.selectedElement.label})]}),a.text]})}):I==="item"&&T===xt.length-1?ls.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:12,padding:12,borderRadius:8,border:"1px solid #e4e4e7",background:"#ffffff"},children:[ls.jsx("div",{style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:28,height:28,flexShrink:0,borderRadius:6,background:"#f4f4f5",color:"#0a0a0a"},children:ls.jsx(lucideReact.BadgeCheck,{style:{width:16,height:16}})}),ls.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:2,flex:1,minWidth:0},children:[ls.jsx("div",{style:{fontSize:13,fontWeight:500,color:"#0a0a0a",lineHeight:1.3},children:"Feature applied"}),ls.jsx("div",{style:{fontSize:13,color:"#71717a",lineHeight:1.4},children:a.text})]}),b&&De!=="running"&&ls.jsx("button",{onClick:B=>{B.stopPropagation(),Ir();},disabled:p,style:{padding:"4px 10px",fontSize:12,fontWeight:500,borderRadius:6,border:"1px solid #e4e4e7",background:"#ffffff",color:"#0a0a0a",cursor:p?"default":"pointer",opacity:p?.4:1,height:28,flexShrink:0},children:"Undo"})]}):ls.jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:8,background:"#ffffff",border:"1px solid #e5e7eb",borderRadius:10,boxShadow:"0 1px 2px rgba(0, 0, 0, 0.03)",padding:"9px 12px",maxWidth:"90%",boxSizing:"border-box"},children:[ls.jsx("span",{style:{width:7,height:7,borderRadius:"50%",background:"#94a3b8",flexShrink:0}}),ls.jsx("span",{style:{fontSize:12.5,fontWeight:600,color:"#334155",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:a.text}),a.timestamp&&ls.jsx("span",{style:{fontSize:11,color:"#9ca3af",flexShrink:0},children:Kn(a.timestamp)}),b&&T===xt.length-1&&De!=="running"&&ls.jsxs("button",{onClick:B=>{B.stopPropagation(),Ir();},onMouseEnter:()=>q(T),onMouseLeave:()=>q(null),disabled:p,style:{position:"relative",padding:2,borderRadius:4,border:"none",background:x===T?"rgba(0,0,0,0.06)":"transparent",color:x===T?"#6b7280":"#d1d5db",cursor:p?"default":"pointer",display:"flex",alignItems:"center",justifyContent:"center",transition:"color 0.15s, background 0.15s",opacity:p?.4:1,flexShrink:0},children:[ls.jsx(lucideReact.Undo2,{style:{width:12,height:12}}),x===T&&ls.jsx("span",{style:{position:"absolute",bottom:"calc(100% + 4px)",right:0,fontSize:10,fontWeight:500,color:"#fff",background:"#374151",borderRadius:4,padding:"2px 6px",whiteSpace:"nowrap",pointerEvents:"none",lineHeight:"16px"},children:"Undo"})]})]})},T))}),De==="running"&&ls.jsx("div",{style:{margin:"12px 16px 0 16px"},children:ls.jsxs("div",{onClick:()=>w(!M),style:{background:"#ffffff",border:"1px solid #e5e7eb",borderRadius:10,boxShadow:"0 1px 2px rgba(0, 0, 0, 0.03)",overflow:"hidden",cursor:"pointer",transition:"all 0.3s cubic-bezier(0.22, 1, 0.36, 1)"},children:[ls.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"9px 12px"},children:[ls.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[ls.jsx("span",{style:{width:7,height:7,borderRadius:"50%",background:"#f59e0b",flexShrink:0,animation:"__fork-pulse 1.4s ease-in-out infinite"}}),ls.jsx(Ci,{events:ht},c??"__compose__")]}),ls.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flexShrink:0,marginLeft:8},children:[ht[0]?.timestamp&&ls.jsx("span",{style:{fontSize:11,color:"#9ca3af"},children:Kn(ht[0].timestamp)}),ls.jsx("div",{style:{color:"#9ca3af",transition:"transform 0.2s ease",transform:M?"rotate(180deg)":"rotate(0deg)",display:"flex"},children:ls.jsx(lucideReact.ChevronDown,{style:{width:14,height:14}})})]})]}),ls.jsx("div",{style:{maxHeight:M?320:0,opacity:M?1:0,transition:"max-height 0.35s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.25s ease",overflow:"hidden"},children:ls.jsx("div",{style:{background:"#1a1a2e",borderTop:"1px solid #e5e7eb",maxHeight:320,overflowY:"auto"},children:ls.jsx(Zr,{events:ht},c??"__compose__")})})]})}),De==="error"&&ls.jsxs("div",{style:{padding:"20px 16px",textAlign:"center"},children:[ls.jsx("div",{style:{width:36,height:36,backgroundColor:"#fef2f2",borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",margin:"0 auto 10px auto"},children:ls.jsx(lucideReact.X,{style:{width:18,height:18,color:"#ef4444"}})}),ls.jsx("p",{style:{fontSize:12,color:"#6b7280",marginBottom:10,maxWidth:260,margin:"0 auto 10px auto"},children:Yo??r}),ls.jsxs("button",{onClick:()=>{let a=Sn?.prompt||qt.current;a&&h(a,vt);},onMouseEnter:()=>C(true),onMouseLeave:()=>C(false),style:{display:"inline-flex",alignItems:"center",gap:6,padding:"6px 12px",borderRadius:8,fontSize:12,fontWeight:500,color:"#111827",backgroundColor:U?"#e5e7eb":"#f3f4f6",border:"none",cursor:"pointer",transition:"background-color 0.15s",fontFamily:"inherit"},children:[ls.jsx(lucideReact.RotateCcw,{style:{width:12,height:12}})," Try Again"]})]})]}),!(c?De==="running":A&&e==="running")&&ls.jsxs("div",{style:{padding:"8px 12px 12px 12px",borderTop:"1px solid rgba(229, 231, 235, 0.6)",flexShrink:0,position:"relative"},children:[pt&&ls.jsx("div",{style:{position:"absolute",top:-42,left:"50%",transform:"translateX(-50%)",background:"#111827",color:"#ffffff",fontSize:12,fontWeight:500,padding:"7px 14px",borderRadius:999,boxShadow:"0 4px 16px rgba(0, 0, 0, 0.22)",whiteSpace:"nowrap",maxWidth:jn-32,overflow:"hidden",textOverflow:"ellipsis",pointerEvents:"none",zIndex:5},children:pt}),ls.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6,borderRadius:14,padding:"10px 10px 8px 12px",background:"#ffffff",border:"1px solid #e5e7eb",boxShadow:"0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 14px -6px rgba(0, 0, 0, 0.08)"},children:[(ie.length>0||ce)&&ls.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:6,alignItems:"center"},children:[ie.map(a=>ls.jsxs("div",{onMouseEnter:()=>ur(a.id),onMouseLeave:()=>ur(null),style:{position:"relative",width:44,height:44,borderRadius:8,overflow:"hidden",border:"1px solid #e5e7eb",flexShrink:0},children:[ls.jsx("img",{src:a.dataUrl,alt:"attachment",style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}}),ls.jsx("button",{onClick:()=>be(T=>T.filter(B=>B.id!==a.id)),title:"Remove image",style:{position:"absolute",top:2,right:2,width:15,height:15,borderRadius:"50%",background:"rgba(17, 24, 39, 0.78)",color:"#ffffff",border:"none",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",padding:0,opacity:Ko===a.id?1:.6,transition:"opacity 0.12s"},children:ls.jsx(lucideReact.X,{style:{width:9,height:9}})})]},a.id)),ce&&ls.jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:5,background:"#eef2ff",border:"1px solid #c7d2fe",color:"#4338ca",borderRadius:999,padding:"4px 6px 4px 9px",fontSize:11,fontWeight:500,maxWidth:"100%",minWidth:0},children:[ls.jsx(lucideReact.MousePointer2,{style:{width:11,height:11,flexShrink:0}}),ls.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"ui-monospace, SFMono-Regular, Menlo, monospace"},children:an(ce)}),ls.jsx("button",{onClick:()=>me(null),title:"Remove element context",style:{width:14,height:14,borderRadius:"50%",background:"transparent",color:"#6366f1",border:"none",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",padding:0,flexShrink:0},children:ls.jsx(lucideReact.X,{style:{width:10,height:10}})})]})]}),ls.jsx("textarea",{ref:Z,value:m,onChange:a=>P(a.target.value),onPaste:a=>{let T=eo(a.nativeEvent);T.length>0&&(a.preventDefault(),vr(T));},onKeyDown:a=>{a.key==="Enter"&&!a.shiftKey&&(a.preventDefault(),xr()),a.key==="Escape"&&!S&&Cr();},placeholder:c?"Iterate on this feature...":"Start building a new Fork...",rows:1,style:{width:"100%",backgroundColor:"transparent",fontSize:13,color:"#111827",border:"none",outline:"none",padding:0,fontFamily:"inherit",resize:"none",lineHeight:1.5,maxHeight:160,overflow:"auto",boxSizing:"border-box"}}),ls.jsxs("div",{style:{display:"flex",alignItems:"center",gap:2},children:[ls.jsx("button",{onClick:()=>ir.current?.click(),onMouseEnter:()=>ar(true),onMouseLeave:()=>ar(false),title:"Attach an image",style:{width:28,height:28,borderRadius:8,display:"flex",alignItems:"center",justifyContent:"center",background:Bo?"rgba(0, 0, 0, 0.05)":"transparent",color:"#6b7280",border:"none",cursor:"pointer",padding:0,flexShrink:0,transition:"background 0.12s"},children:ls.jsx(lucideReact.ImagePlus,{style:{width:16,height:16}})}),ls.jsx("button",{onClick:es,onMouseEnter:()=>lr(true),onMouseLeave:()=>lr(false),title:ae?"Cancel element selection":"Select an element on the page",style:{width:28,height:28,borderRadius:8,display:"flex",alignItems:"center",justifyContent:"center",background:ae?"#eef2ff":Do?"rgba(0, 0, 0, 0.05)":"transparent",color:ae?"#4f46e5":"#6b7280",border:"none",cursor:"pointer",padding:0,flexShrink:0,transition:"background 0.12s, color 0.12s"},children:ls.jsx(lucideReact.MousePointer2,{style:{width:16,height:16}})}),ls.jsx("div",{style:{flex:1}}),ls.jsx("button",{onClick:ts,onMouseEnter:()=>cr(true),onMouseLeave:()=>cr(false),title:fe?"Stop voice input":"Voice input",style:{width:28,height:28,borderRadius:8,display:"flex",alignItems:"center",justifyContent:"center",background:fe?"#fef2f2":jo?"rgba(0, 0, 0, 0.05)":"transparent",color:fe?"#dc2626":"#6b7280",border:"none",cursor:"pointer",padding:0,flexShrink:0,transition:"background 0.12s, color 0.12s",animation:fe?"__fork-pulse 1.4s ease-in-out infinite":void 0},children:ls.jsx(lucideReact.Mic,{style:{width:16,height:16}})}),ls.jsx("button",{onClick:xr,disabled:!yt,onMouseEnter:()=>X(true),onMouseLeave:()=>X(false),title:"Send",style:{width:28,height:28,borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",color:"#ffffff",opacity:yt?1:.35,transform:W&&yt?"scale(1.08)":"scale(1)",background:yt?"#111827":"rgba(0, 0, 0, 0.12)",border:"none",cursor:yt?"pointer":"default",flexShrink:0,transition:"transform 0.15s, opacity 0.15s, background 0.15s",padding:0,marginLeft:4},children:ls.jsx(lucideReact.ArrowUp,{style:{width:14,height:14}})})]})]}),ls.jsx("input",{ref:ir,type:"file",accept:"image/*",multiple:true,style:{display:"none"},onChange:a=>{let T=Array.from(a.target.files??[]);a.target.value="",vr(T);}})]})]})]});return S?Fn:Oe&&Ie?as.createPortal(Fn,Ie.document.body):ls.jsx(Mi,{children:Fn})}function uo(e){if("target"in e&&e.target)return e.target;if("boundaryId"in e&&e.boundaryId)return {type:"boundary",id:e.boundaryId,title:e.title};if("slotId"in e&&e.slotId)return {type:"slot",id:e.slotId,title:e.title??e.slotLabel};throw new Error("Fork chat target requires either target, slotId, or boundaryId.")}function zn(e){let{apiKey:t,userId:n,userHash:r,baseUrl:o,appId:s,adminContext:i,refreshModuleManifest:l,queueBoundaryAnimation:u,trackForkActivity:h,recordForkActivityEvent:b}=ve(),[d,k]=Pn.useState({}),[R,v]=Pn.useState(null),[f,g]=Pn.useState("idle"),[S,I]=Pn.useState(false),[m,P]=Pn.useState(null),L=Pn.useRef(new Map),j=Pn.useCallback((C,M)=>{k(w=>{let $=w[C]??{forkId:C,state:"running",fork:M.fork,events:[],error:null};return {...w,[C]:{...$,...M}}});},[]),O=Pn.useCallback((C,M)=>{k(w=>{let p=w[C];return p?{...w,[C]:{...p,events:[...p.events,M]}}:w});},[]),N=Pn.useCallback(C=>{let M=L.current.get(C);M&&(M.close(),L.current.delete(C));},[]),oe=Pn.useCallback(()=>{g("prompting"),P(null),I(false),v(null);},[]),Y=Pn.useCallback(()=>{g("idle"),I(false),P(null),v(null);for(let C of L.current.values())C.close();L.current.clear(),k({});},[]),_=Pn.useCallback((C,M)=>{N(C.id);let w=new URLSearchParams({key:t});n&&w.set("userId",n),r&&w.set("userHash",r),i.isAdmin&&i.containerId&&w.set("containerId",i.containerId);let p=new EventSource(`${o}/api/v1/forks/${C.id}/events?${w.toString()}`);L.current.set(C.id,p),p.onmessage=$=>{try{let x=JSON.parse($.data);if(b(C.id,x),O(C.id,x),x.type==="complete"){let q=x.data;u(M,C.id),l().catch(()=>{}).finally(()=>{let re={...C,status:"complete",moduleUrl:q.moduleUrl,cssUrls:q.cssUrls,summary:q.summary,completedAt:new Date().toISOString()};j(C.id,{state:"complete",fork:re}),N(C.id);});}else if(x.type==="error"){let q=x.data;j(C.id,{state:"error",error:q.error||"Unknown error"}),N(C.id);}}catch{}},p.onerror=()=>{let $={Authorization:`Bearer ${t}`,...pe()};n&&($["X-Fork-User-Id"]=n),r&&($["X-Fork-User-Hash"]=r),fetch(`${o}/api/v1/forks/${C.id}`,{headers:$}).then(x=>x.json()).then(x=>{x.status==="complete"?(u(M,x.id),l().catch(()=>{}),j(C.id,{state:"complete",fork:x})):x.status==="error"?j(C.id,{state:"error",fork:x,error:x.error||"Fork generation failed"}):j(C.id,{fork:x});}).catch(()=>{j(C.id,{state:"error",error:"Connection lost"});}),N(C.id);};},[i.containerId,i.isAdmin,t,O,o,N,u,b,l,j,r,n]),F=Pn.useCallback(async(C,M,w)=>{try{if(!s)throw new Error("ForkProvider requires appId for module boundary prompts.");I(!0),P(null),v(null);let p;if(w?.forkId){let $={prompt:C};n&&($.userId=n),r&&($.userHash=r),w?.attachments?.length&&($.attachments=w.attachments),w?.selectedElement&&($.selectedElement=w.selectedElement);let x=await fetch(`${o}/api/v1/forks/${encodeURIComponent(w.forkId)}/prompts`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`,...pe()},body:JSON.stringify($)});if(!x.ok){let q=await x.json().catch(()=>({}));throw new Error(q.error||`API error: ${x.status}`)}p=await x.json();}else {let $={userId:n,prompt:C,boundaryId:e,appId:s};M?$.containerId=M:i.isAdmin&&i.containerId&&($.containerId=i.containerId),r&&($.userHash=r),w?.forceNew&&($.force_new=!0),w?.attachments?.length&&($.attachments=w.attachments),w?.selectedElement&&($.selectedElement=w.selectedElement);let x=await fetch(`${o}/api/v1/forks`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`,...pe()},body:JSON.stringify($)});if(!x.ok){let q=await x.json().catch(()=>({}));throw new Error(q.error||`API error: ${x.status}`)}p=await x.json();}k($=>({...$,[p.id]:{forkId:p.id,state:"running",fork:p,events:[],error:null}})),v(p.id),I(!1),h(p,{targetKind:"module",targetId:e}),_(p,p.boundaryId??e);}catch(p){P(p.message),I(false);}},[i.containerId,i.isAdmin,t,s,o,e,_,h,r,n]),H=Pn.useCallback(async C=>{try{let M={Authorization:`Bearer ${t}`,...pe()};n&&(M["X-Fork-User-Id"]=n),r&&(M["X-Fork-User-Hash"]=r);let w=await fetch(`${o}/api/v1/forks/${C}`,{headers:M});if(!w.ok)return;let p=await w.json(),$=p.boundaryId??e;if(h(p,{targetKind:"module",targetId:$}),p.status==="complete"){k(x=>({...x,[p.id]:{forkId:p.id,state:"complete",fork:p,events:[],error:null}})),v(p.id);return}if(p.status==="error"){k(x=>({...x,[p.id]:{forkId:p.id,state:"error",fork:p,events:[],error:p.error||"Fork generation failed"}})),v(p.id);return}if(p.status!=="pending"&&p.status!=="running"&&p.status!=="building")return;k(x=>({...x,[p.id]:{forkId:p.id,state:"running",fork:p,events:[],error:null}})),v(p.id),_(p,$);}catch{}},[t,o,e,_,h,r,n]),D=Pn.useCallback(async C=>{try{if(!s)throw new Error("ForkProvider requires appId for boundary undo.");let M={userId:n,boundaryId:e,appId:s};r&&(M.userHash=r),C&&(M.fork_id=C);let w=await fetch(`${o}/api/v1/forks/undo`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`},body:JSON.stringify(M)});if(!w.ok){let $=await w.json().catch(()=>({}));throw new Error($.error||`API error: ${w.status}`)}let p=await w.json();if(await l().catch(()=>{}),p.removed)k($=>{let x={};for(let[q,re]of Object.entries($))(re.fork.boundaryId??e)!==e&&(x[q]=re);return x}),v(null),g("prompting");else if(p.fork){let $=p.fork;j($.id,{state:"complete",fork:$}),v($.id);}return p}catch(M){throw P(M.message),M}},[t,s,o,e,l,j,r,n]),K=R?d[R]??null:null,V=S?"running":m?"error":K?K.state:f,W=K?.fork??null,X=K?.events??[],U=m??K?.error??null;return {state:V,fork:W,events:X,error:U,runs:d,open:oe,close:Y,startFork:F,undoFork:D,adoptRunningFork:H}}var Pi=0;function mo(e){let{state:t,fork:n,events:r,error:o,runs:s,open:i,close:l,startFork:u,undoFork:h,adoptRunningFork:b}=zn(e),[d,k]=Pn.useState(false),R=Pn.useRef(null),v=Pn.useRef(t),f=Pn.useCallback(()=>{R.current!==null&&(clearTimeout(R.current),R.current=null);},[]),g=Pn.useCallback(()=>{f(),k(true),i();},[f,i]),S=Pn.useCallback(()=>{f(),k(false),l();},[f,l]),I=Pn.useCallback(async P=>{f(),k(true),await b(P);},[b,f]),m=Object.values(s).filter(P=>P.state==="running").length;return Pn.useEffect(()=>{let P=v.current;v.current=t,t==="complete"&&P==="running"&&d&&m===0&&(f(),R.current=setTimeout(()=>{R.current=null,k(false),l();},Pi)),(t==="running"||t==="prompting")&&f();},[t,d,m,f,l]),Pn.useEffect(()=>f,[f]),{state:t,fork:n,events:r,error:o,runs:s,isOpen:d,open:g,close:S,submit:u,undo:h,adoptRunningFork:I}}function Wn(){let{apiKey:e,userId:t,userHash:n,baseUrl:r,adminContext:o,setSlotFork:s,clearSlotFork:i,skipAnimationForSlot:l,trackForkActivity:u,recordForkActivityEvent:h}=ve(),[b,d]=Pn.useState({}),[k,R]=Pn.useState(null),[v,f]=Pn.useState("idle"),[g,S]=Pn.useState(false),[I,m]=Pn.useState(null),P=Pn.useRef(new Map),L=Pn.useCallback((U,C)=>{d(M=>{let p=M[U]??{forkId:U,state:"running",fork:C.fork,events:[],error:null};return {...M,[U]:{...p,...C}}});},[]),j=Pn.useCallback((U,C)=>{d(M=>{let w=M[U];return w?{...M,[U]:{...w,events:[...w.events,C]}}:M});},[]),O=Pn.useCallback(U=>{let C=P.current.get(U);C&&(C.close(),P.current.delete(U));},[]),N=Pn.useCallback(()=>{f("prompting"),m(null),S(false),R(null);},[]),oe=Pn.useCallback(()=>{f("idle"),S(false),m(null),R(null);for(let U of P.current.values())U.close();P.current.clear(),d({});},[]),Y=Pn.useCallback((U,C)=>{O(U.id);let M=new URLSearchParams({key:e});t&&M.set("userId",t),n&&M.set("userHash",n),o.isAdmin&&o.containerId&&M.set("containerId",o.containerId);let w=new EventSource(`${r}/api/v1/forks/${U.id}/events?${M.toString()}`);P.current.set(U.id,w),w.onmessage=p=>{try{let $=JSON.parse(p.data);if(h(U.id,$),j(U.id,$),$.type==="complete"){let x=$.data,q={...U,status:"complete",bundleUrl:x.bundleUrl,summary:x.summary,revealPending:!0,completedAt:new Date().toISOString()};L(U.id,{state:"complete",fork:q});let re=C??U.slotId;re&&x.bundleUrl&&s(re,q),O(U.id);}else if($.type==="error"){let x=$.data;L(U.id,{state:"error",error:x.error||"Unknown error"}),O(U.id);}}catch{}},w.onerror=()=>{let p={Authorization:`Bearer ${e}`,...pe()};t&&(p["X-Fork-User-Id"]=t),n&&(p["X-Fork-User-Hash"]=n),fetch(`${r}/api/v1/forks/${U.id}`,{headers:p}).then($=>$.json()).then($=>{if($.status==="complete"){L(U.id,{state:"complete",fork:{...$,revealPending:true}});let x=C??$.slotId;x&&$.bundleUrl&&s(x,{...$,revealPending:true});}else $.status==="error"?L(U.id,{state:"error",fork:$,error:$.error||"Fork generation failed"}):L(U.id,{fork:$});}).catch(()=>{L(U.id,{state:"error",error:"Connection lost"});}),O(U.id);};},[o.containerId,o.isAdmin,e,j,r,O,h,s,L,n,t]),_=Pn.useCallback(async(U,C,M,w)=>{try{S(!0),m(null),R(null);let p;if(w?.forkId){let x={prompt:U};t&&(x.userId=t),n&&(x.userHash=n),w?.attachments?.length&&(x.attachments=w.attachments),w?.selectedElement&&(x.selectedElement=w.selectedElement);let q=await fetch(`${r}/api/v1/forks/${encodeURIComponent(w.forkId)}/prompts`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`,...pe()},body:JSON.stringify(x)});if(!q.ok){let re=await q.json().catch(()=>({}));throw new Error(re.error||`API error: ${q.status}`)}p=await q.json();}else {let x={userId:t,prompt:U};C&&(x.slotId=C),M?x.containerId=M:o.isAdmin&&o.containerId&&(x.containerId=o.containerId),n&&(x.userHash=n),w?.forceNew&&(x.force_new=!0),w?.attachments?.length&&(x.attachments=w.attachments),w?.selectedElement&&(x.selectedElement=w.selectedElement);let q=await fetch(`${r}/api/v1/forks`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`,...pe()},body:JSON.stringify(x)});if(!q.ok){let re=await q.json().catch(()=>({}));throw new Error(re.error||`API error: ${q.status}`)}p=await q.json();}d(x=>({...x,[p.id]:{forkId:p.id,state:"running",fork:p,events:[],error:null}})),R(p.id),S(!1);let $=C??p.slotId;$&&u(p,{targetKind:"slot",targetId:$}),Y(p,C);}catch(p){m(p.message),S(false);}},[o.containerId,o.isAdmin,e,r,Y,u,n,t]),F=Pn.useCallback(async U=>{try{let C={Authorization:`Bearer ${e}`,...pe()};t&&(C["X-Fork-User-Id"]=t),n&&(C["X-Fork-User-Hash"]=n);let M=await fetch(`${r}/api/v1/forks/${U}`,{headers:C});if(!M.ok)return;let w=await M.json();if(w.slotId&&u(w,{targetKind:"slot",targetId:w.slotId}),w.status==="complete"){d(p=>({...p,[w.id]:{forkId:w.id,state:"complete",fork:w,events:[],error:null}})),R(w.id);return}if(w.status==="error"){d(p=>({...p,[w.id]:{forkId:w.id,state:"error",fork:w,events:[],error:w.error||"Fork generation failed"}})),R(w.id);return}if(w.status!=="pending"&&w.status!=="running"&&w.status!=="building")return;d(p=>({...p,[w.id]:{forkId:w.id,state:"running",fork:w,events:[],error:null}})),R(w.id),Y(w,w.slotId);}catch{}},[e,r,Y,u,n,t]),H=Pn.useCallback(async U=>{try{let C={userId:t,slotId:U};n&&(C.userHash=n);let M=await fetch(`${r}/api/v1/forks/undo`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`},body:JSON.stringify(C)});if(!M.ok){let p=await M.json().catch(()=>({}));throw new Error(p.error||`API error: ${M.status}`)}let w=await M.json();if(l(U),w.removed)i(U),d(p=>{let $={};for(let[x,q]of Object.entries(p))q.fork.slotId!==U&&($[x]=q);return $}),R(null),f("prompting");else if(w.fork){s(U,w.fork);let p=w.fork;L(p.id,{state:"complete",fork:p});}return w}catch(C){throw m(C.message),C}},[e,t,n,r,i,s,l,L]),D=k?b[k]??null:null,K=g?"running":I?"error":D?D.state:v,V=D?.fork??null,W=D?.events??[],X=I??D?.error??null;return {state:K,fork:V,events:W,error:X,runs:b,open:N,close:oe,startFork:_,undoFork:H,adoptRunningFork:F}}var Hi=0;function yo(){let{state:e,fork:t,events:n,error:r,runs:o,open:s,close:i,startFork:l,undoFork:u,adoptRunningFork:h}=Wn(),[b,d]=Pn.useState(false),k=Pn.useRef(null),R=Pn.useRef(e),v=Pn.useCallback(()=>{k.current!==null&&(clearTimeout(k.current),k.current=null);},[]),f=Pn.useCallback(()=>{v(),d(true),s();},[v,s]),g=Pn.useCallback(()=>{v(),d(false),i();},[v,i]),S=Pn.useCallback(async m=>{v(),d(true),await h(m);},[h,v]),I=Object.values(o).filter(m=>m.state==="running").length;return Pn.useEffect(()=>{let m=R.current;R.current=e,e==="complete"&&m==="running"&&b&&I===0&&(v(),k.current=setTimeout(()=>{k.current=null,d(false),i();},Hi)),(e==="running"||e==="prompting")&&v();},[e,b,I,v,i]),Pn.useEffect(()=>v,[v]),{state:e,fork:t,events:n,error:r,runs:o,isOpen:b,open:f,close:g,submit:l,undo:u,adoptRunningFork:S}}var Oi=new Set(["pending","running","building"]);function Vn(e){let t=uo(e),n=yo(),r=mo(t.type==="boundary"?t.id:""),{baseUrl:o,apiKey:s,userId:i,userHash:l,appId:u,activitySummary:h,forkActivities:b}=ve(),d=t.type==="slot"?n:r,k=t.type==="slot"?"slot":"boundary",R=t.id,v=t.title,f=t.type==="slot"?"slot":"module",g=b.find(L=>L.targetKind===f&&L.targetId===t.id&&Oi.has(L.status)),S=b.find(L=>L.targetKind===f&&L.targetId===t.id&&L.status==="complete"&&L.unread),I=Pn.useCallback(()=>{let L=g??S;if(L){d.adoptRunningFork(L.id);return}d.open();},[d,g,S]),m=Pn.useCallback((L,j,O,N)=>t.type==="slot"?n.submit(L,j??t.id,O,N):r.submit(L,O,N),[r,n,t]),P=Pn.useCallback((L,j)=>t.type==="slot"?n.undo(L??t.id):r.undo(j),[r,n,t]);return {...d,open:I,target:t,targetId:R,targetLabel:v,historyMode:k,submit:m,undo:P,buttonProps:{onClick:I,hasNotification:h.unreadCompletedCount>0,activity:h},panelProps:{state:d.state,fork:d.fork,events:d.events,error:d.error,runs:d.runs,...t.type==="slot"?{slotId:R,targetLabel:v,historyMode:k}:{targetId:R,targetLabel:v,historyMode:k},onSubmit:m,onUndo:P,onClose:d.close,baseUrl:o,apiKey:s,userId:i,userHash:l,appId:u}}}function _t(e){let{embedded:t,completeVariant:n}=e,r=Vn(e);return t?ls.jsx(dn,{...r.panelProps,embedded:true,completeVariant:n}):r.isOpen?ls.jsx(dn,{...r.panelProps,completeVariant:n}):ls.jsx(Nn,{...r.buttonProps})}function Ni({boundaryId:e,title:t}){return ls.jsx(_t,{boundaryId:e,title:t})}function qn(e){let t=Array.from(e.children).filter(r=>r instanceof HTMLElement);return t.length===1?t[0]:getComputedStyle(e).display==="contents"?null:e}function ko(e){let t=e.getBoundingClientRect(),n=e.cloneNode(true);n.setAttribute("data-fork-clone-overlay","true"),n.style.position="fixed",n.style.top=`${t.top}px`,n.style.left=`${t.left}px`,n.style.width=`${t.width}px`,n.style.height=`${t.height}px`,n.style.flex="none",n.style.minHeight="auto",n.style.zIndex="9998",n.style.pointerEvents="none",n.style.overflow="hidden";let r=getComputedStyle(e).backgroundColor;n.style.backgroundColor=r&&r!=="rgba(0, 0, 0, 0)"&&r!=="transparent"?r:getComputedStyle(document.body).backgroundColor||"#ffffff",document.body.appendChild(n);let o=e.querySelectorAll("*"),s=n.querySelectorAll("*");for(let i=0;i<o.length;i+=1)o[i].scrollTop!==0&&(s[i].scrollTop=o[i].scrollTop),o[i].scrollLeft!==0&&(s[i].scrollLeft=o[i].scrollLeft);return n}function Gn(e){let t=[],n=e.querySelectorAll("*");for(let r of n){if(!(r instanceof HTMLElement))continue;let o=r.getBoundingClientRect();if(o.width<10||o.height<10||["SCRIPT","STYLE","META","LINK"].includes(r.tagName))continue;let s=getComputedStyle(r),i=parseFloat(s.borderTopLeftRadius)||0;t.push({tag:r.tagName,className:r.className||"",text:(r.textContent||"").slice(0,50).trim(),rect:o,borderRadius:i});}return t}function bo(e,t){let n=[];for(let r of t)if(!(e.find(i=>i.tag===r.tag&&i.className===r.className&&Math.abs(i.rect.top-r.rect.top)<20&&Math.abs(i.rect.left-r.rect.left)<20)||n.some(i=>r.rect.top>=i.rect.top&&r.rect.left>=i.rect.left&&r.rect.right<=i.rect.right&&r.rect.bottom<=i.rect.bottom))){for(let i=n.length-1;i>=0;i-=1){let l=n[i];l.rect.top>=r.rect.top&&l.rect.left>=r.rect.left&&l.rect.right<=r.rect.right&&l.rect.bottom<=r.rect.bottom&&n.splice(i,1);}n.push({rect:r.rect,borderRadius:r.borderRadius});}return n}function wo(e,t){let n=[];for(let r of e)if(!(t.find(i=>i.tag===r.tag&&i.className===r.className&&Math.abs(i.rect.top-r.rect.top)<20&&Math.abs(i.rect.left-r.rect.left)<20)||n.some(i=>r.rect.top>=i.rect.top&&r.rect.left>=i.rect.left&&r.rect.right<=i.rect.right&&r.rect.bottom<=i.rect.bottom))){for(let i=n.length-1;i>=0;i-=1){let l=n[i];l.rect.top>=r.rect.top&&l.rect.left>=r.rect.left&&l.rect.right<=r.rect.right&&l.rect.bottom<=r.rect.bottom&&n.splice(i,1);}n.push({rect:r.rect,borderRadius:r.borderRadius});}return n}function vo(e,t,n,r,o){let s=Math.max(0,Math.min(o,n/2,r/2));return s===0?`M ${e} ${t} L ${e+n} ${t} L ${e+n} ${t+r} L ${e} ${t+r} Z`:[`M ${e+s} ${t}`,`L ${e+n-s} ${t}`,`A ${s} ${s} 0 0 1 ${e+n} ${t+s}`,`L ${e+n} ${t+r-s}`,`A ${s} ${s} 0 0 1 ${e+n-s} ${t+r}`,`L ${e+s} ${t+r}`,`A ${s} ${s} 0 0 1 ${e} ${t+r-s}`,`L ${e} ${t+s}`,`A ${s} ${s} 0 0 1 ${e+s} ${t}`,"Z"].join(" ")}function Yn(e){let t="http://www.w3.org/2000/svg",n=document.createElement("div");n.setAttribute("data-fork-highlights","true"),n.style.cssText="position:fixed;top:0;left:0;width:100%;height:100%;pointer-events:none;z-index:9999;";let r=document.createElementNS(t,"svg");r.setAttribute("width","100%"),r.setAttribute("height","100%"),r.style.cssText="position:absolute;top:0;left:0;overflow:visible;";let o=document.createElementNS(t,"defs");r.appendChild(o);let s=[];for(let b=0;b<e.length;b+=1){let{rect:d,borderRadius:k}=e[b],R=d.left-.5,v=d.top-.5,f=d.width+1,g=d.height+1,S=Math.min(k+.5,f/2,g/2),I=vo(R,v,f,g,S),m=`__fork-glow-${b}`,P=document.createElementNS(t,"filter");P.setAttribute("id",m),P.setAttribute("x","-100%"),P.setAttribute("y","-100%"),P.setAttribute("width","300%"),P.setAttribute("height","300%");let L=document.createElementNS(t,"feGaussianBlur");L.setAttribute("in","SourceGraphic"),L.setAttribute("stdDeviation","8"),P.appendChild(L),o.appendChild(P);let j=`__fork-mask-${b}`,O=document.createElementNS(t,"mask");O.setAttribute("id",j),O.setAttribute("maskUnits","userSpaceOnUse"),O.setAttribute("x",String(R-200)),O.setAttribute("y",String(v-200)),O.setAttribute("width",String(f+400)),O.setAttribute("height",String(g+400));let N=document.createElementNS(t,"rect");N.setAttribute("x",String(R-200)),N.setAttribute("y",String(v-200)),N.setAttribute("width",String(f+400)),N.setAttribute("height",String(g+400)),N.setAttribute("fill","white"),O.appendChild(N);let oe=document.createElementNS(t,"path");oe.setAttribute("d",I),oe.setAttribute("fill","black"),O.appendChild(oe),o.appendChild(O);let Y=document.createElementNS(t,"g");Y.setAttribute("mask",`url(#${j})`),Y.setAttribute("opacity","0");let _=document.createElementNS(t,"g");_.setAttribute("filter",`url(#${m})`);let F=document.createElementNS(t,"path");F.setAttribute("d",I),F.setAttribute("fill","none"),F.setAttribute("stroke","rgba(150, 185, 220, 0.6)"),F.setAttribute("stroke-width","6"),F.setAttribute("stroke-linecap","round"),_.appendChild(F),Y.appendChild(_),r.appendChild(Y);let H=document.createElementNS(t,"path");H.setAttribute("d",I),H.setAttribute("fill","none"),H.setAttribute("stroke","rgba(150, 185, 220, 0.35)"),H.setAttribute("stroke-width","2"),H.setAttribute("stroke-linecap","round"),H.setAttribute("opacity","0"),r.appendChild(H),s.push(F,H),F.__group=Y;}n.appendChild(r),document.body.appendChild(n);let i=[];for(let b=0;b<s.length;b+=2){let d=s[b],k=s[b+1],R=d.__group;if(!R)continue;let v=k.getTotalLength(),f=d.getTotalLength();if(v<=0)continue;let g=v*.35;k.setAttribute("stroke-dasharray",`${g} ${v-g}`),k.setAttribute("stroke-dashoffset","0"),i.push(k.animate([{strokeDashoffset:0,opacity:0,offset:0},{strokeDashoffset:-0.2*v,opacity:.92,offset:.06},{strokeDashoffset:-2*v,opacity:.92,offset:.92},{strokeDashoffset:-2.25*v,opacity:0,offset:1}],{duration:14e3,easing:"ease-in-out",fill:"forwards"}));let S=f*.35;d.setAttribute("stroke-dasharray",`${S} ${f-S}`),d.setAttribute("stroke-dashoffset","0"),i.push(d.animate([{strokeDashoffset:0,offset:0},{strokeDashoffset:-0.2*f,offset:.06},{strokeDashoffset:-2*f,offset:.92},{strokeDashoffset:-2.25*f,offset:1}],{duration:14e3,easing:"ease-in-out",fill:"forwards"})),i.push(R.animate([{opacity:0,offset:0},{opacity:.92,offset:.06},{opacity:.92,offset:.92},{opacity:0,offset:1}],{duration:14e3,easing:"ease-in-out",fill:"forwards"}));}let l=false,u=()=>{if(l)return;l=true,clearTimeout(h);for(let d of i)try{d.cancel();}catch{}let b=n.animate([{opacity:1},{opacity:0}],{duration:400,fill:"forwards"});b.onfinish=()=>n.remove(),window.removeEventListener("click",u);},h=setTimeout(u,14500);return setTimeout(()=>{l||window.addEventListener("click",u);},500),u}function So(e){let t="http://www.w3.org/2000/svg",n=document.createElement("div");n.setAttribute("data-fork-removed","true"),n.style.cssText="position:fixed;top:0;left:0;width:100%;height:100%;pointer-events:none;z-index:9999;";let r=document.createElementNS(t,"svg");r.setAttribute("width","100%"),r.setAttribute("height","100%"),r.style.cssText="position:absolute;top:0;left:0;overflow:visible;";let o=document.createElementNS(t,"defs"),s=document.createElementNS(t,"filter");s.setAttribute("id","__fork-removed-shadow"),s.setAttribute("x","-10%"),s.setAttribute("y","-10%"),s.setAttribute("width","120%"),s.setAttribute("height","120%");let i=document.createElementNS(t,"feDropShadow");i.setAttribute("dx","0"),i.setAttribute("dy","1"),i.setAttribute("stdDeviation","2"),i.setAttribute("flood-color","rgba(0,0,0,0.15)"),s.appendChild(i),o.appendChild(s),r.appendChild(o);for(let{rect:l,borderRadius:u}of e){let h=document.createElementNS(t,"path");h.setAttribute("d",vo(l.left,l.top,l.width,l.height,u)),h.setAttribute("fill","none"),h.setAttribute("stroke","rgba(120, 125, 135, 0.6)"),h.setAttribute("stroke-width","1.5"),h.setAttribute("stroke-dasharray","8 4"),h.setAttribute("stroke-linecap","round"),h.setAttribute("filter","url(#__fork-removed-shadow)"),h.setAttribute("opacity","0"),r.appendChild(h),h.animate([{opacity:0,offset:0},{opacity:.6,offset:.08},{opacity:.05,offset:.45},{opacity:.6,offset:.85},{opacity:.05,offset:1}],{duration:5e3,easing:"ease-in-out",fill:"forwards"});}return n.appendChild(r),document.body.appendChild(n),n}function Ao(e,t){if(Bi(t.selector))return xo(e,t);let r=xo(e,t);if(r)return r;try{let s=document.querySelector(t.selector);if(s instanceof HTMLElement&&s!==e&&e.contains(s))return s}catch{}if(Fo(t.selector))try{let s=e.querySelector(t.selector);if(s instanceof HTMLElement&&s!==e)return s}catch{}if(t.textHint){let s=t.textHint.trim();if(s){let i=Qn(e,b=>b===s);if(i)return i;let l=s.toLowerCase(),u=Qn(e,b=>b.toLowerCase()===l);if(u)return u;let h=Qn(e,b=>b.toLowerCase().includes(l));if(h)return h}}let o=Di(t.selector);if(o&&o!==t.selector&&Fo(o))try{let s=e.querySelector(o);if(s instanceof HTMLElement&&s!==e)return s}catch{}return null}function Fo(e){let t=e.split(/\s+|>|~|\+/),n=t[t.length-1]??"";return /[#\[]|:not\(|:nth-/.test(n)}function xo(e,t){let n=Array.from(e.querySelectorAll("[data-fork-new]"));if(n.length===0)return null;let r=Zn(t.label),o=Zn(t.textHint);return n.find(i=>{let l=Zn(i.getAttribute("data-fork-new"));return !!l&&(l===r||l===o)})??null}function Bi(e){return e.trim()==="[data-fork-new]"}function Zn(e){return e?.trim().replace(/\s+/g," ").toLowerCase()||null}function Di(e){return e.replace(/\[class[\*~|^$]?=("[^"]*"|'[^']*'|[^\]]+)\]/g,"").replace(/\.[A-Za-z_][\w-]*/g,"").replace(/\s+/g," ").trim()}function Qn(e,t){let n=null,r=1/0,o=e.querySelectorAll("*");for(let s of o){let i=s.textContent?.trim();if(!i||!t(i))continue;let l=s.getBoundingClientRect();if(l.width<4||l.height<4)continue;let u=l.width*l.height;u<r&&(n=s,r=u);}return n}var er=2147483600,ji=1600,Ki=3e4,zi=300,Qe=10;function Wi(e){let n=getComputedStyle(e).borderTopLeftRadius;if(!n)return 4;if(n.endsWith("%")){let i=parseFloat(n);if(!Number.isFinite(i)||i<=0)return 4;let l=e.getBoundingClientRect(),u=Math.min(l.width,l.height);return Math.max(4,i/100*u)}let r=parseFloat(n);if(!Number.isFinite(r)||r<=0)return 4;let o=e.getBoundingClientRect(),s=Math.min(o.width,o.height)/2;return r>=s?s:Math.min(r,16)}function Ji(e,t,n,r){let s=window.innerWidth,i=window.innerHeight,l=e;l==="top"&&t.top<r+Qe+8?l="bottom":l==="bottom"&&i-t.bottom<r+Qe+8?l="top":l==="left"&&t.left<n+Qe+8?l="right":l==="right"&&s-t.right<n+Qe+8&&(l="left");let u=0,h=0;return l==="top"?(u=t.top-r-Qe,h=t.left+t.width/2-n/2):l==="bottom"?(u=t.bottom+Qe,h=t.left+t.width/2-n/2):l==="left"?(u=t.top+t.height/2-r/2,h=t.left-n-Qe):(u=t.top+t.height/2-r/2,h=t.right+Qe),h=Math.max(8,Math.min(h,s-n-8)),u=Math.max(8,Math.min(u,i-r-8)),{top:u,left:h,placement:l}}function Vi(e){let t=document.createElement("div");t.setAttribute("data-fork-highlight-outline","true"),t.style.cssText=["position:fixed","pointer-events:none",`z-index:${er}`,"border:1.5px solid rgba(59,130,246,0.85)","box-sizing:border-box","opacity:0","transition:opacity 200ms ease-out"].join(";");let n=document.createElement("div");n.setAttribute("data-fork-highlight-glow","true"),n.style.cssText=["position:fixed","pointer-events:none",`z-index:${er-1}`,"box-sizing:border-box","border:1px solid rgba(59,130,246,0.36)","box-shadow:0 0 0 4px rgba(59,130,246,0.16), 0 0 18px 2px rgba(59,130,246,0.31)","opacity:0","transition:opacity 200ms ease-out"].join(";");let r=document.createElement("div");return r.setAttribute("data-fork-highlight-tooltip","true"),r.style.cssText=["position:fixed","pointer-events:none",`z-index:${er+1}`,"padding:6px 10px","font:500 12px/1.2 -apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif","color:#ffffff","background:linear-gradient(135deg,#64748b,#475569)","border-radius:999px","box-shadow:0 4px 14px rgba(71,85,105,0.31),0 1px 2px rgba(0,0,0,0.1)","white-space:nowrap","opacity:0","transform:translateY(-2px)","transition:opacity 200ms ease-out, transform 200ms ease-out"].join(";"),r.textContent=`New: ${e}`,{outline:t,glow:n,tooltip:r}}function Xi(){if(document.getElementById("__fork-highlight-keyframes"))return;let e=document.createElement("style");e.id="__fork-highlight-keyframes",e.textContent=`
|
|
60
60
|
@keyframes __fork-highlight-pulse {
|
|
61
61
|
0%, 100% { box-shadow: 0 0 0 3px rgba(59,130,246,0.11), 0 0 12px 1px rgba(59,130,246,0.22); }
|
|
62
62
|
50% { box-shadow: 0 0 0 6px rgba(59,130,246,0.25), 0 0 22px 4px rgba(59,130,246,0.49); }
|
package/dist/index.js
CHANGED
|
@@ -56,7 +56,7 @@ import*as Pn from'react';import Pn__default,{createContext,useState,useRef,useEf
|
|
|
56
56
|
scrollbar-width: thin;
|
|
57
57
|
scrollbar-color: rgba(0, 0, 0, 0.12) transparent;
|
|
58
58
|
}
|
|
59
|
-
`}),jsxs("div",{className:"__fork-panel",style:rs,children:[jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"0 16px",height:54,boxSizing:"border-box",borderBottom:"1px solid rgba(229, 231, 235, 0.8)",flexShrink:0},children:[jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0,flex:1},children:[c||A?jsxs(Fragment,{children:[jsx("button",{onClick:()=>{y(null),z(false),Q.current=false;},style:{width:30,height:30,borderRadius:9,background:"#ffffff",border:"1px solid #e5e7eb",color:"#111827",cursor:"pointer",display:"inline-flex",alignItems:"center",justifyContent:"center",padding:0,flexShrink:0,transition:"background 0.12s, border-color 0.12s"},onMouseEnter:a=>{a.currentTarget.style.background="#f9fafb",a.currentTarget.style.borderColor="#d1d5db";},onMouseLeave:a=>{a.currentTarget.style.background="#ffffff",a.currentTarget.style.borderColor="#e5e7eb";},title:"Back to all forks",children:jsx(ChevronLeft,{style:{width:15,height:15}})}),(()=>{let a=c?o[c]:void 0,B=(a?a.events.find(G=>{let le=G.data;return G.type==="status"&&le.summary})?.data?.summary??a.fork.summary:void 0)||vn?.summary||"New Feature";return jsx("span",{style:{fontSize:13.5,fontWeight:700,color:"#111827",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",minWidth:0},title:B,children:B})})()]}):jsxs(Fragment,{children:[jsx("span",{onDoubleClick:async a=>{if(a.stopPropagation(),!re&&confirm("Kill all forks in this container?")){Ae(true);try{let T=await zo();`${T?.deleted??0}`,ft([]),y(null),z(!1),P("");}catch(T){console.error("[Fork] Reset failed:",T);}finally{Ae(false);}}},style:{display:"inline-flex",alignItems:"center",justifyContent:"center",padding:4,margin:-4,cursor:"pointer",flexShrink:0},children:jsx(nn,{style:{width:16,height:16,color:"#111827",pointerEvents:"none"}})}),De==="running"?jsx("span",{style:{fontSize:13,fontWeight:600,color:"#111827",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:Qo}):Te.length===0&&!Vt?jsx("span",{style:{fontSize:13,fontWeight:600,color:"#111827",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:"Fork"}):Vt?jsxs("div",{ref:Yt,style:{position:"relative",minWidth:0,display:"inline-flex"},children:[jsxs("button",{type:"button",onClick:()=>{ke(a=>!a);},onMouseEnter:()=>Bt(true),onMouseLeave:()=>Bt(false),"aria-haspopup":"menu","aria-expanded":$e,style:{display:"inline-flex",alignItems:"center",gap:4,padding:"3px 6px",border:"1px solid transparent",borderRadius:6,background:hn||$e?"#f3f4f6":"transparent",fontSize:13,fontWeight:600,color:"#111827",fontFamily:"inherit",cursor:"pointer",maxWidth:180,minWidth:0,transition:"background-color 0.12s"},children:[jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:Mr}),jsx(ChevronDown,{style:{width:12,height:12,color:"#6b7280",flexShrink:0,transform:$e?"rotate(180deg)":void 0,transition:"transform 0.15s"}})]}),$e&&jsxs("div",{role:"menu",style:{position:"absolute",top:"calc(100% + 4px)",left:0,minWidth:200,maxWidth:260,background:"#ffffff",border:"1px solid #e5e7eb",borderRadius:8,boxShadow:"0 4px 12px rgba(0,0,0,0.08), 0 1px 3px rgba(0,0,0,0.06)",padding:4,zIndex:2147483001},children:[Te.map(a=>{let T=a.id===Se,B=yn===a.id,G=ge===a.id;return jsxs("button",{type:"button",role:"menuitem",onMouseEnter:()=>Dt(a.id),onMouseLeave:()=>Dt(null),onClick:()=>{a.id!==Se&&ns(a.id);},disabled:!!ge,style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"6px 8px",border:"none",background:B?"#f3f4f6":"transparent",borderRadius:4,fontSize:13,fontFamily:"inherit",color:"#111827",cursor:ge?"default":"pointer",textAlign:"left",fontWeight:T?600:400,opacity:ge&&!G?.55:1},children:[jsx("span",{style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:14,height:14,color:"#111827",flexShrink:0},children:T&&jsx(Check,{style:{width:12,height:12}})}),jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:G?"Switching...":a.name})]},a.id)}),jsx("div",{style:{height:1,background:"#e5e7eb",margin:"4px 0"}}),bt?jsxs("div",{style:{display:"flex",alignItems:"center",gap:4,padding:"4px 4px"},children:[jsx("input",{ref:wt,type:"text",value:Be,placeholder:"Container name",disabled:ge==="__new__",onChange:a=>Xe(a.target.value),onKeyDown:a=>{a.key==="Enter"?(a.preventDefault(),Rr(Be)):a.key==="Escape"&&(a.preventDefault(),a.stopPropagation(),ut(false),Xe(""));},style:{flex:1,minWidth:0,padding:"5px 8px",border:"1px solid #d1d5db",borderRadius:4,fontSize:13,fontFamily:"inherit",color:"#111827",background:"#ffffff",outline:"none"},onFocus:a=>{a.currentTarget.style.borderColor="#111827",a.currentTarget.style.boxShadow="0 0 0 2px rgba(17,24,39,0.15)";},onBlur:a=>{a.currentTarget.style.borderColor="#d1d5db",a.currentTarget.style.boxShadow="none";}}),jsx("button",{type:"button",onClick:()=>{Rr(Be);},disabled:!Be.trim()||ge==="__new__",title:"Create",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:26,height:26,border:"none",borderRadius:4,background:!Be.trim()||ge==="__new__"?"#e5e7eb":"#111827",color:!Be.trim()||ge==="__new__"?"#9ca3af":"#ffffff",cursor:!Be.trim()||ge==="__new__"?"default":"pointer",flexShrink:0},children:ge==="__new__"?jsx("span",{style:{width:10,height:10,border:"1.5px solid currentColor",borderTopColor:"transparent",borderRadius:"50%",animation:"__fork-spin 0.7s linear infinite"}}):jsx(Check,{style:{width:12,height:12}})})]}):jsx("button",{type:"button",role:"menuitem",onMouseEnter:()=>jt(true),onMouseLeave:()=>jt(false),onClick:()=>{ge||(Fe(null),Xe(""),ut(true));},disabled:!!ge,style:{display:"flex",alignItems:"center",width:"100%",padding:"6px 8px",border:"none",background:tt?"#f3f4f6":"transparent",borderRadius:4,fontSize:13,fontFamily:"inherit",color:"#111827",cursor:ge?"default":"pointer",textAlign:"left",opacity:ge&&ge!=="__new__"?.55:1},children:"+ New container"}),Kt&&jsx("div",{style:{padding:"6px 8px",fontSize:11,lineHeight:1.35,color:"#b91c1c"},children:Kt})]})]}):jsx("span",{style:{fontSize:13,fontWeight:600,color:"#111827",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:Mr})]}),De==="running"&&jsx("span",{title:nt?`Estimated ~${nt} min`:"Estimating\u2026",style:{fontSize:10,fontWeight:600,color:nt?"#111827":"#9ca3af",backgroundColor:nt?"rgba(17, 24, 39, 0.08)":"rgba(156, 163, 175, 0.12)",padding:"1px 6px",borderRadius:999,flexShrink:0,fontVariantNumeric:"tabular-nums",animation:nt?void 0:"__fork-pulse 1.4s ease-in-out infinite",minWidth:28,textAlign:"center"},children:nt?`~${nt}m`:"~ m"})]}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:2,flexShrink:0},children:[Vo&&jsx("button",{type:"button",role:"switch","aria-checked":!mt,"aria-label":mt?"Turn Fork back on":"Turn Fork off",title:mt?"Fork is off \u2014 you're seeing the original app. Turn it back on. Only affects you.":"Turn Fork off to see the original app. Only affects you.",onClick:()=>{Jo(!mt);},onMouseEnter:()=>gr(true),onMouseLeave:()=>gr(false),style:{position:"relative",width:26,height:15,borderRadius:999,border:"none",padding:0,marginRight:6,flexShrink:0,cursor:"pointer",backgroundColor:mt?mr?"#9ca3af":"#d1d5db":mr?"#374151":"#111827",transition:"background-color 0.18s ease",outline:"none",boxSizing:"border-box"},children:jsx("span",{"aria-hidden":true,style:{position:"absolute",top:2,left:mt?2:13,width:11,height:11,borderRadius:"50%",backgroundColor:"#ffffff",boxShadow:"0 1px 2px rgba(15, 23, 42, 0.25)",transition:"left 0.18s cubic-bezier(0.16, 1, 0.3, 1)"}})}),!S&&jsxs(Fragment,{children:[yr&&jsx("button",{onClick:Oe?qo:Xo,onMouseEnter:()=>V(true),onMouseLeave:()=>V(false),title:Oe?"Redock to sidebar":"Pop out into window",style:{padding:6,borderRadius:6,color:K?"#4b5563":"#9ca3af",backgroundColor:K?"#f3f4f6":"transparent",border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",transition:"background-color 0.15s, color 0.15s"},children:Oe?jsx(PictureInPicture,{style:{width:16,height:16}}):jsx(PictureInPicture2,{style:{width:16,height:16}})}),jsx("button",{onClick:Cr,onMouseEnter:()=>D(true),onMouseLeave:()=>D(false),style:{padding:6,borderRadius:6,color:H?"#4b5563":"#9ca3af",backgroundColor:H?"#f3f4f6":"transparent",border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",transition:"background-color 0.15s, color 0.15s"},children:jsx(X,{style:{width:16,height:16}})})]})]})]}),jsxs("div",{ref:ne,style:{flex:1,overflowY:"auto",minHeight:0,display:"flex",flexDirection:"column"},children:[!c&&!A&&jsxs("div",{style:{display:"flex",flexDirection:"column"},children:[Ne.length===0&&jsx("div",{style:{padding:"24px 20px",textAlign:"center",fontSize:13,color:"#6b7280"},children:"No forks yet. Describe a feature below to start one."}),Ne.length>0&&jsx("div",{style:{display:"flex",flexDirection:"column"},children:Ne.map((a,T)=>{let B=o[a.id],le=(B?B.events.find(Ye=>{let ss=Ye.data;return Ye.type==="status"&&ss.summary})?.data?.summary??B.fork.summary:void 0)||a.summary||"Untitled fork",je=!!fr.find(Ye=>Ye.id===a.id)?.unread,Me=o[a.id]?.state??a.status,os=Me==="running"||Me==="building"||Me==="pending";return jsxs(Fragment$1,{children:[jsxs("button",{onClick:()=>{z(false),y(a.id);},style:{textAlign:"left",padding:"12px 16px",background:"transparent",border:"none",cursor:"pointer",display:"flex",alignItems:"flex-start",gap:8,width:"100%",transition:"background 0.12s",fontFamily:"inherit"},onMouseEnter:Ye=>{Ye.currentTarget.style.background="#fafafa";},onMouseLeave:Ye=>{Ye.currentTarget.style.background="transparent";},children:[je&&jsx("span",{"aria-label":"Not viewed yet",title:"Not viewed yet",style:{width:7,height:7,borderRadius:"50%",backgroundColor:"#111827",flexShrink:0,marginTop:5}}),jsxs("div",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:5,alignItems:"flex-start"},children:[jsx("span",{style:{fontSize:13.5,fontWeight:600,color:"#111827",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",maxWidth:"100%"},children:le}),jsx("span",{style:{fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, "Liberation Mono", "Courier New", monospace',fontSize:10,color:"#9ca3af",background:"#f8f9fa",borderRadius:5,padding:"1px 6px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",maxWidth:"100%",boxSizing:"border-box"},children:a.targetId})]}),os&&jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:5,background:"#fff7ed",border:"1px solid #fed7aa",color:"#c2410c",borderRadius:999,padding:"2px 9px",fontSize:11,fontWeight:600,flexShrink:0},children:[jsx("span",{style:{width:6,height:6,borderRadius:"50%",background:"#f59e0b",animation:"__fork-pulse 1.4s ease-in-out infinite"}}),"Running"]}),Me==="error"&&jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:5,background:"#fef2f2",border:"1px solid #fecaca",color:"#b91c1c",borderRadius:999,padding:"2px 9px",fontSize:11,fontWeight:600,flexShrink:0},children:"Failed"}),jsx("span",{style:{fontSize:11.5,color:"#9ca3af",flexShrink:0,marginTop:2},children:Kn(a.updatedAt)})]}),T<Ne.length-1&&jsx("div",{style:{height:1,background:"#f3f4f6",margin:"0 16px",flexShrink:0}})]},a.id)})})]}),c&&xt.length>0&&jsx("div",{style:{margin:"16px 16px 0 16px"},children:xt.map((a,T)=>jsx("div",{style:{marginBottom:T<xt.length-1?12:0},children:a.type==="user"?jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:jsxs("div",{style:{backgroundColor:"#f3f4f6",borderRadius:12,padding:"10px 14px",fontSize:13,color:"#374151",lineHeight:1.5,maxWidth:"85%"},children:[a.attachments&&a.attachments.length>0&&jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,marginBottom:6},children:a.attachments.map((B,G)=>jsx("img",{src:B.dataUrl,alt:"attachment",style:{maxWidth:150,maxHeight:110,borderRadius:8,border:"1px solid #e5e7eb",display:"block",objectFit:"cover"}},G))}),a.selectedElement&&jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:4,background:"#eef2ff",border:"1px solid #c7d2fe",color:"#4338ca",borderRadius:999,padding:"2px 8px",fontSize:10.5,fontWeight:500,marginBottom:5,marginRight:6,maxWidth:"100%"},children:[jsx(MousePointer2,{style:{width:10,height:10,flexShrink:0}}),jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"ui-monospace, SFMono-Regular, Menlo, monospace"},children:a.selectedElement.label})]}),a.text]})}):I==="item"&&T===xt.length-1?jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:12,padding:12,borderRadius:8,border:"1px solid #e4e4e7",background:"#ffffff"},children:[jsx("div",{style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:28,height:28,flexShrink:0,borderRadius:6,background:"#f4f4f5",color:"#0a0a0a"},children:jsx(BadgeCheck,{style:{width:16,height:16}})}),jsxs("div",{style:{display:"flex",flexDirection:"column",gap:2,flex:1,minWidth:0},children:[jsx("div",{style:{fontSize:13,fontWeight:500,color:"#0a0a0a",lineHeight:1.3},children:"Feature applied"}),jsx("div",{style:{fontSize:13,color:"#71717a",lineHeight:1.4},children:a.text})]}),b&&De!=="running"&&jsx("button",{onClick:B=>{B.stopPropagation(),Ir();},disabled:p,style:{padding:"4px 10px",fontSize:12,fontWeight:500,borderRadius:6,border:"1px solid #e4e4e7",background:"#ffffff",color:"#0a0a0a",cursor:p?"default":"pointer",opacity:p?.4:1,height:28,flexShrink:0},children:"Undo"})]}):jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:8,background:"#ffffff",border:"1px solid #e5e7eb",borderRadius:10,boxShadow:"0 1px 2px rgba(0, 0, 0, 0.03)",padding:"9px 12px",maxWidth:"90%",boxSizing:"border-box"},children:[jsx("span",{style:{width:7,height:7,borderRadius:"50%",background:"#94a3b8",flexShrink:0}}),jsx("span",{style:{fontSize:12.5,fontWeight:600,color:"#334155",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:a.text}),a.timestamp&&jsx("span",{style:{fontSize:11,color:"#9ca3af",flexShrink:0},children:Kn(a.timestamp)}),b&&T===xt.length-1&&De!=="running"&&jsxs("button",{onClick:B=>{B.stopPropagation(),Ir();},onMouseEnter:()=>q(T),onMouseLeave:()=>q(null),disabled:p,style:{position:"relative",padding:2,borderRadius:4,border:"none",background:x===T?"rgba(0,0,0,0.06)":"transparent",color:x===T?"#6b7280":"#d1d5db",cursor:p?"default":"pointer",display:"flex",alignItems:"center",justifyContent:"center",transition:"color 0.15s, background 0.15s",opacity:p?.4:1,flexShrink:0},children:[jsx(Undo2,{style:{width:12,height:12}}),x===T&&jsx("span",{style:{position:"absolute",bottom:"calc(100% + 4px)",right:0,fontSize:10,fontWeight:500,color:"#fff",background:"#374151",borderRadius:4,padding:"2px 6px",whiteSpace:"nowrap",pointerEvents:"none",lineHeight:"16px"},children:"Undo"})]})]})},T))}),De==="running"&&jsx("div",{style:{margin:"12px 16px 0 16px"},children:jsxs("div",{onClick:()=>w(!M),style:{background:"#ffffff",border:"1px solid #e5e7eb",borderRadius:10,boxShadow:"0 1px 2px rgba(0, 0, 0, 0.03)",overflow:"hidden",cursor:"pointer",transition:"all 0.3s cubic-bezier(0.22, 1, 0.36, 1)"},children:[jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"9px 12px"},children:[jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[jsx("span",{style:{width:7,height:7,borderRadius:"50%",background:"#f59e0b",flexShrink:0,animation:"__fork-pulse 1.4s ease-in-out infinite"}}),jsx(Ci,{events:ht},c??"__compose__")]}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flexShrink:0,marginLeft:8},children:[ht[0]?.timestamp&&jsx("span",{style:{fontSize:11,color:"#9ca3af"},children:Kn(ht[0].timestamp)}),jsx("div",{style:{color:"#9ca3af",transition:"transform 0.2s ease",transform:M?"rotate(180deg)":"rotate(0deg)",display:"flex"},children:jsx(ChevronDown,{style:{width:14,height:14}})})]})]}),jsx("div",{style:{maxHeight:M?320:0,opacity:M?1:0,transition:"max-height 0.35s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.25s ease",overflow:"hidden"},children:jsx("div",{style:{background:"#1a1a2e",borderTop:"1px solid #e5e7eb",maxHeight:320,overflowY:"auto"},children:jsx(Zr,{events:ht},c??"__compose__")})})]})}),De==="error"&&jsxs("div",{style:{padding:"20px 16px",textAlign:"center"},children:[jsx("div",{style:{width:36,height:36,backgroundColor:"#fef2f2",borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",margin:"0 auto 10px auto"},children:jsx(X,{style:{width:18,height:18,color:"#ef4444"}})}),jsx("p",{style:{fontSize:12,color:"#6b7280",marginBottom:10,maxWidth:260,margin:"0 auto 10px auto"},children:Yo??r}),jsxs("button",{onClick:()=>{let a=Sn?.prompt||qt.current;a&&h(a,vt);},onMouseEnter:()=>C(true),onMouseLeave:()=>C(false),style:{display:"inline-flex",alignItems:"center",gap:6,padding:"6px 12px",borderRadius:8,fontSize:12,fontWeight:500,color:"#111827",backgroundColor:U?"#e5e7eb":"#f3f4f6",border:"none",cursor:"pointer",transition:"background-color 0.15s",fontFamily:"inherit"},children:[jsx(RotateCcw,{style:{width:12,height:12}})," Try Again"]})]})]}),!(c?De==="running":A&&e==="running")&&jsxs("div",{style:{padding:"8px 12px 12px 12px",borderTop:"1px solid rgba(229, 231, 235, 0.6)",flexShrink:0,position:"relative"},children:[pt&&jsx("div",{style:{position:"absolute",top:-42,left:"50%",transform:"translateX(-50%)",background:"#111827",color:"#ffffff",fontSize:12,fontWeight:500,padding:"7px 14px",borderRadius:999,boxShadow:"0 4px 16px rgba(0, 0, 0, 0.22)",whiteSpace:"nowrap",maxWidth:jn-32,overflow:"hidden",textOverflow:"ellipsis",pointerEvents:"none",zIndex:5},children:pt}),jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6,borderRadius:14,padding:"10px 10px 8px 12px",background:"#ffffff",border:"1px solid #e5e7eb",boxShadow:"0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 14px -6px rgba(0, 0, 0, 0.08)"},children:[(ie.length>0||ce)&&jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:6,alignItems:"center"},children:[ie.map(a=>jsxs("div",{onMouseEnter:()=>ur(a.id),onMouseLeave:()=>ur(null),style:{position:"relative",width:44,height:44,borderRadius:8,overflow:"hidden",border:"1px solid #e5e7eb",flexShrink:0},children:[jsx("img",{src:a.dataUrl,alt:"attachment",style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}}),jsx("button",{onClick:()=>be(T=>T.filter(B=>B.id!==a.id)),title:"Remove image",style:{position:"absolute",top:2,right:2,width:15,height:15,borderRadius:"50%",background:"rgba(17, 24, 39, 0.78)",color:"#ffffff",border:"none",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",padding:0,opacity:Ko===a.id?1:.6,transition:"opacity 0.12s"},children:jsx(X,{style:{width:9,height:9}})})]},a.id)),ce&&jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:5,background:"#eef2ff",border:"1px solid #c7d2fe",color:"#4338ca",borderRadius:999,padding:"4px 6px 4px 9px",fontSize:11,fontWeight:500,maxWidth:"100%",minWidth:0},children:[jsx(MousePointer2,{style:{width:11,height:11,flexShrink:0}}),jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"ui-monospace, SFMono-Regular, Menlo, monospace"},children:an(ce)}),jsx("button",{onClick:()=>me(null),title:"Remove element context",style:{width:14,height:14,borderRadius:"50%",background:"transparent",color:"#6366f1",border:"none",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",padding:0,flexShrink:0},children:jsx(X,{style:{width:10,height:10}})})]})]}),jsx("textarea",{ref:Z,value:m,onChange:a=>P(a.target.value),onPaste:a=>{let T=eo(a.nativeEvent);T.length>0&&(a.preventDefault(),vr(T));},onKeyDown:a=>{a.key==="Enter"&&!a.shiftKey&&(a.preventDefault(),xr()),a.key==="Escape"&&!S&&Cr();},placeholder:c?"Iterate on this feature...":"Start building a new Fork...",rows:1,style:{width:"100%",backgroundColor:"transparent",fontSize:13,color:"#111827",border:"none",outline:"none",padding:0,fontFamily:"inherit",resize:"none",lineHeight:1.5,maxHeight:160,overflow:"auto",boxSizing:"border-box"}}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:2},children:[jsx("button",{onClick:()=>ir.current?.click(),onMouseEnter:()=>ar(true),onMouseLeave:()=>ar(false),title:"Attach an image",style:{width:28,height:28,borderRadius:8,display:"flex",alignItems:"center",justifyContent:"center",background:Bo?"rgba(0, 0, 0, 0.05)":"transparent",color:"#6b7280",border:"none",cursor:"pointer",padding:0,flexShrink:0,transition:"background 0.12s"},children:jsx(ImagePlus,{style:{width:16,height:16}})}),jsx("button",{onClick:es,onMouseEnter:()=>lr(true),onMouseLeave:()=>lr(false),title:ae?"Cancel element selection":"Select an element on the page",style:{width:28,height:28,borderRadius:8,display:"flex",alignItems:"center",justifyContent:"center",background:ae?"#eef2ff":Do?"rgba(0, 0, 0, 0.05)":"transparent",color:ae?"#4f46e5":"#6b7280",border:"none",cursor:"pointer",padding:0,flexShrink:0,transition:"background 0.12s, color 0.12s"},children:jsx(MousePointer2,{style:{width:16,height:16}})}),jsx("div",{style:{flex:1}}),jsx("button",{onClick:ts,onMouseEnter:()=>cr(true),onMouseLeave:()=>cr(false),title:fe?"Stop voice input":"Voice input",style:{width:28,height:28,borderRadius:8,display:"flex",alignItems:"center",justifyContent:"center",background:fe?"#fef2f2":jo?"rgba(0, 0, 0, 0.05)":"transparent",color:fe?"#dc2626":"#6b7280",border:"none",cursor:"pointer",padding:0,flexShrink:0,transition:"background 0.12s, color 0.12s",animation:fe?"__fork-pulse 1.4s ease-in-out infinite":void 0},children:jsx(Mic,{style:{width:16,height:16}})}),jsx("button",{onClick:xr,disabled:!yt,onMouseEnter:()=>X$1(true),onMouseLeave:()=>X$1(false),title:"Send",style:{width:28,height:28,borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",color:"#ffffff",opacity:yt?1:.35,transform:W&&yt?"scale(1.08)":"scale(1)",background:yt?"#111827":"rgba(0, 0, 0, 0.12)",border:"none",cursor:yt?"pointer":"default",flexShrink:0,transition:"transform 0.15s, opacity 0.15s, background 0.15s",padding:0,marginLeft:4},children:jsx(ArrowUp,{style:{width:14,height:14}})})]})]}),jsx("input",{ref:ir,type:"file",accept:"image/*",multiple:true,style:{display:"none"},onChange:a=>{let T=Array.from(a.target.files??[]);a.target.value="",vr(T);}})]})]})]});return S?Fn:Oe&&Ie?createPortal(Fn,Ie.document.body):jsx(Mi,{children:Fn})}function uo(e){if("target"in e&&e.target)return e.target;if("boundaryId"in e&&e.boundaryId)return {type:"boundary",id:e.boundaryId,title:e.title};if("slotId"in e&&e.slotId)return {type:"slot",id:e.slotId,title:e.title??e.slotLabel};throw new Error("Fork chat target requires either target, slotId, or boundaryId.")}function zn(e){let{apiKey:t,userId:n,userHash:r,baseUrl:o,appId:s,adminContext:i,refreshModuleManifest:l,queueBoundaryAnimation:u,trackForkActivity:h,recordForkActivityEvent:b}=ve(),[d,k]=useState({}),[R,v]=useState(null),[f,g]=useState("idle"),[S,I]=useState(false),[m,P]=useState(null),L=useRef(new Map),j=useCallback((C,M)=>{k(w=>{let $=w[C]??{forkId:C,state:"running",fork:M.fork,events:[],error:null};return {...w,[C]:{...$,...M}}});},[]),O=useCallback((C,M)=>{k(w=>{let p=w[C];return p?{...w,[C]:{...p,events:[...p.events,M]}}:w});},[]),N=useCallback(C=>{let M=L.current.get(C);M&&(M.close(),L.current.delete(C));},[]),oe=useCallback(()=>{g("prompting"),P(null),I(false),v(null);},[]),Y=useCallback(()=>{g("idle"),I(false),P(null),v(null);for(let C of L.current.values())C.close();L.current.clear(),k({});},[]),_=useCallback((C,M)=>{N(C.id);let w=new URLSearchParams({key:t});n&&w.set("userId",n),r&&w.set("userHash",r),i.isAdmin&&i.containerId&&w.set("containerId",i.containerId);let p=new EventSource(`${o}/api/v1/forks/${C.id}/events?${w.toString()}`);L.current.set(C.id,p),p.onmessage=$=>{try{let x=JSON.parse($.data);if(b(C.id,x),O(C.id,x),x.type==="complete"){let q=x.data;u(M,C.id),l().catch(()=>{}).finally(()=>{let re={...C,status:"complete",moduleUrl:q.moduleUrl,cssUrls:q.cssUrls,summary:q.summary,completedAt:new Date().toISOString()};j(C.id,{state:"complete",fork:re}),N(C.id);});}else if(x.type==="error"){let q=x.data;j(C.id,{state:"error",error:q.error||"Unknown error"}),N(C.id);}}catch{}},p.onerror=()=>{let $={Authorization:`Bearer ${t}`,...pe()};n&&($["X-Fork-User-Id"]=n),r&&($["X-Fork-User-Hash"]=r),fetch(`${o}/api/v1/forks/${C.id}`,{headers:$}).then(x=>x.json()).then(x=>{x.status==="complete"?(u(M,x.id),l().catch(()=>{}),j(C.id,{state:"complete",fork:x})):x.status==="error"?j(C.id,{state:"error",fork:x,error:x.error||"Fork generation failed"}):j(C.id,{fork:x});}).catch(()=>{j(C.id,{state:"error",error:"Connection lost"});}),N(C.id);};},[i.containerId,i.isAdmin,t,O,o,N,u,b,l,j,r,n]),F=useCallback(async(C,M,w)=>{try{if(!s)throw new Error("ForkProvider requires appId for module boundary prompts.");I(!0),P(null),v(null);let p;if(w?.forkId){let $={prompt:C};n&&($.userId=n),r&&($.userHash=r),w?.attachments?.length&&($.attachments=w.attachments),w?.selectedElement&&($.selectedElement=w.selectedElement);let x=await fetch(`${o}/api/v1/forks/${encodeURIComponent(w.forkId)}/prompts`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`,...pe()},body:JSON.stringify($)});if(!x.ok){let q=await x.json().catch(()=>({}));throw new Error(q.error||`API error: ${x.status}`)}p=await x.json();}else {let $={userId:n,prompt:C,boundaryId:e,appId:s};M?$.containerId=M:i.isAdmin&&i.containerId&&($.containerId=i.containerId),r&&($.userHash=r),w?.forceNew&&($.force_new=!0),w?.attachments?.length&&($.attachments=w.attachments),w?.selectedElement&&($.selectedElement=w.selectedElement);let x=await fetch(`${o}/api/v1/forks`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`,...pe()},body:JSON.stringify($)});if(!x.ok){let q=await x.json().catch(()=>({}));throw new Error(q.error||`API error: ${x.status}`)}p=await x.json();}k($=>({...$,[p.id]:{forkId:p.id,state:"running",fork:p,events:[],error:null}})),v(p.id),I(!1),h(p,{targetKind:"module",targetId:e}),_(p,p.boundaryId??e);}catch(p){P(p.message),I(false);}},[i.containerId,i.isAdmin,t,s,o,e,_,h,r,n]),H=useCallback(async C=>{try{let M={Authorization:`Bearer ${t}`,...pe()};n&&(M["X-Fork-User-Id"]=n),r&&(M["X-Fork-User-Hash"]=r);let w=await fetch(`${o}/api/v1/forks/${C}`,{headers:M});if(!w.ok)return;let p=await w.json(),$=p.boundaryId??e;if(h(p,{targetKind:"module",targetId:$}),p.status==="complete"){k(x=>({...x,[p.id]:{forkId:p.id,state:"complete",fork:p,events:[],error:null}})),v(p.id);return}if(p.status==="error"){k(x=>({...x,[p.id]:{forkId:p.id,state:"error",fork:p,events:[],error:p.error||"Fork generation failed"}})),v(p.id);return}if(p.status!=="pending"&&p.status!=="running"&&p.status!=="building")return;k(x=>({...x,[p.id]:{forkId:p.id,state:"running",fork:p,events:[],error:null}})),v(p.id),_(p,$);}catch{}},[t,o,e,_,h,r,n]),D=useCallback(async C=>{try{if(!s)throw new Error("ForkProvider requires appId for boundary undo.");let M={userId:n,boundaryId:e,appId:s};r&&(M.userHash=r),C&&(M.fork_id=C);let w=await fetch(`${o}/api/v1/forks/undo`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`},body:JSON.stringify(M)});if(!w.ok){let $=await w.json().catch(()=>({}));throw new Error($.error||`API error: ${w.status}`)}let p=await w.json();if(await l().catch(()=>{}),p.removed)k($=>{let x={};for(let[q,re]of Object.entries($))(re.fork.boundaryId??e)!==e&&(x[q]=re);return x}),v(null),g("prompting");else if(p.fork){let $=p.fork;j($.id,{state:"complete",fork:$}),v($.id);}return p}catch(M){throw P(M.message),M}},[t,s,o,e,l,j,r,n]),K=R?d[R]??null:null,V=S?"running":m?"error":K?K.state:f,W=K?.fork??null,X=K?.events??[],U=m??K?.error??null;return {state:V,fork:W,events:X,error:U,runs:d,open:oe,close:Y,startFork:F,undoFork:D,adoptRunningFork:H}}var Pi=0;function mo(e){let{state:t,fork:n,events:r,error:o,runs:s,open:i,close:l,startFork:u,undoFork:h,adoptRunningFork:b}=zn(e),[d,k]=useState(false),R=useRef(null),v=useRef(t),f=useCallback(()=>{R.current!==null&&(clearTimeout(R.current),R.current=null);},[]),g=useCallback(()=>{f(),k(true),i();},[f,i]),S=useCallback(()=>{f(),k(false),l();},[f,l]),I=useCallback(async P=>{f(),k(true),await b(P);},[b,f]),m=Object.values(s).filter(P=>P.state==="running").length;return useEffect(()=>{let P=v.current;v.current=t,t==="complete"&&P==="running"&&d&&m===0&&(f(),R.current=setTimeout(()=>{R.current=null,k(false),l();},Pi)),(t==="running"||t==="prompting")&&f();},[t,d,m,f,l]),useEffect(()=>f,[f]),{state:t,fork:n,events:r,error:o,runs:s,isOpen:d,open:g,close:S,submit:u,undo:h,adoptRunningFork:I}}function Wn(){let{apiKey:e,userId:t,userHash:n,baseUrl:r,adminContext:o,setSlotFork:s,clearSlotFork:i,skipAnimationForSlot:l,trackForkActivity:u,recordForkActivityEvent:h}=ve(),[b,d]=useState({}),[k,R]=useState(null),[v,f]=useState("idle"),[g,S]=useState(false),[I,m]=useState(null),P=useRef(new Map),L=useCallback((U,C)=>{d(M=>{let p=M[U]??{forkId:U,state:"running",fork:C.fork,events:[],error:null};return {...M,[U]:{...p,...C}}});},[]),j=useCallback((U,C)=>{d(M=>{let w=M[U];return w?{...M,[U]:{...w,events:[...w.events,C]}}:M});},[]),O=useCallback(U=>{let C=P.current.get(U);C&&(C.close(),P.current.delete(U));},[]),N=useCallback(()=>{f("prompting"),m(null),S(false),R(null);},[]),oe=useCallback(()=>{f("idle"),S(false),m(null),R(null);for(let U of P.current.values())U.close();P.current.clear(),d({});},[]),Y=useCallback((U,C)=>{O(U.id);let M=new URLSearchParams({key:e});t&&M.set("userId",t),n&&M.set("userHash",n),o.isAdmin&&o.containerId&&M.set("containerId",o.containerId);let w=new EventSource(`${r}/api/v1/forks/${U.id}/events?${M.toString()}`);P.current.set(U.id,w),w.onmessage=p=>{try{let $=JSON.parse(p.data);if(h(U.id,$),j(U.id,$),$.type==="complete"){let x=$.data,q={...U,status:"complete",bundleUrl:x.bundleUrl,summary:x.summary,revealPending:!0,completedAt:new Date().toISOString()};L(U.id,{state:"complete",fork:q});let re=C??U.slotId;re&&x.bundleUrl&&s(re,q),O(U.id);}else if($.type==="error"){let x=$.data;L(U.id,{state:"error",error:x.error||"Unknown error"}),O(U.id);}}catch{}},w.onerror=()=>{let p={Authorization:`Bearer ${e}`,...pe()};t&&(p["X-Fork-User-Id"]=t),n&&(p["X-Fork-User-Hash"]=n),fetch(`${r}/api/v1/forks/${U.id}`,{headers:p}).then($=>$.json()).then($=>{if($.status==="complete"){L(U.id,{state:"complete",fork:{...$,revealPending:true}});let x=C??$.slotId;x&&$.bundleUrl&&s(x,{...$,revealPending:true});}else $.status==="error"?L(U.id,{state:"error",fork:$,error:$.error||"Fork generation failed"}):L(U.id,{fork:$});}).catch(()=>{L(U.id,{state:"error",error:"Connection lost"});}),O(U.id);};},[o.containerId,o.isAdmin,e,j,r,O,h,s,L,n,t]),_=useCallback(async(U,C,M,w)=>{try{S(!0),m(null),R(null);let p;if(w?.forkId){let x={prompt:U};t&&(x.userId=t),n&&(x.userHash=n),w?.attachments?.length&&(x.attachments=w.attachments),w?.selectedElement&&(x.selectedElement=w.selectedElement);let q=await fetch(`${r}/api/v1/forks/${encodeURIComponent(w.forkId)}/prompts`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`,...pe()},body:JSON.stringify(x)});if(!q.ok){let re=await q.json().catch(()=>({}));throw new Error(re.error||`API error: ${q.status}`)}p=await q.json();}else {let x={userId:t,prompt:U};C&&(x.slotId=C),M?x.containerId=M:o.isAdmin&&o.containerId&&(x.containerId=o.containerId),n&&(x.userHash=n),w?.forceNew&&(x.force_new=!0),w?.attachments?.length&&(x.attachments=w.attachments),w?.selectedElement&&(x.selectedElement=w.selectedElement);let q=await fetch(`${r}/api/v1/forks`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`,...pe()},body:JSON.stringify(x)});if(!q.ok){let re=await q.json().catch(()=>({}));throw new Error(re.error||`API error: ${q.status}`)}p=await q.json();}d(x=>({...x,[p.id]:{forkId:p.id,state:"running",fork:p,events:[],error:null}})),R(p.id),S(!1);let $=C??p.slotId;$&&u(p,{targetKind:"slot",targetId:$}),Y(p,C);}catch(p){m(p.message),S(false);}},[o.containerId,o.isAdmin,e,r,Y,u,n,t]),F=useCallback(async U=>{try{let C={Authorization:`Bearer ${e}`,...pe()};t&&(C["X-Fork-User-Id"]=t),n&&(C["X-Fork-User-Hash"]=n);let M=await fetch(`${r}/api/v1/forks/${U}`,{headers:C});if(!M.ok)return;let w=await M.json();if(w.slotId&&u(w,{targetKind:"slot",targetId:w.slotId}),w.status==="complete"){d(p=>({...p,[w.id]:{forkId:w.id,state:"complete",fork:w,events:[],error:null}})),R(w.id);return}if(w.status==="error"){d(p=>({...p,[w.id]:{forkId:w.id,state:"error",fork:w,events:[],error:w.error||"Fork generation failed"}})),R(w.id);return}if(w.status!=="pending"&&w.status!=="running"&&w.status!=="building")return;d(p=>({...p,[w.id]:{forkId:w.id,state:"running",fork:w,events:[],error:null}})),R(w.id),Y(w,w.slotId);}catch{}},[e,r,Y,u,n,t]),H=useCallback(async U=>{try{let C={userId:t,slotId:U};n&&(C.userHash=n);let M=await fetch(`${r}/api/v1/forks/undo`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`},body:JSON.stringify(C)});if(!M.ok){let p=await M.json().catch(()=>({}));throw new Error(p.error||`API error: ${M.status}`)}let w=await M.json();if(l(U),w.removed)i(U),d(p=>{let $={};for(let[x,q]of Object.entries(p))q.fork.slotId!==U&&($[x]=q);return $}),R(null),f("prompting");else if(w.fork){s(U,w.fork);let p=w.fork;L(p.id,{state:"complete",fork:p});}return w}catch(C){throw m(C.message),C}},[e,t,n,r,i,s,l,L]),D=k?b[k]??null:null,K=g?"running":I?"error":D?D.state:v,V=D?.fork??null,W=D?.events??[],X=I??D?.error??null;return {state:K,fork:V,events:W,error:X,runs:b,open:N,close:oe,startFork:_,undoFork:H,adoptRunningFork:F}}var Hi=0;function yo(){let{state:e,fork:t,events:n,error:r,runs:o,open:s,close:i,startFork:l,undoFork:u,adoptRunningFork:h}=Wn(),[b,d]=useState(false),k=useRef(null),R=useRef(e),v=useCallback(()=>{k.current!==null&&(clearTimeout(k.current),k.current=null);},[]),f=useCallback(()=>{v(),d(true),s();},[v,s]),g=useCallback(()=>{v(),d(false),i();},[v,i]),S=useCallback(async m=>{v(),d(true),await h(m);},[h,v]),I=Object.values(o).filter(m=>m.state==="running").length;return useEffect(()=>{let m=R.current;R.current=e,e==="complete"&&m==="running"&&b&&I===0&&(v(),k.current=setTimeout(()=>{k.current=null,d(false),i();},Hi)),(e==="running"||e==="prompting")&&v();},[e,b,I,v,i]),useEffect(()=>v,[v]),{state:e,fork:t,events:n,error:r,runs:o,isOpen:b,open:f,close:g,submit:l,undo:u,adoptRunningFork:S}}var Oi=new Set(["pending","running","building"]);function Vn(e){let t=uo(e),n=yo(),r=mo(t.type==="boundary"?t.id:""),{baseUrl:o,apiKey:s,userId:i,userHash:l,appId:u,activitySummary:h,forkActivities:b}=ve(),d=t.type==="slot"?n:r,k=t.type==="slot"?"slot":"boundary",R=t.id,v=t.title,f=t.type==="slot"?"slot":"module",g=b.find(L=>L.targetKind===f&&L.targetId===t.id&&Oi.has(L.status)),S=b.find(L=>L.targetKind===f&&L.targetId===t.id&&L.status==="complete"&&L.unread),I=useCallback(()=>{let L=g??S;if(L){d.adoptRunningFork(L.id);return}d.open();},[d,g,S]),m=useCallback((L,j,O,N)=>t.type==="slot"?n.submit(L,j??t.id,O,N):r.submit(L,O,N),[r,n,t]),P=useCallback((L,j)=>t.type==="slot"?n.undo(L??t.id):r.undo(j),[r,n,t]);return {...d,open:I,target:t,targetId:R,targetLabel:v,historyMode:k,submit:m,undo:P,buttonProps:{onClick:I,hasNotification:h.unreadCompletedCount>0,activity:h},panelProps:{state:d.state,fork:d.fork,events:d.events,error:d.error,runs:d.runs,...t.type==="slot"?{slotId:R,targetLabel:v,historyMode:k}:{targetId:R,targetLabel:v,historyMode:k},onSubmit:m,onUndo:P,onClose:d.close,baseUrl:o,apiKey:s,userId:i,userHash:l,appId:u}}}function _t(e){let{embedded:t,completeVariant:n}=e,r=Vn(e);return t?jsx(dn,{...r.panelProps,embedded:true,completeVariant:n}):r.isOpen?jsx(dn,{...r.panelProps,completeVariant:n}):jsx(Nn,{...r.buttonProps})}function Ni({boundaryId:e,title:t}){return jsx(_t,{boundaryId:e,title:t})}function qn(e){let t=Array.from(e.children).filter(r=>r instanceof HTMLElement);return t.length===1?t[0]:getComputedStyle(e).display==="contents"?null:e}function ko(e){let t=e.getBoundingClientRect(),n=e.cloneNode(true);n.setAttribute("data-fork-clone-overlay","true"),n.style.position="fixed",n.style.top=`${t.top}px`,n.style.left=`${t.left}px`,n.style.width=`${t.width}px`,n.style.height=`${t.height}px`,n.style.flex="none",n.style.minHeight="auto",n.style.zIndex="9998",n.style.pointerEvents="none",n.style.overflow="hidden";let r=getComputedStyle(e).backgroundColor;n.style.backgroundColor=r&&r!=="rgba(0, 0, 0, 0)"&&r!=="transparent"?r:getComputedStyle(document.body).backgroundColor||"#ffffff",document.body.appendChild(n);let o=e.querySelectorAll("*"),s=n.querySelectorAll("*");for(let i=0;i<o.length;i+=1)o[i].scrollTop!==0&&(s[i].scrollTop=o[i].scrollTop),o[i].scrollLeft!==0&&(s[i].scrollLeft=o[i].scrollLeft);return n}function Gn(e){let t=[],n=e.querySelectorAll("*");for(let r of n){if(!(r instanceof HTMLElement))continue;let o=r.getBoundingClientRect();if(o.width<10||o.height<10||["SCRIPT","STYLE","META","LINK"].includes(r.tagName))continue;let s=getComputedStyle(r),i=parseFloat(s.borderTopLeftRadius)||0;t.push({tag:r.tagName,className:r.className||"",text:(r.textContent||"").slice(0,50).trim(),rect:o,borderRadius:i});}return t}function bo(e,t){let n=[];for(let r of t)if(!(e.find(i=>i.tag===r.tag&&i.className===r.className&&Math.abs(i.rect.top-r.rect.top)<20&&Math.abs(i.rect.left-r.rect.left)<20)||n.some(i=>r.rect.top>=i.rect.top&&r.rect.left>=i.rect.left&&r.rect.right<=i.rect.right&&r.rect.bottom<=i.rect.bottom))){for(let i=n.length-1;i>=0;i-=1){let l=n[i];l.rect.top>=r.rect.top&&l.rect.left>=r.rect.left&&l.rect.right<=r.rect.right&&l.rect.bottom<=r.rect.bottom&&n.splice(i,1);}n.push({rect:r.rect,borderRadius:r.borderRadius});}return n}function wo(e,t){let n=[];for(let r of e)if(!(t.find(i=>i.tag===r.tag&&i.className===r.className&&Math.abs(i.rect.top-r.rect.top)<20&&Math.abs(i.rect.left-r.rect.left)<20)||n.some(i=>r.rect.top>=i.rect.top&&r.rect.left>=i.rect.left&&r.rect.right<=i.rect.right&&r.rect.bottom<=i.rect.bottom))){for(let i=n.length-1;i>=0;i-=1){let l=n[i];l.rect.top>=r.rect.top&&l.rect.left>=r.rect.left&&l.rect.right<=r.rect.right&&l.rect.bottom<=r.rect.bottom&&n.splice(i,1);}n.push({rect:r.rect,borderRadius:r.borderRadius});}return n}function vo(e,t,n,r,o){let s=Math.max(0,Math.min(o,n/2,r/2));return s===0?`M ${e} ${t} L ${e+n} ${t} L ${e+n} ${t+r} L ${e} ${t+r} Z`:[`M ${e+s} ${t}`,`L ${e+n-s} ${t}`,`A ${s} ${s} 0 0 1 ${e+n} ${t+s}`,`L ${e+n} ${t+r-s}`,`A ${s} ${s} 0 0 1 ${e+n-s} ${t+r}`,`L ${e+s} ${t+r}`,`A ${s} ${s} 0 0 1 ${e} ${t+r-s}`,`L ${e} ${t+s}`,`A ${s} ${s} 0 0 1 ${e+s} ${t}`,"Z"].join(" ")}function Yn(e){let t="http://www.w3.org/2000/svg",n=document.createElement("div");n.setAttribute("data-fork-highlights","true"),n.style.cssText="position:fixed;top:0;left:0;width:100%;height:100%;pointer-events:none;z-index:9999;";let r=document.createElementNS(t,"svg");r.setAttribute("width","100%"),r.setAttribute("height","100%"),r.style.cssText="position:absolute;top:0;left:0;overflow:visible;";let o=document.createElementNS(t,"defs");r.appendChild(o);let s=[];for(let b=0;b<e.length;b+=1){let{rect:d,borderRadius:k}=e[b],R=d.left-.5,v=d.top-.5,f=d.width+1,g=d.height+1,S=Math.min(k+.5,f/2,g/2),I=vo(R,v,f,g,S),m=`__fork-glow-${b}`,P=document.createElementNS(t,"filter");P.setAttribute("id",m),P.setAttribute("x","-100%"),P.setAttribute("y","-100%"),P.setAttribute("width","300%"),P.setAttribute("height","300%");let L=document.createElementNS(t,"feGaussianBlur");L.setAttribute("in","SourceGraphic"),L.setAttribute("stdDeviation","8"),P.appendChild(L),o.appendChild(P);let j=`__fork-mask-${b}`,O=document.createElementNS(t,"mask");O.setAttribute("id",j),O.setAttribute("maskUnits","userSpaceOnUse"),O.setAttribute("x",String(R-200)),O.setAttribute("y",String(v-200)),O.setAttribute("width",String(f+400)),O.setAttribute("height",String(g+400));let N=document.createElementNS(t,"rect");N.setAttribute("x",String(R-200)),N.setAttribute("y",String(v-200)),N.setAttribute("width",String(f+400)),N.setAttribute("height",String(g+400)),N.setAttribute("fill","white"),O.appendChild(N);let oe=document.createElementNS(t,"path");oe.setAttribute("d",I),oe.setAttribute("fill","black"),O.appendChild(oe),o.appendChild(O);let Y=document.createElementNS(t,"g");Y.setAttribute("mask",`url(#${j})`),Y.setAttribute("opacity","0");let _=document.createElementNS(t,"g");_.setAttribute("filter",`url(#${m})`);let F=document.createElementNS(t,"path");F.setAttribute("d",I),F.setAttribute("fill","none"),F.setAttribute("stroke","rgba(150, 185, 220, 0.6)"),F.setAttribute("stroke-width","6"),F.setAttribute("stroke-linecap","round"),_.appendChild(F),Y.appendChild(_),r.appendChild(Y);let H=document.createElementNS(t,"path");H.setAttribute("d",I),H.setAttribute("fill","none"),H.setAttribute("stroke","rgba(150, 185, 220, 0.35)"),H.setAttribute("stroke-width","2"),H.setAttribute("stroke-linecap","round"),H.setAttribute("opacity","0"),r.appendChild(H),s.push(F,H),F.__group=Y;}n.appendChild(r),document.body.appendChild(n);let i=[];for(let b=0;b<s.length;b+=2){let d=s[b],k=s[b+1],R=d.__group;if(!R)continue;let v=k.getTotalLength(),f=d.getTotalLength();if(v<=0)continue;let g=v*.35;k.setAttribute("stroke-dasharray",`${g} ${v-g}`),k.setAttribute("stroke-dashoffset","0"),i.push(k.animate([{strokeDashoffset:0,opacity:0,offset:0},{strokeDashoffset:-0.2*v,opacity:.92,offset:.06},{strokeDashoffset:-2*v,opacity:.92,offset:.92},{strokeDashoffset:-2.25*v,opacity:0,offset:1}],{duration:14e3,easing:"ease-in-out",fill:"forwards"}));let S=f*.35;d.setAttribute("stroke-dasharray",`${S} ${f-S}`),d.setAttribute("stroke-dashoffset","0"),i.push(d.animate([{strokeDashoffset:0,offset:0},{strokeDashoffset:-0.2*f,offset:.06},{strokeDashoffset:-2*f,offset:.92},{strokeDashoffset:-2.25*f,offset:1}],{duration:14e3,easing:"ease-in-out",fill:"forwards"})),i.push(R.animate([{opacity:0,offset:0},{opacity:.92,offset:.06},{opacity:.92,offset:.92},{opacity:0,offset:1}],{duration:14e3,easing:"ease-in-out",fill:"forwards"}));}let l=false,u=()=>{if(l)return;l=true,clearTimeout(h);for(let d of i)try{d.cancel();}catch{}let b=n.animate([{opacity:1},{opacity:0}],{duration:400,fill:"forwards"});b.onfinish=()=>n.remove(),window.removeEventListener("click",u);},h=setTimeout(u,14500);return setTimeout(()=>{l||window.addEventListener("click",u);},500),u}function So(e){let t="http://www.w3.org/2000/svg",n=document.createElement("div");n.setAttribute("data-fork-removed","true"),n.style.cssText="position:fixed;top:0;left:0;width:100%;height:100%;pointer-events:none;z-index:9999;";let r=document.createElementNS(t,"svg");r.setAttribute("width","100%"),r.setAttribute("height","100%"),r.style.cssText="position:absolute;top:0;left:0;overflow:visible;";let o=document.createElementNS(t,"defs"),s=document.createElementNS(t,"filter");s.setAttribute("id","__fork-removed-shadow"),s.setAttribute("x","-10%"),s.setAttribute("y","-10%"),s.setAttribute("width","120%"),s.setAttribute("height","120%");let i=document.createElementNS(t,"feDropShadow");i.setAttribute("dx","0"),i.setAttribute("dy","1"),i.setAttribute("stdDeviation","2"),i.setAttribute("flood-color","rgba(0,0,0,0.15)"),s.appendChild(i),o.appendChild(s),r.appendChild(o);for(let{rect:l,borderRadius:u}of e){let h=document.createElementNS(t,"path");h.setAttribute("d",vo(l.left,l.top,l.width,l.height,u)),h.setAttribute("fill","none"),h.setAttribute("stroke","rgba(120, 125, 135, 0.6)"),h.setAttribute("stroke-width","1.5"),h.setAttribute("stroke-dasharray","8 4"),h.setAttribute("stroke-linecap","round"),h.setAttribute("filter","url(#__fork-removed-shadow)"),h.setAttribute("opacity","0"),r.appendChild(h),h.animate([{opacity:0,offset:0},{opacity:.6,offset:.08},{opacity:.05,offset:.45},{opacity:.6,offset:.85},{opacity:.05,offset:1}],{duration:5e3,easing:"ease-in-out",fill:"forwards"});}return n.appendChild(r),document.body.appendChild(n),n}function Ao(e,t){if(Bi(t.selector))return xo(e,t);let r=xo(e,t);if(r)return r;try{let s=document.querySelector(t.selector);if(s instanceof HTMLElement&&s!==e&&e.contains(s))return s}catch{}if(Fo(t.selector))try{let s=e.querySelector(t.selector);if(s instanceof HTMLElement&&s!==e)return s}catch{}if(t.textHint){let s=t.textHint.trim();if(s){let i=Qn(e,b=>b===s);if(i)return i;let l=s.toLowerCase(),u=Qn(e,b=>b.toLowerCase()===l);if(u)return u;let h=Qn(e,b=>b.toLowerCase().includes(l));if(h)return h}}let o=Di(t.selector);if(o&&o!==t.selector&&Fo(o))try{let s=e.querySelector(o);if(s instanceof HTMLElement&&s!==e)return s}catch{}return null}function Fo(e){let t=e.split(/\s+|>|~|\+/),n=t[t.length-1]??"";return /[#\[]|:not\(|:nth-/.test(n)}function xo(e,t){let n=Array.from(e.querySelectorAll("[data-fork-new]"));if(n.length===0)return null;let r=Zn(t.label),o=Zn(t.textHint);return n.find(i=>{let l=Zn(i.getAttribute("data-fork-new"));return !!l&&(l===r||l===o)})??null}function Bi(e){return e.trim()==="[data-fork-new]"}function Zn(e){return e?.trim().replace(/\s+/g," ").toLowerCase()||null}function Di(e){return e.replace(/\[class[\*~|^$]?=("[^"]*"|'[^']*'|[^\]]+)\]/g,"").replace(/\.[A-Za-z_][\w-]*/g,"").replace(/\s+/g," ").trim()}function Qn(e,t){let n=null,r=1/0,o=e.querySelectorAll("*");for(let s of o){let i=s.textContent?.trim();if(!i||!t(i))continue;let l=s.getBoundingClientRect();if(l.width<4||l.height<4)continue;let u=l.width*l.height;u<r&&(n=s,r=u);}return n}var er=2147483600,ji=1600,Ki=3e4,zi=300,Qe=10;function Wi(e){let n=getComputedStyle(e).borderTopLeftRadius;if(!n)return 4;if(n.endsWith("%")){let i=parseFloat(n);if(!Number.isFinite(i)||i<=0)return 4;let l=e.getBoundingClientRect(),u=Math.min(l.width,l.height);return Math.max(4,i/100*u)}let r=parseFloat(n);if(!Number.isFinite(r)||r<=0)return 4;let o=e.getBoundingClientRect(),s=Math.min(o.width,o.height)/2;return r>=s?s:Math.min(r,16)}function Ji(e,t,n,r){let s=window.innerWidth,i=window.innerHeight,l=e;l==="top"&&t.top<r+Qe+8?l="bottom":l==="bottom"&&i-t.bottom<r+Qe+8?l="top":l==="left"&&t.left<n+Qe+8?l="right":l==="right"&&s-t.right<n+Qe+8&&(l="left");let u=0,h=0;return l==="top"?(u=t.top-r-Qe,h=t.left+t.width/2-n/2):l==="bottom"?(u=t.bottom+Qe,h=t.left+t.width/2-n/2):l==="left"?(u=t.top+t.height/2-r/2,h=t.left-n-Qe):(u=t.top+t.height/2-r/2,h=t.right+Qe),h=Math.max(8,Math.min(h,s-n-8)),u=Math.max(8,Math.min(u,i-r-8)),{top:u,left:h,placement:l}}function Vi(e){let t=document.createElement("div");t.setAttribute("data-fork-highlight-outline","true"),t.style.cssText=["position:fixed","pointer-events:none",`z-index:${er}`,"border:1.5px solid rgba(59,130,246,0.85)","box-sizing:border-box","opacity:0","transition:opacity 200ms ease-out"].join(";");let n=document.createElement("div");n.setAttribute("data-fork-highlight-glow","true"),n.style.cssText=["position:fixed","pointer-events:none",`z-index:${er-1}`,"box-sizing:border-box","border:1px solid rgba(59,130,246,0.36)","box-shadow:0 0 0 4px rgba(59,130,246,0.16), 0 0 18px 2px rgba(59,130,246,0.31)","opacity:0","transition:opacity 200ms ease-out"].join(";");let r=document.createElement("div");return r.setAttribute("data-fork-highlight-tooltip","true"),r.style.cssText=["position:fixed","pointer-events:none",`z-index:${er+1}`,"padding:6px 10px","font:500 12px/1.2 -apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif","color:#ffffff","background:linear-gradient(135deg,#64748b,#475569)","border-radius:999px","box-shadow:0 4px 14px rgba(71,85,105,0.31),0 1px 2px rgba(0,0,0,0.1)","white-space:nowrap","opacity:0","transform:translateY(-2px)","transition:opacity 200ms ease-out, transform 200ms ease-out"].join(";"),r.textContent=`New: ${e}`,{outline:t,glow:n,tooltip:r}}function Xi(){if(document.getElementById("__fork-highlight-keyframes"))return;let e=document.createElement("style");e.id="__fork-highlight-keyframes",e.textContent=`
|
|
59
|
+
`}),jsxs("div",{className:"__fork-panel",style:rs,children:[jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"0 16px",height:54,boxSizing:"border-box",borderBottom:"1px solid rgba(229, 231, 235, 0.8)",flexShrink:0},children:[jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0,flex:1},children:[c||A?jsxs(Fragment,{children:[jsx("button",{onClick:()=>{y(null),z(false),Q.current=false;},style:{width:30,height:30,borderRadius:9,background:"#ffffff",border:"1px solid #e5e7eb",color:"#111827",cursor:"pointer",display:"inline-flex",alignItems:"center",justifyContent:"center",padding:0,flexShrink:0,transition:"background 0.12s, border-color 0.12s"},onMouseEnter:a=>{a.currentTarget.style.background="#f9fafb",a.currentTarget.style.borderColor="#d1d5db";},onMouseLeave:a=>{a.currentTarget.style.background="#ffffff",a.currentTarget.style.borderColor="#e5e7eb";},title:"Back to all forks",children:jsx(ChevronLeft,{style:{width:15,height:15}})}),(()=>{let a=c?o[c]:void 0,B=(a?a.events.find(G=>{let le=G.data;return G.type==="status"&&le.summary})?.data?.summary??a.fork.summary:void 0)||vn?.summary||"New Feature";return jsx("span",{style:{fontSize:13.5,fontWeight:700,color:"#111827",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",minWidth:0},title:B,children:B})})()]}):jsxs(Fragment,{children:[jsx("span",{onDoubleClick:async a=>{if(a.stopPropagation(),!re&&confirm("Kill all forks in this container?")){Ae(true);try{let T=await zo();`${T?.deleted??0}`,ft([]),y(null),z(!1),P("");}catch(T){console.error("[Fork] Reset failed:",T);}finally{Ae(false);}}},style:{display:"inline-flex",alignItems:"center",justifyContent:"center",padding:4,margin:-4,cursor:"pointer",flexShrink:0},children:jsx(nn,{style:{width:16,height:16,color:"#111827",pointerEvents:"none"}})}),De==="running"?jsx("span",{style:{fontSize:13,fontWeight:600,color:"#111827",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:Qo}):Te.length===0&&!Vt?jsx("span",{style:{fontSize:13,fontWeight:600,color:"#111827",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:"Fork"}):Vt?jsxs("div",{ref:Yt,style:{position:"relative",minWidth:0,display:"inline-flex"},children:[jsxs("button",{type:"button",onClick:()=>{ke(a=>!a);},onMouseEnter:()=>Bt(true),onMouseLeave:()=>Bt(false),"aria-haspopup":"menu","aria-expanded":$e,style:{display:"inline-flex",alignItems:"center",gap:4,padding:"3px 6px",border:"1px solid transparent",borderRadius:6,background:hn||$e?"#f3f4f6":"transparent",fontSize:13,fontWeight:600,color:"#111827",fontFamily:"inherit",cursor:"pointer",maxWidth:180,minWidth:0,transition:"background-color 0.12s"},children:[jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:Mr}),jsx(ChevronDown,{style:{width:12,height:12,color:"#6b7280",flexShrink:0,transform:$e?"rotate(180deg)":void 0,transition:"transform 0.15s"}})]}),$e&&jsxs("div",{role:"menu",style:{position:"absolute",top:"calc(100% + 4px)",left:0,minWidth:200,maxWidth:260,background:"#ffffff",border:"1px solid #e5e7eb",borderRadius:8,boxShadow:"0 4px 12px rgba(0,0,0,0.08), 0 1px 3px rgba(0,0,0,0.06)",padding:4,zIndex:2147483001},children:[Te.map(a=>{let T=a.id===Se,B=yn===a.id,G=ge===a.id;return jsxs("button",{type:"button",role:"menuitem",onMouseEnter:()=>Dt(a.id),onMouseLeave:()=>Dt(null),onClick:()=>{a.id!==Se&&ns(a.id);},disabled:!!ge,style:{display:"flex",alignItems:"center",gap:8,width:"100%",padding:"6px 8px",border:"none",background:B?"#f3f4f6":"transparent",borderRadius:4,fontSize:13,fontFamily:"inherit",color:"#111827",cursor:ge?"default":"pointer",textAlign:"left",fontWeight:T?600:400,opacity:ge&&!G?.55:1},children:[jsx("span",{style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:14,height:14,color:"#111827",flexShrink:0},children:T&&jsx(Check,{style:{width:12,height:12}})}),jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:G?"Switching...":a.name})]},a.id)}),jsx("div",{style:{height:1,background:"#e5e7eb",margin:"4px 0"}}),bt?jsxs("div",{style:{display:"flex",alignItems:"center",gap:4,padding:"4px 4px"},children:[jsx("input",{ref:wt,type:"text",value:Be,placeholder:"Container name",disabled:ge==="__new__",onChange:a=>Xe(a.target.value),onKeyDown:a=>{a.key==="Enter"?(a.preventDefault(),Rr(Be)):a.key==="Escape"&&(a.preventDefault(),a.stopPropagation(),ut(false),Xe(""));},style:{flex:1,minWidth:0,padding:"5px 8px",border:"1px solid #d1d5db",borderRadius:4,fontSize:13,fontFamily:"inherit",color:"#111827",background:"#ffffff",outline:"none"},onFocus:a=>{a.currentTarget.style.borderColor="#111827",a.currentTarget.style.boxShadow="0 0 0 2px rgba(17,24,39,0.15)";},onBlur:a=>{a.currentTarget.style.borderColor="#d1d5db",a.currentTarget.style.boxShadow="none";}}),jsx("button",{type:"button",onClick:()=>{Rr(Be);},disabled:!Be.trim()||ge==="__new__",title:"Create",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:26,height:26,border:"none",borderRadius:4,background:!Be.trim()||ge==="__new__"?"#e5e7eb":"#111827",color:!Be.trim()||ge==="__new__"?"#9ca3af":"#ffffff",cursor:!Be.trim()||ge==="__new__"?"default":"pointer",flexShrink:0},children:ge==="__new__"?jsx("span",{style:{width:10,height:10,border:"1.5px solid currentColor",borderTopColor:"transparent",borderRadius:"50%",animation:"__fork-spin 0.7s linear infinite"}}):jsx(Check,{style:{width:12,height:12}})})]}):jsx("button",{type:"button",role:"menuitem",onMouseEnter:()=>jt(true),onMouseLeave:()=>jt(false),onClick:()=>{ge||(Fe(null),Xe(""),ut(true));},disabled:!!ge,style:{display:"flex",alignItems:"center",width:"100%",padding:"6px 8px",border:"none",background:tt?"#f3f4f6":"transparent",borderRadius:4,fontSize:13,fontFamily:"inherit",color:"#111827",cursor:ge?"default":"pointer",textAlign:"left",opacity:ge&&ge!=="__new__"?.55:1},children:"+ New container"}),Kt&&jsx("div",{style:{padding:"6px 8px",fontSize:11,lineHeight:1.35,color:"#b91c1c"},children:Kt})]})]}):jsx("span",{style:{fontSize:13,fontWeight:600,color:"#111827",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:Mr})]}),De==="running"&&jsx("span",{title:nt?`Estimated ~${nt} min`:"Estimating\u2026",style:{fontSize:10,fontWeight:600,color:nt?"#111827":"#9ca3af",backgroundColor:nt?"rgba(17, 24, 39, 0.08)":"rgba(156, 163, 175, 0.12)",padding:"1px 6px",borderRadius:999,flexShrink:0,fontVariantNumeric:"tabular-nums",animation:nt?void 0:"__fork-pulse 1.4s ease-in-out infinite",minWidth:28,textAlign:"center"},children:nt?`~${nt}m`:"~ m"})]}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:2,flexShrink:0},children:[Vo&&jsx("button",{type:"button",role:"switch","aria-checked":!mt,"aria-label":mt?"Turn Fork back on":"Turn Fork off",title:mt?"Fork is off \u2014 you're seeing the original app. Turn it back on. Only affects you.":"Turn Fork off to see the original app. Only affects you.",onClick:()=>{Jo(!mt);},onMouseEnter:()=>gr(true),onMouseLeave:()=>gr(false),style:{position:"relative",width:26,height:15,borderRadius:999,border:"none",padding:0,marginRight:6,flexShrink:0,cursor:"pointer",backgroundColor:mt?mr?"#9ca3af":"#d1d5db":mr?"#374151":"#111827",transition:"background-color 0.18s ease",outline:"none",boxSizing:"border-box"},children:jsx("span",{"aria-hidden":true,style:{position:"absolute",top:2,left:mt?2:13,width:11,height:11,borderRadius:"50%",backgroundColor:"#ffffff",boxShadow:"0 1px 2px rgba(15, 23, 42, 0.25)",transition:"left 0.18s cubic-bezier(0.16, 1, 0.3, 1)"}})}),!S&&jsxs(Fragment,{children:[yr&&jsx("button",{onClick:Oe?qo:Xo,onMouseEnter:()=>V(true),onMouseLeave:()=>V(false),title:Oe?"Redock to sidebar":"Pop out into window",style:{padding:6,borderRadius:6,color:K?"#4b5563":"#9ca3af",backgroundColor:K?"#f3f4f6":"transparent",border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",transition:"background-color 0.15s, color 0.15s"},children:Oe?jsx(PictureInPicture,{style:{width:16,height:16}}):jsx(PictureInPicture2,{style:{width:16,height:16}})}),jsx("button",{onClick:Cr,onMouseEnter:()=>D(true),onMouseLeave:()=>D(false),style:{padding:6,borderRadius:6,color:H?"#4b5563":"#9ca3af",backgroundColor:H?"#f3f4f6":"transparent",border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",transition:"background-color 0.15s, color 0.15s"},children:jsx(X,{style:{width:16,height:16}})})]})]})]}),jsxs("div",{ref:ne,style:{flex:1,overflowY:"auto",minHeight:0,display:"flex",flexDirection:"column"},children:[!c&&!A&&jsxs("div",{style:{display:"flex",flexDirection:"column"},children:[Ne.length===0&&jsx("div",{style:{padding:"24px 20px",textAlign:"center",fontSize:13,color:"#6b7280"},children:"No forks yet. Describe a feature below to start one."}),Ne.length>0&&jsx("div",{style:{display:"flex",flexDirection:"column"},children:Ne.map((a,T)=>{let B=o[a.id],le=(B?B.events.find(Ye=>{let ss=Ye.data;return Ye.type==="status"&&ss.summary})?.data?.summary??B.fork.summary:void 0)||a.summary||"Untitled fork",je=!!fr.find(Ye=>Ye.id===a.id)?.unread,Me=o[a.id]?.state??a.status,os=Me==="running"||Me==="building"||Me==="pending";return jsxs(Fragment$1,{children:[jsxs("button",{onClick:()=>{z(false),y(a.id);},style:{textAlign:"left",padding:"12px 16px",background:"transparent",border:"none",cursor:"pointer",display:"flex",alignItems:"flex-start",gap:8,width:"100%",transition:"background 0.12s",fontFamily:"inherit"},onMouseEnter:Ye=>{Ye.currentTarget.style.background="#fafafa";},onMouseLeave:Ye=>{Ye.currentTarget.style.background="transparent";},children:[je&&jsx("span",{"aria-label":"Not viewed yet",title:"Not viewed yet",style:{width:7,height:7,borderRadius:"50%",backgroundColor:"#111827",flexShrink:0,marginTop:5}}),jsxs("div",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:5,alignItems:"flex-start"},children:[jsx("span",{style:{fontSize:13.5,fontWeight:600,color:"#111827",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",maxWidth:"100%"},children:le}),jsx("span",{style:{fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, "Liberation Mono", "Courier New", monospace',fontSize:10,color:"#9ca3af",background:"#f8f9fa",borderRadius:5,padding:"1px 6px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",maxWidth:"100%",boxSizing:"border-box"},children:a.targetId})]}),os&&jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:5,background:"#fff7ed",border:"1px solid #fed7aa",color:"#c2410c",borderRadius:999,padding:"2px 9px",fontSize:11,fontWeight:600,flexShrink:0},children:[jsx("span",{style:{width:6,height:6,borderRadius:"50%",background:"#f59e0b",animation:"__fork-pulse 1.4s ease-in-out infinite"}}),"Running"]}),Me==="error"&&jsx("span",{style:{display:"inline-flex",alignItems:"center",gap:5,background:"#fef2f2",border:"1px solid #fecaca",color:"#b91c1c",borderRadius:999,padding:"2px 9px",fontSize:11,fontWeight:600,flexShrink:0},children:"Failed"}),jsx("span",{style:{fontSize:11.5,color:"#9ca3af",flexShrink:0,marginTop:2},children:Kn(a.updatedAt)})]}),T<Ne.length-1&&jsx("div",{style:{height:1,background:"#f3f4f6",margin:"0 16px",flexShrink:0}})]},a.id)})})]}),c&&xt.length>0&&jsx("div",{style:{margin:"16px 16px 0 16px"},children:xt.map((a,T)=>jsx("div",{style:{marginBottom:T<xt.length-1?12:0},children:a.type==="user"?jsx("div",{style:{display:"flex",justifyContent:"flex-end"},children:jsxs("div",{style:{backgroundColor:"#f3f4f6",borderRadius:12,padding:"10px 14px",fontSize:13,color:"#374151",lineHeight:1.5,maxWidth:"85%"},children:[a.attachments&&a.attachments.length>0&&jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:4,marginBottom:6},children:a.attachments.map((B,G)=>jsx("img",{src:B.dataUrl,alt:"attachment",style:{maxWidth:150,maxHeight:110,borderRadius:8,border:"1px solid #e5e7eb",display:"block",objectFit:"cover"}},G))}),a.selectedElement&&jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:4,background:"#eef2ff",border:"1px solid #c7d2fe",color:"#4338ca",borderRadius:999,padding:"2px 8px",fontSize:10.5,fontWeight:500,marginRight:6,maxWidth:"100%"},children:[jsx(MousePointer2,{style:{width:10,height:10,flexShrink:0}}),jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"ui-monospace, SFMono-Regular, Menlo, monospace"},children:a.selectedElement.label})]}),a.text]})}):I==="item"&&T===xt.length-1?jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:12,padding:12,borderRadius:8,border:"1px solid #e4e4e7",background:"#ffffff"},children:[jsx("div",{style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:28,height:28,flexShrink:0,borderRadius:6,background:"#f4f4f5",color:"#0a0a0a"},children:jsx(BadgeCheck,{style:{width:16,height:16}})}),jsxs("div",{style:{display:"flex",flexDirection:"column",gap:2,flex:1,minWidth:0},children:[jsx("div",{style:{fontSize:13,fontWeight:500,color:"#0a0a0a",lineHeight:1.3},children:"Feature applied"}),jsx("div",{style:{fontSize:13,color:"#71717a",lineHeight:1.4},children:a.text})]}),b&&De!=="running"&&jsx("button",{onClick:B=>{B.stopPropagation(),Ir();},disabled:p,style:{padding:"4px 10px",fontSize:12,fontWeight:500,borderRadius:6,border:"1px solid #e4e4e7",background:"#ffffff",color:"#0a0a0a",cursor:p?"default":"pointer",opacity:p?.4:1,height:28,flexShrink:0},children:"Undo"})]}):jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:8,background:"#ffffff",border:"1px solid #e5e7eb",borderRadius:10,boxShadow:"0 1px 2px rgba(0, 0, 0, 0.03)",padding:"9px 12px",maxWidth:"90%",boxSizing:"border-box"},children:[jsx("span",{style:{width:7,height:7,borderRadius:"50%",background:"#94a3b8",flexShrink:0}}),jsx("span",{style:{fontSize:12.5,fontWeight:600,color:"#334155",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:0},children:a.text}),a.timestamp&&jsx("span",{style:{fontSize:11,color:"#9ca3af",flexShrink:0},children:Kn(a.timestamp)}),b&&T===xt.length-1&&De!=="running"&&jsxs("button",{onClick:B=>{B.stopPropagation(),Ir();},onMouseEnter:()=>q(T),onMouseLeave:()=>q(null),disabled:p,style:{position:"relative",padding:2,borderRadius:4,border:"none",background:x===T?"rgba(0,0,0,0.06)":"transparent",color:x===T?"#6b7280":"#d1d5db",cursor:p?"default":"pointer",display:"flex",alignItems:"center",justifyContent:"center",transition:"color 0.15s, background 0.15s",opacity:p?.4:1,flexShrink:0},children:[jsx(Undo2,{style:{width:12,height:12}}),x===T&&jsx("span",{style:{position:"absolute",bottom:"calc(100% + 4px)",right:0,fontSize:10,fontWeight:500,color:"#fff",background:"#374151",borderRadius:4,padding:"2px 6px",whiteSpace:"nowrap",pointerEvents:"none",lineHeight:"16px"},children:"Undo"})]})]})},T))}),De==="running"&&jsx("div",{style:{margin:"12px 16px 0 16px"},children:jsxs("div",{onClick:()=>w(!M),style:{background:"#ffffff",border:"1px solid #e5e7eb",borderRadius:10,boxShadow:"0 1px 2px rgba(0, 0, 0, 0.03)",overflow:"hidden",cursor:"pointer",transition:"all 0.3s cubic-bezier(0.22, 1, 0.36, 1)"},children:[jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"9px 12px"},children:[jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[jsx("span",{style:{width:7,height:7,borderRadius:"50%",background:"#f59e0b",flexShrink:0,animation:"__fork-pulse 1.4s ease-in-out infinite"}}),jsx(Ci,{events:ht},c??"__compose__")]}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flexShrink:0,marginLeft:8},children:[ht[0]?.timestamp&&jsx("span",{style:{fontSize:11,color:"#9ca3af"},children:Kn(ht[0].timestamp)}),jsx("div",{style:{color:"#9ca3af",transition:"transform 0.2s ease",transform:M?"rotate(180deg)":"rotate(0deg)",display:"flex"},children:jsx(ChevronDown,{style:{width:14,height:14}})})]})]}),jsx("div",{style:{maxHeight:M?320:0,opacity:M?1:0,transition:"max-height 0.35s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.25s ease",overflow:"hidden"},children:jsx("div",{style:{background:"#1a1a2e",borderTop:"1px solid #e5e7eb",maxHeight:320,overflowY:"auto"},children:jsx(Zr,{events:ht},c??"__compose__")})})]})}),De==="error"&&jsxs("div",{style:{padding:"20px 16px",textAlign:"center"},children:[jsx("div",{style:{width:36,height:36,backgroundColor:"#fef2f2",borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",margin:"0 auto 10px auto"},children:jsx(X,{style:{width:18,height:18,color:"#ef4444"}})}),jsx("p",{style:{fontSize:12,color:"#6b7280",marginBottom:10,maxWidth:260,margin:"0 auto 10px auto"},children:Yo??r}),jsxs("button",{onClick:()=>{let a=Sn?.prompt||qt.current;a&&h(a,vt);},onMouseEnter:()=>C(true),onMouseLeave:()=>C(false),style:{display:"inline-flex",alignItems:"center",gap:6,padding:"6px 12px",borderRadius:8,fontSize:12,fontWeight:500,color:"#111827",backgroundColor:U?"#e5e7eb":"#f3f4f6",border:"none",cursor:"pointer",transition:"background-color 0.15s",fontFamily:"inherit"},children:[jsx(RotateCcw,{style:{width:12,height:12}})," Try Again"]})]})]}),!(c?De==="running":A&&e==="running")&&jsxs("div",{style:{padding:"8px 12px 12px 12px",borderTop:"1px solid rgba(229, 231, 235, 0.6)",flexShrink:0,position:"relative"},children:[pt&&jsx("div",{style:{position:"absolute",top:-42,left:"50%",transform:"translateX(-50%)",background:"#111827",color:"#ffffff",fontSize:12,fontWeight:500,padding:"7px 14px",borderRadius:999,boxShadow:"0 4px 16px rgba(0, 0, 0, 0.22)",whiteSpace:"nowrap",maxWidth:jn-32,overflow:"hidden",textOverflow:"ellipsis",pointerEvents:"none",zIndex:5},children:pt}),jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6,borderRadius:14,padding:"10px 10px 8px 12px",background:"#ffffff",border:"1px solid #e5e7eb",boxShadow:"0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 14px -6px rgba(0, 0, 0, 0.08)"},children:[(ie.length>0||ce)&&jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:6,alignItems:"center"},children:[ie.map(a=>jsxs("div",{onMouseEnter:()=>ur(a.id),onMouseLeave:()=>ur(null),style:{position:"relative",width:44,height:44,borderRadius:8,overflow:"hidden",border:"1px solid #e5e7eb",flexShrink:0},children:[jsx("img",{src:a.dataUrl,alt:"attachment",style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}}),jsx("button",{onClick:()=>be(T=>T.filter(B=>B.id!==a.id)),title:"Remove image",style:{position:"absolute",top:2,right:2,width:15,height:15,borderRadius:"50%",background:"rgba(17, 24, 39, 0.78)",color:"#ffffff",border:"none",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",padding:0,opacity:Ko===a.id?1:.6,transition:"opacity 0.12s"},children:jsx(X,{style:{width:9,height:9}})})]},a.id)),ce&&jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:5,background:"#eef2ff",border:"1px solid #c7d2fe",color:"#4338ca",borderRadius:999,padding:"4px 6px 4px 9px",fontSize:11,fontWeight:500,maxWidth:"100%",minWidth:0},children:[jsx(MousePointer2,{style:{width:11,height:11,flexShrink:0}}),jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontFamily:"ui-monospace, SFMono-Regular, Menlo, monospace"},children:an(ce)}),jsx("button",{onClick:()=>me(null),title:"Remove element context",style:{width:14,height:14,borderRadius:"50%",background:"transparent",color:"#6366f1",border:"none",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",padding:0,flexShrink:0},children:jsx(X,{style:{width:10,height:10}})})]})]}),jsx("textarea",{ref:Z,value:m,onChange:a=>P(a.target.value),onPaste:a=>{let T=eo(a.nativeEvent);T.length>0&&(a.preventDefault(),vr(T));},onKeyDown:a=>{a.key==="Enter"&&!a.shiftKey&&(a.preventDefault(),xr()),a.key==="Escape"&&!S&&Cr();},placeholder:c?"Iterate on this feature...":"Start building a new Fork...",rows:1,style:{width:"100%",backgroundColor:"transparent",fontSize:13,color:"#111827",border:"none",outline:"none",padding:0,fontFamily:"inherit",resize:"none",lineHeight:1.5,maxHeight:160,overflow:"auto",boxSizing:"border-box"}}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:2},children:[jsx("button",{onClick:()=>ir.current?.click(),onMouseEnter:()=>ar(true),onMouseLeave:()=>ar(false),title:"Attach an image",style:{width:28,height:28,borderRadius:8,display:"flex",alignItems:"center",justifyContent:"center",background:Bo?"rgba(0, 0, 0, 0.05)":"transparent",color:"#6b7280",border:"none",cursor:"pointer",padding:0,flexShrink:0,transition:"background 0.12s"},children:jsx(ImagePlus,{style:{width:16,height:16}})}),jsx("button",{onClick:es,onMouseEnter:()=>lr(true),onMouseLeave:()=>lr(false),title:ae?"Cancel element selection":"Select an element on the page",style:{width:28,height:28,borderRadius:8,display:"flex",alignItems:"center",justifyContent:"center",background:ae?"#eef2ff":Do?"rgba(0, 0, 0, 0.05)":"transparent",color:ae?"#4f46e5":"#6b7280",border:"none",cursor:"pointer",padding:0,flexShrink:0,transition:"background 0.12s, color 0.12s"},children:jsx(MousePointer2,{style:{width:16,height:16}})}),jsx("div",{style:{flex:1}}),jsx("button",{onClick:ts,onMouseEnter:()=>cr(true),onMouseLeave:()=>cr(false),title:fe?"Stop voice input":"Voice input",style:{width:28,height:28,borderRadius:8,display:"flex",alignItems:"center",justifyContent:"center",background:fe?"#fef2f2":jo?"rgba(0, 0, 0, 0.05)":"transparent",color:fe?"#dc2626":"#6b7280",border:"none",cursor:"pointer",padding:0,flexShrink:0,transition:"background 0.12s, color 0.12s",animation:fe?"__fork-pulse 1.4s ease-in-out infinite":void 0},children:jsx(Mic,{style:{width:16,height:16}})}),jsx("button",{onClick:xr,disabled:!yt,onMouseEnter:()=>X$1(true),onMouseLeave:()=>X$1(false),title:"Send",style:{width:28,height:28,borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",color:"#ffffff",opacity:yt?1:.35,transform:W&&yt?"scale(1.08)":"scale(1)",background:yt?"#111827":"rgba(0, 0, 0, 0.12)",border:"none",cursor:yt?"pointer":"default",flexShrink:0,transition:"transform 0.15s, opacity 0.15s, background 0.15s",padding:0,marginLeft:4},children:jsx(ArrowUp,{style:{width:14,height:14}})})]})]}),jsx("input",{ref:ir,type:"file",accept:"image/*",multiple:true,style:{display:"none"},onChange:a=>{let T=Array.from(a.target.files??[]);a.target.value="",vr(T);}})]})]})]});return S?Fn:Oe&&Ie?createPortal(Fn,Ie.document.body):jsx(Mi,{children:Fn})}function uo(e){if("target"in e&&e.target)return e.target;if("boundaryId"in e&&e.boundaryId)return {type:"boundary",id:e.boundaryId,title:e.title};if("slotId"in e&&e.slotId)return {type:"slot",id:e.slotId,title:e.title??e.slotLabel};throw new Error("Fork chat target requires either target, slotId, or boundaryId.")}function zn(e){let{apiKey:t,userId:n,userHash:r,baseUrl:o,appId:s,adminContext:i,refreshModuleManifest:l,queueBoundaryAnimation:u,trackForkActivity:h,recordForkActivityEvent:b}=ve(),[d,k]=useState({}),[R,v]=useState(null),[f,g]=useState("idle"),[S,I]=useState(false),[m,P]=useState(null),L=useRef(new Map),j=useCallback((C,M)=>{k(w=>{let $=w[C]??{forkId:C,state:"running",fork:M.fork,events:[],error:null};return {...w,[C]:{...$,...M}}});},[]),O=useCallback((C,M)=>{k(w=>{let p=w[C];return p?{...w,[C]:{...p,events:[...p.events,M]}}:w});},[]),N=useCallback(C=>{let M=L.current.get(C);M&&(M.close(),L.current.delete(C));},[]),oe=useCallback(()=>{g("prompting"),P(null),I(false),v(null);},[]),Y=useCallback(()=>{g("idle"),I(false),P(null),v(null);for(let C of L.current.values())C.close();L.current.clear(),k({});},[]),_=useCallback((C,M)=>{N(C.id);let w=new URLSearchParams({key:t});n&&w.set("userId",n),r&&w.set("userHash",r),i.isAdmin&&i.containerId&&w.set("containerId",i.containerId);let p=new EventSource(`${o}/api/v1/forks/${C.id}/events?${w.toString()}`);L.current.set(C.id,p),p.onmessage=$=>{try{let x=JSON.parse($.data);if(b(C.id,x),O(C.id,x),x.type==="complete"){let q=x.data;u(M,C.id),l().catch(()=>{}).finally(()=>{let re={...C,status:"complete",moduleUrl:q.moduleUrl,cssUrls:q.cssUrls,summary:q.summary,completedAt:new Date().toISOString()};j(C.id,{state:"complete",fork:re}),N(C.id);});}else if(x.type==="error"){let q=x.data;j(C.id,{state:"error",error:q.error||"Unknown error"}),N(C.id);}}catch{}},p.onerror=()=>{let $={Authorization:`Bearer ${t}`,...pe()};n&&($["X-Fork-User-Id"]=n),r&&($["X-Fork-User-Hash"]=r),fetch(`${o}/api/v1/forks/${C.id}`,{headers:$}).then(x=>x.json()).then(x=>{x.status==="complete"?(u(M,x.id),l().catch(()=>{}),j(C.id,{state:"complete",fork:x})):x.status==="error"?j(C.id,{state:"error",fork:x,error:x.error||"Fork generation failed"}):j(C.id,{fork:x});}).catch(()=>{j(C.id,{state:"error",error:"Connection lost"});}),N(C.id);};},[i.containerId,i.isAdmin,t,O,o,N,u,b,l,j,r,n]),F=useCallback(async(C,M,w)=>{try{if(!s)throw new Error("ForkProvider requires appId for module boundary prompts.");I(!0),P(null),v(null);let p;if(w?.forkId){let $={prompt:C};n&&($.userId=n),r&&($.userHash=r),w?.attachments?.length&&($.attachments=w.attachments),w?.selectedElement&&($.selectedElement=w.selectedElement);let x=await fetch(`${o}/api/v1/forks/${encodeURIComponent(w.forkId)}/prompts`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`,...pe()},body:JSON.stringify($)});if(!x.ok){let q=await x.json().catch(()=>({}));throw new Error(q.error||`API error: ${x.status}`)}p=await x.json();}else {let $={userId:n,prompt:C,boundaryId:e,appId:s};M?$.containerId=M:i.isAdmin&&i.containerId&&($.containerId=i.containerId),r&&($.userHash=r),w?.forceNew&&($.force_new=!0),w?.attachments?.length&&($.attachments=w.attachments),w?.selectedElement&&($.selectedElement=w.selectedElement);let x=await fetch(`${o}/api/v1/forks`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`,...pe()},body:JSON.stringify($)});if(!x.ok){let q=await x.json().catch(()=>({}));throw new Error(q.error||`API error: ${x.status}`)}p=await x.json();}k($=>({...$,[p.id]:{forkId:p.id,state:"running",fork:p,events:[],error:null}})),v(p.id),I(!1),h(p,{targetKind:"module",targetId:e}),_(p,p.boundaryId??e);}catch(p){P(p.message),I(false);}},[i.containerId,i.isAdmin,t,s,o,e,_,h,r,n]),H=useCallback(async C=>{try{let M={Authorization:`Bearer ${t}`,...pe()};n&&(M["X-Fork-User-Id"]=n),r&&(M["X-Fork-User-Hash"]=r);let w=await fetch(`${o}/api/v1/forks/${C}`,{headers:M});if(!w.ok)return;let p=await w.json(),$=p.boundaryId??e;if(h(p,{targetKind:"module",targetId:$}),p.status==="complete"){k(x=>({...x,[p.id]:{forkId:p.id,state:"complete",fork:p,events:[],error:null}})),v(p.id);return}if(p.status==="error"){k(x=>({...x,[p.id]:{forkId:p.id,state:"error",fork:p,events:[],error:p.error||"Fork generation failed"}})),v(p.id);return}if(p.status!=="pending"&&p.status!=="running"&&p.status!=="building")return;k(x=>({...x,[p.id]:{forkId:p.id,state:"running",fork:p,events:[],error:null}})),v(p.id),_(p,$);}catch{}},[t,o,e,_,h,r,n]),D=useCallback(async C=>{try{if(!s)throw new Error("ForkProvider requires appId for boundary undo.");let M={userId:n,boundaryId:e,appId:s};r&&(M.userHash=r),C&&(M.fork_id=C);let w=await fetch(`${o}/api/v1/forks/undo`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`},body:JSON.stringify(M)});if(!w.ok){let $=await w.json().catch(()=>({}));throw new Error($.error||`API error: ${w.status}`)}let p=await w.json();if(await l().catch(()=>{}),p.removed)k($=>{let x={};for(let[q,re]of Object.entries($))(re.fork.boundaryId??e)!==e&&(x[q]=re);return x}),v(null),g("prompting");else if(p.fork){let $=p.fork;j($.id,{state:"complete",fork:$}),v($.id);}return p}catch(M){throw P(M.message),M}},[t,s,o,e,l,j,r,n]),K=R?d[R]??null:null,V=S?"running":m?"error":K?K.state:f,W=K?.fork??null,X=K?.events??[],U=m??K?.error??null;return {state:V,fork:W,events:X,error:U,runs:d,open:oe,close:Y,startFork:F,undoFork:D,adoptRunningFork:H}}var Pi=0;function mo(e){let{state:t,fork:n,events:r,error:o,runs:s,open:i,close:l,startFork:u,undoFork:h,adoptRunningFork:b}=zn(e),[d,k]=useState(false),R=useRef(null),v=useRef(t),f=useCallback(()=>{R.current!==null&&(clearTimeout(R.current),R.current=null);},[]),g=useCallback(()=>{f(),k(true),i();},[f,i]),S=useCallback(()=>{f(),k(false),l();},[f,l]),I=useCallback(async P=>{f(),k(true),await b(P);},[b,f]),m=Object.values(s).filter(P=>P.state==="running").length;return useEffect(()=>{let P=v.current;v.current=t,t==="complete"&&P==="running"&&d&&m===0&&(f(),R.current=setTimeout(()=>{R.current=null,k(false),l();},Pi)),(t==="running"||t==="prompting")&&f();},[t,d,m,f,l]),useEffect(()=>f,[f]),{state:t,fork:n,events:r,error:o,runs:s,isOpen:d,open:g,close:S,submit:u,undo:h,adoptRunningFork:I}}function Wn(){let{apiKey:e,userId:t,userHash:n,baseUrl:r,adminContext:o,setSlotFork:s,clearSlotFork:i,skipAnimationForSlot:l,trackForkActivity:u,recordForkActivityEvent:h}=ve(),[b,d]=useState({}),[k,R]=useState(null),[v,f]=useState("idle"),[g,S]=useState(false),[I,m]=useState(null),P=useRef(new Map),L=useCallback((U,C)=>{d(M=>{let p=M[U]??{forkId:U,state:"running",fork:C.fork,events:[],error:null};return {...M,[U]:{...p,...C}}});},[]),j=useCallback((U,C)=>{d(M=>{let w=M[U];return w?{...M,[U]:{...w,events:[...w.events,C]}}:M});},[]),O=useCallback(U=>{let C=P.current.get(U);C&&(C.close(),P.current.delete(U));},[]),N=useCallback(()=>{f("prompting"),m(null),S(false),R(null);},[]),oe=useCallback(()=>{f("idle"),S(false),m(null),R(null);for(let U of P.current.values())U.close();P.current.clear(),d({});},[]),Y=useCallback((U,C)=>{O(U.id);let M=new URLSearchParams({key:e});t&&M.set("userId",t),n&&M.set("userHash",n),o.isAdmin&&o.containerId&&M.set("containerId",o.containerId);let w=new EventSource(`${r}/api/v1/forks/${U.id}/events?${M.toString()}`);P.current.set(U.id,w),w.onmessage=p=>{try{let $=JSON.parse(p.data);if(h(U.id,$),j(U.id,$),$.type==="complete"){let x=$.data,q={...U,status:"complete",bundleUrl:x.bundleUrl,summary:x.summary,revealPending:!0,completedAt:new Date().toISOString()};L(U.id,{state:"complete",fork:q});let re=C??U.slotId;re&&x.bundleUrl&&s(re,q),O(U.id);}else if($.type==="error"){let x=$.data;L(U.id,{state:"error",error:x.error||"Unknown error"}),O(U.id);}}catch{}},w.onerror=()=>{let p={Authorization:`Bearer ${e}`,...pe()};t&&(p["X-Fork-User-Id"]=t),n&&(p["X-Fork-User-Hash"]=n),fetch(`${r}/api/v1/forks/${U.id}`,{headers:p}).then($=>$.json()).then($=>{if($.status==="complete"){L(U.id,{state:"complete",fork:{...$,revealPending:true}});let x=C??$.slotId;x&&$.bundleUrl&&s(x,{...$,revealPending:true});}else $.status==="error"?L(U.id,{state:"error",fork:$,error:$.error||"Fork generation failed"}):L(U.id,{fork:$});}).catch(()=>{L(U.id,{state:"error",error:"Connection lost"});}),O(U.id);};},[o.containerId,o.isAdmin,e,j,r,O,h,s,L,n,t]),_=useCallback(async(U,C,M,w)=>{try{S(!0),m(null),R(null);let p;if(w?.forkId){let x={prompt:U};t&&(x.userId=t),n&&(x.userHash=n),w?.attachments?.length&&(x.attachments=w.attachments),w?.selectedElement&&(x.selectedElement=w.selectedElement);let q=await fetch(`${r}/api/v1/forks/${encodeURIComponent(w.forkId)}/prompts`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`,...pe()},body:JSON.stringify(x)});if(!q.ok){let re=await q.json().catch(()=>({}));throw new Error(re.error||`API error: ${q.status}`)}p=await q.json();}else {let x={userId:t,prompt:U};C&&(x.slotId=C),M?x.containerId=M:o.isAdmin&&o.containerId&&(x.containerId=o.containerId),n&&(x.userHash=n),w?.forceNew&&(x.force_new=!0),w?.attachments?.length&&(x.attachments=w.attachments),w?.selectedElement&&(x.selectedElement=w.selectedElement);let q=await fetch(`${r}/api/v1/forks`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`,...pe()},body:JSON.stringify(x)});if(!q.ok){let re=await q.json().catch(()=>({}));throw new Error(re.error||`API error: ${q.status}`)}p=await q.json();}d(x=>({...x,[p.id]:{forkId:p.id,state:"running",fork:p,events:[],error:null}})),R(p.id),S(!1);let $=C??p.slotId;$&&u(p,{targetKind:"slot",targetId:$}),Y(p,C);}catch(p){m(p.message),S(false);}},[o.containerId,o.isAdmin,e,r,Y,u,n,t]),F=useCallback(async U=>{try{let C={Authorization:`Bearer ${e}`,...pe()};t&&(C["X-Fork-User-Id"]=t),n&&(C["X-Fork-User-Hash"]=n);let M=await fetch(`${r}/api/v1/forks/${U}`,{headers:C});if(!M.ok)return;let w=await M.json();if(w.slotId&&u(w,{targetKind:"slot",targetId:w.slotId}),w.status==="complete"){d(p=>({...p,[w.id]:{forkId:w.id,state:"complete",fork:w,events:[],error:null}})),R(w.id);return}if(w.status==="error"){d(p=>({...p,[w.id]:{forkId:w.id,state:"error",fork:w,events:[],error:w.error||"Fork generation failed"}})),R(w.id);return}if(w.status!=="pending"&&w.status!=="running"&&w.status!=="building")return;d(p=>({...p,[w.id]:{forkId:w.id,state:"running",fork:w,events:[],error:null}})),R(w.id),Y(w,w.slotId);}catch{}},[e,r,Y,u,n,t]),H=useCallback(async U=>{try{let C={userId:t,slotId:U};n&&(C.userHash=n);let M=await fetch(`${r}/api/v1/forks/undo`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e}`},body:JSON.stringify(C)});if(!M.ok){let p=await M.json().catch(()=>({}));throw new Error(p.error||`API error: ${M.status}`)}let w=await M.json();if(l(U),w.removed)i(U),d(p=>{let $={};for(let[x,q]of Object.entries(p))q.fork.slotId!==U&&($[x]=q);return $}),R(null),f("prompting");else if(w.fork){s(U,w.fork);let p=w.fork;L(p.id,{state:"complete",fork:p});}return w}catch(C){throw m(C.message),C}},[e,t,n,r,i,s,l,L]),D=k?b[k]??null:null,K=g?"running":I?"error":D?D.state:v,V=D?.fork??null,W=D?.events??[],X=I??D?.error??null;return {state:K,fork:V,events:W,error:X,runs:b,open:N,close:oe,startFork:_,undoFork:H,adoptRunningFork:F}}var Hi=0;function yo(){let{state:e,fork:t,events:n,error:r,runs:o,open:s,close:i,startFork:l,undoFork:u,adoptRunningFork:h}=Wn(),[b,d]=useState(false),k=useRef(null),R=useRef(e),v=useCallback(()=>{k.current!==null&&(clearTimeout(k.current),k.current=null);},[]),f=useCallback(()=>{v(),d(true),s();},[v,s]),g=useCallback(()=>{v(),d(false),i();},[v,i]),S=useCallback(async m=>{v(),d(true),await h(m);},[h,v]),I=Object.values(o).filter(m=>m.state==="running").length;return useEffect(()=>{let m=R.current;R.current=e,e==="complete"&&m==="running"&&b&&I===0&&(v(),k.current=setTimeout(()=>{k.current=null,d(false),i();},Hi)),(e==="running"||e==="prompting")&&v();},[e,b,I,v,i]),useEffect(()=>v,[v]),{state:e,fork:t,events:n,error:r,runs:o,isOpen:b,open:f,close:g,submit:l,undo:u,adoptRunningFork:S}}var Oi=new Set(["pending","running","building"]);function Vn(e){let t=uo(e),n=yo(),r=mo(t.type==="boundary"?t.id:""),{baseUrl:o,apiKey:s,userId:i,userHash:l,appId:u,activitySummary:h,forkActivities:b}=ve(),d=t.type==="slot"?n:r,k=t.type==="slot"?"slot":"boundary",R=t.id,v=t.title,f=t.type==="slot"?"slot":"module",g=b.find(L=>L.targetKind===f&&L.targetId===t.id&&Oi.has(L.status)),S=b.find(L=>L.targetKind===f&&L.targetId===t.id&&L.status==="complete"&&L.unread),I=useCallback(()=>{let L=g??S;if(L){d.adoptRunningFork(L.id);return}d.open();},[d,g,S]),m=useCallback((L,j,O,N)=>t.type==="slot"?n.submit(L,j??t.id,O,N):r.submit(L,O,N),[r,n,t]),P=useCallback((L,j)=>t.type==="slot"?n.undo(L??t.id):r.undo(j),[r,n,t]);return {...d,open:I,target:t,targetId:R,targetLabel:v,historyMode:k,submit:m,undo:P,buttonProps:{onClick:I,hasNotification:h.unreadCompletedCount>0,activity:h},panelProps:{state:d.state,fork:d.fork,events:d.events,error:d.error,runs:d.runs,...t.type==="slot"?{slotId:R,targetLabel:v,historyMode:k}:{targetId:R,targetLabel:v,historyMode:k},onSubmit:m,onUndo:P,onClose:d.close,baseUrl:o,apiKey:s,userId:i,userHash:l,appId:u}}}function _t(e){let{embedded:t,completeVariant:n}=e,r=Vn(e);return t?jsx(dn,{...r.panelProps,embedded:true,completeVariant:n}):r.isOpen?jsx(dn,{...r.panelProps,completeVariant:n}):jsx(Nn,{...r.buttonProps})}function Ni({boundaryId:e,title:t}){return jsx(_t,{boundaryId:e,title:t})}function qn(e){let t=Array.from(e.children).filter(r=>r instanceof HTMLElement);return t.length===1?t[0]:getComputedStyle(e).display==="contents"?null:e}function ko(e){let t=e.getBoundingClientRect(),n=e.cloneNode(true);n.setAttribute("data-fork-clone-overlay","true"),n.style.position="fixed",n.style.top=`${t.top}px`,n.style.left=`${t.left}px`,n.style.width=`${t.width}px`,n.style.height=`${t.height}px`,n.style.flex="none",n.style.minHeight="auto",n.style.zIndex="9998",n.style.pointerEvents="none",n.style.overflow="hidden";let r=getComputedStyle(e).backgroundColor;n.style.backgroundColor=r&&r!=="rgba(0, 0, 0, 0)"&&r!=="transparent"?r:getComputedStyle(document.body).backgroundColor||"#ffffff",document.body.appendChild(n);let o=e.querySelectorAll("*"),s=n.querySelectorAll("*");for(let i=0;i<o.length;i+=1)o[i].scrollTop!==0&&(s[i].scrollTop=o[i].scrollTop),o[i].scrollLeft!==0&&(s[i].scrollLeft=o[i].scrollLeft);return n}function Gn(e){let t=[],n=e.querySelectorAll("*");for(let r of n){if(!(r instanceof HTMLElement))continue;let o=r.getBoundingClientRect();if(o.width<10||o.height<10||["SCRIPT","STYLE","META","LINK"].includes(r.tagName))continue;let s=getComputedStyle(r),i=parseFloat(s.borderTopLeftRadius)||0;t.push({tag:r.tagName,className:r.className||"",text:(r.textContent||"").slice(0,50).trim(),rect:o,borderRadius:i});}return t}function bo(e,t){let n=[];for(let r of t)if(!(e.find(i=>i.tag===r.tag&&i.className===r.className&&Math.abs(i.rect.top-r.rect.top)<20&&Math.abs(i.rect.left-r.rect.left)<20)||n.some(i=>r.rect.top>=i.rect.top&&r.rect.left>=i.rect.left&&r.rect.right<=i.rect.right&&r.rect.bottom<=i.rect.bottom))){for(let i=n.length-1;i>=0;i-=1){let l=n[i];l.rect.top>=r.rect.top&&l.rect.left>=r.rect.left&&l.rect.right<=r.rect.right&&l.rect.bottom<=r.rect.bottom&&n.splice(i,1);}n.push({rect:r.rect,borderRadius:r.borderRadius});}return n}function wo(e,t){let n=[];for(let r of e)if(!(t.find(i=>i.tag===r.tag&&i.className===r.className&&Math.abs(i.rect.top-r.rect.top)<20&&Math.abs(i.rect.left-r.rect.left)<20)||n.some(i=>r.rect.top>=i.rect.top&&r.rect.left>=i.rect.left&&r.rect.right<=i.rect.right&&r.rect.bottom<=i.rect.bottom))){for(let i=n.length-1;i>=0;i-=1){let l=n[i];l.rect.top>=r.rect.top&&l.rect.left>=r.rect.left&&l.rect.right<=r.rect.right&&l.rect.bottom<=r.rect.bottom&&n.splice(i,1);}n.push({rect:r.rect,borderRadius:r.borderRadius});}return n}function vo(e,t,n,r,o){let s=Math.max(0,Math.min(o,n/2,r/2));return s===0?`M ${e} ${t} L ${e+n} ${t} L ${e+n} ${t+r} L ${e} ${t+r} Z`:[`M ${e+s} ${t}`,`L ${e+n-s} ${t}`,`A ${s} ${s} 0 0 1 ${e+n} ${t+s}`,`L ${e+n} ${t+r-s}`,`A ${s} ${s} 0 0 1 ${e+n-s} ${t+r}`,`L ${e+s} ${t+r}`,`A ${s} ${s} 0 0 1 ${e} ${t+r-s}`,`L ${e} ${t+s}`,`A ${s} ${s} 0 0 1 ${e+s} ${t}`,"Z"].join(" ")}function Yn(e){let t="http://www.w3.org/2000/svg",n=document.createElement("div");n.setAttribute("data-fork-highlights","true"),n.style.cssText="position:fixed;top:0;left:0;width:100%;height:100%;pointer-events:none;z-index:9999;";let r=document.createElementNS(t,"svg");r.setAttribute("width","100%"),r.setAttribute("height","100%"),r.style.cssText="position:absolute;top:0;left:0;overflow:visible;";let o=document.createElementNS(t,"defs");r.appendChild(o);let s=[];for(let b=0;b<e.length;b+=1){let{rect:d,borderRadius:k}=e[b],R=d.left-.5,v=d.top-.5,f=d.width+1,g=d.height+1,S=Math.min(k+.5,f/2,g/2),I=vo(R,v,f,g,S),m=`__fork-glow-${b}`,P=document.createElementNS(t,"filter");P.setAttribute("id",m),P.setAttribute("x","-100%"),P.setAttribute("y","-100%"),P.setAttribute("width","300%"),P.setAttribute("height","300%");let L=document.createElementNS(t,"feGaussianBlur");L.setAttribute("in","SourceGraphic"),L.setAttribute("stdDeviation","8"),P.appendChild(L),o.appendChild(P);let j=`__fork-mask-${b}`,O=document.createElementNS(t,"mask");O.setAttribute("id",j),O.setAttribute("maskUnits","userSpaceOnUse"),O.setAttribute("x",String(R-200)),O.setAttribute("y",String(v-200)),O.setAttribute("width",String(f+400)),O.setAttribute("height",String(g+400));let N=document.createElementNS(t,"rect");N.setAttribute("x",String(R-200)),N.setAttribute("y",String(v-200)),N.setAttribute("width",String(f+400)),N.setAttribute("height",String(g+400)),N.setAttribute("fill","white"),O.appendChild(N);let oe=document.createElementNS(t,"path");oe.setAttribute("d",I),oe.setAttribute("fill","black"),O.appendChild(oe),o.appendChild(O);let Y=document.createElementNS(t,"g");Y.setAttribute("mask",`url(#${j})`),Y.setAttribute("opacity","0");let _=document.createElementNS(t,"g");_.setAttribute("filter",`url(#${m})`);let F=document.createElementNS(t,"path");F.setAttribute("d",I),F.setAttribute("fill","none"),F.setAttribute("stroke","rgba(150, 185, 220, 0.6)"),F.setAttribute("stroke-width","6"),F.setAttribute("stroke-linecap","round"),_.appendChild(F),Y.appendChild(_),r.appendChild(Y);let H=document.createElementNS(t,"path");H.setAttribute("d",I),H.setAttribute("fill","none"),H.setAttribute("stroke","rgba(150, 185, 220, 0.35)"),H.setAttribute("stroke-width","2"),H.setAttribute("stroke-linecap","round"),H.setAttribute("opacity","0"),r.appendChild(H),s.push(F,H),F.__group=Y;}n.appendChild(r),document.body.appendChild(n);let i=[];for(let b=0;b<s.length;b+=2){let d=s[b],k=s[b+1],R=d.__group;if(!R)continue;let v=k.getTotalLength(),f=d.getTotalLength();if(v<=0)continue;let g=v*.35;k.setAttribute("stroke-dasharray",`${g} ${v-g}`),k.setAttribute("stroke-dashoffset","0"),i.push(k.animate([{strokeDashoffset:0,opacity:0,offset:0},{strokeDashoffset:-0.2*v,opacity:.92,offset:.06},{strokeDashoffset:-2*v,opacity:.92,offset:.92},{strokeDashoffset:-2.25*v,opacity:0,offset:1}],{duration:14e3,easing:"ease-in-out",fill:"forwards"}));let S=f*.35;d.setAttribute("stroke-dasharray",`${S} ${f-S}`),d.setAttribute("stroke-dashoffset","0"),i.push(d.animate([{strokeDashoffset:0,offset:0},{strokeDashoffset:-0.2*f,offset:.06},{strokeDashoffset:-2*f,offset:.92},{strokeDashoffset:-2.25*f,offset:1}],{duration:14e3,easing:"ease-in-out",fill:"forwards"})),i.push(R.animate([{opacity:0,offset:0},{opacity:.92,offset:.06},{opacity:.92,offset:.92},{opacity:0,offset:1}],{duration:14e3,easing:"ease-in-out",fill:"forwards"}));}let l=false,u=()=>{if(l)return;l=true,clearTimeout(h);for(let d of i)try{d.cancel();}catch{}let b=n.animate([{opacity:1},{opacity:0}],{duration:400,fill:"forwards"});b.onfinish=()=>n.remove(),window.removeEventListener("click",u);},h=setTimeout(u,14500);return setTimeout(()=>{l||window.addEventListener("click",u);},500),u}function So(e){let t="http://www.w3.org/2000/svg",n=document.createElement("div");n.setAttribute("data-fork-removed","true"),n.style.cssText="position:fixed;top:0;left:0;width:100%;height:100%;pointer-events:none;z-index:9999;";let r=document.createElementNS(t,"svg");r.setAttribute("width","100%"),r.setAttribute("height","100%"),r.style.cssText="position:absolute;top:0;left:0;overflow:visible;";let o=document.createElementNS(t,"defs"),s=document.createElementNS(t,"filter");s.setAttribute("id","__fork-removed-shadow"),s.setAttribute("x","-10%"),s.setAttribute("y","-10%"),s.setAttribute("width","120%"),s.setAttribute("height","120%");let i=document.createElementNS(t,"feDropShadow");i.setAttribute("dx","0"),i.setAttribute("dy","1"),i.setAttribute("stdDeviation","2"),i.setAttribute("flood-color","rgba(0,0,0,0.15)"),s.appendChild(i),o.appendChild(s),r.appendChild(o);for(let{rect:l,borderRadius:u}of e){let h=document.createElementNS(t,"path");h.setAttribute("d",vo(l.left,l.top,l.width,l.height,u)),h.setAttribute("fill","none"),h.setAttribute("stroke","rgba(120, 125, 135, 0.6)"),h.setAttribute("stroke-width","1.5"),h.setAttribute("stroke-dasharray","8 4"),h.setAttribute("stroke-linecap","round"),h.setAttribute("filter","url(#__fork-removed-shadow)"),h.setAttribute("opacity","0"),r.appendChild(h),h.animate([{opacity:0,offset:0},{opacity:.6,offset:.08},{opacity:.05,offset:.45},{opacity:.6,offset:.85},{opacity:.05,offset:1}],{duration:5e3,easing:"ease-in-out",fill:"forwards"});}return n.appendChild(r),document.body.appendChild(n),n}function Ao(e,t){if(Bi(t.selector))return xo(e,t);let r=xo(e,t);if(r)return r;try{let s=document.querySelector(t.selector);if(s instanceof HTMLElement&&s!==e&&e.contains(s))return s}catch{}if(Fo(t.selector))try{let s=e.querySelector(t.selector);if(s instanceof HTMLElement&&s!==e)return s}catch{}if(t.textHint){let s=t.textHint.trim();if(s){let i=Qn(e,b=>b===s);if(i)return i;let l=s.toLowerCase(),u=Qn(e,b=>b.toLowerCase()===l);if(u)return u;let h=Qn(e,b=>b.toLowerCase().includes(l));if(h)return h}}let o=Di(t.selector);if(o&&o!==t.selector&&Fo(o))try{let s=e.querySelector(o);if(s instanceof HTMLElement&&s!==e)return s}catch{}return null}function Fo(e){let t=e.split(/\s+|>|~|\+/),n=t[t.length-1]??"";return /[#\[]|:not\(|:nth-/.test(n)}function xo(e,t){let n=Array.from(e.querySelectorAll("[data-fork-new]"));if(n.length===0)return null;let r=Zn(t.label),o=Zn(t.textHint);return n.find(i=>{let l=Zn(i.getAttribute("data-fork-new"));return !!l&&(l===r||l===o)})??null}function Bi(e){return e.trim()==="[data-fork-new]"}function Zn(e){return e?.trim().replace(/\s+/g," ").toLowerCase()||null}function Di(e){return e.replace(/\[class[\*~|^$]?=("[^"]*"|'[^']*'|[^\]]+)\]/g,"").replace(/\.[A-Za-z_][\w-]*/g,"").replace(/\s+/g," ").trim()}function Qn(e,t){let n=null,r=1/0,o=e.querySelectorAll("*");for(let s of o){let i=s.textContent?.trim();if(!i||!t(i))continue;let l=s.getBoundingClientRect();if(l.width<4||l.height<4)continue;let u=l.width*l.height;u<r&&(n=s,r=u);}return n}var er=2147483600,ji=1600,Ki=3e4,zi=300,Qe=10;function Wi(e){let n=getComputedStyle(e).borderTopLeftRadius;if(!n)return 4;if(n.endsWith("%")){let i=parseFloat(n);if(!Number.isFinite(i)||i<=0)return 4;let l=e.getBoundingClientRect(),u=Math.min(l.width,l.height);return Math.max(4,i/100*u)}let r=parseFloat(n);if(!Number.isFinite(r)||r<=0)return 4;let o=e.getBoundingClientRect(),s=Math.min(o.width,o.height)/2;return r>=s?s:Math.min(r,16)}function Ji(e,t,n,r){let s=window.innerWidth,i=window.innerHeight,l=e;l==="top"&&t.top<r+Qe+8?l="bottom":l==="bottom"&&i-t.bottom<r+Qe+8?l="top":l==="left"&&t.left<n+Qe+8?l="right":l==="right"&&s-t.right<n+Qe+8&&(l="left");let u=0,h=0;return l==="top"?(u=t.top-r-Qe,h=t.left+t.width/2-n/2):l==="bottom"?(u=t.bottom+Qe,h=t.left+t.width/2-n/2):l==="left"?(u=t.top+t.height/2-r/2,h=t.left-n-Qe):(u=t.top+t.height/2-r/2,h=t.right+Qe),h=Math.max(8,Math.min(h,s-n-8)),u=Math.max(8,Math.min(u,i-r-8)),{top:u,left:h,placement:l}}function Vi(e){let t=document.createElement("div");t.setAttribute("data-fork-highlight-outline","true"),t.style.cssText=["position:fixed","pointer-events:none",`z-index:${er}`,"border:1.5px solid rgba(59,130,246,0.85)","box-sizing:border-box","opacity:0","transition:opacity 200ms ease-out"].join(";");let n=document.createElement("div");n.setAttribute("data-fork-highlight-glow","true"),n.style.cssText=["position:fixed","pointer-events:none",`z-index:${er-1}`,"box-sizing:border-box","border:1px solid rgba(59,130,246,0.36)","box-shadow:0 0 0 4px rgba(59,130,246,0.16), 0 0 18px 2px rgba(59,130,246,0.31)","opacity:0","transition:opacity 200ms ease-out"].join(";");let r=document.createElement("div");return r.setAttribute("data-fork-highlight-tooltip","true"),r.style.cssText=["position:fixed","pointer-events:none",`z-index:${er+1}`,"padding:6px 10px","font:500 12px/1.2 -apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif","color:#ffffff","background:linear-gradient(135deg,#64748b,#475569)","border-radius:999px","box-shadow:0 4px 14px rgba(71,85,105,0.31),0 1px 2px rgba(0,0,0,0.1)","white-space:nowrap","opacity:0","transform:translateY(-2px)","transition:opacity 200ms ease-out, transform 200ms ease-out"].join(";"),r.textContent=`New: ${e}`,{outline:t,glow:n,tooltip:r}}function Xi(){if(document.getElementById("__fork-highlight-keyframes"))return;let e=document.createElement("style");e.id="__fork-highlight-keyframes",e.textContent=`
|
|
60
60
|
@keyframes __fork-highlight-pulse {
|
|
61
61
|
0%, 100% { box-shadow: 0 0 0 3px rgba(59,130,246,0.11), 0 0 12px 1px rgba(59,130,246,0.22); }
|
|
62
62
|
50% { box-shadow: 0 0 0 6px rgba(59,130,246,0.25), 0 0 22px 4px rgba(59,130,246,0.49); }
|
package/package.json
CHANGED