// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-3.0-or-later // @source: https://gitlab.com/soapbox-pub/ditto/-/tree/f0a3877c import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{Tr as t,Wr as n,_n as r,mn as i,qi as a}from"./lucide-icons-BdRF0moN.js";import{t as o}from"./jsx-runtime-By8HlURe.js";import{t as s}from"./dist-DQ82bf9M.js";import{u as c}from"./esm-CRVqHnq2.js";import{t as l}from"./useQuery-rCAlChE8.js";import{t as u}from"./useInfiniteQuery-BFtb_-3K.js";import{D as d,N as f,S as p,l as m,t as h,x as g,y as _}from"./useTheme-B8n3R7ig.js";import{a as v}from"./fontLoader-C8ZADbrS.js";import{l as y,o as b,t as x}from"./useCurrentUser-C6OJJlWo.js";import{t as S}from"./button-Cs26nq0r.js";import{t as C}from"./nostrId-DuqQCAdJ.js";import{f as w,i as T,o as E,p as D,s as O,u as k}from"./letterTypes-BLLFWtiN.js";import{c as A,n as j,t as M}from"./dialog-C3CFmras.js";import{i as N,o as P,t as F}from"./letterUtils-ByLgglzi.js";import{t as I}from"./NoteMoreMenu-FwlS01AC.js";import{n as L,t as R}from"./colorMomentUtils-VGseiWMP.js";import{t as z}from"./useStationeryColors-O59Qp8EM.js";import{t as B}from"./LetterStickers-B8Ngg6eA.js";var V=e(a(),1),H=o(),U=V.forwardRef(({className:e,strokeWidth:t=2,...n},r)=>(0,H.jsx)(`svg`,{ref:r,xmlns:`http://www.w3.org/2000/svg`,width:24,height:24,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:t,strokeLinecap:`round`,strokeLinejoin:`round`,className:e,...n,children:(0,H.jsx)(`path`,{d:`M17.9 8H9.2m-4.1 4H14l8-8.2c-2.3-2.3-6.1-2.3-8.5 0L2 15m0 4h8m11-2v1c0 1 1 1.5 1 2.5c0 .8-.7 1.5-1.5 1.5h-5c-.8 0-1.5-.7-1.5-1.5c0-1 1-1.5 1-2.5v-1m-1 0h8`})}));U.displayName=`InkPenIcon`;var W=50;function G(e){if(e.kind!==8211)return null;let t=e.tags.find(([e])=>e===`p`)?.[1];return C(t)?{event:e,recipient:t,sender:e.pubkey,decrypted:!1,timestamp:e.created_at}:null}function K(e){let{nostr:t}=s(),{user:n}=x(),r=u({queryKey:[`letters-inbox`,n?.pubkey,e??null],queryFn:async({pageParam:r})=>{if(!n)return[];let i={kinds:[E],"#p":[n.pubkey],limit:W};if(r&&(i.until=r),e){if(e.length===0)return[];i.authors=e}return(await t.query([i])).map(G).filter(e=>e!==null).sort((e,t)=>t.timestamp-e.timestamp)},initialPageParam:void 0,getNextPageParam:e=>{if(e.length{if(!t)return[];let r={kinds:[E],authors:[t.pubkey],limit:W};return n&&(r.until=n),(await e.query([r])).map(G).filter(e=>e!==null).sort((e,t)=>t.timestamp-e.timestamp)},initialPageParam:void 0,getNextPageParam:e=>{if(e.length{if(!t||!e)return null;if(!t.signer.nip44)throw Error(`NIP-44 encryption not supported by your signer`);let n=e.sender===t.pubkey?e.recipient:e.sender;try{let r=await t.signer.nip44.decrypt(n,e.event.content),i=JSON.parse(r);return!i.body&&(!i.stickers||i.stickers.length===0)?null:{content:i,stationery:i.stationery}}catch{return null}},enabled:!!t&&!!e&&!!e.event.content,retry:!1})}function Y(e,t){let n=g(e,t,.08),r=d(n)<.45;return{body:n,bodyLight:f(n,.06),bodyDark:p(n,.06),stroke:p(n,.2),corner:p(n,.12),shadow:p(n,.3),text:r?f(n,.55):p(n,.55),textMuted:r?f(n,.4):p(n,.4)}}function X(e){let t=Math.max(0,Math.floor(Date.now()/1e3-e));if(t<60)return`now`;let n=Math.floor(t/60);if(n<60)return`${n}m`;let r=Math.floor(n/60);if(r<24)return`${r}h`;let i=Math.floor(r/24);if(i<7)return`${i}d`;let a=Math.floor(i/7);if(a<5)return`${a}w`;let o=Math.floor(i/30);return o<12?`${o}mo`:`${Math.floor(i/365)}y`}var Z=65,Q=15;function $({letter:e,mode:r,index:i,onClick:a,minimal:o}){let s=y(r===`inbox`?e.sender:e.recipient),{data:c}=J(e),[l,u]=(0,V.useState)(!1),d=s.data?.metadata?.name||s.data?.metadata?.display_name||`Anonymous`,f=s.data?.metadata?.picture,m=X(e.timestamp),h=c?.stationery,g=(0,V.useMemo)(()=>w(h??{color:`#F5E6D3`}),[h]),_=g.color,v=g.primaryColor??g.colors?.[0]??_,b=(0,V.useMemo)(()=>Y(_,v),[_,v]),x=`polygon(0% 0%, 100% 0%, 100% ${Q}%, 50% ${Z}%, 0% ${Q}%)`;return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`button`,{onClick:a,className:`envelope-card group outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2 rounded-xl w-full`,style:{"--entrance-delay":`${Math.min(i*60,300)}ms`},title:`${r===`inbox`?`From`:`To`} ${d}`,children:(0,H.jsxs)(`div`,{className:`envelope-body relative w-full overflow-hidden rounded-xl`,style:{aspectRatio:`200 / 136`,boxShadow:`0 4px 16px ${b.shadow}22, 0 2px 6px ${b.shadow}18`},children:[(0,H.jsx)(`div`,{className:`absolute inset-0`,style:{background:`linear-gradient(170deg, ${b.bodyLight} 0%, ${b.body} 45%, ${b.bodyDark} 100%)`}}),(0,H.jsx)(`div`,{className:`absolute inset-0`,style:{clipPath:x,zIndex:1},children:(0,H.jsx)(N,{stationery:h,className:`w-full h-full`})}),(0,H.jsxs)(`svg`,{className:`absolute inset-0 w-full h-full pointer-events-none`,viewBox:`0 0 200 136`,preserveAspectRatio:`none`,style:{zIndex:2},children:[(0,H.jsx)(`defs`,{children:(0,H.jsxs)(`linearGradient`,{id:`vfold-${e.event.id}`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,H.jsx)(`stop`,{offset:`0%`,stopColor:b.body}),(0,H.jsx)(`stop`,{offset:`100%`,stopColor:b.bodyDark})]})}),(0,H.jsx)(`path`,{d:`M0,${Q*1.36} L92,${Z*1.36-10} Q100,${Z*1.36} 108,${Z*1.36-10} L200,${Q*1.36} L200,128 Q200,136 192,136 L8,136 Q0,136 0,128 Z`,fill:`url(#vfold-${e.event.id})`}),(0,H.jsx)(`path`,{d:`M0,${Q*1.36} L92,${Z*1.36-10} Q100,${Z*1.36} 108,${Z*1.36-10} L200,${Q*1.36}`,fill:`none`,stroke:b.stroke,strokeWidth:`1.4`,strokeLinecap:`round`,strokeLinejoin:`round`,opacity:`0.3`}),(0,H.jsx)(`path`,{d:`M2,134 L70,70`,stroke:b.corner,strokeWidth:`1.2`,strokeLinecap:`round`,fill:`none`,opacity:`0.4`}),(0,H.jsx)(`path`,{d:`M198,134 L130,70`,stroke:b.corner,strokeWidth:`1.2`,strokeLinecap:`round`,fill:`none`,opacity:`0.4`}),(0,H.jsx)(`rect`,{x:`0`,y:`132`,width:`200`,height:`4`,rx:`2`,fill:b.shadow,opacity:`0.06`})]}),!o&&(0,H.jsxs)(`div`,{className:`absolute left-0 right-0 bottom-0 flex flex-col items-start px-2.5 pb-1.5 pt-0.5`,style:{zIndex:3},children:[(0,H.jsxs)(`span`,{className:`flex items-center gap-0.5 text-[9px] font-medium leading-tight`,style:{color:b.textMuted},children:[(0,H.jsx)(n,{className:`w-2 h-2`}),m]}),(0,H.jsx)(`span`,{className:`text-[11px] font-semibold truncate leading-tight max-w-full`,style:{color:b.text},children:d})]}),(0,H.jsx)(`div`,{className:`absolute z-10`,style:{left:`50%`,top:`${Z-8}%`,transform:`translate(-50%, -50%)`},children:(0,H.jsx)(`div`,{className:`rounded-full transition-transform duration-200 group-hover:scale-110 overflow-hidden`,style:{width:40,height:40,boxShadow:`0 3px 10px ${b.shadow}77, 0 1px 3px ${b.shadow}44, inset 0 1.5px 3px rgba(255,255,255,0.3)`,border:`3px solid ${p(v,.18)}`,background:` radial-gradient(ellipse at 35% 30%, rgba(255,255,255,0.22) 0%, transparent 50%), radial-gradient(ellipse at 65% 70%, rgba(0,0,0,0.12) 0%, transparent 50%), radial-gradient(circle at 50% 50%, ${v}, ${p(v,.18)}) `},children:f?(0,H.jsx)(`img`,{src:f,alt:``,className:`w-full h-full object-cover`,loading:`lazy`,decoding:`async`}):(0,H.jsx)(`div`,{className:`w-full h-full flex items-center justify-center`,children:(0,H.jsx)(`img`,{src:`/logo.svg`,alt:``,style:{width:22,height:22,filter:`brightness(0) invert(1) opacity(0.85)`},decoding:`async`})})})}),(0,H.jsx)(`div`,{className:`absolute bottom-1.5 right-1.5`,style:{zIndex:20},children:(0,H.jsx)(`button`,{onClick:e=>{e.stopPropagation(),u(!0)},className:`p-1 rounded-full transition-colors opacity-0 group-hover:opacity-100 focus:opacity-100`,style:{background:`${b.body}cc`,color:b.textMuted},title:`More options`,children:(0,H.jsx)(t,{className:`w-3.5 h-3.5`,strokeWidth:2.5})})})]})}),(0,H.jsx)(I,{event:e.event,open:l,onOpenChange:u})]})}function ee({event:e}){let{applyCustomTheme:t,theme:n,customTheme:r,setTheme:i}=h(),[a,o]=(0,V.useState)(!1),s=(0,V.useRef)(void 0),c=(0,V.useMemo)(()=>{if(e.kind===3367){let t=R(e.tags);return t.length<2?null:{type:`color-moment`,label:`Color Moment`,colors:t,core:L(t),resolved:w(k(e))}}if(e.kind===36767){let t=m(e);if(!t)return null;let n=w(D(e));return{type:`theme`,label:t.title??`Theme`,colors:[],core:t.colors,resolved:n,themeConfig:{colors:t.colors,font:t.font,titleFont:t.titleFont,background:t.background,title:t.title}}}return null},[e]),l=(0,V.useCallback)(()=>{c&&(s.current={mode:n,config:r},c.type===`color-moment`?t(c.core):t(c.themeConfig),o(!0),b({title:`Theme applied`,description:`"${c.label}" is now your active theme.`,action:(0,H.jsx)(`button`,{className:`text-sm font-medium underline underline-offset-2`,onClick:()=>{let e=s.current;e&&(e.mode===`custom`&&e.config?t(e.config):i(e.mode),o(!1))},children:`Undo`})}))},[c,n,r,t,i]);if(!c)return null;let{resolved:u}=c,f=u.color,p=`hsl(${c.core.primary})`,g=d(f)>.85,v=c.type===`color-moment`?c.colors[Math.floor(c.colors.length/2)]??p:p,y=_(f);return(0,H.jsxs)(`div`,{className:`relative max-w-[220px] mx-auto mb-12 pointer-events-none`,children:[(0,H.jsx)(`div`,{className:`flex justify-center relative z-10 mb-[-20px]`,children:(0,H.jsxs)(`svg`,{width:`56`,height:`60`,viewBox:`0 0 56 60`,fill:`none`,className:`drop-shadow-sm`,children:[(0,H.jsx)(`rect`,{x:`4`,y:`26`,width:`48`,height:`32`,rx:`3`,fill:f,stroke:g?`#0001`:`none`,strokeWidth:`1`}),(0,H.jsx)(`rect`,{x:`4`,y:`26`,width:`48`,height:`8`,rx:`3`,fill:`white`,opacity:`0.07`}),(0,H.jsx)(`rect`,{x:`24`,y:`26`,width:`8`,height:`32`,fill:v,opacity:`0.8`}),(0,H.jsx)(`rect`,{x:`4`,y:`38`,width:`48`,height:`6`,fill:v,opacity:`0.8`}),(0,H.jsx)(`rect`,{x:`2`,y:`18`,width:`52`,height:`10`,rx:`2.5`,fill:f,stroke:g?`#0001`:v,strokeWidth:g?1:.5,strokeOpacity:g?1:.2}),(0,H.jsx)(`rect`,{x:`2`,y:`18`,width:`52`,height:`4`,rx:`2.5`,fill:`white`,opacity:`0.1`}),(0,H.jsx)(`rect`,{x:`24`,y:`18`,width:`8`,height:`10`,fill:v,opacity:`0.8`}),(0,H.jsx)(`ellipse`,{cx:`20`,cy:`14`,rx:`8`,ry:`6`,fill:v}),(0,H.jsx)(`ellipse`,{cx:`19.5`,cy:`12.5`,rx:`4.5`,ry:`3`,fill:`white`,opacity:`0.2`}),(0,H.jsx)(`ellipse`,{cx:`36`,cy:`14`,rx:`8`,ry:`6`,fill:v}),(0,H.jsx)(`ellipse`,{cx:`36.5`,cy:`12.5`,rx:`4.5`,ry:`3`,fill:`white`,opacity:`0.2`}),(0,H.jsx)(`ellipse`,{cx:`28`,cy:`16`,rx:`5`,ry:`4`,fill:v}),(0,H.jsx)(`ellipse`,{cx:`28`,cy:`15`,rx:`2.5`,ry:`2`,fill:`white`,opacity:`0.15`})]})}),(0,H.jsxs)(`div`,{onClick:e=>{e.stopPropagation(),l()},role:`button`,tabIndex:0,title:a?`Theme applied!`:`Tap to use "${c.label}" as your theme`,className:`relative rounded-2xl overflow-hidden pointer-events-auto cursor-pointer transition-transform duration-200 active:scale-95 hover:scale-[1.02]`,style:{background:f,border:g?`1px solid hsl(var(--border))`:`1px solid ${v}22`},children:[c.type===`color-moment`&&c.colors.length>0&&(0,H.jsx)(P,{colors:c.colors,layout:u.layout||`horizontal`,className:`absolute inset-0`}),c.type===`theme`&&u.imageUrl&&(0,H.jsx)(`div`,{className:`absolute inset-0`,children:(0,H.jsx)(`img`,{src:u.imageUrl,alt:``,className:`w-full h-full object-cover`,decoding:`async`})}),(0,H.jsx)(`div`,{className:`absolute inset-0`,style:{background:`${f}bb`}}),(0,H.jsxs)(`div`,{className:`relative px-4 pt-7 pb-3.5 text-center`,children:[(0,H.jsx)(`p`,{className:`text-xs font-semibold truncate`,style:{color:y},children:c.label}),(0,H.jsx)(`p`,{className:`text-[11px] mt-0.5`,style:{color:y,opacity:.6},children:a?`Applied as your theme`:`Tap to use as theme`})]})]})]})}function te({letter:e,onClose:t,onReply:n}){let a=(0,V.useRef)(null),[o,s]=(0,V.useState)(0),{user:l}=x(),{data:u,isLoading:d}=J(e??void 0),f=u?.content,p=u?.stationery,m=p?.frame,h=p?.frameTint,{text:g,faint:_,line:y}=z(p),b=p?.fontFamily?v(p.fontFamily):void 0,C=b?b.includes(`,`)?b:`${b}, ${T[0].family}`:T[0].family;return(0,V.useLayoutEffect)(()=>{F(C)},[C]),(0,V.useEffect)(()=>{if(!e)return;let t=setTimeout(()=>{let e=a.current;if(!e)return;let t=e.getBoundingClientRect().width;t>0&&s(Math.round(t*O))},50),n=a.current;if(!n)return()=>clearTimeout(t);let r,i=new ResizeObserver(([e])=>{cancelAnimationFrame(r),r=requestAnimationFrame(()=>{let t=e.contentBoxSize?.[0]?.inlineSize??e.contentRect.width;t>0&&s(Math.round(t*O))})});return i.observe(n),()=>{clearTimeout(t),i.disconnect(),cancelAnimationFrame(r)}},[e]),(0,H.jsx)(M,{open:!!e,onOpenChange:e=>{e||t()},children:(0,H.jsxs)(j,{className:`p-0 gap-0 border-none bg-transparent shadow-none max-w-[calc(100vw-2rem)] sm:max-w-lg overflow-visible [&>button]:hidden`,children:[(0,H.jsx)(A,{className:`sr-only`,children:`Letter`}),(0,H.jsxs)(`div`,{className:`relative`,onClick:t,children:[p?.event&&(0,H.jsx)(`div`,{className:`absolute bottom-full left-0 right-0 pointer-events-none`,children:(0,H.jsx)(ee,{event:p.event})}),(0,H.jsxs)(`div`,{ref:a,className:`relative`,onClick:e=>e.stopPropagation(),style:{containerType:`inline-size`,...m&&m!==`none`?{padding:`28px 28px 44px`}:{}},children:[(0,H.jsx)(N,{stationery:p,frame:m,frameTint:h,className:`rounded-3xl shadow-inner shadow-black/5`,children:(0,H.jsx)(`div`,{className:`relative z-10 flex flex-col`,style:{aspectRatio:`5 / 4`,padding:`5cqw`},children:d?(0,H.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,H.jsxs)(`div`,{className:`flex flex-col items-center gap-2.5`,style:{color:_},children:[(0,H.jsx)(r,{className:`w-5 h-5 animate-spin`}),(0,H.jsx)(`span`,{className:`text-xs`,children:`unsealing...`})]})}):f?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`p`,{dir:`auto`,className:`whitespace-pre-wrap font-semibold tracking-wide overflow-hidden flex-1 min-h-0`,style:{fontSize:`4.8cqw`,lineHeight:o>0?`${o}px`:`8.4cqw`,letterSpacing:`0.06em`,paddingTop:`0.5cqw`,fontFamily:C,color:g,...o>0?{backgroundImage:`linear-gradient(to bottom, transparent ${o-3}px, ${y} ${o-3}px)`,backgroundSize:`100% ${o}px`,backgroundRepeat:`repeat-y`,maxHeight:`${o*5}px`}:{},backgroundPosition:`0 0`},children:f.body}),(f.closing||f.signature)&&(0,H.jsxs)(`div`,{className:`flex flex-col items-end`,style:{paddingTop:`6cqw`,gap:`3cqw`,paddingRight:`4cqw`,fontFamily:C},children:[f.closing&&(0,H.jsx)(`p`,{dir:`auto`,style:{fontSize:`4.8cqw`,color:g},children:f.closing}),f.signature&&(0,H.jsx)(`p`,{dir:`auto`,className:`font-semibold`,style:{fontSize:`5cqw`,color:g},children:f.signature})]})]}):(0,H.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,H.jsxs)(`div`,{className:`flex flex-col items-center gap-2`,style:{color:_},children:[(0,H.jsx)(i,{className:`w-5 h-5`}),(0,H.jsx)(`p`,{className:`text-xs italic`,children:`couldn't unseal this one`})]})})})}),f?.stickers&&f.stickers.length>0&&(0,H.jsx)(`div`,{className:`absolute inset-0 rounded-3xl overflow-hidden pointer-events-none`,style:{zIndex:20},children:(0,H.jsx)(`div`,{className:`relative w-full h-full`,children:(0,H.jsx)(B,{stickers:f.stickers})})})]}),n&&e&&l?.pubkey!==e.sender&&(0,H.jsx)(`div`,{className:`absolute top-full left-0 right-0 flex justify-center pt-12 pointer-events-none`,children:(0,H.jsxs)(S,{variant:`default`,size:`lg`,className:`gap-3 rounded-full px-12 text-lg h-14 bg-primary text-primary-foreground hover:bg-primary/90 pointer-events-auto`,style:{filter:`drop-shadow(0 2px 8px hsl(var(--primary) / 0.25))`},onClick:r=>{r.stopPropagation();let i=c.npubEncode(e.sender);t(),setTimeout(()=>n(i),150)},children:[(0,H.jsx)(U,{className:`w-5 h-5`,strokeWidth:2}),`Reply`]})})]})]})})}export{U as a,q as i,$ as n,K as r,te as t}; // @license-end