@udixio/theme 1.0.0-beta.23 → 1.0.0-beta.25
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.
- package/dist/config/config.interface.d.ts +1 -1
- package/dist/plugins/font/font.plugin.d.ts +1 -1
- package/dist/plugins/tailwind/plugins-tailwind/themer.d.ts +10 -4
- package/dist/plugins/tailwind/tailwind.plugin.d.ts +3 -2
- package/dist/theme.cjs.development.js +59 -7
- package/dist/theme.cjs.development.js.map +1 -1
- package/dist/theme.cjs.production.min.js +1 -1
- package/dist/theme.cjs.production.min.js.map +1 -1
- package/dist/theme.esm.js +59 -7
- package/dist/theme.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/config/config.interface.ts +1 -1
- package/src/plugins/font/font.plugin.ts +1 -1
- package/src/plugins/tailwind/plugins-tailwind/themer.ts +85 -9
- package/src/plugins/tailwind/tailwind.plugin.ts +10 -5
package/package.json
CHANGED
|
@@ -1,13 +1,60 @@
|
|
|
1
|
-
|
|
1
|
+
import { AppService } from '../../../app.service';
|
|
2
|
+
|
|
3
|
+
type SubTheme = {
|
|
4
|
+
name: string;
|
|
5
|
+
selectors?: string[];
|
|
6
|
+
mediaQuery?: '@media (prefers-color-scheme: dark)';
|
|
7
|
+
extend: {
|
|
8
|
+
colors: Record<string, string>;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
function createSubTheme({
|
|
13
|
+
name,
|
|
14
|
+
darkMode,
|
|
15
|
+
isDarkTheme,
|
|
16
|
+
colors,
|
|
17
|
+
}: {
|
|
18
|
+
name: string;
|
|
19
|
+
isDarkTheme: boolean;
|
|
20
|
+
darkMode: 'class' | 'media';
|
|
21
|
+
colors: Record<string, string>;
|
|
22
|
+
}): SubTheme {
|
|
23
|
+
const theme: SubTheme = {
|
|
24
|
+
name: isDarkTheme ? name + 'Dark' : name,
|
|
25
|
+
selectors:
|
|
26
|
+
isDarkTheme && darkMode === 'class'
|
|
27
|
+
? [
|
|
28
|
+
'.dark-mode .theme-' + name,
|
|
29
|
+
'.dark-mode.theme-' + name,
|
|
30
|
+
'[data-theme="dark"] .theme-' + name,
|
|
31
|
+
'[data-theme="dark"].theme-' + name,
|
|
32
|
+
]
|
|
33
|
+
: ['.theme-' + name],
|
|
34
|
+
mediaQuery:
|
|
35
|
+
isDarkTheme && darkMode === 'media'
|
|
36
|
+
? '@media (prefers-color-scheme: dark)'
|
|
37
|
+
: undefined,
|
|
38
|
+
extend: {
|
|
39
|
+
colors: colors,
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
return theme;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export const themer = (args: {
|
|
2
46
|
colors: Record<
|
|
3
47
|
string,
|
|
4
48
|
{
|
|
5
49
|
light: string;
|
|
6
50
|
dark: string;
|
|
7
51
|
}
|
|
8
|
-
|
|
9
|
-
darkMode: 'class' | 'media'
|
|
10
|
-
|
|
52
|
+
>;
|
|
53
|
+
darkMode: 'class' | 'media';
|
|
54
|
+
subThemes?: Record<string, string>;
|
|
55
|
+
appService: AppService;
|
|
56
|
+
}) => {
|
|
57
|
+
const { themeService, colorService } = args.appService;
|
|
11
58
|
const options: {
|
|
12
59
|
defaultTheme: {
|
|
13
60
|
extend: {
|
|
@@ -16,13 +63,14 @@ export const themer = (
|
|
|
16
63
|
};
|
|
17
64
|
themes: [
|
|
18
65
|
{
|
|
19
|
-
name:
|
|
66
|
+
name: string;
|
|
20
67
|
selectors?: ['.dark-mode', '[data-theme="dark"]'];
|
|
21
68
|
mediaQuery?: '@media (prefers-color-scheme: dark)';
|
|
22
69
|
extend: {
|
|
23
70
|
colors: Record<string, string>;
|
|
24
71
|
};
|
|
25
|
-
}
|
|
72
|
+
},
|
|
73
|
+
...SubTheme[]
|
|
26
74
|
];
|
|
27
75
|
} = {
|
|
28
76
|
defaultTheme: {
|
|
@@ -40,14 +88,42 @@ export const themer = (
|
|
|
40
88
|
],
|
|
41
89
|
};
|
|
42
90
|
|
|
43
|
-
Object.entries(colors).forEach(([key, value]) => {
|
|
91
|
+
Object.entries(args.colors).forEach(([key, value]) => {
|
|
44
92
|
options.defaultTheme.extend.colors[key] = value.light;
|
|
45
93
|
options.themes[0].extend.colors[key] = value.dark;
|
|
46
94
|
});
|
|
47
95
|
options.themes[0].selectors =
|
|
48
|
-
darkMode === 'class'
|
|
96
|
+
args.darkMode === 'class'
|
|
97
|
+
? ['.dark-mode', '[data-theme="dark"]']
|
|
98
|
+
: undefined;
|
|
49
99
|
options.themes[0].mediaQuery =
|
|
50
|
-
darkMode === 'media'
|
|
100
|
+
args.darkMode === 'media'
|
|
101
|
+
? '@media (prefers-color-scheme: dark)'
|
|
102
|
+
: undefined;
|
|
103
|
+
|
|
104
|
+
if (args.subThemes) {
|
|
105
|
+
Object.entries(args.subThemes).forEach(([key, value]) => {
|
|
106
|
+
themeService.update({ sourceColorHex: value });
|
|
107
|
+
for (const isDarkTheme of [true, false]) {
|
|
108
|
+
const colors: Record<string, string> = {};
|
|
109
|
+
themeService.update({ isDark: isDarkTheme });
|
|
110
|
+
for (const [key, value] of colorService.getColors().entries()) {
|
|
111
|
+
const newKey = key
|
|
112
|
+
.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, '$1-$2')
|
|
113
|
+
.toLowerCase();
|
|
114
|
+
colors[newKey] = value.getHex();
|
|
115
|
+
}
|
|
116
|
+
options.themes.push(
|
|
117
|
+
createSubTheme({
|
|
118
|
+
name: key,
|
|
119
|
+
isDarkTheme: isDarkTheme,
|
|
120
|
+
darkMode: args.darkMode,
|
|
121
|
+
colors: colors,
|
|
122
|
+
})
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
51
127
|
|
|
52
128
|
return require('tailwindcss-themer')(options);
|
|
53
129
|
};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { PluginAbstract } from '../../plugin
|
|
1
|
+
import { PluginAbstract } from '../../plugin';
|
|
2
2
|
import { AppService } from '../../app.service';
|
|
3
3
|
import { Theme } from './main';
|
|
4
|
-
import { state } from './plugins-tailwind
|
|
5
|
-
import {
|
|
6
|
-
import { FontPlugin } from '../font/font.plugin';
|
|
4
|
+
import { state, themer } from './plugins-tailwind';
|
|
5
|
+
import { FontPlugin } from '../font';
|
|
7
6
|
import { font } from './plugins-tailwind/font';
|
|
8
7
|
|
|
9
8
|
interface TailwindPluginOptions {
|
|
10
9
|
darkMode?: 'class' | 'media';
|
|
11
10
|
responsiveBreakPoints?: Record<string, number>;
|
|
11
|
+
subThemes?: Record<string, string>;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export class TailwindPlugin extends PluginAbstract {
|
|
@@ -56,8 +56,13 @@ export class TailwindPlugin extends PluginAbstract {
|
|
|
56
56
|
fontFamily: fontFamily,
|
|
57
57
|
plugins: [
|
|
58
58
|
state(Object.keys(colors)),
|
|
59
|
-
themer(colors, this.options.darkMode!),
|
|
60
59
|
font(fontStyles, this.options.responsiveBreakPoints!),
|
|
60
|
+
themer({
|
|
61
|
+
colors,
|
|
62
|
+
darkMode: this.options.darkMode!,
|
|
63
|
+
subThemes: this.options.subThemes,
|
|
64
|
+
appService: this.appService,
|
|
65
|
+
}),
|
|
61
66
|
],
|
|
62
67
|
};
|
|
63
68
|
}
|