@udixio/theme 1.0.0-beta.2

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 (54) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +73 -0
  3. package/dist/app.module.d.ts +2 -0
  4. package/dist/app.service.d.ts +7 -0
  5. package/dist/color/color-manager.service.d.ts +15 -0
  6. package/dist/color/color.interface.d.ts +9 -0
  7. package/dist/color/color.module.d.ts +2 -0
  8. package/dist/color/color.service.d.ts +13 -0
  9. package/dist/color/entities/color.entity.d.ts +37 -0
  10. package/dist/color/models/default-color.model.d.ts +4 -0
  11. package/dist/index.d.ts +1 -0
  12. package/dist/index.js +8 -0
  13. package/dist/main.d.ts +2 -0
  14. package/dist/material-color-utilities/contrastCurve.d.ts +46 -0
  15. package/dist/material-color-utilities/dynamic_color.d.ts +171 -0
  16. package/dist/material-color-utilities/index.d.ts +2 -0
  17. package/dist/material-color-utilities/toneDeltaPair.d.ts +60 -0
  18. package/dist/theme/entities/scheme.entity.d.ts +15 -0
  19. package/dist/theme/entities/variant.entity.d.ts +6 -0
  20. package/dist/theme/models/variant.model.d.ts +8 -0
  21. package/dist/theme/services/scheme.service.d.ts +12 -0
  22. package/dist/theme/services/theme.service.d.ts +13 -0
  23. package/dist/theme/services/variant.service.d.ts +7 -0
  24. package/dist/theme/theme.module.d.ts +2 -0
  25. package/dist/theme.cjs.development.js +1310 -0
  26. package/dist/theme.cjs.development.js.map +1 -0
  27. package/dist/theme.cjs.production.min.js +2 -0
  28. package/dist/theme.cjs.production.min.js.map +1 -0
  29. package/dist/theme.esm.js +1306 -0
  30. package/dist/theme.esm.js.map +1 -0
  31. package/package.json +101 -0
  32. package/src/app.module.ts +10 -0
  33. package/src/app.service.spec.ts +15 -0
  34. package/src/app.service.ts +11 -0
  35. package/src/color/color-manager.service.ts +186 -0
  36. package/src/color/color.interface.ts +15 -0
  37. package/src/color/color.module.ts +11 -0
  38. package/src/color/color.service.spec.ts +28 -0
  39. package/src/color/color.service.ts +52 -0
  40. package/src/color/entities/color.entity.ts +60 -0
  41. package/src/color/models/default-color.model.ts +297 -0
  42. package/src/index.ts +1 -0
  43. package/src/main.ts +11 -0
  44. package/src/material-color-utilities/contrastCurve.ts +63 -0
  45. package/src/material-color-utilities/dynamic_color.ts +450 -0
  46. package/src/material-color-utilities/index.ts +2 -0
  47. package/src/material-color-utilities/toneDeltaPair.ts +64 -0
  48. package/src/theme/entities/scheme.entity.ts +44 -0
  49. package/src/theme/entities/variant.entity.ts +38 -0
  50. package/src/theme/models/variant.model.ts +56 -0
  51. package/src/theme/services/scheme.service.ts +52 -0
  52. package/src/theme/services/theme.service.ts +58 -0
  53. package/src/theme/services/variant.service.ts +17 -0
  54. package/src/theme/theme.module.ts +10 -0
@@ -0,0 +1,52 @@
1
+ import { Injectable } from '@nestjs/common';
2
+ import { SchemeEntity, SchemeOptions } from '../entities/scheme.entity';
3
+ import {
4
+ argbFromHex,
5
+ Hct,
6
+ TonalPalette,
7
+ } from '@material/material-color-utilities';
8
+ import mergeDeep from 'merge-deep';
9
+
10
+ export type SchemeServiceOptions = Omit<
11
+ SchemeOptions,
12
+ 'palettes' | 'sourceColorArgb'
13
+ > & {
14
+ sourceColorHex: string;
15
+ palettes: Record<string, (sourceColorHct: Hct) => TonalPalette>;
16
+ };
17
+
18
+ @Injectable()
19
+ export class SchemeService {
20
+ private schemeEntity?: SchemeEntity;
21
+ private options?: SchemeServiceOptions;
22
+
23
+ createOrUpdate(options: Partial<SchemeServiceOptions>) {
24
+ this.options = mergeDeep(this.options, options);
25
+ const palettes = new Map<string, TonalPalette>();
26
+
27
+ const sourceColorArgb = argbFromHex(this.options.sourceColorHex);
28
+ const sourceColorHct: Hct = Hct.fromInt(sourceColorArgb);
29
+
30
+ if (!this.options.palettes) {
31
+ return;
32
+ }
33
+ for (const [key, paletteFunction] of Object.entries(
34
+ this.options.palettes
35
+ )) {
36
+ const palette: TonalPalette = paletteFunction(sourceColorHct);
37
+ palettes.set(key, palette);
38
+ }
39
+ this.schemeEntity = new SchemeEntity({
40
+ ...this.options,
41
+ palettes: palettes,
42
+ sourceColorArgb: sourceColorArgb,
43
+ });
44
+ }
45
+
46
+ get(): SchemeEntity {
47
+ if (!this.schemeEntity) {
48
+ throw new Error('Scheme is not created');
49
+ }
50
+ return this.schemeEntity;
51
+ }
52
+ }
@@ -0,0 +1,58 @@
1
+ import { DynamicColor } from '@material/material-color-utilities';
2
+ import { Injectable } from '@nestjs/common';
3
+ import { SchemeService, SchemeServiceOptions } from './scheme.service';
4
+ import { VariantService } from './variant.service';
5
+ import { VariantEntity } from '../entities/variant.entity';
6
+
7
+ type ThemeOptions = Omit<SchemeServiceOptions, 'palettes'>;
8
+
9
+ const colorPaletteKeyColor = DynamicColor.fromPalette({
10
+ name: 'primary_palette_key_color',
11
+ palette: (s) => s.primaryPalette,
12
+ tone: (s) => s.primaryPalette.keyColor.tone,
13
+ });
14
+
15
+ @Injectable()
16
+ export class ThemeService {
17
+ constructor(
18
+ private schemeService: SchemeService,
19
+ private variantService: VariantService
20
+ ) {
21
+ // this.addPalette({key: "primary", addDefaultColors: true})
22
+ // this.addPalette({key: "secondary", addDefaultColors: true})
23
+ // this.addPalette({key: "tertiary", addDefaultColors: true})
24
+ // this.addPalette({key: "error", palette: TonalPalette.fromHueAndChroma(25.0, 84.0)})
25
+ // this.addPalette({key: "neutral"})
26
+ // this.addPalette({key: "neutralVariant"})
27
+ }
28
+ // addPalette({key, palette, addDefaultColors}: {key: string; palette: TonalPalette; addDefaultColors: boolean}) {
29
+ // this.themeOptions.palettes.set(key, palette);
30
+ // if (addDefaultColors){
31
+ // this.colorService.addPalette(key)
32
+ // }
33
+ // }
34
+
35
+ // create(args: ThemeOptions): SchemeService {
36
+ // return new SchemeService(args, this.colorService)
37
+ // }
38
+ //
39
+ // update(options: Partial<ThemeOptions>): SchemeService {
40
+ // Object.assign(this.themeOptions, options);
41
+ // return this.theme();
42
+ // }
43
+
44
+ create(options: ThemeOptions) {
45
+ this.schemeService.createOrUpdate(options);
46
+ }
47
+
48
+ addVariant(variant: VariantEntity) {
49
+ this.variantService.set(variant);
50
+ }
51
+
52
+ update(options: Partial<ThemeOptions>) {
53
+ this.schemeService.createOrUpdate(options);
54
+ }
55
+ // theme(): SchemeService {
56
+ // return new SchemeService(this.themeOptions, this.colorService)
57
+ // }
58
+ }
@@ -0,0 +1,17 @@
1
+ import { SchemeService } from './scheme.service';
2
+ import { VariantEntity } from '../entities/variant.entity';
3
+ import { Injectable } from '@nestjs/common';
4
+ import { TonalPalette } from '@material/material-color-utilities';
5
+
6
+ @Injectable()
7
+ export class VariantService {
8
+ constructor(private schemeService: SchemeService) {}
9
+
10
+ set(variantEntity: VariantEntity) {
11
+ if (!variantEntity.palettes.error) {
12
+ variantEntity.palettes.error = () =>
13
+ TonalPalette.fromHueAndChroma(25.0, 84.0);
14
+ }
15
+ this.schemeService.createOrUpdate(variantEntity);
16
+ }
17
+ }
@@ -0,0 +1,10 @@
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';
5
+
6
+ @Module({
7
+ providers: [SchemeService, ThemeService, VariantService],
8
+ exports: [ThemeService, SchemeService],
9
+ })
10
+ export class ThemeModule {}