@udixio/theme 1.0.0-beta.25 → 1.0.0-beta.27
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 +2 -2
- package/dist/plugin/index.d.ts +1 -1
- package/dist/plugin/plugin.service.d.ts +4 -8
- package/dist/plugin/pluginAbstract.d.ts +18 -0
- package/dist/plugins/font/font.plugin.d.ts +20 -9
- package/dist/plugins/tailwind/tailwind.plugin.d.ts +8 -8
- package/dist/theme.cjs.development.js +128 -70
- 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 +128 -71
- package/dist/theme.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/config/config.interface.ts +2 -2
- package/src/config/config.service.ts +1 -5
- package/src/plugin/index.ts +1 -1
- package/src/plugin/plugin.service.ts +14 -20
- package/src/plugin/pluginAbstract.ts +44 -0
- package/src/plugins/font/font.plugin.ts +53 -22
- package/src/plugins/tailwind/main.ts +2 -5
- package/src/plugins/tailwind/tailwind.plugin.ts +18 -15
- package/dist/plugin/plugin.abstract.d.ts +0 -7
- package/src/plugin/plugin.abstract.ts +0 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AddColorsOptions } from '../color';
|
|
2
2
|
import { VariantEntity } from '../theme';
|
|
3
|
-
import {
|
|
3
|
+
import { PluginAbstract } from '../plugin';
|
|
4
4
|
|
|
5
5
|
export interface ConfigInterface {
|
|
6
6
|
sourceColor: string;
|
|
@@ -10,5 +10,5 @@ export interface ConfigInterface {
|
|
|
10
10
|
colors?: AddColorsOptions | AddColorsOptions[];
|
|
11
11
|
useDefaultColors?: boolean;
|
|
12
12
|
palettes?: Record<string, string>;
|
|
13
|
-
plugins?:
|
|
13
|
+
plugins?: PluginAbstract<any, any>[];
|
|
14
14
|
}
|
|
@@ -56,11 +56,7 @@ export class ConfigService {
|
|
|
56
56
|
}
|
|
57
57
|
if (plugins) {
|
|
58
58
|
plugins.forEach((plugin) => {
|
|
59
|
-
|
|
60
|
-
pluginService.addPlugin(plugin[0], plugin[1]);
|
|
61
|
-
} else {
|
|
62
|
-
pluginService.addPlugin(plugin, {});
|
|
63
|
-
}
|
|
59
|
+
pluginService.addPlugin(plugin);
|
|
64
60
|
});
|
|
65
61
|
pluginService.loadPlugins(this.appService);
|
|
66
62
|
}
|
package/src/plugin/index.ts
CHANGED
|
@@ -1,47 +1,41 @@
|
|
|
1
|
-
import { PluginAbstract } from './
|
|
1
|
+
import { PluginAbstract } from './pluginAbstract';
|
|
2
2
|
import { AppService } from '../app.service';
|
|
3
3
|
|
|
4
|
-
export type PluginConstructor = (new (
|
|
5
|
-
appService: AppService,
|
|
6
|
-
options: any
|
|
7
|
-
) => PluginAbstract) & { dependencies: PluginConstructor[] };
|
|
8
|
-
|
|
9
4
|
export class PluginService {
|
|
10
|
-
private
|
|
11
|
-
private pluginConstructors = new Map<string, [PluginConstructor, object]>();
|
|
5
|
+
private plugins = new Map<string, PluginAbstract<any, any>>();
|
|
12
6
|
|
|
13
|
-
public addPlugin(plugin:
|
|
14
|
-
this.
|
|
7
|
+
public addPlugin(plugin: PluginAbstract<any, any>) {
|
|
8
|
+
this.plugins.set(plugin.name, plugin);
|
|
15
9
|
}
|
|
16
10
|
|
|
17
11
|
public loadPlugins(appService: AppService) {
|
|
18
|
-
const plugins = new Map(this.
|
|
12
|
+
const plugins = new Map(this.plugins);
|
|
19
13
|
|
|
20
14
|
let size = 0;
|
|
21
15
|
do {
|
|
22
16
|
size = plugins.size;
|
|
23
|
-
plugins.forEach((
|
|
17
|
+
plugins.forEach((plugin, key) => {
|
|
24
18
|
const deps = plugin.dependencies.filter(
|
|
25
|
-
(dep) => !this.
|
|
19
|
+
(dep) => !this.plugins.has(new dep().name)
|
|
26
20
|
);
|
|
27
21
|
if (deps.length === 0) {
|
|
28
|
-
this.
|
|
22
|
+
this.plugins.set(plugin.name, plugin.init(appService));
|
|
29
23
|
plugins.delete(key);
|
|
30
24
|
}
|
|
31
25
|
});
|
|
32
26
|
} while (plugins.size != 0 && plugins.size < size);
|
|
33
27
|
|
|
34
28
|
if (plugins.size > 0)
|
|
35
|
-
|
|
36
|
-
"Some plugins couldn't be loaded due to missing dependencies: "
|
|
37
|
-
|
|
29
|
+
throw new Error(
|
|
30
|
+
"Some plugins couldn't be loaded due to missing dependencies: " +
|
|
31
|
+
Array.from(plugins.keys())
|
|
38
32
|
);
|
|
39
33
|
}
|
|
40
34
|
|
|
41
|
-
public getPlugin<T extends PluginAbstract
|
|
42
|
-
plugin: new (
|
|
35
|
+
public getPlugin<T extends PluginAbstract<any, any>>(
|
|
36
|
+
plugin: new (...args: any) => T
|
|
43
37
|
): T {
|
|
44
|
-
const pluginInstance = this.
|
|
38
|
+
const pluginInstance = this.plugins.get(new plugin().name);
|
|
45
39
|
if (!pluginInstance) throw new Error(`Plugin ${plugin.name} not found`);
|
|
46
40
|
return pluginInstance as T;
|
|
47
41
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { AppService } from '../app.service';
|
|
2
|
+
|
|
3
|
+
export type PluginConstructor<Plugin extends PluginImplAbstract<any>> = new (
|
|
4
|
+
...args: any
|
|
5
|
+
) => Plugin;
|
|
6
|
+
|
|
7
|
+
export abstract class PluginAbstract<
|
|
8
|
+
Plugin extends PluginImplAbstract<Options>,
|
|
9
|
+
Options extends object
|
|
10
|
+
> {
|
|
11
|
+
public abstract readonly dependencies: (new (...args: any) => PluginAbstract<
|
|
12
|
+
any,
|
|
13
|
+
any
|
|
14
|
+
>)[];
|
|
15
|
+
public abstract readonly name: string;
|
|
16
|
+
public options: Options;
|
|
17
|
+
public abstract readonly pluginClass: PluginConstructor<Plugin>;
|
|
18
|
+
protected pluginInstance: Plugin | undefined;
|
|
19
|
+
|
|
20
|
+
constructor(options: Options) {
|
|
21
|
+
this.options = options;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public init(appService: AppService) {
|
|
25
|
+
this.pluginInstance = new this.pluginClass(appService, this.options);
|
|
26
|
+
this.pluginInstance.onInit();
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public getInstance(): Plugin {
|
|
31
|
+
if (!this.pluginInstance) {
|
|
32
|
+
throw new Error(`Plugin ${this.name} is not initialized`);
|
|
33
|
+
}
|
|
34
|
+
return this.pluginInstance;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export abstract class PluginImplAbstract<Options extends object> {
|
|
39
|
+
constructor(protected appService: AppService, protected options: Options) {
|
|
40
|
+
this.onInit();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
abstract onInit(): void;
|
|
44
|
+
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { PluginAbstract } from '../../plugin';
|
|
1
|
+
import { PluginAbstract, PluginImplAbstract } from '../../plugin';
|
|
3
2
|
|
|
4
3
|
export enum FontFamily {
|
|
5
4
|
Expressive = 'expressive',
|
|
@@ -22,18 +21,58 @@ interface FontPluginOptions {
|
|
|
22
21
|
fontStyles?: Partial<Record<FontRole, Record<FontSize, Partial<FontStyle>>>>;
|
|
23
22
|
}
|
|
24
23
|
|
|
25
|
-
export class FontPlugin extends PluginAbstract
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
export class FontPlugin extends PluginAbstract<
|
|
25
|
+
FontPluginImpl,
|
|
26
|
+
FontPluginOptions
|
|
27
|
+
> {
|
|
28
|
+
dependencies = [];
|
|
29
|
+
name = 'font';
|
|
30
|
+
pluginClass = FontPluginImpl;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
class FontPluginImpl extends PluginImplAbstract<FontPluginOptions> {
|
|
34
|
+
private _fontFamily: { expressive: string[]; neutral: string[] } | undefined;
|
|
35
|
+
|
|
36
|
+
get fontFamily(): { expressive: string[]; neutral: string[] } {
|
|
37
|
+
if (!this._fontFamily) throw new Error('Font family not initialized');
|
|
38
|
+
return this._fontFamily;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
set fontFamily(
|
|
42
|
+
value: { expressive: string[]; neutral: string[] } | undefined
|
|
43
|
+
) {
|
|
44
|
+
this._fontFamily = value;
|
|
45
|
+
}
|
|
28
46
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
47
|
+
private _fontStyles:
|
|
48
|
+
| Record<FontRole, Record<FontSize, FontStyle>>
|
|
49
|
+
| undefined;
|
|
50
|
+
|
|
51
|
+
get fontStyles(): Record<FontRole, Record<FontSize, FontStyle>> {
|
|
52
|
+
if (!this._fontStyles) throw new Error('Font styles not initialized');
|
|
53
|
+
return this._fontStyles;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
set fontStyles(
|
|
57
|
+
value: Record<FontRole, Record<FontSize, FontStyle>> | undefined
|
|
32
58
|
) {
|
|
33
|
-
|
|
59
|
+
this._fontStyles = value;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
getFonts() {
|
|
63
|
+
return {
|
|
64
|
+
fontStyles: this.fontStyles,
|
|
65
|
+
fontFamily: this.fontFamily,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
onInit(): void {
|
|
34
70
|
this.fontFamily = {
|
|
35
|
-
expressive: options?.fontFamily?.expressive ?? [
|
|
36
|
-
|
|
71
|
+
expressive: this.options?.fontFamily?.expressive ?? [
|
|
72
|
+
'Roboto',
|
|
73
|
+
'sans-serif',
|
|
74
|
+
],
|
|
75
|
+
neutral: this.options?.fontFamily?.neutral ?? ['Roboto', 'sans-serif'],
|
|
37
76
|
};
|
|
38
77
|
this.fontStyles = {
|
|
39
78
|
display: {
|
|
@@ -146,8 +185,9 @@ export class FontPlugin extends PluginAbstract {
|
|
|
146
185
|
},
|
|
147
186
|
},
|
|
148
187
|
};
|
|
149
|
-
|
|
150
|
-
|
|
188
|
+
|
|
189
|
+
if (this.options && this.options.fontStyles)
|
|
190
|
+
Object.entries(this.options.fontStyles).forEach(([key, fontParam]) => {
|
|
151
191
|
const fontRole: FontRole = key as FontRole;
|
|
152
192
|
Object.entries(fontParam).forEach(([size, fontStyle]) => {
|
|
153
193
|
const fontSize: FontSize = size as FontSize;
|
|
@@ -160,13 +200,4 @@ export class FontPlugin extends PluginAbstract {
|
|
|
160
200
|
});
|
|
161
201
|
});
|
|
162
202
|
}
|
|
163
|
-
static config(options: FontPluginOptions): FontPluginOptions {
|
|
164
|
-
return options;
|
|
165
|
-
}
|
|
166
|
-
getFonts() {
|
|
167
|
-
return {
|
|
168
|
-
fontStyles: this.fontStyles,
|
|
169
|
-
fontFamily: this.fontFamily,
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
203
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PluginsConfig } from 'tailwindcss/types/config';
|
|
2
2
|
import { bootstrapFromConfig } from '../../main';
|
|
3
|
-
import { TailwindPlugin } from './tailwind.plugin';
|
|
4
3
|
import { AppService } from '../../app.service';
|
|
4
|
+
import { TailwindPlugin } from './tailwind.plugin';
|
|
5
5
|
|
|
6
6
|
export type Theme = {
|
|
7
7
|
colors: Record<string, string>;
|
|
@@ -11,9 +11,6 @@ export type Theme = {
|
|
|
11
11
|
|
|
12
12
|
export const createTheme = (): Theme & { appService: AppService } => {
|
|
13
13
|
const app = bootstrapFromConfig();
|
|
14
|
-
const plugin = app.pluginService.getPlugin(TailwindPlugin);
|
|
15
|
-
if (!plugin) {
|
|
16
|
-
throw new Error('Tailwind plugin not found');
|
|
17
|
-
}
|
|
14
|
+
const plugin = app.pluginService.getPlugin(TailwindPlugin).getInstance();
|
|
18
15
|
return { ...plugin.getTheme(), appService: app };
|
|
19
16
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { PluginAbstract } from '../../plugin';
|
|
2
|
-
import { AppService } from '../../app.service';
|
|
1
|
+
import { PluginAbstract, PluginImplAbstract } from '../../plugin';
|
|
3
2
|
import { Theme } from './main';
|
|
4
3
|
import { state, themer } from './plugins-tailwind';
|
|
5
|
-
|
|
4
|
+
|
|
6
5
|
import { font } from './plugins-tailwind/font';
|
|
6
|
+
import { FontPlugin } from '../font';
|
|
7
7
|
|
|
8
8
|
interface TailwindPluginOptions {
|
|
9
9
|
darkMode?: 'class' | 'media';
|
|
@@ -11,21 +11,23 @@ interface TailwindPluginOptions {
|
|
|
11
11
|
subThemes?: Record<string, string>;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
export class TailwindPlugin extends PluginAbstract
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
export class TailwindPlugin extends PluginAbstract<
|
|
15
|
+
TailwindImplPlugin,
|
|
16
|
+
TailwindPluginOptions
|
|
17
|
+
> {
|
|
18
|
+
public dependencies = [FontPlugin];
|
|
19
|
+
public name = 'tailwind';
|
|
20
|
+
pluginClass = TailwindImplPlugin;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
class TailwindImplPlugin extends PluginImplAbstract<TailwindPluginOptions> {
|
|
24
|
+
onInit() {
|
|
25
|
+
this.options.darkMode ??= 'class';
|
|
26
|
+
this.options.responsiveBreakPoints ??= {
|
|
22
27
|
lg: 1.125,
|
|
23
28
|
};
|
|
24
|
-
super();
|
|
25
|
-
}
|
|
26
|
-
static config(options: TailwindPluginOptions): TailwindPluginOptions {
|
|
27
|
-
return options;
|
|
28
29
|
}
|
|
30
|
+
|
|
29
31
|
getTheme(): Theme {
|
|
30
32
|
const colors: Record<
|
|
31
33
|
string,
|
|
@@ -50,6 +52,7 @@ export class TailwindPlugin extends PluginAbstract {
|
|
|
50
52
|
|
|
51
53
|
const { fontStyles, fontFamily } = this.appService.pluginService
|
|
52
54
|
.getPlugin(FontPlugin)
|
|
55
|
+
.getInstance()
|
|
53
56
|
.getFonts();
|
|
54
57
|
return {
|
|
55
58
|
colors: {},
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { AppService } from '../app.service';
|
|
2
|
-
import { PluginConstructor } from './plugin.service';
|
|
3
|
-
export declare abstract class PluginAbstract {
|
|
4
|
-
static dependencies: PluginConstructor[];
|
|
5
|
-
protected abstract appService: AppService;
|
|
6
|
-
protected abstract options: object;
|
|
7
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { AppService } from '../app.service';
|
|
2
|
-
import { PluginConstructor } from './plugin.service';
|
|
3
|
-
|
|
4
|
-
export abstract class PluginAbstract {
|
|
5
|
-
static dependencies: PluginConstructor[] = [];
|
|
6
|
-
|
|
7
|
-
protected abstract appService: AppService;
|
|
8
|
-
protected abstract options: object;
|
|
9
|
-
}
|