@frank-auth/react
Version:
Flexible and customizable React UI components for Frank Authentication
6 lines (5 loc) • 5.62 kB
JavaScript
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("../utils/theme.cjs"),a=require("./defaults.cjs");var y=Object.defineProperty,u=(r,e,t)=>e in r?y(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,i=(r,e,t)=>u(r,typeof e!="symbol"?e+"":e,t);function l(r){const e={...r.colors,background:"#0f172a",foreground:"#f8fafc",card:"#1e293b",cardForeground:"#f8fafc",popover:"#1e293b",popoverForeground:"#f8fafc",muted:"#334155",mutedForeground:"#94a3b8",accent:"#334155",accentForeground:"#f8fafc",border:"#334155",input:"#334155",ring:r.palette.primary.DEFAULT};return{...r,mode:"dark",colors:e,palette:{...r.palette,primary:{...r.palette.primary,DEFAULT:r.colors.primary[400],foreground:"#000000"},secondary:{...r.palette.secondary,DEFAULT:r.colors.secondary[400],foreground:"#000000"}}}}const m={...a.DEFAULT_THEME_CONFIG,colors:{...a.DEFAULT_THEME_CONFIG.colors,primary:o.generateColorPalette("#3b82f6")},palette:{...a.DEFAULT_COLOR_PALETTE,primary:o.generateColorPalette("#3b82f6")}},E={...a.DEFAULT_THEME_CONFIG,colors:{...a.DEFAULT_THEME_CONFIG.colors,primary:o.generateColorPalette("#8b5cf6"),secondary:o.generateColorPalette("#6366f1")},palette:{...a.DEFAULT_COLOR_PALETTE,primary:o.generateColorPalette("#8b5cf6"),secondary:o.generateColorPalette("#6366f1")}},f={...a.DEFAULT_THEME_CONFIG,colors:{...a.DEFAULT_THEME_CONFIG.colors,primary:o.generateColorPalette("#10b981"),secondary:o.generateColorPalette("#059669")},palette:{...a.DEFAULT_COLOR_PALETTE,primary:o.generateColorPalette("#10b981"),secondary:o.generateColorPalette("#059669")}},T={...a.DEFAULT_THEME_CONFIG,colors:{...a.DEFAULT_THEME_CONFIG.colors,primary:o.generateColorPalette("#f97316").DEFAULT,secondary:o.generateColorPalette("#ea580c").DEFAULT},palette:{...a.DEFAULT_COLOR_PALETTE,primary:o.generateColorPalette("#f97316"),secondary:o.generateColorPalette("#ea580c")}},h={...a.DEFAULT_THEME_CONFIG,colors:{...a.DEFAULT_THEME_CONFIG.colors,primary:o.generateColorPalette("#ec4899").DEFAULT,secondary:o.generateColorPalette("#db2777").DEFAULT},palette:{...a.DEFAULT_COLOR_PALETTE,primary:o.generateColorPalette("#ec4899"),secondary:o.generateColorPalette("#db2777")}},p={blue:m,purple:E,green:f,orange:T,pink:h};class c{constructor(e){i(this,"currentTheme"),i(this,"systemPreference"),i(this,"listeners",new Set),this.currentTheme=this.mergeTheme(a.DEFAULT_THEME_CONFIG,e),this.systemPreference=this.detectSystemPreference(),typeof window<"u"&&window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",()=>{this.systemPreference=this.detectSystemPreference(),this.updateTheme()})}getTheme(){return{...this.currentTheme}}setTheme(e){this.currentTheme=this.mergeTheme(this.currentTheme,e),this.updateTheme()}applyPreset(e){this.currentTheme={...p[e]},this.updateTheme()}setMode(e){this.currentTheme.mode=e,this.updateTheme()}getEffectiveMode(){return this.currentTheme.mode==="system"?this.systemPreference==="dark"?"dark":"light":this.currentTheme.mode==="dark"?"dark":"light"}applyBranding(e){e.colors?.primary&&(this.currentTheme.palette.primary=o.generateColorPalette(e.colors.primary)),e.colors?.secondary&&(this.currentTheme.palette.secondary=o.generateColorPalette(e.colors.secondary)),e.fonts?.primary&&(this.currentTheme.typography.fontFamily.sans=[e.fonts.primary,...this.currentTheme.typography.fontFamily.sans]),this.updateTheme()}generateCSSVariables(){const e=this.getResolvedTheme();return o.ThemeUtils.generateCSSVariables(e)}applyToDOM(){if(typeof document>"u")return;const e=this.generateCSSVariables(),t=document.documentElement;Object.entries(e).forEach(([s,d])=>{t.style.setProperty(s,d)});const n=this.getEffectiveMode();t.classList.remove("light","dark"),t.classList.add(n)}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}detectSystemPreference(){return typeof window>"u"?"light":window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}mergeTheme(e,t){return t?{...e,...t,colors:{...e.colors,...t.colors},typography:{...e.typography,...t.typography,fontFamily:{...e.typography.fontFamily,...t.typography?.fontFamily},fontSize:{...e.typography.fontSize,...t.typography?.fontSize},fontWeight:{...e.typography.fontWeight,...t.typography?.fontWeight}},spacing:{...e.spacing,...t.spacing},borderRadius:{...e.borderRadius,...t.borderRadius},shadows:{...e.shadows,...t.shadows},animations:{...e.animations,...t.animations,duration:{...e.animations.duration,...t.animations?.duration},timingFunction:{...e.animations.timingFunction,...t.animations?.timingFunction},keyframes:{...e.animations.keyframes,...t.animations?.keyframes}}}:{...e}}getResolvedTheme(){return this.getEffectiveMode()==="dark"&&this.currentTheme.mode!=="dark"?l(this.currentTheme):this.currentTheme}updateTheme(){this.applyToDOM(),this.listeners.forEach(e=>e(this.currentTheme))}}function g(r){return new c(r)}function _(r){const t=new c(r).generateCSSVariables();return`:root {
${Object.entries(t).map(([n,s])=>`${n}: ${s};`).join(`
`)}
}`}function F(r){try{if(r.colors){const e=["primary","secondary","background","foreground"];for(const t of e)if(!(t in r.colors))return!1}return!(r.typography&&r.typography.fontFamily&&!Array.isArray(r.typography.fontFamily.sans))}catch{return!1}}exports.DEFAULT_THEME_CONFIG=a.DEFAULT_THEME_CONFIG;exports.BLUE_THEME=m;exports.GREEN_THEME=f;exports.ORANGE_THEME=T;exports.PINK_THEME=h;exports.PURPLE_THEME=E;exports.THEME_PRESETS=p;exports.ThemeManager=c;exports.createDarkTheme=l;exports.createThemeManager=g;exports.getThemeCSS=_;exports.validateTheme=F;
//# sourceMappingURL=theme.cjs.map