@udixio/theme 1.0.0-beta.22 → 1.0.0-beta.24
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 +3 -3
- 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 +3 -3
- package/src/plugins/font/font.plugin.ts +1 -1
- package/src/plugins/tailwind/plugins-tailwind/themer.ts +82 -9
- package/src/plugins/tailwind/tailwind.plugin.ts +10 -5
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { VariantEntity } from '../theme';
|
|
2
1
|
import { AddColorsOptions } from '../color';
|
|
3
|
-
import {
|
|
2
|
+
import { VariantEntity } from '../theme';
|
|
3
|
+
import { PluginConstructor } from '../plugin';
|
|
4
4
|
|
|
5
5
|
export interface ConfigInterface {
|
|
6
6
|
sourceColor: string;
|
|
7
|
-
contrastLevel?:
|
|
7
|
+
contrastLevel?: number;
|
|
8
8
|
isDark?: boolean;
|
|
9
9
|
variant?: VariantEntity;
|
|
10
10
|
colors?: AddColorsOptions | AddColorsOptions[];
|
|
@@ -1,13 +1,57 @@
|
|
|
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: '@media (prefers-color-scheme: dark)',
|
|
35
|
+
extend: {
|
|
36
|
+
colors: colors,
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
return theme;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const themer = (args: {
|
|
2
43
|
colors: Record<
|
|
3
44
|
string,
|
|
4
45
|
{
|
|
5
46
|
light: string;
|
|
6
47
|
dark: string;
|
|
7
48
|
}
|
|
8
|
-
|
|
9
|
-
darkMode: 'class' | 'media'
|
|
10
|
-
|
|
49
|
+
>;
|
|
50
|
+
darkMode: 'class' | 'media';
|
|
51
|
+
subThemes?: Record<string, string>;
|
|
52
|
+
appService: AppService;
|
|
53
|
+
}) => {
|
|
54
|
+
const { themeService, colorService } = args.appService;
|
|
11
55
|
const options: {
|
|
12
56
|
defaultTheme: {
|
|
13
57
|
extend: {
|
|
@@ -16,13 +60,14 @@ export const themer = (
|
|
|
16
60
|
};
|
|
17
61
|
themes: [
|
|
18
62
|
{
|
|
19
|
-
name:
|
|
63
|
+
name: string;
|
|
20
64
|
selectors?: ['.dark-mode', '[data-theme="dark"]'];
|
|
21
65
|
mediaQuery?: '@media (prefers-color-scheme: dark)';
|
|
22
66
|
extend: {
|
|
23
67
|
colors: Record<string, string>;
|
|
24
68
|
};
|
|
25
|
-
}
|
|
69
|
+
},
|
|
70
|
+
...SubTheme[]
|
|
26
71
|
];
|
|
27
72
|
} = {
|
|
28
73
|
defaultTheme: {
|
|
@@ -40,14 +85,42 @@ export const themer = (
|
|
|
40
85
|
],
|
|
41
86
|
};
|
|
42
87
|
|
|
43
|
-
Object.entries(colors).forEach(([key, value]) => {
|
|
88
|
+
Object.entries(args.colors).forEach(([key, value]) => {
|
|
44
89
|
options.defaultTheme.extend.colors[key] = value.light;
|
|
45
90
|
options.themes[0].extend.colors[key] = value.dark;
|
|
46
91
|
});
|
|
47
92
|
options.themes[0].selectors =
|
|
48
|
-
darkMode === 'class'
|
|
93
|
+
args.darkMode === 'class'
|
|
94
|
+
? ['.dark-mode', '[data-theme="dark"]']
|
|
95
|
+
: undefined;
|
|
49
96
|
options.themes[0].mediaQuery =
|
|
50
|
-
darkMode === 'media'
|
|
97
|
+
args.darkMode === 'media'
|
|
98
|
+
? '@media (prefers-color-scheme: dark)'
|
|
99
|
+
: undefined;
|
|
100
|
+
|
|
101
|
+
if (args.subThemes) {
|
|
102
|
+
Object.entries(args.subThemes).forEach(([key, value]) => {
|
|
103
|
+
themeService.update({ sourceColorHex: value });
|
|
104
|
+
for (const isDarkTheme of [true, false]) {
|
|
105
|
+
const colors: Record<string, string> = {};
|
|
106
|
+
themeService.update({ isDark: isDarkTheme });
|
|
107
|
+
for (const [key, value] of colorService.getColors().entries()) {
|
|
108
|
+
const newKey = key
|
|
109
|
+
.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, '$1-$2')
|
|
110
|
+
.toLowerCase();
|
|
111
|
+
colors[newKey] = value.getHex();
|
|
112
|
+
}
|
|
113
|
+
options.themes.push(
|
|
114
|
+
createSubTheme({
|
|
115
|
+
name: key,
|
|
116
|
+
isDarkTheme: isDarkTheme,
|
|
117
|
+
darkMode: args.darkMode,
|
|
118
|
+
colors: colors,
|
|
119
|
+
})
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
51
124
|
|
|
52
125
|
return require('tailwindcss-themer')(options);
|
|
53
126
|
};
|
|
@@ -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
|
}
|