@ours.network/messenger-server 1.0.11 → 1.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/{chunk-VAAEOUKO.js → chunk-RR7VODRD.js} +1 -1
- package/dist/chunks/{server-ONX7REAF.js → server-2PPYOKEJ.js} +25 -2
- package/dist/cli.js +2 -2
- package/dist/web/assets/{abnfDiagram-N423BO3Z-CqPWn49C.js → abnfDiagram-N423BO3Z-BtRodSLT.js} +2 -2
- package/dist/web/assets/{abnfDiagram-N423BO3Z-CqPWn49C.js.map → abnfDiagram-N423BO3Z-BtRodSLT.js.map} +1 -1
- package/dist/web/assets/{arc-3B7PFRgm.js → arc-CGff2Gxi.js} +2 -2
- package/dist/web/assets/{arc-3B7PFRgm.js.map → arc-CGff2Gxi.js.map} +1 -1
- package/dist/web/assets/{architectureDiagram-T3A2C74G-DfLEjIUl.js → architectureDiagram-T3A2C74G-CEkaPUJO.js} +2 -2
- package/dist/web/assets/{architectureDiagram-T3A2C74G-DfLEjIUl.js.map → architectureDiagram-T3A2C74G-CEkaPUJO.js.map} +1 -1
- package/dist/web/assets/{blockDiagram-VBNYF7ZC-DbJ87tB6.js → blockDiagram-VBNYF7ZC-DH-BzAD-.js} +2 -2
- package/dist/web/assets/{blockDiagram-VBNYF7ZC-DbJ87tB6.js.map → blockDiagram-VBNYF7ZC-DH-BzAD-.js.map} +1 -1
- package/dist/web/assets/{browser-CqRIlH-x.js → browser-DQqNbucF.js} +2 -2
- package/dist/web/assets/{browser-CqRIlH-x.js.map → browser-DQqNbucF.js.map} +1 -1
- package/dist/web/assets/{c4Diagram-5PPSVZJV-aYlJS5PI.js → c4Diagram-5PPSVZJV-Cg-gF1-m.js} +2 -2
- package/dist/web/assets/{c4Diagram-5PPSVZJV-aYlJS5PI.js.map → c4Diagram-5PPSVZJV-Cg-gF1-m.js.map} +1 -1
- package/dist/web/assets/channel-29vHEcuz.js +2 -0
- package/dist/web/assets/{channel-dW2gWx3T.js.map → channel-29vHEcuz.js.map} +1 -1
- package/dist/web/assets/{chunk-2GRJ4B5K-AJhprA8r.js → chunk-2GRJ4B5K-CAtSMTHm.js} +2 -2
- package/dist/web/assets/{chunk-2GRJ4B5K-AJhprA8r.js.map → chunk-2GRJ4B5K-CAtSMTHm.js.map} +1 -1
- package/dist/web/assets/{chunk-2Q5K7J3B-DlHDneWM.js → chunk-2Q5K7J3B-DcxLp8hA.js} +2 -2
- package/dist/web/assets/{chunk-2Q5K7J3B-DlHDneWM.js.map → chunk-2Q5K7J3B-DcxLp8hA.js.map} +1 -1
- package/dist/web/assets/{chunk-5RXB4S5H-DVtX858s.js → chunk-5RXB4S5H-BsJn7KTc.js} +2 -2
- package/dist/web/assets/{chunk-5RXB4S5H-DVtX858s.js.map → chunk-5RXB4S5H-BsJn7KTc.js.map} +1 -1
- package/dist/web/assets/{chunk-5VM5RSS4-BnqyETiw.js → chunk-5VM5RSS4-D82tGBQx.js} +2 -2
- package/dist/web/assets/{chunk-5VM5RSS4-BnqyETiw.js.map → chunk-5VM5RSS4-D82tGBQx.js.map} +1 -1
- package/dist/web/assets/{chunk-6Q2QTUOP-VwtdxEqq.js → chunk-6Q2QTUOP-BbhK4WhF.js} +2 -2
- package/dist/web/assets/{chunk-6Q2QTUOP-VwtdxEqq.js.map → chunk-6Q2QTUOP-BbhK4WhF.js.map} +1 -1
- package/dist/web/assets/{chunk-GF5L2VYU-BP-GNqx9.js → chunk-GF5L2VYU-CqAzpSE4.js} +2 -2
- package/dist/web/assets/{chunk-GF5L2VYU-BP-GNqx9.js.map → chunk-GF5L2VYU-CqAzpSE4.js.map} +1 -1
- package/dist/web/assets/{chunk-JWPE2WC7-DzY9yv5e.js → chunk-JWPE2WC7-BDu-DE29.js} +2 -2
- package/dist/web/assets/{chunk-JWPE2WC7-DzY9yv5e.js.map → chunk-JWPE2WC7-BDu-DE29.js.map} +1 -1
- package/dist/web/assets/{chunk-KBJHAD2P-EWGGIyEs.js → chunk-KBJHAD2P-ZsKKsPl9.js} +2 -2
- package/dist/web/assets/{chunk-KBJHAD2P-EWGGIyEs.js.map → chunk-KBJHAD2P-ZsKKsPl9.js.map} +1 -1
- package/dist/web/assets/{chunk-RYQCIY6F-zdkBQ149.js → chunk-RYQCIY6F-Bo9uGPTs.js} +2 -2
- package/dist/web/assets/{chunk-RYQCIY6F-zdkBQ149.js.map → chunk-RYQCIY6F-Bo9uGPTs.js.map} +1 -1
- package/dist/web/assets/{chunk-XXDRQBXY-B5s1DPid.js → chunk-XXDRQBXY-BZctD5FG.js} +2 -2
- package/dist/web/assets/{chunk-XXDRQBXY-B5s1DPid.js.map → chunk-XXDRQBXY-BZctD5FG.js.map} +1 -1
- package/dist/web/assets/classDiagram-JCYQIIEL-DetglZ6m.js +2 -0
- package/dist/web/assets/{classDiagram-JCYQIIEL-qy_NR-tD.js.map → classDiagram-JCYQIIEL-DetglZ6m.js.map} +1 -1
- package/dist/web/assets/classDiagram-v2-OCEON4UE-DetglZ6m.js +2 -0
- package/dist/web/assets/{classDiagram-v2-OCEON4UE-qy_NR-tD.js.map → classDiagram-v2-OCEON4UE-DetglZ6m.js.map} +1 -1
- package/dist/web/assets/{cose-bilkent-JH36ORCC-D_C2gOXL.js → cose-bilkent-JH36ORCC-rjt8sxQq.js} +2 -2
- package/dist/web/assets/{cose-bilkent-JH36ORCC-D_C2gOXL.js.map → cose-bilkent-JH36ORCC-rjt8sxQq.js.map} +1 -1
- package/dist/web/assets/{cynefin-VYW2F7L2-D5Shoam2.js → cynefin-VYW2F7L2-DQq1LN_j.js} +2 -2
- package/dist/web/assets/{cynefin-VYW2F7L2-D5Shoam2.js.map → cynefin-VYW2F7L2-DQq1LN_j.js.map} +1 -1
- package/dist/web/assets/{cynefinDiagram-MW4NZA55-BlnnDAn4.js → cynefinDiagram-MW4NZA55-CvjcY_Lo.js} +2 -2
- package/dist/web/assets/{cynefinDiagram-MW4NZA55-BlnnDAn4.js.map → cynefinDiagram-MW4NZA55-CvjcY_Lo.js.map} +1 -1
- package/dist/web/assets/{dagre-VZM6K2ZE-CcmbgD8y.js → dagre-VZM6K2ZE-BlKo0jE-.js} +2 -2
- package/dist/web/assets/{dagre-VZM6K2ZE-CcmbgD8y.js.map → dagre-VZM6K2ZE-BlKo0jE-.js.map} +1 -1
- package/dist/web/assets/{diagram-7IWD3JNH-BnuvXuOG.js → diagram-7IWD3JNH-DSyy73Pb.js} +2 -2
- package/dist/web/assets/{diagram-7IWD3JNH-BnuvXuOG.js.map → diagram-7IWD3JNH-DSyy73Pb.js.map} +1 -1
- package/dist/web/assets/{diagram-B4RE2ZJO-qN04fvc2.js → diagram-B4RE2ZJO-CsC5SVP0.js} +2 -2
- package/dist/web/assets/{diagram-B4RE2ZJO-qN04fvc2.js.map → diagram-B4RE2ZJO-CsC5SVP0.js.map} +1 -1
- package/dist/web/assets/{diagram-LBJQPF4R-MyFiPTsp.js → diagram-LBJQPF4R-ffHYgA61.js} +2 -2
- package/dist/web/assets/{diagram-LBJQPF4R-MyFiPTsp.js.map → diagram-LBJQPF4R-ffHYgA61.js.map} +1 -1
- package/dist/web/assets/{diagram-Q27KOJAE-D6KbyLDa.js → diagram-Q27KOJAE-DRQ5U-HA.js} +2 -2
- package/dist/web/assets/{diagram-Q27KOJAE-D6KbyLDa.js.map → diagram-Q27KOJAE-DRQ5U-HA.js.map} +1 -1
- package/dist/web/assets/{diagram-UB23O5K3-BYfEham2.js → diagram-UB23O5K3-Df8as1Sq.js} +2 -2
- package/dist/web/assets/{diagram-UB23O5K3-BYfEham2.js.map → diagram-UB23O5K3-Df8as1Sq.js.map} +1 -1
- package/dist/web/assets/{ebnfDiagram-BXEA7PRR-B2sQIaDq.js → ebnfDiagram-BXEA7PRR--Vtau0CL.js} +2 -2
- package/dist/web/assets/{ebnfDiagram-BXEA7PRR-B2sQIaDq.js.map → ebnfDiagram-BXEA7PRR--Vtau0CL.js.map} +1 -1
- package/dist/web/assets/{erDiagram-JOGREHBK-TTjrYibZ.js → erDiagram-JOGREHBK-Bu6NFMOj.js} +2 -2
- package/dist/web/assets/{erDiagram-JOGREHBK-TTjrYibZ.js.map → erDiagram-JOGREHBK-Bu6NFMOj.js.map} +1 -1
- package/dist/web/assets/{flowDiagram-UKHOOZJN-DBkhF11F.js → flowDiagram-UKHOOZJN-D88NgdSs.js} +2 -2
- package/dist/web/assets/{flowDiagram-UKHOOZJN-DBkhF11F.js.map → flowDiagram-UKHOOZJN-D88NgdSs.js.map} +1 -1
- package/dist/web/assets/{ganttDiagram-PKOTCBZU-CZhiXP06.js → ganttDiagram-PKOTCBZU-CsIQ1Pkj.js} +2 -2
- package/dist/web/assets/{ganttDiagram-PKOTCBZU-CZhiXP06.js.map → ganttDiagram-PKOTCBZU-CsIQ1Pkj.js.map} +1 -1
- package/dist/web/assets/{gitGraphDiagram-DS77QQ5N-DY6N0imD.js → gitGraphDiagram-DS77QQ5N-h5Nf8R7y.js} +2 -2
- package/dist/web/assets/{gitGraphDiagram-DS77QQ5N-DY6N0imD.js.map → gitGraphDiagram-DS77QQ5N-h5Nf8R7y.js.map} +1 -1
- package/dist/web/assets/{index-2K1tlrb7.js → index-cWVvKFp5.js} +3 -3
- package/dist/web/assets/{index-2K1tlrb7.js.map → index-cWVvKFp5.js.map} +1 -1
- package/dist/web/assets/{infoDiagram-6WML65LV-A8svJtko.js → infoDiagram-6WML65LV-DZej-R2F.js} +2 -2
- package/dist/web/assets/{infoDiagram-6WML65LV-A8svJtko.js.map → infoDiagram-6WML65LV-DZej-R2F.js.map} +1 -1
- package/dist/web/assets/{ishikawaDiagram-WSZJBQD7-B_fUtCK4.js → ishikawaDiagram-WSZJBQD7-DSnr8b77.js} +2 -2
- package/dist/web/assets/{ishikawaDiagram-WSZJBQD7-B_fUtCK4.js.map → ishikawaDiagram-WSZJBQD7-DSnr8b77.js.map} +1 -1
- package/dist/web/assets/{journeyDiagram-NVQOT4AX-CznRCnfr.js → journeyDiagram-NVQOT4AX-ItalVAlK.js} +2 -2
- package/dist/web/assets/{journeyDiagram-NVQOT4AX-CznRCnfr.js.map → journeyDiagram-NVQOT4AX-ItalVAlK.js.map} +1 -1
- package/dist/web/assets/{jsQR-Bf0UGUa9.js → jsQR-C_F4GL5i.js} +2 -2
- package/dist/web/assets/{jsQR-Bf0UGUa9.js.map → jsQR-C_F4GL5i.js.map} +1 -1
- package/dist/web/assets/{kanban-definition-27J2QSJJ-DWDbR8YK.js → kanban-definition-27J2QSJJ-CdEY4YFZ.js} +2 -2
- package/dist/web/assets/{kanban-definition-27J2QSJJ-DWDbR8YK.js.map → kanban-definition-27J2QSJJ-CdEY4YFZ.js.map} +1 -1
- package/dist/web/assets/{linear-v3DKup6r.js → linear-g9GymkVk.js} +2 -2
- package/dist/web/assets/{linear-v3DKup6r.js.map → linear-g9GymkVk.js.map} +1 -1
- package/dist/web/assets/{mermaid.core-DFaFLwYZ.js → mermaid.core-DhIQAWlJ.js} +5 -5
- package/dist/web/assets/{mermaid.core-DFaFLwYZ.js.map → mermaid.core-DhIQAWlJ.js.map} +1 -1
- package/dist/web/assets/{mindmap-definition-FAOFIHXS-WlyKZ1qh.js → mindmap-definition-FAOFIHXS-Bx8rT8q4.js} +2 -2
- package/dist/web/assets/{mindmap-definition-FAOFIHXS-WlyKZ1qh.js.map → mindmap-definition-FAOFIHXS-Bx8rT8q4.js.map} +1 -1
- package/dist/web/assets/{pegDiagram-VL7TDLO6-J8XQMbkI.js → pegDiagram-VL7TDLO6-BN0BZuRg.js} +2 -2
- package/dist/web/assets/{pegDiagram-VL7TDLO6-J8XQMbkI.js.map → pegDiagram-VL7TDLO6-BN0BZuRg.js.map} +1 -1
- package/dist/web/assets/{pieDiagram-7S7Q4E2Y-Y6kKLO8X.js → pieDiagram-7S7Q4E2Y-C5gwicTb.js} +2 -2
- package/dist/web/assets/{pieDiagram-7S7Q4E2Y-Y6kKLO8X.js.map → pieDiagram-7S7Q4E2Y-C5gwicTb.js.map} +1 -1
- package/dist/web/assets/{quadrantDiagram-CIZ2JOQS-C75AhFwr.js → quadrantDiagram-CIZ2JOQS-Bmf5MRQA.js} +2 -2
- package/dist/web/assets/{quadrantDiagram-CIZ2JOQS-C75AhFwr.js.map → quadrantDiagram-CIZ2JOQS-Bmf5MRQA.js.map} +1 -1
- package/dist/web/assets/{railroadDiagram-AXF67PYL-tU0Z34Hp.js → railroadDiagram-AXF67PYL-DBvQYPes.js} +2 -2
- package/dist/web/assets/{railroadDiagram-AXF67PYL-tU0Z34Hp.js.map → railroadDiagram-AXF67PYL-DBvQYPes.js.map} +1 -1
- package/dist/web/assets/{requirementDiagram-LRYGKXZP-BCC1SaAL.js → requirementDiagram-LRYGKXZP-DO4US4yM.js} +2 -2
- package/dist/web/assets/{requirementDiagram-LRYGKXZP-BCC1SaAL.js.map → requirementDiagram-LRYGKXZP-DO4US4yM.js.map} +1 -1
- package/dist/web/assets/{sankeyDiagram-W5VNT64P-TyaWRXVE.js → sankeyDiagram-W5VNT64P-vx2ZHnTB.js} +2 -2
- package/dist/web/assets/{sankeyDiagram-W5VNT64P-TyaWRXVE.js.map → sankeyDiagram-W5VNT64P-vx2ZHnTB.js.map} +1 -1
- package/dist/web/assets/{sequenceDiagram-SI44F4Z6-DMfSW_GK.js → sequenceDiagram-SI44F4Z6-HdMQr-FA.js} +2 -2
- package/dist/web/assets/{sequenceDiagram-SI44F4Z6-DMfSW_GK.js.map → sequenceDiagram-SI44F4Z6-HdMQr-FA.js.map} +1 -1
- package/dist/web/assets/{sizeCapture-X5ZJPWSS-CGk_4Pap.js → sizeCapture-X5ZJPWSS-BpHkMIy3.js} +2 -2
- package/dist/web/assets/{sizeCapture-X5ZJPWSS-CGk_4Pap.js.map → sizeCapture-X5ZJPWSS-BpHkMIy3.js.map} +1 -1
- package/dist/web/assets/{stateDiagram-OKZ733FA-BcV5L0Yw.js → stateDiagram-OKZ733FA-CsqUc3WB.js} +2 -2
- package/dist/web/assets/{stateDiagram-OKZ733FA-BcV5L0Yw.js.map → stateDiagram-OKZ733FA-CsqUc3WB.js.map} +1 -1
- package/dist/web/assets/stateDiagram-v2-UEYNNEHI-DaUn2Cqz.js +2 -0
- package/dist/web/assets/{stateDiagram-v2-UEYNNEHI-Bl46jJlT.js.map → stateDiagram-v2-UEYNNEHI-DaUn2Cqz.js.map} +1 -1
- package/dist/web/assets/{swimlanes-SLNWSIFB-qPeYgkYp.js → swimlanes-SLNWSIFB-DfXFY7nI.js} +3 -3
- package/dist/web/assets/{swimlanes-SLNWSIFB-qPeYgkYp.js.map → swimlanes-SLNWSIFB-DfXFY7nI.js.map} +1 -1
- package/dist/web/assets/swimlanesDiagram-ULZ7WXOC-BPObaxCO.js +9 -0
- package/dist/web/assets/{swimlanesDiagram-ULZ7WXOC-DImmVV5Y.js.map → swimlanesDiagram-ULZ7WXOC-BPObaxCO.js.map} +1 -1
- package/dist/web/assets/{timeline-definition-Z64GVDOM-DK8nOg_7.js → timeline-definition-Z64GVDOM-DWLl9YDZ.js} +2 -2
- package/dist/web/assets/{timeline-definition-Z64GVDOM-DK8nOg_7.js.map → timeline-definition-Z64GVDOM-DWLl9YDZ.js.map} +1 -1
- package/dist/web/assets/{vennDiagram-T6HMQDX7-gPw7k48o.js → vennDiagram-T6HMQDX7-D2aFHygB.js} +2 -2
- package/dist/web/assets/{vennDiagram-T6HMQDX7-gPw7k48o.js.map → vennDiagram-T6HMQDX7-D2aFHygB.js.map} +1 -1
- package/dist/web/assets/{wardleyDiagram-T6FBY63Y-DuSm8bGc.js → wardleyDiagram-T6FBY63Y-CKkdjvhY.js} +2 -2
- package/dist/web/assets/{wardleyDiagram-T6FBY63Y-DuSm8bGc.js.map → wardleyDiagram-T6FBY63Y-CKkdjvhY.js.map} +1 -1
- package/dist/web/assets/{xychartDiagram-ELKLHX3M-CWypWmMd.js → xychartDiagram-ELKLHX3M-Cjf6Fex6.js} +2 -2
- package/dist/web/assets/{xychartDiagram-ELKLHX3M-CWypWmMd.js.map → xychartDiagram-ELKLHX3M-Cjf6Fex6.js.map} +1 -1
- package/dist/web/index.html +1 -1
- package/dist/web/sw.js +1 -1
- package/dist/web/version.json +1 -1
- package/package.json +1 -1
- package/dist/web/assets/channel-dW2gWx3T.js +0 -2
- package/dist/web/assets/classDiagram-JCYQIIEL-qy_NR-tD.js +0 -2
- package/dist/web/assets/classDiagram-v2-OCEON4UE-qy_NR-tD.js +0 -2
- package/dist/web/assets/stateDiagram-v2-UEYNNEHI-Bl46jJlT.js +0 -2
- package/dist/web/assets/swimlanesDiagram-ULZ7WXOC-DImmVV5Y.js +0 -9
|
@@ -315,7 +315,7 @@ ${l.join(`
|
|
|
315
315
|
`});++i<e.length;)i&&n.push({type:"text",value:`
|
|
316
316
|
`}),n.push(e[i]);return t&&e.length>0&&n.push({type:"text",value:`
|
|
317
317
|
`}),n}function sx(e){let t=0,n=e.charCodeAt(t);for(;n===9||n===32;)t++,n=e.charCodeAt(t);return e.slice(t)}function ax(e,t){const n=BO(e,t),i=n.one(e,void 0),s=zO(n),l=Array.isArray(i)?{type:"root",children:i}:i||{type:"root",children:[]};return s&&l.children.push({type:"text",value:`
|
|
318
|
-
`},s),l}function KO(e,t){return e&&"run"in e?async function(n,i){const s=ax(n,{file:i,...t});await e.run(s,i)}:function(n,i){return ax(n,{file:i,...e||t})}}function lx(e){if(e)throw e}var yf,ux;function qO(){if(ux)return yf;ux=1;var e=Object.prototype.hasOwnProperty,t=Object.prototype.toString,n=Object.defineProperty,i=Object.getOwnPropertyDescriptor,s=function(h){return typeof Array.isArray=="function"?Array.isArray(h):t.call(h)==="[object Array]"},l=function(h){if(!h||t.call(h)!=="[object Object]")return!1;var m=e.call(h,"constructor"),p=h.constructor&&h.constructor.prototype&&e.call(h.constructor.prototype,"isPrototypeOf");if(h.constructor&&!m&&!p)return!1;var y;for(y in h);return typeof y>"u"||e.call(h,y)},a=function(h,m){n&&m.name==="__proto__"?n(h,m.name,{enumerable:!0,configurable:!0,value:m.newValue,writable:!0}):h[m.name]=m.newValue},c=function(h,m){if(m==="__proto__")if(e.call(h,m)){if(i)return i(h,m).value}else return;return h[m]};return yf=function d(){var h,m,p,y,w,S,C=arguments[0],E=1,T=arguments.length,M=!1;for(typeof C=="boolean"&&(M=C,C=arguments[1]||{},E=2),(C==null||typeof C!="object"&&typeof C!="function")&&(C={});E<T;++E)if(h=arguments[E],h!=null)for(m in h)p=c(C,m),y=c(h,m),C!==y&&(M&&y&&(l(y)||(w=s(y)))?(w?(w=!1,S=p&&s(p)?p:[]):S=p&&l(p)?p:{},a(C,{name:m,newValue:d(M,S,y)})):typeof y<"u"&&a(C,{name:m,newValue:y}));return C},yf}var XO=qO();const vf=Id(XO);function Pd(e){if(typeof e!="object"||e===null)return!1;const t=Object.getPrototypeOf(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Symbol.toStringTag in e)&&!(Symbol.iterator in e)}function YO(){const e=[],t={run:n,use:i};return t;function n(...s){let l=-1;const a=s.pop();if(typeof a!="function")throw new TypeError("Expected function as last argument, not "+a);c(null,...s);function c(d,...h){const m=e[++l];let p=-1;if(d){a(d);return}for(;++p<s.length;)(h[p]===null||h[p]===void 0)&&(h[p]=s[p]);s=h,m?GO(m,c)(...h):a(null,...h)}}function i(s){if(typeof s!="function")throw new TypeError("Expected `middelware` to be a function, not "+s);return e.push(s),t}}function GO(e,t){let n;return i;function i(...a){const c=e.length>a.length;let d;c&&a.push(s);try{d=e.apply(this,a)}catch(h){const m=h;if(c&&n)throw m;return s(m)}c||(d&&d.then&&typeof d.then=="function"?d.then(l,s):d instanceof Error?s(d):l(d))}function s(a,...c){n||(n=!0,t(a,...c))}function l(a){s(null,a)}}const Un={basename:QO,dirname:ZO,extname:JO,join:eF,sep:"/"};function QO(e,t){if(t!==void 0&&typeof t!="string")throw new TypeError('"ext" argument must be a string');js(e);let n=0,i=-1,s=e.length,l;if(t===void 0||t.length===0||t.length>e.length){for(;s--;)if(e.codePointAt(s)===47){if(l){n=s+1;break}}else i<0&&(l=!0,i=s+1);return i<0?"":e.slice(n,i)}if(t===e)return"";let a=-1,c=t.length-1;for(;s--;)if(e.codePointAt(s)===47){if(l){n=s+1;break}}else a<0&&(l=!0,a=s+1),c>-1&&(e.codePointAt(s)===t.codePointAt(c--)?c<0&&(i=s):(c=-1,i=a));return n===i?i=a:i<0&&(i=e.length),e.slice(n,i)}function ZO(e){if(js(e),e.length===0)return".";let t=-1,n=e.length,i;for(;--n;)if(e.codePointAt(n)===47){if(i){t=n;break}}else i||(i=!0);return t<0?e.codePointAt(0)===47?"/":".":t===1&&e.codePointAt(0)===47?"//":e.slice(0,t)}function JO(e){js(e);let t=e.length,n=-1,i=0,s=-1,l=0,a;for(;t--;){const c=e.codePointAt(t);if(c===47){if(a){i=t+1;break}continue}n<0&&(a=!0,n=t+1),c===46?s<0?s=t:l!==1&&(l=1):s>-1&&(l=-1)}return s<0||n<0||l===0||l===1&&s===n-1&&s===i+1?"":e.slice(s,n)}function eF(...e){let t=-1,n;for(;++t<e.length;)js(e[t]),e[t]&&(n=n===void 0?e[t]:n+"/"+e[t]);return n===void 0?".":tF(n)}function tF(e){js(e);const t=e.codePointAt(0)===47;let n=nF(e,!t);return n.length===0&&!t&&(n="."),n.length>0&&e.codePointAt(e.length-1)===47&&(n+="/"),t?"/"+n:n}function nF(e,t){let n="",i=0,s=-1,l=0,a=-1,c,d;for(;++a<=e.length;){if(a<e.length)c=e.codePointAt(a);else{if(c===47)break;c=47}if(c===47){if(!(s===a-1||l===1))if(s!==a-1&&l===2){if(n.length<2||i!==2||n.codePointAt(n.length-1)!==46||n.codePointAt(n.length-2)!==46){if(n.length>2){if(d=n.lastIndexOf("/"),d!==n.length-1){d<0?(n="",i=0):(n=n.slice(0,d),i=n.length-1-n.lastIndexOf("/")),s=a,l=0;continue}}else if(n.length>0){n="",i=0,s=a,l=0;continue}}t&&(n=n.length>0?n+"/..":"..",i=2)}else n.length>0?n+="/"+e.slice(s+1,a):n=e.slice(s+1,a),i=a-s-1;s=a,l=0}else c===46&&l>-1?l++:l=-1}return n}function js(e){if(typeof e!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(e))}const rF={cwd:iF};function iF(){return"/"}function Rd(e){return!!(e!==null&&typeof e=="object"&&"href"in e&&e.href&&"protocol"in e&&e.protocol&&e.auth===void 0)}function oF(e){if(typeof e=="string")e=new URL(e);else if(!Rd(e)){const t=new TypeError('The "path" argument must be of type string or an instance of URL. Received `'+e+"`");throw t.code="ERR_INVALID_ARG_TYPE",t}if(e.protocol!=="file:"){const t=new TypeError("The URL must be of scheme file");throw t.code="ERR_INVALID_URL_SCHEME",t}return sF(e)}function sF(e){if(e.hostname!==""){const i=new TypeError('File URL host must be "localhost" or empty on darwin');throw i.code="ERR_INVALID_FILE_URL_HOST",i}const t=e.pathname;let n=-1;for(;++n<t.length;)if(t.codePointAt(n)===37&&t.codePointAt(n+1)===50){const i=t.codePointAt(n+2);if(i===70||i===102){const s=new TypeError("File URL path must not include encoded / characters");throw s.code="ERR_INVALID_FILE_URL_PATH",s}}return decodeURIComponent(t)}const xf=["history","path","basename","stem","extname","dirname"];class Fk{constructor(t){let n;t?Rd(t)?n={path:t}:typeof t=="string"||aF(t)?n={value:t}:n=t:n={},this.cwd="cwd"in n?"":rF.cwd(),this.data={},this.history=[],this.messages=[],this.value,this.map,this.result,this.stored;let i=-1;for(;++i<xf.length;){const l=xf[i];l in n&&n[l]!==void 0&&n[l]!==null&&(this[l]=l==="history"?[...n[l]]:n[l])}let s;for(s in n)xf.includes(s)||(this[s]=n[s])}get basename(){return typeof this.path=="string"?Un.basename(this.path):void 0}set basename(t){kf(t,"basename"),wf(t,"basename"),this.path=Un.join(this.dirname||"",t)}get dirname(){return typeof this.path=="string"?Un.dirname(this.path):void 0}set dirname(t){cx(this.basename,"dirname"),this.path=Un.join(t||"",this.basename)}get extname(){return typeof this.path=="string"?Un.extname(this.path):void 0}set extname(t){if(wf(t,"extname"),cx(this.dirname,"extname"),t){if(t.codePointAt(0)!==46)throw new Error("`extname` must start with `.`");if(t.includes(".",1))throw new Error("`extname` cannot contain multiple dots")}this.path=Un.join(this.dirname,this.stem+(t||""))}get path(){return this.history[this.history.length-1]}set path(t){Rd(t)&&(t=oF(t)),kf(t,"path"),this.path!==t&&this.history.push(t)}get stem(){return typeof this.path=="string"?Un.basename(this.path,this.extname):void 0}set stem(t){kf(t,"stem"),wf(t,"stem"),this.path=Un.join(this.dirname||"",t+(this.extname||""))}fail(t,n,i){const s=this.message(t,n,i);throw s.fatal=!0,s}info(t,n,i){const s=this.message(t,n,i);return s.fatal=void 0,s}message(t,n,i){const s=new zt(t,n,i);return this.path&&(s.name=this.path+":"+s.name,s.file=this.path),s.fatal=!1,this.messages.push(s),s}toString(t){return this.value===void 0?"":typeof this.value=="string"?this.value:new TextDecoder(t||void 0).decode(this.value)}}function wf(e,t){if(e&&e.includes(Un.sep))throw new Error("`"+t+"` cannot be a path: did not expect `"+Un.sep+"`")}function kf(e,t){if(!e)throw new Error("`"+t+"` cannot be empty")}function cx(e,t){if(!e)throw new Error("Setting `"+t+"` requires `path` to be set too")}function aF(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const lF=function(e){const i=this.constructor.prototype,s=i[e],l=function(){return s.apply(l,arguments)};return Object.setPrototypeOf(l,i),l},uF={}.hasOwnProperty;class Wh extends lF{constructor(){super("copy"),this.Compiler=void 0,this.Parser=void 0,this.attachers=[],this.compiler=void 0,this.freezeIndex=-1,this.frozen=void 0,this.namespace={},this.parser=void 0,this.transformers=YO()}copy(){const t=new Wh;let n=-1;for(;++n<this.attachers.length;){const i=this.attachers[n];t.use(...i)}return t.data(vf(!0,{},this.namespace)),t}data(t,n){return typeof t=="string"?arguments.length===2?(Cf("data",this.frozen),this.namespace[t]=n,this):uF.call(this.namespace,t)&&this.namespace[t]||void 0:t?(Cf("data",this.frozen),this.namespace=t,this):this.namespace}freeze(){if(this.frozen)return this;const t=this;for(;++this.freezeIndex<this.attachers.length;){const[n,...i]=this.attachers[this.freezeIndex];if(i[0]===!1)continue;i[0]===!0&&(i[0]=void 0);const s=n.call(t,...i);typeof s=="function"&&this.transformers.use(s)}return this.frozen=!0,this.freezeIndex=Number.POSITIVE_INFINITY,this}parse(t){this.freeze();const n=rl(t),i=this.parser||this.Parser;return Sf("parse",i),i(String(n),n)}process(t,n){const i=this;return this.freeze(),Sf("process",this.parser||this.Parser),bf("process",this.compiler||this.Compiler),n?s(void 0,n):new Promise(s);function s(l,a){const c=rl(t),d=i.parse(c);i.run(d,c,function(m,p,y){if(m||!p||!y)return h(m);const w=p,S=i.stringify(w,y);dF(S)?y.value=S:y.result=S,h(m,y)});function h(m,p){m||!p?a(m):l?l(p):n(void 0,p)}}}processSync(t){let n=!1,i;return this.freeze(),Sf("processSync",this.parser||this.Parser),bf("processSync",this.compiler||this.Compiler),this.process(t,s),dx("processSync","process",n),i;function s(l,a){n=!0,lx(l),i=a}}run(t,n,i){fx(t),this.freeze();const s=this.transformers;return!i&&typeof n=="function"&&(i=n,n=void 0),i?l(void 0,i):new Promise(l);function l(a,c){const d=rl(n);s.run(t,d,h);function h(m,p,y){const w=p||t;m?c(m):a?a(w):i(void 0,w,y)}}}runSync(t,n){let i=!1,s;return this.run(t,n,l),dx("runSync","run",i),s;function l(a,c){lx(a),s=c,i=!0}}stringify(t,n){this.freeze();const i=rl(n),s=this.compiler||this.Compiler;return bf("stringify",s),fx(t),s(t,i)}use(t,...n){const i=this.attachers,s=this.namespace;if(Cf("use",this.frozen),t!=null)if(typeof t=="function")d(t,n);else if(typeof t=="object")Array.isArray(t)?c(t):a(t);else throw new TypeError("Expected usable value, not `"+t+"`");return this;function l(h){if(typeof h=="function")d(h,[]);else if(typeof h=="object")if(Array.isArray(h)){const[m,...p]=h;d(m,p)}else a(h);else throw new TypeError("Expected usable value, not `"+h+"`")}function a(h){if(!("plugins"in h)&&!("settings"in h))throw new Error("Expected usable value but received an empty preset, which is probably a mistake: presets typically come with `plugins` and sometimes with `settings`, but this has neither");c(h.plugins),h.settings&&(s.settings=vf(!0,s.settings,h.settings))}function c(h){let m=-1;if(h!=null)if(Array.isArray(h))for(;++m<h.length;){const p=h[m];l(p)}else throw new TypeError("Expected a list of plugins, not `"+h+"`")}function d(h,m){let p=-1,y=-1;for(;++p<i.length;)if(i[p][0]===h){y=p;break}if(y===-1)i.push([h,...m]);else if(m.length>0){let[w,...S]=m;const C=i[y][1];Pd(C)&&Pd(w)&&(w=vf(!0,C,w)),i[y]=[h,w,...S]}}}}const cF=new Wh().freeze();function Sf(e,t){if(typeof t!="function")throw new TypeError("Cannot `"+e+"` without `parser`")}function bf(e,t){if(typeof t!="function")throw new TypeError("Cannot `"+e+"` without `compiler`")}function Cf(e,t){if(t)throw new Error("Cannot call `"+e+"` on a frozen processor.\nCreate a new processor first, by calling it: use `processor()` instead of `processor`.")}function fx(e){if(!Pd(e)||typeof e.type!="string")throw new TypeError("Expected node, got `"+e+"`")}function dx(e,t,n){if(!n)throw new Error("`"+e+"` finished async. Use `"+t+"` instead")}function rl(e){return fF(e)?e:new Fk(e)}function fF(e){return!!(e&&typeof e=="object"&&"message"in e&&"messages"in e)}function dF(e){return typeof e=="string"||hF(e)}function hF(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const pF="https://github.com/remarkjs/react-markdown/blob/main/changelog.md",hx=[],px={allowDangerousHtml:!0},mF=/^(https?|ircs?|mailto|xmpp)$/i,gF=[{from:"astPlugins",id:"remove-buggy-html-in-markdown-parser"},{from:"allowDangerousHtml",id:"remove-buggy-html-in-markdown-parser"},{from:"allowNode",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"allowElement"},{from:"allowedTypes",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"allowedElements"},{from:"className",id:"remove-classname"},{from:"disallowedTypes",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"disallowedElements"},{from:"escapeHtml",id:"remove-buggy-html-in-markdown-parser"},{from:"includeElementIndex",id:"#remove-includeelementindex"},{from:"includeNodeIndex",id:"change-includenodeindex-to-includeelementindex"},{from:"linkTarget",id:"remove-linktarget"},{from:"plugins",id:"change-plugins-to-remarkplugins",to:"remarkPlugins"},{from:"rawSourcePos",id:"#remove-rawsourcepos"},{from:"renderers",id:"change-renderers-to-components",to:"components"},{from:"source",id:"change-source-to-children",to:"children"},{from:"sourcePos",id:"#remove-sourcepos"},{from:"transformImageUri",id:"#add-urltransform",to:"urlTransform"},{from:"transformLinkUri",id:"#add-urltransform",to:"urlTransform"}];function zk(e){const t=yF(e),n=vF(e);return xF(t.runSync(t.parse(n),n),e)}function yF(e){const t=e.rehypePlugins||hx,n=e.remarkPlugins||hx,i=e.remarkRehypeOptions?{...e.remarkRehypeOptions,...px}:px;return cF().use(sO).use(n).use(KO,i).use(t)}function vF(e){const t=e.children||"",n=new Fk;return typeof t=="string"&&(n.value=t),n}function xF(e,t){const n=t.allowedElements,i=t.allowElement,s=t.components,l=t.disallowedElements,a=t.skipHtml,c=t.unwrapDisallowed,d=t.urlTransform||wF;for(const m of gF)Object.hasOwn(t,m.from)&&(""+m.from+(m.to?"use `"+m.to+"` instead":"remove it")+pF+m.id,void 0);return ph(e,h),WL(e,{Fragment:v.Fragment,components:s,ignoreInvalidStyle:!0,jsx:v.jsx,jsxs:v.jsxs,passKeys:!0,passNode:!0});function h(m,p,y){if(m.type==="raw"&&y&&typeof p=="number")return a?y.children.splice(p,1):y.children[p]={type:"text",value:m.value},p;if(m.type==="element"){let w;for(w in gf)if(Object.hasOwn(gf,w)&&Object.hasOwn(m.properties,w)){const S=m.properties[w],C=gf[w];(C===null||C.includes(m.tagName))&&(m.properties[w]=d(String(S||""),w,m))}}if(m.type==="element"){let w=n?!n.includes(m.tagName):l?l.includes(m.tagName):!1;if(!w&&i&&typeof p=="number"&&(w=!i(m,p,y)),w&&y&&typeof p=="number")return c&&m.children?y.children.splice(p,1,...m.children):y.children.splice(p,1),p}}}function wF(e){const t=e.indexOf(":"),n=e.indexOf("?"),i=e.indexOf("#"),s=e.indexOf("/");return t===-1||s!==-1&&t>s||n!==-1&&t>n||i!==-1&&t>i||mF.test(e.slice(0,t))?e:""}const kF={};function Vk(e){const t=this,n=e||kF,i=t.data(),s=i.micromarkExtensions||(i.micromarkExtensions=[]),l=i.fromMarkdownExtensions||(i.fromMarkdownExtensions=[]),a=i.toMarkdownExtensions||(i.toMarkdownExtensions=[]);s.push(f1(n)),l.push(U0()),a.push(RN(n))}function Ds(e){const t=k.useRef(null);return k.useEffect(()=>(t.current=document.activeElement instanceof HTMLElement?document.activeElement:null,()=>{const n=t.current;n?.isConnected&&requestAnimationFrame(()=>n.focus())}),[]),v.jsx(uk,{open:!0,onOpenChange:n=>{n||e.onClose()},children:v.jsxs(dk,{children:[v.jsx(hk,{className:"modal-backdrop"}),v.jsxs(pk,{id:e.contentId,className:"modal"+(e.wide?" modal-wide":"")+(e.className?` ${e.className}`:""),children:[v.jsxs("div",{className:"modal-head",children:[v.jsxs("div",{children:[v.jsx(gk,{asChild:!0,children:v.jsx("h3",{children:e.title})}),e.description&&v.jsx(yk,{className:"modal-description",children:e.description})]}),v.jsx(vk,{asChild:!0,children:v.jsx("button",{className:"icon-btn","aria-label":`Close ${e.title}`,children:v.jsx(Ee,{name:"close"})})})]}),e.tabs,v.jsx("div",{className:"modal-body",children:e.children})]})]})})}const SF=.25,bF=8;let mx=Promise.resolve();function gx(){return document.documentElement.classList.contains("theme-dark")?"dark":"default"}function CF(){const[e,t]=k.useState(gx);return k.useEffect(()=>{const n=document.documentElement,i=()=>t(gx()),s=new MutationObserver(i);return s.observe(n,{attributes:!0,attributeFilter:["class"]}),i(),()=>s.disconnect()},[]),e}function EF(e,t,n){const i=mx.then(async()=>{const{default:s}=await Ch(async()=>{const{default:l}=await import("./mermaid.core-DFaFLwYZ.js").then(a=>a.bp);return{default:l}},[]);return s.initialize({startOnLoad:!1,securityLevel:"strict",theme:n,fontFamily:"var(--sans)"}),s.render(e,t)});return mx=i.then(()=>{},()=>{}),i}function TF(e){return Math.min(bF,Math.max(SF,e))}function PF(e){const t=k.useRef(null),n=k.useRef(null),[i,s]=k.useState(1),[l,a]=k.useState({x:0,y:0}),[c,d]=k.useState(!1),h=()=>{s(1),a({x:0,y:0})},m=(p,y,w)=>{const S=TF(p);if(S===i)return;const C=t.current?.getBoundingClientRect();if(C){const E=(y??C.left+C.width/2)-C.left-C.width/2,T=(w??C.top+C.height/2)-C.top-C.height/2,M=S/i;a(P=>({x:E-M*(E-P.x),y:T-M*(T-P.y)}))}s(S)};return k.useEffect(()=>{const p=y=>{y.key==="+"||y.key==="="?(y.preventDefault(),m(i*1.25)):y.key==="-"?(y.preventDefault(),m(i/1.25)):y.key==="0"&&(y.preventDefault(),h())};return window.addEventListener("keydown",p),()=>window.removeEventListener("keydown",p)}),v.jsx(uk,{open:!0,onOpenChange:p=>{p||e.onClose()},children:v.jsxs(dk,{children:[v.jsx(hk,{className:"mermaid-fullscreen-backdrop"}),v.jsxs(pk,{className:"mermaid-fullscreen","data-mermaid-theme":e.theme,"aria-describedby":"mermaid-fullscreen-help",children:[v.jsx(gk,{className:"mermaid-fullscreen-title",children:"Diagram viewer"}),v.jsxs("div",{className:"mermaid-fullscreen-tools",children:[v.jsx("button",{className:"icon-btn","aria-label":"Zoom out",title:"Zoom out (−)",onClick:()=>m(i/1.25),children:v.jsx(Ee,{name:"minus"})}),v.jsxs("button",{className:"mermaid-zoom-value",onClick:h,title:"Reset zoom and position",children:[Math.round(i*100),"%"]}),v.jsx("button",{className:"icon-btn","aria-label":"Zoom in",title:"Zoom in (+)",onClick:()=>m(i*1.25),children:v.jsx(Ee,{name:"plus"})}),v.jsx(vk,{asChild:!0,children:v.jsx("button",{className:"icon-btn","aria-label":"Close diagram viewer",title:"Close (Esc)",children:v.jsx(Ee,{name:"close"})})})]}),v.jsx("div",{ref:t,className:"mermaid-fullscreen-viewport"+(c?" dragging":""),onWheel:p=>{p.preventDefault(),m(i*Math.exp(-p.deltaY*.0015),p.clientX,p.clientY)},onDoubleClick:p=>m(i*1.5,p.clientX,p.clientY),onPointerDown:p=>{p.button===0&&(n.current={pointerId:p.pointerId,startX:p.clientX,startY:p.clientY,panX:l.x,panY:l.y},p.currentTarget.setPointerCapture(p.pointerId),d(!0))},onPointerMove:p=>{const y=n.current;!y||y.pointerId!==p.pointerId||a({x:y.panX+p.clientX-y.startX,y:y.panY+p.clientY-y.startY})},onPointerUp:p=>{n.current?.pointerId===p.pointerId&&(n.current=null,d(!1),p.currentTarget.releasePointerCapture(p.pointerId))},onPointerCancel:()=>{n.current=null,d(!1)},children:v.jsx("div",{className:"mermaid-fullscreen-canvas",style:{transform:`translate(${l.x}px, ${l.y}px) scale(${i})`},dangerouslySetInnerHTML:{__html:e.svg}})}),v.jsx(yk,{id:"mermaid-fullscreen-help",className:"mermaid-fullscreen-help",children:"Scroll to zoom · drag to move · double-click to zoom in"})]})]})})}function RF({source:e}){const t=k.useId(),[n,i]=k.useState(""),[s,l]=k.useState(""),[a,c]=k.useState("default"),[d,h]=k.useState(!1),m=CF();return k.useEffect(()=>{let p=!0;const y=`mermaid-${t.replace(/[^a-zA-Z0-9_-]/g,"")}`;return i(""),l(""),EF(y,e,m).then(w=>{p&&(c(m),i(w.svg))}).catch(w=>{p&&l(w instanceof Error?w.message:String(w))}),()=>{p=!1,document.getElementById(`d${y}`)?.remove()}},[t,e,m]),s?v.jsxs("pre",{className:"markdown-mermaid-error",children:["Mermaid error: ",s]}):n?v.jsxs(v.Fragment,{children:[v.jsxs("div",{className:"markdown-mermaid","data-mermaid-theme":a,children:[v.jsx("button",{className:"icon-btn markdown-mermaid-expand","aria-label":"View diagram fullscreen",title:"View diagram fullscreen",onClick:()=>h(!0),children:v.jsx(Ee,{name:"maximize"})}),v.jsx("div",{className:"markdown-mermaid-diagram",dangerouslySetInnerHTML:{__html:n}})]}),d&&v.jsx(PF,{svg:n,theme:a,onClose:()=>h(!1)})]}):v.jsx("div",{className:"markdown-mermaid-loading",children:"Rendering diagram…"})}const MF=k.memo(function(t){return v.jsx("article",{className:"markdown-body",ref:t.contentRef,children:v.jsx(zk,{remarkPlugins:[Vk],components:{a:({children:n,...i})=>v.jsx("a",{...i,target:"_blank",rel:"noreferrer",children:n}),code:({className:n,children:i,...s})=>{const l=/language-([\w-]+)/.exec(n??"")?.[1],a=String(i).replace(/\n$/,"");return l==="mermaid"?v.jsx(RF,{source:a}):v.jsx("code",{className:n,...s,children:i})}},children:t.markdown})})});function Bk(e){const{rec:t}=e,n=k.useRef(null),[i,s]=k.useState(""),[l,a]=k.useState(null),[c,d]=k.useState("loading"),[h,m]=k.useState(""),[p,y]=k.useState(0),[w,S]=k.useState(""),[C,E]=k.useState(0),[T,M]=k.useState(!1),[P,D]=k.useState(""),[$,j]=k.useState(!1),[Y,U]=k.useState(!1),[O,N]=k.useState([]),[X,V]=k.useState(!1),[fe,J]=k.useState(null),[ee,xe]=k.useState(!1),[Pe,Q]=k.useState("");k.useEffect(()=>{let A=!0,te=null;return d("loading"),Ul(t.id).then(ge=>{if(A){if(!ge){d("missing");return}s(new TextDecoder("utf-8").decode(ge)),te=URL.createObjectURL(new Blob([ge],{type:"text/markdown;charset=utf-8"})),a(te),d("ready")}}).catch(()=>{A&&d("error")}),()=>{A=!1,te&&URL.revokeObjectURL(te)}},[t.id]),k.useEffect(()=>{const A=()=>{const te=window.getSelection(),ge=n.current;if(!te||te.isCollapsed||!ge){m(""),y(0);return}if(!ge.contains(te.anchorNode)||!ge.contains(te.focusNode)){m(""),y(0);return}const ye=te.getRangeAt(0),me=te.toString(),we=me.length-me.trimStart().length,pe=me.trim().slice(0,4e3),Ve=document.createRange();Ve.selectNodeContents(ge),Ve.setEnd(ye.startContainer,ye.startOffset);const qe=Ve.toString().length+we;m(pe),y(eD(ge.textContent,pe,qe))};return document.addEventListener("selectionchange",A),()=>document.removeEventListener("selectionchange",A)},[]);const de=()=>{h&&(S(h),E(p),M(!0),Q(""))},R=async()=>{if(Y){if(!w||!P.trim())return;N(te=>[...te,{selection:w,comment:P.trim(),occurrence:C}]),D(""),M(!1),Q("Comment added to review");return}const A=Zj(w,P);if(!(!A||!P.trim()||$)){j(!0),Q("");try{await e.onSendText(A,t.id||void 0),D(""),M(!1),Q("Feedback sent")}catch(te){Q(`Send failed: ${String(te)}`)}finally{j(!1)}}},F=async()=>{if(O.length===0||X)return;const A=sD(i,O);V(!0),Q("");try{e.onSendFile?await e.onSendFile({filename:Jj(t.filename),mime:"text/markdown",bytes:new TextEncoder().encode(A)},t.id||void 0):await e.onSendText(A,t.id||void 0),N([]),U(!1),Q("Review submitted")}catch(te){Q(`Review send failed: ${String(te)}`)}finally{V(!1)}},G=async()=>{if(!(!fe||!e.onSendFile||ee)){xe(!0),Q("");try{await e.onSendFile(fe,t.id||void 0),J(null),Q("Voice feedback sent")}catch(A){Q(`Voice send failed: ${String(A)}`)}finally{xe(!1)}}};return v.jsx(Ds,{title:t.filename,description:"Markdown preview · select text to send precise feedback",onClose:e.onClose,wide:!0,className:"markdown-modal",children:v.jsxs("div",{className:"markdown-preview",children:[v.jsxs("div",{className:"markdown-review-toolbar",children:[v.jsxs("button",{className:"btn sm",disabled:!h,onMouseDown:A=>A.preventDefault(),onClick:de,children:[v.jsx(Ee,{name:"reply",size:14}),Y?"Add review comment":"Quick message",h?` (${h.length})`:""]}),Y?v.jsx("button",{className:"btn sm",onClick:()=>{U(!1),N([]),M(!1),Q("Review discarded")},children:"Cancel review"}):v.jsxs("button",{className:"btn sm",onClick:()=>{U(!0),N([]),Q("Review started — select passages to add comments")},children:[v.jsx(Ee,{name:"edit",size:14}),"Start review"]}),l&&v.jsxs("a",{className:"btn sm",href:l,download:t.filename,children:[v.jsx(Ee,{name:"download",size:14}),"Download"]}),e.onSendFile&&v.jsx(k1,{disabled:!!fe||ee,onReady:J,onError:Q}),v.jsx("span",{className:"markdown-review-hint",children:h?"Selection ready for feedback":"Highlight any passage to comment on it"})]}),T&&v.jsxs("div",{className:"markdown-feedback",children:[v.jsx("blockquote",{children:w}),v.jsx("textarea",{className:"field",rows:3,autoFocus:!0,placeholder:"What should change?",value:P,onChange:A=>D(A.target.value)}),v.jsxs("div",{className:"markdown-feedback-actions",children:[v.jsx("button",{className:"btn sm",onClick:()=>M(!1),children:"Cancel"}),v.jsxs("button",{className:"btn sm primary",disabled:!P.trim()||$,onClick:()=>void R(),children:[v.jsx(Ee,{name:"send",size:14}),Y?"Add to review":$?"Sending…":"Send feedback"]})]})]}),Y&&v.jsxs("div",{className:"markdown-review-draft",children:[v.jsxs("div",{className:"markdown-review-draft-head",children:[v.jsxs("strong",{children:["Review · ",O.length," comment",O.length===1?"":"s"]}),v.jsxs("button",{className:"btn sm primary",disabled:O.length===0||X,onClick:()=>void F(),children:[v.jsx(Ee,{name:"send",size:14}),X?"Submitting…":"Submit review"]})]}),O.map((A,te)=>v.jsxs("div",{className:"markdown-review-comment",children:[v.jsx("span",{children:te+1}),v.jsxs("div",{children:[v.jsx("blockquote",{children:A.selection}),v.jsx("p",{children:A.comment})]}),v.jsx("button",{className:"icon-btn",title:"Remove comment",onClick:()=>N(ge=>ge.filter((ye,me)=>me!==te)),children:v.jsx(Ee,{name:"close",size:14})})]},`${te}-${A.selection.slice(0,24)}`))]}),fe&&v.jsx(w1,{att:fe,sending:ee,onSend:()=>void G(),onDiscard:()=>J(null)}),Pe&&v.jsx("div",{className:"markdown-review-status",role:"status",children:Pe}),v.jsxs("div",{className:"markdown-preview-scroll",children:[c==="loading"&&v.jsx("div",{className:"markdown-empty",children:"Loading preview…"}),c==="missing"&&v.jsx("div",{className:"markdown-empty",children:"This file is available on the original device only."}),c==="error"&&v.jsx("div",{className:"markdown-empty",children:"The file could not be opened."}),c==="ready"&&v.jsx(MF,{markdown:i,contentRef:n})]})]})})}function $k(e){const{rec:t}=e,[n,i]=k.useState(null),[s,l]=k.useState(0),[a,c]=k.useState("loading");return k.useEffect(()=>{let d=!0,h=null;return c("loading"),Ul(t.id).then(m=>{if(d){if(!m){c("missing");return}l(m.byteLength),h=URL.createObjectURL(new Blob([m],{type:wh(t.mime,t.filename)})),i(h),c("ready")}}).catch(()=>{d&&c("error")}),()=>{d=!1,h&&URL.revokeObjectURL(h)}},[t.id,t.mime,t.filename]),v.jsx(Ds,{title:t.filename,description:"Transformed safe preview · external navigation disabled",onClose:e.onClose,wide:!0,className:"markdown-modal html-modal",children:v.jsxs("div",{className:"html-preview",children:[v.jsxs("div",{className:"html-preview-toolbar",children:[v.jsxs("span",{className:"html-preview-shield",children:[v.jsx(Ee,{name:"shield",size:14}),"Scripts, forms and network requests are blocked"]}),n&&v.jsxs("a",{className:"btn sm",href:n,download:t.filename,children:[v.jsx(Ee,{name:"download",size:14}),"Download original",s?` · ${Fr(s)}`:""]})]}),v.jsxs("div",{className:"html-preview-frame",children:[a==="loading"&&v.jsx("div",{className:"markdown-empty",children:"Loading preview…"}),a==="missing"&&v.jsx("div",{className:"markdown-empty",children:"This file is available on the original device only."}),a==="error"&&v.jsx("div",{className:"markdown-empty",children:"The file could not be opened."}),a==="ready"&&v.jsx("iframe",{className:"html-preview-iframe",title:`Sandboxed preview of ${t.filename}`,sandbox:aD,referrerPolicy:"no-referrer",src:`/api/html-preview/${encodeURIComponent(t.id)}`},t.id)]})]})})}function Uk(e){const t=(n,i)=>{const{key:s}=n;if(!["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End"].includes(s))return;n.preventDefault();const l=e.options.length-1,a=s==="Home"?0:s==="End"?l:s==="ArrowLeft"||s==="ArrowUp"?(i-1+e.options.length)%e.options.length:(i+1)%e.options.length,c=e.options[a];c&&(e.onChange(c.id),document.getElementById(`${e.idPrefix}-${c.id}`)?.focus())};return v.jsx("div",{className:e.className,role:"tablist","aria-label":e.label,children:e.options.map((n,i)=>v.jsxs("button",{id:`${e.idPrefix}-${n.id}`,type:"button",role:"tab","aria-selected":e.value===n.id,"aria-controls":e.panelId,tabIndex:e.value===n.id?0:-1,className:"tab"+(e.value===n.id?" active":""),onClick:()=>e.onChange(n.id),onKeyDown:s=>t(s,i),children:[n.label,n.count===void 0?null:v.jsxs(v.Fragment,{children:[" ",v.jsx("span",{children:n.count})]})]},n.id))})}function Md(e){const{message:t}=e,[n,i]=k.useState(null),[s,l]=k.useState(0),a=S0(t.wireId)??{id:t.wireId,dir:t.dir,filename:t.filename??"file",mime:t.mime??"application/octet-stream",size:s,date:t.date};k.useEffect(()=>{let h=!0,m=null;if(t.wireId)return Ul(t.wireId).then(p=>{!h||!p||(l(p.byteLength),m=URL.createObjectURL(new Blob([p],{type:wh(a.mime,a.filename)})),i(m))}).catch(()=>{}),()=>{h=!1,m&&URL.revokeObjectURL(m)}},[t.wireId,a.mime,a.filename]);const c=cd(t)==="photo",d=eo(a.mime,a.filename);return v.jsxs("div",{className:"shared-media-item"+(c?" shared-photo-item":""),children:[v.jsxs("button",{className:"shared-media-jump",onClick:()=>e.onJump(e.messageKey),children:[c&&n?v.jsx("img",{src:n,alt:a.filename}):v.jsx("span",{className:"shared-media-icon",children:v.jsx(Ee,{name:d?"mic":"copy",size:18})}),v.jsxs("span",{className:"shared-media-copy",children:[v.jsx("strong",{children:c?a.filename||"Photo":d?"Voice message":a.filename}),v.jsxs("span",{children:[e.versionLabel?`${e.versionLabel} · `:"",ys(a.date),s?` · ${Fr(s)}`:""]})]})]}),v.jsxs("span",{className:"shared-media-actions",children:[d1(a.filename)&&n&&v.jsx("button",{className:"icon-btn",title:"Preview markdown",onClick:()=>e.onPreview(a),children:v.jsx(Ee,{name:"monitor",size:16})}),As(a.filename,a.mime)&&n&&v.jsx("button",{className:"icon-btn",title:"Preview HTML",onClick:()=>e.onPreview(a),children:v.jsx(Ee,{name:"monitor",size:16})}),v.jsx("a",{className:"icon-btn"+(n?"":" disabled"),href:n??void 0,download:a.filename,title:"Download",children:v.jsx(Ee,{name:"download",size:16})})]})]})}function AF(e){const[t,n]=k.useState(!1);if(e.versions.length===1){const i=e.versions[0];return v.jsx(Md,{message:i.message,messageKey:i.key,onJump:e.onJump,onPreview:e.onPreview})}return v.jsxs("div",{className:"file-version-stack"+(t?" expanded":""),children:[v.jsxs("button",{className:"file-version-stack-head",onClick:()=>n(i=>!i),children:[v.jsx("span",{className:"shared-media-icon",children:v.jsx(Ee,{name:"copy",size:18})}),v.jsxs("span",{className:"shared-media-copy",children:[v.jsx("strong",{children:e.filename}),v.jsxs("span",{children:[e.versions.length," versions · newest ",ys(e.versions[0].message.date)]})]}),v.jsx(Ee,{name:t?"chevronDown":"chevron",size:16})]}),t&&v.jsx("div",{className:"file-version-stack-list",children:e.versions.map((i,s)=>v.jsx(Md,{message:i.message,messageKey:i.key,versionLabel:`Version ${e.versions.length-s}`,onJump:e.onJump,onPreview:e.onPreview},i.key))})]})}function NF(e){const[t,n]=k.useState("photo"),i=e.messages.map((h,m)=>({message:h,key:h.wireId||`${h.date}-${(e.indexOffset??0)+m}`})),s=i.filter(({message:h})=>cd(h)==="photo"),l=i.filter(({message:h})=>cd(h)==="file"),a=nD(l),c=i.flatMap(({message:h,key:m})=>h.kind==="file"?[]:tD(h.text).map(p=>({url:p,message:h,key:m}))),d=[{id:"photo",label:"Photos",count:s.length},{id:"file",label:"Files",count:l.length},{id:"link",label:"Links",count:c.length}];return v.jsx(Ds,{title:"Shared media",description:"Photos, files, and links from this conversation",onClose:e.onClose,wide:!0,className:"shared-media-modal",tabs:v.jsx(Uk,{className:"shared-media-tabs",label:"Shared media type",options:d,value:t,onChange:n,idPrefix:"shared-media-tab",panelId:"shared-media-panel"}),children:v.jsxs("div",{id:"shared-media-panel",role:"tabpanel","aria-labelledby":`shared-media-tab-${t}`,className:"shared-media-list"+(t==="photo"?" photos":""),children:[t==="photo"&&s.map(h=>v.jsx(Md,{message:h.message,messageKey:h.key,onJump:e.onJump,onPreview:e.onPreview},h.key)),t==="file"&&a.map(h=>v.jsx(AF,{filename:h.filename,versions:h.versions,onJump:e.onJump,onPreview:e.onPreview},h.filename)),t==="link"&&c.map((h,m)=>v.jsxs("div",{className:"shared-media-item",children:[v.jsxs("a",{className:"shared-media-jump",href:h.url,target:"_blank",rel:"noreferrer",children:[v.jsx("span",{className:"shared-media-icon",children:v.jsx(Ee,{name:"link",size:18})}),v.jsxs("span",{className:"shared-media-copy",children:[v.jsx("strong",{children:h.url}),v.jsx("span",{children:ys(h.message.date)})]})]}),v.jsx("button",{className:"icon-btn",title:"Jump to message",onClick:()=>e.onJump(h.key),children:v.jsx(Ee,{name:"reply",size:16})})]},`${h.key}-${h.url}-${m}`)),(t==="photo"&&s.length===0||t==="file"&&l.length===0||t==="link"&&c.length===0)&&v.jsxs("div",{className:"markdown-empty",children:["No ",t==="photo"?"photos":`${t}s`," in this chat yet."]})]})})}const IF=Object.freeze(["image/avif","image/bmp","image/heic","image/heif","image/jpeg","image/jpg","image/png","image/webp"]),jF=/\.(avif|bmp|heic|heif|jpe?g|png|webp)$/i;function Wk(e,t=""){return IF.includes(String(e??"").toLowerCase())||jF.test(String(t??""))}function DF(e){return`${(String(e||"photo").trim()||"photo").replace(/\.[^./\\]+$/,"")||"photo"}.jpg`}function _F(e,t,n){const i=Math.max(1,Number(e)||1),s=Math.max(1,Number(t)||1),l=Math.max(1,Number(n)||1),a=Math.min(1,l/Math.max(i,s));return{width:Math.max(1,Math.round(i*a)),height:Math.max(1,Math.round(s*a))}}const LF=2048,OF=640,FF=.82,zF=[.84,.7,.56,.44],VF=.94;function BF(e){return new Promise((t,n)=>{const i=URL.createObjectURL(e),s=new Image,l=()=>URL.revokeObjectURL(i);s.onload=()=>t({image:s,release:l}),s.onerror=()=>{l(),n(new Error("This browser could not decode the selected image."))},s.src=i})}function $F(e,t){return new Promise((n,i)=>{e.toBlob(s=>s?n(s):i(new Error("This browser could not encode the optimized photo.")),"image/jpeg",t)})}async function UF(e,t){if(!Wk(e.type,e.name))throw new Error("This image format cannot be optimized safely in this browser.");const n=Math.max(1,Math.floor(t*VF)),{image:i,release:s}=await BF(e),l=document.createElement("canvas"),a=l.getContext("2d",{alpha:!1});if(!a)throw s(),new Error("Photo optimization is unavailable in this browser.");try{let c=Math.min(LF,Math.max(i.naturalWidth,i.naturalHeight));for(;c>=OF;){const d=_F(i.naturalWidth,i.naturalHeight,c);l.width=d.width,l.height=d.height,a.fillStyle="#fff",a.fillRect(0,0,l.width,l.height),a.drawImage(i,0,0,l.width,l.height);for(const h of zF){const m=await $F(l,h);if(m.size<=n)return{filename:DF(e.name),mime:"image/jpeg",bytes:new Uint8Array(await m.arrayBuffer()),width:l.width,height:l.height,originalSize:e.size}}c=Math.floor(c*FF)}}finally{s(),l.width=1,l.height=1}throw new Error("The photo is still too large after optimization.")}const WF=5e4,HF=new Set(["http:","https:","mailto:"]);function Hk(e){if(!(!e||e!==e.trim()||/[\u0000-\u001f\u007f]/u.test(e)))try{const t=new URL(e);return HF.has(t.protocol.toLowerCase())?e:void 0}catch{return}}function Kk(e){const t="language-";return e?.startsWith(t)&&e.slice(t.length)||void 0}function KF(e){return e.split(/(\n[ \t]*\n)/).map(t=>{if(/^\n[ \t]*\n$/.test(t))return t;const n=t.split(`
|
|
318
|
+
`},s),l}function KO(e,t){return e&&"run"in e?async function(n,i){const s=ax(n,{file:i,...t});await e.run(s,i)}:function(n,i){return ax(n,{file:i,...e||t})}}function lx(e){if(e)throw e}var yf,ux;function qO(){if(ux)return yf;ux=1;var e=Object.prototype.hasOwnProperty,t=Object.prototype.toString,n=Object.defineProperty,i=Object.getOwnPropertyDescriptor,s=function(h){return typeof Array.isArray=="function"?Array.isArray(h):t.call(h)==="[object Array]"},l=function(h){if(!h||t.call(h)!=="[object Object]")return!1;var m=e.call(h,"constructor"),p=h.constructor&&h.constructor.prototype&&e.call(h.constructor.prototype,"isPrototypeOf");if(h.constructor&&!m&&!p)return!1;var y;for(y in h);return typeof y>"u"||e.call(h,y)},a=function(h,m){n&&m.name==="__proto__"?n(h,m.name,{enumerable:!0,configurable:!0,value:m.newValue,writable:!0}):h[m.name]=m.newValue},c=function(h,m){if(m==="__proto__")if(e.call(h,m)){if(i)return i(h,m).value}else return;return h[m]};return yf=function d(){var h,m,p,y,w,S,C=arguments[0],E=1,T=arguments.length,M=!1;for(typeof C=="boolean"&&(M=C,C=arguments[1]||{},E=2),(C==null||typeof C!="object"&&typeof C!="function")&&(C={});E<T;++E)if(h=arguments[E],h!=null)for(m in h)p=c(C,m),y=c(h,m),C!==y&&(M&&y&&(l(y)||(w=s(y)))?(w?(w=!1,S=p&&s(p)?p:[]):S=p&&l(p)?p:{},a(C,{name:m,newValue:d(M,S,y)})):typeof y<"u"&&a(C,{name:m,newValue:y}));return C},yf}var XO=qO();const vf=Id(XO);function Pd(e){if(typeof e!="object"||e===null)return!1;const t=Object.getPrototypeOf(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Symbol.toStringTag in e)&&!(Symbol.iterator in e)}function YO(){const e=[],t={run:n,use:i};return t;function n(...s){let l=-1;const a=s.pop();if(typeof a!="function")throw new TypeError("Expected function as last argument, not "+a);c(null,...s);function c(d,...h){const m=e[++l];let p=-1;if(d){a(d);return}for(;++p<s.length;)(h[p]===null||h[p]===void 0)&&(h[p]=s[p]);s=h,m?GO(m,c)(...h):a(null,...h)}}function i(s){if(typeof s!="function")throw new TypeError("Expected `middelware` to be a function, not "+s);return e.push(s),t}}function GO(e,t){let n;return i;function i(...a){const c=e.length>a.length;let d;c&&a.push(s);try{d=e.apply(this,a)}catch(h){const m=h;if(c&&n)throw m;return s(m)}c||(d&&d.then&&typeof d.then=="function"?d.then(l,s):d instanceof Error?s(d):l(d))}function s(a,...c){n||(n=!0,t(a,...c))}function l(a){s(null,a)}}const Un={basename:QO,dirname:ZO,extname:JO,join:eF,sep:"/"};function QO(e,t){if(t!==void 0&&typeof t!="string")throw new TypeError('"ext" argument must be a string');js(e);let n=0,i=-1,s=e.length,l;if(t===void 0||t.length===0||t.length>e.length){for(;s--;)if(e.codePointAt(s)===47){if(l){n=s+1;break}}else i<0&&(l=!0,i=s+1);return i<0?"":e.slice(n,i)}if(t===e)return"";let a=-1,c=t.length-1;for(;s--;)if(e.codePointAt(s)===47){if(l){n=s+1;break}}else a<0&&(l=!0,a=s+1),c>-1&&(e.codePointAt(s)===t.codePointAt(c--)?c<0&&(i=s):(c=-1,i=a));return n===i?i=a:i<0&&(i=e.length),e.slice(n,i)}function ZO(e){if(js(e),e.length===0)return".";let t=-1,n=e.length,i;for(;--n;)if(e.codePointAt(n)===47){if(i){t=n;break}}else i||(i=!0);return t<0?e.codePointAt(0)===47?"/":".":t===1&&e.codePointAt(0)===47?"//":e.slice(0,t)}function JO(e){js(e);let t=e.length,n=-1,i=0,s=-1,l=0,a;for(;t--;){const c=e.codePointAt(t);if(c===47){if(a){i=t+1;break}continue}n<0&&(a=!0,n=t+1),c===46?s<0?s=t:l!==1&&(l=1):s>-1&&(l=-1)}return s<0||n<0||l===0||l===1&&s===n-1&&s===i+1?"":e.slice(s,n)}function eF(...e){let t=-1,n;for(;++t<e.length;)js(e[t]),e[t]&&(n=n===void 0?e[t]:n+"/"+e[t]);return n===void 0?".":tF(n)}function tF(e){js(e);const t=e.codePointAt(0)===47;let n=nF(e,!t);return n.length===0&&!t&&(n="."),n.length>0&&e.codePointAt(e.length-1)===47&&(n+="/"),t?"/"+n:n}function nF(e,t){let n="",i=0,s=-1,l=0,a=-1,c,d;for(;++a<=e.length;){if(a<e.length)c=e.codePointAt(a);else{if(c===47)break;c=47}if(c===47){if(!(s===a-1||l===1))if(s!==a-1&&l===2){if(n.length<2||i!==2||n.codePointAt(n.length-1)!==46||n.codePointAt(n.length-2)!==46){if(n.length>2){if(d=n.lastIndexOf("/"),d!==n.length-1){d<0?(n="",i=0):(n=n.slice(0,d),i=n.length-1-n.lastIndexOf("/")),s=a,l=0;continue}}else if(n.length>0){n="",i=0,s=a,l=0;continue}}t&&(n=n.length>0?n+"/..":"..",i=2)}else n.length>0?n+="/"+e.slice(s+1,a):n=e.slice(s+1,a),i=a-s-1;s=a,l=0}else c===46&&l>-1?l++:l=-1}return n}function js(e){if(typeof e!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(e))}const rF={cwd:iF};function iF(){return"/"}function Rd(e){return!!(e!==null&&typeof e=="object"&&"href"in e&&e.href&&"protocol"in e&&e.protocol&&e.auth===void 0)}function oF(e){if(typeof e=="string")e=new URL(e);else if(!Rd(e)){const t=new TypeError('The "path" argument must be of type string or an instance of URL. Received `'+e+"`");throw t.code="ERR_INVALID_ARG_TYPE",t}if(e.protocol!=="file:"){const t=new TypeError("The URL must be of scheme file");throw t.code="ERR_INVALID_URL_SCHEME",t}return sF(e)}function sF(e){if(e.hostname!==""){const i=new TypeError('File URL host must be "localhost" or empty on darwin');throw i.code="ERR_INVALID_FILE_URL_HOST",i}const t=e.pathname;let n=-1;for(;++n<t.length;)if(t.codePointAt(n)===37&&t.codePointAt(n+1)===50){const i=t.codePointAt(n+2);if(i===70||i===102){const s=new TypeError("File URL path must not include encoded / characters");throw s.code="ERR_INVALID_FILE_URL_PATH",s}}return decodeURIComponent(t)}const xf=["history","path","basename","stem","extname","dirname"];class Fk{constructor(t){let n;t?Rd(t)?n={path:t}:typeof t=="string"||aF(t)?n={value:t}:n=t:n={},this.cwd="cwd"in n?"":rF.cwd(),this.data={},this.history=[],this.messages=[],this.value,this.map,this.result,this.stored;let i=-1;for(;++i<xf.length;){const l=xf[i];l in n&&n[l]!==void 0&&n[l]!==null&&(this[l]=l==="history"?[...n[l]]:n[l])}let s;for(s in n)xf.includes(s)||(this[s]=n[s])}get basename(){return typeof this.path=="string"?Un.basename(this.path):void 0}set basename(t){kf(t,"basename"),wf(t,"basename"),this.path=Un.join(this.dirname||"",t)}get dirname(){return typeof this.path=="string"?Un.dirname(this.path):void 0}set dirname(t){cx(this.basename,"dirname"),this.path=Un.join(t||"",this.basename)}get extname(){return typeof this.path=="string"?Un.extname(this.path):void 0}set extname(t){if(wf(t,"extname"),cx(this.dirname,"extname"),t){if(t.codePointAt(0)!==46)throw new Error("`extname` must start with `.`");if(t.includes(".",1))throw new Error("`extname` cannot contain multiple dots")}this.path=Un.join(this.dirname,this.stem+(t||""))}get path(){return this.history[this.history.length-1]}set path(t){Rd(t)&&(t=oF(t)),kf(t,"path"),this.path!==t&&this.history.push(t)}get stem(){return typeof this.path=="string"?Un.basename(this.path,this.extname):void 0}set stem(t){kf(t,"stem"),wf(t,"stem"),this.path=Un.join(this.dirname||"",t+(this.extname||""))}fail(t,n,i){const s=this.message(t,n,i);throw s.fatal=!0,s}info(t,n,i){const s=this.message(t,n,i);return s.fatal=void 0,s}message(t,n,i){const s=new zt(t,n,i);return this.path&&(s.name=this.path+":"+s.name,s.file=this.path),s.fatal=!1,this.messages.push(s),s}toString(t){return this.value===void 0?"":typeof this.value=="string"?this.value:new TextDecoder(t||void 0).decode(this.value)}}function wf(e,t){if(e&&e.includes(Un.sep))throw new Error("`"+t+"` cannot be a path: did not expect `"+Un.sep+"`")}function kf(e,t){if(!e)throw new Error("`"+t+"` cannot be empty")}function cx(e,t){if(!e)throw new Error("Setting `"+t+"` requires `path` to be set too")}function aF(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const lF=function(e){const i=this.constructor.prototype,s=i[e],l=function(){return s.apply(l,arguments)};return Object.setPrototypeOf(l,i),l},uF={}.hasOwnProperty;class Wh extends lF{constructor(){super("copy"),this.Compiler=void 0,this.Parser=void 0,this.attachers=[],this.compiler=void 0,this.freezeIndex=-1,this.frozen=void 0,this.namespace={},this.parser=void 0,this.transformers=YO()}copy(){const t=new Wh;let n=-1;for(;++n<this.attachers.length;){const i=this.attachers[n];t.use(...i)}return t.data(vf(!0,{},this.namespace)),t}data(t,n){return typeof t=="string"?arguments.length===2?(Cf("data",this.frozen),this.namespace[t]=n,this):uF.call(this.namespace,t)&&this.namespace[t]||void 0:t?(Cf("data",this.frozen),this.namespace=t,this):this.namespace}freeze(){if(this.frozen)return this;const t=this;for(;++this.freezeIndex<this.attachers.length;){const[n,...i]=this.attachers[this.freezeIndex];if(i[0]===!1)continue;i[0]===!0&&(i[0]=void 0);const s=n.call(t,...i);typeof s=="function"&&this.transformers.use(s)}return this.frozen=!0,this.freezeIndex=Number.POSITIVE_INFINITY,this}parse(t){this.freeze();const n=rl(t),i=this.parser||this.Parser;return Sf("parse",i),i(String(n),n)}process(t,n){const i=this;return this.freeze(),Sf("process",this.parser||this.Parser),bf("process",this.compiler||this.Compiler),n?s(void 0,n):new Promise(s);function s(l,a){const c=rl(t),d=i.parse(c);i.run(d,c,function(m,p,y){if(m||!p||!y)return h(m);const w=p,S=i.stringify(w,y);dF(S)?y.value=S:y.result=S,h(m,y)});function h(m,p){m||!p?a(m):l?l(p):n(void 0,p)}}}processSync(t){let n=!1,i;return this.freeze(),Sf("processSync",this.parser||this.Parser),bf("processSync",this.compiler||this.Compiler),this.process(t,s),dx("processSync","process",n),i;function s(l,a){n=!0,lx(l),i=a}}run(t,n,i){fx(t),this.freeze();const s=this.transformers;return!i&&typeof n=="function"&&(i=n,n=void 0),i?l(void 0,i):new Promise(l);function l(a,c){const d=rl(n);s.run(t,d,h);function h(m,p,y){const w=p||t;m?c(m):a?a(w):i(void 0,w,y)}}}runSync(t,n){let i=!1,s;return this.run(t,n,l),dx("runSync","run",i),s;function l(a,c){lx(a),s=c,i=!0}}stringify(t,n){this.freeze();const i=rl(n),s=this.compiler||this.Compiler;return bf("stringify",s),fx(t),s(t,i)}use(t,...n){const i=this.attachers,s=this.namespace;if(Cf("use",this.frozen),t!=null)if(typeof t=="function")d(t,n);else if(typeof t=="object")Array.isArray(t)?c(t):a(t);else throw new TypeError("Expected usable value, not `"+t+"`");return this;function l(h){if(typeof h=="function")d(h,[]);else if(typeof h=="object")if(Array.isArray(h)){const[m,...p]=h;d(m,p)}else a(h);else throw new TypeError("Expected usable value, not `"+h+"`")}function a(h){if(!("plugins"in h)&&!("settings"in h))throw new Error("Expected usable value but received an empty preset, which is probably a mistake: presets typically come with `plugins` and sometimes with `settings`, but this has neither");c(h.plugins),h.settings&&(s.settings=vf(!0,s.settings,h.settings))}function c(h){let m=-1;if(h!=null)if(Array.isArray(h))for(;++m<h.length;){const p=h[m];l(p)}else throw new TypeError("Expected a list of plugins, not `"+h+"`")}function d(h,m){let p=-1,y=-1;for(;++p<i.length;)if(i[p][0]===h){y=p;break}if(y===-1)i.push([h,...m]);else if(m.length>0){let[w,...S]=m;const C=i[y][1];Pd(C)&&Pd(w)&&(w=vf(!0,C,w)),i[y]=[h,w,...S]}}}}const cF=new Wh().freeze();function Sf(e,t){if(typeof t!="function")throw new TypeError("Cannot `"+e+"` without `parser`")}function bf(e,t){if(typeof t!="function")throw new TypeError("Cannot `"+e+"` without `compiler`")}function Cf(e,t){if(t)throw new Error("Cannot call `"+e+"` on a frozen processor.\nCreate a new processor first, by calling it: use `processor()` instead of `processor`.")}function fx(e){if(!Pd(e)||typeof e.type!="string")throw new TypeError("Expected node, got `"+e+"`")}function dx(e,t,n){if(!n)throw new Error("`"+e+"` finished async. Use `"+t+"` instead")}function rl(e){return fF(e)?e:new Fk(e)}function fF(e){return!!(e&&typeof e=="object"&&"message"in e&&"messages"in e)}function dF(e){return typeof e=="string"||hF(e)}function hF(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const pF="https://github.com/remarkjs/react-markdown/blob/main/changelog.md",hx=[],px={allowDangerousHtml:!0},mF=/^(https?|ircs?|mailto|xmpp)$/i,gF=[{from:"astPlugins",id:"remove-buggy-html-in-markdown-parser"},{from:"allowDangerousHtml",id:"remove-buggy-html-in-markdown-parser"},{from:"allowNode",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"allowElement"},{from:"allowedTypes",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"allowedElements"},{from:"className",id:"remove-classname"},{from:"disallowedTypes",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"disallowedElements"},{from:"escapeHtml",id:"remove-buggy-html-in-markdown-parser"},{from:"includeElementIndex",id:"#remove-includeelementindex"},{from:"includeNodeIndex",id:"change-includenodeindex-to-includeelementindex"},{from:"linkTarget",id:"remove-linktarget"},{from:"plugins",id:"change-plugins-to-remarkplugins",to:"remarkPlugins"},{from:"rawSourcePos",id:"#remove-rawsourcepos"},{from:"renderers",id:"change-renderers-to-components",to:"components"},{from:"source",id:"change-source-to-children",to:"children"},{from:"sourcePos",id:"#remove-sourcepos"},{from:"transformImageUri",id:"#add-urltransform",to:"urlTransform"},{from:"transformLinkUri",id:"#add-urltransform",to:"urlTransform"}];function zk(e){const t=yF(e),n=vF(e);return xF(t.runSync(t.parse(n),n),e)}function yF(e){const t=e.rehypePlugins||hx,n=e.remarkPlugins||hx,i=e.remarkRehypeOptions?{...e.remarkRehypeOptions,...px}:px;return cF().use(sO).use(n).use(KO,i).use(t)}function vF(e){const t=e.children||"",n=new Fk;return typeof t=="string"&&(n.value=t),n}function xF(e,t){const n=t.allowedElements,i=t.allowElement,s=t.components,l=t.disallowedElements,a=t.skipHtml,c=t.unwrapDisallowed,d=t.urlTransform||wF;for(const m of gF)Object.hasOwn(t,m.from)&&(""+m.from+(m.to?"use `"+m.to+"` instead":"remove it")+pF+m.id,void 0);return ph(e,h),WL(e,{Fragment:v.Fragment,components:s,ignoreInvalidStyle:!0,jsx:v.jsx,jsxs:v.jsxs,passKeys:!0,passNode:!0});function h(m,p,y){if(m.type==="raw"&&y&&typeof p=="number")return a?y.children.splice(p,1):y.children[p]={type:"text",value:m.value},p;if(m.type==="element"){let w;for(w in gf)if(Object.hasOwn(gf,w)&&Object.hasOwn(m.properties,w)){const S=m.properties[w],C=gf[w];(C===null||C.includes(m.tagName))&&(m.properties[w]=d(String(S||""),w,m))}}if(m.type==="element"){let w=n?!n.includes(m.tagName):l?l.includes(m.tagName):!1;if(!w&&i&&typeof p=="number"&&(w=!i(m,p,y)),w&&y&&typeof p=="number")return c&&m.children?y.children.splice(p,1,...m.children):y.children.splice(p,1),p}}}function wF(e){const t=e.indexOf(":"),n=e.indexOf("?"),i=e.indexOf("#"),s=e.indexOf("/");return t===-1||s!==-1&&t>s||n!==-1&&t>n||i!==-1&&t>i||mF.test(e.slice(0,t))?e:""}const kF={};function Vk(e){const t=this,n=e||kF,i=t.data(),s=i.micromarkExtensions||(i.micromarkExtensions=[]),l=i.fromMarkdownExtensions||(i.fromMarkdownExtensions=[]),a=i.toMarkdownExtensions||(i.toMarkdownExtensions=[]);s.push(f1(n)),l.push(U0()),a.push(RN(n))}function Ds(e){const t=k.useRef(null);return k.useEffect(()=>(t.current=document.activeElement instanceof HTMLElement?document.activeElement:null,()=>{const n=t.current;n?.isConnected&&requestAnimationFrame(()=>n.focus())}),[]),v.jsx(uk,{open:!0,onOpenChange:n=>{n||e.onClose()},children:v.jsxs(dk,{children:[v.jsx(hk,{className:"modal-backdrop"}),v.jsxs(pk,{id:e.contentId,className:"modal"+(e.wide?" modal-wide":"")+(e.className?` ${e.className}`:""),children:[v.jsxs("div",{className:"modal-head",children:[v.jsxs("div",{children:[v.jsx(gk,{asChild:!0,children:v.jsx("h3",{children:e.title})}),e.description&&v.jsx(yk,{className:"modal-description",children:e.description})]}),v.jsx(vk,{asChild:!0,children:v.jsx("button",{className:"icon-btn","aria-label":`Close ${e.title}`,children:v.jsx(Ee,{name:"close"})})})]}),e.tabs,v.jsx("div",{className:"modal-body",children:e.children})]})]})})}const SF=.25,bF=8;let mx=Promise.resolve();function gx(){return document.documentElement.classList.contains("theme-dark")?"dark":"default"}function CF(){const[e,t]=k.useState(gx);return k.useEffect(()=>{const n=document.documentElement,i=()=>t(gx()),s=new MutationObserver(i);return s.observe(n,{attributes:!0,attributeFilter:["class"]}),i(),()=>s.disconnect()},[]),e}function EF(e,t,n){const i=mx.then(async()=>{const{default:s}=await Ch(async()=>{const{default:l}=await import("./mermaid.core-DhIQAWlJ.js").then(a=>a.bp);return{default:l}},[]);return s.initialize({startOnLoad:!1,securityLevel:"strict",theme:n,fontFamily:"var(--sans)"}),s.render(e,t)});return mx=i.then(()=>{},()=>{}),i}function TF(e){return Math.min(bF,Math.max(SF,e))}function PF(e){const t=k.useRef(null),n=k.useRef(null),[i,s]=k.useState(1),[l,a]=k.useState({x:0,y:0}),[c,d]=k.useState(!1),h=()=>{s(1),a({x:0,y:0})},m=(p,y,w)=>{const S=TF(p);if(S===i)return;const C=t.current?.getBoundingClientRect();if(C){const E=(y??C.left+C.width/2)-C.left-C.width/2,T=(w??C.top+C.height/2)-C.top-C.height/2,M=S/i;a(P=>({x:E-M*(E-P.x),y:T-M*(T-P.y)}))}s(S)};return k.useEffect(()=>{const p=y=>{y.key==="+"||y.key==="="?(y.preventDefault(),m(i*1.25)):y.key==="-"?(y.preventDefault(),m(i/1.25)):y.key==="0"&&(y.preventDefault(),h())};return window.addEventListener("keydown",p),()=>window.removeEventListener("keydown",p)}),v.jsx(uk,{open:!0,onOpenChange:p=>{p||e.onClose()},children:v.jsxs(dk,{children:[v.jsx(hk,{className:"mermaid-fullscreen-backdrop"}),v.jsxs(pk,{className:"mermaid-fullscreen","data-mermaid-theme":e.theme,"aria-describedby":"mermaid-fullscreen-help",children:[v.jsx(gk,{className:"mermaid-fullscreen-title",children:"Diagram viewer"}),v.jsxs("div",{className:"mermaid-fullscreen-tools",children:[v.jsx("button",{className:"icon-btn","aria-label":"Zoom out",title:"Zoom out (−)",onClick:()=>m(i/1.25),children:v.jsx(Ee,{name:"minus"})}),v.jsxs("button",{className:"mermaid-zoom-value",onClick:h,title:"Reset zoom and position",children:[Math.round(i*100),"%"]}),v.jsx("button",{className:"icon-btn","aria-label":"Zoom in",title:"Zoom in (+)",onClick:()=>m(i*1.25),children:v.jsx(Ee,{name:"plus"})}),v.jsx(vk,{asChild:!0,children:v.jsx("button",{className:"icon-btn","aria-label":"Close diagram viewer",title:"Close (Esc)",children:v.jsx(Ee,{name:"close"})})})]}),v.jsx("div",{ref:t,className:"mermaid-fullscreen-viewport"+(c?" dragging":""),onWheel:p=>{p.preventDefault(),m(i*Math.exp(-p.deltaY*.0015),p.clientX,p.clientY)},onDoubleClick:p=>m(i*1.5,p.clientX,p.clientY),onPointerDown:p=>{p.button===0&&(n.current={pointerId:p.pointerId,startX:p.clientX,startY:p.clientY,panX:l.x,panY:l.y},p.currentTarget.setPointerCapture(p.pointerId),d(!0))},onPointerMove:p=>{const y=n.current;!y||y.pointerId!==p.pointerId||a({x:y.panX+p.clientX-y.startX,y:y.panY+p.clientY-y.startY})},onPointerUp:p=>{n.current?.pointerId===p.pointerId&&(n.current=null,d(!1),p.currentTarget.releasePointerCapture(p.pointerId))},onPointerCancel:()=>{n.current=null,d(!1)},children:v.jsx("div",{className:"mermaid-fullscreen-canvas",style:{transform:`translate(${l.x}px, ${l.y}px) scale(${i})`},dangerouslySetInnerHTML:{__html:e.svg}})}),v.jsx(yk,{id:"mermaid-fullscreen-help",className:"mermaid-fullscreen-help",children:"Scroll to zoom · drag to move · double-click to zoom in"})]})]})})}function RF({source:e}){const t=k.useId(),[n,i]=k.useState(""),[s,l]=k.useState(""),[a,c]=k.useState("default"),[d,h]=k.useState(!1),m=CF();return k.useEffect(()=>{let p=!0;const y=`mermaid-${t.replace(/[^a-zA-Z0-9_-]/g,"")}`;return i(""),l(""),EF(y,e,m).then(w=>{p&&(c(m),i(w.svg))}).catch(w=>{p&&l(w instanceof Error?w.message:String(w))}),()=>{p=!1,document.getElementById(`d${y}`)?.remove()}},[t,e,m]),s?v.jsxs("pre",{className:"markdown-mermaid-error",children:["Mermaid error: ",s]}):n?v.jsxs(v.Fragment,{children:[v.jsxs("div",{className:"markdown-mermaid","data-mermaid-theme":a,children:[v.jsx("button",{className:"icon-btn markdown-mermaid-expand","aria-label":"View diagram fullscreen",title:"View diagram fullscreen",onClick:()=>h(!0),children:v.jsx(Ee,{name:"maximize"})}),v.jsx("div",{className:"markdown-mermaid-diagram",dangerouslySetInnerHTML:{__html:n}})]}),d&&v.jsx(PF,{svg:n,theme:a,onClose:()=>h(!1)})]}):v.jsx("div",{className:"markdown-mermaid-loading",children:"Rendering diagram…"})}const MF=k.memo(function(t){return v.jsx("article",{className:"markdown-body",ref:t.contentRef,children:v.jsx(zk,{remarkPlugins:[Vk],components:{a:({children:n,...i})=>v.jsx("a",{...i,target:"_blank",rel:"noreferrer",children:n}),code:({className:n,children:i,...s})=>{const l=/language-([\w-]+)/.exec(n??"")?.[1],a=String(i).replace(/\n$/,"");return l==="mermaid"?v.jsx(RF,{source:a}):v.jsx("code",{className:n,...s,children:i})}},children:t.markdown})})});function Bk(e){const{rec:t}=e,n=k.useRef(null),[i,s]=k.useState(""),[l,a]=k.useState(null),[c,d]=k.useState("loading"),[h,m]=k.useState(""),[p,y]=k.useState(0),[w,S]=k.useState(""),[C,E]=k.useState(0),[T,M]=k.useState(!1),[P,D]=k.useState(""),[$,j]=k.useState(!1),[Y,U]=k.useState(!1),[O,N]=k.useState([]),[X,V]=k.useState(!1),[fe,J]=k.useState(null),[ee,xe]=k.useState(!1),[Pe,Q]=k.useState("");k.useEffect(()=>{let A=!0,te=null;return d("loading"),Ul(t.id).then(ge=>{if(A){if(!ge){d("missing");return}s(new TextDecoder("utf-8").decode(ge)),te=URL.createObjectURL(new Blob([ge],{type:"text/markdown;charset=utf-8"})),a(te),d("ready")}}).catch(()=>{A&&d("error")}),()=>{A=!1,te&&URL.revokeObjectURL(te)}},[t.id]),k.useEffect(()=>{const A=()=>{const te=window.getSelection(),ge=n.current;if(!te||te.isCollapsed||!ge){m(""),y(0);return}if(!ge.contains(te.anchorNode)||!ge.contains(te.focusNode)){m(""),y(0);return}const ye=te.getRangeAt(0),me=te.toString(),we=me.length-me.trimStart().length,pe=me.trim().slice(0,4e3),Ve=document.createRange();Ve.selectNodeContents(ge),Ve.setEnd(ye.startContainer,ye.startOffset);const qe=Ve.toString().length+we;m(pe),y(eD(ge.textContent,pe,qe))};return document.addEventListener("selectionchange",A),()=>document.removeEventListener("selectionchange",A)},[]);const de=()=>{h&&(S(h),E(p),M(!0),Q(""))},R=async()=>{if(Y){if(!w||!P.trim())return;N(te=>[...te,{selection:w,comment:P.trim(),occurrence:C}]),D(""),M(!1),Q("Comment added to review");return}const A=Zj(w,P);if(!(!A||!P.trim()||$)){j(!0),Q("");try{await e.onSendText(A,t.id||void 0),D(""),M(!1),Q("Feedback sent")}catch(te){Q(`Send failed: ${String(te)}`)}finally{j(!1)}}},F=async()=>{if(O.length===0||X)return;const A=sD(i,O);V(!0),Q("");try{e.onSendFile?await e.onSendFile({filename:Jj(t.filename),mime:"text/markdown",bytes:new TextEncoder().encode(A)},t.id||void 0):await e.onSendText(A,t.id||void 0),N([]),U(!1),Q("Review submitted")}catch(te){Q(`Review send failed: ${String(te)}`)}finally{V(!1)}},G=async()=>{if(!(!fe||!e.onSendFile||ee)){xe(!0),Q("");try{await e.onSendFile(fe,t.id||void 0),J(null),Q("Voice feedback sent")}catch(A){Q(`Voice send failed: ${String(A)}`)}finally{xe(!1)}}};return v.jsx(Ds,{title:t.filename,description:"Markdown preview · select text to send precise feedback",onClose:e.onClose,wide:!0,className:"markdown-modal",children:v.jsxs("div",{className:"markdown-preview",children:[v.jsxs("div",{className:"markdown-review-toolbar",children:[v.jsxs("button",{className:"btn sm",disabled:!h,onMouseDown:A=>A.preventDefault(),onClick:de,children:[v.jsx(Ee,{name:"reply",size:14}),Y?"Add review comment":"Quick message",h?` (${h.length})`:""]}),Y?v.jsx("button",{className:"btn sm",onClick:()=>{U(!1),N([]),M(!1),Q("Review discarded")},children:"Cancel review"}):v.jsxs("button",{className:"btn sm",onClick:()=>{U(!0),N([]),Q("Review started — select passages to add comments")},children:[v.jsx(Ee,{name:"edit",size:14}),"Start review"]}),l&&v.jsxs("a",{className:"btn sm",href:l,download:t.filename,children:[v.jsx(Ee,{name:"download",size:14}),"Download"]}),e.onSendFile&&v.jsx(k1,{disabled:!!fe||ee,onReady:J,onError:Q}),v.jsx("span",{className:"markdown-review-hint",children:h?"Selection ready for feedback":"Highlight any passage to comment on it"})]}),T&&v.jsxs("div",{className:"markdown-feedback",children:[v.jsx("blockquote",{children:w}),v.jsx("textarea",{className:"field",rows:3,autoFocus:!0,placeholder:"What should change?",value:P,onChange:A=>D(A.target.value)}),v.jsxs("div",{className:"markdown-feedback-actions",children:[v.jsx("button",{className:"btn sm",onClick:()=>M(!1),children:"Cancel"}),v.jsxs("button",{className:"btn sm primary",disabled:!P.trim()||$,onClick:()=>void R(),children:[v.jsx(Ee,{name:"send",size:14}),Y?"Add to review":$?"Sending…":"Send feedback"]})]})]}),Y&&v.jsxs("div",{className:"markdown-review-draft",children:[v.jsxs("div",{className:"markdown-review-draft-head",children:[v.jsxs("strong",{children:["Review · ",O.length," comment",O.length===1?"":"s"]}),v.jsxs("button",{className:"btn sm primary",disabled:O.length===0||X,onClick:()=>void F(),children:[v.jsx(Ee,{name:"send",size:14}),X?"Submitting…":"Submit review"]})]}),O.map((A,te)=>v.jsxs("div",{className:"markdown-review-comment",children:[v.jsx("span",{children:te+1}),v.jsxs("div",{children:[v.jsx("blockquote",{children:A.selection}),v.jsx("p",{children:A.comment})]}),v.jsx("button",{className:"icon-btn",title:"Remove comment",onClick:()=>N(ge=>ge.filter((ye,me)=>me!==te)),children:v.jsx(Ee,{name:"close",size:14})})]},`${te}-${A.selection.slice(0,24)}`))]}),fe&&v.jsx(w1,{att:fe,sending:ee,onSend:()=>void G(),onDiscard:()=>J(null)}),Pe&&v.jsx("div",{className:"markdown-review-status",role:"status",children:Pe}),v.jsxs("div",{className:"markdown-preview-scroll",children:[c==="loading"&&v.jsx("div",{className:"markdown-empty",children:"Loading preview…"}),c==="missing"&&v.jsx("div",{className:"markdown-empty",children:"This file is available on the original device only."}),c==="error"&&v.jsx("div",{className:"markdown-empty",children:"The file could not be opened."}),c==="ready"&&v.jsx(MF,{markdown:i,contentRef:n})]})]})})}function $k(e){const{rec:t}=e,[n,i]=k.useState(null),[s,l]=k.useState(0),[a,c]=k.useState("loading");return k.useEffect(()=>{let d=!0,h=null;return c("loading"),Ul(t.id).then(m=>{if(d){if(!m){c("missing");return}l(m.byteLength),h=URL.createObjectURL(new Blob([m],{type:wh(t.mime,t.filename)})),i(h),c("ready")}}).catch(()=>{d&&c("error")}),()=>{d=!1,h&&URL.revokeObjectURL(h)}},[t.id,t.mime,t.filename]),v.jsx(Ds,{title:t.filename,description:"Transformed safe preview · external navigation disabled",onClose:e.onClose,wide:!0,className:"markdown-modal html-modal",children:v.jsxs("div",{className:"html-preview",children:[v.jsxs("div",{className:"html-preview-toolbar",children:[v.jsxs("span",{className:"html-preview-shield",children:[v.jsx(Ee,{name:"shield",size:14}),"Scripts, forms and network requests are blocked"]}),n&&v.jsxs("a",{className:"btn sm",href:n,download:t.filename,children:[v.jsx(Ee,{name:"download",size:14}),"Download original",s?` · ${Fr(s)}`:""]})]}),v.jsxs("div",{className:"html-preview-frame",children:[a==="loading"&&v.jsx("div",{className:"markdown-empty",children:"Loading preview…"}),a==="missing"&&v.jsx("div",{className:"markdown-empty",children:"This file is available on the original device only."}),a==="error"&&v.jsx("div",{className:"markdown-empty",children:"The file could not be opened."}),a==="ready"&&v.jsx("iframe",{className:"html-preview-iframe",title:`Sandboxed preview of ${t.filename}`,sandbox:aD,referrerPolicy:"no-referrer",src:`/api/html-preview/${encodeURIComponent(t.id)}`},t.id)]})]})})}function Uk(e){const t=(n,i)=>{const{key:s}=n;if(!["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End"].includes(s))return;n.preventDefault();const l=e.options.length-1,a=s==="Home"?0:s==="End"?l:s==="ArrowLeft"||s==="ArrowUp"?(i-1+e.options.length)%e.options.length:(i+1)%e.options.length,c=e.options[a];c&&(e.onChange(c.id),document.getElementById(`${e.idPrefix}-${c.id}`)?.focus())};return v.jsx("div",{className:e.className,role:"tablist","aria-label":e.label,children:e.options.map((n,i)=>v.jsxs("button",{id:`${e.idPrefix}-${n.id}`,type:"button",role:"tab","aria-selected":e.value===n.id,"aria-controls":e.panelId,tabIndex:e.value===n.id?0:-1,className:"tab"+(e.value===n.id?" active":""),onClick:()=>e.onChange(n.id),onKeyDown:s=>t(s,i),children:[n.label,n.count===void 0?null:v.jsxs(v.Fragment,{children:[" ",v.jsx("span",{children:n.count})]})]},n.id))})}function Md(e){const{message:t}=e,[n,i]=k.useState(null),[s,l]=k.useState(0),a=S0(t.wireId)??{id:t.wireId,dir:t.dir,filename:t.filename??"file",mime:t.mime??"application/octet-stream",size:s,date:t.date};k.useEffect(()=>{let h=!0,m=null;if(t.wireId)return Ul(t.wireId).then(p=>{!h||!p||(l(p.byteLength),m=URL.createObjectURL(new Blob([p],{type:wh(a.mime,a.filename)})),i(m))}).catch(()=>{}),()=>{h=!1,m&&URL.revokeObjectURL(m)}},[t.wireId,a.mime,a.filename]);const c=cd(t)==="photo",d=eo(a.mime,a.filename);return v.jsxs("div",{className:"shared-media-item"+(c?" shared-photo-item":""),children:[v.jsxs("button",{className:"shared-media-jump",onClick:()=>e.onJump(e.messageKey),children:[c&&n?v.jsx("img",{src:n,alt:a.filename}):v.jsx("span",{className:"shared-media-icon",children:v.jsx(Ee,{name:d?"mic":"copy",size:18})}),v.jsxs("span",{className:"shared-media-copy",children:[v.jsx("strong",{children:c?a.filename||"Photo":d?"Voice message":a.filename}),v.jsxs("span",{children:[e.versionLabel?`${e.versionLabel} · `:"",ys(a.date),s?` · ${Fr(s)}`:""]})]})]}),v.jsxs("span",{className:"shared-media-actions",children:[d1(a.filename)&&n&&v.jsx("button",{className:"icon-btn",title:"Preview markdown",onClick:()=>e.onPreview(a),children:v.jsx(Ee,{name:"monitor",size:16})}),As(a.filename,a.mime)&&n&&v.jsx("button",{className:"icon-btn",title:"Preview HTML",onClick:()=>e.onPreview(a),children:v.jsx(Ee,{name:"monitor",size:16})}),v.jsx("a",{className:"icon-btn"+(n?"":" disabled"),href:n??void 0,download:a.filename,title:"Download",children:v.jsx(Ee,{name:"download",size:16})})]})]})}function AF(e){const[t,n]=k.useState(!1);if(e.versions.length===1){const i=e.versions[0];return v.jsx(Md,{message:i.message,messageKey:i.key,onJump:e.onJump,onPreview:e.onPreview})}return v.jsxs("div",{className:"file-version-stack"+(t?" expanded":""),children:[v.jsxs("button",{className:"file-version-stack-head",onClick:()=>n(i=>!i),children:[v.jsx("span",{className:"shared-media-icon",children:v.jsx(Ee,{name:"copy",size:18})}),v.jsxs("span",{className:"shared-media-copy",children:[v.jsx("strong",{children:e.filename}),v.jsxs("span",{children:[e.versions.length," versions · newest ",ys(e.versions[0].message.date)]})]}),v.jsx(Ee,{name:t?"chevronDown":"chevron",size:16})]}),t&&v.jsx("div",{className:"file-version-stack-list",children:e.versions.map((i,s)=>v.jsx(Md,{message:i.message,messageKey:i.key,versionLabel:`Version ${e.versions.length-s}`,onJump:e.onJump,onPreview:e.onPreview},i.key))})]})}function NF(e){const[t,n]=k.useState("photo"),i=e.messages.map((h,m)=>({message:h,key:h.wireId||`${h.date}-${(e.indexOffset??0)+m}`})),s=i.filter(({message:h})=>cd(h)==="photo"),l=i.filter(({message:h})=>cd(h)==="file"),a=nD(l),c=i.flatMap(({message:h,key:m})=>h.kind==="file"?[]:tD(h.text).map(p=>({url:p,message:h,key:m}))),d=[{id:"photo",label:"Photos",count:s.length},{id:"file",label:"Files",count:l.length},{id:"link",label:"Links",count:c.length}];return v.jsx(Ds,{title:"Shared media",description:"Photos, files, and links from this conversation",onClose:e.onClose,wide:!0,className:"shared-media-modal",tabs:v.jsx(Uk,{className:"shared-media-tabs",label:"Shared media type",options:d,value:t,onChange:n,idPrefix:"shared-media-tab",panelId:"shared-media-panel"}),children:v.jsxs("div",{id:"shared-media-panel",role:"tabpanel","aria-labelledby":`shared-media-tab-${t}`,className:"shared-media-list"+(t==="photo"?" photos":""),children:[t==="photo"&&s.map(h=>v.jsx(Md,{message:h.message,messageKey:h.key,onJump:e.onJump,onPreview:e.onPreview},h.key)),t==="file"&&a.map(h=>v.jsx(AF,{filename:h.filename,versions:h.versions,onJump:e.onJump,onPreview:e.onPreview},h.filename)),t==="link"&&c.map((h,m)=>v.jsxs("div",{className:"shared-media-item",children:[v.jsxs("a",{className:"shared-media-jump",href:h.url,target:"_blank",rel:"noreferrer",children:[v.jsx("span",{className:"shared-media-icon",children:v.jsx(Ee,{name:"link",size:18})}),v.jsxs("span",{className:"shared-media-copy",children:[v.jsx("strong",{children:h.url}),v.jsx("span",{children:ys(h.message.date)})]})]}),v.jsx("button",{className:"icon-btn",title:"Jump to message",onClick:()=>e.onJump(h.key),children:v.jsx(Ee,{name:"reply",size:16})})]},`${h.key}-${h.url}-${m}`)),(t==="photo"&&s.length===0||t==="file"&&l.length===0||t==="link"&&c.length===0)&&v.jsxs("div",{className:"markdown-empty",children:["No ",t==="photo"?"photos":`${t}s`," in this chat yet."]})]})})}const IF=Object.freeze(["image/avif","image/bmp","image/heic","image/heif","image/jpeg","image/jpg","image/png","image/webp"]),jF=/\.(avif|bmp|heic|heif|jpe?g|png|webp)$/i;function Wk(e,t=""){return IF.includes(String(e??"").toLowerCase())||jF.test(String(t??""))}function DF(e){return`${(String(e||"photo").trim()||"photo").replace(/\.[^./\\]+$/,"")||"photo"}.jpg`}function _F(e,t,n){const i=Math.max(1,Number(e)||1),s=Math.max(1,Number(t)||1),l=Math.max(1,Number(n)||1),a=Math.min(1,l/Math.max(i,s));return{width:Math.max(1,Math.round(i*a)),height:Math.max(1,Math.round(s*a))}}const LF=2048,OF=640,FF=.82,zF=[.84,.7,.56,.44],VF=.94;function BF(e){return new Promise((t,n)=>{const i=URL.createObjectURL(e),s=new Image,l=()=>URL.revokeObjectURL(i);s.onload=()=>t({image:s,release:l}),s.onerror=()=>{l(),n(new Error("This browser could not decode the selected image."))},s.src=i})}function $F(e,t){return new Promise((n,i)=>{e.toBlob(s=>s?n(s):i(new Error("This browser could not encode the optimized photo.")),"image/jpeg",t)})}async function UF(e,t){if(!Wk(e.type,e.name))throw new Error("This image format cannot be optimized safely in this browser.");const n=Math.max(1,Math.floor(t*VF)),{image:i,release:s}=await BF(e),l=document.createElement("canvas"),a=l.getContext("2d",{alpha:!1});if(!a)throw s(),new Error("Photo optimization is unavailable in this browser.");try{let c=Math.min(LF,Math.max(i.naturalWidth,i.naturalHeight));for(;c>=OF;){const d=_F(i.naturalWidth,i.naturalHeight,c);l.width=d.width,l.height=d.height,a.fillStyle="#fff",a.fillRect(0,0,l.width,l.height),a.drawImage(i,0,0,l.width,l.height);for(const h of zF){const m=await $F(l,h);if(m.size<=n)return{filename:DF(e.name),mime:"image/jpeg",bytes:new Uint8Array(await m.arrayBuffer()),width:l.width,height:l.height,originalSize:e.size}}c=Math.floor(c*FF)}}finally{s(),l.width=1,l.height=1}throw new Error("The photo is still too large after optimization.")}const WF=5e4,HF=new Set(["http:","https:","mailto:"]);function Hk(e){if(!(!e||e!==e.trim()||/[\u0000-\u001f\u007f]/u.test(e)))try{const t=new URL(e);return HF.has(t.protocol.toLowerCase())?e:void 0}catch{return}}function Kk(e){const t="language-";return e?.startsWith(t)&&e.slice(t.length)||void 0}function KF(e){return e.split(/(\n[ \t]*\n)/).map(t=>{if(/^\n[ \t]*\n$/.test(t))return t;const n=t.split(`
|
|
319
319
|
`),i=n.filter(a=>a.trim().length>0);if(i.length===0)return t;const s=i.map(a=>a.match(/^[ \t]+/)?.[0]??"");if(s.some(a=>a.length===0))return t;const l=Math.min(...s.map(a=>a.length));return n.map(a=>a.trim().length>0?a.slice(l):a).join(`
|
|
320
|
-
`)}).join("")}function qF({children:e}){const t=k.isValidElement(e)?e:null,n=Kk(t?.props.className);return v.jsxs("div",{className:"message-code-block","data-language":n||void 0,children:[n&&v.jsx("div",{className:"message-code-language",children:n}),v.jsx("pre",{children:e})]})}const XF=[Vk],YF={a:({node:e,children:t,href:n,...i})=>{const s=Hk(n);return s?v.jsx("a",{...i,href:s,target:"_blank",rel:"noopener noreferrer",children:t}):v.jsx("span",{className:"message-link-blocked",children:t})},img:({alt:e})=>v.jsxs("span",{className:"message-image-placeholder",children:["[image: ",e||"remote image blocked","]"]}),pre:qF,code:({node:e,className:t,children:n,...i})=>v.jsx("code",{className:t,"data-language":Kk(t),...i,children:n})},yx=k.memo(function({text:t,className:n="bubble-text message-markdown"}){return t.length>WF?v.jsx("div",{className:`${n} message-markdown-plaintext`,"data-render-mode":"plaintext",children:t}):v.jsx("div",{className:n,"data-render-mode":"markdown",children:v.jsx(zk,{remarkPlugins:XF,components:YF,urlTransform:i=>Hk(i)??"",children:KF(t)})})}),yl={type:"spring",stiffness:430,damping:38,mass:.72},vx=10,qk=56,GF=18,QF=650;function ZF(e,t){return Math.abs(e)<vx&&Math.abs(t)<vx?"pending":Math.abs(e)>Math.abs(t)&&e>0?"drag":"reject"}function JF(e){const t=e.at(-1),n=t?e.slice(0,-1).reverse().find(i=>i.x!==t.x&&t.time-i.time<=100):void 0;return n&&t&&t.time>n.time?(t.x-n.x)/(t.time-n.time)*1e3:0}function ez(e,t){const n=JF(t);return n>=0&&(e>=qk||e>=GF&&n>=QF)}const Ad="ours.chats.listMode",cs="recent";function Xk(){try{return globalThis.localStorage}catch{return}}function tz(e=Xk()){try{return e?.getItem(Ad)==="identity"?"identity":cs}catch{return cs}}function nz(e,t=Xk()){const n=e==="identity"?"identity":cs;try{return t?.setItem(Ad,n),t?.getItem(Ad)===n?n:cs}catch{return cs}}function Ss(e){return typeof e=="string"?e:""}function _l(e,t){const n=Ss(e),i=Ss(t),s=n.normalize().toLowerCase(),l=i.normalize().toLowerCase();return s<l?-1:s>l?1:n<i?-1:n>i?1:0}function rz(e,t){const n=Rl(Ss(t.activityAt))-Rl(Ss(e.activityAt));if(n!==0)return n;const i=_l(e.name,t.name);return i!==0?i:_l(e.id,t.id)}function Nd(e){return[...e].sort(rz)}function xx(e){return e.contacts.length>0?Rl(Ss(e.contacts[0].activityAt)):0}function iz(e,t){const n=new Map,i=[];for(const l of e){const a=l.root||(t?.[l.id]?l.id:null);if(!a){i.push(l);continue}const c=t?.[a]||{label:a,note:""};let d=n.get(a);d||(d={id:`root:${a}`,rootId:a,label:c.label,note:c.note,contacts:[]},n.set(a,d)),d.contacts.push(l)}const s=[...n.values()].map(l=>({...l,contacts:Nd(l.contacts)}));return i.length>0&&s.push({id:"rootless",rootId:null,label:"Independent identities",note:"People, agents and apps without a verified Human/root group",contacts:Nd(i)}),s.sort((l,a)=>{const c=xx(a)-xx(l);if(c!==0)return c;const d=_l(l.label,a.label);return d!==0?d:_l(l.id,a.id)})}const oz=15e3;function Ef(e){const{c:t,active:n,grouped:i}=e,[s,l]=k.useState(!1),a=async(h,m)=>{if(!(!h||s)){l(!0);try{const p=await h();requestAnimationFrame(()=>{p?document.getElementById("chat-list-title")?.focus():m.focus()})}finally{l(!1)}}},c=v.jsxs(v.Fragment,{children:[v.jsx("span",{className:"contact-avatar","aria-hidden":!0,children:t.initials}),v.jsxs("span",{className:"contact-copy",children:[v.jsxs("span",{className:"contact-row-topline",children:[v.jsx("span",{className:"contact-name",children:t.name}),t.when&&v.jsx("span",{className:"contact-time",children:t.when})]}),v.jsxs("span",{className:"contact-row-bottomline",children:[v.jsx("span",{className:"contact-last",children:t.last}),t.status==="pending"&&v.jsx("span",{className:"chip",children:"pending approval"}),!!t.unread&&v.jsx("span",{className:"contact-unread",children:t.unread})]})]}),t.status==="pending"&&v.jsxs("span",{className:"pending-actions",role:"group","aria-label":`Decide whether to accept ${t.name}`,children:[v.jsx("button",{type:"button",className:"linkbtn",disabled:s,onClick:h=>void a(e.onApprove,h.currentTarget),children:"Approve"}),v.jsx("button",{type:"button",className:"linkbtn quiet",disabled:s,onClick:h=>void a(e.onReject,h.currentTarget),children:"Reject"})]}),n&&v.jsx(ss.span,{className:"contact-active-glow",layoutId:"active-contact",transition:yl})]}),d="contact-row"+(n?" active":"")+(i?" grouped":"")+(t.status==="pending"?" pending":"");return t.status==="pending"?v.jsx("div",{className:d,children:c}):v.jsx(ss.button,{type:"button",className:d,onClick:e.onClick,children:c})}function sz(e){const{contacts:t,roots:n,selected:i}=e,[s,l]=k.useState(""),a=k.useRef(null),c=k.useRef(null),[d,h]=k.useState(()=>tz()),m=O=>O.name.toLowerCase().includes(s.toLowerCase()),p=t.filter(O=>O.status!=="pending"&&m(O)),y=t.filter(O=>O.status==="pending"&&m(O)),w=Nd(p),S=iz(p,n),C=p.length===0&&y.length===0,E=O=>{h(nz(O))},T=[{id:"recent",label:"Recent"},{id:"identity",label:"By identity"}],M=k.useRef(null),P=k.useRef({id:-1,x0:0,y0:0,mode:"idle"}),D=k.useRef(!1),$=(O,N)=>{const X=P.current;if(X.id!==O)return;const V=M.current;if(N&&X.mode==="drag"&&V){const fe=parseFloat(V.style.getPropertyValue("--mode-drag-x"))||0,J=Math.max(0,(V.clientWidth-8)/2);E(fe>=J/2?"identity":"recent"),D.current=!0,window.setTimeout(()=>{D.current=!1},0)}P.current={id:-1,x0:0,y0:0,mode:"idle"},V?.hasPointerCapture?.(O)&&V.releasePointerCapture(O),V?.classList.remove("dragging"),V?.style.removeProperty("--mode-drag-x")},j=O=>{!O.isPrimary||P.current.id!==-1||(P.current={id:O.pointerId,x0:O.clientX,y0:O.clientY,mode:"pending"})},Y=O=>{const N=P.current;if(N.id!==O.pointerId||N.mode==="idle")return;const X=O.clientX-N.x0,V=O.clientY-N.y0;if(N.mode==="pending"){if(Math.abs(X)<10&&Math.abs(V)<10)return;if(Math.abs(V)>Math.abs(X)){$(O.pointerId,!1);return}N.mode="drag",O.currentTarget.setPointerCapture?.(O.pointerId),O.currentTarget.classList.add("dragging")}O.preventDefault();const fe=Math.max(0,(O.currentTarget.clientWidth-8)/2),J=d==="identity"?fe:0;O.currentTarget.style.setProperty("--mode-drag-x",`${Math.min(fe,Math.max(0,J+X))}px`)},U=(O,N)=>{if(!["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End"].includes(O.key))return;O.preventDefault();const V=O.key==="Home"?"recent":O.key==="End"||N==="recent"?"identity":"recent";E(V),document.getElementById(`conversation-list-${V}`)?.focus()};return k.useLayoutEffect(()=>{const O=a.current,N=c.current;if(!O||!N)return;const X=()=>O.style.setProperty("--list-bottom-chrome-height",`${N.getBoundingClientRect().height}px`);X();const V=new ResizeObserver(X);return V.observe(N),()=>{V.disconnect(),O.style.removeProperty("--list-bottom-chrome-height")}},[]),v.jsxs("div",{className:"listcol",ref:a,children:[v.jsxs("div",{className:"listcol-head",children:[v.jsxs("div",{className:"listcol-titlebar",children:[v.jsxs("h2",{id:"chat-list-title",className:"listcol-title messenger-lockup",tabIndex:-1,children:[v.jsx("span",{className:"messenger-brand-ours",children:"Ours"}),v.jsx("span",{className:"messenger-brand-product",children:"messenger"})]}),v.jsxs("div",{className:"listcol-actions",children:[v.jsx("button",{className:"btn icon-btn desktop-invite","aria-label":"Invite",title:"Invite",onClick:e.onInvite,children:v.jsx(Ee,{name:"invite",size:18})}),v.jsx("button",{className:"icon-btn","aria-label":"Settings",title:"Settings",onClick:e.onSettings,children:v.jsx(Ee,{name:"settings",size:18})})]})]}),v.jsx("div",{ref:M,className:"conversation-list-modes",role:"tablist","aria-label":"Conversation list layout","data-mode":d,onPointerDown:j,onPointerMove:Y,onPointerUp:O=>$(O.pointerId,!0),onPointerCancel:O=>$(O.pointerId,!1),onLostPointerCapture:O=>$(O.pointerId,!1),children:T.map(O=>v.jsx("button",{id:`conversation-list-${O.id}`,type:"button",role:"tab","aria-selected":d===O.id,"aria-controls":"conversation-list-panel",tabIndex:d===O.id?0:-1,className:d===O.id?"active":"",onClick:N=>{if(D.current){N.preventDefault();return}E(O.id)},onKeyDown:N=>U(N,O.id),children:O.label},O.id))})]}),v.jsxs("div",{id:"conversation-list-panel",className:"listcol-scroll",role:"tabpanel","aria-labelledby":`conversation-list-${d}`,children:[d==="recent"&&w.length>0&&v.jsx("div",{className:"conversation-group",children:w.map(O=>v.jsx(Ef,{c:O,active:i===O.id,onClick:()=>e.onSelect(O.id)},O.id))}),d==="identity"&&S.map(O=>v.jsxs("div",{children:[v.jsxs("div",{className:"group-label",title:O.note,children:[O.rootId&&v.jsx(Ee,{name:"clusters"}),v.jsx("span",{children:O.label}),O.note&&v.jsxs("span",{className:"gl-note",children:["· ",O.note]})]}),v.jsx("div",{className:"conversation-group",children:O.contacts.map(N=>v.jsx(Ef,{c:N,grouped:O.rootId!==null,active:i===N.id,onClick:()=>e.onSelect(N.id)},N.id))})]},O.id)),y.length>0&&v.jsxs("div",{children:[v.jsx("div",{className:"group-label",children:v.jsx("span",{children:"Pending"})}),v.jsx("div",{className:"conversation-group",children:y.map(O=>v.jsx(Ef,{c:O,active:!1,onClick:()=>{},onApprove:()=>e.onApprovePending(O.id.slice(8)),onReject:()=>e.onRejectPending(O.id.slice(8))},O.id))})]}),C&&v.jsx("p",{className:"muted",style:{padding:"14px 10px",fontSize:"0.85rem"},children:"No contacts yet — share an invite to start."})]}),v.jsxs("div",{className:"list-bottom-chrome",ref:c,children:[v.jsxs("div",{className:"search adaptive-search",role:"search",children:[v.jsx("span",{className:"adaptive-search-icon","aria-hidden":!0,children:v.jsx(Ee,{name:"search"})}),v.jsx("input",{className:"field",placeholder:"Search people, agents, apps…",value:s,onChange:O=>l(O.target.value),onKeyDown:O=>{O.key==="Escape"&&(O.preventDefault(),l(""))}})]}),v.jsx("button",{type:"button",className:"icon-btn list-bottom-invite","aria-label":"Invite",title:"Invite",onClick:e.onInvite,children:v.jsx(Ee,{name:"invite",size:20})})]})]})}function az(e){const[t,n]=k.useState(!1),[i,s]=k.useState(e.contact.name),[l,a]=k.useState(!1),[c,d]=k.useState(null),h=k.useRef(!1);k.useEffect(()=>{const p=y=>{y.key!=="Escape"||l||c||t||(y.preventDefault(),e.onBack())};return document.addEventListener("keydown",p),()=>document.removeEventListener("keydown",p)},[t,c,e.onBack,l]);const m=()=>{if(h.current)return;h.current=!0;const p=i.trim();p&&p!==e.contact.name?e.onRename(p):s(e.contact.name),n(!1)};return v.jsxs("div",{className:"detail contact-screen",children:[v.jsxs("div",{className:"detail-head contact-screen-head",children:[v.jsx("button",{type:"button",className:"icon-btn detail-back contact-back","aria-label":"Back to conversation",onClick:e.onBack,children:v.jsx(Ee,{name:"back"})}),v.jsx("strong",{children:"Contact"})]}),v.jsxs("div",{className:"contact-screen-scroll",children:[v.jsxs("section",{className:"contact-hero","aria-labelledby":"contact-screen-name",children:[v.jsx("div",{className:"avatar accent contact-avatar-large","aria-hidden":!0,children:e.contact.initials}),t?v.jsx("input",{id:"contact-screen-name",className:"field contact-name-input",value:i,autoFocus:!0,onChange:p=>s(p.target.value),onBlur:m,onKeyDown:p=>{p.key==="Enter"&&m(),p.key==="Escape"&&(h.current=!0,s(e.contact.name),n(!1))}}):v.jsx("h2",{id:"contact-screen-name",children:e.contact.name}),v.jsxs("p",{children:[v.jsx(Ee,{name:"lock",size:13})," End-to-end encrypted connection"]})]}),v.jsxs("section",{className:"contact-action-group","aria-label":"Contact actions",children:[v.jsxs("button",{type:"button",onClick:()=>a(!0),children:[v.jsxs("span",{children:[v.jsx(Ee,{name:"paperclip"}),"Shared photos, files, and links"]}),v.jsx(Ee,{name:"chevron"})]}),v.jsxs("button",{type:"button",onClick:()=>{h.current=!1,s(e.contact.name),n(!0)},children:[v.jsxs("span",{children:[v.jsx(Ee,{name:"edit"}),"Rename contact"]}),v.jsx(Ee,{name:"chevron"})]})]}),v.jsxs("section",{className:"contact-identity","aria-labelledby":"contact-identity-title",children:[v.jsx("h3",{id:"contact-identity-title",children:"Verified identity"}),e.contact.roleId&&v.jsxs("p",{children:["Role ",v.jsx("strong",{children:e.contact.roleId})," of ",v.jsx("strong",{children:e.contact.rootName})]}),v.jsx("code",{children:e.contact.id}),v.jsxs("button",{type:"button",className:"btn sm",onClick:()=>void navigator.clipboard.writeText(e.contact.id),children:[v.jsx(Ee,{name:"copy",size:14}),"Copy identity"]})]}),v.jsxs("button",{type:"button",className:"contact-remove",onClick:e.onRemove,children:[v.jsx(Ee,{name:"trash"}),"Remove contact"]})]}),l&&v.jsx(NF,{messages:e.messages,indexOffset:e.indexOffset,onClose:()=>a(!1),onJump:e.onOpenMessage,onPreview:p=>{a(!1),d(p)}}),c&&(As(c.filename,c.mime)?v.jsx($k,{rec:c,onClose:()=>d(null)}):v.jsx(Bk,{rec:c,onClose:()=>d(null),onSendText:e.onSendText,onSendFile:e.onSendFile}))]})}const wx=e=>`chat-message-${encodeURIComponent(e)}`,Yk=()=>typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;function kx(e){const{dir:t,canReply:n,onReply:i}=e,s=k.useRef(null),l=k.useRef(null),a=k.useRef(null),c=k.useRef(i);c.current=i;const d=t==="in"?1:-1,h=qk,m=84,p=()=>({id:-1,x0:0,y0:0,mode:"idle",armed:!1,distance:0,samples:[]}),y=k.useRef(p()),w=M=>{const P=l.current,D=a.current,$=Yk();if(P&&(P.style.transform=M&&!$?`translateX(${M}px)`:""),D){const j=Math.min(1,Math.abs(M)/h);D.style.opacity=String(j),D.style.transform=$?"scale(1)":`scale(${.5+.5*j})`}},S=(M,P)=>{const D=y.current;if(D.id!==M)return;const $=P&&D.mode==="drag"&&ez(D.distance,D.samples);y.current=p(),l.current?.classList.remove("swiping"),a.current?.classList.remove("armed"),w(0);const j=s.current;j?.hasPointerCapture?.(M)&&j.releasePointerCapture(M),$&&c.current()};k.useEffect(()=>{const M=s.current;if(!M)return;const P=D=>S(D.pointerId,!1);return M.addEventListener("lostpointercapture",P),()=>{M.removeEventListener("lostpointercapture",P);const D=y.current.id;D!==-1&&S(D,!1)}},[]);const C=M=>{const P=M.target,D=window.getSelection?.();!n||!M.isPrimary||M.pointerType==="mouse"||M.pointerType==="pen"&&M.button!==0||y.current.id!==-1||D&&!D.isCollapsed||P.closest('a, button, input, textarea, select, [role="button"], audio, video, img, [draggable="true"], .filecard, .filecard-bubble, .image-bubble, .voice-bubble, .ours-message-file, .attachment')||(y.current={id:M.pointerId,x0:M.clientX,y0:M.clientY,mode:"maybe",armed:!1,distance:0,samples:[{x:M.clientX*d,time:M.timeStamp}]},w(0))},E=M=>{const P=y.current;if(P.id!==M.pointerId||P.mode==="idle")return;const D=M.clientX-P.x0,$=M.clientY-P.y0,j=window.getSelection?.();if(j&&!j.isCollapsed){S(M.pointerId,!1);return}if(P.mode==="maybe"){const X=ZF(D*d,$);if(X==="pending")return;if(X==="drag")P.mode="drag",M.currentTarget.setPointerCapture?.(M.pointerId),l.current?.classList.add("swiping");else{P.mode="idle";return}}M.preventDefault();const Y=M.timeStamp;P.samples.push({x:M.clientX*d,time:Y}),P.samples=P.samples.filter(X=>Y-X.time<=120);let U=D*d;U<0&&(U=0),U>h&&(U=h+(U-h)*.35),U=Math.min(U,m),P.distance=U;const O=U*d,N=Math.abs(O)>=h;N!==P.armed&&(P.armed=N,a.current?.classList.toggle("armed",N),N&&navigator.vibrate?.(10)),w(O)},T=M=>{const P=y.current;P.id===M.pointerId&&P.mode==="drag"&&(P.samples.push({x:M.clientX*d,time:M.timeStamp}),P.distance=Math.max(0,(M.clientX-P.x0)*d),P.armed=P.distance>=h),S(M.pointerId,!0)};return v.jsxs("div",{ref:s,className:"msg-row "+(e.rowClass??t),style:n?{touchAction:"pan-y"}:void 0,onPointerDown:C,onPointerMove:E,onPointerUp:T,onPointerCancel:M=>S(M.pointerId,!1),onLostPointerCapture:M=>S(M.pointerId,!1),children:[n&&v.jsx("span",{className:"swipe-cue",ref:a,"aria-hidden":!0,children:v.jsx(Ee,{name:"reply",size:16})}),v.jsx("div",{className:"bubble-wrap",ref:l,children:e.children}),e.after]})}function lz(e){const{contact:t,messages:n}=e,[i,s]=k.useState(""),[l,a]=k.useState(!1),[c,d]=k.useState(null),[h,m]=k.useState(null),[p,y]=k.useState(null),[w,S]=k.useState(null),[C,E]=k.useState(null),[T,M]=k.useState(!1),[P,D]=k.useState(!1),[$,j]=k.useState(!1),[Y,U]=k.useState(null),O=k.useRef(null),N=k.useRef(null),X=k.useRef(null),V=k.useRef(null),fe=k.useRef(null),J=k.useRef(!1),ee=k.useRef(null),xe=k.useRef(!1),[Pe,Q]=k.useState(!1),[de,R]=k.useState(0),F=k.useRef(null),G=k.useRef(!0),A=k.useRef(null),te=k.useRef(0),ge=k.useRef(null),ye=k.useRef(new Map),me=k.useRef(0),we=k.useRef(null),pe=k.useRef(null),Ve=k.useRef(0),qe=k.useRef(null);k.useLayoutEffect(()=>{const _=X.current,Z=V.current,he=fe.current;if(!_||!Z||!he)return;let De=-1,W=-1,le=null;const ne=()=>{const ke=Math.round(Z.getBoundingClientRect().height),ce=Math.round(he.getBoundingClientRect().height);if(ke!==De&&(De=ke,_.style.setProperty("--conversation-head-height",`${ke}px`)),ce!==W){const Ae=G.current;W=ce,_.style.setProperty("--conversation-compose-height",`${ce}px`),Ae&&(le!==null&&cancelAnimationFrame(le),le=requestAnimationFrame(()=>{le=null;const ft=ee.current;ft&&G.current&&(ft.scrollTop=Math.max(0,ft.scrollHeight-ft.clientHeight))}))}};ne();const Me=new ResizeObserver(ne);return Me.observe(Z),Me.observe(he),()=>{Me.disconnect(),le!==null&&cancelAnimationFrame(le),_.style.removeProperty("--conversation-head-height"),_.style.removeProperty("--conversation-compose-height")}},[t?.id]),k.useEffect(()=>{s(""),m(null),y(null),d(null),S(null),E(null),M(!1),D(!1),j(!1),te.current+=1,U(null),ye.current.clear(),we.current=null,pe.current=null},[t?.id]),k.useEffect(()=>{if(!p)return;const _=p.reply?.wireId;n.some(he=>he.kind!=="file"&&he.dir==="out"&&!!he.wireId&&!p.wireIds.has(he.wireId)&&he.text===p.text&&(he.replyTo?.wireId??void 0)===_)&&(y(null),m(null),s(he=>he===p.draft?"":he),S(he=>he===p.reply?null:he))},[n,p]);const it=!!c?.wireId&&n.some(_=>_.wireId===c.wireId),We=k.useMemo(()=>c&&!it?[...n,c.message]:n,[n,c,it]);k.useEffect(()=>{it&&d(null)},[it]),k.useLayoutEffect(()=>{const _=N.current;if(!_)return;_.style.height="0px";const Z=Math.max(44,Math.min(_.scrollHeight,132));_.style.height=`${Z}px`,_.style.overflowY=_.scrollHeight>132?"auto":"hidden"},[i,t?.id]);const at=_=>{const Z=ee.current;if(!Z)return;const he=Math.max(0,Z.scrollHeight-Z.clientHeight);if(Math.abs(Z.scrollTop-he)<1){we.current=null,pe.current=null;return}const De=_&&!Yk();we.current=De?he:null,pe.current=De?Z.scrollTop:null,De?Z.scrollTo({top:he,behavior:"smooth"}):Z.scrollTop=he},xt=()=>{F.current===null&&(F.current=requestAnimationFrame(()=>{F.current=null;const _=ee.current;if(!_)return;const Z=_.scrollHeight-_.clientHeight-_.scrollTop>48;Q(Z),Z||R(0)}))};k.useLayoutEffect(()=>{if(!t){A.current=null,G.current=!0,Ve.current=0;return}const _=ee.current;if(!_)return;const Z=A.current!==t.id,he=Ve.current,De=We.length!==he,W=We.at(-1),le=W?W.wireId||`${W.date}:${W.text}`:null,ne=qe.current;if(Ve.current=We.length,qe.current=le,!Z&&!De&&we.current===null&&(G.current=_.scrollHeight-_.clientHeight-_.scrollTop<=48),Z||G.current)at(De&&!Z&&A.current!==null),G.current=!0;else if(De&&We.length>he&&le!==ne){const Me=ne===null?-1:We.findIndex(ke=>(ke.wireId||`${ke.date}:${ke.text}`)===ne);R(ke=>ke+Math.max(1,We.length-Math.max(0,Me+1)))}A.current=t.id,xt()},[t,We.length]),k.useLayoutEffect(()=>{if(xe.current||!e.unreadOpen||window.location.hash.startsWith("#chat-message-"))return;const _=ee.current,Z=document.getElementById(`unread-${wx(e.unreadOpen.wireId)}`);!_||!Z||(_.scrollTop=Math.max(0,Z.offsetTop-16),G.current=!1,xe.current=!0,xt())},[e.unreadOpen,We.length]),k.useLayoutEffect(()=>{const _=window.location.hash;if(!_.startsWith("#chat-message-"))return;const Z=document.getElementById(_.slice(1));Z&&(Z.scrollIntoView({block:"center"}),G.current=!1)},[t?.id,We.length]),k.useLayoutEffect(()=>{const _=ge.current,Z=ee.current;if(_===null||!Z)return;const he=requestAnimationFrame(()=>{ge.current===_&&(Z.scrollTop=_.top+Z.scrollHeight-_.height,ge.current=null)});return()=>cancelAnimationFrame(he)},[We.length]),k.useEffect(()=>{const _=ee.current;if(!_||typeof ResizeObserver>"u")return;const Z=_.firstElementChild;if(!Z)return;const he=new ResizeObserver(()=>{G.current&&at(we.current!==null),xt()});return he.observe(Z),he.observe(_),()=>{he.disconnect(),F.current!==null&&cancelAnimationFrame(F.current)}},[t?.id]);const Vt=async _=>{const Z=++te.current;m(null),j(!0);try{if(_.size>ts&&Wk(_.type,_.name)){const De=await UF(_,ts);if(Z!==te.current)return;E({filename:De.filename,mime:De.mime,bytes:De.bytes,originalSize:De.originalSize});return}if(_.size>ts){m(`"${_.name}" is ${Fr(_.size)} — files up to ${Fr(ts)} can be sent.`);return}const he=await _.arrayBuffer();if(Z!==te.current)return;E({filename:_.name||"file",mime:_.type||"application/octet-stream",bytes:new Uint8Array(he)})}catch(he){Z===te.current&&m(`Photo optimization failed: ${he instanceof Error?he.message:String(he)}`)}finally{Z===te.current&&j(!1)}},lt=()=>{!C||!e.onSendFile||P||(D(!0),e.onSendFile(C,w?.wireId).then(()=>{E(null),S(null)}).catch(_=>m(`File send failed: ${String(_)} — it was not delivered.`)).finally(()=>D(!1)))},Pt=e.onDraftChange;k.useEffect(()=>(Pt?.(i.trim().length>0||l),()=>Pt?.(!1)),[i,l,Pt]);const fn=new Map;for(const _ of We)_.wireId&&fn.set(_.wireId,_);const It=k.useMemo(()=>{const _=new Map;for(const Z of We)_.set(Z,Z.kind==="file"?null:Z.dir==="in"?y2(t?.announcedName??"",Z.text):null);return _},[We,t?.announcedName]),jt=_=>It.get(_)??null,Ln=_=>{if(_.dir==="out")return"You";const Z=jt(_);return Z&&Z.variant==="chat"?Z.author:t?.name??"Them"},ze=_=>{if(_.kind==="file")return _.mime?.startsWith("image/")?"Photo":eo(_.mime??"",_.filename??"")?"Voice message":_.filename||"File";const Z=jt(_);return Z?Z.text||C2(Z):_.text},ur=_=>{if(!_.replyTo)return null;const Z=fn.get(_.replyTo.wireId);return Z?{author:Ln(Z),text:ze(Z)}:{author:"",text:"Original message"}};if(!t)return e.emptyOverride?v.jsx(v.Fragment,{children:e.emptyOverride}):v.jsx("div",{className:"detail",children:v.jsxs("div",{className:"detail-empty",children:[v.jsx(Ee,{name:"chat"}),v.jsxs("div",{children:[v.jsx("div",{style:{fontWeight:650,color:"var(--text-2)"},children:"Select a conversation"}),v.jsx("div",{style:{fontSize:"0.85rem"},children:"Chat with people, agents and apps across ours."})]})]})});const bn=async()=>{const _=i,Z=_.trim(),he=!!p&&_===p.draft&&(w?.wireId??void 0)===p.reply?.wireId;if(!Z||J.current||he)return;p&&y(null),J.current=!0,a(!0),m(null);const De=w,W=De?.wireId,le=new AbortController;let ne=!1,Me=0;s(""),S(null);const ke=`optimistic-${++me.current}`;d({key:ke,wireId:null,message:{dir:"out",text:Z,date:new Date().toISOString(),read:!0,wireId:"",replyTo:W?{wireId:W}:null}});try{const ce=await Promise.race([e.onSend(Z,W,le.signal),new Promise((Ae,ft)=>{Me=window.setTimeout(()=>{ne=!0,le.abort(),ft(new Error("send timeout"))},oz)})]);ce?(ye.current.set(ce,ke),d(Ae=>Ae?.key===ke?{...Ae,wireId:ce}:Ae)):d(Ae=>Ae?.key===ke?null:Ae),y(null)}catch(ce){d(null),s(Ae=>Ae===""?_:Ae),S(Ae=>Ae===null?De:Ae),ne||!(ce instanceof Qf)?(y({draft:_,text:Z,reply:De,wireIds:new Set(n.flatMap(Ae=>Ae.wireId?[Ae.wireId]:[]))}),m(`${ne?"Send timed out":"Send connection was interrupted"} — delivery status is unknown. Check the conversation; edit the draft before sending again.`)):m(`Send failed: ${String(ce)} — the message was not delivered.`)}finally{window.clearTimeout(Me),J.current=!1,a(!1)}},q=!!p&&i===p.draft&&(w?.wireId??void 0)===p.reply?.wireId,se=_=>{_.wireId&&S({wireId:_.wireId,author:Ln(_),text:ze(_)})};return v.jsxs("div",{className:"detail detail-chat",ref:X,children:[v.jsx("div",{className:"detail-head",ref:V,children:v.jsxs("div",{className:"conv-peer",children:[v.jsx("button",{className:"icon-btn detail-back","aria-label":"Back to conversations",onClick:e.onBack,children:v.jsx(Ee,{name:"back"})}),v.jsxs("div",{className:"conv-peer-status",children:[v.jsx("span",{className:"conv-peer-name",children:t.name}),e.syncing&&v.jsxs("div",{className:"conv-sync",role:"status","aria-live":"polite",children:[v.jsx("span",{className:"conv-sync-dot","aria-hidden":!0}),e.syncing==="connecting"?"Connecting…":"Updating…"]}),!e.syncing&&v.jsxs("span",{className:"conv-contact-status",children:[v.jsx(Ee,{name:"lock",size:11}),"Encrypted connection"]})]}),v.jsx("button",{type:"button",className:"conv-contact-trigger conv-contact-avatar","data-contact-trigger":!0,onClick:e.onOpenContact,disabled:!e.onOpenContact,"aria-label":`Open contact details for ${t.name}`,children:v.jsx("span",{className:"conv-contact-initials","aria-hidden":!0,children:t.initials})})]})}),v.jsx("div",{className:"messages",ref:ee,tabIndex:-1,"aria-label":"Conversation timeline",onScroll:_=>{const Z=_.currentTarget,he=Z.scrollHeight-Z.clientHeight-Z.scrollTop;if(we.current!==null){const De=pe.current;if(De===null||Z.scrollTop>=De-1){pe.current=Z.scrollTop,he<=4&&(we.current=null,pe.current=null);return}we.current=null,pe.current=null}G.current=he<=48,xt()},onPointerDown:()=>{we.current=null,pe.current=null},onTouchStart:()=>{we.current=null,pe.current=null},onWheel:()=>{we.current=null,pe.current=null},onDragOver:_=>{e.onSendFile&&_.preventDefault()},onDrop:_=>{if(!e.onSendFile)return;_.preventDefault();const Z=_.dataTransfer.files?.[0];Z&&Vt(Z)},children:v.jsxs("div",{className:"messages-inner",children:[v.jsxs("div",{className:"e2e-note",children:[v.jsx(Ee,{name:"lock"}),"End-to-end encrypted · the broker only sees ciphertext"]}),(e.hiddenEarlier??0)>0&&e.onLoadEarlier&&v.jsxs("button",{className:"btn sm chat-load-earlier",onClick:()=>{G.current=!1;const _=ee.current;ge.current=_?{height:_.scrollHeight,top:_.scrollTop}:null,e.onLoadEarlier?.()},children:["Load earlier messages (",e.hiddenEarlier," remaining)"]}),v.jsx(qP,{initial:!1,children:We.map((_,Z)=>{const he=_===c?.message?c.key:_.wireId&&ye.current.get(_.wireId)||_.wireId||`${_.date}-${(e.hiddenEarlier??0)+Z}`,De=wx(_.wireId||he),W=We[Z-1],le=We[Z+1],ne=jt(_),Me=Ge=>{if(!Ge)return null;const Ye=jt(Ge);return Ye?Ye.variant==="system"?"room:system":`room:chat:${Ye.author}${Ye.role}`:Ge.dir},ke=Me(_),ce=!!W&&Me(W)===ke&&ke!=="room:system",Ae=!!le&&Me(le)===ke&&ke!=="room:system",ft=(_.dir==="out"?"out":"in")+(ce?" cont-top":"")+(Ae?" cont-bot":""),nn=_.wireId?v.jsx("button",{className:"msg-reply",title:"Reply",onClick:()=>se(_),children:v.jsx(Ee,{name:"reply",size:15})}):null;if(ne&&ne.variant==="system"){const Ge=ne.presentation??"system";return v.jsxs(ss.div,{className:"message-motion",id:De,initial:{opacity:0,y:8},animate:{opacity:1,y:0},exit:{opacity:0},transition:yl,children:[_.wireId===e.unreadOpen?.wireId&&v.jsx("div",{id:`unread-${De}`,className:"unread-divider",role:"separator",children:v.jsx("span",{children:"Unread messages"})}),v.jsxs("div",{className:`room-system room-${Ge}-card`,role:"note",children:[ne.label&&v.jsx("span",{className:"room-system-label",children:ne.label}),ne.roomName&&v.jsx("strong",{className:"room-card-name",children:ne.roomName}),v.jsx(yx,{text:ne.text,className:"room-system-text message-markdown"}),!!ne.details?.length&&v.jsx("ul",{className:"room-card-details","aria-label":"Room event details",children:ne.details.map(Ye=>v.jsx("li",{children:Ye},Ye))}),v.jsxs("span",{className:"room-card-provenance",children:[ne.authoredBy&&v.jsx("span",{className:"room-card-author",children:ne.authoredBy}),v.jsx("span",{className:"room-system-at",children:ys(ne.authoredAt||_.date)})]})]})]},he)}if(_.kind==="file"){const Ge=S0(_.wireId)??{id:_.wireId,dir:_.dir,filename:_.filename??"file",mime:_.mime??"application/octet-stream",size:0,date:_.date};return v.jsxs(ss.div,{className:"message-motion",id:De,initial:{opacity:0,y:12,scale:.985},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,scale:.98},transition:yl,children:[_.wireId===e.unreadOpen?.wireId&&v.jsx("div",{id:`unread-${De}`,className:"unread-divider",role:"separator",children:v.jsx("span",{children:"Unread messages"})}),v.jsx(kx,{dir:_.dir==="out"?"out":"in",rowClass:ft,canReply:!!_.wireId,onReply:()=>se(_),after:nn,children:v.jsx("div",{className:`ours-message ours-message-file ours-message--${_.dir}`,children:v.jsx(CD,{rec:Ge,receipt:_.receipt,receiptless:_.receiptless,onPreview:U,onFetch:e.onFetchFile})})})]},he)}const ot=ur(_);return v.jsxs(ss.div,{className:"message-motion",id:De,initial:{opacity:0,y:12,scale:.985},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,scale:.98},transition:yl,children:[_.wireId===e.unreadOpen?.wireId&&v.jsx("div",{id:`unread-${De}`,className:"unread-divider",role:"separator",children:v.jsx("span",{children:"Unread messages"})}),v.jsx(kx,{dir:_.dir==="out"?"out":"in",rowClass:ft,canReply:!!_.wireId,onReply:()=>se(_),after:nn,children:v.jsxs("div",{className:`ours-message ours-message--${_.dir}`,children:[ot&&v.jsxs("div",{className:"quote",children:[ot.author&&v.jsx("span",{className:"quote-author",children:ot.author}),v.jsx("span",{className:"quote-text",children:ot.text})]}),ne&&!ce&&v.jsxs(v.Fragment,{children:[ne.roomName&&v.jsx("div",{className:"room-message-room",children:ne.roomName}),v.jsxs("div",{className:"room-author",children:[v.jsx("span",{className:"room-author-name",children:ne.author}),ne.role&&v.jsx("span",{className:"room-author-role",children:ne.role})]})]}),v.jsx(yx,{text:ne?ne.text:_.text}),v.jsxs("div",{className:"bubble-at",children:[ys(ne?.authoredAt||_.date),_.dir==="out"&&v.jsx(b0,{receipt:_.receipt,receiptless:_.receiptless})]})]})})]},he)})}),v.jsx("div",{className:"thread-end","aria-hidden":!0})]})},t.id),Pe&&v.jsxs("button",{type:"button",className:"jump-latest btn sm","aria-label":de?`Jump to latest, ${de} new messages`:"Jump to latest",onClick:_=>{const Z=_.currentTarget===document.activeElement;R(0),at(!0),Z&&requestAnimationFrame(()=>ee.current?.focus({preventScroll:!0}))},children:[v.jsx("span",{children:"Jump to latest"}),!!de&&v.jsx("span",{className:"jump-latest-count","aria-live":"polite",children:de})]}),h&&v.jsxs("div",{className:"banner error",role:"alert",children:[h,h.startsWith("Send failed:")&&v.jsx("span",{className:"banner-actions",children:v.jsx("button",{className:"linkbtn",onClick:()=>void bn(),children:"retry"})})]}),v.jsxs("div",{className:"composer-wrap",ref:fe,children:[w&&v.jsxs("div",{className:"reply-bar",children:[v.jsx("div",{className:"reply-bar-line"}),v.jsxs("div",{className:"reply-bar-body",children:[v.jsxs("div",{className:"reply-bar-author",children:["Replying to ",w.author]}),v.jsx("div",{className:"reply-bar-text",children:w.text})]}),v.jsx("button",{className:"icon-btn",title:"Cancel reply",onClick:()=>S(null),children:v.jsx(Ee,{name:"close",size:16})})]}),C&&v.jsx(w1,{att:C,sending:P,onSend:lt,onDiscard:()=>E(null)}),$&&v.jsx("div",{className:"attachment-processing",role:"status",children:"Optimizing photo for secure delivery…"}),v.jsxs("div",{className:"composer"+(T?" recording":""),children:[e.onSendFile&&v.jsxs(v.Fragment,{children:[v.jsx("input",{ref:O,type:"file",style:{display:"none"},onChange:_=>{const Z=_.target.files?.[0];Z&&Vt(Z),_.target.value=""}}),v.jsx("button",{className:"icon-btn composer-tool",title:"Attach a file or photo",disabled:P||$||T,onClick:()=>O.current?.click(),children:v.jsx(Ee,{name:"paperclip",size:18})})]}),v.jsx("textarea",{ref:N,className:"field",rows:1,placeholder:(w?"Reply to "+w.author:"Message "+t.name)+"…",value:i,"aria-busy":l,onChange:_=>s(_.target.value),onKeyDown:_=>{_.key==="Enter"?!(window.matchMedia("(pointer: coarse)").matches||window.innerWidth<=860)&&!_.shiftKey&&(_.preventDefault(),bn()):_.key==="Escape"&&S(null)}}),e.onSendFile&&!i.trim()&&!C&&!$&&!P?v.jsx(k1,{disabled:P||$||!!C,onReady:_=>{M(!1),E(_)},onError:_=>{M(!1),m(_)},onActiveChange:M},t.id):v.jsxs("button",{className:"btn primary","aria-label":"Send",onPointerDown:_=>{_.button===0&&document.activeElement===N.current&&_.preventDefault()},onClick:()=>void bn(),disabled:l||q||!i.trim(),title:q?"Delivery status unknown — edit before sending again":void 0,children:[v.jsx(Ee,{name:"send",size:16}),v.jsx("span",{className:"btn-label",children:"Send"})]})]})]}),Y&&(As(Y.filename,Y.mime)?v.jsx($k,{rec:Y,onClose:()=>U(null)}):v.jsx(Bk,{rec:Y,onClose:()=>U(null),onSendText:e.onSend,onSendFile:e.onSendFile}))]})}const Gk=3;function uz(e,t,n=Gk){return[t,...e.filter(i=>i.cid!==t.cid)].slice(0,n)}function cz(e,t){return e.filter(n=>n.id!==t)}const fz=6e3,dz=uz,hz=cz;function pz(){const[e,t]=k.useState([]),n=k.useRef(0),i=k.useCallback((a,c,d)=>{const h=Date.now(),m={id:`${a}:${h}:${n.current++}`,cid:a,name:c,preview:"",at:h};t(p=>dz(p,m,Gk))},[]),s=k.useCallback(a=>t(c=>hz(c,a)),[]),l=k.useCallback(a=>t(c=>c.filter(d=>d.cid!==a)),[]);return{toasts:e,push:i,dismiss:s,clear:l}}function mz(e){const{item:t,onOpen:n,onDismiss:i}=e,[s,l]=k.useState(!1),[a,c]=k.useState(!1),d=s||a;return k.useEffect(()=>{if(d)return;const h=setTimeout(()=>i(t.id),fz);return()=>clearTimeout(h)},[t.id,d,i]),v.jsxs("div",{className:"banner msg",role:"status",onMouseEnter:()=>l(!0),onMouseLeave:()=>l(!1),onFocus:()=>c(!0),onBlur:h=>{h.currentTarget.contains(h.relatedTarget)||c(!1)},children:[v.jsxs("button",{className:"msg-open",title:`Open the conversation with ${t.name}`,onClick:()=>n(t.cid),children:[v.jsx("span",{className:"avatar sm accent","aria-hidden":"true",children:rd(t.name)}),v.jsxs("span",{className:"msg-text",children:[v.jsx("strong",{className:"msg-name",children:t.name}),v.jsx("span",{className:"msg-preview",children:t.preview||"New message"})]})]}),v.jsx("button",{className:"icon-btn msg-close",title:"Dismiss","aria-label":`Dismiss the notification from ${t.name}`,onClick:()=>i(t.id),children:v.jsx(Ee,{name:"close",size:15})})]})}function gz(e){return v.jsx(v.Fragment,{children:e.items.map(t=>v.jsx(mz,{item:t,onOpen:e.onOpen,onDismiss:e.onDismiss},t.id))})}function yz(e){const t=k.useRef(null),{text:n,size:i=240}=e;return k.useEffect(()=>{if(!t.current||!n)return;const s=t.current;Ch(()=>import("./browser-CqRIlH-x.js").then(l=>l.b),[]).then(l=>{l.toCanvas(s,n,{width:i,margin:2,errorCorrectionLevel:"M",color:{dark:"#000000",light:"#ffffff"}})})},[n,i]),v.jsx("div",{style:{display:"flex",justifyContent:"center",margin:"8px 0"},children:v.jsx("canvas",{ref:t,"data-testid":"qr-canvas","data-invite":n,width:i,height:i,style:{borderRadius:8,border:"1px solid var(--line)",imageRendering:"pixelated"}})})}function vz(e){const t=k.useRef(null),n=k.useRef(null),i=k.useRef(null),s=k.useRef(0),l=k.useRef(!0),[a,c]=k.useState("requesting"),[d,h]=k.useState(""),m=k.useCallback(()=>{s.current&&cancelAnimationFrame(s.current),i.current&&(i.current.getTracks().forEach(w=>w.stop()),i.current=null),t.current&&(t.current.srcObject=null)},[]),p=k.useCallback(w=>{i.current=w;const S=t.current;S.srcObject=w,S.setAttribute("playsinline","true"),S.play();const C=n.current,E=C.getContext("2d"),T=()=>{if(l.current)if(S.readyState>=S.HAVE_ENOUGH_DATA){const M=S.videoWidth||320,P=S.videoHeight||240;C.width=M,C.height=P,E.drawImage(S,0,0,M,P);const D=E.getImageData(0,0,M,P);Ch(()=>import("./jsQR-Bf0UGUa9.js").then($=>$.j),[]).then($=>{const j=$.default,Y=j(D.data,D.width,D.height,{inversionAttempts:"dontInvert"});if(Y&&Y.data&&l.current){m(),e.onDecode(Y.data);return}l.current&&(s.current=requestAnimationFrame(T))})}else s.current=requestAnimationFrame(T)};s.current=requestAnimationFrame(T)},[m,e]);k.useEffect(()=>{if(l.current=!0,!navigator.mediaDevices?.getUserMedia){c("nocamera");return}return navigator.mediaDevices.getUserMedia({video:{facingMode:"environment"}}).then(w=>{if(!l.current){w.getTracks().forEach(S=>S.stop());return}c("scanning"),p(w)}).catch(w=>{if(!l.current)return;const S=w.name??"";S==="NotAllowedError"||S==="PermissionDeniedError"?c("denied"):S==="NotFoundError"||S==="DevicesNotFoundError"?c("nocamera"):(c("error"),h(w.message??String(w)))}),()=>{l.current=!1,m()}},[]);const y=()=>{m(),e.onClose()};return v.jsxs("div",{"data-testid":"qr-scanner",style:{display:"flex",flexDirection:"column",gap:12,padding:"12px 0"},children:[(a==="requesting"||a==="scanning")&&v.jsxs(v.Fragment,{children:[v.jsx("p",{className:"muted",style:{margin:0,fontSize:"0.88rem"},children:a==="requesting"?"Requesting camera…":"Point your camera at the QR code."}),v.jsxs("div",{style:{position:"relative",borderRadius:8,overflow:"hidden",background:"#000",minHeight:200},children:[v.jsx("canvas",{ref:n,"data-testid":"scanner-canvas",style:{display:"none"}}),v.jsx("video",{ref:t,"data-testid":"scanner-video",muted:!0,playsInline:!0,style:{width:"100%",display:"block",borderRadius:8}}),a==="scanning"&&v.jsx("div",{style:{position:"absolute",inset:0,pointerEvents:"none",display:"flex",alignItems:"center",justifyContent:"center"},children:v.jsx("div",{style:{width:160,height:160,borderRadius:12,border:"2px solid var(--accent)",boxShadow:"0 0 0 9999px rgba(0,0,0,0.4)"}})})]})]}),a==="denied"&&v.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[v.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,color:"var(--text-2)"},children:[v.jsx(Ee,{name:"shield",size:16}),v.jsx("span",{style:{fontWeight:600,fontSize:"0.9rem"},children:"Camera access denied"})]}),v.jsx("p",{className:"muted",style:{margin:0,fontSize:"0.88rem"},children:"Camera permission was denied. To scan QR codes, allow camera access in your browser settings, then try again. Or paste the invite text below instead."})]}),a==="nocamera"&&v.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[v.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,color:"var(--text-2)"},children:[v.jsx(Ee,{name:"close",size:16}),v.jsx("span",{style:{fontWeight:600,fontSize:"0.9rem"},children:"No camera available"})]}),v.jsx("p",{className:"muted",style:{margin:0,fontSize:"0.88rem"},children:"No camera was found on this device. Paste the invite text below instead."})]}),a==="error"&&v.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8},children:v.jsxs("p",{style:{margin:0,fontSize:"0.85rem",color:"var(--danger, #e53)"},children:["Camera error: ",d||"unknown error",". Paste the invite text below instead."]})}),v.jsx("button",{className:"btn",style:{justifyContent:"center"},onClick:y,children:a==="scanning"?v.jsxs(v.Fragment,{children:[v.jsx(Ee,{name:"close",size:14}),"Cancel scan"]}):v.jsxs(v.Fragment,{children:[v.jsx(Ee,{name:"close",size:14}),"Close scanner"]})})]})}function xz(e){const[t,n]=k.useState("generate"),[i,s]=k.useState("one_time"),[l,a]=k.useState(""),[c,d]=k.useState(null),[h,m]=k.useState("one_time"),[p,y]=k.useState(""),[w,S]=k.useState(""),[C,E]=k.useState(!1),[T,M]=k.useState(null),[P,D]=k.useState(null),[$,j]=k.useState(!1),[Y,U]=k.useState(null),O=k.useRef(!1),N=async()=>{if(!O.current){O.current=!0,E(!0),D(null),M(null);try{m(i),d(await e.onCreate(i,i==="one_time"&&l.trim()||void 0))}catch(V){D(V instanceof Error?V.message:String(V))}finally{O.current=!1,E(!1)}}},X=v.jsx(Uk,{className:"modal-tabs",label:"Invite mode",options:[{id:"generate",label:"Generate invite"},{id:"accept",label:"Accept invite"}],value:t,onChange:n,idPrefix:"invite-tab",panelId:"invite-panel"});return v.jsx(Ds,{title:t==="generate"?"Invite a contact":"Accept an invite",onClose:()=>{O.current||e.onClose()},tabs:X,children:v.jsxs("div",{id:"invite-panel",role:"tabpanel","aria-labelledby":`invite-tab-${t}`,children:[t==="generate"&&!c&&v.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:13},children:[v.jsxs("p",{className:"muted","data-testid":"invite-identity",style:{margin:0,fontSize:"0.85rem"},children:["Creating as ",v.jsx("strong",{children:e.identity.name})," · ",v.jsxs("span",{className:"mono",children:["@",w0(e.identity.cid)]})]}),v.jsxs("div",{role:"radiogroup","aria-label":"Invite kind",style:{display:"flex",flexDirection:"column",gap:7},children:[v.jsxs("label",{children:[v.jsx("input",{type:"radio",name:"invite-kind",checked:i==="one_time",onChange:()=>s("one_time")})," One person (one time)"]}),v.jsxs("label",{children:[v.jsx("input",{type:"radio",name:"invite-kind",checked:i==="public",onChange:()=>s("public")})," Reusable public invite"]})]}),i==="one_time"?v.jsxs(v.Fragment,{children:[v.jsx("p",{className:"muted",style:{margin:0,fontSize:"0.9rem"},children:"Optionally name the person or agent this invite is for."}),v.jsx("input",{className:"field",value:l,onChange:V=>a(V.target.value),placeholder:"Their name (optional), e.g. Bob",maxLength:64})]}):v.jsx("p",{className:"onb-warning","data-testid":"public-invite-warning",style:{margin:0,fontSize:"0.9rem"},children:"Anyone with this invite can connect until you revoke it. It has no expiry and stays valid across server restarts."}),v.jsx("button",{className:"btn primary",style:{justifyContent:"center"},disabled:C,onClick:()=>void N(),children:C?"Generating…":i==="public"?"Create public invite":"Generate invite"}),i==="public"&&v.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[v.jsx("h4",{style:{margin:0,fontSize:"0.9rem"},children:"Active reusable invites"}),e.invites.filter(V=>V.mode==="public").length===0&&v.jsx("p",{className:"muted",style:{margin:0},children:"None right now."}),e.invites.filter(V=>V.mode==="public").map(V=>v.jsxs("div",{"data-testid":"public-invite-row",style:{padding:"8px 10px",background:"var(--inset)",borderRadius:7},children:[v.jsx("span",{className:"mono",children:V.invite_id}),v.jsxs("p",{className:"muted",children:["Created ",V.created?R2(V.created):"unknown"," · Active until revoked · No expiry"]}),Y===V.invite_id?v.jsxs("span",{children:[v.jsx("button",{className:"btn sm danger",onClick:()=>void e.onRevoke(V.invite_id).then(()=>(U(null),e.onRefresh())).catch(fe=>D(String(fe))),children:"Confirm revoke"})," ",v.jsx("button",{className:"btn sm",onClick:()=>U(null),children:"Keep it"})]}):v.jsx("button",{className:"btn sm",onClick:()=>U(V.invite_id),children:"Revoke"})]},V.invite_id))]}),T&&v.jsx("p",{className:"muted",children:T}),P&&v.jsx("p",{className:"onb-error",children:P})]}),t==="generate"&&c&&v.jsxs(v.Fragment,{children:[v.jsx("p",{className:"muted","data-testid":h==="public"?"public-result-note":void 0,children:h==="public"?"Shown only on this screen. Copy it now; the text cannot be recovered later. The invite stays active until revoked.":`Send this invite to ${l.trim()||"your contact"}. It can be redeemed once.`}),v.jsx("textarea",{className:"field mono","data-testid":"invite-result-text",readOnly:!0,rows:5,value:c,onFocus:V=>V.currentTarget.select()}),h==="one_time"&&v.jsx(yz,{text:c}),v.jsxs("button",{className:"btn primary",onClick:()=>void navigator.clipboard.writeText(c).then(()=>M("Copied to clipboard.")),children:[v.jsx(Ee,{name:"copy",size:15}),"Copy invite"]}),h==="public"&&v.jsx("button",{className:"btn","data-testid":"done-hide-invite",onClick:()=>{d(null),a(""),e.onRefresh()},children:"Done — hide invite"}),T&&v.jsx("p",{className:"muted",children:T})]}),t==="accept"&&v.jsxs("form",{style:{display:"flex",flexDirection:"column",gap:13},onSubmit:V=>{V.preventDefault(),!(!p.trim()||C)&&(E(!0),D(null),e.onAccept(p.trim(),w.trim()||void 0).then(()=>{M("Invite accepted — the contact will appear once the sender verifies your identity."),y(""),S("")}).catch(fe=>D(String(fe))).finally(()=>E(!1)))},children:[v.jsx("p",{className:"muted",children:"Paste the invite you received, or scan a QR code."}),$?v.jsx(vz,{onDecode:V=>{y(V),j(!1)},onClose:()=>j(!1)}):v.jsxs("button",{type:"button",className:"btn",onClick:()=>j(!0),children:[v.jsx(Ee,{name:"monitor",size:15}),"Scan QR code"]}),v.jsx("textarea",{className:"field mono","aria-label":"Invite",rows:5,value:p,onChange:V=>y(V.target.value),placeholder:"Paste invite text…"}),v.jsx("input",{className:"field",value:w,onChange:V=>S(V.target.value),placeholder:"Rename them (optional)",maxLength:64}),v.jsx("button",{className:"btn primary",type:"submit",disabled:C||!p.trim(),children:C?"Connecting…":"Add contact"}),T&&v.jsx("p",{className:"muted",children:T}),P&&v.jsx("p",{className:"onb-error",children:P})]})]})})}function wz(e){const[t,n]=k.useState(e.identity.bio??""),[i,s]=k.useState(!1),[l,a]=k.useState(null),[c,d]=k.useState(e.push.preview),h=xM(),m=!e.workerSupported||e.push.status==="unsupported"?h??"Unavailable — requires a secure browser with service-worker support.":e.push.status==="needs-permission"?h??"Needs permission — allow notifications, then choose Enable or Repair.":e.push.status==="on"?"On — this browser and the server agree on the current Web Push configuration.":e.push.status==="repairing"?"Repairing — checking the browser subscription and server acknowledgement…":e.push.status==="error"?"Repair needed — the browser and server could not confirm the same subscription.":"Off — enable notifications for this browser.";return v.jsxs(Ds,{title:"Settings",onClose:e.onClose,wide:!0,children:[v.jsxs("div",{children:[v.jsx("span",{className:"lbl",children:"Display name"}),v.jsx("input",{className:"field",readOnly:!0,value:e.identity.name})]}),v.jsxs("div",{children:[v.jsx("span",{className:"lbl",children:"Your address"}),v.jsx("input",{className:"field mono",readOnly:!0,value:e.identity.cid,onFocus:p=>p.currentTarget.select()}),v.jsx("p",{className:"muted",children:"Your public address on ours. Share an invite to connect more easily."})]}),v.jsxs("div",{children:[v.jsx("span",{className:"lbl",children:"Public bio"}),v.jsx("textarea",{className:"field",rows:3,value:t,onChange:p=>{n(p.target.value),s(!1),a(null)}}),v.jsx("button",{className:"btn sm",onClick:()=>{a(null),e.onSaveBio(t).then(()=>s(!0)).catch(p=>a(String(p)))},children:i?"Saved":"Save bio"}),l&&v.jsx("p",{className:"onb-error",children:l})]}),v.jsxs("label",{style:{display:"flex",gap:9},children:[v.jsx("input",{type:"checkbox",checked:e.dark,onChange:e.onToggleDark})," Dark mode"]}),v.jsxs("div",{style:{borderTop:"1px solid var(--line)",paddingTop:16},children:[v.jsx("h4",{children:"Notifications"}),v.jsx("p",{className:e.push.status==="needs-permission"||e.push.status==="error"?"onb-error":"muted",children:m}),h&&h!==m&&v.jsx("p",{className:"muted","data-testid":"push-platform-guidance",children:h}),v.jsxs("fieldset",{style:{border:0,padding:0,margin:"12px 0"},children:[v.jsx("legend",{className:"lbl",children:"Lock-screen preview"}),v.jsxs("label",{style:{display:"block",marginTop:7},children:[v.jsx("input",{type:"radio",name:"push-preview",checked:c==="full",onChange:()=>d("full")})," Full — sender and message text or filename"]}),v.jsxs("label",{style:{display:"block",marginTop:7},children:[v.jsx("input",{type:"radio",name:"push-preview",checked:c==="private",onChange:()=>d("private")})," Private — generic content only"]})]}),v.jsx("p",{className:"muted",children:"Full previews can expose sender names, message text, and filenames on the lock screen. The push provider still sees delivery endpoint, timing, and payload size metadata in either mode."}),v.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:e.push.status==="on"?v.jsxs(v.Fragment,{children:[v.jsx("button",{className:"btn",disabled:e.busy,onClick:()=>void e.onPushAction("disable",c),children:"Disable notifications"}),v.jsx("button",{className:"btn",disabled:e.busy,onClick:()=>void e.onPushAction("repair",c),children:"Repair"}),c!==e.push.preview&&v.jsx("button",{className:"btn primary",disabled:e.busy,onClick:()=>void e.onPushAction("enable",c),children:"Save preview"})]}):v.jsx("button",{className:"btn primary",disabled:e.busy||!e.workerSupported||e.push.status==="unsupported",onClick:()=>void e.onPushAction(e.push.status==="error"||e.push.blocked?"repair":"enable",c),children:e.busy?"Repairing…":e.push.status==="error"||e.push.blocked?"Repair":"Enable notifications"})})]}),v.jsxs("div",{style:{borderTop:"1px solid var(--line)",paddingTop:16},children:[v.jsx("h4",{children:"App status"}),v.jsx("p",{className:"muted",children:e.offline?"Offline — reconnecting. Message and identity data are never cached.":"Online."}),e.onInstall&&v.jsx("button",{className:"btn",onClick:e.onInstall,children:"Install app"}),e.updateAvailable&&v.jsx("button",{className:"btn primary",onClick:e.onReloadUpdate,children:"Reload to update"})]}),v.jsxs("div",{style:{borderTop:"1px solid var(--line)",paddingTop:16},children:[v.jsx("h4",{children:"Build"}),v.jsx("input",{className:"field mono",readOnly:!0,value:e.build?`${e.build.version} · ${e.build.sha}`:"Loading…"})]})]})}function kz(e,t,n,i,s=6e4){return!t||!t.sha?"current":t.sha===e?(n.remoteSha=null,n.firstMismatchAt=null,"current"):(n.remoteSha=t.sha,(n.firstMismatchAt===null||n.firstMismatchAt===void 0)&&(n.firstMismatchAt=i),n.controllerChanged?"newer-available":i-n.firstMismatchAt>=s?"stuck":"newer-available")}const Sz="31a3834ab34539ece7cc07af9ee4efaaef5c7151",bz=15*6e4,Cz=6e4,Ez=kz;async function Tz(){try{const e=await fetch("/version.json",{cache:"no-store"});return e.ok?await e.json():null}catch{return null}}function Pz(e){const t={remoteSha:null,firstMismatchAt:null,controllerChanged:!1},n=()=>{t.controllerChanged=!0};navigator.serviceWorker?.addEventListener("controllerchange",n);let i=!1;const s=async()=>{const d=await Tz(),h=Ez(Sz,d,t,Date.now(),Cz);h==="newer-available"?(e.onUpdateAvailable(),navigator.serviceWorker?.getRegistration().then(m=>m?.update())):h==="stuck"&&!i&&(i=!0,e.onStuck(d.sha))},l=setTimeout(()=>void s(),5e3),a=setInterval(()=>void s(),bz),c=()=>{document.visibilityState==="visible"&&s()};return document.addEventListener("visibilitychange",c),()=>{clearTimeout(l),clearInterval(a),document.removeEventListener("visibilitychange",c),navigator.serviceWorker?.removeEventListener("controllerchange",n)}}async function Rz(e){try{const t=await navigator.serviceWorker.getRegistrations();await Promise.all(t.map(i=>i.unregister()));const n=await caches.keys();await Promise.all(n.map(i=>caches.delete(i)))}catch{}return location.replace(location.pathname+"?v="+encodeURIComponent(e)),new Promise(()=>{})}function Mz(){const e=new URL(location.href);e.searchParams.has("v")&&(e.searchParams.delete("v"),history.replaceState(null,"",e.pathname+e.search+e.hash))}const Sx=[0,100,400,1e3,3e3,6e3],bx=e=>new Promise(t=>setTimeout(t,e)),Cx={delivered:1,read:2},Ex="ours-dark-v3",Tx="#chat-message-",Px=Rl,Az=e=>e instanceof Error&&e.message?e.message:"The request could not be completed.";function Qk(e,t){const n=new Map,i=[];for(const s of e?.messages??[]){const l={dir:s.dir,text:s.text,date:s.date,read:s.read,wireId:s.wire_id,replyTo:s.reply_to?{wireId:s.reply_to.wire_id}:null,receipt:s.receipt??void 0,receiptless:s.dir==="out"&&!s.wire_id};s.wire_id?n.set(s.wire_id,l):i.push(l)}for(const s of t){const l=n.get(s.wire_id);n.set(s.wire_id,{dir:s.dir,text:"",date:s.date,read:l?.read??s.dir==="out",wireId:s.wire_id,replyTo:s.reply_to?{wireId:s.reply_to.wire_id}:l?.replyTo??null,kind:"file",filename:s.filename,mime:s.mime,receipt:l?.receipt})}return[...i,...n.values()].sort((s,l)=>{const a=Px(s.date)-Px(l.date);return a===0?s.wireId.localeCompare(l.wireId):a})}function Nz(e){const t={};for(const n of Object.values(e.roots??{}))t[n.root_cid]={label:n.root_name,note:"Verified identity"};return t}function Iz(e,t){return[...e.contacts.contacts.map(i=>{const s=e.contacts.roots?.[i.container_id],l=or(e,i.container_id),c=Qk(l,t[i.container_id]??[]).at(-1),d=Al(i);return{id:i.container_id,name:d,announcedName:i.name,initials:rd(d),when:c?P2(c.date):"",activityAt:c?.date??"",last:c?.kind==="file"?L2(c.filename,c.mime):l?.preview??c?.text??"",unread:l?.unread??0,status:"active",root:s?.root_cid??null,sub:s?`role “${s.role_id}” of ${s.root_name}`:"",roleId:s?.role_id??null,rootName:s?.root_name??null,mine:!1,kind:s?"agent":"person"}}),...e.contacts.pending.map(i=>{const s=Al(i);return{id:`pending:${i.container_id}`,name:s,announcedName:i.name,initials:rd(s),when:"",activityAt:"",last:`${i.queued} queued · approval required`,unread:0,status:"pending",root:null,sub:"",roleId:null,rootName:null,mine:!1,kind:"person"}})]}function jz(){return v.jsx(Dz,{})}function Dz(){const e=k.useRef(hM(Gy(window.location.pathname))).current,[t,n]=k.useReducer(Jy,e),[i,s]=k.useState(null),l=k.useRef(0),a=k.useRef(null),c=k.useRef(t),d=k.useRef(new uM),h=k.useRef(null),m=k.useRef(new Map),p=k.useRef(new Map),[y,w]=k.useState({}),S=k.useRef(y),[C,E]=k.useState(null),T=k.useRef(new Set),[M,P]=k.useState(null),D=k.useRef(M),$=k.useRef(!1),[j,Y]=k.useState([]),[U,O]=k.useState(null),[N,X]=k.useState(()=>localStorage.getItem(Ex)!=="0"),[V,fe]=k.useState(null),[J,ee]=k.useState({supported:!1,offline:!navigator.onLine,updateAvailable:!1,registration:null}),[xe,Pe]=k.useState({status:"unsupported",preview:"full"}),[Q,de]=k.useState(!1),R=k.useRef(!1),[F,G]=k.useState(()=>window.location.hash.startsWith(Tx)),{toasts:A,push:te,dismiss:ge,clear:ye}=pz(),me=k.useCallback(W=>{c.current=Jy(c.current,W),n(W)},[]),we=k.useCallback(W=>{$.current=W},[]);k.useEffect(()=>{c.current=t},[t]),D.current=M,S.current=y,k.useMemo(()=>(cv(Object.values(y).flat()),null),[y]),k.useEffect(()=>(document.documentElement.classList.toggle("theme-dark",N),()=>document.documentElement.classList.remove("theme-dark")),[N]);const pe=k.useCallback(W=>me({type:"error",message:Az(W)}),[me]),Ve=k.useCallback(()=>{const W=c.current;return{visibility:document.visibilityState,appRoute:W.route.name==="chats"?"chats":"other",selectedContactCid:ri(W),desktopLayout:h.current?.matches??window.innerWidth>=861,mobileDetailOpen:W.mobileDetailOpen,conversationCoveringDialogOpen:D.current!==null}},[]),qe=k.useCallback(async(W,le=!0)=>{try{const ne=await Ke.conversation(W);return me({type:"page",contactCid:W,page:ne}),ne}catch(ne){return le&&pe(ne),null}},[me,pe]),it=k.useCallback(async(W,le=!0)=>{try{const ne=await Ke.files(W);return cv(ne.files),w(Me=>({...Me,[W]:ne.files})),ne.files}catch(ne){return le&&pe(ne),null}},[pe]);k.useEffect(()=>Pz({onUpdateAvailable:()=>ee(W=>({...W,updateAvailable:!0})),onStuck:W=>{Rz(W)}}),[]);const We=k.useCallback(async()=>{const W=await Ke.contacts();return me({type:"contacts",contacts:{...W,pending:W.pending??[]}}),W},[me]),at=k.useCallback(async()=>{try{const[W,le,ne]=await Promise.all([Ke.identity(),Ke.contacts(),Ke.buildInfo()]),Me={...le,pending:le.pending??[]};return c.current.identity&&c.current.identity.cid!==W.cid&&(j2(),S.current={},w({})),me({type:"snapshot",identity:W,contacts:Me}),O(ne),await Promise.all(Me.contacts.flatMap(ke=>[qe(ke.container_id,!1),it(ke.container_id,!1)])),ri(c.current)}catch(W){return pe(W),null}},[me,it,qe,pe]),xt=k.useCallback(async W=>{await d.current.request(W,async()=>{lM(W,Ve())&&(await Ke.markRead(W),await Promise.all([qe(W),We()]))}).catch(pe)},[Ve,We,qe,pe]),Vt=k.useCallback(async W=>{const le=++l.current;a.current?.abort();const ne=new AbortController;a.current=ne,s(null),ye(W),it(W,!1);let Me;try{Me=await Ke.conversation(W,void 0,ne.signal)}catch(Ye){ne.signal.aborted||pe(Ye);return}if(ne.signal.aborted||le!==l.current)return;me({type:"page",contactCid:W,page:Me});const ke=Me.unread;let ce=[...Me.messages],Ae=Me.nextBefore;const ft=new Set,nn=new Set(ce.map(Ye=>Ye.wire_id).filter(Boolean)),ot=()=>ce.filter(Ye=>Ye.dir==="in"&&!Ye.read);for(;ot().length<ke&&Ae&&!ft.has(Ae);){ft.add(Ae);let Ye;try{Ye=await Ke.conversation(W,Ae,ne.signal)}catch{break}if(ne.signal.aborted||le!==l.current)return;const cr=Ye.messages.filter(fr=>!fr.wire_id||!nn.has(fr.wire_id));if(!cr.length&&Ye.nextBefore===Ae)break;for(const fr of cr)fr.wire_id&&nn.add(fr.wire_id);ce=[...cr,...ce],me({type:"older_page",contactCid:W,page:Ye,newer:Me.messages}),Ae=Ye.nextBefore}const Ge=ot()[0];Ge?.wire_id&&le===l.current&&!ne.signal.aborted&&s({contactCid:W,wireId:Ge.wire_id,count:ke}),await xt(W)},[ye,me,xt,it,pe]),lt=k.useCallback(async(W,le,ne="page")=>{const Me=`page:${W}:${ne}`,ke=(m.current.get(Me)??0)+1;m.current.set(Me,ke);for(const ce of Sx){if(ce&&await bx(ce),m.current.get(Me)!==ke)return;const Ae=await qe(W,!1);if(Ae&&le(Ae))return}},[qe]),Pt=k.useCallback(async(W,le)=>{const ne=`file:${W}`,Me=(m.current.get(ne)??0)+1;m.current.set(ne,Me);for(const ke of Sx)if(ke&&await bx(ke),m.current.get(ne)!==Me||(await it(W,!1))?.some(Ae=>Ae.wire_id===le))return},[it]),fn=k.useRef(!1);k.useEffect(()=>{if(!F||!t.loaded)return;const W=decodeURIComponent(window.location.hash.slice(Tx.length)),le=ri(c.current);if(!W||!le){G(!1);return}if(or(c.current,le)?.messages.some(ne=>ne.wire_id===W)){G(!1);return}fn.current||(fn.current=!0,lt(le,ne=>ne.messages.some(Me=>Me.wire_id===W),`anchor:${W}`).catch(()=>{}).finally(()=>G(!1)))},[F,lt,t.loaded,t.pages]),k.useMemo(()=>(I2({url:W=>Object.values(S.current).flat().find(ne=>ne.wire_id===W)?.available?Ke.mediaUrl(W):null,bytes:async W=>{if(!Object.values(S.current).flat().find(Me=>Me.wire_id===W)?.available)return null;const ne=await fetch(Ke.mediaUrl(W),{cache:"no-store",credentials:"same-origin"});if(!ne.ok)throw new Error(`Media request failed (HTTP ${ne.status})`);return new Uint8Array(await ne.arrayBuffer())},fetch:async W=>{const le=Object.values(S.current).flat().find(ne=>ne.wire_id===W);if(!le)throw new Error("Media record is unavailable");await Ke.fetchFiles([W]),await it(le.contact_id)}}),null),[it]),k.useEffect(()=>{let W;gM(ne=>{ee(ne),nv(ne.registration).then(Pe).catch(()=>Pe(Me=>({...Me,status:"error"})))},{shouldDeferReload:()=>$.current||D.current!==null}).then(ne=>{W=ne}).catch(pe);const le=ne=>{ne.preventDefault(),fe(ne)};return window.addEventListener("beforeinstallprompt",le),()=>{W?.(),window.removeEventListener("beforeinstallprompt",le)}},[pe]),k.useEffect(()=>CM(),[]),k.useEffect(()=>{if(!(!J.registration||xe.status!=="on"))return aM({registration:J.registration,identity:Ke.identity,onEvent:d0})},[xe.status,xe.bindingId,J.registration]),k.useEffect(()=>{const W=()=>Pe(le=>({...le,status:"error"}));return window.addEventListener("ours-push-repair-required",W),()=>window.removeEventListener("ours-push-repair-required",W)},[]),k.useEffect(()=>{window.location.pathname==="/"&&window.history.replaceState(null,"",ni()),h.current=window.matchMedia("(min-width: 861px)");const W=()=>{const ce=Gy(window.location.pathname);a.current?.abort(),l.current+=1,s(null),me({type:"route",route:ce}),R.current&&ce.name==="chats"&&ce.contactCid&&(R.current=!1,requestAnimationFrame(()=>document.querySelector("[data-contact-trigger]")?.focus({preventScroll:!0}))),ce.name==="chats"&&ce.contactCid&&Vt(ce.contactCid)},le=()=>{if(document.visibilityState!=="visible")return;const ce=ri(c.current);ce&&xt(ce),g0(),J.registration&&nv(J.registration).then(Pe).catch(()=>Pe(Ae=>({...Ae,status:"error"})))};window.addEventListener("popstate",W),document.addEventListener("visibilitychange",le);const ne=ce=>{const Ae=ce.type==="sync_required"?`${ce.type}:${ce.reason}`:ce.type==="receipt_received"?`${ce.type}:${ce.contact_id}:${ce.kind}:${ce.wire_ids.join(",")}`:`${ce.type}:${ce.contact_id}:${ce.wire_id}`,ft=Date.now(),nn=p.current.get(Ae)??0;p.current.set(Ae,ft);for(const[ot,Ge]of p.current)ft-Ge>6e4&&p.current.delete(ot);ft-nn<6e4||(async()=>{if(ce.type==="sync_required"){await at();return}if(We().catch(pe),ce.type==="file_received"){await Pt(ce.contact_id,ce.wire_id);const ot=c.current.contacts.contacts.find(Ge=>Ge.container_id===ce.contact_id);ri(c.current)!==ce.contact_id&&ot&&te(ce.contact_id,Al(ot),"New file");return}if(ce.type==="message_received"){const ot=c.current.contacts.contacts.find(Ge=>Ge.container_id===ce.contact_id);await lt(ce.contact_id,Ge=>Ge.messages.some(Ye=>Ye.wire_id===ce.wire_id),`message:${ce.wire_id}`),ri(c.current)===ce.contact_id?await xt(ce.contact_id):ot&&te(ce.contact_id,Al(ot),"New message");return}me({type:"receipt",contactCid:ce.contact_id,kind:ce.kind,wireIds:ce.wire_ids}),await lt(ce.contact_id,ot=>ce.wire_ids.every(Ge=>{const Ye=ot.messages.find(cr=>cr.wire_id===Ge);return!!Ye?.receipt&&Cx[Ye.receipt]>=Cx[ce.kind]}),`receipt:${ce.wire_ids.join(",")}`)})().catch(pe)},Me=rM(ne),ke=iM(ne,ce=>me({type:"connection",connection:ce}));return at().then(ce=>{ce&&Vt(ce)}),()=>{ke(),Me(),window.removeEventListener("popstate",W),document.removeEventListener("visibilitychange",le)}},[lt,Pt,me,xt,Vt,te,We,at,pe,J.registration]);const It=(W,le,ne)=>{window.history.pushState({oursMessenger:!0},"",le),me({type:"route",route:W,mobileDetailOpen:ne})},jt=async W=>{It({name:"chats",contactCid:W},ni(W),!0),await Vt(W)},Ln=async W=>{const le=or(c.current,W);if(!(!le?.nextBefore||T.current.has(W))){T.current.add(W),E(W);try{const ne=await Ke.conversation(W,le.nextBefore);me({type:"older_page",contactCid:W,page:ne,newer:le.messages})}catch(ne){pe(ne)}finally{T.current.delete(W),E(null)}}},ze=ri(t),ur=t.contacts.contacts.find(W=>W.container_id===ze),bn=k.useMemo(()=>Iz(t,y),[t,y]),q=bn.find(W=>W.id===ze)??null,se=ze?Qk(or(t,ze),y[ze]??[]):[],_=t.identity,Z=t.loaded?ze&&!or(t,ze)||F?"updating":t.connection!=="live"?"connecting":null:"connecting",he=async(W,le=xe.preview)=>{if(J.registration){de(!0),Pe(ne=>({...ne,status:"repairing",preview:le}));try{Pe(await(W==="enable"?m0(J.registration,{preview:le}):W==="repair"?SM(J.registration,le):bM(J.registration,xe)))}catch(ne){Pe(Me=>({...Me,status:"error"})),pe(ne)}finally{de(!1)}}},De=()=>{Y([]),P("invite"),Ke.invites().then(Y).catch(pe)};return t.route.name==="not_found"?v.jsxs("div",{className:"centered-screen",children:[v.jsx("h1",{children:"Page not found"}),v.jsx("button",{className:"btn primary",onClick:()=>It({name:"chats",contactCid:null},ni()),children:"Open chats"})]}):_?v.jsx("div",{className:N?"theme-dark":"",style:{height:"100%"},children:v.jsxs("div",{className:"app signal-app",children:[v.jsxs("main",{className:"section signal-stage"+(t.mobileDetailOpen?" show-detail":""),children:[v.jsx(sz,{contacts:bn,roots:Nz(t.contacts),selected:ze,onSelect:W=>{W.startsWith("pending:")||jt(W)},onInvite:De,onSettings:()=>P("settings"),onApprovePending:async W=>{try{return await Ke.respondToIntroduction(W,"approve"),await at(),!0}catch(le){return pe(le),!1}},onRejectPending:async W=>{try{return await Ke.respondToIntroduction(W,"reject"),await at(),!0}catch(le){return pe(le),!1}}}),t.route.name==="contact"&&q?v.jsx(az,{contact:q,messages:se,onBack:()=>{R.current=!0,fM(window.history.state)==="back"?window.history.back():(window.history.replaceState({oursMessenger:!0},"",ni(q.id)),me({type:"route",route:{name:"chats",contactCid:q.id},mobileDetailOpen:!0}),requestAnimationFrame(()=>document.querySelector("[data-contact-trigger]")?.focus({preventScroll:!0})),R.current=!1)},onRename:W=>void Ke.renameContact(q.id,W).then(at).catch(pe),onRemove:()=>{confirm(`Remove “${ur?.name??"contact"}”?`)&&Ke.removeContact(q.id).then(()=>(window.history.replaceState({oursMessenger:!0},"",ni()),me({type:"route",route:{name:"chats",contactCid:null},mobileDetailOpen:!1}),at())).catch(pe)},onOpenMessage:W=>{It({name:"chats",contactCid:q.id},ni(q.id),!0);let le=12;const ne=()=>{const Me=document.getElementById(`chat-message-${encodeURIComponent(W)}`),ke=Me?.closest(".messages");if((!Me||!ke||ke.clientHeight<=0)&&le-- >0){requestAnimationFrame(ne);return}if(!Me||!ke)return;const ce=Me.getBoundingClientRect(),Ae=ke.getBoundingClientRect(),ft=ke.scrollTop+ce.top-Ae.top-Math.max(0,(ke.clientHeight-ce.height)/2),nn=Math.max(0,Math.min(ft,ke.scrollHeight-ke.clientHeight));ke.scrollTo({top:nn,behavior:window.matchMedia("(prefers-reduced-motion: reduce)").matches?"auto":"smooth"})};requestAnimationFrame(ne)},indexOffset:or(t,q.id)?.hasMore?Math.max(1,(or(t,q.id)?.total??se.length)-se.length):0,onSendText:async(W,le)=>{const ne=await Ke.send(q.id,W,le);return await qe(q.id,!1),ne.wire_id??void 0},onSendFile:async(W,le)=>{await Ke.sendFile(q.id,new Blob([W.bytes],{type:W.mime}),W.filename,W.mime,le),await Promise.all([it(q.id),qe(q.id,!1)])}}):v.jsx(lz,{contact:q,messages:se,syncing:Z,unreadOpen:i?.contactCid===ze?i:null,hiddenEarlier:or(t,ze??"")?.hasMore?Math.max(1,(or(t,ze??"")?.total??se.length)-se.length):0,onLoadEarlier:ze&&C!==ze?()=>void Ln(ze):void 0,onBack:()=>{a.current?.abort(),l.current+=1,s(null),It({name:"chats",contactCid:null},ni(),!1)},onOpenContact:()=>{ze&&It({name:"contact",contactCid:ze},cM(ze),!0)},onDraftChange:we,onSend:async(W,le,ne)=>{if(!ze)return;const Me=ze,ke=await Ke.send(Me,W,le,ne);return me({type:"sent_message",contactCid:Me,message:{dir:"out",text:W,date:new Date().toISOString(),read:!0,wire_id:ke.wire_id??"",receipt:null,reply_to:le?{wire_id:le}:null}}),ke.wire_id?lt(Me,ce=>ce.messages.some(Ae=>Ae.wire_id===ke.wire_id),`send:${ke.wire_id}`):We().catch(pe),ke.wire_id??void 0},onSendFile:async(W,le)=>{ze&&(await Ke.sendFile(ze,new Blob([W.bytes],{type:W.mime}),W.filename,W.mime,le),await Promise.all([it(ze),qe(ze,!1)]))},onFetchFile:async W=>{await Ke.fetchFiles([W]),ze&&await it(ze)}},ze??"no-conversation")]}),v.jsxs("div",{className:"app-banners",children:[J.offline&&v.jsx("div",{className:"banner warn",role:"status","aria-live":"polite",children:"Offline — reconnecting to the network…"}),t.connection!=="live"&&v.jsx("div",{className:"banner warn",role:"status","aria-live":"polite",children:t.connection==="retrying"?"Live updates interrupted — reconnecting…":"Connecting to live updates…"}),J.updateAvailable&&v.jsxs("div",{className:"banner info",children:[v.jsx("span",{role:"status","aria-live":"polite",children:"A new version is available."}),v.jsx("span",{className:"banner-actions",children:v.jsx("button",{className:"linkbtn",onClick:()=>{J.registration&&ev(J.registration)},children:"Restart now"})})]}),v.jsx(gz,{items:A,onDismiss:ge,onOpen:W=>void jt(W)})]}),M==="invite"&&v.jsx(xz,{identity:_,invites:j,onRefresh:async()=>Y(await Ke.invites()),onCreate:async(W,le)=>(await Ke.createInvite(W,le)).blob,onAccept:async(W,le)=>{await Ke.addContact(W,le),await at()},onRevoke:async W=>{await Ke.revokeInvite(W)},onClose:()=>{P(null),at()}}),M==="settings"&&v.jsx(wz,{identity:_,push:xe,workerSupported:J.supported,busy:Q,offline:J.offline,updateAvailable:J.updateAvailable,build:U,dark:N,onToggleDark:()=>X(W=>(localStorage.setItem(Ex,W?"0":"1"),!W)),onSaveBio:async W=>{await Ke.setBio(W),await at()},onPushAction:he,onInstall:V?()=>void V.prompt().then(()=>fe(null)):void 0,onReloadUpdate:()=>{J.registration&&ev(J.registration)},onClose:()=>{D.current=null,P(null),ze&&xt(ze)}}),t.error&&v.jsxs("div",{className:"banner error",role:"alert","aria-live":"assertive",children:[t.error,v.jsx("button",{className:"linkbtn",onClick:()=>me({type:"error",message:null}),children:"dismiss"})]})]})}):v.jsx("div",{className:N?"theme-dark":"",style:{height:"100%"},children:v.jsx("div",{className:"centered-screen",children:v.jsx("p",{className:"muted",children:"Loading…"})})})}Mz();const Zk=document.getElementById("root");if(!Zk)throw new Error("missing #root");tC.createRoot(Zk).render(v.jsx(ZP,{reducedMotion:"user",children:v.jsx(jz,{})}));export{Ch as _,Id as g};
|
|
321
|
-
//# sourceMappingURL=index-
|
|
320
|
+
`)}).join("")}function qF({children:e}){const t=k.isValidElement(e)?e:null,n=Kk(t?.props.className);return v.jsxs("div",{className:"message-code-block","data-language":n||void 0,children:[n&&v.jsx("div",{className:"message-code-language",children:n}),v.jsx("pre",{children:e})]})}const XF=[Vk],YF={a:({node:e,children:t,href:n,...i})=>{const s=Hk(n);return s?v.jsx("a",{...i,href:s,target:"_blank",rel:"noopener noreferrer",children:t}):v.jsx("span",{className:"message-link-blocked",children:t})},img:({alt:e})=>v.jsxs("span",{className:"message-image-placeholder",children:["[image: ",e||"remote image blocked","]"]}),pre:qF,code:({node:e,className:t,children:n,...i})=>v.jsx("code",{className:t,"data-language":Kk(t),...i,children:n})},yx=k.memo(function({text:t,className:n="bubble-text message-markdown"}){return t.length>WF?v.jsx("div",{className:`${n} message-markdown-plaintext`,"data-render-mode":"plaintext",children:t}):v.jsx("div",{className:n,"data-render-mode":"markdown",children:v.jsx(zk,{remarkPlugins:XF,components:YF,urlTransform:i=>Hk(i)??"",children:KF(t)})})}),yl={type:"spring",stiffness:430,damping:38,mass:.72},vx=10,qk=56,GF=18,QF=650;function ZF(e,t){return Math.abs(e)<vx&&Math.abs(t)<vx?"pending":Math.abs(e)>Math.abs(t)&&e>0?"drag":"reject"}function JF(e){const t=e.at(-1),n=t?e.slice(0,-1).reverse().find(i=>i.x!==t.x&&t.time-i.time<=100):void 0;return n&&t&&t.time>n.time?(t.x-n.x)/(t.time-n.time)*1e3:0}function ez(e,t){const n=JF(t);return n>=0&&(e>=qk||e>=GF&&n>=QF)}const Ad="ours.chats.listMode",cs="recent";function Xk(){try{return globalThis.localStorage}catch{return}}function tz(e=Xk()){try{return e?.getItem(Ad)==="identity"?"identity":cs}catch{return cs}}function nz(e,t=Xk()){const n=e==="identity"?"identity":cs;try{return t?.setItem(Ad,n),t?.getItem(Ad)===n?n:cs}catch{return cs}}function Ss(e){return typeof e=="string"?e:""}function _l(e,t){const n=Ss(e),i=Ss(t),s=n.normalize().toLowerCase(),l=i.normalize().toLowerCase();return s<l?-1:s>l?1:n<i?-1:n>i?1:0}function rz(e,t){const n=Rl(Ss(t.activityAt))-Rl(Ss(e.activityAt));if(n!==0)return n;const i=_l(e.name,t.name);return i!==0?i:_l(e.id,t.id)}function Nd(e){return[...e].sort(rz)}function xx(e){return e.contacts.length>0?Rl(Ss(e.contacts[0].activityAt)):0}function iz(e,t){const n=new Map,i=[];for(const l of e){const a=l.root||(t?.[l.id]?l.id:null);if(!a){i.push(l);continue}const c=t?.[a]||{label:a,note:""};let d=n.get(a);d||(d={id:`root:${a}`,rootId:a,label:c.label,note:c.note,contacts:[]},n.set(a,d)),d.contacts.push(l)}const s=[...n.values()].map(l=>({...l,contacts:Nd(l.contacts)}));return i.length>0&&s.push({id:"rootless",rootId:null,label:"Independent identities",note:"People, agents and apps without a verified Human/root group",contacts:Nd(i)}),s.sort((l,a)=>{const c=xx(a)-xx(l);if(c!==0)return c;const d=_l(l.label,a.label);return d!==0?d:_l(l.id,a.id)})}const oz=15e3;function Ef(e){const{c:t,active:n,grouped:i}=e,[s,l]=k.useState(!1),a=async(h,m)=>{if(!(!h||s)){l(!0);try{const p=await h();requestAnimationFrame(()=>{p?document.getElementById("chat-list-title")?.focus():m.focus()})}finally{l(!1)}}},c=v.jsxs(v.Fragment,{children:[v.jsx("span",{className:"contact-avatar","aria-hidden":!0,children:t.initials}),v.jsxs("span",{className:"contact-copy",children:[v.jsxs("span",{className:"contact-row-topline",children:[v.jsx("span",{className:"contact-name",children:t.name}),t.when&&v.jsx("span",{className:"contact-time",children:t.when})]}),v.jsxs("span",{className:"contact-row-bottomline",children:[v.jsx("span",{className:"contact-last",children:t.last}),t.status==="pending"&&v.jsx("span",{className:"chip",children:"pending approval"}),!!t.unread&&v.jsx("span",{className:"contact-unread",children:t.unread})]})]}),t.status==="pending"&&v.jsxs("span",{className:"pending-actions",role:"group","aria-label":`Decide whether to accept ${t.name}`,children:[v.jsx("button",{type:"button",className:"linkbtn",disabled:s,onClick:h=>void a(e.onApprove,h.currentTarget),children:"Approve"}),v.jsx("button",{type:"button",className:"linkbtn quiet",disabled:s,onClick:h=>void a(e.onReject,h.currentTarget),children:"Reject"})]}),n&&v.jsx(ss.span,{className:"contact-active-glow",layoutId:"active-contact",transition:yl})]}),d="contact-row"+(n?" active":"")+(i?" grouped":"")+(t.status==="pending"?" pending":"");return t.status==="pending"?v.jsx("div",{className:d,children:c}):v.jsx(ss.button,{type:"button",className:d,onClick:e.onClick,children:c})}function sz(e){const{contacts:t,roots:n,selected:i}=e,[s,l]=k.useState(""),a=k.useRef(null),c=k.useRef(null),[d,h]=k.useState(()=>tz()),m=O=>O.name.toLowerCase().includes(s.toLowerCase()),p=t.filter(O=>O.status!=="pending"&&m(O)),y=t.filter(O=>O.status==="pending"&&m(O)),w=Nd(p),S=iz(p,n),C=p.length===0&&y.length===0,E=O=>{h(nz(O))},T=[{id:"recent",label:"Recent"},{id:"identity",label:"By identity"}],M=k.useRef(null),P=k.useRef({id:-1,x0:0,y0:0,mode:"idle"}),D=k.useRef(!1),$=(O,N)=>{const X=P.current;if(X.id!==O)return;const V=M.current;if(N&&X.mode==="drag"&&V){const fe=parseFloat(V.style.getPropertyValue("--mode-drag-x"))||0,J=Math.max(0,(V.clientWidth-8)/2);E(fe>=J/2?"identity":"recent"),D.current=!0,window.setTimeout(()=>{D.current=!1},0)}P.current={id:-1,x0:0,y0:0,mode:"idle"},V?.hasPointerCapture?.(O)&&V.releasePointerCapture(O),V?.classList.remove("dragging"),V?.style.removeProperty("--mode-drag-x")},j=O=>{!O.isPrimary||P.current.id!==-1||(P.current={id:O.pointerId,x0:O.clientX,y0:O.clientY,mode:"pending"})},Y=O=>{const N=P.current;if(N.id!==O.pointerId||N.mode==="idle")return;const X=O.clientX-N.x0,V=O.clientY-N.y0;if(N.mode==="pending"){if(Math.abs(X)<10&&Math.abs(V)<10)return;if(Math.abs(V)>Math.abs(X)){$(O.pointerId,!1);return}N.mode="drag",O.currentTarget.setPointerCapture?.(O.pointerId),O.currentTarget.classList.add("dragging")}O.preventDefault();const fe=Math.max(0,(O.currentTarget.clientWidth-8)/2),J=d==="identity"?fe:0;O.currentTarget.style.setProperty("--mode-drag-x",`${Math.min(fe,Math.max(0,J+X))}px`)},U=(O,N)=>{if(!["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End"].includes(O.key))return;O.preventDefault();const V=O.key==="Home"?"recent":O.key==="End"||N==="recent"?"identity":"recent";E(V),document.getElementById(`conversation-list-${V}`)?.focus()};return k.useLayoutEffect(()=>{const O=a.current,N=c.current;if(!O||!N)return;const X=()=>O.style.setProperty("--list-bottom-chrome-height",`${N.getBoundingClientRect().height}px`);X();const V=new ResizeObserver(X);return V.observe(N),()=>{V.disconnect(),O.style.removeProperty("--list-bottom-chrome-height")}},[]),v.jsxs("div",{className:"listcol",ref:a,children:[v.jsxs("div",{className:"listcol-head",children:[v.jsxs("div",{className:"listcol-titlebar",children:[v.jsxs("h2",{id:"chat-list-title",className:"listcol-title messenger-lockup",tabIndex:-1,children:[v.jsx("span",{className:"messenger-brand-ours",children:"Ours"}),v.jsx("span",{className:"messenger-brand-product",children:"messenger"})]}),v.jsxs("div",{className:"listcol-actions",children:[v.jsx("button",{className:"btn icon-btn desktop-invite","aria-label":"Invite",title:"Invite",onClick:e.onInvite,children:v.jsx(Ee,{name:"invite",size:18})}),v.jsx("button",{className:"icon-btn","aria-label":"Settings",title:"Settings",onClick:e.onSettings,children:v.jsx(Ee,{name:"settings",size:18})})]})]}),v.jsx("div",{ref:M,className:"conversation-list-modes",role:"tablist","aria-label":"Conversation list layout","data-mode":d,onPointerDown:j,onPointerMove:Y,onPointerUp:O=>$(O.pointerId,!0),onPointerCancel:O=>$(O.pointerId,!1),onLostPointerCapture:O=>$(O.pointerId,!1),children:T.map(O=>v.jsx("button",{id:`conversation-list-${O.id}`,type:"button",role:"tab","aria-selected":d===O.id,"aria-controls":"conversation-list-panel",tabIndex:d===O.id?0:-1,className:d===O.id?"active":"",onClick:N=>{if(D.current){N.preventDefault();return}E(O.id)},onKeyDown:N=>U(N,O.id),children:O.label},O.id))})]}),v.jsxs("div",{id:"conversation-list-panel",className:"listcol-scroll",role:"tabpanel","aria-labelledby":`conversation-list-${d}`,children:[d==="recent"&&w.length>0&&v.jsx("div",{className:"conversation-group",children:w.map(O=>v.jsx(Ef,{c:O,active:i===O.id,onClick:()=>e.onSelect(O.id)},O.id))}),d==="identity"&&S.map(O=>v.jsxs("div",{children:[v.jsxs("div",{className:"group-label",title:O.note,children:[O.rootId&&v.jsx(Ee,{name:"clusters"}),v.jsx("span",{children:O.label}),O.note&&v.jsxs("span",{className:"gl-note",children:["· ",O.note]})]}),v.jsx("div",{className:"conversation-group",children:O.contacts.map(N=>v.jsx(Ef,{c:N,grouped:O.rootId!==null,active:i===N.id,onClick:()=>e.onSelect(N.id)},N.id))})]},O.id)),y.length>0&&v.jsxs("div",{children:[v.jsx("div",{className:"group-label",children:v.jsx("span",{children:"Pending"})}),v.jsx("div",{className:"conversation-group",children:y.map(O=>v.jsx(Ef,{c:O,active:!1,onClick:()=>{},onApprove:()=>e.onApprovePending(O.id.slice(8)),onReject:()=>e.onRejectPending(O.id.slice(8))},O.id))})]}),C&&v.jsx("p",{className:"muted",style:{padding:"14px 10px",fontSize:"0.85rem"},children:"No contacts yet — share an invite to start."})]}),v.jsxs("div",{className:"list-bottom-chrome",ref:c,children:[v.jsxs("div",{className:"search adaptive-search",role:"search",children:[v.jsx("span",{className:"adaptive-search-icon","aria-hidden":!0,children:v.jsx(Ee,{name:"search"})}),v.jsx("input",{className:"field",placeholder:"Search people, agents, apps…",value:s,onChange:O=>l(O.target.value),onKeyDown:O=>{O.key==="Escape"&&(O.preventDefault(),l(""))}})]}),v.jsx("button",{type:"button",className:"icon-btn list-bottom-invite","aria-label":"Invite",title:"Invite",onClick:e.onInvite,children:v.jsx(Ee,{name:"invite",size:20})})]})]})}function az(e){const[t,n]=k.useState(!1),[i,s]=k.useState(e.contact.name),[l,a]=k.useState(!1),[c,d]=k.useState(null),h=k.useRef(!1);k.useEffect(()=>{const p=y=>{y.key!=="Escape"||l||c||t||(y.preventDefault(),e.onBack())};return document.addEventListener("keydown",p),()=>document.removeEventListener("keydown",p)},[t,c,e.onBack,l]);const m=()=>{if(h.current)return;h.current=!0;const p=i.trim();p&&p!==e.contact.name?e.onRename(p):s(e.contact.name),n(!1)};return v.jsxs("div",{className:"detail contact-screen",children:[v.jsxs("div",{className:"detail-head contact-screen-head",children:[v.jsx("button",{type:"button",className:"icon-btn detail-back contact-back","aria-label":"Back to conversation",onClick:e.onBack,children:v.jsx(Ee,{name:"back"})}),v.jsx("strong",{children:"Contact"})]}),v.jsxs("div",{className:"contact-screen-scroll",children:[v.jsxs("section",{className:"contact-hero","aria-labelledby":"contact-screen-name",children:[v.jsx("div",{className:"avatar accent contact-avatar-large","aria-hidden":!0,children:e.contact.initials}),t?v.jsx("input",{id:"contact-screen-name",className:"field contact-name-input",value:i,autoFocus:!0,onChange:p=>s(p.target.value),onBlur:m,onKeyDown:p=>{p.key==="Enter"&&m(),p.key==="Escape"&&(h.current=!0,s(e.contact.name),n(!1))}}):v.jsx("h2",{id:"contact-screen-name",children:e.contact.name}),v.jsxs("p",{children:[v.jsx(Ee,{name:"lock",size:13})," End-to-end encrypted connection"]})]}),v.jsxs("section",{className:"contact-action-group","aria-label":"Contact actions",children:[v.jsxs("button",{type:"button",onClick:()=>a(!0),children:[v.jsxs("span",{children:[v.jsx(Ee,{name:"paperclip"}),"Shared photos, files, and links"]}),v.jsx(Ee,{name:"chevron"})]}),v.jsxs("button",{type:"button",onClick:()=>{h.current=!1,s(e.contact.name),n(!0)},children:[v.jsxs("span",{children:[v.jsx(Ee,{name:"edit"}),"Rename contact"]}),v.jsx(Ee,{name:"chevron"})]})]}),v.jsxs("section",{className:"contact-identity","aria-labelledby":"contact-identity-title",children:[v.jsx("h3",{id:"contact-identity-title",children:"Verified identity"}),e.contact.roleId&&v.jsxs("p",{children:["Role ",v.jsx("strong",{children:e.contact.roleId})," of ",v.jsx("strong",{children:e.contact.rootName})]}),v.jsx("code",{children:e.contact.id}),v.jsxs("button",{type:"button",className:"btn sm",onClick:()=>void navigator.clipboard.writeText(e.contact.id),children:[v.jsx(Ee,{name:"copy",size:14}),"Copy identity"]})]}),v.jsxs("button",{type:"button",className:"contact-remove",onClick:e.onRemove,children:[v.jsx(Ee,{name:"trash"}),"Remove contact"]})]}),l&&v.jsx(NF,{messages:e.messages,indexOffset:e.indexOffset,onClose:()=>a(!1),onJump:e.onOpenMessage,onPreview:p=>{a(!1),d(p)}}),c&&(As(c.filename,c.mime)?v.jsx($k,{rec:c,onClose:()=>d(null)}):v.jsx(Bk,{rec:c,onClose:()=>d(null),onSendText:e.onSendText,onSendFile:e.onSendFile}))]})}const wx=e=>`chat-message-${encodeURIComponent(e)}`,Yk=()=>typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;function kx(e){const{dir:t,canReply:n,onReply:i}=e,s=k.useRef(null),l=k.useRef(null),a=k.useRef(null),c=k.useRef(i);c.current=i;const d=t==="in"?1:-1,h=qk,m=84,p=()=>({id:-1,x0:0,y0:0,mode:"idle",armed:!1,distance:0,samples:[]}),y=k.useRef(p()),w=M=>{const P=l.current,D=a.current,$=Yk();if(P&&(P.style.transform=M&&!$?`translateX(${M}px)`:""),D){const j=Math.min(1,Math.abs(M)/h);D.style.opacity=String(j),D.style.transform=$?"scale(1)":`scale(${.5+.5*j})`}},S=(M,P)=>{const D=y.current;if(D.id!==M)return;const $=P&&D.mode==="drag"&&ez(D.distance,D.samples);y.current=p(),l.current?.classList.remove("swiping"),a.current?.classList.remove("armed"),w(0);const j=s.current;j?.hasPointerCapture?.(M)&&j.releasePointerCapture(M),$&&c.current()};k.useEffect(()=>{const M=s.current;if(!M)return;const P=D=>S(D.pointerId,!1);return M.addEventListener("lostpointercapture",P),()=>{M.removeEventListener("lostpointercapture",P);const D=y.current.id;D!==-1&&S(D,!1)}},[]);const C=M=>{const P=M.target,D=window.getSelection?.();!n||!M.isPrimary||M.pointerType==="mouse"||M.pointerType==="pen"&&M.button!==0||y.current.id!==-1||D&&!D.isCollapsed||P.closest('a, button, input, textarea, select, [role="button"], audio, video, img, [draggable="true"], .filecard, .filecard-bubble, .image-bubble, .voice-bubble, .ours-message-file, .attachment')||(y.current={id:M.pointerId,x0:M.clientX,y0:M.clientY,mode:"maybe",armed:!1,distance:0,samples:[{x:M.clientX*d,time:M.timeStamp}]},w(0))},E=M=>{const P=y.current;if(P.id!==M.pointerId||P.mode==="idle")return;const D=M.clientX-P.x0,$=M.clientY-P.y0,j=window.getSelection?.();if(j&&!j.isCollapsed){S(M.pointerId,!1);return}if(P.mode==="maybe"){const X=ZF(D*d,$);if(X==="pending")return;if(X==="drag")P.mode="drag",M.currentTarget.setPointerCapture?.(M.pointerId),l.current?.classList.add("swiping");else{P.mode="idle";return}}M.preventDefault();const Y=M.timeStamp;P.samples.push({x:M.clientX*d,time:Y}),P.samples=P.samples.filter(X=>Y-X.time<=120);let U=D*d;U<0&&(U=0),U>h&&(U=h+(U-h)*.35),U=Math.min(U,m),P.distance=U;const O=U*d,N=Math.abs(O)>=h;N!==P.armed&&(P.armed=N,a.current?.classList.toggle("armed",N),N&&navigator.vibrate?.(10)),w(O)},T=M=>{const P=y.current;P.id===M.pointerId&&P.mode==="drag"&&(P.samples.push({x:M.clientX*d,time:M.timeStamp}),P.distance=Math.max(0,(M.clientX-P.x0)*d),P.armed=P.distance>=h),S(M.pointerId,!0)};return v.jsxs("div",{ref:s,className:"msg-row "+(e.rowClass??t),style:n?{touchAction:"pan-y"}:void 0,onPointerDown:C,onPointerMove:E,onPointerUp:T,onPointerCancel:M=>S(M.pointerId,!1),onLostPointerCapture:M=>S(M.pointerId,!1),children:[n&&v.jsx("span",{className:"swipe-cue",ref:a,"aria-hidden":!0,children:v.jsx(Ee,{name:"reply",size:16})}),v.jsx("div",{className:"bubble-wrap",ref:l,children:e.children}),e.after]})}function lz(e){const{contact:t,messages:n}=e,[i,s]=k.useState(""),[l,a]=k.useState(!1),[c,d]=k.useState(null),[h,m]=k.useState(null),[p,y]=k.useState(null),[w,S]=k.useState(null),[C,E]=k.useState(null),[T,M]=k.useState(!1),[P,D]=k.useState(!1),[$,j]=k.useState(!1),[Y,U]=k.useState(null),O=k.useRef(null),N=k.useRef(null),X=k.useRef(null),V=k.useRef(null),fe=k.useRef(null),J=k.useRef(!1),ee=k.useRef(null),xe=k.useRef(!1),[Pe,Q]=k.useState(!1),[de,R]=k.useState(0),F=k.useRef(null),G=k.useRef(!0),A=k.useRef(null),te=k.useRef(0),ge=k.useRef(null),ye=k.useRef(new Map),me=k.useRef(0),we=k.useRef(null),pe=k.useRef(null),Ve=k.useRef(0),qe=k.useRef(null);k.useLayoutEffect(()=>{const _=X.current,Z=V.current,he=fe.current;if(!_||!Z||!he)return;let De=-1,W=-1,le=null;const ne=()=>{const ke=Math.round(Z.getBoundingClientRect().height),ce=Math.round(he.getBoundingClientRect().height);if(ke!==De&&(De=ke,_.style.setProperty("--conversation-head-height",`${ke}px`)),ce!==W){const Ae=G.current;W=ce,_.style.setProperty("--conversation-compose-height",`${ce}px`),Ae&&(le!==null&&cancelAnimationFrame(le),le=requestAnimationFrame(()=>{le=null;const ft=ee.current;ft&&G.current&&(ft.scrollTop=Math.max(0,ft.scrollHeight-ft.clientHeight))}))}};ne();const Me=new ResizeObserver(ne);return Me.observe(Z),Me.observe(he),()=>{Me.disconnect(),le!==null&&cancelAnimationFrame(le),_.style.removeProperty("--conversation-head-height"),_.style.removeProperty("--conversation-compose-height")}},[t?.id]),k.useEffect(()=>{s(""),m(null),y(null),d(null),S(null),E(null),M(!1),D(!1),j(!1),te.current+=1,U(null),ye.current.clear(),we.current=null,pe.current=null},[t?.id]),k.useEffect(()=>{if(!p)return;const _=p.reply?.wireId;n.some(he=>he.kind!=="file"&&he.dir==="out"&&!!he.wireId&&!p.wireIds.has(he.wireId)&&he.text===p.text&&(he.replyTo?.wireId??void 0)===_)&&(y(null),m(null),s(he=>he===p.draft?"":he),S(he=>he===p.reply?null:he))},[n,p]);const it=!!c?.wireId&&n.some(_=>_.wireId===c.wireId),We=k.useMemo(()=>c&&!it?[...n,c.message]:n,[n,c,it]);k.useEffect(()=>{it&&d(null)},[it]),k.useLayoutEffect(()=>{const _=N.current;if(!_)return;_.style.height="0px";const Z=Math.max(44,Math.min(_.scrollHeight,132));_.style.height=`${Z}px`,_.style.overflowY=_.scrollHeight>132?"auto":"hidden"},[i,t?.id]);const at=_=>{const Z=ee.current;if(!Z)return;const he=Math.max(0,Z.scrollHeight-Z.clientHeight);if(Math.abs(Z.scrollTop-he)<1){we.current=null,pe.current=null;return}const De=_&&!Yk();we.current=De?he:null,pe.current=De?Z.scrollTop:null,De?Z.scrollTo({top:he,behavior:"smooth"}):Z.scrollTop=he},xt=()=>{F.current===null&&(F.current=requestAnimationFrame(()=>{F.current=null;const _=ee.current;if(!_)return;const Z=_.scrollHeight-_.clientHeight-_.scrollTop>48;Q(Z),Z||R(0)}))};k.useLayoutEffect(()=>{if(!t){A.current=null,G.current=!0,Ve.current=0;return}const _=ee.current;if(!_)return;const Z=A.current!==t.id,he=Ve.current,De=We.length!==he,W=We.at(-1),le=W?W.wireId||`${W.date}:${W.text}`:null,ne=qe.current;if(Ve.current=We.length,qe.current=le,!Z&&!De&&we.current===null&&(G.current=_.scrollHeight-_.clientHeight-_.scrollTop<=48),Z||G.current)at(De&&!Z&&A.current!==null),G.current=!0;else if(De&&We.length>he&&le!==ne){const Me=ne===null?-1:We.findIndex(ke=>(ke.wireId||`${ke.date}:${ke.text}`)===ne);R(ke=>ke+Math.max(1,We.length-Math.max(0,Me+1)))}A.current=t.id,xt()},[t,We.length]),k.useLayoutEffect(()=>{if(xe.current||!e.unreadOpen||window.location.hash.startsWith("#chat-message-"))return;const _=ee.current,Z=document.getElementById(`unread-${wx(e.unreadOpen.wireId)}`);!_||!Z||(_.scrollTop=Math.max(0,Z.offsetTop-16),G.current=!1,xe.current=!0,xt())},[e.unreadOpen,We.length]),k.useLayoutEffect(()=>{const _=window.location.hash;if(!_.startsWith("#chat-message-"))return;const Z=document.getElementById(_.slice(1));Z&&(Z.scrollIntoView({block:"center"}),G.current=!1)},[t?.id,We.length]),k.useLayoutEffect(()=>{const _=ge.current,Z=ee.current;if(_===null||!Z)return;const he=requestAnimationFrame(()=>{ge.current===_&&(Z.scrollTop=_.top+Z.scrollHeight-_.height,ge.current=null)});return()=>cancelAnimationFrame(he)},[We.length]),k.useEffect(()=>{const _=ee.current;if(!_||typeof ResizeObserver>"u")return;const Z=_.firstElementChild;if(!Z)return;const he=new ResizeObserver(()=>{G.current&&at(we.current!==null),xt()});return he.observe(Z),he.observe(_),()=>{he.disconnect(),F.current!==null&&cancelAnimationFrame(F.current)}},[t?.id]);const Vt=async _=>{const Z=++te.current;m(null),j(!0);try{if(_.size>ts&&Wk(_.type,_.name)){const De=await UF(_,ts);if(Z!==te.current)return;E({filename:De.filename,mime:De.mime,bytes:De.bytes,originalSize:De.originalSize});return}if(_.size>ts){m(`"${_.name}" is ${Fr(_.size)} — files up to ${Fr(ts)} can be sent.`);return}const he=await _.arrayBuffer();if(Z!==te.current)return;E({filename:_.name||"file",mime:_.type||"application/octet-stream",bytes:new Uint8Array(he)})}catch(he){Z===te.current&&m(`Photo optimization failed: ${he instanceof Error?he.message:String(he)}`)}finally{Z===te.current&&j(!1)}},lt=()=>{!C||!e.onSendFile||P||(D(!0),e.onSendFile(C,w?.wireId).then(()=>{E(null),S(null)}).catch(_=>m(`File send failed: ${String(_)} — it was not delivered.`)).finally(()=>D(!1)))},Pt=e.onDraftChange;k.useEffect(()=>(Pt?.(i.trim().length>0||l),()=>Pt?.(!1)),[i,l,Pt]);const fn=new Map;for(const _ of We)_.wireId&&fn.set(_.wireId,_);const It=k.useMemo(()=>{const _=new Map;for(const Z of We)_.set(Z,Z.kind==="file"?null:Z.dir==="in"?y2(t?.announcedName??"",Z.text):null);return _},[We,t?.announcedName]),jt=_=>It.get(_)??null,Ln=_=>{if(_.dir==="out")return"You";const Z=jt(_);return Z&&Z.variant==="chat"?Z.author:t?.name??"Them"},ze=_=>{if(_.kind==="file")return _.mime?.startsWith("image/")?"Photo":eo(_.mime??"",_.filename??"")?"Voice message":_.filename||"File";const Z=jt(_);return Z?Z.text||C2(Z):_.text},ur=_=>{if(!_.replyTo)return null;const Z=fn.get(_.replyTo.wireId);return Z?{author:Ln(Z),text:ze(Z)}:{author:"",text:"Original message"}};if(!t)return e.emptyOverride?v.jsx(v.Fragment,{children:e.emptyOverride}):v.jsx("div",{className:"detail",children:v.jsxs("div",{className:"detail-empty",children:[v.jsx(Ee,{name:"chat"}),v.jsxs("div",{children:[v.jsx("div",{style:{fontWeight:650,color:"var(--text-2)"},children:"Select a conversation"}),v.jsx("div",{style:{fontSize:"0.85rem"},children:"Chat with people, agents and apps across ours."})]})]})});const bn=async()=>{const _=i,Z=_.trim(),he=!!p&&_===p.draft&&(w?.wireId??void 0)===p.reply?.wireId;if(!Z||J.current||he)return;p&&y(null),J.current=!0,a(!0),m(null);const De=w,W=De?.wireId,le=new AbortController;let ne=!1,Me=0;s(""),S(null);const ke=`optimistic-${++me.current}`;d({key:ke,wireId:null,message:{dir:"out",text:Z,date:new Date().toISOString(),read:!0,wireId:"",replyTo:W?{wireId:W}:null}});try{const ce=await Promise.race([e.onSend(Z,W,le.signal),new Promise((Ae,ft)=>{Me=window.setTimeout(()=>{ne=!0,le.abort(),ft(new Error("send timeout"))},oz)})]);ce?(ye.current.set(ce,ke),d(Ae=>Ae?.key===ke?{...Ae,wireId:ce}:Ae)):d(Ae=>Ae?.key===ke?null:Ae),y(null)}catch(ce){d(null),s(Ae=>Ae===""?_:Ae),S(Ae=>Ae===null?De:Ae),ne||!(ce instanceof Qf)?(y({draft:_,text:Z,reply:De,wireIds:new Set(n.flatMap(Ae=>Ae.wireId?[Ae.wireId]:[]))}),m(`${ne?"Send timed out":"Send connection was interrupted"} — delivery status is unknown. Check the conversation; edit the draft before sending again.`)):m(`Send failed: ${String(ce)} — the message was not delivered.`)}finally{window.clearTimeout(Me),J.current=!1,a(!1)}},q=!!p&&i===p.draft&&(w?.wireId??void 0)===p.reply?.wireId,se=_=>{_.wireId&&S({wireId:_.wireId,author:Ln(_),text:ze(_)})};return v.jsxs("div",{className:"detail detail-chat",ref:X,children:[v.jsx("div",{className:"detail-head",ref:V,children:v.jsxs("div",{className:"conv-peer",children:[v.jsx("button",{className:"icon-btn detail-back","aria-label":"Back to conversations",onClick:e.onBack,children:v.jsx(Ee,{name:"back"})}),v.jsxs("div",{className:"conv-peer-status",children:[v.jsx("span",{className:"conv-peer-name",children:t.name}),e.syncing&&v.jsxs("div",{className:"conv-sync",role:"status","aria-live":"polite",children:[v.jsx("span",{className:"conv-sync-dot","aria-hidden":!0}),e.syncing==="connecting"?"Connecting…":"Updating…"]}),!e.syncing&&v.jsxs("span",{className:"conv-contact-status",children:[v.jsx(Ee,{name:"lock",size:11}),"Encrypted connection"]})]}),v.jsx("button",{type:"button",className:"conv-contact-trigger conv-contact-avatar","data-contact-trigger":!0,onClick:e.onOpenContact,disabled:!e.onOpenContact,"aria-label":`Open contact details for ${t.name}`,children:v.jsx("span",{className:"conv-contact-initials","aria-hidden":!0,children:t.initials})})]})}),v.jsx("div",{className:"messages",ref:ee,tabIndex:-1,"aria-label":"Conversation timeline",onScroll:_=>{const Z=_.currentTarget,he=Z.scrollHeight-Z.clientHeight-Z.scrollTop;if(we.current!==null){const De=pe.current;if(De===null||Z.scrollTop>=De-1){pe.current=Z.scrollTop,he<=4&&(we.current=null,pe.current=null);return}we.current=null,pe.current=null}G.current=he<=48,xt()},onPointerDown:()=>{we.current=null,pe.current=null},onTouchStart:()=>{we.current=null,pe.current=null},onWheel:()=>{we.current=null,pe.current=null},onDragOver:_=>{e.onSendFile&&_.preventDefault()},onDrop:_=>{if(!e.onSendFile)return;_.preventDefault();const Z=_.dataTransfer.files?.[0];Z&&Vt(Z)},children:v.jsxs("div",{className:"messages-inner",children:[v.jsxs("div",{className:"e2e-note",children:[v.jsx(Ee,{name:"lock"}),"End-to-end encrypted · the broker only sees ciphertext"]}),(e.hiddenEarlier??0)>0&&e.onLoadEarlier&&v.jsxs("button",{className:"btn sm chat-load-earlier",onClick:()=>{G.current=!1;const _=ee.current;ge.current=_?{height:_.scrollHeight,top:_.scrollTop}:null,e.onLoadEarlier?.()},children:["Load earlier messages (",e.hiddenEarlier," remaining)"]}),v.jsx(qP,{initial:!1,children:We.map((_,Z)=>{const he=_===c?.message?c.key:_.wireId&&ye.current.get(_.wireId)||_.wireId||`${_.date}-${(e.hiddenEarlier??0)+Z}`,De=wx(_.wireId||he),W=We[Z-1],le=We[Z+1],ne=jt(_),Me=Ge=>{if(!Ge)return null;const Ye=jt(Ge);return Ye?Ye.variant==="system"?"room:system":`room:chat:${Ye.author}${Ye.role}`:Ge.dir},ke=Me(_),ce=!!W&&Me(W)===ke&&ke!=="room:system",Ae=!!le&&Me(le)===ke&&ke!=="room:system",ft=(_.dir==="out"?"out":"in")+(ce?" cont-top":"")+(Ae?" cont-bot":""),nn=_.wireId?v.jsx("button",{className:"msg-reply",title:"Reply",onClick:()=>se(_),children:v.jsx(Ee,{name:"reply",size:15})}):null;if(ne&&ne.variant==="system"){const Ge=ne.presentation??"system";return v.jsxs(ss.div,{className:"message-motion",id:De,initial:{opacity:0,y:8},animate:{opacity:1,y:0},exit:{opacity:0},transition:yl,children:[_.wireId===e.unreadOpen?.wireId&&v.jsx("div",{id:`unread-${De}`,className:"unread-divider",role:"separator",children:v.jsx("span",{children:"Unread messages"})}),v.jsxs("div",{className:`room-system room-${Ge}-card`,role:"note",children:[ne.label&&v.jsx("span",{className:"room-system-label",children:ne.label}),ne.roomName&&v.jsx("strong",{className:"room-card-name",children:ne.roomName}),v.jsx(yx,{text:ne.text,className:"room-system-text message-markdown"}),!!ne.details?.length&&v.jsx("ul",{className:"room-card-details","aria-label":"Room event details",children:ne.details.map(Ye=>v.jsx("li",{children:Ye},Ye))}),v.jsxs("span",{className:"room-card-provenance",children:[ne.authoredBy&&v.jsx("span",{className:"room-card-author",children:ne.authoredBy}),v.jsx("span",{className:"room-system-at",children:ys(ne.authoredAt||_.date)})]})]})]},he)}if(_.kind==="file"){const Ge=S0(_.wireId)??{id:_.wireId,dir:_.dir,filename:_.filename??"file",mime:_.mime??"application/octet-stream",size:0,date:_.date};return v.jsxs(ss.div,{className:"message-motion",id:De,initial:{opacity:0,y:12,scale:.985},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,scale:.98},transition:yl,children:[_.wireId===e.unreadOpen?.wireId&&v.jsx("div",{id:`unread-${De}`,className:"unread-divider",role:"separator",children:v.jsx("span",{children:"Unread messages"})}),v.jsx(kx,{dir:_.dir==="out"?"out":"in",rowClass:ft,canReply:!!_.wireId,onReply:()=>se(_),after:nn,children:v.jsx("div",{className:`ours-message ours-message-file ours-message--${_.dir}`,children:v.jsx(CD,{rec:Ge,receipt:_.receipt,receiptless:_.receiptless,onPreview:U,onFetch:e.onFetchFile})})})]},he)}const ot=ur(_);return v.jsxs(ss.div,{className:"message-motion",id:De,initial:{opacity:0,y:12,scale:.985},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,scale:.98},transition:yl,children:[_.wireId===e.unreadOpen?.wireId&&v.jsx("div",{id:`unread-${De}`,className:"unread-divider",role:"separator",children:v.jsx("span",{children:"Unread messages"})}),v.jsx(kx,{dir:_.dir==="out"?"out":"in",rowClass:ft,canReply:!!_.wireId,onReply:()=>se(_),after:nn,children:v.jsxs("div",{className:`ours-message ours-message--${_.dir}`,children:[ot&&v.jsxs("div",{className:"quote",children:[ot.author&&v.jsx("span",{className:"quote-author",children:ot.author}),v.jsx("span",{className:"quote-text",children:ot.text})]}),ne&&!ce&&v.jsxs(v.Fragment,{children:[ne.roomName&&v.jsx("div",{className:"room-message-room",children:ne.roomName}),v.jsxs("div",{className:"room-author",children:[v.jsx("span",{className:"room-author-name",children:ne.author}),ne.role&&v.jsx("span",{className:"room-author-role",children:ne.role})]})]}),v.jsx(yx,{text:ne?ne.text:_.text}),v.jsxs("div",{className:"bubble-at",children:[ys(ne?.authoredAt||_.date),_.dir==="out"&&v.jsx(b0,{receipt:_.receipt,receiptless:_.receiptless})]})]})})]},he)})}),v.jsx("div",{className:"thread-end","aria-hidden":!0})]})},t.id),Pe&&v.jsxs("button",{type:"button",className:"jump-latest btn sm","aria-label":de?`Jump to latest, ${de} new messages`:"Jump to latest",onClick:_=>{const Z=_.currentTarget===document.activeElement;R(0),at(!0),Z&&requestAnimationFrame(()=>ee.current?.focus({preventScroll:!0}))},children:[v.jsx("span",{children:"Jump to latest"}),!!de&&v.jsx("span",{className:"jump-latest-count","aria-live":"polite",children:de})]}),h&&v.jsxs("div",{className:"banner error",role:"alert",children:[h,h.startsWith("Send failed:")&&v.jsx("span",{className:"banner-actions",children:v.jsx("button",{className:"linkbtn",onClick:()=>void bn(),children:"retry"})})]}),v.jsxs("div",{className:"composer-wrap",ref:fe,children:[w&&v.jsxs("div",{className:"reply-bar",children:[v.jsx("div",{className:"reply-bar-line"}),v.jsxs("div",{className:"reply-bar-body",children:[v.jsxs("div",{className:"reply-bar-author",children:["Replying to ",w.author]}),v.jsx("div",{className:"reply-bar-text",children:w.text})]}),v.jsx("button",{className:"icon-btn",title:"Cancel reply",onClick:()=>S(null),children:v.jsx(Ee,{name:"close",size:16})})]}),C&&v.jsx(w1,{att:C,sending:P,onSend:lt,onDiscard:()=>E(null)}),$&&v.jsx("div",{className:"attachment-processing",role:"status",children:"Optimizing photo for secure delivery…"}),v.jsxs("div",{className:"composer"+(T?" recording":""),children:[e.onSendFile&&v.jsxs(v.Fragment,{children:[v.jsx("input",{ref:O,type:"file",style:{display:"none"},onChange:_=>{const Z=_.target.files?.[0];Z&&Vt(Z),_.target.value=""}}),v.jsx("button",{className:"icon-btn composer-tool",title:"Attach a file or photo",disabled:P||$||T,onClick:()=>O.current?.click(),children:v.jsx(Ee,{name:"paperclip",size:18})})]}),v.jsx("textarea",{ref:N,className:"field",rows:1,placeholder:(w?"Reply to "+w.author:"Message "+t.name)+"…",value:i,"aria-busy":l,onChange:_=>s(_.target.value),onKeyDown:_=>{_.key==="Enter"?!(window.matchMedia("(pointer: coarse)").matches||window.innerWidth<=860)&&!_.shiftKey&&(_.preventDefault(),bn()):_.key==="Escape"&&S(null)}}),e.onSendFile&&!i.trim()&&!C&&!$&&!P?v.jsx(k1,{disabled:P||$||!!C,onReady:_=>{M(!1),E(_)},onError:_=>{M(!1),m(_)},onActiveChange:M},t.id):v.jsxs("button",{className:"btn primary","aria-label":"Send",onPointerDown:_=>{_.button===0&&document.activeElement===N.current&&_.preventDefault()},onClick:()=>void bn(),disabled:l||q||!i.trim(),title:q?"Delivery status unknown — edit before sending again":void 0,children:[v.jsx(Ee,{name:"send",size:16}),v.jsx("span",{className:"btn-label",children:"Send"})]})]})]}),Y&&(As(Y.filename,Y.mime)?v.jsx($k,{rec:Y,onClose:()=>U(null)}):v.jsx(Bk,{rec:Y,onClose:()=>U(null),onSendText:e.onSend,onSendFile:e.onSendFile}))]})}const Gk=3;function uz(e,t,n=Gk){return[t,...e.filter(i=>i.cid!==t.cid)].slice(0,n)}function cz(e,t){return e.filter(n=>n.id!==t)}const fz=6e3,dz=uz,hz=cz;function pz(){const[e,t]=k.useState([]),n=k.useRef(0),i=k.useCallback((a,c,d)=>{const h=Date.now(),m={id:`${a}:${h}:${n.current++}`,cid:a,name:c,preview:"",at:h};t(p=>dz(p,m,Gk))},[]),s=k.useCallback(a=>t(c=>hz(c,a)),[]),l=k.useCallback(a=>t(c=>c.filter(d=>d.cid!==a)),[]);return{toasts:e,push:i,dismiss:s,clear:l}}function mz(e){const{item:t,onOpen:n,onDismiss:i}=e,[s,l]=k.useState(!1),[a,c]=k.useState(!1),d=s||a;return k.useEffect(()=>{if(d)return;const h=setTimeout(()=>i(t.id),fz);return()=>clearTimeout(h)},[t.id,d,i]),v.jsxs("div",{className:"banner msg",role:"status",onMouseEnter:()=>l(!0),onMouseLeave:()=>l(!1),onFocus:()=>c(!0),onBlur:h=>{h.currentTarget.contains(h.relatedTarget)||c(!1)},children:[v.jsxs("button",{className:"msg-open",title:`Open the conversation with ${t.name}`,onClick:()=>n(t.cid),children:[v.jsx("span",{className:"avatar sm accent","aria-hidden":"true",children:rd(t.name)}),v.jsxs("span",{className:"msg-text",children:[v.jsx("strong",{className:"msg-name",children:t.name}),v.jsx("span",{className:"msg-preview",children:t.preview||"New message"})]})]}),v.jsx("button",{className:"icon-btn msg-close",title:"Dismiss","aria-label":`Dismiss the notification from ${t.name}`,onClick:()=>i(t.id),children:v.jsx(Ee,{name:"close",size:15})})]})}function gz(e){return v.jsx(v.Fragment,{children:e.items.map(t=>v.jsx(mz,{item:t,onOpen:e.onOpen,onDismiss:e.onDismiss},t.id))})}function yz(e){const t=k.useRef(null),{text:n,size:i=240}=e;return k.useEffect(()=>{if(!t.current||!n)return;const s=t.current;Ch(()=>import("./browser-DQqNbucF.js").then(l=>l.b),[]).then(l=>{l.toCanvas(s,n,{width:i,margin:2,errorCorrectionLevel:"M",color:{dark:"#000000",light:"#ffffff"}})})},[n,i]),v.jsx("div",{style:{display:"flex",justifyContent:"center",margin:"8px 0"},children:v.jsx("canvas",{ref:t,"data-testid":"qr-canvas","data-invite":n,width:i,height:i,style:{borderRadius:8,border:"1px solid var(--line)",imageRendering:"pixelated"}})})}function vz(e){const t=k.useRef(null),n=k.useRef(null),i=k.useRef(null),s=k.useRef(0),l=k.useRef(!0),[a,c]=k.useState("requesting"),[d,h]=k.useState(""),m=k.useCallback(()=>{s.current&&cancelAnimationFrame(s.current),i.current&&(i.current.getTracks().forEach(w=>w.stop()),i.current=null),t.current&&(t.current.srcObject=null)},[]),p=k.useCallback(w=>{i.current=w;const S=t.current;S.srcObject=w,S.setAttribute("playsinline","true"),S.play();const C=n.current,E=C.getContext("2d"),T=()=>{if(l.current)if(S.readyState>=S.HAVE_ENOUGH_DATA){const M=S.videoWidth||320,P=S.videoHeight||240;C.width=M,C.height=P,E.drawImage(S,0,0,M,P);const D=E.getImageData(0,0,M,P);Ch(()=>import("./jsQR-C_F4GL5i.js").then($=>$.j),[]).then($=>{const j=$.default,Y=j(D.data,D.width,D.height,{inversionAttempts:"dontInvert"});if(Y&&Y.data&&l.current){m(),e.onDecode(Y.data);return}l.current&&(s.current=requestAnimationFrame(T))})}else s.current=requestAnimationFrame(T)};s.current=requestAnimationFrame(T)},[m,e]);k.useEffect(()=>{if(l.current=!0,!navigator.mediaDevices?.getUserMedia){c("nocamera");return}return navigator.mediaDevices.getUserMedia({video:{facingMode:"environment"}}).then(w=>{if(!l.current){w.getTracks().forEach(S=>S.stop());return}c("scanning"),p(w)}).catch(w=>{if(!l.current)return;const S=w.name??"";S==="NotAllowedError"||S==="PermissionDeniedError"?c("denied"):S==="NotFoundError"||S==="DevicesNotFoundError"?c("nocamera"):(c("error"),h(w.message??String(w)))}),()=>{l.current=!1,m()}},[]);const y=()=>{m(),e.onClose()};return v.jsxs("div",{"data-testid":"qr-scanner",style:{display:"flex",flexDirection:"column",gap:12,padding:"12px 0"},children:[(a==="requesting"||a==="scanning")&&v.jsxs(v.Fragment,{children:[v.jsx("p",{className:"muted",style:{margin:0,fontSize:"0.88rem"},children:a==="requesting"?"Requesting camera…":"Point your camera at the QR code."}),v.jsxs("div",{style:{position:"relative",borderRadius:8,overflow:"hidden",background:"#000",minHeight:200},children:[v.jsx("canvas",{ref:n,"data-testid":"scanner-canvas",style:{display:"none"}}),v.jsx("video",{ref:t,"data-testid":"scanner-video",muted:!0,playsInline:!0,style:{width:"100%",display:"block",borderRadius:8}}),a==="scanning"&&v.jsx("div",{style:{position:"absolute",inset:0,pointerEvents:"none",display:"flex",alignItems:"center",justifyContent:"center"},children:v.jsx("div",{style:{width:160,height:160,borderRadius:12,border:"2px solid var(--accent)",boxShadow:"0 0 0 9999px rgba(0,0,0,0.4)"}})})]})]}),a==="denied"&&v.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[v.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,color:"var(--text-2)"},children:[v.jsx(Ee,{name:"shield",size:16}),v.jsx("span",{style:{fontWeight:600,fontSize:"0.9rem"},children:"Camera access denied"})]}),v.jsx("p",{className:"muted",style:{margin:0,fontSize:"0.88rem"},children:"Camera permission was denied. To scan QR codes, allow camera access in your browser settings, then try again. Or paste the invite text below instead."})]}),a==="nocamera"&&v.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[v.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,color:"var(--text-2)"},children:[v.jsx(Ee,{name:"close",size:16}),v.jsx("span",{style:{fontWeight:600,fontSize:"0.9rem"},children:"No camera available"})]}),v.jsx("p",{className:"muted",style:{margin:0,fontSize:"0.88rem"},children:"No camera was found on this device. Paste the invite text below instead."})]}),a==="error"&&v.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8},children:v.jsxs("p",{style:{margin:0,fontSize:"0.85rem",color:"var(--danger, #e53)"},children:["Camera error: ",d||"unknown error",". Paste the invite text below instead."]})}),v.jsx("button",{className:"btn",style:{justifyContent:"center"},onClick:y,children:a==="scanning"?v.jsxs(v.Fragment,{children:[v.jsx(Ee,{name:"close",size:14}),"Cancel scan"]}):v.jsxs(v.Fragment,{children:[v.jsx(Ee,{name:"close",size:14}),"Close scanner"]})})]})}function xz(e){const[t,n]=k.useState("generate"),[i,s]=k.useState("one_time"),[l,a]=k.useState(""),[c,d]=k.useState(null),[h,m]=k.useState("one_time"),[p,y]=k.useState(""),[w,S]=k.useState(""),[C,E]=k.useState(!1),[T,M]=k.useState(null),[P,D]=k.useState(null),[$,j]=k.useState(!1),[Y,U]=k.useState(null),O=k.useRef(!1),N=async()=>{if(!O.current){O.current=!0,E(!0),D(null),M(null);try{m(i),d(await e.onCreate(i,i==="one_time"&&l.trim()||void 0))}catch(V){D(V instanceof Error?V.message:String(V))}finally{O.current=!1,E(!1)}}},X=v.jsx(Uk,{className:"modal-tabs",label:"Invite mode",options:[{id:"generate",label:"Generate invite"},{id:"accept",label:"Accept invite"}],value:t,onChange:n,idPrefix:"invite-tab",panelId:"invite-panel"});return v.jsx(Ds,{title:t==="generate"?"Invite a contact":"Accept an invite",onClose:()=>{O.current||e.onClose()},tabs:X,children:v.jsxs("div",{id:"invite-panel",role:"tabpanel","aria-labelledby":`invite-tab-${t}`,children:[t==="generate"&&!c&&v.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:13},children:[v.jsxs("p",{className:"muted","data-testid":"invite-identity",style:{margin:0,fontSize:"0.85rem"},children:["Creating as ",v.jsx("strong",{children:e.identity.name})," · ",v.jsxs("span",{className:"mono",children:["@",w0(e.identity.cid)]})]}),v.jsxs("div",{role:"radiogroup","aria-label":"Invite kind",style:{display:"flex",flexDirection:"column",gap:7},children:[v.jsxs("label",{children:[v.jsx("input",{type:"radio",name:"invite-kind",checked:i==="one_time",onChange:()=>s("one_time")})," One person (one time)"]}),v.jsxs("label",{children:[v.jsx("input",{type:"radio",name:"invite-kind",checked:i==="public",onChange:()=>s("public")})," Reusable public invite"]})]}),i==="one_time"?v.jsxs(v.Fragment,{children:[v.jsx("p",{className:"muted",style:{margin:0,fontSize:"0.9rem"},children:"Optionally name the person or agent this invite is for."}),v.jsx("input",{className:"field",value:l,onChange:V=>a(V.target.value),placeholder:"Their name (optional), e.g. Bob",maxLength:64})]}):v.jsx("p",{className:"onb-warning","data-testid":"public-invite-warning",style:{margin:0,fontSize:"0.9rem"},children:"Anyone with this invite can connect until you revoke it. It has no expiry and stays valid across server restarts."}),v.jsx("button",{className:"btn primary",style:{justifyContent:"center"},disabled:C,onClick:()=>void N(),children:C?"Generating…":i==="public"?"Create public invite":"Generate invite"}),i==="public"&&v.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[v.jsx("h4",{style:{margin:0,fontSize:"0.9rem"},children:"Active reusable invites"}),e.invites.filter(V=>V.mode==="public").length===0&&v.jsx("p",{className:"muted",style:{margin:0},children:"None right now."}),e.invites.filter(V=>V.mode==="public").map(V=>v.jsxs("div",{"data-testid":"public-invite-row",style:{padding:"8px 10px",background:"var(--inset)",borderRadius:7},children:[v.jsx("span",{className:"mono",children:V.invite_id}),v.jsxs("p",{className:"muted",children:["Created ",V.created?R2(V.created):"unknown"," · Active until revoked · No expiry"]}),Y===V.invite_id?v.jsxs("span",{children:[v.jsx("button",{className:"btn sm danger",onClick:()=>void e.onRevoke(V.invite_id).then(()=>(U(null),e.onRefresh())).catch(fe=>D(String(fe))),children:"Confirm revoke"})," ",v.jsx("button",{className:"btn sm",onClick:()=>U(null),children:"Keep it"})]}):v.jsx("button",{className:"btn sm",onClick:()=>U(V.invite_id),children:"Revoke"})]},V.invite_id))]}),T&&v.jsx("p",{className:"muted",children:T}),P&&v.jsx("p",{className:"onb-error",children:P})]}),t==="generate"&&c&&v.jsxs(v.Fragment,{children:[v.jsx("p",{className:"muted","data-testid":h==="public"?"public-result-note":void 0,children:h==="public"?"Shown only on this screen. Copy it now; the text cannot be recovered later. The invite stays active until revoked.":`Send this invite to ${l.trim()||"your contact"}. It can be redeemed once.`}),v.jsx("textarea",{className:"field mono","data-testid":"invite-result-text",readOnly:!0,rows:5,value:c,onFocus:V=>V.currentTarget.select()}),h==="one_time"&&v.jsx(yz,{text:c}),v.jsxs("button",{className:"btn primary",onClick:()=>void navigator.clipboard.writeText(c).then(()=>M("Copied to clipboard.")),children:[v.jsx(Ee,{name:"copy",size:15}),"Copy invite"]}),h==="public"&&v.jsx("button",{className:"btn","data-testid":"done-hide-invite",onClick:()=>{d(null),a(""),e.onRefresh()},children:"Done — hide invite"}),T&&v.jsx("p",{className:"muted",children:T})]}),t==="accept"&&v.jsxs("form",{style:{display:"flex",flexDirection:"column",gap:13},onSubmit:V=>{V.preventDefault(),!(!p.trim()||C)&&(E(!0),D(null),e.onAccept(p.trim(),w.trim()||void 0).then(()=>{M("Invite accepted — the contact will appear once the sender verifies your identity."),y(""),S("")}).catch(fe=>D(String(fe))).finally(()=>E(!1)))},children:[v.jsx("p",{className:"muted",children:"Paste the invite you received, or scan a QR code."}),$?v.jsx(vz,{onDecode:V=>{y(V),j(!1)},onClose:()=>j(!1)}):v.jsxs("button",{type:"button",className:"btn",onClick:()=>j(!0),children:[v.jsx(Ee,{name:"monitor",size:15}),"Scan QR code"]}),v.jsx("textarea",{className:"field mono","aria-label":"Invite",rows:5,value:p,onChange:V=>y(V.target.value),placeholder:"Paste invite text…"}),v.jsx("input",{className:"field",value:w,onChange:V=>S(V.target.value),placeholder:"Rename them (optional)",maxLength:64}),v.jsx("button",{className:"btn primary",type:"submit",disabled:C||!p.trim(),children:C?"Connecting…":"Add contact"}),T&&v.jsx("p",{className:"muted",children:T}),P&&v.jsx("p",{className:"onb-error",children:P})]})]})})}function wz(e){const[t,n]=k.useState(e.identity.bio??""),[i,s]=k.useState(!1),[l,a]=k.useState(null),[c,d]=k.useState(e.push.preview),h=xM(),m=!e.workerSupported||e.push.status==="unsupported"?h??"Unavailable — requires a secure browser with service-worker support.":e.push.status==="needs-permission"?h??"Needs permission — allow notifications, then choose Enable or Repair.":e.push.status==="on"?"On — this browser and the server agree on the current Web Push configuration.":e.push.status==="repairing"?"Repairing — checking the browser subscription and server acknowledgement…":e.push.status==="error"?"Repair needed — the browser and server could not confirm the same subscription.":"Off — enable notifications for this browser.";return v.jsxs(Ds,{title:"Settings",onClose:e.onClose,wide:!0,children:[v.jsxs("div",{children:[v.jsx("span",{className:"lbl",children:"Display name"}),v.jsx("input",{className:"field",readOnly:!0,value:e.identity.name})]}),v.jsxs("div",{children:[v.jsx("span",{className:"lbl",children:"Your address"}),v.jsx("input",{className:"field mono",readOnly:!0,value:e.identity.cid,onFocus:p=>p.currentTarget.select()}),v.jsx("p",{className:"muted",children:"Your public address on ours. Share an invite to connect more easily."})]}),v.jsxs("div",{children:[v.jsx("span",{className:"lbl",children:"Public bio"}),v.jsx("textarea",{className:"field",rows:3,value:t,onChange:p=>{n(p.target.value),s(!1),a(null)}}),v.jsx("button",{className:"btn sm",onClick:()=>{a(null),e.onSaveBio(t).then(()=>s(!0)).catch(p=>a(String(p)))},children:i?"Saved":"Save bio"}),l&&v.jsx("p",{className:"onb-error",children:l})]}),v.jsxs("label",{style:{display:"flex",gap:9},children:[v.jsx("input",{type:"checkbox",checked:e.dark,onChange:e.onToggleDark})," Dark mode"]}),v.jsxs("div",{style:{borderTop:"1px solid var(--line)",paddingTop:16},children:[v.jsx("h4",{children:"Notifications"}),v.jsx("p",{className:e.push.status==="needs-permission"||e.push.status==="error"?"onb-error":"muted",children:m}),h&&h!==m&&v.jsx("p",{className:"muted","data-testid":"push-platform-guidance",children:h}),v.jsxs("fieldset",{style:{border:0,padding:0,margin:"12px 0"},children:[v.jsx("legend",{className:"lbl",children:"Lock-screen preview"}),v.jsxs("label",{style:{display:"block",marginTop:7},children:[v.jsx("input",{type:"radio",name:"push-preview",checked:c==="full",onChange:()=>d("full")})," Full — sender and message text or filename"]}),v.jsxs("label",{style:{display:"block",marginTop:7},children:[v.jsx("input",{type:"radio",name:"push-preview",checked:c==="private",onChange:()=>d("private")})," Private — generic content only"]})]}),v.jsx("p",{className:"muted",children:"Full previews can expose sender names, message text, and filenames on the lock screen. The push provider still sees delivery endpoint, timing, and payload size metadata in either mode."}),v.jsx("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:e.push.status==="on"?v.jsxs(v.Fragment,{children:[v.jsx("button",{className:"btn",disabled:e.busy,onClick:()=>void e.onPushAction("disable",c),children:"Disable notifications"}),v.jsx("button",{className:"btn",disabled:e.busy,onClick:()=>void e.onPushAction("repair",c),children:"Repair"}),c!==e.push.preview&&v.jsx("button",{className:"btn primary",disabled:e.busy,onClick:()=>void e.onPushAction("enable",c),children:"Save preview"})]}):v.jsx("button",{className:"btn primary",disabled:e.busy||!e.workerSupported||e.push.status==="unsupported",onClick:()=>void e.onPushAction(e.push.status==="error"||e.push.blocked?"repair":"enable",c),children:e.busy?"Repairing…":e.push.status==="error"||e.push.blocked?"Repair":"Enable notifications"})})]}),v.jsxs("div",{style:{borderTop:"1px solid var(--line)",paddingTop:16},children:[v.jsx("h4",{children:"App status"}),v.jsx("p",{className:"muted",children:e.offline?"Offline — reconnecting. Message and identity data are never cached.":"Online."}),e.onInstall&&v.jsx("button",{className:"btn",onClick:e.onInstall,children:"Install app"}),e.updateAvailable&&v.jsx("button",{className:"btn primary",onClick:e.onReloadUpdate,children:"Reload to update"})]}),v.jsxs("div",{style:{borderTop:"1px solid var(--line)",paddingTop:16},children:[v.jsx("h4",{children:"Build"}),v.jsx("input",{className:"field mono",readOnly:!0,value:e.build?`${e.build.version} · ${e.build.sha}`:"Loading…"})]})]})}function kz(e,t,n,i,s=6e4){return!t||!t.sha?"current":t.sha===e?(n.remoteSha=null,n.firstMismatchAt=null,"current"):(n.remoteSha=t.sha,(n.firstMismatchAt===null||n.firstMismatchAt===void 0)&&(n.firstMismatchAt=i),n.controllerChanged?"newer-available":i-n.firstMismatchAt>=s?"stuck":"newer-available")}const Sz="44b02891e4845ff6027694986cfd703bb4727c77",bz=15*6e4,Cz=6e4,Ez=kz;async function Tz(){try{const e=await fetch("/version.json",{cache:"no-store"});return e.ok?await e.json():null}catch{return null}}function Pz(e){const t={remoteSha:null,firstMismatchAt:null,controllerChanged:!1},n=()=>{t.controllerChanged=!0};navigator.serviceWorker?.addEventListener("controllerchange",n);let i=!1;const s=async()=>{const d=await Tz(),h=Ez(Sz,d,t,Date.now(),Cz);h==="newer-available"?(e.onUpdateAvailable(),navigator.serviceWorker?.getRegistration().then(m=>m?.update())):h==="stuck"&&!i&&(i=!0,e.onStuck(d.sha))},l=setTimeout(()=>void s(),5e3),a=setInterval(()=>void s(),bz),c=()=>{document.visibilityState==="visible"&&s()};return document.addEventListener("visibilitychange",c),()=>{clearTimeout(l),clearInterval(a),document.removeEventListener("visibilitychange",c),navigator.serviceWorker?.removeEventListener("controllerchange",n)}}async function Rz(e){try{const t=await navigator.serviceWorker.getRegistrations();await Promise.all(t.map(i=>i.unregister()));const n=await caches.keys();await Promise.all(n.map(i=>caches.delete(i)))}catch{}return location.replace(location.pathname+"?v="+encodeURIComponent(e)),new Promise(()=>{})}function Mz(){const e=new URL(location.href);e.searchParams.has("v")&&(e.searchParams.delete("v"),history.replaceState(null,"",e.pathname+e.search+e.hash))}const Sx=[0,100,400,1e3,3e3,6e3],bx=e=>new Promise(t=>setTimeout(t,e)),Cx={delivered:1,read:2},Ex="ours-dark-v3",Tx="#chat-message-",Px=Rl,Az=e=>e instanceof Error&&e.message?e.message:"The request could not be completed.";function Qk(e,t){const n=new Map,i=[];for(const s of e?.messages??[]){const l={dir:s.dir,text:s.text,date:s.date,read:s.read,wireId:s.wire_id,replyTo:s.reply_to?{wireId:s.reply_to.wire_id}:null,receipt:s.receipt??void 0,receiptless:s.dir==="out"&&!s.wire_id};s.wire_id?n.set(s.wire_id,l):i.push(l)}for(const s of t){const l=n.get(s.wire_id);n.set(s.wire_id,{dir:s.dir,text:"",date:s.date,read:l?.read??s.dir==="out",wireId:s.wire_id,replyTo:s.reply_to?{wireId:s.reply_to.wire_id}:l?.replyTo??null,kind:"file",filename:s.filename,mime:s.mime,receipt:l?.receipt})}return[...i,...n.values()].sort((s,l)=>{const a=Px(s.date)-Px(l.date);return a===0?s.wireId.localeCompare(l.wireId):a})}function Nz(e){const t={};for(const n of Object.values(e.roots??{}))t[n.root_cid]={label:n.root_name,note:"Verified identity"};return t}function Iz(e,t){return[...e.contacts.contacts.map(i=>{const s=e.contacts.roots?.[i.container_id],l=or(e,i.container_id),c=Qk(l,t[i.container_id]??[]).at(-1),d=Al(i);return{id:i.container_id,name:d,announcedName:i.name,initials:rd(d),when:c?P2(c.date):"",activityAt:c?.date??"",last:c?.kind==="file"?L2(c.filename,c.mime):l?.preview??c?.text??"",unread:l?.unread??0,status:"active",root:s?.root_cid??null,sub:s?`role “${s.role_id}” of ${s.root_name}`:"",roleId:s?.role_id??null,rootName:s?.root_name??null,mine:!1,kind:s?"agent":"person"}}),...e.contacts.pending.map(i=>{const s=Al(i);return{id:`pending:${i.container_id}`,name:s,announcedName:i.name,initials:rd(s),when:"",activityAt:"",last:`${i.queued} queued · approval required`,unread:0,status:"pending",root:null,sub:"",roleId:null,rootName:null,mine:!1,kind:"person"}})]}function jz(){return v.jsx(Dz,{})}function Dz(){const e=k.useRef(hM(Gy(window.location.pathname))).current,[t,n]=k.useReducer(Jy,e),[i,s]=k.useState(null),l=k.useRef(0),a=k.useRef(null),c=k.useRef(t),d=k.useRef(new uM),h=k.useRef(null),m=k.useRef(new Map),p=k.useRef(new Map),[y,w]=k.useState({}),S=k.useRef(y),[C,E]=k.useState(null),T=k.useRef(new Set),[M,P]=k.useState(null),D=k.useRef(M),$=k.useRef(!1),[j,Y]=k.useState([]),[U,O]=k.useState(null),[N,X]=k.useState(()=>localStorage.getItem(Ex)!=="0"),[V,fe]=k.useState(null),[J,ee]=k.useState({supported:!1,offline:!navigator.onLine,updateAvailable:!1,registration:null}),[xe,Pe]=k.useState({status:"unsupported",preview:"full"}),[Q,de]=k.useState(!1),R=k.useRef(!1),[F,G]=k.useState(()=>window.location.hash.startsWith(Tx)),{toasts:A,push:te,dismiss:ge,clear:ye}=pz(),me=k.useCallback(W=>{c.current=Jy(c.current,W),n(W)},[]),we=k.useCallback(W=>{$.current=W},[]);k.useEffect(()=>{c.current=t},[t]),D.current=M,S.current=y,k.useMemo(()=>(cv(Object.values(y).flat()),null),[y]),k.useEffect(()=>(document.documentElement.classList.toggle("theme-dark",N),()=>document.documentElement.classList.remove("theme-dark")),[N]);const pe=k.useCallback(W=>me({type:"error",message:Az(W)}),[me]),Ve=k.useCallback(()=>{const W=c.current;return{visibility:document.visibilityState,appRoute:W.route.name==="chats"?"chats":"other",selectedContactCid:ri(W),desktopLayout:h.current?.matches??window.innerWidth>=861,mobileDetailOpen:W.mobileDetailOpen,conversationCoveringDialogOpen:D.current!==null}},[]),qe=k.useCallback(async(W,le=!0)=>{try{const ne=await Ke.conversation(W);return me({type:"page",contactCid:W,page:ne}),ne}catch(ne){return le&&pe(ne),null}},[me,pe]),it=k.useCallback(async(W,le=!0)=>{try{const ne=await Ke.files(W);return cv(ne.files),w(Me=>({...Me,[W]:ne.files})),ne.files}catch(ne){return le&&pe(ne),null}},[pe]);k.useEffect(()=>Pz({onUpdateAvailable:()=>ee(W=>({...W,updateAvailable:!0})),onStuck:W=>{Rz(W)}}),[]);const We=k.useCallback(async()=>{const W=await Ke.contacts();return me({type:"contacts",contacts:{...W,pending:W.pending??[]}}),W},[me]),at=k.useCallback(async()=>{try{const[W,le,ne]=await Promise.all([Ke.identity(),Ke.contacts(),Ke.buildInfo()]),Me={...le,pending:le.pending??[]};return c.current.identity&&c.current.identity.cid!==W.cid&&(j2(),S.current={},w({})),me({type:"snapshot",identity:W,contacts:Me}),O(ne),await Promise.all(Me.contacts.flatMap(ke=>[qe(ke.container_id,!1),it(ke.container_id,!1)])),ri(c.current)}catch(W){return pe(W),null}},[me,it,qe,pe]),xt=k.useCallback(async W=>{await d.current.request(W,async()=>{lM(W,Ve())&&(await Ke.markRead(W),await Promise.all([qe(W),We()]))}).catch(pe)},[Ve,We,qe,pe]),Vt=k.useCallback(async W=>{const le=++l.current;a.current?.abort();const ne=new AbortController;a.current=ne,s(null),ye(W),it(W,!1);let Me;try{Me=await Ke.conversation(W,void 0,ne.signal)}catch(Ye){ne.signal.aborted||pe(Ye);return}if(ne.signal.aborted||le!==l.current)return;me({type:"page",contactCid:W,page:Me});const ke=Me.unread;let ce=[...Me.messages],Ae=Me.nextBefore;const ft=new Set,nn=new Set(ce.map(Ye=>Ye.wire_id).filter(Boolean)),ot=()=>ce.filter(Ye=>Ye.dir==="in"&&!Ye.read);for(;ot().length<ke&&Ae&&!ft.has(Ae);){ft.add(Ae);let Ye;try{Ye=await Ke.conversation(W,Ae,ne.signal)}catch{break}if(ne.signal.aborted||le!==l.current)return;const cr=Ye.messages.filter(fr=>!fr.wire_id||!nn.has(fr.wire_id));if(!cr.length&&Ye.nextBefore===Ae)break;for(const fr of cr)fr.wire_id&&nn.add(fr.wire_id);ce=[...cr,...ce],me({type:"older_page",contactCid:W,page:Ye,newer:Me.messages}),Ae=Ye.nextBefore}const Ge=ot()[0];Ge?.wire_id&&le===l.current&&!ne.signal.aborted&&s({contactCid:W,wireId:Ge.wire_id,count:ke}),await xt(W)},[ye,me,xt,it,pe]),lt=k.useCallback(async(W,le,ne="page")=>{const Me=`page:${W}:${ne}`,ke=(m.current.get(Me)??0)+1;m.current.set(Me,ke);for(const ce of Sx){if(ce&&await bx(ce),m.current.get(Me)!==ke)return;const Ae=await qe(W,!1);if(Ae&&le(Ae))return}},[qe]),Pt=k.useCallback(async(W,le)=>{const ne=`file:${W}`,Me=(m.current.get(ne)??0)+1;m.current.set(ne,Me);for(const ke of Sx)if(ke&&await bx(ke),m.current.get(ne)!==Me||(await it(W,!1))?.some(Ae=>Ae.wire_id===le))return},[it]),fn=k.useRef(!1);k.useEffect(()=>{if(!F||!t.loaded)return;const W=decodeURIComponent(window.location.hash.slice(Tx.length)),le=ri(c.current);if(!W||!le){G(!1);return}if(or(c.current,le)?.messages.some(ne=>ne.wire_id===W)){G(!1);return}fn.current||(fn.current=!0,lt(le,ne=>ne.messages.some(Me=>Me.wire_id===W),`anchor:${W}`).catch(()=>{}).finally(()=>G(!1)))},[F,lt,t.loaded,t.pages]),k.useMemo(()=>(I2({url:W=>Object.values(S.current).flat().find(ne=>ne.wire_id===W)?.available?Ke.mediaUrl(W):null,bytes:async W=>{if(!Object.values(S.current).flat().find(Me=>Me.wire_id===W)?.available)return null;const ne=await fetch(Ke.mediaUrl(W),{cache:"no-store",credentials:"same-origin"});if(!ne.ok)throw new Error(`Media request failed (HTTP ${ne.status})`);return new Uint8Array(await ne.arrayBuffer())},fetch:async W=>{const le=Object.values(S.current).flat().find(ne=>ne.wire_id===W);if(!le)throw new Error("Media record is unavailable");await Ke.fetchFiles([W]),await it(le.contact_id)}}),null),[it]),k.useEffect(()=>{let W;gM(ne=>{ee(ne),nv(ne.registration).then(Pe).catch(()=>Pe(Me=>({...Me,status:"error"})))},{shouldDeferReload:()=>$.current||D.current!==null}).then(ne=>{W=ne}).catch(pe);const le=ne=>{ne.preventDefault(),fe(ne)};return window.addEventListener("beforeinstallprompt",le),()=>{W?.(),window.removeEventListener("beforeinstallprompt",le)}},[pe]),k.useEffect(()=>CM(),[]),k.useEffect(()=>{if(!(!J.registration||xe.status!=="on"))return aM({registration:J.registration,identity:Ke.identity,onEvent:d0})},[xe.status,xe.bindingId,J.registration]),k.useEffect(()=>{const W=()=>Pe(le=>({...le,status:"error"}));return window.addEventListener("ours-push-repair-required",W),()=>window.removeEventListener("ours-push-repair-required",W)},[]),k.useEffect(()=>{window.location.pathname==="/"&&window.history.replaceState(null,"",ni()),h.current=window.matchMedia("(min-width: 861px)");const W=()=>{const ce=Gy(window.location.pathname);a.current?.abort(),l.current+=1,s(null),me({type:"route",route:ce}),R.current&&ce.name==="chats"&&ce.contactCid&&(R.current=!1,requestAnimationFrame(()=>document.querySelector("[data-contact-trigger]")?.focus({preventScroll:!0}))),ce.name==="chats"&&ce.contactCid&&Vt(ce.contactCid)},le=()=>{if(document.visibilityState!=="visible")return;const ce=ri(c.current);ce&&xt(ce),g0(),J.registration&&nv(J.registration).then(Pe).catch(()=>Pe(Ae=>({...Ae,status:"error"})))};window.addEventListener("popstate",W),document.addEventListener("visibilitychange",le);const ne=ce=>{const Ae=ce.type==="sync_required"?`${ce.type}:${ce.reason}`:ce.type==="receipt_received"?`${ce.type}:${ce.contact_id}:${ce.kind}:${ce.wire_ids.join(",")}`:`${ce.type}:${ce.contact_id}:${ce.wire_id}`,ft=Date.now(),nn=p.current.get(Ae)??0;p.current.set(Ae,ft);for(const[ot,Ge]of p.current)ft-Ge>6e4&&p.current.delete(ot);ft-nn<6e4||(async()=>{if(ce.type==="sync_required"){await at();return}if(We().catch(pe),ce.type==="file_received"){await Pt(ce.contact_id,ce.wire_id);const ot=c.current.contacts.contacts.find(Ge=>Ge.container_id===ce.contact_id);ri(c.current)!==ce.contact_id&&ot&&te(ce.contact_id,Al(ot),"New file");return}if(ce.type==="message_received"){const ot=c.current.contacts.contacts.find(Ge=>Ge.container_id===ce.contact_id);await lt(ce.contact_id,Ge=>Ge.messages.some(Ye=>Ye.wire_id===ce.wire_id),`message:${ce.wire_id}`),ri(c.current)===ce.contact_id?await xt(ce.contact_id):ot&&te(ce.contact_id,Al(ot),"New message");return}me({type:"receipt",contactCid:ce.contact_id,kind:ce.kind,wireIds:ce.wire_ids}),await lt(ce.contact_id,ot=>ce.wire_ids.every(Ge=>{const Ye=ot.messages.find(cr=>cr.wire_id===Ge);return!!Ye?.receipt&&Cx[Ye.receipt]>=Cx[ce.kind]}),`receipt:${ce.wire_ids.join(",")}`)})().catch(pe)},Me=rM(ne),ke=iM(ne,ce=>me({type:"connection",connection:ce}));return at().then(ce=>{ce&&Vt(ce)}),()=>{ke(),Me(),window.removeEventListener("popstate",W),document.removeEventListener("visibilitychange",le)}},[lt,Pt,me,xt,Vt,te,We,at,pe,J.registration]);const It=(W,le,ne)=>{window.history.pushState({oursMessenger:!0},"",le),me({type:"route",route:W,mobileDetailOpen:ne})},jt=async W=>{It({name:"chats",contactCid:W},ni(W),!0),await Vt(W)},Ln=async W=>{const le=or(c.current,W);if(!(!le?.nextBefore||T.current.has(W))){T.current.add(W),E(W);try{const ne=await Ke.conversation(W,le.nextBefore);me({type:"older_page",contactCid:W,page:ne,newer:le.messages})}catch(ne){pe(ne)}finally{T.current.delete(W),E(null)}}},ze=ri(t),ur=t.contacts.contacts.find(W=>W.container_id===ze),bn=k.useMemo(()=>Iz(t,y),[t,y]),q=bn.find(W=>W.id===ze)??null,se=ze?Qk(or(t,ze),y[ze]??[]):[],_=t.identity,Z=t.loaded?ze&&!or(t,ze)||F?"updating":t.connection!=="live"?"connecting":null:"connecting",he=async(W,le=xe.preview)=>{if(J.registration){de(!0),Pe(ne=>({...ne,status:"repairing",preview:le}));try{Pe(await(W==="enable"?m0(J.registration,{preview:le}):W==="repair"?SM(J.registration,le):bM(J.registration,xe)))}catch(ne){Pe(Me=>({...Me,status:"error"})),pe(ne)}finally{de(!1)}}},De=()=>{Y([]),P("invite"),Ke.invites().then(Y).catch(pe)};return t.route.name==="not_found"?v.jsxs("div",{className:"centered-screen",children:[v.jsx("h1",{children:"Page not found"}),v.jsx("button",{className:"btn primary",onClick:()=>It({name:"chats",contactCid:null},ni()),children:"Open chats"})]}):_?v.jsx("div",{className:N?"theme-dark":"",style:{height:"100%"},children:v.jsxs("div",{className:"app signal-app",children:[v.jsxs("main",{className:"section signal-stage"+(t.mobileDetailOpen?" show-detail":""),children:[v.jsx(sz,{contacts:bn,roots:Nz(t.contacts),selected:ze,onSelect:W=>{W.startsWith("pending:")||jt(W)},onInvite:De,onSettings:()=>P("settings"),onApprovePending:async W=>{try{return await Ke.respondToIntroduction(W,"approve"),await at(),!0}catch(le){return pe(le),!1}},onRejectPending:async W=>{try{return await Ke.respondToIntroduction(W,"reject"),await at(),!0}catch(le){return pe(le),!1}}}),t.route.name==="contact"&&q?v.jsx(az,{contact:q,messages:se,onBack:()=>{R.current=!0,fM(window.history.state)==="back"?window.history.back():(window.history.replaceState({oursMessenger:!0},"",ni(q.id)),me({type:"route",route:{name:"chats",contactCid:q.id},mobileDetailOpen:!0}),requestAnimationFrame(()=>document.querySelector("[data-contact-trigger]")?.focus({preventScroll:!0})),R.current=!1)},onRename:W=>void Ke.renameContact(q.id,W).then(at).catch(pe),onRemove:()=>{confirm(`Remove “${ur?.name??"contact"}”?`)&&Ke.removeContact(q.id).then(()=>(window.history.replaceState({oursMessenger:!0},"",ni()),me({type:"route",route:{name:"chats",contactCid:null},mobileDetailOpen:!1}),at())).catch(pe)},onOpenMessage:W=>{It({name:"chats",contactCid:q.id},ni(q.id),!0);let le=12;const ne=()=>{const Me=document.getElementById(`chat-message-${encodeURIComponent(W)}`),ke=Me?.closest(".messages");if((!Me||!ke||ke.clientHeight<=0)&&le-- >0){requestAnimationFrame(ne);return}if(!Me||!ke)return;const ce=Me.getBoundingClientRect(),Ae=ke.getBoundingClientRect(),ft=ke.scrollTop+ce.top-Ae.top-Math.max(0,(ke.clientHeight-ce.height)/2),nn=Math.max(0,Math.min(ft,ke.scrollHeight-ke.clientHeight));ke.scrollTo({top:nn,behavior:window.matchMedia("(prefers-reduced-motion: reduce)").matches?"auto":"smooth"})};requestAnimationFrame(ne)},indexOffset:or(t,q.id)?.hasMore?Math.max(1,(or(t,q.id)?.total??se.length)-se.length):0,onSendText:async(W,le)=>{const ne=await Ke.send(q.id,W,le);return await qe(q.id,!1),ne.wire_id??void 0},onSendFile:async(W,le)=>{await Ke.sendFile(q.id,new Blob([W.bytes],{type:W.mime}),W.filename,W.mime,le),await Promise.all([it(q.id),qe(q.id,!1)])}}):v.jsx(lz,{contact:q,messages:se,syncing:Z,unreadOpen:i?.contactCid===ze?i:null,hiddenEarlier:or(t,ze??"")?.hasMore?Math.max(1,(or(t,ze??"")?.total??se.length)-se.length):0,onLoadEarlier:ze&&C!==ze?()=>void Ln(ze):void 0,onBack:()=>{a.current?.abort(),l.current+=1,s(null),It({name:"chats",contactCid:null},ni(),!1)},onOpenContact:()=>{ze&&It({name:"contact",contactCid:ze},cM(ze),!0)},onDraftChange:we,onSend:async(W,le,ne)=>{if(!ze)return;const Me=ze,ke=await Ke.send(Me,W,le,ne);return me({type:"sent_message",contactCid:Me,message:{dir:"out",text:W,date:new Date().toISOString(),read:!0,wire_id:ke.wire_id??"",receipt:null,reply_to:le?{wire_id:le}:null}}),ke.wire_id?lt(Me,ce=>ce.messages.some(Ae=>Ae.wire_id===ke.wire_id),`send:${ke.wire_id}`):We().catch(pe),ke.wire_id??void 0},onSendFile:async(W,le)=>{ze&&(await Ke.sendFile(ze,new Blob([W.bytes],{type:W.mime}),W.filename,W.mime,le),await Promise.all([it(ze),qe(ze,!1)]))},onFetchFile:async W=>{await Ke.fetchFiles([W]),ze&&await it(ze)}},ze??"no-conversation")]}),v.jsxs("div",{className:"app-banners",children:[J.offline&&v.jsx("div",{className:"banner warn",role:"status","aria-live":"polite",children:"Offline — reconnecting to the network…"}),t.connection!=="live"&&v.jsx("div",{className:"banner warn",role:"status","aria-live":"polite",children:t.connection==="retrying"?"Live updates interrupted — reconnecting…":"Connecting to live updates…"}),J.updateAvailable&&v.jsxs("div",{className:"banner info",children:[v.jsx("span",{role:"status","aria-live":"polite",children:"A new version is available."}),v.jsx("span",{className:"banner-actions",children:v.jsx("button",{className:"linkbtn",onClick:()=>{J.registration&&ev(J.registration)},children:"Restart now"})})]}),v.jsx(gz,{items:A,onDismiss:ge,onOpen:W=>void jt(W)})]}),M==="invite"&&v.jsx(xz,{identity:_,invites:j,onRefresh:async()=>Y(await Ke.invites()),onCreate:async(W,le)=>(await Ke.createInvite(W,le)).blob,onAccept:async(W,le)=>{await Ke.addContact(W,le),await at()},onRevoke:async W=>{await Ke.revokeInvite(W)},onClose:()=>{P(null),at()}}),M==="settings"&&v.jsx(wz,{identity:_,push:xe,workerSupported:J.supported,busy:Q,offline:J.offline,updateAvailable:J.updateAvailable,build:U,dark:N,onToggleDark:()=>X(W=>(localStorage.setItem(Ex,W?"0":"1"),!W)),onSaveBio:async W=>{await Ke.setBio(W),await at()},onPushAction:he,onInstall:V?()=>void V.prompt().then(()=>fe(null)):void 0,onReloadUpdate:()=>{J.registration&&ev(J.registration)},onClose:()=>{D.current=null,P(null),ze&&xt(ze)}}),t.error&&v.jsxs("div",{className:"banner error",role:"alert","aria-live":"assertive",children:[t.error,v.jsx("button",{className:"linkbtn",onClick:()=>me({type:"error",message:null}),children:"dismiss"})]})]})}):v.jsx("div",{className:N?"theme-dark":"",style:{height:"100%"},children:v.jsx("div",{className:"centered-screen",children:v.jsx("p",{className:"muted",children:"Loading…"})})})}Mz();const Zk=document.getElementById("root");if(!Zk)throw new Error("missing #root");tC.createRoot(Zk).render(v.jsx(ZP,{reducedMotion:"user",children:v.jsx(jz,{})}));export{Ch as _,Id as g};
|
|
321
|
+
//# sourceMappingURL=index-cWVvKFp5.js.map
|