// @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{qi as t,qt as n}from"./lucide-icons-BdRF0moN.js";import{t as r}from"./jsx-runtime-By8HlURe.js";import{t as i}from"./dist-DQ82bf9M.js";import{t as a}from"./useQuery-rCAlChE8.js";import{t as o}from"./useAppContext-Ughdk2-Z.js";import{A as s,f as c,h as l,m as u,t as d}from"./useTheme-B8n3R7ig.js";import{c as f}from"./fontLoader-C8ZADbrS.js";import{t as p}from"./useCurrentUser-C6OJJlWo.js";import{n as m}from"./useFollowActions-cve70R08.js";import{a as h,c as g,d as _,f as v,i as y,l as b,n as x,p as S,s as C,t as w,u as T}from"./letterTypes-BLLFWtiN.js";import{n as E}from"./chunk-62JRHF6Z-yJW_vgm4.js";import{t as D}from"./skeleton-CVls4GW9.js";import{a as O,c as k,n as A,t as j}from"./dialog-C3CFmras.js";import{a as M,i as N,n as P}from"./letterUtils-ByLgglzi.js";import{t as F}from"./switch-B6lxwP1L.js";import{t as I}from"./useMutedAuthorFilter-CTggZCaG.js";import{o as L}from"./index-CYEZWNq6.js";import{i as R,n as z,o as B,s as V,t as H}from"./select-DRTcxeFR.js";import{t as U}from"./useStationeryColors-O59Qp8EM.js";var W=e(t(),1);function ee(){let{theme:e,customTheme:t,themes:n}=d(),{config:r}=o();return(0,W.useMemo)(()=>{let i=u(e),a,o,d,f,p,m;if(i===`custom`&&t){let{colors:e,font:n,background:r}=t;a=s(e.background),o=s(e.text),d=s(e.primary),f=n?.family??void 0,p=r?.url??void 0,m=r?.mode??void 0}else{let e=l(i,n??r.themes).colors??c[i];a=s(e.background),o=s(e.text),d=s(e.primary)}return{color:a,textColor:o,primaryColor:d,...f?{fontFamily:f}:{},...p?{imageUrl:p,imageMode:m??`cover`}:{}}},[e,t,n,r.themes])}function te(e){if(e.kind!==3367)return null;let t=e.tags.filter(([e])=>e===`c`);if(t.length<3||t.length>6)return null;let n=/^#[0-9A-Fa-f]{6}$/;return t.every(([,e])=>n.test(e))?e:null}function G(e){if(e.kind!==36767)return null;let t=e.tags.find(([e])=>e===`d`)?.[1],n=e.tags.find(([e])=>e===`title`)?.[1];return!t||!n?null:e}function K(e=24,t,n){let{nostr:r}=i();return a({queryKey:[`color-moments-page`,e,t,n??null],queryFn:async()=>{let i={kinds:[x],limit:e,...t?{until:t}:{},...n&&n.length>0?{authors:n}:{}},a=await r.query([i]),o=new Map;for(let e of a)o.set(e.id,e);return Array.from(o.values()).filter(e=>te(e)!==null).sort((e,t)=>t.created_at-e.created_at)}})}function q(e=24,t,n){let{nostr:r}=i();return a({queryKey:[`themes-page`,e,t,n??null],queryFn:async()=>{let i={kinds:[b],limit:e,...t?{until:t}:{},...n&&n.length>0?{authors:n}:{}};return(await r.query([i])).filter(e=>G(e)!==null).sort((e,t)=>t.created_at-e.created_at)}})}var J=r(),Y=24,X=Object.entries(g);function Z({selectedStationery:e,onSelect:t,authors:n}){let[r,i]=(0,W.useState)([]),[a,o]=(0,W.useState)(void 0),[s,c]=(0,W.useState)(!0),l=(0,W.useRef)(`init`),{data:u,isLoading:d}=K(Y,a,n);(0,W.useEffect)(()=>{!u||d||l.current!==a&&(l.current=a,u.length>0?(i(e=>[...e,u]),u.length0||!d&&l.current!==`init`,m=(0,W.useCallback)(()=>{!s||d||f.length===0||o(f[f.length-1].created_at-1)},[s,d,f]),h=(0,W.useRef)(null),g=(0,W.useCallback)(e=>{h.current?.disconnect(),e&&(h.current=new IntersectionObserver(e=>{e[0].isIntersecting&&m()},{threshold:.1}),h.current.observe(e))},[m]);return!p&&d?(0,J.jsx)(`div`,{className:`grid grid-cols-5 gap-2`,children:Array.from({length:10}).map((e,t)=>(0,J.jsx)(D,{className:`aspect-square rounded-2xl`},t))}):p&&f.length===0?(0,J.jsx)(`p`,{className:`py-6 text-center text-sm text-muted-foreground`,children:`none found — try presets`}):(0,J.jsx)(`div`,{className:`overflow-y-auto rounded-xl`,style:{height:160},children:(0,J.jsxs)(`div`,{className:`grid grid-cols-5 gap-2`,children:[f.map(n=>{let r=T(n),i=e?.event?.id===n.id,a=n.tags.find(([e])=>e===`name`)?.[1];return(0,J.jsx)(`button`,{onClick:()=>t(r),title:a,className:`relative aspect-square rounded-2xl overflow-hidden transition-all hover:scale-105 active:scale-95`,children:(0,J.jsx)(M,{stationery:r,selected:i,className:`w-full h-full`})},n.id)}),s&&(0,J.jsx)(`div`,{ref:g,className:`col-span-5 h-2`,children:d&&Array.from({length:5}).map((e,t)=>(0,J.jsx)(D,{className:`aspect-square rounded-2xl`},t))})]})})}function ne({selectedStationery:e,onSelect:t,authors:n}){let[r,i]=(0,W.useState)([]),[a,o]=(0,W.useState)(void 0),[s,c]=(0,W.useState)(!0),l=(0,W.useRef)(`init`),{data:u,isLoading:d}=q(Y,a,n);(0,W.useEffect)(()=>{!u||d||l.current!==a&&(l.current=a,u.length>0?(i(e=>[...e,u]),u.length0||!d&&l.current!==`init`,m=(0,W.useCallback)(()=>{!s||d||f.length===0||o(f[f.length-1].created_at-1)},[s,d,f]),h=(0,W.useRef)(null),g=(0,W.useCallback)(e=>{h.current?.disconnect(),e&&(h.current=new IntersectionObserver(e=>{e[0].isIntersecting&&m()},{threshold:.1}),h.current.observe(e))},[m]);return!p&&d?(0,J.jsx)(`div`,{className:`grid grid-cols-5 gap-2`,children:Array.from({length:10}).map((e,t)=>(0,J.jsx)(D,{className:`aspect-square rounded-2xl`},t))}):p&&f.length===0?(0,J.jsx)(`p`,{className:`py-6 text-center text-sm text-muted-foreground`,children:`none found — try presets`}):(0,J.jsx)(`div`,{className:`overflow-y-auto rounded-xl`,style:{height:160},children:(0,J.jsxs)(`div`,{className:`grid grid-cols-5 gap-2`,children:[f.map(n=>{let r=S(n),i=e?.event?.id===n.id,a=n.tags.find(([e])=>e===`title`)?.[1];return(0,J.jsx)(`button`,{onClick:()=>t(r),title:a,className:`relative aspect-square rounded-2xl overflow-hidden transition-all hover:scale-105 active:scale-95`,children:(0,J.jsx)(M,{stationery:r,selected:i,className:`w-full h-full`})},n.id)}),s&&(0,J.jsx)(`div`,{ref:g,className:`col-span-5 h-2`,children:d&&Array.from({length:5}).map((e,t)=>(0,J.jsx)(D,{className:`aspect-square rounded-2xl`},t))})]})})}function re({selected:e,onSelect:t}){let[n,r]=(0,W.useState)(`presets`),[i,a]=(0,W.useState)(`everyone`),[s,c]=(0,W.useState)(!1),{user:l}=p(),{config:u}=o(),d=m().data?.pubkeys,f=(0,W.useMemo)(()=>new Set(d??[]),[d]),{excludeMuted:h}=I(),g=(0,W.useMemo)(()=>{if(i===`mine`)return l?[l.pubkey]:void 0;if(i===`friends`){if(f.size===0)return;let e=h(Array.from(f));return e.length>0?e:void 0}},[i,l,f,h]),y=e?v(e):void 0,S=e?.emojiMode??`tile`,C=!!y?.emoji,w=e?.event?.kind===x,T=e?.event?.kind===b,D=(0,W.useRef)(void 0);w&&e?.event&&(D.current=e.event);let N=!!(e&&!e.event&&D.current),P=()=>{if(e){if(N&&D.current)t({...e,event:D.current});else if(w&&e.event){let{event:n,...r}=e;t(r)}}},L=()=>{e&&t({...e,emojiMode:S===`tile`?`emblem`:`tile`})},R=[{id:`presets`,label:`presets`},{id:`colors`,label:`moments`},{id:`themes`,label:`themes`}],z=n===`colors`,B=n===`themes`,V=z||B;return(0,J.jsxs)(`div`,{className:`space-y-3`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[R.map(e=>(0,J.jsx)(`button`,{onClick:()=>{r(e.id),a(`everyone`)},className:`px-3 py-1.5 rounded-full text-sm font-medium transition-all border ${n===e.id?`bg-foreground text-background border-foreground`:`bg-secondary text-muted-foreground hover:text-foreground border-secondary`}`,children:e.label},e.id)),V&&(0,J.jsx)(`button`,{onClick:()=>c(!0),className:`ml-auto opacity-70 hover:opacity-100 transition-opacity text-xs text-muted-foreground font-medium px-2 py-1 rounded-full bg-secondary`,children:`about`})]}),V&&(0,J.jsx)(`div`,{className:`flex gap-1`,children:[`everyone`,`friends`,...l?[`mine`]:[]].map(e=>(0,J.jsx)(`button`,{onClick:()=>a(e),className:`px-2.5 py-1 rounded-full text-xs font-medium transition-all border ${i===e?`bg-foreground text-background border-foreground`:`bg-secondary text-muted-foreground hover:text-foreground border-secondary`}`,children:e},e))}),(0,J.jsxs)(`div`,{children:[n===`presets`&&(0,J.jsx)(`div`,{className:`rounded-xl`,children:(0,J.jsx)(`div`,{className:`grid grid-cols-5 gap-2`,children:X.map(([n,r])=>{let i={color:r.color,emoji:r.emoji};return(0,J.jsx)(`button`,{onClick:()=>t(_(n)??i),title:r.name,className:`relative aspect-square rounded-2xl overflow-hidden transition-all hover:scale-105 active:scale-95`,children:(0,J.jsx)(M,{stationery:i,selected:e?.color===r.color&&!e?.event,className:`w-full h-full`})},n)})})}),n===`colors`&&(0,J.jsx)(Z,{selectedStationery:e,onSelect:t,authors:g},i),n===`themes`&&(0,J.jsx)(ne,{selectedStationery:e,onSelect:t,authors:g},i)]}),(C&&!T||w||N)&&(0,J.jsxs)(`div`,{className:`flex items-center gap-4 px-1 pt-1`,children:[C&&!T&&(0,J.jsxs)(`label`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(F,{checked:S===`emblem`,onCheckedChange:L}),(0,J.jsx)(`span`,{className:`text-sm text-muted-foreground font-medium`,children:`emblem`})]}),(w||N)&&(0,J.jsxs)(`label`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(F,{checked:N,onCheckedChange:P}),(0,J.jsx)(`span`,{className:`text-sm text-muted-foreground font-medium`,children:`flat`})]})]}),(0,J.jsx)(j,{open:s,onOpenChange:c,children:(0,J.jsxs)(A,{className:`max-w-xs rounded-2xl`,children:[z&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(O,{children:(0,J.jsx)(k,{children:`Color moments`})}),(0,J.jsxs)(`div`,{className:`space-y-3 text-sm text-muted-foreground`,children:[(0,J.jsx)(`p`,{children:`Color moments are beautiful color combinations created and shared by the community. Each one gives your letter a unique palette and mood.`}),(0,J.jsx)(`p`,{children:(0,J.jsx)(E,{to:`/colors`,onClick:()=>c(!1),className:`text-foreground font-medium underline underline-offset-2 hover:no-underline`,children:`Discover and create color moments`})})]})]}),B&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(O,{children:(0,J.jsxs)(k,{children:[u.appName,` themes`]})}),(0,J.jsxs)(`div`,{className:`space-y-3 text-sm text-muted-foreground`,children:[(0,J.jsxs)(`p`,{children:[u.appName,` themes are UI themes shared by the community. Letters borrows their colors and fonts to style your letter.`]}),(0,J.jsx)(`p`,{children:(0,J.jsx)(E,{to:`/themes`,onClick:()=>c(!1),className:`text-foreground font-medium underline underline-offset-2 hover:no-underline`,children:`Browse and create themes`})})]})]})]})})]})}var Q=`#f5e6d3`;function $(){return(0,J.jsxs)(`svg`,{viewBox:`0 0 64 64`,xmlns:`http://www.w3.org/2000/svg`,className:`w-full h-full`,children:[(0,J.jsx)(`rect`,{x:`10`,y:`10`,width:`44`,height:`44`,fill:Q,rx:`4`}),[20,28,36,44].map(e=>(0,J.jsx)(`line`,{x1:`14`,y1:e,x2:`50`,y2:e,stroke:`#c4a88240`,strokeWidth:`0.8`},e)),(0,J.jsx)(`line`,{x1:`22`,y1:`32`,x2:`42`,y2:`32`,stroke:`#c4a882`,strokeWidth:`1.5`,strokeLinecap:`round`})]})}function ie({frameId:e}){let t=h.find(t=>t.id===e);return!t?.emojis||!t.bgColor?null:(0,J.jsxs)(`svg`,{viewBox:`0 0 64 64`,xmlns:`http://www.w3.org/2000/svg`,className:`w-full h-full`,children:[(0,J.jsx)(`rect`,{x:`0`,y:`0`,width:`64`,height:`64`,fill:t.bgColor,rx:`8`}),[{x:5,y:6},{x:15,y:4},{x:25,y:7},{x:35,y:4},{x:45,y:6},{x:55,y:5},{x:5,y:58},{x:15,y:60},{x:25,y:57},{x:35,y:60},{x:45,y:58},{x:55,y:59},{x:4,y:18},{x:6,y:30},{x:4,y:42},{x:6,y:52},{x:58,y:18},{x:60,y:30},{x:58,y:42},{x:60,y:52},{x:8,y:10},{x:56,y:10},{x:8,y:54},{x:56,y:54}].map((e,n)=>(0,J.jsx)(`text`,{x:e.x,y:e.y,fontSize:`8`,textAnchor:`middle`,dominantBaseline:`central`,children:t.emojis[n%t.emojis.length]},n)),(0,J.jsx)(`rect`,{x:`10`,y:`10`,width:`44`,height:`44`,fill:Q,rx:`4`}),[20,28,36,44].map(e=>(0,J.jsx)(`line`,{x1:`14`,y1:e,x2:`50`,y2:e,stroke:`#c4a88240`,strokeWidth:`0.8`},e))]})}function ae({frame:e,frameTint:t,onFrameSelect:n,onFrameTintChange:r}){let i=e!==`none`;return(0,J.jsxs)(`div`,{className:`space-y-3`,children:[(0,J.jsx)(`div`,{className:`grid grid-cols-5 gap-2`,children:h.map(t=>{let r=e===t.id;return(0,J.jsx)(`button`,{onClick:()=>n(t.id),title:t.name,className:`aspect-square rounded-2xl overflow-hidden transition-all hover:scale-105 active:scale-95 ${r?`scale-105 shadow-md`:`opacity-70 hover:opacity-100`}`,children:t.id===`none`?(0,J.jsx)($,{}):(0,J.jsx)(ie,{frameId:t.id})},t.id)})}),i&&(0,J.jsxs)(`div`,{className:`flex items-center justify-between px-1 pt-1`,children:[(0,J.jsx)(`span`,{className:`text-sm text-muted-foreground font-medium`,children:`match stationery color`}),(0,J.jsx)(F,{checked:t,onCheckedChange:r})]})]})}function oe({className:e,strokeWidth:t=2}){return(0,J.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:t,strokeLinecap:`round`,strokeLinejoin:`round`,className:e,children:[(0,J.jsx)(`rect`,{x:`2`,y:`3`,width:`20`,height:`18`,rx:`3`}),(0,J.jsx)(`rect`,{x:`5.5`,y:`6.5`,width:`13`,height:`11`,rx:`2`}),(0,J.jsx)(`path`,{d:`M4 5 C4.5 5.5 5 6 5.5 6.5`}),(0,J.jsx)(`path`,{d:`M20 5 C19.5 5.5 19 6 18.5 6.5`}),(0,J.jsx)(`path`,{d:`M4 19 C4.5 18.5 5 18 5.5 17.5`}),(0,J.jsx)(`path`,{d:`M20 19 C19.5 18.5 19 18 18.5 17.5`})]})}function se({state:e,renderToolbarButtons:t,extraButtons:r,extraDrawerContent:i,overlay:a,setOverlay:o,bodyContent:s,cardOverlay:c,beforeCard:l,cardRef:u}){let{selectedFont:d,setSelectedFont:p,stationery:m,setStationery:h,frame:g,setFrame:_,frameTint:v,setFrameTint:b,closing:x,setClosing:S,signature:T,setSignature:E}=e,D=(0,W.useRef)(null),O=u??D,[k,A]=(0,W.useState)(0);(0,W.useEffect)(()=>{let e=O.current;if(!e)return;let t=new ResizeObserver(([e])=>{let t=e.contentBoxSize?.[0]?.inlineSize??e.contentRect.width;A(Math.round(t*C))});return t.observe(e),()=>t.disconnect()},[O]),(0,W.useEffect)(()=>{f(d.family.split(`,`)[0].trim())},[d.family]),(0,W.useEffect)(()=>{a===`font`&&[`Fredoka`,`Nunito`,`Playfair Display`,`Caveat`,`Pacifico`,`Pirata One`,`Permanent Marker`,`Special Elite`,`Creepster`,`Silkscreen`].forEach(e=>f(e))},[a]);let{text:j,line:M,fontFamily:F}=U(m),I=P(d.family,F);return(0,J.jsxs)(J.Fragment,{children:[t((0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(L,{label:`Font`,active:a===`font`,onClick:()=>o(a===`font`?`none`:`font`),children:(0,J.jsx)(`span`,{className:`text-base font-bold`,children:`Aa`})}),(0,J.jsx)(L,{label:`Stationery`,active:a===`stationery`,onClick:()=>o(a===`stationery`?`none`:`stationery`),children:(0,J.jsx)(n,{className:`h-5 w-5`,strokeWidth:2.5})}),(0,J.jsx)(L,{label:`Frame`,active:a===`frame`,onClick:()=>o(a===`frame`?`none`:`frame`),children:(0,J.jsx)(oe,{className:`h-5 w-5`,strokeWidth:2.5})}),r]}),(0,J.jsx)(`div`,{className:`bg-background/90 backdrop-blur-sm`,style:{overflow:`hidden`,maxHeight:a===`none`?`0`:a===`draw`?`600px`:`400px`,transition:`max-height 0.25s ease-in-out`},children:(0,J.jsxs)(`div`,{className:`max-w-xl mx-auto w-full px-4 pb-5 pt-3`,children:[a===`font`&&(0,J.jsx)(`div`,{className:`flex gap-2 flex-wrap`,children:y.map(e=>(0,J.jsx)(`button`,{onClick:()=>p(e),className:`px-4 py-2.5 rounded-2xl text-base font-medium transition-all ${d.value===e.value?`bg-primary text-primary-foreground shadow-sm`:`bg-muted text-muted-foreground hover:text-foreground`}`,style:{fontFamily:e.family},children:e.label},e.value))}),a===`stationery`&&(0,J.jsx)(re,{selected:m,onSelect:h}),a===`frame`&&(0,J.jsx)(ae,{frame:g,frameTint:v,onFrameSelect:_,onFrameTintChange:b}),!(e=>[`none`,`font`,`stationery`,`frame`].includes(e))(a)&&i]})})),l,(0,J.jsx)(`div`,{className:`max-w-xl mx-auto w-full`,style:g===`none`?{padding:`0 16px 16px`}:{padding:`28px 44px 44px`},children:(0,J.jsxs)(`div`,{ref:O,className:`relative`,style:{containerType:`inline-size`},children:[(0,J.jsx)(N,{stationery:m,frame:g,frameTint:v,className:`rounded-3xl shadow-[0_2px_12px_rgba(0,0,0,0.06)]`,children:(0,J.jsxs)(`div`,{className:`relative z-10 flex flex-col`,style:{aspectRatio:`5 / 4`,padding:`5cqw`},children:[s?.({lineHeightPx:k,stationeryTextColor:j,stationeryLineColor:M,resolvedFontFamily:I}),(0,J.jsxs)(`div`,{className:`flex flex-col items-end`,style:{paddingTop:`4cqw`,gap:`3cqw`,paddingRight:`4cqw`},children:[(0,J.jsxs)(H,{value:x||`__none__`,onValueChange:e=>S(e===`__none__`?``:e),children:[(0,J.jsx)(B,{className:`w-auto h-auto focus:ring-0 focus:ring-offset-0 ring-0 ring-offset-0 outline-none rounded-2xl border-0 shadow-none flex-row-reverse gap-3 [&>span]:text-right`,style:{fontSize:`4cqw`,padding:`2.5cqw 4cqw`,marginRight:`-4cqw`,color:x?j:`${j}44`,backgroundColor:parseInt(j.slice(j.indexOf(`(`)+1),10)<128?`rgba(0,0,0,0.07)`:`rgba(255,255,255,0.18)`,fontFamily:I},children:(0,J.jsx)(V,{placeholder:`Closing...`})}),(0,J.jsxs)(z,{children:[(0,J.jsx)(R,{value:`__none__`,children:(0,J.jsx)(`span`,{className:`text-muted-foreground italic`,children:`None`})}),w.map(e=>(0,J.jsx)(R,{value:e,children:e},e))]})]}),(0,J.jsx)(`input`,{type:`text`,dir:`auto`,value:T,onChange:e=>E(e.target.value),onFocus:()=>o(`none`),maxLength:50,placeholder:`Your Name`,className:`bg-transparent border-none font-semibold text-right focus:outline-none placeholder:opacity-60`,style:{fontSize:`4.2cqw`,color:j,width:`60%`,fontFamily:I}})]})]})}),c&&(0,J.jsx)(`div`,{className:`absolute inset-0 rounded-3xl overflow-hidden pointer-events-none`,style:{zIndex:20},children:(0,J.jsx)(`div`,{className:`relative w-full h-full`,children:c})})]})})]})}export{ee as n,se as t}; // @license-end