@tapflowio/relay 0.9.1 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/dist/RelayServer.d.ts +4 -0
  2. package/dist/RelayServer.d.ts.map +1 -1
  3. package/dist/RelayServer.js +67 -17
  4. package/dist/RelayServer.js.map +1 -1
  5. package/dist/SessionManager.d.ts +12 -1
  6. package/dist/SessionManager.d.ts.map +1 -1
  7. package/dist/SessionManager.js +19 -1
  8. package/dist/SessionManager.js.map +1 -1
  9. package/dist/api/builds.d.ts +2 -0
  10. package/dist/api/builds.d.ts.map +1 -1
  11. package/dist/api/builds.js +34 -7
  12. package/dist/api/builds.js.map +1 -1
  13. package/dist/index.d.ts +1 -0
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +1 -0
  16. package/dist/index.js.map +1 -1
  17. package/dist/lib/tlsTasks.d.ts +13 -0
  18. package/dist/lib/tlsTasks.d.ts.map +1 -0
  19. package/dist/lib/tlsTasks.js +21 -0
  20. package/dist/lib/tlsTasks.js.map +1 -0
  21. package/dist/migrations/012_build_delete_after.sql +14 -0
  22. package/dist/server.js +4 -10
  23. package/dist/server.js.map +1 -1
  24. package/dist/types.d.ts +1 -0
  25. package/dist/types.d.ts.map +1 -1
  26. package/package.json +4 -4
  27. package/public/assets/AppCenter-BkK502r-.js +21 -0
  28. package/public/assets/AppCenter-BkK502r-.js.br +0 -0
  29. package/public/assets/{Default-CK_yhJO6.js → Default-DJ3O2SsV.js} +1 -1
  30. package/public/assets/Default-DJ3O2SsV.js.br +0 -0
  31. package/public/assets/{Invite-9g1gI701.js → Invite-CvXlN2kS.js} +1 -1
  32. package/public/assets/Invite-CvXlN2kS.js.br +0 -0
  33. package/public/assets/{MacResources-41d3_9X2.js → MacResources-5y1xvEIy.js} +1 -1
  34. package/public/assets/MacResources-5y1xvEIy.js.br +0 -0
  35. package/public/assets/{NotFound-DsMP9eZN.js → NotFound-FsRS9tXW.js} +1 -1
  36. package/public/assets/NotFound-FsRS9tXW.js.br +0 -0
  37. package/public/assets/QASession-DaXI2EbF.js +130 -0
  38. package/public/assets/QASession-DaXI2EbF.js.br +0 -0
  39. package/public/assets/{ResetPassword-DsXsNFTA.js → ResetPassword-BmOUZhvy.js} +1 -1
  40. package/public/assets/ResetPassword-BmOUZhvy.js.br +0 -0
  41. package/public/assets/{Setup-CouJNq4v.js → Setup-DIjEK62E.js} +1 -1
  42. package/public/assets/Setup-DIjEK62E.js.br +0 -0
  43. package/public/assets/{Team-DUG0YTtb.js → Team-BF_Sypz1.js} +1 -1
  44. package/public/assets/Team-BF_Sypz1.js.br +0 -0
  45. package/public/assets/Tokens-CeT9D1an.js +1 -0
  46. package/public/assets/Tokens-CeT9D1an.js.br +0 -0
  47. package/public/assets/{alert-dialog-qlHDtr4B.js → alert-dialog-DdKN_y9-.js} +1 -1
  48. package/public/assets/alert-dialog-DdKN_y9-.js.br +0 -0
  49. package/public/assets/{badge-Cx2-XXcg.js → badge-BWfJJL5y.js} +1 -1
  50. package/public/assets/badge-BWfJJL5y.js.br +0 -0
  51. package/public/assets/build-format-B_GKS7x0.js +11 -0
  52. package/public/assets/build-format-B_GKS7x0.js.br +0 -0
  53. package/public/assets/{dialog-DzNUT3NF.js → dialog-C4OyiMxc.js} +1 -1
  54. package/public/assets/dialog-C4OyiMxc.js.br +0 -0
  55. package/public/assets/{index-Dfs85Uiw.js → index-C1qD3uWi.js} +3 -3
  56. package/public/assets/index-C1qD3uWi.js.br +0 -0
  57. package/public/assets/{pencil-CrO7Me4O.js → pencil-CKHOeGOo.js} +1 -1
  58. package/public/assets/pencil-CKHOeGOo.js.br +0 -0
  59. package/public/assets/{table-BXnp_tRt.js → table-CRKLjzLC.js} +1 -1
  60. package/public/assets/table-CRKLjzLC.js.br +0 -0
  61. package/public/assets/{tabs-BTnhanO2.js → tabs-LFfwE6UX.js} +1 -1
  62. package/public/assets/tabs-LFfwE6UX.js.br +0 -0
  63. package/public/assets/trash-2-DswjRF4T.js +11 -0
  64. package/public/assets/trash-2-DswjRF4T.js.br +0 -0
  65. package/public/index.html +1 -1
  66. package/public/index.html.br +0 -0
  67. package/public/assets/AppCenter-CH3MXel8.js +0 -16
  68. package/public/assets/AppCenter-CH3MXel8.js.br +0 -0
  69. package/public/assets/Default-CK_yhJO6.js.br +0 -0
  70. package/public/assets/Invite-9g1gI701.js.br +0 -0
  71. package/public/assets/MacResources-41d3_9X2.js.br +0 -0
  72. package/public/assets/NotFound-DsMP9eZN.js.br +0 -2
  73. package/public/assets/QASession-B02bILlB.js +0 -130
  74. package/public/assets/QASession-B02bILlB.js.br +0 -0
  75. package/public/assets/ResetPassword-DsXsNFTA.js.br +0 -0
  76. package/public/assets/Setup-CouJNq4v.js.br +0 -0
  77. package/public/assets/Team-DUG0YTtb.js.br +0 -0
  78. package/public/assets/Tokens-BWBEl4ax.js +0 -6
  79. package/public/assets/Tokens-BWBEl4ax.js.br +0 -0
  80. package/public/assets/alert-dialog-qlHDtr4B.js.br +0 -0
  81. package/public/assets/badge-Cx2-XXcg.js.br +0 -0
  82. package/public/assets/build-format-BvNznvYq.js +0 -11
  83. package/public/assets/build-format-BvNznvYq.js.br +0 -0
  84. package/public/assets/dialog-DzNUT3NF.js.br +0 -0
  85. package/public/assets/index-Dfs85Uiw.js.br +0 -0
  86. package/public/assets/pencil-CrO7Me4O.js.br +0 -0
  87. package/public/assets/plus-DnAOz8DL.js +0 -6
  88. package/public/assets/plus-DnAOz8DL.js.br +0 -0
  89. package/public/assets/table-BXnp_tRt.js.br +0 -0
  90. package/public/assets/tabs-BTnhanO2.js.br +0 -0
@@ -1,16 +0,0 @@
1
- import{Y as T,a7 as n,a4 as e,B as b,L as y,a9 as P,K as G,I as L,S as E,g as K,al as Q,am as J}from"./index-Dfs85Uiw.js";import{d as W,S as X,P as Z,g as ee,f as se,h as ae,b as te,u as le}from"./build-format-BvNznvYq.js";import{D as z,f as M,a as U,d as V,e as q,S as k,i as D,j as A,g as C,h as c,C as ne}from"./dialog-DzNUT3NF.js";import{P as re}from"./plus-DnAOz8DL.js";import{B as O}from"./badge-Cx2-XXcg.js";import{A as ie,c as ce,f as oe,g as de,d as xe,e as ue,b as pe,a as he}from"./alert-dialog-qlHDtr4B.js";/**
2
- * @license lucide-react v0.577.0 - ISC
3
- *
4
- * This source code is licensed under the ISC license.
5
- * See the LICENSE file in the root directory of this source tree.
6
- */const me=[["path",{d:"M12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83z",key:"zw3jo"}],["path",{d:"M2 12a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 12",key:"1wduqc"}],["path",{d:"M2 17a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 17",key:"kqbvx6"}]],fe=T("layers",me);/**
7
- * @license lucide-react v0.577.0 - ISC
8
- *
9
- * This source code is licensed under the ISC license.
10
- * See the LICENSE file in the root directory of this source tree.
11
- */const ge=[["path",{d:"M11 21.73a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73z",key:"1a0edw"}],["path",{d:"M12 22V12",key:"d0xqtd"}],["polyline",{points:"3.29 7 12 12 20.71 7",key:"ousv84"}],["path",{d:"m7.5 4.27 9 5.15",key:"1c824w"}]],je=T("package",ge);/**
12
- * @license lucide-react v0.577.0 - ISC
13
- *
14
- * This source code is licensed under the ISC license.
15
- * See the LICENSE file in the root directory of this source tree.
16
- */const ve=[["path",{d:"M12 3v12",key:"1x0j5s"}],["path",{d:"m17 8-5-5-5 5",key:"7q97r8"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}]],Ne=T("upload",ve);function Se({onSuccess:s,appId:l}){const[u,r]=n.useState(!1),[a,h]=n.useState(null),[o,p]=n.useState("none"),g=n.useRef(null);function f(i){if(i.preventDefault(),!a)return;const d=new FormData;d.append("file",a),o!=="none"&&d.append("status",o),l&&d.append("app_id",String(l));const N=fetch("/api/v1/builds",{method:"POST",credentials:"include",body:d}).then(async x=>{if(!x.ok){const m=await x.json().catch(()=>({}));throw new Error(m.error??"Upload failed. Check the file format.")}s()});P.promise(N,{loading:"Uploading build…",success:"Build uploaded",error:x=>x instanceof Error?x.message:"Failed to upload build"}),r(!1),h(null),p("none")}function v(i){r(i),i||(h(null),p("none"))}return e.jsxs(z,{open:u,onOpenChange:v,children:[e.jsx(M,{asChild:!0,children:e.jsxs(b,{size:"sm",children:[e.jsx(Ne,{className:"mr-2 h-4 w-4"}),"Upload build"]})}),e.jsxs(U,{className:"sm:max-w-md",children:[e.jsx(V,{children:e.jsx(q,{children:"Upload build"})}),e.jsxs("form",{onSubmit:f,className:"flex flex-col gap-4 pt-2",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(y,{children:"File"}),e.jsx("div",{className:"flex h-24 cursor-pointer items-center justify-center rounded-md border-2 border-dashed text-sm text-muted-foreground hover:border-primary",onClick:()=>{var i;return(i=g.current)==null?void 0:i.click()},onDragOver:i=>i.preventDefault(),onDrop:i=>{i.preventDefault();const d=i.dataTransfer.files[0];d&&h(d)},children:a?a.name:"Click or drag to upload"}),e.jsx("input",{ref:g,type:"file",accept:".zip,.apk",className:"hidden",onChange:i=>{var d;return h(((d=i.target.files)==null?void 0:d[0])??null)}}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["iOS: ",e.jsx("code",{children:".app.zip"})," (zip the ",e.jsx("code",{children:".app"})," folder after ",e.jsx("code",{children:"xcodebuild -sdk iphonesimulator"}),")  · Android: ",e.jsx("code",{children:".apk"})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs(y,{children:["Status ",e.jsx("span",{className:"text-muted-foreground",children:"(optional)"})]}),e.jsxs(k,{value:o,onValueChange:p,children:[e.jsx(D,{children:e.jsx(A,{})}),e.jsxs(C,{children:[e.jsx(c,{value:"none",children:"None"}),e.jsx(c,{value:"Backlog",children:"Backlog"}),e.jsx(c,{value:"In Progress",children:"In Progress"}),e.jsx(c,{value:"Done",children:"Done"}),e.jsx(c,{value:"Rejected",children:"Rejected"})]})]})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(b,{type:"button",variant:"outline",className:"w-24",onClick:()=>r(!1),children:"Cancel"}),e.jsx(b,{type:"submit",className:"w-24",disabled:!a,children:"Upload"})]})]})]})]})}function w({className:s,...l}){return e.jsx("span",{className:G("font-mono text-xs tabular-nums tracking-tight",s),...l})}function be({onSuccess:s}){const[l,u]=n.useState(!1),[r,a]=n.useState(""),[h,o]=n.useState(""),[p,g]=n.useState("ios"),[f,v]=n.useState(""),[i,d]=n.useState(!1);async function N(x){x.preventDefault(),v(""),d(!0);try{const m=await W({name:r.trim(),bundle_id_key:h.trim(),platform:p});if(!m){v("Failed to create app");return}if("error"in m){v(m.error);return}u(!1),a(""),o(""),g("ios"),P.success("App created"),s()}catch{P.error("Failed to create app — check your network")}finally{d(!1)}}return e.jsxs(z,{open:l,onOpenChange:u,children:[e.jsx(M,{asChild:!0,children:e.jsxs("button",{className:"flex w-full items-center gap-1.5 rounded-md px-2 py-1.5 text-left text-sm text-muted-foreground hover:bg-accent hover:text-foreground transition-colors",children:[e.jsx(re,{className:"size-3.5 shrink-0"}),e.jsx("span",{children:"Add App"})]})}),e.jsxs(U,{className:"sm:max-w-sm",children:[e.jsx(V,{children:e.jsx(q,{children:"Add App"})}),e.jsxs("form",{onSubmit:N,className:"flex flex-col gap-4 pt-2",children:[e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(y,{htmlFor:"app-name",children:"Name"}),e.jsx(L,{id:"app-name",value:r,onChange:x=>a(x.target.value),placeholder:"My App",required:!0})]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(y,{htmlFor:"bundle-id",children:"Bundle ID"}),e.jsx(L,{id:"bundle-id",value:h,onChange:x=>o(x.target.value),placeholder:"com.example.myapp",required:!0})]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(y,{htmlFor:"platform",children:"Platform"}),e.jsxs(k,{value:p,onValueChange:x=>g(x),children:[e.jsx(D,{id:"platform",children:e.jsx(A,{})}),e.jsxs(C,{children:[e.jsx(c,{value:"ios",children:"iOS"}),e.jsx(c,{value:"android",children:"Android"}),e.jsx(c,{value:"both",children:"Both"})]})]})]}),f&&e.jsx("p",{className:"text-sm text-destructive",children:f}),e.jsx(b,{type:"submit",disabled:i,className:"w-full",children:i?"Creating…":"Create App"})]})]})]})}function ye({apps:s,selectedAppId:l,onSelect:u,onAdd:r}){return e.jsxs("aside",{className:"w-64 shrink-0 border-r flex flex-col gap-1 p-3 overflow-y-auto",children:[e.jsx("span",{className:"px-2 pb-1 font-mono text-xs font-medium text-muted-foreground uppercase tracking-wider",children:"Apps"}),s.length===0&&e.jsx("span",{className:"px-2 text-sm text-muted-foreground",children:"No apps yet"}),s.map(a=>e.jsxs("button",{onClick:()=>u(a.id),className:["flex flex-col gap-0.5 rounded-md px-2 py-2 text-left text-sm hover:bg-accent overflow-hidden",a.id===l?"bg-accent font-medium":""].join(" "),children:[e.jsx("span",{className:"truncate",children:a.name}),e.jsx(w,{className:"text-muted-foreground truncate",children:a.bundle_id_key})]},a.id)),e.jsx("div",{className:"mt-1 border-t pt-1",children:e.jsx(be,{onSuccess:r})})]})}function we(s){const r=new Date(s).getTime()+6048e5-Date.now();if(r<=0)return{label:"Expired",urgent:!0};const a=Math.floor(r/36e5);return a<1?{label:"< 1 hour left",urgent:!0}:a<24?{label:`Expires in ${a}h`,urgent:a<6}:{label:`Expires in ${Math.floor(a/24)}d`,urgent:!1}}function ke({build:s,isLast:l,onNavigate:u,onStatusChange:r}){const[a,h]=n.useState(!1),o=s.status_label==="Done",p=o&&s.completed_at?we(s.completed_at):null;function g(f){if(f==="Done"){h(!0);return}r(s.id,f==="none"?null:f)}return e.jsxs(e.Fragment,{children:[e.jsx(ie,{open:a,onOpenChange:h,children:e.jsxs(ce,{children:[e.jsxs(oe,{children:[e.jsx(de,{children:"Mark as Done?"}),e.jsx(xe,{children:"Build files will be automatically deleted after 7 days. Reverting the status will cancel the scheduled deletion."})]}),e.jsxs(ue,{children:[e.jsx(pe,{children:"Cancel"}),e.jsx(he,{onClick:()=>{r(s.id,"Done"),h(!1)},children:"Confirm"})]})]})}),e.jsxs("div",{className:["flex items-center gap-3 px-4 py-3",l?"":"border-b"].join(" "),children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs("span",{className:"text-sm font-medium",children:["build ",e.jsx(w,{children:s.build_number??"—"})]}),e.jsx(O,{tone:s.platform==="ios"?"ios":"android",className:"text-xs capitalize",children:s.platform}),s.status_label&&e.jsx(O,{tone:X[s.status_label],className:"text-xs",children:s.status_label})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"row",gap:"14px",marginTop:"0.7rem",alignItems:"center"},className:"text-xs text-muted-foreground",children:[s.uploader&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:s.uploader}),e.jsx(E,{orientation:"vertical",className:"h-3"})]}),e.jsx(w,{children:new Date(s.uploaded_at).toLocaleDateString()}),p&&e.jsxs(e.Fragment,{children:[e.jsx(E,{orientation:"vertical",className:"h-3"}),e.jsx("span",{className:p.urgent?"text-destructive":"",children:p.label})]})]})]}),e.jsxs(k,{value:s.status_label??"none",onValueChange:g,children:[e.jsx(D,{className:"h-9 w-32 text-xs",children:e.jsx(A,{})}),e.jsxs(C,{children:[e.jsx(c,{value:"none",children:e.jsx("span",{className:"text-muted-foreground",children:"—"})}),e.jsx(c,{value:"Backlog",children:"Backlog"}),e.jsx(c,{value:"In Progress",children:"In Progress"}),e.jsx(c,{value:"Done",children:"Done"}),e.jsx(c,{value:"Rejected",children:"Rejected"})]})]}),e.jsxs(b,{size:"sm",onClick:()=>u(s.id),disabled:o,children:[e.jsx(Z,{className:"mr-1.5 h-3.5 w-3.5"}),"Start QA"]})]})]})}function De({versionName:s,builds:l,isOpen:u,onToggle:r,onNavigate:a,onStatusChange:h}){return e.jsxs("div",{className:"rounded-lg shadow-card-2 overflow-hidden",children:[e.jsxs("button",{className:"flex w-full items-center gap-2 px-4 py-3 text-left hover:bg-accent/50 bg-card",onClick:r,children:[u?e.jsx(ne,{className:"h-4 w-4 shrink-0 text-muted-foreground"}):e.jsx(K,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),e.jsx(w,{className:"font-medium text-sm text-foreground",children:s}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["(",l.length," build",l.length>1?"s":"",")"]})]}),u&&e.jsx("div",{className:"border-t bg-card",children:l.map((o,p)=>e.jsx(ke,{build:o,isLast:p===l.length-1,onNavigate:a,onStatusChange:h},o.id))})]})}function Te(){const s=Q(),[l,u]=J(),[r,a]=n.useState([]),[h,o]=n.useState([]),[p,g]=n.useState(""),[f,v]=n.useState("all"),[i,d]=n.useState(!0),[N,x]=n.useState(new Set),m=l.get("appId")?Number(l.get("appId")):null,R=r.find(t=>t.id===m)??null,_=n.useCallback(async()=>{const t=await ee();a(t),!l.get("appId")&&t.length>0&&u({appId:String(t[0].id)},{replace:!0})},[l,u]),B=n.useCallback(async()=>{if(!m){o([]),d(!1);return}d(!0);try{const t=await se({appId:m,search:p,statusFilter:f});o(t),t.length>0&&N.size===0&&x(new Set([t[0].version_name??"Unversioned"]))}finally{d(!1)}},[m,p,f]);n.useEffect(()=>{_()},[]),n.useEffect(()=>{B()},[B]);function $(t){t!==m&&(o([]),x(new Set)),u({appId:String(t)})}function H(t){x(S=>{const j=new Set(S);return j.has(t)?j.delete(t):j.add(t),j})}async function Y(t,S){await le(t,S),o(j=>j.map(I=>I.id===t?{...I,status_label:S}:I))}const F=ae(h);return e.jsxs("div",{className:"flex h-full gap-0",children:[e.jsx(ye,{apps:r,selectedAppId:m,onSelect:$,onAdd:_}),e.jsxs("main",{className:"flex-1 flex flex-col gap-4 p-4 overflow-y-auto min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-2",children:[e.jsx("h1",{className:"text-xl font-semibold tracking-display-sm",children:R?R.name:"App Center"}),e.jsx(Se,{onSuccess:()=>{_(),B()},appId:m})]}),m?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(te,{placeholder:"Search version…",value:p,onChange:g}),e.jsxs(k,{value:f,onValueChange:v,children:[e.jsx(D,{className:"h-8 w-36",children:e.jsx(A,{placeholder:"Status"})}),e.jsxs(C,{children:[e.jsx(c,{value:"all",children:"All statuses"}),e.jsx(c,{value:"Backlog",children:"Backlog"}),e.jsx(c,{value:"In Progress",children:"In Progress"}),e.jsx(c,{value:"Done",children:"Done"}),e.jsx(c,{value:"Rejected",children:"Rejected"})]})]})]}),i?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading…"}):F.length===0?e.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center gap-2 text-center",children:[e.jsx(je,{className:"w-8 h-8 text-muted-foreground/40"}),e.jsx("p",{className:"text-sm font-medium",children:"No builds yet"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Upload the first build to get started."})]}):e.jsx("div",{className:"flex flex-col gap-2",children:F.map(({versionName:t,builds:S})=>e.jsx(De,{versionName:t,builds:S,isOpen:N.has(t),onToggle:()=>H(t),onNavigate:j=>s(`/app-center/build?id=${j}`),onStatusChange:Y},t))})]}):e.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center gap-2 text-center",children:[e.jsx(fe,{className:"w-8 h-8 text-muted-foreground/40"}),e.jsx("p",{className:"text-sm font-medium",children:"No app selected"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Choose an app from the sidebar to view its builds."})]})]})]})}export{Te as AppCenter};
Binary file
@@ -1,2 +0,0 @@
1
- +��rN_�r�J���)NR�O��n�񃵖͉]6FOqF6u�GItv�Z�A����3N�[p^����O��3ꜘ�b����\��p�j9w9o����Z�'��W�S�gY�c�Ԇ�> ��W��Ni�{��
2
- W�M$SPD�5��@�@%�q�`�wM/�� �\s21'��ڣ5�=G�a�F�G�a�Ex> 6�:�)Ă+�lb5=�2�Fy.��O�)��"�v��z�x�%B�7,Y����^�G�����M
@@ -1,130 +0,0 @@
1
- import{Y as G,a7 as o,am as Jt,a4 as n,K,z as kt,T as we,E as Se,B as ee,y as Re,S as Zt,s as Vn,a9 as at,ae as $e,ag as Xn,u as Ie,t as bt,Q as Qt,N as Ue,ad as qe,ak as Yn,U as Kn,x as Gn,g as qn,af as Jn,an as Zn,al as Qn,ac as er,L as tr}from"./index-Dfs85Uiw.js";import{e as nr,a as rr,P as en,c as $t,S as sr,b as or}from"./build-format-BvNznvYq.js";import{u as tn,T as ar,b as ir,c as It,a as Ft}from"./tabs-BTnhanO2.js";import{D as nn,a as rn,d as cr,e as sn,b as lr,c as dr,k as ur,u as hr,S as fr,i as pr,j as mr,g as gr,h as Bt}from"./dialog-DzNUT3NF.js";import{B as xr}from"./badge-Cx2-XXcg.js";/**
2
- * @license lucide-react v0.577.0 - ISC
3
- *
4
- * This source code is licensed under the ISC license.
5
- * See the LICENSE file in the root directory of this source tree.
6
- */const br=[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]],yr=G("arrow-left",br);/**
7
- * @license lucide-react v0.577.0 - ISC
8
- *
9
- * This source code is licensed under the ISC license.
10
- * See the LICENSE file in the root directory of this source tree.
11
- */const vr=[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]],wr=G("arrow-up",vr);/**
12
- * @license lucide-react v0.577.0 - ISC
13
- *
14
- * This source code is licensed under the ISC license.
15
- * See the LICENSE file in the root directory of this source tree.
16
- */const Sr=[["path",{d:"M13.997 4a2 2 0 0 1 1.76 1.05l.486.9A2 2 0 0 0 18.003 7H20a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V9a2 2 0 0 1 2-2h1.997a2 2 0 0 0 1.759-1.048l.489-.904A2 2 0 0 1 10.004 4z",key:"18u6gg"}],["circle",{cx:"12",cy:"13",r:"3",key:"1vg3eu"}]],Rr=G("camera",Sr);/**
17
- * @license lucide-react v0.577.0 - ISC
18
- *
19
- * This source code is licensed under the ISC license.
20
- * See the LICENSE file in the root directory of this source tree.
21
- */const jr=[["path",{d:"M12 15V3",key:"m9g1x1"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}],["path",{d:"m7 10 5 5 5-5",key:"brsn70"}]],kr=G("download",jr);/**
22
- * @license lucide-react v0.577.0 - ISC
23
- *
24
- * This source code is licensed under the ISC license.
25
- * See the LICENSE file in the root directory of this source tree.
26
- */const Cr=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M7 3v18",key:"bbkbws"}],["path",{d:"M3 7.5h4",key:"zfgn84"}],["path",{d:"M3 12h18",key:"1i2n21"}],["path",{d:"M3 16.5h4",key:"1230mu"}],["path",{d:"M17 3v18",key:"in4fa5"}],["path",{d:"M17 7.5h4",key:"myr1c1"}],["path",{d:"M17 16.5h4",key:"go4c1d"}]],Er=G("film",Cr);/**
27
- * @license lucide-react v0.577.0 - ISC
28
- *
29
- * This source code is licensed under the ISC license.
30
- * See the LICENSE file in the root directory of this source tree.
31
- */const Nr=[["path",{d:"M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8",key:"5wwlr5"}],["path",{d:"M3 10a2 2 0 0 1 .709-1.528l7-6a2 2 0 0 1 2.582 0l7 6A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z",key:"r6nss1"}]],on=G("house",Nr);/**
32
- * @license lucide-react v0.577.0 - ISC
33
- *
34
- * This source code is licensed under the ISC license.
35
- * See the LICENSE file in the root directory of this source tree.
36
- */const _r=[["path",{d:"M16 5h6",key:"1vod17"}],["path",{d:"M19 2v6",key:"4bpg5p"}],["path",{d:"M21 11.5V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h7.5",key:"1ue2ih"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21",key:"1xmnt7"}],["circle",{cx:"9",cy:"9",r:"2",key:"af1f0g"}]],Tr=G("image-plus",_r);/**
37
- * @license lucide-react v0.577.0 - ISC
38
- *
39
- * This source code is licensed under the ISC license.
40
- * See the LICENSE file in the root directory of this source tree.
41
- */const Pr=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 16v-4",key:"1dtifu"}],["path",{d:"M12 8h.01",key:"e9boi3"}]],Ar=G("info",Pr);/**
42
- * @license lucide-react v0.577.0 - ISC
43
- *
44
- * This source code is licensed under the ISC license.
45
- * See the LICENSE file in the root directory of this source tree.
46
- */const Dr=[["path",{d:"M10 8h.01",key:"1r9ogq"}],["path",{d:"M12 12h.01",key:"1mp3jc"}],["path",{d:"M14 8h.01",key:"1primd"}],["path",{d:"M16 12h.01",key:"1l6xoz"}],["path",{d:"M18 8h.01",key:"emo2bl"}],["path",{d:"M6 8h.01",key:"x9i8wu"}],["path",{d:"M7 16h10",key:"wp8him"}],["path",{d:"M8 12h.01",key:"czm47f"}],["rect",{width:"20",height:"16",x:"2",y:"4",rx:"2",key:"18n3k1"}]],Lr=G("keyboard",Dr);/**
47
- * @license lucide-react v0.577.0 - ISC
48
- *
49
- * This source code is licensed under the ISC license.
50
- * See the LICENSE file in the root directory of this source tree.
51
- */const Mr=[["path",{d:"M9 17H7A5 5 0 0 1 7 7h2",key:"8i5ue5"}],["path",{d:"M15 7h2a5 5 0 1 1 0 10h-2",key:"1b9ql8"}],["line",{x1:"8",x2:"16",y1:"12",y2:"12",key:"1jonct"}]],an=G("link-2",Mr);/**
52
- * @license lucide-react v0.577.0 - ISC
53
- *
54
- * This source code is licensed under the ISC license.
55
- * See the LICENSE file in the root directory of this source tree.
56
- */const Hr=[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]],pt=G("loader-circle",Hr);/**
57
- * @license lucide-react v0.577.0 - ISC
58
- *
59
- * This source code is licensed under the ISC license.
60
- * See the LICENSE file in the root directory of this source tree.
61
- */const Ur=[["path",{d:"M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z",key:"18887p"}]],$r=G("message-square",Ur);/**
62
- * @license lucide-react v0.577.0 - ISC
63
- *
64
- * This source code is licensed under the ISC license.
65
- * See the LICENSE file in the root directory of this source tree.
66
- */const Ir=[["path",{d:"M12 2v10",key:"mnfbl"}],["path",{d:"M18.4 6.6a9 9 0 1 1-12.77.04",key:"obofu9"}]],Fr=G("power",Ir);/**
67
- * @license lucide-react v0.577.0 - ISC
68
- *
69
- * This source code is licensed under the ISC license.
70
- * See the LICENSE file in the root directory of this source tree.
71
- */const Br=[["path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8",key:"1p45f6"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}]],zr=G("rotate-cw",Br);/**
72
- * @license lucide-react v0.577.0 - ISC
73
- *
74
- * This source code is licensed under the ISC license.
75
- * See the LICENSE file in the root directory of this source tree.
76
- */const Or=[["path",{d:"M3 7V5a2 2 0 0 1 2-2h2",key:"aa7l1z"}],["path",{d:"M17 3h2a2 2 0 0 1 2 2v2",key:"4qcy5o"}],["path",{d:"M21 17v2a2 2 0 0 1-2 2h-2",key:"6vwrx8"}],["path",{d:"M7 21H5a2 2 0 0 1-2-2v-2",key:"ioqczr"}],["path",{d:"M7 12h10",key:"b7w52i"}]],Wr=G("scan-line",Or);/**
77
- * @license lucide-react v0.577.0 - ISC
78
- *
79
- * This source code is licensed under the ISC license.
80
- * See the LICENSE file in the root directory of this source tree.
81
- */const Vr=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]],Xr=G("square",Vr);/**
82
- * @license lucide-react v0.577.0 - ISC
83
- *
84
- * This source code is licensed under the ISC license.
85
- * See the LICENSE file in the root directory of this source tree.
86
- */const Yr=[["path",{d:"m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.752-.432L16 10.5",key:"ftymec"}],["rect",{x:"2",y:"6",width:"14",height:"12",rx:"2",key:"158x01"}]],Kr=G("video",Yr);/**
87
- * @license lucide-react v0.577.0 - ISC
88
- *
89
- * This source code is licensed under the ISC license.
90
- * See the LICENSE file in the root directory of this source tree.
91
- */const Gr=[["path",{d:"M11 4.702a.705.705 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298z",key:"uqj9uw"}],["path",{d:"M16 9a5 5 0 0 1 0 6",key:"1q6k2b"}],["path",{d:"M19.364 18.364a9 9 0 0 0 0-12.728",key:"ijwkga"}]],qr=G("volume-2",Gr);/**
92
- * @license lucide-react v0.577.0 - ISC
93
- *
94
- * This source code is licensed under the ISC license.
95
- * See the LICENSE file in the root directory of this source tree.
96
- */const Jr=[["path",{d:"M11 4.702a.705.705 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298z",key:"uqj9uw"}],["path",{d:"M16 9a5 5 0 0 1 0 6",key:"1q6k2b"}]],Zr=G("volume-1",Jr);function Qr(e){const[t,r]=o.useState(null);return o.useEffect(()=>{e&&nr(e).then(r)},[e]),{build:t}}function es(e){const[t,r]=o.useState([]),[s,a]=o.useState(null),[i,l]=o.useState(null),[f,h]=o.useState(""),[m,p]=o.useState(!1),[x,d]=o.useState(""),v=o.useCallback(D=>{D.type==="agents:listed"&&r(D.sessions),D.type==="session:joined"&&(p(!1),d("Connected")),D.type==="error"&&(p(!1),d(`Error: ${D.message}`))},[]),{send:S,connected:L}=tn(v);o.useEffect(()=>{if(!L)return;S({type:"agents:list"});const D=setInterval(()=>S({type:"agents:list"}),5e3);return()=>clearInterval(D)},[L,S]);const k=o.useRef({sessionId:i,deviceId:f});o.useEffect(()=>{k.current={sessionId:i,deviceId:f}},[i,f]),o.useEffect(()=>()=>{const{sessionId:D,deviceId:B}=k.current;D&&B&&S({type:"device:shutdown",sessionId:D,payload:{deviceId:B}})},[S]);const A=t.filter(D=>D.devices.some(B=>B.platform===e)),C=o.useCallback(D=>{h(D.id),p(!0),d("Booting…"),l(D.sessionId)},[]),T=o.useCallback(()=>h(""),[]),E=o.useCallback(()=>{const{sessionId:D,deviceId:B}=k.current;D&&B&&S({type:"device:shutdown",sessionId:D,payload:{deviceId:B}}),l(null),p(!1),d("")},[S]),$=o.useCallback(()=>{const{sessionId:D,deviceId:B}=k.current;D&&B&&S({type:"device:shutdown",sessionId:D,payload:{deviceId:B}}),l(null),a(null),p(!1),d("")},[S]);return{sessions:t,selectedAgent:s,setSelectedAgent:a,activeSessionId:i,deviceId:f,booting:m,status:x,send:S,connected:L,agentGroups:A,startDevice:C,resetDevice:T,handleBack:E,handleBackToMacs:$}}function ts(e,t){const[r,s]=o.useState(""),[a,i]=o.useState(""),[l,f]=o.useState("app-only"),h=(e==null?void 0:e.devices.filter(x=>x.platform===t))??[],m=[...new Set(h.map(x=>x.osVersion).filter(Boolean))].sort((x,d)=>{const v=k=>k.replace(/^[^\d]*/,"").split(".").map(Number),[S,L]=[v(x),v(d)];for(let k=0;k<Math.max(S.length,L.length);k++){const A=(L[k]??0)-(S[k]??0);if(A!==0)return A}return 0}),p=(r?h.filter(x=>x.osVersion===r):h).filter(x=>!a||x.name.toLowerCase().includes(a.toLowerCase()));return{filteredDevices:h,osVersions:m,osVersion:r,setOsVersion:s,deviceSearch:a,setDeviceSearch:i,versionedDevices:p,resetMode:l,setResetMode:f}}function ns(){const[e]=Jt(),t=e.get("perf")==="1",[r,s]=o.useState(t);return o.useEffect(()=>{if(!t){s(!1);return}s(!0);const a=i=>{i.ctrlKey&&i.shiftKey&&i.key==="P"&&s(l=>!l)};return window.addEventListener("keydown",a),()=>window.removeEventListener("keydown",a)},[t]),{perfMode:t,visible:r}}const rs=["video/mp4;codecs=avc1","video/webm;codecs=vp9","video/webm;codecs=vp8","video/webm"];function cn({sessionId:e,buildId:t,onRecordingUploaded:r}){const[s,a]=o.useState("idle"),i=o.useRef(null),l=o.useRef(r);o.useEffect(()=>{l.current=r},[r]);const f=o.useRef(!1),h=o.useRef(null),m=o.useRef([]),p=o.useRef(""),x=o.useRef(0),d=o.useRef(null),v=o.useCallback(()=>{var k;f.current&&((k=d.current)==null||k.call(d),x.current=requestAnimationFrame(v))},[]),S=o.useCallback(k=>{const A=i.current;if(!A)return;const C=A.getContext("2d");C&&(C.fillStyle="#000",C.fillRect(0,0,A.width,A.height));const T=rs.find($=>MediaRecorder.isTypeSupported($))??"";if(!T)return;p.current=T,m.current=[];const E=new MediaRecorder(A.captureStream(30),{mimeType:T});E.ondataavailable=$=>{$.data.size>0&&m.current.push($.data)},h.current=E,E.start(1e3),d.current=k,f.current=!0,x.current=requestAnimationFrame(v),a("recording")},[v]),L=o.useCallback(async()=>{var $;a("uploading"),f.current=!1,cancelAnimationFrame(x.current);const k=h.current;if(!k){a("idle");return}await new Promise(D=>{const B=setTimeout(D,5e3);k.onstop=()=>{clearTimeout(B),D()};try{k.stop()}catch{clearTimeout(B),D()}}),h.current=null;const A=p.current,C=A.includes("mp4")?".mp4":".webm",T=new Blob(m.current,{type:A});m.current=[];const E=new FormData;E.append("file",T,`tapflow-${Date.now()}${C}`);try{const D=new URLSearchParams({sessionId:e});t&&D.set("buildId",String(t));const B=await fetch(`/api/v1/recordings/upload?${D}`,{method:"POST",credentials:"include",body:E}),X=await B.json();if(B.ok&&X.url){const I=document.createElement("a");I.href=X.url,I.download="",I.click(),($=l.current)==null||$.call(l),a("done"),setTimeout(()=>a("idle"),2e3)}else a("idle")}catch{a("idle")}},[e,t]);return o.useEffect(()=>{if(s!=="recording")return;const k=()=>{document.visibilityState==="hidden"&&L()};return document.addEventListener("visibilitychange",k),()=>{var A;document.removeEventListener("visibilitychange",k),f.current&&(f.current=!1,cancelAnimationFrame(x.current),(A=h.current)==null||A.stop(),h.current=null)}},[s,L]),{recordState:s,recordCanvasRef:i,startClientRecording:S,stopClientRecording:L}}function ln(){const e=o.useRef(0),[t,r]=o.useState(0);return o.useEffect(()=>{const s=setInterval(()=>{r(e.current),e.current=0},1e3);return()=>clearInterval(s)},[]),{fps:t,frameCount:e}}function Ge({className:e,...t}){return n.jsx("kbd",{"data-slot":"kbd",className:K("bg-muted text-muted-foreground pointer-events-none inline-flex h-5 w-fit min-w-5 select-none items-center justify-center gap-1 rounded-sm px-1 font-sans text-xs font-medium","[&_svg:not([class*='size-'])]:size-3","[[data-slot=tooltip-content]_&]:bg-background/20 [[data-slot=tooltip-content]_&]:text-background dark:[[data-slot=tooltip-content]_&]:bg-background/10",e),...t})}function Ct({className:e,...t}){return n.jsx("kbd",{"data-slot":"kbd-group",className:K("inline-flex items-center gap-1",e),...t})}function rt({label:e,keys:t}){return n.jsxs("span",{className:"flex items-center gap-3",children:[e,n.jsx(Ct,{children:t.map(r=>n.jsx(Ge,{children:r},r))})]})}function dn({joined:e,onScreenshot:t,onRecordToggle:r,recordState:s,onRotate:a,onDeepLink:i,platformSlot:l,launchSlot:f}){return e?n.jsx(kt,{delayDuration:400,children:n.jsxs("div",{className:"flex flex-col items-center gap-0.5 rounded-2xl border bg-background/90 backdrop-blur-sm px-1.5 py-2.5 shrink-0 mt-3",children:[f,l,n.jsxs(we,{children:[n.jsx(Se,{asChild:!0,children:n.jsx(ee,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:i,children:n.jsx(an,{className:"h-4 w-4"})})}),n.jsx(Re,{side:"left",children:n.jsx(rt,{label:"Deeplink",keys:["⌘","K"]})})]}),n.jsx("div",{className:"w-4 h-px bg-border my-1"}),n.jsxs(we,{children:[n.jsx(Se,{asChild:!0,children:n.jsx(ee,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:t,children:n.jsx(Rr,{className:"h-4 w-4"})})}),n.jsx(Re,{side:"left",children:n.jsx(rt,{label:"Screenshot",keys:["⌘","S"]})})]}),n.jsxs(we,{children:[n.jsx(Se,{asChild:!0,children:n.jsx(ee,{variant:"ghost",size:"icon",className:K("h-8 w-8",s==="recording"&&"text-red-500 hover:text-red-500"),disabled:s==="uploading"||s==="done",onClick:r,children:s==="uploading"?n.jsx(pt,{className:"h-4 w-4 animate-spin"}):s==="recording"?n.jsx(Xr,{className:"h-4 w-4 fill-current"}):n.jsx(Kr,{className:"h-4 w-4"})})}),n.jsx(Re,{side:"left",children:s==="idle"?n.jsx(rt,{label:"Start recording",keys:["⌘","⇧","Y"]}):s==="recording"?n.jsx(rt,{label:"Stop recording",keys:["⌘","⇧","Y"]}):"Processing…"})]}),n.jsx("div",{className:"w-4 h-px bg-border my-1"}),n.jsxs(we,{children:[n.jsx(Se,{asChild:!0,children:n.jsx(ee,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:a,children:n.jsx(zr,{className:"h-4 w-4"})})}),n.jsx(Re,{side:"left",children:n.jsx(rt,{label:"Rotate",keys:["⌘","⇧","O"]})})]})]})}):null}class Et{constructor(t){this.bytes=t,this.bitPos=0}get position(){return this.bitPos}bit(){const t=this.bitPos>>3,r=7-(this.bitPos&7);return this.bitPos++,t>=this.bytes.length?0:this.bytes[t]>>r&1}bits(t){let r=0;for(let s=0;s<t;s++)r=r<<1|this.bit();return r>>>0}flag(){return this.bit()===1}ue(){let t=0;for(;this.bit()===0&&t<32;)t++;return t===0?0:(1<<t)-1+this.bits(t)}se(){const t=this.ue();return t&1?Math.ceil(t/2):-Math.ceil(t/2)}}class ss{constructor(){this.bitsArr=[]}bit(t){this.bitsArr.push(t&1)}ue(t){const r=t+1,s=Math.floor(Math.log2(r));for(let a=0;a<s;a++)this.bit(0);for(let a=s;a>=0;a--)this.bit(r>>a&1)}toBytes(){const t=[];for(let r=0;r<this.bitsArr.length;r+=8){let s=0;for(let a=0;a<8;a++)s=s<<1|(this.bitsArr[r+a]??0);t.push(s)}return new Uint8Array(t)}}function un(e){const t=[];let r=0;for(let s=1;s<e.length;s++){const a=e[s];if(r>=2&&a===3){r=0;continue}t.push(a),r=a===0?r+1:0}return new Uint8Array(t)}function os(e){const t=[];let r=0;for(const s of e)r>=2&&s<=3&&(t.push(3),r=0),t.push(s),r=s===0?r+1:0;return new Uint8Array(t)}const as=new Set([100,110,122,244,44,83,86,118,128,138,139,134,135]);function zt(e){const t=e.ue()+1;e.bits(4),e.bits(4);for(let r=0;r<t;r++)e.ue(),e.ue(),e.flag();e.bits(5),e.bits(5),e.bits(5),e.bits(5)}function hn(e){const t=e.bits(8);e.bits(8);const r=e.bits(8);if(e.ue(),as.has(t)){const x=e.ue();if(x===3&&e.flag(),e.ue(),e.ue(),e.flag(),e.flag()){const d=x!==3?8:12;for(let v=0;v<d;v++)if(e.flag()){const S=v<6?16:64;let L=8,k=8;for(let A=0;A<S;A++)k!==0&&(k=(L+e.se()+256)%256),L=k===0?L:k}}}e.ue();const s=e.ue();if(s===0)e.ue();else if(s===1){e.flag(),e.se(),e.se();const x=e.ue();for(let d=0;d<x;d++)e.se()}const a=e.ue();e.flag(),e.ue(),e.ue(),e.flag()||e.flag(),e.flag(),e.flag()&&(e.ue(),e.ue(),e.ue(),e.ue());const i={profileIdc:t,levelIdc:r,numRefFrames:a,bitstreamRestriction:!1,maxNumReorderFrames:null,maxDecFrameBuffering:null};if(!e.flag())return{...i,vuiPresent:!1,restrictionFlagPos:-1};e.flag()&&e.bits(8)===255&&(e.bits(16),e.bits(16)),e.flag()&&e.flag(),e.flag()&&(e.bits(3),e.flag(),e.flag()&&(e.bits(8),e.bits(8),e.bits(8))),e.flag()&&(e.ue(),e.ue()),e.flag()&&(e.bits(32),e.bits(32),e.flag());const f=e.flag();f&&zt(e);const h=e.flag();h&&zt(e),(f||h)&&e.flag(),e.flag();const m=e.position;return e.flag()?(e.flag(),e.ue(),e.ue(),e.ue(),e.ue(),{...i,vuiPresent:!0,bitstreamRestriction:!0,maxNumReorderFrames:e.ue(),maxDecFrameBuffering:e.ue(),restrictionFlagPos:m}):{...i,vuiPresent:!0,restrictionFlagPos:m}}function is(e){const t=hn(new Et(un(e)));return{profileIdc:t.profileIdc,levelIdc:t.levelIdc,vuiPresent:t.vuiPresent,bitstreamRestriction:t.bitstreamRestriction,maxNumReorderFrames:t.maxNumReorderFrames,maxDecFrameBuffering:t.maxDecFrameBuffering}}function cs(e){const t=un(e),r=hn(new Et(t));if(!r.vuiPresent||r.restrictionFlagPos<0||r.bitstreamRestriction)return null;const s=new ss,a=new Et(t);for(let i=0;i<r.restrictionFlagPos;i++)s.bit(a.bit());return s.bit(1),s.bit(1),s.ue(0),s.ue(0),s.ue(0),s.ue(0),s.ue(0),s.ue(r.numRefFrames),s.bit(1),Uint8Array.from([e[0],...os(s.toBytes())])}function ls(e){const t=[],r=e.length;let s=-1,a=0;for(;a+2<r;){const i=a+3<r&&e[a]===0&&e[a+1]===0&&e[a+2]===0&&e[a+3]===1,l=e[a]===0&&e[a+1]===0&&e[a+2]===1;i||l?(s>=0&&t.push(e.subarray(s,a)),a+=i?4:3,s=a):a++}return s>=0&&t.push(e.subarray(s,r)),t}class ds{constructor(t){this.onFrame=t,this.decoder=null,this.sps=null,this.pps=null,this.frameCount=0,this.submitAt=new Map,this.spsLogged=!1}setDecodeSampler(t){this.decodeSampler=t}decode(t){const r=[];let s=!1;for(const m of ls(new Uint8Array(t))){const p=m[0]&31;if(p===7){const x=!this.sps||m.length!==this.sps.length||m.some((d,v)=>d!==this.sps[v]);this.sps=m,x&&this.decoder&&(this.decoder.close(),this.decoder=null)}else p===8?this.pps=m:p>=1&&p<=5&&(p===5&&(s=!0),r.push(m))}if(s&&this.sps&&this.pps&&!this.decoder&&this.initDecoder(this.sps,this.pps),!this.decoder||r.length===0)return;let a=0;for(const m of r)a+=4+m.length;const i=new Uint8Array(a),l=new DataView(i.buffer);let f=0;for(const m of r)l.setUint32(f,m.length,!1),f+=4,i.set(m,f),f+=m.length;const h=Math.round(this.frameCount++*(1e6/30));if(this.decodeSampler&&(this.submitAt.set(h,performance.now()),this.submitAt.size>120)){const m=this.submitAt.keys().next().value;m!==void 0&&this.submitAt.delete(m)}try{this.decoder.decode(new EncodedVideoChunk({type:s?"key":"delta",timestamp:h,data:i}))}catch{}}sampleDecode(t){var s;if(!this.decodeSampler)return;const r=this.submitAt.get(t.timestamp);r!==void 0&&(this.submitAt.delete(t.timestamp),this.decodeSampler({decodeMs:performance.now()-r,queueSize:((s=this.decoder)==null?void 0:s.decodeQueueSize)??0}))}close(){var t;(t=this.decoder)==null||t.close(),this.decoder=null}logSpsVui(t){if(!(this.spsLogged||!this.decodeSampler)){this.spsLogged=!0;try{console.log("[sps-vui]",JSON.stringify(is(t)))}catch(r){console.warn("[sps-vui] parse failed",r)}}}initDecoder(t,r){this.logSpsVui(t);const s=cs(t)??t,a=s[0]===0?s.subarray(4):s,i=`avc1.${a[1].toString(16).padStart(2,"0")}${a[2].toString(16).padStart(2,"0")}${a[3].toString(16).padStart(2,"0")}`,l=this.buildAVCC(s,r);this.decoder=new VideoDecoder({output:f=>{this.sampleDecode(f),this.onFrame(f)},error:f=>console.error("[WebCodecsCore]",f)}),this.decoder.configure({codec:i,description:l,optimizeForLatency:!0})}buildAVCC(t,r){const s=t[0]===0?t.subarray(4):t,a=r[0]===0?r.subarray(4):r,i=new Uint8Array(8+s.length+1+2+a.length);let l=0;return i[l++]=1,i[l++]=s[1],i[l++]=s[2],i[l++]=s[3],i[l++]=255,i[l++]=225,i[l++]=s.length>>8&255,i[l++]=s.length&255,i.set(s,l),l+=s.length,i[l++]=1,i[l++]=a.length>>8&255,i[l++]=a.length&255,i.set(a,l),i}}const us=`#version 300 es
97
- in vec2 a_pos;
98
- out vec2 v_uv;
99
- void main() {
100
- v_uv = vec2(a_pos.x * 0.5 + 0.5, 0.5 - a_pos.y * 0.5);
101
- gl_Position = vec4(a_pos, 0.0, 1.0);
102
- }`,hs=`#version 300 es
103
- precision mediump float;
104
- in vec2 v_uv;
105
- uniform sampler2D u_tex;
106
- out vec4 out_color;
107
- void main() {
108
- out_color = texture(u_tex, v_uv);
109
- }`;function fs(e){const t=e.getContext("webgl2",{alpha:!1,antialias:!1,powerPreference:"high-performance",preserveDrawingBuffer:!0});if(!t)return null;const r=(p,x)=>{const d=t.createShader(p);return t.shaderSource(d,x),t.compileShader(d),d},s=t.createProgram(),a=r(t.VERTEX_SHADER,us),i=r(t.FRAGMENT_SHADER,hs);t.attachShader(s,a),t.attachShader(s,i),t.linkProgram(s),t.deleteShader(a),t.deleteShader(i),t.useProgram(s);const l=t.createVertexArray();t.bindVertexArray(l);const f=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,f),t.bufferData(t.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,-1,1,1,-1,1,1]),t.STATIC_DRAW);const h=t.getAttribLocation(s,"a_pos");t.enableVertexAttribArray(h),t.vertexAttribPointer(h,2,t.FLOAT,!1,0,0),t.bindVertexArray(null);const m=t.createTexture();return t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,m),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.uniform1i(t.getUniformLocation(s,"u_tex"),0),{gl:t,program:s,tex:m,vao:l}}class ps{constructor(t){this.canvas=t,this.state=null}init(){return this.state=fs(this.canvas),this.state!==null}drawFrame(t){const r=this.state;if(!r)return t.close(),null;const s=t.displayWidth,a=t.displayHeight;try{return(this.canvas.width!==s||this.canvas.height!==a)&&(this.canvas.width=s,this.canvas.height=a,r.gl.viewport(0,0,s,a)),r.gl.activeTexture(r.gl.TEXTURE0),r.gl.bindTexture(r.gl.TEXTURE_2D,r.tex),r.gl.texImage2D(r.gl.TEXTURE_2D,0,r.gl.RGBA,r.gl.RGBA,r.gl.UNSIGNED_BYTE,t),r.gl.bindVertexArray(r.vao),r.gl.drawArrays(r.gl.TRIANGLES,0,6),r.gl.bindVertexArray(null),r.gl.bindTexture(r.gl.TEXTURE_2D,null),{width:s,height:a}}finally{t.close()}}dispose(){const t=this.state;t&&(t.gl.deleteTexture(t.tex),t.gl.deleteVertexArray(t.vao),t.gl.deleteProgram(t.program),this.state=null)}}function ms(e){const t=new ps(e);return t.init(),t}class gs{constructor(t=ms){this._size=null,this.canvas=document.createElement("canvas"),this.renderer=t(this.canvas),this.core=new ds(r=>this.render(r))}get surface(){return this.canvas}get size(){return this._size}onResize(t){this.resizeCb=t}onDecodedFrame(t){this.decodedCb=t,this.core.setDecodeSampler(r=>{this.lastSample=r})}decode(t){this.core.decode(t)}close(){this.core.close(),this.renderer.dispose()}render(t){var s,a;const r=this.renderer.drawFrame(t);r&&((s=this.decodedCb)==null||s.call(this,performance.now(),this.lastSample),this.lastSample=void 0,(!this._size||this._size.width!==r.width||this._size.height!==r.height)&&(this._size=r,(a=this.resizeCb)==null||a.call(this,r)))}}const xs=`#version 300 es
110
- in vec2 a_pos;
111
- out vec2 v_uv;
112
- void main() {
113
- v_uv = vec2(a_pos.x * 0.5 + 0.5, 0.5 - a_pos.y * 0.5);
114
- gl_Position = vec4(a_pos, 0.0, 1.0);
115
- }`,bs=`#version 300 es
116
- precision mediump float;
117
- in vec2 v_uv;
118
- uniform sampler2D u_texY;
119
- uniform sampler2D u_texU;
120
- uniform sampler2D u_texV;
121
- out vec4 out_color;
122
- void main() {
123
- float Y = (texture(u_texY, v_uv).r - 0.0627451) * 1.1643836; // (y-16/255)*255/219
124
- float U = (texture(u_texU, v_uv).r - 0.5019608) * 1.1383929; // (u-128/255)*255/224
125
- float V = (texture(u_texV, v_uv).r - 0.5019608) * 1.1383929;
126
- float r = Y + 1.5748 * V;
127
- float g = Y - 0.1873 * U - 0.4681 * V;
128
- float b = Y + 1.8556 * U;
129
- out_color = vec4(r, g, b, 1.0);
130
- }`;function Rt(e,t,r,s){const a=e.createTexture();return e.activeTexture(e.TEXTURE0+t),e.bindTexture(e.TEXTURE_2D,a),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.uniform1i(e.getUniformLocation(s,r),t),a}function ys(e){const t=e.getContext("webgl2",{alpha:!1,antialias:!1,powerPreference:"high-performance",preserveDrawingBuffer:!0});if(!t)return null;const r=(d,v)=>{const S=t.createShader(d);return t.shaderSource(S,v),t.compileShader(S),S},s=t.createProgram(),a=r(t.VERTEX_SHADER,xs),i=r(t.FRAGMENT_SHADER,bs);t.attachShader(s,a),t.attachShader(s,i),t.linkProgram(s),t.deleteShader(a),t.deleteShader(i),t.useProgram(s);const l=t.createVertexArray();t.bindVertexArray(l);const f=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,f),t.bufferData(t.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,-1,1,1,-1,1,1]),t.STATIC_DRAW);const h=t.getAttribLocation(s,"a_pos");t.enableVertexAttribArray(h),t.vertexAttribPointer(h,2,t.FLOAT,!1,0,0),t.bindVertexArray(null),t.pixelStorei(t.UNPACK_ALIGNMENT,1);const m=Rt(t,0,"u_texY",s),p=Rt(t,1,"u_texU",s),x=Rt(t,2,"u_texV",s);return{gl:t,program:s,texY:m,texU:p,texV:x,vao:l}}class vs{constructor(t){this.canvas=t,this.state=null}init(){return this.state=ys(this.canvas),this.state!==null}drawI420(t,r,s){const a=this.state;if(!a)return null;const{gl:i}=a,l=r+1>>1,f=s+1>>1,h=r*s,m=l*f,p=t.subarray(0,h),x=t.subarray(h,h+m),d=t.subarray(h+m,h+2*m);(this.canvas.width!==r||this.canvas.height!==s)&&(this.canvas.width=r,this.canvas.height=s,i.viewport(0,0,r,s));const v=(S,L,k,A,C)=>{i.activeTexture(i.TEXTURE0+S),i.bindTexture(i.TEXTURE_2D,L),i.texImage2D(i.TEXTURE_2D,0,i.R8,k,A,0,i.RED,i.UNSIGNED_BYTE,C)};return v(0,a.texY,r,s,p),v(1,a.texU,l,f,x),v(2,a.texV,l,f,d),i.bindVertexArray(a.vao),i.drawArrays(i.TRIANGLES,0,6),i.bindVertexArray(null),{width:r,height:s}}dispose(){const t=this.state;t&&(t.gl.deleteTexture(t.texY),t.gl.deleteTexture(t.texU),t.gl.deleteTexture(t.texV),t.gl.deleteVertexArray(t.vao),t.gl.deleteProgram(t.program),this.state=null)}}const ws=0;function Ss(e){const t=new vs(e);return t.init(),t}function Rs(){return new Worker(new URL("/assets/tinyh264.worker-DiJ50Hai.js",import.meta.url),{type:"module"})}class js{constructor(t=Ss,r=Rs){this.ready=!1,this.pending=[],this._size=null,this.canvas=document.createElement("canvas"),this.renderer=t(this.canvas),this.worker=r(),this.worker.onmessage=s=>this.onMessage(s.data)}get surface(){return this.canvas}get size(){return this._size}onResize(t){this.resizeCb=t}onDecodedFrame(t){this.decodedCb=t}decode(t){if(!this.ready){this.pending.push(t);return}this.post(t)}close(){this.worker.terminate(),this.renderer.dispose()}post(t){this.worker.postMessage({type:"decode",data:t,offset:0,length:t.byteLength,renderStateId:ws},[t])}onMessage(t){var s,a;if(t.type==="decoderReady"){this.ready=!0;for(const i of this.pending)this.post(i);this.pending.length=0;return}const r=this.renderer.drawI420(new Uint8Array(t.data),t.width,t.height);r&&((s=this.decodedCb)==null||s.call(this,performance.now()),(!this._size||this._size.width!==r.width||this._size.height!==r.height)&&(this._size=r,(a=this.resizeCb)==null||a.call(this,r)))}}function Nt(){const e=typeof window<"u";let t=!1;try{t=!!document.createElement("canvas").getContext("webgl2")}catch{t=!1}return{secureContext:e&&window.isSecureContext===!0,webCodecs:e&&"VideoDecoder"in window,webgl2:t,wasm:typeof WebAssembly<"u"&&typeof Worker<"u"}}function ks(e=Nt()){return e.secureContext&&e.webCodecs&&e.webgl2?new gs:e.wasm&&e.webgl2?new js:null}function Cs(e=Nt()){return e.secureContext&&e.webCodecs&&e.webgl2||e.wasm&&e.webgl2}function Es(e=Nt()){return e.secureContext&&e.webCodecs&&e.webgl2?"high":e.wasm&&e.webgl2?"standard":"unsupported"}const Ot="tapflow.perfModeNoticeDismissed",Ns="https://www.tapflow.dev/reference/configuration#https-secure-context";function _s(e,t){return e==="standard"&&!t}function Ts({open:e,onOpenChange:t}){return n.jsx(nn,{open:e,onOpenChange:t,children:n.jsxs(rn,{className:"sm:max-w-[440px]",children:[n.jsxs(cr,{children:[n.jsx(sn,{children:"Streaming in Standard mode"}),n.jsxs(lr,{className:"space-y-3 pt-1",children:[n.jsx("span",{className:"block",children:"This screen is running in Standard mode. For a faster, smoother picture, switch to High performance."}),n.jsx("span",{className:"block",children:"High performance needs the relay served over HTTPS. If you didn't set up tapflow, ask whoever did."})]})]}),n.jsxs(dr,{children:[n.jsx(ee,{variant:"outline",onClick:()=>window.open(Ns,"_blank","noopener,noreferrer"),children:"How to enable"}),n.jsx(ee,{onClick:()=>t(!1),children:"Got it"})]})]})})}const Ps={high:"High performance",standard:"Standard",unsupported:null};function As(e){const{connected:t,joined:r,bootError:s,deviceReady:a,installing:i,installError:l}=e;return t?r?s?`Boot failed: ${s.length>40?s.slice(0,40)+"…":s}`:a?i?"Installing app…":l?`Install failed: ${l}`:null:"Starting device…":"Joining session…":"Connecting…"}function _t(e){const{joined:t,fps:r,keyboardActive:s}=e,a=As(e),i=r>15,l=r>0&&r<=15,f=i?"#10b981":l?"#94a3b8":"transparent",h=i?"Active":l?"Idle":null,m=o.useMemo(()=>Es(),[]),p=Ps[m],[x,d]=o.useState(!1);o.useEffect(()=>{let S=!1;try{S=localStorage.getItem(Ot)==="1"}catch{}_s(m,S)&&d(!0)},[m]);const v=S=>{if(d(S),!S)try{localStorage.setItem(Ot,"1")}catch{}};return n.jsxs("div",{className:"w-[300px] shrink-0 mt-3 rounded-xl border bg-background px-4 py-4 flex flex-col gap-3",children:[n.jsxs("div",{className:K("flex items-center",s?"text-emerald-500":"text-muted-foreground"),style:{gap:6},children:[n.jsx(Wr,{className:"h-3.5 w-3.5 shrink-0"}),n.jsx("span",{className:"text-[12px] font-medium",children:"Focus"})]}),t&&n.jsxs("div",{className:"flex items-center gap-[12px]",children:[n.jsxs("div",{className:"flex items-center gap-[4px]",children:[n.jsx("span",{className:"h-2 w-2 rounded-full shrink-0 mr-1",style:{background:f}}),n.jsx("span",{className:"text-[12px] font-mono text-foreground/75",children:r}),n.jsx("span",{className:"text-[12px] text-muted-foreground",children:"fps"}),h&&n.jsx("span",{className:"text-[11px] text-muted-foreground/60",children:"·"}),h&&n.jsx("span",{className:K("text-[11px]",i?"text-emerald-500":"text-muted-foreground/60"),children:h})]}),p&&n.jsxs(n.Fragment,{children:[n.jsx(Zt,{orientation:"vertical",className:"h-3"}),m==="standard"?n.jsx("button",{type:"button",onClick:()=>d(!0),className:"text-[11px] text-foreground/70 hover:text-foreground underline-offset-2 hover:underline",children:p}):n.jsx("span",{className:"text-[11px] text-muted-foreground",children:p})]})]}),a&&n.jsx("p",{className:"text-[12px] text-muted-foreground leading-relaxed break-all",children:a}),n.jsx(Ts,{open:x,onOpenChange:v})]})}function fn({open:e,onOpenChange:t,sessionId:r,send:s}){const[a,i]=o.useState(""),l=o.useRef(null);o.useEffect(()=>{e?setTimeout(()=>{var h;return(h=l.current)==null?void 0:h.focus()},0):i("")},[e]);const f=()=>{a.trim()&&(s({type:"open-url",sessionId:r,payload:{url:a.trim()}}),t(!1))};return n.jsx(nn,{open:e,onOpenChange:t,children:n.jsxs(rn,{className:"w-[500px] max-w-[500px] h-[52px] !rounded-[18px] p-[10px] border border-border bg-background shadow-lg overflow-hidden [&>button]:hidden","aria-describedby":void 0,children:[n.jsx(sn,{className:"sr-only",children:"Open Deeplink"}),n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsxs("div",{className:"flex-1 h-[32px] flex items-center gap-2 pl-[4px] pb-[1px]",children:[n.jsx(rr,{className:"h-4 w-4 text-muted-foreground shrink-0"}),n.jsx("input",{ref:l,className:"flex-1 bg-transparent text-sm outline-none placeholder:text-muted-foreground min-w-0",placeholder:"myapp://home...",value:a,onChange:h=>i(h.target.value),onKeyDown:h=>{h.key==="Enter"&&f()}})]}),n.jsx(ee,{size:"sm",disabled:!a.trim(),onClick:f,className:"shrink-0 rounded-xl h-8 px-4",children:"Open"})]})]})})}function Ds(e,t,r,s,a,i){const{x:l,y:f,width:h,height:m}=a;let p,x;if(i){const d=(e.x-t.left)/t.width;p=(1-(e.y-t.top)/t.height)*r,x=d*s}else p=(e.x-t.left)*(r/t.width),x=(e.y-t.top)*(s/t.height);return p<l||p>l+h||x<f||x>f+m?null:{x:(p-l)/h,y:(x-f)/m}}function Ls(e,t,r){const s=(e.x-t.left)/t.width,a=(e.y-t.top)/t.height;return s<0||s>1||a<0||a>1?null:r?{x:a,y:1-s}:{x:s,y:a}}function pn(e){return{f0:{x:1-e.x,y:1-e.y},f1:e}}function Ms(e,t){return e>0?Math.min(1,t/e):1}const mn=22,Wt=[84,70,70,69],Hs=1,Us=0,mt=1,$s=1,Is=2;function Fs(e){if(e.byteLength<mn)return null;const t=new DataView(e);for(let a=0;a<Wt.length;a++)if(t.getUint8(a)!==Wt[a])return null;if(t.getUint8(4)!==Hs)return null;const r=t.getUint8(5),s=r&$s?mt:Us;return{capturedAt:Number(t.getBigUint64(6)),relayedAt:Number(t.getBigUint64(14)),codec:s,keyframe:s===mt&&(r&Is)!==0}}function gn(e){const{binaryFrameHandlerRef:t,perfHookRef:r,frameCount:s}=e,a=o.useRef(e);a.current=e,o.useEffect(()=>{let i=null,l=!1,f=!1,h;const m=()=>{if(i)return i;if(l)return null;const p=ks();return p?(i=p,p.onResize(x=>a.current.onResize(x)),h=a.current.onDecoderReady(p),p):(l=!0,a.current.onUnsupported(),console.warn("[decoder] none available — set up HTTPS or use a supported browser"),null)};return t.current=(p,x)=>{const d=a.current.onJpegFrame;if(d&&(x==null?void 0:x.codec)!==mt){d(p,x);return}const v=m();if(v){if(!f){if(!(x!=null&&x.keyframe))return;f=!0}v.decode(p),s.current+=1}},()=>{t.current=void 0,typeof h=="function"&&h(),i==null||i.close(),i==null||i.surface.remove(),i=null}},[t,r,s])}const Ne=13,Ye=8,Vt=16,Bs=.02,zs=100;function Os({sessionId:e,buildId:t,send:r,connected:s,joined:a,deviceReady:i,installing:l,installed:f,installError:h,bootError:m,launching:p,setLaunching:x,chrome:d,binaryFrameHandlerRef:v,onRecordingUploaded:S,swKeyboardVisible:L,swKeyboardPending:k,onKbdToggle:A,perfHookRef:C}){const T=o.useRef(null),E=o.useRef(null),$=o.useRef(null),{fps:D,frameCount:B}=ln(),X=o.useRef(0),{recordState:I,recordCanvasRef:z,startClientRecording:q,stopClientRecording:je}=cn({sessionId:e,buildId:t,onRecordingUploaded:S}),he=o.useRef(0),[ae,ke]=o.useState(!1),[fe,ie]=o.useState(!1),[N,O]=o.useState(!1),[Z,te]=o.useState(!1),[Ce,M]=o.useState(null),[W,Q]=o.useState(null),[ce,J]=o.useState(!1),[re,ye]=o.useState(null),pe=o.useRef(re);o.useEffect(()=>{pe.current=re},[re]);const le=o.useRef(null),de=o.useRef(null),se=o.useRef(!1),oe=o.useRef(!1),me=o.useRef(0),ne=o.useRef(null),ge=o.useRef(null),Ee=o.useRef("idle"),Te=o.useRef(null),Fe=o.useRef(null),Le=o.useRef(null);o.useEffect(()=>{Le.current=d},[d]),o.useEffect(()=>{const c=new Image;c.onload=()=>{Fe.current=c},c.src=`data:image/png;base64,${d.framePng}`},[d.framePng]),gn({binaryFrameHandlerRef:v,perfHookRef:C,frameCount:B,onUnsupported:()=>{},onResize:c=>{const g=T.current;if(g&&(g.width!==c.width||g.height!==c.height)&&(g.width=c.width,g.height=c.height,!Le.current)){const u=z.current;u&&(u.width=c.width,u.height=c.height)}ie(!0)},onDecoderReady:c=>{var y;const g=c.surface,u=T.current;g.style.position="absolute",u&&(g.style.left=u.style.left,g.style.top=u.style.top,g.style.width=u.style.width,g.style.height=u.style.height,g.style.borderRadius=u.style.borderRadius),g.style.objectFit="fill",g.style.zIndex="3",g.style.pointerEvents="none",(y=E.current)==null||y.appendChild(g);let R=null;const j=()=>{const P=T.current,U=P==null?void 0:P.getContext("2d");if(P&&U&&c.size)try{U.drawImage(c.surface,0,0,P.width,P.height)}catch{}R=requestAnimationFrame(j)};return R=requestAnimationFrame(j),()=>{R!==null&&cancelAnimationFrame(R)}},onJpegFrame:c=>{const g=performance.now();X.current&&g-X.current,X.current=g;const u=he.current;createImageBitmap(new Blob([c],{type:"image/jpeg"})).then(R=>{if(performance.now()-g,he.current!==u){R.close();return}const j=T.current,y=j==null?void 0:j.getContext("2d");if(!j||!y){R.close();return}if((j.width!==R.width||j.height!==R.height)&&(j.width=R.width,j.height=R.height,!Le.current)){const U=z.current;U&&(U.width=R.width,U.height=R.height)}const P=performance.now();y.drawImage(R,0,0),performance.now()-P,R.close(),ie(!0),B.current+=1}).catch(()=>{})}}),o.useEffect(()=>{const c=z.current,g=E.current;c&&g&&(c.width=g.clientWidth,c.height=g.clientHeight)},[d]);const tt=o.useCallback(()=>{const c=z.current,g=T.current;if(!c||!g)return;const u=c.getContext("2d");if(!u)return;const R=Le.current;if(u.clearRect(0,0,c.width,c.height),R){Fe.current&&u.drawImage(Fe.current,0,0,c.width,c.height);const P=Math.round(R.screenCornerRadius/2*(c.height/(R.compositeHeight/2)));u.save(),u.beginPath(),P>0?u.roundRect(g.offsetLeft,g.offsetTop,g.clientWidth,g.clientHeight,P):u.rect(g.offsetLeft,g.offsetTop,g.clientWidth,g.clientHeight),u.clip(),u.drawImage(g,g.offsetLeft,g.offsetTop,g.clientWidth,g.clientHeight),u.restore()}else u.drawImage(g,0,0,c.width,c.height);const j=pe.current;if(j)for(const P of[j.f0,j.f1]){const U=R?g.offsetLeft+P.x*g.clientWidth:P.x*c.width,V=R?g.offsetTop+P.y*g.clientHeight:P.y*c.height;se.current?(u.beginPath(),u.arc(U,V,Ye,0,Math.PI*2),u.fillStyle="rgba(255,255,255,0.92)",u.fill(),u.strokeStyle="rgba(0,0,0,0.2)",u.lineWidth=1,u.stroke()):(u.beginPath(),u.arc(U,V,Ne,0,Math.PI*2),u.strokeStyle="rgba(0,0,0,0.3)",u.lineWidth=3,u.stroke(),u.beginPath(),u.arc(U,V,Ne,0,Math.PI*2),u.strokeStyle="rgba(255,255,255,0.65)",u.lineWidth=1.5,u.stroke())}const y=ge.current;if(y){const P=Ee.current,U=Te.current;if(u.save(),P==="down")u.beginPath(),u.arc(y.x,y.y,Ye,0,Math.PI*2),u.fillStyle="rgba(255,255,255,0.92)",u.fill(),u.strokeStyle="rgba(0,0,0,0.2)",u.lineWidth=1,u.stroke();else if(P==="release"&&U){const V=Math.min((performance.now()-U.startTime)/350,1);u.beginPath(),u.arc(y.x,y.y,Ye+26*V,0,Math.PI*2),u.strokeStyle=`rgba(255,255,255,${(1-V)*.55})`,u.lineWidth=1.5,u.stroke(),V>=1&&(Ee.current="idle",Te.current=null)}else u.beginPath(),u.arc(y.x,y.y,Ne,0,Math.PI*2),u.strokeStyle="rgba(0,0,0,0.3)",u.lineWidth=3,u.stroke(),u.beginPath(),u.arc(y.x,y.y,Ne,0,Math.PI*2),u.strokeStyle="rgba(255,255,255,0.65)",u.lineWidth=1.5,u.stroke();u.restore()}},[]),Be=o.useCallback(()=>{const c=T.current;if(!c)return;const g=document.createElement("canvas"),u=g.getContext("2d");u&&(g.width=c.width,g.height=c.height,u.drawImage(c,0,0),g.toBlob(R=>{if(!R)return;const j=URL.createObjectURL(R),y=document.createElement("a");y.href=j,y.download=`tapflow-${Date.now()}.png`,y.click(),URL.revokeObjectURL(j)},"image/png"))},[]),ve=o.useCallback(()=>{if(I==="idle"){const c=z.current;if(!c)return;const g=E.current;if(g&&g.clientWidth>0)c.width=g.clientWidth,c.height=g.clientHeight;else{const u=T.current;if(u&&u.width>0)c.width=u.width,c.height=u.height;else return}q(tt)}else I==="recording"&&je()},[I,q,je,tt]),Pe=o.useCallback(()=>{r({type:"input:rotate",sessionId:e}),O(c=>!c)},[r,e]),it=o.useRef(N);o.useEffect(()=>{it.current=N},[N]),o.useEffect(()=>()=>{it.current&&r({type:"input:rotate",sessionId:e})},[]),o.useEffect(()=>{const c=new Set(["ShiftLeft","ShiftRight","ControlLeft","ControlRight","MetaLeft","MetaRight"]),g=y=>{if(y.code==="AltLeft"||y.code==="AltRight"){oe.current=!0;return}if(y.metaKey){const U=document.activeElement;if(!U||U.tagName!=="INPUT"&&U.tagName!=="TEXTAREA"){if(!y.shiftKey&&y.code==="KeyK"){y.preventDefault(),ke(!0);return}if(!y.shiftKey&&y.code==="KeyS"){y.preventDefault(),Be();return}if(y.shiftKey&&y.code==="KeyY"){y.preventDefault(),ve();return}if(y.shiftKey&&y.code==="KeyO"){y.preventDefault(),Pe();return}if(y.shiftKey&&y.code==="KeyU"){y.preventDefault(),r({type:"input:button",sessionId:e,payload:{name:"home"}});return}if(y.shiftKey&&y.code==="KeyK"){y.preventDefault(),k||A();return}}}if(!Z||c.has(y.code))return;y.preventDefault();const P=(y.shiftKey?2:0)|(y.ctrlKey?1:0)|(y.metaKey?8:0);r({type:"input:key",sessionId:e,payload:{code:y.code,modifiers:P}})},u=()=>{se.current&&(se.current=!1,J(!1),r({type:"input:pinch:end",sessionId:e})),oe.current=!1,ye(null)},R=y=>{(y.code==="AltLeft"||y.code==="AltRight")&&u()},j=()=>{oe.current&&u()};return window.addEventListener("keydown",g),window.addEventListener("keyup",R),window.addEventListener("blur",j),()=>{window.removeEventListener("keydown",g),window.removeEventListener("keyup",R),window.removeEventListener("blur",j)}},[Z,r,e,Be,ve,Pe,A,k]),o.useEffect(()=>{if(!Z)return;const c=g=>{const u=E.current??T.current;u&&!u.contains(g.target)&&te(!1)};return document.addEventListener("pointerdown",c),()=>document.removeEventListener("pointerdown",c)},[Z]);const Ae=o.useCallback(c=>{const g=(N?$.current:null)??E.current;if(!g)return null;const u=g.getBoundingClientRect(),R=d.compositeWidth/2,j=d.compositeHeight/2,y=d.screenRect.x/2,P=d.screenRect.y/2,U=d.screenRect.width/2,V=d.screenRect.height/2;return Ds({x:c.clientX,y:c.clientY},u,R,j,{x:y,y:P,width:U,height:V},N)},[d,N]),ze=o.useCallback(c=>{const g=Ae(c);return g?pn(g):null},[Ae]),Je=o.useCallback(c=>{const g=N?$.current:E.current;if(!g)return null;const u=g.getBoundingClientRect();let R,j;if(N){const y=u.height-(c.clientY-u.top),P=c.clientX-u.left;R=y*(d.compositeWidth/u.height),j=P*(d.compositeHeight/u.width)}else R=(c.clientX-u.left)*(d.compositeWidth/u.width),j=(c.clientY-u.top)*(d.compositeHeight/u.height);for(const y of d.buttons){const P=R-y.normalOffset.x,U=j-y.normalOffset.y;if(P*P+U*U<zs**2)return y.name}return null},[d,N]),Oe=o.useCallback(c=>{const g=T.current,u=z.current;return g&&g.clientWidth>0?{x:g.offsetLeft+c.x*g.clientWidth,y:g.offsetTop+c.y*g.clientHeight}:{x:c.x*((u==null?void 0:u.width)??1),y:c.y*((u==null?void 0:u.height)??1)}},[]),xe=o.useCallback(c=>{if(te(!0),oe.current){const y=ze(c);if(!y)return;se.current=!0,J(!0),c.target.setPointerCapture(c.pointerId),ye(y),r({type:"input:pinch:start",sessionId:e,payload:y});return}const g=Je(c);if(g){le.current=g,M(g);return}const u=Ae(c);if(!u)return;de.current=u,c.target.setPointerCapture(c.pointerId),ge.current=Oe(u),Ee.current="down",Te.current=null;const R=c.currentTarget.getBoundingClientRect(),j=ne.current;j&&(j.style.display="block",j.style.left=`${c.clientX-R.left}px`,j.style.top=`${c.clientY-R.top}px`,j.style.width=`${Ye*2}px`,j.style.height=`${Ye*2}px`,j.style.background="rgba(255,255,255,0.92)",j.style.border="1.5px solid rgba(0,0,0,0.2)",j.style.boxShadow="0 0 0 1px rgba(0,0,0,0.15), 0 0 8px rgba(255,255,255,0.25)"),r({type:"input:touch:start",sessionId:e,payload:u})},[Je,Ae,ze,Oe,r,e]),ct=o.useCallback(c=>{if(c.buttons===0){if(Q(Je(c)),oe.current){ye(ze(c)),ge.current=null;const P=ne.current;P&&(P.style.display="none")}else{ye(null);const P=Ae(c);ge.current=P?Oe(P):null,Ee.current!=="down"&&(Ee.current="idle");const U=ne.current;if(U)if(P){const V=c.currentTarget.getBoundingClientRect();U.style.display="block",U.style.left=`${c.clientX-V.left}px`,U.style.top=`${c.clientY-V.top}px`,U.style.width=`${Ne*2}px`,U.style.height=`${Ne*2}px`,U.style.background="transparent",U.style.border="1.5px solid rgba(255,255,255,0.6)",U.style.boxShadow="0 0 0 1px rgba(0,0,0,0.3)"}else U.style.display="none"}return}if(se.current){const P=ze(c);if(!P)return;const U=performance.now();if(U-me.current<Vt)return;me.current=U,ye(P),r({type:"input:pinch:move",sessionId:e,payload:P});return}if(le.current||!de.current)return;const g=Ae(c);if(!g)return;const u=g.x-de.current.x,R=g.y-de.current.y;if(Math.sqrt(u*u+R*R)<Bs)return;const j=performance.now();if(j-me.current<Vt)return;me.current=j,ge.current=Oe(g);const y=ne.current;if(y&&y.style.display!=="none"){const P=c.currentTarget.getBoundingClientRect();y.style.left=`${c.clientX-P.left}px`,y.style.top=`${c.clientY-P.top}px`}r({type:"input:touch:move",sessionId:e,payload:g})},[Je,Ae,ze,Oe,r,e]),Me=o.useCallback(()=>{if(se.current){se.current=!1,J(!1),ye(null),r({type:"input:pinch:end",sessionId:e});return}if(de.current=null,le.current){r({type:"input:button",sessionId:e,payload:{name:le.current}}),le.current=null,setTimeout(()=>M(null),100);return}Ee.current="release",Te.current={startTime:performance.now()};const c=ne.current;c&&(c.style.width=`${Ne*2}px`,c.style.height=`${Ne*2}px`,c.style.background="transparent",c.style.border="1.5px solid rgba(255,255,255,0.6)",c.style.boxShadow="0 0 0 1px rgba(0,0,0,0.3)"),r({type:"input:touch:end",sessionId:e})},[r,e]),We=o.useCallback(()=>{if(se.current){se.current=!1,J(!1),ye(null),r({type:"input:pinch:end",sessionId:e});return}if(de.current=null,le.current){le.current=null,M(null);return}Ee.current="release",Te.current={startTime:performance.now()},r({type:"input:touch:end",sessionId:e})},[r,e]),St=o.useCallback(()=>{Q(null),ye(null),ge.current=null;const c=ne.current;c&&(c.style.display="none")},[]),He=d.compositeWidth/2,lt=d.compositeHeight/2,Ze=Ms(lt,750),Ve=Math.round(He*Ze),Xe=Math.round(lt*Ze),Qe=d.screenRect.x/d.compositeWidth*100,b=d.screenRect.y/d.compositeHeight*100,_=d.screenRect.width/d.compositeWidth*100,F=d.screenRect.height/d.compositeHeight*100,w=Math.round(d.screenCornerRadius/2*Ze),Y=n.jsxs(n.Fragment,{children:[n.jsxs(we,{children:[n.jsx(Se,{asChild:!0,children:n.jsx(ee,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>r({type:"input:button",sessionId:e,payload:{name:"home"}}),children:n.jsx(on,{className:"h-4 w-4"})})}),n.jsx(Re,{side:"left",children:n.jsxs("span",{className:"flex items-center gap-3",children:["Home ",n.jsxs(Ct,{children:[n.jsx(Ge,{children:"⌘"}),n.jsx(Ge,{children:"⇧"}),n.jsx(Ge,{children:"U"})]})]})})]}),n.jsxs(we,{children:[n.jsx(Se,{asChild:!0,children:n.jsx(ee,{variant:"ghost",size:"icon",className:"h-8 w-8",disabled:k,onClick:A,"data-active":L,children:k?n.jsx(pt,{className:"h-4 w-4 animate-spin"}):n.jsx(Lr,{className:"h-4 w-4"})})}),n.jsx(Re,{side:"left",children:n.jsxs("span",{className:"flex items-center gap-3",children:["Software keyboard ",n.jsxs(Ct,{children:[n.jsx(Ge,{children:"⌘"}),n.jsx(Ge,{children:"⇧"}),n.jsx(Ge,{children:"K"})]})]})})]})]}),H=f&&t?n.jsxs(we,{children:[n.jsx(Se,{asChild:!0,children:n.jsx(ee,{variant:"ghost",size:"icon",className:"h-8 w-8",disabled:p,onClick:()=>{x(!0),r({type:"app:launch",sessionId:e,buildId:t})},children:p?n.jsx(pt,{className:"h-4 w-4 animate-spin"}):n.jsx(en,{className:"h-4 w-4"})})}),n.jsx(Re,{side:"left",children:p?"Launching…":"Launch app"})]}):null;return n.jsxs("div",{className:"flex items-start justify-center gap-16",children:[n.jsx("canvas",{ref:z,style:{display:"none"}}),n.jsx(fn,{open:ae,onOpenChange:ke,sessionId:e,send:r}),n.jsx(dn,{joined:a,onDeepLink:()=>ke(!0),onScreenshot:Be,onRecordToggle:ve,recordState:I,onRotate:Pe,platformSlot:Y,launchSlot:H}),n.jsxs("div",{className:"flex items-start gap-8",children:[n.jsxs("div",{ref:$,style:{width:N?Xe:Ve,height:N?Ve:Xe,position:"relative",flexShrink:0},children:[n.jsxs("div",{ref:E,className:`relative ${W?"cursor-pointer":"cursor-default"}`,style:{width:Ve,height:Xe,...N?{position:"absolute",top:(Ve-Xe)/2,left:(Xe-Ve)/2,transform:"rotate(-90deg)",transformOrigin:"center center"}:{}},onPointerDown:xe,onPointerMove:ct,onPointerUp:Me,onPointerCancel:We,onPointerLeave:St,children:[n.jsx("img",{src:`data:image/png;base64,${d.framePng}`,style:{position:"absolute",top:0,left:0,zIndex:2,width:"100%",height:"100%",display:"block",pointerEvents:"none",userSelect:"none"},draggable:!1,alt:""}),n.jsx("canvas",{ref:T,style:{position:"absolute",zIndex:3,left:`${Qe}%`,top:`${b}%`,width:`${_}%`,height:`${F}%`,borderRadius:w>0?`${w}px`:void 0,backgroundColor:"#010101",cursor:"none",visibility:fe?"visible":"hidden"}}),!fe&&n.jsx("div",{className:"absolute animate-pulse bg-zinc-700",style:{zIndex:3,left:`${Qe}%`,top:`${b}%`,width:`${_}%`,height:`${F}%`,borderRadius:w>0?`${w}px`:void 0}}),re&&(()=>{const c=Qe/100,g=b/100,u=_/100,R=F/100,j=(y,P)=>({left:`${(c+y*u)*100}%`,top:`${(g+P*R)*100}%`});return n.jsx(n.Fragment,{children:[re.f0,re.f1].map((y,P)=>n.jsx("div",{style:{position:"absolute",zIndex:10,borderRadius:"50%",transform:"translate(-50%, -50%)",pointerEvents:"none",transition:"width 0.1s ease, height 0.1s ease, background 0.1s ease",...ce?{width:Ye*2,height:Ye*2,background:"rgba(255,255,255,0.92)",border:"1.5px solid rgba(0,0,0,0.2)",boxShadow:"0 0 0 1px rgba(0,0,0,0.15), 0 0 8px rgba(255,255,255,0.25)"}:{width:Ne*2,height:Ne*2,background:"transparent",border:"1.5px solid rgba(255,255,255,0.6)",boxShadow:"0 0 0 1px rgba(0,0,0,0.3)"},...j(y.x,y.y)}},P))})})(),a&&D===0&&n.jsx("div",{style:{position:"absolute",zIndex:8,left:`${Qe}%`,top:`${b}%`,width:`${_}%`,height:`${F}%`,display:"flex",alignItems:"center",justifyContent:"center",pointerEvents:"none"},children:n.jsx("span",{style:{color:"white",fontSize:"0.875rem"},children:"Waiting for first frame..."})}),d.buttons.map(c=>{const g=Ce===c.name,u=W===c.name,R=c.anchor==="bottom",j=c.anchor==="top",y=R?(c.normalOffset.y-c.buttonH/2)/d.compositeHeight*100:j?c.rolloverOffset.y/d.compositeHeight*100:(c.normalOffset.y-c.buttonH/2)/d.compositeHeight*100,P=c.buttonH/d.compositeHeight*100,U=c.buttonW/d.compositeWidth*100,V=c.buttonW/2,ue=(c.rolloverOffset.x-V)/d.compositeWidth*100,De=(2*c.rolloverOffset.x-c.normalOffset.x-V)/d.compositeWidth*100,dt=c.rolloverOffset.x/d.compositeWidth*100,nt=R?(c.normalOffset.y-c.buttonH/2)/d.compositeHeight*100:j?c.rolloverOffset.y/d.compositeHeight*100:(c.normalOffset.y-c.buttonH/2)/d.compositeHeight*100,Ut=j?(2*c.rolloverOffset.y-c.normalOffset.y)/d.compositeHeight*100:0,Wn=c.onTop?4:1;return n.jsxs(o.Fragment,{children:[c.buttonPng&&n.jsx("img",{src:`data:image/png;base64,${c.buttonPng}`,style:{position:"absolute",zIndex:Wn,top:`${j&&u?Ut:y}%`,left:`${j?ue:u?De:ue}%`,width:`${U}%`,height:`${P}%`,transition:j?"top 0.15s ease":"left 0.15s ease",pointerEvents:"none",userSelect:"none"},draggable:!1,alt:""}),g&&c.pressedPng&&c.pressedRect&&n.jsx("img",{src:`data:image/png;base64,${c.pressedPng}`,style:{position:"absolute",zIndex:c.onTop?3:1,left:`${j?ue:u?De:ue}%`,top:`${j&&u?Ut:y}%`,width:`${c.pressedRect.width/d.compositeWidth*100}%`,height:`${c.pressedRect.height/d.compositeHeight*100}%`,pointerEvents:"none",userSelect:"none"},draggable:!1,alt:""}),u&&n.jsx("div",{className:"bg-foreground/85 text-background text-[11px] px-[7px] py-1.5 rounded-lg whitespace-nowrap pointer-events-none",style:{position:"absolute",zIndex:5,left:`${dt}%`,top:`${nt}%`,transform:"translate(-50%, calc(-100% - 8px))"},children:c.accessibilityTitle})]},c.name)})]}),n.jsx("div",{ref:ne,style:{display:"none",position:"absolute",zIndex:20,borderRadius:"50%",transform:"translate(-50%, -50%)",pointerEvents:"none",transition:"width 0.1s ease, height 0.1s ease, background 0.1s ease, box-shadow 0.1s ease"}})]}),n.jsx(_t,{joined:a,fps:D,connected:s,deviceReady:i,bootError:m,installing:l,installError:h,keyboardActive:Z})]})]})}const Ke=13,st=8,Xt=16,Ws=.02,jt=720;function Vs({sessionId:e,buildId:t,send:r,connected:s,joined:a,deviceReady:i,installing:l,installed:f,installError:h,bootError:m,launching:p,setLaunching:x,androidButtons:d,binaryFrameHandlerRef:v,onRecordingUploaded:S,screenWidth:L,screenHeight:k,cornerRadius:A,perfHookRef:C}){const T=o.useRef(null),E=o.useRef(null),$=o.useRef(null),{fps:D,frameCount:B}=ln(),{recordState:X,recordCanvasRef:I,startClientRecording:z,stopClientRecording:q}=cn({sessionId:e,buildId:t,onRecordingUploaded:S}),[je,he]=o.useState(!1),[ae,ke]=o.useState(!1),[fe,ie]=o.useState(!1),N=o.useRef(null),[O,Z]=o.useState(null),[te,Ce]=o.useState(!1),[M,W]=o.useState(!1),[Q,ce]=o.useState(!1),[J,re]=o.useState(null),ye=o.useRef(J);o.useEffect(()=>{ye.current=J},[J]);const pe=o.useRef(!1),le=o.useRef(!1),de=o.useRef(null),se=o.useRef(0),oe=o.useRef(null),me=o.useRef(null),ne=o.useRef("idle"),ge=o.useRef(null);gn({binaryFrameHandlerRef:v,perfHookRef:C,frameCount:B,onUnsupported:()=>ie(!0),onResize:b=>{ke(!0);const _=N.current;(!_||_.width!==b.width||_.height!==b.height)&&(N.current=b,Z(b))},onDecoderReady:b=>{var F;$.current=b;const _=b.surface;_.style.display="block",_.style.width="100%",_.style.height="100%",_.style.objectFit="fill",(F=T.current)==null||F.appendChild(_)}});const Ee=o.useCallback(()=>{var U;const b=I.current,_=(U=$.current)==null?void 0:U.surface,F=N.current;if(!b||!_||!F)return;const w=b.getContext("2d");if(!w)return;const Y=F.width,H=F.height,c=b.width>b.height!=Y>H;w.save(),c&&(w.translate(b.width,0),w.rotate(Math.PI/2)),w.drawImage(_,0,0,Y,H);const g=Math.max(Y,H),u=g>jt?g/jt:1,R=Ke*u,j=st*u,y=ye.current;if(y)for(const V of[y.f0,y.f1]){const ue=V.x*Y,De=V.y*H;pe.current?(w.beginPath(),w.arc(ue,De,j,0,Math.PI*2),w.fillStyle="rgba(255,255,255,0.92)",w.fill(),w.strokeStyle="rgba(0,0,0,0.2)",w.lineWidth=u,w.stroke()):(w.beginPath(),w.arc(ue,De,R,0,Math.PI*2),w.strokeStyle="rgba(0,0,0,0.3)",w.lineWidth=3*u,w.stroke(),w.beginPath(),w.arc(ue,De,R,0,Math.PI*2),w.strokeStyle="rgba(255,255,255,0.65)",w.lineWidth=1.5*u,w.stroke())}const P=me.current;if(P){const V=P.x*Y,ue=P.y*H,De=ne.current,dt=ge.current;if(De==="down")w.beginPath(),w.arc(V,ue,j,0,Math.PI*2),w.fillStyle="rgba(255,255,255,0.92)",w.fill(),w.strokeStyle="rgba(0,0,0,0.2)",w.lineWidth=u,w.stroke();else if(De==="release"&&dt){const nt=Math.min((performance.now()-dt.startTime)/350,1);w.beginPath(),w.arc(V,ue,j+26*u*nt,0,Math.PI*2),w.strokeStyle=`rgba(255,255,255,${(1-nt)*.55})`,w.lineWidth=1.5*u,w.stroke(),nt>=1&&(ne.current="idle",ge.current=null)}else w.beginPath(),w.arc(V,ue,R,0,Math.PI*2),w.strokeStyle="rgba(0,0,0,0.3)",w.lineWidth=3*u,w.stroke(),w.beginPath(),w.arc(V,ue,R,0,Math.PI*2),w.strokeStyle="rgba(255,255,255,0.65)",w.lineWidth=1.5*u,w.stroke()}w.restore()},[]),Te=o.useCallback(()=>{var Y;const b=(Y=$.current)==null?void 0:Y.surface,_=N.current;if(!b||!_)return;const F=document.createElement("canvas"),w=F.getContext("2d");w&&(F.width=_.width,F.height=_.height,w.drawImage(b,0,0,_.width,_.height),F.toBlob(H=>{if(!H)return;const c=URL.createObjectURL(H),g=document.createElement("a");g.href=c,g.download=`tapflow-${Date.now()}.png`,g.click(),URL.revokeObjectURL(c)},"image/png"))},[]),Fe=o.useCallback(()=>{if(X==="idle"){const b=I.current;if(!b)return;const _=N.current;if(!_)return;const F=Be.current;b.width=F?_.height:_.width,b.height=F?_.width:_.height,z(Ee)}else X==="recording"&&q()},[X,z,q,Ee]),Le=o.useCallback(()=>{r({type:"input:rotate",sessionId:e}),Ce(b=>!b)},[r,e]),tt=o.useRef(te);o.useEffect(()=>{tt.current=te},[te]),o.useEffect(()=>()=>{tt.current&&r({type:"input:rotate",sessionId:e})},[]),o.useEffect(()=>{const b=new Set(["ShiftLeft","ShiftRight","ControlLeft","ControlRight","MetaLeft","MetaRight"]),_=H=>{if(H.code==="AltLeft"||H.code==="AltRight"){le.current=!0;return}if(H.metaKey){const g=document.activeElement;if(!g||g.tagName!=="INPUT"&&g.tagName!=="TEXTAREA"){if(!H.shiftKey&&H.code==="KeyK"){H.preventDefault(),he(!0);return}if(!H.shiftKey&&H.code==="KeyS"){H.preventDefault(),Te();return}if(H.shiftKey&&H.code==="KeyY"){H.preventDefault(),Fe();return}if(H.shiftKey&&H.code==="KeyO"){H.preventDefault(),Le();return}}}if(!M||b.has(H.code))return;H.preventDefault();const c=(H.shiftKey?2:0)|(H.ctrlKey?1:0)|(H.metaKey?8:0);r({type:"input:key",sessionId:e,payload:{code:H.code,modifiers:c}})},F=()=>{pe.current&&(pe.current=!1,ce(!1),r({type:"input:pinch:end",sessionId:e})),le.current=!1,re(null)},w=H=>{(H.code==="AltLeft"||H.code==="AltRight")&&F()},Y=()=>{le.current&&F()};return window.addEventListener("keydown",_),window.addEventListener("keyup",w),window.addEventListener("blur",Y),()=>{window.removeEventListener("keydown",_),window.removeEventListener("keyup",w),window.removeEventListener("blur",Y)}},[M,r,e,Te,Fe,Le]),o.useEffect(()=>{if(!M)return;const b=_=>{const F=E.current??T.current;F&&!F.contains(_.target)&&W(!1)};return document.addEventListener("pointerdown",b),()=>document.removeEventListener("pointerdown",b)},[M]);const Be=o.useRef(!1),ve=o.useCallback(b=>{const _=T.current;if(!_)return null;const F=_.getBoundingClientRect();return Ls({x:b.clientX,y:b.clientY},F,Be.current)},[]),Pe=o.useCallback(b=>{const _=ve(b);return _?pn(_):null},[ve]),it=o.useCallback(b=>{if(le.current){const Y=Pe(b);if(!Y)return;pe.current=!0,ce(!0),b.target.setPointerCapture(b.pointerId);const H=oe.current;H&&(H.style.display="none"),re(Y),r({type:"input:pinch:start",sessionId:e,payload:Y});return}const _=ve(b);if(!_)return;W(!0),de.current=_,b.target.setPointerCapture(b.pointerId);const F=b.currentTarget.getBoundingClientRect();me.current=_,ne.current="down",ge.current=null;const w=oe.current;w&&(w.style.display="block",w.style.left=`${b.clientX-F.left}px`,w.style.top=`${b.clientY-F.top}px`,w.style.width=`${st*2}px`,w.style.height=`${st*2}px`,w.style.background="rgba(255,255,255,0.92)",w.style.border="1.5px solid rgba(0,0,0,0.2)",w.style.boxShadow="0 0 0 1px rgba(0,0,0,0.15), 0 0 8px rgba(255,255,255,0.25)"),r({type:"input:touch:start",sessionId:e,payload:_})},[ve,Pe,r,e]),Ae=o.useCallback(b=>{if(b.buttons===0){if(le.current){re(Pe(b)),me.current=null;const j=oe.current;j&&(j.style.display="none");return}const g=ve(b),u=b.currentTarget.getBoundingClientRect(),R=oe.current;g?(me.current=g,ne.current!=="down"&&(ne.current="idle"),R&&(R.style.display="block",R.style.left=`${b.clientX-u.left}px`,R.style.top=`${b.clientY-u.top}px`,R.style.width=`${Ke*2}px`,R.style.height=`${Ke*2}px`,R.style.background="transparent",R.style.border="1.5px solid rgba(255,255,255,0.6)",R.style.boxShadow="0 0 0 1px rgba(0,0,0,0.3)")):(me.current=null,R&&(R.style.display="none"));return}if(pe.current){const g=Pe(b);if(!g)return;const u=performance.now();if(u-se.current<Xt)return;se.current=u,re(g),r({type:"input:pinch:move",sessionId:e,payload:g});return}if(!de.current)return;const _=ve(b);if(!_)return;const F=_.x-de.current.x,w=_.y-de.current.y;if(Math.sqrt(F*F+w*w)<Ws)return;const Y=performance.now();if(Y-se.current<Xt)return;se.current=Y;const H=b.currentTarget.getBoundingClientRect();me.current=_;const c=oe.current;c&&c.style.display!=="none"&&(c.style.left=`${b.clientX-H.left}px`,c.style.top=`${b.clientY-H.top}px`),r({type:"input:touch:move",sessionId:e,payload:_})},[ve,Pe,r,e]),ze=o.useCallback(()=>{if(pe.current){pe.current=!1,ce(!1),re(null),r({type:"input:pinch:end",sessionId:e});return}de.current=null,ne.current="release",ge.current={startTime:performance.now()};const b=oe.current;b&&(b.style.width=`${Ke*2}px`,b.style.height=`${Ke*2}px`,b.style.background="transparent",b.style.border="1.5px solid rgba(255,255,255,0.6)",b.style.boxShadow="0 0 0 1px rgba(0,0,0,0.3)"),r({type:"input:touch:end",sessionId:e})},[r,e]),Je=o.useCallback(()=>{if(pe.current){pe.current=!1,ce(!1),re(null),r({type:"input:pinch:end",sessionId:e});return}de.current=null,ne.current="release",ge.current={startTime:performance.now()},r({type:"input:touch:end",sessionId:e})},[r,e]),Oe=o.useCallback(()=>{re(null),me.current=null;const b=oe.current;b&&(b.style.display="none")},[]),xe=O??(L&&k?{width:L,height:k}:null),ct=xe?Math.min(1,jt/Math.max(xe.width,xe.height)):.3,Me=xe?Math.round(xe.width*ct):324,We=xe?Math.round(xe.height*ct):720,St=xe?xe.width>xe.height:!1,He=te&&!St;o.useLayoutEffect(()=>{Be.current=He},[He]);const lt=He?We:Me,Ht=He?Me:We,Ze=A!=null?Math.round(A*Me):22,Ve=He?{position:"absolute",width:Me,height:We,top:(Me-We)/2,left:(We-Me)/2,transform:"rotate(90deg)",transformOrigin:"center center",visibility:ae?"visible":"hidden",cursor:"none"}:{visibility:ae?"visible":"hidden",cursor:"none"},Xe=n.jsx(n.Fragment,{children:d==null?void 0:d.map(b=>n.jsxs(we,{children:[n.jsx(Se,{asChild:!0,children:n.jsx(ee,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>r({type:"input:button",sessionId:e,payload:{name:b.name}}),children:b.name==="back"?n.jsx(yr,{className:"h-4 w-4"}):b.name==="recent_apps"?n.jsx(Vn,{className:"h-4 w-4"}):b.name==="volume_up"?n.jsx(qr,{className:"h-4 w-4"}):b.name==="volume_down"?n.jsx(Zr,{className:"h-4 w-4"}):b.name==="power"?n.jsx(Fr,{className:"h-4 w-4"}):n.jsx(on,{className:"h-4 w-4"})})}),n.jsx(Re,{side:"left",children:b.accessibilityTitle})]},b.name))}),Qe=f&&t?n.jsxs(we,{children:[n.jsx(Se,{asChild:!0,children:n.jsx(ee,{variant:"ghost",size:"icon",className:"h-8 w-8",disabled:p||l,onClick:()=>{x(!0),r({type:"app:launch",sessionId:e,buildId:t})},children:p?n.jsx(pt,{className:"h-4 w-4 animate-spin"}):n.jsx(en,{className:"h-4 w-4"})})}),n.jsx(Re,{side:"left",children:p?"Launching…":l?"Installing…":"Launch app"})]}):null;return n.jsxs("div",{className:"flex items-start justify-center gap-16",children:[n.jsx("canvas",{ref:I,style:{display:"none"}}),n.jsx(fn,{open:je,onOpenChange:he,sessionId:e,send:r}),n.jsx(dn,{joined:a,onDeepLink:()=>he(!0),onScreenshot:Te,onRecordToggle:Fe,recordState:X,onRotate:Le,platformSlot:Xe,launchSlot:Qe}),n.jsxs("div",{className:"flex items-start gap-8",children:[n.jsx("div",{style:{background:"#1c1c1e",borderRadius:`${Ze+12}px`,padding:"12px",flexShrink:0,boxShadow:"0 8px 32px rgba(0,0,0,0.45), inset 0 1px 0 rgba(255,255,255,0.06)"},children:n.jsx("div",{ref:E,className:"relative",style:{width:lt,height:Ht,backgroundColor:"#010101",borderRadius:`${Ze}px`,overflow:"hidden"},children:fe?n.jsx("div",{className:"absolute inset-0 flex items-center justify-center p-4 text-center",children:n.jsxs("span",{style:{color:"rgba(255,255,255,0.6)",fontSize:"0.875rem"},children:["이 환경에서는 스트리밍을 표시할 수 없습니다.",n.jsx("br",{}),"Chrome/Edge 또는 HTTPS 환경에서 다시 시도해 주세요."]})}):n.jsxs(n.Fragment,{children:[n.jsx("div",{ref:T,className:He?void 0:"block w-full h-full",style:Ve,onPointerDown:it,onPointerMove:Ae,onPointerUp:ze,onPointerCancel:Je,onPointerLeave:Oe}),!ae&&n.jsx("div",{className:"absolute inset-0 animate-pulse bg-zinc-700"}),!ae&&i&&n.jsx("div",{className:"absolute inset-0 flex items-center justify-center pointer-events-none",children:n.jsx("span",{style:{color:"rgba(255,255,255,0.6)",fontSize:"0.875rem"},children:"Waiting for stream…"})}),n.jsx("div",{ref:oe,style:{display:"none",position:"absolute",zIndex:20,borderRadius:"50%",transform:"translate(-50%, -50%)",pointerEvents:"none",transition:"width 0.1s ease, height 0.1s ease, background 0.1s ease, box-shadow 0.1s ease"}}),J&&n.jsx(n.Fragment,{children:[J.f0,J.f1].map((b,_)=>n.jsx("div",{style:{position:"absolute",zIndex:10,borderRadius:"50%",transform:"translate(-50%, -50%)",pointerEvents:"none",transition:"width 0.1s ease, height 0.1s ease, background 0.1s ease",left:`${b.x*100}%`,top:`${b.y*100}%`,...Q?{width:st*2,height:st*2,background:"rgba(255,255,255,0.92)",border:"1.5px solid rgba(0,0,0,0.2)",boxShadow:"0 0 0 1px rgba(0,0,0,0.15), 0 0 8px rgba(255,255,255,0.25)"}:{width:Ke*2,height:Ke*2,background:"transparent",border:"1.5px solid rgba(255,255,255,0.6)",boxShadow:"0 0 0 1px rgba(0,0,0,0.3)"}}},_))})]})})}),n.jsx(_t,{joined:a,fps:D,connected:s,deviceReady:i,bootError:m,installing:l,installError:h,keyboardActive:M})]})]})}function Xs({sessionId:e,deviceId:t,buildId:r,resetMode:s,onRecordingUploaded:a}){const i=o.useRef(()=>{});ns();const l=o.useRef(null),f=o.useRef(null),h=o.useRef([]);o.useRef({onFrameBegin:()=>{var M;return(M=l.current)==null?void 0:M.onFrameBegin()},onFrameEnd:M=>{var ce,J;const W=h.current.shift()??null,Q=W?{...M,capturedAt:W.capturedAt,relayedAt:W.relayedAt}:M;(ce=l.current)==null||ce.onFrameEnd(Q),(J=f.current)==null||J.call(f,Q)}});const[m,p]=o.useState(!1),[x,d]=o.useState(!1),[v,S]=o.useState(null),[L,k]=o.useState(!1),[A,C]=o.useState(!1),[T,E]=o.useState(null),[$,D]=o.useState(null),[B,X]=o.useState(!1),[I,z]=o.useState(!1),[q,je]=o.useState(!1),he=o.useRef(void 0),ae=o.useCallback(M=>{if(M.type==="session:joined"&&(p(!0),i.current({type:"device:boot",sessionId:e,payload:{deviceId:t,resetMode:s,acceptH264:Cs(),secureContext:window.isSecureContext}})),M.type==="device:boot-error"&&D(M.message),M.type==="device:booting"&&(d(!1),k(!1),C(!1),E(null),D(null),S(null)),M.type==="device:ready"&&(d(!0),r&&(k(!0),i.current({type:"app:install",sessionId:e,buildId:r}))),M.type==="app:install-done"&&(k(!1),C(!0)),M.type==="app:install-error"&&(k(!1),E(M.message)),M.type==="app:launch-done"&&X(!1),M.type==="app:launch-error"&&X(!1),M.type==="session:chrome"&&S(M.payload),M.type==="keyboard:toggled"){const{visible:W}=M.payload;z(W),je(!1)}M.type==="open-url:done"&&at.success("Deeplink opened"),M.type==="open-url:error"&&at.error(M.message),M.type==="error"&&M.message==="Agent resources exhausted"&&at.error("Could not start session — this Mac is currently overloaded.",{description:"Go back and select a different Mac."})},[e,t,r]),ke=o.useCallback(M=>{var J;const W=Fs(M);W&&W.codec===mt||h.current.push(W);const Q=W?M.slice(mn):M,ce=W?{codec:W.codec,keyframe:W.keyframe,capturedAt:W.capturedAt,relayedAt:W.relayedAt}:void 0;(J=he.current)==null||J.call(he,Q,ce)},[]),{send:fe,connected:ie}=tn(ae,ke);o.useLayoutEffect(()=>{i.current=fe}),o.useEffect(()=>{ie&&fe({type:"session:start",sessionId:e})},[ie,fe,e]);const N=v!==null&&"framePng"in v?v:null,O=v!==null&&!("framePng"in v)?v:null,te={sessionId:e,buildId:r,send:fe,connected:ie,joined:m,deviceReady:x,installing:L,installed:A,installError:T,bootError:$,launching:B,setLaunching:X,binaryFrameHandlerRef:he,onRecordingUploaded:a,swKeyboardVisible:I,swKeyboardPending:q,onKbdToggle:()=>{je(!0),fe({type:"input:keyboard:toggle",sessionId:e})}};if(!N&&!O)return n.jsxs("div",{className:"flex items-start justify-center gap-16",children:[n.jsx("div",{className:"flex flex-col items-center gap-0.5 rounded-2xl border bg-background/90 px-1.5 py-2.5 shrink-0 mt-3 opacity-40",children:Array.from({length:5}).map((M,W)=>n.jsx("div",{className:"h-8 w-8 rounded-md bg-muted animate-pulse"},W))}),n.jsxs("div",{className:"flex items-start gap-8",children:[n.jsx("div",{style:{background:"#1c1c1e",borderRadius:"34px",padding:"12px",flexShrink:0},children:n.jsx("div",{className:"animate-pulse bg-zinc-700",style:{width:324,height:720,borderRadius:"22px"}})}),n.jsx(_t,{joined:m,fps:0,connected:ie,deviceReady:x,bootError:$,installing:L,installError:T,keyboardActive:!1})]})]});const Ce=void 0;return n.jsxs(n.Fragment,{children:[N&&n.jsx(Os,{...te,chrome:N,perfHookRef:Ce}),O&&n.jsx(Vs,{...te,androidButtons:O.buttons,screenWidth:O.screenWidth,screenHeight:O.screenHeight,cornerRadius:O.cornerRadius,perfHookRef:Ce}),!1]})}const xn=o.forwardRef(({className:e,...t},r)=>n.jsx("textarea",{className:K("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",e),ref:r,...t}));xn.displayName="Textarea";function Ys(e,t){return o.useReducer((r,s)=>t[r][s]??r,e)}var Tt="ScrollArea",[bn]=Qt(Tt),[Ks,be]=bn(Tt),yn=o.forwardRef((e,t)=>{const{__scopeScrollArea:r,type:s="hover",dir:a,scrollHideDelay:i=600,...l}=e,[f,h]=o.useState(null),[m,p]=o.useState(null),[x,d]=o.useState(null),[v,S]=o.useState(null),[L,k]=o.useState(null),[A,C]=o.useState(0),[T,E]=o.useState(0),[$,D]=o.useState(!1),[B,X]=o.useState(!1),I=$e(t,q=>h(q)),z=Xn(a);return n.jsx(Ks,{scope:r,type:s,dir:z,scrollHideDelay:i,scrollArea:f,viewport:m,onViewportChange:p,content:x,onContentChange:d,scrollbarX:v,onScrollbarXChange:S,scrollbarXEnabled:$,onScrollbarXEnabledChange:D,scrollbarY:L,onScrollbarYChange:k,scrollbarYEnabled:B,onScrollbarYEnabledChange:X,onCornerWidthChange:C,onCornerHeightChange:E,children:n.jsx(Ie.div,{dir:z,...l,ref:I,style:{position:"relative","--radix-scroll-area-corner-width":A+"px","--radix-scroll-area-corner-height":T+"px",...e.style}})})});yn.displayName=Tt;var vn="ScrollAreaViewport",wn=o.forwardRef((e,t)=>{const{__scopeScrollArea:r,children:s,nonce:a,...i}=e,l=be(vn,r),f=o.useRef(null),h=$e(t,f,l.onViewportChange);return n.jsxs(n.Fragment,{children:[n.jsx(Gs,{nonce:a}),n.jsx(Ie.div,{"data-radix-scroll-area-viewport":"",...i,ref:h,style:{overflowX:l.scrollbarXEnabled?"scroll":"hidden",overflowY:l.scrollbarYEnabled?"scroll":"hidden",...e.style},children:n.jsx("div",{ref:l.onContentChange,style:{minWidth:"100%",display:"table"},children:s})})]})});wn.displayName=vn;var Gs=o.memo(({nonce:e})=>n.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-scroll-area-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-scroll-area-viewport]::-webkit-scrollbar{display:none}"},nonce:e}),(e,t)=>e.nonce===t.nonce),_e="ScrollAreaScrollbar",Pt=o.forwardRef((e,t)=>{const{forceMount:r,...s}=e,a=be(_e,e.__scopeScrollArea),{onScrollbarXEnabledChange:i,onScrollbarYEnabledChange:l}=a,f=e.orientation==="horizontal";return o.useEffect(()=>(f?i(!0):l(!0),()=>{f?i(!1):l(!1)}),[f,i,l]),a.type==="hover"?n.jsx(qs,{...s,ref:t,forceMount:r}):a.type==="scroll"?n.jsx(Js,{...s,ref:t,forceMount:r}):a.type==="auto"?n.jsx(Sn,{...s,ref:t,forceMount:r}):a.type==="always"?n.jsx(At,{...s,ref:t,"data-state":"visible"}):null});Pt.displayName=_e;var qs=o.forwardRef((e,t)=>{const{forceMount:r,...s}=e,a=be(_e,e.__scopeScrollArea),[i,l]=o.useState(!1);return o.useEffect(()=>{const f=a.scrollArea;let h=0;if(f){const m=()=>{window.clearTimeout(h),l(!0)},p=()=>{h=window.setTimeout(()=>l(!1),a.scrollHideDelay)};return f.addEventListener("pointerenter",m),f.addEventListener("pointerleave",p),()=>{window.clearTimeout(h),f.removeEventListener("pointerenter",m),f.removeEventListener("pointerleave",p)}}},[a.scrollArea,a.scrollHideDelay]),n.jsx(bt,{present:r||i,children:n.jsx(Sn,{"data-state":i?"visible":"hidden",...s,ref:t})})}),Js=o.forwardRef((e,t)=>{const{forceMount:r,...s}=e,a=be(_e,e.__scopeScrollArea),i=e.orientation==="horizontal",l=vt(()=>h("SCROLL_END"),100),[f,h]=Ys("hidden",{hidden:{SCROLL:"scrolling"},scrolling:{SCROLL_END:"idle",POINTER_ENTER:"interacting"},interacting:{SCROLL:"interacting",POINTER_LEAVE:"idle"},idle:{HIDE:"hidden",SCROLL:"scrolling",POINTER_ENTER:"interacting"}});return o.useEffect(()=>{if(f==="idle"){const m=window.setTimeout(()=>h("HIDE"),a.scrollHideDelay);return()=>window.clearTimeout(m)}},[f,a.scrollHideDelay,h]),o.useEffect(()=>{const m=a.viewport,p=i?"scrollLeft":"scrollTop";if(m){let x=m[p];const d=()=>{const v=m[p];x!==v&&(h("SCROLL"),l()),x=v};return m.addEventListener("scroll",d),()=>m.removeEventListener("scroll",d)}},[a.viewport,i,h,l]),n.jsx(bt,{present:r||f!=="hidden",children:n.jsx(At,{"data-state":f==="hidden"?"hidden":"visible",...s,ref:t,onPointerEnter:Ue(e.onPointerEnter,()=>h("POINTER_ENTER")),onPointerLeave:Ue(e.onPointerLeave,()=>h("POINTER_LEAVE"))})})}),Sn=o.forwardRef((e,t)=>{const r=be(_e,e.__scopeScrollArea),{forceMount:s,...a}=e,[i,l]=o.useState(!1),f=e.orientation==="horizontal",h=vt(()=>{if(r.viewport){const m=r.viewport.offsetWidth<r.viewport.scrollWidth,p=r.viewport.offsetHeight<r.viewport.scrollHeight;l(f?m:p)}},10);return et(r.viewport,h),et(r.content,h),n.jsx(bt,{present:s||i,children:n.jsx(At,{"data-state":i?"visible":"hidden",...a,ref:t})})}),At=o.forwardRef((e,t)=>{const{orientation:r="vertical",...s}=e,a=be(_e,e.__scopeScrollArea),i=o.useRef(null),l=o.useRef(0),[f,h]=o.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),m=En(f.viewport,f.content),p={...s,sizes:f,onSizesChange:h,hasThumb:m>0&&m<1,onThumbChange:d=>i.current=d,onThumbPointerUp:()=>l.current=0,onThumbPointerDown:d=>l.current=d};function x(d,v){return ro(d,l.current,f,v)}return r==="horizontal"?n.jsx(Zs,{...p,ref:t,onThumbPositionChange:()=>{if(a.viewport&&i.current){const d=a.viewport.scrollLeft,v=Yt(d,f,a.dir);i.current.style.transform=`translate3d(${v}px, 0, 0)`}},onWheelScroll:d=>{a.viewport&&(a.viewport.scrollLeft=d)},onDragScroll:d=>{a.viewport&&(a.viewport.scrollLeft=x(d,a.dir))}}):r==="vertical"?n.jsx(Qs,{...p,ref:t,onThumbPositionChange:()=>{if(a.viewport&&i.current){const d=a.viewport.scrollTop,v=Yt(d,f);i.current.style.transform=`translate3d(0, ${v}px, 0)`}},onWheelScroll:d=>{a.viewport&&(a.viewport.scrollTop=d)},onDragScroll:d=>{a.viewport&&(a.viewport.scrollTop=x(d))}}):null}),Zs=o.forwardRef((e,t)=>{const{sizes:r,onSizesChange:s,...a}=e,i=be(_e,e.__scopeScrollArea),[l,f]=o.useState(),h=o.useRef(null),m=$e(t,h,i.onScrollbarXChange);return o.useEffect(()=>{h.current&&f(getComputedStyle(h.current))},[h]),n.jsx(jn,{"data-orientation":"horizontal",...a,ref:m,sizes:r,style:{bottom:0,left:i.dir==="rtl"?"var(--radix-scroll-area-corner-width)":0,right:i.dir==="ltr"?"var(--radix-scroll-area-corner-width)":0,"--radix-scroll-area-thumb-width":yt(r)+"px",...e.style},onThumbPointerDown:p=>e.onThumbPointerDown(p.x),onDragScroll:p=>e.onDragScroll(p.x),onWheelScroll:(p,x)=>{if(i.viewport){const d=i.viewport.scrollLeft+p.deltaX;e.onWheelScroll(d),_n(d,x)&&p.preventDefault()}},onResize:()=>{h.current&&i.viewport&&l&&s({content:i.viewport.scrollWidth,viewport:i.viewport.offsetWidth,scrollbar:{size:h.current.clientWidth,paddingStart:xt(l.paddingLeft),paddingEnd:xt(l.paddingRight)}})}})}),Qs=o.forwardRef((e,t)=>{const{sizes:r,onSizesChange:s,...a}=e,i=be(_e,e.__scopeScrollArea),[l,f]=o.useState(),h=o.useRef(null),m=$e(t,h,i.onScrollbarYChange);return o.useEffect(()=>{h.current&&f(getComputedStyle(h.current))},[h]),n.jsx(jn,{"data-orientation":"vertical",...a,ref:m,sizes:r,style:{top:0,right:i.dir==="ltr"?0:void 0,left:i.dir==="rtl"?0:void 0,bottom:"var(--radix-scroll-area-corner-height)","--radix-scroll-area-thumb-height":yt(r)+"px",...e.style},onThumbPointerDown:p=>e.onThumbPointerDown(p.y),onDragScroll:p=>e.onDragScroll(p.y),onWheelScroll:(p,x)=>{if(i.viewport){const d=i.viewport.scrollTop+p.deltaY;e.onWheelScroll(d),_n(d,x)&&p.preventDefault()}},onResize:()=>{h.current&&i.viewport&&l&&s({content:i.viewport.scrollHeight,viewport:i.viewport.offsetHeight,scrollbar:{size:h.current.clientHeight,paddingStart:xt(l.paddingTop),paddingEnd:xt(l.paddingBottom)}})}})}),[eo,Rn]=bn(_e),jn=o.forwardRef((e,t)=>{const{__scopeScrollArea:r,sizes:s,hasThumb:a,onThumbChange:i,onThumbPointerUp:l,onThumbPointerDown:f,onThumbPositionChange:h,onDragScroll:m,onWheelScroll:p,onResize:x,...d}=e,v=be(_e,r),[S,L]=o.useState(null),k=$e(t,I=>L(I)),A=o.useRef(null),C=o.useRef(""),T=v.viewport,E=s.content-s.viewport,$=qe(p),D=qe(h),B=vt(x,10);function X(I){if(A.current){const z=I.clientX-A.current.left,q=I.clientY-A.current.top;m({x:z,y:q})}}return o.useEffect(()=>{const I=z=>{const q=z.target;(S==null?void 0:S.contains(q))&&$(z,E)};return document.addEventListener("wheel",I,{passive:!1}),()=>document.removeEventListener("wheel",I,{passive:!1})},[T,S,E,$]),o.useEffect(D,[s,D]),et(S,B),et(v.content,B),n.jsx(eo,{scope:r,scrollbar:S,hasThumb:a,onThumbChange:qe(i),onThumbPointerUp:qe(l),onThumbPositionChange:D,onThumbPointerDown:qe(f),children:n.jsx(Ie.div,{...d,ref:k,style:{position:"absolute",...d.style},onPointerDown:Ue(e.onPointerDown,I=>{I.button===0&&(I.target.setPointerCapture(I.pointerId),A.current=S.getBoundingClientRect(),C.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",v.viewport&&(v.viewport.style.scrollBehavior="auto"),X(I))}),onPointerMove:Ue(e.onPointerMove,X),onPointerUp:Ue(e.onPointerUp,I=>{const z=I.target;z.hasPointerCapture(I.pointerId)&&z.releasePointerCapture(I.pointerId),document.body.style.webkitUserSelect=C.current,v.viewport&&(v.viewport.style.scrollBehavior=""),A.current=null})})})}),gt="ScrollAreaThumb",kn=o.forwardRef((e,t)=>{const{forceMount:r,...s}=e,a=Rn(gt,e.__scopeScrollArea);return n.jsx(bt,{present:r||a.hasThumb,children:n.jsx(to,{ref:t,...s})})}),to=o.forwardRef((e,t)=>{const{__scopeScrollArea:r,style:s,...a}=e,i=be(gt,r),l=Rn(gt,r),{onThumbPositionChange:f}=l,h=$e(t,x=>l.onThumbChange(x)),m=o.useRef(void 0),p=vt(()=>{m.current&&(m.current(),m.current=void 0)},100);return o.useEffect(()=>{const x=i.viewport;if(x){const d=()=>{if(p(),!m.current){const v=so(x,f);m.current=v,f()}};return f(),x.addEventListener("scroll",d),()=>x.removeEventListener("scroll",d)}},[i.viewport,p,f]),n.jsx(Ie.div,{"data-state":l.hasThumb?"visible":"hidden",...a,ref:h,style:{width:"var(--radix-scroll-area-thumb-width)",height:"var(--radix-scroll-area-thumb-height)",...s},onPointerDownCapture:Ue(e.onPointerDownCapture,x=>{const v=x.target.getBoundingClientRect(),S=x.clientX-v.left,L=x.clientY-v.top;l.onThumbPointerDown({x:S,y:L})}),onPointerUp:Ue(e.onPointerUp,l.onThumbPointerUp)})});kn.displayName=gt;var Dt="ScrollAreaCorner",Cn=o.forwardRef((e,t)=>{const r=be(Dt,e.__scopeScrollArea),s=!!(r.scrollbarX&&r.scrollbarY);return r.type!=="scroll"&&s?n.jsx(no,{...e,ref:t}):null});Cn.displayName=Dt;var no=o.forwardRef((e,t)=>{const{__scopeScrollArea:r,...s}=e,a=be(Dt,r),[i,l]=o.useState(0),[f,h]=o.useState(0),m=!!(i&&f);return et(a.scrollbarX,()=>{var x;const p=((x=a.scrollbarX)==null?void 0:x.offsetHeight)||0;a.onCornerHeightChange(p),h(p)}),et(a.scrollbarY,()=>{var x;const p=((x=a.scrollbarY)==null?void 0:x.offsetWidth)||0;a.onCornerWidthChange(p),l(p)}),m?n.jsx(Ie.div,{...s,ref:t,style:{width:i,height:f,position:"absolute",right:a.dir==="ltr"?0:void 0,left:a.dir==="rtl"?0:void 0,bottom:0,...e.style}}):null});function xt(e){return e?parseInt(e,10):0}function En(e,t){const r=e/t;return isNaN(r)?0:r}function yt(e){const t=En(e.viewport,e.content),r=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,s=(e.scrollbar.size-r)*t;return Math.max(s,18)}function ro(e,t,r,s="ltr"){const a=yt(r),i=a/2,l=t||i,f=a-l,h=r.scrollbar.paddingStart+l,m=r.scrollbar.size-r.scrollbar.paddingEnd-f,p=r.content-r.viewport,x=s==="ltr"?[0,p]:[p*-1,0];return Nn([h,m],x)(e)}function Yt(e,t,r="ltr"){const s=yt(t),a=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,i=t.scrollbar.size-a,l=t.content-t.viewport,f=i-s,h=r==="ltr"?[0,l]:[l*-1,0],m=ur(e,h);return Nn([0,l],[0,f])(m)}function Nn(e,t){return r=>{if(e[0]===e[1]||t[0]===t[1])return t[0];const s=(t[1]-t[0])/(e[1]-e[0]);return t[0]+s*(r-e[0])}}function _n(e,t){return e>0&&e<t}var so=(e,t=()=>{})=>{let r={left:e.scrollLeft,top:e.scrollTop},s=0;return(function a(){const i={left:e.scrollLeft,top:e.scrollTop},l=r.left!==i.left,f=r.top!==i.top;(l||f)&&t(),r=i,s=window.requestAnimationFrame(a)})(),()=>window.cancelAnimationFrame(s)};function vt(e,t){const r=qe(e),s=o.useRef(0);return o.useEffect(()=>()=>window.clearTimeout(s.current),[]),o.useCallback(()=>{window.clearTimeout(s.current),s.current=window.setTimeout(r,t)},[r,t])}function et(e,t){const r=qe(t);Yn(()=>{let s=0;if(e){const a=new ResizeObserver(()=>{cancelAnimationFrame(s),s=window.requestAnimationFrame(r)});return a.observe(e),()=>{window.cancelAnimationFrame(s),a.unobserve(e)}}},[e,r])}var Tn=yn,oo=wn,ao=Cn;const Pn=o.forwardRef(({className:e,children:t,...r},s)=>n.jsxs(Tn,{ref:s,className:K("relative overflow-hidden",e),...r,children:[n.jsx(oo,{className:"h-full w-full rounded-[inherit]",children:t}),n.jsx(An,{}),n.jsx(ao,{})]}));Pn.displayName=Tn.displayName;const An=o.forwardRef(({className:e,orientation:t="vertical",...r},s)=>n.jsx(Pt,{ref:s,orientation:t,className:K("flex touch-none select-none transition-colors",t==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",t==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",e),...r,children:n.jsx(kn,{className:"relative flex-1 rounded-full bg-border"})}));An.displayName=Pt.displayName;function Dn(e){return/[Zz]|[+-]\d{2}/.test(e)?new Date(e):new Date(e.replace(" ","T")+"Z")}function io(e){const t=new Map;for(const a of e){const i=Dn(a.created_at).toDateString();t.has(i)||t.set(i,[]),t.get(i).push(a)}const r=new Date().toDateString(),s=new Date(Date.now()-864e5).toDateString();return Array.from(t.entries()).map(([a,i])=>{let l;if(a===r)l="Today";else if(a===s)l="Yesterday";else{const f=new Date(a);l=f.toLocaleDateString(void 0,{month:"short",day:"numeric",...f.getFullYear()!==new Date().getFullYear()?{year:"numeric"}:{}})}return{label:l,items:i}})}function co(e){return Dn(e).toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"})}const lo=5*1024*1024,uo=["image/png","image/jpeg","image/webp"];function ho({buildId:e}){const[t,r]=o.useState([]),[s,a]=o.useState(""),[i,l]=o.useState(null),[f,h]=o.useState(!1),[m,p]=o.useState(""),x=o.useRef(null),d=o.useRef({});function v(){fetch(`/api/v1/comments?build_id=${e}`,{credentials:"include"}).then(C=>C.ok?C.json():[]).then(r)}o.useEffect(()=>{v()},[e]),o.useEffect(()=>{const C=window.location.hash;if(!C.startsWith("#comment-"))return;const T=Number(C.replace("#comment-","")),E=d.current[T];if(!E)return;E.scrollIntoView({behavior:"smooth"});const $=document.documentElement.classList.contains("dark");E.style.backgroundColor=$?"rgb(0 112 243 / 0.18)":"#d3e5ff",setTimeout(()=>{E.style.backgroundColor=""},2e3)},[t]);function S(C){const T=`${location.origin}${location.pathname}${location.search}#comment-${C}`;navigator.clipboard.writeText(T).then(()=>at.success("Link copied")).catch(()=>at.error("Could not copy link"))}function L(C){if(p(""),!uo.includes(C.type)){p("Only png, jpg, webp allowed");return}if(C.size>lo){p("Max 5MB");return}l(C)}async function k(C){if(C.preventDefault(),!s.trim()&&!i)return;h(!0);const T=new FormData;T.append("build_id",String(e)),T.append("body",s),i&&T.append("attachment",i),(await fetch("/api/v1/comments",{method:"POST",credentials:"include",body:T})).ok&&(a(""),l(null),v()),h(!1)}const A=io(t);return n.jsxs("div",{className:"flex h-full flex-col gap-3 px-1",children:[n.jsx(Pn,{className:"flex-1 rounded-md border",children:n.jsx("div",{className:"p-3",children:t.length===0?n.jsx("p",{className:"text-sm text-muted-foreground text-center py-8",children:"No comments yet."}):n.jsx("div",{className:"flex flex-col",children:A.map(({label:C,items:T})=>n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center gap-2 py-3",children:[n.jsx("div",{className:"h-px flex-1 bg-border"}),n.jsx("span",{className:"text-[11px] font-medium text-muted-foreground px-1 select-none",children:C}),n.jsx("div",{className:"h-px flex-1 bg-border"})]}),n.jsx("div",{className:"flex flex-col gap-4",children:T.map(E=>n.jsxs("div",{id:`comment-${E.id}`,ref:$=>{d.current[E.id]=$},className:"group flex gap-2.5 rounded-md px-2 py-1.5 transition-all",children:[n.jsx("div",{className:"mt-0.5 shrink-0",children:n.jsx(Kn,{name:E.author,avatarUrl:E.authorAvatarUrl,size:28})}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx("span",{className:"text-sm font-semibold leading-none",children:E.author}),n.jsx("span",{className:"text-[11px] text-muted-foreground leading-none",children:co(E.created_at)}),n.jsx(ee,{variant:"ghost",size:"icon",className:"h-4 w-4 ml-0.5 opacity-0 group-hover:opacity-50 hover:!opacity-100 transition-opacity",onClick:()=>S(E.id),children:n.jsx(an,{className:"h-3 w-3"})})]}),n.jsx("p",{className:"text-sm leading-relaxed whitespace-pre-wrap mt-1",children:E.body}),E.attachments.map($=>n.jsx("a",{href:$.file_path,target:"_blank",rel:"noreferrer",className:"mt-1.5 block",children:n.jsx("img",{src:$.file_path,alt:"attachment",className:"max-h-48 rounded border object-contain"})},$.id))]})]},E.id))})]},C))})})}),n.jsx("div",{className:"pb-1",children:n.jsx("form",{onSubmit:k,children:n.jsxs("div",{className:"rounded-xl border border-input bg-background ring-offset-background transition-shadow focus-within:outline-none focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2",children:[n.jsx(xn,{placeholder:"Leave a comment…",value:s,onChange:C=>a(C.target.value),className:"min-h-16 resize-none border-0 bg-transparent shadow-none focus-visible:ring-0 focus-visible:ring-offset-0 text-sm"}),(i||m)&&n.jsxs("div",{className:"px-3 -mt-1 pb-1",children:[i&&n.jsx("p",{className:"text-xs text-muted-foreground",children:i.name}),m&&n.jsx("p",{className:"text-xs text-destructive",children:m})]}),n.jsxs("div",{className:"flex items-center gap-2 px-2 py-2",children:[n.jsx(ee,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground",onClick:()=>{var C;return(C=x.current)==null?void 0:C.click()},children:n.jsx(Tr,{className:"h-4 w-4"})}),n.jsx("input",{ref:x,type:"file",accept:"image/png,image/jpeg,image/webp",className:"hidden",onChange:C=>{var E;const T=(E=C.target.files)==null?void 0:E[0];T&&L(T)}}),n.jsx("div",{className:"flex-1"}),n.jsx(ee,{type:"submit",size:"icon",className:"h-7 w-7 rounded-full",disabled:f||!s.trim()&&!i,children:n.jsx(wr,{className:"h-3.5 w-3.5"})})]})]})})})]})}function fo(e){return e<1024*1024?`${(e/1024).toFixed(0)} KB`:`${(e/1024/1024).toFixed(1)} MB`}function po(e){return new Date(e).toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function mo(e){const t=new Date(e).getTime()-Date.now();if(t<=0)return{label:"Expired",urgent:!0};const r=Math.floor(t/36e5);return r<1?{label:"< 1 hour left",urgent:!0}:r<24?{label:`Expires in ${r}h`,urgent:r<6}:{label:`Expires in ${Math.floor(r/24)}d`,urgent:!1}}function go({buildId:e,refreshKey:t}){const[r,s]=o.useState([]),[a,i]=o.useState(!0),[l,f]=o.useState(!1);return o.useEffect(()=>{i(!0),f(!1);const h=setTimeout(()=>f(!0),250);return fetch(`/api/v1/recordings?buildId=${e}`,{credentials:"include"}).then(m=>m.ok?m.json():[]).then(m=>s(m)).catch(()=>s([])).finally(()=>{clearTimeout(h),i(!1)}),()=>clearTimeout(h)},[e,t]),a?l?n.jsx("p",{className:"text-xs text-muted-foreground",children:"Loading recordings…"}):null:r.length===0?n.jsx("p",{className:"py-8 text-center text-sm text-muted-foreground",children:"No recordings yet."}):n.jsx("div",{className:"flex flex-col gap-2",children:r.map(h=>{const m=mo(h.expiresAt);return n.jsxs("div",{className:"flex items-center justify-between rounded-md border border-border px-3 py-2 text-sm",children:[n.jsxs("div",{className:"flex flex-col gap-0.5 min-w-0",children:[n.jsx("span",{className:"text-xs font-medium truncate",children:po(h.createdAt)}),n.jsxs("span",{className:`text-xs ${m.urgent?"text-destructive":"text-muted-foreground"}`,children:[m.label," · ",fo(h.fileSize)]})]}),n.jsx(ee,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0 ml-2",title:"Download",onClick:()=>{const p=document.createElement("a");p.href=h.url,p.download="",p.click()},children:n.jsx(kr,{className:"h-3.5 w-3.5"})})]},h.id)})})}function xo({buildId:e,recordingsRefreshKey:t=0}){return n.jsxs(ar,{defaultValue:"comments",className:"flex h-full flex-col",children:[n.jsx("div",{className:"shrink-0 px-1",children:n.jsxs(ir,{className:"w-full",children:[n.jsxs(It,{value:"comments",className:"flex-1 gap-1.5",children:[n.jsx($r,{className:"h-3.5 w-3.5"}),"Comments"]}),n.jsxs(It,{value:"recordings",className:"flex-1 gap-1.5",children:[n.jsx(Er,{className:"h-3.5 w-3.5"}),"Recordings"]})]})}),n.jsx(Ft,{value:"comments",className:"mt-3 min-h-0 flex-1 overflow-hidden",children:n.jsx(ho,{buildId:e})}),n.jsx(Ft,{value:"recordings",className:"mt-3 min-h-0 flex-1 overflow-y-auto",children:n.jsx(go,{buildId:e,refreshKey:t})})]})}const Ln=o.forwardRef(({...e},t)=>n.jsx("nav",{ref:t,"aria-label":"breadcrumb",...e}));Ln.displayName="Breadcrumb";const Mn=o.forwardRef(({className:e,...t},r)=>n.jsx("ol",{ref:r,className:K("flex flex-wrap items-center gap-1.5 break-words text-sm text-muted-foreground sm:gap-2.5",e),...t}));Mn.displayName="BreadcrumbList";const ot=o.forwardRef(({className:e,...t},r)=>n.jsx("li",{ref:r,className:K("inline-flex items-center gap-1.5",e),...t}));ot.displayName="BreadcrumbItem";const ut=o.forwardRef(({asChild:e,className:t,...r},s)=>{const a=e?Gn:"a";return n.jsx(a,{ref:s,className:K("transition-colors hover:text-foreground cursor-pointer",t),...r})});ut.displayName="BreadcrumbLink";const ht=o.forwardRef(({className:e,...t},r)=>n.jsx("span",{ref:r,role:"link","aria-disabled":"true","aria-current":"page",className:K("font-medium text-foreground",e),...t}));ht.displayName="BreadcrumbPage";const ft=({children:e,className:t,...r})=>n.jsx("li",{role:"presentation","aria-hidden":"true",className:K("[&>svg]:h-3.5 [&>svg]:w-3.5",t),...r,children:e??n.jsx(qn,{})});ft.displayName="BreadcrumbSeparator";var wt="Switch",[bo]=Qt(wt),[yo,Lt]=bo(wt);function vo(e){const{__scopeSwitch:t,checked:r,children:s,defaultChecked:a,disabled:i,form:l,name:f,onCheckedChange:h,required:m,value:p="on",internal_do_not_use_render:x}=e,[d,v]=Jn({prop:r,defaultProp:a??!1,onChange:h,caller:wt}),[S,L]=o.useState(null),[k,A]=o.useState(null),C=o.useRef(!1),T=S?!!l||!!S.closest("form"):!0,E={checked:d,setChecked:v,disabled:i,control:S,setControl:L,name:f,form:l,value:p,hasConsumerStoppedPropagationRef:C,required:m,defaultChecked:a,isFormControl:T,bubbleInput:k,setBubbleInput:A};return n.jsx(yo,{scope:t,...E,children:wo(x)?x(E):s})}var Hn="SwitchTrigger",Un=o.forwardRef(({__scopeSwitch:e,onClick:t,...r},s)=>{const{value:a,disabled:i,checked:l,required:f,setControl:h,setChecked:m,hasConsumerStoppedPropagationRef:p,isFormControl:x,bubbleInput:d}=Lt(Hn,e),v=$e(s,h);return n.jsx(Ie.button,{type:"button",role:"switch","aria-checked":l,"aria-required":f,"data-state":zn(l),"data-disabled":i?"":void 0,disabled:i,value:a,...r,ref:v,onClick:Ue(t,S=>{m(L=>!L),d&&x&&(p.current=S.isPropagationStopped(),p.current||S.stopPropagation())})})});Un.displayName=Hn;var Mt=o.forwardRef((e,t)=>{const{__scopeSwitch:r,name:s,checked:a,defaultChecked:i,required:l,disabled:f,value:h,onCheckedChange:m,form:p,...x}=e;return n.jsx(vo,{__scopeSwitch:r,checked:a,defaultChecked:i,disabled:f,required:l,onCheckedChange:m,name:s,form:p,value:h,internal_do_not_use_render:({isFormControl:d})=>n.jsxs(n.Fragment,{children:[n.jsx(Un,{...x,ref:t,__scopeSwitch:r}),d&&n.jsx(Bn,{__scopeSwitch:r})]})})});Mt.displayName=wt;var $n="SwitchThumb",In=o.forwardRef((e,t)=>{const{__scopeSwitch:r,...s}=e,a=Lt($n,r);return n.jsx(Ie.span,{"data-state":zn(a.checked),"data-disabled":a.disabled?"":void 0,...s,ref:t})});In.displayName=$n;var Fn="SwitchBubbleInput",Bn=o.forwardRef(({__scopeSwitch:e,...t},r)=>{const{control:s,hasConsumerStoppedPropagationRef:a,checked:i,defaultChecked:l,required:f,disabled:h,name:m,value:p,form:x,bubbleInput:d,setBubbleInput:v}=Lt(Fn,e),S=$e(r,v),L=hr(i),k=Zn(s);o.useEffect(()=>{const C=d;if(!C)return;const T=window.HTMLInputElement.prototype,$=Object.getOwnPropertyDescriptor(T,"checked").set,D=!a.current;if(L!==i&&$){const B=new Event("click",{bubbles:D});$.call(C,i),C.dispatchEvent(B)}},[d,L,i,a]);const A=o.useRef(i);return n.jsx(Ie.input,{type:"checkbox","aria-hidden":!0,defaultChecked:l??A.current,required:f,disabled:h,name:m,value:p,form:x,...t,tabIndex:-1,ref:S,style:{...t.style,...k,position:"absolute",pointerEvents:"none",opacity:0,margin:0,transform:"translateX(-100%)"}})});Bn.displayName=Fn;function wo(e){return typeof e=="function"}function zn(e){return e?"checked":"unchecked"}const On=o.forwardRef(({className:e,...t},r)=>n.jsx(Mt,{className:K("peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",e),...t,ref:r,children:n.jsx(In,{className:K("pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0")})}));On.displayName=Mt.displayName;const Kt=70,Gt=80;function So(e,t){if(!e||t)return"unknown";const r=e.memUsedMB/e.memTotalMB*100;return e.cpuPercent>Gt||r>Gt?"overloaded":e.cpuPercent>=Kt||r>=Kt?"warning":"healthy"}function _o(){const[e]=Jt(),t=Qn(),r=e.get("id"),{build:s}=Qr(r),[a,i]=o.useState(0),l=(s==null?void 0:s.platform)??"ios",{sessions:f,selectedAgent:h,setSelectedAgent:m,activeSessionId:p,deviceId:x,booting:d,status:v,connected:S,agentGroups:L,startDevice:k,resetDevice:A,handleBack:C,handleBackToMacs:T}=es(l),E=L.find(N=>N.agentName===h),{osVersions:$,osVersion:D,setOsVersion:B,deviceSearch:X,setDeviceSearch:I,versionedDevices:z,resetMode:q,setResetMode:je}=ts(E,l),ae=f.flatMap(N=>N.devices).find(N=>N.id===x),ke=ae?`${ae.name}${ae.osVersion?` · ${ae.osVersion}`:""}`:"",fe=o.useCallback(()=>i(N=>N+1),[]),{setNode:ie}=er();return o.useEffect(()=>{if(s)return ie(n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx(Ln,{children:n.jsxs(Mn,{children:[n.jsx(ot,{children:n.jsx(ut,{asChild:!0,children:n.jsx("button",{onClick:()=>t(`/app-center?appId=${s.app_id}`),children:s.name})})}),n.jsx(ft,{}),n.jsx(ot,{children:h?n.jsx(ut,{asChild:!0,children:n.jsx("button",{onClick:T,children:$t(s)})}):n.jsx(ht,{children:$t(s)})}),h&&n.jsxs(n.Fragment,{children:[n.jsx(ft,{}),n.jsx(ot,{children:p?n.jsx(ut,{asChild:!0,children:n.jsx("button",{onClick:C,children:h})}):n.jsx(ht,{children:h})})]}),p&&n.jsxs(n.Fragment,{children:[n.jsx(ft,{}),n.jsx(ot,{children:n.jsx(ht,{children:ke})})]})]})}),!h&&s.status_label&&n.jsx(xr,{tone:sr[s.status_label],children:s.status_label})]})),()=>ie(null)},[s,h,p,ke,t,C,T,ie]),n.jsxs("div",{className:"flex h-full min-h-0 gap-6 p-6",children:[n.jsx("div",{className:"flex flex-col gap-3 flex-1 min-w-0 min-h-0",children:n.jsx("div",{className:"flex-1 min-h-0 overflow-auto -ml-1 pl-1 -mr-4 pr-4",children:p?n.jsx("div",{className:"min-h-full flex items-center justify-center py-6 px-8 min-w-max",children:n.jsx(Xs,{sessionId:p,deviceId:x,buildId:s==null?void 0:s.id,resetMode:q,onRecordingUploaded:fe})}):h?n.jsxs("div",{className:"flex flex-col gap-5",children:[n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx("button",{onClick:T,className:"text-sm text-muted-foreground hover:text-foreground transition-colors",children:"← All Macs"}),n.jsx("h1",{className:"text-xl font-semibold tracking-tight",children:"Select device"})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(or,{placeholder:"Search device…",value:X,onChange:I}),$.length>0&&n.jsxs(fr,{value:D||"__all__",onValueChange:N=>{B(N==="__all__"?"":N),A()},children:[n.jsx(pr,{className:"h-8 w-36 shrink-0",children:n.jsx(mr,{})}),n.jsxs(gr,{children:[n.jsx(Bt,{value:"__all__",children:"Any version"}),$.map(N=>n.jsx(Bt,{value:N,children:N},N))]})]}),n.jsx(kt,{children:n.jsxs(we,{children:[n.jsxs("div",{className:"ml-auto flex items-center gap-2 shrink-0",children:[n.jsx(Se,{asChild:!0,children:n.jsxs(tr,{htmlFor:"reset-mode",className:"flex items-center gap-1 text-sm cursor-pointer whitespace-nowrap",children:[n.jsx(Ar,{className:"h-3.5 w-3.5 text-muted-foreground"}),"Full reset"]})}),n.jsx(On,{id:"reset-mode",checked:q==="full-erase",onCheckedChange:N=>je(N?"full-erase":"app-only")})]}),n.jsx(Re,{children:q==="full-erase"?"Erase all data before booting":"Keep existing data"})]})})]}),z.length===0?n.jsx("p",{className:"text-sm text-muted-foreground",children:S?"No devices available for this OS.":"Connecting to relay…"}):n.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-2 2xl:grid-cols-3 gap-2",children:z.map(N=>{const O=N.status==="booted",Z=N.busy,te=Z?"In use":O?"Booted":"Available",Ce=Z?"bg-amber-400":O?"bg-emerald-400":"bg-muted-foreground/40";return n.jsxs("button",{disabled:Z||d||!S,onClick:()=>k(N),className:K("flex flex-col gap-3 rounded-lg border p-3 text-left transition-colors min-h-[100px]","hover:bg-accent disabled:cursor-not-allowed disabled:opacity-50"),children:[n.jsx("span",{className:"text-sm font-medium leading-tight",children:N.name}),N.osVersion&&n.jsx("span",{className:"font-mono text-xs text-muted-foreground",children:N.osVersion}),n.jsxs("span",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[n.jsx("span",{className:K("inline-block h-1.5 w-1.5 rounded-full",Ce)}),te]})]},N.id)})}),v&&n.jsx("p",{className:"text-sm text-muted-foreground",children:v})]}):n.jsxs("div",{className:"flex flex-col gap-5",children:[n.jsx("h1",{className:"text-xl font-semibold tracking-tight",children:"Select Mac"}),L.length===0?n.jsx("p",{className:"text-sm text-muted-foreground",children:S?`No agents available for ${l}.`:"Connecting to relay…"}):n.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-2 2xl:grid-cols-3 gap-2",children:L.map(N=>{const O=N.resources,Z=O?Date.now()-O.reportedAt>3e4:!1,te=N.devices.filter(ce=>ce.platform===l).length,Ce=(O==null?void 0:O.cpuPercent)??0,M=O?O.memUsedMB/O.memTotalMB*100:0,W=So(O,Z),Q=W==="overloaded";return n.jsx(kt,{children:n.jsxs(we,{children:[n.jsx(Se,{asChild:!0,children:n.jsx("span",{tabIndex:Q?0:void 0,className:Q?"cursor-not-allowed":void 0,children:n.jsxs("button",{disabled:Q,"aria-disabled":Q,onClick:()=>m(N.agentName??null),className:K("flex flex-col gap-3 rounded-lg border p-3 text-left transition-colors min-h-[100px] w-full",Q?"pointer-events-none":"hover:bg-accent"),children:[n.jsxs("div",{className:"flex items-start justify-between gap-2",children:[n.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[n.jsx(Ro,{health:W}),n.jsx("span",{className:"text-sm font-medium leading-tight truncate",children:N.agentName??"Unknown"})]}),Z&&n.jsx("span",{className:"shrink-0 text-[10px] font-medium text-amber-500",children:"Stale"})]}),n.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[n.jsxs("span",{children:[te," device",te!==1?"s":""]}),O&&n.jsxs(n.Fragment,{children:[n.jsx("span",{children:"·"}),n.jsxs("span",{children:[O.slotsAvailable,"/",O.slotsTotal," slots"]})]})]}),O&&!Z&&n.jsxs("div",{className:"flex flex-col gap-1.5 w-full",children:[n.jsx(qt,{label:"CPU",percent:Ce,colorClass:"bg-blue-400"}),n.jsx(qt,{label:"RAM",percent:M,colorClass:"bg-violet-400"})]})]})})}),Q&&n.jsx(Re,{children:"This Mac is currently overloaded. Try again later."})]})},N.agentName)})})]})})}),r&&n.jsxs(n.Fragment,{children:[n.jsx(Zt,{orientation:"vertical",className:"h-auto"}),n.jsx("div",{className:"w-80 shrink-0 h-full",children:n.jsx(xo,{buildId:Number(r),recordingsRefreshKey:a})})]})]})}function Ro({health:e}){const t={unknown:"bg-muted-foreground/40",healthy:"bg-emerald-400",warning:"bg-amber-400",overloaded:"bg-red-500"}[e];return n.jsx("span",{"data-testid":"resource-health-dot",className:K("inline-block h-2 w-2 shrink-0 rounded-full",t)})}function qt({label:e,percent:t,colorClass:r}){return n.jsxs("div",{className:"flex flex-col gap-0.5",children:[n.jsxs("div",{className:"flex justify-between text-[10px] text-muted-foreground",children:[n.jsx("span",{children:e}),n.jsxs("span",{children:[t.toFixed(0),"%"]})]}),n.jsx("div",{className:"h-1 w-full rounded-full bg-muted overflow-hidden",children:n.jsx("div",{className:K("h-full rounded-full transition-all",r),style:{width:`${Math.min(100,t)}%`}})})]})}export{_o as QASession};
Binary file
Binary file
@@ -1,6 +0,0 @@
1
- import{Y as $,a7 as n,ai as H,aa as M,a4 as e,B as d,a9 as a,L as k,I as S,C as O,d as V,e as z,c as W,b as J,a5 as U,a8 as A}from"./index-Dfs85Uiw.js";import{B as I}from"./badge-Cx2-XXcg.js";import{A as Y,c as q,f as G,g as K,d as Q,e as X,b as Z}from"./alert-dialog-qlHDtr4B.js";import{D as ee,f as se,a as ae,d as te,e as ne,S as re,i as oe,j as ie,g as le,h as _}from"./dialog-DzNUT3NF.js";import{T as ce,d as de,e as y,c as x,a as xe,b as i}from"./table-BXnp_tRt.js";import{P as he}from"./plus-DnAOz8DL.js";/**
2
- * @license lucide-react v0.577.0 - ISC
3
- *
4
- * This source code is licensed under the ISC license.
5
- * See the LICENSE file in the root directory of this source tree.
6
- */const me=[["path",{d:"M10 11v6",key:"nco0om"}],["path",{d:"M14 11v6",key:"outv1u"}],["path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6",key:"miytrc"}],["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2",key:"e791ji"}]],pe=$("trash-2",me);async function ue(){const t=window.location.protocol==="https:"?"wss":"ws";if(["localhost","127.0.0.1","[::1]"].includes(window.location.hostname))try{const h=await fetch("/api/v1/relay/host",{credentials:"include"});if(h.ok){const{lanHost:l,port:o}=await h.json();if(l)return`${t}://${l}:${o}`}}catch{}return`${t}://${window.location.host}`}const je=U({name:A().min(1),expiresDays:A().refine(t=>{const r=parseInt(t,10);return!isNaN(r)&&r>=1&&r<=365},{message:"Must be between 1 and 365"})});function Ne(){const[t,r]=n.useState([]),[h,l]=n.useState(!1),[o,v]=n.useState(""),[c,w]=n.useState("api"),[N,b]=n.useState(""),[u,j]=n.useState(null),{register:T,handleSubmit:B,reset:E,formState:{errors:m,isSubmitting:C}}=H({resolver:M(je),mode:"onBlur",defaultValues:{name:"",expiresDays:"30"}});function g(){fetch("/api/v1/tokens",{credentials:"include"}).then(s=>s.json()).then(r)}n.useEffect(()=>{g()},[]);async function L(s){try{const p=await fetch("/api/v1/tokens",{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:s.name,expires_in_days:parseInt(s.expiresDays,10),...c==="agent"?{scope:"agent"}:{}})});if(!p.ok){const f=await p.json().catch(()=>null);a.error((f==null?void 0:f.error)??"Failed to create token");return}const P=await p.json();c==="agent"&&b(await ue()),a.success("Token created"),v(P.token),g()}catch{a.error("Network error")}}function R(s){l(s),s||(v(""),w("api"),b(""),E())}async function F(s){try{return(await fetch(`/api/v1/tokens/${s}`,{method:"DELETE",credentials:"include"})).ok?(a.success("Token revoked"),g(),!0):(a.error("Failed to revoke token"),!1)}catch{return a.error("Network error"),!1}}function D(s){return s.expires_at&&new Date(s.expires_at)<new Date}return e.jsxs("div",{className:"flex flex-col gap-6 max-w-[900px] mx-auto w-full p-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h1",{className:"text-xl font-semibold",children:"Personal Access Tokens"}),e.jsxs(ee,{open:h,onOpenChange:R,children:[e.jsx(se,{asChild:!0,children:e.jsxs(d,{size:"sm",children:[e.jsx(he,{className:"mr-2 h-4 w-4"}),"New token"]})}),e.jsxs(ae,{className:"sm:max-w-md",children:[e.jsx(te,{children:e.jsx(ne,{children:"Create token"})}),o?e.jsxs("div",{className:"flex flex-col gap-3 pt-2",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Copy this token now — it won't be shown again."}),e.jsx("code",{className:"rounded bg-muted px-3 py-2 text-xs break-all font-mono",children:o}),c==="agent"&&N&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Run this on the agent Mac to connect it to this relay:"}),e.jsx("code",{className:"rounded bg-muted px-3 py-2 text-xs break-all font-mono",children:`tapflow agent start --relay ${N} --token ${o}`})]}),e.jsx(d,{onClick:()=>{navigator.clipboard.writeText(o).then(()=>{a.success("Token copied to clipboard"),l(!1)}).catch(()=>a.error("Failed to copy — copy manually"))},children:"Copy & close"})]}):e.jsxs("form",{onSubmit:B(L),className:"flex flex-col gap-4 pt-2",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(k,{htmlFor:"token-name",children:"Name"}),e.jsx(S,{id:"token-name",placeholder:"e.g. ci-deploy",...T("name")}),m.name&&e.jsx("p",{className:"text-sm text-destructive",children:m.name.message})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(k,{htmlFor:"expires",children:"Expires in (days)"}),e.jsx(S,{id:"expires",type:"number",...T("expiresDays")}),m.expiresDays&&e.jsx("p",{className:"text-sm text-destructive",children:m.expiresDays.message})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(k,{children:"Type"}),e.jsxs(re,{value:c,onValueChange:s=>w(s),children:[e.jsx(oe,{children:e.jsx(ie,{})}),e.jsxs(le,{children:[e.jsx(_,{value:"api",children:"API — CI uploads & API access"}),e.jsx(_,{value:"agent",children:"Agent — connect remote device agents (Admin only)"})]})]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Scope: ",e.jsx(I,{variant:"secondary",children:c==="agent"?"agent":"view, builds:write"})]}),e.jsx(d,{type:"submit",disabled:C,children:C?"Creating…":"Create token"})]})]})]})]}),e.jsxs(O,{children:[e.jsxs(V,{children:[e.jsx(z,{children:"Active tokens"}),e.jsxs(W,{children:["Use these tokens with ",e.jsx("code",{className:"text-xs",children:"Authorization: Bearer <token>"})," for API deployments."]})]}),e.jsx(J,{className:"px-4 pt-0 pb-2",children:e.jsxs(ce,{children:[e.jsx(de,{children:e.jsxs(y,{children:[e.jsx(x,{children:"Name"}),e.jsx(x,{children:"Scope"}),e.jsx(x,{children:"Last used"}),e.jsx(x,{children:"Expires"}),e.jsx(x,{className:"w-10"})]})}),e.jsx(xe,{children:t.length===0?e.jsx(y,{children:e.jsx(i,{colSpan:5,className:"h-20 text-center text-muted-foreground",children:"No tokens yet."})}):t.map(s=>e.jsxs(y,{className:"hover:bg-transparent",children:[e.jsx(i,{className:"font-medium",children:s.name}),e.jsx(i,{children:e.jsx(I,{variant:"secondary",children:s.scope})}),e.jsx(i,{className:"text-muted-foreground text-sm",children:s.last_used_at?new Date(s.last_used_at).toLocaleDateString():"Never"}),e.jsx(i,{children:s.expires_at?e.jsx("span",{className:D(s)?"text-destructive text-sm":"text-muted-foreground text-sm",children:D(s)?"Expired":new Date(s.expires_at).toLocaleDateString()}):e.jsx("span",{className:"text-muted-foreground text-sm",children:"Never"})}),e.jsx(i,{children:e.jsx(d,{variant:"destructive",size:"icon",className:"h-7 w-7","aria-label":"Revoke token",onClick:()=>j(s.id),children:e.jsx(pe,{className:"h-4 w-4"})})})]},s.id))})]})})]}),e.jsx(Y,{open:u!==null,onOpenChange:s=>{s||j(null)},children:e.jsxs(q,{children:[e.jsxs(G,{children:[e.jsx(K,{children:"Revoke token?"}),e.jsx(Q,{children:"Any active API calls using this token will immediately fail."})]}),e.jsxs(X,{children:[e.jsx(Z,{children:"Cancel"}),e.jsx(d,{variant:"destructive",onClick:async()=>{if(u===null)return;await F(u)&&j(null)},children:"Revoke"})]})]})})]})}export{Ne as TokenSettings};
Binary file
Binary file
@@ -1,11 +0,0 @@
1
- import{Y as i,a4 as r,I as o}from"./index-Dfs85Uiw.js";/**
2
- * @license lucide-react v0.577.0 - ISC
3
- *
4
- * This source code is licensed under the ISC license.
5
- * See the LICENSE file in the root directory of this source tree.
6
- */const c=[["path",{d:"M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z",key:"10ikf1"}]],f=i("play",c);/**
7
- * @license lucide-react v0.577.0 - ISC
8
- *
9
- * This source code is licensed under the ISC license.
10
- * See the LICENSE file in the root directory of this source tree.
11
- */const u=[["path",{d:"m21 21-4.34-4.34",key:"14j7rj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}]],l=i("search",u);function m({value:e,onChange:a,placeholder:t,className:n}){return r.jsxs("div",{className:"relative",children:[r.jsx(l,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground pointer-events-none"}),r.jsx(o,{placeholder:t,value:e,onChange:s=>a(s.target.value),className:`h-8 pl-8 ${n??"w-48"}`})]})}async function h(){const e=await fetch("/api/v1/apps",{credentials:"include"});return e.ok?(await e.json()).items:[]}async function y({appId:e,search:a,statusFilter:t}){const n=new URLSearchParams({app_id:String(e),limit:"100",sort:"uploaded_at",dir:"desc"});a&&n.set("q",a),t&&t!=="all"&&n.set("status",t);const s=await fetch(`/api/v1/builds?${n}`,{credentials:"include"});return s.ok?(await s.json()).items:[]}async function b(e){const a=await fetch("/api/v1/apps",{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});return a.status===409?{error:"App with this bundle ID and platform already exists"}:a.ok?a.json():null}async function _(e,a){await fetch(`/api/v1/builds/${e}`,{method:"PATCH",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify({status_label:a})})}async function g(e){const a=await fetch(`/api/v1/builds/${e}`,{credentials:"include"});return a.ok?a.json():null}function j(e){const a=new Map;for(const t of e){const n=t.version_name??"Unversioned";a.has(n)||a.set(n,[]),a.get(n).push(t)}return Array.from(a.entries()).map(([t,n])=>({versionName:t,builds:n}))}const v={Backlog:"backlog","In Progress":"progress",Done:"done",Rejected:"rejected"};function w(e){return e.version_name&&e.build_number?`${e.version_name} · build ${e.build_number}`:e.version_name??e.version_label??(e.build_number?`build ${e.build_number}`:"Build")}export{f as P,v as S,l as a,m as b,w as c,b as d,g as e,y as f,h as g,j as h,_ as u};
Binary file
Binary file
Binary file
@@ -1,6 +0,0 @@
1
- import{Y as e}from"./index-Dfs85Uiw.js";/**
2
- * @license lucide-react v0.577.0 - ISC
3
- *
4
- * This source code is licensed under the ISC license.
5
- * See the LICENSE file in the root directory of this source tree.
6
- */const o=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]],t=e("plus",o);export{t as P};
Binary file
Binary file
Binary file