rivet-design 0.21.2 → 0.21.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/dist/agent-variants/WorktreeOrchestrator.d.ts +1 -1
  2. package/dist/agent-variants/WorktreeOrchestrator.d.ts.map +1 -1
  3. package/dist/agent-variants/WorktreeOrchestrator.js +6 -7
  4. package/dist/agent-variants/WorktreeOrchestrator.js.map +1 -1
  5. package/dist/agent-variants/contracts.d.ts +286 -286
  6. package/dist/agent-variants/guidancePrompt.d.ts.map +1 -1
  7. package/dist/agent-variants/guidancePrompt.js +17 -0
  8. package/dist/agent-variants/guidancePrompt.js.map +1 -1
  9. package/dist/agent-variants/workItemBriefing.d.ts.map +1 -1
  10. package/dist/agent-variants/workItemBriefing.js +1 -1
  11. package/dist/agent-variants/workItemBriefing.js.map +1 -1
  12. package/dist/agent-variants/workItemContextFiles.d.ts.map +1 -1
  13. package/dist/agent-variants/workItemContextFiles.js +9 -4
  14. package/dist/agent-variants/workItemContextFiles.js.map +1 -1
  15. package/dist/cli/commands/contextRequest.d.ts.map +1 -1
  16. package/dist/cli/commands/contextRequest.js +19 -4
  17. package/dist/cli/commands/contextRequest.js.map +1 -1
  18. package/dist/cli/commands/generationPreflight.js +1 -1
  19. package/dist/cli/commands/generationPreflight.js.map +1 -1
  20. package/dist/cli/commands/guidanceReferences.d.ts +11 -0
  21. package/dist/cli/commands/guidanceReferences.d.ts.map +1 -0
  22. package/dist/cli/commands/guidanceReferences.js +56 -0
  23. package/dist/cli/commands/guidanceReferences.js.map +1 -0
  24. package/dist/cli/commands/mcpServe.d.ts.map +1 -1
  25. package/dist/cli/commands/mcpServe.js +9 -1
  26. package/dist/cli/commands/mcpServe.js.map +1 -1
  27. package/dist/cli/commands/open.d.ts.map +1 -1
  28. package/dist/cli/commands/open.js +18 -59
  29. package/dist/cli/commands/open.js.map +1 -1
  30. package/dist/cli/commands/status.js +1 -1
  31. package/dist/cli/commands/status.js.map +1 -1
  32. package/dist/cli/commands/update.d.ts.map +1 -1
  33. package/dist/cli/commands/update.js +7 -0
  34. package/dist/cli/commands/update.js.map +1 -1
  35. package/dist/cli/commands/wait.d.ts.map +1 -1
  36. package/dist/cli/commands/wait.js +37 -4
  37. package/dist/cli/commands/wait.js.map +1 -1
  38. package/dist/cli/entry.d.ts.map +1 -1
  39. package/dist/cli/entry.js +16 -0
  40. package/dist/cli/entry.js.map +1 -1
  41. package/dist/cli/projectRuntimeUpgrade.d.ts +21 -0
  42. package/dist/cli/projectRuntimeUpgrade.d.ts.map +1 -0
  43. package/dist/cli/projectRuntimeUpgrade.js +116 -0
  44. package/dist/cli/projectRuntimeUpgrade.js.map +1 -0
  45. package/dist/cli/router.d.ts.map +1 -1
  46. package/dist/cli/router.js +4 -3
  47. package/dist/cli/router.js.map +1 -1
  48. package/dist/cli/runtimeInterruption.d.ts +32 -0
  49. package/dist/cli/runtimeInterruption.d.ts.map +1 -0
  50. package/dist/cli/runtimeInterruption.js +65 -0
  51. package/dist/cli/runtimeInterruption.js.map +1 -0
  52. package/dist/cli/serverVersion.js +1 -1
  53. package/dist/cli/serverVersion.js.map +1 -1
  54. package/dist/cli/synchronizeRuntimes.d.ts +19 -0
  55. package/dist/cli/synchronizeRuntimes.d.ts.map +1 -0
  56. package/dist/cli/synchronizeRuntimes.js +113 -0
  57. package/dist/cli/synchronizeRuntimes.js.map +1 -0
  58. package/dist/library/HubClient.d.ts +2 -0
  59. package/dist/library/HubClient.d.ts.map +1 -1
  60. package/dist/library/HubClient.js +48 -9
  61. package/dist/library/HubClient.js.map +1 -1
  62. package/dist/routes/cli.d.ts +1 -0
  63. package/dist/routes/cli.d.ts.map +1 -1
  64. package/dist/routes/cli.js +11 -4
  65. package/dist/routes/cli.js.map +1 -1
  66. package/dist/routes/library/guidance.d.ts.map +1 -1
  67. package/dist/routes/library/guidance.js +6 -1
  68. package/dist/routes/library/guidance.js.map +1 -1
  69. package/dist/server.d.ts.map +1 -1
  70. package/dist/server.js +1 -0
  71. package/dist/server.js.map +1 -1
  72. package/dist/services/RuntimeAdmission.d.ts +1 -1
  73. package/dist/services/RuntimeAdmission.d.ts.map +1 -1
  74. package/dist/services/RuntimeAdmission.js +3 -2
  75. package/dist/services/RuntimeAdmission.js.map +1 -1
  76. package/dist/services/VariantRunService.d.ts +1 -0
  77. package/dist/services/VariantRunService.d.ts.map +1 -1
  78. package/dist/services/VariantRunService.js +8 -2
  79. package/dist/services/VariantRunService.js.map +1 -1
  80. package/dist/services/guidanceDelivery.d.ts.map +1 -1
  81. package/dist/services/guidanceDelivery.js +15 -11
  82. package/dist/services/guidanceDelivery.js.map +1 -1
  83. package/dist/services/guidanceReferences.d.ts +6 -0
  84. package/dist/services/guidanceReferences.d.ts.map +1 -0
  85. package/dist/services/guidanceReferences.js +133 -0
  86. package/dist/services/guidanceReferences.js.map +1 -0
  87. package/dist/services/profiles/DesignProfiles.d.ts +66 -1
  88. package/dist/services/profiles/DesignProfiles.d.ts.map +1 -1
  89. package/dist/services/profiles/DesignProfiles.js +5 -1
  90. package/dist/services/profiles/DesignProfiles.js.map +1 -1
  91. package/dist/services/profiles/ProfilePlanning.d.ts +1 -1
  92. package/dist/services/runtimeVersion.d.ts +1 -1
  93. package/dist/services/runtimeVersion.d.ts.map +1 -1
  94. package/dist/services/runtimeVersion.js +1 -1
  95. package/dist/services/runtimeVersion.js.map +1 -1
  96. package/dist/services/stopRuntimeProcess.d.ts +9 -0
  97. package/dist/services/stopRuntimeProcess.d.ts.map +1 -0
  98. package/dist/services/stopRuntimeProcess.js +84 -0
  99. package/dist/services/stopRuntimeProcess.js.map +1 -0
  100. package/dist/storage/profiles/ProfilePlans.d.ts +4 -4
  101. package/dist/storage/profiles/ProfileRecords.d.ts +1 -1
  102. package/dist/storage/profiles/ProfileRecords.d.ts.map +1 -1
  103. package/dist/storage/profiles/ProfileRecords.js +3 -1
  104. package/dist/storage/profiles/ProfileRecords.js.map +1 -1
  105. package/dist/storage/profiles/migrations.d.ts +2 -2
  106. package/dist/storage/profiles/migrations.d.ts.map +1 -1
  107. package/dist/storage/profiles/migrations.js +3 -0
  108. package/dist/storage/profiles/migrations.js.map +1 -1
  109. package/dist/storage/profiles/planSchema.d.ts +1 -1
  110. package/dist/storage/profiles/schema.d.ts +29 -1
  111. package/dist/storage/profiles/schema.d.ts.map +1 -1
  112. package/dist/storage/profiles/schema.js +1 -0
  113. package/dist/storage/profiles/schema.js.map +1 -1
  114. package/dist/types/design-profile.d.ts +2 -2
  115. package/dist/types/guidance-references.d.ts +230 -0
  116. package/dist/types/guidance-references.d.ts.map +1 -0
  117. package/dist/types/guidance-references.js +133 -0
  118. package/dist/types/guidance-references.js.map +1 -0
  119. package/dist/types/guidance.d.ts +662 -1
  120. package/dist/types/guidance.d.ts.map +1 -1
  121. package/dist/types/guidance.js +10 -2
  122. package/dist/types/guidance.js.map +1 -1
  123. package/dist/types/reference-onboarding.d.ts +2 -2
  124. package/dist/utils/skills/cli-guidance.d.ts +1 -1
  125. package/dist/utils/skills/cli-guidance.d.ts.map +1 -1
  126. package/dist/utils/skills/cli-guidance.js +4 -2
  127. package/dist/utils/skills/cli-guidance.js.map +1 -1
  128. package/package.json +3 -2
  129. package/src/ui/dist/assets/{LibraryEntry-B5kPF3Ey.js → LibraryEntry-yoxzWNdQ.js} +1 -1
  130. package/src/ui/dist/assets/{main-Er_TRZTd.js → main-DlZAsDUG.js} +2 -2
  131. package/src/ui/dist/index.html +1 -1
@@ -138,7 +138,7 @@ function useAtomValueWithDelay<Value>(
138
138
  <body>
139
139
  <div class="panel">${Z3}</div>
140
140
  </body>
141
- </html>`,gte=Tn({success:xh(),authUrl:Xe().optional(),sessionId:Xe().optional(),pollSecret:Xe().optional(),error:Xe().optional(),message:Xe().optional()}),vte=Tn({success:xh(),token:Xe().optional(),refreshToken:Xe().optional(),user:Tn({id:Xe().optional(),email:Xe().optional()}).optional(),error:Xe().optional(),message:Xe().optional()}),yte="/api/auth/install-ref",_te=Tn({installRef:Xe().nullable()}),wte=async()=>{try{const t=await fetch(yte);if(!t.ok)return;const e=_te.safeParse(await t.json());return e.success?e.data.installRef??void 0:void 0}catch{return}},O9=(t="editor_gate",e)=>{const n=Ei(),[r,s]=m.useState(!1),[i,o]=m.useState(null);return{startLogin:m.useCallback(async()=>{var g;const u=globalThis.crypto.randomUUID(),d=Date.now();s(!0),o(null);const f=I_({outcome:"started",authAttemptId:u,entryPoint:t,startedAt:d,now:d});n==null||n.capture(f.event,f.properties);let h=null;try{if(h=window.open("","_blank"),!h)throw new Error("Pop-up blocked. Please allow pop-ups and try again.");try{h.document.open(),h.document.write(mte),h.document.close()}catch(S){B3.warn("Failed to render loading state in auth popup:",S)}const v=await wte(),w=await fetch(`${W3}/api/auth/google/start`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({source:"core",...v?{ref:v}:{}})}),_=gte.safeParse(await w.json());if(!_.success)throw new Error("Invalid Google login response");const x=_.data;if(!w.ok||!x.success||!x.authUrl||!x.sessionId||!x.pollSecret)throw new Error(x.error||x.message||"Failed to start Google login");if(h.closed)throw new Error("Sign-in window was closed before Google login started.");h.location.href=x.authUrl;for(let S=0;S<pte;S+=1){if(h.closed)throw new Error("Sign-in window was closed before authentication completed.");const k=await fetch(`${W3}/api/auth/google/token`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({session:x.sessionId,pollSecret:x.pollSecret})}),C=vte.safeParse(await k.json());if(!C.success)throw new Error("Invalid Google token response");const A=C.data;if(A.success&&A.token&&((g=A.user)!=null&&g.email)){const T={email:A.user.email,token:A.token,refreshToken:A.refreshToken,userId:A.user.id,...v?{installRef:v}:{}};if(e)await e(T);else if(!(await tl("/api/auth/store",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(T)})).ok)throw new Error("Signed in, but failed to store session locally.");h.close(),window.sessionStorage.setItem(Tg,"1");const I=I_({outcome:"completed",authAttemptId:u,entryPoint:t,startedAt:d,now:Date.now()});n==null||n.capture(I.event,I.properties),window.location.reload();return}if(A.error&&A.error!=="Pending")throw new Error(A.error||"Google login failed");await new Promise(T=>setTimeout(T,hte))}throw new Error("Authentication timed out. Please try again.")}catch(v){h&&!h.closed&&h.close();const w=v instanceof Error?v.message:"Failed to start login flow";B3.warn("Login failed:",w);const _=I_({outcome:"failed",authAttemptId:u,entryPoint:t,startedAt:d,now:Date.now(),failureReason:fte(w)});n==null||n.capture(_.event,_.properties),o(w),s(!1)}},[n,t,e]),isStartingLogin:r,loginError:i}},xte=Ms("useIntegrations"),bte=Tn({provider:Xe(),status:Xe(),externalUsername:Xe().nullable(),connectedAt:Xe()}),Ste=Tn({integrations:dd(bte).optional()}),kte=Tn({authUrl:Xe().min(1).optional(),error:Xe().optional()}),Ete=Tn({error:Xe().optional()}),O_=["integrations"],Cte="rivet:connect-result",Pte=t=>typeof t=="object"&&t!==null&&t.type===Cte,Ate=ft(null),q3=async()=>{const t=await tl("/api/integrations");if(!t.ok)throw new Error(`Failed to load integrations (${t.status})`);return Ste.parse(await t.json()).integrations??[]},Tte=()=>{const t=JP(),[e,n]=QT(Ate),r=uh({queryKey:O_,queryFn:q3,staleTime:1e4}),s=m.useCallback(async()=>(await t.invalidateQueries({queryKey:O_,refetchType:"none"}),t.fetchQuery({queryKey:O_,queryFn:q3})),[t]),i=m.useCallback(async l=>{const u=window.open("","_blank","width=560,height=720");if(!u)throw new Error("Popup blocked. Allow popups to connect.");n(l);try{const d=await tl(`/api/integrations/${l}/connect`,{method:"POST"}),f=kte.safeParse(await d.json().catch(()=>({}))),h=f.success?f.data:{};if(!d.ok||!h.authUrl)throw u.close(),new Error(h.error||`Could not connect ${l}`);return u.location.href=h.authUrl,await new Promise(g=>{let v=!1,w=null;const _=async(S,k=!1)=>{if(!v){v=!0,window.removeEventListener("message",x),w&&clearInterval(w);try{const A=(await s()).some(T=>T.provider===l&&T.status==="connected");g(k&&A?"connected":S)}catch{g(S)}}},x=S=>{if(Pte(S.data)&&S.data.provider===l){if(S.data.status==="error"){xte.warn(`Connect failed for ${l}:`,S.data.message),_("failed");return}_("connected")}};window.addEventListener("message",x),w=setInterval(()=>{u.closed&&_("closed",!0)},500)})}finally{n(null)}},[s,n]),o=m.useCallback(async l=>{n(l);try{const u=await tl(`/api/integrations/${l}`,{method:"DELETE"});if(!u.ok){const d=Ete.safeParse(await u.json().catch(()=>({}))),f=d.success?d.data:{};throw new Error(f.error||`Could not disconnect ${l}`)}await s()}finally{n(null)}},[s,n]);return{integrations:r.data??[],isLoading:r.isPending,error:r.error instanceof Error?r.error.message:null,pendingProvider:e,connect:i,disconnect:o,refetch:s}},Dl=({action:t,outcome:e,provider:n,entryPoint:r,durationMs:s,failureReason:i})=>({event:`visual_editor_reference_${t==="connect"?"connection":"disconnection"}_${e}`,properties:{provider:n,entry_point:r,...s!==void 0?{duration_ms:s}:{},...i?{failure_reason:i}:{}}}),up=async(t,e="GET",n)=>{if(window.location.pathname.startsWith("/rivet/library"))return Cz(t,{method:e,body:n});const r=await tl(t.replace(/^\/profile/,"/api/reference-profiles"),{method:e,headers:{"Content-Type":"application/json"},...n!==void 0?{body:JSON.stringify(n)}:{}}),s=await r.text();let i;try{i=JSON.parse(s)}catch{throw new Error(`Reference profile request failed (${r.status})`)}if(!r.ok)throw new Error(i.error??`Request failed (${r.status})`);return i},L9=()=>up("/profile"),Rte=t=>uh({queryKey:["cosmos-profile"],queryFn:L9,enabled:t}),Mte=t=>up("/profile/discoveries","POST",{url:t}),Ite=({discoveryId:t,collectionIds:e,runtime:n})=>up("/profile/import-plans","POST",{discoveryId:t,collectionIds:e,runtime:n}),Ote=t=>up("/profile","PATCH",{isEnabled:!0,runtime:t}),Lte=t=>up(`/profile/import-plans/${t.id}/imports`,"POST",{revision:t.revision,isApproved:!0}),Qw=Xe().regex(/^[1-9]\d{0,15}$/).refine(t=>Number.isSafeInteger(Number(t))),Nte=Xe().min(1).max(4096),N9=t=>{const e=()=>new Error("Use an HTTPS Cosmos profile URL such as https://www.cosmos.so/username");let n;try{n=new URL(t)}catch{throw e()}const r=n.pathname.split("/").filter(Boolean);if(n.protocol!=="https:"||n.username||n.password||n.port||!["cosmos.so","www.cosmos.so"].includes(n.hostname)||r.length!==1)throw e();let s;try{s=decodeURIComponent(r[0])}catch{throw e()}if(!/^[a-zA-Z0-9_.-]{1,100}$/.test(s)||["e","login","signup","explore","search","collections","settings","api","profile"].includes(s.toLowerCase()))throw e();return{username:s,url:`https://www.cosmos.so/${encodeURIComponent(s)}`}};Xe().max(2048).transform((t,e)=>{try{return N9(t).url}catch(n){return e.addIssue({code:xe.custom,message:n instanceof Error?n.message:"Invalid Cosmos profile URL"}),xz}});const Dte=t=>{const e=()=>new Error("Use an HTTPS Cosmos collection URL such as https://www.cosmos.so/owner/collection");let n;try{n=new URL(t)}catch{throw e()}const r=n.pathname.split("/").filter(Boolean);if(n.protocol!=="https:"||n.username||n.password||n.port||!["cosmos.so","www.cosmos.so"].includes(n.hostname)||r.length<2||r.length>3||r[0]==="e")throw e();let s;try{s=r.map(i=>decodeURIComponent(i))}catch{throw e()}if(s.some(i=>!i.length||i.length>300||/[/\\\p{Cc}]/u.test(i)))throw e();return{ownerUsername:s[0],slug:s[1],subcollectionSlug:s[2],url:`https://www.cosmos.so/${s.map(encodeURIComponent).join("/")}`}},jte=Xe().url().refine(t=>{const e=new URL(t);return e.protocol==="https:"&&e.hostname==="cdn.cosmos.so"&&!e.username&&!e.password&&!e.port}),$te=Tn({id:Qw,title:Xe().min(1).max(500),url:Xe().url().transform(t=>Dte(t).url),children:dd(Qw)}),Fte=Tn({id:Qw,url:Xe().url(),title:Xe().max(1e3),text:Xe().max(1e5),author:Xe().nullable(),owner:Xe().nullable(),sourceUrl:Xe().url().nullable(),images:dd(Tn({url:jte,representation:Zg(["image","video-cover"])})).max(100),unsupportedReason:Xe().optional()}),Vte=Tn({collection:$te,elements:dd(Fte),total:HT().int().nonnegative(),nextCursor:Nte.nullable()});wz("status",[Vte.extend({status:mE("ok")}),Tn({status:mE("error"),message:Xe(),reason:Zg(["rate_limited","provider_unavailable","collection_unavailable"]).optional(),retryAfterMs:HT().nonnegative().optional()})]);const Hte=({isOpen:t,onClose:e,onImported:n})=>{const[r,s]=m.useState(""),[i,o]=m.useState(null),[l,u]=m.useState([]),[d,f]=m.useState(""),[h,g]=m.useState(null),[v,w]=m.useState(null),[_,x]=m.useState(!1),S=m.useRef(0),k=Ei(),C=()=>{S.current+=1,s(""),o(null),u([]),f(""),g(null),w(null),x(!1)},A=()=>{k==null||k.capture("visual_editor_cosmos_modal_closed"),C(),e()},T=async O=>{O.preventDefault(),w(null);let N;try{N=N9(r.trim()).url}catch(F){w(F instanceof Error?F.message:"Invalid Cosmos profile URL");return}k==null||k.capture("visual_editor_cosmos_discovery_started");const D=++S.current;x(!0);try{const F=await Mte(N);if(D!==S.current)return;o(F),u([]),k==null||k.capture("visual_editor_cosmos_discovery_completed",{collection_count:F.collections.length})}catch(F){if(D!==S.current)return;w(F instanceof Error?F.message:"Could not find Cosmos profile"),k==null||k.capture("visual_editor_cosmos_discovery_failed")}finally{D===S.current&&x(!1)}},I=async()=>{if(!i||l.length===0||!d)return;w(null),k==null||k.capture("visual_editor_cosmos_plan_started",{collection_count:l.length,runtime:d});const O=++S.current;x(!0);try{const N=await Ite({discoveryId:i.id,collectionIds:l,runtime:d});if(O!==S.current)return;g(N),k==null||k.capture("visual_editor_cosmos_plan_completed",{collection_count:N.collectionCount,reference_count:N.referenceCount})}catch(N){if(O!==S.current)return;w(N instanceof Error?N.message:"Could not prepare import plan"),k==null||k.capture("visual_editor_cosmos_plan_failed")}finally{O===S.current&&x(!1)}},M=async()=>{if(!h||!d)return;w(null),k==null||k.capture("visual_editor_cosmos_import_started",{collection_count:h.collectionCount,reference_count:h.referenceCount});const O=++S.current;x(!0);try{if((await L9()).profile.isEnabled||await Ote(d),await Lte(h),k==null||k.capture("visual_editor_cosmos_import_completed",{reference_count:h.referenceCount}),n(),O!==S.current)return;C(),e()}catch(N){if(k==null||k.capture("visual_editor_cosmos_import_failed"),O!==S.current)return;w(N instanceof Error?N.message:"Could not start Cosmos import")}finally{O===S.current&&x(!1)}},R=O=>{u(N=>N.includes(O)?N.filter(D=>D!==O):[...N,O]),k==null||k.capture("visual_editor_cosmos_collection_toggled")};return b.jsx(uv,{open:t,onOpenChange:O=>!O&&A(),children:b.jsxs(dv,{children:[b.jsx(fv,{className:"z-max fixed inset-0 bg-black/60"}),b.jsxs(hv,{className:"z-max border-main-border bg-main font-main fixed top-1/2 left-1/2 max-h-[min(680px,calc(100vh-32px))] w-[min(440px,calc(100vw-32px))] -translate-x-1/2 -translate-y-1/2 overflow-y-auto rounded-lg border shadow-2xl outline-none",children:[b.jsxs("div",{className:"border-main-border bg-main-light flex items-center justify-between rounded-t-lg border-b px-4 py-2",children:[b.jsx(pv,{className:"text-content text-base font-medium",children:"Connect Cosmos"}),b.jsx(Qi,{onClick:A,title:"Close","aria-label":"Close",variant:"ghost",size:"icon-compact",children:b.jsx(Ob,{className:"h-4 w-4",weight:"bold"})})]}),b.jsxs("div",{className:"space-y-4 p-4",children:[b.jsx(mv,{className:"text-content-subtle text-sm",children:"Add public collections from a Cosmos profile to your design references."}),i?null:b.jsxs("form",{onSubmit:O=>void T(O),className:"space-y-4",children:[b.jsx("label",{className:"text-content block text-sm font-medium",htmlFor:"cosmos-profile-url",children:"Cosmos profile URL"}),b.jsx("input",{id:"cosmos-profile-url",type:"url",required:!0,autoFocus:!0,value:r,onChange:O=>s(O.target.value),placeholder:"https://www.cosmos.so/username",className:"border-main-border bg-main-input text-content placeholder:text-content-muted focus:border-secondary w-full rounded-md border px-3 py-2 text-sm outline-none"}),b.jsx("button",{type:"submit",disabled:_,className:"bg-secondary text-secondary-foreground hover:bg-accent rounded-md px-4 py-2 text-sm font-medium disabled:opacity-50",children:_?"Finding collections…":"Continue"})]}),i&&!h?b.jsxs("div",{className:"space-y-4",children:[b.jsxs("p",{className:"text-content text-sm font-medium",children:["Choose collections from"," ",i.profile.title||i.profile.username]}),b.jsx("div",{className:"border-main-border max-h-60 divide-y overflow-y-auto rounded-md border",children:i.collections.map(O=>b.jsxs("label",{className:"text-content hover:bg-main-light flex cursor-pointer items-center gap-3 px-3 py-2 text-sm",children:[b.jsx("input",{type:"checkbox",checked:l.includes(O.id),disabled:_,onChange:()=>R(O.id)}),b.jsx("span",{className:"min-w-0 flex-1 truncate",children:O.title}),b.jsx("span",{className:"text-content-muted text-xs",children:O.total??"—"})]},O.id))}),i.collections.length===0?b.jsx("p",{className:"text-content-muted text-sm",children:"No public collections found for this profile."}):null,b.jsxs("label",{className:"text-content flex items-center justify-between gap-3 text-sm",children:["Analysis runtime",b.jsxs("select",{value:d,disabled:_,onChange:O=>{const N=O.target.value;f(N),k==null||k.capture("visual_editor_cosmos_runtime_selected",{runtime:N})},className:"border-main-border bg-main-input rounded-md border px-2 py-1.5",children:[b.jsx("option",{value:"",disabled:!0,children:"Select a runtime"}),b.jsx("option",{value:"codex",children:"Codex"}),b.jsx("option",{value:"claude",children:"Claude"}),b.jsx("option",{value:"cursor",children:"Cursor"})]})]}),b.jsx("button",{type:"button",onClick:()=>void I(),disabled:_||l.length===0||!d,className:"bg-secondary text-secondary-foreground hover:bg-accent rounded-md px-4 py-2 text-sm font-medium disabled:opacity-50",children:_?"Preparing plan…":"Review import plan"}),b.jsx("button",{type:"button",onClick:()=>{k==null||k.capture("visual_editor_cosmos_profile_changed"),C()},disabled:_,className:"text-content-muted hover:text-content ml-3 text-sm",children:"Use another profile"})]}):null,h?b.jsxs("div",{className:"space-y-4 text-sm",children:[b.jsxs("p",{className:"text-content",children:[h.collectionCount," ",h.collectionCount===1?"collection":"collections"," ·"," ",h.referenceCount," ",h.referenceCount===1?"reference":"references"," ·"," ",h.imageCount," ",h.imageCount===1?"image":"images"]}),b.jsx("p",{className:"text-content-subtle",children:h.scopeDisclosure}),b.jsx("p",{className:"text-content-subtle",children:h.usageDisclosure}),b.jsxs("p",{className:"text-content-muted text-xs",children:[h.reusableCount," reusable · ",h.unsupportedCount," ","unsupported · runtime: ",d]}),b.jsx("button",{type:"button",onClick:()=>void M(),disabled:_,className:"bg-secondary text-secondary-foreground hover:bg-accent rounded-md px-4 py-2 text-sm font-medium disabled:opacity-50",children:_?"Starting import…":"Approve and import"}),b.jsx("button",{type:"button",onClick:()=>{k==null||k.capture("visual_editor_cosmos_plan_revised"),g(null)},disabled:_,className:"text-content-muted hover:text-content ml-3 text-sm",children:"Change selection"})]}):null,v?b.jsx("p",{role:"alert",className:"text-sm text-red-300",children:v}):null]})]})]})})},G3=Ms("ConnectorsModal"),zte=[{provider:"x",name:"X",iconClassName:"text-content",icon:b.jsx(nh,{provider:"x"})},{provider:"pinterest",name:"Pinterest",iconClassName:"text-[#e60023]",icon:b.jsx(nh,{provider:"pinterest"})},{provider:"arena",name:"Are.na",iconClassName:"text-content",icon:b.jsx(nh,{provider:"arena"})}],Ute={name:"Cosmos",iconClassName:"text-content",icon:b.jsx(nh,{provider:"cosmos"})},K3=({meta:t,status:e,actionLabel:n,buttonLabel:r,isDisabled:s,isHighlighted:i,onAction:o})=>b.jsxs("li",{className:`flex min-h-[64px] items-center gap-3 py-3 ${i?"ring-secondary -mx-2 rounded-md px-2 ring-2":""}`,children:[b.jsx("span",{className:`grid h-7 w-7 flex-none place-items-center ${t.iconClassName}`,"aria-hidden":"true",children:t.icon}),b.jsxs("div",{className:"min-w-0 flex-1",children:[b.jsx("span",{className:"text-content block text-sm font-medium",children:t.name}),b.jsx("span",{className:"text-content-muted block truncate text-xs",children:e})]}),b.jsx("button",{type:"button","aria-label":n,onClick:o,disabled:s,className:"active-push bg-main-input text-content hover:bg-main-input/80 inline-flex min-h-8 w-24 flex-none items-center justify-center rounded-md px-3 text-xs font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-50",children:r})]}),Jw=({isOpen:t,onClose:e,context:n="menu",highlightProvider:r=null})=>{var I;const{integrations:s,isLoading:i,error:o,pendingProvider:l,connect:u,disconnect:d}=Tte(),f=Ei(),[h,g]=m.useState(null),[v,w]=m.useState(!1),_=Rte(t),x=M=>s.find(R=>R.provider===M),S=m.useCallback(M=>{const R=Date.now(),O=Dl({action:"connect",outcome:"started",provider:M,entryPoint:n});f==null||f.capture(O.event,O.properties),u(M).then(N=>{const D=Date.now()-R;if(N==="connected"){const K=Dl({action:"connect",outcome:"completed",provider:M,entryPoint:n,durationMs:D});f==null||f.capture(K.event,K.properties);return}const F=Dl({action:"connect",outcome:"failed",provider:M,entryPoint:n,durationMs:D,failureReason:N==="closed"?"popup_closed":"provider_failed"});f==null||f.capture(F.event,F.properties)}).catch(N=>{const D=N instanceof Error?N.message:"Could not connect.",F=Dl({action:"connect",outcome:"failed",provider:M,entryPoint:n,durationMs:Date.now()-R,failureReason:D.includes("Popup blocked")?"popup_blocked":"request_failed"});f==null||f.capture(F.event,F.properties),G3.warn(`Connect error for ${M}:`,D),Mt.error(D)})},[u,n,f]),k=m.useCallback(M=>{const R=Date.now(),O=Dl({action:"disconnect",outcome:"started",provider:M,entryPoint:n});f==null||f.capture(O.event,O.properties),d(M).then(()=>{const N=Dl({action:"disconnect",outcome:"completed",provider:M,entryPoint:n,durationMs:Date.now()-R});f==null||f.capture(N.event,N.properties)}).catch(N=>{const D=N instanceof Error?N.message:"Could not disconnect.",F=Dl({action:"disconnect",outcome:"failed",provider:M,entryPoint:n,durationMs:Date.now()-R,failureReason:"request_failed"});f==null||f.capture(F.event,F.properties),G3.warn(`Disconnect error for ${M}:`,D),Mt.error(D)})},[n,d,f]),C=n==="onboarding",A=(I=_.data)==null?void 0:I.sources.some(M=>M.provider==="cosmos");let T=A?"Connected":"Not connected";return _.isError&&(T="Status unavailable"),_.isPending&&(T="Checking status…"),b.jsxs(b.Fragment,{children:[b.jsx(uv,{open:t,onOpenChange:M=>!M&&e(),children:b.jsxs(dv,{children:[b.jsx(fv,{className:"z-max fixed inset-0 bg-black/40"}),b.jsx(hv,{ref:g,className:"z-max border-main-border bg-main font-main fixed top-1/2 left-1/2 w-[min(440px,calc(100vw-32px))] -translate-x-1/2 -translate-y-1/2 rounded-lg border shadow-2xl outline-none",children:b.jsxs(AO,{value:h,children:[b.jsxs("div",{className:"border-main-border bg-main-light flex items-center justify-between rounded-t-lg border-b px-4 py-2",children:[b.jsx(pv,{className:"text-content text-base font-medium",children:"Connect design references"}),b.jsx(Qi,{onClick:e,title:"Close","aria-label":"Close",variant:"ghost",size:"icon-compact",children:b.jsx(Ob,{className:"h-4 w-4",weight:"bold"})})]}),b.jsxs("div",{className:"flex flex-col gap-4 p-4",children:[b.jsx(mv,{className:"text-content-subtle text-sm",children:"Connect your references to add them to your Rivet library. Rivet can use them to inspire new design directions."}),o?b.jsx("p",{className:"rounded-lg bg-red-500/10 px-4 py-3 text-[13px] font-medium text-red-300",children:o}):null,b.jsxs("ul",{className:"divide-main-border divide-y","aria-label":"Design reference services",children:[zte.map(M=>{const R=x(M.provider),O=(R==null?void 0:R.status)==="connected",N=R==null?void 0:R.externalUsername;let D=O?`Connected${N?` as @${N}`:""}`:"Not connected";i&&(D="Checking status…");const F=l===M.provider,K=O?"Disconnect":"Connect";return b.jsx(K3,{meta:M,status:D,actionLabel:`${K} ${M.name}`,buttonLabel:F?`${K}ing…`:K,isDisabled:i||F,isHighlighted:r===M.provider,onAction:()=>O?k(M.provider):S(M.provider)},M.provider)}),b.jsx(K3,{meta:Ute,status:T,actionLabel:A?"Add Cosmos profile":"Connect Cosmos",buttonLabel:A?"Add profile":"Connect",isDisabled:!1,isHighlighted:!1,onAction:()=>{f==null||f.capture("visual_editor_cosmos_modal_opened"),w(!0)}})]}),C?b.jsxs("div",{className:"flex items-center justify-between gap-4",children:[b.jsx("p",{className:"text-content-subtle text-xs",children:"You can always do this later from the account menu."}),b.jsx("button",{type:"button",onClick:e,className:"active-push bg-secondary text-secondary-foreground hover:bg-accent flex-none rounded-lg px-3.5 py-2 text-[13px] font-medium transition-colors",children:"Skip for now"})]}):null]})]})})]})}),b.jsx(Hte,{isOpen:v,onClose:()=>w(!1),onImported:()=>{_.refetch()}})]})},Y3=({className:t=""})=>b.jsx("span",{"aria-hidden":"true",className:`rivet-skeleton block rounded ${t}`.trim()}),Bte=Ms("SupportTicketModal"),X3=5e3,L_="feedback",Zte=Tn({error:Xe().optional(),details:_z([Xe(),Tn({formErrors:dd(Xe()).optional(),fieldErrors:zT(Xe(),dd(Xe()).optional()).optional()})]).optional()}),Wte=t=>{var r;if(!t)return null;const e=(r=t.formErrors)==null?void 0:r[0];if(e)return e;const n=t.fieldErrors??{};for(const s of Object.values(n)){const i=s==null?void 0:s[0];if(i)return i}return null},qte=async t=>{let e;try{const n=Zte.safeParse(await t.json());e=n.success?n.data:void 0}catch{e=void 0}if(t.status===400){if(typeof(e==null?void 0:e.details)=="string"&&e.details.trim())return e.details;if(typeof(e==null?void 0:e.details)=="object"&&e.details!==null){const n=Wte(e.details);if(n)return n}return"Please check your feedback and try again."}return t.status>=500?typeof(e==null?void 0:e.details)=="string"&&e.details.trim()?e.details:"Could not send feedback right now. Please try again later.":typeof(e==null?void 0:e.error)=="string"&&e.error.trim()?e.error:`HTTP ${t.status}`},Gte=({isOpen:t,onClose:e,contactEmail:n})=>{const r=Ei(),[s,i]=m.useState(""),[o,l]=m.useState(!1),[u,d]=m.useState(null),f=m.useCallback(()=>{i("")},[]),h=m.useCallback(()=>{o||(f(),e())},[o,e,f]),g=m.useCallback(async()=>{const x=s.trim();if(!(!x||o)){l(!0);try{const S=typeof(r==null?void 0:r.get_session_id)=="function"?r.get_session_id():void 0,k=typeof(r==null?void 0:r.get_distinct_id)=="function"?r.get_distinct_id():void 0,C=n==null?void 0:n.trim(),A=await tl("/api/support/tickets",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:L_,message:x,contactEmail:C||void 0,metadata:{posthogSessionId:S??void 0,posthogDistinctId:k??void 0,appVersion:"0.21.2",appEnvironment:"production",pageUrl:window.location.href,userAgent:navigator.userAgent,submittedAt:new Date().toISOString()}})});if(!A.ok){const T=await qte(A);throw new Error(T)}r==null||r.capture("support_ticket_submitted",{ticket_type:L_,has_posthog_session_id:!!S}),Mt.success("Feedback sent",{description:"Thanks for sharing this."}),f(),e()}catch(S){const k=S instanceof Error?S.message:"Failed to send message";r==null||r.capture("support_ticket_submit_failed",{ticket_type:L_,error:k}),Bte.error("Failed to submit support ticket:",k),Mt.error("Could not send feedback",{description:k})}finally{l(!1)}}},[n,o,s,e,r,f]),v=m.useCallback(x=>{x.key==="Enter"&&(x.metaKey||x.ctrlKey)&&(x.preventDefault(),g())},[g]),w=X3-s.length,_=o||s.trim().length===0;return b.jsx(uv,{open:t,onOpenChange:x=>!x&&h(),children:b.jsxs(dv,{children:[b.jsx(fv,{className:"z-max fixed inset-0 bg-black/40"}),b.jsx(hv,{ref:d,className:"z-max border-main-border bg-main font-main fixed top-1/2 left-1/2 w-[440px] -translate-x-1/2 -translate-y-1/2 rounded-lg border shadow-2xl outline-none",children:b.jsxs(AO,{value:u,children:[b.jsxs("div",{className:"border-main-border bg-main-light flex items-center justify-between rounded-t-lg border-b px-4 py-2",children:[b.jsx(pv,{className:"text-content text-base font-medium",children:"Send feedback"}),b.jsx(Qi,{onClick:h,disabled:o,title:"Close","aria-label":"Close",variant:"ghost",size:"icon-compact",children:b.jsx(Ob,{className:"h-4 w-4",weight:"bold"})})]}),b.jsxs("div",{className:"flex flex-col gap-3 p-4",children:[b.jsx(mv,{className:"text-content-subtle text-sm",children:"Tell us what happened or what we can improve."}),b.jsxs("div",{className:"bg-main-input rounded-lg outline outline-1 outline-transparent transition-[outline-color] focus-within:outline-white/20",children:[b.jsx("textarea",{id:"support-ticket-message","aria-label":"Your feedback",value:s,onChange:x=>i(x.target.value),onKeyDown:v,maxLength:X3,rows:6,disabled:o,placeholder:"What happened?",className:"text-content placeholder-content-subtle max-h-64 w-full resize-none overflow-y-auto bg-transparent pt-3 pr-3 pb-1 pl-3 text-sm focus:outline-none disabled:opacity-50"}),b.jsxs("div",{className:"flex items-center justify-between px-3 pt-1 pb-3",children:[b.jsx("span",{className:"text-content-subtle text-xs",children:"Context details are included automatically."}),b.jsxs("div",{className:"flex items-center gap-2",children:[w<=500&&b.jsx("span",{className:"text-content-subtle text-xs",children:w}),b.jsx(Qi,{onClick:g,disabled:_,title:"Send feedback",shortcut:"⌘↵","aria-label":"Send feedback",size:"icon-compact",children:o?b.jsx(ev,{className:"h-5 w-5 animate-spin",weight:"bold"}):b.jsx(hK,{className:"h-5 w-5",weight:"bold"})})]})]})]})]})]})})]})})},Kte=Ms("ProfileAvatar"),D9=(t,e)=>{const n=(t??"").trim();if(n)return n.split(/\s+/).filter(Boolean)[0]??"";const s=((e??"").split("@")[0]??"").split(/[._\-+]/).filter(Boolean)[0]??"";return s?s[0].toUpperCase()+s.slice(1):""},Yte=(t,e)=>D9(t,e).charAt(0).toUpperCase(),Xte=({className:t="",side:e="bottom",align:n="end"})=>{var K,B,G;const r=dte(),s=((K=r.data)==null?void 0:K.name)??null,i=((B=r.data)==null?void 0:B.email)??null,o=((G=r.data)==null?void 0:G.isAuthenticated)===!0,l=Ei(),{startLogin:u,isStartingLogin:d,loginError:f}=O9("account_menu"),[h,g]=m.useState(!1),[v,w]=m.useState(!1),[_,x]=m.useState(!1),[S,k]=m.useState(!1),{containerRef:C,onKeyDown:A,onCloseAutoFocus:T}=r9({onDismiss:()=>F(!1)}),I=Yte(s,i);if(r.isPending)return b.jsxs("span",{"data-testid":"profile-avatar-skeleton","aria-hidden":"true",className:`flex shrink-0 items-center gap-2 ${t}`.trim(),children:[b.jsx(Y3,{className:"h-8 w-8 rounded-full"}),b.jsx(Y3,{className:"h-3.5 w-16"})]});const M=D9(s,i),R=(s==null?void 0:s.trim())||null,O=(i==null?void 0:i.trim())||null,N=async()=>{k(!0);try{const H=await tl("/api/auth/logout",{method:"POST",credentials:"same-origin"});if(!H.ok)throw new Error(`Logout failed: ${H.status}`);window.location.pathname.startsWith("/rivet/library")&&BT()}catch(H){Kte.warn("Logout request failed",H),Mt.error("Could not log out. Please try again."),k(!1);return}window.location.reload()};let D="Log in";o&&(D=M||"Account"),r.error&&!r.data&&(D="Account unavailable");const F=H=>{g(H),l==null||l.capture(`visual_editor_account_menu_${H?"opened":"closed"}`,{is_authenticated:o})};return b.jsxs(b.Fragment,{children:[b.jsxs(i4,{open:h,onOpenChange:F,children:[b.jsx(o4,{asChild:!0,children:b.jsxs("button",{type:"button","aria-label":"Account","data-rivet-private":!0,className:`ph-no-capture text-content-muted hover:text-content flex shrink-0 items-center gap-2 transition-colors select-none ${t}`,children:[b.jsx("span",{className:"border-main-border bg-main-input flex h-8 w-8 items-center justify-center rounded-full border text-xs leading-none font-semibold",children:I||b.jsx(CK,{className:"h-4 w-4",weight:"bold"})}),b.jsx("span",{className:"max-w-[8rem] truncate text-sm font-medium",children:D})]})}),b.jsx(a4,{children:b.jsxs(l4,{"data-rivet-private":!0,ref:C,onKeyDown:A,onCloseAutoFocus:T,role:"menu",className:"ph-no-capture bg-popover shadow-surface-4 z-[60] min-w-[180px] rounded-lg p-1",side:e,sideOffset:6,align:n,children:[R||O?b.jsxs("div",{className:"border-main-border border-b px-3 py-2",children:[R?b.jsx("div",{className:"text-content truncate text-sm font-medium",children:R}):null,O?b.jsx("div",{className:"text-content-muted truncate text-xs",children:O}):null]}):null,b.jsxs("button",{type:"button",role:"menuitem","data-menu-item":!0,onClick:()=>{F(!1),w(!0)},disabled:!o,className:"text-content hover:bg-hover focus-visible:bg-hover mt-1 flex w-full items-center gap-2 rounded-md px-3 py-1.5 text-sm transition-colors focus:outline-none disabled:cursor-not-allowed disabled:opacity-50",children:[b.jsx(sI,{className:"h-4 w-4",weight:"bold"}),"Connect design references"]}),b.jsxs("button",{type:"button",role:"menuitem","data-menu-item":!0,onClick:()=>{F(!1),x(!0)},className:"text-content hover:bg-hover focus-visible:bg-hover mt-1 flex w-full items-center gap-2 rounded-md px-3 py-1.5 text-sm transition-colors focus:outline-none",children:[b.jsx(gK,{className:"h-4 w-4",weight:"bold"}),"Share feedback"]}),o?b.jsxs("button",{type:"button",role:"menuitem","data-menu-item":!0,onClick:N,disabled:S,className:"text-content hover:bg-hover focus-visible:bg-hover mt-1 flex w-full items-center gap-2 rounded-md px-3 py-1.5 text-sm transition-colors focus:outline-none disabled:cursor-not-allowed disabled:opacity-50",children:[b.jsx(kK,{className:"h-4 w-4",weight:"bold"}),S?"Logging out…":"Log out"]}):null,!o&&!r.error?b.jsxs("button",{type:"button",role:"menuitem","data-menu-item":!0,onClick:()=>{u()},disabled:d,className:"text-content hover:bg-hover focus-visible:bg-hover mt-1 flex w-full items-center gap-2 rounded-md px-3 py-1.5 text-sm focus:outline-none disabled:opacity-50",children:[b.jsx(SK,{className:"h-4 w-4",weight:"bold"}),d?"Logging in…":"Log in"]}):null,r.error?b.jsx("button",{type:"button",role:"menuitem","data-menu-item":!0,onClick:()=>{r.refetch()},className:"text-content mt-1 px-3 py-1.5 text-sm",children:"Retry account"}):null,f?b.jsx("p",{role:"alert",className:"max-w-64 px-3 py-2 text-sm text-red-300",children:f}):null]})})]}),v?b.jsx(Jw,{isOpen:!0,onClose:()=>w(!1)}):null,b.jsx(Gte,{isOpen:_,onClose:()=>x(!1),contactEmail:i??void 0})]})},Qte=({onClose:t,libraryOrigin:e})=>b.jsxs("div",{className:"bg-main font-main scrollbar-hide relative flex h-full w-full cursor-auto flex-col overflow-hidden shadow-2xl","data-cy":"element-inspector",children:[b.jsx(cte,{onClose:t,libraryOrigin:e}),b.jsx("div",{className:"flex min-h-0 flex-1 flex-col",children:b.jsx(Hee,{})}),b.jsx("div",{className:"border-main-border bg-main-light flex flex-shrink-0 items-center border-t px-2.5 py-2.5",children:b.jsx(Xte,{side:"top",align:"start"})})]});async function Jte(t,e){const{delaysMs:n,shouldRetry:r,onRetry:s}=e;for(let i=1;;i++)try{return await t(i)}catch(o){const l=n[i-1];if(l===void 0||r&&!r(o))throw o;s==null||s(o,i,l),await new Promise(u=>setTimeout(u,l))}}const Q3=Ms("useServerConfig"),j9=[250,500,1e3,2e3,4e3],J3=j9.length+1,ene=async()=>{var n;const t=await fetch("/api/health");if(!t.ok)throw new Error(`Failed to fetch config: ${t.status}`);const e=await t.json();if(!e.framework)throw new Error("Server did not return framework information");return{userPort:((n=e.ports)==null?void 0:n.userDevServer)||3e3,framework:e.framework}},tne=()=>{const[t,e]=m.useState(null),[n,r]=m.useState(!0),[s,i]=m.useState(null),o=m.useCallback(async()=>{try{r(!0),i(null);const l=await Jte(ene,{delaysMs:j9,onRetry:(u,d,f)=>{Q3.warn(`Server config fetch failed (attempt ${d}); retrying in ${f}ms`,u)}});return e(l),l}catch(l){const u=l instanceof Error?l.message:"Failed to fetch server config";throw i(u),Q3.warn("Error fetching server config:",l),l}finally{r(!1)}},[]);return{config:t,fetchConfig:o,isLoading:n,error:s}},nne="#1C1C20",So=[118,118,124],eP=.85,rne=3,sne=.15,Y0=36,ine=4.4,one=.7,ane=3.5,lne=.8,tP=9,cne=11,une=[1.35,1.12,.95,.85],dne=[0,1.1,2.3,3.1],fne=[0,.35,.16,.13],hne=[.9,.5,.4,.35],jl=3,N_=[[{x1:.1,y1:.08,x2:.9,y2:.92,level:0},{x1:.14,y1:.13,x2:.86,y2:.23,level:1},{x1:.14,y1:.28,x2:.3,y2:.87,level:1},{x1:.34,y1:.28,x2:.86,y2:.87,level:1},{x1:.165,y1:.155,x2:.225,y2:.205,level:2},{x1:.7,y1:.155,x2:.755,y2:.205,level:2},{x1:.775,y1:.155,x2:.83,y2:.205,level:2},{x1:.165,y1:.32,x2:.275,y2:.375,level:2},{x1:.165,y1:.415,x2:.275,y2:.47,level:2},{x1:.165,y1:.51,x2:.275,y2:.565,level:2},{x1:.37,y1:.32,x2:.585,y2:.56,level:2},{x1:.615,y1:.32,x2:.83,y2:.56,level:2},{x1:.37,y1:.61,x2:.83,y2:.83,level:2},{hline:!0,x1:.39,x2:.81,y:.685,level:3},{hline:!0,x1:.39,x2:.75,y:.755,level:3}],[{x1:.1,y1:.08,x2:.9,y2:.92,level:0},{x1:.16,y1:.17,x2:.52,y2:.45,level:1},{x1:.58,y1:.17,x2:.685,y2:.29,level:1},{x1:.715,y1:.17,x2:.84,y2:.29,level:1},{x1:.58,y1:.33,x2:.685,y2:.45,level:1},{x1:.715,y1:.33,x2:.84,y2:.45,level:1},{x1:.16,y1:.55,x2:.84,y2:.85,level:1},{x1:.19,y1:.21,x2:.36,y2:.33,level:2},{hline:!0,x1:.19,x2:.48,y:.37,level:3},{hline:!0,x1:.19,x2:.42,y:.42,level:3},{x1:.19,y1:.6,x2:.49,y2:.8,level:2},{hline:!0,x1:.53,x2:.8,y:.63,level:3},{hline:!0,x1:.53,x2:.76,y:.7,level:3},{hline:!0,x1:.53,x2:.79,y:.77,level:3}],[{x1:.1,y1:.08,x2:.9,y2:.92,level:0},{x1:.14,y1:.13,x2:.86,y2:.22,level:1},{x1:.14,y1:.28,x2:.36,y2:.87,level:1},{x1:.39,y1:.28,x2:.61,y2:.87,level:1},{x1:.64,y1:.28,x2:.86,y2:.87,level:1},{x1:.165,y1:.15,x2:.225,y2:.2,level:2},{x1:.165,y1:.32,x2:.335,y2:.52,level:2},{x1:.415,y1:.32,x2:.585,y2:.52,level:2},{x1:.665,y1:.32,x2:.835,y2:.52,level:2},{hline:!0,x1:.165,x2:.335,y:.6,level:3},{hline:!0,x1:.165,x2:.3,y:.67,level:3},{hline:!0,x1:.415,x2:.585,y:.6,level:3},{hline:!0,x1:.415,x2:.55,y:.67,level:3},{hline:!0,x1:.665,x2:.835,y:.6,level:3},{hline:!0,x1:.665,x2:.8,y:.67,level:3}],[{x1:.1,y1:.08,x2:.9,y2:.92,level:0},{x1:.3,y1:.22,x2:.7,y2:.74,level:1},{x1:.34,y1:.27,x2:.55,y2:.34,level:2},{hline:!0,x1:.36,x2:.64,y:.42,level:3},{hline:!0,x1:.36,x2:.6,y:.49,level:3},{hline:!0,x1:.36,x2:.62,y:.56,level:3},{x1:.5,y1:.63,x2:.575,y2:.69,level:2},{x1:.595,y1:.63,x2:.66,y2:.69,level:2}]],X0=t=>{let e=t|0;return e=Math.imul(e^e>>>16,73244475),e=Math.imul(e^e>>>16,73244475),e^=e>>>16,(e>>>0)/4294967296},km=t=>{const e=Math.min(1,Math.max(0,t));return e*e*(3-2*e)},$l=(t,e)=>(Math.round(t/e-.5)+.5)*e,pne=Math.sin(Math.PI/3),nP=(t,e,n,r,s)=>{if(t.beginPath(),e===0)t.arc(n,r,s,0,Math.PI*2);else if(e===1){const i=s*pne;t.moveTo(n,r-s),t.lineTo(n+i,r+s/2),t.lineTo(n-i,r+s/2),t.closePath()}else{const i=s*.85;t.rect(n-i,r-i,i*2,i*2)}t.fill()},mne=(t,e,n)=>{let r;if(n.hline){const s=Math.max(n.x1-t,t-n.x2,0),i=Math.abs(e-n.y1);r=Math.hypot(s,i)-tP}else{const s=Math.max(n.x1-t,t-n.x2,0),i=Math.max(n.y1-e,e-n.y2,0);s===0&&i===0?r=-Math.min(t-n.x1,n.x2-t,e-n.y1,n.y2-e):r=Math.hypot(s,i),r=Math.abs(r)-tP}return km(.5-r/(2*cne))},$9=({className:t="",trackGlobalLoaderCount:e=!0})=>{const n=gt(d9),r=m.useRef(null),s=m.useCallback(i=>{var N;if((N=r.current)==null||N.call(r),r.current=null,!i)return;const o=i.getContext("2d");if(!o)return;e&&n(D=>D+1);const l=window.matchMedia("(prefers-reduced-motion: reduce)").matches;let u=[],d=0,f=0,h=Y0,g=Y0,v=null,w=null,_=0,x=-1;const S=new Array(33),k=D=>{const F=Math.round(D*32);let K=S[F];if(!K){const B=F/32,G=Math.round(So[0]+(255-So[0])*B),H=Math.round(So[1]+(255-So[1])*B),Y=Math.round(So[2]+(255-So[2])*B);K=`rgba(${G}, ${H}, ${Y}, ${eP})`,S[F]=K}return K},C=D=>{const F=1-.35*D,K=Math.round(So[0]*F),B=Math.round(So[1]*F),G=Math.round(So[2]*F);return`rgba(${K}, ${B}, ${G}, ${eP})`},A=D=>{let F=Math.floor(Math.random()*N_.length);F===x&&(F=(F+1)%N_.length),x=F;const K=[0,0,0,0],B=N_[F].map((j,Q)=>{const oe=j.level,ne=K[oe]++,se=dne[oe]+ne*fne[oe],de=hne[oe]+X0(F*131+Q*17+5)*.2;if(j.hline){const ae=$l((j.y??0)*f,g);return{hline:!0,x1:$l(j.x1*d,h),x2:$l(j.x2*d,h),y1:ae,y2:ae,level:oe,start:se,dur:de}}const ve=$l(j.x1*d,h),ue=$l((j.y1??0)*f,g);return{hline:!1,x1:ve,y1:ue,x2:Math.max($l(j.x2*d,h),ve+h),y2:Math.max($l((j.y2??0)*f,g),ue+g),level:oe,start:se,dur:de}}),G=B.reduce((j,Q)=>Math.max(j,Q.start+Q.dur),0),H=u.length,Y=new Float32Array(H*jl),U=new Int16Array(H*jl).fill(-1),J=new Uint8Array(H),Z=B[0];for(let j=0;j<H;j++){const Q=u[j];Q.x>Z.x1&&Q.x<Z.x2&&Q.y>Z.y1&&Q.y<Z.y2&&(J[j]=1);const oe=j*jl;for(let ne=0;ne<B.length;ne++){const se=mne(Q.x,Q.y,B[ne]);if(se<=.02)continue;let de=oe;for(let ve=oe;ve<oe+jl;ve++){if(U[ve]===-1){de=ve;break}Y[ve]<Y[de]&&(de=ve)}(U[de]===-1||se>Y[de])&&(Y[de]=se,U[de]=ne)}}return{startT:D,buildEnd:G,els:B,frame:Z,cellQ:Y,cellEl:U,inFrame:J}},T=()=>{const D=i.getBoundingClientRect();d=Math.max(1,D.width),f=Math.max(1,D.height);const F=Math.min(2,window.devicePixelRatio||1);i.width=Math.round(d*F),i.height=Math.round(f*F),o.setTransform(F,0,0,F,0,0);const K=Math.max(8,Math.round(d/Y0)),B=Math.max(6,Math.round(f/Y0));h=d/K,g=f/B,u=[];for(let G=0;G<B;G++){const H=B>1?G/(B-1):.5,Y=ine*(1+one*.4*(H*2-1));for(let U=0;U<K;U++){const J=G*8191+U*131+1,Z={x:(U+.5)*h,y:(G+.5)*g,size:Y,seed:J,phase:X0(J),kind:0};Z.kind=Math.floor(X0(J*97)*3),u.push(Z)}}w=null,v=null},I=new Float32Array(32),M=D=>{o.fillStyle=nne,o.fillRect(0,0,d,f),v||(v=A(D+.2)),D>=v.startT+v.buildEnd+ane&&(w=v,_=D,v=A(D+.2));let F=0;w&&(F=1-km((D-_)/lne),F<=0&&(w=null));const K=v;for(let Z=0;Z<K.els.length;Z++){const j=K.els[Z];I[Z]=km(Math.min(1,Math.max(0,(D-K.startT-j.start)/j.dur)))}const B=I[0],G=C(0),H=C(B),Y=F>0?C(F):G,U=F>0?C(Math.max(B,F)):H,J=u.length;for(let Z=0;Z<J;Z++){const j=u[Z];let Q=0,oe=0;const ne=Z*jl;for(let We=ne;We<ne+jl;We++){const Ee=K.cellEl[We];if(Ee<0)break;const pt=K.cellQ[We]*I[Ee];pt>Q&&(Q=pt,oe=K.els[Ee].level)}if(w)for(let We=ne;We<ne+jl;We++){const Ee=w.cellEl[We];if(Ee<0)break;const pt=w.cellQ[We]*F;pt>Q&&(Q=pt,oe=w.els[Ee].level)}const se=D/rne+j.phase,de=Math.floor(se),ve=se-de,ue=km(Math.min(ve,1-ve)/sne),ae=Math.floor(X0(j.seed*97+de*7919)*3);ae!==j.kind&&Q<.02&&ue<.05&&(j.kind=ae);const Oe=Math.max(ue*(1-Q),Q);if(!(Oe<.01))if(Q<.02){const We=K.inFrame[Z]===1,Ee=w?w.inFrame[Z]===1:!1;We?o.fillStyle=Ee?U:H:o.fillStyle=Ee?Y:G;const pt=Math.max(We?B:0,Ee?F:0);nP(o,j.kind,j.x,j.y,j.size*Oe*(1-.2*pt))}else{o.fillStyle=k(Q);const We=1+(une[oe]-1)*Q;nP(o,j.kind,j.x,j.y,j.size*Oe*We)}}};T();let R=0;if(l)v=A(-100),M(0);else{const D=performance.now(),F=K=>{M((K-D)/1e3),R=requestAnimationFrame(F)};R=requestAnimationFrame(F)}const O=new ResizeObserver(()=>{T(),l&&(v=A(-100),M(0))});O.observe(i),r.current=()=>{cancelAnimationFrame(R),O.disconnect(),e&&n(D=>D-1)}},[e,n]);return b.jsx("canvas",{ref:s,"aria-hidden":"true",className:`h-full w-full ${t}`.trim()})},gne=async(t=null)=>{if(t)return vne(t);let e;try{e=await fetch("/api/mcp/status")}catch{return{isOk:!1,unavailableReason:"rivet_unreachable",upstreamStatus:null}}if(e.status===404||!(e.headers.get("content-type")??"").toLowerCase().includes("application/json"))return Q0();if(!e.ok)return{isOk:!1,unavailableReason:"rivet_unreachable",upstreamStatus:null};let r;try{r=await e.json()}catch{return Q0()}const s=r.devServerHealth;return s?s.ownership==="none"?{isOk:!1,unavailableReason:"upstream_unreachable",upstreamStatus:null}:s.isReachable===!0?{isOk:!0,unavailableReason:"upstream_unreachable",upstreamStatus:null}:{isOk:!1,unavailableReason:s.reason==="rivet_unreachable"?"rivet_unreachable":"upstream_unreachable",upstreamStatus:null}:Q0()},F9=async t=>{try{const e=await fetch(t);return{isOk:e.status!==502&&e.status!==503,unavailableReason:"upstream_unreachable",upstreamStatus:e.status}}catch{return{isOk:!1,unavailableReason:"rivet_unreachable",upstreamStatus:null}}},vne=t=>F9(t),Q0=()=>F9("/"),D_=Ms("usePreviewUpstreamHealth"),yne=500,_ne=4e3,wne=15e3,xne=3,bne=(t,e={})=>{const n=m.useRef(null),r=m.useRef(null),s=e.probeMsWhileDown??yne,i=e.probeMsWhileUp??_ne,o=e.firstUnreachableCaptureAfterMs??wne,l=e.rerunProbeImmediatelyOnVersion,u=e.probePath??null,d=e.skip??!1,f=m.useRef(e.onPersistentUpstreamServerErrors);f.current=e.onPersistentUpstreamServerErrors;const[h,g]=m.useState(t==="static"),[v,w]=m.useState(0),[_,x]=m.useState(null),[S,k]=m.useState(0),[C,A]=m.useState(!1),[T,I]=m.useState(!1),[M,R]=m.useState(t==="static"?null:"upstream_unreachable");return m.useEffect(()=>{if(t==="static"){g(!0),x(null),k(0),A(!1),I(!0),R(null);return}if(d){g(!1),x(null),k(0),A(!1),I(!0),R("upstream_unreachable"),n.current=null;return}let O=!0;const N=Date.now();x(N),k(0),A(!1),g(!1),I(!1),R("upstream_unreachable");const D={current:!1},F={current:!1},K={current:!1},B={current:null},G={current:!1},H={current:!1},Y={current:0},U={current:!1},J={current:null};let Z=null;const j=()=>{K.current||(K.current=!0,O&&I(!0))},Q=()=>{Z!==null&&(clearTimeout(Z),Z=null)},oe=(se,de)=>{Q(),Z=setTimeout(de,se)},ne=async()=>{var pt;if(!O)return;k(Ot=>Ot+1);const{isOk:se,unavailableReason:de,upstreamStatus:ve}=await gne(u);if(!O)return;j(),J.current=ve;const ue=se&&ve!==null&&ve>=500;ue&&H.current?Y.current+=1:se&&!ue&&(Y.current=0);const ae=Y.current>=xne;if(ae&&!U.current&&ve!==null&&(U.current=!0,Ce==null||Ce.capture("preview_upstream_error_responses",{framework:t,upstream_status:ve,consecutive_count:Y.current}),D_.warn(`Preview upstream is listening but has served ${Y.current} consecutive ${ve} responses`),(pt=f.current)==null||pt.call(f,{upstreamStatus:ve,consecutiveCount:Y.current})),se&&!ae){ue||(H.current=!0,U.current=!1);const Ot=!G.current;G.current=!0,g(!0),R(null),B.current=null,F.current=!1,A(!1),D.current?Ot&&(Ce==null||Ce.capture("preview_upstream_restored",{framework:t})):(D.current=!0,Ce==null||Ce.capture("preview_dev_server_ready",{framework:t,ready_after_ms:Date.now()-N})),oe(i,ne);return}const We=G.current;G.current=!1,g(!1),R(de),B.current===null&&(B.current=Date.now(),F.current=!1,A(!1)),We&&(Ce==null||Ce.capture("preview_upstream_lost",{framework:t,upstream_status:ve}),w(Ot=>Ot+1),D_.warn("Preview upstream became unavailable after it was ready"));const Ee=Date.now()-B.current;Ee>=o&&!F.current&&(F.current=!0,A(!0),Ce==null||Ce.capture("preview_dev_server_unreachable",{framework:t,elapsed_ms:Ee,upstream_status:J.current}),D_.warn("Dev server did not become ready within timeout window")),oe(s,ne)};return n.current=()=>oe(0,ne),oe(0,ne),()=>{O=!1,n.current=null,Q()}},[t,s,i,o,u,d]),m.useEffect(()=>{var N;if(t==="static"||l===void 0)return;const O=r.current;r.current=l,O!==null&&O!==l&&((N=n.current)==null||N.call(n))},[t,l]),{isUpstreamReady:h,iframeRemountKey:v,probeStartedAt:_,probeAttemptCount:S,isFirstUnreachableWindowExceeded:C,initialProbeComplete:T,unavailableReason:M}};function Sne(t){return t.enteringSplit&&t.isExistingSession&&t.hasActiveVariantProxy}const V9=t=>{var e;return t!=="embedded"||typeof window>"u"?"":((e=window.__RIVET_BOOTSTRAP__)==null?void 0:e.previewOrigin)??`${window.location.protocol}//localhost:${window.location.port}`},H9=({agentApplyMode:t,url:e})=>e.startsWith("/")?`${V9(t)}${e}`:e,kne="allow-scripts allow-same-origin allow-forms allow-popups allow-modals",Ene=t=>kne,Cne=Ms("PreviewSurface"),rP=(t,e)=>t==="about:blank"?"blank":t.includes("/api/variants/")?"static_artifact":e.kind==="variant"?"dev_server":"original",z9=({target:t,src:e,framework:n,remountKey:r})=>(dt(yv),b.jsx("div",{className:"relative h-full w-full",children:b.jsx("iframe",{src:e,className:"h-full w-full border-none",title:"Project Preview",sandbox:Ene(),onLoad:()=>{Ce==null||Ce.capture("preview_iframe_loaded",{framework:n,src:e}),t.kind==="variant"&&(Ce==null||Ce.capture("variants_panel.preview_displayed",{sessionId:t.sessionId,variantId:t.variantId,renderedTarget:"variant",iframeSrcKind:rP(e,t),framework:n}))},onError:()=>{Ce==null||Ce.capture("preview_iframe_load_failed",{framework:n,src:e}),t.kind==="variant"&&(Ce==null||Ce.capture("variants_panel.preview_display_failed",{sessionId:t.sessionId,variantId:t.variantId,renderedTarget:"variant",iframeSrcKind:rP(e,t),framework:n})),Cne.warn("Preview iframe failed to load",{framework:n,src:e})}},r)})),Pne=m.lazy(()=>XP(()=>Promise.resolve().then(()=>lse),void 0)),Ane={surface:"relative flex h-full w-full items-center justify-center bg-main px-6",overlay:"absolute inset-0 z-10 flex items-center justify-center bg-main/90 px-6",page:"relative flex h-screen w-full items-center justify-center bg-main px-6"},Tne={sm:"text-lg font-semibold text-content",md:"text-2xl font-semibold text-content",lg:"text-3xl font-semibold text-content"},Rne={neutral:"rounded-md border border-divider bg-transparent px-5 py-2 text-sm font-medium text-content transition-colors hover:bg-surface-3",ghost:"rounded-md px-5 py-2 text-sm font-medium text-content-muted transition-colors hover:text-content"},ju=({backdrop:t,media:e,title:n,description:r,actions:s,tone:i="neutral",fill:o="surface",size:l="md",children:u,state:d,role:f="status",busy:h=!1,className:g=""})=>{const v=m.useCallback(_=>{_&&d&&(Ce==null||Ce.capture("status_surface_shown",{state:d,tone:i,fill:o}))},[d,i,o]),w=!!(e||n||r||u||s!=null&&s.length);return b.jsxs("div",{ref:v,className:`${Ane[o]} ${g}`.trim(),role:f,"aria-live":"polite","aria-busy":h||void 0,"data-state":d,children:[t?b.jsx("div",{className:"absolute inset-0",children:t}):null,w?b.jsxs("div",{className:"relative z-10 flex max-w-sm flex-col items-center gap-5 text-center",children:[e,n?b.jsx("h2",{className:Tne[l],children:n}):null,r?b.jsx("p",{className:"text-content-muted text-base leading-relaxed",children:r}):null,u,s!=null&&s.length?b.jsx("div",{className:"flex flex-row items-center gap-3",children:s.map(_=>b.jsx("button",{type:"button",onClick:_.onClick,className:Rne[_.variant??"neutral"],children:_.label},_.label))}):null]}):null]})},ex=({loader:t="coalesce",trackGlobalLoaderCount:e,size:n="lg",...r})=>t==="coalesce"?b.jsx(ju,{...r,size:n,busy:!0,backdrop:b.jsx($9,{trackGlobalLoaderCount:e})}):t==="logo"?b.jsx(ju,{...r,size:n,busy:!0,backdrop:b.jsx(m.Suspense,{fallback:null,children:b.jsx(Pne,{className:"absolute inset-0"})})}):b.jsx(ju,{...r,size:n,busy:!0,media:b.jsx(ev,{"aria-hidden":!0,className:"text-content h-8 w-8 shrink-0 animate-spin",weight:"bold"})}),U9=({icon:t,...e})=>b.jsx(ju,{...e,tone:"neutral",media:t?b.jsx("div",{className:"text-content-muted",children:t}):void 0}),p4=t=>b.jsx(ju,{...t,tone:"error",role:"alert"}),sP="/static/",Mne=t=>{try{return new URL(t,"http://localhost").pathname.endsWith(sP)}catch{return t.endsWith(sP)}},Ine=t=>t==="spawn_error"?"The direction is saved, but its preview process didn’t start.":t==="exited"?"The direction is saved, but its preview stopped before it was ready.":t==="timeout"?"The direction is saved, but its preview took too long to become ready.":t==="dependency_install_failed"?"The direction is saved, but its dependencies couldn’t be prepared. Fix the installation error, then retry the preview.":t==="compile_error"?"The direction is saved, but its app couldn’t compile. Fix the app error, then retry the preview.":t==="missing_dev_script"?"The direction is saved, but Rivet couldn’t find a dev script to preview it.":t==="missing_static_entry"?"The direction is saved, but Rivet couldn’t find an HTML entry to preview it.":"The direction is saved, but Rivet couldn’t prepare its preview.",One=t=>t.status==="failed"&&t.errorCode==="VARIANT_VERIFICATION_UNAVAILABLE"?{state:"variant_verification_unavailable",title:"Rivet couldn’t verify this direction",description:"The worker completed, but Rivet couldn’t inspect its generated files.",detail:t.errorMessage??t.errorCode,isError:!0}:t.status==="failed"&&t.errorCode==="VARIANT_QA_FAILED"?{state:"variant_output_integrity_failed",title:"This direction couldn’t be verified",description:"The worker completed, but Rivet found a structural problem in the generated files.",detail:t.errorMessage??t.errorCode,isError:!0}:t.status==="failed"?{state:"variant_worker_failed",title:"This direction didn’t complete",description:"The worker stopped before producing a usable result.",detail:t.errorMessage??t.errorCode,isError:!0}:t.status==="cancelled"?{state:"variant_cancelled",title:"Direction was cancelled",description:"Rivet stopped before a preview was ready. Your other directions are unchanged.",isError:!1}:t.status==="succeeded"&&t.previewUnavailable&&t.previewUnavailable.reason!=="idle_timeout"?{state:"preview_unavailable",title:"Rivet couldn’t preview this direction",description:Ine(t.previewUnavailable.reason),detail:t.previewUnavailable.portInUse?"The preview port was already in use.":void 0,isError:!0}:null,Lne=({issue:t,retryTarget:e})=>{const n=Ei(),r=m.useRef(!1),[s,i]=m.useState(!1),[o,l]=m.useState(null),u=async()=>{if(!(!e||r.current)){r.current=!0,i(!0),l(null),n==null||n.capture("preview_retry_clicked",{session_id:e.sessionId,variant_id:e.variantId});try{const d=await fetch(`/api/variants/${encodeURIComponent(e.sessionId)}/preview-port`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({variantId:e.variantId,retry:!0})});if(!d.ok){const f=Tn({message:Xe().optional()}).safeParse(await d.json().catch(()=>({}))),h=f.success?f.data:{};throw new Error(h.message??"The preview could not restart. Try again.")}}catch(d){l(d instanceof Error?d.message:"The preview could not restart. Try again.")}finally{r.current=!1,i(!1)}}};return b.jsxs(ju,{fill:"overlay",size:"sm",state:t.state,role:t.isError?"alert":"status",tone:t.isError?"error":"neutral",title:t.title,description:t.description,busy:s,actions:e&&!s?[{label:"Retry preview",onClick:()=>void u()}]:void 0,children:[s?b.jsx("p",{className:"text-content-subtle text-xs",children:"Starting preview…"}):null,o?b.jsx("p",{className:"text-content-subtle text-xs",children:o}):null,t.detail?b.jsx("p",{className:"text-content-subtle text-xs leading-relaxed break-words",children:t.detail}):null]})},Nne=({isInteractionDisabled:t=!1,framework:e,userPort:n})=>{var _t;const r=dt(Bw),s=gt(Bw),i=dt(Pg),o=gt(Pg),l=dt(cp),u=dt(yv),d=dt(Zw),f=dt(Ww),h=dt(f9),g=dt(h9),v=gt(Ww),w=dt(Ko),_=dt(Sm),x=gt(Zw),S=l.active&&l.projectContext.kind==="fresh",k=dt(qw),C=l.active?l.variants.find(qe=>qe.workItemId===k&&(qe.status==="pending"||qe.status==="running"||qe.status==="succeeded"&&!qe.preview&&typeof qe.port!="number"&&(!qe.previewUnavailable||qe.previewUnavailable.reason==="idle_timeout")))??null:null,A=l.active&&l.variants.some(qe=>qe.status==="pending"||qe.status==="running"),T=S||A,I=l.active?l.variants.find(qe=>qe.workItemId===k)??null:null,M=I?One(I):null,R=e==="static"&&i!==null&&Mne(i);m.useEffect(()=>{l.active||x(!1)},[l.active,x]);const O=m.useRef(!1);m.useEffect(()=>{const qe=!!(w!=null&&w.left||w!=null&&w.right),Ke=qe&&!O.current;O.current=qe;const Ct=l.active?l.sessionId:null;!Ct||!Sne({enteringSplit:Ke,isExistingSession:l.active&&l.projectContext.kind==="existing",hasActiveVariantProxy:d&&f!==null})||(x(!1),v(null),s(Te=>Te+1),fetch(`/api/variants/${encodeURIComponent(Ct)}/preview-port`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({variantId:null})}).catch(()=>{}))},[w,l,d,f,x,v,s]);const D=m.useMemo(()=>{var Lt;if(d||i&&!R||!l.active)return null;const{stage:qe,variants:Ke}=l,Ct=qe==="ready"||qe==="degraded",Te=Ke.some(Ge=>{var Pt,as;return((Pt=Ge.refinement)==null?void 0:Pt.status)==="pending"||((as=Ge.refinement)==null?void 0:as.status)==="running"});if(!Ct&&!Te)return null;const Ye=Ke.find(Ge=>{var Pt;return Ge.status==="succeeded"&&((Pt=Ge.preview)==null?void 0:Pt.kind)==="static_artifact"});return((Lt=Ye==null?void 0:Ye.preview)==null?void 0:Lt.kind)==="static_artifact"?Ye.preview.url:null},[R,i,d,l])??i,F=m.useMemo(()=>!l.active||!D?null:l.variants.find(qe=>{var Ke;return((Ke=qe.preview)==null?void 0:Ke.kind)==="static_artifact"&&D.startsWith(qe.preview.url)})??null,[D,l]),K=m.useMemo(()=>{if((_==null?void 0:_.previewKind)==="static")return{kind:"variant",sessionId:_.sessionId,variantId:_.variantId};if(!l.active)return Cg;if(F)return{kind:"variant",sessionId:l.sessionId,variantId:F.workItemId};if(D){const Ke=D.match(/\/__rivet\/preview\/variant\/([^/]+)\/([^/?#]+)/),Ct=Ke!=null&&Ke[1]?decodeURIComponent(Ke[1]):null,Te=Ke!=null&&Ke[2]?decodeURIComponent(Ke[2]):null;if(Ct===l.sessionId&&Te&&l.variants.some(Ge=>Ge.workItemId===Te))return{kind:"variant",sessionId:l.sessionId,variantId:Te};const Ye=D.match(/\/api\/variants\/[^/]+\/static\/([^/?#]+)/),Lt=Ye!=null&&Ye[1]?decodeURIComponent(Ye[1]):null;if(Lt&&l.variants.some(Ge=>Ge.workItemId===Lt))return{kind:"variant",sessionId:l.sessionId,variantId:Lt}}const qe=!!(w!=null&&w.left||w!=null&&w.right);return(!qe||S)&&!D&&d&&f&&l.variants.some(Ke=>Ke.workItemId===f)?{kind:"variant",sessionId:l.sessionId,variantId:f}:(!qe||S)&&!D&&k&&l.variants.some(Ke=>Ke.workItemId===k)?{kind:"variant",sessionId:l.sessionId,variantId:k}:Cg},[_,F,l,d,f,D,w,S,k]),B=m.useRef(null);m.useEffect(()=>{var Te,Ye;if(!F||((Te=F.preview)==null?void 0:Te.kind)!=="static_artifact"||((Ye=F.refinement)==null?void 0:Ye.status)!=="succeeded")return;const qe=`${F.workItemId}:${F.refinement.workItemId}`;if(B.current===qe)return;B.current=qe;const Ke=F.preview.url.includes("?")?"&":"?",Ct=`${F.preview.url}${Ke}refinement=${encodeURIComponent(F.refinement.workItemId)}`;D!==Ct&&(o(Ct),s(Lt=>Lt+1))},[D,F,s,o,l]);const G=D!==null&&Iee(D),H=D!==null&&!G||S&&!d&&!G,{isUpstreamReady:Y,iframeRemountKey:U,probeAttemptCount:J,initialProbeComplete:Z}=bne(e,{rerunProbeImmediatelyOnVersion:r,probePath:G?D:null,skip:H}),[j,Q]=m.useState(()=>h&&Y?r:null),oe=m.useRef(null);m.useEffect(()=>{if(!h){oe.current=null,Q(null);return}if(j===r){oe.current=null;return}const qe=oe.current;if(!qe||qe.remountKey!==r){oe.current={remountKey:r,probeAttemptCount:J};return}Y&&J>qe.probeAttemptCount&&(oe.current=null,Q(r))},[j,r,h,J,Y]);const se=D!==null&&!G||Y,ve=g||h&&j!==r||h&&!se,ue=`${U}:${r}`,ae=x9(window.location.pathname),Oe=e==="static"?`/static${ae??"/"}`:ae??"/",We=V9(u);let Ee=null;D&&(Ee=H9({agentApplyMode:u,url:D}));const Ot=C||M||ve?"about:blank":(G&&!se?"about:blank":Ee)??(se?`${We}${Oe}`:"about:blank"),en=!!C||!!M||!se&&Z;let bt=null;if(ve)bt=b.jsx(ex,{fill:"overlay",loader:"coalesce",trackGlobalLoaderCount:!1,state:"preview_replay_boot"});else if(C)bt=b.jsx(ex,{fill:"overlay",loader:"coalesce",trackGlobalLoaderCount:!1,state:"variant_building",children:b.jsx("span",{className:"sr-only",children:"Building your direction"})});else if(M){const qe=l.active&&I&&M.state==="preview_unavailable"&&((_t=I.previewUnavailable)==null?void 0:_t.reason)!=="missing_static_entry"?{sessionId:l.sessionId,variantId:I.workItemId}:void 0;bt=b.jsx(Lne,{issue:M,retryTarget:qe},I==null?void 0:I.workItemId)}else en&&(bt=T?b.jsx(U9,{fill:"overlay",state:"preview_no_selection",title:"Nothing to preview yet",description:"Pick a direction from the panel."}):b.jsx(p4,{fill:"overlay",state:"preview_offline",title:"Preview isn't connected",description:"Rivet lost connection to your project.",actions:[{label:"Reload",onClick:()=>window.location.reload()}]}));return b.jsx("div",{className:"relative flex h-full min-h-0 w-full flex-col",children:b.jsxs("div",{className:"relative min-h-0 flex-1",children:[bt,b.jsx(z9,{target:K,src:Ot,framework:e,remountKey:ue})]})})};function iP({side:t,sessionId:e,variantId:n,url:r,label:s,source:i,isFallback:o=!1}){var C;const l=dt(Ko),u=gt(Ko),d=Ei(),f=dt(cp),h=dt(yv),g=m.useRef(!1),v=m.useCallback(()=>{g.current||(g.current=!0,gd({source:i,sessionId:e,variantId:n}))},[i,e,n]),w=m.useCallback(()=>{if(o){u(null);const M=Ag("ended",l);d==null||d.capture(M.event,M.properties);return}v();const A={...l};delete A[t];const T=A.left||A.right?A:null;u(T);const I=Ag(T?"updated":"ended",T??l);d==null||d.capture(I.event,I.properties)},[o,d,u,t,l,v]),_=m.useMemo(()=>({kind:"variant",sessionId:e,variantId:n}),[e,n]),x=m.useMemo(()=>!f.active||f.sessionId!==e?null:f.variants.find(A=>A.workItemId===n)??null,[e,n,f]),S=m.useMemo(()=>{var T,I;let A=r;if(((T=x==null?void 0:x.preview)==null?void 0:T.kind)==="static_artifact"&&((I=x.refinement)==null?void 0:I.status)==="succeeded"){const M=x.preview.url.includes("?")?"&":"?";A=`${x.preview.url}${M}refinement=${encodeURIComponent(x.refinement.workItemId)}`}return H9({agentApplyMode:h,url:A})},[h,x,r]),k=((C=x==null?void 0:x.refinement)==null?void 0:C.status)==="succeeded"?`${n}:${x.refinement.workItemId}`:n;return b.jsxs("div",{className:"variant-split-secondary","data-cy":"variant-split-pane","data-variant-id":n,children:[b.jsxs("div",{className:"variant-split-secondary-toolbar",children:[b.jsx("span",{className:"variant-split-secondary-label",title:s,children:s}),b.jsx(kc,{label:"Collapse",children:b.jsx("button",{type:"button",className:"variant-split-secondary-close",onClick:w,"aria-label":"Collapse split view",children:b.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12","aria-hidden":"true",focusable:"false",children:b.jsx("path",{d:"M2.5 2.5 L9.5 9.5 M9.5 2.5 L2.5 9.5",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"})})})})]}),b.jsx("div",{className:"variant-split-secondary-body relative min-h-0 flex-1",children:b.jsx(z9,{target:_,src:S,framework:"static",remountKey:k})})]})}function Dne(){const t=dt(md),e=dt(u4);return!t||!e?null:ip.createPortal(b.jsx("div",{"aria-hidden":"true",className:"border-main-border bg-main pointer-events-none fixed top-0 left-0 z-[70] flex max-w-60 items-center gap-2 rounded-md border px-3 py-1.5 shadow-lg",style:{transform:`translate3d(${e.x+12}px, ${e.y+12}px, 0)`},children:b.jsx("span",{className:"text-content truncate text-sm font-medium",children:t.label})}),document.body)}function jne(){const t=dt(md),e=dt(u4),n=dt(Ko),r=gt(md),s=gt(Ko),i=Ei(),o=m.useRef(null),[l,u]=m.useState(null),[d,f]=m.useState("hidden");m.useEffect(()=>{t||(f("hidden"),u(null))},[t]);const h=m.useCallback((v,w)=>{const _=o.current;if(!_)return null;const x=_.getBoundingClientRect();return v<x.left||v>x.right||w<x.top||w>x.bottom?null:v<(x.left+x.right)/2?"left":"right"},[]);if(m.useEffect(()=>{if(!t||!e)return;const v=h(e.x,e.y);u(w=>w===v?w:v),f(w=>{if(w==="exiting")return w;const _=v!==null?"visible":"hidden";return w===_?w:_})},[t,e,h]),m.useEffect(()=>{if(!t)return;const v=w=>{const _=h(w.clientX,w.clientY);if(_&&t.url){const x={sessionId:t.sessionId,variantId:t.variantId,label:t.label,url:t.url,source:t.source},S=n==null?void 0:n[_];S&&(S.sessionId!==x.sessionId||S.variantId!==x.variantId)&&gd(S);const k={...n??{},[_]:x};s(k);const C=Ag(n?"updated":"started",k);i==null||i.capture(C.event,C.properties),f("exiting"),window.setTimeout(()=>r(null),220)}else gd(t),f("exiting"),window.setTimeout(()=>r(null),220)};return window.addEventListener("pointerup",v),window.addEventListener("pointercancel",v),()=>{window.removeEventListener("pointerup",v),window.removeEventListener("pointercancel",v)}},[t,h,i,r,s,n]),!t)return null;const g=["variant-drop-zones",d==="visible"&&"is-visible",d==="exiting"&&"is-exiting"].filter(Boolean).join(" ");return b.jsxs("div",{ref:o,className:g,"aria-hidden":"true",children:[b.jsx(oP,{side:"left",hovered:l==="left",canDrop:!!t.url,label:t.label}),b.jsx(oP,{side:"right",hovered:l==="right",canDrop:!!t.url,label:t.label})]})}function oP({side:t,hovered:e,canDrop:n,label:r}){return b.jsxs("div",{className:["variant-drop-zone",`is-${t}`,e&&"is-hover",!n&&"is-disabled"].filter(Boolean).join(" "),children:[b.jsxs("div",{className:"variant-drop-zone-inner",children:[b.jsx("div",{className:`variant-drop-zone-icon is-${t}`}),b.jsx("div",{className:"variant-drop-zone-caption",children:n?`Add ${t} split`:"Split unavailable for this direction"})]}),b.jsx("div",{className:"variant-drop-zone-preview","aria-hidden":"true",children:b.jsx("div",{className:"variant-drop-zone-preview-label",children:r})}),b.jsx("div",{className:"variant-drop-zone-border"})]})}const B9=(t,e,n)=>{var i,o;if(!t.active||t.sessionId!==e)return null;const r=t.variants.find(l=>l.workItemId===n);if(((i=r==null?void 0:r.preview)==null?void 0:i.kind)!=="static_artifact")return null;if(((o=r.refinement)==null?void 0:o.status)!=="succeeded")return r.preview.url;const s=r.preview.url.includes("?")?"&":"?";return`${r.preview.url}${s}refinement=${encodeURIComponent(r.refinement.workItemId)}`},aP=(t,e)=>{if(!t)return;const n=B9(e,t.sessionId,t.variantId);return!n||n===t.url?t:{...t,url:n}},$ne=()=>b.jsx("div",{"data-testid":"preview-boot-skeleton",role:"status","aria-busy":"true","aria-label":"Loading preview",className:"bg-main flex h-full min-h-0 w-full flex-1 flex-col p-3",children:b.jsx("div",{className:"border-main-border relative min-h-0 flex-1 overflow-hidden rounded-lg border",children:b.jsx($9,{trackGlobalLoaderCount:!1})})}),Fne=({isLoading:t=!1,isInteractionDisabled:e=!1})=>{const{config:n,fetchConfig:r,isLoading:s,error:i}=tne();return m.useEffect(()=>{r().catch(o=>{Ce==null||Ce.capture("preview_config_load_failed",{message:o instanceof Error?o.message:"unknown_error",attempts:J3})})},[r]),s?b.jsx($ne,{}):i||!n?b.jsx(p4,{fill:"surface",size:"sm",state:"preview_config_error",title:"Couldn't load preview",description:"We couldn't load the preview configuration.",actions:[{label:"Retry",onClick:()=>{Ce==null||Ce.capture("preview_config_retry_clicked"),r().catch(o=>{Ce==null||Ce.capture("preview_config_load_failed",{message:o instanceof Error?o.message:"unknown_error",attempts:J3})})}}]}):b.jsx(Vne,{isLoading:t,isInteractionDisabled:e,framework:n.framework,userPort:n.userPort})};function Vne(t){const e=dt(Ko),n=dt(md),r=dt(cp),s=dt(Pg),i=e==null?void 0:e.left,o=e==null?void 0:e.right,l=m.useMemo(()=>{var T,I;if(!r.active||r.projectContext.kind!=="fresh"||!(!!i!=!!o))return;const _=(T=i??o)==null?void 0:T.variantId,x=r.variants.filter(M=>{var R;return M.status==="succeeded"&&((R=M.preview)==null?void 0:R.kind)==="static_artifact"&&M.workItemId!==_}),S=s==null?void 0:s.replace(/[?&]refinement=[^&]*$/,""),C=x.find(M=>{var R;return((R=M.preview)==null?void 0:R.kind)==="static_artifact"&&M.preview.url===S})??x[0];if(((I=C==null?void 0:C.preview)==null?void 0:I.kind)!=="static_artifact")return;const A=B9(r,r.sessionId,C.workItemId);if(A)return{sessionId:r.sessionId,variantId:C.workItemId,label:C.label,url:A,source:"live"}},[r,i,o,s]),u=aP(i,r)??(o?l:void 0),d=aP(o,r)??(i?l:void 0),f=!i&&!!u,h=!o&&!!d,g=!!(u||d),v=b.jsx(Nne,{isInteractionDisabled:t.isInteractionDisabled,framework:t.framework,userPort:t.userPort});return b.jsx("div",{className:"relative flex h-full min-h-0 w-full flex-1 flex-col",children:b.jsxs("div",{className:`variant-preview-region relative flex h-full min-h-0 w-full flex-1 flex-col ${n?"is-dragging":""} ${g?"is-split":""}`,children:[b.jsxs("div",{className:"variant-preview-row flex h-full min-h-0 w-full flex-1",children:[u&&b.jsx(iP,{side:"left",sessionId:u.sessionId,variantId:u.variantId,url:u.url,label:u.label,source:u.source,isFallback:f},`left-${u.sessionId}:${u.variantId}:${u.url}`),!(u&&d)&&b.jsx("div",{className:"variant-preview-primary flex h-full min-h-0 flex-1 flex-col",children:v}),d&&b.jsx(iP,{side:"right",sessionId:d.sessionId,variantId:d.variantId,url:d.url,label:d.label,source:d.source,isFallback:h},`right-${d.sessionId}:${d.variantId}:${d.url}`)]}),b.jsx("div",{className:"variant-preview-atmosphere","aria-hidden":"true"}),b.jsx(jne,{}),b.jsx(Dne,{})]})})}function Mo(t){if(t===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function Z9(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}/*!
141
+ </html>`,gte=Tn({success:xh(),authUrl:Xe().optional(),sessionId:Xe().optional(),pollSecret:Xe().optional(),error:Xe().optional(),message:Xe().optional()}),vte=Tn({success:xh(),token:Xe().optional(),refreshToken:Xe().optional(),user:Tn({id:Xe().optional(),email:Xe().optional()}).optional(),error:Xe().optional(),message:Xe().optional()}),yte="/api/auth/install-ref",_te=Tn({installRef:Xe().nullable()}),wte=async()=>{try{const t=await fetch(yte);if(!t.ok)return;const e=_te.safeParse(await t.json());return e.success?e.data.installRef??void 0:void 0}catch{return}},O9=(t="editor_gate",e)=>{const n=Ei(),[r,s]=m.useState(!1),[i,o]=m.useState(null);return{startLogin:m.useCallback(async()=>{var g;const u=globalThis.crypto.randomUUID(),d=Date.now();s(!0),o(null);const f=I_({outcome:"started",authAttemptId:u,entryPoint:t,startedAt:d,now:d});n==null||n.capture(f.event,f.properties);let h=null;try{if(h=window.open("","_blank"),!h)throw new Error("Pop-up blocked. Please allow pop-ups and try again.");try{h.document.open(),h.document.write(mte),h.document.close()}catch(S){B3.warn("Failed to render loading state in auth popup:",S)}const v=await wte(),w=await fetch(`${W3}/api/auth/google/start`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({source:"core",...v?{ref:v}:{}})}),_=gte.safeParse(await w.json());if(!_.success)throw new Error("Invalid Google login response");const x=_.data;if(!w.ok||!x.success||!x.authUrl||!x.sessionId||!x.pollSecret)throw new Error(x.error||x.message||"Failed to start Google login");if(h.closed)throw new Error("Sign-in window was closed before Google login started.");h.location.href=x.authUrl;for(let S=0;S<pte;S+=1){if(h.closed)throw new Error("Sign-in window was closed before authentication completed.");const k=await fetch(`${W3}/api/auth/google/token`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({session:x.sessionId,pollSecret:x.pollSecret})}),C=vte.safeParse(await k.json());if(!C.success)throw new Error("Invalid Google token response");const A=C.data;if(A.success&&A.token&&((g=A.user)!=null&&g.email)){const T={email:A.user.email,token:A.token,refreshToken:A.refreshToken,userId:A.user.id,...v?{installRef:v}:{}};if(e)await e(T);else if(!(await tl("/api/auth/store",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(T)})).ok)throw new Error("Signed in, but failed to store session locally.");h.close(),window.sessionStorage.setItem(Tg,"1");const I=I_({outcome:"completed",authAttemptId:u,entryPoint:t,startedAt:d,now:Date.now()});n==null||n.capture(I.event,I.properties),window.location.reload();return}if(A.error&&A.error!=="Pending")throw new Error(A.error||"Google login failed");await new Promise(T=>setTimeout(T,hte))}throw new Error("Authentication timed out. Please try again.")}catch(v){h&&!h.closed&&h.close();const w=v instanceof Error?v.message:"Failed to start login flow";B3.warn("Login failed:",w);const _=I_({outcome:"failed",authAttemptId:u,entryPoint:t,startedAt:d,now:Date.now(),failureReason:fte(w)});n==null||n.capture(_.event,_.properties),o(w),s(!1)}},[n,t,e]),isStartingLogin:r,loginError:i}},xte=Ms("useIntegrations"),bte=Tn({provider:Xe(),status:Xe(),externalUsername:Xe().nullable(),connectedAt:Xe()}),Ste=Tn({integrations:dd(bte).optional()}),kte=Tn({authUrl:Xe().min(1).optional(),error:Xe().optional()}),Ete=Tn({error:Xe().optional()}),O_=["integrations"],Cte="rivet:connect-result",Pte=t=>typeof t=="object"&&t!==null&&t.type===Cte,Ate=ft(null),q3=async()=>{const t=await tl("/api/integrations");if(!t.ok)throw new Error(`Failed to load integrations (${t.status})`);return Ste.parse(await t.json()).integrations??[]},Tte=()=>{const t=JP(),[e,n]=QT(Ate),r=uh({queryKey:O_,queryFn:q3,staleTime:1e4}),s=m.useCallback(async()=>(await t.invalidateQueries({queryKey:O_,refetchType:"none"}),t.fetchQuery({queryKey:O_,queryFn:q3})),[t]),i=m.useCallback(async l=>{const u=window.open("","_blank","width=560,height=720");if(!u)throw new Error("Popup blocked. Allow popups to connect.");n(l);try{const d=await tl(`/api/integrations/${l}/connect`,{method:"POST"}),f=kte.safeParse(await d.json().catch(()=>({}))),h=f.success?f.data:{};if(!d.ok||!h.authUrl)throw u.close(),new Error(h.error||`Could not connect ${l}`);return u.location.href=h.authUrl,await new Promise(g=>{let v=!1,w=null;const _=async(S,k=!1)=>{if(!v){v=!0,window.removeEventListener("message",x),w&&clearInterval(w);try{const A=(await s()).some(T=>T.provider===l&&T.status==="connected");g(k&&A?"connected":S)}catch{g(S)}}},x=S=>{if(Pte(S.data)&&S.data.provider===l){if(S.data.status==="error"){xte.warn(`Connect failed for ${l}:`,S.data.message),_("failed");return}_("connected")}};window.addEventListener("message",x),w=setInterval(()=>{u.closed&&_("closed",!0)},500)})}finally{n(null)}},[s,n]),o=m.useCallback(async l=>{n(l);try{const u=await tl(`/api/integrations/${l}`,{method:"DELETE"});if(!u.ok){const d=Ete.safeParse(await u.json().catch(()=>({}))),f=d.success?d.data:{};throw new Error(f.error||`Could not disconnect ${l}`)}await s()}finally{n(null)}},[s,n]);return{integrations:r.data??[],isLoading:r.isPending,error:r.error instanceof Error?r.error.message:null,pendingProvider:e,connect:i,disconnect:o,refetch:s}},Dl=({action:t,outcome:e,provider:n,entryPoint:r,durationMs:s,failureReason:i})=>({event:`visual_editor_reference_${t==="connect"?"connection":"disconnection"}_${e}`,properties:{provider:n,entry_point:r,...s!==void 0?{duration_ms:s}:{},...i?{failure_reason:i}:{}}}),up=async(t,e="GET",n)=>{if(window.location.pathname.startsWith("/rivet/library"))return Cz(t,{method:e,body:n});const r=await tl(t.replace(/^\/profile/,"/api/reference-profiles"),{method:e,headers:{"Content-Type":"application/json"},...n!==void 0?{body:JSON.stringify(n)}:{}}),s=await r.text();let i;try{i=JSON.parse(s)}catch{throw new Error(`Reference profile request failed (${r.status})`)}if(!r.ok)throw new Error(i.error??`Request failed (${r.status})`);return i},L9=()=>up("/profile"),Rte=t=>uh({queryKey:["cosmos-profile"],queryFn:L9,enabled:t}),Mte=t=>up("/profile/discoveries","POST",{url:t}),Ite=({discoveryId:t,collectionIds:e,runtime:n})=>up("/profile/import-plans","POST",{discoveryId:t,collectionIds:e,runtime:n}),Ote=t=>up("/profile","PATCH",{isEnabled:!0,runtime:t}),Lte=t=>up(`/profile/import-plans/${t.id}/imports`,"POST",{revision:t.revision,isApproved:!0}),Qw=Xe().regex(/^[1-9]\d{0,15}$/).refine(t=>Number.isSafeInteger(Number(t))),Nte=Xe().min(1).max(4096),N9=t=>{const e=()=>new Error("Use an HTTPS Cosmos profile URL such as https://www.cosmos.so/username");let n;try{n=new URL(t)}catch{throw e()}const r=n.pathname.split("/").filter(Boolean);if(n.protocol!=="https:"||n.username||n.password||n.port||!["cosmos.so","www.cosmos.so"].includes(n.hostname)||r.length!==1)throw e();let s;try{s=decodeURIComponent(r[0])}catch{throw e()}if(!/^[a-zA-Z0-9_.-]{1,100}$/.test(s)||["e","login","signup","explore","search","collections","settings","api","profile"].includes(s.toLowerCase()))throw e();return{username:s,url:`https://www.cosmos.so/${encodeURIComponent(s)}`}};Xe().max(2048).transform((t,e)=>{try{return N9(t).url}catch(n){return e.addIssue({code:xe.custom,message:n instanceof Error?n.message:"Invalid Cosmos profile URL"}),xz}});const Dte=t=>{const e=()=>new Error("Use an HTTPS Cosmos collection URL such as https://www.cosmos.so/owner/collection");let n;try{n=new URL(t)}catch{throw e()}const r=n.pathname.split("/").filter(Boolean);if(n.protocol!=="https:"||n.username||n.password||n.port||!["cosmos.so","www.cosmos.so"].includes(n.hostname)||r.length<2||r.length>3||r[0]==="e")throw e();let s;try{s=r.map(i=>decodeURIComponent(i))}catch{throw e()}if(s.some(i=>!i.length||i.length>300||/[/\\\p{Cc}]/u.test(i)))throw e();return{ownerUsername:s[0],slug:s[1],subcollectionSlug:s[2],url:`https://www.cosmos.so/${s.map(encodeURIComponent).join("/")}`}},jte=Xe().url().refine(t=>{const e=new URL(t);return e.protocol==="https:"&&e.hostname==="cdn.cosmos.so"&&!e.username&&!e.password&&!e.port}),$te=Tn({id:Qw,title:Xe().min(1).max(500),url:Xe().url().transform(t=>Dte(t).url),children:dd(Qw)}),Fte=Tn({id:Qw,url:Xe().url(),title:Xe().max(1e3),text:Xe().max(1e5),author:Xe().nullable(),owner:Xe().nullable(),sourceUrl:Xe().url().nullable(),images:dd(Tn({url:jte,representation:Zg(["image","video-cover"])})).max(100),unsupportedReason:Xe().optional()}),Vte=Tn({collection:$te,elements:dd(Fte),total:HT().int().nonnegative(),nextCursor:Nte.nullable()});wz("status",[Vte.extend({status:mE("ok")}),Tn({status:mE("error"),message:Xe(),reason:Zg(["rate_limited","provider_unavailable","collection_unavailable"]).optional(),retryAfterMs:HT().nonnegative().optional()})]);const Hte=({isOpen:t,onClose:e,onImported:n})=>{const[r,s]=m.useState(""),[i,o]=m.useState(null),[l,u]=m.useState([]),[d,f]=m.useState(""),[h,g]=m.useState(null),[v,w]=m.useState(null),[_,x]=m.useState(!1),S=m.useRef(0),k=Ei(),C=()=>{S.current+=1,s(""),o(null),u([]),f(""),g(null),w(null),x(!1)},A=()=>{k==null||k.capture("visual_editor_cosmos_modal_closed"),C(),e()},T=async O=>{O.preventDefault(),w(null);let N;try{N=N9(r.trim()).url}catch(F){w(F instanceof Error?F.message:"Invalid Cosmos profile URL");return}k==null||k.capture("visual_editor_cosmos_discovery_started");const D=++S.current;x(!0);try{const F=await Mte(N);if(D!==S.current)return;o(F),u([]),k==null||k.capture("visual_editor_cosmos_discovery_completed",{collection_count:F.collections.length})}catch(F){if(D!==S.current)return;w(F instanceof Error?F.message:"Could not find Cosmos profile"),k==null||k.capture("visual_editor_cosmos_discovery_failed")}finally{D===S.current&&x(!1)}},I=async()=>{if(!i||l.length===0||!d)return;w(null),k==null||k.capture("visual_editor_cosmos_plan_started",{collection_count:l.length,runtime:d});const O=++S.current;x(!0);try{const N=await Ite({discoveryId:i.id,collectionIds:l,runtime:d});if(O!==S.current)return;g(N),k==null||k.capture("visual_editor_cosmos_plan_completed",{collection_count:N.collectionCount,reference_count:N.referenceCount})}catch(N){if(O!==S.current)return;w(N instanceof Error?N.message:"Could not prepare import plan"),k==null||k.capture("visual_editor_cosmos_plan_failed")}finally{O===S.current&&x(!1)}},M=async()=>{if(!h||!d)return;w(null),k==null||k.capture("visual_editor_cosmos_import_started",{collection_count:h.collectionCount,reference_count:h.referenceCount});const O=++S.current;x(!0);try{if((await L9()).profile.isEnabled||await Ote(d),await Lte(h),k==null||k.capture("visual_editor_cosmos_import_completed",{reference_count:h.referenceCount}),n(),O!==S.current)return;C(),e()}catch(N){if(k==null||k.capture("visual_editor_cosmos_import_failed"),O!==S.current)return;w(N instanceof Error?N.message:"Could not start Cosmos import")}finally{O===S.current&&x(!1)}},R=O=>{u(N=>N.includes(O)?N.filter(D=>D!==O):[...N,O]),k==null||k.capture("visual_editor_cosmos_collection_toggled")};return b.jsx(uv,{open:t,onOpenChange:O=>!O&&A(),children:b.jsxs(dv,{children:[b.jsx(fv,{className:"z-max fixed inset-0 bg-black/60"}),b.jsxs(hv,{className:"z-max border-main-border bg-main font-main fixed top-1/2 left-1/2 max-h-[min(680px,calc(100vh-32px))] w-[min(440px,calc(100vw-32px))] -translate-x-1/2 -translate-y-1/2 overflow-y-auto rounded-lg border shadow-2xl outline-none",children:[b.jsxs("div",{className:"border-main-border bg-main-light flex items-center justify-between rounded-t-lg border-b px-4 py-2",children:[b.jsx(pv,{className:"text-content text-base font-medium",children:"Connect Cosmos"}),b.jsx(Qi,{onClick:A,title:"Close","aria-label":"Close",variant:"ghost",size:"icon-compact",children:b.jsx(Ob,{className:"h-4 w-4",weight:"bold"})})]}),b.jsxs("div",{className:"space-y-4 p-4",children:[b.jsx(mv,{className:"text-content-subtle text-sm",children:"Add public collections from a Cosmos profile to your design references."}),i?null:b.jsxs("form",{onSubmit:O=>void T(O),className:"space-y-4",children:[b.jsx("label",{className:"text-content block text-sm font-medium",htmlFor:"cosmos-profile-url",children:"Cosmos profile URL"}),b.jsx("input",{id:"cosmos-profile-url",type:"url",required:!0,autoFocus:!0,value:r,onChange:O=>s(O.target.value),placeholder:"https://www.cosmos.so/username",className:"border-main-border bg-main-input text-content placeholder:text-content-muted focus:border-secondary w-full rounded-md border px-3 py-2 text-sm outline-none"}),b.jsx("button",{type:"submit",disabled:_,className:"bg-secondary text-secondary-foreground hover:bg-accent rounded-md px-4 py-2 text-sm font-medium disabled:opacity-50",children:_?"Finding collections…":"Continue"})]}),i&&!h?b.jsxs("div",{className:"space-y-4",children:[b.jsxs("p",{className:"text-content text-sm font-medium",children:["Choose collections from"," ",i.profile.title||i.profile.username]}),b.jsx("div",{className:"border-main-border max-h-60 divide-y overflow-y-auto rounded-md border",children:i.collections.map(O=>b.jsxs("label",{className:"text-content hover:bg-main-light flex cursor-pointer items-center gap-3 px-3 py-2 text-sm",children:[b.jsx("input",{type:"checkbox",checked:l.includes(O.id),disabled:_,onChange:()=>R(O.id)}),b.jsx("span",{className:"min-w-0 flex-1 truncate",children:O.title}),b.jsx("span",{className:"text-content-muted text-xs",children:O.total??"—"})]},O.id))}),i.collections.length===0?b.jsx("p",{className:"text-content-muted text-sm",children:"No public collections found for this profile."}):null,b.jsxs("label",{className:"text-content flex items-center justify-between gap-3 text-sm",children:["Analysis runtime",b.jsxs("select",{value:d,disabled:_,onChange:O=>{const N=O.target.value;f(N),k==null||k.capture("visual_editor_cosmos_runtime_selected",{runtime:N})},className:"border-main-border bg-main-input rounded-md border px-2 py-1.5",children:[b.jsx("option",{value:"",disabled:!0,children:"Select a runtime"}),b.jsx("option",{value:"codex",children:"Codex"}),b.jsx("option",{value:"claude",children:"Claude"}),b.jsx("option",{value:"cursor",children:"Cursor"})]})]}),b.jsx("button",{type:"button",onClick:()=>void I(),disabled:_||l.length===0||!d,className:"bg-secondary text-secondary-foreground hover:bg-accent rounded-md px-4 py-2 text-sm font-medium disabled:opacity-50",children:_?"Preparing plan…":"Review import plan"}),b.jsx("button",{type:"button",onClick:()=>{k==null||k.capture("visual_editor_cosmos_profile_changed"),C()},disabled:_,className:"text-content-muted hover:text-content ml-3 text-sm",children:"Use another profile"})]}):null,h?b.jsxs("div",{className:"space-y-4 text-sm",children:[b.jsxs("p",{className:"text-content",children:[h.collectionCount," ",h.collectionCount===1?"collection":"collections"," ·"," ",h.referenceCount," ",h.referenceCount===1?"reference":"references"," ·"," ",h.imageCount," ",h.imageCount===1?"image":"images"]}),b.jsx("p",{className:"text-content-subtle",children:h.scopeDisclosure}),b.jsx("p",{className:"text-content-subtle",children:h.usageDisclosure}),b.jsxs("p",{className:"text-content-muted text-xs",children:[h.reusableCount," reusable · ",h.unsupportedCount," ","unsupported · runtime: ",d]}),b.jsx("button",{type:"button",onClick:()=>void M(),disabled:_,className:"bg-secondary text-secondary-foreground hover:bg-accent rounded-md px-4 py-2 text-sm font-medium disabled:opacity-50",children:_?"Starting import…":"Approve and import"}),b.jsx("button",{type:"button",onClick:()=>{k==null||k.capture("visual_editor_cosmos_plan_revised"),g(null)},disabled:_,className:"text-content-muted hover:text-content ml-3 text-sm",children:"Change selection"})]}):null,v?b.jsx("p",{role:"alert",className:"text-sm text-red-300",children:v}):null]})]})]})})},G3=Ms("ConnectorsModal"),zte=[{provider:"x",name:"X",iconClassName:"text-content",icon:b.jsx(nh,{provider:"x"})},{provider:"pinterest",name:"Pinterest",iconClassName:"text-[#e60023]",icon:b.jsx(nh,{provider:"pinterest"})},{provider:"arena",name:"Are.na",iconClassName:"text-content",icon:b.jsx(nh,{provider:"arena"})}],Ute={name:"Cosmos",iconClassName:"text-content",icon:b.jsx(nh,{provider:"cosmos"})},K3=({meta:t,status:e,actionLabel:n,buttonLabel:r,isDisabled:s,isHighlighted:i,onAction:o})=>b.jsxs("li",{className:`flex min-h-[64px] items-center gap-3 py-3 ${i?"ring-secondary -mx-2 rounded-md px-2 ring-2":""}`,children:[b.jsx("span",{className:`grid h-7 w-7 flex-none place-items-center ${t.iconClassName}`,"aria-hidden":"true",children:t.icon}),b.jsxs("div",{className:"min-w-0 flex-1",children:[b.jsx("span",{className:"text-content block text-sm font-medium",children:t.name}),b.jsx("span",{className:"text-content-muted block truncate text-xs",children:e})]}),b.jsx("button",{type:"button","aria-label":n,onClick:o,disabled:s,className:"active-push bg-main-input text-content hover:bg-main-input/80 inline-flex min-h-8 w-24 flex-none items-center justify-center rounded-md px-3 text-xs font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-50",children:r})]}),Jw=({isOpen:t,onClose:e,context:n="menu",highlightProvider:r=null})=>{var I;const{integrations:s,isLoading:i,error:o,pendingProvider:l,connect:u,disconnect:d}=Tte(),f=Ei(),[h,g]=m.useState(null),[v,w]=m.useState(!1),_=Rte(t),x=M=>s.find(R=>R.provider===M),S=m.useCallback(M=>{const R=Date.now(),O=Dl({action:"connect",outcome:"started",provider:M,entryPoint:n});f==null||f.capture(O.event,O.properties),u(M).then(N=>{const D=Date.now()-R;if(N==="connected"){const K=Dl({action:"connect",outcome:"completed",provider:M,entryPoint:n,durationMs:D});f==null||f.capture(K.event,K.properties);return}const F=Dl({action:"connect",outcome:"failed",provider:M,entryPoint:n,durationMs:D,failureReason:N==="closed"?"popup_closed":"provider_failed"});f==null||f.capture(F.event,F.properties)}).catch(N=>{const D=N instanceof Error?N.message:"Could not connect.",F=Dl({action:"connect",outcome:"failed",provider:M,entryPoint:n,durationMs:Date.now()-R,failureReason:D.includes("Popup blocked")?"popup_blocked":"request_failed"});f==null||f.capture(F.event,F.properties),G3.warn(`Connect error for ${M}:`,D),Mt.error(D)})},[u,n,f]),k=m.useCallback(M=>{const R=Date.now(),O=Dl({action:"disconnect",outcome:"started",provider:M,entryPoint:n});f==null||f.capture(O.event,O.properties),d(M).then(()=>{const N=Dl({action:"disconnect",outcome:"completed",provider:M,entryPoint:n,durationMs:Date.now()-R});f==null||f.capture(N.event,N.properties)}).catch(N=>{const D=N instanceof Error?N.message:"Could not disconnect.",F=Dl({action:"disconnect",outcome:"failed",provider:M,entryPoint:n,durationMs:Date.now()-R,failureReason:"request_failed"});f==null||f.capture(F.event,F.properties),G3.warn(`Disconnect error for ${M}:`,D),Mt.error(D)})},[n,d,f]),C=n==="onboarding",A=(I=_.data)==null?void 0:I.sources.some(M=>M.provider==="cosmos");let T=A?"Connected":"Not connected";return _.isError&&(T="Status unavailable"),_.isPending&&(T="Checking status…"),b.jsxs(b.Fragment,{children:[b.jsx(uv,{open:t,onOpenChange:M=>!M&&e(),children:b.jsxs(dv,{children:[b.jsx(fv,{className:"z-max fixed inset-0 bg-black/40"}),b.jsx(hv,{ref:g,className:"z-max border-main-border bg-main font-main fixed top-1/2 left-1/2 w-[min(440px,calc(100vw-32px))] -translate-x-1/2 -translate-y-1/2 rounded-lg border shadow-2xl outline-none",children:b.jsxs(AO,{value:h,children:[b.jsxs("div",{className:"border-main-border bg-main-light flex items-center justify-between rounded-t-lg border-b px-4 py-2",children:[b.jsx(pv,{className:"text-content text-base font-medium",children:"Connect design references"}),b.jsx(Qi,{onClick:e,title:"Close","aria-label":"Close",variant:"ghost",size:"icon-compact",children:b.jsx(Ob,{className:"h-4 w-4",weight:"bold"})})]}),b.jsxs("div",{className:"flex flex-col gap-4 p-4",children:[b.jsx(mv,{className:"text-content-subtle text-sm",children:"Connect your references to add them to your Rivet library. Rivet can use them to inspire new design directions."}),o?b.jsx("p",{className:"rounded-lg bg-red-500/10 px-4 py-3 text-[13px] font-medium text-red-300",children:o}):null,b.jsxs("ul",{className:"divide-main-border divide-y","aria-label":"Design reference services",children:[zte.map(M=>{const R=x(M.provider),O=(R==null?void 0:R.status)==="connected",N=R==null?void 0:R.externalUsername;let D=O?`Connected${N?` as @${N}`:""}`:"Not connected";i&&(D="Checking status…");const F=l===M.provider,K=O?"Disconnect":"Connect";return b.jsx(K3,{meta:M,status:D,actionLabel:`${K} ${M.name}`,buttonLabel:F?`${K}ing…`:K,isDisabled:i||F,isHighlighted:r===M.provider,onAction:()=>O?k(M.provider):S(M.provider)},M.provider)}),b.jsx(K3,{meta:Ute,status:T,actionLabel:A?"Add Cosmos profile":"Connect Cosmos",buttonLabel:A?"Add profile":"Connect",isDisabled:!1,isHighlighted:!1,onAction:()=>{f==null||f.capture("visual_editor_cosmos_modal_opened"),w(!0)}})]}),C?b.jsxs("div",{className:"flex items-center justify-between gap-4",children:[b.jsx("p",{className:"text-content-subtle text-xs",children:"You can always do this later from the account menu."}),b.jsx("button",{type:"button",onClick:e,className:"active-push bg-secondary text-secondary-foreground hover:bg-accent flex-none rounded-lg px-3.5 py-2 text-[13px] font-medium transition-colors",children:"Skip for now"})]}):null]})]})})]})}),b.jsx(Hte,{isOpen:v,onClose:()=>w(!1),onImported:()=>{_.refetch()}})]})},Y3=({className:t=""})=>b.jsx("span",{"aria-hidden":"true",className:`rivet-skeleton block rounded ${t}`.trim()}),Bte=Ms("SupportTicketModal"),X3=5e3,L_="feedback",Zte=Tn({error:Xe().optional(),details:_z([Xe(),Tn({formErrors:dd(Xe()).optional(),fieldErrors:zT(Xe(),dd(Xe()).optional()).optional()})]).optional()}),Wte=t=>{var r;if(!t)return null;const e=(r=t.formErrors)==null?void 0:r[0];if(e)return e;const n=t.fieldErrors??{};for(const s of Object.values(n)){const i=s==null?void 0:s[0];if(i)return i}return null},qte=async t=>{let e;try{const n=Zte.safeParse(await t.json());e=n.success?n.data:void 0}catch{e=void 0}if(t.status===400){if(typeof(e==null?void 0:e.details)=="string"&&e.details.trim())return e.details;if(typeof(e==null?void 0:e.details)=="object"&&e.details!==null){const n=Wte(e.details);if(n)return n}return"Please check your feedback and try again."}return t.status>=500?typeof(e==null?void 0:e.details)=="string"&&e.details.trim()?e.details:"Could not send feedback right now. Please try again later.":typeof(e==null?void 0:e.error)=="string"&&e.error.trim()?e.error:`HTTP ${t.status}`},Gte=({isOpen:t,onClose:e,contactEmail:n})=>{const r=Ei(),[s,i]=m.useState(""),[o,l]=m.useState(!1),[u,d]=m.useState(null),f=m.useCallback(()=>{i("")},[]),h=m.useCallback(()=>{o||(f(),e())},[o,e,f]),g=m.useCallback(async()=>{const x=s.trim();if(!(!x||o)){l(!0);try{const S=typeof(r==null?void 0:r.get_session_id)=="function"?r.get_session_id():void 0,k=typeof(r==null?void 0:r.get_distinct_id)=="function"?r.get_distinct_id():void 0,C=n==null?void 0:n.trim(),A=await tl("/api/support/tickets",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:L_,message:x,contactEmail:C||void 0,metadata:{posthogSessionId:S??void 0,posthogDistinctId:k??void 0,appVersion:"0.21.4",appEnvironment:"production",pageUrl:window.location.href,userAgent:navigator.userAgent,submittedAt:new Date().toISOString()}})});if(!A.ok){const T=await qte(A);throw new Error(T)}r==null||r.capture("support_ticket_submitted",{ticket_type:L_,has_posthog_session_id:!!S}),Mt.success("Feedback sent",{description:"Thanks for sharing this."}),f(),e()}catch(S){const k=S instanceof Error?S.message:"Failed to send message";r==null||r.capture("support_ticket_submit_failed",{ticket_type:L_,error:k}),Bte.error("Failed to submit support ticket:",k),Mt.error("Could not send feedback",{description:k})}finally{l(!1)}}},[n,o,s,e,r,f]),v=m.useCallback(x=>{x.key==="Enter"&&(x.metaKey||x.ctrlKey)&&(x.preventDefault(),g())},[g]),w=X3-s.length,_=o||s.trim().length===0;return b.jsx(uv,{open:t,onOpenChange:x=>!x&&h(),children:b.jsxs(dv,{children:[b.jsx(fv,{className:"z-max fixed inset-0 bg-black/40"}),b.jsx(hv,{ref:d,className:"z-max border-main-border bg-main font-main fixed top-1/2 left-1/2 w-[440px] -translate-x-1/2 -translate-y-1/2 rounded-lg border shadow-2xl outline-none",children:b.jsxs(AO,{value:u,children:[b.jsxs("div",{className:"border-main-border bg-main-light flex items-center justify-between rounded-t-lg border-b px-4 py-2",children:[b.jsx(pv,{className:"text-content text-base font-medium",children:"Send feedback"}),b.jsx(Qi,{onClick:h,disabled:o,title:"Close","aria-label":"Close",variant:"ghost",size:"icon-compact",children:b.jsx(Ob,{className:"h-4 w-4",weight:"bold"})})]}),b.jsxs("div",{className:"flex flex-col gap-3 p-4",children:[b.jsx(mv,{className:"text-content-subtle text-sm",children:"Tell us what happened or what we can improve."}),b.jsxs("div",{className:"bg-main-input rounded-lg outline outline-1 outline-transparent transition-[outline-color] focus-within:outline-white/20",children:[b.jsx("textarea",{id:"support-ticket-message","aria-label":"Your feedback",value:s,onChange:x=>i(x.target.value),onKeyDown:v,maxLength:X3,rows:6,disabled:o,placeholder:"What happened?",className:"text-content placeholder-content-subtle max-h-64 w-full resize-none overflow-y-auto bg-transparent pt-3 pr-3 pb-1 pl-3 text-sm focus:outline-none disabled:opacity-50"}),b.jsxs("div",{className:"flex items-center justify-between px-3 pt-1 pb-3",children:[b.jsx("span",{className:"text-content-subtle text-xs",children:"Context details are included automatically."}),b.jsxs("div",{className:"flex items-center gap-2",children:[w<=500&&b.jsx("span",{className:"text-content-subtle text-xs",children:w}),b.jsx(Qi,{onClick:g,disabled:_,title:"Send feedback",shortcut:"⌘↵","aria-label":"Send feedback",size:"icon-compact",children:o?b.jsx(ev,{className:"h-5 w-5 animate-spin",weight:"bold"}):b.jsx(hK,{className:"h-5 w-5",weight:"bold"})})]})]})]})]})]})})]})})},Kte=Ms("ProfileAvatar"),D9=(t,e)=>{const n=(t??"").trim();if(n)return n.split(/\s+/).filter(Boolean)[0]??"";const s=((e??"").split("@")[0]??"").split(/[._\-+]/).filter(Boolean)[0]??"";return s?s[0].toUpperCase()+s.slice(1):""},Yte=(t,e)=>D9(t,e).charAt(0).toUpperCase(),Xte=({className:t="",side:e="bottom",align:n="end"})=>{var K,B,G;const r=dte(),s=((K=r.data)==null?void 0:K.name)??null,i=((B=r.data)==null?void 0:B.email)??null,o=((G=r.data)==null?void 0:G.isAuthenticated)===!0,l=Ei(),{startLogin:u,isStartingLogin:d,loginError:f}=O9("account_menu"),[h,g]=m.useState(!1),[v,w]=m.useState(!1),[_,x]=m.useState(!1),[S,k]=m.useState(!1),{containerRef:C,onKeyDown:A,onCloseAutoFocus:T}=r9({onDismiss:()=>F(!1)}),I=Yte(s,i);if(r.isPending)return b.jsxs("span",{"data-testid":"profile-avatar-skeleton","aria-hidden":"true",className:`flex shrink-0 items-center gap-2 ${t}`.trim(),children:[b.jsx(Y3,{className:"h-8 w-8 rounded-full"}),b.jsx(Y3,{className:"h-3.5 w-16"})]});const M=D9(s,i),R=(s==null?void 0:s.trim())||null,O=(i==null?void 0:i.trim())||null,N=async()=>{k(!0);try{const H=await tl("/api/auth/logout",{method:"POST",credentials:"same-origin"});if(!H.ok)throw new Error(`Logout failed: ${H.status}`);window.location.pathname.startsWith("/rivet/library")&&BT()}catch(H){Kte.warn("Logout request failed",H),Mt.error("Could not log out. Please try again."),k(!1);return}window.location.reload()};let D="Log in";o&&(D=M||"Account"),r.error&&!r.data&&(D="Account unavailable");const F=H=>{g(H),l==null||l.capture(`visual_editor_account_menu_${H?"opened":"closed"}`,{is_authenticated:o})};return b.jsxs(b.Fragment,{children:[b.jsxs(i4,{open:h,onOpenChange:F,children:[b.jsx(o4,{asChild:!0,children:b.jsxs("button",{type:"button","aria-label":"Account","data-rivet-private":!0,className:`ph-no-capture text-content-muted hover:text-content flex shrink-0 items-center gap-2 transition-colors select-none ${t}`,children:[b.jsx("span",{className:"border-main-border bg-main-input flex h-8 w-8 items-center justify-center rounded-full border text-xs leading-none font-semibold",children:I||b.jsx(CK,{className:"h-4 w-4",weight:"bold"})}),b.jsx("span",{className:"max-w-[8rem] truncate text-sm font-medium",children:D})]})}),b.jsx(a4,{children:b.jsxs(l4,{"data-rivet-private":!0,ref:C,onKeyDown:A,onCloseAutoFocus:T,role:"menu",className:"ph-no-capture bg-popover shadow-surface-4 z-[60] min-w-[180px] rounded-lg p-1",side:e,sideOffset:6,align:n,children:[R||O?b.jsxs("div",{className:"border-main-border border-b px-3 py-2",children:[R?b.jsx("div",{className:"text-content truncate text-sm font-medium",children:R}):null,O?b.jsx("div",{className:"text-content-muted truncate text-xs",children:O}):null]}):null,b.jsxs("button",{type:"button",role:"menuitem","data-menu-item":!0,onClick:()=>{F(!1),w(!0)},disabled:!o,className:"text-content hover:bg-hover focus-visible:bg-hover mt-1 flex w-full items-center gap-2 rounded-md px-3 py-1.5 text-sm transition-colors focus:outline-none disabled:cursor-not-allowed disabled:opacity-50",children:[b.jsx(sI,{className:"h-4 w-4",weight:"bold"}),"Connect design references"]}),b.jsxs("button",{type:"button",role:"menuitem","data-menu-item":!0,onClick:()=>{F(!1),x(!0)},className:"text-content hover:bg-hover focus-visible:bg-hover mt-1 flex w-full items-center gap-2 rounded-md px-3 py-1.5 text-sm transition-colors focus:outline-none",children:[b.jsx(gK,{className:"h-4 w-4",weight:"bold"}),"Share feedback"]}),o?b.jsxs("button",{type:"button",role:"menuitem","data-menu-item":!0,onClick:N,disabled:S,className:"text-content hover:bg-hover focus-visible:bg-hover mt-1 flex w-full items-center gap-2 rounded-md px-3 py-1.5 text-sm transition-colors focus:outline-none disabled:cursor-not-allowed disabled:opacity-50",children:[b.jsx(kK,{className:"h-4 w-4",weight:"bold"}),S?"Logging out…":"Log out"]}):null,!o&&!r.error?b.jsxs("button",{type:"button",role:"menuitem","data-menu-item":!0,onClick:()=>{u()},disabled:d,className:"text-content hover:bg-hover focus-visible:bg-hover mt-1 flex w-full items-center gap-2 rounded-md px-3 py-1.5 text-sm focus:outline-none disabled:opacity-50",children:[b.jsx(SK,{className:"h-4 w-4",weight:"bold"}),d?"Logging in…":"Log in"]}):null,r.error?b.jsx("button",{type:"button",role:"menuitem","data-menu-item":!0,onClick:()=>{r.refetch()},className:"text-content mt-1 px-3 py-1.5 text-sm",children:"Retry account"}):null,f?b.jsx("p",{role:"alert",className:"max-w-64 px-3 py-2 text-sm text-red-300",children:f}):null]})})]}),v?b.jsx(Jw,{isOpen:!0,onClose:()=>w(!1)}):null,b.jsx(Gte,{isOpen:_,onClose:()=>x(!1),contactEmail:i??void 0})]})},Qte=({onClose:t,libraryOrigin:e})=>b.jsxs("div",{className:"bg-main font-main scrollbar-hide relative flex h-full w-full cursor-auto flex-col overflow-hidden shadow-2xl","data-cy":"element-inspector",children:[b.jsx(cte,{onClose:t,libraryOrigin:e}),b.jsx("div",{className:"flex min-h-0 flex-1 flex-col",children:b.jsx(Hee,{})}),b.jsx("div",{className:"border-main-border bg-main-light flex flex-shrink-0 items-center border-t px-2.5 py-2.5",children:b.jsx(Xte,{side:"top",align:"start"})})]});async function Jte(t,e){const{delaysMs:n,shouldRetry:r,onRetry:s}=e;for(let i=1;;i++)try{return await t(i)}catch(o){const l=n[i-1];if(l===void 0||r&&!r(o))throw o;s==null||s(o,i,l),await new Promise(u=>setTimeout(u,l))}}const Q3=Ms("useServerConfig"),j9=[250,500,1e3,2e3,4e3],J3=j9.length+1,ene=async()=>{var n;const t=await fetch("/api/health");if(!t.ok)throw new Error(`Failed to fetch config: ${t.status}`);const e=await t.json();if(!e.framework)throw new Error("Server did not return framework information");return{userPort:((n=e.ports)==null?void 0:n.userDevServer)||3e3,framework:e.framework}},tne=()=>{const[t,e]=m.useState(null),[n,r]=m.useState(!0),[s,i]=m.useState(null),o=m.useCallback(async()=>{try{r(!0),i(null);const l=await Jte(ene,{delaysMs:j9,onRetry:(u,d,f)=>{Q3.warn(`Server config fetch failed (attempt ${d}); retrying in ${f}ms`,u)}});return e(l),l}catch(l){const u=l instanceof Error?l.message:"Failed to fetch server config";throw i(u),Q3.warn("Error fetching server config:",l),l}finally{r(!1)}},[]);return{config:t,fetchConfig:o,isLoading:n,error:s}},nne="#1C1C20",So=[118,118,124],eP=.85,rne=3,sne=.15,Y0=36,ine=4.4,one=.7,ane=3.5,lne=.8,tP=9,cne=11,une=[1.35,1.12,.95,.85],dne=[0,1.1,2.3,3.1],fne=[0,.35,.16,.13],hne=[.9,.5,.4,.35],jl=3,N_=[[{x1:.1,y1:.08,x2:.9,y2:.92,level:0},{x1:.14,y1:.13,x2:.86,y2:.23,level:1},{x1:.14,y1:.28,x2:.3,y2:.87,level:1},{x1:.34,y1:.28,x2:.86,y2:.87,level:1},{x1:.165,y1:.155,x2:.225,y2:.205,level:2},{x1:.7,y1:.155,x2:.755,y2:.205,level:2},{x1:.775,y1:.155,x2:.83,y2:.205,level:2},{x1:.165,y1:.32,x2:.275,y2:.375,level:2},{x1:.165,y1:.415,x2:.275,y2:.47,level:2},{x1:.165,y1:.51,x2:.275,y2:.565,level:2},{x1:.37,y1:.32,x2:.585,y2:.56,level:2},{x1:.615,y1:.32,x2:.83,y2:.56,level:2},{x1:.37,y1:.61,x2:.83,y2:.83,level:2},{hline:!0,x1:.39,x2:.81,y:.685,level:3},{hline:!0,x1:.39,x2:.75,y:.755,level:3}],[{x1:.1,y1:.08,x2:.9,y2:.92,level:0},{x1:.16,y1:.17,x2:.52,y2:.45,level:1},{x1:.58,y1:.17,x2:.685,y2:.29,level:1},{x1:.715,y1:.17,x2:.84,y2:.29,level:1},{x1:.58,y1:.33,x2:.685,y2:.45,level:1},{x1:.715,y1:.33,x2:.84,y2:.45,level:1},{x1:.16,y1:.55,x2:.84,y2:.85,level:1},{x1:.19,y1:.21,x2:.36,y2:.33,level:2},{hline:!0,x1:.19,x2:.48,y:.37,level:3},{hline:!0,x1:.19,x2:.42,y:.42,level:3},{x1:.19,y1:.6,x2:.49,y2:.8,level:2},{hline:!0,x1:.53,x2:.8,y:.63,level:3},{hline:!0,x1:.53,x2:.76,y:.7,level:3},{hline:!0,x1:.53,x2:.79,y:.77,level:3}],[{x1:.1,y1:.08,x2:.9,y2:.92,level:0},{x1:.14,y1:.13,x2:.86,y2:.22,level:1},{x1:.14,y1:.28,x2:.36,y2:.87,level:1},{x1:.39,y1:.28,x2:.61,y2:.87,level:1},{x1:.64,y1:.28,x2:.86,y2:.87,level:1},{x1:.165,y1:.15,x2:.225,y2:.2,level:2},{x1:.165,y1:.32,x2:.335,y2:.52,level:2},{x1:.415,y1:.32,x2:.585,y2:.52,level:2},{x1:.665,y1:.32,x2:.835,y2:.52,level:2},{hline:!0,x1:.165,x2:.335,y:.6,level:3},{hline:!0,x1:.165,x2:.3,y:.67,level:3},{hline:!0,x1:.415,x2:.585,y:.6,level:3},{hline:!0,x1:.415,x2:.55,y:.67,level:3},{hline:!0,x1:.665,x2:.835,y:.6,level:3},{hline:!0,x1:.665,x2:.8,y:.67,level:3}],[{x1:.1,y1:.08,x2:.9,y2:.92,level:0},{x1:.3,y1:.22,x2:.7,y2:.74,level:1},{x1:.34,y1:.27,x2:.55,y2:.34,level:2},{hline:!0,x1:.36,x2:.64,y:.42,level:3},{hline:!0,x1:.36,x2:.6,y:.49,level:3},{hline:!0,x1:.36,x2:.62,y:.56,level:3},{x1:.5,y1:.63,x2:.575,y2:.69,level:2},{x1:.595,y1:.63,x2:.66,y2:.69,level:2}]],X0=t=>{let e=t|0;return e=Math.imul(e^e>>>16,73244475),e=Math.imul(e^e>>>16,73244475),e^=e>>>16,(e>>>0)/4294967296},km=t=>{const e=Math.min(1,Math.max(0,t));return e*e*(3-2*e)},$l=(t,e)=>(Math.round(t/e-.5)+.5)*e,pne=Math.sin(Math.PI/3),nP=(t,e,n,r,s)=>{if(t.beginPath(),e===0)t.arc(n,r,s,0,Math.PI*2);else if(e===1){const i=s*pne;t.moveTo(n,r-s),t.lineTo(n+i,r+s/2),t.lineTo(n-i,r+s/2),t.closePath()}else{const i=s*.85;t.rect(n-i,r-i,i*2,i*2)}t.fill()},mne=(t,e,n)=>{let r;if(n.hline){const s=Math.max(n.x1-t,t-n.x2,0),i=Math.abs(e-n.y1);r=Math.hypot(s,i)-tP}else{const s=Math.max(n.x1-t,t-n.x2,0),i=Math.max(n.y1-e,e-n.y2,0);s===0&&i===0?r=-Math.min(t-n.x1,n.x2-t,e-n.y1,n.y2-e):r=Math.hypot(s,i),r=Math.abs(r)-tP}return km(.5-r/(2*cne))},$9=({className:t="",trackGlobalLoaderCount:e=!0})=>{const n=gt(d9),r=m.useRef(null),s=m.useCallback(i=>{var N;if((N=r.current)==null||N.call(r),r.current=null,!i)return;const o=i.getContext("2d");if(!o)return;e&&n(D=>D+1);const l=window.matchMedia("(prefers-reduced-motion: reduce)").matches;let u=[],d=0,f=0,h=Y0,g=Y0,v=null,w=null,_=0,x=-1;const S=new Array(33),k=D=>{const F=Math.round(D*32);let K=S[F];if(!K){const B=F/32,G=Math.round(So[0]+(255-So[0])*B),H=Math.round(So[1]+(255-So[1])*B),Y=Math.round(So[2]+(255-So[2])*B);K=`rgba(${G}, ${H}, ${Y}, ${eP})`,S[F]=K}return K},C=D=>{const F=1-.35*D,K=Math.round(So[0]*F),B=Math.round(So[1]*F),G=Math.round(So[2]*F);return`rgba(${K}, ${B}, ${G}, ${eP})`},A=D=>{let F=Math.floor(Math.random()*N_.length);F===x&&(F=(F+1)%N_.length),x=F;const K=[0,0,0,0],B=N_[F].map((j,Q)=>{const oe=j.level,ne=K[oe]++,se=dne[oe]+ne*fne[oe],de=hne[oe]+X0(F*131+Q*17+5)*.2;if(j.hline){const ae=$l((j.y??0)*f,g);return{hline:!0,x1:$l(j.x1*d,h),x2:$l(j.x2*d,h),y1:ae,y2:ae,level:oe,start:se,dur:de}}const ve=$l(j.x1*d,h),ue=$l((j.y1??0)*f,g);return{hline:!1,x1:ve,y1:ue,x2:Math.max($l(j.x2*d,h),ve+h),y2:Math.max($l((j.y2??0)*f,g),ue+g),level:oe,start:se,dur:de}}),G=B.reduce((j,Q)=>Math.max(j,Q.start+Q.dur),0),H=u.length,Y=new Float32Array(H*jl),U=new Int16Array(H*jl).fill(-1),J=new Uint8Array(H),Z=B[0];for(let j=0;j<H;j++){const Q=u[j];Q.x>Z.x1&&Q.x<Z.x2&&Q.y>Z.y1&&Q.y<Z.y2&&(J[j]=1);const oe=j*jl;for(let ne=0;ne<B.length;ne++){const se=mne(Q.x,Q.y,B[ne]);if(se<=.02)continue;let de=oe;for(let ve=oe;ve<oe+jl;ve++){if(U[ve]===-1){de=ve;break}Y[ve]<Y[de]&&(de=ve)}(U[de]===-1||se>Y[de])&&(Y[de]=se,U[de]=ne)}}return{startT:D,buildEnd:G,els:B,frame:Z,cellQ:Y,cellEl:U,inFrame:J}},T=()=>{const D=i.getBoundingClientRect();d=Math.max(1,D.width),f=Math.max(1,D.height);const F=Math.min(2,window.devicePixelRatio||1);i.width=Math.round(d*F),i.height=Math.round(f*F),o.setTransform(F,0,0,F,0,0);const K=Math.max(8,Math.round(d/Y0)),B=Math.max(6,Math.round(f/Y0));h=d/K,g=f/B,u=[];for(let G=0;G<B;G++){const H=B>1?G/(B-1):.5,Y=ine*(1+one*.4*(H*2-1));for(let U=0;U<K;U++){const J=G*8191+U*131+1,Z={x:(U+.5)*h,y:(G+.5)*g,size:Y,seed:J,phase:X0(J),kind:0};Z.kind=Math.floor(X0(J*97)*3),u.push(Z)}}w=null,v=null},I=new Float32Array(32),M=D=>{o.fillStyle=nne,o.fillRect(0,0,d,f),v||(v=A(D+.2)),D>=v.startT+v.buildEnd+ane&&(w=v,_=D,v=A(D+.2));let F=0;w&&(F=1-km((D-_)/lne),F<=0&&(w=null));const K=v;for(let Z=0;Z<K.els.length;Z++){const j=K.els[Z];I[Z]=km(Math.min(1,Math.max(0,(D-K.startT-j.start)/j.dur)))}const B=I[0],G=C(0),H=C(B),Y=F>0?C(F):G,U=F>0?C(Math.max(B,F)):H,J=u.length;for(let Z=0;Z<J;Z++){const j=u[Z];let Q=0,oe=0;const ne=Z*jl;for(let We=ne;We<ne+jl;We++){const Ee=K.cellEl[We];if(Ee<0)break;const pt=K.cellQ[We]*I[Ee];pt>Q&&(Q=pt,oe=K.els[Ee].level)}if(w)for(let We=ne;We<ne+jl;We++){const Ee=w.cellEl[We];if(Ee<0)break;const pt=w.cellQ[We]*F;pt>Q&&(Q=pt,oe=w.els[Ee].level)}const se=D/rne+j.phase,de=Math.floor(se),ve=se-de,ue=km(Math.min(ve,1-ve)/sne),ae=Math.floor(X0(j.seed*97+de*7919)*3);ae!==j.kind&&Q<.02&&ue<.05&&(j.kind=ae);const Oe=Math.max(ue*(1-Q),Q);if(!(Oe<.01))if(Q<.02){const We=K.inFrame[Z]===1,Ee=w?w.inFrame[Z]===1:!1;We?o.fillStyle=Ee?U:H:o.fillStyle=Ee?Y:G;const pt=Math.max(We?B:0,Ee?F:0);nP(o,j.kind,j.x,j.y,j.size*Oe*(1-.2*pt))}else{o.fillStyle=k(Q);const We=1+(une[oe]-1)*Q;nP(o,j.kind,j.x,j.y,j.size*Oe*We)}}};T();let R=0;if(l)v=A(-100),M(0);else{const D=performance.now(),F=K=>{M((K-D)/1e3),R=requestAnimationFrame(F)};R=requestAnimationFrame(F)}const O=new ResizeObserver(()=>{T(),l&&(v=A(-100),M(0))});O.observe(i),r.current=()=>{cancelAnimationFrame(R),O.disconnect(),e&&n(D=>D-1)}},[e,n]);return b.jsx("canvas",{ref:s,"aria-hidden":"true",className:`h-full w-full ${t}`.trim()})},gne=async(t=null)=>{if(t)return vne(t);let e;try{e=await fetch("/api/mcp/status")}catch{return{isOk:!1,unavailableReason:"rivet_unreachable",upstreamStatus:null}}if(e.status===404||!(e.headers.get("content-type")??"").toLowerCase().includes("application/json"))return Q0();if(!e.ok)return{isOk:!1,unavailableReason:"rivet_unreachable",upstreamStatus:null};let r;try{r=await e.json()}catch{return Q0()}const s=r.devServerHealth;return s?s.ownership==="none"?{isOk:!1,unavailableReason:"upstream_unreachable",upstreamStatus:null}:s.isReachable===!0?{isOk:!0,unavailableReason:"upstream_unreachable",upstreamStatus:null}:{isOk:!1,unavailableReason:s.reason==="rivet_unreachable"?"rivet_unreachable":"upstream_unreachable",upstreamStatus:null}:Q0()},F9=async t=>{try{const e=await fetch(t);return{isOk:e.status!==502&&e.status!==503,unavailableReason:"upstream_unreachable",upstreamStatus:e.status}}catch{return{isOk:!1,unavailableReason:"rivet_unreachable",upstreamStatus:null}}},vne=t=>F9(t),Q0=()=>F9("/"),D_=Ms("usePreviewUpstreamHealth"),yne=500,_ne=4e3,wne=15e3,xne=3,bne=(t,e={})=>{const n=m.useRef(null),r=m.useRef(null),s=e.probeMsWhileDown??yne,i=e.probeMsWhileUp??_ne,o=e.firstUnreachableCaptureAfterMs??wne,l=e.rerunProbeImmediatelyOnVersion,u=e.probePath??null,d=e.skip??!1,f=m.useRef(e.onPersistentUpstreamServerErrors);f.current=e.onPersistentUpstreamServerErrors;const[h,g]=m.useState(t==="static"),[v,w]=m.useState(0),[_,x]=m.useState(null),[S,k]=m.useState(0),[C,A]=m.useState(!1),[T,I]=m.useState(!1),[M,R]=m.useState(t==="static"?null:"upstream_unreachable");return m.useEffect(()=>{if(t==="static"){g(!0),x(null),k(0),A(!1),I(!0),R(null);return}if(d){g(!1),x(null),k(0),A(!1),I(!0),R("upstream_unreachable"),n.current=null;return}let O=!0;const N=Date.now();x(N),k(0),A(!1),g(!1),I(!1),R("upstream_unreachable");const D={current:!1},F={current:!1},K={current:!1},B={current:null},G={current:!1},H={current:!1},Y={current:0},U={current:!1},J={current:null};let Z=null;const j=()=>{K.current||(K.current=!0,O&&I(!0))},Q=()=>{Z!==null&&(clearTimeout(Z),Z=null)},oe=(se,de)=>{Q(),Z=setTimeout(de,se)},ne=async()=>{var pt;if(!O)return;k(Ot=>Ot+1);const{isOk:se,unavailableReason:de,upstreamStatus:ve}=await gne(u);if(!O)return;j(),J.current=ve;const ue=se&&ve!==null&&ve>=500;ue&&H.current?Y.current+=1:se&&!ue&&(Y.current=0);const ae=Y.current>=xne;if(ae&&!U.current&&ve!==null&&(U.current=!0,Ce==null||Ce.capture("preview_upstream_error_responses",{framework:t,upstream_status:ve,consecutive_count:Y.current}),D_.warn(`Preview upstream is listening but has served ${Y.current} consecutive ${ve} responses`),(pt=f.current)==null||pt.call(f,{upstreamStatus:ve,consecutiveCount:Y.current})),se&&!ae){ue||(H.current=!0,U.current=!1);const Ot=!G.current;G.current=!0,g(!0),R(null),B.current=null,F.current=!1,A(!1),D.current?Ot&&(Ce==null||Ce.capture("preview_upstream_restored",{framework:t})):(D.current=!0,Ce==null||Ce.capture("preview_dev_server_ready",{framework:t,ready_after_ms:Date.now()-N})),oe(i,ne);return}const We=G.current;G.current=!1,g(!1),R(de),B.current===null&&(B.current=Date.now(),F.current=!1,A(!1)),We&&(Ce==null||Ce.capture("preview_upstream_lost",{framework:t,upstream_status:ve}),w(Ot=>Ot+1),D_.warn("Preview upstream became unavailable after it was ready"));const Ee=Date.now()-B.current;Ee>=o&&!F.current&&(F.current=!0,A(!0),Ce==null||Ce.capture("preview_dev_server_unreachable",{framework:t,elapsed_ms:Ee,upstream_status:J.current}),D_.warn("Dev server did not become ready within timeout window")),oe(s,ne)};return n.current=()=>oe(0,ne),oe(0,ne),()=>{O=!1,n.current=null,Q()}},[t,s,i,o,u,d]),m.useEffect(()=>{var N;if(t==="static"||l===void 0)return;const O=r.current;r.current=l,O!==null&&O!==l&&((N=n.current)==null||N.call(n))},[t,l]),{isUpstreamReady:h,iframeRemountKey:v,probeStartedAt:_,probeAttemptCount:S,isFirstUnreachableWindowExceeded:C,initialProbeComplete:T,unavailableReason:M}};function Sne(t){return t.enteringSplit&&t.isExistingSession&&t.hasActiveVariantProxy}const V9=t=>{var e;return t!=="embedded"||typeof window>"u"?"":((e=window.__RIVET_BOOTSTRAP__)==null?void 0:e.previewOrigin)??`${window.location.protocol}//localhost:${window.location.port}`},H9=({agentApplyMode:t,url:e})=>e.startsWith("/")?`${V9(t)}${e}`:e,kne="allow-scripts allow-same-origin allow-forms allow-popups allow-modals",Ene=t=>kne,Cne=Ms("PreviewSurface"),rP=(t,e)=>t==="about:blank"?"blank":t.includes("/api/variants/")?"static_artifact":e.kind==="variant"?"dev_server":"original",z9=({target:t,src:e,framework:n,remountKey:r})=>(dt(yv),b.jsx("div",{className:"relative h-full w-full",children:b.jsx("iframe",{src:e,className:"h-full w-full border-none",title:"Project Preview",sandbox:Ene(),onLoad:()=>{Ce==null||Ce.capture("preview_iframe_loaded",{framework:n,src:e}),t.kind==="variant"&&(Ce==null||Ce.capture("variants_panel.preview_displayed",{sessionId:t.sessionId,variantId:t.variantId,renderedTarget:"variant",iframeSrcKind:rP(e,t),framework:n}))},onError:()=>{Ce==null||Ce.capture("preview_iframe_load_failed",{framework:n,src:e}),t.kind==="variant"&&(Ce==null||Ce.capture("variants_panel.preview_display_failed",{sessionId:t.sessionId,variantId:t.variantId,renderedTarget:"variant",iframeSrcKind:rP(e,t),framework:n})),Cne.warn("Preview iframe failed to load",{framework:n,src:e})}},r)})),Pne=m.lazy(()=>XP(()=>Promise.resolve().then(()=>lse),void 0)),Ane={surface:"relative flex h-full w-full items-center justify-center bg-main px-6",overlay:"absolute inset-0 z-10 flex items-center justify-center bg-main/90 px-6",page:"relative flex h-screen w-full items-center justify-center bg-main px-6"},Tne={sm:"text-lg font-semibold text-content",md:"text-2xl font-semibold text-content",lg:"text-3xl font-semibold text-content"},Rne={neutral:"rounded-md border border-divider bg-transparent px-5 py-2 text-sm font-medium text-content transition-colors hover:bg-surface-3",ghost:"rounded-md px-5 py-2 text-sm font-medium text-content-muted transition-colors hover:text-content"},ju=({backdrop:t,media:e,title:n,description:r,actions:s,tone:i="neutral",fill:o="surface",size:l="md",children:u,state:d,role:f="status",busy:h=!1,className:g=""})=>{const v=m.useCallback(_=>{_&&d&&(Ce==null||Ce.capture("status_surface_shown",{state:d,tone:i,fill:o}))},[d,i,o]),w=!!(e||n||r||u||s!=null&&s.length);return b.jsxs("div",{ref:v,className:`${Ane[o]} ${g}`.trim(),role:f,"aria-live":"polite","aria-busy":h||void 0,"data-state":d,children:[t?b.jsx("div",{className:"absolute inset-0",children:t}):null,w?b.jsxs("div",{className:"relative z-10 flex max-w-sm flex-col items-center gap-5 text-center",children:[e,n?b.jsx("h2",{className:Tne[l],children:n}):null,r?b.jsx("p",{className:"text-content-muted text-base leading-relaxed",children:r}):null,u,s!=null&&s.length?b.jsx("div",{className:"flex flex-row items-center gap-3",children:s.map(_=>b.jsx("button",{type:"button",onClick:_.onClick,className:Rne[_.variant??"neutral"],children:_.label},_.label))}):null]}):null]})},ex=({loader:t="coalesce",trackGlobalLoaderCount:e,size:n="lg",...r})=>t==="coalesce"?b.jsx(ju,{...r,size:n,busy:!0,backdrop:b.jsx($9,{trackGlobalLoaderCount:e})}):t==="logo"?b.jsx(ju,{...r,size:n,busy:!0,backdrop:b.jsx(m.Suspense,{fallback:null,children:b.jsx(Pne,{className:"absolute inset-0"})})}):b.jsx(ju,{...r,size:n,busy:!0,media:b.jsx(ev,{"aria-hidden":!0,className:"text-content h-8 w-8 shrink-0 animate-spin",weight:"bold"})}),U9=({icon:t,...e})=>b.jsx(ju,{...e,tone:"neutral",media:t?b.jsx("div",{className:"text-content-muted",children:t}):void 0}),p4=t=>b.jsx(ju,{...t,tone:"error",role:"alert"}),sP="/static/",Mne=t=>{try{return new URL(t,"http://localhost").pathname.endsWith(sP)}catch{return t.endsWith(sP)}},Ine=t=>t==="spawn_error"?"The direction is saved, but its preview process didn’t start.":t==="exited"?"The direction is saved, but its preview stopped before it was ready.":t==="timeout"?"The direction is saved, but its preview took too long to become ready.":t==="dependency_install_failed"?"The direction is saved, but its dependencies couldn’t be prepared. Fix the installation error, then retry the preview.":t==="compile_error"?"The direction is saved, but its app couldn’t compile. Fix the app error, then retry the preview.":t==="missing_dev_script"?"The direction is saved, but Rivet couldn’t find a dev script to preview it.":t==="missing_static_entry"?"The direction is saved, but Rivet couldn’t find an HTML entry to preview it.":"The direction is saved, but Rivet couldn’t prepare its preview.",One=t=>t.status==="failed"&&t.errorCode==="VARIANT_VERIFICATION_UNAVAILABLE"?{state:"variant_verification_unavailable",title:"Rivet couldn’t verify this direction",description:"The worker completed, but Rivet couldn’t inspect its generated files.",detail:t.errorMessage??t.errorCode,isError:!0}:t.status==="failed"&&t.errorCode==="VARIANT_QA_FAILED"?{state:"variant_output_integrity_failed",title:"This direction couldn’t be verified",description:"The worker completed, but Rivet found a structural problem in the generated files.",detail:t.errorMessage??t.errorCode,isError:!0}:t.status==="failed"?{state:"variant_worker_failed",title:"This direction didn’t complete",description:"The worker stopped before producing a usable result.",detail:t.errorMessage??t.errorCode,isError:!0}:t.status==="cancelled"?{state:"variant_cancelled",title:"Direction was cancelled",description:"Rivet stopped before a preview was ready. Your other directions are unchanged.",isError:!1}:t.status==="succeeded"&&t.previewUnavailable&&t.previewUnavailable.reason!=="idle_timeout"?{state:"preview_unavailable",title:"Rivet couldn’t preview this direction",description:Ine(t.previewUnavailable.reason),detail:t.previewUnavailable.portInUse?"The preview port was already in use.":void 0,isError:!0}:null,Lne=({issue:t,retryTarget:e})=>{const n=Ei(),r=m.useRef(!1),[s,i]=m.useState(!1),[o,l]=m.useState(null),u=async()=>{if(!(!e||r.current)){r.current=!0,i(!0),l(null),n==null||n.capture("preview_retry_clicked",{session_id:e.sessionId,variant_id:e.variantId});try{const d=await fetch(`/api/variants/${encodeURIComponent(e.sessionId)}/preview-port`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({variantId:e.variantId,retry:!0})});if(!d.ok){const f=Tn({message:Xe().optional()}).safeParse(await d.json().catch(()=>({}))),h=f.success?f.data:{};throw new Error(h.message??"The preview could not restart. Try again.")}}catch(d){l(d instanceof Error?d.message:"The preview could not restart. Try again.")}finally{r.current=!1,i(!1)}}};return b.jsxs(ju,{fill:"overlay",size:"sm",state:t.state,role:t.isError?"alert":"status",tone:t.isError?"error":"neutral",title:t.title,description:t.description,busy:s,actions:e&&!s?[{label:"Retry preview",onClick:()=>void u()}]:void 0,children:[s?b.jsx("p",{className:"text-content-subtle text-xs",children:"Starting preview…"}):null,o?b.jsx("p",{className:"text-content-subtle text-xs",children:o}):null,t.detail?b.jsx("p",{className:"text-content-subtle text-xs leading-relaxed break-words",children:t.detail}):null]})},Nne=({isInteractionDisabled:t=!1,framework:e,userPort:n})=>{var _t;const r=dt(Bw),s=gt(Bw),i=dt(Pg),o=gt(Pg),l=dt(cp),u=dt(yv),d=dt(Zw),f=dt(Ww),h=dt(f9),g=dt(h9),v=gt(Ww),w=dt(Ko),_=dt(Sm),x=gt(Zw),S=l.active&&l.projectContext.kind==="fresh",k=dt(qw),C=l.active?l.variants.find(qe=>qe.workItemId===k&&(qe.status==="pending"||qe.status==="running"||qe.status==="succeeded"&&!qe.preview&&typeof qe.port!="number"&&(!qe.previewUnavailable||qe.previewUnavailable.reason==="idle_timeout")))??null:null,A=l.active&&l.variants.some(qe=>qe.status==="pending"||qe.status==="running"),T=S||A,I=l.active?l.variants.find(qe=>qe.workItemId===k)??null:null,M=I?One(I):null,R=e==="static"&&i!==null&&Mne(i);m.useEffect(()=>{l.active||x(!1)},[l.active,x]);const O=m.useRef(!1);m.useEffect(()=>{const qe=!!(w!=null&&w.left||w!=null&&w.right),Ke=qe&&!O.current;O.current=qe;const Ct=l.active?l.sessionId:null;!Ct||!Sne({enteringSplit:Ke,isExistingSession:l.active&&l.projectContext.kind==="existing",hasActiveVariantProxy:d&&f!==null})||(x(!1),v(null),s(Te=>Te+1),fetch(`/api/variants/${encodeURIComponent(Ct)}/preview-port`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({variantId:null})}).catch(()=>{}))},[w,l,d,f,x,v,s]);const D=m.useMemo(()=>{var Lt;if(d||i&&!R||!l.active)return null;const{stage:qe,variants:Ke}=l,Ct=qe==="ready"||qe==="degraded",Te=Ke.some(Ge=>{var Pt,as;return((Pt=Ge.refinement)==null?void 0:Pt.status)==="pending"||((as=Ge.refinement)==null?void 0:as.status)==="running"});if(!Ct&&!Te)return null;const Ye=Ke.find(Ge=>{var Pt;return Ge.status==="succeeded"&&((Pt=Ge.preview)==null?void 0:Pt.kind)==="static_artifact"});return((Lt=Ye==null?void 0:Ye.preview)==null?void 0:Lt.kind)==="static_artifact"?Ye.preview.url:null},[R,i,d,l])??i,F=m.useMemo(()=>!l.active||!D?null:l.variants.find(qe=>{var Ke;return((Ke=qe.preview)==null?void 0:Ke.kind)==="static_artifact"&&D.startsWith(qe.preview.url)})??null,[D,l]),K=m.useMemo(()=>{if((_==null?void 0:_.previewKind)==="static")return{kind:"variant",sessionId:_.sessionId,variantId:_.variantId};if(!l.active)return Cg;if(F)return{kind:"variant",sessionId:l.sessionId,variantId:F.workItemId};if(D){const Ke=D.match(/\/__rivet\/preview\/variant\/([^/]+)\/([^/?#]+)/),Ct=Ke!=null&&Ke[1]?decodeURIComponent(Ke[1]):null,Te=Ke!=null&&Ke[2]?decodeURIComponent(Ke[2]):null;if(Ct===l.sessionId&&Te&&l.variants.some(Ge=>Ge.workItemId===Te))return{kind:"variant",sessionId:l.sessionId,variantId:Te};const Ye=D.match(/\/api\/variants\/[^/]+\/static\/([^/?#]+)/),Lt=Ye!=null&&Ye[1]?decodeURIComponent(Ye[1]):null;if(Lt&&l.variants.some(Ge=>Ge.workItemId===Lt))return{kind:"variant",sessionId:l.sessionId,variantId:Lt}}const qe=!!(w!=null&&w.left||w!=null&&w.right);return(!qe||S)&&!D&&d&&f&&l.variants.some(Ke=>Ke.workItemId===f)?{kind:"variant",sessionId:l.sessionId,variantId:f}:(!qe||S)&&!D&&k&&l.variants.some(Ke=>Ke.workItemId===k)?{kind:"variant",sessionId:l.sessionId,variantId:k}:Cg},[_,F,l,d,f,D,w,S,k]),B=m.useRef(null);m.useEffect(()=>{var Te,Ye;if(!F||((Te=F.preview)==null?void 0:Te.kind)!=="static_artifact"||((Ye=F.refinement)==null?void 0:Ye.status)!=="succeeded")return;const qe=`${F.workItemId}:${F.refinement.workItemId}`;if(B.current===qe)return;B.current=qe;const Ke=F.preview.url.includes("?")?"&":"?",Ct=`${F.preview.url}${Ke}refinement=${encodeURIComponent(F.refinement.workItemId)}`;D!==Ct&&(o(Ct),s(Lt=>Lt+1))},[D,F,s,o,l]);const G=D!==null&&Iee(D),H=D!==null&&!G||S&&!d&&!G,{isUpstreamReady:Y,iframeRemountKey:U,probeAttemptCount:J,initialProbeComplete:Z}=bne(e,{rerunProbeImmediatelyOnVersion:r,probePath:G?D:null,skip:H}),[j,Q]=m.useState(()=>h&&Y?r:null),oe=m.useRef(null);m.useEffect(()=>{if(!h){oe.current=null,Q(null);return}if(j===r){oe.current=null;return}const qe=oe.current;if(!qe||qe.remountKey!==r){oe.current={remountKey:r,probeAttemptCount:J};return}Y&&J>qe.probeAttemptCount&&(oe.current=null,Q(r))},[j,r,h,J,Y]);const se=D!==null&&!G||Y,ve=g||h&&j!==r||h&&!se,ue=`${U}:${r}`,ae=x9(window.location.pathname),Oe=e==="static"?`/static${ae??"/"}`:ae??"/",We=V9(u);let Ee=null;D&&(Ee=H9({agentApplyMode:u,url:D}));const Ot=C||M||ve?"about:blank":(G&&!se?"about:blank":Ee)??(se?`${We}${Oe}`:"about:blank"),en=!!C||!!M||!se&&Z;let bt=null;if(ve)bt=b.jsx(ex,{fill:"overlay",loader:"coalesce",trackGlobalLoaderCount:!1,state:"preview_replay_boot"});else if(C)bt=b.jsx(ex,{fill:"overlay",loader:"coalesce",trackGlobalLoaderCount:!1,state:"variant_building",children:b.jsx("span",{className:"sr-only",children:"Building your direction"})});else if(M){const qe=l.active&&I&&M.state==="preview_unavailable"&&((_t=I.previewUnavailable)==null?void 0:_t.reason)!=="missing_static_entry"?{sessionId:l.sessionId,variantId:I.workItemId}:void 0;bt=b.jsx(Lne,{issue:M,retryTarget:qe},I==null?void 0:I.workItemId)}else en&&(bt=T?b.jsx(U9,{fill:"overlay",state:"preview_no_selection",title:"Nothing to preview yet",description:"Pick a direction from the panel."}):b.jsx(p4,{fill:"overlay",state:"preview_offline",title:"Preview isn't connected",description:"Rivet lost connection to your project.",actions:[{label:"Reload",onClick:()=>window.location.reload()}]}));return b.jsx("div",{className:"relative flex h-full min-h-0 w-full flex-col",children:b.jsxs("div",{className:"relative min-h-0 flex-1",children:[bt,b.jsx(z9,{target:K,src:Ot,framework:e,remountKey:ue})]})})};function iP({side:t,sessionId:e,variantId:n,url:r,label:s,source:i,isFallback:o=!1}){var C;const l=dt(Ko),u=gt(Ko),d=Ei(),f=dt(cp),h=dt(yv),g=m.useRef(!1),v=m.useCallback(()=>{g.current||(g.current=!0,gd({source:i,sessionId:e,variantId:n}))},[i,e,n]),w=m.useCallback(()=>{if(o){u(null);const M=Ag("ended",l);d==null||d.capture(M.event,M.properties);return}v();const A={...l};delete A[t];const T=A.left||A.right?A:null;u(T);const I=Ag(T?"updated":"ended",T??l);d==null||d.capture(I.event,I.properties)},[o,d,u,t,l,v]),_=m.useMemo(()=>({kind:"variant",sessionId:e,variantId:n}),[e,n]),x=m.useMemo(()=>!f.active||f.sessionId!==e?null:f.variants.find(A=>A.workItemId===n)??null,[e,n,f]),S=m.useMemo(()=>{var T,I;let A=r;if(((T=x==null?void 0:x.preview)==null?void 0:T.kind)==="static_artifact"&&((I=x.refinement)==null?void 0:I.status)==="succeeded"){const M=x.preview.url.includes("?")?"&":"?";A=`${x.preview.url}${M}refinement=${encodeURIComponent(x.refinement.workItemId)}`}return H9({agentApplyMode:h,url:A})},[h,x,r]),k=((C=x==null?void 0:x.refinement)==null?void 0:C.status)==="succeeded"?`${n}:${x.refinement.workItemId}`:n;return b.jsxs("div",{className:"variant-split-secondary","data-cy":"variant-split-pane","data-variant-id":n,children:[b.jsxs("div",{className:"variant-split-secondary-toolbar",children:[b.jsx("span",{className:"variant-split-secondary-label",title:s,children:s}),b.jsx(kc,{label:"Collapse",children:b.jsx("button",{type:"button",className:"variant-split-secondary-close",onClick:w,"aria-label":"Collapse split view",children:b.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12","aria-hidden":"true",focusable:"false",children:b.jsx("path",{d:"M2.5 2.5 L9.5 9.5 M9.5 2.5 L2.5 9.5",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round"})})})})]}),b.jsx("div",{className:"variant-split-secondary-body relative min-h-0 flex-1",children:b.jsx(z9,{target:_,src:S,framework:"static",remountKey:k})})]})}function Dne(){const t=dt(md),e=dt(u4);return!t||!e?null:ip.createPortal(b.jsx("div",{"aria-hidden":"true",className:"border-main-border bg-main pointer-events-none fixed top-0 left-0 z-[70] flex max-w-60 items-center gap-2 rounded-md border px-3 py-1.5 shadow-lg",style:{transform:`translate3d(${e.x+12}px, ${e.y+12}px, 0)`},children:b.jsx("span",{className:"text-content truncate text-sm font-medium",children:t.label})}),document.body)}function jne(){const t=dt(md),e=dt(u4),n=dt(Ko),r=gt(md),s=gt(Ko),i=Ei(),o=m.useRef(null),[l,u]=m.useState(null),[d,f]=m.useState("hidden");m.useEffect(()=>{t||(f("hidden"),u(null))},[t]);const h=m.useCallback((v,w)=>{const _=o.current;if(!_)return null;const x=_.getBoundingClientRect();return v<x.left||v>x.right||w<x.top||w>x.bottom?null:v<(x.left+x.right)/2?"left":"right"},[]);if(m.useEffect(()=>{if(!t||!e)return;const v=h(e.x,e.y);u(w=>w===v?w:v),f(w=>{if(w==="exiting")return w;const _=v!==null?"visible":"hidden";return w===_?w:_})},[t,e,h]),m.useEffect(()=>{if(!t)return;const v=w=>{const _=h(w.clientX,w.clientY);if(_&&t.url){const x={sessionId:t.sessionId,variantId:t.variantId,label:t.label,url:t.url,source:t.source},S=n==null?void 0:n[_];S&&(S.sessionId!==x.sessionId||S.variantId!==x.variantId)&&gd(S);const k={...n??{},[_]:x};s(k);const C=Ag(n?"updated":"started",k);i==null||i.capture(C.event,C.properties),f("exiting"),window.setTimeout(()=>r(null),220)}else gd(t),f("exiting"),window.setTimeout(()=>r(null),220)};return window.addEventListener("pointerup",v),window.addEventListener("pointercancel",v),()=>{window.removeEventListener("pointerup",v),window.removeEventListener("pointercancel",v)}},[t,h,i,r,s,n]),!t)return null;const g=["variant-drop-zones",d==="visible"&&"is-visible",d==="exiting"&&"is-exiting"].filter(Boolean).join(" ");return b.jsxs("div",{ref:o,className:g,"aria-hidden":"true",children:[b.jsx(oP,{side:"left",hovered:l==="left",canDrop:!!t.url,label:t.label}),b.jsx(oP,{side:"right",hovered:l==="right",canDrop:!!t.url,label:t.label})]})}function oP({side:t,hovered:e,canDrop:n,label:r}){return b.jsxs("div",{className:["variant-drop-zone",`is-${t}`,e&&"is-hover",!n&&"is-disabled"].filter(Boolean).join(" "),children:[b.jsxs("div",{className:"variant-drop-zone-inner",children:[b.jsx("div",{className:`variant-drop-zone-icon is-${t}`}),b.jsx("div",{className:"variant-drop-zone-caption",children:n?`Add ${t} split`:"Split unavailable for this direction"})]}),b.jsx("div",{className:"variant-drop-zone-preview","aria-hidden":"true",children:b.jsx("div",{className:"variant-drop-zone-preview-label",children:r})}),b.jsx("div",{className:"variant-drop-zone-border"})]})}const B9=(t,e,n)=>{var i,o;if(!t.active||t.sessionId!==e)return null;const r=t.variants.find(l=>l.workItemId===n);if(((i=r==null?void 0:r.preview)==null?void 0:i.kind)!=="static_artifact")return null;if(((o=r.refinement)==null?void 0:o.status)!=="succeeded")return r.preview.url;const s=r.preview.url.includes("?")?"&":"?";return`${r.preview.url}${s}refinement=${encodeURIComponent(r.refinement.workItemId)}`},aP=(t,e)=>{if(!t)return;const n=B9(e,t.sessionId,t.variantId);return!n||n===t.url?t:{...t,url:n}},$ne=()=>b.jsx("div",{"data-testid":"preview-boot-skeleton",role:"status","aria-busy":"true","aria-label":"Loading preview",className:"bg-main flex h-full min-h-0 w-full flex-1 flex-col p-3",children:b.jsx("div",{className:"border-main-border relative min-h-0 flex-1 overflow-hidden rounded-lg border",children:b.jsx($9,{trackGlobalLoaderCount:!1})})}),Fne=({isLoading:t=!1,isInteractionDisabled:e=!1})=>{const{config:n,fetchConfig:r,isLoading:s,error:i}=tne();return m.useEffect(()=>{r().catch(o=>{Ce==null||Ce.capture("preview_config_load_failed",{message:o instanceof Error?o.message:"unknown_error",attempts:J3})})},[r]),s?b.jsx($ne,{}):i||!n?b.jsx(p4,{fill:"surface",size:"sm",state:"preview_config_error",title:"Couldn't load preview",description:"We couldn't load the preview configuration.",actions:[{label:"Retry",onClick:()=>{Ce==null||Ce.capture("preview_config_retry_clicked"),r().catch(o=>{Ce==null||Ce.capture("preview_config_load_failed",{message:o instanceof Error?o.message:"unknown_error",attempts:J3})})}}]}):b.jsx(Vne,{isLoading:t,isInteractionDisabled:e,framework:n.framework,userPort:n.userPort})};function Vne(t){const e=dt(Ko),n=dt(md),r=dt(cp),s=dt(Pg),i=e==null?void 0:e.left,o=e==null?void 0:e.right,l=m.useMemo(()=>{var T,I;if(!r.active||r.projectContext.kind!=="fresh"||!(!!i!=!!o))return;const _=(T=i??o)==null?void 0:T.variantId,x=r.variants.filter(M=>{var R;return M.status==="succeeded"&&((R=M.preview)==null?void 0:R.kind)==="static_artifact"&&M.workItemId!==_}),S=s==null?void 0:s.replace(/[?&]refinement=[^&]*$/,""),C=x.find(M=>{var R;return((R=M.preview)==null?void 0:R.kind)==="static_artifact"&&M.preview.url===S})??x[0];if(((I=C==null?void 0:C.preview)==null?void 0:I.kind)!=="static_artifact")return;const A=B9(r,r.sessionId,C.workItemId);if(A)return{sessionId:r.sessionId,variantId:C.workItemId,label:C.label,url:A,source:"live"}},[r,i,o,s]),u=aP(i,r)??(o?l:void 0),d=aP(o,r)??(i?l:void 0),f=!i&&!!u,h=!o&&!!d,g=!!(u||d),v=b.jsx(Nne,{isInteractionDisabled:t.isInteractionDisabled,framework:t.framework,userPort:t.userPort});return b.jsx("div",{className:"relative flex h-full min-h-0 w-full flex-1 flex-col",children:b.jsxs("div",{className:`variant-preview-region relative flex h-full min-h-0 w-full flex-1 flex-col ${n?"is-dragging":""} ${g?"is-split":""}`,children:[b.jsxs("div",{className:"variant-preview-row flex h-full min-h-0 w-full flex-1",children:[u&&b.jsx(iP,{side:"left",sessionId:u.sessionId,variantId:u.variantId,url:u.url,label:u.label,source:u.source,isFallback:f},`left-${u.sessionId}:${u.variantId}:${u.url}`),!(u&&d)&&b.jsx("div",{className:"variant-preview-primary flex h-full min-h-0 flex-1 flex-col",children:v}),d&&b.jsx(iP,{side:"right",sessionId:d.sessionId,variantId:d.variantId,url:d.url,label:d.label,source:d.source,isFallback:h},`right-${d.sessionId}:${d.variantId}:${d.url}`)]}),b.jsx("div",{className:"variant-preview-atmosphere","aria-hidden":"true"}),b.jsx(jne,{}),b.jsx(Dne,{})]})})}function Mo(t){if(t===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function Z9(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}/*!
142
142
  * GSAP 3.15.0
143
143
  * https://gsap.com
144
144
  *
@@ -432,4 +432,4 @@ function useAtomValueWithDelay<Value>(
432
432
  *
433
433
  * This source code is licensed under the ISC license.
434
434
  * See the LICENSE file in the root directory of this source tree.
435
- */const UN={name:"x",size:24,node:[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]};UN.node;const Soe=lt(UN),koe={"chevron-right":Fie,"chevron-down":$ie,pipette:loe,x:Soe,copy:zie,menu:eoe,dot:Uie,monitor:noe,sun:woe,moon:roe,"rectangle-horizontal":doe,circle:Vie,"square-library":yoe,clock:Hie,star:_oe,settings:moe,plus:uoe,"arrow-left":Iie,"arrow-right":Oie,"arrow-up":Lie,search:poe,loader:Xie,users:boe,lock:Qie,mail:Jie,bell:Nie,shield:goe,palette:ioe,lightbulb:Kie,rocket:foe,heart:Zie,paintbrush:soe,brain:Die,globe:Bie,user:xoe,image:qie,link:Yie,check:jie,"rotate-ccw":hoe,play:coe,pause:ooe,home:Wie,"message-circle":toe,inbox:Gie,pencil:aoe,"skip-forward":voe},OP={lucide:koe},BN=m.createContext(null);function Eoe(t){const e=m.useContext(BN);return e?OP[e.iconLibrary][t]:OP.lucide[t]}function Coe({children:t,defaultLibrary:e="lucide"}){const[n,r]=m.useState(e),s=m.useCallback(i=>{r(i)},[]);return b.jsx(BN.Provider,{value:{iconLibrary:n,setIconLibrary:s},children:t})}const ZN=m.createContext(null);function U4(){return m.useContext(ZN)}const WN=m.createContext(null);function qN(){const t=m.useContext(WN);if(!t)throw new Error("AccordionTrigger/AccordionContent must be used within an AccordionItem");return t}const Poe=m.forwardRef((t,e)=>{const{children:n,type:r="single",className:s,...i}=t,o=m.useRef(null),l=m.useRef(new Map),[u,d]=m.useState(new Map),{activeIndex:f,setActiveIndex:h,itemRects:g,sessionRef:v,handlers:w,registerItem:_,measureItems:x}=n9(o),S=m.useCallback((ue,ae)=>{ae?l.current.set(ue,ae):l.current.delete(ue)},[]),k=m.useCallback(()=>{if(!o.current)return;const ue=new Map;l.current.forEach((ae,Oe)=>{ue.set(Oe,{top:ae.offsetTop,left:ae.offsetLeft,width:ae.offsetWidth,height:ae.offsetHeight})}),d(ue)},[]),[C,A]=m.useState(()=>r==="single"?t.defaultValue??"":""),[T,I]=m.useState(()=>r==="multiple"?t.defaultValue??[]:[]),M=t.onValueChange,R=t.onValueChange,O=t.value,N=new Set(r==="multiple"?t.value??T:(()=>{const ue=t.value??C;return ue?[ue]:[]})()),D=m.useCallback(ue=>{const ae=t;ae.onValueChange?ae.onValueChange(ue):A(ue)},[M]),F=m.useCallback(ue=>{const ae=t;ae.onValueChange?ae.onValueChange(ue):I(ue)},[R]),K=m.useCallback(ue=>{if(r==="multiple"){const ae=t.value??T;F(ae.filter(Oe=>Oe!==ue))}else D("")},[r,D,F,T,O]);m.useEffect(()=>{x(),k()},[x,k,n]);const B=[...N].join(",");m.useEffect(()=>{x(),k()},[x,k,B]);const[G,H]=m.useState(null),Y=f!==null?g[f]:null,U=G!==null?g[G]:null,J=f!==null&&!u.has(f),Z=op(),{value:j,defaultValue:Q,onValueChange:oe,collapsible:ne,type:se,...de}=i,ve=r==="multiple"?{type:"multiple",value:t.value??T,onValueChange:F}:{type:"single",collapsible:t.collapsible??!0,value:t.value??C,onValueChange:D};return b.jsx(ZN.Provider,{value:{registerItem:_,registerFullItem:S,activeIndex:f,grouped:!0,remeasure:()=>{x(),k()},openValues:N,openItemRects:u,toggleValue:K},children:b.jsx(GL,{...ve,asChild:!0,children:b.jsxs("div",{ref:ue=>{o.current=ue,typeof e=="function"?e(ue):e&&(e.current=ue)},onMouseEnter:w.onMouseEnter,onMouseMove:ue=>{const ae=o.current;if(ae){const Oe=ae.getBoundingClientRect(),We=ae.offsetHeight,Ee=Oe.height,pt=We>0?Ee/We:1,Ot=(ue.clientY-Oe.top)/pt+ae.scrollTop;for(const[en,bt]of u){const _t=g[en];if(!_t)continue;const qe=_t.top+_t.height,Ke=bt.top+bt.height;if(Ot>=qe&&Ot<=Ke){h(null);return}}}w.onMouseMove(ue)},onMouseLeave:w.onMouseLeave,onFocus:ue=>{var Oe;const ae=(Oe=ue.target.closest("[data-proximity-index]"))==null?void 0:Oe.getAttribute("data-proximity-index");if(ae!=null){const We=Number(ae);h(We),H(ue.target.matches(":focus-visible")?We:null)}},onBlur:ue=>{var ae;(ae=o.current)!=null&&ae.contains(ue.relatedTarget)||(H(null),h(null))},className:Ut("relative flex flex-col gap-0.5 w-72 max-w-full",s),...de,children:[b.jsx(Cs,{children:[...u.entries()].map(([ue,ae])=>b.jsx(Ho.div,{className:`absolute ${Z.bg} bg-accent/20 dark:bg-accent/12 pointer-events-none`,initial:!1,animate:{top:ae.top,left:ae.left,width:ae.width,height:ae.height,opacity:J?.7:1},exit:{opacity:0,transition:{duration:.12}},transition:{top:{duration:0},left:{duration:0},width:{duration:0},height:{duration:0},opacity:{duration:.08}}},`expanded-${ue}`))}),b.jsx(Cs,{children:Y&&b.jsx(Ho.div,{className:`absolute ${Z.bg} bg-hover pointer-events-none`,initial:{opacity:0,top:Y.top,left:Y.left,width:Y.width,height:Y.height},animate:{opacity:1,top:Y.top,left:Y.left,width:Y.width,height:Y.height},exit:{opacity:0,transition:{duration:.06}},transition:{...Lh.fast,opacity:{duration:.08}}},v.current)}),b.jsx(Cs,{children:U&&b.jsx(Ho.div,{className:`absolute ${Z.focusRing} pointer-events-none z-20 border border-[#6B97FF]`,initial:!1,animate:{left:U.left-2,top:U.top-2,width:U.width+4,height:U.height+4},exit:{opacity:0,transition:{duration:.06}},transition:{...Lh.fast,opacity:{duration:.08}}})}),n]})})})});Poe.displayName="AccordionGroup";const GN=m.forwardRef(({children:t,type:e="single",collapsible:n=!0,defaultValue:r,value:s,onValueChange:i,className:o,...l},u)=>{const[d,f]=m.useState(()=>e==="single"?r??"":""),[h,g]=m.useState(()=>e==="multiple"?r??[]:[]),v=new Set(e==="multiple"?s??h:(()=>{const k=s??d;return k?[k]:[]})()),w=m.useCallback(k=>{i?i(k):f(k)},[i]),_=m.useCallback(k=>{i?i(k):g(k)},[i]),x=m.useCallback(k=>{e==="multiple"?_((s??h).filter(A=>A!==k)):w("")},[e,s,h,w,_]),S=e==="multiple"?{type:"multiple",value:s??h,defaultValue:r,onValueChange:_}:{type:"single",collapsible:n,value:s??d,defaultValue:r,onValueChange:w};return b.jsx(GL,{...S,asChild:!0,children:b.jsx("div",{ref:u,className:Ut("w-72 max-w-full flex flex-col gap-0.5",o),...l,children:b.jsx(KN.Provider,{value:v,children:b.jsx(YN.Provider,{value:x,children:t})})})})});GN.displayName="Accordion";const KN=m.createContext(new Set),YN=m.createContext(()=>{}),XN=m.forwardRef(({value:t,index:e,disabled:n,children:r,className:s,...i},o)=>{const l=m.useRef(null),u=U4(),d=m.useContext(KN),f=m.useContext(YN),h=op(),g=u!=null&&u.grouped?u.openValues.has(t):d.has(t),v=m.useRef(null),w=m.useCallback(()=>{u!=null&&u.grouped?u.toggleValue(t):f(t)},[u,f,t]);return m.useEffect(()=>{if(u!=null&&u.grouped&&e!==void 0)return u.registerItem(e,v.current),()=>u.registerItem(e,null)},[e,u]),m.useEffect(()=>{if(u!=null&&u.grouped&&e!==void 0)return g?u.registerFullItem(e,l.current):u.registerFullItem(e,null),()=>u.registerFullItem(e,null)},[e,u,g]),b.jsx(WN.Provider,{value:{index:e,value:t,isOpen:g,onToggle:w,triggerRef:v},children:b.jsxs(gie,{ref:_=>{l.current=_,typeof o=="function"?o(_):o&&(o.current=_)},value:t,disabled:n,"data-proximity-index":e,className:Ut(!(u!=null&&u.grouped)&&"relative",s),...i,children:[!(u!=null&&u.grouped)&&b.jsx(Cs,{children:g&&b.jsx(Ho.div,{className:`absolute inset-0 ${h.bg} bg-accent/20 dark:bg-accent/12 pointer-events-none`,initial:{opacity:0},animate:{opacity:1},exit:{opacity:0,transition:{duration:.06}},transition:{duration:.08}})}),r]})})});XN.displayName="AccordionItem";const QN=m.forwardRef(({children:t,className:e,...n},r)=>{const s=Eoe("chevron-right"),i=U4(),{index:o,isOpen:l,triggerRef:u}=qN(),d=op(),[f,h]=m.useState(!1),g=i!=null&&i.grouped?i.activeIndex===o:f,v=b.jsx(yie,{asChild:!0,children:b.jsx("div",{children:b.jsxs(_ie,{ref:r,className:Ut(`relative z-10 flex items-center gap-2.5 ${d.item} px-3 py-2 w-full cursor-pointer outline-none select-none`,!(i!=null&&i.grouped)&&"focus-visible:ring-1 focus-visible:ring-[#6B97FF] focus-visible:ring-offset-0",e),...n,children:[b.jsxs("span",{className:"inline-grid text-[13px] flex-1 text-left",children:[b.jsx("span",{className:"col-start-1 row-start-1 invisible",style:{fontVariationSettings:rh.semibold},"aria-hidden":"true",children:t}),b.jsx("span",{className:Ut("col-start-1 row-start-1 transition-[color,font-variation-settings] duration-80",l||g?"text-foreground":"text-muted-foreground"),style:{fontVariationSettings:l?rh.semibold:rh.normal},children:t})]}),b.jsx(Ho.span,{className:"shrink-0 inline-flex items-center justify-center",animate:{rotate:l?90:0},transition:Lh.fast,children:b.jsx(s,{size:16,strokeWidth:l||g?2:1.5,className:Ut("transition-[color,stroke-width] duration-80",l||g?"text-foreground":"text-muted-foreground")})})]})})});return i!=null&&i.grouped?b.jsx("div",{ref:u,children:v}):b.jsxs("div",{className:"relative",onMouseEnter:()=>h(!0),onMouseLeave:()=>h(!1),children:[b.jsx(Cs,{children:f&&b.jsx(Ho.div,{className:`absolute inset-0 ${d.bg} bg-hover pointer-events-none`,initial:{opacity:0},animate:{opacity:1},exit:{opacity:0,transition:{duration:.06}},transition:{duration:.08}})}),v]})});QN.displayName="AccordionTrigger";const JN=m.forwardRef(({children:t,className:e,...n},r)=>{const s=U4(),{isOpen:i}=qN();return b.jsx(Cs,{initial:!1,children:i&&b.jsx(xie,{forceMount:!0,asChild:!0,...n,children:b.jsx(Ho.div,{ref:r,className:Ut("overflow-hidden",e),initial:{height:0},animate:{height:"auto"},exit:{height:0},transition:{...Lh.moderate,bounce:0},onUpdate:()=>{s==null||s.remeasure()},onAnimationComplete:()=>{s==null||s.remeasure()},children:b.jsx("div",{className:"px-3 pb-3 pt-1 text-[13px] text-muted-foreground",children:t})})})})});JN.displayName="AccordionContent";const Rm=({children:t,defaultValue:e=[],className:n=""})=>b.jsx(GN,{type:"multiple",defaultValue:e,className:Ut("w-full",n),children:t}),Aoe=({value:t,title:e,description:n,dataCy:r,icon:s,children:i,className:o=""})=>{const l=o.includes("first-item");return b.jsxs(XN,{value:t,className:Ut("w-full",!l&&"border-t border-main-border"),children:[b.jsxs(QN,{"data-cy":r,children:[s?b.jsx("span",{className:"mr-1 inline-flex items-center",children:s}):null,e]}),b.jsxs(JN,{children:[n?b.jsx("p",{className:"pb-2 text-sm text-content-subtle",children:n}):null,i]})]})};Rm.Item=Aoe;const Toe=({message:t,isLoading:e=!0})=>b.jsxs("div",{className:"flex items-center gap-2 text-sm text-content",children:[e?b.jsx(ev,{className:"h-4 w-4 shrink-0 animate-spin text-primary",weight:"bold"}):null,b.jsx("span",{className:"whitespace-pre-wrap font-sans",children:t})]}),Roe=()=>{const t=m.useRef(Date.now()),[e,n]=m.useState(0);return m.useEffect(()=>{const r=()=>n(Math.max(0,Math.floor((Date.now()-t.current)/1e3)));r();const s=setInterval(r,1e3);return()=>clearInterval(s)},[]),e},Moe=t=>{const e=Math.floor(t/60),n=t%60;return`${e}:${n.toString().padStart(2,"0")}`},LP="M 12 8 C 14.21 8 16 9.79 16 12 C 16 14.21 14.21 16 12 16 C 9.79 16 8 14.21 8 12 C 8 9.79 9.79 8 12 8 Z",NP="M 12 12 C 14 8.5 19 8.5 19 12 C 19 15.5 14 15.5 12 12 C 10 8.5 5 8.5 5 12 C 5 15.5 10 15.5 12 12 Z",Ioe="M 12 16 C 14.21 16 16 14.21 16 12 C 16 9.79 14.21 8 12 8 C 9.79 8 8 9.79 8 12 C 8 14.21 9.79 16 12 16 Z",Mm=["Applying","Thinking","Planning","Crafting"],Ooe=Mm.reduce((t,e)=>t.length>=e.length?t:e),Loe=20,Noe="Still working — runs can take a few minutes.",Doe=({hint:t,showElapsed:e=!0})=>{const[n,r]=m.useState(0),s=Roe();m.useEffect(()=>{const o=setInterval(()=>{r(l=>(l+1)%Mm.length)},4e3);return()=>clearInterval(o)},[]);const i=t??(e&&s>=Loe?Noe:null);return b.jsxs("div",{role:"status",className:"flex items-center gap-2 px-3 py-1","data-cy":"thinking-indicator",children:[b.jsx(Si.svg,{"aria-hidden":!0,width:20,height:20,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0 text-muted-foreground",children:b.jsx(Si.path,{animate:{d:[LP,NP,Ioe,NP,LP]},transition:{d:{duration:6,ease:"easeInOut",repeat:1/0,times:[0,.25,.5,.75,1]}}})}),b.jsxs("span",{className:"inline-grid overflow-hidden text-sm font-medium",style:{fontVariationSettings:rh.medium},children:[b.jsx("span",{className:"shimmer-text invisible col-start-1 row-start-1","aria-hidden":"true",children:Ooe}),b.jsx(Cs,{mode:"popLayout",initial:!1,children:b.jsx(Si.span,{className:"shimmer-text col-start-1 row-start-1",initial:{y:"80%",opacity:0},animate:{y:0,opacity:1,transition:{duration:.24,ease:[.4,0,.2,1]}},exit:{y:"-80%",opacity:0,transition:{duration:.16,ease:[.4,0,.2,1]}},children:Mm[n]},Mm[n])})]}),e?b.jsx("span",{className:"text-xs tabular-nums text-content-subtle","data-cy":"thinking-elapsed",children:Moe(s)}):null,i?b.jsx("span",{className:"text-xs text-content-subtle",children:i}):null]})};var joe=Object.defineProperty,$oe=(t,e)=>joe(t,"name",{value:e,configurable:!0});function $g(t,[e,n]){return Math.min(n,Math.max(e,t))}$oe($g,"clamp");var Foe=Object.defineProperty,Voe=(t,e)=>Foe(t,"name",{value:e,configurable:!0});function eD(t){const e=m.useRef({value:t,previous:t});return m.useMemo(()=>(e.current.value!==t&&(e.current.previous=e.current.value,e.current.value=t),e.current.previous),[t])}Voe(eD,"usePrevious");var Hoe=Object.defineProperty,jt=(t,e)=>Hoe(t,"name",{value:e,configurable:!0}),DP={Horizontal:"horizontal"},zoe={LTR:"ltr"},tD=["PageUp","PageDown"],nD=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],rD={"from-left":["Home","PageDown","ArrowDown","ArrowLeft"],"from-right":["Home","PageDown","ArrowDown","ArrowRight"],"from-bottom":["Home","PageDown","ArrowDown","ArrowLeft"],"from-top":["Home","PageDown","ArrowUp","ArrowLeft"]},hp="Slider",[_x,Uoe,Boe]=L4(hp),[B4,Fae]=so(hp,[Boe]),[Zoe,pp]=B4(hp),Woe=m.forwardRef(jt(function(e,n){const{name:r,min:s=0,max:i=100,step:o=1,orientation:l=DP.Horizontal,disabled:u=!1,minStepsBetweenThumbs:d=0,preserveThumbOrder:f=!1,defaultValue:h=[s],value:g,onValueChange:v=jt(()=>{},"onValueChange"),onValueCommit:w=jt(()=>{},"onValueCommit"),inverted:_=!1,form:x,...S}=e,k=m.useRef(new Set),C=m.useRef(0),A=m.useRef(!1),I=l===DP.Horizontal?qoe:Goe,[M,R]=m.useState(null),O=Jt(n,R),[N=[],D]=cl({prop:g,defaultProp:h,onChange:jt(U=>{var Z;(Z=[...k.current][C.current])==null||Z.focus({preventScroll:!0,focusVisible:A.current}),A.current=!1,v(U)},"onChange")}),F=m.useRef(N),K=m.useRef(N);m.useEffect(()=>{const U=x?M==null?void 0:M.ownerDocument.getElementById(x):M==null?void 0:M.closest("form");if(U instanceof HTMLFormElement){const J=jt(()=>D(K.current),"reset");return U.addEventListener("reset",J),()=>U.removeEventListener("reset",J)}},[M,x,D]);function B(U){const J=dD(N,U);Y(U,J)}jt(B,"handleSlideStart");function G(U){Y(U,C.current)}jt(G,"handleSlideMove");function H(){String(N)!==String(F.current)&&w(N)}jt(H,"handleSlideEnd");function Y(U,J,{commit:Z}={commit:!1}){const j=W4(o),Q=lh(Math.round((U-s)/o)*o+s,j),oe=$g(Q,[s,i]);D((ne=[])=>{const se=d*o,de=f?$g(oe,[ne[J-1]===void 0?s:ne[J-1]+se,ne[J+1]===void 0?i:ne[J+1]-se]):oe,ve=cD(ne,de,J);if(pD(ve,se)){C.current=f?J:ve.indexOf(de);const ue=String(ve)!==String(ne);return ue&&Z&&w(ve),ue?ve:ne}else return ne})}return jt(Y,"updateValues"),b.jsx(Zoe,{scope:e.__scopeSlider,name:r,disabled:u,min:s,max:i,valueIndexToChangeRef:C,thumbs:k.current,values:N,orientation:l,form:x,children:b.jsx(_x.Provider,{scope:e.__scopeSlider,children:b.jsx(_x.Slot,{scope:e.__scopeSlider,children:b.jsx(I,{"aria-disabled":u,"data-disabled":u?"":void 0,...S,ref:O,onPointerDown:Yt(S.onPointerDown,()=>{u||(F.current=N,A.current=!1)}),min:s,max:i,inverted:_,onSlideStart:u?void 0:B,onSlideMove:u?void 0:G,onSlideEnd:u?void 0:H,onHomeKeyDown:()=>{u||(A.current=!0,Y(s,0,{commit:!0}))},onEndKeyDown:()=>{u||(A.current=!0,Y(i,N.length-1,{commit:!0}))},onStepKeyDown:({event:U,direction:J})=>{if(!u){A.current=!0;const Q=tD.includes(U.key)||U.shiftKey&&nD.includes(U.key)?10:1,oe=C.current,ne=N[oe],se=mD(ne,{min:s,step:o,direction:J,multiplier:Q});Y(se,oe,{commit:!0})}}})})})})},"Slider")),[sD,iD]=B4(hp,{startEdge:"left",endEdge:"right",size:"width",direction:1}),qoe=m.forwardRef(jt(function(e,n){const{min:r,max:s,dir:i,inverted:o,onSlideStart:l,onSlideMove:u,onSlideEnd:d,onStepKeyDown:f,...h}=e,[g,v]=m.useState(null),w=Jt(n,v),_=m.useRef(void 0),x=$4(i),S=x===zoe.LTR,k=S&&!o||!S&&o;function C(A){const T=_.current||g.getBoundingClientRect(),I=[0,T.width],R=Cv(I,k?[r,s]:[s,r]);return _.current=T,R(A-T.left)}return jt(C,"getValueFromPointer"),b.jsx(sD,{scope:e.__scopeSlider,startEdge:k?"left":"right",endEdge:k?"right":"left",direction:k?1:-1,size:"width",children:b.jsx(oD,{dir:x,"data-orientation":"horizontal",...h,ref:w,style:{...h.style,"--radix-slider-thumb-transform":"translateX(-50%)"},onSlideStart:A=>{const T=C(A.clientX);l==null||l(T)},onSlideMove:A=>{const T=C(A.clientX);u==null||u(T)},onSlideEnd:()=>{_.current=void 0,d==null||d()},onStepKeyDown:A=>{const I=rD[k?"from-left":"from-right"].includes(A.key);f==null||f({event:A,direction:I?-1:1})}})})},"SliderHorizontal")),Goe=m.forwardRef(jt(function(e,n){const{min:r,max:s,inverted:i,onSlideStart:o,onSlideMove:l,onSlideEnd:u,onStepKeyDown:d,...f}=e,h=m.useRef(null),g=Jt(n,h),v=m.useRef(void 0),w=!i;function _(x){const S=v.current||h.current.getBoundingClientRect(),k=[0,S.height],A=Cv(k,w?[s,r]:[r,s]);return v.current=S,A(x-S.top)}return jt(_,"getValueFromPointer"),b.jsx(sD,{scope:e.__scopeSlider,startEdge:w?"bottom":"top",endEdge:w?"top":"bottom",size:"height",direction:w?1:-1,children:b.jsx(oD,{"data-orientation":"vertical",...f,ref:g,style:{...f.style,"--radix-slider-thumb-transform":"translateY(50%)"},onSlideStart:x=>{const S=_(x.clientY);o==null||o(S)},onSlideMove:x=>{const S=_(x.clientY);l==null||l(S)},onSlideEnd:()=>{v.current=void 0,u==null||u()},onStepKeyDown:x=>{const k=rD[w?"from-bottom":"from-top"].includes(x.key);d==null||d({event:x,direction:k?-1:1})}})})},"SliderVertical")),oD=m.forwardRef(jt(function(e,n){const{__scopeSlider:r,onSlideStart:s,onSlideMove:i,onSlideEnd:o,onHomeKeyDown:l,onEndKeyDown:u,onStepKeyDown:d,...f}=e,h=pp(hp,r);return b.jsx(En.span,{...f,ref:n,onKeyDown:Yt(e.onKeyDown,g=>{g.key==="Home"?(l(g),g.preventDefault()):g.key==="End"?(u(g),g.preventDefault()):tD.concat(nD).includes(g.key)&&(d(g),g.preventDefault())}),onPointerDown:Yt(e.onPointerDown,g=>{const v=g.target;v.setPointerCapture(g.pointerId),g.preventDefault(),h.thumbs.has(v)?v.focus({preventScroll:!0,focusVisible:!1}):s(g)}),onPointerMove:Yt(e.onPointerMove,g=>{g.target.hasPointerCapture(g.pointerId)&&i(g)}),onPointerUp:Yt(e.onPointerUp,g=>{const v=g.target;v.hasPointerCapture(g.pointerId)&&(v.releasePointerCapture(g.pointerId),o(g))})})},"SliderImpl")),Koe="SliderTrack",Yoe=m.forwardRef(jt(function(e,n){const{__scopeSlider:r,...s}=e,i=pp(Koe,r);return b.jsx(En.span,{"data-disabled":i.disabled?"":void 0,"data-orientation":i.orientation,...s,ref:n})},"SliderTrack")),jP="SliderRange",Xoe=m.forwardRef(jt(function(e,n){const{__scopeSlider:r,...s}=e,i=pp(jP,r),o=iD(jP,r),l=m.useRef(null),u=Jt(n,l),d=i.values.length,f=i.values.map(v=>Z4(v,i.min,i.max)),h=d>1?Math.min(...f):0,g=100-Math.max(...f);return b.jsx(En.span,{"data-orientation":i.orientation,"data-disabled":i.disabled?"":void 0,...s,ref:u,style:{...e.style,[o.startEdge]:h+"%",[o.endEdge]:g+"%"}})},"SliderRange")),Qoe="SliderThumb",[Joe,aD]=B4(Qoe),eae="SliderThumbProvider";function lD(t){const{__scopeSlider:e,name:n,children:r,internal_do_not_use_render:s}=t,i=pp(eae,e),o=Uoe(e),[l,u]=m.useState(null),d=m.useMemo(()=>l?o().findIndex(x=>x.ref.current===l):-1,[o,l]),f=Zb(l),h=l?!!i.form||!!l.closest("form"):!0,g=i.values[d],v=n??(i.name?i.name+(i.values.length>1?"[]":""):void 0),w=g===void 0?0:Z4(g,i.min,i.max);m.useEffect(()=>{if(l)return i.thumbs.add(l),()=>{i.thumbs.delete(l)}},[l,i.thumbs]);const _={value:g,name:v,form:i.form,isFormControl:h,index:d,thumb:l,onThumbChange:u,percent:w,size:f};return b.jsx(Joe,{scope:e,..._,children:gD(s)?s(_):r})}jt(lD,"SliderThumbProvider");var X_="SliderThumbTrigger",tae=m.forwardRef(jt(function(e,n){const{__scopeSlider:r,...s}=e,i=pp(X_,r),o=iD(X_,r),{index:l,value:u,percent:d,size:f,onThumbChange:h}=aD(X_,r),g=Jt(n,h),v=uD(l,i.values.length),w=f==null?void 0:f[o.size],_=w?fD(w,d,o.direction):0;return b.jsx("span",{style:{transform:"var(--radix-slider-thumb-transform)",position:"absolute",[o.startEdge]:`calc(${d}% + ${_}px)`},children:b.jsx(_x.ItemSlot,{scope:r,children:b.jsx(En.span,{role:"slider","aria-label":e["aria-label"]||v,"aria-valuemin":i.min,"aria-valuenow":u,"aria-valuemax":i.max,"aria-orientation":i.orientation,"data-orientation":i.orientation,"data-disabled":i.disabled?"":void 0,tabIndex:i.disabled?void 0:0,...s,ref:g,style:u===void 0?{display:"none"}:e.style,onFocus:Yt(e.onFocus,()=>{i.valueIndexToChangeRef.current=l})})})})},"SliderThumbTrigger")),nae=m.forwardRef(jt(function(e,n){const{__scopeSlider:r,name:s,...i}=e;return b.jsx(lD,{__scopeSlider:r,name:s,internal_do_not_use_render:({index:o,isFormControl:l})=>b.jsxs(b.Fragment,{children:[b.jsx(tae,{...i,ref:n,__scopeSlider:r}),l?b.jsx(sae,{__scopeSlider:r},o):null]})})},"SliderThumb")),rae="SliderBubbleInput",sae=m.forwardRef(jt(function({__scopeSlider:e,...n},r){const{value:s,name:i,form:o}=aD(rae,e),l=m.useRef(null),u=Jt(l,r),d=eD(s);return m.useEffect(()=>{const f=l.current;if(!f)return;const h=window.HTMLInputElement.prototype,v=Object.getOwnPropertyDescriptor(h,"value").set;if(d!==s&&v){const w=new Event("input",{bubbles:!0});v.call(f,s),f.dispatchEvent(w)}},[d,s]),b.jsx(En.input,{style:{display:"none"},name:i,form:o,...n,ref:u,defaultValue:s})},"SliderBubbleInput"));function cD(t=[],e,n){const r=[...t];return r[n]=e,r.sort((s,i)=>s-i)}jt(cD,"getNextSortedValues");function Z4(t,e,n){const i=100/(n-e)*(t-e);return $g(i,[0,100])}jt(Z4,"convertValueToPercentage");function uD(t,e){return e>2?`Value ${t+1} of ${e}`:e===2?["Minimum","Maximum"][t]:void 0}jt(uD,"getLabel");function dD(t,e){if(t.length===1)return 0;const n=t.map(s=>Math.abs(s-e)),r=Math.min(...n);return n.indexOf(r)}jt(dD,"getClosestValueIndex");function fD(t,e,n){const r=t/2,i=Cv([0,50],[0,r]);return(r-i(e)*n)*n}jt(fD,"getThumbInBoundsOffset");function hD(t){return t.slice(0,-1).map((e,n)=>t[n+1]-e)}jt(hD,"getStepsBetweenValues");function pD(t,e){if(e>0){const n=hD(t);return Math.min(...n)>=e}return!0}jt(pD,"hasMinStepsBetweenValues");function Cv(t,e){return n=>{if(t[0]===t[1]||e[0]===e[1])return e[0];const r=(e[1]-e[0])/(t[1]-t[0]);return e[0]+r*(n-t[0])}}jt(Cv,"linearScale");function W4(t){if(!Number.isFinite(t))return 0;const e=t.toString();if(e.includes("e")){const[r,s]=e.split("e"),i=r.split(".")[1]||"",o=Number(s);return Math.max(0,i.length-o)}const n=e.split(".")[1];return n?n.length:0}jt(W4,"getDecimalCount");function lh(t,e){const n=Math.pow(10,e);return Math.round(t*n)/n}jt(lh,"roundValue");function mD(t,{min:e,step:n,direction:r,multiplier:s}){const i=W4(n),o=(t-e)/n,l=Math.round(o),u=lh(l*n+e,i)===lh(t,i);let d;return u?d=l+s*r:r>0?d=Math.ceil(o):d=Math.floor(o),lh(d*n+e,i)}jt(mD,"getNextStepValue");function gD(t){return typeof t=="function"}jt(gD,"isFunction");const wx=m.forwardRef(({className:t,...e},n)=>b.jsxs(Woe,{ref:n,className:Ut("relative flex w-full touch-none select-none items-center","data-[disabled]:opacity-50",t),...e,children:[b.jsx(Yoe,{className:"relative h-1 w-full grow overflow-hidden rounded-full bg-input",children:b.jsx(Xoe,{className:"absolute h-full bg-primary"})}),b.jsx(nae,{className:Ut("block h-3.5 w-3.5 rounded-full border border-border bg-foreground shadow-sm","transition-transform hover:scale-110 active:scale-95","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#6B97FF]","disabled:pointer-events-none")})]}));wx.displayName="Slider";const iae=[{name:"surface-1",utility:"bg-surface-1",className:"bg-surface-1"},{name:"surface-2",utility:"bg-surface-2",className:"bg-surface-2"},{name:"surface-3",utility:"bg-surface-3",className:"bg-surface-3"},{name:"surface-4",utility:"bg-surface-4",className:"bg-surface-4"},{name:"surface-5",utility:"bg-surface-5",className:"bg-surface-5"},{name:"surface-6",utility:"bg-surface-6",className:"bg-surface-6"}],oae=[{name:"primary",utility:"bg-primary",className:"bg-primary"},{name:"selected",utility:"bg-selected",className:"bg-selected"},{name:"accent",utility:"bg-accent",className:"bg-accent"},{name:"success",utility:"bg-accent-success",className:"bg-accent-success"},{name:"warning",utility:"bg-accent-warning",className:"bg-accent-warning"},{name:"error",utility:"bg-accent-error",className:"bg-accent-error"}],aae=[{name:"gap-1",className:"w-1"},{name:"gap-2",className:"w-2"},{name:"gap-3",className:"w-3"},{name:"gap-4",className:"w-4"},{name:"gap-6",className:"w-6"},{name:"gap-8",className:"w-8"}],tm=[{name:"Accordion",path:"components/Accordion.tsx",status:"showcased",note:"Reusable primitive shown with local item composition."},{name:"AgentVariantsPanel",path:"components/AgentVariantsPanel.tsx",status:"feature-only",note:"Requires live variant session state and editor atoms."},{name:"AuthProgressScreen",path:"components/AuthProgressScreen.tsx",status:"feature-only",note:"Auth flow surface; represented through progress treatment."},{name:"AuthScreenView",path:"components/AuthScreenView.tsx",status:"feature-only",note:"Auth flow surface that depends on sign-in actions."},{name:"Button",path:"components/Button.tsx",status:"showcased",note:"Reusable tooltip-wrapped button shown in multiple states."},{name:"CommentCarouselLayer",path:"components/CommentCarouselLayer.tsx",status:"feature-only",note:"Preview overlay layer tied to iframe geometry."},{name:"CommentMarker",path:"components/CommentMarker.tsx",status:"feature-only",note:"Preview overlay marker tied to comment positions."},{name:"CommentPopover",path:"components/CommentPopover.tsx",status:"feature-only",note:"Comment workflow popover tied to editor state."},{name:"CommentReferenceChip",path:"components/CommentReferenceChip.tsx",status:"feature-only",note:"Comment workflow chip tied to selected references."},{name:"CommentReferencePicker",path:"components/CommentReferencePicker.tsx",status:"feature-only",note:"Comment workflow picker tied to preview elements."},{name:"ElementInspector",path:"components/ElementInspector.tsx",status:"feature-only",note:"Primary editor surface with many app-level dependencies."},{name:"GitHome",path:"components/GitHome.tsx",status:"feature-only",note:"Git dashboard tied to repository state."},{name:"IframePreview",path:"components/IframePreview.tsx",status:"unsuitable",note:"Needs live iframe target and cross-window integration."},{name:"PreviewFrame",path:"components/PreviewFrame.tsx",status:"unsuitable",note:"Requires proxied app URL and iframe lifecycle."},{name:"PreviewSurface",path:"components/PreviewSurface.tsx",status:"unsuitable",note:"Requires preview iframe and overlay orchestration."},{name:"ProfileAvatar",path:"components/ProfileAvatar.tsx",status:"feature-only",note:"Account chrome tied to user identity data."},{name:"Progress",path:"components/Progress.tsx",status:"showcased",note:"Reusable inline loading/status primitive."},{name:"SecondaryVariantIframe",path:"components/SecondaryVariantIframe.tsx",status:"unsuitable",note:"Requires variant preview iframe lifecycle."},{name:"SparkleLoader",path:"components/SparkleLoader.tsx",status:"showcased",note:"Reusable loading animation shown in feedback states."},{name:"SplitButton",path:"components/SplitButton.tsx",status:"showcased",note:"Reusable compound action button shown with dropdown."},{name:"StatusSurface",path:"components/StatusSurface.tsx",status:"showcased",note:"Unified full-surface primitive: LoadingSurface / EmptyState / ErrorState."},{name:"SupportTicketModal",path:"components/SupportTicketModal.tsx",status:"feature-only",note:"Support workflow modal tied to form submission."},{name:"ThinkingIndicator",path:"components/ThinkingIndicator.tsx",status:"showcased",note:"Reusable thinking/loading indicator shown in feedback states."},{name:"Tooltip",path:"components/Tooltip.tsx",status:"showcased",note:"Reusable tooltip API shown with hover target."},{name:"VariantDragGhost",path:"components/VariantDragGhost.tsx",status:"feature-only",note:"Drag visual tied to variant split interactions."},{name:"VariantSplitDropZones",path:"components/VariantSplitDropZones.tsx",status:"feature-only",note:"Drop-zone visual tied to variant split interactions."},{name:"ui/accordion",path:"components/ui/accordion.tsx",status:"showcased",note:"Radix accordion primitive backing the local Accordion showcase."},{name:"ui/slider",path:"components/ui/slider.tsx",status:"showcased",note:"Radix slider primitive shown in enabled and disabled states."},{name:"ui/tooltip",path:"components/ui/tooltip.tsx",status:"showcased",note:"Radix tooltip primitive shown with forced-open preview."}],lae=()=>{window.location.hash=""},ko=({title:t,eyebrow:e,description:n,children:r})=>b.jsxs("section",{className:"border-border bg-card shadow-surface-3 rounded-2xl border p-5",children:[b.jsxs("div",{className:"mb-5 max-w-2xl",children:[b.jsx("p",{className:"text-primary text-xs font-semibold tracking-[0.18em] uppercase",children:e}),b.jsx("h2",{className:"text-foreground mt-2 text-xl font-semibold",children:t}),b.jsx("p",{className:"text-muted-foreground mt-2 text-sm leading-6",children:n})]}),r]}),$P=({swatches:t})=>b.jsx("div",{className:"grid gap-3 sm:grid-cols-2 lg:grid-cols-3",children:t.map(e=>b.jsxs("div",{className:"border-border bg-surface-2 rounded-xl border p-3",children:[b.jsx("div",{className:`h-16 rounded-lg ${e.className}`}),b.jsxs("div",{className:"mt-3 flex items-center justify-between gap-3",children:[b.jsx("span",{className:"text-foreground text-sm font-medium",children:e.name}),b.jsx("code",{className:"bg-muted text-muted-foreground rounded px-2 py-1 text-xs",children:e.utility})]})]},e.name))}),cae=t=>t==="showcased"?"border-accent-success/40 bg-accent-success/10 text-accent-success":t==="cataloged"?"border-primary/40 bg-primary/10 text-primary":t==="generated"?"border-accent/40 bg-accent/10 text-accent":t==="unsuitable"?"border-accent-warning/40 bg-accent-warning/10 text-accent-warning":"border-border bg-surface-4 text-content-muted",uae=()=>{const t=tm.filter(n=>n.status==="showcased").length,e=tm.filter(n=>n.status==="cataloged").length;return b.jsx("main",{className:"bg-main font-main text-content h-screen overflow-y-auto",children:b.jsxs("div",{className:"mx-auto flex w-full max-w-6xl flex-col gap-6 px-6 py-6 lg:px-8",children:[b.jsxs("header",{className:"border-border bg-surface-2 shadow-surface-4 rounded-3xl border p-6",children:[b.jsxs("button",{type:"button",onClick:lae,className:"text-content-subtle hover:text-content mb-6 inline-flex items-center gap-2 text-sm transition-colors",children:[b.jsx(dK,{className:"h-4 w-4",weight:"bold"}),"Back to editor"]}),b.jsxs("div",{className:"flex flex-col gap-5 lg:flex-row lg:items-end lg:justify-between",children:[b.jsxs("div",{className:"max-w-3xl",children:[b.jsx("p",{className:"text-primary text-xs font-semibold tracking-[0.22em] uppercase",children:"Local component gallery"}),b.jsx("h1",{className:"text-foreground mt-3 text-4xl font-semibold tracking-tight",children:"Rivet design system"}),b.jsx("p",{className:"text-muted-foreground mt-3 text-base leading-7",children:"A Storybook-like route for checking the current UI primitives, tokens, and interaction states inside the Vite app."})]}),b.jsx("div",{className:"border-border bg-surface-3 rounded-2xl border p-4",children:b.jsxs("div",{className:"text-content-muted flex items-center gap-3 text-sm",children:[b.jsx(sI,{className:"text-primary h-5 w-5",weight:"bold"}),"Open with ",b.jsx("code",{className:"text-content",children:"#/design-system"})]})})]})]}),b.jsx(ko,{eyebrow:"Controls",title:"Button, split button, and tooltip",description:"Rivet's shared Button exposes variants and sizes backed by Fluid Functionalism, alongside the split button and tooltip controls.",children:b.jsxs("div",{className:"grid gap-4 lg:grid-cols-[1fr_1fr]",children:[b.jsxs("div",{className:"border-border bg-surface-2 rounded-xl border p-4",children:[b.jsx("p",{className:"text-foreground mb-3 text-sm font-medium",children:"Rivet Button"}),b.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[b.jsx(Qi,{title:"Primary action",shortcut:"D",variant:"primary",children:"Design action"}),b.jsx(Qi,{title:"Secondary action",variant:"secondary",children:"Secondary"}),b.jsx(Qi,{title:"Disabled action",disabled:!0,variant:"tertiary",children:"Disabled"}),b.jsx(_9,{primaryLabel:"Ship",primaryIcon:g_,primaryAction:()=>{},dropdownItems:[{label:"Create PR",onClick:()=>{}},{label:"Copy branch",onClick:()=>{}}]})]})]}),b.jsxs("div",{className:"border-border bg-surface-2 rounded-xl border p-4",children:[b.jsx("p",{className:"text-foreground mb-3 text-sm font-medium",children:"Tooltip states"}),b.jsxs("div",{className:"flex flex-wrap items-center gap-4",children:[b.jsx(kc,{label:"Rivet tooltip API",side:"bottom",children:b.jsx("button",{className:"border-border bg-surface-4 text-content rounded-lg border px-4 py-2 text-sm",children:"Hover target"})}),b.jsx(Yb,{content:"Forced open preview",forceOpen:!0,side:"right",children:b.jsx("button",{className:"bg-selected text-content rounded-lg px-4 py-2 text-sm",children:"UI tooltip"})})]})]})]})}),b.jsx(ko,{eyebrow:"Tokens",title:"Surface ladder",description:"Surface tokens move from the base app background toward raised panels without leaving the dark Rivet palette.",children:b.jsx($P,{swatches:iae})}),b.jsx(ko,{eyebrow:"Tokens",title:"Color roles",description:"Named roles should communicate purpose: brand, selection, neutral accent, and outcome colors.",children:b.jsx($P,{swatches:oae})}),b.jsx(ko,{eyebrow:"Type",title:"Typography",description:"Satoshi remains the default UI voice with clear hierarchy and muted support text.",children:b.jsxs("div",{className:"grid gap-4 lg:grid-cols-3",children:[b.jsxs("div",{className:"border-border bg-surface-2 rounded-xl border p-4",children:[b.jsx("p",{className:"text-primary text-xs tracking-[0.18em] uppercase",children:"Display"}),b.jsx("p",{className:"text-foreground mt-2 text-3xl font-semibold tracking-tight",children:"Visual edits, quickly"})]}),b.jsxs("div",{className:"border-border bg-surface-2 rounded-xl border p-4",children:[b.jsx("p",{className:"text-foreground text-sm font-semibold",children:"Panel heading"}),b.jsx("p",{className:"text-muted-foreground mt-2 text-sm leading-6",children:"Body copy uses compact line height and muted contrast for dense inspector panels."})]}),b.jsxs("div",{className:"border-border bg-surface-2 rounded-xl border p-4",children:[b.jsx("p",{className:"text-content-subtle text-xs font-medium tracking-[0.16em] uppercase",children:"Micro label"}),b.jsx("code",{className:"bg-muted text-muted-foreground mt-3 block rounded-lg px-3 py-2 text-xs",children:"font-main text-content"})]})]})}),b.jsx(ko,{eyebrow:"Layout",title:"Spacing rhythm",description:"A compact spacing scale keeps editor chrome dense while preserving scannable groupings.",children:b.jsx("div",{className:"border-border bg-surface-2 rounded-xl border p-4",children:b.jsx("div",{className:"flex flex-col gap-3",children:aae.map(n=>b.jsxs("div",{className:"flex items-center gap-4",children:[b.jsx("code",{className:"text-muted-foreground w-16 text-xs",children:n.name}),b.jsx("div",{className:`${n.className} bg-primary h-4 rounded`}),b.jsx("div",{className:"bg-border h-px flex-1"})]},n.name))})})}),b.jsx(ko,{eyebrow:"Primitives",title:"Accordion and slider",description:"Representative Radix primitives styled through the local component layer.",children:b.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[b.jsxs(Rm,{defaultValue:["foundations"],className:"border-border bg-surface-2 rounded-xl border p-2",children:[b.jsx(Rm.Item,{value:"foundations",title:"Foundations",description:"Tokens, surfaces, type, and spacing.",className:"first-item",icon:b.jsx(g_,{className:"text-primary h-4 w-4"}),children:b.jsx("p",{children:"Use these pieces before adding one-off visual rules."})}),b.jsx(Rm.Item,{value:"components",title:"Components",description:"Buttons, tooltips, accordions, sliders.",children:b.jsx("p",{children:"Keep states visible in this route as the system evolves."})})]}),b.jsxs("div",{className:"border-border bg-surface-2 rounded-xl border p-5",children:[b.jsx("p",{className:"text-foreground mb-5 text-sm font-medium",children:"Slider states"}),b.jsxs("div",{className:"space-y-6",children:[b.jsx(wx,{defaultValue:[64],max:100,step:1}),b.jsx(wx,{defaultValue:[36],max:100,step:1,disabled:!0})]})]})]})}),b.jsx(ko,{eyebrow:"Feedback",title:"Motion and loading",description:"Loading states use existing CSS animation utilities and avoid per-frame React work where possible.",children:b.jsxs("div",{className:"grid gap-4 sm:grid-cols-3",children:[b.jsxs("div",{className:"border-border bg-surface-2 rounded-xl border p-4",children:[b.jsx("p",{className:"text-foreground mb-4 text-sm font-medium",children:"Progress"}),b.jsx(Toe,{message:"Applying visual change..."})]}),b.jsxs("div",{className:"border-border bg-surface-2 rounded-xl border p-4",children:[b.jsx("p",{className:"text-foreground mb-4 text-sm font-medium",children:"Sparkle strip"}),b.jsx(f4,{className:"text-primary text-xl"})]}),b.jsxs("div",{className:"border-border bg-surface-2 rounded-xl border p-4",children:[b.jsx("p",{className:"text-foreground mb-4 text-sm font-medium",children:"Shimmer text"}),b.jsx("span",{className:"shimmer-text text-sm font-medium",children:"Generating variants"})]}),b.jsx("div",{className:"border-border bg-surface-2 rounded-xl border p-4 sm:col-span-3",children:b.jsx(Doe,{hint:"Reading selected elements"})})]})}),b.jsx(ko,{eyebrow:"Feedback",title:"Status surfaces",description:"The unified full-surface system: one StatusSurface primitive with LoadingSurface / EmptyState / ErrorState wrappers. Every full-page loading, empty, and error state routes through these so they share layout, copy tone, and a single status_surface_shown impression event. Inline loaders (Sparkle, ThinkingIndicator, above) stay inline and are deliberately not part of this system.",children:b.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[b.jsx("div",{className:"border-border relative h-56 overflow-hidden rounded-xl border",children:b.jsx(ex,{fill:"surface",loader:"coalesce",trackGlobalLoaderCount:!1})}),b.jsx("div",{className:"border-border relative h-56 overflow-hidden rounded-xl border",children:b.jsx(U9,{icon:b.jsx(g_,{size:32}),title:"Nothing to preview yet",description:"Pick a direction from the panel."})}),b.jsx("div",{className:"border-border relative h-56 overflow-hidden rounded-xl border",children:b.jsx(p4,{fill:"surface",size:"sm",title:"Preview isn't connected",description:"Rivet lost connection to your project.",actions:[{label:"Reload",onClick:()=>{}}]})})]})}),b.jsxs(ko,{eyebrow:"Inventory",title:"Component coverage",description:"Every current component file is accounted for here. Reusable primitives are rendered above; app surfaces that need live editor, git, auth, iframe, or generated state are cataloged instead of mounted unsafely.",children:[b.jsxs("div",{className:"mb-4 grid gap-3 sm:grid-cols-3",children:[b.jsxs("div",{className:"border-border bg-surface-2 rounded-xl border p-4",children:[b.jsx("p",{className:"text-content-subtle text-xs tracking-[0.16em] uppercase",children:"Total components"}),b.jsx("p",{className:"text-foreground mt-2 text-2xl font-semibold",children:tm.length})]}),b.jsxs("div",{className:"border-border bg-surface-2 rounded-xl border p-4",children:[b.jsx("p",{className:"text-content-subtle text-xs tracking-[0.16em] uppercase",children:"Showcased"}),b.jsx("p",{className:"text-accent-success mt-2 text-2xl font-semibold",children:t})]}),b.jsxs("div",{className:"border-border bg-surface-2 rounded-xl border p-4",children:[b.jsx("p",{className:"text-content-subtle text-xs tracking-[0.16em] uppercase",children:"Cataloged"}),b.jsx("p",{className:"text-primary mt-2 text-2xl font-semibold",children:e})]})]}),b.jsxs("div",{className:"border-border overflow-hidden rounded-xl border",children:[b.jsxs("div",{className:"border-border bg-surface-3 text-content-subtle grid grid-cols-[minmax(140px,1fr)_minmax(110px,auto)_minmax(220px,2fr)] border-b px-4 py-3 text-xs font-semibold tracking-[0.14em] uppercase",children:[b.jsx("span",{children:"Component"}),b.jsx("span",{children:"Status"}),b.jsx("span",{children:"Coverage note"})]}),b.jsx("div",{className:"divide-border bg-surface-2 divide-y",children:tm.map(n=>b.jsxs("div",{className:"grid grid-cols-[minmax(140px,1fr)_minmax(110px,auto)_minmax(220px,2fr)] gap-3 px-4 py-3 text-sm",children:[b.jsxs("div",{children:[b.jsx("p",{className:"text-foreground font-medium",children:n.name}),b.jsx("code",{className:"text-muted-foreground text-xs",children:n.path})]}),b.jsx("div",{children:b.jsx("span",{className:`inline-flex rounded-full border px-2 py-1 text-xs font-medium ${cae(n.status)}`,children:n.status})}),b.jsx("p",{className:"text-muted-foreground",children:n.note})]},n.path))})]})]})]})})},dae=t=>(t.startsWith("#/")?t.slice(2):t.slice(1)).split("?")[0]==="design-system"?"design-system":"editor",xx=274,Fg=395,Q_=Math.min(Fg,Math.round((xx+Fg)/2*1.1)),FP="rivet:panelWidth:v2",fae=t=>{if(!(t instanceof HTMLElement))return!1;const e=t.tagName.toLowerCase();return t.isContentEditable||e==="input"||e==="textarea"||e==="select"},hae=({projectPath:t,libraryOrigin:e})=>{const n=dt(d9)>0,[r,s]=QT(c9),i=lG(),[o,l]=m.useState(()=>{if(typeof window>"u")return Q_;const T=Number(window.localStorage.getItem(FP));return Number.isFinite(T)&&T>=xx&&T<=Fg?T:Q_}),[u,d]=m.useState(!1),[f,h]=m.useState(Ese),g=r?o:0,[v,w]=m.useState(r);m.useEffect(()=>{if(!r){w(!1);return}h(T=>kse({position:T,boundsLeftPx:o}))},[r,o]),m.useEffect(()=>{window.localStorage.setItem(FP,String(o))},[o]),m.useEffect(()=>{if(!r)return;const T=I=>{I.key==="Escape"&&(fae(I.target)||(I.preventDefault(),s(!1)))};return window.addEventListener("keydown",T),()=>window.removeEventListener("keydown",T)},[r,s]);const _=m.useCallback(T=>{T.preventDefault(),T.stopPropagation();const I=T.clientX,M=o;d(!0);const R=N=>{const D=Math.min(Fg,Math.max(xx,M+(N.clientX-I)));l(D)},O=()=>{window.removeEventListener("pointermove",R),window.removeEventListener("pointerup",O),window.removeEventListener("pointercancel",O),d(!1)};window.addEventListener("pointermove",R),window.addEventListener("pointerup",O),window.addEventListener("pointercancel",O)},[o]),x=m.useCallback(()=>l(Q_),[]),S=Vse(),k=dt(vv);Use({enabled:!k});const C=S.isProcessing?"Completing authentication...":null,A=gt(d4);return m.useEffect(()=>{A(t??null)},[t,A]),b.jsxs(Si.div,{className:"relative flex h-screen overflow-hidden",initial:!1,animate:{opacity:1},transition:{duration:.5,ease:"easeOut"},"data-cy":"rivet-app",children:[C!==null?b.jsx("div",{className:"absolute inset-0 z-50",children:b.jsx(dse,{message:C})}):null,b.jsx(Fne,{}),b.jsx(b.Fragment,{children:n?null:b.jsxs(b.Fragment,{children:[b.jsx("div",{className:"relative order-first h-full flex-shrink-0",style:{width:v?o:0},children:b.jsxs(Si.div,{className:"absolute inset-y-0 left-0 z-30",initial:!1,animate:{x:r?0:-o},transition:i?{duration:0}:{duration:.2,ease:[.22,1,.36,1]},onAnimationComplete:()=>{r&&w(!0)},style:{width:o,willChange:"transform"},children:[b.jsx(Qte,{onClose:()=>s(!1),libraryOrigin:e}),b.jsx("div",{role:"separator","aria-orientation":"vertical","aria-label":"Resize panel",onPointerDown:_,onDoubleClick:x,className:"group/resize absolute inset-y-0 right-0 z-20 flex w-3 cursor-col-resize touch-none justify-end",children:b.jsx("span",{className:`h-full transition-all duration-150 ${u?"bg-content-muted w-0.5":"bg-divider group-hover/resize:bg-content-muted w-px group-hover/resize:w-0.5"}`})})]})}),u&&b.jsx("div",{className:"fixed inset-0 z-[100] cursor-col-resize"}),b.jsx(Ase,{isVisible:!0,isPanelOpen:r,isReducedMotion:!!i,position:f,dragBoundsLeftPx:g,onPositionChange:h,onToggle:()=>s(T=>!T)})]})}),b.jsx($G,{duration:5e3,richColors:!0,toastOptions:{style:{maxHeight:"150px",overflow:"hidden"}}})]})},bx="rivet_connect_deep_link",pae=()=>{if(typeof window>"u")return null;const t=new URLSearchParams(window.location.search),e=t.get("connect"),n=e??window.sessionStorage.getItem(bx);if(n!=="pinterest"&&n!=="arena"&&n!=="x")return null;if(window.sessionStorage.setItem(bx,n),e){t.delete("connect");const r=t.toString();window.history.replaceState(null,document.title,window.location.pathname+(r?`?${r}`:"")+window.location.hash)}return n},mae=pae(),gae=()=>{const[t,e]=m.useState(window.location.hash),[n]=m.useState(()=>typeof window<"u"&&window.sessionStorage.getItem(Tg)==="1"),[r,s]=m.useState(!1),[i,o]=m.useState(mae);m.useEffect(()=>{n&&window.sessionStorage.removeItem(Tg)},[n]);const{config:l,refetchConfig:u,loading:d,error:f}=$se(),h=gt(vv),{startLogin:g,isStartingLogin:v,loginError:w}=O9(),[_,x]=m.useState(!1);m.useEffect(()=>{l!=null&&l.userId?(Ce.identify(l.userId,{...l.email?{email:l.email}:{}}),l.email&&Ce.alias(l.email,l.userId)):l!=null&&l.email&&Ce.identify(l.email,{email:l.email})},[l==null?void 0:l.userId,l==null?void 0:l.email]),m.useEffect(()=>{l&&Ce.register({source:"visual_editor",surface:"visual_editor"})},[l]);const S=l!=null&&l.agentModeAvailable!==!0,k=dae(t),C=m.useCallback(async()=>{x(!0),h(!0);try{await u()}finally{h(!1),x(!1)}},[u,h]);if(m.useEffect(()=>{const M=()=>{const R=window.location.hash;e(R)};return window.addEventListener("hashchange",M),()=>window.removeEventListener("hashchange",M)},[]),k==="design-system")return b.jsx(uae,{});if(!d&&l===null&&!_){const M=f||"Could not load Rivet configuration.";return b.jsx("div",{className:"bg-main flex h-screen items-center justify-center px-6",children:b.jsxs("div",{className:"border-divider bg-main w-full max-w-md rounded-lg border p-6 text-center shadow-lg",children:[b.jsx("p",{className:"text-content text-sm font-medium",children:"We could not start Rivet yet."}),b.jsx("p",{className:"text-content-dim mt-2 text-xs",children:M}),b.jsx("button",{type:"button",className:"border-divider text-content hover:bg-main/80 mt-4 rounded-md border px-3 py-1.5 text-xs",onClick:()=>{C()},children:"Retry"})]})})}if(S)return b.jsx(cse,{isSigningIn:v,onStartSignIn:()=>{g()},errorMessage:w,displayMode:"full"});const T=(l==null?void 0:l.agentModeAvailable)===!0&&i!==null,I=(l==null?void 0:l.agentModeAvailable)===!0&&n&&!r&&!T;return b.jsxs(b.Fragment,{children:[b.jsx(hae,{projectPath:l==null?void 0:l.projectPath,libraryOrigin:(l==null?void 0:l.libraryOrigin)??null}),b.jsx(Jw,{context:"onboarding",isOpen:I,onClose:()=>s(!0)}),b.jsx(Jw,{context:"menu",isOpen:T,highlightProvider:i,onClose:()=>{window.sessionStorage.removeItem(bx),o(null)}})]})},vae=m.lazy(()=>XP(()=>import("./LibraryEntry-B5kPF3Ey.js"),[])),vD=window.location.pathname.startsWith("/rivet/library"),yae="phc_Ntj9tXHbS64XgYxlTfhglRmFivFsfm0AERph4ZlnNH",_ae=new Cj,wae={session_recording:{maskAllInputs:!0,maskTextSelector:"[data-rivet-private]"}},xae=()=>b.jsx("div",{style:{display:"flex",height:"100vh",alignItems:"center",justifyContent:"center"},children:b.jsx("p",{style:{fontSize:"14px",color:"#6b7280"},children:"Something went wrong. Please reload the page."})}),yD=document.getElementById("root");if(!yD)throw new Error("Rivet root element is missing");const VP=()=>Oz.createRoot(yD).render(b.jsx(we.StrictMode,{children:b.jsx(HH,{apiKey:yae,options:{api_host:"https://rivet-proxy.onrender.com/ingest",ui_host:"https://us.posthog.com",person_profiles:"always",capture_exceptions:!0,autocapture:!0,capture_pageview:!0,capture_performance:!0,persistence:"localStorage",...wae,mask_all_text:!1,mask_all_element_attributes:!1,loaded:t=>{t.register({source:"visual_editor",surface:"visual_editor",telemetry_version:2,rivet_version:"0.21.2",env:"production"})}},children:b.jsx(qH,{fallback:b.jsx(xae,{}),children:b.jsx(ej,{client:_ae,children:b.jsx(RY,{defaultShape:"rounded",children:b.jsx(Coe,{defaultLibrary:"lucide",children:vD?b.jsx(m.Suspense,{fallback:b.jsx("div",{className:"bg-background h-screen"}),children:b.jsx(vae,{})}):b.jsx(gae,{})})})})})})}));vD?Ez().then(VP):VP();export{kae as $,dv as A,Qi as B,fv as C,uv as D,hv as E,pv as F,mv as G,Mt as H,fse as I,ip as J,poe as K,ZT as L,uh as M,dI as N,jie as O,i4 as P,wj as Q,nh as R,Qh as S,Zg as T,Tn as U,Xe as V,HT as W,Soe as X,dd as Y,mE as Z,_z as _,Pj as a,bY as a0,xe as a1,xz as a2,xh as a3,Nae as a4,Dae as a5,Cz as a6,dte as a7,Ut as a8,Rae as a9,Mae as aa,Iie as ab,Xte as ac,$G as ad,ate as ae,Aae as af,Pae as ag,Eae as ah,O9 as ai,kz as aj,Sz as ak,Cae as al,Rj as b,m as c,Mj as d,Lj as e,Ij as f,Sj as g,ch as h,Kr as i,Nj as j,Dj as k,Oj as l,s5 as m,pr as n,lt as o,Ei as p,r9 as q,n5 as r,ay as s,b as t,JP as u,Pw as v,o4 as w,a4 as x,l4 as y,aoe as z};
435
+ */const UN={name:"x",size:24,node:[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]};UN.node;const Soe=lt(UN),koe={"chevron-right":Fie,"chevron-down":$ie,pipette:loe,x:Soe,copy:zie,menu:eoe,dot:Uie,monitor:noe,sun:woe,moon:roe,"rectangle-horizontal":doe,circle:Vie,"square-library":yoe,clock:Hie,star:_oe,settings:moe,plus:uoe,"arrow-left":Iie,"arrow-right":Oie,"arrow-up":Lie,search:poe,loader:Xie,users:boe,lock:Qie,mail:Jie,bell:Nie,shield:goe,palette:ioe,lightbulb:Kie,rocket:foe,heart:Zie,paintbrush:soe,brain:Die,globe:Bie,user:xoe,image:qie,link:Yie,check:jie,"rotate-ccw":hoe,play:coe,pause:ooe,home:Wie,"message-circle":toe,inbox:Gie,pencil:aoe,"skip-forward":voe},OP={lucide:koe},BN=m.createContext(null);function Eoe(t){const e=m.useContext(BN);return e?OP[e.iconLibrary][t]:OP.lucide[t]}function Coe({children:t,defaultLibrary:e="lucide"}){const[n,r]=m.useState(e),s=m.useCallback(i=>{r(i)},[]);return b.jsx(BN.Provider,{value:{iconLibrary:n,setIconLibrary:s},children:t})}const ZN=m.createContext(null);function U4(){return m.useContext(ZN)}const WN=m.createContext(null);function qN(){const t=m.useContext(WN);if(!t)throw new Error("AccordionTrigger/AccordionContent must be used within an AccordionItem");return t}const Poe=m.forwardRef((t,e)=>{const{children:n,type:r="single",className:s,...i}=t,o=m.useRef(null),l=m.useRef(new Map),[u,d]=m.useState(new Map),{activeIndex:f,setActiveIndex:h,itemRects:g,sessionRef:v,handlers:w,registerItem:_,measureItems:x}=n9(o),S=m.useCallback((ue,ae)=>{ae?l.current.set(ue,ae):l.current.delete(ue)},[]),k=m.useCallback(()=>{if(!o.current)return;const ue=new Map;l.current.forEach((ae,Oe)=>{ue.set(Oe,{top:ae.offsetTop,left:ae.offsetLeft,width:ae.offsetWidth,height:ae.offsetHeight})}),d(ue)},[]),[C,A]=m.useState(()=>r==="single"?t.defaultValue??"":""),[T,I]=m.useState(()=>r==="multiple"?t.defaultValue??[]:[]),M=t.onValueChange,R=t.onValueChange,O=t.value,N=new Set(r==="multiple"?t.value??T:(()=>{const ue=t.value??C;return ue?[ue]:[]})()),D=m.useCallback(ue=>{const ae=t;ae.onValueChange?ae.onValueChange(ue):A(ue)},[M]),F=m.useCallback(ue=>{const ae=t;ae.onValueChange?ae.onValueChange(ue):I(ue)},[R]),K=m.useCallback(ue=>{if(r==="multiple"){const ae=t.value??T;F(ae.filter(Oe=>Oe!==ue))}else D("")},[r,D,F,T,O]);m.useEffect(()=>{x(),k()},[x,k,n]);const B=[...N].join(",");m.useEffect(()=>{x(),k()},[x,k,B]);const[G,H]=m.useState(null),Y=f!==null?g[f]:null,U=G!==null?g[G]:null,J=f!==null&&!u.has(f),Z=op(),{value:j,defaultValue:Q,onValueChange:oe,collapsible:ne,type:se,...de}=i,ve=r==="multiple"?{type:"multiple",value:t.value??T,onValueChange:F}:{type:"single",collapsible:t.collapsible??!0,value:t.value??C,onValueChange:D};return b.jsx(ZN.Provider,{value:{registerItem:_,registerFullItem:S,activeIndex:f,grouped:!0,remeasure:()=>{x(),k()},openValues:N,openItemRects:u,toggleValue:K},children:b.jsx(GL,{...ve,asChild:!0,children:b.jsxs("div",{ref:ue=>{o.current=ue,typeof e=="function"?e(ue):e&&(e.current=ue)},onMouseEnter:w.onMouseEnter,onMouseMove:ue=>{const ae=o.current;if(ae){const Oe=ae.getBoundingClientRect(),We=ae.offsetHeight,Ee=Oe.height,pt=We>0?Ee/We:1,Ot=(ue.clientY-Oe.top)/pt+ae.scrollTop;for(const[en,bt]of u){const _t=g[en];if(!_t)continue;const qe=_t.top+_t.height,Ke=bt.top+bt.height;if(Ot>=qe&&Ot<=Ke){h(null);return}}}w.onMouseMove(ue)},onMouseLeave:w.onMouseLeave,onFocus:ue=>{var Oe;const ae=(Oe=ue.target.closest("[data-proximity-index]"))==null?void 0:Oe.getAttribute("data-proximity-index");if(ae!=null){const We=Number(ae);h(We),H(ue.target.matches(":focus-visible")?We:null)}},onBlur:ue=>{var ae;(ae=o.current)!=null&&ae.contains(ue.relatedTarget)||(H(null),h(null))},className:Ut("relative flex flex-col gap-0.5 w-72 max-w-full",s),...de,children:[b.jsx(Cs,{children:[...u.entries()].map(([ue,ae])=>b.jsx(Ho.div,{className:`absolute ${Z.bg} bg-accent/20 dark:bg-accent/12 pointer-events-none`,initial:!1,animate:{top:ae.top,left:ae.left,width:ae.width,height:ae.height,opacity:J?.7:1},exit:{opacity:0,transition:{duration:.12}},transition:{top:{duration:0},left:{duration:0},width:{duration:0},height:{duration:0},opacity:{duration:.08}}},`expanded-${ue}`))}),b.jsx(Cs,{children:Y&&b.jsx(Ho.div,{className:`absolute ${Z.bg} bg-hover pointer-events-none`,initial:{opacity:0,top:Y.top,left:Y.left,width:Y.width,height:Y.height},animate:{opacity:1,top:Y.top,left:Y.left,width:Y.width,height:Y.height},exit:{opacity:0,transition:{duration:.06}},transition:{...Lh.fast,opacity:{duration:.08}}},v.current)}),b.jsx(Cs,{children:U&&b.jsx(Ho.div,{className:`absolute ${Z.focusRing} pointer-events-none z-20 border border-[#6B97FF]`,initial:!1,animate:{left:U.left-2,top:U.top-2,width:U.width+4,height:U.height+4},exit:{opacity:0,transition:{duration:.06}},transition:{...Lh.fast,opacity:{duration:.08}}})}),n]})})})});Poe.displayName="AccordionGroup";const GN=m.forwardRef(({children:t,type:e="single",collapsible:n=!0,defaultValue:r,value:s,onValueChange:i,className:o,...l},u)=>{const[d,f]=m.useState(()=>e==="single"?r??"":""),[h,g]=m.useState(()=>e==="multiple"?r??[]:[]),v=new Set(e==="multiple"?s??h:(()=>{const k=s??d;return k?[k]:[]})()),w=m.useCallback(k=>{i?i(k):f(k)},[i]),_=m.useCallback(k=>{i?i(k):g(k)},[i]),x=m.useCallback(k=>{e==="multiple"?_((s??h).filter(A=>A!==k)):w("")},[e,s,h,w,_]),S=e==="multiple"?{type:"multiple",value:s??h,defaultValue:r,onValueChange:_}:{type:"single",collapsible:n,value:s??d,defaultValue:r,onValueChange:w};return b.jsx(GL,{...S,asChild:!0,children:b.jsx("div",{ref:u,className:Ut("w-72 max-w-full flex flex-col gap-0.5",o),...l,children:b.jsx(KN.Provider,{value:v,children:b.jsx(YN.Provider,{value:x,children:t})})})})});GN.displayName="Accordion";const KN=m.createContext(new Set),YN=m.createContext(()=>{}),XN=m.forwardRef(({value:t,index:e,disabled:n,children:r,className:s,...i},o)=>{const l=m.useRef(null),u=U4(),d=m.useContext(KN),f=m.useContext(YN),h=op(),g=u!=null&&u.grouped?u.openValues.has(t):d.has(t),v=m.useRef(null),w=m.useCallback(()=>{u!=null&&u.grouped?u.toggleValue(t):f(t)},[u,f,t]);return m.useEffect(()=>{if(u!=null&&u.grouped&&e!==void 0)return u.registerItem(e,v.current),()=>u.registerItem(e,null)},[e,u]),m.useEffect(()=>{if(u!=null&&u.grouped&&e!==void 0)return g?u.registerFullItem(e,l.current):u.registerFullItem(e,null),()=>u.registerFullItem(e,null)},[e,u,g]),b.jsx(WN.Provider,{value:{index:e,value:t,isOpen:g,onToggle:w,triggerRef:v},children:b.jsxs(gie,{ref:_=>{l.current=_,typeof o=="function"?o(_):o&&(o.current=_)},value:t,disabled:n,"data-proximity-index":e,className:Ut(!(u!=null&&u.grouped)&&"relative",s),...i,children:[!(u!=null&&u.grouped)&&b.jsx(Cs,{children:g&&b.jsx(Ho.div,{className:`absolute inset-0 ${h.bg} bg-accent/20 dark:bg-accent/12 pointer-events-none`,initial:{opacity:0},animate:{opacity:1},exit:{opacity:0,transition:{duration:.06}},transition:{duration:.08}})}),r]})})});XN.displayName="AccordionItem";const QN=m.forwardRef(({children:t,className:e,...n},r)=>{const s=Eoe("chevron-right"),i=U4(),{index:o,isOpen:l,triggerRef:u}=qN(),d=op(),[f,h]=m.useState(!1),g=i!=null&&i.grouped?i.activeIndex===o:f,v=b.jsx(yie,{asChild:!0,children:b.jsx("div",{children:b.jsxs(_ie,{ref:r,className:Ut(`relative z-10 flex items-center gap-2.5 ${d.item} px-3 py-2 w-full cursor-pointer outline-none select-none`,!(i!=null&&i.grouped)&&"focus-visible:ring-1 focus-visible:ring-[#6B97FF] focus-visible:ring-offset-0",e),...n,children:[b.jsxs("span",{className:"inline-grid text-[13px] flex-1 text-left",children:[b.jsx("span",{className:"col-start-1 row-start-1 invisible",style:{fontVariationSettings:rh.semibold},"aria-hidden":"true",children:t}),b.jsx("span",{className:Ut("col-start-1 row-start-1 transition-[color,font-variation-settings] duration-80",l||g?"text-foreground":"text-muted-foreground"),style:{fontVariationSettings:l?rh.semibold:rh.normal},children:t})]}),b.jsx(Ho.span,{className:"shrink-0 inline-flex items-center justify-center",animate:{rotate:l?90:0},transition:Lh.fast,children:b.jsx(s,{size:16,strokeWidth:l||g?2:1.5,className:Ut("transition-[color,stroke-width] duration-80",l||g?"text-foreground":"text-muted-foreground")})})]})})});return i!=null&&i.grouped?b.jsx("div",{ref:u,children:v}):b.jsxs("div",{className:"relative",onMouseEnter:()=>h(!0),onMouseLeave:()=>h(!1),children:[b.jsx(Cs,{children:f&&b.jsx(Ho.div,{className:`absolute inset-0 ${d.bg} bg-hover pointer-events-none`,initial:{opacity:0},animate:{opacity:1},exit:{opacity:0,transition:{duration:.06}},transition:{duration:.08}})}),v]})});QN.displayName="AccordionTrigger";const JN=m.forwardRef(({children:t,className:e,...n},r)=>{const s=U4(),{isOpen:i}=qN();return b.jsx(Cs,{initial:!1,children:i&&b.jsx(xie,{forceMount:!0,asChild:!0,...n,children:b.jsx(Ho.div,{ref:r,className:Ut("overflow-hidden",e),initial:{height:0},animate:{height:"auto"},exit:{height:0},transition:{...Lh.moderate,bounce:0},onUpdate:()=>{s==null||s.remeasure()},onAnimationComplete:()=>{s==null||s.remeasure()},children:b.jsx("div",{className:"px-3 pb-3 pt-1 text-[13px] text-muted-foreground",children:t})})})})});JN.displayName="AccordionContent";const Rm=({children:t,defaultValue:e=[],className:n=""})=>b.jsx(GN,{type:"multiple",defaultValue:e,className:Ut("w-full",n),children:t}),Aoe=({value:t,title:e,description:n,dataCy:r,icon:s,children:i,className:o=""})=>{const l=o.includes("first-item");return b.jsxs(XN,{value:t,className:Ut("w-full",!l&&"border-t border-main-border"),children:[b.jsxs(QN,{"data-cy":r,children:[s?b.jsx("span",{className:"mr-1 inline-flex items-center",children:s}):null,e]}),b.jsxs(JN,{children:[n?b.jsx("p",{className:"pb-2 text-sm text-content-subtle",children:n}):null,i]})]})};Rm.Item=Aoe;const Toe=({message:t,isLoading:e=!0})=>b.jsxs("div",{className:"flex items-center gap-2 text-sm text-content",children:[e?b.jsx(ev,{className:"h-4 w-4 shrink-0 animate-spin text-primary",weight:"bold"}):null,b.jsx("span",{className:"whitespace-pre-wrap font-sans",children:t})]}),Roe=()=>{const t=m.useRef(Date.now()),[e,n]=m.useState(0);return m.useEffect(()=>{const r=()=>n(Math.max(0,Math.floor((Date.now()-t.current)/1e3)));r();const s=setInterval(r,1e3);return()=>clearInterval(s)},[]),e},Moe=t=>{const e=Math.floor(t/60),n=t%60;return`${e}:${n.toString().padStart(2,"0")}`},LP="M 12 8 C 14.21 8 16 9.79 16 12 C 16 14.21 14.21 16 12 16 C 9.79 16 8 14.21 8 12 C 8 9.79 9.79 8 12 8 Z",NP="M 12 12 C 14 8.5 19 8.5 19 12 C 19 15.5 14 15.5 12 12 C 10 8.5 5 8.5 5 12 C 5 15.5 10 15.5 12 12 Z",Ioe="M 12 16 C 14.21 16 16 14.21 16 12 C 16 9.79 14.21 8 12 8 C 9.79 8 8 9.79 8 12 C 8 14.21 9.79 16 12 16 Z",Mm=["Applying","Thinking","Planning","Crafting"],Ooe=Mm.reduce((t,e)=>t.length>=e.length?t:e),Loe=20,Noe="Still working — runs can take a few minutes.",Doe=({hint:t,showElapsed:e=!0})=>{const[n,r]=m.useState(0),s=Roe();m.useEffect(()=>{const o=setInterval(()=>{r(l=>(l+1)%Mm.length)},4e3);return()=>clearInterval(o)},[]);const i=t??(e&&s>=Loe?Noe:null);return b.jsxs("div",{role:"status",className:"flex items-center gap-2 px-3 py-1","data-cy":"thinking-indicator",children:[b.jsx(Si.svg,{"aria-hidden":!0,width:20,height:20,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round",className:"shrink-0 text-muted-foreground",children:b.jsx(Si.path,{animate:{d:[LP,NP,Ioe,NP,LP]},transition:{d:{duration:6,ease:"easeInOut",repeat:1/0,times:[0,.25,.5,.75,1]}}})}),b.jsxs("span",{className:"inline-grid overflow-hidden text-sm font-medium",style:{fontVariationSettings:rh.medium},children:[b.jsx("span",{className:"shimmer-text invisible col-start-1 row-start-1","aria-hidden":"true",children:Ooe}),b.jsx(Cs,{mode:"popLayout",initial:!1,children:b.jsx(Si.span,{className:"shimmer-text col-start-1 row-start-1",initial:{y:"80%",opacity:0},animate:{y:0,opacity:1,transition:{duration:.24,ease:[.4,0,.2,1]}},exit:{y:"-80%",opacity:0,transition:{duration:.16,ease:[.4,0,.2,1]}},children:Mm[n]},Mm[n])})]}),e?b.jsx("span",{className:"text-xs tabular-nums text-content-subtle","data-cy":"thinking-elapsed",children:Moe(s)}):null,i?b.jsx("span",{className:"text-xs text-content-subtle",children:i}):null]})};var joe=Object.defineProperty,$oe=(t,e)=>joe(t,"name",{value:e,configurable:!0});function $g(t,[e,n]){return Math.min(n,Math.max(e,t))}$oe($g,"clamp");var Foe=Object.defineProperty,Voe=(t,e)=>Foe(t,"name",{value:e,configurable:!0});function eD(t){const e=m.useRef({value:t,previous:t});return m.useMemo(()=>(e.current.value!==t&&(e.current.previous=e.current.value,e.current.value=t),e.current.previous),[t])}Voe(eD,"usePrevious");var Hoe=Object.defineProperty,jt=(t,e)=>Hoe(t,"name",{value:e,configurable:!0}),DP={Horizontal:"horizontal"},zoe={LTR:"ltr"},tD=["PageUp","PageDown"],nD=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],rD={"from-left":["Home","PageDown","ArrowDown","ArrowLeft"],"from-right":["Home","PageDown","ArrowDown","ArrowRight"],"from-bottom":["Home","PageDown","ArrowDown","ArrowLeft"],"from-top":["Home","PageDown","ArrowUp","ArrowLeft"]},hp="Slider",[_x,Uoe,Boe]=L4(hp),[B4,Fae]=so(hp,[Boe]),[Zoe,pp]=B4(hp),Woe=m.forwardRef(jt(function(e,n){const{name:r,min:s=0,max:i=100,step:o=1,orientation:l=DP.Horizontal,disabled:u=!1,minStepsBetweenThumbs:d=0,preserveThumbOrder:f=!1,defaultValue:h=[s],value:g,onValueChange:v=jt(()=>{},"onValueChange"),onValueCommit:w=jt(()=>{},"onValueCommit"),inverted:_=!1,form:x,...S}=e,k=m.useRef(new Set),C=m.useRef(0),A=m.useRef(!1),I=l===DP.Horizontal?qoe:Goe,[M,R]=m.useState(null),O=Jt(n,R),[N=[],D]=cl({prop:g,defaultProp:h,onChange:jt(U=>{var Z;(Z=[...k.current][C.current])==null||Z.focus({preventScroll:!0,focusVisible:A.current}),A.current=!1,v(U)},"onChange")}),F=m.useRef(N),K=m.useRef(N);m.useEffect(()=>{const U=x?M==null?void 0:M.ownerDocument.getElementById(x):M==null?void 0:M.closest("form");if(U instanceof HTMLFormElement){const J=jt(()=>D(K.current),"reset");return U.addEventListener("reset",J),()=>U.removeEventListener("reset",J)}},[M,x,D]);function B(U){const J=dD(N,U);Y(U,J)}jt(B,"handleSlideStart");function G(U){Y(U,C.current)}jt(G,"handleSlideMove");function H(){String(N)!==String(F.current)&&w(N)}jt(H,"handleSlideEnd");function Y(U,J,{commit:Z}={commit:!1}){const j=W4(o),Q=lh(Math.round((U-s)/o)*o+s,j),oe=$g(Q,[s,i]);D((ne=[])=>{const se=d*o,de=f?$g(oe,[ne[J-1]===void 0?s:ne[J-1]+se,ne[J+1]===void 0?i:ne[J+1]-se]):oe,ve=cD(ne,de,J);if(pD(ve,se)){C.current=f?J:ve.indexOf(de);const ue=String(ve)!==String(ne);return ue&&Z&&w(ve),ue?ve:ne}else return ne})}return jt(Y,"updateValues"),b.jsx(Zoe,{scope:e.__scopeSlider,name:r,disabled:u,min:s,max:i,valueIndexToChangeRef:C,thumbs:k.current,values:N,orientation:l,form:x,children:b.jsx(_x.Provider,{scope:e.__scopeSlider,children:b.jsx(_x.Slot,{scope:e.__scopeSlider,children:b.jsx(I,{"aria-disabled":u,"data-disabled":u?"":void 0,...S,ref:O,onPointerDown:Yt(S.onPointerDown,()=>{u||(F.current=N,A.current=!1)}),min:s,max:i,inverted:_,onSlideStart:u?void 0:B,onSlideMove:u?void 0:G,onSlideEnd:u?void 0:H,onHomeKeyDown:()=>{u||(A.current=!0,Y(s,0,{commit:!0}))},onEndKeyDown:()=>{u||(A.current=!0,Y(i,N.length-1,{commit:!0}))},onStepKeyDown:({event:U,direction:J})=>{if(!u){A.current=!0;const Q=tD.includes(U.key)||U.shiftKey&&nD.includes(U.key)?10:1,oe=C.current,ne=N[oe],se=mD(ne,{min:s,step:o,direction:J,multiplier:Q});Y(se,oe,{commit:!0})}}})})})})},"Slider")),[sD,iD]=B4(hp,{startEdge:"left",endEdge:"right",size:"width",direction:1}),qoe=m.forwardRef(jt(function(e,n){const{min:r,max:s,dir:i,inverted:o,onSlideStart:l,onSlideMove:u,onSlideEnd:d,onStepKeyDown:f,...h}=e,[g,v]=m.useState(null),w=Jt(n,v),_=m.useRef(void 0),x=$4(i),S=x===zoe.LTR,k=S&&!o||!S&&o;function C(A){const T=_.current||g.getBoundingClientRect(),I=[0,T.width],R=Cv(I,k?[r,s]:[s,r]);return _.current=T,R(A-T.left)}return jt(C,"getValueFromPointer"),b.jsx(sD,{scope:e.__scopeSlider,startEdge:k?"left":"right",endEdge:k?"right":"left",direction:k?1:-1,size:"width",children:b.jsx(oD,{dir:x,"data-orientation":"horizontal",...h,ref:w,style:{...h.style,"--radix-slider-thumb-transform":"translateX(-50%)"},onSlideStart:A=>{const T=C(A.clientX);l==null||l(T)},onSlideMove:A=>{const T=C(A.clientX);u==null||u(T)},onSlideEnd:()=>{_.current=void 0,d==null||d()},onStepKeyDown:A=>{const I=rD[k?"from-left":"from-right"].includes(A.key);f==null||f({event:A,direction:I?-1:1})}})})},"SliderHorizontal")),Goe=m.forwardRef(jt(function(e,n){const{min:r,max:s,inverted:i,onSlideStart:o,onSlideMove:l,onSlideEnd:u,onStepKeyDown:d,...f}=e,h=m.useRef(null),g=Jt(n,h),v=m.useRef(void 0),w=!i;function _(x){const S=v.current||h.current.getBoundingClientRect(),k=[0,S.height],A=Cv(k,w?[s,r]:[r,s]);return v.current=S,A(x-S.top)}return jt(_,"getValueFromPointer"),b.jsx(sD,{scope:e.__scopeSlider,startEdge:w?"bottom":"top",endEdge:w?"top":"bottom",size:"height",direction:w?1:-1,children:b.jsx(oD,{"data-orientation":"vertical",...f,ref:g,style:{...f.style,"--radix-slider-thumb-transform":"translateY(50%)"},onSlideStart:x=>{const S=_(x.clientY);o==null||o(S)},onSlideMove:x=>{const S=_(x.clientY);l==null||l(S)},onSlideEnd:()=>{v.current=void 0,u==null||u()},onStepKeyDown:x=>{const k=rD[w?"from-bottom":"from-top"].includes(x.key);d==null||d({event:x,direction:k?-1:1})}})})},"SliderVertical")),oD=m.forwardRef(jt(function(e,n){const{__scopeSlider:r,onSlideStart:s,onSlideMove:i,onSlideEnd:o,onHomeKeyDown:l,onEndKeyDown:u,onStepKeyDown:d,...f}=e,h=pp(hp,r);return b.jsx(En.span,{...f,ref:n,onKeyDown:Yt(e.onKeyDown,g=>{g.key==="Home"?(l(g),g.preventDefault()):g.key==="End"?(u(g),g.preventDefault()):tD.concat(nD).includes(g.key)&&(d(g),g.preventDefault())}),onPointerDown:Yt(e.onPointerDown,g=>{const v=g.target;v.setPointerCapture(g.pointerId),g.preventDefault(),h.thumbs.has(v)?v.focus({preventScroll:!0,focusVisible:!1}):s(g)}),onPointerMove:Yt(e.onPointerMove,g=>{g.target.hasPointerCapture(g.pointerId)&&i(g)}),onPointerUp:Yt(e.onPointerUp,g=>{const v=g.target;v.hasPointerCapture(g.pointerId)&&(v.releasePointerCapture(g.pointerId),o(g))})})},"SliderImpl")),Koe="SliderTrack",Yoe=m.forwardRef(jt(function(e,n){const{__scopeSlider:r,...s}=e,i=pp(Koe,r);return b.jsx(En.span,{"data-disabled":i.disabled?"":void 0,"data-orientation":i.orientation,...s,ref:n})},"SliderTrack")),jP="SliderRange",Xoe=m.forwardRef(jt(function(e,n){const{__scopeSlider:r,...s}=e,i=pp(jP,r),o=iD(jP,r),l=m.useRef(null),u=Jt(n,l),d=i.values.length,f=i.values.map(v=>Z4(v,i.min,i.max)),h=d>1?Math.min(...f):0,g=100-Math.max(...f);return b.jsx(En.span,{"data-orientation":i.orientation,"data-disabled":i.disabled?"":void 0,...s,ref:u,style:{...e.style,[o.startEdge]:h+"%",[o.endEdge]:g+"%"}})},"SliderRange")),Qoe="SliderThumb",[Joe,aD]=B4(Qoe),eae="SliderThumbProvider";function lD(t){const{__scopeSlider:e,name:n,children:r,internal_do_not_use_render:s}=t,i=pp(eae,e),o=Uoe(e),[l,u]=m.useState(null),d=m.useMemo(()=>l?o().findIndex(x=>x.ref.current===l):-1,[o,l]),f=Zb(l),h=l?!!i.form||!!l.closest("form"):!0,g=i.values[d],v=n??(i.name?i.name+(i.values.length>1?"[]":""):void 0),w=g===void 0?0:Z4(g,i.min,i.max);m.useEffect(()=>{if(l)return i.thumbs.add(l),()=>{i.thumbs.delete(l)}},[l,i.thumbs]);const _={value:g,name:v,form:i.form,isFormControl:h,index:d,thumb:l,onThumbChange:u,percent:w,size:f};return b.jsx(Joe,{scope:e,..._,children:gD(s)?s(_):r})}jt(lD,"SliderThumbProvider");var X_="SliderThumbTrigger",tae=m.forwardRef(jt(function(e,n){const{__scopeSlider:r,...s}=e,i=pp(X_,r),o=iD(X_,r),{index:l,value:u,percent:d,size:f,onThumbChange:h}=aD(X_,r),g=Jt(n,h),v=uD(l,i.values.length),w=f==null?void 0:f[o.size],_=w?fD(w,d,o.direction):0;return b.jsx("span",{style:{transform:"var(--radix-slider-thumb-transform)",position:"absolute",[o.startEdge]:`calc(${d}% + ${_}px)`},children:b.jsx(_x.ItemSlot,{scope:r,children:b.jsx(En.span,{role:"slider","aria-label":e["aria-label"]||v,"aria-valuemin":i.min,"aria-valuenow":u,"aria-valuemax":i.max,"aria-orientation":i.orientation,"data-orientation":i.orientation,"data-disabled":i.disabled?"":void 0,tabIndex:i.disabled?void 0:0,...s,ref:g,style:u===void 0?{display:"none"}:e.style,onFocus:Yt(e.onFocus,()=>{i.valueIndexToChangeRef.current=l})})})})},"SliderThumbTrigger")),nae=m.forwardRef(jt(function(e,n){const{__scopeSlider:r,name:s,...i}=e;return b.jsx(lD,{__scopeSlider:r,name:s,internal_do_not_use_render:({index:o,isFormControl:l})=>b.jsxs(b.Fragment,{children:[b.jsx(tae,{...i,ref:n,__scopeSlider:r}),l?b.jsx(sae,{__scopeSlider:r},o):null]})})},"SliderThumb")),rae="SliderBubbleInput",sae=m.forwardRef(jt(function({__scopeSlider:e,...n},r){const{value:s,name:i,form:o}=aD(rae,e),l=m.useRef(null),u=Jt(l,r),d=eD(s);return m.useEffect(()=>{const f=l.current;if(!f)return;const h=window.HTMLInputElement.prototype,v=Object.getOwnPropertyDescriptor(h,"value").set;if(d!==s&&v){const w=new Event("input",{bubbles:!0});v.call(f,s),f.dispatchEvent(w)}},[d,s]),b.jsx(En.input,{style:{display:"none"},name:i,form:o,...n,ref:u,defaultValue:s})},"SliderBubbleInput"));function cD(t=[],e,n){const r=[...t];return r[n]=e,r.sort((s,i)=>s-i)}jt(cD,"getNextSortedValues");function Z4(t,e,n){const i=100/(n-e)*(t-e);return $g(i,[0,100])}jt(Z4,"convertValueToPercentage");function uD(t,e){return e>2?`Value ${t+1} of ${e}`:e===2?["Minimum","Maximum"][t]:void 0}jt(uD,"getLabel");function dD(t,e){if(t.length===1)return 0;const n=t.map(s=>Math.abs(s-e)),r=Math.min(...n);return n.indexOf(r)}jt(dD,"getClosestValueIndex");function fD(t,e,n){const r=t/2,i=Cv([0,50],[0,r]);return(r-i(e)*n)*n}jt(fD,"getThumbInBoundsOffset");function hD(t){return t.slice(0,-1).map((e,n)=>t[n+1]-e)}jt(hD,"getStepsBetweenValues");function pD(t,e){if(e>0){const n=hD(t);return Math.min(...n)>=e}return!0}jt(pD,"hasMinStepsBetweenValues");function Cv(t,e){return n=>{if(t[0]===t[1]||e[0]===e[1])return e[0];const r=(e[1]-e[0])/(t[1]-t[0]);return e[0]+r*(n-t[0])}}jt(Cv,"linearScale");function W4(t){if(!Number.isFinite(t))return 0;const e=t.toString();if(e.includes("e")){const[r,s]=e.split("e"),i=r.split(".")[1]||"",o=Number(s);return Math.max(0,i.length-o)}const n=e.split(".")[1];return n?n.length:0}jt(W4,"getDecimalCount");function lh(t,e){const n=Math.pow(10,e);return Math.round(t*n)/n}jt(lh,"roundValue");function mD(t,{min:e,step:n,direction:r,multiplier:s}){const i=W4(n),o=(t-e)/n,l=Math.round(o),u=lh(l*n+e,i)===lh(t,i);let d;return u?d=l+s*r:r>0?d=Math.ceil(o):d=Math.floor(o),lh(d*n+e,i)}jt(mD,"getNextStepValue");function gD(t){return typeof t=="function"}jt(gD,"isFunction");const wx=m.forwardRef(({className:t,...e},n)=>b.jsxs(Woe,{ref:n,className:Ut("relative flex w-full touch-none select-none items-center","data-[disabled]:opacity-50",t),...e,children:[b.jsx(Yoe,{className:"relative h-1 w-full grow overflow-hidden rounded-full bg-input",children:b.jsx(Xoe,{className:"absolute h-full bg-primary"})}),b.jsx(nae,{className:Ut("block h-3.5 w-3.5 rounded-full border border-border bg-foreground shadow-sm","transition-transform hover:scale-110 active:scale-95","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#6B97FF]","disabled:pointer-events-none")})]}));wx.displayName="Slider";const iae=[{name:"surface-1",utility:"bg-surface-1",className:"bg-surface-1"},{name:"surface-2",utility:"bg-surface-2",className:"bg-surface-2"},{name:"surface-3",utility:"bg-surface-3",className:"bg-surface-3"},{name:"surface-4",utility:"bg-surface-4",className:"bg-surface-4"},{name:"surface-5",utility:"bg-surface-5",className:"bg-surface-5"},{name:"surface-6",utility:"bg-surface-6",className:"bg-surface-6"}],oae=[{name:"primary",utility:"bg-primary",className:"bg-primary"},{name:"selected",utility:"bg-selected",className:"bg-selected"},{name:"accent",utility:"bg-accent",className:"bg-accent"},{name:"success",utility:"bg-accent-success",className:"bg-accent-success"},{name:"warning",utility:"bg-accent-warning",className:"bg-accent-warning"},{name:"error",utility:"bg-accent-error",className:"bg-accent-error"}],aae=[{name:"gap-1",className:"w-1"},{name:"gap-2",className:"w-2"},{name:"gap-3",className:"w-3"},{name:"gap-4",className:"w-4"},{name:"gap-6",className:"w-6"},{name:"gap-8",className:"w-8"}],tm=[{name:"Accordion",path:"components/Accordion.tsx",status:"showcased",note:"Reusable primitive shown with local item composition."},{name:"AgentVariantsPanel",path:"components/AgentVariantsPanel.tsx",status:"feature-only",note:"Requires live variant session state and editor atoms."},{name:"AuthProgressScreen",path:"components/AuthProgressScreen.tsx",status:"feature-only",note:"Auth flow surface; represented through progress treatment."},{name:"AuthScreenView",path:"components/AuthScreenView.tsx",status:"feature-only",note:"Auth flow surface that depends on sign-in actions."},{name:"Button",path:"components/Button.tsx",status:"showcased",note:"Reusable tooltip-wrapped button shown in multiple states."},{name:"CommentCarouselLayer",path:"components/CommentCarouselLayer.tsx",status:"feature-only",note:"Preview overlay layer tied to iframe geometry."},{name:"CommentMarker",path:"components/CommentMarker.tsx",status:"feature-only",note:"Preview overlay marker tied to comment positions."},{name:"CommentPopover",path:"components/CommentPopover.tsx",status:"feature-only",note:"Comment workflow popover tied to editor state."},{name:"CommentReferenceChip",path:"components/CommentReferenceChip.tsx",status:"feature-only",note:"Comment workflow chip tied to selected references."},{name:"CommentReferencePicker",path:"components/CommentReferencePicker.tsx",status:"feature-only",note:"Comment workflow picker tied to preview elements."},{name:"ElementInspector",path:"components/ElementInspector.tsx",status:"feature-only",note:"Primary editor surface with many app-level dependencies."},{name:"GitHome",path:"components/GitHome.tsx",status:"feature-only",note:"Git dashboard tied to repository state."},{name:"IframePreview",path:"components/IframePreview.tsx",status:"unsuitable",note:"Needs live iframe target and cross-window integration."},{name:"PreviewFrame",path:"components/PreviewFrame.tsx",status:"unsuitable",note:"Requires proxied app URL and iframe lifecycle."},{name:"PreviewSurface",path:"components/PreviewSurface.tsx",status:"unsuitable",note:"Requires preview iframe and overlay orchestration."},{name:"ProfileAvatar",path:"components/ProfileAvatar.tsx",status:"feature-only",note:"Account chrome tied to user identity data."},{name:"Progress",path:"components/Progress.tsx",status:"showcased",note:"Reusable inline loading/status primitive."},{name:"SecondaryVariantIframe",path:"components/SecondaryVariantIframe.tsx",status:"unsuitable",note:"Requires variant preview iframe lifecycle."},{name:"SparkleLoader",path:"components/SparkleLoader.tsx",status:"showcased",note:"Reusable loading animation shown in feedback states."},{name:"SplitButton",path:"components/SplitButton.tsx",status:"showcased",note:"Reusable compound action button shown with dropdown."},{name:"StatusSurface",path:"components/StatusSurface.tsx",status:"showcased",note:"Unified full-surface primitive: LoadingSurface / EmptyState / ErrorState."},{name:"SupportTicketModal",path:"components/SupportTicketModal.tsx",status:"feature-only",note:"Support workflow modal tied to form submission."},{name:"ThinkingIndicator",path:"components/ThinkingIndicator.tsx",status:"showcased",note:"Reusable thinking/loading indicator shown in feedback states."},{name:"Tooltip",path:"components/Tooltip.tsx",status:"showcased",note:"Reusable tooltip API shown with hover target."},{name:"VariantDragGhost",path:"components/VariantDragGhost.tsx",status:"feature-only",note:"Drag visual tied to variant split interactions."},{name:"VariantSplitDropZones",path:"components/VariantSplitDropZones.tsx",status:"feature-only",note:"Drop-zone visual tied to variant split interactions."},{name:"ui/accordion",path:"components/ui/accordion.tsx",status:"showcased",note:"Radix accordion primitive backing the local Accordion showcase."},{name:"ui/slider",path:"components/ui/slider.tsx",status:"showcased",note:"Radix slider primitive shown in enabled and disabled states."},{name:"ui/tooltip",path:"components/ui/tooltip.tsx",status:"showcased",note:"Radix tooltip primitive shown with forced-open preview."}],lae=()=>{window.location.hash=""},ko=({title:t,eyebrow:e,description:n,children:r})=>b.jsxs("section",{className:"border-border bg-card shadow-surface-3 rounded-2xl border p-5",children:[b.jsxs("div",{className:"mb-5 max-w-2xl",children:[b.jsx("p",{className:"text-primary text-xs font-semibold tracking-[0.18em] uppercase",children:e}),b.jsx("h2",{className:"text-foreground mt-2 text-xl font-semibold",children:t}),b.jsx("p",{className:"text-muted-foreground mt-2 text-sm leading-6",children:n})]}),r]}),$P=({swatches:t})=>b.jsx("div",{className:"grid gap-3 sm:grid-cols-2 lg:grid-cols-3",children:t.map(e=>b.jsxs("div",{className:"border-border bg-surface-2 rounded-xl border p-3",children:[b.jsx("div",{className:`h-16 rounded-lg ${e.className}`}),b.jsxs("div",{className:"mt-3 flex items-center justify-between gap-3",children:[b.jsx("span",{className:"text-foreground text-sm font-medium",children:e.name}),b.jsx("code",{className:"bg-muted text-muted-foreground rounded px-2 py-1 text-xs",children:e.utility})]})]},e.name))}),cae=t=>t==="showcased"?"border-accent-success/40 bg-accent-success/10 text-accent-success":t==="cataloged"?"border-primary/40 bg-primary/10 text-primary":t==="generated"?"border-accent/40 bg-accent/10 text-accent":t==="unsuitable"?"border-accent-warning/40 bg-accent-warning/10 text-accent-warning":"border-border bg-surface-4 text-content-muted",uae=()=>{const t=tm.filter(n=>n.status==="showcased").length,e=tm.filter(n=>n.status==="cataloged").length;return b.jsx("main",{className:"bg-main font-main text-content h-screen overflow-y-auto",children:b.jsxs("div",{className:"mx-auto flex w-full max-w-6xl flex-col gap-6 px-6 py-6 lg:px-8",children:[b.jsxs("header",{className:"border-border bg-surface-2 shadow-surface-4 rounded-3xl border p-6",children:[b.jsxs("button",{type:"button",onClick:lae,className:"text-content-subtle hover:text-content mb-6 inline-flex items-center gap-2 text-sm transition-colors",children:[b.jsx(dK,{className:"h-4 w-4",weight:"bold"}),"Back to editor"]}),b.jsxs("div",{className:"flex flex-col gap-5 lg:flex-row lg:items-end lg:justify-between",children:[b.jsxs("div",{className:"max-w-3xl",children:[b.jsx("p",{className:"text-primary text-xs font-semibold tracking-[0.22em] uppercase",children:"Local component gallery"}),b.jsx("h1",{className:"text-foreground mt-3 text-4xl font-semibold tracking-tight",children:"Rivet design system"}),b.jsx("p",{className:"text-muted-foreground mt-3 text-base leading-7",children:"A Storybook-like route for checking the current UI primitives, tokens, and interaction states inside the Vite app."})]}),b.jsx("div",{className:"border-border bg-surface-3 rounded-2xl border p-4",children:b.jsxs("div",{className:"text-content-muted flex items-center gap-3 text-sm",children:[b.jsx(sI,{className:"text-primary h-5 w-5",weight:"bold"}),"Open with ",b.jsx("code",{className:"text-content",children:"#/design-system"})]})})]})]}),b.jsx(ko,{eyebrow:"Controls",title:"Button, split button, and tooltip",description:"Rivet's shared Button exposes variants and sizes backed by Fluid Functionalism, alongside the split button and tooltip controls.",children:b.jsxs("div",{className:"grid gap-4 lg:grid-cols-[1fr_1fr]",children:[b.jsxs("div",{className:"border-border bg-surface-2 rounded-xl border p-4",children:[b.jsx("p",{className:"text-foreground mb-3 text-sm font-medium",children:"Rivet Button"}),b.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[b.jsx(Qi,{title:"Primary action",shortcut:"D",variant:"primary",children:"Design action"}),b.jsx(Qi,{title:"Secondary action",variant:"secondary",children:"Secondary"}),b.jsx(Qi,{title:"Disabled action",disabled:!0,variant:"tertiary",children:"Disabled"}),b.jsx(_9,{primaryLabel:"Ship",primaryIcon:g_,primaryAction:()=>{},dropdownItems:[{label:"Create PR",onClick:()=>{}},{label:"Copy branch",onClick:()=>{}}]})]})]}),b.jsxs("div",{className:"border-border bg-surface-2 rounded-xl border p-4",children:[b.jsx("p",{className:"text-foreground mb-3 text-sm font-medium",children:"Tooltip states"}),b.jsxs("div",{className:"flex flex-wrap items-center gap-4",children:[b.jsx(kc,{label:"Rivet tooltip API",side:"bottom",children:b.jsx("button",{className:"border-border bg-surface-4 text-content rounded-lg border px-4 py-2 text-sm",children:"Hover target"})}),b.jsx(Yb,{content:"Forced open preview",forceOpen:!0,side:"right",children:b.jsx("button",{className:"bg-selected text-content rounded-lg px-4 py-2 text-sm",children:"UI tooltip"})})]})]})]})}),b.jsx(ko,{eyebrow:"Tokens",title:"Surface ladder",description:"Surface tokens move from the base app background toward raised panels without leaving the dark Rivet palette.",children:b.jsx($P,{swatches:iae})}),b.jsx(ko,{eyebrow:"Tokens",title:"Color roles",description:"Named roles should communicate purpose: brand, selection, neutral accent, and outcome colors.",children:b.jsx($P,{swatches:oae})}),b.jsx(ko,{eyebrow:"Type",title:"Typography",description:"Satoshi remains the default UI voice with clear hierarchy and muted support text.",children:b.jsxs("div",{className:"grid gap-4 lg:grid-cols-3",children:[b.jsxs("div",{className:"border-border bg-surface-2 rounded-xl border p-4",children:[b.jsx("p",{className:"text-primary text-xs tracking-[0.18em] uppercase",children:"Display"}),b.jsx("p",{className:"text-foreground mt-2 text-3xl font-semibold tracking-tight",children:"Visual edits, quickly"})]}),b.jsxs("div",{className:"border-border bg-surface-2 rounded-xl border p-4",children:[b.jsx("p",{className:"text-foreground text-sm font-semibold",children:"Panel heading"}),b.jsx("p",{className:"text-muted-foreground mt-2 text-sm leading-6",children:"Body copy uses compact line height and muted contrast for dense inspector panels."})]}),b.jsxs("div",{className:"border-border bg-surface-2 rounded-xl border p-4",children:[b.jsx("p",{className:"text-content-subtle text-xs font-medium tracking-[0.16em] uppercase",children:"Micro label"}),b.jsx("code",{className:"bg-muted text-muted-foreground mt-3 block rounded-lg px-3 py-2 text-xs",children:"font-main text-content"})]})]})}),b.jsx(ko,{eyebrow:"Layout",title:"Spacing rhythm",description:"A compact spacing scale keeps editor chrome dense while preserving scannable groupings.",children:b.jsx("div",{className:"border-border bg-surface-2 rounded-xl border p-4",children:b.jsx("div",{className:"flex flex-col gap-3",children:aae.map(n=>b.jsxs("div",{className:"flex items-center gap-4",children:[b.jsx("code",{className:"text-muted-foreground w-16 text-xs",children:n.name}),b.jsx("div",{className:`${n.className} bg-primary h-4 rounded`}),b.jsx("div",{className:"bg-border h-px flex-1"})]},n.name))})})}),b.jsx(ko,{eyebrow:"Primitives",title:"Accordion and slider",description:"Representative Radix primitives styled through the local component layer.",children:b.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[b.jsxs(Rm,{defaultValue:["foundations"],className:"border-border bg-surface-2 rounded-xl border p-2",children:[b.jsx(Rm.Item,{value:"foundations",title:"Foundations",description:"Tokens, surfaces, type, and spacing.",className:"first-item",icon:b.jsx(g_,{className:"text-primary h-4 w-4"}),children:b.jsx("p",{children:"Use these pieces before adding one-off visual rules."})}),b.jsx(Rm.Item,{value:"components",title:"Components",description:"Buttons, tooltips, accordions, sliders.",children:b.jsx("p",{children:"Keep states visible in this route as the system evolves."})})]}),b.jsxs("div",{className:"border-border bg-surface-2 rounded-xl border p-5",children:[b.jsx("p",{className:"text-foreground mb-5 text-sm font-medium",children:"Slider states"}),b.jsxs("div",{className:"space-y-6",children:[b.jsx(wx,{defaultValue:[64],max:100,step:1}),b.jsx(wx,{defaultValue:[36],max:100,step:1,disabled:!0})]})]})]})}),b.jsx(ko,{eyebrow:"Feedback",title:"Motion and loading",description:"Loading states use existing CSS animation utilities and avoid per-frame React work where possible.",children:b.jsxs("div",{className:"grid gap-4 sm:grid-cols-3",children:[b.jsxs("div",{className:"border-border bg-surface-2 rounded-xl border p-4",children:[b.jsx("p",{className:"text-foreground mb-4 text-sm font-medium",children:"Progress"}),b.jsx(Toe,{message:"Applying visual change..."})]}),b.jsxs("div",{className:"border-border bg-surface-2 rounded-xl border p-4",children:[b.jsx("p",{className:"text-foreground mb-4 text-sm font-medium",children:"Sparkle strip"}),b.jsx(f4,{className:"text-primary text-xl"})]}),b.jsxs("div",{className:"border-border bg-surface-2 rounded-xl border p-4",children:[b.jsx("p",{className:"text-foreground mb-4 text-sm font-medium",children:"Shimmer text"}),b.jsx("span",{className:"shimmer-text text-sm font-medium",children:"Generating variants"})]}),b.jsx("div",{className:"border-border bg-surface-2 rounded-xl border p-4 sm:col-span-3",children:b.jsx(Doe,{hint:"Reading selected elements"})})]})}),b.jsx(ko,{eyebrow:"Feedback",title:"Status surfaces",description:"The unified full-surface system: one StatusSurface primitive with LoadingSurface / EmptyState / ErrorState wrappers. Every full-page loading, empty, and error state routes through these so they share layout, copy tone, and a single status_surface_shown impression event. Inline loaders (Sparkle, ThinkingIndicator, above) stay inline and are deliberately not part of this system.",children:b.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[b.jsx("div",{className:"border-border relative h-56 overflow-hidden rounded-xl border",children:b.jsx(ex,{fill:"surface",loader:"coalesce",trackGlobalLoaderCount:!1})}),b.jsx("div",{className:"border-border relative h-56 overflow-hidden rounded-xl border",children:b.jsx(U9,{icon:b.jsx(g_,{size:32}),title:"Nothing to preview yet",description:"Pick a direction from the panel."})}),b.jsx("div",{className:"border-border relative h-56 overflow-hidden rounded-xl border",children:b.jsx(p4,{fill:"surface",size:"sm",title:"Preview isn't connected",description:"Rivet lost connection to your project.",actions:[{label:"Reload",onClick:()=>{}}]})})]})}),b.jsxs(ko,{eyebrow:"Inventory",title:"Component coverage",description:"Every current component file is accounted for here. Reusable primitives are rendered above; app surfaces that need live editor, git, auth, iframe, or generated state are cataloged instead of mounted unsafely.",children:[b.jsxs("div",{className:"mb-4 grid gap-3 sm:grid-cols-3",children:[b.jsxs("div",{className:"border-border bg-surface-2 rounded-xl border p-4",children:[b.jsx("p",{className:"text-content-subtle text-xs tracking-[0.16em] uppercase",children:"Total components"}),b.jsx("p",{className:"text-foreground mt-2 text-2xl font-semibold",children:tm.length})]}),b.jsxs("div",{className:"border-border bg-surface-2 rounded-xl border p-4",children:[b.jsx("p",{className:"text-content-subtle text-xs tracking-[0.16em] uppercase",children:"Showcased"}),b.jsx("p",{className:"text-accent-success mt-2 text-2xl font-semibold",children:t})]}),b.jsxs("div",{className:"border-border bg-surface-2 rounded-xl border p-4",children:[b.jsx("p",{className:"text-content-subtle text-xs tracking-[0.16em] uppercase",children:"Cataloged"}),b.jsx("p",{className:"text-primary mt-2 text-2xl font-semibold",children:e})]})]}),b.jsxs("div",{className:"border-border overflow-hidden rounded-xl border",children:[b.jsxs("div",{className:"border-border bg-surface-3 text-content-subtle grid grid-cols-[minmax(140px,1fr)_minmax(110px,auto)_minmax(220px,2fr)] border-b px-4 py-3 text-xs font-semibold tracking-[0.14em] uppercase",children:[b.jsx("span",{children:"Component"}),b.jsx("span",{children:"Status"}),b.jsx("span",{children:"Coverage note"})]}),b.jsx("div",{className:"divide-border bg-surface-2 divide-y",children:tm.map(n=>b.jsxs("div",{className:"grid grid-cols-[minmax(140px,1fr)_minmax(110px,auto)_minmax(220px,2fr)] gap-3 px-4 py-3 text-sm",children:[b.jsxs("div",{children:[b.jsx("p",{className:"text-foreground font-medium",children:n.name}),b.jsx("code",{className:"text-muted-foreground text-xs",children:n.path})]}),b.jsx("div",{children:b.jsx("span",{className:`inline-flex rounded-full border px-2 py-1 text-xs font-medium ${cae(n.status)}`,children:n.status})}),b.jsx("p",{className:"text-muted-foreground",children:n.note})]},n.path))})]})]})]})})},dae=t=>(t.startsWith("#/")?t.slice(2):t.slice(1)).split("?")[0]==="design-system"?"design-system":"editor",xx=274,Fg=395,Q_=Math.min(Fg,Math.round((xx+Fg)/2*1.1)),FP="rivet:panelWidth:v2",fae=t=>{if(!(t instanceof HTMLElement))return!1;const e=t.tagName.toLowerCase();return t.isContentEditable||e==="input"||e==="textarea"||e==="select"},hae=({projectPath:t,libraryOrigin:e})=>{const n=dt(d9)>0,[r,s]=QT(c9),i=lG(),[o,l]=m.useState(()=>{if(typeof window>"u")return Q_;const T=Number(window.localStorage.getItem(FP));return Number.isFinite(T)&&T>=xx&&T<=Fg?T:Q_}),[u,d]=m.useState(!1),[f,h]=m.useState(Ese),g=r?o:0,[v,w]=m.useState(r);m.useEffect(()=>{if(!r){w(!1);return}h(T=>kse({position:T,boundsLeftPx:o}))},[r,o]),m.useEffect(()=>{window.localStorage.setItem(FP,String(o))},[o]),m.useEffect(()=>{if(!r)return;const T=I=>{I.key==="Escape"&&(fae(I.target)||(I.preventDefault(),s(!1)))};return window.addEventListener("keydown",T),()=>window.removeEventListener("keydown",T)},[r,s]);const _=m.useCallback(T=>{T.preventDefault(),T.stopPropagation();const I=T.clientX,M=o;d(!0);const R=N=>{const D=Math.min(Fg,Math.max(xx,M+(N.clientX-I)));l(D)},O=()=>{window.removeEventListener("pointermove",R),window.removeEventListener("pointerup",O),window.removeEventListener("pointercancel",O),d(!1)};window.addEventListener("pointermove",R),window.addEventListener("pointerup",O),window.addEventListener("pointercancel",O)},[o]),x=m.useCallback(()=>l(Q_),[]),S=Vse(),k=dt(vv);Use({enabled:!k});const C=S.isProcessing?"Completing authentication...":null,A=gt(d4);return m.useEffect(()=>{A(t??null)},[t,A]),b.jsxs(Si.div,{className:"relative flex h-screen overflow-hidden",initial:!1,animate:{opacity:1},transition:{duration:.5,ease:"easeOut"},"data-cy":"rivet-app",children:[C!==null?b.jsx("div",{className:"absolute inset-0 z-50",children:b.jsx(dse,{message:C})}):null,b.jsx(Fne,{}),b.jsx(b.Fragment,{children:n?null:b.jsxs(b.Fragment,{children:[b.jsx("div",{className:"relative order-first h-full flex-shrink-0",style:{width:v?o:0},children:b.jsxs(Si.div,{className:"absolute inset-y-0 left-0 z-30",initial:!1,animate:{x:r?0:-o},transition:i?{duration:0}:{duration:.2,ease:[.22,1,.36,1]},onAnimationComplete:()=>{r&&w(!0)},style:{width:o,willChange:"transform"},children:[b.jsx(Qte,{onClose:()=>s(!1),libraryOrigin:e}),b.jsx("div",{role:"separator","aria-orientation":"vertical","aria-label":"Resize panel",onPointerDown:_,onDoubleClick:x,className:"group/resize absolute inset-y-0 right-0 z-20 flex w-3 cursor-col-resize touch-none justify-end",children:b.jsx("span",{className:`h-full transition-all duration-150 ${u?"bg-content-muted w-0.5":"bg-divider group-hover/resize:bg-content-muted w-px group-hover/resize:w-0.5"}`})})]})}),u&&b.jsx("div",{className:"fixed inset-0 z-[100] cursor-col-resize"}),b.jsx(Ase,{isVisible:!0,isPanelOpen:r,isReducedMotion:!!i,position:f,dragBoundsLeftPx:g,onPositionChange:h,onToggle:()=>s(T=>!T)})]})}),b.jsx($G,{duration:5e3,richColors:!0,toastOptions:{style:{maxHeight:"150px",overflow:"hidden"}}})]})},bx="rivet_connect_deep_link",pae=()=>{if(typeof window>"u")return null;const t=new URLSearchParams(window.location.search),e=t.get("connect"),n=e??window.sessionStorage.getItem(bx);if(n!=="pinterest"&&n!=="arena"&&n!=="x")return null;if(window.sessionStorage.setItem(bx,n),e){t.delete("connect");const r=t.toString();window.history.replaceState(null,document.title,window.location.pathname+(r?`?${r}`:"")+window.location.hash)}return n},mae=pae(),gae=()=>{const[t,e]=m.useState(window.location.hash),[n]=m.useState(()=>typeof window<"u"&&window.sessionStorage.getItem(Tg)==="1"),[r,s]=m.useState(!1),[i,o]=m.useState(mae);m.useEffect(()=>{n&&window.sessionStorage.removeItem(Tg)},[n]);const{config:l,refetchConfig:u,loading:d,error:f}=$se(),h=gt(vv),{startLogin:g,isStartingLogin:v,loginError:w}=O9(),[_,x]=m.useState(!1);m.useEffect(()=>{l!=null&&l.userId?(Ce.identify(l.userId,{...l.email?{email:l.email}:{}}),l.email&&Ce.alias(l.email,l.userId)):l!=null&&l.email&&Ce.identify(l.email,{email:l.email})},[l==null?void 0:l.userId,l==null?void 0:l.email]),m.useEffect(()=>{l&&Ce.register({source:"visual_editor",surface:"visual_editor"})},[l]);const S=l!=null&&l.agentModeAvailable!==!0,k=dae(t),C=m.useCallback(async()=>{x(!0),h(!0);try{await u()}finally{h(!1),x(!1)}},[u,h]);if(m.useEffect(()=>{const M=()=>{const R=window.location.hash;e(R)};return window.addEventListener("hashchange",M),()=>window.removeEventListener("hashchange",M)},[]),k==="design-system")return b.jsx(uae,{});if(!d&&l===null&&!_){const M=f||"Could not load Rivet configuration.";return b.jsx("div",{className:"bg-main flex h-screen items-center justify-center px-6",children:b.jsxs("div",{className:"border-divider bg-main w-full max-w-md rounded-lg border p-6 text-center shadow-lg",children:[b.jsx("p",{className:"text-content text-sm font-medium",children:"We could not start Rivet yet."}),b.jsx("p",{className:"text-content-dim mt-2 text-xs",children:M}),b.jsx("button",{type:"button",className:"border-divider text-content hover:bg-main/80 mt-4 rounded-md border px-3 py-1.5 text-xs",onClick:()=>{C()},children:"Retry"})]})})}if(S)return b.jsx(cse,{isSigningIn:v,onStartSignIn:()=>{g()},errorMessage:w,displayMode:"full"});const T=(l==null?void 0:l.agentModeAvailable)===!0&&i!==null,I=(l==null?void 0:l.agentModeAvailable)===!0&&n&&!r&&!T;return b.jsxs(b.Fragment,{children:[b.jsx(hae,{projectPath:l==null?void 0:l.projectPath,libraryOrigin:(l==null?void 0:l.libraryOrigin)??null}),b.jsx(Jw,{context:"onboarding",isOpen:I,onClose:()=>s(!0)}),b.jsx(Jw,{context:"menu",isOpen:T,highlightProvider:i,onClose:()=>{window.sessionStorage.removeItem(bx),o(null)}})]})},vae=m.lazy(()=>XP(()=>import("./LibraryEntry-yoxzWNdQ.js"),[])),vD=window.location.pathname.startsWith("/rivet/library"),yae="phc_Ntj9tXHbS64XgYxlTfhglRmFivFsfm0AERph4ZlnNH",_ae=new Cj,wae={session_recording:{maskAllInputs:!0,maskTextSelector:"[data-rivet-private]"}},xae=()=>b.jsx("div",{style:{display:"flex",height:"100vh",alignItems:"center",justifyContent:"center"},children:b.jsx("p",{style:{fontSize:"14px",color:"#6b7280"},children:"Something went wrong. Please reload the page."})}),yD=document.getElementById("root");if(!yD)throw new Error("Rivet root element is missing");const VP=()=>Oz.createRoot(yD).render(b.jsx(we.StrictMode,{children:b.jsx(HH,{apiKey:yae,options:{api_host:"https://rivet-proxy.onrender.com/ingest",ui_host:"https://us.posthog.com",person_profiles:"always",capture_exceptions:!0,autocapture:!0,capture_pageview:!0,capture_performance:!0,persistence:"localStorage",...wae,mask_all_text:!1,mask_all_element_attributes:!1,loaded:t=>{t.register({source:"visual_editor",surface:"visual_editor",telemetry_version:2,rivet_version:"0.21.4",env:"production"})}},children:b.jsx(qH,{fallback:b.jsx(xae,{}),children:b.jsx(ej,{client:_ae,children:b.jsx(RY,{defaultShape:"rounded",children:b.jsx(Coe,{defaultLibrary:"lucide",children:vD?b.jsx(m.Suspense,{fallback:b.jsx("div",{className:"bg-background h-screen"}),children:b.jsx(vae,{})}):b.jsx(gae,{})})})})})})}));vD?Ez().then(VP):VP();export{kae as $,dv as A,Qi as B,fv as C,uv as D,hv as E,pv as F,mv as G,Mt as H,fse as I,ip as J,poe as K,ZT as L,uh as M,dI as N,jie as O,i4 as P,wj as Q,nh as R,Qh as S,Zg as T,Tn as U,Xe as V,HT as W,Soe as X,dd as Y,mE as Z,_z as _,Pj as a,bY as a0,xe as a1,xz as a2,xh as a3,Nae as a4,Dae as a5,Cz as a6,dte as a7,Ut as a8,Rae as a9,Mae as aa,Iie as ab,Xte as ac,$G as ad,ate as ae,Aae as af,Pae as ag,Eae as ah,O9 as ai,kz as aj,Sz as ak,Cae as al,Rj as b,m as c,Mj as d,Lj as e,Ij as f,Sj as g,ch as h,Kr as i,Nj as j,Dj as k,Oj as l,s5 as m,pr as n,lt as o,Ei as p,r9 as q,n5 as r,ay as s,b as t,JP as u,Pw as v,o4 as w,a4 as x,l4 as y,aoe as z};