@getdashfy/themes 0.1.0

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.
@@ -0,0 +1,318 @@
1
+ import { ThemeMode } from '@getdashfy/types';
2
+ export { ThemeMode } from '@getdashfy/types';
3
+
4
+ interface ThemeColors {
5
+ background: string;
6
+ foreground: string;
7
+ card: string;
8
+ cardForeground: string;
9
+ popover: string;
10
+ popoverForeground: string;
11
+ primary: string;
12
+ primaryForeground: string;
13
+ secondary: string;
14
+ secondaryForeground: string;
15
+ muted: string;
16
+ mutedForeground: string;
17
+ accent: string;
18
+ accentForeground: string;
19
+ destructive: string;
20
+ destructiveForeground: string;
21
+ success: string;
22
+ successForeground: string;
23
+ warning: string;
24
+ warningForeground: string;
25
+ error: string;
26
+ errorForeground: string;
27
+ info: string;
28
+ infoForeground: string;
29
+ border: string;
30
+ input: string;
31
+ ring: string;
32
+ chart1: string;
33
+ chart2: string;
34
+ chart3: string;
35
+ chart4: string;
36
+ chart5: string;
37
+ }
38
+ interface ThemeFonts {
39
+ importHref: string;
40
+ cssVariables: {
41
+ '--font-sans': string;
42
+ '--font-serif'?: string;
43
+ '--font-mono': string;
44
+ };
45
+ }
46
+ interface Theme {
47
+ id: string;
48
+ name: string;
49
+ displayName: string;
50
+ fonts?: ThemeFonts;
51
+ light: {
52
+ colors: ThemeColors;
53
+ cssVariables: Record<string, string>;
54
+ };
55
+ dark: {
56
+ colors: ThemeColors;
57
+ cssVariables: Record<string, string>;
58
+ };
59
+ }
60
+
61
+ /**
62
+ * Default theme for Dashfy (shadcn/ui default).
63
+ */
64
+ declare const defaultTheme: Theme;
65
+
66
+ /**
67
+ * Kodama Grove theme for Dashfy.
68
+ *
69
+ * @link https://tweakcn.com/editor/theme?theme=kodama-grove
70
+ */
71
+ declare const kodamaGroveTheme: Theme;
72
+
73
+ /**
74
+ * Midnight Blue theme for Dashfy.
75
+ */
76
+ declare const midnightBlueTheme: Theme;
77
+
78
+ /**
79
+ * Minimal monochrome theme for Dashfy.
80
+ */
81
+ declare const minimalTheme: Theme;
82
+
83
+ /**
84
+ * Nord theme for Dashfy.
85
+ */
86
+ declare const nordTheme: Theme;
87
+
88
+ declare const themes: {
89
+ readonly default: Theme;
90
+ readonly kodamaGrove: Theme;
91
+ readonly midnightBlue: Theme;
92
+ readonly minimal: Theme;
93
+ readonly nord: Theme;
94
+ };
95
+ type PresetThemeId = keyof typeof themes;
96
+
97
+ /**
98
+ * [Geist](https://fonts.google.com/specimen/Geist) + [Geist Mono](https://fonts.google.com/specimen/Geist+Mono) via the [Google Fonts CSS API](https://developers.google.com/fonts/docs/css2).
99
+ * `applyTheme` injects `importHref` as `<link rel="stylesheet">` on the document.
100
+ */
101
+ declare const DEFAULT_FONT: ThemeFonts;
102
+ /**
103
+ * Geist Mono ([Google Fonts](https://fonts.google.com/specimen/Geist+Mono)).
104
+ */
105
+ declare const DEFAULT_FONT_MONO: ThemeFonts;
106
+
107
+ declare const DEFAULT_FONTS_FALLBACK: Record<string, string>;
108
+ interface GoogleFontEntry {
109
+ /** Font family name exactly as it appears on fonts.google.com (e.g. `'Source Serif 4'`). */
110
+ family: string;
111
+ /** Numeric weights to load (default: `[400]`). */
112
+ weights?: number[];
113
+ /** Override the default fallback stack (e.g. `'serif'`). */
114
+ fallback?: string;
115
+ }
116
+ interface GoogleFontConfig {
117
+ sans: GoogleFontEntry;
118
+ serif?: GoogleFontEntry;
119
+ mono: GoogleFontEntry;
120
+ }
121
+ /**
122
+ * Build a {@link ThemeFonts} object from a declarative config, so you never
123
+ * have to hand-craft Google Fonts URLs or CSS variable fallback stacks.
124
+ *
125
+ * @example
126
+ * ```ts
127
+ * import { googleFont } from '@getdashfy/themes'
128
+ *
129
+ * const fonts = googleFont({
130
+ * sans: { family: 'Merriweather', weights: [400, 500, 600, 700], fallback: 'serif' },
131
+ * serif: { family: 'Source Serif 4', weights: [400, 500, 600, 700], fallback: 'serif' },
132
+ * mono: { family: 'JetBrains Mono', weights: [400, 500, 600, 700] },
133
+ * })
134
+ * ```
135
+ */
136
+ declare function googleFont(config: GoogleFontConfig): ThemeFonts;
137
+
138
+ /** Default theme to use when no theme is saved or selected. */
139
+ declare const DEFAULT_THEME: PresetThemeId;
140
+ /**
141
+ * Get a theme by ID.
142
+ *
143
+ * @param id - The theme identifier (e.g., 'default', 'minimal', 'nord')
144
+ * @returns The theme object
145
+ *
146
+ * @example
147
+ * ```ts
148
+ * import { getTheme } from '@getdashfy/themes'
149
+ *
150
+ * const minimalTheme = getTheme('minimal')
151
+ * console.log(minimalTheme.displayName) // "Minimal"
152
+ * ```
153
+ */
154
+ declare function getTheme(id: PresetThemeId): Theme;
155
+ /**
156
+ * Apply a theme by setting CSS variables on the document root element.
157
+ *
158
+ * This function:
159
+ * - Sets all theme CSS variables on `:root`
160
+ * - Adds a `data-theme` attribute for theme-specific CSS selectors
161
+ * - Applies the appropriate mode (light or dark) based on the current mode setting
162
+ * - Is safe to call in SSR environments (no-op when document is undefined)
163
+ *
164
+ * @param theme - The theme object to apply
165
+ * @param mode - Optional mode to apply ('light' or 'dark'). If not provided, uses current mode from DOM
166
+ *
167
+ * @example
168
+ * ```ts
169
+ * import { applyTheme, defaultTheme } from '@getdashfy/themes'
170
+ *
171
+ * // Apply default theme in light mode
172
+ * applyTheme(defaultTheme, 'light')
173
+ *
174
+ * // Apply default theme in dark mode
175
+ * applyTheme(defaultTheme, 'dark')
176
+ *
177
+ * // Apply theme using current mode from DOM
178
+ * applyTheme(defaultTheme)
179
+ * ```
180
+ */
181
+ declare function applyTheme(theme: Theme, mode?: ThemeMode): void;
182
+ /**
183
+ * Remove a theme by clearing its CSS variables from the document root.
184
+ *
185
+ * This function:
186
+ * - Removes all CSS variables defined by the theme
187
+ * - Removes the `data-theme` attribute
188
+ * - Is safe to call in SSR environments (no-op when document is undefined)
189
+ *
190
+ * @param theme - The theme object to remove
191
+ *
192
+ * @remarks
193
+ * Typically you would just apply a new theme instead of removing one.
194
+ * This function is useful for cleanup or testing scenarios.
195
+ *
196
+ * @example
197
+ * ```ts
198
+ * import { removeTheme, darkTheme } from '@getdashfy/themes'
199
+ *
200
+ * // Remove theme styling
201
+ * removeTheme(darkTheme)
202
+ * ```
203
+ */
204
+ declare function removeTheme(theme: Theme): void;
205
+ /**
206
+ * Get the currently applied theme ID from the document.
207
+ *
208
+ * Reads the `data-theme` attribute from the document root element.
209
+ *
210
+ * @returns The current theme ID, or null if no theme is applied or in SSR
211
+ *
212
+ * @example
213
+ * ```ts
214
+ * import { getCurrentTheme, applyTheme, darkTheme } from '@getdashfy/themes'
215
+ *
216
+ * applyTheme(darkTheme)
217
+ * const current = getCurrentTheme()
218
+ * console.log(current) // "dark"
219
+ * ```
220
+ */
221
+ declare function getCurrentTheme(): PresetThemeId | null;
222
+ /**
223
+ * Get an array of all available theme IDs.
224
+ *
225
+ * @returns Array of theme identifiers
226
+ *
227
+ * @example
228
+ * ```ts
229
+ * import { listThemes } from '@getdashfy/themes'
230
+ *
231
+ * const themeIds = listThemes()
232
+ * console.log(themeIds) // ["default", "minimal", "nord"]
233
+ *
234
+ * // Use in a theme selector
235
+ * themeIds.forEach(id => {
236
+ * console.log(`Available theme: ${id}`)
237
+ * })
238
+ * ```
239
+ */
240
+ declare function listThemes(): PresetThemeId[];
241
+ interface CreateThemeOptions {
242
+ /** Unique theme identifier (e.g., 'custom-blue') */
243
+ id: string;
244
+ /** Internal theme name (e.g., 'customBlue') */
245
+ name: string;
246
+ /** Human-readable name shown in UI (e.g., 'Custom Blue') */
247
+ displayName: string;
248
+ /** Partial color overrides for light mode */
249
+ lightColors: Partial<ThemeColors>;
250
+ /** Partial color overrides for dark mode (optional, defaults to lightColors) */
251
+ darkColors?: Partial<ThemeColors>;
252
+ /** Base theme to extend from (defaults to defaultTheme) */
253
+ baseTheme?: Theme;
254
+ /** Override typography / Google Fonts (defaults to base theme) */
255
+ fonts?: ThemeFonts;
256
+ }
257
+ /**
258
+ * Create a custom theme by extending an existing theme.
259
+ *
260
+ * This utility function creates a new theme object by:
261
+ * - Merging your custom colors with a base theme
262
+ * - Automatically generating CSS variables from color names
263
+ * - Converting camelCase color names to kebab-case CSS variables
264
+ * - Supports both light and dark mode colors
265
+ *
266
+ * @param options - Theme configuration options
267
+ * @returns A complete theme object ready to use with `applyTheme()`
268
+ *
269
+ * @example Basic custom theme
270
+ * ```ts
271
+ * import { createTheme, applyTheme } from '@getdashfy/themes'
272
+ *
273
+ * const myTheme = createTheme({
274
+ * id: 'ocean',
275
+ * name: 'ocean',
276
+ * displayName: 'Ocean Blue',
277
+ * lightColors: {
278
+ * primary: 'hsl(200 80% 50%)',
279
+ * secondary: 'hsl(180 70% 50%)',
280
+ * }
281
+ * })
282
+ *
283
+ * applyTheme(myTheme, 'light')
284
+ * ```
285
+ *
286
+ * @example Theme with different light and dark colors
287
+ * ```ts
288
+ * import { createTheme, applyTheme } from '@getdashfy/themes'
289
+ *
290
+ * const customTheme = createTheme({
291
+ * id: 'custom',
292
+ * name: 'custom',
293
+ * displayName: 'Custom Theme',
294
+ * lightColors: { primary: 'hsl(200 80% 50%)' },
295
+ * darkColors: { primary: 'hsl(200 80% 70%)' }
296
+ * })
297
+ *
298
+ * applyTheme(customTheme, 'dark')
299
+ * ```
300
+ *
301
+ * @example Extending a different base theme
302
+ * ```ts
303
+ * import { createTheme, minimalTheme, applyTheme } from '@getdashfy/themes'
304
+ *
305
+ * const customMinimal = createTheme({
306
+ * id: 'custom-minimal',
307
+ * name: 'customMinimal',
308
+ * displayName: 'Custom Minimal',
309
+ * lightColors: { primary: 'hsl(0 0% 20%)' },
310
+ * baseTheme: minimalTheme
311
+ * })
312
+ *
313
+ * applyTheme(customMinimal, 'light')
314
+ * ```
315
+ */
316
+ declare function createTheme(options: CreateThemeOptions): Theme;
317
+
318
+ export { type CreateThemeOptions, DEFAULT_FONT, DEFAULT_FONTS_FALLBACK, DEFAULT_FONT_MONO, DEFAULT_THEME, type GoogleFontConfig, type GoogleFontEntry, type PresetThemeId, type Theme, type ThemeColors, type ThemeFonts, applyTheme, createTheme, defaultTheme, getCurrentTheme, getTheme, googleFont, kodamaGroveTheme, listThemes, midnightBlueTheme, minimalTheme, nordTheme, removeTheme, themes };