@ours.network/messenger-server 1.0.7 → 1.0.8
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-OT5O4T5Z.js → chunk-POBOFY4X.js} +1 -1
- package/dist/chunks/{server-O777BQPR.js → server-LQRHHD7N.js} +1 -1
- package/dist/cli.js +2 -2
- package/dist/web/assets/{abnfDiagram-N423BO3Z-BOkNfPqh.js → abnfDiagram-N423BO3Z-qMhK_Buw.js} +2 -2
- package/dist/web/assets/{abnfDiagram-N423BO3Z-BOkNfPqh.js.map → abnfDiagram-N423BO3Z-qMhK_Buw.js.map} +1 -1
- package/dist/web/assets/{arc-DWJW_5_j.js → arc-Dtb1k1Iv.js} +2 -2
- package/dist/web/assets/{arc-DWJW_5_j.js.map → arc-Dtb1k1Iv.js.map} +1 -1
- package/dist/web/assets/{architectureDiagram-T3A2C74G-BlGt_gjc.js → architectureDiagram-T3A2C74G-DZu6IItN.js} +2 -2
- package/dist/web/assets/{architectureDiagram-T3A2C74G-BlGt_gjc.js.map → architectureDiagram-T3A2C74G-DZu6IItN.js.map} +1 -1
- package/dist/web/assets/{blockDiagram-VBNYF7ZC-BaFw3f19.js → blockDiagram-VBNYF7ZC-CBino6Ns.js} +2 -2
- package/dist/web/assets/{blockDiagram-VBNYF7ZC-BaFw3f19.js.map → blockDiagram-VBNYF7ZC-CBino6Ns.js.map} +1 -1
- package/dist/web/assets/{browser-DGdhyi2S.js → browser-D0w2D7AY.js} +2 -2
- package/dist/web/assets/{browser-DGdhyi2S.js.map → browser-D0w2D7AY.js.map} +1 -1
- package/dist/web/assets/{c4Diagram-5PPSVZJV-7whJMuuH.js → c4Diagram-5PPSVZJV-DjJMio-4.js} +2 -2
- package/dist/web/assets/{c4Diagram-5PPSVZJV-7whJMuuH.js.map → c4Diagram-5PPSVZJV-DjJMio-4.js.map} +1 -1
- package/dist/web/assets/channel-542hi9fV.js +2 -0
- package/dist/web/assets/{channel-S4TikcPh.js.map → channel-542hi9fV.js.map} +1 -1
- package/dist/web/assets/{chunk-2GRJ4B5K-DvOfJlD5.js → chunk-2GRJ4B5K-scTxq8oJ.js} +2 -2
- package/dist/web/assets/{chunk-2GRJ4B5K-DvOfJlD5.js.map → chunk-2GRJ4B5K-scTxq8oJ.js.map} +1 -1
- package/dist/web/assets/{chunk-2Q5K7J3B-Dr1bUTG1.js → chunk-2Q5K7J3B-BV4pabc5.js} +2 -2
- package/dist/web/assets/{chunk-2Q5K7J3B-Dr1bUTG1.js.map → chunk-2Q5K7J3B-BV4pabc5.js.map} +1 -1
- package/dist/web/assets/{chunk-5RXB4S5H-Bn4UBcQm.js → chunk-5RXB4S5H-BoiDeGif.js} +2 -2
- package/dist/web/assets/{chunk-5RXB4S5H-Bn4UBcQm.js.map → chunk-5RXB4S5H-BoiDeGif.js.map} +1 -1
- package/dist/web/assets/{chunk-5VM5RSS4-PVXgYunx.js → chunk-5VM5RSS4-Bhg1wR-d.js} +2 -2
- package/dist/web/assets/{chunk-5VM5RSS4-PVXgYunx.js.map → chunk-5VM5RSS4-Bhg1wR-d.js.map} +1 -1
- package/dist/web/assets/{chunk-6Q2QTUOP-BsVFmayU.js → chunk-6Q2QTUOP-BNrwIbbS.js} +2 -2
- package/dist/web/assets/{chunk-6Q2QTUOP-BsVFmayU.js.map → chunk-6Q2QTUOP-BNrwIbbS.js.map} +1 -1
- package/dist/web/assets/{chunk-GF5L2VYU-C8YoDtfY.js → chunk-GF5L2VYU-B4Zw0ux3.js} +2 -2
- package/dist/web/assets/{chunk-GF5L2VYU-C8YoDtfY.js.map → chunk-GF5L2VYU-B4Zw0ux3.js.map} +1 -1
- package/dist/web/assets/{chunk-JWPE2WC7-CFEqJZwb.js → chunk-JWPE2WC7-Cjth4POb.js} +2 -2
- package/dist/web/assets/{chunk-JWPE2WC7-CFEqJZwb.js.map → chunk-JWPE2WC7-Cjth4POb.js.map} +1 -1
- package/dist/web/assets/{chunk-KBJHAD2P-DNWp0SmN.js → chunk-KBJHAD2P-C0aFsbnL.js} +2 -2
- package/dist/web/assets/{chunk-KBJHAD2P-DNWp0SmN.js.map → chunk-KBJHAD2P-C0aFsbnL.js.map} +1 -1
- package/dist/web/assets/{chunk-RYQCIY6F-DXiksuP3.js → chunk-RYQCIY6F-DAqntJ8V.js} +2 -2
- package/dist/web/assets/{chunk-RYQCIY6F-DXiksuP3.js.map → chunk-RYQCIY6F-DAqntJ8V.js.map} +1 -1
- package/dist/web/assets/{chunk-XXDRQBXY-DARsEql9.js → chunk-XXDRQBXY-CzlQafLF.js} +2 -2
- package/dist/web/assets/{chunk-XXDRQBXY-DARsEql9.js.map → chunk-XXDRQBXY-CzlQafLF.js.map} +1 -1
- package/dist/web/assets/classDiagram-JCYQIIEL-B6vLdCfe.js +2 -0
- package/dist/web/assets/{classDiagram-JCYQIIEL-BI1nT_Qn.js.map → classDiagram-JCYQIIEL-B6vLdCfe.js.map} +1 -1
- package/dist/web/assets/classDiagram-v2-OCEON4UE-B6vLdCfe.js +2 -0
- package/dist/web/assets/{classDiagram-v2-OCEON4UE-BI1nT_Qn.js.map → classDiagram-v2-OCEON4UE-B6vLdCfe.js.map} +1 -1
- package/dist/web/assets/{cose-bilkent-JH36ORCC-CbY_Emxl.js → cose-bilkent-JH36ORCC-soI0Ahkc.js} +2 -2
- package/dist/web/assets/{cose-bilkent-JH36ORCC-CbY_Emxl.js.map → cose-bilkent-JH36ORCC-soI0Ahkc.js.map} +1 -1
- package/dist/web/assets/{cynefin-VYW2F7L2-U3ekT2gx.js → cynefin-VYW2F7L2-Bdxx-X7n.js} +2 -2
- package/dist/web/assets/{cynefin-VYW2F7L2-U3ekT2gx.js.map → cynefin-VYW2F7L2-Bdxx-X7n.js.map} +1 -1
- package/dist/web/assets/{cynefinDiagram-MW4NZA55-SBZsW88o.js → cynefinDiagram-MW4NZA55-Duckm3xZ.js} +2 -2
- package/dist/web/assets/{cynefinDiagram-MW4NZA55-SBZsW88o.js.map → cynefinDiagram-MW4NZA55-Duckm3xZ.js.map} +1 -1
- package/dist/web/assets/{dagre-VZM6K2ZE-BdBBBFDX.js → dagre-VZM6K2ZE-vmzgH2hI.js} +2 -2
- package/dist/web/assets/{dagre-VZM6K2ZE-BdBBBFDX.js.map → dagre-VZM6K2ZE-vmzgH2hI.js.map} +1 -1
- package/dist/web/assets/{diagram-7IWD3JNH-CNMma2cs.js → diagram-7IWD3JNH-CXsBpnT8.js} +2 -2
- package/dist/web/assets/{diagram-7IWD3JNH-CNMma2cs.js.map → diagram-7IWD3JNH-CXsBpnT8.js.map} +1 -1
- package/dist/web/assets/{diagram-B4RE2ZJO-CHBsZThC.js → diagram-B4RE2ZJO-KAY3p5ot.js} +2 -2
- package/dist/web/assets/{diagram-B4RE2ZJO-CHBsZThC.js.map → diagram-B4RE2ZJO-KAY3p5ot.js.map} +1 -1
- package/dist/web/assets/{diagram-LBJQPF4R-Cf2amKeh.js → diagram-LBJQPF4R-D7zGkdCs.js} +2 -2
- package/dist/web/assets/{diagram-LBJQPF4R-Cf2amKeh.js.map → diagram-LBJQPF4R-D7zGkdCs.js.map} +1 -1
- package/dist/web/assets/{diagram-Q27KOJAE-qeQk6AE3.js → diagram-Q27KOJAE-DJZKSnNq.js} +2 -2
- package/dist/web/assets/{diagram-Q27KOJAE-qeQk6AE3.js.map → diagram-Q27KOJAE-DJZKSnNq.js.map} +1 -1
- package/dist/web/assets/{diagram-UB23O5K3-BHQxwwpr.js → diagram-UB23O5K3-C_B3tyKN.js} +2 -2
- package/dist/web/assets/{diagram-UB23O5K3-BHQxwwpr.js.map → diagram-UB23O5K3-C_B3tyKN.js.map} +1 -1
- package/dist/web/assets/{ebnfDiagram-BXEA7PRR-CLUmbihv.js → ebnfDiagram-BXEA7PRR-fgAVP0wM.js} +2 -2
- package/dist/web/assets/{ebnfDiagram-BXEA7PRR-CLUmbihv.js.map → ebnfDiagram-BXEA7PRR-fgAVP0wM.js.map} +1 -1
- package/dist/web/assets/{erDiagram-JOGREHBK-CIcc_L4O.js → erDiagram-JOGREHBK-BM6un2KG.js} +2 -2
- package/dist/web/assets/{erDiagram-JOGREHBK-CIcc_L4O.js.map → erDiagram-JOGREHBK-BM6un2KG.js.map} +1 -1
- package/dist/web/assets/{flowDiagram-UKHOOZJN-Dm515w9v.js → flowDiagram-UKHOOZJN-C0pSZAyE.js} +2 -2
- package/dist/web/assets/{flowDiagram-UKHOOZJN-Dm515w9v.js.map → flowDiagram-UKHOOZJN-C0pSZAyE.js.map} +1 -1
- package/dist/web/assets/{ganttDiagram-PKOTCBZU-D9exeNt2.js → ganttDiagram-PKOTCBZU-DIvGDL0M.js} +2 -2
- package/dist/web/assets/{ganttDiagram-PKOTCBZU-D9exeNt2.js.map → ganttDiagram-PKOTCBZU-DIvGDL0M.js.map} +1 -1
- package/dist/web/assets/{gitGraphDiagram-DS77QQ5N-ByHEcpv2.js → gitGraphDiagram-DS77QQ5N-B6X-r_29.js} +2 -2
- package/dist/web/assets/{gitGraphDiagram-DS77QQ5N-ByHEcpv2.js.map → gitGraphDiagram-DS77QQ5N-B6X-r_29.js.map} +1 -1
- package/dist/web/assets/{index-B0fkLcr3.css → index-C_i-8uiO.css} +1 -1
- package/dist/web/assets/{index-BtlMz_WJ.js → index-GLm6dAFY.js} +3 -3
- package/dist/web/assets/index-GLm6dAFY.js.map +1 -0
- package/dist/web/assets/{infoDiagram-6WML65LV-03SKV0cB.js → infoDiagram-6WML65LV-eR4Lixdc.js} +2 -2
- package/dist/web/assets/{infoDiagram-6WML65LV-03SKV0cB.js.map → infoDiagram-6WML65LV-eR4Lixdc.js.map} +1 -1
- package/dist/web/assets/{ishikawaDiagram-WSZJBQD7-DaYDUXEK.js → ishikawaDiagram-WSZJBQD7-CequJl9g.js} +2 -2
- package/dist/web/assets/{ishikawaDiagram-WSZJBQD7-DaYDUXEK.js.map → ishikawaDiagram-WSZJBQD7-CequJl9g.js.map} +1 -1
- package/dist/web/assets/{journeyDiagram-NVQOT4AX-DYfA1FN_.js → journeyDiagram-NVQOT4AX-BzLOGca5.js} +2 -2
- package/dist/web/assets/{journeyDiagram-NVQOT4AX-DYfA1FN_.js.map → journeyDiagram-NVQOT4AX-BzLOGca5.js.map} +1 -1
- package/dist/web/assets/{jsQR-BmxRSd9_.js → jsQR-DKYZJtWP.js} +2 -2
- package/dist/web/assets/{jsQR-BmxRSd9_.js.map → jsQR-DKYZJtWP.js.map} +1 -1
- package/dist/web/assets/{kanban-definition-27J2QSJJ-Cyzatq31.js → kanban-definition-27J2QSJJ-Jr3TEVPz.js} +2 -2
- package/dist/web/assets/{kanban-definition-27J2QSJJ-Cyzatq31.js.map → kanban-definition-27J2QSJJ-Jr3TEVPz.js.map} +1 -1
- package/dist/web/assets/{linear-DfAWJY7i.js → linear-Cnh_iIPp.js} +2 -2
- package/dist/web/assets/{linear-DfAWJY7i.js.map → linear-Cnh_iIPp.js.map} +1 -1
- package/dist/web/assets/{mermaid.core-DRwRVnqY.js → mermaid.core-BIVhb0_T.js} +5 -5
- package/dist/web/assets/{mermaid.core-DRwRVnqY.js.map → mermaid.core-BIVhb0_T.js.map} +1 -1
- package/dist/web/assets/{mindmap-definition-FAOFIHXS-Crjz0ueM.js → mindmap-definition-FAOFIHXS-DIfaNyyT.js} +2 -2
- package/dist/web/assets/{mindmap-definition-FAOFIHXS-Crjz0ueM.js.map → mindmap-definition-FAOFIHXS-DIfaNyyT.js.map} +1 -1
- package/dist/web/assets/{pegDiagram-VL7TDLO6-BqlgNkIE.js → pegDiagram-VL7TDLO6-DwrFn3Vz.js} +2 -2
- package/dist/web/assets/{pegDiagram-VL7TDLO6-BqlgNkIE.js.map → pegDiagram-VL7TDLO6-DwrFn3Vz.js.map} +1 -1
- package/dist/web/assets/{pieDiagram-7S7Q4E2Y-DVRVBBQ-.js → pieDiagram-7S7Q4E2Y-BwFw_s72.js} +2 -2
- package/dist/web/assets/{pieDiagram-7S7Q4E2Y-DVRVBBQ-.js.map → pieDiagram-7S7Q4E2Y-BwFw_s72.js.map} +1 -1
- package/dist/web/assets/{quadrantDiagram-CIZ2JOQS-B2AVI8tL.js → quadrantDiagram-CIZ2JOQS-DEd2HsZg.js} +2 -2
- package/dist/web/assets/{quadrantDiagram-CIZ2JOQS-B2AVI8tL.js.map → quadrantDiagram-CIZ2JOQS-DEd2HsZg.js.map} +1 -1
- package/dist/web/assets/{railroadDiagram-AXF67PYL-d0fiWzFm.js → railroadDiagram-AXF67PYL-wP5aSiB2.js} +2 -2
- package/dist/web/assets/{railroadDiagram-AXF67PYL-d0fiWzFm.js.map → railroadDiagram-AXF67PYL-wP5aSiB2.js.map} +1 -1
- package/dist/web/assets/{requirementDiagram-LRYGKXZP-3Oshgo7v.js → requirementDiagram-LRYGKXZP-zecuIYog.js} +2 -2
- package/dist/web/assets/{requirementDiagram-LRYGKXZP-3Oshgo7v.js.map → requirementDiagram-LRYGKXZP-zecuIYog.js.map} +1 -1
- package/dist/web/assets/{sankeyDiagram-W5VNT64P-CKaFZz1o.js → sankeyDiagram-W5VNT64P-C5XPDU_o.js} +2 -2
- package/dist/web/assets/{sankeyDiagram-W5VNT64P-CKaFZz1o.js.map → sankeyDiagram-W5VNT64P-C5XPDU_o.js.map} +1 -1
- package/dist/web/assets/{sequenceDiagram-SI44F4Z6-Blfb_SVL.js → sequenceDiagram-SI44F4Z6-DpGDLSf8.js} +2 -2
- package/dist/web/assets/{sequenceDiagram-SI44F4Z6-Blfb_SVL.js.map → sequenceDiagram-SI44F4Z6-DpGDLSf8.js.map} +1 -1
- package/dist/web/assets/{sizeCapture-X5ZJPWSS-DE_gsDrn.js → sizeCapture-X5ZJPWSS-ChGjGVmk.js} +2 -2
- package/dist/web/assets/{sizeCapture-X5ZJPWSS-DE_gsDrn.js.map → sizeCapture-X5ZJPWSS-ChGjGVmk.js.map} +1 -1
- package/dist/web/assets/{stateDiagram-OKZ733FA-CMpJH5dn.js → stateDiagram-OKZ733FA-BJqVhlh4.js} +2 -2
- package/dist/web/assets/{stateDiagram-OKZ733FA-CMpJH5dn.js.map → stateDiagram-OKZ733FA-BJqVhlh4.js.map} +1 -1
- package/dist/web/assets/stateDiagram-v2-UEYNNEHI-DEycCHlR.js +2 -0
- package/dist/web/assets/{stateDiagram-v2-UEYNNEHI-Dt-50l8x.js.map → stateDiagram-v2-UEYNNEHI-DEycCHlR.js.map} +1 -1
- package/dist/web/assets/{swimlanes-SLNWSIFB-DOBYNUPr.js → swimlanes-SLNWSIFB-BXgUB7W2.js} +3 -3
- package/dist/web/assets/{swimlanes-SLNWSIFB-DOBYNUPr.js.map → swimlanes-SLNWSIFB-BXgUB7W2.js.map} +1 -1
- package/dist/web/assets/swimlanesDiagram-ULZ7WXOC-BxkZkkBd.js +9 -0
- package/dist/web/assets/{swimlanesDiagram-ULZ7WXOC-aV_Cee-1.js.map → swimlanesDiagram-ULZ7WXOC-BxkZkkBd.js.map} +1 -1
- package/dist/web/assets/{timeline-definition-Z64GVDOM-Cc709uLM.js → timeline-definition-Z64GVDOM-RBVjnAzV.js} +2 -2
- package/dist/web/assets/{timeline-definition-Z64GVDOM-Cc709uLM.js.map → timeline-definition-Z64GVDOM-RBVjnAzV.js.map} +1 -1
- package/dist/web/assets/{vennDiagram-T6HMQDX7-CkXpoMia.js → vennDiagram-T6HMQDX7-yO7SV1ID.js} +2 -2
- package/dist/web/assets/{vennDiagram-T6HMQDX7-CkXpoMia.js.map → vennDiagram-T6HMQDX7-yO7SV1ID.js.map} +1 -1
- package/dist/web/assets/{wardleyDiagram-T6FBY63Y-BInkDQt9.js → wardleyDiagram-T6FBY63Y-DT5PBJ5G.js} +2 -2
- package/dist/web/assets/{wardleyDiagram-T6FBY63Y-BInkDQt9.js.map → wardleyDiagram-T6FBY63Y-DT5PBJ5G.js.map} +1 -1
- package/dist/web/assets/{xychartDiagram-ELKLHX3M-BvbWSLAa.js → xychartDiagram-ELKLHX3M-BRcOS6Cq.js} +2 -2
- package/dist/web/assets/{xychartDiagram-ELKLHX3M-BvbWSLAa.js.map → xychartDiagram-ELKLHX3M-BRcOS6Cq.js.map} +1 -1
- package/dist/web/index.html +2 -2
- package/dist/web/sw.js +1 -1
- package/dist/web/version.json +1 -1
- package/package.json +1 -1
- package/dist/web/assets/channel-S4TikcPh.js +0 -2
- package/dist/web/assets/classDiagram-JCYQIIEL-BI1nT_Qn.js +0 -2
- package/dist/web/assets/classDiagram-v2-OCEON4UE-BI1nT_Qn.js +0 -2
- package/dist/web/assets/index-BtlMz_WJ.js.map +0 -1
- package/dist/web/assets/stateDiagram-v2-UEYNNEHI-Dt-50l8x.js +0 -2
- package/dist/web/assets/swimlanesDiagram-ULZ7WXOC-aV_Cee-1.js +0 -9
|
@@ -316,7 +316,7 @@ ${l.join(`
|
|
|
316
316
|
`});++i<e.length;)i&&n.push({type:"text",value:`
|
|
317
317
|
`}),n.push(e[i]);return t&&e.length>0&&n.push({type:"text",value:`
|
|
318
318
|
`}),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=WO(e,t),i=n.one(e,void 0),s=$O(n),l=Array.isArray(i)?{type:"root",children:i}:i||{type:"root",children:[]};return s&&l.children.push({type:"text",value:`
|
|
319
|
-
`},s),l}function YO(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 GO(){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,E=arguments[0],T=1,C=arguments.length,R=!1;for(typeof E=="boolean"&&(R=E,E=arguments[1]||{},T=2),(E==null||typeof E!="object"&&typeof E!="function")&&(E={});T<C;++T)if(h=arguments[T],h!=null)for(m in h)p=c(E,m),y=c(h,m),E!==y&&(R&&y&&(l(y)||(w=s(y)))?(w?(w=!1,S=p&&s(p)?p:[]):S=p&&l(p)?p:{},a(E,{name:m,newValue:d(R,S,y)})):typeof y<"u"&&a(E,{name:m,newValue:y}));return E},yf}var QO=GO();const vf=jd(QO);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 ZO(){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?JO(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 JO(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 Wn={basename:eF,dirname:tF,extname:nF,join:rF,sep:"/"};function eF(e,t){if(t!==void 0&&typeof t!="string")throw new TypeError('"ext" argument must be a string');Is(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 tF(e){if(Is(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 nF(e){Is(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 rF(...e){let t=-1,n;for(;++t<e.length;)Is(e[t]),e[t]&&(n=n===void 0?e[t]:n+"/"+e[t]);return n===void 0?".":iF(n)}function iF(e){Is(e);const t=e.codePointAt(0)===47;let n=oF(e,!t);return n.length===0&&!t&&(n="."),n.length>0&&e.codePointAt(e.length-1)===47&&(n+="/"),t?"/"+n:n}function oF(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 Is(e){if(typeof e!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(e))}const sF={cwd:aF};function aF(){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 lF(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 uF(e)}function uF(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"||cF(t)?n={value:t}:n=t:n={},this.cwd="cwd"in n?"":sF.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"?Wn.basename(this.path):void 0}set basename(t){kf(t,"basename"),wf(t,"basename"),this.path=Wn.join(this.dirname||"",t)}get dirname(){return typeof this.path=="string"?Wn.dirname(this.path):void 0}set dirname(t){cx(this.basename,"dirname"),this.path=Wn.join(t||"",this.basename)}get extname(){return typeof this.path=="string"?Wn.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=Wn.join(this.dirname,this.stem+(t||""))}get path(){return this.history[this.history.length-1]}set path(t){Rd(t)&&(t=lF(t)),kf(t,"path"),this.path!==t&&this.history.push(t)}get stem(){return typeof this.path=="string"?Wn.basename(this.path,this.extname):void 0}set stem(t){kf(t,"stem"),wf(t,"stem"),this.path=Wn.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 Vt(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(Wn.sep))throw new Error("`"+t+"` cannot be a path: did not expect `"+Wn.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 cF(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const fF=function(e){const i=this.constructor.prototype,s=i[e],l=function(){return s.apply(l,arguments)};return Object.setPrototypeOf(l,i),l},dF={}.hasOwnProperty;class Wh extends fF{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=ZO()}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):dF.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);mF(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 E=i[y][1];Pd(E)&&Pd(w)&&(w=vf(!0,E,w)),i[y]=[h,w,...S]}}}}const hF=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 pF(e)?e:new Fk(e)}function pF(e){return!!(e&&typeof e=="object"&&"message"in e&&"messages"in e)}function mF(e){return typeof e=="string"||gF(e)}function gF(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const yF="https://github.com/remarkjs/react-markdown/blob/main/changelog.md",hx=[],px={allowDangerousHtml:!0},vF=/^(https?|ircs?|mailto|xmpp)$/i,xF=[{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=wF(e),n=kF(e);return SF(t.runSync(t.parse(n),n),e)}function wF(e){const t=e.rehypePlugins||hx,n=e.remarkPlugins||hx,i=e.remarkRehypeOptions?{...e.remarkRehypeOptions,...px}:px;return hF().use(uO).use(n).use(YO,i).use(t)}function kF(e){const t=e.children||"",n=new Fk;return typeof t=="string"&&(n.value=t),n}function SF(e,t){const n=t.allowedElements,i=t.allowElement,s=t.components,l=t.disallowedElements,a=t.skipHtml,c=t.unwrapDisallowed,d=t.urlTransform||bF;for(const m of xF)Object.hasOwn(t,m.from)&&(""+m.from+(m.to?"use `"+m.to+"` instead":"remove it")+yF+m.id,void 0);return ph(e,h),qL(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],E=gf[w];(E===null||E.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 bF(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||vF.test(e.slice(0,t))?e:""}const CF={};function Vk(e){const t=this,n=e||CF,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(be,{name:"close"})})})]}),e.tabs,v.jsx("div",{className:"modal-body",children:e.children})]})]})})}const EF=.25,TF=8;let mx=Promise.resolve();function gx(){return document.documentElement.classList.contains("theme-dark")?"dark":"default"}function PF(){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 RF(e,t,n){const i=mx.then(async()=>{const{default:s}=await Ch(async()=>{const{default:l}=await import("./mermaid.core-DRwRVnqY.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 AF(e){return Math.min(TF,Math.max(EF,e))}function MF(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=AF(p);if(S===i)return;const E=t.current?.getBoundingClientRect();if(E){const T=(y??E.left+E.width/2)-E.left-E.width/2,C=(w??E.top+E.height/2)-E.top-E.height/2,R=S/i;a(A=>({x:T-R*(T-A.x),y:C-R*(C-A.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(be,{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(be,{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(be,{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 NF({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=PF();return k.useEffect(()=>{let p=!0;const y=`mermaid-${t.replace(/[^a-zA-Z0-9_-]/g,"")}`;return i(""),l(""),RF(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(be,{name:"maximize"})}),v.jsx("div",{className:"markdown-mermaid-diagram",dangerouslySetInnerHTML:{__html:n}})]}),d&&v.jsx(MF,{svg:n,theme:a,onClose:()=>h(!1)})]}):v.jsx("div",{className:"markdown-mermaid-loading",children:"Rendering diagram…"})}const jF=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(NF,{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(""),[E,T]=k.useState(0),[C,R]=k.useState(!1),[A,_]=k.useState(""),[B,I]=k.useState(!1),[X,$]=k.useState(!1),[G,j]=k.useState([]),[Q,U]=k.useState(!1),[fe,J]=k.useState(null),[te,ge]=k.useState(!1),[Ce,Y]=k.useState("");k.useEffect(()=>{let M=!0,ee=null;return d("loading"),Ul(t.id).then(ce=>{if(M){if(!ce){d("missing");return}s(new TextDecoder("utf-8").decode(ce)),ee=URL.createObjectURL(new Blob([ce],{type:"text/markdown;charset=utf-8"})),a(ee),d("ready")}}).catch(()=>{M&&d("error")}),()=>{M=!1,ee&&URL.revokeObjectURL(ee)}},[t.id]),k.useEffect(()=>{const M=()=>{const ee=window.getSelection(),ce=n.current;if(!ee||ee.isCollapsed||!ce){m(""),y(0);return}if(!ce.contains(ee.anchorNode)||!ce.contains(ee.focusNode)){m(""),y(0);return}const de=ee.getRangeAt(0),pe=ee.toString(),Pe=pe.length-pe.trimStart().length,ye=pe.trim().slice(0,4e3),De=document.createRange();De.selectNodeContents(ce),De.setEnd(de.startContainer,de.startOffset);const Ke=De.toString().length+Pe;m(ye),y(eD(ce.textContent,ye,Ke))};return document.addEventListener("selectionchange",M),()=>document.removeEventListener("selectionchange",M)},[]);const ae=()=>{h&&(S(h),T(p),R(!0),Y(""))},P=async()=>{if(X){if(!w||!A.trim())return;j(ee=>[...ee,{selection:w,comment:A.trim(),occurrence:E}]),_(""),R(!1),Y("Comment added to review");return}const M=ZI(w,A);if(!(!M||!A.trim()||B)){I(!0),Y("");try{await e.onSendText(M,t.id||void 0),_(""),R(!1),Y("Feedback sent")}catch(ee){Y(`Send failed: ${String(ee)}`)}finally{I(!1)}}},O=async()=>{if(G.length===0||Q)return;const M=sD(i,G);U(!0),Y("");try{e.onSendFile?await e.onSendFile({filename:JI(t.filename),mime:"text/markdown",bytes:new TextEncoder().encode(M)},t.id||void 0):await e.onSendText(M,t.id||void 0),j([]),$(!1),Y("Review submitted")}catch(ee){Y(`Review send failed: ${String(ee)}`)}finally{U(!1)}},Z=async()=>{if(!(!fe||!e.onSendFile||te)){ge(!0),Y("");try{await e.onSendFile(fe,t.id||void 0),J(null),Y("Voice feedback sent")}catch(M){Y(`Voice send failed: ${String(M)}`)}finally{ge(!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:M=>M.preventDefault(),onClick:ae,children:[v.jsx(be,{name:"reply",size:14}),X?"Add review comment":"Quick message",h?` (${h.length})`:""]}),X?v.jsx("button",{className:"btn sm",onClick:()=>{$(!1),j([]),R(!1),Y("Review discarded")},children:"Cancel review"}):v.jsxs("button",{className:"btn sm",onClick:()=>{$(!0),j([]),Y("Review started — select passages to add comments")},children:[v.jsx(be,{name:"edit",size:14}),"Start review"]}),l&&v.jsxs("a",{className:"btn sm",href:l,download:t.filename,children:[v.jsx(be,{name:"download",size:14}),"Download"]}),e.onSendFile&&v.jsx(k1,{disabled:!!fe||te,onReady:J,onError:Y}),v.jsx("span",{className:"markdown-review-hint",children:h?"Selection ready for feedback":"Highlight any passage to comment on it"})]}),C&&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:A,onChange:M=>_(M.target.value)}),v.jsxs("div",{className:"markdown-feedback-actions",children:[v.jsx("button",{className:"btn sm",onClick:()=>R(!1),children:"Cancel"}),v.jsxs("button",{className:"btn sm primary",disabled:!A.trim()||B,onClick:()=>void P(),children:[v.jsx(be,{name:"send",size:14}),X?"Add to review":B?"Sending…":"Send feedback"]})]})]}),X&&v.jsxs("div",{className:"markdown-review-draft",children:[v.jsxs("div",{className:"markdown-review-draft-head",children:[v.jsxs("strong",{children:["Review · ",G.length," comment",G.length===1?"":"s"]}),v.jsxs("button",{className:"btn sm primary",disabled:G.length===0||Q,onClick:()=>void O(),children:[v.jsx(be,{name:"send",size:14}),Q?"Submitting…":"Submit review"]})]}),G.map((M,ee)=>v.jsxs("div",{className:"markdown-review-comment",children:[v.jsx("span",{children:ee+1}),v.jsxs("div",{children:[v.jsx("blockquote",{children:M.selection}),v.jsx("p",{children:M.comment})]}),v.jsx("button",{className:"icon-btn",title:"Remove comment",onClick:()=>j(ce=>ce.filter((de,pe)=>pe!==ee)),children:v.jsx(be,{name:"close",size:14})})]},`${ee}-${M.selection.slice(0,24)}`))]}),fe&&v.jsx(w1,{att:fe,sending:te,onSend:()=>void Z(),onDiscard:()=>J(null)}),Ce&&v.jsx("div",{className:"markdown-review-status",role:"status",children:Ce}),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(jF,{markdown:i,contentRef:n})]})]})})}function $k(e){const{rec:t}=e,[n,i]=k.useState(""),[s,l]=k.useState(null),[a,c]=k.useState(0),[d,h]=k.useState("loading");return k.useEffect(()=>{let m=!0,p=null;return h("loading"),Ul(t.id).then(y=>{if(m){if(!y){h("missing");return}i(hD(new TextDecoder("utf-8").decode(y))),c(y.byteLength),p=URL.createObjectURL(new Blob([y],{type:wh(t.mime,t.filename)})),l(p),h("ready")}}).catch(()=>{m&&h("error")}),()=>{m=!1,p&&URL.revokeObjectURL(p)}},[t.id,t.mime,t.filename]),v.jsx(Ds,{title:t.filename,description:"HTML preview · sandboxed, static rendering only",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(be,{name:"shield",size:14}),"Scripts, forms and network requests are blocked"]}),s&&v.jsxs("a",{className:"btn sm",href:s,download:t.filename,children:[v.jsx(be,{name:"download",size:14}),"Download original",a?` · ${Fr(a)}`:""]})]}),v.jsxs("div",{className:"html-preview-frame",children:[d==="loading"&&v.jsx("div",{className:"markdown-empty",children:"Loading preview…"}),d==="missing"&&v.jsx("div",{className:"markdown-empty",children:"This file is available on the original device only."}),d==="error"&&v.jsx("div",{className:"markdown-empty",children:"The file could not be opened."}),d==="ready"&&v.jsx("iframe",{className:"html-preview-iframe",title:`Sandboxed preview of ${t.filename}`,sandbox:lD,referrerPolicy:"no-referrer",srcDoc:n})]})]})})}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 Ad(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(be,{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(be,{name:"monitor",size:16})}),Ms(a.filename,a.mime)&&n&&v.jsx("button",{className:"icon-btn",title:"Preview HTML",onClick:()=>e.onPreview(a),children:v.jsx(be,{name:"monitor",size:16})}),v.jsx("a",{className:"icon-btn"+(n?"":" disabled"),href:n??void 0,download:a.filename,title:"Download",children:v.jsx(be,{name:"download",size:16})})]})]})}function IF(e){const[t,n]=k.useState(!1);if(e.versions.length===1){const i=e.versions[0];return v.jsx(Ad,{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(be,{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(be,{name:t?"chevronDown":"chevron",size:16})]}),t&&v.jsx("div",{className:"file-version-stack-list",children:e.versions.map((i,s)=>v.jsx(Ad,{message:i.message,messageKey:i.key,versionLabel:`Version ${e.versions.length-s}`,onJump:e.onJump,onPreview:e.onPreview},i.key))})]})}function DF(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(Ad,{message:h.message,messageKey:h.key,onJump:e.onJump,onPreview:e.onPreview},h.key)),t==="file"&&a.map(h=>v.jsx(IF,{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(be,{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(be,{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 _F=Object.freeze(["image/avif","image/bmp","image/heic","image/heif","image/jpeg","image/jpg","image/png","image/webp"]),LF=/\.(avif|bmp|heic|heif|jpe?g|png|webp)$/i;function Wk(e,t=""){return _F.includes(String(e??"").toLowerCase())||LF.test(String(t??""))}function OF(e){return`${(String(e||"photo").trim()||"photo").replace(/\.[^./\\]+$/,"")||"photo"}.jpg`}function FF(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 zF=2048,VF=640,BF=.82,$F=[.84,.7,.56,.44],UF=.94;function WF(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 HF(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 KF(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*UF)),{image:i,release:s}=await WF(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(zF,Math.max(i.naturalWidth,i.naturalHeight));for(;c>=VF;){const d=FF(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 $F){const m=await HF(l,h);if(m.size<=n)return{filename:OF(e.name),mime:"image/jpeg",bytes:new Uint8Array(await m.arrayBuffer()),width:l.width,height:l.height,originalSize:e.size}}c=Math.floor(c*BF)}}finally{s(),l.width=1,l.height=1}throw new Error("The photo is still too large after optimization.")}const qF=5e4,XF=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 XF.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 YF(e){return e.split(/(\n[ \t]*\n)/).map(t=>{if(/^\n[ \t]*\n$/.test(t))return t;const n=t.split(`
|
|
319
|
+
`},s),l}function YO(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 GO(){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,E=arguments[0],T=1,C=arguments.length,R=!1;for(typeof E=="boolean"&&(R=E,E=arguments[1]||{},T=2),(E==null||typeof E!="object"&&typeof E!="function")&&(E={});T<C;++T)if(h=arguments[T],h!=null)for(m in h)p=c(E,m),y=c(h,m),E!==y&&(R&&y&&(l(y)||(w=s(y)))?(w?(w=!1,S=p&&s(p)?p:[]):S=p&&l(p)?p:{},a(E,{name:m,newValue:d(R,S,y)})):typeof y<"u"&&a(E,{name:m,newValue:y}));return E},yf}var QO=GO();const vf=jd(QO);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 ZO(){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?JO(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 JO(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 Wn={basename:eF,dirname:tF,extname:nF,join:rF,sep:"/"};function eF(e,t){if(t!==void 0&&typeof t!="string")throw new TypeError('"ext" argument must be a string');Is(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 tF(e){if(Is(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 nF(e){Is(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 rF(...e){let t=-1,n;for(;++t<e.length;)Is(e[t]),e[t]&&(n=n===void 0?e[t]:n+"/"+e[t]);return n===void 0?".":iF(n)}function iF(e){Is(e);const t=e.codePointAt(0)===47;let n=oF(e,!t);return n.length===0&&!t&&(n="."),n.length>0&&e.codePointAt(e.length-1)===47&&(n+="/"),t?"/"+n:n}function oF(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 Is(e){if(typeof e!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(e))}const sF={cwd:aF};function aF(){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 lF(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 uF(e)}function uF(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"||cF(t)?n={value:t}:n=t:n={},this.cwd="cwd"in n?"":sF.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"?Wn.basename(this.path):void 0}set basename(t){kf(t,"basename"),wf(t,"basename"),this.path=Wn.join(this.dirname||"",t)}get dirname(){return typeof this.path=="string"?Wn.dirname(this.path):void 0}set dirname(t){cx(this.basename,"dirname"),this.path=Wn.join(t||"",this.basename)}get extname(){return typeof this.path=="string"?Wn.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=Wn.join(this.dirname,this.stem+(t||""))}get path(){return this.history[this.history.length-1]}set path(t){Rd(t)&&(t=lF(t)),kf(t,"path"),this.path!==t&&this.history.push(t)}get stem(){return typeof this.path=="string"?Wn.basename(this.path,this.extname):void 0}set stem(t){kf(t,"stem"),wf(t,"stem"),this.path=Wn.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 Vt(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(Wn.sep))throw new Error("`"+t+"` cannot be a path: did not expect `"+Wn.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 cF(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const fF=function(e){const i=this.constructor.prototype,s=i[e],l=function(){return s.apply(l,arguments)};return Object.setPrototypeOf(l,i),l},dF={}.hasOwnProperty;class Wh extends fF{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=ZO()}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):dF.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);mF(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 E=i[y][1];Pd(E)&&Pd(w)&&(w=vf(!0,E,w)),i[y]=[h,w,...S]}}}}const hF=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 pF(e)?e:new Fk(e)}function pF(e){return!!(e&&typeof e=="object"&&"message"in e&&"messages"in e)}function mF(e){return typeof e=="string"||gF(e)}function gF(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const yF="https://github.com/remarkjs/react-markdown/blob/main/changelog.md",hx=[],px={allowDangerousHtml:!0},vF=/^(https?|ircs?|mailto|xmpp)$/i,xF=[{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=wF(e),n=kF(e);return SF(t.runSync(t.parse(n),n),e)}function wF(e){const t=e.rehypePlugins||hx,n=e.remarkPlugins||hx,i=e.remarkRehypeOptions?{...e.remarkRehypeOptions,...px}:px;return hF().use(uO).use(n).use(YO,i).use(t)}function kF(e){const t=e.children||"",n=new Fk;return typeof t=="string"&&(n.value=t),n}function SF(e,t){const n=t.allowedElements,i=t.allowElement,s=t.components,l=t.disallowedElements,a=t.skipHtml,c=t.unwrapDisallowed,d=t.urlTransform||bF;for(const m of xF)Object.hasOwn(t,m.from)&&(""+m.from+(m.to?"use `"+m.to+"` instead":"remove it")+yF+m.id,void 0);return ph(e,h),qL(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],E=gf[w];(E===null||E.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 bF(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||vF.test(e.slice(0,t))?e:""}const CF={};function Vk(e){const t=this,n=e||CF,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(be,{name:"close"})})})]}),e.tabs,v.jsx("div",{className:"modal-body",children:e.children})]})]})})}const EF=.25,TF=8;let mx=Promise.resolve();function gx(){return document.documentElement.classList.contains("theme-dark")?"dark":"default"}function PF(){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 RF(e,t,n){const i=mx.then(async()=>{const{default:s}=await Ch(async()=>{const{default:l}=await import("./mermaid.core-BIVhb0_T.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 AF(e){return Math.min(TF,Math.max(EF,e))}function MF(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=AF(p);if(S===i)return;const E=t.current?.getBoundingClientRect();if(E){const T=(y??E.left+E.width/2)-E.left-E.width/2,C=(w??E.top+E.height/2)-E.top-E.height/2,R=S/i;a(A=>({x:T-R*(T-A.x),y:C-R*(C-A.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(be,{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(be,{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(be,{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 NF({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=PF();return k.useEffect(()=>{let p=!0;const y=`mermaid-${t.replace(/[^a-zA-Z0-9_-]/g,"")}`;return i(""),l(""),RF(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(be,{name:"maximize"})}),v.jsx("div",{className:"markdown-mermaid-diagram",dangerouslySetInnerHTML:{__html:n}})]}),d&&v.jsx(MF,{svg:n,theme:a,onClose:()=>h(!1)})]}):v.jsx("div",{className:"markdown-mermaid-loading",children:"Rendering diagram…"})}const jF=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(NF,{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(""),[E,T]=k.useState(0),[C,R]=k.useState(!1),[A,_]=k.useState(""),[B,I]=k.useState(!1),[X,$]=k.useState(!1),[G,j]=k.useState([]),[Q,U]=k.useState(!1),[fe,J]=k.useState(null),[te,ge]=k.useState(!1),[Ce,Y]=k.useState("");k.useEffect(()=>{let M=!0,ee=null;return d("loading"),Ul(t.id).then(ce=>{if(M){if(!ce){d("missing");return}s(new TextDecoder("utf-8").decode(ce)),ee=URL.createObjectURL(new Blob([ce],{type:"text/markdown;charset=utf-8"})),a(ee),d("ready")}}).catch(()=>{M&&d("error")}),()=>{M=!1,ee&&URL.revokeObjectURL(ee)}},[t.id]),k.useEffect(()=>{const M=()=>{const ee=window.getSelection(),ce=n.current;if(!ee||ee.isCollapsed||!ce){m(""),y(0);return}if(!ce.contains(ee.anchorNode)||!ce.contains(ee.focusNode)){m(""),y(0);return}const de=ee.getRangeAt(0),pe=ee.toString(),Pe=pe.length-pe.trimStart().length,ye=pe.trim().slice(0,4e3),De=document.createRange();De.selectNodeContents(ce),De.setEnd(de.startContainer,de.startOffset);const Ke=De.toString().length+Pe;m(ye),y(eD(ce.textContent,ye,Ke))};return document.addEventListener("selectionchange",M),()=>document.removeEventListener("selectionchange",M)},[]);const ae=()=>{h&&(S(h),T(p),R(!0),Y(""))},P=async()=>{if(X){if(!w||!A.trim())return;j(ee=>[...ee,{selection:w,comment:A.trim(),occurrence:E}]),_(""),R(!1),Y("Comment added to review");return}const M=ZI(w,A);if(!(!M||!A.trim()||B)){I(!0),Y("");try{await e.onSendText(M,t.id||void 0),_(""),R(!1),Y("Feedback sent")}catch(ee){Y(`Send failed: ${String(ee)}`)}finally{I(!1)}}},O=async()=>{if(G.length===0||Q)return;const M=sD(i,G);U(!0),Y("");try{e.onSendFile?await e.onSendFile({filename:JI(t.filename),mime:"text/markdown",bytes:new TextEncoder().encode(M)},t.id||void 0):await e.onSendText(M,t.id||void 0),j([]),$(!1),Y("Review submitted")}catch(ee){Y(`Review send failed: ${String(ee)}`)}finally{U(!1)}},Z=async()=>{if(!(!fe||!e.onSendFile||te)){ge(!0),Y("");try{await e.onSendFile(fe,t.id||void 0),J(null),Y("Voice feedback sent")}catch(M){Y(`Voice send failed: ${String(M)}`)}finally{ge(!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:M=>M.preventDefault(),onClick:ae,children:[v.jsx(be,{name:"reply",size:14}),X?"Add review comment":"Quick message",h?` (${h.length})`:""]}),X?v.jsx("button",{className:"btn sm",onClick:()=>{$(!1),j([]),R(!1),Y("Review discarded")},children:"Cancel review"}):v.jsxs("button",{className:"btn sm",onClick:()=>{$(!0),j([]),Y("Review started — select passages to add comments")},children:[v.jsx(be,{name:"edit",size:14}),"Start review"]}),l&&v.jsxs("a",{className:"btn sm",href:l,download:t.filename,children:[v.jsx(be,{name:"download",size:14}),"Download"]}),e.onSendFile&&v.jsx(k1,{disabled:!!fe||te,onReady:J,onError:Y}),v.jsx("span",{className:"markdown-review-hint",children:h?"Selection ready for feedback":"Highlight any passage to comment on it"})]}),C&&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:A,onChange:M=>_(M.target.value)}),v.jsxs("div",{className:"markdown-feedback-actions",children:[v.jsx("button",{className:"btn sm",onClick:()=>R(!1),children:"Cancel"}),v.jsxs("button",{className:"btn sm primary",disabled:!A.trim()||B,onClick:()=>void P(),children:[v.jsx(be,{name:"send",size:14}),X?"Add to review":B?"Sending…":"Send feedback"]})]})]}),X&&v.jsxs("div",{className:"markdown-review-draft",children:[v.jsxs("div",{className:"markdown-review-draft-head",children:[v.jsxs("strong",{children:["Review · ",G.length," comment",G.length===1?"":"s"]}),v.jsxs("button",{className:"btn sm primary",disabled:G.length===0||Q,onClick:()=>void O(),children:[v.jsx(be,{name:"send",size:14}),Q?"Submitting…":"Submit review"]})]}),G.map((M,ee)=>v.jsxs("div",{className:"markdown-review-comment",children:[v.jsx("span",{children:ee+1}),v.jsxs("div",{children:[v.jsx("blockquote",{children:M.selection}),v.jsx("p",{children:M.comment})]}),v.jsx("button",{className:"icon-btn",title:"Remove comment",onClick:()=>j(ce=>ce.filter((de,pe)=>pe!==ee)),children:v.jsx(be,{name:"close",size:14})})]},`${ee}-${M.selection.slice(0,24)}`))]}),fe&&v.jsx(w1,{att:fe,sending:te,onSend:()=>void Z(),onDiscard:()=>J(null)}),Ce&&v.jsx("div",{className:"markdown-review-status",role:"status",children:Ce}),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(jF,{markdown:i,contentRef:n})]})]})})}function $k(e){const{rec:t}=e,[n,i]=k.useState(""),[s,l]=k.useState(null),[a,c]=k.useState(0),[d,h]=k.useState("loading");return k.useEffect(()=>{let m=!0,p=null;return h("loading"),Ul(t.id).then(y=>{if(m){if(!y){h("missing");return}i(hD(new TextDecoder("utf-8").decode(y))),c(y.byteLength),p=URL.createObjectURL(new Blob([y],{type:wh(t.mime,t.filename)})),l(p),h("ready")}}).catch(()=>{m&&h("error")}),()=>{m=!1,p&&URL.revokeObjectURL(p)}},[t.id,t.mime,t.filename]),v.jsx(Ds,{title:t.filename,description:"HTML preview · sandboxed, static rendering only",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(be,{name:"shield",size:14}),"Scripts, forms and network requests are blocked"]}),s&&v.jsxs("a",{className:"btn sm",href:s,download:t.filename,children:[v.jsx(be,{name:"download",size:14}),"Download original",a?` · ${Fr(a)}`:""]})]}),v.jsxs("div",{className:"html-preview-frame",children:[d==="loading"&&v.jsx("div",{className:"markdown-empty",children:"Loading preview…"}),d==="missing"&&v.jsx("div",{className:"markdown-empty",children:"This file is available on the original device only."}),d==="error"&&v.jsx("div",{className:"markdown-empty",children:"The file could not be opened."}),d==="ready"&&v.jsx("iframe",{className:"html-preview-iframe",title:`Sandboxed preview of ${t.filename}`,sandbox:lD,referrerPolicy:"no-referrer",srcDoc:n})]})]})})}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 Ad(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(be,{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(be,{name:"monitor",size:16})}),Ms(a.filename,a.mime)&&n&&v.jsx("button",{className:"icon-btn",title:"Preview HTML",onClick:()=>e.onPreview(a),children:v.jsx(be,{name:"monitor",size:16})}),v.jsx("a",{className:"icon-btn"+(n?"":" disabled"),href:n??void 0,download:a.filename,title:"Download",children:v.jsx(be,{name:"download",size:16})})]})]})}function IF(e){const[t,n]=k.useState(!1);if(e.versions.length===1){const i=e.versions[0];return v.jsx(Ad,{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(be,{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(be,{name:t?"chevronDown":"chevron",size:16})]}),t&&v.jsx("div",{className:"file-version-stack-list",children:e.versions.map((i,s)=>v.jsx(Ad,{message:i.message,messageKey:i.key,versionLabel:`Version ${e.versions.length-s}`,onJump:e.onJump,onPreview:e.onPreview},i.key))})]})}function DF(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(Ad,{message:h.message,messageKey:h.key,onJump:e.onJump,onPreview:e.onPreview},h.key)),t==="file"&&a.map(h=>v.jsx(IF,{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(be,{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(be,{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 _F=Object.freeze(["image/avif","image/bmp","image/heic","image/heif","image/jpeg","image/jpg","image/png","image/webp"]),LF=/\.(avif|bmp|heic|heif|jpe?g|png|webp)$/i;function Wk(e,t=""){return _F.includes(String(e??"").toLowerCase())||LF.test(String(t??""))}function OF(e){return`${(String(e||"photo").trim()||"photo").replace(/\.[^./\\]+$/,"")||"photo"}.jpg`}function FF(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 zF=2048,VF=640,BF=.82,$F=[.84,.7,.56,.44],UF=.94;function WF(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 HF(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 KF(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*UF)),{image:i,release:s}=await WF(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(zF,Math.max(i.naturalWidth,i.naturalHeight));for(;c>=VF;){const d=FF(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 $F){const m=await HF(l,h);if(m.size<=n)return{filename:OF(e.name),mime:"image/jpeg",bytes:new Uint8Array(await m.arrayBuffer()),width:l.width,height:l.height,originalSize:e.size}}c=Math.floor(c*BF)}}finally{s(),l.width=1,l.height=1}throw new Error("The photo is still too large after optimization.")}const qF=5e4,XF=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 XF.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 YF(e){return e.split(/(\n[ \t]*\n)/).map(t=>{if(/^\n[ \t]*\n$/.test(t))return t;const n=t.split(`
|
|
320
320
|
`),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(`
|
|
321
|
-
`)}).join("")}function GF({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 QF=[Vk],ZF={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:GF,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>qF?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:QF,components:ZF,urlTransform:i=>Hk(i)??"",children:YF(t)})})}),yl={type:"spring",stiffness:430,damping:38,mass:.72},vx=10,qk=56,JF=18,ez=650;function tz(e,t){return Math.abs(e)<vx&&Math.abs(t)<vx?"pending":Math.abs(e)>Math.abs(t)&&e>0?"drag":"reject"}function nz(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 rz(e,t){const n=nz(t);return n>=0&&(e>=qk||e>=JF&&n>=ez)}const Md="ours.chats.listMode",cs="recent";function Xk(){try{return globalThis.localStorage}catch{return}}function iz(e=Xk()){try{return e?.getItem(Md)==="identity"?"identity":cs}catch{return cs}}function oz(e,t=Xk()){const n=e==="identity"?"identity":cs;try{return t?.setItem(Md,n),t?.getItem(Md)===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 sz(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(sz)}function xx(e){return e.contacts.length>0?Rl(Ss(e.contacts[0].activityAt)):0}function az(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 lz=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 uz(e){const{contacts:t,roots:n,selected:i}=e,[s,l]=k.useState(""),[a,c]=k.useState(()=>iz()),d=C=>C.name.toLowerCase().includes(s.toLowerCase()),h=t.filter(C=>C.status!=="pending"&&d(C)),m=t.filter(C=>C.status==="pending"&&d(C)),p=Nd(h),y=az(h,n),w=h.length===0&&m.length===0,S=C=>{c(oz(C))},E=[{id:"recent",label:"Recent"},{id:"identity",label:"By identity"}],T=(C,R)=>{if(!["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End"].includes(C.key))return;C.preventDefault();const _=C.key==="Home"?"recent":C.key==="End"||R==="recent"?"identity":"recent";S(_),document.getElementById(`conversation-list-${_}`)?.focus()};return v.jsxs("div",{className:"listcol",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(be,{name:"lock",size:16}),"Ours Messenger"]}),v.jsxs("div",{className:"listcol-actions",children:[v.jsxs("button",{className:"btn sm primary",onClick:e.onInvite,children:[v.jsx(be,{name:"invite",size:15}),"Invite"]}),v.jsx("button",{className:"icon-btn",title:"Settings",onClick:e.onSettings,children:v.jsx(be,{name:"settings"})})]})]}),v.jsxs("div",{className:"search",children:[v.jsx(be,{name:"search"}),v.jsx("input",{className:"field",placeholder:"Search people, agents, apps…",value:s,onChange:C=>l(C.target.value)})]}),v.jsx("div",{className:"conversation-list-modes",role:"tablist","aria-label":"Conversation list layout",children:E.map(C=>v.jsx("button",{id:`conversation-list-${C.id}`,type:"button",role:"tab","aria-selected":a===C.id,"aria-controls":"conversation-list-panel",tabIndex:a===C.id?0:-1,className:a===C.id?"active":"",onClick:()=>S(C.id),onKeyDown:R=>T(R,C.id),children:C.label},C.id))})]}),v.jsxs("div",{id:"conversation-list-panel",className:"listcol-scroll",role:"tabpanel","aria-labelledby":`conversation-list-${a}`,children:[a==="recent"&&p.length>0&&v.jsx("div",{className:"conversation-group",children:p.map(C=>v.jsx(Ef,{c:C,active:i===C.id,onClick:()=>e.onSelect(C.id)},C.id))}),a==="identity"&&y.map(C=>v.jsxs("div",{children:[v.jsxs("div",{className:"group-label",title:C.note,children:[C.rootId&&v.jsx(be,{name:"clusters"}),v.jsx("span",{children:C.label}),C.note&&v.jsxs("span",{className:"gl-note",children:["· ",C.note]})]}),v.jsx("div",{className:"conversation-group",children:C.contacts.map(R=>v.jsx(Ef,{c:R,grouped:C.rootId!==null,active:i===R.id,onClick:()=>e.onSelect(R.id)},R.id))})]},C.id)),m.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:m.map(C=>v.jsx(Ef,{c:C,active:!1,onClick:()=>{},onApprove:()=>e.onApprovePending(C.id.slice(8)),onReject:()=>e.onRejectPending(C.id.slice(8))},C.id))})]}),w&&v.jsx("p",{className:"muted",style:{padding:"14px 10px",fontSize:"0.85rem"},children:"No contacts yet — share an invite to start."})]})]})}function cz(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(be,{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(be,{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(be,{name:"paperclip"}),"Shared photos, files, and links"]}),v.jsx(be,{name:"chevron"})]}),v.jsxs("button",{type:"button",onClick:()=>{h.current=!1,s(e.contact.name),n(!0)},children:[v.jsxs("span",{children:[v.jsx(be,{name:"edit"}),"Rename contact"]}),v.jsx(be,{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(be,{name:"copy",size:14}),"Copy identity"]})]}),v.jsxs("button",{type:"button",className:"contact-remove",onClick:e.onRemove,children:[v.jsx(be,{name:"trash"}),"Remove contact"]})]}),l&&v.jsx(DF,{messages:e.messages,indexOffset:e.indexOffset,onClose:()=>a(!1),onJump:e.onOpenMessage,onPreview:p=>{a(!1),d(p)}}),c&&(Ms(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=R=>{const A=l.current,_=a.current,B=Yk();if(A&&(A.style.transform=R&&!B?`translateX(${R}px)`:""),_){const I=Math.min(1,Math.abs(R)/h);_.style.opacity=String(I),_.style.transform=B?"scale(1)":`scale(${.5+.5*I})`}},S=(R,A)=>{const _=y.current;if(_.id!==R)return;const B=A&&_.mode==="drag"&&rz(_.distance,_.samples);y.current=p(),l.current?.classList.remove("swiping"),a.current?.classList.remove("armed"),w(0);const I=s.current;I?.hasPointerCapture?.(R)&&I.releasePointerCapture(R),B&&c.current()};k.useEffect(()=>{const R=s.current;if(!R)return;const A=_=>S(_.pointerId,!1);return R.addEventListener("lostpointercapture",A),()=>{R.removeEventListener("lostpointercapture",A);const _=y.current.id;_!==-1&&S(_,!1)}},[]);const E=R=>{const A=R.target,_=window.getSelection?.();!n||!R.isPrimary||R.pointerType==="mouse"||R.button!==0||y.current.id!==-1||_&&!_.isCollapsed||A.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:R.pointerId,x0:R.clientX,y0:R.clientY,mode:"maybe",armed:!1,distance:0,samples:[{x:R.clientX*d,time:R.timeStamp}]},w(0))},T=R=>{const A=y.current;if(A.id!==R.pointerId||A.mode==="idle")return;const _=R.clientX-A.x0,B=R.clientY-A.y0,I=window.getSelection?.();if(I&&!I.isCollapsed){S(R.pointerId,!1);return}if(A.mode==="maybe"){const Q=tz(_*d,B);if(Q==="pending")return;if(Q==="drag")A.mode="drag",R.currentTarget.setPointerCapture?.(R.pointerId),l.current?.classList.add("swiping");else{A.mode="idle";return}}R.preventDefault();const X=R.timeStamp;A.samples.push({x:R.clientX*d,time:X}),A.samples=A.samples.filter(Q=>X-Q.time<=120);let $=_*d;$<0&&($=0),$>h&&($=h+($-h)*.35),$=Math.min($,m),A.distance=$;const G=$*d,j=Math.abs(G)>=h;j!==A.armed&&(A.armed=j,a.current?.classList.toggle("armed",j),j&&navigator.vibrate?.(10)),w(G)},C=R=>{const A=y.current;A.id===R.pointerId&&A.mode==="drag"&&(A.samples.push({x:R.clientX*d,time:R.timeStamp}),A.distance=Math.max(0,(R.clientX-A.x0)*d),A.armed=A.distance>=h),S(R.pointerId,!0)};return v.jsxs("div",{ref:s,className:"msg-row "+(e.rowClass??t),style:n?{touchAction:"pan-y"}:void 0,onPointerDown:E,onPointerMove:T,onPointerUp:C,onPointerCancel:R=>S(R.pointerId,!1),onLostPointerCapture:R=>S(R.pointerId,!1),children:[n&&v.jsx("span",{className:"swipe-cue",ref:a,"aria-hidden":!0,children:v.jsx(be,{name:"reply",size:16})}),v.jsx("div",{className:"bubble-wrap",ref:l,children:e.children}),e.after]})}function fz(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),[E,T]=k.useState(null),[C,R]=k.useState(!1),[A,_]=k.useState(!1),[B,I]=k.useState(!1),[X,$]=k.useState(null),G=k.useRef(null),j=k.useRef(null),Q=k.useRef(!1),U=k.useRef(null),fe=k.useRef(!1),[J,te]=k.useState(!1),[ge,Ce]=k.useState(0),Y=k.useRef(null),ae=k.useRef(!0),P=k.useRef(null),O=k.useRef(0),Z=k.useRef(null),M=k.useRef(new Map),ee=k.useRef(0),ce=k.useRef(null),de=k.useRef(null),pe=k.useRef(0),Pe=k.useRef(null);k.useEffect(()=>{s(""),m(null),y(null),d(null),S(null),T(null),R(!1),_(!1),I(!1),O.current+=1,$(null),M.current.clear(),ce.current=null,de.current=null},[t?.id]),k.useEffect(()=>{if(!p)return;const V=p.reply?.wireId;n.some(q=>q.kind!=="file"&&q.dir==="out"&&!!q.wireId&&!p.wireIds.has(q.wireId)&&q.text===p.text&&(q.replyTo?.wireId??void 0)===V)&&(y(null),m(null),s(q=>q===p.draft?"":q),S(q=>q===p.reply?null:q))},[n,p]);const ye=!!c?.wireId&&n.some(V=>V.wireId===c.wireId),De=k.useMemo(()=>c&&!ye?[...n,c.message]:n,[n,c,ye]);k.useEffect(()=>{ye&&d(null)},[ye]),k.useLayoutEffect(()=>{const V=j.current;if(!V)return;V.style.height="0px";const D=Math.max(44,Math.min(V.scrollHeight,132));V.style.height=`${D}px`,V.style.overflowY=V.scrollHeight>132?"auto":"hidden"},[i,t?.id]);const Ke=V=>{const D=U.current;if(!D)return;const q=Math.max(0,D.scrollHeight-D.clientHeight);if(Math.abs(D.scrollTop-q)<1){ce.current=null,de.current=null;return}const he=V&&!Yk();ce.current=he?q:null,de.current=he?D.scrollTop:null,he?D.scrollTo({top:q,behavior:"smooth"}):D.scrollTop=q},nt=()=>{Y.current===null&&(Y.current=requestAnimationFrame(()=>{Y.current=null;const V=U.current;if(!V)return;const D=V.scrollHeight-V.clientHeight-V.scrollTop>48;te(D),D||Ce(0)}))};k.useLayoutEffect(()=>{if(!t){P.current=null,ae.current=!0,pe.current=0;return}const V=U.current;if(!V)return;const D=P.current!==t.id,q=pe.current,he=De.length!==q,Re=De.at(-1),Oe=Re?Re.wireId||`${Re.date}:${Re.text}`:null,Ie=Pe.current;if(pe.current=De.length,Pe.current=Oe,!D&&!he&&ce.current===null&&(ae.current=V.scrollHeight-V.clientHeight-V.scrollTop<=48),D||ae.current)Ke(he&&!D&&P.current!==null),ae.current=!0;else if(he&&De.length>q&&Oe!==Ie){const H=Ie===null?-1:De.findIndex(se=>(se.wireId||`${se.date}:${se.text}`)===Ie);Ce(se=>se+Math.max(1,De.length-Math.max(0,H+1)))}P.current=t.id,nt()},[t,De.length]),k.useLayoutEffect(()=>{if(fe.current||!e.unreadOpen||window.location.hash.startsWith("#chat-message-"))return;const V=U.current,D=document.getElementById(`unread-${wx(e.unreadOpen.wireId)}`);!V||!D||(V.scrollTop=Math.max(0,D.offsetTop-16),ae.current=!1,fe.current=!0,nt())},[e.unreadOpen,De.length]),k.useLayoutEffect(()=>{const V=window.location.hash;if(!V.startsWith("#chat-message-"))return;const D=document.getElementById(V.slice(1));D&&(D.scrollIntoView({block:"center"}),ae.current=!1)},[t?.id,De.length]),k.useLayoutEffect(()=>{const V=Z.current,D=U.current;if(V===null||!D)return;const q=requestAnimationFrame(()=>{Z.current===V&&(D.scrollTop=V.top+D.scrollHeight-V.height,Z.current=null)});return()=>cancelAnimationFrame(q)},[De.length]),k.useEffect(()=>{const V=U.current;if(!V||typeof ResizeObserver>"u")return;const D=V.firstElementChild;if(!D)return;const q=new ResizeObserver(()=>{ae.current&&Ke(ce.current!==null),nt()});return q.observe(D),q.observe(V),()=>{q.disconnect(),Y.current!==null&&cancelAnimationFrame(Y.current)}},[t?.id]);const St=async V=>{const D=++O.current;m(null),I(!0);try{if(V.size>ts&&Wk(V.type,V.name)){const he=await KF(V,ts);if(D!==O.current)return;T({filename:he.filename,mime:he.mime,bytes:he.bytes,originalSize:he.originalSize});return}if(V.size>ts){m(`"${V.name}" is ${Fr(V.size)} — files up to ${Fr(ts)} can be sent.`);return}const q=await V.arrayBuffer();if(D!==O.current)return;T({filename:V.name||"file",mime:V.type||"application/octet-stream",bytes:new Uint8Array(q)})}catch(q){D===O.current&&m(`Photo optimization failed: ${q instanceof Error?q.message:String(q)}`)}finally{D===O.current&&I(!1)}},ut=()=>{!E||!e.onSendFile||A||(_(!0),e.onSendFile(E,w?.wireId).then(()=>{T(null),S(null)}).catch(V=>m(`File send failed: ${String(V)} — it was not delivered.`)).finally(()=>_(!1)))},bt=e.onDraftChange;k.useEffect(()=>(bt?.(i.trim().length>0||l),()=>bt?.(!1)),[i,l,bt]);const Bt=new Map;for(const V of De)V.wireId&&Bt.set(V.wireId,V);const it=k.useMemo(()=>{const V=new Map;for(const D of De)V.set(D,D.kind==="file"?null:D.dir==="in"?yA(t?.announcedName??"",D.text):null);return V},[De,t?.announcedName]),Ct=V=>it.get(V)??null,dn=V=>{if(V.dir==="out")return"You";const D=Ct(V);return D&&D.variant==="chat"?D.author:t?.name??"Them"},Mt=V=>{if(V.kind==="file")return V.mime?.startsWith("image/")?"Photo":eo(V.mime??"",V.filename??"")?"Voice message":V.filename||"File";const D=Ct(V);return D?D.text||CA(D):V.text},rn=V=>{if(!V.replyTo)return null;const D=Bt.get(V.replyTo.wireId);return D?{author:dn(D),text:Mt(D)}:{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(be,{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 Cn=async()=>{const V=i,D=V.trim(),q=!!p&&V===p.draft&&(w?.wireId??void 0)===p.reply?.wireId;if(!D||Q.current||q)return;p&&y(null),Q.current=!0,a(!0),m(null);const he=w,Re=he?.wireId,Oe=new AbortController;let Ie=!1,H=0;s(""),S(null);const se=`optimistic-${++ee.current}`;d({key:se,wireId:null,message:{dir:"out",text:D,date:new Date().toISOString(),read:!0,wireId:"",replyTo:Re?{wireId:Re}:null}});try{const ue=await Promise.race([e.onSend(D,Re,Oe.signal),new Promise((we,Ae)=>{H=window.setTimeout(()=>{Ie=!0,Oe.abort(),Ae(new Error("send timeout"))},lz)})]);ue?(M.current.set(ue,se),d(we=>we?.key===se?{...we,wireId:ue}:we)):d(we=>we?.key===se?null:we),y(null)}catch(ue){d(null),s(we=>we===""?V:we),S(we=>we===null?he:we),Ie||!(ue instanceof Qf)?(y({draft:V,text:D,reply:he,wireIds:new Set(n.flatMap(we=>we.wireId?[we.wireId]:[]))}),m(`${Ie?"Send timed out":"Send connection was interrupted"} — delivery status is unknown. Check the conversation; edit the draft before sending again.`)):m(`Send failed: ${String(ue)} — the message was not delivered.`)}finally{window.clearTimeout(H),Q.current=!1,a(!1)}},Be=!!p&&i===p.draft&&(w?.wireId??void 0)===p.reply?.wireId,On=V=>{V.wireId&&S({wireId:V.wireId,author:dn(V),text:Mt(V)})};return v.jsxs("div",{className:"detail detail-chat",children:[v.jsx("div",{className:"detail-head",children:v.jsxs("div",{className:"conv-peer",children:[v.jsx("button",{className:"icon-btn detail-back",onClick:e.onBack,children:v.jsx(be,{name:"back"})}),v.jsxs("button",{type:"button",className:"conv-contact-trigger","data-contact-trigger":!0,onClick:e.onOpenContact,disabled:!e.onOpenContact,"aria-label":`Open contact details for ${t.name}`,children:[v.jsx("span",{className:"avatar accent",children:t.initials}),v.jsxs("span",{className:"conv-peer-meta",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(be,{name:"lock",size:11}),"Encrypted connection"]})]})]})]})}),v.jsx("div",{className:"messages",ref:U,tabIndex:-1,"aria-label":"Conversation timeline",onScroll:V=>{const D=V.currentTarget,q=D.scrollHeight-D.clientHeight-D.scrollTop;if(ce.current!==null){const he=de.current;if(he===null||D.scrollTop>=he-1){de.current=D.scrollTop,q<=4&&(ce.current=null,de.current=null);return}ce.current=null,de.current=null}ae.current=q<=48,nt()},onPointerDown:()=>{ce.current=null,de.current=null},onTouchStart:()=>{ce.current=null,de.current=null},onWheel:()=>{ce.current=null,de.current=null},onDragOver:V=>{e.onSendFile&&V.preventDefault()},onDrop:V=>{if(!e.onSendFile)return;V.preventDefault();const D=V.dataTransfer.files?.[0];D&&St(D)},children:v.jsxs("div",{className:"messages-inner",children:[v.jsxs("div",{className:"e2e-note",children:[v.jsx(be,{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:()=>{ae.current=!1;const V=U.current;Z.current=V?{height:V.scrollHeight,top:V.scrollTop}:null,e.onLoadEarlier?.()},children:["Load earlier messages (",e.hiddenEarlier," remaining)"]}),v.jsx(qP,{initial:!1,children:De.map((V,D)=>{const q=V===c?.message?c.key:V.wireId&&M.current.get(V.wireId)||V.wireId||`${V.date}-${(e.hiddenEarlier??0)+D}`,he=wx(V.wireId||q),Re=De[D-1],Oe=De[D+1],Ie=Ct(V),H=dt=>{if(!dt)return null;const Et=Ct(dt);return Et?Et.variant==="system"?"room:system":`room:chat:${Et.author}${Et.role}`:dt.dir},se=H(V),ue=!!Re&&H(Re)===se&&se!=="room:system",we=!!Oe&&H(Oe)===se&&se!=="room:system",Ae=(V.dir==="out"?"out":"in")+(ue?" cont-top":"")+(we?" cont-bot":""),me=V.wireId?v.jsx("button",{className:"msg-reply",title:"Reply",onClick:()=>On(V),children:v.jsx(be,{name:"reply",size:15})}):null;if(Ie&&Ie.variant==="system"){const dt=Ie.presentation??"system";return v.jsxs(ss.div,{className:"message-motion",id:he,initial:{opacity:0,y:8},animate:{opacity:1,y:0},exit:{opacity:0},transition:yl,children:[V.wireId===e.unreadOpen?.wireId&&v.jsx("div",{id:`unread-${he}`,className:"unread-divider",role:"separator",children:v.jsx("span",{children:"Unread messages"})}),v.jsxs("div",{className:`room-system room-${dt}-card`,role:"note",children:[Ie.label&&v.jsx("span",{className:"room-system-label",children:Ie.label}),Ie.roomName&&v.jsx("strong",{className:"room-card-name",children:Ie.roomName}),v.jsx(yx,{text:Ie.text,className:"room-system-text message-markdown"}),!!Ie.details?.length&&v.jsx("ul",{className:"room-card-details","aria-label":"Room event details",children:Ie.details.map(Et=>v.jsx("li",{children:Et},Et))}),v.jsxs("span",{className:"room-card-provenance",children:[Ie.authoredBy&&v.jsx("span",{className:"room-card-author",children:Ie.authoredBy}),v.jsx("span",{className:"room-system-at",children:ys(Ie.authoredAt||V.date)})]})]})]},q)}if(V.kind==="file"){const dt=S0(V.wireId)??{id:V.wireId,dir:V.dir,filename:V.filename??"file",mime:V.mime??"application/octet-stream",size:0,date:V.date};return v.jsxs(ss.div,{className:"message-motion",id:he,initial:{opacity:0,y:12,scale:.985},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,scale:.98},transition:yl,children:[V.wireId===e.unreadOpen?.wireId&&v.jsx("div",{id:`unread-${he}`,className:"unread-divider",role:"separator",children:v.jsx("span",{children:"Unread messages"})}),v.jsx(kx,{dir:V.dir==="out"?"out":"in",rowClass:Ae,canReply:!!V.wireId,onReply:()=>On(V),after:me,children:v.jsx("div",{className:`ours-message ours-message-file ours-message--${V.dir}`,children:v.jsx(PD,{rec:dt,receipt:V.receipt,receiptless:V.receiptless,onPreview:$,onFetch:e.onFetchFile})})})]},q)}const Fe=rn(V);return v.jsxs(ss.div,{className:"message-motion",id:he,initial:{opacity:0,y:12,scale:.985},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,scale:.98},transition:yl,children:[V.wireId===e.unreadOpen?.wireId&&v.jsx("div",{id:`unread-${he}`,className:"unread-divider",role:"separator",children:v.jsx("span",{children:"Unread messages"})}),v.jsx(kx,{dir:V.dir==="out"?"out":"in",rowClass:Ae,canReply:!!V.wireId,onReply:()=>On(V),after:me,children:v.jsxs("div",{className:`ours-message ours-message--${V.dir}`,children:[Fe&&v.jsxs("div",{className:"quote",children:[Fe.author&&v.jsx("span",{className:"quote-author",children:Fe.author}),v.jsx("span",{className:"quote-text",children:Fe.text})]}),Ie&&!ue&&v.jsxs(v.Fragment,{children:[Ie.roomName&&v.jsx("div",{className:"room-message-room",children:Ie.roomName}),v.jsxs("div",{className:"room-author",children:[v.jsx("span",{className:"room-author-name",children:Ie.author}),Ie.role&&v.jsx("span",{className:"room-author-role",children:Ie.role})]})]}),v.jsx(yx,{text:Ie?Ie.text:V.text}),v.jsxs("div",{className:"bubble-at",children:[ys(Ie?.authoredAt||V.date),V.dir==="out"&&v.jsx(b0,{receipt:V.receipt,receiptless:V.receiptless})]})]})})]},q)})}),v.jsx("div",{className:"thread-end","aria-hidden":!0})]})},t.id),J&&v.jsxs("button",{type:"button",className:"jump-latest btn sm","aria-label":ge?`Jump to latest, ${ge} new messages`:"Jump to latest",onClick:V=>{const D=V.currentTarget===document.activeElement;Ce(0),Ke(!0),D&&requestAnimationFrame(()=>U.current?.focus({preventScroll:!0}))},children:[v.jsx("span",{children:"Jump to latest"}),!!ge&&v.jsx("span",{className:"jump-latest-count","aria-live":"polite",children:ge})]}),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 Cn(),children:"retry"})})]}),v.jsxs("div",{className:"composer-wrap",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(be,{name:"close",size:16})})]}),E&&v.jsx(w1,{att:E,sending:A,onSend:ut,onDiscard:()=>T(null)}),B&&v.jsx("div",{className:"attachment-processing",role:"status",children:"Optimizing photo for secure delivery…"}),v.jsxs("div",{className:"composer"+(C?" recording":""),children:[e.onSendFile&&v.jsxs(v.Fragment,{children:[v.jsx("input",{ref:G,type:"file",style:{display:"none"},onChange:V=>{const D=V.target.files?.[0];D&&St(D),V.target.value=""}}),v.jsx("button",{className:"icon-btn composer-tool",title:"Attach a file or photo",disabled:A||B||C,onClick:()=>G.current?.click(),children:v.jsx(be,{name:"paperclip",size:18})})]}),v.jsx("textarea",{ref:j,className:"field",rows:1,placeholder:(w?"Reply to "+w.author:"Message "+t.name)+"…",value:i,"aria-busy":l,onChange:V=>s(V.target.value),onKeyDown:V=>{V.key==="Enter"?!(window.matchMedia("(pointer: coarse)").matches||window.innerWidth<=860)&&!V.shiftKey&&(V.preventDefault(),Cn()):V.key==="Escape"&&S(null)}}),e.onSendFile&&!i.trim()&&!E&&!B&&!A?v.jsx(k1,{disabled:A||B||!!E,onReady:V=>{R(!1),T(V)},onError:V=>{R(!1),m(V)},onActiveChange:R},t.id):v.jsxs("button",{className:"btn primary","aria-label":"Send",onPointerDown:V=>{V.button===0&&document.activeElement===j.current&&V.preventDefault()},onClick:()=>void Cn(),disabled:l||Be||!i.trim(),title:Be?"Delivery status unknown — edit before sending again":void 0,children:[v.jsx(be,{name:"send",size:16}),v.jsx("span",{className:"btn-label",children:"Send"})]})]})]}),X&&(Ms(X.filename,X.mime)?v.jsx($k,{rec:X,onClose:()=>$(null)}):v.jsx(Bk,{rec:X,onClose:()=>$(null),onSendText:e.onSend,onSendFile:e.onSendFile}))]})}const Gk=3;function dz(e,t,n=Gk){return[t,...e.filter(i=>i.cid!==t.cid)].slice(0,n)}function hz(e,t){return e.filter(n=>n.id!==t)}const pz=6e3,mz=dz,gz=hz;function yz(){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=>mz(p,m,Gk))},[]),s=k.useCallback(a=>t(c=>gz(c,a)),[]),l=k.useCallback(a=>t(c=>c.filter(d=>d.cid!==a)),[]);return{toasts:e,push:i,dismiss:s,clear:l}}function vz(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),pz);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(be,{name:"close",size:15})})]})}function xz(e){return v.jsx(v.Fragment,{children:e.items.map(t=>v.jsx(vz,{item:t,onOpen:e.onOpen,onDismiss:e.onDismiss},t.id))})}function wz(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-DGdhyi2S.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 kz(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 E=n.current,T=E.getContext("2d"),C=()=>{if(l.current)if(S.readyState>=S.HAVE_ENOUGH_DATA){const R=S.videoWidth||320,A=S.videoHeight||240;E.width=R,E.height=A,T.drawImage(S,0,0,R,A);const _=T.getImageData(0,0,R,A);Ch(()=>import("./jsQR-BmxRSd9_.js").then(B=>B.j),[]).then(B=>{const I=B.default,X=I(_.data,_.width,_.height,{inversionAttempts:"dontInvert"});if(X&&X.data&&l.current){m(),e.onDecode(X.data);return}l.current&&(s.current=requestAnimationFrame(C))})}else s.current=requestAnimationFrame(C)};s.current=requestAnimationFrame(C)},[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(be,{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(be,{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(be,{name:"close",size:14}),"Cancel scan"]}):v.jsxs(v.Fragment,{children:[v.jsx(be,{name:"close",size:14}),"Close scanner"]})})]})}function Sz(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(""),[E,T]=k.useState(!1),[C,R]=k.useState(null),[A,_]=k.useState(null),[B,I]=k.useState(!1),[X,$]=k.useState(null),G=k.useRef(!1),j=async()=>{if(!G.current){G.current=!0,T(!0),_(null),R(null);try{m(i),d(await e.onCreate(i,i==="one_time"&&l.trim()||void 0))}catch(U){_(U instanceof Error?U.message:String(U))}finally{G.current=!1,T(!1)}}},Q=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:()=>{G.current||e.onClose()},tabs:Q,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:U=>a(U.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:E,onClick:()=>void j(),children:E?"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(U=>U.mode==="public").length===0&&v.jsx("p",{className:"muted",style:{margin:0},children:"None right now."}),e.invites.filter(U=>U.mode==="public").map(U=>v.jsxs("div",{"data-testid":"public-invite-row",style:{padding:"8px 10px",background:"var(--inset)",borderRadius:7},children:[v.jsx("span",{className:"mono",children:U.invite_id}),v.jsxs("p",{className:"muted",children:["Created ",U.created?RA(U.created):"unknown"," · Active until revoked · No expiry"]}),X===U.invite_id?v.jsxs("span",{children:[v.jsx("button",{className:"btn sm danger",onClick:()=>void e.onRevoke(U.invite_id).then(()=>($(null),e.onRefresh())).catch(fe=>_(String(fe))),children:"Confirm revoke"})," ",v.jsx("button",{className:"btn sm",onClick:()=>$(null),children:"Keep it"})]}):v.jsx("button",{className:"btn sm",onClick:()=>$(U.invite_id),children:"Revoke"})]},U.invite_id))]}),C&&v.jsx("p",{className:"muted",children:C}),A&&v.jsx("p",{className:"onb-error",children:A})]}),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:U=>U.currentTarget.select()}),h==="one_time"&&v.jsx(wz,{text:c}),v.jsxs("button",{className:"btn primary",onClick:()=>void navigator.clipboard.writeText(c).then(()=>R("Copied to clipboard.")),children:[v.jsx(be,{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"}),C&&v.jsx("p",{className:"muted",children:C})]}),t==="accept"&&v.jsxs("form",{style:{display:"flex",flexDirection:"column",gap:13},onSubmit:U=>{U.preventDefault(),!(!p.trim()||E)&&(T(!0),_(null),e.onAccept(p.trim(),w.trim()||void 0).then(()=>{R("Invite accepted — the contact will appear once the sender verifies your identity."),y(""),S("")}).catch(fe=>_(String(fe))).finally(()=>T(!1)))},children:[v.jsx("p",{className:"muted",children:"Paste the invite you received, or scan a QR code."}),B?v.jsx(kz,{onDecode:U=>{y(U),I(!1)},onClose:()=>I(!1)}):v.jsxs("button",{type:"button",className:"btn",onClick:()=>I(!0),children:[v.jsx(be,{name:"monitor",size:15}),"Scan QR code"]}),v.jsx("textarea",{className:"field mono","aria-label":"Invite",rows:5,value:p,onChange:U=>y(U.target.value),placeholder:"Paste invite text…"}),v.jsx("input",{className:"field",value:w,onChange:U=>S(U.target.value),placeholder:"Rename them (optional)",maxLength:64}),v.jsx("button",{className:"btn primary",type:"submit",disabled:E||!p.trim(),children:E?"Connecting…":"Add contact"}),C&&v.jsx("p",{className:"muted",children:C}),A&&v.jsx("p",{className:"onb-error",children:A})]})]})})}function bz(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=x2(),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 Cz(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 Ez="3b15cbf8a6084166abc26693da2f97472f97e024",Tz=15*6e4,Pz=6e4,Rz=Cz;async function Az(){try{const e=await fetch("/version.json",{cache:"no-store"});return e.ok?await e.json():null}catch{return null}}function Mz(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 Az(),h=Rz(Ez,d,t,Date.now(),Pz);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(),Tz),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 Nz(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 jz(){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,Iz=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 Dz(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 _z(e,t){return[...e.contacts.contacts.map(i=>{const s=e.contacts.roots?.[i.container_id],l=sr(e,i.container_id),c=Qk(l,t[i.container_id]??[]).at(-1),d=Ml(i);return{id:i.container_id,name:d,announcedName:i.name,initials:rd(d),when:c?PA(c.date):"",activityAt:c?.date??"",last:c?.kind==="file"?LA(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=Ml(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 Lz(){return v.jsx(Oz,{})}function Oz(){const e=k.useRef(h2(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 u2),h=k.useRef(null),m=k.useRef(new Map),p=k.useRef(new Map),[y,w]=k.useState({}),S=k.useRef(y),[E,T]=k.useState(null),C=k.useRef(new Set),[R,A]=k.useState(null),_=k.useRef(R),B=k.useRef(!1),[I,X]=k.useState([]),[$,G]=k.useState(null),[j,Q]=k.useState(()=>localStorage.getItem(Ex)!=="0"),[U,fe]=k.useState(null),[J,te]=k.useState({supported:!1,offline:!navigator.onLine,updateAvailable:!1,registration:null}),[ge,Ce]=k.useState({status:"unsupported",preview:"full"}),[Y,ae]=k.useState(!1),P=k.useRef(!1),[O,Z]=k.useState(()=>window.location.hash.startsWith(Tx)),{toasts:M,push:ee,dismiss:ce,clear:de}=yz(),pe=k.useCallback(H=>{c.current=Jy(c.current,H),n(H)},[]),Pe=k.useCallback(H=>{B.current=H},[]);k.useEffect(()=>{c.current=t},[t]),_.current=R,S.current=y,k.useMemo(()=>(cv(Object.values(y).flat()),null),[y]),k.useEffect(()=>(document.documentElement.classList.toggle("theme-dark",j),()=>document.documentElement.classList.remove("theme-dark")),[j]);const ye=k.useCallback(H=>pe({type:"error",message:Iz(H)}),[pe]),De=k.useCallback(()=>{const H=c.current;return{visibility:document.visibilityState,appRoute:H.route.name==="chats"?"chats":"other",selectedContactCid:ri(H),desktopLayout:h.current?.matches??window.innerWidth>=861,mobileDetailOpen:H.mobileDetailOpen,conversationCoveringDialogOpen:_.current!==null}},[]),Ke=k.useCallback(async(H,se=!0)=>{try{const ue=await qe.conversation(H);return pe({type:"page",contactCid:H,page:ue}),ue}catch(ue){return se&&ye(ue),null}},[pe,ye]),nt=k.useCallback(async(H,se=!0)=>{try{const ue=await qe.files(H);return cv(ue.files),w(we=>({...we,[H]:ue.files})),ue.files}catch(ue){return se&&ye(ue),null}},[ye]);k.useEffect(()=>Mz({onUpdateAvailable:()=>te(H=>({...H,updateAvailable:!0})),onStuck:H=>{Nz(H)}}),[]);const St=k.useCallback(async()=>{const H=await qe.contacts();return pe({type:"contacts",contacts:{...H,pending:H.pending??[]}}),H},[pe]),ut=k.useCallback(async()=>{try{const[H,se,ue]=await Promise.all([qe.identity(),qe.contacts(),qe.buildInfo()]),we={...se,pending:se.pending??[]};return c.current.identity&&c.current.identity.cid!==H.cid&&(IA(),S.current={},w({})),pe({type:"snapshot",identity:H,contacts:we}),G(ue),await Promise.all(we.contacts.flatMap(Ae=>[Ke(Ae.container_id,!1),nt(Ae.container_id,!1)])),ri(c.current)}catch(H){return ye(H),null}},[pe,nt,Ke,ye]),bt=k.useCallback(async H=>{await d.current.request(H,async()=>{l2(H,De())&&(await qe.markRead(H),await Promise.all([Ke(H),St()]))}).catch(ye)},[De,St,Ke,ye]),Bt=k.useCallback(async H=>{const se=++l.current;a.current?.abort();const ue=new AbortController;a.current=ue,s(null),de(H),nt(H,!1);let we;try{we=await qe.conversation(H,void 0,ue.signal)}catch(ht){ue.signal.aborted||ye(ht);return}if(ue.signal.aborted||se!==l.current)return;pe({type:"page",contactCid:H,page:we});const Ae=we.unread;let me=[...we.messages],Fe=we.nextBefore;const dt=new Set,Et=new Set(me.map(ht=>ht.wire_id).filter(Boolean)),yt=()=>me.filter(ht=>ht.dir==="in"&&!ht.read);for(;yt().length<Ae&&Fe&&!dt.has(Fe);){dt.add(Fe);let ht;try{ht=await qe.conversation(H,Fe,ue.signal)}catch{break}if(ue.signal.aborted||se!==l.current)return;const cr=ht.messages.filter(fr=>!fr.wire_id||!Et.has(fr.wire_id));if(!cr.length&&ht.nextBefore===Fe)break;for(const fr of cr)fr.wire_id&&Et.add(fr.wire_id);me=[...cr,...me],pe({type:"older_page",contactCid:H,page:ht,newer:we.messages}),Fe=ht.nextBefore}const vt=yt()[0];vt?.wire_id&&se===l.current&&!ue.signal.aborted&&s({contactCid:H,wireId:vt.wire_id,count:Ae}),await bt(H)},[de,pe,bt,nt,ye]),it=k.useCallback(async(H,se,ue="page")=>{const we=`page:${H}:${ue}`,Ae=(m.current.get(we)??0)+1;m.current.set(we,Ae);for(const me of Sx){if(me&&await bx(me),m.current.get(we)!==Ae)return;const Fe=await Ke(H,!1);if(Fe&&se(Fe))return}},[Ke]),Ct=k.useCallback(async(H,se)=>{const ue=`file:${H}`,we=(m.current.get(ue)??0)+1;m.current.set(ue,we);for(const Ae of Sx)if(Ae&&await bx(Ae),m.current.get(ue)!==we||(await nt(H,!1))?.some(Fe=>Fe.wire_id===se))return},[nt]),dn=k.useRef(!1);k.useEffect(()=>{if(!O||!t.loaded)return;const H=decodeURIComponent(window.location.hash.slice(Tx.length)),se=ri(c.current);if(!H||!se){Z(!1);return}if(sr(c.current,se)?.messages.some(ue=>ue.wire_id===H)){Z(!1);return}dn.current||(dn.current=!0,it(se,ue=>ue.messages.some(we=>we.wire_id===H),`anchor:${H}`).catch(()=>{}).finally(()=>Z(!1)))},[O,it,t.loaded,t.pages]),k.useMemo(()=>(jA({url:H=>Object.values(S.current).flat().find(ue=>ue.wire_id===H)?.available?qe.mediaUrl(H):null,bytes:async H=>{if(!Object.values(S.current).flat().find(we=>we.wire_id===H)?.available)return null;const ue=await fetch(qe.mediaUrl(H),{cache:"no-store",credentials:"same-origin"});if(!ue.ok)throw new Error(`Media request failed (HTTP ${ue.status})`);return new Uint8Array(await ue.arrayBuffer())},fetch:async H=>{const se=Object.values(S.current).flat().find(ue=>ue.wire_id===H);if(!se)throw new Error("Media record is unavailable");await qe.fetchFiles([H]),await nt(se.contact_id)}}),null),[nt]),k.useEffect(()=>{let H;g2(ue=>{te(ue),nv(ue.registration).then(Ce).catch(()=>Ce(we=>({...we,status:"error"})))},{shouldDeferReload:()=>B.current||_.current!==null}).then(ue=>{H=ue}).catch(ye);const se=ue=>{ue.preventDefault(),fe(ue)};return window.addEventListener("beforeinstallprompt",se),()=>{H?.(),window.removeEventListener("beforeinstallprompt",se)}},[ye]),k.useEffect(()=>C2(),[]),k.useEffect(()=>{if(!(!J.registration||ge.status!=="on"))return a2({registration:J.registration,identity:qe.identity,onEvent:d0})},[ge.status,ge.bindingId,J.registration]),k.useEffect(()=>{const H=()=>Ce(se=>({...se,status:"error"}));return window.addEventListener("ours-push-repair-required",H),()=>window.removeEventListener("ours-push-repair-required",H)},[]),k.useEffect(()=>{window.location.pathname==="/"&&window.history.replaceState(null,"",ni()),h.current=window.matchMedia("(min-width: 861px)");const H=()=>{const me=Gy(window.location.pathname);a.current?.abort(),l.current+=1,s(null),pe({type:"route",route:me}),P.current&&me.name==="chats"&&me.contactCid&&(P.current=!1,requestAnimationFrame(()=>document.querySelector("[data-contact-trigger]")?.focus({preventScroll:!0}))),me.name==="chats"&&me.contactCid&&Bt(me.contactCid)},se=()=>{if(document.visibilityState!=="visible")return;const me=ri(c.current);me&&bt(me),g0(),J.registration&&nv(J.registration).then(Ce).catch(()=>Ce(Fe=>({...Fe,status:"error"})))};window.addEventListener("popstate",H),document.addEventListener("visibilitychange",se);const ue=me=>{const Fe=me.type==="sync_required"?`${me.type}:${me.reason}`:me.type==="receipt_received"?`${me.type}:${me.contact_id}:${me.kind}:${me.wire_ids.join(",")}`:`${me.type}:${me.contact_id}:${me.wire_id}`,dt=Date.now(),Et=p.current.get(Fe)??0;p.current.set(Fe,dt);for(const[yt,vt]of p.current)dt-vt>6e4&&p.current.delete(yt);dt-Et<6e4||(async()=>{if(me.type==="sync_required"){await ut();return}if(St().catch(ye),me.type==="file_received"){await Ct(me.contact_id,me.wire_id);const yt=c.current.contacts.contacts.find(vt=>vt.container_id===me.contact_id);ri(c.current)!==me.contact_id&&yt&&ee(me.contact_id,Ml(yt),"New file");return}if(me.type==="message_received"){const yt=c.current.contacts.contacts.find(vt=>vt.container_id===me.contact_id);await it(me.contact_id,vt=>vt.messages.some(ht=>ht.wire_id===me.wire_id),`message:${me.wire_id}`),ri(c.current)===me.contact_id?await bt(me.contact_id):yt&&ee(me.contact_id,Ml(yt),"New message");return}pe({type:"receipt",contactCid:me.contact_id,kind:me.kind,wireIds:me.wire_ids}),await it(me.contact_id,yt=>me.wire_ids.every(vt=>{const ht=yt.messages.find(cr=>cr.wire_id===vt);return!!ht?.receipt&&Cx[ht.receipt]>=Cx[me.kind]}),`receipt:${me.wire_ids.join(",")}`)})().catch(ye)},we=r2(ue),Ae=i2(ue,me=>pe({type:"connection",connection:me}));return ut().then(me=>{me&&Bt(me)}),()=>{Ae(),we(),window.removeEventListener("popstate",H),document.removeEventListener("visibilitychange",se)}},[it,Ct,pe,bt,Bt,ee,St,ut,ye,J.registration]);const Mt=(H,se,ue)=>{window.history.pushState({oursMessenger:!0},"",se),pe({type:"route",route:H,mobileDetailOpen:ue})},rn=async H=>{Mt({name:"chats",contactCid:H},ni(H),!0),await Bt(H)},Cn=async H=>{const se=sr(c.current,H);if(!(!se?.nextBefore||C.current.has(H))){C.current.add(H),T(H);try{const ue=await qe.conversation(H,se.nextBefore);pe({type:"older_page",contactCid:H,page:ue,newer:se.messages})}catch(ue){ye(ue)}finally{C.current.delete(H),T(null)}}},Be=ri(t),On=t.contacts.contacts.find(H=>H.container_id===Be),V=k.useMemo(()=>_z(t,y),[t,y]),D=V.find(H=>H.id===Be)??null,q=Be?Qk(sr(t,Be),y[Be]??[]):[],he=t.identity,Re=t.loaded?Be&&!sr(t,Be)||O?"updating":t.connection!=="live"?"connecting":null:"connecting",Oe=async(H,se=ge.preview)=>{if(J.registration){ae(!0),Ce(ue=>({...ue,status:"repairing",preview:se}));try{Ce(await(H==="enable"?m0(J.registration,{preview:se}):H==="repair"?S2(J.registration,se):b2(J.registration,ge)))}catch(ue){Ce(we=>({...we,status:"error"})),ye(ue)}finally{ae(!1)}}},Ie=()=>{X([]),A("invite"),qe.invites().then(X).catch(ye)};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:()=>Mt({name:"chats",contactCid:null},ni()),children:"Open chats"})]}):he?v.jsx("div",{className:j?"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(uz,{contacts:V,roots:Dz(t.contacts),selected:Be,onSelect:H=>{H.startsWith("pending:")||rn(H)},onInvite:Ie,onSettings:()=>A("settings"),onApprovePending:async H=>{try{return await qe.respondToIntroduction(H,"approve"),await ut(),!0}catch(se){return ye(se),!1}},onRejectPending:async H=>{try{return await qe.respondToIntroduction(H,"reject"),await ut(),!0}catch(se){return ye(se),!1}}}),t.route.name==="contact"&&D?v.jsx(cz,{contact:D,messages:q,onBack:()=>{P.current=!0,f2(window.history.state)==="back"?window.history.back():(window.history.replaceState({oursMessenger:!0},"",ni(D.id)),pe({type:"route",route:{name:"chats",contactCid:D.id},mobileDetailOpen:!0}),requestAnimationFrame(()=>document.querySelector("[data-contact-trigger]")?.focus({preventScroll:!0})),P.current=!1)},onRename:H=>void qe.renameContact(D.id,H).then(ut).catch(ye),onRemove:()=>{confirm(`Remove “${On?.name??"contact"}”?`)&&qe.removeContact(D.id).then(()=>(window.history.replaceState({oursMessenger:!0},"",ni()),pe({type:"route",route:{name:"chats",contactCid:null},mobileDetailOpen:!1}),ut())).catch(ye)},onOpenMessage:H=>{Mt({name:"chats",contactCid:D.id},ni(D.id),!0);let se=12;const ue=()=>{const we=document.getElementById(`chat-message-${encodeURIComponent(H)}`),Ae=we?.closest(".messages");if((!we||!Ae||Ae.clientHeight<=0)&&se-- >0){requestAnimationFrame(ue);return}if(!we||!Ae)return;const me=we.getBoundingClientRect(),Fe=Ae.getBoundingClientRect(),dt=Ae.scrollTop+me.top-Fe.top-Math.max(0,(Ae.clientHeight-me.height)/2),Et=Math.max(0,Math.min(dt,Ae.scrollHeight-Ae.clientHeight));Ae.scrollTo({top:Et,behavior:window.matchMedia("(prefers-reduced-motion: reduce)").matches?"auto":"smooth"})};requestAnimationFrame(ue)},indexOffset:sr(t,D.id)?.hasMore?Math.max(1,(sr(t,D.id)?.total??q.length)-q.length):0,onSendText:async(H,se)=>{const ue=await qe.send(D.id,H,se);return await Ke(D.id,!1),ue.wire_id??void 0},onSendFile:async(H,se)=>{await qe.sendFile(D.id,new Blob([H.bytes],{type:H.mime}),H.filename,H.mime,se),await Promise.all([nt(D.id),Ke(D.id,!1)])}}):v.jsx(fz,{contact:D,messages:q,syncing:Re,unreadOpen:i?.contactCid===Be?i:null,hiddenEarlier:sr(t,Be??"")?.hasMore?Math.max(1,(sr(t,Be??"")?.total??q.length)-q.length):0,onLoadEarlier:Be&&E!==Be?()=>void Cn(Be):void 0,onBack:()=>{a.current?.abort(),l.current+=1,s(null),Mt({name:"chats",contactCid:null},ni(),!1)},onOpenContact:()=>{Be&&Mt({name:"contact",contactCid:Be},c2(Be),!0)},onDraftChange:Pe,onSend:async(H,se,ue)=>{if(!Be)return;const we=Be,Ae=await qe.send(we,H,se,ue);return pe({type:"sent_message",contactCid:we,message:{dir:"out",text:H,date:new Date().toISOString(),read:!0,wire_id:Ae.wire_id??"",receipt:null,reply_to:se?{wire_id:se}:null}}),Ae.wire_id?it(we,me=>me.messages.some(Fe=>Fe.wire_id===Ae.wire_id),`send:${Ae.wire_id}`):St().catch(ye),Ae.wire_id??void 0},onSendFile:async(H,se)=>{Be&&(await qe.sendFile(Be,new Blob([H.bytes],{type:H.mime}),H.filename,H.mime,se),await Promise.all([nt(Be),Ke(Be,!1)]))},onFetchFile:async H=>{await qe.fetchFiles([H]),Be&&await nt(Be)}},Be??"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(xz,{items:M,onDismiss:ce,onOpen:H=>void rn(H)})]}),R==="invite"&&v.jsx(Sz,{identity:he,invites:I,onRefresh:async()=>X(await qe.invites()),onCreate:async(H,se)=>(await qe.createInvite(H,se)).blob,onAccept:async(H,se)=>{await qe.addContact(H,se),await ut()},onRevoke:async H=>{await qe.revokeInvite(H)},onClose:()=>{A(null),ut()}}),R==="settings"&&v.jsx(bz,{identity:he,push:ge,workerSupported:J.supported,busy:Y,offline:J.offline,updateAvailable:J.updateAvailable,build:$,dark:j,onToggleDark:()=>Q(H=>(localStorage.setItem(Ex,H?"0":"1"),!H)),onSaveBio:async H=>{await qe.setBio(H),await ut()},onPushAction:Oe,onInstall:U?()=>void U.prompt().then(()=>fe(null)):void 0,onReloadUpdate:()=>{J.registration&&ev(J.registration)},onClose:()=>{_.current=null,A(null),Be&&bt(Be)}}),t.error&&v.jsxs("div",{className:"banner error",role:"alert","aria-live":"assertive",children:[t.error,v.jsx("button",{className:"linkbtn",onClick:()=>pe({type:"error",message:null}),children:"dismiss"})]})]})}):v.jsx("div",{className:j?"theme-dark":"",style:{height:"100%"},children:v.jsx("div",{className:"centered-screen",children:v.jsx("p",{className:"muted",children:"Loading…"})})})}jz();const Zk=document.getElementById("root");if(!Zk)throw new Error("missing #root");tC.createRoot(Zk).render(v.jsx(ZP,{reducedMotion:"user",children:v.jsx(Lz,{})}));export{Ch as _,jd as g};
|
|
322
|
-
//# sourceMappingURL=index-
|
|
321
|
+
`)}).join("")}function GF({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 QF=[Vk],ZF={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:GF,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>qF?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:QF,components:ZF,urlTransform:i=>Hk(i)??"",children:YF(t)})})}),yl={type:"spring",stiffness:430,damping:38,mass:.72},vx=10,qk=56,JF=18,ez=650;function tz(e,t){return Math.abs(e)<vx&&Math.abs(t)<vx?"pending":Math.abs(e)>Math.abs(t)&&e>0?"drag":"reject"}function nz(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 rz(e,t){const n=nz(t);return n>=0&&(e>=qk||e>=JF&&n>=ez)}const Md="ours.chats.listMode",cs="recent";function Xk(){try{return globalThis.localStorage}catch{return}}function iz(e=Xk()){try{return e?.getItem(Md)==="identity"?"identity":cs}catch{return cs}}function oz(e,t=Xk()){const n=e==="identity"?"identity":cs;try{return t?.setItem(Md,n),t?.getItem(Md)===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 sz(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(sz)}function xx(e){return e.contacts.length>0?Rl(Ss(e.contacts[0].activityAt)):0}function az(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 lz=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 uz(e){const{contacts:t,roots:n,selected:i}=e,[s,l]=k.useState(""),[a,c]=k.useState(()=>iz()),d=C=>C.name.toLowerCase().includes(s.toLowerCase()),h=t.filter(C=>C.status!=="pending"&&d(C)),m=t.filter(C=>C.status==="pending"&&d(C)),p=Nd(h),y=az(h,n),w=h.length===0&&m.length===0,S=C=>{c(oz(C))},E=[{id:"recent",label:"Recent"},{id:"identity",label:"By identity"}],T=(C,R)=>{if(!["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End"].includes(C.key))return;C.preventDefault();const _=C.key==="Home"?"recent":C.key==="End"||R==="recent"?"identity":"recent";S(_),document.getElementById(`conversation-list-${_}`)?.focus()};return v.jsxs("div",{className:"listcol",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.jsxs("button",{className:"btn sm primary",onClick:e.onInvite,children:[v.jsx(be,{name:"invite",size:15}),"Invite"]}),v.jsxs("button",{className:"btn sm",onClick:e.onSettings,children:[v.jsx(be,{name:"settings",size:15}),"Settings"]})]})]}),v.jsxs("div",{className:"search",children:[v.jsx(be,{name:"search"}),v.jsx("input",{className:"field",placeholder:"Search people, agents, apps…",value:s,onChange:C=>l(C.target.value)})]}),v.jsx("div",{className:"conversation-list-modes",role:"tablist","aria-label":"Conversation list layout",children:E.map(C=>v.jsx("button",{id:`conversation-list-${C.id}`,type:"button",role:"tab","aria-selected":a===C.id,"aria-controls":"conversation-list-panel",tabIndex:a===C.id?0:-1,className:a===C.id?"active":"",onClick:()=>S(C.id),onKeyDown:R=>T(R,C.id),children:C.label},C.id))})]}),v.jsxs("div",{id:"conversation-list-panel",className:"listcol-scroll",role:"tabpanel","aria-labelledby":`conversation-list-${a}`,children:[a==="recent"&&p.length>0&&v.jsx("div",{className:"conversation-group",children:p.map(C=>v.jsx(Ef,{c:C,active:i===C.id,onClick:()=>e.onSelect(C.id)},C.id))}),a==="identity"&&y.map(C=>v.jsxs("div",{children:[v.jsxs("div",{className:"group-label",title:C.note,children:[C.rootId&&v.jsx(be,{name:"clusters"}),v.jsx("span",{children:C.label}),C.note&&v.jsxs("span",{className:"gl-note",children:["· ",C.note]})]}),v.jsx("div",{className:"conversation-group",children:C.contacts.map(R=>v.jsx(Ef,{c:R,grouped:C.rootId!==null,active:i===R.id,onClick:()=>e.onSelect(R.id)},R.id))})]},C.id)),m.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:m.map(C=>v.jsx(Ef,{c:C,active:!1,onClick:()=>{},onApprove:()=>e.onApprovePending(C.id.slice(8)),onReject:()=>e.onRejectPending(C.id.slice(8))},C.id))})]}),w&&v.jsx("p",{className:"muted",style:{padding:"14px 10px",fontSize:"0.85rem"},children:"No contacts yet — share an invite to start."})]})]})}function cz(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(be,{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(be,{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(be,{name:"paperclip"}),"Shared photos, files, and links"]}),v.jsx(be,{name:"chevron"})]}),v.jsxs("button",{type:"button",onClick:()=>{h.current=!1,s(e.contact.name),n(!0)},children:[v.jsxs("span",{children:[v.jsx(be,{name:"edit"}),"Rename contact"]}),v.jsx(be,{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(be,{name:"copy",size:14}),"Copy identity"]})]}),v.jsxs("button",{type:"button",className:"contact-remove",onClick:e.onRemove,children:[v.jsx(be,{name:"trash"}),"Remove contact"]})]}),l&&v.jsx(DF,{messages:e.messages,indexOffset:e.indexOffset,onClose:()=>a(!1),onJump:e.onOpenMessage,onPreview:p=>{a(!1),d(p)}}),c&&(Ms(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=R=>{const A=l.current,_=a.current,B=Yk();if(A&&(A.style.transform=R&&!B?`translateX(${R}px)`:""),_){const I=Math.min(1,Math.abs(R)/h);_.style.opacity=String(I),_.style.transform=B?"scale(1)":`scale(${.5+.5*I})`}},S=(R,A)=>{const _=y.current;if(_.id!==R)return;const B=A&&_.mode==="drag"&&rz(_.distance,_.samples);y.current=p(),l.current?.classList.remove("swiping"),a.current?.classList.remove("armed"),w(0);const I=s.current;I?.hasPointerCapture?.(R)&&I.releasePointerCapture(R),B&&c.current()};k.useEffect(()=>{const R=s.current;if(!R)return;const A=_=>S(_.pointerId,!1);return R.addEventListener("lostpointercapture",A),()=>{R.removeEventListener("lostpointercapture",A);const _=y.current.id;_!==-1&&S(_,!1)}},[]);const E=R=>{const A=R.target,_=window.getSelection?.();!n||!R.isPrimary||R.pointerType==="mouse"||R.button!==0||y.current.id!==-1||_&&!_.isCollapsed||A.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:R.pointerId,x0:R.clientX,y0:R.clientY,mode:"maybe",armed:!1,distance:0,samples:[{x:R.clientX*d,time:R.timeStamp}]},w(0))},T=R=>{const A=y.current;if(A.id!==R.pointerId||A.mode==="idle")return;const _=R.clientX-A.x0,B=R.clientY-A.y0,I=window.getSelection?.();if(I&&!I.isCollapsed){S(R.pointerId,!1);return}if(A.mode==="maybe"){const Q=tz(_*d,B);if(Q==="pending")return;if(Q==="drag")A.mode="drag",R.currentTarget.setPointerCapture?.(R.pointerId),l.current?.classList.add("swiping");else{A.mode="idle";return}}R.preventDefault();const X=R.timeStamp;A.samples.push({x:R.clientX*d,time:X}),A.samples=A.samples.filter(Q=>X-Q.time<=120);let $=_*d;$<0&&($=0),$>h&&($=h+($-h)*.35),$=Math.min($,m),A.distance=$;const G=$*d,j=Math.abs(G)>=h;j!==A.armed&&(A.armed=j,a.current?.classList.toggle("armed",j),j&&navigator.vibrate?.(10)),w(G)},C=R=>{const A=y.current;A.id===R.pointerId&&A.mode==="drag"&&(A.samples.push({x:R.clientX*d,time:R.timeStamp}),A.distance=Math.max(0,(R.clientX-A.x0)*d),A.armed=A.distance>=h),S(R.pointerId,!0)};return v.jsxs("div",{ref:s,className:"msg-row "+(e.rowClass??t),style:n?{touchAction:"pan-y"}:void 0,onPointerDown:E,onPointerMove:T,onPointerUp:C,onPointerCancel:R=>S(R.pointerId,!1),onLostPointerCapture:R=>S(R.pointerId,!1),children:[n&&v.jsx("span",{className:"swipe-cue",ref:a,"aria-hidden":!0,children:v.jsx(be,{name:"reply",size:16})}),v.jsx("div",{className:"bubble-wrap",ref:l,children:e.children}),e.after]})}function fz(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),[E,T]=k.useState(null),[C,R]=k.useState(!1),[A,_]=k.useState(!1),[B,I]=k.useState(!1),[X,$]=k.useState(null),G=k.useRef(null),j=k.useRef(null),Q=k.useRef(!1),U=k.useRef(null),fe=k.useRef(!1),[J,te]=k.useState(!1),[ge,Ce]=k.useState(0),Y=k.useRef(null),ae=k.useRef(!0),P=k.useRef(null),O=k.useRef(0),Z=k.useRef(null),M=k.useRef(new Map),ee=k.useRef(0),ce=k.useRef(null),de=k.useRef(null),pe=k.useRef(0),Pe=k.useRef(null);k.useEffect(()=>{s(""),m(null),y(null),d(null),S(null),T(null),R(!1),_(!1),I(!1),O.current+=1,$(null),M.current.clear(),ce.current=null,de.current=null},[t?.id]),k.useEffect(()=>{if(!p)return;const V=p.reply?.wireId;n.some(q=>q.kind!=="file"&&q.dir==="out"&&!!q.wireId&&!p.wireIds.has(q.wireId)&&q.text===p.text&&(q.replyTo?.wireId??void 0)===V)&&(y(null),m(null),s(q=>q===p.draft?"":q),S(q=>q===p.reply?null:q))},[n,p]);const ye=!!c?.wireId&&n.some(V=>V.wireId===c.wireId),De=k.useMemo(()=>c&&!ye?[...n,c.message]:n,[n,c,ye]);k.useEffect(()=>{ye&&d(null)},[ye]),k.useLayoutEffect(()=>{const V=j.current;if(!V)return;V.style.height="0px";const D=Math.max(44,Math.min(V.scrollHeight,132));V.style.height=`${D}px`,V.style.overflowY=V.scrollHeight>132?"auto":"hidden"},[i,t?.id]);const Ke=V=>{const D=U.current;if(!D)return;const q=Math.max(0,D.scrollHeight-D.clientHeight);if(Math.abs(D.scrollTop-q)<1){ce.current=null,de.current=null;return}const he=V&&!Yk();ce.current=he?q:null,de.current=he?D.scrollTop:null,he?D.scrollTo({top:q,behavior:"smooth"}):D.scrollTop=q},nt=()=>{Y.current===null&&(Y.current=requestAnimationFrame(()=>{Y.current=null;const V=U.current;if(!V)return;const D=V.scrollHeight-V.clientHeight-V.scrollTop>48;te(D),D||Ce(0)}))};k.useLayoutEffect(()=>{if(!t){P.current=null,ae.current=!0,pe.current=0;return}const V=U.current;if(!V)return;const D=P.current!==t.id,q=pe.current,he=De.length!==q,Re=De.at(-1),Oe=Re?Re.wireId||`${Re.date}:${Re.text}`:null,Ie=Pe.current;if(pe.current=De.length,Pe.current=Oe,!D&&!he&&ce.current===null&&(ae.current=V.scrollHeight-V.clientHeight-V.scrollTop<=48),D||ae.current)Ke(he&&!D&&P.current!==null),ae.current=!0;else if(he&&De.length>q&&Oe!==Ie){const H=Ie===null?-1:De.findIndex(se=>(se.wireId||`${se.date}:${se.text}`)===Ie);Ce(se=>se+Math.max(1,De.length-Math.max(0,H+1)))}P.current=t.id,nt()},[t,De.length]),k.useLayoutEffect(()=>{if(fe.current||!e.unreadOpen||window.location.hash.startsWith("#chat-message-"))return;const V=U.current,D=document.getElementById(`unread-${wx(e.unreadOpen.wireId)}`);!V||!D||(V.scrollTop=Math.max(0,D.offsetTop-16),ae.current=!1,fe.current=!0,nt())},[e.unreadOpen,De.length]),k.useLayoutEffect(()=>{const V=window.location.hash;if(!V.startsWith("#chat-message-"))return;const D=document.getElementById(V.slice(1));D&&(D.scrollIntoView({block:"center"}),ae.current=!1)},[t?.id,De.length]),k.useLayoutEffect(()=>{const V=Z.current,D=U.current;if(V===null||!D)return;const q=requestAnimationFrame(()=>{Z.current===V&&(D.scrollTop=V.top+D.scrollHeight-V.height,Z.current=null)});return()=>cancelAnimationFrame(q)},[De.length]),k.useEffect(()=>{const V=U.current;if(!V||typeof ResizeObserver>"u")return;const D=V.firstElementChild;if(!D)return;const q=new ResizeObserver(()=>{ae.current&&Ke(ce.current!==null),nt()});return q.observe(D),q.observe(V),()=>{q.disconnect(),Y.current!==null&&cancelAnimationFrame(Y.current)}},[t?.id]);const St=async V=>{const D=++O.current;m(null),I(!0);try{if(V.size>ts&&Wk(V.type,V.name)){const he=await KF(V,ts);if(D!==O.current)return;T({filename:he.filename,mime:he.mime,bytes:he.bytes,originalSize:he.originalSize});return}if(V.size>ts){m(`"${V.name}" is ${Fr(V.size)} — files up to ${Fr(ts)} can be sent.`);return}const q=await V.arrayBuffer();if(D!==O.current)return;T({filename:V.name||"file",mime:V.type||"application/octet-stream",bytes:new Uint8Array(q)})}catch(q){D===O.current&&m(`Photo optimization failed: ${q instanceof Error?q.message:String(q)}`)}finally{D===O.current&&I(!1)}},ut=()=>{!E||!e.onSendFile||A||(_(!0),e.onSendFile(E,w?.wireId).then(()=>{T(null),S(null)}).catch(V=>m(`File send failed: ${String(V)} — it was not delivered.`)).finally(()=>_(!1)))},bt=e.onDraftChange;k.useEffect(()=>(bt?.(i.trim().length>0||l),()=>bt?.(!1)),[i,l,bt]);const Bt=new Map;for(const V of De)V.wireId&&Bt.set(V.wireId,V);const it=k.useMemo(()=>{const V=new Map;for(const D of De)V.set(D,D.kind==="file"?null:D.dir==="in"?yA(t?.announcedName??"",D.text):null);return V},[De,t?.announcedName]),Ct=V=>it.get(V)??null,dn=V=>{if(V.dir==="out")return"You";const D=Ct(V);return D&&D.variant==="chat"?D.author:t?.name??"Them"},Mt=V=>{if(V.kind==="file")return V.mime?.startsWith("image/")?"Photo":eo(V.mime??"",V.filename??"")?"Voice message":V.filename||"File";const D=Ct(V);return D?D.text||CA(D):V.text},rn=V=>{if(!V.replyTo)return null;const D=Bt.get(V.replyTo.wireId);return D?{author:dn(D),text:Mt(D)}:{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(be,{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 Cn=async()=>{const V=i,D=V.trim(),q=!!p&&V===p.draft&&(w?.wireId??void 0)===p.reply?.wireId;if(!D||Q.current||q)return;p&&y(null),Q.current=!0,a(!0),m(null);const he=w,Re=he?.wireId,Oe=new AbortController;let Ie=!1,H=0;s(""),S(null);const se=`optimistic-${++ee.current}`;d({key:se,wireId:null,message:{dir:"out",text:D,date:new Date().toISOString(),read:!0,wireId:"",replyTo:Re?{wireId:Re}:null}});try{const ue=await Promise.race([e.onSend(D,Re,Oe.signal),new Promise((we,Ae)=>{H=window.setTimeout(()=>{Ie=!0,Oe.abort(),Ae(new Error("send timeout"))},lz)})]);ue?(M.current.set(ue,se),d(we=>we?.key===se?{...we,wireId:ue}:we)):d(we=>we?.key===se?null:we),y(null)}catch(ue){d(null),s(we=>we===""?V:we),S(we=>we===null?he:we),Ie||!(ue instanceof Qf)?(y({draft:V,text:D,reply:he,wireIds:new Set(n.flatMap(we=>we.wireId?[we.wireId]:[]))}),m(`${Ie?"Send timed out":"Send connection was interrupted"} — delivery status is unknown. Check the conversation; edit the draft before sending again.`)):m(`Send failed: ${String(ue)} — the message was not delivered.`)}finally{window.clearTimeout(H),Q.current=!1,a(!1)}},Be=!!p&&i===p.draft&&(w?.wireId??void 0)===p.reply?.wireId,On=V=>{V.wireId&&S({wireId:V.wireId,author:dn(V),text:Mt(V)})};return v.jsxs("div",{className:"detail detail-chat",children:[v.jsx("div",{className:"detail-head",children:v.jsxs("div",{className:"conv-peer",children:[v.jsx("button",{className:"icon-btn detail-back",onClick:e.onBack,children:v.jsx(be,{name:"back"})}),v.jsxs("button",{type:"button",className:"conv-contact-trigger","data-contact-trigger":!0,onClick:e.onOpenContact,disabled:!e.onOpenContact,"aria-label":`Open contact details for ${t.name}`,children:[v.jsx("span",{className:"avatar accent",children:t.initials}),v.jsxs("span",{className:"conv-peer-meta",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(be,{name:"lock",size:11}),"Encrypted connection"]})]})]})]})}),v.jsx("div",{className:"messages",ref:U,tabIndex:-1,"aria-label":"Conversation timeline",onScroll:V=>{const D=V.currentTarget,q=D.scrollHeight-D.clientHeight-D.scrollTop;if(ce.current!==null){const he=de.current;if(he===null||D.scrollTop>=he-1){de.current=D.scrollTop,q<=4&&(ce.current=null,de.current=null);return}ce.current=null,de.current=null}ae.current=q<=48,nt()},onPointerDown:()=>{ce.current=null,de.current=null},onTouchStart:()=>{ce.current=null,de.current=null},onWheel:()=>{ce.current=null,de.current=null},onDragOver:V=>{e.onSendFile&&V.preventDefault()},onDrop:V=>{if(!e.onSendFile)return;V.preventDefault();const D=V.dataTransfer.files?.[0];D&&St(D)},children:v.jsxs("div",{className:"messages-inner",children:[v.jsxs("div",{className:"e2e-note",children:[v.jsx(be,{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:()=>{ae.current=!1;const V=U.current;Z.current=V?{height:V.scrollHeight,top:V.scrollTop}:null,e.onLoadEarlier?.()},children:["Load earlier messages (",e.hiddenEarlier," remaining)"]}),v.jsx(qP,{initial:!1,children:De.map((V,D)=>{const q=V===c?.message?c.key:V.wireId&&M.current.get(V.wireId)||V.wireId||`${V.date}-${(e.hiddenEarlier??0)+D}`,he=wx(V.wireId||q),Re=De[D-1],Oe=De[D+1],Ie=Ct(V),H=dt=>{if(!dt)return null;const Et=Ct(dt);return Et?Et.variant==="system"?"room:system":`room:chat:${Et.author}${Et.role}`:dt.dir},se=H(V),ue=!!Re&&H(Re)===se&&se!=="room:system",we=!!Oe&&H(Oe)===se&&se!=="room:system",Ae=(V.dir==="out"?"out":"in")+(ue?" cont-top":"")+(we?" cont-bot":""),me=V.wireId?v.jsx("button",{className:"msg-reply",title:"Reply",onClick:()=>On(V),children:v.jsx(be,{name:"reply",size:15})}):null;if(Ie&&Ie.variant==="system"){const dt=Ie.presentation??"system";return v.jsxs(ss.div,{className:"message-motion",id:he,initial:{opacity:0,y:8},animate:{opacity:1,y:0},exit:{opacity:0},transition:yl,children:[V.wireId===e.unreadOpen?.wireId&&v.jsx("div",{id:`unread-${he}`,className:"unread-divider",role:"separator",children:v.jsx("span",{children:"Unread messages"})}),v.jsxs("div",{className:`room-system room-${dt}-card`,role:"note",children:[Ie.label&&v.jsx("span",{className:"room-system-label",children:Ie.label}),Ie.roomName&&v.jsx("strong",{className:"room-card-name",children:Ie.roomName}),v.jsx(yx,{text:Ie.text,className:"room-system-text message-markdown"}),!!Ie.details?.length&&v.jsx("ul",{className:"room-card-details","aria-label":"Room event details",children:Ie.details.map(Et=>v.jsx("li",{children:Et},Et))}),v.jsxs("span",{className:"room-card-provenance",children:[Ie.authoredBy&&v.jsx("span",{className:"room-card-author",children:Ie.authoredBy}),v.jsx("span",{className:"room-system-at",children:ys(Ie.authoredAt||V.date)})]})]})]},q)}if(V.kind==="file"){const dt=S0(V.wireId)??{id:V.wireId,dir:V.dir,filename:V.filename??"file",mime:V.mime??"application/octet-stream",size:0,date:V.date};return v.jsxs(ss.div,{className:"message-motion",id:he,initial:{opacity:0,y:12,scale:.985},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,scale:.98},transition:yl,children:[V.wireId===e.unreadOpen?.wireId&&v.jsx("div",{id:`unread-${he}`,className:"unread-divider",role:"separator",children:v.jsx("span",{children:"Unread messages"})}),v.jsx(kx,{dir:V.dir==="out"?"out":"in",rowClass:Ae,canReply:!!V.wireId,onReply:()=>On(V),after:me,children:v.jsx("div",{className:`ours-message ours-message-file ours-message--${V.dir}`,children:v.jsx(PD,{rec:dt,receipt:V.receipt,receiptless:V.receiptless,onPreview:$,onFetch:e.onFetchFile})})})]},q)}const Fe=rn(V);return v.jsxs(ss.div,{className:"message-motion",id:he,initial:{opacity:0,y:12,scale:.985},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,scale:.98},transition:yl,children:[V.wireId===e.unreadOpen?.wireId&&v.jsx("div",{id:`unread-${he}`,className:"unread-divider",role:"separator",children:v.jsx("span",{children:"Unread messages"})}),v.jsx(kx,{dir:V.dir==="out"?"out":"in",rowClass:Ae,canReply:!!V.wireId,onReply:()=>On(V),after:me,children:v.jsxs("div",{className:`ours-message ours-message--${V.dir}`,children:[Fe&&v.jsxs("div",{className:"quote",children:[Fe.author&&v.jsx("span",{className:"quote-author",children:Fe.author}),v.jsx("span",{className:"quote-text",children:Fe.text})]}),Ie&&!ue&&v.jsxs(v.Fragment,{children:[Ie.roomName&&v.jsx("div",{className:"room-message-room",children:Ie.roomName}),v.jsxs("div",{className:"room-author",children:[v.jsx("span",{className:"room-author-name",children:Ie.author}),Ie.role&&v.jsx("span",{className:"room-author-role",children:Ie.role})]})]}),v.jsx(yx,{text:Ie?Ie.text:V.text}),v.jsxs("div",{className:"bubble-at",children:[ys(Ie?.authoredAt||V.date),V.dir==="out"&&v.jsx(b0,{receipt:V.receipt,receiptless:V.receiptless})]})]})})]},q)})}),v.jsx("div",{className:"thread-end","aria-hidden":!0})]})},t.id),J&&v.jsxs("button",{type:"button",className:"jump-latest btn sm","aria-label":ge?`Jump to latest, ${ge} new messages`:"Jump to latest",onClick:V=>{const D=V.currentTarget===document.activeElement;Ce(0),Ke(!0),D&&requestAnimationFrame(()=>U.current?.focus({preventScroll:!0}))},children:[v.jsx("span",{children:"Jump to latest"}),!!ge&&v.jsx("span",{className:"jump-latest-count","aria-live":"polite",children:ge})]}),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 Cn(),children:"retry"})})]}),v.jsxs("div",{className:"composer-wrap",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(be,{name:"close",size:16})})]}),E&&v.jsx(w1,{att:E,sending:A,onSend:ut,onDiscard:()=>T(null)}),B&&v.jsx("div",{className:"attachment-processing",role:"status",children:"Optimizing photo for secure delivery…"}),v.jsxs("div",{className:"composer"+(C?" recording":""),children:[e.onSendFile&&v.jsxs(v.Fragment,{children:[v.jsx("input",{ref:G,type:"file",style:{display:"none"},onChange:V=>{const D=V.target.files?.[0];D&&St(D),V.target.value=""}}),v.jsx("button",{className:"icon-btn composer-tool",title:"Attach a file or photo",disabled:A||B||C,onClick:()=>G.current?.click(),children:v.jsx(be,{name:"paperclip",size:18})})]}),v.jsx("textarea",{ref:j,className:"field",rows:1,placeholder:(w?"Reply to "+w.author:"Message "+t.name)+"…",value:i,"aria-busy":l,onChange:V=>s(V.target.value),onKeyDown:V=>{V.key==="Enter"?!(window.matchMedia("(pointer: coarse)").matches||window.innerWidth<=860)&&!V.shiftKey&&(V.preventDefault(),Cn()):V.key==="Escape"&&S(null)}}),e.onSendFile&&!i.trim()&&!E&&!B&&!A?v.jsx(k1,{disabled:A||B||!!E,onReady:V=>{R(!1),T(V)},onError:V=>{R(!1),m(V)},onActiveChange:R},t.id):v.jsxs("button",{className:"btn primary","aria-label":"Send",onPointerDown:V=>{V.button===0&&document.activeElement===j.current&&V.preventDefault()},onClick:()=>void Cn(),disabled:l||Be||!i.trim(),title:Be?"Delivery status unknown — edit before sending again":void 0,children:[v.jsx(be,{name:"send",size:16}),v.jsx("span",{className:"btn-label",children:"Send"})]})]})]}),X&&(Ms(X.filename,X.mime)?v.jsx($k,{rec:X,onClose:()=>$(null)}):v.jsx(Bk,{rec:X,onClose:()=>$(null),onSendText:e.onSend,onSendFile:e.onSendFile}))]})}const Gk=3;function dz(e,t,n=Gk){return[t,...e.filter(i=>i.cid!==t.cid)].slice(0,n)}function hz(e,t){return e.filter(n=>n.id!==t)}const pz=6e3,mz=dz,gz=hz;function yz(){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=>mz(p,m,Gk))},[]),s=k.useCallback(a=>t(c=>gz(c,a)),[]),l=k.useCallback(a=>t(c=>c.filter(d=>d.cid!==a)),[]);return{toasts:e,push:i,dismiss:s,clear:l}}function vz(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),pz);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(be,{name:"close",size:15})})]})}function xz(e){return v.jsx(v.Fragment,{children:e.items.map(t=>v.jsx(vz,{item:t,onOpen:e.onOpen,onDismiss:e.onDismiss},t.id))})}function wz(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-D0w2D7AY.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 kz(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 E=n.current,T=E.getContext("2d"),C=()=>{if(l.current)if(S.readyState>=S.HAVE_ENOUGH_DATA){const R=S.videoWidth||320,A=S.videoHeight||240;E.width=R,E.height=A,T.drawImage(S,0,0,R,A);const _=T.getImageData(0,0,R,A);Ch(()=>import("./jsQR-DKYZJtWP.js").then(B=>B.j),[]).then(B=>{const I=B.default,X=I(_.data,_.width,_.height,{inversionAttempts:"dontInvert"});if(X&&X.data&&l.current){m(),e.onDecode(X.data);return}l.current&&(s.current=requestAnimationFrame(C))})}else s.current=requestAnimationFrame(C)};s.current=requestAnimationFrame(C)},[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(be,{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(be,{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(be,{name:"close",size:14}),"Cancel scan"]}):v.jsxs(v.Fragment,{children:[v.jsx(be,{name:"close",size:14}),"Close scanner"]})})]})}function Sz(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(""),[E,T]=k.useState(!1),[C,R]=k.useState(null),[A,_]=k.useState(null),[B,I]=k.useState(!1),[X,$]=k.useState(null),G=k.useRef(!1),j=async()=>{if(!G.current){G.current=!0,T(!0),_(null),R(null);try{m(i),d(await e.onCreate(i,i==="one_time"&&l.trim()||void 0))}catch(U){_(U instanceof Error?U.message:String(U))}finally{G.current=!1,T(!1)}}},Q=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:()=>{G.current||e.onClose()},tabs:Q,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:U=>a(U.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:E,onClick:()=>void j(),children:E?"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(U=>U.mode==="public").length===0&&v.jsx("p",{className:"muted",style:{margin:0},children:"None right now."}),e.invites.filter(U=>U.mode==="public").map(U=>v.jsxs("div",{"data-testid":"public-invite-row",style:{padding:"8px 10px",background:"var(--inset)",borderRadius:7},children:[v.jsx("span",{className:"mono",children:U.invite_id}),v.jsxs("p",{className:"muted",children:["Created ",U.created?RA(U.created):"unknown"," · Active until revoked · No expiry"]}),X===U.invite_id?v.jsxs("span",{children:[v.jsx("button",{className:"btn sm danger",onClick:()=>void e.onRevoke(U.invite_id).then(()=>($(null),e.onRefresh())).catch(fe=>_(String(fe))),children:"Confirm revoke"})," ",v.jsx("button",{className:"btn sm",onClick:()=>$(null),children:"Keep it"})]}):v.jsx("button",{className:"btn sm",onClick:()=>$(U.invite_id),children:"Revoke"})]},U.invite_id))]}),C&&v.jsx("p",{className:"muted",children:C}),A&&v.jsx("p",{className:"onb-error",children:A})]}),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:U=>U.currentTarget.select()}),h==="one_time"&&v.jsx(wz,{text:c}),v.jsxs("button",{className:"btn primary",onClick:()=>void navigator.clipboard.writeText(c).then(()=>R("Copied to clipboard.")),children:[v.jsx(be,{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"}),C&&v.jsx("p",{className:"muted",children:C})]}),t==="accept"&&v.jsxs("form",{style:{display:"flex",flexDirection:"column",gap:13},onSubmit:U=>{U.preventDefault(),!(!p.trim()||E)&&(T(!0),_(null),e.onAccept(p.trim(),w.trim()||void 0).then(()=>{R("Invite accepted — the contact will appear once the sender verifies your identity."),y(""),S("")}).catch(fe=>_(String(fe))).finally(()=>T(!1)))},children:[v.jsx("p",{className:"muted",children:"Paste the invite you received, or scan a QR code."}),B?v.jsx(kz,{onDecode:U=>{y(U),I(!1)},onClose:()=>I(!1)}):v.jsxs("button",{type:"button",className:"btn",onClick:()=>I(!0),children:[v.jsx(be,{name:"monitor",size:15}),"Scan QR code"]}),v.jsx("textarea",{className:"field mono","aria-label":"Invite",rows:5,value:p,onChange:U=>y(U.target.value),placeholder:"Paste invite text…"}),v.jsx("input",{className:"field",value:w,onChange:U=>S(U.target.value),placeholder:"Rename them (optional)",maxLength:64}),v.jsx("button",{className:"btn primary",type:"submit",disabled:E||!p.trim(),children:E?"Connecting…":"Add contact"}),C&&v.jsx("p",{className:"muted",children:C}),A&&v.jsx("p",{className:"onb-error",children:A})]})]})})}function bz(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=x2(),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 Cz(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 Ez="d2a52cbbd5c126ce99102f9dab82a41c470661cd",Tz=15*6e4,Pz=6e4,Rz=Cz;async function Az(){try{const e=await fetch("/version.json",{cache:"no-store"});return e.ok?await e.json():null}catch{return null}}function Mz(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 Az(),h=Rz(Ez,d,t,Date.now(),Pz);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(),Tz),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 Nz(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 jz(){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,Iz=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 Dz(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 _z(e,t){return[...e.contacts.contacts.map(i=>{const s=e.contacts.roots?.[i.container_id],l=sr(e,i.container_id),c=Qk(l,t[i.container_id]??[]).at(-1),d=Ml(i);return{id:i.container_id,name:d,announcedName:i.name,initials:rd(d),when:c?PA(c.date):"",activityAt:c?.date??"",last:c?.kind==="file"?LA(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=Ml(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 Lz(){return v.jsx(Oz,{})}function Oz(){const e=k.useRef(h2(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 u2),h=k.useRef(null),m=k.useRef(new Map),p=k.useRef(new Map),[y,w]=k.useState({}),S=k.useRef(y),[E,T]=k.useState(null),C=k.useRef(new Set),[R,A]=k.useState(null),_=k.useRef(R),B=k.useRef(!1),[I,X]=k.useState([]),[$,G]=k.useState(null),[j,Q]=k.useState(()=>localStorage.getItem(Ex)!=="0"),[U,fe]=k.useState(null),[J,te]=k.useState({supported:!1,offline:!navigator.onLine,updateAvailable:!1,registration:null}),[ge,Ce]=k.useState({status:"unsupported",preview:"full"}),[Y,ae]=k.useState(!1),P=k.useRef(!1),[O,Z]=k.useState(()=>window.location.hash.startsWith(Tx)),{toasts:M,push:ee,dismiss:ce,clear:de}=yz(),pe=k.useCallback(H=>{c.current=Jy(c.current,H),n(H)},[]),Pe=k.useCallback(H=>{B.current=H},[]);k.useEffect(()=>{c.current=t},[t]),_.current=R,S.current=y,k.useMemo(()=>(cv(Object.values(y).flat()),null),[y]),k.useEffect(()=>(document.documentElement.classList.toggle("theme-dark",j),()=>document.documentElement.classList.remove("theme-dark")),[j]);const ye=k.useCallback(H=>pe({type:"error",message:Iz(H)}),[pe]),De=k.useCallback(()=>{const H=c.current;return{visibility:document.visibilityState,appRoute:H.route.name==="chats"?"chats":"other",selectedContactCid:ri(H),desktopLayout:h.current?.matches??window.innerWidth>=861,mobileDetailOpen:H.mobileDetailOpen,conversationCoveringDialogOpen:_.current!==null}},[]),Ke=k.useCallback(async(H,se=!0)=>{try{const ue=await qe.conversation(H);return pe({type:"page",contactCid:H,page:ue}),ue}catch(ue){return se&&ye(ue),null}},[pe,ye]),nt=k.useCallback(async(H,se=!0)=>{try{const ue=await qe.files(H);return cv(ue.files),w(we=>({...we,[H]:ue.files})),ue.files}catch(ue){return se&&ye(ue),null}},[ye]);k.useEffect(()=>Mz({onUpdateAvailable:()=>te(H=>({...H,updateAvailable:!0})),onStuck:H=>{Nz(H)}}),[]);const St=k.useCallback(async()=>{const H=await qe.contacts();return pe({type:"contacts",contacts:{...H,pending:H.pending??[]}}),H},[pe]),ut=k.useCallback(async()=>{try{const[H,se,ue]=await Promise.all([qe.identity(),qe.contacts(),qe.buildInfo()]),we={...se,pending:se.pending??[]};return c.current.identity&&c.current.identity.cid!==H.cid&&(IA(),S.current={},w({})),pe({type:"snapshot",identity:H,contacts:we}),G(ue),await Promise.all(we.contacts.flatMap(Ae=>[Ke(Ae.container_id,!1),nt(Ae.container_id,!1)])),ri(c.current)}catch(H){return ye(H),null}},[pe,nt,Ke,ye]),bt=k.useCallback(async H=>{await d.current.request(H,async()=>{l2(H,De())&&(await qe.markRead(H),await Promise.all([Ke(H),St()]))}).catch(ye)},[De,St,Ke,ye]),Bt=k.useCallback(async H=>{const se=++l.current;a.current?.abort();const ue=new AbortController;a.current=ue,s(null),de(H),nt(H,!1);let we;try{we=await qe.conversation(H,void 0,ue.signal)}catch(ht){ue.signal.aborted||ye(ht);return}if(ue.signal.aborted||se!==l.current)return;pe({type:"page",contactCid:H,page:we});const Ae=we.unread;let me=[...we.messages],Fe=we.nextBefore;const dt=new Set,Et=new Set(me.map(ht=>ht.wire_id).filter(Boolean)),yt=()=>me.filter(ht=>ht.dir==="in"&&!ht.read);for(;yt().length<Ae&&Fe&&!dt.has(Fe);){dt.add(Fe);let ht;try{ht=await qe.conversation(H,Fe,ue.signal)}catch{break}if(ue.signal.aborted||se!==l.current)return;const cr=ht.messages.filter(fr=>!fr.wire_id||!Et.has(fr.wire_id));if(!cr.length&&ht.nextBefore===Fe)break;for(const fr of cr)fr.wire_id&&Et.add(fr.wire_id);me=[...cr,...me],pe({type:"older_page",contactCid:H,page:ht,newer:we.messages}),Fe=ht.nextBefore}const vt=yt()[0];vt?.wire_id&&se===l.current&&!ue.signal.aborted&&s({contactCid:H,wireId:vt.wire_id,count:Ae}),await bt(H)},[de,pe,bt,nt,ye]),it=k.useCallback(async(H,se,ue="page")=>{const we=`page:${H}:${ue}`,Ae=(m.current.get(we)??0)+1;m.current.set(we,Ae);for(const me of Sx){if(me&&await bx(me),m.current.get(we)!==Ae)return;const Fe=await Ke(H,!1);if(Fe&&se(Fe))return}},[Ke]),Ct=k.useCallback(async(H,se)=>{const ue=`file:${H}`,we=(m.current.get(ue)??0)+1;m.current.set(ue,we);for(const Ae of Sx)if(Ae&&await bx(Ae),m.current.get(ue)!==we||(await nt(H,!1))?.some(Fe=>Fe.wire_id===se))return},[nt]),dn=k.useRef(!1);k.useEffect(()=>{if(!O||!t.loaded)return;const H=decodeURIComponent(window.location.hash.slice(Tx.length)),se=ri(c.current);if(!H||!se){Z(!1);return}if(sr(c.current,se)?.messages.some(ue=>ue.wire_id===H)){Z(!1);return}dn.current||(dn.current=!0,it(se,ue=>ue.messages.some(we=>we.wire_id===H),`anchor:${H}`).catch(()=>{}).finally(()=>Z(!1)))},[O,it,t.loaded,t.pages]),k.useMemo(()=>(jA({url:H=>Object.values(S.current).flat().find(ue=>ue.wire_id===H)?.available?qe.mediaUrl(H):null,bytes:async H=>{if(!Object.values(S.current).flat().find(we=>we.wire_id===H)?.available)return null;const ue=await fetch(qe.mediaUrl(H),{cache:"no-store",credentials:"same-origin"});if(!ue.ok)throw new Error(`Media request failed (HTTP ${ue.status})`);return new Uint8Array(await ue.arrayBuffer())},fetch:async H=>{const se=Object.values(S.current).flat().find(ue=>ue.wire_id===H);if(!se)throw new Error("Media record is unavailable");await qe.fetchFiles([H]),await nt(se.contact_id)}}),null),[nt]),k.useEffect(()=>{let H;g2(ue=>{te(ue),nv(ue.registration).then(Ce).catch(()=>Ce(we=>({...we,status:"error"})))},{shouldDeferReload:()=>B.current||_.current!==null}).then(ue=>{H=ue}).catch(ye);const se=ue=>{ue.preventDefault(),fe(ue)};return window.addEventListener("beforeinstallprompt",se),()=>{H?.(),window.removeEventListener("beforeinstallprompt",se)}},[ye]),k.useEffect(()=>C2(),[]),k.useEffect(()=>{if(!(!J.registration||ge.status!=="on"))return a2({registration:J.registration,identity:qe.identity,onEvent:d0})},[ge.status,ge.bindingId,J.registration]),k.useEffect(()=>{const H=()=>Ce(se=>({...se,status:"error"}));return window.addEventListener("ours-push-repair-required",H),()=>window.removeEventListener("ours-push-repair-required",H)},[]),k.useEffect(()=>{window.location.pathname==="/"&&window.history.replaceState(null,"",ni()),h.current=window.matchMedia("(min-width: 861px)");const H=()=>{const me=Gy(window.location.pathname);a.current?.abort(),l.current+=1,s(null),pe({type:"route",route:me}),P.current&&me.name==="chats"&&me.contactCid&&(P.current=!1,requestAnimationFrame(()=>document.querySelector("[data-contact-trigger]")?.focus({preventScroll:!0}))),me.name==="chats"&&me.contactCid&&Bt(me.contactCid)},se=()=>{if(document.visibilityState!=="visible")return;const me=ri(c.current);me&&bt(me),g0(),J.registration&&nv(J.registration).then(Ce).catch(()=>Ce(Fe=>({...Fe,status:"error"})))};window.addEventListener("popstate",H),document.addEventListener("visibilitychange",se);const ue=me=>{const Fe=me.type==="sync_required"?`${me.type}:${me.reason}`:me.type==="receipt_received"?`${me.type}:${me.contact_id}:${me.kind}:${me.wire_ids.join(",")}`:`${me.type}:${me.contact_id}:${me.wire_id}`,dt=Date.now(),Et=p.current.get(Fe)??0;p.current.set(Fe,dt);for(const[yt,vt]of p.current)dt-vt>6e4&&p.current.delete(yt);dt-Et<6e4||(async()=>{if(me.type==="sync_required"){await ut();return}if(St().catch(ye),me.type==="file_received"){await Ct(me.contact_id,me.wire_id);const yt=c.current.contacts.contacts.find(vt=>vt.container_id===me.contact_id);ri(c.current)!==me.contact_id&&yt&&ee(me.contact_id,Ml(yt),"New file");return}if(me.type==="message_received"){const yt=c.current.contacts.contacts.find(vt=>vt.container_id===me.contact_id);await it(me.contact_id,vt=>vt.messages.some(ht=>ht.wire_id===me.wire_id),`message:${me.wire_id}`),ri(c.current)===me.contact_id?await bt(me.contact_id):yt&&ee(me.contact_id,Ml(yt),"New message");return}pe({type:"receipt",contactCid:me.contact_id,kind:me.kind,wireIds:me.wire_ids}),await it(me.contact_id,yt=>me.wire_ids.every(vt=>{const ht=yt.messages.find(cr=>cr.wire_id===vt);return!!ht?.receipt&&Cx[ht.receipt]>=Cx[me.kind]}),`receipt:${me.wire_ids.join(",")}`)})().catch(ye)},we=r2(ue),Ae=i2(ue,me=>pe({type:"connection",connection:me}));return ut().then(me=>{me&&Bt(me)}),()=>{Ae(),we(),window.removeEventListener("popstate",H),document.removeEventListener("visibilitychange",se)}},[it,Ct,pe,bt,Bt,ee,St,ut,ye,J.registration]);const Mt=(H,se,ue)=>{window.history.pushState({oursMessenger:!0},"",se),pe({type:"route",route:H,mobileDetailOpen:ue})},rn=async H=>{Mt({name:"chats",contactCid:H},ni(H),!0),await Bt(H)},Cn=async H=>{const se=sr(c.current,H);if(!(!se?.nextBefore||C.current.has(H))){C.current.add(H),T(H);try{const ue=await qe.conversation(H,se.nextBefore);pe({type:"older_page",contactCid:H,page:ue,newer:se.messages})}catch(ue){ye(ue)}finally{C.current.delete(H),T(null)}}},Be=ri(t),On=t.contacts.contacts.find(H=>H.container_id===Be),V=k.useMemo(()=>_z(t,y),[t,y]),D=V.find(H=>H.id===Be)??null,q=Be?Qk(sr(t,Be),y[Be]??[]):[],he=t.identity,Re=t.loaded?Be&&!sr(t,Be)||O?"updating":t.connection!=="live"?"connecting":null:"connecting",Oe=async(H,se=ge.preview)=>{if(J.registration){ae(!0),Ce(ue=>({...ue,status:"repairing",preview:se}));try{Ce(await(H==="enable"?m0(J.registration,{preview:se}):H==="repair"?S2(J.registration,se):b2(J.registration,ge)))}catch(ue){Ce(we=>({...we,status:"error"})),ye(ue)}finally{ae(!1)}}},Ie=()=>{X([]),A("invite"),qe.invites().then(X).catch(ye)};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:()=>Mt({name:"chats",contactCid:null},ni()),children:"Open chats"})]}):he?v.jsx("div",{className:j?"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(uz,{contacts:V,roots:Dz(t.contacts),selected:Be,onSelect:H=>{H.startsWith("pending:")||rn(H)},onInvite:Ie,onSettings:()=>A("settings"),onApprovePending:async H=>{try{return await qe.respondToIntroduction(H,"approve"),await ut(),!0}catch(se){return ye(se),!1}},onRejectPending:async H=>{try{return await qe.respondToIntroduction(H,"reject"),await ut(),!0}catch(se){return ye(se),!1}}}),t.route.name==="contact"&&D?v.jsx(cz,{contact:D,messages:q,onBack:()=>{P.current=!0,f2(window.history.state)==="back"?window.history.back():(window.history.replaceState({oursMessenger:!0},"",ni(D.id)),pe({type:"route",route:{name:"chats",contactCid:D.id},mobileDetailOpen:!0}),requestAnimationFrame(()=>document.querySelector("[data-contact-trigger]")?.focus({preventScroll:!0})),P.current=!1)},onRename:H=>void qe.renameContact(D.id,H).then(ut).catch(ye),onRemove:()=>{confirm(`Remove “${On?.name??"contact"}”?`)&&qe.removeContact(D.id).then(()=>(window.history.replaceState({oursMessenger:!0},"",ni()),pe({type:"route",route:{name:"chats",contactCid:null},mobileDetailOpen:!1}),ut())).catch(ye)},onOpenMessage:H=>{Mt({name:"chats",contactCid:D.id},ni(D.id),!0);let se=12;const ue=()=>{const we=document.getElementById(`chat-message-${encodeURIComponent(H)}`),Ae=we?.closest(".messages");if((!we||!Ae||Ae.clientHeight<=0)&&se-- >0){requestAnimationFrame(ue);return}if(!we||!Ae)return;const me=we.getBoundingClientRect(),Fe=Ae.getBoundingClientRect(),dt=Ae.scrollTop+me.top-Fe.top-Math.max(0,(Ae.clientHeight-me.height)/2),Et=Math.max(0,Math.min(dt,Ae.scrollHeight-Ae.clientHeight));Ae.scrollTo({top:Et,behavior:window.matchMedia("(prefers-reduced-motion: reduce)").matches?"auto":"smooth"})};requestAnimationFrame(ue)},indexOffset:sr(t,D.id)?.hasMore?Math.max(1,(sr(t,D.id)?.total??q.length)-q.length):0,onSendText:async(H,se)=>{const ue=await qe.send(D.id,H,se);return await Ke(D.id,!1),ue.wire_id??void 0},onSendFile:async(H,se)=>{await qe.sendFile(D.id,new Blob([H.bytes],{type:H.mime}),H.filename,H.mime,se),await Promise.all([nt(D.id),Ke(D.id,!1)])}}):v.jsx(fz,{contact:D,messages:q,syncing:Re,unreadOpen:i?.contactCid===Be?i:null,hiddenEarlier:sr(t,Be??"")?.hasMore?Math.max(1,(sr(t,Be??"")?.total??q.length)-q.length):0,onLoadEarlier:Be&&E!==Be?()=>void Cn(Be):void 0,onBack:()=>{a.current?.abort(),l.current+=1,s(null),Mt({name:"chats",contactCid:null},ni(),!1)},onOpenContact:()=>{Be&&Mt({name:"contact",contactCid:Be},c2(Be),!0)},onDraftChange:Pe,onSend:async(H,se,ue)=>{if(!Be)return;const we=Be,Ae=await qe.send(we,H,se,ue);return pe({type:"sent_message",contactCid:we,message:{dir:"out",text:H,date:new Date().toISOString(),read:!0,wire_id:Ae.wire_id??"",receipt:null,reply_to:se?{wire_id:se}:null}}),Ae.wire_id?it(we,me=>me.messages.some(Fe=>Fe.wire_id===Ae.wire_id),`send:${Ae.wire_id}`):St().catch(ye),Ae.wire_id??void 0},onSendFile:async(H,se)=>{Be&&(await qe.sendFile(Be,new Blob([H.bytes],{type:H.mime}),H.filename,H.mime,se),await Promise.all([nt(Be),Ke(Be,!1)]))},onFetchFile:async H=>{await qe.fetchFiles([H]),Be&&await nt(Be)}},Be??"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(xz,{items:M,onDismiss:ce,onOpen:H=>void rn(H)})]}),R==="invite"&&v.jsx(Sz,{identity:he,invites:I,onRefresh:async()=>X(await qe.invites()),onCreate:async(H,se)=>(await qe.createInvite(H,se)).blob,onAccept:async(H,se)=>{await qe.addContact(H,se),await ut()},onRevoke:async H=>{await qe.revokeInvite(H)},onClose:()=>{A(null),ut()}}),R==="settings"&&v.jsx(bz,{identity:he,push:ge,workerSupported:J.supported,busy:Y,offline:J.offline,updateAvailable:J.updateAvailable,build:$,dark:j,onToggleDark:()=>Q(H=>(localStorage.setItem(Ex,H?"0":"1"),!H)),onSaveBio:async H=>{await qe.setBio(H),await ut()},onPushAction:Oe,onInstall:U?()=>void U.prompt().then(()=>fe(null)):void 0,onReloadUpdate:()=>{J.registration&&ev(J.registration)},onClose:()=>{_.current=null,A(null),Be&&bt(Be)}}),t.error&&v.jsxs("div",{className:"banner error",role:"alert","aria-live":"assertive",children:[t.error,v.jsx("button",{className:"linkbtn",onClick:()=>pe({type:"error",message:null}),children:"dismiss"})]})]})}):v.jsx("div",{className:j?"theme-dark":"",style:{height:"100%"},children:v.jsx("div",{className:"centered-screen",children:v.jsx("p",{className:"muted",children:"Loading…"})})})}jz();const Zk=document.getElementById("root");if(!Zk)throw new Error("missing #root");tC.createRoot(Zk).render(v.jsx(ZP,{reducedMotion:"user",children:v.jsx(Lz,{})}));export{Ch as _,jd as g};
|
|
322
|
+
//# sourceMappingURL=index-GLm6dAFY.js.map
|