@udixio/theme 1.0.0-beta.3 → 1.0.0-beta.31

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.
Files changed (97) hide show
  1. package/dist/app.container.d.ts +5 -0
  2. package/dist/app.module.d.ts +2 -2
  3. package/dist/app.service.d.ts +9 -3
  4. package/dist/color/color.interface.d.ts +1 -2
  5. package/dist/color/color.module.d.ts +2 -2
  6. package/dist/color/entities/color.entity.d.ts +6 -1
  7. package/dist/color/entities/index.d.ts +1 -0
  8. package/dist/color/index.d.ts +5 -0
  9. package/dist/color/models/default-color.model.d.ts +2 -3
  10. package/dist/color/models/index.d.ts +1 -0
  11. package/dist/color/services/color-manager.service.d.ts +18 -0
  12. package/dist/color/services/color.service.d.ts +21 -0
  13. package/dist/color/services/index.d.ts +2 -0
  14. package/dist/config/config.interface.d.ts +13 -0
  15. package/dist/config/config.module.d.ts +2 -0
  16. package/dist/config/config.service.d.ts +12 -0
  17. package/dist/config/index.d.ts +3 -0
  18. package/dist/index.d.ts +11 -0
  19. package/dist/main.d.ts +6 -1
  20. package/dist/material-color-utilities/index.d.ts +1 -0
  21. package/dist/plugin/index.d.ts +3 -0
  22. package/dist/plugin/plugin.module.d.ts +2 -0
  23. package/dist/plugin/plugin.service.d.ts +8 -0
  24. package/dist/plugin/pluginAbstract.d.ts +18 -0
  25. package/dist/plugins/font/font.plugin.d.ts +49 -0
  26. package/dist/plugins/font/index.d.ts +1 -0
  27. package/dist/plugins/tailwind/index.d.ts +3 -0
  28. package/dist/plugins/tailwind/main.d.ts +13 -0
  29. package/dist/plugins/tailwind/plugins-tailwind/font.d.ts +5 -0
  30. package/dist/plugins/tailwind/plugins-tailwind/index.d.ts +2 -0
  31. package/dist/plugins/tailwind/plugins-tailwind/state.d.ts +4 -0
  32. package/dist/plugins/tailwind/plugins-tailwind/themer.d.ts +10 -0
  33. package/dist/plugins/tailwind/tailwind.plugin.d.ts +18 -0
  34. package/dist/theme/entities/index.d.ts +2 -0
  35. package/dist/theme/entities/variant.entity.d.ts +2 -1
  36. package/dist/theme/index.d.ts +4 -0
  37. package/dist/theme/models/index.d.ts +1 -0
  38. package/dist/theme/services/index.d.ts +3 -0
  39. package/dist/theme/services/scheme.service.d.ts +7 -2
  40. package/dist/theme/services/theme.service.d.ts +16 -7
  41. package/dist/theme/services/variant.service.d.ts +8 -2
  42. package/dist/theme/theme.module.d.ts +2 -2
  43. package/dist/theme.cjs.development.js +1418 -906
  44. package/dist/theme.cjs.development.js.map +1 -1
  45. package/dist/theme.cjs.production.min.js +1 -1
  46. package/dist/theme.cjs.production.min.js.map +1 -1
  47. package/dist/theme.esm.js +1385 -907
  48. package/dist/theme.esm.js.map +1 -1
  49. package/package.json +21 -22
  50. package/src/app.container.ts +46 -0
  51. package/src/app.module.ts +5 -8
  52. package/src/app.service.spec.ts +1 -1
  53. package/src/app.service.ts +20 -8
  54. package/src/color/color.interface.ts +1 -3
  55. package/src/color/color.module.ts +8 -10
  56. package/src/color/entities/color.entity.ts +13 -1
  57. package/src/color/entities/index.ts +1 -0
  58. package/src/color/index.ts +5 -0
  59. package/src/color/models/default-color.model.ts +205 -202
  60. package/src/color/models/index.ts +1 -0
  61. package/src/color/{color-manager.service.ts → services/color-manager.service.ts} +23 -15
  62. package/src/color/{color.service.spec.ts → services/color.service.spec.ts} +1 -1
  63. package/src/color/services/color.service.ts +75 -0
  64. package/src/color/services/index.ts +2 -0
  65. package/src/config/config.interface.ts +14 -0
  66. package/src/config/config.module.ts +7 -0
  67. package/src/config/config.service.ts +104 -0
  68. package/src/config/index.ts +3 -0
  69. package/src/index.ts +11 -0
  70. package/src/main.ts +13 -7
  71. package/src/material-color-utilities/index.ts +1 -0
  72. package/src/plugin/index.ts +3 -0
  73. package/src/plugin/plugin.module.ts +7 -0
  74. package/src/plugin/plugin.service.ts +42 -0
  75. package/src/plugin/pluginAbstract.ts +44 -0
  76. package/src/plugins/font/font.plugin.ts +203 -0
  77. package/src/plugins/font/index.ts +1 -0
  78. package/src/plugins/tailwind/index.ts +3 -0
  79. package/src/plugins/tailwind/main.ts +16 -0
  80. package/src/plugins/tailwind/plugins-tailwind/font.ts +69 -0
  81. package/src/plugins/tailwind/plugins-tailwind/index.ts +2 -0
  82. package/src/plugins/tailwind/plugins-tailwind/state.ts +88 -0
  83. package/src/plugins/tailwind/plugins-tailwind/themer.ts +137 -0
  84. package/src/plugins/tailwind/tailwind.plugin.ts +72 -0
  85. package/src/theme/entities/index.ts +2 -0
  86. package/src/theme/entities/variant.entity.ts +2 -1
  87. package/src/theme/index.ts +4 -0
  88. package/src/theme/models/index.ts +1 -0
  89. package/src/theme/models/variant.model.ts +7 -0
  90. package/src/theme/services/index.ts +3 -0
  91. package/src/theme/services/scheme.service.ts +39 -11
  92. package/src/theme/services/theme.service.ts +30 -14
  93. package/src/theme/services/variant.service.ts +40 -5
  94. package/src/theme/theme.module.ts +8 -9
  95. package/dist/color/color-manager.service.d.ts +0 -15
  96. package/dist/color/color.service.d.ts +0 -14
  97. package/src/color/color.service.ts +0 -58
@@ -0,0 +1,137 @@
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
+ : [
34
+ '.theme-' + name,
35
+ `.theme-${name} .light-mode`,
36
+ `.theme-${name} [data-theme="light"]`,
37
+ `.light-mode .theme-${name}`,
38
+ `.light-mode.theme-${name}`,
39
+ `[data-theme="light"] .theme-${name}`,
40
+ `[data-theme="light"].theme-${name}`,
41
+ ],
42
+ mediaQuery:
43
+ isDarkTheme && darkMode === 'media'
44
+ ? '@media (prefers-color-scheme: dark)'
45
+ : undefined,
46
+ extend: {
47
+ colors: colors,
48
+ },
49
+ };
50
+ return theme;
51
+ }
52
+
53
+ export const themer = (args: {
54
+ colors: Record<
55
+ string,
56
+ {
57
+ light: string;
58
+ dark: string;
59
+ }
60
+ >;
61
+ darkMode: 'class' | 'media';
62
+ subThemes?: Record<string, string>;
63
+ appService: AppService;
64
+ }) => {
65
+ const { themeService, colorService } = args.appService;
66
+ const options: {
67
+ defaultTheme: {
68
+ extend: {
69
+ colors: Record<string, string>;
70
+ };
71
+ };
72
+ themes: [
73
+ {
74
+ name: string;
75
+ selectors?: ['.dark-mode', '[data-theme="dark"]'];
76
+ mediaQuery?: '@media (prefers-color-scheme: dark)';
77
+ extend: {
78
+ colors: Record<string, string>;
79
+ };
80
+ },
81
+ ...SubTheme[]
82
+ ];
83
+ } = {
84
+ defaultTheme: {
85
+ extend: {
86
+ colors: {},
87
+ },
88
+ },
89
+ themes: [
90
+ {
91
+ name: 'darkTheme',
92
+ extend: {
93
+ colors: {},
94
+ },
95
+ },
96
+ ],
97
+ };
98
+
99
+ Object.entries(args.colors).forEach(([key, value]) => {
100
+ options.defaultTheme.extend.colors[key] = value.light;
101
+ options.themes[0].extend.colors[key] = value.dark;
102
+ });
103
+ options.themes[0].selectors =
104
+ args.darkMode === 'class'
105
+ ? ['.dark-mode', '[data-theme="dark"]']
106
+ : undefined;
107
+ options.themes[0].mediaQuery =
108
+ args.darkMode === 'media'
109
+ ? '@media (prefers-color-scheme: dark)'
110
+ : undefined;
111
+
112
+ if (args.subThemes) {
113
+ Object.entries(args.subThemes).forEach(([key, value]) => {
114
+ themeService.update({ sourceColorHex: value });
115
+ for (const isDarkTheme of [true, false]) {
116
+ const colors: Record<string, string> = {};
117
+ themeService.update({ isDark: isDarkTheme });
118
+ for (const [key, value] of colorService.getColors().entries()) {
119
+ const newKey = key
120
+ .replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, '$1-$2')
121
+ .toLowerCase();
122
+ colors[newKey] = value.getHex();
123
+ }
124
+ options.themes.push(
125
+ createSubTheme({
126
+ name: key,
127
+ isDarkTheme: isDarkTheme,
128
+ darkMode: args.darkMode,
129
+ colors: colors,
130
+ })
131
+ );
132
+ }
133
+ });
134
+ }
135
+
136
+ return require('tailwindcss-themer')(options);
137
+ };
@@ -0,0 +1,72 @@
1
+ import { PluginAbstract, PluginImplAbstract } from '../../plugin';
2
+ import { Theme } from './main';
3
+ import { state, themer } from './plugins-tailwind';
4
+
5
+ import { font } from './plugins-tailwind/font';
6
+ import { FontPlugin } from '../font';
7
+
8
+ interface TailwindPluginOptions {
9
+ darkMode?: 'class' | 'media';
10
+ responsiveBreakPoints?: Record<string, number>;
11
+ subThemes?: Record<string, string>;
12
+ }
13
+
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 ??= {
27
+ lg: 1.125,
28
+ };
29
+ }
30
+
31
+ getTheme(): Theme {
32
+ const colors: Record<
33
+ string,
34
+ {
35
+ light: string;
36
+ dark: string;
37
+ }
38
+ > = {};
39
+
40
+ for (const isDark of [false, true]) {
41
+ this.appService.themeService.update({ isDark: isDark });
42
+ for (const [key, value] of this.appService.colorService
43
+ .getColors()
44
+ .entries()) {
45
+ const newKey = key
46
+ .replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, '$1-$2')
47
+ .toLowerCase();
48
+ colors[newKey] ??= { light: '', dark: '' };
49
+ colors[newKey][isDark ? 'dark' : 'light'] = value.getHex();
50
+ }
51
+ }
52
+
53
+ const { fontStyles, fontFamily } = this.appService.pluginService
54
+ .getPlugin(FontPlugin)
55
+ .getInstance()
56
+ .getFonts();
57
+ return {
58
+ colors: {},
59
+ fontFamily: fontFamily,
60
+ plugins: [
61
+ state(Object.keys(colors)),
62
+ font(fontStyles, this.options.responsiveBreakPoints!),
63
+ themer({
64
+ colors,
65
+ darkMode: this.options.darkMode!,
66
+ subThemes: this.options.subThemes,
67
+ appService: this.appService,
68
+ }),
69
+ ],
70
+ };
71
+ }
72
+ }
@@ -0,0 +1,2 @@
1
+ export * from './scheme.entity';
2
+ export * from './variant.entity';
@@ -33,6 +33,7 @@ export const getRotatedHue = (
33
33
 
34
34
  export class VariantEntity {
35
35
  constructor(
36
- public palettes: Record<string, (sourceColorHct: Hct) => TonalPalette> = {}
36
+ public palettes: Record<string, (sourceColorHct: Hct) => TonalPalette> = {},
37
+ public customPalettes?: (colorHct: Hct) => TonalPalette
37
38
  ) {}
38
39
  }
@@ -0,0 +1,4 @@
1
+ export * from './entities';
2
+ export * from './models';
3
+ export * from './services';
4
+ export * from './theme.module';
@@ -0,0 +1 @@
1
+ export * from './variant.model';
@@ -21,6 +21,8 @@ export class VariantModel {
21
21
  neutralVariant: (sourceColorHct) =>
22
22
  TonalPalette.fromHueAndChroma(sourceColorHct.hue, 8.0),
23
23
  },
24
+ customPalettes: (colorHct) =>
25
+ TonalPalette.fromHueAndChroma(colorHct.hue, 16),
24
26
  };
25
27
  static vibrant: VariantEntity = {
26
28
  palettes: {
@@ -41,6 +43,11 @@ export class VariantModel {
41
43
  neutralVariant: (sourceColorHct) =>
42
44
  TonalPalette.fromHueAndChroma(sourceColorHct.hue, 8.0),
43
45
  },
46
+ customPalettes: (colorHct) =>
47
+ TonalPalette.fromHueAndChroma(
48
+ getRotatedHue(colorHct, this.hues, this.secondaryRotations),
49
+ 24.0
50
+ ),
44
51
  };
45
52
 
46
53
  private static readonly hues = [
@@ -0,0 +1,3 @@
1
+ export * from './scheme.service';
2
+ export * from './theme.service';
3
+ export * from './variant.service';
@@ -1,39 +1,67 @@
1
- import { Injectable } from '@nestjs/common';
2
1
  import { SchemeEntity, SchemeOptions } from '../entities/scheme.entity';
3
2
  import {
4
3
  argbFromHex,
5
4
  Hct,
6
5
  TonalPalette,
7
6
  } from '@material/material-color-utilities';
8
- import mergeDeep from 'merge-deep';
9
7
 
10
8
  export type SchemeServiceOptions = Omit<
11
9
  SchemeOptions,
12
10
  'palettes' | 'sourceColorArgb'
13
11
  > & {
14
- sourceColorHex: string;
15
- palettes: Record<string, (sourceColorHct: Hct) => TonalPalette>;
12
+ sourcesColorHex: Record<string, string> & { primary?: string };
13
+ palettes: Record<
14
+ string,
15
+ {
16
+ sourceColorkey?: string;
17
+ tonalPalette: (sourceColorHct: Hct) => TonalPalette;
18
+ }
19
+ >;
16
20
  };
17
21
 
18
- @Injectable()
19
22
  export class SchemeService {
20
23
  private schemeEntity?: SchemeEntity;
21
24
  private options?: SchemeServiceOptions;
22
25
 
23
26
  createOrUpdate(options: Partial<SchemeServiceOptions>) {
24
- this.options = mergeDeep(options, this.options);
27
+ this.options = {
28
+ ...this.options,
29
+ ...options,
30
+ sourcesColorHex: {
31
+ ...this.options?.sourcesColorHex,
32
+ ...options.sourcesColorHex,
33
+ },
34
+ palettes: {
35
+ ...this.options?.palettes,
36
+ ...options.palettes,
37
+ },
38
+ } as SchemeServiceOptions;
25
39
  const palettes = new Map<string, TonalPalette>();
26
40
 
27
- const sourceColorArgb = argbFromHex(this.options.sourceColorHex);
41
+ if (!this.options.sourcesColorHex.primary) {
42
+ throw new Error('Primary source color is not set');
43
+ }
44
+
45
+ const sourceColorArgb = argbFromHex(this.options.sourcesColorHex.primary);
28
46
  const sourceColorHct: Hct = Hct.fromInt(sourceColorArgb);
29
47
 
30
48
  if (!this.options.palettes) {
31
49
  return;
32
50
  }
33
- for (const [key, paletteFunction] of Object.entries(
34
- this.options.palettes
35
- )) {
36
- const palette: TonalPalette = paletteFunction(sourceColorHct);
51
+ for (const [
52
+ key,
53
+ { sourceColorkey, tonalPalette: paletteFunction },
54
+ ] of Object.entries(this.options.palettes)) {
55
+ let palette: TonalPalette;
56
+ if (!sourceColorkey) {
57
+ palette = paletteFunction(sourceColorHct);
58
+ } else {
59
+ const sourceColorArgb = argbFromHex(
60
+ this.options.sourcesColorHex[sourceColorkey]
61
+ );
62
+ const sourceColorHct: Hct = Hct.fromInt(sourceColorArgb);
63
+ palette = paletteFunction(sourceColorHct);
64
+ }
37
65
  palettes.set(key, palette);
38
66
  }
39
67
  this.schemeEntity = new SchemeEntity({
@@ -1,10 +1,12 @@
1
1
  import { DynamicColor } from '@material/material-color-utilities';
2
- import { Injectable } from '@nestjs/common';
3
2
  import { SchemeService, SchemeServiceOptions } from './scheme.service';
4
3
  import { VariantService } from './variant.service';
5
4
  import { VariantEntity } from '../entities/variant.entity';
6
5
 
7
- type ThemeOptions = Omit<SchemeServiceOptions, 'palettes'>;
6
+ type ThemeOptions = Omit<
7
+ SchemeServiceOptions,
8
+ 'palettes' | 'sourcesColorHex'
9
+ > & { sourceColorHex: string };
8
10
 
9
11
  const colorPaletteKeyColor = DynamicColor.fromPalette({
10
12
  name: 'primary_palette_key_color',
@@ -12,12 +14,19 @@ const colorPaletteKeyColor = DynamicColor.fromPalette({
12
14
  tone: (s) => s.primaryPalette.keyColor.tone,
13
15
  });
14
16
 
15
- @Injectable()
16
17
  export class ThemeService {
17
- constructor(
18
- private schemeService: SchemeService,
19
- private variantService: VariantService
20
- ) {
18
+ private readonly schemeService: SchemeService;
19
+ private readonly variantService: VariantService;
20
+ constructor({
21
+ schemeService,
22
+ variantService,
23
+ }: {
24
+ schemeService: SchemeService;
25
+ variantService: VariantService;
26
+ }) {
27
+ this.schemeService = schemeService;
28
+ this.variantService = variantService;
29
+
21
30
  // this.addPalette({key: "primary", addDefaultColors: true})
22
31
  // this.addPalette({key: "secondary", addDefaultColors: true})
23
32
  // this.addPalette({key: "tertiary", addDefaultColors: true})
@@ -41,16 +50,23 @@ export class ThemeService {
41
50
  // return this.theme();
42
51
  // }
43
52
 
44
- create(options: ThemeOptions) {
45
- this.schemeService.createOrUpdate(options);
53
+ create(options: ThemeOptions & { variant: VariantEntity }) {
54
+ this.schemeService.createOrUpdate({
55
+ ...options,
56
+ sourcesColorHex: { primary: options.sourceColorHex },
57
+ });
58
+ this.variantService.set(options.variant);
46
59
  }
47
60
 
48
- addVariant(variant: VariantEntity) {
49
- this.variantService.set(variant);
61
+ update(options: Partial<ThemeOptions> & { variant?: VariantEntity }) {
62
+ const themeOptions: Partial<SchemeServiceOptions> = { ...options };
63
+ if (options.sourceColorHex)
64
+ themeOptions.sourcesColorHex = { primary: options.sourceColorHex };
65
+ this.schemeService.createOrUpdate(themeOptions);
66
+ if (options.variant) this.variantService.set(options.variant);
50
67
  }
51
-
52
- update(options: Partial<ThemeOptions>) {
53
- this.schemeService.createOrUpdate(options);
68
+ addCustomPalette(key: string, colorHex: string) {
69
+ this.variantService.addCustomPalette(key, colorHex);
54
70
  }
55
71
  // theme(): SchemeService {
56
72
  // return new SchemeService(this.themeOptions, this.colorService)
@@ -1,17 +1,52 @@
1
1
  import { SchemeService } from './scheme.service';
2
2
  import { VariantEntity } from '../entities/variant.entity';
3
- import { Injectable } from '@nestjs/common';
4
- import { TonalPalette } from '@material/material-color-utilities';
3
+ import { Hct, TonalPalette } from '@material/material-color-utilities';
5
4
 
6
- @Injectable()
7
5
  export class VariantService {
8
- constructor(private schemeService: SchemeService) {}
6
+ public customPalettes: Record<string, string> = {};
7
+ private variantEntity?: VariantEntity;
8
+
9
+ private readonly schemeService: SchemeService;
10
+ constructor({ schemeService }: { schemeService: SchemeService }) {
11
+ this.schemeService = schemeService;
12
+ }
13
+
14
+ addCustomPalette(key: string, colorHex: string) {
15
+ this.customPalettes[key] = colorHex;
16
+ this.update();
17
+ }
9
18
 
10
19
  set(variantEntity: VariantEntity) {
20
+ this.variantEntity = variantEntity;
11
21
  if (!variantEntity.palettes.error) {
12
22
  variantEntity.palettes.error = () =>
13
23
  TonalPalette.fromHueAndChroma(25.0, 84.0);
14
24
  }
15
- this.schemeService.createOrUpdate(variantEntity);
25
+ this.update();
26
+ }
27
+ private update() {
28
+ if (!this.variantEntity) return;
29
+ const palettes: Record<
30
+ string,
31
+ {
32
+ sourceColorkey?: string;
33
+ tonalPalette: (sourceColorHct: Hct) => TonalPalette;
34
+ }
35
+ > = {};
36
+ Object.keys(this.variantEntity.palettes).forEach((key) => {
37
+ palettes[key] = { tonalPalette: this.variantEntity!.palettes[key] };
38
+ });
39
+ if (this.variantEntity.customPalettes) {
40
+ Object.keys(this.customPalettes).forEach((key) => {
41
+ palettes[key] = {
42
+ sourceColorkey: key,
43
+ tonalPalette: this.variantEntity!.customPalettes!,
44
+ };
45
+ });
46
+ }
47
+ this.schemeService.createOrUpdate({
48
+ sourcesColorHex: this.customPalettes,
49
+ palettes: palettes,
50
+ });
16
51
  }
17
52
  }
@@ -1,10 +1,9 @@
1
- import { Module } from '@nestjs/common';
2
- import { SchemeService } from './services/scheme.service';
3
- import { ThemeService } from './services/theme.service';
4
- import { VariantService } from './services/variant.service';
1
+ import { SchemeService, ThemeService, VariantService } from './services';
2
+ import { asClass } from 'awilix';
3
+ import { Module } from '../app.container';
5
4
 
6
- @Module({
7
- providers: [SchemeService, ThemeService, VariantService],
8
- exports: [ThemeService, SchemeService],
9
- })
10
- export class ThemeModule {}
5
+ export const ThemeModule: Module = {
6
+ schemeService: asClass(SchemeService).singleton(),
7
+ variantService: asClass(VariantService).singleton(),
8
+ themeService: asClass(ThemeService).singleton(),
9
+ };
@@ -1,15 +0,0 @@
1
- import { DynamicColor } from '../material-color-utilities/dynamic_color';
2
- import { SchemeEntity } from '../theme/entities/scheme.entity';
3
- import { ColorEntity, ColorOptions } from './entities/color.entity';
4
- import { SchemeService } from '../theme/services/scheme.service';
5
- export declare const highestSurface: (s: SchemeEntity, colorManagerService: ColorManagerService) => DynamicColor;
6
- export declare class ColorManagerService {
7
- private schemeService;
8
- private colorMap;
9
- constructor(schemeService: SchemeService);
10
- createOrUpdate(key: string, args: Partial<ColorOptions>): ColorEntity;
11
- remove(key: string): boolean;
12
- get(key: string): ColorEntity;
13
- getAll(): ReadonlyMap<string, ColorEntity>;
14
- addFromPalette(key: string): void;
15
- }
@@ -1,14 +0,0 @@
1
- import { ColorManagerService } from './color-manager.service';
2
- import { ColorInterface } from './color.interface';
3
- import { ColorEntity, ColorOptions } from './entities/color.entity';
4
- export declare class ColorService implements ColorInterface {
5
- private colorManagerService;
6
- constructor(colorManagerService: ColorManagerService);
7
- getAllColors(): ReadonlyMap<string, ColorEntity>;
8
- addBaseColors(): void;
9
- addColor(key: string, color: ColorOptions): ColorEntity;
10
- addColors(colors: Record<string, ColorOptions>): ColorEntity[];
11
- getColor(key: string): ColorEntity;
12
- removeColor(key: string): boolean;
13
- updateColor(key: string, newColor: Partial<ColorOptions>): ColorEntity;
14
- }
@@ -1,58 +0,0 @@
1
- import { Injectable } from '@nestjs/common';
2
- import { ColorManagerService } from './color-manager.service';
3
- import { ColorInterface } from './color.interface';
4
- import { ColorEntity, ColorOptions } from './entities/color.entity';
5
- import { defaultColors, DynamicColorKey } from './models/default-color.model';
6
-
7
- @Injectable()
8
- export class ColorService implements ColorInterface {
9
- constructor(private colorManagerService: ColorManagerService) {}
10
-
11
- getAllColors() {
12
- return this.colorManagerService.getAll();
13
- }
14
-
15
- // getColors() {
16
- // const colors: Record<string, string> = {};
17
- //
18
- // for (const [key, value] of this.colorManagerService.getAll()) {
19
- // colors[key] = hexFromArgb(value.getArgb(this.schemeService.get()));
20
- // }
21
- //
22
- // return colors;
23
- // }
24
-
25
- addBaseColors() {
26
- this.colorManagerService.addFromPalette('primary');
27
- this.colorManagerService.addFromPalette('secondary');
28
- this.colorManagerService.addFromPalette('tertiary');
29
-
30
- const colors = defaultColors(this.colorManagerService);
31
- Object.keys(colors).map((key) => {
32
- const color: Partial<ColorOptions> | undefined =
33
- colors[key as DynamicColorKey];
34
- if (!color) return;
35
- return this.colorManagerService.createOrUpdate(key, color);
36
- });
37
- }
38
-
39
- addColor(key: string, color: ColorOptions): ColorEntity {
40
- return this.colorManagerService.createOrUpdate(key, color);
41
- }
42
-
43
- addColors(colors: Record<string, ColorOptions>): ColorEntity[] {
44
- return Object.keys(colors).map((key) => this.addColor(key, colors[key]));
45
- }
46
-
47
- getColor(key: string): ColorEntity {
48
- return this.colorManagerService.get(key);
49
- }
50
-
51
- removeColor(key: string): boolean {
52
- return this.colorManagerService.remove(key);
53
- }
54
-
55
- updateColor(key: string, newColor: Partial<ColorOptions>): ColorEntity {
56
- return this.colorManagerService.createOrUpdate(key, newColor);
57
- }
58
- }