@udixio/theme 1.0.0-beta.2 → 1.0.0-beta.20

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 +2 -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.abstract.d.ts +7 -0
  23. package/dist/plugin/plugin.module.d.ts +2 -0
  24. package/dist/plugin/plugin.service.d.ts +12 -0
  25. package/dist/plugins/font/font.plugin.d.ts +38 -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 +4 -0
  33. package/dist/plugins/tailwind/tailwind.plugin.d.ts +17 -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 +1316 -579
  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 +1284 -580
  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 +14 -3
  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} +22 -17
  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 +95 -0
  68. package/src/config/index.ts +3 -0
  69. package/src/index.ts +11 -0
  70. package/src/main.ts +10 -7
  71. package/src/material-color-utilities/index.ts +1 -0
  72. package/src/plugin/index.ts +3 -0
  73. package/src/plugin/plugin.abstract.ts +9 -0
  74. package/src/plugin/plugin.module.ts +7 -0
  75. package/src/plugin/plugin.service.ts +48 -0
  76. package/src/plugins/font/font.plugin.ts +172 -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 +19 -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 +53 -0
  84. package/src/plugins/tailwind/tailwind.plugin.ts +64 -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 -13
  97. package/src/color/color.service.ts +0 -52
@@ -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(this.options, 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<Omit<ColorOptions, 'name'>>): ColorEntity;
11
- remove(key: string): boolean;
12
- get(key: string): ColorEntity;
13
- getAll(): ReadonlyMap<string, ColorEntity>;
14
- addFromPalette(key: string): void;
15
- }
@@ -1,13 +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
- addColor(key: string, color: ColorOptions): ColorEntity;
9
- addColors(colors: Record<string, ColorOptions>): ColorEntity[];
10
- getColor(key: string): ColorEntity;
11
- removeColor(key: string): boolean;
12
- updateColor(key: string, newColor: Partial<ColorOptions>): ColorEntity;
13
- }
@@ -1,52 +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
-
6
- @Injectable()
7
- export class ColorService implements ColorInterface {
8
- constructor(private colorManagerService: ColorManagerService) {}
9
-
10
- getAllColors() {
11
- return this.colorManagerService.getAll();
12
- }
13
-
14
- // getColors() {
15
- // const colors: Record<string, string> = {};
16
- //
17
- // for (const [key, value] of this.colorManagerService.getAll()) {
18
- // colors[key] = hexFromArgb(value.getArgb(this.schemeService.get()));
19
- // }
20
- //
21
- // return colors;
22
- // }
23
- //
24
- // addBaseColors() {
25
- // this.colorManagerService.addFromPalette('primary');
26
- // this.colorManagerService.addFromPalette('secondary');
27
- // this.colorManagerService.addFromPalette('tertiary');
28
- // for (const [key, value] of Object.entries(this.defaultColorModel.colors)) {
29
- // this.colorManagerService.createOrUpdate(key, value as any);
30
- // }
31
- // }
32
-
33
- addColor(key: string, color: ColorOptions): ColorEntity {
34
- return this.colorManagerService.createOrUpdate(key, color);
35
- }
36
-
37
- addColors(colors: Record<string, ColorOptions>): ColorEntity[] {
38
- return Object.keys(colors).map((key) => this.addColor(key, colors[key]));
39
- }
40
-
41
- getColor(key: string): ColorEntity {
42
- return this.colorManagerService.get(key);
43
- }
44
-
45
- removeColor(key: string): boolean {
46
- return this.colorManagerService.remove(key);
47
- }
48
-
49
- updateColor(key: string, newColor: Partial<ColorOptions>): ColorEntity {
50
- return this.colorManagerService.createOrUpdate(key, newColor);
51
- }
52
- }