PageSourceSearch

https://rebelbase.social/assets/useTheme-BH_fAl9K.js

js rebelbase.social collected 2026-10-07 02:07:36 UTC 17,169 bytes, 4 lines download raw bytes

1// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-3.0-or-later
2// @source: https://gitlab.com/soapbox-pub/ditto/-/tree/main
3import{o as e}from"./rolldown-runtime-DAXXjFlN.js";import{qi as t}from"./lucide-icons-CItI72Jx.js";import{h as n}from"./useQuery-Ctvfrh1W.js";import{t as r}from"./useAppContext-DJPYVUf_.js";import{r as i}from"./useEncryptedSettings-kUKRqdMX.js";import{i as a}from"./fontLoader-vUn-ePfV.js";import{r as o}from"./sanitizeUrl-Bk5f35GN.js";import{t as s}from"./useCurrentUser-C_Di2And.js";import{t as c}from"./useNostrPublish-B6VbdWNQ.js";var l=e(t(),1);function u(e){let t=e.trim().replace(/%/g,``).split(/\s+/).map(Number);return{h:t[0],s:t[1],l:t[2]}}function d(e,t,n){return`${Math.round(e*10)/10} ${Math.round(t*10)/10}% ${Math.round(n*10)/10}%`}function f(e,t,n){t/=100,n/=100;let r=t=>(t+e/30)%12,i=t*Math.min(n,1-n),a=e=>n-i*Math.max(-1,Math.min(r(e)-3,Math.min(9-r(e),1)));return[Math.round(a(0)*255),Math.round(a(8)*255),Math.round(a(4)*255)]}function p(e,t,n){e/=255,t/=255,n/=255;let r=Math.max(e,t,n),i=Math.min(e,t,n),a=(r+i)/2;if(r===i)return{h:0,s:0,l:a*100};let o=r-i,s=a>.5?o/(2-r-i):o/(r+i),c=0;return c=r===e?((t-n)/o+(t<n?6:0))/6:r===t?((n-e)/o+2)/6:((e-t)/o+4)/6,{h:c*360,s:s*100,l:a*100}}function m(e){return/^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/.test(e)}function h(e){return e=e.replace(`#`,``),e.length===3&&(e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]),[parseInt(e.slice(0,2),16),parseInt(e.slice(2,4),16),parseInt(e.slice(4,6),16)]}function g(e,t,n){return`#`+[e,t,n].map(e=>e.toString(16).padStart(2,`0`)).join(``)}function _(e){let[t,n,r]=h(e),{h:i,s:a,l:o}=p(t,n,r);return d(i,a,o)}
3function v(e){let{h:t,s:n,l:r}=u(e),[i,a,o]=f(t,n,r);return g(i,a,o)}function y(e,t,n){let r=[e,t,n].map(e=>(e/=255,e<=.03928?e/12.92:((e+.055)/1.055)**2.4));return .2126*r[0]+.7152*r[1]+.0722*r[2]}function ee(e,t){let n=y(...e),r=y(...t),i=Math.max(n,r),a=Math.min(n,r);return(i+.05)/(a+.05)}function b(e){let{h:t,s:n,l:r}=u(e),[i,a,o]=f(t,n,r);return y(i,a,o)<.2}function te(){if(typeof document>`u`)return`light`;let e=getComputedStyle(document.documentElement).getPropertyValue(`--background`).trim();return e&&b(e)?`dark`:`light`}function x(e,t){let{h:n,s:r,l:i}=u(e);return d(n,r,Math.min(100,i+t))}function S(e,t){let{h:n,s:r,l:i}=u(e);return d(n,r,Math.max(0,i-t))}function ne(e){let{h:t,s:n,l:r}=u(e),[i,a,o]=f(t,n,r);return y(i,a,o)>.5?`222.2 84% 4.9%`:`0 0% 100%`}function re(e,t,n){let r=b(e),i=r?x(e,2):e,a=r?x(e,2):e,o=r?x(e,8):S(e,4),s=r?x(e,8):S(e,4),c=r?d(u(n).h,u(n).s*.4,30):d(u(n).h,u(n).s*.5,82),l=c,f=u(t),p=r?d(f.h,Math.max(f.s-20,0),Math.max(f.l-30,40)):d(f.h,Math.max(f.s-30,0),Math.min(f.l+35,55)),m=t,h=t,g=t,_=ne(n);return{background:e,foreground:t,card:i,cardForeground:m,popover:a,popoverForeground:h,primary:n,primaryForeground:_,secondary:o,secondaryForeground:g,muted:s,mutedForeground:p,accent:n,accentForeground:_,destructive:r?`0 72% 51%`:`0 84.2% 60.2%`,destructiveForeground:r?`0 0% 95%`:`210 40% 98%`,border:c,input:l,ring:n}}function ie(e,t){let[n,r,i]=h(e),a=e=>Math.max(0,Math.round(e*(1-t)));return g(a(n),a(r),a(i))}function ae(e,t){let[n,r,i]=h(e),a=e=>Math.min(255,Math.round(e+(255-e)*t));return g(a(n),a(r),a(i))}function C(e,t,n){let[r,i,a]=h(e),[o,s,c]=h(t);return g(Math.round(r+(o-r)*n),Math.round(i+(s-i)*n),Math.round(a+(c-a)*n))}function w(e){if(!e)return .5;let t=parseInt(e.slice(1,3),16)/255,n=parseInt(e.slice(3,5),16)/255,r=parseInt(e.slice(5,7),16)/255,i=e=>e<=.03928?e/12.92:((e+.055)/1.055)**2.4;return .2126*i(t)+.7152*i(n)+.0722*i(r)}function T(e){return e.length===0||e.reduce((e,t)=>e+w(t),0)/e.length>.5?`rgba(0,0,0,0.75)`:`rgba(255,255,255,0.90)`}function E(e){return w(e)>.5?`rgba(0,0,0,0.75)`:`rgba(255,255,255,0.90)`}function D(e){return e.length===0||e.reduce((e,t)=>e+w(t),0)/e.length>.5?`rgba(0,0,0,0.30)`:`rgba(255,255,255,0.35)`}function O(e){return w(e)>.5?`rgba(0,0,0,0.30)`:`rgba(255,255,255,0.35)`}function k(e){return e.length===0||e.reduce((e,t)=>e+w(t),0)/e.length>.5?`rgba(0,0,0,0.08)`:`rgba(255,255,255,0.15)`}function oe(e){return w(e)>.5?`rgba(0,0,0,0.08)`:`rgba(255,255,255,0.15)`}var A={light:{background:`270 50% 97%`,text:`270 25% 12%`,primary:`270 65% 55%`},dark:{background:`228 20% 10%`,text:`210 40% 98%`,primary:`258 70% 60%`}},se={pink:{label:`Pink`,emoji:`🌸`,featured:!0,colors:{background:`330 100% 96%`,text:`330 30% 10%`,primary:`330 90% 60%`},font:{family:`Comfortaa`},background:{url:`https://blossom.ditto.pub/2c9d4fe206f39b81655eab559998a89e1dca12f4db81c10fd8f472c69fe9c68a.jpeg`,mode:`cover`,mimeType:`image/jpeg`}}
3,toxic:{label:`Toxic`,emoji:`☢️`,colors:{background:`130 30% 7%`,text:`120 40% 92%`,primary:`128 70% 42%`},font:{family:`JetBrains Mono`}},sunset:{label:`Sunset`,emoji:`🌅`,colors:{background:`20 40% 96%`,text:`15 30% 12%`,primary:`15 85% 55%`},font:{family:`Lora`}},skater:{label:`Skater`,emoji:`🛹`,featured:!0,colors:{background:`0 0% 42%`,text:`0 0% 100%`,primary:`80 100% 50%`},font:{family:`Rubik Maps`},background:{url:`https://blossom.primal.net/9c4262aaa53d8feae41b3b6206647e25c6f388d9e836fb3e8abcf9be72be493e.png`,mode:`cover`,mimeType:`image/png`}},kawaii:{label:`Kawaii`,emoji:`🌸`,featured:!0,colors:{background:`340 60% 95%`,text:`345 30% 35%`,primary:`340 100% 76%`},font:{family:`Cherry Bomb One`},background:{url:`https://blossom.ditto.pub/4e11a3ca749f9cc8989b61cb9efe78682533d2836eccaf4bccf104dd7b583e09.png`,mode:`cover`,mimeType:`image/png`}},grunge:{label:`Grunge`,emoji:`🖤`,featured:!0,colors:{background:`276 40% 8%`,text:`0 0% 75%`,primary:`328 100% 54%`},font:{family:`Lacquer`},background:{url:`https://blossom.primal.net/9fa0f1f7cd7da344f3e1db6ecfbdbeb2bb0763d3eaccbc0f5368871d0421b50b.png`,mode:`cover`,mimeType:`image/png`}},mspaint:{label:`MS Paint`,emoji:`🖥️`,featured:!0,colors:{background:`200 20% 95%`,text:`0 0% 10%`,primary:`240 100% 50%`},font:{family:`Silkscreen`},background:{url:`https://blossom.ditto.pub/946fedd46ec6b283472c0b3a102817ff414a6d640517df5c679bb63830ef21bf.png`,mode:`cover`,mimeType:`image/png`}},retropop:{label:`Retro Pop`,emoji:`💿`,featured:!0,colors:{background:`244 100% 92%`,text:`40 40% 10%`,primary:`260 50% 70%`},font:{family:`Bungee Shade`},background:{url:`https://blossom.ditto.pub/3832abebc944668c4c0bd34309b0dfe120054671e20ca8c8e9abbb24114c972e.png`,mode:`cover`,mimeType:`image/png`}},bubblegum:{label:`Bubblegum`,emoji:`🍬`,featured:!0,colors:{background:`0 0% 100%`,text:`285 25% 31%`,primary:`279 100% 50%`},font:{family:`Barriecito`},background:{url:`https://blossom.ditto.pub/edd3139e0c4d60b96dcf54edbe7410b1f58d9e5753c8d481fe9bb6812aca00d4.png`,mode:`cover`,mimeType:`image/png`}},gamer:{label:`Gamer`,emoji:`⚡`,featured:!0,colors:{background:`140 60% 4%`,text:`120 100% 50%`,primary:`195 100% 50%`},font:{family:`Press Start 2P`},background:{url:`https://blossom.ditto.pub/c5597382d7da762dcce32b5b5dbbd95a719faee5cad7c356df1956648b58be69.png`,mode:`cover`,mimeType:`image/png`}},cottage:{label:`Cottage`,emoji:`🌿`,featured:!0,colors:{background:`100 25% 92%`,text:`100 20% 12%`,primary:`43 80% 55%`},font:{family:`Lora`},background:{url:`https://images.unsplash.com/photo-1470252649378-9c29740c9fa8?w=1920&q=80`,mode:`cover`,mimeType:`image/jpeg`}},midnight:{label:`Midnight`,emoji:`🌃`,featured:!0,colors:{background:`0 0% 9%`,text:`0 0% 95%`,primary:`190 100% 50%`},font:{family:`Inter`},background:{url:`https://images.unsplash.com/photo-1519501025264-65ba15a82390?w=1920&q=80`,mode:`cover`,mimeType:`image/jpeg`}},sky:{label:`Sky`,emoji:`☁️`,featured:!0,colors:{background:`200 60% 88%`,text:`220 30% 15%`,primary:`280 55% 65%`},font:{family:`Nunito`},background:{url:`https://images.unsplash.com/photo-1517483000871-1dbf64a6e1c6?w=1920&q=80`,mode:`cover`,mimeType:`image/jpeg`}},motherboard:{label:`Motherboard`,emoji:`🪟`,featured:!0,colors:{background:`0 0% 75%`,text:`0 0% 5%`,primary:`240 100% 30%`},font:{family:`Courier Prime`},background:{url:`https://images.unsplash.com/photo-1518770660439-4636190af475?w=1920&q=80`,mode:`cover`,mimeType:`image/jpeg`}},plush:{label:`Plush`,emoji:`🧸`,colors:{background:`265 55% 72%`,text:`55 100% 50%`,primary:`210 90% 55%`},font:{family:`Comic Neue`},background:{url:`https://images.unsplash.com/photo-1550684376-efcbd6e3f031?w=1920&q=80`,mode:`cover`,mimeType:`image/jpeg`}},galaxy:{label:`Galaxy`,emoji:`🌌`,featured:!0,colors:{background:`260 40% 8%`,text:`220 30% 95%`,primary:`270 80% 65%`},font:{family:`DM Sans`},background:{url:`https://images.unsplash.com/photo-1462331940025-496dfbfc7564?w=1920&q=80`,mode:`cover`,mimeType:`image/jpeg`}},ocean:{label:`Ocean`,emoji:`🌊`,featured:!0,colors:{background:`195 50% 12%`,text:`185 30% 92%`,primary:`175 70% 50%`},font:{family:`Nunito`},background:{url:`https://images.unsplash.com/photo-1507525428034-b723cf961d3e?w=1920&q=80`,mode:`cover`,mimeType:`image/jpeg`}},forest:{label:`Forest`,emoji:`🌲`,featured:!0,colors:{background:`150 30% 10%`,text:`120 20% 90%`,primary:`150 60% 45%`},font:{family:`Merriweather`},background:{url:`https://images.unsplash.com/photo-1448375240586-882707db888b?w=1920&q=80`,mode:`cover`,mimeType:`image/jpeg`}},clearsky:{label:`Clear Sky Vibes`,emoji:`✨`,featured:!0,colors:{background:`228 37% 8%`,text:`185 100% 72%`,primary:`300 100% 60%`},font:{family:`Comfortaa`},background:{url:`https://images.unsplash.com/photo-1519681393784-d120267933ba?w=1920&q=80`,mode:`cover`,mimeType:`image/jpeg`}},silenttorii:{label:`Silent Torii`,emoji:`⛩️`,featured:!0,colors:{primary:`3 62% 50%`,text:`0 0% 100%`,background:`0 7% 22%`},font:{family:`DM Sans`},background:{url:`https://blossom.ditto.pub/7a609544b62918264b6cfd1f05ae38f9ed9a7922465a4ecc2edbb1a769f887d0.jpeg`,mode:`cover`,mimeType:`image/jpeg`}},quiethorizon:{label:`Quiet Horizon`,emoji:`🌅`,featured:!0,colors:{primary:`170 15% 39%`,text:`0 0% 100%`,background:`0 7% 22%`},font:{family:`Lora`},background:{url:`https://blossom.ditto.pub/3fc3800e0551340c000a0ac75496e642f6dbd5bddf17c5ba7f4c4ebfc8bae55f.
3jpeg`,mode:`cover`,mimeType:`image/jpeg`}},wherepathsmeet:{label:`Where Paths Meet`,emoji:`🌉`,featured:!0,colors:{primary:`180 11% 78%`,text:`120 3% 81%`,background:`180 19% 15%`},font:{family:`DM Sans`},background:{url:`https://blossom.ditto.pub/a9f38f1bda2d7d984167f3b1197d3d2c7280a650ad609d24f97e35795f7cfd17.jpeg`,mode:`cover`,mimeType:`image/jpeg`}},once:{label:`Once`,emoji:`🎲`,featured:!0,colors:{primary:`217 94% 72%`,text:`120 3% 81%`,background:`210 17% 7%`},font:{family:`Outfit`},background:{url:`https://picsum.photos/1920/1080`,mode:`cover`,mimeType:`image/jpeg`}}};function j(e){return`--${e.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`)}`}function M(e){return`:root { ${Object.entries(e).map(([e,t])=>`${j(e)}: ${t};`).join(` `)} }`}function N(e){return re(e.background,e.text,e.primary)}function P(e){return M(N(e))}function F(e){return e===`system`?window.matchMedia(`(prefers-color-scheme: dark)`).matches?`dark`:`light`:e}function I(e,t){return t?.[e]??{colors:A[e]}}var L=36767,R=16767;function z(e){return[`background`,`text`,`primary`].map(t=>[`c`,v(e[t]),t])}function B(e){let t=new Map;for(let n of e)n[0]===`c`&&n[1]&&n[2]&&t.set(n[2],n[1]);let n=t.get(`background`),r=t.get(`text`),i=t.get(`primary`);return!n||!r||!i||!m(n)||!m(r)||!m(i)?null:{background:_(n),text:_(r),primary:_(i)}}function V(e,t){let n=[];if(e?.family){let t=[`f`,e.family];e.url?t.push(e.url):t.push(``),t.push(`body`),n.push(t)}if(t?.family){let e=[`f`,t.family];t.url?e.push(t.url):e.push(``),e.push(`title`),n.push(e)}return n}function H(e){let t,n;for(let r of e){if(r[0]!==`f`||!r[1])continue;let e=r[3],i={family:r[1]},a=o(r[2]);a&&(i.url=a),e===`title`?n||=i:t||=i}return{font:t,titleFont:n}}function U(e){if(!e?.url)return[];let t=[`bg`,`url ${e.url}`];return e.mode&&t.push(`mode ${e.mode}`),e.mimeType&&t.push(`m ${e.mimeType}`),e.dimensions&&t.push(`dim ${e.dimensions}`),e.blurhash&&t.push(`blurhash ${e.blurhash}`),[t]}function W(e){let t=e.find(([e])=>e===`bg`);if(!t)return;let n=new Map;for(let e=1;e<t.length;e++){let r=t[e],i=r.indexOf(` `);i!==-1&&n.set(r.slice(0,i),r.slice(i+1))}let r=o(n.get(`url`));if(!r)return;let i={url:r},a=n.get(`mode`);return(a===`cover`||a===`tile`)&&(i.mode=a),i.mimeType=n.get(`m`),i.dimensions=n.get(`dim`),i.blurhash=n.get(`blurhash`),i}function G(e){if(e.kind!==36767)return null;let t=e.tags.find(([e])=>e===`d`)?.[1];if(!t)return null;let n=e.tags.find(([e])=>e===`title`)?.[1];if(!n)return null;let r=e.tags.find(([e])=>e===`description`)?.[1],i=B(e.tags);if(!i)return null;let{font:a,titleFont:o}=H(e.tags);return{identifier:t,title:n,description:r,colors:i,font:a,titleFont:o,background:W(e.tags),event:e}}function ce(e,t,n,r){let i=[[`d`,e],...z(n.colors),...V(n.font,n.titleFont),...U(n.background),[`title`,t],[`alt`,`Custom theme: ${t}`],[`t`,`theme`]];return r&&i.push([`description`,r]),i}function le(e){return e.toLowerCase().trim().replace(/[^a-z0-9\s-]/g,``).replace(/\s+/g,`-`).replace(/-+/g,`-`).slice(0,64)}function K(e){if(e.kind!==16767)return null;let t=B(e.tags);if(!t)return null;let{font:n,titleFont:r}=H(e.tags);return{colors:t,font:n,titleFont:r,background:W(e.tags),sourceRef:e.tags.find(([e])=>e===`a`)?.[1],event:e}}function ue(e,t,n,r){let i=[...z(e.colors),...V(e.font,e.titleFont),...U(e.background),[`alt`,`Active profile theme`]];return e.title&&i.push([`title`,e.title]),r&&i.push([`description`,r]),t&&n&&i.push([`a`,`${L}:${t}:${n}`]),i}function q(e){let t=e.titleFont??e.font;return{...e,font:e.font?{family:e.font.family,url:a(e.font.family,e.font.url)}:void 0,titleFont:t?{family:t.family,url:a(t.family,t.url)}:void 0}}function J(){let{user:e}=s(),{mutateAsync:t,isPending:r}=c(),i=n();return{publishTheme:(0,l.useCallback)(async n=>{if(!e)throw Error(`Must be logged in`);let r=n.identifier||le(n.title),a=q(n.themeConfig),o=ce(r,n.title,a,n.description);return await t({kind:L,content:``,tags:o}),i.invalidateQueries({queryKey:[`userThemes`,e.pubkey]}),r},[e,t,i]),setActiveTheme:(0,l.useCallback)(async n=>{if(!e)throw Error(`Must be logged in`);let r=ue(q(n.themeConfig),n.sourceAuthor,n.sourceIdentifier,n.description),a=K({id:``,pubkey:e.pubkey,created_at:Math.floor(Date.now()/1e3),kind:R,tags:r,content:``,sig:``});i.setQueryData([`activeProfileTheme`,e.pubkey],a),await t({kind:R,content:``,tags:r}),i.invalidateQueries({queryKey:[`activeProfileTheme`,e.pubkey]})},[e,t,i]),deleteTheme:(0,l.useCallback)(async n=>{if(!e)throw Error(`Must be logged in`);await t({kind:5,content:``,tags:[[`e`,n.event.id],[`a`,`${L}:${e.pubkey}:${n.identifier}`],[`k`,String(L)]]}),i.setQueryData([`userThemes`,e.pubkey],e=>e?.filter(e=>e.identifier!==n.identifier)??[]),i.invalidateQueries({queryKey:[`feed`]}),i.invalidateQueries({queryKey:[`streamKind`]})},[e,t,i]),clearActiveTheme:(0,l.useCallback)(async()=>
3{if(!e)throw Error(`Must be logged in`);i.setQueryData([`activeProfileTheme`,e.pubkey],null),await t({kind:R,content:``,tags:[]}),i.invalidateQueries({queryKey:[`activeProfileTheme`,e.pubkey]})},[e,t,i]),isPending:r}}var Y=!1,X=null;function de(){Y=!0,X=null}function Z(){Y=!1}function Q(){return Y}function $(e){X={...X,...e}}function fe(){let e=X;return X=null,e}function pe(){let{config:e,updateConfig:t}=r(),{updateSettings:n}=i(),{setActiveTheme:a}=J(),{user:o}=s(),c=(0,l.useRef)(void 0),u=(0,l.useRef)(void 0),d=(0,l.useCallback)(e=>{o&&(c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{n.mutateAsync(e).catch(e=>{console.error(`Failed to sync theme to encrypted storage:`,e)})},1e3))},[o,n]),f=(0,l.useCallback)(t=>{!o||!e.autoShareTheme||(u.current&&clearTimeout(u.current),u.current=setTimeout(()=>{a({themeConfig:t}).catch(e=>{console.error(`Failed to auto-publish theme to profile:`,e)})},2e3))},[o,e.autoShareTheme,a]),p=(0,l.useCallback)(n=>{let r=document.createElement(`style`);r.textContent=`*, *::before, *::after { transition: none !important; }`,document.head.appendChild(r);let i=F(n),a=P(i===`custom`?e.customTheme?.colors??A.dark:I(i,e.themes).colors),o=document.getElementById(`theme-vars`);o||(o=document.createElement(`style`),o.id=`theme-vars`,document.head.appendChild(o)),o.textContent=a,document.documentElement.className=i,requestAnimationFrame(()=>r.remove()),t(e=>({...e,theme:n})),Q()?$({theme:n}):d({theme:n})},[e.themes,e.customTheme?.colors,t,d]),m=(0,l.useCallback)(e=>{let n=`colors`in e?e:{colors:e},r={...n,background:n.background??void 0};t(e=>({...e,theme:`custom`,customTheme:r})),Q()?$({theme:`custom`,customTheme:r}):(d({theme:`custom`,customTheme:r}),f(r))},[t,d,f]),h=(0,l.useCallback)(e=>{t(t=>({...t,autoShareTheme:e})),o&&n.mutateAsync({autoShareTheme:e}).catch(e=>{console.error(`Failed to sync autoShareTheme to encrypted storage:`,e)})},[o,t,n]);return{theme:e.theme,customTheme:e.customTheme,themes:e.themes,autoShareTheme:e.autoShareTheme,setTheme:p,applyCustomTheme:m,setAutoShareTheme:h}}export{v as A,d as C,w as D,y as E,T as F,D as I,u as L,b as M,ae as N,_ as O,k as P,g as R,ie as S,ee as T,j as _,J as a,O as b,K as c,P as d,A as f,se as g,I as h,fe as i,f as j,h as k,G as l,F as m,de as n,R as o,N as p,Z as r,L as s,pe as t,M as u,oe as v,te as w,C as x,E as y,p as z};
4// @license-end

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.